From f099426a9e0c5ab8ca0756c2deb9bc3f4db15d92 Mon Sep 17 00:00:00 2001 From: Louis DeJardin Date: Mon, 2 Jun 2014 16:24:55 -0700 Subject: [PATCH 0001/1662] Adding empty project structure --- .gitattributes | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ .gitignore | 26 ++++++++++++++++++++++++++ NuGet.config | 7 +++++++ build.cmd | 26 ++++++++++++++++++++++++++ build.sh | 30 ++++++++++++++++++++++++++++++ global.json | 5 +++++ makefile.shade | 7 +++++++ 7 files changed, 151 insertions(+) create mode 100644 .gitattributes create mode 100644 .gitignore create mode 100644 NuGet.config create mode 100644 build.cmd create mode 100644 build.sh create mode 100644 global.json create mode 100644 makefile.shade diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000000..bdaa5ba982 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,50 @@ +*.doc diff=astextplain +*.DOC diff=astextplain +*.docx diff=astextplain +*.DOCX diff=astextplain +*.dot diff=astextplain +*.DOT diff=astextplain +*.pdf diff=astextplain +*.PDF diff=astextplain +*.rtf diff=astextplain +*.RTF diff=astextplain + +*.jpg binary +*.png binary +*.gif binary + +*.cs text=auto diff=csharp +*.vb text=auto +*.resx text=auto +*.c text=auto +*.cpp text=auto +*.cxx text=auto +*.h text=auto +*.hxx text=auto +*.py text=auto +*.rb text=auto +*.java text=auto +*.html text=auto +*.htm text=auto +*.css text=auto +*.scss text=auto +*.sass text=auto +*.less text=auto +*.js text=auto +*.lisp text=auto +*.clj text=auto +*.sql text=auto +*.php text=auto +*.lua text=auto +*.m text=auto +*.asm text=auto +*.erl text=auto +*.fs text=auto +*.fsx text=auto +*.hs text=auto + +*.csproj text=auto +*.vbproj text=auto +*.fsproj text=auto +*.dbproj text=auto +*.sln text=auto eol=crlf diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000..216e8d9c58 --- /dev/null +++ b/.gitignore @@ -0,0 +1,26 @@ +[Oo]bj/ +[Bb]in/ +TestResults/ +.nuget/ +*.sln.ide/ +_ReSharper.*/ +packages/ +artifacts/ +PublishProfiles/ +*.user +*.suo +*.cache +*.docstates +_ReSharper.* +nuget.exe +*net45.csproj +*net451.csproj +*k10.csproj +*.psess +*.vsp +*.pidb +*.userprefs +*DS_Store +*.ncrunchsolution +*.*sdf +*.ipch \ No newline at end of file diff --git a/NuGet.config b/NuGet.config new file mode 100644 index 0000000000..600a375c7e --- /dev/null +++ b/NuGet.config @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/build.cmd b/build.cmd new file mode 100644 index 0000000000..903d532df3 --- /dev/null +++ b/build.cmd @@ -0,0 +1,26 @@ +@echo off +cd %~dp0 + +SETLOCAL +SET CACHED_NUGET=%LocalAppData%\NuGet\NuGet.exe + +IF EXIST %CACHED_NUGET% goto copynuget +echo Downloading latest version of NuGet.exe... +IF NOT EXIST %LocalAppData%\NuGet md %LocalAppData%\NuGet +@powershell -NoProfile -ExecutionPolicy unrestricted -Command "$ProgressPreference = 'SilentlyContinue'; Invoke-WebRequest 'https://www.nuget.org/nuget.exe' -OutFile '%CACHED_NUGET%'" + +:copynuget +IF EXIST .nuget\nuget.exe goto restore +md .nuget +copy %CACHED_NUGET% .nuget\nuget.exe > nul + +:restore +IF EXIST packages\KoreBuild goto run +.nuget\NuGet.exe install KoreBuild -ExcludeVersion -o packages -nocache -pre +.nuget\NuGet.exe install Sake -version 0.2 -o packages -ExcludeVersion +CALL packages\KoreBuild\build\kvm upgrade -svr50 -x86 +CALL packages\KoreBuild\build\kvm install default -svrc50 -x86 + +:run +CALL packages\KoreBuild\build\kvm use default -svr50 -x86 +packages\Sake\tools\Sake.exe -I packages\KoreBuild\build -f makefile.shade %* diff --git a/build.sh b/build.sh new file mode 100644 index 0000000000..db1e0c3dde --- /dev/null +++ b/build.sh @@ -0,0 +1,30 @@ +#!/bin/sh + +if test `uname` = Darwin; then + cachedir=~/Library/Caches/KBuild +else + if x$XDG_DATA_HOME = x; then + cachedir=$HOME/.local/share + else + cachedir=$XDG_DATA_HOME; + fi +fi +mkdir -p $cachedir + +url=https://www.nuget.org/nuget.exe + +if test ! -f $cachedir/nuget.exe; then + wget -o $cachedir/nuget.exe $url 2>/dev/null || curl -o $cachedir/nuget.exe --location $url /dev/null +fi + +if test ! -e .nuget; then + mkdir .nuget + cp $cachedir/nuget.exe .nuget +fi + +if test ! -d packages/KoreBuild; then + mono .nuget/nuget.exe install KoreBuild -ExcludeVersion -o packages -nocache -pre + mono .nuget/nuget.exe install Sake -version 0.2 -o packages -ExcludeVersion +fi + +mono packages/Sake/tools/Sake.exe -I packages/KoreBuild/build -f makefile.shade "$@" \ No newline at end of file diff --git a/global.json b/global.json new file mode 100644 index 0000000000..ea28015a77 --- /dev/null +++ b/global.json @@ -0,0 +1,5 @@ +{ + "sources": [ + "src" + ] +} diff --git a/makefile.shade b/makefile.shade new file mode 100644 index 0000000000..6357ea2841 --- /dev/null +++ b/makefile.shade @@ -0,0 +1,7 @@ + +var VERSION='0.1' +var FULL_VERSION='0.1' +var AUTHORS='Microsoft' + +use-standard-lifecycle +k-standard-goals From 3404100f08d5cc7916bf12a9784adf8b51705c07 Mon Sep 17 00:00:00 2001 From: Louis DeJardin Date: Mon, 2 Jun 2014 16:31:33 -0700 Subject: [PATCH 0002/1662] Adding empty projects and solution --- KestrelHttpServer.sln | 33 +++++++++++++++++++ .../Project.json | 8 +++++ .../Project.json | 13 ++++++++ 3 files changed, 54 insertions(+) create mode 100644 KestrelHttpServer.sln create mode 100644 src/Microsoft.AspNet.Server.Kestrel/Project.json create mode 100644 test/Microsoft.AspNet.Server.KestralTests/Project.json diff --git a/KestrelHttpServer.sln b/KestrelHttpServer.sln new file mode 100644 index 0000000000..9b0ccec28c --- /dev/null +++ b/KestrelHttpServer.sln @@ -0,0 +1,33 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 14 +VisualStudioVersion = 14.0.21728.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.Server.Kestrel", "src\Microsoft.AspNet.Server.Kestrel\Microsoft.AspNet.Server.Kestrel.kproj", "{F510611A-3BEE-4B88-A613-5F4A74ED82A1}" +EndProject +Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.Server.KestralTests", "test\Microsoft.AspNet.Server.KestralTests\Microsoft.AspNet.Server.KestralTests.kproj", "{37F3BFB2-6454-49E5-9D7F-581BF755CCFE}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{7972A5D6-3385-4127-9277-428506DD44FF}" + ProjectSection(SolutionItems) = preProject + global.json = global.json + EndProjectSection +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {F510611A-3BEE-4B88-A613-5F4A74ED82A1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F510611A-3BEE-4B88-A613-5F4A74ED82A1}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F510611A-3BEE-4B88-A613-5F4A74ED82A1}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F510611A-3BEE-4B88-A613-5F4A74ED82A1}.Release|Any CPU.Build.0 = Release|Any CPU + {37F3BFB2-6454-49E5-9D7F-581BF755CCFE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {37F3BFB2-6454-49E5-9D7F-581BF755CCFE}.Debug|Any CPU.Build.0 = Debug|Any CPU + {37F3BFB2-6454-49E5-9D7F-581BF755CCFE}.Release|Any CPU.ActiveCfg = Release|Any CPU + {37F3BFB2-6454-49E5-9D7F-581BF755CCFE}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/src/Microsoft.AspNet.Server.Kestrel/Project.json b/src/Microsoft.AspNet.Server.Kestrel/Project.json new file mode 100644 index 0000000000..0802ababfa --- /dev/null +++ b/src/Microsoft.AspNet.Server.Kestrel/Project.json @@ -0,0 +1,8 @@ +{ + "version": "0.1-alpha-*", + "dependencies": { + }, + "compilationOptions": { + "allowUnsafe": true + } +} diff --git a/test/Microsoft.AspNet.Server.KestralTests/Project.json b/test/Microsoft.AspNet.Server.KestralTests/Project.json new file mode 100644 index 0000000000..a9db68cb96 --- /dev/null +++ b/test/Microsoft.AspNet.Server.KestralTests/Project.json @@ -0,0 +1,13 @@ +{ + "version": "0.1-alpha-*", + "dependencies": { + "Xunit.KRunner": "0.1-*", + "xunit.assert": "2.0.0-*", + "xunit.abstractions": "2.0.0-*", + "Microsoft.AspNet.Server.Kestrel": "0.1-*" + }, + "commands": { + "run": "Xunit.KRunner", + "test": "Xunit.KRunner" + } +} From 1b412bc99f493105dfda2068fd267d968a35ff70 Mon Sep 17 00:00:00 2001 From: Louis DeJardin Date: Mon, 2 Jun 2014 16:32:31 -0700 Subject: [PATCH 0003/1662] Adding libuv p/invokes --- .../Networking/Libuv.cs | 196 ++++++++++++++++++ .../Networking/UcAsyncHandle.cs | 39 ++++ .../Networking/UvHandle.cs | 58 ++++++ .../Networking/UvLoopHandle.cs | 40 ++++ .../Networking/UvStreamHandle.cs | 74 +++++++ .../Networking/UvTcpHandle.cs | 23 ++ .../NetworkingTests.cs | 152 ++++++++++++++ .../libuv.dll | Bin 0 -> 317440 bytes 8 files changed, 582 insertions(+) create mode 100644 src/Microsoft.AspNet.Server.Kestrel/Networking/Libuv.cs create mode 100644 src/Microsoft.AspNet.Server.Kestrel/Networking/UcAsyncHandle.cs create mode 100644 src/Microsoft.AspNet.Server.Kestrel/Networking/UvHandle.cs create mode 100644 src/Microsoft.AspNet.Server.Kestrel/Networking/UvLoopHandle.cs create mode 100644 src/Microsoft.AspNet.Server.Kestrel/Networking/UvStreamHandle.cs create mode 100644 src/Microsoft.AspNet.Server.Kestrel/Networking/UvTcpHandle.cs create mode 100644 test/Microsoft.AspNet.Server.KestralTests/NetworkingTests.cs create mode 100644 test/Microsoft.AspNet.Server.KestralTests/libuv.dll diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/Libuv.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/Libuv.cs new file mode 100644 index 0000000000..2431574d4e --- /dev/null +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/Libuv.cs @@ -0,0 +1,196 @@ +// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Reflection; +using System.Runtime.InteropServices; + +namespace Microsoft.AspNet.Server.Kestrel.Networking +{ + public class Libuv + { + private IntPtr _module = IntPtr.Zero; + + [DllImport("kernel32")] + public static extern IntPtr LoadLibrary(string dllToLoad); + + [DllImport("kernel32", CharSet = CharSet.Ansi, ExactSpelling = true, SetLastError = true)] + public static extern IntPtr GetProcAddress(IntPtr hModule, string procedureName); + + [DllImport("kernel32")] + public static extern bool FreeLibrary(IntPtr hModule); + + + public void Load(string dllToLoad) + { + var module = LoadLibrary(dllToLoad); + foreach (var field in GetType().GetTypeInfo().DeclaredFields) + { + var procAddress = GetProcAddress(module, field.Name.TrimStart('_')); + if (procAddress == IntPtr.Zero) + { + continue; + } + var value = Marshal.GetDelegateForFunctionPointer(procAddress, field.FieldType); + field.SetValue(this, value); + } + } + + public int Check(int statusCode) + { + if (statusCode < 0) + { + throw new Exception("Status code " + statusCode); + } + return statusCode; + } + + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + delegate int uv_loop_init(UvLoopHandle a0); + uv_loop_init _uv_loop_init; + public void loop_init(UvLoopHandle handle) + { + Check(_uv_loop_init(handle)); + } + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + delegate int uv_loop_close(IntPtr a0); + uv_loop_close _uv_loop_close; + public void loop_close(UvLoopHandle handle) + { + Check(_uv_loop_close(handle.DangerousGetHandle())); + } + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + delegate int uv_run(UvLoopHandle handle, int mode); + uv_run _uv_run; + public int run(UvLoopHandle handle, int mode) + { + return Check(_uv_run(handle, mode)); + } + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + delegate void uv_stop(UvLoopHandle handle); + uv_stop _uv_stop; + public void stop(UvLoopHandle handle) + { + _uv_stop(handle); + } + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + public delegate void uv_close_cb(IntPtr handle); + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + delegate void uv_close(IntPtr handle, uv_close_cb close_cb); + uv_close _uv_close; + public void close(UvHandle handle, uv_close_cb close_cb) + { + _uv_close(handle.DangerousGetHandle(), close_cb); + } + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + public delegate void uv_async_cb(IntPtr handle); + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + delegate int uv_async_init(UvLoopHandle loop, UvAsyncHandle handle, uv_async_cb cb); + uv_async_init _uv_async_init; + public void async_init(UvLoopHandle loop, UvAsyncHandle handle, uv_async_cb cb) + { + Check(_uv_async_init(loop, handle, cb)); + } + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + delegate int uv_async_send(UvAsyncHandle handle); + uv_async_send _uv_async_send; + public void async_send(UvAsyncHandle handle) + { + Check(_uv_async_send(handle)); + } + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + delegate int uv_tcp_init(UvLoopHandle loop, UvTcpHandle handle); + uv_tcp_init _uv_tcp_init; + public void tcp_init(UvLoopHandle loop, UvTcpHandle handle) + { + Check(_uv_tcp_init(loop, handle)); + } + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + delegate int uv_tcp_bind(UvTcpHandle handle, ref sockaddr addr, int flags); + uv_tcp_bind _uv_tcp_bind; + public void tcp_bind(UvTcpHandle handle, ref sockaddr addr, int flags) + { + Check(_uv_tcp_bind(handle, ref addr, flags)); + } + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + public delegate void uv_connection_cb(IntPtr server, int status); + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + delegate int uv_listen(UvStreamHandle handle, int backlog, uv_connection_cb cb); + uv_listen _uv_listen; + public void listen(UvStreamHandle handle, int backlog, uv_connection_cb cb) + { + Check(_uv_listen(handle, backlog, cb)); + } + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + delegate int uv_accept(UvStreamHandle server, UvStreamHandle client); + uv_accept _uv_accept; + public void accept(UvStreamHandle server, UvStreamHandle client) + { + Check(_uv_accept(server, client)); + } + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + public delegate void uv_alloc_cb(IntPtr server, int suggested_size, out uv_buf_t buf); + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + public delegate void uv_read_cb(IntPtr server, int nread, ref uv_buf_t buf); + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + delegate int uv_read_start(UvStreamHandle handle, uv_alloc_cb alloc_cb, uv_read_cb read_cb); + uv_read_start _uv_read_start; + public void read_start(UvStreamHandle handle, uv_alloc_cb alloc_cb, uv_read_cb read_cb) + { + Check(_uv_read_start(handle, alloc_cb, read_cb)); + } + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + delegate int uv_read_stop(UvStreamHandle handle); + uv_read_stop _uv_read_stop; + public void read_stop(UvStreamHandle handle) + { + Check(_uv_read_stop(handle)); + } + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + delegate int uv_ip4_addr(string ip, int port, out sockaddr addr); + + uv_ip4_addr _uv_ip4_addr; + public void ip4_addr(string ip, int port, out sockaddr addr) + { + Check(_uv_ip4_addr(ip, port, out addr)); + } + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + delegate int uv_ip6_addr(string ip, int port, out sockaddr addr); + + uv_ip6_addr _uv_ip6_addr; + public void ip6_addr(string ip, int port, out sockaddr addr) + { + Check(_uv_ip6_addr(ip, port, out addr)); + } + + public struct sockaddr + { + long w; + long x; + long y; + long z; + } + + public struct uv_buf_t + { + public uint len; + public IntPtr memory; + } + + } +} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/UcAsyncHandle.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/UcAsyncHandle.cs new file mode 100644 index 0000000000..6d8f919abb --- /dev/null +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/UcAsyncHandle.cs @@ -0,0 +1,39 @@ +// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Runtime.InteropServices; + +namespace Microsoft.AspNet.Server.Kestrel.Networking +{ + public class UvAsyncHandle : UvHandle + { + private static Libuv.uv_async_cb _uv_async_cb = AsyncCb; + + unsafe static void AsyncCb(IntPtr handle) + { + GCHandle gcHandle = GCHandle.FromIntPtr(*(IntPtr*)handle); + var self = (UvAsyncHandle)gcHandle.Target; + self._callback.Invoke(); + } + + private Action _callback; + + public void Init(UvLoopHandle loop, Action callback) + { + CreateHandle(loop, 256); + _callback = callback; + _uv.async_init(loop, this, _uv_async_cb); + } + + private void UvAsyncCb(IntPtr handle) + { + _callback.Invoke(); + } + + public void Send() + { + _uv.async_send(this); + } + } +} diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvHandle.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvHandle.cs new file mode 100644 index 0000000000..d03240e45c --- /dev/null +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvHandle.cs @@ -0,0 +1,58 @@ +// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Runtime.InteropServices; + +namespace Microsoft.AspNet.Server.Kestrel.Networking +{ + public abstract class UvHandle : SafeHandle + { + protected Libuv _uv; + static Libuv.uv_close_cb _close_cb = DestroyHandle; + + public UvHandle() : base(IntPtr.Zero, true) + { + } + + public override bool IsInvalid + { + get + { + return handle == IntPtr.Zero; + } + } + + unsafe protected void CreateHandle(Libuv uv, int size) + { + _uv = uv; + handle = Marshal.AllocCoTaskMem(size); + *(IntPtr*)handle = GCHandle.ToIntPtr(GCHandle.Alloc(this)); + } + + protected void CreateHandle(UvLoopHandle loop, int size) + { + CreateHandle(loop._uv, size); + } + protected override bool ReleaseHandle() + { + var memory = handle; + if (memory != IntPtr.Zero) + { + _uv.close(this, _close_cb); + handle = IntPtr.Zero; + } + return true; + } + + unsafe protected static void DestroyHandle(IntPtr memory) + { + var gcHandlePtr = *(IntPtr*)memory; + if (gcHandlePtr != IntPtr.Zero) + { + GCHandle.FromIntPtr(gcHandlePtr).Free(); + } + Marshal.FreeCoTaskMem(memory); + } + } +} diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvLoopHandle.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvLoopHandle.cs new file mode 100644 index 0000000000..73bab4b5f7 --- /dev/null +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvLoopHandle.cs @@ -0,0 +1,40 @@ +// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; + +namespace Microsoft.AspNet.Server.Kestrel.Networking +{ + public class UvLoopHandle : UvHandle + { + public void Init(Libuv uv) + { + CreateHandle(uv, 256); + _uv.loop_init(this); + } + + + public int Run(int mode = 0) + { + return _uv.run(this, mode); + } + + public void Stop() + { + _uv.stop(this); + } + + protected override bool ReleaseHandle() + { + var memory = this.handle; + if (memory != IntPtr.Zero) + { + _uv.loop_close(this); + handle = IntPtr.Zero; + DestroyHandle(memory); + } + return true; + } + + } +} diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvStreamHandle.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvStreamHandle.cs new file mode 100644 index 0000000000..1436852863 --- /dev/null +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvStreamHandle.cs @@ -0,0 +1,74 @@ +// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Runtime.InteropServices; + +namespace Microsoft.AspNet.Server.Kestrel.Networking +{ + public abstract class UvStreamHandle : UvHandle + { + private Libuv.uv_connection_cb _connection_cb; + private Libuv.uv_alloc_cb _alloc_cb; + private Libuv.uv_read_cb _read_cb; + + private Action _connection; + private Action _alloc; + private Action _read; + + public void Listen(int backlog, Action connection) + { + _connection_cb = OnConnection; + _connection = connection; + _uv.listen(this, 10, _connection_cb); + } + + public void OnConnection(IntPtr server, int status) + { + _connection(status, this); + } + + public void Accept(UvStreamHandle handle) + { + _uv.accept(this, handle); + } + + public void ReadStart(Action read) + { + _alloc_cb = OnAlloc; + _read_cb = OnRead; + _read = read; + _uv.read_start(this, _alloc_cb, _read_cb); + } + + private void OnAlloc(IntPtr server, int suggested_size, out Libuv.uv_buf_t buf) + { + buf = new Libuv.uv_buf_t + { + memory = Marshal.AllocCoTaskMem(suggested_size), + len = (uint)suggested_size, + }; + } + + private void OnRead(IntPtr server, int nread, ref Libuv.uv_buf_t buf) + { + if (nread == -4095) + { + _read(0, null, this); + Marshal.FreeCoTaskMem(buf.memory); + return; + } + var length = _uv.Check(nread); + var data = new byte[length]; + Marshal.Copy(buf.memory, data, 0, length); + Marshal.FreeCoTaskMem(buf.memory); + + _read(length, data, this); + } + + public void ReadStop() + { + _uv.read_stop(this); + } + } +} diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvTcpHandle.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvTcpHandle.cs new file mode 100644 index 0000000000..0962ff650c --- /dev/null +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvTcpHandle.cs @@ -0,0 +1,23 @@ +// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System.Net; + +namespace Microsoft.AspNet.Server.Kestrel.Networking +{ + public class UvTcpHandle : UvStreamHandle + { + public void Init(UvLoopHandle loop) + { + CreateHandle(loop, 256); + _uv.tcp_init(loop, this); + } + + public void Bind(IPEndPoint endpoint) + { + Libuv.sockaddr addr; + _uv.ip4_addr(endpoint.Address.ToString(), endpoint.Port, out addr); + _uv.tcp_bind(this, ref addr, 0); + } + } +} diff --git a/test/Microsoft.AspNet.Server.KestralTests/NetworkingTests.cs b/test/Microsoft.AspNet.Server.KestralTests/NetworkingTests.cs new file mode 100644 index 0000000000..90e4168e28 --- /dev/null +++ b/test/Microsoft.AspNet.Server.KestralTests/NetworkingTests.cs @@ -0,0 +1,152 @@ +// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using Microsoft.AspNet.Server.Kestrel.Networking; +using System; +using System.Net; +using System.Net.Sockets; +using System.Threading.Tasks; +using Xunit; + +namespace Microsoft.AspNet.Server.KestralTests +{ + /// + /// Summary description for NetworkingTests + /// + public class NetworkingTests + { + Libuv _uv; + public NetworkingTests() + { + _uv = new Libuv(); + _uv.Load("libuv.dll"); + } + + [Fact] + public async Task LoopCanBeInitAndClose() + { + var loop = new UvLoopHandle(); + loop.Init(_uv); + loop.Run(); + loop.Close(); + } + + [Fact] + public async Task AsyncCanBeSent() + { + var loop = new UvLoopHandle(); + loop.Init(_uv); + var trigger = new UvAsyncHandle(); + var called = false; + trigger.Init(loop, () => + { + called = true; + trigger.Close(); + }); + trigger.Send(); + loop.Run(); + loop.Close(); + Assert.True(called); + } + + [Fact] + public async Task SocketCanBeInitAndClose() + { + var loop = new UvLoopHandle(); + loop.Init(_uv); + var tcp = new UvTcpHandle(); + tcp.Init(loop); + tcp.Bind(new IPEndPoint(IPAddress.Loopback, 0)); + tcp.Close(); + loop.Run(); + loop.Close(); + } + + + [Fact] + public async Task SocketCanListenAndAccept() + { + var loop = new UvLoopHandle(); + loop.Init(_uv); + var tcp = new UvTcpHandle(); + tcp.Init(loop); + tcp.Bind(new IPEndPoint(IPAddress.Loopback, 54321)); + tcp.Listen(10, (status, handle) => + { + var tcp2 = new UvTcpHandle(); + tcp2.Init(loop); + tcp.Accept(tcp2); + tcp2.Close(); + tcp.Close(); + }); + var t = Task.Run(async () => + { + var socket = new Socket( + AddressFamily.InterNetwork, + SocketType.Stream, + ProtocolType.Tcp); + await Task.Factory.FromAsync( + socket.BeginConnect, + socket.EndConnect, + new IPEndPoint(IPAddress.Loopback, 54321), + null, + TaskCreationOptions.None); + socket.Close(); + }); + loop.Run(); + loop.Close(); + await t; + } + + + [Fact] + public async Task SocketCanRead() + { + int bytesRead = 0; + var loop = new UvLoopHandle(); + loop.Init(_uv); + var tcp = new UvTcpHandle(); + tcp.Init(loop); + tcp.Bind(new IPEndPoint(IPAddress.Loopback, 54321)); + tcp.Listen(10, (status, handle) => + { + var tcp2 = new UvTcpHandle(); + tcp2.Init(loop); + tcp.Accept(tcp2); + tcp2.ReadStart((nread, data, handle2) => + { + bytesRead += nread; + if (nread == 0) + { + tcp2.Close(); + } + }); + tcp.Close(); + }); + var t = Task.Run(async () => + { + var socket = new Socket( + AddressFamily.InterNetwork, + SocketType.Stream, + ProtocolType.Tcp); + await Task.Factory.FromAsync( + socket.BeginConnect, + socket.EndConnect, + new IPEndPoint(IPAddress.Loopback, 54321), + null, + TaskCreationOptions.None); + await Task.Factory.FromAsync( + socket.BeginSend, + socket.EndSend, + new[] { new ArraySegment(new byte[] { 1, 2, 3, 4, 5 }) }, + SocketFlags.None, + null, + TaskCreationOptions.None); + socket.Close(); + }); + loop.Run(); + loop.Close(); + await t; + } + } +} \ No newline at end of file diff --git a/test/Microsoft.AspNet.Server.KestralTests/libuv.dll b/test/Microsoft.AspNet.Server.KestralTests/libuv.dll new file mode 100644 index 0000000000000000000000000000000000000000..d3a583471805a26c08d10de032d0efb67350ed3e GIT binary patch literal 317440 zcmeFa4|r6?)jxidEU@6hE|5UPs6i2;{1GK;FrZ0bH6p7UB#Mdx3N!=+gk3=-LRg}# zYg)9>YPA(DDk^Q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Pt?j90jdhtUO`nUT^s6D82wR+ zsjD|aU85sV@c?}j=0%+WlJTacQElR=3Y2Ki4alJ5=wv$G@&5}^eOwJb*3P;2I*h?7 zpysRe2J+kAFyF}=vz;n9m7E}l7v(U^$poJ62!GZCsJfq1!^<#+V`h_`0nfm!rUjVO z^f_iUZGgw#37>r!IOjC*^AE;NAiD?fa=vC6hYPE1HbAtovtP zsjGE%&`Mux0FYxkFxDub$H~Btv#t3KleHQVoT-R?<={@s@f8Io0(%qT^tIM_JAi1I3L~bFovLGumm4ktb!sKx9v(G$k o0&?X=sNL^&Z0Qc>(%7?BSi5rY{NHm8JlDW;4LsMte*q2r4;T>E Date: Mon, 2 Jun 2014 17:29:38 -0700 Subject: [PATCH 0004/1662] Marking the unit test project target framework explicitly --- test/Microsoft.AspNet.Server.KestralTests/Project.json | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/Microsoft.AspNet.Server.KestralTests/Project.json b/test/Microsoft.AspNet.Server.KestralTests/Project.json index a9db68cb96..131b7d78c1 100644 --- a/test/Microsoft.AspNet.Server.KestralTests/Project.json +++ b/test/Microsoft.AspNet.Server.KestralTests/Project.json @@ -6,6 +6,9 @@ "xunit.abstractions": "2.0.0-*", "Microsoft.AspNet.Server.Kestrel": "0.1-*" }, + "configurations": { + "net45": {} + }, "commands": { "run": "Xunit.KRunner", "test": "Xunit.KRunner" From c9d6db14bc2f20e8ef5c13e186e689d094d8f72d Mon Sep 17 00:00:00 2001 From: Louis DeJardin Date: Tue, 3 Jun 2014 16:41:55 -0700 Subject: [PATCH 0005/1662] Adding an engine, a thread manager, an accept loop --- .../Http/Listener.cs | 83 +++++++++++ .../Infrastructure/Disposable.cs | 43 ++++++ .../Infrastructure/KestrelThread.cs | 130 ++++++++++++++++++ .../KestrelEngine.cs | 65 +++++++++ .../Networking/Libuv.cs | 17 +++ .../Networking/UcAsyncHandle.cs | 4 +- .../Networking/UvHandle.cs | 16 +++ .../Networking/UvStreamHandle.cs | 95 +++++++------ .../EngineTests.cs | 30 ++++ .../NetworkingTests.cs | 16 +-- 10 files changed, 446 insertions(+), 53 deletions(-) create mode 100644 src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs create mode 100644 src/Microsoft.AspNet.Server.Kestrel/Infrastructure/Disposable.cs create mode 100644 src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs create mode 100644 src/Microsoft.AspNet.Server.Kestrel/KestrelEngine.cs create mode 100644 test/Microsoft.AspNet.Server.KestralTests/EngineTests.cs diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs new file mode 100644 index 0000000000..720db481fe --- /dev/null +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs @@ -0,0 +1,83 @@ +using Microsoft.AspNet.Server.Kestrel.Networking; +using System; +using System.Collections.Generic; +using System.Net; +using System.Text; +using System.Threading; +using System.Threading.Tasks; + +namespace Microsoft.AspNet.Server.Kestrel +{ + /// + /// Summary description for Accept + /// + public class Listener : IDisposable + { + private readonly KestrelThread _thread; + UvTcpHandle _socket; + private readonly Action _connectionCallback = ConnectionCallback; + + private static void ConnectionCallback(UvStreamHandle stream, int status, object state) + { + ((Listener)state).OnConnection(stream, status); + } + + public Listener(KestrelThread thread) + { + _thread = thread; + } + + public Task StartAsync() + { + var tcs = new TaskCompletionSource(); + _thread.Post(OnStart, tcs); + return tcs.Task; + } + + public void OnStart(object parameter) + { + var tcs = (TaskCompletionSource)parameter; + try + { + _socket = new UvTcpHandle(); + _socket.Init(_thread.Loop); + _socket.Bind(new IPEndPoint(IPAddress.Any, 4001)); + _socket.Listen(10, _connectionCallback, this); + tcs.SetResult(0); + } + catch (Exception ex) + { + tcs.SetException(ex); + } + } + + private void OnConnection(UvStreamHandle socket, int status) + { + var connection = new UvTcpHandle(); + connection.Init(_thread.Loop); + socket.Accept(connection); + connection.ReadStart(OnRead, null); + } + + private void OnRead(UvStreamHandle socket, int count, byte[] data, object _) + { + var text = Encoding.UTF8.GetString(data); + if (count <= 0) + { + socket.Close(); + } + } + + public void Dispose() + { + var socket = _socket; + _socket = null; + _thread.Post(OnDispose, socket); + } + + private void OnDispose(object socket) + { + ((UvHandle)socket).Close(); + } + } +} diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/Disposable.cs b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/Disposable.cs new file mode 100644 index 0000000000..9bb2a7f4bd --- /dev/null +++ b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/Disposable.cs @@ -0,0 +1,43 @@ +using System; + +namespace Microsoft.AspNet.Server.Kestrel +{ + /// + /// Summary description for Disposable + /// + public class Disposable : IDisposable + { + private Action _dispose; + + public Disposable(Action dispose) + { + _dispose = dispose; + } + + #region IDisposable Support + private bool disposedValue = false; // To detect redundant calls + + protected virtual void Dispose(bool disposing) + { + if (!disposedValue) + { + if (disposing) + { + _dispose.Invoke(); + } + + _dispose = null; + disposedValue = true; + } + } + + // This code added to correctly implement the disposable pattern. + public void Dispose() + { + // Do not change this code. Put cleanup code in Dispose(bool disposing) above. + Dispose(true); + GC.SuppressFinalize(this); + } + #endregion + } +} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs new file mode 100644 index 0000000000..83dd84a4a5 --- /dev/null +++ b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs @@ -0,0 +1,130 @@ +using Microsoft.AspNet.Server.Kestrel.Networking; +using System; +using System.Collections.Generic; +using System.Threading; +using System.Threading.Tasks; + +namespace Microsoft.AspNet.Server.Kestrel +{ + /// + /// Summary description for KestrelThread + /// + public class KestrelThread + { + KestrelEngine _engine; + Thread _thread; + UvLoopHandle _loop; + UvAsyncHandle _post; + Queue _workAdding = new Queue(); + Queue _workRunning = new Queue(); + object _workSync = new Object(); + bool _stopImmediate = false; + + public KestrelThread(KestrelEngine engine) + { + _engine = engine; + _loop = new UvLoopHandle(); + _post = new UvAsyncHandle(); + _thread = new Thread(ThreadStart); + } + + public UvLoopHandle Loop { get { return _loop; } } + + public Task StartAsync() + { + var tcs = new TaskCompletionSource(); + _thread.Start(tcs); + return tcs.Task; + } + + public void Stop(TimeSpan timeout) + { + Post(OnStop, null); + if (!_thread.Join(timeout)) + { + Post(OnStopImmediate, null); + if (!_thread.Join(timeout)) + { + _thread.Abort(); + } + } + } + + private void OnStop(object obj) + { + _post.Unreference(); + } + + private void OnStopImmediate(object obj) + { + _stopImmediate = true; + _loop.Stop(); + } + + public void Post(Action callback, object state) + { + lock (_workSync) + { + _workAdding.Enqueue(new Work { Callback = callback, State = state }); + } + _post.Send(); + } + + private void ThreadStart(object parameter) + { + var tcs = (TaskCompletionSource)parameter; + try + { + _loop.Init(_engine.Libuv); + _post.Init(_loop, OnPost); + tcs.SetResult(0); + } + catch (Exception ex) + { + tcs.SetException(ex); + } + var ran1 = _loop.Run(); + if (_stopImmediate) + { + // thread-abort form of exit, resources will be leaked + return; + } + + // run the loop one more time to delete the _post handle + _post.Reference(); + _post.Close(); + var ran2 = _loop.Run(); + + // delete the last of the unmanaged memory + _loop.Close(); + } + + private void OnPost() + { + var queue = _workAdding; + lock (_workSync) + { + _workAdding = _workRunning; + } + _workRunning = queue; + while (queue.Count != 0) + { + var work = queue.Dequeue(); + try + { + work.Callback(work.State); + } + catch (Exception ex) + { + //TODO: unhandled exceptions + } + } + } + + private struct Work + { + public Action Callback; + public object State; + } + } +} diff --git a/src/Microsoft.AspNet.Server.Kestrel/KestrelEngine.cs b/src/Microsoft.AspNet.Server.Kestrel/KestrelEngine.cs new file mode 100644 index 0000000000..b404d6eb63 --- /dev/null +++ b/src/Microsoft.AspNet.Server.Kestrel/KestrelEngine.cs @@ -0,0 +1,65 @@ + +using System; +using Microsoft.AspNet.Server.Kestrel.Networking; +using System.Threading; +using System.Collections.Generic; +using System.Threading.Tasks; + +namespace Microsoft.AspNet.Server.Kestrel +{ + public class KestrelEngine + { + + public KestrelEngine() + { + Threads = new List(); + Listeners = new List(); + Libuv = new Libuv(); + Libuv.Load("libuv.dll"); + } + + public Libuv Libuv { get; private set; } + public List Threads { get; private set; } + public List Listeners { get; private set; } + + public void Start(int count) + { + for (var index = 0; index != count; ++index) + { + Threads.Add(new KestrelThread(this)); + } + + foreach (var thread in Threads) + { + thread.StartAsync().Wait(); + } + } + + public void Stop() + { + foreach (var thread in Threads) + { + thread.Stop(TimeSpan.FromSeconds(45)); + } + Threads.Clear(); + } + + public IDisposable CreateServer() + { + var listeners = new List(); + foreach (var thread in Threads) + { + var listener = new Listener(thread); + listener.StartAsync().Wait(); + listeners.Add(listener); + } + return new Disposable(() => + { + foreach (var listener in listeners) + { + listener.Dispose(); + } + }); + } + } +} diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/Libuv.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/Libuv.cs index 2431574d4e..17a2299a44 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/Libuv.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/Libuv.cs @@ -78,6 +78,23 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking _uv_stop(handle); } + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + delegate void uv_ref(UvHandle handle); + uv_ref _uv_ref; + public void @ref(UvHandle handle) + { + _uv_ref(handle); + } + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + delegate void uv_unref(UvHandle handle); + uv_unref _uv_unref; + public void unref(UvHandle handle) + { + _uv_unref(handle); + } + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] public delegate void uv_close_cb(IntPtr handle); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/UcAsyncHandle.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/UcAsyncHandle.cs index 6d8f919abb..d09b815e75 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/UcAsyncHandle.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/UcAsyncHandle.cs @@ -12,9 +12,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking unsafe static void AsyncCb(IntPtr handle) { - GCHandle gcHandle = GCHandle.FromIntPtr(*(IntPtr*)handle); - var self = (UvAsyncHandle)gcHandle.Target; - self._callback.Invoke(); + FromIntPtr(handle)._callback.Invoke(); } private Action _callback; diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvHandle.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvHandle.cs index d03240e45c..033c649484 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvHandle.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvHandle.cs @@ -54,5 +54,21 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking } Marshal.FreeCoTaskMem(memory); } + + unsafe public static THandle FromIntPtr(IntPtr handle) + { + GCHandle gcHandle = GCHandle.FromIntPtr(*(IntPtr*)handle); + return (THandle)gcHandle.Target; + } + + public void Reference() + { + _uv.@ref(this); + } + + public void Unreference() + { + _uv.unref(this); + } } } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvStreamHandle.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvStreamHandle.cs index 1436852863..e4d33aa849 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvStreamHandle.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvStreamHandle.cs @@ -8,24 +8,25 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking { public abstract class UvStreamHandle : UvHandle { - private Libuv.uv_connection_cb _connection_cb; - private Libuv.uv_alloc_cb _alloc_cb; - private Libuv.uv_read_cb _read_cb; + private readonly static Libuv.uv_connection_cb _uv_connection_cb = UvConnectionCb; + private readonly static Libuv.uv_alloc_cb _uv_alloc_cb = UvAllocCb; + private readonly static Libuv.uv_read_cb _uv_read_cb = UvReadCb; - private Action _connection; - private Action _alloc; - private Action _read; + public Action _connectionCallback; + public object _connectionState; - public void Listen(int backlog, Action connection) + public Action _readCallback; + public object _readState; + + public UvStreamHandle() { - _connection_cb = OnConnection; - _connection = connection; - _uv.listen(this, 10, _connection_cb); } - public void OnConnection(IntPtr server, int status) + public void Listen(int backlog, Action callback, object state) { - _connection(status, this); + _connectionCallback = callback; + _connectionState = state; + _uv.listen(this, 10, _uv_connection_cb); } public void Accept(UvStreamHandle handle) @@ -33,42 +34,52 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking _uv.accept(this, handle); } - public void ReadStart(Action read) + public void ReadStart( + Action callback, + object state) { - _alloc_cb = OnAlloc; - _read_cb = OnRead; - _read = read; - _uv.read_start(this, _alloc_cb, _read_cb); - } - - private void OnAlloc(IntPtr server, int suggested_size, out Libuv.uv_buf_t buf) - { - buf = new Libuv.uv_buf_t - { - memory = Marshal.AllocCoTaskMem(suggested_size), - len = (uint)suggested_size, - }; - } - - private void OnRead(IntPtr server, int nread, ref Libuv.uv_buf_t buf) - { - if (nread == -4095) - { - _read(0, null, this); - Marshal.FreeCoTaskMem(buf.memory); - return; - } - var length = _uv.Check(nread); - var data = new byte[length]; - Marshal.Copy(buf.memory, data, 0, length); - Marshal.FreeCoTaskMem(buf.memory); - - _read(length, data, this); + _readCallback = callback; + _readState = state; + _uv.read_start(this, _uv_alloc_cb, _uv_read_cb); } public void ReadStop() { _uv.read_stop(this); } + + private static void UvConnectionCb(IntPtr handle, int status) + { + var stream = FromIntPtr(handle); + stream._connectionCallback(stream, status, stream._connectionState); + } + + private static void UvAllocCb(IntPtr server, int suggested_size, out Libuv.uv_buf_t buf) + { + buf = new Libuv.uv_buf_t + { + memory = Marshal.AllocCoTaskMem(suggested_size), + len = (uint)suggested_size, + }; + + } + + private static void UvReadCb(IntPtr ptr, int nread, ref Libuv.uv_buf_t buf) + { + var stream = FromIntPtr(ptr); + if (nread == -4095) + { + stream._readCallback(stream, 0, null, stream._readState); + Marshal.FreeCoTaskMem(buf.memory); + return; + } + + var length = stream._uv.Check(nread); + var data = new byte[length]; + Marshal.Copy(buf.memory, data, 0, length); + Marshal.FreeCoTaskMem(buf.memory); + + stream._readCallback(stream, length, data, stream._readState); + } } } diff --git a/test/Microsoft.AspNet.Server.KestralTests/EngineTests.cs b/test/Microsoft.AspNet.Server.KestralTests/EngineTests.cs new file mode 100644 index 0000000000..3287054606 --- /dev/null +++ b/test/Microsoft.AspNet.Server.KestralTests/EngineTests.cs @@ -0,0 +1,30 @@ +using Microsoft.AspNet.Server.Kestrel; +using System; +using System.Threading.Tasks; +using Xunit; + +namespace Microsoft.AspNet.Server.KestralTests +{ + /// + /// Summary description for EngineTests + /// + public class EngineTests + { + [Fact] + public async Task EngineCanStartAndStop() + { + var engine = new KestrelEngine(); + engine.Start(1); + engine.Stop(); + } + [Fact] + public async Task ListenerCanCreateAndDispose() + { + var engine = new KestrelEngine(); + engine.Start(1); + var started = engine.CreateServer(); + started.Dispose(); + engine.Stop(); + } + } +} \ No newline at end of file diff --git a/test/Microsoft.AspNet.Server.KestralTests/NetworkingTests.cs b/test/Microsoft.AspNet.Server.KestralTests/NetworkingTests.cs index 90e4168e28..2f17803fd4 100644 --- a/test/Microsoft.AspNet.Server.KestralTests/NetworkingTests.cs +++ b/test/Microsoft.AspNet.Server.KestralTests/NetworkingTests.cs @@ -71,14 +71,14 @@ namespace Microsoft.AspNet.Server.KestralTests var tcp = new UvTcpHandle(); tcp.Init(loop); tcp.Bind(new IPEndPoint(IPAddress.Loopback, 54321)); - tcp.Listen(10, (status, handle) => + tcp.Listen(10, (stream, status, state) => { var tcp2 = new UvTcpHandle(); tcp2.Init(loop); - tcp.Accept(tcp2); + stream.Accept(tcp2); tcp2.Close(); - tcp.Close(); - }); + stream.Close(); + }, null); var t = Task.Run(async () => { var socket = new Socket( @@ -108,21 +108,21 @@ namespace Microsoft.AspNet.Server.KestralTests var tcp = new UvTcpHandle(); tcp.Init(loop); tcp.Bind(new IPEndPoint(IPAddress.Loopback, 54321)); - tcp.Listen(10, (status, handle) => + tcp.Listen(10, (_, status, state) => { var tcp2 = new UvTcpHandle(); tcp2.Init(loop); tcp.Accept(tcp2); - tcp2.ReadStart((nread, data, handle2) => + tcp2.ReadStart((__, nread, data, state2) => { bytesRead += nread; if (nread == 0) { tcp2.Close(); } - }); + }, null); tcp.Close(); - }); + }, null); var t = Task.Run(async () => { var socket = new Socket( From e517e39aac7a2f2f143b237b556c7e490a66c121 Mon Sep 17 00:00:00 2001 From: Louis DeJardin Date: Fri, 6 Jun 2014 22:13:31 -0700 Subject: [PATCH 0006/1662] Not working, but worth taking a snapshot of the source --- KestrelHttpServer.sln | 6 + .../Http/CallContext.cs | 51 ++ .../Http/Connection.cs | 159 ++++++ .../Http/Frame.cs | 540 ++++++++++++++++++ .../Http/FrameDuplexStream.cs | 166 ++++++ .../Http/FrameRequestStream.cs | 94 +++ .../Http/FrameResponseStream.cs | 93 +++ .../Http/Listener.cs | 82 +-- .../Http/MemoryPool.cs | 154 +++++ .../Http/MemoryPoolTextWriter.cs | 155 +++++ .../Http/MessageBody.cs | 342 +++++++++++ .../Http/MessageBodyExchanger.cs | 144 +++++ .../Http/ReasonPhrases.cs | 133 +++++ .../Http/SocketInput.cs | 106 ++++ .../Http/SocketOutput.cs | 106 ++++ .../Infrastructure/Disposable.cs | 5 +- .../Infrastructure/KestrelThread.cs | 5 +- .../KestrelEngine.cs | 11 +- .../Microsoft.AspNet.Server.Kestrel.kproj | 57 ++ .../Networking/Libuv.cs | 48 ++ .../Networking/UvHandle.cs | 41 +- .../Networking/UvLoopHandle.cs | 1 - .../Networking/UvMemory.cs | 58 ++ .../Networking/UvShutdownReq.cs | 38 ++ .../Networking/UvStreamHandle.cs | 43 +- .../Networking/UvWriteRequest.cs | 57 ++ .../Project.json | 1 + src/SampleApp/Program.cs | 36 ++ src/SampleApp/SampleApp.kproj | 35 ++ src/SampleApp/libuv.dll | Bin 0 -> 317440 bytes src/SampleApp/project.json | 14 + .../EngineTests.cs | 52 +- .../MessageBodyExchangerTests.cs | 190 ++++++ .../MessageBodyTests.cs | 64 +++ ...Microsoft.AspNet.Server.KestralTests.kproj | 37 ++ .../NetworkingTests.cs | 19 +- .../TestInput.cs | 34 ++ 37 files changed, 3065 insertions(+), 112 deletions(-) create mode 100644 src/Microsoft.AspNet.Server.Kestrel/Http/CallContext.cs create mode 100644 src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs create mode 100644 src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs create mode 100644 src/Microsoft.AspNet.Server.Kestrel/Http/FrameDuplexStream.cs create mode 100644 src/Microsoft.AspNet.Server.Kestrel/Http/FrameRequestStream.cs create mode 100644 src/Microsoft.AspNet.Server.Kestrel/Http/FrameResponseStream.cs create mode 100644 src/Microsoft.AspNet.Server.Kestrel/Http/MemoryPool.cs create mode 100644 src/Microsoft.AspNet.Server.Kestrel/Http/MemoryPoolTextWriter.cs create mode 100644 src/Microsoft.AspNet.Server.Kestrel/Http/MessageBody.cs create mode 100644 src/Microsoft.AspNet.Server.Kestrel/Http/MessageBodyExchanger.cs create mode 100644 src/Microsoft.AspNet.Server.Kestrel/Http/ReasonPhrases.cs create mode 100644 src/Microsoft.AspNet.Server.Kestrel/Http/SocketInput.cs create mode 100644 src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs create mode 100644 src/Microsoft.AspNet.Server.Kestrel/Microsoft.AspNet.Server.Kestrel.kproj create mode 100644 src/Microsoft.AspNet.Server.Kestrel/Networking/UvMemory.cs create mode 100644 src/Microsoft.AspNet.Server.Kestrel/Networking/UvShutdownReq.cs create mode 100644 src/Microsoft.AspNet.Server.Kestrel/Networking/UvWriteRequest.cs create mode 100644 src/SampleApp/Program.cs create mode 100644 src/SampleApp/SampleApp.kproj create mode 100644 src/SampleApp/libuv.dll create mode 100644 src/SampleApp/project.json create mode 100644 test/Microsoft.AspNet.Server.KestralTests/MessageBodyExchangerTests.cs create mode 100644 test/Microsoft.AspNet.Server.KestralTests/MessageBodyTests.cs create mode 100644 test/Microsoft.AspNet.Server.KestralTests/Microsoft.AspNet.Server.KestralTests.kproj create mode 100644 test/Microsoft.AspNet.Server.KestralTests/TestInput.cs diff --git a/KestrelHttpServer.sln b/KestrelHttpServer.sln index 9b0ccec28c..fbfe94da08 100644 --- a/KestrelHttpServer.sln +++ b/KestrelHttpServer.sln @@ -12,6 +12,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution global.json = global.json EndProjectSection EndProject +Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "SampleApp", "src\SampleApp\SampleApp.kproj", "{2C3CB3DC-EEBF-4F52-9E1C-4F2F972E76C3}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -26,6 +28,10 @@ Global {37F3BFB2-6454-49E5-9D7F-581BF755CCFE}.Debug|Any CPU.Build.0 = Debug|Any CPU {37F3BFB2-6454-49E5-9D7F-581BF755CCFE}.Release|Any CPU.ActiveCfg = Release|Any CPU {37F3BFB2-6454-49E5-9D7F-581BF755CCFE}.Release|Any CPU.Build.0 = Release|Any CPU + {2C3CB3DC-EEBF-4F52-9E1C-4F2F972E76C3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {2C3CB3DC-EEBF-4F52-9E1C-4F2F972E76C3}.Debug|Any CPU.Build.0 = Debug|Any CPU + {2C3CB3DC-EEBF-4F52-9E1C-4F2F972E76C3}.Release|Any CPU.ActiveCfg = Release|Any CPU + {2C3CB3DC-EEBF-4F52-9E1C-4F2F972E76C3}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/CallContext.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/CallContext.cs new file mode 100644 index 0000000000..39b11b7ac3 --- /dev/null +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/CallContext.cs @@ -0,0 +1,51 @@ +// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using Microsoft.AspNet.HttpFeature; +using System; +using System.Collections.Generic; +using System.IO; + +namespace Microsoft.AspNet.Server.Kestrel +{ + /// + /// Summary description for CallContext + /// + public class CallContext : + IHttpRequestFeature, + IHttpResponseFeature + { + public CallContext() + { + ((IHttpResponseFeature)this).StatusCode = 200; + } + + Stream IHttpResponseFeature.Body { get; set; } + + Stream IHttpRequestFeature.Body { get; set; } + + IDictionary IHttpResponseFeature.Headers { get; set; } + + IDictionary IHttpRequestFeature.Headers { get; set; } + + string IHttpRequestFeature.Method { get; set; } + + string IHttpRequestFeature.Path { get; set; } + + string IHttpRequestFeature.PathBase { get; set; } + + string IHttpRequestFeature.Protocol { get; set; } + + string IHttpRequestFeature.QueryString { get; set; } + + string IHttpResponseFeature.ReasonPhrase { get; set; } + + string IHttpRequestFeature.Scheme { get; set; } + + int IHttpResponseFeature.StatusCode { get; set; } + + void IHttpResponseFeature.OnSendingHeaders(Action callback, object state) + { + } + } +} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs new file mode 100644 index 0000000000..89837db215 --- /dev/null +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs @@ -0,0 +1,159 @@ +// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Diagnostics; +using System.Net.Sockets; +using System.Threading; +using System.Threading.Tasks; +using Microsoft.AspNet.Server.Kestrel.Networking; + +namespace Microsoft.AspNet.Server.Kestrel.Http +{ + public class ConnectionContext : ListenerContext + { + public ConnectionContext() + { + } + + public ConnectionContext(ListenerContext context) : base(context) + { + } + + public SocketInput SocketInput { get; set; } + public ISocketOutput SocketOutput { get; set; } + + public IConnectionControl ConnectionControl { get; set; } + } + + public interface IConnectionControl + { + void Pause(); + void Resume(); + void End(ProduceEndType endType); + } + + public class Connection : ConnectionContext, IConnectionControl + { + private static readonly Action _readCallback = ReadCallback; + private static readonly Func _allocCallback = AllocCallback; + + private static Libuv.uv_buf_t AllocCallback(UvStreamHandle handle, int suggestedSize, object state) + { + return ((Connection)state).OnAlloc(handle, suggestedSize); + } + + private static void ReadCallback(UvStreamHandle handle, int nread, object state) + { + ((Connection)state).OnRead(handle, nread); + } + + + private readonly Func _app; + private readonly UvStreamHandle _socket; + + private Frame _frame; + + private Action _fault; + private Action _frameConsumeCallback; + private Action _receiveAsyncCompleted; + private Frame _receiveAsyncCompletedFrame; + + public Connection(ListenerContext context, UvStreamHandle socket) : base(context) + { + _socket = socket; + ConnectionControl = this; + } + + public void Start() + { + //_services.Trace.Event(TraceEventType.Start, TraceMessage.Connection); + + SocketInput = new SocketInput(Memory); + SocketOutput = new SocketOutput(Thread, _socket); + + _socket.ReadStart(_allocCallback, _readCallback, this); + + //_fault = ex => { Debug.WriteLine(ex.Message); }; + + //_frameConsumeCallback = (frame, error) => + //{ + // if (error != null) + // { + // _fault(error); + // } + // try + // { + // Go(false, frame); + // } + // catch (Exception ex) + // { + // _fault(ex); + // } + //}; + + //try + //{ + // //_socket.Blocking = false; + // //_socket.NoDelay = true; + // Go(true, null); + //} + //catch (Exception ex) + //{ + // _fault(ex); + //} + } + + private Libuv.uv_buf_t OnAlloc(UvStreamHandle handle, int suggestedSize) + { + return new Libuv.uv_buf_t + { + memory = SocketInput.Pin(2048), + len = 2048 + }; + } + + private void OnRead(UvStreamHandle handle, int nread) + { + SocketInput.Unpin(nread); + + if (nread == 0) + { + SocketInput.RemoteIntakeFin = true; + } + + if (_frame == null) + { + _frame = new Frame(this); + } + _frame.Consume(); + } + + void IConnectionControl.Pause() + { + _socket.ReadStop(); + } + + void IConnectionControl.Resume() + { + _socket.ReadStart(_allocCallback, _readCallback, this); + } + + void IConnectionControl.End(ProduceEndType endType) + { + switch (endType) + { + case ProduceEndType.SocketShutdownSend: + var shutdown = new UvShutdownReq(); + shutdown.Init(Thread.Loop); + shutdown.Shutdown(_socket, (req, status, state) => req.Close(), null); + break; + case ProduceEndType.ConnectionKeepAlive: + break; + case ProduceEndType.SocketDisconnect: + _socket.Close(); + break; + } + } + } +} diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs new file mode 100644 index 0000000000..0697149351 --- /dev/null +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs @@ -0,0 +1,540 @@ +// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using Microsoft.AspNet.HttpFeature; +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Net; +using System.Text; +using System.Threading.Tasks; + +// ReSharper disable AccessToModifiedClosure + +namespace Microsoft.AspNet.Server.Kestrel.Http +{ + + public enum ProduceEndType + { + SocketShutdownSend, + SocketDisconnect, + ConnectionKeepAlive, + } + + public class Frame + { + private ConnectionContext _context; + + Mode _mode; + + enum Mode + { + StartLine, + MessageHeader, + MessageBody, + Terminated, + } + + + private string _method; + private string _requestUri; + private string _path; + private string _queryString; + private string _httpVersion; + + private readonly IDictionary _requestHeaders = + new Dictionary(StringComparer.OrdinalIgnoreCase); + + readonly IDictionary _responseHeaders = + new Dictionary(StringComparer.OrdinalIgnoreCase); + + private MessageBody _messageBody; + private bool _resultStarted; + private bool _keepAlive; + + private CallContext _callContext; + /* + //IDictionary _environment; + + CancellationTokenSource _cts = new CancellationTokenSource(); + */ + FrameResponseStream _outputStream; + FrameRequestStream _inputStream; + FrameDuplexStream _duplexStream; + + Task _upgradeTask = _completedTask; + static readonly Task _completedTask = Task.FromResult(0); + + public Frame(ConnectionContext context) + { + _context = context; + } + /* + public bool LocalIntakeFin + { + get + { + return _mode == Mode.MessageBody + ? _messageBody.LocalIntakeFin + : _mode == Mode.Terminated; + } + } + */ + public void Consume() + { + var input = _context.SocketInput; + for (; ;) + { + switch (_mode) + { + case Mode.StartLine: + if (input.RemoteIntakeFin) + { + _mode = Mode.Terminated; + return; + } + + if (!TakeStartLine(input)) + { + return; + } + + _mode = Mode.MessageHeader; + break; + + case Mode.MessageHeader: + if (input.RemoteIntakeFin) + { + _mode = Mode.Terminated; + return; + } + + var endOfHeaders = false; + while (!endOfHeaders) + { + if (!TakeMessageHeader(input, out endOfHeaders)) + { + return; + } + } + + //var resumeBody = HandleExpectContinue(callback); + Execute(); + _mode = Mode.MessageBody; + break; + + case Mode.MessageBody: + _messageBody.Consume(); + // NOTE: keep looping? + return; + + case Mode.Terminated: + return; + } + } + } + + Action HandleExpectContinue(Action continuation) + { + string[] expect; + if (_httpVersion.Equals("HTTP/1.1") && + _requestHeaders.TryGetValue("Expect", out expect) && + (expect.FirstOrDefault() ?? "").Equals("100-continue", StringComparison.OrdinalIgnoreCase)) + { + return (frame, error) => + { + if (_resultStarted) + { + continuation.Invoke(frame, error); + } + else + { + var bytes = Encoding.Default.GetBytes("HTTP/1.1 100 Continue\r\n\r\n"); + + //var isasync = _context.SocketOutput.Write( + // new ArraySegment(bytes), + // error2 => continuation(frame, error2)); + + //if (!isasync) + //{ + // continuation.Invoke(frame, null); + //} + } + }; + } + return continuation; + } + + private void Execute() + { + _messageBody = MessageBody.For( + _httpVersion, + _requestHeaders, + _context); + _keepAlive = _messageBody.RequestKeepAlive; + _callContext = CreateCallContext(); + _context.SocketInput.Free(); + Task.Run(ExecuteAsync); + } + + private async Task ExecuteAsync() + { + Exception error = null; + try + { + await _context.Application.Invoke(_callContext); + await _upgradeTask; + } + catch (Exception ex) + { + error = ex; + } + finally + { + ProduceEnd(error); + } + } + + private CallContext CreateCallContext() + { + _inputStream = new FrameRequestStream(_messageBody); + _outputStream = new FrameResponseStream(OnWrite); + _duplexStream = new FrameDuplexStream(_inputStream, _outputStream); + + var remoteIpAddress = "127.0.0.1"; + var remotePort = "0"; + var localIpAddress = "127.0.0.1"; + var localPort = "80"; + var isLocal = false; + + //if (_context.Socket != null) + //{ + // var remoteEndPoint = _context.Socket.RemoteEndPoint as IPEndPoint; + // if (remoteEndPoint != null) + // { + // remoteIpAddress = remoteEndPoint.Address.ToString(); + // remotePort = remoteEndPoint.Port.ToString(CultureInfo.InvariantCulture); + // } + + // var localEndPoint = _context.Socket.LocalEndPoint as IPEndPoint; + // if (localEndPoint != null) + // { + // localIpAddress = localEndPoint.Address.ToString(); + // localPort = localEndPoint.Port.ToString(CultureInfo.InvariantCulture); + // } + + // if (remoteEndPoint != null && localEndPoint != null) + // { + // isLocal = Equals(remoteEndPoint.Address, localEndPoint.Address); + // } + //} + + var callContext = new CallContext(); + var request = (IHttpRequestFeature)callContext; + var response = (IHttpResponseFeature)callContext; + //var lifetime = (IHttpRequestLifetimeFeature)callContext; + request.Protocol = _httpVersion; + request.Scheme = "http"; + request.Method = _method; + request.Path = _path; + request.PathBase = ""; + request.QueryString = _queryString; + request.Headers = _requestHeaders; + request.Body = _inputStream; + response.Headers = _responseHeaders; + response.Body = _outputStream; + + //var env = new Dictionary(); + //env["owin.Version"] = "1.0"; + //env["owin.RequestProtocol"] = _httpVersion; + //env["owin.RequestScheme"] = "http"; + //env["owin.RequestMethod"] = _method; + //env["owin.RequestPath"] = _path; + //env["owin.RequestPathBase"] = ""; + //env["owin.RequestQueryString"] = _queryString; + //env["owin.RequestHeaders"] = _requestHeaders; + //env["owin.RequestBody"] = _inputStream; + //env["owin.ResponseHeaders"] = _responseHeaders; + //env["owin.ResponseBody"] = _outputStream; + //env["owin.CallCancelled"] = _cts.Token; + //env["opaque.Upgrade"] = (Action, Func, Task>>)Upgrade; + //env["opaque.Stream"] = _duplexStream; + //env["server.RemoteIpAddress"] = remoteIpAddress; + //env["server.RemotePort"] = remotePort; + //env["server.LocalIpAddress"] = localIpAddress; + //env["server.LocalPort"] = localPort; + //env["server.IsLocal"] = isLocal; + return callContext; + } + + void OnWrite(ArraySegment data, Action callback, object state) + { + ProduceStart(); + _context.SocketOutput.Write(data, callback, state); + } + + void Upgrade(IDictionary options, Func callback) + { + _keepAlive = false; + ProduceStart(); + + _upgradeTask = callback(_callContext); + } + + void ProduceStart() + { + if (_resultStarted) return; + + _resultStarted = true; + + var response = (IHttpResponseFeature)_callContext; + var status = ReasonPhrases.ToStatus( + response.StatusCode, + response.ReasonPhrase); + + var responseHeader = CreateResponseHeader(status, _responseHeaders); + _context.SocketOutput.Write(responseHeader.Item1, x => ((IDisposable)x).Dispose(), responseHeader.Item2); + } + + private void ProduceEnd(Exception ex) + { + ProduceStart(); + + if (!_keepAlive) + { + _context.ConnectionControl.End(ProduceEndType.SocketShutdownSend); + } + + _messageBody.Drain(() => + _context.ConnectionControl.End(_keepAlive ? ProduceEndType.ConnectionKeepAlive : ProduceEndType.SocketDisconnect)); + } + + + private Tuple, IDisposable> CreateResponseHeader( + string status, IEnumerable> headers) + { + var writer = new MemoryPoolTextWriter(_context.Memory); + writer.Write(_httpVersion); + writer.Write(' '); + writer.Write(status); + writer.Write('\r'); + writer.Write('\n'); + + var hasConnection = false; + var hasTransferEncoding = false; + var hasContentLength = false; + if (headers != null) + { + foreach (var header in headers) + { + var isConnection = false; + if (!hasConnection && + string.Equals(header.Key, "Connection", StringComparison.OrdinalIgnoreCase)) + { + hasConnection = isConnection = true; + } + else if (!hasTransferEncoding && + string.Equals(header.Key, "Transfer-Encoding", StringComparison.OrdinalIgnoreCase)) + { + hasTransferEncoding = true; + } + else if (!hasContentLength && + string.Equals(header.Key, "Content-Length", StringComparison.OrdinalIgnoreCase)) + { + hasContentLength = true; + } + + foreach (var value in header.Value) + { + writer.Write(header.Key); + writer.Write(':'); + writer.Write(' '); + writer.Write(value); + writer.Write('\r'); + writer.Write('\n'); + + if (isConnection && value.IndexOf("close", StringComparison.OrdinalIgnoreCase) != -1) + { + _keepAlive = false; + } + } + } + } + + if (hasTransferEncoding == false && hasContentLength == false) + { + _keepAlive = false; + } + if (_keepAlive == false && hasConnection == false && _httpVersion == "HTTP/1.1") + { + writer.Write("Connection: close\r\n\r\n"); + } + else if (_keepAlive && hasConnection == false && _httpVersion == "HTTP/1.0") + { + writer.Write("Connection: keep-alive\r\n\r\n"); + } + else + { + writer.Write('\r'); + writer.Write('\n'); + } + writer.Flush(); + return new Tuple, IDisposable>(writer.Buffer, writer); + } + + private bool TakeStartLine(SocketInput baton) + { + var remaining = baton.Buffer; + if (remaining.Count < 2) + { + return false; + } + var firstSpace = -1; + var secondSpace = -1; + var questionMark = -1; + var ch0 = remaining.Array[remaining.Offset]; + for (var index = 0; index != remaining.Count - 1; ++index) + { + var ch1 = remaining.Array[remaining.Offset + index + 1]; + if (ch0 == '\r' && ch1 == '\n') + { + if (secondSpace == -1) + { + throw new InvalidOperationException("INVALID REQUEST FORMAT"); + } + _method = GetString(remaining, 0, firstSpace); + _requestUri = GetString(remaining, firstSpace + 1, secondSpace); + if (questionMark == -1) + { + _path = _requestUri; + _queryString = string.Empty; + } + else + { + _path = GetString(remaining, firstSpace + 1, questionMark); + _queryString = GetString(remaining, questionMark, secondSpace); + } + _httpVersion = GetString(remaining, secondSpace + 1, index); + baton.Skip(index + 2); + return true; + } + + if (ch0 == ' ' && firstSpace == -1) + { + firstSpace = index; + } + else if (ch0 == ' ' && firstSpace != -1 && secondSpace == -1) + { + secondSpace = index; + } + else if (ch0 == '?' && firstSpace != -1 && questionMark == -1 && secondSpace == -1) + { + questionMark = index; + } + ch0 = ch1; + } + return false; + } + + static string GetString(ArraySegment range, int startIndex, int endIndex) + { + return Encoding.Default.GetString(range.Array, range.Offset + startIndex, endIndex - startIndex); + } + + + private bool TakeMessageHeader(SocketInput baton, out bool endOfHeaders) + { + var remaining = baton.Buffer; + endOfHeaders = false; + if (remaining.Count < 2) + { + return false; + } + var ch0 = remaining.Array[remaining.Offset]; + var ch1 = remaining.Array[remaining.Offset + 1]; + if (ch0 == '\r' && ch1 == '\n') + { + endOfHeaders = true; + baton.Skip(2); + return true; + } + + if (remaining.Count < 3) + { + return false; + } + var wrappedHeaders = false; + var colonIndex = -1; + var valueStartIndex = -1; + var valueEndIndex = -1; + for (var index = 0; index != remaining.Count - 2; ++index) + { + var ch2 = remaining.Array[remaining.Offset + index + 2]; + if (ch0 == '\r' && + ch1 == '\n' && + ch2 != ' ' && + ch2 != '\t') + { + var name = Encoding.ASCII.GetString(remaining.Array, remaining.Offset, colonIndex); + var value = ""; + if (valueEndIndex != -1) + { + value = Encoding.ASCII.GetString( + remaining.Array, remaining.Offset + valueStartIndex, valueEndIndex - valueStartIndex); + } + if (wrappedHeaders) + { + value = value.Replace("\r\n", " "); + } + AddRequestHeader(name, value); + baton.Skip(index + 2); + return true; + } + if (colonIndex == -1 && ch0 == ':') + { + colonIndex = index; + } + else if (colonIndex != -1 && + ch0 != ' ' && + ch0 != '\t' && + ch0 != '\r' && + ch0 != '\n') + { + if (valueStartIndex == -1) + { + valueStartIndex = index; + } + valueEndIndex = index + 1; + } + else if (!wrappedHeaders && + ch0 == '\r' && + ch1 == '\n' && + (ch2 == ' ' || + ch2 == '\t')) + { + wrappedHeaders = true; + } + + ch0 = ch1; + ch1 = ch2; + } + return false; + } + + private void AddRequestHeader(string name, string value) + { + string[] existing; + if (!_requestHeaders.TryGetValue(name, out existing) || + existing == null || + existing.Length == 0) + { + _requestHeaders[name] = new[] { value }; + } + else + { + _requestHeaders[name] = existing.Concat(new[] { value }).ToArray(); + } + } + } +} diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameDuplexStream.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameDuplexStream.cs new file mode 100644 index 0000000000..7028eacdb4 --- /dev/null +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameDuplexStream.cs @@ -0,0 +1,166 @@ +// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.IO; + +namespace Microsoft.AspNet.Server.Kestrel.Http +{ + class FrameDuplexStream : Stream + { + readonly FrameRequestStream _requestStream; + readonly FrameResponseStream _responseStream; + + public FrameDuplexStream(FrameRequestStream requestStream, FrameResponseStream responseStream) + { + _requestStream = requestStream; + _responseStream = responseStream; + } + + public override void Close() + { + _requestStream.Close(); + _responseStream.Close(); + } + + protected override void Dispose(bool disposing) + { + if (disposing) + { + _requestStream.Dispose(); + _responseStream.Dispose(); + } + } + + public override void Flush() + { + _responseStream.Flush(); + } + + public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback callback, object state) + { + return _requestStream.BeginRead(buffer, offset, count, callback, state); + } + + public override int EndRead(IAsyncResult asyncResult) + { + return _requestStream.EndRead(asyncResult); + } + + public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback callback, object state) + { + return _responseStream.BeginWrite(buffer, offset, count, callback, state); + } + + public override void EndWrite(IAsyncResult asyncResult) + { + _responseStream.EndWrite(asyncResult); + } + + public override long Seek(long offset, SeekOrigin origin) + { + return _requestStream.Seek(offset, origin); + } + + public override void SetLength(long value) + { + _requestStream.SetLength(value); + } + + public override int Read(byte[] buffer, int offset, int count) + { + return _requestStream.Read(buffer, offset, count); + } + + public override int ReadByte() + { + return _requestStream.ReadByte(); + } + + public override void Write(byte[] buffer, int offset, int count) + { + _responseStream.Write(buffer, offset, count); + } + + public override void WriteByte(byte value) + { + _responseStream.WriteByte(value); + } + + public override bool CanRead + { + get + { + return _requestStream.CanRead; + } + } + + public override bool CanSeek + { + get + { + return _requestStream.CanSeek; + } + } + + public override bool CanTimeout + { + get + { + return _responseStream.CanTimeout || _requestStream.CanTimeout; + } + } + + public override bool CanWrite + { + get + { + return _responseStream.CanWrite; + } + } + + public override long Length + { + get + { + return _requestStream.Length; + } + } + + public override long Position + { + get + { + return _requestStream.Position; + } + set + { + _requestStream.Position = value; + } + } + + public override int ReadTimeout + { + get + { + return _requestStream.ReadTimeout; + } + set + { + _requestStream.ReadTimeout = value; + } + } + + public override int WriteTimeout + { + get + { + return _responseStream.WriteTimeout; + } + set + { + _responseStream.WriteTimeout = value; + } + } + } +} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameRequestStream.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameRequestStream.cs new file mode 100644 index 0000000000..16a4c90920 --- /dev/null +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameRequestStream.cs @@ -0,0 +1,94 @@ +// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.IO; +using System.Threading; +using System.Threading.Tasks; + +namespace Microsoft.AspNet.Server.Kestrel.Http +{ + public class FrameRequestStream : Stream + { + readonly MessageBody _body; + + //int _readLength; + //bool _readFin; + //Exception _readError; + + public FrameRequestStream(MessageBody body) + { + _body = body; + } + + public override void Flush() + { + throw new NotImplementedException(); + } + + public override long Seek(long offset, SeekOrigin origin) + { + throw new NotImplementedException(); + } + + public override void SetLength(long value) + { + throw new NotImplementedException(); + } + + public override int Read(byte[] buffer, int offset, int count) + { + return ReadAsync(buffer, offset, count).Result; + } + + public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback callback, object state) + { + var task = ReadAsync(buffer, offset, count, CancellationToken.None, state); + if (callback != null) + { + task.ContinueWith(t => callback.Invoke(t)); + } + return task; + } + + public override int EndRead(IAsyncResult asyncResult) + { + return ((Task)asyncResult).Result; + } + + public override Task ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) + { + return _body.ReadAsync(new ArraySegment(buffer, offset, count)); + } + + public Task ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken, object state) + { + //NOTE todo + throw new NotImplementedException(); + //var tcs = new TaskCompletionSource(state); + //_body.ReadAsync(new ArraySegment(buffer, offset, count)); + //return tcs.Task; + } + + public override void Write(byte[] buffer, int offset, int count) + { + throw new NotImplementedException(); + } + + public override bool CanRead { get { return true; } } + + public override bool CanSeek { get { return false; } } + + public override bool CanWrite { get { return false; } } + + public override long Length + { + get + { + throw new NotImplementedException(); + } + } + + public override long Position { get; set; } + } +} diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameResponseStream.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameResponseStream.cs new file mode 100644 index 0000000000..d4b34fbce6 --- /dev/null +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameResponseStream.cs @@ -0,0 +1,93 @@ +// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.IO; +using System.Threading; +using System.Threading.Tasks; + +namespace Microsoft.AspNet.Server.Kestrel.Http +{ + class FrameResponseStream : Stream + { + readonly Action, Action, object> _write; + + public FrameResponseStream(Action, Action, object> write) + { + _write = write; + } + + public override void Flush() + { + //_write(default(ArraySegment), null); + } + + public override Task FlushAsync(CancellationToken cancellationToken) + { + var tcs = new TaskCompletionSource(); + _write(new ArraySegment(new byte[0]), x => ((TaskCompletionSource)x).SetResult(0), tcs); + return tcs.Task; + } + + public override long Seek(long offset, SeekOrigin origin) + { + throw new NotImplementedException(); + } + + public override void SetLength(long value) + { + throw new NotImplementedException(); + } + + public override int Read(byte[] buffer, int offset, int count) + { + throw new NotImplementedException(); + } + + public override void Write(byte[] buffer, int offset, int count) + { + throw new NotImplementedException(); + } + + public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) + { + var tcs = new TaskCompletionSource(); + _write(new ArraySegment(buffer, offset, count), x => ((TaskCompletionSource)x).SetResult(0), tcs); + return tcs.Task; + } + + public override bool CanRead + { + get + { + return false; + } + } + + public override bool CanSeek + { + get + { + return false; + } + } + + public override bool CanWrite + { + get + { + return true; + } + } + + public override long Length + { + get + { + throw new NotImplementedException(); + } + } + + public override long Position { get; set; } + } +} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs index 720db481fe..95995f9100 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs @@ -1,36 +1,58 @@ -using Microsoft.AspNet.Server.Kestrel.Networking; +// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using Microsoft.AspNet.Server.Kestrel.Networking; using System; -using System.Collections.Generic; using System.Net; using System.Text; -using System.Threading; using System.Threading.Tasks; -namespace Microsoft.AspNet.Server.Kestrel +namespace Microsoft.AspNet.Server.Kestrel.Http { + public class ListenerContext + { + public ListenerContext() { } + + public ListenerContext(ListenerContext context) + { + Thread = context.Thread; + Application = context.Application; + Memory = context.Memory; + } + + public KestrelThread Thread { get; set; } + + public Func Application { get; set; } + + public IMemoryPool Memory { get; set; } + } + /// /// Summary description for Accept /// - public class Listener : IDisposable + public class Listener : ListenerContext, IDisposable { - private readonly KestrelThread _thread; - UvTcpHandle _socket; - private readonly Action _connectionCallback = ConnectionCallback; + private static readonly Action _connectionCallback = ConnectionCallback; + + UvTcpHandle ListenSocket { get; set; } private static void ConnectionCallback(UvStreamHandle stream, int status, object state) { ((Listener)state).OnConnection(stream, status); } - public Listener(KestrelThread thread) + public Listener(IMemoryPool memory) { - _thread = thread; + Memory = memory; } - public Task StartAsync() + public Task StartAsync(KestrelThread thread, Func app) { + Thread = thread; + Application = app; + var tcs = new TaskCompletionSource(); - _thread.Post(OnStart, tcs); + Thread.Post(OnStart, tcs); return tcs.Task; } @@ -39,10 +61,10 @@ namespace Microsoft.AspNet.Server.Kestrel var tcs = (TaskCompletionSource)parameter; try { - _socket = new UvTcpHandle(); - _socket.Init(_thread.Loop); - _socket.Bind(new IPEndPoint(IPAddress.Any, 4001)); - _socket.Listen(10, _connectionCallback, this); + ListenSocket = new UvTcpHandle(); + ListenSocket.Init(Thread.Loop); + ListenSocket.Bind(new IPEndPoint(IPAddress.Any, 4001)); + ListenSocket.Listen(10, _connectionCallback, this); tcs.SetResult(0); } catch (Exception ex) @@ -51,33 +73,25 @@ namespace Microsoft.AspNet.Server.Kestrel } } - private void OnConnection(UvStreamHandle socket, int status) + private void OnConnection(UvStreamHandle listenSocket, int status) { - var connection = new UvTcpHandle(); - connection.Init(_thread.Loop); - socket.Accept(connection); - connection.ReadStart(OnRead, null); - } + var acceptSocket = new UvTcpHandle(); + acceptSocket.Init(Thread.Loop); + listenSocket.Accept(acceptSocket); - private void OnRead(UvStreamHandle socket, int count, byte[] data, object _) - { - var text = Encoding.UTF8.GetString(data); - if (count <= 0) - { - socket.Close(); - } + var connection = new Connection(this, acceptSocket); + connection.Start(); } public void Dispose() { - var socket = _socket; - _socket = null; - _thread.Post(OnDispose, socket); + Thread.Post(OnDispose, ListenSocket); + ListenSocket = null; } - private void OnDispose(object socket) + private void OnDispose(object listenSocket) { - ((UvHandle)socket).Close(); + ((UvHandle)listenSocket).Close(); } } } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/MemoryPool.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/MemoryPool.cs new file mode 100644 index 0000000000..f97675f776 --- /dev/null +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/MemoryPool.cs @@ -0,0 +1,154 @@ +// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Collections.Generic; +using System.Net.Sockets; + +namespace Microsoft.AspNet.Server.Kestrel.Http +{ + public interface IMemoryPool + { + byte[] Empty { get; } + + byte[] AllocByte(int minimumSize); + void FreeByte(byte[] memory); + + char[] AllocChar(int minimumSize); + void FreeChar(char[] memory); + + /// + /// Acquires a sub-segment of a larger memory allocation. Used for async sends of write-behind + /// buffers to reduce number of array segments pinned + /// + /// The smallest length of the ArraySegment.Count that may be returned + /// An array segment which is a sub-block of a larger allocation + ArraySegment AllocSegment(int minimumSize); + + /// + /// Frees a sub-segment of a larger memory allocation produced by AllocSegment. The original ArraySegment + /// must be frees exactly once and must have the same offset and count that was returned by the Alloc. + /// If a segment is not freed it won't be re-used and has the same effect as a memory leak, so callers must be + /// implemented exactly correctly. + /// + /// The sub-block that was originally returned by a call to AllocSegment. + void FreeSegment(ArraySegment segment); + } + + public class MemoryPool : IMemoryPool + { + static readonly byte[] EmptyArray = new byte[0]; + + class Pool + { + readonly Stack _stack = new Stack(); + readonly object _sync = new object(); + + public T[] Alloc(int size) + { + lock (_sync) + { + if (_stack.Count != 0) + { + return _stack.Pop(); + } + } + return new T[size]; + } + + public void Free(T[] value, int limit) + { + lock (_sync) + { + if (_stack.Count < limit) + { + _stack.Push(value); + } + } + } + } + + readonly Pool _pool1 = new Pool(); + readonly Pool _pool2 = new Pool(); + readonly Pool _pool3 = new Pool(); + + public byte[] Empty + { + get + { + return EmptyArray; + } + } + + public byte[] AllocByte(int minimumSize) + { + if (minimumSize == 0) + { + return EmptyArray; + } + if (minimumSize <= 1024) + { + return _pool1.Alloc(1024); + } + if (minimumSize <= 2048) + { + return _pool2.Alloc(2048); + } + return new byte[minimumSize]; + } + + public void FreeByte(byte[] memory) + { + if (memory == null) + { + return; + } + switch (memory.Length) + { + case 1024: + _pool1.Free(memory, 256); + break; + case 2048: + _pool2.Free(memory, 64); + break; + } + } + + public char[] AllocChar(int minimumSize) + { + if (minimumSize == 0) + { + return new char[0]; + } + if (minimumSize <= 128) + { + return _pool3.Alloc(128); + } + return new char[minimumSize]; + } + + public void FreeChar(char[] memory) + { + if (memory == null) + { + return; + } + switch (memory.Length) + { + case 128: + _pool3.Free(memory, 256); + break; + } + } + + public ArraySegment AllocSegment(int minimumSize) + { + return new ArraySegment(AllocByte(minimumSize)); + } + + public void FreeSegment(ArraySegment segment) + { + FreeByte(segment.Array); + } + } +} diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/MemoryPoolTextWriter.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/MemoryPoolTextWriter.cs new file mode 100644 index 0000000000..c094178846 --- /dev/null +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/MemoryPoolTextWriter.cs @@ -0,0 +1,155 @@ +// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.IO; +using System.Text; + +namespace Microsoft.AspNet.Server.Kestrel.Http +{ + public class MemoryPoolTextWriter : TextWriter + { + private readonly IMemoryPool _memory; + + private char[] _textArray; + private int _textBegin; + private int _textEnd; + // ReSharper disable InconsistentNaming + private const int _textLength = 128; + // ReSharper restore InconsistentNaming + + private byte[] _dataArray; + private int _dataEnd; + + private readonly Encoder _encoder; + + public ArraySegment Buffer + { + get + { + return new ArraySegment(_dataArray, 0, _dataEnd); + } + } + + public MemoryPoolTextWriter(IMemoryPool memory) + { + _memory = memory; + _textArray = _memory.AllocChar(_textLength); + _dataArray = _memory.Empty; + _encoder = Encoding.Default.GetEncoder(); + } + + public override Encoding Encoding + { + get + { + return Encoding.Default; + } + } + + protected override void Dispose(bool disposing) + { + try + { + if (disposing) + { + if (_textArray != null) + { + _memory.FreeChar(_textArray); + _textArray = null; + } + if (_dataArray != null) + { + _memory.FreeByte(_dataArray); + _dataArray = null; + } + } + } + finally + { + base.Dispose(disposing); + } + } + + private void Encode(bool flush) + { + var bytesNeeded = _encoder.GetByteCount( + _textArray, + _textBegin, + _textEnd - _textBegin, + flush); + + Grow(bytesNeeded); + + var bytesUsed = _encoder.GetBytes( + _textArray, + _textBegin, + _textEnd - _textBegin, + _dataArray, + _dataEnd, + flush); + + _textBegin = _textEnd = 0; + _dataEnd += bytesUsed; + } + + private void Grow(int minimumAvailable) + { + if (_dataArray.Length - _dataEnd >= minimumAvailable) + { + return; + } + + var newLength = _dataArray.Length + Math.Max(_dataArray.Length, minimumAvailable); + var newArray = _memory.AllocByte(newLength); + Array.Copy(_dataArray, 0, newArray, 0, _dataEnd); + _memory.FreeByte(_dataArray); + _dataArray = newArray; + } + + public override void Write(char value) + { + if (_textLength == _textEnd) + { + Encode(false); + if (_textLength == _textEnd) + { + throw new InvalidOperationException("Unexplainable failure to encode text"); + } + } + + _textArray[_textEnd++] = value; + } + + public override void Write(string value) + { + var sourceIndex = 0; + var sourceLength = value.Length; + while (sourceIndex < sourceLength) + { + if (_textLength == _textEnd) + { + Encode(false); + } + + var count = sourceLength - sourceIndex; + if (count > _textLength - _textEnd) + { + count = _textLength - _textEnd; + } + + value.CopyTo(sourceIndex, _textArray, _textEnd, count); + sourceIndex += count; + _textEnd += count; + } + } + + public override void Flush() + { + while (_textBegin != _textEnd) + { + Encode(true); + } + } + } +} diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/MessageBody.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/MessageBody.cs new file mode 100644 index 0000000000..0ade9006fb --- /dev/null +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/MessageBody.cs @@ -0,0 +1,342 @@ +// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Collections.Generic; +using System.Threading; + +namespace Microsoft.AspNet.Server.Kestrel.Http +{ + public static class DelegateExtensions + { + public static void InvokeNoThrow(this Action d) + { + try + { d.Invoke(); } + catch + { } + } + public static void InvokeNoThrow(this Action d, T arg1) + { + try + { d.Invoke(arg1); } + catch + { } + } + } + + public abstract class MessageBody : MessageBodyExchanger + { + private Action _continuation = () => { }; + + public bool RequestKeepAlive { get; protected set; } + + protected MessageBody(ConnectionContext context) : base(context) + { + } + + public void Intake(int count) + { + Transfer(count, false); + } + + public void IntakeFin(int count) + { + Transfer(count, true); + if (_continuation != null) + { + _continuation.Invoke(); + } + } + + public abstract void Consume(); + + public static MessageBody For( + string httpVersion, + IDictionary headers, + ConnectionContext context) + { + // see also http://tools.ietf.org/html/rfc2616#section-4.4 + + var keepAlive = httpVersion != "HTTP/1.0"; + + string connection; + if (TryGet(headers, "Connection", out connection)) + { + keepAlive = connection.Equals("keep-alive", StringComparison.OrdinalIgnoreCase); + } + + string transferEncoding; + if (TryGet(headers, "Transfer-Encoding", out transferEncoding)) + { + return new ForChunkedEncoding(keepAlive, context); + } + + string contentLength; + if (TryGet(headers, "Content-Length", out contentLength)) + { + return new ForContentLength(keepAlive, int.Parse(contentLength), context); + } + + if (keepAlive) + { + return new ForContentLength(true, 0, context); + } + + return new ForRemainingData(context); + } + + public static bool TryGet(IDictionary headers, string name, out string value) + { + string[] values; + if (!headers.TryGetValue(name, out values) || values == null) + { + value = null; + return false; + } + var count = values.Length; + if (count == 0) + { + value = null; + return false; + } + if (count == 1) + { + value = values[0]; + return true; + } + value = String.Join(",", values); + return true; + } + + public void Drain(Action continuation) + { + _continuation = continuation; + _continuation.Invoke(); + } + + + class ForRemainingData : MessageBody + { + public ForRemainingData(ConnectionContext context) + : base(context) + { + } + + public override void Consume() + { + var input = _context.SocketInput; + + if (input.RemoteIntakeFin) + { + IntakeFin(input.Buffer.Count); + } + else + { + Intake(input.Buffer.Count); + } + } + } + + class ForContentLength : MessageBody + { + private readonly int _contentLength; + private int _neededLength; + + public ForContentLength(bool keepAlive, int contentLength, ConnectionContext context) + : base(context) + { + RequestKeepAlive = keepAlive; + _contentLength = contentLength; + _neededLength = _contentLength; + } + + public override void Consume() + { + var input = _context.SocketInput; + var consumeLength = Math.Min(_neededLength, input.Buffer.Count); + _neededLength -= consumeLength; + + var consumed = input.Take(consumeLength); + + if (_neededLength != 0) + { + Intake(consumeLength); + } + else + { + IntakeFin(consumeLength); + } + } + } + + + /// + /// http://tools.ietf.org/html/rfc2616#section-3.6.1 + /// + class ForChunkedEncoding : MessageBody + { + private int _neededLength; + + private Mode _mode = Mode.ChunkSizeLine; + + private enum Mode + { + ChunkSizeLine, + ChunkData, + ChunkDataCRLF, + Complete, + }; + + + public ForChunkedEncoding(bool keepAlive, ConnectionContext context) + : base(context) + { + RequestKeepAlive = keepAlive; + } + + public override void Consume() + { + var input = _context.SocketInput; + for (; ;) + { + switch (_mode) + { + case Mode.ChunkSizeLine: + var chunkSize = 0; + if (!TakeChunkedLine(input, ref chunkSize)) + { + return; + } + + _neededLength = chunkSize; + if (chunkSize == 0) + { + _mode = Mode.Complete; + IntakeFin(0); + return; + } + _mode = Mode.ChunkData; + break; + + case Mode.ChunkData: + if (_neededLength == 0) + { + _mode = Mode.ChunkDataCRLF; + break; + } + if (input.Buffer.Count == 0) + { + return; + } + + var consumeLength = Math.Min(_neededLength, input.Buffer.Count); + _neededLength -= consumeLength; + + Intake(consumeLength); + break; + + case Mode.ChunkDataCRLF: + if (input.Buffer.Count < 2) + { + return; + } + var crlf = input.Take(2); + if (crlf.Array[crlf.Offset] != '\r' || + crlf.Array[crlf.Offset + 1] != '\n') + { + throw new NotImplementedException("INVALID REQUEST FORMAT"); + } + _mode = Mode.ChunkSizeLine; + break; + + default: + throw new NotImplementedException("INVALID REQUEST FORMAT"); + } + } + } + + private static bool TakeChunkedLine(SocketInput baton, ref int chunkSizeOut) + { + var remaining = baton.Buffer; + if (remaining.Count < 2) + { + return false; + } + var ch0 = remaining.Array[remaining.Offset]; + var chunkSize = 0; + var mode = 0; + for (var index = 0; index != remaining.Count - 1; ++index) + { + var ch1 = remaining.Array[remaining.Offset + index + 1]; + + if (mode == 0) + { + if (ch0 >= '0' && ch0 <= '9') + { + chunkSize = chunkSize * 0x10 + (ch0 - '0'); + } + else if (ch0 >= 'A' && ch0 <= 'F') + { + chunkSize = chunkSize * 0x10 + (ch0 - ('A' - 10)); + } + else if (ch0 >= 'a' && ch0 <= 'f') + { + chunkSize = chunkSize * 0x10 + (ch0 - ('a' - 10)); + } + else + { + throw new NotImplementedException("INVALID REQUEST FORMAT"); + } + mode = 1; + } + else if (mode == 1) + { + if (ch0 >= '0' && ch0 <= '9') + { + chunkSize = chunkSize * 0x10 + (ch0 - '0'); + } + else if (ch0 >= 'A' && ch0 <= 'F') + { + chunkSize = chunkSize * 0x10 + (ch0 - ('A' - 10)); + } + else if (ch0 >= 'a' && ch0 <= 'f') + { + chunkSize = chunkSize * 0x10 + (ch0 - ('a' - 10)); + } + else if (ch0 == ';') + { + mode = 2; + } + else if (ch0 == '\r' && ch1 == '\n') + { + baton.Skip(index + 2); + chunkSizeOut = chunkSize; + return true; + } + else + { + throw new NotImplementedException("INVALID REQUEST FORMAT"); + } + } + else if (mode == 2) + { + if (ch0 == '\r' && ch1 == '\n') + { + baton.Skip(index + 2); + chunkSizeOut = chunkSize; + return true; + } + else + { + // chunk-extensions not currently parsed + } + } + + ch0 = ch1; + } + return false; + } + } + } +} diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/MessageBodyExchanger.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/MessageBodyExchanger.cs new file mode 100644 index 0000000000..29837ad131 --- /dev/null +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/MessageBodyExchanger.cs @@ -0,0 +1,144 @@ +// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; + +namespace Microsoft.AspNet.Server.Kestrel.Http +{ + /// + /// Summary description for MessageBodyExchanger + /// + public class MessageBodyExchanger + { + private static readonly WaitCallback _completePending = CompletePending; + protected readonly ConnectionContext _context; + + object _sync = new Object(); + + ArraySegment _buffer; + Queue _reads = new Queue(); + + public MessageBodyExchanger(ConnectionContext context) + { + _context = context; + _buffer = new ArraySegment(_context.Memory.Empty); + } + + public bool LocalIntakeFin { get; set; } + + public void Transfer(int count, bool fin) + { + var input = _context.SocketInput; + lock (_sync) + { + // NOTE: this should not copy each time + var oldBuffer = _buffer; + var newData = _context.SocketInput.Take(count); + + var newBuffer = new ArraySegment( + _context.Memory.AllocByte(oldBuffer.Count + newData.Count), + 0, + oldBuffer.Count + newData.Count); + + Array.Copy(oldBuffer.Array, oldBuffer.Offset, newBuffer.Array, newBuffer.Offset, oldBuffer.Count); + Array.Copy(newData.Array, newData.Offset, newBuffer.Array, newBuffer.Offset + oldBuffer.Count, newData.Count); + + _buffer = newBuffer; + _context.Memory.FreeByte(oldBuffer.Array); + + if (fin) + { + LocalIntakeFin = true; + } + if (_reads.Any()) + { + ThreadPool.QueueUserWorkItem(_completePending, this); + } + } + } + + public Task ReadAsync(ArraySegment buffer) + { + for (; ;) + { + while (CompletePending()) + { + // earlier reads have priority + } + lock (_sync) + { + if (_buffer.Count != 0 || buffer.Count == 0 || LocalIntakeFin) + { + // there is data we can take right now + if (_reads.Any()) + { + // someone snuck in, try again + continue; + } + + var count = Math.Min(buffer.Count, _buffer.Count); + Array.Copy(_buffer.Array, _buffer.Offset, buffer.Array, buffer.Offset, count); + _buffer = new ArraySegment(_buffer.Array, _buffer.Offset + count, _buffer.Count - count); + return Task.FromResult(count); + } + else + { + // add ourselves to the line + var tcs = new TaskCompletionSource(); + _reads.Enqueue(new ReadOperation + { + Buffer = buffer, + CompletionSource = tcs, + }); + return tcs.Task; + } + } + } + } + + static void CompletePending(object state) + { + while (((MessageBodyExchanger)state).CompletePending()) + { + // loop until none left + } + } + + bool CompletePending() + { + ReadOperation read; + int count; + lock (_sync) + { + if (_buffer.Count == 0 && !LocalIntakeFin) + { + return false; + } + if (!_reads.Any()) + { + return false; + } + read = _reads.Dequeue(); + + count = Math.Min(read.Buffer.Count, _buffer.Count); + Array.Copy(_buffer.Array, _buffer.Offset, read.Buffer.Array, read.Buffer.Offset, count); + _buffer = new ArraySegment(_buffer.Array, _buffer.Offset + count, _buffer.Count - count); + } + if (read.CompletionSource != null) + { + read.CompletionSource.SetResult(count); + } + return true; + } + + public struct ReadOperation + { + public TaskCompletionSource CompletionSource; + public ArraySegment Buffer; + } + } +} diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/ReasonPhrases.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/ReasonPhrases.cs new file mode 100644 index 0000000000..33076d1505 --- /dev/null +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/ReasonPhrases.cs @@ -0,0 +1,133 @@ +// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System.Globalization; + +namespace Microsoft.AspNet.Server.Kestrel.Http +{ + public static class ReasonPhrases + { + public static string ToStatus(int statusCode, string reasonPhrase = null) + { + if (string.IsNullOrEmpty(reasonPhrase)) + { + reasonPhrase = ToReasonPhrase(statusCode); + } + return statusCode.ToString(CultureInfo.InvariantCulture) + " " + reasonPhrase; + } + + public static string ToReasonPhrase(int statusCode) + { + switch (statusCode) + { + case 100: + return "Continue"; + case 101: + return "Switching Protocols"; + case 102: + return "Processing"; + case 200: + return "OK"; + case 201: + return "Created"; + case 202: + return "Accepted"; + case 203: + return "Non-Authoritative Information"; + case 204: + return "No Content"; + case 205: + return "Reset Content"; + case 206: + return "Partial Content"; + case 207: + return "Multi-Status"; + case 226: + return "IM Used"; + case 300: + return "Multiple Choices"; + case 301: + return "Moved Permanently"; + case 302: + return "Found"; + case 303: + return "See Other"; + case 304: + return "Not Modified"; + case 305: + return "Use Proxy"; + case 306: + return "Reserved"; + case 307: + return "Temporary Redirect"; + case 400: + return "Bad Request"; + case 401: + return "Unauthorized"; + case 402: + return "Payment Required"; + case 403: + return "Forbidden"; + case 404: + return "Not Found"; + case 405: + return "Method Not Allowed"; + case 406: + return "Not Acceptable"; + case 407: + return "Proxy Authentication Required"; + case 408: + return "Request Timeout"; + case 409: + return "Conflict"; + case 410: + return "Gone"; + case 411: + return "Length Required"; + case 412: + return "Precondition Failed"; + case 413: + return "Request Entity Too Large"; + case 414: + return "Request-URI Too Long"; + case 415: + return "Unsupported Media Type"; + case 416: + return "Requested Range Not Satisfiable"; + case 417: + return "Expectation Failed"; + case 418: + return "I'm a Teapot"; + case 422: + return "Unprocessable Entity"; + case 423: + return "Locked"; + case 424: + return "Failed Dependency"; + case 426: + return "Upgrade Required"; + case 500: + return "Internal Server Error"; + case 501: + return "Not Implemented"; + case 502: + return "Bad Gateway"; + case 503: + return "Service Unavailable"; + case 504: + return "Gateway Timeout"; + case 505: + return "HTTP Version Not Supported"; + case 506: + return "Variant Also Negotiates"; + case 507: + return "Insufficient Storage"; + case 510: + return "Not Extended"; + default: + return null; + } + } + } + +} diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketInput.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketInput.cs new file mode 100644 index 0000000000..5016a9881f --- /dev/null +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketInput.cs @@ -0,0 +1,106 @@ +// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Diagnostics; +using System.Runtime.InteropServices; + +namespace Microsoft.AspNet.Server.Kestrel.Http +{ + public class SocketInput + { + private readonly IMemoryPool _memory; + private GCHandle _gcHandle; + + public SocketInput(IMemoryPool memory) + { + _memory = memory; + Buffer = new ArraySegment(_memory.Empty, 0, 0); + } + + public ArraySegment Buffer { get; set; } + + public bool RemoteIntakeFin { get; set; } + + + public void Skip(int count) + { + Buffer = new ArraySegment(Buffer.Array, Buffer.Offset + count, Buffer.Count - count); + } + + public ArraySegment Take(int count) + { + var taken = new ArraySegment(Buffer.Array, Buffer.Offset, count); + Skip(count); + return taken; + } + + public void Free() + { + if (Buffer.Count == 0 && Buffer.Array.Length != 0) + { + _memory.FreeByte(Buffer.Array); + Buffer = new ArraySegment(_memory.Empty, 0, 0); + } + } + + public ArraySegment Available(int minimumSize) + { + if (Buffer.Count == 0 && Buffer.Offset != 0) + { + Buffer = new ArraySegment(Buffer.Array, 0, 0); + } + + var availableSize = Buffer.Array.Length - Buffer.Offset - Buffer.Count; + + if (availableSize < minimumSize) + { + if (availableSize + Buffer.Offset >= minimumSize) + { + Array.Copy(Buffer.Array, Buffer.Offset, Buffer.Array, 0, Buffer.Count); + if (Buffer.Count != 0) + { + Buffer = new ArraySegment(Buffer.Array, 0, Buffer.Count); + } + availableSize = Buffer.Array.Length - Buffer.Offset - Buffer.Count; + } + else + { + var largerSize = Buffer.Array.Length + Math.Max(Buffer.Array.Length, minimumSize); + var larger = new ArraySegment(_memory.AllocByte(largerSize), 0, Buffer.Count); + if (Buffer.Count != 0) + { + Array.Copy(Buffer.Array, Buffer.Offset, larger.Array, 0, Buffer.Count); + } + _memory.FreeByte(Buffer.Array); + Buffer = larger; + availableSize = Buffer.Array.Length - Buffer.Offset - Buffer.Count; + } + } + return new ArraySegment(Buffer.Array, Buffer.Offset + Buffer.Count, availableSize); + } + + public void Extend(int count) + { + Debug.Assert(count >= 0); + Debug.Assert(Buffer.Offset >= 0); + Debug.Assert(Buffer.Offset <= Buffer.Array.Length); + Debug.Assert(Buffer.Offset + Buffer.Count <= Buffer.Array.Length); + Debug.Assert(Buffer.Offset + Buffer.Count + count <= Buffer.Array.Length); + + Buffer = new ArraySegment(Buffer.Array, Buffer.Offset, Buffer.Count + count); + } + public IntPtr Pin(int minimumSize) + { + var segment = Available(minimumSize); + _gcHandle = GCHandle.Alloc(segment.Array, GCHandleType.Pinned); + return _gcHandle.AddrOfPinnedObject() + segment.Offset; + } + public void Unpin(int count) + { + _gcHandle.Free(); + Extend(count); + } + + } +} diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs new file mode 100644 index 0000000000..d33719c57d --- /dev/null +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs @@ -0,0 +1,106 @@ +// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using Microsoft.AspNet.Server.Kestrel.Networking; +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Net.Sockets; +using System.Runtime.InteropServices; + +namespace Microsoft.AspNet.Server.Kestrel.Http +{ + /// + /// Operations performed for buffered socket output + /// + public interface ISocketOutput + { + void Write(ArraySegment buffer, Action callback, object state); + } + + public class SocketOutput : ISocketOutput + { + private readonly KestrelThread _thread; + private readonly UvStreamHandle _socket; + + public SocketOutput(KestrelThread thread, UvStreamHandle socket) + { + _thread = thread; + _socket = socket; + } + + public void Write(ArraySegment buffer, Action callback, object state) + { + var req = new ThisWriteReq(); + req.Init(_thread.Loop); + req.Contextualize(this, _socket, buffer, callback, state); + _thread.Post(x => + { + ((ThisWriteReq)x).Write(); + }, req); + } + + public class ThisWriteReq : UvWriteReq + { + private static readonly Action _writeCallback = WriteCallback; + private static void WriteCallback(UvWriteReq req, int status, object state) + { + ((ThisWriteReq)state).OnWrite(req, status); + } + + SocketOutput _self; + ArraySegment _buffer; + Action _drained; + UvStreamHandle _socket; + Action _callback; + object _state; + GCHandle _pin; + + internal void Contextualize( + SocketOutput socketOutput, + UvStreamHandle socket, + ArraySegment buffer, + Action callback, + object state) + { + _self = socketOutput; + _socket = socket; + _buffer = buffer; + _callback = callback; + _state = state; + } + + public void Write() + { + _pin = GCHandle.Alloc(_buffer.Array, GCHandleType.Pinned); + var buf = new Libuv.uv_buf_t + { + len = (uint)_buffer.Count, + memory = _pin.AddrOfPinnedObject() + _buffer.Offset + }; + + Write( + _socket, + new[] { buf }, + 1, + _writeCallback, + this); + } + + private void OnWrite(UvWriteReq req, int status) + { + _pin.Free(); + //NOTE: pool this? + Close(); + _callback(_state); + } + } + + + public bool Flush(Action drained) + { + return false; + } + + } +} diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/Disposable.cs b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/Disposable.cs index 9bb2a7f4bd..8e61adb824 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/Disposable.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/Disposable.cs @@ -1,4 +1,7 @@ -using System; +// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; namespace Microsoft.AspNet.Server.Kestrel { diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs index 83dd84a4a5..43d09a593c 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs @@ -1,4 +1,7 @@ -using Microsoft.AspNet.Server.Kestrel.Networking; +// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using Microsoft.AspNet.Server.Kestrel.Networking; using System; using System.Collections.Generic; using System.Threading; diff --git a/src/Microsoft.AspNet.Server.Kestrel/KestrelEngine.cs b/src/Microsoft.AspNet.Server.Kestrel/KestrelEngine.cs index b404d6eb63..add92c5f37 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/KestrelEngine.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/KestrelEngine.cs @@ -1,9 +1,12 @@ +// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; using Microsoft.AspNet.Server.Kestrel.Networking; using System.Threading; using System.Collections.Generic; using System.Threading.Tasks; +using Microsoft.AspNet.Server.Kestrel.Http; namespace Microsoft.AspNet.Server.Kestrel { @@ -14,11 +17,13 @@ namespace Microsoft.AspNet.Server.Kestrel { Threads = new List(); Listeners = new List(); + Memory = new MemoryPool(); Libuv = new Libuv(); Libuv.Load("libuv.dll"); } public Libuv Libuv { get; private set; } + public IMemoryPool Memory { get; set; } public List Threads { get; private set; } public List Listeners { get; private set; } @@ -44,13 +49,13 @@ namespace Microsoft.AspNet.Server.Kestrel Threads.Clear(); } - public IDisposable CreateServer() + public IDisposable CreateServer(Func app) { var listeners = new List(); foreach (var thread in Threads) { - var listener = new Listener(thread); - listener.StartAsync().Wait(); + var listener = new Listener(Memory); + listener.StartAsync(thread, app).Wait(); listeners.Add(listener); } return new Disposable(() => diff --git a/src/Microsoft.AspNet.Server.Kestrel/Microsoft.AspNet.Server.Kestrel.kproj b/src/Microsoft.AspNet.Server.Kestrel/Microsoft.AspNet.Server.Kestrel.kproj new file mode 100644 index 0000000000..ca3a199436 --- /dev/null +++ b/src/Microsoft.AspNet.Server.Kestrel/Microsoft.AspNet.Server.Kestrel.kproj @@ -0,0 +1,57 @@ + + + + 12.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + + + + f510611a-3bee-4b88-a613-5f4a74ed82a1 + Library + + + ConsoleDebugger + + + WebDebugger + + + + + + + 2.0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/Libuv.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/Libuv.cs index 17a2299a44..a9e5dd7676 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/Libuv.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/Libuv.cs @@ -177,6 +177,50 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking Check(_uv_read_stop(handle)); } + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + delegate int uv_try_write(UvStreamHandle handle, Libuv.uv_buf_t[] bufs, int nbufs); + uv_try_write _uv_try_write; + public int try_write(UvStreamHandle handle, Libuv.uv_buf_t[] bufs, int nbufs) + { + return Check(_uv_try_write(handle, bufs, nbufs)); + } + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + public delegate void uv_write_cb(IntPtr req, int status); + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + delegate int uv_write(UvWriteReq req, UvStreamHandle handle, Libuv.uv_buf_t[] bufs, int nbufs, uv_write_cb cb); + uv_write _uv_write; + public void write(UvWriteReq req, UvStreamHandle handle, Libuv.uv_buf_t[] bufs, int nbufs, uv_write_cb cb) + { + Check(_uv_write(req, handle, bufs, nbufs, cb)); + } + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + public delegate void uv_shutdown_cb(IntPtr req, int status); + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + delegate int uv_shutdown(UvShutdownReq req, UvStreamHandle handle, uv_shutdown_cb cb); + uv_shutdown _uv_shutdown; + public void shutdown(UvShutdownReq req, UvStreamHandle handle, uv_shutdown_cb cb) + { + Check(_uv_shutdown(req, handle, cb)); + } + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + delegate int uv_handle_size(int handleType); + uv_handle_size _uv_handle_size; + public int handle_size(int handleType) + { + return _uv_handle_size(handleType); + } + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + delegate int uv_req_size(int handleType); + uv_req_size _uv_req_size; + public int req_size(int handleType) + { + return _uv_req_size(handleType); + } + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] delegate int uv_ip4_addr(string ip, int port, out sockaddr addr); @@ -209,5 +253,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking public IntPtr memory; } + //int handle_size_async; + //int handle_size_tcp; + //int req_size_write; + //int req_size_shutdown; } } \ No newline at end of file diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvHandle.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvHandle.cs index 033c649484..e76dac9176 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvHandle.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvHandle.cs @@ -2,38 +2,15 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.Runtime.InteropServices; namespace Microsoft.AspNet.Server.Kestrel.Networking { - public abstract class UvHandle : SafeHandle + public abstract class UvHandle : UvMemory { - protected Libuv _uv; static Libuv.uv_close_cb _close_cb = DestroyHandle; - public UvHandle() : base(IntPtr.Zero, true) - { - } - public override bool IsInvalid - { - get - { - return handle == IntPtr.Zero; - } - } - unsafe protected void CreateHandle(Libuv uv, int size) - { - _uv = uv; - handle = Marshal.AllocCoTaskMem(size); - *(IntPtr*)handle = GCHandle.ToIntPtr(GCHandle.Alloc(this)); - } - - protected void CreateHandle(UvLoopHandle loop, int size) - { - CreateHandle(loop._uv, size); - } protected override bool ReleaseHandle() { var memory = handle; @@ -45,22 +22,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking return true; } - unsafe protected static void DestroyHandle(IntPtr memory) - { - var gcHandlePtr = *(IntPtr*)memory; - if (gcHandlePtr != IntPtr.Zero) - { - GCHandle.FromIntPtr(gcHandlePtr).Free(); - } - Marshal.FreeCoTaskMem(memory); - } - - unsafe public static THandle FromIntPtr(IntPtr handle) - { - GCHandle gcHandle = GCHandle.FromIntPtr(*(IntPtr*)handle); - return (THandle)gcHandle.Target; - } - public void Reference() { _uv.@ref(this); diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvLoopHandle.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvLoopHandle.cs index 73bab4b5f7..ec87e7db56 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvLoopHandle.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvLoopHandle.cs @@ -13,7 +13,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking _uv.loop_init(this); } - public int Run(int mode = 0) { return _uv.run(this, mode); diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvMemory.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvMemory.cs new file mode 100644 index 0000000000..145b286fe1 --- /dev/null +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvMemory.cs @@ -0,0 +1,58 @@ +// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Runtime.InteropServices; + +namespace Microsoft.AspNet.Server.Kestrel.Networking +{ + /// + /// Summary description for UvMemory + /// + public abstract class UvMemory : SafeHandle + { + protected Libuv _uv; + public UvMemory() : base(IntPtr.Zero, true) + { + } + + public Libuv Libuv { get { return _uv; } } + + public override bool IsInvalid + { + get + { + return handle == IntPtr.Zero; + } + } + + unsafe protected void CreateHandle(Libuv uv, int size) + { + _uv = uv; + handle = Marshal.AllocCoTaskMem(size); + *(IntPtr*)handle = GCHandle.ToIntPtr(GCHandle.Alloc(this)); + } + + protected void CreateHandle(UvLoopHandle loop, int size) + { + CreateHandle(loop._uv, size); + } + + unsafe protected static void DestroyHandle(IntPtr memory) + { + var gcHandlePtr = *(IntPtr*)memory; + if (gcHandlePtr != IntPtr.Zero) + { + GCHandle.FromIntPtr(gcHandlePtr).Free(); + } + Marshal.FreeCoTaskMem(memory); + } + + unsafe public static THandle FromIntPtr(IntPtr handle) + { + GCHandle gcHandle = GCHandle.FromIntPtr(*(IntPtr*)handle); + return (THandle)gcHandle.Target; + } + + } +} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvShutdownReq.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvShutdownReq.cs new file mode 100644 index 0000000000..2bc23468e2 --- /dev/null +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvShutdownReq.cs @@ -0,0 +1,38 @@ +// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; + +namespace Microsoft.AspNet.Server.Kestrel.Networking +{ + /// + /// Summary description for UvShutdownRequest + /// + public class UvShutdownReq : UvReq + { + private readonly static Libuv.uv_shutdown_cb _uv_shutdown_cb = UvShutdownCb; + + Action _callback; + object _state; + + public void Init(UvLoopHandle loop) + { + CreateHandle(loop.Libuv, loop.Libuv.req_size(3)); + } + + public void Shutdown(UvStreamHandle handle, Action callback, object state) + { + _callback = callback; + _state = state; + _uv.shutdown(this, handle, _uv_shutdown_cb); + } + + private static void UvShutdownCb(IntPtr ptr, int status) + { + var req = FromIntPtr(ptr); + req._callback(req, status, req._state); + req._callback = null; + req._state = null; + } + } +} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvStreamHandle.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvStreamHandle.cs index e4d33aa849..7f2ff901e7 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvStreamHandle.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvStreamHandle.cs @@ -15,12 +15,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking public Action _connectionCallback; public object _connectionState; - public Action _readCallback; + public Func _allocCallback; + + public Action _readCallback; public object _readState; - public UvStreamHandle() - { - } public void Listen(int backlog, Action callback, object state) { @@ -35,10 +34,12 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking } public void ReadStart( - Action callback, + Func allocCallback, + Action readCallback, object state) { - _readCallback = callback; + _allocCallback = allocCallback; + _readCallback = readCallback; _readState = state; _uv.read_start(this, _uv_alloc_cb, _uv_read_cb); } @@ -48,38 +49,38 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking _uv.read_stop(this); } + public int TryWrite(Libuv.uv_buf_t buf) + { + return _uv.try_write(this, new[] { buf }, 1); + } + + private static void UvConnectionCb(IntPtr handle, int status) { var stream = FromIntPtr(handle); stream._connectionCallback(stream, status, stream._connectionState); } - private static void UvAllocCb(IntPtr server, int suggested_size, out Libuv.uv_buf_t buf) + private static void UvAllocCb(IntPtr handle, int suggested_size, out Libuv.uv_buf_t buf) { - buf = new Libuv.uv_buf_t - { - memory = Marshal.AllocCoTaskMem(suggested_size), - len = (uint)suggested_size, - }; - + var stream = FromIntPtr(handle); + buf = stream._allocCallback(stream, suggested_size, stream._readState); } - private static void UvReadCb(IntPtr ptr, int nread, ref Libuv.uv_buf_t buf) + private static void UvReadCb(IntPtr handle, int nread, ref Libuv.uv_buf_t buf) { - var stream = FromIntPtr(ptr); + var stream = FromIntPtr(handle); + if (nread == -4095) { - stream._readCallback(stream, 0, null, stream._readState); - Marshal.FreeCoTaskMem(buf.memory); + stream._readCallback(stream, 0, stream._readState); return; } var length = stream._uv.Check(nread); - var data = new byte[length]; - Marshal.Copy(buf.memory, data, 0, length); - Marshal.FreeCoTaskMem(buf.memory); - stream._readCallback(stream, length, data, stream._readState); + stream._readCallback(stream, nread, stream._readState); } + } } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvWriteRequest.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvWriteRequest.cs new file mode 100644 index 0000000000..17381696c5 --- /dev/null +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvWriteRequest.cs @@ -0,0 +1,57 @@ +// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Runtime.InteropServices; + +namespace Microsoft.AspNet.Server.Kestrel.Networking +{ + /// + /// Summary description for UvWriteRequest + /// + public class UvWriteReq : UvReq + { + private readonly static Libuv.uv_write_cb _uv_write_cb = UvWriteCb; + + Action _callback; + object _state; + + public void Init(UvLoopHandle loop) + { + CreateHandle(loop.Libuv, loop.Libuv.req_size(2)); + } + + public void Write(UvStreamHandle handle, Libuv.uv_buf_t[] bufs, int nbufs, Action callback, object state) + { + _callback = callback; + _state = state; + _uv.write(this, handle, bufs, nbufs, _uv_write_cb); + } + + private static void UvWriteCb(IntPtr ptr, int status) + { + var req = FromIntPtr(ptr); + req._callback(req, status, req._state); + req._callback = null; + req._state = null; + } + } + + public abstract class UvReq : UvMemory + { + + unsafe protected void CreateHandle(Libuv uv, int size) + { + _uv = uv; + handle = Marshal.AllocCoTaskMem(size); + *(IntPtr*)handle = GCHandle.ToIntPtr(GCHandle.Alloc(this)); + } + + protected override bool ReleaseHandle() + { + DestroyHandle(handle); + handle = IntPtr.Zero; + return true; + } + } +} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Server.Kestrel/Project.json b/src/Microsoft.AspNet.Server.Kestrel/Project.json index 0802ababfa..cb7ece47c7 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Project.json +++ b/src/Microsoft.AspNet.Server.Kestrel/Project.json @@ -1,6 +1,7 @@ { "version": "0.1-alpha-*", "dependencies": { + "Microsoft.AspNet.Hosting": "0.1-*" }, "compilationOptions": { "allowUnsafe": true diff --git a/src/SampleApp/Program.cs b/src/SampleApp/Program.cs new file mode 100644 index 0000000000..446628b570 --- /dev/null +++ b/src/SampleApp/Program.cs @@ -0,0 +1,36 @@ +using System; +using System.Threading.Tasks; + +namespace SampleApp +{ + public class Program + { + public static void Main(string[] args) + { + var engine = new Microsoft.AspNet.Server.Kestrel.KestrelEngine(); + engine.Start(1); + using (var server = engine.CreateServer(App)) + { + Console.WriteLine("Hello World"); + Console.ReadLine(); + } + engine.Stop(); + } + + private static async Task App(object arg) + { + var httpContext = new Microsoft.AspNet.PipelineCore.DefaultHttpContext( + new Microsoft.AspNet.FeatureModel.FeatureCollection( + new Microsoft.AspNet.FeatureModel.FeatureObject(arg))); + + Console.WriteLine("{0} {1}{2}{3}", + httpContext.Request.Method, + httpContext.Request.PathBase, + httpContext.Request.Path, + httpContext.Request.QueryString); + + httpContext.Response.ContentType = "text/plain"; + await httpContext.Response.WriteAsync("Hello world"); + } + } +} diff --git a/src/SampleApp/SampleApp.kproj b/src/SampleApp/SampleApp.kproj new file mode 100644 index 0000000000..7452dd8c38 --- /dev/null +++ b/src/SampleApp/SampleApp.kproj @@ -0,0 +1,35 @@ + + + + 12.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + + + Debug + AnyCPU + + + + 2c3cb3dc-eebf-4f52-9e1c-4f2f972e76c3 + Console + + + ConsoleDebugger + + + WebDebugger + + + + + 2.0 + + + + + + + + + + \ No newline at end of file diff --git a/src/SampleApp/libuv.dll b/src/SampleApp/libuv.dll new file mode 100644 index 0000000000000000000000000000000000000000..d3a583471805a26c08d10de032d0efb67350ed3e GIT binary patch literal 317440 zcmeFa4|r6?)jxidEU@6hE|5UPs6i2;{1GK;FrZ0bH6p7UB#Mdx3N!=+gk3=-LRg}# zYg)9>YPA(DDk^QUQdul&pwR>y`v&EGO)IT|M%{JOHnp)vjqdOBIdkvk?q=g_zwi5f z>i79&pJ(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ki4alJ5=wv$G@&5}^eOwJb*3P;2I*h?7 zpysRe2J+kAFyF}=vz;n9m7E}l7v(U^$poJ62!GZCsJfq1!^<#+V`h_`0nfm!rUjVO z^f_iUZGgw#37>r!IOjC*^AE;NAiD?fa=vC6hYPE1HbAtovtP zsjGE%&`Mux0FYxkFxDub$H~Btv#t3KleHQVoT-R?<={@s@f8Io0(%qT^tIM_JAi1I3L~bFovLGumm4ktb!sKx9v(G$k o0&?X=sNL^&Z0Qc>(%7?BSi5rY{NHm8JlDW;4LsMte*q2r4;T>E public class EngineTests { - [Fact] + private async Task App(object callContext) + { + var request = callContext as IHttpRequestFeature; + var response = callContext as IHttpResponseFeature; + for (; ;) + { + var buffer = new byte[8192]; + var count = await request.Body.ReadAsync(buffer, 0, buffer.Length); + if (count == 0) + { + break; + } + await response.Body.WriteAsync(buffer, 0, count); + } + } + + [Fact] public async Task EngineCanStartAndStop() { var engine = new KestrelEngine(); engine.Start(1); engine.Stop(); } + [Fact] public async Task ListenerCanCreateAndDispose() { var engine = new KestrelEngine(); engine.Start(1); - var started = engine.CreateServer(); + var started = engine.CreateServer(App); + started.Dispose(); + engine.Stop(); + } + + + [Fact] + public async Task ConnectionCanReadAndWrite() + { + var engine = new KestrelEngine(); + engine.Start(1); + var started = engine.CreateServer(App); + + var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); + socket.Connect(new IPEndPoint(IPAddress.Loopback, 4001)); + socket.Send(Encoding.ASCII.GetBytes("POST / HTTP/1.0\r\n\r\nHello World")); + socket.Shutdown(SocketShutdown.Send); + var buffer = new byte[8192]; + for (; ;) + { + var length = socket.Receive(buffer); + if (length == 0) { break; } + var text = Encoding.ASCII.GetString(buffer, 0, length); + } started.Dispose(); engine.Stop(); } } -} \ No newline at end of file +} diff --git a/test/Microsoft.AspNet.Server.KestralTests/MessageBodyExchangerTests.cs b/test/Microsoft.AspNet.Server.KestralTests/MessageBodyExchangerTests.cs new file mode 100644 index 0000000000..db8ff8218f --- /dev/null +++ b/test/Microsoft.AspNet.Server.KestralTests/MessageBodyExchangerTests.cs @@ -0,0 +1,190 @@ +using Microsoft.AspNet.Server.Kestrel; +using Microsoft.AspNet.Server.Kestrel.Http; +using System; +using System.Threading.Tasks; +using Xunit; + +namespace Microsoft.AspNet.Server.KestralTests +{ + /// + /// Summary description for MessageBodyExchangerTests + /// + public class MessageBodyExchangerTests + { + [Fact] + public async Task CallingReadAsyncBeforeTransfer() + { + var testInput = new TestInput(); + var context = new ConnectionContext(); + context.SocketInput = new SocketInput(new MemoryPool()); + + var exchanger = new MessageBodyExchanger(testInput.ConnectionContext); + + var buffer1 = new byte[1024]; + var buffer2 = new byte[1024]; + var task1 = exchanger.ReadAsync(new ArraySegment(buffer1)); + var task2 = exchanger.ReadAsync(new ArraySegment(buffer2)); + + Assert.False(task1.IsCompleted); + Assert.False(task2.IsCompleted); + + testInput.Add("Hello"); + + exchanger.Transfer(3, false); + + var count1 = await task1; + + Assert.True(task1.IsCompleted); + Assert.False(task2.IsCompleted); + AssertASCII("Hel", new ArraySegment(buffer1, 0, count1)); + + exchanger.Transfer(2, false); + + var count2 = await task2; + + Assert.True(task1.IsCompleted); + Assert.True(task2.IsCompleted); + AssertASCII("lo", new ArraySegment(buffer2, 0, count2)); + } + + [Fact] + public async Task CallingTransferBeforeReadAsync() + { + var testInput = new TestInput(); + var context = new ConnectionContext(); + context.SocketInput = new SocketInput(new MemoryPool()); + + var exchanger = new MessageBodyExchanger(testInput.ConnectionContext); + + testInput.Add("Hello"); + + exchanger.Transfer(5, false); + + var buffer1 = new byte[1024]; + var buffer2 = new byte[1024]; + var task1 = exchanger.ReadAsync(new ArraySegment(buffer1)); + var task2 = exchanger.ReadAsync(new ArraySegment(buffer2)); + + Assert.True(task1.IsCompleted); + Assert.False(task2.IsCompleted); + + await task1; + + var count1 = await task1; + + Assert.True(task1.IsCompleted); + Assert.False(task2.IsCompleted); + AssertASCII("Hello", new ArraySegment(buffer1, 0, count1)); + } + + [Fact] + public async Task TransferZeroBytesDoesNotReleaseReadAsync() + { + var testInput = new TestInput(); + var context = new ConnectionContext(); + context.SocketInput = new SocketInput(new MemoryPool()); + + var exchanger = new MessageBodyExchanger(testInput.ConnectionContext); + + var buffer1 = new byte[1024]; + var buffer2 = new byte[1024]; + var task1 = exchanger.ReadAsync(new ArraySegment(buffer1)); + var task2 = exchanger.ReadAsync(new ArraySegment(buffer2)); + + Assert.False(task1.IsCompleted); + Assert.False(task2.IsCompleted); + + testInput.Add("Hello"); + + exchanger.Transfer(3, false); + + var count1 = await task1; + + Assert.True(task1.IsCompleted); + Assert.False(task2.IsCompleted); + AssertASCII("Hel", new ArraySegment(buffer1, 0, count1)); + + exchanger.Transfer(0, false); + + Assert.True(task1.IsCompleted); + Assert.False(task2.IsCompleted); + } + + [Fact] + public async Task TransferFinDoesReleaseReadAsync() + { + var testInput = new TestInput(); + var context = new ConnectionContext(); + context.SocketInput = new SocketInput(new MemoryPool()); + + var exchanger = new MessageBodyExchanger(testInput.ConnectionContext); + + var buffer1 = new byte[1024]; + var buffer2 = new byte[1024]; + var task1 = exchanger.ReadAsync(new ArraySegment(buffer1)); + var task2 = exchanger.ReadAsync(new ArraySegment(buffer2)); + + Assert.False(task1.IsCompleted); + Assert.False(task2.IsCompleted); + + testInput.Add("Hello"); + + exchanger.Transfer(3, false); + + var count1 = await task1; + + Assert.True(task1.IsCompleted); + Assert.False(task2.IsCompleted); + AssertASCII("Hel", new ArraySegment(buffer1, 0, count1)); + + exchanger.Transfer(0, true); + + var count2 = await task2; + + Assert.True(task1.IsCompleted); + Assert.True(task2.IsCompleted); + Assert.Equal(0, count2); + } + + + [Fact] + public async Task TransferFinFirstDoesReturnsCompletedReadAsyncs() + { + + var testInput = new TestInput(); + var context = new ConnectionContext(); + context.SocketInput = new SocketInput(new MemoryPool()); + + var exchanger = new MessageBodyExchanger(testInput.ConnectionContext); + + testInput.Add("Hello"); + + exchanger.Transfer(5, true); + + var buffer1 = new byte[1024]; + var buffer2 = new byte[1024]; + var task1 = exchanger.ReadAsync(new ArraySegment(buffer1)); + var task2 = exchanger.ReadAsync(new ArraySegment(buffer2)); + + Assert.True(task1.IsCompleted); + Assert.True(task2.IsCompleted); + + var count1 = await task1; + var count2 = await task2; + + AssertASCII("Hello", new ArraySegment(buffer1, 0, count1)); + Assert.Equal(0, count2); + } + + private void AssertASCII(string expected, ArraySegment actual) + { + var encoding = System.Text.Encoding.ASCII; + var bytes = encoding.GetBytes(expected); + Assert.Equal(bytes.Length, actual.Count); + for (var index = 0; index != bytes.Length; ++index) + { + Assert.Equal(bytes[index], actual.Array[actual.Offset + index]); + } + } + } +} \ No newline at end of file diff --git a/test/Microsoft.AspNet.Server.KestralTests/MessageBodyTests.cs b/test/Microsoft.AspNet.Server.KestralTests/MessageBodyTests.cs new file mode 100644 index 0000000000..db1e3e3f89 --- /dev/null +++ b/test/Microsoft.AspNet.Server.KestralTests/MessageBodyTests.cs @@ -0,0 +1,64 @@ +using Microsoft.AspNet.Server.Kestrel.Http; +using System; +using System.Collections.Generic; +using System.Text; +using System.Threading.Tasks; +using Xunit; + +namespace Microsoft.AspNet.Server.KestralTests +{ + /// + /// Summary description for MessageBodyTests + /// + public class MessageBodyTests + { + [Fact] + public async Task Http10ConnectionClose() + { + var input = new TestInput(); + var body = MessageBody.For("HTTP/1.0", new Dictionary(), input.ConnectionContext); + var stream = new FrameRequestStream(body); + + input.Add("Hello", true); + body.Consume(); + + var buffer1 = new byte[1024]; + var count1 = stream.Read(buffer1, 0, 1024); + AssertASCII("Hello", new ArraySegment(buffer1, 0, 5)); + + var buffer2 = new byte[1024]; + var count2 = stream.Read(buffer2, 0, 1024); + Assert.Equal(0, count2); + } + + [Fact] + public async Task Http10ConnectionCloseAsync() + { + var input = new TestInput(); + var body = MessageBody.For("HTTP/1.0", new Dictionary(), input.ConnectionContext); + var stream = new FrameRequestStream(body); + + input.Add("Hello", true); + body.Consume(); + + var buffer1 = new byte[1024]; + var count1 = await stream.ReadAsync(buffer1, 0, 1024); + AssertASCII("Hello", new ArraySegment(buffer1, 0, 5)); + + var buffer2 = new byte[1024]; + var count2 = await stream.ReadAsync(buffer2, 0, 1024); + Assert.Equal(0, count2); + } + + private void AssertASCII(string expected, ArraySegment actual) + { + var encoding = Encoding.ASCII; + var bytes = encoding.GetBytes(expected); + Assert.Equal(bytes.Length, actual.Count); + for (var index = 0; index != bytes.Length; ++index) + { + Assert.Equal(bytes[index], actual.Array[actual.Offset + index]); + } + } + } +} \ No newline at end of file diff --git a/test/Microsoft.AspNet.Server.KestralTests/Microsoft.AspNet.Server.KestralTests.kproj b/test/Microsoft.AspNet.Server.KestralTests/Microsoft.AspNet.Server.KestralTests.kproj new file mode 100644 index 0000000000..1458edb016 --- /dev/null +++ b/test/Microsoft.AspNet.Server.KestralTests/Microsoft.AspNet.Server.KestralTests.kproj @@ -0,0 +1,37 @@ + + + + 12.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + + + + 37f3bfb2-6454-49e5-9d7f-581bf755ccfe + Console + + + ConsoleDebugger + + + WebDebugger + + + + + + + 2.0 + + + + + + + + + + + + + + \ No newline at end of file diff --git a/test/Microsoft.AspNet.Server.KestralTests/NetworkingTests.cs b/test/Microsoft.AspNet.Server.KestralTests/NetworkingTests.cs index 2f17803fd4..4ccd07526c 100644 --- a/test/Microsoft.AspNet.Server.KestralTests/NetworkingTests.cs +++ b/test/Microsoft.AspNet.Server.KestralTests/NetworkingTests.cs @@ -5,6 +5,7 @@ using Microsoft.AspNet.Server.Kestrel.Networking; using System; using System.Net; using System.Net.Sockets; +using System.Runtime.InteropServices; using System.Threading.Tasks; using Xunit; @@ -113,14 +114,18 @@ namespace Microsoft.AspNet.Server.KestralTests var tcp2 = new UvTcpHandle(); tcp2.Init(loop); tcp.Accept(tcp2); - tcp2.ReadStart((__, nread, data, state2) => - { - bytesRead += nread; - if (nread == 0) + var data = Marshal.AllocCoTaskMem(500); + tcp2.ReadStart( + (a, b, c) => new Libuv.uv_buf_t { memory = data, len = 500 }, + (__, nread, state2) => { - tcp2.Close(); - } - }, null); + bytesRead += nread; + if (nread == 0) + { + tcp2.Close(); + } + }, + null); tcp.Close(); }, null); var t = Task.Run(async () => diff --git a/test/Microsoft.AspNet.Server.KestralTests/TestInput.cs b/test/Microsoft.AspNet.Server.KestralTests/TestInput.cs new file mode 100644 index 0000000000..4e920c8192 --- /dev/null +++ b/test/Microsoft.AspNet.Server.KestralTests/TestInput.cs @@ -0,0 +1,34 @@ +using System; +using Microsoft.AspNet.Server.Kestrel.Http; + +namespace Microsoft.AspNet.Server.KestralTests +{ + class TestInput + { + public TestInput() + { + var memory = new MemoryPool(); + ConnectionContext = new ConnectionContext + { + SocketInput = new SocketInput(memory), + Memory = memory, + }; + + } + public ConnectionContext ConnectionContext { get; set; } + + public void Add(string text, bool fin = false) + { + var encoding = System.Text.Encoding.ASCII; + var count = encoding.GetByteCount(text); + var buffer = ConnectionContext.SocketInput.Available(text.Length); + count = encoding.GetBytes(text, 0, text.Length, buffer.Array, buffer.Offset); + ConnectionContext.SocketInput.Extend(count); + if (fin) + { + ConnectionContext.SocketInput.RemoteIntakeFin = true; + } + } + } +} + From 313db3f0cf9cbb93465fc7c467cee5606740e7d7 Mon Sep 17 00:00:00 2001 From: Louis DeJardin Date: Fri, 6 Jun 2014 22:16:08 -0700 Subject: [PATCH 0007/1662] Removing unnecessary using statements --- src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs | 3 --- src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs | 2 -- src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs | 1 - src/Microsoft.AspNet.Server.Kestrel/Http/MemoryPool.cs | 1 - src/Microsoft.AspNet.Server.Kestrel/Http/MessageBody.cs | 1 - src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs | 3 --- src/Microsoft.AspNet.Server.Kestrel/KestrelEngine.cs | 1 - .../Networking/UcAsyncHandle.cs | 1 - .../Networking/UvStreamHandle.cs | 1 - 9 files changed, 14 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs index 89837db215..6baf4864bb 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs @@ -2,9 +2,6 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.Diagnostics; -using System.Net.Sockets; -using System.Threading; using System.Threading.Tasks; using Microsoft.AspNet.Server.Kestrel.Networking; diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs index 0697149351..ca1d2c1bc5 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs @@ -4,9 +4,7 @@ using Microsoft.AspNet.HttpFeature; using System; using System.Collections.Generic; -using System.Globalization; using System.Linq; -using System.Net; using System.Text; using System.Threading.Tasks; diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs index 95995f9100..3114548b81 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs @@ -4,7 +4,6 @@ using Microsoft.AspNet.Server.Kestrel.Networking; using System; using System.Net; -using System.Text; using System.Threading.Tasks; namespace Microsoft.AspNet.Server.Kestrel.Http diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/MemoryPool.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/MemoryPool.cs index f97675f776..3b7c247a1c 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/MemoryPool.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/MemoryPool.cs @@ -3,7 +3,6 @@ using System; using System.Collections.Generic; -using System.Net.Sockets; namespace Microsoft.AspNet.Server.Kestrel.Http { diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/MessageBody.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/MessageBody.cs index 0ade9006fb..a2603bf8fb 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/MessageBody.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/MessageBody.cs @@ -3,7 +3,6 @@ using System; using System.Collections.Generic; -using System.Threading; namespace Microsoft.AspNet.Server.Kestrel.Http { diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs index d33719c57d..db1922cc0a 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs @@ -3,9 +3,6 @@ using Microsoft.AspNet.Server.Kestrel.Networking; using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.Net.Sockets; using System.Runtime.InteropServices; namespace Microsoft.AspNet.Server.Kestrel.Http diff --git a/src/Microsoft.AspNet.Server.Kestrel/KestrelEngine.cs b/src/Microsoft.AspNet.Server.Kestrel/KestrelEngine.cs index add92c5f37..6bebfd1239 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/KestrelEngine.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/KestrelEngine.cs @@ -3,7 +3,6 @@ using System; using Microsoft.AspNet.Server.Kestrel.Networking; -using System.Threading; using System.Collections.Generic; using System.Threading.Tasks; using Microsoft.AspNet.Server.Kestrel.Http; diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/UcAsyncHandle.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/UcAsyncHandle.cs index d09b815e75..f1a126eac9 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/UcAsyncHandle.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/UcAsyncHandle.cs @@ -2,7 +2,6 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.Runtime.InteropServices; namespace Microsoft.AspNet.Server.Kestrel.Networking { diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvStreamHandle.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvStreamHandle.cs index 7f2ff901e7..feb9dc4f6f 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvStreamHandle.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvStreamHandle.cs @@ -2,7 +2,6 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.Runtime.InteropServices; namespace Microsoft.AspNet.Server.Kestrel.Networking { From 044bbb83e6cfa126711677c7e810ad4c1da0e10e Mon Sep 17 00:00:00 2001 From: Louis DeJardin Date: Sat, 7 Jun 2014 02:49:25 -0700 Subject: [PATCH 0008/1662] Getting request body variations to work --- .../Http/Connection.cs | 65 ++---- .../Http/Frame.cs | 19 +- .../Http/MessageBody.cs | 20 -- .../Networking/Libuv.cs | 21 ++ .../Networking/UvHandle.cs | 2 - .../Networking/UvMemory.cs | 17 +- .../Networking/UvShutdownReq.cs | 2 +- .../Networking/UvWriteRequest.cs | 10 +- src/SampleApp/Program.cs | 3 + .../EngineTests.cs | 202 ++++++++++++++++++ .../Project.json | 4 +- 11 files changed, 280 insertions(+), 85 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs index 6baf4864bb..a5372243e8 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs @@ -45,17 +45,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Http ((Connection)state).OnRead(handle, nread); } - - private readonly Func _app; private readonly UvStreamHandle _socket; - private Frame _frame; - private Action _fault; - private Action _frameConsumeCallback; - private Action _receiveAsyncCompleted; - private Frame _receiveAsyncCompletedFrame; - public Connection(ListenerContext context, UvStreamHandle socket) : base(context) { _socket = socket; @@ -64,41 +56,10 @@ namespace Microsoft.AspNet.Server.Kestrel.Http public void Start() { - //_services.Trace.Event(TraceEventType.Start, TraceMessage.Connection); - SocketInput = new SocketInput(Memory); SocketOutput = new SocketOutput(Thread, _socket); - + _frame = new Frame(this); _socket.ReadStart(_allocCallback, _readCallback, this); - - //_fault = ex => { Debug.WriteLine(ex.Message); }; - - //_frameConsumeCallback = (frame, error) => - //{ - // if (error != null) - // { - // _fault(error); - // } - // try - // { - // Go(false, frame); - // } - // catch (Exception ex) - // { - // _fault(ex); - // } - //}; - - //try - //{ - // //_socket.Blocking = false; - // //_socket.NoDelay = true; - // Go(true, null); - //} - //catch (Exception ex) - //{ - // _fault(ex); - //} } private Libuv.uv_buf_t OnAlloc(UvStreamHandle handle, int suggestedSize) @@ -119,10 +80,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Http SocketInput.RemoteIntakeFin = true; } - if (_frame == null) - { - _frame = new Frame(this); - } _frame.Consume(); } @@ -141,14 +98,26 @@ namespace Microsoft.AspNet.Server.Kestrel.Http switch (endType) { case ProduceEndType.SocketShutdownSend: - var shutdown = new UvShutdownReq(); - shutdown.Init(Thread.Loop); - shutdown.Shutdown(_socket, (req, status, state) => req.Close(), null); + Thread.Post( + x => + { + var self = (Connection)x; + var shutdown = new UvShutdownReq(); + shutdown.Init(self.Thread.Loop); + shutdown.Shutdown(self._socket, (req, status, state) => req.Close(), null); + }, + this); break; case ProduceEndType.ConnectionKeepAlive: + _frame = new Frame(this); + Thread.Post( + x => ((Frame)x).Consume(), + _frame); break; case ProduceEndType.SocketDisconnect: - _socket.Close(); + Thread.Post( + x => ((UvHandle)x).Close(), + _socket); break; } } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs index ca1d2c1bc5..3049e3dc32 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs @@ -87,7 +87,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http switch (_mode) { case Mode.StartLine: - if (input.RemoteIntakeFin) + if (input.Buffer.Count == 0 && input.RemoteIntakeFin) { _mode = Mode.Terminated; return; @@ -95,6 +95,10 @@ namespace Microsoft.AspNet.Server.Kestrel.Http if (!TakeStartLine(input)) { + if (input.RemoteIntakeFin) + { + _mode = Mode.Terminated; + } return; } @@ -102,7 +106,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http break; case Mode.MessageHeader: - if (input.RemoteIntakeFin) + if (input.Buffer.Count == 0 && input.RemoteIntakeFin) { _mode = Mode.Terminated; return; @@ -113,16 +117,25 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { if (!TakeMessageHeader(input, out endOfHeaders)) { + if (input.RemoteIntakeFin) + { + _mode = Mode.Terminated; + } return; } } //var resumeBody = HandleExpectContinue(callback); - Execute(); _mode = Mode.MessageBody; + Execute(); break; case Mode.MessageBody: + if (_messageBody.LocalIntakeFin) + { + // NOTE: stop reading and resume on keepalive? + return; + } _messageBody.Consume(); // NOTE: keep looping? return; diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/MessageBody.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/MessageBody.cs index a2603bf8fb..ecdfc27aad 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/MessageBody.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/MessageBody.cs @@ -6,24 +6,6 @@ using System.Collections.Generic; namespace Microsoft.AspNet.Server.Kestrel.Http { - public static class DelegateExtensions - { - public static void InvokeNoThrow(this Action d) - { - try - { d.Invoke(); } - catch - { } - } - public static void InvokeNoThrow(this Action d, T arg1) - { - try - { d.Invoke(arg1); } - catch - { } - } - } - public abstract class MessageBody : MessageBodyExchanger { private Action _continuation = () => { }; @@ -156,8 +138,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Http var consumeLength = Math.Min(_neededLength, input.Buffer.Count); _neededLength -= consumeLength; - var consumed = input.Take(consumeLength); - if (_neededLength != 0) { Intake(consumeLength); diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/Libuv.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/Libuv.cs index a9e5dd7676..7f4bf0eaf0 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/Libuv.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/Libuv.cs @@ -59,6 +59,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking uv_loop_close _uv_loop_close; public void loop_close(UvLoopHandle handle) { + handle.Validate(closed: true); Check(_uv_loop_close(handle.DangerousGetHandle())); } @@ -67,6 +68,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking uv_run _uv_run; public int run(UvLoopHandle handle, int mode) { + handle.Validate(); return Check(_uv_run(handle, mode)); } @@ -75,6 +77,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking uv_stop _uv_stop; public void stop(UvLoopHandle handle) { + handle.Validate(); _uv_stop(handle); } @@ -83,6 +86,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking uv_ref _uv_ref; public void @ref(UvHandle handle) { + handle.Validate(); _uv_ref(handle); } @@ -91,6 +95,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking uv_unref _uv_unref; public void unref(UvHandle handle) { + handle.Validate(); _uv_unref(handle); } @@ -102,6 +107,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking uv_close _uv_close; public void close(UvHandle handle, uv_close_cb close_cb) { + handle.Validate(closed: true); _uv_close(handle.DangerousGetHandle(), close_cb); } @@ -112,6 +118,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking uv_async_init _uv_async_init; public void async_init(UvLoopHandle loop, UvAsyncHandle handle, uv_async_cb cb) { + loop.Validate(); + handle.Validate(); Check(_uv_async_init(loop, handle, cb)); } @@ -128,6 +136,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking uv_tcp_init _uv_tcp_init; public void tcp_init(UvLoopHandle loop, UvTcpHandle handle) { + loop.Validate(); + handle.Validate(); Check(_uv_tcp_init(loop, handle)); } @@ -136,6 +146,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking uv_tcp_bind _uv_tcp_bind; public void tcp_bind(UvTcpHandle handle, ref sockaddr addr, int flags) { + handle.Validate(); Check(_uv_tcp_bind(handle, ref addr, flags)); } @@ -146,6 +157,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking uv_listen _uv_listen; public void listen(UvStreamHandle handle, int backlog, uv_connection_cb cb) { + handle.Validate(); Check(_uv_listen(handle, backlog, cb)); } @@ -154,6 +166,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking uv_accept _uv_accept; public void accept(UvStreamHandle server, UvStreamHandle client) { + server.Validate(); + client.Validate(); Check(_uv_accept(server, client)); } @@ -166,6 +180,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking uv_read_start _uv_read_start; public void read_start(UvStreamHandle handle, uv_alloc_cb alloc_cb, uv_read_cb read_cb) { + handle.Validate(); Check(_uv_read_start(handle, alloc_cb, read_cb)); } @@ -174,6 +189,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking uv_read_stop _uv_read_stop; public void read_stop(UvStreamHandle handle) { + handle.Validate(); Check(_uv_read_stop(handle)); } @@ -182,6 +198,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking uv_try_write _uv_try_write; public int try_write(UvStreamHandle handle, Libuv.uv_buf_t[] bufs, int nbufs) { + handle.Validate(); return Check(_uv_try_write(handle, bufs, nbufs)); } @@ -192,6 +209,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking uv_write _uv_write; public void write(UvWriteReq req, UvStreamHandle handle, Libuv.uv_buf_t[] bufs, int nbufs, uv_write_cb cb) { + req.Validate(); + handle.Validate(); Check(_uv_write(req, handle, bufs, nbufs, cb)); } @@ -202,6 +221,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking uv_shutdown _uv_shutdown; public void shutdown(UvShutdownReq req, UvStreamHandle handle, uv_shutdown_cb cb) { + req.Validate(); + handle.Validate(); Check(_uv_shutdown(req, handle, cb)); } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvHandle.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvHandle.cs index e76dac9176..d08a6910d7 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvHandle.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvHandle.cs @@ -9,8 +9,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking { static Libuv.uv_close_cb _close_cb = DestroyHandle; - - protected override bool ReleaseHandle() { var memory = handle; diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvMemory.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvMemory.cs index 145b286fe1..a970b1e053 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvMemory.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvMemory.cs @@ -1,8 +1,10 @@ // Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - +#define TRACE using System; +using System.Diagnostics; using System.Runtime.InteropServices; +using System.Threading; namespace Microsoft.AspNet.Server.Kestrel.Networking { @@ -12,6 +14,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking public abstract class UvMemory : SafeHandle { protected Libuv _uv; + int _threadId; + public UvMemory() : base(IntPtr.Zero, true) { } @@ -29,6 +33,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking unsafe protected void CreateHandle(Libuv uv, int size) { _uv = uv; + _threadId = Thread.CurrentThread.ManagedThreadId; + handle = Marshal.AllocCoTaskMem(size); *(IntPtr*)handle = GCHandle.ToIntPtr(GCHandle.Alloc(this)); } @@ -36,8 +42,17 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking protected void CreateHandle(UvLoopHandle loop, int size) { CreateHandle(loop._uv, size); + _threadId = loop._threadId; } + public void Validate(bool closed = false) + { + Trace.Assert(IsClosed == closed, "Handle is closed"); + Trace.Assert(!IsInvalid, "Handle is invalid"); + Trace.Assert(_threadId == Thread.CurrentThread.ManagedThreadId, "ThreadId is correct"); + } + + unsafe protected static void DestroyHandle(IntPtr memory) { var gcHandlePtr = *(IntPtr*)memory; diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvShutdownReq.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvShutdownReq.cs index 2bc23468e2..05496b3a06 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvShutdownReq.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvShutdownReq.cs @@ -17,7 +17,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking public void Init(UvLoopHandle loop) { - CreateHandle(loop.Libuv, loop.Libuv.req_size(3)); + CreateHandle(loop, loop.Libuv.req_size(3)); } public void Shutdown(UvStreamHandle handle, Action callback, object state) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvWriteRequest.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvWriteRequest.cs index 17381696c5..54d69a3580 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvWriteRequest.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvWriteRequest.cs @@ -18,7 +18,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking public void Init(UvLoopHandle loop) { - CreateHandle(loop.Libuv, loop.Libuv.req_size(2)); + CreateHandle(loop, loop.Libuv.req_size(2)); } public void Write(UvStreamHandle handle, Libuv.uv_buf_t[] bufs, int nbufs, Action callback, object state) @@ -39,14 +39,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking public abstract class UvReq : UvMemory { - - unsafe protected void CreateHandle(Libuv uv, int size) - { - _uv = uv; - handle = Marshal.AllocCoTaskMem(size); - *(IntPtr*)handle = GCHandle.ToIntPtr(GCHandle.Alloc(this)); - } - protected override bool ReleaseHandle() { DestroyHandle(handle); diff --git a/src/SampleApp/Program.cs b/src/SampleApp/Program.cs index 446628b570..21673112e6 100644 --- a/src/SampleApp/Program.cs +++ b/src/SampleApp/Program.cs @@ -1,4 +1,5 @@ using System; +using System.Runtime.InteropServices; using System.Threading.Tasks; namespace SampleApp @@ -17,6 +18,8 @@ namespace SampleApp engine.Stop(); } + + private static async Task App(object arg) { var httpContext = new Microsoft.AspNet.PipelineCore.DefaultHttpContext( diff --git a/test/Microsoft.AspNet.Server.KestralTests/EngineTests.cs b/test/Microsoft.AspNet.Server.KestralTests/EngineTests.cs index 4c5b7e6887..3fe9f291d3 100644 --- a/test/Microsoft.AspNet.Server.KestralTests/EngineTests.cs +++ b/test/Microsoft.AspNet.Server.KestralTests/EngineTests.cs @@ -1,6 +1,7 @@ using Microsoft.AspNet.HttpFeature; using Microsoft.AspNet.Server.Kestrel; using System; +using System.IO; using System.Net; using System.Net.Sockets; using System.Text; @@ -29,6 +30,25 @@ namespace Microsoft.AspNet.Server.KestralTests await response.Body.WriteAsync(buffer, 0, count); } } + private async Task AppChunked(object callContext) + { + var request = callContext as IHttpRequestFeature; + var response = callContext as IHttpResponseFeature; + response.Headers["Transfer-Encoding"] = new[] { "chunked" }; + for (; ;) + { + var buffer = new byte[8192]; + var count = await request.Body.ReadAsync(buffer, 0, buffer.Length); + var hex = Encoding.ASCII.GetBytes(count.ToString("x") + "\r\n"); + await response.Body.WriteAsync(hex, 0, hex.Length); + if (count == 0) + { + break; + } + await response.Body.WriteAsync(buffer, 0, count); + await response.Body.WriteAsync(new[] { (byte)'\r', (byte)'\n' }, 0, 2); + } + } [Fact] public async Task EngineCanStartAndStop() @@ -70,5 +90,187 @@ namespace Microsoft.AspNet.Server.KestralTests started.Dispose(); engine.Stop(); } + + [Fact] + public async Task Http10() + { + var engine = new KestrelEngine(); + engine.Start(1); + var started = engine.CreateServer(App); + + Transceive( +@"POST / HTTP/1.0 + +Hello World", +@"HTTP/1.0 200 OK + +Hello World"); + started.Dispose(); + engine.Stop(); + } + + [Fact] + public async Task Http10ContentLength() + { + var engine = new KestrelEngine(); + engine.Start(1); + var started = engine.CreateServer(App); + + Transceive( +@"POST / HTTP/1.0 +Content-Length: 5 + +Hello World", +@"HTTP/1.0 200 OK + +Hello"); + started.Dispose(); + engine.Stop(); + } + + [Fact] + public async Task Http10TransferEncoding() + { + var engine = new KestrelEngine(); + engine.Start(1); + var started = engine.CreateServer(App); + + Transceive( +@"POST / HTTP/1.0 +Transfer-Encoding: chunked + +5 +Hello +6 + World +0 +ignored", +@"HTTP/1.0 200 OK + +Hello World"); + started.Dispose(); + engine.Stop(); + } + + + [Fact] + public async Task Http10KeepAlive() + { + var engine = new KestrelEngine(); + engine.Start(1); + var started = engine.CreateServer(AppChunked); + + Transceive( +@"GET / HTTP/1.0 +Connection: Keep-Alive + +POST / HTTP/1.0 + +Goodbye", +@"HTTP/1.0 200 OK +Transfer-Encoding: chunked +Connection: keep-alive + +0 +HTTP/1.0 200 OK +Transfer-Encoding: chunked + +7 +Goodbye +0 +"); + started.Dispose(); + engine.Stop(); + } + + [Fact] + public async Task Http10KeepAliveContentLength() + { + var engine = new KestrelEngine(); + engine.Start(1); + var started = engine.CreateServer(AppChunked); + + Transceive( +@"POST / HTTP/1.0 +Connection: Keep-Alive +Content-Length: 11 + +Hello WorldPOST / HTTP/1.0 + +Goodbye", +@"HTTP/1.0 200 OK +Transfer-Encoding: chunked +Connection: keep-alive + +b +Hello World +0 +HTTP/1.0 200 OK +Transfer-Encoding: chunked + +7 +Goodbye +0 +"); + started.Dispose(); + engine.Stop(); + } + + [Fact] + public async Task Http10KeepAliveTransferEncoding() + { + var engine = new KestrelEngine(); + engine.Start(1); + var started = engine.CreateServer(AppChunked); + + Transceive( +@"POST / HTTP/1.0 +Transfer-Encoding: chunked +Connection: keep-alive + +5 +Hello +6 + World +0 +POST / HTTP/1.0 + +Goodbye", +@"HTTP/1.0 200 OK +Transfer-Encoding: chunked +Connection: keep-alive + +b +Hello World +0 +HTTP/1.0 200 OK +Transfer-Encoding: chunked + +7 +Goodbye +0 +"); + started.Dispose(); + engine.Stop(); + } + + + private void Transceive(string send, string expected) + { + var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); + socket.Connect(new IPEndPoint(IPAddress.Loopback, 4001)); + + var stream = new NetworkStream(socket, false); + var writer = new StreamWriter(stream, Encoding.ASCII); + writer.Write(send); + writer.Flush(); + stream.Flush(); + socket.Shutdown(SocketShutdown.Send); + + var reader = new StreamReader(stream, Encoding.ASCII); + var actual = reader.ReadToEnd(); + + Assert.Equal(expected, actual); + } } } diff --git a/test/Microsoft.AspNet.Server.KestralTests/Project.json b/test/Microsoft.AspNet.Server.KestralTests/Project.json index 131b7d78c1..748dedce43 100644 --- a/test/Microsoft.AspNet.Server.KestralTests/Project.json +++ b/test/Microsoft.AspNet.Server.KestralTests/Project.json @@ -7,7 +7,9 @@ "Microsoft.AspNet.Server.Kestrel": "0.1-*" }, "configurations": { - "net45": {} + "net45": { + "compilationOptions": { "define": [ "TRACE" ] } + } }, "commands": { "run": "Xunit.KRunner", From ebd6af0fd6d4b42d2ae31643c28762114964cda1 Mon Sep 17 00:00:00 2001 From: Louis DeJardin Date: Sun, 8 Jun 2014 01:03:56 -0700 Subject: [PATCH 0009/1662] Trying to get 100 Continue working again --- .../Http/Connection.cs | 7 + .../Http/Frame.cs | 102 +++++---- .../Http/FrameRequestStream.cs | 24 +- .../Http/FrameResponseStream.cs | 10 +- .../Http/MessageBody.cs | 10 +- .../Http/MessageBodyExchanger.cs | 29 ++- .../Infrastructure/KestrelThread.cs | 37 ++- .../Networking/UcAsyncHandle.cs | 6 + .../EngineTests.cs | 212 ++++++++++-------- .../MessageBodyExchangerTests.cs | 10 +- .../MessageBodyTests.cs | 4 +- ...Microsoft.AspNet.Server.KestralTests.kproj | 1 + .../TestConnection.cs | 87 +++++++ .../TestInput.cs | 35 ++- 14 files changed, 390 insertions(+), 184 deletions(-) create mode 100644 test/Microsoft.AspNet.Server.KestralTests/TestConnection.cs diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs index a5372243e8..7fb9baac3c 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs @@ -17,6 +17,13 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { } + public ConnectionContext(ConnectionContext context) : base(context) + { + SocketInput = context.SocketInput; + SocketOutput = context.SocketOutput; + ConnectionControl = context.ConnectionControl; + } + public SocketInput SocketInput { get; set; } public ISocketOutput SocketOutput { get; set; } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs index 3049e3dc32..3d7693802a 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs @@ -20,10 +20,29 @@ namespace Microsoft.AspNet.Server.Kestrel.Http ConnectionKeepAlive, } - public class Frame + public class FrameContext : ConnectionContext { - private ConnectionContext _context; + public FrameContext() + { + } + + public FrameContext(ConnectionContext context) : base(context) + { + + } + + public IFrameControl FrameControl { get; set; } + } + + public interface IFrameControl + { + void ProduceContinue(); + void Write(ArraySegment data, Action callback, object state); + } + + public class Frame : FrameContext, IFrameControl + { Mode _mode; enum Mode @@ -64,10 +83,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http Task _upgradeTask = _completedTask; static readonly Task _completedTask = Task.FromResult(0); - public Frame(ConnectionContext context) + public Frame(ConnectionContext context) : base(context) { - _context = context; + FrameControl = this; } + /* public bool LocalIntakeFin { @@ -81,7 +101,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http */ public void Consume() { - var input = _context.SocketInput; + var input = SocketInput; for (; ;) { switch (_mode) @@ -146,46 +166,15 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } - Action HandleExpectContinue(Action continuation) - { - string[] expect; - if (_httpVersion.Equals("HTTP/1.1") && - _requestHeaders.TryGetValue("Expect", out expect) && - (expect.FirstOrDefault() ?? "").Equals("100-continue", StringComparison.OrdinalIgnoreCase)) - { - return (frame, error) => - { - if (_resultStarted) - { - continuation.Invoke(frame, error); - } - else - { - var bytes = Encoding.Default.GetBytes("HTTP/1.1 100 Continue\r\n\r\n"); - - //var isasync = _context.SocketOutput.Write( - // new ArraySegment(bytes), - // error2 => continuation(frame, error2)); - - //if (!isasync) - //{ - // continuation.Invoke(frame, null); - //} - } - }; - } - return continuation; - } - private void Execute() { _messageBody = MessageBody.For( _httpVersion, _requestHeaders, - _context); + this); _keepAlive = _messageBody.RequestKeepAlive; _callContext = CreateCallContext(); - _context.SocketInput.Free(); + SocketInput.Free(); Task.Run(ExecuteAsync); } @@ -194,7 +183,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http Exception error = null; try { - await _context.Application.Invoke(_callContext); + await Application.Invoke(_callContext); await _upgradeTask; } catch (Exception ex) @@ -210,7 +199,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http private CallContext CreateCallContext() { _inputStream = new FrameRequestStream(_messageBody); - _outputStream = new FrameResponseStream(OnWrite); + _outputStream = new FrameResponseStream(this); _duplexStream = new FrameDuplexStream(_inputStream, _outputStream); var remoteIpAddress = "127.0.0.1"; @@ -279,13 +268,13 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return callContext; } - void OnWrite(ArraySegment data, Action callback, object state) + public void Write(ArraySegment data, Action callback, object state) { ProduceStart(); - _context.SocketOutput.Write(data, callback, state); + SocketOutput.Write(data, callback, state); } - void Upgrade(IDictionary options, Func callback) + public void Upgrade(IDictionary options, Func callback) { _keepAlive = false; ProduceStart(); @@ -293,7 +282,22 @@ namespace Microsoft.AspNet.Server.Kestrel.Http _upgradeTask = callback(_callContext); } - void ProduceStart() + byte[] _continueBytes = Encoding.ASCII.GetBytes("HTTP/1.1 100 Continue\r\n\r\n"); + + public void ProduceContinue() + { + if (_resultStarted) return; + + string[] expect; + if (_httpVersion.Equals("HTTP/1.1") && + _requestHeaders.TryGetValue("Expect", out expect) && + (expect.FirstOrDefault() ?? "").Equals("100-continue", StringComparison.OrdinalIgnoreCase)) + { + SocketOutput.Write(new ArraySegment(_continueBytes, 0, _continueBytes.Length), _ => { }, null); + } + } + + public void ProduceStart() { if (_resultStarted) return; @@ -305,27 +309,27 @@ namespace Microsoft.AspNet.Server.Kestrel.Http response.ReasonPhrase); var responseHeader = CreateResponseHeader(status, _responseHeaders); - _context.SocketOutput.Write(responseHeader.Item1, x => ((IDisposable)x).Dispose(), responseHeader.Item2); + SocketOutput.Write(responseHeader.Item1, x => ((IDisposable)x).Dispose(), responseHeader.Item2); } - private void ProduceEnd(Exception ex) + public void ProduceEnd(Exception ex) { ProduceStart(); if (!_keepAlive) { - _context.ConnectionControl.End(ProduceEndType.SocketShutdownSend); + ConnectionControl.End(ProduceEndType.SocketShutdownSend); } _messageBody.Drain(() => - _context.ConnectionControl.End(_keepAlive ? ProduceEndType.ConnectionKeepAlive : ProduceEndType.SocketDisconnect)); + ConnectionControl.End(_keepAlive ? ProduceEndType.ConnectionKeepAlive : ProduceEndType.SocketDisconnect)); } private Tuple, IDisposable> CreateResponseHeader( string status, IEnumerable> headers) { - var writer = new MemoryPoolTextWriter(_context.Memory); + var writer = new MemoryPoolTextWriter(Memory); writer.Write(_httpVersion); writer.Write(' '); writer.Write(status); diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameRequestStream.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameRequestStream.cs index 16a4c90920..cff0776520 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameRequestStream.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameRequestStream.cs @@ -63,11 +63,25 @@ namespace Microsoft.AspNet.Server.Kestrel.Http public Task ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken, object state) { - //NOTE todo - throw new NotImplementedException(); - //var tcs = new TaskCompletionSource(state); - //_body.ReadAsync(new ArraySegment(buffer, offset, count)); - //return tcs.Task; + var tcs = new TaskCompletionSource(state); + var task = _body.ReadAsync(new ArraySegment(buffer, offset, count)); + task.ContinueWith((t, x) => + { + var tcs2 = (TaskCompletionSource)x; + if (t.IsCanceled) + { + tcs2.SetCanceled(); + } + else if (t.IsFaulted) + { + tcs2.SetException(t.Exception); + } + else + { + tcs2.SetResult(t.Result); + } + }, tcs); + return tcs.Task; } public override void Write(byte[] buffer, int offset, int count) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameResponseStream.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameResponseStream.cs index d4b34fbce6..756304ae0b 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameResponseStream.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameResponseStream.cs @@ -10,11 +10,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { class FrameResponseStream : Stream { - readonly Action, Action, object> _write; + private readonly FrameContext _context; - public FrameResponseStream(Action, Action, object> write) + public FrameResponseStream(FrameContext context) { - _write = write; + _context = context; } public override void Flush() @@ -25,7 +25,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http public override Task FlushAsync(CancellationToken cancellationToken) { var tcs = new TaskCompletionSource(); - _write(new ArraySegment(new byte[0]), x => ((TaskCompletionSource)x).SetResult(0), tcs); + _context.FrameControl.Write(new ArraySegment(new byte[0]), x => ((TaskCompletionSource)x).SetResult(0), tcs); return tcs.Task; } @@ -52,7 +52,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) { var tcs = new TaskCompletionSource(); - _write(new ArraySegment(buffer, offset, count), x => ((TaskCompletionSource)x).SetResult(0), tcs); + _context.FrameControl.Write(new ArraySegment(buffer, offset, count), x => ((TaskCompletionSource)x).SetResult(0), tcs); return tcs.Task; } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/MessageBody.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/MessageBody.cs index ecdfc27aad..a4ab91cedc 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/MessageBody.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/MessageBody.cs @@ -12,7 +12,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http public bool RequestKeepAlive { get; protected set; } - protected MessageBody(ConnectionContext context) : base(context) + protected MessageBody(FrameContext context) : base(context) { } @@ -35,7 +35,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http public static MessageBody For( string httpVersion, IDictionary headers, - ConnectionContext context) + FrameContext context) { // see also http://tools.ietf.org/html/rfc2616#section-4.4 @@ -99,7 +99,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http class ForRemainingData : MessageBody { - public ForRemainingData(ConnectionContext context) + public ForRemainingData(FrameContext context) : base(context) { } @@ -124,7 +124,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http private readonly int _contentLength; private int _neededLength; - public ForContentLength(bool keepAlive, int contentLength, ConnectionContext context) + public ForContentLength(bool keepAlive, int contentLength, FrameContext context) : base(context) { RequestKeepAlive = keepAlive; @@ -168,7 +168,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http }; - public ForChunkedEncoding(bool keepAlive, ConnectionContext context) + public ForChunkedEncoding(bool keepAlive, FrameContext context) : base(context) { RequestKeepAlive = keepAlive; diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/MessageBodyExchanger.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/MessageBodyExchanger.cs index 29837ad131..df1dc29309 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/MessageBodyExchanger.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/MessageBodyExchanger.cs @@ -15,14 +15,15 @@ namespace Microsoft.AspNet.Server.Kestrel.Http public class MessageBodyExchanger { private static readonly WaitCallback _completePending = CompletePending; - protected readonly ConnectionContext _context; + protected readonly FrameContext _context; object _sync = new Object(); ArraySegment _buffer; Queue _reads = new Queue(); + bool _send100Continue = true; - public MessageBodyExchanger(ConnectionContext context) + public MessageBodyExchanger(FrameContext context) { _context = context; _buffer = new ArraySegment(_context.Memory.Empty); @@ -32,9 +33,18 @@ namespace Microsoft.AspNet.Server.Kestrel.Http public void Transfer(int count, bool fin) { + if (count == 0 && !fin) + { + return; + } var input = _context.SocketInput; lock (_sync) { + if (_send100Continue) + { + _send100Continue = false; + } + // NOTE: this should not copy each time var oldBuffer = _buffer; var newData = _context.SocketInput.Take(count); @@ -63,7 +73,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Http public Task ReadAsync(ArraySegment buffer) { - for (; ;) + Task result = null; + var send100Continue = false; + while (result == null) { while (CompletePending()) { @@ -83,7 +95,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http var count = Math.Min(buffer.Count, _buffer.Count); Array.Copy(_buffer.Array, _buffer.Offset, buffer.Array, buffer.Offset, count); _buffer = new ArraySegment(_buffer.Array, _buffer.Offset + count, _buffer.Count - count); - return Task.FromResult(count); + result = Task.FromResult(count); } else { @@ -94,10 +106,17 @@ namespace Microsoft.AspNet.Server.Kestrel.Http Buffer = buffer, CompletionSource = tcs, }); - return tcs.Task; + result = tcs.Task; + send100Continue = _send100Continue; + _send100Continue = false; } } } + if (send100Continue) + { + _context.FrameControl.ProduceContinue(); + } + return result; } static void CompletePending(object state) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs index 43d09a593c..b72a99c73c 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs @@ -4,6 +4,7 @@ using Microsoft.AspNet.Server.Kestrel.Networking; using System; using System.Collections.Generic; +using System.Runtime.ExceptionServices; using System.Threading; using System.Threading.Tasks; @@ -22,6 +23,7 @@ namespace Microsoft.AspNet.Server.Kestrel Queue _workRunning = new Queue(); object _workSync = new Object(); bool _stopImmediate = false; + private ExceptionDispatchInfo _closeError; public KestrelThread(KestrelEngine engine) { @@ -51,6 +53,10 @@ namespace Microsoft.AspNet.Server.Kestrel _thread.Abort(); } } + if (_closeError != null) + { + _closeError.Throw(); + } } private void OnStop(object obj) @@ -86,20 +92,27 @@ namespace Microsoft.AspNet.Server.Kestrel { tcs.SetException(ex); } - var ran1 = _loop.Run(); - if (_stopImmediate) + try { - // thread-abort form of exit, resources will be leaked - return; + var ran1 = _loop.Run(); + if (_stopImmediate) + { + // thread-abort form of exit, resources will be leaked + return; + } + + // run the loop one more time to delete the _post handle + _post.Reference(); + _post.DangerousClose(); + var ran2 = _loop.Run(); + + // delete the last of the unmanaged memory + _loop.Close(); + } + catch (Exception ex) + { + _closeError = ExceptionDispatchInfo.Capture(ex); } - - // run the loop one more time to delete the _post handle - _post.Reference(); - _post.Close(); - var ran2 = _loop.Run(); - - // delete the last of the unmanaged memory - _loop.Close(); } private void OnPost() diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/UcAsyncHandle.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/UcAsyncHandle.cs index f1a126eac9..b15e376384 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/UcAsyncHandle.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/UcAsyncHandle.cs @@ -23,6 +23,12 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking _uv.async_init(loop, this, _uv_async_cb); } + public void DangerousClose() + { + Close(); + ReleaseHandle(); + } + private void UvAsyncCb(IntPtr handle) { _callback.Invoke(); diff --git a/test/Microsoft.AspNet.Server.KestralTests/EngineTests.cs b/test/Microsoft.AspNet.Server.KestralTests/EngineTests.cs index 3fe9f291d3..bf7ad6678b 100644 --- a/test/Microsoft.AspNet.Server.KestralTests/EngineTests.cs +++ b/test/Microsoft.AspNet.Server.KestralTests/EngineTests.cs @@ -34,20 +34,21 @@ namespace Microsoft.AspNet.Server.KestralTests { var request = callContext as IHttpRequestFeature; var response = callContext as IHttpResponseFeature; - response.Headers["Transfer-Encoding"] = new[] { "chunked" }; + + var data = new MemoryStream(); for (; ;) { var buffer = new byte[8192]; var count = await request.Body.ReadAsync(buffer, 0, buffer.Length); - var hex = Encoding.ASCII.GetBytes(count.ToString("x") + "\r\n"); - await response.Body.WriteAsync(hex, 0, hex.Length); if (count == 0) { break; } - await response.Body.WriteAsync(buffer, 0, count); - await response.Body.WriteAsync(new[] { (byte)'\r', (byte)'\n' }, 0, 2); + data.Write(buffer, 0, count); } + var bytes = data.ToArray(); + response.Headers["Content-Length"] = new[] { bytes.Length.ToString() }; + await response.Body.WriteAsync(bytes, 0, bytes.Length); } [Fact] @@ -118,12 +119,12 @@ Hello World"); Transceive( @"POST / HTTP/1.0 -Content-Length: 5 +Content-Length: 11 Hello World", @"HTTP/1.0 200 OK -Hello"); +Hello World"); started.Dispose(); engine.Stop(); } @@ -135,19 +136,21 @@ Hello"); engine.Start(1); var started = engine.CreateServer(App); - Transceive( -@"POST / HTTP/1.0 -Transfer-Encoding: chunked + using (var connection = new TestConnection()) + { + await connection.Send( + "POST / HTTP/1.0", + "Transfer-Encoding: chunked", + "", + "5", "Hello", "6", " World", "0\r\n"); + await connection.ReceiveEnd( + "HTTP/1.0 200 OK", + "", + "Hello World"); + } + -5 -Hello -6 - World -0 -ignored", -@"HTTP/1.0 200 OK -Hello World"); started.Dispose(); engine.Stop(); } @@ -160,25 +163,27 @@ Hello World"); engine.Start(1); var started = engine.CreateServer(AppChunked); - Transceive( -@"GET / HTTP/1.0 -Connection: Keep-Alive + using (var connection = new TestConnection()) + { + await connection.SendEnd( + "GET / HTTP/1.0", + "Connection: keep-alive", + "", + "POST / HTTP/1.0", + "", + "Goodbye"); + await connection.Receive( + "HTTP/1.0 200 OK", + "Content-Length: 0", + "Connection: keep-alive", + "\r\n"); + await connection.ReceiveEnd( + "HTTP/1.0 200 OK", + "Content-Length: 7", + "", + "Goodbye"); + } -POST / HTTP/1.0 - -Goodbye", -@"HTTP/1.0 200 OK -Transfer-Encoding: chunked -Connection: keep-alive - -0 -HTTP/1.0 200 OK -Transfer-Encoding: chunked - -7 -Goodbye -0 -"); started.Dispose(); engine.Stop(); } @@ -190,28 +195,28 @@ Goodbye engine.Start(1); var started = engine.CreateServer(AppChunked); - Transceive( -@"POST / HTTP/1.0 -Connection: Keep-Alive -Content-Length: 11 - -Hello WorldPOST / HTTP/1.0 - -Goodbye", -@"HTTP/1.0 200 OK -Transfer-Encoding: chunked -Connection: keep-alive - -b -Hello World -0 -HTTP/1.0 200 OK -Transfer-Encoding: chunked - -7 -Goodbye -0 -"); + using (var connection = new TestConnection()) + { + await connection.SendEnd( + "POST / HTTP/1.0", + "Connection: keep-alive", + "Content-Length: 11", + "", + "Hello WorldPOST / HTTP/1.0", + "", + "Goodbye"); + await connection.Receive( + "HTTP/1.0 200 OK", + "Content-Length: 11", + "Connection: keep-alive", + "", + "Hello World"); + await connection.ReceiveEnd( + "HTTP/1.0 200 OK", + "Content-Length: 7", + "", + "Goodbye"); + } started.Dispose(); engine.Stop(); } @@ -223,37 +228,52 @@ Goodbye engine.Start(1); var started = engine.CreateServer(AppChunked); - Transceive( -@"POST / HTTP/1.0 -Transfer-Encoding: chunked -Connection: keep-alive + using (var connection = new TestConnection()) + { + await connection.SendEnd( + "POST / HTTP/1.0", + "Transfer-Encoding: chunked", + "Connection: keep-alive", + "", + "5", "Hello", "6", " World", "0", + "POST / HTTP/1.0", + "", + "Goodbye"); + await connection.Receive( + "HTTP/1.0 200 OK", + "Content-Length: 11", + "Connection: keep-alive", + "", + "Hello World"); + await connection.ReceiveEnd( + "HTTP/1.0 200 OK", + "Content-Length: 7", + "", + "Goodbye"); + } -5 -Hello -6 - World -0 -POST / HTTP/1.0 - -Goodbye", -@"HTTP/1.0 200 OK -Transfer-Encoding: chunked -Connection: keep-alive - -b -Hello World -0 -HTTP/1.0 200 OK -Transfer-Encoding: chunked - -7 -Goodbye -0 -"); started.Dispose(); engine.Stop(); } + [Fact(Skip = "This is still not working")] + public async Task Expect100ContinueForBody() + { + var engine = new KestrelEngine(); + engine.Start(1); + var started = engine.CreateServer(AppChunked); + + using (var connection = new TestConnection()) + { + await connection.Send("POST / HTTP/1.1", "Expect: 100-continue", "Content-Length: 11", "\r\n"); + await connection.Receive("HTTP/1.1 100 Continue", "\r\n"); + await connection.SendEnd("Hello World"); + await connection.ReceiveEnd("HTTP/1.1 200 OK", "Content-Length: 11", "", "Hello World"); + } + + started.Dispose(); + engine.Stop(); + } private void Transceive(string send, string expected) { @@ -261,11 +281,25 @@ Goodbye socket.Connect(new IPEndPoint(IPAddress.Loopback, 4001)); var stream = new NetworkStream(socket, false); - var writer = new StreamWriter(stream, Encoding.ASCII); - writer.Write(send); - writer.Flush(); - stream.Flush(); - socket.Shutdown(SocketShutdown.Send); + Task.Run(async () => + { + try + { + var writer = new StreamWriter(stream, Encoding.ASCII); + foreach (var ch in send) + { + await writer.WriteAsync(ch); + await writer.FlushAsync(); + await Task.Delay(TimeSpan.FromMilliseconds(5)); + } + writer.Flush(); + stream.Flush(); + socket.Shutdown(SocketShutdown.Send); + } + catch (Exception ex) + { + } + }); var reader = new StreamReader(stream, Encoding.ASCII); var actual = reader.ReadToEnd(); diff --git a/test/Microsoft.AspNet.Server.KestralTests/MessageBodyExchangerTests.cs b/test/Microsoft.AspNet.Server.KestralTests/MessageBodyExchangerTests.cs index db8ff8218f..a96efcc8ad 100644 --- a/test/Microsoft.AspNet.Server.KestralTests/MessageBodyExchangerTests.cs +++ b/test/Microsoft.AspNet.Server.KestralTests/MessageBodyExchangerTests.cs @@ -18,7 +18,7 @@ namespace Microsoft.AspNet.Server.KestralTests var context = new ConnectionContext(); context.SocketInput = new SocketInput(new MemoryPool()); - var exchanger = new MessageBodyExchanger(testInput.ConnectionContext); + var exchanger = new MessageBodyExchanger(testInput.FrameContext); var buffer1 = new byte[1024]; var buffer2 = new byte[1024]; @@ -54,7 +54,7 @@ namespace Microsoft.AspNet.Server.KestralTests var context = new ConnectionContext(); context.SocketInput = new SocketInput(new MemoryPool()); - var exchanger = new MessageBodyExchanger(testInput.ConnectionContext); + var exchanger = new MessageBodyExchanger(testInput.FrameContext); testInput.Add("Hello"); @@ -84,7 +84,7 @@ namespace Microsoft.AspNet.Server.KestralTests var context = new ConnectionContext(); context.SocketInput = new SocketInput(new MemoryPool()); - var exchanger = new MessageBodyExchanger(testInput.ConnectionContext); + var exchanger = new MessageBodyExchanger(testInput.FrameContext); var buffer1 = new byte[1024]; var buffer2 = new byte[1024]; @@ -117,7 +117,7 @@ namespace Microsoft.AspNet.Server.KestralTests var context = new ConnectionContext(); context.SocketInput = new SocketInput(new MemoryPool()); - var exchanger = new MessageBodyExchanger(testInput.ConnectionContext); + var exchanger = new MessageBodyExchanger(testInput.FrameContext); var buffer1 = new byte[1024]; var buffer2 = new byte[1024]; @@ -155,7 +155,7 @@ namespace Microsoft.AspNet.Server.KestralTests var context = new ConnectionContext(); context.SocketInput = new SocketInput(new MemoryPool()); - var exchanger = new MessageBodyExchanger(testInput.ConnectionContext); + var exchanger = new MessageBodyExchanger(testInput.FrameContext); testInput.Add("Hello"); diff --git a/test/Microsoft.AspNet.Server.KestralTests/MessageBodyTests.cs b/test/Microsoft.AspNet.Server.KestralTests/MessageBodyTests.cs index db1e3e3f89..7f6bec71d6 100644 --- a/test/Microsoft.AspNet.Server.KestralTests/MessageBodyTests.cs +++ b/test/Microsoft.AspNet.Server.KestralTests/MessageBodyTests.cs @@ -16,7 +16,7 @@ namespace Microsoft.AspNet.Server.KestralTests public async Task Http10ConnectionClose() { var input = new TestInput(); - var body = MessageBody.For("HTTP/1.0", new Dictionary(), input.ConnectionContext); + var body = MessageBody.For("HTTP/1.0", new Dictionary(), input.FrameContext); var stream = new FrameRequestStream(body); input.Add("Hello", true); @@ -35,7 +35,7 @@ namespace Microsoft.AspNet.Server.KestralTests public async Task Http10ConnectionCloseAsync() { var input = new TestInput(); - var body = MessageBody.For("HTTP/1.0", new Dictionary(), input.ConnectionContext); + var body = MessageBody.For("HTTP/1.0", new Dictionary(), input.FrameContext); var stream = new FrameRequestStream(body); input.Add("Hello", true); diff --git a/test/Microsoft.AspNet.Server.KestralTests/Microsoft.AspNet.Server.KestralTests.kproj b/test/Microsoft.AspNet.Server.KestralTests/Microsoft.AspNet.Server.KestralTests.kproj index 1458edb016..e67fb478bf 100644 --- a/test/Microsoft.AspNet.Server.KestralTests/Microsoft.AspNet.Server.KestralTests.kproj +++ b/test/Microsoft.AspNet.Server.KestralTests/Microsoft.AspNet.Server.KestralTests.kproj @@ -31,6 +31,7 @@ + diff --git a/test/Microsoft.AspNet.Server.KestralTests/TestConnection.cs b/test/Microsoft.AspNet.Server.KestralTests/TestConnection.cs new file mode 100644 index 0000000000..353801f3da --- /dev/null +++ b/test/Microsoft.AspNet.Server.KestralTests/TestConnection.cs @@ -0,0 +1,87 @@ +using System; +using System.IO; +using System.Net; +using System.Net.Sockets; +using System.Text; +using System.Threading.Tasks; +using Xunit; + +namespace Microsoft.AspNet.Server.KestralTests +{ + /// + /// Summary description for TestConnection + /// + public class TestConnection : IDisposable + { + private Socket _socket; + private NetworkStream _stream; + private StreamReader _reader; + + public TestConnection() + { + Create(); + } + + public void Create() + { + _socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); + _socket.Connect(new IPEndPoint(IPAddress.Loopback, 4001)); + + _stream = new NetworkStream(_socket, false); + _reader = new StreamReader(_stream, Encoding.ASCII); + } + public void Dispose() + { + _stream.Close(); + _socket.Close(); + } + + public async Task Send(params string[] lines) + { + var text = String.Join("\r\n", lines); + var writer = new StreamWriter(_stream, Encoding.ASCII); + foreach (var ch in text) + { + await writer.WriteAsync(ch); + await writer.FlushAsync(); + await Task.Delay(TimeSpan.FromMilliseconds(5)); + } + writer.Flush(); + _stream.Flush(); + } + + public async Task SendEnd(params string[] lines) + { + await Send(lines); + _socket.Shutdown(SocketShutdown.Send); + } + + public async Task Receive(params string[] lines) + { + var expected = String.Join("\r\n", lines); + var actual = new char[expected.Length]; + var offset = 0; + while (offset < expected.Length) + { + var task = _reader.ReadAsync(actual, offset, actual.Length - offset); + Assert.True(task.Wait(1000), "timeout"); + var count = await task; + if (count == 0) + { + break; + } + offset += count; + } + + Assert.Equal(expected, new String(actual, 0, offset)); + } + + public async Task ReceiveEnd(params string[] lines) + { + await Receive(lines); + var ch = new char[1]; + var count = await _reader.ReadAsync(ch, 0, 1); + Assert.Equal(0, count); + } + } +} \ No newline at end of file diff --git a/test/Microsoft.AspNet.Server.KestralTests/TestInput.cs b/test/Microsoft.AspNet.Server.KestralTests/TestInput.cs index 4e920c8192..c7aa430c1f 100644 --- a/test/Microsoft.AspNet.Server.KestralTests/TestInput.cs +++ b/test/Microsoft.AspNet.Server.KestralTests/TestInput.cs @@ -3,32 +3,53 @@ using Microsoft.AspNet.Server.Kestrel.Http; namespace Microsoft.AspNet.Server.KestralTests { - class TestInput + class TestInput : IConnectionControl, IFrameControl { public TestInput() { var memory = new MemoryPool(); - ConnectionContext = new ConnectionContext + FrameContext = new FrameContext { SocketInput = new SocketInput(memory), Memory = memory, + ConnectionControl = this, + FrameControl = this }; - } - public ConnectionContext ConnectionContext { get; set; } + + public FrameContext FrameContext { get; set; } public void Add(string text, bool fin = false) { var encoding = System.Text.Encoding.ASCII; var count = encoding.GetByteCount(text); - var buffer = ConnectionContext.SocketInput.Available(text.Length); + var buffer = FrameContext.SocketInput.Available(text.Length); count = encoding.GetBytes(text, 0, text.Length, buffer.Array, buffer.Offset); - ConnectionContext.SocketInput.Extend(count); + FrameContext.SocketInput.Extend(count); if (fin) { - ConnectionContext.SocketInput.RemoteIntakeFin = true; + FrameContext.SocketInput.RemoteIntakeFin = true; } } + + public void ProduceContinue() + { + } + + public void Pause() + { + } + + public void Resume() + { + } + + public void Write(ArraySegment data, Action callback, object state) + { + } + public void End(ProduceEndType endType) + { + } } } From 75d0b29954809a85703c497ad88f5d506a7f2ba4 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Sun, 8 Jun 2014 23:39:08 -0700 Subject: [PATCH 0010/1662] Renamed Project.json to Project.json2 --- .../{Project.json => Project.json2} | 0 .../{Project.json => Project.json2} | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename src/Microsoft.AspNet.Server.Kestrel/{Project.json => Project.json2} (100%) rename test/Microsoft.AspNet.Server.KestralTests/{Project.json => Project.json2} (100%) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Project.json b/src/Microsoft.AspNet.Server.Kestrel/Project.json2 similarity index 100% rename from src/Microsoft.AspNet.Server.Kestrel/Project.json rename to src/Microsoft.AspNet.Server.Kestrel/Project.json2 diff --git a/test/Microsoft.AspNet.Server.KestralTests/Project.json b/test/Microsoft.AspNet.Server.KestralTests/Project.json2 similarity index 100% rename from test/Microsoft.AspNet.Server.KestralTests/Project.json rename to test/Microsoft.AspNet.Server.KestralTests/Project.json2 From ad738561afebb8caa51f98feee403c27b9e497d1 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Sun, 8 Jun 2014 23:39:09 -0700 Subject: [PATCH 0011/1662] Fixed project.json casing --- .../Microsoft.AspNet.Server.Kestrel.kproj | 4 ++-- .../{Project.json2 => project.json} | 0 src/SampleApp/SampleApp.kproj | 2 +- .../Microsoft.AspNet.Server.KestralTests.kproj | 4 ++-- .../{Project.json2 => project.json} | 0 5 files changed, 5 insertions(+), 5 deletions(-) rename src/Microsoft.AspNet.Server.Kestrel/{Project.json2 => project.json} (100%) rename test/Microsoft.AspNet.Server.KestralTests/{Project.json2 => project.json} (100%) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Microsoft.AspNet.Server.Kestrel.kproj b/src/Microsoft.AspNet.Server.Kestrel/Microsoft.AspNet.Server.Kestrel.kproj index ca3a199436..112e8fd2ab 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Microsoft.AspNet.Server.Kestrel.kproj +++ b/src/Microsoft.AspNet.Server.Kestrel/Microsoft.AspNet.Server.Kestrel.kproj @@ -23,7 +23,7 @@ 2.0 - + @@ -54,4 +54,4 @@ - \ No newline at end of file + diff --git a/src/Microsoft.AspNet.Server.Kestrel/Project.json2 b/src/Microsoft.AspNet.Server.Kestrel/project.json similarity index 100% rename from src/Microsoft.AspNet.Server.Kestrel/Project.json2 rename to src/Microsoft.AspNet.Server.Kestrel/project.json diff --git a/src/SampleApp/SampleApp.kproj b/src/SampleApp/SampleApp.kproj index 7452dd8c38..fe5828cdf7 100644 --- a/src/SampleApp/SampleApp.kproj +++ b/src/SampleApp/SampleApp.kproj @@ -32,4 +32,4 @@ - \ No newline at end of file + diff --git a/test/Microsoft.AspNet.Server.KestralTests/Microsoft.AspNet.Server.KestralTests.kproj b/test/Microsoft.AspNet.Server.KestralTests/Microsoft.AspNet.Server.KestralTests.kproj index e67fb478bf..fab0735264 100644 --- a/test/Microsoft.AspNet.Server.KestralTests/Microsoft.AspNet.Server.KestralTests.kproj +++ b/test/Microsoft.AspNet.Server.KestralTests/Microsoft.AspNet.Server.KestralTests.kproj @@ -23,7 +23,7 @@ 2.0 - + @@ -35,4 +35,4 @@ - \ No newline at end of file + diff --git a/test/Microsoft.AspNet.Server.KestralTests/Project.json2 b/test/Microsoft.AspNet.Server.KestralTests/project.json similarity index 100% rename from test/Microsoft.AspNet.Server.KestralTests/Project.json2 rename to test/Microsoft.AspNet.Server.KestralTests/project.json From 660babcd7f74b5e5aa672b4891925b006e534645 Mon Sep 17 00:00:00 2001 From: Louis DeJardin Date: Tue, 10 Jun 2014 00:28:52 -0700 Subject: [PATCH 0012/1662] Adding core clr configurations --- .../Http/Connection.cs | 4 +-- .../Http/Frame.cs | 2 +- .../Http/FrameDuplexStream.cs | 28 +++++++++++++++++++ .../Http/FrameRequestStream.cs | 2 ++ .../Http/Listener.cs | 2 +- .../Http/MemoryPoolTextWriter.cs | 4 +-- .../Http/SocketOutput.cs | 2 +- .../Infrastructure/KestrelThread.cs | 8 ++++-- .../Networking/UcAsyncHandle.cs | 18 ++++-------- .../Networking/UvMemory.cs | 3 +- .../project.json | 13 +++++++++ .../EngineTests.cs | 16 +++++++++-- .../MessageBodyTests.cs | 1 + .../NetworkingTests.cs | 26 ++++++++--------- .../TestConnection.cs | 6 ++-- .../project.json | 9 +++++- 16 files changed, 101 insertions(+), 43 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs index 7fb9baac3c..039ce58318 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs @@ -111,7 +111,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http var self = (Connection)x; var shutdown = new UvShutdownReq(); shutdown.Init(self.Thread.Loop); - shutdown.Shutdown(self._socket, (req, status, state) => req.Close(), null); + shutdown.Shutdown(self._socket, (req, status, state) => req.Dispose(), null); }, this); break; @@ -123,7 +123,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http break; case ProduceEndType.SocketDisconnect: Thread.Post( - x => ((UvHandle)x).Close(), + x => ((UvHandle)x).Dispose(), _socket); break; } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs index 3d7693802a..c9966e085c 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs @@ -454,7 +454,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http static string GetString(ArraySegment range, int startIndex, int endIndex) { - return Encoding.Default.GetString(range.Array, range.Offset + startIndex, endIndex - startIndex); + return Encoding.UTF8.GetString(range.Array, range.Offset + startIndex, endIndex - startIndex); } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameDuplexStream.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameDuplexStream.cs index 7028eacdb4..f129004b51 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameDuplexStream.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameDuplexStream.cs @@ -3,6 +3,8 @@ using System; using System.IO; +using System.Threading; +using System.Threading.Tasks; namespace Microsoft.AspNet.Server.Kestrel.Http { @@ -17,11 +19,13 @@ namespace Microsoft.AspNet.Server.Kestrel.Http _responseStream = responseStream; } +#if NET45 public override void Close() { _requestStream.Close(); _responseStream.Close(); } +#endif protected override void Dispose(bool disposing) { @@ -37,6 +41,12 @@ namespace Microsoft.AspNet.Server.Kestrel.Http _responseStream.Flush(); } + public override Task FlushAsync(CancellationToken cancellationToken) + { + return _responseStream.FlushAsync(cancellationToken); + } + +#if NET45 public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback callback, object state) { return _requestStream.BeginRead(buffer, offset, count, callback, state); @@ -46,7 +56,19 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { return _requestStream.EndRead(asyncResult); } +#endif + public override Task ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) + { + return _requestStream.ReadAsync(buffer, offset, count, cancellationToken); + } + + public override Task CopyToAsync(Stream destination, int bufferSize, CancellationToken cancellationToken) + { + return _requestStream.CopyToAsync(destination, bufferSize, cancellationToken); + } + +#if NET45 public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback callback, object state) { return _responseStream.BeginWrite(buffer, offset, count, callback, state); @@ -56,6 +78,12 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { _responseStream.EndWrite(asyncResult); } +#endif + + public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) + { + return _responseStream.WriteAsync(buffer, offset, count, cancellationToken); + } public override long Seek(long offset, SeekOrigin origin) { diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameRequestStream.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameRequestStream.cs index cff0776520..b7a219b8d9 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameRequestStream.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameRequestStream.cs @@ -41,6 +41,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return ReadAsync(buffer, offset, count).Result; } +#if NET45 public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback callback, object state) { var task = ReadAsync(buffer, offset, count, CancellationToken.None, state); @@ -55,6 +56,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { return ((Task)asyncResult).Result; } +#endif public override Task ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) { diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs index 3114548b81..9bf1413579 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs @@ -90,7 +90,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http private void OnDispose(object listenSocket) { - ((UvHandle)listenSocket).Close(); + ((UvHandle)listenSocket).Dispose(); } } } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/MemoryPoolTextWriter.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/MemoryPoolTextWriter.cs index c094178846..54763a0e26 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/MemoryPoolTextWriter.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/MemoryPoolTextWriter.cs @@ -36,14 +36,14 @@ namespace Microsoft.AspNet.Server.Kestrel.Http _memory = memory; _textArray = _memory.AllocChar(_textLength); _dataArray = _memory.Empty; - _encoder = Encoding.Default.GetEncoder(); + _encoder = Encoding.UTF8.GetEncoder(); } public override Encoding Encoding { get { - return Encoding.Default; + return Encoding.UTF8; } } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs index db1922cc0a..d3381f22fe 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs @@ -88,7 +88,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { _pin.Free(); //NOTE: pool this? - Close(); + Dispose(); _callback(_state); } } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs index b72a99c73c..6929767280 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs @@ -45,12 +45,14 @@ namespace Microsoft.AspNet.Server.Kestrel public void Stop(TimeSpan timeout) { Post(OnStop, null); - if (!_thread.Join(timeout)) + if (!_thread.Join((int)timeout.TotalMilliseconds)) { Post(OnStopImmediate, null); - if (!_thread.Join(timeout)) + if (!_thread.Join((int)timeout.TotalMilliseconds)) { +#if NET45 _thread.Abort(); +#endif } } if (_closeError != null) @@ -107,7 +109,7 @@ namespace Microsoft.AspNet.Server.Kestrel var ran2 = _loop.Run(); // delete the last of the unmanaged memory - _loop.Close(); + _loop.Dispose(); } catch (Exception ex) { diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/UcAsyncHandle.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/UcAsyncHandle.cs index b15e376384..e30cbe63ba 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/UcAsyncHandle.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/UcAsyncHandle.cs @@ -8,12 +8,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking public class UvAsyncHandle : UvHandle { private static Libuv.uv_async_cb _uv_async_cb = AsyncCb; - - unsafe static void AsyncCb(IntPtr handle) - { - FromIntPtr(handle)._callback.Invoke(); - } - private Action _callback; public void Init(UvLoopHandle loop, Action callback) @@ -25,18 +19,18 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking public void DangerousClose() { - Close(); + Dispose(); ReleaseHandle(); } - private void UvAsyncCb(IntPtr handle) - { - _callback.Invoke(); - } - public void Send() { _uv.async_send(this); } + + unsafe static void AsyncCb(IntPtr handle) + { + FromIntPtr(handle)._callback.Invoke(); + } } } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvMemory.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvMemory.cs index a970b1e053..661445c2e3 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvMemory.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvMemory.cs @@ -45,9 +45,10 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking _threadId = loop._threadId; } + public void Validate(bool closed = false) { - Trace.Assert(IsClosed == closed, "Handle is closed"); + Trace.Assert(closed || !IsClosed, "Handle is closed"); Trace.Assert(!IsInvalid, "Handle is invalid"); Trace.Assert(_threadId == Thread.CurrentThread.ManagedThreadId, "ThreadId is correct"); } diff --git a/src/Microsoft.AspNet.Server.Kestrel/project.json b/src/Microsoft.AspNet.Server.Kestrel/project.json index cb7ece47c7..591be84f59 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/project.json +++ b/src/Microsoft.AspNet.Server.Kestrel/project.json @@ -3,6 +3,19 @@ "dependencies": { "Microsoft.AspNet.Hosting": "0.1-*" }, + "configurations": { + "net45": { }, + "k10": { + "dependencies": { + "System.Threading.ThreadPool": "4.0.10.0", + "System.Diagnostics.Debug": "4.0.10.0", + "System.Threading.Thread": "4.0.0.0", + "System.Diagnostics.TraceSource": "4.0.0.0", + "System.Text.Encoding": "4.0.20.0", + "System.Threading.Tasks": "4.0.10.0" + } + } + }, "compilationOptions": { "allowUnsafe": true } diff --git a/test/Microsoft.AspNet.Server.KestralTests/EngineTests.cs b/test/Microsoft.AspNet.Server.KestralTests/EngineTests.cs index bf7ad6678b..56c8e551c1 100644 --- a/test/Microsoft.AspNet.Server.KestralTests/EngineTests.cs +++ b/test/Microsoft.AspNet.Server.KestralTests/EngineTests.cs @@ -256,7 +256,7 @@ Hello World"); engine.Stop(); } - [Fact(Skip = "This is still not working")] + [Fact] public async Task Expect100ContinueForBody() { var engine = new KestrelEngine(); @@ -265,10 +265,20 @@ Hello World"); using (var connection = new TestConnection()) { - await connection.Send("POST / HTTP/1.1", "Expect: 100-continue", "Content-Length: 11", "\r\n"); + await connection.Send( + "POST / HTTP/1.1", + "Expect: 100-continue", + "Content-Length: 11", + "Connection: close", + "\r\n"); await connection.Receive("HTTP/1.1 100 Continue", "\r\n"); await connection.SendEnd("Hello World"); - await connection.ReceiveEnd("HTTP/1.1 200 OK", "Content-Length: 11", "", "Hello World"); + await connection.Receive( + "HTTP/1.1 200 OK", + "Content-Length: 11", + "Connection: close", + "", + "Hello World"); } started.Dispose(); diff --git a/test/Microsoft.AspNet.Server.KestralTests/MessageBodyTests.cs b/test/Microsoft.AspNet.Server.KestralTests/MessageBodyTests.cs index 7f6bec71d6..ea5d2a75ce 100644 --- a/test/Microsoft.AspNet.Server.KestralTests/MessageBodyTests.cs +++ b/test/Microsoft.AspNet.Server.KestralTests/MessageBodyTests.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; using System.Text; +using System.Threading; using System.Threading.Tasks; using Xunit; diff --git a/test/Microsoft.AspNet.Server.KestralTests/NetworkingTests.cs b/test/Microsoft.AspNet.Server.KestralTests/NetworkingTests.cs index 4ccd07526c..90860a6a8b 100644 --- a/test/Microsoft.AspNet.Server.KestralTests/NetworkingTests.cs +++ b/test/Microsoft.AspNet.Server.KestralTests/NetworkingTests.cs @@ -29,7 +29,7 @@ namespace Microsoft.AspNet.Server.KestralTests var loop = new UvLoopHandle(); loop.Init(_uv); loop.Run(); - loop.Close(); + loop.Dispose(); } [Fact] @@ -42,11 +42,11 @@ namespace Microsoft.AspNet.Server.KestralTests trigger.Init(loop, () => { called = true; - trigger.Close(); + trigger.Dispose(); }); trigger.Send(); loop.Run(); - loop.Close(); + loop.Dispose(); Assert.True(called); } @@ -58,9 +58,9 @@ namespace Microsoft.AspNet.Server.KestralTests var tcp = new UvTcpHandle(); tcp.Init(loop); tcp.Bind(new IPEndPoint(IPAddress.Loopback, 0)); - tcp.Close(); + tcp.Dispose(); loop.Run(); - loop.Close(); + loop.Dispose(); } @@ -77,8 +77,8 @@ namespace Microsoft.AspNet.Server.KestralTests var tcp2 = new UvTcpHandle(); tcp2.Init(loop); stream.Accept(tcp2); - tcp2.Close(); - stream.Close(); + tcp2.Dispose(); + stream.Dispose(); }, null); var t = Task.Run(async () => { @@ -92,10 +92,10 @@ namespace Microsoft.AspNet.Server.KestralTests new IPEndPoint(IPAddress.Loopback, 54321), null, TaskCreationOptions.None); - socket.Close(); + socket.Dispose(); }); loop.Run(); - loop.Close(); + loop.Dispose(); await t; } @@ -122,11 +122,11 @@ namespace Microsoft.AspNet.Server.KestralTests bytesRead += nread; if (nread == 0) { - tcp2.Close(); + tcp2.Dispose(); } }, null); - tcp.Close(); + tcp.Dispose(); }, null); var t = Task.Run(async () => { @@ -147,10 +147,10 @@ namespace Microsoft.AspNet.Server.KestralTests SocketFlags.None, null, TaskCreationOptions.None); - socket.Close(); + socket.Dispose(); }); loop.Run(); - loop.Close(); + loop.Dispose(); await t; } } diff --git a/test/Microsoft.AspNet.Server.KestralTests/TestConnection.cs b/test/Microsoft.AspNet.Server.KestralTests/TestConnection.cs index 353801f3da..a53d2594de 100644 --- a/test/Microsoft.AspNet.Server.KestralTests/TestConnection.cs +++ b/test/Microsoft.AspNet.Server.KestralTests/TestConnection.cs @@ -32,8 +32,8 @@ namespace Microsoft.AspNet.Server.KestralTests } public void Dispose() { - _stream.Close(); - _socket.Close(); + _stream.Dispose(); + _socket.Dispose(); } public async Task Send(params string[] lines) @@ -64,7 +64,7 @@ namespace Microsoft.AspNet.Server.KestralTests while (offset < expected.Length) { var task = _reader.ReadAsync(actual, offset, actual.Length - offset); - Assert.True(task.Wait(1000), "timeout"); +// Assert.True(task.Wait(1000), "timeout"); var count = await task; if (count == 0) { diff --git a/test/Microsoft.AspNet.Server.KestralTests/project.json b/test/Microsoft.AspNet.Server.KestralTests/project.json index 748dedce43..de7c2275d3 100644 --- a/test/Microsoft.AspNet.Server.KestralTests/project.json +++ b/test/Microsoft.AspNet.Server.KestralTests/project.json @@ -9,10 +9,17 @@ "configurations": { "net45": { "compilationOptions": { "define": [ "TRACE" ] } + }, + "k10": { + "compilationOptions": { "define": [ "TRACE" ] }, + "dependencies": { + "System.Net.Sockets": "4.0.0.0", + "System.Runtime.Handles": "4.0.0.0" + } } }, "commands": { - "run": "Xunit.KRunner", + "run": "Xunit.KRunner -trait x=vs", "test": "Xunit.KRunner" } } From 9c7cb6a958c01ae3e99353047bce3138049171b4 Mon Sep 17 00:00:00 2001 From: Louis DeJardin Date: Wed, 11 Jun 2014 17:09:25 -0700 Subject: [PATCH 0013/1662] Adding some tests for Http11 Requires updating to test utilities Adding initial EventSource to try to see some order of events --- .../Http/Connection.cs | 26 +- .../Http/Frame.cs | 4 +- .../Http/MessageBody.cs | 13 +- .../Http/SocketOutput.cs | 2 + .../Infrastructure/KestrelTrace.cs | 83 +++++ .../Microsoft.AspNet.Server.Kestrel.kproj | 3 +- .../project.json | 3 +- .../EngineTests.cs | 334 ++++++++---------- .../TestConnection.cs | 9 +- .../TestServer.cs | 34 ++ 10 files changed, 313 insertions(+), 198 deletions(-) create mode 100644 src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelTrace.cs create mode 100644 test/Microsoft.AspNet.Server.KestralTests/TestServer.cs diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs index 039ce58318..8560a7bbbd 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs @@ -54,6 +54,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http private readonly UvStreamHandle _socket; private Frame _frame; + long _connectionId; public Connection(ListenerContext context, UvStreamHandle socket) : base(context) { @@ -63,6 +64,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http public void Start() { + KestrelTrace.Log.ConnectionStart(_connectionId); + SocketInput = new SocketInput(Memory); SocketOutput = new SocketOutput(Thread, _socket); _frame = new Frame(this); @@ -85,6 +88,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http if (nread == 0) { SocketInput.RemoteIntakeFin = true; + KestrelTrace.Log.ConnectionReadFin(_connectionId); + } + else + { + KestrelTrace.Log.ConnectionRead(_connectionId, nread); } _frame.Consume(); @@ -92,11 +100,13 @@ namespace Microsoft.AspNet.Server.Kestrel.Http void IConnectionControl.Pause() { + KestrelTrace.Log.ConnectionPause(_connectionId); _socket.ReadStop(); } void IConnectionControl.Resume() { + KestrelTrace.Log.ConnectionResume(_connectionId); _socket.ReadStart(_allocCallback, _readCallback, this); } @@ -105,25 +115,37 @@ namespace Microsoft.AspNet.Server.Kestrel.Http switch (endType) { case ProduceEndType.SocketShutdownSend: + KestrelTrace.Log.ConnectionWriteFin(_connectionId, 0); Thread.Post( x => { + KestrelTrace.Log.ConnectionWriteFin(_connectionId, 1); var self = (Connection)x; var shutdown = new UvShutdownReq(); shutdown.Init(self.Thread.Loop); - shutdown.Shutdown(self._socket, (req, status, state) => req.Dispose(), null); + shutdown.Shutdown(self._socket, (req, status, state) => + { + KestrelTrace.Log.ConnectionWriteFin(_connectionId, 1); + req.Dispose(); + }, null); }, this); break; case ProduceEndType.ConnectionKeepAlive: + KestrelTrace.Log.ConnectionKeepAlive(_connectionId); _frame = new Frame(this); Thread.Post( x => ((Frame)x).Consume(), _frame); break; case ProduceEndType.SocketDisconnect: + KestrelTrace.Log.ConnectionDisconnect(_connectionId); Thread.Post( - x => ((UvHandle)x).Dispose(), + x => + { + KestrelTrace.Log.ConnectionStop(_connectionId); + ((UvHandle)x).Dispose(); + }, _socket); break; } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs index c9966e085c..2104952722 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs @@ -321,8 +321,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http ConnectionControl.End(ProduceEndType.SocketShutdownSend); } - _messageBody.Drain(() => - ConnectionControl.End(_keepAlive ? ProduceEndType.ConnectionKeepAlive : ProduceEndType.SocketDisconnect)); + //NOTE: must finish reading request body + ConnectionControl.End(_keepAlive ? ProduceEndType.ConnectionKeepAlive : ProduceEndType.SocketDisconnect); } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/MessageBody.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/MessageBody.cs index a4ab91cedc..a77bda0f6b 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/MessageBody.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/MessageBody.cs @@ -3,13 +3,12 @@ using System; using System.Collections.Generic; +using System.Threading; namespace Microsoft.AspNet.Server.Kestrel.Http { public abstract class MessageBody : MessageBodyExchanger { - private Action _continuation = () => { }; - public bool RequestKeepAlive { get; protected set; } protected MessageBody(FrameContext context) : base(context) @@ -24,10 +23,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Http public void IntakeFin(int count) { Transfer(count, true); - if (_continuation != null) - { - _continuation.Invoke(); - } } public abstract void Consume(); @@ -90,12 +85,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return true; } - public void Drain(Action continuation) - { - _continuation = continuation; - _continuation.Invoke(); - } - class ForRemainingData : MessageBody { diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs index d3381f22fe..fb1aa9cc0b 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs @@ -28,6 +28,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http public void Write(ArraySegment buffer, Action callback, object state) { + KestrelTrace.Log.ConnectionWrite(0, buffer.Count); var req = new ThisWriteReq(); req.Init(_thread.Loop); req.Contextualize(this, _socket, buffer, callback, state); @@ -87,6 +88,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http private void OnWrite(UvWriteReq req, int status) { _pin.Free(); + KestrelTrace.Log.ConnectionWriteCallback(0, status); //NOTE: pool this? Dispose(); _callback(_state); diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelTrace.cs b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelTrace.cs new file mode 100644 index 0000000000..907567bb82 --- /dev/null +++ b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelTrace.cs @@ -0,0 +1,83 @@ +using System; +using System.Diagnostics.Tracing; + +namespace Microsoft.AspNet.Server.Kestrel +{ + /// + /// Summary description for KestrelTrace + /// + public class KestrelTrace : EventSource + { + public static KestrelTrace Log = new KestrelTrace(); + static EventTask Connection = (EventTask)1; + static EventTask Frame = (EventTask)1; + + + [Event(13, Level = EventLevel.Informational, Message = "Id {0}")] + public void ConnectionStart(long connectionId) + { + WriteEvent(13, connectionId); + } + + [Event(14, Level = EventLevel.Informational, Message = "Id {0}")] + public void ConnectionStop(long connectionId) + { + WriteEvent(14, connectionId); + } + + + [Event(4, Message = "Id {0} Status {1}")] + internal void ConnectionRead(long connectionId, int status) + { + WriteEvent(4, connectionId, status); + } + + [Event(5, Message = "Id {0}")] + internal void ConnectionPause(long connectionId) + { + WriteEvent(5, connectionId); + } + + [Event(6, Message = "Id {0}")] + internal void ConnectionResume(long connectionId) + { + WriteEvent(6, connectionId); + } + + [Event(7, Message = "Id {0}")] + internal void ConnectionReadFin(long connectionId) + { + WriteEvent(7, connectionId); + } + + [Event(8, Message = "Id {0} Step {1}")] + internal void ConnectionWriteFin(long connectionId, int step) + { + WriteEvent(8, connectionId, step); + } + + [Event(9, Message = "Id {0}")] + internal void ConnectionKeepAlive(long connectionId) + { + WriteEvent(9, connectionId); + } + + [Event(10, Message = "Id {0}")] + internal void ConnectionDisconnect(long connectionId) + { + WriteEvent(10, connectionId); + } + + [Event(11, Message = "Id {0} Count {1}")] + internal void ConnectionWrite(long connectionId, int count) + { + WriteEvent(11, connectionId, count); + } + + [Event(12, Message = "Id {0} Status {1}")] + internal void ConnectionWriteCallback(long connectionId, int status) + { + WriteEvent(12, connectionId, status); + } + } +} diff --git a/src/Microsoft.AspNet.Server.Kestrel/Microsoft.AspNet.Server.Kestrel.kproj b/src/Microsoft.AspNet.Server.Kestrel/Microsoft.AspNet.Server.Kestrel.kproj index 112e8fd2ab..9ba02d48db 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Microsoft.AspNet.Server.Kestrel.kproj +++ b/src/Microsoft.AspNet.Server.Kestrel/Microsoft.AspNet.Server.Kestrel.kproj @@ -42,6 +42,7 @@ + @@ -54,4 +55,4 @@ - + \ No newline at end of file diff --git a/src/Microsoft.AspNet.Server.Kestrel/project.json b/src/Microsoft.AspNet.Server.Kestrel/project.json index 591be84f59..6dba34e730 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/project.json +++ b/src/Microsoft.AspNet.Server.Kestrel/project.json @@ -12,7 +12,8 @@ "System.Threading.Thread": "4.0.0.0", "System.Diagnostics.TraceSource": "4.0.0.0", "System.Text.Encoding": "4.0.20.0", - "System.Threading.Tasks": "4.0.10.0" + "System.Threading.Tasks": "4.0.10.0", + "System.Diagnostics.Tracing": "4.0.10.0" } } }, diff --git a/test/Microsoft.AspNet.Server.KestralTests/EngineTests.cs b/test/Microsoft.AspNet.Server.KestralTests/EngineTests.cs index 56c8e551c1..414e825277 100644 --- a/test/Microsoft.AspNet.Server.KestralTests/EngineTests.cs +++ b/test/Microsoft.AspNet.Server.KestralTests/EngineTests.cs @@ -95,226 +95,204 @@ namespace Microsoft.AspNet.Server.KestralTests [Fact] public async Task Http10() { - var engine = new KestrelEngine(); - engine.Start(1); - var started = engine.CreateServer(App); - - Transceive( -@"POST / HTTP/1.0 - -Hello World", -@"HTTP/1.0 200 OK - -Hello World"); - started.Dispose(); - engine.Stop(); + using (var server = new TestServer(App)) + { + using (var connection = new TestConnection()) + { + await connection.SendEnd( + "POST / HTTP/1.0", + "", + "Hello World"); + await connection.ReceiveEnd( + "HTTP/1.0 200 OK", + "", + "Hello World"); + } + } } + [Fact] + public async Task Http11() + { + using (var server = new TestServer(AppChunked)) + { + using (var connection = new TestConnection()) + { + await connection.SendEnd( + "GET / HTTP/1.1", + "", + "GET / HTTP/1.1", + "Connection: close", + "", + "Goodbye"); + await connection.ReceiveEnd( + "HTTP/1.1 200 OK", + "Content-Length: 0", + "", + "HTTP/1.1 200 OK", + "Content-Length: 7", + "Connection: close", + "", + "Goodbye"); + } + } + } + + [Fact] public async Task Http10ContentLength() { - var engine = new KestrelEngine(); - engine.Start(1); - var started = engine.CreateServer(App); - - Transceive( -@"POST / HTTP/1.0 -Content-Length: 11 - -Hello World", -@"HTTP/1.0 200 OK - -Hello World"); - started.Dispose(); - engine.Stop(); + using (var server = new TestServer(App)) + { + using (var connection = new TestConnection()) + { + await connection.Send( + "POST / HTTP/1.0", + "Content-Length: 11", + "", + "Hello World"); + await connection.ReceiveEnd( + "HTTP/1.0 200 OK", + "", + "Hello World"); + } + } } [Fact] public async Task Http10TransferEncoding() { - var engine = new KestrelEngine(); - engine.Start(1); - var started = engine.CreateServer(App); - - using (var connection = new TestConnection()) + using (var server = new TestServer(App)) { - await connection.Send( - "POST / HTTP/1.0", - "Transfer-Encoding: chunked", - "", - "5", "Hello", "6", " World", "0\r\n"); - await connection.ReceiveEnd( - "HTTP/1.0 200 OK", - "", - "Hello World"); + using (var connection = new TestConnection()) + { + await connection.Send( + "POST / HTTP/1.0", + "Transfer-Encoding: chunked", + "", + "5", "Hello", "6", " World", "0\r\n"); + await connection.ReceiveEnd( + "HTTP/1.0 200 OK", + "", + "Hello World"); + } } - - - - started.Dispose(); - engine.Stop(); } [Fact] public async Task Http10KeepAlive() { - var engine = new KestrelEngine(); - engine.Start(1); - var started = engine.CreateServer(AppChunked); - - using (var connection = new TestConnection()) + using (var server = new TestServer(AppChunked)) { - await connection.SendEnd( - "GET / HTTP/1.0", - "Connection: keep-alive", - "", - "POST / HTTP/1.0", - "", - "Goodbye"); - await connection.Receive( - "HTTP/1.0 200 OK", - "Content-Length: 0", - "Connection: keep-alive", - "\r\n"); - await connection.ReceiveEnd( - "HTTP/1.0 200 OK", - "Content-Length: 7", - "", - "Goodbye"); + using (var connection = new TestConnection()) + { + await connection.SendEnd( + "GET / HTTP/1.0", + "Connection: keep-alive", + "", + "POST / HTTP/1.0", + "", + "Goodbye"); + await connection.Receive( + "HTTP/1.0 200 OK", + "Content-Length: 0", + "Connection: keep-alive", + "\r\n"); + await connection.ReceiveEnd( + "HTTP/1.0 200 OK", + "Content-Length: 7", + "", + "Goodbye"); + } } - - started.Dispose(); - engine.Stop(); } [Fact] public async Task Http10KeepAliveContentLength() { - var engine = new KestrelEngine(); - engine.Start(1); - var started = engine.CreateServer(AppChunked); - - using (var connection = new TestConnection()) + using (var server = new TestServer(AppChunked)) { - await connection.SendEnd( - "POST / HTTP/1.0", - "Connection: keep-alive", - "Content-Length: 11", - "", - "Hello WorldPOST / HTTP/1.0", - "", - "Goodbye"); - await connection.Receive( - "HTTP/1.0 200 OK", - "Content-Length: 11", - "Connection: keep-alive", - "", - "Hello World"); - await connection.ReceiveEnd( - "HTTP/1.0 200 OK", - "Content-Length: 7", - "", - "Goodbye"); + using (var connection = new TestConnection()) + { + await connection.SendEnd( + "POST / HTTP/1.0", + "Connection: keep-alive", + "Content-Length: 11", + "", + "Hello WorldPOST / HTTP/1.0", + "", + "Goodbye"); + await connection.Receive( + "HTTP/1.0 200 OK", + "Content-Length: 11", + "Connection: keep-alive", + "", + "Hello World"); + await connection.ReceiveEnd( + "HTTP/1.0 200 OK", + "Content-Length: 7", + "", + "Goodbye"); + } } - started.Dispose(); - engine.Stop(); } [Fact] public async Task Http10KeepAliveTransferEncoding() { - var engine = new KestrelEngine(); - engine.Start(1); - var started = engine.CreateServer(AppChunked); - - using (var connection = new TestConnection()) + using (var server = new TestServer(AppChunked)) { - await connection.SendEnd( - "POST / HTTP/1.0", - "Transfer-Encoding: chunked", - "Connection: keep-alive", - "", - "5", "Hello", "6", " World", "0", - "POST / HTTP/1.0", - "", - "Goodbye"); - await connection.Receive( - "HTTP/1.0 200 OK", - "Content-Length: 11", - "Connection: keep-alive", - "", - "Hello World"); - await connection.ReceiveEnd( - "HTTP/1.0 200 OK", - "Content-Length: 7", - "", - "Goodbye"); + using (var connection = new TestConnection()) + { + await connection.SendEnd( + "POST / HTTP/1.0", + "Transfer-Encoding: chunked", + "Connection: keep-alive", + "", + "5", "Hello", "6", " World", "0", + "POST / HTTP/1.0", + "", + "Goodbye"); + await connection.Receive( + "HTTP/1.0 200 OK", + "Content-Length: 11", + "Connection: keep-alive", + "", + "Hello World"); + await connection.ReceiveEnd( + "HTTP/1.0 200 OK", + "Content-Length: 7", + "", + "Goodbye"); + } } - - started.Dispose(); - engine.Stop(); } [Fact] public async Task Expect100ContinueForBody() { - var engine = new KestrelEngine(); - engine.Start(1); - var started = engine.CreateServer(AppChunked); - - using (var connection = new TestConnection()) + using (var server = new TestServer(AppChunked)) { - await connection.Send( - "POST / HTTP/1.1", - "Expect: 100-continue", - "Content-Length: 11", - "Connection: close", - "\r\n"); - await connection.Receive("HTTP/1.1 100 Continue", "\r\n"); - await connection.SendEnd("Hello World"); - await connection.Receive( - "HTTP/1.1 200 OK", - "Content-Length: 11", - "Connection: close", - "", - "Hello World"); + using (var connection = new TestConnection()) + { + await connection.Send( + "POST / HTTP/1.1", + "Expect: 100-continue", + "Content-Length: 11", + "Connection: close", + "\r\n"); + await connection.Receive("HTTP/1.1 100 Continue", "\r\n"); + await connection.SendEnd("Hello World"); + await connection.Receive( + "HTTP/1.1 200 OK", + "Content-Length: 11", + "Connection: close", + "", + "Hello World"); + } } - - started.Dispose(); - engine.Stop(); } - private void Transceive(string send, string expected) - { - var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); - socket.Connect(new IPEndPoint(IPAddress.Loopback, 4001)); - - var stream = new NetworkStream(socket, false); - Task.Run(async () => - { - try - { - var writer = new StreamWriter(stream, Encoding.ASCII); - foreach (var ch in send) - { - await writer.WriteAsync(ch); - await writer.FlushAsync(); - await Task.Delay(TimeSpan.FromMilliseconds(5)); - } - writer.Flush(); - stream.Flush(); - socket.Shutdown(SocketShutdown.Send); - } - catch (Exception ex) - { - } - }); - - var reader = new StreamReader(stream, Encoding.ASCII); - var actual = reader.ReadToEnd(); - - Assert.Equal(expected, actual); - } } } diff --git a/test/Microsoft.AspNet.Server.KestralTests/TestConnection.cs b/test/Microsoft.AspNet.Server.KestralTests/TestConnection.cs index a53d2594de..d07e0e4925 100644 --- a/test/Microsoft.AspNet.Server.KestralTests/TestConnection.cs +++ b/test/Microsoft.AspNet.Server.KestralTests/TestConnection.cs @@ -1,4 +1,5 @@ using System; +using System.Diagnostics; using System.IO; using System.Net; using System.Net.Sockets; @@ -40,8 +41,9 @@ namespace Microsoft.AspNet.Server.KestralTests { var text = String.Join("\r\n", lines); var writer = new StreamWriter(_stream, Encoding.ASCII); - foreach (var ch in text) + for (var index = 0; index != text.Length; ++index) { + var ch = text[index]; await writer.WriteAsync(ch); await writer.FlushAsync(); await Task.Delay(TimeSpan.FromMilliseconds(5)); @@ -64,7 +66,10 @@ namespace Microsoft.AspNet.Server.KestralTests while (offset < expected.Length) { var task = _reader.ReadAsync(actual, offset, actual.Length - offset); -// Assert.True(task.Wait(1000), "timeout"); + if (!Debugger.IsAttached) + { + Assert.True(task.Wait(1000), "timeout"); + } var count = await task; if (count == 0) { diff --git a/test/Microsoft.AspNet.Server.KestralTests/TestServer.cs b/test/Microsoft.AspNet.Server.KestralTests/TestServer.cs new file mode 100644 index 0000000000..4291532317 --- /dev/null +++ b/test/Microsoft.AspNet.Server.KestralTests/TestServer.cs @@ -0,0 +1,34 @@ +using Microsoft.AspNet.Server.Kestrel; +using System; +using System.Threading.Tasks; + +namespace Microsoft.AspNet.Server.KestralTests +{ + /// + /// Summary description for TestServer + /// + public class TestServer : IDisposable + { + private KestrelEngine _engine; + private IDisposable _server; + + public TestServer(Func app) + { + Create(app); + } + + public void Create(Func app) + { + _engine = new KestrelEngine(); + _engine.Start(1); + _server = _engine.CreateServer(app); + + } + + public void Dispose() + { + _server.Dispose(); + _engine.Stop(); + } + } +} \ No newline at end of file From 6ac6419f4f5beacae5c2d560d3b22c56c545c5ff Mon Sep 17 00:00:00 2001 From: Louis DeJardin Date: Fri, 13 Jun 2014 13:10:46 -0700 Subject: [PATCH 0014/1662] Adding support for 'k web --server kestrel' --- KestrelHttpServer.sln | 6 + src/Kestrel/Kestrel.kproj | 36 +++ src/Kestrel/ServerFactory.cs | 35 +++ src/Kestrel/ServerInformation.cs | 21 ++ src/Kestrel/ServerRequest.cs | 180 +++++++++++++++ src/Kestrel/project.json | 17 ++ .../Http/CallContext.cs | 51 ----- .../Http/Frame.cs | 209 +++++++----------- .../Http/FrameDuplexStream.cs | 6 +- .../Http/Listener.cs | 6 +- .../KestrelEngine.cs | 8 +- .../Microsoft.AspNet.Server.Kestrel.kproj | 1 - .../project.json | 10 +- src/SampleApp/Program.cs | 34 +-- src/SampleApp/SampleApp.kproj | 6 +- src/SampleApp/Startup.cs | 23 ++ src/SampleApp/project.json | 12 +- .../EngineTests.cs | 29 +-- ...Microsoft.AspNet.Server.KestralTests.kproj | 4 +- .../Program.cs | 15 ++ .../TestServer.cs | 7 +- .../project.json | 4 +- 22 files changed, 475 insertions(+), 245 deletions(-) create mode 100644 src/Kestrel/Kestrel.kproj create mode 100644 src/Kestrel/ServerFactory.cs create mode 100644 src/Kestrel/ServerInformation.cs create mode 100644 src/Kestrel/ServerRequest.cs create mode 100644 src/Kestrel/project.json delete mode 100644 src/Microsoft.AspNet.Server.Kestrel/Http/CallContext.cs create mode 100644 src/SampleApp/Startup.cs create mode 100644 test/Microsoft.AspNet.Server.KestralTests/Program.cs diff --git a/KestrelHttpServer.sln b/KestrelHttpServer.sln index fbfe94da08..9f7f3f0bc5 100644 --- a/KestrelHttpServer.sln +++ b/KestrelHttpServer.sln @@ -14,6 +14,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution EndProject Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "SampleApp", "src\SampleApp\SampleApp.kproj", "{2C3CB3DC-EEBF-4F52-9E1C-4F2F972E76C3}" EndProject +Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Kestrel", "src\Kestrel\Kestrel.kproj", "{30B7617E-58EF-4382-B3EA-5B2E718CF1A6}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -32,6 +34,10 @@ Global {2C3CB3DC-EEBF-4F52-9E1C-4F2F972E76C3}.Debug|Any CPU.Build.0 = Debug|Any CPU {2C3CB3DC-EEBF-4F52-9E1C-4F2F972E76C3}.Release|Any CPU.ActiveCfg = Release|Any CPU {2C3CB3DC-EEBF-4F52-9E1C-4F2F972E76C3}.Release|Any CPU.Build.0 = Release|Any CPU + {30B7617E-58EF-4382-B3EA-5B2E718CF1A6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {30B7617E-58EF-4382-B3EA-5B2E718CF1A6}.Debug|Any CPU.Build.0 = Debug|Any CPU + {30B7617E-58EF-4382-B3EA-5B2E718CF1A6}.Release|Any CPU.ActiveCfg = Release|Any CPU + {30B7617E-58EF-4382-B3EA-5B2E718CF1A6}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/src/Kestrel/Kestrel.kproj b/src/Kestrel/Kestrel.kproj new file mode 100644 index 0000000000..63934a9baa --- /dev/null +++ b/src/Kestrel/Kestrel.kproj @@ -0,0 +1,36 @@ + + + + 12.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + + + Debug + AnyCPU + + + + 30b7617e-58ef-4382-b3ea-5b2e718cf1a6 + Library + + + ConsoleDebugger + + + WebDebugger + + + + + 2.0 + + + + + + + + + + + \ No newline at end of file diff --git a/src/Kestrel/ServerFactory.cs b/src/Kestrel/ServerFactory.cs new file mode 100644 index 0000000000..c4f3bf770e --- /dev/null +++ b/src/Kestrel/ServerFactory.cs @@ -0,0 +1,35 @@ +using Microsoft.AspNet.Hosting.Server; +using System; +using Microsoft.AspNet.Builder; +using Microsoft.Framework.ConfigurationModel; +using System.Threading.Tasks; +using Microsoft.AspNet.Server.Kestrel; + +namespace Kestrel +{ + /// + /// Summary description for ServerFactory + /// + public class ServerFactory : IServerFactory + { + public IServerInformation Initialize(IConfiguration configuration) + { + var information = new ServerInformation(); + information.Initialize(configuration); + return information; + } + + public IDisposable Start(IServerInformation serverInformation, Func application) + { + var information = (ServerInformation)serverInformation; + var engine = new KestrelEngine(); + engine.Start(1); + engine.CreateServer(async frame => + { + var request = new ServerRequest(frame); + await application.Invoke(request); + }); + return engine; + } + } +} diff --git a/src/Kestrel/ServerInformation.cs b/src/Kestrel/ServerInformation.cs new file mode 100644 index 0000000000..ac8377a8f1 --- /dev/null +++ b/src/Kestrel/ServerInformation.cs @@ -0,0 +1,21 @@ +using System; +using Microsoft.AspNet.Builder; +using Microsoft.Framework.ConfigurationModel; + +namespace Kestrel +{ + public class ServerInformation : IServerInformation + { + public void Initialize(IConfiguration configuration) + { + } + + public string Name + { + get + { + return "Kestrel"; + } + } + } +} \ No newline at end of file diff --git a/src/Kestrel/ServerRequest.cs b/src/Kestrel/ServerRequest.cs new file mode 100644 index 0000000000..643e464d5f --- /dev/null +++ b/src/Kestrel/ServerRequest.cs @@ -0,0 +1,180 @@ +using Microsoft.AspNet.HttpFeature; +using Microsoft.AspNet.Server.Kestrel.Http; +using System; +using System.Collections.Generic; +using System.IO; + +namespace Kestrel +{ + public class ServerRequest : IHttpRequestFeature, IHttpResponseFeature + { + Frame _frame; + string _scheme; + string _pathBase; + + public ServerRequest(Frame frame) + { + _frame = frame; + } + + string IHttpRequestFeature.Protocol + { + get + { + return _frame.HttpVersion; + } + + set + { + _frame.HttpVersion = value; + } + } + + string IHttpRequestFeature.Scheme + { + get + { + return _scheme ?? "http"; + } + + set + { + _scheme = value; + } + } + + string IHttpRequestFeature.Method + { + get + { + return _frame.Method; + } + + set + { + _frame.Method = value; + } + } + + string IHttpRequestFeature.PathBase + { + get + { + return _pathBase ?? ""; + } + + set + { + _pathBase = value; + } + } + + string IHttpRequestFeature.Path + { + get + { + return _frame.Path; + } + + set + { + _frame.Path = value; + } + } + + string IHttpRequestFeature.QueryString + { + get + { + return _frame.QueryString; + } + + set + { + _frame.QueryString = value; + } + } + + IDictionary IHttpRequestFeature.Headers + { + get + { + return _frame.RequestHeaders; + } + + set + { + _frame.RequestHeaders = value; + } + } + + Stream IHttpRequestFeature.Body + { + get + { + return _frame.RequestBody; + } + + set + { + _frame.RequestBody = value; + } + } + + int IHttpResponseFeature.StatusCode + { + get + { + return _frame.StatusCode; + } + + set + { + _frame.StatusCode = value; + } + } + + string IHttpResponseFeature.ReasonPhrase + { + get + { + return _frame.ReasonPhrase; + } + + set + { + _frame.ReasonPhrase = value; + } + } + + IDictionary IHttpResponseFeature.Headers + { + get + { + return _frame.ResponseHeaders; + } + + set + { + _frame.ResponseHeaders = value; + } + } + + Stream IHttpResponseFeature.Body + { + get + { + return _frame.ResponseBody; + } + + set + { + _frame.ResponseBody = value; + } + } + void IHttpResponseFeature.OnSendingHeaders(Action callback, object state) + { + _frame.OnSendingHeaders(callback, state); + } + } +} diff --git a/src/Kestrel/project.json b/src/Kestrel/project.json new file mode 100644 index 0000000000..75592a1e20 --- /dev/null +++ b/src/Kestrel/project.json @@ -0,0 +1,17 @@ +{ + "version": "0.1-alpha-*", + "dependencies": { + "Microsoft.AspNet.Hosting": "0.1-*", + "Microsoft.AspNet.Server.Kestrel": "0.1-*" + }, + "configurations": { + "net45": { + "dependencies": { } + }, + "k10": { + "dependencies": { + "System.Runtime": "4.0.20.0" + } + } + } +} diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/CallContext.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/CallContext.cs deleted file mode 100644 index 39b11b7ac3..0000000000 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/CallContext.cs +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using Microsoft.AspNet.HttpFeature; -using System; -using System.Collections.Generic; -using System.IO; - -namespace Microsoft.AspNet.Server.Kestrel -{ - /// - /// Summary description for CallContext - /// - public class CallContext : - IHttpRequestFeature, - IHttpResponseFeature - { - public CallContext() - { - ((IHttpResponseFeature)this).StatusCode = 200; - } - - Stream IHttpResponseFeature.Body { get; set; } - - Stream IHttpRequestFeature.Body { get; set; } - - IDictionary IHttpResponseFeature.Headers { get; set; } - - IDictionary IHttpRequestFeature.Headers { get; set; } - - string IHttpRequestFeature.Method { get; set; } - - string IHttpRequestFeature.Path { get; set; } - - string IHttpRequestFeature.PathBase { get; set; } - - string IHttpRequestFeature.Protocol { get; set; } - - string IHttpRequestFeature.QueryString { get; set; } - - string IHttpResponseFeature.ReasonPhrase { get; set; } - - string IHttpRequestFeature.Scheme { get; set; } - - int IHttpResponseFeature.StatusCode { get; set; } - - void IHttpResponseFeature.OnSendingHeaders(Action callback, object state) - { - } - } -} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs index 2104952722..428b0ca6b4 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs @@ -1,9 +1,9 @@ // Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using Microsoft.AspNet.HttpFeature; using System; using System.Collections.Generic; +using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -43,8 +43,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Http public class Frame : FrameContext, IFrameControl { - Mode _mode; - enum Mode { StartLine, @@ -53,41 +51,43 @@ namespace Microsoft.AspNet.Server.Kestrel.Http Terminated, } - - private string _method; - private string _requestUri; - private string _path; - private string _queryString; - private string _httpVersion; - - private readonly IDictionary _requestHeaders = - new Dictionary(StringComparer.OrdinalIgnoreCase); - - readonly IDictionary _responseHeaders = - new Dictionary(StringComparer.OrdinalIgnoreCase); - - private MessageBody _messageBody; + Mode _mode; private bool _resultStarted; private bool _keepAlive; - private CallContext _callContext; /* //IDictionary _environment; CancellationTokenSource _cts = new CancellationTokenSource(); */ - FrameResponseStream _outputStream; - FrameRequestStream _inputStream; - FrameDuplexStream _duplexStream; - Task _upgradeTask = _completedTask; - static readonly Task _completedTask = Task.FromResult(0); + List, object>> _onSendingHeaders; + object _onSendingHeadersSync = new Object(); + Stream _duplexStream; public Frame(ConnectionContext context) : base(context) { FrameControl = this; + StatusCode = 200; + RequestHeaders = new Dictionary(StringComparer.OrdinalIgnoreCase); + ResponseHeaders = new Dictionary(StringComparer.OrdinalIgnoreCase); } + public string Method { get; set; } + public string RequestUri { get; set; } + public string Path { get; set; } + public string QueryString { get; set; } + public string HttpVersion { get; set; } + public IDictionary RequestHeaders { get; set; } + public MessageBody MessageBody { get; set; } + public Stream RequestBody { get; set; } + + public int StatusCode { get; set; } + public string ReasonPhrase { get; set; } + public IDictionary ResponseHeaders { get; set; } + public Stream ResponseBody { get; set; } + + /* public bool LocalIntakeFin { @@ -151,12 +151,12 @@ namespace Microsoft.AspNet.Server.Kestrel.Http break; case Mode.MessageBody: - if (_messageBody.LocalIntakeFin) + if (MessageBody.LocalIntakeFin) { // NOTE: stop reading and resume on keepalive? return; } - _messageBody.Consume(); + MessageBody.Consume(); // NOTE: keep looping? return; @@ -168,23 +168,53 @@ namespace Microsoft.AspNet.Server.Kestrel.Http private void Execute() { - _messageBody = MessageBody.For( - _httpVersion, - _requestHeaders, + MessageBody = MessageBody.For( + HttpVersion, + RequestHeaders, this); - _keepAlive = _messageBody.RequestKeepAlive; - _callContext = CreateCallContext(); + _keepAlive = MessageBody.RequestKeepAlive; + RequestBody = new FrameRequestStream(MessageBody); + ResponseBody = new FrameResponseStream(this); + _duplexStream = new FrameDuplexStream(RequestBody, ResponseBody); SocketInput.Free(); Task.Run(ExecuteAsync); } + public void OnSendingHeaders(Action callback, object state) + { + lock (_onSendingHeadersSync) + { + if (_onSendingHeaders == null) + { + _onSendingHeaders = new List, object>>(); + } + _onSendingHeaders.Add(new KeyValuePair, object>(callback, state)); + } + } + + private void FireOnSendingHeaders() + { + List, object>> onSendingHeaders = null; + lock (_onSendingHeadersSync) + { + onSendingHeaders = _onSendingHeaders; + _onSendingHeaders = null; + } + if (onSendingHeaders != null) + { + foreach (var entry in onSendingHeaders) + { + entry.Key.Invoke(entry.Value); + } + } + } + private async Task ExecuteAsync() { Exception error = null; try { - await Application.Invoke(_callContext); - await _upgradeTask; + await Application.Invoke(this); } catch (Exception ex) { @@ -196,77 +226,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } - private CallContext CreateCallContext() - { - _inputStream = new FrameRequestStream(_messageBody); - _outputStream = new FrameResponseStream(this); - _duplexStream = new FrameDuplexStream(_inputStream, _outputStream); - - var remoteIpAddress = "127.0.0.1"; - var remotePort = "0"; - var localIpAddress = "127.0.0.1"; - var localPort = "80"; - var isLocal = false; - - //if (_context.Socket != null) - //{ - // var remoteEndPoint = _context.Socket.RemoteEndPoint as IPEndPoint; - // if (remoteEndPoint != null) - // { - // remoteIpAddress = remoteEndPoint.Address.ToString(); - // remotePort = remoteEndPoint.Port.ToString(CultureInfo.InvariantCulture); - // } - - // var localEndPoint = _context.Socket.LocalEndPoint as IPEndPoint; - // if (localEndPoint != null) - // { - // localIpAddress = localEndPoint.Address.ToString(); - // localPort = localEndPoint.Port.ToString(CultureInfo.InvariantCulture); - // } - - // if (remoteEndPoint != null && localEndPoint != null) - // { - // isLocal = Equals(remoteEndPoint.Address, localEndPoint.Address); - // } - //} - - var callContext = new CallContext(); - var request = (IHttpRequestFeature)callContext; - var response = (IHttpResponseFeature)callContext; - //var lifetime = (IHttpRequestLifetimeFeature)callContext; - request.Protocol = _httpVersion; - request.Scheme = "http"; - request.Method = _method; - request.Path = _path; - request.PathBase = ""; - request.QueryString = _queryString; - request.Headers = _requestHeaders; - request.Body = _inputStream; - response.Headers = _responseHeaders; - response.Body = _outputStream; - - //var env = new Dictionary(); - //env["owin.Version"] = "1.0"; - //env["owin.RequestProtocol"] = _httpVersion; - //env["owin.RequestScheme"] = "http"; - //env["owin.RequestMethod"] = _method; - //env["owin.RequestPath"] = _path; - //env["owin.RequestPathBase"] = ""; - //env["owin.RequestQueryString"] = _queryString; - //env["owin.RequestHeaders"] = _requestHeaders; - //env["owin.RequestBody"] = _inputStream; - //env["owin.ResponseHeaders"] = _responseHeaders; - //env["owin.ResponseBody"] = _outputStream; - //env["owin.CallCancelled"] = _cts.Token; - //env["opaque.Upgrade"] = (Action, Func, Task>>)Upgrade; - //env["opaque.Stream"] = _duplexStream; - //env["server.RemoteIpAddress"] = remoteIpAddress; - //env["server.RemotePort"] = remotePort; - //env["server.LocalIpAddress"] = localIpAddress; - //env["server.LocalPort"] = localPort; - //env["server.IsLocal"] = isLocal; - return callContext; - } public void Write(ArraySegment data, Action callback, object state) { @@ -279,7 +238,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http _keepAlive = false; ProduceStart(); - _upgradeTask = callback(_callContext); + // NOTE: needs changes + //_upgradeTask = callback(_callContext); } byte[] _continueBytes = Encoding.ASCII.GetBytes("HTTP/1.1 100 Continue\r\n\r\n"); @@ -289,8 +249,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http if (_resultStarted) return; string[] expect; - if (_httpVersion.Equals("HTTP/1.1") && - _requestHeaders.TryGetValue("Expect", out expect) && + if (HttpVersion.Equals("HTTP/1.1") && + RequestHeaders.TryGetValue("Expect", out expect) && (expect.FirstOrDefault() ?? "").Equals("100-continue", StringComparison.OrdinalIgnoreCase)) { SocketOutput.Write(new ArraySegment(_continueBytes, 0, _continueBytes.Length), _ => { }, null); @@ -300,15 +260,13 @@ namespace Microsoft.AspNet.Server.Kestrel.Http public void ProduceStart() { if (_resultStarted) return; - _resultStarted = true; - var response = (IHttpResponseFeature)_callContext; - var status = ReasonPhrases.ToStatus( - response.StatusCode, - response.ReasonPhrase); + FireOnSendingHeaders(); - var responseHeader = CreateResponseHeader(status, _responseHeaders); + var status = ReasonPhrases.ToStatus(StatusCode, ReasonPhrase); + + var responseHeader = CreateResponseHeader(status, ResponseHeaders); SocketOutput.Write(responseHeader.Item1, x => ((IDisposable)x).Dispose(), responseHeader.Item2); } @@ -325,12 +283,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http ConnectionControl.End(_keepAlive ? ProduceEndType.ConnectionKeepAlive : ProduceEndType.SocketDisconnect); } - private Tuple, IDisposable> CreateResponseHeader( string status, IEnumerable> headers) { var writer = new MemoryPoolTextWriter(Memory); - writer.Write(_httpVersion); + writer.Write(HttpVersion); writer.Write(' '); writer.Write(status); writer.Write('\r'); @@ -381,11 +338,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { _keepAlive = false; } - if (_keepAlive == false && hasConnection == false && _httpVersion == "HTTP/1.1") + if (_keepAlive == false && hasConnection == false && HttpVersion == "HTTP/1.1") { writer.Write("Connection: close\r\n\r\n"); } - else if (_keepAlive && hasConnection == false && _httpVersion == "HTTP/1.0") + else if (_keepAlive && hasConnection == false && HttpVersion == "HTTP/1.0") { writer.Write("Connection: keep-alive\r\n\r\n"); } @@ -418,19 +375,19 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { throw new InvalidOperationException("INVALID REQUEST FORMAT"); } - _method = GetString(remaining, 0, firstSpace); - _requestUri = GetString(remaining, firstSpace + 1, secondSpace); + Method = GetString(remaining, 0, firstSpace); + RequestUri = GetString(remaining, firstSpace + 1, secondSpace); if (questionMark == -1) { - _path = _requestUri; - _queryString = string.Empty; + Path = RequestUri; + QueryString = string.Empty; } else { - _path = GetString(remaining, firstSpace + 1, questionMark); - _queryString = GetString(remaining, questionMark, secondSpace); + Path = GetString(remaining, firstSpace + 1, questionMark); + QueryString = GetString(remaining, questionMark, secondSpace); } - _httpVersion = GetString(remaining, secondSpace + 1, index); + HttpVersion = GetString(remaining, secondSpace + 1, index); baton.Skip(index + 2); return true; } @@ -540,15 +497,15 @@ namespace Microsoft.AspNet.Server.Kestrel.Http private void AddRequestHeader(string name, string value) { string[] existing; - if (!_requestHeaders.TryGetValue(name, out existing) || + if (!RequestHeaders.TryGetValue(name, out existing) || existing == null || existing.Length == 0) { - _requestHeaders[name] = new[] { value }; + RequestHeaders[name] = new[] { value }; } else { - _requestHeaders[name] = existing.Concat(new[] { value }).ToArray(); + RequestHeaders[name] = existing.Concat(new[] { value }).ToArray(); } } } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameDuplexStream.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameDuplexStream.cs index f129004b51..6d4276f8eb 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameDuplexStream.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameDuplexStream.cs @@ -10,10 +10,10 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { class FrameDuplexStream : Stream { - readonly FrameRequestStream _requestStream; - readonly FrameResponseStream _responseStream; + readonly Stream _requestStream; + readonly Stream _responseStream; - public FrameDuplexStream(FrameRequestStream requestStream, FrameResponseStream responseStream) + public FrameDuplexStream(Stream requestStream, Stream responseStream) { _requestStream = requestStream; _responseStream = responseStream; diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs index 9bf1413579..1b8a71b25e 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs @@ -21,7 +21,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http public KestrelThread Thread { get; set; } - public Func Application { get; set; } + public Func Application { get; set; } public IMemoryPool Memory { get; set; } } @@ -45,10 +45,10 @@ namespace Microsoft.AspNet.Server.Kestrel.Http Memory = memory; } - public Task StartAsync(KestrelThread thread, Func app) + public Task StartAsync(KestrelThread thread, Func application) { Thread = thread; - Application = app; + Application = application; var tcs = new TaskCompletionSource(); Thread.Post(OnStart, tcs); diff --git a/src/Microsoft.AspNet.Server.Kestrel/KestrelEngine.cs b/src/Microsoft.AspNet.Server.Kestrel/KestrelEngine.cs index 6bebfd1239..6375b45fc6 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/KestrelEngine.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/KestrelEngine.cs @@ -9,7 +9,7 @@ using Microsoft.AspNet.Server.Kestrel.Http; namespace Microsoft.AspNet.Server.Kestrel { - public class KestrelEngine + public class KestrelEngine : IDisposable { public KestrelEngine() @@ -39,7 +39,7 @@ namespace Microsoft.AspNet.Server.Kestrel } } - public void Stop() + public void Dispose() { foreach (var thread in Threads) { @@ -48,13 +48,13 @@ namespace Microsoft.AspNet.Server.Kestrel Threads.Clear(); } - public IDisposable CreateServer(Func app) + public IDisposable CreateServer(Func application) { var listeners = new List(); foreach (var thread in Threads) { var listener = new Listener(Memory); - listener.StartAsync(thread, app).Wait(); + listener.StartAsync(thread, application).Wait(); listeners.Add(listener); } return new Disposable(() => diff --git a/src/Microsoft.AspNet.Server.Kestrel/Microsoft.AspNet.Server.Kestrel.kproj b/src/Microsoft.AspNet.Server.Kestrel/Microsoft.AspNet.Server.Kestrel.kproj index 9ba02d48db..943ae5c366 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Microsoft.AspNet.Server.Kestrel.kproj +++ b/src/Microsoft.AspNet.Server.Kestrel/Microsoft.AspNet.Server.Kestrel.kproj @@ -26,7 +26,6 @@ - diff --git a/src/Microsoft.AspNet.Server.Kestrel/project.json b/src/Microsoft.AspNet.Server.Kestrel/project.json index 6dba34e730..c20f6afdc4 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/project.json +++ b/src/Microsoft.AspNet.Server.Kestrel/project.json @@ -1,7 +1,6 @@ { "version": "0.1-alpha-*", "dependencies": { - "Microsoft.AspNet.Hosting": "0.1-*" }, "configurations": { "net45": { }, @@ -13,7 +12,14 @@ "System.Diagnostics.TraceSource": "4.0.0.0", "System.Text.Encoding": "4.0.20.0", "System.Threading.Tasks": "4.0.10.0", - "System.Diagnostics.Tracing": "4.0.10.0" + "System.Diagnostics.Tracing": "4.0.10.0", + "System.Collections": "4.0.0.0", + "System.IO": "4.0.0.0", + "System.Linq": "4.0.0.0", + "System.Net.Primitives": "4.0.10.0", + "System.Runtime.Extensions": "4.0.10.0", + "System.Threading": "4.0.0.0", + "System.Globalization": "4.0.10.0" } } }, diff --git a/src/SampleApp/Program.cs b/src/SampleApp/Program.cs index 21673112e6..b32fd7577a 100644 --- a/src/SampleApp/Program.cs +++ b/src/SampleApp/Program.cs @@ -1,39 +1,21 @@ using System; -using System.Runtime.InteropServices; -using System.Threading.Tasks; namespace SampleApp { public class Program { - public static void Main(string[] args) + private IServiceProvider _services; + + public Program(IServiceProvider services) { - var engine = new Microsoft.AspNet.Server.Kestrel.KestrelEngine(); - engine.Start(1); - using (var server = engine.CreateServer(App)) - { - Console.WriteLine("Hello World"); - Console.ReadLine(); - } - engine.Stop(); + _services = services; } - - - private static async Task App(object arg) + public void Main(string[] args) { - var httpContext = new Microsoft.AspNet.PipelineCore.DefaultHttpContext( - new Microsoft.AspNet.FeatureModel.FeatureCollection( - new Microsoft.AspNet.FeatureModel.FeatureObject(arg))); - - Console.WriteLine("{0} {1}{2}{3}", - httpContext.Request.Method, - httpContext.Request.PathBase, - httpContext.Request.Path, - httpContext.Request.QueryString); - - httpContext.Response.ContentType = "text/plain"; - await httpContext.Response.WriteAsync("Hello world"); + new Microsoft.AspNet.Hosting.Program(_services).Main(new[] { + "--server","kestrel" + }); } } } diff --git a/src/SampleApp/SampleApp.kproj b/src/SampleApp/SampleApp.kproj index fe5828cdf7..c1ca9168bf 100644 --- a/src/SampleApp/SampleApp.kproj +++ b/src/SampleApp/SampleApp.kproj @@ -24,12 +24,16 @@ 2.0 + + web + + - + \ No newline at end of file diff --git a/src/SampleApp/Startup.cs b/src/SampleApp/Startup.cs new file mode 100644 index 0000000000..acafabf447 --- /dev/null +++ b/src/SampleApp/Startup.cs @@ -0,0 +1,23 @@ +using Microsoft.AspNet.Builder; +using System; + +namespace SampleApp +{ + public class Startup + { + public void Configure(IBuilder app) + { + app.Run(async context => + { + Console.WriteLine("{0} {1}{2}{3}", + context.Request.Method, + context.Request.PathBase, + context.Request.Path, + context.Request.QueryString); + + context.Response.ContentType = "text/plain"; + await context.Response.WriteAsync("Hello world"); + }); + } + } +} \ No newline at end of file diff --git a/src/SampleApp/project.json b/src/SampleApp/project.json index c1110915de..1d23fd79d2 100644 --- a/src/SampleApp/project.json +++ b/src/SampleApp/project.json @@ -1,14 +1,16 @@ { "dependencies": { - "Microsoft.AspNet.Server.Kestrel": "0.1-alpha-*", - "Microsoft.AspNet.PipelineCore": "0.1-alpha-*" + "Kestrel": "0.1-alpha-*" }, - "configurations" : { - "net45" : { }, - "k10" : { + "configurations": { + "net45": { }, + "k10": { "dependencies": { "System.Console": "4.0.0.0" } } + }, + "commands": { + "web": "Microsoft.AspNet.Hosting --server kestrel" } } diff --git a/test/Microsoft.AspNet.Server.KestralTests/EngineTests.cs b/test/Microsoft.AspNet.Server.KestralTests/EngineTests.cs index 414e825277..a40dcaaf70 100644 --- a/test/Microsoft.AspNet.Server.KestralTests/EngineTests.cs +++ b/test/Microsoft.AspNet.Server.KestralTests/EngineTests.cs @@ -1,5 +1,5 @@ -using Microsoft.AspNet.HttpFeature; -using Microsoft.AspNet.Server.Kestrel; +using Microsoft.AspNet.Server.Kestrel; +using Microsoft.AspNet.Server.Kestrel.Http; using System; using System.IO; using System.Net; @@ -15,31 +15,26 @@ namespace Microsoft.AspNet.Server.KestralTests /// public class EngineTests { - private async Task App(object callContext) + private async Task App(Frame frame) { - var request = callContext as IHttpRequestFeature; - var response = callContext as IHttpResponseFeature; for (; ;) { var buffer = new byte[8192]; - var count = await request.Body.ReadAsync(buffer, 0, buffer.Length); + var count = await frame.RequestBody.ReadAsync(buffer, 0, buffer.Length); if (count == 0) { break; } - await response.Body.WriteAsync(buffer, 0, count); + await frame.ResponseBody.WriteAsync(buffer, 0, count); } } - private async Task AppChunked(object callContext) + private async Task AppChunked(Frame frame) { - var request = callContext as IHttpRequestFeature; - var response = callContext as IHttpResponseFeature; - var data = new MemoryStream(); for (; ;) { var buffer = new byte[8192]; - var count = await request.Body.ReadAsync(buffer, 0, buffer.Length); + var count = await frame.RequestBody.ReadAsync(buffer, 0, buffer.Length); if (count == 0) { break; @@ -47,8 +42,8 @@ namespace Microsoft.AspNet.Server.KestralTests data.Write(buffer, 0, count); } var bytes = data.ToArray(); - response.Headers["Content-Length"] = new[] { bytes.Length.ToString() }; - await response.Body.WriteAsync(bytes, 0, bytes.Length); + frame.ResponseHeaders["Content-Length"] = new[] { bytes.Length.ToString() }; + await frame.ResponseBody.WriteAsync(bytes, 0, bytes.Length); } [Fact] @@ -56,7 +51,7 @@ namespace Microsoft.AspNet.Server.KestralTests { var engine = new KestrelEngine(); engine.Start(1); - engine.Stop(); + engine.Dispose(); } [Fact] @@ -66,7 +61,7 @@ namespace Microsoft.AspNet.Server.KestralTests engine.Start(1); var started = engine.CreateServer(App); started.Dispose(); - engine.Stop(); + engine.Dispose(); } @@ -89,7 +84,7 @@ namespace Microsoft.AspNet.Server.KestralTests var text = Encoding.ASCII.GetString(buffer, 0, length); } started.Dispose(); - engine.Stop(); + engine.Dispose(); } [Fact] diff --git a/test/Microsoft.AspNet.Server.KestralTests/Microsoft.AspNet.Server.KestralTests.kproj b/test/Microsoft.AspNet.Server.KestralTests/Microsoft.AspNet.Server.KestralTests.kproj index fab0735264..aecd9b6963 100644 --- a/test/Microsoft.AspNet.Server.KestralTests/Microsoft.AspNet.Server.KestralTests.kproj +++ b/test/Microsoft.AspNet.Server.KestralTests/Microsoft.AspNet.Server.KestralTests.kproj @@ -31,8 +31,10 @@ + + - + \ No newline at end of file diff --git a/test/Microsoft.AspNet.Server.KestralTests/Program.cs b/test/Microsoft.AspNet.Server.KestralTests/Program.cs new file mode 100644 index 0000000000..86ae9b71d7 --- /dev/null +++ b/test/Microsoft.AspNet.Server.KestralTests/Program.cs @@ -0,0 +1,15 @@ +using System; + +namespace Microsoft.AspNet.Server.KestralTests +{ + /// + /// Summary description for Program + /// + public class Program + { + public void Main() + { + new EngineTests().Http11().Wait(); + } + } +} \ No newline at end of file diff --git a/test/Microsoft.AspNet.Server.KestralTests/TestServer.cs b/test/Microsoft.AspNet.Server.KestralTests/TestServer.cs index 4291532317..1efd5d95f5 100644 --- a/test/Microsoft.AspNet.Server.KestralTests/TestServer.cs +++ b/test/Microsoft.AspNet.Server.KestralTests/TestServer.cs @@ -1,4 +1,5 @@ using Microsoft.AspNet.Server.Kestrel; +using Microsoft.AspNet.Server.Kestrel.Http; using System; using System.Threading.Tasks; @@ -12,12 +13,12 @@ namespace Microsoft.AspNet.Server.KestralTests private KestrelEngine _engine; private IDisposable _server; - public TestServer(Func app) + public TestServer(Func app) { Create(app); } - public void Create(Func app) + public void Create(Func app) { _engine = new KestrelEngine(); _engine.Start(1); @@ -28,7 +29,7 @@ namespace Microsoft.AspNet.Server.KestralTests public void Dispose() { _server.Dispose(); - _engine.Stop(); + _engine.Dispose(); } } } \ No newline at end of file diff --git a/test/Microsoft.AspNet.Server.KestralTests/project.json b/test/Microsoft.AspNet.Server.KestralTests/project.json index de7c2275d3..8cb87eaf48 100644 --- a/test/Microsoft.AspNet.Server.KestralTests/project.json +++ b/test/Microsoft.AspNet.Server.KestralTests/project.json @@ -14,12 +14,12 @@ "compilationOptions": { "define": [ "TRACE" ] }, "dependencies": { "System.Net.Sockets": "4.0.0.0", - "System.Runtime.Handles": "4.0.0.0" + "System.Runtime.Handles": "4.0.0.0", + "System.IO": "4.0.0.0" } } }, "commands": { - "run": "Xunit.KRunner -trait x=vs", "test": "Xunit.KRunner" } } From 17e566c5d11362997ee31a2e25686c71cb1b723b Mon Sep 17 00:00:00 2001 From: Louis DeJardin Date: Tue, 17 Jun 2014 22:45:53 -0700 Subject: [PATCH 0015/1662] Adding "server.urls" configuration support to kestrel --- src/Kestrel/Kestrel.kproj | 1 + src/Kestrel/ServerAddress.cs | 10 ++ src/Kestrel/ServerFactory.cs | 24 ++++- src/Kestrel/ServerInformation.cs | 95 ++++++++++++++++++- .../Http/FrameResponseStream.cs | 2 +- .../Http/Listener.cs | 40 ++++---- .../KestrelEngine.cs | 4 +- src/SampleApp/Microsoft.AspNet.Hosting.ini | 4 + src/SampleApp/SampleApp.kproj | 1 + src/SampleApp/project.json | 6 +- .../EngineTests.cs | 6 +- .../TestConnection.cs | 2 +- .../TestServer.cs | 6 +- 13 files changed, 167 insertions(+), 34 deletions(-) create mode 100644 src/Kestrel/ServerAddress.cs create mode 100644 src/SampleApp/Microsoft.AspNet.Hosting.ini diff --git a/src/Kestrel/Kestrel.kproj b/src/Kestrel/Kestrel.kproj index 63934a9baa..0626b83124 100644 --- a/src/Kestrel/Kestrel.kproj +++ b/src/Kestrel/Kestrel.kproj @@ -25,6 +25,7 @@ 2.0 + diff --git a/src/Kestrel/ServerAddress.cs b/src/Kestrel/ServerAddress.cs new file mode 100644 index 0000000000..d5eac3be2b --- /dev/null +++ b/src/Kestrel/ServerAddress.cs @@ -0,0 +1,10 @@ +namespace Kestrel +{ + public class ServerAddress + { + public string Host { get; internal set; } + public string Path { get; internal set; } + public int Port { get; internal set; } + public string Scheme { get; internal set; } + } +} \ No newline at end of file diff --git a/src/Kestrel/ServerFactory.cs b/src/Kestrel/ServerFactory.cs index c4f3bf770e..a84ad1ae6e 100644 --- a/src/Kestrel/ServerFactory.cs +++ b/src/Kestrel/ServerFactory.cs @@ -4,6 +4,7 @@ using Microsoft.AspNet.Builder; using Microsoft.Framework.ConfigurationModel; using System.Threading.Tasks; using Microsoft.AspNet.Server.Kestrel; +using System.Collections.Generic; namespace Kestrel { @@ -21,15 +22,30 @@ namespace Kestrel public IDisposable Start(IServerInformation serverInformation, Func application) { + var disposables = new List(); var information = (ServerInformation)serverInformation; var engine = new KestrelEngine(); engine.Start(1); - engine.CreateServer(async frame => + foreach (var address in information.Addresses) { - var request = new ServerRequest(frame); - await application.Invoke(request); + disposables.Add(engine.CreateServer( + address.Scheme, + address.Host, + address.Port, + async frame => + { + var request = new ServerRequest(frame); + await application.Invoke(request); + })); + } + disposables.Add(engine); + return new Disposable(() => + { + foreach (var disposable in disposables) + { + disposable.Dispose(); + } }); - return engine; } } } diff --git a/src/Kestrel/ServerInformation.cs b/src/Kestrel/ServerInformation.cs index ac8377a8f1..dc0dbc4399 100644 --- a/src/Kestrel/ServerInformation.cs +++ b/src/Kestrel/ServerInformation.cs @@ -1,13 +1,43 @@ using System; using Microsoft.AspNet.Builder; using Microsoft.Framework.ConfigurationModel; +using System.Globalization; +using System.Collections.Generic; namespace Kestrel { public class ServerInformation : IServerInformation { + public ServerInformation() + { + Addresses = new List(); + } + public void Initialize(IConfiguration configuration) { + string urls; + if (!configuration.TryGet("server.urls", out urls)) + { + urls = "http://+:5000/"; + } + foreach (var url in urls.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries)) + { + string scheme; + string host; + int port; + string path; + if (DeconstructUrl(url, out scheme, out host, out port, out path)) + { + Addresses.Add( + new ServerAddress + { + Scheme = scheme, + Host = host, + Port = port, + Path = path + }); + } + } } public string Name @@ -17,5 +47,68 @@ namespace Kestrel return "Kestrel"; } } + + public IList Addresses { get; private set; } + + internal static bool DeconstructUrl( + string url, + out string scheme, + out string host, + out int port, + out string path) + { + url = url ?? string.Empty; + + int delimiterStart1 = url.IndexOf("://", StringComparison.Ordinal); + if (delimiterStart1 < 0) + { + scheme = null; + host = null; + port = 0; + path = null; + return false; + } + int delimiterEnd1 = delimiterStart1 + "://".Length; + + int delimiterStart3 = url.IndexOf("/", delimiterEnd1, StringComparison.Ordinal); + if (delimiterStart3 < 0) + { + delimiterStart3 = url.Length; + } + int delimiterStart2 = url.LastIndexOf(":", delimiterStart3 - 1, delimiterStart3 - delimiterEnd1, StringComparison.Ordinal); + int delimiterEnd2 = delimiterStart2 + ":".Length; + if (delimiterStart2 < 0) + { + delimiterStart2 = delimiterStart3; + delimiterEnd2 = delimiterStart3; + } + + scheme = url.Substring(0, delimiterStart1); + string portString = url.Substring(delimiterEnd2, delimiterStart3 - delimiterEnd2); + int portNumber; + if (int.TryParse(portString, NumberStyles.Integer, CultureInfo.InvariantCulture, out portNumber)) + { + host = url.Substring(delimiterEnd1, delimiterStart2 - delimiterEnd1); + port = portNumber; + } + else + { + if (string.Equals(scheme, "http", StringComparison.OrdinalIgnoreCase)) + { + port = 80; + } + else if (string.Equals(scheme, "https", StringComparison.OrdinalIgnoreCase)) + { + port = 443; + } + else + { + port = 0; + } + host = url.Substring(delimiterEnd1, delimiterStart3 - delimiterEnd1); + } + path = url.Substring(delimiterStart3); + return true; + } } -} \ No newline at end of file +} diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameResponseStream.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameResponseStream.cs index 756304ae0b..dc05b4dd7f 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameResponseStream.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameResponseStream.cs @@ -46,7 +46,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http public override void Write(byte[] buffer, int offset, int count) { - throw new NotImplementedException(); + WriteAsync(buffer, offset, count).Wait(); } public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs index 1b8a71b25e..123336ee6c 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs @@ -45,33 +45,35 @@ namespace Microsoft.AspNet.Server.Kestrel.Http Memory = memory; } - public Task StartAsync(KestrelThread thread, Func application) + public Task StartAsync( + string scheme, + string host, + int port, + KestrelThread thread, + Func application) { Thread = thread; Application = application; var tcs = new TaskCompletionSource(); - Thread.Post(OnStart, tcs); + Thread.Post(_ => + { + try + { + ListenSocket = new UvTcpHandle(); + ListenSocket.Init(Thread.Loop); + ListenSocket.Bind(new IPEndPoint(IPAddress.Any, port)); + ListenSocket.Listen(10, _connectionCallback, this); + tcs.SetResult(0); + } + catch (Exception ex) + { + tcs.SetException(ex); + } + }, null); return tcs.Task; } - public void OnStart(object parameter) - { - var tcs = (TaskCompletionSource)parameter; - try - { - ListenSocket = new UvTcpHandle(); - ListenSocket.Init(Thread.Loop); - ListenSocket.Bind(new IPEndPoint(IPAddress.Any, 4001)); - ListenSocket.Listen(10, _connectionCallback, this); - tcs.SetResult(0); - } - catch (Exception ex) - { - tcs.SetException(ex); - } - } - private void OnConnection(UvStreamHandle listenSocket, int status) { var acceptSocket = new UvTcpHandle(); diff --git a/src/Microsoft.AspNet.Server.Kestrel/KestrelEngine.cs b/src/Microsoft.AspNet.Server.Kestrel/KestrelEngine.cs index 6375b45fc6..78abaa224e 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/KestrelEngine.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/KestrelEngine.cs @@ -48,13 +48,13 @@ namespace Microsoft.AspNet.Server.Kestrel Threads.Clear(); } - public IDisposable CreateServer(Func application) + public IDisposable CreateServer(string scheme, string host, int port, Func application) { var listeners = new List(); foreach (var thread in Threads) { var listener = new Listener(Memory); - listener.StartAsync(thread, application).Wait(); + listener.StartAsync(scheme, host, port, thread, application).Wait(); listeners.Add(listener); } return new Disposable(() => diff --git a/src/SampleApp/Microsoft.AspNet.Hosting.ini b/src/SampleApp/Microsoft.AspNet.Hosting.ini new file mode 100644 index 0000000000..f0def9d26b --- /dev/null +++ b/src/SampleApp/Microsoft.AspNet.Hosting.ini @@ -0,0 +1,4 @@ + +Server=Kestrel +; Server = Microsoft.AspNet.Server.WebListener +Server.Urls = http://localhost:5000/ diff --git a/src/SampleApp/SampleApp.kproj b/src/SampleApp/SampleApp.kproj index c1ca9168bf..35a172e4e1 100644 --- a/src/SampleApp/SampleApp.kproj +++ b/src/SampleApp/SampleApp.kproj @@ -33,6 +33,7 @@ + diff --git a/src/SampleApp/project.json b/src/SampleApp/project.json index 1d23fd79d2..12bc80da47 100644 --- a/src/SampleApp/project.json +++ b/src/SampleApp/project.json @@ -1,6 +1,7 @@ { "dependencies": { - "Kestrel": "0.1-alpha-*" + "Kestrel": "0.1-alpha-*", + "Microsoft.AspNet.Server.WebListener": "0.1-alpha-*" }, "configurations": { "net45": { }, @@ -11,6 +12,7 @@ } }, "commands": { - "web": "Microsoft.AspNet.Hosting --server kestrel" + "run": "Microsoft.AspNet.Hosting", + "web": "Microsoft.AspNet.Hosting" } } diff --git a/test/Microsoft.AspNet.Server.KestralTests/EngineTests.cs b/test/Microsoft.AspNet.Server.KestralTests/EngineTests.cs index a40dcaaf70..e92e2a9b70 100644 --- a/test/Microsoft.AspNet.Server.KestralTests/EngineTests.cs +++ b/test/Microsoft.AspNet.Server.KestralTests/EngineTests.cs @@ -59,7 +59,7 @@ namespace Microsoft.AspNet.Server.KestralTests { var engine = new KestrelEngine(); engine.Start(1); - var started = engine.CreateServer(App); + var started = engine.CreateServer("http", "localhost", 54321, App); started.Dispose(); engine.Dispose(); } @@ -70,10 +70,10 @@ namespace Microsoft.AspNet.Server.KestralTests { var engine = new KestrelEngine(); engine.Start(1); - var started = engine.CreateServer(App); + var started = engine.CreateServer("http", "localhost", 54321, App); var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); - socket.Connect(new IPEndPoint(IPAddress.Loopback, 4001)); + socket.Connect(new IPEndPoint(IPAddress.Loopback, 54321)); socket.Send(Encoding.ASCII.GetBytes("POST / HTTP/1.0\r\n\r\nHello World")); socket.Shutdown(SocketShutdown.Send); var buffer = new byte[8192]; diff --git a/test/Microsoft.AspNet.Server.KestralTests/TestConnection.cs b/test/Microsoft.AspNet.Server.KestralTests/TestConnection.cs index d07e0e4925..a1447fae25 100644 --- a/test/Microsoft.AspNet.Server.KestralTests/TestConnection.cs +++ b/test/Microsoft.AspNet.Server.KestralTests/TestConnection.cs @@ -26,7 +26,7 @@ namespace Microsoft.AspNet.Server.KestralTests public void Create() { _socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); - _socket.Connect(new IPEndPoint(IPAddress.Loopback, 4001)); + _socket.Connect(new IPEndPoint(IPAddress.Loopback, 54321)); _stream = new NetworkStream(_socket, false); _reader = new StreamReader(_stream, Encoding.ASCII); diff --git a/test/Microsoft.AspNet.Server.KestralTests/TestServer.cs b/test/Microsoft.AspNet.Server.KestralTests/TestServer.cs index 1efd5d95f5..4f8a2dd440 100644 --- a/test/Microsoft.AspNet.Server.KestralTests/TestServer.cs +++ b/test/Microsoft.AspNet.Server.KestralTests/TestServer.cs @@ -22,7 +22,11 @@ namespace Microsoft.AspNet.Server.KestralTests { _engine = new KestrelEngine(); _engine.Start(1); - _server = _engine.CreateServer(app); + _server = _engine.CreateServer( + "http", + "localhost", + 54321, + app); } From 9e4bc602051f5854ec52e2fa20fde7b940b0be84 Mon Sep 17 00:00:00 2001 From: Louis DeJardin Date: Fri, 20 Jun 2014 21:09:44 -0700 Subject: [PATCH 0016/1662] Adding amd64 support Moves Libuv.dll into nupkg Uses ILibraryManager to locate location for native libraries Updates version numbers to 1.0.0-* Throws exceptions with error text provided by libuv.dll Bind to ip4 or ip6 endpoints Getting server defaults from ini Enabling "Kestrel" to be used as a Main entrypoint --- src/Kestrel/Kestrel.kproj | 1 + src/Kestrel/Program.cs | 23 +++++++++ src/Kestrel/ServerFactory.cs | 10 +++- src/Kestrel/project.json | 6 +-- .../Http/Listener.cs | 2 +- .../KestrelEngine.cs | 18 ++++++- .../Microsoft.AspNet.Server.Kestrel.kproj | 2 + .../Networking/Libuv.cs | 47 ++++++++++++++++-- .../Networking/UvTcpHandle.cs | 17 ++++++- .../amd64/libuv.dll | Bin 0 -> 137728 bytes .../project.json | 6 ++- .../x86}/libuv.dll | Bin src/SampleApp/Microsoft.AspNet.Hosting.ini | 3 +- src/SampleApp/SampleApp.kproj | 4 +- src/SampleApp/Startup.cs | 1 + src/SampleApp/project.json | 7 +-- .../EngineTests.cs | 19 +++++-- ...Microsoft.AspNet.Server.KestralTests.kproj | 1 - .../NetworkingTests.cs | 16 +++++- .../TestServer.cs | 14 +++++- .../libuv.dll | Bin 317440 -> 0 bytes .../project.json | 7 +-- 22 files changed, 171 insertions(+), 33 deletions(-) create mode 100644 src/Kestrel/Program.cs create mode 100644 src/Microsoft.AspNet.Server.Kestrel/amd64/libuv.dll rename src/{SampleApp => Microsoft.AspNet.Server.Kestrel/x86}/libuv.dll (100%) delete mode 100644 test/Microsoft.AspNet.Server.KestralTests/libuv.dll diff --git a/src/Kestrel/Kestrel.kproj b/src/Kestrel/Kestrel.kproj index 0626b83124..219d40d100 100644 --- a/src/Kestrel/Kestrel.kproj +++ b/src/Kestrel/Kestrel.kproj @@ -25,6 +25,7 @@ 2.0 + diff --git a/src/Kestrel/Program.cs b/src/Kestrel/Program.cs new file mode 100644 index 0000000000..7f877d9002 --- /dev/null +++ b/src/Kestrel/Program.cs @@ -0,0 +1,23 @@ +using System; +using System.Linq; + +namespace Kestrel +{ + public class Program + { + private readonly IServiceProvider _serviceProvider; + + public Program(IServiceProvider serviceProvider) + { + _serviceProvider = serviceProvider; + } + + public void Main(string[] args) + { + var program = new Microsoft.AspNet.Hosting.Program(_serviceProvider); + var mergedArgs = new[] { "--server", "Kestrel" }.Concat(args).ToArray(); + program.Main(mergedArgs); + } + } +} + diff --git a/src/Kestrel/ServerFactory.cs b/src/Kestrel/ServerFactory.cs index a84ad1ae6e..c683d63be6 100644 --- a/src/Kestrel/ServerFactory.cs +++ b/src/Kestrel/ServerFactory.cs @@ -5,6 +5,7 @@ using Microsoft.Framework.ConfigurationModel; using System.Threading.Tasks; using Microsoft.AspNet.Server.Kestrel; using System.Collections.Generic; +using Microsoft.Framework.Runtime; namespace Kestrel { @@ -13,6 +14,13 @@ namespace Kestrel /// public class ServerFactory : IServerFactory { + private readonly ILibraryManager _libraryManager; + + public ServerFactory(ILibraryManager libraryManager) + { + _libraryManager = libraryManager; + } + public IServerInformation Initialize(IConfiguration configuration) { var information = new ServerInformation(); @@ -24,7 +32,7 @@ namespace Kestrel { var disposables = new List(); var information = (ServerInformation)serverInformation; - var engine = new KestrelEngine(); + var engine = new KestrelEngine(_libraryManager); engine.Start(1); foreach (var address in information.Addresses) { diff --git a/src/Kestrel/project.json b/src/Kestrel/project.json index 75592a1e20..2781b38bb3 100644 --- a/src/Kestrel/project.json +++ b/src/Kestrel/project.json @@ -1,8 +1,8 @@ { - "version": "0.1-alpha-*", + "version": "1.0.0-*", "dependencies": { - "Microsoft.AspNet.Hosting": "0.1-*", - "Microsoft.AspNet.Server.Kestrel": "0.1-*" + "Microsoft.AspNet.Hosting": "1.0.0-*", + "Microsoft.AspNet.Server.Kestrel": "1.0.0-*" }, "configurations": { "net45": { diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs index 123336ee6c..111df0065b 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs @@ -62,7 +62,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { ListenSocket = new UvTcpHandle(); ListenSocket.Init(Thread.Loop); - ListenSocket.Bind(new IPEndPoint(IPAddress.Any, port)); + ListenSocket.Bind(new IPEndPoint(IPAddress.IPv6Any, port)); ListenSocket.Listen(10, _connectionCallback, this); tcs.SetResult(0); } diff --git a/src/Microsoft.AspNet.Server.Kestrel/KestrelEngine.cs b/src/Microsoft.AspNet.Server.Kestrel/KestrelEngine.cs index 78abaa224e..257c127f6a 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/KestrelEngine.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/KestrelEngine.cs @@ -6,19 +6,33 @@ using Microsoft.AspNet.Server.Kestrel.Networking; using System.Collections.Generic; using System.Threading.Tasks; using Microsoft.AspNet.Server.Kestrel.Http; +using Microsoft.Framework.Runtime; +using System.IO; namespace Microsoft.AspNet.Server.Kestrel { public class KestrelEngine : IDisposable { - public KestrelEngine() + public KestrelEngine(ILibraryManager libraryManager) { Threads = new List(); Listeners = new List(); Memory = new MemoryPool(); Libuv = new Libuv(); - Libuv.Load("libuv.dll"); + + var library = libraryManager.GetLibraryInformation("Microsoft.AspNet.Server.Kestrel"); + var libraryPath = library.Path; + if (library.Type == "Project") + { + libraryPath = Path.GetDirectoryName(libraryPath); + } + var architecture = IntPtr.Size == 4 + ? "x86" + : "amd64"; + libraryPath = Path.Combine(libraryPath, architecture, "libuv.dll"); + + Libuv.Load(libraryPath); } public Libuv Libuv { get; private set; } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Microsoft.AspNet.Server.Kestrel.kproj b/src/Microsoft.AspNet.Server.Kestrel/Microsoft.AspNet.Server.Kestrel.kproj index 943ae5c366..f860285346 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Microsoft.AspNet.Server.Kestrel.kproj +++ b/src/Microsoft.AspNet.Server.Kestrel/Microsoft.AspNet.Server.Kestrel.kproj @@ -23,7 +23,9 @@ 2.0 + + diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/Libuv.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/Libuv.cs index 7f4bf0eaf0..b326d101ad 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/Libuv.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/Libuv.cs @@ -4,6 +4,7 @@ using System; using System.Reflection; using System.Runtime.InteropServices; +using System.Text; namespace Microsoft.AspNet.Server.Kestrel.Networking { @@ -37,10 +38,27 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking } public int Check(int statusCode) + { + Exception error; + var result = Check(statusCode, out error); + if (error != null) + { + throw error; + } + return statusCode; + } + + public int Check(int statusCode, out Exception error) { if (statusCode < 0) { - throw new Exception("Status code " + statusCode); + var errorName = err_name(statusCode); + var errorDescription = strerror(statusCode); + error = new Exception("Error " + statusCode + " " + errorName + " " + errorDescription); + } + else + { + error = null; } return statusCode; } @@ -234,6 +252,25 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking return _uv_handle_size(handleType); } + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + delegate IntPtr uv_err_name(int err); + uv_err_name _uv_err_name; + public unsafe String err_name(int err) + { + IntPtr ptr = _uv_err_name(err); + return ptr == IntPtr.Zero ? null : Marshal.PtrToStringAnsi(ptr); + } + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + delegate IntPtr uv_strerror(int err); + uv_strerror _uv_strerror; + public unsafe String strerror(int err) + { + IntPtr ptr = _uv_strerror(err); + return ptr == IntPtr.Zero ? null : Marshal.PtrToStringAnsi(ptr); + } + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] delegate int uv_req_size(int handleType); uv_req_size _uv_req_size; @@ -246,18 +283,18 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking delegate int uv_ip4_addr(string ip, int port, out sockaddr addr); uv_ip4_addr _uv_ip4_addr; - public void ip4_addr(string ip, int port, out sockaddr addr) + public int ip4_addr(string ip, int port, out sockaddr addr, out Exception error) { - Check(_uv_ip4_addr(ip, port, out addr)); + return Check(_uv_ip4_addr(ip, port, out addr), out error); } [UnmanagedFunctionPointer(CallingConvention.Cdecl)] delegate int uv_ip6_addr(string ip, int port, out sockaddr addr); uv_ip6_addr _uv_ip6_addr; - public void ip6_addr(string ip, int port, out sockaddr addr) + public int ip6_addr(string ip, int port, out sockaddr addr, out Exception error) { - Check(_uv_ip6_addr(ip, port, out addr)); + return Check(_uv_ip6_addr(ip, port, out addr), out error); } public struct sockaddr diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvTcpHandle.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvTcpHandle.cs index 0962ff650c..187656647f 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvTcpHandle.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvTcpHandle.cs @@ -1,6 +1,7 @@ // Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; using System.Net; namespace Microsoft.AspNet.Server.Kestrel.Networking @@ -16,7 +17,21 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking public void Bind(IPEndPoint endpoint) { Libuv.sockaddr addr; - _uv.ip4_addr(endpoint.Address.ToString(), endpoint.Port, out addr); + var addressText = endpoint.Address.ToString(); + + Exception error1; + _uv.ip4_addr(addressText, endpoint.Port, out addr, out error1); + + if (error1 != null) + { + Exception error2; + _uv.ip6_addr(addressText, endpoint.Port, out addr, out error2); + if (error2 != null) + { + throw error1; + } + } + _uv.tcp_bind(this, ref addr, 0); } } diff --git a/src/Microsoft.AspNet.Server.Kestrel/amd64/libuv.dll b/src/Microsoft.AspNet.Server.Kestrel/amd64/libuv.dll new file mode 100644 index 0000000000000000000000000000000000000000..436ee491a1cd8676e21a144b0000b7a177f02cac GIT binary patch literal 137728 zcmd?Sdwf*I`S`!N!4fVf2n)fYtQs_mmuS2Mkh+@-ISY$KQArgg8jDe>rm!n02nm}M zj>oN7>!q!&)Y^}<_F}b4fLaoQB!D7dRlIyETCKaT7HTUOFP!iDnRCwOf+Dux@9X!+ zFR#qboH=uS=6RlZ=9y>aOu2lyC(GmUWaBK$<7vT{zkvGvik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pW?E$ab zK>y+nfTy%EHeaBw;E4g`RN{b30I^3Q`1Bw=#x3}A;1KQ(@X76_++6VAfPUyIdKv6aSMLVx_iN2 zyOjC1m%4(Z_A3M@d=*_s{(>VwC2qmD0?oLcwkX6##a+M-=z^aVKW@RqObivasUGB-hb_MMuj@%`mdnNqAE%(X4X5Bl$vpV1pbh$IVd8^S~P8$_stK#~r z;LlqI%boNyaO=D2orceH5B)_zWI*n1&)G)*5J&DYUvo8i;+DJka?d`5+i7D$Y)@PR z+zVast-xcrowg*z#>C0jF}9!!7F!V?<96DN5L*(vu6HTV9}RvKcL8p}zXwWi%l-M^ ze%;iq5B&EV>{$CIWdn7@*#SQ8M&owcjSzbhc{jr&;s`DRcHkELD_|FHr)>za8S#@_ z8Sl^qKL`94x6>Ac*oav39ohn2@D)JT+sGdH-rH#l?jG=)z#QCt;8X7~bv^_98BhXU z?P9zG!v8Vgp8)fr^9?^W;=3k(7Wl&NG47zR27en6oqrqn;9aDJUU@e<3b+q9-~Ce) z?=fjT;9dctgZ~6bS^eM}zmI%D7yJ+)^gTiYWb6x`cCT@ZJ(R70#MuV^6QFh74_s;) zpx%LpV6jti7kLW4!@9*Dh1i@By5KjgTm66f$Ju!52XqXrrrc3xefuT!v?SKIgw+)$ za8hb$D)G%ZhiZP85_@> zD&I+JY2t?M3Ui^rltxw_&wRP3r(fjT+)ny$a?3wSrz2&%uOZCIi7nO-MZa<6?pkAI zuw^6fOF7vR3v>pTZYHT5wJ7&(^tF0gq)zi^#u`WR`7@(@!}G=N_#$ODV;JgzdwTE5`M&4-s)u(j|Nn8|{{nlwSRDWW literal 0 HcmV?d00001 diff --git a/src/Microsoft.AspNet.Server.Kestrel/project.json b/src/Microsoft.AspNet.Server.Kestrel/project.json index c20f6afdc4..3435c86826 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/project.json +++ b/src/Microsoft.AspNet.Server.Kestrel/project.json @@ -1,6 +1,7 @@ { - "version": "0.1-alpha-*", + "version": "1.0.0-*", "dependencies": { + "Microsoft.Framework.Runtime.Interfaces": "1.0.0-*" }, "configurations": { "net45": { }, @@ -19,7 +20,8 @@ "System.Net.Primitives": "4.0.10.0", "System.Runtime.Extensions": "4.0.10.0", "System.Threading": "4.0.0.0", - "System.Globalization": "4.0.10.0" + "System.Globalization": "4.0.10.0", + "System.Runtime.InteropServices": "4.0.20.0" } } }, diff --git a/src/SampleApp/libuv.dll b/src/Microsoft.AspNet.Server.Kestrel/x86/libuv.dll similarity index 100% rename from src/SampleApp/libuv.dll rename to src/Microsoft.AspNet.Server.Kestrel/x86/libuv.dll diff --git a/src/SampleApp/Microsoft.AspNet.Hosting.ini b/src/SampleApp/Microsoft.AspNet.Hosting.ini index f0def9d26b..3992612903 100644 --- a/src/SampleApp/Microsoft.AspNet.Hosting.ini +++ b/src/SampleApp/Microsoft.AspNet.Hosting.ini @@ -1,4 +1,3 @@  -Server=Kestrel -; Server = Microsoft.AspNet.Server.WebListener +Server = Microsoft.AspNet.Server.WebListener Server.Urls = http://localhost:5000/ diff --git a/src/SampleApp/SampleApp.kproj b/src/SampleApp/SampleApp.kproj index 35a172e4e1..a49005a910 100644 --- a/src/SampleApp/SampleApp.kproj +++ b/src/SampleApp/SampleApp.kproj @@ -25,14 +25,14 @@ 2.0 - web + + - diff --git a/src/SampleApp/Startup.cs b/src/SampleApp/Startup.cs index acafabf447..9eba33a386 100644 --- a/src/SampleApp/Startup.cs +++ b/src/SampleApp/Startup.cs @@ -15,6 +15,7 @@ namespace SampleApp context.Request.Path, context.Request.QueryString); + context.Response.ContentLength = 11; context.Response.ContentType = "text/plain"; await context.Response.WriteAsync("Hello world"); }); diff --git a/src/SampleApp/project.json b/src/SampleApp/project.json index 12bc80da47..19174804d7 100644 --- a/src/SampleApp/project.json +++ b/src/SampleApp/project.json @@ -1,7 +1,8 @@ { + "version": "1.0.0-*", "dependencies": { - "Kestrel": "0.1-alpha-*", - "Microsoft.AspNet.Server.WebListener": "0.1-alpha-*" + "Kestrel": "1.0.0-*", + "Microsoft.AspNet.Server.WebListener": "1.0.0-*" }, "configurations": { "net45": { }, @@ -12,7 +13,7 @@ } }, "commands": { - "run": "Microsoft.AspNet.Hosting", + "run": "Kestrel", "web": "Microsoft.AspNet.Hosting" } } diff --git a/test/Microsoft.AspNet.Server.KestralTests/EngineTests.cs b/test/Microsoft.AspNet.Server.KestralTests/EngineTests.cs index e92e2a9b70..8873de5041 100644 --- a/test/Microsoft.AspNet.Server.KestralTests/EngineTests.cs +++ b/test/Microsoft.AspNet.Server.KestralTests/EngineTests.cs @@ -1,5 +1,7 @@ using Microsoft.AspNet.Server.Kestrel; using Microsoft.AspNet.Server.Kestrel.Http; +using Microsoft.Framework.Runtime; +using Microsoft.Framework.Runtime.Infrastructure; using System; using System.IO; using System.Net; @@ -28,6 +30,17 @@ namespace Microsoft.AspNet.Server.KestralTests await frame.ResponseBody.WriteAsync(buffer, 0, count); } } + + ILibraryManager LibraryManager + { + get + { + var services = CallContextServiceLocator.Locator.ServiceProvider; + return (ILibraryManager)services.GetService(typeof(ILibraryManager)); + } + } + + private async Task AppChunked(Frame frame) { var data = new MemoryStream(); @@ -49,7 +62,7 @@ namespace Microsoft.AspNet.Server.KestralTests [Fact] public async Task EngineCanStartAndStop() { - var engine = new KestrelEngine(); + var engine = new KestrelEngine(LibraryManager); engine.Start(1); engine.Dispose(); } @@ -57,7 +70,7 @@ namespace Microsoft.AspNet.Server.KestralTests [Fact] public async Task ListenerCanCreateAndDispose() { - var engine = new KestrelEngine(); + var engine = new KestrelEngine(LibraryManager); engine.Start(1); var started = engine.CreateServer("http", "localhost", 54321, App); started.Dispose(); @@ -68,7 +81,7 @@ namespace Microsoft.AspNet.Server.KestralTests [Fact] public async Task ConnectionCanReadAndWrite() { - var engine = new KestrelEngine(); + var engine = new KestrelEngine(LibraryManager); engine.Start(1); var started = engine.CreateServer("http", "localhost", 54321, App); diff --git a/test/Microsoft.AspNet.Server.KestralTests/Microsoft.AspNet.Server.KestralTests.kproj b/test/Microsoft.AspNet.Server.KestralTests/Microsoft.AspNet.Server.KestralTests.kproj index aecd9b6963..78011f5326 100644 --- a/test/Microsoft.AspNet.Server.KestralTests/Microsoft.AspNet.Server.KestralTests.kproj +++ b/test/Microsoft.AspNet.Server.KestralTests/Microsoft.AspNet.Server.KestralTests.kproj @@ -24,7 +24,6 @@ - diff --git a/test/Microsoft.AspNet.Server.KestralTests/NetworkingTests.cs b/test/Microsoft.AspNet.Server.KestralTests/NetworkingTests.cs index 90860a6a8b..f2994a1e85 100644 --- a/test/Microsoft.AspNet.Server.KestralTests/NetworkingTests.cs +++ b/test/Microsoft.AspNet.Server.KestralTests/NetworkingTests.cs @@ -1,7 +1,10 @@ // Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using Microsoft.AspNet.Server.Kestrel; using Microsoft.AspNet.Server.Kestrel.Networking; +using Microsoft.Framework.Runtime; +using Microsoft.Framework.Runtime.Infrastructure; using System; using System.Net; using System.Net.Sockets; @@ -19,8 +22,17 @@ namespace Microsoft.AspNet.Server.KestralTests Libuv _uv; public NetworkingTests() { - _uv = new Libuv(); - _uv.Load("libuv.dll"); + var engine = new KestrelEngine(LibraryManager); + _uv = engine.Libuv; + } + + ILibraryManager LibraryManager + { + get + { + var services = CallContextServiceLocator.Locator.ServiceProvider; + return (ILibraryManager)services.GetService(typeof(ILibraryManager)); + } } [Fact] diff --git a/test/Microsoft.AspNet.Server.KestralTests/TestServer.cs b/test/Microsoft.AspNet.Server.KestralTests/TestServer.cs index 4f8a2dd440..e947f6b866 100644 --- a/test/Microsoft.AspNet.Server.KestralTests/TestServer.cs +++ b/test/Microsoft.AspNet.Server.KestralTests/TestServer.cs @@ -1,5 +1,7 @@ using Microsoft.AspNet.Server.Kestrel; using Microsoft.AspNet.Server.Kestrel.Http; +using Microsoft.Framework.Runtime; +using Microsoft.Framework.Runtime.Infrastructure; using System; using System.Threading.Tasks; @@ -18,16 +20,24 @@ namespace Microsoft.AspNet.Server.KestralTests Create(app); } + ILibraryManager LibraryManager + { + get + { + var services = CallContextServiceLocator.Locator.ServiceProvider; + return (ILibraryManager)services.GetService(typeof(ILibraryManager)); + } + } + public void Create(Func app) { - _engine = new KestrelEngine(); + _engine = new KestrelEngine(LibraryManager); _engine.Start(1); _server = _engine.CreateServer( "http", "localhost", 54321, app); - } public void Dispose() diff --git a/test/Microsoft.AspNet.Server.KestralTests/libuv.dll b/test/Microsoft.AspNet.Server.KestralTests/libuv.dll deleted file mode 100644 index d3a583471805a26c08d10de032d0efb67350ed3e..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 317440 zcmeFa4|r6?)jxidEU@6hE|5UPs6i2;{1GK;FrZ0bH6p7UB#Mdx3N!=+gk3=-LRg}# zYg)9>YPA(DDk^QUQdul&pwR>y`v&EGO)IT|M%{JOHnp)vjqdOBIdkvk?q=g_zwi5f z>i79&pJ(=-JAcodIdkUB%$d2a8@6g`nxllu{D1wQHAT|~o&M4wZEycK zM+Q@7zBzJs*^<@SD_5=f&Z-5sW#77B`SKN>>{}LPuktR>Ua~xU`qkHD-?n1mq6q^B z4j83ponH0Jr`#>aJ~78R-ZEblN<4L zxBT&w7x2t}aLOlF$y58J1kamZ>?hCc2UF!aYssx;ETg9yxt*FeGo_za{>8o57;&1l z)R8Bp*fgyJ6gr{%{t>VPu!9r>L^xH``tl7wAtK|(p6Ye}T^8*J znV|QtEZY4HZnkJsBx}Byer*%JM!PQ*3+3Q&y+Dw?*n9|CqD9%!R& zjL#79Y9=gE5yxjC95`yH;kl_>yn+dyWvdaQ^=DCy2xk=LYx)&1zg4SO-3mXUT{FVj z5IeiYE10lq(XthY_~dwmw;_B2p3ioRR|MbxU;G;Q3tziZ)55o3iN6CE;_tfhR4x40 zcLCi7-U#p7nWBZSnSsBbT#nb1!G_`7*@*Hz5Hb9RD*<^c0d2ese~+xf-v{&Y_rNV_ zTKL$#fSv~9gog~n-XI2uHzZZ$DG)d=h_uI~DP67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%^JArc? z0n1#5J1UQH76ELz92E*gr5!$4;cd@PNJlkq6zX}C;nikiTrC9Bu(`rb!VdV7eBmfq z!}Cs+#I6K90#*wUD~N#}yw*bG9KJpjRj&xKvi!1Bow+LCfDQcyL{>$q3D#|-G6tAz z8gk)z%BQFouff>d3SVwF_A0J@~1E z;I9j%hN!fDBA)>dTUL2dsRhry4!(OEG}thS_EdaC{*Y9|}?1E}&eplvWe={3y0NQAFg=hPhB8SfRa zxw_HG$VA;?Ie4dLrh%M%0qJF^D+?fM0OUt3c9FDUIMFOkT*zw)F<9SY}*88G7$46CSsmM4p31Z_|XFH z9OuPr{7ilo|FU3#uULafyjM6Z90NLT0>145Di)(rlRhAw27mnnDv0-_2hs$2iu^Hh zg{o>jR4WLuuZif^MSTNRvn=EY@2WG^xfo@K)N}BYPt?j90jdhtUO`nUT^s6D82wR+ zsjD|aU85sV@c?}j=0%+WlJTacQElR=3Y2Ki4alJ5=wv$G@&5}^eOwJb*3P;2I*h?7 zpysRe2J+kAFyF}=vz;n9m7E}l7v(U^$poJ62!GZCsJfq1!^<#+V`h_`0nfm!rUjVO z^f_iUZGgw#37>r!IOjC*^AE;NAiD?fa=vC6hYPE1HbAtovtP zsjGE%&`Mux0FYxkFxDub$H~Btv#t3KleHQVoT-R?<={@s@f8Io0(%qT^tIM_JAi1I3L~bFovLGumm4ktb!sKx9v(G$k o0&?X=sNL^&Z0Qc>(%7?BSi5rY{NHm8JlDW;4LsMte*q2r4;T>E Date: Fri, 20 Jun 2014 21:59:11 -0700 Subject: [PATCH 0017/1662] Adding native dlls in custom build step --- build.cmd | 2 +- build/_custom-goals.shade | 15 +++++++++++++++ makefile.shade | 1 + 3 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 build/_custom-goals.shade diff --git a/build.cmd b/build.cmd index 903d532df3..7987edb77d 100644 --- a/build.cmd +++ b/build.cmd @@ -23,4 +23,4 @@ CALL packages\KoreBuild\build\kvm install default -svrc50 -x86 :run CALL packages\KoreBuild\build\kvm use default -svr50 -x86 -packages\Sake\tools\Sake.exe -I packages\KoreBuild\build -f makefile.shade %* +packages\Sake\tools\Sake.exe -I build -I packages\KoreBuild\build -f makefile.shade %* diff --git a/build/_custom-goals.shade b/build/_custom-goals.shade new file mode 100644 index 0000000000..f05bf30713 --- /dev/null +++ b/build/_custom-goals.shade @@ -0,0 +1,15 @@ +use assembly="System.IO.Compression.FileSystem, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" +use assembly="System.IO.Compression, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" +use namespace="System.IO" +use namespace="System.IO.Compression" +use namespace="System.Net" + +#add-files target="compile" + var each='var nupkgFile in Files.Include("artifacts\\build\\Microsoft.AspNet.Server.Kestrel.*.nupkg").Where(x=>!x.EndsWith("symbols.nupkg"))' + log info='Adding content to ${nupkgFile}' + var archive='${ZipFile.Open(nupkgFile, ZipArchiveMode.Update)}' + @{ + archive.CreateEntryFromFile("src/Microsoft.AspNet.Server.Kestrel/amd64/libuv.dll", "amd64/libuv.dll"); + archive.CreateEntryFromFile("src/Microsoft.AspNet.Server.Kestrel/x86/libuv.dll", "x86/libuv.dll"); + archive.Dispose(); + } diff --git a/makefile.shade b/makefile.shade index 6357ea2841..0fad94bacc 100644 --- a/makefile.shade +++ b/makefile.shade @@ -5,3 +5,4 @@ var AUTHORS='Microsoft' use-standard-lifecycle k-standard-goals +custom-goals From 63637be07365d247eff9d72d17957095d3b3fbb8 Mon Sep 17 00:00:00 2001 From: Louis DeJardin Date: Wed, 25 Jun 2014 20:57:12 -0700 Subject: [PATCH 0018/1662] Listener.Dispose should block until operation is complete --- .../Http/Listener.cs | 23 ++++++++++++++----- 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs index 111df0065b..588966e005 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs @@ -86,13 +86,24 @@ namespace Microsoft.AspNet.Server.Kestrel.Http public void Dispose() { - Thread.Post(OnDispose, ListenSocket); + Console.WriteLine("Listener.Dispose"); + var tcs = new TaskCompletionSource(); + Thread.Post( + _ => + { + try + { + ListenSocket.Dispose(); + tcs.SetResult(0); + } + catch (Exception ex) + { + tcs.SetException(ex); + } + }, + null); + tcs.Task.Wait(); ListenSocket = null; } - - private void OnDispose(object listenSocket) - { - ((UvHandle)listenSocket).Dispose(); - } } } From 08a3685f53f7272bf457a8d71d1a30694c5016d6 Mon Sep 17 00:00:00 2001 From: Louis DeJardin Date: Fri, 27 Jun 2014 19:33:48 -0700 Subject: [PATCH 0019/1662] Moving native resources, updating loading code --- build/_custom-goals.shade | 11 ++++- .../KestrelEngine.cs | 42 +++++++++++++----- .../native/darwin/universal/libuv.dylib | Bin 0 -> 273620 bytes .../{ => native/windows}/amd64/libuv.dll | Bin .../{ => native/windows}/x86/libuv.dll | Bin 5 files changed, 41 insertions(+), 12 deletions(-) create mode 100755 src/Microsoft.AspNet.Server.Kestrel/native/darwin/universal/libuv.dylib rename src/Microsoft.AspNet.Server.Kestrel/{ => native/windows}/amd64/libuv.dll (100%) rename src/Microsoft.AspNet.Server.Kestrel/{ => native/windows}/x86/libuv.dll (100%) diff --git a/build/_custom-goals.shade b/build/_custom-goals.shade index f05bf30713..be70db8ae0 100644 --- a/build/_custom-goals.shade +++ b/build/_custom-goals.shade @@ -9,7 +9,14 @@ use namespace="System.Net" log info='Adding content to ${nupkgFile}' var archive='${ZipFile.Open(nupkgFile, ZipArchiveMode.Update)}' @{ - archive.CreateEntryFromFile("src/Microsoft.AspNet.Server.Kestrel/amd64/libuv.dll", "amd64/libuv.dll"); - archive.CreateEntryFromFile("src/Microsoft.AspNet.Server.Kestrel/x86/libuv.dll", "x86/libuv.dll"); + archive.CreateEntryFromFile( + "src/Microsoft.AspNet.Server.Kestrel/native/windows/amd64/libuv.dll", + "native/windows/amd64/libuv.dll"); + archive.CreateEntryFromFile( + "src/Microsoft.AspNet.Server.Kestrel/native/windows/x86/libuv.dll", + "native/windows/x86/libuv.dll"); + archive.CreateEntryFromFile( + "src/Microsoft.AspNet.Server.Kestrel/native/darwin/universal/libuv.dylib", + "native/darwin/universal/libuv.dylib"); archive.Dispose(); } diff --git a/src/Microsoft.AspNet.Server.Kestrel/KestrelEngine.cs b/src/Microsoft.AspNet.Server.Kestrel/KestrelEngine.cs index 257c127f6a..dec882350c 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/KestrelEngine.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/KestrelEngine.cs @@ -21,17 +21,39 @@ namespace Microsoft.AspNet.Server.Kestrel Memory = new MemoryPool(); Libuv = new Libuv(); - var library = libraryManager.GetLibraryInformation("Microsoft.AspNet.Server.Kestrel"); - var libraryPath = library.Path; - if (library.Type == "Project") - { - libraryPath = Path.GetDirectoryName(libraryPath); - } - var architecture = IntPtr.Size == 4 - ? "x86" - : "amd64"; - libraryPath = Path.Combine(libraryPath, architecture, "libuv.dll"); + var libraryPath = default(string); + if (libraryManager != null) + { + var library = libraryManager.GetLibraryInformation("Microsoft.AspNet.Server.Kestrel"); + libraryPath = library.Path; + if (library.Type == "Project") + { + libraryPath = Path.GetDirectoryName(libraryPath); + } + if (Libuv.IsWindows) + { + var architecture = IntPtr.Size == 4 + ? "x86" + : "amd64"; + + libraryPath = Path.Combine( + libraryPath, + "native", + "windows", + architecture, + "libuv.dll"); + } + else + { + libraryPath = Path.Combine( + libraryPath, + "native", + "darwin", + "universal", + "libuv.dylib"); + } + } Libuv.Load(libraryPath); } diff --git a/src/Microsoft.AspNet.Server.Kestrel/native/darwin/universal/libuv.dylib b/src/Microsoft.AspNet.Server.Kestrel/native/darwin/universal/libuv.dylib new file mode 100755 index 0000000000000000000000000000000000000000..cb7ccee0086477d9d482c5396df627f6ac58cc5a GIT binary patch literal 273620 zcmeFa3w%_?+4#Q;2`mygK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L6Hf)v`mCPL4h!+Xf!O>iVmO5 zCY44MX*Vv3(GLEb%M`PyMwy)A6;#0RD_Xyxp^X^ul>uxIP{lRs?q5EL=bu=~T?XxE zTfy<)CX`qHn?-euf9<^w|EBmTCjL#UAgv17Ri7otgGa8SBd~6F|JJv-q_=ghyHgZm zDC4ZzuwEsGQxQZJf@Y3Bi_Qczk!C(%U~6OBYGwjvlYT{6o{6m6%PjGh6nl8ZdfSM= IyrVJyAJytd+yDRo literal 0 HcmV?d00001 diff --git a/src/Microsoft.AspNet.Server.Kestrel/amd64/libuv.dll b/src/Microsoft.AspNet.Server.Kestrel/native/windows/amd64/libuv.dll similarity index 100% rename from src/Microsoft.AspNet.Server.Kestrel/amd64/libuv.dll rename to src/Microsoft.AspNet.Server.Kestrel/native/windows/amd64/libuv.dll diff --git a/src/Microsoft.AspNet.Server.Kestrel/x86/libuv.dll b/src/Microsoft.AspNet.Server.Kestrel/native/windows/x86/libuv.dll similarity index 100% rename from src/Microsoft.AspNet.Server.Kestrel/x86/libuv.dll rename to src/Microsoft.AspNet.Server.Kestrel/native/windows/x86/libuv.dll From 9c29ccdd32dc8708cea22e04f21cac741bc77676 Mon Sep 17 00:00:00 2001 From: Louis DeJardin Date: Fri, 27 Jun 2014 19:45:31 -0700 Subject: [PATCH 0020/1662] Cross-platform LoadLibrary, adjusting libuv apis --- .../Networking/Libuv.cs | 135 +++++++++++++----- .../Networking/PlatformApis.cs | 90 ++++++++++++ .../Networking/UcAsyncHandle.cs | 2 +- .../Networking/UvLoopHandle.cs | 2 +- .../Networking/UvMemory.cs | 5 +- .../Networking/UvShutdownReq.cs | 2 +- .../Networking/UvTcpHandle.cs | 2 +- .../Networking/UvWriteRequest.cs | 39 ++++- 8 files changed, 237 insertions(+), 40 deletions(-) create mode 100644 src/Microsoft.AspNet.Server.Kestrel/Networking/PlatformApis.cs diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/Libuv.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/Libuv.cs index b326d101ad..18e9478f86 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/Libuv.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/Libuv.cs @@ -10,20 +10,20 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking { public class Libuv { - private IntPtr _module = IntPtr.Zero; - - [DllImport("kernel32")] - public static extern IntPtr LoadLibrary(string dllToLoad); - - [DllImport("kernel32", CharSet = CharSet.Ansi, ExactSpelling = true, SetLastError = true)] - public static extern IntPtr GetProcAddress(IntPtr hModule, string procedureName); - - [DllImport("kernel32")] - public static extern bool FreeLibrary(IntPtr hModule); + public Libuv() + { + IsWindows = PlatformApis.IsWindows(); + } + public bool IsWindows; + public Func LoadLibrary; + public Func FreeLibrary; + public Func GetProcAddress; public void Load(string dllToLoad) { + PlatformApis.Apply(this); + var module = LoadLibrary(dllToLoad); foreach (var field in GetType().GetTypeInfo().DeclaredFields) { @@ -78,7 +78,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking public void loop_close(UvLoopHandle handle) { handle.Validate(closed: true); - Check(_uv_loop_close(handle.DangerousGetHandle())); + Check(_uv_loop_close(handle.InternalGetHandle())); } [UnmanagedFunctionPointer(CallingConvention.Cdecl)] @@ -126,7 +126,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking public void close(UvHandle handle, uv_close_cb close_cb) { handle.Validate(closed: true); - _uv_close(handle.DangerousGetHandle(), close_cb); + _uv_close(handle.InternalGetHandle(), close_cb); } [UnmanagedFunctionPointer(CallingConvention.Cdecl)] @@ -223,9 +223,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking [UnmanagedFunctionPointer(CallingConvention.Cdecl)] public delegate void uv_write_cb(IntPtr req, int status); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - delegate int uv_write(UvWriteReq req, UvStreamHandle handle, Libuv.uv_buf_t[] bufs, int nbufs, uv_write_cb cb); + unsafe delegate int uv_write(UvWriteReq req, UvStreamHandle handle, Libuv.uv_buf_t* bufs, int nbufs, uv_write_cb cb); uv_write _uv_write; - public void write(UvWriteReq req, UvStreamHandle handle, Libuv.uv_buf_t[] bufs, int nbufs, uv_write_cb cb) + unsafe public void write(UvWriteReq req, UvStreamHandle handle, Libuv.uv_buf_t* bufs, int nbufs, uv_write_cb cb) { req.Validate(); handle.Validate(); @@ -244,14 +244,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking Check(_uv_shutdown(req, handle, cb)); } - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - delegate int uv_handle_size(int handleType); - uv_handle_size _uv_handle_size; - public int handle_size(int handleType) - { - return _uv_handle_size(handleType); - } - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] delegate IntPtr uv_err_name(int err); uv_err_name _uv_err_name; @@ -270,13 +262,28 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking return ptr == IntPtr.Zero ? null : Marshal.PtrToStringAnsi(ptr); } + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + delegate int uv_loop_size(); + uv_loop_size _uv_loop_size; + public int loop_size() + { + return _uv_loop_size(); + } [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - delegate int uv_req_size(int handleType); - uv_req_size _uv_req_size; - public int req_size(int handleType) + delegate int uv_handle_size(HandleType handleType); + uv_handle_size _uv_handle_size; + public int handle_size(HandleType handleType) { - return _uv_req_size(handleType); + return _uv_handle_size(handleType); + } + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + delegate int uv_req_size(RequestType reqType); + uv_req_size _uv_req_size; + public int req_size(RequestType reqType) + { + return _uv_req_size(reqType); } [UnmanagedFunctionPointer(CallingConvention.Cdecl)] @@ -297,20 +304,84 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking return Check(_uv_ip6_addr(ip, port, out addr), out error); } + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + public delegate void uv_walk_cb(IntPtr handle, IntPtr arg); + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + unsafe delegate int uv_walk(UvLoopHandle loop, uv_walk_cb walk_cb, IntPtr arg); + uv_walk _uv_walk; + unsafe public void walk(UvLoopHandle loop, uv_walk_cb walk_cb, IntPtr arg) + { + loop.Validate(); + _uv_walk(loop, walk_cb, arg); + } + + public uv_buf_t buf_init(IntPtr memory, int len) + { + return new uv_buf_t(memory, len, IsWindows); + } + public struct sockaddr { - long w; - long x; - long y; - long z; + long x0; + long x1; + long x2; + long x3; } public struct uv_buf_t { - public uint len; - public IntPtr memory; + public uv_buf_t(IntPtr memory, int len, bool IsWindows) + { + if (IsWindows) + { + x0 = (IntPtr)len; + x1 = memory; + } + else + { + x0 = memory; + x1 = (IntPtr)len; + } + } + + public IntPtr x0; + public IntPtr x1; } + public enum HandleType + { + Unknown = 0, + ASYNC, + CHECK, + FS_EVENT, + FS_POLL, + HANDLE, + IDLE, + NAMED_PIPE, + POLL, + PREPARE, + PROCESS, + STREAM, + TCP, + TIMER, + TTY, + UDP, + SIGNAL, + } + + public enum RequestType + { + Unknown = 0, + REQ, + CONNECT, + WRITE, + SHUTDOWN, + UDP_SEND, + FS, + WORK, + GETADDRINFO, + GETNAMEINFO, + } //int handle_size_async; //int handle_size_tcp; //int req_size_write; diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/PlatformApis.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/PlatformApis.cs new file mode 100644 index 0000000000..e55e16577e --- /dev/null +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/PlatformApis.cs @@ -0,0 +1,90 @@ +// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Reflection; +using System.Runtime.InteropServices; +using System.Text; + +namespace Microsoft.AspNet.Server.Kestrel.Networking +{ + public static class PlatformApis + { + public static bool IsWindows() + { + var p = (int)Environment.OSVersion.Platform; + return (p != 4) && (p != 6) && (p != 128); + } + + public static void Apply(Libuv libuv) + { + if (libuv.IsWindows) + { + WindowsApis.Apply(libuv); + } + else + { + LinuxApis.Apply(libuv); + } + } + + public static class WindowsApis + { + [DllImport("kernel32")] + public static extern IntPtr LoadLibrary(string dllToLoad); + + [DllImport("kernel32")] + public static extern bool FreeLibrary(IntPtr hModule); + + [DllImport("kernel32", CharSet = CharSet.Ansi, ExactSpelling = true, SetLastError = true)] + public static extern IntPtr GetProcAddress(IntPtr hModule, string procedureName); + + public static void Apply(Libuv libuv) + { + libuv.LoadLibrary = LoadLibrary; + libuv.FreeLibrary = FreeLibrary; + libuv.GetProcAddress = GetProcAddress; + } + } + + public static class LinuxApis + { + [DllImport("libdl")] + public static extern IntPtr dlopen(String fileName, int flags); + + [DllImport("libdl")] + public static extern IntPtr dlsym(IntPtr handle, String symbol); + + [DllImport("libdl")] + public static extern int dlclose(IntPtr handle); + + [DllImport("libdl")] + public static extern IntPtr dlerror(); + + public static IntPtr LoadLibrary(string dllToLoad) + { + return dlopen(dllToLoad, 2); + } + + public static bool FreeLibrary(IntPtr hModule) + { + return dlclose(hModule) == 0; + } + + public static IntPtr GetProcAddress(IntPtr hModule, string procedureName) + { + dlerror(); + var res = dlsym(hModule, procedureName); + var errPtr = dlerror(); + return errPtr == IntPtr.Zero ? res : IntPtr.Zero; + } + + public static void Apply(Libuv libuv) + { + libuv.LoadLibrary = LoadLibrary; + libuv.FreeLibrary = FreeLibrary; + libuv.GetProcAddress = GetProcAddress; + } + } + } +} diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/UcAsyncHandle.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/UcAsyncHandle.cs index e30cbe63ba..7709ebd50c 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/UcAsyncHandle.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/UcAsyncHandle.cs @@ -12,7 +12,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking public void Init(UvLoopHandle loop, Action callback) { - CreateHandle(loop, 256); + CreateHandle(loop, loop.Libuv.handle_size(Libuv.HandleType.ASYNC)); _callback = callback; _uv.async_init(loop, this, _uv_async_cb); } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvLoopHandle.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvLoopHandle.cs index ec87e7db56..9ea5cb3d8a 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvLoopHandle.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvLoopHandle.cs @@ -9,7 +9,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking { public void Init(Libuv uv) { - CreateHandle(uv, 256); + CreateHandle(uv, uv.loop_size()); _uv.loop_init(this); } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvMemory.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvMemory.cs index 661445c2e3..6000c82ebb 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvMemory.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvMemory.cs @@ -45,6 +45,10 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking _threadId = loop._threadId; } + internal IntPtr InternalGetHandle() + { + return handle; + } public void Validate(bool closed = false) { @@ -53,7 +57,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking Trace.Assert(_threadId == Thread.CurrentThread.ManagedThreadId, "ThreadId is correct"); } - unsafe protected static void DestroyHandle(IntPtr memory) { var gcHandlePtr = *(IntPtr*)memory; diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvShutdownReq.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvShutdownReq.cs index 05496b3a06..2606285aa0 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvShutdownReq.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvShutdownReq.cs @@ -17,7 +17,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking public void Init(UvLoopHandle loop) { - CreateHandle(loop, loop.Libuv.req_size(3)); + CreateHandle(loop, loop.Libuv.req_size(Libuv.RequestType.SHUTDOWN)); } public void Shutdown(UvStreamHandle handle, Action callback, object state) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvTcpHandle.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvTcpHandle.cs index 187656647f..96d5ddbbc9 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvTcpHandle.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvTcpHandle.cs @@ -10,7 +10,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking { public void Init(UvLoopHandle loop) { - CreateHandle(loop, 256); + CreateHandle(loop, loop.Libuv.handle_size(Libuv.HandleType.TCP)); _uv.tcp_init(loop, this); } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvWriteRequest.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvWriteRequest.cs index 54d69a3580..f44865e121 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvWriteRequest.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvWriteRequest.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Collections.Generic; using System.Runtime.InteropServices; namespace Microsoft.AspNet.Server.Kestrel.Networking @@ -13,24 +14,56 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking { private readonly static Libuv.uv_write_cb _uv_write_cb = UvWriteCb; + IntPtr _bufs; + Action _callback; object _state; + const int BUFFER_COUNT = 4; + + List _pins = new List(); public void Init(UvLoopHandle loop) { - CreateHandle(loop, loop.Libuv.req_size(2)); + var requestSize = loop.Libuv.req_size(Libuv.RequestType.WRITE); + var bufferSize = Marshal.SizeOf(typeof(Libuv.uv_buf_t)) * BUFFER_COUNT; + CreateHandle(loop, requestSize + bufferSize); + _bufs = handle + requestSize; } - public void Write(UvStreamHandle handle, Libuv.uv_buf_t[] bufs, int nbufs, Action callback, object state) + public unsafe void Write(UvStreamHandle handle, ArraySegment> bufs, Action callback, object state) { + var pBuffers = (Libuv.uv_buf_t*)_bufs; + var nBuffers = bufs.Count; + if (nBuffers > BUFFER_COUNT) + { + var bufArray = new Libuv.uv_buf_t[nBuffers]; + var gcHandle = GCHandle.Alloc(bufArray, GCHandleType.Pinned); + _pins.Add(gcHandle); + pBuffers = (Libuv.uv_buf_t*)gcHandle.AddrOfPinnedObject(); + } + for (var index = 0; index != nBuffers; ++index) + { + var buf = bufs.Array[bufs.Offset + index]; + + var gcHandle = GCHandle.Alloc(buf.Array, GCHandleType.Pinned); + _pins.Add(gcHandle); + pBuffers[index] = Libuv.buf_init( + gcHandle.AddrOfPinnedObject() + buf.Offset, + buf.Count); + } _callback = callback; _state = state; - _uv.write(this, handle, bufs, nbufs, _uv_write_cb); + _uv.write(this, handle, pBuffers, nBuffers, _uv_write_cb); } private static void UvWriteCb(IntPtr ptr, int status) { var req = FromIntPtr(ptr); + foreach(var pin in req._pins) + { + pin.Free(); + } + req._pins.Clear(); req._callback(req, status, req._state); req._callback = null; req._state = null; From e4b9bd265c75704529409638fd9cdfac504a93ef Mon Sep 17 00:00:00 2001 From: Louis DeJardin Date: Fri, 27 Jun 2014 20:01:44 -0700 Subject: [PATCH 0021/1662] Adjusting Kestrel to run cross platform --- .../Http/Connection.cs | 8 +- .../Http/Listener.cs | 3 +- .../Http/SocketOutput.cs | 17 ++- .../Infrastructure/KestrelThread.cs | 41 ++++++- .../Infrastructure/KestrelTrace.cs | 52 ++++----- .../EngineTests.cs | 18 +++- .../NetworkingTests.cs | 102 +++++++++++++++++- .../TestServer.cs | 15 ++- 8 files changed, 203 insertions(+), 53 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs index 8560a7bbbd..8dffb3fc1f 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs @@ -74,11 +74,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Http private Libuv.uv_buf_t OnAlloc(UvStreamHandle handle, int suggestedSize) { - return new Libuv.uv_buf_t - { - memory = SocketInput.Pin(2048), - len = 2048 - }; + return handle.Libuv.buf_init( + SocketInput.Pin(2048), + 2048); } private void OnRead(UvStreamHandle handle, int nread) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs index 588966e005..d6e20e0f3a 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs @@ -62,7 +62,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { ListenSocket = new UvTcpHandle(); ListenSocket.Init(Thread.Loop); - ListenSocket.Bind(new IPEndPoint(IPAddress.IPv6Any, port)); + ListenSocket.Bind(new IPEndPoint(IPAddress.Any, port)); ListenSocket.Listen(10, _connectionCallback, this); tcs.SetResult(0); } @@ -86,7 +86,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Http public void Dispose() { - Console.WriteLine("Listener.Dispose"); var tcs = new TaskCompletionSource(); Thread.Post( _ => diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs index fb1aa9cc0b..fa0b0a6ab3 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs @@ -28,6 +28,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http public void Write(ArraySegment buffer, Action callback, object state) { + //TODO: need buffering that works + var copy = new byte[buffer.Count]; + Array.Copy(buffer.Array, buffer.Offset, copy, 0, buffer.Count); + buffer = new ArraySegment(copy); + KestrelTrace.Log.ConnectionWrite(0, buffer.Count); var req = new ThisWriteReq(); req.Init(_thread.Loop); @@ -70,24 +75,16 @@ namespace Microsoft.AspNet.Server.Kestrel.Http public void Write() { - _pin = GCHandle.Alloc(_buffer.Array, GCHandleType.Pinned); - var buf = new Libuv.uv_buf_t - { - len = (uint)_buffer.Count, - memory = _pin.AddrOfPinnedObject() + _buffer.Offset - }; - Write( _socket, - new[] { buf }, - 1, + new ArraySegment>( + new[]{_buffer}), _writeCallback, this); } private void OnWrite(UvWriteReq req, int status) { - _pin.Free(); KestrelTrace.Log.ConnectionWriteCallback(0, status); //NOTE: pool this? Dispose(); diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs index 6929767280..a59f7ba42e 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs @@ -81,6 +81,17 @@ namespace Microsoft.AspNet.Server.Kestrel _post.Send(); } + public Task PostAsync(Action callback, object state) + { + var tcs = new TaskCompletionSource(); + lock (_workSync) + { + _workAdding.Enqueue(new Work { Callback = callback, State = state, Completion = tcs }); + } + _post.Send(); + return tcs.Task; + } + private void ThreadStart(object parameter) { var tcs = (TaskCompletionSource)parameter; @@ -103,12 +114,19 @@ namespace Microsoft.AspNet.Server.Kestrel return; } - // run the loop one more time to delete the _post handle + // run the loop one more time to delete the open handles _post.Reference(); _post.DangerousClose(); + _engine.Libuv.walk( + _loop, + (ptr, arg) => + { + var handle = UvMemory.FromIntPtr(ptr); + handle.Dispose(); + }, + IntPtr.Zero); var ran2 = _loop.Run(); - // delete the last of the unmanaged memory _loop.Dispose(); } catch (Exception ex) @@ -131,10 +149,26 @@ namespace Microsoft.AspNet.Server.Kestrel try { work.Callback(work.State); + if (work.Completion != null) + { + ThreadPool.QueueUserWorkItem( + tcs => + { + ((TaskCompletionSource)tcs).SetResult(0); + }, + work.Completion); + } } catch (Exception ex) { - //TODO: unhandled exceptions + if (work.Completion != null) + { + ThreadPool.QueueUserWorkItem(_ => work.Completion.SetException(ex), null); + } + else + { + // TODO: unobserved exception? + } } } } @@ -143,6 +177,7 @@ namespace Microsoft.AspNet.Server.Kestrel { public Action Callback; public object State; + public TaskCompletionSource Completion; } } } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelTrace.cs b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelTrace.cs index 907567bb82..6aa018b6bf 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelTrace.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelTrace.cs @@ -1,83 +1,83 @@ using System; -using System.Diagnostics.Tracing; +//using System.Diagnostics.Tracing; namespace Microsoft.AspNet.Server.Kestrel { /// /// Summary description for KestrelTrace /// - public class KestrelTrace : EventSource + public class KestrelTrace //: EventSource { public static KestrelTrace Log = new KestrelTrace(); - static EventTask Connection = (EventTask)1; - static EventTask Frame = (EventTask)1; + // static EventTask Connection = (EventTask)1; + // static EventTask Frame = (EventTask)1; - [Event(13, Level = EventLevel.Informational, Message = "Id {0}")] + // [Event(13, Level = EventLevel.Informational, Message = "Id {0}")] public void ConnectionStart(long connectionId) { - WriteEvent(13, connectionId); + // WriteEvent(13, connectionId); } - [Event(14, Level = EventLevel.Informational, Message = "Id {0}")] + // [Event(14, Level = EventLevel.Informational, Message = "Id {0}")] public void ConnectionStop(long connectionId) { - WriteEvent(14, connectionId); + // WriteEvent(14, connectionId); } - [Event(4, Message = "Id {0} Status {1}")] + // [Event(4, Message = "Id {0} Status {1}")] internal void ConnectionRead(long connectionId, int status) { - WriteEvent(4, connectionId, status); + // WriteEvent(4, connectionId, status); } - [Event(5, Message = "Id {0}")] + // [Event(5, Message = "Id {0}")] internal void ConnectionPause(long connectionId) { - WriteEvent(5, connectionId); + // WriteEvent(5, connectionId); } - [Event(6, Message = "Id {0}")] + // [Event(6, Message = "Id {0}")] internal void ConnectionResume(long connectionId) { - WriteEvent(6, connectionId); + // WriteEvent(6, connectionId); } - [Event(7, Message = "Id {0}")] + // [Event(7, Message = "Id {0}")] internal void ConnectionReadFin(long connectionId) { - WriteEvent(7, connectionId); + // WriteEvent(7, connectionId); } - [Event(8, Message = "Id {0} Step {1}")] +// [Event(8, Message = "Id {0} Step {1}")] internal void ConnectionWriteFin(long connectionId, int step) { - WriteEvent(8, connectionId, step); + // WriteEvent(8, connectionId, step); } - [Event(9, Message = "Id {0}")] + // [Event(9, Message = "Id {0}")] internal void ConnectionKeepAlive(long connectionId) { - WriteEvent(9, connectionId); + // WriteEvent(9, connectionId); } - [Event(10, Message = "Id {0}")] + // [Event(10, Message = "Id {0}")] internal void ConnectionDisconnect(long connectionId) { - WriteEvent(10, connectionId); + // WriteEvent(10, connectionId); } - [Event(11, Message = "Id {0} Count {1}")] + // [Event(11, Message = "Id {0} Count {1}")] internal void ConnectionWrite(long connectionId, int count) { - WriteEvent(11, connectionId, count); + // WriteEvent(11, connectionId, count); } - [Event(12, Message = "Id {0} Status {1}")] + // [Event(12, Message = "Id {0} Status {1}")] internal void ConnectionWriteCallback(long connectionId, int status) { - WriteEvent(12, connectionId, status); + // WriteEvent(12, connectionId, status); } } } diff --git a/test/Microsoft.AspNet.Server.KestralTests/EngineTests.cs b/test/Microsoft.AspNet.Server.KestralTests/EngineTests.cs index 8873de5041..2e821c1af2 100644 --- a/test/Microsoft.AspNet.Server.KestralTests/EngineTests.cs +++ b/test/Microsoft.AspNet.Server.KestralTests/EngineTests.cs @@ -35,12 +35,23 @@ namespace Microsoft.AspNet.Server.KestralTests { get { - var services = CallContextServiceLocator.Locator.ServiceProvider; - return (ILibraryManager)services.GetService(typeof(ILibraryManager)); + try + { + var locator = CallContextServiceLocator.Locator; + if (locator == null) + { + return null; + } + var services = locator.ServiceProvider; + if (services == null) + { + return null; + } + return (ILibraryManager)services.GetService(typeof(ILibraryManager)); + } catch (NullReferenceException) { return null; } } } - private async Task AppChunked(Frame frame) { var data = new MemoryStream(); @@ -85,6 +96,7 @@ namespace Microsoft.AspNet.Server.KestralTests engine.Start(1); var started = engine.CreateServer("http", "localhost", 54321, App); + Console.WriteLine("Started"); var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); socket.Connect(new IPEndPoint(IPAddress.Loopback, 54321)); socket.Send(Encoding.ASCII.GetBytes("POST / HTTP/1.0\r\n\r\nHello World")); diff --git a/test/Microsoft.AspNet.Server.KestralTests/NetworkingTests.cs b/test/Microsoft.AspNet.Server.KestralTests/NetworkingTests.cs index f2994a1e85..19b0178c14 100644 --- a/test/Microsoft.AspNet.Server.KestralTests/NetworkingTests.cs +++ b/test/Microsoft.AspNet.Server.KestralTests/NetworkingTests.cs @@ -30,7 +30,16 @@ namespace Microsoft.AspNet.Server.KestralTests { get { - var services = CallContextServiceLocator.Locator.ServiceProvider; + var locator = CallContextServiceLocator.Locator; + if (locator == null) + { + return null; + } + var services = locator.ServiceProvider; + if (services == null) + { + return null; + } return (ILibraryManager)services.GetService(typeof(ILibraryManager)); } } @@ -123,12 +132,13 @@ namespace Microsoft.AspNet.Server.KestralTests tcp.Bind(new IPEndPoint(IPAddress.Loopback, 54321)); tcp.Listen(10, (_, status, state) => { + Console.WriteLine("Connected"); var tcp2 = new UvTcpHandle(); tcp2.Init(loop); tcp.Accept(tcp2); var data = Marshal.AllocCoTaskMem(500); tcp2.ReadStart( - (a, b, c) => new Libuv.uv_buf_t { memory = data, len = 500 }, + (a, b, c) => _uv.buf_init(data, 500), (__, nread, state2) => { bytesRead += nread; @@ -140,6 +150,7 @@ namespace Microsoft.AspNet.Server.KestralTests null); tcp.Dispose(); }, null); + Console.WriteLine("Task.Run"); var t = Task.Run(async () => { var socket = new Socket( @@ -165,5 +176,92 @@ namespace Microsoft.AspNet.Server.KestralTests loop.Dispose(); await t; } + + [Fact] + public async Task SocketCanReadAndWrite() + { + int bytesRead = 0; + var loop = new UvLoopHandle(); + loop.Init(_uv); + var tcp = new UvTcpHandle(); + tcp.Init(loop); + tcp.Bind(new IPEndPoint(IPAddress.Loopback, 54321)); + tcp.Listen(10, (_, status, state) => + { + Console.WriteLine("Connected"); + var tcp2 = new UvTcpHandle(); + tcp2.Init(loop); + tcp.Accept(tcp2); + var data = Marshal.AllocCoTaskMem(500); + tcp2.ReadStart( + (a, b, c) => tcp2.Libuv.buf_init(data, 500), + (__, nread, state2) => + { + bytesRead += nread; + if (nread == 0) + { + tcp2.Dispose(); + } + else + { + for (var x = 0; x != 2; ++x) + { + var req = new UvWriteReq(); + req.Init(loop); + req.Write( + tcp2, + new ArraySegment>( + new[]{new ArraySegment(new byte[]{65,66,67,68,69})} + ), + (___,____,_____)=>{}, + null); + } + } + }, + null); + tcp.Dispose(); + }, null); + Console.WriteLine("Task.Run"); + var t = Task.Run(async () => + { + var socket = new Socket( + AddressFamily.InterNetwork, + SocketType.Stream, + ProtocolType.Tcp); + await Task.Factory.FromAsync( + socket.BeginConnect, + socket.EndConnect, + new IPEndPoint(IPAddress.Loopback, 54321), + null, + TaskCreationOptions.None); + await Task.Factory.FromAsync( + socket.BeginSend, + socket.EndSend, + new[] { new ArraySegment(new byte[] { 1, 2, 3, 4, 5 }) }, + SocketFlags.None, + null, + TaskCreationOptions.None); + socket.Shutdown(SocketShutdown.Send); + var buffer = new ArraySegment(new byte[2048]); + for(;;) + { + var count = await Task.Factory.FromAsync( + socket.BeginReceive, + socket.EndReceive, + new[] { buffer }, + SocketFlags.None, + null, + TaskCreationOptions.None); + Console.WriteLine("count {0} {1}", + count, + System.Text.Encoding.ASCII.GetString(buffer.Array, 0, count)); + if (count <= 0) break; + } + socket.Dispose(); + }); + loop.Run(); + loop.Dispose(); + await t; + } } } \ No newline at end of file diff --git a/test/Microsoft.AspNet.Server.KestralTests/TestServer.cs b/test/Microsoft.AspNet.Server.KestralTests/TestServer.cs index e947f6b866..828c60ce67 100644 --- a/test/Microsoft.AspNet.Server.KestralTests/TestServer.cs +++ b/test/Microsoft.AspNet.Server.KestralTests/TestServer.cs @@ -24,8 +24,19 @@ namespace Microsoft.AspNet.Server.KestralTests { get { - var services = CallContextServiceLocator.Locator.ServiceProvider; - return (ILibraryManager)services.GetService(typeof(ILibraryManager)); + try{ + var locator = CallContextServiceLocator.Locator; + if (locator == null) + { + return null; + } + var services = locator.ServiceProvider; + if (services == null) + { + return null; + } + return (ILibraryManager)services.GetService(typeof(ILibraryManager)); + } catch (NullReferenceException) { return null; } } } From 0f1a72e7e0d4bda774676835499abf883ed05afb Mon Sep 17 00:00:00 2001 From: Louis DeJardin Date: Fri, 27 Jun 2014 20:59:39 -0700 Subject: [PATCH 0022/1662] Tiny CLR won't tell you what the OS is. Assume tiny CLR is running on Windows. --- .../Networking/PlatformApis.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/PlatformApis.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/PlatformApis.cs index e55e16577e..7803250f87 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/PlatformApis.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/PlatformApis.cs @@ -12,8 +12,12 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking { public static bool IsWindows() { +#if K10 + return true; +#else var p = (int)Environment.OSVersion.Platform; return (p != 4) && (p != 6) && (p != 128); +#endif } public static void Apply(Libuv libuv) From 5e51783087a73b0dc16e77f3a8beaea6cdbbe472 Mon Sep 17 00:00:00 2001 From: Louis DeJardin Date: Fri, 27 Jun 2014 21:00:06 -0700 Subject: [PATCH 0023/1662] Recompiling windows binaries because uv_loop_size was added --- .../native/windows/amd64/libuv.dll | Bin 137728 -> 141312 bytes .../native/windows/x86/libuv.dll | Bin 317440 -> 119808 bytes 2 files changed, 0 insertions(+), 0 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/native/windows/amd64/libuv.dll b/src/Microsoft.AspNet.Server.Kestrel/native/windows/amd64/libuv.dll index 436ee491a1cd8676e21a144b0000b7a177f02cac..1174ae2c275385827a2e277753da13f5f9be574a 100644 GIT binary patch delta 55936 zcmb?^2|!fU_y4>nq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024/1662] Adding Upgrade support, using WebSocket middleware from sample app --- src/Kestrel/ServerRequest.cs | 35 ++++++++++++++- .../Http/Frame.cs | 6 ++- src/SampleApp/Startup.cs | 45 +++++++++++++++++-- src/SampleApp/project.json | 3 +- 4 files changed, 82 insertions(+), 7 deletions(-) diff --git a/src/Kestrel/ServerRequest.cs b/src/Kestrel/ServerRequest.cs index 643e464d5f..d558308a52 100644 --- a/src/Kestrel/ServerRequest.cs +++ b/src/Kestrel/ServerRequest.cs @@ -3,10 +3,12 @@ using Microsoft.AspNet.Server.Kestrel.Http; using System; using System.Collections.Generic; using System.IO; +using System.Linq; +using System.Threading.Tasks; namespace Kestrel { - public class ServerRequest : IHttpRequestFeature, IHttpResponseFeature + public class ServerRequest : IHttpRequestFeature, IHttpResponseFeature, IHttpOpaqueUpgradeFeature { Frame _frame; string _scheme; @@ -172,9 +174,40 @@ namespace Kestrel _frame.ResponseBody = value; } } + void IHttpResponseFeature.OnSendingHeaders(Action callback, object state) { _frame.OnSendingHeaders(callback, state); } + + bool IHttpOpaqueUpgradeFeature.IsUpgradableRequest + { + get + { + string[] values; + if (_frame.RequestHeaders.TryGetValue("Connection", out values)) + { + return values.Any(value => value.IndexOf("upgrade", StringComparison.OrdinalIgnoreCase) != -1); + } + return false; + } + } + + async Task IHttpOpaqueUpgradeFeature.UpgradeAsync() + { + _frame.StatusCode = 101; + _frame.ReasonPhrase = "Switching Protocols"; + _frame.ResponseHeaders["Connection"] = new string[] { "Upgrade" }; + if (!_frame.ResponseHeaders.ContainsKey("Upgrade")) + { + string[] values; + if (_frame.RequestHeaders.TryGetValue("Upgrade", out values)) + { + _frame.ResponseHeaders["Upgrade"] = values; + } + } + _frame.ProduceStart(); + return _frame.DuplexStream; + } } } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs index 428b0ca6b4..fd0696d180 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs @@ -63,7 +63,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Http List, object>> _onSendingHeaders; object _onSendingHeadersSync = new Object(); - Stream _duplexStream; public Frame(ConnectionContext context) : base(context) { @@ -87,6 +86,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Http public IDictionary ResponseHeaders { get; set; } public Stream ResponseBody { get; set; } + public Stream DuplexStream { get; set; } + + /* public bool LocalIntakeFin @@ -175,7 +177,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http _keepAlive = MessageBody.RequestKeepAlive; RequestBody = new FrameRequestStream(MessageBody); ResponseBody = new FrameResponseStream(this); - _duplexStream = new FrameDuplexStream(RequestBody, ResponseBody); + DuplexStream = new FrameDuplexStream(RequestBody, ResponseBody); SocketInput.Free(); Task.Run(ExecuteAsync); } diff --git a/src/SampleApp/Startup.cs b/src/SampleApp/Startup.cs index 9eba33a386..65462519d6 100644 --- a/src/SampleApp/Startup.cs +++ b/src/SampleApp/Startup.cs @@ -1,5 +1,8 @@ using Microsoft.AspNet.Builder; using System; +using System.Net.WebSockets; +using System.Threading; +using System.Threading.Tasks; namespace SampleApp { @@ -7,6 +10,8 @@ namespace SampleApp { public void Configure(IBuilder app) { + app.UseWebSockets(); + app.Run(async context => { Console.WriteLine("{0} {1}{2}{3}", @@ -15,10 +20,44 @@ namespace SampleApp context.Request.Path, context.Request.QueryString); - context.Response.ContentLength = 11; - context.Response.ContentType = "text/plain"; - await context.Response.WriteAsync("Hello world"); + if (context.IsWebSocketRequest) + { + var webSocket = await context.AcceptWebSocketAsync(); + await EchoAsync(webSocket); + } + else + { + context.Response.ContentLength = 11; + context.Response.ContentType = "text/plain"; + await context.Response.WriteAsync("Hello world"); + } }); } + + public async Task EchoAsync(WebSocket webSocket) + { + var buffer = new ArraySegment(new byte[8192]); + for (; ;) + { + var result = await webSocket.ReceiveAsync( + buffer, + CancellationToken.None); + + if (result.MessageType == WebSocketMessageType.Close) + { + return; + } + else if (result.MessageType == WebSocketMessageType.Text) + { + Console.WriteLine("{0}", System.Text.Encoding.UTF8.GetString(buffer.Array, 0, result.Count)); + } + + await webSocket.SendAsync( + new ArraySegment(buffer.Array, 0, result.Count), + result.MessageType, + result.EndOfMessage, + CancellationToken.None); + } + } } } \ No newline at end of file diff --git a/src/SampleApp/project.json b/src/SampleApp/project.json index 19174804d7..f34a5acc74 100644 --- a/src/SampleApp/project.json +++ b/src/SampleApp/project.json @@ -2,7 +2,8 @@ "version": "1.0.0-*", "dependencies": { "Kestrel": "1.0.0-*", - "Microsoft.AspNet.Server.WebListener": "1.0.0-*" + "Microsoft.AspNet.Server.WebListener": "1.0.0-*", + "Microsoft.AspNet.WebSockets.Middleware": "1.0.0-*" }, "configurations": { "net45": { }, From 9118d037fe635ccf464035bcd138cfb53a3ee2de Mon Sep 17 00:00:00 2001 From: David Fowler Date: Fri, 27 Jun 2014 23:02:52 -0700 Subject: [PATCH 0025/1662] Updated the kproj --- .../Microsoft.AspNet.Server.Kestrel.kproj | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Microsoft.AspNet.Server.Kestrel.kproj b/src/Microsoft.AspNet.Server.Kestrel/Microsoft.AspNet.Server.Kestrel.kproj index f860285346..73aa45b30b 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Microsoft.AspNet.Server.Kestrel.kproj +++ b/src/Microsoft.AspNet.Server.Kestrel/Microsoft.AspNet.Server.Kestrel.kproj @@ -23,9 +23,10 @@ 2.0 - + + + - @@ -44,6 +45,7 @@ + From e74c4bfa8158b0ed6d1131514d6abbf822a11896 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Sun, 29 Jun 2014 09:28:43 -0700 Subject: [PATCH 0026/1662] Disable flaky engine tests --- test/Microsoft.AspNet.Server.KestralTests/EngineTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Microsoft.AspNet.Server.KestralTests/EngineTests.cs b/test/Microsoft.AspNet.Server.KestralTests/EngineTests.cs index 2e821c1af2..1c667ecafb 100644 --- a/test/Microsoft.AspNet.Server.KestralTests/EngineTests.cs +++ b/test/Microsoft.AspNet.Server.KestralTests/EngineTests.cs @@ -15,7 +15,7 @@ namespace Microsoft.AspNet.Server.KestralTests /// /// Summary description for EngineTests /// - public class EngineTests + internal class EngineTests { private async Task App(Frame frame) { From 8d527e4e0b7d7db73475ed988b62197ecd4a99b0 Mon Sep 17 00:00:00 2001 From: Louis DeJardin Date: Mon, 30 Jun 2014 14:04:25 -0700 Subject: [PATCH 0027/1662] Removing a reference to make things work better --- test/Microsoft.AspNet.Server.KestralTests/project.json | 2 -- 1 file changed, 2 deletions(-) diff --git a/test/Microsoft.AspNet.Server.KestralTests/project.json b/test/Microsoft.AspNet.Server.KestralTests/project.json index c67b190301..cdd8390707 100644 --- a/test/Microsoft.AspNet.Server.KestralTests/project.json +++ b/test/Microsoft.AspNet.Server.KestralTests/project.json @@ -2,8 +2,6 @@ "version": "1.0.0-*", "dependencies": { "Xunit.KRunner": "1.0.0-*", - "xunit.assert": "2.0.0-*", - "xunit.abstractions": "2.0.0-*", "Microsoft.AspNet.Server.Kestrel": "1.0.0-*" }, "configurations": { From be88722cb5489a4da83a83f6faf2adb5070ebf06 Mon Sep 17 00:00:00 2001 From: Pranav K Date: Tue, 1 Jul 2014 09:24:32 -0700 Subject: [PATCH 0028/1662] Moving SampleApp from src to samples --- {src => samples}/SampleApp/Microsoft.AspNet.Hosting.ini | 0 {src => samples}/SampleApp/Program.cs | 0 {src => samples}/SampleApp/SampleApp.kproj | 0 {src => samples}/SampleApp/Startup.cs | 0 {src => samples}/SampleApp/project.json | 0 5 files changed, 0 insertions(+), 0 deletions(-) rename {src => samples}/SampleApp/Microsoft.AspNet.Hosting.ini (100%) rename {src => samples}/SampleApp/Program.cs (100%) rename {src => samples}/SampleApp/SampleApp.kproj (100%) rename {src => samples}/SampleApp/Startup.cs (100%) rename {src => samples}/SampleApp/project.json (100%) diff --git a/src/SampleApp/Microsoft.AspNet.Hosting.ini b/samples/SampleApp/Microsoft.AspNet.Hosting.ini similarity index 100% rename from src/SampleApp/Microsoft.AspNet.Hosting.ini rename to samples/SampleApp/Microsoft.AspNet.Hosting.ini diff --git a/src/SampleApp/Program.cs b/samples/SampleApp/Program.cs similarity index 100% rename from src/SampleApp/Program.cs rename to samples/SampleApp/Program.cs diff --git a/src/SampleApp/SampleApp.kproj b/samples/SampleApp/SampleApp.kproj similarity index 100% rename from src/SampleApp/SampleApp.kproj rename to samples/SampleApp/SampleApp.kproj diff --git a/src/SampleApp/Startup.cs b/samples/SampleApp/Startup.cs similarity index 100% rename from src/SampleApp/Startup.cs rename to samples/SampleApp/Startup.cs diff --git a/src/SampleApp/project.json b/samples/SampleApp/project.json similarity index 100% rename from src/SampleApp/project.json rename to samples/SampleApp/project.json From 365352ce3594283bc1c68e1e4911ea2bcac27a35 Mon Sep 17 00:00:00 2001 From: Eilon Lipton Date: Wed, 2 Jul 2014 11:34:42 -0700 Subject: [PATCH 0029/1662] Create CONTRIBUTING.md --- CONTRIBUTING.md | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 CONTRIBUTING.md diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000000..eac4268e4c --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,4 @@ +Contributing +====== + +Information on contributing to this repo is in the [Contributing Guide](https://github.com/aspnet/Home/blob/master/CONTRIBUTING.md) in the Home repo. From 19cf259d60256d543c09d0fcde8b81e0a9f4cb42 Mon Sep 17 00:00:00 2001 From: Eilon Lipton Date: Wed, 2 Jul 2014 12:50:49 -0700 Subject: [PATCH 0030/1662] Create README.md --- README.md | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000000..4921a45505 --- /dev/null +++ b/README.md @@ -0,0 +1,7 @@ +KestrelHttpServer +================= + +This repo contains a development web server for ASP.NET vNext based on [libuv](https://github.com/joyent/libuv). + +This project is part of ASP.NET vNext. You can find samples, documentation and getting started instructions for ASP.NET vNext at the [Home](https://github.com/aspnet/home) repo. + From 747777ab549a48448e930f66942522f576f2e996 Mon Sep 17 00:00:00 2001 From: Louis DeJardin Date: Thu, 3 Jul 2014 11:27:40 -0700 Subject: [PATCH 0031/1662] Adding dylib binary to source control --- .../native/darwin/universal/libuv.dylib | Bin 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100755 => 100644 src/Microsoft.AspNet.Server.Kestrel/native/darwin/universal/libuv.dylib diff --git a/src/Microsoft.AspNet.Server.Kestrel/native/darwin/universal/libuv.dylib b/src/Microsoft.AspNet.Server.Kestrel/native/darwin/universal/libuv.dylib old mode 100755 new mode 100644 From 6edd238f3806a6de846666dff3cea9de7889a831 Mon Sep 17 00:00:00 2001 From: Chris Ross Date: Thu, 3 Jul 2014 14:14:07 -0700 Subject: [PATCH 0032/1662] Rename IHttpOpaqueUpgradeFeature to IHttpUpgradeFeature. --- src/Kestrel/ServerRequest.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Kestrel/ServerRequest.cs b/src/Kestrel/ServerRequest.cs index d558308a52..b167f50278 100644 --- a/src/Kestrel/ServerRequest.cs +++ b/src/Kestrel/ServerRequest.cs @@ -8,7 +8,7 @@ using System.Threading.Tasks; namespace Kestrel { - public class ServerRequest : IHttpRequestFeature, IHttpResponseFeature, IHttpOpaqueUpgradeFeature + public class ServerRequest : IHttpRequestFeature, IHttpResponseFeature, IHttpUpgradeFeature { Frame _frame; string _scheme; @@ -180,7 +180,7 @@ namespace Kestrel _frame.OnSendingHeaders(callback, state); } - bool IHttpOpaqueUpgradeFeature.IsUpgradableRequest + bool IHttpUpgradeFeature.IsUpgradableRequest { get { @@ -193,7 +193,7 @@ namespace Kestrel } } - async Task IHttpOpaqueUpgradeFeature.UpgradeAsync() + async Task IHttpUpgradeFeature.UpgradeAsync() { _frame.StatusCode = 101; _frame.ReasonPhrase = "Switching Protocols"; From 8624b82b2b34a150c1b5baf70df77d78e6af3127 Mon Sep 17 00:00:00 2001 From: Louis DeJardin Date: Mon, 7 Jul 2014 13:02:18 -0700 Subject: [PATCH 0033/1662] Improving callback exception support Also renaming KestralTests to KestrelTests --- .../Http/Connection.cs | 16 ++++-- .../Http/Frame.cs | 28 ++++++++-- .../Http/FrameResponseStream.cs | 32 ++++++++++- .../Http/Listener.cs | 16 ++++-- .../Http/SocketOutput.cs | 18 +++--- .../Infrastructure/KestrelThread.cs | 1 + .../Networking/UvStreamHandle.cs | 56 ++++++++++++++----- .../Networking/UvWriteRequest.cs | 33 +++++++++-- .../EngineTests.cs | 36 ++++++++++-- .../MessageBodyExchangerTests.cs | 2 +- .../MessageBodyTests.cs | 2 +- ...icrosoft.AspNet.Server.KestrelTests.kproj} | 0 .../NetworkingTests.cs | 24 ++++---- .../Program.cs | 4 +- .../TestConnection.cs | 2 +- .../TestInput.cs | 4 +- .../TestServer.cs | 2 +- 17 files changed, 209 insertions(+), 67 deletions(-) rename test/Microsoft.AspNet.Server.KestralTests/{Microsoft.AspNet.Server.KestralTests.kproj => Microsoft.AspNet.Server.KestrelTests.kproj} (100%) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs index 8dffb3fc1f..486e0a82ec 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs @@ -4,6 +4,7 @@ using System; using System.Threading.Tasks; using Microsoft.AspNet.Server.Kestrel.Networking; +using System.Diagnostics; namespace Microsoft.AspNet.Server.Kestrel.Http { @@ -39,7 +40,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http public class Connection : ConnectionContext, IConnectionControl { - private static readonly Action _readCallback = ReadCallback; + private static readonly Action _readCallback = ReadCallback; private static readonly Func _allocCallback = AllocCallback; private static Libuv.uv_buf_t AllocCallback(UvStreamHandle handle, int suggestedSize, object state) @@ -47,9 +48,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return ((Connection)state).OnAlloc(handle, suggestedSize); } - private static void ReadCallback(UvStreamHandle handle, int nread, object state) + private static void ReadCallback(UvStreamHandle handle, int nread, Exception error, object state) { - ((Connection)state).OnRead(handle, nread); + ((Connection)state).OnRead(handle, nread, error); } private readonly UvStreamHandle _socket; @@ -79,14 +80,19 @@ namespace Microsoft.AspNet.Server.Kestrel.Http 2048); } - private void OnRead(UvStreamHandle handle, int nread) + private void OnRead(UvStreamHandle handle, int nread, Exception error) { SocketInput.Unpin(nread); - if (nread == 0) + if (nread == 0 || error != null) { SocketInput.RemoteIntakeFin = true; KestrelTrace.Log.ConnectionReadFin(_connectionId); + + if (error != null) + { + Trace.WriteLine("Connection.OnRead " + error.ToString()); + } } else { diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs index fd0696d180..1f8552459b 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using System.IO; using System.Linq; using System.Text; @@ -38,7 +39,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http public interface IFrameControl { void ProduceContinue(); - void Write(ArraySegment data, Action callback, object state); + void Write(ArraySegment data, Action callback, object state); } public class Frame : FrameContext, IFrameControl @@ -229,7 +230,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } - public void Write(ArraySegment data, Action callback, object state) + public void Write(ArraySegment data, Action callback, object state) { ProduceStart(); SocketOutput.Write(data, callback, state); @@ -255,7 +256,16 @@ namespace Microsoft.AspNet.Server.Kestrel.Http RequestHeaders.TryGetValue("Expect", out expect) && (expect.FirstOrDefault() ?? "").Equals("100-continue", StringComparison.OrdinalIgnoreCase)) { - SocketOutput.Write(new ArraySegment(_continueBytes, 0, _continueBytes.Length), _ => { }, null); + SocketOutput.Write( + new ArraySegment(_continueBytes, 0, _continueBytes.Length), + (error, _) => + { + if (error != null) + { + Trace.WriteLine("ProduceContinue " + error.ToString()); + } + }, + null); } } @@ -269,7 +279,17 @@ namespace Microsoft.AspNet.Server.Kestrel.Http var status = ReasonPhrases.ToStatus(StatusCode, ReasonPhrase); var responseHeader = CreateResponseHeader(status, ResponseHeaders); - SocketOutput.Write(responseHeader.Item1, x => ((IDisposable)x).Dispose(), responseHeader.Item2); + SocketOutput.Write( + responseHeader.Item1, + (error, x) => + { + if (error != null) + { + Trace.WriteLine("ProduceStart " + error.ToString()); + } + ((IDisposable)x).Dispose(); + }, + responseHeader.Item2); } public void ProduceEnd(Exception ex) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameResponseStream.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameResponseStream.cs index dc05b4dd7f..2ee9f27f32 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameResponseStream.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameResponseStream.cs @@ -25,7 +25,21 @@ namespace Microsoft.AspNet.Server.Kestrel.Http public override Task FlushAsync(CancellationToken cancellationToken) { var tcs = new TaskCompletionSource(); - _context.FrameControl.Write(new ArraySegment(new byte[0]), x => ((TaskCompletionSource)x).SetResult(0), tcs); + _context.FrameControl.Write( + new ArraySegment(new byte[0]), + (error, arg) => + { + var tcsArg = (TaskCompletionSource)arg; + if (error != null) + { + tcsArg.SetException(error); + } + else + { + tcsArg.SetResult(0); + } + }, + tcs); return tcs.Task; } @@ -52,7 +66,21 @@ namespace Microsoft.AspNet.Server.Kestrel.Http public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) { var tcs = new TaskCompletionSource(); - _context.FrameControl.Write(new ArraySegment(buffer, offset, count), x => ((TaskCompletionSource)x).SetResult(0), tcs); + _context.FrameControl.Write( + new ArraySegment(buffer, offset, count), + (error, arg) => + { + var tcsArg = (TaskCompletionSource)arg; + if (error != null) + { + tcsArg.SetException(error); + } + else + { + tcsArg.SetResult(0); + } + }, + tcs); return tcs.Task; } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs index d6e20e0f3a..98de2b440f 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs @@ -3,6 +3,7 @@ using Microsoft.AspNet.Server.Kestrel.Networking; using System; +using System.Diagnostics; using System.Net; using System.Threading.Tasks; @@ -31,13 +32,20 @@ namespace Microsoft.AspNet.Server.Kestrel.Http /// public class Listener : ListenerContext, IDisposable { - private static readonly Action _connectionCallback = ConnectionCallback; + private static readonly Action _connectionCallback = ConnectionCallback; UvTcpHandle ListenSocket { get; set; } - private static void ConnectionCallback(UvStreamHandle stream, int status, object state) + private static void ConnectionCallback(UvStreamHandle stream, int status, Exception error, object state) { - ((Listener)state).OnConnection(stream, status); + if (error != null) + { + Trace.WriteLine("Listener.ConnectionCallback " + error.ToString()); + } + else + { + ((Listener)state).OnConnection(stream, status); + } } public Listener(IMemoryPool memory) @@ -99,7 +107,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { tcs.SetException(ex); } - }, + }, null); tcs.Task.Wait(); ListenSocket = null; diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs index fa0b0a6ab3..c43d13dcba 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs @@ -12,7 +12,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http /// public interface ISocketOutput { - void Write(ArraySegment buffer, Action callback, object state); + void Write(ArraySegment buffer, Action callback, object state); } public class SocketOutput : ISocketOutput @@ -26,7 +26,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http _socket = socket; } - public void Write(ArraySegment buffer, Action callback, object state) + public void Write(ArraySegment buffer, Action callback, object state) { //TODO: need buffering that works var copy = new byte[buffer.Count]; @@ -45,17 +45,17 @@ namespace Microsoft.AspNet.Server.Kestrel.Http public class ThisWriteReq : UvWriteReq { - private static readonly Action _writeCallback = WriteCallback; - private static void WriteCallback(UvWriteReq req, int status, object state) + private static readonly Action _writeCallback = WriteCallback; + private static void WriteCallback(UvWriteReq req, int status, Exception error, object state) { - ((ThisWriteReq)state).OnWrite(req, status); + ((ThisWriteReq)state).OnWrite(req, status, error); } SocketOutput _self; ArraySegment _buffer; Action _drained; UvStreamHandle _socket; - Action _callback; + Action _callback; object _state; GCHandle _pin; @@ -63,7 +63,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http SocketOutput socketOutput, UvStreamHandle socket, ArraySegment buffer, - Action callback, + Action callback, object state) { _self = socketOutput; @@ -83,12 +83,12 @@ namespace Microsoft.AspNet.Server.Kestrel.Http this); } - private void OnWrite(UvWriteReq req, int status) + private void OnWrite(UvWriteReq req, int status, Exception error) { KestrelTrace.Log.ConnectionWriteCallback(0, status); //NOTE: pool this? Dispose(); - _callback(_state); + _callback(error, _state); } } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs index a59f7ba42e..fae471eec5 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs @@ -105,6 +105,7 @@ namespace Microsoft.AspNet.Server.Kestrel { tcs.SetException(ex); } + try { var ran1 = _loop.Run(); diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvStreamHandle.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvStreamHandle.cs index feb9dc4f6f..9249b53104 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvStreamHandle.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvStreamHandle.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Diagnostics; namespace Microsoft.AspNet.Server.Kestrel.Networking { @@ -11,16 +12,16 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking private readonly static Libuv.uv_alloc_cb _uv_alloc_cb = UvAllocCb; private readonly static Libuv.uv_read_cb _uv_read_cb = UvReadCb; - public Action _connectionCallback; + public Action _connectionCallback; public object _connectionState; public Func _allocCallback; - public Action _readCallback; + public Action _readCallback; public object _readState; - public void Listen(int backlog, Action callback, object state) + public void Listen(int backlog, Action callback, object state) { _connectionCallback = callback; _connectionState = state; @@ -34,7 +35,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking public void ReadStart( Func allocCallback, - Action readCallback, + Action readCallback, object state) { _allocCallback = allocCallback; @@ -57,28 +58,57 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking private static void UvConnectionCb(IntPtr handle, int status) { var stream = FromIntPtr(handle); - stream._connectionCallback(stream, status, stream._connectionState); + + Exception error; + status = stream.Libuv.Check(status, out error); + + try + { + stream._connectionCallback(stream, status, error, stream._connectionState); + } + catch (Exception ex) + { + Trace.WriteLine("UvConnectionCb " + ex.ToString()); + } } + private static void UvAllocCb(IntPtr handle, int suggested_size, out Libuv.uv_buf_t buf) { var stream = FromIntPtr(handle); - buf = stream._allocCallback(stream, suggested_size, stream._readState); + try + { + buf = stream._allocCallback(stream, suggested_size, stream._readState); + } + catch (Exception ex) + { + Trace.WriteLine("UvAllocCb " + ex.ToString()); + buf = stream.Libuv.buf_init(IntPtr.Zero, 0); + throw; + } } private static void UvReadCb(IntPtr handle, int nread, ref Libuv.uv_buf_t buf) { var stream = FromIntPtr(handle); - if (nread == -4095) + try { - stream._readCallback(stream, 0, stream._readState); - return; + if (nread < 0) + { + Exception error; + stream._uv.Check(nread, out error); + stream._readCallback(stream, 0, error, stream._readState); + } + else + { + stream._readCallback(stream, nread, null, stream._readState); + } + } + catch (Exception ex) + { + Trace.WriteLine("UbReadCb " + ex.ToString()); } - - var length = stream._uv.Check(nread); - - stream._readCallback(stream, nread, stream._readState); } } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvWriteRequest.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvWriteRequest.cs index f44865e121..dee7b6bb66 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvWriteRequest.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvWriteRequest.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using System.Runtime.InteropServices; namespace Microsoft.AspNet.Server.Kestrel.Networking @@ -16,12 +17,12 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking IntPtr _bufs; - Action _callback; + Action _callback; object _state; const int BUFFER_COUNT = 4; List _pins = new List(); - + public void Init(UvLoopHandle loop) { var requestSize = loop.Libuv.req_size(Libuv.RequestType.WRITE); @@ -30,7 +31,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking _bufs = handle + requestSize; } - public unsafe void Write(UvStreamHandle handle, ArraySegment> bufs, Action callback, object state) + public unsafe void Write( + UvStreamHandle handle, + ArraySegment> bufs, + Action callback, + object state) { var pBuffers = (Libuv.uv_buf_t*)_bufs; var nBuffers = bufs.Count; @@ -59,14 +64,32 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking private static void UvWriteCb(IntPtr ptr, int status) { var req = FromIntPtr(ptr); - foreach(var pin in req._pins) + foreach (var pin in req._pins) { pin.Free(); } req._pins.Clear(); - req._callback(req, status, req._state); + + var callback = req._callback; req._callback = null; + + var state = req._state; req._state = null; + + Exception error = null; + if (status < 0) + { + req.Libuv.Check(status, out error); + } + + try + { + callback(req, status, error, state); + } + catch (Exception ex) + { + Trace.WriteLine("UvWriteCb " + ex.ToString()); + } } } diff --git a/test/Microsoft.AspNet.Server.KestralTests/EngineTests.cs b/test/Microsoft.AspNet.Server.KestralTests/EngineTests.cs index 1c667ecafb..f3bc95c1af 100644 --- a/test/Microsoft.AspNet.Server.KestralTests/EngineTests.cs +++ b/test/Microsoft.AspNet.Server.KestralTests/EngineTests.cs @@ -10,7 +10,7 @@ using System.Text; using System.Threading.Tasks; using Xunit; -namespace Microsoft.AspNet.Server.KestralTests +namespace Microsoft.AspNet.Server.KestrelTests { /// /// Summary description for EngineTests @@ -35,20 +35,22 @@ namespace Microsoft.AspNet.Server.KestralTests { get { - try + try { var locator = CallContextServiceLocator.Locator; - if (locator == null) + if (locator == null) { return null; } var services = locator.ServiceProvider; - if (services == null) + if (services == null) { return null; } return (ILibraryManager)services.GetService(typeof(ILibraryManager)); - } catch (NullReferenceException) { return null; } + } + catch (NullReferenceException) + { return null; } } } @@ -314,5 +316,29 @@ namespace Microsoft.AspNet.Server.KestralTests } } + + [Fact] + public async Task DisconnectingClient() + { + using (var server = new TestServer(App)) + { + var socket = new Socket(SocketType.Stream, ProtocolType.IP); + socket.Connect(IPAddress.Loopback, 54321); + await Task.Delay(200); + socket.Disconnect(false); + socket.Dispose(); + + await Task.Delay(200); + using (var connection = new TestConnection()) + { + await connection.SendEnd( + "GET / HTTP/1.0", + "\r\n"); + await connection.ReceiveEnd( + "HTTP/1.0 200 OK", + "\r\n"); + } + } + } } } diff --git a/test/Microsoft.AspNet.Server.KestralTests/MessageBodyExchangerTests.cs b/test/Microsoft.AspNet.Server.KestralTests/MessageBodyExchangerTests.cs index a96efcc8ad..b8606ef8dd 100644 --- a/test/Microsoft.AspNet.Server.KestralTests/MessageBodyExchangerTests.cs +++ b/test/Microsoft.AspNet.Server.KestralTests/MessageBodyExchangerTests.cs @@ -4,7 +4,7 @@ using System; using System.Threading.Tasks; using Xunit; -namespace Microsoft.AspNet.Server.KestralTests +namespace Microsoft.AspNet.Server.KestrelTests { /// /// Summary description for MessageBodyExchangerTests diff --git a/test/Microsoft.AspNet.Server.KestralTests/MessageBodyTests.cs b/test/Microsoft.AspNet.Server.KestralTests/MessageBodyTests.cs index ea5d2a75ce..a8be2d3420 100644 --- a/test/Microsoft.AspNet.Server.KestralTests/MessageBodyTests.cs +++ b/test/Microsoft.AspNet.Server.KestralTests/MessageBodyTests.cs @@ -6,7 +6,7 @@ using System.Threading; using System.Threading.Tasks; using Xunit; -namespace Microsoft.AspNet.Server.KestralTests +namespace Microsoft.AspNet.Server.KestrelTests { /// /// Summary description for MessageBodyTests diff --git a/test/Microsoft.AspNet.Server.KestralTests/Microsoft.AspNet.Server.KestralTests.kproj b/test/Microsoft.AspNet.Server.KestralTests/Microsoft.AspNet.Server.KestrelTests.kproj similarity index 100% rename from test/Microsoft.AspNet.Server.KestralTests/Microsoft.AspNet.Server.KestralTests.kproj rename to test/Microsoft.AspNet.Server.KestralTests/Microsoft.AspNet.Server.KestrelTests.kproj diff --git a/test/Microsoft.AspNet.Server.KestralTests/NetworkingTests.cs b/test/Microsoft.AspNet.Server.KestralTests/NetworkingTests.cs index 19b0178c14..cca8bb0f4d 100644 --- a/test/Microsoft.AspNet.Server.KestralTests/NetworkingTests.cs +++ b/test/Microsoft.AspNet.Server.KestralTests/NetworkingTests.cs @@ -12,7 +12,7 @@ using System.Runtime.InteropServices; using System.Threading.Tasks; using Xunit; -namespace Microsoft.AspNet.Server.KestralTests +namespace Microsoft.AspNet.Server.KestrelTests { /// /// Summary description for NetworkingTests @@ -31,12 +31,12 @@ namespace Microsoft.AspNet.Server.KestralTests get { var locator = CallContextServiceLocator.Locator; - if (locator == null) + if (locator == null) { return null; } var services = locator.ServiceProvider; - if (services == null) + if (services == null) { return null; } @@ -93,7 +93,7 @@ namespace Microsoft.AspNet.Server.KestralTests var tcp = new UvTcpHandle(); tcp.Init(loop); tcp.Bind(new IPEndPoint(IPAddress.Loopback, 54321)); - tcp.Listen(10, (stream, status, state) => + tcp.Listen(10, (stream, status, error, state) => { var tcp2 = new UvTcpHandle(); tcp2.Init(loop); @@ -130,7 +130,7 @@ namespace Microsoft.AspNet.Server.KestralTests var tcp = new UvTcpHandle(); tcp.Init(loop); tcp.Bind(new IPEndPoint(IPAddress.Loopback, 54321)); - tcp.Listen(10, (_, status, state) => + tcp.Listen(10, (_, status, error, state) => { Console.WriteLine("Connected"); var tcp2 = new UvTcpHandle(); @@ -139,7 +139,7 @@ namespace Microsoft.AspNet.Server.KestralTests var data = Marshal.AllocCoTaskMem(500); tcp2.ReadStart( (a, b, c) => _uv.buf_init(data, 500), - (__, nread, state2) => + (__, nread, error2, state2) => { bytesRead += nread; if (nread == 0) @@ -186,7 +186,7 @@ namespace Microsoft.AspNet.Server.KestralTests var tcp = new UvTcpHandle(); tcp.Init(loop); tcp.Bind(new IPEndPoint(IPAddress.Loopback, 54321)); - tcp.Listen(10, (_, status, state) => + tcp.Listen(10, (_, status, error, state) => { Console.WriteLine("Connected"); var tcp2 = new UvTcpHandle(); @@ -195,7 +195,7 @@ namespace Microsoft.AspNet.Server.KestralTests var data = Marshal.AllocCoTaskMem(500); tcp2.ReadStart( (a, b, c) => tcp2.Libuv.buf_init(data, 500), - (__, nread, state2) => + (__, nread, error2, state2) => { bytesRead += nread; if (nread == 0) @@ -211,9 +211,9 @@ namespace Microsoft.AspNet.Server.KestralTests req.Write( tcp2, new ArraySegment>( - new[]{new ArraySegment(new byte[]{65,66,67,68,69})} + new[] { new ArraySegment(new byte[] { 65, 66, 67, 68, 69 }) } ), - (___,____,_____)=>{}, + (_1, _2, _3, _4) => { }, null); } } @@ -243,7 +243,7 @@ namespace Microsoft.AspNet.Server.KestralTests TaskCreationOptions.None); socket.Shutdown(SocketShutdown.Send); var buffer = new ArraySegment(new byte[2048]); - for(;;) + for (; ;) { var count = await Task.Factory.FromAsync( socket.BeginReceive, @@ -252,7 +252,7 @@ namespace Microsoft.AspNet.Server.KestralTests SocketFlags.None, null, TaskCreationOptions.None); - Console.WriteLine("count {0} {1}", + Console.WriteLine("count {0} {1}", count, System.Text.Encoding.ASCII.GetString(buffer.Array, 0, count)); if (count <= 0) break; diff --git a/test/Microsoft.AspNet.Server.KestralTests/Program.cs b/test/Microsoft.AspNet.Server.KestralTests/Program.cs index 86ae9b71d7..9e36b9f8c2 100644 --- a/test/Microsoft.AspNet.Server.KestralTests/Program.cs +++ b/test/Microsoft.AspNet.Server.KestralTests/Program.cs @@ -1,6 +1,6 @@ using System; -namespace Microsoft.AspNet.Server.KestralTests +namespace Microsoft.AspNet.Server.KestrelTests { /// /// Summary description for Program @@ -9,7 +9,7 @@ namespace Microsoft.AspNet.Server.KestralTests { public void Main() { - new EngineTests().Http11().Wait(); + new EngineTests().DisconnectingClient().Wait(); } } } \ No newline at end of file diff --git a/test/Microsoft.AspNet.Server.KestralTests/TestConnection.cs b/test/Microsoft.AspNet.Server.KestralTests/TestConnection.cs index a1447fae25..be079ad17f 100644 --- a/test/Microsoft.AspNet.Server.KestralTests/TestConnection.cs +++ b/test/Microsoft.AspNet.Server.KestralTests/TestConnection.cs @@ -7,7 +7,7 @@ using System.Text; using System.Threading.Tasks; using Xunit; -namespace Microsoft.AspNet.Server.KestralTests +namespace Microsoft.AspNet.Server.KestrelTests { /// /// Summary description for TestConnection diff --git a/test/Microsoft.AspNet.Server.KestralTests/TestInput.cs b/test/Microsoft.AspNet.Server.KestralTests/TestInput.cs index c7aa430c1f..a9448ac942 100644 --- a/test/Microsoft.AspNet.Server.KestralTests/TestInput.cs +++ b/test/Microsoft.AspNet.Server.KestralTests/TestInput.cs @@ -1,7 +1,7 @@ using System; using Microsoft.AspNet.Server.Kestrel.Http; -namespace Microsoft.AspNet.Server.KestralTests +namespace Microsoft.AspNet.Server.KestrelTests { class TestInput : IConnectionControl, IFrameControl { @@ -44,7 +44,7 @@ namespace Microsoft.AspNet.Server.KestralTests { } - public void Write(ArraySegment data, Action callback, object state) + public void Write(ArraySegment data, Action callback, object state) { } public void End(ProduceEndType endType) diff --git a/test/Microsoft.AspNet.Server.KestralTests/TestServer.cs b/test/Microsoft.AspNet.Server.KestralTests/TestServer.cs index 828c60ce67..0e2c9f3d33 100644 --- a/test/Microsoft.AspNet.Server.KestralTests/TestServer.cs +++ b/test/Microsoft.AspNet.Server.KestralTests/TestServer.cs @@ -5,7 +5,7 @@ using Microsoft.Framework.Runtime.Infrastructure; using System; using System.Threading.Tasks; -namespace Microsoft.AspNet.Server.KestralTests +namespace Microsoft.AspNet.Server.KestrelTests { /// /// Summary description for TestServer From 74a4c8cd27da69ac5583a295625c92175254c73e Mon Sep 17 00:00:00 2001 From: Louis DeJardin Date: Mon, 7 Jul 2014 13:07:15 -0700 Subject: [PATCH 0034/1662] Renaming KestralTests folder KestrelTests --- KestrelHttpServer.sln | 28 +++++++++++++++++-- .../EngineTests.cs | 0 .../MessageBodyExchangerTests.cs | 0 .../MessageBodyTests.cs | 0 ...Microsoft.AspNet.Server.KestrelTests.kproj | 0 .../NetworkingTests.cs | 0 .../Program.cs | 0 .../TestConnection.cs | 0 .../TestInput.cs | 0 .../TestServer.cs | 0 .../project.json | 0 11 files changed, 26 insertions(+), 2 deletions(-) rename test/{Microsoft.AspNet.Server.KestralTests => Microsoft.AspNet.Server.KestrelTests}/EngineTests.cs (100%) rename test/{Microsoft.AspNet.Server.KestralTests => Microsoft.AspNet.Server.KestrelTests}/MessageBodyExchangerTests.cs (100%) rename test/{Microsoft.AspNet.Server.KestralTests => Microsoft.AspNet.Server.KestrelTests}/MessageBodyTests.cs (100%) rename test/{Microsoft.AspNet.Server.KestralTests => Microsoft.AspNet.Server.KestrelTests}/Microsoft.AspNet.Server.KestrelTests.kproj (100%) rename test/{Microsoft.AspNet.Server.KestralTests => Microsoft.AspNet.Server.KestrelTests}/NetworkingTests.cs (100%) rename test/{Microsoft.AspNet.Server.KestralTests => Microsoft.AspNet.Server.KestrelTests}/Program.cs (100%) rename test/{Microsoft.AspNet.Server.KestralTests => Microsoft.AspNet.Server.KestrelTests}/TestConnection.cs (100%) rename test/{Microsoft.AspNet.Server.KestralTests => Microsoft.AspNet.Server.KestrelTests}/TestInput.cs (100%) rename test/{Microsoft.AspNet.Server.KestralTests => Microsoft.AspNet.Server.KestrelTests}/TestServer.cs (100%) rename test/{Microsoft.AspNet.Server.KestralTests => Microsoft.AspNet.Server.KestrelTests}/project.json (100%) diff --git a/KestrelHttpServer.sln b/KestrelHttpServer.sln index 9f7f3f0bc5..46e325ddf7 100644 --- a/KestrelHttpServer.sln +++ b/KestrelHttpServer.sln @@ -1,22 +1,34 @@  Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 14 -VisualStudioVersion = 14.0.21728.0 +VisualStudioVersion = 14.0.21813.0 MinimumVisualStudioVersion = 10.0.40219.1 Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.Server.Kestrel", "src\Microsoft.AspNet.Server.Kestrel\Microsoft.AspNet.Server.Kestrel.kproj", "{F510611A-3BEE-4B88-A613-5F4A74ED82A1}" EndProject -Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.Server.KestralTests", "test\Microsoft.AspNet.Server.KestralTests\Microsoft.AspNet.Server.KestralTests.kproj", "{37F3BFB2-6454-49E5-9D7F-581BF755CCFE}" +Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.Server.KestrelTests", "test\Microsoft.AspNet.Server.KestrelTests\Microsoft.AspNet.Server.KestrelTests.kproj", "{37F3BFB2-6454-49E5-9D7F-581BF755CCFE}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{7972A5D6-3385-4127-9277-428506DD44FF}" ProjectSection(SolutionItems) = preProject + build\_custom-goals.shade = build\_custom-goals.shade + build.cmd = build.cmd global.json = global.json + makefile.shade = makefile.shade EndProjectSection EndProject Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "SampleApp", "src\SampleApp\SampleApp.kproj", "{2C3CB3DC-EEBF-4F52-9E1C-4F2F972E76C3}" EndProject Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Kestrel", "src\Kestrel\Kestrel.kproj", "{30B7617E-58EF-4382-B3EA-5B2E718CF1A6}" EndProject +Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Mvc.Modules", "..\Entropy\samples\Mvc.Modules\Mvc.Modules.kproj", "{181C52C4-E916-416E-96BA-2B645841807F}" +EndProject +Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.RequestContainer", "..\Hosting\src\Microsoft.AspNet.RequestContainer\Microsoft.AspNet.RequestContainer.kproj", "{374A5B0C-3E93-4A23-A4A0-EE2AB6DF7814}" +EndProject +Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.Hosting", "..\Hosting\src\Microsoft.AspNet.Hosting\Microsoft.AspNet.Hosting.kproj", "{3944F036-7E75-47E8-AA52-C4B89A64EC3A}" +EndProject Global + GlobalSection(Performance) = preSolution + HasPerformanceSessions = true + EndGlobalSection GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU Release|Any CPU = Release|Any CPU @@ -38,6 +50,18 @@ Global {30B7617E-58EF-4382-B3EA-5B2E718CF1A6}.Debug|Any CPU.Build.0 = Debug|Any CPU {30B7617E-58EF-4382-B3EA-5B2E718CF1A6}.Release|Any CPU.ActiveCfg = Release|Any CPU {30B7617E-58EF-4382-B3EA-5B2E718CF1A6}.Release|Any CPU.Build.0 = Release|Any CPU + {181C52C4-E916-416E-96BA-2B645841807F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {181C52C4-E916-416E-96BA-2B645841807F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {181C52C4-E916-416E-96BA-2B645841807F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {181C52C4-E916-416E-96BA-2B645841807F}.Release|Any CPU.Build.0 = Release|Any CPU + {374A5B0C-3E93-4A23-A4A0-EE2AB6DF7814}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {374A5B0C-3E93-4A23-A4A0-EE2AB6DF7814}.Debug|Any CPU.Build.0 = Debug|Any CPU + {374A5B0C-3E93-4A23-A4A0-EE2AB6DF7814}.Release|Any CPU.ActiveCfg = Release|Any CPU + {374A5B0C-3E93-4A23-A4A0-EE2AB6DF7814}.Release|Any CPU.Build.0 = Release|Any CPU + {3944F036-7E75-47E8-AA52-C4B89A64EC3A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {3944F036-7E75-47E8-AA52-C4B89A64EC3A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {3944F036-7E75-47E8-AA52-C4B89A64EC3A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {3944F036-7E75-47E8-AA52-C4B89A64EC3A}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/test/Microsoft.AspNet.Server.KestralTests/EngineTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs similarity index 100% rename from test/Microsoft.AspNet.Server.KestralTests/EngineTests.cs rename to test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs diff --git a/test/Microsoft.AspNet.Server.KestralTests/MessageBodyExchangerTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/MessageBodyExchangerTests.cs similarity index 100% rename from test/Microsoft.AspNet.Server.KestralTests/MessageBodyExchangerTests.cs rename to test/Microsoft.AspNet.Server.KestrelTests/MessageBodyExchangerTests.cs diff --git a/test/Microsoft.AspNet.Server.KestralTests/MessageBodyTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/MessageBodyTests.cs similarity index 100% rename from test/Microsoft.AspNet.Server.KestralTests/MessageBodyTests.cs rename to test/Microsoft.AspNet.Server.KestrelTests/MessageBodyTests.cs diff --git a/test/Microsoft.AspNet.Server.KestralTests/Microsoft.AspNet.Server.KestrelTests.kproj b/test/Microsoft.AspNet.Server.KestrelTests/Microsoft.AspNet.Server.KestrelTests.kproj similarity index 100% rename from test/Microsoft.AspNet.Server.KestralTests/Microsoft.AspNet.Server.KestrelTests.kproj rename to test/Microsoft.AspNet.Server.KestrelTests/Microsoft.AspNet.Server.KestrelTests.kproj diff --git a/test/Microsoft.AspNet.Server.KestralTests/NetworkingTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/NetworkingTests.cs similarity index 100% rename from test/Microsoft.AspNet.Server.KestralTests/NetworkingTests.cs rename to test/Microsoft.AspNet.Server.KestrelTests/NetworkingTests.cs diff --git a/test/Microsoft.AspNet.Server.KestralTests/Program.cs b/test/Microsoft.AspNet.Server.KestrelTests/Program.cs similarity index 100% rename from test/Microsoft.AspNet.Server.KestralTests/Program.cs rename to test/Microsoft.AspNet.Server.KestrelTests/Program.cs diff --git a/test/Microsoft.AspNet.Server.KestralTests/TestConnection.cs b/test/Microsoft.AspNet.Server.KestrelTests/TestConnection.cs similarity index 100% rename from test/Microsoft.AspNet.Server.KestralTests/TestConnection.cs rename to test/Microsoft.AspNet.Server.KestrelTests/TestConnection.cs diff --git a/test/Microsoft.AspNet.Server.KestralTests/TestInput.cs b/test/Microsoft.AspNet.Server.KestrelTests/TestInput.cs similarity index 100% rename from test/Microsoft.AspNet.Server.KestralTests/TestInput.cs rename to test/Microsoft.AspNet.Server.KestrelTests/TestInput.cs diff --git a/test/Microsoft.AspNet.Server.KestralTests/TestServer.cs b/test/Microsoft.AspNet.Server.KestrelTests/TestServer.cs similarity index 100% rename from test/Microsoft.AspNet.Server.KestralTests/TestServer.cs rename to test/Microsoft.AspNet.Server.KestrelTests/TestServer.cs diff --git a/test/Microsoft.AspNet.Server.KestralTests/project.json b/test/Microsoft.AspNet.Server.KestrelTests/project.json similarity index 100% rename from test/Microsoft.AspNet.Server.KestralTests/project.json rename to test/Microsoft.AspNet.Server.KestrelTests/project.json From 9c1cb29cdd482a968afa573f987208daaf274dbd Mon Sep 17 00:00:00 2001 From: Louis DeJardin Date: Mon, 7 Jul 2014 13:15:29 -0700 Subject: [PATCH 0035/1662] SampleApp changed location --- KestrelHttpServer.sln | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/KestrelHttpServer.sln b/KestrelHttpServer.sln index 46e325ddf7..45852b07ac 100644 --- a/KestrelHttpServer.sln +++ b/KestrelHttpServer.sln @@ -15,7 +15,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution makefile.shade = makefile.shade EndProjectSection EndProject -Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "SampleApp", "src\SampleApp\SampleApp.kproj", "{2C3CB3DC-EEBF-4F52-9E1C-4F2F972E76C3}" +Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "SampleApp", "samples\SampleApp\SampleApp.kproj", "{2C3CB3DC-EEBF-4F52-9E1C-4F2F972E76C3}" EndProject Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Kestrel", "src\Kestrel\Kestrel.kproj", "{30B7617E-58EF-4382-B3EA-5B2E718CF1A6}" EndProject From 21778f631a4d8a976c19f32655d2c9f6dd1d7074 Mon Sep 17 00:00:00 2001 From: Louis DeJardin Date: Mon, 7 Jul 2014 14:01:02 -0700 Subject: [PATCH 0036/1662] Guarding against more read_cb cases --- KestrelHttpServer.sln | 18 ---------- .../Http/Connection.cs | 35 +++++++++++++------ .../Http/SocketInput.cs | 12 +++++-- .../project.json | 11 +++++- 4 files changed, 44 insertions(+), 32 deletions(-) diff --git a/KestrelHttpServer.sln b/KestrelHttpServer.sln index 45852b07ac..72427af0cb 100644 --- a/KestrelHttpServer.sln +++ b/KestrelHttpServer.sln @@ -19,12 +19,6 @@ Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "SampleApp", "samples\Sample EndProject Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Kestrel", "src\Kestrel\Kestrel.kproj", "{30B7617E-58EF-4382-B3EA-5B2E718CF1A6}" EndProject -Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Mvc.Modules", "..\Entropy\samples\Mvc.Modules\Mvc.Modules.kproj", "{181C52C4-E916-416E-96BA-2B645841807F}" -EndProject -Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.RequestContainer", "..\Hosting\src\Microsoft.AspNet.RequestContainer\Microsoft.AspNet.RequestContainer.kproj", "{374A5B0C-3E93-4A23-A4A0-EE2AB6DF7814}" -EndProject -Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.Hosting", "..\Hosting\src\Microsoft.AspNet.Hosting\Microsoft.AspNet.Hosting.kproj", "{3944F036-7E75-47E8-AA52-C4B89A64EC3A}" -EndProject Global GlobalSection(Performance) = preSolution HasPerformanceSessions = true @@ -50,18 +44,6 @@ Global {30B7617E-58EF-4382-B3EA-5B2E718CF1A6}.Debug|Any CPU.Build.0 = Debug|Any CPU {30B7617E-58EF-4382-B3EA-5B2E718CF1A6}.Release|Any CPU.ActiveCfg = Release|Any CPU {30B7617E-58EF-4382-B3EA-5B2E718CF1A6}.Release|Any CPU.Build.0 = Release|Any CPU - {181C52C4-E916-416E-96BA-2B645841807F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {181C52C4-E916-416E-96BA-2B645841807F}.Debug|Any CPU.Build.0 = Debug|Any CPU - {181C52C4-E916-416E-96BA-2B645841807F}.Release|Any CPU.ActiveCfg = Release|Any CPU - {181C52C4-E916-416E-96BA-2B645841807F}.Release|Any CPU.Build.0 = Release|Any CPU - {374A5B0C-3E93-4A23-A4A0-EE2AB6DF7814}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {374A5B0C-3E93-4A23-A4A0-EE2AB6DF7814}.Debug|Any CPU.Build.0 = Debug|Any CPU - {374A5B0C-3E93-4A23-A4A0-EE2AB6DF7814}.Release|Any CPU.ActiveCfg = Release|Any CPU - {374A5B0C-3E93-4A23-A4A0-EE2AB6DF7814}.Release|Any CPU.Build.0 = Release|Any CPU - {3944F036-7E75-47E8-AA52-C4B89A64EC3A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {3944F036-7E75-47E8-AA52-C4B89A64EC3A}.Debug|Any CPU.Build.0 = Debug|Any CPU - {3944F036-7E75-47E8-AA52-C4B89A64EC3A}.Release|Any CPU.ActiveCfg = Release|Any CPU - {3944F036-7E75-47E8-AA52-C4B89A64EC3A}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs index 486e0a82ec..32ca223b97 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs @@ -76,30 +76,43 @@ namespace Microsoft.AspNet.Server.Kestrel.Http private Libuv.uv_buf_t OnAlloc(UvStreamHandle handle, int suggestedSize) { return handle.Libuv.buf_init( - SocketInput.Pin(2048), + SocketInput.Pin(2048), 2048); } - private void OnRead(UvStreamHandle handle, int nread, Exception error) + private void OnRead(UvStreamHandle handle, int status, Exception error) { - SocketInput.Unpin(nread); + SocketInput.Unpin(status); - if (nread == 0 || error != null) + var normalRead = error == null && status > 0; + var normalDone = status == 0 || status == -4077 || status == -4095; + var errorDone = !(normalDone || normalRead); + + if (normalRead) + { + KestrelTrace.Log.ConnectionRead(_connectionId, status); + } + else if (normalDone || errorDone) { - SocketInput.RemoteIntakeFin = true; KestrelTrace.Log.ConnectionReadFin(_connectionId); - if (error != null) + SocketInput.RemoteIntakeFin = true; + + if (errorDone && error != null) { Trace.WriteLine("Connection.OnRead " + error.ToString()); } } - else - { - KestrelTrace.Log.ConnectionRead(_connectionId, nread); - } - _frame.Consume(); + + try + { + _frame.Consume(); + } + catch (Exception ex) + { + Trace.WriteLine("Connection._frame.Consume " + ex.ToString()); + } } void IConnectionControl.Pause() diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketInput.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketInput.cs index 5016a9881f..69e5ca2eda 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketInput.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketInput.cs @@ -90,16 +90,24 @@ namespace Microsoft.AspNet.Server.Kestrel.Http Buffer = new ArraySegment(Buffer.Array, Buffer.Offset, Buffer.Count + count); } + public IntPtr Pin(int minimumSize) { var segment = Available(minimumSize); _gcHandle = GCHandle.Alloc(segment.Array, GCHandleType.Pinned); return _gcHandle.AddrOfPinnedObject() + segment.Offset; } + public void Unpin(int count) { - _gcHandle.Free(); - Extend(count); + // read_cb may called without an earlier alloc_cb + // this does not need to be thread-safe + // IsAllocated is checked only because Unpin can be called redundantly + if (_gcHandle.IsAllocated) + { + _gcHandle.Free(); + Extend(count); + } } } diff --git a/src/Microsoft.AspNet.Server.Kestrel/project.json b/src/Microsoft.AspNet.Server.Kestrel/project.json index 3435c86826..9f7a6f79e3 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/project.json +++ b/src/Microsoft.AspNet.Server.Kestrel/project.json @@ -4,8 +4,17 @@ "Microsoft.Framework.Runtime.Interfaces": "1.0.0-*" }, "configurations": { - "net45": { }, + "net45": { + "compilationOptions": { + "define": [ "TRACE", "NET45" ], + "allowUnsafe": true + } + }, "k10": { + "compilationOptions": { + "define": [ "TRACE", "K10" ], + "allowUnsafe": true + }, "dependencies": { "System.Threading.ThreadPool": "4.0.10.0", "System.Diagnostics.Debug": "4.0.10.0", From b0f738651ebc64baf1f52acc9d3a61f170f69f27 Mon Sep 17 00:00:00 2001 From: Louis DeJardin Date: Mon, 7 Jul 2014 14:23:49 -0700 Subject: [PATCH 0037/1662] WebSockets package renamed to .Server --- samples/SampleApp/project.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/SampleApp/project.json b/samples/SampleApp/project.json index f34a5acc74..ffdf474e65 100644 --- a/samples/SampleApp/project.json +++ b/samples/SampleApp/project.json @@ -3,7 +3,7 @@ "dependencies": { "Kestrel": "1.0.0-*", "Microsoft.AspNet.Server.WebListener": "1.0.0-*", - "Microsoft.AspNet.WebSockets.Middleware": "1.0.0-*" + "Microsoft.AspNet.WebSockets.Server": "1.0.0-*" }, "configurations": { "net45": { }, From ca9e8370480d650aa8be797f0f699ad9bd23c7de Mon Sep 17 00:00:00 2001 From: Louis DeJardin Date: Mon, 7 Jul 2014 15:07:28 -0700 Subject: [PATCH 0038/1662] Need to add content type to dylib for nupkg file format to see it --- build/_custom-goals.shade | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/build/_custom-goals.shade b/build/_custom-goals.shade index be70db8ae0..78e64e8b7d 100644 --- a/build/_custom-goals.shade +++ b/build/_custom-goals.shade @@ -18,5 +18,23 @@ use namespace="System.Net" archive.CreateEntryFromFile( "src/Microsoft.AspNet.Server.Kestrel/native/darwin/universal/libuv.dylib", "native/darwin/universal/libuv.dylib"); + + XDocument doc; + var entry = archive.GetEntry("[Content_Types].xml"); + using (var stream = entry.Open()) + { + doc = XDocument.Load(stream); + } + doc.Root.Add( + new XElement( + XName.Get("Default", "http://schemas.openxmlformats.org/package/2006/content-types"), + new XAttribute("Extension", "dylib"), + new XAttribute("ContentType", "application/octet") + )); + using (var stream = entry.Open()) + { + doc.Save(stream); + } + archive.Dispose(); } From 836be5565abdf455dfe4103f53fddbd882bee000 Mon Sep 17 00:00:00 2001 From: Louis DeJardin Date: Tue, 8 Jul 2014 14:51:13 -0700 Subject: [PATCH 0039/1662] Using weak gchandles from native to managed See #15 --- .../Http/Connection.cs | 2 +- .../KestrelEngine.cs | 2 +- .../Networking/UvMemory.cs | 4 +-- .../Networking/UvStreamHandle.cs | 32 +++++++++++++++---- 4 files changed, 30 insertions(+), 10 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs index 32ca223b97..b159b251f1 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs @@ -95,8 +95,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http else if (normalDone || errorDone) { KestrelTrace.Log.ConnectionReadFin(_connectionId); - SocketInput.RemoteIntakeFin = true; + _socket.ReadStop(); if (errorDone && error != null) { diff --git a/src/Microsoft.AspNet.Server.Kestrel/KestrelEngine.cs b/src/Microsoft.AspNet.Server.Kestrel/KestrelEngine.cs index dec882350c..3e2b01985b 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/KestrelEngine.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/KestrelEngine.cs @@ -79,7 +79,7 @@ namespace Microsoft.AspNet.Server.Kestrel { foreach (var thread in Threads) { - thread.Stop(TimeSpan.FromSeconds(45)); + thread.Stop(TimeSpan.FromSeconds(2.5)); } Threads.Clear(); } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvMemory.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvMemory.cs index 6000c82ebb..e43e600ec3 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvMemory.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvMemory.cs @@ -36,7 +36,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking _threadId = Thread.CurrentThread.ManagedThreadId; handle = Marshal.AllocCoTaskMem(size); - *(IntPtr*)handle = GCHandle.ToIntPtr(GCHandle.Alloc(this)); + *(IntPtr*)handle = GCHandle.ToIntPtr(GCHandle.Alloc(this, GCHandleType.Weak)); } protected void CreateHandle(UvLoopHandle loop, int size) @@ -54,7 +54,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking { Trace.Assert(closed || !IsClosed, "Handle is closed"); Trace.Assert(!IsInvalid, "Handle is invalid"); - Trace.Assert(_threadId == Thread.CurrentThread.ManagedThreadId, "ThreadId is correct"); + Trace.Assert(_threadId == Thread.CurrentThread.ManagedThreadId, "ThreadId is incorrect"); } unsafe protected static void DestroyHandle(IntPtr memory) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvStreamHandle.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvStreamHandle.cs index 9249b53104..ecde6e08e3 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvStreamHandle.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvStreamHandle.cs @@ -3,6 +3,7 @@ using System; using System.Diagnostics; +using System.Runtime.InteropServices; namespace Microsoft.AspNet.Server.Kestrel.Networking { @@ -12,19 +13,33 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking private readonly static Libuv.uv_alloc_cb _uv_alloc_cb = UvAllocCb; private readonly static Libuv.uv_read_cb _uv_read_cb = UvReadCb; - public Action _connectionCallback; - public object _connectionState; + public Action _listenCallback; + public object _listenState; + private GCHandle _listenVitality; public Func _allocCallback; - public Action _readCallback; public object _readState; + private GCHandle _readVitality; + protected override bool ReleaseHandle() + { + if (_listenVitality.IsAllocated) + { + _listenVitality.Free(); + } + if (_readVitality.IsAllocated) + { + _readVitality.Free(); + } + return base.ReleaseHandle(); + } public void Listen(int backlog, Action callback, object state) { - _connectionCallback = callback; - _connectionState = state; + _listenCallback = callback; + _listenState = state; + _listenVitality = GCHandle.Alloc(this, GCHandleType.Normal); _uv.listen(this, 10, _uv_connection_cb); } @@ -41,11 +56,16 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking _allocCallback = allocCallback; _readCallback = readCallback; _readState = state; + _readVitality = GCHandle.Alloc(this, GCHandleType.Normal); _uv.read_start(this, _uv_alloc_cb, _uv_read_cb); } public void ReadStop() { + _allocCallback = null; + _readCallback = null; + _readState = null; + _readVitality.Free(); _uv.read_stop(this); } @@ -64,7 +84,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking try { - stream._connectionCallback(stream, status, error, stream._connectionState); + stream._listenCallback(stream, status, error, stream._listenState); } catch (Exception ex) { From 2da561cb7ab1cb8fa50c915373d128cba214125f Mon Sep 17 00:00:00 2001 From: Louis DeJardin Date: Tue, 8 Jul 2014 16:02:09 -0700 Subject: [PATCH 0040/1662] Garbage collecting safe handles need to queue the uv_close All of the uv_* calls must be called on the original thread the finalizer thread cleaning up safehandle classes needs special handling see #16 --- .../Http/Listener.cs | 4 +- .../Infrastructure/KestrelThread.cs | 59 +++++++++++++++++-- .../Networking/Libuv.cs | 4 ++ .../Networking/UcAsyncHandle.cs | 6 +- .../Networking/UvHandle.cs | 24 +++++++- .../Networking/UvLoopHandle.cs | 9 ++- .../Networking/UvMemory.cs | 41 +++++++------ .../Networking/UvShutdownReq.cs | 5 +- .../Networking/UvTcpHandle.cs | 16 ++++- .../Networking/UvWriteRequest.cs | 14 ++++- 10 files changed, 149 insertions(+), 33 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs index 98de2b440f..5bc7ebdeaf 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs @@ -69,7 +69,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http try { ListenSocket = new UvTcpHandle(); - ListenSocket.Init(Thread.Loop); + ListenSocket.Init(Thread.Loop, Thread.QueueCloseHandle); ListenSocket.Bind(new IPEndPoint(IPAddress.Any, port)); ListenSocket.Listen(10, _connectionCallback, this); tcs.SetResult(0); @@ -85,7 +85,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http private void OnConnection(UvStreamHandle listenSocket, int status) { var acceptSocket = new UvTcpHandle(); - acceptSocket.Init(Thread.Loop); + acceptSocket.Init(Thread.Loop, Thread.QueueCloseHandle); listenSocket.Accept(acceptSocket); var connection = new Connection(this, acceptSocket); diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs index fae471eec5..5ef6f101a7 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs @@ -4,6 +4,7 @@ using Microsoft.AspNet.Server.Kestrel.Networking; using System; using System.Collections.Generic; +using System.Diagnostics; using System.Runtime.ExceptionServices; using System.Threading; using System.Threading.Tasks; @@ -21,6 +22,8 @@ namespace Microsoft.AspNet.Server.Kestrel UvAsyncHandle _post; Queue _workAdding = new Queue(); Queue _workRunning = new Queue(); + Queue _closeHandleAdding = new Queue(); + Queue _closeHandleRunning = new Queue(); object _workSync = new Object(); bool _stopImmediate = false; private ExceptionDispatchInfo _closeError; @@ -31,10 +34,13 @@ namespace Microsoft.AspNet.Server.Kestrel _loop = new UvLoopHandle(); _post = new UvAsyncHandle(); _thread = new Thread(ThreadStart); + QueueCloseHandle = PostCloseHandle; } public UvLoopHandle Loop { get { return _loop; } } + public Action, IntPtr> QueueCloseHandle { get; internal set; } + public Task StartAsync() { var tcs = new TaskCompletionSource(); @@ -92,6 +98,15 @@ namespace Microsoft.AspNet.Server.Kestrel return tcs.Task; } + private void PostCloseHandle(Action callback, IntPtr handle) + { + lock (_workSync) + { + _closeHandleAdding.Enqueue(new CloseHandle { Callback = callback, Handle = handle }); + } + _post.Send(); + } + private void ThreadStart(object parameter) { var tcs = (TaskCompletionSource)parameter; @@ -119,7 +134,7 @@ namespace Microsoft.AspNet.Server.Kestrel _post.Reference(); _post.DangerousClose(); _engine.Libuv.walk( - _loop, + _loop, (ptr, arg) => { var handle = UvMemory.FromIntPtr(ptr); @@ -138,12 +153,19 @@ namespace Microsoft.AspNet.Server.Kestrel private void OnPost() { - var queue = _workAdding; + DoPostWork(); + DoPostCloseHandle(); + } + + private void DoPostWork() + { + Queue queue; lock (_workSync) { + queue = _workAdding; _workAdding = _workRunning; + _workRunning = queue; } - _workRunning = queue; while (queue.Count != 0) { var work = queue.Dequeue(); @@ -156,7 +178,7 @@ namespace Microsoft.AspNet.Server.Kestrel tcs => { ((TaskCompletionSource)tcs).SetResult(0); - }, + }, work.Completion); } } @@ -168,11 +190,33 @@ namespace Microsoft.AspNet.Server.Kestrel } else { - // TODO: unobserved exception? + Trace.WriteLine("KestrelThread.DoPostWork " + ex.ToString()); } } } } + private void DoPostCloseHandle() + { + Queue queue; + lock (_workSync) + { + queue = _closeHandleAdding; + _closeHandleAdding = _closeHandleRunning; + _closeHandleRunning = queue; + } + while (queue.Count != 0) + { + var closeHandle = queue.Dequeue(); + try + { + closeHandle.Callback(closeHandle.Handle); + } + catch (Exception ex) + { + Trace.WriteLine("KestrelThread.DoPostCloseHandle " + ex.ToString()); + } + } + } private struct Work { @@ -180,5 +224,10 @@ namespace Microsoft.AspNet.Server.Kestrel public object State; public TaskCompletionSource Completion; } + private struct CloseHandle + { + public Action Callback; + public IntPtr Handle; + } } } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/Libuv.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/Libuv.cs index 18e9478f86..c777af7998 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/Libuv.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/Libuv.cs @@ -128,6 +128,10 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking handle.Validate(closed: true); _uv_close(handle.InternalGetHandle(), close_cb); } + public void close(IntPtr handle, uv_close_cb close_cb) + { + _uv_close(handle, close_cb); + } [UnmanagedFunctionPointer(CallingConvention.Cdecl)] public delegate void uv_async_cb(IntPtr handle); diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/UcAsyncHandle.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/UcAsyncHandle.cs index 7709ebd50c..31e8f9b054 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/UcAsyncHandle.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/UcAsyncHandle.cs @@ -12,7 +12,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking public void Init(UvLoopHandle loop, Action callback) { - CreateHandle(loop, loop.Libuv.handle_size(Libuv.HandleType.ASYNC)); + CreateMemory( + loop.Libuv, + loop.ThreadId, + loop.Libuv.handle_size(Libuv.HandleType.ASYNC)); + _callback = callback; _uv.async_init(loop, this, _uv_async_cb); } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvHandle.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvHandle.cs index d08a6910d7..fe12f19330 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvHandle.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvHandle.cs @@ -2,20 +2,40 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Threading; namespace Microsoft.AspNet.Server.Kestrel.Networking { public abstract class UvHandle : UvMemory { - static Libuv.uv_close_cb _close_cb = DestroyHandle; + static Libuv.uv_close_cb _destroyMemory = DestroyMemory; + Action, IntPtr> _queueCloseHandle; + + unsafe protected void CreateHandle( + Libuv uv, + int threadId, + int size, + Action, IntPtr> queueCloseHandle) + { + _queueCloseHandle = queueCloseHandle; + CreateMemory(uv, threadId, size); + } protected override bool ReleaseHandle() { var memory = handle; if (memory != IntPtr.Zero) { - _uv.close(this, _close_cb); handle = IntPtr.Zero; + + if (Thread.CurrentThread.ManagedThreadId == ThreadId) + { + _uv.close(memory, _destroyMemory); + } + else + { + _queueCloseHandle(memory2 => _uv.close(memory2, _destroyMemory), memory); + } } return true; } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvLoopHandle.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvLoopHandle.cs index 9ea5cb3d8a..a13ae2ccce 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvLoopHandle.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvLoopHandle.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Threading; namespace Microsoft.AspNet.Server.Kestrel.Networking { @@ -9,7 +10,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking { public void Init(Libuv uv) { - CreateHandle(uv, uv.loop_size()); + CreateMemory( + uv, + Thread.CurrentThread.ManagedThreadId, + uv.loop_size()); + _uv.loop_init(this); } @@ -30,7 +35,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking { _uv.loop_close(this); handle = IntPtr.Zero; - DestroyHandle(memory); + DestroyMemory(memory); } return true; } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvMemory.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvMemory.cs index e43e600ec3..c3b3c6ce28 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvMemory.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvMemory.cs @@ -14,7 +14,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking public abstract class UvMemory : SafeHandle { protected Libuv _uv; - int _threadId; + private int _threadId; public UvMemory() : base(IntPtr.Zero, true) { @@ -30,19 +30,36 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking } } - unsafe protected void CreateHandle(Libuv uv, int size) + public int ThreadId + { + get + { + return _threadId; + } + private set + { + _threadId = value; + } + } + + unsafe protected void CreateMemory(Libuv uv, int threadId, int size) { _uv = uv; - _threadId = Thread.CurrentThread.ManagedThreadId; - + ThreadId = threadId; + handle = Marshal.AllocCoTaskMem(size); *(IntPtr*)handle = GCHandle.ToIntPtr(GCHandle.Alloc(this, GCHandleType.Weak)); } - protected void CreateHandle(UvLoopHandle loop, int size) + unsafe protected static void DestroyMemory(IntPtr memory) { - CreateHandle(loop._uv, size); - _threadId = loop._threadId; + var gcHandlePtr = *(IntPtr*)memory; + if (gcHandlePtr != IntPtr.Zero) + { + var gcHandle = GCHandle.FromIntPtr(gcHandlePtr); + gcHandle.Free(); + } + Marshal.FreeCoTaskMem(memory); } internal IntPtr InternalGetHandle() @@ -57,16 +74,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking Trace.Assert(_threadId == Thread.CurrentThread.ManagedThreadId, "ThreadId is incorrect"); } - unsafe protected static void DestroyHandle(IntPtr memory) - { - var gcHandlePtr = *(IntPtr*)memory; - if (gcHandlePtr != IntPtr.Zero) - { - GCHandle.FromIntPtr(gcHandlePtr).Free(); - } - Marshal.FreeCoTaskMem(memory); - } - unsafe public static THandle FromIntPtr(IntPtr handle) { GCHandle gcHandle = GCHandle.FromIntPtr(*(IntPtr*)handle); diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvShutdownReq.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvShutdownReq.cs index 2606285aa0..ef280549c8 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvShutdownReq.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvShutdownReq.cs @@ -17,7 +17,10 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking public void Init(UvLoopHandle loop) { - CreateHandle(loop, loop.Libuv.req_size(Libuv.RequestType.SHUTDOWN)); + CreateMemory( + loop.Libuv, + loop.ThreadId, + loop.Libuv.req_size(Libuv.RequestType.SHUTDOWN)); } public void Shutdown(UvStreamHandle handle, Action callback, object state) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvTcpHandle.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvTcpHandle.cs index 96d5ddbbc9..e3f90ad846 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvTcpHandle.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvTcpHandle.cs @@ -10,7 +10,21 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking { public void Init(UvLoopHandle loop) { - CreateHandle(loop, loop.Libuv.handle_size(Libuv.HandleType.TCP)); + CreateMemory( + loop.Libuv, + loop.ThreadId, + loop.Libuv.handle_size(Libuv.HandleType.TCP)); + + _uv.tcp_init(loop, this); + } + + public void Init(UvLoopHandle loop, Action, IntPtr> queueCloseHandle) + { + CreateHandle( + loop.Libuv, + loop.ThreadId, + loop.Libuv.handle_size(Libuv.HandleType.TCP), queueCloseHandle); + _uv.tcp_init(loop, this); } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvWriteRequest.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvWriteRequest.cs index dee7b6bb66..60228c4eca 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvWriteRequest.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvWriteRequest.cs @@ -27,7 +27,10 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking { var requestSize = loop.Libuv.req_size(Libuv.RequestType.WRITE); var bufferSize = Marshal.SizeOf(typeof(Libuv.uv_buf_t)) * BUFFER_COUNT; - CreateHandle(loop, requestSize + bufferSize); + CreateMemory( + loop.Libuv, + loop.ThreadId, + requestSize + bufferSize); _bufs = handle + requestSize; } @@ -37,17 +40,23 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking Action callback, object state) { + // add GCHandle to keeps this SafeHandle alive while request processing + _pins.Add(GCHandle.Alloc(this, GCHandleType.Normal)); + var pBuffers = (Libuv.uv_buf_t*)_bufs; var nBuffers = bufs.Count; if (nBuffers > BUFFER_COUNT) { + // create and pin buffer array when it's larger than the pre-allocated one var bufArray = new Libuv.uv_buf_t[nBuffers]; var gcHandle = GCHandle.Alloc(bufArray, GCHandleType.Pinned); _pins.Add(gcHandle); pBuffers = (Libuv.uv_buf_t*)gcHandle.AddrOfPinnedObject(); } + for (var index = 0; index != nBuffers; ++index) { + // create and pin each segment being written var buf = bufs.Array[bufs.Offset + index]; var gcHandle = GCHandle.Alloc(buf.Array, GCHandleType.Pinned); @@ -56,6 +65,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking gcHandle.AddrOfPinnedObject() + buf.Offset, buf.Count); } + _callback = callback; _state = state; _uv.write(this, handle, pBuffers, nBuffers, _uv_write_cb); @@ -97,7 +107,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking { protected override bool ReleaseHandle() { - DestroyHandle(handle); + DestroyMemory(handle); handle = IntPtr.Zero; return true; } From 1406ec94c32b34f8c11590fbe28b37ae080161a6 Mon Sep 17 00:00:00 2001 From: Louis DeJardin Date: Tue, 8 Jul 2014 16:14:41 -0700 Subject: [PATCH 0041/1662] Fixing WriteAsync reference --- samples/SampleApp/Startup.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/samples/SampleApp/Startup.cs b/samples/SampleApp/Startup.cs index 65462519d6..f6a9e33a64 100644 --- a/samples/SampleApp/Startup.cs +++ b/samples/SampleApp/Startup.cs @@ -1,4 +1,5 @@ using Microsoft.AspNet.Builder; +using Microsoft.AspNet.Http; using System; using System.Net.WebSockets; using System.Threading; From de6c32dc4b33c066bad84e65b76e05e46202769a Mon Sep 17 00:00:00 2001 From: Louis DeJardin Date: Tue, 8 Jul 2014 18:11:09 -0700 Subject: [PATCH 0042/1662] Guarding against leaking GCHandles in read/write operations See #19 --- .../Http/SocketOutput.cs | 10 ++- .../Networking/UvStreamHandle.cs | 57 ++++++++++++--- .../Networking/UvWriteRequest.cs | 69 +++++++++++-------- 3 files changed, 97 insertions(+), 39 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs index c43d13dcba..9b6e9fa52c 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs @@ -53,11 +53,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Http SocketOutput _self; ArraySegment _buffer; - Action _drained; UvStreamHandle _socket; Action _callback; object _state; - GCHandle _pin; internal void Contextualize( SocketOutput socketOutput, @@ -87,8 +85,14 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { KestrelTrace.Log.ConnectionWriteCallback(0, status); //NOTE: pool this? + + var callback = _callback; + _callback = null; + var state = _state; + _state = null; + Dispose(); - _callback(error, _state); + callback(error, state); } } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvStreamHandle.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvStreamHandle.cs index ecde6e08e3..e9f9279f16 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvStreamHandle.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvStreamHandle.cs @@ -37,10 +37,27 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking public void Listen(int backlog, Action callback, object state) { - _listenCallback = callback; - _listenState = state; - _listenVitality = GCHandle.Alloc(this, GCHandleType.Normal); - _uv.listen(this, 10, _uv_connection_cb); + if (_listenVitality.IsAllocated) + { + throw new InvalidOperationException("TODO: Listen may not be called more than once"); + } + try + { + _listenCallback = callback; + _listenState = state; + _listenVitality = GCHandle.Alloc(this, GCHandleType.Normal); + _uv.listen(this, 10, _uv_connection_cb); + } + catch + { + _listenCallback = null; + _listenState = null; + if (_listenVitality.IsAllocated) + { + _listenVitality.Free(); + } + throw; + } } public void Accept(UvStreamHandle handle) @@ -53,15 +70,37 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking Action readCallback, object state) { - _allocCallback = allocCallback; - _readCallback = readCallback; - _readState = state; - _readVitality = GCHandle.Alloc(this, GCHandleType.Normal); - _uv.read_start(this, _uv_alloc_cb, _uv_read_cb); + if (_readVitality.IsAllocated) + { + throw new InvalidOperationException("TODO: ReadStop must be called before ReadStart may be called again"); + } + try + { + _allocCallback = allocCallback; + _readCallback = readCallback; + _readState = state; + _readVitality = GCHandle.Alloc(this, GCHandleType.Normal); + _uv.read_start(this, _uv_alloc_cb, _uv_read_cb); + } + catch + { + _allocCallback = null; + _readCallback = null; + _readState = null; + if (_readVitality.IsAllocated) + { + _readVitality.Free(); + } + throw; + } } public void ReadStop() { + if (!_readVitality.IsAllocated) + { + throw new InvalidOperationException("TODO: ReadStart must be called before ReadStop may be called"); + } _allocCallback = null; _readCallback = null; _readState = null; diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvWriteRequest.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvWriteRequest.cs index 60228c4eca..dc58e5688f 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvWriteRequest.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvWriteRequest.cs @@ -40,45 +40,60 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking Action callback, object state) { - // add GCHandle to keeps this SafeHandle alive while request processing - _pins.Add(GCHandle.Alloc(this, GCHandleType.Normal)); - - var pBuffers = (Libuv.uv_buf_t*)_bufs; - var nBuffers = bufs.Count; - if (nBuffers > BUFFER_COUNT) + try { - // create and pin buffer array when it's larger than the pre-allocated one - var bufArray = new Libuv.uv_buf_t[nBuffers]; - var gcHandle = GCHandle.Alloc(bufArray, GCHandleType.Pinned); - _pins.Add(gcHandle); - pBuffers = (Libuv.uv_buf_t*)gcHandle.AddrOfPinnedObject(); - } + // add GCHandle to keeps this SafeHandle alive while request processing + _pins.Add(GCHandle.Alloc(this, GCHandleType.Normal)); - for (var index = 0; index != nBuffers; ++index) + var pBuffers = (Libuv.uv_buf_t*)_bufs; + var nBuffers = bufs.Count; + if (nBuffers > BUFFER_COUNT) + { + // create and pin buffer array when it's larger than the pre-allocated one + var bufArray = new Libuv.uv_buf_t[nBuffers]; + var gcHandle = GCHandle.Alloc(bufArray, GCHandleType.Pinned); + _pins.Add(gcHandle); + pBuffers = (Libuv.uv_buf_t*)gcHandle.AddrOfPinnedObject(); + } + + for (var index = 0; index != nBuffers; ++index) + { + // create and pin each segment being written + var buf = bufs.Array[bufs.Offset + index]; + + var gcHandle = GCHandle.Alloc(buf.Array, GCHandleType.Pinned); + _pins.Add(gcHandle); + pBuffers[index] = Libuv.buf_init( + gcHandle.AddrOfPinnedObject() + buf.Offset, + buf.Count); + } + + _callback = callback; + _state = state; + _uv.write(this, handle, pBuffers, nBuffers, _uv_write_cb); + } + catch { - // create and pin each segment being written - var buf = bufs.Array[bufs.Offset + index]; - - var gcHandle = GCHandle.Alloc(buf.Array, GCHandleType.Pinned); - _pins.Add(gcHandle); - pBuffers[index] = Libuv.buf_init( - gcHandle.AddrOfPinnedObject() + buf.Offset, - buf.Count); + _callback = null; + _state = null; + Unpin(this); + throw; } - - _callback = callback; - _state = state; - _uv.write(this, handle, pBuffers, nBuffers, _uv_write_cb); } - private static void UvWriteCb(IntPtr ptr, int status) + private static void Unpin(UvWriteReq req) { - var req = FromIntPtr(ptr); foreach (var pin in req._pins) { pin.Free(); } req._pins.Clear(); + } + + private static void UvWriteCb(IntPtr ptr, int status) + { + var req = FromIntPtr(ptr); + Unpin(req); var callback = req._callback; req._callback = null; From 33cd0d89aaf82d71fd964938ce10d2828209e722 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Sun, 13 Jul 2014 22:12:48 -0700 Subject: [PATCH 0043/1662] Renamed configurations to frameworks in project.json --- samples/SampleApp/project.json | 2 +- src/Kestrel/project.json | 2 +- src/Microsoft.AspNet.Server.Kestrel/project.json | 4 ++-- test/Microsoft.AspNet.Server.KestrelTests/project.json | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/samples/SampleApp/project.json b/samples/SampleApp/project.json index ffdf474e65..6cdf28bc48 100644 --- a/samples/SampleApp/project.json +++ b/samples/SampleApp/project.json @@ -5,7 +5,7 @@ "Microsoft.AspNet.Server.WebListener": "1.0.0-*", "Microsoft.AspNet.WebSockets.Server": "1.0.0-*" }, - "configurations": { + "frameworks": { "net45": { }, "k10": { "dependencies": { diff --git a/src/Kestrel/project.json b/src/Kestrel/project.json index 2781b38bb3..1f8ca15042 100644 --- a/src/Kestrel/project.json +++ b/src/Kestrel/project.json @@ -4,7 +4,7 @@ "Microsoft.AspNet.Hosting": "1.0.0-*", "Microsoft.AspNet.Server.Kestrel": "1.0.0-*" }, - "configurations": { + "frameworks": { "net45": { "dependencies": { } }, diff --git a/src/Microsoft.AspNet.Server.Kestrel/project.json b/src/Microsoft.AspNet.Server.Kestrel/project.json index 9f7a6f79e3..c7acb38796 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/project.json +++ b/src/Microsoft.AspNet.Server.Kestrel/project.json @@ -1,9 +1,9 @@ -{ +{ "version": "1.0.0-*", "dependencies": { "Microsoft.Framework.Runtime.Interfaces": "1.0.0-*" }, - "configurations": { + "frameworks": { "net45": { "compilationOptions": { "define": [ "TRACE", "NET45" ], diff --git a/test/Microsoft.AspNet.Server.KestrelTests/project.json b/test/Microsoft.AspNet.Server.KestrelTests/project.json index cdd8390707..9afbb9a1e3 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/project.json +++ b/test/Microsoft.AspNet.Server.KestrelTests/project.json @@ -1,10 +1,10 @@ -{ +{ "version": "1.0.0-*", "dependencies": { "Xunit.KRunner": "1.0.0-*", "Microsoft.AspNet.Server.Kestrel": "1.0.0-*" }, - "configurations": { + "frameworks": { "net45": { "compilationOptions": { "define": [ "TRACE" ] } }, From 4fc0be86b6c8a62d3a1f2a89d8ac3aacf7faedb6 Mon Sep 17 00:00:00 2001 From: Pranav K Date: Mon, 14 Jul 2014 15:11:48 -0700 Subject: [PATCH 0044/1662] Reacting to System.Collections version change --- src/Microsoft.AspNet.Server.Kestrel/project.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/project.json b/src/Microsoft.AspNet.Server.Kestrel/project.json index c7acb38796..de43a8c018 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/project.json +++ b/src/Microsoft.AspNet.Server.Kestrel/project.json @@ -23,7 +23,7 @@ "System.Text.Encoding": "4.0.20.0", "System.Threading.Tasks": "4.0.10.0", "System.Diagnostics.Tracing": "4.0.10.0", - "System.Collections": "4.0.0.0", + "System.Collections": "4.0.10.0", "System.IO": "4.0.0.0", "System.Linq": "4.0.0.0", "System.Net.Primitives": "4.0.10.0", From 6b2099df28bb97d7495e47e07c257d487b211bec Mon Sep 17 00:00:00 2001 From: Pranav K Date: Mon, 14 Jul 2014 22:06:25 -0700 Subject: [PATCH 0045/1662] Consume SKIP_KRE_INSTALL in build.cmd to skip installing kvm --- build.cmd | 2 ++ 1 file changed, 2 insertions(+) diff --git a/build.cmd b/build.cmd index 7987edb77d..60179e48c3 100644 --- a/build.cmd +++ b/build.cmd @@ -18,6 +18,8 @@ copy %CACHED_NUGET% .nuget\nuget.exe > nul IF EXIST packages\KoreBuild goto run .nuget\NuGet.exe install KoreBuild -ExcludeVersion -o packages -nocache -pre .nuget\NuGet.exe install Sake -version 0.2 -o packages -ExcludeVersion + +IF "%SKIP_KRE_INSTALL%"=="1" goto run CALL packages\KoreBuild\build\kvm upgrade -svr50 -x86 CALL packages\KoreBuild\build\kvm install default -svrc50 -x86 From 80c48ca216b455f7050aedd531351736ac72a467 Mon Sep 17 00:00:00 2001 From: Pranav K Date: Tue, 5 Aug 2014 15:33:03 -0700 Subject: [PATCH 0046/1662] Changing case for NuGet.config extension to make it inline with casing for all other repos --- NuGet.config => NuGet.Config | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) rename NuGet.config => NuGet.Config (70%) diff --git a/NuGet.config b/NuGet.Config similarity index 70% rename from NuGet.config rename to NuGet.Config index 600a375c7e..1ce6b9e257 100644 --- a/NuGet.config +++ b/NuGet.Config @@ -1,7 +1,7 @@ - + - + - \ No newline at end of file + From 28389dc20d74d476ed5d824529fd8e5cd31ac5f6 Mon Sep 17 00:00:00 2001 From: Pranav K Date: Tue, 5 Aug 2014 15:44:21 -0700 Subject: [PATCH 0047/1662] Fixing vNext branch to point to aspnetvnext --- NuGet.Config | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NuGet.Config b/NuGet.Config index 1ce6b9e257..ee9e18c33d 100644 --- a/NuGet.Config +++ b/NuGet.Config @@ -1,7 +1,7 @@ - + From 624d49df36ec7aeaade3a31ac87968dc629b5a25 Mon Sep 17 00:00:00 2001 From: Pranav K Date: Tue, 5 Aug 2014 15:49:53 -0700 Subject: [PATCH 0048/1662] Updating release Nuget.config --- NuGet.Config | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NuGet.Config b/NuGet.Config index ee9e18c33d..1ce6b9e257 100644 --- a/NuGet.Config +++ b/NuGet.Config @@ -1,7 +1,7 @@ - + From 18ac38e4a75cefc78c326aa6cb9309238fe4f658 Mon Sep 17 00:00:00 2001 From: Pranav K Date: Wed, 6 Aug 2014 12:30:53 -0700 Subject: [PATCH 0049/1662] Updating dev Nuget.config --- NuGet.Config | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/NuGet.Config b/NuGet.Config index 1ce6b9e257..f41e9c631d 100644 --- a/NuGet.Config +++ b/NuGet.Config @@ -1,7 +1,7 @@ - + - + From 26084c7f13d836a89960c10fdec015008d08fa4e Mon Sep 17 00:00:00 2001 From: David Fowler Date: Fri, 15 Aug 2014 08:17:40 -0700 Subject: [PATCH 0050/1662] Removed source files from the project --- KestrelHttpServer.sln | 5 +-- samples/SampleApp/SampleApp.kproj | 8 ----- src/Kestrel/Kestrel.kproj | 10 ------ .../Microsoft.AspNet.Server.Kestrel.kproj | 35 ------------------- ...Microsoft.AspNet.Server.KestrelTests.kproj | 13 ------- 5 files changed, 1 insertion(+), 70 deletions(-) diff --git a/KestrelHttpServer.sln b/KestrelHttpServer.sln index 72427af0cb..0f6a44b724 100644 --- a/KestrelHttpServer.sln +++ b/KestrelHttpServer.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 14 -VisualStudioVersion = 14.0.21813.0 +VisualStudioVersion = 14.0.22013.1 MinimumVisualStudioVersion = 10.0.40219.1 Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.Server.Kestrel", "src\Microsoft.AspNet.Server.Kestrel\Microsoft.AspNet.Server.Kestrel.kproj", "{F510611A-3BEE-4B88-A613-5F4A74ED82A1}" EndProject @@ -20,9 +20,6 @@ EndProject Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Kestrel", "src\Kestrel\Kestrel.kproj", "{30B7617E-58EF-4382-B3EA-5B2E718CF1A6}" EndProject Global - GlobalSection(Performance) = preSolution - HasPerformanceSessions = true - EndGlobalSection GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU Release|Any CPU = Release|Any CPU diff --git a/samples/SampleApp/SampleApp.kproj b/samples/SampleApp/SampleApp.kproj index a49005a910..3145a2c37e 100644 --- a/samples/SampleApp/SampleApp.kproj +++ b/samples/SampleApp/SampleApp.kproj @@ -28,13 +28,5 @@ - - - - - - - - \ No newline at end of file diff --git a/src/Kestrel/Kestrel.kproj b/src/Kestrel/Kestrel.kproj index 219d40d100..8b95d5d6b0 100644 --- a/src/Kestrel/Kestrel.kproj +++ b/src/Kestrel/Kestrel.kproj @@ -24,15 +24,5 @@ 2.0 - - - - - - - - - - \ No newline at end of file diff --git a/src/Microsoft.AspNet.Server.Kestrel/Microsoft.AspNet.Server.Kestrel.kproj b/src/Microsoft.AspNet.Server.Kestrel/Microsoft.AspNet.Server.Kestrel.kproj index 73aa45b30b..03c042d14d 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Microsoft.AspNet.Server.Kestrel.kproj +++ b/src/Microsoft.AspNet.Server.Kestrel/Microsoft.AspNet.Server.Kestrel.kproj @@ -22,40 +22,5 @@ 2.0 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/test/Microsoft.AspNet.Server.KestrelTests/Microsoft.AspNet.Server.KestrelTests.kproj b/test/Microsoft.AspNet.Server.KestrelTests/Microsoft.AspNet.Server.KestrelTests.kproj index 78011f5326..8df4e15e4d 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/Microsoft.AspNet.Server.KestrelTests.kproj +++ b/test/Microsoft.AspNet.Server.KestrelTests/Microsoft.AspNet.Server.KestrelTests.kproj @@ -22,18 +22,5 @@ 2.0 - - - - - - - - - - - - - \ No newline at end of file From 226e6f329107954ea6de9485bd72503bcca81f7b Mon Sep 17 00:00:00 2001 From: Pranav K Date: Wed, 20 Aug 2014 06:56:34 -0700 Subject: [PATCH 0051/1662] Reacting to System.IO package version change --- src/Microsoft.AspNet.Server.Kestrel/project.json | 4 ++-- test/Microsoft.AspNet.Server.KestrelTests/project.json | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/project.json b/src/Microsoft.AspNet.Server.Kestrel/project.json index de43a8c018..cdf77c22f4 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/project.json +++ b/src/Microsoft.AspNet.Server.Kestrel/project.json @@ -1,4 +1,4 @@ -{ +{ "version": "1.0.0-*", "dependencies": { "Microsoft.Framework.Runtime.Interfaces": "1.0.0-*" @@ -24,7 +24,7 @@ "System.Threading.Tasks": "4.0.10.0", "System.Diagnostics.Tracing": "4.0.10.0", "System.Collections": "4.0.10.0", - "System.IO": "4.0.0.0", + "System.IO": "4.0.10.0", "System.Linq": "4.0.0.0", "System.Net.Primitives": "4.0.10.0", "System.Runtime.Extensions": "4.0.10.0", diff --git a/test/Microsoft.AspNet.Server.KestrelTests/project.json b/test/Microsoft.AspNet.Server.KestrelTests/project.json index 9afbb9a1e3..17f1a499c1 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/project.json +++ b/test/Microsoft.AspNet.Server.KestrelTests/project.json @@ -1,4 +1,4 @@ -{ +{ "version": "1.0.0-*", "dependencies": { "Xunit.KRunner": "1.0.0-*", @@ -13,7 +13,7 @@ "dependencies": { "System.Net.Sockets": "4.0.0.0", "System.Runtime.Handles": "4.0.0.0", - "System.IO": "4.0.0.0" + "System.IO": "4.0.10.0" } } }, From 77d6318cfc4456ab4e3b948b0fa98a125c0d03a9 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Thu, 28 Aug 2014 23:39:13 -0700 Subject: [PATCH 0052/1662] Updated to use the new target framework in project.json --- samples/SampleApp/project.json | 4 ++-- src/Kestrel/project.json | 4 ++-- .../Networking/PlatformApis.cs | 2 +- src/Microsoft.AspNet.Server.Kestrel/project.json | 2 +- test/Microsoft.AspNet.Server.KestrelTests/project.json | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/samples/SampleApp/project.json b/samples/SampleApp/project.json index 6cdf28bc48..f116683326 100644 --- a/samples/SampleApp/project.json +++ b/samples/SampleApp/project.json @@ -1,4 +1,4 @@ -{ +{ "version": "1.0.0-*", "dependencies": { "Kestrel": "1.0.0-*", @@ -7,7 +7,7 @@ }, "frameworks": { "net45": { }, - "k10": { + "aspnetcore50": { "dependencies": { "System.Console": "4.0.0.0" } diff --git a/src/Kestrel/project.json b/src/Kestrel/project.json index 1f8ca15042..ea2f0f22df 100644 --- a/src/Kestrel/project.json +++ b/src/Kestrel/project.json @@ -1,4 +1,4 @@ -{ +{ "version": "1.0.0-*", "dependencies": { "Microsoft.AspNet.Hosting": "1.0.0-*", @@ -8,7 +8,7 @@ "net45": { "dependencies": { } }, - "k10": { + "aspnetcore50": { "dependencies": { "System.Runtime": "4.0.20.0" } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/PlatformApis.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/PlatformApis.cs index 7803250f87..d7907e4d88 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/PlatformApis.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/PlatformApis.cs @@ -12,7 +12,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking { public static bool IsWindows() { -#if K10 +#if ASPNETCORE50 return true; #else var p = (int)Environment.OSVersion.Platform; diff --git a/src/Microsoft.AspNet.Server.Kestrel/project.json b/src/Microsoft.AspNet.Server.Kestrel/project.json index cdf77c22f4..44c423ad5b 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/project.json +++ b/src/Microsoft.AspNet.Server.Kestrel/project.json @@ -10,7 +10,7 @@ "allowUnsafe": true } }, - "k10": { + "aspnetcore50": { "compilationOptions": { "define": [ "TRACE", "K10" ], "allowUnsafe": true diff --git a/test/Microsoft.AspNet.Server.KestrelTests/project.json b/test/Microsoft.AspNet.Server.KestrelTests/project.json index 17f1a499c1..81324784a0 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/project.json +++ b/test/Microsoft.AspNet.Server.KestrelTests/project.json @@ -8,7 +8,7 @@ "net45": { "compilationOptions": { "define": [ "TRACE" ] } }, - "k10": { + "aspnetcore50": { "compilationOptions": { "define": [ "TRACE" ] }, "dependencies": { "System.Net.Sockets": "4.0.0.0", From 418f7452925d4d502efdd20334dcd2870a2368e0 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Thu, 4 Sep 2014 01:52:19 -0700 Subject: [PATCH 0053/1662] Updated to use the new target framework in project.json --- samples/SampleApp/project.json | 2 +- src/Kestrel/project.json | 2 +- .../Http/FrameDuplexStream.cs | 10 +++++----- .../Http/FrameRequestStream.cs | 4 ++-- .../Infrastructure/KestrelThread.cs | 4 ++-- src/Microsoft.AspNet.Server.Kestrel/project.json | 2 +- test/Microsoft.AspNet.Server.KestrelTests/project.json | 2 +- 7 files changed, 13 insertions(+), 13 deletions(-) diff --git a/samples/SampleApp/project.json b/samples/SampleApp/project.json index f116683326..53324e948f 100644 --- a/samples/SampleApp/project.json +++ b/samples/SampleApp/project.json @@ -6,7 +6,7 @@ "Microsoft.AspNet.WebSockets.Server": "1.0.0-*" }, "frameworks": { - "net45": { }, + "aspnet50": { }, "aspnetcore50": { "dependencies": { "System.Console": "4.0.0.0" diff --git a/src/Kestrel/project.json b/src/Kestrel/project.json index ea2f0f22df..02b470341b 100644 --- a/src/Kestrel/project.json +++ b/src/Kestrel/project.json @@ -5,7 +5,7 @@ "Microsoft.AspNet.Server.Kestrel": "1.0.0-*" }, "frameworks": { - "net45": { + "aspnet50": { "dependencies": { } }, "aspnetcore50": { diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameDuplexStream.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameDuplexStream.cs index 6d4276f8eb..27db2d30b0 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameDuplexStream.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameDuplexStream.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -19,7 +19,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http _responseStream = responseStream; } -#if NET45 +#if ASPNET50 public override void Close() { _requestStream.Close(); @@ -46,7 +46,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return _responseStream.FlushAsync(cancellationToken); } -#if NET45 +#if ASPNET50 public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback callback, object state) { return _requestStream.BeginRead(buffer, offset, count, callback, state); @@ -68,7 +68,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return _requestStream.CopyToAsync(destination, bufferSize, cancellationToken); } -#if NET45 +#if ASPNET50 public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback callback, object state) { return _responseStream.BeginWrite(buffer, offset, count, callback, state); @@ -191,4 +191,4 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } } -} \ No newline at end of file +} diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameRequestStream.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameRequestStream.cs index b7a219b8d9..aed7e30cf3 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameRequestStream.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameRequestStream.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -41,7 +41,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return ReadAsync(buffer, offset, count).Result; } -#if NET45 +#if ASPNET50 public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback callback, object state) { var task = ReadAsync(buffer, offset, count, CancellationToken.None, state); diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs index 5ef6f101a7..b7fd07c627 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using Microsoft.AspNet.Server.Kestrel.Networking; @@ -56,7 +56,7 @@ namespace Microsoft.AspNet.Server.Kestrel Post(OnStopImmediate, null); if (!_thread.Join((int)timeout.TotalMilliseconds)) { -#if NET45 +#if ASPNET50 _thread.Abort(); #endif } diff --git a/src/Microsoft.AspNet.Server.Kestrel/project.json b/src/Microsoft.AspNet.Server.Kestrel/project.json index 44c423ad5b..84771e2c53 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/project.json +++ b/src/Microsoft.AspNet.Server.Kestrel/project.json @@ -4,7 +4,7 @@ "Microsoft.Framework.Runtime.Interfaces": "1.0.0-*" }, "frameworks": { - "net45": { + "aspnet50": { "compilationOptions": { "define": [ "TRACE", "NET45" ], "allowUnsafe": true diff --git a/test/Microsoft.AspNet.Server.KestrelTests/project.json b/test/Microsoft.AspNet.Server.KestrelTests/project.json index 81324784a0..99c5d008c7 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/project.json +++ b/test/Microsoft.AspNet.Server.KestrelTests/project.json @@ -5,7 +5,7 @@ "Microsoft.AspNet.Server.Kestrel": "1.0.0-*" }, "frameworks": { - "net45": { + "aspnet50": { "compilationOptions": { "define": [ "TRACE" ] } }, "aspnetcore50": { From 5f44495cc81d64f7e84b0664cb77cd31cc99a27f Mon Sep 17 00:00:00 2001 From: David Fowler Date: Fri, 5 Sep 2014 01:49:15 -0700 Subject: [PATCH 0054/1662] Updated build.cmd --- build.cmd | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/build.cmd b/build.cmd index 60179e48c3..86ca5bbbf1 100644 --- a/build.cmd +++ b/build.cmd @@ -20,9 +20,9 @@ IF EXIST packages\KoreBuild goto run .nuget\NuGet.exe install Sake -version 0.2 -o packages -ExcludeVersion IF "%SKIP_KRE_INSTALL%"=="1" goto run -CALL packages\KoreBuild\build\kvm upgrade -svr50 -x86 -CALL packages\KoreBuild\build\kvm install default -svrc50 -x86 +CALL packages\KoreBuild\build\kvm upgrade -runtime CLR -x86 +CALL packages\KoreBuild\build\kvm install default -runtime CoreCLR -x86 :run -CALL packages\KoreBuild\build\kvm use default -svr50 -x86 -packages\Sake\tools\Sake.exe -I build -I packages\KoreBuild\build -f makefile.shade %* +CALL packages\KoreBuild\build\kvm use default -runtime CLR -x86 +packages\Sake\tools\Sake.exe -I packages\KoreBuild\build -f makefile.shade %* From 3b28e06d15ad4df961f2350bc958d0cf30ea450a Mon Sep 17 00:00:00 2001 From: David Fowler Date: Fri, 5 Sep 2014 11:43:30 -0700 Subject: [PATCH 0055/1662] Fixed kestrel build --- build.cmd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.cmd b/build.cmd index 86ca5bbbf1..62484c042c 100644 --- a/build.cmd +++ b/build.cmd @@ -25,4 +25,4 @@ CALL packages\KoreBuild\build\kvm install default -runtime CoreCLR -x86 :run CALL packages\KoreBuild\build\kvm use default -runtime CLR -x86 -packages\Sake\tools\Sake.exe -I packages\KoreBuild\build -f makefile.shade %* +packages\Sake\tools\Sake.exe -I build -I packages\KoreBuild\build -f makefile.shade %* From 1b1e02e9ddc44c7d7b799b4e40558d5ff14f7e6a Mon Sep 17 00:00:00 2001 From: Pranav K Date: Thu, 11 Sep 2014 10:06:52 -0700 Subject: [PATCH 0056/1662] Reacting to System.Text.Encoding package version change --- src/Microsoft.AspNet.Server.Kestrel/project.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/project.json b/src/Microsoft.AspNet.Server.Kestrel/project.json index 84771e2c53..b9318104e7 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/project.json +++ b/src/Microsoft.AspNet.Server.Kestrel/project.json @@ -20,7 +20,7 @@ "System.Diagnostics.Debug": "4.0.10.0", "System.Threading.Thread": "4.0.0.0", "System.Diagnostics.TraceSource": "4.0.0.0", - "System.Text.Encoding": "4.0.20.0", + "System.Text.Encoding": "4.0.10.0", "System.Threading.Tasks": "4.0.10.0", "System.Diagnostics.Tracing": "4.0.10.0", "System.Collections": "4.0.10.0", From 69237f5c19d7c4bcfb173fd9a9b5d2c7ec4442e1 Mon Sep 17 00:00:00 2001 From: Pranav K Date: Wed, 17 Sep 2014 10:01:04 -0700 Subject: [PATCH 0057/1662] Updating release NuGet.config --- NuGet.Config | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/NuGet.Config b/NuGet.Config index f41e9c631d..1ce6b9e257 100644 --- a/NuGet.Config +++ b/NuGet.Config @@ -1,7 +1,7 @@ - + - + From b5df3eb1d58e57775d4fd3271fc57a1e1d7673f6 Mon Sep 17 00:00:00 2001 From: Pranav K Date: Wed, 17 Sep 2014 10:01:06 -0700 Subject: [PATCH 0058/1662] Updating dev NuGet.config --- NuGet.Config | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/NuGet.Config b/NuGet.Config index 1ce6b9e257..f41e9c631d 100644 --- a/NuGet.Config +++ b/NuGet.Config @@ -1,7 +1,7 @@ - + - + From 72c32367a47820cf484485b9fc217df2511479e9 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Sun, 5 Oct 2014 11:26:15 -0700 Subject: [PATCH 0059/1662] Fixup references and the sample --- KestrelHttpServer.sln | 14 +++++++++++++- samples/SampleApp/Startup.cs | 2 +- src/Microsoft.AspNet.Server.Kestrel/project.json | 13 ++----------- .../project.json | 5 +---- 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/KestrelHttpServer.sln b/KestrelHttpServer.sln index 0f6a44b724..30b34d2c9d 100644 --- a/KestrelHttpServer.sln +++ b/KestrelHttpServer.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 14 -VisualStudioVersion = 14.0.22013.1 +VisualStudioVersion = 14.0.22111.0 MinimumVisualStudioVersion = 10.0.40219.1 Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.Server.Kestrel", "src\Microsoft.AspNet.Server.Kestrel\Microsoft.AspNet.Server.Kestrel.kproj", "{F510611A-3BEE-4B88-A613-5F4A74ED82A1}" EndProject @@ -19,6 +19,12 @@ Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "SampleApp", "samples\Sample EndProject Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Kestrel", "src\Kestrel\Kestrel.kproj", "{30B7617E-58EF-4382-B3EA-5B2E718CF1A6}" EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{2D5D5227-4DBD-499A-96B1-76A36B03B750}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{D3273454-EA07-41D2-BF0B-FCC3675C2483}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "samples", "samples", "{8A3D00B8-1CCF-4BE6-A060-11104CE2D9CE}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -45,4 +51,10 @@ Global GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection + GlobalSection(NestedProjects) = preSolution + {F510611A-3BEE-4B88-A613-5F4A74ED82A1} = {2D5D5227-4DBD-499A-96B1-76A36B03B750} + {37F3BFB2-6454-49E5-9D7F-581BF755CCFE} = {D3273454-EA07-41D2-BF0B-FCC3675C2483} + {2C3CB3DC-EEBF-4F52-9E1C-4F2F972E76C3} = {8A3D00B8-1CCF-4BE6-A060-11104CE2D9CE} + {30B7617E-58EF-4382-B3EA-5B2E718CF1A6} = {2D5D5227-4DBD-499A-96B1-76A36B03B750} + EndGlobalSection EndGlobal diff --git a/samples/SampleApp/Startup.cs b/samples/SampleApp/Startup.cs index f6a9e33a64..8a5b27fe3e 100644 --- a/samples/SampleApp/Startup.cs +++ b/samples/SampleApp/Startup.cs @@ -9,7 +9,7 @@ namespace SampleApp { public class Startup { - public void Configure(IBuilder app) + public void Configure(IApplicationBuilder app) { app.UseWebSockets(); diff --git a/src/Microsoft.AspNet.Server.Kestrel/project.json b/src/Microsoft.AspNet.Server.Kestrel/project.json index b9318104e7..a76c33de04 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/project.json +++ b/src/Microsoft.AspNet.Server.Kestrel/project.json @@ -1,20 +1,11 @@ { "version": "1.0.0-*", "dependencies": { - "Microsoft.Framework.Runtime.Interfaces": "1.0.0-*" + "Microsoft.Framework.Runtime.Interfaces": { "version": "1.0.0-*","type": "build" } }, "frameworks": { - "aspnet50": { - "compilationOptions": { - "define": [ "TRACE", "NET45" ], - "allowUnsafe": true - } - }, + "aspnet50": { }, "aspnetcore50": { - "compilationOptions": { - "define": [ "TRACE", "K10" ], - "allowUnsafe": true - }, "dependencies": { "System.Threading.ThreadPool": "4.0.10.0", "System.Diagnostics.Debug": "4.0.10.0", diff --git a/test/Microsoft.AspNet.Server.KestrelTests/project.json b/test/Microsoft.AspNet.Server.KestrelTests/project.json index 99c5d008c7..8a4f25365e 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/project.json +++ b/test/Microsoft.AspNet.Server.KestrelTests/project.json @@ -5,11 +5,8 @@ "Microsoft.AspNet.Server.Kestrel": "1.0.0-*" }, "frameworks": { - "aspnet50": { - "compilationOptions": { "define": [ "TRACE" ] } - }, + "aspnet50": { }, "aspnetcore50": { - "compilationOptions": { "define": [ "TRACE" ] }, "dependencies": { "System.Net.Sockets": "4.0.0.0", "System.Runtime.Handles": "4.0.0.0", From 0124d06ced9c013a16142b44b01d1fc165069b15 Mon Sep 17 00:00:00 2001 From: Eilon Lipton Date: Mon, 6 Oct 2014 10:13:52 -0700 Subject: [PATCH 0060/1662] Create LICENSE.txt --- LICENSE.txt | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 LICENSE.txt diff --git a/LICENSE.txt b/LICENSE.txt new file mode 100644 index 0000000000..c0e6e7629e --- /dev/null +++ b/LICENSE.txt @@ -0,0 +1,13 @@ +Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); you may not use +these files except in compliance with the License. You may obtain a copy of the +License at + +http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software distributed +under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR +CONDITIONS OF ANY KIND, either express or implied. See the License for the +specific language governing permissions and limitations under the License. + From ba0e3321bf608078d815fda251a5e7f855591cdf Mon Sep 17 00:00:00 2001 From: Pranav K Date: Fri, 10 Oct 2014 10:33:06 -0700 Subject: [PATCH 0061/1662] Reacting to CLR package versioning changes --- samples/SampleApp/project.json | 2 +- src/Kestrel/project.json | 2 +- .../project.json | 30 +++++++++---------- .../project.json | 6 ++-- 4 files changed, 20 insertions(+), 20 deletions(-) diff --git a/samples/SampleApp/project.json b/samples/SampleApp/project.json index 53324e948f..25d10106db 100644 --- a/samples/SampleApp/project.json +++ b/samples/SampleApp/project.json @@ -9,7 +9,7 @@ "aspnet50": { }, "aspnetcore50": { "dependencies": { - "System.Console": "4.0.0.0" + "System.Console": "4.0.0-beta-*" } } }, diff --git a/src/Kestrel/project.json b/src/Kestrel/project.json index 02b470341b..afc776aba1 100644 --- a/src/Kestrel/project.json +++ b/src/Kestrel/project.json @@ -10,7 +10,7 @@ }, "aspnetcore50": { "dependencies": { - "System.Runtime": "4.0.20.0" + "System.Runtime": "4.0.20-beta-*" } } } diff --git a/src/Microsoft.AspNet.Server.Kestrel/project.json b/src/Microsoft.AspNet.Server.Kestrel/project.json index a76c33de04..96359378c7 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/project.json +++ b/src/Microsoft.AspNet.Server.Kestrel/project.json @@ -7,21 +7,21 @@ "aspnet50": { }, "aspnetcore50": { "dependencies": { - "System.Threading.ThreadPool": "4.0.10.0", - "System.Diagnostics.Debug": "4.0.10.0", - "System.Threading.Thread": "4.0.0.0", - "System.Diagnostics.TraceSource": "4.0.0.0", - "System.Text.Encoding": "4.0.10.0", - "System.Threading.Tasks": "4.0.10.0", - "System.Diagnostics.Tracing": "4.0.10.0", - "System.Collections": "4.0.10.0", - "System.IO": "4.0.10.0", - "System.Linq": "4.0.0.0", - "System.Net.Primitives": "4.0.10.0", - "System.Runtime.Extensions": "4.0.10.0", - "System.Threading": "4.0.0.0", - "System.Globalization": "4.0.10.0", - "System.Runtime.InteropServices": "4.0.20.0" + "System.Threading.ThreadPool": "4.0.10-beta-*", + "System.Diagnostics.Debug": "4.0.10-beta-*", + "System.Threading.Thread": "4.0.0-beta-*", + "System.Diagnostics.TraceSource": "4.0.0-beta-*", + "System.Text.Encoding": "4.0.10-beta-*", + "System.Threading.Tasks": "4.0.10-beta-*", + "System.Diagnostics.Tracing": "4.0.10-beta-*", + "System.Collections": "4.0.10-beta-*", + "System.IO": "4.0.10-beta-*", + "System.Linq": "4.0.0-beta-*", + "System.Net.Primitives": "4.0.10-beta-*", + "System.Runtime.Extensions": "4.0.10-beta-*", + "System.Threading": "4.0.0-beta-*", + "System.Globalization": "4.0.10-beta-*", + "System.Runtime.InteropServices": "4.0.20-beta-*" } } }, diff --git a/test/Microsoft.AspNet.Server.KestrelTests/project.json b/test/Microsoft.AspNet.Server.KestrelTests/project.json index 8a4f25365e..52c53f7470 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/project.json +++ b/test/Microsoft.AspNet.Server.KestrelTests/project.json @@ -8,9 +8,9 @@ "aspnet50": { }, "aspnetcore50": { "dependencies": { - "System.Net.Sockets": "4.0.0.0", - "System.Runtime.Handles": "4.0.0.0", - "System.IO": "4.0.10.0" + "System.Net.Sockets": "4.0.0-beta-*", + "System.Runtime.Handles": "4.0.0-beta-*", + "System.IO": "4.0.10-beta-*" } } }, From dcf55abc9f6a2e5c923320315743419bc039670c Mon Sep 17 00:00:00 2001 From: Louis DeJardin Date: Mon, 13 Oct 2014 22:48:47 -0700 Subject: [PATCH 0062/1662] Changing shared library name on Unix OS type --- src/Microsoft.AspNet.Server.Kestrel/KestrelEngine.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Microsoft.AspNet.Server.Kestrel/KestrelEngine.cs b/src/Microsoft.AspNet.Server.Kestrel/KestrelEngine.cs index 3e2b01985b..8d58604ccd 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/KestrelEngine.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/KestrelEngine.cs @@ -44,6 +44,10 @@ namespace Microsoft.AspNet.Server.Kestrel architecture, "libuv.dll"); } + else if ((int)Environment.OSVersion.Platform == 4) + { + libraryPath = "libuv.so.1"; + } else { libraryPath = Path.Combine( From e550d1f1ec2515e9bdc4c1c366aabdd891fa9d72 Mon Sep 17 00:00:00 2001 From: Louis DeJardin Date: Mon, 20 Oct 2014 16:11:48 -0700 Subject: [PATCH 0063/1662] Updating Darwin OS detection --- .../KestrelEngine.cs | 14 +++---- .../Networking/Libuv.cs | 6 +++ .../Networking/PlatformApis.cs | 38 ++++++++++++++++--- 3 files changed, 46 insertions(+), 12 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/KestrelEngine.cs b/src/Microsoft.AspNet.Server.Kestrel/KestrelEngine.cs index 8d58604ccd..31861d023a 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/KestrelEngine.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/KestrelEngine.cs @@ -44,19 +44,19 @@ namespace Microsoft.AspNet.Server.Kestrel architecture, "libuv.dll"); } - else if ((int)Environment.OSVersion.Platform == 4) - { - libraryPath = "libuv.so.1"; - } - else + else if (Libuv.IsDarwin) { libraryPath = Path.Combine( libraryPath, - "native", + "native", "darwin", - "universal", + "universal", "libuv.dylib"); } + else + { + libraryPath = "libuv.so.1"; + } } Libuv.Load(libraryPath); } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/Libuv.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/Libuv.cs index c777af7998..741c3b48f8 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/Libuv.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/Libuv.cs @@ -13,9 +13,15 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking public Libuv() { IsWindows = PlatformApis.IsWindows(); + if (!IsWindows) + { + IsDarwin = PlatformApis.IsDarwin(); + } } public bool IsWindows; + public bool IsDarwin; + public Func LoadLibrary; public Func FreeLibrary; public Func GetProcAddress; diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/PlatformApis.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/PlatformApis.cs index d7907e4d88..ff7c4fa12c 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/PlatformApis.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/PlatformApis.cs @@ -10,7 +10,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking { public static class PlatformApis { - public static bool IsWindows() + public static bool IsWindows() { #if ASPNETCORE50 return true; @@ -20,6 +20,34 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking #endif } + [DllImport("libc")] + static extern int uname(IntPtr buf); + + static unsafe string GetUname() + { + var buffer = new byte[8192]; + try + { + fixed (byte* buf = buffer) + { + if (uname((IntPtr)buf) == 0) + { + return Marshal.PtrToStringAnsi((IntPtr)buf); + } + } + return string.Empty; + } + catch + { + return string.Empty; + } + } + + public static bool IsDarwin() + { + return string.Equals(GetUname(), "Darwin", StringComparison.Ordinal); + } + public static void Apply(Libuv libuv) { if (libuv.IsWindows) @@ -55,7 +83,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking { [DllImport("libdl")] public static extern IntPtr dlopen(String fileName, int flags); - + [DllImport("libdl")] public static extern IntPtr dlsym(IntPtr handle, String symbol); @@ -65,17 +93,17 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking [DllImport("libdl")] public static extern IntPtr dlerror(); - public static IntPtr LoadLibrary(string dllToLoad) + public static IntPtr LoadLibrary(string dllToLoad) { return dlopen(dllToLoad, 2); } - public static bool FreeLibrary(IntPtr hModule) + public static bool FreeLibrary(IntPtr hModule) { return dlclose(hModule) == 0; } - public static IntPtr GetProcAddress(IntPtr hModule, string procedureName) + public static IntPtr GetProcAddress(IntPtr hModule, string procedureName) { dlerror(); var res = dlsym(hModule, procedureName); From c8d17ed7fd1cc18f45de6f0508bc802c1c548c72 Mon Sep 17 00:00:00 2001 From: Pranav K Date: Tue, 21 Oct 2014 12:45:40 -0700 Subject: [PATCH 0064/1662] Updating build.sh to work on Mono --- build.sh | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/build.sh b/build.sh index db1e0c3dde..c7873ef58e 100644 --- a/build.sh +++ b/build.sh @@ -1,12 +1,12 @@ -#!/bin/sh +#!/bin/bash if test `uname` = Darwin; then cachedir=~/Library/Caches/KBuild else - if x$XDG_DATA_HOME = x; then - cachedir=$HOME/.local/share + if [ -z $XDG_DATA_HOME ]; then + cachedir=$HOME/.local/share else - cachedir=$XDG_DATA_HOME; + cachedir=$XDG_DATA_HOME; fi fi mkdir -p $cachedir @@ -14,12 +14,12 @@ mkdir -p $cachedir url=https://www.nuget.org/nuget.exe if test ! -f $cachedir/nuget.exe; then - wget -o $cachedir/nuget.exe $url 2>/dev/null || curl -o $cachedir/nuget.exe --location $url /dev/null + wget -O $cachedir/nuget.exe $url 2>/dev/null || curl -o $cachedir/nuget.exe --location $url /dev/null fi if test ! -e .nuget; then mkdir .nuget - cp $cachedir/nuget.exe .nuget + cp $cachedir/nuget.exe .nuget/nuget.exe fi if test ! -d packages/KoreBuild; then @@ -27,4 +27,12 @@ if test ! -d packages/KoreBuild; then mono .nuget/nuget.exe install Sake -version 0.2 -o packages -ExcludeVersion fi -mono packages/Sake/tools/Sake.exe -I packages/KoreBuild/build -f makefile.shade "$@" \ No newline at end of file +if ! type k > /dev/null 2>&1; then + source packages/KoreBuild/build/kvm.sh +fi + +if ! type k > /dev/null 2>&1; then + kvm upgrade +fi + +mono packages/Sake/tools/Sake.exe -I packages/KoreBuild/build -f makefile.shade "$@" From 1e9c6007a935c8f82c129b69bfe3ed8dfc0af930 Mon Sep 17 00:00:00 2001 From: Chris Ross Date: Mon, 27 Oct 2014 10:36:42 -0700 Subject: [PATCH 0065/1662] Remove WebListener and WebSockets from sample due to dependencies. --- samples/SampleApp/Microsoft.AspNet.Hosting.ini | 2 +- samples/SampleApp/Startup.cs | 2 -- samples/SampleApp/project.json | 4 +--- 3 files changed, 2 insertions(+), 6 deletions(-) diff --git a/samples/SampleApp/Microsoft.AspNet.Hosting.ini b/samples/SampleApp/Microsoft.AspNet.Hosting.ini index 3992612903..3acac330ec 100644 --- a/samples/SampleApp/Microsoft.AspNet.Hosting.ini +++ b/samples/SampleApp/Microsoft.AspNet.Hosting.ini @@ -1,3 +1,3 @@  -Server = Microsoft.AspNet.Server.WebListener +Server = Kestrel Server.Urls = http://localhost:5000/ diff --git a/samples/SampleApp/Startup.cs b/samples/SampleApp/Startup.cs index 8a5b27fe3e..880cc4a984 100644 --- a/samples/SampleApp/Startup.cs +++ b/samples/SampleApp/Startup.cs @@ -11,8 +11,6 @@ namespace SampleApp { public void Configure(IApplicationBuilder app) { - app.UseWebSockets(); - app.Run(async context => { Console.WriteLine("{0} {1}{2}{3}", diff --git a/samples/SampleApp/project.json b/samples/SampleApp/project.json index 25d10106db..4d30db9489 100644 --- a/samples/SampleApp/project.json +++ b/samples/SampleApp/project.json @@ -1,9 +1,7 @@ { "version": "1.0.0-*", "dependencies": { - "Kestrel": "1.0.0-*", - "Microsoft.AspNet.Server.WebListener": "1.0.0-*", - "Microsoft.AspNet.WebSockets.Server": "1.0.0-*" + "Kestrel": "1.0.0-*" }, "frameworks": { "aspnet50": { }, From 0174d213d145caa00ebb7e42751d66e711b4c520 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Fri, 31 Oct 2014 01:48:15 -0700 Subject: [PATCH 0066/1662] Added package descriptions --- src/Kestrel/project.json | 1 + src/Microsoft.AspNet.Server.Kestrel/project.json | 1 + 2 files changed, 2 insertions(+) diff --git a/src/Kestrel/project.json b/src/Kestrel/project.json index afc776aba1..726fa65fd7 100644 --- a/src/Kestrel/project.json +++ b/src/Kestrel/project.json @@ -1,5 +1,6 @@ { "version": "1.0.0-*", + "description": "ASP.NET 5 cross platform development web server.", "dependencies": { "Microsoft.AspNet.Hosting": "1.0.0-*", "Microsoft.AspNet.Server.Kestrel": "1.0.0-*" diff --git a/src/Microsoft.AspNet.Server.Kestrel/project.json b/src/Microsoft.AspNet.Server.Kestrel/project.json index 96359378c7..7bab92a7be 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/project.json +++ b/src/Microsoft.AspNet.Server.Kestrel/project.json @@ -1,5 +1,6 @@ { "version": "1.0.0-*", + "description": "ASP.NET 5 cross platform development web server.", "dependencies": { "Microsoft.Framework.Runtime.Interfaces": { "version": "1.0.0-*","type": "build" } }, From d1a784e98d53497d71d1790e4e8782e35be7b483 Mon Sep 17 00:00:00 2001 From: Pranav K Date: Thu, 6 Nov 2014 10:51:20 -0800 Subject: [PATCH 0067/1662] Updating to release NuGet.config --- NuGet.Config | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NuGet.Config b/NuGet.Config index f41e9c631d..2d3b0cb857 100644 --- a/NuGet.Config +++ b/NuGet.Config @@ -1,7 +1,7 @@  - + From 045a6eb4bac5da41ed1a0953e137e1ae7826b5ea Mon Sep 17 00:00:00 2001 From: Chris Ross Date: Thu, 30 Oct 2014 14:16:04 -0700 Subject: [PATCH 0068/1662] Add new HeadersSent API. --- src/Kestrel/ServerRequest.cs | 5 +++++ src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs | 7 +++++++ 2 files changed, 12 insertions(+) diff --git a/src/Kestrel/ServerRequest.cs b/src/Kestrel/ServerRequest.cs index b167f50278..27398ca987 100644 --- a/src/Kestrel/ServerRequest.cs +++ b/src/Kestrel/ServerRequest.cs @@ -175,6 +175,11 @@ namespace Kestrel } } + bool IHttpResponseFeature.HeadersSent + { + get { return _frame.HeadersSent; } + } + void IHttpResponseFeature.OnSendingHeaders(Action callback, object state) { _frame.OnSendingHeaders(callback, state); diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs index 1f8552459b..c20ae236b1 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs @@ -54,6 +54,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http Mode _mode; private bool _resultStarted; + private bool _headersSent; private bool _keepAlive; /* @@ -89,6 +90,10 @@ namespace Microsoft.AspNet.Server.Kestrel.Http public Stream DuplexStream { get; set; } + public bool HeadersSent + { + get { return _headersSent; } + } /* @@ -276,6 +281,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http FireOnSendingHeaders(); + _headersSent = true; + var status = ReasonPhrases.ToStatus(StatusCode, ReasonPhrase); var responseHeader = CreateResponseHeader(status, ResponseHeaders); From 1b8f25f7d41b83e29c4851e6f3e582c5c301bc5a Mon Sep 17 00:00:00 2001 From: Victor Hurdugaci Date: Wed, 12 Nov 2014 15:15:40 -0800 Subject: [PATCH 0069/1662] Update KProj to the latest format --- samples/SampleApp/SampleApp.kproj | 30 ++++--------------- src/Kestrel/Kestrel.kproj | 26 ++++------------ .../Microsoft.AspNet.Server.Kestrel.kproj | 24 ++++----------- ...Microsoft.AspNet.Server.KestrelTests.kproj | 24 ++++----------- 4 files changed, 24 insertions(+), 80 deletions(-) diff --git a/samples/SampleApp/SampleApp.kproj b/samples/SampleApp/SampleApp.kproj index 3145a2c37e..398df659b1 100644 --- a/samples/SampleApp/SampleApp.kproj +++ b/samples/SampleApp/SampleApp.kproj @@ -1,32 +1,14 @@ - - + + - 12.0 + 14.0 $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) - - Debug - AnyCPU - 2c3cb3dc-eebf-4f52-9e1c-4f2f972e76c3 - Console - - - ConsoleDebugger - - - WebDebugger - - - - - 2.0 - - - - + ..\..\artifacts\obj\$(MSBuildProjectName) + ..\..\artifacts\bin\$(MSBuildProjectName)\ - \ No newline at end of file + diff --git a/src/Kestrel/Kestrel.kproj b/src/Kestrel/Kestrel.kproj index 8b95d5d6b0..a2a1d5443b 100644 --- a/src/Kestrel/Kestrel.kproj +++ b/src/Kestrel/Kestrel.kproj @@ -1,28 +1,14 @@ - - + + - 12.0 + 14.0 $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) - - Debug - AnyCPU - 30b7617e-58ef-4382-b3ea-5b2e718cf1a6 - Library - - - ConsoleDebugger - - - WebDebugger - - - - - 2.0 + ..\..\artifacts\obj\$(MSBuildProjectName) + ..\..\artifacts\bin\$(MSBuildProjectName)\ - \ No newline at end of file + diff --git a/src/Microsoft.AspNet.Server.Kestrel/Microsoft.AspNet.Server.Kestrel.kproj b/src/Microsoft.AspNet.Server.Kestrel/Microsoft.AspNet.Server.Kestrel.kproj index 03c042d14d..e6428bd7c3 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Microsoft.AspNet.Server.Kestrel.kproj +++ b/src/Microsoft.AspNet.Server.Kestrel/Microsoft.AspNet.Server.Kestrel.kproj @@ -1,26 +1,14 @@ - - + + - 12.0 + 14.0 $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) f510611a-3bee-4b88-a613-5f4a74ed82a1 - Library - - - ConsoleDebugger - - - WebDebugger - - - - - - - 2.0 + ..\..\artifacts\obj\$(MSBuildProjectName) + ..\..\artifacts\bin\$(MSBuildProjectName)\ - \ No newline at end of file + diff --git a/test/Microsoft.AspNet.Server.KestrelTests/Microsoft.AspNet.Server.KestrelTests.kproj b/test/Microsoft.AspNet.Server.KestrelTests/Microsoft.AspNet.Server.KestrelTests.kproj index 8df4e15e4d..48c60ccf04 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/Microsoft.AspNet.Server.KestrelTests.kproj +++ b/test/Microsoft.AspNet.Server.KestrelTests/Microsoft.AspNet.Server.KestrelTests.kproj @@ -1,26 +1,14 @@ - - + + - 12.0 + 14.0 $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) 37f3bfb2-6454-49e5-9d7f-581bf755ccfe - Console - - - ConsoleDebugger - - - WebDebugger - - - - - - - 2.0 + ..\..\artifacts\obj\$(MSBuildProjectName) + ..\..\artifacts\bin\$(MSBuildProjectName)\ - \ No newline at end of file + From 4a2dd8f279dd7985f1a0a90fa05bea4bb3db96bd Mon Sep 17 00:00:00 2001 From: Victor Hurdugaci Date: Tue, 25 Nov 2014 10:54:18 -0800 Subject: [PATCH 0070/1662] Add schema version to kproj files --- samples/SampleApp/SampleApp.kproj | 3 +++ src/Kestrel/Kestrel.kproj | 3 +++ .../Microsoft.AspNet.Server.Kestrel.kproj | 3 +++ .../Microsoft.AspNet.Server.KestrelTests.kproj | 3 +++ 4 files changed, 12 insertions(+) diff --git a/samples/SampleApp/SampleApp.kproj b/samples/SampleApp/SampleApp.kproj index 398df659b1..266183c44f 100644 --- a/samples/SampleApp/SampleApp.kproj +++ b/samples/SampleApp/SampleApp.kproj @@ -10,5 +10,8 @@ ..\..\artifacts\obj\$(MSBuildProjectName) ..\..\artifacts\bin\$(MSBuildProjectName)\ + + 2.0 + diff --git a/src/Kestrel/Kestrel.kproj b/src/Kestrel/Kestrel.kproj index a2a1d5443b..07fa602304 100644 --- a/src/Kestrel/Kestrel.kproj +++ b/src/Kestrel/Kestrel.kproj @@ -10,5 +10,8 @@ ..\..\artifacts\obj\$(MSBuildProjectName) ..\..\artifacts\bin\$(MSBuildProjectName)\ + + 2.0 + diff --git a/src/Microsoft.AspNet.Server.Kestrel/Microsoft.AspNet.Server.Kestrel.kproj b/src/Microsoft.AspNet.Server.Kestrel/Microsoft.AspNet.Server.Kestrel.kproj index e6428bd7c3..e6aef0564f 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Microsoft.AspNet.Server.Kestrel.kproj +++ b/src/Microsoft.AspNet.Server.Kestrel/Microsoft.AspNet.Server.Kestrel.kproj @@ -10,5 +10,8 @@ ..\..\artifacts\obj\$(MSBuildProjectName) ..\..\artifacts\bin\$(MSBuildProjectName)\ + + 2.0 + diff --git a/test/Microsoft.AspNet.Server.KestrelTests/Microsoft.AspNet.Server.KestrelTests.kproj b/test/Microsoft.AspNet.Server.KestrelTests/Microsoft.AspNet.Server.KestrelTests.kproj index 48c60ccf04..e3d71ba62b 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/Microsoft.AspNet.Server.KestrelTests.kproj +++ b/test/Microsoft.AspNet.Server.KestrelTests/Microsoft.AspNet.Server.KestrelTests.kproj @@ -10,5 +10,8 @@ ..\..\artifacts\obj\$(MSBuildProjectName) ..\..\artifacts\bin\$(MSBuildProjectName)\ + + 2.0 + From f1b36e038b60d8a584302fb0b5f44ee3243e0722 Mon Sep 17 00:00:00 2001 From: Giovanni Bassi Date: Sun, 30 Nov 2014 13:55:24 -0200 Subject: [PATCH 0071/1662] update readme.md to new github repo for libuv --- README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/README.md b/README.md index 4921a45505..ad45dd6a1e 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,6 @@ KestrelHttpServer ================= -This repo contains a development web server for ASP.NET vNext based on [libuv](https://github.com/joyent/libuv). +This repo contains a development web server for ASP.NET vNext based on [libuv](https://github.com/libuv/libuv). This project is part of ASP.NET vNext. You can find samples, documentation and getting started instructions for ASP.NET vNext at the [Home](https://github.com/aspnet/home) repo. - From ae6c971bfbcb2ba44f01639f4e4aa770eaacb94f Mon Sep 17 00:00:00 2001 From: Suhas Joshi Date: Mon, 8 Dec 2014 15:16:10 -0800 Subject: [PATCH 0072/1662] Updating to release NuGet.config --- NuGet.Config | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NuGet.Config b/NuGet.Config index f41e9c631d..2d3b0cb857 100644 --- a/NuGet.Config +++ b/NuGet.Config @@ -1,7 +1,7 @@  - + From 425e9305a51a3d15f952b3e2ba21c917ec4bce63 Mon Sep 17 00:00:00 2001 From: Suhas Joshi Date: Mon, 8 Dec 2014 15:25:08 -0800 Subject: [PATCH 0073/1662] Updating to dev NuGet.config --- NuGet.Config | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NuGet.Config b/NuGet.Config index 2d3b0cb857..f41e9c631d 100644 --- a/NuGet.Config +++ b/NuGet.Config @@ -1,7 +1,7 @@  - + From 10a32fda26132bcd24e26a43c49e5facf02654f1 Mon Sep 17 00:00:00 2001 From: Pranav K Date: Mon, 15 Dec 2014 14:44:30 -0800 Subject: [PATCH 0074/1662] Reacting to System.Threading version changes * Sorting project.json references alphabetically --- .../project.json | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/project.json b/src/Microsoft.AspNet.Server.Kestrel/project.json index 7bab92a7be..df54825460 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/project.json +++ b/src/Microsoft.AspNet.Server.Kestrel/project.json @@ -8,21 +8,21 @@ "aspnet50": { }, "aspnetcore50": { "dependencies": { - "System.Threading.ThreadPool": "4.0.10-beta-*", - "System.Diagnostics.Debug": "4.0.10-beta-*", - "System.Threading.Thread": "4.0.0-beta-*", - "System.Diagnostics.TraceSource": "4.0.0-beta-*", - "System.Text.Encoding": "4.0.10-beta-*", - "System.Threading.Tasks": "4.0.10-beta-*", - "System.Diagnostics.Tracing": "4.0.10-beta-*", "System.Collections": "4.0.10-beta-*", + "System.Diagnostics.Debug": "4.0.10-beta-*", + "System.Diagnostics.TraceSource": "4.0.0-beta-*", + "System.Diagnostics.Tracing": "4.0.10-beta-*", + "System.Globalization": "4.0.10-beta-*", "System.IO": "4.0.10-beta-*", "System.Linq": "4.0.0-beta-*", "System.Net.Primitives": "4.0.10-beta-*", "System.Runtime.Extensions": "4.0.10-beta-*", - "System.Threading": "4.0.0-beta-*", - "System.Globalization": "4.0.10-beta-*", - "System.Runtime.InteropServices": "4.0.20-beta-*" + "System.Runtime.InteropServices": "4.0.20-beta-*", + "System.Text.Encoding": "4.0.10-beta-*", + "System.Threading": "4.0.10-beta-*", + "System.Threading.Tasks": "4.0.10-beta-*", + "System.Threading.Thread": "4.0.0-beta-*", + "System.Threading.ThreadPool": "4.0.10-beta-*" } } }, From 2e943eb3aba5e4103251b2a1ef93801996e22b4a Mon Sep 17 00:00:00 2001 From: Pranav K Date: Mon, 15 Dec 2014 16:20:40 -0800 Subject: [PATCH 0075/1662] Reacting to System.Diagnostics.Tracing version change --- src/Microsoft.AspNet.Server.Kestrel/project.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/project.json b/src/Microsoft.AspNet.Server.Kestrel/project.json index df54825460..ce0501a412 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/project.json +++ b/src/Microsoft.AspNet.Server.Kestrel/project.json @@ -11,7 +11,7 @@ "System.Collections": "4.0.10-beta-*", "System.Diagnostics.Debug": "4.0.10-beta-*", "System.Diagnostics.TraceSource": "4.0.0-beta-*", - "System.Diagnostics.Tracing": "4.0.10-beta-*", + "System.Diagnostics.Tracing": "4.0.20-beta-*", "System.Globalization": "4.0.10-beta-*", "System.IO": "4.0.10-beta-*", "System.Linq": "4.0.0-beta-*", From d08e5d357293549edce0d2a86f22a09454b82894 Mon Sep 17 00:00:00 2001 From: Brennan Date: Mon, 15 Dec 2014 14:52:11 -0800 Subject: [PATCH 0076/1662] Updating tests to use official xunit --- test/Microsoft.AspNet.Server.KestrelTests/project.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/Microsoft.AspNet.Server.KestrelTests/project.json b/test/Microsoft.AspNet.Server.KestrelTests/project.json index 52c53f7470..e7ccd24e25 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/project.json +++ b/test/Microsoft.AspNet.Server.KestrelTests/project.json @@ -1,7 +1,7 @@ { "version": "1.0.0-*", "dependencies": { - "Xunit.KRunner": "1.0.0-*", + "xunit.runner.kre": "1.0.0-*", "Microsoft.AspNet.Server.Kestrel": "1.0.0-*" }, "frameworks": { @@ -15,7 +15,7 @@ } }, "commands": { - "run": "Xunit.KRunner", - "test": "Xunit.KRunner" + "run": "xunit.runner.kre", + "test": "xunit.runner.kre" } } From e421b3f01c2a1875c36204abda3f8f029a1b0fa0 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Fri, 26 Dec 2014 14:37:37 -0800 Subject: [PATCH 0077/1662] Throw better error when libuv can't be loaded - Throw more specific exception for *nix machines --- .../Networking/Libuv.cs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/Libuv.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/Libuv.cs index 741c3b48f8..977fb18260 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/Libuv.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/Libuv.cs @@ -31,6 +31,20 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking PlatformApis.Apply(this); var module = LoadLibrary(dllToLoad); + + if (module == IntPtr.Zero) + { + var message = "Unable to load libuv."; + if (!IsWindows && !IsDarwin) + { + // *nix box, so libuv needs to be installed + // TODO: fwlink? + message += " Make sure libuv is installed and available as libuv.so.1"; + } + + throw new InvalidOperationException(message); + } + foreach (var field in GetType().GetTypeInfo().DeclaredFields) { var procAddress = GetProcAddress(module, field.Name.TrimStart('_')); From cc720bd3fee6e8b45fbfff809cc40be0593837b8 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Sun, 18 Jan 2015 21:04:13 -0800 Subject: [PATCH 0078/1662] Handle HttpFeature rename --- src/Kestrel/ServerRequest.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Kestrel/ServerRequest.cs b/src/Kestrel/ServerRequest.cs index 27398ca987..3b60965b6f 100644 --- a/src/Kestrel/ServerRequest.cs +++ b/src/Kestrel/ServerRequest.cs @@ -1,4 +1,4 @@ -using Microsoft.AspNet.HttpFeature; +using Microsoft.AspNet.Http.Interfaces; using Microsoft.AspNet.Server.Kestrel.Http; using System; using System.Collections.Generic; From 42dd52a2b22f5692e352f0d9f7706bdfe95b934e Mon Sep 17 00:00:00 2001 From: Pranav K Date: Tue, 20 Jan 2015 01:31:59 -0800 Subject: [PATCH 0079/1662] Updating build.cmd and build.sh to use dotnetsdk --- build.cmd | 8 ++++---- build.sh | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/build.cmd b/build.cmd index 62484c042c..c8041fdd9d 100644 --- a/build.cmd +++ b/build.cmd @@ -20,9 +20,9 @@ IF EXIST packages\KoreBuild goto run .nuget\NuGet.exe install Sake -version 0.2 -o packages -ExcludeVersion IF "%SKIP_KRE_INSTALL%"=="1" goto run -CALL packages\KoreBuild\build\kvm upgrade -runtime CLR -x86 -CALL packages\KoreBuild\build\kvm install default -runtime CoreCLR -x86 +CALL packages\KoreBuild\build\dotnetsdk upgrade -runtime CLR -x86 +CALL packages\KoreBuild\build\dotnetsdk install default -runtime CoreCLR -x86 :run -CALL packages\KoreBuild\build\kvm use default -runtime CLR -x86 -packages\Sake\tools\Sake.exe -I build -I packages\KoreBuild\build -f makefile.shade %* +CALL packages\KoreBuild\build\dotnetsdk use default -runtime CLR -x86 +packages\Sake\tools\Sake.exe -I packages\KoreBuild\build -f makefile.shade %* diff --git a/build.sh b/build.sh index c7873ef58e..3f3c731c04 100644 --- a/build.sh +++ b/build.sh @@ -28,11 +28,11 @@ if test ! -d packages/KoreBuild; then fi if ! type k > /dev/null 2>&1; then - source packages/KoreBuild/build/kvm.sh + source setup/dotnetsdk.sh fi if ! type k > /dev/null 2>&1; then - kvm upgrade + dotnetsdk upgrade fi mono packages/Sake/tools/Sake.exe -I packages/KoreBuild/build -f makefile.shade "$@" From ac20982505bd915454d606aabaf8d81c39fca795 Mon Sep 17 00:00:00 2001 From: Pranav K Date: Tue, 20 Jan 2015 01:36:16 -0800 Subject: [PATCH 0080/1662] Updating build.cmd and build.sh to use dotnetsdk --- build.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.sh b/build.sh index 3f3c731c04..350d7e389a 100644 --- a/build.sh +++ b/build.sh @@ -28,7 +28,7 @@ if test ! -d packages/KoreBuild; then fi if ! type k > /dev/null 2>&1; then - source setup/dotnetsdk.sh + source packages/KoreBuild/build/dotnetsdk.sh fi if ! type k > /dev/null 2>&1; then From ad9cfa8666698e340e13fc8ea9576d63f1eafbaf Mon Sep 17 00:00:00 2001 From: Pranav K Date: Tue, 20 Jan 2015 02:27:19 -0800 Subject: [PATCH 0081/1662] Reverting build script customization that was overwritten --- build.cmd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.cmd b/build.cmd index c8041fdd9d..13f4e275a6 100644 --- a/build.cmd +++ b/build.cmd @@ -25,4 +25,4 @@ CALL packages\KoreBuild\build\dotnetsdk install default -runtime CoreCLR -x86 :run CALL packages\KoreBuild\build\dotnetsdk use default -runtime CLR -x86 -packages\Sake\tools\Sake.exe -I packages\KoreBuild\build -f makefile.shade %* +packages\Sake\tools\Sake.exe -I build -I packages\KoreBuild\build -f makefile.shade %* From 34a23df76b2d764c68839973dab7958de9011548 Mon Sep 17 00:00:00 2001 From: Wei Wang Date: Tue, 20 Jan 2015 18:25:02 -0800 Subject: [PATCH 0082/1662] Rename SKIP_KRE_INSTALL to SKIP_DOTNET_INSTALL --- build.cmd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.cmd b/build.cmd index 13f4e275a6..e61b61ef2e 100644 --- a/build.cmd +++ b/build.cmd @@ -19,7 +19,7 @@ IF EXIST packages\KoreBuild goto run .nuget\NuGet.exe install KoreBuild -ExcludeVersion -o packages -nocache -pre .nuget\NuGet.exe install Sake -version 0.2 -o packages -ExcludeVersion -IF "%SKIP_KRE_INSTALL%"=="1" goto run +IF "%SKIP_DOTNET_INSTALL%"=="1" goto run CALL packages\KoreBuild\build\dotnetsdk upgrade -runtime CLR -x86 CALL packages\KoreBuild\build\dotnetsdk install default -runtime CoreCLR -x86 From 780564b8c39d7fc54028e14ba2e83f1b4f7bf6ff Mon Sep 17 00:00:00 2001 From: Aligned Date: Wed, 21 Jan 2015 13:16:55 -0600 Subject: [PATCH 0083/1662] Change ASP.NET vNext to ASP.Net 5 in the Readme.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index ad45dd6a1e..62ee846848 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ KestrelHttpServer ================= -This repo contains a development web server for ASP.NET vNext based on [libuv](https://github.com/libuv/libuv). +This repo contains a development web server for ASP.NET 5 based on [libuv](https://github.com/libuv/libuv). -This project is part of ASP.NET vNext. You can find samples, documentation and getting started instructions for ASP.NET vNext at the [Home](https://github.com/aspnet/home) repo. +This project is part of ASP.NET 5. You can find samples, documentation and getting started instructions for ASP.NET 5 at the [Home](https://github.com/aspnet/home) repo. From 25e1fefaf51d89879004d155065e2829c1f279b9 Mon Sep 17 00:00:00 2001 From: Suhas Joshi Date: Wed, 21 Jan 2015 15:55:33 -0800 Subject: [PATCH 0084/1662] Updating to release NuGet.config --- NuGet.Config | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NuGet.Config b/NuGet.Config index f41e9c631d..2d3b0cb857 100644 --- a/NuGet.Config +++ b/NuGet.Config @@ -1,7 +1,7 @@  - + From ab257ed71659c3b851362309c8feb5cdd8786101 Mon Sep 17 00:00:00 2001 From: Wei Wang Date: Wed, 28 Jan 2015 18:20:06 -0800 Subject: [PATCH 0085/1662] Update build.cmd and build.sh to use kvm --- build.cmd | 6 +++--- build.sh | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/build.cmd b/build.cmd index e61b61ef2e..89a02eb2ea 100644 --- a/build.cmd +++ b/build.cmd @@ -20,9 +20,9 @@ IF EXIST packages\KoreBuild goto run .nuget\NuGet.exe install Sake -version 0.2 -o packages -ExcludeVersion IF "%SKIP_DOTNET_INSTALL%"=="1" goto run -CALL packages\KoreBuild\build\dotnetsdk upgrade -runtime CLR -x86 -CALL packages\KoreBuild\build\dotnetsdk install default -runtime CoreCLR -x86 +CALL packages\KoreBuild\build\kvm upgrade -runtime CLR -x86 +CALL packages\KoreBuild\build\kvm install default -runtime CoreCLR -x86 :run -CALL packages\KoreBuild\build\dotnetsdk use default -runtime CLR -x86 +CALL packages\KoreBuild\build\kvm use default -runtime CLR -x86 packages\Sake\tools\Sake.exe -I build -I packages\KoreBuild\build -f makefile.shade %* diff --git a/build.sh b/build.sh index 350d7e389a..c7873ef58e 100644 --- a/build.sh +++ b/build.sh @@ -28,11 +28,11 @@ if test ! -d packages/KoreBuild; then fi if ! type k > /dev/null 2>&1; then - source packages/KoreBuild/build/dotnetsdk.sh + source packages/KoreBuild/build/kvm.sh fi if ! type k > /dev/null 2>&1; then - dotnetsdk upgrade + kvm upgrade fi mono packages/Sake/tools/Sake.exe -I packages/KoreBuild/build -f makefile.shade "$@" From 37eb84a8405d7c294e5f240d5e00b3cbc0f0c880 Mon Sep 17 00:00:00 2001 From: Wei Wang Date: Wed, 28 Jan 2015 18:20:22 -0800 Subject: [PATCH 0086/1662] Change SKIP_DOTNET_INSTALL to SKIP_KRE_INSTALL --- build.cmd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.cmd b/build.cmd index 89a02eb2ea..62484c042c 100644 --- a/build.cmd +++ b/build.cmd @@ -19,7 +19,7 @@ IF EXIST packages\KoreBuild goto run .nuget\NuGet.exe install KoreBuild -ExcludeVersion -o packages -nocache -pre .nuget\NuGet.exe install Sake -version 0.2 -o packages -ExcludeVersion -IF "%SKIP_DOTNET_INSTALL%"=="1" goto run +IF "%SKIP_KRE_INSTALL%"=="1" goto run CALL packages\KoreBuild\build\kvm upgrade -runtime CLR -x86 CALL packages\KoreBuild\build\kvm install default -runtime CoreCLR -x86 From e8d9414d920c2227f0c2ee65d23cc33fed53c527 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Tue, 10 Feb 2015 10:08:16 -0800 Subject: [PATCH 0087/1662] Removed build time dependency --- src/Microsoft.AspNet.Server.Kestrel/project.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/project.json b/src/Microsoft.AspNet.Server.Kestrel/project.json index ce0501a412..4e685035cb 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/project.json +++ b/src/Microsoft.AspNet.Server.Kestrel/project.json @@ -2,7 +2,7 @@ "version": "1.0.0-*", "description": "ASP.NET 5 cross platform development web server.", "dependencies": { - "Microsoft.Framework.Runtime.Interfaces": { "version": "1.0.0-*","type": "build" } + "Microsoft.Framework.Runtime.Interfaces": "1.0.0-*" }, "frameworks": { "aspnet50": { }, From 0da745439c04077a4d7366534396698d9260d227 Mon Sep 17 00:00:00 2001 From: Wei Wang Date: Mon, 16 Feb 2015 13:33:56 -0800 Subject: [PATCH 0088/1662] Add project.lock.json to .gitignore --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 216e8d9c58..5de40f3cd7 100644 --- a/.gitignore +++ b/.gitignore @@ -23,4 +23,5 @@ nuget.exe *DS_Store *.ncrunchsolution *.*sdf -*.ipch \ No newline at end of file +*.ipch +project.lock.json From cb3def56683cc9e0294b5e78fb70f686be4074ee Mon Sep 17 00:00:00 2001 From: Praburaj Date: Wed, 25 Feb 2015 17:40:17 -0800 Subject: [PATCH 0089/1662] Changing signature of AppFunc to pass on IFeatureCollection Reaction to this fix: https://github.com/aspnet/Hosting/issues/162 --- src/Kestrel/ServerFactory.cs | 18 +++++++++++------- src/Kestrel/ServerRequest.cs | 23 +++++++++++++++++++++-- 2 files changed, 32 insertions(+), 9 deletions(-) diff --git a/src/Kestrel/ServerFactory.cs b/src/Kestrel/ServerFactory.cs index c683d63be6..4c8997519d 100644 --- a/src/Kestrel/ServerFactory.cs +++ b/src/Kestrel/ServerFactory.cs @@ -1,10 +1,14 @@ -using Microsoft.AspNet.Hosting.Server; +// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + using System; -using Microsoft.AspNet.Builder; -using Microsoft.Framework.ConfigurationModel; -using System.Threading.Tasks; -using Microsoft.AspNet.Server.Kestrel; using System.Collections.Generic; +using System.Threading.Tasks; +using Microsoft.AspNet.Builder; +using Microsoft.AspNet.FeatureModel; +using Microsoft.AspNet.Hosting.Server; +using Microsoft.AspNet.Server.Kestrel; +using Microsoft.Framework.ConfigurationModel; using Microsoft.Framework.Runtime; namespace Kestrel @@ -28,7 +32,7 @@ namespace Kestrel return information; } - public IDisposable Start(IServerInformation serverInformation, Func application) + public IDisposable Start(IServerInformation serverInformation, Func application) { var disposables = new List(); var information = (ServerInformation)serverInformation; @@ -43,7 +47,7 @@ namespace Kestrel async frame => { var request = new ServerRequest(frame); - await application.Invoke(request); + await application.Invoke(request.Features); })); } disposables.Add(engine); diff --git a/src/Kestrel/ServerRequest.cs b/src/Kestrel/ServerRequest.cs index 3b60965b6f..d455feefad 100644 --- a/src/Kestrel/ServerRequest.cs +++ b/src/Kestrel/ServerRequest.cs @@ -1,10 +1,14 @@ -using Microsoft.AspNet.Http.Interfaces; -using Microsoft.AspNet.Server.Kestrel.Http; +// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Threading.Tasks; +using Microsoft.AspNet.FeatureModel; +using Microsoft.AspNet.Http.Interfaces; +using Microsoft.AspNet.Server.Kestrel.Http; namespace Kestrel { @@ -13,10 +17,25 @@ namespace Kestrel Frame _frame; string _scheme; string _pathBase; + private FeatureCollection _features; public ServerRequest(Frame frame) { _frame = frame; + _features = new FeatureCollection(); + PopulateFeatures(); + } + + private void PopulateFeatures() + { + _features.Add(typeof(IHttpRequestFeature), this); + _features.Add(typeof(IHttpResponseFeature), this); + _features.Add(typeof(IHttpUpgradeFeature), this); + } + + internal IFeatureCollection Features + { + get { return _features; } } string IHttpRequestFeature.Protocol From 620e83b59032e2e9a965bd65b3887a457502adfa Mon Sep 17 00:00:00 2001 From: Praburaj Date: Thu, 5 Mar 2015 16:23:18 -0800 Subject: [PATCH 0090/1662] Rename Microsoft.AspNet.Http.Interfaces => Microsoft.AspNet.Http --- src/Kestrel/ServerRequest.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Kestrel/ServerRequest.cs b/src/Kestrel/ServerRequest.cs index d455feefad..2a7a942ac8 100644 --- a/src/Kestrel/ServerRequest.cs +++ b/src/Kestrel/ServerRequest.cs @@ -7,7 +7,7 @@ using System.IO; using System.Linq; using System.Threading.Tasks; using Microsoft.AspNet.FeatureModel; -using Microsoft.AspNet.Http.Interfaces; +using Microsoft.AspNet.Http; using Microsoft.AspNet.Server.Kestrel.Http; namespace Kestrel From 06a82669f598e0d768e4afca04483521962eb0f8 Mon Sep 17 00:00:00 2001 From: "N. Taylor Mullen" Date: Sun, 8 Mar 2015 12:51:12 -0700 Subject: [PATCH 0091/1662] Update aspnet50/aspnetcore50 => dnx451/dnxcore50. --- samples/SampleApp/project.json | 6 +++--- src/Kestrel/project.json | 6 +++--- .../Http/FrameDuplexStream.cs | 8 ++++---- .../Http/FrameRequestStream.cs | 4 ++-- .../Infrastructure/KestrelThread.cs | 4 ++-- .../Networking/PlatformApis.cs | 4 ++-- src/Microsoft.AspNet.Server.Kestrel/project.json | 6 +++--- test/Microsoft.AspNet.Server.KestrelTests/project.json | 6 +++--- 8 files changed, 22 insertions(+), 22 deletions(-) diff --git a/samples/SampleApp/project.json b/samples/SampleApp/project.json index 4d30db9489..f627f9f10f 100644 --- a/samples/SampleApp/project.json +++ b/samples/SampleApp/project.json @@ -1,11 +1,11 @@ -{ +{ "version": "1.0.0-*", "dependencies": { "Kestrel": "1.0.0-*" }, "frameworks": { - "aspnet50": { }, - "aspnetcore50": { + "dnx451": { }, + "dnxcore50": { "dependencies": { "System.Console": "4.0.0-beta-*" } diff --git a/src/Kestrel/project.json b/src/Kestrel/project.json index 726fa65fd7..c97ceea693 100644 --- a/src/Kestrel/project.json +++ b/src/Kestrel/project.json @@ -1,4 +1,4 @@ -{ +{ "version": "1.0.0-*", "description": "ASP.NET 5 cross platform development web server.", "dependencies": { @@ -6,10 +6,10 @@ "Microsoft.AspNet.Server.Kestrel": "1.0.0-*" }, "frameworks": { - "aspnet50": { + "dnx451": { "dependencies": { } }, - "aspnetcore50": { + "dnxcore50": { "dependencies": { "System.Runtime": "4.0.20-beta-*" } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameDuplexStream.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameDuplexStream.cs index 27db2d30b0..661c9ec59f 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameDuplexStream.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameDuplexStream.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -19,7 +19,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http _responseStream = responseStream; } -#if ASPNET50 +#if DNX451 public override void Close() { _requestStream.Close(); @@ -46,7 +46,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return _responseStream.FlushAsync(cancellationToken); } -#if ASPNET50 +#if DNX451 public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback callback, object state) { return _requestStream.BeginRead(buffer, offset, count, callback, state); @@ -68,7 +68,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return _requestStream.CopyToAsync(destination, bufferSize, cancellationToken); } -#if ASPNET50 +#if DNX451 public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback callback, object state) { return _responseStream.BeginWrite(buffer, offset, count, callback, state); diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameRequestStream.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameRequestStream.cs index aed7e30cf3..645a7afb12 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameRequestStream.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameRequestStream.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -41,7 +41,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return ReadAsync(buffer, offset, count).Result; } -#if ASPNET50 +#if DNX451 public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback callback, object state) { var task = ReadAsync(buffer, offset, count, CancellationToken.None, state); diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs index b7fd07c627..3b6b885df1 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using Microsoft.AspNet.Server.Kestrel.Networking; @@ -56,7 +56,7 @@ namespace Microsoft.AspNet.Server.Kestrel Post(OnStopImmediate, null); if (!_thread.Join((int)timeout.TotalMilliseconds)) { -#if ASPNET50 +#if DNX451 _thread.Abort(); #endif } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/PlatformApis.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/PlatformApis.cs index ff7c4fa12c..55a2fe77b4 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/PlatformApis.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/PlatformApis.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -12,7 +12,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking { public static bool IsWindows() { -#if ASPNETCORE50 +#if DNXCORE50 return true; #else var p = (int)Environment.OSVersion.Platform; diff --git a/src/Microsoft.AspNet.Server.Kestrel/project.json b/src/Microsoft.AspNet.Server.Kestrel/project.json index 4e685035cb..796e9ab1ed 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/project.json +++ b/src/Microsoft.AspNet.Server.Kestrel/project.json @@ -1,12 +1,12 @@ -{ +{ "version": "1.0.0-*", "description": "ASP.NET 5 cross platform development web server.", "dependencies": { "Microsoft.Framework.Runtime.Interfaces": "1.0.0-*" }, "frameworks": { - "aspnet50": { }, - "aspnetcore50": { + "dnx451": { }, + "dnxcore50": { "dependencies": { "System.Collections": "4.0.10-beta-*", "System.Diagnostics.Debug": "4.0.10-beta-*", diff --git a/test/Microsoft.AspNet.Server.KestrelTests/project.json b/test/Microsoft.AspNet.Server.KestrelTests/project.json index e7ccd24e25..1ea27e057b 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/project.json +++ b/test/Microsoft.AspNet.Server.KestrelTests/project.json @@ -1,12 +1,12 @@ -{ +{ "version": "1.0.0-*", "dependencies": { "xunit.runner.kre": "1.0.0-*", "Microsoft.AspNet.Server.Kestrel": "1.0.0-*" }, "frameworks": { - "aspnet50": { }, - "aspnetcore50": { + "dnx451": { }, + "dnxcore50": { "dependencies": { "System.Net.Sockets": "4.0.0-beta-*", "System.Runtime.Handles": "4.0.0-beta-*", From dc5fe8a7bcb24be49b9cb169462e81bda6bead6e Mon Sep 17 00:00:00 2001 From: "N. Taylor Mullen" Date: Sun, 8 Mar 2015 12:51:12 -0700 Subject: [PATCH 0092/1662] Update K_BUILD_VERSION/kre/KRE/.k => DNX_BUILD_VERSION/dnx/DNX/.dnx. --- build.cmd | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build.cmd b/build.cmd index 62484c042c..9b58d9c809 100644 --- a/build.cmd +++ b/build.cmd @@ -1,4 +1,4 @@ -@echo off +@echo off cd %~dp0 SETLOCAL @@ -19,7 +19,7 @@ IF EXIST packages\KoreBuild goto run .nuget\NuGet.exe install KoreBuild -ExcludeVersion -o packages -nocache -pre .nuget\NuGet.exe install Sake -version 0.2 -o packages -ExcludeVersion -IF "%SKIP_KRE_INSTALL%"=="1" goto run +IF "%SKIP_DNX_INSTALL%"=="1" goto run CALL packages\KoreBuild\build\kvm upgrade -runtime CLR -x86 CALL packages\KoreBuild\build\kvm install default -runtime CoreCLR -x86 From 814689826ff7c76c4ec21020f6df8b27eddaac20 Mon Sep 17 00:00:00 2001 From: "N. Taylor Mullen" Date: Sun, 8 Mar 2015 12:51:13 -0700 Subject: [PATCH 0093/1662] Update kvm/KVM/Kvm => dnvm/DNVM/Dnvm. --- build.cmd | 6 +++--- build.sh | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/build.cmd b/build.cmd index 9b58d9c809..7c90be33c2 100644 --- a/build.cmd +++ b/build.cmd @@ -20,9 +20,9 @@ IF EXIST packages\KoreBuild goto run .nuget\NuGet.exe install Sake -version 0.2 -o packages -ExcludeVersion IF "%SKIP_DNX_INSTALL%"=="1" goto run -CALL packages\KoreBuild\build\kvm upgrade -runtime CLR -x86 -CALL packages\KoreBuild\build\kvm install default -runtime CoreCLR -x86 +CALL packages\KoreBuild\build\dnvm upgrade -runtime CLR -x86 +CALL packages\KoreBuild\build\dnvm install default -runtime CoreCLR -x86 :run -CALL packages\KoreBuild\build\kvm use default -runtime CLR -x86 +CALL packages\KoreBuild\build\dnvm use default -runtime CLR -x86 packages\Sake\tools\Sake.exe -I build -I packages\KoreBuild\build -f makefile.shade %* diff --git a/build.sh b/build.sh index c7873ef58e..74cb3421e6 100644 --- a/build.sh +++ b/build.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/bash if test `uname` = Darwin; then cachedir=~/Library/Caches/KBuild @@ -28,11 +28,11 @@ if test ! -d packages/KoreBuild; then fi if ! type k > /dev/null 2>&1; then - source packages/KoreBuild/build/kvm.sh + source packages/KoreBuild/build/dnvm.sh fi if ! type k > /dev/null 2>&1; then - kvm upgrade + dnvm upgrade fi mono packages/Sake/tools/Sake.exe -I packages/KoreBuild/build -f makefile.shade "$@" From 8c71b6855d4601b79c41efbcaea164acf13ed8ec Mon Sep 17 00:00:00 2001 From: "N. Taylor Mullen" Date: Sun, 8 Mar 2015 12:51:13 -0700 Subject: [PATCH 0094/1662] Update build.sh to use dnvm correctly. --- build.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/build.sh b/build.sh index 74cb3421e6..a9ce06d087 100644 --- a/build.sh +++ b/build.sh @@ -27,7 +27,7 @@ if test ! -d packages/KoreBuild; then mono .nuget/nuget.exe install Sake -version 0.2 -o packages -ExcludeVersion fi -if ! type k > /dev/null 2>&1; then +if ! type dnvm > /dev/null 2>&1; then source packages/KoreBuild/build/dnvm.sh fi @@ -36,3 +36,4 @@ if ! type k > /dev/null 2>&1; then fi mono packages/Sake/tools/Sake.exe -I packages/KoreBuild/build -f makefile.shade "$@" + From f796e1a5fcea7aad8caaf88c3b0f7acb11cd9444 Mon Sep 17 00:00:00 2001 From: "N. Taylor Mullen" Date: Mon, 9 Mar 2015 12:55:39 -0700 Subject: [PATCH 0095/1662] Remove BOM from project.json, *.cmd, *.sh and *.shade files. --- build.cmd | 2 +- build.sh | 2 +- samples/SampleApp/project.json | 2 +- src/Kestrel/project.json | 2 +- src/Microsoft.AspNet.Server.Kestrel/project.json | 2 +- test/Microsoft.AspNet.Server.KestrelTests/project.json | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/build.cmd b/build.cmd index 7c90be33c2..d9afe51fb6 100644 --- a/build.cmd +++ b/build.cmd @@ -1,4 +1,4 @@ -@echo off +@echo off cd %~dp0 SETLOCAL diff --git a/build.sh b/build.sh index a9ce06d087..ec3263114a 100644 --- a/build.sh +++ b/build.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/bash if test `uname` = Darwin; then cachedir=~/Library/Caches/KBuild diff --git a/samples/SampleApp/project.json b/samples/SampleApp/project.json index f627f9f10f..fe1e191d79 100644 --- a/samples/SampleApp/project.json +++ b/samples/SampleApp/project.json @@ -1,4 +1,4 @@ -{ +{ "version": "1.0.0-*", "dependencies": { "Kestrel": "1.0.0-*" diff --git a/src/Kestrel/project.json b/src/Kestrel/project.json index c97ceea693..8b6eb1c2d9 100644 --- a/src/Kestrel/project.json +++ b/src/Kestrel/project.json @@ -1,4 +1,4 @@ -{ +{ "version": "1.0.0-*", "description": "ASP.NET 5 cross platform development web server.", "dependencies": { diff --git a/src/Microsoft.AspNet.Server.Kestrel/project.json b/src/Microsoft.AspNet.Server.Kestrel/project.json index 796e9ab1ed..73bb020159 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/project.json +++ b/src/Microsoft.AspNet.Server.Kestrel/project.json @@ -1,4 +1,4 @@ -{ +{ "version": "1.0.0-*", "description": "ASP.NET 5 cross platform development web server.", "dependencies": { diff --git a/test/Microsoft.AspNet.Server.KestrelTests/project.json b/test/Microsoft.AspNet.Server.KestrelTests/project.json index 1ea27e057b..1f04bb37eb 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/project.json +++ b/test/Microsoft.AspNet.Server.KestrelTests/project.json @@ -1,4 +1,4 @@ -{ +{ "version": "1.0.0-*", "dependencies": { "xunit.runner.kre": "1.0.0-*", From cb323e8c7ed40220be54ef69cdc4afd713b64908 Mon Sep 17 00:00:00 2001 From: Praburaj Date: Mon, 9 Mar 2015 20:54:25 -0700 Subject: [PATCH 0096/1662] Renaming Nuget.org feed key name to Nuget. fixes https://github.com/aspnet/Universe/issues/174 --- NuGet.Config | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/NuGet.Config b/NuGet.Config index f41e9c631d..da57d47267 100644 --- a/NuGet.Config +++ b/NuGet.Config @@ -2,6 +2,6 @@ - + - + \ No newline at end of file From 8d8c6ea823b55cb53f48d05d483b8f266f4c8d26 Mon Sep 17 00:00:00 2001 From: "N. Taylor Mullen" Date: Wed, 11 Mar 2015 14:09:00 -0700 Subject: [PATCH 0097/1662] Update .kproj => .xproj. --- KestrelHttpServer.sln | 8 ++++---- samples/SampleApp/{SampleApp.kproj => SampleApp.xproj} | 0 src/Kestrel/{Kestrel.kproj => Kestrel.xproj} | 0 ...estrel.kproj => Microsoft.AspNet.Server.Kestrel.xproj} | 0 ...s.kproj => Microsoft.AspNet.Server.KestrelTests.xproj} | 0 5 files changed, 4 insertions(+), 4 deletions(-) rename samples/SampleApp/{SampleApp.kproj => SampleApp.xproj} (100%) rename src/Kestrel/{Kestrel.kproj => Kestrel.xproj} (100%) rename src/Microsoft.AspNet.Server.Kestrel/{Microsoft.AspNet.Server.Kestrel.kproj => Microsoft.AspNet.Server.Kestrel.xproj} (100%) rename test/Microsoft.AspNet.Server.KestrelTests/{Microsoft.AspNet.Server.KestrelTests.kproj => Microsoft.AspNet.Server.KestrelTests.xproj} (100%) diff --git a/KestrelHttpServer.sln b/KestrelHttpServer.sln index 30b34d2c9d..a9437d0659 100644 --- a/KestrelHttpServer.sln +++ b/KestrelHttpServer.sln @@ -3,9 +3,9 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 14 VisualStudioVersion = 14.0.22111.0 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.Server.Kestrel", "src\Microsoft.AspNet.Server.Kestrel\Microsoft.AspNet.Server.Kestrel.kproj", "{F510611A-3BEE-4B88-A613-5F4A74ED82A1}" +Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.Server.Kestrel", "src\Microsoft.AspNet.Server.Kestrel\Microsoft.AspNet.Server.Kestrel.xproj", "{F510611A-3BEE-4B88-A613-5F4A74ED82A1}" EndProject -Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.Server.KestrelTests", "test\Microsoft.AspNet.Server.KestrelTests\Microsoft.AspNet.Server.KestrelTests.kproj", "{37F3BFB2-6454-49E5-9D7F-581BF755CCFE}" +Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.Server.KestrelTests", "test\Microsoft.AspNet.Server.KestrelTests\Microsoft.AspNet.Server.KestrelTests.xproj", "{37F3BFB2-6454-49E5-9D7F-581BF755CCFE}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{7972A5D6-3385-4127-9277-428506DD44FF}" ProjectSection(SolutionItems) = preProject @@ -15,9 +15,9 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution makefile.shade = makefile.shade EndProjectSection EndProject -Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "SampleApp", "samples\SampleApp\SampleApp.kproj", "{2C3CB3DC-EEBF-4F52-9E1C-4F2F972E76C3}" +Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "SampleApp", "samples\SampleApp\SampleApp.xproj", "{2C3CB3DC-EEBF-4F52-9E1C-4F2F972E76C3}" EndProject -Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Kestrel", "src\Kestrel\Kestrel.kproj", "{30B7617E-58EF-4382-B3EA-5B2E718CF1A6}" +Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Kestrel", "src\Kestrel\Kestrel.xproj", "{30B7617E-58EF-4382-B3EA-5B2E718CF1A6}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{2D5D5227-4DBD-499A-96B1-76A36B03B750}" EndProject diff --git a/samples/SampleApp/SampleApp.kproj b/samples/SampleApp/SampleApp.xproj similarity index 100% rename from samples/SampleApp/SampleApp.kproj rename to samples/SampleApp/SampleApp.xproj diff --git a/src/Kestrel/Kestrel.kproj b/src/Kestrel/Kestrel.xproj similarity index 100% rename from src/Kestrel/Kestrel.kproj rename to src/Kestrel/Kestrel.xproj diff --git a/src/Microsoft.AspNet.Server.Kestrel/Microsoft.AspNet.Server.Kestrel.kproj b/src/Microsoft.AspNet.Server.Kestrel/Microsoft.AspNet.Server.Kestrel.xproj similarity index 100% rename from src/Microsoft.AspNet.Server.Kestrel/Microsoft.AspNet.Server.Kestrel.kproj rename to src/Microsoft.AspNet.Server.Kestrel/Microsoft.AspNet.Server.Kestrel.xproj diff --git a/test/Microsoft.AspNet.Server.KestrelTests/Microsoft.AspNet.Server.KestrelTests.kproj b/test/Microsoft.AspNet.Server.KestrelTests/Microsoft.AspNet.Server.KestrelTests.xproj similarity index 100% rename from test/Microsoft.AspNet.Server.KestrelTests/Microsoft.AspNet.Server.KestrelTests.kproj rename to test/Microsoft.AspNet.Server.KestrelTests/Microsoft.AspNet.Server.KestrelTests.xproj From 1990b9ee97889c15b4daa526b64eb12df66c56f5 Mon Sep 17 00:00:00 2001 From: Doug Bunting Date: Wed, 11 Mar 2015 16:58:28 -0700 Subject: [PATCH 0098/1662] Do not use deprecated `dnvm -x86` switch --- build.cmd | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/build.cmd b/build.cmd index d9afe51fb6..6d798a5b37 100644 --- a/build.cmd +++ b/build.cmd @@ -20,9 +20,9 @@ IF EXIST packages\KoreBuild goto run .nuget\NuGet.exe install Sake -version 0.2 -o packages -ExcludeVersion IF "%SKIP_DNX_INSTALL%"=="1" goto run -CALL packages\KoreBuild\build\dnvm upgrade -runtime CLR -x86 -CALL packages\KoreBuild\build\dnvm install default -runtime CoreCLR -x86 +CALL packages\KoreBuild\build\dnvm upgrade -runtime CLR -arch x86 +CALL packages\KoreBuild\build\dnvm install default -runtime CoreCLR -arch x86 :run -CALL packages\KoreBuild\build\dnvm use default -runtime CLR -x86 +CALL packages\KoreBuild\build\dnvm use default -runtime CLR -arch x86 packages\Sake\tools\Sake.exe -I build -I packages\KoreBuild\build -f makefile.shade %* From 20ffd7e08128292e65b6229de534a6433f6f9957 Mon Sep 17 00:00:00 2001 From: Brennan Date: Thu, 12 Mar 2015 16:26:13 -0700 Subject: [PATCH 0099/1662] Update xunit.runner.kre => xunit.runner.aspnet. --- test/Microsoft.AspNet.Server.KestrelTests/project.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/Microsoft.AspNet.Server.KestrelTests/project.json b/test/Microsoft.AspNet.Server.KestrelTests/project.json index 1f04bb37eb..8d1e6a4443 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/project.json +++ b/test/Microsoft.AspNet.Server.KestrelTests/project.json @@ -1,7 +1,7 @@ { "version": "1.0.0-*", "dependencies": { - "xunit.runner.kre": "1.0.0-*", + "xunit.runner.aspnet": "2.0.0-aspnet-*", "Microsoft.AspNet.Server.Kestrel": "1.0.0-*" }, "frameworks": { @@ -15,7 +15,7 @@ } }, "commands": { - "run": "xunit.runner.kre", - "test": "xunit.runner.kre" + "run": "xunit.runner.aspnet", + "test": "xunit.runner.aspnet" } } From c1e298b01085f763261374ea4d25e341e33d854c Mon Sep 17 00:00:00 2001 From: Ajay Bhargav Baaskaran Date: Thu, 19 Feb 2015 18:09:43 -0800 Subject: [PATCH 0100/1662] React to aspnet/HttpAbstractions#160 - Implementing OnResponseCompleted --- src/Kestrel/ServerRequest.cs | 5 +++ .../Http/Frame.cs | 39 +++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/src/Kestrel/ServerRequest.cs b/src/Kestrel/ServerRequest.cs index 2a7a942ac8..5c3ffc10ff 100644 --- a/src/Kestrel/ServerRequest.cs +++ b/src/Kestrel/ServerRequest.cs @@ -204,6 +204,11 @@ namespace Kestrel _frame.OnSendingHeaders(callback, state); } + void IHttpResponseFeature.OnResponseCompleted(Action callback, object state) + { + _frame.OnResponseCompleted(callback, state); + } + bool IHttpUpgradeFeature.IsUpgradableRequest { get diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs index c20ae236b1..bf682a7075 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs @@ -64,7 +64,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Http */ List, object>> _onSendingHeaders; + List, object>> _onResponseCompleted; object _onSendingHeadersSync = new Object(); + object _onResponseCompletedSync = new Object(); public Frame(ConnectionContext context) : base(context) { @@ -200,6 +202,18 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } + public void OnResponseCompleted(Action callback, object state) + { + lock (_onResponseCompletedSync) + { + if (_onResponseCompleted == null) + { + _onResponseCompleted = new List, object>>(); + } + _onResponseCompleted.Add(new KeyValuePair, object>(callback, state)); + } + } + private void FireOnSendingHeaders() { List, object>> onSendingHeaders = null; @@ -217,6 +231,30 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } + private void FireOnResponseCompleted() + { + List, object>> onResponseCompleted = null; + lock (_onResponseCompletedSync) + { + onResponseCompleted = _onResponseCompleted; + _onResponseCompleted = null; + } + if (onResponseCompleted != null) + { + foreach (var entry in onResponseCompleted) + { + try + { + entry.Key.Invoke(entry.Value); + } + catch + { + // Ignore exceptions + } + } + } + } + private async Task ExecuteAsync() { Exception error = null; @@ -230,6 +268,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } finally { + FireOnResponseCompleted(); ProduceEnd(error); } } From ceb37405d5b9e80a8e937ec5f6297794e313d3e0 Mon Sep 17 00:00:00 2001 From: Wei Wang Date: Tue, 24 Mar 2015 21:34:59 -0700 Subject: [PATCH 0101/1662] Remove k command and use dnx instead --- build.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.sh b/build.sh index ec3263114a..d81164353c 100644 --- a/build.sh +++ b/build.sh @@ -31,7 +31,7 @@ if ! type dnvm > /dev/null 2>&1; then source packages/KoreBuild/build/dnvm.sh fi -if ! type k > /dev/null 2>&1; then +if ! type dnx > /dev/null 2>&1; then dnvm upgrade fi From ba3a544b8a13507f73dc21b379e03c2351814bac Mon Sep 17 00:00:00 2001 From: suhasj Date: Wed, 25 Mar 2015 11:48:00 -0700 Subject: [PATCH 0102/1662] Updating to release NuGet.config --- NuGet.Config | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/NuGet.Config b/NuGet.Config index da57d47267..1978dc065a 100644 --- a/NuGet.Config +++ b/NuGet.Config @@ -1,7 +1,7 @@  - + - \ No newline at end of file + From 180aa13d3059aae729822366067ce04f045a6c02 Mon Sep 17 00:00:00 2001 From: "N. Taylor Mullen" Date: Wed, 1 Apr 2015 15:51:37 -0700 Subject: [PATCH 0103/1662] Add travis and appveyor CI support. --- .travis.yml | 3 +++ appveyor.yml | 5 +++++ build.sh | 0 3 files changed, 8 insertions(+) create mode 100644 .travis.yml create mode 100644 appveyor.yml mode change 100644 => 100755 build.sh diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000000..0f4cb93e59 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,3 @@ +language: csharp +script: + - ./build.sh verify \ No newline at end of file diff --git a/appveyor.yml b/appveyor.yml new file mode 100644 index 0000000000..88cb9ef145 --- /dev/null +++ b/appveyor.yml @@ -0,0 +1,5 @@ +build_script: + - build.cmd verify +clone_depth: 1 +test: off +deploy: off \ No newline at end of file diff --git a/build.sh b/build.sh old mode 100644 new mode 100755 From f91f3da29cdeb85cedac1afee2652c0eb3b2e707 Mon Sep 17 00:00:00 2001 From: "N. Taylor Mullen" Date: Wed, 1 Apr 2015 17:06:34 -0700 Subject: [PATCH 0104/1662] Turn off sudo for .travis.yml. --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 0f4cb93e59..5939a529e5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,3 +1,4 @@ language: csharp +sudo: false script: - ./build.sh verify \ No newline at end of file From d6a6b986ea164beea83b05fa9616dcd628d26334 Mon Sep 17 00:00:00 2001 From: Troy Dai Date: Thu, 2 Apr 2015 09:20:17 -0700 Subject: [PATCH 0105/1662] Update global.json, sources=>projects --- global.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/global.json b/global.json index ea28015a77..302a900d30 100644 --- a/global.json +++ b/global.json @@ -1,5 +1,5 @@ { - "sources": [ + "projects": [ "src" ] } From 5ad7aea8b4086ebb535922da6f10ce68668aa224 Mon Sep 17 00:00:00 2001 From: Doug Bunting Date: Thu, 2 Apr 2015 13:49:26 -0700 Subject: [PATCH 0106/1662] Update .xproj files for Microsoft.Web.AspNet.* -> Microsoft.DNX.* rename --- samples/SampleApp/SampleApp.xproj | 8 ++++---- src/Kestrel/Kestrel.xproj | 8 ++++---- .../Microsoft.AspNet.Server.Kestrel.xproj | 8 ++++---- .../Microsoft.AspNet.Server.KestrelTests.xproj | 8 ++++---- 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/samples/SampleApp/SampleApp.xproj b/samples/SampleApp/SampleApp.xproj index 266183c44f..043c9b1b41 100644 --- a/samples/SampleApp/SampleApp.xproj +++ b/samples/SampleApp/SampleApp.xproj @@ -1,10 +1,10 @@ - + 14.0 $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) - + 2c3cb3dc-eebf-4f52-9e1c-4f2f972e76c3 ..\..\artifacts\obj\$(MSBuildProjectName) @@ -13,5 +13,5 @@ 2.0 - - + + \ No newline at end of file diff --git a/src/Kestrel/Kestrel.xproj b/src/Kestrel/Kestrel.xproj index 07fa602304..446aa1f972 100644 --- a/src/Kestrel/Kestrel.xproj +++ b/src/Kestrel/Kestrel.xproj @@ -1,10 +1,10 @@ - + 14.0 $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) - + 30b7617e-58ef-4382-b3ea-5b2e718cf1a6 ..\..\artifacts\obj\$(MSBuildProjectName) @@ -13,5 +13,5 @@ 2.0 - - + + \ No newline at end of file diff --git a/src/Microsoft.AspNet.Server.Kestrel/Microsoft.AspNet.Server.Kestrel.xproj b/src/Microsoft.AspNet.Server.Kestrel/Microsoft.AspNet.Server.Kestrel.xproj index e6aef0564f..e31ba32074 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Microsoft.AspNet.Server.Kestrel.xproj +++ b/src/Microsoft.AspNet.Server.Kestrel/Microsoft.AspNet.Server.Kestrel.xproj @@ -1,10 +1,10 @@ - + 14.0 $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) - + f510611a-3bee-4b88-a613-5f4a74ed82a1 ..\..\artifacts\obj\$(MSBuildProjectName) @@ -13,5 +13,5 @@ 2.0 - - + + \ No newline at end of file diff --git a/test/Microsoft.AspNet.Server.KestrelTests/Microsoft.AspNet.Server.KestrelTests.xproj b/test/Microsoft.AspNet.Server.KestrelTests/Microsoft.AspNet.Server.KestrelTests.xproj index e3d71ba62b..5919699731 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/Microsoft.AspNet.Server.KestrelTests.xproj +++ b/test/Microsoft.AspNet.Server.KestrelTests/Microsoft.AspNet.Server.KestrelTests.xproj @@ -1,10 +1,10 @@ - + 14.0 $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) - + 37f3bfb2-6454-49e5-9d7f-581bf755ccfe ..\..\artifacts\obj\$(MSBuildProjectName) @@ -13,5 +13,5 @@ 2.0 - - + + \ No newline at end of file From 41da48265e7cc1852d508bdc788bdb635c251794 Mon Sep 17 00:00:00 2001 From: Wei Wang Date: Fri, 3 Apr 2015 17:16:25 -0700 Subject: [PATCH 0107/1662] Fix AppVeyor git line ending config --- appveyor.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/appveyor.yml b/appveyor.yml index 88cb9ef145..3fab83e134 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,3 +1,5 @@ +init: + - git config --global core.autocrlf true build_script: - build.cmd verify clone_depth: 1 From ee9211a1163add095d879048e6743d27be64825c Mon Sep 17 00:00:00 2001 From: "N. Taylor Mullen" Date: Tue, 7 Apr 2015 16:15:45 -0700 Subject: [PATCH 0108/1662] Update .travis.yml and appveyor.yml to build quietly. --- .travis.yml | 2 +- appveyor.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 5939a529e5..947bf868ee 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,4 @@ language: csharp sudo: false script: - - ./build.sh verify \ No newline at end of file + - ./build.sh --quiet verify \ No newline at end of file diff --git a/appveyor.yml b/appveyor.yml index 3fab83e134..636a7618d3 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,7 +1,7 @@ init: - git config --global core.autocrlf true build_script: - - build.cmd verify + - build.cmd --quiet verify clone_depth: 1 test: off deploy: off \ No newline at end of file From ea636140c73b18418f40007c6fabfb5f6b4fc8ae Mon Sep 17 00:00:00 2001 From: Matt Ellis Date: Mon, 6 Apr 2015 17:53:16 -0700 Subject: [PATCH 0109/1662] Allow Kestrel to boot when on CoreCLR and *NIX With cross platform .NET Core support coming online, we need to update our IsWindows check to not assume running on .NET Core means running on Windows. Since CoreFX doesn't yet expose a method for doing this (they are working on adding it back), we'll just call Uname and if that returns an empty string assume that we are on Windows. --- .../Networking/PlatformApis.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/PlatformApis.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/PlatformApis.cs index 55a2fe77b4..8bbb9df28a 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/PlatformApis.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/PlatformApis.cs @@ -13,7 +13,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking public static bool IsWindows() { #if DNXCORE50 - return true; + // Until Environment.OSVersion.Platform is exposed on .NET Core, we + // try to call uname and if that fails we assume we are on Windows. + return GetUname() == string.Empty; #else var p = (int)Environment.OSVersion.Platform; return (p != 4) && (p != 6) && (p != 128); From a23b665e8da5f291cbf9b200e339a373e9731233 Mon Sep 17 00:00:00 2001 From: Chris Ross Date: Fri, 10 Apr 2015 10:47:31 -0700 Subject: [PATCH 0110/1662] Update IServerInformation namespace. --- src/Kestrel/ServerFactory.cs | 1 - src/Kestrel/ServerInformation.cs | 9 ++++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/Kestrel/ServerFactory.cs b/src/Kestrel/ServerFactory.cs index 4c8997519d..ca56d63653 100644 --- a/src/Kestrel/ServerFactory.cs +++ b/src/Kestrel/ServerFactory.cs @@ -4,7 +4,6 @@ using System; using System.Collections.Generic; using System.Threading.Tasks; -using Microsoft.AspNet.Builder; using Microsoft.AspNet.FeatureModel; using Microsoft.AspNet.Hosting.Server; using Microsoft.AspNet.Server.Kestrel; diff --git a/src/Kestrel/ServerInformation.cs b/src/Kestrel/ServerInformation.cs index dc0dbc4399..852ec6a4c4 100644 --- a/src/Kestrel/ServerInformation.cs +++ b/src/Kestrel/ServerInformation.cs @@ -1,8 +1,11 @@ +// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + using System; -using Microsoft.AspNet.Builder; -using Microsoft.Framework.ConfigurationModel; -using System.Globalization; using System.Collections.Generic; +using System.Globalization; +using Microsoft.AspNet.Hosting.Server; +using Microsoft.Framework.ConfigurationModel; namespace Kestrel { From 01a13bfa1d9533f1373d47b3997c56aad7e10f95 Mon Sep 17 00:00:00 2001 From: "N. Taylor Mullen" Date: Tue, 14 Apr 2015 15:00:26 -0700 Subject: [PATCH 0111/1662] Add serviceable attribute to projects. aspnet/DNX#1600 --- src/Kestrel/Properties/AssemblyInfo.cs | 6 ++++++ .../Properties/AssemblyInfo.cs | 6 ++++++ 2 files changed, 12 insertions(+) create mode 100644 src/Kestrel/Properties/AssemblyInfo.cs create mode 100644 src/Microsoft.AspNet.Server.Kestrel/Properties/AssemblyInfo.cs diff --git a/src/Kestrel/Properties/AssemblyInfo.cs b/src/Kestrel/Properties/AssemblyInfo.cs new file mode 100644 index 0000000000..f5c6f4a83a --- /dev/null +++ b/src/Kestrel/Properties/AssemblyInfo.cs @@ -0,0 +1,6 @@ +// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System.Reflection; + +[assembly: AssemblyMetadata("Serviceable", "True")] \ No newline at end of file diff --git a/src/Microsoft.AspNet.Server.Kestrel/Properties/AssemblyInfo.cs b/src/Microsoft.AspNet.Server.Kestrel/Properties/AssemblyInfo.cs new file mode 100644 index 0000000000..f5c6f4a83a --- /dev/null +++ b/src/Microsoft.AspNet.Server.Kestrel/Properties/AssemblyInfo.cs @@ -0,0 +1,6 @@ +// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System.Reflection; + +[assembly: AssemblyMetadata("Serviceable", "True")] \ No newline at end of file From 59e40904ad6d6cbd68f4c1c3eecda73a02973c03 Mon Sep 17 00:00:00 2001 From: Chris Ross Date: Fri, 24 Apr 2015 09:50:36 -0700 Subject: [PATCH 0112/1662] Remove redundant websocket sample code. --- samples/SampleApp/Startup.cs | 47 ++++-------------------------------- 1 file changed, 5 insertions(+), 42 deletions(-) diff --git a/samples/SampleApp/Startup.cs b/samples/SampleApp/Startup.cs index 880cc4a984..816ab79f3c 100644 --- a/samples/SampleApp/Startup.cs +++ b/samples/SampleApp/Startup.cs @@ -1,9 +1,6 @@ -using Microsoft.AspNet.Builder; +using System; +using Microsoft.AspNet.Builder; using Microsoft.AspNet.Http; -using System; -using System.Net.WebSockets; -using System.Threading; -using System.Threading.Tasks; namespace SampleApp { @@ -19,44 +16,10 @@ namespace SampleApp context.Request.Path, context.Request.QueryString); - if (context.IsWebSocketRequest) - { - var webSocket = await context.AcceptWebSocketAsync(); - await EchoAsync(webSocket); - } - else - { - context.Response.ContentLength = 11; - context.Response.ContentType = "text/plain"; - await context.Response.WriteAsync("Hello world"); - } + context.Response.ContentLength = 11; + context.Response.ContentType = "text/plain"; + await context.Response.WriteAsync("Hello world"); }); } - - public async Task EchoAsync(WebSocket webSocket) - { - var buffer = new ArraySegment(new byte[8192]); - for (; ;) - { - var result = await webSocket.ReceiveAsync( - buffer, - CancellationToken.None); - - if (result.MessageType == WebSocketMessageType.Close) - { - return; - } - else if (result.MessageType == WebSocketMessageType.Text) - { - Console.WriteLine("{0}", System.Text.Encoding.UTF8.GetString(buffer.Array, 0, result.Count)); - } - - await webSocket.SendAsync( - new ArraySegment(buffer.Array, 0, result.Count), - result.MessageType, - result.EndOfMessage, - CancellationToken.None); - } - } } } \ No newline at end of file From cb4361b2538fbe936387ea0d39175bfd97e46aba Mon Sep 17 00:00:00 2001 From: Brennan Date: Fri, 1 May 2015 11:07:18 -0700 Subject: [PATCH 0113/1662] React to DNX package renames --- src/Microsoft.AspNet.Server.Kestrel/project.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/project.json b/src/Microsoft.AspNet.Server.Kestrel/project.json index 73bb020159..a9bdf0f6d6 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/project.json +++ b/src/Microsoft.AspNet.Server.Kestrel/project.json @@ -2,7 +2,7 @@ "version": "1.0.0-*", "description": "ASP.NET 5 cross platform development web server.", "dependencies": { - "Microsoft.Framework.Runtime.Interfaces": "1.0.0-*" + "Microsoft.Framework.Runtime.Abstractions": "1.0.0-*" }, "frameworks": { "dnx451": { }, From 063fb64c8b828d37a962f57d7b66319597bff5f0 Mon Sep 17 00:00:00 2001 From: "N. Taylor Mullen" Date: Fri, 1 May 2015 13:53:45 -0700 Subject: [PATCH 0114/1662] Update LICENSE.txt and license header on files. --- LICENSE.txt | 2 +- src/Kestrel/Properties/AssemblyInfo.cs | 2 +- src/Kestrel/ServerFactory.cs | 2 +- src/Kestrel/ServerInformation.cs | 2 +- src/Kestrel/ServerRequest.cs | 2 +- src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs | 2 +- src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs | 2 +- src/Microsoft.AspNet.Server.Kestrel/Http/FrameDuplexStream.cs | 2 +- src/Microsoft.AspNet.Server.Kestrel/Http/FrameRequestStream.cs | 2 +- src/Microsoft.AspNet.Server.Kestrel/Http/FrameResponseStream.cs | 2 +- src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs | 2 +- src/Microsoft.AspNet.Server.Kestrel/Http/MemoryPool.cs | 2 +- .../Http/MemoryPoolTextWriter.cs | 2 +- src/Microsoft.AspNet.Server.Kestrel/Http/MessageBody.cs | 2 +- .../Http/MessageBodyExchanger.cs | 2 +- src/Microsoft.AspNet.Server.Kestrel/Http/ReasonPhrases.cs | 2 +- src/Microsoft.AspNet.Server.Kestrel/Http/SocketInput.cs | 2 +- src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs | 2 +- .../Infrastructure/Disposable.cs | 2 +- .../Infrastructure/KestrelThread.cs | 2 +- src/Microsoft.AspNet.Server.Kestrel/KestrelEngine.cs | 2 +- src/Microsoft.AspNet.Server.Kestrel/Networking/Libuv.cs | 2 +- src/Microsoft.AspNet.Server.Kestrel/Networking/PlatformApis.cs | 2 +- src/Microsoft.AspNet.Server.Kestrel/Networking/UcAsyncHandle.cs | 2 +- src/Microsoft.AspNet.Server.Kestrel/Networking/UvHandle.cs | 2 +- src/Microsoft.AspNet.Server.Kestrel/Networking/UvLoopHandle.cs | 2 +- src/Microsoft.AspNet.Server.Kestrel/Networking/UvMemory.cs | 2 +- src/Microsoft.AspNet.Server.Kestrel/Networking/UvShutdownReq.cs | 2 +- .../Networking/UvStreamHandle.cs | 2 +- src/Microsoft.AspNet.Server.Kestrel/Networking/UvTcpHandle.cs | 2 +- .../Networking/UvWriteRequest.cs | 2 +- src/Microsoft.AspNet.Server.Kestrel/Properties/AssemblyInfo.cs | 2 +- test/Microsoft.AspNet.Server.KestrelTests/NetworkingTests.cs | 2 +- 33 files changed, 33 insertions(+), 33 deletions(-) diff --git a/LICENSE.txt b/LICENSE.txt index c0e6e7629e..3d50203c08 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -1,4 +1,4 @@ -Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +Copyright (c) .NET Foundation. All rights reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use these files except in compliance with the License. You may obtain a copy of the diff --git a/src/Kestrel/Properties/AssemblyInfo.cs b/src/Kestrel/Properties/AssemblyInfo.cs index f5c6f4a83a..025a94598c 100644 --- a/src/Kestrel/Properties/AssemblyInfo.cs +++ b/src/Kestrel/Properties/AssemblyInfo.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Reflection; diff --git a/src/Kestrel/ServerFactory.cs b/src/Kestrel/ServerFactory.cs index ca56d63653..87ac6c4ee0 100644 --- a/src/Kestrel/ServerFactory.cs +++ b/src/Kestrel/ServerFactory.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; diff --git a/src/Kestrel/ServerInformation.cs b/src/Kestrel/ServerInformation.cs index 852ec6a4c4..075491d992 100644 --- a/src/Kestrel/ServerInformation.cs +++ b/src/Kestrel/ServerInformation.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; diff --git a/src/Kestrel/ServerRequest.cs b/src/Kestrel/ServerRequest.cs index 5c3ffc10ff..7d1f221638 100644 --- a/src/Kestrel/ServerRequest.cs +++ b/src/Kestrel/ServerRequest.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs index b159b251f1..36de9ce5ca 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs index bf682a7075..8761f0c64f 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameDuplexStream.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameDuplexStream.cs index 661c9ec59f..98d09be383 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameDuplexStream.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameDuplexStream.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameRequestStream.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameRequestStream.cs index 645a7afb12..47873ea1d1 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameRequestStream.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameRequestStream.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameResponseStream.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameResponseStream.cs index 2ee9f27f32..3309579449 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameResponseStream.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameResponseStream.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs index 5bc7ebdeaf..5a2752709d 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using Microsoft.AspNet.Server.Kestrel.Networking; diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/MemoryPool.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/MemoryPool.cs index 3b7c247a1c..20e7b870bc 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/MemoryPool.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/MemoryPool.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/MemoryPoolTextWriter.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/MemoryPoolTextWriter.cs index 54763a0e26..3a7d3ef215 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/MemoryPoolTextWriter.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/MemoryPoolTextWriter.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/MessageBody.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/MessageBody.cs index a77bda0f6b..2c22d5b57f 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/MessageBody.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/MessageBody.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/MessageBodyExchanger.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/MessageBodyExchanger.cs index df1dc29309..c84c5e17ec 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/MessageBodyExchanger.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/MessageBodyExchanger.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/ReasonPhrases.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/ReasonPhrases.cs index 33076d1505..8406449709 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/ReasonPhrases.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/ReasonPhrases.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Globalization; diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketInput.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketInput.cs index 69e5ca2eda..405ec68009 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketInput.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketInput.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs index 9b6e9fa52c..9ab5eea89a 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using Microsoft.AspNet.Server.Kestrel.Networking; diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/Disposable.cs b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/Disposable.cs index 8e61adb824..8bb2520792 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/Disposable.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/Disposable.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs index 3b6b885df1..5807898bb2 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using Microsoft.AspNet.Server.Kestrel.Networking; diff --git a/src/Microsoft.AspNet.Server.Kestrel/KestrelEngine.cs b/src/Microsoft.AspNet.Server.Kestrel/KestrelEngine.cs index 31861d023a..ae0c87590d 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/KestrelEngine.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/KestrelEngine.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/Libuv.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/Libuv.cs index 977fb18260..eb77481ed2 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/Libuv.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/Libuv.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/PlatformApis.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/PlatformApis.cs index 8bbb9df28a..8eeee2f719 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/PlatformApis.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/PlatformApis.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/UcAsyncHandle.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/UcAsyncHandle.cs index 31e8f9b054..bc8addba09 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/UcAsyncHandle.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/UcAsyncHandle.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvHandle.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvHandle.cs index fe12f19330..98a0f1e077 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvHandle.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvHandle.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvLoopHandle.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvLoopHandle.cs index a13ae2ccce..c6ad9c7f6c 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvLoopHandle.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvLoopHandle.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvMemory.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvMemory.cs index c3b3c6ce28..d1f07627bf 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvMemory.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvMemory.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. #define TRACE using System; diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvShutdownReq.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvShutdownReq.cs index ef280549c8..815350d3cc 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvShutdownReq.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvShutdownReq.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvStreamHandle.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvStreamHandle.cs index e9f9279f16..4ed7b4781a 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvStreamHandle.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvStreamHandle.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvTcpHandle.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvTcpHandle.cs index e3f90ad846..39d2a8a435 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvTcpHandle.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvTcpHandle.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvWriteRequest.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvWriteRequest.cs index dc58e5688f..4696912db2 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvWriteRequest.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvWriteRequest.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; diff --git a/src/Microsoft.AspNet.Server.Kestrel/Properties/AssemblyInfo.cs b/src/Microsoft.AspNet.Server.Kestrel/Properties/AssemblyInfo.cs index f5c6f4a83a..025a94598c 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Properties/AssemblyInfo.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Properties/AssemblyInfo.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Reflection; diff --git a/test/Microsoft.AspNet.Server.KestrelTests/NetworkingTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/NetworkingTests.cs index cca8bb0f4d..3e549f53a8 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/NetworkingTests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/NetworkingTests.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using Microsoft.AspNet.Server.Kestrel; From bff13b2e9bae0986c711989dc95c5aed3097e3af Mon Sep 17 00:00:00 2001 From: Chris R Date: Thu, 7 May 2015 13:43:34 -0700 Subject: [PATCH 0115/1662] React to Http namespace changes. --- src/Kestrel/ServerRequest.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Kestrel/ServerRequest.cs b/src/Kestrel/ServerRequest.cs index 7d1f221638..eb65c5281f 100644 --- a/src/Kestrel/ServerRequest.cs +++ b/src/Kestrel/ServerRequest.cs @@ -7,7 +7,7 @@ using System.IO; using System.Linq; using System.Threading.Tasks; using Microsoft.AspNet.FeatureModel; -using Microsoft.AspNet.Http; +using Microsoft.AspNet.Http.Features; using Microsoft.AspNet.Server.Kestrel.Http; namespace Kestrel From 72e88864af8f3efba18997be6ecf21f8545ddc94 Mon Sep 17 00:00:00 2001 From: Eilon Lipton Date: Tue, 12 May 2015 11:48:17 -0700 Subject: [PATCH 0116/1662] Update Home master -> Home dev --- CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index eac4268e4c..64ff041d5c 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,4 +1,4 @@ Contributing ====== -Information on contributing to this repo is in the [Contributing Guide](https://github.com/aspnet/Home/blob/master/CONTRIBUTING.md) in the Home repo. +Information on contributing to this repo is in the [Contributing Guide](https://github.com/aspnet/Home/blob/dev/CONTRIBUTING.md) in the Home repo. From 7e78374053aee142b34788ed50db721d297c63ac Mon Sep 17 00:00:00 2001 From: Kirthi Krishnamraju Date: Wed, 20 May 2015 17:26:00 -0700 Subject: [PATCH 0117/1662] React to aspnet/Configuration #195,#198 --- src/Kestrel/ServerFactory.cs | 2 +- src/Kestrel/ServerInformation.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Kestrel/ServerFactory.cs b/src/Kestrel/ServerFactory.cs index 87ac6c4ee0..dbe91f9e06 100644 --- a/src/Kestrel/ServerFactory.cs +++ b/src/Kestrel/ServerFactory.cs @@ -7,7 +7,7 @@ using System.Threading.Tasks; using Microsoft.AspNet.FeatureModel; using Microsoft.AspNet.Hosting.Server; using Microsoft.AspNet.Server.Kestrel; -using Microsoft.Framework.ConfigurationModel; +using Microsoft.Framework.Configuration; using Microsoft.Framework.Runtime; namespace Kestrel diff --git a/src/Kestrel/ServerInformation.cs b/src/Kestrel/ServerInformation.cs index 075491d992..7df85df587 100644 --- a/src/Kestrel/ServerInformation.cs +++ b/src/Kestrel/ServerInformation.cs @@ -5,7 +5,7 @@ using System; using System.Collections.Generic; using System.Globalization; using Microsoft.AspNet.Hosting.Server; -using Microsoft.Framework.ConfigurationModel; +using Microsoft.Framework.Configuration; namespace Kestrel { From 3418116a9c5da44796a2ee4799b7e7145e4afdee Mon Sep 17 00:00:00 2001 From: Pranav K Date: Wed, 27 May 2015 16:32:17 -0700 Subject: [PATCH 0118/1662] Updating to release NuGet.config --- NuGet.Config | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/NuGet.Config b/NuGet.Config index da57d47267..0e74a4912d 100644 --- a/NuGet.Config +++ b/NuGet.Config @@ -1,7 +1,8 @@  - + + - \ No newline at end of file + From de72acc2ca05d192d3d45e4281d65d771513ed85 Mon Sep 17 00:00:00 2001 From: Chris R Date: Fri, 5 Jun 2015 15:28:19 -0700 Subject: [PATCH 0119/1662] Update test Socket dependency --- test/Microsoft.AspNet.Server.KestrelTests/project.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Microsoft.AspNet.Server.KestrelTests/project.json b/test/Microsoft.AspNet.Server.KestrelTests/project.json index 8d1e6a4443..ea63991f94 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/project.json +++ b/test/Microsoft.AspNet.Server.KestrelTests/project.json @@ -8,7 +8,7 @@ "dnx451": { }, "dnxcore50": { "dependencies": { - "System.Net.Sockets": "4.0.0-beta-*", + "System.Net.Sockets": "4.0.10-beta-*", "System.Runtime.Handles": "4.0.0-beta-*", "System.IO": "4.0.10-beta-*" } From 148723acc2422316587d0290e9da2a3b993e3165 Mon Sep 17 00:00:00 2001 From: Chris R Date: Fri, 5 Jun 2015 15:28:19 -0700 Subject: [PATCH 0120/1662] Update test Socket dependency --- test/Microsoft.AspNet.Server.KestrelTests/project.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Microsoft.AspNet.Server.KestrelTests/project.json b/test/Microsoft.AspNet.Server.KestrelTests/project.json index 8d1e6a4443..ea63991f94 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/project.json +++ b/test/Microsoft.AspNet.Server.KestrelTests/project.json @@ -8,7 +8,7 @@ "dnx451": { }, "dnxcore50": { "dependencies": { - "System.Net.Sockets": "4.0.0-beta-*", + "System.Net.Sockets": "4.0.10-beta-*", "System.Runtime.Handles": "4.0.0-beta-*", "System.IO": "4.0.10-beta-*" } From b43e5940e5c326bc17cdb88bbfb5db5989079349 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Thu, 11 Jun 2015 16:56:33 -0700 Subject: [PATCH 0121/1662] Gracefully shutdown even when there are open connections --- .gitignore | 1 + .../Infrastructure/KestrelThread.cs | 35 +++++++++++++------ .../{UcAsyncHandle.cs => UvAsyncHandle.cs} | 0 .../Networking/UvHandle.cs | 7 ++-- 4 files changed, 30 insertions(+), 13 deletions(-) rename src/Microsoft.AspNet.Server.Kestrel/Networking/{UcAsyncHandle.cs => UvAsyncHandle.cs} (100%) diff --git a/.gitignore b/.gitignore index 5de40f3cd7..0042f1e9e0 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,7 @@ _ReSharper.*/ packages/ artifacts/ PublishProfiles/ +.vs/ *.user *.suo *.cache diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs index 5807898bb2..e24b4e1f12 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs @@ -53,12 +53,16 @@ namespace Microsoft.AspNet.Server.Kestrel Post(OnStop, null); if (!_thread.Join((int)timeout.TotalMilliseconds)) { - Post(OnStopImmediate, null); + Post(OnStopRude, null); if (!_thread.Join((int)timeout.TotalMilliseconds)) { + Post(OnStopImmediate, null); + if (!_thread.Join((int)timeout.TotalMilliseconds)) + { #if DNX451 - _thread.Abort(); + _thread.Abort(); #endif + } } } if (_closeError != null) @@ -72,6 +76,21 @@ namespace Microsoft.AspNet.Server.Kestrel _post.Unreference(); } + private void OnStopRude(object obj) + { + _engine.Libuv.walk( + _loop, + (ptr, arg) => + { + var handle = UvMemory.FromIntPtr(ptr); + if (handle != _post) + { + handle.Dispose(); + } + }, + IntPtr.Zero); + } + private void OnStopImmediate(object obj) { _stopImmediate = true; @@ -133,14 +152,8 @@ namespace Microsoft.AspNet.Server.Kestrel // run the loop one more time to delete the open handles _post.Reference(); _post.DangerousClose(); - _engine.Libuv.walk( - _loop, - (ptr, arg) => - { - var handle = UvMemory.FromIntPtr(ptr); - handle.Dispose(); - }, - IntPtr.Zero); + + // Ensure the "DangerousClose" operation completes in the event loop. var ran2 = _loop.Run(); _loop.Dispose(); @@ -203,7 +216,7 @@ namespace Microsoft.AspNet.Server.Kestrel queue = _closeHandleAdding; _closeHandleAdding = _closeHandleRunning; _closeHandleRunning = queue; - } + } while (queue.Count != 0) { var closeHandle = queue.Dequeue(); diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/UcAsyncHandle.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvAsyncHandle.cs similarity index 100% rename from src/Microsoft.AspNet.Server.Kestrel/Networking/UcAsyncHandle.cs rename to src/Microsoft.AspNet.Server.Kestrel/Networking/UvAsyncHandle.cs diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvHandle.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvHandle.cs index 98a0f1e077..4c9f23aec1 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvHandle.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvHandle.cs @@ -32,9 +32,12 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking { _uv.close(memory, _destroyMemory); } - else + else if (_queueCloseHandle != null) { - _queueCloseHandle(memory2 => _uv.close(memory2, _destroyMemory), memory); + // This can be called from the finalizer. + // Ensure the closure doesn't reference "this". + var uv = _uv; + _queueCloseHandle(memory2 => uv.close(memory2, _destroyMemory), memory); } } return true; From 106edf8c86e12e3c7be6fad38cd6f64393baae70 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Fri, 12 Jun 2015 12:49:52 -0700 Subject: [PATCH 0122/1662] Ensure all handles still get released after graceful shutdown --- .../Infrastructure/KestrelThread.cs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs index e24b4e1f12..821a8216da 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs @@ -153,6 +153,18 @@ namespace Microsoft.AspNet.Server.Kestrel _post.Reference(); _post.DangerousClose(); + _engine.Libuv.walk( + _loop, + (ptr, arg) => + { + var handle = UvMemory.FromIntPtr(ptr); + if (handle != _post) + { + handle.Dispose(); + } + }, + IntPtr.Zero); + // Ensure the "DangerousClose" operation completes in the event loop. var ran2 = _loop.Run(); From 08c0bbbd601784bffc851e7ffae0d88028e6ab4a Mon Sep 17 00:00:00 2001 From: Chris R Date: Fri, 12 Jun 2015 15:05:45 -0700 Subject: [PATCH 0123/1662] React to OnSendingHeaders rename. --- src/Kestrel/ServerRequest.cs | 8 ++-- .../Http/Frame.cs | 38 +++++++++---------- 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/src/Kestrel/ServerRequest.cs b/src/Kestrel/ServerRequest.cs index eb65c5281f..47d9905afb 100644 --- a/src/Kestrel/ServerRequest.cs +++ b/src/Kestrel/ServerRequest.cs @@ -194,14 +194,14 @@ namespace Kestrel } } - bool IHttpResponseFeature.HeadersSent + bool IHttpResponseFeature.HasStarted { - get { return _frame.HeadersSent; } + get { return _frame.HasResponseStarted; } } - void IHttpResponseFeature.OnSendingHeaders(Action callback, object state) + void IHttpResponseFeature.OnResponseStarting(Action callback, object state) { - _frame.OnSendingHeaders(callback, state); + _frame.OnResponseStarting(callback, state); } void IHttpResponseFeature.OnResponseCompleted(Action callback, object state) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs index 8761f0c64f..3a9277f85c 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs @@ -54,7 +54,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http Mode _mode; private bool _resultStarted; - private bool _headersSent; + private bool _responseStarted; private bool _keepAlive; /* @@ -63,9 +63,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Http CancellationTokenSource _cts = new CancellationTokenSource(); */ - List, object>> _onSendingHeaders; + List, object>> _onResponseStarting; List, object>> _onResponseCompleted; - object _onSendingHeadersSync = new Object(); + object _onResponseStartingSync = new Object(); object _onResponseCompletedSync = new Object(); public Frame(ConnectionContext context) : base(context) @@ -92,9 +92,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Http public Stream DuplexStream { get; set; } - public bool HeadersSent + public bool HasResponseStarted { - get { return _headersSent; } + get { return _responseStarted; } } @@ -190,15 +190,15 @@ namespace Microsoft.AspNet.Server.Kestrel.Http Task.Run(ExecuteAsync); } - public void OnSendingHeaders(Action callback, object state) + public void OnResponseStarting(Action callback, object state) { - lock (_onSendingHeadersSync) + lock (_onResponseStartingSync) { - if (_onSendingHeaders == null) + if (_onResponseStarting == null) { - _onSendingHeaders = new List, object>>(); + _onResponseStarting = new List, object>>(); } - _onSendingHeaders.Add(new KeyValuePair, object>(callback, state)); + _onResponseStarting.Add(new KeyValuePair, object>(callback, state)); } } @@ -214,17 +214,17 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } - private void FireOnSendingHeaders() + private void FireOnResponseStarting() { - List, object>> onSendingHeaders = null; - lock (_onSendingHeadersSync) + List, object>> onResponseStarting = null; + lock (_onResponseStartingSync) { - onSendingHeaders = _onSendingHeaders; - _onSendingHeaders = null; + onResponseStarting = _onResponseStarting; + _onResponseStarting = null; } - if (onSendingHeaders != null) + if (onResponseStarting != null) { - foreach (var entry in onSendingHeaders) + foreach (var entry in onResponseStarting) { entry.Key.Invoke(entry.Value); } @@ -318,9 +318,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Http if (_resultStarted) return; _resultStarted = true; - FireOnSendingHeaders(); + FireOnResponseStarting(); - _headersSent = true; + _responseStarted = true; var status = ReasonPhrases.ToStatus(StatusCode, ReasonPhrase); From 7e125faa7360d616d12477c92c6fde0ed5c6ce26 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Fri, 12 Jun 2015 17:01:33 -0700 Subject: [PATCH 0124/1662] Dispatch user defined callback so it can't block the event loop --- .../Http/SocketOutput.cs | 47 +++++++++---------- 1 file changed, 23 insertions(+), 24 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs index 9ab5eea89a..531fc65858 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs @@ -4,6 +4,7 @@ using Microsoft.AspNet.Server.Kestrel.Networking; using System; using System.Runtime.InteropServices; +using System.Threading; namespace Microsoft.AspNet.Server.Kestrel.Http { @@ -37,25 +38,17 @@ namespace Microsoft.AspNet.Server.Kestrel.Http var req = new ThisWriteReq(); req.Init(_thread.Loop); req.Contextualize(this, _socket, buffer, callback, state); - _thread.Post(x => - { - ((ThisWriteReq)x).Write(); - }, req); + req.Write(); } public class ThisWriteReq : UvWriteReq { - private static readonly Action _writeCallback = WriteCallback; - private static void WriteCallback(UvWriteReq req, int status, Exception error, object state) - { - ((ThisWriteReq)state).OnWrite(req, status, error); - } - SocketOutput _self; ArraySegment _buffer; UvStreamHandle _socket; Action _callback; object _state; + Exception _callbackError; internal void Contextualize( SocketOutput socketOutput, @@ -73,27 +66,33 @@ namespace Microsoft.AspNet.Server.Kestrel.Http public void Write() { - Write( - _socket, - new ArraySegment>( - new[]{_buffer}), - _writeCallback, - this); + _self._thread.Post(obj => + { + var req = (ThisWriteReq)obj; + req.Write( + req._socket, + new ArraySegment>( + new[] { req._buffer }), + (r, status, error, state) => ((ThisWriteReq)state).OnWrite(status, error), + req); + }, this); } - private void OnWrite(UvWriteReq req, int status, Exception error) + private void OnWrite(int status, Exception error) { KestrelTrace.Log.ConnectionWriteCallback(0, status); //NOTE: pool this? - var callback = _callback; - _callback = null; - var state = _state; - _state = null; - Dispose(); - callback(error, state); - } + + // Get off the event loop before calling user code! + _callbackError = error; + ThreadPool.QueueUserWorkItem(obj => + { + var req = (ThisWriteReq)obj; + req._callback(req._callbackError, req._state); + }, this); + } } From 5c6a53c4911cddf05e02a5f97c5cf06fcae3eb90 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Fri, 12 Jun 2015 17:01:48 -0700 Subject: [PATCH 0125/1662] Dispose Listeners if they fail to start --- .../KestrelEngine.cs | 26 ++++++++++++++----- 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/KestrelEngine.cs b/src/Microsoft.AspNet.Server.Kestrel/KestrelEngine.cs index ae0c87590d..21b4df4523 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/KestrelEngine.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/KestrelEngine.cs @@ -91,19 +91,33 @@ namespace Microsoft.AspNet.Server.Kestrel public IDisposable CreateServer(string scheme, string host, int port, Func application) { var listeners = new List(); - foreach (var thread in Threads) + + try { - var listener = new Listener(Memory); - listener.StartAsync(scheme, host, port, thread, application).Wait(); - listeners.Add(listener); + foreach (var thread in Threads) + { + var listener = new Listener(Memory); + + listeners.Add(listener); + listener.StartAsync(scheme, host, port, thread, application).Wait(); + } + return new Disposable(() => + { + foreach (var listener in listeners) + { + listener.Dispose(); + } + }); } - return new Disposable(() => + catch { foreach (var listener in listeners) { listener.Dispose(); } - }); + + throw; + } } } } From 31057f65bc671aa1bba853befb6bb4c171987d5b Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Thu, 11 Jun 2015 16:56:33 -0700 Subject: [PATCH 0126/1662] Gracefully shutdown even when there are open connections --- .gitignore | 1 + .../Infrastructure/KestrelThread.cs | 35 +++++++++++++------ .../{UcAsyncHandle.cs => UvAsyncHandle.cs} | 0 .../Networking/UvHandle.cs | 7 ++-- 4 files changed, 30 insertions(+), 13 deletions(-) rename src/Microsoft.AspNet.Server.Kestrel/Networking/{UcAsyncHandle.cs => UvAsyncHandle.cs} (100%) diff --git a/.gitignore b/.gitignore index 5de40f3cd7..0042f1e9e0 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,7 @@ _ReSharper.*/ packages/ artifacts/ PublishProfiles/ +.vs/ *.user *.suo *.cache diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs index 5807898bb2..e24b4e1f12 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs @@ -53,12 +53,16 @@ namespace Microsoft.AspNet.Server.Kestrel Post(OnStop, null); if (!_thread.Join((int)timeout.TotalMilliseconds)) { - Post(OnStopImmediate, null); + Post(OnStopRude, null); if (!_thread.Join((int)timeout.TotalMilliseconds)) { + Post(OnStopImmediate, null); + if (!_thread.Join((int)timeout.TotalMilliseconds)) + { #if DNX451 - _thread.Abort(); + _thread.Abort(); #endif + } } } if (_closeError != null) @@ -72,6 +76,21 @@ namespace Microsoft.AspNet.Server.Kestrel _post.Unreference(); } + private void OnStopRude(object obj) + { + _engine.Libuv.walk( + _loop, + (ptr, arg) => + { + var handle = UvMemory.FromIntPtr(ptr); + if (handle != _post) + { + handle.Dispose(); + } + }, + IntPtr.Zero); + } + private void OnStopImmediate(object obj) { _stopImmediate = true; @@ -133,14 +152,8 @@ namespace Microsoft.AspNet.Server.Kestrel // run the loop one more time to delete the open handles _post.Reference(); _post.DangerousClose(); - _engine.Libuv.walk( - _loop, - (ptr, arg) => - { - var handle = UvMemory.FromIntPtr(ptr); - handle.Dispose(); - }, - IntPtr.Zero); + + // Ensure the "DangerousClose" operation completes in the event loop. var ran2 = _loop.Run(); _loop.Dispose(); @@ -203,7 +216,7 @@ namespace Microsoft.AspNet.Server.Kestrel queue = _closeHandleAdding; _closeHandleAdding = _closeHandleRunning; _closeHandleRunning = queue; - } + } while (queue.Count != 0) { var closeHandle = queue.Dequeue(); diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/UcAsyncHandle.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvAsyncHandle.cs similarity index 100% rename from src/Microsoft.AspNet.Server.Kestrel/Networking/UcAsyncHandle.cs rename to src/Microsoft.AspNet.Server.Kestrel/Networking/UvAsyncHandle.cs diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvHandle.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvHandle.cs index 98a0f1e077..4c9f23aec1 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvHandle.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvHandle.cs @@ -32,9 +32,12 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking { _uv.close(memory, _destroyMemory); } - else + else if (_queueCloseHandle != null) { - _queueCloseHandle(memory2 => _uv.close(memory2, _destroyMemory), memory); + // This can be called from the finalizer. + // Ensure the closure doesn't reference "this". + var uv = _uv; + _queueCloseHandle(memory2 => uv.close(memory2, _destroyMemory), memory); } } return true; From adc03104916968ef7958fc051f0ddd92f885118c Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Fri, 12 Jun 2015 12:49:52 -0700 Subject: [PATCH 0127/1662] Ensure all handles still get released after graceful shutdown --- .../Infrastructure/KestrelThread.cs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs index e24b4e1f12..821a8216da 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs @@ -153,6 +153,18 @@ namespace Microsoft.AspNet.Server.Kestrel _post.Reference(); _post.DangerousClose(); + _engine.Libuv.walk( + _loop, + (ptr, arg) => + { + var handle = UvMemory.FromIntPtr(ptr); + if (handle != _post) + { + handle.Dispose(); + } + }, + IntPtr.Zero); + // Ensure the "DangerousClose" operation completes in the event loop. var ran2 = _loop.Run(); From a992c785487271a9c60f079d53e0dc8bf122a70a Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Fri, 12 Jun 2015 17:01:33 -0700 Subject: [PATCH 0128/1662] Dispatch user defined callback so it can't block the event loop --- .../Http/SocketOutput.cs | 47 +++++++++---------- 1 file changed, 23 insertions(+), 24 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs index 9ab5eea89a..531fc65858 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs @@ -4,6 +4,7 @@ using Microsoft.AspNet.Server.Kestrel.Networking; using System; using System.Runtime.InteropServices; +using System.Threading; namespace Microsoft.AspNet.Server.Kestrel.Http { @@ -37,25 +38,17 @@ namespace Microsoft.AspNet.Server.Kestrel.Http var req = new ThisWriteReq(); req.Init(_thread.Loop); req.Contextualize(this, _socket, buffer, callback, state); - _thread.Post(x => - { - ((ThisWriteReq)x).Write(); - }, req); + req.Write(); } public class ThisWriteReq : UvWriteReq { - private static readonly Action _writeCallback = WriteCallback; - private static void WriteCallback(UvWriteReq req, int status, Exception error, object state) - { - ((ThisWriteReq)state).OnWrite(req, status, error); - } - SocketOutput _self; ArraySegment _buffer; UvStreamHandle _socket; Action _callback; object _state; + Exception _callbackError; internal void Contextualize( SocketOutput socketOutput, @@ -73,27 +66,33 @@ namespace Microsoft.AspNet.Server.Kestrel.Http public void Write() { - Write( - _socket, - new ArraySegment>( - new[]{_buffer}), - _writeCallback, - this); + _self._thread.Post(obj => + { + var req = (ThisWriteReq)obj; + req.Write( + req._socket, + new ArraySegment>( + new[] { req._buffer }), + (r, status, error, state) => ((ThisWriteReq)state).OnWrite(status, error), + req); + }, this); } - private void OnWrite(UvWriteReq req, int status, Exception error) + private void OnWrite(int status, Exception error) { KestrelTrace.Log.ConnectionWriteCallback(0, status); //NOTE: pool this? - var callback = _callback; - _callback = null; - var state = _state; - _state = null; - Dispose(); - callback(error, state); - } + + // Get off the event loop before calling user code! + _callbackError = error; + ThreadPool.QueueUserWorkItem(obj => + { + var req = (ThisWriteReq)obj; + req._callback(req._callbackError, req._state); + }, this); + } } From 1592459a0bc53d1b0efc107f4b25ce9e44eb9cc0 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Fri, 12 Jun 2015 17:01:48 -0700 Subject: [PATCH 0129/1662] Dispose Listeners if they fail to start --- .../KestrelEngine.cs | 26 ++++++++++++++----- 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/KestrelEngine.cs b/src/Microsoft.AspNet.Server.Kestrel/KestrelEngine.cs index ae0c87590d..21b4df4523 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/KestrelEngine.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/KestrelEngine.cs @@ -91,19 +91,33 @@ namespace Microsoft.AspNet.Server.Kestrel public IDisposable CreateServer(string scheme, string host, int port, Func application) { var listeners = new List(); - foreach (var thread in Threads) + + try { - var listener = new Listener(Memory); - listener.StartAsync(scheme, host, port, thread, application).Wait(); - listeners.Add(listener); + foreach (var thread in Threads) + { + var listener = new Listener(Memory); + + listeners.Add(listener); + listener.StartAsync(scheme, host, port, thread, application).Wait(); + } + return new Disposable(() => + { + foreach (var listener in listeners) + { + listener.Dispose(); + } + }); } - return new Disposable(() => + catch { foreach (var listener in listeners) { listener.Dispose(); } - }); + + throw; + } } } } From 29098d63836d0dfc6373ecd84ff1035c9cda6476 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Wed, 17 Jun 2015 17:53:56 -0700 Subject: [PATCH 0130/1662] Fix UvLoopHandle.ReleaseHandle on linux Libuv.loop_close can clear the GCHandle pointer on linux --- .../Networking/UvLoopHandle.cs | 9 ++++++--- .../Networking/UvMemory.cs | 5 +++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvLoopHandle.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvLoopHandle.cs index c6ad9c7f6c..f0f3d454b1 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvLoopHandle.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvLoopHandle.cs @@ -28,17 +28,20 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking _uv.stop(this); } - protected override bool ReleaseHandle() + unsafe protected override bool ReleaseHandle() { var memory = this.handle; if (memory != IntPtr.Zero) { + // loop_close clears the gcHandlePtr + var gcHandlePtr = *(IntPtr*)memory; + _uv.loop_close(this); handle = IntPtr.Zero; - DestroyMemory(memory); + + DestroyMemory(memory, gcHandlePtr); } return true; } - } } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvMemory.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvMemory.cs index d1f07627bf..37e75ef537 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvMemory.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvMemory.cs @@ -54,6 +54,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking unsafe protected static void DestroyMemory(IntPtr memory) { var gcHandlePtr = *(IntPtr*)memory; + DestroyMemory(memory, gcHandlePtr); + } + + unsafe protected static void DestroyMemory(IntPtr memory, IntPtr gcHandlePtr) + { if (gcHandlePtr != IntPtr.Zero) { var gcHandle = GCHandle.FromIntPtr(gcHandlePtr); From ea09b9b339a8da30b1ef542e40944297add1b460 Mon Sep 17 00:00:00 2001 From: Hisham Abdullah Bin Ateya Date: Sat, 20 Jun 2015 23:31:36 +0300 Subject: [PATCH 0131/1662] Add AppVeyor, Travis build status --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 62ee846848..a43c71f919 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,10 @@ KestrelHttpServer ================= +AppVeyor: [![AppVeyor](https://ci.appveyor.com/api/projects/status/nr0s92ykm57q0bjv/branch/dev?svg=true)](https://ci.appveyor.com/project/aspnetci/KestrelHttpServer/branch/dev) + +Travis: [![Travis](https://travis-ci.org/aspnet/KestrelHttpServer.svg?branch=dev)](https://travis-ci.org/aspnet/KestrelHttpServer) + This repo contains a development web server for ASP.NET 5 based on [libuv](https://github.com/libuv/libuv). This project is part of ASP.NET 5. You can find samples, documentation and getting started instructions for ASP.NET 5 at the [Home](https://github.com/aspnet/home) repo. From 14c4f4635944d2a6814c1da310caf67aeb1b2fcf Mon Sep 17 00:00:00 2001 From: Doug Bunting Date: Tue, 23 Jun 2015 11:00:06 -0700 Subject: [PATCH 0132/1662] Change hardcoded `bash` shebang to `env` - aspnet/Home#695 - support various `bash` installation locations - in particular, enable building on FreeBSD --- build.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.sh b/build.sh index d81164353c..3ef874f9bd 100755 --- a/build.sh +++ b/build.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash if test `uname` = Darwin; then cachedir=~/Library/Caches/KBuild From f724fefbda83e1ece95b8b5ef390e52e737e5d7b Mon Sep 17 00:00:00 2001 From: Hao Kung Date: Thu, 25 Jun 2015 17:28:07 -0700 Subject: [PATCH 0133/1662] React to HttpChanges --- src/Kestrel/ServerRequest.cs | 8 +-- .../Http/Frame.cs | 60 +++++++++---------- 2 files changed, 34 insertions(+), 34 deletions(-) diff --git a/src/Kestrel/ServerRequest.cs b/src/Kestrel/ServerRequest.cs index 47d9905afb..5edfda327d 100644 --- a/src/Kestrel/ServerRequest.cs +++ b/src/Kestrel/ServerRequest.cs @@ -199,14 +199,14 @@ namespace Kestrel get { return _frame.HasResponseStarted; } } - void IHttpResponseFeature.OnResponseStarting(Action callback, object state) + void IHttpResponseFeature.OnStarting(Func callback, object state) { - _frame.OnResponseStarting(callback, state); + _frame.OnStarting(callback, state); } - void IHttpResponseFeature.OnResponseCompleted(Action callback, object state) + void IHttpResponseFeature.OnCompleted(Func callback, object state) { - _frame.OnResponseCompleted(callback, state); + _frame.OnCompleted(callback, state); } bool IHttpUpgradeFeature.IsUpgradableRequest diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs index 3a9277f85c..1b86736968 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs @@ -63,10 +63,10 @@ namespace Microsoft.AspNet.Server.Kestrel.Http CancellationTokenSource _cts = new CancellationTokenSource(); */ - List, object>> _onResponseStarting; - List, object>> _onResponseCompleted; - object _onResponseStartingSync = new Object(); - object _onResponseCompletedSync = new Object(); + List, object>> _onStarting; + List, object>> _onCompleted; + object _onStartingSync = new Object(); + object _onCompletedSync = new Object(); public Frame(ConnectionContext context) : base(context) { @@ -190,58 +190,58 @@ namespace Microsoft.AspNet.Server.Kestrel.Http Task.Run(ExecuteAsync); } - public void OnResponseStarting(Action callback, object state) + public void OnStarting(Func callback, object state) { - lock (_onResponseStartingSync) + lock (_onStartingSync) { - if (_onResponseStarting == null) + if (_onStarting == null) { - _onResponseStarting = new List, object>>(); + _onStarting = new List, object>>(); } - _onResponseStarting.Add(new KeyValuePair, object>(callback, state)); + _onStarting.Add(new KeyValuePair, object>(callback, state)); } } - public void OnResponseCompleted(Action callback, object state) + public void OnCompleted(Func callback, object state) { - lock (_onResponseCompletedSync) + lock (_onCompletedSync) { - if (_onResponseCompleted == null) + if (_onCompleted == null) { - _onResponseCompleted = new List, object>>(); + _onCompleted = new List, object>>(); } - _onResponseCompleted.Add(new KeyValuePair, object>(callback, state)); + _onCompleted.Add(new KeyValuePair, object>(callback, state)); } } - private void FireOnResponseStarting() + private void FireOnStarting() { - List, object>> onResponseStarting = null; - lock (_onResponseStartingSync) + List, object>> onStarting = null; + lock (_onStartingSync) { - onResponseStarting = _onResponseStarting; - _onResponseStarting = null; + onStarting = _onStarting; + _onStarting = null; } - if (onResponseStarting != null) + if (onStarting != null) { - foreach (var entry in onResponseStarting) + foreach (var entry in onStarting) { entry.Key.Invoke(entry.Value); } } } - private void FireOnResponseCompleted() + private void FireOnCompleted() { - List, object>> onResponseCompleted = null; - lock (_onResponseCompletedSync) + List, object>> onCompleted = null; + lock (_onCompletedSync) { - onResponseCompleted = _onResponseCompleted; - _onResponseCompleted = null; + onCompleted = _onCompleted; + _onCompleted = null; } - if (onResponseCompleted != null) + if (onCompleted != null) { - foreach (var entry in onResponseCompleted) + foreach (var entry in onCompleted) { try { @@ -268,7 +268,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } finally { - FireOnResponseCompleted(); + FireOnCompleted(); ProduceEnd(error); } } @@ -318,7 +318,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http if (_resultStarted) return; _resultStarted = true; - FireOnResponseStarting(); + FireOnStarting(); _responseStarted = true; From fd038b7b913ec8094fa2d8b9daeea2979a073481 Mon Sep 17 00:00:00 2001 From: Victor Hurdugaci Date: Wed, 1 Jul 2015 20:13:32 -0700 Subject: [PATCH 0134/1662] Add repository information to project files --- src/Kestrel/project.json | 4 ++++ src/Microsoft.AspNet.Server.Kestrel/project.json | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/src/Kestrel/project.json b/src/Kestrel/project.json index 8b6eb1c2d9..eb2037ca21 100644 --- a/src/Kestrel/project.json +++ b/src/Kestrel/project.json @@ -1,6 +1,10 @@ { "version": "1.0.0-*", "description": "ASP.NET 5 cross platform development web server.", + "repository": { + "type": "git", + "url": "git://github.com/aspnet/kestrelhttpserver" + }, "dependencies": { "Microsoft.AspNet.Hosting": "1.0.0-*", "Microsoft.AspNet.Server.Kestrel": "1.0.0-*" diff --git a/src/Microsoft.AspNet.Server.Kestrel/project.json b/src/Microsoft.AspNet.Server.Kestrel/project.json index a9bdf0f6d6..35f11ed90e 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/project.json +++ b/src/Microsoft.AspNet.Server.Kestrel/project.json @@ -1,6 +1,10 @@ { "version": "1.0.0-*", "description": "ASP.NET 5 cross platform development web server.", + "repository": { + "type": "git", + "url": "git://github.com/aspnet/kestrelhttpserver" + }, "dependencies": { "Microsoft.Framework.Runtime.Abstractions": "1.0.0-*" }, From 4b66edc4fed5e9702a5b137ffe142a536c21cec6 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Tue, 23 Jun 2015 15:15:13 -0700 Subject: [PATCH 0135/1662] Move non-nested classes and interfaces to their own files --- .../Http/Connection.cs | 31 ------------------ .../Http/ConnectionContext.cs | 25 +++++++++++++++ .../Http/Frame.cs | 29 ----------------- .../Http/FrameContext.cs | 17 ++++++++++ .../Http/IConnectionControl.cs | 9 ++++++ .../Http/IFrameControl.cs | 10 ++++++ .../Http/IMemoryPool.cs | 32 +++++++++++++++++++ .../Http/ISocketOutput.cs | 12 +++++++ .../Http/Listener.cs | 18 ----------- .../Http/ListenerContext.cs | 23 +++++++++++++ .../Http/MemoryPool.cs | 28 ---------------- .../Http/MessageBody.cs | 1 - .../Http/ProduceEndType.cs | 9 ++++++ .../Http/SocketOutput.cs | 9 ------ .../Networking/Libuv.cs | 1 - .../Networking/PlatformApis.cs | 2 -- .../Networking/UvAsyncHandle.cs | 2 +- .../Networking/UvReq.cs | 17 ++++++++++ .../{UvWriteRequest.cs => UvWriteReq.cs} | 13 -------- 19 files changed, 155 insertions(+), 133 deletions(-) create mode 100644 src/Microsoft.AspNet.Server.Kestrel/Http/ConnectionContext.cs create mode 100644 src/Microsoft.AspNet.Server.Kestrel/Http/FrameContext.cs create mode 100644 src/Microsoft.AspNet.Server.Kestrel/Http/IConnectionControl.cs create mode 100644 src/Microsoft.AspNet.Server.Kestrel/Http/IFrameControl.cs create mode 100644 src/Microsoft.AspNet.Server.Kestrel/Http/IMemoryPool.cs create mode 100644 src/Microsoft.AspNet.Server.Kestrel/Http/ISocketOutput.cs create mode 100644 src/Microsoft.AspNet.Server.Kestrel/Http/ListenerContext.cs create mode 100644 src/Microsoft.AspNet.Server.Kestrel/Http/ProduceEndType.cs create mode 100644 src/Microsoft.AspNet.Server.Kestrel/Networking/UvReq.cs rename src/Microsoft.AspNet.Server.Kestrel/Networking/{UvWriteRequest.cs => UvWriteReq.cs} (90%) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs index 36de9ce5ca..a6fd1b40bb 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs @@ -2,42 +2,11 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.Threading.Tasks; using Microsoft.AspNet.Server.Kestrel.Networking; using System.Diagnostics; namespace Microsoft.AspNet.Server.Kestrel.Http { - public class ConnectionContext : ListenerContext - { - public ConnectionContext() - { - } - - public ConnectionContext(ListenerContext context) : base(context) - { - } - - public ConnectionContext(ConnectionContext context) : base(context) - { - SocketInput = context.SocketInput; - SocketOutput = context.SocketOutput; - ConnectionControl = context.ConnectionControl; - } - - public SocketInput SocketInput { get; set; } - public ISocketOutput SocketOutput { get; set; } - - public IConnectionControl ConnectionControl { get; set; } - } - - public interface IConnectionControl - { - void Pause(); - void Resume(); - void End(ProduceEndType endType); - } - public class Connection : ConnectionContext, IConnectionControl { private static readonly Action _readCallback = ReadCallback; diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/ConnectionContext.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/ConnectionContext.cs new file mode 100644 index 0000000000..cedfc63aeb --- /dev/null +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/ConnectionContext.cs @@ -0,0 +1,25 @@ +namespace Microsoft.AspNet.Server.Kestrel.Http +{ + public class ConnectionContext : ListenerContext + { + public ConnectionContext() + { + } + + public ConnectionContext(ListenerContext context) : base(context) + { + } + + public ConnectionContext(ConnectionContext context) : base(context) + { + SocketInput = context.SocketInput; + SocketOutput = context.SocketOutput; + ConnectionControl = context.ConnectionControl; + } + + public SocketInput SocketInput { get; set; } + public ISocketOutput SocketOutput { get; set; } + + public IConnectionControl ConnectionControl { get; set; } + } +} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs index 1b86736968..3ae0d60b6b 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs @@ -13,35 +13,6 @@ using System.Threading.Tasks; namespace Microsoft.AspNet.Server.Kestrel.Http { - - public enum ProduceEndType - { - SocketShutdownSend, - SocketDisconnect, - ConnectionKeepAlive, - } - - public class FrameContext : ConnectionContext - { - public FrameContext() - { - - } - - public FrameContext(ConnectionContext context) : base(context) - { - - } - - public IFrameControl FrameControl { get; set; } - } - - public interface IFrameControl - { - void ProduceContinue(); - void Write(ArraySegment data, Action callback, object state); - } - public class Frame : FrameContext, IFrameControl { enum Mode diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameContext.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameContext.cs new file mode 100644 index 0000000000..dedcb1b41f --- /dev/null +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameContext.cs @@ -0,0 +1,17 @@ +namespace Microsoft.AspNet.Server.Kestrel.Http +{ + public class FrameContext : ConnectionContext + { + public FrameContext() + { + + } + + public FrameContext(ConnectionContext context) : base(context) + { + + } + + public IFrameControl FrameControl { get; set; } + } +} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/IConnectionControl.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/IConnectionControl.cs new file mode 100644 index 0000000000..f0be1f74d6 --- /dev/null +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/IConnectionControl.cs @@ -0,0 +1,9 @@ +namespace Microsoft.AspNet.Server.Kestrel.Http +{ + public interface IConnectionControl + { + void Pause(); + void Resume(); + void End(ProduceEndType endType); + } +} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/IFrameControl.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/IFrameControl.cs new file mode 100644 index 0000000000..3dfab0893a --- /dev/null +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/IFrameControl.cs @@ -0,0 +1,10 @@ +using System; + +namespace Microsoft.AspNet.Server.Kestrel.Http +{ + public interface IFrameControl + { + void ProduceContinue(); + void Write(ArraySegment data, Action callback, object state); + } +} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/IMemoryPool.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/IMemoryPool.cs new file mode 100644 index 0000000000..6e28b4529f --- /dev/null +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/IMemoryPool.cs @@ -0,0 +1,32 @@ +using System; + +namespace Microsoft.AspNet.Server.Kestrel.Http +{ + public interface IMemoryPool + { + byte[] Empty { get; } + + byte[] AllocByte(int minimumSize); + void FreeByte(byte[] memory); + + char[] AllocChar(int minimumSize); + void FreeChar(char[] memory); + + /// + /// Acquires a sub-segment of a larger memory allocation. Used for async sends of write-behind + /// buffers to reduce number of array segments pinned + /// + /// The smallest length of the ArraySegment.Count that may be returned + /// An array segment which is a sub-block of a larger allocation + ArraySegment AllocSegment(int minimumSize); + + /// + /// Frees a sub-segment of a larger memory allocation produced by AllocSegment. The original ArraySegment + /// must be frees exactly once and must have the same offset and count that was returned by the Alloc. + /// If a segment is not freed it won't be re-used and has the same effect as a memory leak, so callers must be + /// implemented exactly correctly. + /// + /// The sub-block that was originally returned by a call to AllocSegment. + void FreeSegment(ArraySegment segment); + } +} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/ISocketOutput.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/ISocketOutput.cs new file mode 100644 index 0000000000..43dd4fb4b2 --- /dev/null +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/ISocketOutput.cs @@ -0,0 +1,12 @@ +using System; + +namespace Microsoft.AspNet.Server.Kestrel.Http +{ + /// + /// Operations performed for buffered socket output + /// + public interface ISocketOutput + { + void Write(ArraySegment buffer, Action callback, object state); + } +} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs index 5a2752709d..b2cf408f75 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs @@ -9,24 +9,6 @@ using System.Threading.Tasks; namespace Microsoft.AspNet.Server.Kestrel.Http { - public class ListenerContext - { - public ListenerContext() { } - - public ListenerContext(ListenerContext context) - { - Thread = context.Thread; - Application = context.Application; - Memory = context.Memory; - } - - public KestrelThread Thread { get; set; } - - public Func Application { get; set; } - - public IMemoryPool Memory { get; set; } - } - /// /// Summary description for Accept /// diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerContext.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerContext.cs new file mode 100644 index 0000000000..a2a4283a46 --- /dev/null +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerContext.cs @@ -0,0 +1,23 @@ +using System; +using System.Threading.Tasks; + +namespace Microsoft.AspNet.Server.Kestrel.Http +{ + public class ListenerContext + { + public ListenerContext() { } + + public ListenerContext(ListenerContext context) + { + Thread = context.Thread; + Application = context.Application; + Memory = context.Memory; + } + + public KestrelThread Thread { get; set; } + + public Func Application { get; set; } + + public IMemoryPool Memory { get; set; } + } +} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/MemoryPool.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/MemoryPool.cs index 20e7b870bc..e08eba68fd 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/MemoryPool.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/MemoryPool.cs @@ -6,34 +6,6 @@ using System.Collections.Generic; namespace Microsoft.AspNet.Server.Kestrel.Http { - public interface IMemoryPool - { - byte[] Empty { get; } - - byte[] AllocByte(int minimumSize); - void FreeByte(byte[] memory); - - char[] AllocChar(int minimumSize); - void FreeChar(char[] memory); - - /// - /// Acquires a sub-segment of a larger memory allocation. Used for async sends of write-behind - /// buffers to reduce number of array segments pinned - /// - /// The smallest length of the ArraySegment.Count that may be returned - /// An array segment which is a sub-block of a larger allocation - ArraySegment AllocSegment(int minimumSize); - - /// - /// Frees a sub-segment of a larger memory allocation produced by AllocSegment. The original ArraySegment - /// must be frees exactly once and must have the same offset and count that was returned by the Alloc. - /// If a segment is not freed it won't be re-used and has the same effect as a memory leak, so callers must be - /// implemented exactly correctly. - /// - /// The sub-block that was originally returned by a call to AllocSegment. - void FreeSegment(ArraySegment segment); - } - public class MemoryPool : IMemoryPool { static readonly byte[] EmptyArray = new byte[0]; diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/MessageBody.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/MessageBody.cs index 2c22d5b57f..b07f10c948 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/MessageBody.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/MessageBody.cs @@ -3,7 +3,6 @@ using System; using System.Collections.Generic; -using System.Threading; namespace Microsoft.AspNet.Server.Kestrel.Http { diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/ProduceEndType.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/ProduceEndType.cs new file mode 100644 index 0000000000..31ea4754cf --- /dev/null +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/ProduceEndType.cs @@ -0,0 +1,9 @@ +namespace Microsoft.AspNet.Server.Kestrel.Http +{ + public enum ProduceEndType + { + SocketShutdownSend, + SocketDisconnect, + ConnectionKeepAlive, + } +} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs index 531fc65858..4c3e4c8cc8 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs @@ -3,19 +3,10 @@ using Microsoft.AspNet.Server.Kestrel.Networking; using System; -using System.Runtime.InteropServices; using System.Threading; namespace Microsoft.AspNet.Server.Kestrel.Http { - /// - /// Operations performed for buffered socket output - /// - public interface ISocketOutput - { - void Write(ArraySegment buffer, Action callback, object state); - } - public class SocketOutput : ISocketOutput { private readonly KestrelThread _thread; diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/Libuv.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/Libuv.cs index eb77481ed2..4a12712d0d 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/Libuv.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/Libuv.cs @@ -4,7 +4,6 @@ using System; using System.Reflection; using System.Runtime.InteropServices; -using System.Text; namespace Microsoft.AspNet.Server.Kestrel.Networking { diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/PlatformApis.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/PlatformApis.cs index 8eeee2f719..b2e34c5aeb 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/PlatformApis.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/PlatformApis.cs @@ -2,9 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.Reflection; using System.Runtime.InteropServices; -using System.Text; namespace Microsoft.AspNet.Server.Kestrel.Networking { diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvAsyncHandle.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvAsyncHandle.cs index bc8addba09..138853da85 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvAsyncHandle.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvAsyncHandle.cs @@ -32,7 +32,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking _uv.async_send(this); } - unsafe static void AsyncCb(IntPtr handle) + unsafe private static void AsyncCb(IntPtr handle) { FromIntPtr(handle)._callback.Invoke(); } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvReq.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvReq.cs new file mode 100644 index 0000000000..56e738710d --- /dev/null +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvReq.cs @@ -0,0 +1,17 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; + +namespace Microsoft.AspNet.Server.Kestrel.Networking +{ + public abstract class UvReq : UvMemory + { + protected override bool ReleaseHandle() + { + DestroyMemory(handle); + handle = IntPtr.Zero; + return true; + } + } +} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvWriteRequest.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvWriteReq.cs similarity index 90% rename from src/Microsoft.AspNet.Server.Kestrel/Networking/UvWriteRequest.cs rename to src/Microsoft.AspNet.Server.Kestrel/Networking/UvWriteReq.cs index 4696912db2..3e88312805 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvWriteRequest.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvWriteReq.cs @@ -1,6 +1,3 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - using System; using System.Collections.Generic; using System.Diagnostics; @@ -117,14 +114,4 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking } } } - - public abstract class UvReq : UvMemory - { - protected override bool ReleaseHandle() - { - DestroyMemory(handle); - handle = IntPtr.Zero; - return true; - } - } } \ No newline at end of file From 0670b7ae618572833bdb678645dbb2acf6ff9192 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Tue, 23 Jun 2015 15:48:18 -0700 Subject: [PATCH 0136/1662] Ensure all the C# files have copyright notices --- samples/SampleApp/Program.cs | 5 ++++- samples/SampleApp/Startup.cs | 5 ++++- src/Kestrel/Program.cs | 5 ++++- src/Kestrel/ServerAddress.cs | 5 ++++- .../Http/ConnectionContext.cs | 3 +++ src/Microsoft.AspNet.Server.Kestrel/Http/FrameContext.cs | 3 +++ .../Http/IConnectionControl.cs | 3 +++ src/Microsoft.AspNet.Server.Kestrel/Http/IFrameControl.cs | 3 +++ src/Microsoft.AspNet.Server.Kestrel/Http/IMemoryPool.cs | 3 +++ src/Microsoft.AspNet.Server.Kestrel/Http/ISocketOutput.cs | 3 +++ src/Microsoft.AspNet.Server.Kestrel/Http/ListenerContext.cs | 3 +++ src/Microsoft.AspNet.Server.Kestrel/Http/ProduceEndType.cs | 3 +++ .../Infrastructure/KestrelTrace.cs | 4 +++- .../Networking/UvWriteReq.cs | 3 +++ test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs | 5 ++++- .../MessageBodyExchangerTests.cs | 4 +++- .../MessageBodyTests.cs | 6 ++++-- test/Microsoft.AspNet.Server.KestrelTests/Program.cs | 3 ++- test/Microsoft.AspNet.Server.KestrelTests/TestConnection.cs | 5 ++++- test/Microsoft.AspNet.Server.KestrelTests/TestInput.cs | 5 ++++- test/Microsoft.AspNet.Server.KestrelTests/TestServer.cs | 5 ++++- 21 files changed, 71 insertions(+), 13 deletions(-) diff --git a/samples/SampleApp/Program.cs b/samples/SampleApp/Program.cs index b32fd7577a..9e1e66cd02 100644 --- a/samples/SampleApp/Program.cs +++ b/samples/SampleApp/Program.cs @@ -1,4 +1,7 @@ -using System; +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; namespace SampleApp { diff --git a/samples/SampleApp/Startup.cs b/samples/SampleApp/Startup.cs index 816ab79f3c..5f81cbefcc 100644 --- a/samples/SampleApp/Startup.cs +++ b/samples/SampleApp/Startup.cs @@ -1,4 +1,7 @@ -using System; +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; using Microsoft.AspNet.Builder; using Microsoft.AspNet.Http; diff --git a/src/Kestrel/Program.cs b/src/Kestrel/Program.cs index 7f877d9002..220cf1eed3 100644 --- a/src/Kestrel/Program.cs +++ b/src/Kestrel/Program.cs @@ -1,4 +1,7 @@ -using System; +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; using System.Linq; namespace Kestrel diff --git a/src/Kestrel/ServerAddress.cs b/src/Kestrel/ServerAddress.cs index d5eac3be2b..b957b62791 100644 --- a/src/Kestrel/ServerAddress.cs +++ b/src/Kestrel/ServerAddress.cs @@ -1,4 +1,7 @@ -namespace Kestrel +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +namespace Kestrel { public class ServerAddress { diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/ConnectionContext.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/ConnectionContext.cs index cedfc63aeb..85ac78591b 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/ConnectionContext.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/ConnectionContext.cs @@ -1,3 +1,6 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + namespace Microsoft.AspNet.Server.Kestrel.Http { public class ConnectionContext : ListenerContext diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameContext.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameContext.cs index dedcb1b41f..f18efc6658 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameContext.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameContext.cs @@ -1,3 +1,6 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + namespace Microsoft.AspNet.Server.Kestrel.Http { public class FrameContext : ConnectionContext diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/IConnectionControl.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/IConnectionControl.cs index f0be1f74d6..c6e2f7ec04 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/IConnectionControl.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/IConnectionControl.cs @@ -1,3 +1,6 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + namespace Microsoft.AspNet.Server.Kestrel.Http { public interface IConnectionControl diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/IFrameControl.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/IFrameControl.cs index 3dfab0893a..77240740e6 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/IFrameControl.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/IFrameControl.cs @@ -1,3 +1,6 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + using System; namespace Microsoft.AspNet.Server.Kestrel.Http diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/IMemoryPool.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/IMemoryPool.cs index 6e28b4529f..82dcc7a218 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/IMemoryPool.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/IMemoryPool.cs @@ -1,3 +1,6 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + using System; namespace Microsoft.AspNet.Server.Kestrel.Http diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/ISocketOutput.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/ISocketOutput.cs index 43dd4fb4b2..52f11f62ac 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/ISocketOutput.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/ISocketOutput.cs @@ -1,3 +1,6 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + using System; namespace Microsoft.AspNet.Server.Kestrel.Http diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerContext.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerContext.cs index a2a4283a46..4285f59311 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerContext.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerContext.cs @@ -1,3 +1,6 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + using System; using System.Threading.Tasks; diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/ProduceEndType.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/ProduceEndType.cs index 31ea4754cf..4df5ed4e48 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/ProduceEndType.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/ProduceEndType.cs @@ -1,3 +1,6 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + namespace Microsoft.AspNet.Server.Kestrel.Http { public enum ProduceEndType diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelTrace.cs b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelTrace.cs index 6aa018b6bf..53a1cb73e3 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelTrace.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelTrace.cs @@ -1,4 +1,6 @@ -using System; +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + //using System.Diagnostics.Tracing; namespace Microsoft.AspNet.Server.Kestrel diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvWriteReq.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvWriteReq.cs index 3e88312805..6539d5574f 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvWriteReq.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvWriteReq.cs @@ -1,3 +1,6 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + using System; using System.Collections.Generic; using System.Diagnostics; diff --git a/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs index f3bc95c1af..fd9960c819 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs @@ -1,4 +1,7 @@ -using Microsoft.AspNet.Server.Kestrel; +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using Microsoft.AspNet.Server.Kestrel; using Microsoft.AspNet.Server.Kestrel.Http; using Microsoft.Framework.Runtime; using Microsoft.Framework.Runtime.Infrastructure; diff --git a/test/Microsoft.AspNet.Server.KestrelTests/MessageBodyExchangerTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/MessageBodyExchangerTests.cs index b8606ef8dd..8e7612de3f 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/MessageBodyExchangerTests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/MessageBodyExchangerTests.cs @@ -1,4 +1,6 @@ -using Microsoft.AspNet.Server.Kestrel; +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + using Microsoft.AspNet.Server.Kestrel.Http; using System; using System.Threading.Tasks; diff --git a/test/Microsoft.AspNet.Server.KestrelTests/MessageBodyTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/MessageBodyTests.cs index a8be2d3420..5a66846619 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/MessageBodyTests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/MessageBodyTests.cs @@ -1,8 +1,10 @@ -using Microsoft.AspNet.Server.Kestrel.Http; +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using Microsoft.AspNet.Server.Kestrel.Http; using System; using System.Collections.Generic; using System.Text; -using System.Threading; using System.Threading.Tasks; using Xunit; diff --git a/test/Microsoft.AspNet.Server.KestrelTests/Program.cs b/test/Microsoft.AspNet.Server.KestrelTests/Program.cs index 9e36b9f8c2..adcc2288c5 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/Program.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/Program.cs @@ -1,4 +1,5 @@ -using System; +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. namespace Microsoft.AspNet.Server.KestrelTests { diff --git a/test/Microsoft.AspNet.Server.KestrelTests/TestConnection.cs b/test/Microsoft.AspNet.Server.KestrelTests/TestConnection.cs index be079ad17f..085589beb0 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/TestConnection.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/TestConnection.cs @@ -1,4 +1,7 @@ -using System; +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; using System.Diagnostics; using System.IO; using System.Net; diff --git a/test/Microsoft.AspNet.Server.KestrelTests/TestInput.cs b/test/Microsoft.AspNet.Server.KestrelTests/TestInput.cs index a9448ac942..1676a92044 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/TestInput.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/TestInput.cs @@ -1,4 +1,7 @@ -using System; +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; using Microsoft.AspNet.Server.Kestrel.Http; namespace Microsoft.AspNet.Server.KestrelTests diff --git a/test/Microsoft.AspNet.Server.KestrelTests/TestServer.cs b/test/Microsoft.AspNet.Server.KestrelTests/TestServer.cs index 0e2c9f3d33..e2de4d29b0 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/TestServer.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/TestServer.cs @@ -1,4 +1,7 @@ -using Microsoft.AspNet.Server.Kestrel; +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using Microsoft.AspNet.Server.Kestrel; using Microsoft.AspNet.Server.Kestrel.Http; using Microsoft.Framework.Runtime; using Microsoft.Framework.Runtime.Infrastructure; From 98995132de817fcec4c02536e6494a32eaf13cb7 Mon Sep 17 00:00:00 2001 From: markrendle Date: Tue, 30 Jun 2015 11:00:37 +0100 Subject: [PATCH 0137/1662] Pre-create Continue bytes in Frame --- src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs index 3ae0d60b6b..4689db0804 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs @@ -260,7 +260,13 @@ namespace Microsoft.AspNet.Server.Kestrel.Http //_upgradeTask = callback(_callContext); } - byte[] _continueBytes = Encoding.ASCII.GetBytes("HTTP/1.1 100 Continue\r\n\r\n"); + private static readonly ArraySegment _continueBytes = CreateAsciiByteArraySegment("HTTP/1.1 100 Continue\r\n\r\n"); + + private static ArraySegment CreateAsciiByteArraySegment(string text) + { + var bytes = Encoding.ASCII.GetBytes(text); + return new ArraySegment(bytes); + } public void ProduceContinue() { @@ -272,7 +278,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http (expect.FirstOrDefault() ?? "").Equals("100-continue", StringComparison.OrdinalIgnoreCase)) { SocketOutput.Write( - new ArraySegment(_continueBytes, 0, _continueBytes.Length), + _continueBytes, (error, _) => { if (error != null) From 94dba8ff0e7e6de52f38cdc7c24477fe727ba671 Mon Sep 17 00:00:00 2001 From: Steve Smith Date: Wed, 1 Jul 2015 12:49:18 -0400 Subject: [PATCH 0138/1662] Moved address parsing to ServerAddress --- src/Kestrel/ServerAddress.cs | 63 ++++++++++++++++++++++++-- src/Kestrel/ServerInformation.cs | 78 ++------------------------------ 2 files changed, 62 insertions(+), 79 deletions(-) diff --git a/src/Kestrel/ServerAddress.cs b/src/Kestrel/ServerAddress.cs index b957b62791..dfbe1ff3df 100644 --- a/src/Kestrel/ServerAddress.cs +++ b/src/Kestrel/ServerAddress.cs @@ -1,13 +1,68 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; +using System.Globalization; + namespace Kestrel { public class ServerAddress { - public string Host { get; internal set; } - public string Path { get; internal set; } - public int Port { get; internal set; } - public string Scheme { get; internal set; } + public string Host { get; private set; } + public string Path { get; private set; } + public int Port { get; private set; } + public string Scheme { get; private set; } + + public static ServerAddress FromUrl(string url) + { + url = url ?? string.Empty; + + int delimiterStart1 = url.IndexOf("://", StringComparison.Ordinal); + if (delimiterStart1 < 0) + { + return null; + } + int delimiterEnd1 = delimiterStart1 + "://".Length; + + int delimiterStart3 = url.IndexOf("/", delimiterEnd1, StringComparison.Ordinal); + if (delimiterStart3 < 0) + { + delimiterStart3 = url.Length; + } + int delimiterStart2 = url.LastIndexOf(":", delimiterStart3 - 1, delimiterStart3 - delimiterEnd1, StringComparison.Ordinal); + int delimiterEnd2 = delimiterStart2 + ":".Length; + if (delimiterStart2 < 0) + { + delimiterStart2 = delimiterStart3; + delimiterEnd2 = delimiterStart3; + } + var serverAddress = new ServerAddress(); + serverAddress.Scheme = url.Substring(0, delimiterStart1); + string portString = url.Substring(delimiterEnd2, delimiterStart3 - delimiterEnd2); + int portNumber; + if (int.TryParse(portString, NumberStyles.Integer, CultureInfo.InvariantCulture, out portNumber)) + { + serverAddress.Host = url.Substring(delimiterEnd1, delimiterStart2 - delimiterEnd1); + serverAddress.Port = portNumber; + } + else + { + if (string.Equals(serverAddress.Scheme, "http", StringComparison.OrdinalIgnoreCase)) + { + serverAddress.Port = 80; + } + else if (string.Equals(serverAddress.Scheme, "https", StringComparison.OrdinalIgnoreCase)) + { + serverAddress.Port = 443; + } + else + { + serverAddress.Port = 0; + } + serverAddress.Host = url.Substring(delimiterEnd1, delimiterStart3 - delimiterEnd1); + } + serverAddress.Path = url.Substring(delimiterStart3); + return serverAddress; + } } } \ No newline at end of file diff --git a/src/Kestrel/ServerInformation.cs b/src/Kestrel/ServerInformation.cs index 7df85df587..dfbde7e91d 100644 --- a/src/Kestrel/ServerInformation.cs +++ b/src/Kestrel/ServerInformation.cs @@ -3,7 +3,6 @@ using System; using System.Collections.Generic; -using System.Globalization; using Microsoft.AspNet.Hosting.Server; using Microsoft.Framework.Configuration; @@ -25,20 +24,10 @@ namespace Kestrel } foreach (var url in urls.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries)) { - string scheme; - string host; - int port; - string path; - if (DeconstructUrl(url, out scheme, out host, out port, out path)) + var address = ServerAddress.FromUrl(url); + if(address != null) { - Addresses.Add( - new ServerAddress - { - Scheme = scheme, - Host = host, - Port = port, - Path = path - }); + Addresses.Add(address); } } } @@ -52,66 +41,5 @@ namespace Kestrel } public IList Addresses { get; private set; } - - internal static bool DeconstructUrl( - string url, - out string scheme, - out string host, - out int port, - out string path) - { - url = url ?? string.Empty; - - int delimiterStart1 = url.IndexOf("://", StringComparison.Ordinal); - if (delimiterStart1 < 0) - { - scheme = null; - host = null; - port = 0; - path = null; - return false; - } - int delimiterEnd1 = delimiterStart1 + "://".Length; - - int delimiterStart3 = url.IndexOf("/", delimiterEnd1, StringComparison.Ordinal); - if (delimiterStart3 < 0) - { - delimiterStart3 = url.Length; - } - int delimiterStart2 = url.LastIndexOf(":", delimiterStart3 - 1, delimiterStart3 - delimiterEnd1, StringComparison.Ordinal); - int delimiterEnd2 = delimiterStart2 + ":".Length; - if (delimiterStart2 < 0) - { - delimiterStart2 = delimiterStart3; - delimiterEnd2 = delimiterStart3; - } - - scheme = url.Substring(0, delimiterStart1); - string portString = url.Substring(delimiterEnd2, delimiterStart3 - delimiterEnd2); - int portNumber; - if (int.TryParse(portString, NumberStyles.Integer, CultureInfo.InvariantCulture, out portNumber)) - { - host = url.Substring(delimiterEnd1, delimiterStart2 - delimiterEnd1); - port = portNumber; - } - else - { - if (string.Equals(scheme, "http", StringComparison.OrdinalIgnoreCase)) - { - port = 80; - } - else if (string.Equals(scheme, "https", StringComparison.OrdinalIgnoreCase)) - { - port = 443; - } - else - { - port = 0; - } - host = url.Substring(delimiterEnd1, delimiterStart3 - delimiterEnd1); - } - path = url.Substring(delimiterStart3); - return true; - } } } From 3aaae6964f8eba30ff78b426fe0569a99eacd4f1 Mon Sep 17 00:00:00 2001 From: Peter Hsu Date: Tue, 14 Jul 2015 10:36:34 -0700 Subject: [PATCH 0139/1662] Fix NPE issue where UvShutdownReq being garbage collected before the shutdown callback executed --- .../Networking/UvShutdownReq.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvShutdownReq.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvShutdownReq.cs index 815350d3cc..53073f0e2a 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvShutdownReq.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvShutdownReq.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Runtime.InteropServices; namespace Microsoft.AspNet.Server.Kestrel.Networking { @@ -14,6 +15,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking Action _callback; object _state; + GCHandle _pin; public void Init(UvLoopHandle loop) { @@ -27,12 +29,14 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking { _callback = callback; _state = state; + _pin = GCHandle.Alloc(this, GCHandleType.Normal); _uv.shutdown(this, handle, _uv_shutdown_cb); } private static void UvShutdownCb(IntPtr ptr, int status) { var req = FromIntPtr(ptr); + req._pin.Free(); req._callback(req, status, req._state); req._callback = null; req._state = null; From c1ea96d1e0a8a907453416022506afaa34ec788e Mon Sep 17 00:00:00 2001 From: Pranav K Date: Thu, 16 Jul 2015 09:01:37 -0700 Subject: [PATCH 0140/1662] Updating to release NuGet.config --- NuGet.Config | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/NuGet.Config b/NuGet.Config index da57d47267..0e74a4912d 100644 --- a/NuGet.Config +++ b/NuGet.Config @@ -1,7 +1,8 @@  - + + - \ No newline at end of file + From 93477efb41c8657a94ceb799cb63f0b2287588ab Mon Sep 17 00:00:00 2001 From: Chris R Date: Fri, 17 Jul 2015 09:58:55 -0700 Subject: [PATCH 0141/1662] React to FeatureModel package change. --- src/Kestrel/ServerFactory.cs | 2 +- src/Kestrel/ServerRequest.cs | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Kestrel/ServerFactory.cs b/src/Kestrel/ServerFactory.cs index dbe91f9e06..e7e19f8353 100644 --- a/src/Kestrel/ServerFactory.cs +++ b/src/Kestrel/ServerFactory.cs @@ -4,8 +4,8 @@ using System; using System.Collections.Generic; using System.Threading.Tasks; -using Microsoft.AspNet.FeatureModel; using Microsoft.AspNet.Hosting.Server; +using Microsoft.AspNet.Http.Features; using Microsoft.AspNet.Server.Kestrel; using Microsoft.Framework.Configuration; using Microsoft.Framework.Runtime; diff --git a/src/Kestrel/ServerRequest.cs b/src/Kestrel/ServerRequest.cs index 5edfda327d..e1ac126af5 100644 --- a/src/Kestrel/ServerRequest.cs +++ b/src/Kestrel/ServerRequest.cs @@ -6,7 +6,6 @@ using System.Collections.Generic; using System.IO; using System.Linq; using System.Threading.Tasks; -using Microsoft.AspNet.FeatureModel; using Microsoft.AspNet.Http.Features; using Microsoft.AspNet.Server.Kestrel.Http; From aedd548c3be0c7aaf09fbdf3a649a4ac9a7e8856 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Sun, 19 Jul 2015 15:32:37 +0100 Subject: [PATCH 0142/1662] Fix sample perf (Option 1) No need to await just return Task --- samples/SampleApp/Startup.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/samples/SampleApp/Startup.cs b/samples/SampleApp/Startup.cs index 5f81cbefcc..edc92abac0 100644 --- a/samples/SampleApp/Startup.cs +++ b/samples/SampleApp/Startup.cs @@ -11,7 +11,7 @@ namespace SampleApp { public void Configure(IApplicationBuilder app) { - app.Run(async context => + app.Run(context => { Console.WriteLine("{0} {1}{2}{3}", context.Request.Method, @@ -21,8 +21,8 @@ namespace SampleApp context.Response.ContentLength = 11; context.Response.ContentType = "text/plain"; - await context.Response.WriteAsync("Hello world"); + return context.Response.WriteAsync("Hello world"); }); } } -} \ No newline at end of file +} From e69f63e49469408e34e5baa957bdffc2615e6ca4 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Sun, 19 Jul 2015 15:47:39 +0100 Subject: [PATCH 0143/1662] ConfigureAwait(false) --- src/Kestrel/ServerFactory.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Kestrel/ServerFactory.cs b/src/Kestrel/ServerFactory.cs index e7e19f8353..e34217e081 100644 --- a/src/Kestrel/ServerFactory.cs +++ b/src/Kestrel/ServerFactory.cs @@ -46,7 +46,7 @@ namespace Kestrel async frame => { var request = new ServerRequest(frame); - await application.Invoke(request.Features); + await application.Invoke(request.Features).ConfigureAwait(false); })); } disposables.Add(engine); From 23ffc3fea94774e3a2fac46f6a9ff9c5925e535a Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Sun, 19 Jul 2015 15:50:42 +0100 Subject: [PATCH 0144/1662] ConfigureAwait(false) --- src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs index 4689db0804..f0126a1414 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs @@ -231,7 +231,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http Exception error = null; try { - await Application.Invoke(this); + await Application.Invoke(this).ConfigureAwait(false); } catch (Exception ex) { From b9901c3bfef479dc41d27980c5fefa4fd5b9b53d Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Wed, 15 Jul 2015 16:17:59 -0700 Subject: [PATCH 0145/1662] Surface fatal exceptions that stop the event loop - Request an app Shutdown so KestrelEngine gets disposed - Ensure Listener.Dispose doesn't deadlock before the engine can be disposed - Rely on the existing logic to rethrow in the fatal error when the engine gets disposed --- src/Kestrel/ServerFactory.cs | 6 ++- .../Http/Listener.cs | 40 ++++++++++++------- .../Infrastructure/KestrelThread.cs | 4 ++ .../KestrelEngine.cs | 5 ++- .../EngineTests.cs | 6 +-- .../NetworkingTests.cs | 2 +- .../ShutdownNotImplemented.cs | 25 ++++++++++++ .../TestServer.cs | 2 +- 8 files changed, 66 insertions(+), 24 deletions(-) create mode 100644 test/Microsoft.AspNet.Server.KestrelTests/ShutdownNotImplemented.cs diff --git a/src/Kestrel/ServerFactory.cs b/src/Kestrel/ServerFactory.cs index dbe91f9e06..41fb30cd2e 100644 --- a/src/Kestrel/ServerFactory.cs +++ b/src/Kestrel/ServerFactory.cs @@ -18,10 +18,12 @@ namespace Kestrel public class ServerFactory : IServerFactory { private readonly ILibraryManager _libraryManager; + private readonly IApplicationShutdown _appShutdownService; - public ServerFactory(ILibraryManager libraryManager) + public ServerFactory(ILibraryManager libraryManager, IApplicationShutdown appShutdownService) { _libraryManager = libraryManager; + _appShutdownService = appShutdownService; } public IServerInformation Initialize(IConfiguration configuration) @@ -35,7 +37,7 @@ namespace Kestrel { var disposables = new List(); var information = (ServerInformation)serverInformation; - var engine = new KestrelEngine(_libraryManager); + var engine = new KestrelEngine(_libraryManager, _appShutdownService); engine.Start(1); foreach (var address in information.Addresses) { diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs index b2cf408f75..c48e43b18a 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs @@ -76,22 +76,32 @@ namespace Microsoft.AspNet.Server.Kestrel.Http public void Dispose() { - var tcs = new TaskCompletionSource(); - Thread.Post( - _ => - { - try + // Ensure the event loop is still running. + // If the event loop isn't running and we try to wait on this Post + // to complete, then KestrelEngine will never be disposed and + // the exception that stopped the event loop will never be surfaced. + if (Thread.FatalError == null) + { + var tcs = new TaskCompletionSource(); + Thread.Post( + _ => { - ListenSocket.Dispose(); - tcs.SetResult(0); - } - catch (Exception ex) - { - tcs.SetException(ex); - } - }, - null); - tcs.Task.Wait(); + try + { + ListenSocket.Dispose(); + tcs.SetResult(0); + } + catch (Exception ex) + { + tcs.SetException(ex); + } + }, + null); + + // REVIEW: Should we add a timeout here to be safe? + tcs.Task.Wait(); + } + ListenSocket = null; } } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs index 821a8216da..c971eca102 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs @@ -38,6 +38,7 @@ namespace Microsoft.AspNet.Server.Kestrel } public UvLoopHandle Loop { get { return _loop; } } + public ExceptionDispatchInfo FatalError { get { return _closeError; } } public Action, IntPtr> QueueCloseHandle { get; internal set; } @@ -173,6 +174,9 @@ namespace Microsoft.AspNet.Server.Kestrel catch (Exception ex) { _closeError = ExceptionDispatchInfo.Capture(ex); + // Request shutdown so we can rethrow this exception + // in Stop which should be observable. + _engine.AppShutdown.RequestShutdown(); } } diff --git a/src/Microsoft.AspNet.Server.Kestrel/KestrelEngine.cs b/src/Microsoft.AspNet.Server.Kestrel/KestrelEngine.cs index 21b4df4523..394d3a745c 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/KestrelEngine.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/KestrelEngine.cs @@ -13,9 +13,9 @@ namespace Microsoft.AspNet.Server.Kestrel { public class KestrelEngine : IDisposable { - - public KestrelEngine(ILibraryManager libraryManager) + public KestrelEngine(ILibraryManager libraryManager, IApplicationShutdown appShutdownService) { + AppShutdown = appShutdownService; Threads = new List(); Listeners = new List(); Memory = new MemoryPool(); @@ -63,6 +63,7 @@ namespace Microsoft.AspNet.Server.Kestrel public Libuv Libuv { get; private set; } public IMemoryPool Memory { get; set; } + public IApplicationShutdown AppShutdown { get; private set; } public List Threads { get; private set; } public List Listeners { get; private set; } diff --git a/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs index fd9960c819..98be42db2e 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs @@ -78,7 +78,7 @@ namespace Microsoft.AspNet.Server.KestrelTests [Fact] public async Task EngineCanStartAndStop() { - var engine = new KestrelEngine(LibraryManager); + var engine = new KestrelEngine(LibraryManager, new ShutdownNotImplemented()); engine.Start(1); engine.Dispose(); } @@ -86,7 +86,7 @@ namespace Microsoft.AspNet.Server.KestrelTests [Fact] public async Task ListenerCanCreateAndDispose() { - var engine = new KestrelEngine(LibraryManager); + var engine = new KestrelEngine(LibraryManager, new ShutdownNotImplemented()); engine.Start(1); var started = engine.CreateServer("http", "localhost", 54321, App); started.Dispose(); @@ -97,7 +97,7 @@ namespace Microsoft.AspNet.Server.KestrelTests [Fact] public async Task ConnectionCanReadAndWrite() { - var engine = new KestrelEngine(LibraryManager); + var engine = new KestrelEngine(LibraryManager, new ShutdownNotImplemented()); engine.Start(1); var started = engine.CreateServer("http", "localhost", 54321, App); diff --git a/test/Microsoft.AspNet.Server.KestrelTests/NetworkingTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/NetworkingTests.cs index 3e549f53a8..2cf9c71d05 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/NetworkingTests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/NetworkingTests.cs @@ -22,7 +22,7 @@ namespace Microsoft.AspNet.Server.KestrelTests Libuv _uv; public NetworkingTests() { - var engine = new KestrelEngine(LibraryManager); + var engine = new KestrelEngine(LibraryManager, new ShutdownNotImplemented()); _uv = engine.Libuv; } diff --git a/test/Microsoft.AspNet.Server.KestrelTests/ShutdownNotImplemented.cs b/test/Microsoft.AspNet.Server.KestrelTests/ShutdownNotImplemented.cs new file mode 100644 index 0000000000..58697d9a3e --- /dev/null +++ b/test/Microsoft.AspNet.Server.KestrelTests/ShutdownNotImplemented.cs @@ -0,0 +1,25 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Threading; +using Microsoft.Framework.Runtime; + +namespace Microsoft.AspNet.Server.KestrelTests +{ + public class ShutdownNotImplemented : IApplicationShutdown + { + public CancellationToken ShutdownRequested + { + get + { + throw new NotImplementedException(); + } + } + + public void RequestShutdown() + { + throw new NotImplementedException(); + } + } +} diff --git a/test/Microsoft.AspNet.Server.KestrelTests/TestServer.cs b/test/Microsoft.AspNet.Server.KestrelTests/TestServer.cs index e2de4d29b0..dba5cddcde 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/TestServer.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/TestServer.cs @@ -45,7 +45,7 @@ namespace Microsoft.AspNet.Server.KestrelTests public void Create(Func app) { - _engine = new KestrelEngine(LibraryManager); + _engine = new KestrelEngine(LibraryManager, new ShutdownNotImplemented()); _engine.Start(1); _server = _engine.CreateServer( "http", From 3cc0dd7a257207e27c4985b6d4c0617b00ca275e Mon Sep 17 00:00:00 2001 From: Chris R Date: Fri, 17 Jul 2015 09:58:55 -0700 Subject: [PATCH 0146/1662] React to FeatureModel package change. --- src/Kestrel/ServerFactory.cs | 2 +- src/Kestrel/ServerRequest.cs | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Kestrel/ServerFactory.cs b/src/Kestrel/ServerFactory.cs index 41fb30cd2e..1522c61df8 100644 --- a/src/Kestrel/ServerFactory.cs +++ b/src/Kestrel/ServerFactory.cs @@ -4,8 +4,8 @@ using System; using System.Collections.Generic; using System.Threading.Tasks; -using Microsoft.AspNet.FeatureModel; using Microsoft.AspNet.Hosting.Server; +using Microsoft.AspNet.Http.Features; using Microsoft.AspNet.Server.Kestrel; using Microsoft.Framework.Configuration; using Microsoft.Framework.Runtime; diff --git a/src/Kestrel/ServerRequest.cs b/src/Kestrel/ServerRequest.cs index 5edfda327d..e1ac126af5 100644 --- a/src/Kestrel/ServerRequest.cs +++ b/src/Kestrel/ServerRequest.cs @@ -6,7 +6,6 @@ using System.Collections.Generic; using System.IO; using System.Linq; using System.Threading.Tasks; -using Microsoft.AspNet.FeatureModel; using Microsoft.AspNet.Http.Features; using Microsoft.AspNet.Server.Kestrel.Http; From c199e5eee11370f586009178f34d080642f4bb9d Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Fri, 17 Jul 2015 13:07:30 -0700 Subject: [PATCH 0147/1662] Wait on user-defined OnStarting and OnCompleted callbacks --- src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs index 4689db0804..c21f6b7b84 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs @@ -197,7 +197,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { foreach (var entry in onStarting) { - entry.Key.Invoke(entry.Value); + entry.Key.Invoke(entry.Value).Wait(); } } } @@ -216,7 +216,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { try { - entry.Key.Invoke(entry.Value); + entry.Key.Invoke(entry.Value).Wait(); } catch { From 4a284e5f81d469c2740ac730b544fbe43c471fde Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Tue, 21 Jul 2015 14:17:11 -0700 Subject: [PATCH 0148/1662] Revert "React to FeatureModel package change." This should not have been in the release branch yet! This reverts commit 3cc0dd7a257207e27c4985b6d4c0617b00ca275e. --- src/Kestrel/ServerFactory.cs | 2 +- src/Kestrel/ServerRequest.cs | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Kestrel/ServerFactory.cs b/src/Kestrel/ServerFactory.cs index 1522c61df8..41fb30cd2e 100644 --- a/src/Kestrel/ServerFactory.cs +++ b/src/Kestrel/ServerFactory.cs @@ -4,8 +4,8 @@ using System; using System.Collections.Generic; using System.Threading.Tasks; +using Microsoft.AspNet.FeatureModel; using Microsoft.AspNet.Hosting.Server; -using Microsoft.AspNet.Http.Features; using Microsoft.AspNet.Server.Kestrel; using Microsoft.Framework.Configuration; using Microsoft.Framework.Runtime; diff --git a/src/Kestrel/ServerRequest.cs b/src/Kestrel/ServerRequest.cs index e1ac126af5..5edfda327d 100644 --- a/src/Kestrel/ServerRequest.cs +++ b/src/Kestrel/ServerRequest.cs @@ -6,6 +6,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; using System.Threading.Tasks; +using Microsoft.AspNet.FeatureModel; using Microsoft.AspNet.Http.Features; using Microsoft.AspNet.Server.Kestrel.Http; From ceeb4edabd9d905991ecadfac13e6bf7b8453013 Mon Sep 17 00:00:00 2001 From: Louis DeJardin Date: Thu, 23 Jul 2015 12:51:31 -0700 Subject: [PATCH 0149/1662] Adding UvPipeHandle --- .../Http/Connection.cs | 2 +- .../Http/SocketOutput.cs | 1 - .../Networking/Libuv.cs | 110 +++++++++++++----- .../Networking/UvConnectRequest.cs | 70 +++++++++++ .../Networking/UvPipeHandle.cs | 40 +++++++ .../Networking/UvReq.cs | 17 --- .../Networking/UvRequest.cs | 31 +++++ .../Networking/UvShutdownReq.cs | 7 +- .../Networking/UvTcpHandle.cs | 5 + .../Networking/UvWriteReq.cs | 4 +- .../native/windows/amd64/libuv.dll | Bin 141312 -> 159232 bytes .../native/windows/x86/libuv.dll | Bin 119808 -> 133120 bytes .../project.json | 3 + 13 files changed, 237 insertions(+), 53 deletions(-) create mode 100644 src/Microsoft.AspNet.Server.Kestrel/Networking/UvConnectRequest.cs create mode 100644 src/Microsoft.AspNet.Server.Kestrel/Networking/UvPipeHandle.cs delete mode 100644 src/Microsoft.AspNet.Server.Kestrel/Networking/UvReq.cs create mode 100644 src/Microsoft.AspNet.Server.Kestrel/Networking/UvRequest.cs diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs index a6fd1b40bb..d43a1ab4ce 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs @@ -24,7 +24,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http private readonly UvStreamHandle _socket; private Frame _frame; - long _connectionId; + long _connectionId = 0; public Connection(ListenerContext context, UvStreamHandle socket) : base(context) { diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs index 02ed046576..4c3e4c8cc8 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs @@ -4,7 +4,6 @@ using Microsoft.AspNet.Server.Kestrel.Networking; using System; using System.Threading; -using System.Threading; namespace Microsoft.AspNet.Server.Kestrel.Http { diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/Libuv.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/Libuv.cs index 4a12712d0d..5429451f2f 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/Libuv.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/Libuv.cs @@ -58,6 +58,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking public int Check(int statusCode) { + var x = Marshal.GetLastWin32Error(); + Exception error; var result = Check(statusCode, out error); if (error != null) @@ -85,7 +87,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking [UnmanagedFunctionPointer(CallingConvention.Cdecl)] delegate int uv_loop_init(UvLoopHandle a0); - uv_loop_init _uv_loop_init; + uv_loop_init _uv_loop_init = default(uv_loop_init); public void loop_init(UvLoopHandle handle) { Check(_uv_loop_init(handle)); @@ -93,7 +95,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking [UnmanagedFunctionPointer(CallingConvention.Cdecl)] delegate int uv_loop_close(IntPtr a0); - uv_loop_close _uv_loop_close; + uv_loop_close _uv_loop_close = default(uv_loop_close); public void loop_close(UvLoopHandle handle) { handle.Validate(closed: true); @@ -102,7 +104,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking [UnmanagedFunctionPointer(CallingConvention.Cdecl)] delegate int uv_run(UvLoopHandle handle, int mode); - uv_run _uv_run; + uv_run _uv_run = default(uv_run); public int run(UvLoopHandle handle, int mode) { handle.Validate(); @@ -111,7 +113,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking [UnmanagedFunctionPointer(CallingConvention.Cdecl)] delegate void uv_stop(UvLoopHandle handle); - uv_stop _uv_stop; + uv_stop _uv_stop = default(uv_stop); public void stop(UvLoopHandle handle) { handle.Validate(); @@ -120,7 +122,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking [UnmanagedFunctionPointer(CallingConvention.Cdecl)] delegate void uv_ref(UvHandle handle); - uv_ref _uv_ref; + uv_ref _uv_ref = default(uv_ref); public void @ref(UvHandle handle) { handle.Validate(); @@ -129,7 +131,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking [UnmanagedFunctionPointer(CallingConvention.Cdecl)] delegate void uv_unref(UvHandle handle); - uv_unref _uv_unref; + uv_unref _uv_unref = default(uv_unref); public void unref(UvHandle handle) { handle.Validate(); @@ -141,7 +143,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking public delegate void uv_close_cb(IntPtr handle); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] delegate void uv_close(IntPtr handle, uv_close_cb close_cb); - uv_close _uv_close; + uv_close _uv_close = default(uv_close); public void close(UvHandle handle, uv_close_cb close_cb) { handle.Validate(closed: true); @@ -156,7 +158,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking public delegate void uv_async_cb(IntPtr handle); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] delegate int uv_async_init(UvLoopHandle loop, UvAsyncHandle handle, uv_async_cb cb); - uv_async_init _uv_async_init; + uv_async_init _uv_async_init = default(uv_async_init); public void async_init(UvLoopHandle loop, UvAsyncHandle handle, uv_async_cb cb) { loop.Validate(); @@ -166,7 +168,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking [UnmanagedFunctionPointer(CallingConvention.Cdecl)] delegate int uv_async_send(UvAsyncHandle handle); - uv_async_send _uv_async_send; + uv_async_send _uv_async_send = default(uv_async_send); public void async_send(UvAsyncHandle handle) { Check(_uv_async_send(handle)); @@ -174,7 +176,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking [UnmanagedFunctionPointer(CallingConvention.Cdecl)] delegate int uv_tcp_init(UvLoopHandle loop, UvTcpHandle handle); - uv_tcp_init _uv_tcp_init; + uv_tcp_init _uv_tcp_init = default(uv_tcp_init); public void tcp_init(UvLoopHandle loop, UvTcpHandle handle) { loop.Validate(); @@ -184,18 +186,46 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking [UnmanagedFunctionPointer(CallingConvention.Cdecl)] delegate int uv_tcp_bind(UvTcpHandle handle, ref sockaddr addr, int flags); - uv_tcp_bind _uv_tcp_bind; + uv_tcp_bind _uv_tcp_bind = default(uv_tcp_bind); public void tcp_bind(UvTcpHandle handle, ref sockaddr addr, int flags) { handle.Validate(); Check(_uv_tcp_bind(handle, ref addr, flags)); } + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + delegate int uv_tcp_open(UvTcpHandle handle, IntPtr hSocket); + uv_tcp_open _uv_tcp_open = default(uv_tcp_open); + public void tcp_open(UvTcpHandle handle, IntPtr hSocket) + { + handle.Validate(); + Check(_uv_tcp_open(handle, hSocket)); + } + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + delegate int uv_pipe_init(UvLoopHandle loop, UvPipeHandle handle, int ipc); + uv_pipe_init _uv_pipe_init = default(uv_pipe_init); + public void pipe_init(UvLoopHandle loop, UvPipeHandle handle, bool ipc) + { + loop.Validate(); + handle.Validate(); + Check(_uv_pipe_init(loop, handle, ipc ? -1 : 0)); + } + + [UnmanagedFunctionPointer(CallingConvention.Cdecl, CharSet = CharSet.Ansi)] + delegate int uv_pipe_bind(UvPipeHandle loop, string name); + uv_pipe_bind _uv_pipe_bind = default(uv_pipe_bind); + public void pipe_bind(UvPipeHandle handle, string name) + { + handle.Validate(); + Check(_uv_pipe_bind(handle, name)); + } + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] public delegate void uv_connection_cb(IntPtr server, int status); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] delegate int uv_listen(UvStreamHandle handle, int backlog, uv_connection_cb cb); - uv_listen _uv_listen; + uv_listen _uv_listen = default(uv_listen); public void listen(UvStreamHandle handle, int backlog, uv_connection_cb cb) { handle.Validate(); @@ -204,7 +234,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking [UnmanagedFunctionPointer(CallingConvention.Cdecl)] delegate int uv_accept(UvStreamHandle server, UvStreamHandle client); - uv_accept _uv_accept; + uv_accept _uv_accept = default(uv_accept); public void accept(UvStreamHandle server, UvStreamHandle client) { server.Validate(); @@ -212,13 +242,25 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking Check(_uv_accept(server, client)); } + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + public delegate void uv_connect_cb(IntPtr req, int status); + [UnmanagedFunctionPointer(CallingConvention.Cdecl, CharSet = CharSet.Ansi)] + unsafe delegate int uv_pipe_connect(UvConnectRequest req, UvPipeHandle handle, string name, uv_connect_cb cb); + uv_pipe_connect _uv_pipe_connect = default(uv_pipe_connect); + unsafe public void pipe_connect(UvConnectRequest req, UvPipeHandle handle, string name, uv_connect_cb cb) + { + req.Validate(); + handle.Validate(); + Check(_uv_pipe_connect(req, handle, name, cb)); + } + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] public delegate void uv_alloc_cb(IntPtr server, int suggested_size, out uv_buf_t buf); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] public delegate void uv_read_cb(IntPtr server, int nread, ref uv_buf_t buf); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] delegate int uv_read_start(UvStreamHandle handle, uv_alloc_cb alloc_cb, uv_read_cb read_cb); - uv_read_start _uv_read_start; + uv_read_start _uv_read_start = default(uv_read_start); public void read_start(UvStreamHandle handle, uv_alloc_cb alloc_cb, uv_read_cb read_cb) { handle.Validate(); @@ -227,7 +269,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking [UnmanagedFunctionPointer(CallingConvention.Cdecl)] delegate int uv_read_stop(UvStreamHandle handle); - uv_read_stop _uv_read_stop; + uv_read_stop _uv_read_stop = default(uv_read_stop); public void read_stop(UvStreamHandle handle) { handle.Validate(); @@ -236,7 +278,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking [UnmanagedFunctionPointer(CallingConvention.Cdecl)] delegate int uv_try_write(UvStreamHandle handle, Libuv.uv_buf_t[] bufs, int nbufs); - uv_try_write _uv_try_write; + uv_try_write _uv_try_write = default(uv_try_write); public int try_write(UvStreamHandle handle, Libuv.uv_buf_t[] bufs, int nbufs) { handle.Validate(); @@ -246,20 +288,30 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking [UnmanagedFunctionPointer(CallingConvention.Cdecl)] public delegate void uv_write_cb(IntPtr req, int status); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - unsafe delegate int uv_write(UvWriteReq req, UvStreamHandle handle, Libuv.uv_buf_t* bufs, int nbufs, uv_write_cb cb); - uv_write _uv_write; - unsafe public void write(UvWriteReq req, UvStreamHandle handle, Libuv.uv_buf_t* bufs, int nbufs, uv_write_cb cb) + unsafe delegate int uv_write(UvRequest req, UvStreamHandle handle, Libuv.uv_buf_t* bufs, int nbufs, uv_write_cb cb); + uv_write _uv_write = default(uv_write); + unsafe public void write(UvRequest req, UvStreamHandle handle, Libuv.uv_buf_t* bufs, int nbufs, uv_write_cb cb) { req.Validate(); handle.Validate(); Check(_uv_write(req, handle, bufs, nbufs, cb)); } + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + unsafe delegate int uv_write2(UvRequest req, UvStreamHandle handle, Libuv.uv_buf_t* bufs, int nbufs, UvStreamHandle sendHandle, uv_write_cb cb); + uv_write2 _uv_write2 = default(uv_write2); + unsafe public void write2(UvRequest req, UvStreamHandle handle, Libuv.uv_buf_t* bufs, int nbufs, UvStreamHandle sendHandle, uv_write_cb cb) + { + req.Validate(); + handle.Validate(); + Check(_uv_write2(req, handle, bufs, nbufs, sendHandle, cb)); + } + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] public delegate void uv_shutdown_cb(IntPtr req, int status); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] delegate int uv_shutdown(UvShutdownReq req, UvStreamHandle handle, uv_shutdown_cb cb); - uv_shutdown _uv_shutdown; + uv_shutdown _uv_shutdown = default(uv_shutdown); public void shutdown(UvShutdownReq req, UvStreamHandle handle, uv_shutdown_cb cb) { req.Validate(); @@ -269,7 +321,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking [UnmanagedFunctionPointer(CallingConvention.Cdecl)] delegate IntPtr uv_err_name(int err); - uv_err_name _uv_err_name; + uv_err_name _uv_err_name = default(uv_err_name); public unsafe String err_name(int err) { IntPtr ptr = _uv_err_name(err); @@ -278,7 +330,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking [UnmanagedFunctionPointer(CallingConvention.Cdecl)] delegate IntPtr uv_strerror(int err); - uv_strerror _uv_strerror; + uv_strerror _uv_strerror = default(uv_strerror); public unsafe String strerror(int err) { IntPtr ptr = _uv_strerror(err); @@ -287,7 +339,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking [UnmanagedFunctionPointer(CallingConvention.Cdecl)] delegate int uv_loop_size(); - uv_loop_size _uv_loop_size; + uv_loop_size _uv_loop_size = default(uv_loop_size); public int loop_size() { return _uv_loop_size(); @@ -295,7 +347,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking [UnmanagedFunctionPointer(CallingConvention.Cdecl)] delegate int uv_handle_size(HandleType handleType); - uv_handle_size _uv_handle_size; + uv_handle_size _uv_handle_size = default(uv_handle_size); public int handle_size(HandleType handleType) { return _uv_handle_size(handleType); @@ -303,7 +355,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking [UnmanagedFunctionPointer(CallingConvention.Cdecl)] delegate int uv_req_size(RequestType reqType); - uv_req_size _uv_req_size; + uv_req_size _uv_req_size = default(uv_req_size); public int req_size(RequestType reqType) { return _uv_req_size(reqType); @@ -312,7 +364,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking [UnmanagedFunctionPointer(CallingConvention.Cdecl)] delegate int uv_ip4_addr(string ip, int port, out sockaddr addr); - uv_ip4_addr _uv_ip4_addr; + uv_ip4_addr _uv_ip4_addr = default(uv_ip4_addr); public int ip4_addr(string ip, int port, out sockaddr addr, out Exception error) { return Check(_uv_ip4_addr(ip, port, out addr), out error); @@ -321,7 +373,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking [UnmanagedFunctionPointer(CallingConvention.Cdecl)] delegate int uv_ip6_addr(string ip, int port, out sockaddr addr); - uv_ip6_addr _uv_ip6_addr; + uv_ip6_addr _uv_ip6_addr = default(uv_ip6_addr); public int ip6_addr(string ip, int port, out sockaddr addr, out Exception error) { return Check(_uv_ip6_addr(ip, port, out addr), out error); @@ -331,7 +383,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking public delegate void uv_walk_cb(IntPtr handle, IntPtr arg); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] unsafe delegate int uv_walk(UvLoopHandle loop, uv_walk_cb walk_cb, IntPtr arg); - uv_walk _uv_walk; + uv_walk _uv_walk = default(uv_walk); unsafe public void walk(UvLoopHandle loop, uv_walk_cb walk_cb, IntPtr arg) { loop.Validate(); @@ -345,6 +397,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking public struct sockaddr { + public sockaddr(long ignored) { x3 = x0 = x1 = x2 = x3 = 0; } + long x0; long x1; long x2; diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvConnectRequest.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvConnectRequest.cs new file mode 100644 index 0000000000..90791f5fd8 --- /dev/null +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvConnectRequest.cs @@ -0,0 +1,70 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Runtime.InteropServices; + +namespace Microsoft.AspNet.Server.Kestrel.Networking +{ + /// + /// Summary description for UvWriteRequest + /// + public class UvConnectRequest : UvRequest + { + private readonly static Libuv.uv_connect_cb _uv_connect_cb = UvConnectCb; + + Action _callback; + object _state; + + public void Init(UvLoopHandle loop) + { + var requestSize = loop.Libuv.req_size(Libuv.RequestType.CONNECT); + CreateMemory( + loop.Libuv, + loop.ThreadId, + requestSize); + } + + public void Connect( + UvPipeHandle pipe, + string name, + Action callback, + object state) + { + _callback = callback; + _state = state; + + Pin(); + Libuv.pipe_connect(this, pipe, name, _uv_connect_cb); + } + + private static void UvConnectCb(IntPtr ptr, int status) + { + var req = FromIntPtr(ptr); + req.Unpin(); + + var callback = req._callback; + req._callback = null; + + var state = req._state; + req._state = null; + + Exception error = null; + if (status < 0) + { + req.Libuv.Check(status, out error); + } + + try + { + callback(req, status, error, state); + } + catch (Exception ex) + { + Trace.WriteLine("UvConnectRequest " + ex.ToString()); + } + } + } +} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvPipeHandle.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvPipeHandle.cs new file mode 100644 index 0000000000..59e0fbf379 --- /dev/null +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvPipeHandle.cs @@ -0,0 +1,40 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Net; + +namespace Microsoft.AspNet.Server.Kestrel.Networking +{ + public class UvPipeHandle : UvStreamHandle + { + public void Init(UvLoopHandle loop, bool ipc) + { + CreateMemory( + loop.Libuv, + loop.ThreadId, + loop.Libuv.handle_size(Libuv.HandleType.NAMED_PIPE)); + + _uv.pipe_init(loop, this, ipc); + } + + public void Init(UvLoopHandle loop, Action, IntPtr> queueCloseHandle) + { + CreateHandle( + loop.Libuv, + loop.ThreadId, + loop.Libuv.handle_size(Libuv.HandleType.TCP), queueCloseHandle); + + _uv.pipe_init(loop, this, false); + } + + public void Bind(string name) + { + _uv.pipe_bind(this, name); + } + + //public void Open(IntPtr hSocket) + //{ + //} + } +} diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvReq.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvReq.cs deleted file mode 100644 index 56e738710d..0000000000 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvReq.cs +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; - -namespace Microsoft.AspNet.Server.Kestrel.Networking -{ - public abstract class UvReq : UvMemory - { - protected override bool ReleaseHandle() - { - DestroyMemory(handle); - handle = IntPtr.Zero; - return true; - } - } -} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvRequest.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvRequest.cs new file mode 100644 index 0000000000..42285e536a --- /dev/null +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvRequest.cs @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.InteropServices; +using System.Threading.Tasks; + +namespace Microsoft.AspNet.Server.Kestrel.Networking +{ + public class UvRequest : UvMemory + { + GCHandle _pin; + + protected override bool ReleaseHandle() + { + DestroyMemory(handle); + handle = IntPtr.Zero; + return true; + } + + public virtual void Pin() + { + _pin = GCHandle.Alloc(this, GCHandleType.Normal); + } + + public virtual void Unpin() + { + _pin.Free(); + } + } +} + diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvShutdownReq.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvShutdownReq.cs index 53073f0e2a..fc40f8967d 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvShutdownReq.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvShutdownReq.cs @@ -9,13 +9,12 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking /// /// Summary description for UvShutdownRequest /// - public class UvShutdownReq : UvReq + public class UvShutdownReq : UvRequest { private readonly static Libuv.uv_shutdown_cb _uv_shutdown_cb = UvShutdownCb; Action _callback; object _state; - GCHandle _pin; public void Init(UvLoopHandle loop) { @@ -29,14 +28,14 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking { _callback = callback; _state = state; - _pin = GCHandle.Alloc(this, GCHandleType.Normal); + Pin(); _uv.shutdown(this, handle, _uv_shutdown_cb); } private static void UvShutdownCb(IntPtr ptr, int status) { var req = FromIntPtr(ptr); - req._pin.Free(); + req.Unpin(); req._callback(req, status, req._state); req._callback = null; req._state = null; diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvTcpHandle.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvTcpHandle.cs index 39d2a8a435..281f29190b 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvTcpHandle.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvTcpHandle.cs @@ -48,5 +48,10 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking _uv.tcp_bind(this, ref addr, 0); } + + public void Open(IntPtr hSocket) + { + _uv.tcp_open(this, hSocket); + } } } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvWriteReq.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvWriteReq.cs index 6539d5574f..a97175b7c3 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvWriteReq.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvWriteReq.cs @@ -11,7 +11,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking /// /// Summary description for UvWriteRequest /// - public class UvWriteReq : UvReq + public class UvWriteReq : UvRequest { private readonly static Libuv.uv_write_cb _uv_write_cb = UvWriteCb; @@ -26,7 +26,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking public void Init(UvLoopHandle loop) { var requestSize = loop.Libuv.req_size(Libuv.RequestType.WRITE); - var bufferSize = Marshal.SizeOf(typeof(Libuv.uv_buf_t)) * BUFFER_COUNT; + var bufferSize = Marshal.SizeOf() * BUFFER_COUNT; CreateMemory( loop.Libuv, loop.ThreadId, diff --git a/src/Microsoft.AspNet.Server.Kestrel/native/windows/amd64/libuv.dll b/src/Microsoft.AspNet.Server.Kestrel/native/windows/amd64/libuv.dll index 1174ae2c275385827a2e277753da13f5f9be574a..60923dcdb9d0aaa2a00ddce30cb28b59da73d7f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+EV9li=>A_h=Im+e^(xg_Nb;Z0{~-td7os~clmGw# diff --git a/test/Microsoft.AspNet.Server.KestrelTests/project.json b/test/Microsoft.AspNet.Server.KestrelTests/project.json index ea63991f94..afb7e9ad47 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/project.json +++ b/test/Microsoft.AspNet.Server.KestrelTests/project.json @@ -14,6 +14,9 @@ } } }, + "compilationOptions": { + "allowUnsafe": true + }, "commands": { "run": "xunit.runner.aspnet", "test": "xunit.runner.aspnet" From 42246fd51b5dfdaedf48673e89c8a4fb7f2eb6a8 Mon Sep 17 00:00:00 2001 From: Louis DeJardin Date: Fri, 24 Jul 2015 13:49:11 -0700 Subject: [PATCH 0150/1662] Using named pipes to dispatch connections to multiple threads --- src/Kestrel/ServerFactory.cs | 2 +- .../Http/Listener.cs | 11 +- .../Http/ListenerPrimary.cs | 88 ++++++ .../Http/ListenerSecondary.cs | 106 ++++++++ .../Infrastructure/KestrelThread.cs | 12 + .../KestrelEngine.cs | 33 ++- .../Networking/UvStreamHandle.cs | 2 +- .../Networking/UvWriteReq.cs | 48 ++++ .../project.json | 2 +- .../MultipleLoopTests.cs | 251 ++++++++++++++++++ .../Program.cs | 19 +- .../project.json | 2 +- 12 files changed, 561 insertions(+), 15 deletions(-) create mode 100644 src/Microsoft.AspNet.Server.Kestrel/Http/ListenerPrimary.cs create mode 100644 src/Microsoft.AspNet.Server.Kestrel/Http/ListenerSecondary.cs create mode 100644 test/Microsoft.AspNet.Server.KestrelTests/MultipleLoopTests.cs diff --git a/src/Kestrel/ServerFactory.cs b/src/Kestrel/ServerFactory.cs index 1522c61df8..ac60b4c4f2 100644 --- a/src/Kestrel/ServerFactory.cs +++ b/src/Kestrel/ServerFactory.cs @@ -38,7 +38,7 @@ namespace Kestrel var disposables = new List(); var information = (ServerInformation)serverInformation; var engine = new KestrelEngine(_libraryManager, _appShutdownService); - engine.Start(1); + engine.Start(Environment.ProcessorCount); foreach (var address in information.Addresses) { disposables.Add(engine.CreateServer( diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs index c48e43b18a..64fca769dc 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs @@ -53,7 +53,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http ListenSocket = new UvTcpHandle(); ListenSocket.Init(Thread.Loop, Thread.QueueCloseHandle); ListenSocket.Bind(new IPEndPoint(IPAddress.Any, port)); - ListenSocket.Listen(10, _connectionCallback, this); + ListenSocket.Listen(128, _connectionCallback, this); tcs.SetResult(0); } catch (Exception ex) @@ -64,13 +64,18 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return tcs.Task; } - private void OnConnection(UvStreamHandle listenSocket, int status) + protected void OnConnection(UvStreamHandle listenSocket, int status) { var acceptSocket = new UvTcpHandle(); acceptSocket.Init(Thread.Loop, Thread.QueueCloseHandle); listenSocket.Accept(acceptSocket); - var connection = new Connection(this, acceptSocket); + DispatchConnection(acceptSocket); + } + + protected virtual void DispatchConnection(UvTcpHandle socket) + { + var connection = new Connection(this, socket); connection.Start(); } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerPrimary.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerPrimary.cs new file mode 100644 index 0000000000..2de5c44ce5 --- /dev/null +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerPrimary.cs @@ -0,0 +1,88 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using Microsoft.AspNet.Server.Kestrel.Networking; +using System; +using System.Collections.Generic; +using System.Threading.Tasks; + +namespace Microsoft.AspNet.Server.Kestrel.Http +{ + public class ListenerPrimary : Listener + { + UvPipeHandle ListenPipe { get; set; } + + List _dispatchPipes = new List(); + int _dispatchIndex; + ArraySegment> _1234 = new ArraySegment>(new[] { new ArraySegment(new byte[] { 1, 2, 3, 4 }) }); + + public ListenerPrimary(IMemoryPool memory) : base(memory) + { + } + + public async Task StartAsync( + string pipeName, + string scheme, + string host, + int port, + KestrelThread thread, + Func application) + { + await StartAsync(scheme, host, port, thread, application); + + await Thread.PostAsync(_ => + { + ListenPipe = new UvPipeHandle(); + ListenPipe.Init(Thread.Loop, false); + ListenPipe.Bind(pipeName); + ListenPipe.Listen(128, OnListenPipe, null); + }, null); + } + + private void OnListenPipe(UvStreamHandle pipe, int status, Exception error, object state) + { + if (status < 0) + { + return; + } + + var dispatchPipe = new UvPipeHandle(); + dispatchPipe.Init(Thread.Loop, true); + try + { + pipe.Accept(dispatchPipe); + } + catch (Exception) + { + dispatchPipe.Dispose(); + return; + } + _dispatchPipes.Add(dispatchPipe); + } + + protected override void DispatchConnection(UvTcpHandle socket) + { + var index = _dispatchIndex++ % (_dispatchPipes.Count + 1); + if (index == _dispatchPipes.Count) + { + base.DispatchConnection(socket); + } + else + { + var dispatchPipe = _dispatchPipes[index]; + var write = new UvWriteReq(); + write.Init(Thread.Loop); + write.Write2( + dispatchPipe, + _1234, + socket, + (write2, status, error, state) => + { + write.Dispose(); + ((UvTcpHandle)state).Dispose(); + }, + socket); + } + } + } +} diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerSecondary.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerSecondary.cs new file mode 100644 index 0000000000..7f827f3452 --- /dev/null +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerSecondary.cs @@ -0,0 +1,106 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using Microsoft.AspNet.Server.Kestrel.Networking; +using System; +using System.Runtime.InteropServices; +using System.Threading.Tasks; + +namespace Microsoft.AspNet.Server.Kestrel.Http +{ + public class ListenerSecondary : ListenerContext, IDisposable + { + UvPipeHandle DispatchPipe { get; set; } + + public ListenerSecondary(IMemoryPool memory) + { + Memory = memory; + } + + public Task StartAsync( + string pipeName, + KestrelThread thread, + Func application) + { + Thread = thread; + Application = application; + + DispatchPipe = new UvPipeHandle(); + + var tcs = new TaskCompletionSource(); + Thread.Post(_ => + { + try + { + DispatchPipe.Init(Thread.Loop, true); + var connect = new UvConnectRequest(); + connect.Init(Thread.Loop); + connect.Connect( + DispatchPipe, + pipeName, + (connect2, status, error, state) => + { + connect.Dispose(); + if (error != null) + { + tcs.SetException(error); + return; + } + + try + { + var ptr = Marshal.AllocHGlobal(16); + var buf = Thread.Loop.Libuv.buf_init(ptr, 16); + + DispatchPipe.ReadStart( + (_1, _2, _3) => buf, + (_1, status2, error2, state2) => + { + if (status2 <= 0) + { + DispatchPipe.Dispose(); + Marshal.FreeHGlobal(ptr); + return; + } + + var acceptSocket = new UvTcpHandle(); + acceptSocket.Init(Thread.Loop, Thread.QueueCloseHandle); + DispatchPipe.Accept(acceptSocket); + + var connection = new Connection(this, acceptSocket); + connection.Start(); + }, + null); + + tcs.SetResult(0); + } + catch (Exception ex) + { + DispatchPipe.Dispose(); + tcs.SetException(ex); + } + }, + null); + } + catch (Exception ex) + { + DispatchPipe.Dispose(); + tcs.SetException(ex); + } + }, null); + return tcs.Task; + } + + public void Dispose() + { + // Ensure the event loop is still running. + // If the event loop isn't running and we try to wait on this Post + // to complete, then KestrelEngine will never be disposed and + // the exception that stopped the event loop will never be surfaced. + if (Thread.FatalError == null) + { + Thread.Send(_ => DispatchPipe.Dispose(), null); + } + } + } +} diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs index c971eca102..b2a2348c55 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs @@ -118,6 +118,18 @@ namespace Microsoft.AspNet.Server.Kestrel return tcs.Task; } + public void Send(Action callback, object state) + { + if (_loop.ThreadId == Thread.CurrentThread.ManagedThreadId) + { + callback.Invoke(state); + } + else + { + PostAsync(callback, state).Wait(); + } + } + private void PostCloseHandle(Action callback, IntPtr handle) { lock (_workSync) diff --git a/src/Microsoft.AspNet.Server.Kestrel/KestrelEngine.cs b/src/Microsoft.AspNet.Server.Kestrel/KestrelEngine.cs index 394d3a745c..45513365a0 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/KestrelEngine.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/KestrelEngine.cs @@ -38,10 +38,10 @@ namespace Microsoft.AspNet.Server.Kestrel : "amd64"; libraryPath = Path.Combine( - libraryPath, + libraryPath, "native", "windows", - architecture, + architecture, "libuv.dll"); } else if (Libuv.IsDarwin) @@ -91,16 +91,37 @@ namespace Microsoft.AspNet.Server.Kestrel public IDisposable CreateServer(string scheme, string host, int port, Func application) { - var listeners = new List(); + var listeners = new List(); try { + var pipeName = (Libuv.IsWindows ? @"\\.\pipe\kestrel_" : "/tmp/kestrel_") + Guid.NewGuid().ToString("n"); + + var single = Threads.Count == 1; + var first = true; + foreach (var thread in Threads) { - var listener = new Listener(Memory); + if (single) + { + var listener = new Listener(Memory); + listeners.Add(listener); + listener.StartAsync(scheme, host, port, thread, application).Wait(); + } + else if (first) + { + var listener = new ListenerPrimary(Memory); + listeners.Add(listener); + listener.StartAsync(pipeName, scheme, host, port, thread, application).Wait(); + } + else + { + var listener = new ListenerSecondary(Memory); + listeners.Add(listener); + listener.StartAsync(pipeName, thread, application).Wait(); + } - listeners.Add(listener); - listener.StartAsync(scheme, host, port, thread, application).Wait(); + first = false; } return new Disposable(() => { diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvStreamHandle.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvStreamHandle.cs index 4ed7b4781a..33c0008549 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvStreamHandle.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvStreamHandle.cs @@ -46,7 +46,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking _listenCallback = callback; _listenState = state; _listenVitality = GCHandle.Alloc(this, GCHandleType.Normal); - _uv.listen(this, 10, _uv_connection_cb); + _uv.listen(this, backlog, _uv_connection_cb); } catch { diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvWriteReq.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvWriteReq.cs index a97175b7c3..03eee35cd7 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvWriteReq.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvWriteReq.cs @@ -81,6 +81,54 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking } } + public unsafe void Write2( + UvStreamHandle handle, + ArraySegment> bufs, + UvStreamHandle sendHandle, + Action callback, + object state) + { + try + { + // add GCHandle to keeps this SafeHandle alive while request processing + _pins.Add(GCHandle.Alloc(this, GCHandleType.Normal)); + + var pBuffers = (Libuv.uv_buf_t*)_bufs; + var nBuffers = bufs.Count; + if (nBuffers > BUFFER_COUNT) + { + // create and pin buffer array when it's larger than the pre-allocated one + var bufArray = new Libuv.uv_buf_t[nBuffers]; + var gcHandle = GCHandle.Alloc(bufArray, GCHandleType.Pinned); + _pins.Add(gcHandle); + pBuffers = (Libuv.uv_buf_t*)gcHandle.AddrOfPinnedObject(); + } + + for (var index = 0; index != nBuffers; ++index) + { + // create and pin each segment being written + var buf = bufs.Array[bufs.Offset + index]; + + var gcHandle = GCHandle.Alloc(buf.Array, GCHandleType.Pinned); + _pins.Add(gcHandle); + pBuffers[index] = Libuv.buf_init( + gcHandle.AddrOfPinnedObject() + buf.Offset, + buf.Count); + } + + _callback = callback; + _state = state; + _uv.write2(this, handle, pBuffers, nBuffers, sendHandle, _uv_write_cb); + } + catch + { + _callback = null; + _state = null; + Unpin(this); + throw; + } + } + private static void Unpin(UvWriteReq req) { foreach (var pin in req._pins) diff --git a/src/Microsoft.AspNet.Server.Kestrel/project.json b/src/Microsoft.AspNet.Server.Kestrel/project.json index 35f11ed90e..fb04e22a0b 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/project.json +++ b/src/Microsoft.AspNet.Server.Kestrel/project.json @@ -6,7 +6,7 @@ "url": "git://github.com/aspnet/kestrelhttpserver" }, "dependencies": { - "Microsoft.Framework.Runtime.Abstractions": "1.0.0-*" + "Microsoft.Framework.Runtime.Abstractions": "1.0.0-beta7-*" }, "frameworks": { "dnx451": { }, diff --git a/test/Microsoft.AspNet.Server.KestrelTests/MultipleLoopTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/MultipleLoopTests.cs new file mode 100644 index 0000000000..651800e54e --- /dev/null +++ b/test/Microsoft.AspNet.Server.KestrelTests/MultipleLoopTests.cs @@ -0,0 +1,251 @@ +using Microsoft.AspNet.Server.Kestrel; +using Microsoft.AspNet.Server.Kestrel.Networking; +using Microsoft.Framework.Runtime; +using Microsoft.Framework.Runtime.Infrastructure; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net; +using System.Net.Sockets; +using System.Runtime.InteropServices; +using System.Threading; +using System.Threading.Tasks; +using Xunit; + +namespace Microsoft.AspNet.Server.KestrelTests +{ + public class MultipleLoopTests + { + Libuv _uv; + public MultipleLoopTests() + { + var engine = new KestrelEngine(LibraryManager, new ShutdownNotImplemented()); + _uv = engine.Libuv; + } + + ILibraryManager LibraryManager + { + get + { + var locator = CallContextServiceLocator.Locator; + if (locator == null) + { + return null; + } + var services = locator.ServiceProvider; + if (services == null) + { + return null; + } + return (ILibraryManager)services.GetService(typeof(ILibraryManager)); + } + } + + [Fact] + public void InitAndCloseServerPipe() + { + var loop = new UvLoopHandle(); + var pipe = new UvPipeHandle(); + + loop.Init(_uv); + pipe.Init(loop, true); + pipe.Bind(@"\\.\pipe\InitAndCloseServerPipe"); + pipe.Dispose(); + + loop.Run(); + + pipe.Dispose(); + loop.Dispose(); + + } + + [Fact] + public void ServerPipeListenForConnections() + { + var loop = new UvLoopHandle(); + var serverListenPipe = new UvPipeHandle(); + + loop.Init(_uv); + serverListenPipe.Init(loop, false); + serverListenPipe.Bind(@"\\.\pipe\ServerPipeListenForConnections"); + serverListenPipe.Listen(128, (_1, status, error, _2) => + { + var serverConnectionPipe = new UvPipeHandle(); + serverConnectionPipe.Init(loop, true); + try + { + serverListenPipe.Accept(serverConnectionPipe); + } + catch (Exception) + { + serverConnectionPipe.Dispose(); + return; + } + + var writeRequest = new UvWriteReq(); + writeRequest.Init(loop); + writeRequest.Write( + serverConnectionPipe, + new ArraySegment>(new ArraySegment[] { new ArraySegment(new byte[] { 1, 2, 3, 4 }) }), + (_3, status2, error2, _4) => + { + writeRequest.Dispose(); + serverConnectionPipe.Dispose(); + serverListenPipe.Dispose(); + }, + null); + + }, null); + + var worker = new Thread(() => + { + var loop2 = new UvLoopHandle(); + var clientConnectionPipe = new UvPipeHandle(); + var connect = new UvConnectRequest(); + + loop2.Init(_uv); + clientConnectionPipe.Init(loop2, true); + connect.Init(loop2); + connect.Connect(clientConnectionPipe, @"\\.\pipe\ServerPipeListenForConnections", (_1, status, error, _2) => + { + var buf = loop2.Libuv.buf_init(Marshal.AllocHGlobal(8192), 8192); + + connect.Dispose(); + clientConnectionPipe.ReadStart( + (_3, cb, _4) => buf, + (_3, status2, error2, _4) => + { + if (status2 <= 0) + { + clientConnectionPipe.Dispose(); + } + }, + null); + }, null); + loop2.Run(); + loop2.Dispose(); + }); + worker.Start(); + loop.Run(); + loop.Dispose(); + worker.Join(); + } + + + [Fact] + public void ServerPipeDispatchConnections() + { + + var loop = new UvLoopHandle(); + loop.Init(_uv); + + var serverConnectionPipe = default(UvPipeHandle); + + var serverListenPipe = new UvPipeHandle(); + serverListenPipe.Init(loop, false); + serverListenPipe.Bind(@"\\.\pipe\ServerPipeListenForConnections"); + serverListenPipe.Listen(128, (_1, status, error, _2) => + { + serverConnectionPipe = new UvPipeHandle(); + serverConnectionPipe.Init(loop, true); + try + { + serverListenPipe.Accept(serverConnectionPipe); + } + catch (Exception) + { + serverConnectionPipe.Dispose(); + serverConnectionPipe = null; + } + }, null); + + var serverListenTcp = new UvTcpHandle(); + serverListenTcp.Init(loop); + serverListenTcp.Bind(new IPEndPoint(0, 54321)); + serverListenTcp.Listen(128, (_1, status, error, _2) => + { + var serverConnectionTcp = new UvTcpHandle(); + serverConnectionTcp.Init(loop); + serverListenTcp.Accept(serverConnectionTcp); + + var writeRequest = new UvWriteReq(); + writeRequest.Init(loop); + writeRequest.Write2( + serverConnectionPipe, + new ArraySegment>(new ArraySegment[] { new ArraySegment(new byte[] { 1, 2, 3, 4 }) }), + serverConnectionTcp, + (_3, status2, error2, _4) => + { + writeRequest.Dispose(); + serverConnectionPipe.Dispose(); + serverConnectionTcp.Dispose(); + serverListenPipe.Dispose(); + serverListenTcp.Dispose(); + }, + null); + }, null); + + var worker = new Thread(() => + { + var loop2 = new UvLoopHandle(); + var clientConnectionPipe = new UvPipeHandle(); + var connect = new UvConnectRequest(); + + loop2.Init(_uv); + clientConnectionPipe.Init(loop2, true); + connect.Init(loop2); + connect.Connect(clientConnectionPipe, @"\\.\pipe\ServerPipeListenForConnections", (_1, status, error, _2) => + { + connect.Dispose(); + + var buf = loop2.Libuv.buf_init(Marshal.AllocHGlobal(64), 64); + clientConnectionPipe.ReadStart( + (_3, cb, _4) => buf, + (_3, status2, error2, _4) => + { + if (status2 <= 0) + { + clientConnectionPipe.Dispose(); + return; + } + var clientConnectionTcp = new UvTcpHandle(); + clientConnectionTcp.Init(loop2); + clientConnectionPipe.Accept(clientConnectionTcp); + var buf2 = loop2.Libuv.buf_init(Marshal.AllocHGlobal(64), 64); + clientConnectionTcp.ReadStart( + (_5, cb, _6) => buf2, + (_5, status3, error3, _6) => + { + if (status3 <= 0) + { + clientConnectionTcp.Dispose(); + } + }, + null); + }, + null); + }, null); + loop2.Run(); + loop2.Dispose(); + }); + + var worker2 = new Thread(() => + { + var socket = new Socket(SocketType.Stream, ProtocolType.IP); + socket.Connect(IPAddress.Loopback, 54321); + socket.Send(new byte[] { 6, 7, 8, 9 }); + socket.Shutdown(SocketShutdown.Send); + var cb = socket.Receive(new byte[64]); + socket.Dispose(); + }); + + worker.Start(); + worker2.Start(); + + loop.Run(); + loop.Dispose(); + worker.Join(); + worker2.Join(); + } + } +} diff --git a/test/Microsoft.AspNet.Server.KestrelTests/Program.cs b/test/Microsoft.AspNet.Server.KestrelTests/Program.cs index adcc2288c5..2cfa625390 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/Program.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/Program.cs @@ -1,6 +1,9 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using Microsoft.Framework.Runtime; +using System; + namespace Microsoft.AspNet.Server.KestrelTests { /// @@ -8,9 +11,21 @@ namespace Microsoft.AspNet.Server.KestrelTests /// public class Program { - public void Main() + private readonly IApplicationEnvironment env; + private readonly IServiceProvider sp; + + public Program(IApplicationEnvironment env, IServiceProvider sp) { - new EngineTests().DisconnectingClient().Wait(); + this.env = env; + this.sp = sp; + } + + public int Main() + { + return new Xunit.Runner.AspNet.Program(env, sp).Main(new string[] { + "-class", + typeof(MultipleLoopTests).FullName + }); } } } \ No newline at end of file diff --git a/test/Microsoft.AspNet.Server.KestrelTests/project.json b/test/Microsoft.AspNet.Server.KestrelTests/project.json index afb7e9ad47..68c1a69290 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/project.json +++ b/test/Microsoft.AspNet.Server.KestrelTests/project.json @@ -18,7 +18,7 @@ "allowUnsafe": true }, "commands": { - "run": "xunit.runner.aspnet", + "run": "Microsoft.AspNet.Server.KestrelTests", "test": "xunit.runner.aspnet" } } From 3d45602513b138ad02a275b48333353c6aa558bd Mon Sep 17 00:00:00 2001 From: Louis DeJardin Date: Fri, 24 Jul 2015 14:02:42 -0700 Subject: [PATCH 0151/1662] Catch Accept because of EAGAIN --- .../Http/ListenerSecondary.cs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerSecondary.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerSecondary.cs index 7f827f3452..bb60b6d708 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerSecondary.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerSecondary.cs @@ -3,6 +3,7 @@ using Microsoft.AspNet.Server.Kestrel.Networking; using System; +using System.Diagnostics; using System.Runtime.InteropServices; using System.Threading.Tasks; @@ -65,7 +66,17 @@ namespace Microsoft.AspNet.Server.Kestrel.Http var acceptSocket = new UvTcpHandle(); acceptSocket.Init(Thread.Loop, Thread.QueueCloseHandle); - DispatchPipe.Accept(acceptSocket); + + try + { + DispatchPipe.Accept(acceptSocket); + } + catch (Exception ex) + { + Trace.WriteLine("DispatchPipe.Accept " + ex.Message); + acceptSocket.Dispose(); + return; + } var connection = new Connection(this, acceptSocket); connection.Start(); From 598250a1d84b90f73596041cbb3f1f90688f0ee4 Mon Sep 17 00:00:00 2001 From: Louis DeJardin Date: Fri, 24 Jul 2015 15:23:01 -0700 Subject: [PATCH 0152/1662] Fixing pipe name in test --- .../Microsoft.AspNet.Server.KestrelTests/MultipleLoopTests.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/Microsoft.AspNet.Server.KestrelTests/MultipleLoopTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/MultipleLoopTests.cs index 651800e54e..31e632340b 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/MultipleLoopTests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/MultipleLoopTests.cs @@ -143,7 +143,7 @@ namespace Microsoft.AspNet.Server.KestrelTests var serverListenPipe = new UvPipeHandle(); serverListenPipe.Init(loop, false); - serverListenPipe.Bind(@"\\.\pipe\ServerPipeListenForConnections"); + serverListenPipe.Bind(@"\\.\pipe\ServerPipeDispatchConnections"); serverListenPipe.Listen(128, (_1, status, error, _2) => { serverConnectionPipe = new UvPipeHandle(); @@ -194,7 +194,7 @@ namespace Microsoft.AspNet.Server.KestrelTests loop2.Init(_uv); clientConnectionPipe.Init(loop2, true); connect.Init(loop2); - connect.Connect(clientConnectionPipe, @"\\.\pipe\ServerPipeListenForConnections", (_1, status, error, _2) => + connect.Connect(clientConnectionPipe, @"\\.\pipe\ServerPipeDispatchConnections", (_1, status, error, _2) => { connect.Dispose(); From b93845be190877c979dff137c64466128d1554e6 Mon Sep 17 00:00:00 2001 From: Louis DeJardin Date: Fri, 24 Jul 2015 15:25:44 -0700 Subject: [PATCH 0153/1662] Removing debug code --- src/Microsoft.AspNet.Server.Kestrel/Networking/Libuv.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/Libuv.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/Libuv.cs index 5429451f2f..86468bbbde 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/Libuv.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/Libuv.cs @@ -58,8 +58,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking public int Check(int statusCode) { - var x = Marshal.GetLastWin32Error(); - Exception error; var result = Check(statusCode, out error); if (error != null) From f935567cfdde7efac73ea2178d3f9dd42e66ec12 Mon Sep 17 00:00:00 2001 From: Louis DeJardin Date: Fri, 24 Jul 2015 15:36:45 -0700 Subject: [PATCH 0154/1662] Read callback status is always 0 for any error and EOF --- .../Http/ListenerSecondary.cs | 2 +- .../MultipleLoopTests.cs | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerSecondary.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerSecondary.cs index bb60b6d708..7bd97ed543 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerSecondary.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerSecondary.cs @@ -57,7 +57,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http (_1, _2, _3) => buf, (_1, status2, error2, state2) => { - if (status2 <= 0) + if (status2 == 0) { DispatchPipe.Dispose(); Marshal.FreeHGlobal(ptr); diff --git a/test/Microsoft.AspNet.Server.KestrelTests/MultipleLoopTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/MultipleLoopTests.cs index 31e632340b..7a4d3bdb89 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/MultipleLoopTests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/MultipleLoopTests.cs @@ -115,7 +115,7 @@ namespace Microsoft.AspNet.Server.KestrelTests (_3, cb, _4) => buf, (_3, status2, error2, _4) => { - if (status2 <= 0) + if (status2 == 0) { clientConnectionPipe.Dispose(); } @@ -203,7 +203,7 @@ namespace Microsoft.AspNet.Server.KestrelTests (_3, cb, _4) => buf, (_3, status2, error2, _4) => { - if (status2 <= 0) + if (status2 == 0) { clientConnectionPipe.Dispose(); return; @@ -216,7 +216,7 @@ namespace Microsoft.AspNet.Server.KestrelTests (_5, cb, _6) => buf2, (_5, status3, error3, _6) => { - if (status3 <= 0) + if (status3 == 0) { clientConnectionTcp.Dispose(); } From 62ec11be7ef3bfcf340e02b06b034adddae67e45 Mon Sep 17 00:00:00 2001 From: Louis DeJardin Date: Fri, 24 Jul 2015 15:43:43 -0700 Subject: [PATCH 0155/1662] Adding internal Constants class --- src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs | 3 ++- .../Http/ListenerPrimary.cs | 3 ++- .../Infrastructure/Constants.cs | 12 ++++++++++++ 3 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 src/Microsoft.AspNet.Server.Kestrel/Infrastructure/Constants.cs diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs index 64fca769dc..66a1028c3c 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs @@ -1,6 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using Microsoft.AspNet.Server.Kestrel.Infrastructure; using Microsoft.AspNet.Server.Kestrel.Networking; using System; using System.Diagnostics; @@ -53,7 +54,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http ListenSocket = new UvTcpHandle(); ListenSocket.Init(Thread.Loop, Thread.QueueCloseHandle); ListenSocket.Bind(new IPEndPoint(IPAddress.Any, port)); - ListenSocket.Listen(128, _connectionCallback, this); + ListenSocket.Listen(Constants.ListenBacklog, _connectionCallback, this); tcs.SetResult(0); } catch (Exception ex) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerPrimary.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerPrimary.cs index 2de5c44ce5..fb2e9dec6c 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerPrimary.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerPrimary.cs @@ -1,6 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using Microsoft.AspNet.Server.Kestrel.Infrastructure; using Microsoft.AspNet.Server.Kestrel.Networking; using System; using System.Collections.Generic; @@ -35,7 +36,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http ListenPipe = new UvPipeHandle(); ListenPipe.Init(Thread.Loop, false); ListenPipe.Bind(pipeName); - ListenPipe.Listen(128, OnListenPipe, null); + ListenPipe.Listen(Constants.ListenBacklog, OnListenPipe, null); }, null); } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/Constants.cs b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/Constants.cs new file mode 100644 index 0000000000..48d6dc93e9 --- /dev/null +++ b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/Constants.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace Microsoft.AspNet.Server.Kestrel.Infrastructure +{ + internal class Constants + { + public const int ListenBacklog = 128; + } +} From 17a846ad8e16c2412216b8216f5aeb59f5c1514c Mon Sep 17 00:00:00 2001 From: Louis DeJardin Date: Fri, 24 Jul 2015 15:44:27 -0700 Subject: [PATCH 0156/1662] Method not used by descendants --- src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs index 66a1028c3c..370c62ac0d 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs @@ -65,7 +65,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return tcs.Task; } - protected void OnConnection(UvStreamHandle listenSocket, int status) + private void OnConnection(UvStreamHandle listenSocket, int status) { var acceptSocket = new UvTcpHandle(); acceptSocket.Init(Thread.Loop, Thread.QueueCloseHandle); From baeb3e796242c58d3eb256b61cd3c1e737252495 Mon Sep 17 00:00:00 2001 From: Louis DeJardin Date: Fri, 24 Jul 2015 15:47:31 -0700 Subject: [PATCH 0157/1662] Fixing write2.Dispose() to avoid creating closure --- src/Microsoft.AspNet.Server.Kestrel/Http/ListenerPrimary.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerPrimary.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerPrimary.cs index fb2e9dec6c..ac2bdebe5c 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerPrimary.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerPrimary.cs @@ -79,7 +79,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http socket, (write2, status, error, state) => { - write.Dispose(); + write2.Dispose(); ((UvTcpHandle)state).Dispose(); }, socket); From e39fe60da0ea9457eb0fba04f179802e9a5577fc Mon Sep 17 00:00:00 2001 From: Louis DeJardin Date: Fri, 24 Jul 2015 16:19:15 -0700 Subject: [PATCH 0158/1662] Removing commented code --- .../Networking/UvPipeHandle.cs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvPipeHandle.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvPipeHandle.cs index 59e0fbf379..e110c57e6d 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvPipeHandle.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvPipeHandle.cs @@ -32,9 +32,5 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking { _uv.pipe_bind(this, name); } - - //public void Open(IntPtr hSocket) - //{ - //} } } From 10bce6a2ecd4c7ca1c1dcd110f5b729a4e98b246 Mon Sep 17 00:00:00 2001 From: Louis DeJardin Date: Sun, 26 Jul 2015 19:11:17 -0700 Subject: [PATCH 0159/1662] Constrain the timing on the dispatch test --- .../MultipleLoopTests.cs | 40 ++++++++++++++----- 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/test/Microsoft.AspNet.Server.KestrelTests/MultipleLoopTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/MultipleLoopTests.cs index 7a4d3bdb89..f9e53b1d81 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/MultipleLoopTests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/MultipleLoopTests.cs @@ -135,15 +135,18 @@ namespace Microsoft.AspNet.Server.KestrelTests [Fact] public void ServerPipeDispatchConnections() { + var pipeName = @"\\.\pipe\ServerPipeDispatchConnections" + Guid.NewGuid().ToString("n"); var loop = new UvLoopHandle(); loop.Init(_uv); var serverConnectionPipe = default(UvPipeHandle); + var serverConnectionPipeAcceptedEvent = new ManualResetEvent(false); + var serverConnectionTcpDisposedEvent = new ManualResetEvent(false); var serverListenPipe = new UvPipeHandle(); serverListenPipe.Init(loop, false); - serverListenPipe.Bind(@"\\.\pipe\ServerPipeDispatchConnections"); + serverListenPipe.Bind(pipeName); serverListenPipe.Listen(128, (_1, status, error, _2) => { serverConnectionPipe = new UvPipeHandle(); @@ -151,9 +154,11 @@ namespace Microsoft.AspNet.Server.KestrelTests try { serverListenPipe.Accept(serverConnectionPipe); + serverConnectionPipeAcceptedEvent.Set(); } - catch (Exception) + catch (Exception ex) { + Console.WriteLine(ex); serverConnectionPipe.Dispose(); serverConnectionPipe = null; } @@ -168,6 +173,8 @@ namespace Microsoft.AspNet.Server.KestrelTests serverConnectionTcp.Init(loop); serverListenTcp.Accept(serverConnectionTcp); + serverConnectionPipeAcceptedEvent.WaitOne(); + var writeRequest = new UvWriteReq(); writeRequest.Init(loop); writeRequest.Write2( @@ -177,8 +184,9 @@ namespace Microsoft.AspNet.Server.KestrelTests (_3, status2, error2, _4) => { writeRequest.Dispose(); - serverConnectionPipe.Dispose(); serverConnectionTcp.Dispose(); + serverConnectionTcpDisposedEvent.Set(); + serverConnectionPipe.Dispose(); serverListenPipe.Dispose(); serverListenTcp.Dispose(); }, @@ -194,11 +202,14 @@ namespace Microsoft.AspNet.Server.KestrelTests loop2.Init(_uv); clientConnectionPipe.Init(loop2, true); connect.Init(loop2); - connect.Connect(clientConnectionPipe, @"\\.\pipe\ServerPipeDispatchConnections", (_1, status, error, _2) => + connect.Connect(clientConnectionPipe, pipeName, (_1, status, error, _2) => { connect.Dispose(); var buf = loop2.Libuv.buf_init(Marshal.AllocHGlobal(64), 64); + + serverConnectionTcpDisposedEvent.WaitOne(); + clientConnectionPipe.ReadStart( (_3, cb, _4) => buf, (_3, status2, error2, _4) => @@ -231,12 +242,21 @@ namespace Microsoft.AspNet.Server.KestrelTests var worker2 = new Thread(() => { - var socket = new Socket(SocketType.Stream, ProtocolType.IP); - socket.Connect(IPAddress.Loopback, 54321); - socket.Send(new byte[] { 6, 7, 8, 9 }); - socket.Shutdown(SocketShutdown.Send); - var cb = socket.Receive(new byte[64]); - socket.Dispose(); + try + { + serverConnectionPipeAcceptedEvent.WaitOne(); + + var socket = new Socket(SocketType.Stream, ProtocolType.IP); + socket.Connect(IPAddress.Loopback, 54321); + socket.Send(new byte[] { 6, 7, 8, 9 }); + socket.Shutdown(SocketShutdown.Send); + var cb = socket.Receive(new byte[64]); + socket.Dispose(); + } + catch(Exception ex) + { + Console.WriteLine(ex); + } }); worker.Start(); From 5e6e5fec01efe5db13d3b89536ab62952c9e81aa Mon Sep 17 00:00:00 2001 From: Louis DeJardin Date: Mon, 27 Jul 2015 11:40:39 -0700 Subject: [PATCH 0160/1662] Adding an IKestralServerInformation.ThreadCount property Will default to 1 until multi-loop stability is ensured --- src/Kestrel/IKestrelServerInformation.cs | 10 ++++++++++ src/Kestrel/ServerFactory.cs | 2 +- src/Kestrel/ServerInformation.cs | 6 ++++-- 3 files changed, 15 insertions(+), 3 deletions(-) create mode 100644 src/Kestrel/IKestrelServerInformation.cs diff --git a/src/Kestrel/IKestrelServerInformation.cs b/src/Kestrel/IKestrelServerInformation.cs new file mode 100644 index 0000000000..a9fce59d09 --- /dev/null +++ b/src/Kestrel/IKestrelServerInformation.cs @@ -0,0 +1,10 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +namespace Kestrel +{ + public interface IKestrelServerInformation + { + int ThreadCount { get; set; } + } +} diff --git a/src/Kestrel/ServerFactory.cs b/src/Kestrel/ServerFactory.cs index ac60b4c4f2..784b1cdbdd 100644 --- a/src/Kestrel/ServerFactory.cs +++ b/src/Kestrel/ServerFactory.cs @@ -38,7 +38,7 @@ namespace Kestrel var disposables = new List(); var information = (ServerInformation)serverInformation; var engine = new KestrelEngine(_libraryManager, _appShutdownService); - engine.Start(Environment.ProcessorCount); + engine.Start(information.ThreadCount == 0 ? 1 : information.ThreadCount); foreach (var address in information.Addresses) { disposables.Add(engine.CreateServer( diff --git a/src/Kestrel/ServerInformation.cs b/src/Kestrel/ServerInformation.cs index dfbde7e91d..a3b770834c 100644 --- a/src/Kestrel/ServerInformation.cs +++ b/src/Kestrel/ServerInformation.cs @@ -8,7 +8,7 @@ using Microsoft.Framework.Configuration; namespace Kestrel { - public class ServerInformation : IServerInformation + public class ServerInformation : IServerInformation, IKestrelServerInformation { public ServerInformation() { @@ -25,7 +25,7 @@ namespace Kestrel foreach (var url in urls.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries)) { var address = ServerAddress.FromUrl(url); - if(address != null) + if (address != null) { Addresses.Add(address); } @@ -41,5 +41,7 @@ namespace Kestrel } public IList Addresses { get; private set; } + + public int ThreadCount { get; set; } } } From d723f9da210e97ead29cf4fae403ec0a8b4ad452 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Wed, 8 Jul 2015 11:50:11 -0700 Subject: [PATCH 0161/1662] Reduce calls to uv_write by calling it with multiple buffers when possible --- .../Http/SocketOutput.cs | 176 +++++++++++++----- 1 file changed, 131 insertions(+), 45 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs index 4c3e4c8cc8..b611b3cf00 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs @@ -3,15 +3,27 @@ using Microsoft.AspNet.Server.Kestrel.Networking; using System; +using System.Collections.Generic; using System.Threading; namespace Microsoft.AspNet.Server.Kestrel.Http { public class SocketOutput : ISocketOutput { + private const int _maxPendingWrites = 3; + private readonly KestrelThread _thread; private readonly UvStreamHandle _socket; + private WriteContext _nextWriteContext; + + // The number of write operations that have been scheduled so far + // but have not completed. + private int _writesSending = 0; + + // This locks all access to _nextWriteContext and _writesSending + private readonly object _lockObj = new object(); + public SocketOutput(KestrelThread thread, UvStreamHandle socket) { _thread = thread; @@ -26,71 +38,145 @@ namespace Microsoft.AspNet.Server.Kestrel.Http buffer = new ArraySegment(copy); KestrelTrace.Log.ConnectionWrite(0, buffer.Count); - var req = new ThisWriteReq(); - req.Init(_thread.Loop); - req.Contextualize(this, _socket, buffer, callback, state); - req.Write(); + + var context = new WriteOperation + { + Buffer = buffer, + Callback = callback, + State = state + }; + + lock (_lockObj) + { + if (_nextWriteContext == null) + { + _nextWriteContext = new WriteContext(this); + } + + _nextWriteContext.Operations.Add(context); + + if (_writesSending < _maxPendingWrites) + { + ScheduleWrite(); + _writesSending++; + } + } } - public class ThisWriteReq : UvWriteReq + private void ScheduleWrite() { - SocketOutput _self; - ArraySegment _buffer; - UvStreamHandle _socket; - Action _callback; - object _state; - Exception _callbackError; - - internal void Contextualize( - SocketOutput socketOutput, - UvStreamHandle socket, - ArraySegment buffer, - Action callback, - object state) + _thread.Post(obj => { - _self = socketOutput; - _socket = socket; - _buffer = buffer; - _callback = callback; - _state = state; - } + var self = (SocketOutput)obj; + self.WriteAllPending(); + }, this); + } - public void Write() + // This is called on the libuv event loop + private void WriteAllPending() + { + WriteContext writingContext; + + lock (_lockObj) { - _self._thread.Post(obj => + if (_nextWriteContext != null) { - var req = (ThisWriteReq)obj; - req.Write( - req._socket, - new ArraySegment>( - new[] { req._buffer }), - (r, status, error, state) => ((ThisWriteReq)state).OnWrite(status, error), - req); - }, this); + writingContext = _nextWriteContext; + _nextWriteContext = null; + } + else + { + _writesSending--; + return; + } } - private void OnWrite(int status, Exception error) + try + { + var buffers = new ArraySegment[writingContext.Operations.Count]; + + var i = 0; + foreach (var writeOp in writingContext.Operations) + { + buffers[i] = writeOp.Buffer; + i++; + } + + writingContext.WriteReq.Write(_socket, new ArraySegment>(buffers), (r, status, error, state) => + { + var writtenContext = (WriteContext)state; + writtenContext.Self.OnWriteCompleted(writtenContext.Operations, r, status, error); + }, writingContext); + } + catch + { + lock (_lockObj) + { + // Lock instead of using Interlocked.Decrement so _writesSending + // doesn't change in the middle of executing other synchronized code. + _writesSending--; + } + + throw; + } + } + + // This is called on the libuv event loop + private void OnWriteCompleted(List completedWrites, UvWriteReq req, int status, Exception error) + { + lock (_lockObj) + { + if (_nextWriteContext != null) + { + ScheduleWrite(); + } + else + { + _writesSending--; + } + } + + req.Dispose(); + + foreach (var writeOp in completedWrites) { KestrelTrace.Log.ConnectionWriteCallback(0, status); //NOTE: pool this? - Dispose(); - // Get off the event loop before calling user code! - _callbackError = error; + writeOp.Error = error; ThreadPool.QueueUserWorkItem(obj => { - var req = (ThisWriteReq)obj; - req._callback(req._callbackError, req._state); - }, this); - } + var op = (WriteOperation)obj; + op.Callback(op.Error, op.State); + }, writeOp); + } } - - public bool Flush(Action drained) + private class WriteOperation { - return false; + public ArraySegment Buffer; + public Exception Error; + public Action Callback; + public object State; } + private class WriteContext + { + public WriteContext(SocketOutput self) + { + Self = self; + + WriteReq = new UvWriteReq(); + WriteReq.Init(self._thread.Loop); + + Operations = new List(); + } + + public SocketOutput Self; + + public UvWriteReq WriteReq; + public List Operations; + } } } From 5b06a763672a20577ef775334473ae97f1d6e540 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Wed, 8 Jul 2015 12:42:32 -0700 Subject: [PATCH 0162/1662] Add sample that can produce large responses --- KestrelHttpServer.sln | 9 ++++- .../LargeResponseApp/LargeResponseApp.xproj | 19 ++++++++++ .../Microsoft.AspNet.Hosting.ini | 3 ++ samples/LargeResponseApp/Startup.cs | 38 +++++++++++++++++++ samples/LargeResponseApp/project.json | 16 ++++++++ 5 files changed, 84 insertions(+), 1 deletion(-) create mode 100644 samples/LargeResponseApp/LargeResponseApp.xproj create mode 100644 samples/LargeResponseApp/Microsoft.AspNet.Hosting.ini create mode 100644 samples/LargeResponseApp/Startup.cs create mode 100644 samples/LargeResponseApp/project.json diff --git a/KestrelHttpServer.sln b/KestrelHttpServer.sln index a9437d0659..d2ebe3ed3d 100644 --- a/KestrelHttpServer.sln +++ b/KestrelHttpServer.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 14 -VisualStudioVersion = 14.0.22111.0 +VisualStudioVersion = 14.0.22823.1 MinimumVisualStudioVersion = 10.0.40219.1 Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.Server.Kestrel", "src\Microsoft.AspNet.Server.Kestrel\Microsoft.AspNet.Server.Kestrel.xproj", "{F510611A-3BEE-4B88-A613-5F4A74ED82A1}" EndProject @@ -25,6 +25,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{D3273454-E EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "samples", "samples", "{8A3D00B8-1CCF-4BE6-A060-11104CE2D9CE}" EndProject +Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "LargeResponseApp", "samples\LargeResponseApp\LargeResponseApp.xproj", "{B35D4D31-E74C-4646-8A11-7A7A40F0021E}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -47,6 +49,10 @@ Global {30B7617E-58EF-4382-B3EA-5B2E718CF1A6}.Debug|Any CPU.Build.0 = Debug|Any CPU {30B7617E-58EF-4382-B3EA-5B2E718CF1A6}.Release|Any CPU.ActiveCfg = Release|Any CPU {30B7617E-58EF-4382-B3EA-5B2E718CF1A6}.Release|Any CPU.Build.0 = Release|Any CPU + {B35D4D31-E74C-4646-8A11-7A7A40F0021E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B35D4D31-E74C-4646-8A11-7A7A40F0021E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B35D4D31-E74C-4646-8A11-7A7A40F0021E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B35D4D31-E74C-4646-8A11-7A7A40F0021E}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -56,5 +62,6 @@ Global {37F3BFB2-6454-49E5-9D7F-581BF755CCFE} = {D3273454-EA07-41D2-BF0B-FCC3675C2483} {2C3CB3DC-EEBF-4F52-9E1C-4F2F972E76C3} = {8A3D00B8-1CCF-4BE6-A060-11104CE2D9CE} {30B7617E-58EF-4382-B3EA-5B2E718CF1A6} = {2D5D5227-4DBD-499A-96B1-76A36B03B750} + {B35D4D31-E74C-4646-8A11-7A7A40F0021E} = {8A3D00B8-1CCF-4BE6-A060-11104CE2D9CE} EndGlobalSection EndGlobal diff --git a/samples/LargeResponseApp/LargeResponseApp.xproj b/samples/LargeResponseApp/LargeResponseApp.xproj new file mode 100644 index 0000000000..48abc5f22c --- /dev/null +++ b/samples/LargeResponseApp/LargeResponseApp.xproj @@ -0,0 +1,19 @@ + + + + 14.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + + + + b35d4d31-e74c-4646-8a11-7a7a40f0021e + LargeResponseApp + ..\..\artifacts\obj\$(MSBuildProjectName) + ..\..\artifacts\bin\$(MSBuildProjectName)\ + + + 2.0 + 42216 + + + \ No newline at end of file diff --git a/samples/LargeResponseApp/Microsoft.AspNet.Hosting.ini b/samples/LargeResponseApp/Microsoft.AspNet.Hosting.ini new file mode 100644 index 0000000000..3fc5452c97 --- /dev/null +++ b/samples/LargeResponseApp/Microsoft.AspNet.Hosting.ini @@ -0,0 +1,3 @@ + +Server = Kestrel +Server.Urls = http://localhost:5001/ diff --git a/samples/LargeResponseApp/Startup.cs b/samples/LargeResponseApp/Startup.cs new file mode 100644 index 0000000000..407b1fdd49 --- /dev/null +++ b/samples/LargeResponseApp/Startup.cs @@ -0,0 +1,38 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using Microsoft.AspNet.Builder; +using System.Text; +using System.Threading.Tasks; + +namespace LargeResponseApp +{ + public class Startup + { + private const int _chunkSize = 4096; + private const int _defaultNumChunks = 16; + private static byte[] _chunk = Encoding.UTF8.GetBytes(new string('a', _chunkSize)); + private static Task _emptyTask = Task.FromResult(null); + + public void Configure(IApplicationBuilder app) + { + app.Run(async (context) => + { + int numChunks; + var path = context.Request.Path; + if (!path.HasValue || !int.TryParse(path.Value.Substring(1), out numChunks)) + { + numChunks = _defaultNumChunks; + } + + context.Response.ContentLength = _chunkSize * numChunks; + context.Response.ContentType = "text/plain"; + + for (int i = 0; i < numChunks; i++) + { + await context.Response.Body.WriteAsync(_chunk, 0, _chunkSize); + } + }); + } + } +} diff --git a/samples/LargeResponseApp/project.json b/samples/LargeResponseApp/project.json new file mode 100644 index 0000000000..f533e7ed47 --- /dev/null +++ b/samples/LargeResponseApp/project.json @@ -0,0 +1,16 @@ +{ + "version": "1.0.0-*", + "dependencies": { + "Kestrel": "1.0.0-*" + }, + + "frameworks": { + "dnx451": { }, + "dnxcore50": { } + }, + + "commands": { + "run": "Kestrel", + "web": "Microsoft.AspNet.Hosting" + } +} From 74fa82bca73e381bd251f40750e8b6637a7f6ccd Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Mon, 13 Jul 2015 10:34:19 -0700 Subject: [PATCH 0163/1662] Complete WriteAsync Tasks early when there are less than 64KB buffered --- .../Http/SocketOutput.cs | 99 +++++++++++++------ 1 file changed, 69 insertions(+), 30 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs index b611b3cf00..5deeb83672 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs @@ -11,23 +11,28 @@ namespace Microsoft.AspNet.Server.Kestrel.Http public class SocketOutput : ISocketOutput { private const int _maxPendingWrites = 3; + private const int _maxBytesBufferedBeforeThrottling = 65536 / 8; private readonly KestrelThread _thread; private readonly UvStreamHandle _socket; - private WriteContext _nextWriteContext; + // This locks all access to to all the below + private readonly object _lockObj = new object(); // The number of write operations that have been scheduled so far // but have not completed. - private int _writesSending = 0; + private int _writesPending = 0; - // This locks all access to _nextWriteContext and _writesSending - private readonly object _lockObj = new object(); + private int _numBytesBuffered = 0; + private Exception _lastWriteError; + private WriteContext _nextWriteContext; + private readonly Queue _callbacksPending; public SocketOutput(KestrelThread thread, UvStreamHandle socket) { _thread = thread; _socket = socket; + _callbacksPending = new Queue(); } public void Write(ArraySegment buffer, Action callback, object state) @@ -39,11 +44,16 @@ namespace Microsoft.AspNet.Server.Kestrel.Http KestrelTrace.Log.ConnectionWrite(0, buffer.Count); - var context = new WriteOperation + var writeOp = new WriteOperation + { + Buffer = buffer + }; + + var callbackContext = new CallbackContext { - Buffer = buffer, Callback = callback, - State = state + State = state, + BytesToWrite = buffer.Count }; lock (_lockObj) @@ -53,12 +63,26 @@ namespace Microsoft.AspNet.Server.Kestrel.Http _nextWriteContext = new WriteContext(this); } - _nextWriteContext.Operations.Add(context); + _nextWriteContext.Operations.Enqueue(writeOp); + _numBytesBuffered += buffer.Count; - if (_writesSending < _maxPendingWrites) + // Complete the write task immediately if all previous write tasks have been completed, + // the buffers haven't grown too large, and the last write to the socket succeeded. + if (_lastWriteError == null && + _callbacksPending.Count == 0 && + _numBytesBuffered < _maxBytesBufferedBeforeThrottling) + { + TriggerCallback(callbackContext); + } + else + { + _callbacksPending.Enqueue(callbackContext); + } + + if (_writesPending < _maxPendingWrites) { ScheduleWrite(); - _writesSending++; + _writesPending++; } } } @@ -86,7 +110,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } else { - _writesSending--; + _writesPending--; return; } } @@ -114,7 +138,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { // Lock instead of using Interlocked.Decrement so _writesSending // doesn't change in the middle of executing other synchronized code. - _writesSending--; + _writesPending--; } throw; @@ -122,43 +146,58 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } // This is called on the libuv event loop - private void OnWriteCompleted(List completedWrites, UvWriteReq req, int status, Exception error) + private void OnWriteCompleted(Queue completedWrites, UvWriteReq req, int status, Exception error) { lock (_lockObj) { + _lastWriteError = error; + if (_nextWriteContext != null) { ScheduleWrite(); } else { - _writesSending--; + _writesPending--; + } + + foreach (var writeOp in completedWrites) + { + _numBytesBuffered -= writeOp.Buffer.Count; + } + + var bytesLeftToBuffer = _maxBytesBufferedBeforeThrottling - _numBytesBuffered; + while (_callbacksPending.Count > 0 && _callbacksPending.Peek().BytesToWrite < bytesLeftToBuffer) + { + var context = _callbacksPending.Dequeue(); + TriggerCallback(context); } } req.Dispose(); + } - foreach (var writeOp in completedWrites) + private void TriggerCallback(CallbackContext context) + { + context.Error = _lastWriteError; + ThreadPool.QueueUserWorkItem(obj => { - KestrelTrace.Log.ConnectionWriteCallback(0, status); - //NOTE: pool this? + var c = (CallbackContext)obj; + c.Callback(c.Error, c.State); + }, context); + } - // Get off the event loop before calling user code! - writeOp.Error = error; - ThreadPool.QueueUserWorkItem(obj => - { - var op = (WriteOperation)obj; - op.Callback(op.Error, op.State); - }, writeOp); - } + private class CallbackContext + { + public Exception Error; + public Action Callback; + public object State; + public int BytesToWrite; } private class WriteOperation { public ArraySegment Buffer; - public Exception Error; - public Action Callback; - public object State; } private class WriteContext @@ -170,13 +209,13 @@ namespace Microsoft.AspNet.Server.Kestrel.Http WriteReq = new UvWriteReq(); WriteReq.Init(self._thread.Loop); - Operations = new List(); + Operations = new Queue(); } public SocketOutput Self; public UvWriteReq WriteReq; - public List Operations; + public Queue Operations; } } } From c345849707a69821b563307992700f4db0d004b2 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Wed, 15 Jul 2015 20:03:43 -0700 Subject: [PATCH 0164/1662] Don't use QueueUserWorkItem to trigger write callbacks immediately - In this case we are off the event loop, so we can invoke the callback directly. - Increase _maxBytesBufferedBeforeThrottling --- .../Http/SocketOutput.cs | 84 ++++++++----------- 1 file changed, 37 insertions(+), 47 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs index 5deeb83672..7ee91339e0 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs @@ -11,12 +11,12 @@ namespace Microsoft.AspNet.Server.Kestrel.Http public class SocketOutput : ISocketOutput { private const int _maxPendingWrites = 3; - private const int _maxBytesBufferedBeforeThrottling = 65536 / 8; + private const int _maxBytesBufferedBeforeThrottling = 65536; private readonly KestrelThread _thread; private readonly UvStreamHandle _socket; - // This locks all access to to all the below + // This locks access to to all of the below fields private readonly object _lockObj = new object(); // The number of write operations that have been scheduled so far @@ -44,17 +44,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http KestrelTrace.Log.ConnectionWrite(0, buffer.Count); - var writeOp = new WriteOperation - { - Buffer = buffer - }; - - var callbackContext = new CallbackContext - { - Callback = callback, - State = state, - BytesToWrite = buffer.Count - }; + bool triggerCallbackNow = false; lock (_lockObj) { @@ -63,20 +53,22 @@ namespace Microsoft.AspNet.Server.Kestrel.Http _nextWriteContext = new WriteContext(this); } - _nextWriteContext.Operations.Enqueue(writeOp); + _nextWriteContext.Buffers.Enqueue(buffer); _numBytesBuffered += buffer.Count; // Complete the write task immediately if all previous write tasks have been completed, // the buffers haven't grown too large, and the last write to the socket succeeded. - if (_lastWriteError == null && - _callbacksPending.Count == 0 && - _numBytesBuffered < _maxBytesBufferedBeforeThrottling) + triggerCallbackNow = _lastWriteError == null && + _callbacksPending.Count == 0 && + _numBytesBuffered <= _maxBytesBufferedBeforeThrottling; + if (!triggerCallbackNow) { - TriggerCallback(callbackContext); - } - else - { - _callbacksPending.Enqueue(callbackContext); + _callbacksPending.Enqueue(new CallbackContext + { + Callback = callback, + State = state, + BytesToWrite = buffer.Count + }); } if (_writesPending < _maxPendingWrites) @@ -85,6 +77,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http _writesPending++; } } + + if (triggerCallbackNow) + { + callback(null, state); + } } private void ScheduleWrite() @@ -117,19 +114,21 @@ namespace Microsoft.AspNet.Server.Kestrel.Http try { - var buffers = new ArraySegment[writingContext.Operations.Count]; + var buffers = new ArraySegment[writingContext.Buffers.Count]; var i = 0; - foreach (var writeOp in writingContext.Operations) + foreach (var buffer in writingContext.Buffers) { - buffers[i] = writeOp.Buffer; - i++; + buffers[i++] = buffer; } - writingContext.WriteReq.Write(_socket, new ArraySegment>(buffers), (r, status, error, state) => + var writeReq = new UvWriteReq(); + writeReq.Init(_thread.Loop); + + writeReq.Write(_socket, new ArraySegment>(buffers), (r, status, error, state) => { var writtenContext = (WriteContext)state; - writtenContext.Self.OnWriteCompleted(writtenContext.Operations, r, status, error); + writtenContext.Self.OnWriteCompleted(writtenContext.Buffers, r, status, error); }, writingContext); } catch @@ -146,8 +145,10 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } // This is called on the libuv event loop - private void OnWriteCompleted(Queue completedWrites, UvWriteReq req, int status, Exception error) + private void OnWriteCompleted(Queue> writtenBuffers, UvWriteReq req, int status, Exception error) { + KestrelTrace.Log.ConnectionWriteCallback(0, status); + lock (_lockObj) { _lastWriteError = error; @@ -161,16 +162,16 @@ namespace Microsoft.AspNet.Server.Kestrel.Http _writesPending--; } - foreach (var writeOp in completedWrites) + foreach (var writeBuffer in writtenBuffers) { - _numBytesBuffered -= writeOp.Buffer.Count; + _numBytesBuffered -= writeBuffer.Count; } var bytesLeftToBuffer = _maxBytesBufferedBeforeThrottling - _numBytesBuffered; - while (_callbacksPending.Count > 0 && _callbacksPending.Peek().BytesToWrite < bytesLeftToBuffer) + while (_callbacksPending.Count > 0 && + _callbacksPending.Peek().BytesToWrite <= bytesLeftToBuffer) { - var context = _callbacksPending.Dequeue(); - TriggerCallback(context); + TriggerCallback(_callbacksPending.Dequeue()); } } @@ -195,27 +196,16 @@ namespace Microsoft.AspNet.Server.Kestrel.Http public int BytesToWrite; } - private class WriteOperation - { - public ArraySegment Buffer; - } - private class WriteContext { public WriteContext(SocketOutput self) { Self = self; - - WriteReq = new UvWriteReq(); - WriteReq.Init(self._thread.Loop); - - Operations = new Queue(); + Buffers = new Queue>(); } public SocketOutput Self; - - public UvWriteReq WriteReq; - public Queue Operations; + public Queue> Buffers; } } } From cce9d8f09cb1a03c46628d69800325da7d880613 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Fri, 24 Jul 2015 16:47:05 -0700 Subject: [PATCH 0165/1662] Make SocketOutput more testable - Added a MockLibUv class - Create a SocketOutputTests class --- .../KestrelEngine.cs | 20 ++- .../Networking/Libuv.cs | 124 ++++++++-------- .../Networking/UvMemory.cs | 2 +- .../Properties/AssemblyInfo.cs | 2 + .../SocketOutputTests.cs | 133 ++++++++++++++++++ .../TestHelpers/MockLibUv.cs | 84 +++++++++++ 6 files changed, 298 insertions(+), 67 deletions(-) create mode 100644 test/Microsoft.AspNet.Server.KestrelTests/SocketOutputTests.cs create mode 100644 test/Microsoft.AspNet.Server.KestrelTests/TestHelpers/MockLibUv.cs diff --git a/src/Microsoft.AspNet.Server.Kestrel/KestrelEngine.cs b/src/Microsoft.AspNet.Server.Kestrel/KestrelEngine.cs index 45513365a0..49d3ac0a0b 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/KestrelEngine.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/KestrelEngine.cs @@ -14,11 +14,8 @@ namespace Microsoft.AspNet.Server.Kestrel public class KestrelEngine : IDisposable { public KestrelEngine(ILibraryManager libraryManager, IApplicationShutdown appShutdownService) + : this(appShutdownService) { - AppShutdown = appShutdownService; - Threads = new List(); - Listeners = new List(); - Memory = new MemoryPool(); Libuv = new Libuv(); var libraryPath = default(string); @@ -61,6 +58,21 @@ namespace Microsoft.AspNet.Server.Kestrel Libuv.Load(libraryPath); } + // For testing + internal KestrelEngine(Libuv uv, IApplicationShutdown appShutdownService) + : this(appShutdownService) + { + Libuv = uv; + } + + private KestrelEngine(IApplicationShutdown appShutdownService) + { + AppShutdown = appShutdownService; + Threads = new List(); + Listeners = new List(); + Memory = new MemoryPool(); + } + public Libuv Libuv { get; private set; } public IMemoryPool Memory { get; set; } public IApplicationShutdown AppShutdown { get; private set; } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/Libuv.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/Libuv.cs index 86468bbbde..4ff90ecd5b 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/Libuv.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/Libuv.cs @@ -84,16 +84,16 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - delegate int uv_loop_init(UvLoopHandle a0); - uv_loop_init _uv_loop_init = default(uv_loop_init); + protected delegate int uv_loop_init(UvLoopHandle a0); + protected uv_loop_init _uv_loop_init = default(uv_loop_init); public void loop_init(UvLoopHandle handle) { Check(_uv_loop_init(handle)); } [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - delegate int uv_loop_close(IntPtr a0); - uv_loop_close _uv_loop_close = default(uv_loop_close); + protected delegate int uv_loop_close(IntPtr a0); + protected uv_loop_close _uv_loop_close = default(uv_loop_close); public void loop_close(UvLoopHandle handle) { handle.Validate(closed: true); @@ -101,8 +101,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking } [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - delegate int uv_run(UvLoopHandle handle, int mode); - uv_run _uv_run = default(uv_run); + protected delegate int uv_run(UvLoopHandle handle, int mode); + protected uv_run _uv_run = default(uv_run); public int run(UvLoopHandle handle, int mode) { handle.Validate(); @@ -110,8 +110,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking } [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - delegate void uv_stop(UvLoopHandle handle); - uv_stop _uv_stop = default(uv_stop); + protected delegate void uv_stop(UvLoopHandle handle); + protected uv_stop _uv_stop = default(uv_stop); public void stop(UvLoopHandle handle) { handle.Validate(); @@ -119,8 +119,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking } [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - delegate void uv_ref(UvHandle handle); - uv_ref _uv_ref = default(uv_ref); + protected delegate void uv_ref(UvHandle handle); + protected uv_ref _uv_ref = default(uv_ref); public void @ref(UvHandle handle) { handle.Validate(); @@ -128,8 +128,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking } [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - delegate void uv_unref(UvHandle handle); - uv_unref _uv_unref = default(uv_unref); + protected delegate void uv_unref(UvHandle handle); + protected uv_unref _uv_unref = default(uv_unref); public void unref(UvHandle handle) { handle.Validate(); @@ -140,8 +140,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking [UnmanagedFunctionPointer(CallingConvention.Cdecl)] public delegate void uv_close_cb(IntPtr handle); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - delegate void uv_close(IntPtr handle, uv_close_cb close_cb); - uv_close _uv_close = default(uv_close); + protected delegate void uv_close(IntPtr handle, uv_close_cb close_cb); + protected uv_close _uv_close = default(uv_close); public void close(UvHandle handle, uv_close_cb close_cb) { handle.Validate(closed: true); @@ -155,8 +155,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking [UnmanagedFunctionPointer(CallingConvention.Cdecl)] public delegate void uv_async_cb(IntPtr handle); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - delegate int uv_async_init(UvLoopHandle loop, UvAsyncHandle handle, uv_async_cb cb); - uv_async_init _uv_async_init = default(uv_async_init); + protected delegate int uv_async_init(UvLoopHandle loop, UvAsyncHandle handle, uv_async_cb cb); + protected uv_async_init _uv_async_init = default(uv_async_init); public void async_init(UvLoopHandle loop, UvAsyncHandle handle, uv_async_cb cb) { loop.Validate(); @@ -165,16 +165,16 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking } [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - delegate int uv_async_send(UvAsyncHandle handle); - uv_async_send _uv_async_send = default(uv_async_send); + protected delegate int uv_async_send(UvAsyncHandle handle); + protected uv_async_send _uv_async_send = default(uv_async_send); public void async_send(UvAsyncHandle handle) { Check(_uv_async_send(handle)); } [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - delegate int uv_tcp_init(UvLoopHandle loop, UvTcpHandle handle); - uv_tcp_init _uv_tcp_init = default(uv_tcp_init); + protected delegate int uv_tcp_init(UvLoopHandle loop, UvTcpHandle handle); + protected uv_tcp_init _uv_tcp_init = default(uv_tcp_init); public void tcp_init(UvLoopHandle loop, UvTcpHandle handle) { loop.Validate(); @@ -183,8 +183,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking } [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - delegate int uv_tcp_bind(UvTcpHandle handle, ref sockaddr addr, int flags); - uv_tcp_bind _uv_tcp_bind = default(uv_tcp_bind); + protected delegate int uv_tcp_bind(UvTcpHandle handle, ref sockaddr addr, int flags); + protected uv_tcp_bind _uv_tcp_bind = default(uv_tcp_bind); public void tcp_bind(UvTcpHandle handle, ref sockaddr addr, int flags) { handle.Validate(); @@ -192,8 +192,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking } [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - delegate int uv_tcp_open(UvTcpHandle handle, IntPtr hSocket); - uv_tcp_open _uv_tcp_open = default(uv_tcp_open); + protected delegate int uv_tcp_open(UvTcpHandle handle, IntPtr hSocket); + protected uv_tcp_open _uv_tcp_open = default(uv_tcp_open); public void tcp_open(UvTcpHandle handle, IntPtr hSocket) { handle.Validate(); @@ -201,8 +201,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking } [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - delegate int uv_pipe_init(UvLoopHandle loop, UvPipeHandle handle, int ipc); - uv_pipe_init _uv_pipe_init = default(uv_pipe_init); + protected delegate int uv_pipe_init(UvLoopHandle loop, UvPipeHandle handle, int ipc); + protected uv_pipe_init _uv_pipe_init = default(uv_pipe_init); public void pipe_init(UvLoopHandle loop, UvPipeHandle handle, bool ipc) { loop.Validate(); @@ -211,8 +211,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking } [UnmanagedFunctionPointer(CallingConvention.Cdecl, CharSet = CharSet.Ansi)] - delegate int uv_pipe_bind(UvPipeHandle loop, string name); - uv_pipe_bind _uv_pipe_bind = default(uv_pipe_bind); + protected delegate int uv_pipe_bind(UvPipeHandle loop, string name); + protected uv_pipe_bind _uv_pipe_bind = default(uv_pipe_bind); public void pipe_bind(UvPipeHandle handle, string name) { handle.Validate(); @@ -222,8 +222,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking [UnmanagedFunctionPointer(CallingConvention.Cdecl)] public delegate void uv_connection_cb(IntPtr server, int status); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - delegate int uv_listen(UvStreamHandle handle, int backlog, uv_connection_cb cb); - uv_listen _uv_listen = default(uv_listen); + protected delegate int uv_listen(UvStreamHandle handle, int backlog, uv_connection_cb cb); + protected uv_listen _uv_listen = default(uv_listen); public void listen(UvStreamHandle handle, int backlog, uv_connection_cb cb) { handle.Validate(); @@ -231,8 +231,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking } [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - delegate int uv_accept(UvStreamHandle server, UvStreamHandle client); - uv_accept _uv_accept = default(uv_accept); + protected delegate int uv_accept(UvStreamHandle server, UvStreamHandle client); + protected uv_accept _uv_accept = default(uv_accept); public void accept(UvStreamHandle server, UvStreamHandle client) { server.Validate(); @@ -243,8 +243,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking [UnmanagedFunctionPointer(CallingConvention.Cdecl)] public delegate void uv_connect_cb(IntPtr req, int status); [UnmanagedFunctionPointer(CallingConvention.Cdecl, CharSet = CharSet.Ansi)] - unsafe delegate int uv_pipe_connect(UvConnectRequest req, UvPipeHandle handle, string name, uv_connect_cb cb); - uv_pipe_connect _uv_pipe_connect = default(uv_pipe_connect); + unsafe protected delegate int uv_pipe_connect(UvConnectRequest req, UvPipeHandle handle, string name, uv_connect_cb cb); + protected uv_pipe_connect _uv_pipe_connect = default(uv_pipe_connect); unsafe public void pipe_connect(UvConnectRequest req, UvPipeHandle handle, string name, uv_connect_cb cb) { req.Validate(); @@ -257,8 +257,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking [UnmanagedFunctionPointer(CallingConvention.Cdecl)] public delegate void uv_read_cb(IntPtr server, int nread, ref uv_buf_t buf); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - delegate int uv_read_start(UvStreamHandle handle, uv_alloc_cb alloc_cb, uv_read_cb read_cb); - uv_read_start _uv_read_start = default(uv_read_start); + protected delegate int uv_read_start(UvStreamHandle handle, uv_alloc_cb alloc_cb, uv_read_cb read_cb); + protected uv_read_start _uv_read_start = default(uv_read_start); public void read_start(UvStreamHandle handle, uv_alloc_cb alloc_cb, uv_read_cb read_cb) { handle.Validate(); @@ -266,8 +266,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking } [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - delegate int uv_read_stop(UvStreamHandle handle); - uv_read_stop _uv_read_stop = default(uv_read_stop); + protected delegate int uv_read_stop(UvStreamHandle handle); + protected uv_read_stop _uv_read_stop = default(uv_read_stop); public void read_stop(UvStreamHandle handle) { handle.Validate(); @@ -275,8 +275,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking } [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - delegate int uv_try_write(UvStreamHandle handle, Libuv.uv_buf_t[] bufs, int nbufs); - uv_try_write _uv_try_write = default(uv_try_write); + protected delegate int uv_try_write(UvStreamHandle handle, Libuv.uv_buf_t[] bufs, int nbufs); + protected uv_try_write _uv_try_write = default(uv_try_write); public int try_write(UvStreamHandle handle, Libuv.uv_buf_t[] bufs, int nbufs) { handle.Validate(); @@ -286,8 +286,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking [UnmanagedFunctionPointer(CallingConvention.Cdecl)] public delegate void uv_write_cb(IntPtr req, int status); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - unsafe delegate int uv_write(UvRequest req, UvStreamHandle handle, Libuv.uv_buf_t* bufs, int nbufs, uv_write_cb cb); - uv_write _uv_write = default(uv_write); + unsafe protected delegate int uv_write(UvRequest req, UvStreamHandle handle, Libuv.uv_buf_t* bufs, int nbufs, uv_write_cb cb); + protected uv_write _uv_write = default(uv_write); unsafe public void write(UvRequest req, UvStreamHandle handle, Libuv.uv_buf_t* bufs, int nbufs, uv_write_cb cb) { req.Validate(); @@ -296,8 +296,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking } [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - unsafe delegate int uv_write2(UvRequest req, UvStreamHandle handle, Libuv.uv_buf_t* bufs, int nbufs, UvStreamHandle sendHandle, uv_write_cb cb); - uv_write2 _uv_write2 = default(uv_write2); + unsafe protected delegate int uv_write2(UvRequest req, UvStreamHandle handle, Libuv.uv_buf_t* bufs, int nbufs, UvStreamHandle sendHandle, uv_write_cb cb); + protected uv_write2 _uv_write2 = default(uv_write2); unsafe public void write2(UvRequest req, UvStreamHandle handle, Libuv.uv_buf_t* bufs, int nbufs, UvStreamHandle sendHandle, uv_write_cb cb) { req.Validate(); @@ -308,8 +308,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking [UnmanagedFunctionPointer(CallingConvention.Cdecl)] public delegate void uv_shutdown_cb(IntPtr req, int status); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - delegate int uv_shutdown(UvShutdownReq req, UvStreamHandle handle, uv_shutdown_cb cb); - uv_shutdown _uv_shutdown = default(uv_shutdown); + protected delegate int uv_shutdown(UvShutdownReq req, UvStreamHandle handle, uv_shutdown_cb cb); + protected uv_shutdown _uv_shutdown = default(uv_shutdown); public void shutdown(UvShutdownReq req, UvStreamHandle handle, uv_shutdown_cb cb) { req.Validate(); @@ -318,8 +318,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking } [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - delegate IntPtr uv_err_name(int err); - uv_err_name _uv_err_name = default(uv_err_name); + protected delegate IntPtr uv_err_name(int err); + protected uv_err_name _uv_err_name = default(uv_err_name); public unsafe String err_name(int err) { IntPtr ptr = _uv_err_name(err); @@ -327,8 +327,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking } [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - delegate IntPtr uv_strerror(int err); - uv_strerror _uv_strerror = default(uv_strerror); + protected delegate IntPtr uv_strerror(int err); + protected uv_strerror _uv_strerror = default(uv_strerror); public unsafe String strerror(int err) { IntPtr ptr = _uv_strerror(err); @@ -336,42 +336,42 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking } [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - delegate int uv_loop_size(); - uv_loop_size _uv_loop_size = default(uv_loop_size); + protected delegate int uv_loop_size(); + protected uv_loop_size _uv_loop_size = default(uv_loop_size); public int loop_size() { return _uv_loop_size(); } [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - delegate int uv_handle_size(HandleType handleType); - uv_handle_size _uv_handle_size = default(uv_handle_size); + protected delegate int uv_handle_size(HandleType handleType); + protected uv_handle_size _uv_handle_size = default(uv_handle_size); public int handle_size(HandleType handleType) { return _uv_handle_size(handleType); } [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - delegate int uv_req_size(RequestType reqType); - uv_req_size _uv_req_size = default(uv_req_size); + protected delegate int uv_req_size(RequestType reqType); + protected uv_req_size _uv_req_size = default(uv_req_size); public int req_size(RequestType reqType) { return _uv_req_size(reqType); } [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - delegate int uv_ip4_addr(string ip, int port, out sockaddr addr); + protected delegate int uv_ip4_addr(string ip, int port, out sockaddr addr); - uv_ip4_addr _uv_ip4_addr = default(uv_ip4_addr); + protected uv_ip4_addr _uv_ip4_addr = default(uv_ip4_addr); public int ip4_addr(string ip, int port, out sockaddr addr, out Exception error) { return Check(_uv_ip4_addr(ip, port, out addr), out error); } [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - delegate int uv_ip6_addr(string ip, int port, out sockaddr addr); + protected delegate int uv_ip6_addr(string ip, int port, out sockaddr addr); - uv_ip6_addr _uv_ip6_addr = default(uv_ip6_addr); + protected uv_ip6_addr _uv_ip6_addr = default(uv_ip6_addr); public int ip6_addr(string ip, int port, out sockaddr addr, out Exception error) { return Check(_uv_ip6_addr(ip, port, out addr), out error); @@ -380,8 +380,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking [UnmanagedFunctionPointer(CallingConvention.Cdecl)] public delegate void uv_walk_cb(IntPtr handle, IntPtr arg); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - unsafe delegate int uv_walk(UvLoopHandle loop, uv_walk_cb walk_cb, IntPtr arg); - uv_walk _uv_walk = default(uv_walk); + unsafe protected delegate int uv_walk(UvLoopHandle loop, uv_walk_cb walk_cb, IntPtr arg); + protected uv_walk _uv_walk = default(uv_walk); unsafe public void walk(UvLoopHandle loop, uv_walk_cb walk_cb, IntPtr arg) { loop.Validate(); diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvMemory.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvMemory.cs index 37e75ef537..f9d0e11ed2 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvMemory.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvMemory.cs @@ -14,7 +14,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking public abstract class UvMemory : SafeHandle { protected Libuv _uv; - private int _threadId; + protected int _threadId; public UvMemory() : base(IntPtr.Zero, true) { diff --git a/src/Microsoft.AspNet.Server.Kestrel/Properties/AssemblyInfo.cs b/src/Microsoft.AspNet.Server.Kestrel/Properties/AssemblyInfo.cs index 025a94598c..573f5c3634 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Properties/AssemblyInfo.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Properties/AssemblyInfo.cs @@ -2,5 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Reflection; +using System.Runtime.CompilerServices; +[assembly: InternalsVisibleTo("Microsoft.AspNet.Server.KestrelTests")] [assembly: AssemblyMetadata("Serviceable", "True")] \ No newline at end of file diff --git a/test/Microsoft.AspNet.Server.KestrelTests/SocketOutputTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/SocketOutputTests.cs new file mode 100644 index 0000000000..bb95a96507 --- /dev/null +++ b/test/Microsoft.AspNet.Server.KestrelTests/SocketOutputTests.cs @@ -0,0 +1,133 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Collections.Generic; +using System.Threading; +using Microsoft.AspNet.Server.Kestrel; +using Microsoft.AspNet.Server.Kestrel.Http; +using Microsoft.AspNet.Server.Kestrel.Networking; +using Microsoft.AspNet.Server.KestrelTests.TestHelpers; +using Xunit; + +namespace Microsoft.AspNet.Server.KestrelTests +{ + public class SocketOutputTests + { + [Fact] + public void CanWrite1MB() + { + // This test was added because when initially implementing write-behind buffering in + // SocketOutput, the write callback would never be invoked for writes larger than + // _maxBytesPreCompleted even after the write actually completed. + + // Arrange + var mockLibuv = new MockLibuv + { + OnWrite = (socket, buffers, triggerCompleted) => + { + triggerCompleted(0); + return 0; + } + }; + + using (var kestrelEngine = new KestrelEngine(mockLibuv, new ShutdownNotImplemented())) + { + kestrelEngine.Start(count: 1); + + var kestrelThread = kestrelEngine.Threads[0]; + var socket = new MockSocket(kestrelThread.Loop.ThreadId); + var socketOutput = new SocketOutput(kestrelThread, socket); + + // I doubt _maxBytesPreCompleted will ever be over a MB. If it is, we should change this test. + var bufferSize = 1048576; + var buffer = new ArraySegment(new byte[bufferSize], 0, bufferSize); + var completedWh = new ManualResetEventSlim(); + Action onCompleted = (ex, state) => + { + Assert.Null(ex); + Assert.Null(state); + completedWh.Set(); + }; + + // Act + socketOutput.Write(buffer, onCompleted, state: null); + + // Assert + Assert.True(completedWh.Wait(100)); + } + } + + [Fact] + public void WritesDontCompleteImmediatelyWhenTooManyBytesAreAlreadyPreCompleted() + { + // This should match _maxBytesPreCompleted in SocketOutput + var maxBytesPreCompleted = 65536; + var completeQueue = new Queue>(); + + // Arrange + var mockLibuv = new MockLibuv + { + OnWrite = (socket, buffers, triggerCompleted) => + { + completeQueue.Enqueue(triggerCompleted); + return 0; + } + }; + + using (var kestrelEngine = new KestrelEngine(mockLibuv, new ShutdownNotImplemented())) + { + kestrelEngine.Start(count: 1); + + var kestrelThread = kestrelEngine.Threads[0]; + var socket = new MockSocket(kestrelThread.Loop.ThreadId); + var socketOutput = new SocketOutput(kestrelThread, socket); + + var bufferSize = maxBytesPreCompleted; + var buffer = new ArraySegment(new byte[bufferSize], 0, bufferSize); + var completedWh = new ManualResetEventSlim(); + Action onCompleted = (ex, state) => + { + Assert.Null(ex); + Assert.Null(state); + completedWh.Set(); + }; + + // Act + socketOutput.Write(buffer, onCompleted, state: null); + // Assert + // The first write should pre-complete since it is <= _maxBytesPreCompleted. + Assert.True(completedWh.Wait(100)); + // Arrange + completedWh.Reset(); + // Act + socketOutput.Write(buffer, onCompleted, state: null); + // Assert + // Too many bytes are already pre-completed for the second write to pre-complete. + Assert.False(completedWh.Wait(100)); + // Act + completeQueue.Dequeue()(0); + // Assert + // Finishing the first write should allow the second write to pre-complete. + Assert.True(completedWh.Wait(100)); + } + } + + private class MockSocket : UvStreamHandle + { + public MockSocket(int threadId) + { + // Set the handle to something other than IntPtr.Zero + // so handle.Validate doesn't fail in Libuv.write + handle = (IntPtr)1; + _threadId = threadId; + } + + protected override bool ReleaseHandle() + { + // No-op + return true; + } + } + } +} diff --git a/test/Microsoft.AspNet.Server.KestrelTests/TestHelpers/MockLibUv.cs b/test/Microsoft.AspNet.Server.KestrelTests/TestHelpers/MockLibUv.cs new file mode 100644 index 0000000000..a23cd076ce --- /dev/null +++ b/test/Microsoft.AspNet.Server.KestrelTests/TestHelpers/MockLibUv.cs @@ -0,0 +1,84 @@ +using System; +using System.Threading; +using Microsoft.AspNet.Server.Kestrel.Networking; + +namespace Microsoft.AspNet.Server.KestrelTests.TestHelpers +{ + public class MockLibuv : Libuv + { + private UvAsyncHandle _postHandle; + private uv_async_cb _onPost; + + private bool _stopLoop; + private readonly ManualResetEventSlim _loopWh = new ManualResetEventSlim(); + + private Func>, Action, int> _onWrite; + + unsafe public MockLibuv() + { + _uv_write = UvWrite; + + _uv_async_send = postHandle => + { + _loopWh.Set(); + + return 0; + }; + + _uv_async_init = (loop, postHandle, callback) => + { + _postHandle = postHandle; + _onPost = callback; + + return 0; + }; + + _uv_run = (loopHandle, mode) => + { + while (!_stopLoop) + { + _loopWh.Wait(); + _loopWh.Reset(); + _onPost(_postHandle.InternalGetHandle()); + } + + _postHandle.Dispose(); + loopHandle.Dispose(); + return 0; + }; + + _uv_stop = handle => + { + _stopLoop = true; + _loopWh.Set(); + }; + + _uv_req_size = reqType => IntPtr.Size; + _uv_loop_size = () => IntPtr.Size; + _uv_handle_size = handleType => IntPtr.Size; + _uv_loop_init = loop => 0; + _uv_tcp_init = (loopHandle, tcpHandle) => 0; + _uv_close = (handle, callback) => callback(handle); + _uv_loop_close = handle => 0; + _uv_unref = handle => { }; + _uv_walk = (loop, callback, ignore) => 0; + } + + public Func>, Action, int> OnWrite + { + get + { + return _onWrite; + } + set + { + _onWrite = value; + } + } + + unsafe private int UvWrite(UvRequest req, UvStreamHandle handle, uv_buf_t* bufs, int nbufs, uv_write_cb cb) + { + return _onWrite(handle, new ArraySegment>(), status => cb(req.InternalGetHandle(), status)); + } + } +} From 47d7f73bdce175e6a47acbd96c6ec04b91c078b4 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Mon, 27 Jul 2015 19:40:27 -0700 Subject: [PATCH 0166/1662] Fix SocketOutput so that it can now complete large writes - Complete in this context means that the callback gets invoked. - Previously, calls to write would never complete if the buffer contained more than 64 KB (_maxBytesPreCompleted). - This is tested by SocketOutputTests.CanWrite1MB. --- .../Http/SocketOutput.cs | 34 ++++++++++++++----- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs index 7ee91339e0..45253dfe98 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs @@ -5,13 +5,14 @@ using Microsoft.AspNet.Server.Kestrel.Networking; using System; using System.Collections.Generic; using System.Threading; +using System.Diagnostics; namespace Microsoft.AspNet.Server.Kestrel.Http { public class SocketOutput : ISocketOutput { private const int _maxPendingWrites = 3; - private const int _maxBytesBufferedBeforeThrottling = 65536; + private const int _maxBytesPreCompleted = 65536; private readonly KestrelThread _thread; private readonly UvStreamHandle _socket; @@ -23,7 +24,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http // but have not completed. private int _writesPending = 0; - private int _numBytesBuffered = 0; + private int _numBytesPreCompleted = 0; private Exception _lastWriteError; private WriteContext _nextWriteContext; private readonly Queue _callbacksPending; @@ -54,14 +55,17 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } _nextWriteContext.Buffers.Enqueue(buffer); - _numBytesBuffered += buffer.Count; // Complete the write task immediately if all previous write tasks have been completed, // the buffers haven't grown too large, and the last write to the socket succeeded. triggerCallbackNow = _lastWriteError == null && _callbacksPending.Count == 0 && - _numBytesBuffered <= _maxBytesBufferedBeforeThrottling; - if (!triggerCallbackNow) + _numBytesPreCompleted + buffer.Count <= _maxBytesPreCompleted; + if (triggerCallbackNow) + { + _numBytesPreCompleted += buffer.Count; + } + else { _callbacksPending.Enqueue(new CallbackContext { @@ -78,6 +82,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } + // Make sure we call user code outside of the lock. if (triggerCallbackNow) { callback(null, state); @@ -164,15 +169,28 @@ namespace Microsoft.AspNet.Server.Kestrel.Http foreach (var writeBuffer in writtenBuffers) { - _numBytesBuffered -= writeBuffer.Count; + // _numBytesPreCompleted can temporarily go negative in the event there are + // completed writes that we haven't triggered callbacks for yet. + _numBytesPreCompleted -= writeBuffer.Count; } - var bytesLeftToBuffer = _maxBytesBufferedBeforeThrottling - _numBytesBuffered; + + // bytesLeftToBuffer can be greater than _maxBytesPreCompleted + // This allows large writes to complete once they've actually finished. + var bytesLeftToBuffer = _maxBytesPreCompleted - _numBytesPreCompleted; while (_callbacksPending.Count > 0 && _callbacksPending.Peek().BytesToWrite <= bytesLeftToBuffer) { - TriggerCallback(_callbacksPending.Dequeue()); + var callbackContext = _callbacksPending.Dequeue(); + + _numBytesPreCompleted += callbackContext.BytesToWrite; + + TriggerCallback(callbackContext); } + + // Now that the while loop has completed the following invariants should hold true: + Trace.Assert(_numBytesPreCompleted >= 0); + Trace.Assert(_numBytesPreCompleted <= _maxBytesPreCompleted); } req.Dispose(); From 343d69828649ffca6b0e8bb46aac414c2e7fb6ea Mon Sep 17 00:00:00 2001 From: Victor Hurdugaci Date: Wed, 29 Jul 2015 01:04:59 -0700 Subject: [PATCH 0167/1662] React to DNX renames --- src/Kestrel/ServerFactory.cs | 2 +- .../KestrelEngine.cs | 6 +++--- src/Microsoft.AspNet.Server.Kestrel/project.json | 2 +- .../EngineTests.cs | 8 ++++---- .../MultipleLoopTests.cs | 13 +++++-------- .../NetworkingTests.cs | 8 ++++---- .../Microsoft.AspNet.Server.KestrelTests/Program.cs | 2 +- .../ShutdownNotImplemented.cs | 2 +- .../TestServer.cs | 8 ++++---- 9 files changed, 24 insertions(+), 27 deletions(-) diff --git a/src/Kestrel/ServerFactory.cs b/src/Kestrel/ServerFactory.cs index 784b1cdbdd..2c4b960306 100644 --- a/src/Kestrel/ServerFactory.cs +++ b/src/Kestrel/ServerFactory.cs @@ -7,8 +7,8 @@ using System.Threading.Tasks; using Microsoft.AspNet.Hosting.Server; using Microsoft.AspNet.Http.Features; using Microsoft.AspNet.Server.Kestrel; +using Microsoft.Dnx.Runtime; using Microsoft.Framework.Configuration; -using Microsoft.Framework.Runtime; namespace Kestrel { diff --git a/src/Microsoft.AspNet.Server.Kestrel/KestrelEngine.cs b/src/Microsoft.AspNet.Server.Kestrel/KestrelEngine.cs index 49d3ac0a0b..465dbd0cf7 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/KestrelEngine.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/KestrelEngine.cs @@ -2,12 +2,12 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using Microsoft.AspNet.Server.Kestrel.Networking; using System.Collections.Generic; +using System.IO; using System.Threading.Tasks; using Microsoft.AspNet.Server.Kestrel.Http; -using Microsoft.Framework.Runtime; -using System.IO; +using Microsoft.AspNet.Server.Kestrel.Networking; +using Microsoft.Dnx.Runtime; namespace Microsoft.AspNet.Server.Kestrel { diff --git a/src/Microsoft.AspNet.Server.Kestrel/project.json b/src/Microsoft.AspNet.Server.Kestrel/project.json index fb04e22a0b..cbcb1444df 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/project.json +++ b/src/Microsoft.AspNet.Server.Kestrel/project.json @@ -6,7 +6,7 @@ "url": "git://github.com/aspnet/kestrelhttpserver" }, "dependencies": { - "Microsoft.Framework.Runtime.Abstractions": "1.0.0-beta7-*" + "Microsoft.Dnx.Runtime.Abstractions": "1.0.0-beta7-*" }, "frameworks": { "dnx451": { }, diff --git a/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs index 98be42db2e..4ca8ae6648 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs @@ -1,16 +1,16 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using Microsoft.AspNet.Server.Kestrel; -using Microsoft.AspNet.Server.Kestrel.Http; -using Microsoft.Framework.Runtime; -using Microsoft.Framework.Runtime.Infrastructure; using System; using System.IO; using System.Net; using System.Net.Sockets; using System.Text; using System.Threading.Tasks; +using Microsoft.AspNet.Server.Kestrel; +using Microsoft.AspNet.Server.Kestrel.Http; +using Microsoft.Dnx.Runtime; +using Microsoft.Dnx.Runtime.Infrastructure; using Xunit; namespace Microsoft.AspNet.Server.KestrelTests diff --git a/test/Microsoft.AspNet.Server.KestrelTests/MultipleLoopTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/MultipleLoopTests.cs index f9e53b1d81..35f4f334e6 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/MultipleLoopTests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/MultipleLoopTests.cs @@ -1,15 +1,12 @@ -using Microsoft.AspNet.Server.Kestrel; -using Microsoft.AspNet.Server.Kestrel.Networking; -using Microsoft.Framework.Runtime; -using Microsoft.Framework.Runtime.Infrastructure; -using System; -using System.Collections.Generic; -using System.Linq; +using System; using System.Net; using System.Net.Sockets; using System.Runtime.InteropServices; using System.Threading; -using System.Threading.Tasks; +using Microsoft.AspNet.Server.Kestrel; +using Microsoft.AspNet.Server.Kestrel.Networking; +using Microsoft.Dnx.Runtime; +using Microsoft.Dnx.Runtime.Infrastructure; using Xunit; namespace Microsoft.AspNet.Server.KestrelTests diff --git a/test/Microsoft.AspNet.Server.KestrelTests/NetworkingTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/NetworkingTests.cs index 2cf9c71d05..f5f4b42d6c 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/NetworkingTests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/NetworkingTests.cs @@ -1,15 +1,15 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using Microsoft.AspNet.Server.Kestrel; -using Microsoft.AspNet.Server.Kestrel.Networking; -using Microsoft.Framework.Runtime; -using Microsoft.Framework.Runtime.Infrastructure; using System; using System.Net; using System.Net.Sockets; using System.Runtime.InteropServices; using System.Threading.Tasks; +using Microsoft.AspNet.Server.Kestrel; +using Microsoft.AspNet.Server.Kestrel.Networking; +using Microsoft.Dnx.Runtime; +using Microsoft.Dnx.Runtime.Infrastructure; using Xunit; namespace Microsoft.AspNet.Server.KestrelTests diff --git a/test/Microsoft.AspNet.Server.KestrelTests/Program.cs b/test/Microsoft.AspNet.Server.KestrelTests/Program.cs index 2cfa625390..1baf869b8c 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/Program.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/Program.cs @@ -1,8 +1,8 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using Microsoft.Framework.Runtime; using System; +using Microsoft.Dnx.Runtime; namespace Microsoft.AspNet.Server.KestrelTests { diff --git a/test/Microsoft.AspNet.Server.KestrelTests/ShutdownNotImplemented.cs b/test/Microsoft.AspNet.Server.KestrelTests/ShutdownNotImplemented.cs index 58697d9a3e..5d32828583 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/ShutdownNotImplemented.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/ShutdownNotImplemented.cs @@ -3,7 +3,7 @@ using System; using System.Threading; -using Microsoft.Framework.Runtime; +using Microsoft.Dnx.Runtime; namespace Microsoft.AspNet.Server.KestrelTests { diff --git a/test/Microsoft.AspNet.Server.KestrelTests/TestServer.cs b/test/Microsoft.AspNet.Server.KestrelTests/TestServer.cs index dba5cddcde..b299d26246 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/TestServer.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/TestServer.cs @@ -1,12 +1,12 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using Microsoft.AspNet.Server.Kestrel; -using Microsoft.AspNet.Server.Kestrel.Http; -using Microsoft.Framework.Runtime; -using Microsoft.Framework.Runtime.Infrastructure; using System; using System.Threading.Tasks; +using Microsoft.AspNet.Server.Kestrel; +using Microsoft.AspNet.Server.Kestrel.Http; +using Microsoft.Dnx.Runtime; +using Microsoft.Dnx.Runtime.Infrastructure; namespace Microsoft.AspNet.Server.KestrelTests { From 07de3cafd11487716dde84b89d7289c29877568b Mon Sep 17 00:00:00 2001 From: Troy Dai Date: Wed, 22 Jul 2015 11:33:35 -0700 Subject: [PATCH 0168/1662] Clean build warnings --- src/Kestrel/ServerRequest.cs | 4 ++-- .../Http/FrameDuplexStream.cs | 2 ++ src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs | 4 ++-- test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs | 6 +++--- .../MessageBodyTests.cs | 2 +- .../Microsoft.AspNet.Server.KestrelTests/NetworkingTests.cs | 6 +++--- 6 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/Kestrel/ServerRequest.cs b/src/Kestrel/ServerRequest.cs index e1ac126af5..c766c99c49 100644 --- a/src/Kestrel/ServerRequest.cs +++ b/src/Kestrel/ServerRequest.cs @@ -221,7 +221,7 @@ namespace Kestrel } } - async Task IHttpUpgradeFeature.UpgradeAsync() + Task IHttpUpgradeFeature.UpgradeAsync() { _frame.StatusCode = 101; _frame.ReasonPhrase = "Switching Protocols"; @@ -235,7 +235,7 @@ namespace Kestrel } } _frame.ProduceStart(); - return _frame.DuplexStream; + return Task.FromResult(_frame.DuplexStream); } } } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameDuplexStream.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameDuplexStream.cs index 98d09be383..58b2c88d0a 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameDuplexStream.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameDuplexStream.cs @@ -1,7 +1,9 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +#if DNX451 using System; +#endif using System.IO; using System.Threading; using System.Threading.Tasks; diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs index 45253dfe98..78ab050e31 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs @@ -1,11 +1,11 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using Microsoft.AspNet.Server.Kestrel.Networking; using System; using System.Collections.Generic; -using System.Threading; using System.Diagnostics; +using System.Threading; +using Microsoft.AspNet.Server.Kestrel.Networking; namespace Microsoft.AspNet.Server.Kestrel.Http { diff --git a/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs index 4ca8ae6648..6b9ed7c728 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs @@ -76,7 +76,7 @@ namespace Microsoft.AspNet.Server.KestrelTests } [Fact] - public async Task EngineCanStartAndStop() + public void EngineCanStartAndStop() { var engine = new KestrelEngine(LibraryManager, new ShutdownNotImplemented()); engine.Start(1); @@ -84,7 +84,7 @@ namespace Microsoft.AspNet.Server.KestrelTests } [Fact] - public async Task ListenerCanCreateAndDispose() + public void ListenerCanCreateAndDispose() { var engine = new KestrelEngine(LibraryManager, new ShutdownNotImplemented()); engine.Start(1); @@ -95,7 +95,7 @@ namespace Microsoft.AspNet.Server.KestrelTests [Fact] - public async Task ConnectionCanReadAndWrite() + public void ConnectionCanReadAndWrite() { var engine = new KestrelEngine(LibraryManager, new ShutdownNotImplemented()); engine.Start(1); diff --git a/test/Microsoft.AspNet.Server.KestrelTests/MessageBodyTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/MessageBodyTests.cs index 5a66846619..54f6e98509 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/MessageBodyTests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/MessageBodyTests.cs @@ -16,7 +16,7 @@ namespace Microsoft.AspNet.Server.KestrelTests public class MessageBodyTests { [Fact] - public async Task Http10ConnectionClose() + public void Http10ConnectionClose() { var input = new TestInput(); var body = MessageBody.For("HTTP/1.0", new Dictionary(), input.FrameContext); diff --git a/test/Microsoft.AspNet.Server.KestrelTests/NetworkingTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/NetworkingTests.cs index f5f4b42d6c..4e381b079d 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/NetworkingTests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/NetworkingTests.cs @@ -45,7 +45,7 @@ namespace Microsoft.AspNet.Server.KestrelTests } [Fact] - public async Task LoopCanBeInitAndClose() + public void LoopCanBeInitAndClose() { var loop = new UvLoopHandle(); loop.Init(_uv); @@ -54,7 +54,7 @@ namespace Microsoft.AspNet.Server.KestrelTests } [Fact] - public async Task AsyncCanBeSent() + public void AsyncCanBeSent() { var loop = new UvLoopHandle(); loop.Init(_uv); @@ -72,7 +72,7 @@ namespace Microsoft.AspNet.Server.KestrelTests } [Fact] - public async Task SocketCanBeInitAndClose() + public void SocketCanBeInitAndClose() { var loop = new UvLoopHandle(); loop.Init(_uv); From b2289b9a5400fdfb520d09b380020e39a3e7a5a1 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Thu, 30 Jul 2015 15:20:22 -0700 Subject: [PATCH 0169/1662] Disable parallel test execution - MultipleLoopTests and NetworkingTests seem to interfere with each other. --- test/Microsoft.AspNet.Server.KestrelTests/project.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Microsoft.AspNet.Server.KestrelTests/project.json b/test/Microsoft.AspNet.Server.KestrelTests/project.json index 68c1a69290..ad74555390 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/project.json +++ b/test/Microsoft.AspNet.Server.KestrelTests/project.json @@ -19,6 +19,6 @@ }, "commands": { "run": "Microsoft.AspNet.Server.KestrelTests", - "test": "xunit.runner.aspnet" + "test": "xunit.runner.aspnet -parallel none" } } From 4a9515d2e00ac11fcc0fe62530bc495042aa944b Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Mon, 13 Jul 2015 15:55:37 -0700 Subject: [PATCH 0170/1662] Gracefully handle uncaught exceptions in user code when possible --- .../Http/Frame.cs | 22 +++++++ .../EngineTests.cs | 63 ++++++++++++++++++- 2 files changed, 84 insertions(+), 1 deletion(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs index c21f6b7b84..4f66998345 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs @@ -317,6 +317,28 @@ namespace Microsoft.AspNet.Server.Kestrel.Http public void ProduceEnd(Exception ex) { + if (ex != null) + { + if (_resultStarted) + { + // We can no longer respond with a 500, so we simply close the connection. + ConnectionControl.End(ProduceEndType.SocketDisconnect); + return; + } + else + { + StatusCode = 500; + ReasonPhrase = null; + + // If OnStarting hasn't been triggered yet, we don't want to trigger it now that + // the app func has failed. https://github.com/aspnet/KestrelHttpServer/issues/43 + _onStarting = null; + + ResponseHeaders.Clear(); + ResponseHeaders["Content-Length"] = new[] { "0" }; + } + } + ProduceStart(); if (!_keepAlive) diff --git a/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs index 6b9ed7c728..9c65ea36c1 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs @@ -18,7 +18,7 @@ namespace Microsoft.AspNet.Server.KestrelTests /// /// Summary description for EngineTests /// - internal class EngineTests + public class EngineTests { private async Task App(Frame frame) { @@ -57,6 +57,20 @@ namespace Microsoft.AspNet.Server.KestrelTests } } + private async Task AppThatThrows(Frame frame) + { + // Anything added to the ResponseHeaders dictionary is ignored + frame.ResponseHeaders["Content-Length"] = new[] { "11" }; + throw new Exception(); + } + + private async Task AppThatThrowsAfterWrite(Frame frame) + { + frame.ResponseHeaders["Content-Length"] = new[] { "11" }; + await frame.ResponseBody.WriteAsync(Encoding.UTF8.GetBytes("Hello World"), 0, 11); + throw new Exception(); + } + private async Task AppChunked(Frame frame) { var data = new MemoryStream(); @@ -343,5 +357,52 @@ namespace Microsoft.AspNet.Server.KestrelTests } } } + + [Fact] + public async Task ThrowingResultsIn500Response() + { + using (var server = new TestServer(AppThatThrows)) + { + using (var connection = new TestConnection()) + { + await connection.SendEnd( + "GET / HTTP/1.1", + "", + "GET / HTTP/1.1", + "Connection: close", + "", + ""); + await connection.ReceiveEnd( + "HTTP/1.1 500 Internal Server Error", + "Content-Length: 0", + "", + "HTTP/1.1 500 Internal Server Error", + "Content-Length: 0", + "Connection: close", + "", + ""); + } + } + } + + [Fact] + public async Task ThrowingAfterWritingKillsConnection() + { + using (var server = new TestServer(AppThatThrowsAfterWrite)) + { + using (var connection = new TestConnection()) + { + await connection.Send( + "GET / HTTP/1.1", + "", + ""); + await connection.ReceiveEnd( + "HTTP/1.1 200 OK", + "Content-Length: 11", + "", + "Hello World"); + } + } + } } } From 6da15a65b2f7a304e58e178dea48f2aa402ebcd8 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Fri, 17 Jul 2015 14:04:28 -0700 Subject: [PATCH 0171/1662] Additional testing using app funcs that throw exceptions --- .../EngineTests.cs | 83 +++++++++++++++---- 1 file changed, 67 insertions(+), 16 deletions(-) diff --git a/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs index 9c65ea36c1..b8f0a95a14 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs @@ -57,20 +57,6 @@ namespace Microsoft.AspNet.Server.KestrelTests } } - private async Task AppThatThrows(Frame frame) - { - // Anything added to the ResponseHeaders dictionary is ignored - frame.ResponseHeaders["Content-Length"] = new[] { "11" }; - throw new Exception(); - } - - private async Task AppThatThrowsAfterWrite(Frame frame) - { - frame.ResponseHeaders["Content-Length"] = new[] { "11" }; - await frame.ResponseBody.WriteAsync(Encoding.UTF8.GetBytes("Hello World"), 0, 11); - throw new Exception(); - } - private async Task AppChunked(Frame frame) { var data = new MemoryStream(); @@ -361,7 +347,20 @@ namespace Microsoft.AspNet.Server.KestrelTests [Fact] public async Task ThrowingResultsIn500Response() { - using (var server = new TestServer(AppThatThrows)) + bool onStartingCalled = false; + + using (var server = new TestServer(frame => + { + frame.OnStarting(_ => + { + onStartingCalled = true; + return Task.FromResult(null); + }, null); + + // Anything added to the ResponseHeaders dictionary is ignored + frame.ResponseHeaders["Content-Length"] = new[] { "11" }; + throw new Exception(); + })) { using (var connection = new TestConnection()) { @@ -381,6 +380,8 @@ namespace Microsoft.AspNet.Server.KestrelTests "Connection: close", "", ""); + + Assert.False(onStartingCalled); } } } @@ -388,7 +389,20 @@ namespace Microsoft.AspNet.Server.KestrelTests [Fact] public async Task ThrowingAfterWritingKillsConnection() { - using (var server = new TestServer(AppThatThrowsAfterWrite)) + bool onStartingCalled = false; + + using (var server = new TestServer(async frame => + { + frame.OnStarting(_ => + { + onStartingCalled = true; + return Task.FromResult(null); + }, null); + + frame.ResponseHeaders["Content-Length"] = new[] { "11" }; + await frame.ResponseBody.WriteAsync(Encoding.ASCII.GetBytes("Hello World"), 0, 11); + throw new Exception(); + })) { using (var connection = new TestConnection()) { @@ -401,6 +415,43 @@ namespace Microsoft.AspNet.Server.KestrelTests "Content-Length: 11", "", "Hello World"); + + Assert.True(onStartingCalled); + } + } + } + + [Fact] + public async Task ThrowingAfterPartialWriteKillsConnection() + { + bool onStartingCalled = false; + + using (var server = new TestServer(async frame => + { + frame.OnStarting(_ => + { + onStartingCalled = true; + return Task.FromResult(null); + }, null); + + frame.ResponseHeaders["Content-Length"] = new[] { "11" }; + await frame.ResponseBody.WriteAsync(Encoding.ASCII.GetBytes("Hello"), 0, 5); + throw new Exception(); + })) + { + using (var connection = new TestConnection()) + { + await connection.Send( + "GET / HTTP/1.1", + "", + ""); + await connection.ReceiveEnd( + "HTTP/1.1 200 OK", + "Content-Length: 11", + "", + "Hello"); + + Assert.True(onStartingCalled); } } } From be06eec7ba3b4c971fe0121faeea379d566fded5 Mon Sep 17 00:00:00 2001 From: Brennan Date: Thu, 30 Jul 2015 14:30:17 -0700 Subject: [PATCH 0172/1662] Install Libuv on Travis --- .travis.yml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.travis.yml b/.travis.yml index 947bf868ee..1218a0fc0f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,12 @@ language: csharp sudo: false +install: + - curl -sSL https://github.com/libuv/libuv/archive/v1.4.2.tar.gz | tar zxfv - -C /tmp && cd /tmp/libuv-1.4.2/ + - sh autogen.sh + - ./configure --prefix=$HOME/libuvinstall + - make + - make install + - export LD_LIBRARY_PATH="$HOME/libuvinstall/lib" + - cd $OLDPWD script: - ./build.sh --quiet verify \ No newline at end of file From 07304640ed911e25fd2bb95112045c0e9b00d3eb Mon Sep 17 00:00:00 2001 From: anurse Date: Fri, 31 Jul 2015 11:54:52 -0700 Subject: [PATCH 0173/1662] react to DNX renames --- src/Microsoft.AspNet.Server.Kestrel/KestrelEngine.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/KestrelEngine.cs b/src/Microsoft.AspNet.Server.Kestrel/KestrelEngine.cs index 465dbd0cf7..1f356d16d1 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/KestrelEngine.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/KestrelEngine.cs @@ -22,7 +22,7 @@ namespace Microsoft.AspNet.Server.Kestrel if (libraryManager != null) { - var library = libraryManager.GetLibraryInformation("Microsoft.AspNet.Server.Kestrel"); + var library = libraryManager.GetLibrary("Microsoft.AspNet.Server.Kestrel"); libraryPath = library.Path; if (library.Type == "Project") { From 83b2c953853494588cc2075ba3840a6912c5919f Mon Sep 17 00:00:00 2001 From: Chris R Date: Wed, 29 Jul 2015 15:12:57 -0700 Subject: [PATCH 0174/1662] React to IFeatureCollection changes. --- src/Kestrel/ServerRequest.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Kestrel/ServerRequest.cs b/src/Kestrel/ServerRequest.cs index c766c99c49..66f5879f4d 100644 --- a/src/Kestrel/ServerRequest.cs +++ b/src/Kestrel/ServerRequest.cs @@ -27,9 +27,9 @@ namespace Kestrel private void PopulateFeatures() { - _features.Add(typeof(IHttpRequestFeature), this); - _features.Add(typeof(IHttpResponseFeature), this); - _features.Add(typeof(IHttpUpgradeFeature), this); + _features[typeof(IHttpRequestFeature)] = this; + _features[typeof(IHttpResponseFeature)] = this; + _features[typeof(IHttpUpgradeFeature)] = this; } internal IFeatureCollection Features From 963f086eb03c11dc7f5d9e27f0f1ed635c3be0c1 Mon Sep 17 00:00:00 2001 From: Louis DeJardin Date: Wed, 8 Jul 2015 14:45:14 -0700 Subject: [PATCH 0175/1662] Prototypeing a fast header dictionary Conflicts: src/Microsoft.AspNet.Server.Kestrel/project.json --- KestrelHttpServer.sln | 6 + .../KnownHeaders.cs | 305 ++++++++++++++++++ ....AspNet.Server.Kestrel.GeneratedCode.xproj | 20 ++ .../project.json | 28 ++ .../Http/FrameRequestHeaders.cs | 132 ++++++++ .../compiler/preprocess/KnownHeaders.cs | 11 + .../project.json | 3 +- .../FrameRequestHeadersTests.cs | 238 ++++++++++++++ 8 files changed, 742 insertions(+), 1 deletion(-) create mode 100644 src/Microsoft.AspNet.Server.Kestrel.GeneratedCode/KnownHeaders.cs create mode 100644 src/Microsoft.AspNet.Server.Kestrel.GeneratedCode/Microsoft.AspNet.Server.Kestrel.GeneratedCode.xproj create mode 100644 src/Microsoft.AspNet.Server.Kestrel.GeneratedCode/project.json create mode 100644 src/Microsoft.AspNet.Server.Kestrel/Http/FrameRequestHeaders.cs create mode 100644 src/Microsoft.AspNet.Server.Kestrel/compiler/preprocess/KnownHeaders.cs create mode 100644 test/Microsoft.AspNet.Server.KestrelTests/FrameRequestHeadersTests.cs diff --git a/KestrelHttpServer.sln b/KestrelHttpServer.sln index d2ebe3ed3d..207aa84895 100644 --- a/KestrelHttpServer.sln +++ b/KestrelHttpServer.sln @@ -26,6 +26,7 @@ EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "samples", "samples", "{8A3D00B8-1CCF-4BE6-A060-11104CE2D9CE}" EndProject Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "LargeResponseApp", "samples\LargeResponseApp\LargeResponseApp.xproj", "{B35D4D31-E74C-4646-8A11-7A7A40F0021E}" +Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.Server.Kestrel.GeneratedCode", "src\Microsoft.AspNet.Server.Kestrel.GeneratedCode\Microsoft.AspNet.Server.Kestrel.GeneratedCode.xproj", "{BD2D4D29-1BD9-40D0-BB31-337D5416B63C}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -53,6 +54,10 @@ Global {B35D4D31-E74C-4646-8A11-7A7A40F0021E}.Debug|Any CPU.Build.0 = Debug|Any CPU {B35D4D31-E74C-4646-8A11-7A7A40F0021E}.Release|Any CPU.ActiveCfg = Release|Any CPU {B35D4D31-E74C-4646-8A11-7A7A40F0021E}.Release|Any CPU.Build.0 = Release|Any CPU + {BD2D4D29-1BD9-40D0-BB31-337D5416B63C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {BD2D4D29-1BD9-40D0-BB31-337D5416B63C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {BD2D4D29-1BD9-40D0-BB31-337D5416B63C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {BD2D4D29-1BD9-40D0-BB31-337D5416B63C}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -63,5 +68,6 @@ Global {2C3CB3DC-EEBF-4F52-9E1C-4F2F972E76C3} = {8A3D00B8-1CCF-4BE6-A060-11104CE2D9CE} {30B7617E-58EF-4382-B3EA-5B2E718CF1A6} = {2D5D5227-4DBD-499A-96B1-76A36B03B750} {B35D4D31-E74C-4646-8A11-7A7A40F0021E} = {8A3D00B8-1CCF-4BE6-A060-11104CE2D9CE} + {BD2D4D29-1BD9-40D0-BB31-337D5416B63C} = {2D5D5227-4DBD-499A-96B1-76A36B03B750} EndGlobalSection EndGlobal diff --git a/src/Microsoft.AspNet.Server.Kestrel.GeneratedCode/KnownHeaders.cs b/src/Microsoft.AspNet.Server.Kestrel.GeneratedCode/KnownHeaders.cs new file mode 100644 index 0000000000..61cb71178d --- /dev/null +++ b/src/Microsoft.AspNet.Server.Kestrel.GeneratedCode/KnownHeaders.cs @@ -0,0 +1,305 @@ +using Microsoft.Framework.Runtime.Roslyn; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace Microsoft.AspNet.Server.Kestrel.GeneratedCode +{ + // This project can output the Class library as a NuGet Package. + // To enable this option, right-click on the project and select the Properties menu item. In the Build tab select "Produce outputs on build". + public class KnownHeaders : ICompileModule + { + string Each(IEnumerable values, Func formatter) + { + return values.Select(formatter).Aggregate((a, b) => a + b + "\r\n"); + } + + class KnownHeader + { + public string Name { get; set; } + public int Index { get; set; } + public string Identifier => Name.Replace("-", ""); + public string TestBit() => $"((_bits & ({1L << Index}L)) != 0)"; + public string SetBit() => $"_bits |= {1L << Index}L"; + public string ClearBit() => $"_bits &= ~{(1L << Index)}L"; + } + + public virtual void BeforeCompile(BeforeCompileContext context) + { + Console.WriteLine("I like pie"); + + var commonHeaders = new[] + { + "Cache-Control", + "Connection", + "Date", + "Keep-Alive", + "Pragma", + "Trailer", + "Transfer-Encoding", + "Upgrade", + "Via", + "Warning", + "Allow", + "Content-Length", + "Content-Type", + "Content-Encoding", + "Content-Language", + "Content-Location", + "Content-MD5", + "Content-Range", + "Expires", + "Last-Modified" + }; + var requestHeaders = commonHeaders.Concat(new[] + { + "Accept", + "Accept-Charset", + "Accept-Encoding", + "Accept-Language", + "Authorization", + "Cookie", + "Expect", + "From", + "Host", + "If-Match", + "If-Modified-Since", + "If-None-Match", + "If-Range", + "If-Unmodified-Since", + "Max-Forwards", + "Proxy-Authorization", + "Referer", + "Range", + "TE", + "Translage", + "User-Agent", + }).Select((header, index) => new KnownHeader + { + Name = header, + Index = index + }); + + var responseHeaders = commonHeaders.Concat(new[] + { + "Accept-Ranges", + "Age", + "ETag", + "Location", + "Proxy-Autheticate", + "Retry-After", + "Server", + "Set-Cookie", + "Vary", + "WWW-Authenticate", + }).Select((header, index) => new KnownHeader + { + Name = header, + Index = index + }); + + var loops = new[] + { + new + { + Headers = requestHeaders, + HeadersByLength = requestHeaders.GroupBy(x => x.Name.Length), + ClassName = "FrameRequestHeaders" + }, + new + { + Headers = responseHeaders, + HeadersByLength = responseHeaders.GroupBy(x => x.Name.Length), + ClassName = "FrameResponseHeaders" + } + }; + + var syntaxTree = Microsoft.CodeAnalysis.CSharp.CSharpSyntaxTree.ParseText($@" +using System; +using System.Collections.Generic; + +namespace Microsoft.AspNet.Server.Kestrel.Http +{{{Each(loops, loop => $@" + public partial class {loop.ClassName} + {{ + long _bits = 0; + {Each(loop.Headers, header => "string[] _" + header.Identifier + ";")} + + protected override int GetCountFast() + {{ + var count = Unknown.Count; + {Each(loop.Headers, header => $@" + if ({header.TestBit()}) + {{ + ++count; + }} + ")} + return count; + }} + + protected override string[] GetValueFast(string key) + {{ + switch(key.Length) + {{{Each(loop.HeadersByLength, byLength => $@" + case {byLength.Key}: + {{{Each(byLength, header => $@" + if (0 == StringComparer.OrdinalIgnoreCase.Compare(key, ""{header.Name}"")) + {{ + if ({header.TestBit()}) + {{ + return _{header.Identifier}; + }} + else + {{ + throw new System.Collections.Generic.KeyNotFoundException(); + }} + }} + ")}}} + break; + ")}}} + return Unknown[key]; + }} + + protected override bool TryGetValueFast(string key, out string[] value) + {{ + switch(key.Length) + {{{Each(loop.HeadersByLength, byLength => $@" + case {byLength.Key}: + {{{Each(byLength, header => $@" + if (0 == StringComparer.OrdinalIgnoreCase.Compare(key, ""{header.Name}"")) + {{ + if ({header.TestBit()}) + {{ + value = _{header.Identifier}; + return true; + }} + else + {{ + value = null; + return false; + }} + }} + ")}}} + break; + ")}}} + return Unknown.TryGetValue(key, out value); + }} + + protected override void SetValueFast(string key, string[] value) + {{ + switch(key.Length) + {{{Each(loop.HeadersByLength, byLength => $@" + case {byLength.Key}: + {{{Each(byLength, header => $@" + if (0 == StringComparer.OrdinalIgnoreCase.Compare(key, ""{header.Name}"")) + {{ + {header.SetBit()}; + _{header.Identifier} = value; + return; + }} + ")}}} + break; + ")}}} + Unknown[key] = value; + }} + + protected override void AddValueFast(string key, string[] value) + {{ + switch(key.Length) + {{{Each(loop.HeadersByLength, byLength => $@" + case {byLength.Key}: + {{{Each(byLength, header => $@" + if (0 == StringComparer.OrdinalIgnoreCase.Compare(key, ""{header.Name}"")) + {{ + if ({header.TestBit()}) + {{ + throw new ArgumentException(""An item with the same key has already been added.""); + }} + {header.SetBit()}; + _{header.Identifier} = value; + return; + }} + ")}}} + break; + ")}}} + Unknown.Add(key, value); + }} + + protected override bool RemoveFast(string key) + {{ + switch(key.Length) + {{{Each(loop.HeadersByLength, byLength => $@" + case {byLength.Key}: + {{{Each(byLength, header => $@" + if (0 == StringComparer.OrdinalIgnoreCase.Compare(key, ""{header.Name}"")) + {{ + if ({header.TestBit()}) + {{ + {header.ClearBit()}; + return true; + }} + else + {{ + return false; + }} + }} + ")}}} + break; + ")}}} + return Unknown.Remove(key); + }} + + protected override void ClearFast() + {{ + _bits = 0; + Unknown.Clear(); + }} + + protected override void CopyToFast(KeyValuePair[] array, int arrayIndex) + {{ + if (arrayIndex < 0) + {{ + throw new ArgumentException(); + }} + + {Each(loop.Headers, header => $@" + if ({header.TestBit()}) + {{ + if (arrayIndex == array.Length) + {{ + throw new ArgumentException(); + }} + + array[arrayIndex] = new KeyValuePair(""{header.Name}"", _{header.Identifier}); + ++arrayIndex; + }} + ")} + ((ICollection>)Unknown).CopyTo(array, arrayIndex); + }} + + protected override IEnumerable> EnumerateFast() + {{ + {Each(loop.Headers, header => $@" + if ({header.TestBit()}) + {{ + yield return new KeyValuePair(""{header.Name}"", _{header.Identifier}); + }} + ")} + foreach(var kv in Unknown) + {{ + yield return kv; + }} + }} + }} +")}}} +"); + + context.Compilation = context.Compilation.AddSyntaxTrees(syntaxTree); + } + + public virtual void AfterCompile(AfterCompileContext context) + { + } + } +} diff --git a/src/Microsoft.AspNet.Server.Kestrel.GeneratedCode/Microsoft.AspNet.Server.Kestrel.GeneratedCode.xproj b/src/Microsoft.AspNet.Server.Kestrel.GeneratedCode/Microsoft.AspNet.Server.Kestrel.GeneratedCode.xproj new file mode 100644 index 0000000000..12a75e7f62 --- /dev/null +++ b/src/Microsoft.AspNet.Server.Kestrel.GeneratedCode/Microsoft.AspNet.Server.Kestrel.GeneratedCode.xproj @@ -0,0 +1,20 @@ + + + + 14.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + + + + + bd2d4d29-1bd9-40d0-bb31-337d5416b63c + Microsoft.AspNet.Server.Kestrel.GeneratedCode + ..\..\artifacts\obj\$(MSBuildProjectName) + ..\..\artifacts\bin\$(MSBuildProjectName)\ + + + + 2.0 + + + diff --git a/src/Microsoft.AspNet.Server.Kestrel.GeneratedCode/project.json b/src/Microsoft.AspNet.Server.Kestrel.GeneratedCode/project.json new file mode 100644 index 0000000000..a9fe1fd9df --- /dev/null +++ b/src/Microsoft.AspNet.Server.Kestrel.GeneratedCode/project.json @@ -0,0 +1,28 @@ +{ + "version": "1.0.0-*", + "description": "", + "authors": [ "" ], + "tags": [ "" ], + "projectUrl": "", + "licenseUrl": "", + + "dependencies": { + "Microsoft.Framework.Runtime.Roslyn": "1.0.0-beta6-*" + }, + + "frameworks": { + "dnx451": { + "frameworkAssemblies": { + "System.Runtime": "4.0.10.0" + } + }, + "dnxcore50": { + "dependencies": { + "System.Collections": "4.0.10-beta-*", + "System.Linq": "4.0.0-beta-*", + "System.Threading": "4.0.10-beta-*", + "Microsoft.CSharp": "4.0.0-beta-*" + } + } + } +} diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameRequestHeaders.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameRequestHeaders.cs new file mode 100644 index 0000000000..6d6a45683b --- /dev/null +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameRequestHeaders.cs @@ -0,0 +1,132 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Linq; + +namespace Microsoft.AspNet.Server.Kestrel.Http +{ + public partial class FrameRequestHeaders : FrameHeaders + { + } + + public partial class FrameResponseHeaders : FrameHeaders + { + } + + public abstract class FrameHeaders : IDictionary + { + protected Dictionary Unknown = new Dictionary(StringComparer.OrdinalIgnoreCase); + + protected virtual int GetCountFast() + { throw new NotImplementedException(); } + + protected virtual string[] GetValueFast(string key) + { throw new NotImplementedException(); } + + protected virtual bool TryGetValueFast(string key, out string[] value) + { throw new NotImplementedException(); } + + protected virtual void SetValueFast(string key, string[] value) + { throw new NotImplementedException(); } + + protected virtual void AddValueFast(string key, string[] value) + { throw new NotImplementedException(); } + + protected virtual bool RemoveFast(string key) + { throw new NotImplementedException(); } + + protected virtual void ClearFast() + { throw new NotImplementedException(); } + + protected virtual void CopyToFast(KeyValuePair[] array, int arrayIndex) + { throw new NotImplementedException(); } + + protected virtual IEnumerable> EnumerateFast() + { throw new NotImplementedException(); } + + + string[] IDictionary.this[string key] + { + get + { + return GetValueFast(key); + } + + set + { + SetValueFast(key, value); + } + } + + int ICollection>.Count => GetCountFast(); + + bool ICollection>.IsReadOnly => false; + + ICollection IDictionary.Keys => EnumerateFast().Select(x => x.Key).ToList(); + + ICollection IDictionary.Values => EnumerateFast().Select(x => x.Value).ToList(); + + void ICollection>.Add(KeyValuePair item) + { + AddValueFast(item.Key, item.Value); + } + + void IDictionary.Add(string key, string[] value) + { + AddValueFast(key, value); + } + + void ICollection>.Clear() + { + ClearFast(); + } + + bool ICollection>.Contains(KeyValuePair item) + { + string[] value; + return + TryGetValueFast(item.Key, out value) && + object.Equals(value, item.Value); + } + + bool IDictionary.ContainsKey(string key) + { + string[] value; + return TryGetValueFast(key, out value); + } + + void ICollection>.CopyTo(KeyValuePair[] array, int arrayIndex) + { + CopyToFast(array, arrayIndex); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return EnumerateFast().GetEnumerator(); + } + + IEnumerator> IEnumerable>.GetEnumerator() + { + return EnumerateFast().GetEnumerator(); + } + + bool ICollection>.Remove(KeyValuePair item) + { + string[] value; + return + TryGetValueFast(item.Key, out value) && + object.Equals(value, item.Value) && + RemoveFast(item.Key); + } + + bool IDictionary.Remove(string key) + { + return RemoveFast(key); + } + + bool IDictionary.TryGetValue(string key, out string[] value) + { + return TryGetValueFast(key, out value); + } + } +} diff --git a/src/Microsoft.AspNet.Server.Kestrel/compiler/preprocess/KnownHeaders.cs b/src/Microsoft.AspNet.Server.Kestrel/compiler/preprocess/KnownHeaders.cs new file mode 100644 index 0000000000..8ef4e55532 --- /dev/null +++ b/src/Microsoft.AspNet.Server.Kestrel/compiler/preprocess/KnownHeaders.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace Microsoft.AspNet.Server.Kestrel +{ + public class KnownHeaders : Microsoft.AspNet.Server.Kestrel.GeneratedCode.KnownHeaders + { + } +} diff --git a/src/Microsoft.AspNet.Server.Kestrel/project.json b/src/Microsoft.AspNet.Server.Kestrel/project.json index cbcb1444df..93f24a85d1 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/project.json +++ b/src/Microsoft.AspNet.Server.Kestrel/project.json @@ -6,7 +6,8 @@ "url": "git://github.com/aspnet/kestrelhttpserver" }, "dependencies": { - "Microsoft.Dnx.Runtime.Abstractions": "1.0.0-beta7-*" + "Microsoft.Dnx.Runtime.Abstractions": "1.0.0-beta7-*", + "Microsoft.AspNet.Server.Kestrel.GeneratedCode": { "version": "1.0.0-*", "type": "build" } }, "frameworks": { "dnx451": { }, diff --git a/test/Microsoft.AspNet.Server.KestrelTests/FrameRequestHeadersTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/FrameRequestHeadersTests.cs new file mode 100644 index 0000000000..f69b1c0746 --- /dev/null +++ b/test/Microsoft.AspNet.Server.KestrelTests/FrameRequestHeadersTests.cs @@ -0,0 +1,238 @@ +using Microsoft.AspNet.Server.Kestrel.Http; +using System; +using System.Collections.Generic; +using System.Linq; +using Xunit; + +namespace Microsoft.AspNet.Server.KestrelTests +{ + public class FrameRequestHeadersTests + { + [Fact] + public void InitialDictionaryIsEmpty() + { + IDictionary headers = new FrameRequestHeaders(); + + Assert.Equal(0, headers.Count); + Assert.False(headers.IsReadOnly); + } + + [Fact] + public void SettingUnknownHeadersWorks() + { + IDictionary headers = new FrameRequestHeaders(); + + headers["custom"] = new[] { "value" }; + + Assert.NotNull(headers["custom"]); + Assert.Equal(1, headers["custom"].Length); + Assert.Equal("value", headers["custom"][0]); + } + + [Fact] + public void SettingKnownHeadersWorks() + { + IDictionary headers = new FrameRequestHeaders(); + + headers["host"] = new[] { "value" }; + + Assert.NotNull(headers["host"]); + Assert.Equal(1, headers["host"].Length); + Assert.Equal("value", headers["host"][0]); + } + + [Fact] + public void KnownAndCustomHeaderCountAddedTogether() + { + IDictionary headers = new FrameRequestHeaders(); + + headers["host"] = new[] { "value" }; + headers["custom"] = new[] { "value" }; + + Assert.Equal(2, headers.Count); + } + + [Fact] + public void TryGetValueWorksForKnownAndUnknownHeaders() + { + IDictionary headers = new FrameRequestHeaders(); + + string[] value; + Assert.False(headers.TryGetValue("host", out value)); + Assert.False(headers.TryGetValue("custom", out value)); + + headers["host"] = new[] { "value" }; + Assert.True(headers.TryGetValue("host", out value)); + Assert.False(headers.TryGetValue("custom", out value)); + + headers["custom"] = new[] { "value" }; + Assert.True(headers.TryGetValue("host", out value)); + Assert.True(headers.TryGetValue("custom", out value)); + } + + [Fact] + public void SameExceptionThrownForMissingKey() + { + IDictionary headers = new FrameRequestHeaders(); + + Assert.Throws(() => headers["custom"]); + Assert.Throws(() => headers["host"]); + } + + [Fact] + public void EntriesCanBeEnumerated() + { + IDictionary headers = new FrameRequestHeaders(); + var v1 = new[] { "localhost" }; + var v2 = new[] { "value" }; + headers["host"] = v1; + headers["custom"] = v2; + + Assert.Equal( + new[] { + new KeyValuePair("Host", v1), + new KeyValuePair("custom", v2), + }, + headers); + } + + [Fact] + public void KeysAndValuesCanBeEnumerated() + { + IDictionary headers = new FrameRequestHeaders(); + var v1 = new[] { "localhost" }; + var v2 = new[] { "value" }; + headers["host"] = v1; + headers["custom"] = v2; + + Assert.Equal( + new[] { "Host", "custom" }, + headers.Keys); + + Assert.Equal( + new[] { v1, v2 }, + headers.Values); + } + + + [Fact] + public void ContainsAndContainsKeyWork() + { + IDictionary headers = new FrameRequestHeaders(); + var kv1 = new KeyValuePair("host", new[] { "localhost" }); + var kv2 = new KeyValuePair("custom", new[] { "value" }); + var kv1b = new KeyValuePair("host", new[] { "localhost" }); + var kv2b = new KeyValuePair("custom", new[] { "value" }); + + Assert.False(headers.ContainsKey("host")); + Assert.False(headers.ContainsKey("custom")); + Assert.False(headers.Contains(kv1)); + Assert.False(headers.Contains(kv2)); + + headers["host"] = kv1.Value; + Assert.True(headers.ContainsKey("host")); + Assert.False(headers.ContainsKey("custom")); + Assert.True(headers.Contains(kv1)); + Assert.False(headers.Contains(kv2)); + Assert.False(headers.Contains(kv1b)); + Assert.False(headers.Contains(kv2b)); + + headers["custom"] = kv2.Value; + Assert.True(headers.ContainsKey("host")); + Assert.True(headers.ContainsKey("custom")); + Assert.True(headers.Contains(kv1)); + Assert.True(headers.Contains(kv2)); + Assert.False(headers.Contains(kv1b)); + Assert.False(headers.Contains(kv2b)); + } + + [Fact] + public void AddWorksLikeSetAndThrowsIfKeyExists() + { + IDictionary headers = new FrameRequestHeaders(); + + string[] value; + Assert.False(headers.TryGetValue("host", out value)); + Assert.False(headers.TryGetValue("custom", out value)); + + headers.Add("host", new[] { "localhost" }); + headers.Add("custom", new[] { "value" }); + Assert.True(headers.TryGetValue("host", out value)); + Assert.True(headers.TryGetValue("custom", out value)); + + Assert.Throws(() => headers.Add("host", new[] { "localhost" })); + Assert.Throws(() => headers.Add("custom", new[] { "value" })); + Assert.True(headers.TryGetValue("host", out value)); + Assert.True(headers.TryGetValue("custom", out value)); + } + + [Fact] + public void ClearRemovesAllHeaders() + { + IDictionary headers = new FrameRequestHeaders(); + headers.Add("host", new[] { "localhost" }); + headers.Add("custom", new[] { "value" }); + + string[] value; + Assert.Equal(2, headers.Count); + Assert.True(headers.TryGetValue("host", out value)); + Assert.True(headers.TryGetValue("custom", out value)); + + headers.Clear(); + + Assert.Equal(0, headers.Count); + Assert.False(headers.TryGetValue("host", out value)); + Assert.False(headers.TryGetValue("custom", out value)); + } + + [Fact] + public void RemoveTakesHeadersOutOfDictionary() + { + IDictionary headers = new FrameRequestHeaders(); + headers.Add("host", new[] { "localhost" }); + headers.Add("custom", new[] { "value" }); + + string[] value; + Assert.Equal(2, headers.Count); + Assert.True(headers.TryGetValue("host", out value)); + Assert.True(headers.TryGetValue("custom", out value)); + + Assert.True(headers.Remove("host")); + Assert.False(headers.Remove("host")); + + Assert.Equal(1, headers.Count); + Assert.False(headers.TryGetValue("host", out value)); + Assert.True(headers.TryGetValue("custom", out value)); + + Assert.True(headers.Remove("custom")); + Assert.False(headers.Remove("custom")); + + Assert.Equal(0, headers.Count); + Assert.False(headers.TryGetValue("host", out value)); + Assert.False(headers.TryGetValue("custom", out value)); + } + + [Fact] + public void CopyToMovesDataIntoArray() + { + IDictionary headers = new FrameRequestHeaders(); + headers.Add("host", new[] { "localhost" }); + headers.Add("custom", new[] { "value" }); + + var entries = new KeyValuePair[4]; + headers.CopyTo(entries, 1); + + Assert.Null(entries[0].Key); + Assert.Null(entries[0].Value); + + Assert.Equal("Host", entries[1].Key); + Assert.NotNull(entries[1].Value); + + Assert.Equal("custom", entries[2].Key); + Assert.NotNull(entries[2].Value); + + Assert.Null(entries[3].Key); + Assert.Null(entries[3].Value); + } + } +} From ad089be477a97c9730626e8aef4f03b8514d51a6 Mon Sep 17 00:00:00 2001 From: Louis DeJardin Date: Thu, 9 Jul 2015 11:49:14 -0700 Subject: [PATCH 0176/1662] Removing "I like pie" diagnostics --- .../KnownHeaders.cs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel.GeneratedCode/KnownHeaders.cs b/src/Microsoft.AspNet.Server.Kestrel.GeneratedCode/KnownHeaders.cs index 61cb71178d..1af18854a5 100644 --- a/src/Microsoft.AspNet.Server.Kestrel.GeneratedCode/KnownHeaders.cs +++ b/src/Microsoft.AspNet.Server.Kestrel.GeneratedCode/KnownHeaders.cs @@ -20,15 +20,13 @@ namespace Microsoft.AspNet.Server.Kestrel.GeneratedCode public string Name { get; set; } public int Index { get; set; } public string Identifier => Name.Replace("-", ""); - public string TestBit() => $"((_bits & ({1L << Index}L)) != 0)"; + public string TestBit() => $"((_bits & {1L << Index}L) != 0)"; public string SetBit() => $"_bits |= {1L << Index}L"; - public string ClearBit() => $"_bits &= ~{(1L << Index)}L"; + public string ClearBit() => $"_bits &= ~{1L << Index}L"; } public virtual void BeforeCompile(BeforeCompileContext context) { - Console.WriteLine("I like pie"); - var commonHeaders = new[] { "Cache-Control", From 96b03ee2120b51377aff4365d2f258ca818bb782 Mon Sep 17 00:00:00 2001 From: Louis DeJardin Date: Thu, 16 Jul 2015 21:57:33 -0700 Subject: [PATCH 0177/1662] Perf - enumerate with struct Conflicts: src/Microsoft.AspNet.Server.Kestrel/project.json --- .../KnownHeaders.cs | 85 +- .../Program.cs | 30 + .../Http/Frame.cs | 6 +- .../Http/FrameHeaders.Generated.cs | 6825 +++++++++++++++++ ...FrameRequestHeaders.cs => FrameHeaders.cs} | 118 +- .../compiler/preprocess/KnownHeaders.cs | 11 - .../project.json | 6 +- 7 files changed, 7024 insertions(+), 57 deletions(-) create mode 100644 src/Microsoft.AspNet.Server.Kestrel.GeneratedCode/Program.cs create mode 100644 src/Microsoft.AspNet.Server.Kestrel/Http/FrameHeaders.Generated.cs rename src/Microsoft.AspNet.Server.Kestrel/Http/{FrameRequestHeaders.cs => FrameHeaders.cs} (52%) delete mode 100644 src/Microsoft.AspNet.Server.Kestrel/compiler/preprocess/KnownHeaders.cs diff --git a/src/Microsoft.AspNet.Server.Kestrel.GeneratedCode/KnownHeaders.cs b/src/Microsoft.AspNet.Server.Kestrel.GeneratedCode/KnownHeaders.cs index 1af18854a5..3c082cb9a2 100644 --- a/src/Microsoft.AspNet.Server.Kestrel.GeneratedCode/KnownHeaders.cs +++ b/src/Microsoft.AspNet.Server.Kestrel.GeneratedCode/KnownHeaders.cs @@ -10,9 +10,9 @@ namespace Microsoft.AspNet.Server.Kestrel.GeneratedCode // To enable this option, right-click on the project and select the Properties menu item. In the Build tab select "Produce outputs on build". public class KnownHeaders : ICompileModule { - string Each(IEnumerable values, Func formatter) + static string Each(IEnumerable values, Func formatter) { - return values.Select(formatter).Aggregate((a, b) => a + b + "\r\n"); + return values.Select(formatter).Aggregate((a, b) => a + b); } class KnownHeader @@ -26,6 +26,12 @@ namespace Microsoft.AspNet.Server.Kestrel.GeneratedCode } public virtual void BeforeCompile(BeforeCompileContext context) + { + var syntaxTree = Microsoft.CodeAnalysis.CSharp.CSharpSyntaxTree.ParseText(GeneratedFile()); + context.Compilation = context.Compilation.AddSyntaxTrees(syntaxTree); + } + + public static string GeneratedFile() { var commonHeaders = new[] { @@ -71,7 +77,7 @@ namespace Microsoft.AspNet.Server.Kestrel.GeneratedCode "Referer", "Range", "TE", - "Translage", + "Translate", "User-Agent", }).Select((header, index) => new KnownHeader { @@ -113,7 +119,7 @@ namespace Microsoft.AspNet.Server.Kestrel.GeneratedCode } }; - var syntaxTree = Microsoft.CodeAnalysis.CSharp.CSharpSyntaxTree.ParseText($@" + return $@" using System; using System.Collections.Generic; @@ -122,11 +128,12 @@ namespace Microsoft.AspNet.Server.Kestrel.Http public partial class {loop.ClassName} {{ long _bits = 0; - {Each(loop.Headers, header => "string[] _" + header.Identifier + ";")} + {Each(loop.Headers, header => @" + string[] _" + header.Identifier + ";")} protected override int GetCountFast() {{ - var count = Unknown.Count; + var count = MaybeUnknown?.Count ?? 0; {Each(loop.Headers, header => $@" if ({header.TestBit()}) {{ @@ -142,7 +149,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http {{{Each(loop.HeadersByLength, byLength => $@" case {byLength.Key}: {{{Each(byLength, header => $@" - if (0 == StringComparer.OrdinalIgnoreCase.Compare(key, ""{header.Name}"")) + if (""{header.Name}"".Equals(key, StringComparison.OrdinalIgnoreCase)) {{ if ({header.TestBit()}) {{ @@ -156,7 +163,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http ")}}} break; ")}}} - return Unknown[key]; + if (MaybeUnknown == null) + {{ + throw new System.Collections.Generic.KeyNotFoundException(); + }} + return MaybeUnknown[key]; }} protected override bool TryGetValueFast(string key, out string[] value) @@ -165,7 +176,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http {{{Each(loop.HeadersByLength, byLength => $@" case {byLength.Key}: {{{Each(byLength, header => $@" - if (0 == StringComparer.OrdinalIgnoreCase.Compare(key, ""{header.Name}"")) + if (""{header.Name}"".Equals(key, StringComparison.OrdinalIgnoreCase)) {{ if ({header.TestBit()}) {{ @@ -181,7 +192,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http ")}}} break; ")}}} - return Unknown.TryGetValue(key, out value); + value = null; + return MaybeUnknown?.TryGetValue(key, out value) ?? false; }} protected override void SetValueFast(string key, string[] value) @@ -190,7 +202,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http {{{Each(loop.HeadersByLength, byLength => $@" case {byLength.Key}: {{{Each(byLength, header => $@" - if (0 == StringComparer.OrdinalIgnoreCase.Compare(key, ""{header.Name}"")) + if (""{header.Name}"".Equals(key, StringComparison.OrdinalIgnoreCase)) {{ {header.SetBit()}; _{header.Identifier} = value; @@ -208,7 +220,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http {{{Each(loop.HeadersByLength, byLength => $@" case {byLength.Key}: {{{Each(byLength, header => $@" - if (0 == StringComparer.OrdinalIgnoreCase.Compare(key, ""{header.Name}"")) + if (""{header.Name}"".Equals(key, StringComparison.OrdinalIgnoreCase)) {{ if ({header.TestBit()}) {{ @@ -230,7 +242,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http {{{Each(loop.HeadersByLength, byLength => $@" case {byLength.Key}: {{{Each(byLength, header => $@" - if (0 == StringComparer.OrdinalIgnoreCase.Compare(key, ""{header.Name}"")) + if (""{header.Name}"".Equals(key, StringComparison.OrdinalIgnoreCase)) {{ if ({header.TestBit()}) {{ @@ -245,13 +257,13 @@ namespace Microsoft.AspNet.Server.Kestrel.Http ")}}} break; ")}}} - return Unknown.Remove(key); + return MaybeUnknown?.Remove(key) ?? false; }} protected override void ClearFast() {{ _bits = 0; - Unknown.Clear(); + MaybeUnknown?.Clear(); }} protected override void CopyToFast(KeyValuePair[] array, int arrayIndex) @@ -273,27 +285,44 @@ namespace Microsoft.AspNet.Server.Kestrel.Http ++arrayIndex; }} ")} - ((ICollection>)Unknown).CopyTo(array, arrayIndex); + ((ICollection>)MaybeUnknown)?.CopyTo(array, arrayIndex); }} - protected override IEnumerable> EnumerateFast() + public partial struct Enumerator {{ - {Each(loop.Headers, header => $@" - if ({header.TestBit()}) - {{ - yield return new KeyValuePair(""{header.Name}"", _{header.Identifier}); - }} - ")} - foreach(var kv in Unknown) + public bool MoveNext() {{ - yield return kv; + switch (_state) + {{ + {Each(loop.Headers, header => $@" + case {header.Index}: + goto state{header.Index}; + ")} + default: + goto state_default; + }} + {Each(loop.Headers, header => $@" + state{header.Index}: + if ({header.TestBit()}) + {{ + _current = new KeyValuePair(""{header.Name}"", _collection._{header.Identifier}); + _state = {header.Index + 1}; + return true; + }} + ")} + state_default: + if (!_hasUnknown || !_unknownEnumerator.MoveNext()) + {{ + _current = default(KeyValuePair); + return false; + }} + _current = _unknownEnumerator.Current; + return true; }} }} }} ")}}} -"); - - context.Compilation = context.Compilation.AddSyntaxTrees(syntaxTree); +"; } public virtual void AfterCompile(AfterCompileContext context) diff --git a/src/Microsoft.AspNet.Server.Kestrel.GeneratedCode/Program.cs b/src/Microsoft.AspNet.Server.Kestrel.GeneratedCode/Program.cs new file mode 100644 index 0000000000..610176c1c6 --- /dev/null +++ b/src/Microsoft.AspNet.Server.Kestrel.GeneratedCode/Program.cs @@ -0,0 +1,30 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Threading.Tasks; + +namespace Microsoft.AspNet.Server.Kestrel.GeneratedCode +{ + public class Program + { + public int Main(string[] args) + { + var text = KnownHeaders.GeneratedFile(); + + if (args.Length == 1) + { + var existing = File.Exists(args[0]) ? File.ReadAllText(args[0]) : ""; + if (!string.Equals(text, existing)) + { + File.WriteAllText(args[0], text); + } + } + else + { + Console.WriteLine(text); + } + return 0; + } + } +} diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs index 4f66998345..c8a3b5576a 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs @@ -27,6 +27,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http private bool _resultStarted; private bool _responseStarted; private bool _keepAlive; + private readonly FrameRequestHeaders _requestHeaders = new FrameRequestHeaders(); + private readonly FrameResponseHeaders _responseHeaders = new FrameResponseHeaders(); /* //IDictionary _environment; @@ -43,8 +45,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { FrameControl = this; StatusCode = 200; - RequestHeaders = new Dictionary(StringComparer.OrdinalIgnoreCase); - ResponseHeaders = new Dictionary(StringComparer.OrdinalIgnoreCase); + RequestHeaders = _requestHeaders; + ResponseHeaders = _responseHeaders; } public string Method { get; set; } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameHeaders.Generated.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameHeaders.Generated.cs new file mode 100644 index 0000000000..90cf28d245 --- /dev/null +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameHeaders.Generated.cs @@ -0,0 +1,6825 @@ + +using System; +using System.Collections.Generic; + +namespace Microsoft.AspNet.Server.Kestrel.Http +{ + public partial class FrameRequestHeaders + { + long _bits = 0; + + string[] _CacheControl; + string[] _Connection; + string[] _Date; + string[] _KeepAlive; + string[] _Pragma; + string[] _Trailer; + string[] _TransferEncoding; + string[] _Upgrade; + string[] _Via; + string[] _Warning; + string[] _Allow; + string[] _ContentLength; + string[] _ContentType; + string[] _ContentEncoding; + string[] _ContentLanguage; + string[] _ContentLocation; + string[] _ContentMD5; + string[] _ContentRange; + string[] _Expires; + string[] _LastModified; + string[] _Accept; + string[] _AcceptCharset; + string[] _AcceptEncoding; + string[] _AcceptLanguage; + string[] _Authorization; + string[] _Cookie; + string[] _Expect; + string[] _From; + string[] _Host; + string[] _IfMatch; + string[] _IfModifiedSince; + string[] _IfNoneMatch; + string[] _IfRange; + string[] _IfUnmodifiedSince; + string[] _MaxForwards; + string[] _ProxyAuthorization; + string[] _Referer; + string[] _Range; + string[] _TE; + string[] _Translate; + string[] _UserAgent; + + protected override int GetCountFast() + { + var count = MaybeUnknown?.Count ?? 0; + + if (((_bits & 1L) != 0)) + { + ++count; + } + + if (((_bits & 2L) != 0)) + { + ++count; + } + + if (((_bits & 4L) != 0)) + { + ++count; + } + + if (((_bits & 8L) != 0)) + { + ++count; + } + + if (((_bits & 16L) != 0)) + { + ++count; + } + + if (((_bits & 32L) != 0)) + { + ++count; + } + + if (((_bits & 64L) != 0)) + { + ++count; + } + + if (((_bits & 128L) != 0)) + { + ++count; + } + + if (((_bits & 256L) != 0)) + { + ++count; + } + + if (((_bits & 512L) != 0)) + { + ++count; + } + + if (((_bits & 1024L) != 0)) + { + ++count; + } + + if (((_bits & 2048L) != 0)) + { + ++count; + } + + if (((_bits & 4096L) != 0)) + { + ++count; + } + + if (((_bits & 8192L) != 0)) + { + ++count; + } + + if (((_bits & 16384L) != 0)) + { + ++count; + } + + if (((_bits & 32768L) != 0)) + { + ++count; + } + + if (((_bits & 65536L) != 0)) + { + ++count; + } + + if (((_bits & 131072L) != 0)) + { + ++count; + } + + if (((_bits & 262144L) != 0)) + { + ++count; + } + + if (((_bits & 524288L) != 0)) + { + ++count; + } + + if (((_bits & 1048576L) != 0)) + { + ++count; + } + + if (((_bits & 2097152L) != 0)) + { + ++count; + } + + if (((_bits & 4194304L) != 0)) + { + ++count; + } + + if (((_bits & 8388608L) != 0)) + { + ++count; + } + + if (((_bits & 16777216L) != 0)) + { + ++count; + } + + if (((_bits & 33554432L) != 0)) + { + ++count; + } + + if (((_bits & 67108864L) != 0)) + { + ++count; + } + + if (((_bits & 134217728L) != 0)) + { + ++count; + } + + if (((_bits & 268435456L) != 0)) + { + ++count; + } + + if (((_bits & 536870912L) != 0)) + { + ++count; + } + + if (((_bits & 1073741824L) != 0)) + { + ++count; + } + + if (((_bits & 2147483648L) != 0)) + { + ++count; + } + + if (((_bits & 4294967296L) != 0)) + { + ++count; + } + + if (((_bits & 8589934592L) != 0)) + { + ++count; + } + + if (((_bits & 17179869184L) != 0)) + { + ++count; + } + + if (((_bits & 34359738368L) != 0)) + { + ++count; + } + + if (((_bits & 68719476736L) != 0)) + { + ++count; + } + + if (((_bits & 137438953472L) != 0)) + { + ++count; + } + + if (((_bits & 274877906944L) != 0)) + { + ++count; + } + + if (((_bits & 549755813888L) != 0)) + { + ++count; + } + + if (((_bits & 1099511627776L) != 0)) + { + ++count; + } + + return count; + } + + protected override string[] GetValueFast(string key) + { + switch(key.Length) + { + case 13: + { + if ("Cache-Control".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 1L) != 0)) + { + return _CacheControl; + } + else + { + throw new System.Collections.Generic.KeyNotFoundException(); + } + } + + if ("Content-Range".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 131072L) != 0)) + { + return _ContentRange; + } + else + { + throw new System.Collections.Generic.KeyNotFoundException(); + } + } + + if ("Last-Modified".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 524288L) != 0)) + { + return _LastModified; + } + else + { + throw new System.Collections.Generic.KeyNotFoundException(); + } + } + + if ("Authorization".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 16777216L) != 0)) + { + return _Authorization; + } + else + { + throw new System.Collections.Generic.KeyNotFoundException(); + } + } + + if ("If-None-Match".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 2147483648L) != 0)) + { + return _IfNoneMatch; + } + else + { + throw new System.Collections.Generic.KeyNotFoundException(); + } + } + } + break; + + case 10: + { + if ("Connection".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 2L) != 0)) + { + return _Connection; + } + else + { + throw new System.Collections.Generic.KeyNotFoundException(); + } + } + + if ("Keep-Alive".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 8L) != 0)) + { + return _KeepAlive; + } + else + { + throw new System.Collections.Generic.KeyNotFoundException(); + } + } + + if ("User-Agent".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 1099511627776L) != 0)) + { + return _UserAgent; + } + else + { + throw new System.Collections.Generic.KeyNotFoundException(); + } + } + } + break; + + case 4: + { + if ("Date".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 4L) != 0)) + { + return _Date; + } + else + { + throw new System.Collections.Generic.KeyNotFoundException(); + } + } + + if ("From".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 134217728L) != 0)) + { + return _From; + } + else + { + throw new System.Collections.Generic.KeyNotFoundException(); + } + } + + if ("Host".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 268435456L) != 0)) + { + return _Host; + } + else + { + throw new System.Collections.Generic.KeyNotFoundException(); + } + } + } + break; + + case 6: + { + if ("Pragma".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 16L) != 0)) + { + return _Pragma; + } + else + { + throw new System.Collections.Generic.KeyNotFoundException(); + } + } + + if ("Accept".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 1048576L) != 0)) + { + return _Accept; + } + else + { + throw new System.Collections.Generic.KeyNotFoundException(); + } + } + + if ("Cookie".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 33554432L) != 0)) + { + return _Cookie; + } + else + { + throw new System.Collections.Generic.KeyNotFoundException(); + } + } + + if ("Expect".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 67108864L) != 0)) + { + return _Expect; + } + else + { + throw new System.Collections.Generic.KeyNotFoundException(); + } + } + } + break; + + case 7: + { + if ("Trailer".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 32L) != 0)) + { + return _Trailer; + } + else + { + throw new System.Collections.Generic.KeyNotFoundException(); + } + } + + if ("Upgrade".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 128L) != 0)) + { + return _Upgrade; + } + else + { + throw new System.Collections.Generic.KeyNotFoundException(); + } + } + + if ("Warning".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 512L) != 0)) + { + return _Warning; + } + else + { + throw new System.Collections.Generic.KeyNotFoundException(); + } + } + + if ("Expires".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 262144L) != 0)) + { + return _Expires; + } + else + { + throw new System.Collections.Generic.KeyNotFoundException(); + } + } + + if ("Referer".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 68719476736L) != 0)) + { + return _Referer; + } + else + { + throw new System.Collections.Generic.KeyNotFoundException(); + } + } + } + break; + + case 17: + { + if ("Transfer-Encoding".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 64L) != 0)) + { + return _TransferEncoding; + } + else + { + throw new System.Collections.Generic.KeyNotFoundException(); + } + } + + if ("If-Modified-Since".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 1073741824L) != 0)) + { + return _IfModifiedSince; + } + else + { + throw new System.Collections.Generic.KeyNotFoundException(); + } + } + } + break; + + case 3: + { + if ("Via".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 256L) != 0)) + { + return _Via; + } + else + { + throw new System.Collections.Generic.KeyNotFoundException(); + } + } + } + break; + + case 5: + { + if ("Allow".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 1024L) != 0)) + { + return _Allow; + } + else + { + throw new System.Collections.Generic.KeyNotFoundException(); + } + } + + if ("Range".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 137438953472L) != 0)) + { + return _Range; + } + else + { + throw new System.Collections.Generic.KeyNotFoundException(); + } + } + } + break; + + case 14: + { + if ("Content-Length".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 2048L) != 0)) + { + return _ContentLength; + } + else + { + throw new System.Collections.Generic.KeyNotFoundException(); + } + } + + if ("Accept-Charset".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 2097152L) != 0)) + { + return _AcceptCharset; + } + else + { + throw new System.Collections.Generic.KeyNotFoundException(); + } + } + } + break; + + case 12: + { + if ("Content-Type".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 4096L) != 0)) + { + return _ContentType; + } + else + { + throw new System.Collections.Generic.KeyNotFoundException(); + } + } + + if ("Max-Forwards".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 17179869184L) != 0)) + { + return _MaxForwards; + } + else + { + throw new System.Collections.Generic.KeyNotFoundException(); + } + } + } + break; + + case 16: + { + if ("Content-Encoding".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 8192L) != 0)) + { + return _ContentEncoding; + } + else + { + throw new System.Collections.Generic.KeyNotFoundException(); + } + } + + if ("Content-Language".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 16384L) != 0)) + { + return _ContentLanguage; + } + else + { + throw new System.Collections.Generic.KeyNotFoundException(); + } + } + + if ("Content-Location".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 32768L) != 0)) + { + return _ContentLocation; + } + else + { + throw new System.Collections.Generic.KeyNotFoundException(); + } + } + } + break; + + case 11: + { + if ("Content-MD5".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 65536L) != 0)) + { + return _ContentMD5; + } + else + { + throw new System.Collections.Generic.KeyNotFoundException(); + } + } + } + break; + + case 15: + { + if ("Accept-Encoding".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 4194304L) != 0)) + { + return _AcceptEncoding; + } + else + { + throw new System.Collections.Generic.KeyNotFoundException(); + } + } + + if ("Accept-Language".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 8388608L) != 0)) + { + return _AcceptLanguage; + } + else + { + throw new System.Collections.Generic.KeyNotFoundException(); + } + } + } + break; + + case 8: + { + if ("If-Match".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 536870912L) != 0)) + { + return _IfMatch; + } + else + { + throw new System.Collections.Generic.KeyNotFoundException(); + } + } + + if ("If-Range".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 4294967296L) != 0)) + { + return _IfRange; + } + else + { + throw new System.Collections.Generic.KeyNotFoundException(); + } + } + } + break; + + case 19: + { + if ("If-Unmodified-Since".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 8589934592L) != 0)) + { + return _IfUnmodifiedSince; + } + else + { + throw new System.Collections.Generic.KeyNotFoundException(); + } + } + + if ("Proxy-Authorization".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 34359738368L) != 0)) + { + return _ProxyAuthorization; + } + else + { + throw new System.Collections.Generic.KeyNotFoundException(); + } + } + } + break; + + case 2: + { + if ("TE".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 274877906944L) != 0)) + { + return _TE; + } + else + { + throw new System.Collections.Generic.KeyNotFoundException(); + } + } + } + break; + + case 9: + { + if ("Translate".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 549755813888L) != 0)) + { + return _Translate; + } + else + { + throw new System.Collections.Generic.KeyNotFoundException(); + } + } + } + break; + } + if (MaybeUnknown == null) + { + throw new System.Collections.Generic.KeyNotFoundException(); + } + return MaybeUnknown[key]; + } + + protected override bool TryGetValueFast(string key, out string[] value) + { + switch(key.Length) + { + case 13: + { + if ("Cache-Control".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 1L) != 0)) + { + value = _CacheControl; + return true; + } + else + { + value = null; + return false; + } + } + + if ("Content-Range".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 131072L) != 0)) + { + value = _ContentRange; + return true; + } + else + { + value = null; + return false; + } + } + + if ("Last-Modified".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 524288L) != 0)) + { + value = _LastModified; + return true; + } + else + { + value = null; + return false; + } + } + + if ("Authorization".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 16777216L) != 0)) + { + value = _Authorization; + return true; + } + else + { + value = null; + return false; + } + } + + if ("If-None-Match".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 2147483648L) != 0)) + { + value = _IfNoneMatch; + return true; + } + else + { + value = null; + return false; + } + } + } + break; + + case 10: + { + if ("Connection".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 2L) != 0)) + { + value = _Connection; + return true; + } + else + { + value = null; + return false; + } + } + + if ("Keep-Alive".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 8L) != 0)) + { + value = _KeepAlive; + return true; + } + else + { + value = null; + return false; + } + } + + if ("User-Agent".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 1099511627776L) != 0)) + { + value = _UserAgent; + return true; + } + else + { + value = null; + return false; + } + } + } + break; + + case 4: + { + if ("Date".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 4L) != 0)) + { + value = _Date; + return true; + } + else + { + value = null; + return false; + } + } + + if ("From".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 134217728L) != 0)) + { + value = _From; + return true; + } + else + { + value = null; + return false; + } + } + + if ("Host".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 268435456L) != 0)) + { + value = _Host; + return true; + } + else + { + value = null; + return false; + } + } + } + break; + + case 6: + { + if ("Pragma".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 16L) != 0)) + { + value = _Pragma; + return true; + } + else + { + value = null; + return false; + } + } + + if ("Accept".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 1048576L) != 0)) + { + value = _Accept; + return true; + } + else + { + value = null; + return false; + } + } + + if ("Cookie".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 33554432L) != 0)) + { + value = _Cookie; + return true; + } + else + { + value = null; + return false; + } + } + + if ("Expect".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 67108864L) != 0)) + { + value = _Expect; + return true; + } + else + { + value = null; + return false; + } + } + } + break; + + case 7: + { + if ("Trailer".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 32L) != 0)) + { + value = _Trailer; + return true; + } + else + { + value = null; + return false; + } + } + + if ("Upgrade".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 128L) != 0)) + { + value = _Upgrade; + return true; + } + else + { + value = null; + return false; + } + } + + if ("Warning".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 512L) != 0)) + { + value = _Warning; + return true; + } + else + { + value = null; + return false; + } + } + + if ("Expires".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 262144L) != 0)) + { + value = _Expires; + return true; + } + else + { + value = null; + return false; + } + } + + if ("Referer".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 68719476736L) != 0)) + { + value = _Referer; + return true; + } + else + { + value = null; + return false; + } + } + } + break; + + case 17: + { + if ("Transfer-Encoding".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 64L) != 0)) + { + value = _TransferEncoding; + return true; + } + else + { + value = null; + return false; + } + } + + if ("If-Modified-Since".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 1073741824L) != 0)) + { + value = _IfModifiedSince; + return true; + } + else + { + value = null; + return false; + } + } + } + break; + + case 3: + { + if ("Via".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 256L) != 0)) + { + value = _Via; + return true; + } + else + { + value = null; + return false; + } + } + } + break; + + case 5: + { + if ("Allow".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 1024L) != 0)) + { + value = _Allow; + return true; + } + else + { + value = null; + return false; + } + } + + if ("Range".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 137438953472L) != 0)) + { + value = _Range; + return true; + } + else + { + value = null; + return false; + } + } + } + break; + + case 14: + { + if ("Content-Length".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 2048L) != 0)) + { + value = _ContentLength; + return true; + } + else + { + value = null; + return false; + } + } + + if ("Accept-Charset".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 2097152L) != 0)) + { + value = _AcceptCharset; + return true; + } + else + { + value = null; + return false; + } + } + } + break; + + case 12: + { + if ("Content-Type".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 4096L) != 0)) + { + value = _ContentType; + return true; + } + else + { + value = null; + return false; + } + } + + if ("Max-Forwards".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 17179869184L) != 0)) + { + value = _MaxForwards; + return true; + } + else + { + value = null; + return false; + } + } + } + break; + + case 16: + { + if ("Content-Encoding".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 8192L) != 0)) + { + value = _ContentEncoding; + return true; + } + else + { + value = null; + return false; + } + } + + if ("Content-Language".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 16384L) != 0)) + { + value = _ContentLanguage; + return true; + } + else + { + value = null; + return false; + } + } + + if ("Content-Location".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 32768L) != 0)) + { + value = _ContentLocation; + return true; + } + else + { + value = null; + return false; + } + } + } + break; + + case 11: + { + if ("Content-MD5".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 65536L) != 0)) + { + value = _ContentMD5; + return true; + } + else + { + value = null; + return false; + } + } + } + break; + + case 15: + { + if ("Accept-Encoding".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 4194304L) != 0)) + { + value = _AcceptEncoding; + return true; + } + else + { + value = null; + return false; + } + } + + if ("Accept-Language".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 8388608L) != 0)) + { + value = _AcceptLanguage; + return true; + } + else + { + value = null; + return false; + } + } + } + break; + + case 8: + { + if ("If-Match".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 536870912L) != 0)) + { + value = _IfMatch; + return true; + } + else + { + value = null; + return false; + } + } + + if ("If-Range".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 4294967296L) != 0)) + { + value = _IfRange; + return true; + } + else + { + value = null; + return false; + } + } + } + break; + + case 19: + { + if ("If-Unmodified-Since".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 8589934592L) != 0)) + { + value = _IfUnmodifiedSince; + return true; + } + else + { + value = null; + return false; + } + } + + if ("Proxy-Authorization".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 34359738368L) != 0)) + { + value = _ProxyAuthorization; + return true; + } + else + { + value = null; + return false; + } + } + } + break; + + case 2: + { + if ("TE".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 274877906944L) != 0)) + { + value = _TE; + return true; + } + else + { + value = null; + return false; + } + } + } + break; + + case 9: + { + if ("Translate".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 549755813888L) != 0)) + { + value = _Translate; + return true; + } + else + { + value = null; + return false; + } + } + } + break; + } + value = null; + return MaybeUnknown?.TryGetValue(key, out value) ?? false; + } + + protected override void SetValueFast(string key, string[] value) + { + switch(key.Length) + { + case 13: + { + if ("Cache-Control".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + _bits |= 1L; + _CacheControl = value; + return; + } + + if ("Content-Range".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + _bits |= 131072L; + _ContentRange = value; + return; + } + + if ("Last-Modified".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + _bits |= 524288L; + _LastModified = value; + return; + } + + if ("Authorization".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + _bits |= 16777216L; + _Authorization = value; + return; + } + + if ("If-None-Match".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + _bits |= 2147483648L; + _IfNoneMatch = value; + return; + } + } + break; + + case 10: + { + if ("Connection".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + _bits |= 2L; + _Connection = value; + return; + } + + if ("Keep-Alive".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + _bits |= 8L; + _KeepAlive = value; + return; + } + + if ("User-Agent".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + _bits |= 1099511627776L; + _UserAgent = value; + return; + } + } + break; + + case 4: + { + if ("Date".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + _bits |= 4L; + _Date = value; + return; + } + + if ("From".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + _bits |= 134217728L; + _From = value; + return; + } + + if ("Host".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + _bits |= 268435456L; + _Host = value; + return; + } + } + break; + + case 6: + { + if ("Pragma".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + _bits |= 16L; + _Pragma = value; + return; + } + + if ("Accept".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + _bits |= 1048576L; + _Accept = value; + return; + } + + if ("Cookie".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + _bits |= 33554432L; + _Cookie = value; + return; + } + + if ("Expect".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + _bits |= 67108864L; + _Expect = value; + return; + } + } + break; + + case 7: + { + if ("Trailer".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + _bits |= 32L; + _Trailer = value; + return; + } + + if ("Upgrade".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + _bits |= 128L; + _Upgrade = value; + return; + } + + if ("Warning".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + _bits |= 512L; + _Warning = value; + return; + } + + if ("Expires".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + _bits |= 262144L; + _Expires = value; + return; + } + + if ("Referer".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + _bits |= 68719476736L; + _Referer = value; + return; + } + } + break; + + case 17: + { + if ("Transfer-Encoding".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + _bits |= 64L; + _TransferEncoding = value; + return; + } + + if ("If-Modified-Since".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + _bits |= 1073741824L; + _IfModifiedSince = value; + return; + } + } + break; + + case 3: + { + if ("Via".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + _bits |= 256L; + _Via = value; + return; + } + } + break; + + case 5: + { + if ("Allow".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + _bits |= 1024L; + _Allow = value; + return; + } + + if ("Range".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + _bits |= 137438953472L; + _Range = value; + return; + } + } + break; + + case 14: + { + if ("Content-Length".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + _bits |= 2048L; + _ContentLength = value; + return; + } + + if ("Accept-Charset".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + _bits |= 2097152L; + _AcceptCharset = value; + return; + } + } + break; + + case 12: + { + if ("Content-Type".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + _bits |= 4096L; + _ContentType = value; + return; + } + + if ("Max-Forwards".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + _bits |= 17179869184L; + _MaxForwards = value; + return; + } + } + break; + + case 16: + { + if ("Content-Encoding".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + _bits |= 8192L; + _ContentEncoding = value; + return; + } + + if ("Content-Language".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + _bits |= 16384L; + _ContentLanguage = value; + return; + } + + if ("Content-Location".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + _bits |= 32768L; + _ContentLocation = value; + return; + } + } + break; + + case 11: + { + if ("Content-MD5".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + _bits |= 65536L; + _ContentMD5 = value; + return; + } + } + break; + + case 15: + { + if ("Accept-Encoding".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + _bits |= 4194304L; + _AcceptEncoding = value; + return; + } + + if ("Accept-Language".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + _bits |= 8388608L; + _AcceptLanguage = value; + return; + } + } + break; + + case 8: + { + if ("If-Match".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + _bits |= 536870912L; + _IfMatch = value; + return; + } + + if ("If-Range".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + _bits |= 4294967296L; + _IfRange = value; + return; + } + } + break; + + case 19: + { + if ("If-Unmodified-Since".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + _bits |= 8589934592L; + _IfUnmodifiedSince = value; + return; + } + + if ("Proxy-Authorization".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + _bits |= 34359738368L; + _ProxyAuthorization = value; + return; + } + } + break; + + case 2: + { + if ("TE".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + _bits |= 274877906944L; + _TE = value; + return; + } + } + break; + + case 9: + { + if ("Translate".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + _bits |= 549755813888L; + _Translate = value; + return; + } + } + break; + } + Unknown[key] = value; + } + + protected override void AddValueFast(string key, string[] value) + { + switch(key.Length) + { + case 13: + { + if ("Cache-Control".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 1L) != 0)) + { + throw new ArgumentException("An item with the same key has already been added."); + } + _bits |= 1L; + _CacheControl = value; + return; + } + + if ("Content-Range".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 131072L) != 0)) + { + throw new ArgumentException("An item with the same key has already been added."); + } + _bits |= 131072L; + _ContentRange = value; + return; + } + + if ("Last-Modified".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 524288L) != 0)) + { + throw new ArgumentException("An item with the same key has already been added."); + } + _bits |= 524288L; + _LastModified = value; + return; + } + + if ("Authorization".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 16777216L) != 0)) + { + throw new ArgumentException("An item with the same key has already been added."); + } + _bits |= 16777216L; + _Authorization = value; + return; + } + + if ("If-None-Match".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 2147483648L) != 0)) + { + throw new ArgumentException("An item with the same key has already been added."); + } + _bits |= 2147483648L; + _IfNoneMatch = value; + return; + } + } + break; + + case 10: + { + if ("Connection".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 2L) != 0)) + { + throw new ArgumentException("An item with the same key has already been added."); + } + _bits |= 2L; + _Connection = value; + return; + } + + if ("Keep-Alive".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 8L) != 0)) + { + throw new ArgumentException("An item with the same key has already been added."); + } + _bits |= 8L; + _KeepAlive = value; + return; + } + + if ("User-Agent".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 1099511627776L) != 0)) + { + throw new ArgumentException("An item with the same key has already been added."); + } + _bits |= 1099511627776L; + _UserAgent = value; + return; + } + } + break; + + case 4: + { + if ("Date".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 4L) != 0)) + { + throw new ArgumentException("An item with the same key has already been added."); + } + _bits |= 4L; + _Date = value; + return; + } + + if ("From".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 134217728L) != 0)) + { + throw new ArgumentException("An item with the same key has already been added."); + } + _bits |= 134217728L; + _From = value; + return; + } + + if ("Host".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 268435456L) != 0)) + { + throw new ArgumentException("An item with the same key has already been added."); + } + _bits |= 268435456L; + _Host = value; + return; + } + } + break; + + case 6: + { + if ("Pragma".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 16L) != 0)) + { + throw new ArgumentException("An item with the same key has already been added."); + } + _bits |= 16L; + _Pragma = value; + return; + } + + if ("Accept".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 1048576L) != 0)) + { + throw new ArgumentException("An item with the same key has already been added."); + } + _bits |= 1048576L; + _Accept = value; + return; + } + + if ("Cookie".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 33554432L) != 0)) + { + throw new ArgumentException("An item with the same key has already been added."); + } + _bits |= 33554432L; + _Cookie = value; + return; + } + + if ("Expect".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 67108864L) != 0)) + { + throw new ArgumentException("An item with the same key has already been added."); + } + _bits |= 67108864L; + _Expect = value; + return; + } + } + break; + + case 7: + { + if ("Trailer".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 32L) != 0)) + { + throw new ArgumentException("An item with the same key has already been added."); + } + _bits |= 32L; + _Trailer = value; + return; + } + + if ("Upgrade".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 128L) != 0)) + { + throw new ArgumentException("An item with the same key has already been added."); + } + _bits |= 128L; + _Upgrade = value; + return; + } + + if ("Warning".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 512L) != 0)) + { + throw new ArgumentException("An item with the same key has already been added."); + } + _bits |= 512L; + _Warning = value; + return; + } + + if ("Expires".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 262144L) != 0)) + { + throw new ArgumentException("An item with the same key has already been added."); + } + _bits |= 262144L; + _Expires = value; + return; + } + + if ("Referer".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 68719476736L) != 0)) + { + throw new ArgumentException("An item with the same key has already been added."); + } + _bits |= 68719476736L; + _Referer = value; + return; + } + } + break; + + case 17: + { + if ("Transfer-Encoding".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 64L) != 0)) + { + throw new ArgumentException("An item with the same key has already been added."); + } + _bits |= 64L; + _TransferEncoding = value; + return; + } + + if ("If-Modified-Since".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 1073741824L) != 0)) + { + throw new ArgumentException("An item with the same key has already been added."); + } + _bits |= 1073741824L; + _IfModifiedSince = value; + return; + } + } + break; + + case 3: + { + if ("Via".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 256L) != 0)) + { + throw new ArgumentException("An item with the same key has already been added."); + } + _bits |= 256L; + _Via = value; + return; + } + } + break; + + case 5: + { + if ("Allow".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 1024L) != 0)) + { + throw new ArgumentException("An item with the same key has already been added."); + } + _bits |= 1024L; + _Allow = value; + return; + } + + if ("Range".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 137438953472L) != 0)) + { + throw new ArgumentException("An item with the same key has already been added."); + } + _bits |= 137438953472L; + _Range = value; + return; + } + } + break; + + case 14: + { + if ("Content-Length".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 2048L) != 0)) + { + throw new ArgumentException("An item with the same key has already been added."); + } + _bits |= 2048L; + _ContentLength = value; + return; + } + + if ("Accept-Charset".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 2097152L) != 0)) + { + throw new ArgumentException("An item with the same key has already been added."); + } + _bits |= 2097152L; + _AcceptCharset = value; + return; + } + } + break; + + case 12: + { + if ("Content-Type".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 4096L) != 0)) + { + throw new ArgumentException("An item with the same key has already been added."); + } + _bits |= 4096L; + _ContentType = value; + return; + } + + if ("Max-Forwards".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 17179869184L) != 0)) + { + throw new ArgumentException("An item with the same key has already been added."); + } + _bits |= 17179869184L; + _MaxForwards = value; + return; + } + } + break; + + case 16: + { + if ("Content-Encoding".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 8192L) != 0)) + { + throw new ArgumentException("An item with the same key has already been added."); + } + _bits |= 8192L; + _ContentEncoding = value; + return; + } + + if ("Content-Language".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 16384L) != 0)) + { + throw new ArgumentException("An item with the same key has already been added."); + } + _bits |= 16384L; + _ContentLanguage = value; + return; + } + + if ("Content-Location".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 32768L) != 0)) + { + throw new ArgumentException("An item with the same key has already been added."); + } + _bits |= 32768L; + _ContentLocation = value; + return; + } + } + break; + + case 11: + { + if ("Content-MD5".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 65536L) != 0)) + { + throw new ArgumentException("An item with the same key has already been added."); + } + _bits |= 65536L; + _ContentMD5 = value; + return; + } + } + break; + + case 15: + { + if ("Accept-Encoding".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 4194304L) != 0)) + { + throw new ArgumentException("An item with the same key has already been added."); + } + _bits |= 4194304L; + _AcceptEncoding = value; + return; + } + + if ("Accept-Language".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 8388608L) != 0)) + { + throw new ArgumentException("An item with the same key has already been added."); + } + _bits |= 8388608L; + _AcceptLanguage = value; + return; + } + } + break; + + case 8: + { + if ("If-Match".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 536870912L) != 0)) + { + throw new ArgumentException("An item with the same key has already been added."); + } + _bits |= 536870912L; + _IfMatch = value; + return; + } + + if ("If-Range".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 4294967296L) != 0)) + { + throw new ArgumentException("An item with the same key has already been added."); + } + _bits |= 4294967296L; + _IfRange = value; + return; + } + } + break; + + case 19: + { + if ("If-Unmodified-Since".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 8589934592L) != 0)) + { + throw new ArgumentException("An item with the same key has already been added."); + } + _bits |= 8589934592L; + _IfUnmodifiedSince = value; + return; + } + + if ("Proxy-Authorization".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 34359738368L) != 0)) + { + throw new ArgumentException("An item with the same key has already been added."); + } + _bits |= 34359738368L; + _ProxyAuthorization = value; + return; + } + } + break; + + case 2: + { + if ("TE".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 274877906944L) != 0)) + { + throw new ArgumentException("An item with the same key has already been added."); + } + _bits |= 274877906944L; + _TE = value; + return; + } + } + break; + + case 9: + { + if ("Translate".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 549755813888L) != 0)) + { + throw new ArgumentException("An item with the same key has already been added."); + } + _bits |= 549755813888L; + _Translate = value; + return; + } + } + break; + } + Unknown.Add(key, value); + } + + protected override bool RemoveFast(string key) + { + switch(key.Length) + { + case 13: + { + if ("Cache-Control".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 1L) != 0)) + { + _bits &= ~1L; + return true; + } + else + { + return false; + } + } + + if ("Content-Range".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 131072L) != 0)) + { + _bits &= ~131072L; + return true; + } + else + { + return false; + } + } + + if ("Last-Modified".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 524288L) != 0)) + { + _bits &= ~524288L; + return true; + } + else + { + return false; + } + } + + if ("Authorization".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 16777216L) != 0)) + { + _bits &= ~16777216L; + return true; + } + else + { + return false; + } + } + + if ("If-None-Match".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 2147483648L) != 0)) + { + _bits &= ~2147483648L; + return true; + } + else + { + return false; + } + } + } + break; + + case 10: + { + if ("Connection".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 2L) != 0)) + { + _bits &= ~2L; + return true; + } + else + { + return false; + } + } + + if ("Keep-Alive".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 8L) != 0)) + { + _bits &= ~8L; + return true; + } + else + { + return false; + } + } + + if ("User-Agent".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 1099511627776L) != 0)) + { + _bits &= ~1099511627776L; + return true; + } + else + { + return false; + } + } + } + break; + + case 4: + { + if ("Date".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 4L) != 0)) + { + _bits &= ~4L; + return true; + } + else + { + return false; + } + } + + if ("From".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 134217728L) != 0)) + { + _bits &= ~134217728L; + return true; + } + else + { + return false; + } + } + + if ("Host".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 268435456L) != 0)) + { + _bits &= ~268435456L; + return true; + } + else + { + return false; + } + } + } + break; + + case 6: + { + if ("Pragma".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 16L) != 0)) + { + _bits &= ~16L; + return true; + } + else + { + return false; + } + } + + if ("Accept".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 1048576L) != 0)) + { + _bits &= ~1048576L; + return true; + } + else + { + return false; + } + } + + if ("Cookie".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 33554432L) != 0)) + { + _bits &= ~33554432L; + return true; + } + else + { + return false; + } + } + + if ("Expect".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 67108864L) != 0)) + { + _bits &= ~67108864L; + return true; + } + else + { + return false; + } + } + } + break; + + case 7: + { + if ("Trailer".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 32L) != 0)) + { + _bits &= ~32L; + return true; + } + else + { + return false; + } + } + + if ("Upgrade".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 128L) != 0)) + { + _bits &= ~128L; + return true; + } + else + { + return false; + } + } + + if ("Warning".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 512L) != 0)) + { + _bits &= ~512L; + return true; + } + else + { + return false; + } + } + + if ("Expires".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 262144L) != 0)) + { + _bits &= ~262144L; + return true; + } + else + { + return false; + } + } + + if ("Referer".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 68719476736L) != 0)) + { + _bits &= ~68719476736L; + return true; + } + else + { + return false; + } + } + } + break; + + case 17: + { + if ("Transfer-Encoding".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 64L) != 0)) + { + _bits &= ~64L; + return true; + } + else + { + return false; + } + } + + if ("If-Modified-Since".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 1073741824L) != 0)) + { + _bits &= ~1073741824L; + return true; + } + else + { + return false; + } + } + } + break; + + case 3: + { + if ("Via".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 256L) != 0)) + { + _bits &= ~256L; + return true; + } + else + { + return false; + } + } + } + break; + + case 5: + { + if ("Allow".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 1024L) != 0)) + { + _bits &= ~1024L; + return true; + } + else + { + return false; + } + } + + if ("Range".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 137438953472L) != 0)) + { + _bits &= ~137438953472L; + return true; + } + else + { + return false; + } + } + } + break; + + case 14: + { + if ("Content-Length".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 2048L) != 0)) + { + _bits &= ~2048L; + return true; + } + else + { + return false; + } + } + + if ("Accept-Charset".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 2097152L) != 0)) + { + _bits &= ~2097152L; + return true; + } + else + { + return false; + } + } + } + break; + + case 12: + { + if ("Content-Type".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 4096L) != 0)) + { + _bits &= ~4096L; + return true; + } + else + { + return false; + } + } + + if ("Max-Forwards".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 17179869184L) != 0)) + { + _bits &= ~17179869184L; + return true; + } + else + { + return false; + } + } + } + break; + + case 16: + { + if ("Content-Encoding".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 8192L) != 0)) + { + _bits &= ~8192L; + return true; + } + else + { + return false; + } + } + + if ("Content-Language".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 16384L) != 0)) + { + _bits &= ~16384L; + return true; + } + else + { + return false; + } + } + + if ("Content-Location".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 32768L) != 0)) + { + _bits &= ~32768L; + return true; + } + else + { + return false; + } + } + } + break; + + case 11: + { + if ("Content-MD5".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 65536L) != 0)) + { + _bits &= ~65536L; + return true; + } + else + { + return false; + } + } + } + break; + + case 15: + { + if ("Accept-Encoding".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 4194304L) != 0)) + { + _bits &= ~4194304L; + return true; + } + else + { + return false; + } + } + + if ("Accept-Language".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 8388608L) != 0)) + { + _bits &= ~8388608L; + return true; + } + else + { + return false; + } + } + } + break; + + case 8: + { + if ("If-Match".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 536870912L) != 0)) + { + _bits &= ~536870912L; + return true; + } + else + { + return false; + } + } + + if ("If-Range".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 4294967296L) != 0)) + { + _bits &= ~4294967296L; + return true; + } + else + { + return false; + } + } + } + break; + + case 19: + { + if ("If-Unmodified-Since".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 8589934592L) != 0)) + { + _bits &= ~8589934592L; + return true; + } + else + { + return false; + } + } + + if ("Proxy-Authorization".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 34359738368L) != 0)) + { + _bits &= ~34359738368L; + return true; + } + else + { + return false; + } + } + } + break; + + case 2: + { + if ("TE".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 274877906944L) != 0)) + { + _bits &= ~274877906944L; + return true; + } + else + { + return false; + } + } + } + break; + + case 9: + { + if ("Translate".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 549755813888L) != 0)) + { + _bits &= ~549755813888L; + return true; + } + else + { + return false; + } + } + } + break; + } + return MaybeUnknown?.Remove(key) ?? false; + } + + protected override void ClearFast() + { + _bits = 0; + MaybeUnknown?.Clear(); + } + + protected override void CopyToFast(KeyValuePair[] array, int arrayIndex) + { + if (arrayIndex < 0) + { + throw new ArgumentException(); + } + + + if (((_bits & 1L) != 0)) + { + if (arrayIndex == array.Length) + { + throw new ArgumentException(); + } + + array[arrayIndex] = new KeyValuePair("Cache-Control", _CacheControl); + ++arrayIndex; + } + + if (((_bits & 2L) != 0)) + { + if (arrayIndex == array.Length) + { + throw new ArgumentException(); + } + + array[arrayIndex] = new KeyValuePair("Connection", _Connection); + ++arrayIndex; + } + + if (((_bits & 4L) != 0)) + { + if (arrayIndex == array.Length) + { + throw new ArgumentException(); + } + + array[arrayIndex] = new KeyValuePair("Date", _Date); + ++arrayIndex; + } + + if (((_bits & 8L) != 0)) + { + if (arrayIndex == array.Length) + { + throw new ArgumentException(); + } + + array[arrayIndex] = new KeyValuePair("Keep-Alive", _KeepAlive); + ++arrayIndex; + } + + if (((_bits & 16L) != 0)) + { + if (arrayIndex == array.Length) + { + throw new ArgumentException(); + } + + array[arrayIndex] = new KeyValuePair("Pragma", _Pragma); + ++arrayIndex; + } + + if (((_bits & 32L) != 0)) + { + if (arrayIndex == array.Length) + { + throw new ArgumentException(); + } + + array[arrayIndex] = new KeyValuePair("Trailer", _Trailer); + ++arrayIndex; + } + + if (((_bits & 64L) != 0)) + { + if (arrayIndex == array.Length) + { + throw new ArgumentException(); + } + + array[arrayIndex] = new KeyValuePair("Transfer-Encoding", _TransferEncoding); + ++arrayIndex; + } + + if (((_bits & 128L) != 0)) + { + if (arrayIndex == array.Length) + { + throw new ArgumentException(); + } + + array[arrayIndex] = new KeyValuePair("Upgrade", _Upgrade); + ++arrayIndex; + } + + if (((_bits & 256L) != 0)) + { + if (arrayIndex == array.Length) + { + throw new ArgumentException(); + } + + array[arrayIndex] = new KeyValuePair("Via", _Via); + ++arrayIndex; + } + + if (((_bits & 512L) != 0)) + { + if (arrayIndex == array.Length) + { + throw new ArgumentException(); + } + + array[arrayIndex] = new KeyValuePair("Warning", _Warning); + ++arrayIndex; + } + + if (((_bits & 1024L) != 0)) + { + if (arrayIndex == array.Length) + { + throw new ArgumentException(); + } + + array[arrayIndex] = new KeyValuePair("Allow", _Allow); + ++arrayIndex; + } + + if (((_bits & 2048L) != 0)) + { + if (arrayIndex == array.Length) + { + throw new ArgumentException(); + } + + array[arrayIndex] = new KeyValuePair("Content-Length", _ContentLength); + ++arrayIndex; + } + + if (((_bits & 4096L) != 0)) + { + if (arrayIndex == array.Length) + { + throw new ArgumentException(); + } + + array[arrayIndex] = new KeyValuePair("Content-Type", _ContentType); + ++arrayIndex; + } + + if (((_bits & 8192L) != 0)) + { + if (arrayIndex == array.Length) + { + throw new ArgumentException(); + } + + array[arrayIndex] = new KeyValuePair("Content-Encoding", _ContentEncoding); + ++arrayIndex; + } + + if (((_bits & 16384L) != 0)) + { + if (arrayIndex == array.Length) + { + throw new ArgumentException(); + } + + array[arrayIndex] = new KeyValuePair("Content-Language", _ContentLanguage); + ++arrayIndex; + } + + if (((_bits & 32768L) != 0)) + { + if (arrayIndex == array.Length) + { + throw new ArgumentException(); + } + + array[arrayIndex] = new KeyValuePair("Content-Location", _ContentLocation); + ++arrayIndex; + } + + if (((_bits & 65536L) != 0)) + { + if (arrayIndex == array.Length) + { + throw new ArgumentException(); + } + + array[arrayIndex] = new KeyValuePair("Content-MD5", _ContentMD5); + ++arrayIndex; + } + + if (((_bits & 131072L) != 0)) + { + if (arrayIndex == array.Length) + { + throw new ArgumentException(); + } + + array[arrayIndex] = new KeyValuePair("Content-Range", _ContentRange); + ++arrayIndex; + } + + if (((_bits & 262144L) != 0)) + { + if (arrayIndex == array.Length) + { + throw new ArgumentException(); + } + + array[arrayIndex] = new KeyValuePair("Expires", _Expires); + ++arrayIndex; + } + + if (((_bits & 524288L) != 0)) + { + if (arrayIndex == array.Length) + { + throw new ArgumentException(); + } + + array[arrayIndex] = new KeyValuePair("Last-Modified", _LastModified); + ++arrayIndex; + } + + if (((_bits & 1048576L) != 0)) + { + if (arrayIndex == array.Length) + { + throw new ArgumentException(); + } + + array[arrayIndex] = new KeyValuePair("Accept", _Accept); + ++arrayIndex; + } + + if (((_bits & 2097152L) != 0)) + { + if (arrayIndex == array.Length) + { + throw new ArgumentException(); + } + + array[arrayIndex] = new KeyValuePair("Accept-Charset", _AcceptCharset); + ++arrayIndex; + } + + if (((_bits & 4194304L) != 0)) + { + if (arrayIndex == array.Length) + { + throw new ArgumentException(); + } + + array[arrayIndex] = new KeyValuePair("Accept-Encoding", _AcceptEncoding); + ++arrayIndex; + } + + if (((_bits & 8388608L) != 0)) + { + if (arrayIndex == array.Length) + { + throw new ArgumentException(); + } + + array[arrayIndex] = new KeyValuePair("Accept-Language", _AcceptLanguage); + ++arrayIndex; + } + + if (((_bits & 16777216L) != 0)) + { + if (arrayIndex == array.Length) + { + throw new ArgumentException(); + } + + array[arrayIndex] = new KeyValuePair("Authorization", _Authorization); + ++arrayIndex; + } + + if (((_bits & 33554432L) != 0)) + { + if (arrayIndex == array.Length) + { + throw new ArgumentException(); + } + + array[arrayIndex] = new KeyValuePair("Cookie", _Cookie); + ++arrayIndex; + } + + if (((_bits & 67108864L) != 0)) + { + if (arrayIndex == array.Length) + { + throw new ArgumentException(); + } + + array[arrayIndex] = new KeyValuePair("Expect", _Expect); + ++arrayIndex; + } + + if (((_bits & 134217728L) != 0)) + { + if (arrayIndex == array.Length) + { + throw new ArgumentException(); + } + + array[arrayIndex] = new KeyValuePair("From", _From); + ++arrayIndex; + } + + if (((_bits & 268435456L) != 0)) + { + if (arrayIndex == array.Length) + { + throw new ArgumentException(); + } + + array[arrayIndex] = new KeyValuePair("Host", _Host); + ++arrayIndex; + } + + if (((_bits & 536870912L) != 0)) + { + if (arrayIndex == array.Length) + { + throw new ArgumentException(); + } + + array[arrayIndex] = new KeyValuePair("If-Match", _IfMatch); + ++arrayIndex; + } + + if (((_bits & 1073741824L) != 0)) + { + if (arrayIndex == array.Length) + { + throw new ArgumentException(); + } + + array[arrayIndex] = new KeyValuePair("If-Modified-Since", _IfModifiedSince); + ++arrayIndex; + } + + if (((_bits & 2147483648L) != 0)) + { + if (arrayIndex == array.Length) + { + throw new ArgumentException(); + } + + array[arrayIndex] = new KeyValuePair("If-None-Match", _IfNoneMatch); + ++arrayIndex; + } + + if (((_bits & 4294967296L) != 0)) + { + if (arrayIndex == array.Length) + { + throw new ArgumentException(); + } + + array[arrayIndex] = new KeyValuePair("If-Range", _IfRange); + ++arrayIndex; + } + + if (((_bits & 8589934592L) != 0)) + { + if (arrayIndex == array.Length) + { + throw new ArgumentException(); + } + + array[arrayIndex] = new KeyValuePair("If-Unmodified-Since", _IfUnmodifiedSince); + ++arrayIndex; + } + + if (((_bits & 17179869184L) != 0)) + { + if (arrayIndex == array.Length) + { + throw new ArgumentException(); + } + + array[arrayIndex] = new KeyValuePair("Max-Forwards", _MaxForwards); + ++arrayIndex; + } + + if (((_bits & 34359738368L) != 0)) + { + if (arrayIndex == array.Length) + { + throw new ArgumentException(); + } + + array[arrayIndex] = new KeyValuePair("Proxy-Authorization", _ProxyAuthorization); + ++arrayIndex; + } + + if (((_bits & 68719476736L) != 0)) + { + if (arrayIndex == array.Length) + { + throw new ArgumentException(); + } + + array[arrayIndex] = new KeyValuePair("Referer", _Referer); + ++arrayIndex; + } + + if (((_bits & 137438953472L) != 0)) + { + if (arrayIndex == array.Length) + { + throw new ArgumentException(); + } + + array[arrayIndex] = new KeyValuePair("Range", _Range); + ++arrayIndex; + } + + if (((_bits & 274877906944L) != 0)) + { + if (arrayIndex == array.Length) + { + throw new ArgumentException(); + } + + array[arrayIndex] = new KeyValuePair("TE", _TE); + ++arrayIndex; + } + + if (((_bits & 549755813888L) != 0)) + { + if (arrayIndex == array.Length) + { + throw new ArgumentException(); + } + + array[arrayIndex] = new KeyValuePair("Translate", _Translate); + ++arrayIndex; + } + + if (((_bits & 1099511627776L) != 0)) + { + if (arrayIndex == array.Length) + { + throw new ArgumentException(); + } + + array[arrayIndex] = new KeyValuePair("User-Agent", _UserAgent); + ++arrayIndex; + } + + ((ICollection>)MaybeUnknown)?.CopyTo(array, arrayIndex); + } + + public partial struct Enumerator + { + public bool MoveNext() + { + switch (_state) + { + + case 0: + goto state0; + + case 1: + goto state1; + + case 2: + goto state2; + + case 3: + goto state3; + + case 4: + goto state4; + + case 5: + goto state5; + + case 6: + goto state6; + + case 7: + goto state7; + + case 8: + goto state8; + + case 9: + goto state9; + + case 10: + goto state10; + + case 11: + goto state11; + + case 12: + goto state12; + + case 13: + goto state13; + + case 14: + goto state14; + + case 15: + goto state15; + + case 16: + goto state16; + + case 17: + goto state17; + + case 18: + goto state18; + + case 19: + goto state19; + + case 20: + goto state20; + + case 21: + goto state21; + + case 22: + goto state22; + + case 23: + goto state23; + + case 24: + goto state24; + + case 25: + goto state25; + + case 26: + goto state26; + + case 27: + goto state27; + + case 28: + goto state28; + + case 29: + goto state29; + + case 30: + goto state30; + + case 31: + goto state31; + + case 32: + goto state32; + + case 33: + goto state33; + + case 34: + goto state34; + + case 35: + goto state35; + + case 36: + goto state36; + + case 37: + goto state37; + + case 38: + goto state38; + + case 39: + goto state39; + + case 40: + goto state40; + + default: + goto state_default; + } + + state0: + if (((_bits & 1L) != 0)) + { + _current = new KeyValuePair("Cache-Control", _collection._CacheControl); + _state = 1; + return true; + } + + state1: + if (((_bits & 2L) != 0)) + { + _current = new KeyValuePair("Connection", _collection._Connection); + _state = 2; + return true; + } + + state2: + if (((_bits & 4L) != 0)) + { + _current = new KeyValuePair("Date", _collection._Date); + _state = 3; + return true; + } + + state3: + if (((_bits & 8L) != 0)) + { + _current = new KeyValuePair("Keep-Alive", _collection._KeepAlive); + _state = 4; + return true; + } + + state4: + if (((_bits & 16L) != 0)) + { + _current = new KeyValuePair("Pragma", _collection._Pragma); + _state = 5; + return true; + } + + state5: + if (((_bits & 32L) != 0)) + { + _current = new KeyValuePair("Trailer", _collection._Trailer); + _state = 6; + return true; + } + + state6: + if (((_bits & 64L) != 0)) + { + _current = new KeyValuePair("Transfer-Encoding", _collection._TransferEncoding); + _state = 7; + return true; + } + + state7: + if (((_bits & 128L) != 0)) + { + _current = new KeyValuePair("Upgrade", _collection._Upgrade); + _state = 8; + return true; + } + + state8: + if (((_bits & 256L) != 0)) + { + _current = new KeyValuePair("Via", _collection._Via); + _state = 9; + return true; + } + + state9: + if (((_bits & 512L) != 0)) + { + _current = new KeyValuePair("Warning", _collection._Warning); + _state = 10; + return true; + } + + state10: + if (((_bits & 1024L) != 0)) + { + _current = new KeyValuePair("Allow", _collection._Allow); + _state = 11; + return true; + } + + state11: + if (((_bits & 2048L) != 0)) + { + _current = new KeyValuePair("Content-Length", _collection._ContentLength); + _state = 12; + return true; + } + + state12: + if (((_bits & 4096L) != 0)) + { + _current = new KeyValuePair("Content-Type", _collection._ContentType); + _state = 13; + return true; + } + + state13: + if (((_bits & 8192L) != 0)) + { + _current = new KeyValuePair("Content-Encoding", _collection._ContentEncoding); + _state = 14; + return true; + } + + state14: + if (((_bits & 16384L) != 0)) + { + _current = new KeyValuePair("Content-Language", _collection._ContentLanguage); + _state = 15; + return true; + } + + state15: + if (((_bits & 32768L) != 0)) + { + _current = new KeyValuePair("Content-Location", _collection._ContentLocation); + _state = 16; + return true; + } + + state16: + if (((_bits & 65536L) != 0)) + { + _current = new KeyValuePair("Content-MD5", _collection._ContentMD5); + _state = 17; + return true; + } + + state17: + if (((_bits & 131072L) != 0)) + { + _current = new KeyValuePair("Content-Range", _collection._ContentRange); + _state = 18; + return true; + } + + state18: + if (((_bits & 262144L) != 0)) + { + _current = new KeyValuePair("Expires", _collection._Expires); + _state = 19; + return true; + } + + state19: + if (((_bits & 524288L) != 0)) + { + _current = new KeyValuePair("Last-Modified", _collection._LastModified); + _state = 20; + return true; + } + + state20: + if (((_bits & 1048576L) != 0)) + { + _current = new KeyValuePair("Accept", _collection._Accept); + _state = 21; + return true; + } + + state21: + if (((_bits & 2097152L) != 0)) + { + _current = new KeyValuePair("Accept-Charset", _collection._AcceptCharset); + _state = 22; + return true; + } + + state22: + if (((_bits & 4194304L) != 0)) + { + _current = new KeyValuePair("Accept-Encoding", _collection._AcceptEncoding); + _state = 23; + return true; + } + + state23: + if (((_bits & 8388608L) != 0)) + { + _current = new KeyValuePair("Accept-Language", _collection._AcceptLanguage); + _state = 24; + return true; + } + + state24: + if (((_bits & 16777216L) != 0)) + { + _current = new KeyValuePair("Authorization", _collection._Authorization); + _state = 25; + return true; + } + + state25: + if (((_bits & 33554432L) != 0)) + { + _current = new KeyValuePair("Cookie", _collection._Cookie); + _state = 26; + return true; + } + + state26: + if (((_bits & 67108864L) != 0)) + { + _current = new KeyValuePair("Expect", _collection._Expect); + _state = 27; + return true; + } + + state27: + if (((_bits & 134217728L) != 0)) + { + _current = new KeyValuePair("From", _collection._From); + _state = 28; + return true; + } + + state28: + if (((_bits & 268435456L) != 0)) + { + _current = new KeyValuePair("Host", _collection._Host); + _state = 29; + return true; + } + + state29: + if (((_bits & 536870912L) != 0)) + { + _current = new KeyValuePair("If-Match", _collection._IfMatch); + _state = 30; + return true; + } + + state30: + if (((_bits & 1073741824L) != 0)) + { + _current = new KeyValuePair("If-Modified-Since", _collection._IfModifiedSince); + _state = 31; + return true; + } + + state31: + if (((_bits & 2147483648L) != 0)) + { + _current = new KeyValuePair("If-None-Match", _collection._IfNoneMatch); + _state = 32; + return true; + } + + state32: + if (((_bits & 4294967296L) != 0)) + { + _current = new KeyValuePair("If-Range", _collection._IfRange); + _state = 33; + return true; + } + + state33: + if (((_bits & 8589934592L) != 0)) + { + _current = new KeyValuePair("If-Unmodified-Since", _collection._IfUnmodifiedSince); + _state = 34; + return true; + } + + state34: + if (((_bits & 17179869184L) != 0)) + { + _current = new KeyValuePair("Max-Forwards", _collection._MaxForwards); + _state = 35; + return true; + } + + state35: + if (((_bits & 34359738368L) != 0)) + { + _current = new KeyValuePair("Proxy-Authorization", _collection._ProxyAuthorization); + _state = 36; + return true; + } + + state36: + if (((_bits & 68719476736L) != 0)) + { + _current = new KeyValuePair("Referer", _collection._Referer); + _state = 37; + return true; + } + + state37: + if (((_bits & 137438953472L) != 0)) + { + _current = new KeyValuePair("Range", _collection._Range); + _state = 38; + return true; + } + + state38: + if (((_bits & 274877906944L) != 0)) + { + _current = new KeyValuePair("TE", _collection._TE); + _state = 39; + return true; + } + + state39: + if (((_bits & 549755813888L) != 0)) + { + _current = new KeyValuePair("Translate", _collection._Translate); + _state = 40; + return true; + } + + state40: + if (((_bits & 1099511627776L) != 0)) + { + _current = new KeyValuePair("User-Agent", _collection._UserAgent); + _state = 41; + return true; + } + + state_default: + if (!_hasUnknown || !_unknownEnumerator.MoveNext()) + { + _current = default(KeyValuePair); + return false; + } + _current = _unknownEnumerator.Current; + return true; + } + } + } + + public partial class FrameResponseHeaders + { + long _bits = 0; + + string[] _CacheControl; + string[] _Connection; + string[] _Date; + string[] _KeepAlive; + string[] _Pragma; + string[] _Trailer; + string[] _TransferEncoding; + string[] _Upgrade; + string[] _Via; + string[] _Warning; + string[] _Allow; + string[] _ContentLength; + string[] _ContentType; + string[] _ContentEncoding; + string[] _ContentLanguage; + string[] _ContentLocation; + string[] _ContentMD5; + string[] _ContentRange; + string[] _Expires; + string[] _LastModified; + string[] _AcceptRanges; + string[] _Age; + string[] _ETag; + string[] _Location; + string[] _ProxyAutheticate; + string[] _RetryAfter; + string[] _Server; + string[] _SetCookie; + string[] _Vary; + string[] _WWWAuthenticate; + + protected override int GetCountFast() + { + var count = MaybeUnknown?.Count ?? 0; + + if (((_bits & 1L) != 0)) + { + ++count; + } + + if (((_bits & 2L) != 0)) + { + ++count; + } + + if (((_bits & 4L) != 0)) + { + ++count; + } + + if (((_bits & 8L) != 0)) + { + ++count; + } + + if (((_bits & 16L) != 0)) + { + ++count; + } + + if (((_bits & 32L) != 0)) + { + ++count; + } + + if (((_bits & 64L) != 0)) + { + ++count; + } + + if (((_bits & 128L) != 0)) + { + ++count; + } + + if (((_bits & 256L) != 0)) + { + ++count; + } + + if (((_bits & 512L) != 0)) + { + ++count; + } + + if (((_bits & 1024L) != 0)) + { + ++count; + } + + if (((_bits & 2048L) != 0)) + { + ++count; + } + + if (((_bits & 4096L) != 0)) + { + ++count; + } + + if (((_bits & 8192L) != 0)) + { + ++count; + } + + if (((_bits & 16384L) != 0)) + { + ++count; + } + + if (((_bits & 32768L) != 0)) + { + ++count; + } + + if (((_bits & 65536L) != 0)) + { + ++count; + } + + if (((_bits & 131072L) != 0)) + { + ++count; + } + + if (((_bits & 262144L) != 0)) + { + ++count; + } + + if (((_bits & 524288L) != 0)) + { + ++count; + } + + if (((_bits & 1048576L) != 0)) + { + ++count; + } + + if (((_bits & 2097152L) != 0)) + { + ++count; + } + + if (((_bits & 4194304L) != 0)) + { + ++count; + } + + if (((_bits & 8388608L) != 0)) + { + ++count; + } + + if (((_bits & 16777216L) != 0)) + { + ++count; + } + + if (((_bits & 33554432L) != 0)) + { + ++count; + } + + if (((_bits & 67108864L) != 0)) + { + ++count; + } + + if (((_bits & 134217728L) != 0)) + { + ++count; + } + + if (((_bits & 268435456L) != 0)) + { + ++count; + } + + if (((_bits & 536870912L) != 0)) + { + ++count; + } + + return count; + } + + protected override string[] GetValueFast(string key) + { + switch(key.Length) + { + case 13: + { + if ("Cache-Control".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 1L) != 0)) + { + return _CacheControl; + } + else + { + throw new System.Collections.Generic.KeyNotFoundException(); + } + } + + if ("Content-Range".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 131072L) != 0)) + { + return _ContentRange; + } + else + { + throw new System.Collections.Generic.KeyNotFoundException(); + } + } + + if ("Last-Modified".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 524288L) != 0)) + { + return _LastModified; + } + else + { + throw new System.Collections.Generic.KeyNotFoundException(); + } + } + + if ("Accept-Ranges".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 1048576L) != 0)) + { + return _AcceptRanges; + } + else + { + throw new System.Collections.Generic.KeyNotFoundException(); + } + } + } + break; + + case 10: + { + if ("Connection".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 2L) != 0)) + { + return _Connection; + } + else + { + throw new System.Collections.Generic.KeyNotFoundException(); + } + } + + if ("Keep-Alive".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 8L) != 0)) + { + return _KeepAlive; + } + else + { + throw new System.Collections.Generic.KeyNotFoundException(); + } + } + + if ("Set-Cookie".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 134217728L) != 0)) + { + return _SetCookie; + } + else + { + throw new System.Collections.Generic.KeyNotFoundException(); + } + } + } + break; + + case 4: + { + if ("Date".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 4L) != 0)) + { + return _Date; + } + else + { + throw new System.Collections.Generic.KeyNotFoundException(); + } + } + + if ("ETag".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 4194304L) != 0)) + { + return _ETag; + } + else + { + throw new System.Collections.Generic.KeyNotFoundException(); + } + } + + if ("Vary".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 268435456L) != 0)) + { + return _Vary; + } + else + { + throw new System.Collections.Generic.KeyNotFoundException(); + } + } + } + break; + + case 6: + { + if ("Pragma".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 16L) != 0)) + { + return _Pragma; + } + else + { + throw new System.Collections.Generic.KeyNotFoundException(); + } + } + + if ("Server".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 67108864L) != 0)) + { + return _Server; + } + else + { + throw new System.Collections.Generic.KeyNotFoundException(); + } + } + } + break; + + case 7: + { + if ("Trailer".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 32L) != 0)) + { + return _Trailer; + } + else + { + throw new System.Collections.Generic.KeyNotFoundException(); + } + } + + if ("Upgrade".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 128L) != 0)) + { + return _Upgrade; + } + else + { + throw new System.Collections.Generic.KeyNotFoundException(); + } + } + + if ("Warning".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 512L) != 0)) + { + return _Warning; + } + else + { + throw new System.Collections.Generic.KeyNotFoundException(); + } + } + + if ("Expires".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 262144L) != 0)) + { + return _Expires; + } + else + { + throw new System.Collections.Generic.KeyNotFoundException(); + } + } + } + break; + + case 17: + { + if ("Transfer-Encoding".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 64L) != 0)) + { + return _TransferEncoding; + } + else + { + throw new System.Collections.Generic.KeyNotFoundException(); + } + } + + if ("Proxy-Autheticate".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 16777216L) != 0)) + { + return _ProxyAutheticate; + } + else + { + throw new System.Collections.Generic.KeyNotFoundException(); + } + } + } + break; + + case 3: + { + if ("Via".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 256L) != 0)) + { + return _Via; + } + else + { + throw new System.Collections.Generic.KeyNotFoundException(); + } + } + + if ("Age".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 2097152L) != 0)) + { + return _Age; + } + else + { + throw new System.Collections.Generic.KeyNotFoundException(); + } + } + } + break; + + case 5: + { + if ("Allow".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 1024L) != 0)) + { + return _Allow; + } + else + { + throw new System.Collections.Generic.KeyNotFoundException(); + } + } + } + break; + + case 14: + { + if ("Content-Length".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 2048L) != 0)) + { + return _ContentLength; + } + else + { + throw new System.Collections.Generic.KeyNotFoundException(); + } + } + } + break; + + case 12: + { + if ("Content-Type".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 4096L) != 0)) + { + return _ContentType; + } + else + { + throw new System.Collections.Generic.KeyNotFoundException(); + } + } + } + break; + + case 16: + { + if ("Content-Encoding".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 8192L) != 0)) + { + return _ContentEncoding; + } + else + { + throw new System.Collections.Generic.KeyNotFoundException(); + } + } + + if ("Content-Language".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 16384L) != 0)) + { + return _ContentLanguage; + } + else + { + throw new System.Collections.Generic.KeyNotFoundException(); + } + } + + if ("Content-Location".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 32768L) != 0)) + { + return _ContentLocation; + } + else + { + throw new System.Collections.Generic.KeyNotFoundException(); + } + } + + if ("WWW-Authenticate".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 536870912L) != 0)) + { + return _WWWAuthenticate; + } + else + { + throw new System.Collections.Generic.KeyNotFoundException(); + } + } + } + break; + + case 11: + { + if ("Content-MD5".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 65536L) != 0)) + { + return _ContentMD5; + } + else + { + throw new System.Collections.Generic.KeyNotFoundException(); + } + } + + if ("Retry-After".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 33554432L) != 0)) + { + return _RetryAfter; + } + else + { + throw new System.Collections.Generic.KeyNotFoundException(); + } + } + } + break; + + case 8: + { + if ("Location".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 8388608L) != 0)) + { + return _Location; + } + else + { + throw new System.Collections.Generic.KeyNotFoundException(); + } + } + } + break; + } + if (MaybeUnknown == null) + { + throw new System.Collections.Generic.KeyNotFoundException(); + } + return MaybeUnknown[key]; + } + + protected override bool TryGetValueFast(string key, out string[] value) + { + switch(key.Length) + { + case 13: + { + if ("Cache-Control".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 1L) != 0)) + { + value = _CacheControl; + return true; + } + else + { + value = null; + return false; + } + } + + if ("Content-Range".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 131072L) != 0)) + { + value = _ContentRange; + return true; + } + else + { + value = null; + return false; + } + } + + if ("Last-Modified".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 524288L) != 0)) + { + value = _LastModified; + return true; + } + else + { + value = null; + return false; + } + } + + if ("Accept-Ranges".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 1048576L) != 0)) + { + value = _AcceptRanges; + return true; + } + else + { + value = null; + return false; + } + } + } + break; + + case 10: + { + if ("Connection".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 2L) != 0)) + { + value = _Connection; + return true; + } + else + { + value = null; + return false; + } + } + + if ("Keep-Alive".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 8L) != 0)) + { + value = _KeepAlive; + return true; + } + else + { + value = null; + return false; + } + } + + if ("Set-Cookie".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 134217728L) != 0)) + { + value = _SetCookie; + return true; + } + else + { + value = null; + return false; + } + } + } + break; + + case 4: + { + if ("Date".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 4L) != 0)) + { + value = _Date; + return true; + } + else + { + value = null; + return false; + } + } + + if ("ETag".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 4194304L) != 0)) + { + value = _ETag; + return true; + } + else + { + value = null; + return false; + } + } + + if ("Vary".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 268435456L) != 0)) + { + value = _Vary; + return true; + } + else + { + value = null; + return false; + } + } + } + break; + + case 6: + { + if ("Pragma".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 16L) != 0)) + { + value = _Pragma; + return true; + } + else + { + value = null; + return false; + } + } + + if ("Server".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 67108864L) != 0)) + { + value = _Server; + return true; + } + else + { + value = null; + return false; + } + } + } + break; + + case 7: + { + if ("Trailer".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 32L) != 0)) + { + value = _Trailer; + return true; + } + else + { + value = null; + return false; + } + } + + if ("Upgrade".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 128L) != 0)) + { + value = _Upgrade; + return true; + } + else + { + value = null; + return false; + } + } + + if ("Warning".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 512L) != 0)) + { + value = _Warning; + return true; + } + else + { + value = null; + return false; + } + } + + if ("Expires".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 262144L) != 0)) + { + value = _Expires; + return true; + } + else + { + value = null; + return false; + } + } + } + break; + + case 17: + { + if ("Transfer-Encoding".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 64L) != 0)) + { + value = _TransferEncoding; + return true; + } + else + { + value = null; + return false; + } + } + + if ("Proxy-Autheticate".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 16777216L) != 0)) + { + value = _ProxyAutheticate; + return true; + } + else + { + value = null; + return false; + } + } + } + break; + + case 3: + { + if ("Via".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 256L) != 0)) + { + value = _Via; + return true; + } + else + { + value = null; + return false; + } + } + + if ("Age".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 2097152L) != 0)) + { + value = _Age; + return true; + } + else + { + value = null; + return false; + } + } + } + break; + + case 5: + { + if ("Allow".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 1024L) != 0)) + { + value = _Allow; + return true; + } + else + { + value = null; + return false; + } + } + } + break; + + case 14: + { + if ("Content-Length".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 2048L) != 0)) + { + value = _ContentLength; + return true; + } + else + { + value = null; + return false; + } + } + } + break; + + case 12: + { + if ("Content-Type".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 4096L) != 0)) + { + value = _ContentType; + return true; + } + else + { + value = null; + return false; + } + } + } + break; + + case 16: + { + if ("Content-Encoding".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 8192L) != 0)) + { + value = _ContentEncoding; + return true; + } + else + { + value = null; + return false; + } + } + + if ("Content-Language".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 16384L) != 0)) + { + value = _ContentLanguage; + return true; + } + else + { + value = null; + return false; + } + } + + if ("Content-Location".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 32768L) != 0)) + { + value = _ContentLocation; + return true; + } + else + { + value = null; + return false; + } + } + + if ("WWW-Authenticate".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 536870912L) != 0)) + { + value = _WWWAuthenticate; + return true; + } + else + { + value = null; + return false; + } + } + } + break; + + case 11: + { + if ("Content-MD5".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 65536L) != 0)) + { + value = _ContentMD5; + return true; + } + else + { + value = null; + return false; + } + } + + if ("Retry-After".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 33554432L) != 0)) + { + value = _RetryAfter; + return true; + } + else + { + value = null; + return false; + } + } + } + break; + + case 8: + { + if ("Location".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 8388608L) != 0)) + { + value = _Location; + return true; + } + else + { + value = null; + return false; + } + } + } + break; + } + value = null; + return MaybeUnknown?.TryGetValue(key, out value) ?? false; + } + + protected override void SetValueFast(string key, string[] value) + { + switch(key.Length) + { + case 13: + { + if ("Cache-Control".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + _bits |= 1L; + _CacheControl = value; + return; + } + + if ("Content-Range".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + _bits |= 131072L; + _ContentRange = value; + return; + } + + if ("Last-Modified".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + _bits |= 524288L; + _LastModified = value; + return; + } + + if ("Accept-Ranges".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + _bits |= 1048576L; + _AcceptRanges = value; + return; + } + } + break; + + case 10: + { + if ("Connection".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + _bits |= 2L; + _Connection = value; + return; + } + + if ("Keep-Alive".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + _bits |= 8L; + _KeepAlive = value; + return; + } + + if ("Set-Cookie".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + _bits |= 134217728L; + _SetCookie = value; + return; + } + } + break; + + case 4: + { + if ("Date".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + _bits |= 4L; + _Date = value; + return; + } + + if ("ETag".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + _bits |= 4194304L; + _ETag = value; + return; + } + + if ("Vary".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + _bits |= 268435456L; + _Vary = value; + return; + } + } + break; + + case 6: + { + if ("Pragma".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + _bits |= 16L; + _Pragma = value; + return; + } + + if ("Server".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + _bits |= 67108864L; + _Server = value; + return; + } + } + break; + + case 7: + { + if ("Trailer".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + _bits |= 32L; + _Trailer = value; + return; + } + + if ("Upgrade".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + _bits |= 128L; + _Upgrade = value; + return; + } + + if ("Warning".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + _bits |= 512L; + _Warning = value; + return; + } + + if ("Expires".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + _bits |= 262144L; + _Expires = value; + return; + } + } + break; + + case 17: + { + if ("Transfer-Encoding".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + _bits |= 64L; + _TransferEncoding = value; + return; + } + + if ("Proxy-Autheticate".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + _bits |= 16777216L; + _ProxyAutheticate = value; + return; + } + } + break; + + case 3: + { + if ("Via".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + _bits |= 256L; + _Via = value; + return; + } + + if ("Age".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + _bits |= 2097152L; + _Age = value; + return; + } + } + break; + + case 5: + { + if ("Allow".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + _bits |= 1024L; + _Allow = value; + return; + } + } + break; + + case 14: + { + if ("Content-Length".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + _bits |= 2048L; + _ContentLength = value; + return; + } + } + break; + + case 12: + { + if ("Content-Type".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + _bits |= 4096L; + _ContentType = value; + return; + } + } + break; + + case 16: + { + if ("Content-Encoding".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + _bits |= 8192L; + _ContentEncoding = value; + return; + } + + if ("Content-Language".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + _bits |= 16384L; + _ContentLanguage = value; + return; + } + + if ("Content-Location".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + _bits |= 32768L; + _ContentLocation = value; + return; + } + + if ("WWW-Authenticate".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + _bits |= 536870912L; + _WWWAuthenticate = value; + return; + } + } + break; + + case 11: + { + if ("Content-MD5".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + _bits |= 65536L; + _ContentMD5 = value; + return; + } + + if ("Retry-After".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + _bits |= 33554432L; + _RetryAfter = value; + return; + } + } + break; + + case 8: + { + if ("Location".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + _bits |= 8388608L; + _Location = value; + return; + } + } + break; + } + Unknown[key] = value; + } + + protected override void AddValueFast(string key, string[] value) + { + switch(key.Length) + { + case 13: + { + if ("Cache-Control".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 1L) != 0)) + { + throw new ArgumentException("An item with the same key has already been added."); + } + _bits |= 1L; + _CacheControl = value; + return; + } + + if ("Content-Range".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 131072L) != 0)) + { + throw new ArgumentException("An item with the same key has already been added."); + } + _bits |= 131072L; + _ContentRange = value; + return; + } + + if ("Last-Modified".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 524288L) != 0)) + { + throw new ArgumentException("An item with the same key has already been added."); + } + _bits |= 524288L; + _LastModified = value; + return; + } + + if ("Accept-Ranges".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 1048576L) != 0)) + { + throw new ArgumentException("An item with the same key has already been added."); + } + _bits |= 1048576L; + _AcceptRanges = value; + return; + } + } + break; + + case 10: + { + if ("Connection".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 2L) != 0)) + { + throw new ArgumentException("An item with the same key has already been added."); + } + _bits |= 2L; + _Connection = value; + return; + } + + if ("Keep-Alive".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 8L) != 0)) + { + throw new ArgumentException("An item with the same key has already been added."); + } + _bits |= 8L; + _KeepAlive = value; + return; + } + + if ("Set-Cookie".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 134217728L) != 0)) + { + throw new ArgumentException("An item with the same key has already been added."); + } + _bits |= 134217728L; + _SetCookie = value; + return; + } + } + break; + + case 4: + { + if ("Date".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 4L) != 0)) + { + throw new ArgumentException("An item with the same key has already been added."); + } + _bits |= 4L; + _Date = value; + return; + } + + if ("ETag".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 4194304L) != 0)) + { + throw new ArgumentException("An item with the same key has already been added."); + } + _bits |= 4194304L; + _ETag = value; + return; + } + + if ("Vary".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 268435456L) != 0)) + { + throw new ArgumentException("An item with the same key has already been added."); + } + _bits |= 268435456L; + _Vary = value; + return; + } + } + break; + + case 6: + { + if ("Pragma".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 16L) != 0)) + { + throw new ArgumentException("An item with the same key has already been added."); + } + _bits |= 16L; + _Pragma = value; + return; + } + + if ("Server".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 67108864L) != 0)) + { + throw new ArgumentException("An item with the same key has already been added."); + } + _bits |= 67108864L; + _Server = value; + return; + } + } + break; + + case 7: + { + if ("Trailer".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 32L) != 0)) + { + throw new ArgumentException("An item with the same key has already been added."); + } + _bits |= 32L; + _Trailer = value; + return; + } + + if ("Upgrade".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 128L) != 0)) + { + throw new ArgumentException("An item with the same key has already been added."); + } + _bits |= 128L; + _Upgrade = value; + return; + } + + if ("Warning".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 512L) != 0)) + { + throw new ArgumentException("An item with the same key has already been added."); + } + _bits |= 512L; + _Warning = value; + return; + } + + if ("Expires".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 262144L) != 0)) + { + throw new ArgumentException("An item with the same key has already been added."); + } + _bits |= 262144L; + _Expires = value; + return; + } + } + break; + + case 17: + { + if ("Transfer-Encoding".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 64L) != 0)) + { + throw new ArgumentException("An item with the same key has already been added."); + } + _bits |= 64L; + _TransferEncoding = value; + return; + } + + if ("Proxy-Autheticate".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 16777216L) != 0)) + { + throw new ArgumentException("An item with the same key has already been added."); + } + _bits |= 16777216L; + _ProxyAutheticate = value; + return; + } + } + break; + + case 3: + { + if ("Via".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 256L) != 0)) + { + throw new ArgumentException("An item with the same key has already been added."); + } + _bits |= 256L; + _Via = value; + return; + } + + if ("Age".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 2097152L) != 0)) + { + throw new ArgumentException("An item with the same key has already been added."); + } + _bits |= 2097152L; + _Age = value; + return; + } + } + break; + + case 5: + { + if ("Allow".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 1024L) != 0)) + { + throw new ArgumentException("An item with the same key has already been added."); + } + _bits |= 1024L; + _Allow = value; + return; + } + } + break; + + case 14: + { + if ("Content-Length".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 2048L) != 0)) + { + throw new ArgumentException("An item with the same key has already been added."); + } + _bits |= 2048L; + _ContentLength = value; + return; + } + } + break; + + case 12: + { + if ("Content-Type".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 4096L) != 0)) + { + throw new ArgumentException("An item with the same key has already been added."); + } + _bits |= 4096L; + _ContentType = value; + return; + } + } + break; + + case 16: + { + if ("Content-Encoding".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 8192L) != 0)) + { + throw new ArgumentException("An item with the same key has already been added."); + } + _bits |= 8192L; + _ContentEncoding = value; + return; + } + + if ("Content-Language".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 16384L) != 0)) + { + throw new ArgumentException("An item with the same key has already been added."); + } + _bits |= 16384L; + _ContentLanguage = value; + return; + } + + if ("Content-Location".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 32768L) != 0)) + { + throw new ArgumentException("An item with the same key has already been added."); + } + _bits |= 32768L; + _ContentLocation = value; + return; + } + + if ("WWW-Authenticate".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 536870912L) != 0)) + { + throw new ArgumentException("An item with the same key has already been added."); + } + _bits |= 536870912L; + _WWWAuthenticate = value; + return; + } + } + break; + + case 11: + { + if ("Content-MD5".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 65536L) != 0)) + { + throw new ArgumentException("An item with the same key has already been added."); + } + _bits |= 65536L; + _ContentMD5 = value; + return; + } + + if ("Retry-After".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 33554432L) != 0)) + { + throw new ArgumentException("An item with the same key has already been added."); + } + _bits |= 33554432L; + _RetryAfter = value; + return; + } + } + break; + + case 8: + { + if ("Location".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 8388608L) != 0)) + { + throw new ArgumentException("An item with the same key has already been added."); + } + _bits |= 8388608L; + _Location = value; + return; + } + } + break; + } + Unknown.Add(key, value); + } + + protected override bool RemoveFast(string key) + { + switch(key.Length) + { + case 13: + { + if ("Cache-Control".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 1L) != 0)) + { + _bits &= ~1L; + return true; + } + else + { + return false; + } + } + + if ("Content-Range".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 131072L) != 0)) + { + _bits &= ~131072L; + return true; + } + else + { + return false; + } + } + + if ("Last-Modified".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 524288L) != 0)) + { + _bits &= ~524288L; + return true; + } + else + { + return false; + } + } + + if ("Accept-Ranges".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 1048576L) != 0)) + { + _bits &= ~1048576L; + return true; + } + else + { + return false; + } + } + } + break; + + case 10: + { + if ("Connection".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 2L) != 0)) + { + _bits &= ~2L; + return true; + } + else + { + return false; + } + } + + if ("Keep-Alive".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 8L) != 0)) + { + _bits &= ~8L; + return true; + } + else + { + return false; + } + } + + if ("Set-Cookie".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 134217728L) != 0)) + { + _bits &= ~134217728L; + return true; + } + else + { + return false; + } + } + } + break; + + case 4: + { + if ("Date".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 4L) != 0)) + { + _bits &= ~4L; + return true; + } + else + { + return false; + } + } + + if ("ETag".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 4194304L) != 0)) + { + _bits &= ~4194304L; + return true; + } + else + { + return false; + } + } + + if ("Vary".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 268435456L) != 0)) + { + _bits &= ~268435456L; + return true; + } + else + { + return false; + } + } + } + break; + + case 6: + { + if ("Pragma".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 16L) != 0)) + { + _bits &= ~16L; + return true; + } + else + { + return false; + } + } + + if ("Server".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 67108864L) != 0)) + { + _bits &= ~67108864L; + return true; + } + else + { + return false; + } + } + } + break; + + case 7: + { + if ("Trailer".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 32L) != 0)) + { + _bits &= ~32L; + return true; + } + else + { + return false; + } + } + + if ("Upgrade".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 128L) != 0)) + { + _bits &= ~128L; + return true; + } + else + { + return false; + } + } + + if ("Warning".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 512L) != 0)) + { + _bits &= ~512L; + return true; + } + else + { + return false; + } + } + + if ("Expires".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 262144L) != 0)) + { + _bits &= ~262144L; + return true; + } + else + { + return false; + } + } + } + break; + + case 17: + { + if ("Transfer-Encoding".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 64L) != 0)) + { + _bits &= ~64L; + return true; + } + else + { + return false; + } + } + + if ("Proxy-Autheticate".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 16777216L) != 0)) + { + _bits &= ~16777216L; + return true; + } + else + { + return false; + } + } + } + break; + + case 3: + { + if ("Via".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 256L) != 0)) + { + _bits &= ~256L; + return true; + } + else + { + return false; + } + } + + if ("Age".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 2097152L) != 0)) + { + _bits &= ~2097152L; + return true; + } + else + { + return false; + } + } + } + break; + + case 5: + { + if ("Allow".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 1024L) != 0)) + { + _bits &= ~1024L; + return true; + } + else + { + return false; + } + } + } + break; + + case 14: + { + if ("Content-Length".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 2048L) != 0)) + { + _bits &= ~2048L; + return true; + } + else + { + return false; + } + } + } + break; + + case 12: + { + if ("Content-Type".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 4096L) != 0)) + { + _bits &= ~4096L; + return true; + } + else + { + return false; + } + } + } + break; + + case 16: + { + if ("Content-Encoding".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 8192L) != 0)) + { + _bits &= ~8192L; + return true; + } + else + { + return false; + } + } + + if ("Content-Language".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 16384L) != 0)) + { + _bits &= ~16384L; + return true; + } + else + { + return false; + } + } + + if ("Content-Location".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 32768L) != 0)) + { + _bits &= ~32768L; + return true; + } + else + { + return false; + } + } + + if ("WWW-Authenticate".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 536870912L) != 0)) + { + _bits &= ~536870912L; + return true; + } + else + { + return false; + } + } + } + break; + + case 11: + { + if ("Content-MD5".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 65536L) != 0)) + { + _bits &= ~65536L; + return true; + } + else + { + return false; + } + } + + if ("Retry-After".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 33554432L) != 0)) + { + _bits &= ~33554432L; + return true; + } + else + { + return false; + } + } + } + break; + + case 8: + { + if ("Location".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 8388608L) != 0)) + { + _bits &= ~8388608L; + return true; + } + else + { + return false; + } + } + } + break; + } + return MaybeUnknown?.Remove(key) ?? false; + } + + protected override void ClearFast() + { + _bits = 0; + MaybeUnknown?.Clear(); + } + + protected override void CopyToFast(KeyValuePair[] array, int arrayIndex) + { + if (arrayIndex < 0) + { + throw new ArgumentException(); + } + + + if (((_bits & 1L) != 0)) + { + if (arrayIndex == array.Length) + { + throw new ArgumentException(); + } + + array[arrayIndex] = new KeyValuePair("Cache-Control", _CacheControl); + ++arrayIndex; + } + + if (((_bits & 2L) != 0)) + { + if (arrayIndex == array.Length) + { + throw new ArgumentException(); + } + + array[arrayIndex] = new KeyValuePair("Connection", _Connection); + ++arrayIndex; + } + + if (((_bits & 4L) != 0)) + { + if (arrayIndex == array.Length) + { + throw new ArgumentException(); + } + + array[arrayIndex] = new KeyValuePair("Date", _Date); + ++arrayIndex; + } + + if (((_bits & 8L) != 0)) + { + if (arrayIndex == array.Length) + { + throw new ArgumentException(); + } + + array[arrayIndex] = new KeyValuePair("Keep-Alive", _KeepAlive); + ++arrayIndex; + } + + if (((_bits & 16L) != 0)) + { + if (arrayIndex == array.Length) + { + throw new ArgumentException(); + } + + array[arrayIndex] = new KeyValuePair("Pragma", _Pragma); + ++arrayIndex; + } + + if (((_bits & 32L) != 0)) + { + if (arrayIndex == array.Length) + { + throw new ArgumentException(); + } + + array[arrayIndex] = new KeyValuePair("Trailer", _Trailer); + ++arrayIndex; + } + + if (((_bits & 64L) != 0)) + { + if (arrayIndex == array.Length) + { + throw new ArgumentException(); + } + + array[arrayIndex] = new KeyValuePair("Transfer-Encoding", _TransferEncoding); + ++arrayIndex; + } + + if (((_bits & 128L) != 0)) + { + if (arrayIndex == array.Length) + { + throw new ArgumentException(); + } + + array[arrayIndex] = new KeyValuePair("Upgrade", _Upgrade); + ++arrayIndex; + } + + if (((_bits & 256L) != 0)) + { + if (arrayIndex == array.Length) + { + throw new ArgumentException(); + } + + array[arrayIndex] = new KeyValuePair("Via", _Via); + ++arrayIndex; + } + + if (((_bits & 512L) != 0)) + { + if (arrayIndex == array.Length) + { + throw new ArgumentException(); + } + + array[arrayIndex] = new KeyValuePair("Warning", _Warning); + ++arrayIndex; + } + + if (((_bits & 1024L) != 0)) + { + if (arrayIndex == array.Length) + { + throw new ArgumentException(); + } + + array[arrayIndex] = new KeyValuePair("Allow", _Allow); + ++arrayIndex; + } + + if (((_bits & 2048L) != 0)) + { + if (arrayIndex == array.Length) + { + throw new ArgumentException(); + } + + array[arrayIndex] = new KeyValuePair("Content-Length", _ContentLength); + ++arrayIndex; + } + + if (((_bits & 4096L) != 0)) + { + if (arrayIndex == array.Length) + { + throw new ArgumentException(); + } + + array[arrayIndex] = new KeyValuePair("Content-Type", _ContentType); + ++arrayIndex; + } + + if (((_bits & 8192L) != 0)) + { + if (arrayIndex == array.Length) + { + throw new ArgumentException(); + } + + array[arrayIndex] = new KeyValuePair("Content-Encoding", _ContentEncoding); + ++arrayIndex; + } + + if (((_bits & 16384L) != 0)) + { + if (arrayIndex == array.Length) + { + throw new ArgumentException(); + } + + array[arrayIndex] = new KeyValuePair("Content-Language", _ContentLanguage); + ++arrayIndex; + } + + if (((_bits & 32768L) != 0)) + { + if (arrayIndex == array.Length) + { + throw new ArgumentException(); + } + + array[arrayIndex] = new KeyValuePair("Content-Location", _ContentLocation); + ++arrayIndex; + } + + if (((_bits & 65536L) != 0)) + { + if (arrayIndex == array.Length) + { + throw new ArgumentException(); + } + + array[arrayIndex] = new KeyValuePair("Content-MD5", _ContentMD5); + ++arrayIndex; + } + + if (((_bits & 131072L) != 0)) + { + if (arrayIndex == array.Length) + { + throw new ArgumentException(); + } + + array[arrayIndex] = new KeyValuePair("Content-Range", _ContentRange); + ++arrayIndex; + } + + if (((_bits & 262144L) != 0)) + { + if (arrayIndex == array.Length) + { + throw new ArgumentException(); + } + + array[arrayIndex] = new KeyValuePair("Expires", _Expires); + ++arrayIndex; + } + + if (((_bits & 524288L) != 0)) + { + if (arrayIndex == array.Length) + { + throw new ArgumentException(); + } + + array[arrayIndex] = new KeyValuePair("Last-Modified", _LastModified); + ++arrayIndex; + } + + if (((_bits & 1048576L) != 0)) + { + if (arrayIndex == array.Length) + { + throw new ArgumentException(); + } + + array[arrayIndex] = new KeyValuePair("Accept-Ranges", _AcceptRanges); + ++arrayIndex; + } + + if (((_bits & 2097152L) != 0)) + { + if (arrayIndex == array.Length) + { + throw new ArgumentException(); + } + + array[arrayIndex] = new KeyValuePair("Age", _Age); + ++arrayIndex; + } + + if (((_bits & 4194304L) != 0)) + { + if (arrayIndex == array.Length) + { + throw new ArgumentException(); + } + + array[arrayIndex] = new KeyValuePair("ETag", _ETag); + ++arrayIndex; + } + + if (((_bits & 8388608L) != 0)) + { + if (arrayIndex == array.Length) + { + throw new ArgumentException(); + } + + array[arrayIndex] = new KeyValuePair("Location", _Location); + ++arrayIndex; + } + + if (((_bits & 16777216L) != 0)) + { + if (arrayIndex == array.Length) + { + throw new ArgumentException(); + } + + array[arrayIndex] = new KeyValuePair("Proxy-Autheticate", _ProxyAutheticate); + ++arrayIndex; + } + + if (((_bits & 33554432L) != 0)) + { + if (arrayIndex == array.Length) + { + throw new ArgumentException(); + } + + array[arrayIndex] = new KeyValuePair("Retry-After", _RetryAfter); + ++arrayIndex; + } + + if (((_bits & 67108864L) != 0)) + { + if (arrayIndex == array.Length) + { + throw new ArgumentException(); + } + + array[arrayIndex] = new KeyValuePair("Server", _Server); + ++arrayIndex; + } + + if (((_bits & 134217728L) != 0)) + { + if (arrayIndex == array.Length) + { + throw new ArgumentException(); + } + + array[arrayIndex] = new KeyValuePair("Set-Cookie", _SetCookie); + ++arrayIndex; + } + + if (((_bits & 268435456L) != 0)) + { + if (arrayIndex == array.Length) + { + throw new ArgumentException(); + } + + array[arrayIndex] = new KeyValuePair("Vary", _Vary); + ++arrayIndex; + } + + if (((_bits & 536870912L) != 0)) + { + if (arrayIndex == array.Length) + { + throw new ArgumentException(); + } + + array[arrayIndex] = new KeyValuePair("WWW-Authenticate", _WWWAuthenticate); + ++arrayIndex; + } + + ((ICollection>)MaybeUnknown)?.CopyTo(array, arrayIndex); + } + + public partial struct Enumerator + { + public bool MoveNext() + { + switch (_state) + { + + case 0: + goto state0; + + case 1: + goto state1; + + case 2: + goto state2; + + case 3: + goto state3; + + case 4: + goto state4; + + case 5: + goto state5; + + case 6: + goto state6; + + case 7: + goto state7; + + case 8: + goto state8; + + case 9: + goto state9; + + case 10: + goto state10; + + case 11: + goto state11; + + case 12: + goto state12; + + case 13: + goto state13; + + case 14: + goto state14; + + case 15: + goto state15; + + case 16: + goto state16; + + case 17: + goto state17; + + case 18: + goto state18; + + case 19: + goto state19; + + case 20: + goto state20; + + case 21: + goto state21; + + case 22: + goto state22; + + case 23: + goto state23; + + case 24: + goto state24; + + case 25: + goto state25; + + case 26: + goto state26; + + case 27: + goto state27; + + case 28: + goto state28; + + case 29: + goto state29; + + default: + goto state_default; + } + + state0: + if (((_bits & 1L) != 0)) + { + _current = new KeyValuePair("Cache-Control", _collection._CacheControl); + _state = 1; + return true; + } + + state1: + if (((_bits & 2L) != 0)) + { + _current = new KeyValuePair("Connection", _collection._Connection); + _state = 2; + return true; + } + + state2: + if (((_bits & 4L) != 0)) + { + _current = new KeyValuePair("Date", _collection._Date); + _state = 3; + return true; + } + + state3: + if (((_bits & 8L) != 0)) + { + _current = new KeyValuePair("Keep-Alive", _collection._KeepAlive); + _state = 4; + return true; + } + + state4: + if (((_bits & 16L) != 0)) + { + _current = new KeyValuePair("Pragma", _collection._Pragma); + _state = 5; + return true; + } + + state5: + if (((_bits & 32L) != 0)) + { + _current = new KeyValuePair("Trailer", _collection._Trailer); + _state = 6; + return true; + } + + state6: + if (((_bits & 64L) != 0)) + { + _current = new KeyValuePair("Transfer-Encoding", _collection._TransferEncoding); + _state = 7; + return true; + } + + state7: + if (((_bits & 128L) != 0)) + { + _current = new KeyValuePair("Upgrade", _collection._Upgrade); + _state = 8; + return true; + } + + state8: + if (((_bits & 256L) != 0)) + { + _current = new KeyValuePair("Via", _collection._Via); + _state = 9; + return true; + } + + state9: + if (((_bits & 512L) != 0)) + { + _current = new KeyValuePair("Warning", _collection._Warning); + _state = 10; + return true; + } + + state10: + if (((_bits & 1024L) != 0)) + { + _current = new KeyValuePair("Allow", _collection._Allow); + _state = 11; + return true; + } + + state11: + if (((_bits & 2048L) != 0)) + { + _current = new KeyValuePair("Content-Length", _collection._ContentLength); + _state = 12; + return true; + } + + state12: + if (((_bits & 4096L) != 0)) + { + _current = new KeyValuePair("Content-Type", _collection._ContentType); + _state = 13; + return true; + } + + state13: + if (((_bits & 8192L) != 0)) + { + _current = new KeyValuePair("Content-Encoding", _collection._ContentEncoding); + _state = 14; + return true; + } + + state14: + if (((_bits & 16384L) != 0)) + { + _current = new KeyValuePair("Content-Language", _collection._ContentLanguage); + _state = 15; + return true; + } + + state15: + if (((_bits & 32768L) != 0)) + { + _current = new KeyValuePair("Content-Location", _collection._ContentLocation); + _state = 16; + return true; + } + + state16: + if (((_bits & 65536L) != 0)) + { + _current = new KeyValuePair("Content-MD5", _collection._ContentMD5); + _state = 17; + return true; + } + + state17: + if (((_bits & 131072L) != 0)) + { + _current = new KeyValuePair("Content-Range", _collection._ContentRange); + _state = 18; + return true; + } + + state18: + if (((_bits & 262144L) != 0)) + { + _current = new KeyValuePair("Expires", _collection._Expires); + _state = 19; + return true; + } + + state19: + if (((_bits & 524288L) != 0)) + { + _current = new KeyValuePair("Last-Modified", _collection._LastModified); + _state = 20; + return true; + } + + state20: + if (((_bits & 1048576L) != 0)) + { + _current = new KeyValuePair("Accept-Ranges", _collection._AcceptRanges); + _state = 21; + return true; + } + + state21: + if (((_bits & 2097152L) != 0)) + { + _current = new KeyValuePair("Age", _collection._Age); + _state = 22; + return true; + } + + state22: + if (((_bits & 4194304L) != 0)) + { + _current = new KeyValuePair("ETag", _collection._ETag); + _state = 23; + return true; + } + + state23: + if (((_bits & 8388608L) != 0)) + { + _current = new KeyValuePair("Location", _collection._Location); + _state = 24; + return true; + } + + state24: + if (((_bits & 16777216L) != 0)) + { + _current = new KeyValuePair("Proxy-Autheticate", _collection._ProxyAutheticate); + _state = 25; + return true; + } + + state25: + if (((_bits & 33554432L) != 0)) + { + _current = new KeyValuePair("Retry-After", _collection._RetryAfter); + _state = 26; + return true; + } + + state26: + if (((_bits & 67108864L) != 0)) + { + _current = new KeyValuePair("Server", _collection._Server); + _state = 27; + return true; + } + + state27: + if (((_bits & 134217728L) != 0)) + { + _current = new KeyValuePair("Set-Cookie", _collection._SetCookie); + _state = 28; + return true; + } + + state28: + if (((_bits & 268435456L) != 0)) + { + _current = new KeyValuePair("Vary", _collection._Vary); + _state = 29; + return true; + } + + state29: + if (((_bits & 536870912L) != 0)) + { + _current = new KeyValuePair("WWW-Authenticate", _collection._WWWAuthenticate); + _state = 30; + return true; + } + + state_default: + if (!_hasUnknown || !_unknownEnumerator.MoveNext()) + { + _current = default(KeyValuePair); + return false; + } + _current = _unknownEnumerator.Current; + return true; + } + } + } +} diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameRequestHeaders.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameHeaders.cs similarity index 52% rename from src/Microsoft.AspNet.Server.Kestrel/Http/FrameRequestHeaders.cs rename to src/Microsoft.AspNet.Server.Kestrel/Http/FrameHeaders.cs index 6d6a45683b..3393c9875c 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameRequestHeaders.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameHeaders.cs @@ -5,17 +5,11 @@ using System.Linq; namespace Microsoft.AspNet.Server.Kestrel.Http { - public partial class FrameRequestHeaders : FrameHeaders - { - } - - public partial class FrameResponseHeaders : FrameHeaders - { - } - public abstract class FrameHeaders : IDictionary { - protected Dictionary Unknown = new Dictionary(StringComparer.OrdinalIgnoreCase); + protected Dictionary MaybeUnknown; + + protected Dictionary Unknown => MaybeUnknown ?? (MaybeUnknown = new Dictionary(StringComparer.OrdinalIgnoreCase)); protected virtual int GetCountFast() { throw new NotImplementedException(); } @@ -41,7 +35,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http protected virtual void CopyToFast(KeyValuePair[] array, int arrayIndex) { throw new NotImplementedException(); } - protected virtual IEnumerable> EnumerateFast() + protected virtual IEnumerator> GetEnumeratorFast() { throw new NotImplementedException(); } @@ -62,9 +56,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Http bool ICollection>.IsReadOnly => false; - ICollection IDictionary.Keys => EnumerateFast().Select(x => x.Key).ToList(); + ICollection IDictionary.Keys => ((IDictionary)this).Select(x => x.Key).ToList(); - ICollection IDictionary.Values => EnumerateFast().Select(x => x.Value).ToList(); + ICollection IDictionary.Values => ((IDictionary)this).Select(x => x.Value).ToList(); void ICollection>.Add(KeyValuePair item) { @@ -102,12 +96,12 @@ namespace Microsoft.AspNet.Server.Kestrel.Http IEnumerator IEnumerable.GetEnumerator() { - return EnumerateFast().GetEnumerator(); + return GetEnumeratorFast(); } IEnumerator> IEnumerable>.GetEnumerator() { - return EnumerateFast().GetEnumerator(); + return GetEnumeratorFast(); } bool ICollection>.Remove(KeyValuePair item) @@ -129,4 +123,100 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return TryGetValueFast(key, out value); } } + + public partial class FrameRequestHeaders : FrameHeaders + { + public Enumerator GetEnumerator() + { + return new Enumerator(this); + } + + protected override IEnumerator> GetEnumeratorFast() + { + return GetEnumerator(); + } + + public partial struct Enumerator : IEnumerator> + { + FrameRequestHeaders _collection; + long _bits; + int _state; + KeyValuePair _current; + bool _hasUnknown; + Dictionary.Enumerator _unknownEnumerator; + + internal Enumerator(FrameRequestHeaders collection) + { + _collection = collection; + _bits = collection._bits; + _state = 0; + _current = default(KeyValuePair); + _hasUnknown = collection.MaybeUnknown != null; + _unknownEnumerator = _hasUnknown + ? collection.MaybeUnknown.GetEnumerator() + : default(Dictionary.Enumerator); + } + + public KeyValuePair Current => _current; + + object IEnumerator.Current => _current; + + public void Dispose() + { + } + + public void Reset() + { + _state = 0; + } + } + } + + public partial class FrameResponseHeaders : FrameHeaders + { + public Enumerator GetEnumerator() + { + return new Enumerator(this); + } + + protected override IEnumerator> GetEnumeratorFast() + { + return GetEnumerator(); + } + + public partial struct Enumerator : IEnumerator> + { + FrameResponseHeaders _collection; + long _bits; + int _state; + KeyValuePair _current; + bool _hasUnknown; + Dictionary.Enumerator _unknownEnumerator; + + internal Enumerator(FrameResponseHeaders collection) + { + _collection = collection; + _bits = collection._bits; + _state = 0; + _current = default(KeyValuePair); + _hasUnknown = collection.MaybeUnknown != null; + _unknownEnumerator = _hasUnknown + ? collection.MaybeUnknown.GetEnumerator() + : default(Dictionary.Enumerator); + } + + public KeyValuePair Current => _current; + + object IEnumerator.Current => _current; + + public void Dispose() + { + } + + public void Reset() + { + _state = 0; + } + } + } } diff --git a/src/Microsoft.AspNet.Server.Kestrel/compiler/preprocess/KnownHeaders.cs b/src/Microsoft.AspNet.Server.Kestrel/compiler/preprocess/KnownHeaders.cs deleted file mode 100644 index 8ef4e55532..0000000000 --- a/src/Microsoft.AspNet.Server.Kestrel/compiler/preprocess/KnownHeaders.cs +++ /dev/null @@ -1,11 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; - -namespace Microsoft.AspNet.Server.Kestrel -{ - public class KnownHeaders : Microsoft.AspNet.Server.Kestrel.GeneratedCode.KnownHeaders - { - } -} diff --git a/src/Microsoft.AspNet.Server.Kestrel/project.json b/src/Microsoft.AspNet.Server.Kestrel/project.json index 93f24a85d1..c94eea129a 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/project.json +++ b/src/Microsoft.AspNet.Server.Kestrel/project.json @@ -6,8 +6,7 @@ "url": "git://github.com/aspnet/kestrelhttpserver" }, "dependencies": { - "Microsoft.Dnx.Runtime.Abstractions": "1.0.0-beta7-*", - "Microsoft.AspNet.Server.Kestrel.GeneratedCode": { "version": "1.0.0-*", "type": "build" } + "Microsoft.Dnx.Runtime.Abstractions": "1.0.0-beta7-*" }, "frameworks": { "dnx451": { }, @@ -33,5 +32,8 @@ }, "compilationOptions": { "allowUnsafe": true + }, + "scripts": { + "prepare": "dnx ../Microsoft.AspNet.Server.Kestrel.GeneratedCode run Http/FrameHeaders.Generated.cs" } } From f9cf9f193635912cd2cbf3dd2722e870c72a724f Mon Sep 17 00:00:00 2001 From: Louis DeJardin Date: Fri, 17 Jul 2015 00:32:21 -0700 Subject: [PATCH 0178/1662] Improvements to appending request header --- .../KnownHeaders.cs | 26 + .../Http/Frame.cs | 17 +- .../Http/FrameHeaders.Generated.cs | 1130 +++++++++++++++++ .../Http/FrameHeaders.cs | 8 + 4 files changed, 1168 insertions(+), 13 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel.GeneratedCode/KnownHeaders.cs b/src/Microsoft.AspNet.Server.Kestrel.GeneratedCode/KnownHeaders.cs index 3c082cb9a2..4efc96151f 100644 --- a/src/Microsoft.AspNet.Server.Kestrel.GeneratedCode/KnownHeaders.cs +++ b/src/Microsoft.AspNet.Server.Kestrel.GeneratedCode/KnownHeaders.cs @@ -288,6 +288,32 @@ namespace Microsoft.AspNet.Server.Kestrel.Http ((ICollection>)MaybeUnknown)?.CopyTo(array, arrayIndex); }} + public void Append(string key, string value) + {{ + switch(key.Length) + {{{Each(loop.HeadersByLength, byLength => $@" + case {byLength.Key}: + {{{Each(byLength, header => $@" + if (""{header.Name}"".Equals(key, StringComparison.OrdinalIgnoreCase)) + {{ + if ({header.TestBit()}) + {{ + _{header.Identifier} = AppendValue(_{header.Identifier}, value); + }} + else + {{ + {header.SetBit()}; + _{header.Identifier} = new[] {{value}}; + }} + return; + }} + ")}}} + break; + ")}}} + string[] existing; + Unknown[key] = Unknown.TryGetValue(key, out existing) ? AppendValue(existing, value) : new[] {{value}}; + }} + public partial struct Enumerator {{ public bool MoveNext() diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs index c8a3b5576a..d34b09e03c 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs @@ -23,6 +23,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http Terminated, } + static Encoding _ascii = Encoding.ASCII; Mode _mode; private bool _resultStarted; private bool _responseStarted; @@ -517,11 +518,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http ch2 != ' ' && ch2 != '\t') { - var name = Encoding.ASCII.GetString(remaining.Array, remaining.Offset, colonIndex); + var name = _ascii.GetString(remaining.Array, remaining.Offset, colonIndex); var value = ""; if (valueEndIndex != -1) { - value = Encoding.ASCII.GetString( + value = _ascii.GetString( remaining.Array, remaining.Offset + valueStartIndex, valueEndIndex - valueStartIndex); } if (wrappedHeaders) @@ -565,17 +566,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http private void AddRequestHeader(string name, string value) { - string[] existing; - if (!RequestHeaders.TryGetValue(name, out existing) || - existing == null || - existing.Length == 0) - { - RequestHeaders[name] = new[] { value }; - } - else - { - RequestHeaders[name] = existing.Concat(new[] { value }).ToArray(); - } + _requestHeaders.Append(name, value); } } } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameHeaders.Generated.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameHeaders.Generated.cs index 90cf28d245..86f591b54b 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameHeaders.Generated.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameHeaders.Generated.cs @@ -3447,6 +3447,656 @@ namespace Microsoft.AspNet.Server.Kestrel.Http ((ICollection>)MaybeUnknown)?.CopyTo(array, arrayIndex); } + public void Append(string key, string value) + { + switch(key.Length) + { + case 13: + { + if ("Cache-Control".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 1L) != 0)) + { + _CacheControl = AppendValue(_CacheControl, value); + } + else + { + _bits |= 1L; + _CacheControl = new[] {value}; + } + return; + } + + if ("Content-Range".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 131072L) != 0)) + { + _ContentRange = AppendValue(_ContentRange, value); + } + else + { + _bits |= 131072L; + _ContentRange = new[] {value}; + } + return; + } + + if ("Last-Modified".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 524288L) != 0)) + { + _LastModified = AppendValue(_LastModified, value); + } + else + { + _bits |= 524288L; + _LastModified = new[] {value}; + } + return; + } + + if ("Authorization".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 16777216L) != 0)) + { + _Authorization = AppendValue(_Authorization, value); + } + else + { + _bits |= 16777216L; + _Authorization = new[] {value}; + } + return; + } + + if ("If-None-Match".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 2147483648L) != 0)) + { + _IfNoneMatch = AppendValue(_IfNoneMatch, value); + } + else + { + _bits |= 2147483648L; + _IfNoneMatch = new[] {value}; + } + return; + } + } + break; + + case 10: + { + if ("Connection".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 2L) != 0)) + { + _Connection = AppendValue(_Connection, value); + } + else + { + _bits |= 2L; + _Connection = new[] {value}; + } + return; + } + + if ("Keep-Alive".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 8L) != 0)) + { + _KeepAlive = AppendValue(_KeepAlive, value); + } + else + { + _bits |= 8L; + _KeepAlive = new[] {value}; + } + return; + } + + if ("User-Agent".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 1099511627776L) != 0)) + { + _UserAgent = AppendValue(_UserAgent, value); + } + else + { + _bits |= 1099511627776L; + _UserAgent = new[] {value}; + } + return; + } + } + break; + + case 4: + { + if ("Date".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 4L) != 0)) + { + _Date = AppendValue(_Date, value); + } + else + { + _bits |= 4L; + _Date = new[] {value}; + } + return; + } + + if ("From".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 134217728L) != 0)) + { + _From = AppendValue(_From, value); + } + else + { + _bits |= 134217728L; + _From = new[] {value}; + } + return; + } + + if ("Host".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 268435456L) != 0)) + { + _Host = AppendValue(_Host, value); + } + else + { + _bits |= 268435456L; + _Host = new[] {value}; + } + return; + } + } + break; + + case 6: + { + if ("Pragma".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 16L) != 0)) + { + _Pragma = AppendValue(_Pragma, value); + } + else + { + _bits |= 16L; + _Pragma = new[] {value}; + } + return; + } + + if ("Accept".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 1048576L) != 0)) + { + _Accept = AppendValue(_Accept, value); + } + else + { + _bits |= 1048576L; + _Accept = new[] {value}; + } + return; + } + + if ("Cookie".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 33554432L) != 0)) + { + _Cookie = AppendValue(_Cookie, value); + } + else + { + _bits |= 33554432L; + _Cookie = new[] {value}; + } + return; + } + + if ("Expect".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 67108864L) != 0)) + { + _Expect = AppendValue(_Expect, value); + } + else + { + _bits |= 67108864L; + _Expect = new[] {value}; + } + return; + } + } + break; + + case 7: + { + if ("Trailer".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 32L) != 0)) + { + _Trailer = AppendValue(_Trailer, value); + } + else + { + _bits |= 32L; + _Trailer = new[] {value}; + } + return; + } + + if ("Upgrade".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 128L) != 0)) + { + _Upgrade = AppendValue(_Upgrade, value); + } + else + { + _bits |= 128L; + _Upgrade = new[] {value}; + } + return; + } + + if ("Warning".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 512L) != 0)) + { + _Warning = AppendValue(_Warning, value); + } + else + { + _bits |= 512L; + _Warning = new[] {value}; + } + return; + } + + if ("Expires".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 262144L) != 0)) + { + _Expires = AppendValue(_Expires, value); + } + else + { + _bits |= 262144L; + _Expires = new[] {value}; + } + return; + } + + if ("Referer".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 68719476736L) != 0)) + { + _Referer = AppendValue(_Referer, value); + } + else + { + _bits |= 68719476736L; + _Referer = new[] {value}; + } + return; + } + } + break; + + case 17: + { + if ("Transfer-Encoding".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 64L) != 0)) + { + _TransferEncoding = AppendValue(_TransferEncoding, value); + } + else + { + _bits |= 64L; + _TransferEncoding = new[] {value}; + } + return; + } + + if ("If-Modified-Since".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 1073741824L) != 0)) + { + _IfModifiedSince = AppendValue(_IfModifiedSince, value); + } + else + { + _bits |= 1073741824L; + _IfModifiedSince = new[] {value}; + } + return; + } + } + break; + + case 3: + { + if ("Via".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 256L) != 0)) + { + _Via = AppendValue(_Via, value); + } + else + { + _bits |= 256L; + _Via = new[] {value}; + } + return; + } + } + break; + + case 5: + { + if ("Allow".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 1024L) != 0)) + { + _Allow = AppendValue(_Allow, value); + } + else + { + _bits |= 1024L; + _Allow = new[] {value}; + } + return; + } + + if ("Range".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 137438953472L) != 0)) + { + _Range = AppendValue(_Range, value); + } + else + { + _bits |= 137438953472L; + _Range = new[] {value}; + } + return; + } + } + break; + + case 14: + { + if ("Content-Length".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 2048L) != 0)) + { + _ContentLength = AppendValue(_ContentLength, value); + } + else + { + _bits |= 2048L; + _ContentLength = new[] {value}; + } + return; + } + + if ("Accept-Charset".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 2097152L) != 0)) + { + _AcceptCharset = AppendValue(_AcceptCharset, value); + } + else + { + _bits |= 2097152L; + _AcceptCharset = new[] {value}; + } + return; + } + } + break; + + case 12: + { + if ("Content-Type".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 4096L) != 0)) + { + _ContentType = AppendValue(_ContentType, value); + } + else + { + _bits |= 4096L; + _ContentType = new[] {value}; + } + return; + } + + if ("Max-Forwards".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 17179869184L) != 0)) + { + _MaxForwards = AppendValue(_MaxForwards, value); + } + else + { + _bits |= 17179869184L; + _MaxForwards = new[] {value}; + } + return; + } + } + break; + + case 16: + { + if ("Content-Encoding".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 8192L) != 0)) + { + _ContentEncoding = AppendValue(_ContentEncoding, value); + } + else + { + _bits |= 8192L; + _ContentEncoding = new[] {value}; + } + return; + } + + if ("Content-Language".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 16384L) != 0)) + { + _ContentLanguage = AppendValue(_ContentLanguage, value); + } + else + { + _bits |= 16384L; + _ContentLanguage = new[] {value}; + } + return; + } + + if ("Content-Location".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 32768L) != 0)) + { + _ContentLocation = AppendValue(_ContentLocation, value); + } + else + { + _bits |= 32768L; + _ContentLocation = new[] {value}; + } + return; + } + } + break; + + case 11: + { + if ("Content-MD5".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 65536L) != 0)) + { + _ContentMD5 = AppendValue(_ContentMD5, value); + } + else + { + _bits |= 65536L; + _ContentMD5 = new[] {value}; + } + return; + } + } + break; + + case 15: + { + if ("Accept-Encoding".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 4194304L) != 0)) + { + _AcceptEncoding = AppendValue(_AcceptEncoding, value); + } + else + { + _bits |= 4194304L; + _AcceptEncoding = new[] {value}; + } + return; + } + + if ("Accept-Language".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 8388608L) != 0)) + { + _AcceptLanguage = AppendValue(_AcceptLanguage, value); + } + else + { + _bits |= 8388608L; + _AcceptLanguage = new[] {value}; + } + return; + } + } + break; + + case 8: + { + if ("If-Match".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 536870912L) != 0)) + { + _IfMatch = AppendValue(_IfMatch, value); + } + else + { + _bits |= 536870912L; + _IfMatch = new[] {value}; + } + return; + } + + if ("If-Range".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 4294967296L) != 0)) + { + _IfRange = AppendValue(_IfRange, value); + } + else + { + _bits |= 4294967296L; + _IfRange = new[] {value}; + } + return; + } + } + break; + + case 19: + { + if ("If-Unmodified-Since".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 8589934592L) != 0)) + { + _IfUnmodifiedSince = AppendValue(_IfUnmodifiedSince, value); + } + else + { + _bits |= 8589934592L; + _IfUnmodifiedSince = new[] {value}; + } + return; + } + + if ("Proxy-Authorization".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 34359738368L) != 0)) + { + _ProxyAuthorization = AppendValue(_ProxyAuthorization, value); + } + else + { + _bits |= 34359738368L; + _ProxyAuthorization = new[] {value}; + } + return; + } + } + break; + + case 2: + { + if ("TE".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 274877906944L) != 0)) + { + _TE = AppendValue(_TE, value); + } + else + { + _bits |= 274877906944L; + _TE = new[] {value}; + } + return; + } + } + break; + + case 9: + { + if ("Translate".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 549755813888L) != 0)) + { + _Translate = AppendValue(_Translate, value); + } + else + { + _bits |= 549755813888L; + _Translate = new[] {value}; + } + return; + } + } + break; + } + string[] existing; + Unknown[key] = Unknown.TryGetValue(key, out existing) ? AppendValue(existing, value) : new[] {value}; + } + public partial struct Enumerator { public bool MoveNext() @@ -6470,6 +7120,486 @@ namespace Microsoft.AspNet.Server.Kestrel.Http ((ICollection>)MaybeUnknown)?.CopyTo(array, arrayIndex); } + public void Append(string key, string value) + { + switch(key.Length) + { + case 13: + { + if ("Cache-Control".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 1L) != 0)) + { + _CacheControl = AppendValue(_CacheControl, value); + } + else + { + _bits |= 1L; + _CacheControl = new[] {value}; + } + return; + } + + if ("Content-Range".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 131072L) != 0)) + { + _ContentRange = AppendValue(_ContentRange, value); + } + else + { + _bits |= 131072L; + _ContentRange = new[] {value}; + } + return; + } + + if ("Last-Modified".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 524288L) != 0)) + { + _LastModified = AppendValue(_LastModified, value); + } + else + { + _bits |= 524288L; + _LastModified = new[] {value}; + } + return; + } + + if ("Accept-Ranges".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 1048576L) != 0)) + { + _AcceptRanges = AppendValue(_AcceptRanges, value); + } + else + { + _bits |= 1048576L; + _AcceptRanges = new[] {value}; + } + return; + } + } + break; + + case 10: + { + if ("Connection".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 2L) != 0)) + { + _Connection = AppendValue(_Connection, value); + } + else + { + _bits |= 2L; + _Connection = new[] {value}; + } + return; + } + + if ("Keep-Alive".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 8L) != 0)) + { + _KeepAlive = AppendValue(_KeepAlive, value); + } + else + { + _bits |= 8L; + _KeepAlive = new[] {value}; + } + return; + } + + if ("Set-Cookie".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 134217728L) != 0)) + { + _SetCookie = AppendValue(_SetCookie, value); + } + else + { + _bits |= 134217728L; + _SetCookie = new[] {value}; + } + return; + } + } + break; + + case 4: + { + if ("Date".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 4L) != 0)) + { + _Date = AppendValue(_Date, value); + } + else + { + _bits |= 4L; + _Date = new[] {value}; + } + return; + } + + if ("ETag".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 4194304L) != 0)) + { + _ETag = AppendValue(_ETag, value); + } + else + { + _bits |= 4194304L; + _ETag = new[] {value}; + } + return; + } + + if ("Vary".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 268435456L) != 0)) + { + _Vary = AppendValue(_Vary, value); + } + else + { + _bits |= 268435456L; + _Vary = new[] {value}; + } + return; + } + } + break; + + case 6: + { + if ("Pragma".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 16L) != 0)) + { + _Pragma = AppendValue(_Pragma, value); + } + else + { + _bits |= 16L; + _Pragma = new[] {value}; + } + return; + } + + if ("Server".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 67108864L) != 0)) + { + _Server = AppendValue(_Server, value); + } + else + { + _bits |= 67108864L; + _Server = new[] {value}; + } + return; + } + } + break; + + case 7: + { + if ("Trailer".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 32L) != 0)) + { + _Trailer = AppendValue(_Trailer, value); + } + else + { + _bits |= 32L; + _Trailer = new[] {value}; + } + return; + } + + if ("Upgrade".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 128L) != 0)) + { + _Upgrade = AppendValue(_Upgrade, value); + } + else + { + _bits |= 128L; + _Upgrade = new[] {value}; + } + return; + } + + if ("Warning".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 512L) != 0)) + { + _Warning = AppendValue(_Warning, value); + } + else + { + _bits |= 512L; + _Warning = new[] {value}; + } + return; + } + + if ("Expires".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 262144L) != 0)) + { + _Expires = AppendValue(_Expires, value); + } + else + { + _bits |= 262144L; + _Expires = new[] {value}; + } + return; + } + } + break; + + case 17: + { + if ("Transfer-Encoding".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 64L) != 0)) + { + _TransferEncoding = AppendValue(_TransferEncoding, value); + } + else + { + _bits |= 64L; + _TransferEncoding = new[] {value}; + } + return; + } + + if ("Proxy-Autheticate".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 16777216L) != 0)) + { + _ProxyAutheticate = AppendValue(_ProxyAutheticate, value); + } + else + { + _bits |= 16777216L; + _ProxyAutheticate = new[] {value}; + } + return; + } + } + break; + + case 3: + { + if ("Via".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 256L) != 0)) + { + _Via = AppendValue(_Via, value); + } + else + { + _bits |= 256L; + _Via = new[] {value}; + } + return; + } + + if ("Age".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 2097152L) != 0)) + { + _Age = AppendValue(_Age, value); + } + else + { + _bits |= 2097152L; + _Age = new[] {value}; + } + return; + } + } + break; + + case 5: + { + if ("Allow".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 1024L) != 0)) + { + _Allow = AppendValue(_Allow, value); + } + else + { + _bits |= 1024L; + _Allow = new[] {value}; + } + return; + } + } + break; + + case 14: + { + if ("Content-Length".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 2048L) != 0)) + { + _ContentLength = AppendValue(_ContentLength, value); + } + else + { + _bits |= 2048L; + _ContentLength = new[] {value}; + } + return; + } + } + break; + + case 12: + { + if ("Content-Type".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 4096L) != 0)) + { + _ContentType = AppendValue(_ContentType, value); + } + else + { + _bits |= 4096L; + _ContentType = new[] {value}; + } + return; + } + } + break; + + case 16: + { + if ("Content-Encoding".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 8192L) != 0)) + { + _ContentEncoding = AppendValue(_ContentEncoding, value); + } + else + { + _bits |= 8192L; + _ContentEncoding = new[] {value}; + } + return; + } + + if ("Content-Language".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 16384L) != 0)) + { + _ContentLanguage = AppendValue(_ContentLanguage, value); + } + else + { + _bits |= 16384L; + _ContentLanguage = new[] {value}; + } + return; + } + + if ("Content-Location".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 32768L) != 0)) + { + _ContentLocation = AppendValue(_ContentLocation, value); + } + else + { + _bits |= 32768L; + _ContentLocation = new[] {value}; + } + return; + } + + if ("WWW-Authenticate".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 536870912L) != 0)) + { + _WWWAuthenticate = AppendValue(_WWWAuthenticate, value); + } + else + { + _bits |= 536870912L; + _WWWAuthenticate = new[] {value}; + } + return; + } + } + break; + + case 11: + { + if ("Content-MD5".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 65536L) != 0)) + { + _ContentMD5 = AppendValue(_ContentMD5, value); + } + else + { + _bits |= 65536L; + _ContentMD5 = new[] {value}; + } + return; + } + + if ("Retry-After".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 33554432L) != 0)) + { + _RetryAfter = AppendValue(_RetryAfter, value); + } + else + { + _bits |= 33554432L; + _RetryAfter = new[] {value}; + } + return; + } + } + break; + + case 8: + { + if ("Location".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 8388608L) != 0)) + { + _Location = AppendValue(_Location, value); + } + else + { + _bits |= 8388608L; + _Location = new[] {value}; + } + return; + } + } + break; + } + string[] existing; + Unknown[key] = Unknown.TryGetValue(key, out existing) ? AppendValue(existing, value) : new[] {value}; + } + public partial struct Enumerator { public bool MoveNext() diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameHeaders.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameHeaders.cs index 3393c9875c..9cd8d90488 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameHeaders.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameHeaders.cs @@ -11,6 +11,14 @@ namespace Microsoft.AspNet.Server.Kestrel.Http protected Dictionary Unknown => MaybeUnknown ?? (MaybeUnknown = new Dictionary(StringComparer.OrdinalIgnoreCase)); + protected static string[] AppendValue(string[] existing, string append) + { + var appended = new string[existing.Length + 1]; + Array.Copy(existing, appended, existing.Length); + appended[existing.Length] = append; + return appended; + } + protected virtual int GetCountFast() { throw new NotImplementedException(); } From c0728edda7fb6c4c57c03587b9eaa6cf81ccad4b Mon Sep 17 00:00:00 2001 From: Louis DeJardin Date: Fri, 17 Jul 2015 00:38:12 -0700 Subject: [PATCH 0179/1662] Linq .Any() was causing enumeration --- .../Http/MessageBodyExchanger.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/MessageBodyExchanger.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/MessageBodyExchanger.cs index c84c5e17ec..aee1933230 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/MessageBodyExchanger.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/MessageBodyExchanger.cs @@ -64,7 +64,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { LocalIntakeFin = true; } - if (_reads.Any()) + if (_reads.Count != 0) { ThreadPool.QueueUserWorkItem(_completePending, this); } @@ -86,7 +86,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http if (_buffer.Count != 0 || buffer.Count == 0 || LocalIntakeFin) { // there is data we can take right now - if (_reads.Any()) + if (_reads.Count != 0) { // someone snuck in, try again continue; @@ -137,7 +137,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { return false; } - if (!_reads.Any()) + if (_reads.Count == 0) { return false; } From f6dc72544c6c2c7fd35d1f676fcce309fa64a7f3 Mon Sep 17 00:00:00 2001 From: Louis DeJardin Date: Fri, 17 Jul 2015 07:43:06 -0700 Subject: [PATCH 0180/1662] Response headers don't need to be queued before subsequent write --- src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs | 7 ++++--- src/Microsoft.AspNet.Server.Kestrel/Http/ISocketOutput.cs | 2 +- src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs | 4 ++-- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs index d34b09e03c..ad798560c8 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs @@ -250,7 +250,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http public void Write(ArraySegment data, Action callback, object state) { - ProduceStart(); + ProduceStart(immediate: false); SocketOutput.Write(data, callback, state); } @@ -293,7 +293,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } - public void ProduceStart() + public void ProduceStart(bool immediate = true) { if (_resultStarted) return; _resultStarted = true; @@ -315,7 +315,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } ((IDisposable)x).Dispose(); }, - responseHeader.Item2); + responseHeader.Item2, + immediate: immediate); } public void ProduceEnd(Exception ex) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/ISocketOutput.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/ISocketOutput.cs index 52f11f62ac..e4a57c5ebf 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/ISocketOutput.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/ISocketOutput.cs @@ -10,6 +10,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Http /// public interface ISocketOutput { - void Write(ArraySegment buffer, Action callback, object state); + void Write(ArraySegment buffer, Action callback, object state, bool immediate = true); } } \ No newline at end of file diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs index 78ab050e31..7ff695fc52 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs @@ -36,7 +36,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http _callbacksPending = new Queue(); } - public void Write(ArraySegment buffer, Action callback, object state) + public void Write(ArraySegment buffer, Action callback, object state, bool immediate) { //TODO: need buffering that works var copy = new byte[buffer.Count]; @@ -75,7 +75,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http }); } - if (_writesPending < _maxPendingWrites) + if (_writesPending < _maxPendingWrites && immediate) { ScheduleWrite(); _writesPending++; From b999b472187cd2e9eea3da6c4cf1d07d1f37bf9c Mon Sep 17 00:00:00 2001 From: Louis DeJardin Date: Fri, 17 Jul 2015 07:43:32 -0700 Subject: [PATCH 0181/1662] String concatination showed up in profiler --- .../Http/ReasonPhrases.cs | 116 +++++++++++++++++- 1 file changed, 114 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/ReasonPhrases.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/ReasonPhrases.cs index 8406449709..fe8fa6e19e 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/ReasonPhrases.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/ReasonPhrases.cs @@ -11,7 +11,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { if (string.IsNullOrEmpty(reasonPhrase)) { - reasonPhrase = ToReasonPhrase(statusCode); + return ToStatusPhrase(statusCode); } return statusCode.ToString(CultureInfo.InvariantCulture) + " " + reasonPhrase; } @@ -128,6 +128,118 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return null; } } - } + public static string ToStatusPhrase(int statusCode) + { + switch (statusCode) + { + case 100: + return "100 Continue"; + case 101: + return "101 Switching Protocols"; + case 102: + return "102 Processing"; + case 200: + return "200 OK"; + case 201: + return "201 Created"; + case 202: + return "202 Accepted"; + case 203: + return "203 Non-Authoritative Information"; + case 204: + return "204 No Content"; + case 205: + return "205 Reset Content"; + case 206: + return "206 Partial Content"; + case 207: + return "207 Multi-Status"; + case 226: + return "226 IM Used"; + case 300: + return "300 Multiple Choices"; + case 301: + return "301 Moved Permanently"; + case 302: + return "302 Found"; + case 303: + return "303 See Other"; + case 304: + return "304 Not Modified"; + case 305: + return "305 Use Proxy"; + case 306: + return "306 Reserved"; + case 307: + return "307 Temporary Redirect"; + case 400: + return "400 Bad Request"; + case 401: + return "401 Unauthorized"; + case 402: + return "402 Payment Required"; + case 403: + return "403 Forbidden"; + case 404: + return "404 Not Found"; + case 405: + return "405 Method Not Allowed"; + case 406: + return "406 Not Acceptable"; + case 407: + return "407 Proxy Authentication Required"; + case 408: + return "408 Request Timeout"; + case 409: + return "409 Conflict"; + case 410: + return "410 Gone"; + case 411: + return "411 Length Required"; + case 412: + return "412 Precondition Failed"; + case 413: + return "413 Request Entity Too Large"; + case 414: + return "414 Request-URI Too Long"; + case 415: + return "415 Unsupported Media Type"; + case 416: + return "416 Requested Range Not Satisfiable"; + case 417: + return "417 Expectation Failed"; + case 418: + return "418 I'm a Teapot"; + case 422: + return "422 Unprocessable Entity"; + case 423: + return "423 Locked"; + case 424: + return "424 Failed Dependency"; + case 426: + return "426 Upgrade Required"; + case 500: + return "500 Internal Server Error"; + case 501: + return "501 Not Implemented"; + case 502: + return "502 Bad Gateway"; + case 503: + return "503 Service Unavailable"; + case 504: + return "504 Gateway Timeout"; + case 505: + return "505 HTTP Version Not Supported"; + case 506: + return "506 Variant Also Negotiates"; + case 507: + return "507 Insufficient Storage"; + case 510: + return "510 Not Extended"; + default: + return statusCode.ToString(CultureInfo.InvariantCulture) + " Unknown"; + } + } + } } From 6ff894bb191c1c7cdbddcbc035c5b3b81bd80e54 Mon Sep 17 00:00:00 2001 From: Louis DeJardin Date: Fri, 17 Jul 2015 14:40:11 -0700 Subject: [PATCH 0182/1662] Using masked byte sequences to recognize well-known header names --- .../KnownHeaders.cs | 56 ++++++- .../project.json | 12 +- .../Http/Frame.cs | 7 +- .../Http/FrameHeaders.Generated.cs | 158 +++++++++--------- 4 files changed, 140 insertions(+), 93 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel.GeneratedCode/KnownHeaders.cs b/src/Microsoft.AspNet.Server.Kestrel.GeneratedCode/KnownHeaders.cs index 4efc96151f..da93d4df6a 100644 --- a/src/Microsoft.AspNet.Server.Kestrel.GeneratedCode/KnownHeaders.cs +++ b/src/Microsoft.AspNet.Server.Kestrel.GeneratedCode/KnownHeaders.cs @@ -23,6 +23,52 @@ namespace Microsoft.AspNet.Server.Kestrel.GeneratedCode public string TestBit() => $"((_bits & {1L << Index}L) != 0)"; public string SetBit() => $"_bits |= {1L << Index}L"; public string ClearBit() => $"_bits &= ~{1L << Index}L"; + + public string EqualIgnoreCaseBytes() + { + var result = ""; + var delim = ""; + var index = 0; + while (index != Name.Length) + { + if (Name.Length - index >= 8) + { + result += delim + Term(Name, index, 8, "pUL", "uL"); + index += 8; + } + else if (Name.Length - index >= 4) + { + result += delim + Term(Name, index, 4, "pUI", "u"); + index += 4; + } + else if (Name.Length - index >= 2) + { + result += delim + Term(Name, index, 2, "pUS", "u"); + index += 2; + } + else + { + result += delim + Term(Name, index, 1, "pUB", "u"); + index += 1; + } + delim = " && "; + } + return $"({result})"; + } + + protected string Term(string name, int offset, int count, string array, string suffix) + { + ulong mask = 0; + ulong comp = 0; + for (var scan = 0; scan != count; ++scan) + { + var ch = (byte)name[offset + count - scan - 1]; + var isAlpha = (ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z'); + comp = (comp << 8) + (ch & (isAlpha ? 0xdfu : 0xffu)); + mask = (mask << 8) + (isAlpha ? 0xdfu : 0xffu); + } + return $"(({array}[{offset / count}] & {mask}{suffix}) == {comp}{suffix})"; + } } public virtual void BeforeCompile(BeforeCompileContext context) @@ -288,13 +334,14 @@ namespace Microsoft.AspNet.Server.Kestrel.Http ((ICollection>)MaybeUnknown)?.CopyTo(array, arrayIndex); }} - public void Append(string key, string value) + public unsafe void Append(byte[] keyBytes, int keyOffset, int keyLength, string value) {{ - switch(key.Length) + fixed(byte* ptr = keyBytes) {{ var pUB = ptr + keyOffset; var pUL = (ulong*)pUB; var pUI = (uint*)pUB; var pUS = (ushort*)pUB; + switch(keyLength) {{{Each(loop.HeadersByLength, byLength => $@" case {byLength.Key}: {{{Each(byLength, header => $@" - if (""{header.Name}"".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ({header.EqualIgnoreCaseBytes()}) {{ if ({header.TestBit()}) {{ @@ -309,7 +356,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http }} ")}}} break; - ")}}} + ")}}}}} + var key = System.Text.Encoding.ASCII.GetString(keyBytes, keyOffset, keyLength); string[] existing; Unknown[key] = Unknown.TryGetValue(key, out existing) ? AppendValue(existing, value) : new[] {{value}}; }} diff --git a/src/Microsoft.AspNet.Server.Kestrel.GeneratedCode/project.json b/src/Microsoft.AspNet.Server.Kestrel.GeneratedCode/project.json index a9fe1fd9df..314b74a5e0 100644 --- a/src/Microsoft.AspNet.Server.Kestrel.GeneratedCode/project.json +++ b/src/Microsoft.AspNet.Server.Kestrel.GeneratedCode/project.json @@ -10,19 +10,15 @@ "Microsoft.Framework.Runtime.Roslyn": "1.0.0-beta6-*" }, + "commands": { + "run": "Microsoft.AspNet.Server.Kestrel.GeneratedCode" + }, + "frameworks": { "dnx451": { "frameworkAssemblies": { "System.Runtime": "4.0.10.0" } - }, - "dnxcore50": { - "dependencies": { - "System.Collections": "4.0.10-beta-*", - "System.Linq": "4.0.0-beta-*", - "System.Threading": "4.0.10-beta-*", - "Microsoft.CSharp": "4.0.0-beta-*" - } } } } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs index ad798560c8..eaeeb3ca0d 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs @@ -519,7 +519,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Http ch2 != ' ' && ch2 != '\t') { - var name = _ascii.GetString(remaining.Array, remaining.Offset, colonIndex); var value = ""; if (valueEndIndex != -1) { @@ -530,7 +529,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { value = value.Replace("\r\n", " "); } - AddRequestHeader(name, value); + AddRequestHeader(remaining.Array, remaining.Offset, colonIndex, value); baton.Skip(index + 2); return true; } @@ -565,9 +564,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return false; } - private void AddRequestHeader(string name, string value) + private void AddRequestHeader(byte[] keyBytes, int keyOffset, int keyLength, string value) { - _requestHeaders.Append(name, value); + _requestHeaders.Append(keyBytes, keyOffset, keyLength, value); } } } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameHeaders.Generated.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameHeaders.Generated.cs index 86f591b54b..8c1e497a64 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameHeaders.Generated.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameHeaders.Generated.cs @@ -3447,13 +3447,14 @@ namespace Microsoft.AspNet.Server.Kestrel.Http ((ICollection>)MaybeUnknown)?.CopyTo(array, arrayIndex); } - public void Append(string key, string value) + public unsafe void Append(byte[] keyBytes, int keyOffset, int keyLength, string value) { - switch(key.Length) + fixed(byte* ptr = keyBytes) { var pUB = ptr + keyOffset; var pUL = (ulong*)pUB; var pUI = (uint*)pUB; var pUS = (ushort*)pUB; + switch(keyLength) { case 13: { - if ("Cache-Control".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ((((pUL[0] & 16131893727263186911uL) == 5711458528024281411uL) && ((pUI[2] & 3755991007u) == 1330795598u) && ((pUB[12] & 223u) == 76u))) { if (((_bits & 1L) != 0)) { @@ -3467,7 +3468,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return; } - if ("Content-Range".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ((((pUL[0] & 18437701552104792031uL) == 3266321689424580419uL) && ((pUI[2] & 3755991007u) == 1196310866u) && ((pUB[12] & 223u) == 69u))) { if (((_bits & 131072L) != 0)) { @@ -3481,7 +3482,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return; } - if ("Last-Modified".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ((((pUL[0] & 16131858680330051551uL) == 4922237774822850892uL) && ((pUI[2] & 3755991007u) == 1162430025u) && ((pUB[12] & 223u) == 68u))) { if (((_bits & 524288L) != 0)) { @@ -3495,7 +3496,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return; } - if ("Authorization".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ((((pUL[0] & 16131858542891098079uL) == 6505821637182772545uL) && ((pUI[2] & 3755991007u) == 1330205761u) && ((pUB[12] & 223u) == 78u))) { if (((_bits & 16777216L) != 0)) { @@ -3509,7 +3510,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return; } - if ("If-None-Match".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ((((pUL[0] & 18437701552106889183uL) == 3262099607620765257uL) && ((pUI[2] & 3755991007u) == 1129595213u) && ((pUB[12] & 223u) == 72u))) { if (((_bits & 2147483648L) != 0)) { @@ -3527,7 +3528,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http case 10: { - if ("Connection".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ((((pUL[0] & 16131858542891098079uL) == 5283922227757993795uL) && ((pUS[4] & 57311u) == 20047u))) { if (((_bits & 2L) != 0)) { @@ -3541,7 +3542,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return; } - if ("Keep-Alive".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ((((pUL[0] & 16131858680330051551uL) == 5281668125874799947uL) && ((pUS[4] & 57311u) == 17750u))) { if (((_bits & 8L) != 0)) { @@ -3555,7 +3556,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return; } - if ("User-Agent".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ((((pUL[0] & 16131858680330051551uL) == 4992030374873092949uL) && ((pUS[4] & 57311u) == 21582u))) { if (((_bits & 1099511627776L) != 0)) { @@ -3573,7 +3574,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http case 4: { - if ("Date".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ((((pUI[0] & 3755991007u) == 1163149636u))) { if (((_bits & 4L) != 0)) { @@ -3587,7 +3588,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return; } - if ("From".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ((((pUI[0] & 3755991007u) == 1297044038u))) { if (((_bits & 134217728L) != 0)) { @@ -3601,7 +3602,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return; } - if ("Host".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ((((pUI[0] & 3755991007u) == 1414745928u))) { if (((_bits & 268435456L) != 0)) { @@ -3619,7 +3620,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http case 6: { - if ("Pragma".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ((((pUI[0] & 3755991007u) == 1195463248u) && ((pUS[2] & 57311u) == 16717u))) { if (((_bits & 16L) != 0)) { @@ -3633,7 +3634,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return; } - if ("Accept".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ((((pUI[0] & 3755991007u) == 1162036033u) && ((pUS[2] & 57311u) == 21584u))) { if (((_bits & 1048576L) != 0)) { @@ -3647,7 +3648,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return; } - if ("Cookie".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ((((pUI[0] & 3755991007u) == 1263488835u) && ((pUS[2] & 57311u) == 17737u))) { if (((_bits & 33554432L) != 0)) { @@ -3661,7 +3662,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return; } - if ("Expect".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ((((pUI[0] & 3755991007u) == 1162893381u) && ((pUS[2] & 57311u) == 21571u))) { if (((_bits & 67108864L) != 0)) { @@ -3679,7 +3680,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http case 7: { - if ("Trailer".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ((((pUI[0] & 3755991007u) == 1229017684u) && ((pUS[2] & 57311u) == 17740u) && ((pUB[6] & 223u) == 82u))) { if (((_bits & 32L) != 0)) { @@ -3693,7 +3694,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return; } - if ("Upgrade".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ((((pUI[0] & 3755991007u) == 1380405333u) && ((pUS[2] & 57311u) == 17473u) && ((pUB[6] & 223u) == 69u))) { if (((_bits & 128L) != 0)) { @@ -3707,7 +3708,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return; } - if ("Warning".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ((((pUI[0] & 3755991007u) == 1314013527u) && ((pUS[2] & 57311u) == 20041u) && ((pUB[6] & 223u) == 71u))) { if (((_bits & 512L) != 0)) { @@ -3721,7 +3722,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return; } - if ("Expires".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ((((pUI[0] & 3755991007u) == 1230002245u) && ((pUS[2] & 57311u) == 17746u) && ((pUB[6] & 223u) == 83u))) { if (((_bits & 262144L) != 0)) { @@ -3735,7 +3736,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return; } - if ("Referer".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ((((pUI[0] & 3755991007u) == 1162233170u) && ((pUS[2] & 57311u) == 17746u) && ((pUB[6] & 223u) == 82u))) { if (((_bits & 68719476736L) != 0)) { @@ -3753,7 +3754,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http case 17: { - if ("Transfer-Encoding".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ((((pUL[0] & 16131858542891098079uL) == 5928221808112259668uL) && ((pUL[1] & 16131858542891098111uL) == 5641115115480565037uL) && ((pUB[16] & 223u) == 71u))) { if (((_bits & 64L) != 0)) { @@ -3767,7 +3768,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return; } - if ("If-Modified-Since".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ((((pUL[0] & 16131858542893195231uL) == 5064654363342751305uL) && ((pUL[1] & 16131858543427968991uL) == 4849894470315165001uL) && ((pUB[16] & 223u) == 69u))) { if (((_bits & 1073741824L) != 0)) { @@ -3785,7 +3786,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http case 3: { - if ("Via".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ((((pUS[0] & 57311u) == 18774u) && ((pUB[2] & 223u) == 65u))) { if (((_bits & 256L) != 0)) { @@ -3803,7 +3804,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http case 5: { - if ("Allow".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ((((pUI[0] & 3755991007u) == 1330400321u) && ((pUB[4] & 223u) == 87u))) { if (((_bits & 1024L) != 0)) { @@ -3817,7 +3818,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return; } - if ("Range".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ((((pUI[0] & 3755991007u) == 1196310866u) && ((pUB[4] & 223u) == 69u))) { if (((_bits & 137438953472L) != 0)) { @@ -3835,7 +3836,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http case 14: { - if ("Content-Length".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ((((pUL[0] & 18437701552104792031uL) == 3266321689424580419uL) && ((pUI[2] & 3755991007u) == 1196311884u) && ((pUS[6] & 57311u) == 18516u))) { if (((_bits & 2048L) != 0)) { @@ -3849,7 +3850,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return; } - if ("Accept-Charset".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ((((pUL[0] & 16140865742145839071uL) == 4840617878229304129uL) && ((pUI[2] & 3755991007u) == 1397899592u) && ((pUS[6] & 57311u) == 21573u))) { if (((_bits & 2097152L) != 0)) { @@ -3867,7 +3868,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http case 12: { - if ("Content-Type".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ((((pUL[0] & 18437701552104792031uL) == 3266321689424580419uL) && ((pUI[2] & 3755991007u) == 1162893652u))) { if (((_bits & 4096L) != 0)) { @@ -3881,7 +3882,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return; } - if ("Max-Forwards".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ((((pUL[0] & 16131858543427968991uL) == 6292178792217067853uL) && ((pUI[2] & 3755991007u) == 1396986433u))) { if (((_bits & 17179869184L) != 0)) { @@ -3899,7 +3900,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http case 16: { - if ("Content-Encoding".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ((((pUL[0] & 18437701552104792031uL) == 3266321689424580419uL) && ((pUL[1] & 16131858542891098079uL) == 5138124782612729413uL))) { if (((_bits & 8192L) != 0)) { @@ -3913,7 +3914,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return; } - if ("Content-Language".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ((((pUL[0] & 18437701552104792031uL) == 3266321689424580419uL) && ((pUL[1] & 16131858542891098079uL) == 4992030546487820620uL))) { if (((_bits & 16384L) != 0)) { @@ -3927,7 +3928,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return; } - if ("Content-Location".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ((((pUL[0] & 18437701552104792031uL) == 3266321689424580419uL) && ((pUL[1] & 16131858542891098079uL) == 5642809484339531596uL))) { if (((_bits & 32768L) != 0)) { @@ -3945,7 +3946,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http case 11: { - if ("Content-MD5".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ((((pUL[0] & 18437701552104792031uL) == 3266321689424580419uL) && ((pUS[4] & 57311u) == 17485u) && ((pUB[10] & 255u) == 53u))) { if (((_bits & 65536L) != 0)) { @@ -3963,7 +3964,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http case 15: { - if ("Accept-Encoding".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ((((pUL[0] & 16140865742145839071uL) == 4984733066305160001uL) && ((pUI[2] & 3755991007u) == 1146045262u) && ((pUS[6] & 57311u) == 20041u) && ((pUB[14] & 223u) == 71u))) { if (((_bits & 4194304L) != 0)) { @@ -3977,7 +3978,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return; } - if ("Accept-Language".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ((((pUL[0] & 16140865742145839071uL) == 5489136224570655553uL) && ((pUI[2] & 3755991007u) == 1430736449u) && ((pUS[6] & 57311u) == 18241u) && ((pUB[14] & 223u) == 69u))) { if (((_bits & 8388608L) != 0)) { @@ -3995,7 +3996,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http case 8: { - if ("If-Match".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ((((pUL[0] & 16131858542893195231uL) == 5207098233614845513uL))) { if (((_bits & 536870912L) != 0)) { @@ -4009,7 +4010,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return; } - if ("If-Range".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ((((pUL[0] & 16131858542893195231uL) == 4992044754422023753uL))) { if (((_bits & 4294967296L) != 0)) { @@ -4027,7 +4028,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http case 19: { - if ("If-Unmodified-Since".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ((((pUL[0] & 16131858542893195231uL) == 4922237916571059785uL) && ((pUL[1] & 16131893727263186911uL) == 5283616559079179849uL) && ((pUS[8] & 57311u) == 17230u) && ((pUB[18] & 223u) == 69u))) { if (((_bits & 8589934592L) != 0)) { @@ -4041,7 +4042,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return; } - if ("Proxy-Authorization".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ((((pUL[0] & 16131893727263186911uL) == 6143241228466999888uL) && ((pUL[1] & 16131858542891098079uL) == 6071233043632179284uL) && ((pUS[8] & 57311u) == 20297u) && ((pUB[18] & 223u) == 78u))) { if (((_bits & 34359738368L) != 0)) { @@ -4059,7 +4060,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http case 2: { - if ("TE".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ((((pUS[0] & 57311u) == 17748u))) { if (((_bits & 274877906944L) != 0)) { @@ -4077,7 +4078,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http case 9: { - if ("Translate".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ((((pUL[0] & 16131858542891098079uL) == 6071217693351039572uL) && ((pUB[8] & 223u) == 69u))) { if (((_bits & 549755813888L) != 0)) { @@ -4092,7 +4093,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } break; - } + }} + var key = System.Text.Encoding.ASCII.GetString(keyBytes, keyOffset, keyLength); string[] existing; Unknown[key] = Unknown.TryGetValue(key, out existing) ? AppendValue(existing, value) : new[] {value}; } @@ -7120,13 +7122,14 @@ namespace Microsoft.AspNet.Server.Kestrel.Http ((ICollection>)MaybeUnknown)?.CopyTo(array, arrayIndex); } - public void Append(string key, string value) + public unsafe void Append(byte[] keyBytes, int keyOffset, int keyLength, string value) { - switch(key.Length) + fixed(byte* ptr = keyBytes) { var pUB = ptr + keyOffset; var pUL = (ulong*)pUB; var pUI = (uint*)pUB; var pUS = (ushort*)pUB; + switch(keyLength) { case 13: { - if ("Cache-Control".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ((((pUL[0] & 16131893727263186911uL) == 5711458528024281411uL) && ((pUI[2] & 3755991007u) == 1330795598u) && ((pUB[12] & 223u) == 76u))) { if (((_bits & 1L) != 0)) { @@ -7140,7 +7143,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return; } - if ("Content-Range".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ((((pUL[0] & 18437701552104792031uL) == 3266321689424580419uL) && ((pUI[2] & 3755991007u) == 1196310866u) && ((pUB[12] & 223u) == 69u))) { if (((_bits & 131072L) != 0)) { @@ -7154,7 +7157,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return; } - if ("Last-Modified".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ((((pUL[0] & 16131858680330051551uL) == 4922237774822850892uL) && ((pUI[2] & 3755991007u) == 1162430025u) && ((pUB[12] & 223u) == 68u))) { if (((_bits & 524288L) != 0)) { @@ -7168,7 +7171,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return; } - if ("Accept-Ranges".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ((((pUL[0] & 16140865742145839071uL) == 5921481788798223169uL) && ((pUI[2] & 3755991007u) == 1162300993u) && ((pUB[12] & 223u) == 83u))) { if (((_bits & 1048576L) != 0)) { @@ -7186,7 +7189,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http case 10: { - if ("Connection".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ((((pUL[0] & 16131858542891098079uL) == 5283922227757993795uL) && ((pUS[4] & 57311u) == 20047u))) { if (((_bits & 2L) != 0)) { @@ -7200,7 +7203,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return; } - if ("Keep-Alive".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ((((pUL[0] & 16131858680330051551uL) == 5281668125874799947uL) && ((pUS[4] & 57311u) == 17750u))) { if (((_bits & 8L) != 0)) { @@ -7214,7 +7217,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return; } - if ("Set-Cookie".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ((((pUL[0] & 16131858543427968991uL) == 5426643225946637651uL) && ((pUS[4] & 57311u) == 17737u))) { if (((_bits & 134217728L) != 0)) { @@ -7232,7 +7235,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http case 4: { - if ("Date".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ((((pUI[0] & 3755991007u) == 1163149636u))) { if (((_bits & 4L) != 0)) { @@ -7246,7 +7249,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return; } - if ("ETag".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ((((pUI[0] & 3755991007u) == 1195463749u))) { if (((_bits & 4194304L) != 0)) { @@ -7260,7 +7263,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return; } - if ("Vary".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ((((pUI[0] & 3755991007u) == 1498562902u))) { if (((_bits & 268435456L) != 0)) { @@ -7278,7 +7281,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http case 6: { - if ("Pragma".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ((((pUI[0] & 3755991007u) == 1195463248u) && ((pUS[2] & 57311u) == 16717u))) { if (((_bits & 16L) != 0)) { @@ -7292,7 +7295,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return; } - if ("Server".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ((((pUI[0] & 3755991007u) == 1448232275u) && ((pUS[2] & 57311u) == 21061u))) { if (((_bits & 67108864L) != 0)) { @@ -7310,7 +7313,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http case 7: { - if ("Trailer".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ((((pUI[0] & 3755991007u) == 1229017684u) && ((pUS[2] & 57311u) == 17740u) && ((pUB[6] & 223u) == 82u))) { if (((_bits & 32L) != 0)) { @@ -7324,7 +7327,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return; } - if ("Upgrade".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ((((pUI[0] & 3755991007u) == 1380405333u) && ((pUS[2] & 57311u) == 17473u) && ((pUB[6] & 223u) == 69u))) { if (((_bits & 128L) != 0)) { @@ -7338,7 +7341,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return; } - if ("Warning".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ((((pUI[0] & 3755991007u) == 1314013527u) && ((pUS[2] & 57311u) == 20041u) && ((pUB[6] & 223u) == 71u))) { if (((_bits & 512L) != 0)) { @@ -7352,7 +7355,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return; } - if ("Expires".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ((((pUI[0] & 3755991007u) == 1230002245u) && ((pUS[2] & 57311u) == 17746u) && ((pUB[6] & 223u) == 83u))) { if (((_bits & 262144L) != 0)) { @@ -7370,7 +7373,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http case 17: { - if ("Transfer-Encoding".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ((((pUL[0] & 16131858542891098079uL) == 5928221808112259668uL) && ((pUL[1] & 16131858542891098111uL) == 5641115115480565037uL) && ((pUB[16] & 223u) == 71u))) { if (((_bits & 64L) != 0)) { @@ -7384,7 +7387,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return; } - if ("Proxy-Autheticate".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ((((pUL[0] & 16131893727263186911uL) == 6143241228466999888uL) && ((pUL[1] & 16131858542891098079uL) == 6071207754897639508uL) && ((pUB[16] & 223u) == 69u))) { if (((_bits & 16777216L) != 0)) { @@ -7402,7 +7405,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http case 3: { - if ("Via".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ((((pUS[0] & 57311u) == 18774u) && ((pUB[2] & 223u) == 65u))) { if (((_bits & 256L) != 0)) { @@ -7416,7 +7419,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return; } - if ("Age".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ((((pUS[0] & 57311u) == 18241u) && ((pUB[2] & 223u) == 69u))) { if (((_bits & 2097152L) != 0)) { @@ -7434,7 +7437,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http case 5: { - if ("Allow".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ((((pUI[0] & 3755991007u) == 1330400321u) && ((pUB[4] & 223u) == 87u))) { if (((_bits & 1024L) != 0)) { @@ -7452,7 +7455,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http case 14: { - if ("Content-Length".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ((((pUL[0] & 18437701552104792031uL) == 3266321689424580419uL) && ((pUI[2] & 3755991007u) == 1196311884u) && ((pUS[6] & 57311u) == 18516u))) { if (((_bits & 2048L) != 0)) { @@ -7470,7 +7473,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http case 12: { - if ("Content-Type".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ((((pUL[0] & 18437701552104792031uL) == 3266321689424580419uL) && ((pUI[2] & 3755991007u) == 1162893652u))) { if (((_bits & 4096L) != 0)) { @@ -7488,7 +7491,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http case 16: { - if ("Content-Encoding".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ((((pUL[0] & 18437701552104792031uL) == 3266321689424580419uL) && ((pUL[1] & 16131858542891098079uL) == 5138124782612729413uL))) { if (((_bits & 8192L) != 0)) { @@ -7502,7 +7505,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return; } - if ("Content-Language".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ((((pUL[0] & 18437701552104792031uL) == 3266321689424580419uL) && ((pUL[1] & 16131858542891098079uL) == 4992030546487820620uL))) { if (((_bits & 16384L) != 0)) { @@ -7516,7 +7519,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return; } - if ("Content-Location".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ((((pUL[0] & 18437701552104792031uL) == 3266321689424580419uL) && ((pUL[1] & 16131858542891098079uL) == 5642809484339531596uL))) { if (((_bits & 32768L) != 0)) { @@ -7530,7 +7533,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return; } - if ("WWW-Authenticate".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ((((pUL[0] & 16131858543427968991uL) == 5211884407196440407uL) && ((pUL[1] & 16131858542891098079uL) == 4995689643909598789uL))) { if (((_bits & 536870912L) != 0)) { @@ -7548,7 +7551,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http case 11: { - if ("Content-MD5".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ((((pUL[0] & 18437701552104792031uL) == 3266321689424580419uL) && ((pUS[4] & 57311u) == 17485u) && ((pUB[10] & 255u) == 53u))) { if (((_bits & 65536L) != 0)) { @@ -7562,7 +7565,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return; } - if ("Retry-After".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ((((pUL[0] & 16131893727263186911uL) == 5062377317797741906uL) && ((pUS[4] & 57311u) == 17748u) && ((pUB[10] & 223u) == 82u))) { if (((_bits & 33554432L) != 0)) { @@ -7580,7 +7583,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http case 8: { - if ("Location".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ((((pUL[0] & 16131858542891098079uL) == 5642809484339531596uL))) { if (((_bits & 8388608L) != 0)) { @@ -7595,7 +7598,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } break; - } + }} + var key = System.Text.Encoding.ASCII.GetString(keyBytes, keyOffset, keyLength); string[] existing; Unknown[key] = Unknown.TryGetValue(key, out existing) ? AppendValue(existing, value) : new[] {value}; } From 7446fe4cc7bcfdf210376a972d31cd160f782c58 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Wed, 29 Jul 2015 20:03:04 -0700 Subject: [PATCH 0183/1662] Update SocketOutputTests to account for the "immediate" Write param --- src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs | 2 +- .../SocketOutputTests.cs | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs index 7ff695fc52..c48cb87ed1 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs @@ -36,7 +36,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http _callbacksPending = new Queue(); } - public void Write(ArraySegment buffer, Action callback, object state, bool immediate) + public void Write(ArraySegment buffer, Action callback, object state, bool immediate = true) { //TODO: need buffering that works var copy = new byte[buffer.Count]; diff --git a/test/Microsoft.AspNet.Server.KestrelTests/SocketOutputTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/SocketOutputTests.cs index bb95a96507..072feecc4f 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/SocketOutputTests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/SocketOutputTests.cs @@ -51,7 +51,7 @@ namespace Microsoft.AspNet.Server.KestrelTests }; // Act - socketOutput.Write(buffer, onCompleted, state: null); + socketOutput.Write(buffer, onCompleted, null); // Assert Assert.True(completedWh.Wait(100)); @@ -94,14 +94,14 @@ namespace Microsoft.AspNet.Server.KestrelTests }; // Act - socketOutput.Write(buffer, onCompleted, state: null); + socketOutput.Write(buffer, onCompleted, null); // Assert // The first write should pre-complete since it is <= _maxBytesPreCompleted. Assert.True(completedWh.Wait(100)); // Arrange completedWh.Reset(); // Act - socketOutput.Write(buffer, onCompleted, state: null); + socketOutput.Write(buffer, onCompleted, null); // Assert // Too many bytes are already pre-completed for the second write to pre-complete. Assert.False(completedWh.Wait(100)); From 978dd3992411a87dcf2d2519b8c5a643334b0b2b Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Thu, 30 Jul 2015 11:52:34 -0700 Subject: [PATCH 0184/1662] Update the prepare script used to generate code - The syntax to run dnx with a modified appbase has recently changed --- src/Microsoft.AspNet.Server.Kestrel/project.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/project.json b/src/Microsoft.AspNet.Server.Kestrel/project.json index c94eea129a..1b416d8fe3 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/project.json +++ b/src/Microsoft.AspNet.Server.Kestrel/project.json @@ -34,6 +34,6 @@ "allowUnsafe": true }, "scripts": { - "prepare": "dnx ../Microsoft.AspNet.Server.Kestrel.GeneratedCode run Http/FrameHeaders.Generated.cs" + "prepare": "dnx --appbase ../Microsoft.AspNet.Server.Kestrel.GeneratedCode Microsoft.Dnx.ApplicationHost run Http/FrameHeaders.Generated.cs" } } From e5144e31396fce3d092f3a97ead4a4769488a9df Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Thu, 30 Jul 2015 20:46:02 -0700 Subject: [PATCH 0185/1662] Include Server and Date in the initial response header dictionary --- .../KnownHeaders.cs | 15 +++++- .../Http/Frame.cs | 2 +- .../Http/FrameHeaders.Generated.cs | 10 ++++ .../EngineTests.cs | 15 +++++- .../FrameResponseHeadersTests.cs | 47 +++++++++++++++++++ .../TestConnection.cs | 32 +++++++++++++ 6 files changed, 118 insertions(+), 3 deletions(-) create mode 100644 test/Microsoft.AspNet.Server.KestrelTests/FrameResponseHeadersTests.cs diff --git a/src/Microsoft.AspNet.Server.Kestrel.GeneratedCode/KnownHeaders.cs b/src/Microsoft.AspNet.Server.Kestrel.GeneratedCode/KnownHeaders.cs index da93d4df6a..8fd6913052 100644 --- a/src/Microsoft.AspNet.Server.Kestrel.GeneratedCode/KnownHeaders.cs +++ b/src/Microsoft.AspNet.Server.Kestrel.GeneratedCode/KnownHeaders.cs @@ -170,7 +170,20 @@ using System; using System.Collections.Generic; namespace Microsoft.AspNet.Server.Kestrel.Http -{{{Each(loops, loop => $@" +{{ + public partial class FrameResponseHeaders + {{ + public FrameResponseHeaders() + {{ + _Server = new[] {{ ""Kestrel"" }}; + _Date = new[] {{ DateTime.UtcNow.ToString(""r"") }}; + _bits = { + 1L << responseHeaders.First(header => header.Name == "Server").Index | + 1L << responseHeaders.First(header => header.Name == "Date").Index + }L; + }} + }} +{Each(loops, loop => $@" public partial class {loop.ClassName} {{ long _bits = 0; diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs index eaeeb3ca0d..4faca625a3 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs @@ -338,7 +338,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http // the app func has failed. https://github.com/aspnet/KestrelHttpServer/issues/43 _onStarting = null; - ResponseHeaders.Clear(); + ResponseHeaders = new FrameResponseHeaders(); ResponseHeaders["Content-Length"] = new[] { "0" }; } } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameHeaders.Generated.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameHeaders.Generated.cs index 8c1e497a64..686527fadc 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameHeaders.Generated.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameHeaders.Generated.cs @@ -4,6 +4,16 @@ using System.Collections.Generic; namespace Microsoft.AspNet.Server.Kestrel.Http { + public partial class FrameResponseHeaders + { + public FrameResponseHeaders() + { + _Server = new[] { "Kestrel" }; + _Date = new[] { DateTime.UtcNow.ToString("r") }; + _bits = 67108868L; + } + } + public partial class FrameRequestHeaders { long _bits = 0; diff --git a/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs index b8f0a95a14..99fe1b4140 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs @@ -22,6 +22,7 @@ namespace Microsoft.AspNet.Server.KestrelTests { private async Task App(Frame frame) { + frame.ResponseHeaders.Clear(); for (; ;) { var buffer = new byte[8192]; @@ -59,6 +60,7 @@ namespace Microsoft.AspNet.Server.KestrelTests private async Task AppChunked(Frame frame) { + frame.ResponseHeaders.Clear(); var data = new MemoryStream(); for (; ;) { @@ -358,6 +360,7 @@ namespace Microsoft.AspNet.Server.KestrelTests }, null); // Anything added to the ResponseHeaders dictionary is ignored + frame.ResponseHeaders.Clear(); frame.ResponseHeaders["Content-Length"] = new[] { "11" }; throw new Exception(); })) @@ -371,12 +374,20 @@ namespace Microsoft.AspNet.Server.KestrelTests "Connection: close", "", ""); - await connection.ReceiveEnd( + await connection.Receive( "HTTP/1.1 500 Internal Server Error", + ""); + await connection.ReceiveStartsWith("Date:"); + await connection.Receive( "Content-Length: 0", + "Server: Kestrel", "", "HTTP/1.1 500 Internal Server Error", + ""); + await connection.ReceiveStartsWith("Date:"); + await connection.ReceiveEnd( "Content-Length: 0", + "Server: Kestrel", "Connection: close", "", ""); @@ -399,6 +410,7 @@ namespace Microsoft.AspNet.Server.KestrelTests return Task.FromResult(null); }, null); + frame.ResponseHeaders.Clear(); frame.ResponseHeaders["Content-Length"] = new[] { "11" }; await frame.ResponseBody.WriteAsync(Encoding.ASCII.GetBytes("Hello World"), 0, 11); throw new Exception(); @@ -434,6 +446,7 @@ namespace Microsoft.AspNet.Server.KestrelTests return Task.FromResult(null); }, null); + frame.ResponseHeaders.Clear(); frame.ResponseHeaders["Content-Length"] = new[] { "11" }; await frame.ResponseBody.WriteAsync(Encoding.ASCII.GetBytes("Hello"), 0, 5); throw new Exception(); diff --git a/test/Microsoft.AspNet.Server.KestrelTests/FrameResponseHeadersTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/FrameResponseHeadersTests.cs new file mode 100644 index 0000000000..49e573c730 --- /dev/null +++ b/test/Microsoft.AspNet.Server.KestrelTests/FrameResponseHeadersTests.cs @@ -0,0 +1,47 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Collections.Generic; +using Microsoft.AspNet.Server.Kestrel.Http; +using Xunit; + +namespace Microsoft.AspNet.Server.KestrelTests +{ + public class FrameResponseHeadersTests + { + [Fact] + public void InitialDictionaryContainsServerAndDate() + { + IDictionary headers = new FrameResponseHeaders(); + + Assert.Equal(2, headers.Count); + + string[] serverHeader; + Assert.True(headers.TryGetValue("Server", out serverHeader)); + Assert.Equal(1, serverHeader.Length); + Assert.Equal("Kestrel", serverHeader[0]); + + string[] dateHeader; + DateTime date; + Assert.True(headers.TryGetValue("Date", out dateHeader)); + Assert.Equal(1, dateHeader.Length); + Assert.True(DateTime.TryParse(dateHeader[0], out date)); + Assert.True(DateTime.Now - date <= TimeSpan.FromMinutes(1)); + + Assert.False(headers.IsReadOnly); + } + + [Fact] + public void InitialEntriesCanBeCleared() + { + IDictionary headers = new FrameResponseHeaders(); + + headers.Clear(); + + Assert.Equal(0, headers.Count); + Assert.False(headers.ContainsKey("Server")); + Assert.False(headers.ContainsKey("Date")); + } + } +} diff --git a/test/Microsoft.AspNet.Server.KestrelTests/TestConnection.cs b/test/Microsoft.AspNet.Server.KestrelTests/TestConnection.cs index 085589beb0..4afd1628d9 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/TestConnection.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/TestConnection.cs @@ -84,6 +84,38 @@ namespace Microsoft.AspNet.Server.KestrelTests Assert.Equal(expected, new String(actual, 0, offset)); } + public async Task ReceiveStartsWith(string prefix, int maxLineLength = 1024) + { + var actual = new char[maxLineLength]; + var offset = 0; + + while (offset < maxLineLength) + { + // Read one char at a time so we don't read past the end of the line. + var task = _reader.ReadAsync(actual, offset, 1); + if (!Debugger.IsAttached) + { + Assert.True(task.Wait(1000), "timeout"); + } + var count = await task; + if (count == 0) + { + break; + } + + Assert.True(count == 1); + offset++; + + if (actual[offset - 1] == '\n') + { + break; + } + } + + var actualLine = new string(actual, 0, offset); + Assert.StartsWith(prefix, actualLine); + } + public async Task ReceiveEnd(params string[] lines) { await Receive(lines); From b8f930bb4c7673a55b6544c37ae90bba86776aae Mon Sep 17 00:00:00 2001 From: Troy Dai Date: Tue, 4 Aug 2015 10:15:28 -0700 Subject: [PATCH 0186/1662] Update CoreCLR versions --- src/Kestrel/project.json | 2 +- .../project.json | 24 +++++++++---------- .../project.json | 4 ++-- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/Kestrel/project.json b/src/Kestrel/project.json index eb2037ca21..1187eba23c 100644 --- a/src/Kestrel/project.json +++ b/src/Kestrel/project.json @@ -15,7 +15,7 @@ }, "dnxcore50": { "dependencies": { - "System.Runtime": "4.0.20-beta-*" + "System.Runtime": "4.0.21-beta-*" } } } diff --git a/src/Microsoft.AspNet.Server.Kestrel/project.json b/src/Microsoft.AspNet.Server.Kestrel/project.json index 1b416d8fe3..d363b2770d 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/project.json +++ b/src/Microsoft.AspNet.Server.Kestrel/project.json @@ -12,19 +12,19 @@ "dnx451": { }, "dnxcore50": { "dependencies": { - "System.Collections": "4.0.10-beta-*", - "System.Diagnostics.Debug": "4.0.10-beta-*", + "System.Collections": "4.0.11-beta-*", + "System.Diagnostics.Debug": "4.0.11-beta-*", "System.Diagnostics.TraceSource": "4.0.0-beta-*", - "System.Diagnostics.Tracing": "4.0.20-beta-*", - "System.Globalization": "4.0.10-beta-*", - "System.IO": "4.0.10-beta-*", - "System.Linq": "4.0.0-beta-*", - "System.Net.Primitives": "4.0.10-beta-*", - "System.Runtime.Extensions": "4.0.10-beta-*", - "System.Runtime.InteropServices": "4.0.20-beta-*", - "System.Text.Encoding": "4.0.10-beta-*", - "System.Threading": "4.0.10-beta-*", - "System.Threading.Tasks": "4.0.10-beta-*", + "System.Diagnostics.Tracing": "4.0.21-beta-*", + "System.Globalization": "4.0.11-beta-*", + "System.IO": "4.0.11-beta-*", + "System.Linq": "4.0.1-beta-*", + "System.Net.Primitives": "4.0.11-beta-*", + "System.Runtime.Extensions": "4.0.11-beta-*", + "System.Runtime.InteropServices": "4.0.21-beta-*", + "System.Text.Encoding": "4.0.11-beta-*", + "System.Threading": "4.0.11-beta-*", + "System.Threading.Tasks": "4.0.11-beta-*", "System.Threading.Thread": "4.0.0-beta-*", "System.Threading.ThreadPool": "4.0.10-beta-*" } diff --git a/test/Microsoft.AspNet.Server.KestrelTests/project.json b/test/Microsoft.AspNet.Server.KestrelTests/project.json index ad74555390..cd48e8c2ca 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/project.json +++ b/test/Microsoft.AspNet.Server.KestrelTests/project.json @@ -9,8 +9,8 @@ "dnxcore50": { "dependencies": { "System.Net.Sockets": "4.0.10-beta-*", - "System.Runtime.Handles": "4.0.0-beta-*", - "System.IO": "4.0.10-beta-*" + "System.Runtime.Handles": "4.0.1-beta-*", + "System.IO": "4.0.11-beta-*" } } }, From 51693304c1c57a586a42f939af50f0d10e60b2b3 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Wed, 5 Aug 2015 10:32:53 -0700 Subject: [PATCH 0187/1662] Update dependencies after rename to Microsoft.Dnx.Compilation.CSharp --- NuGet.Config | 2 ++ .../KnownHeaders.cs | 5 ++--- .../project.json | 6 ++++-- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/NuGet.Config b/NuGet.Config index da57d47267..8b143c324c 100644 --- a/NuGet.Config +++ b/NuGet.Config @@ -2,6 +2,8 @@ + + \ No newline at end of file diff --git a/src/Microsoft.AspNet.Server.Kestrel.GeneratedCode/KnownHeaders.cs b/src/Microsoft.AspNet.Server.Kestrel.GeneratedCode/KnownHeaders.cs index 8fd6913052..7d02efa2ba 100644 --- a/src/Microsoft.AspNet.Server.Kestrel.GeneratedCode/KnownHeaders.cs +++ b/src/Microsoft.AspNet.Server.Kestrel.GeneratedCode/KnownHeaders.cs @@ -1,8 +1,7 @@ -using Microsoft.Framework.Runtime.Roslyn; -using System; +using System; using System.Collections.Generic; using System.Linq; -using System.Threading.Tasks; +using Microsoft.Dnx.Compilation.CSharp; namespace Microsoft.AspNet.Server.Kestrel.GeneratedCode { diff --git a/src/Microsoft.AspNet.Server.Kestrel.GeneratedCode/project.json b/src/Microsoft.AspNet.Server.Kestrel.GeneratedCode/project.json index 314b74a5e0..c7dba6b155 100644 --- a/src/Microsoft.AspNet.Server.Kestrel.GeneratedCode/project.json +++ b/src/Microsoft.AspNet.Server.Kestrel.GeneratedCode/project.json @@ -7,7 +7,7 @@ "licenseUrl": "", "dependencies": { - "Microsoft.Framework.Runtime.Roslyn": "1.0.0-beta6-*" + "Microsoft.Dnx.Compilation.CSharp.Abstractions": "1.0.0-*" }, "commands": { @@ -17,7 +17,9 @@ "frameworks": { "dnx451": { "frameworkAssemblies": { - "System.Runtime": "4.0.10.0" + "System.Runtime": "4.0.10.0", + "System.Text.Encoding": "4.0.0.0", + "System.Threading.Tasks": "4.0.0.0" } } } From 7dd256f26ef4de55fca5c4ea25f678014a6fec9f Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Wed, 5 Aug 2015 11:32:39 -0700 Subject: [PATCH 0188/1662] Add a "dnu restore" prepare step before generating code - This ensures the generated code project's project.lock.json is created --- .../project.json | 6 +++--- src/Microsoft.AspNet.Server.Kestrel/project.json | 5 ++++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel.GeneratedCode/project.json b/src/Microsoft.AspNet.Server.Kestrel.GeneratedCode/project.json index c7dba6b155..31f0818def 100644 --- a/src/Microsoft.AspNet.Server.Kestrel.GeneratedCode/project.json +++ b/src/Microsoft.AspNet.Server.Kestrel.GeneratedCode/project.json @@ -17,9 +17,9 @@ "frameworks": { "dnx451": { "frameworkAssemblies": { - "System.Runtime": "4.0.10.0", - "System.Text.Encoding": "4.0.0.0", - "System.Threading.Tasks": "4.0.0.0" + "System.Runtime": "4.0.10.0", + "System.Text.Encoding": "4.0.0.0", + "System.Threading.Tasks": "4.0.0.0" } } } diff --git a/src/Microsoft.AspNet.Server.Kestrel/project.json b/src/Microsoft.AspNet.Server.Kestrel/project.json index d363b2770d..067079aaec 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/project.json +++ b/src/Microsoft.AspNet.Server.Kestrel/project.json @@ -34,6 +34,9 @@ "allowUnsafe": true }, "scripts": { - "prepare": "dnx --appbase ../Microsoft.AspNet.Server.Kestrel.GeneratedCode Microsoft.Dnx.ApplicationHost run Http/FrameHeaders.Generated.cs" + "prepare": [ + "dnu restore ../Microsoft.AspNet.Server.Kestrel.GeneratedCode", + "dnx --appbase ../Microsoft.AspNet.Server.Kestrel.GeneratedCode Microsoft.Dnx.ApplicationHost run Http/FrameHeaders.Generated.cs" + ] } } From 5dfca955b3400c1d0149c05596ed4c525bb79cfd Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Wed, 5 Aug 2015 12:12:39 -0700 Subject: [PATCH 0189/1662] Move GeneratedCode project so no NuGet package gets created --- KestrelHttpServer.sln | 7 +++++-- src/Microsoft.AspNet.Server.Kestrel/project.json | 4 ++-- .../KnownHeaders.cs | 0 .../Microsoft.AspNet.Server.Kestrel.GeneratedCode.xproj | 0 .../Program.cs | 0 .../project.json | 5 ----- 6 files changed, 7 insertions(+), 9 deletions(-) rename {src => tools}/Microsoft.AspNet.Server.Kestrel.GeneratedCode/KnownHeaders.cs (100%) rename {src => tools}/Microsoft.AspNet.Server.Kestrel.GeneratedCode/Microsoft.AspNet.Server.Kestrel.GeneratedCode.xproj (100%) rename {src => tools}/Microsoft.AspNet.Server.Kestrel.GeneratedCode/Program.cs (100%) rename {src => tools}/Microsoft.AspNet.Server.Kestrel.GeneratedCode/project.json (81%) diff --git a/KestrelHttpServer.sln b/KestrelHttpServer.sln index 207aa84895..4758d52998 100644 --- a/KestrelHttpServer.sln +++ b/KestrelHttpServer.sln @@ -26,7 +26,10 @@ EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "samples", "samples", "{8A3D00B8-1CCF-4BE6-A060-11104CE2D9CE}" EndProject Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "LargeResponseApp", "samples\LargeResponseApp\LargeResponseApp.xproj", "{B35D4D31-E74C-4646-8A11-7A7A40F0021E}" -Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.Server.Kestrel.GeneratedCode", "src\Microsoft.AspNet.Server.Kestrel.GeneratedCode\Microsoft.AspNet.Server.Kestrel.GeneratedCode.xproj", "{BD2D4D29-1BD9-40D0-BB31-337D5416B63C}" +EndProject +Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.Server.Kestrel.GeneratedCode", "tools\Microsoft.AspNet.Server.Kestrel.GeneratedCode\Microsoft.AspNet.Server.Kestrel.GeneratedCode.xproj", "{BD2D4D29-1BD9-40D0-BB31-337D5416B63C}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tools", "tools", "{327F7880-D9AF-46BD-B45C-3B7E34A01DFD}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -68,6 +71,6 @@ Global {2C3CB3DC-EEBF-4F52-9E1C-4F2F972E76C3} = {8A3D00B8-1CCF-4BE6-A060-11104CE2D9CE} {30B7617E-58EF-4382-B3EA-5B2E718CF1A6} = {2D5D5227-4DBD-499A-96B1-76A36B03B750} {B35D4D31-E74C-4646-8A11-7A7A40F0021E} = {8A3D00B8-1CCF-4BE6-A060-11104CE2D9CE} - {BD2D4D29-1BD9-40D0-BB31-337D5416B63C} = {2D5D5227-4DBD-499A-96B1-76A36B03B750} + {BD2D4D29-1BD9-40D0-BB31-337D5416B63C} = {327F7880-D9AF-46BD-B45C-3B7E34A01DFD} EndGlobalSection EndGlobal diff --git a/src/Microsoft.AspNet.Server.Kestrel/project.json b/src/Microsoft.AspNet.Server.Kestrel/project.json index 067079aaec..2a36031520 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/project.json +++ b/src/Microsoft.AspNet.Server.Kestrel/project.json @@ -35,8 +35,8 @@ }, "scripts": { "prepare": [ - "dnu restore ../Microsoft.AspNet.Server.Kestrel.GeneratedCode", - "dnx --appbase ../Microsoft.AspNet.Server.Kestrel.GeneratedCode Microsoft.Dnx.ApplicationHost run Http/FrameHeaders.Generated.cs" + "dnu restore ../../tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode", + "dnx --appbase ../../tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode Microsoft.Dnx.ApplicationHost run Http/FrameHeaders.Generated.cs" ] } } diff --git a/src/Microsoft.AspNet.Server.Kestrel.GeneratedCode/KnownHeaders.cs b/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/KnownHeaders.cs similarity index 100% rename from src/Microsoft.AspNet.Server.Kestrel.GeneratedCode/KnownHeaders.cs rename to tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/KnownHeaders.cs diff --git a/src/Microsoft.AspNet.Server.Kestrel.GeneratedCode/Microsoft.AspNet.Server.Kestrel.GeneratedCode.xproj b/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/Microsoft.AspNet.Server.Kestrel.GeneratedCode.xproj similarity index 100% rename from src/Microsoft.AspNet.Server.Kestrel.GeneratedCode/Microsoft.AspNet.Server.Kestrel.GeneratedCode.xproj rename to tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/Microsoft.AspNet.Server.Kestrel.GeneratedCode.xproj diff --git a/src/Microsoft.AspNet.Server.Kestrel.GeneratedCode/Program.cs b/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/Program.cs similarity index 100% rename from src/Microsoft.AspNet.Server.Kestrel.GeneratedCode/Program.cs rename to tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/Program.cs diff --git a/src/Microsoft.AspNet.Server.Kestrel.GeneratedCode/project.json b/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/project.json similarity index 81% rename from src/Microsoft.AspNet.Server.Kestrel.GeneratedCode/project.json rename to tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/project.json index 31f0818def..bfcbc212b3 100644 --- a/src/Microsoft.AspNet.Server.Kestrel.GeneratedCode/project.json +++ b/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/project.json @@ -1,10 +1,5 @@ { "version": "1.0.0-*", - "description": "", - "authors": [ "" ], - "tags": [ "" ], - "projectUrl": "", - "licenseUrl": "", "dependencies": { "Microsoft.Dnx.Compilation.CSharp.Abstractions": "1.0.0-*" From b2226772e34cb0877e22d92472e3c155a99f10fe Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Fri, 7 Aug 2015 12:27:04 -0700 Subject: [PATCH 0190/1662] Expand timeout in SocketOutputTests due to flakiness on the CI server #154 --- .../SocketOutputTests.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/Microsoft.AspNet.Server.KestrelTests/SocketOutputTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/SocketOutputTests.cs index 072feecc4f..97b1d998d7 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/SocketOutputTests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/SocketOutputTests.cs @@ -54,7 +54,7 @@ namespace Microsoft.AspNet.Server.KestrelTests socketOutput.Write(buffer, onCompleted, null); // Assert - Assert.True(completedWh.Wait(100)); + Assert.True(completedWh.Wait(1000)); } } @@ -97,19 +97,19 @@ namespace Microsoft.AspNet.Server.KestrelTests socketOutput.Write(buffer, onCompleted, null); // Assert // The first write should pre-complete since it is <= _maxBytesPreCompleted. - Assert.True(completedWh.Wait(100)); + Assert.True(completedWh.Wait(1000)); // Arrange completedWh.Reset(); // Act socketOutput.Write(buffer, onCompleted, null); // Assert // Too many bytes are already pre-completed for the second write to pre-complete. - Assert.False(completedWh.Wait(100)); + Assert.False(completedWh.Wait(1000)); // Act completeQueue.Dequeue()(0); // Assert // Finishing the first write should allow the second write to pre-complete. - Assert.True(completedWh.Wait(100)); + Assert.True(completedWh.Wait(1000)); } } From 0ac3c3dad614940855b007425b49acba5a1b4458 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Tue, 11 Aug 2015 12:37:46 -0700 Subject: [PATCH 0191/1662] More ConfigureAwait(false) --- samples/LargeResponseApp/Startup.cs | 2 +- src/Microsoft.AspNet.Server.Kestrel/Http/ListenerPrimary.cs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/samples/LargeResponseApp/Startup.cs b/samples/LargeResponseApp/Startup.cs index 407b1fdd49..6bae65f890 100644 --- a/samples/LargeResponseApp/Startup.cs +++ b/samples/LargeResponseApp/Startup.cs @@ -30,7 +30,7 @@ namespace LargeResponseApp for (int i = 0; i < numChunks; i++) { - await context.Response.Body.WriteAsync(_chunk, 0, _chunkSize); + await context.Response.Body.WriteAsync(_chunk, 0, _chunkSize).ConfigureAwait(false); } }); } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerPrimary.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerPrimary.cs index ac2bdebe5c..f1299c073b 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerPrimary.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerPrimary.cs @@ -29,7 +29,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http KestrelThread thread, Func application) { - await StartAsync(scheme, host, port, thread, application); + await StartAsync(scheme, host, port, thread, application).ConfigureAwait(false); await Thread.PostAsync(_ => { @@ -37,7 +37,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http ListenPipe.Init(Thread.Loop, false); ListenPipe.Bind(pipeName); ListenPipe.Listen(Constants.ListenBacklog, OnListenPipe, null); - }, null); + }, null).ConfigureAwait(false); } private void OnListenPipe(UvStreamHandle pipe, int status, Exception error, object state) From d97b02696f05f5c367720d46768829132f5e65e2 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Wed, 5 Aug 2015 16:27:56 -0700 Subject: [PATCH 0192/1662] Merge Kestrel into Microsoft.AspNet.Server.Kestrel --- KestrelHttpServer.sln | 9 +------- .../Microsoft.AspNet.Hosting.ini | 2 +- samples/LargeResponseApp/project.json | 2 +- .../SampleApp/Microsoft.AspNet.Hosting.ini | 2 +- samples/SampleApp/project.json | 2 +- src/Kestrel/Kestrel.xproj | 17 -------------- src/Kestrel/Properties/AssemblyInfo.cs | 6 ----- src/Kestrel/project.json | 22 ------------------- .../IKestrelServerInformation.cs | 2 +- .../Program.cs | 3 +-- .../ServerAddress.cs | 2 +- .../ServerFactory.cs | 2 +- .../ServerInformation.cs | 2 +- .../ServerRequest.cs | 2 +- .../project.json | 1 + 15 files changed, 12 insertions(+), 64 deletions(-) delete mode 100644 src/Kestrel/Kestrel.xproj delete mode 100644 src/Kestrel/Properties/AssemblyInfo.cs delete mode 100644 src/Kestrel/project.json rename src/{Kestrel => Microsoft.AspNet.Server.Kestrel}/IKestrelServerInformation.cs (86%) rename src/{Kestrel => Microsoft.AspNet.Server.Kestrel}/Program.cs (94%) rename src/{Kestrel => Microsoft.AspNet.Server.Kestrel}/ServerAddress.cs (98%) rename src/{Kestrel => Microsoft.AspNet.Server.Kestrel}/ServerFactory.cs (98%) rename src/{Kestrel => Microsoft.AspNet.Server.Kestrel}/ServerInformation.cs (96%) rename src/{Kestrel => Microsoft.AspNet.Server.Kestrel}/ServerRequest.cs (99%) diff --git a/KestrelHttpServer.sln b/KestrelHttpServer.sln index 4758d52998..980a5d2537 100644 --- a/KestrelHttpServer.sln +++ b/KestrelHttpServer.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 14 -VisualStudioVersion = 14.0.22823.1 +VisualStudioVersion = 14.0.23107.0 MinimumVisualStudioVersion = 10.0.40219.1 Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.Server.Kestrel", "src\Microsoft.AspNet.Server.Kestrel\Microsoft.AspNet.Server.Kestrel.xproj", "{F510611A-3BEE-4B88-A613-5F4A74ED82A1}" EndProject @@ -17,8 +17,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution EndProject Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "SampleApp", "samples\SampleApp\SampleApp.xproj", "{2C3CB3DC-EEBF-4F52-9E1C-4F2F972E76C3}" EndProject -Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Kestrel", "src\Kestrel\Kestrel.xproj", "{30B7617E-58EF-4382-B3EA-5B2E718CF1A6}" -EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{2D5D5227-4DBD-499A-96B1-76A36B03B750}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{D3273454-EA07-41D2-BF0B-FCC3675C2483}" @@ -49,10 +47,6 @@ Global {2C3CB3DC-EEBF-4F52-9E1C-4F2F972E76C3}.Debug|Any CPU.Build.0 = Debug|Any CPU {2C3CB3DC-EEBF-4F52-9E1C-4F2F972E76C3}.Release|Any CPU.ActiveCfg = Release|Any CPU {2C3CB3DC-EEBF-4F52-9E1C-4F2F972E76C3}.Release|Any CPU.Build.0 = Release|Any CPU - {30B7617E-58EF-4382-B3EA-5B2E718CF1A6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {30B7617E-58EF-4382-B3EA-5B2E718CF1A6}.Debug|Any CPU.Build.0 = Debug|Any CPU - {30B7617E-58EF-4382-B3EA-5B2E718CF1A6}.Release|Any CPU.ActiveCfg = Release|Any CPU - {30B7617E-58EF-4382-B3EA-5B2E718CF1A6}.Release|Any CPU.Build.0 = Release|Any CPU {B35D4D31-E74C-4646-8A11-7A7A40F0021E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {B35D4D31-E74C-4646-8A11-7A7A40F0021E}.Debug|Any CPU.Build.0 = Debug|Any CPU {B35D4D31-E74C-4646-8A11-7A7A40F0021E}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -69,7 +63,6 @@ Global {F510611A-3BEE-4B88-A613-5F4A74ED82A1} = {2D5D5227-4DBD-499A-96B1-76A36B03B750} {37F3BFB2-6454-49E5-9D7F-581BF755CCFE} = {D3273454-EA07-41D2-BF0B-FCC3675C2483} {2C3CB3DC-EEBF-4F52-9E1C-4F2F972E76C3} = {8A3D00B8-1CCF-4BE6-A060-11104CE2D9CE} - {30B7617E-58EF-4382-B3EA-5B2E718CF1A6} = {2D5D5227-4DBD-499A-96B1-76A36B03B750} {B35D4D31-E74C-4646-8A11-7A7A40F0021E} = {8A3D00B8-1CCF-4BE6-A060-11104CE2D9CE} {BD2D4D29-1BD9-40D0-BB31-337D5416B63C} = {327F7880-D9AF-46BD-B45C-3B7E34A01DFD} EndGlobalSection diff --git a/samples/LargeResponseApp/Microsoft.AspNet.Hosting.ini b/samples/LargeResponseApp/Microsoft.AspNet.Hosting.ini index 3fc5452c97..c566ee4f7d 100644 --- a/samples/LargeResponseApp/Microsoft.AspNet.Hosting.ini +++ b/samples/LargeResponseApp/Microsoft.AspNet.Hosting.ini @@ -1,3 +1,3 @@  -Server = Kestrel +Server = Microsoft.AspNet.Server.Kestrel Server.Urls = http://localhost:5001/ diff --git a/samples/LargeResponseApp/project.json b/samples/LargeResponseApp/project.json index f533e7ed47..b2ce387239 100644 --- a/samples/LargeResponseApp/project.json +++ b/samples/LargeResponseApp/project.json @@ -10,7 +10,7 @@ }, "commands": { - "run": "Kestrel", + "run": "Microsoft.AspNet.Server.Kestrel", "web": "Microsoft.AspNet.Hosting" } } diff --git a/samples/SampleApp/Microsoft.AspNet.Hosting.ini b/samples/SampleApp/Microsoft.AspNet.Hosting.ini index 3acac330ec..882b9e0262 100644 --- a/samples/SampleApp/Microsoft.AspNet.Hosting.ini +++ b/samples/SampleApp/Microsoft.AspNet.Hosting.ini @@ -1,3 +1,3 @@  -Server = Kestrel +Server = Microsoft.AspNet.Server.Kestrel Server.Urls = http://localhost:5000/ diff --git a/samples/SampleApp/project.json b/samples/SampleApp/project.json index fe1e191d79..698cdeb262 100644 --- a/samples/SampleApp/project.json +++ b/samples/SampleApp/project.json @@ -12,7 +12,7 @@ } }, "commands": { - "run": "Kestrel", + "run": "Microsoft.AspNet.Server.Kestrel", "web": "Microsoft.AspNet.Hosting" } } diff --git a/src/Kestrel/Kestrel.xproj b/src/Kestrel/Kestrel.xproj deleted file mode 100644 index 446aa1f972..0000000000 --- a/src/Kestrel/Kestrel.xproj +++ /dev/null @@ -1,17 +0,0 @@ - - - - 14.0 - $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) - - - - 30b7617e-58ef-4382-b3ea-5b2e718cf1a6 - ..\..\artifacts\obj\$(MSBuildProjectName) - ..\..\artifacts\bin\$(MSBuildProjectName)\ - - - 2.0 - - - \ No newline at end of file diff --git a/src/Kestrel/Properties/AssemblyInfo.cs b/src/Kestrel/Properties/AssemblyInfo.cs deleted file mode 100644 index 025a94598c..0000000000 --- a/src/Kestrel/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,6 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System.Reflection; - -[assembly: AssemblyMetadata("Serviceable", "True")] \ No newline at end of file diff --git a/src/Kestrel/project.json b/src/Kestrel/project.json deleted file mode 100644 index 1187eba23c..0000000000 --- a/src/Kestrel/project.json +++ /dev/null @@ -1,22 +0,0 @@ -{ - "version": "1.0.0-*", - "description": "ASP.NET 5 cross platform development web server.", - "repository": { - "type": "git", - "url": "git://github.com/aspnet/kestrelhttpserver" - }, - "dependencies": { - "Microsoft.AspNet.Hosting": "1.0.0-*", - "Microsoft.AspNet.Server.Kestrel": "1.0.0-*" - }, - "frameworks": { - "dnx451": { - "dependencies": { } - }, - "dnxcore50": { - "dependencies": { - "System.Runtime": "4.0.21-beta-*" - } - } - } -} diff --git a/src/Kestrel/IKestrelServerInformation.cs b/src/Microsoft.AspNet.Server.Kestrel/IKestrelServerInformation.cs similarity index 86% rename from src/Kestrel/IKestrelServerInformation.cs rename to src/Microsoft.AspNet.Server.Kestrel/IKestrelServerInformation.cs index a9fce59d09..b9bd5641f9 100644 --- a/src/Kestrel/IKestrelServerInformation.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/IKestrelServerInformation.cs @@ -1,7 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -namespace Kestrel +namespace Microsoft.AspNet.Server.Kestrel { public interface IKestrelServerInformation { diff --git a/src/Kestrel/Program.cs b/src/Microsoft.AspNet.Server.Kestrel/Program.cs similarity index 94% rename from src/Kestrel/Program.cs rename to src/Microsoft.AspNet.Server.Kestrel/Program.cs index 220cf1eed3..2b022bac9b 100644 --- a/src/Kestrel/Program.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Program.cs @@ -4,7 +4,7 @@ using System; using System.Linq; -namespace Kestrel +namespace Microsoft.AspNet.Server.Kestrel { public class Program { @@ -23,4 +23,3 @@ namespace Kestrel } } } - diff --git a/src/Kestrel/ServerAddress.cs b/src/Microsoft.AspNet.Server.Kestrel/ServerAddress.cs similarity index 98% rename from src/Kestrel/ServerAddress.cs rename to src/Microsoft.AspNet.Server.Kestrel/ServerAddress.cs index dfbe1ff3df..845baf11bc 100644 --- a/src/Kestrel/ServerAddress.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/ServerAddress.cs @@ -4,7 +4,7 @@ using System; using System.Globalization; -namespace Kestrel +namespace Microsoft.AspNet.Server.Kestrel { public class ServerAddress { diff --git a/src/Kestrel/ServerFactory.cs b/src/Microsoft.AspNet.Server.Kestrel/ServerFactory.cs similarity index 98% rename from src/Kestrel/ServerFactory.cs rename to src/Microsoft.AspNet.Server.Kestrel/ServerFactory.cs index 65514e0fc8..e43e75aef0 100644 --- a/src/Kestrel/ServerFactory.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/ServerFactory.cs @@ -10,7 +10,7 @@ using Microsoft.AspNet.Server.Kestrel; using Microsoft.Dnx.Runtime; using Microsoft.Framework.Configuration; -namespace Kestrel +namespace Microsoft.AspNet.Server.Kestrel { /// /// Summary description for ServerFactory diff --git a/src/Kestrel/ServerInformation.cs b/src/Microsoft.AspNet.Server.Kestrel/ServerInformation.cs similarity index 96% rename from src/Kestrel/ServerInformation.cs rename to src/Microsoft.AspNet.Server.Kestrel/ServerInformation.cs index a3b770834c..6205e4c2c1 100644 --- a/src/Kestrel/ServerInformation.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/ServerInformation.cs @@ -6,7 +6,7 @@ using System.Collections.Generic; using Microsoft.AspNet.Hosting.Server; using Microsoft.Framework.Configuration; -namespace Kestrel +namespace Microsoft.AspNet.Server.Kestrel { public class ServerInformation : IServerInformation, IKestrelServerInformation { diff --git a/src/Kestrel/ServerRequest.cs b/src/Microsoft.AspNet.Server.Kestrel/ServerRequest.cs similarity index 99% rename from src/Kestrel/ServerRequest.cs rename to src/Microsoft.AspNet.Server.Kestrel/ServerRequest.cs index 66f5879f4d..9d7d3dabe9 100644 --- a/src/Kestrel/ServerRequest.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/ServerRequest.cs @@ -9,7 +9,7 @@ using System.Threading.Tasks; using Microsoft.AspNet.Http.Features; using Microsoft.AspNet.Server.Kestrel.Http; -namespace Kestrel +namespace Microsoft.AspNet.Server.Kestrel { public class ServerRequest : IHttpRequestFeature, IHttpResponseFeature, IHttpUpgradeFeature { diff --git a/src/Microsoft.AspNet.Server.Kestrel/project.json b/src/Microsoft.AspNet.Server.Kestrel/project.json index 2a36031520..0ff9347b82 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/project.json +++ b/src/Microsoft.AspNet.Server.Kestrel/project.json @@ -6,6 +6,7 @@ "url": "git://github.com/aspnet/kestrelhttpserver" }, "dependencies": { + "Microsoft.AspNet.Hosting": "1.0.0-*", "Microsoft.Dnx.Runtime.Abstractions": "1.0.0-beta7-*" }, "frameworks": { From 8d416d998bbe40be32e7891223a3bc2901b1120c Mon Sep 17 00:00:00 2001 From: Kiran Challa Date: Tue, 11 Aug 2015 17:09:02 -0700 Subject: [PATCH 0193/1662] Enable pinning build script --- build.cmd | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/build.cmd b/build.cmd index 6d798a5b37..ccf195aee8 100644 --- a/build.cmd +++ b/build.cmd @@ -3,6 +3,8 @@ cd %~dp0 SETLOCAL SET CACHED_NUGET=%LocalAppData%\NuGet\NuGet.exe +SET BUILDCMD_KOREBUILD_VERSION="" +SET BUILDCMD_DNX_VERSION="" IF EXIST %CACHED_NUGET% goto copynuget echo Downloading latest version of NuGet.exe... @@ -16,13 +18,21 @@ copy %CACHED_NUGET% .nuget\nuget.exe > nul :restore IF EXIST packages\KoreBuild goto run -.nuget\NuGet.exe install KoreBuild -ExcludeVersion -o packages -nocache -pre +IF %BUILDCMD_KOREBUILD_VERSION%=="" ( + .nuget\NuGet.exe install KoreBuild -ExcludeVersion -o packages -nocache -pre +) ELSE ( + .nuget\NuGet.exe install KoreBuild -version %BUILDCMD_KOREBUILD_VERSION% -ExcludeVersion -o packages -nocache -pre +) .nuget\NuGet.exe install Sake -version 0.2 -o packages -ExcludeVersion IF "%SKIP_DNX_INSTALL%"=="1" goto run -CALL packages\KoreBuild\build\dnvm upgrade -runtime CLR -arch x86 +IF %BUILDCMD_DNX_VERSION%=="" ( + CALL packages\KoreBuild\build\dnvm upgrade -runtime CLR -arch x86 +) ELSE ( + CALL packages\KoreBuild\build\dnvm install %BUILDCMD_DNX_VERSION% -runtime CLR -arch x86 -a default +) CALL packages\KoreBuild\build\dnvm install default -runtime CoreCLR -arch x86 :run CALL packages\KoreBuild\build\dnvm use default -runtime CLR -arch x86 -packages\Sake\tools\Sake.exe -I build -I packages\KoreBuild\build -f makefile.shade %* +packages\Sake\tools\Sake.exe -I packages\KoreBuild\build -f makefile.shade %* \ No newline at end of file From 9275250f6e386dce74940215e2728cce580d1e89 Mon Sep 17 00:00:00 2001 From: Kiran Challa Date: Wed, 12 Aug 2015 13:10:09 -0700 Subject: [PATCH 0194/1662] Fix build break --- build.cmd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.cmd b/build.cmd index ccf195aee8..231b6cc743 100644 --- a/build.cmd +++ b/build.cmd @@ -35,4 +35,4 @@ CALL packages\KoreBuild\build\dnvm install default -runtime CoreCLR -arch x86 :run CALL packages\KoreBuild\build\dnvm use default -runtime CLR -arch x86 -packages\Sake\tools\Sake.exe -I packages\KoreBuild\build -f makefile.shade %* \ No newline at end of file +packages\Sake\tools\Sake.exe -I build -I packages\KoreBuild\build -f makefile.shade %* \ No newline at end of file From 097fb35ddf7f9ff310938586a5490cb5988dcf5f Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Wed, 12 Aug 2015 15:12:53 -0700 Subject: [PATCH 0195/1662] Fix startup when you reference the assembly directly instead of Hosting - I missed this change in Program.cs when doing the initial package merging --- samples/SampleApp/project.json | 1 + src/Microsoft.AspNet.Server.Kestrel/Program.cs | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/samples/SampleApp/project.json b/samples/SampleApp/project.json index 698cdeb262..b7e9f3b993 100644 --- a/samples/SampleApp/project.json +++ b/samples/SampleApp/project.json @@ -13,6 +13,7 @@ }, "commands": { "run": "Microsoft.AspNet.Server.Kestrel", + "kestrel": "Microsoft.AspNet.Server.Kestrel", "web": "Microsoft.AspNet.Hosting" } } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Program.cs b/src/Microsoft.AspNet.Server.Kestrel/Program.cs index 2b022bac9b..ba7e264f8f 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Program.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Program.cs @@ -18,7 +18,7 @@ namespace Microsoft.AspNet.Server.Kestrel public void Main(string[] args) { var program = new Microsoft.AspNet.Hosting.Program(_serviceProvider); - var mergedArgs = new[] { "--server", "Kestrel" }.Concat(args).ToArray(); + var mergedArgs = new[] { "--server", "Microsoft.AspNet.Server.Kestrel" }.Concat(args).ToArray(); program.Main(mergedArgs); } } From c7535f127c1419866109a9bff60cdeba6515b43d Mon Sep 17 00:00:00 2001 From: Kirthi Krishnamraju Date: Thu, 13 Aug 2015 22:42:48 -0700 Subject: [PATCH 0196/1662] fix build break due to aspnet\configuration #246 --- src/Microsoft.AspNet.Server.Kestrel/ServerInformation.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/ServerInformation.cs b/src/Microsoft.AspNet.Server.Kestrel/ServerInformation.cs index 6205e4c2c1..ec80e002a1 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/ServerInformation.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/ServerInformation.cs @@ -17,8 +17,8 @@ namespace Microsoft.AspNet.Server.Kestrel public void Initialize(IConfiguration configuration) { - string urls; - if (!configuration.TryGet("server.urls", out urls)) + var urls = configuration["server.urls"]; + if (!string.IsNullOrEmpty(urls)) { urls = "http://+:5000/"; } From 43ebf710ab0ea438e37c12dee8676b33217a4ef0 Mon Sep 17 00:00:00 2001 From: Chris R Date: Fri, 14 Aug 2015 09:33:02 -0700 Subject: [PATCH 0197/1662] Fix regression in reading config --- src/Microsoft.AspNet.Server.Kestrel/ServerInformation.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/ServerInformation.cs b/src/Microsoft.AspNet.Server.Kestrel/ServerInformation.cs index ec80e002a1..423c848623 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/ServerInformation.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/ServerInformation.cs @@ -18,7 +18,7 @@ namespace Microsoft.AspNet.Server.Kestrel public void Initialize(IConfiguration configuration) { var urls = configuration["server.urls"]; - if (!string.IsNullOrEmpty(urls)) + if (string.IsNullOrEmpty(urls)) { urls = "http://+:5000/"; } From b162202519c38c280d1d2e838e08f3b9059003c8 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Tue, 4 Aug 2015 16:56:08 -0700 Subject: [PATCH 0198/1662] Properly close keep alive connections --- .../Http/Connection.cs | 5 +- .../Http/Frame.cs | 15 ++++- .../EngineTests.cs | 67 +++++++++++++++++++ 3 files changed, 84 insertions(+), 3 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs index d43a1ab4ce..c5e741043a 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs @@ -9,6 +9,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { public class Connection : ConnectionContext, IConnectionControl { + private const int EOF = -4095; + private const int ECONNRESET = -4077; + private static readonly Action _readCallback = ReadCallback; private static readonly Func _allocCallback = AllocCallback; @@ -54,7 +57,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http SocketInput.Unpin(status); var normalRead = error == null && status > 0; - var normalDone = status == 0 || status == -4077 || status == -4095; + var normalDone = status == 0 || status == ECONNRESET || status == EOF; var errorDone = !(normalDone || normalRead); if (normalRead) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs index 78d4c6f198..fd584323df 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs @@ -94,7 +94,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http if (input.Buffer.Count == 0 && input.RemoteIntakeFin) { _mode = Mode.Terminated; - return; + break; } if (!TakeStartLine(input)) @@ -102,6 +102,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http if (input.RemoteIntakeFin) { _mode = Mode.Terminated; + break; } return; } @@ -113,7 +114,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http if (input.Buffer.Count == 0 && input.RemoteIntakeFin) { _mode = Mode.Terminated; - return; + break; } var endOfHeaders = false; @@ -124,11 +125,19 @@ namespace Microsoft.AspNet.Server.Kestrel.Http if (input.RemoteIntakeFin) { _mode = Mode.Terminated; + break; } return; } } + if (_mode == Mode.Terminated) + { + // If we broke out of the above while loop in the Terminated + // state, we don't want to transition to the MessageBody state. + break; + } + //var resumeBody = HandleExpectContinue(callback); _mode = Mode.MessageBody; Execute(); @@ -145,6 +154,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return; case Mode.Terminated: + ConnectionControl.End(ProduceEndType.SocketShutdownSend); + ConnectionControl.End(ProduceEndType.SocketDisconnect); return; } } diff --git a/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs index 99fe1b4140..771471f632 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs @@ -468,5 +468,72 @@ namespace Microsoft.AspNet.Server.KestrelTests } } } + + [Fact] + public async Task ConnectionClosesWhenFinReceived() + { + using (var server = new TestServer(AppChunked)) + { + using (var connection = new TestConnection()) + { + await connection.SendEnd( + "GET / HTTP/1.1", + "", + "Post / HTTP/1.1", + "Content-Length: 7", + "", + "Goodbye"); + await connection.ReceiveEnd( + "HTTP/1.1 200 OK", + "Content-Length: 0", + "", + "HTTP/1.1 200 OK", + "Content-Length: 7", + "", + "Goodbye"); + } + } + } + + [Fact] + public async Task ConnectionClosesWhenFinReceivedBeforeRequestCompletes() + { + using (var server = new TestServer(AppChunked)) + { + using (var connection = new TestConnection()) + { + await connection.SendEnd( + "GET /"); + await connection.ReceiveEnd(); + } + + using (var connection = new TestConnection()) + { + await connection.SendEnd( + "GET / HTTP/1.1", + "", + "Post / HTTP/1.1"); + await connection.ReceiveEnd( + "HTTP/1.1 200 OK", + "Content-Length: 0", + "", + ""); + } + + using (var connection = new TestConnection()) + { + await connection.SendEnd( + "GET / HTTP/1.1", + "", + "Post / HTTP/1.1", + "Content-Length: 7"); + await connection.ReceiveEnd( + "HTTP/1.1 200 OK", + "Content-Length: 0", + "", + ""); + } + } + } } } From c0cc511b5bd5754d7075826b79a275b66633d002 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Thu, 6 Aug 2015 15:14:50 -0700 Subject: [PATCH 0199/1662] Prevent access to closed socket in in Connection.End --- .../Http/Connection.cs | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs index c5e741043a..a2976c75c9 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs @@ -4,6 +4,7 @@ using System; using Microsoft.AspNet.Server.Kestrel.Networking; using System.Diagnostics; +using System.Threading; namespace Microsoft.AspNet.Server.Kestrel.Http { @@ -15,6 +16,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http private static readonly Action _readCallback = ReadCallback; private static readonly Func _allocCallback = AllocCallback; + private int _connectionState; + private static Libuv.uv_buf_t AllocCallback(UvStreamHandle handle, int suggestedSize, object state) { return ((Connection)state).OnAlloc(handle, suggestedSize); @@ -104,6 +107,12 @@ namespace Microsoft.AspNet.Server.Kestrel.Http switch (endType) { case ProduceEndType.SocketShutdownSend: + if (Interlocked.CompareExchange(ref _connectionState, ConnectionState.Shutdown, ConnectionState.Open) + != ConnectionState.Open) + { + return; + } + KestrelTrace.Log.ConnectionWriteFin(_connectionId, 0); Thread.Post( x => @@ -128,6 +137,12 @@ namespace Microsoft.AspNet.Server.Kestrel.Http _frame); break; case ProduceEndType.SocketDisconnect: + if (Interlocked.Exchange(ref _connectionState, ConnectionState.Disconnected) + == ConnectionState.Disconnected) + { + return; + } + KestrelTrace.Log.ConnectionDisconnect(_connectionId); Thread.Post( x => @@ -139,5 +154,12 @@ namespace Microsoft.AspNet.Server.Kestrel.Http break; } } + + private static class ConnectionState + { + public const int Open = 0; + public const int Shutdown = 1; + public const int Disconnected = 2; + } } } From 6a01043e1a53d9f42eff5e51678148b7bb8c75bc Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Tue, 11 Aug 2015 00:55:39 -0700 Subject: [PATCH 0200/1662] Fix ListenerSecondary so it reliably accepts new connections on Windows Calling uv_read_start on a named pipe with a larger than necessary buffer would cause pieces of the next uv_ipc_frame_uv_stream struct to be read into the uv_read_start buffer when a lot of tcp handles were passed quickly over the pipe. This prevented the struct from properly being queued for the next call to uv_accept to consume. The empty queue caused the call to uv_accept in ListenerSecondary to fail and return WSAEWOULDBLOCK leaving the connection in a zombie state. --- src/Microsoft.AspNet.Server.Kestrel/Http/ListenerSecondary.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerSecondary.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerSecondary.cs index 7bd97ed543..99b21897be 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerSecondary.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerSecondary.cs @@ -50,8 +50,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http try { - var ptr = Marshal.AllocHGlobal(16); - var buf = Thread.Loop.Libuv.buf_init(ptr, 16); + var ptr = Marshal.AllocHGlobal(4); + var buf = Thread.Loop.Libuv.buf_init(ptr, 4); DispatchPipe.ReadStart( (_1, _2, _3) => buf, From 4f0480a4d02b09e32e36dbd2f07f1a2d94530fba Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Mon, 20 Jul 2015 12:26:39 -0700 Subject: [PATCH 0201/1662] Gracefully handle exceptions thrown from OnStarting callbacks - If OnStarting is being called after the app func has completed, return a 500. - If Onstarting is being called due to a call to write, throw from write. --- .../Http/Frame.cs | 19 ++-- .../EngineTests.cs | 87 +++++++++++++++++++ 2 files changed, 99 insertions(+), 7 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs index fd584323df..7dc2603bc3 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs @@ -25,7 +25,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Http static Encoding _ascii = Encoding.ASCII; Mode _mode; - private bool _resultStarted; private bool _responseStarted; private bool _keepAlive; private readonly FrameRequestHeaders _requestHeaders = new FrameRequestHeaders(); @@ -246,6 +245,14 @@ namespace Microsoft.AspNet.Server.Kestrel.Http try { await Application.Invoke(this).ConfigureAwait(false); + + // Trigger FireOnStarting if ProduceStart hasn't been called yet. + // We call it here, so it can go through our normal error handling + // and respond with a 500 if an OnStarting callback throws. + if (!_responseStarted) + { + FireOnStarting(); + } } catch (Exception ex) { @@ -284,7 +291,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http public void ProduceContinue() { - if (_resultStarted) return; + if (_responseStarted) return; string[] expect; if (HttpVersion.Equals("HTTP/1.1") && @@ -306,11 +313,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Http public void ProduceStart(bool immediate = true) { - if (_resultStarted) return; - _resultStarted = true; - + // ProduceStart shouldn't no-op in the future just b/c FireOnStarting throws. + if (_responseStarted) return; FireOnStarting(); - _responseStarted = true; var status = ReasonPhrases.ToStatus(StatusCode, ReasonPhrase); @@ -334,7 +339,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { if (ex != null) { - if (_resultStarted) + if (_responseStarted) { // We can no longer respond with a 500, so we simply close the connection. ConnectionControl.End(ProduceEndType.SocketDisconnect); diff --git a/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs index 771471f632..27526edd83 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs @@ -535,5 +535,92 @@ namespace Microsoft.AspNet.Server.KestrelTests } } } + + [Fact] + public async Task ThrowingInOnStartingResultsIn500Response() + { + using (var server = new TestServer(frame => + { + frame.OnStarting(_ => + { + throw new Exception(); + }, null); + + frame.ResponseHeaders.Clear(); + frame.ResponseHeaders["Content-Length"] = new[] { "11" }; + + // If we write to the response stream, we will not get a 500. + + return Task.FromResult(null); + })) + { + using (var connection = new TestConnection()) + { + await connection.SendEnd( + "GET / HTTP/1.1", + "", + "GET / HTTP/1.1", + "Connection: close", + "", + ""); + await connection.Receive( + "HTTP/1.1 500 Internal Server Error", + ""); + await connection.ReceiveStartsWith("Date:"); + await connection.Receive( + "Content-Length: 0", + "Server: Kestrel", + "", + "HTTP/1.1 500 Internal Server Error", + ""); + await connection.ReceiveStartsWith("Date:"); + await connection.ReceiveEnd( + "Content-Length: 0", + "Server: Kestrel", + "Connection: close", + "", + ""); + } + } + } + + [Fact] + public async Task ThrowingInOnStartingResultsInFailedWrites() + { + using (var server = new TestServer(async frame => + { + var onStartingException = new Exception(); + + frame.OnStarting(_ => + { + throw onStartingException; + }, null); + + frame.ResponseHeaders.Clear(); + frame.ResponseHeaders["Content-Length"] = new[] { "11" }; + + var writeException = await Assert.ThrowsAsync(async () => + await frame.ResponseBody.WriteAsync(Encoding.ASCII.GetBytes("Hello World"), 0, 11)); + + Assert.Same(onStartingException, writeException); + + // The second write should succeed since the OnStarting callback will not be called again + await frame.ResponseBody.WriteAsync(Encoding.ASCII.GetBytes("Exception!!"), 0, 11); + })) + { + using (var connection = new TestConnection()) + { + await connection.Send( + "GET / HTTP/1.1", + "", + ""); + await connection.Receive( + "HTTP/1.1 200 OK", + "Content-Length: 11", + "", + "Exception!!"); ; + } + } + } } } From 32c4f314b6063823b073d92e62ead05de2323069 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Fri, 14 Aug 2015 12:17:06 -0700 Subject: [PATCH 0202/1662] Lock around Connection.End to make it thread-safe --- .../Http/Connection.cs | 108 ++++++++++-------- 1 file changed, 58 insertions(+), 50 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs index a2976c75c9..641d184f8c 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs @@ -4,7 +4,6 @@ using System; using Microsoft.AspNet.Server.Kestrel.Networking; using System.Diagnostics; -using System.Threading; namespace Microsoft.AspNet.Server.Kestrel.Http { @@ -16,8 +15,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Http private static readonly Action _readCallback = ReadCallback; private static readonly Func _allocCallback = AllocCallback; - private int _connectionState; - private static Libuv.uv_buf_t AllocCallback(UvStreamHandle handle, int suggestedSize, object state) { return ((Connection)state).OnAlloc(handle, suggestedSize); @@ -32,6 +29,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Http private Frame _frame; long _connectionId = 0; + private readonly object _stateLock = new object(); + private ConnectionState _connectionState; + public Connection(ListenerContext context, UvStreamHandle socket) : base(context) { _socket = socket; @@ -104,62 +104,70 @@ namespace Microsoft.AspNet.Server.Kestrel.Http void IConnectionControl.End(ProduceEndType endType) { - switch (endType) + lock (_stateLock) { - case ProduceEndType.SocketShutdownSend: - if (Interlocked.CompareExchange(ref _connectionState, ConnectionState.Shutdown, ConnectionState.Open) - != ConnectionState.Open) - { - return; - } - - KestrelTrace.Log.ConnectionWriteFin(_connectionId, 0); - Thread.Post( - x => + switch (endType) + { + case ProduceEndType.SocketShutdownSend: + if (_connectionState != ConnectionState.Open) { - KestrelTrace.Log.ConnectionWriteFin(_connectionId, 1); - var self = (Connection)x; - var shutdown = new UvShutdownReq(); - shutdown.Init(self.Thread.Loop); - shutdown.Shutdown(self._socket, (req, status, state) => + return; + } + _connectionState = ConnectionState.Shutdown; + + KestrelTrace.Log.ConnectionWriteFin(_connectionId, 0); + Thread.Post( + x => { KestrelTrace.Log.ConnectionWriteFin(_connectionId, 1); - req.Dispose(); - }, null); - }, - this); - break; - case ProduceEndType.ConnectionKeepAlive: - KestrelTrace.Log.ConnectionKeepAlive(_connectionId); - _frame = new Frame(this); - Thread.Post( - x => ((Frame)x).Consume(), - _frame); - break; - case ProduceEndType.SocketDisconnect: - if (Interlocked.Exchange(ref _connectionState, ConnectionState.Disconnected) - == ConnectionState.Disconnected) - { - return; - } - - KestrelTrace.Log.ConnectionDisconnect(_connectionId); - Thread.Post( - x => + var self = (Connection)x; + var shutdown = new UvShutdownReq(); + shutdown.Init(self.Thread.Loop); + shutdown.Shutdown(self._socket, (req, status, state) => + { + KestrelTrace.Log.ConnectionWriteFin(_connectionId, 1); + req.Dispose(); + }, null); + }, + this); + break; + case ProduceEndType.ConnectionKeepAlive: + if (_connectionState != ConnectionState.Open) { - KestrelTrace.Log.ConnectionStop(_connectionId); - ((UvHandle)x).Dispose(); - }, - _socket); - break; + return; + } + + KestrelTrace.Log.ConnectionKeepAlive(_connectionId); + _frame = new Frame(this); + Thread.Post( + x => ((Frame)x).Consume(), + _frame); + break; + case ProduceEndType.SocketDisconnect: + if (_connectionState == ConnectionState.Disconnected) + { + return; + } + _connectionState = ConnectionState.Disconnected; + + KestrelTrace.Log.ConnectionDisconnect(_connectionId); + Thread.Post( + x => + { + KestrelTrace.Log.ConnectionStop(_connectionId); + ((UvHandle)x).Dispose(); + }, + _socket); + break; + } } } - private static class ConnectionState + private enum ConnectionState { - public const int Open = 0; - public const int Shutdown = 1; - public const int Disconnected = 2; + Open, + Shutdown, + Disconnected } } } From 3fb33119eec2550a9434e8761ad4c744bd528370 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Fri, 31 Jul 2015 12:38:35 -0700 Subject: [PATCH 0203/1662] Initial non-optimized support for automatically chunking responses --- .../Http/Frame.cs | 65 +++++++++++++++++-- 1 file changed, 61 insertions(+), 4 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs index 7dc2603bc3..bb236f6846 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs @@ -27,6 +27,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http Mode _mode; private bool _responseStarted; private bool _keepAlive; + private bool _autoChunk; private readonly FrameRequestHeaders _requestHeaders = new FrameRequestHeaders(); private readonly FrameResponseHeaders _responseHeaders = new FrameResponseHeaders(); @@ -253,6 +254,12 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { FireOnStarting(); } + + if (_autoChunk) + { + WriteChunkPrefix(numOctets: 0); + WriteChunkSuffix(); + } } catch (Exception ex) { @@ -265,11 +272,53 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } - public void Write(ArraySegment data, Action callback, object state) { ProduceStart(immediate: false); - SocketOutput.Write(data, callback, state); + + if (_autoChunk) + { + WriteChunkPrefix(data.Count); + } + + SocketOutput.Write(data, callback, state, immediate: !_autoChunk); + + if (_autoChunk) + { + WriteChunkSuffix(); + } + } + + private void WriteChunkPrefix(int numOctets) + { + var numOctetBytes = CreateAsciiByteArraySegment(numOctets.ToString("x") + "\r\n"); + + SocketOutput.Write(numOctetBytes, + (error, _) => + { + if (error != null) + { + Trace.WriteLine("WriteChunkPrefix" + error.ToString()); + } + }, + null, + immediate: false); + } + + private static readonly ArraySegment _endChunkBytes = CreateAsciiByteArraySegment("\r\n"); + + private void WriteChunkSuffix() + { + SocketOutput.Write(_endChunkBytes, + (error, _) => + { + if (error != null) + { + Trace.WriteLine("WriteChunkSuffix" + error.ToString()); + } + }, + null, + immediate: true); } public void Upgrade(IDictionary options, Func callback) @@ -421,9 +470,17 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } - if (hasTransferEncoding == false && hasContentLength == false) + if (_keepAlive && !hasTransferEncoding && !hasContentLength) { - _keepAlive = false; + if (HttpVersion == "HTTP/1.1") + { + _autoChunk = true; + writer.Write("Transfer-Encoding: chunked\r\n"); + } + else + { + _keepAlive = false; + } } if (_keepAlive == false && hasConnection == false && HttpVersion == "HTTP/1.1") { From 753d64660d24b2f8a113cac94e030b37bd7d3bb3 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Fri, 14 Aug 2015 15:04:00 -0700 Subject: [PATCH 0204/1662] Ignore zero length writes when automatically chunking responses - Zero length writes would previously be interpreted as the end of response - Optimize writing the chunked response suffix - Add tests for automatic response chunking --- .../Http/Frame.cs | 24 +++++- .../ChunkedResponseTests.cs | 75 +++++++++++++++++++ 2 files changed, 97 insertions(+), 2 deletions(-) create mode 100644 test/Microsoft.AspNet.Server.KestrelTests/ChunkedResponseTests.cs diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs index bb236f6846..43bed07978 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs @@ -257,8 +257,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http if (_autoChunk) { - WriteChunkPrefix(numOctets: 0); - WriteChunkSuffix(); + WriteChunkedResponseSuffix(); } } catch (Exception ex) @@ -278,6 +277,12 @@ namespace Microsoft.AspNet.Server.Kestrel.Http if (_autoChunk) { + if (data.Count == 0) + { + callback(null, state); + return; + } + WriteChunkPrefix(data.Count); } @@ -306,6 +311,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } private static readonly ArraySegment _endChunkBytes = CreateAsciiByteArraySegment("\r\n"); + private static readonly ArraySegment _endChunkedResponseBytes = CreateAsciiByteArraySegment("0\r\n\r\n"); private void WriteChunkSuffix() { @@ -321,6 +327,20 @@ namespace Microsoft.AspNet.Server.Kestrel.Http immediate: true); } + private void WriteChunkedResponseSuffix() + { + SocketOutput.Write(_endChunkedResponseBytes, + (error, _) => + { + if (error != null) + { + Trace.WriteLine("WriteChunkedResponseSuffix" + error.ToString()); + } + }, + null, + immediate: true); + } + public void Upgrade(IDictionary options, Func callback) { _keepAlive = false; diff --git a/test/Microsoft.AspNet.Server.KestrelTests/ChunkedResponseTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/ChunkedResponseTests.cs new file mode 100644 index 0000000000..a1b7ac186d --- /dev/null +++ b/test/Microsoft.AspNet.Server.KestrelTests/ChunkedResponseTests.cs @@ -0,0 +1,75 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System.Text; +using System.Threading.Tasks; +using Xunit; + +namespace Microsoft.AspNet.Server.KestrelTests +{ + public class ChunkedResponseTests + { + [Fact] + public async Task ResponsesAreChunkedAutomatically() + { + using (var server = new TestServer(async frame => + { + frame.ResponseHeaders.Clear(); + await frame.ResponseBody.WriteAsync(Encoding.ASCII.GetBytes("Hello "), 0, 6); + await frame.ResponseBody.WriteAsync(Encoding.ASCII.GetBytes("World!"), 0, 6); + })) + { + using (var connection = new TestConnection()) + { + await connection.SendEnd( + "GET / HTTP/1.1", + "", + ""); + await connection.ReceiveEnd( + "HTTP/1.1 200 OK", + "Transfer-Encoding: chunked", + "", + "6", + "Hello ", + "6", + "World!", + "0", + "", + ""); + } + } + } + + [Fact] + public async Task ZeroLengthWritesAreIgnored() + { + using (var server = new TestServer(async frame => + { + frame.ResponseHeaders.Clear(); + await frame.ResponseBody.WriteAsync(Encoding.ASCII.GetBytes("Hello "), 0, 6); + await frame.ResponseBody.WriteAsync(new byte[0], 0, 0); + await frame.ResponseBody.WriteAsync(Encoding.ASCII.GetBytes("World!"), 0, 6); + })) + { + using (var connection = new TestConnection()) + { + await connection.SendEnd( + "GET / HTTP/1.1", + "", + ""); + await connection.ReceiveEnd( + "HTTP/1.1 200 OK", + "Transfer-Encoding: chunked", + "", + "6", + "Hello ", + "6", + "World!", + "0", + "", + ""); + } + } + } + } +} From 62a909d1a75f7b9569ab07d4a83371bdc9cf6faf Mon Sep 17 00:00:00 2001 From: David Fowler Date: Sat, 15 Aug 2015 03:12:59 -0700 Subject: [PATCH 0205/1662] Handle broken assembly versions on mono --- .../project.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/project.json b/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/project.json index bfcbc212b3..6bede83d5a 100644 --- a/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/project.json +++ b/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/project.json @@ -12,9 +12,9 @@ "frameworks": { "dnx451": { "frameworkAssemblies": { - "System.Runtime": "4.0.10.0", - "System.Text.Encoding": "4.0.0.0", - "System.Threading.Tasks": "4.0.0.0" + "System.Runtime": "", + "System.Text.Encoding": "", + "System.Threading.Tasks": "" } } } From 9ade227abbba385bd42cbeb3b79ada721f40b7a3 Mon Sep 17 00:00:00 2001 From: Daniel Lo Nigro Date: Sat, 15 Aug 2015 15:50:34 -0700 Subject: [PATCH 0206/1662] Implement support for UNIX sockets. The common use-case for Kestrel in production will be behind a reverse proxy such as Nginx. In cases where the reverse proxy is located on the same machine as the application, connecting via a UNIX socket is more efficient than a TCP socket, as it avoids going through the network layer. Accessing 127.0.0.1 through TCP still needs to initiate a TCP connection and perform handshaking, checksumming, etc, all of which is avoided by using UNIX sockets. - Moved TCP-specific stuff from Listener into new TcpListener class (same with ListenerPrimary and ListenerSecondary) - Made Listener abstract - Created new PipeListener. Note that while the use case is for UNIX sockets, this is called "Pipe" in uv, so I've called this "PipeListener" so the terminology is consistant - Uses "unix" URL scheme to determine whether to use socket. "http://127.0.0.1:5000" is for listening via TCP while "unix:///var/run/kestrel-test.sock" is for listening via UNIX socket #156 --- samples/SampleApp/project.json | 1 + .../Http/IListener.cs | 21 +++++++++ .../Http/IListenerPrimary.cs | 23 ++++++++++ .../Http/IListenerSecondary.cs | 20 +++++++++ .../Http/Listener.cs | 41 ++++++++--------- .../Http/ListenerPrimary.cs | 12 +++-- .../Http/ListenerSecondary.cs | 16 +++++-- .../Http/PipeListener.cs | 44 ++++++++++++++++++ .../Http/PipeListenerPrimary.cs | 44 ++++++++++++++++++ .../Http/PipeListenerSecondary.cs | 27 +++++++++++ .../Http/TcpListener.cs | 45 +++++++++++++++++++ .../Http/TcpListenerPrimary.cs | 45 +++++++++++++++++++ .../Http/TcpListenerSecondary.cs | 27 +++++++++++ .../Infrastructure/Constants.cs | 11 +++-- .../KestrelEngine.cs | 17 ++++--- .../ServerFactory.cs | 5 ++- 16 files changed, 358 insertions(+), 41 deletions(-) create mode 100644 src/Microsoft.AspNet.Server.Kestrel/Http/IListener.cs create mode 100644 src/Microsoft.AspNet.Server.Kestrel/Http/IListenerPrimary.cs create mode 100644 src/Microsoft.AspNet.Server.Kestrel/Http/IListenerSecondary.cs create mode 100644 src/Microsoft.AspNet.Server.Kestrel/Http/PipeListener.cs create mode 100644 src/Microsoft.AspNet.Server.Kestrel/Http/PipeListenerPrimary.cs create mode 100644 src/Microsoft.AspNet.Server.Kestrel/Http/PipeListenerSecondary.cs create mode 100644 src/Microsoft.AspNet.Server.Kestrel/Http/TcpListener.cs create mode 100644 src/Microsoft.AspNet.Server.Kestrel/Http/TcpListenerPrimary.cs create mode 100644 src/Microsoft.AspNet.Server.Kestrel/Http/TcpListenerSecondary.cs diff --git a/samples/SampleApp/project.json b/samples/SampleApp/project.json index b7e9f3b993..7a325b00e7 100644 --- a/samples/SampleApp/project.json +++ b/samples/SampleApp/project.json @@ -13,6 +13,7 @@ }, "commands": { "run": "Microsoft.AspNet.Server.Kestrel", + "run-socket": "Microsoft.AspNet.Server.Kestrel --server.urls unix:///tmp/kestrel-test.sock", "kestrel": "Microsoft.AspNet.Server.Kestrel", "web": "Microsoft.AspNet.Hosting" } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/IListener.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/IListener.cs new file mode 100644 index 0000000000..ccd6d104d4 --- /dev/null +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/IListener.cs @@ -0,0 +1,21 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Threading.Tasks; + +namespace Microsoft.AspNet.Server.Kestrel.Http +{ + /// + /// A listener waits for incoming connections on a specified socket. + /// + public interface IListener : IDisposable + { + Task StartAsync( + string scheme, + string host, + int port, + KestrelThread thread, + Func application); + } +} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/IListenerPrimary.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/IListenerPrimary.cs new file mode 100644 index 0000000000..7a42fe02ef --- /dev/null +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/IListenerPrimary.cs @@ -0,0 +1,23 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Threading.Tasks; + +namespace Microsoft.AspNet.Server.Kestrel.Http +{ + /// + /// A primary listener waits for incoming connections on a specified socket. Incoming + /// connections may be passed to a secondary listener to handle. + /// + public interface IListenerPrimary : IListener + { + Task StartAsync( + string pipeName, + string scheme, + string host, + int port, + KestrelThread thread, + Func application); + } +} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/IListenerSecondary.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/IListenerSecondary.cs new file mode 100644 index 0000000000..3230a7e1bc --- /dev/null +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/IListenerSecondary.cs @@ -0,0 +1,20 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Threading.Tasks; + +namespace Microsoft.AspNet.Server.Kestrel.Http +{ + /// + /// A secondary listener is delegated requests from a primary listener via a named pipe or + /// UNIX domain socket. + /// + public interface IListenerSecondary : IDisposable + { + Task StartAsync( + string pipeName, + KestrelThread thread, + Func application); + } +} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs index 370c62ac0d..dd0d6f0228 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs @@ -1,25 +1,22 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using Microsoft.AspNet.Server.Kestrel.Infrastructure; using Microsoft.AspNet.Server.Kestrel.Networking; using System; using System.Diagnostics; -using System.Net; using System.Threading.Tasks; namespace Microsoft.AspNet.Server.Kestrel.Http { /// - /// Summary description for Accept + /// Base class for listeners in Kestrel. Listens for incoming connections /// - public class Listener : ListenerContext, IDisposable + /// Type of socket used by this listener + public abstract class Listener : ListenerContext, IListener where T : UvStreamHandle { - private static readonly Action _connectionCallback = ConnectionCallback; + protected T ListenSocket { get; private set; } - UvTcpHandle ListenSocket { get; set; } - - private static void ConnectionCallback(UvStreamHandle stream, int status, Exception error, object state) + protected static void ConnectionCallback(UvStreamHandle stream, int status, Exception error, object state) { if (error != null) { @@ -27,11 +24,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } else { - ((Listener)state).OnConnection(stream, status); + ((Listener)state).OnConnection((T)stream, status); } } - public Listener(IMemoryPool memory) + protected Listener(IMemoryPool memory) { Memory = memory; } @@ -51,10 +48,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { try { - ListenSocket = new UvTcpHandle(); - ListenSocket.Init(Thread.Loop, Thread.QueueCloseHandle); - ListenSocket.Bind(new IPEndPoint(IPAddress.Any, port)); - ListenSocket.Listen(Constants.ListenBacklog, _connectionCallback, this); + ListenSocket = CreateListenSocket(host, port); tcs.SetResult(0); } catch (Exception ex) @@ -65,16 +59,19 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return tcs.Task; } - private void OnConnection(UvStreamHandle listenSocket, int status) - { - var acceptSocket = new UvTcpHandle(); - acceptSocket.Init(Thread.Loop, Thread.QueueCloseHandle); - listenSocket.Accept(acceptSocket); + /// + /// Creates the socket used to listen for incoming connections + /// + protected abstract T CreateListenSocket(string host, int port); - DispatchConnection(acceptSocket); - } + /// + /// Handles an incoming connection + /// + /// Socket being used to listen on + /// Connection status + protected abstract void OnConnection(T listenSocket, int status); - protected virtual void DispatchConnection(UvTcpHandle socket) + protected virtual void DispatchConnection(T socket) { var connection = new Connection(this, socket); connection.Start(); diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerPrimary.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerPrimary.cs index f1299c073b..c534affe49 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerPrimary.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerPrimary.cs @@ -9,7 +9,11 @@ using System.Threading.Tasks; namespace Microsoft.AspNet.Server.Kestrel.Http { - public class ListenerPrimary : Listener + /// + /// A primary listener waits for incoming connections on a specified socket. Incoming + /// connections may be passed to a secondary listener to handle. + /// + abstract public class ListenerPrimary : Listener, IListenerPrimary where T : UvStreamHandle { UvPipeHandle ListenPipe { get; set; } @@ -17,7 +21,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http int _dispatchIndex; ArraySegment> _1234 = new ArraySegment>(new[] { new ArraySegment(new byte[] { 1, 2, 3, 4 }) }); - public ListenerPrimary(IMemoryPool memory) : base(memory) + protected ListenerPrimary(IMemoryPool memory) : base(memory) { } @@ -61,7 +65,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http _dispatchPipes.Add(dispatchPipe); } - protected override void DispatchConnection(UvTcpHandle socket) + protected override void DispatchConnection(T socket) { var index = _dispatchIndex++ % (_dispatchPipes.Count + 1); if (index == _dispatchPipes.Count) @@ -80,7 +84,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http (write2, status, error, state) => { write2.Dispose(); - ((UvTcpHandle)state).Dispose(); + ((T)state).Dispose(); }, socket); } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerSecondary.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerSecondary.cs index 99b21897be..32c7109553 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerSecondary.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerSecondary.cs @@ -9,11 +9,15 @@ using System.Threading.Tasks; namespace Microsoft.AspNet.Server.Kestrel.Http { - public class ListenerSecondary : ListenerContext, IDisposable + /// + /// A secondary listener is delegated requests from a primary listener via a named pipe or + /// UNIX domain socket. + /// + public abstract class ListenerSecondary : ListenerContext, IListenerSecondary where T : UvStreamHandle { UvPipeHandle DispatchPipe { get; set; } - public ListenerSecondary(IMemoryPool memory) + protected ListenerSecondary(IMemoryPool memory) { Memory = memory; } @@ -64,8 +68,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return; } - var acceptSocket = new UvTcpHandle(); - acceptSocket.Init(Thread.Loop, Thread.QueueCloseHandle); + var acceptSocket = CreateAcceptSocket(); try { @@ -102,6 +105,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return tcs.Task; } + /// + /// Creates a socket which can be used to accept an incoming connection + /// + protected abstract T CreateAcceptSocket(); + public void Dispose() { // Ensure the event loop is still running. diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/PipeListener.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/PipeListener.cs new file mode 100644 index 0000000000..64e732acaa --- /dev/null +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/PipeListener.cs @@ -0,0 +1,44 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using Microsoft.AspNet.Server.Kestrel.Infrastructure; +using Microsoft.AspNet.Server.Kestrel.Networking; + +namespace Microsoft.AspNet.Server.Kestrel.Http +{ + /// + /// Implementation of that uses UNIX domain sockets as its transport. + /// + public class PipeListener : Listener + { + public PipeListener(IMemoryPool memory) : base(memory) + { + } + + /// + /// Creates the socket used to listen for incoming connections + /// + protected override UvPipeHandle CreateListenSocket(string host, int port) + { + var socket = new UvPipeHandle(); + socket.Init(Thread.Loop, false); + socket.Bind(host); + socket.Listen(Constants.ListenBacklog, ConnectionCallback, this); + return socket; + } + + /// + /// Handles an incoming connection + /// + /// Socket being used to listen on + /// Connection status + protected override void OnConnection(UvPipeHandle listenSocket, int status) + { + var acceptSocket = new UvPipeHandle(); + acceptSocket.Init(Thread.Loop, false); + listenSocket.Accept(acceptSocket); + + DispatchConnection(acceptSocket); + } + } +} diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/PipeListenerPrimary.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/PipeListenerPrimary.cs new file mode 100644 index 0000000000..bcfb705fef --- /dev/null +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/PipeListenerPrimary.cs @@ -0,0 +1,44 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using Microsoft.AspNet.Server.Kestrel.Infrastructure; +using Microsoft.AspNet.Server.Kestrel.Networking; + +namespace Microsoft.AspNet.Server.Kestrel.Http +{ + /// + /// An implementation of using UNIX sockets. + /// + public class PipeListenerPrimary : ListenerPrimary + { + public PipeListenerPrimary(IMemoryPool memory) : base(memory) + { + } + + /// + /// Creates the socket used to listen for incoming connections + /// + protected override UvPipeHandle CreateListenSocket(string host, int port) + { + var socket = new UvPipeHandle(); + socket.Init(Thread.Loop, false); + socket.Bind(host); + socket.Listen(Constants.ListenBacklog, ConnectionCallback, this); + return socket; + } + + /// + /// Handles an incoming connection + /// + /// Socket being used to listen on + /// Connection status + protected override void OnConnection(UvPipeHandle listenSocket, int status) + { + var acceptSocket = new UvPipeHandle(); + acceptSocket.Init(Thread.Loop, false); + listenSocket.Accept(acceptSocket); + + DispatchConnection(acceptSocket); + } + } +} diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/PipeListenerSecondary.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/PipeListenerSecondary.cs new file mode 100644 index 0000000000..58f6d4d4b6 --- /dev/null +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/PipeListenerSecondary.cs @@ -0,0 +1,27 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using Microsoft.AspNet.Server.Kestrel.Networking; + +namespace Microsoft.AspNet.Server.Kestrel.Http +{ + /// + /// An implementation of using UNIX sockets. + /// + public class PipeListenerSecondary : ListenerSecondary + { + public PipeListenerSecondary(IMemoryPool memory) : base(memory) + { + } + + /// + /// Creates a socket which can be used to accept an incoming connection + /// + protected override UvPipeHandle CreateAcceptSocket() + { + var acceptSocket = new UvPipeHandle(); + acceptSocket.Init(Thread.Loop, false); + return acceptSocket; + } + } +} diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/TcpListener.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/TcpListener.cs new file mode 100644 index 0000000000..294674b746 --- /dev/null +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/TcpListener.cs @@ -0,0 +1,45 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System.Net; +using Microsoft.AspNet.Server.Kestrel.Infrastructure; +using Microsoft.AspNet.Server.Kestrel.Networking; + +namespace Microsoft.AspNet.Server.Kestrel.Http +{ + /// + /// Implementation of that uses TCP sockets as its transport. + /// + public class TcpListener : Listener + { + public TcpListener(IMemoryPool memory) : base(memory) + { + } + + /// + /// Creates the socket used to listen for incoming connections + /// + protected override UvTcpHandle CreateListenSocket(string host, int port) + { + var socket = new UvTcpHandle(); + socket.Init(Thread.Loop, Thread.QueueCloseHandle); + socket.Bind(new IPEndPoint(IPAddress.Any, port)); + socket.Listen(Constants.ListenBacklog, ConnectionCallback, this); + return socket; + } + + /// + /// Handle an incoming connection + /// + /// Socket being used to listen on + /// Connection status + protected override void OnConnection(UvTcpHandle listenSocket, int status) + { + var acceptSocket = new UvTcpHandle(); + acceptSocket.Init(Thread.Loop, Thread.QueueCloseHandle); + listenSocket.Accept(acceptSocket); + + DispatchConnection(acceptSocket); + } + } +} diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/TcpListenerPrimary.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/TcpListenerPrimary.cs new file mode 100644 index 0000000000..8242d7d403 --- /dev/null +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/TcpListenerPrimary.cs @@ -0,0 +1,45 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System.Net; +using Microsoft.AspNet.Server.Kestrel.Infrastructure; +using Microsoft.AspNet.Server.Kestrel.Networking; + +namespace Microsoft.AspNet.Server.Kestrel.Http +{ + /// + /// An implementation of using TCP sockets. + /// + public class TcpListenerPrimary : ListenerPrimary + { + public TcpListenerPrimary(IMemoryPool memory) : base(memory) + { + } + + /// + /// Creates the socket used to listen for incoming connections + /// + protected override UvTcpHandle CreateListenSocket(string host, int port) + { + var socket = new UvTcpHandle(); + socket.Init(Thread.Loop, Thread.QueueCloseHandle); + socket.Bind(new IPEndPoint(IPAddress.Any, port)); + socket.Listen(Constants.ListenBacklog, ConnectionCallback, this); + return socket; + } + + /// + /// Handles an incoming connection + /// + /// Socket being used to listen on + /// Connection status + protected override void OnConnection(UvTcpHandle listenSocket, int status) + { + var acceptSocket = new UvTcpHandle(); + acceptSocket.Init(Thread.Loop, Thread.QueueCloseHandle); + listenSocket.Accept(acceptSocket); + + DispatchConnection(acceptSocket); + } + } +} diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/TcpListenerSecondary.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/TcpListenerSecondary.cs new file mode 100644 index 0000000000..c7ec374c64 --- /dev/null +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/TcpListenerSecondary.cs @@ -0,0 +1,27 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using Microsoft.AspNet.Server.Kestrel.Networking; + +namespace Microsoft.AspNet.Server.Kestrel.Http +{ + /// + /// An implementation of using TCP sockets. + /// + public class TcpListenerSecondary : ListenerSecondary + { + public TcpListenerSecondary(IMemoryPool memory) : base(memory) + { + } + + /// + /// Creates a socket which can be used to accept an incoming connection + /// + protected override UvTcpHandle CreateAcceptSocket() + { + var acceptSocket = new UvTcpHandle(); + acceptSocket.Init(Thread.Loop, Thread.QueueCloseHandle); + return acceptSocket; + } + } +} diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/Constants.cs b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/Constants.cs index 48d6dc93e9..76b5f1bd5d 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/Constants.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/Constants.cs @@ -1,12 +1,15 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. namespace Microsoft.AspNet.Server.Kestrel.Infrastructure { internal class Constants { public const int ListenBacklog = 128; + + /// + /// URL scheme for specifying Unix sockets in the configuration. + /// + public const string UnixScheme = "unix"; } } diff --git a/src/Microsoft.AspNet.Server.Kestrel/KestrelEngine.cs b/src/Microsoft.AspNet.Server.Kestrel/KestrelEngine.cs index 1f356d16d1..6d5782d54b 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/KestrelEngine.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/KestrelEngine.cs @@ -6,6 +6,7 @@ using System.Collections.Generic; using System.IO; using System.Threading.Tasks; using Microsoft.AspNet.Server.Kestrel.Http; +using Microsoft.AspNet.Server.Kestrel.Infrastructure; using Microsoft.AspNet.Server.Kestrel.Networking; using Microsoft.Dnx.Runtime; @@ -69,7 +70,6 @@ namespace Microsoft.AspNet.Server.Kestrel { AppShutdown = appShutdownService; Threads = new List(); - Listeners = new List(); Memory = new MemoryPool(); } @@ -77,7 +77,6 @@ namespace Microsoft.AspNet.Server.Kestrel public IMemoryPool Memory { get; set; } public IApplicationShutdown AppShutdown { get; private set; } public List Threads { get; private set; } - public List Listeners { get; private set; } public void Start(int count) { @@ -104,6 +103,7 @@ namespace Microsoft.AspNet.Server.Kestrel public IDisposable CreateServer(string scheme, string host, int port, Func application) { var listeners = new List(); + var usingPipes = scheme == Constants.UnixScheme; try { @@ -116,19 +116,26 @@ namespace Microsoft.AspNet.Server.Kestrel { if (single) { - var listener = new Listener(Memory); + var listener = usingPipes ? + (IListener) new PipeListener(Memory) : + new TcpListener(Memory); listeners.Add(listener); listener.StartAsync(scheme, host, port, thread, application).Wait(); } else if (first) { - var listener = new ListenerPrimary(Memory); + var listener = usingPipes + ? (IListenerPrimary) new PipeListenerPrimary(Memory) + : new TcpListenerPrimary(Memory); + listeners.Add(listener); listener.StartAsync(pipeName, scheme, host, port, thread, application).Wait(); } else { - var listener = new ListenerSecondary(Memory); + var listener = usingPipes + ? (IListenerSecondary) new PipeListenerSecondary(Memory) + : new TcpListenerSecondary(Memory); listeners.Add(listener); listener.StartAsync(pipeName, thread, application).Wait(); } diff --git a/src/Microsoft.AspNet.Server.Kestrel/ServerFactory.cs b/src/Microsoft.AspNet.Server.Kestrel/ServerFactory.cs index e43e75aef0..0631303cac 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/ServerFactory.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/ServerFactory.cs @@ -6,9 +6,9 @@ using System.Collections.Generic; using System.Threading.Tasks; using Microsoft.AspNet.Hosting.Server; using Microsoft.AspNet.Http.Features; -using Microsoft.AspNet.Server.Kestrel; using Microsoft.Dnx.Runtime; using Microsoft.Framework.Configuration; +using Constants = Microsoft.AspNet.Server.Kestrel.Infrastructure.Constants; namespace Microsoft.AspNet.Server.Kestrel { @@ -43,7 +43,8 @@ namespace Microsoft.AspNet.Server.Kestrel { disposables.Add(engine.CreateServer( address.Scheme, - address.Host, + // Unix sockets use a file path, not a hostname. + address.Scheme == Constants.UnixScheme ? address.Path : address.Host, address.Port, async frame => { From ed9cd0ec1182da3f3e4963b08553535afd75bcee Mon Sep 17 00:00:00 2001 From: Pranav K Date: Mon, 17 Aug 2015 14:48:44 -0700 Subject: [PATCH 0207/1662] Updating to release NuGet.config. --- NuGet.Config | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/NuGet.Config b/NuGet.Config index 8b143c324c..e0b34f4aed 100644 --- a/NuGet.Config +++ b/NuGet.Config @@ -1,7 +1,7 @@ - + - + From 58292c662057fb22be7b255aebb4c06dda1c7d53 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Mon, 17 Aug 2015 15:55:04 -0700 Subject: [PATCH 0208/1662] Update "Kestrel" dependency in samples after rename --- samples/LargeResponseApp/project.json | 2 +- samples/SampleApp/Program.cs | 2 +- samples/SampleApp/project.json | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/samples/LargeResponseApp/project.json b/samples/LargeResponseApp/project.json index b2ce387239..7754a7b6f7 100644 --- a/samples/LargeResponseApp/project.json +++ b/samples/LargeResponseApp/project.json @@ -1,7 +1,7 @@ { "version": "1.0.0-*", "dependencies": { - "Kestrel": "1.0.0-*" + "Microsoft.AspNet.Server.Kestrel": "1.0.0-*" }, "frameworks": { diff --git a/samples/SampleApp/Program.cs b/samples/SampleApp/Program.cs index 9e1e66cd02..acf7f214c8 100644 --- a/samples/SampleApp/Program.cs +++ b/samples/SampleApp/Program.cs @@ -17,7 +17,7 @@ namespace SampleApp public void Main(string[] args) { new Microsoft.AspNet.Hosting.Program(_services).Main(new[] { - "--server","kestrel" + "--server", "Microsoft.AspNet.Server.Kestrel" }); } } diff --git a/samples/SampleApp/project.json b/samples/SampleApp/project.json index b7e9f3b993..7342e343c0 100644 --- a/samples/SampleApp/project.json +++ b/samples/SampleApp/project.json @@ -1,7 +1,7 @@ { "version": "1.0.0-*", "dependencies": { - "Kestrel": "1.0.0-*" + "Microsoft.AspNet.Server.Kestrel": "1.0.0-*" }, "frameworks": { "dnx451": { }, From b9dec6acfe5251842ef523a36dfbf058bc61db37 Mon Sep 17 00:00:00 2001 From: Pranav K Date: Tue, 18 Aug 2015 14:00:22 -0700 Subject: [PATCH 0209/1662] Updating to aspnetlitedev. --- NuGet.Config | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/NuGet.Config b/NuGet.Config index 8b143c324c..efb2034ee6 100644 --- a/NuGet.Config +++ b/NuGet.Config @@ -1,7 +1,7 @@ - + - + From 06551cda3da1ca54eb5482484af02e74907b566b Mon Sep 17 00:00:00 2001 From: Pranav K Date: Tue, 18 Aug 2015 14:00:22 -0700 Subject: [PATCH 0210/1662] Updating to aspnetliterelease. --- NuGet.Config | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NuGet.Config b/NuGet.Config index e0b34f4aed..f70ffcc085 100644 --- a/NuGet.Config +++ b/NuGet.Config @@ -1,7 +1,7 @@ - + From 7cdfdddaa0dfdfce8ebbfd49ec081f256f9a27de Mon Sep 17 00:00:00 2001 From: Pranav K Date: Tue, 18 Aug 2015 21:34:43 -0700 Subject: [PATCH 0211/1662] Unpinnng Dnx.Runtime.Abstractions package version --- src/Microsoft.AspNet.Server.Kestrel/project.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/project.json b/src/Microsoft.AspNet.Server.Kestrel/project.json index 0ff9347b82..883cf9570f 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/project.json +++ b/src/Microsoft.AspNet.Server.Kestrel/project.json @@ -7,7 +7,7 @@ }, "dependencies": { "Microsoft.AspNet.Hosting": "1.0.0-*", - "Microsoft.Dnx.Runtime.Abstractions": "1.0.0-beta7-*" + "Microsoft.Dnx.Runtime.Abstractions": "1.0.0-*" }, "frameworks": { "dnx451": { }, From f61a7b64ff27cf7518ce866258811aeb65547807 Mon Sep 17 00:00:00 2001 From: "N. Taylor Mullen" Date: Wed, 19 Aug 2015 14:54:19 -0700 Subject: [PATCH 0212/1662] Update NuGet feed from v2 => v3. --- NuGet.Config | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NuGet.Config b/NuGet.Config index efb2034ee6..41705755cf 100644 --- a/NuGet.Config +++ b/NuGet.Config @@ -4,6 +4,6 @@ - + \ No newline at end of file From 87d53700da8965687e48ba28e48663ad9fd07adb Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Wed, 19 Aug 2015 17:08:00 -0700 Subject: [PATCH 0213/1662] Make the GeneratedCode project work on CoreCLR --- .../project.json | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/project.json b/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/project.json index 6bede83d5a..75adb1ec73 100644 --- a/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/project.json +++ b/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/project.json @@ -16,6 +16,11 @@ "System.Text.Encoding": "", "System.Threading.Tasks": "" } + }, + "dnxcore50": { + "dependencies": { + "System.Console": "4.0.0-beta-*" + } } } } From 6bddf101edd6cabcfc0970eb9c4a638ab8006988 Mon Sep 17 00:00:00 2001 From: "N. Taylor Mullen" Date: Thu, 20 Aug 2015 15:37:56 -0700 Subject: [PATCH 0214/1662] Update 'build.cmd' to pull Sake from v2 NuGet feed. --- build.cmd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.cmd b/build.cmd index 231b6cc743..0dee2c2608 100644 --- a/build.cmd +++ b/build.cmd @@ -23,7 +23,7 @@ IF %BUILDCMD_KOREBUILD_VERSION%=="" ( ) ELSE ( .nuget\NuGet.exe install KoreBuild -version %BUILDCMD_KOREBUILD_VERSION% -ExcludeVersion -o packages -nocache -pre ) -.nuget\NuGet.exe install Sake -version 0.2 -o packages -ExcludeVersion +.nuget\NuGet.exe install Sake -ExcludeVersion -Source https://www.nuget.org/api/v2/ -Out packages IF "%SKIP_DNX_INSTALL%"=="1" goto run IF %BUILDCMD_DNX_VERSION%=="" ( From 41b7ce4b237a95d7bc74441064c3c6b0531d8ccd Mon Sep 17 00:00:00 2001 From: "N. Taylor Mullen" Date: Thu, 20 Aug 2015 20:46:47 -0700 Subject: [PATCH 0215/1662] Update 'build.sh' to pull Sake from v2 NuGet feed. --- build.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.sh b/build.sh index 3ef874f9bd..68c3e8cb52 100755 --- a/build.sh +++ b/build.sh @@ -24,7 +24,7 @@ fi if test ! -d packages/KoreBuild; then mono .nuget/nuget.exe install KoreBuild -ExcludeVersion -o packages -nocache -pre - mono .nuget/nuget.exe install Sake -version 0.2 -o packages -ExcludeVersion + mono .nuget/nuget.exe install Sake -ExcludeVersion -Source https://www.nuget.org/api/v2/ -Out packages fi if ! type dnvm > /dev/null 2>&1; then From 69759231ff8aff3fda5056ee58be0d5c729a6bd7 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Tue, 25 Aug 2015 23:07:03 -0700 Subject: [PATCH 0216/1662] Set Content-Length: 0 when an AppFunc completes without a write - Previously an incomplete chunked response would be written instead. - Add test to verify Content-Length: 0 is set automatically. - Add test to verify HTTP/1.0 keep-alive isn't used if no Content-Length is set for the response. - Add tests to verify errors are handled properly after chunked writes. #173 --- .../Http/Frame.cs | 30 ++++--- .../ChunkedResponseTests.cs | 81 +++++++++++++++++++ .../EngineTests.cs | 54 +++++++++++++ 3 files changed, 156 insertions(+), 9 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs index 43bed07978..a78d7f7eae 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs @@ -254,11 +254,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { FireOnStarting(); } - - if (_autoChunk) - { - WriteChunkedResponseSuffix(); - } } catch (Exception ex) { @@ -380,7 +375,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } - public void ProduceStart(bool immediate = true) + public void ProduceStart(bool immediate = true, bool appCompleted = false) { // ProduceStart shouldn't no-op in the future just b/c FireOnStarting throws. if (_responseStarted) return; @@ -389,7 +384,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http var status = ReasonPhrases.ToStatus(StatusCode, ReasonPhrase); - var responseHeader = CreateResponseHeader(status, ResponseHeaders); + var responseHeader = CreateResponseHeader(status, appCompleted, ResponseHeaders); SocketOutput.Write( responseHeader.Item1, (error, x) => @@ -428,7 +423,14 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } - ProduceStart(); + ProduceStart(immediate: true, appCompleted: true); + + // _autoChunk should be checked after we are sure ProduceStart() has been called + // since ProduceStart() may set _autoChunk to true. + if (_autoChunk) + { + WriteChunkedResponseSuffix(); + } if (!_keepAlive) { @@ -440,7 +442,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } private Tuple, IDisposable> CreateResponseHeader( - string status, IEnumerable> headers) + string status, + bool appCompleted, + IEnumerable> headers) { var writer = new MemoryPoolTextWriter(Memory); writer.Write(HttpVersion); @@ -490,6 +494,14 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } + if (appCompleted && !hasTransferEncoding && !hasContentLength) + { + // Since the app has completed and we are only now generating + // the headers we can safely set the Content-Length to 0. + writer.Write("Content-Length: 0\r\n"); + hasContentLength = true; + } + if (_keepAlive && !hasTransferEncoding && !hasContentLength) { if (HttpVersion == "HTTP/1.1") diff --git a/test/Microsoft.AspNet.Server.KestrelTests/ChunkedResponseTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/ChunkedResponseTests.cs index a1b7ac186d..162a29263a 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/ChunkedResponseTests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/ChunkedResponseTests.cs @@ -1,6 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; using System.Text; using System.Threading.Tasks; using Xunit; @@ -71,5 +72,85 @@ namespace Microsoft.AspNet.Server.KestrelTests } } } + + [Fact] + public async Task EmptyResponseBodyHandledCorrectlyWithZeroLengthWrite() + { + using (var server = new TestServer(async frame => + { + frame.ResponseHeaders.Clear(); + await frame.ResponseBody.WriteAsync(new byte[0], 0, 0); + })) + { + using (var connection = new TestConnection()) + { + await connection.SendEnd( + "GET / HTTP/1.1", + "", + ""); + await connection.ReceiveEnd( + "HTTP/1.1 200 OK", + "Transfer-Encoding: chunked", + "", + "0", + "", + ""); + } + } + } + + [Fact] + public async Task ConnectionClosedIfExeptionThrownAfterWrite() + { + using (var server = new TestServer(async frame => + { + frame.ResponseHeaders.Clear(); + await frame.ResponseBody.WriteAsync(Encoding.ASCII.GetBytes("Hello World!"), 0, 12); + throw new Exception(); + })) + { + using (var connection = new TestConnection()) + { + // SendEnd is not called, so it isn't the client closing the connection. + // client closing the connection. + await connection.Send( + "GET / HTTP/1.1", + "", + ""); + await connection.ReceiveEnd( + "HTTP/1.1 200 OK", + "Transfer-Encoding: chunked", + "", + "c", + "Hello World!", + ""); + } + } + } + + [Fact] + public async Task ConnectionClosedIfExeptionThrownAfterZeroLengthWrite() + { + using (var server = new TestServer(async frame => + { + frame.ResponseHeaders.Clear(); + await frame.ResponseBody.WriteAsync(new byte[0], 0, 0); + throw new Exception(); + })) + { + using (var connection = new TestConnection()) + { + // SendEnd is not called, so it isn't the client closing the connection. + await connection.Send( + "GET / HTTP/1.1", + "", + ""); + + // Nothing (not even headers) are written, but the connection is closed. + await connection.ReceiveEnd(); + } + } + } } } + diff --git a/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs index 27526edd83..d36d02aee8 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs @@ -235,6 +235,35 @@ namespace Microsoft.AspNet.Server.KestrelTests } } + [Fact] + public async Task Http10KeepAliveNotUsedIfResponseContentLengthNotSet() + { + using (var server = new TestServer(App)) + { + using (var connection = new TestConnection()) + { + await connection.SendEnd( + "GET / HTTP/1.0", + "Connection: keep-alive", + "", + "POST / HTTP/1.0", + "Connection: keep-alive", + "Content-Length: 7", + "", + "Goodbye"); + await connection.Receive( + "HTTP/1.0 200 OK", + "Content-Length: 0", + "Connection: keep-alive", + "\r\n"); + await connection.ReceiveEnd( + "HTTP/1.0 200 OK", + "", + "Goodbye"); + } + } + } + [Fact] public async Task Http10KeepAliveContentLength() { @@ -341,11 +370,36 @@ namespace Microsoft.AspNet.Server.KestrelTests "\r\n"); await connection.ReceiveEnd( "HTTP/1.0 200 OK", + "Content-Length: 0", "\r\n"); } } } + [Fact] + public async Task EmptyResponseBodyHandledCorrectlyWithoutAnyWrites() + { + using (var server = new TestServer(frame => + { + frame.ResponseHeaders.Clear(); + return Task.FromResult(null); + })) + { + using (var connection = new TestConnection()) + { + await connection.SendEnd( + "GET / HTTP/1.1", + "", + ""); + await connection.ReceiveEnd( + "HTTP/1.1 200 OK", + "Content-Length: 0", + "", + ""); + } + } + } + [Fact] public async Task ThrowingResultsIn500Response() { From 2642c84bf99190eed5f454e6c37b88b913dbf596 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Wed, 26 Aug 2015 12:41:14 -0700 Subject: [PATCH 0217/1662] Don't automatically set Content-Length: 0 in some circumstances - When in response to a HEAD Request - For 101, 204, 205 and 304 responses - For non keep-alive connections --- .../Http/Frame.cs | 40 ++++-- .../EngineTests.cs | 124 +++++++++++++++++- 2 files changed, 145 insertions(+), 19 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs index a78d7f7eae..d5dc958080 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs @@ -494,26 +494,33 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } - if (appCompleted && !hasTransferEncoding && !hasContentLength) - { - // Since the app has completed and we are only now generating - // the headers we can safely set the Content-Length to 0. - writer.Write("Content-Length: 0\r\n"); - hasContentLength = true; - } - if (_keepAlive && !hasTransferEncoding && !hasContentLength) { - if (HttpVersion == "HTTP/1.1") + if (appCompleted) { - _autoChunk = true; - writer.Write("Transfer-Encoding: chunked\r\n"); + // Don't set the Content-Length or Transfer-Encoding headers + // automatically for HEAD requests or 101, 204, 205, 304 responses. + if (Method != "HEAD" && StatusCanHaveBody(StatusCode)) + { + // Since the app has completed and we are only now generating + // the headers we can safely set the Content-Length to 0. + writer.Write("Content-Length: 0\r\n"); + } } else { - _keepAlive = false; + if (HttpVersion == "HTTP/1.1") + { + _autoChunk = true; + writer.Write("Transfer-Encoding: chunked\r\n"); + } + else + { + _keepAlive = false; + } } } + if (_keepAlive == false && hasConnection == false && HttpVersion == "HTTP/1.1") { writer.Write("Connection: close\r\n\r\n"); @@ -673,5 +680,14 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { _requestHeaders.Append(keyBytes, keyOffset, keyLength, value); } + + public bool StatusCanHaveBody(int statusCode) + { + // List of status codes taken from Microsoft.Net.Http.Server.Response + return statusCode != 101 && + statusCode != 204 && + statusCode != 205 && + statusCode != 304; + } } } diff --git a/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs index d36d02aee8..a293e8bae9 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs @@ -77,6 +77,12 @@ namespace Microsoft.AspNet.Server.KestrelTests await frame.ResponseBody.WriteAsync(bytes, 0, bytes.Length); } + private Task EmptyApp(Frame frame) + { + frame.ResponseHeaders.Clear(); + return Task.FromResult(null); + } + [Fact] public void EngineCanStartAndStop() { @@ -370,28 +376,132 @@ namespace Microsoft.AspNet.Server.KestrelTests "\r\n"); await connection.ReceiveEnd( "HTTP/1.0 200 OK", - "Content-Length: 0", "\r\n"); } } } [Fact] - public async Task EmptyResponseBodyHandledCorrectlyWithoutAnyWrites() + public async Task ZeroContentLengthSetAutomaticallyAfterNoWrites() { - using (var server = new TestServer(frame => - { - frame.ResponseHeaders.Clear(); - return Task.FromResult(null); - })) + using (var server = new TestServer(EmptyApp)) { using (var connection = new TestConnection()) { await connection.SendEnd( "GET / HTTP/1.1", "", + "GET / HTTP/1.0", + "Connection: keep-alive", + "", ""); await connection.ReceiveEnd( + "HTTP/1.1 200 OK", + "Content-Length: 0", + "", + "HTTP/1.0 200 OK", + "Content-Length: 0", + "Connection: keep-alive", + "", + ""); + } + } + } + + [Fact] + public async Task ZeroContentLengthNotSetAutomaticallyForNonKeepAliveRequests() + { + using (var server = new TestServer(EmptyApp)) + { + using (var connection = new TestConnection()) + { + await connection.SendEnd( + "GET / HTTP/1.1", + "Connection: close", + "", + ""); + await connection.ReceiveEnd( + "HTTP/1.1 200 OK", + "Connection: close", + "", + ""); + } + + using (var connection = new TestConnection()) + { + await connection.SendEnd( + "GET / HTTP/1.0", + "", + ""); + await connection.ReceiveEnd( + "HTTP/1.0 200 OK", + "", + ""); + } + } + } + + [Fact] + public async Task ZeroContentLengthNotSetAutomaticallyForHeadRequests() + { + using (var server = new TestServer(EmptyApp)) + { + using (var connection = new TestConnection()) + { + await connection.SendEnd( + "HEAD / HTTP/1.1", + "", + ""); + await connection.ReceiveEnd( + "HTTP/1.1 200 OK", + "", + ""); + } + } + } + + [Fact] + public async Task ZeroContentLengthNotSetAutomaticallyForCertainStatusCodes() + { + using (var server = new TestServer(async frame => + { + frame.ResponseHeaders.Clear(); + + using (var reader = new StreamReader(frame.RequestBody, Encoding.ASCII)) + { + var statusString = await reader.ReadLineAsync(); + frame.StatusCode = int.Parse(statusString); + } + })) + { + using (var connection = new TestConnection()) + { + await connection.SendEnd( + "POST / HTTP/1.1", + "Content-Length: 3", + "", + "101POST / HTTP/1.1", + "Content-Length: 3", + "", + "204POST / HTTP/1.1", + "Content-Length: 3", + "", + "205POST / HTTP/1.1", + "Content-Length: 3", + "", + "304POST / HTTP/1.1", + "Content-Length: 3", + "", + "200"); + await connection.ReceiveEnd( + "HTTP/1.1 101 Switching Protocols", + "", + "HTTP/1.1 204 No Content", + "", + "HTTP/1.1 205 Reset Content", + "", + "HTTP/1.1 304 Not Modified", + "", "HTTP/1.1 200 OK", "Content-Length: 0", "", From 803ec3807331a2b4a125d153da69ffb023efa83f Mon Sep 17 00:00:00 2001 From: Chris R Date: Fri, 28 Aug 2015 12:59:00 -0700 Subject: [PATCH 0218/1662] React to string[] -> StringValues changes. --- .../Http/Frame.cs | 9 +- .../Http/FrameHeaders.Generated.cs | 615 +++++++++--------- .../Http/FrameHeaders.cs | 90 ++- .../Http/MessageBody.cs | 9 +- .../ServerRequest.cs | 11 +- .../FrameRequestHeadersTests.cs | 72 +- .../FrameResponseHeadersTests.cs | 13 +- .../MessageBodyTests.cs | 7 +- .../KnownHeaders.cs | 34 +- 9 files changed, 434 insertions(+), 426 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs index d5dc958080..ded01e3efa 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs @@ -8,6 +8,7 @@ using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; +using Microsoft.Framework.Primitives; // ReSharper disable AccessToModifiedClosure @@ -55,13 +56,13 @@ namespace Microsoft.AspNet.Server.Kestrel.Http public string Path { get; set; } public string QueryString { get; set; } public string HttpVersion { get; set; } - public IDictionary RequestHeaders { get; set; } + public IDictionary RequestHeaders { get; set; } public MessageBody MessageBody { get; set; } public Stream RequestBody { get; set; } public int StatusCode { get; set; } public string ReasonPhrase { get; set; } - public IDictionary ResponseHeaders { get; set; } + public IDictionary ResponseHeaders { get; set; } public Stream ResponseBody { get; set; } public Stream DuplexStream { get; set; } @@ -357,7 +358,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { if (_responseStarted) return; - string[] expect; + StringValues expect; if (HttpVersion.Equals("HTTP/1.1") && RequestHeaders.TryGetValue("Expect", out expect) && (expect.FirstOrDefault() ?? "").Equals("100-continue", StringComparison.OrdinalIgnoreCase)) @@ -444,7 +445,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http private Tuple, IDisposable> CreateResponseHeader( string status, bool appCompleted, - IEnumerable> headers) + IEnumerable> headers) { var writer = new MemoryPoolTextWriter(Memory); writer.Write(HttpVersion); diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameHeaders.Generated.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameHeaders.Generated.cs index 686527fadc..a79b61d4c4 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameHeaders.Generated.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameHeaders.Generated.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; +using Microsoft.Framework.Primitives; namespace Microsoft.AspNet.Server.Kestrel.Http { @@ -8,8 +9,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { public FrameResponseHeaders() { - _Server = new[] { "Kestrel" }; - _Date = new[] { DateTime.UtcNow.ToString("r") }; + _Server = "Kestrel"; + _Date = DateTime.UtcNow.ToString("r"); _bits = 67108868L; } } @@ -18,47 +19,47 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { long _bits = 0; - string[] _CacheControl; - string[] _Connection; - string[] _Date; - string[] _KeepAlive; - string[] _Pragma; - string[] _Trailer; - string[] _TransferEncoding; - string[] _Upgrade; - string[] _Via; - string[] _Warning; - string[] _Allow; - string[] _ContentLength; - string[] _ContentType; - string[] _ContentEncoding; - string[] _ContentLanguage; - string[] _ContentLocation; - string[] _ContentMD5; - string[] _ContentRange; - string[] _Expires; - string[] _LastModified; - string[] _Accept; - string[] _AcceptCharset; - string[] _AcceptEncoding; - string[] _AcceptLanguage; - string[] _Authorization; - string[] _Cookie; - string[] _Expect; - string[] _From; - string[] _Host; - string[] _IfMatch; - string[] _IfModifiedSince; - string[] _IfNoneMatch; - string[] _IfRange; - string[] _IfUnmodifiedSince; - string[] _MaxForwards; - string[] _ProxyAuthorization; - string[] _Referer; - string[] _Range; - string[] _TE; - string[] _Translate; - string[] _UserAgent; + StringValues _CacheControl; + StringValues _Connection; + StringValues _Date; + StringValues _KeepAlive; + StringValues _Pragma; + StringValues _Trailer; + StringValues _TransferEncoding; + StringValues _Upgrade; + StringValues _Via; + StringValues _Warning; + StringValues _Allow; + StringValues _ContentLength; + StringValues _ContentType; + StringValues _ContentEncoding; + StringValues _ContentLanguage; + StringValues _ContentLocation; + StringValues _ContentMD5; + StringValues _ContentRange; + StringValues _Expires; + StringValues _LastModified; + StringValues _Accept; + StringValues _AcceptCharset; + StringValues _AcceptEncoding; + StringValues _AcceptLanguage; + StringValues _Authorization; + StringValues _Cookie; + StringValues _Expect; + StringValues _From; + StringValues _Host; + StringValues _IfMatch; + StringValues _IfModifiedSince; + StringValues _IfNoneMatch; + StringValues _IfRange; + StringValues _IfUnmodifiedSince; + StringValues _MaxForwards; + StringValues _ProxyAuthorization; + StringValues _Referer; + StringValues _Range; + StringValues _TE; + StringValues _Translate; + StringValues _UserAgent; protected override int GetCountFast() { @@ -272,7 +273,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return count; } - protected override string[] GetValueFast(string key) + protected override StringValues GetValueFast(string key) { switch(key.Length) { @@ -843,7 +844,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return MaybeUnknown[key]; } - protected override bool TryGetValueFast(string key, out string[] value) + protected override bool TryGetValueFast(string key, out StringValues value) { switch(key.Length) { @@ -858,7 +859,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } else { - value = null; + value = StringValues.Empty; return false; } } @@ -872,7 +873,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } else { - value = null; + value = StringValues.Empty; return false; } } @@ -886,7 +887,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } else { - value = null; + value = StringValues.Empty; return false; } } @@ -900,7 +901,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } else { - value = null; + value = StringValues.Empty; return false; } } @@ -914,7 +915,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } else { - value = null; + value = StringValues.Empty; return false; } } @@ -932,7 +933,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } else { - value = null; + value = StringValues.Empty; return false; } } @@ -946,7 +947,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } else { - value = null; + value = StringValues.Empty; return false; } } @@ -960,7 +961,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } else { - value = null; + value = StringValues.Empty; return false; } } @@ -978,7 +979,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } else { - value = null; + value = StringValues.Empty; return false; } } @@ -992,7 +993,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } else { - value = null; + value = StringValues.Empty; return false; } } @@ -1006,7 +1007,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } else { - value = null; + value = StringValues.Empty; return false; } } @@ -1024,7 +1025,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } else { - value = null; + value = StringValues.Empty; return false; } } @@ -1038,7 +1039,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } else { - value = null; + value = StringValues.Empty; return false; } } @@ -1052,7 +1053,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } else { - value = null; + value = StringValues.Empty; return false; } } @@ -1066,7 +1067,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } else { - value = null; + value = StringValues.Empty; return false; } } @@ -1084,7 +1085,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } else { - value = null; + value = StringValues.Empty; return false; } } @@ -1098,7 +1099,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } else { - value = null; + value = StringValues.Empty; return false; } } @@ -1112,7 +1113,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } else { - value = null; + value = StringValues.Empty; return false; } } @@ -1126,7 +1127,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } else { - value = null; + value = StringValues.Empty; return false; } } @@ -1140,7 +1141,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } else { - value = null; + value = StringValues.Empty; return false; } } @@ -1158,7 +1159,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } else { - value = null; + value = StringValues.Empty; return false; } } @@ -1172,7 +1173,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } else { - value = null; + value = StringValues.Empty; return false; } } @@ -1190,7 +1191,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } else { - value = null; + value = StringValues.Empty; return false; } } @@ -1208,7 +1209,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } else { - value = null; + value = StringValues.Empty; return false; } } @@ -1222,7 +1223,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } else { - value = null; + value = StringValues.Empty; return false; } } @@ -1240,7 +1241,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } else { - value = null; + value = StringValues.Empty; return false; } } @@ -1254,7 +1255,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } else { - value = null; + value = StringValues.Empty; return false; } } @@ -1272,7 +1273,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } else { - value = null; + value = StringValues.Empty; return false; } } @@ -1286,7 +1287,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } else { - value = null; + value = StringValues.Empty; return false; } } @@ -1304,7 +1305,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } else { - value = null; + value = StringValues.Empty; return false; } } @@ -1318,7 +1319,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } else { - value = null; + value = StringValues.Empty; return false; } } @@ -1332,7 +1333,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } else { - value = null; + value = StringValues.Empty; return false; } } @@ -1350,7 +1351,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } else { - value = null; + value = StringValues.Empty; return false; } } @@ -1368,7 +1369,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } else { - value = null; + value = StringValues.Empty; return false; } } @@ -1382,7 +1383,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } else { - value = null; + value = StringValues.Empty; return false; } } @@ -1400,7 +1401,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } else { - value = null; + value = StringValues.Empty; return false; } } @@ -1414,7 +1415,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } else { - value = null; + value = StringValues.Empty; return false; } } @@ -1432,7 +1433,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } else { - value = null; + value = StringValues.Empty; return false; } } @@ -1446,7 +1447,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } else { - value = null; + value = StringValues.Empty; return false; } } @@ -1464,7 +1465,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } else { - value = null; + value = StringValues.Empty; return false; } } @@ -1482,18 +1483,18 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } else { - value = null; + value = StringValues.Empty; return false; } } } break; } - value = null; + value = StringValues.Empty; return MaybeUnknown?.TryGetValue(key, out value) ?? false; } - protected override void SetValueFast(string key, string[] value) + protected override void SetValueFast(string key, StringValues value) { switch(key.Length) { @@ -1855,7 +1856,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http Unknown[key] = value; } - protected override void AddValueFast(string key, string[] value) + protected override void AddValueFast(string key, StringValues value) { switch(key.Length) { @@ -2995,7 +2996,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http MaybeUnknown?.Clear(); } - protected override void CopyToFast(KeyValuePair[] array, int arrayIndex) + protected override void CopyToFast(KeyValuePair[] array, int arrayIndex) { if (arrayIndex < 0) { @@ -3010,7 +3011,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http throw new ArgumentException(); } - array[arrayIndex] = new KeyValuePair("Cache-Control", _CacheControl); + array[arrayIndex] = new KeyValuePair("Cache-Control", _CacheControl); ++arrayIndex; } @@ -3021,7 +3022,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http throw new ArgumentException(); } - array[arrayIndex] = new KeyValuePair("Connection", _Connection); + array[arrayIndex] = new KeyValuePair("Connection", _Connection); ++arrayIndex; } @@ -3032,7 +3033,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http throw new ArgumentException(); } - array[arrayIndex] = new KeyValuePair("Date", _Date); + array[arrayIndex] = new KeyValuePair("Date", _Date); ++arrayIndex; } @@ -3043,7 +3044,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http throw new ArgumentException(); } - array[arrayIndex] = new KeyValuePair("Keep-Alive", _KeepAlive); + array[arrayIndex] = new KeyValuePair("Keep-Alive", _KeepAlive); ++arrayIndex; } @@ -3054,7 +3055,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http throw new ArgumentException(); } - array[arrayIndex] = new KeyValuePair("Pragma", _Pragma); + array[arrayIndex] = new KeyValuePair("Pragma", _Pragma); ++arrayIndex; } @@ -3065,7 +3066,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http throw new ArgumentException(); } - array[arrayIndex] = new KeyValuePair("Trailer", _Trailer); + array[arrayIndex] = new KeyValuePair("Trailer", _Trailer); ++arrayIndex; } @@ -3076,7 +3077,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http throw new ArgumentException(); } - array[arrayIndex] = new KeyValuePair("Transfer-Encoding", _TransferEncoding); + array[arrayIndex] = new KeyValuePair("Transfer-Encoding", _TransferEncoding); ++arrayIndex; } @@ -3087,7 +3088,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http throw new ArgumentException(); } - array[arrayIndex] = new KeyValuePair("Upgrade", _Upgrade); + array[arrayIndex] = new KeyValuePair("Upgrade", _Upgrade); ++arrayIndex; } @@ -3098,7 +3099,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http throw new ArgumentException(); } - array[arrayIndex] = new KeyValuePair("Via", _Via); + array[arrayIndex] = new KeyValuePair("Via", _Via); ++arrayIndex; } @@ -3109,7 +3110,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http throw new ArgumentException(); } - array[arrayIndex] = new KeyValuePair("Warning", _Warning); + array[arrayIndex] = new KeyValuePair("Warning", _Warning); ++arrayIndex; } @@ -3120,7 +3121,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http throw new ArgumentException(); } - array[arrayIndex] = new KeyValuePair("Allow", _Allow); + array[arrayIndex] = new KeyValuePair("Allow", _Allow); ++arrayIndex; } @@ -3131,7 +3132,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http throw new ArgumentException(); } - array[arrayIndex] = new KeyValuePair("Content-Length", _ContentLength); + array[arrayIndex] = new KeyValuePair("Content-Length", _ContentLength); ++arrayIndex; } @@ -3142,7 +3143,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http throw new ArgumentException(); } - array[arrayIndex] = new KeyValuePair("Content-Type", _ContentType); + array[arrayIndex] = new KeyValuePair("Content-Type", _ContentType); ++arrayIndex; } @@ -3153,7 +3154,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http throw new ArgumentException(); } - array[arrayIndex] = new KeyValuePair("Content-Encoding", _ContentEncoding); + array[arrayIndex] = new KeyValuePair("Content-Encoding", _ContentEncoding); ++arrayIndex; } @@ -3164,7 +3165,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http throw new ArgumentException(); } - array[arrayIndex] = new KeyValuePair("Content-Language", _ContentLanguage); + array[arrayIndex] = new KeyValuePair("Content-Language", _ContentLanguage); ++arrayIndex; } @@ -3175,7 +3176,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http throw new ArgumentException(); } - array[arrayIndex] = new KeyValuePair("Content-Location", _ContentLocation); + array[arrayIndex] = new KeyValuePair("Content-Location", _ContentLocation); ++arrayIndex; } @@ -3186,7 +3187,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http throw new ArgumentException(); } - array[arrayIndex] = new KeyValuePair("Content-MD5", _ContentMD5); + array[arrayIndex] = new KeyValuePair("Content-MD5", _ContentMD5); ++arrayIndex; } @@ -3197,7 +3198,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http throw new ArgumentException(); } - array[arrayIndex] = new KeyValuePair("Content-Range", _ContentRange); + array[arrayIndex] = new KeyValuePair("Content-Range", _ContentRange); ++arrayIndex; } @@ -3208,7 +3209,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http throw new ArgumentException(); } - array[arrayIndex] = new KeyValuePair("Expires", _Expires); + array[arrayIndex] = new KeyValuePair("Expires", _Expires); ++arrayIndex; } @@ -3219,7 +3220,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http throw new ArgumentException(); } - array[arrayIndex] = new KeyValuePair("Last-Modified", _LastModified); + array[arrayIndex] = new KeyValuePair("Last-Modified", _LastModified); ++arrayIndex; } @@ -3230,7 +3231,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http throw new ArgumentException(); } - array[arrayIndex] = new KeyValuePair("Accept", _Accept); + array[arrayIndex] = new KeyValuePair("Accept", _Accept); ++arrayIndex; } @@ -3241,7 +3242,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http throw new ArgumentException(); } - array[arrayIndex] = new KeyValuePair("Accept-Charset", _AcceptCharset); + array[arrayIndex] = new KeyValuePair("Accept-Charset", _AcceptCharset); ++arrayIndex; } @@ -3252,7 +3253,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http throw new ArgumentException(); } - array[arrayIndex] = new KeyValuePair("Accept-Encoding", _AcceptEncoding); + array[arrayIndex] = new KeyValuePair("Accept-Encoding", _AcceptEncoding); ++arrayIndex; } @@ -3263,7 +3264,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http throw new ArgumentException(); } - array[arrayIndex] = new KeyValuePair("Accept-Language", _AcceptLanguage); + array[arrayIndex] = new KeyValuePair("Accept-Language", _AcceptLanguage); ++arrayIndex; } @@ -3274,7 +3275,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http throw new ArgumentException(); } - array[arrayIndex] = new KeyValuePair("Authorization", _Authorization); + array[arrayIndex] = new KeyValuePair("Authorization", _Authorization); ++arrayIndex; } @@ -3285,7 +3286,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http throw new ArgumentException(); } - array[arrayIndex] = new KeyValuePair("Cookie", _Cookie); + array[arrayIndex] = new KeyValuePair("Cookie", _Cookie); ++arrayIndex; } @@ -3296,7 +3297,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http throw new ArgumentException(); } - array[arrayIndex] = new KeyValuePair("Expect", _Expect); + array[arrayIndex] = new KeyValuePair("Expect", _Expect); ++arrayIndex; } @@ -3307,7 +3308,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http throw new ArgumentException(); } - array[arrayIndex] = new KeyValuePair("From", _From); + array[arrayIndex] = new KeyValuePair("From", _From); ++arrayIndex; } @@ -3318,7 +3319,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http throw new ArgumentException(); } - array[arrayIndex] = new KeyValuePair("Host", _Host); + array[arrayIndex] = new KeyValuePair("Host", _Host); ++arrayIndex; } @@ -3329,7 +3330,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http throw new ArgumentException(); } - array[arrayIndex] = new KeyValuePair("If-Match", _IfMatch); + array[arrayIndex] = new KeyValuePair("If-Match", _IfMatch); ++arrayIndex; } @@ -3340,7 +3341,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http throw new ArgumentException(); } - array[arrayIndex] = new KeyValuePair("If-Modified-Since", _IfModifiedSince); + array[arrayIndex] = new KeyValuePair("If-Modified-Since", _IfModifiedSince); ++arrayIndex; } @@ -3351,7 +3352,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http throw new ArgumentException(); } - array[arrayIndex] = new KeyValuePair("If-None-Match", _IfNoneMatch); + array[arrayIndex] = new KeyValuePair("If-None-Match", _IfNoneMatch); ++arrayIndex; } @@ -3362,7 +3363,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http throw new ArgumentException(); } - array[arrayIndex] = new KeyValuePair("If-Range", _IfRange); + array[arrayIndex] = new KeyValuePair("If-Range", _IfRange); ++arrayIndex; } @@ -3373,7 +3374,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http throw new ArgumentException(); } - array[arrayIndex] = new KeyValuePair("If-Unmodified-Since", _IfUnmodifiedSince); + array[arrayIndex] = new KeyValuePair("If-Unmodified-Since", _IfUnmodifiedSince); ++arrayIndex; } @@ -3384,7 +3385,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http throw new ArgumentException(); } - array[arrayIndex] = new KeyValuePair("Max-Forwards", _MaxForwards); + array[arrayIndex] = new KeyValuePair("Max-Forwards", _MaxForwards); ++arrayIndex; } @@ -3395,7 +3396,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http throw new ArgumentException(); } - array[arrayIndex] = new KeyValuePair("Proxy-Authorization", _ProxyAuthorization); + array[arrayIndex] = new KeyValuePair("Proxy-Authorization", _ProxyAuthorization); ++arrayIndex; } @@ -3406,7 +3407,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http throw new ArgumentException(); } - array[arrayIndex] = new KeyValuePair("Referer", _Referer); + array[arrayIndex] = new KeyValuePair("Referer", _Referer); ++arrayIndex; } @@ -3417,7 +3418,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http throw new ArgumentException(); } - array[arrayIndex] = new KeyValuePair("Range", _Range); + array[arrayIndex] = new KeyValuePair("Range", _Range); ++arrayIndex; } @@ -3428,7 +3429,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http throw new ArgumentException(); } - array[arrayIndex] = new KeyValuePair("TE", _TE); + array[arrayIndex] = new KeyValuePair("TE", _TE); ++arrayIndex; } @@ -3439,7 +3440,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http throw new ArgumentException(); } - array[arrayIndex] = new KeyValuePair("Translate", _Translate); + array[arrayIndex] = new KeyValuePair("Translate", _Translate); ++arrayIndex; } @@ -3450,11 +3451,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http throw new ArgumentException(); } - array[arrayIndex] = new KeyValuePair("User-Agent", _UserAgent); + array[arrayIndex] = new KeyValuePair("User-Agent", _UserAgent); ++arrayIndex; } - ((ICollection>)MaybeUnknown)?.CopyTo(array, arrayIndex); + ((ICollection>)MaybeUnknown)?.CopyTo(array, arrayIndex); } public unsafe void Append(byte[] keyBytes, int keyOffset, int keyLength, string value) @@ -4105,8 +4106,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Http break; }} var key = System.Text.Encoding.ASCII.GetString(keyBytes, keyOffset, keyLength); - string[] existing; - Unknown[key] = Unknown.TryGetValue(key, out existing) ? AppendValue(existing, value) : new[] {value}; + StringValues existing; + Unknown.TryGetValue(key, out existing); + Unknown[key] = AppendValue(existing, value); } public partial struct Enumerator @@ -4246,7 +4248,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http state0: if (((_bits & 1L) != 0)) { - _current = new KeyValuePair("Cache-Control", _collection._CacheControl); + _current = new KeyValuePair("Cache-Control", _collection._CacheControl); _state = 1; return true; } @@ -4254,7 +4256,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http state1: if (((_bits & 2L) != 0)) { - _current = new KeyValuePair("Connection", _collection._Connection); + _current = new KeyValuePair("Connection", _collection._Connection); _state = 2; return true; } @@ -4262,7 +4264,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http state2: if (((_bits & 4L) != 0)) { - _current = new KeyValuePair("Date", _collection._Date); + _current = new KeyValuePair("Date", _collection._Date); _state = 3; return true; } @@ -4270,7 +4272,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http state3: if (((_bits & 8L) != 0)) { - _current = new KeyValuePair("Keep-Alive", _collection._KeepAlive); + _current = new KeyValuePair("Keep-Alive", _collection._KeepAlive); _state = 4; return true; } @@ -4278,7 +4280,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http state4: if (((_bits & 16L) != 0)) { - _current = new KeyValuePair("Pragma", _collection._Pragma); + _current = new KeyValuePair("Pragma", _collection._Pragma); _state = 5; return true; } @@ -4286,7 +4288,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http state5: if (((_bits & 32L) != 0)) { - _current = new KeyValuePair("Trailer", _collection._Trailer); + _current = new KeyValuePair("Trailer", _collection._Trailer); _state = 6; return true; } @@ -4294,7 +4296,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http state6: if (((_bits & 64L) != 0)) { - _current = new KeyValuePair("Transfer-Encoding", _collection._TransferEncoding); + _current = new KeyValuePair("Transfer-Encoding", _collection._TransferEncoding); _state = 7; return true; } @@ -4302,7 +4304,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http state7: if (((_bits & 128L) != 0)) { - _current = new KeyValuePair("Upgrade", _collection._Upgrade); + _current = new KeyValuePair("Upgrade", _collection._Upgrade); _state = 8; return true; } @@ -4310,7 +4312,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http state8: if (((_bits & 256L) != 0)) { - _current = new KeyValuePair("Via", _collection._Via); + _current = new KeyValuePair("Via", _collection._Via); _state = 9; return true; } @@ -4318,7 +4320,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http state9: if (((_bits & 512L) != 0)) { - _current = new KeyValuePair("Warning", _collection._Warning); + _current = new KeyValuePair("Warning", _collection._Warning); _state = 10; return true; } @@ -4326,7 +4328,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http state10: if (((_bits & 1024L) != 0)) { - _current = new KeyValuePair("Allow", _collection._Allow); + _current = new KeyValuePair("Allow", _collection._Allow); _state = 11; return true; } @@ -4334,7 +4336,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http state11: if (((_bits & 2048L) != 0)) { - _current = new KeyValuePair("Content-Length", _collection._ContentLength); + _current = new KeyValuePair("Content-Length", _collection._ContentLength); _state = 12; return true; } @@ -4342,7 +4344,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http state12: if (((_bits & 4096L) != 0)) { - _current = new KeyValuePair("Content-Type", _collection._ContentType); + _current = new KeyValuePair("Content-Type", _collection._ContentType); _state = 13; return true; } @@ -4350,7 +4352,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http state13: if (((_bits & 8192L) != 0)) { - _current = new KeyValuePair("Content-Encoding", _collection._ContentEncoding); + _current = new KeyValuePair("Content-Encoding", _collection._ContentEncoding); _state = 14; return true; } @@ -4358,7 +4360,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http state14: if (((_bits & 16384L) != 0)) { - _current = new KeyValuePair("Content-Language", _collection._ContentLanguage); + _current = new KeyValuePair("Content-Language", _collection._ContentLanguage); _state = 15; return true; } @@ -4366,7 +4368,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http state15: if (((_bits & 32768L) != 0)) { - _current = new KeyValuePair("Content-Location", _collection._ContentLocation); + _current = new KeyValuePair("Content-Location", _collection._ContentLocation); _state = 16; return true; } @@ -4374,7 +4376,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http state16: if (((_bits & 65536L) != 0)) { - _current = new KeyValuePair("Content-MD5", _collection._ContentMD5); + _current = new KeyValuePair("Content-MD5", _collection._ContentMD5); _state = 17; return true; } @@ -4382,7 +4384,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http state17: if (((_bits & 131072L) != 0)) { - _current = new KeyValuePair("Content-Range", _collection._ContentRange); + _current = new KeyValuePair("Content-Range", _collection._ContentRange); _state = 18; return true; } @@ -4390,7 +4392,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http state18: if (((_bits & 262144L) != 0)) { - _current = new KeyValuePair("Expires", _collection._Expires); + _current = new KeyValuePair("Expires", _collection._Expires); _state = 19; return true; } @@ -4398,7 +4400,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http state19: if (((_bits & 524288L) != 0)) { - _current = new KeyValuePair("Last-Modified", _collection._LastModified); + _current = new KeyValuePair("Last-Modified", _collection._LastModified); _state = 20; return true; } @@ -4406,7 +4408,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http state20: if (((_bits & 1048576L) != 0)) { - _current = new KeyValuePair("Accept", _collection._Accept); + _current = new KeyValuePair("Accept", _collection._Accept); _state = 21; return true; } @@ -4414,7 +4416,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http state21: if (((_bits & 2097152L) != 0)) { - _current = new KeyValuePair("Accept-Charset", _collection._AcceptCharset); + _current = new KeyValuePair("Accept-Charset", _collection._AcceptCharset); _state = 22; return true; } @@ -4422,7 +4424,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http state22: if (((_bits & 4194304L) != 0)) { - _current = new KeyValuePair("Accept-Encoding", _collection._AcceptEncoding); + _current = new KeyValuePair("Accept-Encoding", _collection._AcceptEncoding); _state = 23; return true; } @@ -4430,7 +4432,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http state23: if (((_bits & 8388608L) != 0)) { - _current = new KeyValuePair("Accept-Language", _collection._AcceptLanguage); + _current = new KeyValuePair("Accept-Language", _collection._AcceptLanguage); _state = 24; return true; } @@ -4438,7 +4440,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http state24: if (((_bits & 16777216L) != 0)) { - _current = new KeyValuePair("Authorization", _collection._Authorization); + _current = new KeyValuePair("Authorization", _collection._Authorization); _state = 25; return true; } @@ -4446,7 +4448,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http state25: if (((_bits & 33554432L) != 0)) { - _current = new KeyValuePair("Cookie", _collection._Cookie); + _current = new KeyValuePair("Cookie", _collection._Cookie); _state = 26; return true; } @@ -4454,7 +4456,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http state26: if (((_bits & 67108864L) != 0)) { - _current = new KeyValuePair("Expect", _collection._Expect); + _current = new KeyValuePair("Expect", _collection._Expect); _state = 27; return true; } @@ -4462,7 +4464,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http state27: if (((_bits & 134217728L) != 0)) { - _current = new KeyValuePair("From", _collection._From); + _current = new KeyValuePair("From", _collection._From); _state = 28; return true; } @@ -4470,7 +4472,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http state28: if (((_bits & 268435456L) != 0)) { - _current = new KeyValuePair("Host", _collection._Host); + _current = new KeyValuePair("Host", _collection._Host); _state = 29; return true; } @@ -4478,7 +4480,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http state29: if (((_bits & 536870912L) != 0)) { - _current = new KeyValuePair("If-Match", _collection._IfMatch); + _current = new KeyValuePair("If-Match", _collection._IfMatch); _state = 30; return true; } @@ -4486,7 +4488,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http state30: if (((_bits & 1073741824L) != 0)) { - _current = new KeyValuePair("If-Modified-Since", _collection._IfModifiedSince); + _current = new KeyValuePair("If-Modified-Since", _collection._IfModifiedSince); _state = 31; return true; } @@ -4494,7 +4496,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http state31: if (((_bits & 2147483648L) != 0)) { - _current = new KeyValuePair("If-None-Match", _collection._IfNoneMatch); + _current = new KeyValuePair("If-None-Match", _collection._IfNoneMatch); _state = 32; return true; } @@ -4502,7 +4504,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http state32: if (((_bits & 4294967296L) != 0)) { - _current = new KeyValuePair("If-Range", _collection._IfRange); + _current = new KeyValuePair("If-Range", _collection._IfRange); _state = 33; return true; } @@ -4510,7 +4512,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http state33: if (((_bits & 8589934592L) != 0)) { - _current = new KeyValuePair("If-Unmodified-Since", _collection._IfUnmodifiedSince); + _current = new KeyValuePair("If-Unmodified-Since", _collection._IfUnmodifiedSince); _state = 34; return true; } @@ -4518,7 +4520,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http state34: if (((_bits & 17179869184L) != 0)) { - _current = new KeyValuePair("Max-Forwards", _collection._MaxForwards); + _current = new KeyValuePair("Max-Forwards", _collection._MaxForwards); _state = 35; return true; } @@ -4526,7 +4528,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http state35: if (((_bits & 34359738368L) != 0)) { - _current = new KeyValuePair("Proxy-Authorization", _collection._ProxyAuthorization); + _current = new KeyValuePair("Proxy-Authorization", _collection._ProxyAuthorization); _state = 36; return true; } @@ -4534,7 +4536,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http state36: if (((_bits & 68719476736L) != 0)) { - _current = new KeyValuePair("Referer", _collection._Referer); + _current = new KeyValuePair("Referer", _collection._Referer); _state = 37; return true; } @@ -4542,7 +4544,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http state37: if (((_bits & 137438953472L) != 0)) { - _current = new KeyValuePair("Range", _collection._Range); + _current = new KeyValuePair("Range", _collection._Range); _state = 38; return true; } @@ -4550,7 +4552,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http state38: if (((_bits & 274877906944L) != 0)) { - _current = new KeyValuePair("TE", _collection._TE); + _current = new KeyValuePair("TE", _collection._TE); _state = 39; return true; } @@ -4558,7 +4560,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http state39: if (((_bits & 549755813888L) != 0)) { - _current = new KeyValuePair("Translate", _collection._Translate); + _current = new KeyValuePair("Translate", _collection._Translate); _state = 40; return true; } @@ -4566,7 +4568,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http state40: if (((_bits & 1099511627776L) != 0)) { - _current = new KeyValuePair("User-Agent", _collection._UserAgent); + _current = new KeyValuePair("User-Agent", _collection._UserAgent); _state = 41; return true; } @@ -4574,7 +4576,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http state_default: if (!_hasUnknown || !_unknownEnumerator.MoveNext()) { - _current = default(KeyValuePair); + _current = default(KeyValuePair); return false; } _current = _unknownEnumerator.Current; @@ -4587,36 +4589,36 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { long _bits = 0; - string[] _CacheControl; - string[] _Connection; - string[] _Date; - string[] _KeepAlive; - string[] _Pragma; - string[] _Trailer; - string[] _TransferEncoding; - string[] _Upgrade; - string[] _Via; - string[] _Warning; - string[] _Allow; - string[] _ContentLength; - string[] _ContentType; - string[] _ContentEncoding; - string[] _ContentLanguage; - string[] _ContentLocation; - string[] _ContentMD5; - string[] _ContentRange; - string[] _Expires; - string[] _LastModified; - string[] _AcceptRanges; - string[] _Age; - string[] _ETag; - string[] _Location; - string[] _ProxyAutheticate; - string[] _RetryAfter; - string[] _Server; - string[] _SetCookie; - string[] _Vary; - string[] _WWWAuthenticate; + StringValues _CacheControl; + StringValues _Connection; + StringValues _Date; + StringValues _KeepAlive; + StringValues _Pragma; + StringValues _Trailer; + StringValues _TransferEncoding; + StringValues _Upgrade; + StringValues _Via; + StringValues _Warning; + StringValues _Allow; + StringValues _ContentLength; + StringValues _ContentType; + StringValues _ContentEncoding; + StringValues _ContentLanguage; + StringValues _ContentLocation; + StringValues _ContentMD5; + StringValues _ContentRange; + StringValues _Expires; + StringValues _LastModified; + StringValues _AcceptRanges; + StringValues _Age; + StringValues _ETag; + StringValues _Location; + StringValues _ProxyAutheticate; + StringValues _RetryAfter; + StringValues _Server; + StringValues _SetCookie; + StringValues _Vary; + StringValues _WWWAuthenticate; protected override int GetCountFast() { @@ -4775,7 +4777,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return count; } - protected override string[] GetValueFast(string key) + protected override StringValues GetValueFast(string key) { switch(key.Length) { @@ -5198,7 +5200,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return MaybeUnknown[key]; } - protected override bool TryGetValueFast(string key, out string[] value) + protected override bool TryGetValueFast(string key, out StringValues value) { switch(key.Length) { @@ -5213,7 +5215,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } else { - value = null; + value = StringValues.Empty; return false; } } @@ -5227,7 +5229,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } else { - value = null; + value = StringValues.Empty; return false; } } @@ -5241,7 +5243,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } else { - value = null; + value = StringValues.Empty; return false; } } @@ -5255,7 +5257,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } else { - value = null; + value = StringValues.Empty; return false; } } @@ -5273,7 +5275,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } else { - value = null; + value = StringValues.Empty; return false; } } @@ -5287,7 +5289,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } else { - value = null; + value = StringValues.Empty; return false; } } @@ -5301,7 +5303,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } else { - value = null; + value = StringValues.Empty; return false; } } @@ -5319,7 +5321,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } else { - value = null; + value = StringValues.Empty; return false; } } @@ -5333,7 +5335,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } else { - value = null; + value = StringValues.Empty; return false; } } @@ -5347,7 +5349,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } else { - value = null; + value = StringValues.Empty; return false; } } @@ -5365,7 +5367,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } else { - value = null; + value = StringValues.Empty; return false; } } @@ -5379,7 +5381,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } else { - value = null; + value = StringValues.Empty; return false; } } @@ -5397,7 +5399,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } else { - value = null; + value = StringValues.Empty; return false; } } @@ -5411,7 +5413,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } else { - value = null; + value = StringValues.Empty; return false; } } @@ -5425,7 +5427,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } else { - value = null; + value = StringValues.Empty; return false; } } @@ -5439,7 +5441,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } else { - value = null; + value = StringValues.Empty; return false; } } @@ -5457,7 +5459,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } else { - value = null; + value = StringValues.Empty; return false; } } @@ -5471,7 +5473,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } else { - value = null; + value = StringValues.Empty; return false; } } @@ -5489,7 +5491,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } else { - value = null; + value = StringValues.Empty; return false; } } @@ -5503,7 +5505,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } else { - value = null; + value = StringValues.Empty; return false; } } @@ -5521,7 +5523,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } else { - value = null; + value = StringValues.Empty; return false; } } @@ -5539,7 +5541,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } else { - value = null; + value = StringValues.Empty; return false; } } @@ -5557,7 +5559,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } else { - value = null; + value = StringValues.Empty; return false; } } @@ -5575,7 +5577,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } else { - value = null; + value = StringValues.Empty; return false; } } @@ -5589,7 +5591,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } else { - value = null; + value = StringValues.Empty; return false; } } @@ -5603,7 +5605,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } else { - value = null; + value = StringValues.Empty; return false; } } @@ -5617,7 +5619,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } else { - value = null; + value = StringValues.Empty; return false; } } @@ -5635,7 +5637,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } else { - value = null; + value = StringValues.Empty; return false; } } @@ -5649,7 +5651,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } else { - value = null; + value = StringValues.Empty; return false; } } @@ -5667,18 +5669,18 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } else { - value = null; + value = StringValues.Empty; return false; } } } break; } - value = null; + value = StringValues.Empty; return MaybeUnknown?.TryGetValue(key, out value) ?? false; } - protected override void SetValueFast(string key, string[] value) + protected override void SetValueFast(string key, StringValues value) { switch(key.Length) { @@ -5947,7 +5949,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http Unknown[key] = value; } - protected override void AddValueFast(string key, string[] value) + protected override void AddValueFast(string key, StringValues value) { switch(key.Length) { @@ -6791,7 +6793,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http MaybeUnknown?.Clear(); } - protected override void CopyToFast(KeyValuePair[] array, int arrayIndex) + protected override void CopyToFast(KeyValuePair[] array, int arrayIndex) { if (arrayIndex < 0) { @@ -6806,7 +6808,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http throw new ArgumentException(); } - array[arrayIndex] = new KeyValuePair("Cache-Control", _CacheControl); + array[arrayIndex] = new KeyValuePair("Cache-Control", _CacheControl); ++arrayIndex; } @@ -6817,7 +6819,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http throw new ArgumentException(); } - array[arrayIndex] = new KeyValuePair("Connection", _Connection); + array[arrayIndex] = new KeyValuePair("Connection", _Connection); ++arrayIndex; } @@ -6828,7 +6830,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http throw new ArgumentException(); } - array[arrayIndex] = new KeyValuePair("Date", _Date); + array[arrayIndex] = new KeyValuePair("Date", _Date); ++arrayIndex; } @@ -6839,7 +6841,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http throw new ArgumentException(); } - array[arrayIndex] = new KeyValuePair("Keep-Alive", _KeepAlive); + array[arrayIndex] = new KeyValuePair("Keep-Alive", _KeepAlive); ++arrayIndex; } @@ -6850,7 +6852,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http throw new ArgumentException(); } - array[arrayIndex] = new KeyValuePair("Pragma", _Pragma); + array[arrayIndex] = new KeyValuePair("Pragma", _Pragma); ++arrayIndex; } @@ -6861,7 +6863,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http throw new ArgumentException(); } - array[arrayIndex] = new KeyValuePair("Trailer", _Trailer); + array[arrayIndex] = new KeyValuePair("Trailer", _Trailer); ++arrayIndex; } @@ -6872,7 +6874,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http throw new ArgumentException(); } - array[arrayIndex] = new KeyValuePair("Transfer-Encoding", _TransferEncoding); + array[arrayIndex] = new KeyValuePair("Transfer-Encoding", _TransferEncoding); ++arrayIndex; } @@ -6883,7 +6885,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http throw new ArgumentException(); } - array[arrayIndex] = new KeyValuePair("Upgrade", _Upgrade); + array[arrayIndex] = new KeyValuePair("Upgrade", _Upgrade); ++arrayIndex; } @@ -6894,7 +6896,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http throw new ArgumentException(); } - array[arrayIndex] = new KeyValuePair("Via", _Via); + array[arrayIndex] = new KeyValuePair("Via", _Via); ++arrayIndex; } @@ -6905,7 +6907,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http throw new ArgumentException(); } - array[arrayIndex] = new KeyValuePair("Warning", _Warning); + array[arrayIndex] = new KeyValuePair("Warning", _Warning); ++arrayIndex; } @@ -6916,7 +6918,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http throw new ArgumentException(); } - array[arrayIndex] = new KeyValuePair("Allow", _Allow); + array[arrayIndex] = new KeyValuePair("Allow", _Allow); ++arrayIndex; } @@ -6927,7 +6929,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http throw new ArgumentException(); } - array[arrayIndex] = new KeyValuePair("Content-Length", _ContentLength); + array[arrayIndex] = new KeyValuePair("Content-Length", _ContentLength); ++arrayIndex; } @@ -6938,7 +6940,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http throw new ArgumentException(); } - array[arrayIndex] = new KeyValuePair("Content-Type", _ContentType); + array[arrayIndex] = new KeyValuePair("Content-Type", _ContentType); ++arrayIndex; } @@ -6949,7 +6951,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http throw new ArgumentException(); } - array[arrayIndex] = new KeyValuePair("Content-Encoding", _ContentEncoding); + array[arrayIndex] = new KeyValuePair("Content-Encoding", _ContentEncoding); ++arrayIndex; } @@ -6960,7 +6962,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http throw new ArgumentException(); } - array[arrayIndex] = new KeyValuePair("Content-Language", _ContentLanguage); + array[arrayIndex] = new KeyValuePair("Content-Language", _ContentLanguage); ++arrayIndex; } @@ -6971,7 +6973,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http throw new ArgumentException(); } - array[arrayIndex] = new KeyValuePair("Content-Location", _ContentLocation); + array[arrayIndex] = new KeyValuePair("Content-Location", _ContentLocation); ++arrayIndex; } @@ -6982,7 +6984,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http throw new ArgumentException(); } - array[arrayIndex] = new KeyValuePair("Content-MD5", _ContentMD5); + array[arrayIndex] = new KeyValuePair("Content-MD5", _ContentMD5); ++arrayIndex; } @@ -6993,7 +6995,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http throw new ArgumentException(); } - array[arrayIndex] = new KeyValuePair("Content-Range", _ContentRange); + array[arrayIndex] = new KeyValuePair("Content-Range", _ContentRange); ++arrayIndex; } @@ -7004,7 +7006,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http throw new ArgumentException(); } - array[arrayIndex] = new KeyValuePair("Expires", _Expires); + array[arrayIndex] = new KeyValuePair("Expires", _Expires); ++arrayIndex; } @@ -7015,7 +7017,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http throw new ArgumentException(); } - array[arrayIndex] = new KeyValuePair("Last-Modified", _LastModified); + array[arrayIndex] = new KeyValuePair("Last-Modified", _LastModified); ++arrayIndex; } @@ -7026,7 +7028,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http throw new ArgumentException(); } - array[arrayIndex] = new KeyValuePair("Accept-Ranges", _AcceptRanges); + array[arrayIndex] = new KeyValuePair("Accept-Ranges", _AcceptRanges); ++arrayIndex; } @@ -7037,7 +7039,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http throw new ArgumentException(); } - array[arrayIndex] = new KeyValuePair("Age", _Age); + array[arrayIndex] = new KeyValuePair("Age", _Age); ++arrayIndex; } @@ -7048,7 +7050,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http throw new ArgumentException(); } - array[arrayIndex] = new KeyValuePair("ETag", _ETag); + array[arrayIndex] = new KeyValuePair("ETag", _ETag); ++arrayIndex; } @@ -7059,7 +7061,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http throw new ArgumentException(); } - array[arrayIndex] = new KeyValuePair("Location", _Location); + array[arrayIndex] = new KeyValuePair("Location", _Location); ++arrayIndex; } @@ -7070,7 +7072,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http throw new ArgumentException(); } - array[arrayIndex] = new KeyValuePair("Proxy-Autheticate", _ProxyAutheticate); + array[arrayIndex] = new KeyValuePair("Proxy-Autheticate", _ProxyAutheticate); ++arrayIndex; } @@ -7081,7 +7083,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http throw new ArgumentException(); } - array[arrayIndex] = new KeyValuePair("Retry-After", _RetryAfter); + array[arrayIndex] = new KeyValuePair("Retry-After", _RetryAfter); ++arrayIndex; } @@ -7092,7 +7094,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http throw new ArgumentException(); } - array[arrayIndex] = new KeyValuePair("Server", _Server); + array[arrayIndex] = new KeyValuePair("Server", _Server); ++arrayIndex; } @@ -7103,7 +7105,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http throw new ArgumentException(); } - array[arrayIndex] = new KeyValuePair("Set-Cookie", _SetCookie); + array[arrayIndex] = new KeyValuePair("Set-Cookie", _SetCookie); ++arrayIndex; } @@ -7114,7 +7116,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http throw new ArgumentException(); } - array[arrayIndex] = new KeyValuePair("Vary", _Vary); + array[arrayIndex] = new KeyValuePair("Vary", _Vary); ++arrayIndex; } @@ -7125,11 +7127,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http throw new ArgumentException(); } - array[arrayIndex] = new KeyValuePair("WWW-Authenticate", _WWWAuthenticate); + array[arrayIndex] = new KeyValuePair("WWW-Authenticate", _WWWAuthenticate); ++arrayIndex; } - ((ICollection>)MaybeUnknown)?.CopyTo(array, arrayIndex); + ((ICollection>)MaybeUnknown)?.CopyTo(array, arrayIndex); } public unsafe void Append(byte[] keyBytes, int keyOffset, int keyLength, string value) @@ -7610,8 +7612,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Http break; }} var key = System.Text.Encoding.ASCII.GetString(keyBytes, keyOffset, keyLength); - string[] existing; - Unknown[key] = Unknown.TryGetValue(key, out existing) ? AppendValue(existing, value) : new[] {value}; + StringValues existing; + Unknown.TryGetValue(key, out existing); + Unknown[key] = AppendValue(existing, value); } public partial struct Enumerator @@ -7718,7 +7721,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http state0: if (((_bits & 1L) != 0)) { - _current = new KeyValuePair("Cache-Control", _collection._CacheControl); + _current = new KeyValuePair("Cache-Control", _collection._CacheControl); _state = 1; return true; } @@ -7726,7 +7729,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http state1: if (((_bits & 2L) != 0)) { - _current = new KeyValuePair("Connection", _collection._Connection); + _current = new KeyValuePair("Connection", _collection._Connection); _state = 2; return true; } @@ -7734,7 +7737,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http state2: if (((_bits & 4L) != 0)) { - _current = new KeyValuePair("Date", _collection._Date); + _current = new KeyValuePair("Date", _collection._Date); _state = 3; return true; } @@ -7742,7 +7745,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http state3: if (((_bits & 8L) != 0)) { - _current = new KeyValuePair("Keep-Alive", _collection._KeepAlive); + _current = new KeyValuePair("Keep-Alive", _collection._KeepAlive); _state = 4; return true; } @@ -7750,7 +7753,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http state4: if (((_bits & 16L) != 0)) { - _current = new KeyValuePair("Pragma", _collection._Pragma); + _current = new KeyValuePair("Pragma", _collection._Pragma); _state = 5; return true; } @@ -7758,7 +7761,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http state5: if (((_bits & 32L) != 0)) { - _current = new KeyValuePair("Trailer", _collection._Trailer); + _current = new KeyValuePair("Trailer", _collection._Trailer); _state = 6; return true; } @@ -7766,7 +7769,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http state6: if (((_bits & 64L) != 0)) { - _current = new KeyValuePair("Transfer-Encoding", _collection._TransferEncoding); + _current = new KeyValuePair("Transfer-Encoding", _collection._TransferEncoding); _state = 7; return true; } @@ -7774,7 +7777,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http state7: if (((_bits & 128L) != 0)) { - _current = new KeyValuePair("Upgrade", _collection._Upgrade); + _current = new KeyValuePair("Upgrade", _collection._Upgrade); _state = 8; return true; } @@ -7782,7 +7785,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http state8: if (((_bits & 256L) != 0)) { - _current = new KeyValuePair("Via", _collection._Via); + _current = new KeyValuePair("Via", _collection._Via); _state = 9; return true; } @@ -7790,7 +7793,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http state9: if (((_bits & 512L) != 0)) { - _current = new KeyValuePair("Warning", _collection._Warning); + _current = new KeyValuePair("Warning", _collection._Warning); _state = 10; return true; } @@ -7798,7 +7801,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http state10: if (((_bits & 1024L) != 0)) { - _current = new KeyValuePair("Allow", _collection._Allow); + _current = new KeyValuePair("Allow", _collection._Allow); _state = 11; return true; } @@ -7806,7 +7809,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http state11: if (((_bits & 2048L) != 0)) { - _current = new KeyValuePair("Content-Length", _collection._ContentLength); + _current = new KeyValuePair("Content-Length", _collection._ContentLength); _state = 12; return true; } @@ -7814,7 +7817,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http state12: if (((_bits & 4096L) != 0)) { - _current = new KeyValuePair("Content-Type", _collection._ContentType); + _current = new KeyValuePair("Content-Type", _collection._ContentType); _state = 13; return true; } @@ -7822,7 +7825,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http state13: if (((_bits & 8192L) != 0)) { - _current = new KeyValuePair("Content-Encoding", _collection._ContentEncoding); + _current = new KeyValuePair("Content-Encoding", _collection._ContentEncoding); _state = 14; return true; } @@ -7830,7 +7833,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http state14: if (((_bits & 16384L) != 0)) { - _current = new KeyValuePair("Content-Language", _collection._ContentLanguage); + _current = new KeyValuePair("Content-Language", _collection._ContentLanguage); _state = 15; return true; } @@ -7838,7 +7841,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http state15: if (((_bits & 32768L) != 0)) { - _current = new KeyValuePair("Content-Location", _collection._ContentLocation); + _current = new KeyValuePair("Content-Location", _collection._ContentLocation); _state = 16; return true; } @@ -7846,7 +7849,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http state16: if (((_bits & 65536L) != 0)) { - _current = new KeyValuePair("Content-MD5", _collection._ContentMD5); + _current = new KeyValuePair("Content-MD5", _collection._ContentMD5); _state = 17; return true; } @@ -7854,7 +7857,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http state17: if (((_bits & 131072L) != 0)) { - _current = new KeyValuePair("Content-Range", _collection._ContentRange); + _current = new KeyValuePair("Content-Range", _collection._ContentRange); _state = 18; return true; } @@ -7862,7 +7865,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http state18: if (((_bits & 262144L) != 0)) { - _current = new KeyValuePair("Expires", _collection._Expires); + _current = new KeyValuePair("Expires", _collection._Expires); _state = 19; return true; } @@ -7870,7 +7873,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http state19: if (((_bits & 524288L) != 0)) { - _current = new KeyValuePair("Last-Modified", _collection._LastModified); + _current = new KeyValuePair("Last-Modified", _collection._LastModified); _state = 20; return true; } @@ -7878,7 +7881,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http state20: if (((_bits & 1048576L) != 0)) { - _current = new KeyValuePair("Accept-Ranges", _collection._AcceptRanges); + _current = new KeyValuePair("Accept-Ranges", _collection._AcceptRanges); _state = 21; return true; } @@ -7886,7 +7889,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http state21: if (((_bits & 2097152L) != 0)) { - _current = new KeyValuePair("Age", _collection._Age); + _current = new KeyValuePair("Age", _collection._Age); _state = 22; return true; } @@ -7894,7 +7897,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http state22: if (((_bits & 4194304L) != 0)) { - _current = new KeyValuePair("ETag", _collection._ETag); + _current = new KeyValuePair("ETag", _collection._ETag); _state = 23; return true; } @@ -7902,7 +7905,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http state23: if (((_bits & 8388608L) != 0)) { - _current = new KeyValuePair("Location", _collection._Location); + _current = new KeyValuePair("Location", _collection._Location); _state = 24; return true; } @@ -7910,7 +7913,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http state24: if (((_bits & 16777216L) != 0)) { - _current = new KeyValuePair("Proxy-Autheticate", _collection._ProxyAutheticate); + _current = new KeyValuePair("Proxy-Autheticate", _collection._ProxyAutheticate); _state = 25; return true; } @@ -7918,7 +7921,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http state25: if (((_bits & 33554432L) != 0)) { - _current = new KeyValuePair("Retry-After", _collection._RetryAfter); + _current = new KeyValuePair("Retry-After", _collection._RetryAfter); _state = 26; return true; } @@ -7926,7 +7929,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http state26: if (((_bits & 67108864L) != 0)) { - _current = new KeyValuePair("Server", _collection._Server); + _current = new KeyValuePair("Server", _collection._Server); _state = 27; return true; } @@ -7934,7 +7937,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http state27: if (((_bits & 134217728L) != 0)) { - _current = new KeyValuePair("Set-Cookie", _collection._SetCookie); + _current = new KeyValuePair("Set-Cookie", _collection._SetCookie); _state = 28; return true; } @@ -7942,7 +7945,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http state28: if (((_bits & 268435456L) != 0)) { - _current = new KeyValuePair("Vary", _collection._Vary); + _current = new KeyValuePair("Vary", _collection._Vary); _state = 29; return true; } @@ -7950,7 +7953,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http state29: if (((_bits & 536870912L) != 0)) { - _current = new KeyValuePair("WWW-Authenticate", _collection._WWWAuthenticate); + _current = new KeyValuePair("WWW-Authenticate", _collection._WWWAuthenticate); _state = 30; return true; } @@ -7958,7 +7961,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http state_default: if (!_hasUnknown || !_unknownEnumerator.MoveNext()) { - _current = default(KeyValuePair); + _current = default(KeyValuePair); return false; } _current = _unknownEnumerator.Current; diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameHeaders.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameHeaders.cs index 9cd8d90488..c8a6d7cd44 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameHeaders.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameHeaders.cs @@ -2,36 +2,34 @@ using System.Collections; using System.Collections.Generic; using System.Linq; +using Microsoft.Framework.Primitives; namespace Microsoft.AspNet.Server.Kestrel.Http { - public abstract class FrameHeaders : IDictionary + public abstract class FrameHeaders : IDictionary { - protected Dictionary MaybeUnknown; + protected Dictionary MaybeUnknown; - protected Dictionary Unknown => MaybeUnknown ?? (MaybeUnknown = new Dictionary(StringComparer.OrdinalIgnoreCase)); + protected Dictionary Unknown => MaybeUnknown ?? (MaybeUnknown = new Dictionary(StringComparer.OrdinalIgnoreCase)); - protected static string[] AppendValue(string[] existing, string append) + protected static StringValues AppendValue(StringValues existing, string append) { - var appended = new string[existing.Length + 1]; - Array.Copy(existing, appended, existing.Length); - appended[existing.Length] = append; - return appended; + return StringValues.Concat(existing, append); } protected virtual int GetCountFast() { throw new NotImplementedException(); } - protected virtual string[] GetValueFast(string key) + protected virtual StringValues GetValueFast(string key) { throw new NotImplementedException(); } - protected virtual bool TryGetValueFast(string key, out string[] value) + protected virtual bool TryGetValueFast(string key, out StringValues value) { throw new NotImplementedException(); } - protected virtual void SetValueFast(string key, string[] value) + protected virtual void SetValueFast(string key, StringValues value) { throw new NotImplementedException(); } - protected virtual void AddValueFast(string key, string[] value) + protected virtual void AddValueFast(string key, StringValues value) { throw new NotImplementedException(); } protected virtual bool RemoveFast(string key) @@ -40,14 +38,14 @@ namespace Microsoft.AspNet.Server.Kestrel.Http protected virtual void ClearFast() { throw new NotImplementedException(); } - protected virtual void CopyToFast(KeyValuePair[] array, int arrayIndex) + protected virtual void CopyToFast(KeyValuePair[] array, int arrayIndex) { throw new NotImplementedException(); } - protected virtual IEnumerator> GetEnumeratorFast() + protected virtual IEnumerator> GetEnumeratorFast() { throw new NotImplementedException(); } - string[] IDictionary.this[string key] + StringValues IDictionary.this[string key] { get { @@ -60,44 +58,44 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } - int ICollection>.Count => GetCountFast(); + int ICollection>.Count => GetCountFast(); - bool ICollection>.IsReadOnly => false; + bool ICollection>.IsReadOnly => false; - ICollection IDictionary.Keys => ((IDictionary)this).Select(x => x.Key).ToList(); + ICollection IDictionary.Keys => ((IDictionary)this).Select(x => x.Key).ToList(); - ICollection IDictionary.Values => ((IDictionary)this).Select(x => x.Value).ToList(); + ICollection IDictionary.Values => ((IDictionary)this).Select(x => x.Value).ToList(); - void ICollection>.Add(KeyValuePair item) + void ICollection>.Add(KeyValuePair item) { AddValueFast(item.Key, item.Value); } - void IDictionary.Add(string key, string[] value) + void IDictionary.Add(string key, StringValues value) { AddValueFast(key, value); } - void ICollection>.Clear() + void ICollection>.Clear() { ClearFast(); } - bool ICollection>.Contains(KeyValuePair item) + bool ICollection>.Contains(KeyValuePair item) { - string[] value; + StringValues value; return TryGetValueFast(item.Key, out value) && object.Equals(value, item.Value); } - bool IDictionary.ContainsKey(string key) + bool IDictionary.ContainsKey(string key) { - string[] value; + StringValues value; return TryGetValueFast(key, out value); } - void ICollection>.CopyTo(KeyValuePair[] array, int arrayIndex) + void ICollection>.CopyTo(KeyValuePair[] array, int arrayIndex) { CopyToFast(array, arrayIndex); } @@ -107,26 +105,26 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return GetEnumeratorFast(); } - IEnumerator> IEnumerable>.GetEnumerator() + IEnumerator> IEnumerable>.GetEnumerator() { return GetEnumeratorFast(); } - bool ICollection>.Remove(KeyValuePair item) + bool ICollection>.Remove(KeyValuePair item) { - string[] value; + StringValues value; return TryGetValueFast(item.Key, out value) && object.Equals(value, item.Value) && RemoveFast(item.Key); } - bool IDictionary.Remove(string key) + bool IDictionary.Remove(string key) { return RemoveFast(key); } - bool IDictionary.TryGetValue(string key, out string[] value) + bool IDictionary.TryGetValue(string key, out StringValues value) { return TryGetValueFast(key, out value); } @@ -139,33 +137,33 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return new Enumerator(this); } - protected override IEnumerator> GetEnumeratorFast() + protected override IEnumerator> GetEnumeratorFast() { return GetEnumerator(); } - public partial struct Enumerator : IEnumerator> + public partial struct Enumerator : IEnumerator> { FrameRequestHeaders _collection; long _bits; int _state; - KeyValuePair _current; + KeyValuePair _current; bool _hasUnknown; - Dictionary.Enumerator _unknownEnumerator; + Dictionary.Enumerator _unknownEnumerator; internal Enumerator(FrameRequestHeaders collection) { _collection = collection; _bits = collection._bits; _state = 0; - _current = default(KeyValuePair); + _current = default(KeyValuePair); _hasUnknown = collection.MaybeUnknown != null; _unknownEnumerator = _hasUnknown ? collection.MaybeUnknown.GetEnumerator() - : default(Dictionary.Enumerator); + : default(Dictionary.Enumerator); } - public KeyValuePair Current => _current; + public KeyValuePair Current => _current; object IEnumerator.Current => _current; @@ -187,33 +185,33 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return new Enumerator(this); } - protected override IEnumerator> GetEnumeratorFast() + protected override IEnumerator> GetEnumeratorFast() { return GetEnumerator(); } - public partial struct Enumerator : IEnumerator> + public partial struct Enumerator : IEnumerator> { FrameResponseHeaders _collection; long _bits; int _state; - KeyValuePair _current; + KeyValuePair _current; bool _hasUnknown; - Dictionary.Enumerator _unknownEnumerator; + Dictionary.Enumerator _unknownEnumerator; internal Enumerator(FrameResponseHeaders collection) { _collection = collection; _bits = collection._bits; _state = 0; - _current = default(KeyValuePair); + _current = default(KeyValuePair); _hasUnknown = collection.MaybeUnknown != null; _unknownEnumerator = _hasUnknown ? collection.MaybeUnknown.GetEnumerator() - : default(Dictionary.Enumerator); + : default(Dictionary.Enumerator); } - public KeyValuePair Current => _current; + public KeyValuePair Current => _current; object IEnumerator.Current => _current; diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/MessageBody.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/MessageBody.cs index b07f10c948..e7f788edbc 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/MessageBody.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/MessageBody.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; +using Microsoft.Framework.Primitives; namespace Microsoft.AspNet.Server.Kestrel.Http { @@ -28,7 +29,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http public static MessageBody For( string httpVersion, - IDictionary headers, + IDictionary headers, FrameContext context) { // see also http://tools.ietf.org/html/rfc2616#section-4.4 @@ -61,15 +62,15 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return new ForRemainingData(context); } - public static bool TryGet(IDictionary headers, string name, out string value) + public static bool TryGet(IDictionary headers, string name, out string value) { - string[] values; + StringValues values; if (!headers.TryGetValue(name, out values) || values == null) { value = null; return false; } - var count = values.Length; + var count = values.Count; if (count == 0) { value = null; diff --git a/src/Microsoft.AspNet.Server.Kestrel/ServerRequest.cs b/src/Microsoft.AspNet.Server.Kestrel/ServerRequest.cs index 9d7d3dabe9..ebfa3f406c 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/ServerRequest.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/ServerRequest.cs @@ -8,6 +8,7 @@ using System.Linq; using System.Threading.Tasks; using Microsoft.AspNet.Http.Features; using Microsoft.AspNet.Server.Kestrel.Http; +using Microsoft.Framework.Primitives; namespace Microsoft.AspNet.Server.Kestrel { @@ -115,7 +116,7 @@ namespace Microsoft.AspNet.Server.Kestrel } } - IDictionary IHttpRequestFeature.Headers + IDictionary IHttpRequestFeature.Headers { get { @@ -167,7 +168,7 @@ namespace Microsoft.AspNet.Server.Kestrel } } - IDictionary IHttpResponseFeature.Headers + IDictionary IHttpResponseFeature.Headers { get { @@ -212,7 +213,7 @@ namespace Microsoft.AspNet.Server.Kestrel { get { - string[] values; + StringValues values; if (_frame.RequestHeaders.TryGetValue("Connection", out values)) { return values.Any(value => value.IndexOf("upgrade", StringComparison.OrdinalIgnoreCase) != -1); @@ -225,10 +226,10 @@ namespace Microsoft.AspNet.Server.Kestrel { _frame.StatusCode = 101; _frame.ReasonPhrase = "Switching Protocols"; - _frame.ResponseHeaders["Connection"] = new string[] { "Upgrade" }; + _frame.ResponseHeaders["Connection"] = "Upgrade"; if (!_frame.ResponseHeaders.ContainsKey("Upgrade")) { - string[] values; + StringValues values; if (_frame.RequestHeaders.TryGetValue("Upgrade", out values)) { _frame.ResponseHeaders["Upgrade"] = values; diff --git a/test/Microsoft.AspNet.Server.KestrelTests/FrameRequestHeadersTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/FrameRequestHeadersTests.cs index f69b1c0746..7df87b5a7e 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/FrameRequestHeadersTests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/FrameRequestHeadersTests.cs @@ -1,7 +1,7 @@ -using Microsoft.AspNet.Server.Kestrel.Http; -using System; +using System; using System.Collections.Generic; -using System.Linq; +using Microsoft.AspNet.Server.Kestrel.Http; +using Microsoft.Framework.Primitives; using Xunit; namespace Microsoft.AspNet.Server.KestrelTests @@ -11,7 +11,7 @@ namespace Microsoft.AspNet.Server.KestrelTests [Fact] public void InitialDictionaryIsEmpty() { - IDictionary headers = new FrameRequestHeaders(); + IDictionary headers = new FrameRequestHeaders(); Assert.Equal(0, headers.Count); Assert.False(headers.IsReadOnly); @@ -20,31 +20,31 @@ namespace Microsoft.AspNet.Server.KestrelTests [Fact] public void SettingUnknownHeadersWorks() { - IDictionary headers = new FrameRequestHeaders(); + IDictionary headers = new FrameRequestHeaders(); headers["custom"] = new[] { "value" }; Assert.NotNull(headers["custom"]); - Assert.Equal(1, headers["custom"].Length); + Assert.Equal(1, headers["custom"].Count); Assert.Equal("value", headers["custom"][0]); } [Fact] public void SettingKnownHeadersWorks() { - IDictionary headers = new FrameRequestHeaders(); + IDictionary headers = new FrameRequestHeaders(); headers["host"] = new[] { "value" }; Assert.NotNull(headers["host"]); - Assert.Equal(1, headers["host"].Length); + Assert.Equal(1, headers["host"].Count); Assert.Equal("value", headers["host"][0]); } [Fact] public void KnownAndCustomHeaderCountAddedTogether() { - IDictionary headers = new FrameRequestHeaders(); + IDictionary headers = new FrameRequestHeaders(); headers["host"] = new[] { "value" }; headers["custom"] = new[] { "value" }; @@ -55,9 +55,9 @@ namespace Microsoft.AspNet.Server.KestrelTests [Fact] public void TryGetValueWorksForKnownAndUnknownHeaders() { - IDictionary headers = new FrameRequestHeaders(); + IDictionary headers = new FrameRequestHeaders(); - string[] value; + StringValues value; Assert.False(headers.TryGetValue("host", out value)); Assert.False(headers.TryGetValue("custom", out value)); @@ -73,7 +73,7 @@ namespace Microsoft.AspNet.Server.KestrelTests [Fact] public void SameExceptionThrownForMissingKey() { - IDictionary headers = new FrameRequestHeaders(); + IDictionary headers = new FrameRequestHeaders(); Assert.Throws(() => headers["custom"]); Assert.Throws(() => headers["host"]); @@ -82,7 +82,7 @@ namespace Microsoft.AspNet.Server.KestrelTests [Fact] public void EntriesCanBeEnumerated() { - IDictionary headers = new FrameRequestHeaders(); + IDictionary headers = new FrameRequestHeaders(); var v1 = new[] { "localhost" }; var v2 = new[] { "value" }; headers["host"] = v1; @@ -90,8 +90,8 @@ namespace Microsoft.AspNet.Server.KestrelTests Assert.Equal( new[] { - new KeyValuePair("Host", v1), - new KeyValuePair("custom", v2), + new KeyValuePair("Host", v1), + new KeyValuePair("custom", v2), }, headers); } @@ -99,9 +99,9 @@ namespace Microsoft.AspNet.Server.KestrelTests [Fact] public void KeysAndValuesCanBeEnumerated() { - IDictionary headers = new FrameRequestHeaders(); - var v1 = new[] { "localhost" }; - var v2 = new[] { "value" }; + IDictionary headers = new FrameRequestHeaders(); + StringValues v1 = new[] { "localhost" }; + StringValues v2 = new[] { "value" }; headers["host"] = v1; headers["custom"] = v2; @@ -109,7 +109,7 @@ namespace Microsoft.AspNet.Server.KestrelTests new[] { "Host", "custom" }, headers.Keys); - Assert.Equal( + Assert.Equal( new[] { v1, v2 }, headers.Values); } @@ -118,11 +118,11 @@ namespace Microsoft.AspNet.Server.KestrelTests [Fact] public void ContainsAndContainsKeyWork() { - IDictionary headers = new FrameRequestHeaders(); - var kv1 = new KeyValuePair("host", new[] { "localhost" }); - var kv2 = new KeyValuePair("custom", new[] { "value" }); - var kv1b = new KeyValuePair("host", new[] { "localhost" }); - var kv2b = new KeyValuePair("custom", new[] { "value" }); + IDictionary headers = new FrameRequestHeaders(); + var kv1 = new KeyValuePair("host", new[] { "localhost" }); + var kv2 = new KeyValuePair("custom", new[] { "value" }); + var kv1b = new KeyValuePair("host", new[] { "localhost" }); + var kv2b = new KeyValuePair("custom", new[] { "value" }); Assert.False(headers.ContainsKey("host")); Assert.False(headers.ContainsKey("custom")); @@ -149,9 +149,9 @@ namespace Microsoft.AspNet.Server.KestrelTests [Fact] public void AddWorksLikeSetAndThrowsIfKeyExists() { - IDictionary headers = new FrameRequestHeaders(); + IDictionary headers = new FrameRequestHeaders(); - string[] value; + StringValues value; Assert.False(headers.TryGetValue("host", out value)); Assert.False(headers.TryGetValue("custom", out value)); @@ -169,11 +169,11 @@ namespace Microsoft.AspNet.Server.KestrelTests [Fact] public void ClearRemovesAllHeaders() { - IDictionary headers = new FrameRequestHeaders(); + IDictionary headers = new FrameRequestHeaders(); headers.Add("host", new[] { "localhost" }); headers.Add("custom", new[] { "value" }); - string[] value; + StringValues value; Assert.Equal(2, headers.Count); Assert.True(headers.TryGetValue("host", out value)); Assert.True(headers.TryGetValue("custom", out value)); @@ -188,11 +188,11 @@ namespace Microsoft.AspNet.Server.KestrelTests [Fact] public void RemoveTakesHeadersOutOfDictionary() { - IDictionary headers = new FrameRequestHeaders(); + IDictionary headers = new FrameRequestHeaders(); headers.Add("host", new[] { "localhost" }); headers.Add("custom", new[] { "value" }); - string[] value; + StringValues value; Assert.Equal(2, headers.Count); Assert.True(headers.TryGetValue("host", out value)); Assert.True(headers.TryGetValue("custom", out value)); @@ -215,24 +215,24 @@ namespace Microsoft.AspNet.Server.KestrelTests [Fact] public void CopyToMovesDataIntoArray() { - IDictionary headers = new FrameRequestHeaders(); + IDictionary headers = new FrameRequestHeaders(); headers.Add("host", new[] { "localhost" }); headers.Add("custom", new[] { "value" }); - var entries = new KeyValuePair[4]; + var entries = new KeyValuePair[4]; headers.CopyTo(entries, 1); Assert.Null(entries[0].Key); - Assert.Null(entries[0].Value); + Assert.Equal(new StringValues(), entries[0].Value); Assert.Equal("Host", entries[1].Key); - Assert.NotNull(entries[1].Value); + Assert.Equal(new[] { "localhost" }, entries[1].Value); Assert.Equal("custom", entries[2].Key); - Assert.NotNull(entries[2].Value); + Assert.Equal(new[] { "value" }, entries[2].Value); Assert.Null(entries[3].Key); - Assert.Null(entries[3].Value); + Assert.Equal(new StringValues(), entries[0].Value); } } } diff --git a/test/Microsoft.AspNet.Server.KestrelTests/FrameResponseHeadersTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/FrameResponseHeadersTests.cs index 49e573c730..1e3a5570eb 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/FrameResponseHeadersTests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/FrameResponseHeadersTests.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using Microsoft.AspNet.Server.Kestrel.Http; +using Microsoft.Framework.Primitives; using Xunit; namespace Microsoft.AspNet.Server.KestrelTests @@ -13,19 +14,19 @@ namespace Microsoft.AspNet.Server.KestrelTests [Fact] public void InitialDictionaryContainsServerAndDate() { - IDictionary headers = new FrameResponseHeaders(); + IDictionary headers = new FrameResponseHeaders(); Assert.Equal(2, headers.Count); - string[] serverHeader; + StringValues serverHeader; Assert.True(headers.TryGetValue("Server", out serverHeader)); - Assert.Equal(1, serverHeader.Length); + Assert.Equal(1, serverHeader.Count); Assert.Equal("Kestrel", serverHeader[0]); - string[] dateHeader; + StringValues dateHeader; DateTime date; Assert.True(headers.TryGetValue("Date", out dateHeader)); - Assert.Equal(1, dateHeader.Length); + Assert.Equal(1, dateHeader.Count); Assert.True(DateTime.TryParse(dateHeader[0], out date)); Assert.True(DateTime.Now - date <= TimeSpan.FromMinutes(1)); @@ -35,7 +36,7 @@ namespace Microsoft.AspNet.Server.KestrelTests [Fact] public void InitialEntriesCanBeCleared() { - IDictionary headers = new FrameResponseHeaders(); + IDictionary headers = new FrameResponseHeaders(); headers.Clear(); diff --git a/test/Microsoft.AspNet.Server.KestrelTests/MessageBodyTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/MessageBodyTests.cs index 54f6e98509..c373f42d73 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/MessageBodyTests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/MessageBodyTests.cs @@ -1,11 +1,12 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using Microsoft.AspNet.Server.Kestrel.Http; using System; using System.Collections.Generic; using System.Text; using System.Threading.Tasks; +using Microsoft.AspNet.Server.Kestrel.Http; +using Microsoft.Framework.Primitives; using Xunit; namespace Microsoft.AspNet.Server.KestrelTests @@ -19,7 +20,7 @@ namespace Microsoft.AspNet.Server.KestrelTests public void Http10ConnectionClose() { var input = new TestInput(); - var body = MessageBody.For("HTTP/1.0", new Dictionary(), input.FrameContext); + var body = MessageBody.For("HTTP/1.0", new Dictionary(), input.FrameContext); var stream = new FrameRequestStream(body); input.Add("Hello", true); @@ -38,7 +39,7 @@ namespace Microsoft.AspNet.Server.KestrelTests public async Task Http10ConnectionCloseAsync() { var input = new TestInput(); - var body = MessageBody.For("HTTP/1.0", new Dictionary(), input.FrameContext); + var body = MessageBody.For("HTTP/1.0", new Dictionary(), input.FrameContext); var stream = new FrameRequestStream(body); input.Add("Hello", true); diff --git a/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/KnownHeaders.cs b/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/KnownHeaders.cs index 7d02efa2ba..c9da2fd71a 100644 --- a/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/KnownHeaders.cs +++ b/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/KnownHeaders.cs @@ -167,6 +167,7 @@ namespace Microsoft.AspNet.Server.Kestrel.GeneratedCode return $@" using System; using System.Collections.Generic; +using Microsoft.Framework.Primitives; namespace Microsoft.AspNet.Server.Kestrel.Http {{ @@ -174,8 +175,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http {{ public FrameResponseHeaders() {{ - _Server = new[] {{ ""Kestrel"" }}; - _Date = new[] {{ DateTime.UtcNow.ToString(""r"") }}; + _Server = ""Kestrel""; + _Date = DateTime.UtcNow.ToString(""r""); _bits = { 1L << responseHeaders.First(header => header.Name == "Server").Index | 1L << responseHeaders.First(header => header.Name == "Date").Index @@ -187,7 +188,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http {{ long _bits = 0; {Each(loop.Headers, header => @" - string[] _" + header.Identifier + ";")} + StringValues _" + header.Identifier + ";")} protected override int GetCountFast() {{ @@ -201,7 +202,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return count; }} - protected override string[] GetValueFast(string key) + protected override StringValues GetValueFast(string key) {{ switch(key.Length) {{{Each(loop.HeadersByLength, byLength => $@" @@ -228,7 +229,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return MaybeUnknown[key]; }} - protected override bool TryGetValueFast(string key, out string[] value) + protected override bool TryGetValueFast(string key, out StringValues value) {{ switch(key.Length) {{{Each(loop.HeadersByLength, byLength => $@" @@ -243,18 +244,18 @@ namespace Microsoft.AspNet.Server.Kestrel.Http }} else {{ - value = null; + value = StringValues.Empty; return false; }} }} ")}}} break; ")}}} - value = null; + value = StringValues.Empty; return MaybeUnknown?.TryGetValue(key, out value) ?? false; }} - protected override void SetValueFast(string key, string[] value) + protected override void SetValueFast(string key, StringValues value) {{ switch(key.Length) {{{Each(loop.HeadersByLength, byLength => $@" @@ -272,7 +273,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http Unknown[key] = value; }} - protected override void AddValueFast(string key, string[] value) + protected override void AddValueFast(string key, StringValues value) {{ switch(key.Length) {{{Each(loop.HeadersByLength, byLength => $@" @@ -324,7 +325,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http MaybeUnknown?.Clear(); }} - protected override void CopyToFast(KeyValuePair[] array, int arrayIndex) + protected override void CopyToFast(KeyValuePair[] array, int arrayIndex) {{ if (arrayIndex < 0) {{ @@ -339,11 +340,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http throw new ArgumentException(); }} - array[arrayIndex] = new KeyValuePair(""{header.Name}"", _{header.Identifier}); + array[arrayIndex] = new KeyValuePair(""{header.Name}"", _{header.Identifier}); ++arrayIndex; }} ")} - ((ICollection>)MaybeUnknown)?.CopyTo(array, arrayIndex); + ((ICollection>)MaybeUnknown)?.CopyTo(array, arrayIndex); }} public unsafe void Append(byte[] keyBytes, int keyOffset, int keyLength, string value) @@ -370,8 +371,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Http break; ")}}}}} var key = System.Text.Encoding.ASCII.GetString(keyBytes, keyOffset, keyLength); - string[] existing; - Unknown[key] = Unknown.TryGetValue(key, out existing) ? AppendValue(existing, value) : new[] {{value}}; + StringValues existing; + Unknown.TryGetValue(key, out existing); + Unknown[key] = AppendValue(existing, value); }} public partial struct Enumerator @@ -391,7 +393,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http state{header.Index}: if ({header.TestBit()}) {{ - _current = new KeyValuePair(""{header.Name}"", _collection._{header.Identifier}); + _current = new KeyValuePair(""{header.Name}"", _collection._{header.Identifier}); _state = {header.Index + 1}; return true; }} @@ -399,7 +401,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http state_default: if (!_hasUnknown || !_unknownEnumerator.MoveNext()) {{ - _current = default(KeyValuePair); + _current = default(KeyValuePair); return false; }} _current = _unknownEnumerator.Current; From a9b8cfa58212afc94b93751b53d93acd848b465d Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Thu, 20 Aug 2015 11:50:38 -0700 Subject: [PATCH 0219/1662] Remove unnecessary use of generics in listeners --- .../Http/Listener.cs | 13 ++++++------- .../Http/ListenerPrimary.cs | 6 +++--- .../Http/ListenerSecondary.cs | 4 ++-- .../Http/PipeListener.cs | 8 ++++---- .../Http/PipeListenerPrimary.cs | 8 ++++---- .../Http/PipeListenerSecondary.cs | 6 +++--- .../Http/TcpListener.cs | 8 ++++---- .../Http/TcpListenerPrimary.cs | 8 ++++---- .../Http/TcpListenerSecondary.cs | 6 +++--- 9 files changed, 33 insertions(+), 34 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs index dd0d6f0228..55d8d8dc93 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs @@ -11,10 +11,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Http /// /// Base class for listeners in Kestrel. Listens for incoming connections /// - /// Type of socket used by this listener - public abstract class Listener : ListenerContext, IListener where T : UvStreamHandle + public abstract class Listener : ListenerContext, IListener { - protected T ListenSocket { get; private set; } + protected UvStreamHandle ListenSocket { get; private set; } protected static void ConnectionCallback(UvStreamHandle stream, int status, Exception error, object state) { @@ -24,7 +23,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } else { - ((Listener)state).OnConnection((T)stream, status); + ((Listener)state).OnConnection(stream, status); } } @@ -62,16 +61,16 @@ namespace Microsoft.AspNet.Server.Kestrel.Http /// /// Creates the socket used to listen for incoming connections /// - protected abstract T CreateListenSocket(string host, int port); + protected abstract UvStreamHandle CreateListenSocket(string host, int port); /// /// Handles an incoming connection /// /// Socket being used to listen on /// Connection status - protected abstract void OnConnection(T listenSocket, int status); + protected abstract void OnConnection(UvStreamHandle listenSocket, int status); - protected virtual void DispatchConnection(T socket) + protected virtual void DispatchConnection(UvStreamHandle socket) { var connection = new Connection(this, socket); connection.Start(); diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerPrimary.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerPrimary.cs index c534affe49..df4fdb09fa 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerPrimary.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerPrimary.cs @@ -13,7 +13,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http /// A primary listener waits for incoming connections on a specified socket. Incoming /// connections may be passed to a secondary listener to handle. /// - abstract public class ListenerPrimary : Listener, IListenerPrimary where T : UvStreamHandle + abstract public class ListenerPrimary : Listener, IListenerPrimary { UvPipeHandle ListenPipe { get; set; } @@ -65,7 +65,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http _dispatchPipes.Add(dispatchPipe); } - protected override void DispatchConnection(T socket) + protected override void DispatchConnection(UvStreamHandle socket) { var index = _dispatchIndex++ % (_dispatchPipes.Count + 1); if (index == _dispatchPipes.Count) @@ -84,7 +84,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http (write2, status, error, state) => { write2.Dispose(); - ((T)state).Dispose(); + ((UvStreamHandle)state).Dispose(); }, socket); } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerSecondary.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerSecondary.cs index 32c7109553..1ca3c9b193 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerSecondary.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerSecondary.cs @@ -13,7 +13,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http /// A secondary listener is delegated requests from a primary listener via a named pipe or /// UNIX domain socket. /// - public abstract class ListenerSecondary : ListenerContext, IListenerSecondary where T : UvStreamHandle + public abstract class ListenerSecondary : ListenerContext, IListenerSecondary { UvPipeHandle DispatchPipe { get; set; } @@ -108,7 +108,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http /// /// Creates a socket which can be used to accept an incoming connection /// - protected abstract T CreateAcceptSocket(); + protected abstract UvStreamHandle CreateAcceptSocket(); public void Dispose() { diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/PipeListener.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/PipeListener.cs index 64e732acaa..15b43c78b6 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/PipeListener.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/PipeListener.cs @@ -7,9 +7,9 @@ using Microsoft.AspNet.Server.Kestrel.Networking; namespace Microsoft.AspNet.Server.Kestrel.Http { /// - /// Implementation of that uses UNIX domain sockets as its transport. + /// Implementation of that uses UNIX domain sockets as its transport. /// - public class PipeListener : Listener + public class PipeListener : Listener { public PipeListener(IMemoryPool memory) : base(memory) { @@ -18,7 +18,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http /// /// Creates the socket used to listen for incoming connections /// - protected override UvPipeHandle CreateListenSocket(string host, int port) + protected override UvStreamHandle CreateListenSocket(string host, int port) { var socket = new UvPipeHandle(); socket.Init(Thread.Loop, false); @@ -32,7 +32,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http /// /// Socket being used to listen on /// Connection status - protected override void OnConnection(UvPipeHandle listenSocket, int status) + protected override void OnConnection(UvStreamHandle listenSocket, int status) { var acceptSocket = new UvPipeHandle(); acceptSocket.Init(Thread.Loop, false); diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/PipeListenerPrimary.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/PipeListenerPrimary.cs index bcfb705fef..3ee7f501bc 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/PipeListenerPrimary.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/PipeListenerPrimary.cs @@ -7,9 +7,9 @@ using Microsoft.AspNet.Server.Kestrel.Networking; namespace Microsoft.AspNet.Server.Kestrel.Http { /// - /// An implementation of using UNIX sockets. + /// An implementation of using UNIX sockets. /// - public class PipeListenerPrimary : ListenerPrimary + public class PipeListenerPrimary : ListenerPrimary { public PipeListenerPrimary(IMemoryPool memory) : base(memory) { @@ -18,7 +18,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http /// /// Creates the socket used to listen for incoming connections /// - protected override UvPipeHandle CreateListenSocket(string host, int port) + protected override UvStreamHandle CreateListenSocket(string host, int port) { var socket = new UvPipeHandle(); socket.Init(Thread.Loop, false); @@ -32,7 +32,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http /// /// Socket being used to listen on /// Connection status - protected override void OnConnection(UvPipeHandle listenSocket, int status) + protected override void OnConnection(UvStreamHandle listenSocket, int status) { var acceptSocket = new UvPipeHandle(); acceptSocket.Init(Thread.Loop, false); diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/PipeListenerSecondary.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/PipeListenerSecondary.cs index 58f6d4d4b6..81d70485bf 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/PipeListenerSecondary.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/PipeListenerSecondary.cs @@ -6,9 +6,9 @@ using Microsoft.AspNet.Server.Kestrel.Networking; namespace Microsoft.AspNet.Server.Kestrel.Http { /// - /// An implementation of using UNIX sockets. + /// An implementation of using UNIX sockets. /// - public class PipeListenerSecondary : ListenerSecondary + public class PipeListenerSecondary : ListenerSecondary { public PipeListenerSecondary(IMemoryPool memory) : base(memory) { @@ -17,7 +17,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http /// /// Creates a socket which can be used to accept an incoming connection /// - protected override UvPipeHandle CreateAcceptSocket() + protected override UvStreamHandle CreateAcceptSocket() { var acceptSocket = new UvPipeHandle(); acceptSocket.Init(Thread.Loop, false); diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/TcpListener.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/TcpListener.cs index 294674b746..54739b725d 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/TcpListener.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/TcpListener.cs @@ -8,9 +8,9 @@ using Microsoft.AspNet.Server.Kestrel.Networking; namespace Microsoft.AspNet.Server.Kestrel.Http { /// - /// Implementation of that uses TCP sockets as its transport. + /// Implementation of that uses TCP sockets as its transport. /// - public class TcpListener : Listener + public class TcpListener : Listener { public TcpListener(IMemoryPool memory) : base(memory) { @@ -19,7 +19,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http /// /// Creates the socket used to listen for incoming connections /// - protected override UvTcpHandle CreateListenSocket(string host, int port) + protected override UvStreamHandle CreateListenSocket(string host, int port) { var socket = new UvTcpHandle(); socket.Init(Thread.Loop, Thread.QueueCloseHandle); @@ -33,7 +33,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http /// /// Socket being used to listen on /// Connection status - protected override void OnConnection(UvTcpHandle listenSocket, int status) + protected override void OnConnection(UvStreamHandle listenSocket, int status) { var acceptSocket = new UvTcpHandle(); acceptSocket.Init(Thread.Loop, Thread.QueueCloseHandle); diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/TcpListenerPrimary.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/TcpListenerPrimary.cs index 8242d7d403..8a9546fdd8 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/TcpListenerPrimary.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/TcpListenerPrimary.cs @@ -8,9 +8,9 @@ using Microsoft.AspNet.Server.Kestrel.Networking; namespace Microsoft.AspNet.Server.Kestrel.Http { /// - /// An implementation of using TCP sockets. + /// An implementation of using TCP sockets. /// - public class TcpListenerPrimary : ListenerPrimary + public class TcpListenerPrimary : ListenerPrimary { public TcpListenerPrimary(IMemoryPool memory) : base(memory) { @@ -19,7 +19,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http /// /// Creates the socket used to listen for incoming connections /// - protected override UvTcpHandle CreateListenSocket(string host, int port) + protected override UvStreamHandle CreateListenSocket(string host, int port) { var socket = new UvTcpHandle(); socket.Init(Thread.Loop, Thread.QueueCloseHandle); @@ -33,7 +33,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http /// /// Socket being used to listen on /// Connection status - protected override void OnConnection(UvTcpHandle listenSocket, int status) + protected override void OnConnection(UvStreamHandle listenSocket, int status) { var acceptSocket = new UvTcpHandle(); acceptSocket.Init(Thread.Loop, Thread.QueueCloseHandle); diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/TcpListenerSecondary.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/TcpListenerSecondary.cs index c7ec374c64..5e125c0276 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/TcpListenerSecondary.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/TcpListenerSecondary.cs @@ -6,9 +6,9 @@ using Microsoft.AspNet.Server.Kestrel.Networking; namespace Microsoft.AspNet.Server.Kestrel.Http { /// - /// An implementation of using TCP sockets. + /// An implementation of using TCP sockets. /// - public class TcpListenerSecondary : ListenerSecondary + public class TcpListenerSecondary : ListenerSecondary { public TcpListenerSecondary(IMemoryPool memory) : base(memory) { @@ -17,7 +17,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http /// /// Creates a socket which can be used to accept an incoming connection /// - protected override UvTcpHandle CreateAcceptSocket() + protected override UvStreamHandle CreateAcceptSocket() { var acceptSocket = new UvTcpHandle(); acceptSocket.Init(Thread.Loop, Thread.QueueCloseHandle); From a919ea8d0a954118a0b8f1e70294892a766579ee Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Thu, 20 Aug 2015 11:56:20 -0700 Subject: [PATCH 0220/1662] Remove unnecessary listener interfaces --- .../Http/IListener.cs | 21 ----------------- .../Http/IListenerPrimary.cs | 23 ------------------- .../Http/IListenerSecondary.cs | 20 ---------------- .../Http/Listener.cs | 2 +- .../Http/ListenerPrimary.cs | 2 +- .../Http/ListenerSecondary.cs | 2 +- .../KestrelEngine.cs | 6 ++--- 7 files changed, 6 insertions(+), 70 deletions(-) delete mode 100644 src/Microsoft.AspNet.Server.Kestrel/Http/IListener.cs delete mode 100644 src/Microsoft.AspNet.Server.Kestrel/Http/IListenerPrimary.cs delete mode 100644 src/Microsoft.AspNet.Server.Kestrel/Http/IListenerSecondary.cs diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/IListener.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/IListener.cs deleted file mode 100644 index ccd6d104d4..0000000000 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/IListener.cs +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using System.Threading.Tasks; - -namespace Microsoft.AspNet.Server.Kestrel.Http -{ - /// - /// A listener waits for incoming connections on a specified socket. - /// - public interface IListener : IDisposable - { - Task StartAsync( - string scheme, - string host, - int port, - KestrelThread thread, - Func application); - } -} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/IListenerPrimary.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/IListenerPrimary.cs deleted file mode 100644 index 7a42fe02ef..0000000000 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/IListenerPrimary.cs +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using System.Threading.Tasks; - -namespace Microsoft.AspNet.Server.Kestrel.Http -{ - /// - /// A primary listener waits for incoming connections on a specified socket. Incoming - /// connections may be passed to a secondary listener to handle. - /// - public interface IListenerPrimary : IListener - { - Task StartAsync( - string pipeName, - string scheme, - string host, - int port, - KestrelThread thread, - Func application); - } -} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/IListenerSecondary.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/IListenerSecondary.cs deleted file mode 100644 index 3230a7e1bc..0000000000 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/IListenerSecondary.cs +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using System.Threading.Tasks; - -namespace Microsoft.AspNet.Server.Kestrel.Http -{ - /// - /// A secondary listener is delegated requests from a primary listener via a named pipe or - /// UNIX domain socket. - /// - public interface IListenerSecondary : IDisposable - { - Task StartAsync( - string pipeName, - KestrelThread thread, - Func application); - } -} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs index 55d8d8dc93..b59e7253c1 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs @@ -11,7 +11,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http /// /// Base class for listeners in Kestrel. Listens for incoming connections /// - public abstract class Listener : ListenerContext, IListener + public abstract class Listener : ListenerContext, IDisposable { protected UvStreamHandle ListenSocket { get; private set; } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerPrimary.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerPrimary.cs index df4fdb09fa..6df605409d 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerPrimary.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerPrimary.cs @@ -13,7 +13,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http /// A primary listener waits for incoming connections on a specified socket. Incoming /// connections may be passed to a secondary listener to handle. /// - abstract public class ListenerPrimary : Listener, IListenerPrimary + abstract public class ListenerPrimary : Listener { UvPipeHandle ListenPipe { get; set; } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerSecondary.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerSecondary.cs index 1ca3c9b193..71919b0035 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerSecondary.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerSecondary.cs @@ -13,7 +13,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http /// A secondary listener is delegated requests from a primary listener via a named pipe or /// UNIX domain socket. /// - public abstract class ListenerSecondary : ListenerContext, IListenerSecondary + public abstract class ListenerSecondary : ListenerContext, IDisposable { UvPipeHandle DispatchPipe { get; set; } diff --git a/src/Microsoft.AspNet.Server.Kestrel/KestrelEngine.cs b/src/Microsoft.AspNet.Server.Kestrel/KestrelEngine.cs index 6d5782d54b..61331e9798 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/KestrelEngine.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/KestrelEngine.cs @@ -117,7 +117,7 @@ namespace Microsoft.AspNet.Server.Kestrel if (single) { var listener = usingPipes ? - (IListener) new PipeListener(Memory) : + (Listener) new PipeListener(Memory) : new TcpListener(Memory); listeners.Add(listener); listener.StartAsync(scheme, host, port, thread, application).Wait(); @@ -125,7 +125,7 @@ namespace Microsoft.AspNet.Server.Kestrel else if (first) { var listener = usingPipes - ? (IListenerPrimary) new PipeListenerPrimary(Memory) + ? (ListenerPrimary) new PipeListenerPrimary(Memory) : new TcpListenerPrimary(Memory); listeners.Add(listener); @@ -134,7 +134,7 @@ namespace Microsoft.AspNet.Server.Kestrel else { var listener = usingPipes - ? (IListenerSecondary) new PipeListenerSecondary(Memory) + ? (ListenerSecondary) new PipeListenerSecondary(Memory) : new TcpListenerSecondary(Memory); listeners.Add(listener); listener.StartAsync(pipeName, thread, application).Wait(); From d0bd2b3dd03636e7e0af05d6829cf6bacf9e7096 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Thu, 20 Aug 2015 15:28:05 -0700 Subject: [PATCH 0221/1662] Configure unix pipes via the hostname instead of the scheme. --- samples/SampleApp/project.json | 2 +- .../Infrastructure/Constants.cs | 4 +- .../KestrelEngine.cs | 7 +- .../ServerAddress.cs | 96 ++++++++++++------- .../ServerFactory.cs | 4 +- 5 files changed, 70 insertions(+), 43 deletions(-) diff --git a/samples/SampleApp/project.json b/samples/SampleApp/project.json index 8fa276d0c5..899732b65b 100644 --- a/samples/SampleApp/project.json +++ b/samples/SampleApp/project.json @@ -13,7 +13,7 @@ }, "commands": { "run": "Microsoft.AspNet.Server.Kestrel", - "run-socket": "Microsoft.AspNet.Server.Kestrel --server.urls unix:///tmp/kestrel-test.sock", + "run-socket": "Microsoft.AspNet.Server.Kestrel --server.urls http://unix:/tmp/kestrel-test.sock", "kestrel": "Microsoft.AspNet.Server.Kestrel", "web": "Microsoft.AspNet.Hosting" } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/Constants.cs b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/Constants.cs index 76b5f1bd5d..06a2bed9d6 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/Constants.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/Constants.cs @@ -8,8 +8,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure public const int ListenBacklog = 128; /// - /// URL scheme for specifying Unix sockets in the configuration. + /// Prefix of host name used to specify Unix sockets in the configuration. /// - public const string UnixScheme = "unix"; + public const string UnixPipeHostPrefix = "unix:/"; } } diff --git a/src/Microsoft.AspNet.Server.Kestrel/KestrelEngine.cs b/src/Microsoft.AspNet.Server.Kestrel/KestrelEngine.cs index 61331e9798..161ba83d07 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/KestrelEngine.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/KestrelEngine.cs @@ -103,7 +103,12 @@ namespace Microsoft.AspNet.Server.Kestrel public IDisposable CreateServer(string scheme, string host, int port, Func application) { var listeners = new List(); - var usingPipes = scheme == Constants.UnixScheme; + var usingPipes = host.StartsWith(Constants.UnixPipeHostPrefix); + if (usingPipes) + { + // Subtract one because we want to include the '/' character that starts the path. + host = host.Substring(Constants.UnixPipeHostPrefix.Length - 1); + } try { diff --git a/src/Microsoft.AspNet.Server.Kestrel/ServerAddress.cs b/src/Microsoft.AspNet.Server.Kestrel/ServerAddress.cs index 845baf11bc..44fcf94d5c 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/ServerAddress.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/ServerAddress.cs @@ -3,6 +3,7 @@ using System; using System.Globalization; +using Microsoft.AspNet.Server.Kestrel.Infrastructure; namespace Microsoft.AspNet.Server.Kestrel { @@ -17,51 +18,74 @@ namespace Microsoft.AspNet.Server.Kestrel { url = url ?? string.Empty; - int delimiterStart1 = url.IndexOf("://", StringComparison.Ordinal); - if (delimiterStart1 < 0) + int schemeDelimiterStart = url.IndexOf("://", StringComparison.Ordinal); + if (schemeDelimiterStart < 0) { return null; } - int delimiterEnd1 = delimiterStart1 + "://".Length; + int schemeDelimiterEnd = schemeDelimiterStart + "://".Length; - int delimiterStart3 = url.IndexOf("/", delimiterEnd1, StringComparison.Ordinal); - if (delimiterStart3 < 0) + var isUnixPipe = url.IndexOf(Constants.UnixPipeHostPrefix, schemeDelimiterEnd, StringComparison.Ordinal) == schemeDelimiterEnd; + + int pathDelimiterStart; + int pathDelimiterEnd; + if (!isUnixPipe) { - delimiterStart3 = url.Length; - } - int delimiterStart2 = url.LastIndexOf(":", delimiterStart3 - 1, delimiterStart3 - delimiterEnd1, StringComparison.Ordinal); - int delimiterEnd2 = delimiterStart2 + ":".Length; - if (delimiterStart2 < 0) - { - delimiterStart2 = delimiterStart3; - delimiterEnd2 = delimiterStart3; - } - var serverAddress = new ServerAddress(); - serverAddress.Scheme = url.Substring(0, delimiterStart1); - string portString = url.Substring(delimiterEnd2, delimiterStart3 - delimiterEnd2); - int portNumber; - if (int.TryParse(portString, NumberStyles.Integer, CultureInfo.InvariantCulture, out portNumber)) - { - serverAddress.Host = url.Substring(delimiterEnd1, delimiterStart2 - delimiterEnd1); - serverAddress.Port = portNumber; + pathDelimiterStart = url.IndexOf("/", schemeDelimiterEnd, StringComparison.Ordinal); + pathDelimiterEnd = pathDelimiterStart; } else { - if (string.Equals(serverAddress.Scheme, "http", StringComparison.OrdinalIgnoreCase)) - { - serverAddress.Port = 80; - } - else if (string.Equals(serverAddress.Scheme, "https", StringComparison.OrdinalIgnoreCase)) - { - serverAddress.Port = 443; - } - else - { - serverAddress.Port = 0; - } - serverAddress.Host = url.Substring(delimiterEnd1, delimiterStart3 - delimiterEnd1); + pathDelimiterStart = url.IndexOf(":", schemeDelimiterEnd + Constants.UnixPipeHostPrefix.Length, StringComparison.Ordinal); + pathDelimiterEnd = pathDelimiterStart + ":".Length; } - serverAddress.Path = url.Substring(delimiterStart3); + + if (pathDelimiterStart < 0) + { + pathDelimiterStart = pathDelimiterEnd = url.Length; + } + + var serverAddress = new ServerAddress(); + serverAddress.Scheme = url.Substring(0, schemeDelimiterStart); + + var hasSpecifiedPort = false; + if (!isUnixPipe) + { + int portDelimiterStart = url.LastIndexOf(":", pathDelimiterStart - 1, pathDelimiterStart - schemeDelimiterEnd, StringComparison.Ordinal); + if (portDelimiterStart >= 0) + { + int portDelimiterEnd = portDelimiterStart + ":".Length; + + string portString = url.Substring(portDelimiterEnd, pathDelimiterStart - portDelimiterEnd); + int portNumber; + if (int.TryParse(portString, NumberStyles.Integer, CultureInfo.InvariantCulture, out portNumber)) + { + hasSpecifiedPort = true; + serverAddress.Host = url.Substring(schemeDelimiterEnd, portDelimiterStart - schemeDelimiterEnd); + serverAddress.Port = portNumber; + } + } + + if (!hasSpecifiedPort) + { + if (string.Equals(serverAddress.Scheme, "http", StringComparison.OrdinalIgnoreCase)) + { + serverAddress.Port = 80; + } + else if (string.Equals(serverAddress.Scheme, "https", StringComparison.OrdinalIgnoreCase)) + { + serverAddress.Port = 443; + } + } + } + + if (!hasSpecifiedPort) + { + serverAddress.Host = url.Substring(schemeDelimiterEnd, pathDelimiterStart - schemeDelimiterEnd); + } + + serverAddress.Path = url.Substring(pathDelimiterEnd); + return serverAddress; } } diff --git a/src/Microsoft.AspNet.Server.Kestrel/ServerFactory.cs b/src/Microsoft.AspNet.Server.Kestrel/ServerFactory.cs index 0631303cac..0163e9dc16 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/ServerFactory.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/ServerFactory.cs @@ -8,7 +8,6 @@ using Microsoft.AspNet.Hosting.Server; using Microsoft.AspNet.Http.Features; using Microsoft.Dnx.Runtime; using Microsoft.Framework.Configuration; -using Constants = Microsoft.AspNet.Server.Kestrel.Infrastructure.Constants; namespace Microsoft.AspNet.Server.Kestrel { @@ -43,8 +42,7 @@ namespace Microsoft.AspNet.Server.Kestrel { disposables.Add(engine.CreateServer( address.Scheme, - // Unix sockets use a file path, not a hostname. - address.Scheme == Constants.UnixScheme ? address.Path : address.Host, + address.Host, address.Port, async frame => { From e1b472ddc4a2ed367e1a0988745b9c0fba6f5607 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Mon, 24 Aug 2015 12:37:23 -0700 Subject: [PATCH 0222/1662] Add ServerAddress tests --- .../ServerAddressFacts.cs | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 test/Microsoft.AspNet.Server.KestrelTests/ServerAddressFacts.cs diff --git a/test/Microsoft.AspNet.Server.KestrelTests/ServerAddressFacts.cs b/test/Microsoft.AspNet.Server.KestrelTests/ServerAddressFacts.cs new file mode 100644 index 0000000000..5b280c5e68 --- /dev/null +++ b/test/Microsoft.AspNet.Server.KestrelTests/ServerAddressFacts.cs @@ -0,0 +1,47 @@ +using Microsoft.AspNet.Server.Kestrel; +using Xunit; + +namespace Microsoft.AspNet.Server.KestrelTests +{ + public class ServerAddressFacts + { + [Theory] + [InlineData("")] + [InlineData("//noscheme")] + public void FromUriReturnsNullForSchemelessUrls(string url) + { + Assert.Null(ServerAddress.FromUrl(url)); + } + + [Theory] + [InlineData("://emptyscheme", "", "emptyscheme", 0, "")] + [InlineData("http://localhost", "http", "localhost", 80, "")] + [InlineData("http://www.example.com", "http", "www.example.com", 80, "")] + [InlineData("https://www.example.com", "https", "www.example.com", 443, "")] + [InlineData("http://www.example.com/", "http", "www.example.com", 80, "/")] + [InlineData("http://www.example.com/foo?bar=baz", "http", "www.example.com", 80, "/foo?bar=baz")] + [InlineData("http://www.example.com:5000", "http", "www.example.com", 5000, "")] + [InlineData("https://www.example.com:5000", "https", "www.example.com", 5000, "")] + [InlineData("http://www.example.com:5000/", "http", "www.example.com", 5000, "/")] + [InlineData("http://www.example.com:NOTAPORT", "http", "www.example.com:NOTAPORT", 80, "")] + [InlineData("https://www.example.com:NOTAPORT", "https", "www.example.com:NOTAPORT", 443, "")] + [InlineData("http://www.example.com:NOTAPORT/", "http", "www.example.com:NOTAPORT", 80, "/")] + [InlineData("http://foo:/tmp/kestrel-test.sock:5000/doesn't/matter", "http", "foo:", 80, "/tmp/kestrel-test.sock:5000/doesn't/matter")] + [InlineData("http://unix:foo/tmp/kestrel-test.sock", "http", "unix:foo", 80, "/tmp/kestrel-test.sock")] + [InlineData("http://unix:5000/tmp/kestrel-test.sock", "http", "unix", 5000, "/tmp/kestrel-test.sock")] + [InlineData("http://unix:/tmp/kestrel-test.sock", "http", "unix:/tmp/kestrel-test.sock", 0, "")] + [InlineData("https://unix:/tmp/kestrel-test.sock", "https", "unix:/tmp/kestrel-test.sock", 0, "")] + [InlineData("http://unix:/tmp/kestrel-test.sock:", "http", "unix:/tmp/kestrel-test.sock", 0, "")] + [InlineData("http://unix:/tmp/kestrel-test.sock:/", "http", "unix:/tmp/kestrel-test.sock", 0, "/")] + [InlineData("http://unix:/tmp/kestrel-test.sock:5000/doesn't/matter", "http", "unix:/tmp/kestrel-test.sock", 0, "5000/doesn't/matter")] + public void UrlsAreParsedCorrectly(string url, string scheme, string host, int port, string path) + { + var serverAddress = ServerAddress.FromUrl(url); + + Assert.Equal(scheme, serverAddress.Scheme); + Assert.Equal(host, serverAddress.Host); + Assert.Equal(port, serverAddress.Port); + Assert.Equal(path, serverAddress.Path); + } + } +} From e8b6908b045820136bdf3e312c83828867584ded Mon Sep 17 00:00:00 2001 From: David Fowler Date: Tue, 1 Sep 2015 02:20:22 -0700 Subject: [PATCH 0223/1662] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a43c71f919..854a25705f 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,6 @@ AppVeyor: [![AppVeyor](https://ci.appveyor.com/api/projects/status/nr0s92ykm57q0 Travis: [![Travis](https://travis-ci.org/aspnet/KestrelHttpServer.svg?branch=dev)](https://travis-ci.org/aspnet/KestrelHttpServer) -This repo contains a development web server for ASP.NET 5 based on [libuv](https://github.com/libuv/libuv). +This repo contains a web server for ASP.NET 5 based on [libuv](https://github.com/libuv/libuv). This project is part of ASP.NET 5. You can find samples, documentation and getting started instructions for ASP.NET 5 at the [Home](https://github.com/aspnet/home) repo. From c2192d7bd1eebdda9f13665b614f124fac3c311f Mon Sep 17 00:00:00 2001 From: Chris R Date: Mon, 31 Aug 2015 17:09:54 -0700 Subject: [PATCH 0224/1662] Change IServerInformation to IFeatureCollection. --- ...erInformation.cs => KestrelServerInformation.cs} | 13 ++----------- .../ServerFactory.cs | 12 +++++++----- 2 files changed, 9 insertions(+), 16 deletions(-) rename src/Microsoft.AspNet.Server.Kestrel/{ServerInformation.cs => KestrelServerInformation.cs} (78%) diff --git a/src/Microsoft.AspNet.Server.Kestrel/ServerInformation.cs b/src/Microsoft.AspNet.Server.Kestrel/KestrelServerInformation.cs similarity index 78% rename from src/Microsoft.AspNet.Server.Kestrel/ServerInformation.cs rename to src/Microsoft.AspNet.Server.Kestrel/KestrelServerInformation.cs index 423c848623..b526b59635 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/ServerInformation.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/KestrelServerInformation.cs @@ -3,14 +3,13 @@ using System; using System.Collections.Generic; -using Microsoft.AspNet.Hosting.Server; using Microsoft.Framework.Configuration; namespace Microsoft.AspNet.Server.Kestrel { - public class ServerInformation : IServerInformation, IKestrelServerInformation + public class KestrelServerInformation : IKestrelServerInformation { - public ServerInformation() + public KestrelServerInformation() { Addresses = new List(); } @@ -32,14 +31,6 @@ namespace Microsoft.AspNet.Server.Kestrel } } - public string Name - { - get - { - return "Kestrel"; - } - } - public IList Addresses { get; private set; } public int ThreadCount { get; set; } diff --git a/src/Microsoft.AspNet.Server.Kestrel/ServerFactory.cs b/src/Microsoft.AspNet.Server.Kestrel/ServerFactory.cs index 0163e9dc16..13b2aaac33 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/ServerFactory.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/ServerFactory.cs @@ -25,17 +25,19 @@ namespace Microsoft.AspNet.Server.Kestrel _appShutdownService = appShutdownService; } - public IServerInformation Initialize(IConfiguration configuration) + public IFeatureCollection Initialize(IConfiguration configuration) { - var information = new ServerInformation(); + var information = new KestrelServerInformation(); information.Initialize(configuration); - return information; + var serverFeatures = new FeatureCollection(); + serverFeatures.Set(information); + return serverFeatures; } - public IDisposable Start(IServerInformation serverInformation, Func application) + public IDisposable Start(IFeatureCollection serverFeatures, Func application) { var disposables = new List(); - var information = (ServerInformation)serverInformation; + var information = (KestrelServerInformation)serverFeatures.Get(); var engine = new KestrelEngine(_libraryManager, _appShutdownService); engine.Start(information.ThreadCount == 0 ? 1 : information.ThreadCount); foreach (var address in information.Addresses) From 46604d68b3326547c81660a25a2961634365badd Mon Sep 17 00:00:00 2001 From: Louis DeJardin Date: Tue, 1 Sep 2015 22:25:51 -0700 Subject: [PATCH 0225/1662] Initial commit for style cleanup #184 * adding private keyword to fields * one type per file --- KestrelHttpServer.sln | 7 + global.json | 3 +- .../Http/Connection.cs | 2 +- .../Http/Frame.cs | 12 +- .../Http/FrameDuplexStream.cs | 4 +- .../Http/FrameHeaders.Generated.cs | 146 +++++++++--------- .../Http/FrameHeaders.cs | 101 +----------- .../Http/FrameRequestHeaders.cs | 57 +++++++ .../Http/FrameRequestStream.cs | 2 +- .../Http/FrameResponseHeaders.cs | 57 +++++++ .../Http/ListenerPrimary.cs | 6 +- .../Http/MemoryPool.cs | 12 +- .../Http/MessageBodyExchanger.cs | 8 +- .../Infrastructure/KestrelThread.cs | 20 +-- .../Networking/Libuv.cs | 8 +- .../Networking/UvConnectRequest.cs | 4 +- .../Networking/UvHandle.cs | 4 +- .../Networking/UvRequest.cs | 2 +- .../Networking/UvShutdownReq.cs | 4 +- .../Networking/UvWriteReq.cs | 10 +- .../ServerRequest.cs | 6 +- .../project.json | 6 +- .../KnownHeaders.cs | 4 +- .../Program.cs | 3 - .../Microsoft.StandardsPolice.xproj | 20 +++ tools/Microsoft.StandardsPolice/Program.cs | 49 ++++++ .../StandardsPoliceCompileModule.cs | 109 +++++++++++++ tools/Microsoft.StandardsPolice/project.json | 28 ++++ 28 files changed, 465 insertions(+), 229 deletions(-) create mode 100644 src/Microsoft.AspNet.Server.Kestrel/Http/FrameRequestHeaders.cs create mode 100644 src/Microsoft.AspNet.Server.Kestrel/Http/FrameResponseHeaders.cs create mode 100644 tools/Microsoft.StandardsPolice/Microsoft.StandardsPolice.xproj create mode 100644 tools/Microsoft.StandardsPolice/Program.cs create mode 100644 tools/Microsoft.StandardsPolice/StandardsPoliceCompileModule.cs create mode 100644 tools/Microsoft.StandardsPolice/project.json diff --git a/KestrelHttpServer.sln b/KestrelHttpServer.sln index 980a5d2537..02d3731464 100644 --- a/KestrelHttpServer.sln +++ b/KestrelHttpServer.sln @@ -29,6 +29,8 @@ Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.Server.Kes EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tools", "tools", "{327F7880-D9AF-46BD-B45C-3B7E34A01DFD}" EndProject +Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.StandardsPolice", "tools\Microsoft.StandardsPolice\Microsoft.StandardsPolice.xproj", "{82295647-7C1C-4671-BAB6-0FEF58F949EC}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -55,6 +57,10 @@ Global {BD2D4D29-1BD9-40D0-BB31-337D5416B63C}.Debug|Any CPU.Build.0 = Debug|Any CPU {BD2D4D29-1BD9-40D0-BB31-337D5416B63C}.Release|Any CPU.ActiveCfg = Release|Any CPU {BD2D4D29-1BD9-40D0-BB31-337D5416B63C}.Release|Any CPU.Build.0 = Release|Any CPU + {82295647-7C1C-4671-BAB6-0FEF58F949EC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {82295647-7C1C-4671-BAB6-0FEF58F949EC}.Debug|Any CPU.Build.0 = Debug|Any CPU + {82295647-7C1C-4671-BAB6-0FEF58F949EC}.Release|Any CPU.ActiveCfg = Release|Any CPU + {82295647-7C1C-4671-BAB6-0FEF58F949EC}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -65,5 +71,6 @@ Global {2C3CB3DC-EEBF-4F52-9E1C-4F2F972E76C3} = {8A3D00B8-1CCF-4BE6-A060-11104CE2D9CE} {B35D4D31-E74C-4646-8A11-7A7A40F0021E} = {8A3D00B8-1CCF-4BE6-A060-11104CE2D9CE} {BD2D4D29-1BD9-40D0-BB31-337D5416B63C} = {327F7880-D9AF-46BD-B45C-3B7E34A01DFD} + {82295647-7C1C-4671-BAB6-0FEF58F949EC} = {327F7880-D9AF-46BD-B45C-3B7E34A01DFD} EndGlobalSection EndGlobal diff --git a/global.json b/global.json index 302a900d30..aa789b9c9c 100644 --- a/global.json +++ b/global.json @@ -1,5 +1,6 @@ { "projects": [ - "src" + "src", + "tools" ] } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs index 641d184f8c..81a3551b6d 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs @@ -27,7 +27,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http private readonly UvStreamHandle _socket; private Frame _frame; - long _connectionId = 0; + private long _connectionId = 0; private readonly object _stateLock = new object(); private ConnectionState _connectionState; diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs index ded01e3efa..18138ab5e1 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs @@ -24,8 +24,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http Terminated, } - static Encoding _ascii = Encoding.ASCII; - Mode _mode; + private static Encoding _ascii = Encoding.ASCII; + private Mode _mode; private bool _responseStarted; private bool _keepAlive; private bool _autoChunk; @@ -38,10 +38,10 @@ namespace Microsoft.AspNet.Server.Kestrel.Http CancellationTokenSource _cts = new CancellationTokenSource(); */ - List, object>> _onStarting; - List, object>> _onCompleted; - object _onStartingSync = new Object(); - object _onCompletedSync = new Object(); + private List, object>> _onStarting; + private List, object>> _onCompleted; + private object _onStartingSync = new Object(); + private object _onCompletedSync = new Object(); public Frame(ConnectionContext context) : base(context) { diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameDuplexStream.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameDuplexStream.cs index 58b2c88d0a..0086cdf0aa 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameDuplexStream.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameDuplexStream.cs @@ -12,8 +12,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { class FrameDuplexStream : Stream { - readonly Stream _requestStream; - readonly Stream _responseStream; + private readonly Stream _requestStream; + private readonly Stream _responseStream; public FrameDuplexStream(Stream requestStream, Stream responseStream) { diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameHeaders.Generated.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameHeaders.Generated.cs index a79b61d4c4..f0975ff9b0 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameHeaders.Generated.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameHeaders.Generated.cs @@ -17,49 +17,49 @@ namespace Microsoft.AspNet.Server.Kestrel.Http public partial class FrameRequestHeaders { - long _bits = 0; + private long _bits = 0; - StringValues _CacheControl; - StringValues _Connection; - StringValues _Date; - StringValues _KeepAlive; - StringValues _Pragma; - StringValues _Trailer; - StringValues _TransferEncoding; - StringValues _Upgrade; - StringValues _Via; - StringValues _Warning; - StringValues _Allow; - StringValues _ContentLength; - StringValues _ContentType; - StringValues _ContentEncoding; - StringValues _ContentLanguage; - StringValues _ContentLocation; - StringValues _ContentMD5; - StringValues _ContentRange; - StringValues _Expires; - StringValues _LastModified; - StringValues _Accept; - StringValues _AcceptCharset; - StringValues _AcceptEncoding; - StringValues _AcceptLanguage; - StringValues _Authorization; - StringValues _Cookie; - StringValues _Expect; - StringValues _From; - StringValues _Host; - StringValues _IfMatch; - StringValues _IfModifiedSince; - StringValues _IfNoneMatch; - StringValues _IfRange; - StringValues _IfUnmodifiedSince; - StringValues _MaxForwards; - StringValues _ProxyAuthorization; - StringValues _Referer; - StringValues _Range; - StringValues _TE; - StringValues _Translate; - StringValues _UserAgent; + private StringValues _CacheControl; + private StringValues _Connection; + private StringValues _Date; + private StringValues _KeepAlive; + private StringValues _Pragma; + private StringValues _Trailer; + private StringValues _TransferEncoding; + private StringValues _Upgrade; + private StringValues _Via; + private StringValues _Warning; + private StringValues _Allow; + private StringValues _ContentLength; + private StringValues _ContentType; + private StringValues _ContentEncoding; + private StringValues _ContentLanguage; + private StringValues _ContentLocation; + private StringValues _ContentMD5; + private StringValues _ContentRange; + private StringValues _Expires; + private StringValues _LastModified; + private StringValues _Accept; + private StringValues _AcceptCharset; + private StringValues _AcceptEncoding; + private StringValues _AcceptLanguage; + private StringValues _Authorization; + private StringValues _Cookie; + private StringValues _Expect; + private StringValues _From; + private StringValues _Host; + private StringValues _IfMatch; + private StringValues _IfModifiedSince; + private StringValues _IfNoneMatch; + private StringValues _IfRange; + private StringValues _IfUnmodifiedSince; + private StringValues _MaxForwards; + private StringValues _ProxyAuthorization; + private StringValues _Referer; + private StringValues _Range; + private StringValues _TE; + private StringValues _Translate; + private StringValues _UserAgent; protected override int GetCountFast() { @@ -4587,38 +4587,38 @@ namespace Microsoft.AspNet.Server.Kestrel.Http public partial class FrameResponseHeaders { - long _bits = 0; + private long _bits = 0; - StringValues _CacheControl; - StringValues _Connection; - StringValues _Date; - StringValues _KeepAlive; - StringValues _Pragma; - StringValues _Trailer; - StringValues _TransferEncoding; - StringValues _Upgrade; - StringValues _Via; - StringValues _Warning; - StringValues _Allow; - StringValues _ContentLength; - StringValues _ContentType; - StringValues _ContentEncoding; - StringValues _ContentLanguage; - StringValues _ContentLocation; - StringValues _ContentMD5; - StringValues _ContentRange; - StringValues _Expires; - StringValues _LastModified; - StringValues _AcceptRanges; - StringValues _Age; - StringValues _ETag; - StringValues _Location; - StringValues _ProxyAutheticate; - StringValues _RetryAfter; - StringValues _Server; - StringValues _SetCookie; - StringValues _Vary; - StringValues _WWWAuthenticate; + private StringValues _CacheControl; + private StringValues _Connection; + private StringValues _Date; + private StringValues _KeepAlive; + private StringValues _Pragma; + private StringValues _Trailer; + private StringValues _TransferEncoding; + private StringValues _Upgrade; + private StringValues _Via; + private StringValues _Warning; + private StringValues _Allow; + private StringValues _ContentLength; + private StringValues _ContentType; + private StringValues _ContentEncoding; + private StringValues _ContentLanguage; + private StringValues _ContentLocation; + private StringValues _ContentMD5; + private StringValues _ContentRange; + private StringValues _Expires; + private StringValues _LastModified; + private StringValues _AcceptRanges; + private StringValues _Age; + private StringValues _ETag; + private StringValues _Location; + private StringValues _ProxyAutheticate; + private StringValues _RetryAfter; + private StringValues _Server; + private StringValues _SetCookie; + private StringValues _Vary; + private StringValues _WWWAuthenticate; protected override int GetCountFast() { diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameHeaders.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameHeaders.cs index c8a6d7cd44..55191ec076 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameHeaders.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameHeaders.cs @@ -1,4 +1,7 @@ -using System; +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; using System.Collections; using System.Collections.Generic; using System.Linq; @@ -129,100 +132,4 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return TryGetValueFast(key, out value); } } - - public partial class FrameRequestHeaders : FrameHeaders - { - public Enumerator GetEnumerator() - { - return new Enumerator(this); - } - - protected override IEnumerator> GetEnumeratorFast() - { - return GetEnumerator(); - } - - public partial struct Enumerator : IEnumerator> - { - FrameRequestHeaders _collection; - long _bits; - int _state; - KeyValuePair _current; - bool _hasUnknown; - Dictionary.Enumerator _unknownEnumerator; - - internal Enumerator(FrameRequestHeaders collection) - { - _collection = collection; - _bits = collection._bits; - _state = 0; - _current = default(KeyValuePair); - _hasUnknown = collection.MaybeUnknown != null; - _unknownEnumerator = _hasUnknown - ? collection.MaybeUnknown.GetEnumerator() - : default(Dictionary.Enumerator); - } - - public KeyValuePair Current => _current; - - object IEnumerator.Current => _current; - - public void Dispose() - { - } - - public void Reset() - { - _state = 0; - } - } - } - - public partial class FrameResponseHeaders : FrameHeaders - { - public Enumerator GetEnumerator() - { - return new Enumerator(this); - } - - protected override IEnumerator> GetEnumeratorFast() - { - return GetEnumerator(); - } - - public partial struct Enumerator : IEnumerator> - { - FrameResponseHeaders _collection; - long _bits; - int _state; - KeyValuePair _current; - bool _hasUnknown; - Dictionary.Enumerator _unknownEnumerator; - - internal Enumerator(FrameResponseHeaders collection) - { - _collection = collection; - _bits = collection._bits; - _state = 0; - _current = default(KeyValuePair); - _hasUnknown = collection.MaybeUnknown != null; - _unknownEnumerator = _hasUnknown - ? collection.MaybeUnknown.GetEnumerator() - : default(Dictionary.Enumerator); - } - - public KeyValuePair Current => _current; - - object IEnumerator.Current => _current; - - public void Dispose() - { - } - - public void Reset() - { - _state = 0; - } - } - } } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameRequestHeaders.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameRequestHeaders.cs new file mode 100644 index 0000000000..f6d1dc82e0 --- /dev/null +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameRequestHeaders.cs @@ -0,0 +1,57 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using Microsoft.Framework.Primitives; +using System.Collections; +using System.Collections.Generic; + +namespace Microsoft.AspNet.Server.Kestrel.Http +{ + public partial class FrameRequestHeaders : FrameHeaders + { + public Enumerator GetEnumerator() + { + return new Enumerator(this); + } + + protected override IEnumerator> GetEnumeratorFast() + { + return GetEnumerator(); + } + + public partial struct Enumerator : IEnumerator> + { + private FrameRequestHeaders _collection; + private long _bits; + private int _state; + private KeyValuePair _current; + private bool _hasUnknown; + private Dictionary.Enumerator _unknownEnumerator; + + internal Enumerator(FrameRequestHeaders collection) + { + _collection = collection; + _bits = collection._bits; + _state = 0; + _current = default(KeyValuePair); + _hasUnknown = collection.MaybeUnknown != null; + _unknownEnumerator = _hasUnknown + ? collection.MaybeUnknown.GetEnumerator() + : default(Dictionary.Enumerator); + } + + public KeyValuePair Current => _current; + + object IEnumerator.Current => _current; + + public void Dispose() + { + } + + public void Reset() + { + _state = 0; + } + } + } +} diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameRequestStream.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameRequestStream.cs index 47873ea1d1..2932eab142 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameRequestStream.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameRequestStream.cs @@ -10,7 +10,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { public class FrameRequestStream : Stream { - readonly MessageBody _body; + private readonly MessageBody _body; //int _readLength; //bool _readFin; diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameResponseHeaders.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameResponseHeaders.cs new file mode 100644 index 0000000000..7d1b15ade1 --- /dev/null +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameResponseHeaders.cs @@ -0,0 +1,57 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using Microsoft.Framework.Primitives; +using System.Collections; +using System.Collections.Generic; + +namespace Microsoft.AspNet.Server.Kestrel.Http +{ + public partial class FrameResponseHeaders : FrameHeaders + { + public Enumerator GetEnumerator() + { + return new Enumerator(this); + } + + protected override IEnumerator> GetEnumeratorFast() + { + return GetEnumerator(); + } + + public partial struct Enumerator : IEnumerator> + { + private FrameResponseHeaders _collection; + private long _bits; + private int _state; + private KeyValuePair _current; + private bool _hasUnknown; + private Dictionary.Enumerator _unknownEnumerator; + + internal Enumerator(FrameResponseHeaders collection) + { + _collection = collection; + _bits = collection._bits; + _state = 0; + _current = default(KeyValuePair); + _hasUnknown = collection.MaybeUnknown != null; + _unknownEnumerator = _hasUnknown + ? collection.MaybeUnknown.GetEnumerator() + : default(Dictionary.Enumerator); + } + + public KeyValuePair Current => _current; + + object IEnumerator.Current => _current; + + public void Dispose() + { + } + + public void Reset() + { + _state = 0; + } + } + } +} diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerPrimary.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerPrimary.cs index 6df605409d..516c027eac 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerPrimary.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerPrimary.cs @@ -17,9 +17,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { UvPipeHandle ListenPipe { get; set; } - List _dispatchPipes = new List(); - int _dispatchIndex; - ArraySegment> _1234 = new ArraySegment>(new[] { new ArraySegment(new byte[] { 1, 2, 3, 4 }) }); + private List _dispatchPipes = new List(); + private int _dispatchIndex; + private ArraySegment> _1234 = new ArraySegment>(new[] { new ArraySegment(new byte[] { 1, 2, 3, 4 }) }); protected ListenerPrimary(IMemoryPool memory) : base(memory) { diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/MemoryPool.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/MemoryPool.cs index e08eba68fd..cc26dad0c1 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/MemoryPool.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/MemoryPool.cs @@ -8,12 +8,12 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { public class MemoryPool : IMemoryPool { - static readonly byte[] EmptyArray = new byte[0]; + private static readonly byte[] EmptyArray = new byte[0]; class Pool { - readonly Stack _stack = new Stack(); - readonly object _sync = new object(); + private readonly Stack _stack = new Stack(); + private readonly object _sync = new object(); public T[] Alloc(int size) { @@ -39,9 +39,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } - readonly Pool _pool1 = new Pool(); - readonly Pool _pool2 = new Pool(); - readonly Pool _pool3 = new Pool(); + private readonly Pool _pool1 = new Pool(); + private readonly Pool _pool2 = new Pool(); + private readonly Pool _pool3 = new Pool(); public byte[] Empty { diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/MessageBodyExchanger.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/MessageBodyExchanger.cs index aee1933230..749f34433b 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/MessageBodyExchanger.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/MessageBodyExchanger.cs @@ -17,11 +17,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http private static readonly WaitCallback _completePending = CompletePending; protected readonly FrameContext _context; - object _sync = new Object(); + private object _sync = new Object(); - ArraySegment _buffer; - Queue _reads = new Queue(); - bool _send100Continue = true; + private ArraySegment _buffer; + private Queue _reads = new Queue(); + private bool _send100Continue = true; public MessageBodyExchanger(FrameContext context) { diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs index b2a2348c55..2355ae82be 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs @@ -16,16 +16,16 @@ namespace Microsoft.AspNet.Server.Kestrel /// public class KestrelThread { - KestrelEngine _engine; - Thread _thread; - UvLoopHandle _loop; - UvAsyncHandle _post; - Queue _workAdding = new Queue(); - Queue _workRunning = new Queue(); - Queue _closeHandleAdding = new Queue(); - Queue _closeHandleRunning = new Queue(); - object _workSync = new Object(); - bool _stopImmediate = false; + private KestrelEngine _engine; + private Thread _thread; + private UvLoopHandle _loop; + private UvAsyncHandle _post; + private Queue _workAdding = new Queue(); + private Queue _workRunning = new Queue(); + private Queue _closeHandleAdding = new Queue(); + private Queue _closeHandleRunning = new Queue(); + private object _workSync = new Object(); + private bool _stopImmediate = false; private ExceptionDispatchInfo _closeError; public KestrelThread(KestrelEngine engine) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/Libuv.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/Libuv.cs index 4ff90ecd5b..eec141a421 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/Libuv.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/Libuv.cs @@ -397,10 +397,10 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking { public sockaddr(long ignored) { x3 = x0 = x1 = x2 = x3 = 0; } - long x0; - long x1; - long x2; - long x3; + private long x0; + private long x1; + private long x2; + private long x3; } public struct uv_buf_t diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvConnectRequest.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvConnectRequest.cs index 90791f5fd8..1791fb56e7 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvConnectRequest.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvConnectRequest.cs @@ -15,8 +15,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking { private readonly static Libuv.uv_connect_cb _uv_connect_cb = UvConnectCb; - Action _callback; - object _state; + private Action _callback; + private object _state; public void Init(UvLoopHandle loop) { diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvHandle.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvHandle.cs index 4c9f23aec1..cb4d5a37dc 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvHandle.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvHandle.cs @@ -8,8 +8,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking { public abstract class UvHandle : UvMemory { - static Libuv.uv_close_cb _destroyMemory = DestroyMemory; - Action, IntPtr> _queueCloseHandle; + private static Libuv.uv_close_cb _destroyMemory = DestroyMemory; + private Action, IntPtr> _queueCloseHandle; unsafe protected void CreateHandle( Libuv uv, diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvRequest.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvRequest.cs index 42285e536a..e79ff42674 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvRequest.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvRequest.cs @@ -8,7 +8,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking { public class UvRequest : UvMemory { - GCHandle _pin; + private GCHandle _pin; protected override bool ReleaseHandle() { diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvShutdownReq.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvShutdownReq.cs index fc40f8967d..a8841754bf 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvShutdownReq.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvShutdownReq.cs @@ -13,8 +13,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking { private readonly static Libuv.uv_shutdown_cb _uv_shutdown_cb = UvShutdownCb; - Action _callback; - object _state; + private Action _callback; + private object _state; public void Init(UvLoopHandle loop) { diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvWriteReq.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvWriteReq.cs index 03eee35cd7..39aba8b4dc 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvWriteReq.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvWriteReq.cs @@ -15,13 +15,13 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking { private readonly static Libuv.uv_write_cb _uv_write_cb = UvWriteCb; - IntPtr _bufs; + private IntPtr _bufs; - Action _callback; - object _state; - const int BUFFER_COUNT = 4; + private Action _callback; + private object _state; + private const int BUFFER_COUNT = 4; - List _pins = new List(); + private List _pins = new List(); public void Init(UvLoopHandle loop) { diff --git a/src/Microsoft.AspNet.Server.Kestrel/ServerRequest.cs b/src/Microsoft.AspNet.Server.Kestrel/ServerRequest.cs index ebfa3f406c..ff4499c472 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/ServerRequest.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/ServerRequest.cs @@ -14,9 +14,9 @@ namespace Microsoft.AspNet.Server.Kestrel { public class ServerRequest : IHttpRequestFeature, IHttpResponseFeature, IHttpUpgradeFeature { - Frame _frame; - string _scheme; - string _pathBase; + private Frame _frame; + private string _scheme; + private string _pathBase; private FeatureCollection _features; public ServerRequest(Frame frame) diff --git a/src/Microsoft.AspNet.Server.Kestrel/project.json b/src/Microsoft.AspNet.Server.Kestrel/project.json index 883cf9570f..4a3d0ab496 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/project.json +++ b/src/Microsoft.AspNet.Server.Kestrel/project.json @@ -7,7 +7,11 @@ }, "dependencies": { "Microsoft.AspNet.Hosting": "1.0.0-*", - "Microsoft.Dnx.Runtime.Abstractions": "1.0.0-*" + "Microsoft.Dnx.Runtime.Abstractions": "1.0.0-*", + "Microsoft.StandardsPolice": { + "version": "1.0.0-*", + "type": "build" + } }, "frameworks": { "dnx451": { }, diff --git a/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/KnownHeaders.cs b/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/KnownHeaders.cs index c9da2fd71a..0593f879c1 100644 --- a/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/KnownHeaders.cs +++ b/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/KnownHeaders.cs @@ -186,9 +186,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Http {Each(loops, loop => $@" public partial class {loop.ClassName} {{ - long _bits = 0; + private long _bits = 0; {Each(loop.Headers, header => @" - StringValues _" + header.Identifier + ";")} + private StringValues _" + header.Identifier + ";")} protected override int GetCountFast() {{ diff --git a/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/Program.cs b/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/Program.cs index 610176c1c6..2a77e2542e 100644 --- a/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/Program.cs +++ b/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/Program.cs @@ -1,8 +1,5 @@ using System; -using System.Collections.Generic; using System.IO; -using System.Linq; -using System.Threading.Tasks; namespace Microsoft.AspNet.Server.Kestrel.GeneratedCode { diff --git a/tools/Microsoft.StandardsPolice/Microsoft.StandardsPolice.xproj b/tools/Microsoft.StandardsPolice/Microsoft.StandardsPolice.xproj new file mode 100644 index 0000000000..83282b2e37 --- /dev/null +++ b/tools/Microsoft.StandardsPolice/Microsoft.StandardsPolice.xproj @@ -0,0 +1,20 @@ + + + + 14.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + + + + + 82295647-7c1c-4671-bab6-0fef58f949ec + Microsoft.StandardsPolice + ..\..\artifacts\obj\$(MSBuildProjectName) + ..\..\artifacts\bin\$(MSBuildProjectName)\ + + + + 2.0 + + + diff --git a/tools/Microsoft.StandardsPolice/Program.cs b/tools/Microsoft.StandardsPolice/Program.cs new file mode 100644 index 0000000000..8dd9a0636d --- /dev/null +++ b/tools/Microsoft.StandardsPolice/Program.cs @@ -0,0 +1,49 @@ +using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.CSharp; +using Microsoft.CodeAnalysis.CSharp.Syntax; +using System; +using System.Collections.Generic; +using System.Linq; + +namespace Microsoft.StandardsPolice +{ + public class Program + { + public int Main(string[] args) + { + var tree = CSharpSyntaxTree.ParseText(@" +public class Hello { protected int _foo; int _bar; } +public class World { protected int _foo; int _bar; } +"); + var diags = new List(); + + var comp = CSharpCompilation.Create("Comp", new[] { tree }); + + StandardsPoliceCompileModule.ScanSyntaxTree(diags, tree); + + var hello = comp.GetTypeByMetadataName("Hello"); + foreach (var f in hello.GetMembers().OfType()) + { + var syntax = f.DeclaringSyntaxReferences.Single().GetSyntax(); + Console.WriteLine($"{syntax.ToFullString()}"); + + var fds = syntax.Parent.Parent as FieldDeclarationSyntax; + var toks = syntax.DescendantTokens().ToArray(); + var nods = syntax.DescendantNodesAndSelf().ToArray(); + var mods = fds.Modifiers; + + foreach (var mod in fds.Modifiers) + { + Console.WriteLine($"{mod.Kind()} {mod.ToFullString()}"); + } + var locs = f.Locations.ToArray(); + } + + foreach(var d in diags) + { + Console.WriteLine(d); + } + return 0; + } + } +} diff --git a/tools/Microsoft.StandardsPolice/StandardsPoliceCompileModule.cs b/tools/Microsoft.StandardsPolice/StandardsPoliceCompileModule.cs new file mode 100644 index 0000000000..4981e0fc0c --- /dev/null +++ b/tools/Microsoft.StandardsPolice/StandardsPoliceCompileModule.cs @@ -0,0 +1,109 @@ +using Microsoft.Dnx.Compilation.CSharp; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.CSharp.Syntax; + +namespace Microsoft.StandardsPolice +{ + // This project can output the Class library as a NuGet Package. + // To enable this option, right-click on the project and select the Properties menu item. In the Build tab select "Produce outputs on build". + public class StandardsPoliceCompileModule : ICompileModule + { + public void BeforeCompile(BeforeCompileContext context) + { + ScanNamespace(context.Diagnostics, context.Compilation.GlobalNamespace); + + foreach (var st in context.Compilation.SyntaxTrees) + { + if (!st.FilePath.EndsWith(".Generated.cs")) + { + ScanSyntaxTree(context.Diagnostics, st); + } + } + } + + internal static void ScanSyntaxTree(IList diagnostics, SyntaxTree syntaxTree) + { + var root = syntaxTree.GetRoot(); + + var typeDeclarations = root.DescendantNodes(descendIntoChildren: node => !(node is TypeDeclarationSyntax)) + .OfType() + .ToArray(); + + if (typeDeclarations.Length > 1) + { + foreach (var typeDeclaration in typeDeclarations) + { + diagnostics.Add(Diagnostic.Create( + "SP1002", "StandardsPolice", "more than one type per file", + DiagnosticSeverity.Warning, + DiagnosticSeverity.Warning, + false, + 3, + location: typeDeclaration.GetLocation())); + } + } + } + + private static void ScanNamespace(IList diagnostics, INamespaceSymbol namespaceSymbol) + { + foreach (var member in namespaceSymbol.GetNamespaceMembers()) + { + ScanNamespace(diagnostics, member); + } + foreach (var member in namespaceSymbol.GetTypeMembers()) + { + ScanType(diagnostics, member); + } + } + + private static void ScanType(IList diagnostics, INamedTypeSymbol typeSymbol) + { + foreach (var member in typeSymbol.GetMembers().OfType()) + { + if (member.DeclaredAccessibility != Accessibility.Private) + { + continue; + } + + foreach (var syntaxReference in member.DeclaringSyntaxReferences) + { + var fieldHasPrivateKeyword = false; + var syntax = syntaxReference.GetSyntax(); + var fds = syntax?.Parent?.Parent as FieldDeclarationSyntax; + if (fds == null) + { + continue; + } + foreach (var mod in fds.Modifiers) + { + if (mod.IsKind(CodeAnalysis.CSharp.SyntaxKind.PrivateKeyword)) + { + fieldHasPrivateKeyword = true; + } + } + if (!fieldHasPrivateKeyword) + { + diagnostics.Add(Diagnostic.Create( + "SP1001", "StandardsPolice", "private keyword missing", + DiagnosticSeverity.Warning, + DiagnosticSeverity.Warning, + false, + 3, + location: member.Locations.SingleOrDefault())); + } + } + } + foreach (var member in typeSymbol.GetTypeMembers()) + { + ScanType(diagnostics, member); + } + } + public void AfterCompile(AfterCompileContext context) + { + } + } +} diff --git a/tools/Microsoft.StandardsPolice/project.json b/tools/Microsoft.StandardsPolice/project.json new file mode 100644 index 0000000000..d279e371a3 --- /dev/null +++ b/tools/Microsoft.StandardsPolice/project.json @@ -0,0 +1,28 @@ +{ + "version": "1.0.0-*", + + "description": "Microsoft.StandardsPolice Class Library", + + "dependencies": { + "Microsoft.Dnx.Compilation.CSharp.Abstractions": "1.0.0-beta8-*" + }, + + "commands": { + "Microsoft.StandardsPolice": "Microsoft.StandardsPolice" + }, + + "frameworks": { + "dnx451": { + "frameworkAssemblies": { + "System.Runtime": "", + "System.Text.Encoding": "", + "System.Threading.Tasks": "" + } + }, + "dnxcore50": { + "dependencies": { + "System.Console": "4.0.0-beta-*" + } + } + } +} From 2467cf2ade895de7a12636454852a215e02903a3 Mon Sep 17 00:00:00 2001 From: Louis DeJardin Date: Wed, 2 Sep 2015 00:07:58 -0700 Subject: [PATCH 0226/1662] Nested types must be last --- .../Http/Frame.cs | 16 ++--- .../Http/MemoryPool.cs | 58 +++++++++---------- .../Http/MessageBody.cs | 17 +++--- tools/Microsoft.StandardsPolice/Program.cs | 6 +- .../StandardsPoliceCompileModule.cs | 58 +++++++++++++++++-- 5 files changed, 101 insertions(+), 54 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs index 18138ab5e1..83f8bae9a6 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs @@ -16,14 +16,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { public class Frame : FrameContext, IFrameControl { - enum Mode - { - StartLine, - MessageHeader, - MessageBody, - Terminated, - } - private static Encoding _ascii = Encoding.ASCII; private Mode _mode; private bool _responseStarted; @@ -690,5 +682,13 @@ namespace Microsoft.AspNet.Server.Kestrel.Http statusCode != 205 && statusCode != 304; } + + enum Mode + { + StartLine, + MessageHeader, + MessageBody, + Terminated, + } } } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/MemoryPool.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/MemoryPool.cs index cc26dad0c1..0fc5c390e1 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/MemoryPool.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/MemoryPool.cs @@ -10,35 +10,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { private static readonly byte[] EmptyArray = new byte[0]; - class Pool - { - private readonly Stack _stack = new Stack(); - private readonly object _sync = new object(); - - public T[] Alloc(int size) - { - lock (_sync) - { - if (_stack.Count != 0) - { - return _stack.Pop(); - } - } - return new T[size]; - } - - public void Free(T[] value, int limit) - { - lock (_sync) - { - if (_stack.Count < limit) - { - _stack.Push(value); - } - } - } - } - private readonly Pool _pool1 = new Pool(); private readonly Pool _pool2 = new Pool(); private readonly Pool _pool3 = new Pool(); @@ -121,5 +92,34 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { FreeByte(segment.Array); } + + class Pool + { + private readonly Stack _stack = new Stack(); + private readonly object _sync = new object(); + + public T[] Alloc(int size) + { + lock (_sync) + { + if (_stack.Count != 0) + { + return _stack.Pop(); + } + } + return new T[size]; + } + + public void Free(T[] value, int limit) + { + lock (_sync) + { + if (_stack.Count < limit) + { + _stack.Push(value); + } + } + } + } } } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/MessageBody.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/MessageBody.cs index e7f788edbc..bc60f0c39f 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/MessageBody.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/MessageBody.cs @@ -148,15 +148,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Http private Mode _mode = Mode.ChunkSizeLine; - private enum Mode - { - ChunkSizeLine, - ChunkData, - ChunkDataCRLF, - Complete, - }; - - public ForChunkedEncoding(bool keepAlive, FrameContext context) : base(context) { @@ -305,6 +296,14 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } return false; } + + private enum Mode + { + ChunkSizeLine, + ChunkData, + ChunkDataCRLF, + Complete, + }; } } } diff --git a/tools/Microsoft.StandardsPolice/Program.cs b/tools/Microsoft.StandardsPolice/Program.cs index 8dd9a0636d..0967dbc35c 100644 --- a/tools/Microsoft.StandardsPolice/Program.cs +++ b/tools/Microsoft.StandardsPolice/Program.cs @@ -12,14 +12,14 @@ namespace Microsoft.StandardsPolice public int Main(string[] args) { var tree = CSharpSyntaxTree.ParseText(@" -public class Hello { protected int _foo; int _bar; } -public class World { protected int _foo; int _bar; } +public class Hello { public Hello(int foo){}; protected int _foo; int _bar; } +public class World { public World(int foo){}; protected int _foo; int _bar; static int _quux = 4; enum Blah{} class Clazz{} } "); var diags = new List(); var comp = CSharpCompilation.Create("Comp", new[] { tree }); - StandardsPoliceCompileModule.ScanSyntaxTree(diags, tree); + StandardsPoliceCompileModule.ScanCompilation(diags, comp); var hello = comp.GetTypeByMetadataName("Hello"); foreach (var f in hello.GetMembers().OfType()) diff --git a/tools/Microsoft.StandardsPolice/StandardsPoliceCompileModule.cs b/tools/Microsoft.StandardsPolice/StandardsPoliceCompileModule.cs index 4981e0fc0c..230b1dcc8e 100644 --- a/tools/Microsoft.StandardsPolice/StandardsPoliceCompileModule.cs +++ b/tools/Microsoft.StandardsPolice/StandardsPoliceCompileModule.cs @@ -5,6 +5,7 @@ using System.Linq; using System.Threading.Tasks; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp.Syntax; +using Microsoft.CodeAnalysis.CSharp; namespace Microsoft.StandardsPolice { @@ -14,13 +15,18 @@ namespace Microsoft.StandardsPolice { public void BeforeCompile(BeforeCompileContext context) { - ScanNamespace(context.Diagnostics, context.Compilation.GlobalNamespace); + ScanCompilation(context.Diagnostics, context.Compilation); + } - foreach (var st in context.Compilation.SyntaxTrees) + internal static void ScanCompilation(IList diagnostics, CSharpCompilation compilation) + { + ScanNamespace(diagnostics, compilation.GlobalNamespace); + + foreach (var st in compilation.SyntaxTrees) { if (!st.FilePath.EndsWith(".Generated.cs")) { - ScanSyntaxTree(context.Diagnostics, st); + ScanSyntaxTree(diagnostics, st); } } } @@ -61,6 +67,20 @@ namespace Microsoft.StandardsPolice } private static void ScanType(IList diagnostics, INamedTypeSymbol typeSymbol) + { + if (typeSymbol.Locations.Any(location => location.IsInSource)) + { + RuleFieldPrivateKeyword(diagnostics, typeSymbol); + RuleNestedTypesAreLast(diagnostics, typeSymbol); + } + + foreach (var member in typeSymbol.GetTypeMembers()) + { + ScanType(diagnostics, member); + } + } + + private static void RuleFieldPrivateKeyword(IList diagnostics, INamedTypeSymbol typeSymbol) { foreach (var member in typeSymbol.GetMembers().OfType()) { @@ -97,11 +117,39 @@ namespace Microsoft.StandardsPolice } } } - foreach (var member in typeSymbol.GetTypeMembers()) + } + + private static void RuleNestedTypesAreLast(IList diagnostics, INamedTypeSymbol typeSymbol) + { + var otherThingsWereLower = false; + var members = typeSymbol.GetMembers().Reverse().ToArray(); + foreach (var member in members) { - ScanType(diagnostics, member); + var namedType = member as INamedTypeSymbol; + if (namedType == null || (namedType.TypeKind != TypeKind.Class && namedType.TypeKind != TypeKind.Enum && namedType.TypeKind != TypeKind.Struct)) + { + if (member.IsImplicitlyDeclared == false) + { + otherThingsWereLower = true; + } + continue; + } + if (otherThingsWereLower) + { + if (member.Locations.Count() == 1) + { + diagnostics.Add(Diagnostic.Create( + "SP1003", "StandardsPolice", $"nested types must be last {typeSymbol.Name}:{member.Name}", + DiagnosticSeverity.Warning, + DiagnosticSeverity.Warning, + false, + 3, + location: member.Locations.Single())); + } + } } } + public void AfterCompile(AfterCompileContext context) { } From bf6a163f464242b8952a3373a5826bac6baa54f3 Mon Sep 17 00:00:00 2001 From: Louis DeJardin Date: Wed, 2 Sep 2015 13:34:43 -0700 Subject: [PATCH 0227/1662] Generalizing type member order rule --- .../StandardsPoliceCompileModule.cs | 113 +++++++++++++++--- 1 file changed, 96 insertions(+), 17 deletions(-) diff --git a/tools/Microsoft.StandardsPolice/StandardsPoliceCompileModule.cs b/tools/Microsoft.StandardsPolice/StandardsPoliceCompileModule.cs index 230b1dcc8e..f364aa79c4 100644 --- a/tools/Microsoft.StandardsPolice/StandardsPoliceCompileModule.cs +++ b/tools/Microsoft.StandardsPolice/StandardsPoliceCompileModule.cs @@ -1,16 +1,13 @@ using Microsoft.Dnx.Compilation.CSharp; -using System; using System.Collections.Generic; using System.Linq; -using System.Threading.Tasks; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.CSharp; +using System; namespace Microsoft.StandardsPolice { - // This project can output the Class library as a NuGet Package. - // To enable this option, right-click on the project and select the Properties menu item. In the Build tab select "Produce outputs on build". public class StandardsPoliceCompileModule : ICompileModule { public void BeforeCompile(BeforeCompileContext context) @@ -71,7 +68,7 @@ namespace Microsoft.StandardsPolice if (typeSymbol.Locations.Any(location => location.IsInSource)) { RuleFieldPrivateKeyword(diagnostics, typeSymbol); - RuleNestedTypesAreLast(diagnostics, typeSymbol); + RuleMembersAreInCorrectOrder(diagnostics, typeSymbol, MapClassMembers); } foreach (var member in typeSymbol.GetTypeMembers()) @@ -80,6 +77,7 @@ namespace Microsoft.StandardsPolice } } + private static void RuleFieldPrivateKeyword(IList diagnostics, INamedTypeSymbol typeSymbol) { foreach (var member in typeSymbol.GetMembers().OfType()) @@ -119,27 +117,72 @@ namespace Microsoft.StandardsPolice } } - private static void RuleNestedTypesAreLast(IList diagnostics, INamedTypeSymbol typeSymbol) + enum ClassZone { - var otherThingsWereLower = false; - var members = typeSymbol.GetMembers().Reverse().ToArray(); - foreach (var member in members) + Ignored, + BeforeStart, + Fields, + Constructors, + Properties, + OtherThings, + NestedTypes, + AfterEnd + } + + private static void RuleMembersAreInCorrectOrder(IList diagnostics, INamedTypeSymbol typeSymbol, Func mapZone) + { + var currentZone = ClassZone.BeforeStart; + foreach (var member in typeSymbol.GetMembers()) { - var namedType = member as INamedTypeSymbol; - if (namedType == null || (namedType.TypeKind != TypeKind.Class && namedType.TypeKind != TypeKind.Enum && namedType.TypeKind != TypeKind.Struct)) + var memberZone = mapZone(member); + if (memberZone == ClassZone.Ignored) { - if (member.IsImplicitlyDeclared == false) - { - otherThingsWereLower = true; - } continue; } - if (otherThingsWereLower) + if (currentZone < memberZone) + { + currentZone = memberZone; + } + if (memberZone >= ClassZone.OtherThings) + { + continue; + } + if (memberZone < currentZone) { if (member.Locations.Count() == 1) { diagnostics.Add(Diagnostic.Create( - "SP1003", "StandardsPolice", $"nested types must be last {typeSymbol.Name}:{member.Name}", + "SP1003", "StandardsPolice", $"{memberZone} like {typeSymbol.Name}::{member.Name} shouldn't be after {currentZone}", + DiagnosticSeverity.Warning, + DiagnosticSeverity.Warning, + false, + 3, + location: member.Locations.Single())); + } + } + } + currentZone = ClassZone.AfterEnd; + foreach (var member in typeSymbol.GetMembers()) + { + var memberZone = mapZone(member); + if (memberZone == ClassZone.Ignored) + { + continue; + } + if (currentZone > memberZone) + { + currentZone = memberZone; + } + if (memberZone <= ClassZone.OtherThings) + { + continue; + } + if (memberZone > currentZone) + { + if (member.Locations.Count() == 1) + { + diagnostics.Add(Diagnostic.Create( + "SP1003", "StandardsPolice", $"{memberZone} like {typeSymbol.Name}::{member.Name} shouldn't be before {currentZone}", DiagnosticSeverity.Warning, DiagnosticSeverity.Warning, false, @@ -150,6 +193,42 @@ namespace Microsoft.StandardsPolice } } + private static ClassZone MapClassMembers(ISymbol member) + { + if (member.IsImplicitlyDeclared) + { + return ClassZone.Ignored; + } + if (member.Kind == SymbolKind.Field) + { + return ClassZone.Fields; + } + if (member.Kind == SymbolKind.Method) + { + var method = (IMethodSymbol)member; + if (method.MethodKind == MethodKind.Constructor || + method.MethodKind == MethodKind.StaticConstructor) + { + return ClassZone.Constructors; + } + } + if (member.Kind == SymbolKind.Property) + { + return ClassZone.Properties; + } + if (member.Kind == SymbolKind.NamedType) + { + var namedType = (INamedTypeSymbol)member; + if (namedType.TypeKind == TypeKind.Class || + namedType.TypeKind == TypeKind.Enum || + namedType.TypeKind == TypeKind.Struct) + { + return ClassZone.NestedTypes; + } + } + return ClassZone.OtherThings; + } + public void AfterCompile(AfterCompileContext context) { } From b25d2d97721aca7e6137de3619cdc875e37eac77 Mon Sep 17 00:00:00 2001 From: Louis DeJardin Date: Wed, 2 Sep 2015 20:08:54 -0700 Subject: [PATCH 0228/1662] Continued updates for #184 * Reordering members - Fields - Constructors - Properties - EverythingElse - NestedTypes * Removing commented code --- .../Http/Connection.cs | 32 ++-- .../Http/Frame.cs | 35 +--- .../Http/FrameDuplexStream.cs | 152 +++++++++--------- .../Http/FrameHeaders.cs | 43 +++-- .../Http/FrameRequestStream.cs | 48 +++--- .../Http/FrameResponseStream.cs | 52 ++---- .../Http/Listener.cs | 28 ++-- .../Http/ListenerPrimary.cs | 4 +- .../Http/ListenerSecondary.cs | 4 +- .../Http/MemoryPoolTextWriter.cs | 16 +- .../Http/MessageBody.cs | 4 +- .../Http/SocketOutput.cs | 6 +- .../Infrastructure/Disposable.cs | 2 +- .../Infrastructure/KestrelThread.cs | 47 +++++- .../KestrelServerInformation.cs | 8 +- .../Networking/Libuv.cs | 30 ++-- .../ServerRequest.cs | 34 ++-- .../compiler/preprocess/SPCM.cs | 6 + .../StandardsPoliceCompileModule.cs | 55 ++++--- 19 files changed, 309 insertions(+), 297 deletions(-) create mode 100644 src/Microsoft.AspNet.Server.Kestrel/compiler/preprocess/SPCM.cs diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs index 81a3551b6d..c9bcc64c11 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs @@ -15,16 +15,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Http private static readonly Action _readCallback = ReadCallback; private static readonly Func _allocCallback = AllocCallback; - private static Libuv.uv_buf_t AllocCallback(UvStreamHandle handle, int suggestedSize, object state) - { - return ((Connection)state).OnAlloc(handle, suggestedSize); - } - - private static void ReadCallback(UvStreamHandle handle, int nread, Exception error, object state) - { - ((Connection)state).OnRead(handle, nread, error); - } - private readonly UvStreamHandle _socket; private Frame _frame; private long _connectionId = 0; @@ -48,6 +38,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http _socket.ReadStart(_allocCallback, _readCallback, this); } + private static Libuv.uv_buf_t AllocCallback(UvStreamHandle handle, int suggestedSize, object state) + { + return ((Connection)state).OnAlloc(handle, suggestedSize); + } + private Libuv.uv_buf_t OnAlloc(UvStreamHandle handle, int suggestedSize) { return handle.Libuv.buf_init( @@ -55,6 +50,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http 2048); } + private static void ReadCallback(UvStreamHandle handle, int nread, Exception error, object state) + { + ((Connection)state).OnRead(handle, nread, error); + } + private void OnRead(UvStreamHandle handle, int status, Exception error) { SocketInput.Unpin(status); @@ -117,13 +117,13 @@ namespace Microsoft.AspNet.Server.Kestrel.Http KestrelTrace.Log.ConnectionWriteFin(_connectionId, 0); Thread.Post( - x => + state => { KestrelTrace.Log.ConnectionWriteFin(_connectionId, 1); - var self = (Connection)x; + var self = (Connection)state; var shutdown = new UvShutdownReq(); shutdown.Init(self.Thread.Loop); - shutdown.Shutdown(self._socket, (req, status, state) => + shutdown.Shutdown(self._socket, (req, status, _) => { KestrelTrace.Log.ConnectionWriteFin(_connectionId, 1); req.Dispose(); @@ -140,7 +140,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http KestrelTrace.Log.ConnectionKeepAlive(_connectionId); _frame = new Frame(this); Thread.Post( - x => ((Frame)x).Consume(), + state => ((Frame)state).Consume(), _frame); break; case ProduceEndType.SocketDisconnect: @@ -152,10 +152,10 @@ namespace Microsoft.AspNet.Server.Kestrel.Http KestrelTrace.Log.ConnectionDisconnect(_connectionId); Thread.Post( - x => + state => { KestrelTrace.Log.ConnectionStop(_connectionId); - ((UvHandle)x).Dispose(); + ((UvHandle)state).Dispose(); }, _socket); break; diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs index 83f8bae9a6..323b791eea 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs @@ -17,6 +17,10 @@ namespace Microsoft.AspNet.Server.Kestrel.Http public class Frame : FrameContext, IFrameControl { private static Encoding _ascii = Encoding.ASCII; + private static readonly ArraySegment _endChunkBytes = CreateAsciiByteArraySegment("\r\n"); + private static readonly ArraySegment _endChunkedResponseBytes = CreateAsciiByteArraySegment("0\r\n\r\n"); + private static readonly ArraySegment _continueBytes = CreateAsciiByteArraySegment("HTTP/1.1 100 Continue\r\n\r\n"); + private Mode _mode; private bool _responseStarted; private bool _keepAlive; @@ -24,12 +28,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Http private readonly FrameRequestHeaders _requestHeaders = new FrameRequestHeaders(); private readonly FrameResponseHeaders _responseHeaders = new FrameResponseHeaders(); - /* - //IDictionary _environment; - - CancellationTokenSource _cts = new CancellationTokenSource(); - */ - private List, object>> _onStarting; private List, object>> _onCompleted; private object _onStartingSync = new Object(); @@ -64,18 +62,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Http get { return _responseStarted; } } - - /* - public bool LocalIntakeFin - { - get - { - return _mode == Mode.MessageBody - ? _messageBody.LocalIntakeFin - : _mode == Mode.Terminated; - } - } - */ public void Consume() { var input = SocketInput; @@ -131,7 +117,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Http break; } - //var resumeBody = HandleExpectContinue(callback); _mode = Mode.MessageBody; Execute(); break; @@ -298,9 +283,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Http immediate: false); } - private static readonly ArraySegment _endChunkBytes = CreateAsciiByteArraySegment("\r\n"); - private static readonly ArraySegment _endChunkedResponseBytes = CreateAsciiByteArraySegment("0\r\n\r\n"); - private void WriteChunkSuffix() { SocketOutput.Write(_endChunkBytes, @@ -333,13 +315,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { _keepAlive = false; ProduceStart(); - - // NOTE: needs changes - //_upgradeTask = callback(_callContext); } - private static readonly ArraySegment _continueBytes = CreateAsciiByteArraySegment("HTTP/1.1 100 Continue\r\n\r\n"); - private static ArraySegment CreateAsciiByteArraySegment(string text) { var bytes = Encoding.ASCII.GetBytes(text); @@ -380,13 +357,13 @@ namespace Microsoft.AspNet.Server.Kestrel.Http var responseHeader = CreateResponseHeader(status, appCompleted, ResponseHeaders); SocketOutput.Write( responseHeader.Item1, - (error, x) => + (error, state) => { if (error != null) { Trace.WriteLine("ProduceStart " + error.ToString()); } - ((IDisposable)x).Dispose(); + ((IDisposable)state).Dispose(); }, responseHeader.Item2, immediate: immediate); diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameDuplexStream.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameDuplexStream.cs index 0086cdf0aa..40e860f20e 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameDuplexStream.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameDuplexStream.cs @@ -21,6 +21,82 @@ namespace Microsoft.AspNet.Server.Kestrel.Http _responseStream = responseStream; } + public override bool CanRead + { + get + { + return _requestStream.CanRead; + } + } + + public override bool CanSeek + { + get + { + return _requestStream.CanSeek; + } + } + + public override bool CanTimeout + { + get + { + return _responseStream.CanTimeout || _requestStream.CanTimeout; + } + } + + public override bool CanWrite + { + get + { + return _responseStream.CanWrite; + } + } + + public override long Length + { + get + { + return _requestStream.Length; + } + } + + public override long Position + { + get + { + return _requestStream.Position; + } + set + { + _requestStream.Position = value; + } + } + + public override int ReadTimeout + { + get + { + return _requestStream.ReadTimeout; + } + set + { + _requestStream.ReadTimeout = value; + } + } + + public override int WriteTimeout + { + get + { + return _responseStream.WriteTimeout; + } + set + { + _responseStream.WriteTimeout = value; + } + } + #if DNX451 public override void Close() { @@ -116,81 +192,5 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { _responseStream.WriteByte(value); } - - public override bool CanRead - { - get - { - return _requestStream.CanRead; - } - } - - public override bool CanSeek - { - get - { - return _requestStream.CanSeek; - } - } - - public override bool CanTimeout - { - get - { - return _responseStream.CanTimeout || _requestStream.CanTimeout; - } - } - - public override bool CanWrite - { - get - { - return _responseStream.CanWrite; - } - } - - public override long Length - { - get - { - return _requestStream.Length; - } - } - - public override long Position - { - get - { - return _requestStream.Position; - } - set - { - _requestStream.Position = value; - } - } - - public override int ReadTimeout - { - get - { - return _requestStream.ReadTimeout; - } - set - { - _requestStream.ReadTimeout = value; - } - } - - public override int WriteTimeout - { - get - { - return _responseStream.WriteTimeout; - } - set - { - _responseStream.WriteTimeout = value; - } - } } } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameHeaders.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameHeaders.cs index 55191ec076..526c7326d9 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameHeaders.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameHeaders.cs @@ -15,6 +15,27 @@ namespace Microsoft.AspNet.Server.Kestrel.Http protected Dictionary Unknown => MaybeUnknown ?? (MaybeUnknown = new Dictionary(StringComparer.OrdinalIgnoreCase)); + StringValues IDictionary.this[string key] + { + get + { + return GetValueFast(key); + } + + set + { + SetValueFast(key, value); + } + } + + int ICollection>.Count => GetCountFast(); + + bool ICollection>.IsReadOnly => false; + + ICollection IDictionary.Keys => ((IDictionary)this).Select(pair => pair.Key).ToList(); + + ICollection IDictionary.Values => ((IDictionary)this).Select(pair => pair.Value).ToList(); + protected static StringValues AppendValue(StringValues existing, string append) { return StringValues.Concat(existing, append); @@ -47,28 +68,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Http protected virtual IEnumerator> GetEnumeratorFast() { throw new NotImplementedException(); } - - StringValues IDictionary.this[string key] - { - get - { - return GetValueFast(key); - } - - set - { - SetValueFast(key, value); - } - } - - int ICollection>.Count => GetCountFast(); - - bool ICollection>.IsReadOnly => false; - - ICollection IDictionary.Keys => ((IDictionary)this).Select(x => x.Key).ToList(); - - ICollection IDictionary.Values => ((IDictionary)this).Select(x => x.Value).ToList(); - void ICollection>.Add(KeyValuePair item) { AddValueFast(item.Key, item.Value); diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameRequestStream.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameRequestStream.cs index 2932eab142..c5f178464e 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameRequestStream.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameRequestStream.cs @@ -12,15 +12,27 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { private readonly MessageBody _body; - //int _readLength; - //bool _readFin; - //Exception _readError; - public FrameRequestStream(MessageBody body) { _body = body; } + public override bool CanRead { get { return true; } } + + public override bool CanSeek { get { return false; } } + + public override bool CanWrite { get { return false; } } + + public override long Length + { + get + { + throw new NotImplementedException(); + } + } + + public override long Position { get; set; } + public override void Flush() { throw new NotImplementedException(); @@ -67,20 +79,20 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { var tcs = new TaskCompletionSource(state); var task = _body.ReadAsync(new ArraySegment(buffer, offset, count)); - task.ContinueWith((t, x) => + task.ContinueWith((task2, state2) => { - var tcs2 = (TaskCompletionSource)x; - if (t.IsCanceled) + var tcs2 = (TaskCompletionSource)state2; + if (task2.IsCanceled) { tcs2.SetCanceled(); } - else if (t.IsFaulted) + else if (task2.IsFaulted) { - tcs2.SetException(t.Exception); + tcs2.SetException(task2.Exception); } else { - tcs2.SetResult(t.Result); + tcs2.SetResult(task2.Result); } }, tcs); return tcs.Task; @@ -90,21 +102,5 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { throw new NotImplementedException(); } - - public override bool CanRead { get { return true; } } - - public override bool CanSeek { get { return false; } } - - public override bool CanWrite { get { return false; } } - - public override long Length - { - get - { - throw new NotImplementedException(); - } - } - - public override long Position { get; set; } } } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameResponseStream.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameResponseStream.cs index 3309579449..492313e6bb 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameResponseStream.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameResponseStream.cs @@ -17,9 +17,25 @@ namespace Microsoft.AspNet.Server.Kestrel.Http _context = context; } + public override bool CanRead => false; + + public override bool CanSeek => false; + + public override bool CanWrite => false; + + public override long Length + { + get + { + throw new NotImplementedException(); + } + } + + public override long Position { get; set; } + public override void Flush() { - //_write(default(ArraySegment), null); + FlushAsync(CancellationToken.None).Wait(); } public override Task FlushAsync(CancellationToken cancellationToken) @@ -83,39 +99,5 @@ namespace Microsoft.AspNet.Server.Kestrel.Http tcs); return tcs.Task; } - - public override bool CanRead - { - get - { - return false; - } - } - - public override bool CanSeek - { - get - { - return false; - } - } - - public override bool CanWrite - { - get - { - return true; - } - } - - public override long Length - { - get - { - throw new NotImplementedException(); - } - } - - public override long Position { get; set; } } } \ No newline at end of file diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs index b59e7253c1..33657ea73c 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs @@ -13,25 +13,13 @@ namespace Microsoft.AspNet.Server.Kestrel.Http /// public abstract class Listener : ListenerContext, IDisposable { - protected UvStreamHandle ListenSocket { get; private set; } - - protected static void ConnectionCallback(UvStreamHandle stream, int status, Exception error, object state) - { - if (error != null) - { - Trace.WriteLine("Listener.ConnectionCallback " + error.ToString()); - } - else - { - ((Listener)state).OnConnection(stream, status); - } - } - protected Listener(IMemoryPool memory) { Memory = memory; } + protected UvStreamHandle ListenSocket { get; private set; } + public Task StartAsync( string scheme, string host, @@ -63,6 +51,18 @@ namespace Microsoft.AspNet.Server.Kestrel.Http /// protected abstract UvStreamHandle CreateListenSocket(string host, int port); + protected static void ConnectionCallback(UvStreamHandle stream, int status, Exception error, object state) + { + if (error != null) + { + Trace.WriteLine("Listener.ConnectionCallback " + error.ToString()); + } + else + { + ((Listener)state).OnConnection(stream, status); + } + } + /// /// Handles an incoming connection /// diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerPrimary.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerPrimary.cs index 516c027eac..2e7dbde8ad 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerPrimary.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerPrimary.cs @@ -15,8 +15,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Http /// abstract public class ListenerPrimary : Listener { - UvPipeHandle ListenPipe { get; set; } - private List _dispatchPipes = new List(); private int _dispatchIndex; private ArraySegment> _1234 = new ArraySegment>(new[] { new ArraySegment(new byte[] { 1, 2, 3, 4 }) }); @@ -25,6 +23,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { } + UvPipeHandle ListenPipe { get; set; } + public async Task StartAsync( string pipeName, string scheme, diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerSecondary.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerSecondary.cs index 71919b0035..26105aee87 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerSecondary.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerSecondary.cs @@ -15,13 +15,13 @@ namespace Microsoft.AspNet.Server.Kestrel.Http /// public abstract class ListenerSecondary : ListenerContext, IDisposable { - UvPipeHandle DispatchPipe { get; set; } - protected ListenerSecondary(IMemoryPool memory) { Memory = memory; } + UvPipeHandle DispatchPipe { get; set; } + public Task StartAsync( string pipeName, KestrelThread thread, diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/MemoryPoolTextWriter.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/MemoryPoolTextWriter.cs index 3a7d3ef215..2f549dc157 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/MemoryPoolTextWriter.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/MemoryPoolTextWriter.cs @@ -23,14 +23,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Http private readonly Encoder _encoder; - public ArraySegment Buffer - { - get - { - return new ArraySegment(_dataArray, 0, _dataEnd); - } - } - public MemoryPoolTextWriter(IMemoryPool memory) { _memory = memory; @@ -39,6 +31,14 @@ namespace Microsoft.AspNet.Server.Kestrel.Http _encoder = Encoding.UTF8.GetEncoder(); } + public ArraySegment Buffer + { + get + { + return new ArraySegment(_dataArray, 0, _dataEnd); + } + } + public override Encoding Encoding { get diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/MessageBody.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/MessageBody.cs index bc60f0c39f..c846b9c3ba 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/MessageBody.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/MessageBody.cs @@ -9,12 +9,12 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { public abstract class MessageBody : MessageBodyExchanger { - public bool RequestKeepAlive { get; protected set; } - protected MessageBody(FrameContext context) : base(context) { } + public bool RequestKeepAlive { get; protected set; } + public void Intake(int count) { Transfer(count, false); diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs index c48cb87ed1..dc0cb12061 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs @@ -216,14 +216,14 @@ namespace Microsoft.AspNet.Server.Kestrel.Http private class WriteContext { + public SocketOutput Self; + public Queue> Buffers; + public WriteContext(SocketOutput self) { Self = self; Buffers = new Queue>(); } - - public SocketOutput Self; - public Queue> Buffers; } } } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/Disposable.cs b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/Disposable.cs index 8bb2520792..9ad2e36a1d 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/Disposable.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/Disposable.cs @@ -11,6 +11,7 @@ namespace Microsoft.AspNet.Server.Kestrel public class Disposable : IDisposable { private Action _dispose; + private bool disposedValue = false; // To detect redundant calls public Disposable(Action dispose) { @@ -18,7 +19,6 @@ namespace Microsoft.AspNet.Server.Kestrel } #region IDisposable Support - private bool disposedValue = false; // To detect redundant calls protected virtual void Dispose(bool disposing) { diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs index 2355ae82be..0f051b2e15 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs @@ -16,6 +16,7 @@ namespace Microsoft.AspNet.Server.Kestrel /// public class KestrelThread { + private static Action _objectCallback = (cb, obj) => ((Action)cb).Invoke(obj); private KestrelEngine _engine; private Thread _thread; private UvLoopHandle _loop; @@ -102,7 +103,21 @@ namespace Microsoft.AspNet.Server.Kestrel { lock (_workSync) { - _workAdding.Enqueue(new Work { Callback = callback, State = state }); + _workAdding.Enqueue(new Work { Callback1 = _objectCallback, Callback2 = callback, State = state }); + } + _post.Send(); + } + + public void Post(Action callback, T state) + { + lock (_workSync) + { + _workAdding.Enqueue(new Work + { + Callback1 = (state1, state2) => ((Action)state1).Invoke((T)state2), + Callback2 = callback, + State = state + }); } _post.Send(); } @@ -112,7 +127,30 @@ namespace Microsoft.AspNet.Server.Kestrel var tcs = new TaskCompletionSource(); lock (_workSync) { - _workAdding.Enqueue(new Work { Callback = callback, State = state, Completion = tcs }); + _workAdding.Enqueue(new Work + { + Callback1 = _objectCallback, + Callback2 = callback, + State = state, + Completion = tcs + }); + } + _post.Send(); + return tcs.Task; + } + + public Task PostAsync(Action callback, T state) + { + var tcs = new TaskCompletionSource(); + lock (_workSync) + { + _workAdding.Enqueue(new Work + { + Callback1 = (state1, state2) => ((Action)state1).Invoke((T)state2), + Callback2 = callback, + State = state, + Completion = tcs + }); } _post.Send(); return tcs.Task; @@ -212,7 +250,7 @@ namespace Microsoft.AspNet.Server.Kestrel var work = queue.Dequeue(); try { - work.Callback(work.State); + work.Callback1(work.Callback2, work.State); if (work.Completion != null) { ThreadPool.QueueUserWorkItem( @@ -261,7 +299,8 @@ namespace Microsoft.AspNet.Server.Kestrel private struct Work { - public Action Callback; + public Action Callback1; + public object Callback2; public object State; public TaskCompletionSource Completion; } diff --git a/src/Microsoft.AspNet.Server.Kestrel/KestrelServerInformation.cs b/src/Microsoft.AspNet.Server.Kestrel/KestrelServerInformation.cs index b526b59635..a153525ea1 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/KestrelServerInformation.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/KestrelServerInformation.cs @@ -14,6 +14,10 @@ namespace Microsoft.AspNet.Server.Kestrel Addresses = new List(); } + public IList Addresses { get; private set; } + + public int ThreadCount { get; set; } + public void Initialize(IConfiguration configuration) { var urls = configuration["server.urls"]; @@ -30,9 +34,5 @@ namespace Microsoft.AspNet.Server.Kestrel } } } - - public IList Addresses { get; private set; } - - public int ThreadCount { get; set; } } } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/Libuv.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/Libuv.cs index eec141a421..902cf78dee 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/Libuv.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/Libuv.cs @@ -9,6 +9,13 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking { public class Libuv { + public bool IsWindows; + public bool IsDarwin; + + public Func LoadLibrary; + public Func FreeLibrary; + public Func GetProcAddress; + public Libuv() { IsWindows = PlatformApis.IsWindows(); @@ -18,13 +25,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking } } - public bool IsWindows; - public bool IsDarwin; - - public Func LoadLibrary; - public Func FreeLibrary; - public Func GetProcAddress; - public void Load(string dllToLoad) { PlatformApis.Apply(this); @@ -395,16 +395,19 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking public struct sockaddr { - public sockaddr(long ignored) { x3 = x0 = x1 = x2 = x3 = 0; } - private long x0; private long x1; private long x2; private long x3; + + public sockaddr(long ignored) { x3 = x0 = x1 = x2 = x3 = 0; } } public struct uv_buf_t { + public IntPtr x0; + public IntPtr x1; + public uv_buf_t(IntPtr memory, int len, bool IsWindows) { if (IsWindows) @@ -418,9 +421,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking x1 = (IntPtr)len; } } - - public IntPtr x0; - public IntPtr x1; } public enum HandleType @@ -456,10 +456,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking WORK, GETADDRINFO, GETNAMEINFO, - } - //int handle_size_async; - //int handle_size_tcp; - //int req_size_write; - //int req_size_shutdown; + } } } \ No newline at end of file diff --git a/src/Microsoft.AspNet.Server.Kestrel/ServerRequest.cs b/src/Microsoft.AspNet.Server.Kestrel/ServerRequest.cs index ff4499c472..690539f7c9 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/ServerRequest.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/ServerRequest.cs @@ -26,13 +26,6 @@ namespace Microsoft.AspNet.Server.Kestrel PopulateFeatures(); } - private void PopulateFeatures() - { - _features[typeof(IHttpRequestFeature)] = this; - _features[typeof(IHttpResponseFeature)] = this; - _features[typeof(IHttpUpgradeFeature)] = this; - } - internal IFeatureCollection Features { get { return _features; } @@ -199,16 +192,6 @@ namespace Microsoft.AspNet.Server.Kestrel get { return _frame.HasResponseStarted; } } - void IHttpResponseFeature.OnStarting(Func callback, object state) - { - _frame.OnStarting(callback, state); - } - - void IHttpResponseFeature.OnCompleted(Func callback, object state) - { - _frame.OnCompleted(callback, state); - } - bool IHttpUpgradeFeature.IsUpgradableRequest { get @@ -222,6 +205,23 @@ namespace Microsoft.AspNet.Server.Kestrel } } + private void PopulateFeatures() + { + _features[typeof(IHttpRequestFeature)] = this; + _features[typeof(IHttpResponseFeature)] = this; + _features[typeof(IHttpUpgradeFeature)] = this; + } + + void IHttpResponseFeature.OnStarting(Func callback, object state) + { + _frame.OnStarting(callback, state); + } + + void IHttpResponseFeature.OnCompleted(Func callback, object state) + { + _frame.OnCompleted(callback, state); + } + Task IHttpUpgradeFeature.UpgradeAsync() { _frame.StatusCode = 101; diff --git a/src/Microsoft.AspNet.Server.Kestrel/compiler/preprocess/SPCM.cs b/src/Microsoft.AspNet.Server.Kestrel/compiler/preprocess/SPCM.cs new file mode 100644 index 0000000000..df92e585fc --- /dev/null +++ b/src/Microsoft.AspNet.Server.Kestrel/compiler/preprocess/SPCM.cs @@ -0,0 +1,6 @@ +namespace Microsoft.AspNet.Server.Kestrel +{ + public class StandardsPoliceCompileModule : Microsoft.StandardsPolice.StandardsPoliceCompileModule + { + } +} diff --git a/tools/Microsoft.StandardsPolice/StandardsPoliceCompileModule.cs b/tools/Microsoft.StandardsPolice/StandardsPoliceCompileModule.cs index f364aa79c4..d42bba4663 100644 --- a/tools/Microsoft.StandardsPolice/StandardsPoliceCompileModule.cs +++ b/tools/Microsoft.StandardsPolice/StandardsPoliceCompileModule.cs @@ -117,21 +117,16 @@ namespace Microsoft.StandardsPolice } } - enum ClassZone - { - Ignored, - BeforeStart, - Fields, - Constructors, - Properties, - OtherThings, - NestedTypes, - AfterEnd - } - private static void RuleMembersAreInCorrectOrder(IList diagnostics, INamedTypeSymbol typeSymbol, Func mapZone) { + if (typeSymbol.Locations.Length >= 2 || typeSymbol.Name == "Libuv") + { + // Don't apply to partial classes. All members are enumerated, but are not merged by zone order. + return; + } + var currentZone = ClassZone.BeforeStart; + var currentZoneExample = default(ISymbol); foreach (var member in typeSymbol.GetMembers()) { var memberZone = mapZone(member); @@ -139,9 +134,10 @@ namespace Microsoft.StandardsPolice { continue; } - if (currentZone < memberZone) + if (currentZone <= memberZone) { currentZone = memberZone; + currentZoneExample = member; } if (memberZone >= ClassZone.OtherThings) { @@ -152,26 +148,29 @@ namespace Microsoft.StandardsPolice if (member.Locations.Count() == 1) { diagnostics.Add(Diagnostic.Create( - "SP1003", "StandardsPolice", $"{memberZone} like {typeSymbol.Name}::{member.Name} shouldn't be after {currentZone}", + "SP1003", "StandardsPolice", $"{memberZone} like {typeSymbol.Name}::{member.Name} shouldn't be after {currentZone} like {currentZoneExample.Name}", DiagnosticSeverity.Warning, DiagnosticSeverity.Warning, false, 3, - location: member.Locations.Single())); + location: member.Locations.Single(), + additionalLocations: currentZoneExample.Locations)); } } } currentZone = ClassZone.AfterEnd; - foreach (var member in typeSymbol.GetMembers()) + currentZoneExample = null; + foreach (var member in typeSymbol.GetMembers().Reverse()) { var memberZone = mapZone(member); if (memberZone == ClassZone.Ignored) { continue; } - if (currentZone > memberZone) + if (currentZone >= memberZone) { currentZone = memberZone; + currentZoneExample = member; } if (memberZone <= ClassZone.OtherThings) { @@ -182,12 +181,13 @@ namespace Microsoft.StandardsPolice if (member.Locations.Count() == 1) { diagnostics.Add(Diagnostic.Create( - "SP1003", "StandardsPolice", $"{memberZone} like {typeSymbol.Name}::{member.Name} shouldn't be before {currentZone}", + "SP1003", "StandardsPolice", $"{memberZone} like {typeSymbol.Name}::{member.Name} shouldn't be before {currentZone} like {currentZoneExample.Name}", DiagnosticSeverity.Warning, DiagnosticSeverity.Warning, false, 3, - location: member.Locations.Single())); + location: member.Locations.Single(), + additionalLocations: currentZoneExample.Locations)); } } } @@ -211,6 +211,11 @@ namespace Microsoft.StandardsPolice { return ClassZone.Constructors; } + if (method.MethodKind == MethodKind.PropertyGet || + method.MethodKind == MethodKind.PropertySet) + { + return ClassZone.Properties; + } } if (member.Kind == SymbolKind.Property) { @@ -232,5 +237,17 @@ namespace Microsoft.StandardsPolice public void AfterCompile(AfterCompileContext context) { } + + enum ClassZone + { + Ignored, + BeforeStart, + Fields, + Constructors, + Properties, + OtherThings, + NestedTypes, + AfterEnd + } } } From 3bbb77f9d03dbfadad064be56ddf84379020c7ba Mon Sep 17 00:00:00 2001 From: Louis DeJardin Date: Wed, 2 Sep 2015 20:31:11 -0700 Subject: [PATCH 0229/1662] Alphabetizing using statements --- .../Http/Connection.cs | 2 +- .../StandardsPoliceCompileModule.cs | 35 +++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs index c9bcc64c11..49e777c59c 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs @@ -2,8 +2,8 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using Microsoft.AspNet.Server.Kestrel.Networking; using System.Diagnostics; +using Microsoft.AspNet.Server.Kestrel.Networking; namespace Microsoft.AspNet.Server.Kestrel.Http { diff --git a/tools/Microsoft.StandardsPolice/StandardsPoliceCompileModule.cs b/tools/Microsoft.StandardsPolice/StandardsPoliceCompileModule.cs index d42bba4663..0961eed061 100644 --- a/tools/Microsoft.StandardsPolice/StandardsPoliceCompileModule.cs +++ b/tools/Microsoft.StandardsPolice/StandardsPoliceCompileModule.cs @@ -49,6 +49,41 @@ namespace Microsoft.StandardsPolice location: typeDeclaration.GetLocation())); } } + + var usingDirectives = root.DescendantNodes(descendIntoChildren: node => !(node is TypeDeclarationSyntax)) + .OfType() + .ToArray(); + + var priorUsingDirective = default(UsingDirectiveSyntax); + foreach (var usingDirective in usingDirectives) + { + var acceptableOrder = false; + if (!acceptableOrder && priorUsingDirective == null) + { + acceptableOrder = true; + } + if (!acceptableOrder && string.Compare(priorUsingDirective.Name.ToString(), usingDirective.Name.ToString(), StringComparison.OrdinalIgnoreCase) < 0) + { + acceptableOrder = true; + } + if (!acceptableOrder && + priorUsingDirective.Name.ToString().StartsWith("System.") && + !usingDirective.Name.ToString().StartsWith("System.")) + { + acceptableOrder = true; + } + if (!acceptableOrder) + { + diagnostics.Add(Diagnostic.Create( + "SP1004", "StandardsPolice", "namespaces not alphabetized", + DiagnosticSeverity.Warning, + DiagnosticSeverity.Warning, + false, + 3, + location: usingDirective.GetLocation())); + } + priorUsingDirective = usingDirective; + } } private static void ScanNamespace(IList diagnostics, INamespaceSymbol namespaceSymbol) From 0859d82d6bd246c7f8ea87252387618cc73e1482 Mon Sep 17 00:00:00 2001 From: Louis DeJardin Date: Wed, 2 Sep 2015 20:33:51 -0700 Subject: [PATCH 0230/1662] Adding private keyword to private enums --- src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs | 2 +- tools/Microsoft.StandardsPolice/StandardsPoliceCompileModule.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs index 323b791eea..1b418ee8d8 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs @@ -660,7 +660,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http statusCode != 304; } - enum Mode + private enum Mode { StartLine, MessageHeader, diff --git a/tools/Microsoft.StandardsPolice/StandardsPoliceCompileModule.cs b/tools/Microsoft.StandardsPolice/StandardsPoliceCompileModule.cs index 0961eed061..9be039be75 100644 --- a/tools/Microsoft.StandardsPolice/StandardsPoliceCompileModule.cs +++ b/tools/Microsoft.StandardsPolice/StandardsPoliceCompileModule.cs @@ -273,7 +273,7 @@ namespace Microsoft.StandardsPolice { } - enum ClassZone + private enum ClassZone { Ignored, BeforeStart, From 5c7007a4e98f5d0d207ceee9493c3e1ae9bc5434 Mon Sep 17 00:00:00 2001 From: Louis DeJardin Date: Wed, 2 Sep 2015 20:37:11 -0700 Subject: [PATCH 0231/1662] Fixing member field name --- src/Microsoft.AspNet.Server.Kestrel/Http/ListenerPrimary.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerPrimary.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerPrimary.cs index 2e7dbde8ad..2f71ef4690 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerPrimary.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerPrimary.cs @@ -17,7 +17,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { private List _dispatchPipes = new List(); private int _dispatchIndex; - private ArraySegment> _1234 = new ArraySegment>(new[] { new ArraySegment(new byte[] { 1, 2, 3, 4 }) }); + private ArraySegment> _binaryOneTwoThreeFour = new ArraySegment>(new[] { new ArraySegment(new byte[] { 1, 2, 3, 4 }) }); protected ListenerPrimary(IMemoryPool memory) : base(memory) { @@ -79,7 +79,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http write.Init(Thread.Loop); write.Write2( dispatchPipe, - _1234, + _binaryOneTwoThreeFour, socket, (write2, status, error, state) => { From dffd977c3f3eb1078232bbbac67776c8488029de Mon Sep 17 00:00:00 2001 From: Louis DeJardin Date: Wed, 2 Sep 2015 20:50:21 -0700 Subject: [PATCH 0232/1662] Fixing field names --- .../Networking/Libuv.cs | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/Libuv.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/Libuv.cs index 902cf78dee..aa919e24e0 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/Libuv.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/Libuv.cs @@ -395,30 +395,30 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking public struct sockaddr { - private long x0; - private long x1; - private long x2; - private long x3; + private long _field0; + private long _field1; + private long _field2; + private long _field3; - public sockaddr(long ignored) { x3 = x0 = x1 = x2 = x3 = 0; } + public sockaddr(long ignored) { _field3 = _field0 = _field1 = _field2 = _field3 = 0; } } public struct uv_buf_t { - public IntPtr x0; - public IntPtr x1; + public IntPtr _field0; + public IntPtr _field1; public uv_buf_t(IntPtr memory, int len, bool IsWindows) { if (IsWindows) { - x0 = (IntPtr)len; - x1 = memory; + _field0 = (IntPtr)len; + _field1 = memory; } else { - x0 = memory; - x1 = (IntPtr)len; + _field0 = memory; + _field1 = (IntPtr)len; } } } From c50aec17292b9f6d444da5f11637fd3c9146146d Mon Sep 17 00:00:00 2001 From: Louis DeJardin Date: Wed, 2 Sep 2015 21:14:18 -0700 Subject: [PATCH 0233/1662] Adding comments to meaningless field names --- .../Http/ListenerPrimary.cs | 7 ++++-- .../Infrastructure/KestrelThread.cs | 22 +++++++++---------- .../Networking/Libuv.cs | 17 ++++++++++++-- 3 files changed, 31 insertions(+), 15 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerPrimary.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerPrimary.cs index 2f71ef4690..386489e88e 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerPrimary.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerPrimary.cs @@ -17,7 +17,10 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { private List _dispatchPipes = new List(); private int _dispatchIndex; - private ArraySegment> _binaryOneTwoThreeFour = new ArraySegment>(new[] { new ArraySegment(new byte[] { 1, 2, 3, 4 }) }); + + // this message is passed to write2 because it must be non-zero-length, + // but it has no other functional significance + private readonly ArraySegment> _dummyMessage = new ArraySegment>(new[] { new ArraySegment(new byte[] { 1, 2, 3, 4 }) }); protected ListenerPrimary(IMemoryPool memory) : base(memory) { @@ -79,7 +82,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http write.Init(Thread.Loop); write.Write2( dispatchPipe, - _binaryOneTwoThreeFour, + _dummyMessage, socket, (write2, status, error, state) => { diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs index 0f051b2e15..5a0338d899 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs @@ -16,7 +16,7 @@ namespace Microsoft.AspNet.Server.Kestrel /// public class KestrelThread { - private static Action _objectCallback = (cb, obj) => ((Action)cb).Invoke(obj); + private static Action _objectCallbackAdapter = (callback, state) => ((Action)callback).Invoke(state); private KestrelEngine _engine; private Thread _thread; private UvLoopHandle _loop; @@ -103,7 +103,7 @@ namespace Microsoft.AspNet.Server.Kestrel { lock (_workSync) { - _workAdding.Enqueue(new Work { Callback1 = _objectCallback, Callback2 = callback, State = state }); + _workAdding.Enqueue(new Work { CallbackAdapter = _objectCallbackAdapter, Callback = callback, State = state }); } _post.Send(); } @@ -114,8 +114,8 @@ namespace Microsoft.AspNet.Server.Kestrel { _workAdding.Enqueue(new Work { - Callback1 = (state1, state2) => ((Action)state1).Invoke((T)state2), - Callback2 = callback, + CallbackAdapter = (callback2, state2) => ((Action)callback2).Invoke((T)state2), + Callback = callback, State = state }); } @@ -129,8 +129,8 @@ namespace Microsoft.AspNet.Server.Kestrel { _workAdding.Enqueue(new Work { - Callback1 = _objectCallback, - Callback2 = callback, + CallbackAdapter = _objectCallbackAdapter, + Callback = callback, State = state, Completion = tcs }); @@ -146,8 +146,8 @@ namespace Microsoft.AspNet.Server.Kestrel { _workAdding.Enqueue(new Work { - Callback1 = (state1, state2) => ((Action)state1).Invoke((T)state2), - Callback2 = callback, + CallbackAdapter = (state1, state2) => ((Action)state1).Invoke((T)state2), + Callback = callback, State = state, Completion = tcs }); @@ -250,7 +250,7 @@ namespace Microsoft.AspNet.Server.Kestrel var work = queue.Dequeue(); try { - work.Callback1(work.Callback2, work.State); + work.CallbackAdapter(work.Callback, work.State); if (work.Completion != null) { ThreadPool.QueueUserWorkItem( @@ -299,8 +299,8 @@ namespace Microsoft.AspNet.Server.Kestrel private struct Work { - public Action Callback1; - public object Callback2; + public Action CallbackAdapter; + public object Callback; public object State; public TaskCompletionSource Completion; } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/Libuv.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/Libuv.cs index aa919e24e0..a266ff8cc8 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/Libuv.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/Libuv.cs @@ -395,6 +395,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking public struct sockaddr { + // this type represents native memory occupied by sockaddr struct + // https://msdn.microsoft.com/en-us/library/windows/desktop/ms740496(v=vs.85).aspx + // although the c/c++ header defines it as a 2-byte short followed by a 14-byte array, + // the simplest way to reserve the same size in c# is with four nameless long values + private long _field0; private long _field1; private long _field2; @@ -405,8 +410,16 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking public struct uv_buf_t { - public IntPtr _field0; - public IntPtr _field1; + // this type represents a WSABUF struct on Windows + // https://msdn.microsoft.com/en-us/library/windows/desktop/ms741542(v=vs.85).aspx + // and an iovec struct on *nix + // http://man7.org/linux/man-pages/man2/readv.2.html + // because the order of the fields in these structs is different, the field + // names in this type don't have meaningful symbolic names. instead, they are + // assigned in the correct order by the constructor at runtime + + private readonly IntPtr _field0; + private readonly IntPtr _field1; public uv_buf_t(IntPtr memory, int len, bool IsWindows) { From 1584d70e1f72c9c143495f95444681c8ce58a589 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Tue, 25 Aug 2015 12:41:11 -0700 Subject: [PATCH 0234/1662] Clean up if an exception is thrown in the middle of ServerFactory.Start --- .../ServerFactory.cs | 50 ++++++++++++------- 1 file changed, 32 insertions(+), 18 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/ServerFactory.cs b/src/Microsoft.AspNet.Server.Kestrel/ServerFactory.cs index 13b2aaac33..10b49da527 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/ServerFactory.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/ServerFactory.cs @@ -36,30 +36,44 @@ namespace Microsoft.AspNet.Server.Kestrel public IDisposable Start(IFeatureCollection serverFeatures, Func application) { - var disposables = new List(); - var information = (KestrelServerInformation)serverFeatures.Get(); - var engine = new KestrelEngine(_libraryManager, _appShutdownService); - engine.Start(information.ThreadCount == 0 ? 1 : information.ThreadCount); - foreach (var address in information.Addresses) - { - disposables.Add(engine.CreateServer( - address.Scheme, - address.Host, - address.Port, - async frame => - { - var request = new ServerRequest(frame); - await application.Invoke(request.Features).ConfigureAwait(false); - })); - } - disposables.Add(engine); - return new Disposable(() => + var disposables = new Stack(); + var disposer = new Disposable(() => { foreach (var disposable in disposables) { disposable.Dispose(); } }); + + try + { + var information = (KestrelServerInformation)serverFeatures.Get(); + var engine = new KestrelEngine(_libraryManager, _appShutdownService); + + disposables.Push(engine); + + engine.Start(information.ThreadCount == 0 ? 1 : information.ThreadCount); + + foreach (var address in information.Addresses) + { + disposables.Push(engine.CreateServer( + address.Scheme, + address.Host, + address.Port, + async frame => + { + var request = new ServerRequest(frame); + await application.Invoke(request.Features).ConfigureAwait(false); + })); + } + + return disposer; + } + catch + { + disposer.Dispose(); + throw; + } } } } From f10c989d9034e8cc830db7a4a18008be3b3f84ab Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Thu, 3 Sep 2015 12:42:28 -0700 Subject: [PATCH 0235/1662] Add ServiceContext to make it easier to flow new services through ctors --- .../Http/Listener.cs | 3 +-- .../Http/ListenerContext.cs | 13 +++++++--- .../Http/ListenerPrimary.cs | 2 +- .../Http/ListenerSecondary.cs | 3 +-- .../Http/PipeListener.cs | 2 +- .../Http/PipeListenerPrimary.cs | 2 +- .../Http/PipeListenerSecondary.cs | 2 +- .../Http/TcpListener.cs | 2 +- .../Http/TcpListenerPrimary.cs | 2 +- .../Http/TcpListenerSecondary.cs | 2 +- .../Infrastructure/KestrelThread.cs | 7 +++-- .../KestrelEngine.cs | 26 +++++++++++-------- .../ServiceContext.cs | 15 +++++++++++ 13 files changed, 53 insertions(+), 28 deletions(-) create mode 100644 src/Microsoft.AspNet.Server.Kestrel/ServiceContext.cs diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs index 33657ea73c..8485869296 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs @@ -13,9 +13,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http /// public abstract class Listener : ListenerContext, IDisposable { - protected Listener(IMemoryPool memory) + protected Listener(ServiceContext serviceContext) : base(serviceContext) { - Memory = memory; } protected UvStreamHandle ListenSocket { get; private set; } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerContext.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerContext.cs index 4285f59311..1d8cd86059 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerContext.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerContext.cs @@ -10,11 +10,16 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { public ListenerContext() { } - public ListenerContext(ListenerContext context) + public ListenerContext(ServiceContext serviceContext) { - Thread = context.Thread; - Application = context.Application; - Memory = context.Memory; + Memory = serviceContext.Memory; + } + + public ListenerContext(ListenerContext listenerContext) + { + Thread = listenerContext.Thread; + Application = listenerContext.Application; + Memory = listenerContext.Memory; } public KestrelThread Thread { get; set; } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerPrimary.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerPrimary.cs index 386489e88e..67204fc729 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerPrimary.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerPrimary.cs @@ -22,7 +22,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http // but it has no other functional significance private readonly ArraySegment> _dummyMessage = new ArraySegment>(new[] { new ArraySegment(new byte[] { 1, 2, 3, 4 }) }); - protected ListenerPrimary(IMemoryPool memory) : base(memory) + protected ListenerPrimary(ServiceContext serviceContext) : base(serviceContext) { } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerSecondary.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerSecondary.cs index 26105aee87..f0948b867b 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerSecondary.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerSecondary.cs @@ -15,9 +15,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http /// public abstract class ListenerSecondary : ListenerContext, IDisposable { - protected ListenerSecondary(IMemoryPool memory) + protected ListenerSecondary(ServiceContext serviceContext) : base(serviceContext) { - Memory = memory; } UvPipeHandle DispatchPipe { get; set; } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/PipeListener.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/PipeListener.cs index 15b43c78b6..2fd4dd3c32 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/PipeListener.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/PipeListener.cs @@ -11,7 +11,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http /// public class PipeListener : Listener { - public PipeListener(IMemoryPool memory) : base(memory) + public PipeListener(ServiceContext serviceContext) : base(serviceContext) { } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/PipeListenerPrimary.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/PipeListenerPrimary.cs index 3ee7f501bc..afb4c7c213 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/PipeListenerPrimary.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/PipeListenerPrimary.cs @@ -11,7 +11,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http /// public class PipeListenerPrimary : ListenerPrimary { - public PipeListenerPrimary(IMemoryPool memory) : base(memory) + public PipeListenerPrimary(ServiceContext serviceContext) : base(serviceContext) { } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/PipeListenerSecondary.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/PipeListenerSecondary.cs index 81d70485bf..40b34038d9 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/PipeListenerSecondary.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/PipeListenerSecondary.cs @@ -10,7 +10,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http /// public class PipeListenerSecondary : ListenerSecondary { - public PipeListenerSecondary(IMemoryPool memory) : base(memory) + public PipeListenerSecondary(ServiceContext serviceContext) : base(serviceContext) { } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/TcpListener.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/TcpListener.cs index 54739b725d..7c67208e3f 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/TcpListener.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/TcpListener.cs @@ -12,7 +12,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http /// public class TcpListener : Listener { - public TcpListener(IMemoryPool memory) : base(memory) + public TcpListener(ServiceContext serviceContext) : base(serviceContext) { } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/TcpListenerPrimary.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/TcpListenerPrimary.cs index 8a9546fdd8..098238bde1 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/TcpListenerPrimary.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/TcpListenerPrimary.cs @@ -12,7 +12,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http /// public class TcpListenerPrimary : ListenerPrimary { - public TcpListenerPrimary(IMemoryPool memory) : base(memory) + public TcpListenerPrimary(ServiceContext serviceContext) : base(serviceContext) { } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/TcpListenerSecondary.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/TcpListenerSecondary.cs index 5e125c0276..4cff07cedf 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/TcpListenerSecondary.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/TcpListenerSecondary.cs @@ -10,7 +10,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http /// public class TcpListenerSecondary : ListenerSecondary { - public TcpListenerSecondary(IMemoryPool memory) : base(memory) + public TcpListenerSecondary(ServiceContext serviceContext) : base(serviceContext) { } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs index 5a0338d899..f611d8857a 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs @@ -8,6 +8,7 @@ using System.Diagnostics; using System.Runtime.ExceptionServices; using System.Threading; using System.Threading.Tasks; +using Microsoft.Dnx.Runtime; namespace Microsoft.AspNet.Server.Kestrel { @@ -18,6 +19,7 @@ namespace Microsoft.AspNet.Server.Kestrel { private static Action _objectCallbackAdapter = (callback, state) => ((Action)callback).Invoke(state); private KestrelEngine _engine; + private readonly IApplicationShutdown _appShutdown; private Thread _thread; private UvLoopHandle _loop; private UvAsyncHandle _post; @@ -29,9 +31,10 @@ namespace Microsoft.AspNet.Server.Kestrel private bool _stopImmediate = false; private ExceptionDispatchInfo _closeError; - public KestrelThread(KestrelEngine engine) + public KestrelThread(KestrelEngine engine, ServiceContext serviceContext) { _engine = engine; + _appShutdown = serviceContext.AppShutdown; _loop = new UvLoopHandle(); _post = new UvAsyncHandle(); _thread = new Thread(ThreadStart); @@ -226,7 +229,7 @@ namespace Microsoft.AspNet.Server.Kestrel _closeError = ExceptionDispatchInfo.Capture(ex); // Request shutdown so we can rethrow this exception // in Stop which should be observable. - _engine.AppShutdown.RequestShutdown(); + _appShutdown.RequestShutdown(); } } diff --git a/src/Microsoft.AspNet.Server.Kestrel/KestrelEngine.cs b/src/Microsoft.AspNet.Server.Kestrel/KestrelEngine.cs index 161ba83d07..57fc44876a 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/KestrelEngine.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/KestrelEngine.cs @@ -14,6 +14,8 @@ namespace Microsoft.AspNet.Server.Kestrel { public class KestrelEngine : IDisposable { + private readonly ServiceContext _serviceContext; + public KestrelEngine(ILibraryManager libraryManager, IApplicationShutdown appShutdownService) : this(appShutdownService) { @@ -68,21 +70,23 @@ namespace Microsoft.AspNet.Server.Kestrel private KestrelEngine(IApplicationShutdown appShutdownService) { - AppShutdown = appShutdownService; + _serviceContext = new ServiceContext + { + AppShutdown = appShutdownService, + Memory = new MemoryPool() + }; + Threads = new List(); - Memory = new MemoryPool(); } public Libuv Libuv { get; private set; } - public IMemoryPool Memory { get; set; } - public IApplicationShutdown AppShutdown { get; private set; } public List Threads { get; private set; } public void Start(int count) { for (var index = 0; index != count; ++index) { - Threads.Add(new KestrelThread(this)); + Threads.Add(new KestrelThread(this, _serviceContext)); } foreach (var thread in Threads) @@ -122,16 +126,16 @@ namespace Microsoft.AspNet.Server.Kestrel if (single) { var listener = usingPipes ? - (Listener) new PipeListener(Memory) : - new TcpListener(Memory); + (Listener) new PipeListener(_serviceContext) : + new TcpListener(_serviceContext); listeners.Add(listener); listener.StartAsync(scheme, host, port, thread, application).Wait(); } else if (first) { var listener = usingPipes - ? (ListenerPrimary) new PipeListenerPrimary(Memory) - : new TcpListenerPrimary(Memory); + ? (ListenerPrimary) new PipeListenerPrimary(_serviceContext) + : new TcpListenerPrimary(_serviceContext); listeners.Add(listener); listener.StartAsync(pipeName, scheme, host, port, thread, application).Wait(); @@ -139,8 +143,8 @@ namespace Microsoft.AspNet.Server.Kestrel else { var listener = usingPipes - ? (ListenerSecondary) new PipeListenerSecondary(Memory) - : new TcpListenerSecondary(Memory); + ? (ListenerSecondary) new PipeListenerSecondary(_serviceContext) + : new TcpListenerSecondary(_serviceContext); listeners.Add(listener); listener.StartAsync(pipeName, thread, application).Wait(); } diff --git a/src/Microsoft.AspNet.Server.Kestrel/ServiceContext.cs b/src/Microsoft.AspNet.Server.Kestrel/ServiceContext.cs new file mode 100644 index 0000000000..bd09076565 --- /dev/null +++ b/src/Microsoft.AspNet.Server.Kestrel/ServiceContext.cs @@ -0,0 +1,15 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using Microsoft.AspNet.Server.Kestrel.Http; +using Microsoft.Dnx.Runtime; + +namespace Microsoft.AspNet.Server.Kestrel +{ + public class ServiceContext + { + public IApplicationShutdown AppShutdown { get; set; } + + public IMemoryPool Memory { get; set; } + } +} From 5ee80e0155b028e7f58c181ea90ac5fac833c939 Mon Sep 17 00:00:00 2001 From: Kai Ruhnau Date: Sat, 5 Sep 2015 12:29:00 +0200 Subject: [PATCH 0236/1662] Fix bug #191 introduced by b25d2d9 --- .../Http/FrameResponseStream.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameResponseStream.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameResponseStream.cs index 492313e6bb..cfb6453129 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameResponseStream.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameResponseStream.cs @@ -21,7 +21,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http public override bool CanSeek => false; - public override bool CanWrite => false; + public override bool CanWrite => true; public override long Length { @@ -100,4 +100,4 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return tcs.Task; } } -} \ No newline at end of file +} From 6d47227975ebe317972ada79769cd6abad35bae8 Mon Sep 17 00:00:00 2001 From: Ivan Derevyanko Date: Sat, 5 Sep 2015 18:17:17 +0200 Subject: [PATCH 0237/1662] KestrelTrace refactored and added to the ServiceContext. Close aspnet/KestrelHttpServer#141 --- samples/SampleApp/Startup.cs | 5 +- samples/SampleApp/project.json | 4 +- .../Http/Connection.cs | 24 +++--- .../Http/ListenerContext.cs | 5 ++ .../Http/SocketOutput.cs | 9 +- .../Infrastructure/IKestrelTrace.cs | 29 +++++++ .../Infrastructure/KestrelTrace.cs | 83 ++++++++++--------- .../KestrelEngine.cs | 14 ++-- .../ServerFactory.cs | 7 +- .../ServiceContext.cs | 3 + .../project.json | 3 +- .../EngineTests.cs | 6 +- .../MultipleLoopTests.cs | 2 +- .../NetworkingTests.cs | 2 +- .../SocketOutputTests.cs | 10 ++- .../TestLogger.cs | 23 +++++ .../TestServer.cs | 2 +- 17 files changed, 157 insertions(+), 74 deletions(-) create mode 100644 src/Microsoft.AspNet.Server.Kestrel/Infrastructure/IKestrelTrace.cs create mode 100644 test/Microsoft.AspNet.Server.KestrelTests/TestLogger.cs diff --git a/samples/SampleApp/Startup.cs b/samples/SampleApp/Startup.cs index edc92abac0..f076b27a19 100644 --- a/samples/SampleApp/Startup.cs +++ b/samples/SampleApp/Startup.cs @@ -4,13 +4,16 @@ using System; using Microsoft.AspNet.Builder; using Microsoft.AspNet.Http; +using Microsoft.Framework.Logging; namespace SampleApp { public class Startup { - public void Configure(IApplicationBuilder app) + public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory) { + loggerFactory.MinimumLevel = LogLevel.Debug; + loggerFactory.AddConsole(LogLevel.Debug); app.Run(context => { Console.WriteLine("{0} {1}{2}{3}", diff --git a/samples/SampleApp/project.json b/samples/SampleApp/project.json index 899732b65b..fbfc10abf9 100644 --- a/samples/SampleApp/project.json +++ b/samples/SampleApp/project.json @@ -1,7 +1,9 @@ { "version": "1.0.0-*", "dependencies": { - "Microsoft.AspNet.Server.Kestrel": "1.0.0-*" + "Microsoft.AspNet.Server.Kestrel": "1.0.0-*", + "Microsoft.Framework.Logging.Abstractions": "1.0.0-*", + "Microsoft.Framework.Logging.Console": "1.0.0-*" }, "frameworks": { "dnx451": { }, diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs index 49e777c59c..055acd8b2e 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs @@ -30,10 +30,10 @@ namespace Microsoft.AspNet.Server.Kestrel.Http public void Start() { - KestrelTrace.Log.ConnectionStart(_connectionId); + Log.ConnectionStart(_connectionId); SocketInput = new SocketInput(Memory); - SocketOutput = new SocketOutput(Thread, _socket); + SocketOutput = new SocketOutput(Thread, _socket, Log); _frame = new Frame(this); _socket.ReadStart(_allocCallback, _readCallback, this); } @@ -65,11 +65,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http if (normalRead) { - KestrelTrace.Log.ConnectionRead(_connectionId, status); + Log.ConnectionRead(_connectionId, status); } else if (normalDone || errorDone) { - KestrelTrace.Log.ConnectionReadFin(_connectionId); + Log.ConnectionReadFin(_connectionId); SocketInput.RemoteIntakeFin = true; _socket.ReadStop(); @@ -92,13 +92,13 @@ namespace Microsoft.AspNet.Server.Kestrel.Http void IConnectionControl.Pause() { - KestrelTrace.Log.ConnectionPause(_connectionId); + Log.ConnectionPause(_connectionId); _socket.ReadStop(); } void IConnectionControl.Resume() { - KestrelTrace.Log.ConnectionResume(_connectionId); + Log.ConnectionResume(_connectionId); _socket.ReadStart(_allocCallback, _readCallback, this); } @@ -115,17 +115,17 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } _connectionState = ConnectionState.Shutdown; - KestrelTrace.Log.ConnectionWriteFin(_connectionId, 0); + Log.ConnectionWriteFin(_connectionId, 0); Thread.Post( state => { - KestrelTrace.Log.ConnectionWriteFin(_connectionId, 1); + Log.ConnectionWriteFin(_connectionId, 1); var self = (Connection)state; var shutdown = new UvShutdownReq(); shutdown.Init(self.Thread.Loop); shutdown.Shutdown(self._socket, (req, status, _) => { - KestrelTrace.Log.ConnectionWriteFin(_connectionId, 1); + Log.ConnectionWriteFin(_connectionId, 1); req.Dispose(); }, null); }, @@ -137,7 +137,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return; } - KestrelTrace.Log.ConnectionKeepAlive(_connectionId); + Log.ConnectionKeepAlive(_connectionId); _frame = new Frame(this); Thread.Post( state => ((Frame)state).Consume(), @@ -150,11 +150,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } _connectionState = ConnectionState.Disconnected; - KestrelTrace.Log.ConnectionDisconnect(_connectionId); + Log.ConnectionDisconnect(_connectionId); Thread.Post( state => { - KestrelTrace.Log.ConnectionStop(_connectionId); + Log.ConnectionStop(_connectionId); ((UvHandle)state).Dispose(); }, _socket); diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerContext.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerContext.cs index 1d8cd86059..c0f042b4cc 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerContext.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerContext.cs @@ -3,6 +3,7 @@ using System; using System.Threading.Tasks; +using Microsoft.AspNet.Server.Kestrel.Infrastructure; namespace Microsoft.AspNet.Server.Kestrel.Http { @@ -13,6 +14,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http public ListenerContext(ServiceContext serviceContext) { Memory = serviceContext.Memory; + Log = serviceContext.Log; } public ListenerContext(ListenerContext listenerContext) @@ -20,6 +22,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http Thread = listenerContext.Thread; Application = listenerContext.Application; Memory = listenerContext.Memory; + Log = listenerContext.Log; } public KestrelThread Thread { get; set; } @@ -27,5 +30,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http public Func Application { get; set; } public IMemoryPool Memory { get; set; } + + public IKestrelTrace Log { get; } } } \ No newline at end of file diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs index dc0cb12061..676c0b1461 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs @@ -5,6 +5,7 @@ using System; using System.Collections.Generic; using System.Diagnostics; using System.Threading; +using Microsoft.AspNet.Server.Kestrel.Infrastructure; using Microsoft.AspNet.Server.Kestrel.Networking; namespace Microsoft.AspNet.Server.Kestrel.Http @@ -16,6 +17,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http private readonly KestrelThread _thread; private readonly UvStreamHandle _socket; + private readonly IKestrelTrace _log; // This locks access to to all of the below fields private readonly object _lockObj = new object(); @@ -29,10 +31,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http private WriteContext _nextWriteContext; private readonly Queue _callbacksPending; - public SocketOutput(KestrelThread thread, UvStreamHandle socket) + public SocketOutput(KestrelThread thread, UvStreamHandle socket, IKestrelTrace log) { _thread = thread; _socket = socket; + _log = log; _callbacksPending = new Queue(); } @@ -43,7 +46,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http Array.Copy(buffer.Array, buffer.Offset, copy, 0, buffer.Count); buffer = new ArraySegment(copy); - KestrelTrace.Log.ConnectionWrite(0, buffer.Count); + _log.ConnectionWrite(0, buffer.Count); bool triggerCallbackNow = false; @@ -152,7 +155,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http // This is called on the libuv event loop private void OnWriteCompleted(Queue> writtenBuffers, UvWriteReq req, int status, Exception error) { - KestrelTrace.Log.ConnectionWriteCallback(0, status); + _log.ConnectionWriteCallback(0, status); lock (_lockObj) { diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/IKestrelTrace.cs b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/IKestrelTrace.cs new file mode 100644 index 0000000000..478b573fe8 --- /dev/null +++ b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/IKestrelTrace.cs @@ -0,0 +1,29 @@ +using Microsoft.Framework.Logging; + +namespace Microsoft.AspNet.Server.Kestrel.Infrastructure +{ + public interface IKestrelTrace : ILogger + { + void ConnectionStart(long connectionId); + + void ConnectionStop(long connectionId); + + void ConnectionRead(long connectionId, int status); + + void ConnectionPause(long connectionId); + + void ConnectionResume(long connectionId); + + void ConnectionReadFin(long connectionId); + + void ConnectionWriteFin(long connectionId, int step); + + void ConnectionKeepAlive(long connectionId); + + void ConnectionDisconnect(long connectionId); + + void ConnectionWrite(long connectionId, int count); + + void ConnectionWriteCallback(long connectionId, int status); + } +} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelTrace.cs b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelTrace.cs index 53a1cb73e3..c9ce6bb820 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelTrace.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelTrace.cs @@ -1,85 +1,92 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -//using System.Diagnostics.Tracing; +using System; +using Microsoft.AspNet.Server.Kestrel.Infrastructure; +using Microsoft.Framework.Logging; namespace Microsoft.AspNet.Server.Kestrel { /// /// Summary description for KestrelTrace /// - public class KestrelTrace //: EventSource + public class KestrelTrace : IKestrelTrace { - public static KestrelTrace Log = new KestrelTrace(); - // static EventTask Connection = (EventTask)1; - // static EventTask Frame = (EventTask)1; + private readonly ILogger _logger; + public KestrelTrace(ILogger logger) + { + _logger = logger; + } - // [Event(13, Level = EventLevel.Informational, Message = "Id {0}")] public void ConnectionStart(long connectionId) { - // WriteEvent(13, connectionId); + _logger.LogDebug(13, $"{nameof(ConnectionStart)} -> Id: {connectionId}"); } - // [Event(14, Level = EventLevel.Informational, Message = "Id {0}")] public void ConnectionStop(long connectionId) { - // WriteEvent(14, connectionId); + _logger.LogDebug(14, $"{nameof(ConnectionStop)} -> Id: {connectionId}"); } - - // [Event(4, Message = "Id {0} Status {1}")] - internal void ConnectionRead(long connectionId, int status) + public void ConnectionRead(long connectionId, int status) { - // WriteEvent(4, connectionId, status); + _logger.LogDebug(4, $"{nameof(ConnectionRead)} -> Id: {connectionId}, Status: {status}"); } - // [Event(5, Message = "Id {0}")] - internal void ConnectionPause(long connectionId) + public void ConnectionPause(long connectionId) { - // WriteEvent(5, connectionId); + _logger.LogDebug(5, $"{nameof(ConnectionPause)} -> Id: {connectionId}"); } - // [Event(6, Message = "Id {0}")] - internal void ConnectionResume(long connectionId) + public void ConnectionResume(long connectionId) { - // WriteEvent(6, connectionId); + _logger.LogDebug(6, $"{nameof(ConnectionResume)} -> Id: {connectionId}"); } - // [Event(7, Message = "Id {0}")] - internal void ConnectionReadFin(long connectionId) + public void ConnectionReadFin(long connectionId) { - // WriteEvent(7, connectionId); + _logger.LogDebug(7, $"{nameof(ConnectionReadFin)} -> Id: {connectionId}"); } -// [Event(8, Message = "Id {0} Step {1}")] - internal void ConnectionWriteFin(long connectionId, int step) + public void ConnectionWriteFin(long connectionId, int step) { - // WriteEvent(8, connectionId, step); + _logger.LogDebug(8, $"{nameof(ConnectionWriteFin)} -> Id: {connectionId}, Step: {step}"); } - // [Event(9, Message = "Id {0}")] - internal void ConnectionKeepAlive(long connectionId) + public void ConnectionKeepAlive(long connectionId) { - // WriteEvent(9, connectionId); + _logger.LogDebug(9, $"{nameof(ConnectionKeepAlive)} -> Id: {connectionId}"); } - // [Event(10, Message = "Id {0}")] - internal void ConnectionDisconnect(long connectionId) + public void ConnectionDisconnect(long connectionId) { - // WriteEvent(10, connectionId); + _logger.LogDebug(10, $"{nameof(ConnectionDisconnect)} -> Id: {connectionId}"); } - // [Event(11, Message = "Id {0} Count {1}")] - internal void ConnectionWrite(long connectionId, int count) + public void ConnectionWrite(long connectionId, int count) { - // WriteEvent(11, connectionId, count); + _logger.LogDebug(11, $"{nameof(ConnectionWrite)} -> Id: {connectionId}, Count: {count}"); } - // [Event(12, Message = "Id {0} Status {1}")] - internal void ConnectionWriteCallback(long connectionId, int status) + public void ConnectionWriteCallback(long connectionId, int status) { - // WriteEvent(12, connectionId, status); + _logger.LogDebug(12, $"{nameof(ConnectionWriteCallback)} -> Id: {connectionId}, Status: {status}"); + } + + public void Log(LogLevel logLevel, int eventId, object state, Exception exception, Func formatter) + { + _logger.Log(logLevel, eventId, state, exception, formatter); + } + + public bool IsEnabled(LogLevel logLevel) + { + return _logger.IsEnabled(logLevel); + } + + public IDisposable BeginScopeImpl(object state) + { + return _logger.BeginScopeImpl(state); } } -} +} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Server.Kestrel/KestrelEngine.cs b/src/Microsoft.AspNet.Server.Kestrel/KestrelEngine.cs index 57fc44876a..893bdf94b2 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/KestrelEngine.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/KestrelEngine.cs @@ -9,6 +9,7 @@ using Microsoft.AspNet.Server.Kestrel.Http; using Microsoft.AspNet.Server.Kestrel.Infrastructure; using Microsoft.AspNet.Server.Kestrel.Networking; using Microsoft.Dnx.Runtime; +using Microsoft.Framework.Logging; namespace Microsoft.AspNet.Server.Kestrel { @@ -16,8 +17,8 @@ namespace Microsoft.AspNet.Server.Kestrel { private readonly ServiceContext _serviceContext; - public KestrelEngine(ILibraryManager libraryManager, IApplicationShutdown appShutdownService) - : this(appShutdownService) + public KestrelEngine(ILibraryManager libraryManager, IApplicationShutdown appShutdownService, ILogger logger) + : this(appShutdownService, logger) { Libuv = new Libuv(); @@ -62,18 +63,19 @@ namespace Microsoft.AspNet.Server.Kestrel } // For testing - internal KestrelEngine(Libuv uv, IApplicationShutdown appShutdownService) - : this(appShutdownService) + internal KestrelEngine(Libuv uv, IApplicationShutdown appShutdownService, ILogger logger) + : this(appShutdownService, logger) { Libuv = uv; } - private KestrelEngine(IApplicationShutdown appShutdownService) + private KestrelEngine(IApplicationShutdown appShutdownService, ILogger logger) { _serviceContext = new ServiceContext { AppShutdown = appShutdownService, - Memory = new MemoryPool() + Memory = new MemoryPool(), + Log = new KestrelTrace(logger) }; Threads = new List(); diff --git a/src/Microsoft.AspNet.Server.Kestrel/ServerFactory.cs b/src/Microsoft.AspNet.Server.Kestrel/ServerFactory.cs index 10b49da527..256b70c248 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/ServerFactory.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/ServerFactory.cs @@ -8,6 +8,7 @@ using Microsoft.AspNet.Hosting.Server; using Microsoft.AspNet.Http.Features; using Microsoft.Dnx.Runtime; using Microsoft.Framework.Configuration; +using Microsoft.Framework.Logging; namespace Microsoft.AspNet.Server.Kestrel { @@ -18,11 +19,13 @@ namespace Microsoft.AspNet.Server.Kestrel { private readonly ILibraryManager _libraryManager; private readonly IApplicationShutdown _appShutdownService; + private readonly ILogger _logger; - public ServerFactory(ILibraryManager libraryManager, IApplicationShutdown appShutdownService) + public ServerFactory(ILibraryManager libraryManager, IApplicationShutdown appShutdownService, ILoggerFactory loggerFactory) { _libraryManager = libraryManager; _appShutdownService = appShutdownService; + _logger = loggerFactory.CreateLogger("Microsoft.AspNet.Server.Kestrel"); } public IFeatureCollection Initialize(IConfiguration configuration) @@ -48,7 +51,7 @@ namespace Microsoft.AspNet.Server.Kestrel try { var information = (KestrelServerInformation)serverFeatures.Get(); - var engine = new KestrelEngine(_libraryManager, _appShutdownService); + var engine = new KestrelEngine(_libraryManager, _appShutdownService, _logger); disposables.Push(engine); diff --git a/src/Microsoft.AspNet.Server.Kestrel/ServiceContext.cs b/src/Microsoft.AspNet.Server.Kestrel/ServiceContext.cs index bd09076565..7e9d4d23f1 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/ServiceContext.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/ServiceContext.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using Microsoft.AspNet.Server.Kestrel.Http; +using Microsoft.AspNet.Server.Kestrel.Infrastructure; using Microsoft.Dnx.Runtime; namespace Microsoft.AspNet.Server.Kestrel @@ -11,5 +12,7 @@ namespace Microsoft.AspNet.Server.Kestrel public IApplicationShutdown AppShutdown { get; set; } public IMemoryPool Memory { get; set; } + + public IKestrelTrace Log { get; set; } } } diff --git a/src/Microsoft.AspNet.Server.Kestrel/project.json b/src/Microsoft.AspNet.Server.Kestrel/project.json index 4a3d0ab496..621f75be36 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/project.json +++ b/src/Microsoft.AspNet.Server.Kestrel/project.json @@ -11,7 +11,8 @@ "Microsoft.StandardsPolice": { "version": "1.0.0-*", "type": "build" - } + }, + "Microsoft.Framework.Logging.Abstractions": "1.0.0-*" }, "frameworks": { "dnx451": { }, diff --git a/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs index a293e8bae9..0a49cb3f85 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs @@ -86,7 +86,7 @@ namespace Microsoft.AspNet.Server.KestrelTests [Fact] public void EngineCanStartAndStop() { - var engine = new KestrelEngine(LibraryManager, new ShutdownNotImplemented()); + var engine = new KestrelEngine(LibraryManager, new ShutdownNotImplemented(), new TestLogger()); engine.Start(1); engine.Dispose(); } @@ -94,7 +94,7 @@ namespace Microsoft.AspNet.Server.KestrelTests [Fact] public void ListenerCanCreateAndDispose() { - var engine = new KestrelEngine(LibraryManager, new ShutdownNotImplemented()); + var engine = new KestrelEngine(LibraryManager, new ShutdownNotImplemented(), new TestLogger()); engine.Start(1); var started = engine.CreateServer("http", "localhost", 54321, App); started.Dispose(); @@ -105,7 +105,7 @@ namespace Microsoft.AspNet.Server.KestrelTests [Fact] public void ConnectionCanReadAndWrite() { - var engine = new KestrelEngine(LibraryManager, new ShutdownNotImplemented()); + var engine = new KestrelEngine(LibraryManager, new ShutdownNotImplemented(), new TestLogger()); engine.Start(1); var started = engine.CreateServer("http", "localhost", 54321, App); diff --git a/test/Microsoft.AspNet.Server.KestrelTests/MultipleLoopTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/MultipleLoopTests.cs index 35f4f334e6..f8da4fe984 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/MultipleLoopTests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/MultipleLoopTests.cs @@ -16,7 +16,7 @@ namespace Microsoft.AspNet.Server.KestrelTests Libuv _uv; public MultipleLoopTests() { - var engine = new KestrelEngine(LibraryManager, new ShutdownNotImplemented()); + var engine = new KestrelEngine(LibraryManager, new ShutdownNotImplemented(), new TestLogger()); _uv = engine.Libuv; } diff --git a/test/Microsoft.AspNet.Server.KestrelTests/NetworkingTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/NetworkingTests.cs index 4e381b079d..120d6d49f2 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/NetworkingTests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/NetworkingTests.cs @@ -22,7 +22,7 @@ namespace Microsoft.AspNet.Server.KestrelTests Libuv _uv; public NetworkingTests() { - var engine = new KestrelEngine(LibraryManager, new ShutdownNotImplemented()); + var engine = new KestrelEngine(LibraryManager, new ShutdownNotImplemented(), new TestLogger()); _uv = engine.Libuv; } diff --git a/test/Microsoft.AspNet.Server.KestrelTests/SocketOutputTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/SocketOutputTests.cs index 97b1d998d7..618b3679c6 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/SocketOutputTests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/SocketOutputTests.cs @@ -31,13 +31,14 @@ namespace Microsoft.AspNet.Server.KestrelTests } }; - using (var kestrelEngine = new KestrelEngine(mockLibuv, new ShutdownNotImplemented())) + using (var kestrelEngine = new KestrelEngine(mockLibuv, new ShutdownNotImplemented(), new TestLogger())) { kestrelEngine.Start(count: 1); var kestrelThread = kestrelEngine.Threads[0]; var socket = new MockSocket(kestrelThread.Loop.ThreadId); - var socketOutput = new SocketOutput(kestrelThread, socket); + var trace = new KestrelTrace(new TestLogger()); + var socketOutput = new SocketOutput(kestrelThread, socket, trace); // I doubt _maxBytesPreCompleted will ever be over a MB. If it is, we should change this test. var bufferSize = 1048576; @@ -75,13 +76,14 @@ namespace Microsoft.AspNet.Server.KestrelTests } }; - using (var kestrelEngine = new KestrelEngine(mockLibuv, new ShutdownNotImplemented())) + using (var kestrelEngine = new KestrelEngine(mockLibuv, new ShutdownNotImplemented(), new TestLogger())) { kestrelEngine.Start(count: 1); var kestrelThread = kestrelEngine.Threads[0]; var socket = new MockSocket(kestrelThread.Loop.ThreadId); - var socketOutput = new SocketOutput(kestrelThread, socket); + var trace = new KestrelTrace(new TestLogger()); + var socketOutput = new SocketOutput(kestrelThread, socket, trace); var bufferSize = maxBytesPreCompleted; var buffer = new ArraySegment(new byte[bufferSize], 0, bufferSize); diff --git a/test/Microsoft.AspNet.Server.KestrelTests/TestLogger.cs b/test/Microsoft.AspNet.Server.KestrelTests/TestLogger.cs new file mode 100644 index 0000000000..1f3cef826e --- /dev/null +++ b/test/Microsoft.AspNet.Server.KestrelTests/TestLogger.cs @@ -0,0 +1,23 @@ +using System; +using Microsoft.AspNet.Server.Kestrel; +using Microsoft.Framework.Logging; + +namespace Microsoft.AspNet.Server.KestrelTests +{ + public class TestLogger : ILogger + { + public void Log(LogLevel logLevel, int eventId, object state, Exception exception, Func formatter) + { + } + + public bool IsEnabled(LogLevel logLevel) + { + return true; + } + + public IDisposable BeginScopeImpl(object state) + { + return new Disposable(() => { }); + } + } +} \ No newline at end of file diff --git a/test/Microsoft.AspNet.Server.KestrelTests/TestServer.cs b/test/Microsoft.AspNet.Server.KestrelTests/TestServer.cs index b299d26246..3ada706a90 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/TestServer.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/TestServer.cs @@ -45,7 +45,7 @@ namespace Microsoft.AspNet.Server.KestrelTests public void Create(Func app) { - _engine = new KestrelEngine(LibraryManager, new ShutdownNotImplemented()); + _engine = new KestrelEngine(LibraryManager, new ShutdownNotImplemented(), new TestLogger()); _engine.Start(1); _server = _engine.CreateServer( "http", From ed4850a2b192f3767082b8c8d90b08df9c66392e Mon Sep 17 00:00:00 2001 From: Ivan Derevyanko Date: Sat, 5 Sep 2015 18:32:16 +0200 Subject: [PATCH 0238/1662] Style fix --- samples/SampleApp/Startup.cs | 2 ++ samples/SampleApp/project.json | 1 - test/Microsoft.AspNet.Server.KestrelTests/TestLogger.cs | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/samples/SampleApp/Startup.cs b/samples/SampleApp/Startup.cs index f076b27a19..955df43277 100644 --- a/samples/SampleApp/Startup.cs +++ b/samples/SampleApp/Startup.cs @@ -13,7 +13,9 @@ namespace SampleApp public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory) { loggerFactory.MinimumLevel = LogLevel.Debug; + loggerFactory.AddConsole(LogLevel.Debug); + app.Run(context => { Console.WriteLine("{0} {1}{2}{3}", diff --git a/samples/SampleApp/project.json b/samples/SampleApp/project.json index fbfc10abf9..2e0dd6f9c3 100644 --- a/samples/SampleApp/project.json +++ b/samples/SampleApp/project.json @@ -2,7 +2,6 @@ "version": "1.0.0-*", "dependencies": { "Microsoft.AspNet.Server.Kestrel": "1.0.0-*", - "Microsoft.Framework.Logging.Abstractions": "1.0.0-*", "Microsoft.Framework.Logging.Console": "1.0.0-*" }, "frameworks": { diff --git a/test/Microsoft.AspNet.Server.KestrelTests/TestLogger.cs b/test/Microsoft.AspNet.Server.KestrelTests/TestLogger.cs index 1f3cef826e..2c25a46691 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/TestLogger.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/TestLogger.cs @@ -12,7 +12,7 @@ namespace Microsoft.AspNet.Server.KestrelTests public bool IsEnabled(LogLevel logLevel) { - return true; + return false; } public IDisposable BeginScopeImpl(object state) From a93a66fe7c6164e37b00deac843efefbbce6a4a5 Mon Sep 17 00:00:00 2001 From: Ivan Derevyanko Date: Wed, 9 Sep 2015 00:26:26 +0200 Subject: [PATCH 0239/1662] Replace Trace.WriteLine with ITraceLogger --- .../Http/Connection.cs | 8 ++-- .../Http/Frame.cs | 12 +++--- .../Http/Listener.cs | 6 +-- .../Http/ListenerPrimary.cs | 6 +-- .../Http/ListenerSecondary.cs | 8 ++-- .../Http/PipeListener.cs | 4 +- .../Http/PipeListenerPrimary.cs | 4 +- .../Http/PipeListenerSecondary.cs | 2 +- .../Http/SocketOutput.cs | 2 +- .../Http/TcpListener.cs | 4 +- .../Http/TcpListenerPrimary.cs | 4 +- .../Http/TcpListenerSecondary.cs | 2 +- .../Infrastructure/KestrelThread.cs | 13 +++--- .../Networking/UvAsyncHandle.cs | 5 +++ .../Networking/UvConnectRequest.cs | 16 ++++--- .../Networking/UvHandle.cs | 5 +++ .../Networking/UvLoopHandle.cs | 5 +++ .../Networking/UvMemory.cs | 5 ++- .../Networking/UvPipeHandle.cs | 5 +++ .../Networking/UvRequest.cs | 8 ++-- .../Networking/UvShutdownReq.cs | 6 ++- .../Networking/UvStreamHandle.cs | 28 ++++++++----- .../Networking/UvTcpHandle.cs | 5 +++ .../Networking/UvWriteReq.cs | 14 +++++-- .../project.json | 4 +- .../MultipleLoopTests.cs | 42 ++++++++++--------- .../NetworkingTests.cs | 34 ++++++++------- .../SocketOutputTests.cs | 7 ++-- 28 files changed, 162 insertions(+), 102 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs index 055acd8b2e..088d75ea38 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs @@ -2,8 +2,8 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.Diagnostics; using Microsoft.AspNet.Server.Kestrel.Networking; +using Microsoft.Framework.Logging; namespace Microsoft.AspNet.Server.Kestrel.Http { @@ -75,7 +75,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http if (errorDone && error != null) { - Trace.WriteLine("Connection.OnRead " + error.ToString()); + Log.LogError("Connection.OnRead", error); } } @@ -86,7 +86,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } catch (Exception ex) { - Trace.WriteLine("Connection._frame.Consume " + ex.ToString()); + Log.LogError("Connection._frame.Consume ", ex); } } @@ -121,7 +121,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { Log.ConnectionWriteFin(_connectionId, 1); var self = (Connection)state; - var shutdown = new UvShutdownReq(); + var shutdown = new UvShutdownReq(Log); shutdown.Init(self.Thread.Loop); shutdown.Shutdown(self._socket, (req, status, _) => { diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs index 1b418ee8d8..821e3788c3 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs @@ -3,11 +3,11 @@ using System; using System.Collections.Generic; -using System.Diagnostics; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; +using Microsoft.Framework.Logging; using Microsoft.Framework.Primitives; // ReSharper disable AccessToModifiedClosure @@ -276,7 +276,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { if (error != null) { - Trace.WriteLine("WriteChunkPrefix" + error.ToString()); + Log.LogError("WriteChunkPrefix", error); } }, null, @@ -290,7 +290,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { if (error != null) { - Trace.WriteLine("WriteChunkSuffix" + error.ToString()); + Log.LogError("WriteChunkSuffix", error); } }, null, @@ -304,7 +304,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { if (error != null) { - Trace.WriteLine("WriteChunkedResponseSuffix" + error.ToString()); + Log.LogError("WriteChunkedResponseSuffix", error); } }, null, @@ -338,7 +338,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { if (error != null) { - Trace.WriteLine("ProduceContinue " + error.ToString()); + Log.LogError("ProduceContinue ", error); } }, null); @@ -361,7 +361,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { if (error != null) { - Trace.WriteLine("ProduceStart " + error.ToString()); + Log.LogError("ProduceStart ", error); } ((IDisposable)state).Dispose(); }, diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs index 8485869296..2d2de23113 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs @@ -3,8 +3,8 @@ using Microsoft.AspNet.Server.Kestrel.Networking; using System; -using System.Diagnostics; using System.Threading.Tasks; +using Microsoft.Framework.Logging; namespace Microsoft.AspNet.Server.Kestrel.Http { @@ -50,11 +50,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http /// protected abstract UvStreamHandle CreateListenSocket(string host, int port); - protected static void ConnectionCallback(UvStreamHandle stream, int status, Exception error, object state) + protected void ConnectionCallback(UvStreamHandle stream, int status, Exception error, object state) { if (error != null) { - Trace.WriteLine("Listener.ConnectionCallback " + error.ToString()); + Log.LogError("Listener.ConnectionCallback ", error); } else { diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerPrimary.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerPrimary.cs index 67204fc729..0010c2d60f 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerPrimary.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerPrimary.cs @@ -40,7 +40,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http await Thread.PostAsync(_ => { - ListenPipe = new UvPipeHandle(); + ListenPipe = new UvPipeHandle(Log); ListenPipe.Init(Thread.Loop, false); ListenPipe.Bind(pipeName); ListenPipe.Listen(Constants.ListenBacklog, OnListenPipe, null); @@ -54,7 +54,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return; } - var dispatchPipe = new UvPipeHandle(); + var dispatchPipe = new UvPipeHandle(Log); dispatchPipe.Init(Thread.Loop, true); try { @@ -78,7 +78,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http else { var dispatchPipe = _dispatchPipes[index]; - var write = new UvWriteReq(); + var write = new UvWriteReq(Log); write.Init(Thread.Loop); write.Write2( dispatchPipe, diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerSecondary.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerSecondary.cs index f0948b867b..fd54a27334 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerSecondary.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerSecondary.cs @@ -3,9 +3,9 @@ using Microsoft.AspNet.Server.Kestrel.Networking; using System; -using System.Diagnostics; using System.Runtime.InteropServices; using System.Threading.Tasks; +using Microsoft.Framework.Logging; namespace Microsoft.AspNet.Server.Kestrel.Http { @@ -29,7 +29,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http Thread = thread; Application = application; - DispatchPipe = new UvPipeHandle(); + DispatchPipe = new UvPipeHandle(Log); var tcs = new TaskCompletionSource(); Thread.Post(_ => @@ -37,7 +37,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http try { DispatchPipe.Init(Thread.Loop, true); - var connect = new UvConnectRequest(); + var connect = new UvConnectRequest(Log); connect.Init(Thread.Loop); connect.Connect( DispatchPipe, @@ -75,7 +75,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } catch (Exception ex) { - Trace.WriteLine("DispatchPipe.Accept " + ex.Message); + Log.LogError("DispatchPipe.Accept", ex); acceptSocket.Dispose(); return; } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/PipeListener.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/PipeListener.cs index 2fd4dd3c32..62e12fc9a7 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/PipeListener.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/PipeListener.cs @@ -20,7 +20,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http /// protected override UvStreamHandle CreateListenSocket(string host, int port) { - var socket = new UvPipeHandle(); + var socket = new UvPipeHandle(Log); socket.Init(Thread.Loop, false); socket.Bind(host); socket.Listen(Constants.ListenBacklog, ConnectionCallback, this); @@ -34,7 +34,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http /// Connection status protected override void OnConnection(UvStreamHandle listenSocket, int status) { - var acceptSocket = new UvPipeHandle(); + var acceptSocket = new UvPipeHandle(Log); acceptSocket.Init(Thread.Loop, false); listenSocket.Accept(acceptSocket); diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/PipeListenerPrimary.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/PipeListenerPrimary.cs index afb4c7c213..96691a2b8d 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/PipeListenerPrimary.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/PipeListenerPrimary.cs @@ -20,7 +20,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http /// protected override UvStreamHandle CreateListenSocket(string host, int port) { - var socket = new UvPipeHandle(); + var socket = new UvPipeHandle(Log); socket.Init(Thread.Loop, false); socket.Bind(host); socket.Listen(Constants.ListenBacklog, ConnectionCallback, this); @@ -34,7 +34,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http /// Connection status protected override void OnConnection(UvStreamHandle listenSocket, int status) { - var acceptSocket = new UvPipeHandle(); + var acceptSocket = new UvPipeHandle(Log); acceptSocket.Init(Thread.Loop, false); listenSocket.Accept(acceptSocket); diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/PipeListenerSecondary.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/PipeListenerSecondary.cs index 40b34038d9..a9c3f70529 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/PipeListenerSecondary.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/PipeListenerSecondary.cs @@ -19,7 +19,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http /// protected override UvStreamHandle CreateAcceptSocket() { - var acceptSocket = new UvPipeHandle(); + var acceptSocket = new UvPipeHandle(Log); acceptSocket.Init(Thread.Loop, false); return acceptSocket; } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs index 676c0b1461..af490063fd 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs @@ -130,7 +130,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http buffers[i++] = buffer; } - var writeReq = new UvWriteReq(); + var writeReq = new UvWriteReq(_log); writeReq.Init(_thread.Loop); writeReq.Write(_socket, new ArraySegment>(buffers), (r, status, error, state) => diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/TcpListener.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/TcpListener.cs index 7c67208e3f..4fa374c0fb 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/TcpListener.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/TcpListener.cs @@ -21,7 +21,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http /// protected override UvStreamHandle CreateListenSocket(string host, int port) { - var socket = new UvTcpHandle(); + var socket = new UvTcpHandle(Log); socket.Init(Thread.Loop, Thread.QueueCloseHandle); socket.Bind(new IPEndPoint(IPAddress.Any, port)); socket.Listen(Constants.ListenBacklog, ConnectionCallback, this); @@ -35,7 +35,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http /// Connection status protected override void OnConnection(UvStreamHandle listenSocket, int status) { - var acceptSocket = new UvTcpHandle(); + var acceptSocket = new UvTcpHandle(Log); acceptSocket.Init(Thread.Loop, Thread.QueueCloseHandle); listenSocket.Accept(acceptSocket); diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/TcpListenerPrimary.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/TcpListenerPrimary.cs index 098238bde1..2a80f3caee 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/TcpListenerPrimary.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/TcpListenerPrimary.cs @@ -21,7 +21,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http /// protected override UvStreamHandle CreateListenSocket(string host, int port) { - var socket = new UvTcpHandle(); + var socket = new UvTcpHandle(Log); socket.Init(Thread.Loop, Thread.QueueCloseHandle); socket.Bind(new IPEndPoint(IPAddress.Any, port)); socket.Listen(Constants.ListenBacklog, ConnectionCallback, this); @@ -35,7 +35,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http /// Connection status protected override void OnConnection(UvStreamHandle listenSocket, int status) { - var acceptSocket = new UvTcpHandle(); + var acceptSocket = new UvTcpHandle(Log); acceptSocket.Init(Thread.Loop, Thread.QueueCloseHandle); listenSocket.Accept(acceptSocket); diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/TcpListenerSecondary.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/TcpListenerSecondary.cs index 4cff07cedf..d6680d3318 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/TcpListenerSecondary.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/TcpListenerSecondary.cs @@ -19,7 +19,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http /// protected override UvStreamHandle CreateAcceptSocket() { - var acceptSocket = new UvTcpHandle(); + var acceptSocket = new UvTcpHandle(Log); acceptSocket.Init(Thread.Loop, Thread.QueueCloseHandle); return acceptSocket; } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs index f611d8857a..1af6b04549 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs @@ -4,11 +4,12 @@ using Microsoft.AspNet.Server.Kestrel.Networking; using System; using System.Collections.Generic; -using System.Diagnostics; using System.Runtime.ExceptionServices; using System.Threading; using System.Threading.Tasks; +using Microsoft.AspNet.Server.Kestrel.Infrastructure; using Microsoft.Dnx.Runtime; +using Microsoft.Framework.Logging; namespace Microsoft.AspNet.Server.Kestrel { @@ -30,13 +31,15 @@ namespace Microsoft.AspNet.Server.Kestrel private object _workSync = new Object(); private bool _stopImmediate = false; private ExceptionDispatchInfo _closeError; + private IKestrelTrace _log; public KestrelThread(KestrelEngine engine, ServiceContext serviceContext) { _engine = engine; _appShutdown = serviceContext.AppShutdown; - _loop = new UvLoopHandle(); - _post = new UvAsyncHandle(); + _log = serviceContext.Log; + _loop = new UvLoopHandle(_log); + _post = new UvAsyncHandle(_log); _thread = new Thread(ThreadStart); QueueCloseHandle = PostCloseHandle; } @@ -272,7 +275,7 @@ namespace Microsoft.AspNet.Server.Kestrel } else { - Trace.WriteLine("KestrelThread.DoPostWork " + ex.ToString()); + _log.LogError("KestrelThread.DoPostWork", ex); } } } @@ -295,7 +298,7 @@ namespace Microsoft.AspNet.Server.Kestrel } catch (Exception ex) { - Trace.WriteLine("KestrelThread.DoPostCloseHandle " + ex.ToString()); + _log.LogError("KestrelThread.DoPostCloseHandle", ex); } } } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvAsyncHandle.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvAsyncHandle.cs index 138853da85..04c2ecce3b 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvAsyncHandle.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvAsyncHandle.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using Microsoft.AspNet.Server.Kestrel.Infrastructure; namespace Microsoft.AspNet.Server.Kestrel.Networking { @@ -10,6 +11,10 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking private static Libuv.uv_async_cb _uv_async_cb = AsyncCb; private Action _callback; + public UvAsyncHandle(IKestrelTrace logger) : base(logger) + { + } + public void Init(UvLoopHandle loop, Action callback) { CreateMemory( diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvConnectRequest.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvConnectRequest.cs index 1791fb56e7..59df2af68a 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvConnectRequest.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvConnectRequest.cs @@ -2,9 +2,8 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.Runtime.InteropServices; +using Microsoft.AspNet.Server.Kestrel.Infrastructure; +using Microsoft.Framework.Logging; namespace Microsoft.AspNet.Server.Kestrel.Networking { @@ -13,11 +12,16 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking /// public class UvConnectRequest : UvRequest { - private readonly static Libuv.uv_connect_cb _uv_connect_cb = UvConnectCb; + private readonly Libuv.uv_connect_cb _uv_connect_cb; private Action _callback; private object _state; + public UvConnectRequest(IKestrelTrace logger) : base (logger) + { + _uv_connect_cb = UvConnectCb; + } + public void Init(UvLoopHandle loop) { var requestSize = loop.Libuv.req_size(Libuv.RequestType.CONNECT); @@ -40,7 +44,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking Libuv.pipe_connect(this, pipe, name, _uv_connect_cb); } - private static void UvConnectCb(IntPtr ptr, int status) + private void UvConnectCb(IntPtr ptr, int status) { var req = FromIntPtr(ptr); req.Unpin(); @@ -63,7 +67,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking } catch (Exception ex) { - Trace.WriteLine("UvConnectRequest " + ex.ToString()); + _log.LogError("UvConnectRequest", ex); } } } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvHandle.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvHandle.cs index cb4d5a37dc..4b90ecfd57 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvHandle.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvHandle.cs @@ -3,6 +3,7 @@ using System; using System.Threading; +using Microsoft.AspNet.Server.Kestrel.Infrastructure; namespace Microsoft.AspNet.Server.Kestrel.Networking { @@ -11,6 +12,10 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking private static Libuv.uv_close_cb _destroyMemory = DestroyMemory; private Action, IntPtr> _queueCloseHandle; + protected UvHandle(IKestrelTrace logger) : base (logger) + { + } + unsafe protected void CreateHandle( Libuv uv, int threadId, diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvLoopHandle.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvLoopHandle.cs index f0f3d454b1..5c708c2e23 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvLoopHandle.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvLoopHandle.cs @@ -3,11 +3,16 @@ using System; using System.Threading; +using Microsoft.AspNet.Server.Kestrel.Infrastructure; namespace Microsoft.AspNet.Server.Kestrel.Networking { public class UvLoopHandle : UvHandle { + public UvLoopHandle(IKestrelTrace logger) : base(logger) + { + } + public void Init(Libuv uv) { CreateMemory( diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvMemory.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvMemory.cs index f9d0e11ed2..051218ffef 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvMemory.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvMemory.cs @@ -5,6 +5,7 @@ using System; using System.Diagnostics; using System.Runtime.InteropServices; using System.Threading; +using Microsoft.AspNet.Server.Kestrel.Infrastructure; namespace Microsoft.AspNet.Server.Kestrel.Networking { @@ -15,9 +16,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking { protected Libuv _uv; protected int _threadId; + protected IKestrelTrace _log; - public UvMemory() : base(IntPtr.Zero, true) + protected UvMemory(IKestrelTrace logger) : base(IntPtr.Zero, true) { + _log = logger; } public Libuv Libuv { get { return _uv; } } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvPipeHandle.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvPipeHandle.cs index e110c57e6d..8bd24af53c 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvPipeHandle.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvPipeHandle.cs @@ -3,11 +3,16 @@ using System; using System.Net; +using Microsoft.AspNet.Server.Kestrel.Infrastructure; namespace Microsoft.AspNet.Server.Kestrel.Networking { public class UvPipeHandle : UvStreamHandle { + public UvPipeHandle(IKestrelTrace logger) : base(logger) + { + } + public void Init(UvLoopHandle loop, bool ipc) { CreateMemory( diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvRequest.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvRequest.cs index e79ff42674..4005129cec 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvRequest.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvRequest.cs @@ -1,8 +1,6 @@ using System; -using System.Collections.Generic; -using System.Linq; using System.Runtime.InteropServices; -using System.Threading.Tasks; +using Microsoft.AspNet.Server.Kestrel.Infrastructure; namespace Microsoft.AspNet.Server.Kestrel.Networking { @@ -10,6 +8,10 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking { private GCHandle _pin; + protected UvRequest(IKestrelTrace logger) : base (logger) + { + } + protected override bool ReleaseHandle() { DestroyMemory(handle); diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvShutdownReq.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvShutdownReq.cs index a8841754bf..d6aa2c65ad 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvShutdownReq.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvShutdownReq.cs @@ -2,7 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.Runtime.InteropServices; +using Microsoft.AspNet.Server.Kestrel.Infrastructure; namespace Microsoft.AspNet.Server.Kestrel.Networking { @@ -16,6 +16,10 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking private Action _callback; private object _state; + public UvShutdownReq(IKestrelTrace logger) : base (logger) + { + } + public void Init(UvLoopHandle loop) { CreateMemory( diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvStreamHandle.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvStreamHandle.cs index 33c0008549..4bc2712655 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvStreamHandle.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvStreamHandle.cs @@ -2,16 +2,17 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.Diagnostics; using System.Runtime.InteropServices; +using Microsoft.AspNet.Server.Kestrel.Infrastructure; +using Microsoft.Framework.Logging; namespace Microsoft.AspNet.Server.Kestrel.Networking { public abstract class UvStreamHandle : UvHandle { - private readonly static Libuv.uv_connection_cb _uv_connection_cb = UvConnectionCb; - private readonly static Libuv.uv_alloc_cb _uv_alloc_cb = UvAllocCb; - private readonly static Libuv.uv_read_cb _uv_read_cb = UvReadCb; + private readonly Libuv.uv_connection_cb _uv_connection_cb; + private readonly Libuv.uv_alloc_cb _uv_alloc_cb; + private readonly Libuv.uv_read_cb _uv_read_cb; public Action _listenCallback; public object _listenState; @@ -22,6 +23,13 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking public object _readState; private GCHandle _readVitality; + protected UvStreamHandle(IKestrelTrace logger) : base(logger) + { + _uv_connection_cb = UvConnectionCb; + _uv_alloc_cb = UvAllocCb; + _uv_read_cb = UvReadCb; + } + protected override bool ReleaseHandle() { if (_listenVitality.IsAllocated) @@ -114,7 +122,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking } - private static void UvConnectionCb(IntPtr handle, int status) + private void UvConnectionCb(IntPtr handle, int status) { var stream = FromIntPtr(handle); @@ -127,12 +135,12 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking } catch (Exception ex) { - Trace.WriteLine("UvConnectionCb " + ex.ToString()); + _log.LogError("UvConnectionCb", ex); } } - private static void UvAllocCb(IntPtr handle, int suggested_size, out Libuv.uv_buf_t buf) + private void UvAllocCb(IntPtr handle, int suggested_size, out Libuv.uv_buf_t buf) { var stream = FromIntPtr(handle); try @@ -141,13 +149,13 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking } catch (Exception ex) { - Trace.WriteLine("UvAllocCb " + ex.ToString()); + _log.LogError("UvAllocCb", ex); buf = stream.Libuv.buf_init(IntPtr.Zero, 0); throw; } } - private static void UvReadCb(IntPtr handle, int nread, ref Libuv.uv_buf_t buf) + private void UvReadCb(IntPtr handle, int nread, ref Libuv.uv_buf_t buf) { var stream = FromIntPtr(handle); @@ -166,7 +174,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking } catch (Exception ex) { - Trace.WriteLine("UbReadCb " + ex.ToString()); + _log.LogError("UbReadCb", ex); } } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvTcpHandle.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvTcpHandle.cs index 281f29190b..d99f225bd1 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvTcpHandle.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvTcpHandle.cs @@ -3,11 +3,16 @@ using System; using System.Net; +using Microsoft.AspNet.Server.Kestrel.Infrastructure; namespace Microsoft.AspNet.Server.Kestrel.Networking { public class UvTcpHandle : UvStreamHandle { + public UvTcpHandle(IKestrelTrace logger) : base(logger) + { + } + public void Init(UvLoopHandle loop) { CreateMemory( diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvWriteReq.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvWriteReq.cs index 39aba8b4dc..feadb2de49 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvWriteReq.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvWriteReq.cs @@ -3,8 +3,9 @@ using System; using System.Collections.Generic; -using System.Diagnostics; using System.Runtime.InteropServices; +using Microsoft.AspNet.Server.Kestrel.Infrastructure; +using Microsoft.Framework.Logging; namespace Microsoft.AspNet.Server.Kestrel.Networking { @@ -13,7 +14,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking /// public class UvWriteReq : UvRequest { - private readonly static Libuv.uv_write_cb _uv_write_cb = UvWriteCb; + private readonly Libuv.uv_write_cb _uv_write_cb; private IntPtr _bufs; @@ -23,6 +24,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking private List _pins = new List(); + public UvWriteReq(IKestrelTrace logger) : base(logger) + { + _uv_write_cb = UvWriteCb; + } + public void Init(UvLoopHandle loop) { var requestSize = loop.Libuv.req_size(Libuv.RequestType.WRITE); @@ -138,7 +144,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking req._pins.Clear(); } - private static void UvWriteCb(IntPtr ptr, int status) + private void UvWriteCb(IntPtr ptr, int status) { var req = FromIntPtr(ptr); Unpin(req); @@ -161,7 +167,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking } catch (Exception ex) { - Trace.WriteLine("UvWriteCb " + ex.ToString()); + _log.LogError("UvWriteCb", ex); } } } diff --git a/src/Microsoft.AspNet.Server.Kestrel/project.json b/src/Microsoft.AspNet.Server.Kestrel/project.json index 621f75be36..26e0dc886a 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/project.json +++ b/src/Microsoft.AspNet.Server.Kestrel/project.json @@ -8,11 +8,11 @@ "dependencies": { "Microsoft.AspNet.Hosting": "1.0.0-*", "Microsoft.Dnx.Runtime.Abstractions": "1.0.0-*", + "Microsoft.Framework.Logging.Abstractions": "1.0.0-*", "Microsoft.StandardsPolice": { "version": "1.0.0-*", "type": "build" - }, - "Microsoft.Framework.Logging.Abstractions": "1.0.0-*" + } }, "frameworks": { "dnx451": { }, diff --git a/test/Microsoft.AspNet.Server.KestrelTests/MultipleLoopTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/MultipleLoopTests.cs index f8da4fe984..cef89f8f6c 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/MultipleLoopTests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/MultipleLoopTests.cs @@ -4,6 +4,7 @@ using System.Net.Sockets; using System.Runtime.InteropServices; using System.Threading; using Microsoft.AspNet.Server.Kestrel; +using Microsoft.AspNet.Server.Kestrel.Infrastructure; using Microsoft.AspNet.Server.Kestrel.Networking; using Microsoft.Dnx.Runtime; using Microsoft.Dnx.Runtime.Infrastructure; @@ -13,7 +14,8 @@ namespace Microsoft.AspNet.Server.KestrelTests { public class MultipleLoopTests { - Libuv _uv; + private readonly Libuv _uv; + private readonly IKestrelTrace _logger = new KestrelTrace(new TestLogger()); public MultipleLoopTests() { var engine = new KestrelEngine(LibraryManager, new ShutdownNotImplemented(), new TestLogger()); @@ -41,8 +43,8 @@ namespace Microsoft.AspNet.Server.KestrelTests [Fact] public void InitAndCloseServerPipe() { - var loop = new UvLoopHandle(); - var pipe = new UvPipeHandle(); + var loop = new UvLoopHandle(_logger); + var pipe = new UvPipeHandle(_logger); loop.Init(_uv); pipe.Init(loop, true); @@ -59,15 +61,15 @@ namespace Microsoft.AspNet.Server.KestrelTests [Fact] public void ServerPipeListenForConnections() { - var loop = new UvLoopHandle(); - var serverListenPipe = new UvPipeHandle(); + var loop = new UvLoopHandle(_logger); + var serverListenPipe = new UvPipeHandle(_logger); loop.Init(_uv); serverListenPipe.Init(loop, false); serverListenPipe.Bind(@"\\.\pipe\ServerPipeListenForConnections"); serverListenPipe.Listen(128, (_1, status, error, _2) => { - var serverConnectionPipe = new UvPipeHandle(); + var serverConnectionPipe = new UvPipeHandle(_logger); serverConnectionPipe.Init(loop, true); try { @@ -79,7 +81,7 @@ namespace Microsoft.AspNet.Server.KestrelTests return; } - var writeRequest = new UvWriteReq(); + var writeRequest = new UvWriteReq(new KestrelTrace(new TestLogger())); writeRequest.Init(loop); writeRequest.Write( serverConnectionPipe, @@ -96,9 +98,9 @@ namespace Microsoft.AspNet.Server.KestrelTests var worker = new Thread(() => { - var loop2 = new UvLoopHandle(); - var clientConnectionPipe = new UvPipeHandle(); - var connect = new UvConnectRequest(); + var loop2 = new UvLoopHandle(_logger); + var clientConnectionPipe = new UvPipeHandle(_logger); + var connect = new UvConnectRequest(new KestrelTrace(new TestLogger())); loop2.Init(_uv); clientConnectionPipe.Init(loop2, true); @@ -134,19 +136,19 @@ namespace Microsoft.AspNet.Server.KestrelTests { var pipeName = @"\\.\pipe\ServerPipeDispatchConnections" + Guid.NewGuid().ToString("n"); - var loop = new UvLoopHandle(); + var loop = new UvLoopHandle(_logger); loop.Init(_uv); var serverConnectionPipe = default(UvPipeHandle); var serverConnectionPipeAcceptedEvent = new ManualResetEvent(false); var serverConnectionTcpDisposedEvent = new ManualResetEvent(false); - var serverListenPipe = new UvPipeHandle(); + var serverListenPipe = new UvPipeHandle(_logger); serverListenPipe.Init(loop, false); serverListenPipe.Bind(pipeName); serverListenPipe.Listen(128, (_1, status, error, _2) => { - serverConnectionPipe = new UvPipeHandle(); + serverConnectionPipe = new UvPipeHandle(_logger); serverConnectionPipe.Init(loop, true); try { @@ -161,18 +163,18 @@ namespace Microsoft.AspNet.Server.KestrelTests } }, null); - var serverListenTcp = new UvTcpHandle(); + var serverListenTcp = new UvTcpHandle(_logger); serverListenTcp.Init(loop); serverListenTcp.Bind(new IPEndPoint(0, 54321)); serverListenTcp.Listen(128, (_1, status, error, _2) => { - var serverConnectionTcp = new UvTcpHandle(); + var serverConnectionTcp = new UvTcpHandle(_logger); serverConnectionTcp.Init(loop); serverListenTcp.Accept(serverConnectionTcp); serverConnectionPipeAcceptedEvent.WaitOne(); - var writeRequest = new UvWriteReq(); + var writeRequest = new UvWriteReq(new KestrelTrace(new TestLogger())); writeRequest.Init(loop); writeRequest.Write2( serverConnectionPipe, @@ -192,9 +194,9 @@ namespace Microsoft.AspNet.Server.KestrelTests var worker = new Thread(() => { - var loop2 = new UvLoopHandle(); - var clientConnectionPipe = new UvPipeHandle(); - var connect = new UvConnectRequest(); + var loop2 = new UvLoopHandle(_logger); + var clientConnectionPipe = new UvPipeHandle(_logger); + var connect = new UvConnectRequest(new KestrelTrace(new TestLogger())); loop2.Init(_uv); clientConnectionPipe.Init(loop2, true); @@ -216,7 +218,7 @@ namespace Microsoft.AspNet.Server.KestrelTests clientConnectionPipe.Dispose(); return; } - var clientConnectionTcp = new UvTcpHandle(); + var clientConnectionTcp = new UvTcpHandle(_logger); clientConnectionTcp.Init(loop2); clientConnectionPipe.Accept(clientConnectionTcp); var buf2 = loop2.Libuv.buf_init(Marshal.AllocHGlobal(64), 64); diff --git a/test/Microsoft.AspNet.Server.KestrelTests/NetworkingTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/NetworkingTests.cs index 120d6d49f2..e5dfc9f3cb 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/NetworkingTests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/NetworkingTests.cs @@ -7,6 +7,7 @@ using System.Net.Sockets; using System.Runtime.InteropServices; using System.Threading.Tasks; using Microsoft.AspNet.Server.Kestrel; +using Microsoft.AspNet.Server.Kestrel.Infrastructure; using Microsoft.AspNet.Server.Kestrel.Networking; using Microsoft.Dnx.Runtime; using Microsoft.Dnx.Runtime.Infrastructure; @@ -19,7 +20,8 @@ namespace Microsoft.AspNet.Server.KestrelTests /// public class NetworkingTests { - Libuv _uv; + private readonly Libuv _uv; + private readonly IKestrelTrace _logger = new KestrelTrace(new TestLogger()); public NetworkingTests() { var engine = new KestrelEngine(LibraryManager, new ShutdownNotImplemented(), new TestLogger()); @@ -47,7 +49,7 @@ namespace Microsoft.AspNet.Server.KestrelTests [Fact] public void LoopCanBeInitAndClose() { - var loop = new UvLoopHandle(); + var loop = new UvLoopHandle(_logger); loop.Init(_uv); loop.Run(); loop.Dispose(); @@ -56,9 +58,9 @@ namespace Microsoft.AspNet.Server.KestrelTests [Fact] public void AsyncCanBeSent() { - var loop = new UvLoopHandle(); + var loop = new UvLoopHandle(_logger); loop.Init(_uv); - var trigger = new UvAsyncHandle(); + var trigger = new UvAsyncHandle(_logger); var called = false; trigger.Init(loop, () => { @@ -74,9 +76,9 @@ namespace Microsoft.AspNet.Server.KestrelTests [Fact] public void SocketCanBeInitAndClose() { - var loop = new UvLoopHandle(); + var loop = new UvLoopHandle(_logger); loop.Init(_uv); - var tcp = new UvTcpHandle(); + var tcp = new UvTcpHandle(_logger); tcp.Init(loop); tcp.Bind(new IPEndPoint(IPAddress.Loopback, 0)); tcp.Dispose(); @@ -88,14 +90,14 @@ namespace Microsoft.AspNet.Server.KestrelTests [Fact] public async Task SocketCanListenAndAccept() { - var loop = new UvLoopHandle(); + var loop = new UvLoopHandle(_logger); loop.Init(_uv); - var tcp = new UvTcpHandle(); + var tcp = new UvTcpHandle(_logger); tcp.Init(loop); tcp.Bind(new IPEndPoint(IPAddress.Loopback, 54321)); tcp.Listen(10, (stream, status, error, state) => { - var tcp2 = new UvTcpHandle(); + var tcp2 = new UvTcpHandle(_logger); tcp2.Init(loop); stream.Accept(tcp2); tcp2.Dispose(); @@ -125,15 +127,15 @@ namespace Microsoft.AspNet.Server.KestrelTests public async Task SocketCanRead() { int bytesRead = 0; - var loop = new UvLoopHandle(); + var loop = new UvLoopHandle(_logger); loop.Init(_uv); - var tcp = new UvTcpHandle(); + var tcp = new UvTcpHandle(_logger); tcp.Init(loop); tcp.Bind(new IPEndPoint(IPAddress.Loopback, 54321)); tcp.Listen(10, (_, status, error, state) => { Console.WriteLine("Connected"); - var tcp2 = new UvTcpHandle(); + var tcp2 = new UvTcpHandle(_logger); tcp2.Init(loop); tcp.Accept(tcp2); var data = Marshal.AllocCoTaskMem(500); @@ -181,15 +183,15 @@ namespace Microsoft.AspNet.Server.KestrelTests public async Task SocketCanReadAndWrite() { int bytesRead = 0; - var loop = new UvLoopHandle(); + var loop = new UvLoopHandle(_logger); loop.Init(_uv); - var tcp = new UvTcpHandle(); + var tcp = new UvTcpHandle(_logger); tcp.Init(loop); tcp.Bind(new IPEndPoint(IPAddress.Loopback, 54321)); tcp.Listen(10, (_, status, error, state) => { Console.WriteLine("Connected"); - var tcp2 = new UvTcpHandle(); + var tcp2 = new UvTcpHandle(_logger); tcp2.Init(loop); tcp.Accept(tcp2); var data = Marshal.AllocCoTaskMem(500); @@ -206,7 +208,7 @@ namespace Microsoft.AspNet.Server.KestrelTests { for (var x = 0; x != 2; ++x) { - var req = new UvWriteReq(); + var req = new UvWriteReq(new KestrelTrace(new TestLogger())); req.Init(loop); req.Write( tcp2, diff --git a/test/Microsoft.AspNet.Server.KestrelTests/SocketOutputTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/SocketOutputTests.cs index 618b3679c6..7577fa25d5 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/SocketOutputTests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/SocketOutputTests.cs @@ -6,6 +6,7 @@ using System.Collections.Generic; using System.Threading; using Microsoft.AspNet.Server.Kestrel; using Microsoft.AspNet.Server.Kestrel.Http; +using Microsoft.AspNet.Server.Kestrel.Infrastructure; using Microsoft.AspNet.Server.Kestrel.Networking; using Microsoft.AspNet.Server.KestrelTests.TestHelpers; using Xunit; @@ -36,7 +37,7 @@ namespace Microsoft.AspNet.Server.KestrelTests kestrelEngine.Start(count: 1); var kestrelThread = kestrelEngine.Threads[0]; - var socket = new MockSocket(kestrelThread.Loop.ThreadId); + var socket = new MockSocket(kestrelThread.Loop.ThreadId, new KestrelTrace(new TestLogger())); var trace = new KestrelTrace(new TestLogger()); var socketOutput = new SocketOutput(kestrelThread, socket, trace); @@ -81,7 +82,7 @@ namespace Microsoft.AspNet.Server.KestrelTests kestrelEngine.Start(count: 1); var kestrelThread = kestrelEngine.Threads[0]; - var socket = new MockSocket(kestrelThread.Loop.ThreadId); + var socket = new MockSocket(kestrelThread.Loop.ThreadId, new KestrelTrace(new TestLogger())); var trace = new KestrelTrace(new TestLogger()); var socketOutput = new SocketOutput(kestrelThread, socket, trace); @@ -117,7 +118,7 @@ namespace Microsoft.AspNet.Server.KestrelTests private class MockSocket : UvStreamHandle { - public MockSocket(int threadId) + public MockSocket(int threadId, IKestrelTrace logger) : base(logger) { // Set the handle to something other than IntPtr.Zero // so handle.Validate doesn't fail in Libuv.write From 2041e4d08ba1b54307e38a7b630f3afd09a83fb1 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Thu, 20 Aug 2015 20:13:10 -0700 Subject: [PATCH 0240/1662] Prevent pipes from being closed prematurely on OS X and Linux This change fixes the in-process marshalling of TCP handles on Mac and Linux that is used to support having multiple threads accepting connections from multiple loops. On these two platforms, the ReadStart callback somtimes gets called with a status and pipe_pending_count equal to zero. Now when the status is zero just exit the callback without closing the pipe. This change more closely follows the example at https://nikhilm.github.io/uvbook/processes.html#sending-file-descriptors-over-pipes --- .../Http/Connection.cs | 6 ++---- .../Http/ListenerSecondary.cs | 18 ++++++++++++++++-- .../Infrastructure/Constants.cs | 3 +++ .../Networking/Libuv.cs | 9 +++++++++ .../Networking/UvPipeHandle.cs | 5 +++++ 5 files changed, 35 insertions(+), 6 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs index 49e777c59c..5fa34d141d 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs @@ -3,15 +3,13 @@ using System; using System.Diagnostics; +using Microsoft.AspNet.Server.Kestrel.Infrastructure; using Microsoft.AspNet.Server.Kestrel.Networking; namespace Microsoft.AspNet.Server.Kestrel.Http { public class Connection : ConnectionContext, IConnectionControl { - private const int EOF = -4095; - private const int ECONNRESET = -4077; - private static readonly Action _readCallback = ReadCallback; private static readonly Func _allocCallback = AllocCallback; @@ -60,7 +58,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http SocketInput.Unpin(status); var normalRead = error == null && status > 0; - var normalDone = status == 0 || status == ECONNRESET || status == EOF; + var normalDone = status == 0 || status == Constants.ECONNRESET || status == Constants.EOF; var errorDone = !(normalDone || normalRead); if (normalRead) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerSecondary.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerSecondary.cs index f0948b867b..864dee2f63 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerSecondary.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerSecondary.cs @@ -1,11 +1,12 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using Microsoft.AspNet.Server.Kestrel.Networking; using System; using System.Diagnostics; using System.Runtime.InteropServices; using System.Threading.Tasks; +using Microsoft.AspNet.Server.Kestrel.Infrastructure; +using Microsoft.AspNet.Server.Kestrel.Networking; namespace Microsoft.AspNet.Server.Kestrel.Http { @@ -60,13 +61,26 @@ namespace Microsoft.AspNet.Server.Kestrel.Http (_1, _2, _3) => buf, (_1, status2, error2, state2) => { - if (status2 == 0) + if (status2 < 0) { + if (status2 != Constants.EOF) + { + Exception ex; + Thread.Loop.Libuv.Check(status2, out ex); + // TODO: Replace Trace.WriteLine with real logging + Trace.WriteLine("DispatchPipe.ReadStart " + ex.Message); + } + DispatchPipe.Dispose(); Marshal.FreeHGlobal(ptr); return; } + if (DispatchPipe.PendingCount() == 0) + { + return; + } + var acceptSocket = CreateAcceptSocket(); try diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/Constants.cs b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/Constants.cs index 06a2bed9d6..0f4b72424e 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/Constants.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/Constants.cs @@ -7,6 +7,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure { public const int ListenBacklog = 128; + public const int EOF = -4095; + public const int ECONNRESET = -4077; + /// /// Prefix of host name used to specify Unix sockets in the configuration. /// diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/Libuv.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/Libuv.cs index a266ff8cc8..488780b93f 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/Libuv.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/Libuv.cs @@ -252,6 +252,15 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking Check(_uv_pipe_connect(req, handle, name, cb)); } + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + unsafe protected delegate int uv_pipe_pending_count(UvPipeHandle handle); + protected uv_pipe_pending_count _uv_pipe_pending_count = default(uv_pipe_pending_count); + unsafe public int pipe_pending_count(UvPipeHandle handle) + { + handle.Validate(); + return _uv_pipe_pending_count(handle); + } + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] public delegate void uv_alloc_cb(IntPtr server, int suggested_size, out uv_buf_t buf); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvPipeHandle.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvPipeHandle.cs index e110c57e6d..ea575a64dd 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvPipeHandle.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvPipeHandle.cs @@ -32,5 +32,10 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking { _uv.pipe_bind(this, name); } + + public int PendingCount() + { + return _uv.pipe_pending_count(this); + } } } From 2b2943d5b0756ab8662676e42a97d7cfea965318 Mon Sep 17 00:00:00 2001 From: Ivan Derevyanko Date: Wed, 9 Sep 2015 01:27:44 +0200 Subject: [PATCH 0241/1662] Restore static delegates --- .../Networking/UvConnectRequest.cs | 7 +++---- .../Networking/UvStreamHandle.cs | 21 ++++++++----------- .../Networking/UvWriteReq.cs | 7 +++---- 3 files changed, 15 insertions(+), 20 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvConnectRequest.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvConnectRequest.cs index 59df2af68a..bbc94bc2dc 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvConnectRequest.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvConnectRequest.cs @@ -12,14 +12,13 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking /// public class UvConnectRequest : UvRequest { - private readonly Libuv.uv_connect_cb _uv_connect_cb; + private readonly static Libuv.uv_connect_cb _uv_connect_cb = UvConnectCb; private Action _callback; private object _state; public UvConnectRequest(IKestrelTrace logger) : base (logger) { - _uv_connect_cb = UvConnectCb; } public void Init(UvLoopHandle loop) @@ -44,7 +43,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking Libuv.pipe_connect(this, pipe, name, _uv_connect_cb); } - private void UvConnectCb(IntPtr ptr, int status) + private static void UvConnectCb(IntPtr ptr, int status) { var req = FromIntPtr(ptr); req.Unpin(); @@ -67,7 +66,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking } catch (Exception ex) { - _log.LogError("UvConnectRequest", ex); + req._log.LogError("UvConnectRequest", ex); } } } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvStreamHandle.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvStreamHandle.cs index 4bc2712655..c215ae67e6 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvStreamHandle.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvStreamHandle.cs @@ -10,9 +10,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking { public abstract class UvStreamHandle : UvHandle { - private readonly Libuv.uv_connection_cb _uv_connection_cb; - private readonly Libuv.uv_alloc_cb _uv_alloc_cb; - private readonly Libuv.uv_read_cb _uv_read_cb; + private readonly static Libuv.uv_connection_cb _uv_connection_cb = UvConnectionCb; + private readonly static Libuv.uv_alloc_cb _uv_alloc_cb = UvAllocCb; + private readonly static Libuv.uv_read_cb _uv_read_cb = UvReadCb; public Action _listenCallback; public object _listenState; @@ -25,9 +25,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking protected UvStreamHandle(IKestrelTrace logger) : base(logger) { - _uv_connection_cb = UvConnectionCb; - _uv_alloc_cb = UvAllocCb; - _uv_read_cb = UvReadCb; } protected override bool ReleaseHandle() @@ -122,7 +119,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking } - private void UvConnectionCb(IntPtr handle, int status) + private static void UvConnectionCb(IntPtr handle, int status) { var stream = FromIntPtr(handle); @@ -135,12 +132,12 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking } catch (Exception ex) { - _log.LogError("UvConnectionCb", ex); + stream._log.LogError("UvConnectionCb", ex); } } - private void UvAllocCb(IntPtr handle, int suggested_size, out Libuv.uv_buf_t buf) + private static void UvAllocCb(IntPtr handle, int suggested_size, out Libuv.uv_buf_t buf) { var stream = FromIntPtr(handle); try @@ -149,13 +146,13 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking } catch (Exception ex) { - _log.LogError("UvAllocCb", ex); + stream._log.LogError("UvAllocCb", ex); buf = stream.Libuv.buf_init(IntPtr.Zero, 0); throw; } } - private void UvReadCb(IntPtr handle, int nread, ref Libuv.uv_buf_t buf) + private static void UvReadCb(IntPtr handle, int nread, ref Libuv.uv_buf_t buf) { var stream = FromIntPtr(handle); @@ -174,7 +171,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking } catch (Exception ex) { - _log.LogError("UbReadCb", ex); + stream._log.LogError("UbReadCb", ex); } } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvWriteReq.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvWriteReq.cs index feadb2de49..298bdf416f 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvWriteReq.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvWriteReq.cs @@ -14,7 +14,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking /// public class UvWriteReq : UvRequest { - private readonly Libuv.uv_write_cb _uv_write_cb; + private readonly static Libuv.uv_write_cb _uv_write_cb = UvWriteCb; private IntPtr _bufs; @@ -26,7 +26,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking public UvWriteReq(IKestrelTrace logger) : base(logger) { - _uv_write_cb = UvWriteCb; } public void Init(UvLoopHandle loop) @@ -144,7 +143,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking req._pins.Clear(); } - private void UvWriteCb(IntPtr ptr, int status) + private static void UvWriteCb(IntPtr ptr, int status) { var req = FromIntPtr(ptr); Unpin(req); @@ -167,7 +166,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking } catch (Exception ex) { - _log.LogError("UvWriteCb", ex); + req._log.LogError("UvWriteCb", ex); } } } From ac77c1121150944ae849057ecec1b67d38e8b9da Mon Sep 17 00:00:00 2001 From: Ivan Derevyanko Date: Wed, 9 Sep 2015 02:13:49 +0200 Subject: [PATCH 0242/1662] Make ConnectionCallback static again. --- src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs | 7 ++++--- .../Networking/UvConnectRequest.cs | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs index 2d2de23113..5b87d873a3 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs @@ -50,15 +50,16 @@ namespace Microsoft.AspNet.Server.Kestrel.Http /// protected abstract UvStreamHandle CreateListenSocket(string host, int port); - protected void ConnectionCallback(UvStreamHandle stream, int status, Exception error, object state) + protected static void ConnectionCallback(UvStreamHandle stream, int status, Exception error, object state) { + var listener = (Listener) state; if (error != null) { - Log.LogError("Listener.ConnectionCallback ", error); + listener.Log.LogError("Listener.ConnectionCallback ", error); } else { - ((Listener)state).OnConnection(stream, status); + listener.OnConnection(stream, status); } } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvConnectRequest.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvConnectRequest.cs index bbc94bc2dc..503cc7dfe7 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvConnectRequest.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvConnectRequest.cs @@ -43,7 +43,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking Libuv.pipe_connect(this, pipe, name, _uv_connect_cb); } - private static void UvConnectCb(IntPtr ptr, int status) + private static void UvConnectCb(IntPtr ptr, int status) { var req = FromIntPtr(ptr); req.Unpin(); From 887cf2c7bef5ae57bf46585d909750373a1de7ef Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Thu, 10 Sep 2015 02:57:49 +0100 Subject: [PATCH 0243/1662] Negative thread count fix --- src/Microsoft.AspNet.Server.Kestrel/ServerFactory.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/ServerFactory.cs b/src/Microsoft.AspNet.Server.Kestrel/ServerFactory.cs index 256b70c248..9f7ad6789b 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/ServerFactory.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/ServerFactory.cs @@ -55,7 +55,7 @@ namespace Microsoft.AspNet.Server.Kestrel disposables.Push(engine); - engine.Start(information.ThreadCount == 0 ? 1 : information.ThreadCount); + engine.Start(information.ThreadCount <= 0 ? 1 : information.ThreadCount); foreach (var address in information.Addresses) { From fea510f1d0979ca229afa4f85aaeab985400ddbf Mon Sep 17 00:00:00 2001 From: Doug Bunting Date: Wed, 9 Sep 2015 19:45:47 -0700 Subject: [PATCH 0244/1662] React to `xunit.runner.aspnet` package updates - aspnet/aspnet.xunit@5a12e89 --- .../Microsoft.AspNet.Server.KestrelTests.xproj | 3 +++ .../Microsoft.AspNet.Server.KestrelTests/Program.cs | 13 +++++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/test/Microsoft.AspNet.Server.KestrelTests/Microsoft.AspNet.Server.KestrelTests.xproj b/test/Microsoft.AspNet.Server.KestrelTests/Microsoft.AspNet.Server.KestrelTests.xproj index 5919699731..59c2109f9e 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/Microsoft.AspNet.Server.KestrelTests.xproj +++ b/test/Microsoft.AspNet.Server.KestrelTests/Microsoft.AspNet.Server.KestrelTests.xproj @@ -13,5 +13,8 @@ 2.0 + + + \ No newline at end of file diff --git a/test/Microsoft.AspNet.Server.KestrelTests/Program.cs b/test/Microsoft.AspNet.Server.KestrelTests/Program.cs index 1baf869b8c..858790c686 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/Program.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/Program.cs @@ -13,16 +13,25 @@ namespace Microsoft.AspNet.Server.KestrelTests { private readonly IApplicationEnvironment env; private readonly IServiceProvider sp; + private readonly ILibraryManager _libraryManager; + private readonly IApplicationShutdown _shutdown; - public Program(IApplicationEnvironment env, IServiceProvider sp) + public Program( + IApplicationEnvironment env, + IServiceProvider sp, + ILibraryManager libraryManager, + IApplicationShutdown shutown) { this.env = env; this.sp = sp; + _libraryManager = libraryManager; + _shutdown = shutown; } public int Main() { - return new Xunit.Runner.AspNet.Program(env, sp).Main(new string[] { + return new Xunit.Runner.Dnx.Program(env, sp, _libraryManager, _shutdown).Main(new string[] + { "-class", typeof(MultipleLoopTests).FullName }); From dda5774a8b92bee14a6bf94fa6cf6a7dafe803f1 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Thu, 10 Sep 2015 08:03:42 +0100 Subject: [PATCH 0245/1662] Throw exception if ThreadCount negative --- src/Microsoft.AspNet.Server.Kestrel/ServerFactory.cs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/ServerFactory.cs b/src/Microsoft.AspNet.Server.Kestrel/ServerFactory.cs index 9f7ad6789b..d1025b13b8 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/ServerFactory.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/ServerFactory.cs @@ -55,7 +55,14 @@ namespace Microsoft.AspNet.Server.Kestrel disposables.Push(engine); - engine.Start(information.ThreadCount <= 0 ? 1 : information.ThreadCount); + if (information.ThreadCount < 0) + { + throw new ArgumentOutOfRangeException(nameof(information.ThreadCount), + information.ThreadCount, + "ThreadCount cannot be negative"); + } + + engine.Start(information.ThreadCount == 0 ? 1 : information.ThreadCount); foreach (var address in information.Addresses) { From 0ef096b41ca63e8d21e38a578f8a9fcf5df148c4 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Wed, 9 Sep 2015 12:27:10 -0700 Subject: [PATCH 0246/1662] Increment connection id for logging --- src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs | 7 ++++++- src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs | 8 +++++--- .../SocketOutputTests.cs | 4 ++-- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs index 823ba518c0..fdccb3122b 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Threading; using Microsoft.AspNet.Server.Kestrel.Infrastructure; using Microsoft.AspNet.Server.Kestrel.Networking; using Microsoft.Framework.Logging; @@ -13,6 +14,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http private static readonly Action _readCallback = ReadCallback; private static readonly Func _allocCallback = AllocCallback; + private static long _lastConnectionId; + private readonly UvStreamHandle _socket; private Frame _frame; private long _connectionId = 0; @@ -24,6 +27,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { _socket = socket; ConnectionControl = this; + + _connectionId = Interlocked.Increment(ref _lastConnectionId); } public void Start() @@ -31,7 +36,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http Log.ConnectionStart(_connectionId); SocketInput = new SocketInput(Memory); - SocketOutput = new SocketOutput(Thread, _socket, Log); + SocketOutput = new SocketOutput(Thread, _socket, _connectionId, Log); _frame = new Frame(this); _socket.ReadStart(_allocCallback, _readCallback, this); } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs index af490063fd..3c836df3c3 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs @@ -17,6 +17,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http private readonly KestrelThread _thread; private readonly UvStreamHandle _socket; + private readonly long _connectionId; private readonly IKestrelTrace _log; // This locks access to to all of the below fields @@ -31,10 +32,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http private WriteContext _nextWriteContext; private readonly Queue _callbacksPending; - public SocketOutput(KestrelThread thread, UvStreamHandle socket, IKestrelTrace log) + public SocketOutput(KestrelThread thread, UvStreamHandle socket, long connectionId, IKestrelTrace log) { _thread = thread; _socket = socket; + _connectionId = connectionId; _log = log; _callbacksPending = new Queue(); } @@ -46,7 +48,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http Array.Copy(buffer.Array, buffer.Offset, copy, 0, buffer.Count); buffer = new ArraySegment(copy); - _log.ConnectionWrite(0, buffer.Count); + _log.ConnectionWrite(_connectionId, buffer.Count); bool triggerCallbackNow = false; @@ -155,7 +157,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http // This is called on the libuv event loop private void OnWriteCompleted(Queue> writtenBuffers, UvWriteReq req, int status, Exception error) { - _log.ConnectionWriteCallback(0, status); + _log.ConnectionWriteCallback(_connectionId, status); lock (_lockObj) { diff --git a/test/Microsoft.AspNet.Server.KestrelTests/SocketOutputTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/SocketOutputTests.cs index 7577fa25d5..6253b0651d 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/SocketOutputTests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/SocketOutputTests.cs @@ -39,7 +39,7 @@ namespace Microsoft.AspNet.Server.KestrelTests var kestrelThread = kestrelEngine.Threads[0]; var socket = new MockSocket(kestrelThread.Loop.ThreadId, new KestrelTrace(new TestLogger())); var trace = new KestrelTrace(new TestLogger()); - var socketOutput = new SocketOutput(kestrelThread, socket, trace); + var socketOutput = new SocketOutput(kestrelThread, socket, 0, trace); // I doubt _maxBytesPreCompleted will ever be over a MB. If it is, we should change this test. var bufferSize = 1048576; @@ -84,7 +84,7 @@ namespace Microsoft.AspNet.Server.KestrelTests var kestrelThread = kestrelEngine.Threads[0]; var socket = new MockSocket(kestrelThread.Loop.ThreadId, new KestrelTrace(new TestLogger())); var trace = new KestrelTrace(new TestLogger()); - var socketOutput = new SocketOutput(kestrelThread, socket, trace); + var socketOutput = new SocketOutput(kestrelThread, socket, 0, trace); var bufferSize = maxBytesPreCompleted; var buffer = new ArraySegment(new byte[bufferSize], 0, bufferSize); From 1ebf98d40d715fba0028250ca2acdf0408ab7e0d Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Wed, 9 Sep 2015 13:06:47 -0700 Subject: [PATCH 0247/1662] Log message style changes - Disabled some log messages for possibly being too verbose. - Don't log ConnectionReadFin when there is an error. --- .../Http/Connection.cs | 17 ++++++---- .../Infrastructure/IKestrelTrace.cs | 4 ++- .../Infrastructure/KestrelTrace.cs | 34 ++++++++++++------- 3 files changed, 34 insertions(+), 21 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs index fdccb3122b..2524516181 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs @@ -72,7 +72,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } else if (normalDone || errorDone) { - Log.ConnectionReadFin(_connectionId); SocketInput.RemoteIntakeFin = true; _socket.ReadStop(); @@ -80,6 +79,10 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { Log.LogError("Connection.OnRead", error); } + else + { + Log.ConnectionReadFin(_connectionId); + } } @@ -118,19 +121,19 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } _connectionState = ConnectionState.Shutdown; - Log.ConnectionWriteFin(_connectionId, 0); + Log.ConnectionWriteFin(_connectionId); Thread.Post( state => { - Log.ConnectionWriteFin(_connectionId, 1); var self = (Connection)state; - var shutdown = new UvShutdownReq(Log); + var shutdown = new UvShutdownReq(self.Log); shutdown.Init(self.Thread.Loop); - shutdown.Shutdown(self._socket, (req, status, _) => + shutdown.Shutdown(self._socket, (req, status, state2) => { - Log.ConnectionWriteFin(_connectionId, 1); + var self2 = (Connection)state2; + self2.Log.ConnectionWroteFin(_connectionId, status); req.Dispose(); - }, null); + }, this); }, this); break; diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/IKestrelTrace.cs b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/IKestrelTrace.cs index 478b573fe8..cb825bac39 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/IKestrelTrace.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/IKestrelTrace.cs @@ -16,7 +16,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure void ConnectionReadFin(long connectionId); - void ConnectionWriteFin(long connectionId, int step); + void ConnectionWriteFin(long connectionId); + + void ConnectionWroteFin(long connectionId, int status); void ConnectionKeepAlive(long connectionId); diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelTrace.cs b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelTrace.cs index c9ce6bb820..2a148ed302 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelTrace.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelTrace.cs @@ -21,57 +21,65 @@ namespace Microsoft.AspNet.Server.Kestrel public void ConnectionStart(long connectionId) { - _logger.LogDebug(13, $"{nameof(ConnectionStart)} -> Id: {connectionId}"); + _logger.LogDebug(1, @"Connection id ""{ConnectionId}"" started.", connectionId); } public void ConnectionStop(long connectionId) { - _logger.LogDebug(14, $"{nameof(ConnectionStop)} -> Id: {connectionId}"); + _logger.LogDebug(2, @"Connection id ""{ConnectionId}"" stopped.", connectionId); } - public void ConnectionRead(long connectionId, int status) + public void ConnectionRead(long connectionId, int count) { - _logger.LogDebug(4, $"{nameof(ConnectionRead)} -> Id: {connectionId}, Status: {status}"); + // Don't log for now since this could be *too* verbose. + //_logger.LogVerbose(3, @"Connection id ""{ConnectionId}"" received ""{Count}"" bytes.", connectionId, count); } public void ConnectionPause(long connectionId) { - _logger.LogDebug(5, $"{nameof(ConnectionPause)} -> Id: {connectionId}"); + _logger.LogDebug(4, @"Connection id ""{ConnectionId}"" paused.", connectionId); } public void ConnectionResume(long connectionId) { - _logger.LogDebug(6, $"{nameof(ConnectionResume)} -> Id: {connectionId}"); + _logger.LogDebug(5, @"Connection id ""{ConnectionId}"" resumed.", connectionId); } public void ConnectionReadFin(long connectionId) { - _logger.LogDebug(7, $"{nameof(ConnectionReadFin)} -> Id: {connectionId}"); + _logger.LogDebug(6, @"Connection id ""{ConnectionId}"" received FIN.", connectionId); } - public void ConnectionWriteFin(long connectionId, int step) + public void ConnectionWriteFin(long connectionId) { - _logger.LogDebug(8, $"{nameof(ConnectionWriteFin)} -> Id: {connectionId}, Step: {step}"); + _logger.LogDebug(7, @"Connection id ""{ConnectionId}"" sending FIN."); + } + + public void ConnectionWroteFin(long connectionId, int status) + { + _logger.LogDebug(8, @"Connection id ""{ConnectionId}"" sent FIN with status ""{Status}"".", status); } public void ConnectionKeepAlive(long connectionId) { - _logger.LogDebug(9, $"{nameof(ConnectionKeepAlive)} -> Id: {connectionId}"); + _logger.LogDebug(9, @"Connection id ""{ConnectionId}"" completed keep alive response.", connectionId); } public void ConnectionDisconnect(long connectionId) { - _logger.LogDebug(10, $"{nameof(ConnectionDisconnect)} -> Id: {connectionId}"); + _logger.LogDebug(10, @"Connection id ""{ConnectionId}"" disconnected.", connectionId); } public void ConnectionWrite(long connectionId, int count) { - _logger.LogDebug(11, $"{nameof(ConnectionWrite)} -> Id: {connectionId}, Count: {count}"); + // Don't log for now since this could be *too* verbose. + //_logger.LogVerbose(11, @"Connection id ""{ConnectionId}"" sent ""{Count}"" bytes.", connectionId, count); } public void ConnectionWriteCallback(long connectionId, int status) { - _logger.LogDebug(12, $"{nameof(ConnectionWriteCallback)} -> Id: {connectionId}, Status: {status}"); + // Don't log for now since this could be *too* verbose. + //_logger.LogVerbose(12, @"Connection id ""{ConnectionId}"" finished write with status ""{Status}"".", connectionId, status); } public void Log(LogLevel logLevel, int eventId, object state, Exception exception, Func formatter) From ec88e57f67d27e198a3d9f388ae2c22b5aa1dbe0 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Thu, 10 Sep 2015 11:39:14 -0700 Subject: [PATCH 0248/1662] Remove commented code in KestrelTrace --- .../Infrastructure/KestrelTrace.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelTrace.cs b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelTrace.cs index 2a148ed302..5b758a02b2 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelTrace.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelTrace.cs @@ -32,7 +32,7 @@ namespace Microsoft.AspNet.Server.Kestrel public void ConnectionRead(long connectionId, int count) { // Don't log for now since this could be *too* verbose. - //_logger.LogVerbose(3, @"Connection id ""{ConnectionId}"" received ""{Count}"" bytes.", connectionId, count); + // Reserved: Event ID 3 } public void ConnectionPause(long connectionId) @@ -73,13 +73,13 @@ namespace Microsoft.AspNet.Server.Kestrel public void ConnectionWrite(long connectionId, int count) { // Don't log for now since this could be *too* verbose. - //_logger.LogVerbose(11, @"Connection id ""{ConnectionId}"" sent ""{Count}"" bytes.", connectionId, count); + // Reserved: Event ID 11 } public void ConnectionWriteCallback(long connectionId, int status) { // Don't log for now since this could be *too* verbose. - //_logger.LogVerbose(12, @"Connection id ""{ConnectionId}"" finished write with status ""{Status}"".", connectionId, status); + // Reserved: Event ID 12 } public void Log(LogLevel logLevel, int eventId, object state, Exception exception, Func formatter) From 958cc3eca379d917d7c71832389a11a42710c8af Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Thu, 10 Sep 2015 12:40:16 -0700 Subject: [PATCH 0249/1662] Add missing arguments to LogDebug arguments in KestrelTrace --- .../Infrastructure/KestrelTrace.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelTrace.cs b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelTrace.cs index 5b758a02b2..5fba4c7f01 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelTrace.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelTrace.cs @@ -52,12 +52,12 @@ namespace Microsoft.AspNet.Server.Kestrel public void ConnectionWriteFin(long connectionId) { - _logger.LogDebug(7, @"Connection id ""{ConnectionId}"" sending FIN."); + _logger.LogDebug(7, @"Connection id ""{ConnectionId}"" sending FIN.", connectionId); } public void ConnectionWroteFin(long connectionId, int status) { - _logger.LogDebug(8, @"Connection id ""{ConnectionId}"" sent FIN with status ""{Status}"".", status); + _logger.LogDebug(8, @"Connection id ""{ConnectionId}"" sent FIN with status ""{Status}"".", connectionId, status); } public void ConnectionKeepAlive(long connectionId) From 78de14d24868fd1b44a7335b30d9a2064c984516 Mon Sep 17 00:00:00 2001 From: Pranav K Date: Thu, 10 Sep 2015 18:15:27 -0700 Subject: [PATCH 0250/1662] Adding NeutralResourcesLanguageAttribute --- .../Properties/AssemblyInfo.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Properties/AssemblyInfo.cs b/src/Microsoft.AspNet.Server.Kestrel/Properties/AssemblyInfo.cs index 573f5c3634..7799e552b4 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Properties/AssemblyInfo.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Properties/AssemblyInfo.cs @@ -2,7 +2,9 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Reflection; +using System.Resources; using System.Runtime.CompilerServices; [assembly: InternalsVisibleTo("Microsoft.AspNet.Server.KestrelTests")] -[assembly: AssemblyMetadata("Serviceable", "True")] \ No newline at end of file +[assembly: AssemblyMetadata("Serviceable", "True")] +[assembly: NeutralResourcesLanguage("en-us")] From 2e225b0db695728a1ad8c47359ce5fa07424b1d0 Mon Sep 17 00:00:00 2001 From: Chris R Date: Fri, 11 Sep 2015 14:07:18 -0700 Subject: [PATCH 0251/1662] Hosting#331 Add IServerAddressesFeature. --- .../SampleApp/Microsoft.AspNet.Hosting.ini | 3 -- samples/SampleApp/project.json | 3 +- .../KestrelServerInformation.cs | 26 +++++--------- .../ServerAddress.cs | 34 ++++++++++++++++++ .../ServerFactory.cs | 35 ++++++++++++++----- 5 files changed, 70 insertions(+), 31 deletions(-) delete mode 100644 samples/SampleApp/Microsoft.AspNet.Hosting.ini diff --git a/samples/SampleApp/Microsoft.AspNet.Hosting.ini b/samples/SampleApp/Microsoft.AspNet.Hosting.ini deleted file mode 100644 index 882b9e0262..0000000000 --- a/samples/SampleApp/Microsoft.AspNet.Hosting.ini +++ /dev/null @@ -1,3 +0,0 @@ - -Server = Microsoft.AspNet.Server.Kestrel -Server.Urls = http://localhost:5000/ diff --git a/samples/SampleApp/project.json b/samples/SampleApp/project.json index 2e0dd6f9c3..b77f0a7dd2 100644 --- a/samples/SampleApp/project.json +++ b/samples/SampleApp/project.json @@ -15,7 +15,6 @@ "commands": { "run": "Microsoft.AspNet.Server.Kestrel", "run-socket": "Microsoft.AspNet.Server.Kestrel --server.urls http://unix:/tmp/kestrel-test.sock", - "kestrel": "Microsoft.AspNet.Server.Kestrel", - "web": "Microsoft.AspNet.Hosting" + "kestrel": "Microsoft.AspNet.Server.Kestrel" } } diff --git a/src/Microsoft.AspNet.Server.Kestrel/KestrelServerInformation.cs b/src/Microsoft.AspNet.Server.Kestrel/KestrelServerInformation.cs index a153525ea1..597c45a4d4 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/KestrelServerInformation.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/KestrelServerInformation.cs @@ -3,35 +3,27 @@ using System; using System.Collections.Generic; +using Microsoft.AspNet.Server.Features; using Microsoft.Framework.Configuration; namespace Microsoft.AspNet.Server.Kestrel { - public class KestrelServerInformation : IKestrelServerInformation + public class KestrelServerInformation : IKestrelServerInformation, IServerAddressesFeature { - public KestrelServerInformation() - { - Addresses = new List(); - } - - public IList Addresses { get; private set; } + public ICollection Addresses { get; } = new List(); public int ThreadCount { get; set; } public void Initialize(IConfiguration configuration) { - var urls = configuration["server.urls"]; - if (string.IsNullOrEmpty(urls)) - { - urls = "http://+:5000/"; - } + var urls = configuration["server.urls"] ?? string.Empty; foreach (var url in urls.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries)) { - var address = ServerAddress.FromUrl(url); - if (address != null) - { - Addresses.Add(address); - } + Addresses.Add(url); + } + if (Addresses.Count == 0) + { + Addresses.Add("http://+:5000/"); } } } diff --git a/src/Microsoft.AspNet.Server.Kestrel/ServerAddress.cs b/src/Microsoft.AspNet.Server.Kestrel/ServerAddress.cs index 44fcf94d5c..4599e0a061 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/ServerAddress.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/ServerAddress.cs @@ -14,6 +14,29 @@ namespace Microsoft.AspNet.Server.Kestrel public int Port { get; private set; } public string Scheme { get; private set; } + public override string ToString() + { + return Scheme.ToLowerInvariant() + "://" + Host.ToLowerInvariant() + ":" + Port.ToString(CultureInfo.InvariantCulture) + Path.ToLowerInvariant(); + } + + public override int GetHashCode() + { + return ToString().GetHashCode(); + } + + public override bool Equals(object obj) + { + var other = obj as ServerAddress; + if (other == null) + { + return false; + } + return string.Equals(Scheme, other.Scheme, StringComparison.OrdinalIgnoreCase) + && string.Equals(Host, other.Host, StringComparison.OrdinalIgnoreCase) + && Port == other.Port + && string.Equals(Path, other.Path, StringComparison.OrdinalIgnoreCase); + } + public static ServerAddress FromUrl(string url) { url = url ?? string.Empty; @@ -21,6 +44,17 @@ namespace Microsoft.AspNet.Server.Kestrel int schemeDelimiterStart = url.IndexOf("://", StringComparison.Ordinal); if (schemeDelimiterStart < 0) { + int port; + if (int.TryParse(url, NumberStyles.None, CultureInfo.InvariantCulture, out port)) + { + return new ServerAddress() + { + Scheme = "http", + Host = "+", + Port = port, + Path = "/" + }; + } return null; } int schemeDelimiterEnd = schemeDelimiterStart + "://".Length; diff --git a/src/Microsoft.AspNet.Server.Kestrel/ServerFactory.cs b/src/Microsoft.AspNet.Server.Kestrel/ServerFactory.cs index d1025b13b8..73201020d4 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/ServerFactory.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/ServerFactory.cs @@ -6,6 +6,7 @@ using System.Collections.Generic; using System.Threading.Tasks; using Microsoft.AspNet.Hosting.Server; using Microsoft.AspNet.Http.Features; +using Microsoft.AspNet.Server.Features; using Microsoft.Dnx.Runtime; using Microsoft.Framework.Configuration; using Microsoft.Framework.Logging; @@ -34,6 +35,7 @@ namespace Microsoft.AspNet.Server.Kestrel information.Initialize(configuration); var serverFeatures = new FeatureCollection(); serverFeatures.Set(information); + serverFeatures.Set(information); return serverFeatures; } @@ -63,18 +65,33 @@ namespace Microsoft.AspNet.Server.Kestrel } engine.Start(information.ThreadCount == 0 ? 1 : information.ThreadCount); + bool atLeastOneListener = false; foreach (var address in information.Addresses) { - disposables.Push(engine.CreateServer( - address.Scheme, - address.Host, - address.Port, - async frame => - { - var request = new ServerRequest(frame); - await application.Invoke(request.Features).ConfigureAwait(false); - })); + var parsedAddress = ServerAddress.FromUrl(address); + if (parsedAddress == null) + { + throw new FormatException("Unrecognized listening address: " + address); + } + else + { + atLeastOneListener = true; + disposables.Push(engine.CreateServer( + parsedAddress.Scheme, + parsedAddress.Host, + parsedAddress.Port, + async frame => + { + var request = new ServerRequest(frame); + await application.Invoke(request.Features).ConfigureAwait(false); + })); + } + } + + if (!atLeastOneListener) + { + throw new InvalidOperationException("No recognized listening addresses were configured."); } return disposer; From f14af1f4098f42aa77b0aadc1b67d5dcbbad9a72 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Thu, 10 Sep 2015 12:23:56 -0700 Subject: [PATCH 0252/1662] Don't swallow too many exceptions - Swallowing too many exceptions can end up hiding issues in Kestrel itself. It's better to let the process die. - If we want to handle certain exceptions we should be as specific as possible with our try/catch blocks. --- src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs | 1 + .../Infrastructure/KestrelThread.cs | 2 ++ .../Networking/UvConnectRequest.cs | 1 + .../Networking/UvStreamHandle.cs | 2 ++ src/Microsoft.AspNet.Server.Kestrel/Networking/UvWriteReq.cs | 1 + 5 files changed, 7 insertions(+) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs index 2524516181..d33409dbeb 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs @@ -93,6 +93,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http catch (Exception ex) { Log.LogError("Connection._frame.Consume ", ex); + throw; } } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs index 1af6b04549..85683f2db1 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs @@ -276,6 +276,7 @@ namespace Microsoft.AspNet.Server.Kestrel else { _log.LogError("KestrelThread.DoPostWork", ex); + throw; } } } @@ -299,6 +300,7 @@ namespace Microsoft.AspNet.Server.Kestrel catch (Exception ex) { _log.LogError("KestrelThread.DoPostCloseHandle", ex); + throw; } } } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvConnectRequest.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvConnectRequest.cs index 503cc7dfe7..c01f19eb75 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvConnectRequest.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvConnectRequest.cs @@ -67,6 +67,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking catch (Exception ex) { req._log.LogError("UvConnectRequest", ex); + throw; } } } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvStreamHandle.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvStreamHandle.cs index c215ae67e6..574e1b466d 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvStreamHandle.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvStreamHandle.cs @@ -133,6 +133,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking catch (Exception ex) { stream._log.LogError("UvConnectionCb", ex); + throw; } } @@ -172,6 +173,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking catch (Exception ex) { stream._log.LogError("UbReadCb", ex); + throw; } } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvWriteReq.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvWriteReq.cs index 298bdf416f..1e80f1ffb2 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvWriteReq.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvWriteReq.cs @@ -167,6 +167,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking catch (Exception ex) { req._log.LogError("UvWriteCb", ex); + throw; } } } From 2d01f2752b00e3c89770e090030cd1172b1bbf0f Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Thu, 10 Sep 2015 14:45:26 -0700 Subject: [PATCH 0253/1662] Catch and log uv_accept errors - This is also what is done by node.js - "tcp, pipe: don't assert on uv_accept() errors (Ben Noordhuis)" https://github.com/nodejs/node/commit/0685707bc643250de297b59f4f58878d4c17292e --- .../Http/ListenerPrimary.cs | 10 +++++++--- .../Http/ListenerSecondary.cs | 2 +- .../Http/PipeListener.cs | 13 ++++++++++++- .../Http/PipeListenerPrimary.cs | 13 ++++++++++++- .../Http/TcpListener.cs | 13 ++++++++++++- .../Http/TcpListenerPrimary.cs | 13 ++++++++++++- .../Networking/Libuv.cs | 2 +- .../Networking/UvException.cs | 12 ++++++++++++ 8 files changed, 69 insertions(+), 9 deletions(-) create mode 100644 src/Microsoft.AspNet.Server.Kestrel/Networking/UvException.cs diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerPrimary.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerPrimary.cs index 0010c2d60f..df83d66695 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerPrimary.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerPrimary.cs @@ -1,11 +1,12 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using Microsoft.AspNet.Server.Kestrel.Infrastructure; -using Microsoft.AspNet.Server.Kestrel.Networking; using System; using System.Collections.Generic; using System.Threading.Tasks; +using Microsoft.AspNet.Server.Kestrel.Infrastructure; +using Microsoft.AspNet.Server.Kestrel.Networking; +using Microsoft.Framework.Logging; namespace Microsoft.AspNet.Server.Kestrel.Http { @@ -56,15 +57,18 @@ namespace Microsoft.AspNet.Server.Kestrel.Http var dispatchPipe = new UvPipeHandle(Log); dispatchPipe.Init(Thread.Loop, true); + try { pipe.Accept(dispatchPipe); } - catch (Exception) + catch (UvException ex) { dispatchPipe.Dispose(); + Log.LogError("ListenerPrimary.OnListenPipe", ex); return; } + _dispatchPipes.Add(dispatchPipe); } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerSecondary.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerSecondary.cs index 3a0d2e667c..0334c39d68 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerSecondary.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerSecondary.cs @@ -86,7 +86,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { DispatchPipe.Accept(acceptSocket); } - catch (Exception ex) + catch (UvException ex) { Log.LogError("DispatchPipe.Accept", ex); acceptSocket.Dispose(); diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/PipeListener.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/PipeListener.cs index 62e12fc9a7..a63e3a547b 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/PipeListener.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/PipeListener.cs @@ -1,8 +1,10 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; using Microsoft.AspNet.Server.Kestrel.Infrastructure; using Microsoft.AspNet.Server.Kestrel.Networking; +using Microsoft.Framework.Logging; namespace Microsoft.AspNet.Server.Kestrel.Http { @@ -36,7 +38,16 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { var acceptSocket = new UvPipeHandle(Log); acceptSocket.Init(Thread.Loop, false); - listenSocket.Accept(acceptSocket); + + try + { + listenSocket.Accept(acceptSocket); + } + catch (UvException ex) + { + Log.LogError("PipeListener.OnConnection", ex); + return; + } DispatchConnection(acceptSocket); } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/PipeListenerPrimary.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/PipeListenerPrimary.cs index 96691a2b8d..7b39014487 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/PipeListenerPrimary.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/PipeListenerPrimary.cs @@ -1,8 +1,10 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; using Microsoft.AspNet.Server.Kestrel.Infrastructure; using Microsoft.AspNet.Server.Kestrel.Networking; +using Microsoft.Framework.Logging; namespace Microsoft.AspNet.Server.Kestrel.Http { @@ -36,7 +38,16 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { var acceptSocket = new UvPipeHandle(Log); acceptSocket.Init(Thread.Loop, false); - listenSocket.Accept(acceptSocket); + + try + { + listenSocket.Accept(acceptSocket); + } + catch (UvException ex) + { + Log.LogError("ListenerPrimary.OnConnection", ex); + return; + } DispatchConnection(acceptSocket); } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/TcpListener.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/TcpListener.cs index 4fa374c0fb..2b8e4ea527 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/TcpListener.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/TcpListener.cs @@ -1,9 +1,11 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; using System.Net; using Microsoft.AspNet.Server.Kestrel.Infrastructure; using Microsoft.AspNet.Server.Kestrel.Networking; +using Microsoft.Framework.Logging; namespace Microsoft.AspNet.Server.Kestrel.Http { @@ -37,7 +39,16 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { var acceptSocket = new UvTcpHandle(Log); acceptSocket.Init(Thread.Loop, Thread.QueueCloseHandle); - listenSocket.Accept(acceptSocket); + + try + { + listenSocket.Accept(acceptSocket); + } + catch (UvException ex) + { + Log.LogError("TcpListener.OnConnection", ex); + return; + } DispatchConnection(acceptSocket); } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/TcpListenerPrimary.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/TcpListenerPrimary.cs index 2a80f3caee..af4495784d 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/TcpListenerPrimary.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/TcpListenerPrimary.cs @@ -1,9 +1,11 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; using System.Net; using Microsoft.AspNet.Server.Kestrel.Infrastructure; using Microsoft.AspNet.Server.Kestrel.Networking; +using Microsoft.Framework.Logging; namespace Microsoft.AspNet.Server.Kestrel.Http { @@ -37,7 +39,16 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { var acceptSocket = new UvTcpHandle(Log); acceptSocket.Init(Thread.Loop, Thread.QueueCloseHandle); - listenSocket.Accept(acceptSocket); + + try + { + listenSocket.Accept(acceptSocket); + } + catch (UvException ex) + { + Log.LogError("TcpListenerPrimary.OnConnection", ex); + return; + } DispatchConnection(acceptSocket); } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/Libuv.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/Libuv.cs index 488780b93f..254483454d 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/Libuv.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/Libuv.cs @@ -73,7 +73,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking { var errorName = err_name(statusCode); var errorDescription = strerror(statusCode); - error = new Exception("Error " + statusCode + " " + errorName + " " + errorDescription); + error = new UvException("Error " + statusCode + " " + errorName + " " + errorDescription); } else { diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvException.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvException.cs new file mode 100644 index 0000000000..2a6d5bce1d --- /dev/null +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvException.cs @@ -0,0 +1,12 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; + +namespace Microsoft.AspNet.Server.Kestrel.Networking +{ + public class UvException : Exception + { + public UvException(string message) : base(message) { } + } +} From 47323a88e1c58f7e57c6f8c641415b2a992d22aa Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Mon, 14 Sep 2015 15:42:42 -0700 Subject: [PATCH 0254/1662] Surface errors from Listener.StartAsync better If CreateListenSocket fails, surface the original error instead of throwing a NullReferenceException from Listener.Dispose(). #185 --- src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs index 5b87d873a3..316c5318d9 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs @@ -82,7 +82,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http // If the event loop isn't running and we try to wait on this Post // to complete, then KestrelEngine will never be disposed and // the exception that stopped the event loop will never be surfaced. - if (Thread.FatalError == null) + if (Thread.FatalError == null && ListenSocket != null) { var tcs = new TaskCompletionSource(); Thread.Post( From 6f8c040cfe4714d32d2db9272b2ee56726886adb Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Thu, 17 Sep 2015 00:51:43 -0700 Subject: [PATCH 0255/1662] Fix false positive in Standards Police warning warning SP1004 - "warning SP1004: namespaces not alphabetized" - Any using statement can come after "using System;" --- .../Microsoft.StandardsPolice/StandardsPoliceCompileModule.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tools/Microsoft.StandardsPolice/StandardsPoliceCompileModule.cs b/tools/Microsoft.StandardsPolice/StandardsPoliceCompileModule.cs index 9be039be75..5de3961d58 100644 --- a/tools/Microsoft.StandardsPolice/StandardsPoliceCompileModule.cs +++ b/tools/Microsoft.StandardsPolice/StandardsPoliceCompileModule.cs @@ -66,6 +66,10 @@ namespace Microsoft.StandardsPolice { acceptableOrder = true; } + if (!acceptableOrder && priorUsingDirective.Name.ToString() == "System") + { + acceptableOrder = true; + } if (!acceptableOrder && priorUsingDirective.Name.ToString().StartsWith("System.") && !usingDirective.Name.ToString().StartsWith("System.")) From 3470c6206a0a9c7a4ba5b22e00a03567409cbe27 Mon Sep 17 00:00:00 2001 From: "N. Taylor Mullen" Date: Thu, 17 Sep 2015 18:32:59 -0700 Subject: [PATCH 0256/1662] Update nuget.exe and corresponding feeds to v3. --- NuGet.Config => NuGet.config | 2 +- build.cmd | 13 +++++++------ build.sh | 12 +++++++----- 3 files changed, 15 insertions(+), 12 deletions(-) rename NuGet.Config => NuGet.config (89%) diff --git a/NuGet.Config b/NuGet.config similarity index 89% rename from NuGet.Config rename to NuGet.config index 41705755cf..297aa0ae6c 100644 --- a/NuGet.Config +++ b/NuGet.config @@ -1,7 +1,7 @@ - + diff --git a/build.cmd b/build.cmd index 0dee2c2608..177997c42e 100644 --- a/build.cmd +++ b/build.cmd @@ -2,14 +2,15 @@ cd %~dp0 SETLOCAL -SET CACHED_NUGET=%LocalAppData%\NuGet\NuGet.exe +SET NUGET_VERSION=latest +SET CACHED_NUGET=%LocalAppData%\NuGet\nuget.%NUGET_VERSION%.exe SET BUILDCMD_KOREBUILD_VERSION="" SET BUILDCMD_DNX_VERSION="" IF EXIST %CACHED_NUGET% goto copynuget echo Downloading latest version of NuGet.exe... IF NOT EXIST %LocalAppData%\NuGet md %LocalAppData%\NuGet -@powershell -NoProfile -ExecutionPolicy unrestricted -Command "$ProgressPreference = 'SilentlyContinue'; Invoke-WebRequest 'https://www.nuget.org/nuget.exe' -OutFile '%CACHED_NUGET%'" +@powershell -NoProfile -ExecutionPolicy unrestricted -Command "$ProgressPreference = 'SilentlyContinue'; Invoke-WebRequest 'https://dist.nuget.org/win-x86-commandline/%NUGET_VERSION%/nuget.exe' -OutFile '%CACHED_NUGET%'" :copynuget IF EXIST .nuget\nuget.exe goto restore @@ -19,11 +20,11 @@ copy %CACHED_NUGET% .nuget\nuget.exe > nul :restore IF EXIST packages\KoreBuild goto run IF %BUILDCMD_KOREBUILD_VERSION%=="" ( - .nuget\NuGet.exe install KoreBuild -ExcludeVersion -o packages -nocache -pre + .nuget\nuget.exe install KoreBuild -ExcludeVersion -o packages -nocache -pre ) ELSE ( - .nuget\NuGet.exe install KoreBuild -version %BUILDCMD_KOREBUILD_VERSION% -ExcludeVersion -o packages -nocache -pre + .nuget\nuget.exe install KoreBuild -version %BUILDCMD_KOREBUILD_VERSION% -ExcludeVersion -o packages -nocache -pre ) -.nuget\NuGet.exe install Sake -ExcludeVersion -Source https://www.nuget.org/api/v2/ -Out packages +.nuget\nuget.exe install Sake -ExcludeVersion -Out packages IF "%SKIP_DNX_INSTALL%"=="1" goto run IF %BUILDCMD_DNX_VERSION%=="" ( @@ -35,4 +36,4 @@ CALL packages\KoreBuild\build\dnvm install default -runtime CoreCLR -arch x86 :run CALL packages\KoreBuild\build\dnvm use default -runtime CLR -arch x86 -packages\Sake\tools\Sake.exe -I build -I packages\KoreBuild\build -f makefile.shade %* \ No newline at end of file +packages\Sake\tools\Sake.exe -I packages\KoreBuild\build -f makefile.shade %* \ No newline at end of file diff --git a/build.sh b/build.sh index 68c3e8cb52..0c66139817 100755 --- a/build.sh +++ b/build.sh @@ -10,21 +10,23 @@ else fi fi mkdir -p $cachedir +nugetVersion=latest +cachePath=$cachedir/nuget.$nugetVersion.exe -url=https://www.nuget.org/nuget.exe +url=https://dist.nuget.org/win-x86-commandline/$nugetVersion/nuget.exe -if test ! -f $cachedir/nuget.exe; then - wget -O $cachedir/nuget.exe $url 2>/dev/null || curl -o $cachedir/nuget.exe --location $url /dev/null +if test ! -f $cachePath; then + wget -O $cachePath $url 2>/dev/null || curl -o $cachePath --location $url /dev/null fi if test ! -e .nuget; then mkdir .nuget - cp $cachedir/nuget.exe .nuget/nuget.exe + cp $cachePath .nuget/nuget.exe fi if test ! -d packages/KoreBuild; then mono .nuget/nuget.exe install KoreBuild -ExcludeVersion -o packages -nocache -pre - mono .nuget/nuget.exe install Sake -ExcludeVersion -Source https://www.nuget.org/api/v2/ -Out packages + mono .nuget/nuget.exe install Sake -ExcludeVersion -Out packages fi if ! type dnvm > /dev/null 2>&1; then From 891b991a34892c86eb904dbb7ad0825b211f3be8 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Sat, 19 Sep 2015 03:59:58 -0700 Subject: [PATCH 0257/1662] Use new packInclude feature to include native assets - Now Kestrel won't break when people overwrite the build.cmd --- KestrelHttpServer.sln | 1 - build/_custom-goals.shade | 40 -------- .../project.json | 95 ++++++++++--------- 3 files changed, 50 insertions(+), 86 deletions(-) delete mode 100644 build/_custom-goals.shade diff --git a/KestrelHttpServer.sln b/KestrelHttpServer.sln index 02d3731464..3de96d251c 100644 --- a/KestrelHttpServer.sln +++ b/KestrelHttpServer.sln @@ -9,7 +9,6 @@ Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.Server.Kes EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{7972A5D6-3385-4127-9277-428506DD44FF}" ProjectSection(SolutionItems) = preProject - build\_custom-goals.shade = build\_custom-goals.shade build.cmd = build.cmd global.json = global.json makefile.shade = makefile.shade diff --git a/build/_custom-goals.shade b/build/_custom-goals.shade deleted file mode 100644 index 78e64e8b7d..0000000000 --- a/build/_custom-goals.shade +++ /dev/null @@ -1,40 +0,0 @@ -use assembly="System.IO.Compression.FileSystem, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" -use assembly="System.IO.Compression, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" -use namespace="System.IO" -use namespace="System.IO.Compression" -use namespace="System.Net" - -#add-files target="compile" - var each='var nupkgFile in Files.Include("artifacts\\build\\Microsoft.AspNet.Server.Kestrel.*.nupkg").Where(x=>!x.EndsWith("symbols.nupkg"))' - log info='Adding content to ${nupkgFile}' - var archive='${ZipFile.Open(nupkgFile, ZipArchiveMode.Update)}' - @{ - archive.CreateEntryFromFile( - "src/Microsoft.AspNet.Server.Kestrel/native/windows/amd64/libuv.dll", - "native/windows/amd64/libuv.dll"); - archive.CreateEntryFromFile( - "src/Microsoft.AspNet.Server.Kestrel/native/windows/x86/libuv.dll", - "native/windows/x86/libuv.dll"); - archive.CreateEntryFromFile( - "src/Microsoft.AspNet.Server.Kestrel/native/darwin/universal/libuv.dylib", - "native/darwin/universal/libuv.dylib"); - - XDocument doc; - var entry = archive.GetEntry("[Content_Types].xml"); - using (var stream = entry.Open()) - { - doc = XDocument.Load(stream); - } - doc.Root.Add( - new XElement( - XName.Get("Default", "http://schemas.openxmlformats.org/package/2006/content-types"), - new XAttribute("Extension", "dylib"), - new XAttribute("ContentType", "application/octet") - )); - using (var stream = entry.Open()) - { - doc.Save(stream); - } - - archive.Dispose(); - } diff --git a/src/Microsoft.AspNet.Server.Kestrel/project.json b/src/Microsoft.AspNet.Server.Kestrel/project.json index 26e0dc886a..eff997df0e 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/project.json +++ b/src/Microsoft.AspNet.Server.Kestrel/project.json @@ -1,48 +1,53 @@ { - "version": "1.0.0-*", - "description": "ASP.NET 5 cross platform development web server.", - "repository": { - "type": "git", - "url": "git://github.com/aspnet/kestrelhttpserver" - }, - "dependencies": { - "Microsoft.AspNet.Hosting": "1.0.0-*", - "Microsoft.Dnx.Runtime.Abstractions": "1.0.0-*", - "Microsoft.Framework.Logging.Abstractions": "1.0.0-*", - "Microsoft.StandardsPolice": { - "version": "1.0.0-*", - "type": "build" - } - }, - "frameworks": { - "dnx451": { }, - "dnxcore50": { - "dependencies": { - "System.Collections": "4.0.11-beta-*", - "System.Diagnostics.Debug": "4.0.11-beta-*", - "System.Diagnostics.TraceSource": "4.0.0-beta-*", - "System.Diagnostics.Tracing": "4.0.21-beta-*", - "System.Globalization": "4.0.11-beta-*", - "System.IO": "4.0.11-beta-*", - "System.Linq": "4.0.1-beta-*", - "System.Net.Primitives": "4.0.11-beta-*", - "System.Runtime.Extensions": "4.0.11-beta-*", - "System.Runtime.InteropServices": "4.0.21-beta-*", - "System.Text.Encoding": "4.0.11-beta-*", - "System.Threading": "4.0.11-beta-*", - "System.Threading.Tasks": "4.0.11-beta-*", - "System.Threading.Thread": "4.0.0-beta-*", - "System.Threading.ThreadPool": "4.0.10-beta-*" - } - } - }, - "compilationOptions": { - "allowUnsafe": true - }, - "scripts": { - "prepare": [ - "dnu restore ../../tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode", - "dnx --appbase ../../tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode Microsoft.Dnx.ApplicationHost run Http/FrameHeaders.Generated.cs" - ] + "version": "1.0.0-*", + "description": "ASP.NET 5 cross platform development web server.", + "repository": { + "type": "git", + "url": "git://github.com/aspnet/kestrelhttpserver" + }, + "dependencies": { + "Microsoft.AspNet.Hosting": "1.0.0-*", + "Microsoft.Dnx.Runtime.Abstractions": "1.0.0-*", + "Microsoft.Framework.Logging.Abstractions": "1.0.0-*", + "Microsoft.StandardsPolice": { + "version": "1.0.0-*", + "type": "build" } + }, + "frameworks": { + "dnx451": { }, + "dnxcore50": { + "dependencies": { + "System.Collections": "4.0.11-beta-*", + "System.Diagnostics.Debug": "4.0.11-beta-*", + "System.Diagnostics.TraceSource": "4.0.0-beta-*", + "System.Diagnostics.Tracing": "4.0.21-beta-*", + "System.Globalization": "4.0.11-beta-*", + "System.IO": "4.0.11-beta-*", + "System.Linq": "4.0.1-beta-*", + "System.Net.Primitives": "4.0.11-beta-*", + "System.Runtime.Extensions": "4.0.11-beta-*", + "System.Runtime.InteropServices": "4.0.21-beta-*", + "System.Text.Encoding": "4.0.11-beta-*", + "System.Threading": "4.0.11-beta-*", + "System.Threading.Tasks": "4.0.11-beta-*", + "System.Threading.Thread": "4.0.0-beta-*", + "System.Threading.ThreadPool": "4.0.10-beta-*" + } + } + }, + "compilationOptions": { + "allowUnsafe": true + }, + "scripts": { + "prepare": [ + "dnu restore ../../tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode", + "dnx --appbase ../../tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode Microsoft.Dnx.ApplicationHost run Http/FrameHeaders.Generated.cs" + ] + }, + "packInclude": { + "native/darwin/universal/": "native/darwin/universal/*", + "native/windows/amd64/": "native/windows/amd64/*", + "native/windows/x86/": "native/windows/x86/*" + } } From 5354ce0a71b8f837cd5749b12f8b4be7d3856a84 Mon Sep 17 00:00:00 2001 From: Ajay Bhargav Baaskaran Date: Thu, 17 Sep 2015 12:28:53 -0700 Subject: [PATCH 0258/1662] Enabling NuGetPackageVerifier --- NuGetPackageVerifier.json | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 NuGetPackageVerifier.json diff --git a/NuGetPackageVerifier.json b/NuGetPackageVerifier.json new file mode 100644 index 0000000000..1ae60f54db --- /dev/null +++ b/NuGetPackageVerifier.json @@ -0,0 +1,25 @@ +{ + "adx": { // Packages written by the ADX team and that ship on NuGet.org + "rules": [ + "AssemblyHasDocumentFileRule", + "AssemblyHasVersionAttributesRule", + "AssemblyHasServicingAttributeRule", + "AssemblyHasNeutralResourcesLanguageAttributeRule", + "SatellitePackageRule", + "StrictSemanticVersionValidationRule" + ], + "packages": { + "Microsoft.AspNet.Server.Kestrel": { } + } + }, + "Default": { // Rules to run for packages not listed in any other set. + "rules": [ + "AssemblyHasDocumentFileRule", + "AssemblyHasVersionAttributesRule", + "AssemblyHasServicingAttributeRule", + "AssemblyHasNeutralResourcesLanguageAttributeRule", + "SatellitePackageRule", + "StrictSemanticVersionValidationRule" + ] + } +} \ No newline at end of file From 355bc01a157fe8039675f9bc9ba75aa65dce9f97 Mon Sep 17 00:00:00 2001 From: Chris R Date: Tue, 22 Sep 2015 11:56:46 -0700 Subject: [PATCH 0259/1662] Hosting#358 Move the default address into Hosting. --- .../KestrelServerInformation.cs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/KestrelServerInformation.cs b/src/Microsoft.AspNet.Server.Kestrel/KestrelServerInformation.cs index 597c45a4d4..4f53b80303 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/KestrelServerInformation.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/KestrelServerInformation.cs @@ -21,10 +21,6 @@ namespace Microsoft.AspNet.Server.Kestrel { Addresses.Add(url); } - if (Addresses.Count == 0) - { - Addresses.Add("http://+:5000/"); - } } } } From c4bf10d6e9d77f75fd2a413c87a6186ac52d3c69 Mon Sep 17 00:00:00 2001 From: Eilon Lipton Date: Mon, 21 Sep 2015 22:19:53 -0700 Subject: [PATCH 0260/1662] Add third party notices for libuv Fixes #218 --- content/thirdpartynotices.txt | 32 +++++++++++++++++++ .../project.json | 1 + 2 files changed, 33 insertions(+) create mode 100644 content/thirdpartynotices.txt diff --git a/content/thirdpartynotices.txt b/content/thirdpartynotices.txt new file mode 100644 index 0000000000..155e2b5486 --- /dev/null +++ b/content/thirdpartynotices.txt @@ -0,0 +1,32 @@ +This file is based on or incorporates material from the projects listed below +(Third Party IP). The original copyright notice and the license under which +Microsoft received such Third Party IP, are set forth below. Such licenses and +notices are provided for informational purposes only. Microsoft licenses the +Third Party IP to you under the licensing terms for the Microsoft product. +Microsoft reserves all other rights not expressly granted under this agreement, +whether by implication, estoppel or otherwise. + +libuv v. 1.7.3 + +Copyright Joyent, Inc. and other Node contributors. All rights reserved. + Provided for Informational Purposes Only + +MIT License + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the Software), to deal in the +Software without restriction, including without limitation the rights to use, +copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the +Software, and to permit persons to whom the Software is furnished to do so, +subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/src/Microsoft.AspNet.Server.Kestrel/project.json b/src/Microsoft.AspNet.Server.Kestrel/project.json index eff997df0e..f0363ca83c 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/project.json +++ b/src/Microsoft.AspNet.Server.Kestrel/project.json @@ -46,6 +46,7 @@ ] }, "packInclude": { + "/": "../../content/thirdpartynotices.txt", "native/darwin/universal/": "native/darwin/universal/*", "native/windows/amd64/": "native/windows/amd64/*", "native/windows/x86/": "native/windows/x86/*" From b9f26311ef8a7269318ee2406bcbfdf264ce7ded Mon Sep 17 00:00:00 2001 From: Brennan Date: Thu, 24 Sep 2015 08:26:00 -0700 Subject: [PATCH 0261/1662] Fix test dependency --- test/Microsoft.AspNet.Server.KestrelTests/project.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/test/Microsoft.AspNet.Server.KestrelTests/project.json b/test/Microsoft.AspNet.Server.KestrelTests/project.json index cd48e8c2ca..907cb11eca 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/project.json +++ b/test/Microsoft.AspNet.Server.KestrelTests/project.json @@ -8,9 +8,10 @@ "dnx451": { }, "dnxcore50": { "dependencies": { + "System.Diagnostics.TraceSource": "4.0.0-beta-*", + "System.IO": "4.0.11-beta-*", "System.Net.Sockets": "4.0.10-beta-*", - "System.Runtime.Handles": "4.0.1-beta-*", - "System.IO": "4.0.11-beta-*" + "System.Runtime.Handles": "4.0.1-beta-*" } } }, From ca8161466eafddb7e2e5226a22ba51b0e45871db Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Thu, 24 Sep 2015 17:06:28 -0700 Subject: [PATCH 0262/1662] Allow mock libuv to shutdown gracefully. This speeds up SocketOutputTests and reduces the total test time on my machine from 35 seconds to 25 seconds. --- .../TestHelpers/{MockLibUv.cs => MockLibuv.cs} | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) rename test/Microsoft.AspNet.Server.KestrelTests/TestHelpers/{MockLibUv.cs => MockLibuv.cs} (92%) diff --git a/test/Microsoft.AspNet.Server.KestrelTests/TestHelpers/MockLibUv.cs b/test/Microsoft.AspNet.Server.KestrelTests/TestHelpers/MockLibuv.cs similarity index 92% rename from test/Microsoft.AspNet.Server.KestrelTests/TestHelpers/MockLibUv.cs rename to test/Microsoft.AspNet.Server.KestrelTests/TestHelpers/MockLibuv.cs index a23cd076ce..1134ae8fab 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/TestHelpers/MockLibUv.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/TestHelpers/MockLibuv.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Threading; using Microsoft.AspNet.Server.Kestrel.Networking; @@ -42,11 +42,16 @@ namespace Microsoft.AspNet.Server.KestrelTests.TestHelpers _onPost(_postHandle.InternalGetHandle()); } - _postHandle.Dispose(); - loopHandle.Dispose(); return 0; }; + _uv_ref = handle => { }; + _uv_unref = handle => + { + _stopLoop = true; + _loopWh.Set(); + }; + _uv_stop = handle => { _stopLoop = true; @@ -60,7 +65,6 @@ namespace Microsoft.AspNet.Server.KestrelTests.TestHelpers _uv_tcp_init = (loopHandle, tcpHandle) => 0; _uv_close = (handle, callback) => callback(handle); _uv_loop_close = handle => 0; - _uv_unref = handle => { }; _uv_walk = (loop, callback, ignore) => 0; } From 1e394730479a0850327ec8d45768d77ce18fd7c7 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Thu, 24 Sep 2015 15:15:06 -0700 Subject: [PATCH 0263/1662] uv_pipe_connect returns void This fix prevents Libuv.pipe_connect from throwing when the stack memory that was previously incorrectly interpreted as the int return value happens to be negative. When pipe_connect threw, an assertion failure would follow since the pipe handle would be closed prematurely. http://docs.libuv.org/en/v1.x/pipe.html#c.uv_pipe_connect #205 --- src/Microsoft.AspNet.Server.Kestrel/Networking/Libuv.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/Libuv.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/Libuv.cs index 254483454d..c3bca07e89 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/Libuv.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/Libuv.cs @@ -243,13 +243,13 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking [UnmanagedFunctionPointer(CallingConvention.Cdecl)] public delegate void uv_connect_cb(IntPtr req, int status); [UnmanagedFunctionPointer(CallingConvention.Cdecl, CharSet = CharSet.Ansi)] - unsafe protected delegate int uv_pipe_connect(UvConnectRequest req, UvPipeHandle handle, string name, uv_connect_cb cb); + unsafe protected delegate void uv_pipe_connect(UvConnectRequest req, UvPipeHandle handle, string name, uv_connect_cb cb); protected uv_pipe_connect _uv_pipe_connect = default(uv_pipe_connect); unsafe public void pipe_connect(UvConnectRequest req, UvPipeHandle handle, string name, uv_connect_cb cb) { req.Validate(); handle.Validate(); - Check(_uv_pipe_connect(req, handle, name, cb)); + _uv_pipe_connect(req, handle, name, cb); } [UnmanagedFunctionPointer(CallingConvention.Cdecl)] From 557f6d69937967ed19577033c5ac40ea7d3af8ee Mon Sep 17 00:00:00 2001 From: Louis DeJardin Date: Thu, 3 Sep 2015 19:50:57 -0700 Subject: [PATCH 0264/1662] Refactoring response control flow - Bring through both sync and async execution paths - Remove callback pattern from from and socketoutput write calls --- .../Http/Frame.cs | 143 ++++++++++-------- .../Http/FrameResponseStream.cs | 40 +---- .../Http/IFrameControl.cs | 9 +- .../Http/ISocketOutput.cs | 7 +- .../Http/SocketOutput.cs | 36 ++++- .../Infrastructure/TaskUtilities.cs | 19 +++ .../Networking/Libuv.cs | 2 + .../FrameTests.cs | 38 +++++ .../TestInput.cs | 22 +++ 9 files changed, 207 insertions(+), 109 deletions(-) create mode 100644 src/Microsoft.AspNet.Server.Kestrel/Infrastructure/TaskUtilities.cs create mode 100644 test/Microsoft.AspNet.Server.KestrelTests/FrameTests.cs diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs index 821e3788c3..0f1910e6d1 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs @@ -6,7 +6,9 @@ using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; +using System.Threading; using System.Threading.Tasks; +using Microsoft.AspNet.Server.Kestrel.Infrastructure; using Microsoft.Framework.Logging; using Microsoft.Framework.Primitives; @@ -16,10 +18,12 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { public class Frame : FrameContext, IFrameControl { - private static Encoding _ascii = Encoding.ASCII; + private static readonly Encoding _ascii = Encoding.ASCII; private static readonly ArraySegment _endChunkBytes = CreateAsciiByteArraySegment("\r\n"); private static readonly ArraySegment _endChunkedResponseBytes = CreateAsciiByteArraySegment("0\r\n\r\n"); private static readonly ArraySegment _continueBytes = CreateAsciiByteArraySegment("HTTP/1.1 100 Continue\r\n\r\n"); + private static readonly ArraySegment _emptyData = new ArraySegment(new byte[0]); + private static readonly byte[] _hex = Encoding.ASCII.GetBytes("0123456789abcdef"); private Mode _mode; private bool _responseStarted; @@ -65,7 +69,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http public void Consume() { var input = SocketInput; - for (; ;) + for (;;) { switch (_mode) { @@ -244,7 +248,19 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } - public void Write(ArraySegment data, Action callback, object state) + public void Flush() + { + ProduceStart(immediate: false); + SocketOutput.Write(_emptyData, immediate: true); + } + + public Task FlushAsync(CancellationToken cancellationToken) + { + ProduceStart(immediate: false); + return SocketOutput.WriteAsync(_emptyData, immediate: true); + } + + public void Write(ArraySegment data) { ProduceStart(immediate: false); @@ -252,63 +268,80 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { if (data.Count == 0) { - callback(null, state); return; } - - WriteChunkPrefix(data.Count); + WriteChunked(data); } + else + { + SocketOutput.Write(data, immediate: true); + } + } - SocketOutput.Write(data, callback, state, immediate: !_autoChunk); + public Task WriteAsync(ArraySegment data, CancellationToken cancellationToken) + { + ProduceStart(immediate: false); if (_autoChunk) { - WriteChunkSuffix(); + if (data.Count == 0) + { + return TaskUtilities.CompletedTask; + } + return WriteChunkedAsync(data, cancellationToken); + } + else + { + return SocketOutput.WriteAsync(data, immediate: true, cancellationToken: cancellationToken); } } - private void WriteChunkPrefix(int numOctets) + private void WriteChunked(ArraySegment data) { - var numOctetBytes = CreateAsciiByteArraySegment(numOctets.ToString("x") + "\r\n"); - - SocketOutput.Write(numOctetBytes, - (error, _) => - { - if (error != null) - { - Log.LogError("WriteChunkPrefix", error); - } - }, - null, - immediate: false); + SocketOutput.Write(BeginChunkBytes(data.Count), immediate: false); + SocketOutput.Write(data, immediate: false); + SocketOutput.Write(_endChunkBytes, immediate: true); } - private void WriteChunkSuffix() + private async Task WriteChunkedAsync(ArraySegment data, CancellationToken cancellationToken) { - SocketOutput.Write(_endChunkBytes, - (error, _) => - { - if (error != null) - { - Log.LogError("WriteChunkSuffix", error); - } - }, - null, - immediate: true); + await SocketOutput.WriteAsync(BeginChunkBytes(data.Count), immediate: false, cancellationToken: cancellationToken); + await SocketOutput.WriteAsync(data, immediate: false, cancellationToken: cancellationToken); + await SocketOutput.WriteAsync(_endChunkBytes, immediate: true, cancellationToken: cancellationToken); + } + + public static ArraySegment BeginChunkBytes(int dataCount) + { + var bytes = new byte[10] + { + _hex[((dataCount >> 0x1c) & 0x0f)], + _hex[((dataCount >> 0x18) & 0x0f)], + _hex[((dataCount >> 0x14) & 0x0f)], + _hex[((dataCount >> 0x10) & 0x0f)], + _hex[((dataCount >> 0x0c) & 0x0f)], + _hex[((dataCount >> 0x08) & 0x0f)], + _hex[((dataCount >> 0x04) & 0x0f)], + _hex[((dataCount >> 0x00) & 0x0f)], + (byte)'\r', + (byte)'\n', + }; + + // Determine the most-significant non-zero nibble + int total, shift; + total = (dataCount > 0xffff) ? 0x10 : 0x00; + dataCount >>= total; + shift = (dataCount > 0x00ff) ? 0x08 : 0x00; + dataCount >>= shift; + total |= shift; + total |= (dataCount > 0x000f) ? 0x04 : 0x00; + + var offset = 7 - (total >> 2); + return new ArraySegment(bytes, offset, 10 - offset); } private void WriteChunkedResponseSuffix() { - SocketOutput.Write(_endChunkedResponseBytes, - (error, _) => - { - if (error != null) - { - Log.LogError("WriteChunkedResponseSuffix", error); - } - }, - null, - immediate: true); + SocketOutput.Write(_endChunkedResponseBytes, immediate: true); } public void Upgrade(IDictionary options, Func callback) @@ -332,16 +365,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http RequestHeaders.TryGetValue("Expect", out expect) && (expect.FirstOrDefault() ?? "").Equals("100-continue", StringComparison.OrdinalIgnoreCase)) { - SocketOutput.Write( - _continueBytes, - (error, _) => - { - if (error != null) - { - Log.LogError("ProduceContinue ", error); - } - }, - null); + SocketOutput.Write(_continueBytes); } } @@ -355,18 +379,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http var status = ReasonPhrases.ToStatus(StatusCode, ReasonPhrase); var responseHeader = CreateResponseHeader(status, appCompleted, ResponseHeaders); - SocketOutput.Write( - responseHeader.Item1, - (error, state) => - { - if (error != null) - { - Log.LogError("ProduceStart ", error); - } - ((IDisposable)state).Dispose(); - }, - responseHeader.Item2, - immediate: immediate); + SocketOutput.Write(responseHeader.Item1, immediate: immediate); + responseHeader.Item2.Dispose(); } public void ProduceEnd(Exception ex) @@ -660,6 +674,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http statusCode != 304; } + private enum Mode { StartLine, diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameResponseStream.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameResponseStream.cs index cfb6453129..631c106045 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameResponseStream.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameResponseStream.cs @@ -35,28 +35,12 @@ namespace Microsoft.AspNet.Server.Kestrel.Http public override void Flush() { - FlushAsync(CancellationToken.None).Wait(); + _context.FrameControl.Flush(); } public override Task FlushAsync(CancellationToken cancellationToken) { - var tcs = new TaskCompletionSource(); - _context.FrameControl.Write( - new ArraySegment(new byte[0]), - (error, arg) => - { - var tcsArg = (TaskCompletionSource)arg; - if (error != null) - { - tcsArg.SetException(error); - } - else - { - tcsArg.SetResult(0); - } - }, - tcs); - return tcs.Task; + return _context.FrameControl.FlushAsync(cancellationToken); } public override long Seek(long offset, SeekOrigin origin) @@ -76,28 +60,12 @@ namespace Microsoft.AspNet.Server.Kestrel.Http public override void Write(byte[] buffer, int offset, int count) { - WriteAsync(buffer, offset, count).Wait(); + _context.FrameControl.Write(new ArraySegment(buffer, offset, count)); } public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) { - var tcs = new TaskCompletionSource(); - _context.FrameControl.Write( - new ArraySegment(buffer, offset, count), - (error, arg) => - { - var tcsArg = (TaskCompletionSource)arg; - if (error != null) - { - tcsArg.SetException(error); - } - else - { - tcsArg.SetResult(0); - } - }, - tcs); - return tcs.Task; + return _context.FrameControl.WriteAsync(new ArraySegment(buffer, offset, count), cancellationToken); } } } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/IFrameControl.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/IFrameControl.cs index 77240740e6..6871236b8b 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/IFrameControl.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/IFrameControl.cs @@ -2,12 +2,17 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Threading; +using System.Threading.Tasks; namespace Microsoft.AspNet.Server.Kestrel.Http { public interface IFrameControl { void ProduceContinue(); - void Write(ArraySegment data, Action callback, object state); + void Write(ArraySegment data); + Task WriteAsync(ArraySegment data, CancellationToken cancellationToken); + void Flush(); + Task FlushAsync(CancellationToken cancellationToken); } -} \ No newline at end of file +} diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/ISocketOutput.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/ISocketOutput.cs index e4a57c5ebf..4edffa3055 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/ISocketOutput.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/ISocketOutput.cs @@ -2,6 +2,8 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Threading; +using System.Threading.Tasks; namespace Microsoft.AspNet.Server.Kestrel.Http { @@ -10,6 +12,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http /// public interface ISocketOutput { - void Write(ArraySegment buffer, Action callback, object state, bool immediate = true); + void Write(ArraySegment buffer, bool immediate = true); + Task WriteAsync(ArraySegment buffer, bool immediate = true, CancellationToken cancellationToken = default(CancellationToken)); } -} \ No newline at end of file +} diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs index 3c836df3c3..b6dcd0967f 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs @@ -5,6 +5,7 @@ using System; using System.Collections.Generic; using System.Diagnostics; using System.Threading; +using System.Threading.Tasks; using Microsoft.AspNet.Server.Kestrel.Infrastructure; using Microsoft.AspNet.Server.Kestrel.Networking; @@ -96,11 +97,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http private void ScheduleWrite() { - _thread.Post(obj => - { - var self = (SocketOutput)obj; - self.WriteAllPending(); - }, this); + _thread.Post(_this => _this.WriteAllPending(), this); } // This is called on the libuv event loop @@ -211,6 +208,35 @@ namespace Microsoft.AspNet.Server.Kestrel.Http }, context); } + void ISocketOutput.Write(ArraySegment buffer, bool immediate) + { + ((ISocketOutput)this).WriteAsync(buffer, immediate).Wait(); + } + + Task ISocketOutput.WriteAsync(ArraySegment buffer, bool immediate, CancellationToken cancellationToken) + { + // TODO: Optimize task being used, and remove callback model from the underlying Write + var tcs = new TaskCompletionSource(); + + Write( + buffer, + (error, state) => + { + if (error != null) + { + tcs.SetException(error); + } + else + { + tcs.SetResult(0); + } + }, + tcs, + immediate: immediate); + + return tcs.Task; + } + private class CallbackContext { public Exception Error; diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/TaskUtilities.cs b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/TaskUtilities.cs new file mode 100644 index 0000000000..87b741a728 --- /dev/null +++ b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/TaskUtilities.cs @@ -0,0 +1,19 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System.Threading.Tasks; + +namespace Microsoft.AspNet.Server.Kestrel.Infrastructure +{ + public static class TaskUtilities + { + public static Task CompletedTask = NewCompletedTask(); + + private static Task NewCompletedTask() + { + var tcs = new TaskCompletionSource(); + tcs.SetResult(0); + return tcs.Task; + } + } +} diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/Libuv.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/Libuv.cs index c3bca07e89..f926b16bd5 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/Libuv.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/Libuv.cs @@ -51,7 +51,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking { continue; } +#pragma warning disable CS0618 var value = Marshal.GetDelegateForFunctionPointer(procAddress, field.FieldType); +#pragma warning restore CS0618 field.SetValue(this, value); } } diff --git a/test/Microsoft.AspNet.Server.KestrelTests/FrameTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/FrameTests.cs new file mode 100644 index 0000000000..ec73fcd3b2 --- /dev/null +++ b/test/Microsoft.AspNet.Server.KestrelTests/FrameTests.cs @@ -0,0 +1,38 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using Microsoft.AspNet.Server.Kestrel.Http; +using System.Linq; +using System.Text; +using Xunit; + +namespace Microsoft.AspNet.Server.KestrelTests +{ + public class FrameTests + { + [Theory] + [InlineData(1, "1\r\n")] + [InlineData(10, "a\r\n")] + [InlineData(0x08, "8\r\n")] + [InlineData(0x10, "10\r\n")] + [InlineData(0x080, "80\r\n")] + [InlineData(0x100, "100\r\n")] + [InlineData(0x0800, "800\r\n")] + [InlineData(0x1000, "1000\r\n")] + [InlineData(0x08000, "8000\r\n")] + [InlineData(0x10000, "10000\r\n")] + [InlineData(0x080000, "80000\r\n")] + [InlineData(0x100000, "100000\r\n")] + [InlineData(0x0800000, "800000\r\n")] + [InlineData(0x1000000, "1000000\r\n")] + [InlineData(0x08000000, "8000000\r\n")] + [InlineData(0x10000000, "10000000\r\n")] + [InlineData(0x7fffffffL, "7fffffff\r\n")] + public void ChunkedPrefixMustBeHexCrLfWithoutLeadingZeros(int dataCount, string expected) + { + var beginChunkBytes = Frame.BeginChunkBytes(dataCount); + + Assert.Equal(Encoding.ASCII.GetBytes(expected), beginChunkBytes.ToArray()); + } + } +} diff --git a/test/Microsoft.AspNet.Server.KestrelTests/TestInput.cs b/test/Microsoft.AspNet.Server.KestrelTests/TestInput.cs index 1676a92044..c1b9e75729 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/TestInput.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/TestInput.cs @@ -2,6 +2,8 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Threading; +using System.Threading.Tasks; using Microsoft.AspNet.Server.Kestrel.Http; namespace Microsoft.AspNet.Server.KestrelTests @@ -53,6 +55,26 @@ namespace Microsoft.AspNet.Server.KestrelTests public void End(ProduceEndType endType) { } + + void IFrameControl.ProduceContinue() + { + } + + void IFrameControl.Write(ArraySegment data) + { + } + + async Task IFrameControl.WriteAsync(ArraySegment data, CancellationToken cancellationToken) + { + } + + void IFrameControl.Flush() + { + } + + async Task IFrameControl.FlushAsync(CancellationToken cancellationToken) + { + } } } From 1f6aaebeda73ee391a07265994d4def434772b3f Mon Sep 17 00:00:00 2001 From: Louis DeJardin Date: Tue, 15 Sep 2015 16:40:11 -0700 Subject: [PATCH 0265/1662] Changing flow control for incoming data SocketInput is now awaitable Input buffers are slab-allocated and pinned from large object heap Request frame parsing is offloaded from libuv thread --- samples/SampleApp/Startup.cs | 6 +- .../Http/Connection.cs | 61 +- .../Http/Frame.cs | 373 ++-- .../Http/FrameHeaders.Generated.cs | 1506 ++++++++++++++++- .../Http/FrameHeaders.cs | 6 +- .../Http/FrameRequestStream.cs | 4 +- .../Http/Listener.cs | 1 + .../Http/ListenerContext.cs | 3 + .../Http/ListenerSecondary.cs | 2 +- .../Http/MemoryPool2.cs | 109 ++ .../Http/MemoryPoolBlock2.cs | 479 ++++++ .../Http/MemoryPoolSlab2.cs | 68 + .../Http/MessageBody.cs | 184 +- .../Http/MessageBodyExchanger.cs | 25 + .../Http/SocketInput.cs | 253 ++- .../Networking/UvStreamHandle.cs | 8 +- .../project.json | 1 + .../FrameResponseHeadersTests.cs | 3 +- .../MemoryPoolBlock2Tests.cs | 76 + .../MessageBodyExchangerTests.cs | 10 +- .../MessageBodyTests.cs | 2 - .../MultipleLoopTests.cs | 6 +- .../NetworkingTests.cs | 4 +- .../TestInput.cs | 10 +- .../KnownHeaders.cs | 36 +- 25 files changed, 2823 insertions(+), 413 deletions(-) create mode 100644 src/Microsoft.AspNet.Server.Kestrel/Http/MemoryPool2.cs create mode 100644 src/Microsoft.AspNet.Server.Kestrel/Http/MemoryPoolBlock2.cs create mode 100644 src/Microsoft.AspNet.Server.Kestrel/Http/MemoryPoolSlab2.cs create mode 100644 test/Microsoft.AspNet.Server.KestrelTests/MemoryPoolBlock2Tests.cs diff --git a/samples/SampleApp/Startup.cs b/samples/SampleApp/Startup.cs index 955df43277..4e1d25519f 100644 --- a/samples/SampleApp/Startup.cs +++ b/samples/SampleApp/Startup.cs @@ -16,7 +16,7 @@ namespace SampleApp loggerFactory.AddConsole(LogLevel.Debug); - app.Run(context => + app.Run(async context => { Console.WriteLine("{0} {1}{2}{3}", context.Request.Method, @@ -24,9 +24,11 @@ namespace SampleApp context.Request.Path, context.Request.QueryString); + await context.Request.Body.CopyToAsync(Console.OpenStandardOutput()); + context.Response.ContentLength = 11; context.Response.ContentType = "text/plain"; - return context.Response.WriteAsync("Hello world"); + await context.Response.WriteAsync("Hello world"); }); } } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs index d33409dbeb..e9c960c2e5 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs @@ -3,6 +3,7 @@ using System; using System.Threading; +using System.Threading.Tasks; using Microsoft.AspNet.Server.Kestrel.Infrastructure; using Microsoft.AspNet.Server.Kestrel.Networking; using Microsoft.Framework.Logging; @@ -11,13 +12,17 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { public class Connection : ConnectionContext, IConnectionControl { - private static readonly Action _readCallback = ReadCallback; + private const int EOF = -4095; + private const int ECONNRESET = -4077; + + private static readonly Action _readCallback = ReadCallback; private static readonly Func _allocCallback = AllocCallback; private static long _lastConnectionId; private readonly UvStreamHandle _socket; private Frame _frame; + private Task _frameTask; private long _connectionId = 0; private readonly object _stateLock = new object(); @@ -35,9 +40,10 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { Log.ConnectionStart(_connectionId); - SocketInput = new SocketInput(Memory); + SocketInput = new SocketInput(Memory2); SocketOutput = new SocketOutput(Thread, _socket, _connectionId, Log); _frame = new Frame(this); + _frameTask = Task.Run(_frame.ProcessFraming); _socket.ReadStart(_allocCallback, _readCallback, this); } @@ -48,27 +54,29 @@ namespace Microsoft.AspNet.Server.Kestrel.Http private Libuv.uv_buf_t OnAlloc(UvStreamHandle handle, int suggestedSize) { + var result = SocketInput.Pin(2048); + return handle.Libuv.buf_init( - SocketInput.Pin(2048), - 2048); + result.DataPtr, + result.Data.Count); } - private static void ReadCallback(UvStreamHandle handle, int nread, Exception error, object state) + private static void ReadCallback(UvStreamHandle handle, int readCount, int errorCode, Exception error, object state) { - ((Connection)state).OnRead(handle, nread, error); + ((Connection)state).OnRead(handle, readCount, errorCode, error); } - private void OnRead(UvStreamHandle handle, int status, Exception error) + private void OnRead(UvStreamHandle handle, int readCount, int errorCode, Exception error) { - SocketInput.Unpin(status); + SocketInput.Unpin(readCount); - var normalRead = error == null && status > 0; - var normalDone = status == 0 || status == Constants.ECONNRESET || status == Constants.EOF; + var normalRead = readCount != 0 && errorCode == 0; + var normalDone = readCount == 0 && (errorCode == 0 || errorCode == Constants.ECONNRESET || errorCode == Constants.EOF); var errorDone = !(normalDone || normalRead); if (normalRead) { - Log.ConnectionRead(_connectionId, status); + Log.ConnectionRead(_connectionId, readCount); } else if (normalDone || errorDone) { @@ -85,16 +93,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } - - try - { - _frame.Consume(); - } - catch (Exception ex) - { - Log.LogError("Connection._frame.Consume ", ex); - throw; - } + SocketInput.SetCompleted(errorDone ? error : null); } void IConnectionControl.Pause() @@ -124,17 +123,17 @@ namespace Microsoft.AspNet.Server.Kestrel.Http Log.ConnectionWriteFin(_connectionId); Thread.Post( - state => + _this => { var self = (Connection)state; var shutdown = new UvShutdownReq(self.Log); - shutdown.Init(self.Thread.Loop); - shutdown.Shutdown(self._socket, (req, status, state2) => + shutdown.Init(_this.Thread.Loop); + shutdown.Shutdown(_this._socket, (req, status, state2) => { - var self2 = (Connection)state2; - self2.Log.ConnectionWroteFin(_connectionId, status); + var __this = (Connection)state2; + __this.Log.ConnectionWroteFin(__this._connectionId, status); req.Dispose(); - }, this); + }, _this); }, this); break; @@ -159,12 +158,12 @@ namespace Microsoft.AspNet.Server.Kestrel.Http Log.ConnectionDisconnect(_connectionId); Thread.Post( - state => + _this => { - Log.ConnectionStop(_connectionId); - ((UvHandle)state).Dispose(); + Log.ConnectionStop(_this._connectionId); + _this._socket.Dispose(); }, - _socket); + this); break; } } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs index 0f1910e6d1..86b22b8bac 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs @@ -11,6 +11,8 @@ using System.Threading.Tasks; using Microsoft.AspNet.Server.Kestrel.Infrastructure; using Microsoft.Framework.Logging; using Microsoft.Framework.Primitives; +using System.Numerics; +using Microsoft.AspNet.Hosting.Builder; // ReSharper disable AccessToModifiedClosure @@ -25,24 +27,22 @@ namespace Microsoft.AspNet.Server.Kestrel.Http private static readonly ArraySegment _emptyData = new ArraySegment(new byte[0]); private static readonly byte[] _hex = Encoding.ASCII.GetBytes("0123456789abcdef"); - private Mode _mode; - private bool _responseStarted; - private bool _keepAlive; - private bool _autoChunk; + private readonly object _onStartingSync = new Object(); + private readonly object _onCompletedSync = new Object(); private readonly FrameRequestHeaders _requestHeaders = new FrameRequestHeaders(); private readonly FrameResponseHeaders _responseHeaders = new FrameResponseHeaders(); private List, object>> _onStarting; private List, object>> _onCompleted; - private object _onStartingSync = new Object(); - private object _onCompletedSync = new Object(); + + private bool _responseStarted; + private bool _keepAlive; + private bool _autoChunk; public Frame(ConnectionContext context) : base(context) { FrameControl = this; - StatusCode = 200; - RequestHeaders = _requestHeaders; - ResponseHeaders = _responseHeaders; + Reset(); } public string Method { get; set; } @@ -66,95 +66,112 @@ namespace Microsoft.AspNet.Server.Kestrel.Http get { return _responseStarted; } } - public void Consume() + public void Reset() { - var input = SocketInput; - for (;;) - { - switch (_mode) - { - case Mode.StartLine: - if (input.Buffer.Count == 0 && input.RemoteIntakeFin) - { - _mode = Mode.Terminated; - break; - } + _onStarting = null; + _onCompleted = null; - if (!TakeStartLine(input)) - { - if (input.RemoteIntakeFin) - { - _mode = Mode.Terminated; - break; - } - return; - } + _responseStarted = false; + _keepAlive = false; + _autoChunk = false; - _mode = Mode.MessageHeader; - break; + _requestHeaders.Reset(); + ResetResponseHeaders(); - case Mode.MessageHeader: - if (input.Buffer.Count == 0 && input.RemoteIntakeFin) - { - _mode = Mode.Terminated; - break; - } + Method = null; + RequestUri = null; + Path = null; + QueryString = null; + HttpVersion = null; + RequestHeaders = _requestHeaders; + MessageBody = null; + RequestBody = null; + StatusCode = 200; + ReasonPhrase = null; + ResponseHeaders = _responseHeaders; + ResponseBody = null; + DuplexStream = null; - var endOfHeaders = false; - while (!endOfHeaders) - { - if (!TakeMessageHeader(input, out endOfHeaders)) - { - if (input.RemoteIntakeFin) - { - _mode = Mode.Terminated; - break; - } - return; - } - } - - if (_mode == Mode.Terminated) - { - // If we broke out of the above while loop in the Terminated - // state, we don't want to transition to the MessageBody state. - break; - } - - _mode = Mode.MessageBody; - Execute(); - break; - - case Mode.MessageBody: - if (MessageBody.LocalIntakeFin) - { - // NOTE: stop reading and resume on keepalive? - return; - } - MessageBody.Consume(); - // NOTE: keep looping? - return; - - case Mode.Terminated: - ConnectionControl.End(ProduceEndType.SocketShutdownSend); - ConnectionControl.End(ProduceEndType.SocketDisconnect); - return; - } - } } - private void Execute() + public void ResetResponseHeaders() { - MessageBody = MessageBody.For( - HttpVersion, - RequestHeaders, - this); - _keepAlive = MessageBody.RequestKeepAlive; - RequestBody = new FrameRequestStream(MessageBody); - ResponseBody = new FrameResponseStream(this); - DuplexStream = new FrameDuplexStream(RequestBody, ResponseBody); - SocketInput.Free(); - Task.Run(ExecuteAsync); + _responseHeaders.Reset(); + _responseHeaders.HeaderServer = "Kestrel"; + _responseHeaders.HeaderDate = DateTime.UtcNow.ToString("r"); + } + + public async Task ProcessFraming() + { + var terminated = false; + while (!terminated) + { + while (!terminated && !TakeStartLine(SocketInput)) + { + terminated = SocketInput.RemoteIntakeFin; + if (!terminated) + { + await SocketInput; + } + else + { + var x = 5; + } + } + + while (!terminated && !TakeMessageHeader2(SocketInput)) + { + terminated = SocketInput.RemoteIntakeFin; + if (!terminated) + { + await SocketInput; + } + else + { + var x = 5; + } + } + + if (!terminated) + { + MessageBody = MessageBody.For(HttpVersion, _requestHeaders, this); + _keepAlive = MessageBody.RequestKeepAlive; + RequestBody = new FrameRequestStream(MessageBody); + ResponseBody = new FrameResponseStream(this); + DuplexStream = new FrameDuplexStream(RequestBody, ResponseBody); + + Exception error = null; + try + { + await Application.Invoke(this).ConfigureAwait(false); + + // Trigger FireOnStarting if ProduceStart hasn't been called yet. + // We call it here, so it can go through our normal error handling + // and respond with a 500 if an OnStarting callback throws. + if (!_responseStarted) + { + FireOnStarting(); + } + } + catch (Exception ex) + { + error = ex; + } + finally + { + FireOnCompleted(); + ProduceEnd(error); + } + + terminated = !_keepAlive; + } + + Reset(); + } + + // Connection Terminated! + ConnectionControl.End(ProduceEndType.SocketShutdownSend); + ConnectionControl.End(ProduceEndType.SocketDisconnect); } public void OnStarting(Func callback, object state) @@ -222,32 +239,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } - private async Task ExecuteAsync() - { - Exception error = null; - try - { - await Application.Invoke(this).ConfigureAwait(false); - - // Trigger FireOnStarting if ProduceStart hasn't been called yet. - // We call it here, so it can go through our normal error handling - // and respond with a 500 if an OnStarting callback throws. - if (!_responseStarted) - { - FireOnStarting(); - } - } - catch (Exception ex) - { - error = ex; - } - finally - { - FireOnCompleted(); - ProduceEnd(error); - } - } - public void Flush() { ProduceStart(immediate: false); @@ -402,8 +393,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http // the app func has failed. https://github.com/aspnet/KestrelHttpServer/issues/43 _onStarting = null; - ResponseHeaders = new FrameResponseHeaders(); - ResponseHeaders["Content-Length"] = new[] { "0" }; + ResetResponseHeaders(); + _responseHeaders.HeaderContentLength = "0"; } } @@ -522,58 +513,39 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return new Tuple, IDisposable>(writer.Buffer, writer); } - private bool TakeStartLine(SocketInput baton) + private bool TakeStartLine(SocketInput input) { - var remaining = baton.Buffer; - if (remaining.Count < 2) + var begin = input.GetIterator(); + if (begin.IsDefault) return false; + + var end = begin.IndexOf(' '); + var method = begin.GetString(end); + + char chFound; + begin = end.Add(1); + end = begin.IndexOfAny(' ', '?', out chFound); + var requestUri = begin.GetString(end); + + begin = end; + end = chFound == '?' ? begin.IndexOf(' ') : begin; + var queryString = begin.GetString(end); + + begin = end.Add(1); + end = begin.IndexOf('\r'); + var httpVersion = begin.GetString(end); + + end = end.Add(1); + if (end.Peek() != '\n') { return false; } - var firstSpace = -1; - var secondSpace = -1; - var questionMark = -1; - var ch0 = remaining.Array[remaining.Offset]; - for (var index = 0; index != remaining.Count - 1; ++index) - { - var ch1 = remaining.Array[remaining.Offset + index + 1]; - if (ch0 == '\r' && ch1 == '\n') - { - if (secondSpace == -1) - { - throw new InvalidOperationException("INVALID REQUEST FORMAT"); - } - Method = GetString(remaining, 0, firstSpace); - RequestUri = GetString(remaining, firstSpace + 1, secondSpace); - if (questionMark == -1) - { - Path = RequestUri; - QueryString = string.Empty; - } - else - { - Path = GetString(remaining, firstSpace + 1, questionMark); - QueryString = GetString(remaining, questionMark, secondSpace); - } - HttpVersion = GetString(remaining, secondSpace + 1, index); - baton.Skip(index + 2); - return true; - } - if (ch0 == ' ' && firstSpace == -1) - { - firstSpace = index; - } - else if (ch0 == ' ' && firstSpace != -1 && secondSpace == -1) - { - secondSpace = index; - } - else if (ch0 == '?' && firstSpace != -1 && questionMark == -1 && secondSpace == -1) - { - questionMark = index; - } - ch0 = ch1; - } - return false; + Method = method; + RequestUri = requestUri; + QueryString = queryString; + HttpVersion = httpVersion; + input.JumpTo(end.Add(1)); + return true; } static string GetString(ArraySegment range, int startIndex, int endIndex) @@ -581,6 +553,68 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return Encoding.UTF8.GetString(range.Array, range.Offset + startIndex, endIndex - startIndex); } + private bool TakeMessageHeader2(SocketInput baton) + { + char chFirst; + char chSecond; + var scan = baton.GetIterator(); + while (!scan.IsDefault) + { + var beginName = scan; + scan = scan.IndexOfAny(':', '\r', out chFirst); + + var endName = scan; + chSecond = scan.MoveNext(); + + if (chFirst == '\r' && chSecond == '\n') + { + baton.JumpTo(scan.Add(1)); + return true; + } + if (chFirst == char.MinValue) + { + return false; + } + + while ( + chSecond == ' ' || + chSecond == '\t' || + chSecond == '\r' || + chSecond == '\n') + { + chSecond = scan.MoveNext(); + } + + var beginValue = scan; + var wrapping = false; + while (!scan.IsDefault) + { + var endValue = scan = scan.IndexOf('\r'); + chFirst = scan.MoveNext(); + if (chFirst != '\n') + { + continue; + } + chSecond = scan.MoveNext(); + if (chSecond == ' ' || chSecond == '\t') + { + wrapping = true; + continue; + } + var name = beginName.GetArraySegment(endName); + var value = beginValue.GetString(endValue); + if (wrapping) + { + value = value.Replace("\r\n", " "); + } + + _requestHeaders.Append(name.Array, name.Offset, name.Count, value); + break; + } + } + + return false; + } private bool TakeMessageHeader(SocketInput baton, out bool endOfHeaders) { @@ -673,14 +707,5 @@ namespace Microsoft.AspNet.Server.Kestrel.Http statusCode != 205 && statusCode != 304; } - - - private enum Mode - { - StartLine, - MessageHeader, - MessageBody, - Terminated, - } } } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameHeaders.Generated.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameHeaders.Generated.cs index f0975ff9b0..50d57d6ce0 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameHeaders.Generated.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameHeaders.Generated.cs @@ -5,15 +5,6 @@ using Microsoft.Framework.Primitives; namespace Microsoft.AspNet.Server.Kestrel.Http { - public partial class FrameResponseHeaders - { - public FrameResponseHeaders() - { - _Server = "Kestrel"; - _Date = DateTime.UtcNow.ToString("r"); - _bits = 67108868L; - } - } public partial class FrameRequestHeaders { @@ -61,6 +52,828 @@ namespace Microsoft.AspNet.Server.Kestrel.Http private StringValues _Translate; private StringValues _UserAgent; + + public StringValues HeaderCacheControl + { + get + { + if (((_bits & 1L) != 0)) + { + return _CacheControl; + } + else + { + return StringValues.Empty; + } + } + set + { + _bits |= 1L; + _CacheControl = value; + } + } + + public StringValues HeaderConnection + { + get + { + if (((_bits & 2L) != 0)) + { + return _Connection; + } + else + { + return StringValues.Empty; + } + } + set + { + _bits |= 2L; + _Connection = value; + } + } + + public StringValues HeaderDate + { + get + { + if (((_bits & 4L) != 0)) + { + return _Date; + } + else + { + return StringValues.Empty; + } + } + set + { + _bits |= 4L; + _Date = value; + } + } + + public StringValues HeaderKeepAlive + { + get + { + if (((_bits & 8L) != 0)) + { + return _KeepAlive; + } + else + { + return StringValues.Empty; + } + } + set + { + _bits |= 8L; + _KeepAlive = value; + } + } + + public StringValues HeaderPragma + { + get + { + if (((_bits & 16L) != 0)) + { + return _Pragma; + } + else + { + return StringValues.Empty; + } + } + set + { + _bits |= 16L; + _Pragma = value; + } + } + + public StringValues HeaderTrailer + { + get + { + if (((_bits & 32L) != 0)) + { + return _Trailer; + } + else + { + return StringValues.Empty; + } + } + set + { + _bits |= 32L; + _Trailer = value; + } + } + + public StringValues HeaderTransferEncoding + { + get + { + if (((_bits & 64L) != 0)) + { + return _TransferEncoding; + } + else + { + return StringValues.Empty; + } + } + set + { + _bits |= 64L; + _TransferEncoding = value; + } + } + + public StringValues HeaderUpgrade + { + get + { + if (((_bits & 128L) != 0)) + { + return _Upgrade; + } + else + { + return StringValues.Empty; + } + } + set + { + _bits |= 128L; + _Upgrade = value; + } + } + + public StringValues HeaderVia + { + get + { + if (((_bits & 256L) != 0)) + { + return _Via; + } + else + { + return StringValues.Empty; + } + } + set + { + _bits |= 256L; + _Via = value; + } + } + + public StringValues HeaderWarning + { + get + { + if (((_bits & 512L) != 0)) + { + return _Warning; + } + else + { + return StringValues.Empty; + } + } + set + { + _bits |= 512L; + _Warning = value; + } + } + + public StringValues HeaderAllow + { + get + { + if (((_bits & 1024L) != 0)) + { + return _Allow; + } + else + { + return StringValues.Empty; + } + } + set + { + _bits |= 1024L; + _Allow = value; + } + } + + public StringValues HeaderContentLength + { + get + { + if (((_bits & 2048L) != 0)) + { + return _ContentLength; + } + else + { + return StringValues.Empty; + } + } + set + { + _bits |= 2048L; + _ContentLength = value; + } + } + + public StringValues HeaderContentType + { + get + { + if (((_bits & 4096L) != 0)) + { + return _ContentType; + } + else + { + return StringValues.Empty; + } + } + set + { + _bits |= 4096L; + _ContentType = value; + } + } + + public StringValues HeaderContentEncoding + { + get + { + if (((_bits & 8192L) != 0)) + { + return _ContentEncoding; + } + else + { + return StringValues.Empty; + } + } + set + { + _bits |= 8192L; + _ContentEncoding = value; + } + } + + public StringValues HeaderContentLanguage + { + get + { + if (((_bits & 16384L) != 0)) + { + return _ContentLanguage; + } + else + { + return StringValues.Empty; + } + } + set + { + _bits |= 16384L; + _ContentLanguage = value; + } + } + + public StringValues HeaderContentLocation + { + get + { + if (((_bits & 32768L) != 0)) + { + return _ContentLocation; + } + else + { + return StringValues.Empty; + } + } + set + { + _bits |= 32768L; + _ContentLocation = value; + } + } + + public StringValues HeaderContentMD5 + { + get + { + if (((_bits & 65536L) != 0)) + { + return _ContentMD5; + } + else + { + return StringValues.Empty; + } + } + set + { + _bits |= 65536L; + _ContentMD5 = value; + } + } + + public StringValues HeaderContentRange + { + get + { + if (((_bits & 131072L) != 0)) + { + return _ContentRange; + } + else + { + return StringValues.Empty; + } + } + set + { + _bits |= 131072L; + _ContentRange = value; + } + } + + public StringValues HeaderExpires + { + get + { + if (((_bits & 262144L) != 0)) + { + return _Expires; + } + else + { + return StringValues.Empty; + } + } + set + { + _bits |= 262144L; + _Expires = value; + } + } + + public StringValues HeaderLastModified + { + get + { + if (((_bits & 524288L) != 0)) + { + return _LastModified; + } + else + { + return StringValues.Empty; + } + } + set + { + _bits |= 524288L; + _LastModified = value; + } + } + + public StringValues HeaderAccept + { + get + { + if (((_bits & 1048576L) != 0)) + { + return _Accept; + } + else + { + return StringValues.Empty; + } + } + set + { + _bits |= 1048576L; + _Accept = value; + } + } + + public StringValues HeaderAcceptCharset + { + get + { + if (((_bits & 2097152L) != 0)) + { + return _AcceptCharset; + } + else + { + return StringValues.Empty; + } + } + set + { + _bits |= 2097152L; + _AcceptCharset = value; + } + } + + public StringValues HeaderAcceptEncoding + { + get + { + if (((_bits & 4194304L) != 0)) + { + return _AcceptEncoding; + } + else + { + return StringValues.Empty; + } + } + set + { + _bits |= 4194304L; + _AcceptEncoding = value; + } + } + + public StringValues HeaderAcceptLanguage + { + get + { + if (((_bits & 8388608L) != 0)) + { + return _AcceptLanguage; + } + else + { + return StringValues.Empty; + } + } + set + { + _bits |= 8388608L; + _AcceptLanguage = value; + } + } + + public StringValues HeaderAuthorization + { + get + { + if (((_bits & 16777216L) != 0)) + { + return _Authorization; + } + else + { + return StringValues.Empty; + } + } + set + { + _bits |= 16777216L; + _Authorization = value; + } + } + + public StringValues HeaderCookie + { + get + { + if (((_bits & 33554432L) != 0)) + { + return _Cookie; + } + else + { + return StringValues.Empty; + } + } + set + { + _bits |= 33554432L; + _Cookie = value; + } + } + + public StringValues HeaderExpect + { + get + { + if (((_bits & 67108864L) != 0)) + { + return _Expect; + } + else + { + return StringValues.Empty; + } + } + set + { + _bits |= 67108864L; + _Expect = value; + } + } + + public StringValues HeaderFrom + { + get + { + if (((_bits & 134217728L) != 0)) + { + return _From; + } + else + { + return StringValues.Empty; + } + } + set + { + _bits |= 134217728L; + _From = value; + } + } + + public StringValues HeaderHost + { + get + { + if (((_bits & 268435456L) != 0)) + { + return _Host; + } + else + { + return StringValues.Empty; + } + } + set + { + _bits |= 268435456L; + _Host = value; + } + } + + public StringValues HeaderIfMatch + { + get + { + if (((_bits & 536870912L) != 0)) + { + return _IfMatch; + } + else + { + return StringValues.Empty; + } + } + set + { + _bits |= 536870912L; + _IfMatch = value; + } + } + + public StringValues HeaderIfModifiedSince + { + get + { + if (((_bits & 1073741824L) != 0)) + { + return _IfModifiedSince; + } + else + { + return StringValues.Empty; + } + } + set + { + _bits |= 1073741824L; + _IfModifiedSince = value; + } + } + + public StringValues HeaderIfNoneMatch + { + get + { + if (((_bits & 2147483648L) != 0)) + { + return _IfNoneMatch; + } + else + { + return StringValues.Empty; + } + } + set + { + _bits |= 2147483648L; + _IfNoneMatch = value; + } + } + + public StringValues HeaderIfRange + { + get + { + if (((_bits & 4294967296L) != 0)) + { + return _IfRange; + } + else + { + return StringValues.Empty; + } + } + set + { + _bits |= 4294967296L; + _IfRange = value; + } + } + + public StringValues HeaderIfUnmodifiedSince + { + get + { + if (((_bits & 8589934592L) != 0)) + { + return _IfUnmodifiedSince; + } + else + { + return StringValues.Empty; + } + } + set + { + _bits |= 8589934592L; + _IfUnmodifiedSince = value; + } + } + + public StringValues HeaderMaxForwards + { + get + { + if (((_bits & 17179869184L) != 0)) + { + return _MaxForwards; + } + else + { + return StringValues.Empty; + } + } + set + { + _bits |= 17179869184L; + _MaxForwards = value; + } + } + + public StringValues HeaderProxyAuthorization + { + get + { + if (((_bits & 34359738368L) != 0)) + { + return _ProxyAuthorization; + } + else + { + return StringValues.Empty; + } + } + set + { + _bits |= 34359738368L; + _ProxyAuthorization = value; + } + } + + public StringValues HeaderReferer + { + get + { + if (((_bits & 68719476736L) != 0)) + { + return _Referer; + } + else + { + return StringValues.Empty; + } + } + set + { + _bits |= 68719476736L; + _Referer = value; + } + } + + public StringValues HeaderRange + { + get + { + if (((_bits & 137438953472L) != 0)) + { + return _Range; + } + else + { + return StringValues.Empty; + } + } + set + { + _bits |= 137438953472L; + _Range = value; + } + } + + public StringValues HeaderTE + { + get + { + if (((_bits & 274877906944L) != 0)) + { + return _TE; + } + else + { + return StringValues.Empty; + } + } + set + { + _bits |= 274877906944L; + _TE = value; + } + } + + public StringValues HeaderTranslate + { + get + { + if (((_bits & 549755813888L) != 0)) + { + return _Translate; + } + else + { + return StringValues.Empty; + } + } + set + { + _bits |= 549755813888L; + _Translate = value; + } + } + + public StringValues HeaderUserAgent + { + get + { + if (((_bits & 1099511627776L) != 0)) + { + return _UserAgent; + } + else + { + return StringValues.Empty; + } + } + set + { + _bits |= 1099511627776L; + _UserAgent = value; + } + } + + protected override int GetCountFast() { var count = MaybeUnknown?.Count ?? 0; @@ -2993,6 +3806,48 @@ namespace Microsoft.AspNet.Server.Kestrel.Http protected override void ClearFast() { _bits = 0; + + _CacheControl = StringValues.Empty; + _Connection = StringValues.Empty; + _Date = StringValues.Empty; + _KeepAlive = StringValues.Empty; + _Pragma = StringValues.Empty; + _Trailer = StringValues.Empty; + _TransferEncoding = StringValues.Empty; + _Upgrade = StringValues.Empty; + _Via = StringValues.Empty; + _Warning = StringValues.Empty; + _Allow = StringValues.Empty; + _ContentLength = StringValues.Empty; + _ContentType = StringValues.Empty; + _ContentEncoding = StringValues.Empty; + _ContentLanguage = StringValues.Empty; + _ContentLocation = StringValues.Empty; + _ContentMD5 = StringValues.Empty; + _ContentRange = StringValues.Empty; + _Expires = StringValues.Empty; + _LastModified = StringValues.Empty; + _Accept = StringValues.Empty; + _AcceptCharset = StringValues.Empty; + _AcceptEncoding = StringValues.Empty; + _AcceptLanguage = StringValues.Empty; + _Authorization = StringValues.Empty; + _Cookie = StringValues.Empty; + _Expect = StringValues.Empty; + _From = StringValues.Empty; + _Host = StringValues.Empty; + _IfMatch = StringValues.Empty; + _IfModifiedSince = StringValues.Empty; + _IfNoneMatch = StringValues.Empty; + _IfRange = StringValues.Empty; + _IfUnmodifiedSince = StringValues.Empty; + _MaxForwards = StringValues.Empty; + _ProxyAuthorization = StringValues.Empty; + _Referer = StringValues.Empty; + _Range = StringValues.Empty; + _TE = StringValues.Empty; + _Translate = StringValues.Empty; + _UserAgent = StringValues.Empty; MaybeUnknown?.Clear(); } @@ -4620,6 +5475,608 @@ namespace Microsoft.AspNet.Server.Kestrel.Http private StringValues _Vary; private StringValues _WWWAuthenticate; + + public StringValues HeaderCacheControl + { + get + { + if (((_bits & 1L) != 0)) + { + return _CacheControl; + } + else + { + return StringValues.Empty; + } + } + set + { + _bits |= 1L; + _CacheControl = value; + } + } + + public StringValues HeaderConnection + { + get + { + if (((_bits & 2L) != 0)) + { + return _Connection; + } + else + { + return StringValues.Empty; + } + } + set + { + _bits |= 2L; + _Connection = value; + } + } + + public StringValues HeaderDate + { + get + { + if (((_bits & 4L) != 0)) + { + return _Date; + } + else + { + return StringValues.Empty; + } + } + set + { + _bits |= 4L; + _Date = value; + } + } + + public StringValues HeaderKeepAlive + { + get + { + if (((_bits & 8L) != 0)) + { + return _KeepAlive; + } + else + { + return StringValues.Empty; + } + } + set + { + _bits |= 8L; + _KeepAlive = value; + } + } + + public StringValues HeaderPragma + { + get + { + if (((_bits & 16L) != 0)) + { + return _Pragma; + } + else + { + return StringValues.Empty; + } + } + set + { + _bits |= 16L; + _Pragma = value; + } + } + + public StringValues HeaderTrailer + { + get + { + if (((_bits & 32L) != 0)) + { + return _Trailer; + } + else + { + return StringValues.Empty; + } + } + set + { + _bits |= 32L; + _Trailer = value; + } + } + + public StringValues HeaderTransferEncoding + { + get + { + if (((_bits & 64L) != 0)) + { + return _TransferEncoding; + } + else + { + return StringValues.Empty; + } + } + set + { + _bits |= 64L; + _TransferEncoding = value; + } + } + + public StringValues HeaderUpgrade + { + get + { + if (((_bits & 128L) != 0)) + { + return _Upgrade; + } + else + { + return StringValues.Empty; + } + } + set + { + _bits |= 128L; + _Upgrade = value; + } + } + + public StringValues HeaderVia + { + get + { + if (((_bits & 256L) != 0)) + { + return _Via; + } + else + { + return StringValues.Empty; + } + } + set + { + _bits |= 256L; + _Via = value; + } + } + + public StringValues HeaderWarning + { + get + { + if (((_bits & 512L) != 0)) + { + return _Warning; + } + else + { + return StringValues.Empty; + } + } + set + { + _bits |= 512L; + _Warning = value; + } + } + + public StringValues HeaderAllow + { + get + { + if (((_bits & 1024L) != 0)) + { + return _Allow; + } + else + { + return StringValues.Empty; + } + } + set + { + _bits |= 1024L; + _Allow = value; + } + } + + public StringValues HeaderContentLength + { + get + { + if (((_bits & 2048L) != 0)) + { + return _ContentLength; + } + else + { + return StringValues.Empty; + } + } + set + { + _bits |= 2048L; + _ContentLength = value; + } + } + + public StringValues HeaderContentType + { + get + { + if (((_bits & 4096L) != 0)) + { + return _ContentType; + } + else + { + return StringValues.Empty; + } + } + set + { + _bits |= 4096L; + _ContentType = value; + } + } + + public StringValues HeaderContentEncoding + { + get + { + if (((_bits & 8192L) != 0)) + { + return _ContentEncoding; + } + else + { + return StringValues.Empty; + } + } + set + { + _bits |= 8192L; + _ContentEncoding = value; + } + } + + public StringValues HeaderContentLanguage + { + get + { + if (((_bits & 16384L) != 0)) + { + return _ContentLanguage; + } + else + { + return StringValues.Empty; + } + } + set + { + _bits |= 16384L; + _ContentLanguage = value; + } + } + + public StringValues HeaderContentLocation + { + get + { + if (((_bits & 32768L) != 0)) + { + return _ContentLocation; + } + else + { + return StringValues.Empty; + } + } + set + { + _bits |= 32768L; + _ContentLocation = value; + } + } + + public StringValues HeaderContentMD5 + { + get + { + if (((_bits & 65536L) != 0)) + { + return _ContentMD5; + } + else + { + return StringValues.Empty; + } + } + set + { + _bits |= 65536L; + _ContentMD5 = value; + } + } + + public StringValues HeaderContentRange + { + get + { + if (((_bits & 131072L) != 0)) + { + return _ContentRange; + } + else + { + return StringValues.Empty; + } + } + set + { + _bits |= 131072L; + _ContentRange = value; + } + } + + public StringValues HeaderExpires + { + get + { + if (((_bits & 262144L) != 0)) + { + return _Expires; + } + else + { + return StringValues.Empty; + } + } + set + { + _bits |= 262144L; + _Expires = value; + } + } + + public StringValues HeaderLastModified + { + get + { + if (((_bits & 524288L) != 0)) + { + return _LastModified; + } + else + { + return StringValues.Empty; + } + } + set + { + _bits |= 524288L; + _LastModified = value; + } + } + + public StringValues HeaderAcceptRanges + { + get + { + if (((_bits & 1048576L) != 0)) + { + return _AcceptRanges; + } + else + { + return StringValues.Empty; + } + } + set + { + _bits |= 1048576L; + _AcceptRanges = value; + } + } + + public StringValues HeaderAge + { + get + { + if (((_bits & 2097152L) != 0)) + { + return _Age; + } + else + { + return StringValues.Empty; + } + } + set + { + _bits |= 2097152L; + _Age = value; + } + } + + public StringValues HeaderETag + { + get + { + if (((_bits & 4194304L) != 0)) + { + return _ETag; + } + else + { + return StringValues.Empty; + } + } + set + { + _bits |= 4194304L; + _ETag = value; + } + } + + public StringValues HeaderLocation + { + get + { + if (((_bits & 8388608L) != 0)) + { + return _Location; + } + else + { + return StringValues.Empty; + } + } + set + { + _bits |= 8388608L; + _Location = value; + } + } + + public StringValues HeaderProxyAutheticate + { + get + { + if (((_bits & 16777216L) != 0)) + { + return _ProxyAutheticate; + } + else + { + return StringValues.Empty; + } + } + set + { + _bits |= 16777216L; + _ProxyAutheticate = value; + } + } + + public StringValues HeaderRetryAfter + { + get + { + if (((_bits & 33554432L) != 0)) + { + return _RetryAfter; + } + else + { + return StringValues.Empty; + } + } + set + { + _bits |= 33554432L; + _RetryAfter = value; + } + } + + public StringValues HeaderServer + { + get + { + if (((_bits & 67108864L) != 0)) + { + return _Server; + } + else + { + return StringValues.Empty; + } + } + set + { + _bits |= 67108864L; + _Server = value; + } + } + + public StringValues HeaderSetCookie + { + get + { + if (((_bits & 134217728L) != 0)) + { + return _SetCookie; + } + else + { + return StringValues.Empty; + } + } + set + { + _bits |= 134217728L; + _SetCookie = value; + } + } + + public StringValues HeaderVary + { + get + { + if (((_bits & 268435456L) != 0)) + { + return _Vary; + } + else + { + return StringValues.Empty; + } + } + set + { + _bits |= 268435456L; + _Vary = value; + } + } + + public StringValues HeaderWWWAuthenticate + { + get + { + if (((_bits & 536870912L) != 0)) + { + return _WWWAuthenticate; + } + else + { + return StringValues.Empty; + } + } + set + { + _bits |= 536870912L; + _WWWAuthenticate = value; + } + } + + protected override int GetCountFast() { var count = MaybeUnknown?.Count ?? 0; @@ -6790,6 +8247,37 @@ namespace Microsoft.AspNet.Server.Kestrel.Http protected override void ClearFast() { _bits = 0; + + _CacheControl = StringValues.Empty; + _Connection = StringValues.Empty; + _Date = StringValues.Empty; + _KeepAlive = StringValues.Empty; + _Pragma = StringValues.Empty; + _Trailer = StringValues.Empty; + _TransferEncoding = StringValues.Empty; + _Upgrade = StringValues.Empty; + _Via = StringValues.Empty; + _Warning = StringValues.Empty; + _Allow = StringValues.Empty; + _ContentLength = StringValues.Empty; + _ContentType = StringValues.Empty; + _ContentEncoding = StringValues.Empty; + _ContentLanguage = StringValues.Empty; + _ContentLocation = StringValues.Empty; + _ContentMD5 = StringValues.Empty; + _ContentRange = StringValues.Empty; + _Expires = StringValues.Empty; + _LastModified = StringValues.Empty; + _AcceptRanges = StringValues.Empty; + _Age = StringValues.Empty; + _ETag = StringValues.Empty; + _Location = StringValues.Empty; + _ProxyAutheticate = StringValues.Empty; + _RetryAfter = StringValues.Empty; + _Server = StringValues.Empty; + _SetCookie = StringValues.Empty; + _Vary = StringValues.Empty; + _WWWAuthenticate = StringValues.Empty; MaybeUnknown?.Clear(); } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameHeaders.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameHeaders.cs index 526c7326d9..57440c3434 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameHeaders.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameHeaders.cs @@ -21,7 +21,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { return GetValueFast(key); } - set { SetValueFast(key, value); @@ -36,6 +35,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http ICollection IDictionary.Values => ((IDictionary)this).Select(pair => pair.Value).ToList(); + public void Reset() + { + ClearFast(); + } + protected static StringValues AppendValue(StringValues existing, string append) { return StringValues.Concat(existing, append); diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameRequestStream.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameRequestStream.cs index c5f178464e..3bf79ca3cc 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameRequestStream.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameRequestStream.cs @@ -72,13 +72,13 @@ namespace Microsoft.AspNet.Server.Kestrel.Http public override Task ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) { - return _body.ReadAsync(new ArraySegment(buffer, offset, count)); + return _body.ReadAsync(new ArraySegment(buffer, offset, count), cancellationToken); } public Task ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken, object state) { var tcs = new TaskCompletionSource(state); - var task = _body.ReadAsync(new ArraySegment(buffer, offset, count)); + var task = _body.ReadAsync(new ArraySegment(buffer, offset, count), cancellationToken); task.ContinueWith((task2, state2) => { var tcs2 = (TaskCompletionSource)state2; diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs index 316c5318d9..9cf57b5b4a 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs @@ -15,6 +15,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { protected Listener(ServiceContext serviceContext) : base(serviceContext) { + Memory2 = new MemoryPool2(); } protected UvStreamHandle ListenSocket { get; private set; } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerContext.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerContext.cs index c0f042b4cc..d7e8d1f022 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerContext.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerContext.cs @@ -22,6 +22,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http Thread = listenerContext.Thread; Application = listenerContext.Application; Memory = listenerContext.Memory; + Memory2 = listenerContext.Memory2; Log = listenerContext.Log; } @@ -31,6 +32,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http public IMemoryPool Memory { get; set; } + public MemoryPool2 Memory2 { get; set; } + public IKestrelTrace Log { get; } } } \ No newline at end of file diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerSecondary.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerSecondary.cs index 0334c39d68..e50a69071c 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerSecondary.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerSecondary.cs @@ -59,7 +59,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http DispatchPipe.ReadStart( (_1, _2, _3) => buf, - (_1, status2, error2, state2) => + (_1, status2, errCode, error2, state2) => { if (status2 < 0) { diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/MemoryPool2.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/MemoryPool2.cs new file mode 100644 index 0000000000..0ad2ea8645 --- /dev/null +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/MemoryPool2.cs @@ -0,0 +1,109 @@ +using System; +using System.Collections.Concurrent; +using System.Diagnostics; +using System.Runtime.InteropServices; + +namespace Microsoft.AspNet.Server.Kestrel.Http +{ + public class MemoryPool2 : IDisposable + { + private const int blockStride = 4096; + private const int blockUnused = 64; + private const int blockCount = 32; + private const int blockLength = blockStride - blockUnused; + private const int slabLength = blockStride * blockCount; + + private ConcurrentStack _blocks = new ConcurrentStack(); + private ConcurrentStack _slabs = new ConcurrentStack(); + + public MemoryPoolBlock2 Lease(int minimumSize) + { + if (minimumSize > blockLength) + { + return MemoryPoolBlock2.Create( + new ArraySegment(new byte[minimumSize]), + dataPtr: IntPtr.Zero, + pool: null, + slab: null); + } + + for (;;) + { + MemoryPoolBlock2 block; + if (_blocks.TryPop(out block)) + { + return block; + } + AllocateSlab(); + } + } + + private void AllocateSlab() + { + var slab = MemoryPoolSlab2.Create(slabLength); + _slabs.Push(slab); + + var basePtr = slab.ArrayPtr; + var firstOffset = (blockStride - 1) - ((ushort)(basePtr + blockStride - 1) % blockStride); + + for (var offset = firstOffset; + offset + blockLength <= slabLength; + offset += blockStride) + { + var block = MemoryPoolBlock2.Create( + new ArraySegment(slab.Array, offset, blockLength), + basePtr, + this, + slab); + Return(block); + } + } + + public void Return(MemoryPoolBlock2 block) + { + block.Reset(); + _blocks.Push(block); + } + + #region IDisposable Support + private bool disposedValue = false; // To detect redundant calls + + protected virtual void Dispose(bool disposing) + { + if (!disposedValue) + { + if (disposing) + { + MemoryPoolSlab2 slab; + while (_slabs.TryPop(out slab)) + { + // dispose managed state (managed objects). + slab.Dispose(); + } + } + + // N/A: free unmanaged resources (unmanaged objects) and override a finalizer below. + + // N/A: set large fields to null. + + disposedValue = true; + } + } + + // N/A: override a finalizer only if Dispose(bool disposing) above has code to free unmanaged resources. + // ~MemoryPool2() { + // // Do not change this code. Put cleanup code in Dispose(bool disposing) above. + // Dispose(false); + // } + + // This code added to correctly implement the disposable pattern. + public void Dispose() + { + // Do not change this code. Put cleanup code in Dispose(bool disposing) above. + Dispose(true); + // N/A: uncomment the following line if the finalizer is overridden above. + // GC.SuppressFinalize(this); + } + #endregion + } +} diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/MemoryPoolBlock2.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/MemoryPoolBlock2.cs new file mode 100644 index 0000000000..8bb913ed6e --- /dev/null +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/MemoryPoolBlock2.cs @@ -0,0 +1,479 @@ +using System; +using System.Collections.Concurrent; +using System.Diagnostics; +using System.Linq; +using System.Numerics; +using System.Runtime.InteropServices; +using System.Text; + +namespace Microsoft.AspNet.Server.Kestrel.Http +{ + public class MemoryPoolBlock2 + { + private static Vector _dotIndex = new Vector(Enumerable.Range(0, Vector.Count).Select(x => (byte)-x).ToArray()); + private static Vector _dotCount = new Vector(Byte.MaxValue); + + private GCHandle _pinHandle; + private IntPtr _dataArrayPtr; + + public ArraySegment Data; + + protected MemoryPoolBlock2() + { + } + + public MemoryPool2 Pool { get; private set; } + + public MemoryPoolSlab2 Slab { get; private set; } + + public byte[] Array => Data.Array; + public int Start { get; set; } + public int End { get; set; } + public MemoryPoolBlock2 Next { get; set; } + + ~MemoryPoolBlock2() + { + if (_pinHandle.IsAllocated) + { + _pinHandle.Free(); + } + + if (Slab != null && Slab.IsActive) + { + Pool.Return(new MemoryPoolBlock2 + { + _dataArrayPtr = _dataArrayPtr, + Data = Data, + Pool = Pool, + Slab = Slab, + }); + } + } + + public IntPtr Pin() + { + Debug.Assert(!_pinHandle.IsAllocated); + + if (_dataArrayPtr != IntPtr.Zero) + { + return _dataArrayPtr + End; + } + else + { + _pinHandle = GCHandle.Alloc(Data.Array, GCHandleType.Pinned); + return _pinHandle.AddrOfPinnedObject() + End; + } + } + + public void Unpin() + { + if (_dataArrayPtr == IntPtr.Zero) + { + Debug.Assert(_pinHandle.IsAllocated); + _pinHandle.Free(); + } + } + + public static MemoryPoolBlock2 Create(int size, MemoryPool2 pool) + { + return new MemoryPoolBlock2 + { + Data = new ArraySegment(new byte[size]), + Pool = pool + }; + } + + public static MemoryPoolBlock2 Create( + ArraySegment data, + IntPtr dataPtr, + MemoryPool2 pool, + MemoryPoolSlab2 slab) + { + return new MemoryPoolBlock2 + { + Data = data, + _dataArrayPtr = dataPtr, + Pool = pool, + Slab = slab, + Start = data.Offset, + End = data.Offset, + }; + } + + public void Reset() + { + Next = null; + Start = Data.Offset; + End = Data.Offset; + } + + public override string ToString() + { + return Encoding.ASCII.GetString(Array, Start, End - Start); + } + + public Iterator GetIterator() + { + return new Iterator(this); + } + + public struct Iterator + { + private MemoryPoolBlock2 _block; + private int _index; + + public Iterator(MemoryPoolBlock2 block) + { + _block = block; + _index = _block?.Start ?? 0; + } + public Iterator(MemoryPoolBlock2 block, int index) + { + _block = block; + _index = index; + } + + public bool IsDefault => _block == null; + + public MemoryPoolBlock2 Block => _block; + + public int Index => _index; + + public bool HasAtLeast(int count) + { + var scan = _block; + var index = _index; + while (scan != null) + { + if (count <= scan.End - index) + { + return true; + } + count -= scan.End - index; + scan = scan.Next; + index = scan?.Start ?? 0; + } + return false; + } + + public Iterator Add(int count) + { + var block = _block; + var index = _index; + while (block != null) + { + var tailCount = block.End - index; + if (count < tailCount) + { + return new Iterator(block, index + count); + } + count -= tailCount; + block = block.Next; + index = block?.Start ?? 0; + } + return new Iterator(block, index + count); + } + + public Iterator CopyTo(byte[] array, int offset, int count, out int actual) + { + var block = _block; + var index = _index; + var remaining = count; + while (block != null && remaining != 0) + { + var copyLength = Math.Min(remaining, block.End - index); + Buffer.BlockCopy(block.Array, index, array, offset, copyLength); + index += copyLength; + offset += copyLength; + remaining -= copyLength; + if (index == block.End) + { + block = block.Next; + index = block?.Start ?? 0; + } + } + actual = count - remaining; + return new Iterator(block, index); + } + + public char MoveNext() + { + var block = _block; + var index = _index; + while (block != null && index == block.End) + { + block = block.Next; + index = block?.Start ?? 0; + } + if (block != null) + { + ++index; + } + while (block != null && index == block.End) + { + block = block.Next; + index = block?.Start ?? 0; + } + _block = block; + _index = index; + return block != null ? (char)block.Array[index] : char.MinValue; + } + + public int Peek() + { + while (_block != null) + { + if (_index < _block.End) + { + return _block.Data.Array[_index]; + } + _block = _block.Next; + _index = _block.Start; + } + return -1; + } + + public Iterator IndexOf(char char0) + { + var byte0 = (byte)char0; + var vectorStride = Vector.Count; + var ch0Vector = new Vector(byte0); + + var scanBlock = _block; + var scanArray = scanBlock?.Array; + var scanIndex = _index; + while (scanBlock != null) + { + var tailCount = scanBlock.End - scanIndex; + if (tailCount == 0) + { + scanBlock = scanBlock.Next; + scanArray = scanBlock?.Array; + scanIndex = scanBlock?.Start ?? 0; + continue; + } + if (tailCount >= vectorStride) + { + var data = new Vector(scanBlock.Array, scanIndex); + var ch0Equals = Vector.Equals(data, ch0Vector); + var ch0Count = Vector.Dot(ch0Equals, _dotCount); + + if (ch0Count == 0) + { + scanIndex += vectorStride; + continue; + } + else if (ch0Count == 1) + { + return new Iterator(scanBlock, scanIndex + Vector.Dot(ch0Equals, _dotIndex)); + } + else + { + tailCount = vectorStride; + } + } + for (; tailCount != 0; tailCount--, scanIndex++) + { + var ch = scanBlock.Array[scanIndex]; + if (ch == byte0) + { + return new Iterator(scanBlock, scanIndex); + } + } + } + return new Iterator(null, 0); + } + + public Iterator IndexOfAny(char char0, char char1, out char chFound) + { + var byte0 = (byte)char0; + var byte1 = (byte)char1; + var vectorStride = Vector.Count; + var ch0Vector = new Vector(byte0); + var ch1Vector = new Vector(byte1); + + var scanBlock = _block; + var scanArray = scanBlock?.Array; + var scanIndex = _index; + while (scanBlock != null) + { + var tailCount = scanBlock.End - scanIndex; + if (tailCount == 0) + { + scanBlock = scanBlock.Next; + scanArray = scanBlock?.Array; + scanIndex = scanBlock?.Start ?? 0; + continue; + } + if (tailCount >= vectorStride) + { + var data = new Vector(scanBlock.Array, scanIndex); + var ch0Equals = Vector.Equals(data, ch0Vector); + var ch0Count = Vector.Dot(ch0Equals, _dotCount); + var ch1Equals = Vector.Equals(data, ch1Vector); + var ch1Count = Vector.Dot(ch1Equals, _dotCount); + + if (ch0Count == 0 && ch1Count == 0) + { + scanIndex += vectorStride; + continue; + } + else if (ch0Count < 2 && ch1Count < 2) + { + var ch0Index = ch0Count == 1 ? Vector.Dot(ch0Equals, _dotIndex) : byte.MaxValue; + var ch1Index = ch1Count == 1 ? Vector.Dot(ch1Equals, _dotIndex) : byte.MaxValue; + if (ch0Index < ch1Index) + { + chFound = char0; + return new Iterator(scanBlock, scanIndex + ch0Index); + } + else + { + chFound = char1; + return new Iterator(scanBlock, scanIndex + ch1Index); + } + } + else + { + tailCount = vectorStride; + } + } + for (; tailCount != 0; tailCount--, scanIndex++) + { + var chIndex = scanBlock.Array[scanIndex]; + if (chIndex == byte0) + { + chFound = char0; + return new Iterator(scanBlock, scanIndex); + } + else if (chIndex == byte1) + { + chFound = char1; + return new Iterator(scanBlock, scanIndex); + } + } + } + chFound = char.MinValue; + return new Iterator(null, 0); + } + + public int GetLength(Iterator end) + { + var length = 0; + var block = _block; + var index = _index; + for (;;) + { + if (block == end._block) + { + return length + end._index - index; + } + if (block == null) + { + throw new Exception("end was not after iterator"); + } + length += block.End - index; + block = block.Next; + index = block?.Start ?? 0; + } + } + + public string GetString(Iterator end) + { + if (IsDefault || end.IsDefault) + { + return default(string); + } + if (end._block == _block) + { + return Encoding.ASCII.GetString(_block.Array, _index, end._index - _index); + } + if (end._block == _block.Next && end._index == end._block.Start) + { + return Encoding.ASCII.GetString(_block.Array, _index, _block.End - _index); + } + + var length = GetLength(end); + var result = new char[length]; + var offset = 0; + var decoder = Encoding.ASCII.GetDecoder(); + + var block = _block; + var index = _index; + while (length != 0) + { + if (block == null) + { + throw new Exception("Unexpected end of data"); + } + + var count = Math.Min(block.End - index, length); + + int bytesUsed; + int textAdded; + bool completed; + decoder.Convert( + block.Array, + index, + count, + result, + offset, + length, + count == length, + out bytesUsed, + out textAdded, + out completed); + + Debug.Assert(bytesUsed == count); + Debug.Assert(textAdded == count); + offset += count; + length -= count; + + block = block.Next; + index = block?.Start ?? 0; + } + return new string(result); + } + + public ArraySegment GetArraySegment(Iterator end) + { + if (IsDefault || end.IsDefault) + { + return default(ArraySegment); + } + if (end._block == _block) + { + return new ArraySegment(_block.Array, _index, end._index - _index); + } + if (end._block == _block.Next && end._index == end._block.Start) + { + return new ArraySegment(_block.Array, _index, _block.End - _index); + } + + var length = GetLength(end); + var result = new ArraySegment(new byte[length]); + var offset = result.Offset; + + var block = _block; + var index = _index; + while (length != 0) + { + if (block == null) + { + throw new Exception("Unexpected end of data"); + } + + var count = Math.Min(block.End - index, length); + Buffer.BlockCopy(block.Array, index, result.Array, offset, count); + offset += count; + length -= count; + + block = block.Next; + index = block?.Start ?? 0; + } + + return result; + } + } + } +} diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/MemoryPoolSlab2.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/MemoryPoolSlab2.cs new file mode 100644 index 0000000000..561d26d4df --- /dev/null +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/MemoryPoolSlab2.cs @@ -0,0 +1,68 @@ +using System; +using System.Collections.Concurrent; +using System.Diagnostics; +using System.Runtime.InteropServices; + +namespace Microsoft.AspNet.Server.Kestrel.Http +{ + public class MemoryPoolSlab2 : IDisposable + { + private GCHandle _gcHandle; + public byte[] Array; + public IntPtr ArrayPtr; + public bool IsActive; + + public static MemoryPoolSlab2 Create(int length) + { + var array = new byte[length]; + var gcHandle = GCHandle.Alloc(array, GCHandleType.Pinned); + return new MemoryPoolSlab2 + { + Array = array, + _gcHandle = gcHandle, + ArrayPtr = gcHandle.AddrOfPinnedObject(), + IsActive = true, + }; + } + + #region IDisposable Support + private bool disposedValue = false; // To detect redundant calls + + protected virtual void Dispose(bool disposing) + { + if (!disposedValue) + { + if (disposing) + { + // N/A: dispose managed state (managed objects). + } + + // free unmanaged resources (unmanaged objects) and override a finalizer below. + IsActive = false; + _gcHandle.Free(); + + // set large fields to null. + Array = null; + + disposedValue = true; + } + } + + // override a finalizer only if Dispose(bool disposing) above has code to free unmanaged resources. + ~MemoryPoolSlab2() + { + // Do not change this code. Put cleanup code in Dispose(bool disposing) above. + Dispose(false); + } + + // This code added to correctly implement the disposable pattern. + public void Dispose() + { + // Do not change this code. Put cleanup code in Dispose(bool disposing) above. + Dispose(true); + // uncomment the following line if the finalizer is overridden above. + GC.SuppressFinalize(this); + } + #endregion + } +} diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/MessageBody.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/MessageBody.cs index c846b9c3ba..2e78402899 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/MessageBody.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/MessageBody.cs @@ -3,6 +3,8 @@ using System; using System.Collections.Generic; +using System.Threading; +using System.Threading.Tasks; using Microsoft.Framework.Primitives; namespace Microsoft.AspNet.Server.Kestrel.Http @@ -15,18 +17,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Http public bool RequestKeepAlive { get; protected set; } - public void Intake(int count) - { - Transfer(count, false); - } - - public void IntakeFin(int count) - { - Transfer(count, true); - } - - public abstract void Consume(); - public static MessageBody For( string httpVersion, IDictionary headers, @@ -93,48 +83,49 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { } - public override void Consume() + public override async Task ReadAsyncImplementation(ArraySegment buffer, CancellationToken cancellationToken) { var input = _context.SocketInput; - if (input.RemoteIntakeFin) - { - IntakeFin(input.Buffer.Count); - } - else - { - Intake(input.Buffer.Count); - } + await input; + + var begin = input.GetIterator(); + int actual; + var end = begin.CopyTo(buffer.Array, buffer.Offset, buffer.Count, out actual); + input.JumpTo(end); + return actual; } } class ForContentLength : MessageBody { private readonly int _contentLength; - private int _neededLength; + private int _inputLength; public ForContentLength(bool keepAlive, int contentLength, FrameContext context) : base(context) { RequestKeepAlive = keepAlive; _contentLength = contentLength; - _neededLength = _contentLength; + _inputLength = _contentLength; } - - public override void Consume() + + public override async Task ReadAsyncImplementation(ArraySegment buffer, CancellationToken cancellationToken) { var input = _context.SocketInput; - var consumeLength = Math.Min(_neededLength, input.Buffer.Count); - _neededLength -= consumeLength; - if (_neededLength != 0) + var limit = Math.Min(buffer.Count, _inputLength); + if (limit != 0) { - Intake(consumeLength); - } - else - { - IntakeFin(consumeLength); + await input; } + + var begin = input.GetIterator(); + int actual; + var end = begin.CopyTo(buffer.Array, buffer.Offset, limit, out actual); + _inputLength -= actual; + input.JumpTo(end); + return actual; } } @@ -144,9 +135,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Http /// class ForChunkedEncoding : MessageBody { - private int _neededLength; + private int _inputLength; - private Mode _mode = Mode.ChunkSizeLine; + private Mode _mode = Mode.ChunkPrefix; public ForChunkedEncoding(bool keepAlive, FrameContext context) : base(context) @@ -154,80 +145,83 @@ namespace Microsoft.AspNet.Server.Kestrel.Http RequestKeepAlive = keepAlive; } - public override void Consume() + public override async Task ReadAsyncImplementation(ArraySegment buffer, CancellationToken cancellationToken) { var input = _context.SocketInput; - for (; ;) + + while (_mode != Mode.Complete) { - switch (_mode) + while (_mode == Mode.ChunkPrefix) { - case Mode.ChunkSizeLine: - var chunkSize = 0; - if (!TakeChunkedLine(input, ref chunkSize)) - { - return; - } - - _neededLength = chunkSize; - if (chunkSize == 0) - { - _mode = Mode.Complete; - IntakeFin(0); - return; - } + var chunkSize = 0; + if (!TakeChunkedLine(input, ref chunkSize)) + { + await input; + } + else if (chunkSize == 0) + { + _mode = Mode.Complete; + } + else + { _mode = Mode.ChunkData; - break; + } + _inputLength = chunkSize; + } + while (_mode == Mode.ChunkData) + { + var limit = Math.Min(buffer.Count, _inputLength); + if (limit != 0) + { + await input; + } - case Mode.ChunkData: - if (_neededLength == 0) - { - _mode = Mode.ChunkDataCRLF; - break; - } - if (input.Buffer.Count == 0) - { - return; - } + var begin = input.GetIterator(); + int actual; + var end = begin.CopyTo(buffer.Array, buffer.Offset, limit, out actual); + _inputLength -= actual; + input.JumpTo(end); - var consumeLength = Math.Min(_neededLength, input.Buffer.Count); - _neededLength -= consumeLength; + if (_inputLength == 0) + { + _mode = Mode.ChunkSuffix; + } - Intake(consumeLength); - break; - - case Mode.ChunkDataCRLF: - if (input.Buffer.Count < 2) - { - return; - } - var crlf = input.Take(2); - if (crlf.Array[crlf.Offset] != '\r' || - crlf.Array[crlf.Offset + 1] != '\n') - { - throw new NotImplementedException("INVALID REQUEST FORMAT"); - } - _mode = Mode.ChunkSizeLine; - break; - - default: + return actual; + } + while (_mode == Mode.ChunkSuffix) + { + var begin = input.GetIterator(); + var ch1 = begin.Peek(); + var ch2 = begin.MoveNext(); + if (ch1 == char.MinValue || ch2 == char.MinValue) + { + await input; + } + else if (ch1 == '\r' && ch2 == '\n') + { + input.JumpTo(begin.Add(1)); + _mode = Mode.ChunkPrefix; + } + else + { throw new NotImplementedException("INVALID REQUEST FORMAT"); + } } } + + return 0; } private static bool TakeChunkedLine(SocketInput baton, ref int chunkSizeOut) { - var remaining = baton.Buffer; - if (remaining.Count < 2) - { - return false; - } - var ch0 = remaining.Array[remaining.Offset]; + var remaining = baton.GetIterator(); + var ch0 = remaining.Peek(); var chunkSize = 0; var mode = 0; - for (var index = 0; index != remaining.Count - 1; ++index) + while(ch0 != -1) { - var ch1 = remaining.Array[remaining.Offset + index + 1]; + var ch1 = remaining.MoveNext(); if (mode == 0) { @@ -269,7 +263,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } else if (ch0 == '\r' && ch1 == '\n') { - baton.Skip(index + 2); + baton.JumpTo(remaining.Add(1)); chunkSizeOut = chunkSize; return true; } @@ -282,7 +276,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { if (ch0 == '\r' && ch1 == '\n') { - baton.Skip(index + 2); + baton.JumpTo(remaining.Add(1)); chunkSizeOut = chunkSize; return true; } @@ -299,9 +293,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Http private enum Mode { - ChunkSizeLine, + ChunkPrefix, ChunkData, - ChunkDataCRLF, + ChunkSuffix, Complete, }; } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/MessageBodyExchanger.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/MessageBodyExchanger.cs index 749f34433b..f0e72084fb 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/MessageBodyExchanger.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/MessageBodyExchanger.cs @@ -119,6 +119,31 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return result; } + public Task ReadAsync(ArraySegment buffer, CancellationToken cancellationToken) + { + Task result = null; + var send100Continue = false; + result = ReadAsyncImplementation(buffer, cancellationToken); + if (!result.IsCompleted) + { + lock (_sync) + { + send100Continue = _send100Continue; + _send100Continue = false; + } + } + if (send100Continue) + { + _context.FrameControl.ProduceContinue(); + } + return result; + } + + public virtual Task ReadAsyncImplementation(ArraySegment buffer, CancellationToken cancellationToken) + { + throw new NotImplementedException("TODO"); + } + static void CompletePending(object state) { while (((MessageBodyExchanger)state).CompletePending()) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketInput.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketInput.cs index 405ec68009..27f42c8a5e 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketInput.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketInput.cs @@ -3,25 +3,45 @@ using System; using System.Diagnostics; +using System.Runtime.CompilerServices; using System.Runtime.InteropServices; +using System.Threading; +using System.Threading.Tasks; namespace Microsoft.AspNet.Server.Kestrel.Http { - public class SocketInput + public class SocketInput : ICriticalNotifyCompletion { - private readonly IMemoryPool _memory; - private GCHandle _gcHandle; + private static readonly Action _awaitableIsCompleted = () => { }; + private static readonly Action _awaitableIsNotCompleted = () => { }; - public SocketInput(IMemoryPool memory) + private readonly MemoryPool2 _memory; + + private Action _awaitableState; + private Exception _awaitableError; + + private MemoryPoolBlock2 _head; + private MemoryPoolBlock2 _tail; + private MemoryPoolBlock2 _pinned; + private readonly object _syncHeadAndTail = new Object(); + + public SocketInput(MemoryPool2 memory) { _memory = memory; - Buffer = new ArraySegment(_memory.Empty, 0, 0); + _awaitableState = _awaitableIsNotCompleted; } public ArraySegment Buffer { get; set; } public bool RemoteIntakeFin { get; set; } + public bool IsCompleted + { + get + { + return Equals(_awaitableState, _awaitableIsCompleted); + } + } public void Skip(int count) { @@ -35,80 +55,183 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return taken; } - public void Free() + public PinResult Pin(int minimumSize) { - if (Buffer.Count == 0 && Buffer.Array.Length != 0) + lock (_syncHeadAndTail) { - _memory.FreeByte(Buffer.Array); - Buffer = new ArraySegment(_memory.Empty, 0, 0); - } - } - - public ArraySegment Available(int minimumSize) - { - if (Buffer.Count == 0 && Buffer.Offset != 0) - { - Buffer = new ArraySegment(Buffer.Array, 0, 0); - } - - var availableSize = Buffer.Array.Length - Buffer.Offset - Buffer.Count; - - if (availableSize < minimumSize) - { - if (availableSize + Buffer.Offset >= minimumSize) + if (_tail != null && minimumSize <= _tail.Data.Offset + _tail.Data.Count - _tail.End) { - Array.Copy(Buffer.Array, Buffer.Offset, Buffer.Array, 0, Buffer.Count); - if (Buffer.Count != 0) + _pinned = _tail; + var data = new ArraySegment(_pinned.Data.Array, _pinned.End, _pinned.Data.Offset + _pinned.Data.Count - _pinned.End); + var dataPtr = _pinned.Pin(); + return new PinResult { - Buffer = new ArraySegment(Buffer.Array, 0, Buffer.Count); - } - availableSize = Buffer.Array.Length - Buffer.Offset - Buffer.Count; - } - else - { - var largerSize = Buffer.Array.Length + Math.Max(Buffer.Array.Length, minimumSize); - var larger = new ArraySegment(_memory.AllocByte(largerSize), 0, Buffer.Count); - if (Buffer.Count != 0) - { - Array.Copy(Buffer.Array, Buffer.Offset, larger.Array, 0, Buffer.Count); - } - _memory.FreeByte(Buffer.Array); - Buffer = larger; - availableSize = Buffer.Array.Length - Buffer.Offset - Buffer.Count; + Data = data, + DataPtr = dataPtr, + }; } } - return new ArraySegment(Buffer.Array, Buffer.Offset + Buffer.Count, availableSize); - } - public void Extend(int count) - { - Debug.Assert(count >= 0); - Debug.Assert(Buffer.Offset >= 0); - Debug.Assert(Buffer.Offset <= Buffer.Array.Length); - Debug.Assert(Buffer.Offset + Buffer.Count <= Buffer.Array.Length); - Debug.Assert(Buffer.Offset + Buffer.Count + count <= Buffer.Array.Length); - - Buffer = new ArraySegment(Buffer.Array, Buffer.Offset, Buffer.Count + count); - } - - public IntPtr Pin(int minimumSize) - { - var segment = Available(minimumSize); - _gcHandle = GCHandle.Alloc(segment.Array, GCHandleType.Pinned); - return _gcHandle.AddrOfPinnedObject() + segment.Offset; + _pinned = _memory.Lease(minimumSize); + return new PinResult + { + Data = _pinned.Data, + DataPtr = _pinned.Pin() + }; } public void Unpin(int count) { - // read_cb may called without an earlier alloc_cb - // this does not need to be thread-safe - // IsAllocated is checked only because Unpin can be called redundantly - if (_gcHandle.IsAllocated) + // Unpin may called without an earlier Pin + if (_pinned != null) { - _gcHandle.Free(); - Extend(count); + lock (_syncHeadAndTail) + { + _pinned.End += count; + if (_head == null) + { + _head = _tail = _pinned; + } + else if (_tail == _pinned) + { + // NO-OP: this was a read into unoccupied tail-space + } + else + { + _tail.Next = _pinned; + _tail = _pinned; + } + } + _pinned = null; } } + public SocketInput GetAwaiter() + { + return this; + } + + + public void OnCompleted(Action continuation) + { + var awaitableState = Interlocked.CompareExchange( + ref _awaitableState, + continuation, + _awaitableIsNotCompleted); + + if (awaitableState == _awaitableIsNotCompleted) + { + return; + } + else if (awaitableState == _awaitableIsCompleted) + { + Task.Run(continuation); + } + else + { + // THIS IS AN ERROR STATE - ONLY ONE WAITER CAN WAIT + } + } + + public void UnsafeOnCompleted(Action continuation) + { + OnCompleted(continuation); + } + + public void SetCompleted(Exception error) + { + if (error != null) + { + _awaitableError = error; + } + + var awaitableState = Interlocked.Exchange( + ref _awaitableState, + _awaitableIsCompleted); + + if (awaitableState != _awaitableIsCompleted && + awaitableState != _awaitableIsNotCompleted) + { + Task.Run(awaitableState); + } + } + + public void SetNotCompleted() + { + if (RemoteIntakeFin || _awaitableError != null) + { + // TODO: Race condition - setting either of these can leave awaitable not completed + return; + } + var awaitableState = Interlocked.CompareExchange( + ref _awaitableState, + _awaitableIsNotCompleted, + _awaitableIsCompleted); + + if (awaitableState == _awaitableIsNotCompleted) + { + return; + } + else if (awaitableState == _awaitableIsCompleted) + { + return; + } + else + { + // THIS IS AN ERROR STATE - ONLY ONE WAITER MAY EXIST + } + } + + public void GetResult() + { + var error = _awaitableError; + if (error != null) + { + throw new AggregateException(error); + } + } + + public MemoryPoolBlock2.Iterator GetIterator() + { + lock (_syncHeadAndTail) + { + return new MemoryPoolBlock2.Iterator(_head); + } + } + + public void JumpTo(MemoryPoolBlock2.Iterator iterator) + { + MemoryPoolBlock2 returnStart; + MemoryPoolBlock2 returnEnd; + lock (_syncHeadAndTail) + { + // TODO: leave _pinned intact + + returnStart = _head; + returnEnd = iterator.Block; + _head = iterator.Block; + if (_head == null) + { + _tail = null; + SetNotCompleted(); + } + else + { + _head.Start = iterator.Index; + } + } + while (returnStart != returnEnd) + { + var returnBlock = returnStart; + returnStart = returnStart.Next; + returnBlock.Pool.Return(returnBlock); + } + } + + public struct PinResult + { + public ArraySegment Data; + public IntPtr DataPtr; + } } } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvStreamHandle.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvStreamHandle.cs index 574e1b466d..629a363278 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvStreamHandle.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvStreamHandle.cs @@ -19,7 +19,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking private GCHandle _listenVitality; public Func _allocCallback; - public Action _readCallback; + public Action _readCallback; public object _readState; private GCHandle _readVitality; @@ -72,7 +72,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking public void ReadStart( Func allocCallback, - Action readCallback, + Action readCallback, object state) { if (_readVitality.IsAllocated) @@ -163,11 +163,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking { Exception error; stream._uv.Check(nread, out error); - stream._readCallback(stream, 0, error, stream._readState); + stream._readCallback(stream, 0, nread, error, stream._readState); } else { - stream._readCallback(stream, nread, null, stream._readState); + stream._readCallback(stream, nread, 0, null, stream._readState); } } catch (Exception ex) diff --git a/src/Microsoft.AspNet.Server.Kestrel/project.json b/src/Microsoft.AspNet.Server.Kestrel/project.json index f0363ca83c..787728d2d4 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/project.json +++ b/src/Microsoft.AspNet.Server.Kestrel/project.json @@ -9,6 +9,7 @@ "Microsoft.AspNet.Hosting": "1.0.0-*", "Microsoft.Dnx.Runtime.Abstractions": "1.0.0-*", "Microsoft.Framework.Logging.Abstractions": "1.0.0-*", + "System.Numerics.Vectors": "4.1.1-beta-*", "Microsoft.StandardsPolice": { "version": "1.0.0-*", "type": "build" diff --git a/test/Microsoft.AspNet.Server.KestrelTests/FrameResponseHeadersTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/FrameResponseHeadersTests.cs index 1e3a5570eb..e97d76d142 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/FrameResponseHeadersTests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/FrameResponseHeadersTests.cs @@ -14,7 +14,8 @@ namespace Microsoft.AspNet.Server.KestrelTests [Fact] public void InitialDictionaryContainsServerAndDate() { - IDictionary headers = new FrameResponseHeaders(); + var frame = new Frame(new ConnectionContext()); + IDictionary headers = frame.ResponseHeaders; Assert.Equal(2, headers.Count); diff --git a/test/Microsoft.AspNet.Server.KestrelTests/MemoryPoolBlock2Tests.cs b/test/Microsoft.AspNet.Server.KestrelTests/MemoryPoolBlock2Tests.cs new file mode 100644 index 0000000000..c5f91b33ac --- /dev/null +++ b/test/Microsoft.AspNet.Server.KestrelTests/MemoryPoolBlock2Tests.cs @@ -0,0 +1,76 @@ +using Microsoft.AspNet.Server.Kestrel.Http; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Xunit; + +namespace Microsoft.AspNet.Server.KestrelTests +{ + public class MemoryPoolBlock2Tests + { + [Fact] + public void IndexOfAnyWorks() + { + using (var pool = new MemoryPool2()) + { + var block = pool.Lease(256); + foreach (var ch in Enumerable.Range(0, 256).Select(x => (byte)x)) + { + block.Array[block.End++] = ch; + } + var iterator = block.GetIterator(); + foreach (var ch in Enumerable.Range(0, 256).Select(x => (char)x)) + { + var hit = iterator.IndexOf(ch); + Assert.Equal(ch, iterator.GetLength(hit)); + } + } + } + + [Fact] + public void GetLengthBetweenIteratorsWorks() + { + using (var pool = new MemoryPool2()) + { + var block = pool.Lease(256); + block.End += 256; + TestAllLengths(block, 256); + pool.Return(block); + block = null; + + for (var fragment = 0; fragment != 256; fragment += 4) + { + var next = block; + block = pool.Lease(4); + block.Next = next; + block.End += 4; + } + + TestAllLengths(block, 256); + + while(block != null) + { + var next = block.Next; + pool.Return(block); + block = next; + } + } + } + + private void TestAllLengths(MemoryPoolBlock2 block, int lengths) + { + for (var firstIndex = 0; firstIndex <= lengths; ++firstIndex) + { + for (var lastIndex = firstIndex; lastIndex <= lengths; ++lastIndex) + { + var first = block.GetIterator().Add(firstIndex); + var last = block.GetIterator().Add(lastIndex); + Assert.Equal(firstIndex, block.GetIterator().GetLength(first)); + Assert.Equal(lastIndex, block.GetIterator().GetLength(last)); + Assert.Equal(lastIndex - firstIndex, first.GetLength(last)); + } + } + } + } +} diff --git a/test/Microsoft.AspNet.Server.KestrelTests/MessageBodyExchangerTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/MessageBodyExchangerTests.cs index 8e7612de3f..9983e3a3c7 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/MessageBodyExchangerTests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/MessageBodyExchangerTests.cs @@ -18,7 +18,7 @@ namespace Microsoft.AspNet.Server.KestrelTests { var testInput = new TestInput(); var context = new ConnectionContext(); - context.SocketInput = new SocketInput(new MemoryPool()); + context.SocketInput = new SocketInput(new MemoryPool2()); var exchanger = new MessageBodyExchanger(testInput.FrameContext); @@ -54,7 +54,7 @@ namespace Microsoft.AspNet.Server.KestrelTests { var testInput = new TestInput(); var context = new ConnectionContext(); - context.SocketInput = new SocketInput(new MemoryPool()); + context.SocketInput = new SocketInput(new MemoryPool2()); var exchanger = new MessageBodyExchanger(testInput.FrameContext); @@ -84,7 +84,7 @@ namespace Microsoft.AspNet.Server.KestrelTests { var testInput = new TestInput(); var context = new ConnectionContext(); - context.SocketInput = new SocketInput(new MemoryPool()); + context.SocketInput = new SocketInput(new MemoryPool2()); var exchanger = new MessageBodyExchanger(testInput.FrameContext); @@ -117,7 +117,7 @@ namespace Microsoft.AspNet.Server.KestrelTests { var testInput = new TestInput(); var context = new ConnectionContext(); - context.SocketInput = new SocketInput(new MemoryPool()); + context.SocketInput = new SocketInput(new MemoryPool2()); var exchanger = new MessageBodyExchanger(testInput.FrameContext); @@ -155,7 +155,7 @@ namespace Microsoft.AspNet.Server.KestrelTests var testInput = new TestInput(); var context = new ConnectionContext(); - context.SocketInput = new SocketInput(new MemoryPool()); + context.SocketInput = new SocketInput(new MemoryPool2()); var exchanger = new MessageBodyExchanger(testInput.FrameContext); diff --git a/test/Microsoft.AspNet.Server.KestrelTests/MessageBodyTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/MessageBodyTests.cs index c373f42d73..c3cda8d13a 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/MessageBodyTests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/MessageBodyTests.cs @@ -24,7 +24,6 @@ namespace Microsoft.AspNet.Server.KestrelTests var stream = new FrameRequestStream(body); input.Add("Hello", true); - body.Consume(); var buffer1 = new byte[1024]; var count1 = stream.Read(buffer1, 0, 1024); @@ -43,7 +42,6 @@ namespace Microsoft.AspNet.Server.KestrelTests var stream = new FrameRequestStream(body); input.Add("Hello", true); - body.Consume(); var buffer1 = new byte[1024]; var count1 = await stream.ReadAsync(buffer1, 0, 1024); diff --git a/test/Microsoft.AspNet.Server.KestrelTests/MultipleLoopTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/MultipleLoopTests.cs index cef89f8f6c..10bd46674e 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/MultipleLoopTests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/MultipleLoopTests.cs @@ -112,7 +112,7 @@ namespace Microsoft.AspNet.Server.KestrelTests connect.Dispose(); clientConnectionPipe.ReadStart( (_3, cb, _4) => buf, - (_3, status2, error2, _4) => + (_3, status2, errCode, error2, _4) => { if (status2 == 0) { @@ -211,7 +211,7 @@ namespace Microsoft.AspNet.Server.KestrelTests clientConnectionPipe.ReadStart( (_3, cb, _4) => buf, - (_3, status2, error2, _4) => + (_3, status2, errCode2, error2, _4) => { if (status2 == 0) { @@ -224,7 +224,7 @@ namespace Microsoft.AspNet.Server.KestrelTests var buf2 = loop2.Libuv.buf_init(Marshal.AllocHGlobal(64), 64); clientConnectionTcp.ReadStart( (_5, cb, _6) => buf2, - (_5, status3, error3, _6) => + (_5, status3, errCode3, error3, _6) => { if (status3 == 0) { diff --git a/test/Microsoft.AspNet.Server.KestrelTests/NetworkingTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/NetworkingTests.cs index e5dfc9f3cb..121c042f69 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/NetworkingTests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/NetworkingTests.cs @@ -141,7 +141,7 @@ namespace Microsoft.AspNet.Server.KestrelTests var data = Marshal.AllocCoTaskMem(500); tcp2.ReadStart( (a, b, c) => _uv.buf_init(data, 500), - (__, nread, error2, state2) => + (__, nread, errCode, error2, state2) => { bytesRead += nread; if (nread == 0) @@ -197,7 +197,7 @@ namespace Microsoft.AspNet.Server.KestrelTests var data = Marshal.AllocCoTaskMem(500); tcp2.ReadStart( (a, b, c) => tcp2.Libuv.buf_init(data, 500), - (__, nread, error2, state2) => + (__, nread, errCode, error2, state2) => { bytesRead += nread; if (nread == 0) diff --git a/test/Microsoft.AspNet.Server.KestrelTests/TestInput.cs b/test/Microsoft.AspNet.Server.KestrelTests/TestInput.cs index c1b9e75729..506e1907ac 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/TestInput.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/TestInput.cs @@ -13,9 +13,10 @@ namespace Microsoft.AspNet.Server.KestrelTests public TestInput() { var memory = new MemoryPool(); + var memory2 = new MemoryPool2(); FrameContext = new FrameContext { - SocketInput = new SocketInput(memory), + SocketInput = new SocketInput(memory2), Memory = memory, ConnectionControl = this, FrameControl = this @@ -28,9 +29,10 @@ namespace Microsoft.AspNet.Server.KestrelTests { var encoding = System.Text.Encoding.ASCII; var count = encoding.GetByteCount(text); - var buffer = FrameContext.SocketInput.Available(text.Length); - count = encoding.GetBytes(text, 0, text.Length, buffer.Array, buffer.Offset); - FrameContext.SocketInput.Extend(count); + var buffer = FrameContext.SocketInput.Pin(text.Length); + count = encoding.GetBytes(text, 0, text.Length, buffer.Data.Array, buffer.Data.Offset); + FrameContext.SocketInput.Unpin(count); + FrameContext.SocketInput.SetCompleted(null); if (fin) { FrameContext.SocketInput.RemoteIntakeFin = true; diff --git a/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/KnownHeaders.cs b/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/KnownHeaders.cs index 0593f879c1..03d2e2764a 100644 --- a/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/KnownHeaders.cs +++ b/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/KnownHeaders.cs @@ -171,18 +171,6 @@ using Microsoft.Framework.Primitives; namespace Microsoft.AspNet.Server.Kestrel.Http {{ - public partial class FrameResponseHeaders - {{ - public FrameResponseHeaders() - {{ - _Server = ""Kestrel""; - _Date = DateTime.UtcNow.ToString(""r""); - _bits = { - 1L << responseHeaders.First(header => header.Name == "Server").Index | - 1L << responseHeaders.First(header => header.Name == "Date").Index - }L; - }} - }} {Each(loops, loop => $@" public partial class {loop.ClassName} {{ @@ -190,6 +178,28 @@ namespace Microsoft.AspNet.Server.Kestrel.Http {Each(loop.Headers, header => @" private StringValues _" + header.Identifier + ";")} + {Each(loop.Headers, header => $@" + public StringValues Header{header.Identifier} + {{ + get + {{ + if ({header.TestBit()}) + {{ + return _{header.Identifier}; + }} + else + {{ + return StringValues.Empty; + }} + }} + set + {{ + {header.SetBit()}; + _{header.Identifier} = value; + }} + }} + ")} + protected override int GetCountFast() {{ var count = MaybeUnknown?.Count ?? 0; @@ -322,6 +332,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http protected override void ClearFast() {{ _bits = 0; + {Each(loop.Headers, header => $@" + _{header.Identifier} = StringValues.Empty;")} MaybeUnknown?.Clear(); }} From 4193c92ba78be973fe2734afb47b0d8bfc5b34b6 Mon Sep 17 00:00:00 2001 From: Louis DeJardin Date: Tue, 15 Sep 2015 17:00:58 -0700 Subject: [PATCH 0266/1662] Fixing merge conflicts --- src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs index e9c960c2e5..6a4d9b24d6 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs @@ -125,8 +125,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http Thread.Post( _this => { - var self = (Connection)state; - var shutdown = new UvShutdownReq(self.Log); + var shutdown = new UvShutdownReq(_this.Log); shutdown.Init(_this.Thread.Loop); shutdown.Shutdown(_this._socket, (req, status, state2) => { @@ -144,10 +143,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } Log.ConnectionKeepAlive(_connectionId); - _frame = new Frame(this); - Thread.Post( - state => ((Frame)state).Consume(), - _frame); break; case ProduceEndType.SocketDisconnect: if (_connectionState == ConnectionState.Disconnected) From e5a3bda3a2a6e615da5f01ac03a9e1b26f7b7c0f Mon Sep 17 00:00:00 2001 From: Louis DeJardin Date: Wed, 16 Sep 2015 20:20:07 -0700 Subject: [PATCH 0267/1662] Progress on flow control * Dealing with race conditions * Reworking iterator methods * Shutdown and Close need to be passed throught the write-behind mechanism --- .../Http/Connection.cs | 32 +- .../Http/Frame.cs | 285 ++++------ .../Http/ISocketOutput.cs | 1 + .../Http/MemoryPool2.cs | 6 +- .../Http/MemoryPoolBlock2.cs | 510 ++++++++++-------- .../Http/MemoryPoolSlab2.cs | 2 +- .../Http/MessageBody.cs | 88 +-- .../Http/SocketInput.cs | 9 +- .../Http/SocketOutput.cs | 150 +++++- .../EngineTests.cs | 21 +- .../MemoryPoolBlock2Tests.cs | 57 +- .../MemoryPoolExtensions.cs | 13 + .../StandardsPoliceCompileModule.cs | 4 +- 13 files changed, 682 insertions(+), 496 deletions(-) create mode 100644 test/Microsoft.AspNet.Server.KestrelTests/MemoryPoolExtensions.cs diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs index 6a4d9b24d6..05c1eb1878 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs @@ -82,15 +82,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { SocketInput.RemoteIntakeFin = true; _socket.ReadStop(); - - if (errorDone && error != null) - { - Log.LogError("Connection.OnRead", error); - } - else - { - Log.ConnectionReadFin(_connectionId); - } + Log.ConnectionReadFin(_connectionId); } SocketInput.SetCompleted(errorDone ? error : null); @@ -122,19 +114,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http _connectionState = ConnectionState.Shutdown; Log.ConnectionWriteFin(_connectionId); - Thread.Post( - _this => - { - var shutdown = new UvShutdownReq(_this.Log); - shutdown.Init(_this.Thread.Loop); - shutdown.Shutdown(_this._socket, (req, status, state2) => - { - var __this = (Connection)state2; - __this.Log.ConnectionWroteFin(__this._connectionId, status); - req.Dispose(); - }, _this); - }, - this); + SocketOutput.End(endType); break; case ProduceEndType.ConnectionKeepAlive: if (_connectionState != ConnectionState.Open) @@ -152,13 +132,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http _connectionState = ConnectionState.Disconnected; Log.ConnectionDisconnect(_connectionId); - Thread.Post( - _this => - { - Log.ConnectionStop(_this._connectionId); - _this._socket.Dispose(); - }, - this); + SocketOutput.End(endType); break; } } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs index 86b22b8bac..5bbb1db8a1 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs @@ -113,23 +113,15 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { await SocketInput; } - else - { - var x = 5; - } } - while (!terminated && !TakeMessageHeader2(SocketInput)) + while (!terminated && !TakeMessageHeaders(SocketInput)) { terminated = SocketInput.RemoteIntakeFin; if (!terminated) { await SocketInput; } - else - { - var x = 5; - } } if (!terminated) @@ -171,6 +163,10 @@ namespace Microsoft.AspNet.Server.Kestrel.Http // Connection Terminated! ConnectionControl.End(ProduceEndType.SocketShutdownSend); + + // Wait for client to disconnect, or to receive unexpected data + await SocketInput; + ConnectionControl.End(ProduceEndType.SocketDisconnect); } @@ -407,13 +403,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http WriteChunkedResponseSuffix(); } - if (!_keepAlive) - { - ConnectionControl.End(ProduceEndType.SocketShutdownSend); - } - - //NOTE: must finish reading request body - ConnectionControl.End(_keepAlive ? ProduceEndType.ConnectionKeepAlive : ProduceEndType.SocketDisconnect); + ConnectionControl.End(_keepAlive ? ProduceEndType.ConnectionKeepAlive : ProduceEndType.SocketShutdownSend); } private Tuple, IDisposable> CreateResponseHeader( @@ -515,36 +505,51 @@ namespace Microsoft.AspNet.Server.Kestrel.Http private bool TakeStartLine(SocketInput input) { - var begin = input.GetIterator(); - if (begin.IsDefault) return false; + var scan = input.GetIterator(); - var end = begin.IndexOf(' '); - var method = begin.GetString(end); - - char chFound; - begin = end.Add(1); - end = begin.IndexOfAny(' ', '?', out chFound); - var requestUri = begin.GetString(end); - - begin = end; - end = chFound == '?' ? begin.IndexOf(' ') : begin; - var queryString = begin.GetString(end); - - begin = end.Add(1); - end = begin.IndexOf('\r'); - var httpVersion = begin.GetString(end); - - end = end.Add(1); - if (end.Peek() != '\n') + var begin = scan; + if (scan.Seek(' ') == -1) { return false; } + var method = begin.GetString(scan); + + scan.Take(); + begin = scan; + var chFound = scan.Seek(' ', '?'); + if (chFound == -1) + { + return false; + } + var requestUri = begin.GetString(scan); + + var queryString = ""; + if (chFound == '?') + { + begin = scan; + if (scan.Seek(' ') != ' ') + { + return false; + } + queryString = begin.GetString(scan); + } + + scan.Take(); + begin = scan; + if (scan.Seek('\r') == -1) + { + return false; + } + var httpVersion = begin.GetString(scan); + + scan.Take(); + if (scan.Take() != '\n') return false; Method = method; RequestUri = requestUri; QueryString = queryString; HttpVersion = httpVersion; - input.JumpTo(end.Add(1)); + input.JumpTo(scan); return true; } @@ -553,150 +558,98 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return Encoding.UTF8.GetString(range.Array, range.Offset + startIndex, endIndex - startIndex); } - private bool TakeMessageHeader2(SocketInput baton) + private bool TakeMessageHeaders(SocketInput input) { - char chFirst; - char chSecond; - var scan = baton.GetIterator(); - while (!scan.IsDefault) + int chFirst; + int chSecond; + var scan = input.GetIterator(); + var consumed = scan; + try { - var beginName = scan; - scan = scan.IndexOfAny(':', '\r', out chFirst); - - var endName = scan; - chSecond = scan.MoveNext(); - - if (chFirst == '\r' && chSecond == '\n') + while (!scan.IsEnd) { - baton.JumpTo(scan.Add(1)); - return true; - } - if (chFirst == char.MinValue) - { - return false; - } + var beginName = scan; + scan.Seek(':', '\r'); + var endName = scan; - while ( - chSecond == ' ' || - chSecond == '\t' || - chSecond == '\r' || - chSecond == '\n') - { - chSecond = scan.MoveNext(); - } + chFirst = scan.Take(); + var beginValue = scan; + chSecond = scan.Take(); - var beginValue = scan; - var wrapping = false; - while (!scan.IsDefault) - { - var endValue = scan = scan.IndexOf('\r'); - chFirst = scan.MoveNext(); - if (chFirst != '\n') + if (chFirst == -1 || chSecond == -1) { - continue; + return false; } - chSecond = scan.MoveNext(); - if (chSecond == ' ' || chSecond == '\t') + if (chFirst == '\r') { - wrapping = true; - continue; - } - var name = beginName.GetArraySegment(endName); - var value = beginValue.GetString(endValue); - if (wrapping) - { - value = value.Replace("\r\n", " "); + if (chSecond == '\n') + { + consumed = scan; + return true; + } + throw new Exception("Malformed request"); } - _requestHeaders.Append(name.Array, name.Offset, name.Count, value); - break; + while ( + chSecond == ' ' || + chSecond == '\t' || + chSecond == '\r' || + chSecond == '\n') + { + beginValue = scan; + chSecond = scan.Take(); + } + scan = beginValue; + + var wrapping = false; + while (!scan.IsEnd) + { + if (scan.Seek('\r') == -1) + { + // no "\r" in sight, burn used bytes and go back to await more data + return false; + } + + var endValue = scan; + chFirst = scan.Take(); // expecting: /r + chSecond = scan.Take(); // expecting: /n + + if (chSecond == '\r') + { + // special case, "\r\r". move to the 2nd "\r" and try again + scan = endValue; + scan.Take(); + continue; + } + + var chThird = scan.Peek(); + if (chThird == ' ' || chThird == '\t') + { + // special case, "\r\n " or "\r\n\t". + // this is considered wrapping"linear whitespace" and is actually part of the header value + // continue past this for the next + wrapping = true; + continue; + } + + var name = beginName.GetArraySegment(endName); + var value = beginValue.GetString(endValue); + if (wrapping) + { + value = value.Replace("\r\n", " "); + } + + _requestHeaders.Append(name.Array, name.Offset, name.Count, value); + consumed = scan; + break; + } } - } - - return false; - } - - private bool TakeMessageHeader(SocketInput baton, out bool endOfHeaders) - { - var remaining = baton.Buffer; - endOfHeaders = false; - if (remaining.Count < 2) - { return false; } - var ch0 = remaining.Array[remaining.Offset]; - var ch1 = remaining.Array[remaining.Offset + 1]; - if (ch0 == '\r' && ch1 == '\n') + finally { - endOfHeaders = true; - baton.Skip(2); - return true; + input.JumpTo(consumed); } - - if (remaining.Count < 3) - { - return false; - } - var wrappedHeaders = false; - var colonIndex = -1; - var valueStartIndex = -1; - var valueEndIndex = -1; - for (var index = 0; index != remaining.Count - 2; ++index) - { - var ch2 = remaining.Array[remaining.Offset + index + 2]; - if (ch0 == '\r' && - ch1 == '\n' && - ch2 != ' ' && - ch2 != '\t') - { - var value = ""; - if (valueEndIndex != -1) - { - value = _ascii.GetString( - remaining.Array, remaining.Offset + valueStartIndex, valueEndIndex - valueStartIndex); - } - if (wrappedHeaders) - { - value = value.Replace("\r\n", " "); - } - AddRequestHeader(remaining.Array, remaining.Offset, colonIndex, value); - baton.Skip(index + 2); - return true; - } - if (colonIndex == -1 && ch0 == ':') - { - colonIndex = index; - } - else if (colonIndex != -1 && - ch0 != ' ' && - ch0 != '\t' && - ch0 != '\r' && - ch0 != '\n') - { - if (valueStartIndex == -1) - { - valueStartIndex = index; - } - valueEndIndex = index + 1; - } - else if (!wrappedHeaders && - ch0 == '\r' && - ch1 == '\n' && - (ch2 == ' ' || - ch2 == '\t')) - { - wrappedHeaders = true; - } - - ch0 = ch1; - ch1 = ch2; - } - return false; - } - - private void AddRequestHeader(byte[] keyBytes, int keyOffset, int keyLength, string value) - { - _requestHeaders.Append(keyBytes, keyOffset, keyLength, value); } public bool StatusCanHaveBody(int statusCode) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/ISocketOutput.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/ISocketOutput.cs index 4edffa3055..00c567d571 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/ISocketOutput.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/ISocketOutput.cs @@ -14,5 +14,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { void Write(ArraySegment buffer, bool immediate = true); Task WriteAsync(ArraySegment buffer, bool immediate = true, CancellationToken cancellationToken = default(CancellationToken)); + void End(ProduceEndType endType); } } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/MemoryPool2.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/MemoryPool2.cs index 0ad2ea8645..9256bdb314 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/MemoryPool2.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/MemoryPool2.cs @@ -1,7 +1,5 @@ using System; using System.Collections.Concurrent; -using System.Diagnostics; -using System.Runtime.InteropServices; namespace Microsoft.AspNet.Server.Kestrel.Http { @@ -15,6 +13,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http private ConcurrentStack _blocks = new ConcurrentStack(); private ConcurrentStack _slabs = new ConcurrentStack(); + private bool disposedValue = false; // To detect redundant calls public MemoryPoolBlock2 Lease(int minimumSize) { @@ -27,7 +26,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http slab: null); } - for (;;) + while (true) { MemoryPoolBlock2 block; if (_blocks.TryPop(out block)) @@ -66,7 +65,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } #region IDisposable Support - private bool disposedValue = false; // To detect redundant calls protected virtual void Dispose(bool disposing) { diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/MemoryPoolBlock2.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/MemoryPoolBlock2.cs index 8bb913ed6e..7d2f8d27d1 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/MemoryPoolBlock2.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/MemoryPoolBlock2.cs @@ -135,246 +135,284 @@ namespace Microsoft.AspNet.Server.Kestrel.Http public bool IsDefault => _block == null; + public bool IsEnd + { + get + { + if (_block == null) + { + return true; + } + else if (_index < _block.End) + { + return false; + } + else + { + for (var block = _block.Next; block != null; block = block.Next) + { + if (block.Start < block.End) + { + return true; + } + } + return true; + } + } + } + public MemoryPoolBlock2 Block => _block; public int Index => _index; - public bool HasAtLeast(int count) + public int Take() { - var scan = _block; - var index = _index; - while (scan != null) + if (_block == null) { - if (count <= scan.End - index) - { - return true; - } - count -= scan.End - index; - scan = scan.Next; - index = scan?.Start ?? 0; + return -1; + } + else if (_index < _block.End) + { + return _block.Array[_index++]; } - return false; - } - public Iterator Add(int count) - { var block = _block; var index = _index; - while (block != null) + while (true) { - var tailCount = block.End - index; - if (count < tailCount) + if (index < block.End) { - return new Iterator(block, index + count); + _block = block; + _index = index + 1; + return block.Array[index]; } - count -= tailCount; - block = block.Next; - index = block?.Start ?? 0; - } - return new Iterator(block, index + count); - } - - public Iterator CopyTo(byte[] array, int offset, int count, out int actual) - { - var block = _block; - var index = _index; - var remaining = count; - while (block != null && remaining != 0) - { - var copyLength = Math.Min(remaining, block.End - index); - Buffer.BlockCopy(block.Array, index, array, offset, copyLength); - index += copyLength; - offset += copyLength; - remaining -= copyLength; - if (index == block.End) + else if (block.Next == null) + { + return -1; + } + else { block = block.Next; - index = block?.Start ?? 0; + index = block.Start; } } - actual = count - remaining; - return new Iterator(block, index); - } - - public char MoveNext() - { - var block = _block; - var index = _index; - while (block != null && index == block.End) - { - block = block.Next; - index = block?.Start ?? 0; - } - if (block != null) - { - ++index; - } - while (block != null && index == block.End) - { - block = block.Next; - index = block?.Start ?? 0; - } - _block = block; - _index = index; - return block != null ? (char)block.Array[index] : char.MinValue; } public int Peek() { - while (_block != null) + if (_block == null) { - if (_index < _block.End) - { - return _block.Data.Array[_index]; - } - _block = _block.Next; - _index = _block.Start; + return -1; + } + else if (_index < _block.End) + { + return _block.Array[_index]; + } + else if (_block.Next == null) + { + return -1; + } + + var block = _block.Next; + var index = block.Start; + while (true) + { + if (index < block.End) + { + return block.Array[index]; + } + else if (block.Next == null) + { + return -1; + } + else + { + block = block.Next; + index = block.Start; + } } - return -1; } - public Iterator IndexOf(char char0) + public int Seek(int char0) { + if (IsDefault) + { + return -1; + } + var byte0 = (byte)char0; var vectorStride = Vector.Count; var ch0Vector = new Vector(byte0); - var scanBlock = _block; - var scanArray = scanBlock?.Array; - var scanIndex = _index; - while (scanBlock != null) + var block = _block; + var index = _index; + var array = block.Array; + while (true) { - var tailCount = scanBlock.End - scanIndex; - if (tailCount == 0) + while (block.End == index) { - scanBlock = scanBlock.Next; - scanArray = scanBlock?.Array; - scanIndex = scanBlock?.Start ?? 0; - continue; + if (block.Next == null) + { + _block = block; + _index = index; + return -1; + } + block = block.Next; + index = block.Start; + array = block.Array; } - if (tailCount >= vectorStride) + while (block.End != index) { - var data = new Vector(scanBlock.Array, scanIndex); - var ch0Equals = Vector.Equals(data, ch0Vector); - var ch0Count = Vector.Dot(ch0Equals, _dotCount); + var following = block.End - index; + if (following >= vectorStride) + { + var data = new Vector(array, index); + var ch0Equals = Vector.Equals(data, ch0Vector); + var ch0Count = Vector.Dot(ch0Equals, _dotCount); - if (ch0Count == 0) - { - scanIndex += vectorStride; - continue; + if (ch0Count == 0) + { + index += vectorStride; + continue; + } + else if (ch0Count == 1) + { + _block = block; + _index = index + Vector.Dot(ch0Equals, _dotIndex); + return char0; + } + else + { + following = vectorStride; + } } - else if (ch0Count == 1) + for (; following != 0; following--, index++) { - return new Iterator(scanBlock, scanIndex + Vector.Dot(ch0Equals, _dotIndex)); - } - else - { - tailCount = vectorStride; - } - } - for (; tailCount != 0; tailCount--, scanIndex++) - { - var ch = scanBlock.Array[scanIndex]; - if (ch == byte0) - { - return new Iterator(scanBlock, scanIndex); + if (block.Array[index] == byte0) + { + _block = block; + _index = index; + return char0; + } } } } - return new Iterator(null, 0); } - public Iterator IndexOfAny(char char0, char char1, out char chFound) + public int Seek(int char0, int char1) { + if (IsDefault) + { + return -1; + } + var byte0 = (byte)char0; var byte1 = (byte)char1; var vectorStride = Vector.Count; var ch0Vector = new Vector(byte0); var ch1Vector = new Vector(byte1); - var scanBlock = _block; - var scanArray = scanBlock?.Array; - var scanIndex = _index; - while (scanBlock != null) + var block = _block; + var index = _index; + var array = block.Array; + while (true) { - var tailCount = scanBlock.End - scanIndex; - if (tailCount == 0) + while (block.End == index) { - scanBlock = scanBlock.Next; - scanArray = scanBlock?.Array; - scanIndex = scanBlock?.Start ?? 0; - continue; - } - if (tailCount >= vectorStride) - { - var data = new Vector(scanBlock.Array, scanIndex); - var ch0Equals = Vector.Equals(data, ch0Vector); - var ch0Count = Vector.Dot(ch0Equals, _dotCount); - var ch1Equals = Vector.Equals(data, ch1Vector); - var ch1Count = Vector.Dot(ch1Equals, _dotCount); - - if (ch0Count == 0 && ch1Count == 0) + if (block.Next == null) { - scanIndex += vectorStride; - continue; + _block = block; + _index = index; + return -1; } - else if (ch0Count < 2 && ch1Count < 2) + block = block.Next; + index = block.Start; + array = block.Array; + } + while (block.End != index) + { + var following = block.End - index; + if (following >= vectorStride) { - var ch0Index = ch0Count == 1 ? Vector.Dot(ch0Equals, _dotIndex) : byte.MaxValue; - var ch1Index = ch1Count == 1 ? Vector.Dot(ch1Equals, _dotIndex) : byte.MaxValue; - if (ch0Index < ch1Index) + var data = new Vector(array, index); + var ch0Equals = Vector.Equals(data, ch0Vector); + var ch0Count = Vector.Dot(ch0Equals, _dotCount); + var ch1Equals = Vector.Equals(data, ch1Vector); + var ch1Count = Vector.Dot(ch1Equals, _dotCount); + + if (ch0Count == 0 && ch1Count == 0) { - chFound = char0; - return new Iterator(scanBlock, scanIndex + ch0Index); + index += vectorStride; + continue; + } + else if (ch0Count < 2 && ch1Count < 2) + { + var ch0Index = ch0Count == 1 ? Vector.Dot(ch0Equals, _dotIndex) : byte.MaxValue; + var ch1Index = ch1Count == 1 ? Vector.Dot(ch1Equals, _dotIndex) : byte.MaxValue; + if (ch0Index < ch1Index) + { + _block = block; + _index = index + ch0Index; + return char0; + } + else + { + _block = block; + _index = index + ch1Index; + return char1; + } } else { - chFound = char1; - return new Iterator(scanBlock, scanIndex + ch1Index); + following = vectorStride; } } - else + for (; following != 0; following--, index++) { - tailCount = vectorStride; - } - } - for (; tailCount != 0; tailCount--, scanIndex++) - { - var chIndex = scanBlock.Array[scanIndex]; - if (chIndex == byte0) - { - chFound = char0; - return new Iterator(scanBlock, scanIndex); - } - else if (chIndex == byte1) - { - chFound = char1; - return new Iterator(scanBlock, scanIndex); + var byteIndex = block.Array[index]; + if (byteIndex == byte0) + { + _block = block; + _index = index; + return char0; + } + else if (byteIndex == byte1) + { + _block = block; + _index = index; + return char1; + } } } } - chFound = char.MinValue; - return new Iterator(null, 0); } public int GetLength(Iterator end) { - var length = 0; + if (IsDefault || end.IsDefault) + { + return -1; + } + var block = _block; var index = _index; - for (;;) + var length = 0; + while (true) { if (block == end._block) { return length + end._index - index; } - if (block == null) + else if (block.Next == null) { - throw new Exception("end was not after iterator"); + throw new Exception("end did not follow iterator"); + } + else + { + length += block.End - index; + block = block.Next; + index = block.Start; } - length += block.End - index; - block = block.Next; - index = block?.Start ?? 0; } } @@ -386,53 +424,74 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } if (end._block == _block) { - return Encoding.ASCII.GetString(_block.Array, _index, end._index - _index); - } - if (end._block == _block.Next && end._index == end._block.Start) - { - return Encoding.ASCII.GetString(_block.Array, _index, _block.End - _index); + return Encoding.UTF8.GetString(_block.Array, _index, end._index - _index); } - var length = GetLength(end); - var result = new char[length]; - var offset = 0; var decoder = Encoding.ASCII.GetDecoder(); + var length = GetLength(end); + var charLength = length * 2; + var chars = new char[charLength]; + var charIndex = 0; + var block = _block; var index = _index; - while (length != 0) + var remaining = length; + while (true) { - if (block == null) - { - throw new Exception("Unexpected end of data"); - } - - var count = Math.Min(block.End - index, length); - int bytesUsed; - int textAdded; + int charsUsed; bool completed; - decoder.Convert( - block.Array, - index, - count, - result, - offset, - length, - count == length, - out bytesUsed, - out textAdded, - out completed); - - Debug.Assert(bytesUsed == count); - Debug.Assert(textAdded == count); - offset += count; - length -= count; - - block = block.Next; - index = block?.Start ?? 0; + var following = block.End - index; + if (remaining <= following) + { + decoder.Convert( + block.Array, + index, + remaining, + chars, + charIndex, + charLength - charIndex, + true, + out bytesUsed, + out charsUsed, + out completed); + return new string(chars, 0, charIndex + charsUsed); + } + else if (block.Next == null) + { + decoder.Convert( + block.Array, + index, + following, + chars, + charIndex, + charLength - charIndex, + true, + out bytesUsed, + out charsUsed, + out completed); + return new string(chars, 0, charIndex + charsUsed); + } + else + { + decoder.Convert( + block.Array, + index, + following, + chars, + charIndex, + charLength - charIndex, + false, + out bytesUsed, + out charsUsed, + out completed); + charIndex += charsUsed; + remaining -= following; + block = block.Next; + index = block.Start; + } } - return new string(result); } public ArraySegment GetArraySegment(Iterator end) @@ -445,34 +504,47 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { return new ArraySegment(_block.Array, _index, end._index - _index); } - if (end._block == _block.Next && end._index == end._block.Start) - { - return new ArraySegment(_block.Array, _index, _block.End - _index); - } var length = GetLength(end); - var result = new ArraySegment(new byte[length]); - var offset = result.Offset; + var array = new byte[length]; + CopyTo(array, 0, length, out length); + return new ArraySegment(array, 0, length); + } + + public Iterator CopyTo(byte[] array, int offset, int count, out int actual) + { + if (IsDefault) + { + actual = 0; + return this; + } var block = _block; var index = _index; - while (length != 0) + var remaining = count; + while (true) { - if (block == null) + var following = block.End - index; + if (remaining <= following) { - throw new Exception("Unexpected end of data"); + actual = count; + Buffer.BlockCopy(block.Array, index, array, offset, remaining); + return new Iterator(block, index + remaining); + } + else if (block.Next == null) + { + actual = count - remaining + following; + Buffer.BlockCopy(block.Array, index, array, offset, following); + return new Iterator(block, index + following); + } + else + { + Buffer.BlockCopy(block.Array, index, array, offset, following); + remaining -= following; + block = block.Next; + index = block.Start; } - - var count = Math.Min(block.End - index, length); - Buffer.BlockCopy(block.Array, index, result.Array, offset, count); - offset += count; - length -= count; - - block = block.Next; - index = block?.Start ?? 0; } - - return result; } } } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/MemoryPoolSlab2.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/MemoryPoolSlab2.cs index 561d26d4df..88b20c78b4 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/MemoryPoolSlab2.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/MemoryPoolSlab2.cs @@ -11,6 +11,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http public byte[] Array; public IntPtr ArrayPtr; public bool IsActive; + private bool disposedValue = false; // To detect redundant calls public static MemoryPoolSlab2 Create(int length) { @@ -26,7 +27,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } #region IDisposable Support - private bool disposedValue = false; // To detect redundant calls protected virtual void Dispose(bool disposing) { diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/MessageBody.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/MessageBody.cs index 2e78402899..257df299aa 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/MessageBody.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/MessageBody.cs @@ -86,14 +86,24 @@ namespace Microsoft.AspNet.Server.Kestrel.Http public override async Task ReadAsyncImplementation(ArraySegment buffer, CancellationToken cancellationToken) { var input = _context.SocketInput; + while (true) + { + await input; - await input; + var begin = input.GetIterator(); + int actual; + var end = begin.CopyTo(buffer.Array, buffer.Offset, buffer.Count, out actual); + input.JumpTo(end); - var begin = input.GetIterator(); - int actual; - var end = begin.CopyTo(buffer.Array, buffer.Offset, buffer.Count, out actual); - input.JumpTo(end); - return actual; + if (actual != 0) + { + return actual; + } + if (input.RemoteIntakeFin) + { + return 0; + } + } } } @@ -109,23 +119,35 @@ namespace Microsoft.AspNet.Server.Kestrel.Http _contentLength = contentLength; _inputLength = _contentLength; } - + public override async Task ReadAsyncImplementation(ArraySegment buffer, CancellationToken cancellationToken) { var input = _context.SocketInput; - var limit = Math.Min(buffer.Count, _inputLength); - if (limit != 0) + while (true) { - await input; - } + var limit = Math.Min(buffer.Count, _inputLength); + if (limit == 0) + { + return 0; + } - var begin = input.GetIterator(); - int actual; - var end = begin.CopyTo(buffer.Array, buffer.Offset, limit, out actual); - _inputLength -= actual; - input.JumpTo(end); - return actual; + await input; + + var begin = input.GetIterator(); + int actual; + var end = begin.CopyTo(buffer.Array, buffer.Offset, limit, out actual); + _inputLength -= actual; + input.JumpTo(end); + if (actual != 0) + { + return actual; + } + if (input.RemoteIntakeFin) + { + throw new Exception("Unexpected end of request content"); + } + } } } @@ -186,21 +208,23 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { _mode = Mode.ChunkSuffix; } - - return actual; + if (actual != 0) + { + return actual; + } } while (_mode == Mode.ChunkSuffix) { - var begin = input.GetIterator(); - var ch1 = begin.Peek(); - var ch2 = begin.MoveNext(); - if (ch1 == char.MinValue || ch2 == char.MinValue) + var scan = input.GetIterator(); + var ch1 = scan.Take(); + var ch2 = scan.Take(); + if (ch1 == -1 || ch2 == -1) { await input; } else if (ch1 == '\r' && ch2 == '\n') { - input.JumpTo(begin.Add(1)); + input.JumpTo(scan); _mode = Mode.ChunkPrefix; } else @@ -215,13 +239,17 @@ namespace Microsoft.AspNet.Server.Kestrel.Http private static bool TakeChunkedLine(SocketInput baton, ref int chunkSizeOut) { - var remaining = baton.GetIterator(); - var ch0 = remaining.Peek(); + var scan = baton.GetIterator(); + var ch0 = scan.Take(); var chunkSize = 0; var mode = 0; - while(ch0 != -1) + while (ch0 != -1) { - var ch1 = remaining.MoveNext(); + var ch1 = scan.Take(); + if (ch1 == -1) + { + return false; + } if (mode == 0) { @@ -263,7 +291,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } else if (ch0 == '\r' && ch1 == '\n') { - baton.JumpTo(remaining.Add(1)); + baton.JumpTo(scan); chunkSizeOut = chunkSize; return true; } @@ -276,7 +304,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { if (ch0 == '\r' && ch1 == '\n') { - baton.JumpTo(remaining.Add(1)); + baton.JumpTo(scan); chunkSizeOut = chunkSize; return true; } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketInput.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketInput.cs index 27f42c8a5e..1ff2530bc4 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketInput.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketInput.cs @@ -206,19 +206,16 @@ namespace Microsoft.AspNet.Server.Kestrel.Http lock (_syncHeadAndTail) { // TODO: leave _pinned intact + // TODO: return when empty returnStart = _head; returnEnd = iterator.Block; _head = iterator.Block; - if (_head == null) + _head.Start = iterator.Index; + if (iterator.IsEnd) { - _tail = null; SetNotCompleted(); } - else - { - _head.Start = iterator.Index; - } } while (returnStart != returnEnd) { diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs index b6dcd0967f..7e35251e38 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs @@ -42,14 +42,22 @@ namespace Microsoft.AspNet.Server.Kestrel.Http _callbacksPending = new Queue(); } - public void Write(ArraySegment buffer, Action callback, object state, bool immediate = true) + public void Write( + ArraySegment buffer, + Action callback, + object state, + bool immediate = true, + bool socketShutdownSend = false, + bool socketDisconnect = false) { //TODO: need buffering that works - var copy = new byte[buffer.Count]; - Array.Copy(buffer.Array, buffer.Offset, copy, 0, buffer.Count); - buffer = new ArraySegment(copy); - - _log.ConnectionWrite(_connectionId, buffer.Count); + if (buffer.Array != null) + { + var copy = new byte[buffer.Count]; + Array.Copy(buffer.Array, buffer.Offset, copy, 0, buffer.Count); + buffer = new ArraySegment(copy); + _log.ConnectionWrite(_connectionId, buffer.Count); + } bool triggerCallbackNow = false; @@ -60,8 +68,18 @@ namespace Microsoft.AspNet.Server.Kestrel.Http _nextWriteContext = new WriteContext(this); } - _nextWriteContext.Buffers.Enqueue(buffer); - + if (buffer.Array != null) + { + _nextWriteContext.Buffers.Enqueue(buffer); + } + if (socketShutdownSend) + { + _nextWriteContext.SocketShutdownSend = true; + } + if (socketDisconnect) + { + _nextWriteContext.SocketDisconnect = true; + } // Complete the write task immediately if all previous write tasks have been completed, // the buffers haven't grown too large, and the last write to the socket succeeded. triggerCallbackNow = _lastWriteError == null && @@ -121,22 +139,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http try { - var buffers = new ArraySegment[writingContext.Buffers.Count]; - - var i = 0; - foreach (var buffer in writingContext.Buffers) - { - buffers[i++] = buffer; - } - - var writeReq = new UvWriteReq(_log); - writeReq.Init(_thread.Loop); - - writeReq.Write(_socket, new ArraySegment>(buffers), (r, status, error, state) => - { - var writtenContext = (WriteContext)state; - writtenContext.Self.OnWriteCompleted(writtenContext.Buffers, r, status, error); - }, writingContext); + writingContext.Execute(); } catch { @@ -152,7 +155,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } // This is called on the libuv event loop - private void OnWriteCompleted(Queue> writtenBuffers, UvWriteReq req, int status, Exception error) + private void OnWriteCompleted(Queue> writtenBuffers, int status, Exception error) { _log.ConnectionWriteCallback(_connectionId, status); @@ -194,8 +197,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Http Trace.Assert(_numBytesPreCompleted >= 0); Trace.Assert(_numBytesPreCompleted <= _maxBytesPreCompleted); } - - req.Dispose(); } private void TriggerCallback(CallbackContext context) @@ -237,6 +238,25 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return tcs.Task; } + void ISocketOutput.End(ProduceEndType endType) + { + switch (endType) + { + case ProduceEndType.SocketShutdownSend: + Write(default(ArraySegment), (error, state) => { }, null, + immediate: true, + socketShutdownSend: true, + socketDisconnect: false); + break; + case ProduceEndType.SocketDisconnect: + Write(default(ArraySegment), (error, state) => { }, null, + immediate: true, + socketShutdownSend: false, + socketDisconnect: true); + break; + } + } + private class CallbackContext { public Exception Error; @@ -248,13 +268,89 @@ namespace Microsoft.AspNet.Server.Kestrel.Http private class WriteContext { public SocketOutput Self; + public Queue> Buffers; + public bool SocketShutdownSend; + public bool SocketDisconnect; + + public int WriteStatus; + public Exception WriteError; + + public int ShutdownSendStatus; public WriteContext(SocketOutput self) { Self = self; Buffers = new Queue>(); } + + public void Execute() + { + if (Buffers.Count == 0 || Self._socket.IsClosed) + { + StageTwo(); + return; + } + + var buffers = new ArraySegment[Buffers.Count]; + + var i = 0; + foreach (var buffer in Buffers) + { + buffers[i++] = buffer; + } + + var writeReq = new UvWriteReq(Self._log); + writeReq.Init(Self._thread.Loop); + writeReq.Write(Self._socket, new ArraySegment>(buffers), (_writeReq, status, error, state) => + { + _writeReq.Dispose(); + var _this = (WriteContext)state; + _this.WriteStatus = status; + _this.WriteError = error; + StageTwo(); + }, this); + } + + public void StageTwo() + { + if (SocketShutdownSend == false || Self._socket.IsClosed) + { + StageThree(); + return; + } + + var shutdownReq = new UvShutdownReq(Self._log); + shutdownReq.Init(Self._thread.Loop); + shutdownReq.Shutdown(Self._socket, (_shutdownReq, status, state) => + { + _shutdownReq.Dispose(); + var _this = (WriteContext)state; + _this.ShutdownSendStatus = status; + + Self._log.ConnectionWroteFin(Self._connectionId, status); + + StageThree(); + }, this); + } + + public void StageThree() + { + if (SocketDisconnect == false || Self._socket.IsClosed) + { + Complete(); + return; + } + + Self._socket.Dispose(); + Self._log.ConnectionStop(Self._connectionId); + Complete(); + } + + public void Complete() + { + Self.OnWriteCompleted(Buffers, WriteStatus, WriteError); + } } } } diff --git a/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs index 0a49cb3f85..881c295c6a 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs @@ -12,6 +12,7 @@ using Microsoft.AspNet.Server.Kestrel.Http; using Microsoft.Dnx.Runtime; using Microsoft.Dnx.Runtime.Infrastructure; using Xunit; +using System.Linq; namespace Microsoft.AspNet.Server.KestrelTests { @@ -23,7 +24,7 @@ namespace Microsoft.AspNet.Server.KestrelTests private async Task App(Frame frame) { frame.ResponseHeaders.Clear(); - for (; ;) + while (true) { var buffer = new byte[8192]; var count = await frame.RequestBody.ReadAsync(buffer, 0, buffer.Length); @@ -60,17 +61,17 @@ namespace Microsoft.AspNet.Server.KestrelTests private async Task AppChunked(Frame frame) { + foreach (var h in frame.RequestHeaders) + { + Console.WriteLine($"{h.Key}: {h.Value}"); + } + Console.WriteLine($""); + frame.ResponseHeaders.Clear(); var data = new MemoryStream(); - for (; ;) + while(true) { - var buffer = new byte[8192]; - var count = await frame.RequestBody.ReadAsync(buffer, 0, buffer.Length); - if (count == 0) - { - break; - } - data.Write(buffer, 0, count); + await frame.RequestBody.CopyToAsync(data); } var bytes = data.ToArray(); frame.ResponseHeaders["Content-Length"] = new[] { bytes.Length.ToString() }; @@ -115,7 +116,7 @@ namespace Microsoft.AspNet.Server.KestrelTests socket.Send(Encoding.ASCII.GetBytes("POST / HTTP/1.0\r\n\r\nHello World")); socket.Shutdown(SocketShutdown.Send); var buffer = new byte[8192]; - for (; ;) + for (;;) { var length = socket.Receive(buffer); if (length == 0) { break; } diff --git a/test/Microsoft.AspNet.Server.KestrelTests/MemoryPoolBlock2Tests.cs b/test/Microsoft.AspNet.Server.KestrelTests/MemoryPoolBlock2Tests.cs index c5f91b33ac..a9c6e5a24f 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/MemoryPoolBlock2Tests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/MemoryPoolBlock2Tests.cs @@ -10,7 +10,7 @@ namespace Microsoft.AspNet.Server.KestrelTests public class MemoryPoolBlock2Tests { [Fact] - public void IndexOfAnyWorks() + public void SeekWorks() { using (var pool = new MemoryPool2()) { @@ -22,7 +22,16 @@ namespace Microsoft.AspNet.Server.KestrelTests var iterator = block.GetIterator(); foreach (var ch in Enumerable.Range(0, 256).Select(x => (char)x)) { - var hit = iterator.IndexOf(ch); + var hit = iterator; + hit.Seek(ch); + Assert.Equal(ch, iterator.GetLength(hit)); + + hit = iterator; + hit.Seek(ch, byte.MaxValue); + Assert.Equal(ch, iterator.GetLength(hit)); + + hit = iterator; + hit.Seek(byte.MaxValue, ch); Assert.Equal(ch, iterator.GetLength(hit)); } } @@ -72,5 +81,49 @@ namespace Microsoft.AspNet.Server.KestrelTests } } } + + [Fact] + public void AddDoesNotAdvanceAtEndOfCurrentBlock() + { + using (var pool = new MemoryPool2()) + { + var block1 = pool.Lease(256); + var block2 = block1.Next = pool.Lease(256); + + block1.End += 100; + block2.End += 200; + + var iter0 = block1.GetIterator(); + var iter100 = iter0.Add(100); + + var iter200a = iter0.Add(200); + var iter200b = iter100.Add(100); + + var iter300a = iter0.Add(300); + var iter300b = iter100.Add(200); + var iter300c = iter200a.Add(100); + + var iter300a2 = iter300a.Add(1); + var iter300b2 = iter300b.Add(1); + var iter300c2 = iter300c.Add(1); + + AssertIterator(iter0, block1, block1.Start); + AssertIterator(iter100, block1, block1.End); + AssertIterator(iter200a, block2, block2.Start+100); + AssertIterator(iter200b, block2, block2.Start + 100); + AssertIterator(iter300a, block2, block2.End); + AssertIterator(iter300b, block2, block2.End); + AssertIterator(iter300c, block2, block2.End); + AssertIterator(iter300a2, block2, block2.End); + AssertIterator(iter300b2, block2, block2.End); + AssertIterator(iter300c2, block2, block2.End); + } + } + + private void AssertIterator(MemoryPoolBlock2.Iterator iter, MemoryPoolBlock2 block, int index) + { + Assert.Same(block, iter.Block); + Assert.Equal(index, iter.Index); + } } } diff --git a/test/Microsoft.AspNet.Server.KestrelTests/MemoryPoolExtensions.cs b/test/Microsoft.AspNet.Server.KestrelTests/MemoryPoolExtensions.cs new file mode 100644 index 0000000000..3578dda184 --- /dev/null +++ b/test/Microsoft.AspNet.Server.KestrelTests/MemoryPoolExtensions.cs @@ -0,0 +1,13 @@ +using Microsoft.AspNet.Server.Kestrel.Http; + +namespace Microsoft.AspNet.Server.KestrelTests +{ + public static class MemoryPoolExtensions + { + public static MemoryPoolBlock2.Iterator Add(this MemoryPoolBlock2.Iterator iterator, int count) + { + int actual; + return iterator.CopyTo(new byte[count], 0, count, out actual); + } + } +} diff --git a/tools/Microsoft.StandardsPolice/StandardsPoliceCompileModule.cs b/tools/Microsoft.StandardsPolice/StandardsPoliceCompileModule.cs index 5de3961d58..5e3e5dfa06 100644 --- a/tools/Microsoft.StandardsPolice/StandardsPoliceCompileModule.cs +++ b/tools/Microsoft.StandardsPolice/StandardsPoliceCompileModule.cs @@ -71,8 +71,8 @@ namespace Microsoft.StandardsPolice acceptableOrder = true; } if (!acceptableOrder && - priorUsingDirective.Name.ToString().StartsWith("System.") && - !usingDirective.Name.ToString().StartsWith("System.")) + priorUsingDirective.Name.ToString().StartsWith("System") && + !usingDirective.Name.ToString().StartsWith("System")) { acceptableOrder = true; } From 52dc37eae740192ef19fbbefc7a2c1375e16bed8 Mon Sep 17 00:00:00 2001 From: Louis DeJardin Date: Wed, 16 Sep 2015 21:50:13 -0700 Subject: [PATCH 0268/1662] Fixing a header parsing bug When request header data arrives with \r\n split across packets --- .../Http/Frame.cs | 7 ++-- .../Http/Listener.cs | 3 +- .../Http/ListenerContext.cs | 20 +++++------ .../Infrastructure/KestrelThread.cs | 6 ++-- .../Infrastructure/KestrelTrace.cs | 32 ++++++++--------- .../KestrelEngine.cs | 36 ++++++++----------- .../ServerFactory.cs | 6 ++-- .../ServiceContext.cs | 12 +++++++ .../EngineTests.cs | 17 ++++----- .../MultipleLoopTests.cs | 13 +++---- .../NetworkingTests.cs | 7 ++-- .../SocketOutputTests.cs | 12 +++---- .../TestLogger.cs | 36 +++++++++++++++---- .../TestServer.cs | 14 +++++--- .../TestServiceContext.cs | 13 +++++++ 15 files changed, 142 insertions(+), 92 deletions(-) create mode 100644 test/Microsoft.AspNet.Server.KestrelTests/TestServiceContext.cs diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs index 5bbb1db8a1..080aae8d2b 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs @@ -614,9 +614,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Http chFirst = scan.Take(); // expecting: /r chSecond = scan.Take(); // expecting: /n - if (chSecond == '\r') + if (chSecond != '\n') { - // special case, "\r\r". move to the 2nd "\r" and try again + // "\r" was all by itself, move just after it and try again scan = endValue; scan.Take(); continue; @@ -633,6 +633,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } var name = beginName.GetArraySegment(endName); +#if DEBUG + var nameString = beginName.GetString(endName); +#endif var value = beginValue.GetString(endValue); if (wrapping) { diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs index 9cf57b5b4a..a828d4d17a 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs @@ -13,7 +13,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http /// public abstract class Listener : ListenerContext, IDisposable { - protected Listener(ServiceContext serviceContext) : base(serviceContext) + protected Listener(ServiceContext serviceContext) + : base(serviceContext) { Memory2 = new MemoryPool2(); } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerContext.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerContext.cs index d7e8d1f022..03d27501d6 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerContext.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerContext.cs @@ -7,17 +7,19 @@ using Microsoft.AspNet.Server.Kestrel.Infrastructure; namespace Microsoft.AspNet.Server.Kestrel.Http { - public class ListenerContext + public class ListenerContext : ServiceContext { - public ListenerContext() { } - - public ListenerContext(ServiceContext serviceContext) + public ListenerContext() + { + } + + public ListenerContext(ServiceContext serviceContext) + : base(serviceContext) { - Memory = serviceContext.Memory; - Log = serviceContext.Log; } public ListenerContext(ListenerContext listenerContext) + : base(listenerContext) { Thread = listenerContext.Thread; Application = listenerContext.Application; @@ -30,10 +32,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Http public Func Application { get; set; } - public IMemoryPool Memory { get; set; } - public MemoryPool2 Memory2 { get; set; } - - public IKestrelTrace Log { get; } } -} \ No newline at end of file +} diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs index 85683f2db1..b059bf6fe0 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs @@ -33,11 +33,11 @@ namespace Microsoft.AspNet.Server.Kestrel private ExceptionDispatchInfo _closeError; private IKestrelTrace _log; - public KestrelThread(KestrelEngine engine, ServiceContext serviceContext) + public KestrelThread(KestrelEngine engine) { _engine = engine; - _appShutdown = serviceContext.AppShutdown; - _log = serviceContext.Log; + _appShutdown = engine.AppShutdown; + _log = engine.Log; _loop = new UvLoopHandle(_log); _post = new UvAsyncHandle(_log); _thread = new Thread(ThreadStart); diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelTrace.cs b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelTrace.cs index 5fba4c7f01..b7cc35e5aa 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelTrace.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelTrace.cs @@ -12,87 +12,87 @@ namespace Microsoft.AspNet.Server.Kestrel /// public class KestrelTrace : IKestrelTrace { - private readonly ILogger _logger; + protected readonly ILogger _logger; public KestrelTrace(ILogger logger) { _logger = logger; } - public void ConnectionStart(long connectionId) + public virtual void ConnectionStart(long connectionId) { _logger.LogDebug(1, @"Connection id ""{ConnectionId}"" started.", connectionId); } - public void ConnectionStop(long connectionId) + public virtual void ConnectionStop(long connectionId) { _logger.LogDebug(2, @"Connection id ""{ConnectionId}"" stopped.", connectionId); } - public void ConnectionRead(long connectionId, int count) + public virtual void ConnectionRead(long connectionId, int count) { // Don't log for now since this could be *too* verbose. // Reserved: Event ID 3 } - public void ConnectionPause(long connectionId) + public virtual void ConnectionPause(long connectionId) { _logger.LogDebug(4, @"Connection id ""{ConnectionId}"" paused.", connectionId); } - public void ConnectionResume(long connectionId) + public virtual void ConnectionResume(long connectionId) { _logger.LogDebug(5, @"Connection id ""{ConnectionId}"" resumed.", connectionId); } - public void ConnectionReadFin(long connectionId) + public virtual void ConnectionReadFin(long connectionId) { _logger.LogDebug(6, @"Connection id ""{ConnectionId}"" received FIN.", connectionId); } - public void ConnectionWriteFin(long connectionId) + public virtual void ConnectionWriteFin(long connectionId) { _logger.LogDebug(7, @"Connection id ""{ConnectionId}"" sending FIN.", connectionId); } - public void ConnectionWroteFin(long connectionId, int status) + public virtual void ConnectionWroteFin(long connectionId, int status) { _logger.LogDebug(8, @"Connection id ""{ConnectionId}"" sent FIN with status ""{Status}"".", connectionId, status); } - public void ConnectionKeepAlive(long connectionId) + public virtual void ConnectionKeepAlive(long connectionId) { _logger.LogDebug(9, @"Connection id ""{ConnectionId}"" completed keep alive response.", connectionId); } - public void ConnectionDisconnect(long connectionId) + public virtual void ConnectionDisconnect(long connectionId) { _logger.LogDebug(10, @"Connection id ""{ConnectionId}"" disconnected.", connectionId); } - public void ConnectionWrite(long connectionId, int count) + public virtual void ConnectionWrite(long connectionId, int count) { // Don't log for now since this could be *too* verbose. // Reserved: Event ID 11 } - public void ConnectionWriteCallback(long connectionId, int status) + public virtual void ConnectionWriteCallback(long connectionId, int status) { // Don't log for now since this could be *too* verbose. // Reserved: Event ID 12 } - public void Log(LogLevel logLevel, int eventId, object state, Exception exception, Func formatter) + public virtual void Log(LogLevel logLevel, int eventId, object state, Exception exception, Func formatter) { _logger.Log(logLevel, eventId, state, exception, formatter); } - public bool IsEnabled(LogLevel logLevel) + public virtual bool IsEnabled(LogLevel logLevel) { return _logger.IsEnabled(logLevel); } - public IDisposable BeginScopeImpl(object state) + public virtual IDisposable BeginScopeImpl(object state) { return _logger.BeginScopeImpl(state); } diff --git a/src/Microsoft.AspNet.Server.Kestrel/KestrelEngine.cs b/src/Microsoft.AspNet.Server.Kestrel/KestrelEngine.cs index 893bdf94b2..94f5d74925 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/KestrelEngine.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/KestrelEngine.cs @@ -13,12 +13,10 @@ using Microsoft.Framework.Logging; namespace Microsoft.AspNet.Server.Kestrel { - public class KestrelEngine : IDisposable + public class KestrelEngine : ServiceContext, IDisposable { - private readonly ServiceContext _serviceContext; - - public KestrelEngine(ILibraryManager libraryManager, IApplicationShutdown appShutdownService, ILogger logger) - : this(appShutdownService, logger) + public KestrelEngine(ILibraryManager libraryManager, ServiceContext context) + : this(context) { Libuv = new Libuv(); @@ -63,21 +61,15 @@ namespace Microsoft.AspNet.Server.Kestrel } // For testing - internal KestrelEngine(Libuv uv, IApplicationShutdown appShutdownService, ILogger logger) - : this(appShutdownService, logger) + internal KestrelEngine(Libuv uv, ServiceContext context) + : this(context) { Libuv = uv; } - private KestrelEngine(IApplicationShutdown appShutdownService, ILogger logger) + private KestrelEngine(ServiceContext context) + : base(context) { - _serviceContext = new ServiceContext - { - AppShutdown = appShutdownService, - Memory = new MemoryPool(), - Log = new KestrelTrace(logger) - }; - Threads = new List(); } @@ -88,7 +80,7 @@ namespace Microsoft.AspNet.Server.Kestrel { for (var index = 0; index != count; ++index) { - Threads.Add(new KestrelThread(this, _serviceContext)); + Threads.Add(new KestrelThread(this)); } foreach (var thread in Threads) @@ -128,16 +120,16 @@ namespace Microsoft.AspNet.Server.Kestrel if (single) { var listener = usingPipes ? - (Listener) new PipeListener(_serviceContext) : - new TcpListener(_serviceContext); + (Listener) new PipeListener(this) : + new TcpListener(this); listeners.Add(listener); listener.StartAsync(scheme, host, port, thread, application).Wait(); } else if (first) { var listener = usingPipes - ? (ListenerPrimary) new PipeListenerPrimary(_serviceContext) - : new TcpListenerPrimary(_serviceContext); + ? (ListenerPrimary) new PipeListenerPrimary(this) + : new TcpListenerPrimary(this); listeners.Add(listener); listener.StartAsync(pipeName, scheme, host, port, thread, application).Wait(); @@ -145,8 +137,8 @@ namespace Microsoft.AspNet.Server.Kestrel else { var listener = usingPipes - ? (ListenerSecondary) new PipeListenerSecondary(_serviceContext) - : new TcpListenerSecondary(_serviceContext); + ? (ListenerSecondary) new PipeListenerSecondary(this) + : new TcpListenerSecondary(this); listeners.Add(listener); listener.StartAsync(pipeName, thread, application).Wait(); } diff --git a/src/Microsoft.AspNet.Server.Kestrel/ServerFactory.cs b/src/Microsoft.AspNet.Server.Kestrel/ServerFactory.cs index 73201020d4..36c1ab3952 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/ServerFactory.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/ServerFactory.cs @@ -53,14 +53,14 @@ namespace Microsoft.AspNet.Server.Kestrel try { var information = (KestrelServerInformation)serverFeatures.Get(); - var engine = new KestrelEngine(_libraryManager, _appShutdownService, _logger); + var engine = new KestrelEngine(_libraryManager, new ServiceContext { AppShutdown = _appShutdownService, Log = new KestrelTrace(_logger) }); disposables.Push(engine); if (information.ThreadCount < 0) { - throw new ArgumentOutOfRangeException(nameof(information.ThreadCount), - information.ThreadCount, + throw new ArgumentOutOfRangeException(nameof(information.ThreadCount), + information.ThreadCount, "ThreadCount cannot be negative"); } diff --git a/src/Microsoft.AspNet.Server.Kestrel/ServiceContext.cs b/src/Microsoft.AspNet.Server.Kestrel/ServiceContext.cs index 7e9d4d23f1..8e915dccb9 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/ServiceContext.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/ServiceContext.cs @@ -9,6 +9,18 @@ namespace Microsoft.AspNet.Server.Kestrel { public class ServiceContext { + public ServiceContext() + { + Memory = new MemoryPool(); + } + + public ServiceContext(ServiceContext context) + { + AppShutdown = context.AppShutdown; + Memory = context.Memory; + Log = context.Log; + } + public IApplicationShutdown AppShutdown { get; set; } public IMemoryPool Memory { get; set; } diff --git a/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs index 881c295c6a..d3882bedc4 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs @@ -61,19 +61,20 @@ namespace Microsoft.AspNet.Server.KestrelTests private async Task AppChunked(Frame frame) { + Console.WriteLine($"----"); + Console.WriteLine($"{frame.Method} {frame.RequestUri} {frame.HttpVersion}"); foreach (var h in frame.RequestHeaders) { Console.WriteLine($"{h.Key}: {h.Value}"); } Console.WriteLine($""); - frame.ResponseHeaders.Clear(); var data = new MemoryStream(); - while(true) - { - await frame.RequestBody.CopyToAsync(data); - } + await frame.RequestBody.CopyToAsync(data); var bytes = data.ToArray(); + Console.WriteLine($"{Encoding.ASCII.GetString(bytes)}"); + + frame.ResponseHeaders.Clear(); frame.ResponseHeaders["Content-Length"] = new[] { bytes.Length.ToString() }; await frame.ResponseBody.WriteAsync(bytes, 0, bytes.Length); } @@ -87,7 +88,7 @@ namespace Microsoft.AspNet.Server.KestrelTests [Fact] public void EngineCanStartAndStop() { - var engine = new KestrelEngine(LibraryManager, new ShutdownNotImplemented(), new TestLogger()); + var engine = new KestrelEngine(LibraryManager, new TestServiceContext()); engine.Start(1); engine.Dispose(); } @@ -95,7 +96,7 @@ namespace Microsoft.AspNet.Server.KestrelTests [Fact] public void ListenerCanCreateAndDispose() { - var engine = new KestrelEngine(LibraryManager, new ShutdownNotImplemented(), new TestLogger()); + var engine = new KestrelEngine(LibraryManager, new TestServiceContext()); engine.Start(1); var started = engine.CreateServer("http", "localhost", 54321, App); started.Dispose(); @@ -106,7 +107,7 @@ namespace Microsoft.AspNet.Server.KestrelTests [Fact] public void ConnectionCanReadAndWrite() { - var engine = new KestrelEngine(LibraryManager, new ShutdownNotImplemented(), new TestLogger()); + var engine = new KestrelEngine(LibraryManager, new TestServiceContext()); engine.Start(1); var started = engine.CreateServer("http", "localhost", 54321, App); diff --git a/test/Microsoft.AspNet.Server.KestrelTests/MultipleLoopTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/MultipleLoopTests.cs index 10bd46674e..3da9c93f4a 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/MultipleLoopTests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/MultipleLoopTests.cs @@ -15,11 +15,12 @@ namespace Microsoft.AspNet.Server.KestrelTests public class MultipleLoopTests { private readonly Libuv _uv; - private readonly IKestrelTrace _logger = new KestrelTrace(new TestLogger()); + private readonly IKestrelTrace _logger; public MultipleLoopTests() { - var engine = new KestrelEngine(LibraryManager, new ShutdownNotImplemented(), new TestLogger()); + var engine = new KestrelEngine(LibraryManager, new TestServiceContext()); _uv = engine.Libuv; + _logger = engine.Log; } ILibraryManager LibraryManager @@ -81,7 +82,7 @@ namespace Microsoft.AspNet.Server.KestrelTests return; } - var writeRequest = new UvWriteReq(new KestrelTrace(new TestLogger())); + var writeRequest = new UvWriteReq(new KestrelTrace(new TestKestrelTrace())); writeRequest.Init(loop); writeRequest.Write( serverConnectionPipe, @@ -100,7 +101,7 @@ namespace Microsoft.AspNet.Server.KestrelTests { var loop2 = new UvLoopHandle(_logger); var clientConnectionPipe = new UvPipeHandle(_logger); - var connect = new UvConnectRequest(new KestrelTrace(new TestLogger())); + var connect = new UvConnectRequest(new KestrelTrace(new TestKestrelTrace())); loop2.Init(_uv); clientConnectionPipe.Init(loop2, true); @@ -174,7 +175,7 @@ namespace Microsoft.AspNet.Server.KestrelTests serverConnectionPipeAcceptedEvent.WaitOne(); - var writeRequest = new UvWriteReq(new KestrelTrace(new TestLogger())); + var writeRequest = new UvWriteReq(new KestrelTrace(new TestKestrelTrace())); writeRequest.Init(loop); writeRequest.Write2( serverConnectionPipe, @@ -196,7 +197,7 @@ namespace Microsoft.AspNet.Server.KestrelTests { var loop2 = new UvLoopHandle(_logger); var clientConnectionPipe = new UvPipeHandle(_logger); - var connect = new UvConnectRequest(new KestrelTrace(new TestLogger())); + var connect = new UvConnectRequest(new KestrelTrace(new TestKestrelTrace())); loop2.Init(_uv); clientConnectionPipe.Init(loop2, true); diff --git a/test/Microsoft.AspNet.Server.KestrelTests/NetworkingTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/NetworkingTests.cs index 121c042f69..5c4a47f9c0 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/NetworkingTests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/NetworkingTests.cs @@ -21,11 +21,12 @@ namespace Microsoft.AspNet.Server.KestrelTests public class NetworkingTests { private readonly Libuv _uv; - private readonly IKestrelTrace _logger = new KestrelTrace(new TestLogger()); + private readonly IKestrelTrace _logger; public NetworkingTests() { - var engine = new KestrelEngine(LibraryManager, new ShutdownNotImplemented(), new TestLogger()); + var engine = new KestrelEngine(LibraryManager, new TestServiceContext()); _uv = engine.Libuv; + _logger = engine.Log; } ILibraryManager LibraryManager @@ -208,7 +209,7 @@ namespace Microsoft.AspNet.Server.KestrelTests { for (var x = 0; x != 2; ++x) { - var req = new UvWriteReq(new KestrelTrace(new TestLogger())); + var req = new UvWriteReq(new KestrelTrace(new TestKestrelTrace())); req.Init(loop); req.Write( tcp2, diff --git a/test/Microsoft.AspNet.Server.KestrelTests/SocketOutputTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/SocketOutputTests.cs index 6253b0651d..489f683bf6 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/SocketOutputTests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/SocketOutputTests.cs @@ -32,13 +32,13 @@ namespace Microsoft.AspNet.Server.KestrelTests } }; - using (var kestrelEngine = new KestrelEngine(mockLibuv, new ShutdownNotImplemented(), new TestLogger())) + using (var kestrelEngine = new KestrelEngine(mockLibuv, new TestServiceContext())) { kestrelEngine.Start(count: 1); var kestrelThread = kestrelEngine.Threads[0]; - var socket = new MockSocket(kestrelThread.Loop.ThreadId, new KestrelTrace(new TestLogger())); - var trace = new KestrelTrace(new TestLogger()); + var socket = new MockSocket(kestrelThread.Loop.ThreadId, new KestrelTrace(new TestKestrelTrace())); + var trace = new KestrelTrace(new TestKestrelTrace()); var socketOutput = new SocketOutput(kestrelThread, socket, 0, trace); // I doubt _maxBytesPreCompleted will ever be over a MB. If it is, we should change this test. @@ -77,13 +77,13 @@ namespace Microsoft.AspNet.Server.KestrelTests } }; - using (var kestrelEngine = new KestrelEngine(mockLibuv, new ShutdownNotImplemented(), new TestLogger())) + using (var kestrelEngine = new KestrelEngine(mockLibuv, new TestServiceContext())) { kestrelEngine.Start(count: 1); var kestrelThread = kestrelEngine.Threads[0]; - var socket = new MockSocket(kestrelThread.Loop.ThreadId, new KestrelTrace(new TestLogger())); - var trace = new KestrelTrace(new TestLogger()); + var socket = new MockSocket(kestrelThread.Loop.ThreadId, new KestrelTrace(new TestKestrelTrace())); + var trace = new KestrelTrace(new TestKestrelTrace()); var socketOutput = new SocketOutput(kestrelThread, socket, 0, trace); var bufferSize = maxBytesPreCompleted; diff --git a/test/Microsoft.AspNet.Server.KestrelTests/TestLogger.cs b/test/Microsoft.AspNet.Server.KestrelTests/TestLogger.cs index 2c25a46691..e643c1d0f9 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/TestLogger.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/TestLogger.cs @@ -4,20 +4,44 @@ using Microsoft.Framework.Logging; namespace Microsoft.AspNet.Server.KestrelTests { - public class TestLogger : ILogger + public class TestKestrelTrace : KestrelTrace { - public void Log(LogLevel logLevel, int eventId, object state, Exception exception, Func formatter) + public TestKestrelTrace() : base(new TestLogger()) { + } - public bool IsEnabled(LogLevel logLevel) + public override void ConnectionRead(long connectionId, int count) { - return false; + _logger.LogDebug(1, @"Connection id ""{ConnectionId}"" recv {count} bytes.", connectionId, count); } - public IDisposable BeginScopeImpl(object state) + public override void ConnectionWrite(long connectionId, int count) { - return new Disposable(() => { }); + _logger.LogDebug(1, @"Connection id ""{ConnectionId}"" send {count} bytes.", connectionId, count); + } + + public override void ConnectionWriteCallback(long connectionId, int status) + { + _logger.LogDebug(1, @"Connection id ""{ConnectionId}"" send finished with status {status}.", connectionId, status); + } + + public class TestLogger : ILogger + { + public void Log(LogLevel logLevel, int eventId, object state, Exception exception, Func formatter) + { + Console.WriteLine($"Log {logLevel}[{eventId}]: {formatter(state, exception)} {exception?.Message}"); + } + + public bool IsEnabled(LogLevel logLevel) + { + return true; + } + + public IDisposable BeginScopeImpl(object state) + { + return new Disposable(() => { }); + } } } } \ No newline at end of file diff --git a/test/Microsoft.AspNet.Server.KestrelTests/TestServer.cs b/test/Microsoft.AspNet.Server.KestrelTests/TestServer.cs index 3ada706a90..7ad0141810 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/TestServer.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/TestServer.cs @@ -27,25 +27,29 @@ namespace Microsoft.AspNet.Server.KestrelTests { get { - try{ + try + { var locator = CallContextServiceLocator.Locator; - if (locator == null) + if (locator == null) { return null; } var services = locator.ServiceProvider; - if (services == null) + if (services == null) { return null; } return (ILibraryManager)services.GetService(typeof(ILibraryManager)); - } catch (NullReferenceException) { return null; } + } + catch (NullReferenceException) { return null; } } } public void Create(Func app) { - _engine = new KestrelEngine(LibraryManager, new ShutdownNotImplemented(), new TestLogger()); + _engine = new KestrelEngine( + LibraryManager, + new TestServiceContext()); _engine.Start(1); _server = _engine.CreateServer( "http", diff --git a/test/Microsoft.AspNet.Server.KestrelTests/TestServiceContext.cs b/test/Microsoft.AspNet.Server.KestrelTests/TestServiceContext.cs new file mode 100644 index 0000000000..29b8cfb145 --- /dev/null +++ b/test/Microsoft.AspNet.Server.KestrelTests/TestServiceContext.cs @@ -0,0 +1,13 @@ +using Microsoft.AspNet.Server.Kestrel; + +namespace Microsoft.AspNet.Server.KestrelTests +{ + public class TestServiceContext : ServiceContext + { + public TestServiceContext() + { + AppShutdown = new ShutdownNotImplemented(); + Log = new TestKestrelTrace(); + } + } +} From 79175694660112f2b421912433aee5e5ff78d6fc Mon Sep 17 00:00:00 2001 From: Louis DeJardin Date: Wed, 16 Sep 2015 22:16:06 -0700 Subject: [PATCH 0269/1662] Changing chunked with exception test criteria --- .../ChunkedResponseTests.cs | 8 ++++++-- .../TestConnection.cs | 7 ++++--- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/test/Microsoft.AspNet.Server.KestrelTests/ChunkedResponseTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/ChunkedResponseTests.cs index 162a29263a..f7e4898cad 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/ChunkedResponseTests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/ChunkedResponseTests.cs @@ -146,8 +146,12 @@ namespace Microsoft.AspNet.Server.KestrelTests "", ""); - // Nothing (not even headers) are written, but the connection is closed. - await connection.ReceiveEnd(); + // Headers are sent before connection is closed, but chunked body terminator isn't sent + await connection.ReceiveEnd( + "HTTP/1.1 200 OK", + "Transfer-Encoding: chunked", + "", + ""); } } } diff --git a/test/Microsoft.AspNet.Server.KestrelTests/TestConnection.cs b/test/Microsoft.AspNet.Server.KestrelTests/TestConnection.cs index 4afd1628d9..773bddf70d 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/TestConnection.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/TestConnection.cs @@ -119,9 +119,10 @@ namespace Microsoft.AspNet.Server.KestrelTests public async Task ReceiveEnd(params string[] lines) { await Receive(lines); - var ch = new char[1]; - var count = await _reader.ReadAsync(ch, 0, 1); - Assert.Equal(0, count); + var ch = new char[128]; + var count = await _reader.ReadAsync(ch, 0, 128); + var text = new string(ch, 0, count); + Assert.Equal("", text); } } } \ No newline at end of file From d3a87c4c1423834cd0cd05bc38ed98dd28d2e396 Mon Sep 17 00:00:00 2001 From: Louis DeJardin Date: Thu, 17 Sep 2015 18:17:26 -0700 Subject: [PATCH 0270/1662] Removing MessageBodyExchanger base class --- .../Http/Connection.cs | 7 +- .../Http/Frame.cs | 98 +++++---- .../Http/MessageBody.cs | 186 ++++++++++------- .../Http/MessageBodyExchanger.cs | 188 ----------------- .../Http/SocketInput.cs | 174 ++++++++-------- .../MessageBodyExchangerTests.cs | 192 ------------------ .../TestConnection.cs | 4 +- .../TestInput.cs | 5 +- .../TestLogger.cs | 6 +- 9 files changed, 256 insertions(+), 604 deletions(-) delete mode 100644 src/Microsoft.AspNet.Server.Kestrel/Http/MessageBodyExchanger.cs delete mode 100644 test/Microsoft.AspNet.Server.KestrelTests/MessageBodyExchangerTests.cs diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs index 05c1eb1878..72a753a6f9 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs @@ -54,7 +54,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http private Libuv.uv_buf_t OnAlloc(UvStreamHandle handle, int suggestedSize) { - var result = SocketInput.Pin(2048); + var result = SocketInput.IncomingStart(2048); return handle.Libuv.buf_init( result.DataPtr, @@ -68,8 +68,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Http private void OnRead(UvStreamHandle handle, int readCount, int errorCode, Exception error) { - SocketInput.Unpin(readCount); - var normalRead = readCount != 0 && errorCode == 0; var normalDone = readCount == 0 && (errorCode == 0 || errorCode == Constants.ECONNRESET || errorCode == Constants.EOF); var errorDone = !(normalDone || normalRead); @@ -80,12 +78,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } else if (normalDone || errorDone) { - SocketInput.RemoteIntakeFin = true; _socket.ReadStop(); Log.ConnectionReadFin(_connectionId); } - SocketInput.SetCompleted(errorDone ? error : null); + SocketInput.IncomingComplete(readCount, errorDone ? error : null); } void IConnectionControl.Pause() diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs index 080aae8d2b..944d9807ec 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs @@ -505,52 +505,62 @@ namespace Microsoft.AspNet.Server.Kestrel.Http private bool TakeStartLine(SocketInput input) { - var scan = input.GetIterator(); - - var begin = scan; - if (scan.Seek(' ') == -1) + var scan = input.ConsumingStart(); + var consumed = scan; + try { - return false; - } - var method = begin.GetString(scan); - - scan.Take(); - begin = scan; - var chFound = scan.Seek(' ', '?'); - if (chFound == -1) - { - return false; - } - var requestUri = begin.GetString(scan); - - var queryString = ""; - if (chFound == '?') - { - begin = scan; - if (scan.Seek(' ') != ' ') + var begin = scan; + if (scan.Seek(' ') == -1) { return false; } - queryString = begin.GetString(scan); - } + var method = begin.GetString(scan); - scan.Take(); - begin = scan; - if (scan.Seek('\r') == -1) + scan.Take(); + begin = scan; + var chFound = scan.Seek(' ', '?'); + if (chFound == -1) + { + return false; + } + var requestUri = begin.GetString(scan); + + var queryString = ""; + if (chFound == '?') + { + begin = scan; + if (scan.Seek(' ') != ' ') + { + return false; + } + queryString = begin.GetString(scan); + } + + scan.Take(); + begin = scan; + if (scan.Seek('\r') == -1) + { + return false; + } + var httpVersion = begin.GetString(scan); + + scan.Take(); + if (scan.Take() != '\n') + { + return false; + } + + consumed = scan; + Method = method; + RequestUri = requestUri; + QueryString = queryString; + HttpVersion = httpVersion; + return true; + } + finally { - return false; + input.ConsumingComplete(consumed, scan); } - var httpVersion = begin.GetString(scan); - - scan.Take(); - if (scan.Take() != '\n') return false; - - Method = method; - RequestUri = requestUri; - QueryString = queryString; - HttpVersion = httpVersion; - input.JumpTo(scan); - return true; } static string GetString(ArraySegment range, int startIndex, int endIndex) @@ -560,12 +570,12 @@ namespace Microsoft.AspNet.Server.Kestrel.Http private bool TakeMessageHeaders(SocketInput input) { - int chFirst; - int chSecond; - var scan = input.GetIterator(); + var scan = input.ConsumingStart(); var consumed = scan; try { + int chFirst; + int chSecond; while (!scan.IsEnd) { var beginName = scan; @@ -642,8 +652,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http value = value.Replace("\r\n", " "); } - _requestHeaders.Append(name.Array, name.Offset, name.Count, value); consumed = scan; + _requestHeaders.Append(name.Array, name.Offset, name.Count, value); break; } } @@ -651,7 +661,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } finally { - input.JumpTo(consumed); + input.ConsumingComplete(consumed, scan); } } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/MessageBody.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/MessageBody.cs index 257df299aa..caf528fb5e 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/MessageBody.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/MessageBody.cs @@ -9,14 +9,36 @@ using Microsoft.Framework.Primitives; namespace Microsoft.AspNet.Server.Kestrel.Http { - public abstract class MessageBody : MessageBodyExchanger + public abstract class MessageBody { - protected MessageBody(FrameContext context) : base(context) + private FrameContext _context; + private int _send100Continue = 1; + + protected MessageBody(FrameContext context) { + _context = context; } public bool RequestKeepAlive { get; protected set; } + public Task ReadAsync(ArraySegment buffer, CancellationToken cancellationToken = default(CancellationToken)) + { + Task result = null; + var send100Continue = 0; + result = ReadAsyncImplementation(buffer, cancellationToken); + if (!result.IsCompleted) + { + send100Continue = Interlocked.Exchange(ref _send100Continue, 0); + } + if (send100Continue == 1) + { + _context.FrameControl.ProduceContinue(); + } + return result; + } + + public abstract Task ReadAsyncImplementation(ArraySegment buffer, CancellationToken cancellationToken); + public static MessageBody For( string httpVersion, IDictionary headers, @@ -90,10 +112,10 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { await input; - var begin = input.GetIterator(); + var begin = input.ConsumingStart(); int actual; var end = begin.CopyTo(buffer.Array, buffer.Offset, buffer.Count, out actual); - input.JumpTo(end); + input.ConsumingComplete(end, end); if (actual != 0) { @@ -134,11 +156,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http await input; - var begin = input.GetIterator(); + var begin = input.ConsumingStart(); int actual; var end = begin.CopyTo(buffer.Array, buffer.Offset, limit, out actual); _inputLength -= actual; - input.JumpTo(end); + input.ConsumingComplete(end, end); if (actual != 0) { return actual; @@ -198,11 +220,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http await input; } - var begin = input.GetIterator(); + var begin = input.ConsumingStart(); int actual; var end = begin.CopyTo(buffer.Array, buffer.Offset, limit, out actual); _inputLength -= actual; - input.JumpTo(end); + input.ConsumingComplete(end, end); if (_inputLength == 0) { @@ -215,16 +237,18 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } while (_mode == Mode.ChunkSuffix) { - var scan = input.GetIterator(); + var scan = input.ConsumingStart(); + var consumed = scan; var ch1 = scan.Take(); var ch2 = scan.Take(); if (ch1 == -1 || ch2 == -1) { + input.ConsumingComplete(consumed, scan); await input; } else if (ch1 == '\r' && ch2 == '\n') { - input.JumpTo(scan); + input.ConsumingComplete(scan, scan); _mode = Mode.ChunkPrefix; } else @@ -239,84 +263,92 @@ namespace Microsoft.AspNet.Server.Kestrel.Http private static bool TakeChunkedLine(SocketInput baton, ref int chunkSizeOut) { - var scan = baton.GetIterator(); - var ch0 = scan.Take(); - var chunkSize = 0; - var mode = 0; - while (ch0 != -1) + var scan = baton.ConsumingStart(); + var consumed = scan; + try { - var ch1 = scan.Take(); - if (ch1 == -1) + var ch0 = scan.Take(); + var chunkSize = 0; + var mode = 0; + while (ch0 != -1) { - return false; - } + var ch1 = scan.Take(); + if (ch1 == -1) + { + return false; + } - if (mode == 0) - { - if (ch0 >= '0' && ch0 <= '9') + if (mode == 0) { - chunkSize = chunkSize * 0x10 + (ch0 - '0'); + if (ch0 >= '0' && ch0 <= '9') + { + chunkSize = chunkSize * 0x10 + (ch0 - '0'); + } + else if (ch0 >= 'A' && ch0 <= 'F') + { + chunkSize = chunkSize * 0x10 + (ch0 - ('A' - 10)); + } + else if (ch0 >= 'a' && ch0 <= 'f') + { + chunkSize = chunkSize * 0x10 + (ch0 - ('a' - 10)); + } + else + { + throw new NotImplementedException("INVALID REQUEST FORMAT"); + } + mode = 1; } - else if (ch0 >= 'A' && ch0 <= 'F') + else if (mode == 1) { - chunkSize = chunkSize * 0x10 + (ch0 - ('A' - 10)); + if (ch0 >= '0' && ch0 <= '9') + { + chunkSize = chunkSize * 0x10 + (ch0 - '0'); + } + else if (ch0 >= 'A' && ch0 <= 'F') + { + chunkSize = chunkSize * 0x10 + (ch0 - ('A' - 10)); + } + else if (ch0 >= 'a' && ch0 <= 'f') + { + chunkSize = chunkSize * 0x10 + (ch0 - ('a' - 10)); + } + else if (ch0 == ';') + { + mode = 2; + } + else if (ch0 == '\r' && ch1 == '\n') + { + consumed = scan; + chunkSizeOut = chunkSize; + return true; + } + else + { + throw new NotImplementedException("INVALID REQUEST FORMAT"); + } } - else if (ch0 >= 'a' && ch0 <= 'f') + else if (mode == 2) { - chunkSize = chunkSize * 0x10 + (ch0 - ('a' - 10)); + if (ch0 == '\r' && ch1 == '\n') + { + consumed = scan; + chunkSizeOut = chunkSize; + return true; + } + else + { + // chunk-extensions not currently parsed + } } - else - { - throw new NotImplementedException("INVALID REQUEST FORMAT"); - } - mode = 1; - } - else if (mode == 1) - { - if (ch0 >= '0' && ch0 <= '9') - { - chunkSize = chunkSize * 0x10 + (ch0 - '0'); - } - else if (ch0 >= 'A' && ch0 <= 'F') - { - chunkSize = chunkSize * 0x10 + (ch0 - ('A' - 10)); - } - else if (ch0 >= 'a' && ch0 <= 'f') - { - chunkSize = chunkSize * 0x10 + (ch0 - ('a' - 10)); - } - else if (ch0 == ';') - { - mode = 2; - } - else if (ch0 == '\r' && ch1 == '\n') - { - baton.JumpTo(scan); - chunkSizeOut = chunkSize; - return true; - } - else - { - throw new NotImplementedException("INVALID REQUEST FORMAT"); - } - } - else if (mode == 2) - { - if (ch0 == '\r' && ch1 == '\n') - { - baton.JumpTo(scan); - chunkSizeOut = chunkSize; - return true; - } - else - { - // chunk-extensions not currently parsed - } - } - ch0 = ch1; + ch0 = ch1; + } + return false; + } + finally + { + baton.ConsumingComplete(consumed, scan); } - return false; } private enum Mode diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/MessageBodyExchanger.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/MessageBodyExchanger.cs deleted file mode 100644 index f0e72084fb..0000000000 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/MessageBodyExchanger.cs +++ /dev/null @@ -1,188 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading; -using System.Threading.Tasks; - -namespace Microsoft.AspNet.Server.Kestrel.Http -{ - /// - /// Summary description for MessageBodyExchanger - /// - public class MessageBodyExchanger - { - private static readonly WaitCallback _completePending = CompletePending; - protected readonly FrameContext _context; - - private object _sync = new Object(); - - private ArraySegment _buffer; - private Queue _reads = new Queue(); - private bool _send100Continue = true; - - public MessageBodyExchanger(FrameContext context) - { - _context = context; - _buffer = new ArraySegment(_context.Memory.Empty); - } - - public bool LocalIntakeFin { get; set; } - - public void Transfer(int count, bool fin) - { - if (count == 0 && !fin) - { - return; - } - var input = _context.SocketInput; - lock (_sync) - { - if (_send100Continue) - { - _send100Continue = false; - } - - // NOTE: this should not copy each time - var oldBuffer = _buffer; - var newData = _context.SocketInput.Take(count); - - var newBuffer = new ArraySegment( - _context.Memory.AllocByte(oldBuffer.Count + newData.Count), - 0, - oldBuffer.Count + newData.Count); - - Array.Copy(oldBuffer.Array, oldBuffer.Offset, newBuffer.Array, newBuffer.Offset, oldBuffer.Count); - Array.Copy(newData.Array, newData.Offset, newBuffer.Array, newBuffer.Offset + oldBuffer.Count, newData.Count); - - _buffer = newBuffer; - _context.Memory.FreeByte(oldBuffer.Array); - - if (fin) - { - LocalIntakeFin = true; - } - if (_reads.Count != 0) - { - ThreadPool.QueueUserWorkItem(_completePending, this); - } - } - } - - public Task ReadAsync(ArraySegment buffer) - { - Task result = null; - var send100Continue = false; - while (result == null) - { - while (CompletePending()) - { - // earlier reads have priority - } - lock (_sync) - { - if (_buffer.Count != 0 || buffer.Count == 0 || LocalIntakeFin) - { - // there is data we can take right now - if (_reads.Count != 0) - { - // someone snuck in, try again - continue; - } - - var count = Math.Min(buffer.Count, _buffer.Count); - Array.Copy(_buffer.Array, _buffer.Offset, buffer.Array, buffer.Offset, count); - _buffer = new ArraySegment(_buffer.Array, _buffer.Offset + count, _buffer.Count - count); - result = Task.FromResult(count); - } - else - { - // add ourselves to the line - var tcs = new TaskCompletionSource(); - _reads.Enqueue(new ReadOperation - { - Buffer = buffer, - CompletionSource = tcs, - }); - result = tcs.Task; - send100Continue = _send100Continue; - _send100Continue = false; - } - } - } - if (send100Continue) - { - _context.FrameControl.ProduceContinue(); - } - return result; - } - - public Task ReadAsync(ArraySegment buffer, CancellationToken cancellationToken) - { - Task result = null; - var send100Continue = false; - result = ReadAsyncImplementation(buffer, cancellationToken); - if (!result.IsCompleted) - { - lock (_sync) - { - send100Continue = _send100Continue; - _send100Continue = false; - } - } - if (send100Continue) - { - _context.FrameControl.ProduceContinue(); - } - return result; - } - - public virtual Task ReadAsyncImplementation(ArraySegment buffer, CancellationToken cancellationToken) - { - throw new NotImplementedException("TODO"); - } - - static void CompletePending(object state) - { - while (((MessageBodyExchanger)state).CompletePending()) - { - // loop until none left - } - } - - bool CompletePending() - { - ReadOperation read; - int count; - lock (_sync) - { - if (_buffer.Count == 0 && !LocalIntakeFin) - { - return false; - } - if (_reads.Count == 0) - { - return false; - } - read = _reads.Dequeue(); - - count = Math.Min(read.Buffer.Count, _buffer.Count); - Array.Copy(_buffer.Array, _buffer.Offset, read.Buffer.Array, read.Buffer.Offset, count); - _buffer = new ArraySegment(_buffer.Array, _buffer.Offset + count, _buffer.Count - count); - } - if (read.CompletionSource != null) - { - read.CompletionSource.SetResult(count); - } - return true; - } - - public struct ReadOperation - { - public TaskCompletionSource CompletionSource; - public ArraySegment Buffer; - } - } -} diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketInput.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketInput.cs index 1ff2530bc4..03ef803e9c 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketInput.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketInput.cs @@ -3,6 +3,7 @@ using System; using System.Diagnostics; +using System.IO; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Threading; @@ -16,6 +17,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http private static readonly Action _awaitableIsNotCompleted = () => { }; private readonly MemoryPool2 _memory; + private readonly ManualResetEventSlim _manualResetEvent = new ManualResetEventSlim(false); private Action _awaitableState; private Exception _awaitableError; @@ -23,7 +25,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http private MemoryPoolBlock2 _head; private MemoryPoolBlock2 _tail; private MemoryPoolBlock2 _pinned; - private readonly object _syncHeadAndTail = new Object(); + private readonly object _sync = new Object(); public SocketInput(MemoryPool2 memory) { @@ -55,16 +57,16 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return taken; } - public PinResult Pin(int minimumSize) + public IncomingBuffer IncomingStart(int minimumSize) { - lock (_syncHeadAndTail) + lock (_sync) { if (_tail != null && minimumSize <= _tail.Data.Offset + _tail.Data.Count - _tail.End) { _pinned = _tail; var data = new ArraySegment(_pinned.Data.Array, _pinned.End, _pinned.Data.Offset + _pinned.Data.Count - _pinned.End); var dataPtr = _pinned.Pin(); - return new PinResult + return new IncomingBuffer { Data = data, DataPtr = dataPtr, @@ -73,19 +75,21 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } _pinned = _memory.Lease(minimumSize); - return new PinResult + return new IncomingBuffer { Data = _pinned.Data, DataPtr = _pinned.Pin() }; } - public void Unpin(int count) + public void IncomingComplete(int count, Exception error) { - // Unpin may called without an earlier Pin - if (_pinned != null) + Action awaitableState; + + lock (_sync) { - lock (_syncHeadAndTail) + // Unpin may called without an earlier Pin + if (_pinned != null) { _pinned.End += count; if (_head == null) @@ -103,6 +107,71 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } _pinned = null; + + if (count == 0) + { + RemoteIntakeFin = true; + } + if (error != null) + { + _awaitableError = error; + } + + awaitableState = Interlocked.Exchange( + ref _awaitableState, + _awaitableIsCompleted); + + _manualResetEvent.Set(); + } + + if (awaitableState != _awaitableIsCompleted && + awaitableState != _awaitableIsNotCompleted) + { + Task.Run(awaitableState); + } + } + + public MemoryPoolBlock2.Iterator ConsumingStart() + { + lock (_sync) + { + return new MemoryPoolBlock2.Iterator(_head); + } + } + + public void ConsumingComplete( + MemoryPoolBlock2.Iterator consumed, + MemoryPoolBlock2.Iterator examined) + { + MemoryPoolBlock2 returnStart = null; + MemoryPoolBlock2 returnEnd = null; + lock (_sync) + { + if (!consumed.IsDefault) + { + returnStart = _head; + returnEnd = consumed.Block; + _head = consumed.Block; + _head.Start = consumed.Index; + } + if (!examined.IsDefault && + examined.IsEnd && + RemoteIntakeFin == false && + _awaitableError == null) + { + _manualResetEvent.Reset(); + + var awaitableState = Interlocked.CompareExchange( + ref _awaitableState, + _awaitableIsNotCompleted, + _awaitableIsCompleted); + } + } + while (returnStart != returnEnd) + { + var returnBlock = returnStart; + returnStart = returnStart.Next; + returnBlock.Pool.Return(returnBlock); } } @@ -111,7 +180,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return this; } - public void OnCompleted(Action continuation) { var awaitableState = Interlocked.CompareExchange( @@ -138,94 +206,20 @@ namespace Microsoft.AspNet.Server.Kestrel.Http OnCompleted(continuation); } - public void SetCompleted(Exception error) - { - if (error != null) - { - _awaitableError = error; - } - - var awaitableState = Interlocked.Exchange( - ref _awaitableState, - _awaitableIsCompleted); - - if (awaitableState != _awaitableIsCompleted && - awaitableState != _awaitableIsNotCompleted) - { - Task.Run(awaitableState); - } - } - - public void SetNotCompleted() - { - if (RemoteIntakeFin || _awaitableError != null) - { - // TODO: Race condition - setting either of these can leave awaitable not completed - return; - } - var awaitableState = Interlocked.CompareExchange( - ref _awaitableState, - _awaitableIsNotCompleted, - _awaitableIsCompleted); - - if (awaitableState == _awaitableIsNotCompleted) - { - return; - } - else if (awaitableState == _awaitableIsCompleted) - { - return; - } - else - { - // THIS IS AN ERROR STATE - ONLY ONE WAITER MAY EXIST - } - } - public void GetResult() { + if (!IsCompleted) + { + _manualResetEvent.Wait(); + } var error = _awaitableError; if (error != null) { - throw new AggregateException(error); + throw new IOException(error.Message, error); } } - public MemoryPoolBlock2.Iterator GetIterator() - { - lock (_syncHeadAndTail) - { - return new MemoryPoolBlock2.Iterator(_head); - } - } - - public void JumpTo(MemoryPoolBlock2.Iterator iterator) - { - MemoryPoolBlock2 returnStart; - MemoryPoolBlock2 returnEnd; - lock (_syncHeadAndTail) - { - // TODO: leave _pinned intact - // TODO: return when empty - - returnStart = _head; - returnEnd = iterator.Block; - _head = iterator.Block; - _head.Start = iterator.Index; - if (iterator.IsEnd) - { - SetNotCompleted(); - } - } - while (returnStart != returnEnd) - { - var returnBlock = returnStart; - returnStart = returnStart.Next; - returnBlock.Pool.Return(returnBlock); - } - } - - public struct PinResult + public struct IncomingBuffer { public ArraySegment Data; public IntPtr DataPtr; diff --git a/test/Microsoft.AspNet.Server.KestrelTests/MessageBodyExchangerTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/MessageBodyExchangerTests.cs deleted file mode 100644 index 9983e3a3c7..0000000000 --- a/test/Microsoft.AspNet.Server.KestrelTests/MessageBodyExchangerTests.cs +++ /dev/null @@ -1,192 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using Microsoft.AspNet.Server.Kestrel.Http; -using System; -using System.Threading.Tasks; -using Xunit; - -namespace Microsoft.AspNet.Server.KestrelTests -{ - /// - /// Summary description for MessageBodyExchangerTests - /// - public class MessageBodyExchangerTests - { - [Fact] - public async Task CallingReadAsyncBeforeTransfer() - { - var testInput = new TestInput(); - var context = new ConnectionContext(); - context.SocketInput = new SocketInput(new MemoryPool2()); - - var exchanger = new MessageBodyExchanger(testInput.FrameContext); - - var buffer1 = new byte[1024]; - var buffer2 = new byte[1024]; - var task1 = exchanger.ReadAsync(new ArraySegment(buffer1)); - var task2 = exchanger.ReadAsync(new ArraySegment(buffer2)); - - Assert.False(task1.IsCompleted); - Assert.False(task2.IsCompleted); - - testInput.Add("Hello"); - - exchanger.Transfer(3, false); - - var count1 = await task1; - - Assert.True(task1.IsCompleted); - Assert.False(task2.IsCompleted); - AssertASCII("Hel", new ArraySegment(buffer1, 0, count1)); - - exchanger.Transfer(2, false); - - var count2 = await task2; - - Assert.True(task1.IsCompleted); - Assert.True(task2.IsCompleted); - AssertASCII("lo", new ArraySegment(buffer2, 0, count2)); - } - - [Fact] - public async Task CallingTransferBeforeReadAsync() - { - var testInput = new TestInput(); - var context = new ConnectionContext(); - context.SocketInput = new SocketInput(new MemoryPool2()); - - var exchanger = new MessageBodyExchanger(testInput.FrameContext); - - testInput.Add("Hello"); - - exchanger.Transfer(5, false); - - var buffer1 = new byte[1024]; - var buffer2 = new byte[1024]; - var task1 = exchanger.ReadAsync(new ArraySegment(buffer1)); - var task2 = exchanger.ReadAsync(new ArraySegment(buffer2)); - - Assert.True(task1.IsCompleted); - Assert.False(task2.IsCompleted); - - await task1; - - var count1 = await task1; - - Assert.True(task1.IsCompleted); - Assert.False(task2.IsCompleted); - AssertASCII("Hello", new ArraySegment(buffer1, 0, count1)); - } - - [Fact] - public async Task TransferZeroBytesDoesNotReleaseReadAsync() - { - var testInput = new TestInput(); - var context = new ConnectionContext(); - context.SocketInput = new SocketInput(new MemoryPool2()); - - var exchanger = new MessageBodyExchanger(testInput.FrameContext); - - var buffer1 = new byte[1024]; - var buffer2 = new byte[1024]; - var task1 = exchanger.ReadAsync(new ArraySegment(buffer1)); - var task2 = exchanger.ReadAsync(new ArraySegment(buffer2)); - - Assert.False(task1.IsCompleted); - Assert.False(task2.IsCompleted); - - testInput.Add("Hello"); - - exchanger.Transfer(3, false); - - var count1 = await task1; - - Assert.True(task1.IsCompleted); - Assert.False(task2.IsCompleted); - AssertASCII("Hel", new ArraySegment(buffer1, 0, count1)); - - exchanger.Transfer(0, false); - - Assert.True(task1.IsCompleted); - Assert.False(task2.IsCompleted); - } - - [Fact] - public async Task TransferFinDoesReleaseReadAsync() - { - var testInput = new TestInput(); - var context = new ConnectionContext(); - context.SocketInput = new SocketInput(new MemoryPool2()); - - var exchanger = new MessageBodyExchanger(testInput.FrameContext); - - var buffer1 = new byte[1024]; - var buffer2 = new byte[1024]; - var task1 = exchanger.ReadAsync(new ArraySegment(buffer1)); - var task2 = exchanger.ReadAsync(new ArraySegment(buffer2)); - - Assert.False(task1.IsCompleted); - Assert.False(task2.IsCompleted); - - testInput.Add("Hello"); - - exchanger.Transfer(3, false); - - var count1 = await task1; - - Assert.True(task1.IsCompleted); - Assert.False(task2.IsCompleted); - AssertASCII("Hel", new ArraySegment(buffer1, 0, count1)); - - exchanger.Transfer(0, true); - - var count2 = await task2; - - Assert.True(task1.IsCompleted); - Assert.True(task2.IsCompleted); - Assert.Equal(0, count2); - } - - - [Fact] - public async Task TransferFinFirstDoesReturnsCompletedReadAsyncs() - { - - var testInput = new TestInput(); - var context = new ConnectionContext(); - context.SocketInput = new SocketInput(new MemoryPool2()); - - var exchanger = new MessageBodyExchanger(testInput.FrameContext); - - testInput.Add("Hello"); - - exchanger.Transfer(5, true); - - var buffer1 = new byte[1024]; - var buffer2 = new byte[1024]; - var task1 = exchanger.ReadAsync(new ArraySegment(buffer1)); - var task2 = exchanger.ReadAsync(new ArraySegment(buffer2)); - - Assert.True(task1.IsCompleted); - Assert.True(task2.IsCompleted); - - var count1 = await task1; - var count2 = await task2; - - AssertASCII("Hello", new ArraySegment(buffer1, 0, count1)); - Assert.Equal(0, count2); - } - - private void AssertASCII(string expected, ArraySegment actual) - { - var encoding = System.Text.Encoding.ASCII; - var bytes = encoding.GetBytes(expected); - Assert.Equal(bytes.Length, actual.Count); - for (var index = 0; index != bytes.Length; ++index) - { - Assert.Equal(bytes[index], actual.Array[actual.Offset + index]); - } - } - } -} \ No newline at end of file diff --git a/test/Microsoft.AspNet.Server.KestrelTests/TestConnection.cs b/test/Microsoft.AspNet.Server.KestrelTests/TestConnection.cs index 773bddf70d..c881979f52 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/TestConnection.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/TestConnection.cs @@ -71,7 +71,7 @@ namespace Microsoft.AspNet.Server.KestrelTests var task = _reader.ReadAsync(actual, offset, actual.Length - offset); if (!Debugger.IsAttached) { - Assert.True(task.Wait(1000), "timeout"); + Assert.True(task.Wait(4000), "timeout"); } var count = await task; if (count == 0) @@ -95,7 +95,7 @@ namespace Microsoft.AspNet.Server.KestrelTests var task = _reader.ReadAsync(actual, offset, 1); if (!Debugger.IsAttached) { - Assert.True(task.Wait(1000), "timeout"); + Assert.True(task.Wait(4000), "timeout"); } var count = await task; if (count == 0) diff --git a/test/Microsoft.AspNet.Server.KestrelTests/TestInput.cs b/test/Microsoft.AspNet.Server.KestrelTests/TestInput.cs index 506e1907ac..63f55cab03 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/TestInput.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/TestInput.cs @@ -29,10 +29,9 @@ namespace Microsoft.AspNet.Server.KestrelTests { var encoding = System.Text.Encoding.ASCII; var count = encoding.GetByteCount(text); - var buffer = FrameContext.SocketInput.Pin(text.Length); + var buffer = FrameContext.SocketInput.IncomingStart(text.Length); count = encoding.GetBytes(text, 0, text.Length, buffer.Data.Array, buffer.Data.Offset); - FrameContext.SocketInput.Unpin(count); - FrameContext.SocketInput.SetCompleted(null); + FrameContext.SocketInput.IncomingComplete(count, null); if (fin) { FrameContext.SocketInput.RemoteIntakeFin = true; diff --git a/test/Microsoft.AspNet.Server.KestrelTests/TestLogger.cs b/test/Microsoft.AspNet.Server.KestrelTests/TestLogger.cs index e643c1d0f9..e8658f7615 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/TestLogger.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/TestLogger.cs @@ -13,17 +13,17 @@ namespace Microsoft.AspNet.Server.KestrelTests public override void ConnectionRead(long connectionId, int count) { - _logger.LogDebug(1, @"Connection id ""{ConnectionId}"" recv {count} bytes.", connectionId, count); + //_logger.LogDebug(1, @"Connection id ""{ConnectionId}"" recv {count} bytes.", connectionId, count); } public override void ConnectionWrite(long connectionId, int count) { - _logger.LogDebug(1, @"Connection id ""{ConnectionId}"" send {count} bytes.", connectionId, count); + //_logger.LogDebug(1, @"Connection id ""{ConnectionId}"" send {count} bytes.", connectionId, count); } public override void ConnectionWriteCallback(long connectionId, int status) { - _logger.LogDebug(1, @"Connection id ""{ConnectionId}"" send finished with status {status}.", connectionId, status); + //_logger.LogDebug(1, @"Connection id ""{ConnectionId}"" send finished with status {status}.", connectionId, status); } public class TestLogger : ILogger From 04f6446a50419e025df909033a85e5c36123a2bf Mon Sep 17 00:00:00 2001 From: Louis DeJardin Date: Thu, 17 Sep 2015 18:22:09 -0700 Subject: [PATCH 0271/1662] Updates for PR feedback --- samples/SampleApp/Startup.cs | 2 -- samples/SampleApp/project.json | 1 + src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs | 3 --- src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs | 3 --- src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs | 2 +- 5 files changed, 2 insertions(+), 9 deletions(-) diff --git a/samples/SampleApp/Startup.cs b/samples/SampleApp/Startup.cs index 4e1d25519f..f74fffe57e 100644 --- a/samples/SampleApp/Startup.cs +++ b/samples/SampleApp/Startup.cs @@ -24,8 +24,6 @@ namespace SampleApp context.Request.Path, context.Request.QueryString); - await context.Request.Body.CopyToAsync(Console.OpenStandardOutput()); - context.Response.ContentLength = 11; context.Response.ContentType = "text/plain"; await context.Response.WriteAsync("Hello world"); diff --git a/samples/SampleApp/project.json b/samples/SampleApp/project.json index b77f0a7dd2..35885e8e3f 100644 --- a/samples/SampleApp/project.json +++ b/samples/SampleApp/project.json @@ -13,6 +13,7 @@ } }, "commands": { + "web": "Microsoft.AspNet.Hosting --server Microsoft.AspNet.Server.Kestrel", "run": "Microsoft.AspNet.Server.Kestrel", "run-socket": "Microsoft.AspNet.Server.Kestrel --server.urls http://unix:/tmp/kestrel-test.sock", "kestrel": "Microsoft.AspNet.Server.Kestrel" diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs index 72a753a6f9..c9d5ce2d24 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs @@ -12,9 +12,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { public class Connection : ConnectionContext, IConnectionControl { - private const int EOF = -4095; - private const int ECONNRESET = -4077; - private static readonly Action _readCallback = ReadCallback; private static readonly Func _allocCallback = AllocCallback; diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs index 944d9807ec..465e2b25f3 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs @@ -9,10 +9,7 @@ using System.Text; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNet.Server.Kestrel.Infrastructure; -using Microsoft.Framework.Logging; using Microsoft.Framework.Primitives; -using System.Numerics; -using Microsoft.AspNet.Hosting.Builder; // ReSharper disable AccessToModifiedClosure diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs index 7e35251e38..ecf62582e5 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs @@ -211,7 +211,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http void ISocketOutput.Write(ArraySegment buffer, bool immediate) { - ((ISocketOutput)this).WriteAsync(buffer, immediate).Wait(); + ((ISocketOutput)this).WriteAsync(buffer, immediate).GetAwaiter().GetResult(); } Task ISocketOutput.WriteAsync(ArraySegment buffer, bool immediate, CancellationToken cancellationToken) From 28250d99814ac0415cb5c2a52f7f01dbbe438943 Mon Sep 17 00:00:00 2001 From: Louis DeJardin Date: Thu, 17 Sep 2015 18:28:58 -0700 Subject: [PATCH 0272/1662] Providing Path to application --- src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs index 465e2b25f3..45e1807778 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs @@ -552,6 +552,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http RequestUri = requestUri; QueryString = queryString; HttpVersion = httpVersion; + Path = RequestUri; return true; } finally From 30ec2cb0b1f9f5ebf570031df0da080a936ea73d Mon Sep 17 00:00:00 2001 From: Louis DeJardin Date: Thu, 17 Sep 2015 18:53:35 -0700 Subject: [PATCH 0273/1662] Harden framing epilog * Connection no longer needes Frame's processing Task * Any exceptions from unusual processing is logged --- .../Http/Connection.cs | 2 +- .../Http/Frame.cs | 124 ++++++++++-------- 2 files changed, 72 insertions(+), 54 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs index c9d5ce2d24..ce231cafbf 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs @@ -40,7 +40,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http SocketInput = new SocketInput(Memory2); SocketOutput = new SocketOutput(Thread, _socket, _connectionId, Log); _frame = new Frame(this); - _frameTask = Task.Run(_frame.ProcessFraming); + Task.Run(_frame.ProcessFraming); _socket.ReadStart(_allocCallback, _readCallback, this); } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs index 45e1807778..c3eb8d53d8 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs @@ -9,6 +9,7 @@ using System.Text; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNet.Server.Kestrel.Infrastructure; +using Microsoft.Framework.Logging; using Microsoft.Framework.Primitives; // ReSharper disable AccessToModifiedClosure @@ -98,73 +99,90 @@ namespace Microsoft.AspNet.Server.Kestrel.Http _responseHeaders.HeaderDate = DateTime.UtcNow.ToString("r"); } - public async Task ProcessFraming() + public async void ProcessFraming() { - var terminated = false; - while (!terminated) + try { - while (!terminated && !TakeStartLine(SocketInput)) + var terminated = false; + while (!terminated) { - terminated = SocketInput.RemoteIntakeFin; - if (!terminated) + while (!terminated && !TakeStartLine(SocketInput)) { - await SocketInput; - } - } - - while (!terminated && !TakeMessageHeaders(SocketInput)) - { - terminated = SocketInput.RemoteIntakeFin; - if (!terminated) - { - await SocketInput; - } - } - - if (!terminated) - { - MessageBody = MessageBody.For(HttpVersion, _requestHeaders, this); - _keepAlive = MessageBody.RequestKeepAlive; - RequestBody = new FrameRequestStream(MessageBody); - ResponseBody = new FrameResponseStream(this); - DuplexStream = new FrameDuplexStream(RequestBody, ResponseBody); - - Exception error = null; - try - { - await Application.Invoke(this).ConfigureAwait(false); - - // Trigger FireOnStarting if ProduceStart hasn't been called yet. - // We call it here, so it can go through our normal error handling - // and respond with a 500 if an OnStarting callback throws. - if (!_responseStarted) + terminated = SocketInput.RemoteIntakeFin; + if (!terminated) { - FireOnStarting(); + await SocketInput; } } - catch (Exception ex) + + while (!terminated && !TakeMessageHeaders(SocketInput)) { - error = ex; - } - finally - { - FireOnCompleted(); - ProduceEnd(error); + terminated = SocketInput.RemoteIntakeFin; + if (!terminated) + { + await SocketInput; + } } - terminated = !_keepAlive; + if (!terminated) + { + MessageBody = MessageBody.For(HttpVersion, _requestHeaders, this); + _keepAlive = MessageBody.RequestKeepAlive; + RequestBody = new FrameRequestStream(MessageBody); + ResponseBody = new FrameResponseStream(this); + DuplexStream = new FrameDuplexStream(RequestBody, ResponseBody); + + Exception error = null; + try + { + await Application.Invoke(this).ConfigureAwait(false); + + // Trigger FireOnStarting if ProduceStart hasn't been called yet. + // We call it here, so it can go through our normal error handling + // and respond with a 500 if an OnStarting callback throws. + if (!_responseStarted) + { + FireOnStarting(); + } + } + catch (Exception ex) + { + error = ex; + } + finally + { + FireOnCompleted(); + ProduceEnd(error); + } + + terminated = !_keepAlive; + } + + Reset(); } - - Reset(); } + catch (Exception ex) + { + Log.LogVerbose("Connection processing ended abnormally", ex); + } + finally + { + try + { + // Inform client no more data will ever arrive + ConnectionControl.End(ProduceEndType.SocketShutdownSend); - // Connection Terminated! - ConnectionControl.End(ProduceEndType.SocketShutdownSend); + // Wait for client to either disconnect or send unexpected data + await SocketInput; - // Wait for client to disconnect, or to receive unexpected data - await SocketInput; - - ConnectionControl.End(ProduceEndType.SocketDisconnect); + // Dispose socket + ConnectionControl.End(ProduceEndType.SocketDisconnect); + } + catch(Exception ex) + { + Log.LogVerbose("Connection shutdown abnormally", ex); + } + } } public void OnStarting(Func callback, object state) From ff0affe34d8abee0ce12076663982f3334a31771 Mon Sep 17 00:00:00 2001 From: Louis DeJardin Date: Fri, 18 Sep 2015 15:19:11 -0700 Subject: [PATCH 0274/1662] Removing _frameTask and fixing Task.Run argument --- .../Http/Connection.cs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs index ce231cafbf..8e733de108 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs @@ -18,9 +18,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http private static long _lastConnectionId; private readonly UvStreamHandle _socket; - private Frame _frame; - private Task _frameTask; - private long _connectionId = 0; + private readonly Frame _frame; + private readonly long _connectionId; private readonly object _stateLock = new object(); private ConnectionState _connectionState; @@ -31,16 +30,17 @@ namespace Microsoft.AspNet.Server.Kestrel.Http ConnectionControl = this; _connectionId = Interlocked.Increment(ref _lastConnectionId); + + SocketInput = new SocketInput(Memory2); + SocketOutput = new SocketOutput(Thread, _socket, _connectionId, Log); + _frame = new Frame(this); } public void Start() { Log.ConnectionStart(_connectionId); - SocketInput = new SocketInput(Memory2); - SocketOutput = new SocketOutput(Thread, _socket, _connectionId, Log); - _frame = new Frame(this); - Task.Run(_frame.ProcessFraming); + Task.Run((Action)_frame.ProcessFraming); _socket.ReadStart(_allocCallback, _readCallback, this); } From 76b528e1d26a8c8751147d7672e2c0733502ae0a Mon Sep 17 00:00:00 2001 From: Louis DeJardin Date: Fri, 18 Sep 2015 16:29:29 -0700 Subject: [PATCH 0275/1662] Adding comments to MemoryPool classes --- .../Http/MemoryPool2.cs | 66 ++++++++++++++- .../Http/MemoryPoolBlock2.cs | 81 ++++++++++++++++++- .../Http/MemoryPoolSlab2.cs | 33 ++++++++ 3 files changed, 177 insertions(+), 3 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/MemoryPool2.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/MemoryPool2.cs index 9256bdb314..941fb9b796 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/MemoryPool2.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/MemoryPool2.cs @@ -3,22 +3,70 @@ using System.Collections.Concurrent; namespace Microsoft.AspNet.Server.Kestrel.Http { + /// + /// Used to allocate and distribute re-usable blocks of memory. + /// public class MemoryPool2 : IDisposable { + /// + /// The gap between blocks' starting address. 4096 is chosen because most operating systems are 4k pages in size and alignment. + /// private const int blockStride = 4096; + + /// + /// The last 64 bytes of a block are unused to prevent CPU from pre-fetching the next 64 byte into it's memory cache. + /// See https://github.com/aspnet/KestrelHttpServer/issues/117 and https://www.youtube.com/watch?v=L7zSU9HI-6I + /// private const int blockUnused = 64; + + /// + /// Allocating 32 contiguous blocks per slab makes the slab size 128k. This is larger than the 85k size which will place the memory + /// in the large object heap. This means the GC will not try to relocate this array, so the fact it remains pinned does not negatively + /// affect memory management's compactification. + /// private const int blockCount = 32; + + /// + /// 4096 - 64 gives you a blockLength of 4032 usable bytes per block. + /// private const int blockLength = blockStride - blockUnused; + + /// + /// 4096 * 32 gives you a slabLength of 128k contiguous bytes allocated per slab + /// private const int slabLength = blockStride * blockCount; - private ConcurrentStack _blocks = new ConcurrentStack(); - private ConcurrentStack _slabs = new ConcurrentStack(); + /// + /// Thread-safe collection of blocks which are currently in the pool. A slab will pre-allocate all of the block tracking objects + /// and add them to this collection. When memory is requested it is taken from here first, and when it is returned it is re-added. + /// + private readonly ConcurrentStack _blocks = new ConcurrentStack(); + + /// + /// Thread-safe collection of slabs which have been allocated by this pool. As long as a slab is in this collection and slab.IsActive, + /// the blocks will be added to _blocks when returned. + /// + private readonly ConcurrentStack _slabs = new ConcurrentStack(); + + /// + /// This is part of implementing the IDisposable pattern. + /// private bool disposedValue = false; // To detect redundant calls + /// + /// Called to take a block from the pool. + /// + /// The block returned must be at least this size. It may be larger than this minimum size, and if so, + /// the caller may write to the block's entire size rather than being limited to the minumumSize requested. + /// The block that is reserved for the called. It must be passed to Return when it is no longer being used. public MemoryPoolBlock2 Lease(int minimumSize) { if (minimumSize > blockLength) { + // The requested minimumSize is actually larger then the usable memory of a single block. + // Because this is the degenerate case, a one-time-use byte[] array and tracking object are allocated. + // When this block tracking object is returned it is not added to the pool - instead it will be + // allowed to be garbace collected normally. return MemoryPoolBlock2.Create( new ArraySegment(new byte[minimumSize]), dataPtr: IntPtr.Zero, @@ -31,12 +79,18 @@ namespace Microsoft.AspNet.Server.Kestrel.Http MemoryPoolBlock2 block; if (_blocks.TryPop(out block)) { + // block successfully taken from the stack - return it return block; } + // no blocks available - grow the pool and try again AllocateSlab(); } } + /// + /// Internal method called when a block is requested and the pool is empty. It allocates one additional slab, creates all of the + /// block tracking objects, and adds them all to the pool. + /// private void AllocateSlab() { var slab = MemoryPoolSlab2.Create(slabLength); @@ -58,6 +112,14 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } + /// + /// Called to return a block to the pool. Once Return has been called the memory no longer belongs to the caller, and + /// Very Bad Things will happen if the memory is read of modified subsequently. If a caller fails to call Return and the + /// block tracking object is garbage collected, the block tracking object's finalizer will automatically re-create and return + /// a new tracking object into the pool. This will only happen if there is a bug in the server, however it is necessary to avoid + /// leaving "dead zones" in the slab due to lost block tracking objects. + /// + /// The block to return. It must have been acquired by calling Lease on the same memory pool instance. public void Return(MemoryPoolBlock2 block) { block.Reset(); diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/MemoryPoolBlock2.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/MemoryPoolBlock2.cs index 7d2f8d27d1..f2a47c35d9 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/MemoryPoolBlock2.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/MemoryPoolBlock2.cs @@ -8,33 +8,93 @@ using System.Text; namespace Microsoft.AspNet.Server.Kestrel.Http { + /// + /// Block tracking object used by the byte buffer memory pool. A slab is a large allocation which is divided into smaller blocks. The + /// individual blocks are then treated as independant array segments. + /// public class MemoryPoolBlock2 { - private static Vector _dotIndex = new Vector(Enumerable.Range(0, Vector.Count).Select(x => (byte)-x).ToArray()); + /// + /// Array of "minus one" bytes of the length of SIMD operations on the current hardware. Used as an argument in the + /// vector dot product that counts matching character occurence. + /// private static Vector _dotCount = new Vector(Byte.MaxValue); + /// + /// Array of negative numbers starting at 0 and continuing for the length of SIMD operations on the current hardware. + /// Used as an argument in the vector dot product that determines matching character index. + /// + private static Vector _dotIndex = new Vector(Enumerable.Range(0, Vector.Count).Select(x => (byte)-x).ToArray()); + + /// + /// If this block represents a one-time-use memory object, this GCHandle will hold that memory object at a fixed address + /// so it can be used in native operations. + /// private GCHandle _pinHandle; + + /// + /// Native address of the first byte of this block's Data memory. It is null for one-time-use memory, or copied from + /// the Slab's ArrayPtr for a slab-block segment. The byte it points to corresponds to Data.Array[0], and in practice you will always + /// use the _dataArrayPtr + Start or _dataArrayPtr + End, which point to the start of "active" bytes, or point to just after the "active" bytes. + /// private IntPtr _dataArrayPtr; + /// + /// The array segment describing the range of memory this block is tracking. The caller which has leased this block may only read and + /// modify the memory in this range. + /// public ArraySegment Data; + /// + /// This object cannot be instantiated outside of the static Create method + /// protected MemoryPoolBlock2() { } + /// + /// Back-reference to the memory pool which this block was allocated from. It may only be returned to this pool. + /// public MemoryPool2 Pool { get; private set; } + /// + /// Back-reference to the slab from which this block was taken, or null if it is one-time-use memory. + /// public MemoryPoolSlab2 Slab { get; private set; } + /// + /// Convenience accessor + /// public byte[] Array => Data.Array; + + /// + /// The Start represents the offset into Array where the range of "active" bytes begins. At the point when the block is leased + /// the Start is guaranteed to be equal to Array.Offset. The value of Start may be assigned anywhere between Data.Offset and + /// Data.Offset + Data.Count, and must be equal to or less than End. + /// public int Start { get; set; } + + /// + /// The End represents the offset into Array where the range of "active" bytes ends. At the point when the block is leased + /// the End is guaranteed to be equal to Array.Offset. The value of Start may be assigned anywhere between Data.Offset and + /// Data.Offset + Data.Count, and must be equal to or less than End. + /// public int End { get; set; } + + + /// + /// Reference to the next block of data when the overall "active" bytes spans multiple blocks. At the point when the block is + /// leased Next is guaranteed to be null. Start, End, and Next are used together in order to create a linked-list of discontiguous + /// working memory. The "active" memory is grown when bytes are copied in, End is increased, and Next is assigned. The "active" + /// memory is shrunk when bytes are consumed, Start is increased, and blocks are returned to the pool. + /// public MemoryPoolBlock2 Next { get; set; } ~MemoryPoolBlock2() { if (_pinHandle.IsAllocated) { + // if this is a one-time-use block, ensure that the GCHandle does not leak _pinHandle.Free(); } @@ -50,16 +110,23 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } + /// + /// Called to ensure that a block is pinned, and return the pointer to native memory just after + /// the range of "active" bytes. This is where arriving data is read into. + /// + /// public IntPtr Pin() { Debug.Assert(!_pinHandle.IsAllocated); if (_dataArrayPtr != IntPtr.Zero) { + // this is a slab managed block - use the native address of the slab which is always locked return _dataArrayPtr + End; } else { + // this is one-time-use memory - lock the managed memory until Unpin is called _pinHandle = GCHandle.Alloc(Data.Array, GCHandleType.Pinned); return _pinHandle.AddrOfPinnedObject() + End; } @@ -69,6 +136,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { if (_dataArrayPtr == IntPtr.Zero) { + // this is one-time-use memory - unlock the managed memory Debug.Assert(_pinHandle.IsAllocated); _pinHandle.Free(); } @@ -100,6 +168,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Http }; } + /// + /// called when the block is returned to the pool. mutable values are re-assigned to their guaranteed initialized state. + /// public void Reset() { Next = null; @@ -107,11 +178,19 @@ namespace Microsoft.AspNet.Server.Kestrel.Http End = Data.Offset; } + /// + /// ToString overridden for debugger convenience. This displays the "active" byte information in this block as ASCII characters. + /// + /// public override string ToString() { return Encoding.ASCII.GetString(Array, Start, End - Start); } + /// + /// acquires a cursor pointing into this block at the Start of "active" byte information + /// + /// public Iterator GetIterator() { return new Iterator(this); diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/MemoryPoolSlab2.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/MemoryPoolSlab2.cs index 88b20c78b4..bf0221dda7 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/MemoryPoolSlab2.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/MemoryPoolSlab2.cs @@ -5,18 +5,51 @@ using System.Runtime.InteropServices; namespace Microsoft.AspNet.Server.Kestrel.Http { + /// + /// Slab tracking object used by the byte buffer memory pool. A slab is a large allocation which is divided into smaller blocks. The + /// individual blocks are then treated as independant array segments. + /// public class MemoryPoolSlab2 : IDisposable { + /// + /// This handle pins the managed array in memory until the slab is disposed. This prevents it from being + /// relocated and enables any subsections of the array to be used as native memory pointers to P/Invoked API calls. + /// private GCHandle _gcHandle; + + /// + /// The managed memory allocated in the large object heap. + /// public byte[] Array; + + /// + /// The native memory pointer of the pinned Array. All block native addresses are pointers into the memory + /// ranging from ArrayPtr to ArrayPtr + Array.Length + /// public IntPtr ArrayPtr; + + /// + /// True as long as the blocks from this slab are to be considered returnable to the pool. In order to shrink the + /// memory pool size an entire slab must be removed. That is done by (1) setting IsActive to false and removing the + /// slab from the pool's _slabs collection, (2) as each block currently in use is Return()ed to the pool it will + /// be allowed to be garbage collected rather than re-pooled, and (3) when all block tracking objects are garbage + /// collected and the slab is no longer references the slab will be garbage collected and the memory unpinned will + /// be unpinned by the slab's Dispose. + /// public bool IsActive; + + /// + /// Part of the IDisposable implementation + /// private bool disposedValue = false; // To detect redundant calls public static MemoryPoolSlab2 Create(int length) { + // allocate and pin requested memory length var array = new byte[length]; var gcHandle = GCHandle.Alloc(array, GCHandleType.Pinned); + + // allocate and return slab tracking object return new MemoryPoolSlab2 { Array = array, From 6db3d9e645580726f26d3c2ba812ef6236ea03b2 Mon Sep 17 00:00:00 2001 From: Louis DeJardin Date: Fri, 18 Sep 2015 16:41:43 -0700 Subject: [PATCH 0276/1662] Using specific exception types --- src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs | 2 +- src/Microsoft.AspNet.Server.Kestrel/Http/MemoryPoolBlock2.cs | 2 +- src/Microsoft.AspNet.Server.Kestrel/Http/MessageBody.cs | 3 ++- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs index c3eb8d53d8..5820f1f3b8 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs @@ -613,7 +613,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http consumed = scan; return true; } - throw new Exception("Malformed request"); + throw new InvalidDataException("Malformed request"); } while ( diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/MemoryPoolBlock2.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/MemoryPoolBlock2.cs index f2a47c35d9..681b476758 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/MemoryPoolBlock2.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/MemoryPoolBlock2.cs @@ -484,7 +484,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } else if (block.Next == null) { - throw new Exception("end did not follow iterator"); + throw new InvalidOperationException("end did not follow iterator"); } else { diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/MessageBody.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/MessageBody.cs index caf528fb5e..13f7110168 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/MessageBody.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/MessageBody.cs @@ -6,6 +6,7 @@ using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; using Microsoft.Framework.Primitives; +using System.IO; namespace Microsoft.AspNet.Server.Kestrel.Http { @@ -167,7 +168,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } if (input.RemoteIntakeFin) { - throw new Exception("Unexpected end of request content"); + throw new InvalidDataException("Unexpected end of request content"); } } } From 5ba1b9fb3c62c736f0733823082c247b1ed48cc8 Mon Sep 17 00:00:00 2001 From: Louis DeJardin Date: Fri, 18 Sep 2015 17:17:28 -0700 Subject: [PATCH 0277/1662] Secondary listeners need to allocate their own memory pool --- src/Microsoft.AspNet.Server.Kestrel/Http/ListenerSecondary.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerSecondary.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerSecondary.cs index e50a69071c..2d4df89d52 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerSecondary.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerSecondary.cs @@ -18,6 +18,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { protected ListenerSecondary(ServiceContext serviceContext) : base(serviceContext) { + Memory2 = new MemoryPool2(); } UvPipeHandle DispatchPipe { get; set; } From 13f46bb66b7586b8a6451d734866f6d7843aaeae Mon Sep 17 00:00:00 2001 From: Louis DeJardin Date: Fri, 18 Sep 2015 17:22:10 -0700 Subject: [PATCH 0278/1662] Using multiple threads in SampleApp --- samples/SampleApp/Startup.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/samples/SampleApp/Startup.cs b/samples/SampleApp/Startup.cs index f74fffe57e..f41201db16 100644 --- a/samples/SampleApp/Startup.cs +++ b/samples/SampleApp/Startup.cs @@ -5,6 +5,7 @@ using System; using Microsoft.AspNet.Builder; using Microsoft.AspNet.Http; using Microsoft.Framework.Logging; +using Microsoft.AspNet.Server.Kestrel; namespace SampleApp { @@ -12,6 +13,9 @@ namespace SampleApp { public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory) { + var ksi = app.ServerFeatures[typeof(IKestrelServerInformation)] as IKestrelServerInformation; + ksi.ThreadCount = 4; + loggerFactory.MinimumLevel = LogLevel.Debug; loggerFactory.AddConsole(LogLevel.Debug); From 13defc5a32a4062d54f2a47afb723b3ae1c06811 Mon Sep 17 00:00:00 2001 From: Louis DeJardin Date: Fri, 18 Sep 2015 22:31:05 -0700 Subject: [PATCH 0279/1662] Initialize Memory2 in ListenerContext Better than initializing from multiple other classes --- src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs | 1 - src/Microsoft.AspNet.Server.Kestrel/Http/ListenerContext.cs | 2 ++ src/Microsoft.AspNet.Server.Kestrel/Http/ListenerSecondary.cs | 1 - 3 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs index a828d4d17a..741180aee3 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs @@ -16,7 +16,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Http protected Listener(ServiceContext serviceContext) : base(serviceContext) { - Memory2 = new MemoryPool2(); } protected UvStreamHandle ListenSocket { get; private set; } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerContext.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerContext.cs index 03d27501d6..2f6201016b 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerContext.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerContext.cs @@ -11,11 +11,13 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { public ListenerContext() { + Memory2 = new MemoryPool2(); } public ListenerContext(ServiceContext serviceContext) : base(serviceContext) { + Memory2 = new MemoryPool2(); } public ListenerContext(ListenerContext listenerContext) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerSecondary.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerSecondary.cs index 2d4df89d52..e50a69071c 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerSecondary.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerSecondary.cs @@ -18,7 +18,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { protected ListenerSecondary(ServiceContext serviceContext) : base(serviceContext) { - Memory2 = new MemoryPool2(); } UvPipeHandle DispatchPipe { get; set; } From 091084cfe241d4b17372486624716e036f471f54 Mon Sep 17 00:00:00 2001 From: Louis DeJardin Date: Fri, 18 Sep 2015 22:59:19 -0700 Subject: [PATCH 0280/1662] Refactoring MemoryPool class locations Moving Iterator out into its own file rather than being a nested class Moving pool classes into Infrastructure namespace instead of Http --- .../Http/MemoryPoolBlock2.cs | 630 ------------------ .../Http/SocketInput.cs | 11 +- .../{Http => Infrastructure}/MemoryPool2.cs | 2 +- .../Infrastructure/MemoryPoolBlock2.cs | 184 +++++ .../Infrastructure/MemoryPoolIterator2.cs | 452 +++++++++++++ .../MemoryPoolSlab2.cs | 4 +- .../MemoryPoolBlock2Tests.cs | 9 +- .../MemoryPoolExtensions.cs | 4 +- .../TestInput.cs | 1 + 9 files changed, 649 insertions(+), 648 deletions(-) delete mode 100644 src/Microsoft.AspNet.Server.Kestrel/Http/MemoryPoolBlock2.cs rename src/Microsoft.AspNet.Server.Kestrel/{Http => Infrastructure}/MemoryPool2.cs (99%) create mode 100644 src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolBlock2.cs create mode 100644 src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolIterator2.cs rename src/Microsoft.AspNet.Server.Kestrel/{Http => Infrastructure}/MemoryPoolSlab2.cs (97%) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/MemoryPoolBlock2.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/MemoryPoolBlock2.cs deleted file mode 100644 index 681b476758..0000000000 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/MemoryPoolBlock2.cs +++ /dev/null @@ -1,630 +0,0 @@ -using System; -using System.Collections.Concurrent; -using System.Diagnostics; -using System.Linq; -using System.Numerics; -using System.Runtime.InteropServices; -using System.Text; - -namespace Microsoft.AspNet.Server.Kestrel.Http -{ - /// - /// Block tracking object used by the byte buffer memory pool. A slab is a large allocation which is divided into smaller blocks. The - /// individual blocks are then treated as independant array segments. - /// - public class MemoryPoolBlock2 - { - /// - /// Array of "minus one" bytes of the length of SIMD operations on the current hardware. Used as an argument in the - /// vector dot product that counts matching character occurence. - /// - private static Vector _dotCount = new Vector(Byte.MaxValue); - - /// - /// Array of negative numbers starting at 0 and continuing for the length of SIMD operations on the current hardware. - /// Used as an argument in the vector dot product that determines matching character index. - /// - private static Vector _dotIndex = new Vector(Enumerable.Range(0, Vector.Count).Select(x => (byte)-x).ToArray()); - - /// - /// If this block represents a one-time-use memory object, this GCHandle will hold that memory object at a fixed address - /// so it can be used in native operations. - /// - private GCHandle _pinHandle; - - /// - /// Native address of the first byte of this block's Data memory. It is null for one-time-use memory, or copied from - /// the Slab's ArrayPtr for a slab-block segment. The byte it points to corresponds to Data.Array[0], and in practice you will always - /// use the _dataArrayPtr + Start or _dataArrayPtr + End, which point to the start of "active" bytes, or point to just after the "active" bytes. - /// - private IntPtr _dataArrayPtr; - - /// - /// The array segment describing the range of memory this block is tracking. The caller which has leased this block may only read and - /// modify the memory in this range. - /// - public ArraySegment Data; - - /// - /// This object cannot be instantiated outside of the static Create method - /// - protected MemoryPoolBlock2() - { - } - - /// - /// Back-reference to the memory pool which this block was allocated from. It may only be returned to this pool. - /// - public MemoryPool2 Pool { get; private set; } - - /// - /// Back-reference to the slab from which this block was taken, or null if it is one-time-use memory. - /// - public MemoryPoolSlab2 Slab { get; private set; } - - /// - /// Convenience accessor - /// - public byte[] Array => Data.Array; - - /// - /// The Start represents the offset into Array where the range of "active" bytes begins. At the point when the block is leased - /// the Start is guaranteed to be equal to Array.Offset. The value of Start may be assigned anywhere between Data.Offset and - /// Data.Offset + Data.Count, and must be equal to or less than End. - /// - public int Start { get; set; } - - /// - /// The End represents the offset into Array where the range of "active" bytes ends. At the point when the block is leased - /// the End is guaranteed to be equal to Array.Offset. The value of Start may be assigned anywhere between Data.Offset and - /// Data.Offset + Data.Count, and must be equal to or less than End. - /// - public int End { get; set; } - - - /// - /// Reference to the next block of data when the overall "active" bytes spans multiple blocks. At the point when the block is - /// leased Next is guaranteed to be null. Start, End, and Next are used together in order to create a linked-list of discontiguous - /// working memory. The "active" memory is grown when bytes are copied in, End is increased, and Next is assigned. The "active" - /// memory is shrunk when bytes are consumed, Start is increased, and blocks are returned to the pool. - /// - public MemoryPoolBlock2 Next { get; set; } - - ~MemoryPoolBlock2() - { - if (_pinHandle.IsAllocated) - { - // if this is a one-time-use block, ensure that the GCHandle does not leak - _pinHandle.Free(); - } - - if (Slab != null && Slab.IsActive) - { - Pool.Return(new MemoryPoolBlock2 - { - _dataArrayPtr = _dataArrayPtr, - Data = Data, - Pool = Pool, - Slab = Slab, - }); - } - } - - /// - /// Called to ensure that a block is pinned, and return the pointer to native memory just after - /// the range of "active" bytes. This is where arriving data is read into. - /// - /// - public IntPtr Pin() - { - Debug.Assert(!_pinHandle.IsAllocated); - - if (_dataArrayPtr != IntPtr.Zero) - { - // this is a slab managed block - use the native address of the slab which is always locked - return _dataArrayPtr + End; - } - else - { - // this is one-time-use memory - lock the managed memory until Unpin is called - _pinHandle = GCHandle.Alloc(Data.Array, GCHandleType.Pinned); - return _pinHandle.AddrOfPinnedObject() + End; - } - } - - public void Unpin() - { - if (_dataArrayPtr == IntPtr.Zero) - { - // this is one-time-use memory - unlock the managed memory - Debug.Assert(_pinHandle.IsAllocated); - _pinHandle.Free(); - } - } - - public static MemoryPoolBlock2 Create(int size, MemoryPool2 pool) - { - return new MemoryPoolBlock2 - { - Data = new ArraySegment(new byte[size]), - Pool = pool - }; - } - - public static MemoryPoolBlock2 Create( - ArraySegment data, - IntPtr dataPtr, - MemoryPool2 pool, - MemoryPoolSlab2 slab) - { - return new MemoryPoolBlock2 - { - Data = data, - _dataArrayPtr = dataPtr, - Pool = pool, - Slab = slab, - Start = data.Offset, - End = data.Offset, - }; - } - - /// - /// called when the block is returned to the pool. mutable values are re-assigned to their guaranteed initialized state. - /// - public void Reset() - { - Next = null; - Start = Data.Offset; - End = Data.Offset; - } - - /// - /// ToString overridden for debugger convenience. This displays the "active" byte information in this block as ASCII characters. - /// - /// - public override string ToString() - { - return Encoding.ASCII.GetString(Array, Start, End - Start); - } - - /// - /// acquires a cursor pointing into this block at the Start of "active" byte information - /// - /// - public Iterator GetIterator() - { - return new Iterator(this); - } - - public struct Iterator - { - private MemoryPoolBlock2 _block; - private int _index; - - public Iterator(MemoryPoolBlock2 block) - { - _block = block; - _index = _block?.Start ?? 0; - } - public Iterator(MemoryPoolBlock2 block, int index) - { - _block = block; - _index = index; - } - - public bool IsDefault => _block == null; - - public bool IsEnd - { - get - { - if (_block == null) - { - return true; - } - else if (_index < _block.End) - { - return false; - } - else - { - for (var block = _block.Next; block != null; block = block.Next) - { - if (block.Start < block.End) - { - return true; - } - } - return true; - } - } - } - - public MemoryPoolBlock2 Block => _block; - - public int Index => _index; - - public int Take() - { - if (_block == null) - { - return -1; - } - else if (_index < _block.End) - { - return _block.Array[_index++]; - } - - var block = _block; - var index = _index; - while (true) - { - if (index < block.End) - { - _block = block; - _index = index + 1; - return block.Array[index]; - } - else if (block.Next == null) - { - return -1; - } - else - { - block = block.Next; - index = block.Start; - } - } - } - - public int Peek() - { - if (_block == null) - { - return -1; - } - else if (_index < _block.End) - { - return _block.Array[_index]; - } - else if (_block.Next == null) - { - return -1; - } - - var block = _block.Next; - var index = block.Start; - while (true) - { - if (index < block.End) - { - return block.Array[index]; - } - else if (block.Next == null) - { - return -1; - } - else - { - block = block.Next; - index = block.Start; - } - } - } - - public int Seek(int char0) - { - if (IsDefault) - { - return -1; - } - - var byte0 = (byte)char0; - var vectorStride = Vector.Count; - var ch0Vector = new Vector(byte0); - - var block = _block; - var index = _index; - var array = block.Array; - while (true) - { - while (block.End == index) - { - if (block.Next == null) - { - _block = block; - _index = index; - return -1; - } - block = block.Next; - index = block.Start; - array = block.Array; - } - while (block.End != index) - { - var following = block.End - index; - if (following >= vectorStride) - { - var data = new Vector(array, index); - var ch0Equals = Vector.Equals(data, ch0Vector); - var ch0Count = Vector.Dot(ch0Equals, _dotCount); - - if (ch0Count == 0) - { - index += vectorStride; - continue; - } - else if (ch0Count == 1) - { - _block = block; - _index = index + Vector.Dot(ch0Equals, _dotIndex); - return char0; - } - else - { - following = vectorStride; - } - } - for (; following != 0; following--, index++) - { - if (block.Array[index] == byte0) - { - _block = block; - _index = index; - return char0; - } - } - } - } - } - - public int Seek(int char0, int char1) - { - if (IsDefault) - { - return -1; - } - - var byte0 = (byte)char0; - var byte1 = (byte)char1; - var vectorStride = Vector.Count; - var ch0Vector = new Vector(byte0); - var ch1Vector = new Vector(byte1); - - var block = _block; - var index = _index; - var array = block.Array; - while (true) - { - while (block.End == index) - { - if (block.Next == null) - { - _block = block; - _index = index; - return -1; - } - block = block.Next; - index = block.Start; - array = block.Array; - } - while (block.End != index) - { - var following = block.End - index; - if (following >= vectorStride) - { - var data = new Vector(array, index); - var ch0Equals = Vector.Equals(data, ch0Vector); - var ch0Count = Vector.Dot(ch0Equals, _dotCount); - var ch1Equals = Vector.Equals(data, ch1Vector); - var ch1Count = Vector.Dot(ch1Equals, _dotCount); - - if (ch0Count == 0 && ch1Count == 0) - { - index += vectorStride; - continue; - } - else if (ch0Count < 2 && ch1Count < 2) - { - var ch0Index = ch0Count == 1 ? Vector.Dot(ch0Equals, _dotIndex) : byte.MaxValue; - var ch1Index = ch1Count == 1 ? Vector.Dot(ch1Equals, _dotIndex) : byte.MaxValue; - if (ch0Index < ch1Index) - { - _block = block; - _index = index + ch0Index; - return char0; - } - else - { - _block = block; - _index = index + ch1Index; - return char1; - } - } - else - { - following = vectorStride; - } - } - for (; following != 0; following--, index++) - { - var byteIndex = block.Array[index]; - if (byteIndex == byte0) - { - _block = block; - _index = index; - return char0; - } - else if (byteIndex == byte1) - { - _block = block; - _index = index; - return char1; - } - } - } - } - } - - public int GetLength(Iterator end) - { - if (IsDefault || end.IsDefault) - { - return -1; - } - - var block = _block; - var index = _index; - var length = 0; - while (true) - { - if (block == end._block) - { - return length + end._index - index; - } - else if (block.Next == null) - { - throw new InvalidOperationException("end did not follow iterator"); - } - else - { - length += block.End - index; - block = block.Next; - index = block.Start; - } - } - } - - public string GetString(Iterator end) - { - if (IsDefault || end.IsDefault) - { - return default(string); - } - if (end._block == _block) - { - return Encoding.UTF8.GetString(_block.Array, _index, end._index - _index); - } - - var decoder = Encoding.ASCII.GetDecoder(); - - var length = GetLength(end); - var charLength = length * 2; - var chars = new char[charLength]; - var charIndex = 0; - - var block = _block; - var index = _index; - var remaining = length; - while (true) - { - int bytesUsed; - int charsUsed; - bool completed; - var following = block.End - index; - if (remaining <= following) - { - decoder.Convert( - block.Array, - index, - remaining, - chars, - charIndex, - charLength - charIndex, - true, - out bytesUsed, - out charsUsed, - out completed); - return new string(chars, 0, charIndex + charsUsed); - } - else if (block.Next == null) - { - decoder.Convert( - block.Array, - index, - following, - chars, - charIndex, - charLength - charIndex, - true, - out bytesUsed, - out charsUsed, - out completed); - return new string(chars, 0, charIndex + charsUsed); - } - else - { - decoder.Convert( - block.Array, - index, - following, - chars, - charIndex, - charLength - charIndex, - false, - out bytesUsed, - out charsUsed, - out completed); - charIndex += charsUsed; - remaining -= following; - block = block.Next; - index = block.Start; - } - } - } - - public ArraySegment GetArraySegment(Iterator end) - { - if (IsDefault || end.IsDefault) - { - return default(ArraySegment); - } - if (end._block == _block) - { - return new ArraySegment(_block.Array, _index, end._index - _index); - } - - var length = GetLength(end); - var array = new byte[length]; - CopyTo(array, 0, length, out length); - return new ArraySegment(array, 0, length); - } - - public Iterator CopyTo(byte[] array, int offset, int count, out int actual) - { - if (IsDefault) - { - actual = 0; - return this; - } - - var block = _block; - var index = _index; - var remaining = count; - while (true) - { - var following = block.End - index; - if (remaining <= following) - { - actual = count; - Buffer.BlockCopy(block.Array, index, array, offset, remaining); - return new Iterator(block, index + remaining); - } - else if (block.Next == null) - { - actual = count - remaining + following; - Buffer.BlockCopy(block.Array, index, array, offset, following); - return new Iterator(block, index + following); - } - else - { - Buffer.BlockCopy(block.Array, index, array, offset, following); - remaining -= following; - block = block.Next; - index = block.Start; - } - } - } - } - } -} diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketInput.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketInput.cs index 03ef803e9c..6352b742ef 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketInput.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketInput.cs @@ -2,12 +2,11 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.Diagnostics; using System.IO; using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; using System.Threading; using System.Threading.Tasks; +using Microsoft.AspNet.Server.Kestrel.Infrastructure; namespace Microsoft.AspNet.Server.Kestrel.Http { @@ -131,17 +130,17 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } - public MemoryPoolBlock2.Iterator ConsumingStart() + public MemoryPoolIterator2 ConsumingStart() { lock (_sync) { - return new MemoryPoolBlock2.Iterator(_head); + return new MemoryPoolIterator2(_head); } } public void ConsumingComplete( - MemoryPoolBlock2.Iterator consumed, - MemoryPoolBlock2.Iterator examined) + MemoryPoolIterator2 consumed, + MemoryPoolIterator2 examined) { MemoryPoolBlock2 returnStart = null; MemoryPoolBlock2 returnEnd = null; diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/MemoryPool2.cs b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPool2.cs similarity index 99% rename from src/Microsoft.AspNet.Server.Kestrel/Http/MemoryPool2.cs rename to src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPool2.cs index 941fb9b796..a0fd3e4a7c 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/MemoryPool2.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPool2.cs @@ -1,7 +1,7 @@ using System; using System.Collections.Concurrent; -namespace Microsoft.AspNet.Server.Kestrel.Http +namespace Microsoft.AspNet.Server.Kestrel.Infrastructure { /// /// Used to allocate and distribute re-usable blocks of memory. diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolBlock2.cs b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolBlock2.cs new file mode 100644 index 0000000000..bb7eb5758c --- /dev/null +++ b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolBlock2.cs @@ -0,0 +1,184 @@ +using System; +using System.Diagnostics; +using System.Runtime.InteropServices; +using System.Text; + +namespace Microsoft.AspNet.Server.Kestrel.Infrastructure +{ + /// + /// Block tracking object used by the byte buffer memory pool. A slab is a large allocation which is divided into smaller blocks. The + /// individual blocks are then treated as independant array segments. + /// + public class MemoryPoolBlock2 + { + /// + /// If this block represents a one-time-use memory object, this GCHandle will hold that memory object at a fixed address + /// so it can be used in native operations. + /// + private GCHandle _pinHandle; + + /// + /// Native address of the first byte of this block's Data memory. It is null for one-time-use memory, or copied from + /// the Slab's ArrayPtr for a slab-block segment. The byte it points to corresponds to Data.Array[0], and in practice you will always + /// use the _dataArrayPtr + Start or _dataArrayPtr + End, which point to the start of "active" bytes, or point to just after the "active" bytes. + /// + private IntPtr _dataArrayPtr; + + /// + /// The array segment describing the range of memory this block is tracking. The caller which has leased this block may only read and + /// modify the memory in this range. + /// + public ArraySegment Data; + + /// + /// This object cannot be instantiated outside of the static Create method + /// + protected MemoryPoolBlock2() + { + } + + /// + /// Back-reference to the memory pool which this block was allocated from. It may only be returned to this pool. + /// + public MemoryPool2 Pool { get; private set; } + + /// + /// Back-reference to the slab from which this block was taken, or null if it is one-time-use memory. + /// + public MemoryPoolSlab2 Slab { get; private set; } + + /// + /// Convenience accessor + /// + public byte[] Array => Data.Array; + + /// + /// The Start represents the offset into Array where the range of "active" bytes begins. At the point when the block is leased + /// the Start is guaranteed to be equal to Array.Offset. The value of Start may be assigned anywhere between Data.Offset and + /// Data.Offset + Data.Count, and must be equal to or less than End. + /// + public int Start { get; set; } + + /// + /// The End represents the offset into Array where the range of "active" bytes ends. At the point when the block is leased + /// the End is guaranteed to be equal to Array.Offset. The value of Start may be assigned anywhere between Data.Offset and + /// Data.Offset + Data.Count, and must be equal to or less than End. + /// + public int End { get; set; } + + + /// + /// Reference to the next block of data when the overall "active" bytes spans multiple blocks. At the point when the block is + /// leased Next is guaranteed to be null. Start, End, and Next are used together in order to create a linked-list of discontiguous + /// working memory. The "active" memory is grown when bytes are copied in, End is increased, and Next is assigned. The "active" + /// memory is shrunk when bytes are consumed, Start is increased, and blocks are returned to the pool. + /// + public MemoryPoolBlock2 Next { get; set; } + + ~MemoryPoolBlock2() + { + if (_pinHandle.IsAllocated) + { + // if this is a one-time-use block, ensure that the GCHandle does not leak + _pinHandle.Free(); + } + + if (Slab != null && Slab.IsActive) + { + Pool.Return(new MemoryPoolBlock2 + { + _dataArrayPtr = _dataArrayPtr, + Data = Data, + Pool = Pool, + Slab = Slab, + }); + } + } + + /// + /// Called to ensure that a block is pinned, and return the pointer to native memory just after + /// the range of "active" bytes. This is where arriving data is read into. + /// + /// + public IntPtr Pin() + { + Debug.Assert(!_pinHandle.IsAllocated); + + if (_dataArrayPtr != IntPtr.Zero) + { + // this is a slab managed block - use the native address of the slab which is always locked + return _dataArrayPtr + End; + } + else + { + // this is one-time-use memory - lock the managed memory until Unpin is called + _pinHandle = GCHandle.Alloc(Data.Array, GCHandleType.Pinned); + return _pinHandle.AddrOfPinnedObject() + End; + } + } + + public void Unpin() + { + if (_dataArrayPtr == IntPtr.Zero) + { + // this is one-time-use memory - unlock the managed memory + Debug.Assert(_pinHandle.IsAllocated); + _pinHandle.Free(); + } + } + + public static MemoryPoolBlock2 Create(int size, MemoryPool2 pool) + { + return new MemoryPoolBlock2 + { + Data = new ArraySegment(new byte[size]), + Pool = pool + }; + } + + public static MemoryPoolBlock2 Create( + ArraySegment data, + IntPtr dataPtr, + MemoryPool2 pool, + MemoryPoolSlab2 slab) + { + return new MemoryPoolBlock2 + { + Data = data, + _dataArrayPtr = dataPtr, + Pool = pool, + Slab = slab, + Start = data.Offset, + End = data.Offset, + }; + } + + /// + /// called when the block is returned to the pool. mutable values are re-assigned to their guaranteed initialized state. + /// + public void Reset() + { + Next = null; + Start = Data.Offset; + End = Data.Offset; + } + + /// + /// ToString overridden for debugger convenience. This displays the "active" byte information in this block as ASCII characters. + /// + /// + public override string ToString() + { + return Encoding.ASCII.GetString(Array, Start, End - Start); + } + + /// + /// acquires a cursor pointing into this block at the Start of "active" byte information + /// + /// + public MemoryPoolIterator2 GetIterator() + { + return new MemoryPoolIterator2(this); + } + } +} diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolIterator2.cs b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolIterator2.cs new file mode 100644 index 0000000000..7e409153c4 --- /dev/null +++ b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolIterator2.cs @@ -0,0 +1,452 @@ +using System; +using System.Linq; +using System.Numerics; +using System.Text; + +namespace Microsoft.AspNet.Server.Kestrel.Infrastructure +{ + public struct MemoryPoolIterator2 + { + /// + /// Array of "minus one" bytes of the length of SIMD operations on the current hardware. Used as an argument in the + /// vector dot product that counts matching character occurence. + /// + private static Vector _dotCount = new Vector(Byte.MaxValue); + + /// + /// Array of negative numbers starting at 0 and continuing for the length of SIMD operations on the current hardware. + /// Used as an argument in the vector dot product that determines matching character index. + /// + private static Vector _dotIndex = new Vector(Enumerable.Range(0, Vector.Count).Select(x => (byte)-x).ToArray()); + + private static Encoding _utf8 = Encoding.UTF8; + + private MemoryPoolBlock2 _block; + private int _index; + + public MemoryPoolIterator2(MemoryPoolBlock2 block) + { + _block = block; + _index = _block?.Start ?? 0; + } + public MemoryPoolIterator2(MemoryPoolBlock2 block, int index) + { + _block = block; + _index = index; + } + + public bool IsDefault => _block == null; + + public bool IsEnd + { + get + { + if (_block == null) + { + return true; + } + else if (_index < _block.End) + { + return false; + } + else + { + for (var block = _block.Next; block != null; block = block.Next) + { + if (block.Start < block.End) + { + return true; + } + } + return true; + } + } + } + + public MemoryPoolBlock2 Block => _block; + + public int Index => _index; + + public int Take() + { + if (_block == null) + { + return -1; + } + else if (_index < _block.End) + { + return _block.Array[_index++]; + } + + var block = _block; + var index = _index; + while (true) + { + if (index < block.End) + { + _block = block; + _index = index + 1; + return block.Array[index]; + } + else if (block.Next == null) + { + return -1; + } + else + { + block = block.Next; + index = block.Start; + } + } + } + + public int Peek() + { + if (_block == null) + { + return -1; + } + else if (_index < _block.End) + { + return _block.Array[_index]; + } + else if (_block.Next == null) + { + return -1; + } + + var block = _block.Next; + var index = block.Start; + while (true) + { + if (index < block.End) + { + return block.Array[index]; + } + else if (block.Next == null) + { + return -1; + } + else + { + block = block.Next; + index = block.Start; + } + } + } + + public int Seek(int char0) + { + if (IsDefault) + { + return -1; + } + + var byte0 = (byte)char0; + var vectorStride = Vector.Count; + var ch0Vector = new Vector(byte0); + + var block = _block; + var index = _index; + var array = block.Array; + while (true) + { + while (block.End == index) + { + if (block.Next == null) + { + _block = block; + _index = index; + return -1; + } + block = block.Next; + index = block.Start; + array = block.Array; + } + while (block.End != index) + { + var following = block.End - index; + if (following >= vectorStride) + { + var data = new Vector(array, index); + var ch0Equals = Vector.Equals(data, ch0Vector); + var ch0Count = Vector.Dot(ch0Equals, _dotCount); + + if (ch0Count == 0) + { + index += vectorStride; + continue; + } + else if (ch0Count == 1) + { + _block = block; + _index = index + Vector.Dot(ch0Equals, _dotIndex); + return char0; + } + else + { + following = vectorStride; + } + } + for (; following != 0; following--, index++) + { + if (block.Array[index] == byte0) + { + _block = block; + _index = index; + return char0; + } + } + } + } + } + + public int Seek(int char0, int char1) + { + if (IsDefault) + { + return -1; + } + + var byte0 = (byte)char0; + var byte1 = (byte)char1; + var vectorStride = Vector.Count; + var ch0Vector = new Vector(byte0); + var ch1Vector = new Vector(byte1); + + var block = _block; + var index = _index; + var array = block.Array; + while (true) + { + while (block.End == index) + { + if (block.Next == null) + { + _block = block; + _index = index; + return -1; + } + block = block.Next; + index = block.Start; + array = block.Array; + } + while (block.End != index) + { + var following = block.End - index; + if (following >= vectorStride) + { + var data = new Vector(array, index); + var ch0Equals = Vector.Equals(data, ch0Vector); + var ch0Count = Vector.Dot(ch0Equals, _dotCount); + var ch1Equals = Vector.Equals(data, ch1Vector); + var ch1Count = Vector.Dot(ch1Equals, _dotCount); + + if (ch0Count == 0 && ch1Count == 0) + { + index += vectorStride; + continue; + } + else if (ch0Count < 2 && ch1Count < 2) + { + var ch0Index = ch0Count == 1 ? Vector.Dot(ch0Equals, _dotIndex) : byte.MaxValue; + var ch1Index = ch1Count == 1 ? Vector.Dot(ch1Equals, _dotIndex) : byte.MaxValue; + if (ch0Index < ch1Index) + { + _block = block; + _index = index + ch0Index; + return char0; + } + else + { + _block = block; + _index = index + ch1Index; + return char1; + } + } + else + { + following = vectorStride; + } + } + for (; following != 0; following--, index++) + { + var byteIndex = block.Array[index]; + if (byteIndex == byte0) + { + _block = block; + _index = index; + return char0; + } + else if (byteIndex == byte1) + { + _block = block; + _index = index; + return char1; + } + } + } + } + } + + public int GetLength(MemoryPoolIterator2 end) + { + if (IsDefault || end.IsDefault) + { + return -1; + } + + var block = _block; + var index = _index; + var length = 0; + while (true) + { + if (block == end._block) + { + return length + end._index - index; + } + else if (block.Next == null) + { + throw new InvalidOperationException("end did not follow iterator"); + } + else + { + length += block.End - index; + block = block.Next; + index = block.Start; + } + } + } + + public string GetString(MemoryPoolIterator2 end) + { + if (IsDefault || end.IsDefault) + { + return default(string); + } + if (end._block == _block) + { + return _utf8.GetString(_block.Array, _index, end._index - _index); + } + + var decoder = _utf8.GetDecoder(); + + var length = GetLength(end); + var charLength = length * 2; + var chars = new char[charLength]; + var charIndex = 0; + + var block = _block; + var index = _index; + var remaining = length; + while (true) + { + int bytesUsed; + int charsUsed; + bool completed; + var following = block.End - index; + if (remaining <= following) + { + decoder.Convert( + block.Array, + index, + remaining, + chars, + charIndex, + charLength - charIndex, + true, + out bytesUsed, + out charsUsed, + out completed); + return new string(chars, 0, charIndex + charsUsed); + } + else if (block.Next == null) + { + decoder.Convert( + block.Array, + index, + following, + chars, + charIndex, + charLength - charIndex, + true, + out bytesUsed, + out charsUsed, + out completed); + return new string(chars, 0, charIndex + charsUsed); + } + else + { + decoder.Convert( + block.Array, + index, + following, + chars, + charIndex, + charLength - charIndex, + false, + out bytesUsed, + out charsUsed, + out completed); + charIndex += charsUsed; + remaining -= following; + block = block.Next; + index = block.Start; + } + } + } + + public ArraySegment GetArraySegment(MemoryPoolIterator2 end) + { + if (IsDefault || end.IsDefault) + { + return default(ArraySegment); + } + if (end._block == _block) + { + return new ArraySegment(_block.Array, _index, end._index - _index); + } + + var length = GetLength(end); + var array = new byte[length]; + CopyTo(array, 0, length, out length); + return new ArraySegment(array, 0, length); + } + + public MemoryPoolIterator2 CopyTo(byte[] array, int offset, int count, out int actual) + { + if (IsDefault) + { + actual = 0; + return this; + } + + var block = _block; + var index = _index; + var remaining = count; + while (true) + { + var following = block.End - index; + if (remaining <= following) + { + actual = count; + Buffer.BlockCopy(block.Array, index, array, offset, remaining); + return new MemoryPoolIterator2(block, index + remaining); + } + else if (block.Next == null) + { + actual = count - remaining + following; + Buffer.BlockCopy(block.Array, index, array, offset, following); + return new MemoryPoolIterator2(block, index + following); + } + else + { + Buffer.BlockCopy(block.Array, index, array, offset, following); + remaining -= following; + block = block.Next; + index = block.Start; + } + } + } + } +} diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/MemoryPoolSlab2.cs b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolSlab2.cs similarity index 97% rename from src/Microsoft.AspNet.Server.Kestrel/Http/MemoryPoolSlab2.cs rename to src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolSlab2.cs index bf0221dda7..9e5e3bb2eb 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/MemoryPoolSlab2.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolSlab2.cs @@ -1,9 +1,7 @@ using System; -using System.Collections.Concurrent; -using System.Diagnostics; using System.Runtime.InteropServices; -namespace Microsoft.AspNet.Server.Kestrel.Http +namespace Microsoft.AspNet.Server.Kestrel.Infrastructure { /// /// Slab tracking object used by the byte buffer memory pool. A slab is a large allocation which is divided into smaller blocks. The diff --git a/test/Microsoft.AspNet.Server.KestrelTests/MemoryPoolBlock2Tests.cs b/test/Microsoft.AspNet.Server.KestrelTests/MemoryPoolBlock2Tests.cs index a9c6e5a24f..2f43e0239d 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/MemoryPoolBlock2Tests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/MemoryPoolBlock2Tests.cs @@ -1,8 +1,5 @@ -using Microsoft.AspNet.Server.Kestrel.Http; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; +using System.Linq; +using Microsoft.AspNet.Server.Kestrel.Infrastructure; using Xunit; namespace Microsoft.AspNet.Server.KestrelTests @@ -120,7 +117,7 @@ namespace Microsoft.AspNet.Server.KestrelTests } } - private void AssertIterator(MemoryPoolBlock2.Iterator iter, MemoryPoolBlock2 block, int index) + private void AssertIterator(MemoryPoolIterator2 iter, MemoryPoolBlock2 block, int index) { Assert.Same(block, iter.Block); Assert.Equal(index, iter.Index); diff --git a/test/Microsoft.AspNet.Server.KestrelTests/MemoryPoolExtensions.cs b/test/Microsoft.AspNet.Server.KestrelTests/MemoryPoolExtensions.cs index 3578dda184..1eb6830889 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/MemoryPoolExtensions.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/MemoryPoolExtensions.cs @@ -1,10 +1,10 @@ -using Microsoft.AspNet.Server.Kestrel.Http; +using Microsoft.AspNet.Server.Kestrel.Infrastructure; namespace Microsoft.AspNet.Server.KestrelTests { public static class MemoryPoolExtensions { - public static MemoryPoolBlock2.Iterator Add(this MemoryPoolBlock2.Iterator iterator, int count) + public static MemoryPoolIterator2 Add(this MemoryPoolIterator2 iterator, int count) { int actual; return iterator.CopyTo(new byte[count], 0, count, out actual); diff --git a/test/Microsoft.AspNet.Server.KestrelTests/TestInput.cs b/test/Microsoft.AspNet.Server.KestrelTests/TestInput.cs index 63f55cab03..47470bb4fc 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/TestInput.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/TestInput.cs @@ -5,6 +5,7 @@ using System; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNet.Server.Kestrel.Http; +using Microsoft.AspNet.Server.Kestrel.Infrastructure; namespace Microsoft.AspNet.Server.KestrelTests { From 844c791b16b395cef178cd35b29dea6ebefca80e Mon Sep 17 00:00:00 2001 From: Louis DeJardin Date: Sat, 19 Sep 2015 11:20:42 -0700 Subject: [PATCH 0281/1662] Processing function should return Task --- src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs | 3 +-- src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs index 8e733de108..9d091b752a 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs @@ -39,8 +39,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http public void Start() { Log.ConnectionStart(_connectionId); - - Task.Run((Action)_frame.ProcessFraming); + Task.Run(_frame.ProcessFraming); _socket.ReadStart(_allocCallback, _readCallback, this); } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs index 5820f1f3b8..48640b0776 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs @@ -99,7 +99,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http _responseHeaders.HeaderDate = DateTime.UtcNow.ToString("r"); } - public async void ProcessFraming() + public async Task ProcessFraming() { try { From c424b8437cc62acb1bbee76b9d0905f4e304ad24 Mon Sep 17 00:00:00 2001 From: Louis DeJardin Date: Sat, 19 Sep 2015 11:25:13 -0700 Subject: [PATCH 0282/1662] Renaming based on PR feedback --- .../Http/SocketOutput.cs | 36 +++++++++++++++---- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs index ecf62582e5..478d29ded9 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs @@ -139,7 +139,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http try { - writingContext.Execute(); + writingContext.DoWriteIfNeeded(); } catch { @@ -284,11 +284,23 @@ namespace Microsoft.AspNet.Server.Kestrel.Http Buffers = new Queue>(); } + /// + /// Perform any actions needed by this work item. The individual tasks are non-blocking and + /// will continue through to each other in order. + /// public void Execute() + { + DoWriteIfNeeded(); + } + + /// + /// First step: initiate async write if needed, otherwise go to next step + /// + public void DoWriteIfNeeded() { if (Buffers.Count == 0 || Self._socket.IsClosed) { - StageTwo(); + DoShutdownIfNeeded(); return; } @@ -304,19 +316,26 @@ namespace Microsoft.AspNet.Server.Kestrel.Http writeReq.Init(Self._thread.Loop); writeReq.Write(Self._socket, new ArraySegment>(buffers), (_writeReq, status, error, state) => { + if (error != null) + { + var x = 5; + } _writeReq.Dispose(); var _this = (WriteContext)state; _this.WriteStatus = status; _this.WriteError = error; - StageTwo(); + DoShutdownIfNeeded(); }, this); } - public void StageTwo() + /// + /// Second step: initiate async shutdown if needed, otherwise go to next step + /// + public void DoShutdownIfNeeded() { if (SocketShutdownSend == false || Self._socket.IsClosed) { - StageThree(); + DoDisconnectIfNeeded(); return; } @@ -330,11 +349,14 @@ namespace Microsoft.AspNet.Server.Kestrel.Http Self._log.ConnectionWroteFin(Self._connectionId, status); - StageThree(); + DoDisconnectIfNeeded(); }, this); } - public void StageThree() + /// + /// Third step: disconnect socket if needed, otherwise this work item is complete + /// + public void DoDisconnectIfNeeded() { if (SocketDisconnect == false || Self._socket.IsClosed) { From 37f7dfd01f3aad4bad6ae709b0add4c67fd3f1e2 Mon Sep 17 00:00:00 2001 From: Louis DeJardin Date: Sat, 19 Sep 2015 11:26:35 -0700 Subject: [PATCH 0283/1662] Typo in comments --- .../Infrastructure/MemoryPool2.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPool2.cs b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPool2.cs index a0fd3e4a7c..80705def58 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPool2.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPool2.cs @@ -66,7 +66,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure // The requested minimumSize is actually larger then the usable memory of a single block. // Because this is the degenerate case, a one-time-use byte[] array and tracking object are allocated. // When this block tracking object is returned it is not added to the pool - instead it will be - // allowed to be garbace collected normally. + // allowed to be garbage collected normally. return MemoryPoolBlock2.Create( new ArraySegment(new byte[minimumSize]), dataPtr: IntPtr.Zero, From f89a586b7573d2201b5a70d3e9cd0c27c0c84d04 Mon Sep 17 00:00:00 2001 From: Louis DeJardin Date: Sat, 19 Sep 2015 11:27:54 -0700 Subject: [PATCH 0284/1662] Removing boilerplate-generated #region --- .../Infrastructure/Disposable.cs | 3 --- .../Infrastructure/MemoryPool2.cs | 3 --- .../Infrastructure/MemoryPoolSlab2.cs | 3 --- 3 files changed, 9 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/Disposable.cs b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/Disposable.cs index 9ad2e36a1d..b3fcbbb0a3 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/Disposable.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/Disposable.cs @@ -18,8 +18,6 @@ namespace Microsoft.AspNet.Server.Kestrel _dispose = dispose; } - #region IDisposable Support - protected virtual void Dispose(bool disposing) { if (!disposedValue) @@ -41,6 +39,5 @@ namespace Microsoft.AspNet.Server.Kestrel Dispose(true); GC.SuppressFinalize(this); } - #endregion } } \ No newline at end of file diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPool2.cs b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPool2.cs index 80705def58..4a209c047d 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPool2.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPool2.cs @@ -126,8 +126,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure _blocks.Push(block); } - #region IDisposable Support - protected virtual void Dispose(bool disposing) { if (!disposedValue) @@ -164,6 +162,5 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure // N/A: uncomment the following line if the finalizer is overridden above. // GC.SuppressFinalize(this); } - #endregion } } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolSlab2.cs b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolSlab2.cs index 9e5e3bb2eb..6d277062e9 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolSlab2.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolSlab2.cs @@ -57,8 +57,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure }; } - #region IDisposable Support - protected virtual void Dispose(bool disposing) { if (!disposedValue) @@ -94,6 +92,5 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure // uncomment the following line if the finalizer is overridden above. GC.SuppressFinalize(this); } - #endregion } } From 325423de40ec42e0d8908539b762e00afae58e68 Mon Sep 17 00:00:00 2001 From: Louis DeJardin Date: Sat, 19 Sep 2015 11:29:15 -0700 Subject: [PATCH 0285/1662] Sorting usings --- test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs index d3882bedc4..8a9e9709ae 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs @@ -12,7 +12,6 @@ using Microsoft.AspNet.Server.Kestrel.Http; using Microsoft.Dnx.Runtime; using Microsoft.Dnx.Runtime.Infrastructure; using Xunit; -using System.Linq; namespace Microsoft.AspNet.Server.KestrelTests { From 99fc7e4e50e6b647cb441665ab43e6e0d2f6a22e Mon Sep 17 00:00:00 2001 From: Louis DeJardin Date: Sat, 19 Sep 2015 15:26:21 -0700 Subject: [PATCH 0286/1662] Moving the Start/Stop logic into Frame. Also formalizes the relationship between the function's Task and how it relates to graceful shutdown. Specifically how it relates to finishing the requests currently in progress. --- .../Http/Connection.cs | 2 +- .../Http/Frame.cs | 54 ++++++++++++++++--- 2 files changed, 47 insertions(+), 9 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs index 9d091b752a..def246b92b 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs @@ -39,7 +39,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http public void Start() { Log.ConnectionStart(_connectionId); - Task.Run(_frame.ProcessFraming); + _frame.Start(); _socket.ReadStart(_allocCallback, _readCallback, this); } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs index 48640b0776..2387d8de65 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs @@ -31,8 +31,13 @@ namespace Microsoft.AspNet.Server.Kestrel.Http private readonly FrameResponseHeaders _responseHeaders = new FrameResponseHeaders(); private List, object>> _onStarting; + private List, object>> _onCompleted; + private bool _requestProcessingStarted; + private bool _requestProcessingStopping; + private Task _requestProcessingTask; + private bool _responseStarted; private bool _keepAlive; private bool _autoChunk; @@ -99,14 +104,47 @@ namespace Microsoft.AspNet.Server.Kestrel.Http _responseHeaders.HeaderDate = DateTime.UtcNow.ToString("r"); } - public async Task ProcessFraming() + /// + /// Called once by Connection class to begin the RequestProcessingAsync loop. + /// + public void Start() + { + if (!_requestProcessingStarted) + { + _requestProcessingStarted = true; + _requestProcessingTask = Task.Run(RequestProcessingAsync); + } + } + + /// + /// Should be called when the server wants to initiate a shutdown. The Task returned will + /// become complete when the RequestProcessingAsync function has exited. It is expected that + /// Stop will be called on all active connections, and Task.WaitAll() will be called on every + /// return value. + /// + public Task Stop() + { + if (!_requestProcessingStopping) + { + _requestProcessingStopping = true; + } + return _requestProcessingTask ?? TaskUtilities.CompletedTask; + } + + /// + /// Primary loop which consumes socket input, parses it for protocol framing, and invokes the + /// application delegate for as long as the socket is intended to remain open. + /// The resulting Task from this loop is preserved in a field which is used when the server needs + /// to drain and close all currently active connections. + /// + public async Task RequestProcessingAsync() { try { var terminated = false; - while (!terminated) + while (!terminated && !_requestProcessingStopping) { - while (!terminated && !TakeStartLine(SocketInput)) + while (!terminated && !_requestProcessingStopping && !TakeStartLine(SocketInput)) { terminated = SocketInput.RemoteIntakeFin; if (!terminated) @@ -115,7 +153,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } - while (!terminated && !TakeMessageHeaders(SocketInput)) + while (!terminated && !_requestProcessingStopping && !TakeMessageHeaders(SocketInput)) { terminated = SocketInput.RemoteIntakeFin; if (!terminated) @@ -124,7 +162,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } - if (!terminated) + if (!terminated && !_requestProcessingStopping) { MessageBody = MessageBody.For(HttpVersion, _requestHeaders, this); _keepAlive = MessageBody.RequestKeepAlive; @@ -163,7 +201,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } catch (Exception ex) { - Log.LogVerbose("Connection processing ended abnormally", ex); + Log.LogWarning("Connection processing ended abnormally", ex); } finally { @@ -178,9 +216,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Http // Dispose socket ConnectionControl.End(ProduceEndType.SocketDisconnect); } - catch(Exception ex) + catch (Exception ex) { - Log.LogVerbose("Connection shutdown abnormally", ex); + Log.LogWarning("Connection shutdown abnormally", ex); } } } From 5e678fdbaa8540bcb6077060c4bba33841915035 Mon Sep 17 00:00:00 2001 From: Louis DeJardin Date: Sat, 19 Sep 2015 15:37:47 -0700 Subject: [PATCH 0287/1662] Adding volatile keyword to stopping boolean --- src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs index 2387d8de65..fdedb2ab19 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs @@ -35,8 +35,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http private List, object>> _onCompleted; private bool _requestProcessingStarted; - private bool _requestProcessingStopping; private Task _requestProcessingTask; + private volatile bool _requestProcessingStopping; // volatile, see: https://msdn.microsoft.com/en-us/library/x13ttww7.aspx private bool _responseStarted; private bool _keepAlive; From 789d5b3595199d79d7b25332740261a049152de0 Mon Sep 17 00:00:00 2001 From: Louis DeJardin Date: Mon, 21 Sep 2015 14:31:03 -0700 Subject: [PATCH 0288/1662] Writes which are not immediate always return completed tasks They must always be followed with Writes which are immediate, and returning an incomplete task put them in a state where the callback might not have been initiated. --- .../Http/SocketOutput.cs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs index 478d29ded9..e52823dc60 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs @@ -216,6 +216,18 @@ namespace Microsoft.AspNet.Server.Kestrel.Http Task ISocketOutput.WriteAsync(ArraySegment buffer, bool immediate, CancellationToken cancellationToken) { + if (!immediate) + { + // immediate==false calls always return complete tasks, because there is guaranteed + // to be a subsequent immediate==true call which will go down the following code-path + Write( + buffer, + (error, state) => { }, + null, + immediate: false); + return TaskUtilities.CompletedTask; + } + // TODO: Optimize task being used, and remove callback model from the underlying Write var tcs = new TaskCompletionSource(); @@ -233,7 +245,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } }, tcs, - immediate: immediate); + immediate: true); return tcs.Task; } From dc902f5fc484283388df11c5185b504437b4491a Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Mon, 21 Sep 2015 16:14:19 -0700 Subject: [PATCH 0289/1662] Update SocketOutput to not call QueueUserWorkItem unnecessarily --- .../Http/SocketOutput.cs | 99 +++++++++++++------ .../SocketOutputTests.cs | 4 +- 2 files changed, 72 insertions(+), 31 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs index e52823dc60..5c890807b6 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs @@ -44,7 +44,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http public void Write( ArraySegment buffer, - Action callback, + Action callback, object state, bool immediate = true, bool socketShutdownSend = false, @@ -109,7 +109,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http // Make sure we call user code outside of the lock. if (triggerCallbackNow) { - callback(null, state); + // callback(error, state, calledInline) + callback(null, state, true); } } @@ -190,7 +191,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http _numBytesPreCompleted += callbackContext.BytesToWrite; - TriggerCallback(callbackContext); + // callback(error, state, calledInline) + callbackContext.Callback(_lastWriteError, callbackContext.State, false); } // Now that the while loop has completed the following invariants should hold true: @@ -199,22 +201,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } - private void TriggerCallback(CallbackContext context) - { - context.Error = _lastWriteError; - ThreadPool.QueueUserWorkItem(obj => - { - var c = (CallbackContext)obj; - c.Callback(c.Error, c.State); - }, context); - } - void ISocketOutput.Write(ArraySegment buffer, bool immediate) - { - ((ISocketOutput)this).WriteAsync(buffer, immediate).GetAwaiter().GetResult(); - } - - Task ISocketOutput.WriteAsync(ArraySegment buffer, bool immediate, CancellationToken cancellationToken) { if (!immediate) { @@ -222,10 +209,10 @@ namespace Microsoft.AspNet.Server.Kestrel.Http // to be a subsequent immediate==true call which will go down the following code-path Write( buffer, - (error, state) => { }, + (error, state, calledInline) => { }, null, immediate: false); - return TaskUtilities.CompletedTask; + return; } // TODO: Optimize task being used, and remove callback model from the underlying Write @@ -233,7 +220,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http Write( buffer, - (error, state) => + (error, state, calledInline) => { if (error != null) { @@ -247,6 +234,64 @@ namespace Microsoft.AspNet.Server.Kestrel.Http tcs, immediate: true); + if (tcs.Task.Status != TaskStatus.RanToCompletion) + { + tcs.Task.GetAwaiter().GetResult(); + } + } + + Task ISocketOutput.WriteAsync(ArraySegment buffer, bool immediate, CancellationToken cancellationToken) + { + if (!immediate) + { + // immediate==false calls always return complete tasks, because there is guaranteed + // to be a subsequent immediate==true call which will go down the following code-path + Write( + buffer, + (error, state, calledInline) => { }, + null, + immediate: false); + return TaskUtilities.CompletedTask; + } + + // TODO: Optimize task being used, and remove callback model from the underlying Write + var tcs = new TaskCompletionSource(); + + Write( + buffer, + (error, state, calledInline) => + { + if (!calledInline) + { + ThreadPool.QueueUserWorkItem(state2 => + { + var tcs2 = (TaskCompletionSource)state2; + if (error != null) + { + tcs2.SetException(error); + } + else + { + tcs2.SetResult(0); + } + }, state); + } + else + { + var tcs2 = (TaskCompletionSource)state; + if (error != null) + { + tcs2.SetException(error); + } + else + { + tcs2.SetResult(0); + } + } + }, + tcs, + immediate: true); + return tcs.Task; } @@ -255,13 +300,13 @@ namespace Microsoft.AspNet.Server.Kestrel.Http switch (endType) { case ProduceEndType.SocketShutdownSend: - Write(default(ArraySegment), (error, state) => { }, null, + Write(default(ArraySegment), (error, state, calledInline) => { }, null, immediate: true, socketShutdownSend: true, socketDisconnect: false); break; case ProduceEndType.SocketDisconnect: - Write(default(ArraySegment), (error, state) => { }, null, + Write(default(ArraySegment), (error, state, calledInline) => { }, null, immediate: true, socketShutdownSend: false, socketDisconnect: true); @@ -271,8 +316,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http private class CallbackContext { - public Exception Error; - public Action Callback; + // callback(error, state, calledInline) + public Action Callback; public object State; public int BytesToWrite; } @@ -328,10 +373,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Http writeReq.Init(Self._thread.Loop); writeReq.Write(Self._socket, new ArraySegment>(buffers), (_writeReq, status, error, state) => { - if (error != null) - { - var x = 5; - } _writeReq.Dispose(); var _this = (WriteContext)state; _this.WriteStatus = status; diff --git a/test/Microsoft.AspNet.Server.KestrelTests/SocketOutputTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/SocketOutputTests.cs index 489f683bf6..b636cbf5cd 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/SocketOutputTests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/SocketOutputTests.cs @@ -45,7 +45,7 @@ namespace Microsoft.AspNet.Server.KestrelTests var bufferSize = 1048576; var buffer = new ArraySegment(new byte[bufferSize], 0, bufferSize); var completedWh = new ManualResetEventSlim(); - Action onCompleted = (ex, state) => + Action onCompleted = (ex, state, calledInline) => { Assert.Null(ex); Assert.Null(state); @@ -89,7 +89,7 @@ namespace Microsoft.AspNet.Server.KestrelTests var bufferSize = maxBytesPreCompleted; var buffer = new ArraySegment(new byte[bufferSize], 0, bufferSize); var completedWh = new ManualResetEventSlim(); - Action onCompleted = (ex, state) => + Action onCompleted = (ex, state, calledInline) => { Assert.Null(ex); Assert.Null(state); From b6c272cd5b945cf65854672389816881b595c5e3 Mon Sep 17 00:00:00 2001 From: Louis DeJardin Date: Wed, 23 Sep 2015 13:34:11 -0700 Subject: [PATCH 0290/1662] Removing console output from unit tests --- test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs | 9 --------- test/Microsoft.AspNet.Server.KestrelTests/TestLogger.cs | 2 ++ 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs index 8a9e9709ae..0d7ad85fae 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs @@ -60,18 +60,9 @@ namespace Microsoft.AspNet.Server.KestrelTests private async Task AppChunked(Frame frame) { - Console.WriteLine($"----"); - Console.WriteLine($"{frame.Method} {frame.RequestUri} {frame.HttpVersion}"); - foreach (var h in frame.RequestHeaders) - { - Console.WriteLine($"{h.Key}: {h.Value}"); - } - Console.WriteLine($""); - var data = new MemoryStream(); await frame.RequestBody.CopyToAsync(data); var bytes = data.ToArray(); - Console.WriteLine($"{Encoding.ASCII.GetString(bytes)}"); frame.ResponseHeaders.Clear(); frame.ResponseHeaders["Content-Length"] = new[] { bytes.Length.ToString() }; diff --git a/test/Microsoft.AspNet.Server.KestrelTests/TestLogger.cs b/test/Microsoft.AspNet.Server.KestrelTests/TestLogger.cs index e8658f7615..db346ade3a 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/TestLogger.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/TestLogger.cs @@ -30,7 +30,9 @@ namespace Microsoft.AspNet.Server.KestrelTests { public void Log(LogLevel logLevel, int eventId, object state, Exception exception, Func formatter) { +#if false Console.WriteLine($"Log {logLevel}[{eventId}]: {formatter(state, exception)} {exception?.Message}"); +#endif } public bool IsEnabled(LogLevel logLevel) From 0adbbd0217f87553127f0dbaa9b6a64dc8f95e8c Mon Sep 17 00:00:00 2001 From: Louis DeJardin Date: Fri, 25 Sep 2015 11:14:54 -0700 Subject: [PATCH 0291/1662] Using the well-known-header field without checking set bit --- .../Http/FrameHeaders.Generated.cs | 710 ++++-------------- .../KnownHeaders.cs | 10 +- 2 files changed, 144 insertions(+), 576 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameHeaders.Generated.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameHeaders.Generated.cs index 50d57d6ce0..2d5a6c20c0 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameHeaders.Generated.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameHeaders.Generated.cs @@ -57,14 +57,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { get { - if (((_bits & 1L) != 0)) - { - return _CacheControl; - } - else - { - return StringValues.Empty; - } + return _CacheControl; } set { @@ -77,14 +70,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { get { - if (((_bits & 2L) != 0)) - { - return _Connection; - } - else - { - return StringValues.Empty; - } + return _Connection; } set { @@ -97,14 +83,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { get { - if (((_bits & 4L) != 0)) - { - return _Date; - } - else - { - return StringValues.Empty; - } + return _Date; } set { @@ -117,14 +96,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { get { - if (((_bits & 8L) != 0)) - { - return _KeepAlive; - } - else - { - return StringValues.Empty; - } + return _KeepAlive; } set { @@ -137,14 +109,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { get { - if (((_bits & 16L) != 0)) - { - return _Pragma; - } - else - { - return StringValues.Empty; - } + return _Pragma; } set { @@ -157,14 +122,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { get { - if (((_bits & 32L) != 0)) - { - return _Trailer; - } - else - { - return StringValues.Empty; - } + return _Trailer; } set { @@ -177,14 +135,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { get { - if (((_bits & 64L) != 0)) - { - return _TransferEncoding; - } - else - { - return StringValues.Empty; - } + return _TransferEncoding; } set { @@ -197,14 +148,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { get { - if (((_bits & 128L) != 0)) - { - return _Upgrade; - } - else - { - return StringValues.Empty; - } + return _Upgrade; } set { @@ -217,14 +161,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { get { - if (((_bits & 256L) != 0)) - { - return _Via; - } - else - { - return StringValues.Empty; - } + return _Via; } set { @@ -237,14 +174,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { get { - if (((_bits & 512L) != 0)) - { - return _Warning; - } - else - { - return StringValues.Empty; - } + return _Warning; } set { @@ -257,14 +187,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { get { - if (((_bits & 1024L) != 0)) - { - return _Allow; - } - else - { - return StringValues.Empty; - } + return _Allow; } set { @@ -277,14 +200,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { get { - if (((_bits & 2048L) != 0)) - { - return _ContentLength; - } - else - { - return StringValues.Empty; - } + return _ContentLength; } set { @@ -297,14 +213,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { get { - if (((_bits & 4096L) != 0)) - { - return _ContentType; - } - else - { - return StringValues.Empty; - } + return _ContentType; } set { @@ -317,14 +226,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { get { - if (((_bits & 8192L) != 0)) - { - return _ContentEncoding; - } - else - { - return StringValues.Empty; - } + return _ContentEncoding; } set { @@ -337,14 +239,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { get { - if (((_bits & 16384L) != 0)) - { - return _ContentLanguage; - } - else - { - return StringValues.Empty; - } + return _ContentLanguage; } set { @@ -357,14 +252,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { get { - if (((_bits & 32768L) != 0)) - { - return _ContentLocation; - } - else - { - return StringValues.Empty; - } + return _ContentLocation; } set { @@ -377,14 +265,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { get { - if (((_bits & 65536L) != 0)) - { - return _ContentMD5; - } - else - { - return StringValues.Empty; - } + return _ContentMD5; } set { @@ -397,14 +278,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { get { - if (((_bits & 131072L) != 0)) - { - return _ContentRange; - } - else - { - return StringValues.Empty; - } + return _ContentRange; } set { @@ -417,14 +291,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { get { - if (((_bits & 262144L) != 0)) - { - return _Expires; - } - else - { - return StringValues.Empty; - } + return _Expires; } set { @@ -437,14 +304,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { get { - if (((_bits & 524288L) != 0)) - { - return _LastModified; - } - else - { - return StringValues.Empty; - } + return _LastModified; } set { @@ -457,14 +317,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { get { - if (((_bits & 1048576L) != 0)) - { - return _Accept; - } - else - { - return StringValues.Empty; - } + return _Accept; } set { @@ -477,14 +330,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { get { - if (((_bits & 2097152L) != 0)) - { - return _AcceptCharset; - } - else - { - return StringValues.Empty; - } + return _AcceptCharset; } set { @@ -497,14 +343,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { get { - if (((_bits & 4194304L) != 0)) - { - return _AcceptEncoding; - } - else - { - return StringValues.Empty; - } + return _AcceptEncoding; } set { @@ -517,14 +356,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { get { - if (((_bits & 8388608L) != 0)) - { - return _AcceptLanguage; - } - else - { - return StringValues.Empty; - } + return _AcceptLanguage; } set { @@ -537,14 +369,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { get { - if (((_bits & 16777216L) != 0)) - { - return _Authorization; - } - else - { - return StringValues.Empty; - } + return _Authorization; } set { @@ -557,14 +382,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { get { - if (((_bits & 33554432L) != 0)) - { - return _Cookie; - } - else - { - return StringValues.Empty; - } + return _Cookie; } set { @@ -577,14 +395,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { get { - if (((_bits & 67108864L) != 0)) - { - return _Expect; - } - else - { - return StringValues.Empty; - } + return _Expect; } set { @@ -597,14 +408,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { get { - if (((_bits & 134217728L) != 0)) - { - return _From; - } - else - { - return StringValues.Empty; - } + return _From; } set { @@ -617,14 +421,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { get { - if (((_bits & 268435456L) != 0)) - { - return _Host; - } - else - { - return StringValues.Empty; - } + return _Host; } set { @@ -637,14 +434,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { get { - if (((_bits & 536870912L) != 0)) - { - return _IfMatch; - } - else - { - return StringValues.Empty; - } + return _IfMatch; } set { @@ -657,14 +447,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { get { - if (((_bits & 1073741824L) != 0)) - { - return _IfModifiedSince; - } - else - { - return StringValues.Empty; - } + return _IfModifiedSince; } set { @@ -677,14 +460,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { get { - if (((_bits & 2147483648L) != 0)) - { - return _IfNoneMatch; - } - else - { - return StringValues.Empty; - } + return _IfNoneMatch; } set { @@ -697,14 +473,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { get { - if (((_bits & 4294967296L) != 0)) - { - return _IfRange; - } - else - { - return StringValues.Empty; - } + return _IfRange; } set { @@ -717,14 +486,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { get { - if (((_bits & 8589934592L) != 0)) - { - return _IfUnmodifiedSince; - } - else - { - return StringValues.Empty; - } + return _IfUnmodifiedSince; } set { @@ -737,14 +499,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { get { - if (((_bits & 17179869184L) != 0)) - { - return _MaxForwards; - } - else - { - return StringValues.Empty; - } + return _MaxForwards; } set { @@ -757,14 +512,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { get { - if (((_bits & 34359738368L) != 0)) - { - return _ProxyAuthorization; - } - else - { - return StringValues.Empty; - } + return _ProxyAuthorization; } set { @@ -777,14 +525,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { get { - if (((_bits & 68719476736L) != 0)) - { - return _Referer; - } - else - { - return StringValues.Empty; - } + return _Referer; } set { @@ -797,14 +538,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { get { - if (((_bits & 137438953472L) != 0)) - { - return _Range; - } - else - { - return StringValues.Empty; - } + return _Range; } set { @@ -817,14 +551,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { get { - if (((_bits & 274877906944L) != 0)) - { - return _TE; - } - else - { - return StringValues.Empty; - } + return _TE; } set { @@ -837,14 +564,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { get { - if (((_bits & 549755813888L) != 0)) - { - return _Translate; - } - else - { - return StringValues.Empty; - } + return _Translate; } set { @@ -857,14 +577,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { get { - if (((_bits & 1099511627776L) != 0)) - { - return _UserAgent; - } - else - { - return StringValues.Empty; - } + return _UserAgent; } set { @@ -3206,6 +2919,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http if (((_bits & 1L) != 0)) { _bits &= ~1L; + _CacheControl = StringValues.Empty; return true; } else @@ -3219,6 +2933,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http if (((_bits & 131072L) != 0)) { _bits &= ~131072L; + _ContentRange = StringValues.Empty; return true; } else @@ -3232,6 +2947,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http if (((_bits & 524288L) != 0)) { _bits &= ~524288L; + _LastModified = StringValues.Empty; return true; } else @@ -3245,6 +2961,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http if (((_bits & 16777216L) != 0)) { _bits &= ~16777216L; + _Authorization = StringValues.Empty; return true; } else @@ -3258,6 +2975,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http if (((_bits & 2147483648L) != 0)) { _bits &= ~2147483648L; + _IfNoneMatch = StringValues.Empty; return true; } else @@ -3275,6 +2993,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http if (((_bits & 2L) != 0)) { _bits &= ~2L; + _Connection = StringValues.Empty; return true; } else @@ -3288,6 +3007,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http if (((_bits & 8L) != 0)) { _bits &= ~8L; + _KeepAlive = StringValues.Empty; return true; } else @@ -3301,6 +3021,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http if (((_bits & 1099511627776L) != 0)) { _bits &= ~1099511627776L; + _UserAgent = StringValues.Empty; return true; } else @@ -3318,6 +3039,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http if (((_bits & 4L) != 0)) { _bits &= ~4L; + _Date = StringValues.Empty; return true; } else @@ -3331,6 +3053,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http if (((_bits & 134217728L) != 0)) { _bits &= ~134217728L; + _From = StringValues.Empty; return true; } else @@ -3344,6 +3067,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http if (((_bits & 268435456L) != 0)) { _bits &= ~268435456L; + _Host = StringValues.Empty; return true; } else @@ -3361,6 +3085,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http if (((_bits & 16L) != 0)) { _bits &= ~16L; + _Pragma = StringValues.Empty; return true; } else @@ -3374,6 +3099,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http if (((_bits & 1048576L) != 0)) { _bits &= ~1048576L; + _Accept = StringValues.Empty; return true; } else @@ -3387,6 +3113,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http if (((_bits & 33554432L) != 0)) { _bits &= ~33554432L; + _Cookie = StringValues.Empty; return true; } else @@ -3400,6 +3127,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http if (((_bits & 67108864L) != 0)) { _bits &= ~67108864L; + _Expect = StringValues.Empty; return true; } else @@ -3417,6 +3145,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http if (((_bits & 32L) != 0)) { _bits &= ~32L; + _Trailer = StringValues.Empty; return true; } else @@ -3430,6 +3159,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http if (((_bits & 128L) != 0)) { _bits &= ~128L; + _Upgrade = StringValues.Empty; return true; } else @@ -3443,6 +3173,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http if (((_bits & 512L) != 0)) { _bits &= ~512L; + _Warning = StringValues.Empty; return true; } else @@ -3456,6 +3187,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http if (((_bits & 262144L) != 0)) { _bits &= ~262144L; + _Expires = StringValues.Empty; return true; } else @@ -3469,6 +3201,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http if (((_bits & 68719476736L) != 0)) { _bits &= ~68719476736L; + _Referer = StringValues.Empty; return true; } else @@ -3486,6 +3219,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http if (((_bits & 64L) != 0)) { _bits &= ~64L; + _TransferEncoding = StringValues.Empty; return true; } else @@ -3499,6 +3233,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http if (((_bits & 1073741824L) != 0)) { _bits &= ~1073741824L; + _IfModifiedSince = StringValues.Empty; return true; } else @@ -3516,6 +3251,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http if (((_bits & 256L) != 0)) { _bits &= ~256L; + _Via = StringValues.Empty; return true; } else @@ -3533,6 +3269,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http if (((_bits & 1024L) != 0)) { _bits &= ~1024L; + _Allow = StringValues.Empty; return true; } else @@ -3546,6 +3283,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http if (((_bits & 137438953472L) != 0)) { _bits &= ~137438953472L; + _Range = StringValues.Empty; return true; } else @@ -3563,6 +3301,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http if (((_bits & 2048L) != 0)) { _bits &= ~2048L; + _ContentLength = StringValues.Empty; return true; } else @@ -3576,6 +3315,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http if (((_bits & 2097152L) != 0)) { _bits &= ~2097152L; + _AcceptCharset = StringValues.Empty; return true; } else @@ -3593,6 +3333,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http if (((_bits & 4096L) != 0)) { _bits &= ~4096L; + _ContentType = StringValues.Empty; return true; } else @@ -3606,6 +3347,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http if (((_bits & 17179869184L) != 0)) { _bits &= ~17179869184L; + _MaxForwards = StringValues.Empty; return true; } else @@ -3623,6 +3365,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http if (((_bits & 8192L) != 0)) { _bits &= ~8192L; + _ContentEncoding = StringValues.Empty; return true; } else @@ -3636,6 +3379,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http if (((_bits & 16384L) != 0)) { _bits &= ~16384L; + _ContentLanguage = StringValues.Empty; return true; } else @@ -3649,6 +3393,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http if (((_bits & 32768L) != 0)) { _bits &= ~32768L; + _ContentLocation = StringValues.Empty; return true; } else @@ -3666,6 +3411,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http if (((_bits & 65536L) != 0)) { _bits &= ~65536L; + _ContentMD5 = StringValues.Empty; return true; } else @@ -3683,6 +3429,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http if (((_bits & 4194304L) != 0)) { _bits &= ~4194304L; + _AcceptEncoding = StringValues.Empty; return true; } else @@ -3696,6 +3443,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http if (((_bits & 8388608L) != 0)) { _bits &= ~8388608L; + _AcceptLanguage = StringValues.Empty; return true; } else @@ -3713,6 +3461,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http if (((_bits & 536870912L) != 0)) { _bits &= ~536870912L; + _IfMatch = StringValues.Empty; return true; } else @@ -3726,6 +3475,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http if (((_bits & 4294967296L) != 0)) { _bits &= ~4294967296L; + _IfRange = StringValues.Empty; return true; } else @@ -3743,6 +3493,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http if (((_bits & 8589934592L) != 0)) { _bits &= ~8589934592L; + _IfUnmodifiedSince = StringValues.Empty; return true; } else @@ -3756,6 +3507,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http if (((_bits & 34359738368L) != 0)) { _bits &= ~34359738368L; + _ProxyAuthorization = StringValues.Empty; return true; } else @@ -3773,6 +3525,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http if (((_bits & 274877906944L) != 0)) { _bits &= ~274877906944L; + _TE = StringValues.Empty; return true; } else @@ -3790,6 +3543,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http if (((_bits & 549755813888L) != 0)) { _bits &= ~549755813888L; + _Translate = StringValues.Empty; return true; } else @@ -5480,14 +5234,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { get { - if (((_bits & 1L) != 0)) - { - return _CacheControl; - } - else - { - return StringValues.Empty; - } + return _CacheControl; } set { @@ -5500,14 +5247,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { get { - if (((_bits & 2L) != 0)) - { - return _Connection; - } - else - { - return StringValues.Empty; - } + return _Connection; } set { @@ -5520,14 +5260,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { get { - if (((_bits & 4L) != 0)) - { - return _Date; - } - else - { - return StringValues.Empty; - } + return _Date; } set { @@ -5540,14 +5273,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { get { - if (((_bits & 8L) != 0)) - { - return _KeepAlive; - } - else - { - return StringValues.Empty; - } + return _KeepAlive; } set { @@ -5560,14 +5286,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { get { - if (((_bits & 16L) != 0)) - { - return _Pragma; - } - else - { - return StringValues.Empty; - } + return _Pragma; } set { @@ -5580,14 +5299,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { get { - if (((_bits & 32L) != 0)) - { - return _Trailer; - } - else - { - return StringValues.Empty; - } + return _Trailer; } set { @@ -5600,14 +5312,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { get { - if (((_bits & 64L) != 0)) - { - return _TransferEncoding; - } - else - { - return StringValues.Empty; - } + return _TransferEncoding; } set { @@ -5620,14 +5325,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { get { - if (((_bits & 128L) != 0)) - { - return _Upgrade; - } - else - { - return StringValues.Empty; - } + return _Upgrade; } set { @@ -5640,14 +5338,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { get { - if (((_bits & 256L) != 0)) - { - return _Via; - } - else - { - return StringValues.Empty; - } + return _Via; } set { @@ -5660,14 +5351,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { get { - if (((_bits & 512L) != 0)) - { - return _Warning; - } - else - { - return StringValues.Empty; - } + return _Warning; } set { @@ -5680,14 +5364,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { get { - if (((_bits & 1024L) != 0)) - { - return _Allow; - } - else - { - return StringValues.Empty; - } + return _Allow; } set { @@ -5700,14 +5377,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { get { - if (((_bits & 2048L) != 0)) - { - return _ContentLength; - } - else - { - return StringValues.Empty; - } + return _ContentLength; } set { @@ -5720,14 +5390,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { get { - if (((_bits & 4096L) != 0)) - { - return _ContentType; - } - else - { - return StringValues.Empty; - } + return _ContentType; } set { @@ -5740,14 +5403,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { get { - if (((_bits & 8192L) != 0)) - { - return _ContentEncoding; - } - else - { - return StringValues.Empty; - } + return _ContentEncoding; } set { @@ -5760,14 +5416,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { get { - if (((_bits & 16384L) != 0)) - { - return _ContentLanguage; - } - else - { - return StringValues.Empty; - } + return _ContentLanguage; } set { @@ -5780,14 +5429,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { get { - if (((_bits & 32768L) != 0)) - { - return _ContentLocation; - } - else - { - return StringValues.Empty; - } + return _ContentLocation; } set { @@ -5800,14 +5442,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { get { - if (((_bits & 65536L) != 0)) - { - return _ContentMD5; - } - else - { - return StringValues.Empty; - } + return _ContentMD5; } set { @@ -5820,14 +5455,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { get { - if (((_bits & 131072L) != 0)) - { - return _ContentRange; - } - else - { - return StringValues.Empty; - } + return _ContentRange; } set { @@ -5840,14 +5468,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { get { - if (((_bits & 262144L) != 0)) - { - return _Expires; - } - else - { - return StringValues.Empty; - } + return _Expires; } set { @@ -5860,14 +5481,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { get { - if (((_bits & 524288L) != 0)) - { - return _LastModified; - } - else - { - return StringValues.Empty; - } + return _LastModified; } set { @@ -5880,14 +5494,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { get { - if (((_bits & 1048576L) != 0)) - { - return _AcceptRanges; - } - else - { - return StringValues.Empty; - } + return _AcceptRanges; } set { @@ -5900,14 +5507,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { get { - if (((_bits & 2097152L) != 0)) - { - return _Age; - } - else - { - return StringValues.Empty; - } + return _Age; } set { @@ -5920,14 +5520,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { get { - if (((_bits & 4194304L) != 0)) - { - return _ETag; - } - else - { - return StringValues.Empty; - } + return _ETag; } set { @@ -5940,14 +5533,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { get { - if (((_bits & 8388608L) != 0)) - { - return _Location; - } - else - { - return StringValues.Empty; - } + return _Location; } set { @@ -5960,14 +5546,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { get { - if (((_bits & 16777216L) != 0)) - { - return _ProxyAutheticate; - } - else - { - return StringValues.Empty; - } + return _ProxyAutheticate; } set { @@ -5980,14 +5559,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { get { - if (((_bits & 33554432L) != 0)) - { - return _RetryAfter; - } - else - { - return StringValues.Empty; - } + return _RetryAfter; } set { @@ -6000,14 +5572,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { get { - if (((_bits & 67108864L) != 0)) - { - return _Server; - } - else - { - return StringValues.Empty; - } + return _Server; } set { @@ -6020,14 +5585,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { get { - if (((_bits & 134217728L) != 0)) - { - return _SetCookie; - } - else - { - return StringValues.Empty; - } + return _SetCookie; } set { @@ -6040,14 +5598,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { get { - if (((_bits & 268435456L) != 0)) - { - return _Vary; - } - else - { - return StringValues.Empty; - } + return _Vary; } set { @@ -6060,14 +5611,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { get { - if (((_bits & 536870912L) != 0)) - { - return _WWWAuthenticate; - } - else - { - return StringValues.Empty; - } + return _WWWAuthenticate; } set { @@ -7806,6 +7350,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http if (((_bits & 1L) != 0)) { _bits &= ~1L; + _CacheControl = StringValues.Empty; return true; } else @@ -7819,6 +7364,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http if (((_bits & 131072L) != 0)) { _bits &= ~131072L; + _ContentRange = StringValues.Empty; return true; } else @@ -7832,6 +7378,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http if (((_bits & 524288L) != 0)) { _bits &= ~524288L; + _LastModified = StringValues.Empty; return true; } else @@ -7845,6 +7392,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http if (((_bits & 1048576L) != 0)) { _bits &= ~1048576L; + _AcceptRanges = StringValues.Empty; return true; } else @@ -7862,6 +7410,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http if (((_bits & 2L) != 0)) { _bits &= ~2L; + _Connection = StringValues.Empty; return true; } else @@ -7875,6 +7424,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http if (((_bits & 8L) != 0)) { _bits &= ~8L; + _KeepAlive = StringValues.Empty; return true; } else @@ -7888,6 +7438,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http if (((_bits & 134217728L) != 0)) { _bits &= ~134217728L; + _SetCookie = StringValues.Empty; return true; } else @@ -7905,6 +7456,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http if (((_bits & 4L) != 0)) { _bits &= ~4L; + _Date = StringValues.Empty; return true; } else @@ -7918,6 +7470,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http if (((_bits & 4194304L) != 0)) { _bits &= ~4194304L; + _ETag = StringValues.Empty; return true; } else @@ -7931,6 +7484,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http if (((_bits & 268435456L) != 0)) { _bits &= ~268435456L; + _Vary = StringValues.Empty; return true; } else @@ -7948,6 +7502,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http if (((_bits & 16L) != 0)) { _bits &= ~16L; + _Pragma = StringValues.Empty; return true; } else @@ -7961,6 +7516,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http if (((_bits & 67108864L) != 0)) { _bits &= ~67108864L; + _Server = StringValues.Empty; return true; } else @@ -7978,6 +7534,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http if (((_bits & 32L) != 0)) { _bits &= ~32L; + _Trailer = StringValues.Empty; return true; } else @@ -7991,6 +7548,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http if (((_bits & 128L) != 0)) { _bits &= ~128L; + _Upgrade = StringValues.Empty; return true; } else @@ -8004,6 +7562,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http if (((_bits & 512L) != 0)) { _bits &= ~512L; + _Warning = StringValues.Empty; return true; } else @@ -8017,6 +7576,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http if (((_bits & 262144L) != 0)) { _bits &= ~262144L; + _Expires = StringValues.Empty; return true; } else @@ -8034,6 +7594,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http if (((_bits & 64L) != 0)) { _bits &= ~64L; + _TransferEncoding = StringValues.Empty; return true; } else @@ -8047,6 +7608,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http if (((_bits & 16777216L) != 0)) { _bits &= ~16777216L; + _ProxyAutheticate = StringValues.Empty; return true; } else @@ -8064,6 +7626,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http if (((_bits & 256L) != 0)) { _bits &= ~256L; + _Via = StringValues.Empty; return true; } else @@ -8077,6 +7640,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http if (((_bits & 2097152L) != 0)) { _bits &= ~2097152L; + _Age = StringValues.Empty; return true; } else @@ -8094,6 +7658,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http if (((_bits & 1024L) != 0)) { _bits &= ~1024L; + _Allow = StringValues.Empty; return true; } else @@ -8111,6 +7676,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http if (((_bits & 2048L) != 0)) { _bits &= ~2048L; + _ContentLength = StringValues.Empty; return true; } else @@ -8128,6 +7694,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http if (((_bits & 4096L) != 0)) { _bits &= ~4096L; + _ContentType = StringValues.Empty; return true; } else @@ -8145,6 +7712,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http if (((_bits & 8192L) != 0)) { _bits &= ~8192L; + _ContentEncoding = StringValues.Empty; return true; } else @@ -8158,6 +7726,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http if (((_bits & 16384L) != 0)) { _bits &= ~16384L; + _ContentLanguage = StringValues.Empty; return true; } else @@ -8171,6 +7740,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http if (((_bits & 32768L) != 0)) { _bits &= ~32768L; + _ContentLocation = StringValues.Empty; return true; } else @@ -8184,6 +7754,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http if (((_bits & 536870912L) != 0)) { _bits &= ~536870912L; + _WWWAuthenticate = StringValues.Empty; return true; } else @@ -8201,6 +7772,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http if (((_bits & 65536L) != 0)) { _bits &= ~65536L; + _ContentMD5 = StringValues.Empty; return true; } else @@ -8214,6 +7786,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http if (((_bits & 33554432L) != 0)) { _bits &= ~33554432L; + _RetryAfter = StringValues.Empty; return true; } else @@ -8231,6 +7804,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http if (((_bits & 8388608L) != 0)) { _bits &= ~8388608L; + _Location = StringValues.Empty; return true; } else diff --git a/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/KnownHeaders.cs b/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/KnownHeaders.cs index 03d2e2764a..d58b76bc5c 100644 --- a/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/KnownHeaders.cs +++ b/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/KnownHeaders.cs @@ -183,14 +183,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http {{ get {{ - if ({header.TestBit()}) - {{ - return _{header.Identifier}; - }} - else - {{ - return StringValues.Empty; - }} + return _{header.Identifier}; }} set {{ @@ -316,6 +309,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http if ({header.TestBit()}) {{ {header.ClearBit()}; + _{header.Identifier} = StringValues.Empty; return true; }} else From c42dace9e623cd93e0e5089cd5ddd14a21c86679 Mon Sep 17 00:00:00 2001 From: Louis DeJardin Date: Fri, 25 Sep 2015 12:36:01 -0700 Subject: [PATCH 0292/1662] consts looked like local vars --- .../Infrastructure/MemoryPool2.cs | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPool2.cs b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPool2.cs index 4a209c047d..271b091f68 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPool2.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPool2.cs @@ -11,30 +11,30 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure /// /// The gap between blocks' starting address. 4096 is chosen because most operating systems are 4k pages in size and alignment. /// - private const int blockStride = 4096; + private const int _blockStride = 4096; /// /// The last 64 bytes of a block are unused to prevent CPU from pre-fetching the next 64 byte into it's memory cache. /// See https://github.com/aspnet/KestrelHttpServer/issues/117 and https://www.youtube.com/watch?v=L7zSU9HI-6I /// - private const int blockUnused = 64; + private const int _blockUnused = 64; /// /// Allocating 32 contiguous blocks per slab makes the slab size 128k. This is larger than the 85k size which will place the memory /// in the large object heap. This means the GC will not try to relocate this array, so the fact it remains pinned does not negatively /// affect memory management's compactification. /// - private const int blockCount = 32; + private const int _blockCount = 32; /// /// 4096 - 64 gives you a blockLength of 4032 usable bytes per block. /// - private const int blockLength = blockStride - blockUnused; + private const int _blockLength = _blockStride - _blockUnused; /// /// 4096 * 32 gives you a slabLength of 128k contiguous bytes allocated per slab /// - private const int slabLength = blockStride * blockCount; + private const int _slabLength = _blockStride * _blockCount; /// /// Thread-safe collection of blocks which are currently in the pool. A slab will pre-allocate all of the block tracking objects @@ -61,7 +61,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure /// The block that is reserved for the called. It must be passed to Return when it is no longer being used. public MemoryPoolBlock2 Lease(int minimumSize) { - if (minimumSize > blockLength) + if (minimumSize > _blockLength) { // The requested minimumSize is actually larger then the usable memory of a single block. // Because this is the degenerate case, a one-time-use byte[] array and tracking object are allocated. @@ -93,18 +93,18 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure /// private void AllocateSlab() { - var slab = MemoryPoolSlab2.Create(slabLength); + var slab = MemoryPoolSlab2.Create(_slabLength); _slabs.Push(slab); var basePtr = slab.ArrayPtr; - var firstOffset = (blockStride - 1) - ((ushort)(basePtr + blockStride - 1) % blockStride); + var firstOffset = (_blockStride - 1) - ((ushort)(basePtr + _blockStride - 1) % _blockStride); for (var offset = firstOffset; - offset + blockLength <= slabLength; - offset += blockStride) + offset + _blockLength <= _slabLength; + offset += _blockStride) { var block = MemoryPoolBlock2.Create( - new ArraySegment(slab.Array, offset, blockLength), + new ArraySegment(slab.Array, offset, _blockLength), basePtr, this, slab); From f740616573513d745cc78f6645b52b1582e14df8 Mon Sep 17 00:00:00 2001 From: Louis DeJardin Date: Fri, 25 Sep 2015 12:37:02 -0700 Subject: [PATCH 0293/1662] disposedValue changed to _disposedValue Boilerplate code didn't have _ --- .../Infrastructure/Disposable.cs | 6 +++--- .../Infrastructure/MemoryPool2.cs | 6 +++--- .../Infrastructure/MemoryPoolSlab2.cs | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/Disposable.cs b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/Disposable.cs index b3fcbbb0a3..04d2dac312 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/Disposable.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/Disposable.cs @@ -11,7 +11,7 @@ namespace Microsoft.AspNet.Server.Kestrel public class Disposable : IDisposable { private Action _dispose; - private bool disposedValue = false; // To detect redundant calls + private bool _disposedValue = false; // To detect redundant calls public Disposable(Action dispose) { @@ -20,7 +20,7 @@ namespace Microsoft.AspNet.Server.Kestrel protected virtual void Dispose(bool disposing) { - if (!disposedValue) + if (!_disposedValue) { if (disposing) { @@ -28,7 +28,7 @@ namespace Microsoft.AspNet.Server.Kestrel } _dispose = null; - disposedValue = true; + _disposedValue = true; } } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPool2.cs b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPool2.cs index 271b091f68..0f1975689a 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPool2.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPool2.cs @@ -51,7 +51,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure /// /// This is part of implementing the IDisposable pattern. /// - private bool disposedValue = false; // To detect redundant calls + private bool _disposedValue = false; // To detect redundant calls /// /// Called to take a block from the pool. @@ -128,7 +128,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure protected virtual void Dispose(bool disposing) { - if (!disposedValue) + if (!_disposedValue) { if (disposing) { @@ -144,7 +144,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure // N/A: set large fields to null. - disposedValue = true; + _disposedValue = true; } } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolSlab2.cs b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolSlab2.cs index 6d277062e9..134bc147d2 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolSlab2.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolSlab2.cs @@ -39,7 +39,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure /// /// Part of the IDisposable implementation /// - private bool disposedValue = false; // To detect redundant calls + private bool _disposedValue = false; // To detect redundant calls public static MemoryPoolSlab2 Create(int length) { @@ -59,7 +59,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure protected virtual void Dispose(bool disposing) { - if (!disposedValue) + if (!_disposedValue) { if (disposing) { @@ -73,7 +73,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure // set large fields to null. Array = null; - disposedValue = true; + _disposedValue = true; } } From 318f3b7145a3aa96a5d90aad4e192d121b1bfb48 Mon Sep 17 00:00:00 2001 From: Louis DeJardin Date: Fri, 25 Sep 2015 13:01:54 -0700 Subject: [PATCH 0294/1662] Changing Trace.Assert to Debug.Assert * Also Debug.Assert for unreturned memory blocks --- src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs | 4 ++-- .../Infrastructure/MemoryPoolBlock2.cs | 3 +++ src/Microsoft.AspNet.Server.Kestrel/Networking/UvMemory.cs | 6 +++--- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs index 5c890807b6..0eed51d7d3 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs @@ -196,8 +196,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } // Now that the while loop has completed the following invariants should hold true: - Trace.Assert(_numBytesPreCompleted >= 0); - Trace.Assert(_numBytesPreCompleted <= _maxBytesPreCompleted); + Debug.Assert(_numBytesPreCompleted >= 0); + Debug.Assert(_numBytesPreCompleted <= _maxBytesPreCompleted); } } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolBlock2.cs b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolBlock2.cs index bb7eb5758c..c0c9fae183 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolBlock2.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolBlock2.cs @@ -77,6 +77,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure ~MemoryPoolBlock2() { + Debug.Assert(!_pinHandle.IsAllocated, "Ad-hoc memory block wasn't unpinned"); + Debug.Assert(Slab == null || !Slab.IsActive, "Block being garbage collected instead of returned to pool"); + if (_pinHandle.IsAllocated) { // if this is a one-time-use block, ensure that the GCHandle does not leak diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvMemory.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvMemory.cs index 051218ffef..a8389c39a2 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvMemory.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvMemory.cs @@ -77,9 +77,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking public void Validate(bool closed = false) { - Trace.Assert(closed || !IsClosed, "Handle is closed"); - Trace.Assert(!IsInvalid, "Handle is invalid"); - Trace.Assert(_threadId == Thread.CurrentThread.ManagedThreadId, "ThreadId is incorrect"); + Debug.Assert(closed || !IsClosed, "Handle is closed"); + Debug.Assert(!IsInvalid, "Handle is invalid"); + Debug.Assert(_threadId == Thread.CurrentThread.ManagedThreadId, "ThreadId is incorrect"); } unsafe public static THandle FromIntPtr(IntPtr handle) From 5070b8073e70eb145a78f07dae80609597fd5930 Mon Sep 17 00:00:00 2001 From: Louis DeJardin Date: Fri, 25 Sep 2015 14:17:09 -0700 Subject: [PATCH 0295/1662] Temporarily commenting out the Debug.Assert of block freeing Unit tests using ad-hoc contexts aren't guaranteed to dispose pools. That's kinda making unit tests fail, more or less, because Debug... --- .../Infrastructure/MemoryPoolBlock2.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolBlock2.cs b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolBlock2.cs index c0c9fae183..c6fd9bd7a3 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolBlock2.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolBlock2.cs @@ -78,7 +78,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure ~MemoryPoolBlock2() { Debug.Assert(!_pinHandle.IsAllocated, "Ad-hoc memory block wasn't unpinned"); - Debug.Assert(Slab == null || !Slab.IsActive, "Block being garbage collected instead of returned to pool"); + // Debug.Assert(Slab == null || !Slab.IsActive, "Block being garbage collected instead of returned to pool"); if (_pinHandle.IsAllocated) { From 7c46b2bd3b005fbd92cdbaf5cb02c6108f39a15f Mon Sep 17 00:00:00 2001 From: damianedwards Date: Wed, 9 Sep 2015 09:54:02 -0700 Subject: [PATCH 0296/1662] Use a timer to generate the value for the Date header in responses: - Doing it on each request is expensive - The Timer is started when the first request comes in and fires every second - Every request flips a bool so the Timer knows requests are coming in - The Timer stops itself after a period of no requests coming in (10 seconds) - #163 --- KestrelHttpServer.sln | 1 + .../Http/DateHeaderValueManager.cs | 145 ++++++++++++++++++ .../Http/Frame.cs | 2 +- .../Infrastructure/ISystemClock.cs | 18 +++ .../Infrastructure/SystemClock.cs | 24 +++ .../ServerFactory.cs | 10 +- .../ServiceContext.cs | 3 + .../project.json | 3 +- .../DateHeaderValueManagerTests.cs | 125 +++++++++++++++ .../TestHelpers/MockSystemClock.cs | 28 ++++ 10 files changed, 356 insertions(+), 3 deletions(-) create mode 100644 src/Microsoft.AspNet.Server.Kestrel/Http/DateHeaderValueManager.cs create mode 100644 src/Microsoft.AspNet.Server.Kestrel/Infrastructure/ISystemClock.cs create mode 100644 src/Microsoft.AspNet.Server.Kestrel/Infrastructure/SystemClock.cs create mode 100644 test/Microsoft.AspNet.Server.KestrelTests/DateHeaderValueManagerTests.cs create mode 100644 test/Microsoft.AspNet.Server.KestrelTests/TestHelpers/MockSystemClock.cs diff --git a/KestrelHttpServer.sln b/KestrelHttpServer.sln index 3de96d251c..f82dbec103 100644 --- a/KestrelHttpServer.sln +++ b/KestrelHttpServer.sln @@ -12,6 +12,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution build.cmd = build.cmd global.json = global.json makefile.shade = makefile.shade + NuGet.Config = NuGet.Config EndProjectSection EndProject Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "SampleApp", "samples\SampleApp\SampleApp.xproj", "{2C3CB3DC-EEBF-4F52-9E1C-4F2F972E76C3}" diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/DateHeaderValueManager.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/DateHeaderValueManager.cs new file mode 100644 index 0000000000..216ce37f10 --- /dev/null +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/DateHeaderValueManager.cs @@ -0,0 +1,145 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Threading; +using Microsoft.AspNet.Server.Kestrel.Infrastructure; + +namespace Microsoft.AspNet.Server.Kestrel.Http +{ + /// + /// Manages the generation of the date header value. + /// + public class DateHeaderValueManager : IDisposable + { + private readonly ISystemClock _systemClock; + private readonly TimeSpan _timeWithoutRequestsUntilIdle; + private readonly TimeSpan _timerInterval; + + private volatile string _dateValue; + private object _timerLocker = new object(); + private bool _isDisposed = false; + private bool _hadRequestsSinceLastTimerTick = false; + private Timer _dateValueTimer; + private DateTimeOffset _lastRequestSeen = DateTimeOffset.MinValue; + + /// + /// Initializes a new instance of the class. + /// + public DateHeaderValueManager() + : this( + systemClock: new SystemClock(), + timeWithoutRequestsUntilIdle: TimeSpan.FromSeconds(10), + timerInterval: TimeSpan.FromSeconds(1)) + { + + } + + // Internal for testing + internal DateHeaderValueManager( + ISystemClock systemClock, + TimeSpan timeWithoutRequestsUntilIdle, + TimeSpan timerInterval) + { + _systemClock = systemClock; + _timeWithoutRequestsUntilIdle = timeWithoutRequestsUntilIdle; + _timerInterval = timerInterval; + } + + /// + /// Returns a value representing the current server date/time for use in the HTTP "Date" response header + /// in accordance with http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.18 + /// + /// The value. + public string GetDateHeaderValue() + { + PumpTimer(); + + // See https://msdn.microsoft.com/en-us/library/az4se3k1(v=vs.110).aspx#RFC1123 for info on the format + // string used here. + // The null-coalesce here is to protect against returning null after Dispose() is called, at which + // point _dateValue will be null forever after. + return _dateValue ?? _systemClock.UtcNow.ToString("r"); + } + + /// + /// Releases all resources used by the current instance of . + /// + public void Dispose() + { + lock (_timerLocker) + { + if (_dateValueTimer != null) + { + DisposeTimer(); + } + + _isDisposed = true; + } + } + + private void PumpTimer() + { + _hadRequestsSinceLastTimerTick = true; + + // If we're already disposed we don't care about starting the timer again. This avoids us having to worry + // about requests in flight during dispose (not that that should actually happen) as those will just get + // SystemClock.UtcNow (aka "the slow way"). + if (!_isDisposed && _dateValueTimer == null) + { + lock (_timerLocker) + { + if (!_isDisposed && _dateValueTimer == null) + { + // Immediately assign the date value and start the timer again. We assign the value immediately + // here as the timer won't fire until the timer interval has passed and we want a value assigned + // inline now to serve requests that occur in the meantime. + _dateValue = _systemClock.UtcNow.ToString("r"); + _dateValueTimer = new Timer(UpdateDateValue, state: null, dueTime: _timerInterval, period: _timerInterval); + } + } + } + } + + // Called by the Timer (background) thread + private void UpdateDateValue(object state) + { + var now = _systemClock.UtcNow; + + // See http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.18 for required format of Date header + _dateValue = now.ToString("r"); + + if (_hadRequestsSinceLastTimerTick) + { + // We served requests since the last tick, reset the flag and return as we're still active + _hadRequestsSinceLastTimerTick = false; + _lastRequestSeen = now; + return; + } + + // No requests since the last timer tick, we need to check if we're beyond the idle threshold + var timeSinceLastRequestSeen = now - _lastRequestSeen; + if (timeSinceLastRequestSeen >= _timeWithoutRequestsUntilIdle) + { + // No requests since idle threshold so stop the timer if it's still running + if (_dateValueTimer != null) + { + lock (_timerLocker) + { + if (_dateValueTimer != null) + { + DisposeTimer(); + } + } + } + } + } + + private void DisposeTimer() + { + _dateValueTimer.Dispose(); + _dateValueTimer = null; + _dateValue = null; + } + } +} diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs index fdedb2ab19..bdd06735e6 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs @@ -101,7 +101,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { _responseHeaders.Reset(); _responseHeaders.HeaderServer = "Kestrel"; - _responseHeaders.HeaderDate = DateTime.UtcNow.ToString("r"); + _responseHeaders.HeaderDate = DateHeaderValueManager.GetDateHeaderValue(); } /// diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/ISystemClock.cs b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/ISystemClock.cs new file mode 100644 index 0000000000..c741621de4 --- /dev/null +++ b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/ISystemClock.cs @@ -0,0 +1,18 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; + +namespace Microsoft.AspNet.Server.Kestrel.Infrastructure +{ + /// + /// Abstracts the system clock to facilitate testing. + /// + internal interface ISystemClock + { + /// + /// Retrieves the current system time in UTC. + /// + DateTimeOffset UtcNow { get; } + } +} diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/SystemClock.cs b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/SystemClock.cs new file mode 100644 index 0000000000..c16d40bf6a --- /dev/null +++ b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/SystemClock.cs @@ -0,0 +1,24 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; + +namespace Microsoft.AspNet.Server.Kestrel.Infrastructure +{ + /// + /// Provides access to the normal system clock. + /// + internal class SystemClock : ISystemClock + { + /// + /// Retrieves the current system time in UTC. + /// + public DateTimeOffset UtcNow + { + get + { + return DateTimeOffset.UtcNow; + } + } + } +} diff --git a/src/Microsoft.AspNet.Server.Kestrel/ServerFactory.cs b/src/Microsoft.AspNet.Server.Kestrel/ServerFactory.cs index 36c1ab3952..d81f34885f 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/ServerFactory.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/ServerFactory.cs @@ -7,6 +7,7 @@ using System.Threading.Tasks; using Microsoft.AspNet.Hosting.Server; using Microsoft.AspNet.Http.Features; using Microsoft.AspNet.Server.Features; +using Microsoft.AspNet.Server.Kestrel.Http; using Microsoft.Dnx.Runtime; using Microsoft.Framework.Configuration; using Microsoft.Framework.Logging; @@ -53,9 +54,16 @@ namespace Microsoft.AspNet.Server.Kestrel try { var information = (KestrelServerInformation)serverFeatures.Get(); - var engine = new KestrelEngine(_libraryManager, new ServiceContext { AppShutdown = _appShutdownService, Log = new KestrelTrace(_logger) }); + var dateHeaderValueManager = new DateHeaderValueManager(); + var engine = new KestrelEngine(_libraryManager, new ServiceContext + { + AppShutdown = _appShutdownService, + Log = new KestrelTrace(_logger), + DateHeaderValueManager = dateHeaderValueManager + }); disposables.Push(engine); + disposables.Push(dateHeaderValueManager); if (information.ThreadCount < 0) { diff --git a/src/Microsoft.AspNet.Server.Kestrel/ServiceContext.cs b/src/Microsoft.AspNet.Server.Kestrel/ServiceContext.cs index 8e915dccb9..8a29d2e380 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/ServiceContext.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/ServiceContext.cs @@ -19,6 +19,7 @@ namespace Microsoft.AspNet.Server.Kestrel AppShutdown = context.AppShutdown; Memory = context.Memory; Log = context.Log; + DateHeaderValueManager = context.DateHeaderValueManager; } public IApplicationShutdown AppShutdown { get; set; } @@ -26,5 +27,7 @@ namespace Microsoft.AspNet.Server.Kestrel public IMemoryPool Memory { get; set; } public IKestrelTrace Log { get; set; } + + public DateHeaderValueManager DateHeaderValueManager { get; set; } } } diff --git a/src/Microsoft.AspNet.Server.Kestrel/project.json b/src/Microsoft.AspNet.Server.Kestrel/project.json index 787728d2d4..7d3b95fbda 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/project.json +++ b/src/Microsoft.AspNet.Server.Kestrel/project.json @@ -33,7 +33,8 @@ "System.Threading": "4.0.11-beta-*", "System.Threading.Tasks": "4.0.11-beta-*", "System.Threading.Thread": "4.0.0-beta-*", - "System.Threading.ThreadPool": "4.0.10-beta-*" + "System.Threading.ThreadPool": "4.0.10-beta-*", + "System.Threading.Timer": "4.0.1-beta-*" } } }, diff --git a/test/Microsoft.AspNet.Server.KestrelTests/DateHeaderValueManagerTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/DateHeaderValueManagerTests.cs new file mode 100644 index 0000000000..71c294caae --- /dev/null +++ b/test/Microsoft.AspNet.Server.KestrelTests/DateHeaderValueManagerTests.cs @@ -0,0 +1,125 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Threading.Tasks; +using Microsoft.AspNet.Server.Kestrel.Http; +using Microsoft.AspNet.Server.KestrelTests.TestHelpers; +using Xunit; + +namespace Microsoft.AspNet.Server.KestrelTests +{ + public class DateHeaderValueManagerTests + { + [Fact] + public void GetDateHeaderValue_ReturnsDateValueInRFC1123Format() + { + var now = DateTimeOffset.UtcNow; + var systemClock = new MockSystemClock + { + UtcNow = now + }; + var timeWithoutRequestsUntilIdle = TimeSpan.FromSeconds(1); + var timerInterval = TimeSpan.FromSeconds(10); + var dateHeaderValueManager = new DateHeaderValueManager(systemClock, timeWithoutRequestsUntilIdle, timerInterval); + string result; + + try + { + result = dateHeaderValueManager.GetDateHeaderValue(); + } + finally + { + dateHeaderValueManager.Dispose(); + } + + Assert.Equal(now.ToString("r"), result); + } + + [Fact] + public void GetDateHeaderValue_ReturnsCachedValueBetweenTimerTicks() + { + var now = DateTimeOffset.UtcNow; + var future = now.AddSeconds(10); + var systemClock = new MockSystemClock + { + UtcNow = now + }; + var timeWithoutRequestsUntilIdle = TimeSpan.FromSeconds(1); + var timerInterval = TimeSpan.FromSeconds(10); + var dateHeaderValueManager = new DateHeaderValueManager(systemClock, timeWithoutRequestsUntilIdle, timerInterval); + string result1; + string result2; + + try + { + result1 = dateHeaderValueManager.GetDateHeaderValue(); + systemClock.UtcNow = future; + result2 = dateHeaderValueManager.GetDateHeaderValue(); + } + finally + { + dateHeaderValueManager.Dispose(); + } + + Assert.Equal(now.ToString("r"), result1); + Assert.Equal(now.ToString("r"), result2); + Assert.Equal(1, systemClock.UtcNowCalled); + } + + [Fact] + public async Task GetDateHeaderValue_ReturnsUpdatedValueAfterIdle() + { + var now = DateTimeOffset.UtcNow; + var future = now.AddSeconds(10); + var systemClock = new MockSystemClock + { + UtcNow = now + }; + var timeWithoutRequestsUntilIdle = TimeSpan.FromMilliseconds(50); + var timerInterval = TimeSpan.FromMilliseconds(10); + var dateHeaderValueManager = new DateHeaderValueManager(systemClock, timeWithoutRequestsUntilIdle, timerInterval); + string result1; + string result2; + + try + { + result1 = dateHeaderValueManager.GetDateHeaderValue(); + systemClock.UtcNow = future; + // Wait for twice the idle timeout to ensure the timer is stopped + await Task.Delay(timeWithoutRequestsUntilIdle.Add(timeWithoutRequestsUntilIdle)); + result2 = dateHeaderValueManager.GetDateHeaderValue(); + } + finally + { + dateHeaderValueManager.Dispose(); + } + + Assert.Equal(now.ToString("r"), result1); + Assert.Equal(future.ToString("r"), result2); + Assert.True(systemClock.UtcNowCalled >= 2); + } + + [Fact] + public void GetDateHeaderValue_ReturnsDateValueAfterDisposed() + { + var now = DateTimeOffset.UtcNow; + var future = now.AddSeconds(10); + var systemClock = new MockSystemClock + { + UtcNow = now + }; + var timeWithoutRequestsUntilIdle = TimeSpan.FromSeconds(1); + var timerInterval = TimeSpan.FromSeconds(10); + var dateHeaderValueManager = new DateHeaderValueManager(systemClock, timeWithoutRequestsUntilIdle, timerInterval); + + var result1 = dateHeaderValueManager.GetDateHeaderValue(); + dateHeaderValueManager.Dispose(); + systemClock.UtcNow = future; + var result2 = dateHeaderValueManager.GetDateHeaderValue(); + + Assert.Equal(now.ToString("r"), result1); + Assert.Equal(future.ToString("r"), result2); + } + } +} diff --git a/test/Microsoft.AspNet.Server.KestrelTests/TestHelpers/MockSystemClock.cs b/test/Microsoft.AspNet.Server.KestrelTests/TestHelpers/MockSystemClock.cs new file mode 100644 index 0000000000..6dbf6e3556 --- /dev/null +++ b/test/Microsoft.AspNet.Server.KestrelTests/TestHelpers/MockSystemClock.cs @@ -0,0 +1,28 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using Microsoft.AspNet.Server.Kestrel.Infrastructure; + +namespace Microsoft.AspNet.Server.KestrelTests.TestHelpers +{ + public class MockSystemClock : ISystemClock + { + private DateTimeOffset _utcNow = DateTimeOffset.Now; + + public DateTimeOffset UtcNow + { + get + { + UtcNowCalled++; + return _utcNow; + } + set + { + _utcNow = value; + } + } + + public int UtcNowCalled { get; private set; } + } +} From 3c2408db68f0cd4f0d723845add546a86a488825 Mon Sep 17 00:00:00 2001 From: damianedwards Date: Thu, 24 Sep 2015 16:56:00 -0700 Subject: [PATCH 0297/1662] Fix tests after rebase --- .../Http/DateHeaderValueManager.cs | 2 +- .../FrameResponseHeadersTests.cs | 14 ++++++++------ .../TestDateHeaderValueManager.cs | 16 ++++++++++++++++ .../TestServiceContext.cs | 1 + 4 files changed, 26 insertions(+), 7 deletions(-) create mode 100644 test/Microsoft.AspNet.Server.KestrelTests/TestDateHeaderValueManager.cs diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/DateHeaderValueManager.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/DateHeaderValueManager.cs index 216ce37f10..04dc75f464 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/DateHeaderValueManager.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/DateHeaderValueManager.cs @@ -51,7 +51,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http /// in accordance with http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.18 /// /// The value. - public string GetDateHeaderValue() + public virtual string GetDateHeaderValue() { PumpTimer(); diff --git a/test/Microsoft.AspNet.Server.KestrelTests/FrameResponseHeadersTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/FrameResponseHeadersTests.cs index e97d76d142..b084b9547d 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/FrameResponseHeadersTests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/FrameResponseHeadersTests.cs @@ -14,7 +14,7 @@ namespace Microsoft.AspNet.Server.KestrelTests [Fact] public void InitialDictionaryContainsServerAndDate() { - var frame = new Frame(new ConnectionContext()); + var frame = new Frame(new ConnectionContext { DateHeaderValueManager = new DateHeaderValueManager() }); IDictionary headers = frame.ResponseHeaders; Assert.Equal(2, headers.Count); @@ -37,13 +37,15 @@ namespace Microsoft.AspNet.Server.KestrelTests [Fact] public void InitialEntriesCanBeCleared() { - IDictionary headers = new FrameResponseHeaders(); + var frame = new Frame(new ConnectionContext { DateHeaderValueManager = new DateHeaderValueManager() }); + + Assert.True(frame.ResponseHeaders.Count > 0); - headers.Clear(); + frame.ResponseHeaders.Clear(); - Assert.Equal(0, headers.Count); - Assert.False(headers.ContainsKey("Server")); - Assert.False(headers.ContainsKey("Date")); + Assert.Equal(0, frame.ResponseHeaders.Count); + Assert.False(frame.ResponseHeaders.ContainsKey("Server")); + Assert.False(frame.ResponseHeaders.ContainsKey("Date")); } } } diff --git a/test/Microsoft.AspNet.Server.KestrelTests/TestDateHeaderValueManager.cs b/test/Microsoft.AspNet.Server.KestrelTests/TestDateHeaderValueManager.cs new file mode 100644 index 0000000000..c69221b0ce --- /dev/null +++ b/test/Microsoft.AspNet.Server.KestrelTests/TestDateHeaderValueManager.cs @@ -0,0 +1,16 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using Microsoft.AspNet.Server.Kestrel.Http; + +namespace Microsoft.AspNet.Server.KestrelTests +{ + public class TestDateHeaderValueManager : DateHeaderValueManager + { + public override string GetDateHeaderValue() + { + return DateTimeOffset.UtcNow.ToString("r"); + } + } +} diff --git a/test/Microsoft.AspNet.Server.KestrelTests/TestServiceContext.cs b/test/Microsoft.AspNet.Server.KestrelTests/TestServiceContext.cs index 29b8cfb145..51fe80d8a9 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/TestServiceContext.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/TestServiceContext.cs @@ -8,6 +8,7 @@ namespace Microsoft.AspNet.Server.KestrelTests { AppShutdown = new ShutdownNotImplemented(); Log = new TestKestrelTrace(); + DateHeaderValueManager = new TestDateHeaderValueManager(); } } } From a7b65efa75d37a4a3b85a5fc35e69fd4a410798c Mon Sep 17 00:00:00 2001 From: damianedwards Date: Fri, 25 Sep 2015 14:58:07 -0700 Subject: [PATCH 0298/1662] CR feedback --- .../Http/DateHeaderValueManager.cs | 22 +++++++++---------- .../Infrastructure/Constants.cs | 6 +++++ .../DateHeaderValueManagerTests.cs | 15 +++++++------ 3 files changed, 25 insertions(+), 18 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/DateHeaderValueManager.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/DateHeaderValueManager.cs index 04dc75f464..c471067eca 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/DateHeaderValueManager.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/DateHeaderValueManager.cs @@ -59,7 +59,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http // string used here. // The null-coalesce here is to protect against returning null after Dispose() is called, at which // point _dateValue will be null forever after. - return _dateValue ?? _systemClock.UtcNow.ToString("r"); + return _dateValue ?? _systemClock.UtcNow.ToString(Constants.RFC1123DateFormat); } /// @@ -69,11 +69,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { lock (_timerLocker) { - if (_dateValueTimer != null) - { - DisposeTimer(); - } - + DisposeTimer(); + _isDisposed = true; } } @@ -94,7 +91,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http // Immediately assign the date value and start the timer again. We assign the value immediately // here as the timer won't fire until the timer interval has passed and we want a value assigned // inline now to serve requests that occur in the meantime. - _dateValue = _systemClock.UtcNow.ToString("r"); + _dateValue = _systemClock.UtcNow.ToString(Constants.RFC1123DateFormat); _dateValueTimer = new Timer(UpdateDateValue, state: null, dueTime: _timerInterval, period: _timerInterval); } } @@ -107,7 +104,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http var now = _systemClock.UtcNow; // See http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.18 for required format of Date header - _dateValue = now.ToString("r"); + _dateValue = now.ToString(Constants.RFC1123DateFormat); if (_hadRequestsSinceLastTimerTick) { @@ -137,9 +134,12 @@ namespace Microsoft.AspNet.Server.Kestrel.Http private void DisposeTimer() { - _dateValueTimer.Dispose(); - _dateValueTimer = null; - _dateValue = null; + if (_dateValueTimer != null) + { + _dateValueTimer.Dispose(); + _dateValueTimer = null; + _dateValue = null; + } } } } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/Constants.cs b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/Constants.cs index 0f4b72424e..9b72df3361 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/Constants.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/Constants.cs @@ -14,5 +14,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure /// Prefix of host name used to specify Unix sockets in the configuration. /// public const string UnixPipeHostPrefix = "unix:/"; + + /// + /// DateTime format string for RFC1123. See https://msdn.microsoft.com/en-us/library/az4se3k1(v=vs.110).aspx#RFC1123 + /// for info on the format. + /// + public const string RFC1123DateFormat = "r"; } } diff --git a/test/Microsoft.AspNet.Server.KestrelTests/DateHeaderValueManagerTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/DateHeaderValueManagerTests.cs index 71c294caae..ca4fd8ff01 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/DateHeaderValueManagerTests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/DateHeaderValueManagerTests.cs @@ -4,6 +4,7 @@ using System; using System.Threading.Tasks; using Microsoft.AspNet.Server.Kestrel.Http; +using Microsoft.AspNet.Server.Kestrel.Infrastructure; using Microsoft.AspNet.Server.KestrelTests.TestHelpers; using Xunit; @@ -33,7 +34,7 @@ namespace Microsoft.AspNet.Server.KestrelTests dateHeaderValueManager.Dispose(); } - Assert.Equal(now.ToString("r"), result); + Assert.Equal(now.ToString(Constants.RFC1123DateFormat), result); } [Fact] @@ -62,8 +63,8 @@ namespace Microsoft.AspNet.Server.KestrelTests dateHeaderValueManager.Dispose(); } - Assert.Equal(now.ToString("r"), result1); - Assert.Equal(now.ToString("r"), result2); + Assert.Equal(now.ToString(Constants.RFC1123DateFormat), result1); + Assert.Equal(now.ToString(Constants.RFC1123DateFormat), result2); Assert.Equal(1, systemClock.UtcNowCalled); } @@ -95,8 +96,8 @@ namespace Microsoft.AspNet.Server.KestrelTests dateHeaderValueManager.Dispose(); } - Assert.Equal(now.ToString("r"), result1); - Assert.Equal(future.ToString("r"), result2); + Assert.Equal(now.ToString(Constants.RFC1123DateFormat), result1); + Assert.Equal(future.ToString(Constants.RFC1123DateFormat), result2); Assert.True(systemClock.UtcNowCalled >= 2); } @@ -118,8 +119,8 @@ namespace Microsoft.AspNet.Server.KestrelTests systemClock.UtcNow = future; var result2 = dateHeaderValueManager.GetDateHeaderValue(); - Assert.Equal(now.ToString("r"), result1); - Assert.Equal(future.ToString("r"), result2); + Assert.Equal(now.ToString(Constants.RFC1123DateFormat), result1); + Assert.Equal(future.ToString(Constants.RFC1123DateFormat), result2); } } } From 1718b69f2249d8889d7d32ab61f68e731ef19145 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Sat, 26 Sep 2015 00:01:29 +0100 Subject: [PATCH 0299/1662] Fast path header enumerator Use strongly typed enumerable as interface's allocates. --- .../Http/Frame.cs | 64 +++++++++---------- 1 file changed, 31 insertions(+), 33 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs index bdd06735e6..09ba0f1171 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs @@ -418,7 +418,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http var status = ReasonPhrases.ToStatus(StatusCode, ReasonPhrase); - var responseHeader = CreateResponseHeader(status, appCompleted, ResponseHeaders); + var responseHeader = CreateResponseHeader(status, appCompleted); SocketOutput.Write(responseHeader.Item1, immediate: immediate); responseHeader.Item2.Dispose(); } @@ -461,8 +461,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http private Tuple, IDisposable> CreateResponseHeader( string status, - bool appCompleted, - IEnumerable> headers) + bool appCompleted) { var writer = new MemoryPoolTextWriter(Memory); writer.Write(HttpVersion); @@ -474,42 +473,41 @@ namespace Microsoft.AspNet.Server.Kestrel.Http var hasConnection = false; var hasTransferEncoding = false; var hasContentLength = false; - if (headers != null) + + foreach (var header in _responseHeaders) { - foreach (var header in headers) + var isConnection = false; + if (!hasConnection && + string.Equals(header.Key, "Connection", StringComparison.OrdinalIgnoreCase)) { - var isConnection = false; - if (!hasConnection && - string.Equals(header.Key, "Connection", StringComparison.OrdinalIgnoreCase)) - { - hasConnection = isConnection = true; - } - else if (!hasTransferEncoding && - string.Equals(header.Key, "Transfer-Encoding", StringComparison.OrdinalIgnoreCase)) - { - hasTransferEncoding = true; - } - else if (!hasContentLength && - string.Equals(header.Key, "Content-Length", StringComparison.OrdinalIgnoreCase)) - { - hasContentLength = true; - } + hasConnection = isConnection = true; + } + else if (!hasTransferEncoding && + string.Equals(header.Key, "Transfer-Encoding", StringComparison.OrdinalIgnoreCase)) + { + hasTransferEncoding = true; + } + else if (!hasContentLength && + string.Equals(header.Key, "Content-Length", StringComparison.OrdinalIgnoreCase)) + { + hasContentLength = true; + } - foreach (var value in header.Value) - { - writer.Write(header.Key); - writer.Write(':'); - writer.Write(' '); - writer.Write(value); - writer.Write('\r'); - writer.Write('\n'); + foreach (var value in header.Value) + { + writer.Write(header.Key); + writer.Write(':'); + writer.Write(' '); + writer.Write(value); + writer.Write('\r'); + writer.Write('\n'); - if (isConnection && value.IndexOf("close", StringComparison.OrdinalIgnoreCase) != -1) - { - _keepAlive = false; - } + if (isConnection && value.IndexOf("close", StringComparison.OrdinalIgnoreCase) != -1) + { + _keepAlive = false; } } + } if (_keepAlive && !hasTransferEncoding && !hasContentLength) From f0137b7b9ea25ee4769931da1e8d255a47605e85 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Fri, 25 Sep 2015 15:53:30 -0700 Subject: [PATCH 0300/1662] Bind to specific IP addresses if provided with any This still only applies to IPv4. #98 --- .../Http/TcpListener.cs | 2 +- .../Http/TcpListenerPrimary.cs | 2 +- .../Networking/UvTcpHandle.cs | 28 ++++++++++++++++++- .../CreateIPEndpointTests.cs | 25 +++++++++++++++++ .../MultipleLoopTests.cs | 2 +- .../NetworkingTests.cs | 8 +++--- 6 files changed, 59 insertions(+), 8 deletions(-) create mode 100644 test/Microsoft.AspNet.Server.KestrelTests/CreateIPEndpointTests.cs diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/TcpListener.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/TcpListener.cs index 2b8e4ea527..ba920f34aa 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/TcpListener.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/TcpListener.cs @@ -25,7 +25,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { var socket = new UvTcpHandle(Log); socket.Init(Thread.Loop, Thread.QueueCloseHandle); - socket.Bind(new IPEndPoint(IPAddress.Any, port)); + socket.Bind(host, port); socket.Listen(Constants.ListenBacklog, ConnectionCallback, this); return socket; } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/TcpListenerPrimary.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/TcpListenerPrimary.cs index af4495784d..cc4bb451f8 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/TcpListenerPrimary.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/TcpListenerPrimary.cs @@ -25,7 +25,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { var socket = new UvTcpHandle(Log); socket.Init(Thread.Loop, Thread.QueueCloseHandle); - socket.Bind(new IPEndPoint(IPAddress.Any, port)); + socket.Bind(host, port); socket.Listen(Constants.ListenBacklog, ConnectionCallback, this); return socket; } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvTcpHandle.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvTcpHandle.cs index d99f225bd1..55681bfbe5 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvTcpHandle.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvTcpHandle.cs @@ -33,8 +33,10 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking _uv.tcp_init(loop, this); } - public void Bind(IPEndPoint endpoint) + public void Bind(string host, int port) { + var endpoint = CreateIPEndpoint(host, port); + Libuv.sockaddr addr; var addressText = endpoint.Address.ToString(); @@ -58,5 +60,29 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking { _uv.tcp_open(this, hSocket); } + + /// + /// Returns an for the given host an port. + /// If the host parameter isn't "localhost" or an IP address, use IPAddress.Any. + /// + public static IPEndPoint CreateIPEndpoint(string host, int port) + { + // TODO: IPv6 support + IPAddress ip; + + if (!IPAddress.TryParse(host, out ip)) + { + if (string.Equals(host, "localhost", StringComparison.OrdinalIgnoreCase)) + { + ip = IPAddress.Loopback; + } + else + { + ip = IPAddress.Any; + } + } + + return new IPEndPoint(ip, port); + } } } diff --git a/test/Microsoft.AspNet.Server.KestrelTests/CreateIPEndpointTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/CreateIPEndpointTests.cs new file mode 100644 index 0000000000..716a528721 --- /dev/null +++ b/test/Microsoft.AspNet.Server.KestrelTests/CreateIPEndpointTests.cs @@ -0,0 +1,25 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System.Net; +using Microsoft.AspNet.Server.Kestrel.Networking; +using Xunit; + +namespace Microsoft.AspNet.Server.KestrelTests +{ + public class CreateIPEndpointTests + { + [Theory] + [InlineData("localhost", "127.0.0.1")] + [InlineData("10.10.10.10", "10.10.10.10")] + [InlineData("randomhost", "0.0.0.0")] + public void CorrectIPEndpointsAreCreated(string host, string expectedAddress) + { + // "0.0.0.0" is IPAddress.Any + var endpoint = UvTcpHandle.CreateIPEndpoint(host, 5000); + Assert.NotNull(endpoint); + Assert.Equal(IPAddress.Parse(expectedAddress), endpoint.Address); + Assert.Equal(5000, endpoint.Port); + } + } +} diff --git a/test/Microsoft.AspNet.Server.KestrelTests/MultipleLoopTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/MultipleLoopTests.cs index 3da9c93f4a..4e8c0fddd6 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/MultipleLoopTests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/MultipleLoopTests.cs @@ -166,7 +166,7 @@ namespace Microsoft.AspNet.Server.KestrelTests var serverListenTcp = new UvTcpHandle(_logger); serverListenTcp.Init(loop); - serverListenTcp.Bind(new IPEndPoint(0, 54321)); + serverListenTcp.Bind("0.0.0.0", 54321); serverListenTcp.Listen(128, (_1, status, error, _2) => { var serverConnectionTcp = new UvTcpHandle(_logger); diff --git a/test/Microsoft.AspNet.Server.KestrelTests/NetworkingTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/NetworkingTests.cs index 5c4a47f9c0..8d9eab7df7 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/NetworkingTests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/NetworkingTests.cs @@ -81,7 +81,7 @@ namespace Microsoft.AspNet.Server.KestrelTests loop.Init(_uv); var tcp = new UvTcpHandle(_logger); tcp.Init(loop); - tcp.Bind(new IPEndPoint(IPAddress.Loopback, 0)); + tcp.Bind("localhost", 0); tcp.Dispose(); loop.Run(); loop.Dispose(); @@ -95,7 +95,7 @@ namespace Microsoft.AspNet.Server.KestrelTests loop.Init(_uv); var tcp = new UvTcpHandle(_logger); tcp.Init(loop); - tcp.Bind(new IPEndPoint(IPAddress.Loopback, 54321)); + tcp.Bind("localhost", 54321); tcp.Listen(10, (stream, status, error, state) => { var tcp2 = new UvTcpHandle(_logger); @@ -132,7 +132,7 @@ namespace Microsoft.AspNet.Server.KestrelTests loop.Init(_uv); var tcp = new UvTcpHandle(_logger); tcp.Init(loop); - tcp.Bind(new IPEndPoint(IPAddress.Loopback, 54321)); + tcp.Bind("localhost", 54321); tcp.Listen(10, (_, status, error, state) => { Console.WriteLine("Connected"); @@ -188,7 +188,7 @@ namespace Microsoft.AspNet.Server.KestrelTests loop.Init(_uv); var tcp = new UvTcpHandle(_logger); tcp.Init(loop); - tcp.Bind(new IPEndPoint(IPAddress.Loopback, 54321)); + tcp.Bind("localhost", 54321); tcp.Listen(10, (_, status, error, state) => { Console.WriteLine("Connected"); From e3f141fcde792cdd1464cb594181e47fe6b6dab4 Mon Sep 17 00:00:00 2001 From: Chris R Date: Sat, 26 Sep 2015 06:56:54 -0700 Subject: [PATCH 0301/1662] #227 Fix OverflowException in MemoryPool --- .../Infrastructure/MemoryPool2.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPool2.cs b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPool2.cs index 0f1975689a..2ee01c0d10 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPool2.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPool2.cs @@ -97,7 +97,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure _slabs.Push(slab); var basePtr = slab.ArrayPtr; - var firstOffset = (_blockStride - 1) - ((ushort)(basePtr + _blockStride - 1) % _blockStride); + var firstOffset = (int)((_blockStride - 1) - ((ulong)(basePtr + _blockStride - 1) % _blockStride)); for (var offset = firstOffset; offset + _blockLength <= _slabLength; From d2f282f54fe6045efc34a462d0271316fe96b0ac Mon Sep 17 00:00:00 2001 From: moozzyk Date: Sat, 26 Sep 2015 15:04:45 -0700 Subject: [PATCH 0302/1662] Consuming Libuv from NuGet package Fixes #50 --- .gitignore | 1 + KestrelHttpServer.sln | 7 +++ .../KestrelEngine.cs | 10 ++--- .../native/darwin/universal/libuv.dylib | Bin 273620 -> 0 bytes .../native/windows/amd64/libuv.dll | Bin 159232 -> 0 bytes .../native/windows/x86/libuv.dll | Bin 133120 -> 0 bytes .../project.json | 22 +++++++-- .../MultipleLoopTests.cs | 6 +-- ...ft.AspNet.Server.Kestrel.LibuvCopier.xproj | 20 +++++++++ .../Program.cs | 42 ++++++++++++++++++ .../project.json | 30 +++++++++++++ 11 files changed, 126 insertions(+), 12 deletions(-) delete mode 100644 src/Microsoft.AspNet.Server.Kestrel/native/darwin/universal/libuv.dylib delete mode 100644 src/Microsoft.AspNet.Server.Kestrel/native/windows/amd64/libuv.dll delete mode 100644 src/Microsoft.AspNet.Server.Kestrel/native/windows/x86/libuv.dll create mode 100644 tools/Microsoft.AspNet.Server.Kestrel.LibuvCopier/Microsoft.AspNet.Server.Kestrel.LibuvCopier.xproj create mode 100644 tools/Microsoft.AspNet.Server.Kestrel.LibuvCopier/Program.cs create mode 100644 tools/Microsoft.AspNet.Server.Kestrel.LibuvCopier/project.json diff --git a/.gitignore b/.gitignore index 0042f1e9e0..64f87ceb6d 100644 --- a/.gitignore +++ b/.gitignore @@ -26,3 +26,4 @@ nuget.exe *.*sdf *.ipch project.lock.json +runtimes/ \ No newline at end of file diff --git a/KestrelHttpServer.sln b/KestrelHttpServer.sln index f82dbec103..8b0d78f607 100644 --- a/KestrelHttpServer.sln +++ b/KestrelHttpServer.sln @@ -31,6 +31,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tools", "tools", "{327F7880 EndProject Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.StandardsPolice", "tools\Microsoft.StandardsPolice\Microsoft.StandardsPolice.xproj", "{82295647-7C1C-4671-BAB6-0FEF58F949EC}" EndProject +Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.Server.Kestrel.LibuvCopier", "tools\Microsoft.AspNet.Server.Kestrel.LibuvCopier\Microsoft.AspNet.Server.Kestrel.LibuvCopier.xproj", "{8CBA6FE3-3CC9-4420-8AA3-123E983734C2}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -61,6 +63,10 @@ Global {82295647-7C1C-4671-BAB6-0FEF58F949EC}.Debug|Any CPU.Build.0 = Debug|Any CPU {82295647-7C1C-4671-BAB6-0FEF58F949EC}.Release|Any CPU.ActiveCfg = Release|Any CPU {82295647-7C1C-4671-BAB6-0FEF58F949EC}.Release|Any CPU.Build.0 = Release|Any CPU + {8CBA6FE3-3CC9-4420-8AA3-123E983734C2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {8CBA6FE3-3CC9-4420-8AA3-123E983734C2}.Debug|Any CPU.Build.0 = Debug|Any CPU + {8CBA6FE3-3CC9-4420-8AA3-123E983734C2}.Release|Any CPU.ActiveCfg = Release|Any CPU + {8CBA6FE3-3CC9-4420-8AA3-123E983734C2}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -72,5 +78,6 @@ Global {B35D4D31-E74C-4646-8A11-7A7A40F0021E} = {8A3D00B8-1CCF-4BE6-A060-11104CE2D9CE} {BD2D4D29-1BD9-40D0-BB31-337D5416B63C} = {327F7880-D9AF-46BD-B45C-3B7E34A01DFD} {82295647-7C1C-4671-BAB6-0FEF58F949EC} = {327F7880-D9AF-46BD-B45C-3B7E34A01DFD} + {8CBA6FE3-3CC9-4420-8AA3-123E983734C2} = {327F7880-D9AF-46BD-B45C-3B7E34A01DFD} EndGlobalSection EndGlobal diff --git a/src/Microsoft.AspNet.Server.Kestrel/KestrelEngine.cs b/src/Microsoft.AspNet.Server.Kestrel/KestrelEngine.cs index 94f5d74925..6026072e16 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/KestrelEngine.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/KestrelEngine.cs @@ -34,22 +34,22 @@ namespace Microsoft.AspNet.Server.Kestrel { var architecture = IntPtr.Size == 4 ? "x86" - : "amd64"; + : "x64"; libraryPath = Path.Combine( libraryPath, + "runtimes", + "win7-" + architecture, "native", - "windows", - architecture, "libuv.dll"); } else if (Libuv.IsDarwin) { libraryPath = Path.Combine( libraryPath, + "runtimes", + "osx", "native", - "darwin", - "universal", "libuv.dylib"); } else diff --git a/src/Microsoft.AspNet.Server.Kestrel/native/darwin/universal/libuv.dylib b/src/Microsoft.AspNet.Server.Kestrel/native/darwin/universal/libuv.dylib deleted file mode 100644 index cb7ccee0086477d9d482c5396df627f6ac58cc5a..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 273620 zcmeFa3w%_?+4#Q;2`mygK>?#8#)>x7TVk;$0yRsr;Vf(*Hj2@TL{Y?gqhwcNxdk_? z9FMECRcl+VwAN~?zNM|$$TbmUgO?i7R=fgUCtYmu7C?~weV;jJHy5l*`}X(0e8?xW zb2)Q;=9y=ndFGj!r}nK_$2I} z-@ShGdON8Hy9vbq#r2zh?KO3s4enXLCHe~fdiVw3(zqH3Mk zYkr4x$xEEmrd@h*_~OpMp76_e^J{XWh`(!oohcpHv}u>rb&lHo`(vw{-(Bf}NwTiv z!l`{{u7W2fX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.Server.Kestrel/native/windows/amd64/libuv.dll b/src/Microsoft.AspNet.Server.Kestrel/native/windows/amd64/libuv.dll deleted file mode 100644 index 60923dcdb9d0aaa2a00ddce30cb28b59da73d7f3..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 159232 zcmd?S3w%_?^}xS*k>$AoT|h;N8Z`=PG`0p2-3Oo)b|orG!Y0Dy zx)oo=T3c!B10Stctprd>2qpnk9=`C6ue$4MMXV4|x&QB(d++WBl9oPx|Ih#P`R9|_ znLBsp%*;7w&YU^(xD^*Ja%H((u56rXx?GL;^5;{(|NJK}!{zEXbVWbcvpruqyfGvA z%HiiuyK+|kjG5P7G4s-2s0!{=8y?*2zkT-Ctyk@H`8aWQ`Hxi_u)m3m(FqUA4t@d5SRsC+Gd_Nse% zzURXiR*lC0>#fheXej^r7w=a7=v9{gqIy2($|=*NtnOM?S?+ROerpd`X5X3TIcc`J zj>zww+0W&AlLr6JiVeO?I8TLZ30dJxm#c^MI_bNfB2tjcU#6=%naR#etOdmJB%Q<* zolHJ2{@6^HPYPI+>Dns(j7(STP<-ca2~Y`d^klk9oVYIhyu3`;-Rbe$GF*AN=@Fg7 zCxm`p6C&!hH|#1)+wFEZDf3;f>Jw&Oerf1Z0@o4?OxFzjckt8xe6Z6ARx;Pt-n^)$ zZT!2&$xrIf=W;cjFvCiy+DKbnhw(nRPdeWTGiS}5!YhRnaHHT|)m6HmPrsIg)ueST zvC~c8Ctaz${{Q2jrjK(6qow(6rFlYKE$Yu}E3L{W7|>ms;UBE&rG-J=RooQR{exRx z_MLaW|6KohTI9>Z9sVj`x$#lJhy{%=G~=64-{K}MvZl~~v47Gf7q@8oq=HHNFxgY>j>Y^A2Vi<<)aSv<^dQm^Je zg;#fbEx+Onm1}8!XmDifhr0EU5$?Uz7s}O)u|=ll)}o8sNf+3DF(;YGzCA=?A;QI|CyJUw=SAAKX|V`DhKvBy-Sc2^ec*4{wGG^r6%s z^-Ag>jHVfzK<3F5O7pe_qw``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W2w>@qlrfsny&KTH6@QO_l|gMOX{gTeezeS)aAO1UtYN)`QjXV>I zcTHc-0L@TP#iX&r`a3~00~TPvX0s+*J6XF$`@QxIB-ABBg3w3kFI*4(P=vmfhn-*@ zwA^Qee+s){C%Zy7NH-KVV5e@jZmw=VR@oKMwbo(39V_OEH$m@Bf8oEw4czYQY%nuDGMM zgr#Pcb&d5!jMLlDL$+FXSoc}K!8-FRR+=uhSX)nw+%+~G^z27qjsFsy+11|L zeg$^odf4Ibv%hHHVBc)tXa5=d7<>l+JUI+B)@!zEZq+`Iy;x5{1zWmB7!NxIX{*aY z!Iy>Zy1qKA&Y_zDs=cavPxlGeQ7;zd zq(3q9uF}tetgqAGhyC)a`fv3ah6#qL2A|=6!!xiFZ#C?O*4YM0)(!T@%V2%H3bw}^ zjB2A~v=~PlGaw=IjW-#Kuy1z5iuEC6^^fLwSl9AEztxuKEgtJ!>vPsOU|)>Jp7svg zTd+p7*^b-(wAI*`VlRtMu8qQb0Prp%u6?U?wYqxU670=Z=pKQ#wMMrVoIvLRbQ(Zs z0SBOa9nrPJc6CNa28)5nOLpOAQ>}R=UpZ*C01|f>67id)9;jBS@m=lz2Y>$y;sD== diff --git a/src/Microsoft.AspNet.Server.Kestrel/project.json b/src/Microsoft.AspNet.Server.Kestrel/project.json index 7d3b95fbda..2efa65204c 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/project.json +++ b/src/Microsoft.AspNet.Server.Kestrel/project.json @@ -13,6 +13,14 @@ "Microsoft.StandardsPolice": { "version": "1.0.0-*", "type": "build" + }, + "Microsoft.AspNet.Internal.libuv-Darwin": { + "version": "1.0.0-*", + "type":"build" + }, + "Microsoft.AspNet.Internal.libuv-Windows": { + "version": "1.0.0-*", + "type": "build" } }, "frameworks": { @@ -44,13 +52,19 @@ "scripts": { "prepare": [ "dnu restore ../../tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode", - "dnx --appbase ../../tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode Microsoft.Dnx.ApplicationHost run Http/FrameHeaders.Generated.cs" + "dnx -p ../../tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode run Http/FrameHeaders.Generated.cs" + ], + "postrestore": [ + "dnu restore ../../tools/Microsoft.AspNet.Server.Kestrel.LibuvCopier", + "dnx -p ../../tools/Microsoft.AspNet.Server.Kestrel.LibuvCopier run" ] }, "packInclude": { "/": "../../content/thirdpartynotices.txt", - "native/darwin/universal/": "native/darwin/universal/*", - "native/windows/amd64/": "native/windows/amd64/*", - "native/windows/x86/": "native/windows/x86/*" + "runtimes/win7-x64/native/": "runtimes/win7-x64/native/*", + "runtimes/win7-x86/native/": "runtimes/win7-x86/native/*", + "runtimes/win10-arm/native/": "runtimes/win10-arm/native/*", + "runtimes/osx/native/": "runtimes/osx/native/*" + } } diff --git a/test/Microsoft.AspNet.Server.KestrelTests/MultipleLoopTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/MultipleLoopTests.cs index 4e8c0fddd6..c8b8a1de04 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/MultipleLoopTests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/MultipleLoopTests.cs @@ -41,7 +41,7 @@ namespace Microsoft.AspNet.Server.KestrelTests } } - [Fact] + [Fact(Skip = "Waiting for adding support for multi loop in libuv")] public void InitAndCloseServerPipe() { var loop = new UvLoopHandle(_logger); @@ -59,7 +59,7 @@ namespace Microsoft.AspNet.Server.KestrelTests } - [Fact] + [Fact(Skip = "Waiting for adding support for multi loop in libuv")] public void ServerPipeListenForConnections() { var loop = new UvLoopHandle(_logger); @@ -132,7 +132,7 @@ namespace Microsoft.AspNet.Server.KestrelTests } - [Fact] + [Fact(Skip = "Waiting for adding support for multi loop in libuv")] public void ServerPipeDispatchConnections() { var pipeName = @"\\.\pipe\ServerPipeDispatchConnections" + Guid.NewGuid().ToString("n"); diff --git a/tools/Microsoft.AspNet.Server.Kestrel.LibuvCopier/Microsoft.AspNet.Server.Kestrel.LibuvCopier.xproj b/tools/Microsoft.AspNet.Server.Kestrel.LibuvCopier/Microsoft.AspNet.Server.Kestrel.LibuvCopier.xproj new file mode 100644 index 0000000000..bb7fe23a81 --- /dev/null +++ b/tools/Microsoft.AspNet.Server.Kestrel.LibuvCopier/Microsoft.AspNet.Server.Kestrel.LibuvCopier.xproj @@ -0,0 +1,20 @@ + + + + 14.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + + + + + 8cba6fe3-3cc9-4420-8aa3-123e983734c2 + Microsoft.AspNet.Server.Kestrel.LibuvCopier + ..\..\artifacts\obj\$(MSBuildProjectName) + ..\..\artifacts\bin\$(MSBuildProjectName)\ + + + + 2.0 + + + diff --git a/tools/Microsoft.AspNet.Server.Kestrel.LibuvCopier/Program.cs b/tools/Microsoft.AspNet.Server.Kestrel.LibuvCopier/Program.cs new file mode 100644 index 0000000000..f6be2acec9 --- /dev/null +++ b/tools/Microsoft.AspNet.Server.Kestrel.LibuvCopier/Program.cs @@ -0,0 +1,42 @@ +using System; +using System.IO; +using System.Linq; +using Newtonsoft.Json.Linq; + +namespace Microsoft.AspNet.Server.Kestrel.LibuvCopier +{ + public class Program + { + public void Main(string[] args) + { + try + { + var dnxFolder = Environment.GetEnvironmentVariable("DNX_HOME"); + if (string.IsNullOrEmpty(dnxFolder)) + { + dnxFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".dnx"); + } + + var lockJson = JObject.Parse(File.ReadAllText("project.lock.json")); + + foreach (var libuvLib in lockJson["libraries"].OfType().Where( + p => p.Name.StartsWith("Microsoft.AspNet.Internal.libuv", StringComparison.Ordinal))) + { + foreach (var filePath in libuvLib.Value["files"].Select(v => v.Value())) + { + if (filePath.ToString().StartsWith("runtimes/", StringComparison.Ordinal)) + { + Directory.CreateDirectory(Path.GetDirectoryName(filePath)); + File.Copy(Path.Combine(dnxFolder, "packages", libuvLib.Name, filePath), filePath, overwrite: true); + } + } + } + } + catch(Exception ex) + { + Console.WriteLine(ex); + throw; + } + } + } +} diff --git a/tools/Microsoft.AspNet.Server.Kestrel.LibuvCopier/project.json b/tools/Microsoft.AspNet.Server.Kestrel.LibuvCopier/project.json new file mode 100644 index 0000000000..469aeac902 --- /dev/null +++ b/tools/Microsoft.AspNet.Server.Kestrel.LibuvCopier/project.json @@ -0,0 +1,30 @@ +{ + "version": "1.0.0-*", + "description": "Microsoft.AspNet.Server.Kestrel.LibuvCopier Console Application", + "authors": [ "pawelka" ], + "tags": [ "" ], + "projectUrl": "", + "licenseUrl": "", + + "dependencies": { + "Newtonsoft.Json" : "7.0.1" + }, + + "commands": { + "Microsoft.AspNet.Server.Kestrel.LibuvCopier": "Microsoft.AspNet.Server.Kestrel.LibuvCopier" + }, + + "frameworks": { + "dnx451": { }, + "dnxcore50": { + "dependencies": { + "Microsoft.CSharp": "4.0.1-beta-23225", + "System.Collections": "4.0.11-beta-23225", + "System.Console": "4.0.0-beta-23225", + "System.Linq": "4.0.1-beta-23225", + "System.Threading": "4.0.11-beta-23225", + "System.IO.FileSystem": "4.0.1-beta-23225" + } + } + } +} From e47192b9e908d64caf0ff9581f768b6863c2e459 Mon Sep 17 00:00:00 2001 From: moozzyk Date: Sun, 27 Sep 2015 21:02:18 -0700 Subject: [PATCH 0303/1662] Using a path from `DNX_PACKAGES` if defined --- .../Program.cs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/tools/Microsoft.AspNet.Server.Kestrel.LibuvCopier/Program.cs b/tools/Microsoft.AspNet.Server.Kestrel.LibuvCopier/Program.cs index f6be2acec9..0485b91b1f 100644 --- a/tools/Microsoft.AspNet.Server.Kestrel.LibuvCopier/Program.cs +++ b/tools/Microsoft.AspNet.Server.Kestrel.LibuvCopier/Program.cs @@ -11,10 +11,17 @@ namespace Microsoft.AspNet.Server.Kestrel.LibuvCopier { try { - var dnxFolder = Environment.GetEnvironmentVariable("DNX_HOME"); - if (string.IsNullOrEmpty(dnxFolder)) + var packagesFolder = Environment.GetEnvironmentVariable("DNX_PACKAGES"); + + if (string.IsNullOrEmpty(packagesFolder)) { - dnxFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".dnx"); + var dnxFolder = Environment.GetEnvironmentVariable("DNX_HOME"); + if (string.IsNullOrEmpty(dnxFolder)) + { + dnxFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".dnx"); + } + + packagesFolder = Path.Combine(dnxFolder, "packages"); } var lockJson = JObject.Parse(File.ReadAllText("project.lock.json")); @@ -27,7 +34,7 @@ namespace Microsoft.AspNet.Server.Kestrel.LibuvCopier if (filePath.ToString().StartsWith("runtimes/", StringComparison.Ordinal)) { Directory.CreateDirectory(Path.GetDirectoryName(filePath)); - File.Copy(Path.Combine(dnxFolder, "packages", libuvLib.Name, filePath), filePath, overwrite: true); + File.Copy(Path.Combine(packagesFolder, libuvLib.Name, filePath), filePath, overwrite: true); } } } From 454812e9bc3ba3d2668eb5d6b3bd2b075d20de74 Mon Sep 17 00:00:00 2001 From: moozzyk Date: Mon, 28 Sep 2015 12:14:09 -0700 Subject: [PATCH 0304/1662] Expanding environment variables in paths --- tools/Microsoft.AspNet.Server.Kestrel.LibuvCopier/Program.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tools/Microsoft.AspNet.Server.Kestrel.LibuvCopier/Program.cs b/tools/Microsoft.AspNet.Server.Kestrel.LibuvCopier/Program.cs index 0485b91b1f..a2de3ff4ad 100644 --- a/tools/Microsoft.AspNet.Server.Kestrel.LibuvCopier/Program.cs +++ b/tools/Microsoft.AspNet.Server.Kestrel.LibuvCopier/Program.cs @@ -24,6 +24,8 @@ namespace Microsoft.AspNet.Server.Kestrel.LibuvCopier packagesFolder = Path.Combine(dnxFolder, "packages"); } + packagesFolder = Environment.ExpandEnvironmentVariables(packagesFolder); + var lockJson = JObject.Parse(File.ReadAllText("project.lock.json")); foreach (var libuvLib in lockJson["libraries"].OfType().Where( From 7e386ab57600a85297fbeff6e1a82f94bc358d76 Mon Sep 17 00:00:00 2001 From: Pranav K Date: Mon, 28 Sep 2015 23:12:54 -0700 Subject: [PATCH 0305/1662] Updating to release NuGet.config. --- NuGet.config | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NuGet.config b/NuGet.config index 297aa0ae6c..31dc85d719 100644 --- a/NuGet.config +++ b/NuGet.config @@ -1,7 +1,7 @@ - + From f3b5bc2483ba152840fe99029ea4d61c339506c5 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Tue, 29 Sep 2015 11:07:06 -0700 Subject: [PATCH 0306/1662] Don't set ThreadCount in sample project since it is temporarily broken - We should be able to add this back once https://github.com/libuv/libuv/pull/540 gets merged. --- samples/SampleApp/Startup.cs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/samples/SampleApp/Startup.cs b/samples/SampleApp/Startup.cs index f41201db16..f74fffe57e 100644 --- a/samples/SampleApp/Startup.cs +++ b/samples/SampleApp/Startup.cs @@ -5,7 +5,6 @@ using System; using Microsoft.AspNet.Builder; using Microsoft.AspNet.Http; using Microsoft.Framework.Logging; -using Microsoft.AspNet.Server.Kestrel; namespace SampleApp { @@ -13,9 +12,6 @@ namespace SampleApp { public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory) { - var ksi = app.ServerFeatures[typeof(IKestrelServerInformation)] as IKestrelServerInformation; - ksi.ThreadCount = 4; - loggerFactory.MinimumLevel = LogLevel.Debug; loggerFactory.AddConsole(LogLevel.Debug); From 34a422b86549f0af8f7913686a58a75553a6c943 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Tue, 29 Sep 2015 11:11:58 -0700 Subject: [PATCH 0307/1662] Ifdef lines in LibuvCopier that use APIs not available on CoreCLR - This means DNX_HOME or DNX_PACKAGES must be set to restore with CoreCLR --- .../Program.cs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/tools/Microsoft.AspNet.Server.Kestrel.LibuvCopier/Program.cs b/tools/Microsoft.AspNet.Server.Kestrel.LibuvCopier/Program.cs index a2de3ff4ad..6139fc3b44 100644 --- a/tools/Microsoft.AspNet.Server.Kestrel.LibuvCopier/Program.cs +++ b/tools/Microsoft.AspNet.Server.Kestrel.LibuvCopier/Program.cs @@ -16,12 +16,24 @@ namespace Microsoft.AspNet.Server.Kestrel.LibuvCopier if (string.IsNullOrEmpty(packagesFolder)) { var dnxFolder = Environment.GetEnvironmentVariable("DNX_HOME"); + +#if DNX451 + // DNXCore,Version=v5.0 error CS0117: 'Environment' does not contain a definition for 'SpecialFolder' + // DNXCore,Version=v5.0 error CS0117: 'Environment' does not contain a definition for 'GetFolderPath' if (string.IsNullOrEmpty(dnxFolder)) { dnxFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".dnx"); } +#endif - packagesFolder = Path.Combine(dnxFolder, "packages"); + if (!string.IsNullOrEmpty(dnxFolder)) + { + packagesFolder = Path.Combine(dnxFolder, "packages"); + } + else + { + throw new Exception("DNX folder not found. Try setting the DNX_HOME and/or DNX_PACKAGES environment variables."); + } } packagesFolder = Environment.ExpandEnvironmentVariables(packagesFolder); From 0a6571b9f9c61df1f12028bc308daecf92c480a9 Mon Sep 17 00:00:00 2001 From: "N. Taylor Mullen" Date: Thu, 1 Oct 2015 11:58:14 -0700 Subject: [PATCH 0308/1662] Update 'build.cmd' alias parameter to use full name. --- build.cmd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.cmd b/build.cmd index 177997c42e..70d974a61f 100644 --- a/build.cmd +++ b/build.cmd @@ -30,7 +30,7 @@ IF "%SKIP_DNX_INSTALL%"=="1" goto run IF %BUILDCMD_DNX_VERSION%=="" ( CALL packages\KoreBuild\build\dnvm upgrade -runtime CLR -arch x86 ) ELSE ( - CALL packages\KoreBuild\build\dnvm install %BUILDCMD_DNX_VERSION% -runtime CLR -arch x86 -a default + CALL packages\KoreBuild\build\dnvm install %BUILDCMD_DNX_VERSION% -runtime CLR -arch x86 -alias default ) CALL packages\KoreBuild\build\dnvm install default -runtime CoreCLR -arch x86 From 49451fb11e53a1783a3b3415f228411de5ef45b0 Mon Sep 17 00:00:00 2001 From: Pranav K Date: Sat, 3 Oct 2015 15:44:45 -0700 Subject: [PATCH 0309/1662] Renaming Microsoft.Framework.* -> Microsoft.Extensions.* --- samples/SampleApp/Startup.cs | 4 ++-- samples/SampleApp/project.json | 2 +- src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs | 2 +- src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs | 4 ++-- .../Http/FrameHeaders.Generated.cs | 2 +- src/Microsoft.AspNet.Server.Kestrel/Http/FrameHeaders.cs | 4 ++-- .../Http/FrameRequestHeaders.cs | 4 ++-- .../Http/FrameResponseHeaders.cs | 4 ++-- src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs | 2 +- src/Microsoft.AspNet.Server.Kestrel/Http/ListenerPrimary.cs | 2 +- src/Microsoft.AspNet.Server.Kestrel/Http/ListenerSecondary.cs | 2 +- src/Microsoft.AspNet.Server.Kestrel/Http/MessageBody.cs | 2 +- src/Microsoft.AspNet.Server.Kestrel/Http/PipeListener.cs | 4 ++-- .../Http/PipeListenerPrimary.cs | 4 ++-- src/Microsoft.AspNet.Server.Kestrel/Http/TcpListener.cs | 4 ++-- .../Http/TcpListenerPrimary.cs | 4 ++-- .../Infrastructure/IKestrelTrace.cs | 2 +- .../Infrastructure/KestrelThread.cs | 2 +- .../Infrastructure/KestrelTrace.cs | 4 ++-- src/Microsoft.AspNet.Server.Kestrel/KestrelEngine.cs | 2 +- .../KestrelServerInformation.cs | 2 +- .../Networking/UvConnectRequest.cs | 2 +- .../Networking/UvStreamHandle.cs | 2 +- src/Microsoft.AspNet.Server.Kestrel/Networking/UvWriteReq.cs | 2 +- src/Microsoft.AspNet.Server.Kestrel/ServerFactory.cs | 4 ++-- src/Microsoft.AspNet.Server.Kestrel/ServerRequest.cs | 2 +- src/Microsoft.AspNet.Server.Kestrel/project.json | 2 +- .../FrameRequestHeadersTests.cs | 4 ++-- .../FrameResponseHeadersTests.cs | 4 ++-- test/Microsoft.AspNet.Server.KestrelTests/MessageBodyTests.cs | 4 ++-- test/Microsoft.AspNet.Server.KestrelTests/TestLogger.cs | 4 ++-- .../KnownHeaders.cs | 4 ++-- 32 files changed, 48 insertions(+), 48 deletions(-) diff --git a/samples/SampleApp/Startup.cs b/samples/SampleApp/Startup.cs index f74fffe57e..f471f345cb 100644 --- a/samples/SampleApp/Startup.cs +++ b/samples/SampleApp/Startup.cs @@ -1,10 +1,10 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; using Microsoft.AspNet.Builder; using Microsoft.AspNet.Http; -using Microsoft.Framework.Logging; +using Microsoft.Extensions.Logging; namespace SampleApp { diff --git a/samples/SampleApp/project.json b/samples/SampleApp/project.json index 35885e8e3f..2a45655ae9 100644 --- a/samples/SampleApp/project.json +++ b/samples/SampleApp/project.json @@ -2,7 +2,7 @@ "version": "1.0.0-*", "dependencies": { "Microsoft.AspNet.Server.Kestrel": "1.0.0-*", - "Microsoft.Framework.Logging.Console": "1.0.0-*" + "Microsoft.Extensions.Logging.Console": "1.0.0-*" }, "frameworks": { "dnx451": { }, diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs index def246b92b..fadcce592b 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs @@ -6,7 +6,7 @@ using System.Threading; using System.Threading.Tasks; using Microsoft.AspNet.Server.Kestrel.Infrastructure; using Microsoft.AspNet.Server.Kestrel.Networking; -using Microsoft.Framework.Logging; +using Microsoft.Extensions.Logging; namespace Microsoft.AspNet.Server.Kestrel.Http { diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs index 09ba0f1171..e70d1bd6fc 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs @@ -9,8 +9,8 @@ using System.Text; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNet.Server.Kestrel.Infrastructure; -using Microsoft.Framework.Logging; -using Microsoft.Framework.Primitives; +using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Primitives; // ReSharper disable AccessToModifiedClosure diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameHeaders.Generated.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameHeaders.Generated.cs index 2d5a6c20c0..9666fad29b 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameHeaders.Generated.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameHeaders.Generated.cs @@ -1,7 +1,7 @@ using System; using System.Collections.Generic; -using Microsoft.Framework.Primitives; +using Microsoft.Extensions.Primitives; namespace Microsoft.AspNet.Server.Kestrel.Http { diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameHeaders.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameHeaders.cs index 57440c3434..d188c692f2 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameHeaders.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameHeaders.cs @@ -1,11 +1,11 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; using System.Collections; using System.Collections.Generic; using System.Linq; -using Microsoft.Framework.Primitives; +using Microsoft.Extensions.Primitives; namespace Microsoft.AspNet.Server.Kestrel.Http { diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameRequestHeaders.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameRequestHeaders.cs index f6d1dc82e0..da9429ac79 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameRequestHeaders.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameRequestHeaders.cs @@ -1,7 +1,7 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using Microsoft.Framework.Primitives; +using Microsoft.Extensions.Primitives; using System.Collections; using System.Collections.Generic; diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameResponseHeaders.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameResponseHeaders.cs index 7d1b15ade1..725a647567 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameResponseHeaders.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameResponseHeaders.cs @@ -1,7 +1,7 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using Microsoft.Framework.Primitives; +using Microsoft.Extensions.Primitives; using System.Collections; using System.Collections.Generic; diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs index 741180aee3..a6900f6085 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs @@ -4,7 +4,7 @@ using Microsoft.AspNet.Server.Kestrel.Networking; using System; using System.Threading.Tasks; -using Microsoft.Framework.Logging; +using Microsoft.Extensions.Logging; namespace Microsoft.AspNet.Server.Kestrel.Http { diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerPrimary.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerPrimary.cs index df83d66695..15b0e904e8 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerPrimary.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerPrimary.cs @@ -6,7 +6,7 @@ using System.Collections.Generic; using System.Threading.Tasks; using Microsoft.AspNet.Server.Kestrel.Infrastructure; using Microsoft.AspNet.Server.Kestrel.Networking; -using Microsoft.Framework.Logging; +using Microsoft.Extensions.Logging; namespace Microsoft.AspNet.Server.Kestrel.Http { diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerSecondary.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerSecondary.cs index e50a69071c..37c9c3cc70 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerSecondary.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerSecondary.cs @@ -6,7 +6,7 @@ using System.Runtime.InteropServices; using System.Threading.Tasks; using Microsoft.AspNet.Server.Kestrel.Infrastructure; using Microsoft.AspNet.Server.Kestrel.Networking; -using Microsoft.Framework.Logging; +using Microsoft.Extensions.Logging; namespace Microsoft.AspNet.Server.Kestrel.Http { diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/MessageBody.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/MessageBody.cs index 13f7110168..e60647700e 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/MessageBody.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/MessageBody.cs @@ -5,7 +5,7 @@ using System; using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; -using Microsoft.Framework.Primitives; +using Microsoft.Extensions.Primitives; using System.IO; namespace Microsoft.AspNet.Server.Kestrel.Http diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/PipeListener.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/PipeListener.cs index a63e3a547b..3e5a4a5d56 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/PipeListener.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/PipeListener.cs @@ -1,10 +1,10 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; using Microsoft.AspNet.Server.Kestrel.Infrastructure; using Microsoft.AspNet.Server.Kestrel.Networking; -using Microsoft.Framework.Logging; +using Microsoft.Extensions.Logging; namespace Microsoft.AspNet.Server.Kestrel.Http { diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/PipeListenerPrimary.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/PipeListenerPrimary.cs index 7b39014487..a9ef09ce75 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/PipeListenerPrimary.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/PipeListenerPrimary.cs @@ -1,10 +1,10 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; using Microsoft.AspNet.Server.Kestrel.Infrastructure; using Microsoft.AspNet.Server.Kestrel.Networking; -using Microsoft.Framework.Logging; +using Microsoft.Extensions.Logging; namespace Microsoft.AspNet.Server.Kestrel.Http { diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/TcpListener.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/TcpListener.cs index ba920f34aa..4d0e250adf 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/TcpListener.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/TcpListener.cs @@ -1,11 +1,11 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; using System.Net; using Microsoft.AspNet.Server.Kestrel.Infrastructure; using Microsoft.AspNet.Server.Kestrel.Networking; -using Microsoft.Framework.Logging; +using Microsoft.Extensions.Logging; namespace Microsoft.AspNet.Server.Kestrel.Http { diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/TcpListenerPrimary.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/TcpListenerPrimary.cs index cc4bb451f8..bc46f5bd9a 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/TcpListenerPrimary.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/TcpListenerPrimary.cs @@ -1,11 +1,11 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; using System.Net; using Microsoft.AspNet.Server.Kestrel.Infrastructure; using Microsoft.AspNet.Server.Kestrel.Networking; -using Microsoft.Framework.Logging; +using Microsoft.Extensions.Logging; namespace Microsoft.AspNet.Server.Kestrel.Http { diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/IKestrelTrace.cs b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/IKestrelTrace.cs index cb825bac39..4da5b805f0 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/IKestrelTrace.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/IKestrelTrace.cs @@ -1,4 +1,4 @@ -using Microsoft.Framework.Logging; +using Microsoft.Extensions.Logging; namespace Microsoft.AspNet.Server.Kestrel.Infrastructure { diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs index b059bf6fe0..3c72d00581 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs @@ -9,7 +9,7 @@ using System.Threading; using System.Threading.Tasks; using Microsoft.AspNet.Server.Kestrel.Infrastructure; using Microsoft.Dnx.Runtime; -using Microsoft.Framework.Logging; +using Microsoft.Extensions.Logging; namespace Microsoft.AspNet.Server.Kestrel { diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelTrace.cs b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelTrace.cs index b7cc35e5aa..df4a3a9ac1 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelTrace.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelTrace.cs @@ -1,9 +1,9 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; using Microsoft.AspNet.Server.Kestrel.Infrastructure; -using Microsoft.Framework.Logging; +using Microsoft.Extensions.Logging; namespace Microsoft.AspNet.Server.Kestrel { diff --git a/src/Microsoft.AspNet.Server.Kestrel/KestrelEngine.cs b/src/Microsoft.AspNet.Server.Kestrel/KestrelEngine.cs index 6026072e16..f65cafb855 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/KestrelEngine.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/KestrelEngine.cs @@ -9,7 +9,7 @@ using Microsoft.AspNet.Server.Kestrel.Http; using Microsoft.AspNet.Server.Kestrel.Infrastructure; using Microsoft.AspNet.Server.Kestrel.Networking; using Microsoft.Dnx.Runtime; -using Microsoft.Framework.Logging; +using Microsoft.Extensions.Logging; namespace Microsoft.AspNet.Server.Kestrel { diff --git a/src/Microsoft.AspNet.Server.Kestrel/KestrelServerInformation.cs b/src/Microsoft.AspNet.Server.Kestrel/KestrelServerInformation.cs index 4f53b80303..a6ca56c1ee 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/KestrelServerInformation.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/KestrelServerInformation.cs @@ -4,7 +4,7 @@ using System; using System.Collections.Generic; using Microsoft.AspNet.Server.Features; -using Microsoft.Framework.Configuration; +using Microsoft.Extensions.Configuration; namespace Microsoft.AspNet.Server.Kestrel { diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvConnectRequest.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvConnectRequest.cs index c01f19eb75..0c0ce04b4b 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvConnectRequest.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvConnectRequest.cs @@ -3,7 +3,7 @@ using System; using Microsoft.AspNet.Server.Kestrel.Infrastructure; -using Microsoft.Framework.Logging; +using Microsoft.Extensions.Logging; namespace Microsoft.AspNet.Server.Kestrel.Networking { diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvStreamHandle.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvStreamHandle.cs index 629a363278..42c6cd3e81 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvStreamHandle.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvStreamHandle.cs @@ -4,7 +4,7 @@ using System; using System.Runtime.InteropServices; using Microsoft.AspNet.Server.Kestrel.Infrastructure; -using Microsoft.Framework.Logging; +using Microsoft.Extensions.Logging; namespace Microsoft.AspNet.Server.Kestrel.Networking { diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvWriteReq.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvWriteReq.cs index 1e80f1ffb2..db05ab1432 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvWriteReq.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvWriteReq.cs @@ -5,7 +5,7 @@ using System; using System.Collections.Generic; using System.Runtime.InteropServices; using Microsoft.AspNet.Server.Kestrel.Infrastructure; -using Microsoft.Framework.Logging; +using Microsoft.Extensions.Logging; namespace Microsoft.AspNet.Server.Kestrel.Networking { diff --git a/src/Microsoft.AspNet.Server.Kestrel/ServerFactory.cs b/src/Microsoft.AspNet.Server.Kestrel/ServerFactory.cs index d81f34885f..f1fc15c88e 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/ServerFactory.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/ServerFactory.cs @@ -9,8 +9,8 @@ using Microsoft.AspNet.Http.Features; using Microsoft.AspNet.Server.Features; using Microsoft.AspNet.Server.Kestrel.Http; using Microsoft.Dnx.Runtime; -using Microsoft.Framework.Configuration; -using Microsoft.Framework.Logging; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Logging; namespace Microsoft.AspNet.Server.Kestrel { diff --git a/src/Microsoft.AspNet.Server.Kestrel/ServerRequest.cs b/src/Microsoft.AspNet.Server.Kestrel/ServerRequest.cs index 690539f7c9..559b7bb525 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/ServerRequest.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/ServerRequest.cs @@ -8,7 +8,7 @@ using System.Linq; using System.Threading.Tasks; using Microsoft.AspNet.Http.Features; using Microsoft.AspNet.Server.Kestrel.Http; -using Microsoft.Framework.Primitives; +using Microsoft.Extensions.Primitives; namespace Microsoft.AspNet.Server.Kestrel { diff --git a/src/Microsoft.AspNet.Server.Kestrel/project.json b/src/Microsoft.AspNet.Server.Kestrel/project.json index 2efa65204c..221a1ab18b 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/project.json +++ b/src/Microsoft.AspNet.Server.Kestrel/project.json @@ -8,7 +8,7 @@ "dependencies": { "Microsoft.AspNet.Hosting": "1.0.0-*", "Microsoft.Dnx.Runtime.Abstractions": "1.0.0-*", - "Microsoft.Framework.Logging.Abstractions": "1.0.0-*", + "Microsoft.Extensions.Logging.Abstractions": "1.0.0-*", "System.Numerics.Vectors": "4.1.1-beta-*", "Microsoft.StandardsPolice": { "version": "1.0.0-*", diff --git a/test/Microsoft.AspNet.Server.KestrelTests/FrameRequestHeadersTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/FrameRequestHeadersTests.cs index 7df87b5a7e..24152ca199 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/FrameRequestHeadersTests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/FrameRequestHeadersTests.cs @@ -1,7 +1,7 @@ -using System; +using System; using System.Collections.Generic; using Microsoft.AspNet.Server.Kestrel.Http; -using Microsoft.Framework.Primitives; +using Microsoft.Extensions.Primitives; using Xunit; namespace Microsoft.AspNet.Server.KestrelTests diff --git a/test/Microsoft.AspNet.Server.KestrelTests/FrameResponseHeadersTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/FrameResponseHeadersTests.cs index b084b9547d..d0e129c5f3 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/FrameResponseHeadersTests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/FrameResponseHeadersTests.cs @@ -1,10 +1,10 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; using System.Collections.Generic; using Microsoft.AspNet.Server.Kestrel.Http; -using Microsoft.Framework.Primitives; +using Microsoft.Extensions.Primitives; using Xunit; namespace Microsoft.AspNet.Server.KestrelTests diff --git a/test/Microsoft.AspNet.Server.KestrelTests/MessageBodyTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/MessageBodyTests.cs index c3cda8d13a..76c0a309da 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/MessageBodyTests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/MessageBodyTests.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -6,7 +6,7 @@ using System.Collections.Generic; using System.Text; using System.Threading.Tasks; using Microsoft.AspNet.Server.Kestrel.Http; -using Microsoft.Framework.Primitives; +using Microsoft.Extensions.Primitives; using Xunit; namespace Microsoft.AspNet.Server.KestrelTests diff --git a/test/Microsoft.AspNet.Server.KestrelTests/TestLogger.cs b/test/Microsoft.AspNet.Server.KestrelTests/TestLogger.cs index db346ade3a..b9123285d9 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/TestLogger.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/TestLogger.cs @@ -1,6 +1,6 @@ -using System; +using System; using Microsoft.AspNet.Server.Kestrel; -using Microsoft.Framework.Logging; +using Microsoft.Extensions.Logging; namespace Microsoft.AspNet.Server.KestrelTests { diff --git a/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/KnownHeaders.cs b/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/KnownHeaders.cs index d58b76bc5c..11327a8d60 100644 --- a/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/KnownHeaders.cs +++ b/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/KnownHeaders.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; using Microsoft.Dnx.Compilation.CSharp; @@ -167,7 +167,7 @@ namespace Microsoft.AspNet.Server.Kestrel.GeneratedCode return $@" using System; using System.Collections.Generic; -using Microsoft.Framework.Primitives; +using Microsoft.Extensions.Primitives; namespace Microsoft.AspNet.Server.Kestrel.Http {{ From 2f3a00625a8363656e776cbf6011e167933902db Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Wed, 30 Sep 2015 11:15:09 -0700 Subject: [PATCH 0310/1662] Initial work to support HTTPS using SslStream - Add extension method "UseKestrelHttps" to IApplicationBuilder --- KestrelHttpServer.sln | 7 ++ samples/SampleApp/project.json | 8 +- .../HttpsApplicationBuilderExtensions.cs | 29 ++++++ .../HttpsConnectionFilter.cs | 44 +++++++++ ...icrosoft.AspNet.Server.Kestrel.Https.xproj | 20 ++++ .../project.json | 14 +++ .../Filter/ConnectionFilterContext.cs | 13 +++ .../Filter/FilteredStreamAdapter.cs | 63 ++++++++++++ .../Filter/IConnectionFilter.cs | 12 +++ .../Filter/LibuvStream.cs | 91 +++++++++++++++++ .../Filter/NoOpConnectionFilter.cs | 17 ++++ .../Filter/SocketInputStream.cs | 99 +++++++++++++++++++ .../Filter/StreamSocketOutput.cs | 35 +++++++ .../Http/Connection.cs | 74 ++++++++++++-- .../Http/ISocketOutput.cs | 1 - .../Http/Listener.cs | 9 +- .../Http/ListenerContext.cs | 5 +- .../Http/ListenerPrimary.cs | 6 +- .../Http/ListenerSecondary.cs | 2 + .../Http/MessageBody.cs | 58 +++-------- .../Http/PipeListener.cs | 4 +- .../Http/PipeListenerPrimary.cs | 4 +- .../Http/SocketInputExtensions.cs | 33 +++++++ .../Http/SocketOutput.cs | 38 +++---- .../Http/TcpListener.cs | 4 +- .../Http/TcpListenerPrimary.cs | 4 +- .../IKestrelServerInformation.cs | 4 + .../KestrelEngine.cs | 16 ++- .../KestrelServerInformation.cs | 3 + .../Networking/UvTcpHandle.cs | 12 +-- .../ServerAddress.cs | 19 ++++ .../ServerFactory.cs | 7 +- .../ServiceContext.cs | 4 + .../CreateIPEndpointTests.cs | 3 +- .../EngineTests.cs | 6 +- .../MultipleLoopTests.cs | 3 +- .../NetworkingTests.cs | 12 ++- .../SocketOutputTests.cs | 4 +- .../TestServer.cs | 4 +- 39 files changed, 667 insertions(+), 124 deletions(-) create mode 100644 src/Microsoft.AspNet.Server.Kestrel.Https/HttpsApplicationBuilderExtensions.cs create mode 100644 src/Microsoft.AspNet.Server.Kestrel.Https/HttpsConnectionFilter.cs create mode 100644 src/Microsoft.AspNet.Server.Kestrel.Https/Microsoft.AspNet.Server.Kestrel.Https.xproj create mode 100644 src/Microsoft.AspNet.Server.Kestrel.Https/project.json create mode 100644 src/Microsoft.AspNet.Server.Kestrel/Filter/ConnectionFilterContext.cs create mode 100644 src/Microsoft.AspNet.Server.Kestrel/Filter/FilteredStreamAdapter.cs create mode 100644 src/Microsoft.AspNet.Server.Kestrel/Filter/IConnectionFilter.cs create mode 100644 src/Microsoft.AspNet.Server.Kestrel/Filter/LibuvStream.cs create mode 100644 src/Microsoft.AspNet.Server.Kestrel/Filter/NoOpConnectionFilter.cs create mode 100644 src/Microsoft.AspNet.Server.Kestrel/Filter/SocketInputStream.cs create mode 100644 src/Microsoft.AspNet.Server.Kestrel/Filter/StreamSocketOutput.cs create mode 100644 src/Microsoft.AspNet.Server.Kestrel/Http/SocketInputExtensions.cs diff --git a/KestrelHttpServer.sln b/KestrelHttpServer.sln index 8b0d78f607..f2da75a88c 100644 --- a/KestrelHttpServer.sln +++ b/KestrelHttpServer.sln @@ -33,6 +33,8 @@ Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.StandardsPolice", EndProject Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.Server.Kestrel.LibuvCopier", "tools\Microsoft.AspNet.Server.Kestrel.LibuvCopier\Microsoft.AspNet.Server.Kestrel.LibuvCopier.xproj", "{8CBA6FE3-3CC9-4420-8AA3-123E983734C2}" EndProject +Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.Server.Kestrel.Https", "src\Microsoft.AspNet.Server.Kestrel.Https\Microsoft.AspNet.Server.Kestrel.Https.xproj", "{5F64B3C3-0C2E-431A-B820-A81BBFC863DA}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -67,6 +69,10 @@ Global {8CBA6FE3-3CC9-4420-8AA3-123E983734C2}.Debug|Any CPU.Build.0 = Debug|Any CPU {8CBA6FE3-3CC9-4420-8AA3-123E983734C2}.Release|Any CPU.ActiveCfg = Release|Any CPU {8CBA6FE3-3CC9-4420-8AA3-123E983734C2}.Release|Any CPU.Build.0 = Release|Any CPU + {5F64B3C3-0C2E-431A-B820-A81BBFC863DA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {5F64B3C3-0C2E-431A-B820-A81BBFC863DA}.Debug|Any CPU.Build.0 = Debug|Any CPU + {5F64B3C3-0C2E-431A-B820-A81BBFC863DA}.Release|Any CPU.ActiveCfg = Release|Any CPU + {5F64B3C3-0C2E-431A-B820-A81BBFC863DA}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -79,5 +85,6 @@ Global {BD2D4D29-1BD9-40D0-BB31-337D5416B63C} = {327F7880-D9AF-46BD-B45C-3B7E34A01DFD} {82295647-7C1C-4671-BAB6-0FEF58F949EC} = {327F7880-D9AF-46BD-B45C-3B7E34A01DFD} {8CBA6FE3-3CC9-4420-8AA3-123E983734C2} = {327F7880-D9AF-46BD-B45C-3B7E34A01DFD} + {5F64B3C3-0C2E-431A-B820-A81BBFC863DA} = {2D5D5227-4DBD-499A-96B1-76A36B03B750} EndGlobalSection EndGlobal diff --git a/samples/SampleApp/project.json b/samples/SampleApp/project.json index 2a45655ae9..f4b23cfc64 100644 --- a/samples/SampleApp/project.json +++ b/samples/SampleApp/project.json @@ -5,7 +5,11 @@ "Microsoft.Extensions.Logging.Console": "1.0.0-*" }, "frameworks": { - "dnx451": { }, + "dnx451": { + "dependencies": { + "Microsoft.AspNet.Server.Kestrel.Https": "1.0.0-*" + } + }, "dnxcore50": { "dependencies": { "System.Console": "4.0.0-beta-*" @@ -16,6 +20,6 @@ "web": "Microsoft.AspNet.Hosting --server Microsoft.AspNet.Server.Kestrel", "run": "Microsoft.AspNet.Server.Kestrel", "run-socket": "Microsoft.AspNet.Server.Kestrel --server.urls http://unix:/tmp/kestrel-test.sock", - "kestrel": "Microsoft.AspNet.Server.Kestrel" + "kestrel": "Microsoft.AspNet.Server.Kestrel --server.urls http://localhost:5000;https://localhost:5001" } } diff --git a/src/Microsoft.AspNet.Server.Kestrel.Https/HttpsApplicationBuilderExtensions.cs b/src/Microsoft.AspNet.Server.Kestrel.Https/HttpsApplicationBuilderExtensions.cs new file mode 100644 index 0000000000..844435c152 --- /dev/null +++ b/src/Microsoft.AspNet.Server.Kestrel.Https/HttpsApplicationBuilderExtensions.cs @@ -0,0 +1,29 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System.Security.Cryptography.X509Certificates; +using Microsoft.AspNet.Builder; +using Microsoft.AspNet.Http.Features; +using Microsoft.AspNet.Server.Kestrel.Filter; + +namespace Microsoft.AspNet.Server.Kestrel.Https +{ + public static class HttpsApplicationBuilderExtensions + { + public static IApplicationBuilder UseKestrelHttps(this IApplicationBuilder app, X509Certificate2 cert) + { + var serverInfo = app.ServerFeatures.Get(); + + if (serverInfo == null) + { + return app; + } + + var prevFilter = serverInfo.ConnectionFilter ?? new NoOpConnectionFilter(); + + serverInfo.ConnectionFilter = new HttpsConnectionFilter(cert, prevFilter); + + return app; + } + } +} diff --git a/src/Microsoft.AspNet.Server.Kestrel.Https/HttpsConnectionFilter.cs b/src/Microsoft.AspNet.Server.Kestrel.Https/HttpsConnectionFilter.cs new file mode 100644 index 0000000000..08cad7161d --- /dev/null +++ b/src/Microsoft.AspNet.Server.Kestrel.Https/HttpsConnectionFilter.cs @@ -0,0 +1,44 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Net.Security; +using System.Security.Cryptography.X509Certificates; +using System.Threading.Tasks; +using Microsoft.AspNet.Server.Kestrel.Filter; + +namespace Microsoft.AspNet.Server.Kestrel.Https +{ + public class HttpsConnectionFilter : IConnectionFilter + { + private readonly X509Certificate2 _cert; + private readonly IConnectionFilter _previous; + + public HttpsConnectionFilter(X509Certificate2 cert, IConnectionFilter previous) + { + if (cert == null) + { + throw new ArgumentNullException(nameof(cert)); + } + if (previous == null) + { + throw new ArgumentNullException(nameof(previous)); + } + + _cert = cert; + _previous = previous; + } + + public async Task OnConnection(ConnectionFilterContext context) + { + await _previous.OnConnection(context); + + if (string.Equals(context.Address.Scheme, "https", StringComparison.OrdinalIgnoreCase)) + { + var sslStream = new SslStream(context.Connection); + await sslStream.AuthenticateAsServerAsync(_cert); + context.Connection = sslStream; + } + } + } +} diff --git a/src/Microsoft.AspNet.Server.Kestrel.Https/Microsoft.AspNet.Server.Kestrel.Https.xproj b/src/Microsoft.AspNet.Server.Kestrel.Https/Microsoft.AspNet.Server.Kestrel.Https.xproj new file mode 100644 index 0000000000..4ae185e402 --- /dev/null +++ b/src/Microsoft.AspNet.Server.Kestrel.Https/Microsoft.AspNet.Server.Kestrel.Https.xproj @@ -0,0 +1,20 @@ + + + + 14.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + + + + + 5f64b3c3-0c2e-431a-b820-a81bbfc863da + Microsoft.AspNet.Server.Kestrel.Https + ..\..\artifacts\obj\$(MSBuildProjectName) + ..\..\artifacts\bin\$(MSBuildProjectName)\ + + + + 2.0 + + + diff --git a/src/Microsoft.AspNet.Server.Kestrel.Https/project.json b/src/Microsoft.AspNet.Server.Kestrel.Https/project.json new file mode 100644 index 0000000000..2fc29ec1db --- /dev/null +++ b/src/Microsoft.AspNet.Server.Kestrel.Https/project.json @@ -0,0 +1,14 @@ +{ + "version": "1.0.0-*", + "description": "Adds HTTPS support to Kestrel", + "repository": { + "type": "git", + "url": "git://github.com/aspnet/kestrelhttpserver" + }, + "dependencies": { + "Microsoft.AspNet.Server.Kestrel": "1.0.0-*" + }, + "frameworks": { + "dnx451": { } + } +} diff --git a/src/Microsoft.AspNet.Server.Kestrel/Filter/ConnectionFilterContext.cs b/src/Microsoft.AspNet.Server.Kestrel/Filter/ConnectionFilterContext.cs new file mode 100644 index 0000000000..937e92bec3 --- /dev/null +++ b/src/Microsoft.AspNet.Server.Kestrel/Filter/ConnectionFilterContext.cs @@ -0,0 +1,13 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System.IO; + +namespace Microsoft.AspNet.Server.Kestrel.Filter +{ + public class ConnectionFilterContext + { + public ServerAddress Address { get; set; } + public Stream Connection { get; set; } + } +} diff --git a/src/Microsoft.AspNet.Server.Kestrel/Filter/FilteredStreamAdapter.cs b/src/Microsoft.AspNet.Server.Kestrel/Filter/FilteredStreamAdapter.cs new file mode 100644 index 0000000000..2e0872f704 --- /dev/null +++ b/src/Microsoft.AspNet.Server.Kestrel/Filter/FilteredStreamAdapter.cs @@ -0,0 +1,63 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.IO; +using System.Threading.Tasks; +using Microsoft.AspNet.Server.Kestrel.Http; +using Microsoft.AspNet.Server.Kestrel.Infrastructure; +using Microsoft.Extensions.Logging; + +namespace Microsoft.AspNet.Server.Kestrel.Filter +{ + public class FilteredStreamAdapter + { + private readonly Stream _filteredStream; + private readonly Stream _socketInputStream; + private readonly IKestrelTrace _log; + + public FilteredStreamAdapter( + Stream filteredStream, + MemoryPool2 memory, + IKestrelTrace logger) + { + SocketInput = new SocketInput(memory); + SocketOutput = new StreamSocketOutput(filteredStream); + + _log = logger; + _filteredStream = filteredStream; + _socketInputStream = new SocketInputStream(SocketInput); + + _filteredStream.CopyToAsync(_socketInputStream).ContinueWith((task, state) => + { + ((FilteredStreamAdapter)state).OnStreamClose(task); + }, this); + } + + public SocketInput SocketInput { get; private set; } + + public ISocketOutput SocketOutput { get; private set; } + + private void OnStreamClose(Task copyAsyncTask) + { + if (copyAsyncTask.IsFaulted) + { + _log.LogError("FilteredStreamAdapter.CopyToAsync", copyAsyncTask.Exception); + } + else if (copyAsyncTask.IsCanceled) + { + _log.LogError("FilteredStreamAdapter.CopyToAsync canceled."); + } + + try + { + _filteredStream.Dispose(); + _socketInputStream.Dispose(); + } + catch (Exception ex) + { + _log.LogError("FilteredStreamAdapter.OnStreamClose", ex); + } + } + } +} diff --git a/src/Microsoft.AspNet.Server.Kestrel/Filter/IConnectionFilter.cs b/src/Microsoft.AspNet.Server.Kestrel/Filter/IConnectionFilter.cs new file mode 100644 index 0000000000..accaa3b9d9 --- /dev/null +++ b/src/Microsoft.AspNet.Server.Kestrel/Filter/IConnectionFilter.cs @@ -0,0 +1,12 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System.Threading.Tasks; + +namespace Microsoft.AspNet.Server.Kestrel.Filter +{ + public interface IConnectionFilter + { + Task OnConnection(ConnectionFilterContext context); + } +} diff --git a/src/Microsoft.AspNet.Server.Kestrel/Filter/LibuvStream.cs b/src/Microsoft.AspNet.Server.Kestrel/Filter/LibuvStream.cs new file mode 100644 index 0000000000..16f3ce2c1b --- /dev/null +++ b/src/Microsoft.AspNet.Server.Kestrel/Filter/LibuvStream.cs @@ -0,0 +1,91 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.IO; +using System.Threading; +using System.Threading.Tasks; +using Microsoft.AspNet.Server.Kestrel.Http; + +namespace Microsoft.AspNet.Server.Kestrel.Filter +{ + public class LibuvStream : Stream + { + private readonly SocketInput _input; + private readonly ISocketOutput _output; + + public LibuvStream(SocketInput input, ISocketOutput output) + { + _input = input; + _output = output; + } + + public override bool CanRead => true; + + public override bool CanSeek => false; + + public override bool CanWrite => true; + + public override long Length + { + get + { + throw new NotSupportedException(); + } + } + + public override long Position + { + get + { + throw new NotSupportedException(); + } + set + { + throw new NotSupportedException(); + } + } + + public override long Seek(long offset, SeekOrigin origin) + { + throw new NotSupportedException(); + } + + public override void SetLength(long value) + { + throw new NotSupportedException(); + } + + public override int Read(byte[] buffer, int offset, int count) + { + return ReadAsync(new ArraySegment(buffer, offset, count)).GetAwaiter().GetResult(); + } + + public override Task ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) + { + return ReadAsync(new ArraySegment(buffer, offset, count)); + } + + public override void Write(byte[] buffer, int offset, int count) + { + var segment = new ArraySegment(buffer, offset, count); + _output.Write(segment); + } + + public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken token) + { + var segment = new ArraySegment(buffer, offset, count); + return _output.WriteAsync(segment); + } + + public override void Flush() + { + // No-op since writes are immediate. + } + + private Task ReadAsync(ArraySegment buffer) + { + return _input.ReadAsync(buffer); + } + } +} diff --git a/src/Microsoft.AspNet.Server.Kestrel/Filter/NoOpConnectionFilter.cs b/src/Microsoft.AspNet.Server.Kestrel/Filter/NoOpConnectionFilter.cs new file mode 100644 index 0000000000..65bb9e99b7 --- /dev/null +++ b/src/Microsoft.AspNet.Server.Kestrel/Filter/NoOpConnectionFilter.cs @@ -0,0 +1,17 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System.Threading.Tasks; + +namespace Microsoft.AspNet.Server.Kestrel.Filter +{ + public class NoOpConnectionFilter : IConnectionFilter + { + private static Task _empty = Task.FromResult(null); + + public Task OnConnection(ConnectionFilterContext context) + { + return _empty; + } + } +} diff --git a/src/Microsoft.AspNet.Server.Kestrel/Filter/SocketInputStream.cs b/src/Microsoft.AspNet.Server.Kestrel/Filter/SocketInputStream.cs new file mode 100644 index 0000000000..43f0d0e704 --- /dev/null +++ b/src/Microsoft.AspNet.Server.Kestrel/Filter/SocketInputStream.cs @@ -0,0 +1,99 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.IO; +using System.Threading; +using System.Threading.Tasks; +using Microsoft.AspNet.Server.Kestrel.Http; + +namespace Microsoft.AspNet.Server.Kestrel.Filter +{ + /// + /// This is a write-only stream that copies what is written into a + /// object. This is used as an argument to + /// so input filtered by a + /// ConnectionFilter (e.g. SslStream) can be consumed by . + /// + public class SocketInputStream : Stream + { + private static Task _emptyTask = Task.FromResult(null); + private static byte[] _emptyBuffer = new byte[0]; + + private readonly SocketInput _socketInput; + + public SocketInputStream(SocketInput socketInput) + { + _socketInput = socketInput; + } + + public override bool CanRead => false; + + public override bool CanSeek => false; + + public override bool CanWrite => true; + + public override long Length + { + get + { + throw new NotSupportedException(); + } + } + + public override long Position + { + get + { + throw new NotSupportedException(); + } + + set + { + throw new NotSupportedException(); + } + } + + public override void Flush() + { + // No-op + } + + public override int Read(byte[] buffer, int offset, int count) + { + throw new NotSupportedException(); + } + + public override long Seek(long offset, SeekOrigin origin) + { + throw new NotSupportedException(); + } + + public override void SetLength(long value) + { + throw new NotSupportedException(); + } + + public override void Write(byte[] buffer, int offset, int count) + { + var inputBuffer = _socketInput.IncomingStart(count); + + Buffer.BlockCopy(buffer, offset, inputBuffer.Data.Array, inputBuffer.Data.Offset, count); + + _socketInput.IncomingComplete(count, error: null); + } + + public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken token) + { + Write(buffer, offset, count); + return _emptyTask; + } + + protected override void Dispose(bool disposing) + { + // Close _socketInput with a 0-length write. + Write(_emptyBuffer, 0, 0); + base.Dispose(disposing); + } + } +} diff --git a/src/Microsoft.AspNet.Server.Kestrel/Filter/StreamSocketOutput.cs b/src/Microsoft.AspNet.Server.Kestrel/Filter/StreamSocketOutput.cs new file mode 100644 index 0000000000..f5470ae728 --- /dev/null +++ b/src/Microsoft.AspNet.Server.Kestrel/Filter/StreamSocketOutput.cs @@ -0,0 +1,35 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.IO; +using System.Threading; +using System.Threading.Tasks; +using Microsoft.AspNet.Server.Kestrel.Http; + +namespace Microsoft.AspNet.Server.Kestrel.Filter +{ + public class StreamSocketOutput : ISocketOutput + { + private static readonly Task _emptyTask = Task.FromResult(null); + + private readonly Stream _outputStream; + + public StreamSocketOutput(Stream outputStream) + { + _outputStream = outputStream; + } + + void ISocketOutput.Write(ArraySegment buffer, bool immediate) + { + _outputStream.Write(buffer.Array, buffer.Offset, buffer.Count); + } + + Task ISocketOutput.WriteAsync(ArraySegment buffer, bool immediate, CancellationToken cancellationToken) + { + // TODO: Use _outputStream.WriteAsync + _outputStream.Write(buffer.Array, buffer.Offset, buffer.Count); + return _emptyTask; + } + } +} diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs index fadcce592b..48dd7de7a1 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs @@ -4,6 +4,7 @@ using System; using System.Threading; using System.Threading.Tasks; +using Microsoft.AspNet.Server.Kestrel.Filter; using Microsoft.AspNet.Server.Kestrel.Infrastructure; using Microsoft.AspNet.Server.Kestrel.Networking; using Microsoft.Extensions.Logging; @@ -18,9 +19,13 @@ namespace Microsoft.AspNet.Server.Kestrel.Http private static long _lastConnectionId; private readonly UvStreamHandle _socket; - private readonly Frame _frame; + private Frame _frame; + private ConnectionFilterContext _filterContext; private readonly long _connectionId; + private readonly SocketInput _rawSocketInput; + private readonly SocketOutput _rawSocketOutput; + private readonly object _stateLock = new object(); private ConnectionState _connectionState; @@ -31,16 +36,67 @@ namespace Microsoft.AspNet.Server.Kestrel.Http _connectionId = Interlocked.Increment(ref _lastConnectionId); - SocketInput = new SocketInput(Memory2); - SocketOutput = new SocketOutput(Thread, _socket, _connectionId, Log); - _frame = new Frame(this); + _rawSocketInput = new SocketInput(Memory2); + _rawSocketOutput = new SocketOutput(Thread, _socket, _connectionId, Log); } public void Start() { Log.ConnectionStart(_connectionId); - _frame.Start(); + + // Start socket prior to applying the ConnectionFilter _socket.ReadStart(_allocCallback, _readCallback, this); + + // Don't initialize _frame until SocketInput and SocketOutput are set to their final values. + if (ConnectionFilter == null) + { + SocketInput = _rawSocketInput; + SocketOutput = _rawSocketOutput; + + _frame = new Frame(this); + _frame.Start(); + } + else + { + var libuvStream = new LibuvStream(_rawSocketInput, _rawSocketOutput); + + _filterContext = new ConnectionFilterContext + { + Connection = libuvStream, + Address = ServerAddress + }; + + ConnectionFilter.OnConnection(_filterContext).ContinueWith((task, state) => + { + var connection = (Connection)state; + + if (task.IsFaulted) + { + connection.Log.LogError("ConnectionFilter.OnConnection", task.Exception); + ConnectionControl.End(ProduceEndType.SocketDisconnect); + } + else if (task.IsCanceled) + { + connection.Log.LogError("ConnectionFilter.OnConnection Canceled"); + ConnectionControl.End(ProduceEndType.SocketDisconnect); + } + else + { + connection.ApplyConnectionFilter(); + } + }, this); + } + } + + private void ApplyConnectionFilter() + { + var filteredStreamAdapter = new FilteredStreamAdapter(_filterContext.Connection, Memory2, Log); + + SocketInput = filteredStreamAdapter.SocketInput; + SocketOutput = filteredStreamAdapter.SocketOutput; + + _frame = new Frame(this); + _frame.Start(); } private static Libuv.uv_buf_t AllocCallback(UvStreamHandle handle, int suggestedSize, object state) @@ -50,7 +106,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http private Libuv.uv_buf_t OnAlloc(UvStreamHandle handle, int suggestedSize) { - var result = SocketInput.IncomingStart(2048); + var result = _rawSocketInput.IncomingStart(2048); return handle.Libuv.buf_init( result.DataPtr, @@ -78,7 +134,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http Log.ConnectionReadFin(_connectionId); } - SocketInput.IncomingComplete(readCount, errorDone ? error : null); + _rawSocketInput.IncomingComplete(readCount, errorDone ? error : null); } void IConnectionControl.Pause() @@ -107,7 +163,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http _connectionState = ConnectionState.Shutdown; Log.ConnectionWriteFin(_connectionId); - SocketOutput.End(endType); + _rawSocketOutput.End(endType); break; case ProduceEndType.ConnectionKeepAlive: if (_connectionState != ConnectionState.Open) @@ -125,7 +181,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http _connectionState = ConnectionState.Disconnected; Log.ConnectionDisconnect(_connectionId); - SocketOutput.End(endType); + _rawSocketOutput.End(endType); break; } } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/ISocketOutput.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/ISocketOutput.cs index 00c567d571..4edffa3055 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/ISocketOutput.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/ISocketOutput.cs @@ -14,6 +14,5 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { void Write(ArraySegment buffer, bool immediate = true); Task WriteAsync(ArraySegment buffer, bool immediate = true, CancellationToken cancellationToken = default(CancellationToken)); - void End(ProduceEndType endType); } } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs index a6900f6085..8c7e2b6c05 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs @@ -21,12 +21,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http protected UvStreamHandle ListenSocket { get; private set; } public Task StartAsync( - string scheme, - string host, - int port, + ServerAddress address, KestrelThread thread, Func application) { + ServerAddress = address; Thread = thread; Application = application; @@ -35,7 +34,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { try { - ListenSocket = CreateListenSocket(host, port); + ListenSocket = CreateListenSocket(); tcs.SetResult(0); } catch (Exception ex) @@ -49,7 +48,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http /// /// Creates the socket used to listen for incoming connections /// - protected abstract UvStreamHandle CreateListenSocket(string host, int port); + protected abstract UvStreamHandle CreateListenSocket(); protected static void ConnectionCallback(UvStreamHandle stream, int status, Exception error, object state) { diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerContext.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerContext.cs index 2f6201016b..9e5a8e50ed 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerContext.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerContext.cs @@ -3,6 +3,7 @@ using System; using System.Threading.Tasks; +using Microsoft.AspNet.Server.Kestrel.Filter; using Microsoft.AspNet.Server.Kestrel.Infrastructure; namespace Microsoft.AspNet.Server.Kestrel.Http @@ -23,13 +24,15 @@ namespace Microsoft.AspNet.Server.Kestrel.Http public ListenerContext(ListenerContext listenerContext) : base(listenerContext) { + ServerAddress = listenerContext.ServerAddress; Thread = listenerContext.Thread; Application = listenerContext.Application; - Memory = listenerContext.Memory; Memory2 = listenerContext.Memory2; Log = listenerContext.Log; } + public ServerAddress ServerAddress { get; set; } + public KestrelThread Thread { get; set; } public Func Application { get; set; } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerPrimary.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerPrimary.cs index 15b0e904e8..41aeeb3bfa 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerPrimary.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerPrimary.cs @@ -31,13 +31,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http public async Task StartAsync( string pipeName, - string scheme, - string host, - int port, + ServerAddress address, KestrelThread thread, Func application) { - await StartAsync(scheme, host, port, thread, application).ConfigureAwait(false); + await StartAsync(address, thread, application).ConfigureAwait(false); await Thread.PostAsync(_ => { diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerSecondary.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerSecondary.cs index 37c9c3cc70..1f4e34a4bf 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerSecondary.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerSecondary.cs @@ -24,9 +24,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http public Task StartAsync( string pipeName, + ServerAddress address, KestrelThread thread, Func application) { + ServerAddress = address; Thread = thread; Application = application; diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/MessageBody.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/MessageBody.cs index e60647700e..c6afad0e77 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/MessageBody.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/MessageBody.cs @@ -106,27 +106,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { } - public override async Task ReadAsyncImplementation(ArraySegment buffer, CancellationToken cancellationToken) + public override Task ReadAsyncImplementation(ArraySegment buffer, CancellationToken cancellationToken) { - var input = _context.SocketInput; - while (true) - { - await input; - - var begin = input.ConsumingStart(); - int actual; - var end = begin.CopyTo(buffer.Array, buffer.Offset, buffer.Count, out actual); - input.ConsumingComplete(end, end); - - if (actual != 0) - { - return actual; - } - if (input.RemoteIntakeFin) - { - return 0; - } - } + return _context.SocketInput.ReadAsync(buffer); } } @@ -147,30 +129,22 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { var input = _context.SocketInput; - while (true) + var limit = Math.Min(buffer.Count, _inputLength); + if (limit == 0) { - var limit = Math.Min(buffer.Count, _inputLength); - if (limit == 0) - { - return 0; - } - - await input; - - var begin = input.ConsumingStart(); - int actual; - var end = begin.CopyTo(buffer.Array, buffer.Offset, limit, out actual); - _inputLength -= actual; - input.ConsumingComplete(end, end); - if (actual != 0) - { - return actual; - } - if (input.RemoteIntakeFin) - { - throw new InvalidDataException("Unexpected end of request content"); - } + return 0; } + + var limitedBuffer = new ArraySegment(buffer.Array, buffer.Offset, limit); + var actual = await _context.SocketInput.ReadAsync(limitedBuffer); + _inputLength -= actual; + + if (actual == 0) + { + throw new InvalidDataException("Unexpected end of request content"); + } + + return actual; } } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/PipeListener.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/PipeListener.cs index 3e5a4a5d56..4c3e35f799 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/PipeListener.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/PipeListener.cs @@ -20,11 +20,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http /// /// Creates the socket used to listen for incoming connections /// - protected override UvStreamHandle CreateListenSocket(string host, int port) + protected override UvStreamHandle CreateListenSocket() { var socket = new UvPipeHandle(Log); socket.Init(Thread.Loop, false); - socket.Bind(host); + socket.Bind(ServerAddress.UnixPipePath); socket.Listen(Constants.ListenBacklog, ConnectionCallback, this); return socket; } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/PipeListenerPrimary.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/PipeListenerPrimary.cs index a9ef09ce75..1f7eb285e9 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/PipeListenerPrimary.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/PipeListenerPrimary.cs @@ -20,11 +20,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http /// /// Creates the socket used to listen for incoming connections /// - protected override UvStreamHandle CreateListenSocket(string host, int port) + protected override UvStreamHandle CreateListenSocket() { var socket = new UvPipeHandle(Log); socket.Init(Thread.Loop, false); - socket.Bind(host); + socket.Bind(ServerAddress.UnixPipePath); socket.Listen(Constants.ListenBacklog, ConnectionCallback, this); return socket; } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketInputExtensions.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketInputExtensions.cs new file mode 100644 index 0000000000..9c5d690707 --- /dev/null +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketInputExtensions.cs @@ -0,0 +1,33 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Threading.Tasks; + +namespace Microsoft.AspNet.Server.Kestrel.Http +{ + public static class SocketInputExtensions + { + public static async Task ReadAsync(this SocketInput input, ArraySegment buffer) + { + while (true) + { + await input; + + var begin = input.ConsumingStart(); + int actual; + var end = begin.CopyTo(buffer.Array, buffer.Offset, buffer.Count, out actual); + input.ConsumingComplete(end, end); + + if (actual != 0) + { + return actual; + } + if (input.RemoteIntakeFin) + { + return 0; + } + } + } + } +} diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs index 0eed51d7d3..d0d218ac5a 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs @@ -114,6 +114,25 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } + public void End(ProduceEndType endType) + { + switch (endType) + { + case ProduceEndType.SocketShutdownSend: + Write(default(ArraySegment), (error, state, calledInline) => { }, null, + immediate: true, + socketShutdownSend: true, + socketDisconnect: false); + break; + case ProduceEndType.SocketDisconnect: + Write(default(ArraySegment), (error, state, calledInline) => { }, null, + immediate: true, + socketShutdownSend: false, + socketDisconnect: true); + break; + } + } + private void ScheduleWrite() { _thread.Post(_this => _this.WriteAllPending(), this); @@ -295,25 +314,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return tcs.Task; } - void ISocketOutput.End(ProduceEndType endType) - { - switch (endType) - { - case ProduceEndType.SocketShutdownSend: - Write(default(ArraySegment), (error, state, calledInline) => { }, null, - immediate: true, - socketShutdownSend: true, - socketDisconnect: false); - break; - case ProduceEndType.SocketDisconnect: - Write(default(ArraySegment), (error, state, calledInline) => { }, null, - immediate: true, - socketShutdownSend: false, - socketDisconnect: true); - break; - } - } - private class CallbackContext { // callback(error, state, calledInline) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/TcpListener.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/TcpListener.cs index 4d0e250adf..b09d86a43c 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/TcpListener.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/TcpListener.cs @@ -21,11 +21,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http /// /// Creates the socket used to listen for incoming connections /// - protected override UvStreamHandle CreateListenSocket(string host, int port) + protected override UvStreamHandle CreateListenSocket() { var socket = new UvTcpHandle(Log); socket.Init(Thread.Loop, Thread.QueueCloseHandle); - socket.Bind(host, port); + socket.Bind(ServerAddress); socket.Listen(Constants.ListenBacklog, ConnectionCallback, this); return socket; } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/TcpListenerPrimary.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/TcpListenerPrimary.cs index bc46f5bd9a..700e888195 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/TcpListenerPrimary.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/TcpListenerPrimary.cs @@ -21,11 +21,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http /// /// Creates the socket used to listen for incoming connections /// - protected override UvStreamHandle CreateListenSocket(string host, int port) + protected override UvStreamHandle CreateListenSocket() { var socket = new UvTcpHandle(Log); socket.Init(Thread.Loop, Thread.QueueCloseHandle); - socket.Bind(host, port); + socket.Bind(ServerAddress); socket.Listen(Constants.ListenBacklog, ConnectionCallback, this); return socket; } diff --git a/src/Microsoft.AspNet.Server.Kestrel/IKestrelServerInformation.cs b/src/Microsoft.AspNet.Server.Kestrel/IKestrelServerInformation.cs index b9bd5641f9..5e90ebdfc7 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/IKestrelServerInformation.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/IKestrelServerInformation.cs @@ -1,10 +1,14 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using Microsoft.AspNet.Server.Kestrel.Filter; + namespace Microsoft.AspNet.Server.Kestrel { public interface IKestrelServerInformation { int ThreadCount { get; set; } + + IConnectionFilter ConnectionFilter { get; set; } } } diff --git a/src/Microsoft.AspNet.Server.Kestrel/KestrelEngine.cs b/src/Microsoft.AspNet.Server.Kestrel/KestrelEngine.cs index f65cafb855..e78d6c7e9f 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/KestrelEngine.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/KestrelEngine.cs @@ -98,15 +98,11 @@ namespace Microsoft.AspNet.Server.Kestrel Threads.Clear(); } - public IDisposable CreateServer(string scheme, string host, int port, Func application) + public IDisposable CreateServer(ServerAddress address, Func application) { var listeners = new List(); - var usingPipes = host.StartsWith(Constants.UnixPipeHostPrefix); - if (usingPipes) - { - // Subtract one because we want to include the '/' character that starts the path. - host = host.Substring(Constants.UnixPipeHostPrefix.Length - 1); - } + + var usingPipes = address.IsUnixPipe; try { @@ -123,7 +119,7 @@ namespace Microsoft.AspNet.Server.Kestrel (Listener) new PipeListener(this) : new TcpListener(this); listeners.Add(listener); - listener.StartAsync(scheme, host, port, thread, application).Wait(); + listener.StartAsync(address, thread, application).Wait(); } else if (first) { @@ -132,7 +128,7 @@ namespace Microsoft.AspNet.Server.Kestrel : new TcpListenerPrimary(this); listeners.Add(listener); - listener.StartAsync(pipeName, scheme, host, port, thread, application).Wait(); + listener.StartAsync(pipeName, address, thread, application).Wait(); } else { @@ -140,7 +136,7 @@ namespace Microsoft.AspNet.Server.Kestrel ? (ListenerSecondary) new PipeListenerSecondary(this) : new TcpListenerSecondary(this); listeners.Add(listener); - listener.StartAsync(pipeName, thread, application).Wait(); + listener.StartAsync(pipeName, address, thread, application).Wait(); } first = false; diff --git a/src/Microsoft.AspNet.Server.Kestrel/KestrelServerInformation.cs b/src/Microsoft.AspNet.Server.Kestrel/KestrelServerInformation.cs index a6ca56c1ee..3f50057c5d 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/KestrelServerInformation.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/KestrelServerInformation.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using Microsoft.AspNet.Server.Features; +using Microsoft.AspNet.Server.Kestrel.Filter; using Microsoft.Extensions.Configuration; namespace Microsoft.AspNet.Server.Kestrel @@ -14,6 +15,8 @@ namespace Microsoft.AspNet.Server.Kestrel public int ThreadCount { get; set; } + public IConnectionFilter ConnectionFilter { get; set; } + public void Initialize(IConfiguration configuration) { var urls = configuration["server.urls"] ?? string.Empty; diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvTcpHandle.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvTcpHandle.cs index 55681bfbe5..c5d4e25e63 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvTcpHandle.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvTcpHandle.cs @@ -33,9 +33,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking _uv.tcp_init(loop, this); } - public void Bind(string host, int port) + public void Bind(ServerAddress address) { - var endpoint = CreateIPEndpoint(host, port); + var endpoint = CreateIPEndpoint(address); Libuv.sockaddr addr; var addressText = endpoint.Address.ToString(); @@ -65,14 +65,14 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking /// Returns an for the given host an port. /// If the host parameter isn't "localhost" or an IP address, use IPAddress.Any. /// - public static IPEndPoint CreateIPEndpoint(string host, int port) + public static IPEndPoint CreateIPEndpoint(ServerAddress address) { // TODO: IPv6 support IPAddress ip; - if (!IPAddress.TryParse(host, out ip)) + if (!IPAddress.TryParse(address.Host, out ip)) { - if (string.Equals(host, "localhost", StringComparison.OrdinalIgnoreCase)) + if (string.Equals(address.Host, "localhost", StringComparison.OrdinalIgnoreCase)) { ip = IPAddress.Loopback; } @@ -82,7 +82,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking } } - return new IPEndPoint(ip, port); + return new IPEndPoint(ip, address.Port); } } } diff --git a/src/Microsoft.AspNet.Server.Kestrel/ServerAddress.cs b/src/Microsoft.AspNet.Server.Kestrel/ServerAddress.cs index 4599e0a061..7f910ce959 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/ServerAddress.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/ServerAddress.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Diagnostics; using System.Globalization; using Microsoft.AspNet.Server.Kestrel.Infrastructure; @@ -14,6 +15,24 @@ namespace Microsoft.AspNet.Server.Kestrel public int Port { get; private set; } public string Scheme { get; private set; } + public bool IsUnixPipe + { + get + { + return Host.StartsWith(Constants.UnixPipeHostPrefix); + } + } + + public string UnixPipePath + { + get + { + Debug.Assert(IsUnixPipe); + + return Host.Substring(Constants.UnixPipeHostPrefix.Length - 1); + } + } + public override string ToString() { return Scheme.ToLowerInvariant() + "://" + Host.ToLowerInvariant() + ":" + Port.ToString(CultureInfo.InvariantCulture) + Path.ToLowerInvariant(); diff --git a/src/Microsoft.AspNet.Server.Kestrel/ServerFactory.cs b/src/Microsoft.AspNet.Server.Kestrel/ServerFactory.cs index f1fc15c88e..ed441bc95d 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/ServerFactory.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/ServerFactory.cs @@ -59,7 +59,8 @@ namespace Microsoft.AspNet.Server.Kestrel { AppShutdown = _appShutdownService, Log = new KestrelTrace(_logger), - DateHeaderValueManager = dateHeaderValueManager + DateHeaderValueManager = dateHeaderValueManager, + ConnectionFilter = information.ConnectionFilter }); disposables.Push(engine); @@ -86,9 +87,7 @@ namespace Microsoft.AspNet.Server.Kestrel { atLeastOneListener = true; disposables.Push(engine.CreateServer( - parsedAddress.Scheme, - parsedAddress.Host, - parsedAddress.Port, + parsedAddress, async frame => { var request = new ServerRequest(frame); diff --git a/src/Microsoft.AspNet.Server.Kestrel/ServiceContext.cs b/src/Microsoft.AspNet.Server.Kestrel/ServiceContext.cs index 8a29d2e380..317cfcf274 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/ServiceContext.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/ServiceContext.cs @@ -1,6 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using Microsoft.AspNet.Server.Kestrel.Filter; using Microsoft.AspNet.Server.Kestrel.Http; using Microsoft.AspNet.Server.Kestrel.Infrastructure; using Microsoft.Dnx.Runtime; @@ -20,6 +21,7 @@ namespace Microsoft.AspNet.Server.Kestrel Memory = context.Memory; Log = context.Log; DateHeaderValueManager = context.DateHeaderValueManager; + ConnectionFilter = context.ConnectionFilter; } public IApplicationShutdown AppShutdown { get; set; } @@ -29,5 +31,7 @@ namespace Microsoft.AspNet.Server.Kestrel public IKestrelTrace Log { get; set; } public DateHeaderValueManager DateHeaderValueManager { get; set; } + + public IConnectionFilter ConnectionFilter { get; set; } } } diff --git a/test/Microsoft.AspNet.Server.KestrelTests/CreateIPEndpointTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/CreateIPEndpointTests.cs index 716a528721..5cc5c2345c 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/CreateIPEndpointTests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/CreateIPEndpointTests.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Net; +using Microsoft.AspNet.Server.Kestrel; using Microsoft.AspNet.Server.Kestrel.Networking; using Xunit; @@ -16,7 +17,7 @@ namespace Microsoft.AspNet.Server.KestrelTests public void CorrectIPEndpointsAreCreated(string host, string expectedAddress) { // "0.0.0.0" is IPAddress.Any - var endpoint = UvTcpHandle.CreateIPEndpoint(host, 5000); + var endpoint = UvTcpHandle.CreateIPEndpoint(ServerAddress.FromUrl($"http://{host}:5000/")); Assert.NotNull(endpoint); Assert.Equal(IPAddress.Parse(expectedAddress), endpoint.Address); Assert.Equal(5000, endpoint.Port); diff --git a/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs index 0d7ad85fae..10424fbc54 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs @@ -88,7 +88,8 @@ namespace Microsoft.AspNet.Server.KestrelTests { var engine = new KestrelEngine(LibraryManager, new TestServiceContext()); engine.Start(1); - var started = engine.CreateServer("http", "localhost", 54321, App); + var address = ServerAddress.FromUrl("http://localhost:54321/"); + var started = engine.CreateServer(address, App); started.Dispose(); engine.Dispose(); } @@ -99,7 +100,8 @@ namespace Microsoft.AspNet.Server.KestrelTests { var engine = new KestrelEngine(LibraryManager, new TestServiceContext()); engine.Start(1); - var started = engine.CreateServer("http", "localhost", 54321, App); + var address = ServerAddress.FromUrl("http://localhost:54321/"); + var started = engine.CreateServer(address, App); Console.WriteLine("Started"); var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); diff --git a/test/Microsoft.AspNet.Server.KestrelTests/MultipleLoopTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/MultipleLoopTests.cs index c8b8a1de04..224f90f270 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/MultipleLoopTests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/MultipleLoopTests.cs @@ -166,7 +166,8 @@ namespace Microsoft.AspNet.Server.KestrelTests var serverListenTcp = new UvTcpHandle(_logger); serverListenTcp.Init(loop); - serverListenTcp.Bind("0.0.0.0", 54321); + var address = ServerAddress.FromUrl("http://localhost:54321/"); + serverListenTcp.Bind(address); serverListenTcp.Listen(128, (_1, status, error, _2) => { var serverConnectionTcp = new UvTcpHandle(_logger); diff --git a/test/Microsoft.AspNet.Server.KestrelTests/NetworkingTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/NetworkingTests.cs index 8d9eab7df7..9e4635f175 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/NetworkingTests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/NetworkingTests.cs @@ -81,7 +81,8 @@ namespace Microsoft.AspNet.Server.KestrelTests loop.Init(_uv); var tcp = new UvTcpHandle(_logger); tcp.Init(loop); - tcp.Bind("localhost", 0); + var address = ServerAddress.FromUrl("http://localhost:0/"); + tcp.Bind(address); tcp.Dispose(); loop.Run(); loop.Dispose(); @@ -95,7 +96,8 @@ namespace Microsoft.AspNet.Server.KestrelTests loop.Init(_uv); var tcp = new UvTcpHandle(_logger); tcp.Init(loop); - tcp.Bind("localhost", 54321); + var address = ServerAddress.FromUrl("http://localhost:54321/"); + tcp.Bind(address); tcp.Listen(10, (stream, status, error, state) => { var tcp2 = new UvTcpHandle(_logger); @@ -132,7 +134,8 @@ namespace Microsoft.AspNet.Server.KestrelTests loop.Init(_uv); var tcp = new UvTcpHandle(_logger); tcp.Init(loop); - tcp.Bind("localhost", 54321); + var address = ServerAddress.FromUrl("http://localhost:54321/"); + tcp.Bind(address); tcp.Listen(10, (_, status, error, state) => { Console.WriteLine("Connected"); @@ -188,7 +191,8 @@ namespace Microsoft.AspNet.Server.KestrelTests loop.Init(_uv); var tcp = new UvTcpHandle(_logger); tcp.Init(loop); - tcp.Bind("localhost", 54321); + var address = ServerAddress.FromUrl("http://localhost:54321/"); + tcp.Bind(address); tcp.Listen(10, (_, status, error, state) => { Console.WriteLine("Connected"); diff --git a/test/Microsoft.AspNet.Server.KestrelTests/SocketOutputTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/SocketOutputTests.cs index b636cbf5cd..8e0425ce52 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/SocketOutputTests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/SocketOutputTests.cs @@ -37,7 +37,7 @@ namespace Microsoft.AspNet.Server.KestrelTests kestrelEngine.Start(count: 1); var kestrelThread = kestrelEngine.Threads[0]; - var socket = new MockSocket(kestrelThread.Loop.ThreadId, new KestrelTrace(new TestKestrelTrace())); + var socket = new MockSocket(kestrelThread.Loop.ThreadId, new TestKestrelTrace()); var trace = new KestrelTrace(new TestKestrelTrace()); var socketOutput = new SocketOutput(kestrelThread, socket, 0, trace); @@ -82,7 +82,7 @@ namespace Microsoft.AspNet.Server.KestrelTests kestrelEngine.Start(count: 1); var kestrelThread = kestrelEngine.Threads[0]; - var socket = new MockSocket(kestrelThread.Loop.ThreadId, new KestrelTrace(new TestKestrelTrace())); + var socket = new MockSocket(kestrelThread.Loop.ThreadId, new TestKestrelTrace()); var trace = new KestrelTrace(new TestKestrelTrace()); var socketOutput = new SocketOutput(kestrelThread, socket, 0, trace); diff --git a/test/Microsoft.AspNet.Server.KestrelTests/TestServer.cs b/test/Microsoft.AspNet.Server.KestrelTests/TestServer.cs index 7ad0141810..667ecdd6c7 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/TestServer.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/TestServer.cs @@ -52,9 +52,7 @@ namespace Microsoft.AspNet.Server.KestrelTests new TestServiceContext()); _engine.Start(1); _server = _engine.CreateServer( - "http", - "localhost", - 54321, + ServerAddress.FromUrl("http://localhost:54321/"), app); } From 0844369f5fdf2954cb687098534c6f83c20db949 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Wed, 30 Sep 2015 16:31:16 -0700 Subject: [PATCH 0311/1662] Add unit tests for ConectionFilters and HTTPS - Run all the EngineTests with and without a ConnectionFilter --- samples/SampleApp/Startup.cs | 21 ++ samples/SampleApp/project.json | 7 +- .../ConnectionFilterTests.cs | 178 ++++++++++++++++ .../EngineTests.cs | 190 +++++++++++------- .../HttpsConnectionFilterTests.cs | 74 +++++++ .../TestResources/testCert.cer | Bin 0 -> 759 bytes .../TestServer.cs | 17 +- .../project.json | 10 +- 8 files changed, 413 insertions(+), 84 deletions(-) create mode 100644 test/Microsoft.AspNet.Server.KestrelTests/ConnectionFilterTests.cs create mode 100644 test/Microsoft.AspNet.Server.KestrelTests/HttpsConnectionFilterTests.cs create mode 100644 test/Microsoft.AspNet.Server.KestrelTests/TestResources/testCert.cer diff --git a/samples/SampleApp/Startup.cs b/samples/SampleApp/Startup.cs index f471f345cb..c9a27b42ff 100644 --- a/samples/SampleApp/Startup.cs +++ b/samples/SampleApp/Startup.cs @@ -6,6 +6,12 @@ using Microsoft.AspNet.Builder; using Microsoft.AspNet.Http; using Microsoft.Extensions.Logging; +#if DNX451 +using System.IO; +using System.Security.Cryptography.X509Certificates; +using Microsoft.AspNet.Server.Kestrel.Https; +#endif + namespace SampleApp { public class Startup @@ -16,6 +22,21 @@ namespace SampleApp loggerFactory.AddConsole(LogLevel.Debug); +#if DNX451 + var testCertPath = Path.Combine( + Environment.CurrentDirectory, + @"../../test/Microsoft.AspNet.Server.KestrelTests/TestResources/testCert.cer"); + + if (File.Exists(testCertPath)) + { + app.UseKestrelHttps(new X509Certificate2(testCertPath)); + } + else + { + Console.WriteLine("Could not find certificate at '{0}'. HTTPS is not enabled.", testCertPath); + } +#endif + app.Run(async context => { Console.WriteLine("{0} {1}{2}{3}", diff --git a/samples/SampleApp/project.json b/samples/SampleApp/project.json index f4b23cfc64..fb159ea155 100644 --- a/samples/SampleApp/project.json +++ b/samples/SampleApp/project.json @@ -17,9 +17,8 @@ } }, "commands": { - "web": "Microsoft.AspNet.Hosting --server Microsoft.AspNet.Server.Kestrel", - "run": "Microsoft.AspNet.Server.Kestrel", - "run-socket": "Microsoft.AspNet.Server.Kestrel --server.urls http://unix:/tmp/kestrel-test.sock", - "kestrel": "Microsoft.AspNet.Server.Kestrel --server.urls http://localhost:5000;https://localhost:5001" + "web": "Microsoft.AspNet.Hosting --server Microsoft.AspNet.Server.Kestrel --server.urls http://localhost:5000;https://localhost:5001", + "kestrel": "Microsoft.AspNet.Server.Kestrel --server.urls http://localhost:5000;https://localhost:5001", + "run-socket": "Microsoft.AspNet.Server.Kestrel --server.urls http://unix:/tmp/kestrel-test.sock" } } diff --git a/test/Microsoft.AspNet.Server.KestrelTests/ConnectionFilterTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/ConnectionFilterTests.cs new file mode 100644 index 0000000000..20c5b8fc1b --- /dev/null +++ b/test/Microsoft.AspNet.Server.KestrelTests/ConnectionFilterTests.cs @@ -0,0 +1,178 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System.IO; +using System.Threading.Tasks; +using Microsoft.AspNet.Server.Kestrel.Filter; +using Microsoft.AspNet.Server.Kestrel.Http; +using Xunit; + +namespace Microsoft.AspNet.Server.KestrelTests +{ + public class ConnectionFilterTests + { + private async Task App(Frame frame) + { + frame.ResponseHeaders.Clear(); + while (true) + { + var buffer = new byte[8192]; + var count = await frame.RequestBody.ReadAsync(buffer, 0, buffer.Length); + if (count == 0) + { + break; + } + await frame.ResponseBody.WriteAsync(buffer, 0, count); + } + } + + [Fact] + public async Task CanReadAndWriteWithRewritingConnectionFilter() + { + var filter = new RewritingConnectionFilter(); + var serviceContext = new TestServiceContext() + { + ConnectionFilter = filter + }; + var sendString = "POST / HTTP/1.0\r\n\r\nHello World?"; + + using (var server = new TestServer(App, serviceContext)) + { + using (var connection = new TestConnection()) + { + // "?" changes to "!" + await connection.SendEnd(sendString); + await connection.ReceiveEnd( + "HTTP/1.0 200 OK", + "", + "Hello World!"); + } + } + + Assert.Equal(sendString.Length, filter.BytesRead); + } + + [Fact] + public async Task CanReadAndWriteWithAsyncConnectionFilter() + { + var serviceContext = new TestServiceContext() + { + ConnectionFilter = new AsyncConnectionFilter() + }; + + using (var server = new TestServer(App, serviceContext)) + { + using (var connection = new TestConnection()) + { + await connection.SendEnd( + "POST / HTTP/1.0", + "", + "Hello World?"); + await connection.ReceiveEnd( + "HTTP/1.0 200 OK", + "", + "Hello World!"); + } + } + } + + private class RewritingConnectionFilter : IConnectionFilter + { + private static Task _empty = Task.FromResult(null); + + private RewritingStream _rewritingStream; + + public Task OnConnection(ConnectionFilterContext context) + { + _rewritingStream = new RewritingStream(context.Connection); + context.Connection = _rewritingStream; + return _empty; + } + + public int BytesRead => _rewritingStream.BytesRead; + } + + private class AsyncConnectionFilter : IConnectionFilter + { + public async Task OnConnection(ConnectionFilterContext context) + { + var oldConnection = context.Connection; + + // Set Connection to null to ensure it isn't used until the returned task completes. + context.Connection = null; + await Task.Delay(100); + + context.Connection = new RewritingStream(oldConnection); + } + } + + private class RewritingStream : Stream + { + private readonly Stream _innerStream; + + public RewritingStream(Stream innerStream) + { + _innerStream = innerStream; + } + + public int BytesRead { get; private set; } + + public override bool CanRead => _innerStream.CanRead; + + public override bool CanSeek => _innerStream.CanSeek; + + public override bool CanWrite => _innerStream.CanWrite; + + public override long Length => _innerStream.Length; + + public override long Position + { + get + { + return _innerStream.Position; + } + set + { + _innerStream.Position = value; + } + } + + public override void Flush() + { + // No-op + } + + public override int Read(byte[] buffer, int offset, int count) + { + var actual = _innerStream.Read(buffer, offset, count); + + BytesRead += actual; + + return actual; + } + + public override long Seek(long offset, SeekOrigin origin) + { + return _innerStream.Seek(offset, origin); + } + + public override void SetLength(long value) + { + _innerStream.SetLength(value); + } + + public override void Write(byte[] buffer, int offset, int count) + { + for (int i = 0; i < buffer.Length; i++) + { + if (buffer[i] == '?') + { + buffer[i] = (byte)'!'; + } + } + + _innerStream.Write(buffer, offset, count); + } + } + } +} diff --git a/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs index 10424fbc54..72867771b8 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs @@ -8,6 +8,7 @@ using System.Net.Sockets; using System.Text; using System.Threading.Tasks; using Microsoft.AspNet.Server.Kestrel; +using Microsoft.AspNet.Server.Kestrel.Filter; using Microsoft.AspNet.Server.Kestrel.Http; using Microsoft.Dnx.Runtime; using Microsoft.Dnx.Runtime.Infrastructure; @@ -20,6 +21,25 @@ namespace Microsoft.AspNet.Server.KestrelTests /// public class EngineTests { + public static TheoryData ConnectionFilterData + { + get + { + return new TheoryData + { + { + new TestServiceContext() + }, + { + new TestServiceContext + { + ConnectionFilter = new NoOpConnectionFilter() + } + } + }; + } + } + private async Task App(Frame frame) { frame.ResponseHeaders.Clear(); @@ -75,18 +95,20 @@ namespace Microsoft.AspNet.Server.KestrelTests return Task.FromResult(null); } - [Fact] - public void EngineCanStartAndStop() + [Theory] + [MemberData(nameof(ConnectionFilterData))] + public void EngineCanStartAndStop(ServiceContext testContext) { - var engine = new KestrelEngine(LibraryManager, new TestServiceContext()); + var engine = new KestrelEngine(LibraryManager, testContext); engine.Start(1); engine.Dispose(); } - [Fact] - public void ListenerCanCreateAndDispose() + [Theory] + [MemberData(nameof(ConnectionFilterData))] + public void ListenerCanCreateAndDispose(ServiceContext testContext) { - var engine = new KestrelEngine(LibraryManager, new TestServiceContext()); + var engine = new KestrelEngine(LibraryManager, testContext); engine.Start(1); var address = ServerAddress.FromUrl("http://localhost:54321/"); var started = engine.CreateServer(address, App); @@ -94,11 +116,11 @@ namespace Microsoft.AspNet.Server.KestrelTests engine.Dispose(); } - - [Fact] - public void ConnectionCanReadAndWrite() + [Theory] + [MemberData(nameof(ConnectionFilterData))] + public void ConnectionCanReadAndWrite(ServiceContext testContext) { - var engine = new KestrelEngine(LibraryManager, new TestServiceContext()); + var engine = new KestrelEngine(LibraryManager, testContext); engine.Start(1); var address = ServerAddress.FromUrl("http://localhost:54321/"); var started = engine.CreateServer(address, App); @@ -119,10 +141,12 @@ namespace Microsoft.AspNet.Server.KestrelTests engine.Dispose(); } - [Fact] - public async Task Http10() + + [Theory] + [MemberData(nameof(ConnectionFilterData))] + public async Task Http10(ServiceContext testContext) { - using (var server = new TestServer(App)) + using (var server = new TestServer(App, testContext)) { using (var connection = new TestConnection()) { @@ -138,10 +162,12 @@ namespace Microsoft.AspNet.Server.KestrelTests } } - [Fact] - public async Task Http11() + + [Theory] + [MemberData(nameof(ConnectionFilterData))] + public async Task Http11(ServiceContext testContext) { - using (var server = new TestServer(AppChunked)) + using (var server = new TestServer(AppChunked, testContext)) { using (var connection = new TestConnection()) { @@ -165,11 +191,11 @@ namespace Microsoft.AspNet.Server.KestrelTests } } - - [Fact] - public async Task Http10ContentLength() + [Theory] + [MemberData(nameof(ConnectionFilterData))] + public async Task Http10ContentLength(ServiceContext testContext) { - using (var server = new TestServer(App)) + using (var server = new TestServer(App, testContext)) { using (var connection = new TestConnection()) { @@ -186,10 +212,11 @@ namespace Microsoft.AspNet.Server.KestrelTests } } - [Fact] - public async Task Http10TransferEncoding() + [Theory] + [MemberData(nameof(ConnectionFilterData))] + public async Task Http10TransferEncoding(ServiceContext testContext) { - using (var server = new TestServer(App)) + using (var server = new TestServer(App, testContext)) { using (var connection = new TestConnection()) { @@ -206,11 +233,11 @@ namespace Microsoft.AspNet.Server.KestrelTests } } - - [Fact] - public async Task Http10KeepAlive() + [Theory] + [MemberData(nameof(ConnectionFilterData))] + public async Task Http10KeepAlive(ServiceContext testContext) { - using (var server = new TestServer(AppChunked)) + using (var server = new TestServer(AppChunked, testContext)) { using (var connection = new TestConnection()) { @@ -235,10 +262,11 @@ namespace Microsoft.AspNet.Server.KestrelTests } } - [Fact] - public async Task Http10KeepAliveNotUsedIfResponseContentLengthNotSet() + [Theory] + [MemberData(nameof(ConnectionFilterData))] + public async Task Http10KeepAliveNotUsedIfResponseContentLengthNotSet(ServiceContext testContext) { - using (var server = new TestServer(App)) + using (var server = new TestServer(App, testContext)) { using (var connection = new TestConnection()) { @@ -264,8 +292,9 @@ namespace Microsoft.AspNet.Server.KestrelTests } } - [Fact] - public async Task Http10KeepAliveContentLength() + [Theory] + [MemberData(nameof(ConnectionFilterData))] + public async Task Http10KeepAliveContentLength(ServiceContext testContext) { using (var server = new TestServer(AppChunked)) { @@ -294,8 +323,9 @@ namespace Microsoft.AspNet.Server.KestrelTests } } - [Fact] - public async Task Http10KeepAliveTransferEncoding() + [Theory] + [MemberData(nameof(ConnectionFilterData))] + public async Task Http10KeepAliveTransferEncoding(ServiceContext testContext) { using (var server = new TestServer(AppChunked)) { @@ -325,10 +355,11 @@ namespace Microsoft.AspNet.Server.KestrelTests } } - [Fact] - public async Task Expect100ContinueForBody() + [Theory] + [MemberData(nameof(ConnectionFilterData))] + public async Task Expect100ContinueForBody(ServiceContext testContext) { - using (var server = new TestServer(AppChunked)) + using (var server = new TestServer(AppChunked, testContext)) { using (var connection = new TestConnection()) { @@ -350,11 +381,11 @@ namespace Microsoft.AspNet.Server.KestrelTests } } - - [Fact] - public async Task DisconnectingClient() + [Theory] + [MemberData(nameof(ConnectionFilterData))] + public async Task DisconnectingClient(ServiceContext testContext) { - using (var server = new TestServer(App)) + using (var server = new TestServer(App, testContext)) { var socket = new Socket(SocketType.Stream, ProtocolType.IP); socket.Connect(IPAddress.Loopback, 54321); @@ -375,10 +406,11 @@ namespace Microsoft.AspNet.Server.KestrelTests } } - [Fact] - public async Task ZeroContentLengthSetAutomaticallyAfterNoWrites() + [Theory] + [MemberData(nameof(ConnectionFilterData))] + public async Task ZeroContentLengthSetAutomaticallyAfterNoWrites(ServiceContext testContext) { - using (var server = new TestServer(EmptyApp)) + using (var server = new TestServer(EmptyApp, testContext)) { using (var connection = new TestConnection()) { @@ -402,10 +434,11 @@ namespace Microsoft.AspNet.Server.KestrelTests } } - [Fact] - public async Task ZeroContentLengthNotSetAutomaticallyForNonKeepAliveRequests() + [Theory] + [MemberData(nameof(ConnectionFilterData))] + public async Task ZeroContentLengthNotSetAutomaticallyForNonKeepAliveRequests(ServiceContext testContext) { - using (var server = new TestServer(EmptyApp)) + using (var server = new TestServer(EmptyApp, testContext)) { using (var connection = new TestConnection()) { @@ -435,10 +468,11 @@ namespace Microsoft.AspNet.Server.KestrelTests } } - [Fact] - public async Task ZeroContentLengthNotSetAutomaticallyForHeadRequests() + [Theory] + [MemberData(nameof(ConnectionFilterData))] + public async Task ZeroContentLengthNotSetAutomaticallyForHeadRequests(ServiceContext testContext) { - using (var server = new TestServer(EmptyApp)) + using (var server = new TestServer(EmptyApp, testContext)) { using (var connection = new TestConnection()) { @@ -454,8 +488,9 @@ namespace Microsoft.AspNet.Server.KestrelTests } } - [Fact] - public async Task ZeroContentLengthNotSetAutomaticallyForCertainStatusCodes() + [Theory] + [MemberData(nameof(ConnectionFilterData))] + public async Task ZeroContentLengthNotSetAutomaticallyForCertainStatusCodes(ServiceContext testContext) { using (var server = new TestServer(async frame => { @@ -466,7 +501,7 @@ namespace Microsoft.AspNet.Server.KestrelTests var statusString = await reader.ReadLineAsync(); frame.StatusCode = int.Parse(statusString); } - })) + }, testContext)) { using (var connection = new TestConnection()) { @@ -504,8 +539,9 @@ namespace Microsoft.AspNet.Server.KestrelTests } } - [Fact] - public async Task ThrowingResultsIn500Response() + [Theory] + [MemberData(nameof(ConnectionFilterData))] + public async Task ThrowingResultsIn500Response(ServiceContext testContext) { bool onStartingCalled = false; @@ -521,7 +557,7 @@ namespace Microsoft.AspNet.Server.KestrelTests frame.ResponseHeaders.Clear(); frame.ResponseHeaders["Content-Length"] = new[] { "11" }; throw new Exception(); - })) + }, testContext)) { using (var connection = new TestConnection()) { @@ -555,8 +591,9 @@ namespace Microsoft.AspNet.Server.KestrelTests } } - [Fact] - public async Task ThrowingAfterWritingKillsConnection() + [Theory] + [MemberData(nameof(ConnectionFilterData))] + public async Task ThrowingAfterWritingKillsConnection(ServiceContext testContext) { bool onStartingCalled = false; @@ -572,7 +609,7 @@ namespace Microsoft.AspNet.Server.KestrelTests frame.ResponseHeaders["Content-Length"] = new[] { "11" }; await frame.ResponseBody.WriteAsync(Encoding.ASCII.GetBytes("Hello World"), 0, 11); throw new Exception(); - })) + }, testContext)) { using (var connection = new TestConnection()) { @@ -591,8 +628,9 @@ namespace Microsoft.AspNet.Server.KestrelTests } } - [Fact] - public async Task ThrowingAfterPartialWriteKillsConnection() + [Theory] + [MemberData(nameof(ConnectionFilterData))] + public async Task ThrowingAfterPartialWriteKillsConnection(ServiceContext testContext) { bool onStartingCalled = false; @@ -608,7 +646,7 @@ namespace Microsoft.AspNet.Server.KestrelTests frame.ResponseHeaders["Content-Length"] = new[] { "11" }; await frame.ResponseBody.WriteAsync(Encoding.ASCII.GetBytes("Hello"), 0, 5); throw new Exception(); - })) + }, testContext)) { using (var connection = new TestConnection()) { @@ -627,10 +665,11 @@ namespace Microsoft.AspNet.Server.KestrelTests } } - [Fact] - public async Task ConnectionClosesWhenFinReceived() + [Theory] + [MemberData(nameof(ConnectionFilterData))] + public async Task ConnectionClosesWhenFinReceived(ServiceContext testContext) { - using (var server = new TestServer(AppChunked)) + using (var server = new TestServer(AppChunked, testContext)) { using (var connection = new TestConnection()) { @@ -653,10 +692,11 @@ namespace Microsoft.AspNet.Server.KestrelTests } } - [Fact] - public async Task ConnectionClosesWhenFinReceivedBeforeRequestCompletes() + [Theory] + [MemberData(nameof(ConnectionFilterData))] + public async Task ConnectionClosesWhenFinReceivedBeforeRequestCompletes(ServiceContext testContext) { - using (var server = new TestServer(AppChunked)) + using (var server = new TestServer(AppChunked, testContext)) { using (var connection = new TestConnection()) { @@ -694,8 +734,9 @@ namespace Microsoft.AspNet.Server.KestrelTests } } - [Fact] - public async Task ThrowingInOnStartingResultsIn500Response() + [Theory] + [MemberData(nameof(ConnectionFilterData))] + public async Task ThrowingInOnStartingResultsIn500Response(ServiceContext testContext) { using (var server = new TestServer(frame => { @@ -710,7 +751,7 @@ namespace Microsoft.AspNet.Server.KestrelTests // If we write to the response stream, we will not get a 500. return Task.FromResult(null); - })) + }, testContext)) { using (var connection = new TestConnection()) { @@ -742,8 +783,9 @@ namespace Microsoft.AspNet.Server.KestrelTests } } - [Fact] - public async Task ThrowingInOnStartingResultsInFailedWrites() + [Theory] + [MemberData(nameof(ConnectionFilterData))] + public async Task ThrowingInOnStartingResultsInFailedWrites(ServiceContext testContext) { using (var server = new TestServer(async frame => { @@ -764,7 +806,7 @@ namespace Microsoft.AspNet.Server.KestrelTests // The second write should succeed since the OnStarting callback will not be called again await frame.ResponseBody.WriteAsync(Encoding.ASCII.GetBytes("Exception!!"), 0, 11); - })) + }, testContext)) { using (var connection = new TestConnection()) { diff --git a/test/Microsoft.AspNet.Server.KestrelTests/HttpsConnectionFilterTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/HttpsConnectionFilterTests.cs new file mode 100644 index 0000000000..4a824be407 --- /dev/null +++ b/test/Microsoft.AspNet.Server.KestrelTests/HttpsConnectionFilterTests.cs @@ -0,0 +1,74 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +#if DNX451 +using System.Collections.Generic; +using System.Net; +using System.Net.Http; +using System.Net.Security; +using System.Security.Cryptography.X509Certificates; +using System.Threading.Tasks; +using Microsoft.AspNet.Server.Kestrel.Filter; +using Microsoft.AspNet.Server.Kestrel.Http; +using Microsoft.AspNet.Server.Kestrel.Https; +using Microsoft.AspNet.Testing.xunit; +using Xunit; + +namespace Microsoft.AspNet.Server.KestrelTests +{ + public class HttpsConnectionFilterTests + { + private async Task App(Frame frame) + { + frame.ResponseHeaders.Clear(); + while (true) + { + var buffer = new byte[8192]; + var count = await frame.RequestBody.ReadAsync(buffer, 0, buffer.Length); + if (count == 0) + { + break; + } + await frame.ResponseBody.WriteAsync(buffer, 0, count); + } + } + + // https://github.com/aspnet/KestrelHttpServer/issues/240 + // This test currently fails on mono because of an issue with SslStream. + [ConditionalFact] + [OSSkipCondition(OperatingSystems.Linux | OperatingSystems.MacOSX)] + public async Task CanReadAndWriteWithHttpsConnectionFilter() + { + RemoteCertificateValidationCallback validationCallback = + (sender, cert, chain, sslPolicyErrors) => true; + + try + { + ServicePointManager.ServerCertificateValidationCallback += validationCallback; + + var sereverAddress = "https://localhost:54321/"; + var serviceContext = new TestServiceContext() + { + ConnectionFilter = new HttpsConnectionFilter(new X509Certificate2(@"TestResources/testCert.cer"), new NoOpConnectionFilter()) + }; + + using (var server = new TestServer(App, serviceContext, sereverAddress)) + { + using (var client = new HttpClient()) + { + var result = await client.PostAsync(sereverAddress, new FormUrlEncodedContent(new[] { + new KeyValuePair("content", "Hello World?") + })); + + Assert.Equal("content=Hello+World%3F", await result.Content.ReadAsStringAsync()); + } + } + } + finally + { + ServicePointManager.ServerCertificateValidationCallback -= validationCallback; + } + } + } +} +#endif diff --git a/test/Microsoft.AspNet.Server.KestrelTests/TestResources/testCert.cer b/test/Microsoft.AspNet.Server.KestrelTests/TestResources/testCert.cer new file mode 100644 index 0000000000000000000000000000000000000000..75b57442b0b06daab6eee9a4471002367504aa94 GIT binary patch literal 759 zcmXqLV)|^*#CU%JGZP~dlR%07lTUkVe=Ku;yy#?0kJ zHs(+kW?{~p{N%)(jQrvf137VCLsJ7wLo)+2BO?Q&C?MAi&NYm}p{t2e$$*!QQ>)FR z?K>|cBO@yVa}y&!1JEU0Oihf83~S!O&2x2_dkOdV z!W;KjWScQ)MikBPUMYLFH~ZZr?!LbkygSakJ^N$@NA(QPnuMLN8t?DgVV0U7cvp8; z&H6~`Slx-cR!o$TdcOT{QP5Mz9%aormtUW9d32EbaG2nO-iqklrn*mNw{!0Y9+kd~l)u@frN__g<`%=-<{`jo@ z@H{2_*5%WkQ3@eKyH9>@bo?Ze{%^H#VC$6dIOXt@Ow5c7jEg-D+zniTAuh|vVrO8} zAh0xV%k)hQTV|drzdfBhQJ!a^81~?8!WWOgfM#T<+q&?}!uC@Re`RkS3jY5%YTYLL zItvEB-8Ov|!5dc!{Nn$bvSESLlcVeUw2nM3<(+Wq6kneK;{wOz)CwbODc9(;9f?k7 zZb!v<{Bf*#cJR%)XRofWRjMfWJ0n}M;N}#Um$C{OH}Cc4CMms}ddbPnf$`Vr55=Wt z?;1$P@caFin7Bgh>8Idh??scIulc#1b6?T-%iCh_RYaUnp6-A0&r5;&4U app) + : this(app, new TestServiceContext()) { - Create(app); + } + + public TestServer(Func app, ServiceContext context) + : this(app, context, "http://localhost:54321/") + { + } + public TestServer(Func app, ServiceContext context, string serverAddress) + { + Create(app, context, serverAddress); } ILibraryManager LibraryManager @@ -45,14 +54,14 @@ namespace Microsoft.AspNet.Server.KestrelTests } } - public void Create(Func app) + public void Create(Func app, ServiceContext context, string serverAddress) { _engine = new KestrelEngine( LibraryManager, - new TestServiceContext()); + context); _engine.Start(1); _server = _engine.CreateServer( - ServerAddress.FromUrl("http://localhost:54321/"), + ServerAddress.FromUrl(serverAddress), app); } diff --git a/test/Microsoft.AspNet.Server.KestrelTests/project.json b/test/Microsoft.AspNet.Server.KestrelTests/project.json index 907cb11eca..9cb03bd95e 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/project.json +++ b/test/Microsoft.AspNet.Server.KestrelTests/project.json @@ -2,10 +2,16 @@ "version": "1.0.0-*", "dependencies": { "xunit.runner.aspnet": "2.0.0-aspnet-*", - "Microsoft.AspNet.Server.Kestrel": "1.0.0-*" + "Microsoft.AspNet.Server.Kestrel": "1.0.0-*", + "Microsoft.AspNet.Testing": "1.0.0-*" }, "frameworks": { - "dnx451": { }, + "dnx451": { + "dependencies": { + "System.Net.Http": "4.0.1-beta-*", + "Microsoft.AspNet.Server.Kestrel.Https": "1.0.0-*" + } + }, "dnxcore50": { "dependencies": { "System.Diagnostics.TraceSource": "4.0.0-beta-*", From 8fc8307ad239922dc66edfdbd9aec758c5812651 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Fri, 2 Oct 2015 16:25:32 -0700 Subject: [PATCH 0312/1662] Embed private key with the test X.509 certificate - Use the PKCS #12 certificate format to enable this --- samples/SampleApp/Startup.cs | 9 +++++---- .../HttpsConnectionFilterTests.cs | 4 +++- .../TestResources/testCert.cer | Bin 759 -> 0 bytes .../TestResources/testCert.pfx | Bin 0 -> 2483 bytes 4 files changed, 8 insertions(+), 5 deletions(-) delete mode 100644 test/Microsoft.AspNet.Server.KestrelTests/TestResources/testCert.cer create mode 100644 test/Microsoft.AspNet.Server.KestrelTests/TestResources/testCert.pfx diff --git a/samples/SampleApp/Startup.cs b/samples/SampleApp/Startup.cs index c9a27b42ff..2f18d72aed 100644 --- a/samples/SampleApp/Startup.cs +++ b/samples/SampleApp/Startup.cs @@ -5,6 +5,7 @@ using System; using Microsoft.AspNet.Builder; using Microsoft.AspNet.Http; using Microsoft.Extensions.Logging; +using Microsoft.Dnx.Runtime; #if DNX451 using System.IO; @@ -16,7 +17,7 @@ namespace SampleApp { public class Startup { - public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory) + public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory, IApplicationEnvironment env) { loggerFactory.MinimumLevel = LogLevel.Debug; @@ -24,12 +25,12 @@ namespace SampleApp #if DNX451 var testCertPath = Path.Combine( - Environment.CurrentDirectory, - @"../../test/Microsoft.AspNet.Server.KestrelTests/TestResources/testCert.cer"); + env.ApplicationBasePath, + @"../../test/Microsoft.AspNet.Server.KestrelTests/TestResources/testCert.pfx"); if (File.Exists(testCertPath)) { - app.UseKestrelHttps(new X509Certificate2(testCertPath)); + app.UseKestrelHttps(new X509Certificate2(testCertPath, "testPassword")); } else { diff --git a/test/Microsoft.AspNet.Server.KestrelTests/HttpsConnectionFilterTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/HttpsConnectionFilterTests.cs index 4a824be407..48167e7e68 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/HttpsConnectionFilterTests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/HttpsConnectionFilterTests.cs @@ -49,7 +49,9 @@ namespace Microsoft.AspNet.Server.KestrelTests var sereverAddress = "https://localhost:54321/"; var serviceContext = new TestServiceContext() { - ConnectionFilter = new HttpsConnectionFilter(new X509Certificate2(@"TestResources/testCert.cer"), new NoOpConnectionFilter()) + ConnectionFilter = new HttpsConnectionFilter( + new X509Certificate2(@"TestResources/testCert.pfx", "testPassword"), + new NoOpConnectionFilter()) }; using (var server = new TestServer(App, serviceContext, sereverAddress)) diff --git a/test/Microsoft.AspNet.Server.KestrelTests/TestResources/testCert.cer b/test/Microsoft.AspNet.Server.KestrelTests/TestResources/testCert.cer deleted file mode 100644 index 75b57442b0b06daab6eee9a4471002367504aa94..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 759 zcmXqLV)|^*#CU%JGZP~dlR%07lTUkVe=Ku;yy#?0kJ zHs(+kW?{~p{N%)(jQrvf137VCLsJ7wLo)+2BO?Q&C?MAi&NYm}p{t2e$$*!QQ>)FR z?K>|cBO@yVa}y&!1JEU0Oihf83~S!O&2x2_dkOdV z!W;KjWScQ)MikBPUMYLFH~ZZr?!LbkygSakJ^N$@NA(QPnuMLN8t?DgVV0U7cvp8; z&H6~`Slx-cR!o$TdcOT{QP5Mz9%aormtUW9d32EbaG2nO-iqklrn*mNw{!0Y9+kd~l)u@frN__g<`%=-<{`jo@ z@H{2_*5%WkQ3@eKyH9>@bo?Ze{%^H#VC$6dIOXt@Ow5c7jEg-D+zniTAuh|vVrO8} zAh0xV%k)hQTV|drzdfBhQJ!a^81~?8!WWOgfM#T<+q&?}!uC@Re`RkS3jY5%YTYLL zItvEB-8Ov|!5dc!{Nn$bvSESLlcVeUw2nM3<(+Wq6kneK;{wOz)CwbODc9(;9f?k7 zZb!v<{Bf*#cJR%)XRofWRjMfWJ0n}M;N}#Um$C{OH}Cc4CMms}ddb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vo7cEX!szCT}iX-K^2 w#3o+=C+lQz2J+SOEzVX(eJ)e7=eicC{rr9U2VGDcdH?_b literal 0 HcmV?d00001 From f545f99dab5d5676f39089567f0a63818cbad32d Mon Sep 17 00:00:00 2001 From: Ryan Nowak Date: Mon, 5 Oct 2015 11:22:30 -0700 Subject: [PATCH 0313/1662] Add attributes to fix the build --- .../Properties/AssemblyInfo.cs | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 src/Microsoft.AspNet.Server.Kestrel.Https/Properties/AssemblyInfo.cs diff --git a/src/Microsoft.AspNet.Server.Kestrel.Https/Properties/AssemblyInfo.cs b/src/Microsoft.AspNet.Server.Kestrel.Https/Properties/AssemblyInfo.cs new file mode 100644 index 0000000000..7c3af07032 --- /dev/null +++ b/src/Microsoft.AspNet.Server.Kestrel.Https/Properties/AssemblyInfo.cs @@ -0,0 +1,9 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System.Reflection; +using System.Resources; +using System.Runtime.CompilerServices; + +[assembly: AssemblyMetadata("Serviceable", "True")] +[assembly: NeutralResourcesLanguage("en-us")] From 1f50f4c2a87c961482c0922a56182f36d622da41 Mon Sep 17 00:00:00 2001 From: Chris R Date: Mon, 5 Oct 2015 15:14:18 -0700 Subject: [PATCH 0314/1662] #231 bind to IPv6Any, add functional tests. --- KestrelHttpServer.sln | 7 ++ .../Networking/UvTcpHandle.cs | 2 +- .../AddressRegistrationTests.cs | 75 +++++++++++++++++++ ...spNet.Server.Kestrel.FunctionalTests.xproj | 21 ++++++ .../RequestTests.cs | 71 ++++++++++++++++++ .../ResponseTests.cs | 73 ++++++++++++++++++ .../ThreadCountTests.cs | 74 ++++++++++++++++++ .../project.json | 19 +++++ .../CreateIPEndpointTests.cs | 7 +- .../TestInput.cs | 6 +- 10 files changed, 349 insertions(+), 6 deletions(-) create mode 100644 test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs create mode 100644 test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/Microsoft.AspNet.Server.Kestrel.FunctionalTests.xproj create mode 100644 test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/RequestTests.cs create mode 100644 test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/ResponseTests.cs create mode 100644 test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/ThreadCountTests.cs create mode 100644 test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/project.json diff --git a/KestrelHttpServer.sln b/KestrelHttpServer.sln index f2da75a88c..a0670dfc2a 100644 --- a/KestrelHttpServer.sln +++ b/KestrelHttpServer.sln @@ -35,6 +35,8 @@ Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.Server.Kes EndProject Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.Server.Kestrel.Https", "src\Microsoft.AspNet.Server.Kestrel.Https\Microsoft.AspNet.Server.Kestrel.Https.xproj", "{5F64B3C3-0C2E-431A-B820-A81BBFC863DA}" EndProject +Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.Server.Kestrel.FunctionalTests", "test\Microsoft.AspNet.Server.Kestrel.FunctionalTests\Microsoft.AspNet.Server.Kestrel.FunctionalTests.xproj", "{9559A5F1-080C-4909-B6CF-7E4B3DC55748}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -73,6 +75,10 @@ Global {5F64B3C3-0C2E-431A-B820-A81BBFC863DA}.Debug|Any CPU.Build.0 = Debug|Any CPU {5F64B3C3-0C2E-431A-B820-A81BBFC863DA}.Release|Any CPU.ActiveCfg = Release|Any CPU {5F64B3C3-0C2E-431A-B820-A81BBFC863DA}.Release|Any CPU.Build.0 = Release|Any CPU + {9559A5F1-080C-4909-B6CF-7E4B3DC55748}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {9559A5F1-080C-4909-B6CF-7E4B3DC55748}.Debug|Any CPU.Build.0 = Debug|Any CPU + {9559A5F1-080C-4909-B6CF-7E4B3DC55748}.Release|Any CPU.ActiveCfg = Release|Any CPU + {9559A5F1-080C-4909-B6CF-7E4B3DC55748}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -86,5 +92,6 @@ Global {82295647-7C1C-4671-BAB6-0FEF58F949EC} = {327F7880-D9AF-46BD-B45C-3B7E34A01DFD} {8CBA6FE3-3CC9-4420-8AA3-123E983734C2} = {327F7880-D9AF-46BD-B45C-3B7E34A01DFD} {5F64B3C3-0C2E-431A-B820-A81BBFC863DA} = {2D5D5227-4DBD-499A-96B1-76A36B03B750} + {9559A5F1-080C-4909-B6CF-7E4B3DC55748} = {D3273454-EA07-41D2-BF0B-FCC3675C2483} EndGlobalSection EndGlobal diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvTcpHandle.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvTcpHandle.cs index c5d4e25e63..4e79ea9864 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvTcpHandle.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvTcpHandle.cs @@ -78,7 +78,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking } else { - ip = IPAddress.Any; + ip = IPAddress.IPv6Any; } } diff --git a/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs b/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs new file mode 100644 index 0000000000..b7b7b03877 --- /dev/null +++ b/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs @@ -0,0 +1,75 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System.Collections.Generic; +using System.Net.Http; +using System.Threading.Tasks; +using Microsoft.AspNet.Builder; +using Microsoft.AspNet.Hosting; +using Microsoft.AspNet.Http; +using Microsoft.AspNet.Http.Extensions; +using Microsoft.Dnx.Runtime.Infrastructure; +using Microsoft.Extensions.Configuration; +using Xunit; + +namespace Microsoft.AspNet.Server.Kestrel.FunctionalTests +{ + public class AddressRegistrationTests + { + [Theory, MemberData(nameof(AddressRegistrationData))] + public async Task RegisterAddresses_Success(string addressInput, string[] testUrls) + { + var config = new ConfigurationBuilder() + .AddInMemoryCollection(new Dictionary + { + { "server.urls", addressInput } + }) + .Build(); + + var hostBuilder = new WebHostBuilder(CallContextServiceLocator.Locator.ServiceProvider, config); + hostBuilder.UseServer("Microsoft.AspNet.Server.Kestrel"); + hostBuilder.UseStartup(ConfigureEchoAddress); + + using (var app = hostBuilder.Build().Start()) + { + using (var client = new HttpClient()) + { + foreach (var testUrl in testUrls) + { + var responseText = await client.GetStringAsync(testUrl); + Assert.Equal(testUrl, responseText); + } + } + } + } + + public static TheoryData AddressRegistrationData + { + get + { + var dataset = new TheoryData(); + dataset.Add("8787", new[] { "http://localhost:8787/" }); + dataset.Add("8787;8788", new[] { "http://localhost:8787/", "http://localhost:8788/" }); + dataset.Add("http://*:8787/", new[] { "http://localhost:8787/", "http://127.0.0.1:8787/", "http://[::1]:8787/" }); + dataset.Add("http://localhost:8787/", new[] { "http://localhost:8787/", "http://127.0.0.1:8787/", + /* // https://github.com/aspnet/KestrelHttpServer/issues/231 + "http://[::1]:8787/" + */ }); + dataset.Add("http://127.0.0.1:8787/", new[] { "http://127.0.0.1:8787/", }); + dataset.Add("http://[::1]:8787/", new[] { "http://[::1]:8787/", }); + dataset.Add("http://127.0.0.1:8787/;http://[::1]:8787/", new[] { "http://127.0.0.1:8787/", "http://[::1]:8787/" }); + dataset.Add("http://localhost:8787/base/path", new[] { "http://localhost:8787/base/path" }); + + return dataset; + } + } + + private void ConfigureEchoAddress(IApplicationBuilder app) + { + app.Run(context => + { + return context.Response.WriteAsync(context.Request.GetDisplayUrl()); + }); + } + } +} diff --git a/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/Microsoft.AspNet.Server.Kestrel.FunctionalTests.xproj b/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/Microsoft.AspNet.Server.Kestrel.FunctionalTests.xproj new file mode 100644 index 0000000000..d8807f6583 --- /dev/null +++ b/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/Microsoft.AspNet.Server.Kestrel.FunctionalTests.xproj @@ -0,0 +1,21 @@ + + + + 14.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + + + + 9559a5f1-080c-4909-b6cf-7e4b3dc55748 + Microsoft.AspNet.Server.Kestrel.FunctionalTests + ..\..\artifacts\obj\$(MSBuildProjectName) + ..\..\artifacts\bin\$(MSBuildProjectName)\ + + + 2.0 + + + + + + \ No newline at end of file diff --git a/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/RequestTests.cs b/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/RequestTests.cs new file mode 100644 index 0000000000..5819fc9738 --- /dev/null +++ b/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/RequestTests.cs @@ -0,0 +1,71 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System.Collections.Generic; +using System.Globalization; +using System.Net.Http; +using System.Threading.Tasks; +using Microsoft.AspNet.Builder; +using Microsoft.AspNet.Hosting; +using Microsoft.AspNet.Http; +using Microsoft.Dnx.Runtime.Infrastructure; +using Microsoft.Extensions.Configuration; +using Xunit; + +namespace Microsoft.AspNet.Server.Kestrel.FunctionalTests +{ + public class RequestTests + { + [Fact(Skip = "https://github.com/aspnet/KestrelHttpServer/issues/234")] + public async Task LargeUpload() + { + var config = new ConfigurationBuilder() + .AddInMemoryCollection(new Dictionary + { + { "server.urls", "http://localhost:8791/" } + }) + .Build(); + + var hostBuilder = new WebHostBuilder(CallContextServiceLocator.Locator.ServiceProvider, config); + hostBuilder.UseServer("Microsoft.AspNet.Server.Kestrel"); + hostBuilder.UseStartup(app => + { + app.Run(async context => + { + // Read the full request body + var total = 0; + var bytes = new byte[1024]; + var count = await context.Request.Body.ReadAsync(bytes, 0, bytes.Length); + while (count > 0) + { + for (int i = 0; i < count; i++) + { + Assert.Equal(total % 256, bytes[i]); + total++; + } + count = await context.Request.Body.ReadAsync(bytes, 0, bytes.Length); + } + + await context.Response.WriteAsync(total.ToString(CultureInfo.InvariantCulture)); + }); + }); + + using (var app = hostBuilder.Build().Start()) + { + using (var client = new HttpClient()) + { + var bytes = new byte[1024 * 1024]; + for (int i = 0; i < bytes.Length; i++) + { + bytes[i] = (byte)i; + } + + var response = await client.PostAsync("http://localhost:8791/", new ByteArrayContent(bytes)); + response.EnsureSuccessStatusCode(); + var sizeString = await response.Content.ReadAsStringAsync(); + Assert.Equal(sizeString, bytes.Length.ToString(CultureInfo.InvariantCulture)); + } + } + } + } +} diff --git a/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/ResponseTests.cs b/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/ResponseTests.cs new file mode 100644 index 0000000000..a31c2374fa --- /dev/null +++ b/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/ResponseTests.cs @@ -0,0 +1,73 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System.Collections.Generic; +using System.Net.Http; +using System.Threading.Tasks; +using Microsoft.AspNet.Builder; +using Microsoft.AspNet.Hosting; +using Microsoft.Dnx.Runtime.Infrastructure; +using Microsoft.Extensions.Configuration; +using Xunit; + +namespace Microsoft.AspNet.Server.Kestrel.FunctionalTests +{ + public class ResponseTests + { + [Fact] + public async Task LargeDownload() + { + var config = new ConfigurationBuilder() + .AddInMemoryCollection(new Dictionary + { + { "server.urls", "http://localhost:8792/" } + }) + .Build(); + + var hostBuilder = new WebHostBuilder(CallContextServiceLocator.Locator.ServiceProvider, config); + hostBuilder.UseServer("Microsoft.AspNet.Server.Kestrel"); + hostBuilder.UseStartup(app => + { + app.Run(async context => + { + var bytes = new byte[1024]; + for (int i = 0; i < bytes.Length; i++) + { + bytes[i] = (byte)i; + } + + context.Response.ContentLength = bytes.Length * 1024; + + for (int i = 0; i < 1024; i++) + { + await context.Response.Body.WriteAsync(bytes, 0, bytes.Length); + } + }); + }); + + using (var app = hostBuilder.Build().Start()) + { + using (var client = new HttpClient()) + { + var response = await client.GetAsync("http://localhost:8792/"); + response.EnsureSuccessStatusCode(); + var responseBody = await response.Content.ReadAsStreamAsync(); + + // Read the full response body + var total = 0; + var bytes = new byte[1024]; + var count = await responseBody.ReadAsync(bytes, 0, bytes.Length); + while (count > 0) + { + for (int i = 0; i < count; i++) + { + Assert.Equal(total % 256, bytes[i]); + total++; + } + count = await responseBody.ReadAsync(bytes, 0, bytes.Length); + } + } + } + } + } +} diff --git a/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/ThreadCountTests.cs b/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/ThreadCountTests.cs new file mode 100644 index 0000000000..d47679f540 --- /dev/null +++ b/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/ThreadCountTests.cs @@ -0,0 +1,74 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System.Collections.Generic; +using System.Net.Http; +using System.Threading.Tasks; +using Microsoft.AspNet.Builder; +using Microsoft.AspNet.Hosting; +using Microsoft.AspNet.Http; +using Microsoft.AspNet.Http.Features; +using Microsoft.Dnx.Runtime.Infrastructure; +using Microsoft.Extensions.Configuration; +using Xunit; + +namespace Microsoft.AspNet.Server.Kestrel.FunctionalTests +{ + public class ThreadCountTests + { + [Theory(Skip = "https://github.com/aspnet/KestrelHttpServer/issues/232"), MemberData(nameof(OneToTen))] + public async Task ZeroToTenThreads(int threadCount) + { + var config = new ConfigurationBuilder() + .AddInMemoryCollection(new Dictionary + { + { "server.urls", "http://localhost:8790/" } + }) + .Build(); + + var hostBuilder = new WebHostBuilder(CallContextServiceLocator.Locator.ServiceProvider, config); + hostBuilder.UseServer("Microsoft.AspNet.Server.Kestrel"); + hostBuilder.UseStartup(app => + { + var serverInfo = app.ServerFeatures.Get(); + serverInfo.ThreadCount = threadCount; + app.Run(context => + { + return context.Response.WriteAsync("Hello World"); + }); + }); + + using (var app = hostBuilder.Build().Start()) + { + using (var client = new HttpClient()) + { + // Send 20 requests just to make sure we don't get any failures + var requestTasks = new List>(); + for (int i = 0; i < 20; i++) + { + var requestTask = client.GetStringAsync("http://localhost:8790/"); + requestTasks.Add(requestTask); + } + + foreach (var result in await Task.WhenAll(requestTasks)) + { + Assert.Equal("Hello World", result); + } + } + } + } + + public static TheoryData OneToTen + { + get + { + var dataset = new TheoryData(); + for (int i = 1; i <= 10; i++) + { + dataset.Add(i); + } + return dataset; + } + } + } +} diff --git a/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/project.json b/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/project.json new file mode 100644 index 0000000000..7ecc7fb8ab --- /dev/null +++ b/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/project.json @@ -0,0 +1,19 @@ +{ + "version": "1.0.0-*", + "dependencies": { + "Microsoft.AspNet.Http.Abstractions": "1.0.0-*", + "Microsoft.AspNet.Server.Kestrel": "1.0.0-*", + "System.Net.Http": "4.0.1-beta-*", + "xunit.runner.aspnet": "2.0.0-aspnet-*" + }, + "frameworks": { + "dnx451": { }, + "dnxcore50": { } + }, + "compilationOptions": { + "allowUnsafe": true + }, + "commands": { + "test": "xunit.runner.aspnet -parallel none" + } +} diff --git a/test/Microsoft.AspNet.Server.KestrelTests/CreateIPEndpointTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/CreateIPEndpointTests.cs index 5cc5c2345c..e8a14e55b8 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/CreateIPEndpointTests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/CreateIPEndpointTests.cs @@ -11,12 +11,13 @@ namespace Microsoft.AspNet.Server.KestrelTests public class CreateIPEndpointTests { [Theory] - [InlineData("localhost", "127.0.0.1")] + [InlineData("localhost", "127.0.0.1")] // https://github.com/aspnet/KestrelHttpServer/issues/231 [InlineData("10.10.10.10", "10.10.10.10")] - [InlineData("randomhost", "0.0.0.0")] + [InlineData("[::1]", "::1")] + [InlineData("randomhost", "::")] // "::" is IPAddress.IPv6Any + [InlineData("*", "::")] // "::" is IPAddress.IPv6Any public void CorrectIPEndpointsAreCreated(string host, string expectedAddress) { - // "0.0.0.0" is IPAddress.Any var endpoint = UvTcpHandle.CreateIPEndpoint(ServerAddress.FromUrl($"http://{host}:5000/")); Assert.NotNull(endpoint); Assert.Equal(IPAddress.Parse(expectedAddress), endpoint.Address); diff --git a/test/Microsoft.AspNet.Server.KestrelTests/TestInput.cs b/test/Microsoft.AspNet.Server.KestrelTests/TestInput.cs index 47470bb4fc..3db112560c 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/TestInput.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/TestInput.cs @@ -66,16 +66,18 @@ namespace Microsoft.AspNet.Server.KestrelTests { } - async Task IFrameControl.WriteAsync(ArraySegment data, CancellationToken cancellationToken) + Task IFrameControl.WriteAsync(ArraySegment data, CancellationToken cancellationToken) { + return Task.FromResult(0); } void IFrameControl.Flush() { } - async Task IFrameControl.FlushAsync(CancellationToken cancellationToken) + Task IFrameControl.FlushAsync(CancellationToken cancellationToken) { + return Task.FromResult(0); } } } From 816dabb009a9d4280b19062cd4d9d83e0ca9793a Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Wed, 7 Oct 2015 12:17:58 -0400 Subject: [PATCH 0315/1662] BitCount --- .../KnownHeaders.cs | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/KnownHeaders.cs b/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/KnownHeaders.cs index 11327a8d60..0fc30fa0de 100644 --- a/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/KnownHeaders.cs +++ b/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/KnownHeaders.cs @@ -195,14 +195,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http protected override int GetCountFast() {{ - var count = MaybeUnknown?.Count ?? 0; - {Each(loop.Headers, header => $@" - if ({header.TestBit()}) - {{ - ++count; - }} - ")} - return count; + return _bits.BitCount() + (MaybeUnknown?.Count ?? 0); }} protected override StringValues GetValueFast(string key) From 8bf2c814d64c8475415c1c9ba81ffaae84039275 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Wed, 7 Oct 2015 12:23:20 -0400 Subject: [PATCH 0316/1662] Add BitCount LongExtensions --- .../Http/FrameHeaders.Generated.cs | 364 +----------------- .../Infrastructure/LongExtensions.cs | 18 + .../KnownHeaders.cs | 1 + 3 files changed, 22 insertions(+), 361 deletions(-) create mode 100644 src/Microsoft.AspNet.Server.Kestrel/Infrastructure/LongExtensions.cs diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameHeaders.Generated.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameHeaders.Generated.cs index 9666fad29b..5ca0e5fc12 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameHeaders.Generated.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameHeaders.Generated.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; +using Microsoft.AspNet.Server.Kestrel.Extensions; using Microsoft.Extensions.Primitives; namespace Microsoft.AspNet.Server.Kestrel.Http @@ -589,214 +590,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http protected override int GetCountFast() { - var count = MaybeUnknown?.Count ?? 0; - - if (((_bits & 1L) != 0)) - { - ++count; - } - - if (((_bits & 2L) != 0)) - { - ++count; - } - - if (((_bits & 4L) != 0)) - { - ++count; - } - - if (((_bits & 8L) != 0)) - { - ++count; - } - - if (((_bits & 16L) != 0)) - { - ++count; - } - - if (((_bits & 32L) != 0)) - { - ++count; - } - - if (((_bits & 64L) != 0)) - { - ++count; - } - - if (((_bits & 128L) != 0)) - { - ++count; - } - - if (((_bits & 256L) != 0)) - { - ++count; - } - - if (((_bits & 512L) != 0)) - { - ++count; - } - - if (((_bits & 1024L) != 0)) - { - ++count; - } - - if (((_bits & 2048L) != 0)) - { - ++count; - } - - if (((_bits & 4096L) != 0)) - { - ++count; - } - - if (((_bits & 8192L) != 0)) - { - ++count; - } - - if (((_bits & 16384L) != 0)) - { - ++count; - } - - if (((_bits & 32768L) != 0)) - { - ++count; - } - - if (((_bits & 65536L) != 0)) - { - ++count; - } - - if (((_bits & 131072L) != 0)) - { - ++count; - } - - if (((_bits & 262144L) != 0)) - { - ++count; - } - - if (((_bits & 524288L) != 0)) - { - ++count; - } - - if (((_bits & 1048576L) != 0)) - { - ++count; - } - - if (((_bits & 2097152L) != 0)) - { - ++count; - } - - if (((_bits & 4194304L) != 0)) - { - ++count; - } - - if (((_bits & 8388608L) != 0)) - { - ++count; - } - - if (((_bits & 16777216L) != 0)) - { - ++count; - } - - if (((_bits & 33554432L) != 0)) - { - ++count; - } - - if (((_bits & 67108864L) != 0)) - { - ++count; - } - - if (((_bits & 134217728L) != 0)) - { - ++count; - } - - if (((_bits & 268435456L) != 0)) - { - ++count; - } - - if (((_bits & 536870912L) != 0)) - { - ++count; - } - - if (((_bits & 1073741824L) != 0)) - { - ++count; - } - - if (((_bits & 2147483648L) != 0)) - { - ++count; - } - - if (((_bits & 4294967296L) != 0)) - { - ++count; - } - - if (((_bits & 8589934592L) != 0)) - { - ++count; - } - - if (((_bits & 17179869184L) != 0)) - { - ++count; - } - - if (((_bits & 34359738368L) != 0)) - { - ++count; - } - - if (((_bits & 68719476736L) != 0)) - { - ++count; - } - - if (((_bits & 137438953472L) != 0)) - { - ++count; - } - - if (((_bits & 274877906944L) != 0)) - { - ++count; - } - - if (((_bits & 549755813888L) != 0)) - { - ++count; - } - - if (((_bits & 1099511627776L) != 0)) - { - ++count; - } - - return count; + return _bits.BitCount() + (MaybeUnknown?.Count ?? 0); } protected override StringValues GetValueFast(string key) @@ -5623,159 +5417,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http protected override int GetCountFast() { - var count = MaybeUnknown?.Count ?? 0; - - if (((_bits & 1L) != 0)) - { - ++count; - } - - if (((_bits & 2L) != 0)) - { - ++count; - } - - if (((_bits & 4L) != 0)) - { - ++count; - } - - if (((_bits & 8L) != 0)) - { - ++count; - } - - if (((_bits & 16L) != 0)) - { - ++count; - } - - if (((_bits & 32L) != 0)) - { - ++count; - } - - if (((_bits & 64L) != 0)) - { - ++count; - } - - if (((_bits & 128L) != 0)) - { - ++count; - } - - if (((_bits & 256L) != 0)) - { - ++count; - } - - if (((_bits & 512L) != 0)) - { - ++count; - } - - if (((_bits & 1024L) != 0)) - { - ++count; - } - - if (((_bits & 2048L) != 0)) - { - ++count; - } - - if (((_bits & 4096L) != 0)) - { - ++count; - } - - if (((_bits & 8192L) != 0)) - { - ++count; - } - - if (((_bits & 16384L) != 0)) - { - ++count; - } - - if (((_bits & 32768L) != 0)) - { - ++count; - } - - if (((_bits & 65536L) != 0)) - { - ++count; - } - - if (((_bits & 131072L) != 0)) - { - ++count; - } - - if (((_bits & 262144L) != 0)) - { - ++count; - } - - if (((_bits & 524288L) != 0)) - { - ++count; - } - - if (((_bits & 1048576L) != 0)) - { - ++count; - } - - if (((_bits & 2097152L) != 0)) - { - ++count; - } - - if (((_bits & 4194304L) != 0)) - { - ++count; - } - - if (((_bits & 8388608L) != 0)) - { - ++count; - } - - if (((_bits & 16777216L) != 0)) - { - ++count; - } - - if (((_bits & 33554432L) != 0)) - { - ++count; - } - - if (((_bits & 67108864L) != 0)) - { - ++count; - } - - if (((_bits & 134217728L) != 0)) - { - ++count; - } - - if (((_bits & 268435456L) != 0)) - { - ++count; - } - - if (((_bits & 536870912L) != 0)) - { - ++count; - } - - return count; + return _bits.BitCount() + (MaybeUnknown?.Count ?? 0); } protected override StringValues GetValueFast(string key) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/LongExtensions.cs b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/LongExtensions.cs new file mode 100644 index 0000000000..0ac6a718d4 --- /dev/null +++ b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/LongExtensions.cs @@ -0,0 +1,18 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +namespace Microsoft.AspNet.Server.Kestrel.Extensions +{ + public static class LongExtensions + { + public static int BitCount(this long value) + { + // Parallel bit count for a 64-bit integer + var v = (ulong)value; + v = v - ((v >> 1) & 0x5555555555555555); + v = (v & 0x3333333333333333) + ((v >> 2) & 0x3333333333333333); + v = (v + (v >> 4) & 0x0f0f0f0f0f0f0f0f); + return (int)((v * 0x0101010101010101) >> 56); + } + } +} diff --git a/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/KnownHeaders.cs b/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/KnownHeaders.cs index 0fc30fa0de..6dbad61a7c 100644 --- a/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/KnownHeaders.cs +++ b/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/KnownHeaders.cs @@ -167,6 +167,7 @@ namespace Microsoft.AspNet.Server.Kestrel.GeneratedCode return $@" using System; using System.Collections.Generic; +using Microsoft.AspNet.Server.Kestrel.Extensions; using Microsoft.Extensions.Primitives; namespace Microsoft.AspNet.Server.Kestrel.Http From 05418dd18af08d67639d1ef97b4c2782210c69ff Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Wed, 7 Oct 2015 16:51:10 -0400 Subject: [PATCH 0317/1662] Use corefx implementation --- .../Infrastructure/LongExtensions.cs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/LongExtensions.cs b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/LongExtensions.cs index 0ac6a718d4..3b79425172 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/LongExtensions.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/LongExtensions.cs @@ -7,12 +7,18 @@ namespace Microsoft.AspNet.Server.Kestrel.Extensions { public static int BitCount(this long value) { - // Parallel bit count for a 64-bit integer + // see https://github.com/dotnet/corefx/blob/master/src/System.Reflection.Metadata/src/System/Reflection/Internal/Utilities/BitArithmetic.cs + + const ulong Mask01010101 = 0x5555555555555555UL; + const ulong Mask00110011 = 0x3333333333333333UL; + const ulong Mask00001111 = 0x0F0F0F0F0F0F0F0FUL; + const ulong Mask00000001 = 0x0101010101010101UL; + var v = (ulong)value; - v = v - ((v >> 1) & 0x5555555555555555); - v = (v & 0x3333333333333333) + ((v >> 2) & 0x3333333333333333); - v = (v + (v >> 4) & 0x0f0f0f0f0f0f0f0f); - return (int)((v * 0x0101010101010101) >> 56); + + v = v - ((v >> 1) & Mask01010101); + v = (v & Mask00110011) + ((v >> 2) & Mask00110011); + return (int)(unchecked(((v + (v >> 4)) & Mask00001111) * Mask00000001) >> 56); } } } From cd1c80daa7f13324955b8ecadd6774cf11af7a90 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Wed, 7 Oct 2015 17:25:10 -0700 Subject: [PATCH 0318/1662] Fix EngineTests that weren't using the appropriate ServiceContext - This meant that the affected tests weren't run with the NoOpConnectionFilter --- test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs index 72867771b8..7a7691d052 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs @@ -296,7 +296,7 @@ namespace Microsoft.AspNet.Server.KestrelTests [MemberData(nameof(ConnectionFilterData))] public async Task Http10KeepAliveContentLength(ServiceContext testContext) { - using (var server = new TestServer(AppChunked)) + using (var server = new TestServer(AppChunked, testContext)) { using (var connection = new TestConnection()) { @@ -327,7 +327,7 @@ namespace Microsoft.AspNet.Server.KestrelTests [MemberData(nameof(ConnectionFilterData))] public async Task Http10KeepAliveTransferEncoding(ServiceContext testContext) { - using (var server = new TestServer(AppChunked)) + using (var server = new TestServer(AppChunked, testContext)) { using (var connection = new TestConnection()) { From 4250d353472a8714bb4813631059b56fd53af922 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Thu, 8 Oct 2015 01:11:41 -0400 Subject: [PATCH 0319/1662] PR feeback --- .../Http/FrameHeaders.Generated.cs | 35 +++++++++++++++++-- .../Infrastructure/LongExtensions.cs | 24 ------------- .../KnownHeaders.cs | 18 ++++++++-- 3 files changed, 48 insertions(+), 29 deletions(-) delete mode 100644 src/Microsoft.AspNet.Server.Kestrel/Infrastructure/LongExtensions.cs diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameHeaders.Generated.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameHeaders.Generated.cs index 5ca0e5fc12..63eb6db9ad 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameHeaders.Generated.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameHeaders.Generated.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; -using Microsoft.AspNet.Server.Kestrel.Extensions; using Microsoft.Extensions.Primitives; namespace Microsoft.AspNet.Server.Kestrel.Http @@ -587,10 +586,25 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } + private static int BitCount(long value) + { + // see https://github.com/dotnet/corefx/blob/master/src/System.Reflection.Metadata/src/System/Reflection/Internal/Utilities/BitArithmetic.cs + + const ulong Mask01010101 = 0x5555555555555555UL; + const ulong Mask00110011 = 0x3333333333333333UL; + const ulong Mask00001111 = 0x0F0F0F0F0F0F0F0FUL; + const ulong Mask00000001 = 0x0101010101010101UL; + + var v = (ulong)value; + + v = v - ((v >> 1) & Mask01010101); + v = (v & Mask00110011) + ((v >> 2) & Mask00110011); + return (int)(unchecked(((v + (v >> 4)) & Mask00001111) * Mask00000001) >> 56); + } protected override int GetCountFast() { - return _bits.BitCount() + (MaybeUnknown?.Count ?? 0); + return BitCount(_bits) + (MaybeUnknown?.Count ?? 0); } protected override StringValues GetValueFast(string key) @@ -5414,10 +5428,25 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } + private static int BitCount(long value) + { + // see https://github.com/dotnet/corefx/blob/master/src/System.Reflection.Metadata/src/System/Reflection/Internal/Utilities/BitArithmetic.cs + + const ulong Mask01010101 = 0x5555555555555555UL; + const ulong Mask00110011 = 0x3333333333333333UL; + const ulong Mask00001111 = 0x0F0F0F0F0F0F0F0FUL; + const ulong Mask00000001 = 0x0101010101010101UL; + + var v = (ulong)value; + + v = v - ((v >> 1) & Mask01010101); + v = (v & Mask00110011) + ((v >> 2) & Mask00110011); + return (int)(unchecked(((v + (v >> 4)) & Mask00001111) * Mask00000001) >> 56); + } protected override int GetCountFast() { - return _bits.BitCount() + (MaybeUnknown?.Count ?? 0); + return BitCount(_bits) + (MaybeUnknown?.Count ?? 0); } protected override StringValues GetValueFast(string key) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/LongExtensions.cs b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/LongExtensions.cs deleted file mode 100644 index 3b79425172..0000000000 --- a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/LongExtensions.cs +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -namespace Microsoft.AspNet.Server.Kestrel.Extensions -{ - public static class LongExtensions - { - public static int BitCount(this long value) - { - // see https://github.com/dotnet/corefx/blob/master/src/System.Reflection.Metadata/src/System/Reflection/Internal/Utilities/BitArithmetic.cs - - const ulong Mask01010101 = 0x5555555555555555UL; - const ulong Mask00110011 = 0x3333333333333333UL; - const ulong Mask00001111 = 0x0F0F0F0F0F0F0F0FUL; - const ulong Mask00000001 = 0x0101010101010101UL; - - var v = (ulong)value; - - v = v - ((v >> 1) & Mask01010101); - v = (v & Mask00110011) + ((v >> 2) & Mask00110011); - return (int)(unchecked(((v + (v >> 4)) & Mask00001111) * Mask00000001) >> 56); - } - } -} diff --git a/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/KnownHeaders.cs b/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/KnownHeaders.cs index 6dbad61a7c..ed50e3cc1f 100644 --- a/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/KnownHeaders.cs +++ b/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/KnownHeaders.cs @@ -167,7 +167,6 @@ namespace Microsoft.AspNet.Server.Kestrel.GeneratedCode return $@" using System; using System.Collections.Generic; -using Microsoft.AspNet.Server.Kestrel.Extensions; using Microsoft.Extensions.Primitives; namespace Microsoft.AspNet.Server.Kestrel.Http @@ -193,10 +192,25 @@ namespace Microsoft.AspNet.Server.Kestrel.Http }} }} ")} + private static int BitCount(long value) + {{ + // see https://github.com/dotnet/corefx/blob/master/src/System.Reflection.Metadata/src/System/Reflection/Internal/Utilities/BitArithmetic.cs + + const ulong Mask01010101 = 0x5555555555555555UL; + const ulong Mask00110011 = 0x3333333333333333UL; + const ulong Mask00001111 = 0x0F0F0F0F0F0F0F0FUL; + const ulong Mask00000001 = 0x0101010101010101UL; + + var v = (ulong)value; + + v = v - ((v >> 1) & Mask01010101); + v = (v & Mask00110011) + ((v >> 2) & Mask00110011); + return (int)(unchecked(((v + (v >> 4)) & Mask00001111) * Mask00000001) >> 56); + }} protected override int GetCountFast() {{ - return _bits.BitCount() + (MaybeUnknown?.Count ?? 0); + return BitCount(_bits) + (MaybeUnknown?.Count ?? 0); }} protected override StringValues GetValueFast(string key) From 0a297688b41db2ceb44f088c3e9b4aa956c29f3d Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Fri, 2 Oct 2015 18:12:38 -0400 Subject: [PATCH 0320/1662] Use Jit recongised, standard loop construct For bounds check elimination. Convey intent more clearly; eliminate bounds checks --- .../Infrastructure/MemoryPoolIterator2.cs | 14 ++++++++++---- .../KestrelEngine.cs | 2 +- .../Networking/UvWriteReq.cs | 4 ++-- .../EngineTests.cs | 2 +- .../MemoryPoolBlock2Tests.cs | 2 +- .../MessageBodyTests.cs | 2 +- .../NetworkingTests.cs | 4 ++-- .../TestConnection.cs | 4 ++-- .../KnownHeaders.cs | 2 +- 9 files changed, 21 insertions(+), 15 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolIterator2.cs b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolIterator2.cs index 7e409153c4..994b7d5bbc 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolIterator2.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolIterator2.cs @@ -11,7 +11,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure /// Array of "minus one" bytes of the length of SIMD operations on the current hardware. Used as an argument in the /// vector dot product that counts matching character occurence. /// - private static Vector _dotCount = new Vector(Byte.MaxValue); + private static Vector _dotCount = new Vector(Byte.MaxValue); /// /// Array of negative numbers starting at 0 and continuing for the length of SIMD operations on the current hardware. @@ -51,12 +51,14 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure } else { - for (var block = _block.Next; block != null; block = block.Next) + var block = _block.Next; + while (block != null) { if (block.Start < block.End) { return true; } + block = block.Next; } return true; } @@ -188,7 +190,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure following = vectorStride; } } - for (; following != 0; following--, index++) + while (following > 0) { if (block.Array[index] == byte0) { @@ -196,6 +198,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure _index = index; return char0; } + following--; + index++; } } } @@ -269,7 +273,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure following = vectorStride; } } - for (; following != 0; following--, index++) + while (following > 0) { var byteIndex = block.Array[index]; if (byteIndex == byte0) @@ -284,6 +288,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure _index = index; return char1; } + following--; + index++; } } } diff --git a/src/Microsoft.AspNet.Server.Kestrel/KestrelEngine.cs b/src/Microsoft.AspNet.Server.Kestrel/KestrelEngine.cs index 6026072e16..4eba53b753 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/KestrelEngine.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/KestrelEngine.cs @@ -78,7 +78,7 @@ namespace Microsoft.AspNet.Server.Kestrel public void Start(int count) { - for (var index = 0; index != count; ++index) + for (var index = 0; index < count; index++) { Threads.Add(new KestrelThread(this)); } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvWriteReq.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvWriteReq.cs index 1e80f1ffb2..32cb715522 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvWriteReq.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvWriteReq.cs @@ -61,7 +61,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking pBuffers = (Libuv.uv_buf_t*)gcHandle.AddrOfPinnedObject(); } - for (var index = 0; index != nBuffers; ++index) + for (var index = 0; index < nBuffers; index++) { // create and pin each segment being written var buf = bufs.Array[bufs.Offset + index]; @@ -109,7 +109,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking pBuffers = (Libuv.uv_buf_t*)gcHandle.AddrOfPinnedObject(); } - for (var index = 0; index != nBuffers; ++index) + for (var index = 0; index < nBuffers; index++) { // create and pin each segment being written var buf = bufs.Array[bufs.Offset + index]; diff --git a/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs index 0d7ad85fae..396839f82f 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs @@ -107,7 +107,7 @@ namespace Microsoft.AspNet.Server.KestrelTests socket.Send(Encoding.ASCII.GetBytes("POST / HTTP/1.0\r\n\r\nHello World")); socket.Shutdown(SocketShutdown.Send); var buffer = new byte[8192]; - for (;;) + while (true) { var length = socket.Receive(buffer); if (length == 0) { break; } diff --git a/test/Microsoft.AspNet.Server.KestrelTests/MemoryPoolBlock2Tests.cs b/test/Microsoft.AspNet.Server.KestrelTests/MemoryPoolBlock2Tests.cs index 2f43e0239d..1a8fa0f4e4 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/MemoryPoolBlock2Tests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/MemoryPoolBlock2Tests.cs @@ -45,7 +45,7 @@ namespace Microsoft.AspNet.Server.KestrelTests pool.Return(block); block = null; - for (var fragment = 0; fragment != 256; fragment += 4) + for (var fragment = 0; fragment < 256; fragment += 4) { var next = block; block = pool.Lease(4); diff --git a/test/Microsoft.AspNet.Server.KestrelTests/MessageBodyTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/MessageBodyTests.cs index c3cda8d13a..6bee5b6726 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/MessageBodyTests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/MessageBodyTests.cs @@ -57,7 +57,7 @@ namespace Microsoft.AspNet.Server.KestrelTests var encoding = Encoding.ASCII; var bytes = encoding.GetBytes(expected); Assert.Equal(bytes.Length, actual.Count); - for (var index = 0; index != bytes.Length; ++index) + for (var index = 0; index < bytes.Length; index++) { Assert.Equal(bytes[index], actual.Array[actual.Offset + index]); } diff --git a/test/Microsoft.AspNet.Server.KestrelTests/NetworkingTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/NetworkingTests.cs index 8d9eab7df7..ee1767c14a 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/NetworkingTests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/NetworkingTests.cs @@ -207,7 +207,7 @@ namespace Microsoft.AspNet.Server.KestrelTests } else { - for (var x = 0; x != 2; ++x) + for (var x = 0; x < 2; x++) { var req = new UvWriteReq(new KestrelTrace(new TestKestrelTrace())); req.Init(loop); @@ -246,7 +246,7 @@ namespace Microsoft.AspNet.Server.KestrelTests TaskCreationOptions.None); socket.Shutdown(SocketShutdown.Send); var buffer = new ArraySegment(new byte[2048]); - for (; ;) + while (true) { var count = await Task.Factory.FromAsync( socket.BeginReceive, diff --git a/test/Microsoft.AspNet.Server.KestrelTests/TestConnection.cs b/test/Microsoft.AspNet.Server.KestrelTests/TestConnection.cs index c881979f52..e47c2fc319 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/TestConnection.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/TestConnection.cs @@ -44,7 +44,7 @@ namespace Microsoft.AspNet.Server.KestrelTests { var text = String.Join("\r\n", lines); var writer = new StreamWriter(_stream, Encoding.ASCII); - for (var index = 0; index != text.Length; ++index) + for (var index = 0; index < text.Length; index++) { var ch = text[index]; await writer.WriteAsync(ch); @@ -125,4 +125,4 @@ namespace Microsoft.AspNet.Server.KestrelTests Assert.Equal("", text); } } -} \ No newline at end of file +} diff --git a/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/KnownHeaders.cs b/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/KnownHeaders.cs index d58b76bc5c..9209518f51 100644 --- a/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/KnownHeaders.cs +++ b/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/KnownHeaders.cs @@ -59,7 +59,7 @@ namespace Microsoft.AspNet.Server.Kestrel.GeneratedCode { ulong mask = 0; ulong comp = 0; - for (var scan = 0; scan != count; ++scan) + for (var scan = 0; scan < count; scan++) { var ch = (byte)name[offset + count - scan - 1]; var isAlpha = (ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z'); From 9d251cdb5461cd368195bb0865947d14dacb4106 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Thu, 8 Oct 2015 18:13:22 -0400 Subject: [PATCH 0321/1662] subsequent block has data - IsEnd is false Resolves #249 --- .../Infrastructure/MemoryPoolIterator2.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolIterator2.cs b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolIterator2.cs index 994b7d5bbc..a4ec046e58 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolIterator2.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolIterator2.cs @@ -56,7 +56,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure { if (block.Start < block.End) { - return true; + return false; // subsequent block has data - IsEnd is false } block = block.Next; } From 24c0a8e14260f069c944bfe8792fbbd6b10e223b Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Thu, 8 Oct 2015 16:16:41 -0700 Subject: [PATCH 0322/1662] Fix MemoryPoolIterator2.CopyTo's block traversal - This fix prevents large request streams from being corrupted #234 --- .../Infrastructure/MemoryPoolIterator2.cs | 1 + .../MemoryPoolBlock2Tests.cs | 35 +++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolIterator2.cs b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolIterator2.cs index 7e409153c4..467db4993d 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolIterator2.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolIterator2.cs @@ -442,6 +442,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure else { Buffer.BlockCopy(block.Array, index, array, offset, following); + offset += following; remaining -= following; block = block.Next; index = block.Start; diff --git a/test/Microsoft.AspNet.Server.KestrelTests/MemoryPoolBlock2Tests.cs b/test/Microsoft.AspNet.Server.KestrelTests/MemoryPoolBlock2Tests.cs index 2f43e0239d..9f87347292 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/MemoryPoolBlock2Tests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/MemoryPoolBlock2Tests.cs @@ -117,6 +117,41 @@ namespace Microsoft.AspNet.Server.KestrelTests } } + [Fact] + public void CopyToCorrectlyTraversesBlocks() + { + using (var pool = new MemoryPool2()) + { + var block1 = pool.Lease(128); + var block2 = block1.Next = pool.Lease(128); + + for (int i = 0; i < 128; i++) + { + block1.Array[block1.End++] = (byte)i; + } + for (int i = 128; i < 256; i++) + { + block2.Array[block2.End++] = (byte)i; + } + + var beginIterator = block1.GetIterator(); + + var array = new byte[256]; + int actual; + var endIterator = beginIterator.CopyTo(array, 0, 256, out actual); + + Assert.Equal(256, actual); + + for (int i = 0; i < 256; i++) + { + Assert.Equal(i, array[i]); + } + + endIterator.CopyTo(array, 0, 256, out actual); + Assert.Equal(0, actual); + } + } + private void AssertIterator(MemoryPoolIterator2 iter, MemoryPoolBlock2 block, int index) { Assert.Same(block, iter.Block); From 6f506ba988b6b1b44820e6e5cfe300b83bcbfa32 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Thu, 8 Oct 2015 18:13:22 -0400 Subject: [PATCH 0323/1662] subsequent block has data - IsEnd is false Resolves #249 --- .../Infrastructure/MemoryPoolIterator2.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolIterator2.cs b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolIterator2.cs index 467db4993d..b8f3a9e86d 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolIterator2.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolIterator2.cs @@ -55,7 +55,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure { if (block.Start < block.End) { - return true; + return false; // subsequent block has data - IsEnd is false } } return true; From 7aa85ae7228c613f82830f9f461515fd7873de6b Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Thu, 8 Oct 2015 16:37:17 -0700 Subject: [PATCH 0324/1662] Unit test for the IsEnd fix in the previous commit --- .../MemoryPoolBlock2Tests.cs | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/test/Microsoft.AspNet.Server.KestrelTests/MemoryPoolBlock2Tests.cs b/test/Microsoft.AspNet.Server.KestrelTests/MemoryPoolBlock2Tests.cs index 9f87347292..d266bb37f0 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/MemoryPoolBlock2Tests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/MemoryPoolBlock2Tests.cs @@ -152,6 +152,30 @@ namespace Microsoft.AspNet.Server.KestrelTests } } + [Fact] + public void IsEndCorrectlyTraversesBlocks() + { + using (var pool = new MemoryPool2()) + { + var block1 = pool.Lease(128); + var block2 = block1.Next = pool.Lease(128); + var block3 = block2.Next = pool.Lease(128); + var block4 = block3.Next = pool.Lease(128); + + // There is no data in block2 or block4, so IsEnd should be true after 256 bytes are read. + block1.End += 128; + block3.End += 128; + + var iterStart = block1.GetIterator(); + var iterMid = iterStart.Add(128); + var iterEnd = iterMid.Add(128); + + Assert.False(iterStart.IsEnd); + Assert.False(iterMid.IsEnd); + Assert.True(iterEnd.IsEnd); + } + } + private void AssertIterator(MemoryPoolIterator2 iter, MemoryPoolBlock2 block, int index) { Assert.Same(block, iter.Block); From dcf591c8321f21742843e4794acf1a332208b780 Mon Sep 17 00:00:00 2001 From: Louis DeJardin Date: Fri, 2 Oct 2015 16:09:46 -0700 Subject: [PATCH 0325/1662] Rough implementation of feature collection optimization --- samples/SampleApp/Startup.cs | 5 + .../Frame.FeatureCollection.cs} | 102 +++--- .../Http/Frame.Generated.cs | 297 ++++++++++++++++++ .../Http/Frame.cs | 7 +- .../KestrelEngine.cs | 3 +- .../ServerFactory.cs | 6 +- .../project.json | 3 +- .../FrameFeatureCollection.cs | 112 +++++++ .../Program.cs | 23 +- .../project.json | 6 +- 10 files changed, 500 insertions(+), 64 deletions(-) rename src/Microsoft.AspNet.Server.Kestrel/{ServerRequest.cs => Http/Frame.FeatureCollection.cs} (58%) create mode 100644 src/Microsoft.AspNet.Server.Kestrel/Http/Frame.Generated.cs create mode 100644 tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/FrameFeatureCollection.cs diff --git a/samples/SampleApp/Startup.cs b/samples/SampleApp/Startup.cs index 2f18d72aed..61840db407 100644 --- a/samples/SampleApp/Startup.cs +++ b/samples/SampleApp/Startup.cs @@ -19,6 +19,9 @@ namespace SampleApp { public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory, IApplicationEnvironment env) { + var ksi = app.ServerFeatures[typeof(IKestrelServerInformation)] as IKestrelServerInformation; + //ksi.ThreadCount = 4; + loggerFactory.MinimumLevel = LogLevel.Debug; loggerFactory.AddConsole(LogLevel.Debug); @@ -46,6 +49,8 @@ namespace SampleApp context.Request.Path, context.Request.QueryString); + foreach (var q in context.Request.Query) { } + context.Response.ContentLength = 11; context.Response.ContentType = "text/plain"; await context.Response.WriteAsync("Hello world"); diff --git a/src/Microsoft.AspNet.Server.Kestrel/ServerRequest.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.FeatureCollection.cs similarity index 58% rename from src/Microsoft.AspNet.Server.Kestrel/ServerRequest.cs rename to src/Microsoft.AspNet.Server.Kestrel/Http/Frame.FeatureCollection.cs index 559b7bb525..bb9f2928ff 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/ServerRequest.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.FeatureCollection.cs @@ -2,45 +2,44 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; +using System.Threading; using System.Threading.Tasks; using Microsoft.AspNet.Http.Features; using Microsoft.AspNet.Server.Kestrel.Http; using Microsoft.Extensions.Primitives; -namespace Microsoft.AspNet.Server.Kestrel +namespace Microsoft.AspNet.Server.Kestrel.Http { - public class ServerRequest : IHttpRequestFeature, IHttpResponseFeature, IHttpUpgradeFeature + public partial class Frame : IFeatureCollection, IHttpRequestFeature, IHttpResponseFeature, IHttpUpgradeFeature { - private Frame _frame; private string _scheme; private string _pathBase; - private FeatureCollection _features; + private int _featureRevision; - public ServerRequest(Frame frame) - { - _frame = frame; - _features = new FeatureCollection(); - PopulateFeatures(); - } + private Dictionary Extra => MaybeExtra ?? Interlocked.CompareExchange(ref MaybeExtra, new Dictionary(), null); + private Dictionary MaybeExtra; - internal IFeatureCollection Features + public void ResetFeatureCollection() { - get { return _features; } + FastReset(); + MaybeExtra?.Clear(); + Interlocked.Increment(ref _featureRevision); } string IHttpRequestFeature.Protocol { get { - return _frame.HttpVersion; + return HttpVersion; } set { - _frame.HttpVersion = value; + HttpVersion = value; } } @@ -61,12 +60,12 @@ namespace Microsoft.AspNet.Server.Kestrel { get { - return _frame.Method; + return Method; } set { - _frame.Method = value; + Method = value; } } @@ -87,12 +86,12 @@ namespace Microsoft.AspNet.Server.Kestrel { get { - return _frame.Path; + return Path; } set { - _frame.Path = value; + Path = value; } } @@ -100,12 +99,12 @@ namespace Microsoft.AspNet.Server.Kestrel { get { - return _frame.QueryString; + return QueryString; } set { - _frame.QueryString = value; + QueryString = value; } } @@ -113,12 +112,12 @@ namespace Microsoft.AspNet.Server.Kestrel { get { - return _frame.RequestHeaders; + return RequestHeaders; } set { - _frame.RequestHeaders = value; + RequestHeaders = value; } } @@ -126,12 +125,12 @@ namespace Microsoft.AspNet.Server.Kestrel { get { - return _frame.RequestBody; + return RequestBody; } set { - _frame.RequestBody = value; + RequestBody = value; } } @@ -139,12 +138,12 @@ namespace Microsoft.AspNet.Server.Kestrel { get { - return _frame.StatusCode; + return StatusCode; } set { - _frame.StatusCode = value; + StatusCode = value; } } @@ -152,12 +151,12 @@ namespace Microsoft.AspNet.Server.Kestrel { get { - return _frame.ReasonPhrase; + return ReasonPhrase; } set { - _frame.ReasonPhrase = value; + ReasonPhrase = value; } } @@ -165,12 +164,12 @@ namespace Microsoft.AspNet.Server.Kestrel { get { - return _frame.ResponseHeaders; + return ResponseHeaders; } set { - _frame.ResponseHeaders = value; + ResponseHeaders = value; } } @@ -178,18 +177,18 @@ namespace Microsoft.AspNet.Server.Kestrel { get { - return _frame.ResponseBody; + return ResponseBody; } set { - _frame.ResponseBody = value; + ResponseBody = value; } } bool IHttpResponseFeature.HasStarted { - get { return _frame.HasResponseStarted; } + get { return HasResponseStarted; } } bool IHttpUpgradeFeature.IsUpgradableRequest @@ -197,7 +196,7 @@ namespace Microsoft.AspNet.Server.Kestrel get { StringValues values; - if (_frame.RequestHeaders.TryGetValue("Connection", out values)) + if (RequestHeaders.TryGetValue("Connection", out values)) { return values.Any(value => value.IndexOf("upgrade", StringComparison.OrdinalIgnoreCase) != -1); } @@ -205,38 +204,45 @@ namespace Microsoft.AspNet.Server.Kestrel } } - private void PopulateFeatures() + bool IFeatureCollection.IsReadOnly => false; + + int IFeatureCollection.Revision => _featureRevision; + + object IFeatureCollection.this[Type key] { - _features[typeof(IHttpRequestFeature)] = this; - _features[typeof(IHttpResponseFeature)] = this; - _features[typeof(IHttpUpgradeFeature)] = this; + get { return FastFeatureGet(key); } + set { FastFeatureSet(key, value); } } void IHttpResponseFeature.OnStarting(Func callback, object state) { - _frame.OnStarting(callback, state); + OnStarting(callback, state); } void IHttpResponseFeature.OnCompleted(Func callback, object state) { - _frame.OnCompleted(callback, state); + OnCompleted(callback, state); } Task IHttpUpgradeFeature.UpgradeAsync() { - _frame.StatusCode = 101; - _frame.ReasonPhrase = "Switching Protocols"; - _frame.ResponseHeaders["Connection"] = "Upgrade"; - if (!_frame.ResponseHeaders.ContainsKey("Upgrade")) + StatusCode = 101; + ReasonPhrase = "Switching Protocols"; + ResponseHeaders["Connection"] = "Upgrade"; + if (!ResponseHeaders.ContainsKey("Upgrade")) { StringValues values; - if (_frame.RequestHeaders.TryGetValue("Upgrade", out values)) + if (RequestHeaders.TryGetValue("Upgrade", out values)) { - _frame.ResponseHeaders["Upgrade"] = values; + ResponseHeaders["Upgrade"] = values; } } - _frame.ProduceStart(); - return Task.FromResult(_frame.DuplexStream); + ProduceStart(); + return Task.FromResult(DuplexStream); } + + IEnumerator> IEnumerable>.GetEnumerator() => FastEnumerable().GetEnumerator(); + + IEnumerator IEnumerable.GetEnumerator() => FastEnumerable().GetEnumerator(); } } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.Generated.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.Generated.cs new file mode 100644 index 0000000000..afe65ec80a --- /dev/null +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.Generated.cs @@ -0,0 +1,297 @@ + +using System; +using System.Collections.Generic; + +namespace Microsoft.AspNet.Server.Kestrel.Http +{ + public partial class Frame + { + + private object _currentIHttpRequestFeature; + private object _currentIHttpResponseFeature; + private object _currentIHttpUpgradeFeature; + private object _currentIHttpRequestIdentifierFeature; + private object _currentIHttpConnectionFeature; + private object _currentITlsConnectionFeature; + private object _currentIServiceProvidersFeature; + private object _currentIHttpSendFileFeature; + private object _currentIHttpWebSocketFeature; + private object _currentIQueryFeature; + private object _currentIFormFeature; + private object _currentIItemsFeature; + private object _currentIHttpAuthenticationFeature; + private object _currentIHttpRequestLifetimeFeature; + private object _currentISessionFeature; + private object _currentIResponseCookiesFeature; + + private void FastReset() + { + _currentIHttpRequestFeature = this as global::Microsoft.AspNet.Http.Features.IHttpRequestFeature; + _currentIHttpResponseFeature = this as global::Microsoft.AspNet.Http.Features.IHttpResponseFeature; + _currentIHttpUpgradeFeature = this as global::Microsoft.AspNet.Http.Features.IHttpUpgradeFeature; + _currentIHttpRequestIdentifierFeature = this as global::Microsoft.AspNet.Http.Features.IHttpRequestIdentifierFeature; + _currentIHttpConnectionFeature = this as global::Microsoft.AspNet.Http.Features.IHttpConnectionFeature; + _currentITlsConnectionFeature = this as global::Microsoft.AspNet.Http.Features.ITlsConnectionFeature; + _currentIServiceProvidersFeature = this as global::Microsoft.AspNet.Http.Features.Internal.IServiceProvidersFeature; + _currentIHttpSendFileFeature = this as global::Microsoft.AspNet.Http.Features.IHttpSendFileFeature; + _currentIHttpWebSocketFeature = this as global::Microsoft.AspNet.Http.Features.IHttpWebSocketFeature; + _currentIQueryFeature = this as global::Microsoft.AspNet.Http.Features.Internal.IQueryFeature; + _currentIFormFeature = this as global::Microsoft.AspNet.Http.Features.Internal.IFormFeature; + _currentIItemsFeature = this as global::Microsoft.AspNet.Http.Features.Internal.IItemsFeature; + _currentIHttpAuthenticationFeature = this as global::Microsoft.AspNet.Http.Features.Authentication.IHttpAuthenticationFeature; + _currentIHttpRequestLifetimeFeature = this as global::Microsoft.AspNet.Http.Features.IHttpRequestLifetimeFeature; + _currentISessionFeature = this as global::Microsoft.AspNet.Http.Features.ISessionFeature; + _currentIResponseCookiesFeature = this as global::Microsoft.AspNet.Http.Features.Internal.IResponseCookiesFeature; + } + + private object FastFeatureGet(Type key) + { + if (key == typeof(global::Microsoft.AspNet.Http.Features.IHttpRequestFeature)) + { + return _currentIHttpRequestFeature; + } + if (key == typeof(global::Microsoft.AspNet.Http.Features.IHttpResponseFeature)) + { + return _currentIHttpResponseFeature; + } + if (key == typeof(global::Microsoft.AspNet.Http.Features.IHttpUpgradeFeature)) + { + return _currentIHttpUpgradeFeature; + } + if (key == typeof(global::Microsoft.AspNet.Http.Features.IHttpRequestIdentifierFeature)) + { + return _currentIHttpRequestIdentifierFeature; + } + if (key == typeof(global::Microsoft.AspNet.Http.Features.IHttpConnectionFeature)) + { + return _currentIHttpConnectionFeature; + } + if (key == typeof(global::Microsoft.AspNet.Http.Features.ITlsConnectionFeature)) + { + return _currentITlsConnectionFeature; + } + if (key == typeof(global::Microsoft.AspNet.Http.Features.Internal.IServiceProvidersFeature)) + { + return _currentIServiceProvidersFeature; + } + if (key == typeof(global::Microsoft.AspNet.Http.Features.IHttpSendFileFeature)) + { + return _currentIHttpSendFileFeature; + } + if (key == typeof(global::Microsoft.AspNet.Http.Features.IHttpWebSocketFeature)) + { + return _currentIHttpWebSocketFeature; + } + if (key == typeof(global::Microsoft.AspNet.Http.Features.Internal.IQueryFeature)) + { + return _currentIQueryFeature; + } + if (key == typeof(global::Microsoft.AspNet.Http.Features.Internal.IFormFeature)) + { + return _currentIFormFeature; + } + if (key == typeof(global::Microsoft.AspNet.Http.Features.Internal.IItemsFeature)) + { + return _currentIItemsFeature; + } + if (key == typeof(global::Microsoft.AspNet.Http.Features.Authentication.IHttpAuthenticationFeature)) + { + return _currentIHttpAuthenticationFeature; + } + if (key == typeof(global::Microsoft.AspNet.Http.Features.IHttpRequestLifetimeFeature)) + { + return _currentIHttpRequestLifetimeFeature; + } + if (key == typeof(global::Microsoft.AspNet.Http.Features.ISessionFeature)) + { + return _currentISessionFeature; + } + if (key == typeof(global::Microsoft.AspNet.Http.Features.Internal.IResponseCookiesFeature)) + { + return _currentIResponseCookiesFeature; + } + object feature = null; + if (MaybeExtra?.TryGetValue(key, out feature) ?? false) + { + return feature; + } + return null; + } + + private void FastFeatureSet(Type key, object feature) + { + if (key == typeof(global::Microsoft.AspNet.Http.Features.IHttpRequestFeature)) + { + _currentIHttpRequestFeature = feature; + System.Threading.Interlocked.Increment(ref _featureRevision); + return; + } + if (key == typeof(global::Microsoft.AspNet.Http.Features.IHttpResponseFeature)) + { + _currentIHttpResponseFeature = feature; + System.Threading.Interlocked.Increment(ref _featureRevision); + return; + } + if (key == typeof(global::Microsoft.AspNet.Http.Features.IHttpUpgradeFeature)) + { + _currentIHttpUpgradeFeature = feature; + System.Threading.Interlocked.Increment(ref _featureRevision); + return; + } + if (key == typeof(global::Microsoft.AspNet.Http.Features.IHttpRequestIdentifierFeature)) + { + _currentIHttpRequestIdentifierFeature = feature; + System.Threading.Interlocked.Increment(ref _featureRevision); + return; + } + if (key == typeof(global::Microsoft.AspNet.Http.Features.IHttpConnectionFeature)) + { + _currentIHttpConnectionFeature = feature; + System.Threading.Interlocked.Increment(ref _featureRevision); + return; + } + if (key == typeof(global::Microsoft.AspNet.Http.Features.ITlsConnectionFeature)) + { + _currentITlsConnectionFeature = feature; + System.Threading.Interlocked.Increment(ref _featureRevision); + return; + } + if (key == typeof(global::Microsoft.AspNet.Http.Features.Internal.IServiceProvidersFeature)) + { + _currentIServiceProvidersFeature = feature; + System.Threading.Interlocked.Increment(ref _featureRevision); + return; + } + if (key == typeof(global::Microsoft.AspNet.Http.Features.IHttpSendFileFeature)) + { + _currentIHttpSendFileFeature = feature; + System.Threading.Interlocked.Increment(ref _featureRevision); + return; + } + if (key == typeof(global::Microsoft.AspNet.Http.Features.IHttpWebSocketFeature)) + { + _currentIHttpWebSocketFeature = feature; + System.Threading.Interlocked.Increment(ref _featureRevision); + return; + } + if (key == typeof(global::Microsoft.AspNet.Http.Features.Internal.IQueryFeature)) + { + _currentIQueryFeature = feature; + System.Threading.Interlocked.Increment(ref _featureRevision); + return; + } + if (key == typeof(global::Microsoft.AspNet.Http.Features.Internal.IFormFeature)) + { + _currentIFormFeature = feature; + System.Threading.Interlocked.Increment(ref _featureRevision); + return; + } + if (key == typeof(global::Microsoft.AspNet.Http.Features.Internal.IItemsFeature)) + { + _currentIItemsFeature = feature; + System.Threading.Interlocked.Increment(ref _featureRevision); + return; + } + if (key == typeof(global::Microsoft.AspNet.Http.Features.Authentication.IHttpAuthenticationFeature)) + { + _currentIHttpAuthenticationFeature = feature; + System.Threading.Interlocked.Increment(ref _featureRevision); + return; + } + if (key == typeof(global::Microsoft.AspNet.Http.Features.IHttpRequestLifetimeFeature)) + { + _currentIHttpRequestLifetimeFeature = feature; + System.Threading.Interlocked.Increment(ref _featureRevision); + return; + } + if (key == typeof(global::Microsoft.AspNet.Http.Features.ISessionFeature)) + { + _currentISessionFeature = feature; + System.Threading.Interlocked.Increment(ref _featureRevision); + return; + } + if (key == typeof(global::Microsoft.AspNet.Http.Features.Internal.IResponseCookiesFeature)) + { + _currentIResponseCookiesFeature = feature; + System.Threading.Interlocked.Increment(ref _featureRevision); + return; + } + Extra[key] = feature; + } + + private IEnumerable> FastEnumerable() + { + if (_currentIHttpRequestFeature != null) + { + yield return new KeyValuePair(typeof(global::Microsoft.AspNet.Http.Features.IHttpRequestFeature), _currentIHttpRequestFeature); + } + if (_currentIHttpResponseFeature != null) + { + yield return new KeyValuePair(typeof(global::Microsoft.AspNet.Http.Features.IHttpResponseFeature), _currentIHttpResponseFeature); + } + if (_currentIHttpUpgradeFeature != null) + { + yield return new KeyValuePair(typeof(global::Microsoft.AspNet.Http.Features.IHttpUpgradeFeature), _currentIHttpUpgradeFeature); + } + if (_currentIHttpRequestIdentifierFeature != null) + { + yield return new KeyValuePair(typeof(global::Microsoft.AspNet.Http.Features.IHttpRequestIdentifierFeature), _currentIHttpRequestIdentifierFeature); + } + if (_currentIHttpConnectionFeature != null) + { + yield return new KeyValuePair(typeof(global::Microsoft.AspNet.Http.Features.IHttpConnectionFeature), _currentIHttpConnectionFeature); + } + if (_currentITlsConnectionFeature != null) + { + yield return new KeyValuePair(typeof(global::Microsoft.AspNet.Http.Features.ITlsConnectionFeature), _currentITlsConnectionFeature); + } + if (_currentIServiceProvidersFeature != null) + { + yield return new KeyValuePair(typeof(global::Microsoft.AspNet.Http.Features.Internal.IServiceProvidersFeature), _currentIServiceProvidersFeature); + } + if (_currentIHttpSendFileFeature != null) + { + yield return new KeyValuePair(typeof(global::Microsoft.AspNet.Http.Features.IHttpSendFileFeature), _currentIHttpSendFileFeature); + } + if (_currentIHttpWebSocketFeature != null) + { + yield return new KeyValuePair(typeof(global::Microsoft.AspNet.Http.Features.IHttpWebSocketFeature), _currentIHttpWebSocketFeature); + } + if (_currentIQueryFeature != null) + { + yield return new KeyValuePair(typeof(global::Microsoft.AspNet.Http.Features.Internal.IQueryFeature), _currentIQueryFeature); + } + if (_currentIFormFeature != null) + { + yield return new KeyValuePair(typeof(global::Microsoft.AspNet.Http.Features.Internal.IFormFeature), _currentIFormFeature); + } + if (_currentIItemsFeature != null) + { + yield return new KeyValuePair(typeof(global::Microsoft.AspNet.Http.Features.Internal.IItemsFeature), _currentIItemsFeature); + } + if (_currentIHttpAuthenticationFeature != null) + { + yield return new KeyValuePair(typeof(global::Microsoft.AspNet.Http.Features.Authentication.IHttpAuthenticationFeature), _currentIHttpAuthenticationFeature); + } + if (_currentIHttpRequestLifetimeFeature != null) + { + yield return new KeyValuePair(typeof(global::Microsoft.AspNet.Http.Features.IHttpRequestLifetimeFeature), _currentIHttpRequestLifetimeFeature); + } + if (_currentISessionFeature != null) + { + yield return new KeyValuePair(typeof(global::Microsoft.AspNet.Http.Features.ISessionFeature), _currentISessionFeature); + } + if (_currentIResponseCookiesFeature != null) + { + yield return new KeyValuePair(typeof(global::Microsoft.AspNet.Http.Features.Internal.IResponseCookiesFeature), _currentIResponseCookiesFeature); + } + if (MaybeExtra != null) + { + foreach(var item in MaybeExtra) + { + yield return item; + } + } + } + } +} diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs index e70d1bd6fc..7e813bfb11 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs @@ -2,12 +2,14 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; +using Microsoft.AspNet.Http.Features; using Microsoft.AspNet.Server.Kestrel.Infrastructure; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Primitives; @@ -16,7 +18,7 @@ using Microsoft.Extensions.Primitives; namespace Microsoft.AspNet.Server.Kestrel.Http { - public class Frame : FrameContext, IFrameControl + public partial class Frame : FrameContext, IFrameControl { private static readonly Encoding _ascii = Encoding.ASCII; private static readonly ArraySegment _endChunkBytes = CreateAsciiByteArraySegment("\r\n"); @@ -80,6 +82,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http _requestHeaders.Reset(); ResetResponseHeaders(); + ResetFeatureCollection(); Method = null; RequestUri = null; @@ -725,5 +728,5 @@ namespace Microsoft.AspNet.Server.Kestrel.Http statusCode != 205 && statusCode != 304; } - } + } } diff --git a/src/Microsoft.AspNet.Server.Kestrel/KestrelEngine.cs b/src/Microsoft.AspNet.Server.Kestrel/KestrelEngine.cs index aa02efa35f..dec15232f7 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/KestrelEngine.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/KestrelEngine.cs @@ -5,6 +5,7 @@ using System; using System.Collections.Generic; using System.IO; using System.Threading.Tasks; +using Microsoft.AspNet.Http.Features; using Microsoft.AspNet.Server.Kestrel.Http; using Microsoft.AspNet.Server.Kestrel.Infrastructure; using Microsoft.AspNet.Server.Kestrel.Networking; @@ -98,7 +99,7 @@ namespace Microsoft.AspNet.Server.Kestrel Threads.Clear(); } - public IDisposable CreateServer(ServerAddress address, Func application) + public IDisposable CreateServer(ServerAddress address, Func application) { var listeners = new List(); diff --git a/src/Microsoft.AspNet.Server.Kestrel/ServerFactory.cs b/src/Microsoft.AspNet.Server.Kestrel/ServerFactory.cs index ed441bc95d..c804e4c233 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/ServerFactory.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/ServerFactory.cs @@ -88,11 +88,7 @@ namespace Microsoft.AspNet.Server.Kestrel atLeastOneListener = true; disposables.Push(engine.CreateServer( parsedAddress, - async frame => - { - var request = new ServerRequest(frame); - await application.Invoke(request.Features).ConfigureAwait(false); - })); + application)); } } diff --git a/src/Microsoft.AspNet.Server.Kestrel/project.json b/src/Microsoft.AspNet.Server.Kestrel/project.json index 221a1ab18b..f726255872 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/project.json +++ b/src/Microsoft.AspNet.Server.Kestrel/project.json @@ -52,7 +52,7 @@ "scripts": { "prepare": [ "dnu restore ../../tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode", - "dnx -p ../../tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode run Http/FrameHeaders.Generated.cs" + "dnx -p ../../tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode run Http/FrameHeaders.Generated.cs Http/Frame.Generated.cs" ], "postrestore": [ "dnu restore ../../tools/Microsoft.AspNet.Server.Kestrel.LibuvCopier", @@ -65,6 +65,5 @@ "runtimes/win7-x86/native/": "runtimes/win7-x86/native/*", "runtimes/win10-arm/native/": "runtimes/win10-arm/native/*", "runtimes/osx/native/": "runtimes/osx/native/*" - } } diff --git a/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/FrameFeatureCollection.cs b/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/FrameFeatureCollection.cs new file mode 100644 index 0000000000..fe12bc9b7b --- /dev/null +++ b/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/FrameFeatureCollection.cs @@ -0,0 +1,112 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using Microsoft.AspNet.Http.Features; +using Microsoft.Dnx.Compilation.CSharp; +using Microsoft.AspNet.Http.Features.Internal; +using Microsoft.AspNet.Http.Features.Authentication; + +namespace Microsoft.AspNet.Server.Kestrel.GeneratedCode +{ + // This project can output the Class library as a NuGet Package. + // To enable this option, right-click on the project and select the Properties menu item. In the Build tab select "Produce outputs on build". + public class FrameFeatureCollection : ICompileModule + { + static string Each(IEnumerable values, Func formatter) + { + return values.Select(formatter).Aggregate((a, b) => a + b); + } + + public virtual void BeforeCompile(BeforeCompileContext context) + { + var syntaxTree = Microsoft.CodeAnalysis.CSharp.CSharpSyntaxTree.ParseText(GeneratedFile()); + context.Compilation = context.Compilation.AddSyntaxTrees(syntaxTree); + } + + public static string GeneratedFile() + { + var commonFeatures = new[] + { + typeof(IHttpRequestFeature), + typeof(IHttpResponseFeature), + typeof(IHttpRequestIdentifierFeature), + typeof(IHttpSendFileFeature), + typeof(IServiceProvidersFeature), + typeof(IHttpAuthenticationFeature), + typeof(IHttpRequestLifetimeFeature), + typeof(IQueryFeature), + typeof(IFormFeature), + typeof(IResponseCookiesFeature), + typeof(IItemsFeature), + typeof(IHttpConnectionFeature), + typeof(ITlsConnectionFeature), + typeof(IHttpUpgradeFeature), + typeof(IHttpWebSocketFeature), + typeof(ISessionFeature), + }; + + return $@" +using System; +using System.Collections.Generic; + +namespace Microsoft.AspNet.Server.Kestrel.Http +{{ + public partial class Frame + {{ + {Each(commonFeatures, feature => $@" + private object _current{feature.Name};")} + + private void FastReset() + {{{Each(commonFeatures, feature => $@" + _current{feature.Name} = this as global::{feature.FullName};")} + }} + + private object FastFeatureGet(Type key) + {{{Each(commonFeatures, feature => $@" + if (key == typeof(global::{feature.FullName})) + {{ + return _current{feature.Name}; + }}")} + object feature = null; + if (MaybeExtra?.TryGetValue(key, out feature) ?? false) + {{ + return feature; + }} + return null; + }} + + private void FastFeatureSet(Type key, object feature) + {{{Each(commonFeatures, feature => $@" + if (key == typeof(global::{feature.FullName})) + {{ + _current{feature.Name} = feature; + System.Threading.Interlocked.Increment(ref _featureRevision); + return; + }}")} + Extra[key] = feature; + }} + + private IEnumerable> FastEnumerable() + {{{Each(commonFeatures, feature => $@" + if (_current{feature.Name} != null) + {{ + yield return new KeyValuePair(typeof(global::{feature.FullName}), _current{feature.Name}); + }}")} + if (MaybeExtra != null) + {{ + foreach(var item in MaybeExtra) + {{ + yield return item; + }} + }} + }} + }} +}} +"; + } + + public virtual void AfterCompile(AfterCompileContext context) + { + } + } +} diff --git a/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/Program.cs b/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/Program.cs index 2a77e2542e..3727772c03 100644 --- a/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/Program.cs +++ b/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/Program.cs @@ -7,19 +7,34 @@ namespace Microsoft.AspNet.Server.Kestrel.GeneratedCode { public int Main(string[] args) { - var text = KnownHeaders.GeneratedFile(); + var text0 = KnownHeaders.GeneratedFile(); + var text1 = FrameFeatureCollection.GeneratedFile(); if (args.Length == 1) { var existing = File.Exists(args[0]) ? File.ReadAllText(args[0]) : ""; - if (!string.Equals(text, existing)) + if (!string.Equals(text0, existing)) { - File.WriteAllText(args[0], text); + File.WriteAllText(args[0], text0); + } + } + else if (args.Length == 2) + { + var existing0 = File.Exists(args[0]) ? File.ReadAllText(args[0]) : ""; + if (!string.Equals(text0, existing0)) + { + File.WriteAllText(args[0], text0); + } + + var existing1 = File.Exists(args[1]) ? File.ReadAllText(args[1]) : ""; + if (!string.Equals(text1, existing1)) + { + File.WriteAllText(args[1], text1); } } else { - Console.WriteLine(text); + Console.WriteLine(text0); } return 0; } diff --git a/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/project.json b/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/project.json index 75adb1ec73..465bd1b866 100644 --- a/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/project.json +++ b/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/project.json @@ -1,8 +1,10 @@ -{ +{ "version": "1.0.0-*", "dependencies": { - "Microsoft.Dnx.Compilation.CSharp.Abstractions": "1.0.0-*" + "Microsoft.Dnx.Compilation.CSharp.Abstractions": "1.0.0-*", + "Microsoft.AspNet.Http.Features": "1.0.0-*", + "Microsoft.AspNet.Hosting": "1.0.0-*" }, "commands": { From d48a27dd5948af15c88d3918df1bf80672199d7d Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Sat, 3 Oct 2015 10:39:39 -0400 Subject: [PATCH 0326/1662] Use bitflag for override and cache typeof in statics --- .../Http/Frame.Generated.cs | 361 +++++++++++------- .../FrameFeatureCollection.cs | 48 ++- 2 files changed, 255 insertions(+), 154 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.Generated.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.Generated.cs index afe65ec80a..b403640026 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.Generated.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.Generated.cs @@ -7,109 +7,183 @@ namespace Microsoft.AspNet.Server.Kestrel.Http public partial class Frame { - private object _currentIHttpRequestFeature; - private object _currentIHttpResponseFeature; - private object _currentIHttpUpgradeFeature; - private object _currentIHttpRequestIdentifierFeature; - private object _currentIHttpConnectionFeature; - private object _currentITlsConnectionFeature; - private object _currentIServiceProvidersFeature; - private object _currentIHttpSendFileFeature; - private object _currentIHttpWebSocketFeature; - private object _currentIQueryFeature; - private object _currentIFormFeature; - private object _currentIItemsFeature; - private object _currentIHttpAuthenticationFeature; - private object _currentIHttpRequestLifetimeFeature; - private object _currentISessionFeature; - private object _currentIResponseCookiesFeature; + private const long flagIHttpRequestFeature = 1; + private const long flagIHttpResponseFeature = 2; + private const long flagIHttpRequestIdentifierFeature = 4; + private const long flagIHttpSendFileFeature = 8; + private const long flagIServiceProvidersFeature = 16; + private const long flagIHttpAuthenticationFeature = 32; + private const long flagIHttpRequestLifetimeFeature = 64; + private const long flagIQueryFeature = 128; + private const long flagIFormFeature = 256; + private const long flagIResponseCookiesFeature = 512; + private const long flagIItemsFeature = 1024; + private const long flagIHttpConnectionFeature = 2048; + private const long flagITlsConnectionFeature = 4096; + private const long flagIHttpUpgradeFeature = 8192; + private const long flagIHttpWebSocketFeature = 16384; + private const long flagISessionFeature = 32768; + + + private static readonly Type IHttpRequestFeatureType = typeof(global::Microsoft.AspNet.Http.Features.IHttpRequestFeature); + private static readonly Type IHttpResponseFeatureType = typeof(global::Microsoft.AspNet.Http.Features.IHttpResponseFeature); + private static readonly Type IHttpRequestIdentifierFeatureType = typeof(global::Microsoft.AspNet.Http.Features.IHttpRequestIdentifierFeature); + private static readonly Type IHttpSendFileFeatureType = typeof(global::Microsoft.AspNet.Http.Features.IHttpSendFileFeature); + private static readonly Type IServiceProvidersFeatureType = typeof(global::Microsoft.AspNet.Http.Features.Internal.IServiceProvidersFeature); + private static readonly Type IHttpAuthenticationFeatureType = typeof(global::Microsoft.AspNet.Http.Features.Authentication.IHttpAuthenticationFeature); + private static readonly Type IHttpRequestLifetimeFeatureType = typeof(global::Microsoft.AspNet.Http.Features.IHttpRequestLifetimeFeature); + private static readonly Type IQueryFeatureType = typeof(global::Microsoft.AspNet.Http.Features.Internal.IQueryFeature); + private static readonly Type IFormFeatureType = typeof(global::Microsoft.AspNet.Http.Features.Internal.IFormFeature); + private static readonly Type IResponseCookiesFeatureType = typeof(global::Microsoft.AspNet.Http.Features.Internal.IResponseCookiesFeature); + private static readonly Type IItemsFeatureType = typeof(global::Microsoft.AspNet.Http.Features.Internal.IItemsFeature); + private static readonly Type IHttpConnectionFeatureType = typeof(global::Microsoft.AspNet.Http.Features.IHttpConnectionFeature); + private static readonly Type ITlsConnectionFeatureType = typeof(global::Microsoft.AspNet.Http.Features.ITlsConnectionFeature); + private static readonly Type IHttpUpgradeFeatureType = typeof(global::Microsoft.AspNet.Http.Features.IHttpUpgradeFeature); + private static readonly Type IHttpWebSocketFeatureType = typeof(global::Microsoft.AspNet.Http.Features.IHttpWebSocketFeature); + private static readonly Type ISessionFeatureType = typeof(global::Microsoft.AspNet.Http.Features.ISessionFeature); + + private long _featureOverridenFlags = 0L; private void FastReset() { - _currentIHttpRequestFeature = this as global::Microsoft.AspNet.Http.Features.IHttpRequestFeature; - _currentIHttpResponseFeature = this as global::Microsoft.AspNet.Http.Features.IHttpResponseFeature; - _currentIHttpUpgradeFeature = this as global::Microsoft.AspNet.Http.Features.IHttpUpgradeFeature; - _currentIHttpRequestIdentifierFeature = this as global::Microsoft.AspNet.Http.Features.IHttpRequestIdentifierFeature; - _currentIHttpConnectionFeature = this as global::Microsoft.AspNet.Http.Features.IHttpConnectionFeature; - _currentITlsConnectionFeature = this as global::Microsoft.AspNet.Http.Features.ITlsConnectionFeature; - _currentIServiceProvidersFeature = this as global::Microsoft.AspNet.Http.Features.Internal.IServiceProvidersFeature; - _currentIHttpSendFileFeature = this as global::Microsoft.AspNet.Http.Features.IHttpSendFileFeature; - _currentIHttpWebSocketFeature = this as global::Microsoft.AspNet.Http.Features.IHttpWebSocketFeature; - _currentIQueryFeature = this as global::Microsoft.AspNet.Http.Features.Internal.IQueryFeature; - _currentIFormFeature = this as global::Microsoft.AspNet.Http.Features.Internal.IFormFeature; - _currentIItemsFeature = this as global::Microsoft.AspNet.Http.Features.Internal.IItemsFeature; - _currentIHttpAuthenticationFeature = this as global::Microsoft.AspNet.Http.Features.Authentication.IHttpAuthenticationFeature; - _currentIHttpRequestLifetimeFeature = this as global::Microsoft.AspNet.Http.Features.IHttpRequestLifetimeFeature; - _currentISessionFeature = this as global::Microsoft.AspNet.Http.Features.ISessionFeature; - _currentIResponseCookiesFeature = this as global::Microsoft.AspNet.Http.Features.Internal.IResponseCookiesFeature; + _featureOverridenFlags = 0L; } private object FastFeatureGet(Type key) { - if (key == typeof(global::Microsoft.AspNet.Http.Features.IHttpRequestFeature)) + if (key == IHttpRequestFeatureType) { - return _currentIHttpRequestFeature; + if ((_featureOverridenFlags & flagIHttpRequestFeature) == 0L) + { + return this as global::Microsoft.AspNet.Http.Features.IHttpRequestFeature; + } + return SlowFeatureGet(key); } - if (key == typeof(global::Microsoft.AspNet.Http.Features.IHttpResponseFeature)) + if (key == IHttpResponseFeatureType) { - return _currentIHttpResponseFeature; + if ((_featureOverridenFlags & flagIHttpResponseFeature) == 0L) + { + return this as global::Microsoft.AspNet.Http.Features.IHttpResponseFeature; + } + return SlowFeatureGet(key); } - if (key == typeof(global::Microsoft.AspNet.Http.Features.IHttpUpgradeFeature)) + if (key == IHttpRequestIdentifierFeatureType) { - return _currentIHttpUpgradeFeature; + if ((_featureOverridenFlags & flagIHttpRequestIdentifierFeature) == 0L) + { + return this as global::Microsoft.AspNet.Http.Features.IHttpRequestIdentifierFeature; + } + return SlowFeatureGet(key); } - if (key == typeof(global::Microsoft.AspNet.Http.Features.IHttpRequestIdentifierFeature)) + if (key == IHttpSendFileFeatureType) { - return _currentIHttpRequestIdentifierFeature; + if ((_featureOverridenFlags & flagIHttpSendFileFeature) == 0L) + { + return this as global::Microsoft.AspNet.Http.Features.IHttpSendFileFeature; + } + return SlowFeatureGet(key); } - if (key == typeof(global::Microsoft.AspNet.Http.Features.IHttpConnectionFeature)) + if (key == IServiceProvidersFeatureType) { - return _currentIHttpConnectionFeature; + if ((_featureOverridenFlags & flagIServiceProvidersFeature) == 0L) + { + return this as global::Microsoft.AspNet.Http.Features.Internal.IServiceProvidersFeature; + } + return SlowFeatureGet(key); } - if (key == typeof(global::Microsoft.AspNet.Http.Features.ITlsConnectionFeature)) + if (key == IHttpAuthenticationFeatureType) { - return _currentITlsConnectionFeature; + if ((_featureOverridenFlags & flagIHttpAuthenticationFeature) == 0L) + { + return this as global::Microsoft.AspNet.Http.Features.Authentication.IHttpAuthenticationFeature; + } + return SlowFeatureGet(key); } - if (key == typeof(global::Microsoft.AspNet.Http.Features.Internal.IServiceProvidersFeature)) + if (key == IHttpRequestLifetimeFeatureType) { - return _currentIServiceProvidersFeature; + if ((_featureOverridenFlags & flagIHttpRequestLifetimeFeature) == 0L) + { + return this as global::Microsoft.AspNet.Http.Features.IHttpRequestLifetimeFeature; + } + return SlowFeatureGet(key); } - if (key == typeof(global::Microsoft.AspNet.Http.Features.IHttpSendFileFeature)) + if (key == IQueryFeatureType) { - return _currentIHttpSendFileFeature; + if ((_featureOverridenFlags & flagIQueryFeature) == 0L) + { + return this as global::Microsoft.AspNet.Http.Features.Internal.IQueryFeature; + } + return SlowFeatureGet(key); } - if (key == typeof(global::Microsoft.AspNet.Http.Features.IHttpWebSocketFeature)) + if (key == IFormFeatureType) { - return _currentIHttpWebSocketFeature; + if ((_featureOverridenFlags & flagIFormFeature) == 0L) + { + return this as global::Microsoft.AspNet.Http.Features.Internal.IFormFeature; + } + return SlowFeatureGet(key); } - if (key == typeof(global::Microsoft.AspNet.Http.Features.Internal.IQueryFeature)) + if (key == IResponseCookiesFeatureType) { - return _currentIQueryFeature; + if ((_featureOverridenFlags & flagIResponseCookiesFeature) == 0L) + { + return this as global::Microsoft.AspNet.Http.Features.Internal.IResponseCookiesFeature; + } + return SlowFeatureGet(key); } - if (key == typeof(global::Microsoft.AspNet.Http.Features.Internal.IFormFeature)) + if (key == IItemsFeatureType) { - return _currentIFormFeature; + if ((_featureOverridenFlags & flagIItemsFeature) == 0L) + { + return this as global::Microsoft.AspNet.Http.Features.Internal.IItemsFeature; + } + return SlowFeatureGet(key); } - if (key == typeof(global::Microsoft.AspNet.Http.Features.Internal.IItemsFeature)) + if (key == IHttpConnectionFeatureType) { - return _currentIItemsFeature; + if ((_featureOverridenFlags & flagIHttpConnectionFeature) == 0L) + { + return this as global::Microsoft.AspNet.Http.Features.IHttpConnectionFeature; + } + return SlowFeatureGet(key); } - if (key == typeof(global::Microsoft.AspNet.Http.Features.Authentication.IHttpAuthenticationFeature)) + if (key == ITlsConnectionFeatureType) { - return _currentIHttpAuthenticationFeature; + if ((_featureOverridenFlags & flagITlsConnectionFeature) == 0L) + { + return this as global::Microsoft.AspNet.Http.Features.ITlsConnectionFeature; + } + return SlowFeatureGet(key); } - if (key == typeof(global::Microsoft.AspNet.Http.Features.IHttpRequestLifetimeFeature)) + if (key == IHttpUpgradeFeatureType) { - return _currentIHttpRequestLifetimeFeature; + if ((_featureOverridenFlags & flagIHttpUpgradeFeature) == 0L) + { + return this as global::Microsoft.AspNet.Http.Features.IHttpUpgradeFeature; + } + return SlowFeatureGet(key); } - if (key == typeof(global::Microsoft.AspNet.Http.Features.ISessionFeature)) + if (key == IHttpWebSocketFeatureType) { - return _currentISessionFeature; + if ((_featureOverridenFlags & flagIHttpWebSocketFeature) == 0L) + { + return this as global::Microsoft.AspNet.Http.Features.IHttpWebSocketFeature; + } + return SlowFeatureGet(key); } - if (key == typeof(global::Microsoft.AspNet.Http.Features.Internal.IResponseCookiesFeature)) + if (key == ISessionFeatureType) { - return _currentIResponseCookiesFeature; + if ((_featureOverridenFlags & flagISessionFeature) == 0L) + { + return this as global::Microsoft.AspNet.Http.Features.ISessionFeature; + } + return SlowFeatureGet(key); } + return SlowFeatureGet(key); + } + + private object SlowFeatureGet(Type key) + { object feature = null; if (MaybeExtra?.TryGetValue(key, out feature) ?? false) { @@ -118,102 +192,101 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return null; } + private void FastFeatureSetInner(long flag, Type key, object feature) + { + Extra[key] = feature; + + long currentFeatureFlags; + long updatedFeatureFlags; + do + { + currentFeatureFlags = _featureOverridenFlags; + updatedFeatureFlags = currentFeatureFlags | flag; + } while (System.Threading.Interlocked.CompareExchange(ref _featureOverridenFlags, updatedFeatureFlags, currentFeatureFlags) != currentFeatureFlags); + + System.Threading.Interlocked.Increment(ref _featureRevision); + } + private void FastFeatureSet(Type key, object feature) { - if (key == typeof(global::Microsoft.AspNet.Http.Features.IHttpRequestFeature)) + if (key == IHttpRequestFeatureType) { - _currentIHttpRequestFeature = feature; - System.Threading.Interlocked.Increment(ref _featureRevision); + FastFeatureSetInner(flagIHttpRequestFeature, key, feature); return; } - if (key == typeof(global::Microsoft.AspNet.Http.Features.IHttpResponseFeature)) + if (key == IHttpResponseFeatureType) { - _currentIHttpResponseFeature = feature; - System.Threading.Interlocked.Increment(ref _featureRevision); + FastFeatureSetInner(flagIHttpResponseFeature, key, feature); return; } - if (key == typeof(global::Microsoft.AspNet.Http.Features.IHttpUpgradeFeature)) + if (key == IHttpRequestIdentifierFeatureType) { - _currentIHttpUpgradeFeature = feature; - System.Threading.Interlocked.Increment(ref _featureRevision); + FastFeatureSetInner(flagIHttpRequestIdentifierFeature, key, feature); return; } - if (key == typeof(global::Microsoft.AspNet.Http.Features.IHttpRequestIdentifierFeature)) + if (key == IHttpSendFileFeatureType) { - _currentIHttpRequestIdentifierFeature = feature; - System.Threading.Interlocked.Increment(ref _featureRevision); + FastFeatureSetInner(flagIHttpSendFileFeature, key, feature); return; } - if (key == typeof(global::Microsoft.AspNet.Http.Features.IHttpConnectionFeature)) + if (key == IServiceProvidersFeatureType) { - _currentIHttpConnectionFeature = feature; - System.Threading.Interlocked.Increment(ref _featureRevision); + FastFeatureSetInner(flagIServiceProvidersFeature, key, feature); return; } - if (key == typeof(global::Microsoft.AspNet.Http.Features.ITlsConnectionFeature)) + if (key == IHttpAuthenticationFeatureType) { - _currentITlsConnectionFeature = feature; - System.Threading.Interlocked.Increment(ref _featureRevision); + FastFeatureSetInner(flagIHttpAuthenticationFeature, key, feature); return; } - if (key == typeof(global::Microsoft.AspNet.Http.Features.Internal.IServiceProvidersFeature)) + if (key == IHttpRequestLifetimeFeatureType) { - _currentIServiceProvidersFeature = feature; - System.Threading.Interlocked.Increment(ref _featureRevision); + FastFeatureSetInner(flagIHttpRequestLifetimeFeature, key, feature); return; } - if (key == typeof(global::Microsoft.AspNet.Http.Features.IHttpSendFileFeature)) + if (key == IQueryFeatureType) { - _currentIHttpSendFileFeature = feature; - System.Threading.Interlocked.Increment(ref _featureRevision); + FastFeatureSetInner(flagIQueryFeature, key, feature); return; } - if (key == typeof(global::Microsoft.AspNet.Http.Features.IHttpWebSocketFeature)) + if (key == IFormFeatureType) { - _currentIHttpWebSocketFeature = feature; - System.Threading.Interlocked.Increment(ref _featureRevision); + FastFeatureSetInner(flagIFormFeature, key, feature); return; } - if (key == typeof(global::Microsoft.AspNet.Http.Features.Internal.IQueryFeature)) + if (key == IResponseCookiesFeatureType) { - _currentIQueryFeature = feature; - System.Threading.Interlocked.Increment(ref _featureRevision); + FastFeatureSetInner(flagIResponseCookiesFeature, key, feature); return; } - if (key == typeof(global::Microsoft.AspNet.Http.Features.Internal.IFormFeature)) + if (key == IItemsFeatureType) { - _currentIFormFeature = feature; - System.Threading.Interlocked.Increment(ref _featureRevision); + FastFeatureSetInner(flagIItemsFeature, key, feature); return; } - if (key == typeof(global::Microsoft.AspNet.Http.Features.Internal.IItemsFeature)) + if (key == IHttpConnectionFeatureType) { - _currentIItemsFeature = feature; - System.Threading.Interlocked.Increment(ref _featureRevision); + FastFeatureSetInner(flagIHttpConnectionFeature, key, feature); return; } - if (key == typeof(global::Microsoft.AspNet.Http.Features.Authentication.IHttpAuthenticationFeature)) + if (key == ITlsConnectionFeatureType) { - _currentIHttpAuthenticationFeature = feature; - System.Threading.Interlocked.Increment(ref _featureRevision); + FastFeatureSetInner(flagITlsConnectionFeature, key, feature); return; } - if (key == typeof(global::Microsoft.AspNet.Http.Features.IHttpRequestLifetimeFeature)) + if (key == IHttpUpgradeFeatureType) { - _currentIHttpRequestLifetimeFeature = feature; - System.Threading.Interlocked.Increment(ref _featureRevision); + FastFeatureSetInner(flagIHttpUpgradeFeature, key, feature); return; } - if (key == typeof(global::Microsoft.AspNet.Http.Features.ISessionFeature)) + if (key == IHttpWebSocketFeatureType) { - _currentISessionFeature = feature; - System.Threading.Interlocked.Increment(ref _featureRevision); + FastFeatureSetInner(flagIHttpWebSocketFeature, key, feature); return; } - if (key == typeof(global::Microsoft.AspNet.Http.Features.Internal.IResponseCookiesFeature)) + if (key == ISessionFeatureType) { - _currentIResponseCookiesFeature = feature; - System.Threading.Interlocked.Increment(ref _featureRevision); + FastFeatureSetInner(flagISessionFeature, key, feature); return; } Extra[key] = feature; @@ -221,69 +294,69 @@ namespace Microsoft.AspNet.Server.Kestrel.Http private IEnumerable> FastEnumerable() { - if (_currentIHttpRequestFeature != null) + if ((_featureOverridenFlags & flagIHttpRequestFeature) == 0L) { - yield return new KeyValuePair(typeof(global::Microsoft.AspNet.Http.Features.IHttpRequestFeature), _currentIHttpRequestFeature); + yield return new KeyValuePair(typeof(global::Microsoft.AspNet.Http.Features.IHttpRequestFeature), this as global::Microsoft.AspNet.Http.Features.IHttpRequestFeature); } - if (_currentIHttpResponseFeature != null) + if ((_featureOverridenFlags & flagIHttpResponseFeature) == 0L) { - yield return new KeyValuePair(typeof(global::Microsoft.AspNet.Http.Features.IHttpResponseFeature), _currentIHttpResponseFeature); + yield return new KeyValuePair(typeof(global::Microsoft.AspNet.Http.Features.IHttpResponseFeature), this as global::Microsoft.AspNet.Http.Features.IHttpResponseFeature); } - if (_currentIHttpUpgradeFeature != null) + if ((_featureOverridenFlags & flagIHttpRequestIdentifierFeature) == 0L) { - yield return new KeyValuePair(typeof(global::Microsoft.AspNet.Http.Features.IHttpUpgradeFeature), _currentIHttpUpgradeFeature); + yield return new KeyValuePair(typeof(global::Microsoft.AspNet.Http.Features.IHttpRequestIdentifierFeature), this as global::Microsoft.AspNet.Http.Features.IHttpRequestIdentifierFeature); } - if (_currentIHttpRequestIdentifierFeature != null) + if ((_featureOverridenFlags & flagIHttpSendFileFeature) == 0L) { - yield return new KeyValuePair(typeof(global::Microsoft.AspNet.Http.Features.IHttpRequestIdentifierFeature), _currentIHttpRequestIdentifierFeature); + yield return new KeyValuePair(typeof(global::Microsoft.AspNet.Http.Features.IHttpSendFileFeature), this as global::Microsoft.AspNet.Http.Features.IHttpSendFileFeature); } - if (_currentIHttpConnectionFeature != null) + if ((_featureOverridenFlags & flagIServiceProvidersFeature) == 0L) { - yield return new KeyValuePair(typeof(global::Microsoft.AspNet.Http.Features.IHttpConnectionFeature), _currentIHttpConnectionFeature); + yield return new KeyValuePair(typeof(global::Microsoft.AspNet.Http.Features.Internal.IServiceProvidersFeature), this as global::Microsoft.AspNet.Http.Features.Internal.IServiceProvidersFeature); } - if (_currentITlsConnectionFeature != null) + if ((_featureOverridenFlags & flagIHttpAuthenticationFeature) == 0L) { - yield return new KeyValuePair(typeof(global::Microsoft.AspNet.Http.Features.ITlsConnectionFeature), _currentITlsConnectionFeature); + yield return new KeyValuePair(typeof(global::Microsoft.AspNet.Http.Features.Authentication.IHttpAuthenticationFeature), this as global::Microsoft.AspNet.Http.Features.Authentication.IHttpAuthenticationFeature); } - if (_currentIServiceProvidersFeature != null) + if ((_featureOverridenFlags & flagIHttpRequestLifetimeFeature) == 0L) { - yield return new KeyValuePair(typeof(global::Microsoft.AspNet.Http.Features.Internal.IServiceProvidersFeature), _currentIServiceProvidersFeature); + yield return new KeyValuePair(typeof(global::Microsoft.AspNet.Http.Features.IHttpRequestLifetimeFeature), this as global::Microsoft.AspNet.Http.Features.IHttpRequestLifetimeFeature); } - if (_currentIHttpSendFileFeature != null) + if ((_featureOverridenFlags & flagIQueryFeature) == 0L) { - yield return new KeyValuePair(typeof(global::Microsoft.AspNet.Http.Features.IHttpSendFileFeature), _currentIHttpSendFileFeature); + yield return new KeyValuePair(typeof(global::Microsoft.AspNet.Http.Features.Internal.IQueryFeature), this as global::Microsoft.AspNet.Http.Features.Internal.IQueryFeature); } - if (_currentIHttpWebSocketFeature != null) + if ((_featureOverridenFlags & flagIFormFeature) == 0L) { - yield return new KeyValuePair(typeof(global::Microsoft.AspNet.Http.Features.IHttpWebSocketFeature), _currentIHttpWebSocketFeature); + yield return new KeyValuePair(typeof(global::Microsoft.AspNet.Http.Features.Internal.IFormFeature), this as global::Microsoft.AspNet.Http.Features.Internal.IFormFeature); } - if (_currentIQueryFeature != null) + if ((_featureOverridenFlags & flagIResponseCookiesFeature) == 0L) { - yield return new KeyValuePair(typeof(global::Microsoft.AspNet.Http.Features.Internal.IQueryFeature), _currentIQueryFeature); + yield return new KeyValuePair(typeof(global::Microsoft.AspNet.Http.Features.Internal.IResponseCookiesFeature), this as global::Microsoft.AspNet.Http.Features.Internal.IResponseCookiesFeature); } - if (_currentIFormFeature != null) + if ((_featureOverridenFlags & flagIItemsFeature) == 0L) { - yield return new KeyValuePair(typeof(global::Microsoft.AspNet.Http.Features.Internal.IFormFeature), _currentIFormFeature); + yield return new KeyValuePair(typeof(global::Microsoft.AspNet.Http.Features.Internal.IItemsFeature), this as global::Microsoft.AspNet.Http.Features.Internal.IItemsFeature); } - if (_currentIItemsFeature != null) + if ((_featureOverridenFlags & flagIHttpConnectionFeature) == 0L) { - yield return new KeyValuePair(typeof(global::Microsoft.AspNet.Http.Features.Internal.IItemsFeature), _currentIItemsFeature); + yield return new KeyValuePair(typeof(global::Microsoft.AspNet.Http.Features.IHttpConnectionFeature), this as global::Microsoft.AspNet.Http.Features.IHttpConnectionFeature); } - if (_currentIHttpAuthenticationFeature != null) + if ((_featureOverridenFlags & flagITlsConnectionFeature) == 0L) { - yield return new KeyValuePair(typeof(global::Microsoft.AspNet.Http.Features.Authentication.IHttpAuthenticationFeature), _currentIHttpAuthenticationFeature); + yield return new KeyValuePair(typeof(global::Microsoft.AspNet.Http.Features.ITlsConnectionFeature), this as global::Microsoft.AspNet.Http.Features.ITlsConnectionFeature); } - if (_currentIHttpRequestLifetimeFeature != null) + if ((_featureOverridenFlags & flagIHttpUpgradeFeature) == 0L) { - yield return new KeyValuePair(typeof(global::Microsoft.AspNet.Http.Features.IHttpRequestLifetimeFeature), _currentIHttpRequestLifetimeFeature); + yield return new KeyValuePair(typeof(global::Microsoft.AspNet.Http.Features.IHttpUpgradeFeature), this as global::Microsoft.AspNet.Http.Features.IHttpUpgradeFeature); } - if (_currentISessionFeature != null) + if ((_featureOverridenFlags & flagIHttpWebSocketFeature) == 0L) { - yield return new KeyValuePair(typeof(global::Microsoft.AspNet.Http.Features.ISessionFeature), _currentISessionFeature); + yield return new KeyValuePair(typeof(global::Microsoft.AspNet.Http.Features.IHttpWebSocketFeature), this as global::Microsoft.AspNet.Http.Features.IHttpWebSocketFeature); } - if (_currentIResponseCookiesFeature != null) + if ((_featureOverridenFlags & flagISessionFeature) == 0L) { - yield return new KeyValuePair(typeof(global::Microsoft.AspNet.Http.Features.Internal.IResponseCookiesFeature), _currentIResponseCookiesFeature); + yield return new KeyValuePair(typeof(global::Microsoft.AspNet.Http.Features.ISessionFeature), this as global::Microsoft.AspNet.Http.Features.ISessionFeature); } if (MaybeExtra != null) { diff --git a/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/FrameFeatureCollection.cs b/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/FrameFeatureCollection.cs index fe12bc9b7b..a2ae871972 100644 --- a/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/FrameFeatureCollection.cs +++ b/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/FrameFeatureCollection.cs @@ -53,20 +53,34 @@ namespace Microsoft.AspNet.Server.Kestrel.Http {{ public partial class Frame {{ + {Each(commonFeatures.Select((feature, index) => new { feature, index }), entry => $@" + private const long flag{entry.feature.Name} = {1 << entry.index};")} + {Each(commonFeatures, feature => $@" - private object _current{feature.Name};")} + private static readonly Type {feature.Name}Type = typeof(global::{feature.FullName});")} + + private long _featureOverridenFlags = 0L; private void FastReset() - {{{Each(commonFeatures, feature => $@" - _current{feature.Name} = this as global::{feature.FullName};")} + {{ + _featureOverridenFlags = 0L; }} private object FastFeatureGet(Type key) {{{Each(commonFeatures, feature => $@" - if (key == typeof(global::{feature.FullName})) + if (key == {feature.Name}Type) {{ - return _current{feature.Name}; + if ((_featureOverridenFlags & flag{feature.Name}) == 0L) + {{ + return this as global::{feature.FullName}; + }} + return SlowFeatureGet(key); }}")} + return SlowFeatureGet(key); + }} + + private object SlowFeatureGet(Type key) + {{ object feature = null; if (MaybeExtra?.TryGetValue(key, out feature) ?? false) {{ @@ -75,12 +89,26 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return null; }} + private void FastFeatureSetInner(long flag, Type key, object feature) + {{ + Extra[key] = feature; + + long currentFeatureFlags; + long updatedFeatureFlags; + do + {{ + currentFeatureFlags = _featureOverridenFlags; + updatedFeatureFlags = currentFeatureFlags | flag; + }} while (System.Threading.Interlocked.CompareExchange(ref _featureOverridenFlags, updatedFeatureFlags, currentFeatureFlags) != currentFeatureFlags); + + System.Threading.Interlocked.Increment(ref _featureRevision); + }} + private void FastFeatureSet(Type key, object feature) {{{Each(commonFeatures, feature => $@" - if (key == typeof(global::{feature.FullName})) + if (key == {feature.Name}Type) {{ - _current{feature.Name} = feature; - System.Threading.Interlocked.Increment(ref _featureRevision); + FastFeatureSetInner(flag{feature.Name}, key, feature); return; }}")} Extra[key] = feature; @@ -88,9 +116,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Http private IEnumerable> FastEnumerable() {{{Each(commonFeatures, feature => $@" - if (_current{feature.Name} != null) + if ((_featureOverridenFlags & flag{feature.Name}) == 0L) {{ - yield return new KeyValuePair(typeof(global::{feature.FullName}), _current{feature.Name}); + yield return new KeyValuePair(typeof(global::{feature.FullName}), this as global::{feature.FullName}); }}")} if (MaybeExtra != null) {{ From 05702e81e61f87a6269e10aa12c336b0901aa417 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Sat, 3 Oct 2015 10:55:53 -0400 Subject: [PATCH 0327/1662] more typeof caching --- .../Http/Frame.Generated.cs | 32 +++++++++---------- .../FrameFeatureCollection.cs | 2 +- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.Generated.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.Generated.cs index b403640026..89892a9052 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.Generated.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.Generated.cs @@ -296,67 +296,67 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { if ((_featureOverridenFlags & flagIHttpRequestFeature) == 0L) { - yield return new KeyValuePair(typeof(global::Microsoft.AspNet.Http.Features.IHttpRequestFeature), this as global::Microsoft.AspNet.Http.Features.IHttpRequestFeature); + yield return new KeyValuePair(IHttpRequestFeatureType, this as global::Microsoft.AspNet.Http.Features.IHttpRequestFeature); } if ((_featureOverridenFlags & flagIHttpResponseFeature) == 0L) { - yield return new KeyValuePair(typeof(global::Microsoft.AspNet.Http.Features.IHttpResponseFeature), this as global::Microsoft.AspNet.Http.Features.IHttpResponseFeature); + yield return new KeyValuePair(IHttpResponseFeatureType, this as global::Microsoft.AspNet.Http.Features.IHttpResponseFeature); } if ((_featureOverridenFlags & flagIHttpRequestIdentifierFeature) == 0L) { - yield return new KeyValuePair(typeof(global::Microsoft.AspNet.Http.Features.IHttpRequestIdentifierFeature), this as global::Microsoft.AspNet.Http.Features.IHttpRequestIdentifierFeature); + yield return new KeyValuePair(IHttpRequestIdentifierFeatureType, this as global::Microsoft.AspNet.Http.Features.IHttpRequestIdentifierFeature); } if ((_featureOverridenFlags & flagIHttpSendFileFeature) == 0L) { - yield return new KeyValuePair(typeof(global::Microsoft.AspNet.Http.Features.IHttpSendFileFeature), this as global::Microsoft.AspNet.Http.Features.IHttpSendFileFeature); + yield return new KeyValuePair(IHttpSendFileFeatureType, this as global::Microsoft.AspNet.Http.Features.IHttpSendFileFeature); } if ((_featureOverridenFlags & flagIServiceProvidersFeature) == 0L) { - yield return new KeyValuePair(typeof(global::Microsoft.AspNet.Http.Features.Internal.IServiceProvidersFeature), this as global::Microsoft.AspNet.Http.Features.Internal.IServiceProvidersFeature); + yield return new KeyValuePair(IServiceProvidersFeatureType, this as global::Microsoft.AspNet.Http.Features.Internal.IServiceProvidersFeature); } if ((_featureOverridenFlags & flagIHttpAuthenticationFeature) == 0L) { - yield return new KeyValuePair(typeof(global::Microsoft.AspNet.Http.Features.Authentication.IHttpAuthenticationFeature), this as global::Microsoft.AspNet.Http.Features.Authentication.IHttpAuthenticationFeature); + yield return new KeyValuePair(IHttpAuthenticationFeatureType, this as global::Microsoft.AspNet.Http.Features.Authentication.IHttpAuthenticationFeature); } if ((_featureOverridenFlags & flagIHttpRequestLifetimeFeature) == 0L) { - yield return new KeyValuePair(typeof(global::Microsoft.AspNet.Http.Features.IHttpRequestLifetimeFeature), this as global::Microsoft.AspNet.Http.Features.IHttpRequestLifetimeFeature); + yield return new KeyValuePair(IHttpRequestLifetimeFeatureType, this as global::Microsoft.AspNet.Http.Features.IHttpRequestLifetimeFeature); } if ((_featureOverridenFlags & flagIQueryFeature) == 0L) { - yield return new KeyValuePair(typeof(global::Microsoft.AspNet.Http.Features.Internal.IQueryFeature), this as global::Microsoft.AspNet.Http.Features.Internal.IQueryFeature); + yield return new KeyValuePair(IQueryFeatureType, this as global::Microsoft.AspNet.Http.Features.Internal.IQueryFeature); } if ((_featureOverridenFlags & flagIFormFeature) == 0L) { - yield return new KeyValuePair(typeof(global::Microsoft.AspNet.Http.Features.Internal.IFormFeature), this as global::Microsoft.AspNet.Http.Features.Internal.IFormFeature); + yield return new KeyValuePair(IFormFeatureType, this as global::Microsoft.AspNet.Http.Features.Internal.IFormFeature); } if ((_featureOverridenFlags & flagIResponseCookiesFeature) == 0L) { - yield return new KeyValuePair(typeof(global::Microsoft.AspNet.Http.Features.Internal.IResponseCookiesFeature), this as global::Microsoft.AspNet.Http.Features.Internal.IResponseCookiesFeature); + yield return new KeyValuePair(IResponseCookiesFeatureType, this as global::Microsoft.AspNet.Http.Features.Internal.IResponseCookiesFeature); } if ((_featureOverridenFlags & flagIItemsFeature) == 0L) { - yield return new KeyValuePair(typeof(global::Microsoft.AspNet.Http.Features.Internal.IItemsFeature), this as global::Microsoft.AspNet.Http.Features.Internal.IItemsFeature); + yield return new KeyValuePair(IItemsFeatureType, this as global::Microsoft.AspNet.Http.Features.Internal.IItemsFeature); } if ((_featureOverridenFlags & flagIHttpConnectionFeature) == 0L) { - yield return new KeyValuePair(typeof(global::Microsoft.AspNet.Http.Features.IHttpConnectionFeature), this as global::Microsoft.AspNet.Http.Features.IHttpConnectionFeature); + yield return new KeyValuePair(IHttpConnectionFeatureType, this as global::Microsoft.AspNet.Http.Features.IHttpConnectionFeature); } if ((_featureOverridenFlags & flagITlsConnectionFeature) == 0L) { - yield return new KeyValuePair(typeof(global::Microsoft.AspNet.Http.Features.ITlsConnectionFeature), this as global::Microsoft.AspNet.Http.Features.ITlsConnectionFeature); + yield return new KeyValuePair(ITlsConnectionFeatureType, this as global::Microsoft.AspNet.Http.Features.ITlsConnectionFeature); } if ((_featureOverridenFlags & flagIHttpUpgradeFeature) == 0L) { - yield return new KeyValuePair(typeof(global::Microsoft.AspNet.Http.Features.IHttpUpgradeFeature), this as global::Microsoft.AspNet.Http.Features.IHttpUpgradeFeature); + yield return new KeyValuePair(IHttpUpgradeFeatureType, this as global::Microsoft.AspNet.Http.Features.IHttpUpgradeFeature); } if ((_featureOverridenFlags & flagIHttpWebSocketFeature) == 0L) { - yield return new KeyValuePair(typeof(global::Microsoft.AspNet.Http.Features.IHttpWebSocketFeature), this as global::Microsoft.AspNet.Http.Features.IHttpWebSocketFeature); + yield return new KeyValuePair(IHttpWebSocketFeatureType, this as global::Microsoft.AspNet.Http.Features.IHttpWebSocketFeature); } if ((_featureOverridenFlags & flagISessionFeature) == 0L) { - yield return new KeyValuePair(typeof(global::Microsoft.AspNet.Http.Features.ISessionFeature), this as global::Microsoft.AspNet.Http.Features.ISessionFeature); + yield return new KeyValuePair(ISessionFeatureType, this as global::Microsoft.AspNet.Http.Features.ISessionFeature); } if (MaybeExtra != null) { diff --git a/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/FrameFeatureCollection.cs b/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/FrameFeatureCollection.cs index a2ae871972..7206ba8b4e 100644 --- a/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/FrameFeatureCollection.cs +++ b/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/FrameFeatureCollection.cs @@ -118,7 +118,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http {{{Each(commonFeatures, feature => $@" if ((_featureOverridenFlags & flag{feature.Name}) == 0L) {{ - yield return new KeyValuePair(typeof(global::{feature.FullName}), this as global::{feature.FullName}); + yield return new KeyValuePair({feature.Name}Type, this as global::{feature.FullName}); }}")} if (MaybeExtra != null) {{ From e107c47913dc7b264faa793eed021fc085c66cc3 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Sat, 3 Oct 2015 11:10:25 -0400 Subject: [PATCH 0328/1662] Add comment explanation --- src/Microsoft.AspNet.Server.Kestrel/Http/Frame.Generated.cs | 4 ++++ .../FrameFeatureCollection.cs | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.Generated.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.Generated.cs index 89892a9052..452c7cff40 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.Generated.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.Generated.cs @@ -196,6 +196,10 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { Extra[key] = feature; + // Altering only an individual bit of the long + // so need to make sure other concurrent changes are not overridden + // in a lock-free manner + long currentFeatureFlags; long updatedFeatureFlags; do diff --git a/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/FrameFeatureCollection.cs b/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/FrameFeatureCollection.cs index 7206ba8b4e..b22934c34a 100644 --- a/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/FrameFeatureCollection.cs +++ b/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/FrameFeatureCollection.cs @@ -93,6 +93,10 @@ namespace Microsoft.AspNet.Server.Kestrel.Http {{ Extra[key] = feature; + // Altering only an individual bit of the long + // so need to make sure other concurrent changes are not overridden + // in a lock-free manner + long currentFeatureFlags; long updatedFeatureFlags; do From 47973541b58b78e548561fec8b0038d9c82e575a Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Sat, 3 Oct 2015 12:04:26 -0400 Subject: [PATCH 0329/1662] Remove redundant cast --- .../Http/Frame.Generated.cs | 32 +++++++++---------- .../FrameFeatureCollection.cs | 2 +- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.Generated.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.Generated.cs index 452c7cff40..795441558b 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.Generated.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.Generated.cs @@ -55,7 +55,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { if ((_featureOverridenFlags & flagIHttpRequestFeature) == 0L) { - return this as global::Microsoft.AspNet.Http.Features.IHttpRequestFeature; + return this; } return SlowFeatureGet(key); } @@ -63,7 +63,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { if ((_featureOverridenFlags & flagIHttpResponseFeature) == 0L) { - return this as global::Microsoft.AspNet.Http.Features.IHttpResponseFeature; + return this; } return SlowFeatureGet(key); } @@ -71,7 +71,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { if ((_featureOverridenFlags & flagIHttpRequestIdentifierFeature) == 0L) { - return this as global::Microsoft.AspNet.Http.Features.IHttpRequestIdentifierFeature; + return this; } return SlowFeatureGet(key); } @@ -79,7 +79,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { if ((_featureOverridenFlags & flagIHttpSendFileFeature) == 0L) { - return this as global::Microsoft.AspNet.Http.Features.IHttpSendFileFeature; + return this; } return SlowFeatureGet(key); } @@ -87,7 +87,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { if ((_featureOverridenFlags & flagIServiceProvidersFeature) == 0L) { - return this as global::Microsoft.AspNet.Http.Features.Internal.IServiceProvidersFeature; + return this; } return SlowFeatureGet(key); } @@ -95,7 +95,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { if ((_featureOverridenFlags & flagIHttpAuthenticationFeature) == 0L) { - return this as global::Microsoft.AspNet.Http.Features.Authentication.IHttpAuthenticationFeature; + return this; } return SlowFeatureGet(key); } @@ -103,7 +103,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { if ((_featureOverridenFlags & flagIHttpRequestLifetimeFeature) == 0L) { - return this as global::Microsoft.AspNet.Http.Features.IHttpRequestLifetimeFeature; + return this; } return SlowFeatureGet(key); } @@ -111,7 +111,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { if ((_featureOverridenFlags & flagIQueryFeature) == 0L) { - return this as global::Microsoft.AspNet.Http.Features.Internal.IQueryFeature; + return this; } return SlowFeatureGet(key); } @@ -119,7 +119,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { if ((_featureOverridenFlags & flagIFormFeature) == 0L) { - return this as global::Microsoft.AspNet.Http.Features.Internal.IFormFeature; + return this; } return SlowFeatureGet(key); } @@ -127,7 +127,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { if ((_featureOverridenFlags & flagIResponseCookiesFeature) == 0L) { - return this as global::Microsoft.AspNet.Http.Features.Internal.IResponseCookiesFeature; + return this; } return SlowFeatureGet(key); } @@ -135,7 +135,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { if ((_featureOverridenFlags & flagIItemsFeature) == 0L) { - return this as global::Microsoft.AspNet.Http.Features.Internal.IItemsFeature; + return this; } return SlowFeatureGet(key); } @@ -143,7 +143,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { if ((_featureOverridenFlags & flagIHttpConnectionFeature) == 0L) { - return this as global::Microsoft.AspNet.Http.Features.IHttpConnectionFeature; + return this; } return SlowFeatureGet(key); } @@ -151,7 +151,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { if ((_featureOverridenFlags & flagITlsConnectionFeature) == 0L) { - return this as global::Microsoft.AspNet.Http.Features.ITlsConnectionFeature; + return this; } return SlowFeatureGet(key); } @@ -159,7 +159,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { if ((_featureOverridenFlags & flagIHttpUpgradeFeature) == 0L) { - return this as global::Microsoft.AspNet.Http.Features.IHttpUpgradeFeature; + return this; } return SlowFeatureGet(key); } @@ -167,7 +167,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { if ((_featureOverridenFlags & flagIHttpWebSocketFeature) == 0L) { - return this as global::Microsoft.AspNet.Http.Features.IHttpWebSocketFeature; + return this; } return SlowFeatureGet(key); } @@ -175,7 +175,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { if ((_featureOverridenFlags & flagISessionFeature) == 0L) { - return this as global::Microsoft.AspNet.Http.Features.ISessionFeature; + return this; } return SlowFeatureGet(key); } diff --git a/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/FrameFeatureCollection.cs b/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/FrameFeatureCollection.cs index b22934c34a..d990287eda 100644 --- a/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/FrameFeatureCollection.cs +++ b/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/FrameFeatureCollection.cs @@ -72,7 +72,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http {{ if ((_featureOverridenFlags & flag{feature.Name}) == 0L) {{ - return this as global::{feature.FullName}; + return this; }} return SlowFeatureGet(key); }}")} From 6b0fa776ca56e0efe5620a3afce9a2d8aee6663e Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Sun, 4 Oct 2015 08:32:17 -0400 Subject: [PATCH 0330/1662] More comment clarity --- src/Microsoft.AspNet.Server.Kestrel/Http/Frame.Generated.cs | 4 ++-- .../FrameFeatureCollection.cs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.Generated.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.Generated.cs index 795441558b..bf01e5c9d2 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.Generated.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.Generated.cs @@ -197,8 +197,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http Extra[key] = feature; // Altering only an individual bit of the long - // so need to make sure other concurrent changes are not overridden - // in a lock-free manner + // so need to make sure other concurrent bit changes are not overridden + // in an atomic yet lock-free manner long currentFeatureFlags; long updatedFeatureFlags; diff --git a/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/FrameFeatureCollection.cs b/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/FrameFeatureCollection.cs index d990287eda..95b0539be6 100644 --- a/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/FrameFeatureCollection.cs +++ b/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/FrameFeatureCollection.cs @@ -94,8 +94,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http Extra[key] = feature; // Altering only an individual bit of the long - // so need to make sure other concurrent changes are not overridden - // in a lock-free manner + // so need to make sure other concurrent bit changes are not overridden + // in an atomic yet lock-free manner long currentFeatureFlags; long updatedFeatureFlags; From 71fc2bf2e59d4cb052aaae2ccbf6b0f3acf17482 Mon Sep 17 00:00:00 2001 From: Louis DeJardin Date: Fri, 2 Oct 2015 16:09:46 -0700 Subject: [PATCH 0331/1662] Rough implementation of feature collection optimization --- src/Microsoft.AspNet.Server.Kestrel/KestrelEngine.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Microsoft.AspNet.Server.Kestrel/KestrelEngine.cs b/src/Microsoft.AspNet.Server.Kestrel/KestrelEngine.cs index dec15232f7..357bc78e7b 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/KestrelEngine.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/KestrelEngine.cs @@ -11,6 +11,7 @@ using Microsoft.AspNet.Server.Kestrel.Infrastructure; using Microsoft.AspNet.Server.Kestrel.Networking; using Microsoft.Dnx.Runtime; using Microsoft.Extensions.Logging; +using Microsoft.Framework.Logging; namespace Microsoft.AspNet.Server.Kestrel { From dc0eb679aea9fde763452c086909f33f844ec229 Mon Sep 17 00:00:00 2001 From: Louis DeJardin Date: Tue, 6 Oct 2015 12:52:12 -0700 Subject: [PATCH 0332/1662] Updating unit tests for Frame IFeatureCollection update --- samples/SampleApp/Startup.cs | 1 + .../KestrelEngine.cs | 1 - .../ChunkedResponseTests.cs | 32 ++++---- .../ConnectionFilterTests.cs | 11 ++- .../EngineTests.cs | 78 +++++++++++-------- .../HttpsConnectionFilterTests.cs | 11 ++- .../TestServer.cs | 9 ++- 7 files changed, 84 insertions(+), 59 deletions(-) diff --git a/samples/SampleApp/Startup.cs b/samples/SampleApp/Startup.cs index 61840db407..5453372842 100644 --- a/samples/SampleApp/Startup.cs +++ b/samples/SampleApp/Startup.cs @@ -6,6 +6,7 @@ using Microsoft.AspNet.Builder; using Microsoft.AspNet.Http; using Microsoft.Extensions.Logging; using Microsoft.Dnx.Runtime; +using Microsoft.AspNet.Server.Kestrel; #if DNX451 using System.IO; diff --git a/src/Microsoft.AspNet.Server.Kestrel/KestrelEngine.cs b/src/Microsoft.AspNet.Server.Kestrel/KestrelEngine.cs index 357bc78e7b..dec15232f7 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/KestrelEngine.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/KestrelEngine.cs @@ -11,7 +11,6 @@ using Microsoft.AspNet.Server.Kestrel.Infrastructure; using Microsoft.AspNet.Server.Kestrel.Networking; using Microsoft.Dnx.Runtime; using Microsoft.Extensions.Logging; -using Microsoft.Framework.Logging; namespace Microsoft.AspNet.Server.Kestrel { diff --git a/test/Microsoft.AspNet.Server.KestrelTests/ChunkedResponseTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/ChunkedResponseTests.cs index f7e4898cad..4c9f926600 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/ChunkedResponseTests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/ChunkedResponseTests.cs @@ -1,6 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using Microsoft.AspNet.Http.Features; using System; using System.Text; using System.Threading.Tasks; @@ -15,9 +16,10 @@ namespace Microsoft.AspNet.Server.KestrelTests { using (var server = new TestServer(async frame => { - frame.ResponseHeaders.Clear(); - await frame.ResponseBody.WriteAsync(Encoding.ASCII.GetBytes("Hello "), 0, 6); - await frame.ResponseBody.WriteAsync(Encoding.ASCII.GetBytes("World!"), 0, 6); + var response = frame.Get(); + response.Headers.Clear(); + await response.Body.WriteAsync(Encoding.ASCII.GetBytes("Hello "), 0, 6); + await response.Body.WriteAsync(Encoding.ASCII.GetBytes("World!"), 0, 6); })) { using (var connection = new TestConnection()) @@ -46,10 +48,11 @@ namespace Microsoft.AspNet.Server.KestrelTests { using (var server = new TestServer(async frame => { - frame.ResponseHeaders.Clear(); - await frame.ResponseBody.WriteAsync(Encoding.ASCII.GetBytes("Hello "), 0, 6); - await frame.ResponseBody.WriteAsync(new byte[0], 0, 0); - await frame.ResponseBody.WriteAsync(Encoding.ASCII.GetBytes("World!"), 0, 6); + var response = frame.Get(); + response.Headers.Clear(); + await response.Body.WriteAsync(Encoding.ASCII.GetBytes("Hello "), 0, 6); + await response.Body.WriteAsync(new byte[0], 0, 0); + await response.Body.WriteAsync(Encoding.ASCII.GetBytes("World!"), 0, 6); })) { using (var connection = new TestConnection()) @@ -78,8 +81,9 @@ namespace Microsoft.AspNet.Server.KestrelTests { using (var server = new TestServer(async frame => { - frame.ResponseHeaders.Clear(); - await frame.ResponseBody.WriteAsync(new byte[0], 0, 0); + var response = frame.Get(); + response.Headers.Clear(); + await response.Body.WriteAsync(new byte[0], 0, 0); })) { using (var connection = new TestConnection()) @@ -104,8 +108,9 @@ namespace Microsoft.AspNet.Server.KestrelTests { using (var server = new TestServer(async frame => { - frame.ResponseHeaders.Clear(); - await frame.ResponseBody.WriteAsync(Encoding.ASCII.GetBytes("Hello World!"), 0, 12); + var response = frame.Get(); + response.Headers.Clear(); + await response.Body.WriteAsync(Encoding.ASCII.GetBytes("Hello World!"), 0, 12); throw new Exception(); })) { @@ -133,8 +138,9 @@ namespace Microsoft.AspNet.Server.KestrelTests { using (var server = new TestServer(async frame => { - frame.ResponseHeaders.Clear(); - await frame.ResponseBody.WriteAsync(new byte[0], 0, 0); + var response = frame.Get(); + response.Headers.Clear(); + await response.Body.WriteAsync(new byte[0], 0, 0); throw new Exception(); })) { diff --git a/test/Microsoft.AspNet.Server.KestrelTests/ConnectionFilterTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/ConnectionFilterTests.cs index 20c5b8fc1b..d184cda6d2 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/ConnectionFilterTests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/ConnectionFilterTests.cs @@ -6,23 +6,26 @@ using System.Threading.Tasks; using Microsoft.AspNet.Server.Kestrel.Filter; using Microsoft.AspNet.Server.Kestrel.Http; using Xunit; +using Microsoft.AspNet.Http.Features; namespace Microsoft.AspNet.Server.KestrelTests { public class ConnectionFilterTests { - private async Task App(Frame frame) + private async Task App(IFeatureCollection frame) { - frame.ResponseHeaders.Clear(); + var request = frame.Get(); + var response = frame.Get(); + response.Headers.Clear(); while (true) { var buffer = new byte[8192]; - var count = await frame.RequestBody.ReadAsync(buffer, 0, buffer.Length); + var count = await request.Body.ReadAsync(buffer, 0, buffer.Length); if (count == 0) { break; } - await frame.ResponseBody.WriteAsync(buffer, 0, count); + await response.Body.WriteAsync(buffer, 0, count); } } diff --git a/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs index e2039d739e..4a74eb84dd 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs @@ -13,6 +13,7 @@ using Microsoft.AspNet.Server.Kestrel.Http; using Microsoft.Dnx.Runtime; using Microsoft.Dnx.Runtime.Infrastructure; using Xunit; +using Microsoft.AspNet.Http.Features; namespace Microsoft.AspNet.Server.KestrelTests { @@ -40,18 +41,20 @@ namespace Microsoft.AspNet.Server.KestrelTests } } - private async Task App(Frame frame) + private async Task App(IFeatureCollection frame) { - frame.ResponseHeaders.Clear(); + var request = frame.Get(); + var response = frame.Get(); + response.Headers.Clear(); while (true) { var buffer = new byte[8192]; - var count = await frame.RequestBody.ReadAsync(buffer, 0, buffer.Length); + var count = await request.Body.ReadAsync(buffer, 0, buffer.Length); if (count == 0) { break; } - await frame.ResponseBody.WriteAsync(buffer, 0, count); + await response.Body.WriteAsync(buffer, 0, count); } } @@ -78,20 +81,22 @@ namespace Microsoft.AspNet.Server.KestrelTests } } - private async Task AppChunked(Frame frame) + private async Task AppChunked(IFeatureCollection frame) { + var request = frame.Get(); + var response = frame.Get(); var data = new MemoryStream(); - await frame.RequestBody.CopyToAsync(data); + await request.Body.CopyToAsync(data); var bytes = data.ToArray(); - frame.ResponseHeaders.Clear(); - frame.ResponseHeaders["Content-Length"] = new[] { bytes.Length.ToString() }; - await frame.ResponseBody.WriteAsync(bytes, 0, bytes.Length); + response.Headers.Clear(); + response.Headers["Content-Length"] = bytes.Length.ToString(); + await response.Body.WriteAsync(bytes, 0, bytes.Length); } - private Task EmptyApp(Frame frame) + private Task EmptyApp(IFeatureCollection frame) { - frame.ResponseHeaders.Clear(); + frame.Get().Headers.Clear(); return Task.FromResult(null); } @@ -494,12 +499,14 @@ namespace Microsoft.AspNet.Server.KestrelTests { using (var server = new TestServer(async frame => { - frame.ResponseHeaders.Clear(); + var request = frame.Get(); + var response = frame.Get(); + response.Headers.Clear(); - using (var reader = new StreamReader(frame.RequestBody, Encoding.ASCII)) + using (var reader = new StreamReader(request.Body, Encoding.ASCII)) { var statusString = await reader.ReadLineAsync(); - frame.StatusCode = int.Parse(statusString); + response.StatusCode = int.Parse(statusString); } }, testContext)) { @@ -547,15 +554,16 @@ namespace Microsoft.AspNet.Server.KestrelTests using (var server = new TestServer(frame => { - frame.OnStarting(_ => + var response = frame.Get(); + response.OnStarting(_ => { onStartingCalled = true; return Task.FromResult(null); }, null); // Anything added to the ResponseHeaders dictionary is ignored - frame.ResponseHeaders.Clear(); - frame.ResponseHeaders["Content-Length"] = new[] { "11" }; + response.Headers.Clear(); + response.Headers["Content-Length"] = "11"; throw new Exception(); }, testContext)) { @@ -599,15 +607,16 @@ namespace Microsoft.AspNet.Server.KestrelTests using (var server = new TestServer(async frame => { - frame.OnStarting(_ => + var response = frame.Get(); + response.OnStarting(_ => { onStartingCalled = true; return Task.FromResult(null); }, null); - frame.ResponseHeaders.Clear(); - frame.ResponseHeaders["Content-Length"] = new[] { "11" }; - await frame.ResponseBody.WriteAsync(Encoding.ASCII.GetBytes("Hello World"), 0, 11); + response.Headers.Clear(); + response.Headers["Content-Length"] = new[] { "11" }; + await response.Body.WriteAsync(Encoding.ASCII.GetBytes("Hello World"), 0, 11); throw new Exception(); }, testContext)) { @@ -636,15 +645,16 @@ namespace Microsoft.AspNet.Server.KestrelTests using (var server = new TestServer(async frame => { - frame.OnStarting(_ => + var response = frame.Get(); + response.OnStarting(_ => { onStartingCalled = true; return Task.FromResult(null); }, null); - frame.ResponseHeaders.Clear(); - frame.ResponseHeaders["Content-Length"] = new[] { "11" }; - await frame.ResponseBody.WriteAsync(Encoding.ASCII.GetBytes("Hello"), 0, 5); + response.Headers.Clear(); + response.Headers["Content-Length"] = new[] { "11" }; + await response.Body.WriteAsync(Encoding.ASCII.GetBytes("Hello"), 0, 5); throw new Exception(); }, testContext)) { @@ -740,13 +750,14 @@ namespace Microsoft.AspNet.Server.KestrelTests { using (var server = new TestServer(frame => { - frame.OnStarting(_ => + var response = frame.Get(); + response.OnStarting(_ => { throw new Exception(); }, null); - frame.ResponseHeaders.Clear(); - frame.ResponseHeaders["Content-Length"] = new[] { "11" }; + response.Headers.Clear(); + response.Headers["Content-Length"] = new[] { "11" }; // If we write to the response stream, we will not get a 500. @@ -791,21 +802,22 @@ namespace Microsoft.AspNet.Server.KestrelTests { var onStartingException = new Exception(); - frame.OnStarting(_ => + var response = frame.Get(); + response.OnStarting(_ => { throw onStartingException; }, null); - frame.ResponseHeaders.Clear(); - frame.ResponseHeaders["Content-Length"] = new[] { "11" }; + response.Headers.Clear(); + response.Headers["Content-Length"] = new[] { "11" }; var writeException = await Assert.ThrowsAsync(async () => - await frame.ResponseBody.WriteAsync(Encoding.ASCII.GetBytes("Hello World"), 0, 11)); + await response.Body.WriteAsync(Encoding.ASCII.GetBytes("Hello World"), 0, 11)); Assert.Same(onStartingException, writeException); // The second write should succeed since the OnStarting callback will not be called again - await frame.ResponseBody.WriteAsync(Encoding.ASCII.GetBytes("Exception!!"), 0, 11); + await response.Body.WriteAsync(Encoding.ASCII.GetBytes("Exception!!"), 0, 11); }, testContext)) { using (var connection = new TestConnection()) diff --git a/test/Microsoft.AspNet.Server.KestrelTests/HttpsConnectionFilterTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/HttpsConnectionFilterTests.cs index 48167e7e68..143d802713 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/HttpsConnectionFilterTests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/HttpsConnectionFilterTests.cs @@ -13,23 +13,26 @@ using Microsoft.AspNet.Server.Kestrel.Http; using Microsoft.AspNet.Server.Kestrel.Https; using Microsoft.AspNet.Testing.xunit; using Xunit; +using Microsoft.AspNet.Http.Features; namespace Microsoft.AspNet.Server.KestrelTests { public class HttpsConnectionFilterTests { - private async Task App(Frame frame) + private async Task App(IFeatureCollection frame) { - frame.ResponseHeaders.Clear(); + var request = frame.Get(); + var response = frame.Get(); + response.Headers.Clear(); while (true) { var buffer = new byte[8192]; - var count = await frame.RequestBody.ReadAsync(buffer, 0, buffer.Length); + var count = await request.Body.ReadAsync(buffer, 0, buffer.Length); if (count == 0) { break; } - await frame.ResponseBody.WriteAsync(buffer, 0, count); + await response.Body.WriteAsync(buffer, 0, count); } } diff --git a/test/Microsoft.AspNet.Server.KestrelTests/TestServer.cs b/test/Microsoft.AspNet.Server.KestrelTests/TestServer.cs index 4624dc1e9c..d47238341d 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/TestServer.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/TestServer.cs @@ -7,6 +7,7 @@ using Microsoft.AspNet.Server.Kestrel; using Microsoft.AspNet.Server.Kestrel.Http; using Microsoft.Dnx.Runtime; using Microsoft.Dnx.Runtime.Infrastructure; +using Microsoft.AspNet.Http.Features; namespace Microsoft.AspNet.Server.KestrelTests { @@ -18,16 +19,16 @@ namespace Microsoft.AspNet.Server.KestrelTests private KestrelEngine _engine; private IDisposable _server; - public TestServer(Func app) + public TestServer(Func app) : this(app, new TestServiceContext()) { } - public TestServer(Func app, ServiceContext context) + public TestServer(Func app, ServiceContext context) : this(app, context, "http://localhost:54321/") { } - public TestServer(Func app, ServiceContext context, string serverAddress) + public TestServer(Func app, ServiceContext context, string serverAddress) { Create(app, context, serverAddress); } @@ -54,7 +55,7 @@ namespace Microsoft.AspNet.Server.KestrelTests } } - public void Create(Func app, ServiceContext context, string serverAddress) + public void Create(Func app, ServiceContext context, string serverAddress) { _engine = new KestrelEngine( LibraryManager, From cbc3b4e6f5569bc33dc261044f45d563169ce85b Mon Sep 17 00:00:00 2001 From: Louis DeJardin Date: Tue, 6 Oct 2015 15:03:00 -0700 Subject: [PATCH 0333/1662] PR Feedback * Sorting namespaces * Removing `as` casting for Frame's implemented interfaces --- samples/SampleApp/Startup.cs | 9 ++++----- .../Http/Frame.FeatureCollection.cs | 4 ++++ .../ChunkedResponseTests.cs | 2 +- .../ConnectionFilterTests.cs | 2 +- .../FrameFeatureCollection.cs | 9 +++++++++ 5 files changed, 19 insertions(+), 7 deletions(-) diff --git a/samples/SampleApp/Startup.cs b/samples/SampleApp/Startup.cs index 5453372842..834aadd1d1 100644 --- a/samples/SampleApp/Startup.cs +++ b/samples/SampleApp/Startup.cs @@ -4,9 +4,10 @@ using System; using Microsoft.AspNet.Builder; using Microsoft.AspNet.Http; -using Microsoft.Extensions.Logging; -using Microsoft.Dnx.Runtime; +using Microsoft.AspNet.Http.Features; using Microsoft.AspNet.Server.Kestrel; +using Microsoft.Dnx.Runtime; +using Microsoft.Extensions.Logging; #if DNX451 using System.IO; @@ -20,7 +21,7 @@ namespace SampleApp { public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory, IApplicationEnvironment env) { - var ksi = app.ServerFeatures[typeof(IKestrelServerInformation)] as IKestrelServerInformation; + var ksi = app.ServerFeatures.Get(); //ksi.ThreadCount = 4; loggerFactory.MinimumLevel = LogLevel.Debug; @@ -50,8 +51,6 @@ namespace SampleApp context.Request.Path, context.Request.QueryString); - foreach (var q in context.Request.Query) { } - context.Response.ContentLength = 11; context.Response.ContentType = "text/plain"; await context.Response.WriteAsync("Hello world"); diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.FeatureCollection.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.FeatureCollection.cs index bb9f2928ff..54190bf4c2 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.FeatureCollection.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.FeatureCollection.cs @@ -16,6 +16,10 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { public partial class Frame : IFeatureCollection, IHttpRequestFeature, IHttpResponseFeature, IHttpUpgradeFeature { + // NOTE: When feature interfaces are added to or removed from this Frame class implementation, + // then the list of `implementedFeatures` in the generated code project MUST also be updated. + // See also: tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/FrameFeatureCollection.cs + private string _scheme; private string _pathBase; private int _featureRevision; diff --git a/test/Microsoft.AspNet.Server.KestrelTests/ChunkedResponseTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/ChunkedResponseTests.cs index 4c9f926600..d84bf41df1 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/ChunkedResponseTests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/ChunkedResponseTests.cs @@ -1,10 +1,10 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using Microsoft.AspNet.Http.Features; using System; using System.Text; using System.Threading.Tasks; +using Microsoft.AspNet.Http.Features; using Xunit; namespace Microsoft.AspNet.Server.KestrelTests diff --git a/test/Microsoft.AspNet.Server.KestrelTests/ConnectionFilterTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/ConnectionFilterTests.cs index d184cda6d2..b37d72a6e2 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/ConnectionFilterTests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/ConnectionFilterTests.cs @@ -5,8 +5,8 @@ using System.IO; using System.Threading.Tasks; using Microsoft.AspNet.Server.Kestrel.Filter; using Microsoft.AspNet.Server.Kestrel.Http; -using Xunit; using Microsoft.AspNet.Http.Features; +using Xunit; namespace Microsoft.AspNet.Server.KestrelTests { diff --git a/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/FrameFeatureCollection.cs b/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/FrameFeatureCollection.cs index 95b0539be6..d7025100f7 100644 --- a/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/FrameFeatureCollection.cs +++ b/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/FrameFeatureCollection.cs @@ -45,6 +45,15 @@ namespace Microsoft.AspNet.Server.Kestrel.GeneratedCode typeof(ISessionFeature), }; + // NOTE: This list MUST always match the set of feature interfaces implemented by Frame. + // See also: src/Microsoft.AspNet.Server.Kestrel/Http/Frame.FeatureCollection.cs + var implementedFeatures = new[] + { + typeof(IHttpRequestFeature), + typeof(IHttpResponseFeature), + typeof(IHttpUpgradeFeature), + }; + return $@" using System; using System.Collections.Generic; From 56893df7f9534eb80085d3eeffc31bd3d532f87a Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Wed, 7 Oct 2015 00:50:03 -0400 Subject: [PATCH 0334/1662] Don't iterate overriden features twice --- .../Http/Frame.FeatureCollection.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.FeatureCollection.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.FeatureCollection.cs index 54190bf4c2..b4828a7982 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.FeatureCollection.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.FeatureCollection.cs @@ -31,7 +31,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { FastReset(); MaybeExtra?.Clear(); - Interlocked.Increment(ref _featureRevision); + _featureRevision++; } string IHttpRequestFeature.Protocol From 3c20053d9a347aab5f75b84b81c9555cc5f3b7db Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Wed, 7 Oct 2015 01:28:35 -0400 Subject: [PATCH 0335/1662] Don used cached typeof for tests --- .../Http/Frame.Generated.cs | 29 ++++++++++++------- .../FrameFeatureCollection.cs | 21 +++++++++++--- 2 files changed, 35 insertions(+), 15 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.Generated.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.Generated.cs index bf01e5c9d2..57cf1c411a 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.Generated.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.Generated.cs @@ -6,7 +6,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { public partial class Frame { - private const long flagIHttpRequestFeature = 1; private const long flagIHttpResponseFeature = 2; private const long flagIHttpRequestIdentifierFeature = 4; @@ -24,7 +23,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Http private const long flagIHttpWebSocketFeature = 16384; private const long flagISessionFeature = 32768; - private static readonly Type IHttpRequestFeatureType = typeof(global::Microsoft.AspNet.Http.Features.IHttpRequestFeature); private static readonly Type IHttpResponseFeatureType = typeof(global::Microsoft.AspNet.Http.Features.IHttpResponseFeature); private static readonly Type IHttpRequestIdentifierFeatureType = typeof(global::Microsoft.AspNet.Http.Features.IHttpRequestIdentifierFeature); @@ -41,6 +39,15 @@ namespace Microsoft.AspNet.Server.Kestrel.Http private static readonly Type IHttpUpgradeFeatureType = typeof(global::Microsoft.AspNet.Http.Features.IHttpUpgradeFeature); private static readonly Type IHttpWebSocketFeatureType = typeof(global::Microsoft.AspNet.Http.Features.IHttpWebSocketFeature); private static readonly Type ISessionFeatureType = typeof(global::Microsoft.AspNet.Http.Features.ISessionFeature); + private static readonly Type IHttpSendFileFeatureType = typeof(global::Microsoft.AspNet.Http.Features.IHttpSendFileFeature); + + private object _currentIHttpRequestIdentifierFeature; + private object _currentIServiceProvidersFeature; + private object _currentIHttpRequestLifetimeFeature; + private object _currentIHttpConnectionFeature; + private object _currentIHttpAuthenticationFeature; + private object _currentIQueryFeature; + private object _currentIFormFeature; private long _featureOverridenFlags = 0L; @@ -51,7 +58,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http private object FastFeatureGet(Type key) { - if (key == IHttpRequestFeatureType) + if (key == typeof(global::Microsoft.AspNet.Http.Features.IHttpRequestFeature)) { if ((_featureOverridenFlags & flagIHttpRequestFeature) == 0L) { @@ -59,7 +66,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } return SlowFeatureGet(key); } - if (key == IHttpResponseFeatureType) + if (key == typeof(global::Microsoft.AspNet.Http.Features.IHttpResponseFeature)) { if ((_featureOverridenFlags & flagIHttpResponseFeature) == 0L) { @@ -83,7 +90,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } return SlowFeatureGet(key); } - if (key == IServiceProvidersFeatureType) + if (key == typeof(global::Microsoft.AspNet.Http.Features.Internal.IServiceProvidersFeature)) { if ((_featureOverridenFlags & flagIServiceProvidersFeature) == 0L) { @@ -99,7 +106,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } return SlowFeatureGet(key); } - if (key == IHttpRequestLifetimeFeatureType) + if (key == typeof(global::Microsoft.AspNet.Http.Features.IHttpRequestLifetimeFeature)) { if ((_featureOverridenFlags & flagIHttpRequestLifetimeFeature) == 0L) { @@ -139,7 +146,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } return SlowFeatureGet(key); } - if (key == IHttpConnectionFeatureType) + if (key == typeof(global::Microsoft.AspNet.Http.Features.IHttpConnectionFeature)) { if ((_featureOverridenFlags & flagIHttpConnectionFeature) == 0L) { @@ -218,7 +225,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http FastFeatureSetInner(flagIHttpRequestFeature, key, feature); return; } - if (key == IHttpResponseFeatureType) + if (key == typeof(global::Microsoft.AspNet.Http.Features.IHttpResponseFeature)) { FastFeatureSetInner(flagIHttpResponseFeature, key, feature); return; @@ -233,7 +240,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http FastFeatureSetInner(flagIHttpSendFileFeature, key, feature); return; } - if (key == IServiceProvidersFeatureType) + if (key == typeof(global::Microsoft.AspNet.Http.Features.Internal.IServiceProvidersFeature)) { FastFeatureSetInner(flagIServiceProvidersFeature, key, feature); return; @@ -243,7 +250,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http FastFeatureSetInner(flagIHttpAuthenticationFeature, key, feature); return; } - if (key == IHttpRequestLifetimeFeatureType) + if (key == typeof(global::Microsoft.AspNet.Http.Features.IHttpRequestLifetimeFeature)) { FastFeatureSetInner(flagIHttpRequestLifetimeFeature, key, feature); return; @@ -268,7 +275,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http FastFeatureSetInner(flagIItemsFeature, key, feature); return; } - if (key == IHttpConnectionFeatureType) + if (key == typeof(global::Microsoft.AspNet.Http.Features.IHttpConnectionFeature)) { FastFeatureSetInner(flagIHttpConnectionFeature, key, feature); return; diff --git a/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/FrameFeatureCollection.cs b/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/FrameFeatureCollection.cs index d7025100f7..ff7e2b46f4 100644 --- a/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/FrameFeatureCollection.cs +++ b/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/FrameFeatureCollection.cs @@ -85,6 +85,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http }} return SlowFeatureGet(key); }}")} + {Each(cachedFeatures, feature => $@" + if (key == typeof(global::{feature.FullName})) + {{ + return _current{feature.Name}; + }}")} return SlowFeatureGet(key); }} @@ -118,13 +123,21 @@ namespace Microsoft.AspNet.Server.Kestrel.Http }} private void FastFeatureSet(Type key, object feature) - {{{Each(commonFeatures, feature => $@" - if (key == {feature.Name}Type) + {{ + _featureRevision++; + {Each(implementedFeatures, feature => $@" + if (key == typeof(global::{feature.FullName})) {{ FastFeatureSetInner(flag{feature.Name}, key, feature); return; - }}")} - Extra[key] = feature; + }}")}; + {Each(cachedFeatures, feature => $@" + if (key == typeof(global::{feature.FullName})) + {{ + _current{feature.Name} = feature; + return; + }}")}; + SetExtra(key, feature); }} private IEnumerable> FastEnumerable() From 8f41e47ecaf87a57b4d84adfccd76764c4d5b4c9 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Thu, 8 Oct 2015 00:05:27 -0400 Subject: [PATCH 0336/1662] Remove bitfield for locally implemented interface items Only generate type statics for cached features --- .../Http/Frame.Generated.cs | 134 +++++++----------- .../FrameFeatureCollection.cs | 44 ++---- 2 files changed, 61 insertions(+), 117 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.Generated.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.Generated.cs index 57cf1c411a..0c0f3d6398 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.Generated.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.Generated.cs @@ -6,23 +6,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { public partial class Frame { - private const long flagIHttpRequestFeature = 1; - private const long flagIHttpResponseFeature = 2; - private const long flagIHttpRequestIdentifierFeature = 4; - private const long flagIHttpSendFileFeature = 8; - private const long flagIServiceProvidersFeature = 16; - private const long flagIHttpAuthenticationFeature = 32; - private const long flagIHttpRequestLifetimeFeature = 64; - private const long flagIQueryFeature = 128; - private const long flagIFormFeature = 256; - private const long flagIResponseCookiesFeature = 512; - private const long flagIItemsFeature = 1024; - private const long flagIHttpConnectionFeature = 2048; - private const long flagITlsConnectionFeature = 4096; - private const long flagIHttpUpgradeFeature = 8192; - private const long flagIHttpWebSocketFeature = 16384; - private const long flagISessionFeature = 32768; - private static readonly Type IHttpRequestFeatureType = typeof(global::Microsoft.AspNet.Http.Features.IHttpRequestFeature); private static readonly Type IHttpResponseFeatureType = typeof(global::Microsoft.AspNet.Http.Features.IHttpResponseFeature); private static readonly Type IHttpRequestIdentifierFeatureType = typeof(global::Microsoft.AspNet.Http.Features.IHttpRequestIdentifierFeature); @@ -40,7 +23,10 @@ namespace Microsoft.AspNet.Server.Kestrel.Http private static readonly Type IHttpWebSocketFeatureType = typeof(global::Microsoft.AspNet.Http.Features.IHttpWebSocketFeature); private static readonly Type ISessionFeatureType = typeof(global::Microsoft.AspNet.Http.Features.ISessionFeature); private static readonly Type IHttpSendFileFeatureType = typeof(global::Microsoft.AspNet.Http.Features.IHttpSendFileFeature); + private static readonly Type IHttpUpgradeFeatureType = typeof(global::Microsoft.AspNet.Http.Features.IHttpUpgradeFeature); + private object _currentIHttpRequestFeature; + private object _currentIHttpResponseFeature; private object _currentIHttpRequestIdentifierFeature; private object _currentIServiceProvidersFeature; private object _currentIHttpRequestLifetimeFeature; @@ -48,41 +34,35 @@ namespace Microsoft.AspNet.Server.Kestrel.Http private object _currentIHttpAuthenticationFeature; private object _currentIQueryFeature; private object _currentIFormFeature; - - private long _featureOverridenFlags = 0L; + private object _currentIHttpUpgradeFeature; private void FastReset() { - _featureOverridenFlags = 0L; + _currentIHttpRequestFeature = this; + _currentIHttpResponseFeature = this; + _currentIHttpUpgradeFeature = this; + + _currentIHttpRequestIdentifierFeature = null; + _currentIServiceProvidersFeature = null; + _currentIHttpRequestLifetimeFeature = null; + _currentIHttpConnectionFeature = null; + _currentIHttpAuthenticationFeature = null; + _currentIQueryFeature = null; + _currentIFormFeature = null; } private object FastFeatureGet(Type key) { if (key == typeof(global::Microsoft.AspNet.Http.Features.IHttpRequestFeature)) { - if ((_featureOverridenFlags & flagIHttpRequestFeature) == 0L) - { - return this; - } - return SlowFeatureGet(key); + + return _currentIHttpRequestFeature; } if (key == typeof(global::Microsoft.AspNet.Http.Features.IHttpResponseFeature)) { - if ((_featureOverridenFlags & flagIHttpResponseFeature) == 0L) - { - return this; - } - return SlowFeatureGet(key); + return _currentIHttpResponseFeature; } - if (key == IHttpRequestIdentifierFeatureType) - { - if ((_featureOverridenFlags & flagIHttpRequestIdentifierFeature) == 0L) - { - return this; - } - return SlowFeatureGet(key); - } - if (key == IHttpSendFileFeatureType) + if (key == typeof(global::Microsoft.AspNet.Http.Features.IHttpRequestIdentifierFeature)) { if ((_featureOverridenFlags & flagIHttpSendFileFeature) == 0L) { @@ -146,7 +126,16 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } return SlowFeatureGet(key); } - if (key == typeof(global::Microsoft.AspNet.Http.Features.IHttpConnectionFeature)) + if (key == typeof(global::Microsoft.AspNet.Http.Features.IHttpUpgradeFeature)) + { + return _currentIHttpUpgradeFeature; + } + return SlowFeatureGet(key); + } + + private object SlowFeatureGet(Type key) + { + if (MaybeExtra == null) { if ((_featureOverridenFlags & flagIHttpConnectionFeature) == 0L) { @@ -189,53 +178,20 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return SlowFeatureGet(key); } - private object SlowFeatureGet(Type key) - { - object feature = null; - if (MaybeExtra?.TryGetValue(key, out feature) ?? false) - { - return feature; - } - return null; - } - - private void FastFeatureSetInner(long flag, Type key, object feature) - { - Extra[key] = feature; - - // Altering only an individual bit of the long - // so need to make sure other concurrent bit changes are not overridden - // in an atomic yet lock-free manner - - long currentFeatureFlags; - long updatedFeatureFlags; - do - { - currentFeatureFlags = _featureOverridenFlags; - updatedFeatureFlags = currentFeatureFlags | flag; - } while (System.Threading.Interlocked.CompareExchange(ref _featureOverridenFlags, updatedFeatureFlags, currentFeatureFlags) != currentFeatureFlags); - - System.Threading.Interlocked.Increment(ref _featureRevision); - } private void FastFeatureSet(Type key, object feature) { if (key == IHttpRequestFeatureType) { - FastFeatureSetInner(flagIHttpRequestFeature, key, feature); + _currentIHttpRequestFeature = feature; return; } if (key == typeof(global::Microsoft.AspNet.Http.Features.IHttpResponseFeature)) { - FastFeatureSetInner(flagIHttpResponseFeature, key, feature); + _currentIHttpResponseFeature = feature; return; } - if (key == IHttpRequestIdentifierFeatureType) - { - FastFeatureSetInner(flagIHttpRequestIdentifierFeature, key, feature); - return; - } - if (key == IHttpSendFileFeatureType) + if (key == typeof(global::Microsoft.AspNet.Http.Features.IHttpRequestIdentifierFeature)) { FastFeatureSetInner(flagIHttpSendFileFeature, key, feature); return; @@ -300,24 +256,25 @@ namespace Microsoft.AspNet.Server.Kestrel.Http FastFeatureSetInner(flagISessionFeature, key, feature); return; } - Extra[key] = feature; + if (key == typeof(global::Microsoft.AspNet.Http.Features.IHttpUpgradeFeature)) + { + _currentIHttpUpgradeFeature = feature; + return; + }; + SetExtra(key, feature); } private IEnumerable> FastEnumerable() { - if ((_featureOverridenFlags & flagIHttpRequestFeature) == 0L) + if (_currentIHttpRequestFeature != null) { - yield return new KeyValuePair(IHttpRequestFeatureType, this as global::Microsoft.AspNet.Http.Features.IHttpRequestFeature); + yield return new KeyValuePair(IHttpRequestFeatureType, _currentIHttpRequestFeature as global::Microsoft.AspNet.Http.Features.IHttpRequestFeature); } - if ((_featureOverridenFlags & flagIHttpResponseFeature) == 0L) + if (_currentIHttpResponseFeature != null) { - yield return new KeyValuePair(IHttpResponseFeatureType, this as global::Microsoft.AspNet.Http.Features.IHttpResponseFeature); + yield return new KeyValuePair(IHttpResponseFeatureType, _currentIHttpResponseFeature as global::Microsoft.AspNet.Http.Features.IHttpResponseFeature); } - if ((_featureOverridenFlags & flagIHttpRequestIdentifierFeature) == 0L) - { - yield return new KeyValuePair(IHttpRequestIdentifierFeatureType, this as global::Microsoft.AspNet.Http.Features.IHttpRequestIdentifierFeature); - } - if ((_featureOverridenFlags & flagIHttpSendFileFeature) == 0L) + if (_currentIHttpRequestIdentifierFeature != null) { yield return new KeyValuePair(IHttpSendFileFeatureType, this as global::Microsoft.AspNet.Http.Features.IHttpSendFileFeature); } @@ -369,6 +326,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { yield return new KeyValuePair(ISessionFeatureType, this as global::Microsoft.AspNet.Http.Features.ISessionFeature); } + if (_currentIHttpUpgradeFeature != null) + { + yield return new KeyValuePair(IHttpUpgradeFeatureType, _currentIHttpUpgradeFeature as global::Microsoft.AspNet.Http.Features.IHttpUpgradeFeature); + } + if (MaybeExtra != null) { foreach(var item in MaybeExtra) diff --git a/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/FrameFeatureCollection.cs b/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/FrameFeatureCollection.cs index ff7e2b46f4..9ee9b3ced8 100644 --- a/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/FrameFeatureCollection.cs +++ b/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/FrameFeatureCollection.cs @@ -54,6 +54,10 @@ namespace Microsoft.AspNet.Server.Kestrel.GeneratedCode typeof(IHttpUpgradeFeature), }; + // Only the always, common and implmented features will have backed objects + // the sometimes, rare and user-defined features will use the MaybeExtra collection + var cachedFeatures = alwaysFeatures.Concat(commonFeatures).Union(implementedFeatures); + return $@" using System; using System.Collections.Generic; @@ -61,31 +65,18 @@ using System.Collections.Generic; namespace Microsoft.AspNet.Server.Kestrel.Http {{ public partial class Frame - {{ - {Each(commonFeatures.Select((feature, index) => new { feature, index }), entry => $@" - private const long flag{entry.feature.Name} = {1 << entry.index};")} - - {Each(commonFeatures, feature => $@" + {{{Each(cachedFeatures, feature => $@" private static readonly Type {feature.Name}Type = typeof(global::{feature.FullName});")} - private long _featureOverridenFlags = 0L; - private void FastReset() - {{ - _featureOverridenFlags = 0L; + {{{Each(implementedFeatures, feature => $@" + _current{feature.Name} = this;")} + {Each(cachedFeatures.Where( f => !implementedFeatures.Contains(f)), feature => $@" + _current{feature.Name} = null;")} }} private object FastFeatureGet(Type key) - {{{Each(commonFeatures, feature => $@" - if (key == {feature.Name}Type) - {{ - if ((_featureOverridenFlags & flag{feature.Name}) == 0L) - {{ - return this; - }} - return SlowFeatureGet(key); - }}")} - {Each(cachedFeatures, feature => $@" + {{{Each(cachedFeatures, feature => $@" if (key == typeof(global::{feature.FullName})) {{ return _current{feature.Name}; @@ -119,18 +110,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Http updatedFeatureFlags = currentFeatureFlags | flag; }} while (System.Threading.Interlocked.CompareExchange(ref _featureOverridenFlags, updatedFeatureFlags, currentFeatureFlags) != currentFeatureFlags); - System.Threading.Interlocked.Increment(ref _featureRevision); - }} - private void FastFeatureSet(Type key, object feature) {{ _featureRevision++; - {Each(implementedFeatures, feature => $@" - if (key == typeof(global::{feature.FullName})) - {{ - FastFeatureSetInner(flag{feature.Name}, key, feature); - return; - }}")}; {Each(cachedFeatures, feature => $@" if (key == typeof(global::{feature.FullName})) {{ @@ -141,10 +123,10 @@ namespace Microsoft.AspNet.Server.Kestrel.Http }} private IEnumerable> FastEnumerable() - {{{Each(commonFeatures, feature => $@" - if ((_featureOverridenFlags & flag{feature.Name}) == 0L) + {{{Each(cachedFeatures, feature => $@" + if (_current{feature.Name} != null) {{ - yield return new KeyValuePair({feature.Name}Type, this as global::{feature.FullName}); + yield return new KeyValuePair({feature.Name}Type, _current{feature.Name} as global::{feature.FullName}); }}")} if (MaybeExtra != null) {{ From ccfeef6353bde4af51c382a90e020f382d5fc26b Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Thu, 8 Oct 2015 14:42:57 -0400 Subject: [PATCH 0337/1662] All features to have backing object --- .../Http/Frame.Generated.cs | 96 +++++++++++++++++++ .../FrameFeatureCollection.cs | 16 ++-- 2 files changed, 103 insertions(+), 9 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.Generated.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.Generated.cs index 0c0f3d6398..dca313f9a7 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.Generated.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.Generated.cs @@ -24,6 +24,12 @@ namespace Microsoft.AspNet.Server.Kestrel.Http private static readonly Type ISessionFeatureType = typeof(global::Microsoft.AspNet.Http.Features.ISessionFeature); private static readonly Type IHttpSendFileFeatureType = typeof(global::Microsoft.AspNet.Http.Features.IHttpSendFileFeature); private static readonly Type IHttpUpgradeFeatureType = typeof(global::Microsoft.AspNet.Http.Features.IHttpUpgradeFeature); + private static readonly Type IResponseCookiesFeatureType = typeof(global::Microsoft.AspNet.Http.Features.Internal.IResponseCookiesFeature); + private static readonly Type IItemsFeatureType = typeof(global::Microsoft.AspNet.Http.Features.Internal.IItemsFeature); + private static readonly Type ITlsConnectionFeatureType = typeof(global::Microsoft.AspNet.Http.Features.ITlsConnectionFeature); + private static readonly Type IHttpWebSocketFeatureType = typeof(global::Microsoft.AspNet.Http.Features.IHttpWebSocketFeature); + private static readonly Type ISessionFeatureType = typeof(global::Microsoft.AspNet.Http.Features.ISessionFeature); + private static readonly Type IHttpSendFileFeatureType = typeof(global::Microsoft.AspNet.Http.Features.IHttpSendFileFeature); private object _currentIHttpRequestFeature; private object _currentIHttpResponseFeature; @@ -35,6 +41,12 @@ namespace Microsoft.AspNet.Server.Kestrel.Http private object _currentIQueryFeature; private object _currentIFormFeature; private object _currentIHttpUpgradeFeature; + private object _currentIResponseCookiesFeature; + private object _currentIItemsFeature; + private object _currentITlsConnectionFeature; + private object _currentIHttpWebSocketFeature; + private object _currentISessionFeature; + private object _currentIHttpSendFileFeature; private void FastReset() { @@ -49,6 +61,12 @@ namespace Microsoft.AspNet.Server.Kestrel.Http _currentIHttpAuthenticationFeature = null; _currentIQueryFeature = null; _currentIFormFeature = null; + _currentIResponseCookiesFeature = null; + _currentIItemsFeature = null; + _currentITlsConnectionFeature = null; + _currentIHttpWebSocketFeature = null; + _currentISessionFeature = null; + _currentIHttpSendFileFeature = null; } private object FastFeatureGet(Type key) @@ -130,6 +148,30 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { return _currentIHttpUpgradeFeature; } + if (key == typeof(global::Microsoft.AspNet.Http.Features.Internal.IResponseCookiesFeature)) + { + return _currentIResponseCookiesFeature; + } + if (key == typeof(global::Microsoft.AspNet.Http.Features.Internal.IItemsFeature)) + { + return _currentIItemsFeature; + } + if (key == typeof(global::Microsoft.AspNet.Http.Features.ITlsConnectionFeature)) + { + return _currentITlsConnectionFeature; + } + if (key == typeof(global::Microsoft.AspNet.Http.Features.IHttpWebSocketFeature)) + { + return _currentIHttpWebSocketFeature; + } + if (key == typeof(global::Microsoft.AspNet.Http.Features.ISessionFeature)) + { + return _currentISessionFeature; + } + if (key == typeof(global::Microsoft.AspNet.Http.Features.IHttpSendFileFeature)) + { + return _currentIHttpSendFileFeature; + } return SlowFeatureGet(key); } @@ -260,6 +302,36 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { _currentIHttpUpgradeFeature = feature; return; + } + if (key == typeof(global::Microsoft.AspNet.Http.Features.Internal.IResponseCookiesFeature)) + { + _currentIResponseCookiesFeature = feature; + return; + } + if (key == typeof(global::Microsoft.AspNet.Http.Features.Internal.IItemsFeature)) + { + _currentIItemsFeature = feature; + return; + } + if (key == typeof(global::Microsoft.AspNet.Http.Features.ITlsConnectionFeature)) + { + _currentITlsConnectionFeature = feature; + return; + } + if (key == typeof(global::Microsoft.AspNet.Http.Features.IHttpWebSocketFeature)) + { + _currentIHttpWebSocketFeature = feature; + return; + } + if (key == typeof(global::Microsoft.AspNet.Http.Features.ISessionFeature)) + { + _currentISessionFeature = feature; + return; + } + if (key == typeof(global::Microsoft.AspNet.Http.Features.IHttpSendFileFeature)) + { + _currentIHttpSendFileFeature = feature; + return; }; SetExtra(key, feature); } @@ -330,6 +402,30 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { yield return new KeyValuePair(IHttpUpgradeFeatureType, _currentIHttpUpgradeFeature as global::Microsoft.AspNet.Http.Features.IHttpUpgradeFeature); } + if (_currentIResponseCookiesFeature != null) + { + yield return new KeyValuePair(IResponseCookiesFeatureType, _currentIResponseCookiesFeature as global::Microsoft.AspNet.Http.Features.Internal.IResponseCookiesFeature); + } + if (_currentIItemsFeature != null) + { + yield return new KeyValuePair(IItemsFeatureType, _currentIItemsFeature as global::Microsoft.AspNet.Http.Features.Internal.IItemsFeature); + } + if (_currentITlsConnectionFeature != null) + { + yield return new KeyValuePair(ITlsConnectionFeatureType, _currentITlsConnectionFeature as global::Microsoft.AspNet.Http.Features.ITlsConnectionFeature); + } + if (_currentIHttpWebSocketFeature != null) + { + yield return new KeyValuePair(IHttpWebSocketFeatureType, _currentIHttpWebSocketFeature as global::Microsoft.AspNet.Http.Features.IHttpWebSocketFeature); + } + if (_currentISessionFeature != null) + { + yield return new KeyValuePair(ISessionFeatureType, _currentISessionFeature as global::Microsoft.AspNet.Http.Features.ISessionFeature); + } + if (_currentIHttpSendFileFeature != null) + { + yield return new KeyValuePair(IHttpSendFileFeatureType, _currentIHttpSendFileFeature as global::Microsoft.AspNet.Http.Features.IHttpSendFileFeature); + } if (MaybeExtra != null) { diff --git a/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/FrameFeatureCollection.cs b/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/FrameFeatureCollection.cs index 9ee9b3ced8..4c45f6802d 100644 --- a/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/FrameFeatureCollection.cs +++ b/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/FrameFeatureCollection.cs @@ -53,10 +53,6 @@ namespace Microsoft.AspNet.Server.Kestrel.GeneratedCode typeof(IHttpResponseFeature), typeof(IHttpUpgradeFeature), }; - - // Only the always, common and implmented features will have backed objects - // the sometimes, rare and user-defined features will use the MaybeExtra collection - var cachedFeatures = alwaysFeatures.Concat(commonFeatures).Union(implementedFeatures); return $@" using System; @@ -65,18 +61,20 @@ using System.Collections.Generic; namespace Microsoft.AspNet.Server.Kestrel.Http {{ public partial class Frame - {{{Each(cachedFeatures, feature => $@" + {{{Each(allFeatures, feature => $@" private static readonly Type {feature.Name}Type = typeof(global::{feature.FullName});")} +{Each(allFeatures, feature => $@" + private object _current{feature.Name};")} private void FastReset() {{{Each(implementedFeatures, feature => $@" _current{feature.Name} = this;")} - {Each(cachedFeatures.Where( f => !implementedFeatures.Contains(f)), feature => $@" + {Each(allFeatures.Where( f => !implementedFeatures.Contains(f)), feature => $@" _current{feature.Name} = null;")} }} private object FastFeatureGet(Type key) - {{{Each(cachedFeatures, feature => $@" + {{{Each(allFeatures, feature => $@" if (key == typeof(global::{feature.FullName})) {{ return _current{feature.Name}; @@ -113,7 +111,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http private void FastFeatureSet(Type key, object feature) {{ _featureRevision++; - {Each(cachedFeatures, feature => $@" + {Each(allFeatures, feature => $@" if (key == typeof(global::{feature.FullName})) {{ _current{feature.Name} = feature; @@ -123,7 +121,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http }} private IEnumerable> FastEnumerable() - {{{Each(cachedFeatures, feature => $@" + {{{Each(allFeatures, feature => $@" if (_current{feature.Name} != null) {{ yield return new KeyValuePair({feature.Name}Type, _current{feature.Name} as global::{feature.FullName}); From 29b0b124eeb065b566b567a1b7451a4cbbc649f8 Mon Sep 17 00:00:00 2001 From: Louis DeJardin Date: Thu, 8 Oct 2015 12:35:20 -0700 Subject: [PATCH 0338/1662] Moving non-changing methods into .cs partial --- .../Http/Frame.FeatureCollection.cs | 38 ++++++++++++++- .../Http/Frame.Generated.cs | 48 +------------------ .../FrameFeatureCollection.cs | 31 ++---------- 3 files changed, 41 insertions(+), 76 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.FeatureCollection.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.FeatureCollection.cs index b4828a7982..a8e0e92a74 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.FeatureCollection.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.FeatureCollection.cs @@ -6,10 +6,8 @@ using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; -using System.Threading; using System.Threading.Tasks; using Microsoft.AspNet.Http.Features; -using Microsoft.AspNet.Server.Kestrel.Http; using Microsoft.Extensions.Primitives; namespace Microsoft.AspNet.Server.Kestrel.Http @@ -34,6 +32,42 @@ namespace Microsoft.AspNet.Server.Kestrel.Http _featureRevision++; } + private object ExtraFeatureGet(Type key) + { + if (MaybeExtra == null) + { + return null; + } + for (var i = 0; i < MaybeExtra.Count; i++) + { + var kv = MaybeExtra[i]; + if (kv.Key == key) + { + return kv.Value; + } + } + return null; + } + + private void ExtraFeatureSet(Type key, object value) + { + if (MaybeExtra == null) + { + MaybeExtra = new List>(2); + } + + for (var i = 0; i < MaybeExtra.Count; i++) + { + if (MaybeExtra[i].Key == key) + { + MaybeExtra[i] = new KeyValuePair(key, value); + return; + } + } + MaybeExtra.Add(new KeyValuePair(key, value)); + } + + string IHttpRequestFeature.Protocol { get diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.Generated.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.Generated.cs index dca313f9a7..3339bb30a8 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.Generated.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.Generated.cs @@ -172,52 +172,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { return _currentIHttpSendFileFeature; } - return SlowFeatureGet(key); - } - private object SlowFeatureGet(Type key) - { - if (MaybeExtra == null) - { - if ((_featureOverridenFlags & flagIHttpConnectionFeature) == 0L) - { - return this; - } - return SlowFeatureGet(key); - } - if (key == ITlsConnectionFeatureType) - { - if ((_featureOverridenFlags & flagITlsConnectionFeature) == 0L) - { - return this; - } - return SlowFeatureGet(key); - } - if (key == IHttpUpgradeFeatureType) - { - if ((_featureOverridenFlags & flagIHttpUpgradeFeature) == 0L) - { - return this; - } - return SlowFeatureGet(key); - } - if (key == IHttpWebSocketFeatureType) - { - if ((_featureOverridenFlags & flagIHttpWebSocketFeature) == 0L) - { - return this; - } - return SlowFeatureGet(key); - } - if (key == ISessionFeatureType) - { - if ((_featureOverridenFlags & flagISessionFeature) == 0L) - { - return this; - } - return SlowFeatureGet(key); - } - return SlowFeatureGet(key); + return ExtraFeatureGet(key); } @@ -333,7 +289,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http _currentIHttpSendFileFeature = feature; return; }; - SetExtra(key, feature); + ExtraFeatureSet(key, feature); } private IEnumerable> FastEnumerable() diff --git a/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/FrameFeatureCollection.cs b/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/FrameFeatureCollection.cs index 4c45f6802d..8e1cba3a5f 100644 --- a/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/FrameFeatureCollection.cs +++ b/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/FrameFeatureCollection.cs @@ -79,35 +79,10 @@ namespace Microsoft.AspNet.Server.Kestrel.Http {{ return _current{feature.Name}; }}")} - return SlowFeatureGet(key); + + return ExtraFeatureGet(key); }} - private object SlowFeatureGet(Type key) - {{ - object feature = null; - if (MaybeExtra?.TryGetValue(key, out feature) ?? false) - {{ - return feature; - }} - return null; - }} - - private void FastFeatureSetInner(long flag, Type key, object feature) - {{ - Extra[key] = feature; - - // Altering only an individual bit of the long - // so need to make sure other concurrent bit changes are not overridden - // in an atomic yet lock-free manner - - long currentFeatureFlags; - long updatedFeatureFlags; - do - {{ - currentFeatureFlags = _featureOverridenFlags; - updatedFeatureFlags = currentFeatureFlags | flag; - }} while (System.Threading.Interlocked.CompareExchange(ref _featureOverridenFlags, updatedFeatureFlags, currentFeatureFlags) != currentFeatureFlags); - private void FastFeatureSet(Type key, object feature) {{ _featureRevision++; @@ -117,7 +92,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http _current{feature.Name} = feature; return; }}")}; - SetExtra(key, feature); + ExtraFeatureSet(key, feature); }} private IEnumerable> FastEnumerable() From 6ae0f5d505f0b641786842cd98e9ae77e012df0b Mon Sep 17 00:00:00 2001 From: Louis DeJardin Date: Fri, 9 Oct 2015 12:08:04 -0700 Subject: [PATCH 0339/1662] PR feedback - code formatting --- src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs index 7e813bfb11..945bd3a105 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs @@ -728,5 +728,5 @@ namespace Microsoft.AspNet.Server.Kestrel.Http statusCode != 205 && statusCode != 304; } - } + } } From daf272163d3593001a95fad6d59cfb3e65e5e2af Mon Sep 17 00:00:00 2001 From: Louis DeJardin Date: Fri, 9 Oct 2015 12:13:15 -0700 Subject: [PATCH 0340/1662] Visual Studio insists NuGet.config MUST have a BOM Adding this commit so the file stops showing up as modified --- NuGet.config | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NuGet.config b/NuGet.config index 297aa0ae6c..0e465ebc1e 100644 --- a/NuGet.config +++ b/NuGet.config @@ -1,4 +1,4 @@ - + From 78177e7082267d40a8c8394dc6249ab4606b4c94 Mon Sep 17 00:00:00 2001 From: Louis DeJardin Date: Fri, 9 Oct 2015 13:26:34 -0700 Subject: [PATCH 0341/1662] Fixing rebase errors --- .../Http/Frame.FeatureCollection.cs | 3 +- .../Http/Frame.Generated.cs | 177 ++++-------------- .../FrameFeatureCollection.cs | 34 +++- 3 files changed, 64 insertions(+), 150 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.FeatureCollection.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.FeatureCollection.cs index a8e0e92a74..0fa8447d8f 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.FeatureCollection.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.FeatureCollection.cs @@ -22,8 +22,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http private string _pathBase; private int _featureRevision; - private Dictionary Extra => MaybeExtra ?? Interlocked.CompareExchange(ref MaybeExtra, new Dictionary(), null); - private Dictionary MaybeExtra; + private List> MaybeExtra; public void ResetFeatureCollection() { diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.Generated.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.Generated.cs index 3339bb30a8..4d336eb9e0 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.Generated.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.Generated.cs @@ -9,20 +9,12 @@ namespace Microsoft.AspNet.Server.Kestrel.Http private static readonly Type IHttpRequestFeatureType = typeof(global::Microsoft.AspNet.Http.Features.IHttpRequestFeature); private static readonly Type IHttpResponseFeatureType = typeof(global::Microsoft.AspNet.Http.Features.IHttpResponseFeature); private static readonly Type IHttpRequestIdentifierFeatureType = typeof(global::Microsoft.AspNet.Http.Features.IHttpRequestIdentifierFeature); - private static readonly Type IHttpSendFileFeatureType = typeof(global::Microsoft.AspNet.Http.Features.IHttpSendFileFeature); private static readonly Type IServiceProvidersFeatureType = typeof(global::Microsoft.AspNet.Http.Features.Internal.IServiceProvidersFeature); - private static readonly Type IHttpAuthenticationFeatureType = typeof(global::Microsoft.AspNet.Http.Features.Authentication.IHttpAuthenticationFeature); private static readonly Type IHttpRequestLifetimeFeatureType = typeof(global::Microsoft.AspNet.Http.Features.IHttpRequestLifetimeFeature); + private static readonly Type IHttpConnectionFeatureType = typeof(global::Microsoft.AspNet.Http.Features.IHttpConnectionFeature); + private static readonly Type IHttpAuthenticationFeatureType = typeof(global::Microsoft.AspNet.Http.Features.Authentication.IHttpAuthenticationFeature); private static readonly Type IQueryFeatureType = typeof(global::Microsoft.AspNet.Http.Features.Internal.IQueryFeature); private static readonly Type IFormFeatureType = typeof(global::Microsoft.AspNet.Http.Features.Internal.IFormFeature); - private static readonly Type IResponseCookiesFeatureType = typeof(global::Microsoft.AspNet.Http.Features.Internal.IResponseCookiesFeature); - private static readonly Type IItemsFeatureType = typeof(global::Microsoft.AspNet.Http.Features.Internal.IItemsFeature); - private static readonly Type IHttpConnectionFeatureType = typeof(global::Microsoft.AspNet.Http.Features.IHttpConnectionFeature); - private static readonly Type ITlsConnectionFeatureType = typeof(global::Microsoft.AspNet.Http.Features.ITlsConnectionFeature); - private static readonly Type IHttpUpgradeFeatureType = typeof(global::Microsoft.AspNet.Http.Features.IHttpUpgradeFeature); - private static readonly Type IHttpWebSocketFeatureType = typeof(global::Microsoft.AspNet.Http.Features.IHttpWebSocketFeature); - private static readonly Type ISessionFeatureType = typeof(global::Microsoft.AspNet.Http.Features.ISessionFeature); - private static readonly Type IHttpSendFileFeatureType = typeof(global::Microsoft.AspNet.Http.Features.IHttpSendFileFeature); private static readonly Type IHttpUpgradeFeatureType = typeof(global::Microsoft.AspNet.Http.Features.IHttpUpgradeFeature); private static readonly Type IResponseCookiesFeatureType = typeof(global::Microsoft.AspNet.Http.Features.Internal.IResponseCookiesFeature); private static readonly Type IItemsFeatureType = typeof(global::Microsoft.AspNet.Http.Features.Internal.IItemsFeature); @@ -73,7 +65,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { if (key == typeof(global::Microsoft.AspNet.Http.Features.IHttpRequestFeature)) { - return _currentIHttpRequestFeature; } if (key == typeof(global::Microsoft.AspNet.Http.Features.IHttpResponseFeature)) @@ -82,67 +73,31 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } if (key == typeof(global::Microsoft.AspNet.Http.Features.IHttpRequestIdentifierFeature)) { - if ((_featureOverridenFlags & flagIHttpSendFileFeature) == 0L) - { - return this; - } - return SlowFeatureGet(key); + return _currentIHttpRequestIdentifierFeature; } if (key == typeof(global::Microsoft.AspNet.Http.Features.Internal.IServiceProvidersFeature)) { - if ((_featureOverridenFlags & flagIServiceProvidersFeature) == 0L) - { - return this; - } - return SlowFeatureGet(key); - } - if (key == IHttpAuthenticationFeatureType) - { - if ((_featureOverridenFlags & flagIHttpAuthenticationFeature) == 0L) - { - return this; - } - return SlowFeatureGet(key); + return _currentIServiceProvidersFeature; } if (key == typeof(global::Microsoft.AspNet.Http.Features.IHttpRequestLifetimeFeature)) { - if ((_featureOverridenFlags & flagIHttpRequestLifetimeFeature) == 0L) - { - return this; - } - return SlowFeatureGet(key); + return _currentIHttpRequestLifetimeFeature; } - if (key == IQueryFeatureType) + if (key == typeof(global::Microsoft.AspNet.Http.Features.IHttpConnectionFeature)) { - if ((_featureOverridenFlags & flagIQueryFeature) == 0L) - { - return this; - } - return SlowFeatureGet(key); + return _currentIHttpConnectionFeature; } - if (key == IFormFeatureType) + if (key == typeof(global::Microsoft.AspNet.Http.Features.Authentication.IHttpAuthenticationFeature)) { - if ((_featureOverridenFlags & flagIFormFeature) == 0L) - { - return this; - } - return SlowFeatureGet(key); + return _currentIHttpAuthenticationFeature; } - if (key == IResponseCookiesFeatureType) + if (key == typeof(global::Microsoft.AspNet.Http.Features.Internal.IQueryFeature)) { - if ((_featureOverridenFlags & flagIResponseCookiesFeature) == 0L) - { - return this; - } - return SlowFeatureGet(key); + return _currentIQueryFeature; } - if (key == IItemsFeatureType) + if (key == typeof(global::Microsoft.AspNet.Http.Features.Internal.IFormFeature)) { - if ((_featureOverridenFlags & flagIItemsFeature) == 0L) - { - return this; - } - return SlowFeatureGet(key); + return _currentIFormFeature; } if (key == typeof(global::Microsoft.AspNet.Http.Features.IHttpUpgradeFeature)) { @@ -172,14 +127,14 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { return _currentIHttpSendFileFeature; } - return ExtraFeatureGet(key); } - private void FastFeatureSet(Type key, object feature) { - if (key == IHttpRequestFeatureType) + _featureRevision++; + + if (key == typeof(global::Microsoft.AspNet.Http.Features.IHttpRequestFeature)) { _currentIHttpRequestFeature = feature; return; @@ -191,67 +146,37 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } if (key == typeof(global::Microsoft.AspNet.Http.Features.IHttpRequestIdentifierFeature)) { - FastFeatureSetInner(flagIHttpSendFileFeature, key, feature); + _currentIHttpRequestIdentifierFeature = feature; return; } if (key == typeof(global::Microsoft.AspNet.Http.Features.Internal.IServiceProvidersFeature)) { - FastFeatureSetInner(flagIServiceProvidersFeature, key, feature); - return; - } - if (key == IHttpAuthenticationFeatureType) - { - FastFeatureSetInner(flagIHttpAuthenticationFeature, key, feature); + _currentIServiceProvidersFeature = feature; return; } if (key == typeof(global::Microsoft.AspNet.Http.Features.IHttpRequestLifetimeFeature)) { - FastFeatureSetInner(flagIHttpRequestLifetimeFeature, key, feature); - return; - } - if (key == IQueryFeatureType) - { - FastFeatureSetInner(flagIQueryFeature, key, feature); - return; - } - if (key == IFormFeatureType) - { - FastFeatureSetInner(flagIFormFeature, key, feature); - return; - } - if (key == IResponseCookiesFeatureType) - { - FastFeatureSetInner(flagIResponseCookiesFeature, key, feature); - return; - } - if (key == IItemsFeatureType) - { - FastFeatureSetInner(flagIItemsFeature, key, feature); + _currentIHttpRequestLifetimeFeature = feature; return; } if (key == typeof(global::Microsoft.AspNet.Http.Features.IHttpConnectionFeature)) { - FastFeatureSetInner(flagIHttpConnectionFeature, key, feature); + _currentIHttpConnectionFeature = feature; return; } - if (key == ITlsConnectionFeatureType) + if (key == typeof(global::Microsoft.AspNet.Http.Features.Authentication.IHttpAuthenticationFeature)) { - FastFeatureSetInner(flagITlsConnectionFeature, key, feature); + _currentIHttpAuthenticationFeature = feature; return; } - if (key == IHttpUpgradeFeatureType) + if (key == typeof(global::Microsoft.AspNet.Http.Features.Internal.IQueryFeature)) { - FastFeatureSetInner(flagIHttpUpgradeFeature, key, feature); + _currentIQueryFeature = feature; return; } - if (key == IHttpWebSocketFeatureType) + if (key == typeof(global::Microsoft.AspNet.Http.Features.Internal.IFormFeature)) { - FastFeatureSetInner(flagIHttpWebSocketFeature, key, feature); - return; - } - if (key == ISessionFeatureType) - { - FastFeatureSetInner(flagISessionFeature, key, feature); + _currentIFormFeature = feature; return; } if (key == typeof(global::Microsoft.AspNet.Http.Features.IHttpUpgradeFeature)) @@ -304,55 +229,31 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } if (_currentIHttpRequestIdentifierFeature != null) { - yield return new KeyValuePair(IHttpSendFileFeatureType, this as global::Microsoft.AspNet.Http.Features.IHttpSendFileFeature); + yield return new KeyValuePair(IHttpRequestIdentifierFeatureType, _currentIHttpRequestIdentifierFeature as global::Microsoft.AspNet.Http.Features.IHttpRequestIdentifierFeature); } - if ((_featureOverridenFlags & flagIServiceProvidersFeature) == 0L) + if (_currentIServiceProvidersFeature != null) { - yield return new KeyValuePair(IServiceProvidersFeatureType, this as global::Microsoft.AspNet.Http.Features.Internal.IServiceProvidersFeature); + yield return new KeyValuePair(IServiceProvidersFeatureType, _currentIServiceProvidersFeature as global::Microsoft.AspNet.Http.Features.Internal.IServiceProvidersFeature); } - if ((_featureOverridenFlags & flagIHttpAuthenticationFeature) == 0L) + if (_currentIHttpRequestLifetimeFeature != null) { - yield return new KeyValuePair(IHttpAuthenticationFeatureType, this as global::Microsoft.AspNet.Http.Features.Authentication.IHttpAuthenticationFeature); + yield return new KeyValuePair(IHttpRequestLifetimeFeatureType, _currentIHttpRequestLifetimeFeature as global::Microsoft.AspNet.Http.Features.IHttpRequestLifetimeFeature); } - if ((_featureOverridenFlags & flagIHttpRequestLifetimeFeature) == 0L) + if (_currentIHttpConnectionFeature != null) { - yield return new KeyValuePair(IHttpRequestLifetimeFeatureType, this as global::Microsoft.AspNet.Http.Features.IHttpRequestLifetimeFeature); + yield return new KeyValuePair(IHttpConnectionFeatureType, _currentIHttpConnectionFeature as global::Microsoft.AspNet.Http.Features.IHttpConnectionFeature); } - if ((_featureOverridenFlags & flagIQueryFeature) == 0L) + if (_currentIHttpAuthenticationFeature != null) { - yield return new KeyValuePair(IQueryFeatureType, this as global::Microsoft.AspNet.Http.Features.Internal.IQueryFeature); + yield return new KeyValuePair(IHttpAuthenticationFeatureType, _currentIHttpAuthenticationFeature as global::Microsoft.AspNet.Http.Features.Authentication.IHttpAuthenticationFeature); } - if ((_featureOverridenFlags & flagIFormFeature) == 0L) + if (_currentIQueryFeature != null) { - yield return new KeyValuePair(IFormFeatureType, this as global::Microsoft.AspNet.Http.Features.Internal.IFormFeature); + yield return new KeyValuePair(IQueryFeatureType, _currentIQueryFeature as global::Microsoft.AspNet.Http.Features.Internal.IQueryFeature); } - if ((_featureOverridenFlags & flagIResponseCookiesFeature) == 0L) + if (_currentIFormFeature != null) { - yield return new KeyValuePair(IResponseCookiesFeatureType, this as global::Microsoft.AspNet.Http.Features.Internal.IResponseCookiesFeature); - } - if ((_featureOverridenFlags & flagIItemsFeature) == 0L) - { - yield return new KeyValuePair(IItemsFeatureType, this as global::Microsoft.AspNet.Http.Features.Internal.IItemsFeature); - } - if ((_featureOverridenFlags & flagIHttpConnectionFeature) == 0L) - { - yield return new KeyValuePair(IHttpConnectionFeatureType, this as global::Microsoft.AspNet.Http.Features.IHttpConnectionFeature); - } - if ((_featureOverridenFlags & flagITlsConnectionFeature) == 0L) - { - yield return new KeyValuePair(ITlsConnectionFeatureType, this as global::Microsoft.AspNet.Http.Features.ITlsConnectionFeature); - } - if ((_featureOverridenFlags & flagIHttpUpgradeFeature) == 0L) - { - yield return new KeyValuePair(IHttpUpgradeFeatureType, this as global::Microsoft.AspNet.Http.Features.IHttpUpgradeFeature); - } - if ((_featureOverridenFlags & flagIHttpWebSocketFeature) == 0L) - { - yield return new KeyValuePair(IHttpWebSocketFeatureType, this as global::Microsoft.AspNet.Http.Features.IHttpWebSocketFeature); - } - if ((_featureOverridenFlags & flagISessionFeature) == 0L) - { - yield return new KeyValuePair(ISessionFeatureType, this as global::Microsoft.AspNet.Http.Features.ISessionFeature); + yield return new KeyValuePair(IFormFeatureType, _currentIFormFeature as global::Microsoft.AspNet.Http.Features.Internal.IFormFeature); } if (_currentIHttpUpgradeFeature != null) { diff --git a/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/FrameFeatureCollection.cs b/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/FrameFeatureCollection.cs index 8e1cba3a5f..f8dcf8d927 100644 --- a/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/FrameFeatureCollection.cs +++ b/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/FrameFeatureCollection.cs @@ -25,26 +25,40 @@ namespace Microsoft.AspNet.Server.Kestrel.GeneratedCode public static string GeneratedFile() { - var commonFeatures = new[] + var alwaysFeatures = new[] { typeof(IHttpRequestFeature), typeof(IHttpResponseFeature), typeof(IHttpRequestIdentifierFeature), - typeof(IHttpSendFileFeature), typeof(IServiceProvidersFeature), - typeof(IHttpAuthenticationFeature), typeof(IHttpRequestLifetimeFeature), + typeof(IHttpConnectionFeature) + }; + + var commonFeatures = new[] + { + typeof(IHttpAuthenticationFeature), typeof(IQueryFeature), - typeof(IFormFeature), + typeof(IFormFeature) + }; + + var sometimesFeatures = new[] + { + typeof(IHttpUpgradeFeature), typeof(IResponseCookiesFeature), typeof(IItemsFeature), - typeof(IHttpConnectionFeature), typeof(ITlsConnectionFeature), - typeof(IHttpUpgradeFeature), typeof(IHttpWebSocketFeature), - typeof(ISessionFeature), + typeof(ISessionFeature) }; + var rareFeatures = new[] + { + typeof(IHttpSendFileFeature) + }; + + var allFeatures = alwaysFeatures.Concat(commonFeatures).Concat(sometimesFeatures).Concat(rareFeatures); + // NOTE: This list MUST always match the set of feature interfaces implemented by Frame. // See also: src/Microsoft.AspNet.Server.Kestrel/Http/Frame.FeatureCollection.cs var implementedFeatures = new[] @@ -53,7 +67,7 @@ namespace Microsoft.AspNet.Server.Kestrel.GeneratedCode typeof(IHttpResponseFeature), typeof(IHttpUpgradeFeature), }; - + return $@" using System; using System.Collections.Generic; @@ -69,7 +83,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http private void FastReset() {{{Each(implementedFeatures, feature => $@" _current{feature.Name} = this;")} - {Each(allFeatures.Where( f => !implementedFeatures.Contains(f)), feature => $@" + {Each(allFeatures.Where(f => !implementedFeatures.Contains(f)), feature => $@" _current{feature.Name} = null;")} }} @@ -79,7 +93,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Http {{ return _current{feature.Name}; }}")} - return ExtraFeatureGet(key); }} @@ -101,6 +114,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http {{ yield return new KeyValuePair({feature.Name}Type, _current{feature.Name} as global::{feature.FullName}); }}")} + if (MaybeExtra != null) {{ foreach(var item in MaybeExtra) From 385c0ab244f10c81d18c46b56fd4f2df43287d2f Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Fri, 9 Oct 2015 15:56:57 -0700 Subject: [PATCH 0342/1662] Make project.json dependencies more consistent and permissive - This prevents warning NU1007 from LibraryManager during the build --- .../project.json | 12 ++++++------ tools/Microsoft.StandardsPolice/project.json | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/tools/Microsoft.AspNet.Server.Kestrel.LibuvCopier/project.json b/tools/Microsoft.AspNet.Server.Kestrel.LibuvCopier/project.json index 469aeac902..3932f4fbc4 100644 --- a/tools/Microsoft.AspNet.Server.Kestrel.LibuvCopier/project.json +++ b/tools/Microsoft.AspNet.Server.Kestrel.LibuvCopier/project.json @@ -18,12 +18,12 @@ "dnx451": { }, "dnxcore50": { "dependencies": { - "Microsoft.CSharp": "4.0.1-beta-23225", - "System.Collections": "4.0.11-beta-23225", - "System.Console": "4.0.0-beta-23225", - "System.Linq": "4.0.1-beta-23225", - "System.Threading": "4.0.11-beta-23225", - "System.IO.FileSystem": "4.0.1-beta-23225" + "Microsoft.CSharp": "4.0.1-beta-*", + "System.Collections": "4.0.11-beta-*", + "System.Console": "4.0.0-beta-*", + "System.Linq": "4.0.1-beta-*", + "System.Threading": "4.0.11-beta-*", + "System.IO.FileSystem": "4.0.1-beta-*" } } } diff --git a/tools/Microsoft.StandardsPolice/project.json b/tools/Microsoft.StandardsPolice/project.json index d279e371a3..0129749b3f 100644 --- a/tools/Microsoft.StandardsPolice/project.json +++ b/tools/Microsoft.StandardsPolice/project.json @@ -4,7 +4,7 @@ "description": "Microsoft.StandardsPolice Class Library", "dependencies": { - "Microsoft.Dnx.Compilation.CSharp.Abstractions": "1.0.0-beta8-*" + "Microsoft.Dnx.Compilation.CSharp.Abstractions": "1.0.0-*" }, "commands": { From a9de028ba395f2c3541be88f5c35e37587a586d4 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Fri, 9 Oct 2015 15:58:14 -0700 Subject: [PATCH 0343/1662] Enable the LargeUpload functional test now that #234 is resolved --- .../RequestTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/RequestTests.cs b/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/RequestTests.cs index 5819fc9738..a9996ecb9a 100644 --- a/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/RequestTests.cs +++ b/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/RequestTests.cs @@ -16,7 +16,7 @@ namespace Microsoft.AspNet.Server.Kestrel.FunctionalTests { public class RequestTests { - [Fact(Skip = "https://github.com/aspnet/KestrelHttpServer/issues/234")] + [Fact] public async Task LargeUpload() { var config = new ConfigurationBuilder() From 3eec43a0c3279d8ba758ee3712b2716538ce7d5f Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Fri, 9 Oct 2015 17:27:33 -0700 Subject: [PATCH 0344/1662] Move static BitCount method to base class - Updated comment to point to a specific commit in corefx - This is more consistent with AppendValue since BitCount doesn't need to be generated --- .../Http/FrameHeaders.Generated.cs | 32 ------------------- .../Http/FrameHeaders.cs | 16 ++++++++++ .../KnownHeaders.cs | 16 ---------- 3 files changed, 16 insertions(+), 48 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameHeaders.Generated.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameHeaders.Generated.cs index 63eb6db9ad..f1e7b7974a 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameHeaders.Generated.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameHeaders.Generated.cs @@ -586,22 +586,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } - private static int BitCount(long value) - { - // see https://github.com/dotnet/corefx/blob/master/src/System.Reflection.Metadata/src/System/Reflection/Internal/Utilities/BitArithmetic.cs - - const ulong Mask01010101 = 0x5555555555555555UL; - const ulong Mask00110011 = 0x3333333333333333UL; - const ulong Mask00001111 = 0x0F0F0F0F0F0F0F0FUL; - const ulong Mask00000001 = 0x0101010101010101UL; - - var v = (ulong)value; - - v = v - ((v >> 1) & Mask01010101); - v = (v & Mask00110011) + ((v >> 2) & Mask00110011); - return (int)(unchecked(((v + (v >> 4)) & Mask00001111) * Mask00000001) >> 56); - } - protected override int GetCountFast() { return BitCount(_bits) + (MaybeUnknown?.Count ?? 0); @@ -5428,22 +5412,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } - private static int BitCount(long value) - { - // see https://github.com/dotnet/corefx/blob/master/src/System.Reflection.Metadata/src/System/Reflection/Internal/Utilities/BitArithmetic.cs - - const ulong Mask01010101 = 0x5555555555555555UL; - const ulong Mask00110011 = 0x3333333333333333UL; - const ulong Mask00001111 = 0x0F0F0F0F0F0F0F0FUL; - const ulong Mask00000001 = 0x0101010101010101UL; - - var v = (ulong)value; - - v = v - ((v >> 1) & Mask01010101); - v = (v & Mask00110011) + ((v >> 2) & Mask00110011); - return (int)(unchecked(((v + (v >> 4)) & Mask00001111) * Mask00000001) >> 56); - } - protected override int GetCountFast() { return BitCount(_bits) + (MaybeUnknown?.Count ?? 0); diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameHeaders.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameHeaders.cs index d188c692f2..18b19c114e 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameHeaders.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameHeaders.cs @@ -45,6 +45,22 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return StringValues.Concat(existing, append); } + protected static int BitCount(long value) + { + // see https://github.com/dotnet/corefx/blob/5965fd3756bc9dd9c89a27621eb10c6931126de2/src/System.Reflection.Metadata/src/System/Reflection/Internal/Utilities/BitArithmetic.cs + + const ulong Mask01010101 = 0x5555555555555555UL; + const ulong Mask00110011 = 0x3333333333333333UL; + const ulong Mask00001111 = 0x0F0F0F0F0F0F0F0FUL; + const ulong Mask00000001 = 0x0101010101010101UL; + + var v = (ulong)value; + + v = v - ((v >> 1) & Mask01010101); + v = (v & Mask00110011) + ((v >> 2) & Mask00110011); + return (int)(unchecked(((v + (v >> 4)) & Mask00001111) * Mask00000001) >> 56); + } + protected virtual int GetCountFast() { throw new NotImplementedException(); } diff --git a/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/KnownHeaders.cs b/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/KnownHeaders.cs index e1d6832675..759d6dacf8 100644 --- a/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/KnownHeaders.cs +++ b/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/KnownHeaders.cs @@ -192,22 +192,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Http }} }} ")} - private static int BitCount(long value) - {{ - // see https://github.com/dotnet/corefx/blob/master/src/System.Reflection.Metadata/src/System/Reflection/Internal/Utilities/BitArithmetic.cs - - const ulong Mask01010101 = 0x5555555555555555UL; - const ulong Mask00110011 = 0x3333333333333333UL; - const ulong Mask00001111 = 0x0F0F0F0F0F0F0F0FUL; - const ulong Mask00000001 = 0x0101010101010101UL; - - var v = (ulong)value; - - v = v - ((v >> 1) & Mask01010101); - v = (v & Mask00110011) + ((v >> 2) & Mask00110011); - return (int)(unchecked(((v + (v >> 4)) & Mask00001111) * Mask00000001) >> 56); - }} - protected override int GetCountFast() {{ return BitCount(_bits) + (MaybeUnknown?.Count ?? 0); From cfe6e22a297581b9479a3485a418b8966aef94b5 Mon Sep 17 00:00:00 2001 From: Chris R Date: Mon, 12 Oct 2015 09:29:34 -0700 Subject: [PATCH 0345/1662] React to IHeaderDictionary changes. --- .../Http/Frame.FeatureCollection.cs | 5 +++-- .../Http/Frame.cs | 7 +++---- .../Http/FrameHeaders.cs | 17 ++++++++++++++++- 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.FeatureCollection.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.FeatureCollection.cs index 0fa8447d8f..293c3facc4 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.FeatureCollection.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.FeatureCollection.cs @@ -7,6 +7,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; using System.Threading.Tasks; +using Microsoft.AspNet.Http; using Microsoft.AspNet.Http.Features; using Microsoft.Extensions.Primitives; @@ -145,7 +146,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } - IDictionary IHttpRequestFeature.Headers + IHeaderDictionary IHttpRequestFeature.Headers { get { @@ -197,7 +198,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } - IDictionary IHttpResponseFeature.Headers + IHeaderDictionary IHttpResponseFeature.Headers { get { diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs index 945bd3a105..f772b32da8 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs @@ -2,14 +2,13 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; -using Microsoft.AspNet.Http.Features; +using Microsoft.AspNet.Http; using Microsoft.AspNet.Server.Kestrel.Infrastructure; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Primitives; @@ -55,13 +54,13 @@ namespace Microsoft.AspNet.Server.Kestrel.Http public string Path { get; set; } public string QueryString { get; set; } public string HttpVersion { get; set; } - public IDictionary RequestHeaders { get; set; } + public IHeaderDictionary RequestHeaders { get; set; } public MessageBody MessageBody { get; set; } public Stream RequestBody { get; set; } public int StatusCode { get; set; } public string ReasonPhrase { get; set; } - public IDictionary ResponseHeaders { get; set; } + public IHeaderDictionary ResponseHeaders { get; set; } public Stream ResponseBody { get; set; } public Stream DuplexStream { get; set; } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameHeaders.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameHeaders.cs index 18b19c114e..beb926447c 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameHeaders.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameHeaders.cs @@ -5,16 +5,31 @@ using System; using System.Collections; using System.Collections.Generic; using System.Linq; +using Microsoft.AspNet.Http; using Microsoft.Extensions.Primitives; namespace Microsoft.AspNet.Server.Kestrel.Http { - public abstract class FrameHeaders : IDictionary + public abstract class FrameHeaders : IHeaderDictionary { protected Dictionary MaybeUnknown; protected Dictionary Unknown => MaybeUnknown ?? (MaybeUnknown = new Dictionary(StringComparer.OrdinalIgnoreCase)); + StringValues IHeaderDictionary.this[string key] + { + get + { + StringValues value; + TryGetValueFast(key, out value); + return value; + } + set + { + SetValueFast(key, value); + } + } + StringValues IDictionary.this[string key] { get From ece4169559dbf85c47c191925fc8b81fd770a9ce Mon Sep 17 00:00:00 2001 From: Doug Bunting Date: Thu, 8 Oct 2015 19:00:52 -0700 Subject: [PATCH 0346/1662] React to aspnet/Universe#290 fix --- build.cmd | 25 +++++++++++++------------ build.sh | 12 +++++++----- 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/build.cmd b/build.cmd index 70d974a61f..84dc87e480 100644 --- a/build.cmd +++ b/build.cmd @@ -18,22 +18,23 @@ md .nuget copy %CACHED_NUGET% .nuget\nuget.exe > nul :restore -IF EXIST packages\KoreBuild goto run +IF EXIST packages\Sake goto getdnx IF %BUILDCMD_KOREBUILD_VERSION%=="" ( - .nuget\nuget.exe install KoreBuild -ExcludeVersion -o packages -nocache -pre + .nuget\nuget.exe install KoreBuild -ExcludeVersion -o packages -nocache -pre ) ELSE ( - .nuget\nuget.exe install KoreBuild -version %BUILDCMD_KOREBUILD_VERSION% -ExcludeVersion -o packages -nocache -pre + .nuget\nuget.exe install KoreBuild -version %BUILDCMD_KOREBUILD_VERSION% -ExcludeVersion -o packages -nocache -pre ) -.nuget\nuget.exe install Sake -ExcludeVersion -Out packages +.nuget\NuGet.exe install Sake -ExcludeVersion -Source https://www.nuget.org/api/v2/ -Out packages -IF "%SKIP_DNX_INSTALL%"=="1" goto run -IF %BUILDCMD_DNX_VERSION%=="" ( - CALL packages\KoreBuild\build\dnvm upgrade -runtime CLR -arch x86 +:getdnx +IF "%SKIP_DNX_INSTALL%"=="" ( + IF "%BUILDCMD_DNX_VERSION%"=="" ( + BUILDCMD_DNX_VERSION=latest + ) + CALL packages\KoreBuild\build\dnvm install %BUILDCMD_DNX_VERSION% -runtime CoreCLR -arch x86 -alias default + CALL packages\KoreBuild\build\dnvm install default -runtime CLR -arch x86 -alias default ) ELSE ( - CALL packages\KoreBuild\build\dnvm install %BUILDCMD_DNX_VERSION% -runtime CLR -arch x86 -alias default + CALL packages\KoreBuild\build\dnvm use default -runtime CLR -arch x86 ) -CALL packages\KoreBuild\build\dnvm install default -runtime CoreCLR -arch x86 -:run -CALL packages\KoreBuild\build\dnvm use default -runtime CLR -arch x86 -packages\Sake\tools\Sake.exe -I packages\KoreBuild\build -f makefile.shade %* \ No newline at end of file +packages\Sake\tools\Sake.exe -I packages\KoreBuild\build -f makefile.shade %* diff --git a/build.sh b/build.sh index 0c66139817..da4e3fcd1c 100755 --- a/build.sh +++ b/build.sh @@ -24,18 +24,20 @@ if test ! -e .nuget; then cp $cachePath .nuget/nuget.exe fi -if test ! -d packages/KoreBuild; then +if test ! -d packages/Sake; then mono .nuget/nuget.exe install KoreBuild -ExcludeVersion -o packages -nocache -pre - mono .nuget/nuget.exe install Sake -ExcludeVersion -Out packages + mono .nuget/nuget.exe install Sake -ExcludeVersion -Source https://www.nuget.org/api/v2/ -Out packages fi if ! type dnvm > /dev/null 2>&1; then source packages/KoreBuild/build/dnvm.sh fi -if ! type dnx > /dev/null 2>&1; then - dnvm upgrade +if ! type dnx > /dev/null 2>&1 || [ -z "$SKIP_DNX_INSTALL" ]; then + dnvm install latest -runtime coreclr -alias default + dnvm install default -runtime mono -alias default +else + dnvm use default -runtime mono fi mono packages/Sake/tools/Sake.exe -I packages/KoreBuild/build -f makefile.shade "$@" - From f62b7e4816e851f8527a0d3e2d7199359164f5d8 Mon Sep 17 00:00:00 2001 From: Doug Bunting Date: Mon, 12 Oct 2015 12:57:00 -0700 Subject: [PATCH 0347/1662] Fix local build break --- build.cmd | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/build.cmd b/build.cmd index 84dc87e480..553e3929a0 100644 --- a/build.cmd +++ b/build.cmd @@ -4,8 +4,8 @@ cd %~dp0 SETLOCAL SET NUGET_VERSION=latest SET CACHED_NUGET=%LocalAppData%\NuGet\nuget.%NUGET_VERSION%.exe -SET BUILDCMD_KOREBUILD_VERSION="" -SET BUILDCMD_DNX_VERSION="" +SET BUILDCMD_KOREBUILD_VERSION= +SET BUILDCMD_DNX_VERSION= IF EXIST %CACHED_NUGET% goto copynuget echo Downloading latest version of NuGet.exe... @@ -19,7 +19,7 @@ copy %CACHED_NUGET% .nuget\nuget.exe > nul :restore IF EXIST packages\Sake goto getdnx -IF %BUILDCMD_KOREBUILD_VERSION%=="" ( +IF "%BUILDCMD_KOREBUILD_VERSION%"=="" ( .nuget\nuget.exe install KoreBuild -ExcludeVersion -o packages -nocache -pre ) ELSE ( .nuget\nuget.exe install KoreBuild -version %BUILDCMD_KOREBUILD_VERSION% -ExcludeVersion -o packages -nocache -pre @@ -27,10 +27,10 @@ IF %BUILDCMD_KOREBUILD_VERSION%=="" ( .nuget\NuGet.exe install Sake -ExcludeVersion -Source https://www.nuget.org/api/v2/ -Out packages :getdnx +IF "%BUILDCMD_DNX_VERSION%"=="" ( + SET BUILDCMD_DNX_VERSION=latest +) IF "%SKIP_DNX_INSTALL%"=="" ( - IF "%BUILDCMD_DNX_VERSION%"=="" ( - BUILDCMD_DNX_VERSION=latest - ) CALL packages\KoreBuild\build\dnvm install %BUILDCMD_DNX_VERSION% -runtime CoreCLR -arch x86 -alias default CALL packages\KoreBuild\build\dnvm install default -runtime CLR -arch x86 -alias default ) ELSE ( From dcdf778bcc4a7d3a4377e8fa7de2826cbc188e96 Mon Sep 17 00:00:00 2001 From: Kiran Challa Date: Tue, 13 Oct 2015 05:23:59 -0700 Subject: [PATCH 0348/1662] Reacting to testing changes --- .../HttpsConnectionFilterTests.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/Microsoft.AspNet.Server.KestrelTests/HttpsConnectionFilterTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/HttpsConnectionFilterTests.cs index 143d802713..c44569899b 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/HttpsConnectionFilterTests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/HttpsConnectionFilterTests.cs @@ -39,7 +39,8 @@ namespace Microsoft.AspNet.Server.KestrelTests // https://github.com/aspnet/KestrelHttpServer/issues/240 // This test currently fails on mono because of an issue with SslStream. [ConditionalFact] - [OSSkipCondition(OperatingSystems.Linux | OperatingSystems.MacOSX)] + [OSSkipCondition(OperatingSystems.Linux)] + [OSSkipCondition(OperatingSystems.MacOSX)] public async Task CanReadAndWriteWithHttpsConnectionFilter() { RemoteCertificateValidationCallback validationCallback = From ef38f5589ddb40171902662301baa2151f945c8f Mon Sep 17 00:00:00 2001 From: David Fowler Date: Tue, 13 Oct 2015 03:46:34 -0700 Subject: [PATCH 0349/1662] React to hosting changes to IApplicationLifetime --- .../Infrastructure/KestrelThread.cs | 10 +++---- .../ServerFactory.cs | 9 +++--- .../ServiceContext.cs | 6 ++-- .../ShutdownNotImplemented.cs | 28 +++++++++++++++++-- .../TestServiceContext.cs | 2 +- 5 files changed, 40 insertions(+), 15 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs index 3c72d00581..b989f2762b 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs @@ -1,14 +1,14 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using Microsoft.AspNet.Server.Kestrel.Networking; using System; using System.Collections.Generic; using System.Runtime.ExceptionServices; using System.Threading; using System.Threading.Tasks; +using Microsoft.AspNet.Hosting; using Microsoft.AspNet.Server.Kestrel.Infrastructure; -using Microsoft.Dnx.Runtime; +using Microsoft.AspNet.Server.Kestrel.Networking; using Microsoft.Extensions.Logging; namespace Microsoft.AspNet.Server.Kestrel @@ -20,7 +20,7 @@ namespace Microsoft.AspNet.Server.Kestrel { private static Action _objectCallbackAdapter = (callback, state) => ((Action)callback).Invoke(state); private KestrelEngine _engine; - private readonly IApplicationShutdown _appShutdown; + private readonly IApplicationLifetime _appLifetime; private Thread _thread; private UvLoopHandle _loop; private UvAsyncHandle _post; @@ -36,7 +36,7 @@ namespace Microsoft.AspNet.Server.Kestrel public KestrelThread(KestrelEngine engine) { _engine = engine; - _appShutdown = engine.AppShutdown; + _appLifetime = engine.AppLifetime; _log = engine.Log; _loop = new UvLoopHandle(_log); _post = new UvAsyncHandle(_log); @@ -232,7 +232,7 @@ namespace Microsoft.AspNet.Server.Kestrel _closeError = ExceptionDispatchInfo.Capture(ex); // Request shutdown so we can rethrow this exception // in Stop which should be observable. - _appShutdown.RequestShutdown(); + _appLifetime.RequestShutdown(); } } diff --git a/src/Microsoft.AspNet.Server.Kestrel/ServerFactory.cs b/src/Microsoft.AspNet.Server.Kestrel/ServerFactory.cs index c804e4c233..2abaf71ecf 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/ServerFactory.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/ServerFactory.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using System.Threading.Tasks; +using Microsoft.AspNet.Hosting; using Microsoft.AspNet.Hosting.Server; using Microsoft.AspNet.Http.Features; using Microsoft.AspNet.Server.Features; @@ -20,13 +21,13 @@ namespace Microsoft.AspNet.Server.Kestrel public class ServerFactory : IServerFactory { private readonly ILibraryManager _libraryManager; - private readonly IApplicationShutdown _appShutdownService; + private readonly IApplicationLifetime _appLifetime; private readonly ILogger _logger; - public ServerFactory(ILibraryManager libraryManager, IApplicationShutdown appShutdownService, ILoggerFactory loggerFactory) + public ServerFactory(ILibraryManager libraryManager, IApplicationLifetime appLifetime, ILoggerFactory loggerFactory) { _libraryManager = libraryManager; - _appShutdownService = appShutdownService; + _appLifetime = appLifetime; _logger = loggerFactory.CreateLogger("Microsoft.AspNet.Server.Kestrel"); } @@ -57,7 +58,7 @@ namespace Microsoft.AspNet.Server.Kestrel var dateHeaderValueManager = new DateHeaderValueManager(); var engine = new KestrelEngine(_libraryManager, new ServiceContext { - AppShutdown = _appShutdownService, + AppLifetime = _appLifetime, Log = new KestrelTrace(_logger), DateHeaderValueManager = dateHeaderValueManager, ConnectionFilter = information.ConnectionFilter diff --git a/src/Microsoft.AspNet.Server.Kestrel/ServiceContext.cs b/src/Microsoft.AspNet.Server.Kestrel/ServiceContext.cs index 317cfcf274..b777101539 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/ServiceContext.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/ServiceContext.cs @@ -1,10 +1,10 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using Microsoft.AspNet.Hosting; using Microsoft.AspNet.Server.Kestrel.Filter; using Microsoft.AspNet.Server.Kestrel.Http; using Microsoft.AspNet.Server.Kestrel.Infrastructure; -using Microsoft.Dnx.Runtime; namespace Microsoft.AspNet.Server.Kestrel { @@ -17,14 +17,14 @@ namespace Microsoft.AspNet.Server.Kestrel public ServiceContext(ServiceContext context) { - AppShutdown = context.AppShutdown; + AppLifetime = context.AppLifetime; Memory = context.Memory; Log = context.Log; DateHeaderValueManager = context.DateHeaderValueManager; ConnectionFilter = context.ConnectionFilter; } - public IApplicationShutdown AppShutdown { get; set; } + public IApplicationLifetime AppLifetime { get; set; } public IMemoryPool Memory { get; set; } diff --git a/test/Microsoft.AspNet.Server.KestrelTests/ShutdownNotImplemented.cs b/test/Microsoft.AspNet.Server.KestrelTests/ShutdownNotImplemented.cs index 5d32828583..4e7b084e93 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/ShutdownNotImplemented.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/ShutdownNotImplemented.cs @@ -3,12 +3,36 @@ using System; using System.Threading; -using Microsoft.Dnx.Runtime; +using Microsoft.AspNet.Hosting; namespace Microsoft.AspNet.Server.KestrelTests { - public class ShutdownNotImplemented : IApplicationShutdown + public class ShutdownNotImplemented : IApplicationLifetime { + public CancellationToken ApplicationStarted + { + get + { + throw new NotImplementedException(); + } + } + + public CancellationToken ApplicationStopped + { + get + { + throw new NotImplementedException(); + } + } + + public CancellationToken ApplicationStopping + { + get + { + throw new NotImplementedException(); + } + } + public CancellationToken ShutdownRequested { get diff --git a/test/Microsoft.AspNet.Server.KestrelTests/TestServiceContext.cs b/test/Microsoft.AspNet.Server.KestrelTests/TestServiceContext.cs index 51fe80d8a9..64f2018fdb 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/TestServiceContext.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/TestServiceContext.cs @@ -6,7 +6,7 @@ namespace Microsoft.AspNet.Server.KestrelTests { public TestServiceContext() { - AppShutdown = new ShutdownNotImplemented(); + AppLifetime = new ShutdownNotImplemented(); Log = new TestKestrelTrace(); DateHeaderValueManager = new TestDateHeaderValueManager(); } From 6aaa3cbe0698e31196692bb6244fd6fac4f53534 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Wed, 14 Oct 2015 01:09:11 -0700 Subject: [PATCH 0350/1662] Use IApplicationLifetime.StopApplication instead of IApplicationShutdown. React to hosting changes https://github.com/aspnet/Hosting/commit/374526b2704f6a6b1dbb6587b704efd29109ab30 --- .../Infrastructure/KestrelThread.cs | 2 +- ...wnNotImplemented.cs => LifetimeNotImplemented.cs} | 12 ++---------- .../TestServiceContext.cs | 2 +- 3 files changed, 4 insertions(+), 12 deletions(-) rename test/Microsoft.AspNet.Server.KestrelTests/{ShutdownNotImplemented.cs => LifetimeNotImplemented.cs} (76%) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs index b989f2762b..69281fddae 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs @@ -232,7 +232,7 @@ namespace Microsoft.AspNet.Server.Kestrel _closeError = ExceptionDispatchInfo.Capture(ex); // Request shutdown so we can rethrow this exception // in Stop which should be observable. - _appLifetime.RequestShutdown(); + _appLifetime.StopApplication(); } } diff --git a/test/Microsoft.AspNet.Server.KestrelTests/ShutdownNotImplemented.cs b/test/Microsoft.AspNet.Server.KestrelTests/LifetimeNotImplemented.cs similarity index 76% rename from test/Microsoft.AspNet.Server.KestrelTests/ShutdownNotImplemented.cs rename to test/Microsoft.AspNet.Server.KestrelTests/LifetimeNotImplemented.cs index 4e7b084e93..e014424b41 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/ShutdownNotImplemented.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/LifetimeNotImplemented.cs @@ -7,7 +7,7 @@ using Microsoft.AspNet.Hosting; namespace Microsoft.AspNet.Server.KestrelTests { - public class ShutdownNotImplemented : IApplicationLifetime + public class LifetimeNotImplemented : IApplicationLifetime { public CancellationToken ApplicationStarted { @@ -33,15 +33,7 @@ namespace Microsoft.AspNet.Server.KestrelTests } } - public CancellationToken ShutdownRequested - { - get - { - throw new NotImplementedException(); - } - } - - public void RequestShutdown() + public void StopApplication() { throw new NotImplementedException(); } diff --git a/test/Microsoft.AspNet.Server.KestrelTests/TestServiceContext.cs b/test/Microsoft.AspNet.Server.KestrelTests/TestServiceContext.cs index 64f2018fdb..edbeb9c44b 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/TestServiceContext.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/TestServiceContext.cs @@ -6,7 +6,7 @@ namespace Microsoft.AspNet.Server.KestrelTests { public TestServiceContext() { - AppLifetime = new ShutdownNotImplemented(); + AppLifetime = new LifetimeNotImplemented(); Log = new TestKestrelTrace(); DateHeaderValueManager = new TestDateHeaderValueManager(); } From 06e895b7b62f45446a3559a3f1d5f7bc5eeac131 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Tue, 13 Oct 2015 12:17:16 -0700 Subject: [PATCH 0351/1662] Make LibuvCopier work on CoreCLR even without DNX env variables - This should fix our AppVeyor builds --- .../Program.cs | 41 +++++++++++++------ .../project.json | 3 +- 2 files changed, 30 insertions(+), 14 deletions(-) diff --git a/tools/Microsoft.AspNet.Server.Kestrel.LibuvCopier/Program.cs b/tools/Microsoft.AspNet.Server.Kestrel.LibuvCopier/Program.cs index 6139fc3b44..db3dc207d8 100644 --- a/tools/Microsoft.AspNet.Server.Kestrel.LibuvCopier/Program.cs +++ b/tools/Microsoft.AspNet.Server.Kestrel.LibuvCopier/Program.cs @@ -1,12 +1,20 @@ using System; using System.IO; using System.Linq; +using Microsoft.Dnx.Runtime; using Newtonsoft.Json.Linq; namespace Microsoft.AspNet.Server.Kestrel.LibuvCopier { public class Program { + private readonly IRuntimeEnvironment _runtimeEnv; + + public Program(IRuntimeEnvironment runtimeEnv) + { + _runtimeEnv = runtimeEnv; + } + public void Main(string[] args) { try @@ -17,23 +25,12 @@ namespace Microsoft.AspNet.Server.Kestrel.LibuvCopier { var dnxFolder = Environment.GetEnvironmentVariable("DNX_HOME"); -#if DNX451 - // DNXCore,Version=v5.0 error CS0117: 'Environment' does not contain a definition for 'SpecialFolder' - // DNXCore,Version=v5.0 error CS0117: 'Environment' does not contain a definition for 'GetFolderPath' if (string.IsNullOrEmpty(dnxFolder)) { - dnxFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".dnx"); + dnxFolder = Path.Combine(GetHome(), ".dnx"); } -#endif - if (!string.IsNullOrEmpty(dnxFolder)) - { - packagesFolder = Path.Combine(dnxFolder, "packages"); - } - else - { - throw new Exception("DNX folder not found. Try setting the DNX_HOME and/or DNX_PACKAGES environment variables."); - } + packagesFolder = Path.Combine(dnxFolder, "packages"); } packagesFolder = Environment.ExpandEnvironmentVariables(packagesFolder); @@ -59,5 +56,23 @@ namespace Microsoft.AspNet.Server.Kestrel.LibuvCopier throw; } } + + // Copied from DNX's DnuEnvironment.cs + private string GetHome() + { +#if DNX451 + return Environment.GetFolderPath(Environment.SpecialFolder.UserProfile); +#else + if (_runtimeEnv.OperatingSystem == "Windows") + { + return Environment.GetEnvironmentVariable("USERPROFILE") ?? + Environment.GetEnvironmentVariable("HOMEDRIVE") + Environment.GetEnvironmentVariable("HOMEPATH"); + } + else + { + return Environment.GetEnvironmentVariable("HOME"); + } +#endif + } } } diff --git a/tools/Microsoft.AspNet.Server.Kestrel.LibuvCopier/project.json b/tools/Microsoft.AspNet.Server.Kestrel.LibuvCopier/project.json index 3932f4fbc4..681bfd77ee 100644 --- a/tools/Microsoft.AspNet.Server.Kestrel.LibuvCopier/project.json +++ b/tools/Microsoft.AspNet.Server.Kestrel.LibuvCopier/project.json @@ -7,7 +7,8 @@ "licenseUrl": "", "dependencies": { - "Newtonsoft.Json" : "7.0.1" + "Microsoft.Dnx.Runtime.Abstractions": "1.0.0-*", + "Newtonsoft.Json": "7.0.1" }, "commands": { From a198ae39cc26ebb86b6c4c1032c1f520eb6d5ba4 Mon Sep 17 00:00:00 2001 From: Troy Dai Date: Tue, 13 Oct 2015 15:01:16 -0700 Subject: [PATCH 0352/1662] Split the DNX_HOME environment variable when it is a semi-colon separated list --- .../Program.cs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/tools/Microsoft.AspNet.Server.Kestrel.LibuvCopier/Program.cs b/tools/Microsoft.AspNet.Server.Kestrel.LibuvCopier/Program.cs index db3dc207d8..9d9c1f3280 100644 --- a/tools/Microsoft.AspNet.Server.Kestrel.LibuvCopier/Program.cs +++ b/tools/Microsoft.AspNet.Server.Kestrel.LibuvCopier/Program.cs @@ -25,10 +25,19 @@ namespace Microsoft.AspNet.Server.Kestrel.LibuvCopier { var dnxFolder = Environment.GetEnvironmentVariable("DNX_HOME"); - if (string.IsNullOrEmpty(dnxFolder)) + var firstCandidate = dnxFolder?.Split(';') + ?.Select(path => Environment.ExpandEnvironmentVariables(path)) + ?.Where(path => Directory.Exists(path)) + ?.FirstOrDefault(); + + if (string.IsNullOrEmpty(firstCandidate)) { dnxFolder = Path.Combine(GetHome(), ".dnx"); } + else + { + dnxFolder = firstCandidate; + } packagesFolder = Path.Combine(dnxFolder, "packages"); } @@ -50,7 +59,7 @@ namespace Microsoft.AspNet.Server.Kestrel.LibuvCopier } } } - catch(Exception ex) + catch (Exception ex) { Console.WriteLine(ex); throw; From 412d527d01d5ca5781a84cb2b86c8e729bb64eeb Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Tue, 13 Oct 2015 15:25:07 -0700 Subject: [PATCH 0353/1662] Check all DNX_HOME env variables in LibuvCopier - Report error if the HOME env variable is required and not set on Linux --- .../Program.cs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/tools/Microsoft.AspNet.Server.Kestrel.LibuvCopier/Program.cs b/tools/Microsoft.AspNet.Server.Kestrel.LibuvCopier/Program.cs index 9d9c1f3280..3904cfc2ed 100644 --- a/tools/Microsoft.AspNet.Server.Kestrel.LibuvCopier/Program.cs +++ b/tools/Microsoft.AspNet.Server.Kestrel.LibuvCopier/Program.cs @@ -23,7 +23,9 @@ namespace Microsoft.AspNet.Server.Kestrel.LibuvCopier if (string.IsNullOrEmpty(packagesFolder)) { - var dnxFolder = Environment.GetEnvironmentVariable("DNX_HOME"); + var dnxFolder = Environment.GetEnvironmentVariable("DNX_HOME") ?? + Environment.GetEnvironmentVariable("DNX_USER_HOME") ?? + Environment.GetEnvironmentVariable("DNX_GLOBAL_HOME"); var firstCandidate = dnxFolder?.Split(';') ?.Select(path => Environment.ExpandEnvironmentVariables(path)) @@ -79,7 +81,14 @@ namespace Microsoft.AspNet.Server.Kestrel.LibuvCopier } else { - return Environment.GetEnvironmentVariable("HOME"); + var home = Environment.GetEnvironmentVariable("HOME"); + + if (string.IsNullOrEmpty(home)) + { + throw new Exception("Home directory not found. The HOME environment variable is not set."); + } + + return home; } #endif } From 7c27c5c0e7a01c7a851dcb67a3fca8f5010526be Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Wed, 7 Oct 2015 19:01:57 -0700 Subject: [PATCH 0354/1662] Better handle blocks not taken taken from slabs - If the block needs to be larger than 4032 bytes it won't be backed by a slab --- .../Filter/SocketInputStream.cs | 5 ++--- src/Microsoft.AspNet.Server.Kestrel/Http/SocketInput.cs | 4 +++- .../Infrastructure/MemoryPoolBlock2.cs | 9 --------- 3 files changed, 5 insertions(+), 13 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Filter/SocketInputStream.cs b/src/Microsoft.AspNet.Server.Kestrel/Filter/SocketInputStream.cs index 43f0d0e704..594d2e45ba 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Filter/SocketInputStream.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Filter/SocketInputStream.cs @@ -18,7 +18,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Filter public class SocketInputStream : Stream { private static Task _emptyTask = Task.FromResult(null); - private static byte[] _emptyBuffer = new byte[0]; private readonly SocketInput _socketInput; @@ -91,8 +90,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Filter protected override void Dispose(bool disposing) { - // Close _socketInput with a 0-length write. - Write(_emptyBuffer, 0, 0); + // Close _socketInput with a fake zero-length write that will result in a zero-length read. + _socketInput.IncomingComplete(0, error: null); base.Dispose(disposing); } } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketInput.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketInput.cs index 6352b742ef..0eb74bb906 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketInput.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketInput.cs @@ -90,6 +90,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http // Unpin may called without an earlier Pin if (_pinned != null) { + _pinned.Unpin(); + _pinned.End += count; if (_head == null) { @@ -170,7 +172,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { var returnBlock = returnStart; returnStart = returnStart.Next; - returnBlock.Pool.Return(returnBlock); + returnBlock.Pool?.Return(returnBlock); } } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolBlock2.cs b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolBlock2.cs index c6fd9bd7a3..6e7aadfa26 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolBlock2.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolBlock2.cs @@ -130,15 +130,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure } } - public static MemoryPoolBlock2 Create(int size, MemoryPool2 pool) - { - return new MemoryPoolBlock2 - { - Data = new ArraySegment(new byte[size]), - Pool = pool - }; - } - public static MemoryPoolBlock2 Create( ArraySegment data, IntPtr dataPtr, From 611eaeb76172addc240b6e1b88c80a0fbe053b73 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Mon, 12 Oct 2015 14:45:51 -0700 Subject: [PATCH 0355/1662] Add test for large blocks not taken from slab --- .../MessageBodyTests.cs | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/test/Microsoft.AspNet.Server.KestrelTests/MessageBodyTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/MessageBodyTests.cs index c997b3854f..b5dbfc021a 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/MessageBodyTests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/MessageBodyTests.cs @@ -52,6 +52,35 @@ namespace Microsoft.AspNet.Server.KestrelTests Assert.Equal(0, count2); } + [Fact] + public async Task CanHandleLargeBlocks() + { + var input = new TestInput(); + var body = MessageBody.For("HTTP/1.0", new Dictionary(), input.FrameContext); + var stream = new FrameRequestStream(body); + + // Input needs to be greater than 4032 bytes to allocate a block not backed by a slab. + var largeInput = new string('a', 8192); + + input.Add(largeInput, true); + // Add a smaller block to the end so that SocketInput attempts to return the large + // block to the memory pool. + input.Add("Hello", true); + + var readBuffer = new byte[8192]; + + var count1 = await stream.ReadAsync(readBuffer, 0, 8192); + Assert.Equal(8192, count1); + AssertASCII(largeInput, new ArraySegment(readBuffer, 0, 8192)); + + var count2 = await stream.ReadAsync(readBuffer, 0, 8192); + Assert.Equal(5, count2); + AssertASCII("Hello", new ArraySegment(readBuffer, 0, 5)); + + var count3 = await stream.ReadAsync(readBuffer, 0, 8192); + Assert.Equal(0, count3); + } + private void AssertASCII(string expected, ArraySegment actual) { var encoding = Encoding.ASCII; From b98425d3b15a901b79280000a288b9afb68d21cf Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Mon, 12 Oct 2015 16:51:50 -0700 Subject: [PATCH 0356/1662] Log unhandled exceptions thrown from the AppFunc --- .../Http/Frame.cs | 1 + .../Infrastructure/IKestrelTrace.cs | 3 ++ .../Infrastructure/KestrelTrace.cs | 5 +++ .../EngineTests.cs | 40 ++++++++++++++++++- 4 files changed, 47 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs index f772b32da8..7bcc55630c 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs @@ -187,6 +187,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } catch (Exception ex) { + Log.ApplicationError(ex); error = ex; } finally diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/IKestrelTrace.cs b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/IKestrelTrace.cs index 4da5b805f0..2b31bfefd4 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/IKestrelTrace.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/IKestrelTrace.cs @@ -1,3 +1,4 @@ +using System; using Microsoft.Extensions.Logging; namespace Microsoft.AspNet.Server.Kestrel.Infrastructure @@ -27,5 +28,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure void ConnectionWrite(long connectionId, int count); void ConnectionWriteCallback(long connectionId, int status); + + void ApplicationError(Exception ex); } } \ No newline at end of file diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelTrace.cs b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelTrace.cs index df4a3a9ac1..e55ad72846 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelTrace.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelTrace.cs @@ -82,6 +82,11 @@ namespace Microsoft.AspNet.Server.Kestrel // Reserved: Event ID 12 } + public virtual void ApplicationError(Exception ex) + { + _logger.LogError(13, "An unhandled exception was thrown by the application.", ex); + } + public virtual void Log(LogLevel logLevel, int eventId, object state, Exception exception, Func formatter) { _logger.Log(logLevel, eventId, state, exception, formatter); diff --git a/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs index 4a74eb84dd..b426214341 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs @@ -7,13 +7,13 @@ using System.Net; using System.Net.Sockets; using System.Text; using System.Threading.Tasks; +using Microsoft.AspNet.Http.Features; using Microsoft.AspNet.Server.Kestrel; using Microsoft.AspNet.Server.Kestrel.Filter; -using Microsoft.AspNet.Server.Kestrel.Http; using Microsoft.Dnx.Runtime; using Microsoft.Dnx.Runtime.Infrastructure; +using Microsoft.Extensions.Logging; using Xunit; -using Microsoft.AspNet.Http.Features; namespace Microsoft.AspNet.Server.KestrelTests { @@ -552,6 +552,9 @@ namespace Microsoft.AspNet.Server.KestrelTests { bool onStartingCalled = false; + var testLogger = new TestApplicationErrorLogger(); + testContext.Log = new KestrelTrace(testLogger); + using (var server = new TestServer(frame => { var response = frame.Get(); @@ -595,6 +598,7 @@ namespace Microsoft.AspNet.Server.KestrelTests ""); Assert.False(onStartingCalled); + Assert.Equal(2, testLogger.ApplicationErrorsLogged); } } } @@ -605,6 +609,9 @@ namespace Microsoft.AspNet.Server.KestrelTests { bool onStartingCalled = false; + var testLogger = new TestApplicationErrorLogger(); + testContext.Log = new KestrelTrace(testLogger); + using (var server = new TestServer(async frame => { var response = frame.Get(); @@ -633,6 +640,7 @@ namespace Microsoft.AspNet.Server.KestrelTests "Hello World"); Assert.True(onStartingCalled); + Assert.Equal(1, testLogger.ApplicationErrorsLogged); } } } @@ -643,6 +651,9 @@ namespace Microsoft.AspNet.Server.KestrelTests { bool onStartingCalled = false; + var testLogger = new TestApplicationErrorLogger(); + testContext.Log = new KestrelTrace(testLogger); + using (var server = new TestServer(async frame => { var response = frame.Get(); @@ -671,6 +682,7 @@ namespace Microsoft.AspNet.Server.KestrelTests "Hello"); Assert.True(onStartingCalled); + Assert.Equal(1, testLogger.ApplicationErrorsLogged); } } } @@ -834,5 +846,29 @@ namespace Microsoft.AspNet.Server.KestrelTests } } } + + private class TestApplicationErrorLogger : ILogger + { + public int ApplicationErrorsLogged { get; set; } + + public IDisposable BeginScopeImpl(object state) + { + throw new NotImplementedException(); + } + + public bool IsEnabled(LogLevel logLevel) + { + throw new NotImplementedException(); + } + + public void Log(LogLevel logLevel, int eventId, object state, Exception exception, Func formatter) + { + // Application errors are logged using 13 as the eventId. + if (eventId == 13) + { + ApplicationErrorsLogged++; + } + } + } } } From 513abb45617d872813601a195eb740199f973b75 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Wed, 14 Oct 2015 15:23:56 -0700 Subject: [PATCH 0357/1662] Log errors in OnStarting and OnCompleted --- .../Http/Frame.FeatureCollection.cs | 2 +- .../Http/Frame.cs | 108 +++++++++++------- .../EngineTests.cs | 51 +++++---- 3 files changed, 95 insertions(+), 66 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.FeatureCollection.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.FeatureCollection.cs index 293c3facc4..126dce7891 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.FeatureCollection.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.FeatureCollection.cs @@ -275,7 +275,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http ResponseHeaders["Upgrade"] = values; } } - ProduceStart(); + ProduceStartAndFireOnStarting(immediate: true).GetAwaiter().GetResult(); return Task.FromResult(DuplexStream); } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs index 7bcc55630c..161536aef3 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs @@ -42,6 +42,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http private bool _responseStarted; private bool _keepAlive; private bool _autoChunk; + private bool _applicationFailed; public Frame(ConnectionContext context) : base(context) { @@ -172,28 +173,27 @@ namespace Microsoft.AspNet.Server.Kestrel.Http ResponseBody = new FrameResponseStream(this); DuplexStream = new FrameDuplexStream(RequestBody, ResponseBody); - Exception error = null; try { await Application.Invoke(this).ConfigureAwait(false); - + } + catch (Exception ex) + { + ReportApplicationError(ex); + } + finally + { // Trigger FireOnStarting if ProduceStart hasn't been called yet. // We call it here, so it can go through our normal error handling // and respond with a 500 if an OnStarting callback throws. if (!_responseStarted) { - FireOnStarting(); + await FireOnStarting(); } - } - catch (Exception ex) - { - Log.ApplicationError(ex); - error = ex; - } - finally - { - FireOnCompleted(); - ProduceEnd(error); + + await FireOnCompleted(); + + await ProduceEnd(); } terminated = !_keepAlive; @@ -250,7 +250,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } - private void FireOnStarting() + private async Task FireOnStarting() { List, object>> onStarting = null; lock (_onStartingSync) @@ -262,12 +262,19 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { foreach (var entry in onStarting) { - entry.Key.Invoke(entry.Value).Wait(); + try + { + await entry.Key.Invoke(entry.Value); + } + catch (Exception ex) + { + ReportApplicationError(ex); + } } } } - private void FireOnCompleted() + private async Task FireOnCompleted() { List, object>> onCompleted = null; lock (_onCompletedSync) @@ -281,11 +288,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { try { - entry.Key.Invoke(entry.Value).Wait(); + await entry.Key.Invoke(entry.Value); } - catch + catch (Exception ex) { - // Ignore exceptions + ReportApplicationError(ex); } } } @@ -293,19 +300,19 @@ namespace Microsoft.AspNet.Server.Kestrel.Http public void Flush() { - ProduceStart(immediate: false); + ProduceStartAndFireOnStarting(immediate: false).GetAwaiter().GetResult(); SocketOutput.Write(_emptyData, immediate: true); } - public Task FlushAsync(CancellationToken cancellationToken) + public async Task FlushAsync(CancellationToken cancellationToken) { - ProduceStart(immediate: false); - return SocketOutput.WriteAsync(_emptyData, immediate: true); + await ProduceStartAndFireOnStarting(immediate: false); + await SocketOutput.WriteAsync(_emptyData, immediate: true); } public void Write(ArraySegment data) { - ProduceStart(immediate: false); + ProduceStartAndFireOnStarting(immediate: false).GetAwaiter().GetResult(); if (_autoChunk) { @@ -321,21 +328,21 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } - public Task WriteAsync(ArraySegment data, CancellationToken cancellationToken) + public async Task WriteAsync(ArraySegment data, CancellationToken cancellationToken) { - ProduceStart(immediate: false); + await ProduceStartAndFireOnStarting(immediate: false); if (_autoChunk) { if (data.Count == 0) { - return TaskUtilities.CompletedTask; + return; } - return WriteChunkedAsync(data, cancellationToken); + await WriteChunkedAsync(data, cancellationToken); } else { - return SocketOutput.WriteAsync(data, immediate: true, cancellationToken: cancellationToken); + await SocketOutput.WriteAsync(data, immediate: true, cancellationToken: cancellationToken); } } @@ -387,12 +394,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Http SocketOutput.Write(_endChunkedResponseBytes, immediate: true); } - public void Upgrade(IDictionary options, Func callback) - { - _keepAlive = false; - ProduceStart(); - } - private static ArraySegment CreateAsciiByteArraySegment(string text) { var bytes = Encoding.ASCII.GetBytes(text); @@ -412,23 +413,38 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } - public void ProduceStart(bool immediate = true, bool appCompleted = false) + public async Task ProduceStartAndFireOnStarting(bool immediate = true) + { + if (_responseStarted) return; + + await FireOnStarting(); + + if (_applicationFailed) + { + throw new ObjectDisposedException(typeof(Frame).FullName); + } + + await ProduceStart(immediate, appCompleted: false); + } + + private async Task ProduceStart(bool immediate, bool appCompleted) { - // ProduceStart shouldn't no-op in the future just b/c FireOnStarting throws. if (_responseStarted) return; - FireOnStarting(); _responseStarted = true; var status = ReasonPhrases.ToStatus(StatusCode, ReasonPhrase); var responseHeader = CreateResponseHeader(status, appCompleted); - SocketOutput.Write(responseHeader.Item1, immediate: immediate); - responseHeader.Item2.Dispose(); + + using (responseHeader.Item2) + { + await SocketOutput.WriteAsync(responseHeader.Item1, immediate: immediate); + } } - public void ProduceEnd(Exception ex) + private async Task ProduceEnd() { - if (ex != null) + if (_applicationFailed) { if (_responseStarted) { @@ -450,7 +466,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } - ProduceStart(immediate: true, appCompleted: true); + await ProduceStart(immediate: true, appCompleted: true); // _autoChunk should be checked after we are sure ProduceStart() has been called // since ProduceStart() may set _autoChunk to true. @@ -728,5 +744,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http statusCode != 205 && statusCode != 304; } + + private void ReportApplicationError(Exception ex) + { + _applicationFailed = true; + Log.ApplicationError(ex); + } } } diff --git a/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs index b426214341..b5c36efce0 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs @@ -550,7 +550,7 @@ namespace Microsoft.AspNet.Server.KestrelTests [MemberData(nameof(ConnectionFilterData))] public async Task ThrowingResultsIn500Response(ServiceContext testContext) { - bool onStartingCalled = false; + var onStartingCallCount = 0; var testLogger = new TestApplicationErrorLogger(); testContext.Log = new KestrelTrace(testLogger); @@ -560,7 +560,7 @@ namespace Microsoft.AspNet.Server.KestrelTests var response = frame.Get(); response.OnStarting(_ => { - onStartingCalled = true; + onStartingCallCount++; return Task.FromResult(null); }, null); @@ -597,7 +597,7 @@ namespace Microsoft.AspNet.Server.KestrelTests "", ""); - Assert.False(onStartingCalled); + Assert.Equal(2, onStartingCallCount); Assert.Equal(2, testLogger.ApplicationErrorsLogged); } } @@ -758,22 +758,30 @@ namespace Microsoft.AspNet.Server.KestrelTests [Theory] [MemberData(nameof(ConnectionFilterData))] - public async Task ThrowingInOnStartingResultsIn500Response(ServiceContext testContext) + public async Task ThrowingInOnStartingResultsInFailedWritesAnd500Response(ServiceContext testContext) { - using (var server = new TestServer(frame => + var onStartingCallCount = 0; + var failedWriteCount = 0; + + var testLogger = new TestApplicationErrorLogger(); + testContext.Log = new KestrelTrace(testLogger); + + using (var server = new TestServer(async frame => { var response = frame.Get(); response.OnStarting(_ => { + onStartingCallCount++; throw new Exception(); }, null); response.Headers.Clear(); response.Headers["Content-Length"] = new[] { "11" }; - // If we write to the response stream, we will not get a 500. + await Assert.ThrowsAsync(async () => + await response.Body.WriteAsync(Encoding.ASCII.GetBytes("Hello World"), 0, 11)); - return Task.FromResult(null); + failedWriteCount++; }, testContext)) { using (var connection = new TestConnection()) @@ -802,34 +810,31 @@ namespace Microsoft.AspNet.Server.KestrelTests "Connection: close", "", ""); + + Assert.Equal(2, onStartingCallCount); + Assert.Equal(2, testLogger.ApplicationErrorsLogged); } } } - [Theory] [MemberData(nameof(ConnectionFilterData))] - public async Task ThrowingInOnStartingResultsInFailedWrites(ServiceContext testContext) + public async Task ThrowingInOnCompletedIsLoggedAndClosesConnection(ServiceContext testContext) { + var testLogger = new TestApplicationErrorLogger(); + testContext.Log = new KestrelTrace(testLogger); + using (var server = new TestServer(async frame => { - var onStartingException = new Exception(); - var response = frame.Get(); - response.OnStarting(_ => + response.OnCompleted(_ => { - throw onStartingException; + throw new Exception(); }, null); response.Headers.Clear(); response.Headers["Content-Length"] = new[] { "11" }; - var writeException = await Assert.ThrowsAsync(async () => - await response.Body.WriteAsync(Encoding.ASCII.GetBytes("Hello World"), 0, 11)); - - Assert.Same(onStartingException, writeException); - - // The second write should succeed since the OnStarting callback will not be called again - await response.Body.WriteAsync(Encoding.ASCII.GetBytes("Exception!!"), 0, 11); + await response.Body.WriteAsync(Encoding.ASCII.GetBytes("Hello World"), 0, 11); }, testContext)) { using (var connection = new TestConnection()) @@ -838,12 +843,14 @@ namespace Microsoft.AspNet.Server.KestrelTests "GET / HTTP/1.1", "", ""); - await connection.Receive( + await connection.ReceiveEnd( "HTTP/1.1 200 OK", "Content-Length: 11", "", - "Exception!!"); ; + "Hello World"); } + + Assert.Equal(1, testLogger.ApplicationErrorsLogged); } } From 7b315d2470e57ae832a763a2338b0a275f39eb8f Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Wed, 14 Oct 2015 15:29:30 -0700 Subject: [PATCH 0358/1662] Close connection gracefully in Frame.ProduceEnd - Try sending a FIN before closing the socket - Don't attempt to send a FIN twice for the same connection --- src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs index 161536aef3..22daa279a2 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs @@ -449,7 +449,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http if (_responseStarted) { // We can no longer respond with a 500, so we simply close the connection. - ConnectionControl.End(ProduceEndType.SocketDisconnect); + _keepAlive = false; return; } else @@ -475,7 +475,10 @@ namespace Microsoft.AspNet.Server.Kestrel.Http WriteChunkedResponseSuffix(); } - ConnectionControl.End(_keepAlive ? ProduceEndType.ConnectionKeepAlive : ProduceEndType.SocketShutdownSend); + if (_keepAlive) + { + ConnectionControl.End(ProduceEndType.ConnectionKeepAlive); + } } private Tuple, IDisposable> CreateResponseHeader( From 8e818e3549bcf95ada46911520638ccbec8fc900 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Thu, 15 Oct 2015 16:52:37 -0700 Subject: [PATCH 0359/1662] Address PR feedback --- .../Http/Frame.cs | 40 +++++++++--------- .../EngineTests.cs | 42 +++++++++++++++---- 2 files changed, 53 insertions(+), 29 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs index 22daa279a2..0d7b5ce6e5 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs @@ -42,7 +42,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http private bool _responseStarted; private bool _keepAlive; private bool _autoChunk; - private bool _applicationFailed; + private Exception _applicationException; public Frame(ConnectionContext context) : base(context) { @@ -79,6 +79,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http _responseStarted = false; _keepAlive = false; _autoChunk = false; + _applicationException = null; _requestHeaders.Reset(); ResetResponseHeaders(); @@ -183,10 +184,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } finally { - // Trigger FireOnStarting if ProduceStart hasn't been called yet. - // We call it here, so it can go through our normal error handling - // and respond with a 500 if an OnStarting callback throws. - if (!_responseStarted) + // Trigger OnStarting if it hasn't been called yet and the app hasn't + // already failed. If an OnStarting callback throws we can go through + // our normal error handling in ProduceEnd. + // https://github.com/aspnet/KestrelHttpServer/issues/43 + if (!_responseStarted && _applicationException == null) { await FireOnStarting(); } @@ -260,16 +262,16 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } if (onStarting != null) { - foreach (var entry in onStarting) + try { - try + foreach (var entry in onStarting) { await entry.Key.Invoke(entry.Value); } - catch (Exception ex) - { - ReportApplicationError(ex); - } + } + catch (Exception ex) + { + ReportApplicationError(ex); } } } @@ -419,9 +421,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http await FireOnStarting(); - if (_applicationFailed) + if (_applicationException != null) { - throw new ObjectDisposedException(typeof(Frame).FullName); + throw new ObjectDisposedException( + "The response has been aborted due to an unhandled application exception.", + _applicationException); } await ProduceStart(immediate, appCompleted: false); @@ -444,12 +448,12 @@ namespace Microsoft.AspNet.Server.Kestrel.Http private async Task ProduceEnd() { - if (_applicationFailed) + if (_applicationException != null) { if (_responseStarted) { // We can no longer respond with a 500, so we simply close the connection. - _keepAlive = false; + _requestProcessingStopping = true; return; } else @@ -457,10 +461,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Http StatusCode = 500; ReasonPhrase = null; - // If OnStarting hasn't been triggered yet, we don't want to trigger it now that - // the app func has failed. https://github.com/aspnet/KestrelHttpServer/issues/43 - _onStarting = null; - ResetResponseHeaders(); _responseHeaders.HeaderContentLength = "0"; } @@ -750,7 +750,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http private void ReportApplicationError(Exception ex) { - _applicationFailed = true; + _applicationException = ex; Log.ApplicationError(ex); } } diff --git a/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs index b5c36efce0..3aa7ca2105 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs @@ -550,7 +550,7 @@ namespace Microsoft.AspNet.Server.KestrelTests [MemberData(nameof(ConnectionFilterData))] public async Task ThrowingResultsIn500Response(ServiceContext testContext) { - var onStartingCallCount = 0; + bool onStartingCalled = false; var testLogger = new TestApplicationErrorLogger(); testContext.Log = new KestrelTrace(testLogger); @@ -560,7 +560,7 @@ namespace Microsoft.AspNet.Server.KestrelTests var response = frame.Get(); response.OnStarting(_ => { - onStartingCallCount++; + onStartingCalled = true; return Task.FromResult(null); }, null); @@ -597,7 +597,7 @@ namespace Microsoft.AspNet.Server.KestrelTests "", ""); - Assert.Equal(2, onStartingCallCount); + Assert.False(onStartingCalled); Assert.Equal(2, testLogger.ApplicationErrorsLogged); } } @@ -760,7 +760,8 @@ namespace Microsoft.AspNet.Server.KestrelTests [MemberData(nameof(ConnectionFilterData))] public async Task ThrowingInOnStartingResultsInFailedWritesAnd500Response(ServiceContext testContext) { - var onStartingCallCount = 0; + var onStartingCallCount1 = 0; + var onStartingCallCount2 = 0; var failedWriteCount = 0; var testLogger = new TestApplicationErrorLogger(); @@ -768,19 +769,28 @@ namespace Microsoft.AspNet.Server.KestrelTests using (var server = new TestServer(async frame => { + var onStartingException = new Exception(); + var response = frame.Get(); response.OnStarting(_ => { - onStartingCallCount++; - throw new Exception(); + onStartingCallCount1++; + throw onStartingException; + }, null); + response.OnStarting(_ => + { + onStartingCallCount2++; + throw onStartingException; }, null); response.Headers.Clear(); response.Headers["Content-Length"] = new[] { "11" }; - await Assert.ThrowsAsync(async () => + var writeException = await Assert.ThrowsAsync(async () => await response.Body.WriteAsync(Encoding.ASCII.GetBytes("Hello World"), 0, 11)); + Assert.Same(onStartingException, writeException.InnerException); + failedWriteCount++; }, testContext)) { @@ -811,7 +821,9 @@ namespace Microsoft.AspNet.Server.KestrelTests "", ""); - Assert.Equal(2, onStartingCallCount); + Assert.Equal(2, onStartingCallCount1); + // The second OnStarting callback should not be called since the first failed. + Assert.Equal(0, onStartingCallCount2); Assert.Equal(2, testLogger.ApplicationErrorsLogged); } } @@ -820,6 +832,9 @@ namespace Microsoft.AspNet.Server.KestrelTests [MemberData(nameof(ConnectionFilterData))] public async Task ThrowingInOnCompletedIsLoggedAndClosesConnection(ServiceContext testContext) { + var onCompletedCalled1 = false; + var onCompletedCalled2 = false; + var testLogger = new TestApplicationErrorLogger(); testContext.Log = new KestrelTrace(testLogger); @@ -828,6 +843,12 @@ namespace Microsoft.AspNet.Server.KestrelTests var response = frame.Get(); response.OnCompleted(_ => { + onCompletedCalled1 = true; + throw new Exception(); + }, null); + response.OnCompleted(_ => + { + onCompletedCalled2 = true; throw new Exception(); }, null); @@ -850,7 +871,10 @@ namespace Microsoft.AspNet.Server.KestrelTests "Hello World"); } - Assert.Equal(1, testLogger.ApplicationErrorsLogged); + // All OnCompleted callbacks should be called even if they throw. + Assert.Equal(2, testLogger.ApplicationErrorsLogged); + Assert.True(onCompletedCalled1); + Assert.True(onCompletedCalled2); } } From c809beec18ce29eb31ad55ef1952c1e537ed2b54 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Wed, 14 Oct 2015 17:19:38 -0700 Subject: [PATCH 0360/1662] Don't allocate Exceptions unnecessarily - Allocate Exceptions in the ReadStart callbacks if necessary instead of in UvStreamHandle. - This also fixes a bug in ListenerSecondary where it should have previously been looking at the error code instead of the read count. #237 --- .../Http/Connection.cs | 22 ++++++++++++------- .../Http/ListenerSecondary.cs | 2 +- .../Infrastructure/IKestrelTrace.cs | 2 +- .../Networking/UvStreamHandle.cs | 20 +++++------------ .../MultipleLoopTests.cs | 6 ++--- .../NetworkingTests.cs | 12 ++++------ 6 files changed, 28 insertions(+), 36 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs index 48dd7de7a1..f5a7033795 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs @@ -13,7 +13,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { public class Connection : ConnectionContext, IConnectionControl { - private static readonly Action _readCallback = ReadCallback; + private static readonly Action _readCallback = ReadCallback; private static readonly Func _allocCallback = AllocCallback; private static long _lastConnectionId; @@ -113,28 +113,34 @@ namespace Microsoft.AspNet.Server.Kestrel.Http result.Data.Count); } - private static void ReadCallback(UvStreamHandle handle, int readCount, int errorCode, Exception error, object state) + private static void ReadCallback(UvStreamHandle handle, int status, object state) { - ((Connection)state).OnRead(handle, readCount, errorCode, error); + ((Connection)state).OnRead(handle, status); } - private void OnRead(UvStreamHandle handle, int readCount, int errorCode, Exception error) + private void OnRead(UvStreamHandle handle, int status) { - var normalRead = readCount != 0 && errorCode == 0; - var normalDone = readCount == 0 && (errorCode == 0 || errorCode == Constants.ECONNRESET || errorCode == Constants.EOF); + var normalRead = status > 0; + var normalDone = status == 0 || status == Constants.ECONNRESET || status == Constants.EOF; var errorDone = !(normalDone || normalRead); + var readCount = normalRead ? status : 0; if (normalRead) { Log.ConnectionRead(_connectionId, readCount); } - else if (normalDone || errorDone) + else { _socket.ReadStop(); Log.ConnectionReadFin(_connectionId); } - _rawSocketInput.IncomingComplete(readCount, errorDone ? error : null); + Exception error = null; + if (errorDone) + { + handle.Libuv.Check(status, out error); + } + _rawSocketInput.IncomingComplete(readCount, error); } void IConnectionControl.Pause() diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerSecondary.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerSecondary.cs index 1f4e34a4bf..a348970737 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerSecondary.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerSecondary.cs @@ -61,7 +61,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http DispatchPipe.ReadStart( (_1, _2, _3) => buf, - (_1, status2, errCode, error2, state2) => + (_1, status2, state2) => { if (status2 < 0) { diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/IKestrelTrace.cs b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/IKestrelTrace.cs index 2b31bfefd4..7c5776fcc4 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/IKestrelTrace.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/IKestrelTrace.cs @@ -9,7 +9,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure void ConnectionStop(long connectionId); - void ConnectionRead(long connectionId, int status); + void ConnectionRead(long connectionId, int count); void ConnectionPause(long connectionId); diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvStreamHandle.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvStreamHandle.cs index 42c6cd3e81..e6ffafe24c 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvStreamHandle.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvStreamHandle.cs @@ -19,7 +19,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking private GCHandle _listenVitality; public Func _allocCallback; - public Action _readCallback; + public Action _readCallback; public object _readState; private GCHandle _readVitality; @@ -72,13 +72,14 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking public void ReadStart( Func allocCallback, - Action readCallback, + Action readCallback, object state) { if (_readVitality.IsAllocated) { throw new InvalidOperationException("TODO: ReadStop must be called before ReadStart may be called again"); } + try { _allocCallback = allocCallback; @@ -118,7 +119,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking return _uv.try_write(this, new[] { buf }, 1); } - private static void UvConnectionCb(IntPtr handle, int status) { var stream = FromIntPtr(handle); @@ -137,7 +137,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking } } - private static void UvAllocCb(IntPtr handle, int suggested_size, out Libuv.uv_buf_t buf) { var stream = FromIntPtr(handle); @@ -153,22 +152,13 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking } } - private static void UvReadCb(IntPtr handle, int nread, ref Libuv.uv_buf_t buf) + private static void UvReadCb(IntPtr handle, int status, ref Libuv.uv_buf_t buf) { var stream = FromIntPtr(handle); try { - if (nread < 0) - { - Exception error; - stream._uv.Check(nread, out error); - stream._readCallback(stream, 0, nread, error, stream._readState); - } - else - { - stream._readCallback(stream, nread, 0, null, stream._readState); - } + stream._readCallback(stream, status, stream._readState); } catch (Exception ex) { diff --git a/test/Microsoft.AspNet.Server.KestrelTests/MultipleLoopTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/MultipleLoopTests.cs index 224f90f270..ddbecbd06d 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/MultipleLoopTests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/MultipleLoopTests.cs @@ -113,7 +113,7 @@ namespace Microsoft.AspNet.Server.KestrelTests connect.Dispose(); clientConnectionPipe.ReadStart( (_3, cb, _4) => buf, - (_3, status2, errCode, error2, _4) => + (_3, status2, _4) => { if (status2 == 0) { @@ -213,7 +213,7 @@ namespace Microsoft.AspNet.Server.KestrelTests clientConnectionPipe.ReadStart( (_3, cb, _4) => buf, - (_3, status2, errCode2, error2, _4) => + (_3, status2, _4) => { if (status2 == 0) { @@ -226,7 +226,7 @@ namespace Microsoft.AspNet.Server.KestrelTests var buf2 = loop2.Libuv.buf_init(Marshal.AllocHGlobal(64), 64); clientConnectionTcp.ReadStart( (_5, cb, _6) => buf2, - (_5, status3, errCode3, error3, _6) => + (_5, status3, _6) => { if (status3 == 0) { diff --git a/test/Microsoft.AspNet.Server.KestrelTests/NetworkingTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/NetworkingTests.cs index 81aa4ddcad..363cb1ea4d 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/NetworkingTests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/NetworkingTests.cs @@ -129,7 +129,6 @@ namespace Microsoft.AspNet.Server.KestrelTests [Fact] public async Task SocketCanRead() { - int bytesRead = 0; var loop = new UvLoopHandle(_logger); loop.Init(_uv); var tcp = new UvTcpHandle(_logger); @@ -145,10 +144,9 @@ namespace Microsoft.AspNet.Server.KestrelTests var data = Marshal.AllocCoTaskMem(500); tcp2.ReadStart( (a, b, c) => _uv.buf_init(data, 500), - (__, nread, errCode, error2, state2) => + (__, nread, state2) => { - bytesRead += nread; - if (nread == 0) + if (nread <= 0) { tcp2.Dispose(); } @@ -186,7 +184,6 @@ namespace Microsoft.AspNet.Server.KestrelTests [Fact] public async Task SocketCanReadAndWrite() { - int bytesRead = 0; var loop = new UvLoopHandle(_logger); loop.Init(_uv); var tcp = new UvTcpHandle(_logger); @@ -202,10 +199,9 @@ namespace Microsoft.AspNet.Server.KestrelTests var data = Marshal.AllocCoTaskMem(500); tcp2.ReadStart( (a, b, c) => tcp2.Libuv.buf_init(data, 500), - (__, nread, errCode, error2, state2) => + (__, nread, state2) => { - bytesRead += nread; - if (nread == 0) + if (nread <= 0) { tcp2.Dispose(); } From 8f0d1179ab8cc636febd8a319ba14008d96d037d Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Mon, 19 Oct 2015 12:44:21 -0700 Subject: [PATCH 0361/1662] =?UTF-8?q?Allow=20Nagle=E2=80=99s=20algorithm?= =?UTF-8?q?=20to=20be=20disabled=20via=20IKestrelServerInformation.NoDelay?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- samples/SampleApp/Startup.cs | 1 + src/Microsoft.AspNet.Server.Kestrel/Http/TcpListener.cs | 2 ++ .../Http/TcpListenerPrimary.cs | 2 ++ .../Http/TcpListenerSecondary.cs | 1 + .../IKestrelServerInformation.cs | 2 ++ .../KestrelServerInformation.cs | 2 ++ src/Microsoft.AspNet.Server.Kestrel/Networking/Libuv.cs | 9 +++++++++ .../Networking/UvTcpHandle.cs | 5 +++++ src/Microsoft.AspNet.Server.Kestrel/ServerFactory.cs | 3 ++- src/Microsoft.AspNet.Server.Kestrel/ServiceContext.cs | 3 +++ 10 files changed, 29 insertions(+), 1 deletion(-) diff --git a/samples/SampleApp/Startup.cs b/samples/SampleApp/Startup.cs index 834aadd1d1..7b863a5624 100644 --- a/samples/SampleApp/Startup.cs +++ b/samples/SampleApp/Startup.cs @@ -23,6 +23,7 @@ namespace SampleApp { var ksi = app.ServerFeatures.Get(); //ksi.ThreadCount = 4; + ksi.NoDelay = true; loggerFactory.MinimumLevel = LogLevel.Debug; diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/TcpListener.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/TcpListener.cs index b09d86a43c..d3af771f5d 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/TcpListener.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/TcpListener.cs @@ -25,6 +25,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { var socket = new UvTcpHandle(Log); socket.Init(Thread.Loop, Thread.QueueCloseHandle); + socket.NoDelay(NoDelay); socket.Bind(ServerAddress); socket.Listen(Constants.ListenBacklog, ConnectionCallback, this); return socket; @@ -39,6 +40,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { var acceptSocket = new UvTcpHandle(Log); acceptSocket.Init(Thread.Loop, Thread.QueueCloseHandle); + acceptSocket.NoDelay(NoDelay); try { diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/TcpListenerPrimary.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/TcpListenerPrimary.cs index 700e888195..4f1ff0a48d 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/TcpListenerPrimary.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/TcpListenerPrimary.cs @@ -25,6 +25,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { var socket = new UvTcpHandle(Log); socket.Init(Thread.Loop, Thread.QueueCloseHandle); + socket.NoDelay(NoDelay); socket.Bind(ServerAddress); socket.Listen(Constants.ListenBacklog, ConnectionCallback, this); return socket; @@ -39,6 +40,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { var acceptSocket = new UvTcpHandle(Log); acceptSocket.Init(Thread.Loop, Thread.QueueCloseHandle); + acceptSocket.NoDelay(NoDelay); try { diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/TcpListenerSecondary.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/TcpListenerSecondary.cs index d6680d3318..9a36f2b171 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/TcpListenerSecondary.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/TcpListenerSecondary.cs @@ -21,6 +21,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { var acceptSocket = new UvTcpHandle(Log); acceptSocket.Init(Thread.Loop, Thread.QueueCloseHandle); + acceptSocket.NoDelay(NoDelay); return acceptSocket; } } diff --git a/src/Microsoft.AspNet.Server.Kestrel/IKestrelServerInformation.cs b/src/Microsoft.AspNet.Server.Kestrel/IKestrelServerInformation.cs index 5e90ebdfc7..870fe2e533 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/IKestrelServerInformation.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/IKestrelServerInformation.cs @@ -9,6 +9,8 @@ namespace Microsoft.AspNet.Server.Kestrel { int ThreadCount { get; set; } + bool NoDelay { get; set; } + IConnectionFilter ConnectionFilter { get; set; } } } diff --git a/src/Microsoft.AspNet.Server.Kestrel/KestrelServerInformation.cs b/src/Microsoft.AspNet.Server.Kestrel/KestrelServerInformation.cs index 3f50057c5d..840533012c 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/KestrelServerInformation.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/KestrelServerInformation.cs @@ -15,6 +15,8 @@ namespace Microsoft.AspNet.Server.Kestrel public int ThreadCount { get; set; } + public bool NoDelay { get; set; } + public IConnectionFilter ConnectionFilter { get; set; } public void Initialize(IConfiguration configuration) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/Libuv.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/Libuv.cs index f926b16bd5..a94d954a07 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/Libuv.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/Libuv.cs @@ -202,6 +202,15 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking Check(_uv_tcp_open(handle, hSocket)); } + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + protected delegate int uv_tcp_nodelay(UvTcpHandle handle, int enable); + protected uv_tcp_nodelay _uv_tcp_nodelay = default(uv_tcp_nodelay); + public void tcp_nodelay(UvTcpHandle handle, bool enable) + { + handle.Validate(); + Check(_uv_tcp_nodelay(handle, enable ? 1 : 0)); + } + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] protected delegate int uv_pipe_init(UvLoopHandle loop, UvPipeHandle handle, int ipc); protected uv_pipe_init _uv_pipe_init = default(uv_pipe_init); diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvTcpHandle.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvTcpHandle.cs index 4e79ea9864..b43e9c985e 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvTcpHandle.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvTcpHandle.cs @@ -61,6 +61,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking _uv.tcp_open(this, hSocket); } + public void NoDelay(bool enable) + { + _uv.tcp_nodelay(this, enable); + } + /// /// Returns an for the given host an port. /// If the host parameter isn't "localhost" or an IP address, use IPAddress.Any. diff --git a/src/Microsoft.AspNet.Server.Kestrel/ServerFactory.cs b/src/Microsoft.AspNet.Server.Kestrel/ServerFactory.cs index 2abaf71ecf..f39bff2a27 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/ServerFactory.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/ServerFactory.cs @@ -61,7 +61,8 @@ namespace Microsoft.AspNet.Server.Kestrel AppLifetime = _appLifetime, Log = new KestrelTrace(_logger), DateHeaderValueManager = dateHeaderValueManager, - ConnectionFilter = information.ConnectionFilter + ConnectionFilter = information.ConnectionFilter, + NoDelay = information.NoDelay }); disposables.Push(engine); diff --git a/src/Microsoft.AspNet.Server.Kestrel/ServiceContext.cs b/src/Microsoft.AspNet.Server.Kestrel/ServiceContext.cs index b777101539..35086de40d 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/ServiceContext.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/ServiceContext.cs @@ -22,6 +22,7 @@ namespace Microsoft.AspNet.Server.Kestrel Log = context.Log; DateHeaderValueManager = context.DateHeaderValueManager; ConnectionFilter = context.ConnectionFilter; + NoDelay = context.NoDelay; } public IApplicationLifetime AppLifetime { get; set; } @@ -33,5 +34,7 @@ namespace Microsoft.AspNet.Server.Kestrel public DateHeaderValueManager DateHeaderValueManager { get; set; } public IConnectionFilter ConnectionFilter { get; set; } + + public bool NoDelay { get; set; } } } From f8fd2f9ac9be11e68ac29693166cf4dee0c459b8 Mon Sep 17 00:00:00 2001 From: Pavel Krymets Date: Wed, 21 Oct 2015 10:15:11 -0700 Subject: [PATCH 0362/1662] React to hosting changes --- samples/SampleApp/Program.cs | 14 +++----------- src/Microsoft.AspNet.Server.Kestrel/Program.cs | 12 ++---------- .../AddressRegistrationTests.cs | 2 +- .../RequestTests.cs | 2 +- .../ResponseTests.cs | 2 +- .../ThreadCountTests.cs | 2 +- 6 files changed, 9 insertions(+), 25 deletions(-) diff --git a/samples/SampleApp/Program.cs b/samples/SampleApp/Program.cs index acf7f214c8..06205db078 100644 --- a/samples/SampleApp/Program.cs +++ b/samples/SampleApp/Program.cs @@ -7,18 +7,10 @@ namespace SampleApp { public class Program { - private IServiceProvider _services; - - public Program(IServiceProvider services) + public static void Main(string[] args) { - _services = services; - } - - public void Main(string[] args) - { - new Microsoft.AspNet.Hosting.Program(_services).Main(new[] { - "--server", "Microsoft.AspNet.Server.Kestrel" - }); + var mergedArgs = new[] { "--server", "Microsoft.AspNet.Server.Kestrel" }.Concat(args).ToArray(); + Microsoft.AspNet.Hosting.Program.Main(mergedArgs); } } } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Program.cs b/src/Microsoft.AspNet.Server.Kestrel/Program.cs index ba7e264f8f..b0f18d7c30 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Program.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Program.cs @@ -8,18 +8,10 @@ namespace Microsoft.AspNet.Server.Kestrel { public class Program { - private readonly IServiceProvider _serviceProvider; - - public Program(IServiceProvider serviceProvider) + public static void Main(string[] args) { - _serviceProvider = serviceProvider; - } - - public void Main(string[] args) - { - var program = new Microsoft.AspNet.Hosting.Program(_serviceProvider); var mergedArgs = new[] { "--server", "Microsoft.AspNet.Server.Kestrel" }.Concat(args).ToArray(); - program.Main(mergedArgs); + Microsoft.AspNet.Hosting.Program.Main(mergedArgs); } } } diff --git a/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs b/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs index b7b7b03877..cdc09c4c8b 100644 --- a/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs +++ b/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs @@ -26,7 +26,7 @@ namespace Microsoft.AspNet.Server.Kestrel.FunctionalTests }) .Build(); - var hostBuilder = new WebHostBuilder(CallContextServiceLocator.Locator.ServiceProvider, config); + var hostBuilder = new WebHostBuilder(config); hostBuilder.UseServer("Microsoft.AspNet.Server.Kestrel"); hostBuilder.UseStartup(ConfigureEchoAddress); diff --git a/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/RequestTests.cs b/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/RequestTests.cs index a9996ecb9a..6d8b13bfb6 100644 --- a/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/RequestTests.cs +++ b/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/RequestTests.cs @@ -26,7 +26,7 @@ namespace Microsoft.AspNet.Server.Kestrel.FunctionalTests }) .Build(); - var hostBuilder = new WebHostBuilder(CallContextServiceLocator.Locator.ServiceProvider, config); + var hostBuilder = new WebHostBuilder(config); hostBuilder.UseServer("Microsoft.AspNet.Server.Kestrel"); hostBuilder.UseStartup(app => { diff --git a/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/ResponseTests.cs b/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/ResponseTests.cs index a31c2374fa..75506aa39f 100644 --- a/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/ResponseTests.cs +++ b/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/ResponseTests.cs @@ -24,7 +24,7 @@ namespace Microsoft.AspNet.Server.Kestrel.FunctionalTests }) .Build(); - var hostBuilder = new WebHostBuilder(CallContextServiceLocator.Locator.ServiceProvider, config); + var hostBuilder = new WebHostBuilder(config); hostBuilder.UseServer("Microsoft.AspNet.Server.Kestrel"); hostBuilder.UseStartup(app => { diff --git a/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/ThreadCountTests.cs b/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/ThreadCountTests.cs index d47679f540..b928d19075 100644 --- a/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/ThreadCountTests.cs +++ b/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/ThreadCountTests.cs @@ -26,7 +26,7 @@ namespace Microsoft.AspNet.Server.Kestrel.FunctionalTests }) .Build(); - var hostBuilder = new WebHostBuilder(CallContextServiceLocator.Locator.ServiceProvider, config); + var hostBuilder = new WebHostBuilder(config); hostBuilder.UseServer("Microsoft.AspNet.Server.Kestrel"); hostBuilder.UseStartup(app => { From e3ceeb43ba6740e986c2a7ffe079261554dff752 Mon Sep 17 00:00:00 2001 From: Pavel Krymets Date: Wed, 21 Oct 2015 10:36:02 -0700 Subject: [PATCH 0363/1662] Fix build --- samples/SampleApp/Program.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/samples/SampleApp/Program.cs b/samples/SampleApp/Program.cs index 06205db078..16e2d1f487 100644 --- a/samples/SampleApp/Program.cs +++ b/samples/SampleApp/Program.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Linq; namespace SampleApp { From 8d107b22aecc03785814643ef82b61233ff9196b Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Mon, 19 Oct 2015 16:07:30 -0700 Subject: [PATCH 0364/1662] Socket.Disconnect throws a PlatformNotSupportedException on coreclr/linux #266 --- test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs index 3aa7ca2105..4bde4179f6 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs @@ -395,7 +395,6 @@ namespace Microsoft.AspNet.Server.KestrelTests var socket = new Socket(SocketType.Stream, ProtocolType.IP); socket.Connect(IPAddress.Loopback, 54321); await Task.Delay(200); - socket.Disconnect(false); socket.Dispose(); await Task.Delay(200); From a1e4e022b9550c04d5945159aad16c2ccb0b0729 Mon Sep 17 00:00:00 2001 From: Troy Dai Date: Thu, 15 Oct 2015 14:51:55 -0700 Subject: [PATCH 0365/1662] Clean up --- src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs | 1 - src/Microsoft.AspNet.Server.Kestrel/Http/ConnectionContext.cs | 1 - src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs | 2 +- src/Microsoft.AspNet.Server.Kestrel/Http/ListenerContext.cs | 1 - src/Microsoft.AspNet.Server.Kestrel/Http/TcpListener.cs | 2 -- .../Infrastructure/MemoryPoolBlock2.cs | 1 - 6 files changed, 1 insertion(+), 7 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs index f5a7033795..906faa9861 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs @@ -3,7 +3,6 @@ using System; using System.Threading; -using System.Threading.Tasks; using Microsoft.AspNet.Server.Kestrel.Filter; using Microsoft.AspNet.Server.Kestrel.Infrastructure; using Microsoft.AspNet.Server.Kestrel.Networking; diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/ConnectionContext.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/ConnectionContext.cs index 85ac78591b..4720aa40e5 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/ConnectionContext.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/ConnectionContext.cs @@ -22,7 +22,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Http public SocketInput SocketInput { get; set; } public ISocketOutput SocketOutput { get; set; } - public IConnectionControl ConnectionControl { get; set; } } } \ No newline at end of file diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs index 8c7e2b6c05..8cfba60cd0 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs @@ -1,9 +1,9 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using Microsoft.AspNet.Server.Kestrel.Networking; using System; using System.Threading.Tasks; +using Microsoft.AspNet.Server.Kestrel.Networking; using Microsoft.Extensions.Logging; namespace Microsoft.AspNet.Server.Kestrel.Http diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerContext.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerContext.cs index 9e5a8e50ed..79a096d4d4 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerContext.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerContext.cs @@ -3,7 +3,6 @@ using System; using System.Threading.Tasks; -using Microsoft.AspNet.Server.Kestrel.Filter; using Microsoft.AspNet.Server.Kestrel.Infrastructure; namespace Microsoft.AspNet.Server.Kestrel.Http diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/TcpListener.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/TcpListener.cs index d3af771f5d..86feca412b 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/TcpListener.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/TcpListener.cs @@ -1,8 +1,6 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System; -using System.Net; using Microsoft.AspNet.Server.Kestrel.Infrastructure; using Microsoft.AspNet.Server.Kestrel.Networking; using Microsoft.Extensions.Logging; diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolBlock2.cs b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolBlock2.cs index 6e7aadfa26..a93e03186d 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolBlock2.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolBlock2.cs @@ -66,7 +66,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure /// public int End { get; set; } - /// /// Reference to the next block of data when the overall "active" bytes spans multiple blocks. At the point when the block is /// leased Next is guaranteed to be null. Start, End, and Next are used together in order to create a linked-list of discontiguous From dea782163d858b506e700c521455821aed3d5f0c Mon Sep 17 00:00:00 2001 From: Pranav K Date: Thu, 22 Oct 2015 14:48:42 -0700 Subject: [PATCH 0366/1662] Updating packages to use generations --- .../project.json | 28 +++++----- .../Http/FrameDuplexStream.cs | 8 +-- .../Http/FrameRequestStream.cs | 2 +- .../Infrastructure/KestrelThread.cs | 2 +- .../Networking/PlatformApis.cs | 2 +- .../project.json | 27 ++++++++-- tools/Microsoft.StandardsPolice/project.json | 54 +++++++++++-------- 7 files changed, 78 insertions(+), 45 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel.Https/project.json b/src/Microsoft.AspNet.Server.Kestrel.Https/project.json index 2fc29ec1db..2e29e1ac44 100644 --- a/src/Microsoft.AspNet.Server.Kestrel.Https/project.json +++ b/src/Microsoft.AspNet.Server.Kestrel.Https/project.json @@ -1,14 +1,14 @@ -{ - "version": "1.0.0-*", - "description": "Adds HTTPS support to Kestrel", - "repository": { - "type": "git", - "url": "git://github.com/aspnet/kestrelhttpserver" - }, - "dependencies": { - "Microsoft.AspNet.Server.Kestrel": "1.0.0-*" - }, - "frameworks": { - "dnx451": { } - } -} +{ + "version": "1.0.0-*", + "description": "Adds HTTPS support to Kestrel", + "repository": { + "type": "git", + "url": "git://github.com/aspnet/kestrelhttpserver" + }, + "dependencies": { + "Microsoft.AspNet.Server.Kestrel": "1.0.0-*" + }, + "frameworks": { + "net451": { } + } +} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameDuplexStream.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameDuplexStream.cs index 40e860f20e..d421be7e0d 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameDuplexStream.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameDuplexStream.cs @@ -1,7 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -#if DNX451 +#if NET451 using System; #endif using System.IO; @@ -97,7 +97,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } -#if DNX451 +#if NET451 public override void Close() { _requestStream.Close(); @@ -124,7 +124,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return _responseStream.FlushAsync(cancellationToken); } -#if DNX451 +#if NET451 public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback callback, object state) { return _requestStream.BeginRead(buffer, offset, count, callback, state); @@ -146,7 +146,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return _requestStream.CopyToAsync(destination, bufferSize, cancellationToken); } -#if DNX451 +#if NET451 public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback callback, object state) { return _responseStream.BeginWrite(buffer, offset, count, callback, state); diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameRequestStream.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameRequestStream.cs index 3bf79ca3cc..714728dd43 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameRequestStream.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameRequestStream.cs @@ -53,7 +53,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return ReadAsync(buffer, offset, count).Result; } -#if DNX451 +#if NET451 public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback callback, object state) { var task = ReadAsync(buffer, offset, count, CancellationToken.None, state); diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs index 69281fddae..6c26ec71b1 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs @@ -67,7 +67,7 @@ namespace Microsoft.AspNet.Server.Kestrel Post(OnStopImmediate, null); if (!_thread.Join((int)timeout.TotalMilliseconds)) { -#if DNX451 +#if NET451 _thread.Abort(); #endif } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/PlatformApis.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/PlatformApis.cs index b2e34c5aeb..7b13ccdd9c 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/PlatformApis.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/PlatformApis.cs @@ -10,7 +10,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking { public static bool IsWindows() { -#if DNXCORE50 +#if DOTNET5_4 || DNXCORE50 // Until Environment.OSVersion.Platform is exposed on .NET Core, we // try to call uname and if that fails we assume we are on Windows. return GetUname() == string.Empty; diff --git a/src/Microsoft.AspNet.Server.Kestrel/project.json b/src/Microsoft.AspNet.Server.Kestrel/project.json index f726255872..24e5f01b8f 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/project.json +++ b/src/Microsoft.AspNet.Server.Kestrel/project.json @@ -16,7 +16,7 @@ }, "Microsoft.AspNet.Internal.libuv-Darwin": { "version": "1.0.0-*", - "type":"build" + "type": "build" }, "Microsoft.AspNet.Internal.libuv-Windows": { "version": "1.0.0-*", @@ -25,6 +25,7 @@ }, "frameworks": { "dnx451": { }, + "net451": { }, "dnxcore50": { "dependencies": { "System.Collections": "4.0.11-beta-*", @@ -44,6 +45,26 @@ "System.Threading.ThreadPool": "4.0.10-beta-*", "System.Threading.Timer": "4.0.1-beta-*" } + }, + "dotnet5.4": { + "dependencies": { + "System.Collections": "4.0.11-beta-*", + "System.Diagnostics.Debug": "4.0.11-beta-*", + "System.Diagnostics.TraceSource": "4.0.0-beta-*", + "System.Diagnostics.Tracing": "4.0.21-beta-*", + "System.Globalization": "4.0.11-beta-*", + "System.IO": "4.0.11-beta-*", + "System.Linq": "4.0.1-beta-*", + "System.Net.Primitives": "4.0.11-beta-*", + "System.Runtime.Extensions": "4.0.11-beta-*", + "System.Runtime.InteropServices": "4.0.21-beta-*", + "System.Text.Encoding": "4.0.11-beta-*", + "System.Threading": "4.0.11-beta-*", + "System.Threading.Tasks": "4.0.11-beta-*", + "System.Threading.Thread": "4.0.0-beta-*", + "System.Threading.ThreadPool": "4.0.10-beta-*", + "System.Threading.Timer": "4.0.1-beta-*" + } } }, "compilationOptions": { @@ -64,6 +85,6 @@ "runtimes/win7-x64/native/": "runtimes/win7-x64/native/*", "runtimes/win7-x86/native/": "runtimes/win7-x86/native/*", "runtimes/win10-arm/native/": "runtimes/win10-arm/native/*", - "runtimes/osx/native/": "runtimes/osx/native/*" + "runtimes/osx/native/": "runtimes/osx/native/*" } -} +} \ No newline at end of file diff --git a/tools/Microsoft.StandardsPolice/project.json b/tools/Microsoft.StandardsPolice/project.json index 0129749b3f..63a14295ff 100644 --- a/tools/Microsoft.StandardsPolice/project.json +++ b/tools/Microsoft.StandardsPolice/project.json @@ -1,28 +1,40 @@ { - "version": "1.0.0-*", + "version": "1.0.0-*", - "description": "Microsoft.StandardsPolice Class Library", + "description": "Microsoft.StandardsPolice Class Library", - "dependencies": { - "Microsoft.Dnx.Compilation.CSharp.Abstractions": "1.0.0-*" + "dependencies": { + "Microsoft.Dnx.Compilation.CSharp.Abstractions": "1.0.0-*" + }, + + "commands": { + "Microsoft.StandardsPolice": "Microsoft.StandardsPolice" + }, + + "frameworks": { + "net451": { + "frameworkAssemblies": { + "System.Runtime": "", + "System.Text.Encoding": "", + "System.Threading.Tasks": "" + } }, - - "commands": { - "Microsoft.StandardsPolice": "Microsoft.StandardsPolice" + "dnx451": { + "frameworkAssemblies": { + "System.Runtime": "", + "System.Text.Encoding": "", + "System.Threading.Tasks": "" + } }, - - "frameworks": { - "dnx451": { - "frameworkAssemblies": { - "System.Runtime": "", - "System.Text.Encoding": "", - "System.Threading.Tasks": "" - } - }, - "dnxcore50": { - "dependencies": { - "System.Console": "4.0.0-beta-*" - } - } + "dotnet5.4": { + "dependencies": { + "System.Console": "4.0.0-beta-*" + } + }, + "dnxcore50": { + "dependencies": { + "System.Console": "4.0.0-beta-*" + } } + } } From 2963488cd9cef3aa28f81ca23adfa3eb795da11f Mon Sep 17 00:00:00 2001 From: Pranav K Date: Thu, 22 Oct 2015 16:03:44 -0700 Subject: [PATCH 0367/1662] Removign Roslyn and CoreCLR feeds --- NuGet.config | 2 -- 1 file changed, 2 deletions(-) diff --git a/NuGet.config b/NuGet.config index 0e465ebc1e..03704957e8 100644 --- a/NuGet.config +++ b/NuGet.config @@ -2,8 +2,6 @@ - - \ No newline at end of file From eb2c3a1ce87f4636addc0d13f6c3389dd4a8e073 Mon Sep 17 00:00:00 2001 From: Pavel Krymets Date: Thu, 22 Oct 2015 17:31:24 -0700 Subject: [PATCH 0368/1662] Rename Microsoft.Runtime.Abstractions to Microsoft.Extensions.PlatformAbstractions --- src/Microsoft.AspNet.Server.Kestrel/KestrelEngine.cs | 2 +- src/Microsoft.AspNet.Server.Kestrel/ServerFactory.cs | 2 +- src/Microsoft.AspNet.Server.Kestrel/project.json | 2 +- .../EngineTests.cs | 3 +-- .../MultipleLoopTests.cs | 3 +-- .../NetworkingTests.cs | 3 +-- test/Microsoft.AspNet.Server.KestrelTests/Program.cs | 2 +- .../TestServer.cs | 3 +-- .../Program.cs | 12 +++--------- .../project.json | 2 +- 10 files changed, 12 insertions(+), 22 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/KestrelEngine.cs b/src/Microsoft.AspNet.Server.Kestrel/KestrelEngine.cs index dec15232f7..9a68cd9df3 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/KestrelEngine.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/KestrelEngine.cs @@ -9,7 +9,7 @@ using Microsoft.AspNet.Http.Features; using Microsoft.AspNet.Server.Kestrel.Http; using Microsoft.AspNet.Server.Kestrel.Infrastructure; using Microsoft.AspNet.Server.Kestrel.Networking; -using Microsoft.Dnx.Runtime; +using Microsoft.Extensions.PlatformAbstractions; using Microsoft.Extensions.Logging; namespace Microsoft.AspNet.Server.Kestrel diff --git a/src/Microsoft.AspNet.Server.Kestrel/ServerFactory.cs b/src/Microsoft.AspNet.Server.Kestrel/ServerFactory.cs index f39bff2a27..e801749a87 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/ServerFactory.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/ServerFactory.cs @@ -9,9 +9,9 @@ using Microsoft.AspNet.Hosting.Server; using Microsoft.AspNet.Http.Features; using Microsoft.AspNet.Server.Features; using Microsoft.AspNet.Server.Kestrel.Http; -using Microsoft.Dnx.Runtime; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Logging; +using Microsoft.Extensions.PlatformAbstractions; namespace Microsoft.AspNet.Server.Kestrel { diff --git a/src/Microsoft.AspNet.Server.Kestrel/project.json b/src/Microsoft.AspNet.Server.Kestrel/project.json index 24e5f01b8f..d9a6da0f42 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/project.json +++ b/src/Microsoft.AspNet.Server.Kestrel/project.json @@ -7,7 +7,7 @@ }, "dependencies": { "Microsoft.AspNet.Hosting": "1.0.0-*", - "Microsoft.Dnx.Runtime.Abstractions": "1.0.0-*", + "Microsoft.Extensions.PlatformAbstractions": "1.0.0-*", "Microsoft.Extensions.Logging.Abstractions": "1.0.0-*", "System.Numerics.Vectors": "4.1.1-beta-*", "Microsoft.StandardsPolice": { diff --git a/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs index 4bde4179f6..633c131c53 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs @@ -10,8 +10,7 @@ using System.Threading.Tasks; using Microsoft.AspNet.Http.Features; using Microsoft.AspNet.Server.Kestrel; using Microsoft.AspNet.Server.Kestrel.Filter; -using Microsoft.Dnx.Runtime; -using Microsoft.Dnx.Runtime.Infrastructure; +using Microsoft.Extensions.PlatformAbstractions; using Microsoft.Extensions.Logging; using Xunit; diff --git a/test/Microsoft.AspNet.Server.KestrelTests/MultipleLoopTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/MultipleLoopTests.cs index ddbecbd06d..cb870ea144 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/MultipleLoopTests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/MultipleLoopTests.cs @@ -6,8 +6,7 @@ using System.Threading; using Microsoft.AspNet.Server.Kestrel; using Microsoft.AspNet.Server.Kestrel.Infrastructure; using Microsoft.AspNet.Server.Kestrel.Networking; -using Microsoft.Dnx.Runtime; -using Microsoft.Dnx.Runtime.Infrastructure; +using Microsoft.Extensions.PlatformAbstractions; using Xunit; namespace Microsoft.AspNet.Server.KestrelTests diff --git a/test/Microsoft.AspNet.Server.KestrelTests/NetworkingTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/NetworkingTests.cs index 363cb1ea4d..aea3274475 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/NetworkingTests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/NetworkingTests.cs @@ -9,8 +9,7 @@ using System.Threading.Tasks; using Microsoft.AspNet.Server.Kestrel; using Microsoft.AspNet.Server.Kestrel.Infrastructure; using Microsoft.AspNet.Server.Kestrel.Networking; -using Microsoft.Dnx.Runtime; -using Microsoft.Dnx.Runtime.Infrastructure; +using Microsoft.Extensions.PlatformAbstractions; using Xunit; namespace Microsoft.AspNet.Server.KestrelTests diff --git a/test/Microsoft.AspNet.Server.KestrelTests/Program.cs b/test/Microsoft.AspNet.Server.KestrelTests/Program.cs index 858790c686..83dbb72393 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/Program.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/Program.cs @@ -2,7 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using Microsoft.Dnx.Runtime; +using Microsoft.Extensions.PlatformAbstractions; namespace Microsoft.AspNet.Server.KestrelTests { diff --git a/test/Microsoft.AspNet.Server.KestrelTests/TestServer.cs b/test/Microsoft.AspNet.Server.KestrelTests/TestServer.cs index d47238341d..698b7a1d57 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/TestServer.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/TestServer.cs @@ -5,8 +5,7 @@ using System; using System.Threading.Tasks; using Microsoft.AspNet.Server.Kestrel; using Microsoft.AspNet.Server.Kestrel.Http; -using Microsoft.Dnx.Runtime; -using Microsoft.Dnx.Runtime.Infrastructure; +using Microsoft.Extensions.PlatformAbstractions; using Microsoft.AspNet.Http.Features; namespace Microsoft.AspNet.Server.KestrelTests diff --git a/tools/Microsoft.AspNet.Server.Kestrel.LibuvCopier/Program.cs b/tools/Microsoft.AspNet.Server.Kestrel.LibuvCopier/Program.cs index 3904cfc2ed..0226bbde54 100644 --- a/tools/Microsoft.AspNet.Server.Kestrel.LibuvCopier/Program.cs +++ b/tools/Microsoft.AspNet.Server.Kestrel.LibuvCopier/Program.cs @@ -1,20 +1,13 @@ using System; using System.IO; using System.Linq; -using Microsoft.Dnx.Runtime; +using Microsoft.Extensions.PlatformAbstractions; using Newtonsoft.Json.Linq; namespace Microsoft.AspNet.Server.Kestrel.LibuvCopier { public class Program { - private readonly IRuntimeEnvironment _runtimeEnv; - - public Program(IRuntimeEnvironment runtimeEnv) - { - _runtimeEnv = runtimeEnv; - } - public void Main(string[] args) { try @@ -74,7 +67,8 @@ namespace Microsoft.AspNet.Server.Kestrel.LibuvCopier #if DNX451 return Environment.GetFolderPath(Environment.SpecialFolder.UserProfile); #else - if (_runtimeEnv.OperatingSystem == "Windows") + var runtimeEnv = PlatformServices.Default.Runtime; + if (runtimeEnv.OperatingSystem == "Windows") { return Environment.GetEnvironmentVariable("USERPROFILE") ?? Environment.GetEnvironmentVariable("HOMEDRIVE") + Environment.GetEnvironmentVariable("HOMEPATH"); diff --git a/tools/Microsoft.AspNet.Server.Kestrel.LibuvCopier/project.json b/tools/Microsoft.AspNet.Server.Kestrel.LibuvCopier/project.json index 681bfd77ee..373002bafb 100644 --- a/tools/Microsoft.AspNet.Server.Kestrel.LibuvCopier/project.json +++ b/tools/Microsoft.AspNet.Server.Kestrel.LibuvCopier/project.json @@ -7,7 +7,7 @@ "licenseUrl": "", "dependencies": { - "Microsoft.Dnx.Runtime.Abstractions": "1.0.0-*", + "Microsoft.Extensions.PlatformAbstractions": "1.0.0-*", "Newtonsoft.Json": "7.0.1" }, From 151b0f3a16f76f5b92db0f83a932963c092d577b Mon Sep 17 00:00:00 2001 From: David Fowler Date: Fri, 23 Oct 2015 01:50:35 -0700 Subject: [PATCH 0369/1662] Fixed remaining namespace changes --- samples/SampleApp/Startup.cs | 2 +- .../AddressRegistrationTests.cs | 1 - .../RequestTests.cs | 1 - .../ResponseTests.cs | 1 - .../ThreadCountTests.cs | 1 - 5 files changed, 1 insertion(+), 5 deletions(-) diff --git a/samples/SampleApp/Startup.cs b/samples/SampleApp/Startup.cs index 7b863a5624..fb6c8e9a2b 100644 --- a/samples/SampleApp/Startup.cs +++ b/samples/SampleApp/Startup.cs @@ -6,7 +6,7 @@ using Microsoft.AspNet.Builder; using Microsoft.AspNet.Http; using Microsoft.AspNet.Http.Features; using Microsoft.AspNet.Server.Kestrel; -using Microsoft.Dnx.Runtime; +using Microsoft.Extensions.PlatformAbstractions; using Microsoft.Extensions.Logging; #if DNX451 diff --git a/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs b/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs index cdc09c4c8b..cabb74761b 100644 --- a/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs +++ b/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs @@ -8,7 +8,6 @@ using Microsoft.AspNet.Builder; using Microsoft.AspNet.Hosting; using Microsoft.AspNet.Http; using Microsoft.AspNet.Http.Extensions; -using Microsoft.Dnx.Runtime.Infrastructure; using Microsoft.Extensions.Configuration; using Xunit; diff --git a/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/RequestTests.cs b/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/RequestTests.cs index 6d8b13bfb6..ab6159cffd 100644 --- a/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/RequestTests.cs +++ b/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/RequestTests.cs @@ -8,7 +8,6 @@ using System.Threading.Tasks; using Microsoft.AspNet.Builder; using Microsoft.AspNet.Hosting; using Microsoft.AspNet.Http; -using Microsoft.Dnx.Runtime.Infrastructure; using Microsoft.Extensions.Configuration; using Xunit; diff --git a/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/ResponseTests.cs b/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/ResponseTests.cs index 75506aa39f..54216dcdb8 100644 --- a/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/ResponseTests.cs +++ b/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/ResponseTests.cs @@ -6,7 +6,6 @@ using System.Net.Http; using System.Threading.Tasks; using Microsoft.AspNet.Builder; using Microsoft.AspNet.Hosting; -using Microsoft.Dnx.Runtime.Infrastructure; using Microsoft.Extensions.Configuration; using Xunit; diff --git a/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/ThreadCountTests.cs b/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/ThreadCountTests.cs index b928d19075..dabe7c4abe 100644 --- a/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/ThreadCountTests.cs +++ b/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/ThreadCountTests.cs @@ -8,7 +8,6 @@ using Microsoft.AspNet.Builder; using Microsoft.AspNet.Hosting; using Microsoft.AspNet.Http; using Microsoft.AspNet.Http.Features; -using Microsoft.Dnx.Runtime.Infrastructure; using Microsoft.Extensions.Configuration; using Xunit; From f88631efb3055eeefeac1af27574499619b7461b Mon Sep 17 00:00:00 2001 From: Ryan Nowak Date: Fri, 23 Oct 2015 15:05:09 -0700 Subject: [PATCH 0370/1662] React to breaking changes in StringValues --- src/Microsoft.AspNet.Server.Kestrel/Http/FrameHeaders.cs | 4 ++-- src/Microsoft.AspNet.Server.Kestrel/Http/MessageBody.cs | 2 +- .../FrameRequestHeadersTests.cs | 4 ++-- test/Microsoft.AspNet.Server.KestrelTests/Program.cs | 7 ++----- 4 files changed, 7 insertions(+), 10 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameHeaders.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameHeaders.cs index beb926447c..a97a092098 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameHeaders.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameHeaders.cs @@ -123,7 +123,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http StringValues value; return TryGetValueFast(item.Key, out value) && - object.Equals(value, item.Value); + value.Equals(item.Value); } bool IDictionary.ContainsKey(string key) @@ -152,7 +152,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http StringValues value; return TryGetValueFast(item.Key, out value) && - object.Equals(value, item.Value) && + value.Equals(item.Value) && RemoveFast(item.Key); } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/MessageBody.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/MessageBody.cs index c6afad0e77..3b20247e67 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/MessageBody.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/MessageBody.cs @@ -78,7 +78,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http public static bool TryGet(IDictionary headers, string name, out string value) { StringValues values; - if (!headers.TryGetValue(name, out values) || values == null) + if (!headers.TryGetValue(name, out values) || values.Count == 0) { value = null; return false; diff --git a/test/Microsoft.AspNet.Server.KestrelTests/FrameRequestHeadersTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/FrameRequestHeadersTests.cs index 24152ca199..302eebcf29 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/FrameRequestHeadersTests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/FrameRequestHeadersTests.cs @@ -121,8 +121,8 @@ namespace Microsoft.AspNet.Server.KestrelTests IDictionary headers = new FrameRequestHeaders(); var kv1 = new KeyValuePair("host", new[] { "localhost" }); var kv2 = new KeyValuePair("custom", new[] { "value" }); - var kv1b = new KeyValuePair("host", new[] { "localhost" }); - var kv2b = new KeyValuePair("custom", new[] { "value" }); + var kv1b = new KeyValuePair("host", new[] { "not-localhost" }); + var kv2b = new KeyValuePair("custom", new[] { "not-value" }); Assert.False(headers.ContainsKey("host")); Assert.False(headers.ContainsKey("custom")); diff --git a/test/Microsoft.AspNet.Server.KestrelTests/Program.cs b/test/Microsoft.AspNet.Server.KestrelTests/Program.cs index 83dbb72393..813a581bf1 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/Program.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/Program.cs @@ -14,23 +14,20 @@ namespace Microsoft.AspNet.Server.KestrelTests private readonly IApplicationEnvironment env; private readonly IServiceProvider sp; private readonly ILibraryManager _libraryManager; - private readonly IApplicationShutdown _shutdown; public Program( IApplicationEnvironment env, IServiceProvider sp, - ILibraryManager libraryManager, - IApplicationShutdown shutown) + ILibraryManager libraryManager) { this.env = env; this.sp = sp; _libraryManager = libraryManager; - _shutdown = shutown; } public int Main() { - return new Xunit.Runner.Dnx.Program(env, sp, _libraryManager, _shutdown).Main(new string[] + return new Xunit.Runner.Dnx.Program(env, sp, _libraryManager).Main(new string[] { "-class", typeof(MultipleLoopTests).FullName From 52f4fa91e3f68c5f8a2e726432d85806024fd834 Mon Sep 17 00:00:00 2001 From: Troy Dai Date: Wed, 21 Oct 2015 14:52:14 -0700 Subject: [PATCH 0371/1662] Unescape string in memory 1. In place unescape; 1. UTF-8 verification; 2. MemoryPoolIterator2.Put 3. Tests --- .../Http/Frame.cs | 26 +- .../Http/UrlPathDecoder.cs | 306 ++++++++++++++++++ .../Infrastructure/MemoryPoolIterator2.cs | 170 +++++++++- .../MemoryPoolIterator2Tests.cs | 132 ++++++++ .../UrlPathDecoder.cs | 172 ++++++++++ 5 files changed, 796 insertions(+), 10 deletions(-) create mode 100644 src/Microsoft.AspNet.Server.Kestrel/Http/UrlPathDecoder.cs create mode 100644 test/Microsoft.AspNet.Server.KestrelTests/MemoryPoolIterator2Tests.cs create mode 100644 test/Microsoft.AspNet.Server.KestrelTests/UrlPathDecoder.cs diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs index 0d7b5ce6e5..79552ea944 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs @@ -420,8 +420,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http if (_responseStarted) return; await FireOnStarting(); - - if (_applicationException != null) + + if (_applicationException != null) { throw new ObjectDisposedException( "The response has been aborted due to an unhandled application exception.", @@ -591,12 +591,17 @@ namespace Microsoft.AspNet.Server.Kestrel.Http scan.Take(); begin = scan; - var chFound = scan.Seek(' ', '?'); - if (chFound == -1) + + var needDecode = false; + var chFound = scan.Seek(' ', '?', '%'); + if (chFound == '%') { - return false; + needDecode = true; + chFound = scan.Seek(' ', '?'); } - var requestUri = begin.GetString(scan); + + var pathBegin = begin; + var pathEnd = scan; var queryString = ""; if (chFound == '?') @@ -623,9 +628,16 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return false; } + if (needDecode) + { + pathEnd = UrlPathDecoder.Unescape(pathBegin, pathEnd); + } + + var requestUrlPath = pathBegin.GetString(pathEnd); + consumed = scan; Method = method; - RequestUri = requestUri; + RequestUri = requestUrlPath; QueryString = queryString; HttpVersion = httpVersion; Path = RequestUri; diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/UrlPathDecoder.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/UrlPathDecoder.cs new file mode 100644 index 0000000000..66608a4a22 --- /dev/null +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/UrlPathDecoder.cs @@ -0,0 +1,306 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using Microsoft.AspNet.Server.Kestrel.Infrastructure; + +namespace Microsoft.AspNet.Server.Kestrel.Http +{ + public class UrlPathDecoder + { + /// + /// Unescapes the string between given memory iterators in place. + /// + /// The iterator points to the beginning of the sequence. + /// The iterator points to the byte behind the end of the sequence. + /// The iterator points to the byte behind the end of the processed sequence. + public static MemoryPoolIterator2 Unescape(MemoryPoolIterator2 start, MemoryPoolIterator2 end) + { + // the slot to read the input + var reader = start; + + // the slot to write the unescaped byte + var writer = reader; + + while (true) + { + if (CompareIterators(ref reader, ref end)) + { + return writer; + } + + if (reader.Peek() == '%') + { + var decodeReader = reader; + + // If decoding process succeeds, the writer iterator will be moved + // to the next write-ready location. On the other hand if the scanned + // percent-encodings cannot be interpreted as sequence of UTF-8 octets, + // these bytes should be copied to output as is. + // The decodeReader iterator is always moved to the first byte not yet + // be scanned after the process. A failed decoding means the chars + // between the reader and decodeReader can be copied to output untouched. + if (!DecodeCore(ref decodeReader, ref writer, end)) + { + Copy(reader, decodeReader, ref writer); + } + + reader = decodeReader; + } + else + { + writer.Put((byte)reader.Take()); + } + } + } + + /// + /// Unescape the percent-encodings + /// + /// The iterator point to the first % char + /// The place to write to + /// The end of the sequence + private static bool DecodeCore(ref MemoryPoolIterator2 reader, ref MemoryPoolIterator2 writer, MemoryPoolIterator2 end) + { + // preserves the original head. if the percent-encodings cannot be interpreted as sequence of UTF-8 octets, + // bytes from this till the last scanned one will be copied to the memory pointed by writer. + var byte1 = UnescapePercentEncoding(ref reader, end); + if (byte1 == -1) + { + return false; + } + + if (byte1 <= 0x7F) + { + // first byte < U+007f, it is a single byte ASCII + writer.Put((byte)byte1); + return true; + } + + int byte2 = 0, byte3 = 0, byte4 = 0; + + // anticipate more bytes + var currentDecodeBits = 0; + var byteCount = 1; + var expectValueMin = 0; + if ((byte1 & 0xE0) == 0xC0) + { + // 110x xxxx, expect one more byte + currentDecodeBits = byte1 & 0x1F; + byteCount = 2; + expectValueMin = 0x80; + } + else if ((byte1 & 0xF0) == 0xE0) + { + // 1110 xxxx, expect two more bytes + currentDecodeBits = byte1 & 0x0F; + byteCount = 3; + expectValueMin = 0x800; + } + else if ((byte1 & 0xF8) == 0xF0) + { + // 1111 0xxx, expect three more bytes + currentDecodeBits = byte1 & 0x07; + byteCount = 4; + expectValueMin = 0x10000; + } + else + { + // invalid first byte + return false; + } + + var remainingBytes = byteCount - 1; + while (remainingBytes > 0) + { + // read following three chars + if (CompareIterators(ref reader, ref end)) + { + return false; + } + + var nextItr = reader; + var nextByte = UnescapePercentEncoding(ref nextItr, end); + if (nextByte == -1) + { + return false; + } + + if ((nextByte & 0xC0) != 0x80) + { + // the follow up byte is not in form of 10xx xxxx + return false; + } + + currentDecodeBits = (currentDecodeBits << 6) | (nextByte & 0x3F); + remainingBytes--; + + if (remainingBytes == 1 && currentDecodeBits >= 0x360 && currentDecodeBits <= 0x37F) + { + // this is going to end up in the range of 0xD800-0xDFFF UTF-16 surrogates that + // are not allowed in UTF-8; + return false; + } + + if (remainingBytes == 2 && currentDecodeBits >= 0x110) + { + // this is going to be out of the upper Unicode bound 0x10FFFF. + return false; + } + + reader = nextItr; + if (byteCount - remainingBytes == 2) + { + byte2 = nextByte; + } + else if (byteCount - remainingBytes == 3) + { + byte3 = nextByte; + } + else if (byteCount - remainingBytes == 4) + { + byte4 = nextByte; + } + } + + if (currentDecodeBits < expectValueMin) + { + // overlong encoding (e.g. using 2 bytes to encode something that only needed 1). + return false; + } + + // all bytes are verified, write to the output + if (byteCount > 0) + { + writer.Put((byte)byte1); + } + if (byteCount > 1) + { + writer.Put((byte)byte2); + } + if (byteCount > 2) + { + writer.Put((byte)byte3); + } + if (byteCount > 3) + { + writer.Put((byte)byte4); + } + + return true; + } + + private static void Copy(MemoryPoolIterator2 head, MemoryPoolIterator2 tail, ref MemoryPoolIterator2 writer) + { + while (!CompareIterators(ref head, ref tail)) + { + writer.Put((byte)head.Take()); + } + } + + /// + /// Read the percent-encoding and try unescape it. + /// + /// The operation first peek at the character the + /// iterator points at. If it is % the is then + /// moved on to scan the following to characters. If the two following + /// characters are hexadecimal literals they will be unescaped and the + /// value will be returned. + /// + /// If the first character is not % the iterator + /// will be removed beyond the location of % and -1 will be returned. + /// + /// If the following two characters can't be successfully unescaped the + /// iterator will be move behind the % and -1 + /// will be returned. + /// + /// The value to read + /// The end of the sequence + /// The unescaped byte if success. Otherwise return -1. + private static int UnescapePercentEncoding(ref MemoryPoolIterator2 scan, MemoryPoolIterator2 end) + { + if (scan.Take() != '%') + { + return -1; + } + + var probe = scan; + + int value1 = ReadHex(ref probe, end); + if (value1 == -1) + { + return -1; + } + + int value2 = ReadHex(ref probe, end); + if (value2 == -1) + { + return -1; + } + + if (SkipUnescape(value1, value2)) + { + return -1; + } + + scan = probe; + return (value1 << 4) + value2; + } + + /// + /// Read the next char and convert it into hexadecimal value. + /// + /// The iterator will be moved to the next + /// byte no matter no matter whether the operation successes. + /// + /// The value to read + /// The end of the sequence + /// The hexadecimal value if successes, otherwise -1. + private static int ReadHex(ref MemoryPoolIterator2 scan, MemoryPoolIterator2 end) + { + if (CompareIterators(ref scan, ref end)) + { + return -1; + } + + var value = scan.Take(); + var isHead = (((value >= '0') && (value <= '9')) || + ((value >= 'A') && (value <= 'F')) || + ((value >= 'a') && (value <= 'f'))); + + if (!isHead) + { + return -1; + } + + if (value <= '9') + { + return value - '0'; + } + else if (value <= 'F') + { + return (value - 'A') + 10; + } + else // a - f + { + return (value - 'a') + 10; + } + } + + private static bool SkipUnescape(int value1, int value2) + { + // skip %2F + if (value1 == 2 && value2 == 15) + { + return true; + } + + return false; + } + + private static bool CompareIterators(ref MemoryPoolIterator2 lhs, ref MemoryPoolIterator2 rhs) + { + // uses ref parameter to save cost of copying + return (lhs.Block == rhs.Block) && (lhs.Index == rhs.Index); + } + } +} diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolIterator2.cs b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolIterator2.cs index 8964093d03..7de5c7fb10 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolIterator2.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolIterator2.cs @@ -1,4 +1,7 @@ -using System; +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; using System.Linq; using System.Numerics; using System.Text; @@ -9,9 +12,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure { /// /// Array of "minus one" bytes of the length of SIMD operations on the current hardware. Used as an argument in the - /// vector dot product that counts matching character occurence. + /// vector dot product that counts matching character occurrence. /// - private static Vector _dotCount = new Vector(Byte.MaxValue); + private static Vector _dotCount = new Vector(Byte.MaxValue); /// /// Array of negative numbers starting at 0 and continuing for the length of SIMD operations on the current hardware. @@ -295,6 +298,167 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure } } + public int Seek(int char0, int char1, int char2) + { + if (IsDefault) + { + return -1; + } + + var byte0 = (byte)char0; + var byte1 = (byte)char1; + var byte2 = (byte)char2; + var vectorStride = Vector.Count; + var ch0Vector = new Vector(byte0); + var ch1Vector = new Vector(byte1); + var ch2Vector = new Vector(byte2); + + var block = _block; + var index = _index; + var array = block.Array; + while (true) + { + while (block.End == index) + { + if (block.Next == null) + { + _block = block; + _index = index; + return -1; + } + block = block.Next; + index = block.Start; + array = block.Array; + } + while (block.End != index) + { + var following = block.End - index; + if (following >= vectorStride) + { + var data = new Vector(array, index); + var ch0Equals = Vector.Equals(data, ch0Vector); + var ch0Count = Vector.Dot(ch0Equals, _dotCount); + var ch1Equals = Vector.Equals(data, ch1Vector); + var ch1Count = Vector.Dot(ch1Equals, _dotCount); + var ch2Equals = Vector.Equals(data, ch2Vector); + var ch2Count = Vector.Dot(ch2Equals, _dotCount); + + if (ch0Count == 0 && ch1Count == 0 && ch2Count == 0) + { + index += vectorStride; + continue; + } + else if (ch0Count < 2 && ch1Count < 2 && ch2Count < 2) + { + var ch0Index = ch0Count == 1 ? Vector.Dot(ch0Equals, _dotIndex) : byte.MaxValue; + var ch1Index = ch1Count == 1 ? Vector.Dot(ch1Equals, _dotIndex) : byte.MaxValue; + var ch2Index = ch2Count == 1 ? Vector.Dot(ch2Equals, _dotIndex) : byte.MaxValue; + + int toReturn, toMove; + if (ch0Index < ch1Index) + { + if (ch0Index < ch2Index) + { + toReturn = char0; + toMove = ch0Index; + } + else + { + toReturn = char2; + toMove = ch2Index; + } + } + else + { + if (ch1Index < ch2Index) + { + toReturn = char1; + toMove = ch1Index; + } + else + { + toReturn = char2; + toMove = ch2Index; + } + } + + _block = block; + _index = index + toMove; + return toReturn; + } + else + { + following = vectorStride; + } + } + while (following > 0) + { + var byteIndex = block.Array[index]; + if (byteIndex == byte0) + { + _block = block; + _index = index; + return char0; + } + else if (byteIndex == byte1) + { + _block = block; + _index = index; + return char1; + } + else if (byteIndex == byte2) + { + _block = block; + _index = index; + return char2; + } + following--; + index++; + } + } + } + } + + /// + /// Save the data at the current location then move to the next available space. + /// + /// The byte to be saved. + /// true if the operation successes. false if can't find available space. + public bool Put(byte data) + { + if (_block == null) + { + return false; + } + else if (_index < _block.End) + { + _block.Array[_index++] = data; + return true; + } + + var block = _block; + var index = _index; + while (true) + { + if (index < block.End) + { + _block = block; + _index = index + 1; + block.Array[index] = data; + return true; + } + else if (block.Next == null) + { + return false; + } + else + { + block = block.Next; + index = block.Start; + } + } + } + public int GetLength(MemoryPoolIterator2 end) { if (IsDefault || end.IsDefault) diff --git a/test/Microsoft.AspNet.Server.KestrelTests/MemoryPoolIterator2Tests.cs b/test/Microsoft.AspNet.Server.KestrelTests/MemoryPoolIterator2Tests.cs new file mode 100644 index 0000000000..b7d101c28c --- /dev/null +++ b/test/Microsoft.AspNet.Server.KestrelTests/MemoryPoolIterator2Tests.cs @@ -0,0 +1,132 @@ +using System; +using System.Linq; +using Microsoft.AspNet.Server.Kestrel.Infrastructure; +using Xunit; + +namespace Microsoft.AspNet.Server.KestrelTests +{ + public class MemoryPoolIterator2Tests : IDisposable + { + private readonly MemoryPool2 _pool; + + public MemoryPoolIterator2Tests() + { + _pool = new MemoryPool2(); + } + + public void Dispose() + { + _pool.Dispose(); + } + + [Theory] + [InlineData("a", "a", 'a', 0)] + [InlineData("ab", "a", 'a', 0)] + [InlineData("aab", "a", 'a', 0)] + [InlineData("acab", "a", 'a', 0)] + [InlineData("acab", "c", 'c', 1)] + [InlineData("abcdefghijklmnopqrstuvwxyz", "lo", 'l', 11)] + [InlineData("abcdefghijklmnopqrstuvwxyz", "ol", 'l', 11)] + [InlineData("abcdefghijklmnopqrstuvwxyz", "ll", 'l', 11)] + [InlineData("abcdefghijklmnopqrstuvwxyz", "lmr", 'l', 11)] + [InlineData("abcdefghijklmnopqrstuvwxyz", "rml", 'l', 11)] + [InlineData("abcdefghijklmnopqrstuvwxyz", "mlr", 'l', 11)] + [InlineData("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz", "lmr", 'l', 11)] + [InlineData("aaaaaaaaaaalmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz", "lmr", 'l', 11)] + [InlineData("aaaaaaaaaaacmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz", "lmr", 'm', 12)] + [InlineData("aaaaaaaaaaarmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz", "lmr", 'r', 11)] + [InlineData("/localhost:5000/PATH/%2FPATH2/ HTTP/1.1", " %?", '%', 21)] + [InlineData("/localhost:5000/PATH/%2FPATH2/?key=value HTTP/1.1", " %?", '%', 21)] + [InlineData("/localhost:5000/PATH/PATH2/?key=value HTTP/1.1", " %?", '?', 27)] + [InlineData("/localhost:5000/PATH/PATH2/ HTTP/1.1", " %?", ' ', 27)] + public void MemorySeek(string raw, string search, char expectResult, int expectIndex) + { + var block = _pool.Lease(256); + var chars = raw.ToCharArray().Select(c => (byte)c).ToArray(); + Buffer.BlockCopy(chars, 0, block.Array, block.Start, chars.Length); + block.End += chars.Length; + + var begin = block.GetIterator(); + var searchFor = search.ToCharArray(); + + int found = -1; + if (searchFor.Length == 1) + { + found = begin.Seek(searchFor[0]); + } + else if (searchFor.Length == 2) + { + found = begin.Seek(searchFor[0], searchFor[1]); + } + else if (searchFor.Length == 3) + { + found = begin.Seek(searchFor[0], searchFor[1], searchFor[2]); + } + else + { + Assert.False(true, "Invalid test sample."); + } + + Assert.Equal(expectResult, found); + Assert.Equal(expectIndex, begin.Index - block.Start); + } + + [Fact] + public void Put() + { + var blocks = new MemoryPoolBlock2[4]; + for (var i = 0; i < 4; ++i) + { + blocks[i] = _pool.Lease(16); + blocks[i].End += 16; + + for (var j = 0; j < blocks.Length; ++j) + { + blocks[i].Array[blocks[i].Start + j] = 0x00; + } + + if (i != 0) + { + blocks[i - 1].Next = blocks[i]; + } + } + + // put FF at first block's head + var head = blocks[0].GetIterator(); + Assert.True(head.Put(0xFF)); + + // data is put at correct position + Assert.Equal(0xFF, blocks[0].Array[blocks[0].Start]); + Assert.Equal(0x00, blocks[0].Array[blocks[0].Start + 1]); + + // iterator is moved to next byte after put + Assert.Equal(1, head.Index - blocks[0].Start); + + for (var i = 0; i < 14; ++i) + { + // move itr to the end of the block 0 + head.Take(); + } + + // write to the end of block 0 + Assert.True(head.Put(0xFE)); + Assert.Equal(0xFE, blocks[0].Array[blocks[0].End - 1]); + Assert.Equal(0x00, blocks[1].Array[blocks[1].Start]); + + // put data across the block link + Assert.True(head.Put(0xFD)); + Assert.Equal(0xFD, blocks[1].Array[blocks[1].Start]); + Assert.Equal(0x00, blocks[1].Array[blocks[1].Start + 1]); + + // paint every block + head = blocks[0].GetIterator(); + for (var i = 0; i < 64; ++i) + { + Assert.True(head.Put((byte)i), $"Fail to put data at {i}."); + } + + // Can't put anything by the end + Assert.False(head.Put(0xFF)); + } + } +} diff --git a/test/Microsoft.AspNet.Server.KestrelTests/UrlPathDecoder.cs b/test/Microsoft.AspNet.Server.KestrelTests/UrlPathDecoder.cs new file mode 100644 index 0000000000..928fc84a05 --- /dev/null +++ b/test/Microsoft.AspNet.Server.KestrelTests/UrlPathDecoder.cs @@ -0,0 +1,172 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Linq; +using Microsoft.AspNet.Server.Kestrel.Http; +using Microsoft.AspNet.Server.Kestrel.Infrastructure; +using Xunit; + +namespace Microsoft.AspNet.Server.KestrelTests +{ + public class UrlPathDecoderTests + { + + [Fact] + public void Empty() + { + PositiveAssert(string.Empty, string.Empty); + } + + [Fact] + public void WhiteSpace() + { + PositiveAssert(" ", " "); + } + + [Theory] + [InlineData("/foo/bar", "/foo/bar")] + [InlineData("/foo/BAR", "/foo/BAR")] + [InlineData("/foo/", "/foo/")] + [InlineData("/", "/")] + public void NormalCases(string raw, string expect) + { + PositiveAssert(raw, expect); + } + + [Theory] + [InlineData("%2F", "%2F")] + [InlineData("/foo%2Fbar", "/foo%2Fbar")] + [InlineData("/foo%2F%20bar", "/foo%2F bar")] + public void SkipForwardSlash(string raw, string expect) + { + PositiveAssert(raw, expect); + } + + [Theory] + [InlineData("%D0%A4", "Ф")] + [InlineData("%d0%a4", "Ф")] + [InlineData("%E0%A4%AD", "भ")] + [InlineData("%e0%A4%Ad", "भ")] + [InlineData("%F0%A4%AD%A2", "𤭢")] + [InlineData("%F0%a4%Ad%a2", "𤭢")] + [InlineData("%48%65%6C%6C%6F%20%57%6F%72%6C%64", "Hello World")] + [InlineData("%48%65%6C%6C%6F%2D%C2%B5%40%C3%9F%C3%B6%C3%A4%C3%BC%C3%A0%C3%A1", "Hello-µ@ßöäüàá")] + // Test the borderline cases of overlong UTF8. + [InlineData("%C2%80", "\u0080")] + [InlineData("%E0%A0%80", "\u0800")] + [InlineData("%F0%90%80%80", "\U00010000")] + [InlineData("%63", "c")] + [InlineData("%32", "2")] + [InlineData("%20", " ")] + public void ValidUTF8(string raw, string expect) + { + PositiveAssert(raw, expect); + } + + [Theory] + [InlineData("%C3%84ra%20Benetton", "Ära Benetton")] + [InlineData("%E6%88%91%E8%87%AA%E6%A8%AA%E5%88%80%E5%90%91%E5%A4%A9%E7%AC%91%E5%8E%BB%E7%95%99%E8%82%9D%E8%83%86%E4%B8%A4%E6%98%86%E4%BB%91", "我自横刀向天笑去留肝胆两昆仑")] + public void Internationalized(string raw, string expect) + { + PositiveAssert(raw, expect); + } + + [Theory] + // Overlong ASCII + [InlineData("%C0%A4", "%C0%A4")] + [InlineData("%C1%BF", "%C1%BF")] + [InlineData("%E0%80%AF", "%E0%80%AF")] + [InlineData("%E0%9F%BF", "%E0%9F%BF")] + [InlineData("%F0%80%80%AF", "%F0%80%80%AF")] + [InlineData("%F0%8F%8F%BF", "%F0%8F%8F%BF")] + // Incomplete + [InlineData("%", "%")] + [InlineData("%%", "%%")] + [InlineData("%A", "%A")] + [InlineData("%Y", "%Y")] + // Mixed + [InlineData("%%32", "%2")] + [InlineData("%%20", "% ")] + [InlineData("%C0%A4%32", "%C0%A42")] + [InlineData("%32%C0%A4%32", "2%C0%A42")] + [InlineData("%C0%32%A4", "%C02%A4")] + public void InvalidUTF8(string raw, string expect) + { + PositiveAssert(raw, expect); + } + + [Theory] + [InlineData("/foo%2Fbar", 10, "/foo%2Fbar", 10)] + [InlineData("/foo%2Fbar", 9, "/foo%2Fba", 9)] + [InlineData("/foo%2Fbar", 8, "/foo%2Fb", 8)] + [InlineData("%D0%A4", 6, "Ф", 1)] + [InlineData("%D0%A4", 5, "%D0%A", 5)] + [InlineData("%D0%A4", 4, "%D0%", 4)] + [InlineData("%D0%A4", 3, "%D0", 3)] + [InlineData("%D0%A4", 2, "%D", 2)] + [InlineData("%D0%A4", 1, "%", 1)] + [InlineData("%D0%A4", 0, "", 0)] + [InlineData("%C2%B5%40%C3%9F%C3%B6%C3%A4%C3%BC%C3%A0%C3%A1", 45, "µ@ßöäüàá", 8)] + [InlineData("%C2%B5%40%C3%9F%C3%B6%C3%A4%C3%BC%C3%A0%C3%A1", 44, "µ@ßöäüà%C3%A", 12)] + public void DecodeWithBoundary(string raw, int rawLength, string expect, int expectLength) + { + var begin = BuildSample(raw); + var end = GetIterator(begin, rawLength); + + var end2 = UrlPathDecoder.Unescape(begin, end); + var result = begin.GetString(end2); + + Assert.Equal(expectLength, result.Length); + Assert.Equal(expect, result); + } + + private MemoryPoolIterator2 BuildSample(string data) + { + var store = data.Select(c => (byte)c).ToArray(); + var mem = MemoryPoolBlock2.Create(new ArraySegment(store), IntPtr.Zero, null, null); + mem.End = store.Length; + + return mem.GetIterator(); + } + + private MemoryPoolIterator2 GetIterator(MemoryPoolIterator2 begin, int displacement) + { + var result = begin; + for (int i = 0; i < displacement; ++i) + { + result.Take(); + } + + return result; + } + + private void PositiveAssert(string raw, string expect) + { + var begin = BuildSample(raw); + var end = GetIterator(begin, raw.Length); + + var result = UrlPathDecoder.Unescape(begin, end); + Assert.Equal(expect, begin.GetString(result)); + } + + private void PositiveAssert(string raw) + { + var begin = BuildSample(raw); + var end = GetIterator(begin, raw.Length); + + var result = UrlPathDecoder.Unescape(begin, end); + Assert.NotEqual(raw.Length, begin.GetString(result).Length); + } + + private void NegativeAssert(string raw) + { + var begin = BuildSample(raw); + var end = GetIterator(begin, raw.Length); + + var resultEnd = UrlPathDecoder.Unescape(begin, end); + var result = begin.GetString(resultEnd); + Assert.Equal(raw, result); + } + } +} From 094b8efbf8b760fb3929e821e8eadc5f28d06727 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Wed, 21 Oct 2015 12:49:37 -0700 Subject: [PATCH 0372/1662] Properly handle headers with empty values --- .../Http/Frame.cs | 25 ++++++++++---- .../FrameTests.cs | 33 ++++++++++++++++++- 2 files changed, 51 insertions(+), 7 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs index 79552ea944..f05d250a4b 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs @@ -157,7 +157,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } - while (!terminated && !_requestProcessingStopping && !TakeMessageHeaders(SocketInput)) + while (!terminated && !_requestProcessingStopping && !TakeMessageHeaders(SocketInput, _requestHeaders)) { terminated = SocketInput.RemoteIntakeFin; if (!terminated) @@ -654,7 +654,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return Encoding.UTF8.GetString(range.Array, range.Offset + startIndex, endIndex - startIndex); } - private bool TakeMessageHeaders(SocketInput input) + public static bool TakeMessageHeaders(SocketInput input, FrameRequestHeaders requestHeaders) { var scan = input.ConsumingStart(); var consumed = scan; @@ -692,6 +692,22 @@ namespace Microsoft.AspNet.Server.Kestrel.Http chSecond == '\r' || chSecond == '\n') { + if (chSecond == '\r') + { + var scanAhead = scan; + var chAhead = scanAhead.Take(); + if (chAhead == '\n') + { + chAhead = scanAhead.Take(); + // If the "\r\n" isn't part of "linear whitespace", + // then this header has no value. + if (chAhead != ' ' && chAhead != '\t') + { + break; + } + } + } + beginValue = scan; chSecond = scan.Take(); } @@ -729,9 +745,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } var name = beginName.GetArraySegment(endName); -#if DEBUG - var nameString = beginName.GetString(endName); -#endif var value = beginValue.GetString(endValue); if (wrapping) { @@ -739,7 +752,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } consumed = scan; - _requestHeaders.Append(name.Array, name.Offset, name.Count, value); + requestHeaders.Append(name.Array, name.Offset, name.Count, value); break; } } diff --git a/test/Microsoft.AspNet.Server.KestrelTests/FrameTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/FrameTests.cs index ec73fcd3b2..8266a1c2e9 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/FrameTests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/FrameTests.cs @@ -1,9 +1,11 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using Microsoft.AspNet.Server.Kestrel.Http; +using System; using System.Linq; using System.Text; +using Microsoft.AspNet.Server.Kestrel.Http; +using Microsoft.AspNet.Server.Kestrel.Infrastructure; using Xunit; namespace Microsoft.AspNet.Server.KestrelTests @@ -34,5 +36,34 @@ namespace Microsoft.AspNet.Server.KestrelTests Assert.Equal(Encoding.ASCII.GetBytes(expected), beginChunkBytes.ToArray()); } + + [Theory] + [InlineData("Cookie: \r\n\r\n", 1)] + [InlineData("Cookie:\r\n\r\n", 1)] + [InlineData("Cookie:\r\n value\r\n\r\n", 1)] + [InlineData("Cookie\r\n", 0)] + [InlineData("Cookie: \r\nConnection: close\r\n\r\n", 2)] + [InlineData("Connection: close\r\nCookie: \r\n\r\n", 2)] + [InlineData("Connection: close\r\nCookie \r\n", 1)] + [InlineData("Connection:\r\n \r\nCookie \r\n", 1)] + public void EmptyHeaderValuesCanBeParsed(string rawHeaders, int numHeaders) + { + var socketInput = new SocketInput(new MemoryPool2()); + var headerCollection = new FrameRequestHeaders(); + + var headerArray = Encoding.ASCII.GetBytes(rawHeaders); + var inputBuffer = socketInput.IncomingStart(headerArray.Length); + Buffer.BlockCopy(headerArray, 0, inputBuffer.Data.Array, inputBuffer.Data.Offset, headerArray.Length); + socketInput.IncomingComplete(headerArray.Length, null); + + var success = Frame.TakeMessageHeaders(socketInput, headerCollection); + + Assert.True(success); + Assert.Equal(numHeaders, headerCollection.Count()); + + // Assert TakeMessageHeaders consumed all the input + var scan = socketInput.ConsumingStart(); + Assert.True(scan.IsEnd); + } } } From fb01ea39185c857dcf8230922a648e9b242427f3 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Wed, 21 Oct 2015 16:23:09 -0700 Subject: [PATCH 0373/1662] Consume the full request body when the app does not --- .../Http/Frame.cs | 3 ++ .../EngineTests.cs | 46 +++++++++++++++++++ 2 files changed, 49 insertions(+) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs index f05d250a4b..13546271e5 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs @@ -196,6 +196,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Http await FireOnCompleted(); await ProduceEnd(); + + // Finish reading the request body in case the app did not. + await RequestBody.CopyToAsync(Stream.Null); } terminated = !_keepAlive; diff --git a/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs index 633c131c53..c2d2ad06bb 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs @@ -876,6 +876,52 @@ namespace Microsoft.AspNet.Server.KestrelTests } } + [Theory] + [MemberData(nameof(ConnectionFilterData))] + public async Task RequestBodyIsConsumedAutomaticallyIfAppDoesntConsumeItFully(ServiceContext testContext) + { + using (var server = new TestServer(async frame => + { + var response = frame.Get(); + var request = frame.Get(); + + Assert.Equal("POST", request.Method); + + response.Headers.Clear(); + response.Headers["Content-Length"] = new[] { "11" }; + + await response.Body.WriteAsync(Encoding.ASCII.GetBytes("Hello World"), 0, 11); + }, testContext)) + { + using (var connection = new TestConnection()) + { + await connection.SendEnd( + "POST / HTTP/1.1", + "Content-Length: 5", + "", + "HelloPOST / HTTP/1.1", + "Transfer-Encoding: chunked", + "", + "C", "HelloChunked", "0", + "POST / HTTP/1.1", + "Content-Length: 7", + "", + "Goodbye"); + await connection.ReceiveEnd( + "HTTP/1.1 200 OK", + "Content-Length: 11", + "", + "Hello WorldHTTP/1.1 200 OK", + "Content-Length: 11", + "", + "Hello WorldHTTP/1.1 200 OK", + "Content-Length: 11", + "", + "Hello World"); + } + } + } + private class TestApplicationErrorLogger : ILogger { public int ApplicationErrorsLogged { get; set; } From d4853f9b7c31a28cecac8ac7e965f8f2f783c06b Mon Sep 17 00:00:00 2001 From: moozzyk Date: Wed, 21 Oct 2015 15:34:09 -0700 Subject: [PATCH 0374/1662] Switching to using the built-in loading of native libs --- .../KestrelEngine.cs | 47 +- .../Networking/Libuv.cs | 484 ++++++++++++------ .../Networking/PlatformApis.cs | 81 +-- .../Networking/UvLoopHandle.cs | 2 +- 4 files changed, 343 insertions(+), 271 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/KestrelEngine.cs b/src/Microsoft.AspNet.Server.Kestrel/KestrelEngine.cs index 9a68cd9df3..358a965843 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/KestrelEngine.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/KestrelEngine.cs @@ -3,14 +3,12 @@ using System; using System.Collections.Generic; -using System.IO; using System.Threading.Tasks; using Microsoft.AspNet.Http.Features; using Microsoft.AspNet.Server.Kestrel.Http; -using Microsoft.AspNet.Server.Kestrel.Infrastructure; using Microsoft.AspNet.Server.Kestrel.Networking; -using Microsoft.Extensions.PlatformAbstractions; using Microsoft.Extensions.Logging; +using Microsoft.Extensions.PlatformAbstractions; namespace Microsoft.AspNet.Server.Kestrel { @@ -20,45 +18,6 @@ namespace Microsoft.AspNet.Server.Kestrel : this(context) { Libuv = new Libuv(); - - var libraryPath = default(string); - - if (libraryManager != null) - { - var library = libraryManager.GetLibrary("Microsoft.AspNet.Server.Kestrel"); - libraryPath = library.Path; - if (library.Type == "Project") - { - libraryPath = Path.GetDirectoryName(libraryPath); - } - if (Libuv.IsWindows) - { - var architecture = IntPtr.Size == 4 - ? "x86" - : "x64"; - - libraryPath = Path.Combine( - libraryPath, - "runtimes", - "win7-" + architecture, - "native", - "libuv.dll"); - } - else if (Libuv.IsDarwin) - { - libraryPath = Path.Combine( - libraryPath, - "runtimes", - "osx", - "native", - "libuv.dylib"); - } - else - { - libraryPath = "libuv.so.1"; - } - } - Libuv.Load(libraryPath); } // For testing @@ -116,8 +75,8 @@ namespace Microsoft.AspNet.Server.Kestrel { if (single) { - var listener = usingPipes ? - (Listener) new PipeListener(this) : + var listener = usingPipes ? + (Listener) new PipeListener(this) : new TcpListener(this); listeners.Add(listener); listener.StartAsync(address, thread, application).Wait(); diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/Libuv.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/Libuv.cs index a94d954a07..2a1c9871c5 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/Libuv.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/Libuv.cs @@ -2,61 +2,104 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.Reflection; using System.Runtime.InteropServices; namespace Microsoft.AspNet.Server.Kestrel.Networking { public class Libuv { - public bool IsWindows; - public bool IsDarwin; - - public Func LoadLibrary; - public Func FreeLibrary; - public Func GetProcAddress; - public Libuv() { IsWindows = PlatformApis.IsWindows(); - if (!IsWindows) + + var isDarwinMono = +#if DNX451 + IsWindows ? false : PlatformApis.IsDarwin(); +#else + false; +#endif + + if (isDarwinMono) { - IsDarwin = PlatformApis.IsDarwin(); + _uv_loop_init = NativeDarwinMonoMethods.uv_loop_init; + _uv_loop_close = NativeDarwinMonoMethods.uv_loop_close; + _uv_run = NativeDarwinMonoMethods.uv_run; + _uv_stop = NativeDarwinMonoMethods.uv_stop; + _uv_ref = NativeDarwinMonoMethods.uv_ref; + _uv_unref = NativeDarwinMonoMethods.uv_unref; + _uv_close = NativeDarwinMonoMethods.uv_close; + _uv_async_init = NativeDarwinMonoMethods.uv_async_init; + _uv_async_send = NativeDarwinMonoMethods.uv_async_send; + _uv_tcp_init = NativeDarwinMonoMethods.uv_tcp_init; + _uv_tcp_bind = NativeDarwinMonoMethods.uv_tcp_bind; + _uv_tcp_open = NativeDarwinMonoMethods.uv_tcp_open; + _uv_tcp_nodelay = NativeDarwinMonoMethods.uv_tcp_nodelay; + _uv_pipe_init = NativeDarwinMonoMethods.uv_pipe_init; + _uv_pipe_bind = NativeDarwinMonoMethods.uv_pipe_bind; + _uv_listen = NativeDarwinMonoMethods.uv_listen; + _uv_accept = NativeDarwinMonoMethods.uv_accept; + _uv_pipe_connect = NativeDarwinMonoMethods.uv_pipe_connect; + _uv_pipe_pending_count = NativeDarwinMonoMethods.uv_pipe_pending_count; + _uv_read_start = NativeDarwinMonoMethods.uv_read_start; + _uv_read_stop = NativeDarwinMonoMethods.uv_read_stop; + _uv_try_write = NativeDarwinMonoMethods.uv_try_write; + unsafe + { + _uv_write = NativeDarwinMonoMethods.uv_write; + _uv_write2 = NativeDarwinMonoMethods.uv_write2; + } + _uv_shutdown = NativeDarwinMonoMethods.uv_shutdown; + _uv_err_name = NativeDarwinMonoMethods.uv_err_name; + _uv_strerror = NativeDarwinMonoMethods.uv_strerror; + _uv_loop_size = NativeDarwinMonoMethods.uv_loop_size; + _uv_handle_size = NativeDarwinMonoMethods.uv_handle_size; + _uv_req_size = NativeDarwinMonoMethods.uv_req_size; + _uv_ip4_addr = NativeDarwinMonoMethods.uv_ip4_addr; + _uv_ip6_addr = NativeDarwinMonoMethods.uv_ip6_addr; + _uv_walk = NativeDarwinMonoMethods.uv_walk; + } + else + { + _uv_loop_init = NativeMethods.uv_loop_init; + _uv_loop_close = NativeMethods.uv_loop_close; + _uv_run = NativeMethods.uv_run; + _uv_stop = NativeMethods.uv_stop; + _uv_ref = NativeMethods.uv_ref; + _uv_unref = NativeMethods.uv_unref; + _uv_close = NativeMethods.uv_close; + _uv_async_init = NativeMethods.uv_async_init; + _uv_async_send = NativeMethods.uv_async_send; + _uv_tcp_init = NativeMethods.uv_tcp_init; + _uv_tcp_bind = NativeMethods.uv_tcp_bind; + _uv_tcp_open = NativeMethods.uv_tcp_open; + _uv_tcp_nodelay = NativeMethods.uv_tcp_nodelay; + _uv_pipe_init = NativeMethods.uv_pipe_init; + _uv_pipe_bind = NativeMethods.uv_pipe_bind; + _uv_listen = NativeMethods.uv_listen; + _uv_accept = NativeMethods.uv_accept; + _uv_pipe_connect = NativeMethods.uv_pipe_connect; + _uv_pipe_pending_count = NativeMethods.uv_pipe_pending_count; + _uv_read_start = NativeMethods.uv_read_start; + _uv_read_stop = NativeMethods.uv_read_stop; + _uv_try_write = NativeMethods.uv_try_write; + unsafe + { + _uv_write = NativeMethods.uv_write; + _uv_write2 = NativeMethods.uv_write2; + } + _uv_shutdown = NativeMethods.uv_shutdown; + _uv_err_name = NativeMethods.uv_err_name; + _uv_strerror = NativeMethods.uv_strerror; + _uv_loop_size = NativeMethods.uv_loop_size; + _uv_handle_size = NativeMethods.uv_handle_size; + _uv_req_size = NativeMethods.uv_req_size; + _uv_ip4_addr = NativeMethods.uv_ip4_addr; + _uv_ip6_addr = NativeMethods.uv_ip6_addr; + _uv_walk = NativeMethods.uv_walk; } } - public void Load(string dllToLoad) - { - PlatformApis.Apply(this); - - var module = LoadLibrary(dllToLoad); - - if (module == IntPtr.Zero) - { - var message = "Unable to load libuv."; - if (!IsWindows && !IsDarwin) - { - // *nix box, so libuv needs to be installed - // TODO: fwlink? - message += " Make sure libuv is installed and available as libuv.so.1"; - } - - throw new InvalidOperationException(message); - } - - foreach (var field in GetType().GetTypeInfo().DeclaredFields) - { - var procAddress = GetProcAddress(module, field.Name.TrimStart('_')); - if (procAddress == IntPtr.Zero) - { - continue; - } -#pragma warning disable CS0618 - var value = Marshal.GetDelegateForFunctionPointer(procAddress, field.FieldType); -#pragma warning restore CS0618 - field.SetValue(this, value); - } - } + public bool IsWindows; public int Check(int statusCode) { @@ -84,71 +127,56 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking return statusCode; } - - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - protected delegate int uv_loop_init(UvLoopHandle a0); - protected uv_loop_init _uv_loop_init = default(uv_loop_init); + protected Func _uv_loop_init; public void loop_init(UvLoopHandle handle) { Check(_uv_loop_init(handle)); } - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - protected delegate int uv_loop_close(IntPtr a0); - protected uv_loop_close _uv_loop_close = default(uv_loop_close); + protected Func _uv_loop_close; public void loop_close(UvLoopHandle handle) { handle.Validate(closed: true); Check(_uv_loop_close(handle.InternalGetHandle())); } - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - protected delegate int uv_run(UvLoopHandle handle, int mode); - protected uv_run _uv_run = default(uv_run); + protected Func _uv_run; public int run(UvLoopHandle handle, int mode) { handle.Validate(); return Check(_uv_run(handle, mode)); } - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - protected delegate void uv_stop(UvLoopHandle handle); - protected uv_stop _uv_stop = default(uv_stop); + protected Action _uv_stop; public void stop(UvLoopHandle handle) { handle.Validate(); _uv_stop(handle); } - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - protected delegate void uv_ref(UvHandle handle); - protected uv_ref _uv_ref = default(uv_ref); + protected Action _uv_ref; public void @ref(UvHandle handle) { handle.Validate(); _uv_ref(handle); } - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - protected delegate void uv_unref(UvHandle handle); - protected uv_unref _uv_unref = default(uv_unref); + protected Action _uv_unref; public void unref(UvHandle handle) { handle.Validate(); _uv_unref(handle); } - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] public delegate void uv_close_cb(IntPtr handle); - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - protected delegate void uv_close(IntPtr handle, uv_close_cb close_cb); - protected uv_close _uv_close = default(uv_close); + protected Action _uv_close; public void close(UvHandle handle, uv_close_cb close_cb) { handle.Validate(closed: true); _uv_close(handle.InternalGetHandle(), close_cb); } + public void close(IntPtr handle, uv_close_cb close_cb) { _uv_close(handle, close_cb); @@ -156,9 +184,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking [UnmanagedFunctionPointer(CallingConvention.Cdecl)] public delegate void uv_async_cb(IntPtr handle); - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - protected delegate int uv_async_init(UvLoopHandle loop, UvAsyncHandle handle, uv_async_cb cb); - protected uv_async_init _uv_async_init = default(uv_async_init); + protected Func _uv_async_init; public void async_init(UvLoopHandle loop, UvAsyncHandle handle, uv_async_cb cb) { loop.Validate(); @@ -166,17 +192,13 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking Check(_uv_async_init(loop, handle, cb)); } - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - protected delegate int uv_async_send(UvAsyncHandle handle); - protected uv_async_send _uv_async_send = default(uv_async_send); + protected Func _uv_async_send; public void async_send(UvAsyncHandle handle) { Check(_uv_async_send(handle)); } - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - protected delegate int uv_tcp_init(UvLoopHandle loop, UvTcpHandle handle); - protected uv_tcp_init _uv_tcp_init = default(uv_tcp_init); + protected Func _uv_tcp_init; public void tcp_init(UvLoopHandle loop, UvTcpHandle handle) { loop.Validate(); @@ -184,36 +206,29 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking Check(_uv_tcp_init(loop, handle)); } - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - protected delegate int uv_tcp_bind(UvTcpHandle handle, ref sockaddr addr, int flags); - protected uv_tcp_bind _uv_tcp_bind = default(uv_tcp_bind); + protected delegate int uv_tcp_bind_func(UvTcpHandle handle, ref sockaddr addr, int flags); + protected uv_tcp_bind_func _uv_tcp_bind; public void tcp_bind(UvTcpHandle handle, ref sockaddr addr, int flags) { handle.Validate(); Check(_uv_tcp_bind(handle, ref addr, flags)); } - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - protected delegate int uv_tcp_open(UvTcpHandle handle, IntPtr hSocket); - protected uv_tcp_open _uv_tcp_open = default(uv_tcp_open); + protected Func _uv_tcp_open; public void tcp_open(UvTcpHandle handle, IntPtr hSocket) { handle.Validate(); Check(_uv_tcp_open(handle, hSocket)); } - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - protected delegate int uv_tcp_nodelay(UvTcpHandle handle, int enable); - protected uv_tcp_nodelay _uv_tcp_nodelay = default(uv_tcp_nodelay); + protected Func _uv_tcp_nodelay; public void tcp_nodelay(UvTcpHandle handle, bool enable) { handle.Validate(); Check(_uv_tcp_nodelay(handle, enable ? 1 : 0)); } - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - protected delegate int uv_pipe_init(UvLoopHandle loop, UvPipeHandle handle, int ipc); - protected uv_pipe_init _uv_pipe_init = default(uv_pipe_init); + protected Func _uv_pipe_init; public void pipe_init(UvLoopHandle loop, UvPipeHandle handle, bool ipc) { loop.Validate(); @@ -221,9 +236,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking Check(_uv_pipe_init(loop, handle, ipc ? -1 : 0)); } - [UnmanagedFunctionPointer(CallingConvention.Cdecl, CharSet = CharSet.Ansi)] - protected delegate int uv_pipe_bind(UvPipeHandle loop, string name); - protected uv_pipe_bind _uv_pipe_bind = default(uv_pipe_bind); + protected Func _uv_pipe_bind; public void pipe_bind(UvPipeHandle handle, string name) { handle.Validate(); @@ -232,18 +245,14 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking [UnmanagedFunctionPointer(CallingConvention.Cdecl)] public delegate void uv_connection_cb(IntPtr server, int status); - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - protected delegate int uv_listen(UvStreamHandle handle, int backlog, uv_connection_cb cb); - protected uv_listen _uv_listen = default(uv_listen); + protected Func _uv_listen; public void listen(UvStreamHandle handle, int backlog, uv_connection_cb cb) { handle.Validate(); Check(_uv_listen(handle, backlog, cb)); } - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - protected delegate int uv_accept(UvStreamHandle server, UvStreamHandle client); - protected uv_accept _uv_accept = default(uv_accept); + protected Func _uv_accept; public void accept(UvStreamHandle server, UvStreamHandle client) { server.Validate(); @@ -253,9 +262,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking [UnmanagedFunctionPointer(CallingConvention.Cdecl)] public delegate void uv_connect_cb(IntPtr req, int status); - [UnmanagedFunctionPointer(CallingConvention.Cdecl, CharSet = CharSet.Ansi)] - unsafe protected delegate void uv_pipe_connect(UvConnectRequest req, UvPipeHandle handle, string name, uv_connect_cb cb); - protected uv_pipe_connect _uv_pipe_connect = default(uv_pipe_connect); + protected Action _uv_pipe_connect; unsafe public void pipe_connect(UvConnectRequest req, UvPipeHandle handle, string name, uv_connect_cb cb) { req.Validate(); @@ -263,9 +270,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking _uv_pipe_connect(req, handle, name, cb); } - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - unsafe protected delegate int uv_pipe_pending_count(UvPipeHandle handle); - protected uv_pipe_pending_count _uv_pipe_pending_count = default(uv_pipe_pending_count); + protected Func _uv_pipe_pending_count; unsafe public int pipe_pending_count(UvPipeHandle handle) { handle.Validate(); @@ -276,28 +281,22 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking public delegate void uv_alloc_cb(IntPtr server, int suggested_size, out uv_buf_t buf); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] public delegate void uv_read_cb(IntPtr server, int nread, ref uv_buf_t buf); - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - protected delegate int uv_read_start(UvStreamHandle handle, uv_alloc_cb alloc_cb, uv_read_cb read_cb); - protected uv_read_start _uv_read_start = default(uv_read_start); + protected Func _uv_read_start; public void read_start(UvStreamHandle handle, uv_alloc_cb alloc_cb, uv_read_cb read_cb) { handle.Validate(); Check(_uv_read_start(handle, alloc_cb, read_cb)); } - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - protected delegate int uv_read_stop(UvStreamHandle handle); - protected uv_read_stop _uv_read_stop = default(uv_read_stop); + protected Func _uv_read_stop; public void read_stop(UvStreamHandle handle) { handle.Validate(); Check(_uv_read_stop(handle)); } - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - protected delegate int uv_try_write(UvStreamHandle handle, Libuv.uv_buf_t[] bufs, int nbufs); - protected uv_try_write _uv_try_write = default(uv_try_write); - public int try_write(UvStreamHandle handle, Libuv.uv_buf_t[] bufs, int nbufs) + protected Func _uv_try_write; + public int try_write(UvStreamHandle handle, uv_buf_t[] bufs, int nbufs) { handle.Validate(); return Check(_uv_try_write(handle, bufs, nbufs)); @@ -305,19 +304,18 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking [UnmanagedFunctionPointer(CallingConvention.Cdecl)] public delegate void uv_write_cb(IntPtr req, int status); - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - unsafe protected delegate int uv_write(UvRequest req, UvStreamHandle handle, Libuv.uv_buf_t* bufs, int nbufs, uv_write_cb cb); - protected uv_write _uv_write = default(uv_write); - unsafe public void write(UvRequest req, UvStreamHandle handle, Libuv.uv_buf_t* bufs, int nbufs, uv_write_cb cb) + + unsafe protected delegate int uv_write_func(UvRequest req, UvStreamHandle handle, uv_buf_t* bufs, int nbufs, uv_write_cb cb); + unsafe protected uv_write_func _uv_write; + unsafe public void write(UvRequest req, UvStreamHandle handle, uv_buf_t* bufs, int nbufs, uv_write_cb cb) { req.Validate(); handle.Validate(); Check(_uv_write(req, handle, bufs, nbufs, cb)); } - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - unsafe protected delegate int uv_write2(UvRequest req, UvStreamHandle handle, Libuv.uv_buf_t* bufs, int nbufs, UvStreamHandle sendHandle, uv_write_cb cb); - protected uv_write2 _uv_write2 = default(uv_write2); + unsafe protected delegate int uv_write2_func(UvRequest req, UvStreamHandle handle, uv_buf_t* bufs, int nbufs, UvStreamHandle sendHandle, uv_write_cb cb); + unsafe protected uv_write2_func _uv_write2; unsafe public void write2(UvRequest req, UvStreamHandle handle, Libuv.uv_buf_t* bufs, int nbufs, UvStreamHandle sendHandle, uv_write_cb cb) { req.Validate(); @@ -327,9 +325,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking [UnmanagedFunctionPointer(CallingConvention.Cdecl)] public delegate void uv_shutdown_cb(IntPtr req, int status); - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - protected delegate int uv_shutdown(UvShutdownReq req, UvStreamHandle handle, uv_shutdown_cb cb); - protected uv_shutdown _uv_shutdown = default(uv_shutdown); + protected Func _uv_shutdown; public void shutdown(UvShutdownReq req, UvStreamHandle handle, uv_shutdown_cb cb) { req.Validate(); @@ -337,61 +333,47 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking Check(_uv_shutdown(req, handle, cb)); } - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - protected delegate IntPtr uv_err_name(int err); - protected uv_err_name _uv_err_name = default(uv_err_name); - public unsafe String err_name(int err) + protected Func _uv_err_name; + public unsafe string err_name(int err) { IntPtr ptr = _uv_err_name(err); return ptr == IntPtr.Zero ? null : Marshal.PtrToStringAnsi(ptr); } - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - protected delegate IntPtr uv_strerror(int err); - protected uv_strerror _uv_strerror = default(uv_strerror); - public unsafe String strerror(int err) + protected Func _uv_strerror; + public unsafe string strerror(int err) { IntPtr ptr = _uv_strerror(err); return ptr == IntPtr.Zero ? null : Marshal.PtrToStringAnsi(ptr); } - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - protected delegate int uv_loop_size(); - protected uv_loop_size _uv_loop_size = default(uv_loop_size); + protected Func _uv_loop_size; public int loop_size() { return _uv_loop_size(); } - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - protected delegate int uv_handle_size(HandleType handleType); - protected uv_handle_size _uv_handle_size = default(uv_handle_size); + protected Func _uv_handle_size; public int handle_size(HandleType handleType) { return _uv_handle_size(handleType); } - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - protected delegate int uv_req_size(RequestType reqType); - protected uv_req_size _uv_req_size = default(uv_req_size); + protected Func _uv_req_size; public int req_size(RequestType reqType) { return _uv_req_size(reqType); } - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - protected delegate int uv_ip4_addr(string ip, int port, out sockaddr addr); - - protected uv_ip4_addr _uv_ip4_addr = default(uv_ip4_addr); + protected delegate int uv_ip4_addr_func(string ip, int port, out sockaddr addr); + protected uv_ip4_addr_func _uv_ip4_addr; public int ip4_addr(string ip, int port, out sockaddr addr, out Exception error) { return Check(_uv_ip4_addr(ip, port, out addr), out error); } - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - protected delegate int uv_ip6_addr(string ip, int port, out sockaddr addr); - - protected uv_ip6_addr _uv_ip6_addr = default(uv_ip6_addr); + protected delegate int uv_ip6_addr_func(string ip, int port, out sockaddr addr); + protected uv_ip6_addr_func _uv_ip6_addr; public int ip6_addr(string ip, int port, out sockaddr addr, out Exception error) { return Check(_uv_ip6_addr(ip, port, out addr), out error); @@ -399,9 +381,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking [UnmanagedFunctionPointer(CallingConvention.Cdecl)] public delegate void uv_walk_cb(IntPtr handle, IntPtr arg); - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - unsafe protected delegate int uv_walk(UvLoopHandle loop, uv_walk_cb walk_cb, IntPtr arg); - protected uv_walk _uv_walk = default(uv_walk); + protected Func _uv_walk; unsafe public void walk(UvLoopHandle loop, uv_walk_cb walk_cb, IntPtr arg) { loop.Validate(); @@ -430,7 +410,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking public struct uv_buf_t { - // this type represents a WSABUF struct on Windows + // this type represents a WSABUF struct on Windows // https://msdn.microsoft.com/en-us/library/windows/desktop/ms741542(v=vs.85).aspx // and an iovec struct on *nix // http://man7.org/linux/man-pages/man2/readv.2.html @@ -490,5 +470,209 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking GETADDRINFO, GETNAMEINFO, } + + private static class NativeMethods + { + [DllImport("libuv", CallingConvention = CallingConvention.Cdecl)] + public static extern int uv_loop_init(UvLoopHandle handle); + + [DllImport("libuv", CallingConvention = CallingConvention.Cdecl)] + public static extern int uv_loop_close(IntPtr a0); + + [DllImport("libuv", CallingConvention = CallingConvention.Cdecl)] + public static extern int uv_run(UvLoopHandle handle, int mode); + + [DllImport("libuv", CallingConvention = CallingConvention.Cdecl)] + public static extern void uv_stop(UvLoopHandle handle); + + [DllImport("libuv", CallingConvention = CallingConvention.Cdecl)] + public static extern void uv_ref(UvHandle handle); + + [DllImport("libuv", CallingConvention = CallingConvention.Cdecl)] + public static extern void uv_unref(UvHandle handle); + + [DllImport("libuv", CallingConvention = CallingConvention.Cdecl)] + public static extern void uv_close(IntPtr handle, uv_close_cb close_cb); + + [DllImport("libuv", CallingConvention = CallingConvention.Cdecl)] + public static extern int uv_async_init(UvLoopHandle loop, UvAsyncHandle handle, uv_async_cb cb); + + [DllImport("libuv", CallingConvention = CallingConvention.Cdecl)] + public extern static int uv_async_send(UvAsyncHandle handle); + + [DllImport("libuv", CallingConvention = CallingConvention.Cdecl)] + public static extern int uv_tcp_init(UvLoopHandle loop, UvTcpHandle handle); + + [DllImport("libuv", CallingConvention = CallingConvention.Cdecl)] + public static extern int uv_tcp_bind(UvTcpHandle handle, ref sockaddr addr, int flags); + + [DllImport("libuv", CallingConvention = CallingConvention.Cdecl)] + public static extern int uv_tcp_open(UvTcpHandle handle, IntPtr hSocket); + + [DllImport("libuv", CallingConvention = CallingConvention.Cdecl)] + public static extern int uv_tcp_nodelay(UvTcpHandle handle, int enable); + + [DllImport("libuv", CallingConvention = CallingConvention.Cdecl)] + public static extern int uv_pipe_init(UvLoopHandle loop, UvPipeHandle handle, int ipc); + + [DllImport("libuv", CallingConvention = CallingConvention.Cdecl)] + public static extern int uv_pipe_bind(UvPipeHandle loop, string name); + + [DllImport("libuv", CallingConvention = CallingConvention.Cdecl)] + public static extern int uv_listen(UvStreamHandle handle, int backlog, uv_connection_cb cb); + + [DllImport("libuv", CallingConvention = CallingConvention.Cdecl)] + public static extern int uv_accept(UvStreamHandle server, UvStreamHandle client); + + [DllImport("libuv", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)] + public static extern void uv_pipe_connect(UvConnectRequest req, UvPipeHandle handle, string name, uv_connect_cb cb); + + [DllImport("libuv", CallingConvention = CallingConvention.Cdecl)] + public extern static int uv_pipe_pending_count(UvPipeHandle handle); + + [DllImport("libuv", CallingConvention = CallingConvention.Cdecl)] + public extern static int uv_read_start(UvStreamHandle handle, uv_alloc_cb alloc_cb, uv_read_cb read_cb); + + [DllImport("libuv", CallingConvention = CallingConvention.Cdecl)] + public static extern int uv_read_stop(UvStreamHandle handle); + + [DllImport("libuv", CallingConvention = CallingConvention.Cdecl)] + public static extern int uv_try_write(UvStreamHandle handle, uv_buf_t[] bufs, int nbufs); + + [DllImport("libuv", CallingConvention = CallingConvention.Cdecl)] + unsafe public static extern int uv_write(UvRequest req, UvStreamHandle handle, uv_buf_t* bufs, int nbufs, uv_write_cb cb); + + [DllImport("libuv", CallingConvention = CallingConvention.Cdecl)] + unsafe public static extern int uv_write2(UvRequest req, UvStreamHandle handle, uv_buf_t* bufs, int nbufs, UvStreamHandle sendHandle, uv_write_cb cb); + + [DllImport("libuv", CallingConvention = CallingConvention.Cdecl)] + public static extern int uv_shutdown(UvShutdownReq req, UvStreamHandle handle, uv_shutdown_cb cb); + + [DllImport("libuv", CallingConvention = CallingConvention.Cdecl)] + public extern static IntPtr uv_err_name(int err); + + [DllImport("libuv", CallingConvention = CallingConvention.Cdecl)] + public static extern IntPtr uv_strerror(int err); + + [DllImport("libuv", CallingConvention = CallingConvention.Cdecl)] + public static extern int uv_loop_size(); + + [DllImport("libuv", CallingConvention = CallingConvention.Cdecl)] + public static extern int uv_handle_size(HandleType handleType); + + [DllImport("libuv", CallingConvention = CallingConvention.Cdecl)] + public static extern int uv_req_size(RequestType reqType); + + [DllImport("libuv", CallingConvention = CallingConvention.Cdecl)] + public static extern int uv_ip4_addr(string ip, int port, out sockaddr addr); + + [DllImport("libuv", CallingConvention = CallingConvention.Cdecl)] + public static extern int uv_ip6_addr(string ip, int port, out sockaddr addr); + + [DllImport("libuv", CallingConvention = CallingConvention.Cdecl)] + unsafe public static extern int uv_walk(UvLoopHandle loop, uv_walk_cb walk_cb, IntPtr arg); + } + + private static class NativeDarwinMonoMethods + { + [DllImport("__Internal", CallingConvention = CallingConvention.Cdecl)] + public static extern int uv_loop_init(UvLoopHandle handle); + + [DllImport("__Internal", CallingConvention = CallingConvention.Cdecl)] + public static extern int uv_loop_close(IntPtr a0); + + [DllImport("__Internal", CallingConvention = CallingConvention.Cdecl)] + public static extern int uv_run(UvLoopHandle handle, int mode); + + [DllImport("__Internal", CallingConvention = CallingConvention.Cdecl)] + public static extern void uv_stop(UvLoopHandle handle); + + [DllImport("__Internal", CallingConvention = CallingConvention.Cdecl)] + public static extern void uv_ref(UvHandle handle); + + [DllImport("__Internal", CallingConvention = CallingConvention.Cdecl)] + public static extern void uv_unref(UvHandle handle); + + [DllImport("__Internal", CallingConvention = CallingConvention.Cdecl)] + public static extern void uv_close(IntPtr handle, uv_close_cb close_cb); + + [DllImport("__Internal", CallingConvention = CallingConvention.Cdecl)] + public static extern int uv_async_init(UvLoopHandle loop, UvAsyncHandle handle, uv_async_cb cb); + + [DllImport("__Internal", CallingConvention = CallingConvention.Cdecl)] + public extern static int uv_async_send(UvAsyncHandle handle); + + [DllImport("__Internal", CallingConvention = CallingConvention.Cdecl)] + public static extern int uv_tcp_init(UvLoopHandle loop, UvTcpHandle handle); + + [DllImport("__Internal", CallingConvention = CallingConvention.Cdecl)] + public static extern int uv_tcp_bind(UvTcpHandle handle, ref sockaddr addr, int flags); + + [DllImport("__Internal", CallingConvention = CallingConvention.Cdecl)] + public static extern int uv_tcp_open(UvTcpHandle handle, IntPtr hSocket); + + [DllImport("__Internal", CallingConvention = CallingConvention.Cdecl)] + public static extern int uv_tcp_nodelay(UvTcpHandle handle, int enable); + + [DllImport("__Internal", CallingConvention = CallingConvention.Cdecl)] + public static extern int uv_pipe_init(UvLoopHandle loop, UvPipeHandle handle, int ipc); + + [DllImport("__Internal", CallingConvention = CallingConvention.Cdecl)] + public static extern int uv_pipe_bind(UvPipeHandle loop, string name); + + [DllImport("__Internal", CallingConvention = CallingConvention.Cdecl)] + public static extern int uv_listen(UvStreamHandle handle, int backlog, uv_connection_cb cb); + + [DllImport("__Internal", CallingConvention = CallingConvention.Cdecl)] + public static extern int uv_accept(UvStreamHandle server, UvStreamHandle client); + + [DllImport("__Internal", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)] + public static extern void uv_pipe_connect(UvConnectRequest req, UvPipeHandle handle, string name, uv_connect_cb cb); + + [DllImport("__Internal", CallingConvention = CallingConvention.Cdecl)] + public extern static int uv_pipe_pending_count(UvPipeHandle handle); + + [DllImport("__Internal", CallingConvention = CallingConvention.Cdecl)] + public extern static int uv_read_start(UvStreamHandle handle, uv_alloc_cb alloc_cb, uv_read_cb read_cb); + + [DllImport("__Internal", CallingConvention = CallingConvention.Cdecl)] + public static extern int uv_read_stop(UvStreamHandle handle); + + [DllImport("__Internal", CallingConvention = CallingConvention.Cdecl)] + public static extern int uv_try_write(UvStreamHandle handle, uv_buf_t[] bufs, int nbufs); + + [DllImport("__Internal", CallingConvention = CallingConvention.Cdecl)] + unsafe public static extern int uv_write(UvRequest req, UvStreamHandle handle, uv_buf_t* bufs, int nbufs, uv_write_cb cb); + + [DllImport("__Internal", CallingConvention = CallingConvention.Cdecl)] + unsafe public static extern int uv_write2(UvRequest req, UvStreamHandle handle, uv_buf_t* bufs, int nbufs, UvStreamHandle sendHandle, uv_write_cb cb); + + [DllImport("__Internal", CallingConvention = CallingConvention.Cdecl)] + public static extern int uv_shutdown(UvShutdownReq req, UvStreamHandle handle, uv_shutdown_cb cb); + + [DllImport("__Internal", CallingConvention = CallingConvention.Cdecl)] + public extern static IntPtr uv_err_name(int err); + + [DllImport("__Internal", CallingConvention = CallingConvention.Cdecl)] + public static extern IntPtr uv_strerror(int err); + + [DllImport("__Internal", CallingConvention = CallingConvention.Cdecl)] + public static extern int uv_loop_size(); + + [DllImport("__Internal", CallingConvention = CallingConvention.Cdecl)] + public static extern int uv_handle_size(HandleType handleType); + + [DllImport("__Internal", CallingConvention = CallingConvention.Cdecl)] + public static extern int uv_req_size(RequestType reqType); + + [DllImport("__Internal", CallingConvention = CallingConvention.Cdecl)] + public static extern int uv_ip4_addr(string ip, int port, out sockaddr addr); + + [DllImport("__Internal", CallingConvention = CallingConvention.Cdecl)] + public static extern int uv_ip6_addr(string ip, int port, out sockaddr addr); + + [DllImport("__Internal", CallingConvention = CallingConvention.Cdecl)] + unsafe public static extern int uv_walk(UvLoopHandle loop, uv_walk_cb walk_cb, IntPtr arg); + } } } \ No newline at end of file diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/PlatformApis.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/PlatformApis.cs index 7b13ccdd9c..f874ac9b15 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/PlatformApis.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/PlatformApis.cs @@ -20,6 +20,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking #endif } + public static bool IsDarwin() + { + return string.Equals(GetUname(), "Darwin", StringComparison.Ordinal); + } + [DllImport("libc")] static extern int uname(IntPtr buf); @@ -42,81 +47,5 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking return string.Empty; } } - - public static bool IsDarwin() - { - return string.Equals(GetUname(), "Darwin", StringComparison.Ordinal); - } - - public static void Apply(Libuv libuv) - { - if (libuv.IsWindows) - { - WindowsApis.Apply(libuv); - } - else - { - LinuxApis.Apply(libuv); - } - } - - public static class WindowsApis - { - [DllImport("kernel32")] - public static extern IntPtr LoadLibrary(string dllToLoad); - - [DllImport("kernel32")] - public static extern bool FreeLibrary(IntPtr hModule); - - [DllImport("kernel32", CharSet = CharSet.Ansi, ExactSpelling = true, SetLastError = true)] - public static extern IntPtr GetProcAddress(IntPtr hModule, string procedureName); - - public static void Apply(Libuv libuv) - { - libuv.LoadLibrary = LoadLibrary; - libuv.FreeLibrary = FreeLibrary; - libuv.GetProcAddress = GetProcAddress; - } - } - - public static class LinuxApis - { - [DllImport("libdl")] - public static extern IntPtr dlopen(String fileName, int flags); - - [DllImport("libdl")] - public static extern IntPtr dlsym(IntPtr handle, String symbol); - - [DllImport("libdl")] - public static extern int dlclose(IntPtr handle); - - [DllImport("libdl")] - public static extern IntPtr dlerror(); - - public static IntPtr LoadLibrary(string dllToLoad) - { - return dlopen(dllToLoad, 2); - } - - public static bool FreeLibrary(IntPtr hModule) - { - return dlclose(hModule) == 0; - } - - public static IntPtr GetProcAddress(IntPtr hModule, string procedureName) - { - dlerror(); - var res = dlsym(hModule, procedureName); - var errPtr = dlerror(); - return errPtr == IntPtr.Zero ? res : IntPtr.Zero; - } - - public static void Apply(Libuv libuv) - { - libuv.LoadLibrary = LoadLibrary; - libuv.FreeLibrary = FreeLibrary; - libuv.GetProcAddress = GetProcAddress; - } - } } } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvLoopHandle.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvLoopHandle.cs index 5c708c2e23..75a4bbfdc4 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvLoopHandle.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvLoopHandle.cs @@ -16,7 +16,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking public void Init(Libuv uv) { CreateMemory( - uv, + uv, Thread.CurrentThread.ManagedThreadId, uv.loop_size()); From c1b21b89d554ccb14de6a6fb2e96f55b31fdaf4f Mon Sep 17 00:00:00 2001 From: moozzyk Date: Tue, 27 Oct 2015 00:25:38 -0700 Subject: [PATCH 0375/1662] Removing dependency on Microsoft.Extensions.PlatformAbstractions --- .../KestrelEngine.cs | 17 +++-------- .../ServerFactory.cs | 7 ++--- .../project.json | 1 - .../EngineTests.cs | 30 ++----------------- .../MultipleLoopTests.cs | 21 +------------ .../NetworkingTests.cs | 21 +------------ .../TestServer.cs | 27 +---------------- .../Program.cs | 1 - 8 files changed, 12 insertions(+), 113 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/KestrelEngine.cs b/src/Microsoft.AspNet.Server.Kestrel/KestrelEngine.cs index 358a965843..32dd5dab98 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/KestrelEngine.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/KestrelEngine.cs @@ -7,29 +7,20 @@ using System.Threading.Tasks; using Microsoft.AspNet.Http.Features; using Microsoft.AspNet.Server.Kestrel.Http; using Microsoft.AspNet.Server.Kestrel.Networking; -using Microsoft.Extensions.Logging; -using Microsoft.Extensions.PlatformAbstractions; namespace Microsoft.AspNet.Server.Kestrel { public class KestrelEngine : ServiceContext, IDisposable { - public KestrelEngine(ILibraryManager libraryManager, ServiceContext context) - : this(context) - { - Libuv = new Libuv(); - } + public KestrelEngine(ServiceContext context) + : this(new Libuv(), context) + { } // For testing internal KestrelEngine(Libuv uv, ServiceContext context) - : this(context) + : base(context) { Libuv = uv; - } - - private KestrelEngine(ServiceContext context) - : base(context) - { Threads = new List(); } diff --git a/src/Microsoft.AspNet.Server.Kestrel/ServerFactory.cs b/src/Microsoft.AspNet.Server.Kestrel/ServerFactory.cs index e801749a87..c0b42c0d2c 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/ServerFactory.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/ServerFactory.cs @@ -11,7 +11,6 @@ using Microsoft.AspNet.Server.Features; using Microsoft.AspNet.Server.Kestrel.Http; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Logging; -using Microsoft.Extensions.PlatformAbstractions; namespace Microsoft.AspNet.Server.Kestrel { @@ -20,13 +19,11 @@ namespace Microsoft.AspNet.Server.Kestrel /// public class ServerFactory : IServerFactory { - private readonly ILibraryManager _libraryManager; private readonly IApplicationLifetime _appLifetime; private readonly ILogger _logger; - public ServerFactory(ILibraryManager libraryManager, IApplicationLifetime appLifetime, ILoggerFactory loggerFactory) + public ServerFactory(IApplicationLifetime appLifetime, ILoggerFactory loggerFactory) { - _libraryManager = libraryManager; _appLifetime = appLifetime; _logger = loggerFactory.CreateLogger("Microsoft.AspNet.Server.Kestrel"); } @@ -56,7 +53,7 @@ namespace Microsoft.AspNet.Server.Kestrel { var information = (KestrelServerInformation)serverFeatures.Get(); var dateHeaderValueManager = new DateHeaderValueManager(); - var engine = new KestrelEngine(_libraryManager, new ServiceContext + var engine = new KestrelEngine(new ServiceContext { AppLifetime = _appLifetime, Log = new KestrelTrace(_logger), diff --git a/src/Microsoft.AspNet.Server.Kestrel/project.json b/src/Microsoft.AspNet.Server.Kestrel/project.json index d9a6da0f42..6ef9e06bb1 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/project.json +++ b/src/Microsoft.AspNet.Server.Kestrel/project.json @@ -7,7 +7,6 @@ }, "dependencies": { "Microsoft.AspNet.Hosting": "1.0.0-*", - "Microsoft.Extensions.PlatformAbstractions": "1.0.0-*", "Microsoft.Extensions.Logging.Abstractions": "1.0.0-*", "System.Numerics.Vectors": "4.1.1-beta-*", "Microsoft.StandardsPolice": { diff --git a/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs index c2d2ad06bb..1d2cba53c0 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs @@ -10,7 +10,6 @@ using System.Threading.Tasks; using Microsoft.AspNet.Http.Features; using Microsoft.AspNet.Server.Kestrel; using Microsoft.AspNet.Server.Kestrel.Filter; -using Microsoft.Extensions.PlatformAbstractions; using Microsoft.Extensions.Logging; using Xunit; @@ -57,29 +56,6 @@ namespace Microsoft.AspNet.Server.KestrelTests } } - ILibraryManager LibraryManager - { - get - { - try - { - var locator = CallContextServiceLocator.Locator; - if (locator == null) - { - return null; - } - var services = locator.ServiceProvider; - if (services == null) - { - return null; - } - return (ILibraryManager)services.GetService(typeof(ILibraryManager)); - } - catch (NullReferenceException) - { return null; } - } - } - private async Task AppChunked(IFeatureCollection frame) { var request = frame.Get(); @@ -103,7 +79,7 @@ namespace Microsoft.AspNet.Server.KestrelTests [MemberData(nameof(ConnectionFilterData))] public void EngineCanStartAndStop(ServiceContext testContext) { - var engine = new KestrelEngine(LibraryManager, testContext); + var engine = new KestrelEngine(testContext); engine.Start(1); engine.Dispose(); } @@ -112,7 +88,7 @@ namespace Microsoft.AspNet.Server.KestrelTests [MemberData(nameof(ConnectionFilterData))] public void ListenerCanCreateAndDispose(ServiceContext testContext) { - var engine = new KestrelEngine(LibraryManager, testContext); + var engine = new KestrelEngine(testContext); engine.Start(1); var address = ServerAddress.FromUrl("http://localhost:54321/"); var started = engine.CreateServer(address, App); @@ -124,7 +100,7 @@ namespace Microsoft.AspNet.Server.KestrelTests [MemberData(nameof(ConnectionFilterData))] public void ConnectionCanReadAndWrite(ServiceContext testContext) { - var engine = new KestrelEngine(LibraryManager, testContext); + var engine = new KestrelEngine(testContext); engine.Start(1); var address = ServerAddress.FromUrl("http://localhost:54321/"); var started = engine.CreateServer(address, App); diff --git a/test/Microsoft.AspNet.Server.KestrelTests/MultipleLoopTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/MultipleLoopTests.cs index cb870ea144..8293ad09b0 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/MultipleLoopTests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/MultipleLoopTests.cs @@ -6,7 +6,6 @@ using System.Threading; using Microsoft.AspNet.Server.Kestrel; using Microsoft.AspNet.Server.Kestrel.Infrastructure; using Microsoft.AspNet.Server.Kestrel.Networking; -using Microsoft.Extensions.PlatformAbstractions; using Xunit; namespace Microsoft.AspNet.Server.KestrelTests @@ -17,29 +16,11 @@ namespace Microsoft.AspNet.Server.KestrelTests private readonly IKestrelTrace _logger; public MultipleLoopTests() { - var engine = new KestrelEngine(LibraryManager, new TestServiceContext()); + var engine = new KestrelEngine(new TestServiceContext()); _uv = engine.Libuv; _logger = engine.Log; } - ILibraryManager LibraryManager - { - get - { - var locator = CallContextServiceLocator.Locator; - if (locator == null) - { - return null; - } - var services = locator.ServiceProvider; - if (services == null) - { - return null; - } - return (ILibraryManager)services.GetService(typeof(ILibraryManager)); - } - } - [Fact(Skip = "Waiting for adding support for multi loop in libuv")] public void InitAndCloseServerPipe() { diff --git a/test/Microsoft.AspNet.Server.KestrelTests/NetworkingTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/NetworkingTests.cs index aea3274475..e4f1a48590 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/NetworkingTests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/NetworkingTests.cs @@ -9,7 +9,6 @@ using System.Threading.Tasks; using Microsoft.AspNet.Server.Kestrel; using Microsoft.AspNet.Server.Kestrel.Infrastructure; using Microsoft.AspNet.Server.Kestrel.Networking; -using Microsoft.Extensions.PlatformAbstractions; using Xunit; namespace Microsoft.AspNet.Server.KestrelTests @@ -23,29 +22,11 @@ namespace Microsoft.AspNet.Server.KestrelTests private readonly IKestrelTrace _logger; public NetworkingTests() { - var engine = new KestrelEngine(LibraryManager, new TestServiceContext()); + var engine = new KestrelEngine(new TestServiceContext()); _uv = engine.Libuv; _logger = engine.Log; } - ILibraryManager LibraryManager - { - get - { - var locator = CallContextServiceLocator.Locator; - if (locator == null) - { - return null; - } - var services = locator.ServiceProvider; - if (services == null) - { - return null; - } - return (ILibraryManager)services.GetService(typeof(ILibraryManager)); - } - } - [Fact] public void LoopCanBeInitAndClose() { diff --git a/test/Microsoft.AspNet.Server.KestrelTests/TestServer.cs b/test/Microsoft.AspNet.Server.KestrelTests/TestServer.cs index 698b7a1d57..d4721d72f1 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/TestServer.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/TestServer.cs @@ -4,8 +4,6 @@ using System; using System.Threading.Tasks; using Microsoft.AspNet.Server.Kestrel; -using Microsoft.AspNet.Server.Kestrel.Http; -using Microsoft.Extensions.PlatformAbstractions; using Microsoft.AspNet.Http.Features; namespace Microsoft.AspNet.Server.KestrelTests @@ -32,33 +30,10 @@ namespace Microsoft.AspNet.Server.KestrelTests Create(app, context, serverAddress); } - ILibraryManager LibraryManager - { - get - { - try - { - var locator = CallContextServiceLocator.Locator; - if (locator == null) - { - return null; - } - var services = locator.ServiceProvider; - if (services == null) - { - return null; - } - return (ILibraryManager)services.GetService(typeof(ILibraryManager)); - } - catch (NullReferenceException) { return null; } - } - } public void Create(Func app, ServiceContext context, string serverAddress) { - _engine = new KestrelEngine( - LibraryManager, - context); + _engine = new KestrelEngine(context); _engine.Start(1); _server = _engine.CreateServer( ServerAddress.FromUrl(serverAddress), diff --git a/tools/Microsoft.AspNet.Server.Kestrel.LibuvCopier/Program.cs b/tools/Microsoft.AspNet.Server.Kestrel.LibuvCopier/Program.cs index 0226bbde54..9ee4d03ad7 100644 --- a/tools/Microsoft.AspNet.Server.Kestrel.LibuvCopier/Program.cs +++ b/tools/Microsoft.AspNet.Server.Kestrel.LibuvCopier/Program.cs @@ -1,7 +1,6 @@ using System; using System.IO; using System.Linq; -using Microsoft.Extensions.PlatformAbstractions; using Newtonsoft.Json.Linq; namespace Microsoft.AspNet.Server.Kestrel.LibuvCopier From 4bba074d778933b312011df0ade8ff875250cded Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Wed, 28 Oct 2015 08:53:11 +0000 Subject: [PATCH 0376/1662] Read to null buffer Read to null buffer rather than Stream.Null as the CopyToAsync will create a `new byte[]` on each call https://github.com/dotnet/coreclr/blob/bc146608854d1db9cdbcc0b08029a87754e12b49/src/mscorlib/src/System/IO/Stream.cs#L218 of size 81920 bytes! https://github.com/dotnet/coreclr/blob/bc146608854d1db9cdbcc0b08029a87754e12b49/src/mscorlib/src/System/IO/Stream.cs#L48 --- src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs index 13546271e5..5b7678e48f 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs @@ -29,6 +29,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http private readonly object _onStartingSync = new Object(); private readonly object _onCompletedSync = new Object(); private readonly FrameRequestHeaders _requestHeaders = new FrameRequestHeaders(); + private readonly byte[] _nullBuffer = new byte[4096]; private readonly FrameResponseHeaders _responseHeaders = new FrameResponseHeaders(); private List, object>> _onStarting; @@ -198,7 +199,10 @@ namespace Microsoft.AspNet.Server.Kestrel.Http await ProduceEnd(); // Finish reading the request body in case the app did not. - await RequestBody.CopyToAsync(Stream.Null); + while (await RequestBody.ReadAsync(_nullBuffer, 0, _nullBuffer.Length) != 0) + { + ; + } } terminated = !_keepAlive; From 0e3e42826cd2e05481e1892875ca8ba31f394bcf Mon Sep 17 00:00:00 2001 From: Pranav K Date: Wed, 28 Oct 2015 12:43:07 -0700 Subject: [PATCH 0377/1662] Updating to release NuGet.config. --- NuGet.config | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/NuGet.config b/NuGet.config index 03704957e8..9db87a421e 100644 --- a/NuGet.config +++ b/NuGet.config @@ -1,7 +1,7 @@ - + - + \ No newline at end of file From bdadc8a3dace276ecb1a65d4ea49caafa7c97fb3 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Wed, 28 Oct 2015 22:44:35 +0000 Subject: [PATCH 0378/1662] Move comment into loop, remove noop --- src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs index 5b7678e48f..8f1c804926 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs @@ -198,10 +198,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Http await ProduceEnd(); - // Finish reading the request body in case the app did not. while (await RequestBody.ReadAsync(_nullBuffer, 0, _nullBuffer.Length) != 0) { - ; + // Finish reading the request body in case the app did not. } } From e9a60610236c53e9518fe80ccf75f14b7e5d02f8 Mon Sep 17 00:00:00 2001 From: Troy Dai Date: Tue, 27 Oct 2015 14:40:28 -0700 Subject: [PATCH 0379/1662] Make Frame implements IHttpConnectionFeature Provide RemoteIPAddress as well as RemotePort --- samples/SampleApp/Startup.cs | 5 + .../Http/Connection.cs | 20 +++- .../Http/Frame.FeatureCollection.cs | 17 +++- .../Http/Frame.Generated.cs | 2 +- .../Http/Frame.cs | 41 +++++++- .../Networking/Libuv.cs | 71 ++++++++------ .../Networking/SockAddr.cs | 94 +++++++++++++++++++ .../Networking/UvTcpHandle.cs | 25 ++++- .../RequestTests.cs | 63 ++++++++++++- .../FrameFeatureCollection.cs | 1 + 10 files changed, 297 insertions(+), 42 deletions(-) create mode 100644 src/Microsoft.AspNet.Server.Kestrel/Networking/SockAddr.cs diff --git a/samples/SampleApp/Startup.cs b/samples/SampleApp/Startup.cs index fb6c8e9a2b..61bd9a3aa1 100644 --- a/samples/SampleApp/Startup.cs +++ b/samples/SampleApp/Startup.cs @@ -52,6 +52,11 @@ namespace SampleApp context.Request.Path, context.Request.QueryString); + var connectionFeature = context.Connection; + Console.WriteLine($"Peer: {connectionFeature.RemoteIpAddress?.ToString()} {connectionFeature.RemotePort}"); + Console.WriteLine($"Sock: {connectionFeature.LocalIpAddress?.ToString()} {connectionFeature.LocalPort}"); + Console.WriteLine($"IsLocal: {connectionFeature.IsLocal}"); + context.Response.ContentLength = 11; context.Response.ContentType = "text/plain"; await context.Response.WriteAsync("Hello world"); diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs index 906faa9861..ac0540d182 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Net; using System.Threading; using Microsoft.AspNet.Server.Kestrel.Filter; using Microsoft.AspNet.Server.Kestrel.Infrastructure; @@ -28,6 +29,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Http private readonly object _stateLock = new object(); private ConnectionState _connectionState; + private IPEndPoint _remoteEndPoint; + private IPEndPoint _localEndPoint; + public Connection(ListenerContext context, UvStreamHandle socket) : base(context) { _socket = socket; @@ -46,13 +50,20 @@ namespace Microsoft.AspNet.Server.Kestrel.Http // Start socket prior to applying the ConnectionFilter _socket.ReadStart(_allocCallback, _readCallback, this); + var tcpHandle = _socket as UvTcpHandle; + if (tcpHandle != null) + { + _remoteEndPoint = tcpHandle.GetPeerIPEndPoint(); + _localEndPoint = tcpHandle.GetSockIPEndPoint(); + } + // Don't initialize _frame until SocketInput and SocketOutput are set to their final values. if (ConnectionFilter == null) { SocketInput = _rawSocketInput; SocketOutput = _rawSocketOutput; - _frame = new Frame(this); + _frame = CreateFrame(); _frame.Start(); } else @@ -94,7 +105,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http SocketInput = filteredStreamAdapter.SocketInput; SocketOutput = filteredStreamAdapter.SocketOutput; - _frame = new Frame(this); + _frame = CreateFrame(); _frame.Start(); } @@ -142,6 +153,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http _rawSocketInput.IncomingComplete(readCount, error); } + private Frame CreateFrame() + { + return new Frame(this, _remoteEndPoint, _localEndPoint); + } + void IConnectionControl.Pause() { Log.ConnectionPause(_connectionId); diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.FeatureCollection.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.FeatureCollection.cs index 126dce7891..1a4efb32fb 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.FeatureCollection.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.FeatureCollection.cs @@ -6,6 +6,7 @@ using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; +using System.Net; using System.Threading.Tasks; using Microsoft.AspNet.Http; using Microsoft.AspNet.Http.Features; @@ -13,7 +14,11 @@ using Microsoft.Extensions.Primitives; namespace Microsoft.AspNet.Server.Kestrel.Http { - public partial class Frame : IFeatureCollection, IHttpRequestFeature, IHttpResponseFeature, IHttpUpgradeFeature + public partial class Frame : IFeatureCollection, + IHttpRequestFeature, + IHttpResponseFeature, + IHttpUpgradeFeature, + IHttpConnectionFeature { // NOTE: When feature interfaces are added to or removed from this Frame class implementation, // then the list of `implementedFeatures` in the generated code project MUST also be updated. @@ -246,6 +251,16 @@ namespace Microsoft.AspNet.Server.Kestrel.Http int IFeatureCollection.Revision => _featureRevision; + IPAddress IHttpConnectionFeature.RemoteIpAddress { get; set; } + + IPAddress IHttpConnectionFeature.LocalIpAddress { get; set; } + + int IHttpConnectionFeature.RemotePort { get; set; } + + int IHttpConnectionFeature.LocalPort { get; set; } + + bool IHttpConnectionFeature.IsLocal { get; set; } + object IFeatureCollection.this[Type key] { get { return FastFeatureGet(key); } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.Generated.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.Generated.cs index 4d336eb9e0..985267a57f 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.Generated.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.Generated.cs @@ -45,11 +45,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http _currentIHttpRequestFeature = this; _currentIHttpResponseFeature = this; _currentIHttpUpgradeFeature = this; + _currentIHttpConnectionFeature = this; _currentIHttpRequestIdentifierFeature = null; _currentIServiceProvidersFeature = null; _currentIHttpRequestLifetimeFeature = null; - _currentIHttpConnectionFeature = null; _currentIHttpAuthenticationFeature = null; _currentIQueryFeature = null; _currentIFormFeature = null; diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs index 13546271e5..3c07bf2dec 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs @@ -5,10 +5,12 @@ using System; using System.Collections.Generic; using System.IO; using System.Linq; +using System.Net; using System.Text; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNet.Http; +using Microsoft.AspNet.Http.Features; using Microsoft.AspNet.Server.Kestrel.Infrastructure; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Primitives; @@ -44,8 +46,22 @@ namespace Microsoft.AspNet.Server.Kestrel.Http private bool _autoChunk; private Exception _applicationException; - public Frame(ConnectionContext context) : base(context) + private readonly IPEndPoint _localEndPoint; + private readonly IPEndPoint _remoteEndPoint; + + public Frame(ConnectionContext context) + : this(context, remoteEndPoint: null, localEndPoint: null) { + } + + public Frame(ConnectionContext context, + IPEndPoint remoteEndPoint, + IPEndPoint localEndPoint) + : base(context) + { + _remoteEndPoint = remoteEndPoint; + _localEndPoint = localEndPoint; + FrameControl = this; Reset(); } @@ -99,6 +115,21 @@ namespace Microsoft.AspNet.Server.Kestrel.Http ResponseBody = null; DuplexStream = null; + var httpConnectionFeature = this as IHttpConnectionFeature; + httpConnectionFeature.RemoteIpAddress = _remoteEndPoint?.Address; + httpConnectionFeature.RemotePort = _remoteEndPoint?.Port ?? 0; + + httpConnectionFeature.LocalIpAddress = _localEndPoint?.Address; + httpConnectionFeature.LocalPort = _localEndPoint?.Port ?? 0; + + if (_remoteEndPoint != null && _localEndPoint != null) + { + httpConnectionFeature.IsLocal = _remoteEndPoint.Address.Equals(_localEndPoint.Address); + } + else + { + httpConnectionFeature.IsLocal = false; + } } public void ResetResponseHeaders() @@ -123,7 +154,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http /// /// Should be called when the server wants to initiate a shutdown. The Task returned will /// become complete when the RequestProcessingAsync function has exited. It is expected that - /// Stop will be called on all active connections, and Task.WaitAll() will be called on every + /// Stop will be called on all active connections, and Task.WaitAll() will be called on every /// return value. /// public Task Stop() @@ -136,7 +167,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } /// - /// Primary loop which consumes socket input, parses it for protocol framing, and invokes the + /// Primary loop which consumes socket input, parses it for protocol framing, and invokes the /// application delegate for as long as the socket is intended to remain open. /// The resulting Task from this loop is preserved in a field which is used when the server needs /// to drain and close all currently active connections. @@ -731,7 +762,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http if (chSecond != '\n') { - // "\r" was all by itself, move just after it and try again + // "\r" was all by itself, move just after it and try again scan = endValue; scan.Take(); continue; @@ -740,7 +771,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http var chThird = scan.Peek(); if (chThird == ' ' || chThird == '\t') { - // special case, "\r\n " or "\r\n\t". + // special case, "\r\n " or "\r\n\t". // this is considered wrapping"linear whitespace" and is actually part of the header value // continue past this for the next wrapping = true; diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/Libuv.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/Libuv.cs index 2a1c9871c5..ef6fb74434 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/Libuv.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/Libuv.cs @@ -56,6 +56,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking _uv_req_size = NativeDarwinMonoMethods.uv_req_size; _uv_ip4_addr = NativeDarwinMonoMethods.uv_ip4_addr; _uv_ip6_addr = NativeDarwinMonoMethods.uv_ip6_addr; + _uv_tcp_getpeername = NativeDarwinMonoMethods.uv_tcp_getpeername; + _uv_tcp_getsockname = NativeDarwinMonoMethods.uv_tcp_getsockname; _uv_walk = NativeDarwinMonoMethods.uv_walk; } else @@ -95,6 +97,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking _uv_req_size = NativeMethods.uv_req_size; _uv_ip4_addr = NativeMethods.uv_ip4_addr; _uv_ip6_addr = NativeMethods.uv_ip6_addr; + _uv_tcp_getpeername = NativeMethods.uv_tcp_getpeername; + _uv_tcp_getsockname = NativeMethods.uv_tcp_getsockname; _uv_walk = NativeMethods.uv_walk; } } @@ -206,9 +210,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking Check(_uv_tcp_init(loop, handle)); } - protected delegate int uv_tcp_bind_func(UvTcpHandle handle, ref sockaddr addr, int flags); + protected delegate int uv_tcp_bind_func(UvTcpHandle handle, ref SockAddr addr, int flags); protected uv_tcp_bind_func _uv_tcp_bind; - public void tcp_bind(UvTcpHandle handle, ref sockaddr addr, int flags) + public void tcp_bind(UvTcpHandle handle, ref SockAddr addr, int flags) { handle.Validate(); Check(_uv_tcp_bind(handle, ref addr, flags)); @@ -365,16 +369,16 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking return _uv_req_size(reqType); } - protected delegate int uv_ip4_addr_func(string ip, int port, out sockaddr addr); + protected delegate int uv_ip4_addr_func(string ip, int port, out SockAddr addr); protected uv_ip4_addr_func _uv_ip4_addr; - public int ip4_addr(string ip, int port, out sockaddr addr, out Exception error) + public int ip4_addr(string ip, int port, out SockAddr addr, out Exception error) { return Check(_uv_ip4_addr(ip, port, out addr), out error); } - protected delegate int uv_ip6_addr_func(string ip, int port, out sockaddr addr); + protected delegate int uv_ip6_addr_func(string ip, int port, out SockAddr addr); protected uv_ip6_addr_func _uv_ip6_addr; - public int ip6_addr(string ip, int port, out sockaddr addr, out Exception error) + public int ip6_addr(string ip, int port, out SockAddr addr, out Exception error) { return Check(_uv_ip6_addr(ip, port, out addr), out error); } @@ -388,26 +392,27 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking _uv_walk(loop, walk_cb, arg); } + public delegate int uv_tcp_getsockname_func(UvTcpHandle handle, out SockAddr addr, ref int namelen); + protected uv_tcp_getsockname_func _uv_tcp_getsockname; + public void tcp_getsockname(UvTcpHandle handle, out SockAddr addr, ref int namelen) + { + handle.Validate(); + Check(_uv_tcp_getsockname(handle, out addr, ref namelen)); + } + + public delegate int uv_tcp_getpeername_func(UvTcpHandle handle, out SockAddr addr, ref int namelen); + protected uv_tcp_getpeername_func _uv_tcp_getpeername; + public void tcp_getpeername(UvTcpHandle handle, out SockAddr addr, ref int namelen) + { + handle.Validate(); + Check(_uv_tcp_getpeername(handle, out addr, ref namelen)); + } + public uv_buf_t buf_init(IntPtr memory, int len) { return new uv_buf_t(memory, len, IsWindows); } - public struct sockaddr - { - // this type represents native memory occupied by sockaddr struct - // https://msdn.microsoft.com/en-us/library/windows/desktop/ms740496(v=vs.85).aspx - // although the c/c++ header defines it as a 2-byte short followed by a 14-byte array, - // the simplest way to reserve the same size in c# is with four nameless long values - - private long _field0; - private long _field1; - private long _field2; - private long _field3; - - public sockaddr(long ignored) { _field3 = _field0 = _field1 = _field2 = _field3 = 0; } - } - public struct uv_buf_t { // this type represents a WSABUF struct on Windows @@ -504,7 +509,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking public static extern int uv_tcp_init(UvLoopHandle loop, UvTcpHandle handle); [DllImport("libuv", CallingConvention = CallingConvention.Cdecl)] - public static extern int uv_tcp_bind(UvTcpHandle handle, ref sockaddr addr, int flags); + public static extern int uv_tcp_bind(UvTcpHandle handle, ref SockAddr addr, int flags); [DllImport("libuv", CallingConvention = CallingConvention.Cdecl)] public static extern int uv_tcp_open(UvTcpHandle handle, IntPtr hSocket); @@ -564,10 +569,16 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking public static extern int uv_req_size(RequestType reqType); [DllImport("libuv", CallingConvention = CallingConvention.Cdecl)] - public static extern int uv_ip4_addr(string ip, int port, out sockaddr addr); + public static extern int uv_ip4_addr(string ip, int port, out SockAddr addr); [DllImport("libuv", CallingConvention = CallingConvention.Cdecl)] - public static extern int uv_ip6_addr(string ip, int port, out sockaddr addr); + public static extern int uv_ip6_addr(string ip, int port, out SockAddr addr); + + [DllImport("libuv", CallingConvention = CallingConvention.Cdecl)] + public static extern int uv_tcp_getsockname(UvTcpHandle handle, out SockAddr name, ref int namelen); + + [DllImport("libuv", CallingConvention = CallingConvention.Cdecl)] + public static extern int uv_tcp_getpeername(UvTcpHandle handle, out SockAddr name, ref int namelen); [DllImport("libuv", CallingConvention = CallingConvention.Cdecl)] unsafe public static extern int uv_walk(UvLoopHandle loop, uv_walk_cb walk_cb, IntPtr arg); @@ -606,7 +617,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking public static extern int uv_tcp_init(UvLoopHandle loop, UvTcpHandle handle); [DllImport("__Internal", CallingConvention = CallingConvention.Cdecl)] - public static extern int uv_tcp_bind(UvTcpHandle handle, ref sockaddr addr, int flags); + public static extern int uv_tcp_bind(UvTcpHandle handle, ref SockAddr addr, int flags); [DllImport("__Internal", CallingConvention = CallingConvention.Cdecl)] public static extern int uv_tcp_open(UvTcpHandle handle, IntPtr hSocket); @@ -666,10 +677,16 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking public static extern int uv_req_size(RequestType reqType); [DllImport("__Internal", CallingConvention = CallingConvention.Cdecl)] - public static extern int uv_ip4_addr(string ip, int port, out sockaddr addr); + public static extern int uv_ip4_addr(string ip, int port, out SockAddr addr); [DllImport("__Internal", CallingConvention = CallingConvention.Cdecl)] - public static extern int uv_ip6_addr(string ip, int port, out sockaddr addr); + public static extern int uv_ip6_addr(string ip, int port, out SockAddr addr); + + [DllImport("__Internal", CallingConvention = CallingConvention.Cdecl)] + public static extern int uv_tcp_getsockname(UvTcpHandle handle, out SockAddr name, ref int namelen); + + [DllImport("__Internal", CallingConvention = CallingConvention.Cdecl)] + public static extern int uv_tcp_getpeername(UvTcpHandle handle, out SockAddr name, ref int namelen); [DllImport("__Internal", CallingConvention = CallingConvention.Cdecl)] unsafe public static extern int uv_walk(UvLoopHandle loop, uv_walk_cb walk_cb, IntPtr arg); diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/SockAddr.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/SockAddr.cs new file mode 100644 index 0000000000..c101de111e --- /dev/null +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/SockAddr.cs @@ -0,0 +1,94 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Net; + +namespace Microsoft.AspNet.Server.Kestrel.Networking +{ + public struct SockAddr + { + // this type represents native memory occupied by sockaddr struct + // https://msdn.microsoft.com/en-us/library/windows/desktop/ms740496(v=vs.85).aspx + // although the c/c++ header defines it as a 2-byte short followed by a 14-byte array, + // the simplest way to reserve the same size in c# is with four nameless long values + private long _field0; + private long _field1; + private long _field2; + private long _field3; + + public SockAddr(long ignored) + { + _field3 = _field0 = _field1 = _field2 = _field3 = 0; + } + + public IPEndPoint GetIPEndPoint() + { + // The bytes are represented in network byte order. + // + // Example 1: [2001:4898:e0:391:b9ef:1124:9d3e:a354]:39179 + // + // 0000 0000 0b99 0017 => The third and fourth bytes 990B is the actual port + // 9103 e000 9848 0120 => IPv6 address is represented in the 128bit field1 and field2. + // 54a3 3e9d 2411 efb9 Read these two 64-bit long from right to left byte by byte. + // 0000 0000 0000 0000 + // + // Example 2: 10.135.34.141:39178 when adopt dual-stack sockets, IPv4 is mapped to IPv6 + // + // 0000 0000 0a99 0017 => The port representation are the same + // 0000 0000 0000 0000 + // 8d22 870a ffff 0000 => IPv4 occupies the last 32 bit: 0A.87.22.8d is the actual address. + // 0000 0000 0000 0000 + // + // Example 3: 10.135.34.141:12804, not dual-stack sockets + // 8d22 870a fd31 0002 => sa_family == AF_INET (02) + // 0000 0000 0000 0000 + // 0000 0000 0000 0000 + // 0000 0000 0000 0000 + + + // Quick calculate the port by mask the field and locate the byte 3 and byte 4 + // and then shift them to correct place to form a int. + var port = ((int)(_field0 & 0x00FF0000) >> 8) | (int)((_field0 & 0xFF000000) >> 24); + + var family = (int)_field0 & 0x000000FF; + if (family == 0x00000002) + { + // AF_INET => IPv4 + return new IPEndPoint(new IPAddress((_field0 >> 32) & 0xFFFFFFFF), port); + } + else if (IsIPv4MappedToIPv6()) + { + var ipv4bits = (_field2 >> 32) & 0x00000000FFFFFFFF; + return new IPEndPoint(new IPAddress(ipv4bits), port); + } + else + { + // otherwise IPv6 + var bytes1 = BitConverter.GetBytes(_field1); + var bytes2 = BitConverter.GetBytes(_field2); + + var bytes = new byte[16]; + for (int i = 0; i < 8; ++i) + { + bytes[i] = bytes1[i]; + bytes[i + 8] = bytes2[i]; + } + + return new IPEndPoint(new IPAddress(bytes), port); + } + } + + private bool IsIPv4MappedToIPv6() + { + // If the IPAddress is an IPv4 mapped to IPv6, return the IPv4 representation instead. + // For example [::FFFF:127.0.0.1] will be transform to IPAddress of 127.0.0.1 + if (_field1 != 0) + { + return false; + } + + return (_field2 & 0xFFFFFFFF) == 0xFFFF0000; + } + } +} diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvTcpHandle.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvTcpHandle.cs index b43e9c985e..cc568cc503 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvTcpHandle.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvTcpHandle.cs @@ -3,6 +3,7 @@ using System; using System.Net; +using System.Runtime.InteropServices; using Microsoft.AspNet.Server.Kestrel.Infrastructure; namespace Microsoft.AspNet.Server.Kestrel.Networking @@ -17,7 +18,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking { CreateMemory( loop.Libuv, - loop.ThreadId, + loop.ThreadId, loop.Libuv.handle_size(Libuv.HandleType.TCP)); _uv.tcp_init(loop, this); @@ -26,7 +27,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking public void Init(UvLoopHandle loop, Action, IntPtr> queueCloseHandle) { CreateHandle( - loop.Libuv, + loop.Libuv, loop.ThreadId, loop.Libuv.handle_size(Libuv.HandleType.TCP), queueCloseHandle); @@ -37,7 +38,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking { var endpoint = CreateIPEndpoint(address); - Libuv.sockaddr addr; + SockAddr addr; var addressText = endpoint.Address.ToString(); Exception error1; @@ -56,6 +57,24 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking _uv.tcp_bind(this, ref addr, 0); } + public IPEndPoint GetPeerIPEndPoint() + { + SockAddr socketAddress; + int namelen = Marshal.SizeOf(); + _uv.tcp_getpeername(this, out socketAddress, ref namelen); + + return socketAddress.GetIPEndPoint(); + } + + public IPEndPoint GetSockIPEndPoint() + { + SockAddr socketAddress; + int namelen = Marshal.SizeOf(); + _uv.tcp_getsockname(this, out socketAddress, ref namelen); + + return socketAddress.GetIPEndPoint(); + } + public void Open(IntPtr hSocket) { _uv.tcp_open(this, hSocket); diff --git a/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/RequestTests.cs b/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/RequestTests.cs index ab6159cffd..f90429cf91 100644 --- a/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/RequestTests.cs +++ b/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/RequestTests.cs @@ -9,6 +9,8 @@ using Microsoft.AspNet.Builder; using Microsoft.AspNet.Hosting; using Microsoft.AspNet.Http; using Microsoft.Extensions.Configuration; +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; using Xunit; namespace Microsoft.AspNet.Server.Kestrel.FunctionalTests @@ -47,7 +49,7 @@ namespace Microsoft.AspNet.Server.Kestrel.FunctionalTests await context.Response.WriteAsync(total.ToString(CultureInfo.InvariantCulture)); }); - }); + }); using (var app = hostBuilder.Build().Start()) { @@ -58,7 +60,7 @@ namespace Microsoft.AspNet.Server.Kestrel.FunctionalTests { bytes[i] = (byte)i; } - + var response = await client.PostAsync("http://localhost:8791/", new ByteArrayContent(bytes)); response.EnsureSuccessStatusCode(); var sizeString = await response.Content.ReadAsStringAsync(); @@ -66,5 +68,60 @@ namespace Microsoft.AspNet.Server.Kestrel.FunctionalTests } } } + + [Theory] + [InlineData("127.0.0.1", "127.0.0.1", "8792")] + [InlineData("localhost", "127.0.0.1", "8792")] + public Task RemoteIPv4Address(string requestAddress, string expectAddress, string port) + { + return TestRemoteIPAddress("localhost", requestAddress, expectAddress, port); + } + + [Fact] + public Task RemoteIPv6Address() + { + return TestRemoteIPAddress("[::1]", "[::1]", "::1", "8792"); + } + + private async Task TestRemoteIPAddress(string registerAddress, string requestAddress, string expectAddress, string port) + { + var config = new ConfigurationBuilder().AddInMemoryCollection( + new Dictionary { + { "server.urls", $"http://{registerAddress}:{port}" } + }).Build(); + + var builder = new WebHostBuilder(config) + .UseServer("Microsoft.AspNet.Server.Kestrel") + .UseStartup(app => + { + app.Run(async context => + { + var connection = context.Connection; + await context.Response.WriteAsync(JsonConvert.SerializeObject(new + { + RemoteIPAddress = connection.RemoteIpAddress?.ToString(), + RemotePort = connection.RemotePort, + LocalIPAddress = connection.LocalIpAddress?.ToString(), + LocalPort = connection.LocalPort, + IsLocal = connection.IsLocal + })); + }); + }); + + using (var app = builder.Build().Start()) + using (var client = new HttpClient()) + { + var response = await client.GetAsync($"http://{requestAddress}:{port}/"); + response.EnsureSuccessStatusCode(); + + var connectionFacts = await response.Content.ReadAsStringAsync(); + Assert.NotEmpty(connectionFacts); + + var facts = JsonConvert.DeserializeObject(connectionFacts); + Assert.Equal(expectAddress, facts["RemoteIPAddress"].Value()); + Assert.NotEmpty(facts["RemotePort"].Value()); + Assert.True(facts["IsLocal"].Value()); + } + } } -} +} \ No newline at end of file diff --git a/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/FrameFeatureCollection.cs b/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/FrameFeatureCollection.cs index f8dcf8d927..62b8e19245 100644 --- a/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/FrameFeatureCollection.cs +++ b/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/FrameFeatureCollection.cs @@ -66,6 +66,7 @@ namespace Microsoft.AspNet.Server.Kestrel.GeneratedCode typeof(IHttpRequestFeature), typeof(IHttpResponseFeature), typeof(IHttpUpgradeFeature), + typeof(IHttpConnectionFeature) }; return $@" From 1722150ee99999079e5d7c7d4565102e25e617a2 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Wed, 28 Oct 2015 16:18:51 -0700 Subject: [PATCH 0380/1662] Do nothing in KestrelThread.Stop if libuv fails to load This prevents DllNotFoundExceptions from being masked by NullReferenceExceptions --- .../Infrastructure/KestrelThread.cs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs index 6c26ec71b1..85a4b50621 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs @@ -30,6 +30,7 @@ namespace Microsoft.AspNet.Server.Kestrel private Queue _closeHandleRunning = new Queue(); private object _workSync = new Object(); private bool _stopImmediate = false; + private bool _initCompleted = false; private ExceptionDispatchInfo _closeError; private IKestrelTrace _log; @@ -58,6 +59,11 @@ namespace Microsoft.AspNet.Server.Kestrel public void Stop(TimeSpan timeout) { + if (!_initCompleted) + { + return; + } + Post(OnStop, null); if (!_thread.Join((int)timeout.TotalMilliseconds)) { @@ -195,8 +201,11 @@ namespace Microsoft.AspNet.Server.Kestrel catch (Exception ex) { tcs.SetException(ex); + return; } + _initCompleted = true; + try { var ran1 = _loop.Run(); From 777f52313559a85ece8d8f701571926a24110353 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Mon, 26 Oct 2015 18:57:46 -0700 Subject: [PATCH 0381/1662] Update System.Net.Sockets dependency in test project to 4.1.0 - This only affects the test project - The Socket.*Async extension methods are available for net46 but not net451 so we ifdef. --- .../NetworkingTests.cs | 20 +++++++++++++++++++ .../project.json | 2 +- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/test/Microsoft.AspNet.Server.KestrelTests/NetworkingTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/NetworkingTests.cs index e4f1a48590..fa8a3ada30 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/NetworkingTests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/NetworkingTests.cs @@ -92,12 +92,16 @@ namespace Microsoft.AspNet.Server.KestrelTests AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); +#if DNX451 await Task.Factory.FromAsync( socket.BeginConnect, socket.EndConnect, new IPEndPoint(IPAddress.Loopback, 54321), null, TaskCreationOptions.None); +#else + await socket.ConnectAsync(new IPEndPoint(IPAddress.Loopback, 54321)); +#endif socket.Dispose(); }); loop.Run(); @@ -141,6 +145,7 @@ namespace Microsoft.AspNet.Server.KestrelTests AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); +#if DNX451 await Task.Factory.FromAsync( socket.BeginConnect, socket.EndConnect, @@ -154,6 +159,11 @@ namespace Microsoft.AspNet.Server.KestrelTests SocketFlags.None, null, TaskCreationOptions.None); +#else + await socket.ConnectAsync(new IPEndPoint(IPAddress.Loopback, 54321)); + await socket.SendAsync(new[] { new ArraySegment(new byte[] { 1, 2, 3, 4, 5 }) }, + SocketFlags.None); +#endif socket.Dispose(); }); loop.Run(); @@ -211,6 +221,7 @@ namespace Microsoft.AspNet.Server.KestrelTests AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); +#if DNX451 await Task.Factory.FromAsync( socket.BeginConnect, socket.EndConnect, @@ -224,10 +235,16 @@ namespace Microsoft.AspNet.Server.KestrelTests SocketFlags.None, null, TaskCreationOptions.None); +#else + await socket.ConnectAsync(new IPEndPoint(IPAddress.Loopback, 54321)); + await socket.SendAsync(new[] { new ArraySegment(new byte[] { 1, 2, 3, 4, 5 }) }, + SocketFlags.None); +#endif socket.Shutdown(SocketShutdown.Send); var buffer = new ArraySegment(new byte[2048]); while (true) { +#if DNX451 var count = await Task.Factory.FromAsync( socket.BeginReceive, socket.EndReceive, @@ -235,6 +252,9 @@ namespace Microsoft.AspNet.Server.KestrelTests SocketFlags.None, null, TaskCreationOptions.None); +#else + var count = await socket.ReceiveAsync(new[] { buffer }, SocketFlags.None); +#endif Console.WriteLine("count {0} {1}", count, System.Text.Encoding.ASCII.GetString(buffer.Array, 0, count)); diff --git a/test/Microsoft.AspNet.Server.KestrelTests/project.json b/test/Microsoft.AspNet.Server.KestrelTests/project.json index 9cb03bd95e..7874fbb32f 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/project.json +++ b/test/Microsoft.AspNet.Server.KestrelTests/project.json @@ -16,7 +16,7 @@ "dependencies": { "System.Diagnostics.TraceSource": "4.0.0-beta-*", "System.IO": "4.0.11-beta-*", - "System.Net.Sockets": "4.0.10-beta-*", + "System.Net.Sockets": "4.1.0-beta-*", "System.Runtime.Handles": "4.0.1-beta-*" } } From af2c32f612f68ee68f490c7e93f6e80aa45d407c Mon Sep 17 00:00:00 2001 From: Pavel Krymets Date: Fri, 30 Oct 2015 10:52:59 -0700 Subject: [PATCH 0382/1662] React to xunit change. Fix build error --- test/Microsoft.AspNet.Server.KestrelTests/Program.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Microsoft.AspNet.Server.KestrelTests/Program.cs b/test/Microsoft.AspNet.Server.KestrelTests/Program.cs index 813a581bf1..0b825ad664 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/Program.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/Program.cs @@ -27,7 +27,7 @@ namespace Microsoft.AspNet.Server.KestrelTests public int Main() { - return new Xunit.Runner.Dnx.Program(env, sp, _libraryManager).Main(new string[] + return Xunit.Runner.Dnx.Program.Main(new string[] { "-class", typeof(MultipleLoopTests).FullName From b466c3b7d7aba238867c2e57f54b9d44cf5b3ead Mon Sep 17 00:00:00 2001 From: John Luo Date: Thu, 29 Oct 2015 14:18:34 -0700 Subject: [PATCH 0383/1662] Reacting to Hosting changes --- .../Http/Frame.cs | 5 +- .../Http/Listener.cs | 3 +- .../Http/ListenerContext.cs | 5 +- .../Http/ListenerPrimary.cs | 3 +- .../Http/ListenerSecondary.cs | 3 +- .../KestrelEngine.cs | 5 +- .../KestrelServer.cs | 128 ++++++++++++++++++ .../ServerFactory.cs | 84 ++---------- .../ServiceContext.cs | 4 + .../AddressRegistrationTests.cs | 2 +- .../RequestTests.cs | 2 +- .../ResponseTests.cs | 2 +- .../ThreadCountTests.cs | 2 +- .../ChunkedResponseTests.cs | 21 ++- .../ConnectionFilterTests.cs | 8 +- .../EngineTests.cs | 50 +++---- .../HttpsConnectionFilterTests.cs | 9 +- .../TestServer.cs | 11 +- .../TestServiceContext.cs | 7 +- 19 files changed, 212 insertions(+), 142 deletions(-) create mode 100644 src/Microsoft.AspNet.Server.Kestrel/KestrelServer.cs diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs index 7f51d8e7d4..36f1d92319 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs @@ -206,9 +206,10 @@ namespace Microsoft.AspNet.Server.Kestrel.Http ResponseBody = new FrameResponseStream(this); DuplexStream = new FrameDuplexStream(RequestBody, ResponseBody); + var httpContext = HttpContextFactory.Create(this); try { - await Application.Invoke(this).ConfigureAwait(false); + await Application.Invoke(httpContext).ConfigureAwait(false); } catch (Exception ex) { @@ -227,6 +228,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http await FireOnCompleted(); + HttpContextFactory.Dispose(httpContext); + await ProduceEnd(); while (await RequestBody.ReadAsync(_nullBuffer, 0, _nullBuffer.Length) != 0) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs index 8cfba60cd0..a7b72acc01 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs @@ -3,6 +3,7 @@ using System; using System.Threading.Tasks; +using Microsoft.AspNet.Http; using Microsoft.AspNet.Server.Kestrel.Networking; using Microsoft.Extensions.Logging; @@ -23,7 +24,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http public Task StartAsync( ServerAddress address, KestrelThread thread, - Func application) + RequestDelegate application) { ServerAddress = address; Thread = thread; diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerContext.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerContext.cs index 79a096d4d4..5817200410 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerContext.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerContext.cs @@ -1,8 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System; -using System.Threading.Tasks; +using Microsoft.AspNet.Http; using Microsoft.AspNet.Server.Kestrel.Infrastructure; namespace Microsoft.AspNet.Server.Kestrel.Http @@ -34,7 +33,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http public KestrelThread Thread { get; set; } - public Func Application { get; set; } + public RequestDelegate Application { get; set; } public MemoryPool2 Memory2 { get; set; } } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerPrimary.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerPrimary.cs index 41aeeb3bfa..21c6c55183 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerPrimary.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerPrimary.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using System.Threading.Tasks; +using Microsoft.AspNet.Http; using Microsoft.AspNet.Server.Kestrel.Infrastructure; using Microsoft.AspNet.Server.Kestrel.Networking; using Microsoft.Extensions.Logging; @@ -33,7 +34,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http string pipeName, ServerAddress address, KestrelThread thread, - Func application) + RequestDelegate application) { await StartAsync(address, thread, application).ConfigureAwait(false); diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerSecondary.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerSecondary.cs index a348970737..814ea3ffe3 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerSecondary.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerSecondary.cs @@ -4,6 +4,7 @@ using System; using System.Runtime.InteropServices; using System.Threading.Tasks; +using Microsoft.AspNet.Http; using Microsoft.AspNet.Server.Kestrel.Infrastructure; using Microsoft.AspNet.Server.Kestrel.Networking; using Microsoft.Extensions.Logging; @@ -26,7 +27,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http string pipeName, ServerAddress address, KestrelThread thread, - Func application) + RequestDelegate application) { ServerAddress = address; Thread = thread; diff --git a/src/Microsoft.AspNet.Server.Kestrel/KestrelEngine.cs b/src/Microsoft.AspNet.Server.Kestrel/KestrelEngine.cs index 32dd5dab98..b0150cad1d 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/KestrelEngine.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/KestrelEngine.cs @@ -3,8 +3,7 @@ using System; using System.Collections.Generic; -using System.Threading.Tasks; -using Microsoft.AspNet.Http.Features; +using Microsoft.AspNet.Http; using Microsoft.AspNet.Server.Kestrel.Http; using Microsoft.AspNet.Server.Kestrel.Networking; @@ -49,7 +48,7 @@ namespace Microsoft.AspNet.Server.Kestrel Threads.Clear(); } - public IDisposable CreateServer(ServerAddress address, Func application) + public IDisposable CreateServer(ServerAddress address, RequestDelegate application) { var listeners = new List(); diff --git a/src/Microsoft.AspNet.Server.Kestrel/KestrelServer.cs b/src/Microsoft.AspNet.Server.Kestrel/KestrelServer.cs new file mode 100644 index 0000000000..ff0ca62422 --- /dev/null +++ b/src/Microsoft.AspNet.Server.Kestrel/KestrelServer.cs @@ -0,0 +1,128 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Collections.Generic; +using Microsoft.AspNet.Hosting; +using Microsoft.AspNet.Hosting.Server; +using Microsoft.AspNet.Http; +using Microsoft.AspNet.Http.Features; +using Microsoft.AspNet.Server.Kestrel.Http; +using Microsoft.Extensions.Logging; + +namespace Microsoft.AspNet.Server.Kestrel +{ + public class KestrelServer : IServer + { + private Stack _disposables; + private readonly IApplicationLifetime _applicationLifetime; + private readonly ILogger _logger; + private readonly IHttpContextFactory _httpContextFactory; + + public KestrelServer(IFeatureCollection features, IApplicationLifetime applicationLifetime, ILogger logger, IHttpContextFactory httpContextFactory) + { + if (features == null) + { + throw new ArgumentNullException(nameof(features)); + } + + if (applicationLifetime == null) + { + throw new ArgumentNullException(nameof(applicationLifetime)); + } + + if (logger == null) + { + throw new ArgumentNullException(nameof(logger)); + } + + if (httpContextFactory == null) + { + throw new ArgumentNullException(nameof(httpContextFactory)); + } + + _applicationLifetime = applicationLifetime; + _logger = logger; + Features = features; + _httpContextFactory = httpContextFactory; + } + + public IFeatureCollection Features { get; } + + public void Start(RequestDelegate requestDelegate) + { + if (_disposables != null) + { + // The server has already started and/or has not been cleaned up yet + throw new InvalidOperationException("Server has already started."); + } + _disposables = new Stack(); + + try + { + var information = (KestrelServerInformation)Features.Get(); + var dateHeaderValueManager = new DateHeaderValueManager(); + var engine = new KestrelEngine(new ServiceContext + { + AppLifetime = _applicationLifetime, + Log = new KestrelTrace(_logger), + HttpContextFactory = _httpContextFactory, + DateHeaderValueManager = dateHeaderValueManager, + ConnectionFilter = information.ConnectionFilter, + NoDelay = information.NoDelay + }); + + _disposables.Push(engine); + _disposables.Push(dateHeaderValueManager); + + if (information.ThreadCount < 0) + { + throw new ArgumentOutOfRangeException(nameof(information.ThreadCount), + information.ThreadCount, + "ThreadCount cannot be negative"); + } + + engine.Start(information.ThreadCount == 0 ? 1 : information.ThreadCount); + var atLeastOneListener = false; + + foreach (var address in information.Addresses) + { + var parsedAddress = ServerAddress.FromUrl(address); + if (parsedAddress == null) + { + throw new FormatException("Unrecognized listening address: " + address); + } + else + { + atLeastOneListener = true; + _disposables.Push(engine.CreateServer( + parsedAddress, + requestDelegate)); + } + } + + if (!atLeastOneListener) + { + throw new InvalidOperationException("No recognized listening addresses were configured."); + } + } + catch + { + Dispose(); + throw; + } + } + + public void Dispose() + { + if (_disposables != null) + { + while (_disposables.Count > 0) + { + _disposables.Pop().Dispose(); + } + _disposables = null; + } + } + } +} diff --git a/src/Microsoft.AspNet.Server.Kestrel/ServerFactory.cs b/src/Microsoft.AspNet.Server.Kestrel/ServerFactory.cs index c0b42c0d2c..158e089fee 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/ServerFactory.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/ServerFactory.cs @@ -1,14 +1,11 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System; -using System.Collections.Generic; -using System.Threading.Tasks; using Microsoft.AspNet.Hosting; using Microsoft.AspNet.Hosting.Server; +using Microsoft.AspNet.Http; using Microsoft.AspNet.Http.Features; using Microsoft.AspNet.Server.Features; -using Microsoft.AspNet.Server.Kestrel.Http; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Logging; @@ -20,89 +17,24 @@ namespace Microsoft.AspNet.Server.Kestrel public class ServerFactory : IServerFactory { private readonly IApplicationLifetime _appLifetime; - private readonly ILogger _logger; + private readonly ILoggerFactory _loggerFactory; + private readonly IHttpContextFactory _httpContextFactory; - public ServerFactory(IApplicationLifetime appLifetime, ILoggerFactory loggerFactory) + public ServerFactory(IApplicationLifetime appLifetime, ILoggerFactory loggerFactory, IHttpContextFactory httpContextFactory) { _appLifetime = appLifetime; - _logger = loggerFactory.CreateLogger("Microsoft.AspNet.Server.Kestrel"); + _loggerFactory = loggerFactory; + _httpContextFactory = httpContextFactory; } - public IFeatureCollection Initialize(IConfiguration configuration) + public IServer CreateServer(IConfiguration configuration) { var information = new KestrelServerInformation(); information.Initialize(configuration); var serverFeatures = new FeatureCollection(); serverFeatures.Set(information); serverFeatures.Set(information); - return serverFeatures; - } - - public IDisposable Start(IFeatureCollection serverFeatures, Func application) - { - var disposables = new Stack(); - var disposer = new Disposable(() => - { - foreach (var disposable in disposables) - { - disposable.Dispose(); - } - }); - - try - { - var information = (KestrelServerInformation)serverFeatures.Get(); - var dateHeaderValueManager = new DateHeaderValueManager(); - var engine = new KestrelEngine(new ServiceContext - { - AppLifetime = _appLifetime, - Log = new KestrelTrace(_logger), - DateHeaderValueManager = dateHeaderValueManager, - ConnectionFilter = information.ConnectionFilter, - NoDelay = information.NoDelay - }); - - disposables.Push(engine); - disposables.Push(dateHeaderValueManager); - - if (information.ThreadCount < 0) - { - throw new ArgumentOutOfRangeException(nameof(information.ThreadCount), - information.ThreadCount, - "ThreadCount cannot be negative"); - } - - engine.Start(information.ThreadCount == 0 ? 1 : information.ThreadCount); - bool atLeastOneListener = false; - - foreach (var address in information.Addresses) - { - var parsedAddress = ServerAddress.FromUrl(address); - if (parsedAddress == null) - { - throw new FormatException("Unrecognized listening address: " + address); - } - else - { - atLeastOneListener = true; - disposables.Push(engine.CreateServer( - parsedAddress, - application)); - } - } - - if (!atLeastOneListener) - { - throw new InvalidOperationException("No recognized listening addresses were configured."); - } - - return disposer; - } - catch - { - disposer.Dispose(); - throw; - } + return new KestrelServer(serverFeatures, _appLifetime, _loggerFactory.CreateLogger("Microsoft.AspNet.Server.Kestrel"), _httpContextFactory); } } } diff --git a/src/Microsoft.AspNet.Server.Kestrel/ServiceContext.cs b/src/Microsoft.AspNet.Server.Kestrel/ServiceContext.cs index 35086de40d..d3d1539a59 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/ServiceContext.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/ServiceContext.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using Microsoft.AspNet.Hosting; +using Microsoft.AspNet.Http; using Microsoft.AspNet.Server.Kestrel.Filter; using Microsoft.AspNet.Server.Kestrel.Http; using Microsoft.AspNet.Server.Kestrel.Infrastructure; @@ -20,6 +21,7 @@ namespace Microsoft.AspNet.Server.Kestrel AppLifetime = context.AppLifetime; Memory = context.Memory; Log = context.Log; + HttpContextFactory = context.HttpContextFactory; DateHeaderValueManager = context.DateHeaderValueManager; ConnectionFilter = context.ConnectionFilter; NoDelay = context.NoDelay; @@ -31,6 +33,8 @@ namespace Microsoft.AspNet.Server.Kestrel public IKestrelTrace Log { get; set; } + public IHttpContextFactory HttpContextFactory { get; set; } + public DateHeaderValueManager DateHeaderValueManager { get; set; } public IConnectionFilter ConnectionFilter { get; set; } diff --git a/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs b/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs index cabb74761b..00f6db432d 100644 --- a/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs +++ b/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs @@ -26,7 +26,7 @@ namespace Microsoft.AspNet.Server.Kestrel.FunctionalTests .Build(); var hostBuilder = new WebHostBuilder(config); - hostBuilder.UseServer("Microsoft.AspNet.Server.Kestrel"); + hostBuilder.UseServerFactory("Microsoft.AspNet.Server.Kestrel"); hostBuilder.UseStartup(ConfigureEchoAddress); using (var app = hostBuilder.Build().Start()) diff --git a/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/RequestTests.cs b/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/RequestTests.cs index f90429cf91..99e0c067cf 100644 --- a/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/RequestTests.cs +++ b/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/RequestTests.cs @@ -28,7 +28,7 @@ namespace Microsoft.AspNet.Server.Kestrel.FunctionalTests .Build(); var hostBuilder = new WebHostBuilder(config); - hostBuilder.UseServer("Microsoft.AspNet.Server.Kestrel"); + hostBuilder.UseServerFactory("Microsoft.AspNet.Server.Kestrel"); hostBuilder.UseStartup(app => { app.Run(async context => diff --git a/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/ResponseTests.cs b/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/ResponseTests.cs index 54216dcdb8..245729d94e 100644 --- a/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/ResponseTests.cs +++ b/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/ResponseTests.cs @@ -24,7 +24,7 @@ namespace Microsoft.AspNet.Server.Kestrel.FunctionalTests .Build(); var hostBuilder = new WebHostBuilder(config); - hostBuilder.UseServer("Microsoft.AspNet.Server.Kestrel"); + hostBuilder.UseServerFactory("Microsoft.AspNet.Server.Kestrel"); hostBuilder.UseStartup(app => { app.Run(async context => diff --git a/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/ThreadCountTests.cs b/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/ThreadCountTests.cs index dabe7c4abe..ea654651e3 100644 --- a/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/ThreadCountTests.cs +++ b/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/ThreadCountTests.cs @@ -26,7 +26,7 @@ namespace Microsoft.AspNet.Server.Kestrel.FunctionalTests .Build(); var hostBuilder = new WebHostBuilder(config); - hostBuilder.UseServer("Microsoft.AspNet.Server.Kestrel"); + hostBuilder.UseServerFactory("Microsoft.AspNet.Server.Kestrel"); hostBuilder.UseStartup(app => { var serverInfo = app.ServerFeatures.Get(); diff --git a/test/Microsoft.AspNet.Server.KestrelTests/ChunkedResponseTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/ChunkedResponseTests.cs index d84bf41df1..ca01df5f41 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/ChunkedResponseTests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/ChunkedResponseTests.cs @@ -4,7 +4,6 @@ using System; using System.Text; using System.Threading.Tasks; -using Microsoft.AspNet.Http.Features; using Xunit; namespace Microsoft.AspNet.Server.KestrelTests @@ -14,9 +13,9 @@ namespace Microsoft.AspNet.Server.KestrelTests [Fact] public async Task ResponsesAreChunkedAutomatically() { - using (var server = new TestServer(async frame => + using (var server = new TestServer(async httpContext => { - var response = frame.Get(); + var response = httpContext.Response; response.Headers.Clear(); await response.Body.WriteAsync(Encoding.ASCII.GetBytes("Hello "), 0, 6); await response.Body.WriteAsync(Encoding.ASCII.GetBytes("World!"), 0, 6); @@ -46,9 +45,9 @@ namespace Microsoft.AspNet.Server.KestrelTests [Fact] public async Task ZeroLengthWritesAreIgnored() { - using (var server = new TestServer(async frame => + using (var server = new TestServer(async httpContext => { - var response = frame.Get(); + var response = httpContext.Response; response.Headers.Clear(); await response.Body.WriteAsync(Encoding.ASCII.GetBytes("Hello "), 0, 6); await response.Body.WriteAsync(new byte[0], 0, 0); @@ -79,9 +78,9 @@ namespace Microsoft.AspNet.Server.KestrelTests [Fact] public async Task EmptyResponseBodyHandledCorrectlyWithZeroLengthWrite() { - using (var server = new TestServer(async frame => + using (var server = new TestServer(async httpContext => { - var response = frame.Get(); + var response = httpContext.Response; response.Headers.Clear(); await response.Body.WriteAsync(new byte[0], 0, 0); })) @@ -106,9 +105,9 @@ namespace Microsoft.AspNet.Server.KestrelTests [Fact] public async Task ConnectionClosedIfExeptionThrownAfterWrite() { - using (var server = new TestServer(async frame => + using (var server = new TestServer(async httpContext => { - var response = frame.Get(); + var response = httpContext.Response; response.Headers.Clear(); await response.Body.WriteAsync(Encoding.ASCII.GetBytes("Hello World!"), 0, 12); throw new Exception(); @@ -136,9 +135,9 @@ namespace Microsoft.AspNet.Server.KestrelTests [Fact] public async Task ConnectionClosedIfExeptionThrownAfterZeroLengthWrite() { - using (var server = new TestServer(async frame => + using (var server = new TestServer(async httpContext => { - var response = frame.Get(); + var response = httpContext.Response; response.Headers.Clear(); await response.Body.WriteAsync(new byte[0], 0, 0); throw new Exception(); diff --git a/test/Microsoft.AspNet.Server.KestrelTests/ConnectionFilterTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/ConnectionFilterTests.cs index b37d72a6e2..d4dfc5fe9b 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/ConnectionFilterTests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/ConnectionFilterTests.cs @@ -4,7 +4,7 @@ using System.IO; using System.Threading.Tasks; using Microsoft.AspNet.Server.Kestrel.Filter; -using Microsoft.AspNet.Server.Kestrel.Http; +using Microsoft.AspNet.Http; using Microsoft.AspNet.Http.Features; using Xunit; @@ -12,10 +12,10 @@ namespace Microsoft.AspNet.Server.KestrelTests { public class ConnectionFilterTests { - private async Task App(IFeatureCollection frame) + private async Task App(HttpContext httpContext) { - var request = frame.Get(); - var response = frame.Get(); + var request = httpContext.Request; + var response = httpContext.Response; response.Headers.Clear(); while (true) { diff --git a/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs index 1d2cba53c0..299ba25fe6 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs @@ -7,7 +7,7 @@ using System.Net; using System.Net.Sockets; using System.Text; using System.Threading.Tasks; -using Microsoft.AspNet.Http.Features; +using Microsoft.AspNet.Http; using Microsoft.AspNet.Server.Kestrel; using Microsoft.AspNet.Server.Kestrel.Filter; using Microsoft.Extensions.Logging; @@ -39,10 +39,10 @@ namespace Microsoft.AspNet.Server.KestrelTests } } - private async Task App(IFeatureCollection frame) + private async Task App(HttpContext httpContext) { - var request = frame.Get(); - var response = frame.Get(); + var request = httpContext.Request; + var response = httpContext.Response; response.Headers.Clear(); while (true) { @@ -56,10 +56,10 @@ namespace Microsoft.AspNet.Server.KestrelTests } } - private async Task AppChunked(IFeatureCollection frame) + private async Task AppChunked(HttpContext httpContext) { - var request = frame.Get(); - var response = frame.Get(); + var request = httpContext.Request; + var response = httpContext.Response; var data = new MemoryStream(); await request.Body.CopyToAsync(data); var bytes = data.ToArray(); @@ -69,9 +69,9 @@ namespace Microsoft.AspNet.Server.KestrelTests await response.Body.WriteAsync(bytes, 0, bytes.Length); } - private Task EmptyApp(IFeatureCollection frame) + private Task EmptyApp(HttpContext httpContext) { - frame.Get().Headers.Clear(); + httpContext.Response.Headers.Clear(); return Task.FromResult(null); } @@ -471,10 +471,10 @@ namespace Microsoft.AspNet.Server.KestrelTests [MemberData(nameof(ConnectionFilterData))] public async Task ZeroContentLengthNotSetAutomaticallyForCertainStatusCodes(ServiceContext testContext) { - using (var server = new TestServer(async frame => + using (var server = new TestServer(async httpContext => { - var request = frame.Get(); - var response = frame.Get(); + var request = httpContext.Request; + var response = httpContext.Response; response.Headers.Clear(); using (var reader = new StreamReader(request.Body, Encoding.ASCII)) @@ -529,9 +529,9 @@ namespace Microsoft.AspNet.Server.KestrelTests var testLogger = new TestApplicationErrorLogger(); testContext.Log = new KestrelTrace(testLogger); - using (var server = new TestServer(frame => + using (var server = new TestServer(httpContext => { - var response = frame.Get(); + var response = httpContext.Response; response.OnStarting(_ => { onStartingCalled = true; @@ -586,9 +586,9 @@ namespace Microsoft.AspNet.Server.KestrelTests var testLogger = new TestApplicationErrorLogger(); testContext.Log = new KestrelTrace(testLogger); - using (var server = new TestServer(async frame => + using (var server = new TestServer(async httpContext => { - var response = frame.Get(); + var response = httpContext.Response; response.OnStarting(_ => { onStartingCalled = true; @@ -628,9 +628,9 @@ namespace Microsoft.AspNet.Server.KestrelTests var testLogger = new TestApplicationErrorLogger(); testContext.Log = new KestrelTrace(testLogger); - using (var server = new TestServer(async frame => + using (var server = new TestServer(async httpContext => { - var response = frame.Get(); + var response = httpContext.Response; response.OnStarting(_ => { onStartingCalled = true; @@ -741,11 +741,11 @@ namespace Microsoft.AspNet.Server.KestrelTests var testLogger = new TestApplicationErrorLogger(); testContext.Log = new KestrelTrace(testLogger); - using (var server = new TestServer(async frame => + using (var server = new TestServer(async httpContext => { var onStartingException = new Exception(); - var response = frame.Get(); + var response = httpContext.Response; response.OnStarting(_ => { onStartingCallCount1++; @@ -812,9 +812,9 @@ namespace Microsoft.AspNet.Server.KestrelTests var testLogger = new TestApplicationErrorLogger(); testContext.Log = new KestrelTrace(testLogger); - using (var server = new TestServer(async frame => + using (var server = new TestServer(async httpContext => { - var response = frame.Get(); + var response = httpContext.Response; response.OnCompleted(_ => { onCompletedCalled1 = true; @@ -856,10 +856,10 @@ namespace Microsoft.AspNet.Server.KestrelTests [MemberData(nameof(ConnectionFilterData))] public async Task RequestBodyIsConsumedAutomaticallyIfAppDoesntConsumeItFully(ServiceContext testContext) { - using (var server = new TestServer(async frame => + using (var server = new TestServer(async httpContext => { - var response = frame.Get(); - var request = frame.Get(); + var response = httpContext.Response; + var request = httpContext.Request; Assert.Equal("POST", request.Method); diff --git a/test/Microsoft.AspNet.Server.KestrelTests/HttpsConnectionFilterTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/HttpsConnectionFilterTests.cs index c44569899b..b4e5dbe443 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/HttpsConnectionFilterTests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/HttpsConnectionFilterTests.cs @@ -8,21 +8,20 @@ using System.Net.Http; using System.Net.Security; using System.Security.Cryptography.X509Certificates; using System.Threading.Tasks; +using Microsoft.AspNet.Http; using Microsoft.AspNet.Server.Kestrel.Filter; -using Microsoft.AspNet.Server.Kestrel.Http; using Microsoft.AspNet.Server.Kestrel.Https; using Microsoft.AspNet.Testing.xunit; using Xunit; -using Microsoft.AspNet.Http.Features; namespace Microsoft.AspNet.Server.KestrelTests { public class HttpsConnectionFilterTests { - private async Task App(IFeatureCollection frame) + private async Task App(HttpContext httpContext) { - var request = frame.Get(); - var response = frame.Get(); + var request = httpContext.Request; + var response = httpContext.Response; response.Headers.Clear(); while (true) { diff --git a/test/Microsoft.AspNet.Server.KestrelTests/TestServer.cs b/test/Microsoft.AspNet.Server.KestrelTests/TestServer.cs index d4721d72f1..70f9fd1cb7 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/TestServer.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/TestServer.cs @@ -2,9 +2,8 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.Threading.Tasks; +using Microsoft.AspNet.Http; using Microsoft.AspNet.Server.Kestrel; -using Microsoft.AspNet.Http.Features; namespace Microsoft.AspNet.Server.KestrelTests { @@ -16,22 +15,22 @@ namespace Microsoft.AspNet.Server.KestrelTests private KestrelEngine _engine; private IDisposable _server; - public TestServer(Func app) + public TestServer(RequestDelegate app) : this(app, new TestServiceContext()) { } - public TestServer(Func app, ServiceContext context) + public TestServer(RequestDelegate app, ServiceContext context) : this(app, context, "http://localhost:54321/") { } - public TestServer(Func app, ServiceContext context, string serverAddress) + public TestServer(RequestDelegate app, ServiceContext context, string serverAddress) { Create(app, context, serverAddress); } - public void Create(Func app, ServiceContext context, string serverAddress) + public void Create(RequestDelegate app, ServiceContext context, string serverAddress) { _engine = new KestrelEngine(context); _engine.Start(1); diff --git a/test/Microsoft.AspNet.Server.KestrelTests/TestServiceContext.cs b/test/Microsoft.AspNet.Server.KestrelTests/TestServiceContext.cs index edbeb9c44b..3badc340b7 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/TestServiceContext.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/TestServiceContext.cs @@ -1,4 +1,8 @@ -using Microsoft.AspNet.Server.Kestrel; +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using Microsoft.AspNet.Http.Internal; +using Microsoft.AspNet.Server.Kestrel; namespace Microsoft.AspNet.Server.KestrelTests { @@ -8,6 +12,7 @@ namespace Microsoft.AspNet.Server.KestrelTests { AppLifetime = new LifetimeNotImplemented(); Log = new TestKestrelTrace(); + HttpContextFactory = new HttpContextFactory(new HttpContextAccessor()); DateHeaderValueManager = new TestDateHeaderValueManager(); } } From facf3ad0da635e2c7da79e0da4acc88ec25263b0 Mon Sep 17 00:00:00 2001 From: John Luo Date: Fri, 30 Oct 2015 16:18:50 -0700 Subject: [PATCH 0384/1662] Missed update for test when reacting to hosting changes --- .../RequestTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/RequestTests.cs b/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/RequestTests.cs index 99e0c067cf..1c75f43a7d 100644 --- a/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/RequestTests.cs +++ b/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/RequestTests.cs @@ -91,7 +91,7 @@ namespace Microsoft.AspNet.Server.Kestrel.FunctionalTests }).Build(); var builder = new WebHostBuilder(config) - .UseServer("Microsoft.AspNet.Server.Kestrel") + .UseServerFactory("Microsoft.AspNet.Server.Kestrel") .UseStartup(app => { app.Run(async context => From dd7c4b374d4e9259e621fae2262d936f8d31c61b Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Sat, 31 Oct 2015 01:53:24 +0000 Subject: [PATCH 0385/1662] Fix LibuvCopier DNXCore compile error --- tools/Microsoft.AspNet.Server.Kestrel.LibuvCopier/Program.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/Microsoft.AspNet.Server.Kestrel.LibuvCopier/Program.cs b/tools/Microsoft.AspNet.Server.Kestrel.LibuvCopier/Program.cs index 9ee4d03ad7..b76dd16fe8 100644 --- a/tools/Microsoft.AspNet.Server.Kestrel.LibuvCopier/Program.cs +++ b/tools/Microsoft.AspNet.Server.Kestrel.LibuvCopier/Program.cs @@ -66,7 +66,7 @@ namespace Microsoft.AspNet.Server.Kestrel.LibuvCopier #if DNX451 return Environment.GetFolderPath(Environment.SpecialFolder.UserProfile); #else - var runtimeEnv = PlatformServices.Default.Runtime; + var runtimeEnv = Extensions.PlatformAbstractions.PlatformServices.Default.Runtime; if (runtimeEnv.OperatingSystem == "Windows") { return Environment.GetEnvironmentVariable("USERPROFILE") ?? From ea6f6b10dc5571d6050fc38514f6b4d9b8b3f222 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Sun, 1 Nov 2015 13:27:17 +0000 Subject: [PATCH 0386/1662] Don't capture connection on closure --- src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs index ac0540d182..4061f1e80a 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs @@ -13,8 +13,10 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { public class Connection : ConnectionContext, IConnectionControl { - private static readonly Action _readCallback = ReadCallback; - private static readonly Func _allocCallback = AllocCallback; + private static readonly Action _readCallback = + (handle, status, state) => ReadCallback(handle, status, state); + private static readonly Func _allocCallback = + (handle, suggestedsize, state) => AllocCallback(handle, suggestedsize, state); private static long _lastConnectionId; @@ -83,12 +85,12 @@ namespace Microsoft.AspNet.Server.Kestrel.Http if (task.IsFaulted) { connection.Log.LogError("ConnectionFilter.OnConnection", task.Exception); - ConnectionControl.End(ProduceEndType.SocketDisconnect); + connection.ConnectionControl.End(ProduceEndType.SocketDisconnect); } else if (task.IsCanceled) { connection.Log.LogError("ConnectionFilter.OnConnection Canceled"); - ConnectionControl.End(ProduceEndType.SocketDisconnect); + connection.ConnectionControl.End(ProduceEndType.SocketDisconnect); } else { From eaee76dfebad53ed6143313b73b98b93e086500a Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Mon, 2 Nov 2015 16:16:55 -0800 Subject: [PATCH 0387/1662] Strong name everything. --- .../project.json | 3 +++ .../Properties/AssemblyInfo.cs | 2 +- src/Microsoft.AspNet.Server.Kestrel/project.json | 3 ++- .../project.json | 3 ++- tools/Key.snk | Bin 0 -> 596 bytes tools/Microsoft.StandardsPolice/project.json | 4 ++++ 6 files changed, 12 insertions(+), 3 deletions(-) create mode 100644 tools/Key.snk diff --git a/src/Microsoft.AspNet.Server.Kestrel.Https/project.json b/src/Microsoft.AspNet.Server.Kestrel.Https/project.json index 2e29e1ac44..3d47f866e2 100644 --- a/src/Microsoft.AspNet.Server.Kestrel.Https/project.json +++ b/src/Microsoft.AspNet.Server.Kestrel.Https/project.json @@ -1,5 +1,8 @@ { "version": "1.0.0-*", + "compilationOptions": { + "keyFile": "../../tools/Key.snk" + }, "description": "Adds HTTPS support to Kestrel", "repository": { "type": "git", diff --git a/src/Microsoft.AspNet.Server.Kestrel/Properties/AssemblyInfo.cs b/src/Microsoft.AspNet.Server.Kestrel/Properties/AssemblyInfo.cs index 7799e552b4..a8f71a20f0 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Properties/AssemblyInfo.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Properties/AssemblyInfo.cs @@ -5,6 +5,6 @@ using System.Reflection; using System.Resources; using System.Runtime.CompilerServices; -[assembly: InternalsVisibleTo("Microsoft.AspNet.Server.KestrelTests")] +[assembly: InternalsVisibleTo("Microsoft.AspNet.Server.KestrelTests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")] [assembly: AssemblyMetadata("Serviceable", "True")] [assembly: NeutralResourcesLanguage("en-us")] diff --git a/src/Microsoft.AspNet.Server.Kestrel/project.json b/src/Microsoft.AspNet.Server.Kestrel/project.json index 6ef9e06bb1..2fb2fa9659 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/project.json +++ b/src/Microsoft.AspNet.Server.Kestrel/project.json @@ -67,7 +67,8 @@ } }, "compilationOptions": { - "allowUnsafe": true + "allowUnsafe": true, + "keyFile": "../../tools/Key.snk" }, "scripts": { "prepare": [ diff --git a/test/Microsoft.AspNet.Server.KestrelTests/project.json b/test/Microsoft.AspNet.Server.KestrelTests/project.json index 9cb03bd95e..5696b0afa5 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/project.json +++ b/test/Microsoft.AspNet.Server.KestrelTests/project.json @@ -22,7 +22,8 @@ } }, "compilationOptions": { - "allowUnsafe": true + "allowUnsafe": true, + "keyFile": "../../tools/Key.snk" }, "commands": { "run": "Microsoft.AspNet.Server.KestrelTests", diff --git a/tools/Key.snk b/tools/Key.snk new file mode 100644 index 0000000000000000000000000000000000000000..e10e4889c125d3120cd9e81582243d70f7cbb806 GIT binary patch literal 596 zcmV-a0;~N80ssI2Bme+XQ$aES1ONa50098=Iw=HCsnz~#iVhm& zj%TU(_THUee?3yHBjk$37ysB?i5#7WD$={H zV4B!OxRPrb|8)HPg~A}8P>^=#y<)56#=E&NzcjOtPK~<4n6GHt=K$ro*T(lhby_@U zEk(hLzk1H)0yXj{A_5>fk-TgNoP|q6(tP2xo8zt8i%212CWM#AeCd?`hS|4~L({h~Moo(~vy&3Z z1uI}`fd^*>o=rwbAGymj6RM^pZm(*Kfhs+Y1#`-2JPWZMK8@;ZWCk2+9bX4YP);~fj-BU*R zQPvWv$89!{Rl9wM+zR>_TSkn^voYxA?2G iKnV#iZ6Ah`K>b=@=IjYJXrxL124zR(38)nxe+&q_$QXwJ literal 0 HcmV?d00001 diff --git a/tools/Microsoft.StandardsPolice/project.json b/tools/Microsoft.StandardsPolice/project.json index 63a14295ff..01f7813a3d 100644 --- a/tools/Microsoft.StandardsPolice/project.json +++ b/tools/Microsoft.StandardsPolice/project.json @@ -1,6 +1,10 @@ { "version": "1.0.0-*", + "compilationOptions": { + "keyFile": "../../tools/Key.snk" + }, + "description": "Microsoft.StandardsPolice Class Library", "dependencies": { From c113c0d3a27332993f8cc97baaf67abd6f9d7b7c Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Wed, 4 Nov 2015 07:00:57 +0000 Subject: [PATCH 0388/1662] Don't alloc array per header i.e `new StringValues(string)` rather than `new StringValues(new [] { string } )` --- .../Http/FrameHeaders.Generated.cs | 144 +++++++++--------- .../KnownHeaders.cs | 3 +- 2 files changed, 72 insertions(+), 75 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameHeaders.Generated.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameHeaders.Generated.cs index f1e7b7974a..1b4415b5a9 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameHeaders.Generated.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameHeaders.Generated.cs @@ -51,7 +51,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Http private StringValues _TE; private StringValues _Translate; private StringValues _UserAgent; - public StringValues HeaderCacheControl { @@ -3875,7 +3874,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http else { _bits |= 1L; - _CacheControl = new[] {value}; + _CacheControl = new StringValues(value); } return; } @@ -3889,7 +3888,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http else { _bits |= 131072L; - _ContentRange = new[] {value}; + _ContentRange = new StringValues(value); } return; } @@ -3903,7 +3902,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http else { _bits |= 524288L; - _LastModified = new[] {value}; + _LastModified = new StringValues(value); } return; } @@ -3917,7 +3916,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http else { _bits |= 16777216L; - _Authorization = new[] {value}; + _Authorization = new StringValues(value); } return; } @@ -3931,7 +3930,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http else { _bits |= 2147483648L; - _IfNoneMatch = new[] {value}; + _IfNoneMatch = new StringValues(value); } return; } @@ -3949,7 +3948,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http else { _bits |= 2L; - _Connection = new[] {value}; + _Connection = new StringValues(value); } return; } @@ -3963,7 +3962,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http else { _bits |= 8L; - _KeepAlive = new[] {value}; + _KeepAlive = new StringValues(value); } return; } @@ -3977,7 +3976,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http else { _bits |= 1099511627776L; - _UserAgent = new[] {value}; + _UserAgent = new StringValues(value); } return; } @@ -3995,7 +3994,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http else { _bits |= 4L; - _Date = new[] {value}; + _Date = new StringValues(value); } return; } @@ -4009,7 +4008,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http else { _bits |= 134217728L; - _From = new[] {value}; + _From = new StringValues(value); } return; } @@ -4023,7 +4022,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http else { _bits |= 268435456L; - _Host = new[] {value}; + _Host = new StringValues(value); } return; } @@ -4041,7 +4040,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http else { _bits |= 16L; - _Pragma = new[] {value}; + _Pragma = new StringValues(value); } return; } @@ -4055,7 +4054,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http else { _bits |= 1048576L; - _Accept = new[] {value}; + _Accept = new StringValues(value); } return; } @@ -4069,7 +4068,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http else { _bits |= 33554432L; - _Cookie = new[] {value}; + _Cookie = new StringValues(value); } return; } @@ -4083,7 +4082,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http else { _bits |= 67108864L; - _Expect = new[] {value}; + _Expect = new StringValues(value); } return; } @@ -4101,7 +4100,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http else { _bits |= 32L; - _Trailer = new[] {value}; + _Trailer = new StringValues(value); } return; } @@ -4115,7 +4114,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http else { _bits |= 128L; - _Upgrade = new[] {value}; + _Upgrade = new StringValues(value); } return; } @@ -4129,7 +4128,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http else { _bits |= 512L; - _Warning = new[] {value}; + _Warning = new StringValues(value); } return; } @@ -4143,7 +4142,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http else { _bits |= 262144L; - _Expires = new[] {value}; + _Expires = new StringValues(value); } return; } @@ -4157,7 +4156,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http else { _bits |= 68719476736L; - _Referer = new[] {value}; + _Referer = new StringValues(value); } return; } @@ -4175,7 +4174,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http else { _bits |= 64L; - _TransferEncoding = new[] {value}; + _TransferEncoding = new StringValues(value); } return; } @@ -4189,7 +4188,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http else { _bits |= 1073741824L; - _IfModifiedSince = new[] {value}; + _IfModifiedSince = new StringValues(value); } return; } @@ -4207,7 +4206,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http else { _bits |= 256L; - _Via = new[] {value}; + _Via = new StringValues(value); } return; } @@ -4225,7 +4224,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http else { _bits |= 1024L; - _Allow = new[] {value}; + _Allow = new StringValues(value); } return; } @@ -4239,7 +4238,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http else { _bits |= 137438953472L; - _Range = new[] {value}; + _Range = new StringValues(value); } return; } @@ -4257,7 +4256,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http else { _bits |= 2048L; - _ContentLength = new[] {value}; + _ContentLength = new StringValues(value); } return; } @@ -4271,7 +4270,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http else { _bits |= 2097152L; - _AcceptCharset = new[] {value}; + _AcceptCharset = new StringValues(value); } return; } @@ -4289,7 +4288,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http else { _bits |= 4096L; - _ContentType = new[] {value}; + _ContentType = new StringValues(value); } return; } @@ -4303,7 +4302,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http else { _bits |= 17179869184L; - _MaxForwards = new[] {value}; + _MaxForwards = new StringValues(value); } return; } @@ -4321,7 +4320,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http else { _bits |= 8192L; - _ContentEncoding = new[] {value}; + _ContentEncoding = new StringValues(value); } return; } @@ -4335,7 +4334,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http else { _bits |= 16384L; - _ContentLanguage = new[] {value}; + _ContentLanguage = new StringValues(value); } return; } @@ -4349,7 +4348,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http else { _bits |= 32768L; - _ContentLocation = new[] {value}; + _ContentLocation = new StringValues(value); } return; } @@ -4367,7 +4366,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http else { _bits |= 65536L; - _ContentMD5 = new[] {value}; + _ContentMD5 = new StringValues(value); } return; } @@ -4385,7 +4384,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http else { _bits |= 4194304L; - _AcceptEncoding = new[] {value}; + _AcceptEncoding = new StringValues(value); } return; } @@ -4399,7 +4398,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http else { _bits |= 8388608L; - _AcceptLanguage = new[] {value}; + _AcceptLanguage = new StringValues(value); } return; } @@ -4417,7 +4416,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http else { _bits |= 536870912L; - _IfMatch = new[] {value}; + _IfMatch = new StringValues(value); } return; } @@ -4431,7 +4430,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http else { _bits |= 4294967296L; - _IfRange = new[] {value}; + _IfRange = new StringValues(value); } return; } @@ -4449,7 +4448,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http else { _bits |= 8589934592L; - _IfUnmodifiedSince = new[] {value}; + _IfUnmodifiedSince = new StringValues(value); } return; } @@ -4463,7 +4462,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http else { _bits |= 34359738368L; - _ProxyAuthorization = new[] {value}; + _ProxyAuthorization = new StringValues(value); } return; } @@ -4481,7 +4480,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http else { _bits |= 274877906944L; - _TE = new[] {value}; + _TE = new StringValues(value); } return; } @@ -4499,7 +4498,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http else { _bits |= 549755813888L; - _Translate = new[] {value}; + _Translate = new StringValues(value); } return; } @@ -5020,7 +5019,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Http private StringValues _SetCookie; private StringValues _Vary; private StringValues _WWWAuthenticate; - public StringValues HeaderCacheControl { @@ -7851,7 +7849,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http else { _bits |= 1L; - _CacheControl = new[] {value}; + _CacheControl = new StringValues(value); } return; } @@ -7865,7 +7863,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http else { _bits |= 131072L; - _ContentRange = new[] {value}; + _ContentRange = new StringValues(value); } return; } @@ -7879,7 +7877,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http else { _bits |= 524288L; - _LastModified = new[] {value}; + _LastModified = new StringValues(value); } return; } @@ -7893,7 +7891,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http else { _bits |= 1048576L; - _AcceptRanges = new[] {value}; + _AcceptRanges = new StringValues(value); } return; } @@ -7911,7 +7909,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http else { _bits |= 2L; - _Connection = new[] {value}; + _Connection = new StringValues(value); } return; } @@ -7925,7 +7923,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http else { _bits |= 8L; - _KeepAlive = new[] {value}; + _KeepAlive = new StringValues(value); } return; } @@ -7939,7 +7937,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http else { _bits |= 134217728L; - _SetCookie = new[] {value}; + _SetCookie = new StringValues(value); } return; } @@ -7957,7 +7955,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http else { _bits |= 4L; - _Date = new[] {value}; + _Date = new StringValues(value); } return; } @@ -7971,7 +7969,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http else { _bits |= 4194304L; - _ETag = new[] {value}; + _ETag = new StringValues(value); } return; } @@ -7985,7 +7983,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http else { _bits |= 268435456L; - _Vary = new[] {value}; + _Vary = new StringValues(value); } return; } @@ -8003,7 +8001,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http else { _bits |= 16L; - _Pragma = new[] {value}; + _Pragma = new StringValues(value); } return; } @@ -8017,7 +8015,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http else { _bits |= 67108864L; - _Server = new[] {value}; + _Server = new StringValues(value); } return; } @@ -8035,7 +8033,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http else { _bits |= 32L; - _Trailer = new[] {value}; + _Trailer = new StringValues(value); } return; } @@ -8049,7 +8047,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http else { _bits |= 128L; - _Upgrade = new[] {value}; + _Upgrade = new StringValues(value); } return; } @@ -8063,7 +8061,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http else { _bits |= 512L; - _Warning = new[] {value}; + _Warning = new StringValues(value); } return; } @@ -8077,7 +8075,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http else { _bits |= 262144L; - _Expires = new[] {value}; + _Expires = new StringValues(value); } return; } @@ -8095,7 +8093,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http else { _bits |= 64L; - _TransferEncoding = new[] {value}; + _TransferEncoding = new StringValues(value); } return; } @@ -8109,7 +8107,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http else { _bits |= 16777216L; - _ProxyAutheticate = new[] {value}; + _ProxyAutheticate = new StringValues(value); } return; } @@ -8127,7 +8125,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http else { _bits |= 256L; - _Via = new[] {value}; + _Via = new StringValues(value); } return; } @@ -8141,7 +8139,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http else { _bits |= 2097152L; - _Age = new[] {value}; + _Age = new StringValues(value); } return; } @@ -8159,7 +8157,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http else { _bits |= 1024L; - _Allow = new[] {value}; + _Allow = new StringValues(value); } return; } @@ -8177,7 +8175,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http else { _bits |= 2048L; - _ContentLength = new[] {value}; + _ContentLength = new StringValues(value); } return; } @@ -8195,7 +8193,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http else { _bits |= 4096L; - _ContentType = new[] {value}; + _ContentType = new StringValues(value); } return; } @@ -8213,7 +8211,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http else { _bits |= 8192L; - _ContentEncoding = new[] {value}; + _ContentEncoding = new StringValues(value); } return; } @@ -8227,7 +8225,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http else { _bits |= 16384L; - _ContentLanguage = new[] {value}; + _ContentLanguage = new StringValues(value); } return; } @@ -8241,7 +8239,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http else { _bits |= 32768L; - _ContentLocation = new[] {value}; + _ContentLocation = new StringValues(value); } return; } @@ -8255,7 +8253,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http else { _bits |= 536870912L; - _WWWAuthenticate = new[] {value}; + _WWWAuthenticate = new StringValues(value); } return; } @@ -8273,7 +8271,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http else { _bits |= 65536L; - _ContentMD5 = new[] {value}; + _ContentMD5 = new StringValues(value); } return; } @@ -8287,7 +8285,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http else { _bits |= 33554432L; - _RetryAfter = new[] {value}; + _RetryAfter = new StringValues(value); } return; } @@ -8305,7 +8303,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http else { _bits |= 8388608L; - _Location = new[] {value}; + _Location = new StringValues(value); } return; } diff --git a/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/KnownHeaders.cs b/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/KnownHeaders.cs index 759d6dacf8..b2def16b46 100644 --- a/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/KnownHeaders.cs +++ b/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/KnownHeaders.cs @@ -177,7 +177,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Http private long _bits = 0; {Each(loop.Headers, header => @" private StringValues _" + header.Identifier + ";")} - {Each(loop.Headers, header => $@" public StringValues Header{header.Identifier} {{ @@ -361,7 +360,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http else {{ {header.SetBit()}; - _{header.Identifier} = new[] {{value}}; + _{header.Identifier} = new StringValues(value); }} return; }} From 5ae1c4ecb2cc0562a8490e3d2dcde10560960583 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Wed, 4 Nov 2015 08:07:34 +0000 Subject: [PATCH 0389/1662] MemoryPool2 Allocate returns newest Rather than a while loop on Allocate; return last memory block created rather than returning it to the pool and checking if one can be removed. --- .../Infrastructure/MemoryPool2.cs | 33 ++++++++++++------- 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPool2.cs b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPool2.cs index 2ee01c0d10..cef7779dc4 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPool2.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPool2.cs @@ -74,24 +74,21 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure slab: null); } - while (true) + MemoryPoolBlock2 block; + if (_blocks.TryPop(out block)) { - MemoryPoolBlock2 block; - if (_blocks.TryPop(out block)) - { - // block successfully taken from the stack - return it - return block; - } - // no blocks available - grow the pool and try again - AllocateSlab(); + // block successfully taken from the stack - return it + return block; } + // no blocks available - grow the pool + return AllocateSlab(); } /// /// Internal method called when a block is requested and the pool is empty. It allocates one additional slab, creates all of the /// block tracking objects, and adds them all to the pool. /// - private void AllocateSlab() + private MemoryPoolBlock2 AllocateSlab() { var slab = MemoryPoolSlab2.Create(_slabLength); _slabs.Push(slab); @@ -99,8 +96,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure var basePtr = slab.ArrayPtr; var firstOffset = (int)((_blockStride - 1) - ((ulong)(basePtr + _blockStride - 1) % _blockStride)); - for (var offset = firstOffset; - offset + _blockLength <= _slabLength; + var poolAllocationLength = _slabLength - (_blockLength + _blockStride); + + var offset = firstOffset; + for (; + offset < poolAllocationLength; offset += _blockStride) { var block = MemoryPoolBlock2.Create( @@ -110,6 +110,15 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure slab); Return(block); } + + // return last block rather than adding to pool + var newBlock = MemoryPoolBlock2.Create( + new ArraySegment(slab.Array, offset, _blockLength), + basePtr, + this, + slab); + + return newBlock; } /// From 34c1a671f04f4ff6b98766e1ca4a2d71891a7782 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Sun, 1 Nov 2015 14:10:59 +0000 Subject: [PATCH 0390/1662] ListenerSecondary - reduce closure allocation --- .../Http/ListenerSecondary.cs | 185 ++++++++++-------- 1 file changed, 102 insertions(+), 83 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerSecondary.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerSecondary.cs index 814ea3ffe3..acff41bfeb 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerSecondary.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerSecondary.cs @@ -17,6 +17,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http /// public abstract class ListenerSecondary : ListenerContext, IDisposable { + private string _pipeName; + protected ListenerSecondary(ServiceContext serviceContext) : base(serviceContext) { } @@ -29,97 +31,114 @@ namespace Microsoft.AspNet.Server.Kestrel.Http KestrelThread thread, RequestDelegate application) { + _pipeName = pipeName; ServerAddress = address; Thread = thread; Application = application; DispatchPipe = new UvPipeHandle(Log); - var tcs = new TaskCompletionSource(); - Thread.Post(_ => - { - try - { - DispatchPipe.Init(Thread.Loop, true); - var connect = new UvConnectRequest(Log); - connect.Init(Thread.Loop); - connect.Connect( - DispatchPipe, - pipeName, - (connect2, status, error, state) => - { - connect.Dispose(); - if (error != null) - { - tcs.SetException(error); - return; - } - - try - { - var ptr = Marshal.AllocHGlobal(4); - var buf = Thread.Loop.Libuv.buf_init(ptr, 4); - - DispatchPipe.ReadStart( - (_1, _2, _3) => buf, - (_1, status2, state2) => - { - if (status2 < 0) - { - if (status2 != Constants.EOF) - { - Exception ex; - Thread.Loop.Libuv.Check(status2, out ex); - Log.LogError("DispatchPipe.ReadStart", ex); - } - - DispatchPipe.Dispose(); - Marshal.FreeHGlobal(ptr); - return; - } - - if (DispatchPipe.PendingCount() == 0) - { - return; - } - - var acceptSocket = CreateAcceptSocket(); - - try - { - DispatchPipe.Accept(acceptSocket); - } - catch (UvException ex) - { - Log.LogError("DispatchPipe.Accept", ex); - acceptSocket.Dispose(); - return; - } - - var connection = new Connection(this, acceptSocket); - connection.Start(); - }, - null); - - tcs.SetResult(0); - } - catch (Exception ex) - { - DispatchPipe.Dispose(); - tcs.SetException(ex); - } - }, - null); - } - catch (Exception ex) - { - DispatchPipe.Dispose(); - tcs.SetException(ex); - } - }, null); + var tcs = new TaskCompletionSource(this); + Thread.Post(tcs2 => StartCallback(tcs2), tcs); return tcs.Task; } + private static void StartCallback(TaskCompletionSource tcs) + { + var listener = (ListenerSecondary)tcs.Task.AsyncState; + listener.StartedCallback(tcs); + } + + private void StartedCallback(TaskCompletionSource tcs) + { + try + { + DispatchPipe.Init(Thread.Loop, true); + var connect = new UvConnectRequest(Log); + connect.Init(Thread.Loop); + connect.Connect( + DispatchPipe, + _pipeName, + (connect2, status, error, state) => ConnectCallback(connect2, status, error, (TaskCompletionSource)state), + tcs); + } + catch (Exception ex) + { + DispatchPipe.Dispose(); + tcs.SetException(ex); + } + } + + private static void ConnectCallback(UvConnectRequest connect, int status, Exception error, TaskCompletionSource tcs) + { + var listener = (ListenerSecondary)tcs.Task.AsyncState; + listener.ConnectedCallback(connect, status, error, tcs); + } + private void ConnectedCallback(UvConnectRequest connect, int status, Exception error, TaskCompletionSource tcs) + { + connect.Dispose(); + if (error != null) + { + tcs.SetException(error); + return; + } + + try + { + var ptr = Marshal.AllocHGlobal(4); + var buf = Thread.Loop.Libuv.buf_init(ptr, 4); + + DispatchPipe.ReadStart( + (handle, status2, state) => buf, + (handle, status2, state) => ((ListenerSecondary)state).ReadStartCallback(handle, status2, ptr), this); + + tcs.SetResult(0); + } + catch (Exception ex) + { + DispatchPipe.Dispose(); + tcs.SetException(ex); + } + } + + private void ReadStartCallback(UvStreamHandle handle, int status, IntPtr ptr) + { + if (status < 0) + { + if (status != Constants.EOF) + { + Exception ex; + Thread.Loop.Libuv.Check(status, out ex); + Log.LogError("DispatchPipe.ReadStart", ex); + } + + DispatchPipe.Dispose(); + Marshal.FreeHGlobal(ptr); + return; + } + + if (DispatchPipe.PendingCount() == 0) + { + return; + } + + var acceptSocket = CreateAcceptSocket(); + + try + { + DispatchPipe.Accept(acceptSocket); + } + catch (UvException ex) + { + Log.LogError("DispatchPipe.Accept", ex); + acceptSocket.Dispose(); + return; + } + + var connection = new Connection(this, acceptSocket); + connection.Start(); + } + /// /// Creates a socket which can be used to accept an incoming connection /// @@ -133,7 +152,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http // the exception that stopped the event loop will never be surfaced. if (Thread.FatalError == null) { - Thread.Send(_ => DispatchPipe.Dispose(), null); + Thread.Send(listener => ((ListenerSecondary)listener).DispatchPipe.Dispose(), this); } } } From d104e8a08d422be0f5db931d1d5ae8f3d1d8f16f Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Sun, 1 Nov 2015 14:27:17 +0000 Subject: [PATCH 0391/1662] Reduce delegate allocation --- src/Microsoft.AspNet.Server.Kestrel/Http/MessageBody.cs | 4 ++-- src/Microsoft.AspNet.Server.Kestrel/Http/PipeListener.cs | 2 +- .../Http/PipeListenerPrimary.cs | 2 +- src/Microsoft.AspNet.Server.Kestrel/Http/TcpListener.cs | 2 +- .../Http/TcpListenerPrimary.cs | 2 +- .../Networking/UvAsyncHandle.cs | 2 +- .../Networking/UvConnectRequest.cs | 2 +- src/Microsoft.AspNet.Server.Kestrel/Networking/UvHandle.cs | 2 +- .../Networking/UvStreamHandle.cs | 7 ++++--- 9 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/MessageBody.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/MessageBody.cs index 3b20247e67..e8e438512b 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/MessageBody.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/MessageBody.cs @@ -3,10 +3,10 @@ using System; using System.Collections.Generic; +using System.IO; using System.Threading; using System.Threading.Tasks; using Microsoft.Extensions.Primitives; -using System.IO; namespace Microsoft.AspNet.Server.Kestrel.Http { @@ -94,7 +94,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http value = values[0]; return true; } - value = String.Join(",", values); + value = string.Join(",", values.ToArray()); return true; } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/PipeListener.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/PipeListener.cs index 4c3e35f799..b3a15c1fe3 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/PipeListener.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/PipeListener.cs @@ -25,7 +25,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http var socket = new UvPipeHandle(Log); socket.Init(Thread.Loop, false); socket.Bind(ServerAddress.UnixPipePath); - socket.Listen(Constants.ListenBacklog, ConnectionCallback, this); + socket.Listen(Constants.ListenBacklog, (stream, status, error, state) => ConnectionCallback(stream, status, error, state), this); return socket; } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/PipeListenerPrimary.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/PipeListenerPrimary.cs index 1f7eb285e9..7f15ccb2c0 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/PipeListenerPrimary.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/PipeListenerPrimary.cs @@ -25,7 +25,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http var socket = new UvPipeHandle(Log); socket.Init(Thread.Loop, false); socket.Bind(ServerAddress.UnixPipePath); - socket.Listen(Constants.ListenBacklog, ConnectionCallback, this); + socket.Listen(Constants.ListenBacklog, (stream, status, error, state) => ConnectionCallback(stream, status, error, state), this); return socket; } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/TcpListener.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/TcpListener.cs index 86feca412b..45769cc074 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/TcpListener.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/TcpListener.cs @@ -25,7 +25,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http socket.Init(Thread.Loop, Thread.QueueCloseHandle); socket.NoDelay(NoDelay); socket.Bind(ServerAddress); - socket.Listen(Constants.ListenBacklog, ConnectionCallback, this); + socket.Listen(Constants.ListenBacklog, (stream, status, error, state) => ConnectionCallback(stream, status, error, state), this); return socket; } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/TcpListenerPrimary.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/TcpListenerPrimary.cs index 4f1ff0a48d..2116ed1ab0 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/TcpListenerPrimary.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/TcpListenerPrimary.cs @@ -27,7 +27,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http socket.Init(Thread.Loop, Thread.QueueCloseHandle); socket.NoDelay(NoDelay); socket.Bind(ServerAddress); - socket.Listen(Constants.ListenBacklog, ConnectionCallback, this); + socket.Listen(Constants.ListenBacklog, (stream, status, error, state) => ConnectionCallback(stream, status, error, state), this); return socket; } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvAsyncHandle.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvAsyncHandle.cs index 04c2ecce3b..9b4ecb60f8 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvAsyncHandle.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvAsyncHandle.cs @@ -8,7 +8,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking { public class UvAsyncHandle : UvHandle { - private static Libuv.uv_async_cb _uv_async_cb = AsyncCb; + private static Libuv.uv_async_cb _uv_async_cb = (handle) => AsyncCb(handle); private Action _callback; public UvAsyncHandle(IKestrelTrace logger) : base(logger) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvConnectRequest.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvConnectRequest.cs index 0c0ce04b4b..086c52de77 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvConnectRequest.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvConnectRequest.cs @@ -12,7 +12,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking /// public class UvConnectRequest : UvRequest { - private readonly static Libuv.uv_connect_cb _uv_connect_cb = UvConnectCb; + private readonly static Libuv.uv_connect_cb _uv_connect_cb = (req, status) => UvConnectCb(req, status); private Action _callback; private object _state; diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvHandle.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvHandle.cs index 4b90ecfd57..7fcb2106a9 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvHandle.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvHandle.cs @@ -9,7 +9,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking { public abstract class UvHandle : UvMemory { - private static Libuv.uv_close_cb _destroyMemory = DestroyMemory; + private static Libuv.uv_close_cb _destroyMemory = (handle) => DestroyMemory(handle); private Action, IntPtr> _queueCloseHandle; protected UvHandle(IKestrelTrace logger) : base (logger) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvStreamHandle.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvStreamHandle.cs index e6ffafe24c..bfbdabfef6 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvStreamHandle.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvStreamHandle.cs @@ -10,9 +10,10 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking { public abstract class UvStreamHandle : UvHandle { - private readonly static Libuv.uv_connection_cb _uv_connection_cb = UvConnectionCb; - private readonly static Libuv.uv_alloc_cb _uv_alloc_cb = UvAllocCb; - private readonly static Libuv.uv_read_cb _uv_read_cb = UvReadCb; + private readonly static Libuv.uv_connection_cb _uv_connection_cb = (handle, status) => UvConnectionCb(handle, status); + // Ref and out lamda params must be explicitly typed + private readonly static Libuv.uv_alloc_cb _uv_alloc_cb = (IntPtr handle, int suggested_size, out Libuv.uv_buf_t buf) => UvAllocCb(handle, suggested_size, out buf); + private readonly static Libuv.uv_read_cb _uv_read_cb = (IntPtr handle, int status, ref Libuv.uv_buf_t buf) => UvReadCb(handle, status, ref buf); public Action _listenCallback; public object _listenState; From 1d4b9d663306179756959aec04313fb27a49b95c Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Sun, 1 Nov 2015 13:42:33 +0000 Subject: [PATCH 0392/1662] ListenerPrimary - reduce closure allocation Still captures string pipeName --- .../Http/ListenerPrimary.cs | 23 ++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerPrimary.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerPrimary.cs index 21c6c55183..c5b6321d4a 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerPrimary.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerPrimary.cs @@ -19,6 +19,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { private List _dispatchPipes = new List(); private int _dispatchIndex; + private string _pipeName; // this message is passed to write2 because it must be non-zero-length, // but it has no other functional significance @@ -36,18 +37,24 @@ namespace Microsoft.AspNet.Server.Kestrel.Http KestrelThread thread, RequestDelegate application) { + _pipeName = pipeName; + await StartAsync(address, thread, application).ConfigureAwait(false); - await Thread.PostAsync(_ => - { - ListenPipe = new UvPipeHandle(Log); - ListenPipe.Init(Thread.Loop, false); - ListenPipe.Bind(pipeName); - ListenPipe.Listen(Constants.ListenBacklog, OnListenPipe, null); - }, null).ConfigureAwait(false); + await Thread.PostAsync(_this => _this.PostCallback(), + this).ConfigureAwait(false); } - private void OnListenPipe(UvStreamHandle pipe, int status, Exception error, object state) + private void PostCallback() + { + ListenPipe = new UvPipeHandle(Log); + ListenPipe.Init(Thread.Loop, false); + ListenPipe.Bind(_pipeName); + ListenPipe.Listen(Constants.ListenBacklog, + (pipe, status, error, state) => ((ListenerPrimary)state).OnListenPipe(pipe, status, error), this); + } + + private void OnListenPipe(UvStreamHandle pipe, int status, Exception error) { if (status < 0) { From cc84097016276da3acf5e7089e57a98ce9a39377 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Sun, 1 Nov 2015 13:31:45 +0000 Subject: [PATCH 0393/1662] Listener - remove closure allocation --- .../Http/Listener.cs | 28 +++++++++++-------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs index a7b72acc01..d1a80b7043 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs @@ -30,19 +30,22 @@ namespace Microsoft.AspNet.Server.Kestrel.Http Thread = thread; Application = application; - var tcs = new TaskCompletionSource(); - Thread.Post(_ => + var tcs = new TaskCompletionSource(this); + + Thread.Post(tcs2 => { try { - ListenSocket = CreateListenSocket(); - tcs.SetResult(0); + var listener = ((Listener)tcs2.Task.AsyncState); + listener.ListenSocket = listener.CreateListenSocket(); + tcs2.SetResult(0); } catch (Exception ex) { - tcs.SetException(ex); + tcs2.SetException(ex); } - }, null); + }, tcs); + return tcs.Task; } @@ -85,21 +88,22 @@ namespace Microsoft.AspNet.Server.Kestrel.Http // the exception that stopped the event loop will never be surfaced. if (Thread.FatalError == null && ListenSocket != null) { - var tcs = new TaskCompletionSource(); + var tcs = new TaskCompletionSource(this); Thread.Post( - _ => + tcs2 => { try { - ListenSocket.Dispose(); - tcs.SetResult(0); + var socket = (Listener)tcs2.Task.AsyncState; + socket.ListenSocket.Dispose(); + tcs2.SetResult(0); } catch (Exception ex) { - tcs.SetException(ex); + tcs2.SetException(ex); } }, - null); + tcs); // REVIEW: Should we add a timeout here to be safe? tcs.Task.Wait(); From 22dfd31261a16e4d873179b20f9b033f2af677c3 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Wed, 4 Nov 2015 22:04:19 +0000 Subject: [PATCH 0394/1662] More readable loop condition --- .../Infrastructure/MemoryPool2.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPool2.cs b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPool2.cs index cef7779dc4..86561516c6 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPool2.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPool2.cs @@ -96,11 +96,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure var basePtr = slab.ArrayPtr; var firstOffset = (int)((_blockStride - 1) - ((ulong)(basePtr + _blockStride - 1) % _blockStride)); - var poolAllocationLength = _slabLength - (_blockLength + _blockStride); + var poolAllocationLength = _slabLength - _blockStride; var offset = firstOffset; for (; - offset < poolAllocationLength; + offset + _blockLength < poolAllocationLength; offset += _blockStride) { var block = MemoryPoolBlock2.Create( From 5cef608e5220d68268ac1e7274e81b745d68a04a Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Wed, 4 Nov 2015 22:20:51 +0000 Subject: [PATCH 0395/1662] Dispose _ptr --- .../Http/ListenerSecondary.cs | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerSecondary.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerSecondary.cs index acff41bfeb..79e1ab89c1 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerSecondary.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerSecondary.cs @@ -18,6 +18,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http public abstract class ListenerSecondary : ListenerContext, IDisposable { private string _pipeName; + private IntPtr _ptr = IntPtr.Zero; + private Libuv.uv_buf_t _buf; protected ListenerSecondary(ServiceContext serviceContext) : base(serviceContext) { @@ -74,6 +76,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http var listener = (ListenerSecondary)tcs.Task.AsyncState; listener.ConnectedCallback(connect, status, error, tcs); } + private void ConnectedCallback(UvConnectRequest connect, int status, Exception error, TaskCompletionSource tcs) { connect.Dispose(); @@ -85,12 +88,16 @@ namespace Microsoft.AspNet.Server.Kestrel.Http try { - var ptr = Marshal.AllocHGlobal(4); - var buf = Thread.Loop.Libuv.buf_init(ptr, 4); + _ptr = Marshal.AllocHGlobal(4); + _buf = Thread.Loop.Libuv.buf_init(_ptr, 4); DispatchPipe.ReadStart( - (handle, status2, state) => buf, - (handle, status2, state) => ((ListenerSecondary)state).ReadStartCallback(handle, status2, ptr), this); + (handle, status2, state) => ((ListenerSecondary)state)._buf, + (handle, status2, state) => + { + var listener = ((ListenerSecondary)state); + listener.ReadStartCallback(handle, status2, listener._ptr); + }, this); tcs.SetResult(0); } @@ -146,6 +153,12 @@ namespace Microsoft.AspNet.Server.Kestrel.Http public void Dispose() { + if (_ptr != IntPtr.Zero) + { + Marshal.FreeHGlobal(_ptr); + _ptr = IntPtr.Zero; + } + // Ensure the event loop is still running. // If the event loop isn't running and we try to wait on this Post // to complete, then KestrelEngine will never be disposed and From 3e7969cefe89ec38e9ed64658479ca04cf890515 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Wed, 4 Nov 2015 22:44:30 +0000 Subject: [PATCH 0396/1662] Move handle creation to constructor --- .../Http/ListenerSecondary.cs | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerSecondary.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerSecondary.cs index 79e1ab89c1..d74c664e62 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerSecondary.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerSecondary.cs @@ -18,11 +18,13 @@ namespace Microsoft.AspNet.Server.Kestrel.Http public abstract class ListenerSecondary : ListenerContext, IDisposable { private string _pipeName; - private IntPtr _ptr = IntPtr.Zero; + private IntPtr _ptr; private Libuv.uv_buf_t _buf; protected ListenerSecondary(ServiceContext serviceContext) : base(serviceContext) { + _ptr = Marshal.AllocHGlobal(4); + _buf = Thread.Loop.Libuv.buf_init(_ptr, 4); } UvPipeHandle DispatchPipe { get; set; } @@ -88,9 +90,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Http try { - _ptr = Marshal.AllocHGlobal(4); - _buf = Thread.Loop.Libuv.buf_init(_ptr, 4); - DispatchPipe.ReadStart( (handle, status2, state) => ((ListenerSecondary)state)._buf, (handle, status2, state) => @@ -153,11 +152,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http public void Dispose() { - if (_ptr != IntPtr.Zero) - { - Marshal.FreeHGlobal(_ptr); - _ptr = IntPtr.Zero; - } + Marshal.FreeHGlobal(_ptr); // Ensure the event loop is still running. // If the event loop isn't running and we try to wait on this Post From fff28990fe01ade13fe889cd26e81dcaf168e118 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Wed, 4 Nov 2015 15:45:14 -0800 Subject: [PATCH 0397/1662] Ensure ListenerSecondary buffer isn't double freed or freed too early - Call buf_init in StartAsync so we have access to a KestrelThread --- .../Http/ListenerSecondary.cs | 35 ++++++++++++++----- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerSecondary.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerSecondary.cs index d74c664e62..cdeb6c280c 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerSecondary.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerSecondary.cs @@ -3,6 +3,7 @@ using System; using System.Runtime.InteropServices; +using System.Threading; using System.Threading.Tasks; using Microsoft.AspNet.Http; using Microsoft.AspNet.Server.Kestrel.Infrastructure; @@ -24,7 +25,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Http protected ListenerSecondary(ServiceContext serviceContext) : base(serviceContext) { _ptr = Marshal.AllocHGlobal(4); - _buf = Thread.Loop.Libuv.buf_init(_ptr, 4); } UvPipeHandle DispatchPipe { get; set; } @@ -36,6 +36,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http RequestDelegate application) { _pipeName = pipeName; + _buf = thread.Loop.Libuv.buf_init(_ptr, 4); + ServerAddress = address; Thread = thread; Application = application; @@ -93,10 +95,10 @@ namespace Microsoft.AspNet.Server.Kestrel.Http DispatchPipe.ReadStart( (handle, status2, state) => ((ListenerSecondary)state)._buf, (handle, status2, state) => - { - var listener = ((ListenerSecondary)state); - listener.ReadStartCallback(handle, status2, listener._ptr); - }, this); + { + var listener = ((ListenerSecondary)state); + listener.ReadStartCallback(handle, status2, listener._ptr); + }, this); tcs.SetResult(0); } @@ -119,7 +121,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } DispatchPipe.Dispose(); - Marshal.FreeHGlobal(ptr); return; } @@ -150,17 +151,33 @@ namespace Microsoft.AspNet.Server.Kestrel.Http /// protected abstract UvStreamHandle CreateAcceptSocket(); + private void FreeBuffer() + { + var ptr = Interlocked.Exchange(ref _ptr, IntPtr.Zero); + if (ptr != IntPtr.Zero) + { + Marshal.FreeHGlobal(_ptr); + } + } + public void Dispose() { - Marshal.FreeHGlobal(_ptr); - // Ensure the event loop is still running. // If the event loop isn't running and we try to wait on this Post // to complete, then KestrelEngine will never be disposed and // the exception that stopped the event loop will never be surfaced. if (Thread.FatalError == null) { - Thread.Send(listener => ((ListenerSecondary)listener).DispatchPipe.Dispose(), this); + Thread.Send(state => + { + var listener = (ListenerSecondary)state; + listener.DispatchPipe.Dispose(); + listener.FreeBuffer(); + }, this); + } + else + { + FreeBuffer(); } } } From bb9f83186b909dd49d17122c76fb892dec7435a3 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Thu, 5 Nov 2015 12:09:50 -0800 Subject: [PATCH 0398/1662] Remove unused parameter from ListenerSecondary.ReadStartCallback --- .../Http/ListenerSecondary.cs | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerSecondary.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerSecondary.cs index cdeb6c280c..5891df44ca 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerSecondary.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerSecondary.cs @@ -94,11 +94,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { DispatchPipe.ReadStart( (handle, status2, state) => ((ListenerSecondary)state)._buf, - (handle, status2, state) => - { - var listener = ((ListenerSecondary)state); - listener.ReadStartCallback(handle, status2, listener._ptr); - }, this); + (handle, status2, state) => ((ListenerSecondary)state).ReadStartCallback(handle, status2), + this); tcs.SetResult(0); } @@ -109,7 +106,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } - private void ReadStartCallback(UvStreamHandle handle, int status, IntPtr ptr) + private void ReadStartCallback(UvStreamHandle handle, int status) { if (status < 0) { From 278bd9c962bed190d2686b78b708a1cfcd54ea37 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Sun, 8 Nov 2015 18:12:03 +0000 Subject: [PATCH 0399/1662] Completed Task opt --- .../Filter/NoOpConnectionFilter.cs | 5 ++--- .../Filter/SocketInputStream.cs | 5 ++--- .../Filter/StreamSocketOutput.cs | 5 ++--- .../Infrastructure/TaskUtilities.cs | 15 ++++++--------- 4 files changed, 12 insertions(+), 18 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Filter/NoOpConnectionFilter.cs b/src/Microsoft.AspNet.Server.Kestrel/Filter/NoOpConnectionFilter.cs index 65bb9e99b7..b1217d3034 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Filter/NoOpConnectionFilter.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Filter/NoOpConnectionFilter.cs @@ -2,16 +2,15 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Threading.Tasks; +using Microsoft.AspNet.Server.Kestrel.Infrastructure; namespace Microsoft.AspNet.Server.Kestrel.Filter { public class NoOpConnectionFilter : IConnectionFilter { - private static Task _empty = Task.FromResult(null); - public Task OnConnection(ConnectionFilterContext context) { - return _empty; + return TaskUtilities.CompletedTask; } } } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Filter/SocketInputStream.cs b/src/Microsoft.AspNet.Server.Kestrel/Filter/SocketInputStream.cs index 594d2e45ba..26b513faa7 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Filter/SocketInputStream.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Filter/SocketInputStream.cs @@ -6,6 +6,7 @@ using System.IO; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNet.Server.Kestrel.Http; +using Microsoft.AspNet.Server.Kestrel.Infrastructure; namespace Microsoft.AspNet.Server.Kestrel.Filter { @@ -17,8 +18,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Filter /// public class SocketInputStream : Stream { - private static Task _emptyTask = Task.FromResult(null); - private readonly SocketInput _socketInput; public SocketInputStream(SocketInput socketInput) @@ -85,7 +84,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Filter public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken token) { Write(buffer, offset, count); - return _emptyTask; + return TaskUtilities.CompletedTask; } protected override void Dispose(bool disposing) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Filter/StreamSocketOutput.cs b/src/Microsoft.AspNet.Server.Kestrel/Filter/StreamSocketOutput.cs index f5470ae728..fe9499265f 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Filter/StreamSocketOutput.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Filter/StreamSocketOutput.cs @@ -6,13 +6,12 @@ using System.IO; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNet.Server.Kestrel.Http; +using Microsoft.AspNet.Server.Kestrel.Infrastructure; namespace Microsoft.AspNet.Server.Kestrel.Filter { public class StreamSocketOutput : ISocketOutput { - private static readonly Task _emptyTask = Task.FromResult(null); - private readonly Stream _outputStream; public StreamSocketOutput(Stream outputStream) @@ -29,7 +28,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Filter { // TODO: Use _outputStream.WriteAsync _outputStream.Write(buffer.Array, buffer.Offset, buffer.Count); - return _emptyTask; + return TaskUtilities.CompletedTask; } } } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/TaskUtilities.cs b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/TaskUtilities.cs index 87b741a728..e67ded5acb 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/TaskUtilities.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/TaskUtilities.cs @@ -7,13 +7,10 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure { public static class TaskUtilities { - public static Task CompletedTask = NewCompletedTask(); - - private static Task NewCompletedTask() - { - var tcs = new TaskCompletionSource(); - tcs.SetResult(0); - return tcs.Task; - } +#if DOTNET5_4 || DNXCORE50 + public static Task CompletedTask = Task.CompletedTask; +#else + public static Task CompletedTask = Task.FromResult(null); +#endif } -} +} \ No newline at end of file From 0bfc97e46fe0015bc4ec09b8cbe382d01444cee6 Mon Sep 17 00:00:00 2001 From: Pawel Kadluczka Date: Tue, 10 Nov 2015 01:44:42 +0000 Subject: [PATCH 0400/1662] Fixing test so that it runs on CoreClr --- test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs index 299ba25fe6..983017cfa0 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs @@ -367,7 +367,7 @@ namespace Microsoft.AspNet.Server.KestrelTests { using (var server = new TestServer(App, testContext)) { - var socket = new Socket(SocketType.Stream, ProtocolType.IP); + var socket = new Socket(SocketType.Stream, ProtocolType.Tcp); socket.Connect(IPAddress.Loopback, 54321); await Task.Delay(200); socket.Dispose(); From a2c4e3a654eb2bdc106be0aaa1d3fb94000195c5 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Sun, 1 Nov 2015 02:49:08 +0000 Subject: [PATCH 0401/1662] Task.Run -> ThreadPool.QueueUserWorkItem Task.Run eventually ends up being QueueUserWorkItem. The returned task is ignored, so no added goodness. Short running item. Cut out the middleman --- src/Microsoft.AspNet.Server.Kestrel/Http/SocketInput.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketInput.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketInput.cs index 0eb74bb906..98910340ab 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketInput.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketInput.cs @@ -128,7 +128,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http if (awaitableState != _awaitableIsCompleted && awaitableState != _awaitableIsNotCompleted) { - Task.Run(awaitableState); + ThreadPool.QueueUserWorkItem((o) => ((Action)o)(), awaitableState); } } @@ -194,7 +194,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } else if (awaitableState == _awaitableIsCompleted) { - Task.Run(continuation); + ThreadPool.QueueUserWorkItem((o) => ((Action)o)(), continuation); } else { From c0f82765aafe4328da49177d955d9fe8f6a1f978 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Tue, 3 Nov 2015 19:44:04 +0000 Subject: [PATCH 0402/1662] Move logging to new style --- .../Infrastructure/KestrelTrace.cs | 45 +++++++++++++++---- .../EngineTests.cs | 4 +- 2 files changed, 38 insertions(+), 11 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelTrace.cs b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelTrace.cs index e55ad72846..4ac345e709 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelTrace.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelTrace.cs @@ -12,8 +12,35 @@ namespace Microsoft.AspNet.Server.Kestrel /// public class KestrelTrace : IKestrelTrace { + private static Action _connectionStart; + private static Action _connectionStop; + private static Action _connectionPause; + private static Action _connectionResume; + private static Action _connectionReadFin; + private static Action _connectionWriteFin; + private static Action _connectionWroteFin; + private static Action _connectionKeepAlive; + private static Action _connectionDisconnect; + protected readonly ILogger _logger; + static KestrelTrace() + { + _connectionStart = LoggerMessage.Define(LogLevel.Debug, 1, @"Connection id ""{ConnectionId}"" started."); + _connectionStop = LoggerMessage.Define(LogLevel.Debug, 2, @"Connection id ""{ConnectionId}"" stopped."); + // ConnectionRead: Reserved: 3 + _connectionPause = LoggerMessage.Define(LogLevel.Debug, 4, @"Connection id ""{ConnectionId}"" paused."); + _connectionResume = LoggerMessage.Define(LogLevel.Debug, 5, @"Connection id ""{ConnectionId}"" resumed."); + _connectionReadFin = LoggerMessage.Define(LogLevel.Debug, 6, @"Connection id ""{ConnectionId}"" received FIN."); + _connectionWriteFin = LoggerMessage.Define(LogLevel.Debug, 7, @"Connection id ""{ConnectionId}"" sending FIN."); + _connectionWroteFin = LoggerMessage.Define(LogLevel.Debug, 8, @"Connection id ""{ConnectionId}"" sent FIN with status ""{Status}""."); + _connectionKeepAlive = LoggerMessage.Define(LogLevel.Debug, 9, @"Connection id ""{ConnectionId}"" completed keep alive response."); + _connectionDisconnect = LoggerMessage.Define(LogLevel.Error, 10, @"Connection id ""{ConnectionId}"" disconnected."); + // ConnectionWrite: Reserved: 11 + // ConnectionWriteCallback: Reserved: 12 + // ApplicationError: Reserved: 13 - LoggerMessage.Define overload not present + } + public KestrelTrace(ILogger logger) { _logger = logger; @@ -21,12 +48,12 @@ namespace Microsoft.AspNet.Server.Kestrel public virtual void ConnectionStart(long connectionId) { - _logger.LogDebug(1, @"Connection id ""{ConnectionId}"" started.", connectionId); + _connectionStart(_logger, connectionId, null); } public virtual void ConnectionStop(long connectionId) { - _logger.LogDebug(2, @"Connection id ""{ConnectionId}"" stopped.", connectionId); + _connectionStop(_logger, connectionId, null); } public virtual void ConnectionRead(long connectionId, int count) @@ -37,37 +64,37 @@ namespace Microsoft.AspNet.Server.Kestrel public virtual void ConnectionPause(long connectionId) { - _logger.LogDebug(4, @"Connection id ""{ConnectionId}"" paused.", connectionId); + _connectionPause(_logger, connectionId, null); } public virtual void ConnectionResume(long connectionId) { - _logger.LogDebug(5, @"Connection id ""{ConnectionId}"" resumed.", connectionId); + _connectionResume(_logger, connectionId, null); } public virtual void ConnectionReadFin(long connectionId) { - _logger.LogDebug(6, @"Connection id ""{ConnectionId}"" received FIN.", connectionId); + _connectionReadFin(_logger, connectionId, null); } public virtual void ConnectionWriteFin(long connectionId) { - _logger.LogDebug(7, @"Connection id ""{ConnectionId}"" sending FIN.", connectionId); + _connectionWriteFin(_logger, connectionId, null); } public virtual void ConnectionWroteFin(long connectionId, int status) { - _logger.LogDebug(8, @"Connection id ""{ConnectionId}"" sent FIN with status ""{Status}"".", connectionId, status); + _connectionWroteFin(_logger, connectionId, status, null); } public virtual void ConnectionKeepAlive(long connectionId) { - _logger.LogDebug(9, @"Connection id ""{ConnectionId}"" completed keep alive response.", connectionId); + _connectionKeepAlive(_logger, connectionId, null); } public virtual void ConnectionDisconnect(long connectionId) { - _logger.LogDebug(10, @"Connection id ""{ConnectionId}"" disconnected.", connectionId); + _connectionDisconnect(_logger, connectionId, null); } public virtual void ConnectionWrite(long connectionId, int count) diff --git a/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs index 983017cfa0..c892973375 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs @@ -904,12 +904,12 @@ namespace Microsoft.AspNet.Server.KestrelTests public IDisposable BeginScopeImpl(object state) { - throw new NotImplementedException(); + return new Disposable(() => { }); } public bool IsEnabled(LogLevel logLevel) { - throw new NotImplementedException(); + return true; } public void Log(LogLevel logLevel, int eventId, object state, Exception exception, Func formatter) From d08b83a1c7241bca66c6934facb2410f118489c3 Mon Sep 17 00:00:00 2001 From: Troy Dai Date: Tue, 10 Nov 2015 10:04:10 -0800 Subject: [PATCH 0403/1662] Fix get IPAddress for Darwin --- .../Networking/SockAddr.cs | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/SockAddr.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/SockAddr.cs index c101de111e..eb4cb214d6 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/SockAddr.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/SockAddr.cs @@ -41,18 +41,32 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking // 0000 0000 0000 0000 // // Example 3: 10.135.34.141:12804, not dual-stack sockets + // // 8d22 870a fd31 0002 => sa_family == AF_INET (02) // 0000 0000 0000 0000 // 0000 0000 0000 0000 // 0000 0000 0000 0000 - + // + // Example 4: 127.0.0.1:52798, on a Mac OS + // + // 0100 007F 3ECE 0210 => sa_family == AF_INET (02) Note that struct sockaddr on mac use + // 0000 0000 0000 0000 the second unint8 field for sa family type + // 0000 0000 0000 0000 http://www.opensource.apple.com/source/xnu/xnu-1456.1.26/bsd/sys/socket.h + // 0000 0000 0000 0000 // Quick calculate the port by mask the field and locate the byte 3 and byte 4 // and then shift them to correct place to form a int. var port = ((int)(_field0 & 0x00FF0000) >> 8) | (int)((_field0 & 0xFF000000) >> 24); + + int family = (int)_field0; + if (PlatformApis.IsDarwin()) + { + // see explaination in example 4 + family = family >> 8; + } + family = family & 0xFF; - var family = (int)_field0 & 0x000000FF; - if (family == 0x00000002) + if (family == 2) { // AF_INET => IPv4 return new IPEndPoint(new IPAddress((_field0 >> 32) & 0xFFFFFFFF), port); From 344c821f83979eb8b406d0df975d95b6d8d99ea5 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Tue, 10 Nov 2015 16:24:13 +0000 Subject: [PATCH 0404/1662] Remove sync block->task await rather than synchronously blocking and then returning a Task.FromResult --- .../Http/Frame.FeatureCollection.cs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.FeatureCollection.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.FeatureCollection.cs index 1a4efb32fb..2159d70056 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.FeatureCollection.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.FeatureCollection.cs @@ -277,7 +277,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http OnCompleted(callback, state); } - Task IHttpUpgradeFeature.UpgradeAsync() + async Task IHttpUpgradeFeature.UpgradeAsync() { StatusCode = 101; ReasonPhrase = "Switching Protocols"; @@ -290,8 +290,10 @@ namespace Microsoft.AspNet.Server.Kestrel.Http ResponseHeaders["Upgrade"] = values; } } - ProduceStartAndFireOnStarting(immediate: true).GetAwaiter().GetResult(); - return Task.FromResult(DuplexStream); + + await ProduceStartAndFireOnStarting(immediate: true); + + return DuplexStream; } IEnumerator> IEnumerable>.GetEnumerator() => FastEnumerable().GetEnumerator(); From d9c15e0180c1e5e078a04a72f26d9259743eaa71 Mon Sep 17 00:00:00 2001 From: Troy Dai Date: Tue, 10 Nov 2015 10:37:12 -0800 Subject: [PATCH 0405/1662] Add references to socket in comments --- src/Microsoft.AspNet.Server.Kestrel/Networking/SockAddr.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/SockAddr.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/SockAddr.cs index eb4cb214d6..2d41ed701a 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/SockAddr.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/SockAddr.cs @@ -53,6 +53,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking // 0000 0000 0000 0000 the second unint8 field for sa family type // 0000 0000 0000 0000 http://www.opensource.apple.com/source/xnu/xnu-1456.1.26/bsd/sys/socket.h // 0000 0000 0000 0000 + // + // Reference: + // - Windows: https://msdn.microsoft.com/en-us/library/windows/desktop/ms740506(v=vs.85).aspx + // - Linux: https://github.com/torvalds/linux/blob/master/include/linux/socket.h + // - Apple: http://www.opensource.apple.com/source/xnu/xnu-1456.1.26/bsd/sys/socket.h // Quick calculate the port by mask the field and locate the byte 3 and byte 4 // and then shift them to correct place to form a int. From d0bdede7098e3ff0999edc74ebbcea79b2118c47 Mon Sep 17 00:00:00 2001 From: Troy Dai Date: Tue, 10 Nov 2015 11:11:32 -0800 Subject: [PATCH 0406/1662] Update the reference link in comments of SockAddr --- src/Microsoft.AspNet.Server.Kestrel/Networking/SockAddr.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/SockAddr.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/SockAddr.cs index 2d41ed701a..3be4ee9301 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/SockAddr.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/SockAddr.cs @@ -56,7 +56,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking // // Reference: // - Windows: https://msdn.microsoft.com/en-us/library/windows/desktop/ms740506(v=vs.85).aspx - // - Linux: https://github.com/torvalds/linux/blob/master/include/linux/socket.h + // - Linux: https://github.com/torvalds/linux/blob/6a13feb9c82803e2b815eca72fa7a9f5561d7861/include/linux/socket.h // - Apple: http://www.opensource.apple.com/source/xnu/xnu-1456.1.26/bsd/sys/socket.h // Quick calculate the port by mask the field and locate the byte 3 and byte 4 From 34cec3448dd64f280d47a617082e31de4f0eafa4 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Tue, 10 Nov 2015 17:17:25 +0000 Subject: [PATCH 0407/1662] SocketOutput to Tasks --- .../Http/SocketOutput.cs | 176 +++++------------- .../SocketOutputTests.cs | 24 +-- 2 files changed, 57 insertions(+), 143 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs index d0d218ac5a..d65c93077f 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs @@ -31,7 +31,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http private int _numBytesPreCompleted = 0; private Exception _lastWriteError; private WriteContext _nextWriteContext; - private readonly Queue _callbacksPending; + private readonly Queue> _tasksPending; public SocketOutput(KestrelThread thread, UvStreamHandle socket, long connectionId, IKestrelTrace log) { @@ -39,13 +39,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http _socket = socket; _connectionId = connectionId; _log = log; - _callbacksPending = new Queue(); + _tasksPending = new Queue>(); } - public void Write( + public Task WriteAsync( ArraySegment buffer, - Action callback, - object state, bool immediate = true, bool socketShutdownSend = false, bool socketDisconnect = false) @@ -58,8 +56,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http buffer = new ArraySegment(copy); _log.ConnectionWrite(_connectionId, buffer.Count); } - - bool triggerCallbackNow = false; + + TaskCompletionSource tcs = null; lock (_lockObj) { @@ -80,23 +78,25 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { _nextWriteContext.SocketDisconnect = true; } + // Complete the write task immediately if all previous write tasks have been completed, // the buffers haven't grown too large, and the last write to the socket succeeded. - triggerCallbackNow = _lastWriteError == null && - _callbacksPending.Count == 0 && - _numBytesPreCompleted + buffer.Count <= _maxBytesPreCompleted; - if (triggerCallbackNow) + if (_lastWriteError == null && + _tasksPending.Count == 0 && + _numBytesPreCompleted + buffer.Count <= _maxBytesPreCompleted) { _numBytesPreCompleted += buffer.Count; } + else if (immediate) + { + // immediate write, which is not eligable for instant completion above + tcs = new TaskCompletionSource(buffer.Count); + _tasksPending.Enqueue(tcs); + } else { - _callbacksPending.Enqueue(new CallbackContext - { - Callback = callback, - State = state, - BytesToWrite = buffer.Count - }); + // immediate==false calls always return complete tasks, because there is guaranteed + // to be a subsequent immediate==true call which will go down one of the previous code-paths } if (_writesPending < _maxPendingWrites && immediate) @@ -106,12 +106,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } - // Make sure we call user code outside of the lock. - if (triggerCallbackNow) - { - // callback(error, state, calledInline) - callback(null, state, true); - } + // Return TaskCompletionSource's Task if set, otherwise completed Task + return tcs?.Task ?? TaskUtilities.CompletedTask; } public void End(ProduceEndType endType) @@ -119,13 +115,13 @@ namespace Microsoft.AspNet.Server.Kestrel.Http switch (endType) { case ProduceEndType.SocketShutdownSend: - Write(default(ArraySegment), (error, state, calledInline) => { }, null, + WriteAsync(default(ArraySegment), immediate: true, socketShutdownSend: true, socketDisconnect: false); break; case ProduceEndType.SocketDisconnect: - Write(default(ArraySegment), (error, state, calledInline) => { }, null, + WriteAsync(default(ArraySegment), immediate: true, socketShutdownSend: false, socketDisconnect: true); @@ -198,20 +194,30 @@ namespace Microsoft.AspNet.Server.Kestrel.Http // completed writes that we haven't triggered callbacks for yet. _numBytesPreCompleted -= writeBuffer.Count; } - - + // bytesLeftToBuffer can be greater than _maxBytesPreCompleted // This allows large writes to complete once they've actually finished. var bytesLeftToBuffer = _maxBytesPreCompleted - _numBytesPreCompleted; - while (_callbacksPending.Count > 0 && - _callbacksPending.Peek().BytesToWrite <= bytesLeftToBuffer) + while (_tasksPending.Count > 0 && + (int)(_tasksPending.Peek().Task.AsyncState) <= bytesLeftToBuffer) { - var callbackContext = _callbacksPending.Dequeue(); + var tcs = _tasksPending.Dequeue(); - _numBytesPreCompleted += callbackContext.BytesToWrite; + _numBytesPreCompleted += (int)(tcs.Task.AsyncState); - // callback(error, state, calledInline) - callbackContext.Callback(_lastWriteError, callbackContext.State, false); + if (error == null) + { + ThreadPool.QueueUserWorkItem( + (o) => ((TaskCompletionSource)o).SetResult(null), + tcs); + } + else + { + // error is closure captured + ThreadPool.QueueUserWorkItem( + (o) => ((TaskCompletionSource)o).SetException(error), + tcs); + } } // Now that the while loop has completed the following invariants should hold true: @@ -222,104 +228,21 @@ namespace Microsoft.AspNet.Server.Kestrel.Http void ISocketOutput.Write(ArraySegment buffer, bool immediate) { - if (!immediate) + var task = WriteAsync(buffer, immediate); + + if (task.Status == TaskStatus.RanToCompletion) { - // immediate==false calls always return complete tasks, because there is guaranteed - // to be a subsequent immediate==true call which will go down the following code-path - Write( - buffer, - (error, state, calledInline) => { }, - null, - immediate: false); return; } - - // TODO: Optimize task being used, and remove callback model from the underlying Write - var tcs = new TaskCompletionSource(); - - Write( - buffer, - (error, state, calledInline) => - { - if (error != null) - { - tcs.SetException(error); - } - else - { - tcs.SetResult(0); - } - }, - tcs, - immediate: true); - - if (tcs.Task.Status != TaskStatus.RanToCompletion) + else { - tcs.Task.GetAwaiter().GetResult(); + task.GetAwaiter().GetResult(); } } Task ISocketOutput.WriteAsync(ArraySegment buffer, bool immediate, CancellationToken cancellationToken) { - if (!immediate) - { - // immediate==false calls always return complete tasks, because there is guaranteed - // to be a subsequent immediate==true call which will go down the following code-path - Write( - buffer, - (error, state, calledInline) => { }, - null, - immediate: false); - return TaskUtilities.CompletedTask; - } - - // TODO: Optimize task being used, and remove callback model from the underlying Write - var tcs = new TaskCompletionSource(); - - Write( - buffer, - (error, state, calledInline) => - { - if (!calledInline) - { - ThreadPool.QueueUserWorkItem(state2 => - { - var tcs2 = (TaskCompletionSource)state2; - if (error != null) - { - tcs2.SetException(error); - } - else - { - tcs2.SetResult(0); - } - }, state); - } - else - { - var tcs2 = (TaskCompletionSource)state; - if (error != null) - { - tcs2.SetException(error); - } - else - { - tcs2.SetResult(0); - } - } - }, - tcs, - immediate: true); - - return tcs.Task; - } - - private class CallbackContext - { - // callback(error, state, calledInline) - public Action Callback; - public object State; - public int BytesToWrite; + return WriteAsync(buffer, immediate); } private class WriteContext @@ -341,15 +264,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Http Buffers = new Queue>(); } - /// - /// Perform any actions needed by this work item. The individual tasks are non-blocking and - /// will continue through to each other in order. - /// - public void Execute() - { - DoWriteIfNeeded(); - } - /// /// First step: initiate async write if needed, otherwise go to next step /// diff --git a/test/Microsoft.AspNet.Server.KestrelTests/SocketOutputTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/SocketOutputTests.cs index 8e0425ce52..4f697ea39f 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/SocketOutputTests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/SocketOutputTests.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using System.Threading; +using System.Threading.Tasks; using Microsoft.AspNet.Server.Kestrel; using Microsoft.AspNet.Server.Kestrel.Http; using Microsoft.AspNet.Server.Kestrel.Infrastructure; @@ -45,15 +46,15 @@ namespace Microsoft.AspNet.Server.KestrelTests var bufferSize = 1048576; var buffer = new ArraySegment(new byte[bufferSize], 0, bufferSize); var completedWh = new ManualResetEventSlim(); - Action onCompleted = (ex, state, calledInline) => - { - Assert.Null(ex); - Assert.Null(state); - completedWh.Set(); - }; // Act - socketOutput.Write(buffer, onCompleted, null); + socketOutput.WriteAsync(buffer).ContinueWith( + (t) => + { + Assert.Null(t.Exception); + completedWh.Set(); + } + ); // Assert Assert.True(completedWh.Wait(1000)); @@ -89,22 +90,21 @@ namespace Microsoft.AspNet.Server.KestrelTests var bufferSize = maxBytesPreCompleted; var buffer = new ArraySegment(new byte[bufferSize], 0, bufferSize); var completedWh = new ManualResetEventSlim(); - Action onCompleted = (ex, state, calledInline) => + Action onCompleted = (Task t) => { - Assert.Null(ex); - Assert.Null(state); + Assert.Null(t.Exception); completedWh.Set(); }; // Act - socketOutput.Write(buffer, onCompleted, null); + socketOutput.WriteAsync(buffer).ContinueWith(onCompleted); // Assert // The first write should pre-complete since it is <= _maxBytesPreCompleted. Assert.True(completedWh.Wait(1000)); // Arrange completedWh.Reset(); // Act - socketOutput.Write(buffer, onCompleted, null); + socketOutput.WriteAsync(buffer).ContinueWith(onCompleted); // Assert // Too many bytes are already pre-completed for the second write to pre-complete. Assert.False(completedWh.Wait(1000)); From d32937eafeaf07654789535bef9fef65fd012467 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Tue, 10 Nov 2015 20:51:34 +0000 Subject: [PATCH 0408/1662] Add tests for non-immediate byte counting --- .../Http/SocketOutput.cs | 26 +++---- .../SocketOutputTests.cs | 76 +++++++++++++++++++ 2 files changed, 89 insertions(+), 13 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs index d65c93077f..609d59ef3e 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs @@ -56,7 +56,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http buffer = new ArraySegment(copy); _log.ConnectionWrite(_connectionId, buffer.Count); } - + TaskCompletionSource tcs = null; lock (_lockObj) @@ -79,25 +79,26 @@ namespace Microsoft.AspNet.Server.Kestrel.Http _nextWriteContext.SocketDisconnect = true; } - // Complete the write task immediately if all previous write tasks have been completed, - // the buffers haven't grown too large, and the last write to the socket succeeded. - if (_lastWriteError == null && - _tasksPending.Count == 0 && - _numBytesPreCompleted + buffer.Count <= _maxBytesPreCompleted) + if (!immediate) { + // immediate==false calls always return complete tasks, because there is guaranteed + // to be a subsequent immediate==true call which will go down one of the previous code-paths _numBytesPreCompleted += buffer.Count; } - else if (immediate) + else if (_lastWriteError == null && + _tasksPending.Count == 0 && + _numBytesPreCompleted + buffer.Count <= _maxBytesPreCompleted) + { + // Complete the write task immediately if all previous write tasks have been completed, + // the buffers haven't grown too large, and the last write to the socket succeeded. + _numBytesPreCompleted += buffer.Count; + } + else { // immediate write, which is not eligable for instant completion above tcs = new TaskCompletionSource(buffer.Count); _tasksPending.Enqueue(tcs); } - else - { - // immediate==false calls always return complete tasks, because there is guaranteed - // to be a subsequent immediate==true call which will go down one of the previous code-paths - } if (_writesPending < _maxPendingWrites && immediate) { @@ -222,7 +223,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Http // Now that the while loop has completed the following invariants should hold true: Debug.Assert(_numBytesPreCompleted >= 0); - Debug.Assert(_numBytesPreCompleted <= _maxBytesPreCompleted); } } diff --git a/test/Microsoft.AspNet.Server.KestrelTests/SocketOutputTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/SocketOutputTests.cs index 4f697ea39f..faf3116340 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/SocketOutputTests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/SocketOutputTests.cs @@ -115,6 +115,82 @@ namespace Microsoft.AspNet.Server.KestrelTests Assert.True(completedWh.Wait(1000)); } } + + [Fact] + public void WritesDontCompleteImmediatelyWhenTooManyBytesIncludingNonImmediateAreAlreadyPreCompleted() + { + // This should match _maxBytesPreCompleted in SocketOutput + var maxBytesPreCompleted = 65536; + var completeQueue = new Queue>(); + + // Arrange + var mockLibuv = new MockLibuv + { + OnWrite = (socket, buffers, triggerCompleted) => + { + completeQueue.Enqueue(triggerCompleted); + return 0; + } + }; + + using (var kestrelEngine = new KestrelEngine(mockLibuv, new TestServiceContext())) + { + kestrelEngine.Start(count: 1); + + var kestrelThread = kestrelEngine.Threads[0]; + var socket = new MockSocket(kestrelThread.Loop.ThreadId, new TestKestrelTrace()); + var trace = new KestrelTrace(new TestKestrelTrace()); + var socketOutput = new SocketOutput(kestrelThread, socket, 0, trace); + + var bufferSize = maxBytesPreCompleted; + + var data = new byte[bufferSize]; + var fullBuffer = new ArraySegment(data, 0, bufferSize); + var halfBuffer = new ArraySegment(data, 0, bufferSize / 2); + + var completedWh = new ManualResetEventSlim(); + Action onCompleted = (Task t) => + { + Assert.Null(t.Exception); + completedWh.Set(); + }; + + // Act + socketOutput.WriteAsync(halfBuffer, false).ContinueWith(onCompleted); + // Assert + // The first write should pre-complete since it is not immediate. + Assert.True(completedWh.Wait(1000)); + // Arrange + completedWh.Reset(); + // Act + socketOutput.WriteAsync(halfBuffer).ContinueWith(onCompleted); + // Assert + // The second write should pre-complete since it is <= _maxBytesPreCompleted. + Assert.True(completedWh.Wait(1000)); + // Arrange + completedWh.Reset(); + // Act + socketOutput.WriteAsync(halfBuffer, false).ContinueWith(onCompleted); + // Assert + // The third write should pre-complete since it is not immediate, even though too many. + Assert.True(completedWh.Wait(1000)); + // Arrange + completedWh.Reset(); + // Act + socketOutput.WriteAsync(halfBuffer).ContinueWith(onCompleted); + // Assert + // Too many bytes are already pre-completed for the fourth write to pre-complete. + Assert.False(completedWh.Wait(1000)); + // Act + while (completeQueue.Count > 0) + { + completeQueue.Dequeue()(0); + } + // Assert + // Finishing the first write should allow the second write to pre-complete. + Assert.True(completedWh.Wait(1000)); + } + } private class MockSocket : UvStreamHandle { From 55f6f21d5ac4fe640d5714274c3861c1593ff57d Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Mon, 9 Nov 2015 16:39:40 -0800 Subject: [PATCH 0409/1662] Build Microsoft.AspNet.Server.Kestrel.Https for dotnet5.4 --- samples/SampleApp/Startup.cs | 13 ++++--------- samples/SampleApp/project.json | 4 +--- .../project.json | 7 ++++++- .../HttpsConnectionFilterTests.cs | 13 ++++++++++--- .../project.json | 12 +++++------- 5 files changed, 26 insertions(+), 23 deletions(-) diff --git a/samples/SampleApp/Startup.cs b/samples/SampleApp/Startup.cs index 61bd9a3aa1..7ececbb741 100644 --- a/samples/SampleApp/Startup.cs +++ b/samples/SampleApp/Startup.cs @@ -2,18 +2,15 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.IO; +using System.Security.Cryptography.X509Certificates; using Microsoft.AspNet.Builder; using Microsoft.AspNet.Http; using Microsoft.AspNet.Http.Features; using Microsoft.AspNet.Server.Kestrel; -using Microsoft.Extensions.PlatformAbstractions; -using Microsoft.Extensions.Logging; - -#if DNX451 -using System.IO; -using System.Security.Cryptography.X509Certificates; using Microsoft.AspNet.Server.Kestrel.Https; -#endif +using Microsoft.Extensions.Logging; +using Microsoft.Extensions.PlatformAbstractions; namespace SampleApp { @@ -29,7 +26,6 @@ namespace SampleApp loggerFactory.AddConsole(LogLevel.Debug); -#if DNX451 var testCertPath = Path.Combine( env.ApplicationBasePath, @"../../test/Microsoft.AspNet.Server.KestrelTests/TestResources/testCert.pfx"); @@ -42,7 +38,6 @@ namespace SampleApp { Console.WriteLine("Could not find certificate at '{0}'. HTTPS is not enabled.", testCertPath); } -#endif app.Run(async context => { diff --git a/samples/SampleApp/project.json b/samples/SampleApp/project.json index fb159ea155..751414ca5d 100644 --- a/samples/SampleApp/project.json +++ b/samples/SampleApp/project.json @@ -2,13 +2,11 @@ "version": "1.0.0-*", "dependencies": { "Microsoft.AspNet.Server.Kestrel": "1.0.0-*", + "Microsoft.AspNet.Server.Kestrel.Https": "1.0.0-*", "Microsoft.Extensions.Logging.Console": "1.0.0-*" }, "frameworks": { "dnx451": { - "dependencies": { - "Microsoft.AspNet.Server.Kestrel.Https": "1.0.0-*" - } }, "dnxcore50": { "dependencies": { diff --git a/src/Microsoft.AspNet.Server.Kestrel.Https/project.json b/src/Microsoft.AspNet.Server.Kestrel.Https/project.json index 3d47f866e2..5067c4bf98 100644 --- a/src/Microsoft.AspNet.Server.Kestrel.Https/project.json +++ b/src/Microsoft.AspNet.Server.Kestrel.Https/project.json @@ -12,6 +12,11 @@ "Microsoft.AspNet.Server.Kestrel": "1.0.0-*" }, "frameworks": { - "net451": { } + "net451": { }, + "dotnet5.4": { + "dependencies": { + "System.Net.Security": "4.0.0-beta-*" + } + } } } \ No newline at end of file diff --git a/test/Microsoft.AspNet.Server.KestrelTests/HttpsConnectionFilterTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/HttpsConnectionFilterTests.cs index b4e5dbe443..cf68bd89b1 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/HttpsConnectionFilterTests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/HttpsConnectionFilterTests.cs @@ -1,7 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -#if DNX451 +using System; using System.Collections.Generic; using System.Net; using System.Net.Http; @@ -47,7 +47,13 @@ namespace Microsoft.AspNet.Server.KestrelTests try { +#if DNX451 + var handler = new HttpClientHandler(); ServicePointManager.ServerCertificateValidationCallback += validationCallback; +#else + var handler = new WinHttpHandler(); + handler.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true; +#endif var sereverAddress = "https://localhost:54321/"; var serviceContext = new TestServiceContext() @@ -59,7 +65,7 @@ namespace Microsoft.AspNet.Server.KestrelTests using (var server = new TestServer(App, serviceContext, sereverAddress)) { - using (var client = new HttpClient()) + using (var client = new HttpClient(handler)) { var result = await client.PostAsync(sereverAddress, new FormUrlEncodedContent(new[] { new KeyValuePair("content", "Hello World?") @@ -71,9 +77,10 @@ namespace Microsoft.AspNet.Server.KestrelTests } finally { +#if DNX451 ServicePointManager.ServerCertificateValidationCallback -= validationCallback; +#endif } } } } -#endif diff --git a/test/Microsoft.AspNet.Server.KestrelTests/project.json b/test/Microsoft.AspNet.Server.KestrelTests/project.json index 61719edb2a..730c809d15 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/project.json +++ b/test/Microsoft.AspNet.Server.KestrelTests/project.json @@ -3,19 +3,17 @@ "dependencies": { "xunit.runner.aspnet": "2.0.0-aspnet-*", "Microsoft.AspNet.Server.Kestrel": "1.0.0-*", - "Microsoft.AspNet.Testing": "1.0.0-*" + "Microsoft.AspNet.Server.Kestrel.Https": "1.0.0-*", + "Microsoft.AspNet.Testing": "1.0.0-*", + "System.Net.Http": "4.0.1-beta-*" }, "frameworks": { - "dnx451": { - "dependencies": { - "System.Net.Http": "4.0.1-beta-*", - "Microsoft.AspNet.Server.Kestrel.Https": "1.0.0-*" - } - }, + "dnx451": { }, "dnxcore50": { "dependencies": { "System.Diagnostics.TraceSource": "4.0.0-beta-*", "System.IO": "4.0.11-beta-*", + "System.Net.Http.WinHttpHandler": "4.0.0-beta-*", "System.Net.Sockets": "4.1.0-beta-*", "System.Runtime.Handles": "4.0.1-beta-*" } From d1221e82c1da69b676de7b3e349e7ed9308927f7 Mon Sep 17 00:00:00 2001 From: Nick Craver Date: Tue, 10 Nov 2015 22:58:19 -0500 Subject: [PATCH 0410/1662] Pass cancellation tokens down consistently I'm assuming these are oversights since the usage is inconsistent. Otherwise this served only as a mild waste of time :) --- src/Microsoft.AspNet.Server.Kestrel/Filter/LibuvStream.cs | 2 +- src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs | 2 +- src/Microsoft.AspNet.Server.Kestrel/Http/FrameRequestStream.cs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Filter/LibuvStream.cs b/src/Microsoft.AspNet.Server.Kestrel/Filter/LibuvStream.cs index 16f3ce2c1b..4f63195760 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Filter/LibuvStream.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Filter/LibuvStream.cs @@ -75,7 +75,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Filter public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken token) { var segment = new ArraySegment(buffer, offset, count); - return _output.WriteAsync(segment); + return _output.WriteAsync(segment, cancellationToken: token); } public override void Flush() diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs index 36f1d92319..c08d0eb684 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs @@ -349,7 +349,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http public async Task FlushAsync(CancellationToken cancellationToken) { await ProduceStartAndFireOnStarting(immediate: false); - await SocketOutput.WriteAsync(_emptyData, immediate: true); + await SocketOutput.WriteAsync(_emptyData, immediate: true, cancellationToken: cancellationToken); } public void Write(ArraySegment data) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameRequestStream.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameRequestStream.cs index 714728dd43..b0fed05f09 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameRequestStream.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameRequestStream.cs @@ -94,7 +94,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { tcs2.SetResult(task2.Result); } - }, tcs); + }, tcs, cancellationToken); return tcs.Task; } From 0500043cc9c4464fda96103f32ca7f4ed667a5f2 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Wed, 11 Nov 2015 09:46:56 +0000 Subject: [PATCH 0411/1662] .Result -> .GetAwaiter().GetResult() --- src/Microsoft.AspNet.Server.Kestrel/Http/FrameRequestStream.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameRequestStream.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameRequestStream.cs index 714728dd43..10e6e425cc 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameRequestStream.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameRequestStream.cs @@ -50,7 +50,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http public override int Read(byte[] buffer, int offset, int count) { - return ReadAsync(buffer, offset, count).Result; + return ReadAsync(buffer, offset, count).GetAwaiter().GetResult(); } #if NET451 From ade0dbadb337b19b476f308e2f6a0ef42a11f846 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Wed, 11 Nov 2015 13:06:15 +0000 Subject: [PATCH 0412/1662] Slow date wait for CI Resolves #339 --- .../DateHeaderValueManagerTests.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/Microsoft.AspNet.Server.KestrelTests/DateHeaderValueManagerTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/DateHeaderValueManagerTests.cs index ca4fd8ff01..ef5e31ca6d 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/DateHeaderValueManagerTests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/DateHeaderValueManagerTests.cs @@ -77,8 +77,8 @@ namespace Microsoft.AspNet.Server.KestrelTests { UtcNow = now }; - var timeWithoutRequestsUntilIdle = TimeSpan.FromMilliseconds(50); - var timerInterval = TimeSpan.FromMilliseconds(10); + var timeWithoutRequestsUntilIdle = TimeSpan.FromMilliseconds(250); + var timerInterval = TimeSpan.FromMilliseconds(100); var dateHeaderValueManager = new DateHeaderValueManager(systemClock, timeWithoutRequestsUntilIdle, timerInterval); string result1; string result2; @@ -87,8 +87,8 @@ namespace Microsoft.AspNet.Server.KestrelTests { result1 = dateHeaderValueManager.GetDateHeaderValue(); systemClock.UtcNow = future; - // Wait for twice the idle timeout to ensure the timer is stopped - await Task.Delay(timeWithoutRequestsUntilIdle.Add(timeWithoutRequestsUntilIdle)); + // Wait for longer than the idle timeout to ensure the timer is stopped + await Task.Delay(TimeSpan.FromSeconds(1)); result2 = dateHeaderValueManager.GetDateHeaderValue(); } finally From e5ff33eda2a581cd976dfca44fe38b19b1ec5821 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Mon, 9 Nov 2015 19:31:46 -0800 Subject: [PATCH 0413/1662] Remove UvAsyncHandle.DangerousClose - This should stop the AVs we've been seeing in some of our test runs --- .../Infrastructure/KestrelThread.cs | 25 +++++++++++++++---- .../Networking/UvAsyncHandle.cs | 6 ----- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs index 85a4b50621..a8608de70f 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs @@ -67,10 +67,24 @@ namespace Microsoft.AspNet.Server.Kestrel Post(OnStop, null); if (!_thread.Join((int)timeout.TotalMilliseconds)) { - Post(OnStopRude, null); - if (!_thread.Join((int)timeout.TotalMilliseconds)) + try { - Post(OnStopImmediate, null); + Post(OnStopRude, null); + if (!_thread.Join((int)timeout.TotalMilliseconds)) + { + Post(OnStopImmediate, null); + if (!_thread.Join((int)timeout.TotalMilliseconds)) + { +#if NET451 + _thread.Abort(); +#endif + } + } + } + catch (ObjectDisposedException) + { + // REVIEW: Should we log something here? + // Until we rework this logic, ODEs are bound to happen sometimes. if (!_thread.Join((int)timeout.TotalMilliseconds)) { #if NET451 @@ -79,6 +93,7 @@ namespace Microsoft.AspNet.Server.Kestrel } } } + if (_closeError != null) { _closeError.Throw(); @@ -217,7 +232,7 @@ namespace Microsoft.AspNet.Server.Kestrel // run the loop one more time to delete the open handles _post.Reference(); - _post.DangerousClose(); + _post.Dispose(); _engine.Libuv.walk( _loop, @@ -231,7 +246,7 @@ namespace Microsoft.AspNet.Server.Kestrel }, IntPtr.Zero); - // Ensure the "DangerousClose" operation completes in the event loop. + // Ensure the Dispose operations complete in the event loop. var ran2 = _loop.Run(); _loop.Dispose(); diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvAsyncHandle.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvAsyncHandle.cs index 9b4ecb60f8..03c6ece9e5 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvAsyncHandle.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvAsyncHandle.cs @@ -26,12 +26,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking _uv.async_init(loop, this, _uv_async_cb); } - public void DangerousClose() - { - Dispose(); - ReleaseHandle(); - } - public void Send() { _uv.async_send(this); From a45a671b2253ac40df7652af0b52b26dc3a13bfa Mon Sep 17 00:00:00 2001 From: Nick Craver Date: Wed, 11 Nov 2015 18:55:56 -0500 Subject: [PATCH 0414/1662] Make ReadAsync state overload 451 only and private. --- .../Http/FrameRequestStream.cs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameRequestStream.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameRequestStream.cs index b0fed05f09..706ee8bf11 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameRequestStream.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameRequestStream.cs @@ -68,14 +68,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { return ((Task)asyncResult).Result; } -#endif - public override Task ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) - { - return _body.ReadAsync(new ArraySegment(buffer, offset, count), cancellationToken); - } - - public Task ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken, object state) + private Task ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken, object state) { var tcs = new TaskCompletionSource(state); var task = _body.ReadAsync(new ArraySegment(buffer, offset, count), cancellationToken); @@ -97,6 +91,12 @@ namespace Microsoft.AspNet.Server.Kestrel.Http }, tcs, cancellationToken); return tcs.Task; } +#endif + + public override Task ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) + { + return _body.ReadAsync(new ArraySegment(buffer, offset, count), cancellationToken); + } public override void Write(byte[] buffer, int offset, int count) { From 86e1924cadde5342db9f7395979d6bd6490bdb34 Mon Sep 17 00:00:00 2001 From: "N. Taylor Mullen" Date: Thu, 12 Nov 2015 12:23:45 -0800 Subject: [PATCH 0415/1662] Remove System beta tag in project.json for coreclr packages. --- samples/SampleApp/project.json | 2 +- .../project.json | 4 +- .../project.json | 68 +++++++++---------- .../project.json | 4 +- .../project.json | 12 ++-- .../project.json | 2 +- .../project.json | 14 ++-- tools/Microsoft.StandardsPolice/project.json | 6 +- 8 files changed, 56 insertions(+), 56 deletions(-) diff --git a/samples/SampleApp/project.json b/samples/SampleApp/project.json index 751414ca5d..f9e44a2a05 100644 --- a/samples/SampleApp/project.json +++ b/samples/SampleApp/project.json @@ -10,7 +10,7 @@ }, "dnxcore50": { "dependencies": { - "System.Console": "4.0.0-beta-*" + "System.Console": "4.0.0-*" } } }, diff --git a/src/Microsoft.AspNet.Server.Kestrel.Https/project.json b/src/Microsoft.AspNet.Server.Kestrel.Https/project.json index 5067c4bf98..9598ce03d5 100644 --- a/src/Microsoft.AspNet.Server.Kestrel.Https/project.json +++ b/src/Microsoft.AspNet.Server.Kestrel.Https/project.json @@ -15,8 +15,8 @@ "net451": { }, "dotnet5.4": { "dependencies": { - "System.Net.Security": "4.0.0-beta-*" + "System.Net.Security": "4.0.0-*" } } } -} \ No newline at end of file +} diff --git a/src/Microsoft.AspNet.Server.Kestrel/project.json b/src/Microsoft.AspNet.Server.Kestrel/project.json index 2fb2fa9659..edae688097 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/project.json +++ b/src/Microsoft.AspNet.Server.Kestrel/project.json @@ -8,7 +8,7 @@ "dependencies": { "Microsoft.AspNet.Hosting": "1.0.0-*", "Microsoft.Extensions.Logging.Abstractions": "1.0.0-*", - "System.Numerics.Vectors": "4.1.1-beta-*", + "System.Numerics.Vectors": "4.1.1-*", "Microsoft.StandardsPolice": { "version": "1.0.0-*", "type": "build" @@ -27,42 +27,42 @@ "net451": { }, "dnxcore50": { "dependencies": { - "System.Collections": "4.0.11-beta-*", - "System.Diagnostics.Debug": "4.0.11-beta-*", - "System.Diagnostics.TraceSource": "4.0.0-beta-*", - "System.Diagnostics.Tracing": "4.0.21-beta-*", - "System.Globalization": "4.0.11-beta-*", - "System.IO": "4.0.11-beta-*", - "System.Linq": "4.0.1-beta-*", - "System.Net.Primitives": "4.0.11-beta-*", - "System.Runtime.Extensions": "4.0.11-beta-*", - "System.Runtime.InteropServices": "4.0.21-beta-*", - "System.Text.Encoding": "4.0.11-beta-*", - "System.Threading": "4.0.11-beta-*", - "System.Threading.Tasks": "4.0.11-beta-*", - "System.Threading.Thread": "4.0.0-beta-*", - "System.Threading.ThreadPool": "4.0.10-beta-*", - "System.Threading.Timer": "4.0.1-beta-*" + "System.Collections": "4.0.11-*", + "System.Diagnostics.Debug": "4.0.11-*", + "System.Diagnostics.TraceSource": "4.0.0-*", + "System.Diagnostics.Tracing": "4.0.21-*", + "System.Globalization": "4.0.11-*", + "System.IO": "4.0.11-*", + "System.Linq": "4.0.1-*", + "System.Net.Primitives": "4.0.11-*", + "System.Runtime.Extensions": "4.0.11-*", + "System.Runtime.InteropServices": "4.0.21-*", + "System.Text.Encoding": "4.0.11-*", + "System.Threading": "4.0.11-*", + "System.Threading.Tasks": "4.0.11-*", + "System.Threading.Thread": "4.0.0-*", + "System.Threading.ThreadPool": "4.0.10-*", + "System.Threading.Timer": "4.0.1-*" } }, "dotnet5.4": { "dependencies": { - "System.Collections": "4.0.11-beta-*", - "System.Diagnostics.Debug": "4.0.11-beta-*", - "System.Diagnostics.TraceSource": "4.0.0-beta-*", - "System.Diagnostics.Tracing": "4.0.21-beta-*", - "System.Globalization": "4.0.11-beta-*", - "System.IO": "4.0.11-beta-*", - "System.Linq": "4.0.1-beta-*", - "System.Net.Primitives": "4.0.11-beta-*", - "System.Runtime.Extensions": "4.0.11-beta-*", - "System.Runtime.InteropServices": "4.0.21-beta-*", - "System.Text.Encoding": "4.0.11-beta-*", - "System.Threading": "4.0.11-beta-*", - "System.Threading.Tasks": "4.0.11-beta-*", - "System.Threading.Thread": "4.0.0-beta-*", - "System.Threading.ThreadPool": "4.0.10-beta-*", - "System.Threading.Timer": "4.0.1-beta-*" + "System.Collections": "4.0.11-*", + "System.Diagnostics.Debug": "4.0.11-*", + "System.Diagnostics.TraceSource": "4.0.0-*", + "System.Diagnostics.Tracing": "4.0.21-*", + "System.Globalization": "4.0.11-*", + "System.IO": "4.0.11-*", + "System.Linq": "4.0.1-*", + "System.Net.Primitives": "4.0.11-*", + "System.Runtime.Extensions": "4.0.11-*", + "System.Runtime.InteropServices": "4.0.21-*", + "System.Text.Encoding": "4.0.11-*", + "System.Threading": "4.0.11-*", + "System.Threading.Tasks": "4.0.11-*", + "System.Threading.Thread": "4.0.0-*", + "System.Threading.ThreadPool": "4.0.10-*", + "System.Threading.Timer": "4.0.1-*" } } }, @@ -87,4 +87,4 @@ "runtimes/win10-arm/native/": "runtimes/win10-arm/native/*", "runtimes/osx/native/": "runtimes/osx/native/*" } -} \ No newline at end of file +} diff --git a/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/project.json b/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/project.json index 7ecc7fb8ab..4c78cd4acd 100644 --- a/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/project.json +++ b/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/project.json @@ -1,9 +1,9 @@ -{ +{ "version": "1.0.0-*", "dependencies": { "Microsoft.AspNet.Http.Abstractions": "1.0.0-*", "Microsoft.AspNet.Server.Kestrel": "1.0.0-*", - "System.Net.Http": "4.0.1-beta-*", + "System.Net.Http": "4.0.1-*", "xunit.runner.aspnet": "2.0.0-aspnet-*" }, "frameworks": { diff --git a/test/Microsoft.AspNet.Server.KestrelTests/project.json b/test/Microsoft.AspNet.Server.KestrelTests/project.json index 730c809d15..af2652e3a8 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/project.json +++ b/test/Microsoft.AspNet.Server.KestrelTests/project.json @@ -5,17 +5,17 @@ "Microsoft.AspNet.Server.Kestrel": "1.0.0-*", "Microsoft.AspNet.Server.Kestrel.Https": "1.0.0-*", "Microsoft.AspNet.Testing": "1.0.0-*", - "System.Net.Http": "4.0.1-beta-*" + "System.Net.Http": "4.0.1-*" }, "frameworks": { "dnx451": { }, "dnxcore50": { "dependencies": { - "System.Diagnostics.TraceSource": "4.0.0-beta-*", - "System.IO": "4.0.11-beta-*", - "System.Net.Http.WinHttpHandler": "4.0.0-beta-*", - "System.Net.Sockets": "4.1.0-beta-*", - "System.Runtime.Handles": "4.0.1-beta-*" + "System.Diagnostics.TraceSource": "4.0.0-*", + "System.IO": "4.0.11-*", + "System.Net.Http.WinHttpHandler": "4.0.0-*", + "System.Net.Sockets": "4.1.0-*", + "System.Runtime.Handles": "4.0.1-*" } } }, diff --git a/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/project.json b/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/project.json index 465bd1b866..ede3a70f54 100644 --- a/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/project.json +++ b/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/project.json @@ -21,7 +21,7 @@ }, "dnxcore50": { "dependencies": { - "System.Console": "4.0.0-beta-*" + "System.Console": "4.0.0-*" } } } diff --git a/tools/Microsoft.AspNet.Server.Kestrel.LibuvCopier/project.json b/tools/Microsoft.AspNet.Server.Kestrel.LibuvCopier/project.json index 373002bafb..a9b68f0ec4 100644 --- a/tools/Microsoft.AspNet.Server.Kestrel.LibuvCopier/project.json +++ b/tools/Microsoft.AspNet.Server.Kestrel.LibuvCopier/project.json @@ -1,4 +1,4 @@ -{ +{ "version": "1.0.0-*", "description": "Microsoft.AspNet.Server.Kestrel.LibuvCopier Console Application", "authors": [ "pawelka" ], @@ -19,12 +19,12 @@ "dnx451": { }, "dnxcore50": { "dependencies": { - "Microsoft.CSharp": "4.0.1-beta-*", - "System.Collections": "4.0.11-beta-*", - "System.Console": "4.0.0-beta-*", - "System.Linq": "4.0.1-beta-*", - "System.Threading": "4.0.11-beta-*", - "System.IO.FileSystem": "4.0.1-beta-*" + "Microsoft.CSharp": "4.0.1-*", + "System.Collections": "4.0.11-*", + "System.Console": "4.0.0-*", + "System.Linq": "4.0.1-*", + "System.Threading": "4.0.11-*", + "System.IO.FileSystem": "4.0.1-*" } } } diff --git a/tools/Microsoft.StandardsPolice/project.json b/tools/Microsoft.StandardsPolice/project.json index 01f7813a3d..7f24c4760b 100644 --- a/tools/Microsoft.StandardsPolice/project.json +++ b/tools/Microsoft.StandardsPolice/project.json @@ -1,4 +1,4 @@ -{ +{ "version": "1.0.0-*", "compilationOptions": { @@ -32,12 +32,12 @@ }, "dotnet5.4": { "dependencies": { - "System.Console": "4.0.0-beta-*" + "System.Console": "4.0.0-*" } }, "dnxcore50": { "dependencies": { - "System.Console": "4.0.0-beta-*" + "System.Console": "4.0.0-*" } } } From 59cdd60af68b0c1ab050c2b6fb6422c0d42a6b1c Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Tue, 10 Nov 2015 15:44:00 -0800 Subject: [PATCH 0416/1662] Don't pre-complete too many writes --- .../Http/SocketOutput.cs | 4 +- .../SocketOutputTests.cs | 78 +++++++++++++++++++ 2 files changed, 81 insertions(+), 1 deletion(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs index 609d59ef3e..2871341dbd 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs @@ -203,8 +203,10 @@ namespace Microsoft.AspNet.Server.Kestrel.Http (int)(_tasksPending.Peek().Task.AsyncState) <= bytesLeftToBuffer) { var tcs = _tasksPending.Dequeue(); + var bytesToWrite = (int)tcs.Task.AsyncState; - _numBytesPreCompleted += (int)(tcs.Task.AsyncState); + _numBytesPreCompleted += bytesToWrite; + bytesLeftToBuffer -= bytesToWrite; if (error == null) { diff --git a/test/Microsoft.AspNet.Server.KestrelTests/SocketOutputTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/SocketOutputTests.cs index faf3116340..d8d4f5cee7 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/SocketOutputTests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/SocketOutputTests.cs @@ -192,6 +192,84 @@ namespace Microsoft.AspNet.Server.KestrelTests } } + [Fact] + public void WritesDontGetCompletedTooQuickly() + { + // This should match _maxBytesPreCompleted in SocketOutput + var maxBytesPreCompleted = 65536; + var completeQueue = new Queue>(); + var onWriteWh = new ManualResetEventSlim(); + + // Arrange + var mockLibuv = new MockLibuv + { + OnWrite = (socket, buffers, triggerCompleted) => + { + completeQueue.Enqueue(triggerCompleted); + onWriteWh.Set(); + + return 0; + } + }; + + using (var kestrelEngine = new KestrelEngine(mockLibuv, new TestServiceContext())) + { + kestrelEngine.Start(count: 1); + + var kestrelThread = kestrelEngine.Threads[0]; + var socket = new MockSocket(kestrelThread.Loop.ThreadId, new TestKestrelTrace()); + var trace = new KestrelTrace(new TestKestrelTrace()); + var socketOutput = new SocketOutput(kestrelThread, socket, 0, trace); + + var bufferSize = maxBytesPreCompleted; + var buffer = new ArraySegment(new byte[bufferSize], 0, bufferSize); + + var completedWh = new ManualResetEventSlim(); + Action onCompleted = (Task t) => + { + Assert.Null(t.Exception); + completedWh.Set(); + }; + + var completedWh2 = new ManualResetEventSlim(); + Action onCompleted2 = (Task t) => + { + Assert.Null(t.Exception); + completedWh2.Set(); + }; + + // Act (Pre-complete the maximum number of bytes in preparation for the rest of the test) + socketOutput.WriteAsync(buffer).ContinueWith(onCompleted); + // Assert + // The first write should pre-complete since it is <= _maxBytesPreCompleted. + Assert.True(completedWh.Wait(1000)); + Assert.True(onWriteWh.Wait(1000)); + // Arrange + completedWh.Reset(); + onWriteWh.Reset(); + + // Act + socketOutput.WriteAsync(buffer).ContinueWith(onCompleted); + socketOutput.WriteAsync(buffer).ContinueWith(onCompleted2); + + Assert.True(onWriteWh.Wait(1000)); + completeQueue.Dequeue()(0); + + // Assert + // Too many bytes are already pre-completed for the third but not the second write to pre-complete. + // https://github.com/aspnet/KestrelHttpServer/issues/356 + Assert.True(completedWh.Wait(1000)); + Assert.False(completedWh2.Wait(1000)); + + // Act + completeQueue.Dequeue()(0); + + // Assert + // Finishing the first write should allow the second write to pre-complete. + Assert.True(completedWh2.Wait(1000)); + } + } + private class MockSocket : UvStreamHandle { public MockSocket(int threadId, IKestrelTrace logger) : base(logger) From fc346f7768f7b9a4a7ae921434cfee45972324b0 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Tue, 10 Nov 2015 15:46:28 -0800 Subject: [PATCH 0417/1662] Avoid some closure allocations in SocketOutput --- src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs index 2871341dbd..d2534206e1 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs @@ -293,7 +293,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http var _this = (WriteContext)state; _this.WriteStatus = status; _this.WriteError = error; - DoShutdownIfNeeded(); + _this.DoShutdownIfNeeded(); }, this); } @@ -316,9 +316,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Http var _this = (WriteContext)state; _this.ShutdownSendStatus = status; - Self._log.ConnectionWroteFin(Self._connectionId, status); + _this.Self._log.ConnectionWroteFin(Self._connectionId, status); - DoDisconnectIfNeeded(); + _this.DoDisconnectIfNeeded(); }, this); } From 52fe46968832e6c0520c6f90b79fb3d8d1d3db3b Mon Sep 17 00:00:00 2001 From: Murat Girgin Date: Thu, 12 Nov 2015 22:59:34 -0800 Subject: [PATCH 0418/1662] Update project.json --- src/Microsoft.AspNet.Server.Kestrel/project.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/project.json b/src/Microsoft.AspNet.Server.Kestrel/project.json index edae688097..1582dd0e1a 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/project.json +++ b/src/Microsoft.AspNet.Server.Kestrel/project.json @@ -1,6 +1,6 @@ { "version": "1.0.0-*", - "description": "ASP.NET 5 cross platform development web server.", + "description": "ASP.NET 5 cross platform web server.", "repository": { "type": "git", "url": "git://github.com/aspnet/kestrelhttpserver" From dd1ffa5f84674441b3fbe7b3c931504598f5bc1a Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Wed, 11 Nov 2015 05:41:28 -0800 Subject: [PATCH 0419/1662] Skip some tests on Mono to prevent CI hangs. --- .travis.yml | 10 ++- .../AddressRegistrationTests.cs | 35 +++++++-- .../IPv6SupportedConditionAttribute.cs | 48 ++++++++++++ .../RequestTests.cs | 15 ++-- .../ResponseTests.cs | 4 +- .../project.json | 2 + .../ChunkedResponseTests.cs | 16 ++-- .../ConnectionFilterTests.cs | 9 ++- .../EngineTests.cs | 75 +++++++++++++------ 9 files changed, 169 insertions(+), 45 deletions(-) create mode 100644 test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/IPv6SupportedConditionAttribute.cs diff --git a/.travis.yml b/.travis.yml index 1218a0fc0f..eef144e738 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,10 @@ language: csharp -sudo: false +sudo: required +dist: trusty +addons: + apt: + packages: + - libunwind8 install: - curl -sSL https://github.com/libuv/libuv/archive/v1.4.2.tar.gz | tar zxfv - -C /tmp && cd /tmp/libuv-1.4.2/ - sh autogen.sh @@ -9,4 +14,5 @@ install: - export LD_LIBRARY_PATH="$HOME/libuvinstall/lib" - cd $OLDPWD script: - - ./build.sh --quiet verify \ No newline at end of file + - export KOREBUILD_TEST_DNXCORE=1 + - ./build.sh --quiet verify diff --git a/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs b/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs index 00f6db432d..9921a3d7fc 100644 --- a/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs +++ b/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs @@ -8,6 +8,7 @@ using Microsoft.AspNet.Builder; using Microsoft.AspNet.Hosting; using Microsoft.AspNet.Http; using Microsoft.AspNet.Http.Extensions; +using Microsoft.AspNet.Testing.xunit; using Microsoft.Extensions.Configuration; using Xunit; @@ -15,7 +16,21 @@ namespace Microsoft.AspNet.Server.Kestrel.FunctionalTests { public class AddressRegistrationTests { - [Theory, MemberData(nameof(AddressRegistrationData))] + [ConditionalTheory, MemberData(nameof(AddressRegistrationDataIPv4))] + [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Test hangs after execution on Mono.")] + public async Task RegisterAddresses_IPv4_Success(string addressInput, string[] testUrls) + { + await RegisterAddresses_Success(addressInput, testUrls); + } + + [ConditionalTheory, MemberData(nameof(AddressRegistrationDataIPv6))] + [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Test hangs after execution on Mono.")] + [IPv6SupportedCondition] + public async Task RegisterAddresses_IPv6_Success(string addressInput, string[] testUrls) + { + await RegisterAddresses_Success(addressInput, testUrls); + } + public async Task RegisterAddresses_Success(string addressInput, string[] testUrls) { var config = new ConfigurationBuilder() @@ -27,7 +42,7 @@ namespace Microsoft.AspNet.Server.Kestrel.FunctionalTests var hostBuilder = new WebHostBuilder(config); hostBuilder.UseServerFactory("Microsoft.AspNet.Server.Kestrel"); - hostBuilder.UseStartup(ConfigureEchoAddress); + hostBuilder.UseStartup(ConfigureEchoAddress); using (var app = hostBuilder.Build().Start()) { @@ -42,22 +57,32 @@ namespace Microsoft.AspNet.Server.Kestrel.FunctionalTests } } - public static TheoryData AddressRegistrationData + public static TheoryData AddressRegistrationDataIPv4 { get { var dataset = new TheoryData(); dataset.Add("8787", new[] { "http://localhost:8787/" }); dataset.Add("8787;8788", new[] { "http://localhost:8787/", "http://localhost:8788/" }); + dataset.Add("http://127.0.0.1:8787/", new[] { "http://127.0.0.1:8787/", }); + dataset.Add("http://localhost:8787/base/path", new[] { "http://localhost:8787/base/path" }); + + return dataset; + } + } + + public static TheoryData AddressRegistrationDataIPv6 + { + get + { + var dataset = new TheoryData(); dataset.Add("http://*:8787/", new[] { "http://localhost:8787/", "http://127.0.0.1:8787/", "http://[::1]:8787/" }); dataset.Add("http://localhost:8787/", new[] { "http://localhost:8787/", "http://127.0.0.1:8787/", /* // https://github.com/aspnet/KestrelHttpServer/issues/231 "http://[::1]:8787/" */ }); - dataset.Add("http://127.0.0.1:8787/", new[] { "http://127.0.0.1:8787/", }); dataset.Add("http://[::1]:8787/", new[] { "http://[::1]:8787/", }); dataset.Add("http://127.0.0.1:8787/;http://[::1]:8787/", new[] { "http://127.0.0.1:8787/", "http://[::1]:8787/" }); - dataset.Add("http://localhost:8787/base/path", new[] { "http://localhost:8787/base/path" }); return dataset; } diff --git a/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/IPv6SupportedConditionAttribute.cs b/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/IPv6SupportedConditionAttribute.cs new file mode 100644 index 0000000000..8415f0f040 --- /dev/null +++ b/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/IPv6SupportedConditionAttribute.cs @@ -0,0 +1,48 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Net; +using System.Net.Sockets; +using Microsoft.AspNet.Testing.xunit; + +namespace Microsoft.AspNet.Server.Kestrel.FunctionalTests +{ + [AttributeUsage(AttributeTargets.Method, AllowMultiple = false)] + public class IPv6SupportedConditionAttribute : Attribute, ITestCondition + { + private static Lazy _ipv6Supported = new Lazy(CanBindToIPv6Address); + + public bool IsMet + { + get + { + return _ipv6Supported.Value; + } + } + + public string SkipReason + { + get + { + return "IPv6 not supported on the host."; + } + } + + private static bool CanBindToIPv6Address() + { + try + { + using (var socket = new Socket(AddressFamily.InterNetworkV6, SocketType.Stream, ProtocolType.Tcp)) + { + socket.Bind(new IPEndPoint(IPAddress.IPv6Loopback, 8787)); + return true; + } + } + catch (SocketException) + { + return false; + } + } + } +} diff --git a/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/RequestTests.cs b/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/RequestTests.cs index 1c75f43a7d..c125da04b5 100644 --- a/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/RequestTests.cs +++ b/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/RequestTests.cs @@ -8,6 +8,7 @@ using System.Threading.Tasks; using Microsoft.AspNet.Builder; using Microsoft.AspNet.Hosting; using Microsoft.AspNet.Http; +using Microsoft.AspNet.Testing.xunit; using Microsoft.Extensions.Configuration; using Newtonsoft.Json; using Newtonsoft.Json.Linq; @@ -17,7 +18,8 @@ namespace Microsoft.AspNet.Server.Kestrel.FunctionalTests { public class RequestTests { - [Fact] + [ConditionalFact] + [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Test hangs after execution on Mono.")] public async Task LargeUpload() { var config = new ConfigurationBuilder() @@ -69,15 +71,18 @@ namespace Microsoft.AspNet.Server.Kestrel.FunctionalTests } } - [Theory] + [ConditionalTheory] [InlineData("127.0.0.1", "127.0.0.1", "8792")] [InlineData("localhost", "127.0.0.1", "8792")] + [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Test hangs after execution on Mono.")] public Task RemoteIPv4Address(string requestAddress, string expectAddress, string port) { return TestRemoteIPAddress("localhost", requestAddress, expectAddress, port); } - [Fact] + [ConditionalFact] + [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Test hangs after execution on Mono.")] + [IPv6SupportedCondition] public Task RemoteIPv6Address() { return TestRemoteIPAddress("[::1]", "[::1]", "::1", "8792"); @@ -92,7 +97,7 @@ namespace Microsoft.AspNet.Server.Kestrel.FunctionalTests var builder = new WebHostBuilder(config) .UseServerFactory("Microsoft.AspNet.Server.Kestrel") - .UseStartup(app => + .UseStartup(app => { app.Run(async context => { @@ -124,4 +129,4 @@ namespace Microsoft.AspNet.Server.Kestrel.FunctionalTests } } } -} \ No newline at end of file +} diff --git a/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/ResponseTests.cs b/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/ResponseTests.cs index 245729d94e..c2479c388c 100644 --- a/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/ResponseTests.cs +++ b/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/ResponseTests.cs @@ -6,6 +6,7 @@ using System.Net.Http; using System.Threading.Tasks; using Microsoft.AspNet.Builder; using Microsoft.AspNet.Hosting; +using Microsoft.AspNet.Testing.xunit; using Microsoft.Extensions.Configuration; using Xunit; @@ -13,7 +14,8 @@ namespace Microsoft.AspNet.Server.Kestrel.FunctionalTests { public class ResponseTests { - [Fact] + [ConditionalFact] + [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Test hangs after execution on mono.")] public async Task LargeDownload() { var config = new ConfigurationBuilder() diff --git a/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/project.json b/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/project.json index 4c78cd4acd..b97b9efc44 100644 --- a/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/project.json +++ b/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/project.json @@ -3,7 +3,9 @@ "dependencies": { "Microsoft.AspNet.Http.Abstractions": "1.0.0-*", "Microsoft.AspNet.Server.Kestrel": "1.0.0-*", + "Microsoft.AspNet.Testing": "1.0.0-*", "System.Net.Http": "4.0.1-*", + "System.Net.NameResolution": "4.0.0-*", "xunit.runner.aspnet": "2.0.0-aspnet-*" }, "frameworks": { diff --git a/test/Microsoft.AspNet.Server.KestrelTests/ChunkedResponseTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/ChunkedResponseTests.cs index ca01df5f41..ad0a9120c9 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/ChunkedResponseTests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/ChunkedResponseTests.cs @@ -4,13 +4,15 @@ using System; using System.Text; using System.Threading.Tasks; +using Microsoft.AspNet.Testing.xunit; using Xunit; namespace Microsoft.AspNet.Server.KestrelTests { public class ChunkedResponseTests { - [Fact] + [ConditionalFact] + [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Test hangs after execution on Mono.")] public async Task ResponsesAreChunkedAutomatically() { using (var server = new TestServer(async httpContext => @@ -42,7 +44,8 @@ namespace Microsoft.AspNet.Server.KestrelTests } } - [Fact] + [ConditionalFact] + [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Test hangs after execution on Mono.")] public async Task ZeroLengthWritesAreIgnored() { using (var server = new TestServer(async httpContext => @@ -75,7 +78,8 @@ namespace Microsoft.AspNet.Server.KestrelTests } } - [Fact] + [ConditionalFact] + [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Test hangs after execution on Mono.")] public async Task EmptyResponseBodyHandledCorrectlyWithZeroLengthWrite() { using (var server = new TestServer(async httpContext => @@ -102,7 +106,8 @@ namespace Microsoft.AspNet.Server.KestrelTests } } - [Fact] + [ConditionalFact] + [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Test hangs after execution on Mono.")] public async Task ConnectionClosedIfExeptionThrownAfterWrite() { using (var server = new TestServer(async httpContext => @@ -132,7 +137,8 @@ namespace Microsoft.AspNet.Server.KestrelTests } } - [Fact] + [ConditionalFact] + [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Test hangs after execution on Mono.")] public async Task ConnectionClosedIfExeptionThrownAfterZeroLengthWrite() { using (var server = new TestServer(async httpContext => diff --git a/test/Microsoft.AspNet.Server.KestrelTests/ConnectionFilterTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/ConnectionFilterTests.cs index d4dfc5fe9b..5842e1d7c0 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/ConnectionFilterTests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/ConnectionFilterTests.cs @@ -3,9 +3,10 @@ using System.IO; using System.Threading.Tasks; -using Microsoft.AspNet.Server.Kestrel.Filter; using Microsoft.AspNet.Http; using Microsoft.AspNet.Http.Features; +using Microsoft.AspNet.Server.Kestrel.Filter; +using Microsoft.AspNet.Testing.xunit; using Xunit; namespace Microsoft.AspNet.Server.KestrelTests @@ -29,7 +30,8 @@ namespace Microsoft.AspNet.Server.KestrelTests } } - [Fact] + [ConditionalFact] + [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Test hangs after execution on Mono.")] public async Task CanReadAndWriteWithRewritingConnectionFilter() { var filter = new RewritingConnectionFilter(); @@ -55,7 +57,8 @@ namespace Microsoft.AspNet.Server.KestrelTests Assert.Equal(sendString.Length, filter.BytesRead); } - [Fact] + [ConditionalFact] + [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Test hangs after execution on Mono.")] public async Task CanReadAndWriteWithAsyncConnectionFilter() { var serviceContext = new TestServiceContext() diff --git a/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs index c892973375..d5893e214b 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs @@ -10,6 +10,7 @@ using System.Threading.Tasks; using Microsoft.AspNet.Http; using Microsoft.AspNet.Server.Kestrel; using Microsoft.AspNet.Server.Kestrel.Filter; +using Microsoft.AspNet.Testing.xunit; using Microsoft.Extensions.Logging; using Xunit; @@ -75,8 +76,9 @@ namespace Microsoft.AspNet.Server.KestrelTests return Task.FromResult(null); } - [Theory] + [ConditionalTheory] [MemberData(nameof(ConnectionFilterData))] + [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Test hangs after execution on Mono.")] public void EngineCanStartAndStop(ServiceContext testContext) { var engine = new KestrelEngine(testContext); @@ -84,8 +86,9 @@ namespace Microsoft.AspNet.Server.KestrelTests engine.Dispose(); } - [Theory] + [ConditionalTheory] [MemberData(nameof(ConnectionFilterData))] + [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Test hangs after execution on Mono.")] public void ListenerCanCreateAndDispose(ServiceContext testContext) { var engine = new KestrelEngine(testContext); @@ -96,8 +99,9 @@ namespace Microsoft.AspNet.Server.KestrelTests engine.Dispose(); } - [Theory] + [ConditionalTheory] [MemberData(nameof(ConnectionFilterData))] + [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Test hangs after execution on Mono.")] public void ConnectionCanReadAndWrite(ServiceContext testContext) { var engine = new KestrelEngine(testContext); @@ -122,8 +126,9 @@ namespace Microsoft.AspNet.Server.KestrelTests } - [Theory] + [ConditionalTheory] [MemberData(nameof(ConnectionFilterData))] + [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Test hangs after execution on Mono.")] public async Task Http10(ServiceContext testContext) { using (var server = new TestServer(App, testContext)) @@ -143,8 +148,9 @@ namespace Microsoft.AspNet.Server.KestrelTests } - [Theory] + [ConditionalTheory] [MemberData(nameof(ConnectionFilterData))] + [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Test hangs after execution on Mono.")] public async Task Http11(ServiceContext testContext) { using (var server = new TestServer(AppChunked, testContext)) @@ -171,8 +177,9 @@ namespace Microsoft.AspNet.Server.KestrelTests } } - [Theory] + [ConditionalTheory] [MemberData(nameof(ConnectionFilterData))] + [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Test hangs after execution on Mono.")] public async Task Http10ContentLength(ServiceContext testContext) { using (var server = new TestServer(App, testContext)) @@ -192,8 +199,9 @@ namespace Microsoft.AspNet.Server.KestrelTests } } - [Theory] + [ConditionalTheory] [MemberData(nameof(ConnectionFilterData))] + [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Test hangs after execution on Mono.")] public async Task Http10TransferEncoding(ServiceContext testContext) { using (var server = new TestServer(App, testContext)) @@ -213,8 +221,9 @@ namespace Microsoft.AspNet.Server.KestrelTests } } - [Theory] + [ConditionalTheory] [MemberData(nameof(ConnectionFilterData))] + [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Test hangs after execution on Mono.")] public async Task Http10KeepAlive(ServiceContext testContext) { using (var server = new TestServer(AppChunked, testContext)) @@ -242,8 +251,9 @@ namespace Microsoft.AspNet.Server.KestrelTests } } - [Theory] + [ConditionalTheory] [MemberData(nameof(ConnectionFilterData))] + [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Test hangs after execution on Mono.")] public async Task Http10KeepAliveNotUsedIfResponseContentLengthNotSet(ServiceContext testContext) { using (var server = new TestServer(App, testContext)) @@ -272,8 +282,9 @@ namespace Microsoft.AspNet.Server.KestrelTests } } - [Theory] + [ConditionalTheory] [MemberData(nameof(ConnectionFilterData))] + [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Test hangs after execution on Mono.")] public async Task Http10KeepAliveContentLength(ServiceContext testContext) { using (var server = new TestServer(AppChunked, testContext)) @@ -303,8 +314,9 @@ namespace Microsoft.AspNet.Server.KestrelTests } } - [Theory] + [ConditionalTheory] [MemberData(nameof(ConnectionFilterData))] + [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Test hangs after execution on Mono.")] public async Task Http10KeepAliveTransferEncoding(ServiceContext testContext) { using (var server = new TestServer(AppChunked, testContext)) @@ -335,8 +347,9 @@ namespace Microsoft.AspNet.Server.KestrelTests } } - [Theory] + [ConditionalTheory] [MemberData(nameof(ConnectionFilterData))] + [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Test hangs after execution on Mono.")] public async Task Expect100ContinueForBody(ServiceContext testContext) { using (var server = new TestServer(AppChunked, testContext)) @@ -361,8 +374,9 @@ namespace Microsoft.AspNet.Server.KestrelTests } } - [Theory] + [ConditionalTheory] [MemberData(nameof(ConnectionFilterData))] + [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Test hangs after execution on Mono.")] public async Task DisconnectingClient(ServiceContext testContext) { using (var server = new TestServer(App, testContext)) @@ -385,8 +399,9 @@ namespace Microsoft.AspNet.Server.KestrelTests } } - [Theory] + [ConditionalTheory] [MemberData(nameof(ConnectionFilterData))] + [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Test hangs after execution on Mono.")] public async Task ZeroContentLengthSetAutomaticallyAfterNoWrites(ServiceContext testContext) { using (var server = new TestServer(EmptyApp, testContext)) @@ -413,8 +428,9 @@ namespace Microsoft.AspNet.Server.KestrelTests } } - [Theory] + [ConditionalTheory] [MemberData(nameof(ConnectionFilterData))] + [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Test hangs after execution on Mono.")] public async Task ZeroContentLengthNotSetAutomaticallyForNonKeepAliveRequests(ServiceContext testContext) { using (var server = new TestServer(EmptyApp, testContext)) @@ -447,8 +463,9 @@ namespace Microsoft.AspNet.Server.KestrelTests } } - [Theory] + [ConditionalTheory] [MemberData(nameof(ConnectionFilterData))] + [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Test hangs after execution on Mono.")] public async Task ZeroContentLengthNotSetAutomaticallyForHeadRequests(ServiceContext testContext) { using (var server = new TestServer(EmptyApp, testContext)) @@ -467,8 +484,9 @@ namespace Microsoft.AspNet.Server.KestrelTests } } - [Theory] + [ConditionalTheory] [MemberData(nameof(ConnectionFilterData))] + [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Test hangs after execution on Mono.")] public async Task ZeroContentLengthNotSetAutomaticallyForCertainStatusCodes(ServiceContext testContext) { using (var server = new TestServer(async httpContext => @@ -520,8 +538,9 @@ namespace Microsoft.AspNet.Server.KestrelTests } } - [Theory] + [ConditionalTheory] [MemberData(nameof(ConnectionFilterData))] + [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Test hangs after execution on Mono.")] public async Task ThrowingResultsIn500Response(ServiceContext testContext) { bool onStartingCalled = false; @@ -577,8 +596,9 @@ namespace Microsoft.AspNet.Server.KestrelTests } } - [Theory] + [ConditionalTheory] [MemberData(nameof(ConnectionFilterData))] + [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Test hangs after execution on Mono.")] public async Task ThrowingAfterWritingKillsConnection(ServiceContext testContext) { bool onStartingCalled = false; @@ -619,8 +639,9 @@ namespace Microsoft.AspNet.Server.KestrelTests } } - [Theory] + [ConditionalTheory] [MemberData(nameof(ConnectionFilterData))] + [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Test hangs after execution on Mono.")] public async Task ThrowingAfterPartialWriteKillsConnection(ServiceContext testContext) { bool onStartingCalled = false; @@ -661,8 +682,9 @@ namespace Microsoft.AspNet.Server.KestrelTests } } - [Theory] + [ConditionalTheory] [MemberData(nameof(ConnectionFilterData))] + [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Test hangs after execution on Mono.")] public async Task ConnectionClosesWhenFinReceived(ServiceContext testContext) { using (var server = new TestServer(AppChunked, testContext)) @@ -688,8 +710,9 @@ namespace Microsoft.AspNet.Server.KestrelTests } } - [Theory] + [ConditionalTheory] [MemberData(nameof(ConnectionFilterData))] + [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Test hangs after execution on Mono.")] public async Task ConnectionClosesWhenFinReceivedBeforeRequestCompletes(ServiceContext testContext) { using (var server = new TestServer(AppChunked, testContext)) @@ -730,8 +753,9 @@ namespace Microsoft.AspNet.Server.KestrelTests } } - [Theory] + [ConditionalTheory] [MemberData(nameof(ConnectionFilterData))] + [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Test hangs after execution on Mono.")] public async Task ThrowingInOnStartingResultsInFailedWritesAnd500Response(ServiceContext testContext) { var onStartingCallCount1 = 0; @@ -803,7 +827,9 @@ namespace Microsoft.AspNet.Server.KestrelTests } } + [ConditionalTheory] [MemberData(nameof(ConnectionFilterData))] + [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Test hangs after execution on Mono.")] public async Task ThrowingInOnCompletedIsLoggedAndClosesConnection(ServiceContext testContext) { var onCompletedCalled1 = false; @@ -852,8 +878,9 @@ namespace Microsoft.AspNet.Server.KestrelTests } } - [Theory] + [ConditionalTheory] [MemberData(nameof(ConnectionFilterData))] + [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Test hangs after execution on Mono.")] public async Task RequestBodyIsConsumedAutomaticallyIfAppDoesntConsumeItFully(ServiceContext testContext) { using (var server = new TestServer(async httpContext => From 2ac5e4c790ced5f12813d2d6725126216afbb072 Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Fri, 13 Nov 2015 11:31:25 -0800 Subject: [PATCH 0420/1662] Remove unneeded dependency System.Net.NameResolution. --- .../Microsoft.AspNet.Server.Kestrel.FunctionalTests/project.json | 1 - 1 file changed, 1 deletion(-) diff --git a/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/project.json b/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/project.json index b97b9efc44..1e06cdc21b 100644 --- a/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/project.json +++ b/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/project.json @@ -5,7 +5,6 @@ "Microsoft.AspNet.Server.Kestrel": "1.0.0-*", "Microsoft.AspNet.Testing": "1.0.0-*", "System.Net.Http": "4.0.1-*", - "System.Net.NameResolution": "4.0.0-*", "xunit.runner.aspnet": "2.0.0-aspnet-*" }, "frameworks": { From 59a95f43a3846e7077783cec7f914755c7ec5bf2 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Fri, 13 Nov 2015 19:33:24 +0000 Subject: [PATCH 0421/1662] Set NoDelay as default Resolves #374 --- src/Microsoft.AspNet.Server.Kestrel/KestrelServerInformation.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/KestrelServerInformation.cs b/src/Microsoft.AspNet.Server.Kestrel/KestrelServerInformation.cs index 840533012c..71e6ababcf 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/KestrelServerInformation.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/KestrelServerInformation.cs @@ -15,7 +15,7 @@ namespace Microsoft.AspNet.Server.Kestrel public int ThreadCount { get; set; } - public bool NoDelay { get; set; } + public bool NoDelay { get; set; } = true; public IConnectionFilter ConnectionFilter { get; set; } From a95318c616e58786843f0a7e938e50317a751fee Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Fri, 13 Nov 2015 08:23:13 +0000 Subject: [PATCH 0422/1662] Network thread count defaults --- .../KestrelServer.cs | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/KestrelServer.cs b/src/Microsoft.AspNet.Server.Kestrel/KestrelServer.cs index ff0ca62422..346808ebc4 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/KestrelServer.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/KestrelServer.cs @@ -75,14 +75,37 @@ namespace Microsoft.AspNet.Server.Kestrel _disposables.Push(engine); _disposables.Push(dateHeaderValueManager); + // Actual core count would be a better number + // rather than logical cores which includes hyper-threaded cores. + // Divide by 2 for hyper-threading, and good defaults (still need threads to do webserving). + // Can be user overriden using IKestrelServerInformation.ThreadCount + var threadCount = Environment.ProcessorCount >> 1; + + if (threadCount < 1) + { + // Ensure shifted value is at least one + threadCount = 1; + } + else if (threadCount > 16) + { + // Receive Side Scaling RSS Processor count currently maxes out at 16 + // would be better to check the NIC's current hardware queues; but xplat... + threadCount = 16; + } + if (information.ThreadCount < 0) { throw new ArgumentOutOfRangeException(nameof(information.ThreadCount), information.ThreadCount, "ThreadCount cannot be negative"); } + else if (information.ThreadCount > 0) + { + // ThreadCount has been user set, use that value + threadCount = information.ThreadCount; + } - engine.Start(information.ThreadCount == 0 ? 1 : information.ThreadCount); + engine.Start(threadCount); var atLeastOneListener = false; foreach (var address in information.Addresses) From d493667851d52b9a9e57b0709d68dba18df23141 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Fri, 13 Nov 2015 08:44:27 +0000 Subject: [PATCH 0423/1662] Enable multi loop+thread tests Resolves #232 --- .../ThreadCountTests.cs | 1 - test/Microsoft.AspNet.Server.KestrelTests/MultipleLoopTests.cs | 3 --- 2 files changed, 4 deletions(-) diff --git a/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/ThreadCountTests.cs b/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/ThreadCountTests.cs index ea654651e3..4bd434df68 100644 --- a/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/ThreadCountTests.cs +++ b/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/ThreadCountTests.cs @@ -15,7 +15,6 @@ namespace Microsoft.AspNet.Server.Kestrel.FunctionalTests { public class ThreadCountTests { - [Theory(Skip = "https://github.com/aspnet/KestrelHttpServer/issues/232"), MemberData(nameof(OneToTen))] public async Task ZeroToTenThreads(int threadCount) { var config = new ConfigurationBuilder() diff --git a/test/Microsoft.AspNet.Server.KestrelTests/MultipleLoopTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/MultipleLoopTests.cs index 8293ad09b0..f57c899f6a 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/MultipleLoopTests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/MultipleLoopTests.cs @@ -21,7 +21,6 @@ namespace Microsoft.AspNet.Server.KestrelTests _logger = engine.Log; } - [Fact(Skip = "Waiting for adding support for multi loop in libuv")] public void InitAndCloseServerPipe() { var loop = new UvLoopHandle(_logger); @@ -39,7 +38,6 @@ namespace Microsoft.AspNet.Server.KestrelTests } - [Fact(Skip = "Waiting for adding support for multi loop in libuv")] public void ServerPipeListenForConnections() { var loop = new UvLoopHandle(_logger); @@ -112,7 +110,6 @@ namespace Microsoft.AspNet.Server.KestrelTests } - [Fact(Skip = "Waiting for adding support for multi loop in libuv")] public void ServerPipeDispatchConnections() { var pipeName = @"\\.\pipe\ServerPipeDispatchConnections" + Guid.NewGuid().ToString("n"); From d82c5718310933259fefb5dd97c939b7331d0932 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Wed, 11 Nov 2015 11:43:37 +0000 Subject: [PATCH 0424/1662] Trim exposed KestrelThread api --- .../Http/ListenerSecondary.cs | 3 +- .../Infrastructure/KestrelThread.cs | 56 ++++++++----------- 2 files changed, 23 insertions(+), 36 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerSecondary.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerSecondary.cs index 5891df44ca..0bc8fae781 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerSecondary.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerSecondary.cs @@ -165,9 +165,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http // the exception that stopped the event loop will never be surfaced. if (Thread.FatalError == null) { - Thread.Send(state => + Thread.Send(listener => { - var listener = (ListenerSecondary)state; listener.DispatchPipe.Dispose(); listener.FreeBuffer(); }, this); diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs index a8608de70f..4084e175d8 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs @@ -18,7 +18,7 @@ namespace Microsoft.AspNet.Server.Kestrel /// public class KestrelThread { - private static Action _objectCallbackAdapter = (callback, state) => ((Action)callback).Invoke(state); + private static Action _threadCallbackAdapter = (callback, state) => ((Action)callback).Invoke((KestrelThread)state); private KestrelEngine _engine; private readonly IApplicationLifetime _appLifetime; private Thread _thread; @@ -64,15 +64,15 @@ namespace Microsoft.AspNet.Server.Kestrel return; } - Post(OnStop, null); + Post((t) => OnStop(t)); if (!_thread.Join((int)timeout.TotalMilliseconds)) { try { - Post(OnStopRude, null); + Post((t) => OnStopRude(t)); if (!_thread.Join((int)timeout.TotalMilliseconds)) { - Post(OnStopImmediate, null); + Post((t) => OnStopImmediate(t)); if (!_thread.Join((int)timeout.TotalMilliseconds)) { #if NET451 @@ -100,19 +100,19 @@ namespace Microsoft.AspNet.Server.Kestrel } } - private void OnStop(object obj) + private static void OnStop(KestrelThread thread) { - _post.Unreference(); + thread._post.Unreference(); } - private void OnStopRude(object obj) + private static void OnStopRude(KestrelThread thread) { - _engine.Libuv.walk( - _loop, + thread._engine.Libuv.walk( + thread._loop, (ptr, arg) => { var handle = UvMemory.FromIntPtr(ptr); - if (handle != _post) + if (handle != thread._post) { handle.Dispose(); } @@ -120,17 +120,17 @@ namespace Microsoft.AspNet.Server.Kestrel IntPtr.Zero); } - private void OnStopImmediate(object obj) + private static void OnStopImmediate(KestrelThread thread) { - _stopImmediate = true; - _loop.Stop(); + thread._stopImmediate = true; + thread._loop.Stop(); } - public void Post(Action callback, object state) + private void Post(Action callback) { lock (_workSync) { - _workAdding.Enqueue(new Work { CallbackAdapter = _objectCallbackAdapter, Callback = callback, State = state }); + _workAdding.Enqueue(new Work { CallbackAdapter = _threadCallbackAdapter, Callback = callback, State = this }); } _post.Send(); } @@ -149,23 +149,6 @@ namespace Microsoft.AspNet.Server.Kestrel _post.Send(); } - public Task PostAsync(Action callback, object state) - { - var tcs = new TaskCompletionSource(); - lock (_workSync) - { - _workAdding.Enqueue(new Work - { - CallbackAdapter = _objectCallbackAdapter, - Callback = callback, - State = state, - Completion = tcs - }); - } - _post.Send(); - return tcs.Task; - } - public Task PostAsync(Action callback, T state) { var tcs = new TaskCompletionSource(); @@ -183,7 +166,7 @@ namespace Microsoft.AspNet.Server.Kestrel return tcs.Task; } - public void Send(Action callback, object state) + public void Send(Action callback, T state) { if (_loop.ThreadId == Thread.CurrentThread.ManagedThreadId) { @@ -295,7 +278,12 @@ namespace Microsoft.AspNet.Server.Kestrel { if (work.Completion != null) { - ThreadPool.QueueUserWorkItem(_ => work.Completion.SetException(ex), null); + ThreadPool.QueueUserWorkItem( + tcs => + { + ((TaskCompletionSource)tcs).SetException(ex); + }, + work.Completion); } else { From 558b0ae643eca5f616ad288c0022d46419a5b970 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Fri, 13 Nov 2015 13:04:21 +0000 Subject: [PATCH 0425/1662] statics to instance --- .../Infrastructure/KestrelThread.cs | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs index 4084e175d8..93c30a55dd 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs @@ -64,15 +64,15 @@ namespace Microsoft.AspNet.Server.Kestrel return; } - Post((t) => OnStop(t)); + Post(t => t.OnStop()); if (!_thread.Join((int)timeout.TotalMilliseconds)) { try { - Post((t) => OnStopRude(t)); + Post(t => t.OnStopRude()); if (!_thread.Join((int)timeout.TotalMilliseconds)) { - Post((t) => OnStopImmediate(t)); + Post(t => t.OnStopImmediate()); if (!_thread.Join((int)timeout.TotalMilliseconds)) { #if NET451 @@ -100,19 +100,19 @@ namespace Microsoft.AspNet.Server.Kestrel } } - private static void OnStop(KestrelThread thread) + private void OnStop() { - thread._post.Unreference(); + _post.Unreference(); } - private static void OnStopRude(KestrelThread thread) + private void OnStopRude() { - thread._engine.Libuv.walk( - thread._loop, + _engine.Libuv.walk( + _loop, (ptr, arg) => { var handle = UvMemory.FromIntPtr(ptr); - if (handle != thread._post) + if (handle != _post) { handle.Dispose(); } @@ -120,10 +120,10 @@ namespace Microsoft.AspNet.Server.Kestrel IntPtr.Zero); } - private static void OnStopImmediate(KestrelThread thread) + private void OnStopImmediate() { - thread._stopImmediate = true; - thread._loop.Stop(); + _stopImmediate = true; + _loop.Stop(); } private void Post(Action callback) From 96c1668c54c83c8c91dd54e182870f13c511f77a Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Fri, 13 Nov 2015 07:31:12 +0000 Subject: [PATCH 0426/1662] Result -> GetAwaiter().GetResult() for legacy --- src/Microsoft.AspNet.Server.Kestrel/Http/FrameRequestStream.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameRequestStream.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameRequestStream.cs index 02de4636a8..be3ac5d225 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameRequestStream.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameRequestStream.cs @@ -66,7 +66,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http public override int EndRead(IAsyncResult asyncResult) { - return ((Task)asyncResult).Result; + return ((Task)asyncResult).GetAwaiter().GetResult(); } private Task ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken, object state) From a3a49d21b83c0855a1a339f4fd3ed52a0425c524 Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Fri, 13 Nov 2015 14:29:03 -0800 Subject: [PATCH 0427/1662] Reset Frame.Scheme on each request (#366). --- .../Http/Frame.FeatureCollection.cs | 5 ++-- .../Http/Frame.cs | 2 ++ .../FrameFacts.cs | 26 +++++++++++++++++++ 3 files changed, 30 insertions(+), 3 deletions(-) create mode 100644 test/Microsoft.AspNet.Server.KestrelTests/FrameFacts.cs diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.FeatureCollection.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.FeatureCollection.cs index 2159d70056..8cac73a946 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.FeatureCollection.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.FeatureCollection.cs @@ -24,7 +24,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Http // then the list of `implementedFeatures` in the generated code project MUST also be updated. // See also: tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/FrameFeatureCollection.cs - private string _scheme; private string _pathBase; private int _featureRevision; @@ -90,12 +89,12 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { get { - return _scheme ?? "http"; + return Scheme ?? "http"; } set { - _scheme = value; + Scheme = value; } } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs index c08d0eb684..c13826964b 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs @@ -67,6 +67,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http Reset(); } + public string Scheme { get; set; } public string Method { get; set; } public string RequestUri { get; set; } public string Path { get; set; } @@ -102,6 +103,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http ResetResponseHeaders(); ResetFeatureCollection(); + Scheme = null; Method = null; RequestUri = null; Path = null; diff --git a/test/Microsoft.AspNet.Server.KestrelTests/FrameFacts.cs b/test/Microsoft.AspNet.Server.KestrelTests/FrameFacts.cs new file mode 100644 index 0000000000..d76c015fae --- /dev/null +++ b/test/Microsoft.AspNet.Server.KestrelTests/FrameFacts.cs @@ -0,0 +1,26 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using Microsoft.AspNet.Http.Features; +using Microsoft.AspNet.Server.Kestrel.Http; +using Xunit; + +namespace Microsoft.AspNet.Server.KestrelTests +{ + public class FrameFacts + { + [Fact] + public void ResetResetsScheme() + { + // Arrange + var frame = new Frame(new ConnectionContext() { DateHeaderValueManager = new DateHeaderValueManager() }); + frame.Scheme = "https"; + + // Act + frame.Reset(); + + // Assert + Assert.Equal("http", frame.Get().Scheme); + } + } +} From 2e2dfd87c1dcd5c286679276670becc9b34fc8c4 Mon Sep 17 00:00:00 2001 From: Troy Dai Date: Fri, 13 Nov 2015 21:40:17 -0800 Subject: [PATCH 0428/1662] Fix byte[] array allocation in IsDarwin --- .../Networking/Libuv.cs | 4 ++-- .../Networking/PlatformApis.cs | 24 ++++++++++--------- .../Networking/SockAddr.cs | 2 +- 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/Libuv.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/Libuv.cs index ef6fb74434..f00bfa586e 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/Libuv.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/Libuv.cs @@ -10,11 +10,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking { public Libuv() { - IsWindows = PlatformApis.IsWindows(); + IsWindows = PlatformApis.IsWindows; var isDarwinMono = #if DNX451 - IsWindows ? false : PlatformApis.IsDarwin(); + IsWindows ? false : PlatformApis.IsDarwin; #else false; #endif diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/PlatformApis.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/PlatformApis.cs index f874ac9b15..370fcb30c2 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/PlatformApis.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/PlatformApis.cs @@ -8,23 +8,25 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking { public static class PlatformApis { - public static bool IsWindows() + static PlatformApis() { #if DOTNET5_4 || DNXCORE50 - // Until Environment.OSVersion.Platform is exposed on .NET Core, we - // try to call uname and if that fails we assume we are on Windows. - return GetUname() == string.Empty; + IsWindows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows); + IsDarwin = RuntimeInformation.IsOSPlatform(OSPlatform.OSX); #else - var p = (int)Environment.OSVersion.Platform; - return (p != 4) && (p != 6) && (p != 128); + var p = (int)System.Environment.OSVersion.Platform; + IsWindows = (p != 4) && (p != 6) && (p != 128); + + // When running on Mono in Darwin OSVersion doesn't return Darwin. It returns Unix instead. + // Fallback to use uname. + IsDarwin = string.Equals(GetUname(), "Darwin", StringComparison.Ordinal); #endif } + + public static bool IsWindows { get; } - public static bool IsDarwin() - { - return string.Equals(GetUname(), "Darwin", StringComparison.Ordinal); - } - + public static bool IsDarwin { get; } + [DllImport("libc")] static extern int uname(IntPtr buf); diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/SockAddr.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/SockAddr.cs index 3be4ee9301..762b1f5140 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/SockAddr.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/SockAddr.cs @@ -64,7 +64,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking var port = ((int)(_field0 & 0x00FF0000) >> 8) | (int)((_field0 & 0xFF000000) >> 24); int family = (int)_field0; - if (PlatformApis.IsDarwin()) + if (PlatformApis.IsDarwin) { // see explaination in example 4 family = family >> 8; From bd6e181d93073f29021672972f550a7e33441bb4 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Sun, 15 Nov 2015 21:17:14 +0000 Subject: [PATCH 0429/1662] ConcurrentStack -> ConcurrentQueue --- .../Infrastructure/MemoryPool2.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPool2.cs b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPool2.cs index 86561516c6..37d64ddcaf 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPool2.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPool2.cs @@ -40,7 +40,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure /// Thread-safe collection of blocks which are currently in the pool. A slab will pre-allocate all of the block tracking objects /// and add them to this collection. When memory is requested it is taken from here first, and when it is returned it is re-added. /// - private readonly ConcurrentStack _blocks = new ConcurrentStack(); + private readonly ConcurrentQueue _blocks = new ConcurrentQueue(); /// /// Thread-safe collection of slabs which have been allocated by this pool. As long as a slab is in this collection and slab.IsActive, @@ -75,7 +75,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure } MemoryPoolBlock2 block; - if (_blocks.TryPop(out block)) + if (_blocks.TryDequeue(out block)) { // block successfully taken from the stack - return it return block; @@ -132,7 +132,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure public void Return(MemoryPoolBlock2 block) { block.Reset(); - _blocks.Push(block); + _blocks.Enqueue(block); } protected virtual void Dispose(bool disposing) From f7bdc5a4e9ed9f2b2162301f9e3ff1ac86547ec0 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Sat, 14 Nov 2015 22:37:28 +0000 Subject: [PATCH 0430/1662] Skip non-consumed rather than reading --- .../Http/Frame.cs | 2 +- .../Http/MessageBody.cs | 115 ++++++++++++++++++ .../Http/SocketInputExtensions.cs | 22 ++++ .../Infrastructure/MemoryPoolIterator2.cs | 32 +++++ 4 files changed, 170 insertions(+), 1 deletion(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs index c08d0eb684..dac00934db 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs @@ -232,7 +232,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http await ProduceEnd(); - while (await RequestBody.ReadAsync(_nullBuffer, 0, _nullBuffer.Length) != 0) + while (await MessageBody.SkipAsync() != 0) { // Finish reading the request body in case the app did not. } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/MessageBody.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/MessageBody.cs index e8e438512b..393803e752 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/MessageBody.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/MessageBody.cs @@ -38,8 +38,26 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return result; } + public Task SkipAsync(CancellationToken cancellationToken = default(CancellationToken)) + { + Task result = null; + var send100Continue = 0; + result = SkipImplementation(cancellationToken); + if (!result.IsCompleted) + { + send100Continue = Interlocked.Exchange(ref _send100Continue, 0); + } + if (send100Continue == 1) + { + _context.FrameControl.ProduceContinue(); + } + return result; + } + public abstract Task ReadAsyncImplementation(ArraySegment buffer, CancellationToken cancellationToken); + public abstract Task SkipImplementation(CancellationToken cancellationToken); + public static MessageBody For( string httpVersion, IDictionary headers, @@ -110,6 +128,10 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { return _context.SocketInput.ReadAsync(buffer); } + public override Task SkipImplementation(CancellationToken cancellationToken) + { + return _context.SocketInput.SkipAsync(4096); + } } class ForContentLength : MessageBody @@ -146,6 +168,27 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return actual; } + + public override async Task SkipImplementation(CancellationToken cancellationToken) + { + var input = _context.SocketInput; + + var limit = Math.Min(4096, _inputLength); + if (limit == 0) + { + return 0; + } + + var actual = await _context.SocketInput.SkipAsync(limit); + _inputLength -= actual; + + if (actual == 0) + { + throw new InvalidDataException("Unexpected end of request content"); + } + + return actual; + } } @@ -236,6 +279,78 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return 0; } + public override async Task SkipImplementation(CancellationToken cancellationToken) + { + var input = _context.SocketInput; + + while (_mode != Mode.Complete) + { + while (_mode == Mode.ChunkPrefix) + { + var chunkSize = 0; + if (!TakeChunkedLine(input, ref chunkSize)) + { + await input; + } + else if (chunkSize == 0) + { + _mode = Mode.Complete; + } + else + { + _mode = Mode.ChunkData; + } + _inputLength = chunkSize; + } + while (_mode == Mode.ChunkData) + { + var limit = Math.Min(4096, _inputLength); + if (limit != 0) + { + await input; + } + + var begin = input.ConsumingStart(); + int actual; + var end = begin.Skip(limit, out actual); + _inputLength -= actual; + input.ConsumingComplete(end, end); + + if (_inputLength == 0) + { + _mode = Mode.ChunkSuffix; + } + if (actual != 0) + { + return actual; + } + } + while (_mode == Mode.ChunkSuffix) + { + var scan = input.ConsumingStart(); + var consumed = scan; + var ch1 = scan.Take(); + var ch2 = scan.Take(); + if (ch1 == -1 || ch2 == -1) + { + input.ConsumingComplete(consumed, scan); + await input; + } + else if (ch1 == '\r' && ch2 == '\n') + { + input.ConsumingComplete(scan, scan); + _mode = Mode.ChunkPrefix; + } + else + { + throw new NotImplementedException("INVALID REQUEST FORMAT"); + } + } + } + + return 0; + } + private static bool TakeChunkedLine(SocketInput baton, ref int chunkSizeOut) { var scan = baton.ConsumingStart(); diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketInputExtensions.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketInputExtensions.cs index 9c5d690707..70a491565d 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketInputExtensions.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketInputExtensions.cs @@ -29,5 +29,27 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } } + + public static async Task SkipAsync(this SocketInput input, int limit) + { + while (true) + { + await input; + + var begin = input.ConsumingStart(); + int actual; + var end = begin.Skip(limit, out actual); + input.ConsumingComplete(end, end); + + if (actual != 0) + { + return actual; + } + if (input.RemoteIntakeFin) + { + return 0; + } + } + } } } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolIterator2.cs b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolIterator2.cs index 7de5c7fb10..c14534a176 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolIterator2.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolIterator2.cs @@ -619,5 +619,37 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure } } } + public MemoryPoolIterator2 Skip(int limit, out int actual) + { + if (IsDefault) + { + actual = 0; + return this; + } + + var block = _block; + var index = _index; + var remaining = limit; + while (true) + { + var following = block.End - index; + if (remaining <= following) + { + actual = limit; + return new MemoryPoolIterator2(block, index + remaining); + } + else if (block.Next == null) + { + actual = limit - remaining + following; + return new MemoryPoolIterator2(block, index + following); + } + else + { + remaining -= following; + block = block.Next; + index = block.Start; + } + } + } } } From f48e6ba51af0e8a78ed9042b80e81064baa9a347 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Sat, 14 Nov 2015 22:59:37 +0000 Subject: [PATCH 0431/1662] Add Async in method name --- .../Http/MessageBody.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/MessageBody.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/MessageBody.cs index 393803e752..5453256418 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/MessageBody.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/MessageBody.cs @@ -42,7 +42,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { Task result = null; var send100Continue = 0; - result = SkipImplementation(cancellationToken); + result = SkipAsyncImplementation(cancellationToken); if (!result.IsCompleted) { send100Continue = Interlocked.Exchange(ref _send100Continue, 0); @@ -56,7 +56,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http public abstract Task ReadAsyncImplementation(ArraySegment buffer, CancellationToken cancellationToken); - public abstract Task SkipImplementation(CancellationToken cancellationToken); + public abstract Task SkipAsyncImplementation(CancellationToken cancellationToken); public static MessageBody For( string httpVersion, @@ -128,7 +128,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { return _context.SocketInput.ReadAsync(buffer); } - public override Task SkipImplementation(CancellationToken cancellationToken) + public override Task SkipAsyncImplementation(CancellationToken cancellationToken) { return _context.SocketInput.SkipAsync(4096); } @@ -169,7 +169,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return actual; } - public override async Task SkipImplementation(CancellationToken cancellationToken) + public override async Task SkipAsyncImplementation(CancellationToken cancellationToken) { var input = _context.SocketInput; @@ -279,7 +279,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return 0; } - public override async Task SkipImplementation(CancellationToken cancellationToken) + public override async Task SkipAsyncImplementation(CancellationToken cancellationToken) { var input = _context.SocketInput; From f089abd33727731434c4a2dab44fc5b4bc36391b Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Sun, 15 Nov 2015 21:33:31 +0000 Subject: [PATCH 0432/1662] Consume in single call --- .../Http/Frame.cs | 6 ++--- .../Http/MessageBody.cs | 26 ++++++++++--------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs index dac00934db..e8310aab06 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs @@ -232,10 +232,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http await ProduceEnd(); - while (await MessageBody.SkipAsync() != 0) - { - // Finish reading the request body in case the app did not. - } + // Finish reading the request body in case the app did not. + await MessageBody.Consume(); } terminated = !_keepAlive; diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/MessageBody.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/MessageBody.cs index 5453256418..1604d0145d 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/MessageBody.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/MessageBody.cs @@ -38,20 +38,22 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return result; } - public Task SkipAsync(CancellationToken cancellationToken = default(CancellationToken)) + public async Task Consume(CancellationToken cancellationToken = default(CancellationToken)) { - Task result = null; - var send100Continue = 0; - result = SkipAsyncImplementation(cancellationToken); - if (!result.IsCompleted) + Task result; + do { - send100Continue = Interlocked.Exchange(ref _send100Continue, 0); - } - if (send100Continue == 1) - { - _context.FrameControl.ProduceContinue(); - } - return result; + var send100Continue = 0; + result = SkipAsyncImplementation(cancellationToken); + if (!result.IsCompleted) + { + send100Continue = Interlocked.Exchange(ref _send100Continue, 0); + } + if (send100Continue == 1) + { + _context.FrameControl.ProduceContinue(); + } + } while (await result != 0); } public abstract Task ReadAsyncImplementation(ArraySegment buffer, CancellationToken cancellationToken); From 1589b54018b5a084c3a2ec067bbef49f1d3133fd Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Sun, 15 Nov 2015 21:56:20 +0000 Subject: [PATCH 0433/1662] Early bail, completed tasks+Interlocked --- .../Http/MessageBody.cs | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/MessageBody.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/MessageBody.cs index 1604d0145d..7e75fcb1bb 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/MessageBody.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/MessageBody.cs @@ -41,17 +41,27 @@ namespace Microsoft.AspNet.Server.Kestrel.Http public async Task Consume(CancellationToken cancellationToken = default(CancellationToken)) { Task result; + var firstLoop = true; do { - var send100Continue = 0; result = SkipAsyncImplementation(cancellationToken); if (!result.IsCompleted) { - send100Continue = Interlocked.Exchange(ref _send100Continue, 0); + if (firstLoop && Interlocked.Exchange(ref _send100Continue, 0) == 1) + { + firstLoop = false; + _context.FrameControl.ProduceContinue(); + } } - if (send100Continue == 1) + else if (result.GetAwaiter().GetResult() == 0) { - _context.FrameControl.ProduceContinue(); + // Completed Task, end of stream + return; + } + else + { + // Completed Task, get next Task rather than await + continue; } } while (await result != 0); } From ecc439555e8a89bca9d5431b7e4f4cecc4fd437f Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Sun, 15 Nov 2015 22:27:39 +0000 Subject: [PATCH 0434/1662] Reuse ReadAsync for Consume --- .../Filter/LibuvStream.cs | 2 +- .../Http/MessageBody.cs | 110 +----------------- .../Http/SocketInputExtensions.cs | 26 +---- .../Infrastructure/MemoryPoolIterator2.cs | 47 ++------ 4 files changed, 20 insertions(+), 165 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Filter/LibuvStream.cs b/src/Microsoft.AspNet.Server.Kestrel/Filter/LibuvStream.cs index 4f63195760..d61c0eafbc 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Filter/LibuvStream.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Filter/LibuvStream.cs @@ -85,7 +85,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Filter private Task ReadAsync(ArraySegment buffer) { - return _input.ReadAsync(buffer); + return _input.ReadAsync(buffer.Array, buffer.Offset, buffer.Count); } } } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/MessageBody.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/MessageBody.cs index 7e75fcb1bb..11a15e249b 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/MessageBody.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/MessageBody.cs @@ -44,7 +44,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http var firstLoop = true; do { - result = SkipAsyncImplementation(cancellationToken); + result = ReadAsyncImplementation(default(ArraySegment), cancellationToken); if (!result.IsCompleted) { if (firstLoop && Interlocked.Exchange(ref _send100Continue, 0) == 1) @@ -68,8 +68,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Http public abstract Task ReadAsyncImplementation(ArraySegment buffer, CancellationToken cancellationToken); - public abstract Task SkipAsyncImplementation(CancellationToken cancellationToken); - public static MessageBody For( string httpVersion, IDictionary headers, @@ -138,11 +136,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http public override Task ReadAsyncImplementation(ArraySegment buffer, CancellationToken cancellationToken) { - return _context.SocketInput.ReadAsync(buffer); - } - public override Task SkipAsyncImplementation(CancellationToken cancellationToken) - { - return _context.SocketInput.SkipAsync(4096); + return _context.SocketInput.ReadAsync(buffer.Array, buffer.Offset, buffer.Array == null ? 8192 : buffer.Count); } } @@ -163,35 +157,13 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { var input = _context.SocketInput; - var limit = Math.Min(buffer.Count, _inputLength); + var limit = buffer.Array == null ? _inputLength : Math.Min(buffer.Count, _inputLength); if (limit == 0) { return 0; } - var limitedBuffer = new ArraySegment(buffer.Array, buffer.Offset, limit); - var actual = await _context.SocketInput.ReadAsync(limitedBuffer); - _inputLength -= actual; - - if (actual == 0) - { - throw new InvalidDataException("Unexpected end of request content"); - } - - return actual; - } - - public override async Task SkipAsyncImplementation(CancellationToken cancellationToken) - { - var input = _context.SocketInput; - - var limit = Math.Min(4096, _inputLength); - if (limit == 0) - { - return 0; - } - - var actual = await _context.SocketInput.SkipAsync(limit); + var actual = await _context.SocketInput.ReadAsync(buffer.Array, buffer.Offset, limit); _inputLength -= actual; if (actual == 0) @@ -244,7 +216,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } while (_mode == Mode.ChunkData) { - var limit = Math.Min(buffer.Count, _inputLength); + var limit = buffer.Array == null ? _inputLength : Math.Min(buffer.Count, _inputLength); if (limit != 0) { await input; @@ -291,78 +263,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return 0; } - public override async Task SkipAsyncImplementation(CancellationToken cancellationToken) - { - var input = _context.SocketInput; - - while (_mode != Mode.Complete) - { - while (_mode == Mode.ChunkPrefix) - { - var chunkSize = 0; - if (!TakeChunkedLine(input, ref chunkSize)) - { - await input; - } - else if (chunkSize == 0) - { - _mode = Mode.Complete; - } - else - { - _mode = Mode.ChunkData; - } - _inputLength = chunkSize; - } - while (_mode == Mode.ChunkData) - { - var limit = Math.Min(4096, _inputLength); - if (limit != 0) - { - await input; - } - - var begin = input.ConsumingStart(); - int actual; - var end = begin.Skip(limit, out actual); - _inputLength -= actual; - input.ConsumingComplete(end, end); - - if (_inputLength == 0) - { - _mode = Mode.ChunkSuffix; - } - if (actual != 0) - { - return actual; - } - } - while (_mode == Mode.ChunkSuffix) - { - var scan = input.ConsumingStart(); - var consumed = scan; - var ch1 = scan.Take(); - var ch2 = scan.Take(); - if (ch1 == -1 || ch2 == -1) - { - input.ConsumingComplete(consumed, scan); - await input; - } - else if (ch1 == '\r' && ch2 == '\n') - { - input.ConsumingComplete(scan, scan); - _mode = Mode.ChunkPrefix; - } - else - { - throw new NotImplementedException("INVALID REQUEST FORMAT"); - } - } - } - - return 0; - } - private static bool TakeChunkedLine(SocketInput baton, ref int chunkSizeOut) { var scan = baton.ConsumingStart(); diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketInputExtensions.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketInputExtensions.cs index 70a491565d..c36d88155d 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketInputExtensions.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketInputExtensions.cs @@ -8,7 +8,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { public static class SocketInputExtensions { - public static async Task ReadAsync(this SocketInput input, ArraySegment buffer) + public static async Task ReadAsync(this SocketInput input, byte[] buffer, int offset, int count) { while (true) { @@ -16,29 +16,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http var begin = input.ConsumingStart(); int actual; - var end = begin.CopyTo(buffer.Array, buffer.Offset, buffer.Count, out actual); - input.ConsumingComplete(end, end); - - if (actual != 0) - { - return actual; - } - if (input.RemoteIntakeFin) - { - return 0; - } - } - } - - public static async Task SkipAsync(this SocketInput input, int limit) - { - while (true) - { - await input; - - var begin = input.ConsumingStart(); - int actual; - var end = begin.Skip(limit, out actual); + var end = begin.CopyTo(buffer, offset, count, out actual); input.ConsumingComplete(end, end); if (actual != 0) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolIterator2.cs b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolIterator2.cs index c14534a176..ddb12bff7f 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolIterator2.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolIterator2.cs @@ -600,18 +600,27 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure if (remaining <= following) { actual = count; - Buffer.BlockCopy(block.Array, index, array, offset, remaining); + if (array != null) + { + Buffer.BlockCopy(block.Array, index, array, offset, remaining); + } return new MemoryPoolIterator2(block, index + remaining); } else if (block.Next == null) { actual = count - remaining + following; - Buffer.BlockCopy(block.Array, index, array, offset, following); + if (array != null) + { + Buffer.BlockCopy(block.Array, index, array, offset, following); + } return new MemoryPoolIterator2(block, index + following); } else { - Buffer.BlockCopy(block.Array, index, array, offset, following); + if (array != null) + { + Buffer.BlockCopy(block.Array, index, array, offset, following); + } offset += following; remaining -= following; block = block.Next; @@ -619,37 +628,5 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure } } } - public MemoryPoolIterator2 Skip(int limit, out int actual) - { - if (IsDefault) - { - actual = 0; - return this; - } - - var block = _block; - var index = _index; - var remaining = limit; - while (true) - { - var following = block.End - index; - if (remaining <= following) - { - actual = limit; - return new MemoryPoolIterator2(block, index + remaining); - } - else if (block.Next == null) - { - actual = limit - remaining + following; - return new MemoryPoolIterator2(block, index + following); - } - else - { - remaining -= following; - block = block.Next; - index = block.Start; - } - } - } } } From 7691a7cc2312056418756aaceb2a3b2c57c2f761 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Mon, 16 Nov 2015 06:43:49 +0000 Subject: [PATCH 0435/1662] Improved Send100 Check --- .../Http/MessageBody.cs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/MessageBody.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/MessageBody.cs index 11a15e249b..8edd424a10 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/MessageBody.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/MessageBody.cs @@ -41,16 +41,19 @@ namespace Microsoft.AspNet.Server.Kestrel.Http public async Task Consume(CancellationToken cancellationToken = default(CancellationToken)) { Task result; - var firstLoop = true; + var send100checked = false; do { result = ReadAsyncImplementation(default(ArraySegment), cancellationToken); if (!result.IsCompleted) { - if (firstLoop && Interlocked.Exchange(ref _send100Continue, 0) == 1) + if (!send100checked) { - firstLoop = false; - _context.FrameControl.ProduceContinue(); + if (Interlocked.Exchange(ref _send100Continue, 0) == 1) + { + _context.FrameControl.ProduceContinue(); + } + send100checked = true; } } else if (result.GetAwaiter().GetResult() == 0) From 8941d4b620322e80d5c57d1b23d72b3a56ad4943 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Mon, 16 Nov 2015 14:56:44 +0000 Subject: [PATCH 0436/1662] Disconnect is Debug not Error Resolves #392 --- .../Infrastructure/KestrelTrace.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelTrace.cs b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelTrace.cs index 4ac345e709..9f6d047fdd 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelTrace.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelTrace.cs @@ -35,7 +35,7 @@ namespace Microsoft.AspNet.Server.Kestrel _connectionWriteFin = LoggerMessage.Define(LogLevel.Debug, 7, @"Connection id ""{ConnectionId}"" sending FIN."); _connectionWroteFin = LoggerMessage.Define(LogLevel.Debug, 8, @"Connection id ""{ConnectionId}"" sent FIN with status ""{Status}""."); _connectionKeepAlive = LoggerMessage.Define(LogLevel.Debug, 9, @"Connection id ""{ConnectionId}"" completed keep alive response."); - _connectionDisconnect = LoggerMessage.Define(LogLevel.Error, 10, @"Connection id ""{ConnectionId}"" disconnected."); + _connectionDisconnect = LoggerMessage.Define(LogLevel.Debug, 10, @"Connection id ""{ConnectionId}"" disconnected."); // ConnectionWrite: Reserved: 11 // ConnectionWriteCallback: Reserved: 12 // ApplicationError: Reserved: 13 - LoggerMessage.Define overload not present From aa2b65efccfd6d65ff22ddaf2c1a9fc0ae17e54a Mon Sep 17 00:00:00 2001 From: Doug Bunting Date: Fri, 13 Nov 2015 16:23:41 -0800 Subject: [PATCH 0437/1662] Execute `dnu restore` in Travis builds with .NET Core --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index eef144e738..20cb839d95 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,6 +5,8 @@ addons: apt: packages: - libunwind8 +env: + - KOREBUILD_DNU_RESTORE_CORECLR=true install: - curl -sSL https://github.com/libuv/libuv/archive/v1.4.2.tar.gz | tar zxfv - -C /tmp && cd /tmp/libuv-1.4.2/ - sh autogen.sh From 8c0a1701cd1f8236dc1c5ea171f06e6dc4e2ab0c Mon Sep 17 00:00:00 2001 From: Doug Bunting Date: Sun, 15 Nov 2015 22:53:39 -0800 Subject: [PATCH 0438/1662] Nit: Set `KoreBuild_*` environment variables consistently --- .travis.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 20cb839d95..e5af3cd231 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,7 +6,7 @@ addons: packages: - libunwind8 env: - - KOREBUILD_DNU_RESTORE_CORECLR=true + - KOREBUILD_DNU_RESTORE_CORECLR=true KOREBUILD_TEST_DNXCORE=true install: - curl -sSL https://github.com/libuv/libuv/archive/v1.4.2.tar.gz | tar zxfv - -C /tmp && cd /tmp/libuv-1.4.2/ - sh autogen.sh @@ -16,5 +16,4 @@ install: - export LD_LIBRARY_PATH="$HOME/libuvinstall/lib" - cd $OLDPWD script: - - export KOREBUILD_TEST_DNXCORE=1 - ./build.sh --quiet verify From f60f6c92ca8939f20e9e17c5df3677ddf604af76 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Sun, 1 Nov 2015 09:50:24 +0000 Subject: [PATCH 0439/1662] Stop streams on finish Can't use dispose (or close) as can be disposed too early by user code Resolves #263 --- .../Http/Frame.cs | 9 +++++-- .../Http/FrameRequestStream.cs | 21 +++++++++++++++ .../Http/FrameResponseStream.cs | 26 +++++++++++++++++++ 3 files changed, 54 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs index bf6b821d3e..104fc6c1d9 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs @@ -204,8 +204,10 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { MessageBody = MessageBody.For(HttpVersion, _requestHeaders, this); _keepAlive = MessageBody.RequestKeepAlive; - RequestBody = new FrameRequestStream(MessageBody); - ResponseBody = new FrameResponseStream(this); + var requestBody = new FrameRequestStream(MessageBody); + RequestBody = requestBody; + var responseBody = new FrameResponseStream(this); + ResponseBody = responseBody; DuplexStream = new FrameDuplexStream(RequestBody, ResponseBody); var httpContext = HttpContextFactory.Create(this); @@ -236,6 +238,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Http // Finish reading the request body in case the app did not. await MessageBody.Consume(); + + requestBody.StopAcceptingReads(); + responseBody.StopAcceptingWrites(); } terminated = !_keepAlive; diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameRequestStream.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameRequestStream.cs index be3ac5d225..90ebe8601e 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameRequestStream.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameRequestStream.cs @@ -11,6 +11,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http public class FrameRequestStream : Stream { private readonly MessageBody _body; + private bool _stopped; public FrameRequestStream(MessageBody body) { @@ -50,12 +51,22 @@ namespace Microsoft.AspNet.Server.Kestrel.Http public override int Read(byte[] buffer, int offset, int count) { + if (_stopped) + { + throw new ObjectDisposedException("RequestStream has been disposed"); + } + return ReadAsync(buffer, offset, count).GetAwaiter().GetResult(); } #if NET451 public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback callback, object state) { + if (_stopped) + { + throw new ObjectDisposedException("RequestStream has been disposed"); + } + var task = ReadAsync(buffer, offset, count, CancellationToken.None, state); if (callback != null) { @@ -71,6 +82,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http private Task ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken, object state) { + if (_stopped) + { + throw new ObjectDisposedException("RequestStream has been disposed"); + } + var tcs = new TaskCompletionSource(state); var task = _body.ReadAsync(new ArraySegment(buffer, offset, count), cancellationToken); task.ContinueWith((task2, state2) => @@ -102,5 +118,10 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { throw new NotImplementedException(); } + + public void StopAcceptingReads() + { + _stopped = true; + } } } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameResponseStream.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameResponseStream.cs index 631c106045..813ef23ba4 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameResponseStream.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameResponseStream.cs @@ -11,6 +11,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http class FrameResponseStream : Stream { private readonly FrameContext _context; + private bool _stopped; public FrameResponseStream(FrameContext context) { @@ -35,11 +36,21 @@ namespace Microsoft.AspNet.Server.Kestrel.Http public override void Flush() { + if (_stopped) + { + throw new ObjectDisposedException("ResponseStream has been disposed"); + } + _context.FrameControl.Flush(); } public override Task FlushAsync(CancellationToken cancellationToken) { + if (_stopped) + { + throw new ObjectDisposedException("ResponseStream has been disposed"); + } + return _context.FrameControl.FlushAsync(cancellationToken); } @@ -60,12 +71,27 @@ namespace Microsoft.AspNet.Server.Kestrel.Http public override void Write(byte[] buffer, int offset, int count) { + if (_stopped) + { + throw new ObjectDisposedException("ResponseStream has been disposed"); + } + _context.FrameControl.Write(new ArraySegment(buffer, offset, count)); } public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) { + if (_stopped) + { + throw new ObjectDisposedException("ResponseStream has been disposed"); + } + return _context.FrameControl.WriteAsync(new ArraySegment(buffer, offset, count), cancellationToken); } + + public void StopAcceptingWrites() + { + _stopped = true; + } } } From 5e883827e0c1ed18bdf0badeebb863a315b24098 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Mon, 2 Nov 2015 01:50:17 +0000 Subject: [PATCH 0440/1662] Explain why dispose can't be used --- src/Microsoft.AspNet.Server.Kestrel/Http/FrameRequestStream.cs | 2 ++ src/Microsoft.AspNet.Server.Kestrel/Http/FrameResponseStream.cs | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameRequestStream.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameRequestStream.cs index 90ebe8601e..6545b09e9b 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameRequestStream.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameRequestStream.cs @@ -121,6 +121,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http public void StopAcceptingReads() { + // Can't use dispose (or close) as can be disposed too early by user code + // As exampled in EngineTests.ZeroContentLengthNotSetAutomaticallyForCertainStatusCodes _stopped = true; } } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameResponseStream.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameResponseStream.cs index 813ef23ba4..465e5fe3d2 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameResponseStream.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameResponseStream.cs @@ -91,6 +91,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http public void StopAcceptingWrites() { + // Can't use dispose (or close) as can be disposed too early by user code + // As exampled in EngineTests.ZeroContentLengthNotSetAutomaticallyForCertainStatusCodes _stopped = true; } } From 1cbb273b0d6d752ed557a78de38a5b83a8223d0e Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Tue, 3 Nov 2015 19:26:34 +0000 Subject: [PATCH 0441/1662] Corrected Exception messages --- .../Http/FrameRequestStream.cs | 6 +++--- .../Http/FrameResponseStream.cs | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameRequestStream.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameRequestStream.cs index 6545b09e9b..8483020ddb 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameRequestStream.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameRequestStream.cs @@ -53,7 +53,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { if (_stopped) { - throw new ObjectDisposedException("RequestStream has been disposed"); + throw new ObjectDisposedException(nameof(FrameRequestStream)); } return ReadAsync(buffer, offset, count).GetAwaiter().GetResult(); @@ -64,7 +64,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { if (_stopped) { - throw new ObjectDisposedException("RequestStream has been disposed"); + throw new ObjectDisposedException(nameof(FrameRequestStream)); } var task = ReadAsync(buffer, offset, count, CancellationToken.None, state); @@ -84,7 +84,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { if (_stopped) { - throw new ObjectDisposedException("RequestStream has been disposed"); + throw new ObjectDisposedException(nameof(FrameRequestStream)); } var tcs = new TaskCompletionSource(state); diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameResponseStream.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameResponseStream.cs index 465e5fe3d2..bef3453ad3 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameResponseStream.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameResponseStream.cs @@ -38,7 +38,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { if (_stopped) { - throw new ObjectDisposedException("ResponseStream has been disposed"); + throw new ObjectDisposedException(nameof(FrameResponseStream)); } _context.FrameControl.Flush(); @@ -48,7 +48,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { if (_stopped) { - throw new ObjectDisposedException("ResponseStream has been disposed"); + throw new ObjectDisposedException(nameof(FrameResponseStream)); } return _context.FrameControl.FlushAsync(cancellationToken); @@ -73,7 +73,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { if (_stopped) { - throw new ObjectDisposedException("ResponseStream has been disposed"); + throw new ObjectDisposedException(nameof(FrameResponseStream)); } _context.FrameControl.Write(new ArraySegment(buffer, offset, count)); @@ -83,7 +83,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { if (_stopped) { - throw new ObjectDisposedException("ResponseStream has been disposed"); + throw new ObjectDisposedException(nameof(FrameResponseStream)); } return _context.FrameControl.WriteAsync(new ArraySegment(buffer, offset, count), cancellationToken); From 062caf16be245df0849ef376a35597ed0ad0624d Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Thu, 29 Oct 2015 15:09:48 -0700 Subject: [PATCH 0442/1662] Support for IHttpRequestLifetimeFeature --- .../Http/Connection.cs | 6 ++ .../Http/Frame.FeatureCollection.cs | 12 ++- .../Http/Frame.Generated.cs | 2 +- .../Http/Frame.cs | 81 ++++++++++++++----- .../Http/SocketInput.cs | 17 ++++ .../EngineTests.cs | 72 +++++++++++++++++ .../FrameFeatureCollection.cs | 1 + 7 files changed, 170 insertions(+), 21 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs index 4061f1e80a..182bc98654 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs @@ -152,7 +152,13 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { handle.Libuv.Check(status, out error); } + _rawSocketInput.IncomingComplete(readCount, error); + + if (errorDone) + { + _frame.Abort(); + } } private Frame CreateFrame() diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.FeatureCollection.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.FeatureCollection.cs index 8cac73a946..b14f968f16 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.FeatureCollection.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.FeatureCollection.cs @@ -7,9 +7,11 @@ using System.Collections.Generic; using System.IO; using System.Linq; using System.Net; +using System.Threading; using System.Threading.Tasks; using Microsoft.AspNet.Http; using Microsoft.AspNet.Http.Features; +using Microsoft.Extensions.Logging; using Microsoft.Extensions.Primitives; namespace Microsoft.AspNet.Server.Kestrel.Http @@ -18,7 +20,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http IHttpRequestFeature, IHttpResponseFeature, IHttpUpgradeFeature, - IHttpConnectionFeature + IHttpConnectionFeature, + IHttpRequestLifetimeFeature { // NOTE: When feature interfaces are added to or removed from this Frame class implementation, // then the list of `implementedFeatures` in the generated code project MUST also be updated. @@ -260,6 +263,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http bool IHttpConnectionFeature.IsLocal { get; set; } + CancellationToken IHttpRequestLifetimeFeature.RequestAborted { get; set; } + object IFeatureCollection.this[Type key] { get { return FastFeatureGet(key); } @@ -298,5 +303,10 @@ namespace Microsoft.AspNet.Server.Kestrel.Http IEnumerator> IEnumerable>.GetEnumerator() => FastEnumerable().GetEnumerator(); IEnumerator IEnumerable.GetEnumerator() => FastEnumerable().GetEnumerator(); + + void IHttpRequestLifetimeFeature.Abort() + { + Abort(); + } } } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.Generated.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.Generated.cs index 985267a57f..e449f94d83 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.Generated.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.Generated.cs @@ -45,11 +45,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http _currentIHttpRequestFeature = this; _currentIHttpResponseFeature = this; _currentIHttpUpgradeFeature = this; + _currentIHttpRequestLifetimeFeature = this; _currentIHttpConnectionFeature = this; _currentIHttpRequestIdentifierFeature = null; _currentIServiceProvidersFeature = null; - _currentIHttpRequestLifetimeFeature = null; _currentIHttpAuthenticationFeature = null; _currentIQueryFeature = null; _currentIFormFeature = null; diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs index 104fc6c1d9..39f4e428ec 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs @@ -41,6 +41,12 @@ namespace Microsoft.AspNet.Server.Kestrel.Http private bool _requestProcessingStarted; private Task _requestProcessingTask; private volatile bool _requestProcessingStopping; // volatile, see: https://msdn.microsoft.com/en-us/library/x13ttww7.aspx + private volatile bool _requestAborted; + private CancellationTokenSource _disconnectCts = new CancellationTokenSource(); + private CancellationTokenSource _requestAbortCts; + + private FrameRequestStream _requestBody; + private FrameResponseStream _responseBody; private bool _responseStarted; private bool _keepAlive; @@ -74,7 +80,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Http public string QueryString { get; set; } public string HttpVersion { get; set; } public IHeaderDictionary RequestHeaders { get; set; } - public MessageBody MessageBody { get; set; } public Stream RequestBody { get; set; } public int StatusCode { get; set; } @@ -110,7 +115,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Http QueryString = null; HttpVersion = null; RequestHeaders = _requestHeaders; - MessageBody = null; RequestBody = null; StatusCode = 200; ReasonPhrase = null; @@ -133,6 +137,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { httpConnectionFeature.IsLocal = false; } + + _requestAbortCts?.Dispose(); } public void ResetResponseHeaders() @@ -169,6 +175,30 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return _requestProcessingTask ?? TaskUtilities.CompletedTask; } + /// + /// Immediate kill the connection and poison the request and response streams. + /// + public void Abort() + { + _requestProcessingStopping = true; + _requestAborted = true; + + _requestBody?.StopAcceptingReads(); + _responseBody?.StopAcceptingWrites(); + + try + { + ConnectionControl.End(ProduceEndType.SocketDisconnect); + SocketInput.AbortAwaiting(); + + _disconnectCts.Cancel(); + } + catch (Exception ex) + { + Log.LogError("Abort", ex); + } + } + /// /// Primary loop which consumes socket input, parses it for protocol framing, and invokes the /// application delegate for as long as the socket is intended to remain open. @@ -202,14 +232,17 @@ namespace Microsoft.AspNet.Server.Kestrel.Http if (!terminated && !_requestProcessingStopping) { - MessageBody = MessageBody.For(HttpVersion, _requestHeaders, this); - _keepAlive = MessageBody.RequestKeepAlive; - var requestBody = new FrameRequestStream(MessageBody); - RequestBody = requestBody; - var responseBody = new FrameResponseStream(this); - ResponseBody = responseBody; + var messageBody = MessageBody.For(HttpVersion, _requestHeaders, this); + _keepAlive = messageBody.RequestKeepAlive; + _requestBody = new FrameRequestStream(messageBody); + RequestBody = _requestBody; + _responseBody = new FrameResponseStream(this); + ResponseBody = _responseBody; DuplexStream = new FrameDuplexStream(RequestBody, ResponseBody); + _requestAbortCts = CancellationTokenSource.CreateLinkedTokenSource(_disconnectCts.Token); + ((IHttpRequestLifetimeFeature)this).RequestAborted = _requestAbortCts.Token; + var httpContext = HttpContextFactory.Create(this); try { @@ -234,13 +267,17 @@ namespace Microsoft.AspNet.Server.Kestrel.Http HttpContextFactory.Dispose(httpContext); - await ProduceEnd(); + // If _requestAbort is set, the connection has already been closed. + if (!_requestAborted) + { + await ProduceEnd(); - // Finish reading the request body in case the app did not. - await MessageBody.Consume(); + // Finish reading the request body in case the app did not. + await messageBody.Consume(); + } - requestBody.StopAcceptingReads(); - responseBody.StopAcceptingWrites(); + _requestBody.StopAcceptingReads(); + _responseBody.StopAcceptingWrites(); } terminated = !_keepAlive; @@ -257,14 +294,20 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { try { - // Inform client no more data will ever arrive - ConnectionControl.End(ProduceEndType.SocketShutdownSend); + _disconnectCts.Dispose(); - // Wait for client to either disconnect or send unexpected data - await SocketInput; + // If _requestAborted is set, the connection has already been closed. + if (!_requestAborted) + { + // Inform client no more data will ever arrive + ConnectionControl.End(ProduceEndType.SocketShutdownSend); - // Dispose socket - ConnectionControl.End(ProduceEndType.SocketDisconnect); + // Wait for client to either disconnect or send unexpected data + await SocketInput; + + // Dispose socket + ConnectionControl.End(ProduceEndType.SocketDisconnect); + } } catch (Exception ex) { diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketInput.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketInput.cs index 98910340ab..ae74bffb24 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketInput.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketInput.cs @@ -176,6 +176,22 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } + public void AbortAwaiting() + { + var awaitableState = Interlocked.Exchange( + ref _awaitableState, + _awaitableIsCompleted); + + _awaitableError = new ObjectDisposedException(nameof(SocketInput), "The request was aborted"); + _manualResetEvent.Set(); + + if (awaitableState != _awaitableIsCompleted && + awaitableState != _awaitableIsNotCompleted) + { + Task.Run(awaitableState); + } + } + public SocketInput GetAwaiter() { return this; @@ -199,6 +215,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http else { // THIS IS AN ERROR STATE - ONLY ONE WAITER CAN WAIT + throw new InvalidOperationException("Concurrent reads are not supported."); } } diff --git a/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs index d5893e214b..48db5b9f21 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs @@ -6,8 +6,10 @@ using System.IO; using System.Net; using System.Net.Sockets; using System.Text; +using System.Threading; using System.Threading.Tasks; using Microsoft.AspNet.Http; +using Microsoft.AspNet.Http.Features; using Microsoft.AspNet.Server.Kestrel; using Microsoft.AspNet.Server.Kestrel.Filter; using Microsoft.AspNet.Testing.xunit; @@ -925,6 +927,76 @@ namespace Microsoft.AspNet.Server.KestrelTests } } + [Theory] + [MemberData(nameof(ConnectionFilterData))] + public async Task RequestsCanBeAbortedMidRead(ServiceContext testContext) + { + var readTcs = new TaskCompletionSource(); + var registrationTcs = new TaskCompletionSource(); + var requestId = 0; + + using (var server = new TestServer(async httpContext => + { + requestId++; + + var response = httpContext.Response; + var request = httpContext.Request; + var lifetime = httpContext.Features.Get(); + + lifetime.RequestAborted.Register(() => registrationTcs.TrySetResult(requestId)); + + if (requestId == 1) + { + response.Headers.Clear(); + response.Headers["Content-Length"] = new[] { "5" }; + + await response.WriteAsync("World"); + } + else + { + var readTask = request.Body.CopyToAsync(Stream.Null); + + lifetime.Abort(); + + try + { + await readTask; + } + catch (Exception ex) + { + readTcs.SetException(ex); + throw; + } + } + }, testContext)) + { + using (var connection = new TestConnection()) + { + // Never send the body so CopyToAsync always fails. + await connection.Send( + "POST / HTTP/1.1", + "Content-Length: 5", + "", + "HelloPOST / HTTP/1.1", + "Content-Length: 5", + "", + ""); + + await connection.ReceiveEnd( + "HTTP/1.1 200 OK", + "Content-Length: 5", + "", + "World"); + } + } + + await Assert.ThrowsAsync(async () => await readTcs.Task); + + // The cancellation token for only the last request should be triggered. + var abortedRequestId = await registrationTcs.Task; + Assert.Equal(2, abortedRequestId); + } + private class TestApplicationErrorLogger : ILogger { public int ApplicationErrorsLogged { get; set; } diff --git a/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/FrameFeatureCollection.cs b/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/FrameFeatureCollection.cs index 62b8e19245..e32e54c133 100644 --- a/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/FrameFeatureCollection.cs +++ b/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/FrameFeatureCollection.cs @@ -66,6 +66,7 @@ namespace Microsoft.AspNet.Server.Kestrel.GeneratedCode typeof(IHttpRequestFeature), typeof(IHttpResponseFeature), typeof(IHttpUpgradeFeature), + typeof(IHttpRequestLifetimeFeature), typeof(IHttpConnectionFeature) }; From 874bd29ce192a28ddae7d5f0bee66a5c595fa829 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Tue, 3 Nov 2015 14:02:28 -0800 Subject: [PATCH 0443/1662] Throw IOExceptions instead of ODEs after a request is aborted --- .../Http/Frame.cs | 4 +-- .../Http/FrameRequestStream.cs | 29 +++++++++++++++++++ .../Http/FrameResponseStream.cs | 24 +++++++++++++++ .../TestInput.cs | 4 +++ 4 files changed, 59 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs index 39f4e428ec..521140bfdf 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs @@ -183,8 +183,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http _requestProcessingStopping = true; _requestAborted = true; - _requestBody?.StopAcceptingReads(); - _responseBody?.StopAcceptingWrites(); + _requestBody?.Abort(); + _responseBody?.Abort(); try { diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameRequestStream.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameRequestStream.cs index 8483020ddb..652f2bbd4b 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameRequestStream.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameRequestStream.cs @@ -12,6 +12,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { private readonly MessageBody _body; private bool _stopped; + private bool _aborted; public FrameRequestStream(MessageBody body) { @@ -55,6 +56,10 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { throw new ObjectDisposedException(nameof(FrameRequestStream)); } + if (_aborted) + { + throw new IOException("The request has been aborted."); + } return ReadAsync(buffer, offset, count).GetAwaiter().GetResult(); } @@ -66,6 +71,10 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { throw new ObjectDisposedException(nameof(FrameRequestStream)); } + if (_aborted) + { + throw new IOException("The request has been aborted."); + } var task = ReadAsync(buffer, offset, count, CancellationToken.None, state); if (callback != null) @@ -86,6 +95,10 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { throw new ObjectDisposedException(nameof(FrameRequestStream)); } + if (_aborted) + { + throw new IOException("The request has been aborted."); + } var tcs = new TaskCompletionSource(state); var task = _body.ReadAsync(new ArraySegment(buffer, offset, count), cancellationToken); @@ -111,6 +124,15 @@ namespace Microsoft.AspNet.Server.Kestrel.Http public override Task ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) { + if (_stopped) + { + throw new ObjectDisposedException(nameof(FrameRequestStream)); + } + if (_aborted) + { + throw new IOException("The request has been aborted."); + } + return _body.ReadAsync(new ArraySegment(buffer, offset, count), cancellationToken); } @@ -125,5 +147,12 @@ namespace Microsoft.AspNet.Server.Kestrel.Http // As exampled in EngineTests.ZeroContentLengthNotSetAutomaticallyForCertainStatusCodes _stopped = true; } + + public void Abort() + { + // We don't want to throw an ODE until the app func actually completes. + // If the request is aborted, we throw an IOException instead. + _aborted = true; + } } } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameResponseStream.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameResponseStream.cs index bef3453ad3..25b8a72cfe 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameResponseStream.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameResponseStream.cs @@ -12,6 +12,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { private readonly FrameContext _context; private bool _stopped; + private bool _aborted; public FrameResponseStream(FrameContext context) { @@ -40,6 +41,10 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { throw new ObjectDisposedException(nameof(FrameResponseStream)); } + if (_aborted) + { + throw new IOException("The request has been aborted."); + } _context.FrameControl.Flush(); } @@ -50,6 +55,10 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { throw new ObjectDisposedException(nameof(FrameResponseStream)); } + if (_aborted) + { + throw new IOException("The request has been aborted."); + } return _context.FrameControl.FlushAsync(cancellationToken); } @@ -75,6 +84,10 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { throw new ObjectDisposedException(nameof(FrameResponseStream)); } + if (_aborted) + { + throw new IOException("The request has been aborted."); + } _context.FrameControl.Write(new ArraySegment(buffer, offset, count)); } @@ -85,6 +98,10 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { throw new ObjectDisposedException(nameof(FrameResponseStream)); } + if (_aborted) + { + throw new IOException("The request has been aborted."); + } return _context.FrameControl.WriteAsync(new ArraySegment(buffer, offset, count), cancellationToken); } @@ -95,5 +112,12 @@ namespace Microsoft.AspNet.Server.Kestrel.Http // As exampled in EngineTests.ZeroContentLengthNotSetAutomaticallyForCertainStatusCodes _stopped = true; } + + public void Abort() + { + // We don't want to throw an ODE until the app func actually completes. + // If the request is aborted, we throw an IOException instead. + _aborted = true; + } } } diff --git a/test/Microsoft.AspNet.Server.KestrelTests/TestInput.cs b/test/Microsoft.AspNet.Server.KestrelTests/TestInput.cs index 3db112560c..24cf1cdb77 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/TestInput.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/TestInput.cs @@ -51,6 +51,10 @@ namespace Microsoft.AspNet.Server.KestrelTests { } + public void Abort() + { + } + public void Write(ArraySegment data, Action callback, object state) { } From b73e42b617a84f425a7c43ffd6198e6d539f672e Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Tue, 3 Nov 2015 15:34:29 -0800 Subject: [PATCH 0444/1662] Abort request on any write failure --- .../Http/Connection.cs | 18 +++++- .../Http/SocketOutput.cs | 24 +++++-- .../EngineTests.cs | 64 +++++++++++++++++++ .../SocketOutputTests.cs | 8 +-- 4 files changed, 103 insertions(+), 11 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs index 182bc98654..4e95d3d1ca 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs @@ -42,7 +42,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http _connectionId = Interlocked.Increment(ref _lastConnectionId); _rawSocketInput = new SocketInput(Memory2); - _rawSocketOutput = new SocketOutput(Thread, _socket, _connectionId, Log); + _rawSocketOutput = new SocketOutput(Thread, _socket, this, _connectionId, Log); } public void Start() @@ -100,6 +100,20 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } + public void Abort() + { + if (_frame != null) + { + // Frame.Abort calls user code while this method is always + // called from a libuv thread. + ThreadPool.QueueUserWorkItem(state => + { + var connection = (Connection)this; + connection._frame.Abort(); + }, this); + } + } + private void ApplyConnectionFilter() { var filteredStreamAdapter = new FilteredStreamAdapter(_filterContext.Connection, Memory2, Log); @@ -157,7 +171,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http if (errorDone) { - _frame.Abort(); + Abort(); } } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs index d2534206e1..d1e353388f 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using System.Diagnostics; +using System.IO; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNet.Server.Kestrel.Infrastructure; @@ -18,6 +19,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http private readonly KestrelThread _thread; private readonly UvStreamHandle _socket; + private readonly Connection _connection; private readonly long _connectionId; private readonly IKestrelTrace _log; @@ -33,10 +35,16 @@ namespace Microsoft.AspNet.Server.Kestrel.Http private WriteContext _nextWriteContext; private readonly Queue> _tasksPending; - public SocketOutput(KestrelThread thread, UvStreamHandle socket, long connectionId, IKestrelTrace log) + public SocketOutput( + KestrelThread thread, + UvStreamHandle socket, + Connection connection, + long connectionId, + IKestrelTrace log) { _thread = thread; _socket = socket; + _connection = connection; _connectionId = connectionId; _log = log; _tasksPending = new Queue>(); @@ -176,10 +184,16 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { _log.ConnectionWriteCallback(_connectionId, status); + if (error != null) + { + _lastWriteError = new IOException(error.Message, error); + + // Abort the connection for any failed write. + _connection.Abort(); + } + lock (_lockObj) { - _lastWriteError = error; - if (_nextWriteContext != null) { ScheduleWrite(); @@ -208,7 +222,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http _numBytesPreCompleted += bytesToWrite; bytesLeftToBuffer -= bytesToWrite; - if (error == null) + if (_lastWriteError == null) { ThreadPool.QueueUserWorkItem( (o) => ((TaskCompletionSource)o).SetResult(null), @@ -218,7 +232,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { // error is closure captured ThreadPool.QueueUserWorkItem( - (o) => ((TaskCompletionSource)o).SetException(error), + (o) => ((TaskCompletionSource)o).SetException(_lastWriteError), tcs); } } diff --git a/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs index 48db5b9f21..f19b2b3077 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs @@ -967,6 +967,8 @@ namespace Microsoft.AspNet.Server.KestrelTests readTcs.SetException(ex); throw; } + + readTcs.SetCanceled(); } }, testContext)) { @@ -997,6 +999,68 @@ namespace Microsoft.AspNet.Server.KestrelTests Assert.Equal(2, abortedRequestId); } + [Theory] + [MemberData(nameof(ConnectionFilterData))] + public async Task FailedWritesResultInAbortedRequest(ServiceContext testContext) + { + var writeTcs = new TaskCompletionSource(); + var registrationWh = new ManualResetEventSlim(); + var connectionCloseWh = new ManualResetEventSlim(); + + using (var server = new TestServer(async httpContext => + { + var response = httpContext.Response; + var request = httpContext.Request; + var lifetime = httpContext.Features.Get(); + + lifetime.RequestAborted.Register(() => registrationWh.Set()); + + await request.Body.CopyToAsync(Stream.Null); + connectionCloseWh.Wait(); + + response.Headers.Clear(); + response.Headers["Content-Length"] = new[] { "5" }; + + try + { + // Ensure write is long enough to disable write-behind buffering + for (int i = 0; i < 10; i++) + { + await response.WriteAsync(new string('a', 65537)); + } + } + catch (Exception ex) + { + writeTcs.SetException(ex); + + // Give a chance for RequestAborted to trip before the app completes + registrationWh.Wait(1000); + + throw; + } + + writeTcs.SetCanceled(); + }, testContext)) + { + using (var connection = new TestConnection()) + { + await connection.Send( + "POST / HTTP/1.1", + "Content-Length: 5", + "", + "Hello"); + // Don't wait to receive the response. Just close the socket. + } + + connectionCloseWh.Set(); + + // Write failed + await Assert.ThrowsAsync(async () => await writeTcs.Task); + // RequestAborted tripped + Assert.True(registrationWh.Wait(200)); + } + } + private class TestApplicationErrorLogger : ILogger { public int ApplicationErrorsLogged { get; set; } diff --git a/test/Microsoft.AspNet.Server.KestrelTests/SocketOutputTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/SocketOutputTests.cs index d8d4f5cee7..69224073dc 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/SocketOutputTests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/SocketOutputTests.cs @@ -40,7 +40,7 @@ namespace Microsoft.AspNet.Server.KestrelTests var kestrelThread = kestrelEngine.Threads[0]; var socket = new MockSocket(kestrelThread.Loop.ThreadId, new TestKestrelTrace()); var trace = new KestrelTrace(new TestKestrelTrace()); - var socketOutput = new SocketOutput(kestrelThread, socket, 0, trace); + var socketOutput = new SocketOutput(kestrelThread, socket, null, 0, trace); // I doubt _maxBytesPreCompleted will ever be over a MB. If it is, we should change this test. var bufferSize = 1048576; @@ -85,7 +85,7 @@ namespace Microsoft.AspNet.Server.KestrelTests var kestrelThread = kestrelEngine.Threads[0]; var socket = new MockSocket(kestrelThread.Loop.ThreadId, new TestKestrelTrace()); var trace = new KestrelTrace(new TestKestrelTrace()); - var socketOutput = new SocketOutput(kestrelThread, socket, 0, trace); + var socketOutput = new SocketOutput(kestrelThread, socket, null, 0, trace); var bufferSize = maxBytesPreCompleted; var buffer = new ArraySegment(new byte[bufferSize], 0, bufferSize); @@ -140,7 +140,7 @@ namespace Microsoft.AspNet.Server.KestrelTests var kestrelThread = kestrelEngine.Threads[0]; var socket = new MockSocket(kestrelThread.Loop.ThreadId, new TestKestrelTrace()); var trace = new KestrelTrace(new TestKestrelTrace()); - var socketOutput = new SocketOutput(kestrelThread, socket, 0, trace); + var socketOutput = new SocketOutput(kestrelThread, socket, null, 0, trace); var bufferSize = maxBytesPreCompleted; @@ -219,7 +219,7 @@ namespace Microsoft.AspNet.Server.KestrelTests var kestrelThread = kestrelEngine.Threads[0]; var socket = new MockSocket(kestrelThread.Loop.ThreadId, new TestKestrelTrace()); var trace = new KestrelTrace(new TestKestrelTrace()); - var socketOutput = new SocketOutput(kestrelThread, socket, 0, trace); + var socketOutput = new SocketOutput(kestrelThread, socket, null, 0, trace); var bufferSize = maxBytesPreCompleted; var buffer = new ArraySegment(new byte[bufferSize], 0, bufferSize); From f7a5c38f65182814eefd5d6c5008d48704129dcd Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Mon, 16 Nov 2015 15:10:30 -0800 Subject: [PATCH 0445/1662] Follow common pattern for implementing IHttpRequestLifetimeFeature --- .../Http/Frame.FeatureCollection.cs | 14 ++++++++++++-- src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs | 4 +++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.FeatureCollection.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.FeatureCollection.cs index b14f968f16..f0406a7aa5 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.FeatureCollection.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.FeatureCollection.cs @@ -231,6 +231,18 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } + CancellationToken IHttpRequestLifetimeFeature.RequestAborted + { + get + { + return RequestAborted; + } + set + { + RequestAborted = value; + } + } + bool IHttpResponseFeature.HasStarted { get { return HasResponseStarted; } @@ -263,8 +275,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Http bool IHttpConnectionFeature.IsLocal { get; set; } - CancellationToken IHttpRequestLifetimeFeature.RequestAborted { get; set; } - object IFeatureCollection.this[Type key] { get { return FastFeatureGet(key); } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs index 521140bfdf..16fa98eae7 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs @@ -89,6 +89,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http public Stream DuplexStream { get; set; } + public CancellationToken RequestAborted { get; set; } + public bool HasResponseStarted { get { return _responseStarted; } @@ -241,7 +243,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http DuplexStream = new FrameDuplexStream(RequestBody, ResponseBody); _requestAbortCts = CancellationTokenSource.CreateLinkedTokenSource(_disconnectCts.Token); - ((IHttpRequestLifetimeFeature)this).RequestAborted = _requestAbortCts.Token; + RequestAborted = _requestAbortCts.Token; var httpContext = HttpContextFactory.Create(this); try From 4dc4346fcaa52832241261c10f4d3a5623c38a3b Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Sun, 1 Nov 2015 07:16:22 +0000 Subject: [PATCH 0446/1662] Reduce GetString allocs and conversions --- .../Http/Frame.cs | 26 ++- .../Infrastructure/MemoryPoolIterator2.cs | 98 --------- .../MemoryPoolIterator2Extenstions.cs | 207 ++++++++++++++++++ .../AsciiDecoder.cs | 116 ++++++++++ .../UrlPathDecoder.cs | 8 +- 5 files changed, 342 insertions(+), 113 deletions(-) create mode 100644 src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolIterator2Extenstions.cs create mode 100644 test/Microsoft.AspNet.Server.KestrelTests/AsciiDecoder.cs diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs index c13826964b..b170af9fc8 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs @@ -629,7 +629,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { return false; } - var method = begin.GetString(scan); + var method = begin.GetAsciiString(scan); scan.Take(); begin = scan; @@ -653,7 +653,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { return false; } - queryString = begin.GetString(scan); + queryString = begin.GetAsciiString(scan); } scan.Take(); @@ -662,7 +662,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { return false; } - var httpVersion = begin.GetString(scan); + var httpVersion = begin.GetAsciiString(scan); scan.Take(); if (scan.Take() != '\n') @@ -670,12 +670,21 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return false; } + // URIs are always encoded/escaped to ASCII https://tools.ietf.org/html/rfc3986#page-11 + // Multibyte Internationalized Resource Identifiers (IRIs) are first converted to utf8; + // then encoded/escaped to ASCII https://www.ietf.org/rfc/rfc3987.txt "Mapping of IRIs to URIs" + string requestUrlPath; if (needDecode) { + // URI was encoded, unescape and then parse as utf8 pathEnd = UrlPathDecoder.Unescape(pathBegin, pathEnd); + requestUrlPath = pathBegin.GetUtf8String(pathEnd); + } + else + { + // URI wasn't encoded, parse as ASCII + requestUrlPath = pathBegin.GetAsciiString(pathEnd); } - - var requestUrlPath = pathBegin.GetString(pathEnd); consumed = scan; Method = method; @@ -691,11 +700,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } - static string GetString(ArraySegment range, int startIndex, int endIndex) - { - return Encoding.UTF8.GetString(range.Array, range.Offset + startIndex, endIndex - startIndex); - } - public static bool TakeMessageHeaders(SocketInput input, FrameRequestHeaders requestHeaders) { var scan = input.ConsumingStart(); @@ -787,7 +791,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } var name = beginName.GetArraySegment(endName); - var value = beginValue.GetString(endValue); + var value = beginValue.GetAsciiString(endValue); if (wrapping) { value = value.Replace("\r\n", " "); diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolIterator2.cs b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolIterator2.cs index 7de5c7fb10..9e69b188ad 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolIterator2.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolIterator2.cs @@ -4,7 +4,6 @@ using System; using System.Linq; using System.Numerics; -using System.Text; namespace Microsoft.AspNet.Server.Kestrel.Infrastructure { @@ -22,8 +21,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure /// private static Vector _dotIndex = new Vector(Enumerable.Range(0, Vector.Count).Select(x => (byte)-x).ToArray()); - private static Encoding _utf8 = Encoding.UTF8; - private MemoryPoolBlock2 _block; private int _index; @@ -488,101 +485,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure } } - public string GetString(MemoryPoolIterator2 end) - { - if (IsDefault || end.IsDefault) - { - return default(string); - } - if (end._block == _block) - { - return _utf8.GetString(_block.Array, _index, end._index - _index); - } - - var decoder = _utf8.GetDecoder(); - - var length = GetLength(end); - var charLength = length * 2; - var chars = new char[charLength]; - var charIndex = 0; - - var block = _block; - var index = _index; - var remaining = length; - while (true) - { - int bytesUsed; - int charsUsed; - bool completed; - var following = block.End - index; - if (remaining <= following) - { - decoder.Convert( - block.Array, - index, - remaining, - chars, - charIndex, - charLength - charIndex, - true, - out bytesUsed, - out charsUsed, - out completed); - return new string(chars, 0, charIndex + charsUsed); - } - else if (block.Next == null) - { - decoder.Convert( - block.Array, - index, - following, - chars, - charIndex, - charLength - charIndex, - true, - out bytesUsed, - out charsUsed, - out completed); - return new string(chars, 0, charIndex + charsUsed); - } - else - { - decoder.Convert( - block.Array, - index, - following, - chars, - charIndex, - charLength - charIndex, - false, - out bytesUsed, - out charsUsed, - out completed); - charIndex += charsUsed; - remaining -= following; - block = block.Next; - index = block.Start; - } - } - } - - public ArraySegment GetArraySegment(MemoryPoolIterator2 end) - { - if (IsDefault || end.IsDefault) - { - return default(ArraySegment); - } - if (end._block == _block) - { - return new ArraySegment(_block.Array, _index, end._index - _index); - } - - var length = GetLength(end); - var array = new byte[length]; - CopyTo(array, 0, length, out length); - return new ArraySegment(array, 0, length); - } - public MemoryPoolIterator2 CopyTo(byte[] array, int offset, int count, out int actual) { if (IsDefault) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolIterator2Extenstions.cs b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolIterator2Extenstions.cs new file mode 100644 index 0000000000..d46eee028f --- /dev/null +++ b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolIterator2Extenstions.cs @@ -0,0 +1,207 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Text; + +namespace Microsoft.AspNet.Server.Kestrel.Infrastructure +{ + public static class MemoryPoolIterator2Extenstions + { + private const int _maxStackAllocBytes = 16384; + + private static Encoding _utf8 = Encoding.UTF8; + + private static unsafe string GetAsciiStringStack(byte[] input, int inputOffset, int length) + { + // avoid declaring other local vars, or doing work with stackalloc + // to prevent the .locals init cil flag , see: https://github.com/dotnet/coreclr/issues/1279 + char* output = stackalloc char[length]; + + return GetAsciiStringImplementation(output, input, inputOffset, length); + } + private static unsafe string GetAsciiStringImplementation(char* output, byte[] input, int inputOffset, int length) + { + for (var i = 0; i < length; i++) + { + output[i] = (char)input[inputOffset + i]; + } + + return new string(output, 0, length); + } + + private static unsafe string GetAsciiStringStack(MemoryPoolBlock2 start, MemoryPoolIterator2 end, int inputOffset, int length) + { + // avoid declaring other local vars, or doing work with stackalloc + // to prevent the .locals init cil flag , see: https://github.com/dotnet/coreclr/issues/1279 + char* output = stackalloc char[length]; + + return GetAsciiStringImplementation(output, start, end, inputOffset, length); + } + + private unsafe static string GetAsciiStringHeap(MemoryPoolBlock2 start, MemoryPoolIterator2 end, int inputOffset, int length) + { + var buffer = new char[length]; + + fixed (char* output = buffer) + { + return GetAsciiStringImplementation(output, start, end, inputOffset, length); + } + } + + private static unsafe string GetAsciiStringImplementation(char* output, MemoryPoolBlock2 start, MemoryPoolIterator2 end, int inputOffset, int length) + { + var outputOffset = 0; + var block = start; + var remaining = length; + + var endBlock = end.Block; + var endIndex = end.Index; + + while (true) + { + int following = (block != endBlock ? block.End : endIndex) - inputOffset; + + if (following > 0) + { + var input = block.Array; + for (var i = 0; i < following; i++) + { + output[i + outputOffset] = (char)input[i + inputOffset]; + } + + remaining -= following; + outputOffset += following; + } + + if (remaining == 0) + { + return new string(output, 0, length); + } + + block = block.Next; + inputOffset = block.Start; + } + } + + public static string GetAsciiString(this MemoryPoolIterator2 start, MemoryPoolIterator2 end) + { + if (start.IsDefault || end.IsDefault) + { + return default(string); + } + + var length = start.GetLength(end); + + // Bytes out of the range of ascii are treated as "opaque data" + // and kept in string as a char value that casts to same input byte value + // https://tools.ietf.org/html/rfc7230#section-3.2.4 + if (end.Block == start.Block) + { + return GetAsciiStringStack(start.Block.Array, start.Index, length); + } + + if (length > _maxStackAllocBytes) + { + return GetAsciiStringHeap(start.Block, end, start.Index, length); + } + + return GetAsciiStringStack(start.Block, end, start.Index, length); + } + + public static string GetUtf8String(this MemoryPoolIterator2 start, MemoryPoolIterator2 end) + { + if (start.IsDefault || end.IsDefault) + { + return default(string); + } + if (end.Block == start.Block) + { + return _utf8.GetString(start.Block.Array, start.Index, end.Index - start.Index); + } + + var decoder = _utf8.GetDecoder(); + + var length = start.GetLength(end); + var charLength = length * 2; + var chars = new char[charLength]; + var charIndex = 0; + + var block = start.Block; + var index = start.Index; + var remaining = length; + while (true) + { + int bytesUsed; + int charsUsed; + bool completed; + var following = block.End - index; + if (remaining <= following) + { + decoder.Convert( + block.Array, + index, + remaining, + chars, + charIndex, + charLength - charIndex, + true, + out bytesUsed, + out charsUsed, + out completed); + return new string(chars, 0, charIndex + charsUsed); + } + else if (block.Next == null) + { + decoder.Convert( + block.Array, + index, + following, + chars, + charIndex, + charLength - charIndex, + true, + out bytesUsed, + out charsUsed, + out completed); + return new string(chars, 0, charIndex + charsUsed); + } + else + { + decoder.Convert( + block.Array, + index, + following, + chars, + charIndex, + charLength - charIndex, + false, + out bytesUsed, + out charsUsed, + out completed); + charIndex += charsUsed; + remaining -= following; + block = block.Next; + index = block.Start; + } + } + } + + public static ArraySegment GetArraySegment(this MemoryPoolIterator2 start, MemoryPoolIterator2 end) + { + if (start.IsDefault || end.IsDefault) + { + return default(ArraySegment); + } + if (end.Block == start.Block) + { + return new ArraySegment(start.Block.Array, start.Index, end.Index - start.Index); + } + + var length = start.GetLength(end); + var array = new byte[length]; + start.CopyTo(array, 0, length, out length); + return new ArraySegment(array, 0, length); + } + } +} diff --git a/test/Microsoft.AspNet.Server.KestrelTests/AsciiDecoder.cs b/test/Microsoft.AspNet.Server.KestrelTests/AsciiDecoder.cs new file mode 100644 index 0000000000..26c034d2d5 --- /dev/null +++ b/test/Microsoft.AspNet.Server.KestrelTests/AsciiDecoder.cs @@ -0,0 +1,116 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Linq; +using Microsoft.AspNet.Server.Kestrel.Infrastructure; +using Xunit; + +namespace Microsoft.AspNet.Server.KestrelTests +{ + public class AsciiDecoderTests + { + [Fact] + private void FullByteRangeSupported() + { + var byteRange = Enumerable.Range(0, 255).Select(x => (byte)x).ToArray(); + + var mem = MemoryPoolBlock2.Create(new ArraySegment(byteRange), IntPtr.Zero, null, null); + mem.End = byteRange.Length; + + var begin = mem.GetIterator(); + var end = GetIterator(begin, byteRange.Length); + + var s = begin.GetAsciiString(end); + + Assert.Equal(s.Length, byteRange.Length); + + for (var i = 0; i < byteRange.Length; i++) + { + var sb = (byte)s[i]; + var b = byteRange[i]; + + Assert.Equal(sb, b); + } + } + + [Fact] + private void MultiBlockProducesCorrectResults() + { + var byteRange = Enumerable.Range(0, 512 + 64).Select(x => (byte)x).ToArray(); + var expectedByteRange = byteRange + .Concat(byteRange) + .Concat(byteRange) + .Concat(byteRange) + .ToArray(); + + var mem0 = MemoryPoolBlock2.Create(new ArraySegment(byteRange), IntPtr.Zero, null, null); + var mem1 = MemoryPoolBlock2.Create(new ArraySegment(byteRange), IntPtr.Zero, null, null); + var mem2 = MemoryPoolBlock2.Create(new ArraySegment(byteRange), IntPtr.Zero, null, null); + var mem3 = MemoryPoolBlock2.Create(new ArraySegment(byteRange), IntPtr.Zero, null, null); + mem0.End = byteRange.Length; + mem1.End = byteRange.Length; + mem2.End = byteRange.Length; + mem3.End = byteRange.Length; + + mem0.Next = mem1; + mem1.Next = mem2; + mem2.Next = mem3; + + var begin = mem0.GetIterator(); + var end = GetIterator(begin, expectedByteRange.Length); + + var s = begin.GetAsciiString(end); + + Assert.Equal(s.Length, expectedByteRange.Length); + + for (var i = 0; i < expectedByteRange.Length; i++) + { + var sb = (byte)s[i]; + var b = expectedByteRange[i]; + + Assert.Equal(sb, b); + } + } + + [Fact] + private void HeapAllocationProducesCorrectResults() + { + var byteRange = Enumerable.Range(0, 16384 + 64).Select(x => (byte)x).ToArray(); + var expectedByteRange = byteRange.Concat(byteRange).ToArray(); + + var mem0 = MemoryPoolBlock2.Create(new ArraySegment(byteRange), IntPtr.Zero, null, null); + var mem1 = MemoryPoolBlock2.Create(new ArraySegment(byteRange), IntPtr.Zero, null, null); + mem0.End = byteRange.Length; + mem1.End = byteRange.Length; + + mem0.Next = mem1; + + var begin = mem0.GetIterator(); + var end = GetIterator(begin, expectedByteRange.Length); + + var s = begin.GetAsciiString(end); + + Assert.Equal(s.Length, expectedByteRange.Length); + + for (var i = 0; i < expectedByteRange.Length; i++) + { + var sb = (byte)s[i]; + var b = expectedByteRange[i]; + + Assert.Equal(sb, b); + } + } + + private MemoryPoolIterator2 GetIterator(MemoryPoolIterator2 begin, int displacement) + { + var result = begin; + for (int i = 0; i < displacement; ++i) + { + result.Take(); + } + + return result; + } + } +} diff --git a/test/Microsoft.AspNet.Server.KestrelTests/UrlPathDecoder.cs b/test/Microsoft.AspNet.Server.KestrelTests/UrlPathDecoder.cs index 928fc84a05..02769fd01f 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/UrlPathDecoder.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/UrlPathDecoder.cs @@ -115,7 +115,7 @@ namespace Microsoft.AspNet.Server.KestrelTests var end = GetIterator(begin, rawLength); var end2 = UrlPathDecoder.Unescape(begin, end); - var result = begin.GetString(end2); + var result = begin.GetUtf8String(end2); Assert.Equal(expectLength, result.Length); Assert.Equal(expect, result); @@ -147,7 +147,7 @@ namespace Microsoft.AspNet.Server.KestrelTests var end = GetIterator(begin, raw.Length); var result = UrlPathDecoder.Unescape(begin, end); - Assert.Equal(expect, begin.GetString(result)); + Assert.Equal(expect, begin.GetUtf8String(result)); } private void PositiveAssert(string raw) @@ -156,7 +156,7 @@ namespace Microsoft.AspNet.Server.KestrelTests var end = GetIterator(begin, raw.Length); var result = UrlPathDecoder.Unescape(begin, end); - Assert.NotEqual(raw.Length, begin.GetString(result).Length); + Assert.NotEqual(raw.Length, begin.GetUtf8String(result).Length); } private void NegativeAssert(string raw) @@ -165,7 +165,7 @@ namespace Microsoft.AspNet.Server.KestrelTests var end = GetIterator(begin, raw.Length); var resultEnd = UrlPathDecoder.Unescape(begin, end); - var result = begin.GetString(resultEnd); + var result = begin.GetUtf8String(resultEnd); Assert.Equal(raw, result); } } From 82b1238b27e7819635c22d8662c53226d8f28a3b Mon Sep 17 00:00:00 2001 From: Doug Bunting Date: Tue, 17 Nov 2015 11:05:58 -0800 Subject: [PATCH 0447/1662] Explicitly choose Mono 4.0.5 - avoids future problems related to aspnet/External#48 - e.g. when Travis updates default Mono version in `csharp` bundle --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index e5af3cd231..08e745f9ae 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,5 +15,7 @@ install: - make install - export LD_LIBRARY_PATH="$HOME/libuvinstall/lib" - cd $OLDPWD +mono: + - 4.0.5 script: - ./build.sh --quiet verify From 7e8a4059174c45c404ad67d2dbd78ef135f56e1a Mon Sep 17 00:00:00 2001 From: Doug Bunting Date: Tue, 17 Nov 2015 16:33:20 -0800 Subject: [PATCH 0448/1662] Specify all required packages in `.travis.yml` - most seem to be included in current Travis bundles but Trusty support is in Beta --- .travis.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 08e745f9ae..e9a98166a3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,7 +4,12 @@ dist: trusty addons: apt: packages: - - libunwind8 + - gettext + - libcurl4-openssl-dev + - libicu-dev + - libssl-dev + - libunwind8 + - zlib1g env: - KOREBUILD_DNU_RESTORE_CORECLR=true KOREBUILD_TEST_DNXCORE=true install: From bd30f28dfdca90caf68f72e790cd6747af1a6b93 Mon Sep 17 00:00:00 2001 From: Master T Date: Sat, 14 Nov 2015 11:00:50 +0100 Subject: [PATCH 0449/1662] Implement client certificate authentication --- .../ClientCertificateMode.cs | 12 ++ .../ClientCertificateValidationCallback.cs | 11 + .../HttpsApplicationBuilderExtensions.cs | 7 +- .../HttpsConnectionFilter.cs | 80 ++++++- .../HttpsConnectionFilterOptions.cs | 19 ++ .../Filter/ConnectionFilterContext.cs | 3 +- .../Filter/IConnectionFilter.cs | 2 + .../Filter/NoOpConnectionFilter.cs | 4 + .../Http/Connection.cs | 2 +- .../Http/Frame.cs | 26 ++- .../ConnectionFilterTests.cs | 6 + .../HttpsConnectionFilterTests.cs | 197 +++++++++++++++++- 12 files changed, 345 insertions(+), 24 deletions(-) create mode 100644 src/Microsoft.AspNet.Server.Kestrel.Https/ClientCertificateMode.cs create mode 100644 src/Microsoft.AspNet.Server.Kestrel.Https/ClientCertificateValidationCallback.cs create mode 100644 src/Microsoft.AspNet.Server.Kestrel.Https/HttpsConnectionFilterOptions.cs diff --git a/src/Microsoft.AspNet.Server.Kestrel.Https/ClientCertificateMode.cs b/src/Microsoft.AspNet.Server.Kestrel.Https/ClientCertificateMode.cs new file mode 100644 index 0000000000..34e8b839eb --- /dev/null +++ b/src/Microsoft.AspNet.Server.Kestrel.Https/ClientCertificateMode.cs @@ -0,0 +1,12 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +namespace Microsoft.AspNet.Server.Kestrel.Https +{ + public enum ClientCertificateMode + { + NoCertificate, + AllowCertificate, + RequireCertificate + } +} diff --git a/src/Microsoft.AspNet.Server.Kestrel.Https/ClientCertificateValidationCallback.cs b/src/Microsoft.AspNet.Server.Kestrel.Https/ClientCertificateValidationCallback.cs new file mode 100644 index 0000000000..12616900cc --- /dev/null +++ b/src/Microsoft.AspNet.Server.Kestrel.Https/ClientCertificateValidationCallback.cs @@ -0,0 +1,11 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System.Net.Security; +using System.Security.Cryptography.X509Certificates; + +namespace Microsoft.AspNet.Server.Kestrel.Https +{ + public delegate bool ClientCertificateValidationCallback( + X509Certificate2 certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors); +} diff --git a/src/Microsoft.AspNet.Server.Kestrel.Https/HttpsApplicationBuilderExtensions.cs b/src/Microsoft.AspNet.Server.Kestrel.Https/HttpsApplicationBuilderExtensions.cs index 844435c152..c595376aa9 100644 --- a/src/Microsoft.AspNet.Server.Kestrel.Https/HttpsApplicationBuilderExtensions.cs +++ b/src/Microsoft.AspNet.Server.Kestrel.Https/HttpsApplicationBuilderExtensions.cs @@ -11,6 +11,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Https public static class HttpsApplicationBuilderExtensions { public static IApplicationBuilder UseKestrelHttps(this IApplicationBuilder app, X509Certificate2 cert) + { + return app.UseKestrelHttps(new HttpsConnectionFilterOptions { ServerCertificate = cert}); + } + + public static IApplicationBuilder UseKestrelHttps(this IApplicationBuilder app, HttpsConnectionFilterOptions options) { var serverInfo = app.ServerFeatures.Get(); @@ -21,7 +26,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Https var prevFilter = serverInfo.ConnectionFilter ?? new NoOpConnectionFilter(); - serverInfo.ConnectionFilter = new HttpsConnectionFilter(cert, prevFilter); + serverInfo.ConnectionFilter = new HttpsConnectionFilter(options, prevFilter); return app; } diff --git a/src/Microsoft.AspNet.Server.Kestrel.Https/HttpsConnectionFilter.cs b/src/Microsoft.AspNet.Server.Kestrel.Https/HttpsConnectionFilter.cs index 08cad7161d..e66fa4b3c5 100644 --- a/src/Microsoft.AspNet.Server.Kestrel.Https/HttpsConnectionFilter.cs +++ b/src/Microsoft.AspNet.Server.Kestrel.Https/HttpsConnectionFilter.cs @@ -3,29 +3,37 @@ using System; using System.Net.Security; +using System.Security.Authentication; using System.Security.Cryptography.X509Certificates; using System.Threading.Tasks; +using Microsoft.AspNet.Http.Features; +using Microsoft.AspNet.Http.Features.Internal; using Microsoft.AspNet.Server.Kestrel.Filter; namespace Microsoft.AspNet.Server.Kestrel.Https { public class HttpsConnectionFilter : IConnectionFilter { - private readonly X509Certificate2 _cert; + private readonly X509Certificate2 _serverCert; + private readonly ClientCertificateMode _clientCertMode; + private readonly ClientCertificateValidationCallback _clientValidationCallback; private readonly IConnectionFilter _previous; + private X509Certificate2 _clientCert; - public HttpsConnectionFilter(X509Certificate2 cert, IConnectionFilter previous) + public HttpsConnectionFilter(HttpsConnectionFilterOptions options, IConnectionFilter previous) { - if (cert == null) + if (options.ServerCertificate == null) { - throw new ArgumentNullException(nameof(cert)); + throw new ArgumentNullException(nameof(options.ServerCertificate)); } if (previous == null) { throw new ArgumentNullException(nameof(previous)); } - _cert = cert; + _serverCert = options.ServerCertificate; + _clientCertMode = options.ClientCertificateMode; + _clientValidationCallback = options.ClientCertificateValidation; _previous = previous; } @@ -35,10 +43,68 @@ namespace Microsoft.AspNet.Server.Kestrel.Https if (string.Equals(context.Address.Scheme, "https", StringComparison.OrdinalIgnoreCase)) { - var sslStream = new SslStream(context.Connection); - await sslStream.AuthenticateAsServerAsync(_cert); + SslStream sslStream; + if (_clientCertMode == ClientCertificateMode.NoCertificate) + { + sslStream = new SslStream(context.Connection); + await sslStream.AuthenticateAsServerAsync(_serverCert); + } + else + { + sslStream = new SslStream(context.Connection, leaveInnerStreamOpen: false, + userCertificateValidationCallback: (sender, certificate, chain, sslPolicyErrors) => + { + if (sslPolicyErrors.HasFlag(SslPolicyErrors.RemoteCertificateNotAvailable)) + { + return _clientCertMode != ClientCertificateMode.RequireCertificate; + } + + + if (_clientValidationCallback == null) + { + if (sslPolicyErrors != SslPolicyErrors.None) + { + return false; + } + } +#if DOTNET5_4 + // conversion X509Certificate to X509Certificate2 not supported + // https://github.com/dotnet/corefx/issues/4510 + X509Certificate2 certificate2 = null; + return false; +#else + X509Certificate2 certificate2 = certificate as X509Certificate2 ?? + new X509Certificate2(certificate); + +#endif + if (_clientValidationCallback != null) + { + if (!_clientValidationCallback(certificate2, chain, sslPolicyErrors)) + { + return false; + } + } + + _clientCert = certificate2; + return true; + }); + await sslStream.AuthenticateAsServerAsync(_serverCert, clientCertificateRequired: true, + enabledSslProtocols: SslProtocols.Tls12 | SslProtocols.Tls11 | SslProtocols.Tls, + checkCertificateRevocation: false); + } context.Connection = sslStream; } } + + public void PrepareRequest(IFeatureCollection features) + { + _previous.PrepareRequest(features); + + if (_clientCert != null) + { + features.Set( + new TlsConnectionFeature { ClientCertificate = _clientCert }); + } + } } } diff --git a/src/Microsoft.AspNet.Server.Kestrel.Https/HttpsConnectionFilterOptions.cs b/src/Microsoft.AspNet.Server.Kestrel.Https/HttpsConnectionFilterOptions.cs new file mode 100644 index 0000000000..62c513c216 --- /dev/null +++ b/src/Microsoft.AspNet.Server.Kestrel.Https/HttpsConnectionFilterOptions.cs @@ -0,0 +1,19 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System.Security.Cryptography.X509Certificates; + +namespace Microsoft.AspNet.Server.Kestrel.Https +{ + public class HttpsConnectionFilterOptions + { + public HttpsConnectionFilterOptions() + { + ClientCertificateMode = ClientCertificateMode.NoCertificate; + } + + public X509Certificate2 ServerCertificate { get; set; } + public ClientCertificateMode ClientCertificateMode { get; set; } + public ClientCertificateValidationCallback ClientCertificateValidation { get; set; } + } +} diff --git a/src/Microsoft.AspNet.Server.Kestrel/Filter/ConnectionFilterContext.cs b/src/Microsoft.AspNet.Server.Kestrel/Filter/ConnectionFilterContext.cs index 937e92bec3..278ca58254 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Filter/ConnectionFilterContext.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Filter/ConnectionFilterContext.cs @@ -2,12 +2,13 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.IO; +using Microsoft.AspNet.Http.Features; namespace Microsoft.AspNet.Server.Kestrel.Filter { public class ConnectionFilterContext { public ServerAddress Address { get; set; } - public Stream Connection { get; set; } + public Stream Connection { get; set; } } } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Filter/IConnectionFilter.cs b/src/Microsoft.AspNet.Server.Kestrel/Filter/IConnectionFilter.cs index accaa3b9d9..8c4f827be9 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Filter/IConnectionFilter.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Filter/IConnectionFilter.cs @@ -2,11 +2,13 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Threading.Tasks; +using Microsoft.AspNet.Http.Features; namespace Microsoft.AspNet.Server.Kestrel.Filter { public interface IConnectionFilter { Task OnConnection(ConnectionFilterContext context); + void PrepareRequest(IFeatureCollection features); } } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Filter/NoOpConnectionFilter.cs b/src/Microsoft.AspNet.Server.Kestrel/Filter/NoOpConnectionFilter.cs index b1217d3034..aac76ec34e 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Filter/NoOpConnectionFilter.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Filter/NoOpConnectionFilter.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Threading.Tasks; +using Microsoft.AspNet.Http.Features; using Microsoft.AspNet.Server.Kestrel.Infrastructure; namespace Microsoft.AspNet.Server.Kestrel.Filter @@ -12,5 +13,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Filter { return TaskUtilities.CompletedTask; } + + public void PrepareRequest(IFeatureCollection features) + {} } } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs index 4e95d3d1ca..42d8aeb30a 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs @@ -177,7 +177,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http private Frame CreateFrame() { - return new Frame(this, _remoteEndPoint, _localEndPoint); + return new Frame(this, _remoteEndPoint, _localEndPoint, ConnectionFilter); } void IConnectionControl.Pause() diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs index 4b889c710e..0edaeb3fee 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs @@ -11,6 +11,7 @@ using System.Threading; using System.Threading.Tasks; using Microsoft.AspNet.Http; using Microsoft.AspNet.Http.Features; +using Microsoft.AspNet.Server.Kestrel.Filter; using Microsoft.AspNet.Server.Kestrel.Infrastructure; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Primitives; @@ -55,19 +56,22 @@ namespace Microsoft.AspNet.Server.Kestrel.Http private readonly IPEndPoint _localEndPoint; private readonly IPEndPoint _remoteEndPoint; + private readonly IConnectionFilter _connectionFilter; public Frame(ConnectionContext context) - : this(context, remoteEndPoint: null, localEndPoint: null) + : this(context, remoteEndPoint: null, localEndPoint: null, connectionFilter: null) { } public Frame(ConnectionContext context, IPEndPoint remoteEndPoint, - IPEndPoint localEndPoint) + IPEndPoint localEndPoint, + IConnectionFilter connectionFilter) : base(context) { _remoteEndPoint = remoteEndPoint; _localEndPoint = localEndPoint; + _connectionFilter = connectionFilter; FrameControl = this; Reset(); @@ -140,6 +144,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http httpConnectionFeature.IsLocal = false; } + _connectionFilter?.PrepareRequest(this); + _requestAbortCts?.Dispose(); } @@ -272,7 +278,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http // If _requestAbort is set, the connection has already been closed. if (!_requestAborted) { - await ProduceEnd(); + await ProduceEnd(); // Finish reading the request body in case the app did not. await messageBody.Consume(); @@ -301,15 +307,15 @@ namespace Microsoft.AspNet.Server.Kestrel.Http // If _requestAborted is set, the connection has already been closed. if (!_requestAborted) { - // Inform client no more data will ever arrive - ConnectionControl.End(ProduceEndType.SocketShutdownSend); + // Inform client no more data will ever arrive + ConnectionControl.End(ProduceEndType.SocketShutdownSend); - // Wait for client to either disconnect or send unexpected data - await SocketInput; + // Wait for client to either disconnect or send unexpected data + await SocketInput; - // Dispose socket - ConnectionControl.End(ProduceEndType.SocketDisconnect); - } + // Dispose socket + ConnectionControl.End(ProduceEndType.SocketDisconnect); + } } catch (Exception ex) { diff --git a/test/Microsoft.AspNet.Server.KestrelTests/ConnectionFilterTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/ConnectionFilterTests.cs index 5842e1d7c0..0af98798cb 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/ConnectionFilterTests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/ConnectionFilterTests.cs @@ -95,6 +95,9 @@ namespace Microsoft.AspNet.Server.KestrelTests return _empty; } + public void PrepareRequest(IFeatureCollection frame) + {} + public int BytesRead => _rewritingStream.BytesRead; } @@ -110,6 +113,9 @@ namespace Microsoft.AspNet.Server.KestrelTests context.Connection = new RewritingStream(oldConnection); } + + public void PrepareRequest(IFeatureCollection frame) + {} } private class RewritingStream : Stream diff --git a/test/Microsoft.AspNet.Server.KestrelTests/HttpsConnectionFilterTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/HttpsConnectionFilterTests.cs index cf68bd89b1..b738d97131 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/HttpsConnectionFilterTests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/HttpsConnectionFilterTests.cs @@ -3,12 +3,16 @@ using System; using System.Collections.Generic; +using System.IO; using System.Net; using System.Net.Http; using System.Net.Security; +using System.Net.Sockets; using System.Security.Cryptography.X509Certificates; +using System.Text; using System.Threading.Tasks; using Microsoft.AspNet.Http; +using Microsoft.AspNet.Http.Features; using Microsoft.AspNet.Server.Kestrel.Filter; using Microsoft.AspNet.Server.Kestrel.Https; using Microsoft.AspNet.Testing.xunit; @@ -55,19 +59,20 @@ namespace Microsoft.AspNet.Server.KestrelTests handler.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true; #endif - var sereverAddress = "https://localhost:54321/"; + var serverAddress = "https://localhost:54321/"; var serviceContext = new TestServiceContext() { ConnectionFilter = new HttpsConnectionFilter( - new X509Certificate2(@"TestResources/testCert.pfx", "testPassword"), + new HttpsConnectionFilterOptions + { ServerCertificate = new X509Certificate2(@"TestResources/testCert.pfx", "testPassword")}, new NoOpConnectionFilter()) }; - using (var server = new TestServer(App, serviceContext, sereverAddress)) + using (var server = new TestServer(App, serviceContext, serverAddress)) { using (var client = new HttpClient(handler)) { - var result = await client.PostAsync(sereverAddress, new FormUrlEncodedContent(new[] { + var result = await client.PostAsync(serverAddress, new FormUrlEncodedContent(new[] { new KeyValuePair("content", "Hello World?") })); @@ -82,5 +87,189 @@ namespace Microsoft.AspNet.Server.KestrelTests #endif } } + + // https://github.com/aspnet/KestrelHttpServer/issues/240 + // This test currently fails on mono because of an issue with SslStream. + [ConditionalFact] + [OSSkipCondition(OperatingSystems.Linux)] + [OSSkipCondition(OperatingSystems.MacOSX)] + public async Task RequireCertificateFailsWhenNoCertificate() + { + RemoteCertificateValidationCallback validationCallback = + (sender, cert, chain, sslPolicyErrors) => true; + + try + { +#if DNX451 + var handler = new HttpClientHandler(); + ServicePointManager.ServerCertificateValidationCallback += validationCallback; +#else + var handler = new WinHttpHandler(); + handler.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true; +#endif + + var serverAddress = "https://localhost:54321/"; + var serviceContext = new TestServiceContext() + { + ConnectionFilter = new HttpsConnectionFilter( + new HttpsConnectionFilterOptions + { + ServerCertificate = new X509Certificate2(@"TestResources/testCert.pfx", "testPassword"), + ClientCertificateMode = ClientCertificateMode.RequireCertificate + }, + new NoOpConnectionFilter()) + }; + + using (var server = new TestServer(App, serviceContext, serverAddress)) + { + using (var client = new HttpClient()) + { + await Assert.ThrowsAnyAsync( + () => client.GetAsync(serverAddress)); + } + } + } + finally + { +#if DNX451 + ServicePointManager.ServerCertificateValidationCallback -= validationCallback; +#endif + } + } + + // https://github.com/dotnet/corefx/issues/4512 + // WinHttpHandler throws an Exception (ERROR_INTERNET_SECURE_FAILURE) +#if DNX451 + + // https://github.com/aspnet/KestrelHttpServer/issues/240 + // This test currently fails on mono because of an issue with SslStream. + [ConditionalFact] + [OSSkipCondition(OperatingSystems.Linux)] + [OSSkipCondition(OperatingSystems.MacOSX)] + public async Task AllowCertificateContinuesWhenNoCertificate() + { + RemoteCertificateValidationCallback validationCallback = + (sender, cert, chain, sslPolicyErrors) => true; + + try + { +#if DNX451 + var handler = new HttpClientHandler(); + ServicePointManager.ServerCertificateValidationCallback += validationCallback; +#else + var handler = new WinHttpHandler(); + handler.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true; +#endif + + var serverAddress = "https://localhost:54321/"; + var serviceContext = new TestServiceContext() + { + ConnectionFilter = new HttpsConnectionFilter( + new HttpsConnectionFilterOptions + { + ServerCertificate = new X509Certificate2(@"TestResources/testCert.pfx", "testPassword"), + ClientCertificateMode = ClientCertificateMode.AllowCertificate + }, + new NoOpConnectionFilter()) + }; + + RequestDelegate app = context => + { + Assert.Equal(context.Features.Get(), null); + return context.Response.WriteAsync("hello world"); + }; + + using (var server = new TestServer(app, serviceContext, serverAddress)) + { + using (var client = new HttpClient()) + { + var result = await client.GetAsync(serverAddress); + + Assert.Equal("hello world", await result.Content.ReadAsStringAsync()); + } + } + } + finally + { +#if DNX451 + ServicePointManager.ServerCertificateValidationCallback -= validationCallback; +#endif + } + } +#endif + + // https://github.com/dotnet/corefx/issues/4510 + // Can't convert X509Certificate to X509Certificate2 in HttpsConnectionFilter +#if DNX451 + + // https://github.com/aspnet/KestrelHttpServer/issues/240 + // This test currently fails on mono because of an issue with SslStream. + [ConditionalFact] + [OSSkipCondition(OperatingSystems.Linux)] + [OSSkipCondition(OperatingSystems.MacOSX)] + public async Task CertificatePassedToHttpContext() + { + RemoteCertificateValidationCallback validationCallback = + (sender, cert, chain, sslPolicyErrors) => true; + + try + { +#if DNX451 + ServicePointManager.ServerCertificateValidationCallback += validationCallback; +#endif + + var serverAddress = "https://localhost:54321/"; + var serviceContext = new TestServiceContext() + { + ConnectionFilter = new HttpsConnectionFilter( + new HttpsConnectionFilterOptions + { + ServerCertificate = new X509Certificate2(@"TestResources/testCert.pfx", "testPassword"), + ClientCertificateMode = ClientCertificateMode.RequireCertificate, + ClientCertificateValidation = (certificate, chain, sslPolicyErrors) => true + }, + new NoOpConnectionFilter()) + }; + + RequestDelegate app = context => + { + var tlsFeature = context.Features.Get(); + Assert.NotNull(tlsFeature); + Assert.NotNull(tlsFeature.ClientCertificate); + Assert.NotNull(context.Connection.ClientCertificate); + return context.Response.WriteAsync("hello world"); + }; + + using (var server = new TestServer(app, serviceContext, serverAddress)) + { + // SslStream is used to ensure the certificate is actually passed to the server + // HttpClient might not send the certificate because it is invalid or it doesn't match any + // of the certificate authorities sent by the server in the SSL handshake. + using (var client = new TcpClient()) + { + await client.ConnectAsync("127.0.0.1", 54321); + + SslStream stream = new SslStream(client.GetStream(), false, (sender, certificate, chain, errors) => true, + (sender, host, certificates, certificate, issuers) => new X509Certificate2(@"TestResources/testCert.pfx", "testPassword")); + await stream.AuthenticateAsClientAsync("localhost"); + + var request = Encoding.UTF8.GetBytes("GET / HTTP/1.0\r\n\r\n"); + await stream.WriteAsync(request, 0, request.Length); + + var reader = new StreamReader(stream); + var line = await reader.ReadLineAsync(); + Assert.Equal("HTTP/1.0 200 OK", line); + } + } + } + finally + { +#if DNX451 + ServicePointManager.ServerCertificateValidationCallback -= validationCallback; +#endif + } +} +#endif + } } From bed8c67181b3c55c31ed389c726d64a72372e002 Mon Sep 17 00:00:00 2001 From: Master T Date: Sat, 14 Nov 2015 12:53:29 +0100 Subject: [PATCH 0450/1662] Add SslProtocols option to HttpsConnectionFilter --- .../HttpsConnectionFilter.cs | 8 +++++--- .../HttpsConnectionFilterOptions.cs | 3 +++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel.Https/HttpsConnectionFilter.cs b/src/Microsoft.AspNet.Server.Kestrel.Https/HttpsConnectionFilter.cs index e66fa4b3c5..39149cc0bc 100644 --- a/src/Microsoft.AspNet.Server.Kestrel.Https/HttpsConnectionFilter.cs +++ b/src/Microsoft.AspNet.Server.Kestrel.Https/HttpsConnectionFilter.cs @@ -18,6 +18,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Https private readonly ClientCertificateMode _clientCertMode; private readonly ClientCertificateValidationCallback _clientValidationCallback; private readonly IConnectionFilter _previous; + private readonly SslProtocols _sslProtocols; private X509Certificate2 _clientCert; public HttpsConnectionFilter(HttpsConnectionFilterOptions options, IConnectionFilter previous) @@ -34,6 +35,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Https _serverCert = options.ServerCertificate; _clientCertMode = options.ClientCertificateMode; _clientValidationCallback = options.ClientCertificateValidation; + _sslProtocols = options.SslProtocols; _previous = previous; } @@ -47,7 +49,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Https if (_clientCertMode == ClientCertificateMode.NoCertificate) { sslStream = new SslStream(context.Connection); - await sslStream.AuthenticateAsServerAsync(_serverCert); + await sslStream.AuthenticateAsServerAsync(_serverCert, clientCertificateRequired: false, + enabledSslProtocols: _sslProtocols, checkCertificateRevocation: false); } else { @@ -89,8 +92,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Https return true; }); await sslStream.AuthenticateAsServerAsync(_serverCert, clientCertificateRequired: true, - enabledSslProtocols: SslProtocols.Tls12 | SslProtocols.Tls11 | SslProtocols.Tls, - checkCertificateRevocation: false); + enabledSslProtocols: _sslProtocols, checkCertificateRevocation: false); } context.Connection = sslStream; } diff --git a/src/Microsoft.AspNet.Server.Kestrel.Https/HttpsConnectionFilterOptions.cs b/src/Microsoft.AspNet.Server.Kestrel.Https/HttpsConnectionFilterOptions.cs index 62c513c216..b8d65482c7 100644 --- a/src/Microsoft.AspNet.Server.Kestrel.Https/HttpsConnectionFilterOptions.cs +++ b/src/Microsoft.AspNet.Server.Kestrel.Https/HttpsConnectionFilterOptions.cs @@ -1,6 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System.Security.Authentication; using System.Security.Cryptography.X509Certificates; namespace Microsoft.AspNet.Server.Kestrel.Https @@ -10,10 +11,12 @@ namespace Microsoft.AspNet.Server.Kestrel.Https public HttpsConnectionFilterOptions() { ClientCertificateMode = ClientCertificateMode.NoCertificate; + SslProtocols = SslProtocols.Tls12 | SslProtocols.Tls11 | SslProtocols.Tls; } public X509Certificate2 ServerCertificate { get; set; } public ClientCertificateMode ClientCertificateMode { get; set; } public ClientCertificateValidationCallback ClientCertificateValidation { get; set; } + public SslProtocols SslProtocols { get; set; } } } From 8e910baf04366d901bc939d578e527fd840c123c Mon Sep 17 00:00:00 2001 From: Master T Date: Mon, 16 Nov 2015 22:04:27 +0100 Subject: [PATCH 0451/1662] Improve based on pull request feedback --- .../ClientCertificateValidationCallback.cs | 11 --- .../HttpsConnectionFilter.cs | 91 ++++++++++--------- .../HttpsConnectionFilterOptions.cs | 5 +- .../Filter/ConnectionFilterContext.cs | 2 + .../Filter/IConnectionFilter.cs | 1 - .../Filter/NoOpConnectionFilter.cs | 3 - .../Http/Connection.cs | 2 +- .../Http/Frame.cs | 8 +- .../ConnectionFilterTests.cs | 6 -- .../HttpsConnectionFilterTests.cs | 14 +-- 10 files changed, 61 insertions(+), 82 deletions(-) delete mode 100644 src/Microsoft.AspNet.Server.Kestrel.Https/ClientCertificateValidationCallback.cs diff --git a/src/Microsoft.AspNet.Server.Kestrel.Https/ClientCertificateValidationCallback.cs b/src/Microsoft.AspNet.Server.Kestrel.Https/ClientCertificateValidationCallback.cs deleted file mode 100644 index 12616900cc..0000000000 --- a/src/Microsoft.AspNet.Server.Kestrel.Https/ClientCertificateValidationCallback.cs +++ /dev/null @@ -1,11 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System.Net.Security; -using System.Security.Cryptography.X509Certificates; - -namespace Microsoft.AspNet.Server.Kestrel.Https -{ - public delegate bool ClientCertificateValidationCallback( - X509Certificate2 certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors); -} diff --git a/src/Microsoft.AspNet.Server.Kestrel.Https/HttpsConnectionFilter.cs b/src/Microsoft.AspNet.Server.Kestrel.Https/HttpsConnectionFilter.cs index 39149cc0bc..236f4147d1 100644 --- a/src/Microsoft.AspNet.Server.Kestrel.Https/HttpsConnectionFilter.cs +++ b/src/Microsoft.AspNet.Server.Kestrel.Https/HttpsConnectionFilter.cs @@ -14,28 +14,25 @@ namespace Microsoft.AspNet.Server.Kestrel.Https { public class HttpsConnectionFilter : IConnectionFilter { - private readonly X509Certificate2 _serverCert; - private readonly ClientCertificateMode _clientCertMode; - private readonly ClientCertificateValidationCallback _clientValidationCallback; + private readonly HttpsConnectionFilterOptions _options; private readonly IConnectionFilter _previous; - private readonly SslProtocols _sslProtocols; - private X509Certificate2 _clientCert; public HttpsConnectionFilter(HttpsConnectionFilterOptions options, IConnectionFilter previous) { - if (options.ServerCertificate == null) + if (options == null) { - throw new ArgumentNullException(nameof(options.ServerCertificate)); + throw new ArgumentNullException(nameof(options)); } if (previous == null) { throw new ArgumentNullException(nameof(previous)); } + if (options.ServerCertificate == null) + { + throw new ArgumentException("The server certificate parameter is required."); + } - _serverCert = options.ServerCertificate; - _clientCertMode = options.ClientCertificateMode; - _clientValidationCallback = options.ClientCertificateValidation; - _sslProtocols = options.SslProtocols; + _options = options; _previous = previous; } @@ -45,68 +42,76 @@ namespace Microsoft.AspNet.Server.Kestrel.Https if (string.Equals(context.Address.Scheme, "https", StringComparison.OrdinalIgnoreCase)) { + X509Certificate2 clientCertificate = null; SslStream sslStream; - if (_clientCertMode == ClientCertificateMode.NoCertificate) + if (_options.ClientCertificateMode == ClientCertificateMode.NoCertificate) { sslStream = new SslStream(context.Connection); - await sslStream.AuthenticateAsServerAsync(_serverCert, clientCertificateRequired: false, - enabledSslProtocols: _sslProtocols, checkCertificateRevocation: false); + await sslStream.AuthenticateAsServerAsync(_options.ServerCertificate, clientCertificateRequired: false, + enabledSslProtocols: _options.SslProtocols, checkCertificateRevocation: _options.CheckCertificateRevocation); } else { sslStream = new SslStream(context.Connection, leaveInnerStreamOpen: false, userCertificateValidationCallback: (sender, certificate, chain, sslPolicyErrors) => { - if (sslPolicyErrors.HasFlag(SslPolicyErrors.RemoteCertificateNotAvailable)) + Console.WriteLine("callback type: " + (certificate is X509Certificate2)); + if (certificate == null) { - return _clientCertMode != ClientCertificateMode.RequireCertificate; + return _options.ClientCertificateMode != ClientCertificateMode.RequireCertificate; } - - if (_clientValidationCallback == null) + if (_options.ClientCertificateValidation == null) { if (sslPolicyErrors != SslPolicyErrors.None) { return false; } } -#if DOTNET5_4 - // conversion X509Certificate to X509Certificate2 not supported - // https://github.com/dotnet/corefx/issues/4510 - X509Certificate2 certificate2 = null; - return false; -#else - X509Certificate2 certificate2 = certificate as X509Certificate2 ?? - new X509Certificate2(certificate); -#endif - if (_clientValidationCallback != null) + X509Certificate2 certificate2 = certificate as X509Certificate2; + if (certificate2 == null) { - if (!_clientValidationCallback(certificate2, chain, sslPolicyErrors)) +#if DOTNET5_4 + // conversion X509Certificate to X509Certificate2 not supported + // https://github.com/dotnet/corefx/issues/4510 + return false; +#else + certificate2 = new X509Certificate2(certificate); +#endif + } + + if (_options.ClientCertificateValidation != null) + { + if (!_options.ClientCertificateValidation(certificate2, chain, sslPolicyErrors)) { return false; } } - _clientCert = certificate2; + clientCertificate = certificate2; return true; }); - await sslStream.AuthenticateAsServerAsync(_serverCert, clientCertificateRequired: true, - enabledSslProtocols: _sslProtocols, checkCertificateRevocation: false); + await sslStream.AuthenticateAsServerAsync(_options.ServerCertificate, clientCertificateRequired: true, + enabledSslProtocols: _options.SslProtocols, checkCertificateRevocation: _options.CheckCertificateRevocation); + Console.WriteLine("remote type: " + (sslStream.RemoteCertificate is X509Certificate2)); } + + var previousPrepareRequest = context.PrepareRequest; + context.PrepareRequest = features => + { + previousPrepareRequest?.Invoke(features); + + if (clientCertificate != null) + { + features.Set( + new TlsConnectionFeature {ClientCertificate = clientCertificate}); + } + + features.Get().Scheme = "https"; + }; context.Connection = sslStream; } } - - public void PrepareRequest(IFeatureCollection features) - { - _previous.PrepareRequest(features); - - if (_clientCert != null) - { - features.Set( - new TlsConnectionFeature { ClientCertificate = _clientCert }); - } - } } } diff --git a/src/Microsoft.AspNet.Server.Kestrel.Https/HttpsConnectionFilterOptions.cs b/src/Microsoft.AspNet.Server.Kestrel.Https/HttpsConnectionFilterOptions.cs index b8d65482c7..e066c17f3c 100644 --- a/src/Microsoft.AspNet.Server.Kestrel.Https/HttpsConnectionFilterOptions.cs +++ b/src/Microsoft.AspNet.Server.Kestrel.Https/HttpsConnectionFilterOptions.cs @@ -1,6 +1,8 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; +using System.Net.Security; using System.Security.Authentication; using System.Security.Cryptography.X509Certificates; @@ -16,7 +18,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Https public X509Certificate2 ServerCertificate { get; set; } public ClientCertificateMode ClientCertificateMode { get; set; } - public ClientCertificateValidationCallback ClientCertificateValidation { get; set; } + public Func ClientCertificateValidation { get; set; } public SslProtocols SslProtocols { get; set; } + public bool CheckCertificateRevocation { get; set; } } } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Filter/ConnectionFilterContext.cs b/src/Microsoft.AspNet.Server.Kestrel/Filter/ConnectionFilterContext.cs index 278ca58254..fc4f0384c6 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Filter/ConnectionFilterContext.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Filter/ConnectionFilterContext.cs @@ -1,6 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; using System.IO; using Microsoft.AspNet.Http.Features; @@ -10,5 +11,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Filter { public ServerAddress Address { get; set; } public Stream Connection { get; set; } + public Action PrepareRequest { get; set; } } } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Filter/IConnectionFilter.cs b/src/Microsoft.AspNet.Server.Kestrel/Filter/IConnectionFilter.cs index 8c4f827be9..bc08d959ff 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Filter/IConnectionFilter.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Filter/IConnectionFilter.cs @@ -9,6 +9,5 @@ namespace Microsoft.AspNet.Server.Kestrel.Filter public interface IConnectionFilter { Task OnConnection(ConnectionFilterContext context); - void PrepareRequest(IFeatureCollection features); } } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Filter/NoOpConnectionFilter.cs b/src/Microsoft.AspNet.Server.Kestrel/Filter/NoOpConnectionFilter.cs index aac76ec34e..95ecc7a50a 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Filter/NoOpConnectionFilter.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Filter/NoOpConnectionFilter.cs @@ -13,8 +13,5 @@ namespace Microsoft.AspNet.Server.Kestrel.Filter { return TaskUtilities.CompletedTask; } - - public void PrepareRequest(IFeatureCollection features) - {} } } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs index 42d8aeb30a..c2ff59be01 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs @@ -177,7 +177,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http private Frame CreateFrame() { - return new Frame(this, _remoteEndPoint, _localEndPoint, ConnectionFilter); + return new Frame(this, _remoteEndPoint, _localEndPoint, _filterContext?.PrepareRequest); } void IConnectionControl.Pause() diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs index 0edaeb3fee..7f1c9767fb 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs @@ -56,22 +56,22 @@ namespace Microsoft.AspNet.Server.Kestrel.Http private readonly IPEndPoint _localEndPoint; private readonly IPEndPoint _remoteEndPoint; - private readonly IConnectionFilter _connectionFilter; + private readonly Action _prepareRequest; public Frame(ConnectionContext context) - : this(context, remoteEndPoint: null, localEndPoint: null, connectionFilter: null) + : this(context, remoteEndPoint: null, localEndPoint: null, prepareRequest: null) { } public Frame(ConnectionContext context, IPEndPoint remoteEndPoint, IPEndPoint localEndPoint, - IConnectionFilter connectionFilter) + Action prepareRequest) : base(context) { _remoteEndPoint = remoteEndPoint; _localEndPoint = localEndPoint; - _connectionFilter = connectionFilter; + _prepareRequest = prepareRequest; FrameControl = this; Reset(); diff --git a/test/Microsoft.AspNet.Server.KestrelTests/ConnectionFilterTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/ConnectionFilterTests.cs index 0af98798cb..5842e1d7c0 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/ConnectionFilterTests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/ConnectionFilterTests.cs @@ -95,9 +95,6 @@ namespace Microsoft.AspNet.Server.KestrelTests return _empty; } - public void PrepareRequest(IFeatureCollection frame) - {} - public int BytesRead => _rewritingStream.BytesRead; } @@ -113,9 +110,6 @@ namespace Microsoft.AspNet.Server.KestrelTests context.Connection = new RewritingStream(oldConnection); } - - public void PrepareRequest(IFeatureCollection frame) - {} } private class RewritingStream : Stream diff --git a/test/Microsoft.AspNet.Server.KestrelTests/HttpsConnectionFilterTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/HttpsConnectionFilterTests.cs index b738d97131..8b766fba8e 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/HttpsConnectionFilterTests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/HttpsConnectionFilterTests.cs @@ -122,7 +122,7 @@ namespace Microsoft.AspNet.Server.KestrelTests using (var server = new TestServer(App, serviceContext, serverAddress)) { - using (var client = new HttpClient()) + using (var client = new HttpClient(handler)) { await Assert.ThrowsAnyAsync( () => client.GetAsync(serverAddress)); @@ -137,10 +137,6 @@ namespace Microsoft.AspNet.Server.KestrelTests } } - // https://github.com/dotnet/corefx/issues/4512 - // WinHttpHandler throws an Exception (ERROR_INTERNET_SECURE_FAILURE) -#if DNX451 - // https://github.com/aspnet/KestrelHttpServer/issues/240 // This test currently fails on mono because of an issue with SslStream. [ConditionalFact] @@ -181,7 +177,7 @@ namespace Microsoft.AspNet.Server.KestrelTests using (var server = new TestServer(app, serviceContext, serverAddress)) { - using (var client = new HttpClient()) + using (var client = new HttpClient(handler)) { var result = await client.GetAsync(serverAddress); @@ -196,11 +192,6 @@ namespace Microsoft.AspNet.Server.KestrelTests #endif } } -#endif - - // https://github.com/dotnet/corefx/issues/4510 - // Can't convert X509Certificate to X509Certificate2 in HttpsConnectionFilter -#if DNX451 // https://github.com/aspnet/KestrelHttpServer/issues/240 // This test currently fails on mono because of an issue with SslStream. @@ -269,7 +260,6 @@ namespace Microsoft.AspNet.Server.KestrelTests #endif } } -#endif } } From ba63c894be9468ba3ef6ccb7433981de11c7cfa3 Mon Sep 17 00:00:00 2001 From: Master T Date: Mon, 16 Nov 2015 22:08:53 +0100 Subject: [PATCH 0452/1662] Remove Console.WriteLine --- .../HttpsConnectionFilter.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel.Https/HttpsConnectionFilter.cs b/src/Microsoft.AspNet.Server.Kestrel.Https/HttpsConnectionFilter.cs index 236f4147d1..b7606438f0 100644 --- a/src/Microsoft.AspNet.Server.Kestrel.Https/HttpsConnectionFilter.cs +++ b/src/Microsoft.AspNet.Server.Kestrel.Https/HttpsConnectionFilter.cs @@ -55,7 +55,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Https sslStream = new SslStream(context.Connection, leaveInnerStreamOpen: false, userCertificateValidationCallback: (sender, certificate, chain, sslPolicyErrors) => { - Console.WriteLine("callback type: " + (certificate is X509Certificate2)); if (certificate == null) { return _options.ClientCertificateMode != ClientCertificateMode.RequireCertificate; @@ -94,7 +93,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Https }); await sslStream.AuthenticateAsServerAsync(_options.ServerCertificate, clientCertificateRequired: true, enabledSslProtocols: _options.SslProtocols, checkCertificateRevocation: _options.CheckCertificateRevocation); - Console.WriteLine("remote type: " + (sslStream.RemoteCertificate is X509Certificate2)); } var previousPrepareRequest = context.PrepareRequest; From 85eb6ab600ed7ca3a33d11fe268337c02c541d61 Mon Sep 17 00:00:00 2001 From: Master T Date: Mon, 16 Nov 2015 23:58:16 +0100 Subject: [PATCH 0453/1662] Code cleanup --- src/Microsoft.AspNet.Server.Kestrel/Filter/IConnectionFilter.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Filter/IConnectionFilter.cs b/src/Microsoft.AspNet.Server.Kestrel/Filter/IConnectionFilter.cs index bc08d959ff..accaa3b9d9 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Filter/IConnectionFilter.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Filter/IConnectionFilter.cs @@ -2,7 +2,6 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Threading.Tasks; -using Microsoft.AspNet.Http.Features; namespace Microsoft.AspNet.Server.Kestrel.Filter { From 592d802fde77ec375cd2b7227d0874466fd40c83 Mon Sep 17 00:00:00 2001 From: Master T Date: Wed, 18 Nov 2015 04:52:13 +0100 Subject: [PATCH 0454/1662] Add test for https scheme, code cleanup --- .../HttpsConnectionFilter.cs | 17 +++--- .../HttpsConnectionFilterTests.cs | 54 ++++++++++++++++++- 2 files changed, 60 insertions(+), 11 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel.Https/HttpsConnectionFilter.cs b/src/Microsoft.AspNet.Server.Kestrel.Https/HttpsConnectionFilter.cs index b7606438f0..1d13d6fb2e 100644 --- a/src/Microsoft.AspNet.Server.Kestrel.Https/HttpsConnectionFilter.cs +++ b/src/Microsoft.AspNet.Server.Kestrel.Https/HttpsConnectionFilter.cs @@ -97,17 +97,16 @@ namespace Microsoft.AspNet.Server.Kestrel.Https var previousPrepareRequest = context.PrepareRequest; context.PrepareRequest = features => + { + previousPrepareRequest?.Invoke(features); + + if (clientCertificate != null) { - previousPrepareRequest?.Invoke(features); + features.Set(new TlsConnectionFeature { ClientCertificate = clientCertificate }); + } - if (clientCertificate != null) - { - features.Set( - new TlsConnectionFeature {ClientCertificate = clientCertificate}); - } - - features.Get().Scheme = "https"; - }; + features.Get().Scheme = "https"; + }; context.Connection = sslStream; } } diff --git a/test/Microsoft.AspNet.Server.KestrelTests/HttpsConnectionFilterTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/HttpsConnectionFilterTests.cs index 8b766fba8e..1f7ca8c4d2 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/HttpsConnectionFilterTests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/HttpsConnectionFilterTests.cs @@ -258,8 +258,58 @@ namespace Microsoft.AspNet.Server.KestrelTests #if DNX451 ServicePointManager.ServerCertificateValidationCallback -= validationCallback; #endif - } -} + } + } + // https://github.com/aspnet/KestrelHttpServer/issues/240 + // This test currently fails on mono because of an issue with SslStream. + [ConditionalFact] + [OSSkipCondition(OperatingSystems.Linux)] + [OSSkipCondition(OperatingSystems.MacOSX)] + public async Task HttpsSchemePassedToRequestFeature() + { + RemoteCertificateValidationCallback validationCallback = + (sender, cert, chain, sslPolicyErrors) => true; + + try + { +#if DNX451 + var handler = new HttpClientHandler(); + ServicePointManager.ServerCertificateValidationCallback += validationCallback; +#else + var handler = new WinHttpHandler(); + handler.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true; +#endif + + var serverAddress = "https://localhost:54321/"; + var serviceContext = new TestServiceContext() + { + ConnectionFilter = new HttpsConnectionFilter( + new HttpsConnectionFilterOptions + { + ServerCertificate = new X509Certificate2(@"TestResources/testCert.pfx", "testPassword") + }, + new NoOpConnectionFilter()) + }; + + RequestDelegate app = context => context.Response.WriteAsync(context.Request.Scheme); + + using (var server = new TestServer(app, serviceContext, serverAddress)) + { + using (var client = new HttpClient(handler)) + { + var result = await client.GetAsync(serverAddress); + + Assert.Equal("https", await result.Content.ReadAsStringAsync()); + } + } + } + finally + { +#if DNX451 + ServicePointManager.ServerCertificateValidationCallback -= validationCallback; +#endif + } + } } } From 2cdd659e673b8df2d4e73ec84a13d463174061e7 Mon Sep 17 00:00:00 2001 From: Master T Date: Wed, 18 Nov 2015 05:11:57 +0100 Subject: [PATCH 0455/1662] Fix indentation --- .../Http/Frame.cs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs index 7f1c9767fb..7c5d1ed35b 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs @@ -278,7 +278,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http // If _requestAbort is set, the connection has already been closed. if (!_requestAborted) { - await ProduceEnd(); + await ProduceEnd(); // Finish reading the request body in case the app did not. await messageBody.Consume(); @@ -307,15 +307,15 @@ namespace Microsoft.AspNet.Server.Kestrel.Http // If _requestAborted is set, the connection has already been closed. if (!_requestAborted) { - // Inform client no more data will ever arrive - ConnectionControl.End(ProduceEndType.SocketShutdownSend); + // Inform client no more data will ever arrive + ConnectionControl.End(ProduceEndType.SocketShutdownSend); - // Wait for client to either disconnect or send unexpected data - await SocketInput; + // Wait for client to either disconnect or send unexpected data + await SocketInput; - // Dispose socket - ConnectionControl.End(ProduceEndType.SocketDisconnect); - } + // Dispose socket + ConnectionControl.End(ProduceEndType.SocketDisconnect); + } } catch (Exception ex) { From efec0feda2742a0d436fdfa00b39b5358d03fa0c Mon Sep 17 00:00:00 2001 From: Master T Date: Wed, 18 Nov 2015 08:29:30 +0100 Subject: [PATCH 0456/1662] Fix merge --- src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs index 7c5d1ed35b..7bb0faa0e2 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs @@ -144,7 +144,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http httpConnectionFeature.IsLocal = false; } - _connectionFilter?.PrepareRequest(this); + _prepareRequest?.Invoke(this); _requestAbortCts?.Dispose(); } From 307e020703a8bf697bf4b8ed463c53dedd8391b1 Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Wed, 18 Nov 2015 16:32:22 -0800 Subject: [PATCH 0457/1662] Don't crash the server if a connection filter throws synchronously. --- .../Http/Connection.cs | 42 +++++++++++-------- .../ConnectionFilterTests.cs | 40 +++++++++++++++++- 2 files changed, 64 insertions(+), 18 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs index c2ff59be01..4af0676761 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs @@ -78,25 +78,33 @@ namespace Microsoft.AspNet.Server.Kestrel.Http Address = ServerAddress }; - ConnectionFilter.OnConnection(_filterContext).ContinueWith((task, state) => + try { - var connection = (Connection)state; + ConnectionFilter.OnConnection(_filterContext).ContinueWith((task, state) => + { + var connection = (Connection)state; - if (task.IsFaulted) - { - connection.Log.LogError("ConnectionFilter.OnConnection", task.Exception); - connection.ConnectionControl.End(ProduceEndType.SocketDisconnect); - } - else if (task.IsCanceled) - { - connection.Log.LogError("ConnectionFilter.OnConnection Canceled"); - connection.ConnectionControl.End(ProduceEndType.SocketDisconnect); - } - else - { - connection.ApplyConnectionFilter(); - } - }, this); + if (task.IsFaulted) + { + connection.Log.LogError("ConnectionFilter.OnConnection", task.Exception); + connection.ConnectionControl.End(ProduceEndType.SocketDisconnect); + } + else if (task.IsCanceled) + { + connection.Log.LogError("ConnectionFilter.OnConnection Canceled"); + connection.ConnectionControl.End(ProduceEndType.SocketDisconnect); + } + else + { + connection.ApplyConnectionFilter(); + } + }, this); + } + catch (Exception ex) + { + Log.LogError("ConnectionFilter.OnConnection", ex); + ConnectionControl.End(ProduceEndType.SocketDisconnect); + } } } diff --git a/test/Microsoft.AspNet.Server.KestrelTests/ConnectionFilterTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/ConnectionFilterTests.cs index 5842e1d7c0..5dbe530f14 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/ConnectionFilterTests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/ConnectionFilterTests.cs @@ -1,6 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; using System.IO; using System.Threading.Tasks; using Microsoft.AspNet.Http; @@ -80,7 +81,36 @@ namespace Microsoft.AspNet.Server.KestrelTests "Hello World!"); } } - } + } + + [ConditionalFact] + [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Test hangs after execution on Mono.")] + public async Task ThrowingSynchronousConnectionFilterDoesNotCrashServer() + { + var serviceContext = new TestServiceContext() + { + ConnectionFilter = new ThrowingConnectionFilter() + }; + + using (var server = new TestServer(App, serviceContext)) + { + using (var connection = new TestConnection()) + { + try + { + await connection.SendEnd( + "POST / HTTP/1.0", + "", + "Hello World?"); + } + catch (IOException) + { + // Will throw because the exception in the connection filter will close the connection. + Assert.True(true); + } + } + } + } private class RewritingConnectionFilter : IConnectionFilter { @@ -112,6 +142,14 @@ namespace Microsoft.AspNet.Server.KestrelTests } } + private class ThrowingConnectionFilter : IConnectionFilter + { + public Task OnConnection(ConnectionFilterContext context) + { + throw new Exception(); + } + } + private class RewritingStream : Stream { private readonly Stream _innerStream; From 58d8c851c5fdeea8189529b4d23cff9869489580 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Thu, 19 Nov 2015 21:50:10 +0000 Subject: [PATCH 0458/1662] Remove CreateLinkedTokenSource Resolves #407 --- src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs index 7bb0faa0e2..767ab0425f 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs @@ -43,8 +43,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http private Task _requestProcessingTask; private volatile bool _requestProcessingStopping; // volatile, see: https://msdn.microsoft.com/en-us/library/x13ttww7.aspx private volatile bool _requestAborted; - private CancellationTokenSource _disconnectCts = new CancellationTokenSource(); - private CancellationTokenSource _requestAbortCts; + private CancellationTokenSource _disconnectOrAbortedCts = new CancellationTokenSource(); private FrameRequestStream _requestBody; private FrameResponseStream _responseBody; @@ -145,8 +144,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } _prepareRequest?.Invoke(this); - - _requestAbortCts?.Dispose(); } public void ResetResponseHeaders() @@ -199,7 +196,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http ConnectionControl.End(ProduceEndType.SocketDisconnect); SocketInput.AbortAwaiting(); - _disconnectCts.Cancel(); + _disconnectOrAbortedCts.Cancel(); } catch (Exception ex) { @@ -248,8 +245,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http ResponseBody = _responseBody; DuplexStream = new FrameDuplexStream(RequestBody, ResponseBody); - _requestAbortCts = CancellationTokenSource.CreateLinkedTokenSource(_disconnectCts.Token); - RequestAborted = _requestAbortCts.Token; + RequestAborted = _disconnectOrAbortedCts.Token; var httpContext = HttpContextFactory.Create(this); try @@ -302,7 +298,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { try { - _disconnectCts.Dispose(); + _disconnectOrAbortedCts.Dispose(); // If _requestAborted is set, the connection has already been closed. if (!_requestAborted) From 3c7431aa354e8092571903cc3b96b0a069324a80 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Thu, 19 Nov 2015 23:25:31 +0000 Subject: [PATCH 0459/1662] Change disconnect to abort cts --- .../Http/Frame.cs | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs index 767ab0425f..8156706197 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs @@ -43,7 +43,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http private Task _requestProcessingTask; private volatile bool _requestProcessingStopping; // volatile, see: https://msdn.microsoft.com/en-us/library/x13ttww7.aspx private volatile bool _requestAborted; - private CancellationTokenSource _disconnectOrAbortedCts = new CancellationTokenSource(); + private CancellationTokenSource _abortedCts; private FrameRequestStream _requestBody; private FrameResponseStream _responseBody; @@ -144,6 +144,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } _prepareRequest?.Invoke(this); + + _abortedCts?.Dispose(); + _abortedCts = null; } public void ResetResponseHeaders() @@ -196,12 +199,17 @@ namespace Microsoft.AspNet.Server.Kestrel.Http ConnectionControl.End(ProduceEndType.SocketDisconnect); SocketInput.AbortAwaiting(); - _disconnectOrAbortedCts.Cancel(); + _abortedCts?.Cancel(); } catch (Exception ex) { Log.LogError("Abort", ex); } + finally + { + _abortedCts?.Dispose(); + _abortedCts = null; + } } /// @@ -245,7 +253,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http ResponseBody = _responseBody; DuplexStream = new FrameDuplexStream(RequestBody, ResponseBody); - RequestAborted = _disconnectOrAbortedCts.Token; + _abortedCts = new CancellationTokenSource(); + RequestAborted = _abortedCts.Token; var httpContext = HttpContextFactory.Create(this); try @@ -298,7 +307,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { try { - _disconnectOrAbortedCts.Dispose(); + _abortedCts?.Dispose(); + _abortedCts = null; // If _requestAborted is set, the connection has already been closed. if (!_requestAborted) From 1c40548928692d448746ec9b4db09d51b9f57eab Mon Sep 17 00:00:00 2001 From: Chris R Date: Mon, 16 Nov 2015 15:12:12 -0800 Subject: [PATCH 0460/1662] Add LoggingConnectionFilter. --- samples/SampleApp/Startup.cs | 4 +- .../HttpsApplicationBuilderExtensions.cs | 4 +- .../Filter/LoggingConnectionFilter.cs | 37 +++++ ...ggingFilterApplicationBuilderExtensions.cs | 39 ++++++ .../Filter/LoggingStream.cs | 129 ++++++++++++++++++ 5 files changed, 210 insertions(+), 3 deletions(-) create mode 100644 src/Microsoft.AspNet.Server.Kestrel/Filter/LoggingConnectionFilter.cs create mode 100644 src/Microsoft.AspNet.Server.Kestrel/Filter/LoggingFilterApplicationBuilderExtensions.cs create mode 100644 src/Microsoft.AspNet.Server.Kestrel/Filter/LoggingStream.cs diff --git a/samples/SampleApp/Startup.cs b/samples/SampleApp/Startup.cs index 7ececbb741..97cca8e51e 100644 --- a/samples/SampleApp/Startup.cs +++ b/samples/SampleApp/Startup.cs @@ -8,7 +8,7 @@ using Microsoft.AspNet.Builder; using Microsoft.AspNet.Http; using Microsoft.AspNet.Http.Features; using Microsoft.AspNet.Server.Kestrel; -using Microsoft.AspNet.Server.Kestrel.Https; +using Microsoft.AspNet.Server.Kestrel.Filter; using Microsoft.Extensions.Logging; using Microsoft.Extensions.PlatformAbstractions; @@ -39,6 +39,8 @@ namespace SampleApp Console.WriteLine("Could not find certificate at '{0}'. HTTPS is not enabled.", testCertPath); } + app.UseKestrelConnectionLogging(); + app.Run(async context => { Console.WriteLine("{0} {1}{2}{3}", diff --git a/src/Microsoft.AspNet.Server.Kestrel.Https/HttpsApplicationBuilderExtensions.cs b/src/Microsoft.AspNet.Server.Kestrel.Https/HttpsApplicationBuilderExtensions.cs index c595376aa9..e31f0f6482 100644 --- a/src/Microsoft.AspNet.Server.Kestrel.Https/HttpsApplicationBuilderExtensions.cs +++ b/src/Microsoft.AspNet.Server.Kestrel.Https/HttpsApplicationBuilderExtensions.cs @@ -4,9 +4,9 @@ using System.Security.Cryptography.X509Certificates; using Microsoft.AspNet.Builder; using Microsoft.AspNet.Http.Features; -using Microsoft.AspNet.Server.Kestrel.Filter; +using Microsoft.AspNet.Server.Kestrel.Https; -namespace Microsoft.AspNet.Server.Kestrel.Https +namespace Microsoft.AspNet.Server.Kestrel.Filter { public static class HttpsApplicationBuilderExtensions { diff --git a/src/Microsoft.AspNet.Server.Kestrel/Filter/LoggingConnectionFilter.cs b/src/Microsoft.AspNet.Server.Kestrel/Filter/LoggingConnectionFilter.cs new file mode 100644 index 0000000000..1858715ea9 --- /dev/null +++ b/src/Microsoft.AspNet.Server.Kestrel/Filter/LoggingConnectionFilter.cs @@ -0,0 +1,37 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Threading.Tasks; +using Microsoft.Extensions.Logging; + +namespace Microsoft.AspNet.Server.Kestrel.Filter +{ + public class LoggingConnectionFilter : IConnectionFilter + { + private readonly ILogger _logger; + private readonly IConnectionFilter _previous; + + public LoggingConnectionFilter(ILogger logger, IConnectionFilter previous) + { + if (logger == null) + { + throw new ArgumentNullException(nameof(logger)); + } + if (previous == null) + { + throw new ArgumentNullException(nameof(previous)); + } + + _logger = logger; + _previous = previous; + } + + public async Task OnConnection(ConnectionFilterContext context) + { + await _previous.OnConnection(context); + + context.Connection = new LoggingStream(context.Connection, _logger); + } + } +} diff --git a/src/Microsoft.AspNet.Server.Kestrel/Filter/LoggingFilterApplicationBuilderExtensions.cs b/src/Microsoft.AspNet.Server.Kestrel/Filter/LoggingFilterApplicationBuilderExtensions.cs new file mode 100644 index 0000000000..de0ffab1ac --- /dev/null +++ b/src/Microsoft.AspNet.Server.Kestrel/Filter/LoggingFilterApplicationBuilderExtensions.cs @@ -0,0 +1,39 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using Microsoft.AspNet.Builder; +using Microsoft.AspNet.Http.Features; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; + +namespace Microsoft.AspNet.Server.Kestrel.Filter +{ + public static class LoggingFilterApplicationBuilderExtensions + { + /// + /// Emits verbose logs for bytes read from and written to the connection. + /// + /// + public static IApplicationBuilder UseKestrelConnectionLogging(this IApplicationBuilder app) + { + return app.UseKestrelConnectionLogging(nameof(LoggingConnectionFilter)); + } + + /// + /// Emits verbose logs for bytes read from and written to the connection. + /// + /// + public static IApplicationBuilder UseKestrelConnectionLogging(this IApplicationBuilder app, string loggerName) + { + var serverInfo = app.ServerFeatures.Get(); + if (serverInfo != null) + { + var prevFilter = serverInfo.ConnectionFilter ?? new NoOpConnectionFilter(); + var loggerFactory = app.ApplicationServices.GetRequiredService(); + var logger = loggerFactory.CreateLogger(loggerName ?? nameof(LoggingConnectionFilter)); + serverInfo.ConnectionFilter = new LoggingConnectionFilter(logger, prevFilter); + } + return app; + } + } +} diff --git a/src/Microsoft.AspNet.Server.Kestrel/Filter/LoggingStream.cs b/src/Microsoft.AspNet.Server.Kestrel/Filter/LoggingStream.cs new file mode 100644 index 0000000000..41787c26ca --- /dev/null +++ b/src/Microsoft.AspNet.Server.Kestrel/Filter/LoggingStream.cs @@ -0,0 +1,129 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System.IO; +using System.Text; +using System.Threading; +using System.Threading.Tasks; +using Microsoft.Extensions.Logging; + +namespace Microsoft.AspNet.Server.Kestrel.Filter +{ + internal class LoggingStream : Stream + { + private readonly Stream _inner; + private readonly ILogger _logger; + + public LoggingStream(Stream inner, ILogger logger) + { + _inner = inner; + _logger = logger; + } + + public override bool CanRead + { + get + { + return _inner.CanRead; + } + } + + public override bool CanSeek + { + get + { + return _inner.CanSeek; + } + } + + public override bool CanWrite + { + get + { + return _inner.CanWrite; + } + } + + public override long Length + { + get + { + return _inner.Length; + } + } + + public override long Position + { + get + { + return _inner.Position; + } + + set + { + _inner.Position = value; + } + } + + public override void Flush() + { + _inner.Flush(); + } + + public override int Read(byte[] buffer, int offset, int count) + { + int read = _inner.Read(buffer, offset, count); + Log("Read", read, buffer, offset); + return read; + } + + public async override Task ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) + { + int read = await _inner.ReadAsync(buffer, offset, count, cancellationToken); + Log("ReadAsync", read, buffer, offset); + return read; + } + + public override long Seek(long offset, SeekOrigin origin) + { + return _inner.Seek(offset, origin); + } + + public override void SetLength(long value) + { + _inner.SetLength(value); + } + + public override void Write(byte[] buffer, int offset, int count) + { + Log("Write", count, buffer, offset); + _inner.Write(buffer, offset, count); + } + + public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) + { + Log("WriteAsync", count, buffer, offset); + return _inner.WriteAsync(buffer, offset, count, cancellationToken); + } + + private void Log(string method, int count, byte[] buffer, int offset) + { + var builder = new StringBuilder($"{method}[{count}] "); + + // Write the hex + for (int i = offset; i < offset + count; i++) + { + builder.Append(buffer[i].ToString("X2")); + builder.Append(" "); + } + builder.AppendLine(); + // Write the bytes as if they were ASCII + for (int i = offset; i < offset + count; i++) + { + builder.Append((char)buffer[i]); + } + + _logger.LogVerbose(builder.ToString()); + } + } +} From 174ec739bbe770b41b265f947abf29315f7a5921 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Fri, 20 Nov 2015 00:30:08 +0000 Subject: [PATCH 0461/1662] Don't log ODEs thrown from _abortedCts.Cancel --- src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs index 8156706197..3922f4d9d7 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs @@ -199,7 +199,15 @@ namespace Microsoft.AspNet.Server.Kestrel.Http ConnectionControl.End(ProduceEndType.SocketDisconnect); SocketInput.AbortAwaiting(); - _abortedCts?.Cancel(); + try + { + _abortedCts?.Cancel(); + } + catch (ObjectDisposedException) + { + // Don't log ODEs thrown from _abortedCts.Cancel() + // If _abortedCts is disposed, the app has already completed. + } } catch (Exception ex) { From 9d852632c05674f80dddb93be4c5c929950dbfe3 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Fri, 20 Nov 2015 05:51:25 +0000 Subject: [PATCH 0462/1662] Remove _nullBuffer Was meant to be removed as part of #335 /cc @rynowak --- src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs index 7bb0faa0e2..8dc2670a6a 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs @@ -32,7 +32,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Http private readonly object _onStartingSync = new Object(); private readonly object _onCompletedSync = new Object(); private readonly FrameRequestHeaders _requestHeaders = new FrameRequestHeaders(); - private readonly byte[] _nullBuffer = new byte[4096]; private readonly FrameResponseHeaders _responseHeaders = new FrameResponseHeaders(); private List, object>> _onStarting; From 2572256d3f13bb06f099899e54a9863d50e4eda9 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Fri, 20 Nov 2015 01:56:46 -0800 Subject: [PATCH 0463/1662] Use MemoryPool2 for SocketOutput Buffers Add ProducingStart and ProducingComplete methods to ISocketOutput. These new methods can help prevent double buffering when encoding. --- .../Filter/FilteredStreamAdapter.cs | 2 +- .../Filter/StreamSocketOutput.cs | 27 ++- .../Http/Connection.cs | 4 +- .../Http/ISocketOutput.cs | 18 ++ .../Http/SocketInput.cs | 4 +- .../Http/SocketOutput.cs | 217 ++++++++++++++---- .../Infrastructure/MemoryPool2.cs | 2 +- .../Infrastructure/MemoryPoolBlock2.cs | 15 +- .../Infrastructure/MemoryPoolIterator2.cs | 42 ++++ .../Networking/UvWriteReq.cs | 19 +- .../MemoryPoolBlock2Tests.cs | 35 ++- .../MultipleLoopTests.cs | 12 +- .../NetworkingTests.cs | 18 +- .../SocketOutputTests.cs | 63 ++++- .../TestHelpers/MockLibuv.cs | 6 +- 15 files changed, 408 insertions(+), 76 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Filter/FilteredStreamAdapter.cs b/src/Microsoft.AspNet.Server.Kestrel/Filter/FilteredStreamAdapter.cs index 2e0872f704..e3d2eb5603 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Filter/FilteredStreamAdapter.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Filter/FilteredStreamAdapter.cs @@ -22,7 +22,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Filter IKestrelTrace logger) { SocketInput = new SocketInput(memory); - SocketOutput = new StreamSocketOutput(filteredStream); + SocketOutput = new StreamSocketOutput(filteredStream, memory); _log = logger; _filteredStream = filteredStream; diff --git a/src/Microsoft.AspNet.Server.Kestrel/Filter/StreamSocketOutput.cs b/src/Microsoft.AspNet.Server.Kestrel/Filter/StreamSocketOutput.cs index fe9499265f..ba7c57dcf4 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Filter/StreamSocketOutput.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Filter/StreamSocketOutput.cs @@ -13,10 +13,13 @@ namespace Microsoft.AspNet.Server.Kestrel.Filter public class StreamSocketOutput : ISocketOutput { private readonly Stream _outputStream; + private readonly MemoryPool2 _memory; + private MemoryPoolBlock2 _producingBlock; - public StreamSocketOutput(Stream outputStream) + public StreamSocketOutput(Stream outputStream, MemoryPool2 memory) { _outputStream = outputStream; + _memory = memory; } void ISocketOutput.Write(ArraySegment buffer, bool immediate) @@ -30,5 +33,27 @@ namespace Microsoft.AspNet.Server.Kestrel.Filter _outputStream.Write(buffer.Array, buffer.Offset, buffer.Count); return TaskUtilities.CompletedTask; } + + public MemoryPoolIterator2 ProducingStart() + { + _producingBlock = _memory.Lease(); + return new MemoryPoolIterator2(_producingBlock); + } + + public void ProducingComplete(MemoryPoolIterator2 end, int count) + { + var block = _producingBlock; + while (block != end.Block) + { + _outputStream.Write(block.Data.Array, block.Data.Offset, block.Data.Count); + + var returnBlock = block; + block = block.Next; + returnBlock.Pool?.Return(returnBlock); + } + + _outputStream.Write(end.Block.Array, end.Block.Data.Offset, end.Index); + end.Block.Pool?.Return(end.Block); + } } } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs index 4af0676761..03c2a619b9 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs @@ -42,7 +42,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http _connectionId = Interlocked.Increment(ref _lastConnectionId); _rawSocketInput = new SocketInput(Memory2); - _rawSocketOutput = new SocketOutput(Thread, _socket, this, _connectionId, Log); + _rawSocketOutput = new SocketOutput(Thread, _socket, Memory2, this, _connectionId, Log); } public void Start() @@ -116,7 +116,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http // called from a libuv thread. ThreadPool.QueueUserWorkItem(state => { - var connection = (Connection)this; + var connection = (Connection)state; connection._frame.Abort(); }, this); } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/ISocketOutput.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/ISocketOutput.cs index 4edffa3055..1ec17d269b 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/ISocketOutput.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/ISocketOutput.cs @@ -4,6 +4,7 @@ using System; using System.Threading; using System.Threading.Tasks; +using Microsoft.AspNet.Server.Kestrel.Infrastructure; namespace Microsoft.AspNet.Server.Kestrel.Http { @@ -14,5 +15,22 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { void Write(ArraySegment buffer, bool immediate = true); Task WriteAsync(ArraySegment buffer, bool immediate = true, CancellationToken cancellationToken = default(CancellationToken)); + + /// + /// Returns an iterator pointing to the tail of the response buffer. Response data can be appended + /// manually or by using . + /// Be careful to ensure all appended blocks are backed by a . + /// + MemoryPoolIterator2 ProducingStart(); + + /// + /// Commits the response data appended to the iterator returned from . + /// All the data up to will be included in the response. + /// A write operation isn't guaranteed to be scheduled unless + /// or is called afterwards. + /// + /// Points to the end of the committed data. + /// The number of bytes added to the response. + void ProducingComplete(MemoryPoolIterator2 end, int count); } } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketInput.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketInput.cs index ae74bffb24..b13d678130 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketInput.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketInput.cs @@ -64,7 +64,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { _pinned = _tail; var data = new ArraySegment(_pinned.Data.Array, _pinned.End, _pinned.Data.Offset + _pinned.Data.Count - _pinned.End); - var dataPtr = _pinned.Pin(); + var dataPtr = _pinned.Pin() + _pinned.End; return new IncomingBuffer { Data = data, @@ -77,7 +77,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return new IncomingBuffer { Data = _pinned.Data, - DataPtr = _pinned.Pin() + DataPtr = _pinned.Pin() + _pinned.End }; } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs index d1e353388f..be47d8e720 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs @@ -23,8 +23,18 @@ namespace Microsoft.AspNet.Server.Kestrel.Http private readonly long _connectionId; private readonly IKestrelTrace _log; + // This locks all access to _tail, _isProducing and _returnFromOnProducingComplete. + // _head does not require a lock, since it is only used in the ctor and uv thread. + private readonly object _returnLock = new object(); + + private MemoryPoolBlock2 _head; + private MemoryPoolBlock2 _tail; + + private bool _isProducing; + private MemoryPoolBlock2 _returnFromOnProducingComplete; + // This locks access to to all of the below fields - private readonly object _lockObj = new object(); + private readonly object _contextLock = new object(); // The number of write operations that have been scheduled so far // but have not completed. @@ -38,6 +48,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http public SocketOutput( KestrelThread thread, UvStreamHandle socket, + MemoryPool2 memory, Connection connection, long connectionId, IKestrelTrace log) @@ -48,6 +59,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Http _connectionId = connectionId; _log = log; _tasksPending = new Queue>(); + + _head = memory.Lease(); + _tail = _head; } public Task WriteAsync( @@ -56,28 +70,20 @@ namespace Microsoft.AspNet.Server.Kestrel.Http bool socketShutdownSend = false, bool socketDisconnect = false) { - //TODO: need buffering that works - if (buffer.Array != null) - { - var copy = new byte[buffer.Count]; - Array.Copy(buffer.Array, buffer.Offset, copy, 0, buffer.Count); - buffer = new ArraySegment(copy); - _log.ConnectionWrite(_connectionId, buffer.Count); - } + var tail = ProducingStart(); + tail = tail.CopyFrom(buffer); + // We do our own accounting below + ProducingComplete(tail, count: 0); TaskCompletionSource tcs = null; - lock (_lockObj) + lock (_contextLock) { if (_nextWriteContext == null) { _nextWriteContext = new WriteContext(this); } - if (buffer.Array != null) - { - _nextWriteContext.Buffers.Enqueue(buffer); - } if (socketShutdownSend) { _nextWriteContext.SocketShutdownSend = true; @@ -138,6 +144,58 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } + public MemoryPoolIterator2 ProducingStart() + { + lock (_returnLock) + { + Debug.Assert(!_isProducing); + _isProducing = true; + + if (_tail == null) + { + throw new IOException("The socket has been closed."); + } + + return new MemoryPoolIterator2(_tail, _tail.End); + } + } + + public void ProducingComplete(MemoryPoolIterator2 end, int count) + { + lock (_returnLock) + { + Debug.Assert(_isProducing); + _isProducing = false; + + if (_returnFromOnProducingComplete == null) + { + _tail = end.Block; + _tail.End = end.Index; + + if (count != 0) + { + lock (_contextLock) + { + _numBytesPreCompleted += count; + } + } + } + else + { + var block = _returnFromOnProducingComplete; + while (block != null) + { + var returnBlock = block; + block = block.Next; + + returnBlock.Pool?.Return(returnBlock); + } + + _returnFromOnProducingComplete = null; + } + } + } + private void ScheduleWrite() { _thread.Post(_this => _this.WriteAllPending(), this); @@ -148,7 +206,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { WriteContext writingContext; - lock (_lockObj) + lock (_contextLock) { if (_nextWriteContext != null) { @@ -168,7 +226,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } catch { - lock (_lockObj) + lock (_contextLock) { // Lock instead of using Interlocked.Decrement so _writesSending // doesn't change in the middle of executing other synchronized code. @@ -180,7 +238,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } // This is called on the libuv event loop - private void OnWriteCompleted(Queue> writtenBuffers, int status, Exception error) + private void OnWriteCompleted(int bytesWritten, int status, Exception error) { _log.ConnectionWriteCallback(_connectionId, status); @@ -192,7 +250,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http _connection.Abort(); } - lock (_lockObj) + lock (_contextLock) { if (_nextWriteContext != null) { @@ -203,13 +261,10 @@ namespace Microsoft.AspNet.Server.Kestrel.Http _writesPending--; } - foreach (var writeBuffer in writtenBuffers) - { - // _numBytesPreCompleted can temporarily go negative in the event there are - // completed writes that we haven't triggered callbacks for yet. - _numBytesPreCompleted -= writeBuffer.Count; - } - + // _numBytesPreCompleted can temporarily go negative in the event there are + // completed writes that we haven't triggered callbacks for yet. + _numBytesPreCompleted -= bytesWritten; + // bytesLeftToBuffer can be greater than _maxBytesPreCompleted // This allows large writes to complete once they've actually finished. var bytesLeftToBuffer = _maxBytesPreCompleted - _numBytesPreCompleted; @@ -225,20 +280,48 @@ namespace Microsoft.AspNet.Server.Kestrel.Http if (_lastWriteError == null) { ThreadPool.QueueUserWorkItem( - (o) => ((TaskCompletionSource)o).SetResult(null), + (o) => ((TaskCompletionSource)o).SetResult(null), tcs); } else { // error is closure captured ThreadPool.QueueUserWorkItem( - (o) => ((TaskCompletionSource)o).SetException(_lastWriteError), + (o) => ((TaskCompletionSource)o).SetException(_lastWriteError), tcs); } } + } + } - // Now that the while loop has completed the following invariants should hold true: - Debug.Assert(_numBytesPreCompleted >= 0); + // This is called on the libuv event loop + private void ReturnAllBlocks() + { + lock (_returnLock) + { + var block = _head; + while (block != _tail) + { + var returnBlock = block; + block = block.Next; + + returnBlock.Unpin(); + returnBlock.Pool?.Return(returnBlock); + } + + _tail.Unpin(); + + if (_isProducing) + { + _returnFromOnProducingComplete = _tail; + } + else + { + _tail.Pool?.Return(_tail); + } + + _head = null; + _tail = null; } } @@ -263,9 +346,13 @@ namespace Microsoft.AspNet.Server.Kestrel.Http private class WriteContext { + private MemoryPoolIterator2 _lockedStart; + private MemoryPoolIterator2 _lockedEnd; + private int _bufferCount; + private int _byteCount; + public SocketOutput Self; - public Queue> Buffers; public bool SocketShutdownSend; public bool SocketDisconnect; @@ -277,7 +364,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Http public WriteContext(SocketOutput self) { Self = self; - Buffers = new Queue>(); } /// @@ -285,30 +371,28 @@ namespace Microsoft.AspNet.Server.Kestrel.Http /// public void DoWriteIfNeeded() { - if (Buffers.Count == 0 || Self._socket.IsClosed) + LockWrite(); + + if (_byteCount == 0 || Self._socket.IsClosed) { DoShutdownIfNeeded(); return; } - var buffers = new ArraySegment[Buffers.Count]; - - var i = 0; - foreach (var buffer in Buffers) - { - buffers[i++] = buffer; - } - var writeReq = new UvWriteReq(Self._log); writeReq.Init(Self._thread.Loop); - writeReq.Write(Self._socket, new ArraySegment>(buffers), (_writeReq, status, error, state) => + writeReq.Write(Self._socket, _lockedStart, _lockedEnd, _bufferCount, (_writeReq, status, error, state) => { _writeReq.Dispose(); var _this = (WriteContext)state; + _this.ReturnFullyWrittenBlocks(); _this.WriteStatus = status; _this.WriteError = error; _this.DoShutdownIfNeeded(); }, this); + + Self._head = _lockedEnd.Block; + Self._head.Start = _lockedEnd.Index; } /// @@ -348,13 +432,62 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } Self._socket.Dispose(); + Self.ReturnAllBlocks(); Self._log.ConnectionStop(Self._connectionId); Complete(); } public void Complete() { - Self.OnWriteCompleted(Buffers, WriteStatus, WriteError); + Self.OnWriteCompleted(_byteCount, WriteStatus, WriteError); + } + + private void ReturnFullyWrittenBlocks() + { + var block = _lockedStart.Block; + while (block != _lockedEnd.Block) + { + var returnBlock = block; + block = block.Next; + + returnBlock.Unpin(); + returnBlock.Pool?.Return(returnBlock); + } + } + + private void LockWrite() + { + var head = Self._head; + var tail = Self._tail; + + if (head == null || tail == null) + { + // ReturnAllBlocks has already bee called. Nothing to do here. + // Write will no-op since _byteCount will remain 0. + return; + } + + _lockedStart = new MemoryPoolIterator2(head, head.Start); + _lockedEnd = new MemoryPoolIterator2(tail, tail.End); + + if (_lockedStart.Block == _lockedEnd.Block) + { + _byteCount = _lockedEnd.Index - _lockedStart.Index; + _bufferCount = 1; + return; + } + + _byteCount = _lockedStart.Block.Data.Offset + _lockedStart.Block.Data.Count - _lockedStart.Index; + _bufferCount = 1; + + for (var block = _lockedStart.Block.Next; block != _lockedEnd.Block; block = block.Next) + { + _byteCount += block.Data.Count; + _bufferCount++; + } + + _byteCount += _lockedEnd.Index - _lockedEnd.Block.Data.Offset; + _bufferCount++; } } } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPool2.cs b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPool2.cs index 37d64ddcaf..446f03c2b3 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPool2.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPool2.cs @@ -59,7 +59,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure /// The block returned must be at least this size. It may be larger than this minimum size, and if so, /// the caller may write to the block's entire size rather than being limited to the minumumSize requested. /// The block that is reserved for the called. It must be passed to Return when it is no longer being used. - public MemoryPoolBlock2 Lease(int minimumSize) + public MemoryPoolBlock2 Lease(int minimumSize = _blockLength) { if (minimumSize > _blockLength) { diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolBlock2.cs b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolBlock2.cs index a93e03186d..2bcd21d9a2 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolBlock2.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolBlock2.cs @@ -98,24 +98,27 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure } /// - /// Called to ensure that a block is pinned, and return the pointer to native memory just after - /// the range of "active" bytes. This is where arriving data is read into. + /// Called to ensure that a block is pinned, and return the pointer to the native address + /// of the first byte of this block's Data memory. Arriving data is read into Pin() + End. + /// Outgoing data is read from Pin() + Start. /// /// public IntPtr Pin() { - Debug.Assert(!_pinHandle.IsAllocated); - if (_dataArrayPtr != IntPtr.Zero) { // this is a slab managed block - use the native address of the slab which is always locked - return _dataArrayPtr + End; + return _dataArrayPtr; + } + else if (_pinHandle.IsAllocated) + { + return _pinHandle.AddrOfPinnedObject(); } else { // this is one-time-use memory - lock the managed memory until Unpin is called _pinHandle = GCHandle.Alloc(Data.Array, GCHandleType.Pinned); - return _pinHandle.AddrOfPinnedObject() + End; + return _pinHandle.AddrOfPinnedObject(); } } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolIterator2.cs b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolIterator2.cs index 7bf514707e..6c5c1f205a 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolIterator2.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolIterator2.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Diagnostics; using System.Linq; using System.Numerics; @@ -530,5 +531,46 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure } } } + + public MemoryPoolIterator2 CopyFrom(ArraySegment buffer) + { + Debug.Assert(_block != null); + Debug.Assert(_block.Pool != null); + Debug.Assert(_block.Next == null); + Debug.Assert(_block.End == _index); + + var pool = _block.Pool; + var block = _block; + var blockIndex = _index; + + var bufferIndex = buffer.Offset; + var remaining = buffer.Count; + + while (remaining > 0) + { + var bytesLeftInBlock = block.Data.Offset + block.Data.Count - blockIndex; + + if (bytesLeftInBlock == 0) + { + var nextBlock = pool.Lease(); + block.Next = nextBlock; + block = nextBlock; + + blockIndex = block.Data.Offset; + bytesLeftInBlock = block.Data.Count; + } + + var bytesToCopy = Math.Min(remaining, bytesLeftInBlock); + + Buffer.BlockCopy(buffer.Array, bufferIndex, block.Array, blockIndex, bytesToCopy); + + blockIndex += bytesToCopy; + bufferIndex += bytesToCopy; + remaining -= bytesToCopy; + block.End = blockIndex; + } + + return new MemoryPoolIterator2(block, blockIndex); + } } } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvWriteReq.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvWriteReq.cs index 103ddfc6ee..7330ef3c15 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvWriteReq.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvWriteReq.cs @@ -41,7 +41,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking public unsafe void Write( UvStreamHandle handle, - ArraySegment> bufs, + MemoryPoolIterator2 start, + MemoryPoolIterator2 end, + int nBuffers, Action callback, object state) { @@ -51,7 +53,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking _pins.Add(GCHandle.Alloc(this, GCHandleType.Normal)); var pBuffers = (Libuv.uv_buf_t*)_bufs; - var nBuffers = bufs.Count; if (nBuffers > BUFFER_COUNT) { // create and pin buffer array when it's larger than the pre-allocated one @@ -61,16 +62,18 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking pBuffers = (Libuv.uv_buf_t*)gcHandle.AddrOfPinnedObject(); } + var block = start.Block; for (var index = 0; index < nBuffers; index++) { - // create and pin each segment being written - var buf = bufs.Array[bufs.Offset + index]; + var blockStart = block == start.Block ? start.Index : block.Data.Offset; + var blockEnd = block == end.Block ? end.Index : block.Data.Offset + block.Data.Count; - var gcHandle = GCHandle.Alloc(buf.Array, GCHandleType.Pinned); - _pins.Add(gcHandle); + // create and pin each segment being written pBuffers[index] = Libuv.buf_init( - gcHandle.AddrOfPinnedObject() + buf.Offset, - buf.Count); + block.Pin() + blockStart, + blockEnd - blockStart); + + block = block.Next; } _callback = callback; diff --git a/test/Microsoft.AspNet.Server.KestrelTests/MemoryPoolBlock2Tests.cs b/test/Microsoft.AspNet.Server.KestrelTests/MemoryPoolBlock2Tests.cs index db3b03802f..5f445ef487 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/MemoryPoolBlock2Tests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/MemoryPoolBlock2Tests.cs @@ -1,4 +1,5 @@ -using System.Linq; +using System; +using System.Linq; using Microsoft.AspNet.Server.Kestrel.Infrastructure; using Xunit; @@ -152,6 +153,38 @@ namespace Microsoft.AspNet.Server.KestrelTests } } + [Fact] + public void CopyFromCorrectlyTraversesBlocks() + { + using (var pool = new MemoryPool2()) + { + var block1 = pool.Lease(128); + var iterator = block1.GetIterator(); + var bufferSize = block1.Data.Count * 3; + var buffer = new byte[bufferSize]; + + for (int i = 0; i < bufferSize; i++) + { + buffer[i] = (byte)(i % 73); + } + + Assert.Null(block1.Next); + + var end = iterator.CopyFrom(new ArraySegment(buffer)); + + Assert.NotNull(block1.Next); + + for (int i = 0; i < bufferSize; i++) + { + Assert.Equal(i % 73, iterator.Take()); + } + + Assert.Equal(-1, iterator.Take()); + Assert.Equal(iterator.Block, end.Block); + Assert.Equal(iterator.Index, end.Index); + } + } + [Fact] public void IsEndCorrectlyTraversesBlocks() { diff --git a/test/Microsoft.AspNet.Server.KestrelTests/MultipleLoopTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/MultipleLoopTests.cs index f57c899f6a..44a5757f80 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/MultipleLoopTests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/MultipleLoopTests.cs @@ -62,14 +62,24 @@ namespace Microsoft.AspNet.Server.KestrelTests var writeRequest = new UvWriteReq(new KestrelTrace(new TestKestrelTrace())); writeRequest.Init(loop); + var block = MemoryPoolBlock2.Create( + new ArraySegment(new byte[] { 1, 2, 3, 4 }), + dataPtr: IntPtr.Zero, + pool: null, + slab: null); + var start = new MemoryPoolIterator2(block, 0); + var end = new MemoryPoolIterator2(block, block.Data.Count); writeRequest.Write( serverConnectionPipe, - new ArraySegment>(new ArraySegment[] { new ArraySegment(new byte[] { 1, 2, 3, 4 }) }), + start, + end, + 1, (_3, status2, error2, _4) => { writeRequest.Dispose(); serverConnectionPipe.Dispose(); serverListenPipe.Dispose(); + block.Unpin(); }, null); diff --git a/test/Microsoft.AspNet.Server.KestrelTests/NetworkingTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/NetworkingTests.cs index fa8a3ada30..edaa50870e 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/NetworkingTests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/NetworkingTests.cs @@ -201,12 +201,22 @@ namespace Microsoft.AspNet.Server.KestrelTests { var req = new UvWriteReq(new KestrelTrace(new TestKestrelTrace())); req.Init(loop); + var block = MemoryPoolBlock2.Create( + new ArraySegment(new byte[] { 65, 66, 67, 68, 69 }), + dataPtr: IntPtr.Zero, + pool: null, + slab: null); + var start = new MemoryPoolIterator2(block, 0); + var end = new MemoryPoolIterator2(block, block.Data.Count); req.Write( tcp2, - new ArraySegment>( - new[] { new ArraySegment(new byte[] { 65, 66, 67, 68, 69 }) } - ), - (_1, _2, _3, _4) => { }, + start, + end, + 1, + (_1, _2, _3, _4) => + { + block.Unpin(); + }, null); } } diff --git a/test/Microsoft.AspNet.Server.KestrelTests/SocketOutputTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/SocketOutputTests.cs index 69224073dc..629c35407c 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/SocketOutputTests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/SocketOutputTests.cs @@ -34,13 +34,14 @@ namespace Microsoft.AspNet.Server.KestrelTests }; using (var kestrelEngine = new KestrelEngine(mockLibuv, new TestServiceContext())) + using (var memory = new MemoryPool2()) { kestrelEngine.Start(count: 1); var kestrelThread = kestrelEngine.Threads[0]; var socket = new MockSocket(kestrelThread.Loop.ThreadId, new TestKestrelTrace()); var trace = new KestrelTrace(new TestKestrelTrace()); - var socketOutput = new SocketOutput(kestrelThread, socket, null, 0, trace); + var socketOutput = new SocketOutput(kestrelThread, socket, memory, null, 0, trace); // I doubt _maxBytesPreCompleted will ever be over a MB. If it is, we should change this test. var bufferSize = 1048576; @@ -79,13 +80,14 @@ namespace Microsoft.AspNet.Server.KestrelTests }; using (var kestrelEngine = new KestrelEngine(mockLibuv, new TestServiceContext())) + using (var memory = new MemoryPool2()) { kestrelEngine.Start(count: 1); var kestrelThread = kestrelEngine.Threads[0]; var socket = new MockSocket(kestrelThread.Loop.ThreadId, new TestKestrelTrace()); var trace = new KestrelTrace(new TestKestrelTrace()); - var socketOutput = new SocketOutput(kestrelThread, socket, null, 0, trace); + var socketOutput = new SocketOutput(kestrelThread, socket, memory, null, 0, trace); var bufferSize = maxBytesPreCompleted; var buffer = new ArraySegment(new byte[bufferSize], 0, bufferSize); @@ -134,13 +136,14 @@ namespace Microsoft.AspNet.Server.KestrelTests }; using (var kestrelEngine = new KestrelEngine(mockLibuv, new TestServiceContext())) + using (var memory = new MemoryPool2()) { kestrelEngine.Start(count: 1); var kestrelThread = kestrelEngine.Threads[0]; var socket = new MockSocket(kestrelThread.Loop.ThreadId, new TestKestrelTrace()); var trace = new KestrelTrace(new TestKestrelTrace()); - var socketOutput = new SocketOutput(kestrelThread, socket, null, 0, trace); + var socketOutput = new SocketOutput(kestrelThread, socket, memory, null, 0, trace); var bufferSize = maxBytesPreCompleted; @@ -213,13 +216,14 @@ namespace Microsoft.AspNet.Server.KestrelTests }; using (var kestrelEngine = new KestrelEngine(mockLibuv, new TestServiceContext())) + using (var memory = new MemoryPool2()) { kestrelEngine.Start(count: 1); var kestrelThread = kestrelEngine.Threads[0]; var socket = new MockSocket(kestrelThread.Loop.ThreadId, new TestKestrelTrace()); var trace = new KestrelTrace(new TestKestrelTrace()); - var socketOutput = new SocketOutput(kestrelThread, socket, null, 0, trace); + var socketOutput = new SocketOutput(kestrelThread, socket, memory, null, 0, trace); var bufferSize = maxBytesPreCompleted; var buffer = new ArraySegment(new byte[bufferSize], 0, bufferSize); @@ -270,6 +274,57 @@ namespace Microsoft.AspNet.Server.KestrelTests } } + [Fact] + public void ProducingStartAndProducingCompleteCanBeUsedDirectly() + { + int nBuffers = 0; + var nBufferWh = new ManualResetEventSlim(); + + var mockLibuv = new MockLibuv + { + OnWrite = (socket, buffers, triggerCompleted) => + { + nBuffers = buffers; + nBufferWh.Set(); + triggerCompleted(0); + return 0; + } + }; + + using (var kestrelEngine = new KestrelEngine(mockLibuv, new TestServiceContext())) + using (var memory = new MemoryPool2()) + { + kestrelEngine.Start(count: 1); + + var kestrelThread = kestrelEngine.Threads[0]; + var socket = new MockSocket(kestrelThread.Loop.ThreadId, new TestKestrelTrace()); + var trace = new KestrelTrace(new TestKestrelTrace()); + var socketOutput = new SocketOutput(kestrelThread, socket, memory, null, 0, trace); + + // block 1 + var start = socketOutput.ProducingStart(); + start.Block.End = start.Block.Data.Offset + start.Block.Data.Count; + var totalBytes = start.Block.Data.Count; + + // block 2 + var block2 = memory.Lease(); + block2.End = block2.Data.Offset + block2.Data.Count; + start.Block.Next = block2; + totalBytes += block2.Data.Count; + + var end = new MemoryPoolIterator2(block2, block2.End); + + socketOutput.ProducingComplete(end, totalBytes); + + // A call to Write is required to ensure a write is scheduled + socketOutput.WriteAsync(default(ArraySegment)); + + Assert.True(nBufferWh.Wait(1000)); + Assert.Equal(2, nBuffers); + } + } + + private class MockSocket : UvStreamHandle { public MockSocket(int threadId, IKestrelTrace logger) : base(logger) diff --git a/test/Microsoft.AspNet.Server.KestrelTests/TestHelpers/MockLibuv.cs b/test/Microsoft.AspNet.Server.KestrelTests/TestHelpers/MockLibuv.cs index 1134ae8fab..9a05659186 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/TestHelpers/MockLibuv.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/TestHelpers/MockLibuv.cs @@ -12,7 +12,7 @@ namespace Microsoft.AspNet.Server.KestrelTests.TestHelpers private bool _stopLoop; private readonly ManualResetEventSlim _loopWh = new ManualResetEventSlim(); - private Func>, Action, int> _onWrite; + private Func, int> _onWrite; unsafe public MockLibuv() { @@ -68,7 +68,7 @@ namespace Microsoft.AspNet.Server.KestrelTests.TestHelpers _uv_walk = (loop, callback, ignore) => 0; } - public Func>, Action, int> OnWrite + public Func, int> OnWrite { get { @@ -82,7 +82,7 @@ namespace Microsoft.AspNet.Server.KestrelTests.TestHelpers unsafe private int UvWrite(UvRequest req, UvStreamHandle handle, uv_buf_t* bufs, int nbufs, uv_write_cb cb) { - return _onWrite(handle, new ArraySegment>(), status => cb(req.InternalGetHandle(), status)); + return _onWrite(handle, nbufs, status => cb(req.InternalGetHandle(), status)); } } } From 0dbf1083536bcc6a71f1b1389235fbc6612f152e Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Fri, 20 Nov 2015 12:59:53 -0800 Subject: [PATCH 0464/1662] Smarter unpinning of MemoryPoolBlock2 in SocketOutput --- src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs | 6 +++--- .../Infrastructure/MemoryPoolBlock2.cs | 6 ++---- .../Networking/UvWriteReq.cs | 8 ++++++++ 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs index be47d8e720..404cb601d5 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs @@ -305,12 +305,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Http var returnBlock = block; block = block.Next; - returnBlock.Unpin(); returnBlock.Pool?.Return(returnBlock); } - _tail.Unpin(); - if (_isProducing) { _returnFromOnProducingComplete = _tail; @@ -381,6 +378,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http var writeReq = new UvWriteReq(Self._log); writeReq.Init(Self._thread.Loop); + writeReq.Write(Self._socket, _lockedStart, _lockedEnd, _bufferCount, (_writeReq, status, error, state) => { _writeReq.Dispose(); @@ -453,6 +451,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http returnBlock.Unpin(); returnBlock.Pool?.Return(returnBlock); } + + _lockedEnd.Block.Unpin(); } private void LockWrite() diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolBlock2.cs b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolBlock2.cs index 2bcd21d9a2..26156c6cc0 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolBlock2.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolBlock2.cs @@ -105,15 +105,13 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure /// public IntPtr Pin() { + Debug.Assert(!_pinHandle.IsAllocated); + if (_dataArrayPtr != IntPtr.Zero) { // this is a slab managed block - use the native address of the slab which is always locked return _dataArrayPtr; } - else if (_pinHandle.IsAllocated) - { - return _pinHandle.AddrOfPinnedObject(); - } else { // this is one-time-use memory - lock the managed memory until Unpin is called diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvWriteReq.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvWriteReq.cs index 7330ef3c15..2695036f32 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvWriteReq.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvWriteReq.cs @@ -85,6 +85,14 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking _callback = null; _state = null; Unpin(this); + + var block = start.Block; + for (var index = 0; index < nBuffers; index++) + { + block.Unpin(); + block = block.Next; + } + throw; } } From a3173c487a1adb72a908e69e0a88a51c3b8f2cc1 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Wed, 11 Nov 2015 17:20:31 +0000 Subject: [PATCH 0465/1662] Precomputed header bytes --- .../Http/DateHeaderValueManager.cs | 14 + .../Http/Frame.cs | 192 +-- .../Http/FrameHeaders.Generated.cs | 1070 +++++++++++------ .../Http/FrameResponseHeaders.cs | 31 +- .../Http/MemoryPool.cs | 125 -- .../Http/MemoryPoolTextWriter.cs | 155 --- .../Http/ReasonPhrases.cs | 173 ++- .../Infrastructure/MemoryPool2.cs | 8 +- .../Infrastructure/MemoryPoolIterator2.cs | 104 ++ .../ServiceContext.cs | 4 - .../EngineTests.cs | 25 +- .../TestInput.cs | 2 - .../KnownHeaders.cs | 128 +- 13 files changed, 1231 insertions(+), 800 deletions(-) delete mode 100644 src/Microsoft.AspNet.Server.Kestrel/Http/MemoryPool.cs delete mode 100644 src/Microsoft.AspNet.Server.Kestrel/Http/MemoryPoolTextWriter.cs diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/DateHeaderValueManager.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/DateHeaderValueManager.cs index c471067eca..b85aaa2b1a 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/DateHeaderValueManager.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/DateHeaderValueManager.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Text; using System.Threading; using Microsoft.AspNet.Server.Kestrel.Infrastructure; @@ -17,6 +18,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Http private readonly TimeSpan _timerInterval; private volatile string _dateValue; + private volatile bool _activeDateBytes; + private readonly byte[] _dateBytes0 = Encoding.ASCII.GetBytes("\r\nDate: DDD, dd mmm yyyy hh:mm:ss GMT"); + private readonly byte[] _dateBytes1 = Encoding.ASCII.GetBytes("\r\nDate: DDD, dd mmm yyyy hh:mm:ss GMT"); private object _timerLocker = new object(); private bool _isDisposed = false; private bool _hadRequestsSinceLastTimerTick = false; @@ -62,6 +66,12 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return _dateValue ?? _systemClock.UtcNow.ToString(Constants.RFC1123DateFormat); } + public byte[] GetDateHeaderValueBytes() + { + PumpTimer(); + return _activeDateBytes ? _dateBytes0 : _dateBytes1; + } + /// /// Releases all resources used by the current instance of . /// @@ -92,6 +102,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http // here as the timer won't fire until the timer interval has passed and we want a value assigned // inline now to serve requests that occur in the meantime. _dateValue = _systemClock.UtcNow.ToString(Constants.RFC1123DateFormat); + Encoding.ASCII.GetBytes(_dateValue, 0, _dateValue.Length, !_activeDateBytes ? _dateBytes0 : _dateBytes1, "\r\nDate: ".Length); + _activeDateBytes = !_activeDateBytes; _dateValueTimer = new Timer(UpdateDateValue, state: null, dueTime: _timerInterval, period: _timerInterval); } } @@ -105,6 +117,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http // See http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.18 for required format of Date header _dateValue = now.ToString(Constants.RFC1123DateFormat); + Encoding.ASCII.GetBytes(_dateValue, 0, _dateValue.Length, !_activeDateBytes ? _dateBytes0 : _dateBytes1, "\r\nDate: ".Length); + _activeDateBytes = !_activeDateBytes; if (_hadRequestsSinceLastTimerTick) { diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs index 8dc2670a6a..98652050cd 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs @@ -29,6 +29,17 @@ namespace Microsoft.AspNet.Server.Kestrel.Http private static readonly ArraySegment _emptyData = new ArraySegment(new byte[0]); private static readonly byte[] _hex = Encoding.ASCII.GetBytes("0123456789abcdef"); + private static readonly byte[] _bytesConnectionClose = Encoding.ASCII.GetBytes("\r\nConnection: close"); + private static readonly byte[] _bytesConnectionKeepAlive = Encoding.ASCII.GetBytes("\r\nConnection: keep-alive"); + private static readonly byte[] _bytesTransferEncodingChunked = Encoding.ASCII.GetBytes("\r\nTransfer-Encoding: chunked"); + private static readonly byte[] _bytesHttpVersion1_0 = Encoding.ASCII.GetBytes("HTTP/1.0 "); + private static readonly byte[] _bytesHttpVersion1_1 = Encoding.ASCII.GetBytes("HTTP/1.1 "); + private static readonly byte[] _bytesContentLengthZero = Encoding.ASCII.GetBytes("\r\nContent-Length: 0"); + private static readonly byte[] _bytesSpace = Encoding.ASCII.GetBytes(" "); + private static readonly byte[] _bytesServer = Encoding.ASCII.GetBytes("\r\nServer: Kestrel"); + private static readonly byte[] _bytesDate = Encoding.ASCII.GetBytes("Date: "); + private static readonly byte[] _bytesEndHeaders = Encoding.ASCII.GetBytes("\r\n\r\n"); + private readonly object _onStartingSync = new Object(); private readonly object _onCompletedSync = new Object(); private readonly FrameRequestHeaders _requestHeaders = new FrameRequestHeaders(); @@ -53,6 +64,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http private bool _autoChunk; private Exception _applicationException; + private HttpVersionType _httpVersion; + private readonly IPEndPoint _localEndPoint; private readonly IPEndPoint _remoteEndPoint; private readonly Action _prepareRequest; @@ -81,7 +94,37 @@ namespace Microsoft.AspNet.Server.Kestrel.Http public string RequestUri { get; set; } public string Path { get; set; } public string QueryString { get; set; } - public string HttpVersion { get; set; } + public string HttpVersion + { + get + { + if (_httpVersion == HttpVersionType.Http1_1) + { + return "HTTP/1.1"; + } + if (_httpVersion == HttpVersionType.Http1_0) + { + return "HTTP/1.0"; + } + return ""; + } + set + { + if (value == "HTTP/1.1") + { + _httpVersion = HttpVersionType.Http1_1; + } + else if (value == "HTTP/1.0") + { + _httpVersion = HttpVersionType.Http1_0; + } + else + { + _httpVersion = HttpVersionType.Unknown; + } + } + } + public IHeaderDictionary RequestHeaders { get; set; } public Stream RequestBody { get; set; } @@ -118,7 +161,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http RequestUri = null; Path = null; QueryString = null; - HttpVersion = null; + _httpVersion = HttpVersionType.Unknown; RequestHeaders = _requestHeaders; RequestBody = null; StatusCode = 200; @@ -151,8 +194,12 @@ namespace Microsoft.AspNet.Server.Kestrel.Http public void ResetResponseHeaders() { _responseHeaders.Reset(); - _responseHeaders.HeaderServer = "Kestrel"; - _responseHeaders.HeaderDate = DateHeaderValueManager.GetDateHeaderValue(); + _responseHeaders.SetRawDate( + DateHeaderValueManager.GetDateHeaderValue(), + DateHeaderValueManager.GetDateHeaderValueBytes()); + _responseHeaders.SetRawServer( + "Kestrel", + _bytesServer); } /// @@ -502,7 +549,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http if (_responseStarted) return; StringValues expect; - if (HttpVersion.Equals("HTTP/1.1") && + if (_httpVersion == HttpVersionType.Http1_1 && RequestHeaders.TryGetValue("Expect", out expect) && (expect.FirstOrDefault() ?? "").Equals("100-continue", StringComparison.OrdinalIgnoreCase)) { @@ -526,19 +573,14 @@ namespace Microsoft.AspNet.Server.Kestrel.Http await ProduceStart(immediate, appCompleted: false); } - private async Task ProduceStart(bool immediate, bool appCompleted) + private Task ProduceStart(bool immediate, bool appCompleted) { - if (_responseStarted) return; + if (_responseStarted) return TaskUtilities.CompletedTask; _responseStarted = true; - var status = ReasonPhrases.ToStatus(StatusCode, ReasonPhrase); + var statusBytes = ReasonPhrases.ToStatusBytes(StatusCode, ReasonPhrase); - var responseHeader = CreateResponseHeader(status, appCompleted); - - using (responseHeader.Item2) - { - await SocketOutput.WriteAsync(responseHeader.Item1, immediate: immediate); - } + return CreateResponseHeader(statusBytes, appCompleted, immediate); } private async Task ProduceEnd() @@ -557,7 +599,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http ReasonPhrase = null; ResetResponseHeaders(); - _responseHeaders.HeaderContentLength = "0"; + _responseHeaders.SetRawContentLength("0", _bytesContentLengthZero); } } @@ -576,58 +618,26 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } - private Tuple, IDisposable> CreateResponseHeader( - string status, - bool appCompleted) + private Task CreateResponseHeader( + byte[] statusBytes, + bool appCompleted, + bool immediate) { - var writer = new MemoryPoolTextWriter(Memory); - writer.Write(HttpVersion); - writer.Write(' '); - writer.Write(status); - writer.Write('\r'); - writer.Write('\n'); - - var hasConnection = false; - var hasTransferEncoding = false; - var hasContentLength = false; - - foreach (var header in _responseHeaders) + var memoryBlock = Memory2.Lease(); + var begin = memoryBlock.GetIterator(); + var end = begin; + if (_keepAlive) { - var isConnection = false; - if (!hasConnection && - string.Equals(header.Key, "Connection", StringComparison.OrdinalIgnoreCase)) + foreach (var connectionValue in _responseHeaders.HeaderConnection) { - hasConnection = isConnection = true; - } - else if (!hasTransferEncoding && - string.Equals(header.Key, "Transfer-Encoding", StringComparison.OrdinalIgnoreCase)) - { - hasTransferEncoding = true; - } - else if (!hasContentLength && - string.Equals(header.Key, "Content-Length", StringComparison.OrdinalIgnoreCase)) - { - hasContentLength = true; - } - - foreach (var value in header.Value) - { - writer.Write(header.Key); - writer.Write(':'); - writer.Write(' '); - writer.Write(value); - writer.Write('\r'); - writer.Write('\n'); - - if (isConnection && value.IndexOf("close", StringComparison.OrdinalIgnoreCase) != -1) + if (connectionValue.IndexOf("close", StringComparison.OrdinalIgnoreCase) != -1) { _keepAlive = false; } } - } - if (_keepAlive && !hasTransferEncoding && !hasContentLength) + if (_keepAlive && !_responseHeaders.HasTransferEncoding && !_responseHeaders.HasContentLength) { if (appCompleted) { @@ -637,15 +647,15 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { // Since the app has completed and we are only now generating // the headers we can safely set the Content-Length to 0. - writer.Write("Content-Length: 0\r\n"); + _responseHeaders.SetRawContentLength("0", _bytesContentLengthZero); } } else { - if (HttpVersion == "HTTP/1.1") + if (_httpVersion == HttpVersionType.Http1_1) { _autoChunk = true; - writer.Write("Transfer-Encoding: chunked\r\n"); + _responseHeaders.SetRawTransferEncoding("chunked", _bytesTransferEncodingChunked); } else { @@ -654,21 +664,58 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } - if (_keepAlive == false && hasConnection == false && HttpVersion == "HTTP/1.1") + if (_keepAlive == false && _responseHeaders.HasConnection == false && _httpVersion == HttpVersionType.Http1_1) { - writer.Write("Connection: close\r\n\r\n"); + _responseHeaders.SetRawConnection("close", _bytesConnectionClose); } - else if (_keepAlive && hasConnection == false && HttpVersion == "HTTP/1.0") + else if (_keepAlive && _responseHeaders.HasConnection == false && _httpVersion == HttpVersionType.Http1_0) { - writer.Write("Connection: keep-alive\r\n\r\n"); + _responseHeaders.SetRawConnection("keep-alive", _bytesConnectionKeepAlive); + } + + end.CopyFrom(_httpVersion == HttpVersionType.Http1_1 ? _bytesHttpVersion1_1 : _bytesHttpVersion1_0); + end.CopyFrom(statusBytes); + _responseHeaders.CopyTo(ref end); + end.CopyFrom(_bytesEndHeaders, 0, _bytesEndHeaders.Length); + + // TODO: change this to SocketOutput.ProduceStart/ProduceComplete once that change is made + var scan = begin.Block; + while (scan.Next != null) + { + if (scan.Start != scan.End) + { + SocketOutput.WriteAsync( + new ArraySegment(scan.Array, scan.Start, scan.End - scan.Start), + false); + } + var next = scan.Next; + Memory2.Return(scan); + scan = next; + } + var writeTask = SocketOutput.WriteAsync( + new ArraySegment(scan.Array, scan.Start, scan.End - scan.Start), + immediate); + + if (writeTask.IsCompleted) + { + Memory2.Return(scan); + return TaskUtilities.CompletedTask; } else { - writer.Write('\r'); - writer.Write('\n'); + return writeTask.ContinueWith( + (t, o) => + { + var mb = (MemoryPoolBlock2)o; + mb.Pool.Return(mb); + + if (t.IsFaulted) + { + throw t.Exception; + } + }, + scan); } - writer.Flush(); - return new Tuple, IDisposable>(writer.Buffer, writer); } private bool TakeStartLine(SocketInput input) @@ -877,5 +924,12 @@ namespace Microsoft.AspNet.Server.Kestrel.Http _applicationException = ex; Log.ApplicationError(ex); } + + private enum HttpVersionType + { + Unknown = -1, + Http1_0 = 0, + Http1_1 = 1 + } } } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameHeaders.Generated.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameHeaders.Generated.cs index 1b4415b5a9..5571e9c56b 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameHeaders.Generated.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameHeaders.Generated.cs @@ -1,13 +1,16 @@ using System; using System.Collections.Generic; +using System.Text; +using Microsoft.AspNet.Server.Kestrel.Infrastructure; using Microsoft.Extensions.Primitives; namespace Microsoft.AspNet.Server.Kestrel.Http { - public partial class FrameRequestHeaders + public partial class FrameRequestHeaders { + private long _bits = 0; private StringValues _CacheControl; @@ -52,6 +55,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http private StringValues _Translate; private StringValues _UserAgent; + public StringValues HeaderCacheControl { get @@ -61,10 +65,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Http set { _bits |= 1L; - _CacheControl = value; + _CacheControl = value; } } - public StringValues HeaderConnection { get @@ -74,10 +77,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Http set { _bits |= 2L; - _Connection = value; + _Connection = value; } } - public StringValues HeaderDate { get @@ -87,10 +89,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Http set { _bits |= 4L; - _Date = value; + _Date = value; } } - public StringValues HeaderKeepAlive { get @@ -100,10 +101,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Http set { _bits |= 8L; - _KeepAlive = value; + _KeepAlive = value; } } - public StringValues HeaderPragma { get @@ -113,10 +113,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Http set { _bits |= 16L; - _Pragma = value; + _Pragma = value; } } - public StringValues HeaderTrailer { get @@ -126,10 +125,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Http set { _bits |= 32L; - _Trailer = value; + _Trailer = value; } } - public StringValues HeaderTransferEncoding { get @@ -139,10 +137,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Http set { _bits |= 64L; - _TransferEncoding = value; + _TransferEncoding = value; } } - public StringValues HeaderUpgrade { get @@ -152,10 +149,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Http set { _bits |= 128L; - _Upgrade = value; + _Upgrade = value; } } - public StringValues HeaderVia { get @@ -165,10 +161,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Http set { _bits |= 256L; - _Via = value; + _Via = value; } } - public StringValues HeaderWarning { get @@ -178,10 +173,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Http set { _bits |= 512L; - _Warning = value; + _Warning = value; } } - public StringValues HeaderAllow { get @@ -191,10 +185,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Http set { _bits |= 1024L; - _Allow = value; + _Allow = value; } } - public StringValues HeaderContentLength { get @@ -204,10 +197,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Http set { _bits |= 2048L; - _ContentLength = value; + _ContentLength = value; } } - public StringValues HeaderContentType { get @@ -217,10 +209,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Http set { _bits |= 4096L; - _ContentType = value; + _ContentType = value; } } - public StringValues HeaderContentEncoding { get @@ -230,10 +221,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Http set { _bits |= 8192L; - _ContentEncoding = value; + _ContentEncoding = value; } } - public StringValues HeaderContentLanguage { get @@ -243,10 +233,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Http set { _bits |= 16384L; - _ContentLanguage = value; + _ContentLanguage = value; } } - public StringValues HeaderContentLocation { get @@ -256,10 +245,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Http set { _bits |= 32768L; - _ContentLocation = value; + _ContentLocation = value; } } - public StringValues HeaderContentMD5 { get @@ -269,10 +257,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Http set { _bits |= 65536L; - _ContentMD5 = value; + _ContentMD5 = value; } } - public StringValues HeaderContentRange { get @@ -282,10 +269,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Http set { _bits |= 131072L; - _ContentRange = value; + _ContentRange = value; } } - public StringValues HeaderExpires { get @@ -295,10 +281,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Http set { _bits |= 262144L; - _Expires = value; + _Expires = value; } } - public StringValues HeaderLastModified { get @@ -308,10 +293,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Http set { _bits |= 524288L; - _LastModified = value; + _LastModified = value; } } - public StringValues HeaderAccept { get @@ -321,10 +305,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Http set { _bits |= 1048576L; - _Accept = value; + _Accept = value; } } - public StringValues HeaderAcceptCharset { get @@ -334,10 +317,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Http set { _bits |= 2097152L; - _AcceptCharset = value; + _AcceptCharset = value; } } - public StringValues HeaderAcceptEncoding { get @@ -347,10 +329,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Http set { _bits |= 4194304L; - _AcceptEncoding = value; + _AcceptEncoding = value; } } - public StringValues HeaderAcceptLanguage { get @@ -360,10 +341,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Http set { _bits |= 8388608L; - _AcceptLanguage = value; + _AcceptLanguage = value; } } - public StringValues HeaderAuthorization { get @@ -373,10 +353,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Http set { _bits |= 16777216L; - _Authorization = value; + _Authorization = value; } } - public StringValues HeaderCookie { get @@ -386,10 +365,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Http set { _bits |= 33554432L; - _Cookie = value; + _Cookie = value; } } - public StringValues HeaderExpect { get @@ -399,10 +377,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Http set { _bits |= 67108864L; - _Expect = value; + _Expect = value; } } - public StringValues HeaderFrom { get @@ -412,10 +389,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Http set { _bits |= 134217728L; - _From = value; + _From = value; } } - public StringValues HeaderHost { get @@ -425,10 +401,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Http set { _bits |= 268435456L; - _Host = value; + _Host = value; } } - public StringValues HeaderIfMatch { get @@ -438,10 +413,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Http set { _bits |= 536870912L; - _IfMatch = value; + _IfMatch = value; } } - public StringValues HeaderIfModifiedSince { get @@ -451,10 +425,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Http set { _bits |= 1073741824L; - _IfModifiedSince = value; + _IfModifiedSince = value; } } - public StringValues HeaderIfNoneMatch { get @@ -464,10 +437,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Http set { _bits |= 2147483648L; - _IfNoneMatch = value; + _IfNoneMatch = value; } } - public StringValues HeaderIfRange { get @@ -477,10 +449,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Http set { _bits |= 4294967296L; - _IfRange = value; + _IfRange = value; } } - public StringValues HeaderIfUnmodifiedSince { get @@ -490,10 +461,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Http set { _bits |= 8589934592L; - _IfUnmodifiedSince = value; + _IfUnmodifiedSince = value; } } - public StringValues HeaderMaxForwards { get @@ -503,10 +473,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Http set { _bits |= 17179869184L; - _MaxForwards = value; + _MaxForwards = value; } } - public StringValues HeaderProxyAuthorization { get @@ -516,10 +485,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Http set { _bits |= 34359738368L; - _ProxyAuthorization = value; + _ProxyAuthorization = value; } } - public StringValues HeaderReferer { get @@ -529,10 +497,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Http set { _bits |= 68719476736L; - _Referer = value; + _Referer = value; } } - public StringValues HeaderRange { get @@ -542,10 +509,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Http set { _bits |= 137438953472L; - _Range = value; + _Range = value; } } - public StringValues HeaderTE { get @@ -555,10 +521,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Http set { _bits |= 274877906944L; - _TE = value; + _TE = value; } } - public StringValues HeaderTranslate { get @@ -568,10 +533,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Http set { _bits |= 549755813888L; - _Translate = value; + _Translate = value; } } - public StringValues HeaderUserAgent { get @@ -581,7 +545,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http set { _bits |= 1099511627776L; - _UserAgent = value; + _UserAgent = value; } } @@ -589,14 +553,13 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { return BitCount(_bits) + (MaybeUnknown?.Count ?? 0); } - protected override StringValues GetValueFast(string key) { switch(key.Length) { case 13: { - if ("Cache-Control".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Cache-Control".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 1L) != 0)) { @@ -608,7 +571,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } - if ("Content-Range".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Content-Range".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 131072L) != 0)) { @@ -620,7 +583,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } - if ("Last-Modified".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Last-Modified".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 524288L) != 0)) { @@ -632,7 +595,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } - if ("Authorization".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Authorization".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 16777216L) != 0)) { @@ -644,7 +607,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } - if ("If-None-Match".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("If-None-Match".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 2147483648L) != 0)) { @@ -657,10 +620,10 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } break; - + case 10: { - if ("Connection".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Connection".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 2L) != 0)) { @@ -672,7 +635,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } - if ("Keep-Alive".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Keep-Alive".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 8L) != 0)) { @@ -684,7 +647,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } - if ("User-Agent".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("User-Agent".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 1099511627776L) != 0)) { @@ -697,10 +660,10 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } break; - + case 4: { - if ("Date".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Date".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 4L) != 0)) { @@ -712,7 +675,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } - if ("From".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("From".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 134217728L) != 0)) { @@ -724,7 +687,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } - if ("Host".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Host".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 268435456L) != 0)) { @@ -737,10 +700,10 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } break; - + case 6: { - if ("Pragma".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Pragma".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 16L) != 0)) { @@ -752,7 +715,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } - if ("Accept".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Accept".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 1048576L) != 0)) { @@ -764,7 +727,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } - if ("Cookie".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Cookie".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 33554432L) != 0)) { @@ -776,7 +739,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } - if ("Expect".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Expect".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 67108864L) != 0)) { @@ -789,10 +752,10 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } break; - + case 7: { - if ("Trailer".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Trailer".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 32L) != 0)) { @@ -804,7 +767,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } - if ("Upgrade".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Upgrade".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 128L) != 0)) { @@ -816,7 +779,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } - if ("Warning".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Warning".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 512L) != 0)) { @@ -828,7 +791,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } - if ("Expires".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Expires".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 262144L) != 0)) { @@ -840,7 +803,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } - if ("Referer".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Referer".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 68719476736L) != 0)) { @@ -853,10 +816,10 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } break; - + case 17: { - if ("Transfer-Encoding".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Transfer-Encoding".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 64L) != 0)) { @@ -868,7 +831,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } - if ("If-Modified-Since".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("If-Modified-Since".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 1073741824L) != 0)) { @@ -881,10 +844,10 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } break; - + case 3: { - if ("Via".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Via".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 256L) != 0)) { @@ -897,10 +860,10 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } break; - + case 5: { - if ("Allow".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Allow".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 1024L) != 0)) { @@ -912,7 +875,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } - if ("Range".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Range".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 137438953472L) != 0)) { @@ -925,10 +888,10 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } break; - + case 14: { - if ("Content-Length".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Content-Length".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 2048L) != 0)) { @@ -940,7 +903,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } - if ("Accept-Charset".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Accept-Charset".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 2097152L) != 0)) { @@ -953,10 +916,10 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } break; - + case 12: { - if ("Content-Type".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Content-Type".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 4096L) != 0)) { @@ -968,7 +931,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } - if ("Max-Forwards".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Max-Forwards".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 17179869184L) != 0)) { @@ -981,10 +944,10 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } break; - + case 16: { - if ("Content-Encoding".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Content-Encoding".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 8192L) != 0)) { @@ -996,7 +959,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } - if ("Content-Language".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Content-Language".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 16384L) != 0)) { @@ -1008,7 +971,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } - if ("Content-Location".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Content-Location".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 32768L) != 0)) { @@ -1021,10 +984,10 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } break; - + case 11: { - if ("Content-MD5".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Content-MD5".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 65536L) != 0)) { @@ -1037,10 +1000,10 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } break; - + case 15: { - if ("Accept-Encoding".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Accept-Encoding".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 4194304L) != 0)) { @@ -1052,7 +1015,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } - if ("Accept-Language".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Accept-Language".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 8388608L) != 0)) { @@ -1065,10 +1028,10 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } break; - + case 8: { - if ("If-Match".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("If-Match".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 536870912L) != 0)) { @@ -1080,7 +1043,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } - if ("If-Range".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("If-Range".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 4294967296L) != 0)) { @@ -1093,10 +1056,10 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } break; - + case 19: { - if ("If-Unmodified-Since".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("If-Unmodified-Since".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 8589934592L) != 0)) { @@ -1108,7 +1071,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } - if ("Proxy-Authorization".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Proxy-Authorization".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 34359738368L) != 0)) { @@ -1121,10 +1084,10 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } break; - + case 2: { - if ("TE".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("TE".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 274877906944L) != 0)) { @@ -1137,10 +1100,10 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } break; - + case 9: { - if ("Translate".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Translate".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 549755813888L) != 0)) { @@ -1153,14 +1116,13 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } break; - } +} if (MaybeUnknown == null) { throw new System.Collections.Generic.KeyNotFoundException(); } return MaybeUnknown[key]; } - protected override bool TryGetValueFast(string key, out StringValues value) { switch(key.Length) @@ -1238,7 +1200,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } break; - + case 10: { if ("Connection".Equals(key, StringComparison.OrdinalIgnoreCase)) @@ -1284,7 +1246,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } break; - + case 4: { if ("Date".Equals(key, StringComparison.OrdinalIgnoreCase)) @@ -1330,7 +1292,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } break; - + case 6: { if ("Pragma".Equals(key, StringComparison.OrdinalIgnoreCase)) @@ -1390,7 +1352,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } break; - + case 7: { if ("Trailer".Equals(key, StringComparison.OrdinalIgnoreCase)) @@ -1464,7 +1426,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } break; - + case 17: { if ("Transfer-Encoding".Equals(key, StringComparison.OrdinalIgnoreCase)) @@ -1496,7 +1458,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } break; - + case 3: { if ("Via".Equals(key, StringComparison.OrdinalIgnoreCase)) @@ -1514,7 +1476,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } break; - + case 5: { if ("Allow".Equals(key, StringComparison.OrdinalIgnoreCase)) @@ -1546,7 +1508,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } break; - + case 14: { if ("Content-Length".Equals(key, StringComparison.OrdinalIgnoreCase)) @@ -1578,7 +1540,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } break; - + case 12: { if ("Content-Type".Equals(key, StringComparison.OrdinalIgnoreCase)) @@ -1610,7 +1572,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } break; - + case 16: { if ("Content-Encoding".Equals(key, StringComparison.OrdinalIgnoreCase)) @@ -1656,7 +1618,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } break; - + case 11: { if ("Content-MD5".Equals(key, StringComparison.OrdinalIgnoreCase)) @@ -1674,7 +1636,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } break; - + case 15: { if ("Accept-Encoding".Equals(key, StringComparison.OrdinalIgnoreCase)) @@ -1706,7 +1668,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } break; - + case 8: { if ("If-Match".Equals(key, StringComparison.OrdinalIgnoreCase)) @@ -1738,7 +1700,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } break; - + case 19: { if ("If-Unmodified-Since".Equals(key, StringComparison.OrdinalIgnoreCase)) @@ -1770,7 +1732,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } break; - + case 2: { if ("TE".Equals(key, StringComparison.OrdinalIgnoreCase)) @@ -1788,7 +1750,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } break; - + case 9: { if ("Translate".Equals(key, StringComparison.OrdinalIgnoreCase)) @@ -1806,11 +1768,10 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } break; - } +} value = StringValues.Empty; return MaybeUnknown?.TryGetValue(key, out value) ?? false; } - protected override void SetValueFast(string key, StringValues value) { switch(key.Length) @@ -1853,7 +1814,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } break; - + case 10: { if ("Connection".Equals(key, StringComparison.OrdinalIgnoreCase)) @@ -1878,7 +1839,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } break; - + case 4: { if ("Date".Equals(key, StringComparison.OrdinalIgnoreCase)) @@ -1903,7 +1864,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } break; - + case 6: { if ("Pragma".Equals(key, StringComparison.OrdinalIgnoreCase)) @@ -1935,7 +1896,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } break; - + case 7: { if ("Trailer".Equals(key, StringComparison.OrdinalIgnoreCase)) @@ -1974,7 +1935,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } break; - + case 17: { if ("Transfer-Encoding".Equals(key, StringComparison.OrdinalIgnoreCase)) @@ -1992,7 +1953,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } break; - + case 3: { if ("Via".Equals(key, StringComparison.OrdinalIgnoreCase)) @@ -2003,7 +1964,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } break; - + case 5: { if ("Allow".Equals(key, StringComparison.OrdinalIgnoreCase)) @@ -2021,7 +1982,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } break; - + case 14: { if ("Content-Length".Equals(key, StringComparison.OrdinalIgnoreCase)) @@ -2039,7 +2000,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } break; - + case 12: { if ("Content-Type".Equals(key, StringComparison.OrdinalIgnoreCase)) @@ -2057,7 +2018,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } break; - + case 16: { if ("Content-Encoding".Equals(key, StringComparison.OrdinalIgnoreCase)) @@ -2082,7 +2043,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } break; - + case 11: { if ("Content-MD5".Equals(key, StringComparison.OrdinalIgnoreCase)) @@ -2093,7 +2054,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } break; - + case 15: { if ("Accept-Encoding".Equals(key, StringComparison.OrdinalIgnoreCase)) @@ -2111,7 +2072,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } break; - + case 8: { if ("If-Match".Equals(key, StringComparison.OrdinalIgnoreCase)) @@ -2129,7 +2090,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } break; - + case 19: { if ("If-Unmodified-Since".Equals(key, StringComparison.OrdinalIgnoreCase)) @@ -2147,7 +2108,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } break; - + case 2: { if ("TE".Equals(key, StringComparison.OrdinalIgnoreCase)) @@ -2158,7 +2119,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } break; - + case 9: { if ("Translate".Equals(key, StringComparison.OrdinalIgnoreCase)) @@ -2169,17 +2130,16 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } break; - } +} Unknown[key] = value; } - protected override void AddValueFast(string key, StringValues value) { switch(key.Length) { case 13: { - if ("Cache-Control".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Cache-Control".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 1L) != 0)) { @@ -2190,7 +2150,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return; } - if ("Content-Range".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Content-Range".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 131072L) != 0)) { @@ -2201,7 +2161,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return; } - if ("Last-Modified".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Last-Modified".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 524288L) != 0)) { @@ -2212,7 +2172,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return; } - if ("Authorization".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Authorization".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 16777216L) != 0)) { @@ -2223,7 +2183,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return; } - if ("If-None-Match".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("If-None-Match".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 2147483648L) != 0)) { @@ -2238,7 +2198,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http case 10: { - if ("Connection".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Connection".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 2L) != 0)) { @@ -2249,7 +2209,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return; } - if ("Keep-Alive".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Keep-Alive".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 8L) != 0)) { @@ -2260,7 +2220,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return; } - if ("User-Agent".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("User-Agent".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 1099511627776L) != 0)) { @@ -2275,7 +2235,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http case 4: { - if ("Date".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Date".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 4L) != 0)) { @@ -2286,7 +2246,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return; } - if ("From".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("From".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 134217728L) != 0)) { @@ -2297,7 +2257,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return; } - if ("Host".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Host".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 268435456L) != 0)) { @@ -2312,7 +2272,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http case 6: { - if ("Pragma".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Pragma".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 16L) != 0)) { @@ -2323,7 +2283,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return; } - if ("Accept".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Accept".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 1048576L) != 0)) { @@ -2334,7 +2294,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return; } - if ("Cookie".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Cookie".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 33554432L) != 0)) { @@ -2345,7 +2305,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return; } - if ("Expect".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Expect".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 67108864L) != 0)) { @@ -2360,7 +2320,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http case 7: { - if ("Trailer".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Trailer".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 32L) != 0)) { @@ -2371,7 +2331,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return; } - if ("Upgrade".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Upgrade".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 128L) != 0)) { @@ -2382,7 +2342,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return; } - if ("Warning".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Warning".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 512L) != 0)) { @@ -2393,7 +2353,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return; } - if ("Expires".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Expires".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 262144L) != 0)) { @@ -2404,7 +2364,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return; } - if ("Referer".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Referer".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 68719476736L) != 0)) { @@ -2419,7 +2379,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http case 17: { - if ("Transfer-Encoding".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Transfer-Encoding".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 64L) != 0)) { @@ -2430,7 +2390,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return; } - if ("If-Modified-Since".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("If-Modified-Since".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 1073741824L) != 0)) { @@ -2445,7 +2405,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http case 3: { - if ("Via".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Via".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 256L) != 0)) { @@ -2460,7 +2420,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http case 5: { - if ("Allow".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Allow".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 1024L) != 0)) { @@ -2471,7 +2431,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return; } - if ("Range".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Range".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 137438953472L) != 0)) { @@ -2486,7 +2446,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http case 14: { - if ("Content-Length".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Content-Length".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 2048L) != 0)) { @@ -2497,7 +2457,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return; } - if ("Accept-Charset".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Accept-Charset".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 2097152L) != 0)) { @@ -2512,7 +2472,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http case 12: { - if ("Content-Type".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Content-Type".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 4096L) != 0)) { @@ -2523,7 +2483,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return; } - if ("Max-Forwards".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Max-Forwards".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 17179869184L) != 0)) { @@ -2538,7 +2498,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http case 16: { - if ("Content-Encoding".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Content-Encoding".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 8192L) != 0)) { @@ -2549,7 +2509,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return; } - if ("Content-Language".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Content-Language".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 16384L) != 0)) { @@ -2560,7 +2520,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return; } - if ("Content-Location".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Content-Location".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 32768L) != 0)) { @@ -2575,7 +2535,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http case 11: { - if ("Content-MD5".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Content-MD5".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 65536L) != 0)) { @@ -2590,7 +2550,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http case 15: { - if ("Accept-Encoding".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Accept-Encoding".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 4194304L) != 0)) { @@ -2601,7 +2561,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return; } - if ("Accept-Language".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Accept-Language".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 8388608L) != 0)) { @@ -2616,7 +2576,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http case 8: { - if ("If-Match".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("If-Match".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 536870912L) != 0)) { @@ -2627,7 +2587,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return; } - if ("If-Range".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("If-Range".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 4294967296L) != 0)) { @@ -2642,7 +2602,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http case 19: { - if ("If-Unmodified-Since".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("If-Unmodified-Since".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 8589934592L) != 0)) { @@ -2653,7 +2613,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return; } - if ("Proxy-Authorization".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Proxy-Authorization".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 34359738368L) != 0)) { @@ -2668,7 +2628,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http case 2: { - if ("TE".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("TE".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 274877906944L) != 0)) { @@ -2683,7 +2643,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http case 9: { - if ("Translate".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Translate".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 549755813888L) != 0)) { @@ -2698,7 +2658,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } Unknown.Add(key, value); } - protected override bool RemoveFast(string key) { switch(key.Length) @@ -3347,7 +3306,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } return MaybeUnknown?.Remove(key) ?? false; } - protected override void ClearFast() { _bits = 0; @@ -3393,6 +3351,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http _TE = StringValues.Empty; _Translate = StringValues.Empty; _UserAgent = StringValues.Empty; + MaybeUnknown?.Clear(); } @@ -3402,7 +3361,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { throw new ArgumentException(); } - if (((_bits & 1L) != 0)) { @@ -3857,7 +3815,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http ((ICollection>)MaybeUnknown)?.CopyTo(array, arrayIndex); } - + public unsafe void Append(byte[] keyBytes, int keyOffset, int keyLength, string value) { fixed(byte* ptr = keyBytes) { var pUB = ptr + keyOffset; var pUL = (ulong*)pUB; var pUI = (uint*)pUB; var pUS = (ushort*)pUB; @@ -4510,7 +4468,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Http Unknown.TryGetValue(key, out existing); Unknown[key] = AppendValue(existing, value); } - public partial struct Enumerator { public bool MoveNext() @@ -4985,8 +4942,13 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } - public partial class FrameResponseHeaders + public partial class FrameResponseHeaders { + private static byte[] _headerBytes = new byte[] + { + 13,10,67,97,99,104,101,45,67,111,110,116,114,111,108,58,32,13,10,67,111,110,110,101,99,116,105,111,110,58,32,13,10,68,97,116,101,58,32,13,10,75,101,101,112,45,65,108,105,118,101,58,32,13,10,80,114,97,103,109,97,58,32,13,10,84,114,97,105,108,101,114,58,32,13,10,84,114,97,110,115,102,101,114,45,69,110,99,111,100,105,110,103,58,32,13,10,85,112,103,114,97,100,101,58,32,13,10,86,105,97,58,32,13,10,87,97,114,110,105,110,103,58,32,13,10,65,108,108,111,119,58,32,13,10,67,111,110,116,101,110,116,45,76,101,110,103,116,104,58,32,13,10,67,111,110,116,101,110,116,45,84,121,112,101,58,32,13,10,67,111,110,116,101,110,116,45,69,110,99,111,100,105,110,103,58,32,13,10,67,111,110,116,101,110,116,45,76,97,110,103,117,97,103,101,58,32,13,10,67,111,110,116,101,110,116,45,76,111,99,97,116,105,111,110,58,32,13,10,67,111,110,116,101,110,116,45,77,68,53,58,32,13,10,67,111,110,116,101,110,116,45,82,97,110,103,101,58,32,13,10,69,120,112,105,114,101,115,58,32,13,10,76,97,115,116,45,77,111,100,105,102,105,101,100,58,32,13,10,65,99,99,101,112,116,45,82,97,110,103,101,115,58,32,13,10,65,103,101,58,32,13,10,69,84,97,103,58,32,13,10,76,111,99,97,116,105,111,110,58,32,13,10,80,114,111,120,121,45,65,117,116,104,101,116,105,99,97,116,101,58,32,13,10,82,101,116,114,121,45,65,102,116,101,114,58,32,13,10,83,101,114,118,101,114,58,32,13,10,83,101,116,45,67,111,111,107,105,101,58,32,13,10,86,97,114,121,58,32,13,10,87,87,87,45,65,117,116,104,101,110,116,105,99,97,116,101,58,32, + }; + private long _bits = 0; private StringValues _CacheControl; @@ -5020,6 +4982,12 @@ namespace Microsoft.AspNet.Server.Kestrel.Http private StringValues _Vary; private StringValues _WWWAuthenticate; + private byte[] _rawConnection; + private byte[] _rawDate; + private byte[] _rawTransferEncoding; + private byte[] _rawContentLength; + private byte[] _rawServer; + public StringValues HeaderCacheControl { get @@ -5029,10 +4997,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Http set { _bits |= 1L; - _CacheControl = value; + _CacheControl = value; } } - public StringValues HeaderConnection { get @@ -5042,10 +5009,10 @@ namespace Microsoft.AspNet.Server.Kestrel.Http set { _bits |= 2L; - _Connection = value; + _Connection = value; + _rawConnection = null; } } - public StringValues HeaderDate { get @@ -5055,10 +5022,10 @@ namespace Microsoft.AspNet.Server.Kestrel.Http set { _bits |= 4L; - _Date = value; + _Date = value; + _rawDate = null; } } - public StringValues HeaderKeepAlive { get @@ -5068,10 +5035,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Http set { _bits |= 8L; - _KeepAlive = value; + _KeepAlive = value; } } - public StringValues HeaderPragma { get @@ -5081,10 +5047,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Http set { _bits |= 16L; - _Pragma = value; + _Pragma = value; } } - public StringValues HeaderTrailer { get @@ -5094,10 +5059,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Http set { _bits |= 32L; - _Trailer = value; + _Trailer = value; } } - public StringValues HeaderTransferEncoding { get @@ -5107,10 +5071,10 @@ namespace Microsoft.AspNet.Server.Kestrel.Http set { _bits |= 64L; - _TransferEncoding = value; + _TransferEncoding = value; + _rawTransferEncoding = null; } } - public StringValues HeaderUpgrade { get @@ -5120,10 +5084,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Http set { _bits |= 128L; - _Upgrade = value; + _Upgrade = value; } } - public StringValues HeaderVia { get @@ -5133,10 +5096,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Http set { _bits |= 256L; - _Via = value; + _Via = value; } } - public StringValues HeaderWarning { get @@ -5146,10 +5108,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Http set { _bits |= 512L; - _Warning = value; + _Warning = value; } } - public StringValues HeaderAllow { get @@ -5159,10 +5120,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Http set { _bits |= 1024L; - _Allow = value; + _Allow = value; } } - public StringValues HeaderContentLength { get @@ -5172,10 +5132,10 @@ namespace Microsoft.AspNet.Server.Kestrel.Http set { _bits |= 2048L; - _ContentLength = value; + _ContentLength = value; + _rawContentLength = null; } } - public StringValues HeaderContentType { get @@ -5185,10 +5145,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Http set { _bits |= 4096L; - _ContentType = value; + _ContentType = value; } } - public StringValues HeaderContentEncoding { get @@ -5198,10 +5157,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Http set { _bits |= 8192L; - _ContentEncoding = value; + _ContentEncoding = value; } } - public StringValues HeaderContentLanguage { get @@ -5211,10 +5169,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Http set { _bits |= 16384L; - _ContentLanguage = value; + _ContentLanguage = value; } } - public StringValues HeaderContentLocation { get @@ -5224,10 +5181,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Http set { _bits |= 32768L; - _ContentLocation = value; + _ContentLocation = value; } } - public StringValues HeaderContentMD5 { get @@ -5237,10 +5193,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Http set { _bits |= 65536L; - _ContentMD5 = value; + _ContentMD5 = value; } } - public StringValues HeaderContentRange { get @@ -5250,10 +5205,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Http set { _bits |= 131072L; - _ContentRange = value; + _ContentRange = value; } } - public StringValues HeaderExpires { get @@ -5263,10 +5217,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Http set { _bits |= 262144L; - _Expires = value; + _Expires = value; } } - public StringValues HeaderLastModified { get @@ -5276,10 +5229,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Http set { _bits |= 524288L; - _LastModified = value; + _LastModified = value; } } - public StringValues HeaderAcceptRanges { get @@ -5289,10 +5241,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Http set { _bits |= 1048576L; - _AcceptRanges = value; + _AcceptRanges = value; } } - public StringValues HeaderAge { get @@ -5302,10 +5253,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Http set { _bits |= 2097152L; - _Age = value; + _Age = value; } } - public StringValues HeaderETag { get @@ -5315,10 +5265,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Http set { _bits |= 4194304L; - _ETag = value; + _ETag = value; } } - public StringValues HeaderLocation { get @@ -5328,10 +5277,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Http set { _bits |= 8388608L; - _Location = value; + _Location = value; } } - public StringValues HeaderProxyAutheticate { get @@ -5341,10 +5289,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Http set { _bits |= 16777216L; - _ProxyAutheticate = value; + _ProxyAutheticate = value; } } - public StringValues HeaderRetryAfter { get @@ -5354,10 +5301,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Http set { _bits |= 33554432L; - _RetryAfter = value; + _RetryAfter = value; } } - public StringValues HeaderServer { get @@ -5367,10 +5313,10 @@ namespace Microsoft.AspNet.Server.Kestrel.Http set { _bits |= 67108864L; - _Server = value; + _Server = value; + _rawServer = null; } } - public StringValues HeaderSetCookie { get @@ -5380,10 +5326,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Http set { _bits |= 134217728L; - _SetCookie = value; + _SetCookie = value; } } - public StringValues HeaderVary { get @@ -5393,10 +5338,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Http set { _bits |= 268435456L; - _Vary = value; + _Vary = value; } } - public StringValues HeaderWWWAuthenticate { get @@ -5406,22 +5350,51 @@ namespace Microsoft.AspNet.Server.Kestrel.Http set { _bits |= 536870912L; - _WWWAuthenticate = value; + _WWWAuthenticate = value; } } + public void SetRawConnection(StringValues value, byte[] raw) + { + _bits |= 2L; + _Connection = value; + _rawConnection = raw; + } + public void SetRawDate(StringValues value, byte[] raw) + { + _bits |= 4L; + _Date = value; + _rawDate = raw; + } + public void SetRawTransferEncoding(StringValues value, byte[] raw) + { + _bits |= 64L; + _TransferEncoding = value; + _rawTransferEncoding = raw; + } + public void SetRawContentLength(StringValues value, byte[] raw) + { + _bits |= 2048L; + _ContentLength = value; + _rawContentLength = raw; + } + public void SetRawServer(StringValues value, byte[] raw) + { + _bits |= 67108864L; + _Server = value; + _rawServer = raw; + } protected override int GetCountFast() { return BitCount(_bits) + (MaybeUnknown?.Count ?? 0); } - protected override StringValues GetValueFast(string key) { switch(key.Length) { case 13: { - if ("Cache-Control".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Cache-Control".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 1L) != 0)) { @@ -5433,7 +5406,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } - if ("Content-Range".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Content-Range".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 131072L) != 0)) { @@ -5445,7 +5418,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } - if ("Last-Modified".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Last-Modified".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 524288L) != 0)) { @@ -5457,7 +5430,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } - if ("Accept-Ranges".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Accept-Ranges".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 1048576L) != 0)) { @@ -5470,10 +5443,10 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } break; - + case 10: { - if ("Connection".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Connection".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 2L) != 0)) { @@ -5485,7 +5458,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } - if ("Keep-Alive".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Keep-Alive".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 8L) != 0)) { @@ -5497,7 +5470,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } - if ("Set-Cookie".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Set-Cookie".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 134217728L) != 0)) { @@ -5510,10 +5483,10 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } break; - + case 4: { - if ("Date".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Date".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 4L) != 0)) { @@ -5525,7 +5498,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } - if ("ETag".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("ETag".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 4194304L) != 0)) { @@ -5537,7 +5510,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } - if ("Vary".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Vary".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 268435456L) != 0)) { @@ -5550,10 +5523,10 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } break; - + case 6: { - if ("Pragma".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Pragma".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 16L) != 0)) { @@ -5565,7 +5538,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } - if ("Server".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Server".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 67108864L) != 0)) { @@ -5578,10 +5551,10 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } break; - + case 7: { - if ("Trailer".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Trailer".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 32L) != 0)) { @@ -5593,7 +5566,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } - if ("Upgrade".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Upgrade".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 128L) != 0)) { @@ -5605,7 +5578,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } - if ("Warning".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Warning".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 512L) != 0)) { @@ -5617,7 +5590,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } - if ("Expires".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Expires".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 262144L) != 0)) { @@ -5630,10 +5603,10 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } break; - + case 17: { - if ("Transfer-Encoding".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Transfer-Encoding".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 64L) != 0)) { @@ -5645,7 +5618,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } - if ("Proxy-Autheticate".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Proxy-Autheticate".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 16777216L) != 0)) { @@ -5658,10 +5631,10 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } break; - + case 3: { - if ("Via".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Via".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 256L) != 0)) { @@ -5673,7 +5646,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } - if ("Age".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Age".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 2097152L) != 0)) { @@ -5686,10 +5659,10 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } break; - + case 5: { - if ("Allow".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Allow".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 1024L) != 0)) { @@ -5702,10 +5675,10 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } break; - + case 14: { - if ("Content-Length".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Content-Length".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 2048L) != 0)) { @@ -5718,10 +5691,10 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } break; - + case 12: { - if ("Content-Type".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Content-Type".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 4096L) != 0)) { @@ -5734,10 +5707,10 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } break; - + case 16: { - if ("Content-Encoding".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Content-Encoding".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 8192L) != 0)) { @@ -5749,7 +5722,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } - if ("Content-Language".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Content-Language".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 16384L) != 0)) { @@ -5761,7 +5734,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } - if ("Content-Location".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Content-Location".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 32768L) != 0)) { @@ -5773,7 +5746,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } - if ("WWW-Authenticate".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("WWW-Authenticate".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 536870912L) != 0)) { @@ -5786,10 +5759,10 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } break; - + case 11: { - if ("Content-MD5".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Content-MD5".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 65536L) != 0)) { @@ -5801,7 +5774,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } - if ("Retry-After".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Retry-After".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 33554432L) != 0)) { @@ -5814,10 +5787,10 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } break; - + case 8: { - if ("Location".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Location".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 8388608L) != 0)) { @@ -5830,14 +5803,13 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } break; - } +} if (MaybeUnknown == null) { throw new System.Collections.Generic.KeyNotFoundException(); } return MaybeUnknown[key]; } - protected override bool TryGetValueFast(string key, out StringValues value) { switch(key.Length) @@ -5901,7 +5873,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } break; - + case 10: { if ("Connection".Equals(key, StringComparison.OrdinalIgnoreCase)) @@ -5947,7 +5919,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } break; - + case 4: { if ("Date".Equals(key, StringComparison.OrdinalIgnoreCase)) @@ -5993,7 +5965,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } break; - + case 6: { if ("Pragma".Equals(key, StringComparison.OrdinalIgnoreCase)) @@ -6025,7 +5997,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } break; - + case 7: { if ("Trailer".Equals(key, StringComparison.OrdinalIgnoreCase)) @@ -6085,7 +6057,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } break; - + case 17: { if ("Transfer-Encoding".Equals(key, StringComparison.OrdinalIgnoreCase)) @@ -6117,7 +6089,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } break; - + case 3: { if ("Via".Equals(key, StringComparison.OrdinalIgnoreCase)) @@ -6149,7 +6121,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } break; - + case 5: { if ("Allow".Equals(key, StringComparison.OrdinalIgnoreCase)) @@ -6167,7 +6139,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } break; - + case 14: { if ("Content-Length".Equals(key, StringComparison.OrdinalIgnoreCase)) @@ -6185,7 +6157,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } break; - + case 12: { if ("Content-Type".Equals(key, StringComparison.OrdinalIgnoreCase)) @@ -6203,7 +6175,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } break; - + case 16: { if ("Content-Encoding".Equals(key, StringComparison.OrdinalIgnoreCase)) @@ -6263,7 +6235,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } break; - + case 11: { if ("Content-MD5".Equals(key, StringComparison.OrdinalIgnoreCase)) @@ -6295,7 +6267,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } break; - + case 8: { if ("Location".Equals(key, StringComparison.OrdinalIgnoreCase)) @@ -6313,11 +6285,10 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } break; - } +} value = StringValues.Empty; return MaybeUnknown?.TryGetValue(key, out value) ?? false; } - protected override void SetValueFast(string key, StringValues value) { switch(key.Length) @@ -6353,13 +6324,14 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } break; - + case 10: { if ("Connection".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 2L; _Connection = value; + _rawConnection = null; return; } @@ -6378,13 +6350,14 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } break; - + case 4: { if ("Date".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 4L; _Date = value; + _rawDate = null; return; } @@ -6403,7 +6376,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } break; - + case 6: { if ("Pragma".Equals(key, StringComparison.OrdinalIgnoreCase)) @@ -6417,11 +6390,12 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { _bits |= 67108864L; _Server = value; + _rawServer = null; return; } } break; - + case 7: { if ("Trailer".Equals(key, StringComparison.OrdinalIgnoreCase)) @@ -6453,13 +6427,14 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } break; - + case 17: { if ("Transfer-Encoding".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 64L; _TransferEncoding = value; + _rawTransferEncoding = null; return; } @@ -6471,7 +6446,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } break; - + case 3: { if ("Via".Equals(key, StringComparison.OrdinalIgnoreCase)) @@ -6489,7 +6464,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } break; - + case 5: { if ("Allow".Equals(key, StringComparison.OrdinalIgnoreCase)) @@ -6500,18 +6475,19 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } break; - + case 14: { if ("Content-Length".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 2048L; _ContentLength = value; + _rawContentLength = null; return; } } break; - + case 12: { if ("Content-Type".Equals(key, StringComparison.OrdinalIgnoreCase)) @@ -6522,7 +6498,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } break; - + case 16: { if ("Content-Encoding".Equals(key, StringComparison.OrdinalIgnoreCase)) @@ -6554,7 +6530,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } break; - + case 11: { if ("Content-MD5".Equals(key, StringComparison.OrdinalIgnoreCase)) @@ -6572,7 +6548,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } break; - + case 8: { if ("Location".Equals(key, StringComparison.OrdinalIgnoreCase)) @@ -6583,17 +6559,16 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } break; - } +} Unknown[key] = value; } - protected override void AddValueFast(string key, StringValues value) { switch(key.Length) { case 13: { - if ("Cache-Control".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Cache-Control".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 1L) != 0)) { @@ -6604,7 +6579,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return; } - if ("Content-Range".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Content-Range".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 131072L) != 0)) { @@ -6615,7 +6590,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return; } - if ("Last-Modified".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Last-Modified".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 524288L) != 0)) { @@ -6626,7 +6601,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return; } - if ("Accept-Ranges".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Accept-Ranges".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 1048576L) != 0)) { @@ -6641,7 +6616,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http case 10: { - if ("Connection".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Connection".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 2L) != 0)) { @@ -6649,10 +6624,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } _bits |= 2L; _Connection = value; + _rawConnection = null; return; } - if ("Keep-Alive".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Keep-Alive".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 8L) != 0)) { @@ -6663,7 +6639,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return; } - if ("Set-Cookie".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Set-Cookie".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 134217728L) != 0)) { @@ -6678,7 +6654,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http case 4: { - if ("Date".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Date".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 4L) != 0)) { @@ -6686,10 +6662,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } _bits |= 4L; _Date = value; + _rawDate = null; return; } - if ("ETag".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("ETag".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 4194304L) != 0)) { @@ -6700,7 +6677,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return; } - if ("Vary".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Vary".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 268435456L) != 0)) { @@ -6715,7 +6692,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http case 6: { - if ("Pragma".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Pragma".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 16L) != 0)) { @@ -6726,7 +6703,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return; } - if ("Server".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Server".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 67108864L) != 0)) { @@ -6734,6 +6711,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } _bits |= 67108864L; _Server = value; + _rawServer = null; return; } } @@ -6741,7 +6719,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http case 7: { - if ("Trailer".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Trailer".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 32L) != 0)) { @@ -6752,7 +6730,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return; } - if ("Upgrade".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Upgrade".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 128L) != 0)) { @@ -6763,7 +6741,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return; } - if ("Warning".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Warning".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 512L) != 0)) { @@ -6774,7 +6752,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return; } - if ("Expires".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Expires".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 262144L) != 0)) { @@ -6789,7 +6767,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http case 17: { - if ("Transfer-Encoding".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Transfer-Encoding".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 64L) != 0)) { @@ -6797,10 +6775,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } _bits |= 64L; _TransferEncoding = value; + _rawTransferEncoding = null; return; } - if ("Proxy-Autheticate".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Proxy-Autheticate".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 16777216L) != 0)) { @@ -6815,7 +6794,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http case 3: { - if ("Via".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Via".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 256L) != 0)) { @@ -6826,7 +6805,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return; } - if ("Age".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Age".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 2097152L) != 0)) { @@ -6841,7 +6820,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http case 5: { - if ("Allow".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Allow".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 1024L) != 0)) { @@ -6856,7 +6835,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http case 14: { - if ("Content-Length".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Content-Length".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 2048L) != 0)) { @@ -6864,6 +6843,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } _bits |= 2048L; _ContentLength = value; + _rawContentLength = null; return; } } @@ -6871,7 +6851,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http case 12: { - if ("Content-Type".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Content-Type".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 4096L) != 0)) { @@ -6886,7 +6866,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http case 16: { - if ("Content-Encoding".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Content-Encoding".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 8192L) != 0)) { @@ -6897,7 +6877,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return; } - if ("Content-Language".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Content-Language".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 16384L) != 0)) { @@ -6908,7 +6888,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return; } - if ("Content-Location".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Content-Location".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 32768L) != 0)) { @@ -6919,7 +6899,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return; } - if ("WWW-Authenticate".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("WWW-Authenticate".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 536870912L) != 0)) { @@ -6934,7 +6914,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http case 11: { - if ("Content-MD5".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Content-MD5".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 65536L) != 0)) { @@ -6945,7 +6925,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return; } - if ("Retry-After".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Retry-After".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 33554432L) != 0)) { @@ -6960,7 +6940,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http case 8: { - if ("Location".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Location".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 8388608L) != 0)) { @@ -6975,7 +6955,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } Unknown.Add(key, value); } - protected override bool RemoveFast(string key) { switch(key.Length) @@ -7048,6 +7027,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { _bits &= ~2L; _Connection = StringValues.Empty; + _rawConnection = null; return true; } else @@ -7094,6 +7074,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { _bits &= ~4L; _Date = StringValues.Empty; + _rawDate = null; return true; } else @@ -7154,6 +7135,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { _bits &= ~67108864L; _Server = StringValues.Empty; + _rawServer = null; return true; } else @@ -7232,6 +7214,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { _bits &= ~64L; _TransferEncoding = StringValues.Empty; + _rawTransferEncoding = null; return true; } else @@ -7314,6 +7297,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { _bits &= ~2048L; _ContentLength = StringValues.Empty; + _rawContentLength = null; return true; } else @@ -7454,7 +7438,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } return MaybeUnknown?.Remove(key) ?? false; } - protected override void ClearFast() { _bits = 0; @@ -7489,6 +7472,12 @@ namespace Microsoft.AspNet.Server.Kestrel.Http _SetCookie = StringValues.Empty; _Vary = StringValues.Empty; _WWWAuthenticate = StringValues.Empty; + + _rawConnection = null; + _rawDate = null; + _rawTransferEncoding = null; + _rawContentLength = null; + _rawServer = null; MaybeUnknown?.Clear(); } @@ -7498,7 +7487,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { throw new ArgumentException(); } - if (((_bits & 1L) != 0)) { @@ -7832,7 +7820,301 @@ namespace Microsoft.AspNet.Server.Kestrel.Http ((ICollection>)MaybeUnknown)?.CopyTo(array, arrayIndex); } - + + protected void CopyToFast(ref MemoryPoolIterator2 output) + { + + if (((_bits & 1L) != 0)) + { + foreach(var value in _CacheControl) + { + output.CopyFrom(_headerBytes, 0, 17); + output.CopyFromAscii(value); + } + } + + if (((_bits & 2L) != 0)) + { + if (_rawConnection != null) + { + output.CopyFrom(_rawConnection, 0, _rawConnection.Length); + } else + foreach(var value in _Connection) + { + output.CopyFrom(_headerBytes, 17, 14); + output.CopyFromAscii(value); + } + } + + if (((_bits & 4L) != 0)) + { + if (_rawDate != null) + { + output.CopyFrom(_rawDate, 0, _rawDate.Length); + } else + foreach(var value in _Date) + { + output.CopyFrom(_headerBytes, 31, 8); + output.CopyFromAscii(value); + } + } + + if (((_bits & 8L) != 0)) + { + foreach(var value in _KeepAlive) + { + output.CopyFrom(_headerBytes, 39, 14); + output.CopyFromAscii(value); + } + } + + if (((_bits & 16L) != 0)) + { + foreach(var value in _Pragma) + { + output.CopyFrom(_headerBytes, 53, 10); + output.CopyFromAscii(value); + } + } + + if (((_bits & 32L) != 0)) + { + foreach(var value in _Trailer) + { + output.CopyFrom(_headerBytes, 63, 11); + output.CopyFromAscii(value); + } + } + + if (((_bits & 64L) != 0)) + { + if (_rawTransferEncoding != null) + { + output.CopyFrom(_rawTransferEncoding, 0, _rawTransferEncoding.Length); + } else + foreach(var value in _TransferEncoding) + { + output.CopyFrom(_headerBytes, 74, 21); + output.CopyFromAscii(value); + } + } + + if (((_bits & 128L) != 0)) + { + foreach(var value in _Upgrade) + { + output.CopyFrom(_headerBytes, 95, 11); + output.CopyFromAscii(value); + } + } + + if (((_bits & 256L) != 0)) + { + foreach(var value in _Via) + { + output.CopyFrom(_headerBytes, 106, 7); + output.CopyFromAscii(value); + } + } + + if (((_bits & 512L) != 0)) + { + foreach(var value in _Warning) + { + output.CopyFrom(_headerBytes, 113, 11); + output.CopyFromAscii(value); + } + } + + if (((_bits & 1024L) != 0)) + { + foreach(var value in _Allow) + { + output.CopyFrom(_headerBytes, 124, 9); + output.CopyFromAscii(value); + } + } + + if (((_bits & 2048L) != 0)) + { + if (_rawContentLength != null) + { + output.CopyFrom(_rawContentLength, 0, _rawContentLength.Length); + } else + foreach(var value in _ContentLength) + { + output.CopyFrom(_headerBytes, 133, 18); + output.CopyFromAscii(value); + } + } + + if (((_bits & 4096L) != 0)) + { + foreach(var value in _ContentType) + { + output.CopyFrom(_headerBytes, 151, 16); + output.CopyFromAscii(value); + } + } + + if (((_bits & 8192L) != 0)) + { + foreach(var value in _ContentEncoding) + { + output.CopyFrom(_headerBytes, 167, 20); + output.CopyFromAscii(value); + } + } + + if (((_bits & 16384L) != 0)) + { + foreach(var value in _ContentLanguage) + { + output.CopyFrom(_headerBytes, 187, 20); + output.CopyFromAscii(value); + } + } + + if (((_bits & 32768L) != 0)) + { + foreach(var value in _ContentLocation) + { + output.CopyFrom(_headerBytes, 207, 20); + output.CopyFromAscii(value); + } + } + + if (((_bits & 65536L) != 0)) + { + foreach(var value in _ContentMD5) + { + output.CopyFrom(_headerBytes, 227, 15); + output.CopyFromAscii(value); + } + } + + if (((_bits & 131072L) != 0)) + { + foreach(var value in _ContentRange) + { + output.CopyFrom(_headerBytes, 242, 17); + output.CopyFromAscii(value); + } + } + + if (((_bits & 262144L) != 0)) + { + foreach(var value in _Expires) + { + output.CopyFrom(_headerBytes, 259, 11); + output.CopyFromAscii(value); + } + } + + if (((_bits & 524288L) != 0)) + { + foreach(var value in _LastModified) + { + output.CopyFrom(_headerBytes, 270, 17); + output.CopyFromAscii(value); + } + } + + if (((_bits & 1048576L) != 0)) + { + foreach(var value in _AcceptRanges) + { + output.CopyFrom(_headerBytes, 287, 17); + output.CopyFromAscii(value); + } + } + + if (((_bits & 2097152L) != 0)) + { + foreach(var value in _Age) + { + output.CopyFrom(_headerBytes, 304, 7); + output.CopyFromAscii(value); + } + } + + if (((_bits & 4194304L) != 0)) + { + foreach(var value in _ETag) + { + output.CopyFrom(_headerBytes, 311, 8); + output.CopyFromAscii(value); + } + } + + if (((_bits & 8388608L) != 0)) + { + foreach(var value in _Location) + { + output.CopyFrom(_headerBytes, 319, 12); + output.CopyFromAscii(value); + } + } + + if (((_bits & 16777216L) != 0)) + { + foreach(var value in _ProxyAutheticate) + { + output.CopyFrom(_headerBytes, 331, 21); + output.CopyFromAscii(value); + } + } + + if (((_bits & 33554432L) != 0)) + { + foreach(var value in _RetryAfter) + { + output.CopyFrom(_headerBytes, 352, 15); + output.CopyFromAscii(value); + } + } + + if (((_bits & 67108864L) != 0)) + { + if (_rawServer != null) + { + output.CopyFrom(_rawServer, 0, _rawServer.Length); + } else + foreach(var value in _Server) + { + output.CopyFrom(_headerBytes, 367, 10); + output.CopyFromAscii(value); + } + } + + if (((_bits & 134217728L) != 0)) + { + foreach(var value in _SetCookie) + { + output.CopyFrom(_headerBytes, 377, 14); + output.CopyFromAscii(value); + } + } + + if (((_bits & 268435456L) != 0)) + { + foreach(var value in _Vary) + { + output.CopyFrom(_headerBytes, 391, 8); + output.CopyFromAscii(value); + } + } + + if (((_bits & 536870912L) != 0)) + { + foreach(var value in _WWWAuthenticate) + { + output.CopyFrom(_headerBytes, 399, 20); + output.CopyFromAscii(value); + } + } + + } public unsafe void Append(byte[] keyBytes, int keyOffset, int keyLength, string value) { fixed(byte* ptr = keyBytes) { var pUB = ptr + keyOffset; var pUL = (ulong*)pUB; var pUI = (uint*)pUB; var pUS = (ushort*)pUB; @@ -7910,6 +8192,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { _bits |= 2L; _Connection = new StringValues(value); + _rawConnection = null; } return; } @@ -7956,6 +8239,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { _bits |= 4L; _Date = new StringValues(value); + _rawDate = null; } return; } @@ -8016,6 +8300,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { _bits |= 67108864L; _Server = new StringValues(value); + _rawServer = null; } return; } @@ -8094,6 +8379,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { _bits |= 64L; _TransferEncoding = new StringValues(value); + _rawTransferEncoding = null; } return; } @@ -8176,6 +8462,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { _bits |= 2048L; _ContentLength = new StringValues(value); + _rawContentLength = null; } return; } @@ -8315,7 +8602,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Http Unknown.TryGetValue(key, out existing); Unknown[key] = AppendValue(existing, value); } - public partial struct Enumerator { public bool MoveNext() diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameResponseHeaders.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameResponseHeaders.cs index 725a647567..86c2a18554 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameResponseHeaders.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameResponseHeaders.cs @@ -1,14 +1,25 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using Microsoft.Extensions.Primitives; using System.Collections; using System.Collections.Generic; +using Microsoft.AspNet.Server.Kestrel.Infrastructure; +using Microsoft.Extensions.Primitives; namespace Microsoft.AspNet.Server.Kestrel.Http { public partial class FrameResponseHeaders : FrameHeaders { + private static byte[] _CRLF = new[] { (byte)'\r', (byte)'\n' }; + private static byte[] _colonSpace = new[] { (byte)':', (byte)' ' }; + + public bool HasConnection => HeaderConnection.Count != 0; + + public bool HasTransferEncoding => HeaderTransferEncoding.Count != 0; + + public bool HasContentLength => HeaderContentLength.Count != 0; + + public Enumerator GetEnumerator() { return new Enumerator(this); @@ -19,6 +30,24 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return GetEnumerator(); } + public void CopyTo(ref MemoryPoolIterator2 output) + { + CopyToFast(ref output); + if (MaybeUnknown != null) + { + foreach (var kv in MaybeUnknown) + { + foreach (var value in kv.Value) + { + output.CopyFrom(_CRLF, 0, 2); + output.CopyFromAscii(kv.Key); + output.CopyFrom(_colonSpace, 0, 2); + output.CopyFromAscii(value); + } + } + } + } + public partial struct Enumerator : IEnumerator> { private FrameResponseHeaders _collection; diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/MemoryPool.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/MemoryPool.cs deleted file mode 100644 index 0fc5c390e1..0000000000 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/MemoryPool.cs +++ /dev/null @@ -1,125 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using System.Collections.Generic; - -namespace Microsoft.AspNet.Server.Kestrel.Http -{ - public class MemoryPool : IMemoryPool - { - private static readonly byte[] EmptyArray = new byte[0]; - - private readonly Pool _pool1 = new Pool(); - private readonly Pool _pool2 = new Pool(); - private readonly Pool _pool3 = new Pool(); - - public byte[] Empty - { - get - { - return EmptyArray; - } - } - - public byte[] AllocByte(int minimumSize) - { - if (minimumSize == 0) - { - return EmptyArray; - } - if (minimumSize <= 1024) - { - return _pool1.Alloc(1024); - } - if (minimumSize <= 2048) - { - return _pool2.Alloc(2048); - } - return new byte[minimumSize]; - } - - public void FreeByte(byte[] memory) - { - if (memory == null) - { - return; - } - switch (memory.Length) - { - case 1024: - _pool1.Free(memory, 256); - break; - case 2048: - _pool2.Free(memory, 64); - break; - } - } - - public char[] AllocChar(int minimumSize) - { - if (minimumSize == 0) - { - return new char[0]; - } - if (minimumSize <= 128) - { - return _pool3.Alloc(128); - } - return new char[minimumSize]; - } - - public void FreeChar(char[] memory) - { - if (memory == null) - { - return; - } - switch (memory.Length) - { - case 128: - _pool3.Free(memory, 256); - break; - } - } - - public ArraySegment AllocSegment(int minimumSize) - { - return new ArraySegment(AllocByte(minimumSize)); - } - - public void FreeSegment(ArraySegment segment) - { - FreeByte(segment.Array); - } - - class Pool - { - private readonly Stack _stack = new Stack(); - private readonly object _sync = new object(); - - public T[] Alloc(int size) - { - lock (_sync) - { - if (_stack.Count != 0) - { - return _stack.Pop(); - } - } - return new T[size]; - } - - public void Free(T[] value, int limit) - { - lock (_sync) - { - if (_stack.Count < limit) - { - _stack.Push(value); - } - } - } - } - } -} diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/MemoryPoolTextWriter.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/MemoryPoolTextWriter.cs deleted file mode 100644 index 2f549dc157..0000000000 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/MemoryPoolTextWriter.cs +++ /dev/null @@ -1,155 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using System.IO; -using System.Text; - -namespace Microsoft.AspNet.Server.Kestrel.Http -{ - public class MemoryPoolTextWriter : TextWriter - { - private readonly IMemoryPool _memory; - - private char[] _textArray; - private int _textBegin; - private int _textEnd; - // ReSharper disable InconsistentNaming - private const int _textLength = 128; - // ReSharper restore InconsistentNaming - - private byte[] _dataArray; - private int _dataEnd; - - private readonly Encoder _encoder; - - public MemoryPoolTextWriter(IMemoryPool memory) - { - _memory = memory; - _textArray = _memory.AllocChar(_textLength); - _dataArray = _memory.Empty; - _encoder = Encoding.UTF8.GetEncoder(); - } - - public ArraySegment Buffer - { - get - { - return new ArraySegment(_dataArray, 0, _dataEnd); - } - } - - public override Encoding Encoding - { - get - { - return Encoding.UTF8; - } - } - - protected override void Dispose(bool disposing) - { - try - { - if (disposing) - { - if (_textArray != null) - { - _memory.FreeChar(_textArray); - _textArray = null; - } - if (_dataArray != null) - { - _memory.FreeByte(_dataArray); - _dataArray = null; - } - } - } - finally - { - base.Dispose(disposing); - } - } - - private void Encode(bool flush) - { - var bytesNeeded = _encoder.GetByteCount( - _textArray, - _textBegin, - _textEnd - _textBegin, - flush); - - Grow(bytesNeeded); - - var bytesUsed = _encoder.GetBytes( - _textArray, - _textBegin, - _textEnd - _textBegin, - _dataArray, - _dataEnd, - flush); - - _textBegin = _textEnd = 0; - _dataEnd += bytesUsed; - } - - private void Grow(int minimumAvailable) - { - if (_dataArray.Length - _dataEnd >= minimumAvailable) - { - return; - } - - var newLength = _dataArray.Length + Math.Max(_dataArray.Length, minimumAvailable); - var newArray = _memory.AllocByte(newLength); - Array.Copy(_dataArray, 0, newArray, 0, _dataEnd); - _memory.FreeByte(_dataArray); - _dataArray = newArray; - } - - public override void Write(char value) - { - if (_textLength == _textEnd) - { - Encode(false); - if (_textLength == _textEnd) - { - throw new InvalidOperationException("Unexplainable failure to encode text"); - } - } - - _textArray[_textEnd++] = value; - } - - public override void Write(string value) - { - var sourceIndex = 0; - var sourceLength = value.Length; - while (sourceIndex < sourceLength) - { - if (_textLength == _textEnd) - { - Encode(false); - } - - var count = sourceLength - sourceIndex; - if (count > _textLength - _textEnd) - { - count = _textLength - _textEnd; - } - - value.CopyTo(sourceIndex, _textArray, _textEnd, count); - sourceIndex += count; - _textEnd += count; - } - } - - public override void Flush() - { - while (_textBegin != _textEnd) - { - Encode(true); - } - } - } -} diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/ReasonPhrases.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/ReasonPhrases.cs index fe8fa6e19e..9afbe88d6c 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/ReasonPhrases.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/ReasonPhrases.cs @@ -2,11 +2,65 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Globalization; +using System.Text; namespace Microsoft.AspNet.Server.Kestrel.Http { public static class ReasonPhrases { + private static readonly byte[] _bytesStatus100 = Encoding.ASCII.GetBytes("100 Continue"); + private static readonly byte[] _bytesStatus101 = Encoding.ASCII.GetBytes("101 Switching Protocols"); + private static readonly byte[] _bytesStatus102 = Encoding.ASCII.GetBytes("102 Processing"); + private static readonly byte[] _bytesStatus200 = Encoding.ASCII.GetBytes("200 OK"); + private static readonly byte[] _bytesStatus201 = Encoding.ASCII.GetBytes("201 Created"); + private static readonly byte[] _bytesStatus202 = Encoding.ASCII.GetBytes("202 Accepted"); + private static readonly byte[] _bytesStatus203 = Encoding.ASCII.GetBytes("203 Non-Authoritative Information"); + private static readonly byte[] _bytesStatus204 = Encoding.ASCII.GetBytes("204 No Content"); + private static readonly byte[] _bytesStatus205 = Encoding.ASCII.GetBytes("205 Reset Content"); + private static readonly byte[] _bytesStatus206 = Encoding.ASCII.GetBytes("206 Partial Content"); + private static readonly byte[] _bytesStatus207 = Encoding.ASCII.GetBytes("207 Multi-Status"); + private static readonly byte[] _bytesStatus226 = Encoding.ASCII.GetBytes("226 IM Used"); + private static readonly byte[] _bytesStatus300 = Encoding.ASCII.GetBytes("300 Multiple Choices"); + private static readonly byte[] _bytesStatus301 = Encoding.ASCII.GetBytes("301 Moved Permanently"); + private static readonly byte[] _bytesStatus302 = Encoding.ASCII.GetBytes("302 Found"); + private static readonly byte[] _bytesStatus303 = Encoding.ASCII.GetBytes("303 See Other"); + private static readonly byte[] _bytesStatus304 = Encoding.ASCII.GetBytes("304 Not Modified"); + private static readonly byte[] _bytesStatus305 = Encoding.ASCII.GetBytes("305 Use Proxy"); + private static readonly byte[] _bytesStatus306 = Encoding.ASCII.GetBytes("306 Reserved"); + private static readonly byte[] _bytesStatus307 = Encoding.ASCII.GetBytes("307 Temporary Redirect"); + private static readonly byte[] _bytesStatus400 = Encoding.ASCII.GetBytes("400 Bad Request"); + private static readonly byte[] _bytesStatus401 = Encoding.ASCII.GetBytes("401 Unauthorized"); + private static readonly byte[] _bytesStatus402 = Encoding.ASCII.GetBytes("402 Payment Required"); + private static readonly byte[] _bytesStatus403 = Encoding.ASCII.GetBytes("403 Forbidden"); + private static readonly byte[] _bytesStatus404 = Encoding.ASCII.GetBytes("404 Not Found"); + private static readonly byte[] _bytesStatus405 = Encoding.ASCII.GetBytes("405 Method Not Allowed"); + private static readonly byte[] _bytesStatus406 = Encoding.ASCII.GetBytes("406 Not Acceptable"); + private static readonly byte[] _bytesStatus407 = Encoding.ASCII.GetBytes("407 Proxy Authentication Required"); + private static readonly byte[] _bytesStatus408 = Encoding.ASCII.GetBytes("408 Request Timeout"); + private static readonly byte[] _bytesStatus409 = Encoding.ASCII.GetBytes("409 Conflict"); + private static readonly byte[] _bytesStatus410 = Encoding.ASCII.GetBytes("410 Gone"); + private static readonly byte[] _bytesStatus411 = Encoding.ASCII.GetBytes("411 Length Required"); + private static readonly byte[] _bytesStatus412 = Encoding.ASCII.GetBytes("412 Precondition Failed"); + private static readonly byte[] _bytesStatus413 = Encoding.ASCII.GetBytes("413 Request Entity Too Large"); + private static readonly byte[] _bytesStatus414 = Encoding.ASCII.GetBytes("414 Request-URI Too Long"); + private static readonly byte[] _bytesStatus415 = Encoding.ASCII.GetBytes("415 Unsupported Media Type"); + private static readonly byte[] _bytesStatus416 = Encoding.ASCII.GetBytes("416 Requested Range Not Satisfiable"); + private static readonly byte[] _bytesStatus417 = Encoding.ASCII.GetBytes("417 Expectation Failed"); + private static readonly byte[] _bytesStatus418 = Encoding.ASCII.GetBytes("418 I'm a Teapot"); + private static readonly byte[] _bytesStatus422 = Encoding.ASCII.GetBytes("422 Unprocessable Entity"); + private static readonly byte[] _bytesStatus423 = Encoding.ASCII.GetBytes("423 Locked"); + private static readonly byte[] _bytesStatus424 = Encoding.ASCII.GetBytes("424 Failed Dependency"); + private static readonly byte[] _bytesStatus426 = Encoding.ASCII.GetBytes("426 Upgrade Required"); + private static readonly byte[] _bytesStatus500 = Encoding.ASCII.GetBytes("500 Internal Server Error"); + private static readonly byte[] _bytesStatus501 = Encoding.ASCII.GetBytes("501 Not Implemented"); + private static readonly byte[] _bytesStatus502 = Encoding.ASCII.GetBytes("502 Bad Gateway"); + private static readonly byte[] _bytesStatus503 = Encoding.ASCII.GetBytes("503 Service Unavailable"); + private static readonly byte[] _bytesStatus504 = Encoding.ASCII.GetBytes("504 Gateway Timeout"); + private static readonly byte[] _bytesStatus505 = Encoding.ASCII.GetBytes("505 HTTP Version Not Supported"); + private static readonly byte[] _bytesStatus506 = Encoding.ASCII.GetBytes("506 Variant Also Negotiates"); + private static readonly byte[] _bytesStatus507 = Encoding.ASCII.GetBytes("507 Insufficient Storage"); + private static readonly byte[] _bytesStatus510 = Encoding.ASCII.GetBytes("510 Not Extended"); + public static string ToStatus(int statusCode, string reasonPhrase = null) { if (string.IsNullOrEmpty(reasonPhrase)) @@ -16,6 +70,123 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return statusCode.ToString(CultureInfo.InvariantCulture) + " " + reasonPhrase; } + public static byte[] ToStatusBytes(int statusCode, string reasonPhrase = null) + { + if (string.IsNullOrEmpty(reasonPhrase)) + { + switch (statusCode) + { + case 100: + return _bytesStatus100; + case 101: + return _bytesStatus101; + case 102: + return _bytesStatus102; + case 200: + return _bytesStatus200; + case 201: + return _bytesStatus201; + case 202: + return _bytesStatus202; + case 203: + return _bytesStatus203; + case 204: + return _bytesStatus204; + case 205: + return _bytesStatus205; + case 206: + return _bytesStatus206; + case 207: + return _bytesStatus207; + case 226: + return _bytesStatus226; + case 300: + return _bytesStatus300; + case 301: + return _bytesStatus301; + case 302: + return _bytesStatus302; + case 303: + return _bytesStatus303; + case 304: + return _bytesStatus304; + case 305: + return _bytesStatus305; + case 306: + return _bytesStatus306; + case 307: + return _bytesStatus307; + case 400: + return _bytesStatus400; + case 401: + return _bytesStatus401; + case 402: + return _bytesStatus402; + case 403: + return _bytesStatus403; + case 404: + return _bytesStatus404; + case 405: + return _bytesStatus405; + case 406: + return _bytesStatus406; + case 407: + return _bytesStatus407; + case 408: + return _bytesStatus408; + case 409: + return _bytesStatus409; + case 410: + return _bytesStatus410; + case 411: + return _bytesStatus411; + case 412: + return _bytesStatus412; + case 413: + return _bytesStatus413; + case 414: + return _bytesStatus414; + case 415: + return _bytesStatus415; + case 416: + return _bytesStatus416; + case 417: + return _bytesStatus417; + case 418: + return _bytesStatus418; + case 422: + return _bytesStatus422; + case 423: + return _bytesStatus423; + case 424: + return _bytesStatus424; + case 426: + return _bytesStatus426; + case 500: + return _bytesStatus500; + case 501: + return _bytesStatus501; + case 502: + return _bytesStatus502; + case 503: + return _bytesStatus503; + case 504: + return _bytesStatus504; + case 505: + return _bytesStatus505; + case 506: + return _bytesStatus506; + case 507: + return _bytesStatus507; + case 510: + return _bytesStatus510; + default: + return Encoding.ASCII.GetBytes(statusCode.ToString(CultureInfo.InvariantCulture) + " Unknown"); + } + } + return Encoding.ASCII.GetBytes(statusCode.ToString(CultureInfo.InvariantCulture) + " " + reasonPhrase); + } + public static string ToReasonPhrase(int statusCode) { switch (statusCode) @@ -242,4 +413,4 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } } -} +} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPool2.cs b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPool2.cs index 446f03c2b3..5c9ce81f69 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPool2.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPool2.cs @@ -30,6 +30,12 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure /// 4096 - 64 gives you a blockLength of 4032 usable bytes per block. /// private const int _blockLength = _blockStride - _blockUnused; + + /// + /// Max allocation block size for pooled blocks, + /// larger values can be leased but they will be disposed after use rather than returned to the pool. + /// + public const int MaxPooledBlockLength = _blockLength; /// /// 4096 * 32 gives you a slabLength of 128k contiguous bytes allocated per slab @@ -59,7 +65,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure /// The block returned must be at least this size. It may be larger than this minimum size, and if so, /// the caller may write to the block's entire size rather than being limited to the minumumSize requested. /// The block that is reserved for the called. It must be passed to Return when it is no longer being used. - public MemoryPoolBlock2 Lease(int minimumSize = _blockLength) + public MemoryPoolBlock2 Lease(int minimumSize = MaxPooledBlockLength) { if (minimumSize > _blockLength) { diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolIterator2.cs b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolIterator2.cs index 6c5c1f205a..a3b5e678c5 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolIterator2.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolIterator2.cs @@ -572,5 +572,109 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure return new MemoryPoolIterator2(block, blockIndex); } + + public void CopyFrom(byte[] data) + { + CopyFrom(data, 0, data.Length); + } + + public void CopyFrom(byte[] data, int offset, int count) + { + Debug.Assert(_block.Next == null); + Debug.Assert(_block.End == _index); + + var block = _block; + + var sourceData = data; + var sourceStart = offset; + var sourceEnd = offset + count; + + var targetData = block.Array; + var targetStart = block.End; + var targetEnd = block.Data.Offset + block.Data.Count; + + while (true) + { + // actual count to copy is remaining data, or unused trailing space in the current block, whichever is smaller + var copyCount = Math.Min(sourceEnd - sourceStart, targetEnd - targetStart); + + Buffer.BlockCopy(sourceData, sourceStart, targetData, targetStart, copyCount); + sourceStart += copyCount; + targetStart += copyCount; + + // if this means all source data has been copied + if (sourceStart == sourceEnd) + { + // increase occupied space in the block, and adjust iterator at start of unused trailing space + block.End = targetStart; + _block = block; + _index = targetStart; + return; + } + + // otherwise another block needs to be allocated to follow this one + block.Next = block.Pool.Lease(); + block = block.Next; + + targetData = block.Array; + targetStart = block.End; + targetEnd = block.Data.Offset + block.Data.Count; + } + } + + public unsafe void CopyFromAscii(string data) + { + Debug.Assert(_block.Next == null); + Debug.Assert(_block.End == _index); + + var block = _block; + + var inputLength = data.Length; + var inputLengthMinusSpan = inputLength - 3; + + fixed (char* pData = data) + { + var input = pData; + var inputEnd = pData + data.Length; + var blockRemaining = block.Data.Offset + block.Data.Count - block.End; + var blockRemainingMinusSpan = blockRemaining - 3; + + while (input < inputEnd) + { + if (blockRemaining == 0) + { + block.Next = block.Pool.Lease(); + block = block.Next; + blockRemaining = block.Data.Count; + blockRemainingMinusSpan = blockRemaining - 3; + } + + fixed (byte* pOutput = block.Data.Array) + { + var output = pOutput + block.End; + + var copied = 0; + for (; copied < inputLengthMinusSpan && copied < blockRemainingMinusSpan; copied += 4) + { + *(output) = (byte)*(input); + *(output + 1) = (byte)*(input + 1); + *(output + 2) = (byte)*(input + 2); + *(output + 3) = (byte)*(input + 3); + output += 4; + input += 4; + blockRemainingMinusSpan -= 4; + } + for (; copied < inputLength && copied < blockRemaining; copied++) + { + *(output++) = (byte)*(input++); + blockRemaining--; + } + block.End += copied; + _block = block; + _index = block.End; + } + } + } + } } } diff --git a/src/Microsoft.AspNet.Server.Kestrel/ServiceContext.cs b/src/Microsoft.AspNet.Server.Kestrel/ServiceContext.cs index d3d1539a59..095f37f856 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/ServiceContext.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/ServiceContext.cs @@ -13,13 +13,11 @@ namespace Microsoft.AspNet.Server.Kestrel { public ServiceContext() { - Memory = new MemoryPool(); } public ServiceContext(ServiceContext context) { AppLifetime = context.AppLifetime; - Memory = context.Memory; Log = context.Log; HttpContextFactory = context.HttpContextFactory; DateHeaderValueManager = context.DateHeaderValueManager; @@ -29,8 +27,6 @@ namespace Microsoft.AspNet.Server.Kestrel public IApplicationLifetime AppLifetime { get; set; } - public IMemoryPool Memory { get; set; } - public IKestrelTrace Log { get; set; } public IHttpContextFactory HttpContextFactory { get; set; } diff --git a/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs index f19b2b3077..afc30af8a9 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs @@ -171,8 +171,8 @@ namespace Microsoft.AspNet.Server.KestrelTests "Content-Length: 0", "", "HTTP/1.1 200 OK", - "Content-Length: 7", "Connection: close", + "Content-Length: 7", "", "Goodbye"); } @@ -241,8 +241,8 @@ namespace Microsoft.AspNet.Server.KestrelTests "Goodbye"); await connection.Receive( "HTTP/1.0 200 OK", - "Content-Length: 0", "Connection: keep-alive", + "Content-Length: 0", "\r\n"); await connection.ReceiveEnd( "HTTP/1.0 200 OK", @@ -267,14 +267,14 @@ namespace Microsoft.AspNet.Server.KestrelTests "Connection: keep-alive", "", "POST / HTTP/1.0", - "Connection: keep-alive", "Content-Length: 7", + "Connection: keep-alive", "", "Goodbye"); await connection.Receive( "HTTP/1.0 200 OK", - "Content-Length: 0", "Connection: keep-alive", + "Content-Length: 0", "\r\n"); await connection.ReceiveEnd( "HTTP/1.0 200 OK", @@ -295,16 +295,16 @@ namespace Microsoft.AspNet.Server.KestrelTests { await connection.SendEnd( "POST / HTTP/1.0", - "Connection: keep-alive", "Content-Length: 11", + "Connection: keep-alive", "", "Hello WorldPOST / HTTP/1.0", "", "Goodbye"); await connection.Receive( "HTTP/1.0 200 OK", - "Content-Length: 11", "Connection: keep-alive", + "Content-Length: 11", "", "Hello World"); await connection.ReceiveEnd( @@ -336,8 +336,8 @@ namespace Microsoft.AspNet.Server.KestrelTests "Goodbye"); await connection.Receive( "HTTP/1.0 200 OK", - "Content-Length: 11", "Connection: keep-alive", + "Content-Length: 11", "", "Hello World"); await connection.ReceiveEnd( @@ -361,15 +361,15 @@ namespace Microsoft.AspNet.Server.KestrelTests await connection.Send( "POST / HTTP/1.1", "Expect: 100-continue", - "Content-Length: 11", "Connection: close", + "Content-Length: 11", "\r\n"); await connection.Receive("HTTP/1.1 100 Continue", "\r\n"); await connection.SendEnd("Hello World"); await connection.Receive( "HTTP/1.1 200 OK", - "Content-Length: 11", "Connection: close", + "Content-Length: 11", "", "Hello World"); } @@ -422,8 +422,8 @@ namespace Microsoft.AspNet.Server.KestrelTests "Content-Length: 0", "", "HTTP/1.0 200 OK", - "Content-Length: 0", "Connection: keep-alive", + "Content-Length: 0", "", ""); } @@ -584,11 +584,12 @@ namespace Microsoft.AspNet.Server.KestrelTests "", "HTTP/1.1 500 Internal Server Error", ""); + await connection.Receive("Connection: close", + ""); await connection.ReceiveStartsWith("Date:"); await connection.ReceiveEnd( "Content-Length: 0", "Server: Kestrel", - "Connection: close", "", ""); @@ -812,12 +813,12 @@ namespace Microsoft.AspNet.Server.KestrelTests "Server: Kestrel", "", "HTTP/1.1 500 Internal Server Error", + "Connection: close", ""); await connection.ReceiveStartsWith("Date:"); await connection.ReceiveEnd( "Content-Length: 0", "Server: Kestrel", - "Connection: close", "", ""); diff --git a/test/Microsoft.AspNet.Server.KestrelTests/TestInput.cs b/test/Microsoft.AspNet.Server.KestrelTests/TestInput.cs index 24cf1cdb77..a440ea0edf 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/TestInput.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/TestInput.cs @@ -13,12 +13,10 @@ namespace Microsoft.AspNet.Server.KestrelTests { public TestInput() { - var memory = new MemoryPool(); var memory2 = new MemoryPool2(); FrameContext = new FrameContext { SocketInput = new SocketInput(memory2), - Memory = memory, ConnectionControl = this, FrameControl = this }; diff --git a/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/KnownHeaders.cs b/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/KnownHeaders.cs index b2def16b46..ab20b6c2d9 100644 --- a/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/KnownHeaders.cs +++ b/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/KnownHeaders.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; using System.Linq; using Microsoft.Dnx.Compilation.CSharp; +using System.Text; namespace Microsoft.AspNet.Server.Kestrel.GeneratedCode { @@ -11,7 +12,7 @@ namespace Microsoft.AspNet.Server.Kestrel.GeneratedCode { static string Each(IEnumerable values, Func formatter) { - return values.Select(formatter).Aggregate((a, b) => a + b); + return values.Any() ? values.Select(formatter).Aggregate((a, b) => a + b) : ""; } class KnownHeader @@ -19,10 +20,14 @@ namespace Microsoft.AspNet.Server.Kestrel.GeneratedCode public string Name { get; set; } public int Index { get; set; } public string Identifier => Name.Replace("-", ""); + + public byte[] Bytes => Encoding.ASCII.GetBytes($"\r\n{Name}: "); + public int BytesOffset { get; set; } + public int BytesCount { get; set; } + public bool EnhancedSetter { get; set; } public string TestBit() => $"((_bits & {1L << Index}L) != 0)"; public string SetBit() => $"_bits |= {1L << Index}L"; public string ClearBit() => $"_bits &= ~{1L << Index}L"; - public string EqualIgnoreCaseBytes() { var result = ""; @@ -54,7 +59,6 @@ namespace Microsoft.AspNet.Server.Kestrel.GeneratedCode } return $"({result})"; } - protected string Term(string name, int offset, int count, string array, string suffix) { ulong mask = 0; @@ -69,13 +73,11 @@ namespace Microsoft.AspNet.Server.Kestrel.GeneratedCode return $"(({array}[{offset / count}] & {mask}{suffix}) == {comp}{suffix})"; } } - public virtual void BeforeCompile(BeforeCompileContext context) { var syntaxTree = Microsoft.CodeAnalysis.CSharp.CSharpSyntaxTree.ParseText(GeneratedFile()); context.Compilation = context.Compilation.AddSyntaxTrees(syntaxTree); } - public static string GeneratedFile() { var commonHeaders = new[] @@ -128,8 +130,15 @@ namespace Microsoft.AspNet.Server.Kestrel.GeneratedCode { Name = header, Index = index - }); - + }).ToArray(); + var enhancedHeaders = new[] + { + "Connection", + "Server", + "Date", + "Transfer-Encoding", + "Content-Length", + }; var responseHeaders = commonHeaders.Concat(new[] { "Accept-Ranges", @@ -145,38 +154,60 @@ namespace Microsoft.AspNet.Server.Kestrel.GeneratedCode }).Select((header, index) => new KnownHeader { Name = header, - Index = index - }); - + Index = index, + EnhancedSetter = enhancedHeaders.Contains(header) + }).ToArray(); var loops = new[] { new { Headers = requestHeaders, HeadersByLength = requestHeaders.GroupBy(x => x.Name.Length), - ClassName = "FrameRequestHeaders" + ClassName = "FrameRequestHeaders", + Bytes = default(byte[]) }, new { Headers = responseHeaders, HeadersByLength = responseHeaders.GroupBy(x => x.Name.Length), - ClassName = "FrameResponseHeaders" + ClassName = "FrameResponseHeaders", + Bytes = responseHeaders.SelectMany(header => header.Bytes).ToArray() } }; - + foreach (var loop in loops.Where(l => l.Bytes != null)) + { + var offset = 0; + foreach (var header in loop.Headers) + { + header.BytesOffset = offset; + header.BytesCount += header.Bytes.Length; + offset += header.BytesCount; + } + } return $@" using System; using System.Collections.Generic; +using System.Text; +using Microsoft.AspNet.Server.Kestrel.Infrastructure; using Microsoft.Extensions.Primitives; namespace Microsoft.AspNet.Server.Kestrel.Http {{ {Each(loops, loop => $@" - public partial class {loop.ClassName} - {{ + public partial class {loop.ClassName} + {{{(loop.Bytes != null ? + $@" + private static byte[] _headerBytes = new byte[] + {{ + {Each(loop.Bytes, b => $"{b},")} + }};" + : "")} + private long _bits = 0; {Each(loop.Headers, header => @" private StringValues _" + header.Identifier + ";")} + {Each(loop.Headers.Where(header => header.EnhancedSetter), header => @" + private byte[] _raw" + header.Identifier + ";")} {Each(loop.Headers, header => $@" public StringValues Header{header.Identifier} {{ @@ -187,22 +218,28 @@ namespace Microsoft.AspNet.Server.Kestrel.Http set {{ {header.SetBit()}; - _{header.Identifier} = value; + _{header.Identifier} = value; {(header.EnhancedSetter == false ? "" : $@" + _raw{header.Identifier} = null;")} }} - }} - ")} + }}")} + {Each(loop.Headers.Where(header => header.EnhancedSetter), header => $@" + public void SetRaw{header.Identifier}(StringValues value, byte[] raw) + {{ + {header.SetBit()}; + _{header.Identifier} = value; + _raw{header.Identifier} = raw; + }}")} protected override int GetCountFast() {{ return BitCount(_bits) + (MaybeUnknown?.Count ?? 0); }} - protected override StringValues GetValueFast(string key) {{ switch(key.Length) {{{Each(loop.HeadersByLength, byLength => $@" case {byLength.Key}: {{{Each(byLength, header => $@" - if (""{header.Name}"".Equals(key, StringComparison.OrdinalIgnoreCase)) + if (""{header.Name}"".Equals(key, StringComparison.OrdinalIgnoreCase)) {{ if ({header.TestBit()}) {{ @@ -215,14 +252,13 @@ namespace Microsoft.AspNet.Server.Kestrel.Http }} ")}}} break; - ")}}} +")}}} if (MaybeUnknown == null) {{ throw new System.Collections.Generic.KeyNotFoundException(); }} return MaybeUnknown[key]; }} - protected override bool TryGetValueFast(string key, out StringValues value) {{ switch(key.Length) @@ -244,11 +280,10 @@ namespace Microsoft.AspNet.Server.Kestrel.Http }} ")}}} break; - ")}}} +")}}} value = StringValues.Empty; return MaybeUnknown?.TryGetValue(key, out value) ?? false; }} - protected override void SetValueFast(string key, StringValues value) {{ switch(key.Length) @@ -258,29 +293,30 @@ namespace Microsoft.AspNet.Server.Kestrel.Http if (""{header.Name}"".Equals(key, StringComparison.OrdinalIgnoreCase)) {{ {header.SetBit()}; - _{header.Identifier} = value; + _{header.Identifier} = value;{(header.EnhancedSetter == false ? "" : $@" + _raw{header.Identifier} = null;")} return; }} ")}}} break; - ")}}} +")}}} Unknown[key] = value; }} - protected override void AddValueFast(string key, StringValues value) {{ switch(key.Length) {{{Each(loop.HeadersByLength, byLength => $@" case {byLength.Key}: {{{Each(byLength, header => $@" - if (""{header.Name}"".Equals(key, StringComparison.OrdinalIgnoreCase)) + if (""{header.Name}"".Equals(key, StringComparison.OrdinalIgnoreCase)) {{ if ({header.TestBit()}) {{ throw new ArgumentException(""An item with the same key has already been added.""); }} {header.SetBit()}; - _{header.Identifier} = value; + _{header.Identifier} = value;{(header.EnhancedSetter == false ? "" : $@" + _raw{header.Identifier} = null;")} return; }} ")}}} @@ -288,7 +324,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Http ")}}} Unknown.Add(key, value); }} - protected override bool RemoveFast(string key) {{ switch(key.Length) @@ -300,7 +335,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http if ({header.TestBit()}) {{ {header.ClearBit()}; - _{header.Identifier} = StringValues.Empty; + _{header.Identifier} = StringValues.Empty;{(header.EnhancedSetter == false ? "" : $@" + _raw{header.Identifier} = null;")} return true; }} else @@ -313,12 +349,13 @@ namespace Microsoft.AspNet.Server.Kestrel.Http ")}}} return MaybeUnknown?.Remove(key) ?? false; }} - protected override void ClearFast() {{ _bits = 0; {Each(loop.Headers, header => $@" _{header.Identifier} = StringValues.Empty;")} + {Each(loop.Headers.Where(header => header.EnhancedSetter), header => $@" + _raw{header.Identifier} = null;")} MaybeUnknown?.Clear(); }} @@ -328,7 +365,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Http {{ throw new ArgumentException(); }} - {Each(loop.Headers, header => $@" if ({header.TestBit()}) {{ @@ -343,7 +379,24 @@ namespace Microsoft.AspNet.Server.Kestrel.Http ")} ((ICollection>)MaybeUnknown)?.CopyTo(array, arrayIndex); }} - + {(loop.ClassName == "FrameResponseHeaders" ? $@" + protected void CopyToFast(ref MemoryPoolIterator2 output) + {{ + {Each(loop.Headers, header => $@" + if ({header.TestBit()}) + {{ {(header.EnhancedSetter == false ? "" : $@" + if (_raw{header.Identifier} != null) + {{ + output.CopyFromAscii(_raw{header.Identifier}, 0, _raw{header.Identifier}.Length); + }} else ")} + foreach(var value in _{header.Identifier}) + {{ + output.CopyFromAscii(_headerBytes, {header.BytesOffset}, {header.BytesCount}); + output.CopyFromAscii(value); + }} + }} + ")} + }}" : "")} public unsafe void Append(byte[] keyBytes, int keyOffset, int keyLength, string value) {{ fixed(byte* ptr = keyBytes) {{ var pUB = ptr + keyOffset; var pUL = (ulong*)pUB; var pUI = (uint*)pUB; var pUS = (ushort*)pUB; @@ -360,7 +413,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http else {{ {header.SetBit()}; - _{header.Identifier} = new StringValues(value); + _{header.Identifier} = new StringValues(value);{(header.EnhancedSetter == false ? "" : $@" + _raw{header.Identifier} = null;")} }} return; }} @@ -372,7 +426,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Http Unknown.TryGetValue(key, out existing); Unknown[key] = AppendValue(existing, value); }} - public partial struct Enumerator {{ public bool MoveNext() @@ -409,9 +462,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http ")}}} "; } - public virtual void AfterCompile(AfterCompileContext context) { } } -} +} \ No newline at end of file From feb40402de27de1d6abe0c5ac3eb6e85dbf17d56 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Fri, 20 Nov 2015 21:27:59 +0000 Subject: [PATCH 0466/1662] merge preamble-output, socket-output --- .../Filter/LibuvStream.cs | 20 ++- .../Filter/StreamSocketOutput.cs | 2 +- .../Http/Frame.cs | 48 ++----- .../Http/FrameHeaders.Generated.cs | 134 +++++++++--------- .../Http/FrameResponseHeaders.cs | 15 +- .../Http/SocketOutput.cs | 12 +- .../Infrastructure/MemoryPoolIterator2.cs | 120 +++++++--------- .../MemoryPoolBlock2Tests.cs | 13 +- .../KnownHeaders.cs | 10 +- 9 files changed, 173 insertions(+), 201 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Filter/LibuvStream.cs b/src/Microsoft.AspNet.Server.Kestrel/Filter/LibuvStream.cs index d61c0eafbc..b4e92b2d76 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Filter/LibuvStream.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Filter/LibuvStream.cs @@ -68,13 +68,29 @@ namespace Microsoft.AspNet.Server.Kestrel.Filter public override void Write(byte[] buffer, int offset, int count) { - var segment = new ArraySegment(buffer, offset, count); + ArraySegment segment; + if (buffer != null) + { + segment = new ArraySegment(buffer, offset, count); + } + else + { + segment = default(ArraySegment); + } _output.Write(segment); } public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken token) { - var segment = new ArraySegment(buffer, offset, count); + ArraySegment segment; + if (buffer != null) + { + segment = new ArraySegment(buffer, offset, count); + } + else + { + segment = default(ArraySegment); + } return _output.WriteAsync(segment, cancellationToken: token); } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Filter/StreamSocketOutput.cs b/src/Microsoft.AspNet.Server.Kestrel/Filter/StreamSocketOutput.cs index ba7c57dcf4..e990e34ee8 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Filter/StreamSocketOutput.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Filter/StreamSocketOutput.cs @@ -52,7 +52,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Filter returnBlock.Pool?.Return(returnBlock); } - _outputStream.Write(end.Block.Array, end.Block.Data.Offset, end.Index); + _outputStream.Write(end.Block.Array, end.Block.Data.Offset, end.Index - end.Block.Data.Offset); end.Block.Pool?.Return(end.Block); } } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs index 98652050cd..e86daad1ea 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs @@ -623,8 +623,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http bool appCompleted, bool immediate) { - var memoryBlock = Memory2.Lease(); - var begin = memoryBlock.GetIterator(); + var begin = SocketOutput.ProducingStart(); + var count = 0; var end = begin; if (_keepAlive) { @@ -673,48 +673,20 @@ namespace Microsoft.AspNet.Server.Kestrel.Http _responseHeaders.SetRawConnection("keep-alive", _bytesConnectionKeepAlive); } - end.CopyFrom(_httpVersion == HttpVersionType.Http1_1 ? _bytesHttpVersion1_1 : _bytesHttpVersion1_0); - end.CopyFrom(statusBytes); - _responseHeaders.CopyTo(ref end); - end.CopyFrom(_bytesEndHeaders, 0, _bytesEndHeaders.Length); + count += end.CopyFrom(_httpVersion == HttpVersionType.Http1_1 ? _bytesHttpVersion1_1 : _bytesHttpVersion1_0); + count += end.CopyFrom(statusBytes); + count += _responseHeaders.CopyTo(ref end); + count += end.CopyFrom(_bytesEndHeaders, 0, _bytesEndHeaders.Length); - // TODO: change this to SocketOutput.ProduceStart/ProduceComplete once that change is made - var scan = begin.Block; - while (scan.Next != null) - { - if (scan.Start != scan.End) - { - SocketOutput.WriteAsync( - new ArraySegment(scan.Array, scan.Start, scan.End - scan.Start), - false); - } - var next = scan.Next; - Memory2.Return(scan); - scan = next; - } - var writeTask = SocketOutput.WriteAsync( - new ArraySegment(scan.Array, scan.Start, scan.End - scan.Start), - immediate); + SocketOutput.ProducingComplete(end, count); - if (writeTask.IsCompleted) + if (immediate) { - Memory2.Return(scan); - return TaskUtilities.CompletedTask; + return SocketOutput.WriteAsync(default(ArraySegment), immediate: true); } else { - return writeTask.ContinueWith( - (t, o) => - { - var mb = (MemoryPoolBlock2)o; - mb.Pool.Return(mb); - - if (t.IsFaulted) - { - throw t.Exception; - } - }, - scan); + return TaskUtilities.CompletedTask; } } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameHeaders.Generated.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameHeaders.Generated.cs index 5571e9c56b..bc7f4d0caa 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameHeaders.Generated.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameHeaders.Generated.cs @@ -7821,15 +7821,16 @@ namespace Microsoft.AspNet.Server.Kestrel.Http ((ICollection>)MaybeUnknown)?.CopyTo(array, arrayIndex); } - protected void CopyToFast(ref MemoryPoolIterator2 output) + protected int CopyToFast(ref MemoryPoolIterator2 output) { + var count = 0; if (((_bits & 1L) != 0)) { foreach(var value in _CacheControl) { - output.CopyFrom(_headerBytes, 0, 17); - output.CopyFromAscii(value); + count += output.CopyFrom(_headerBytes, 0, 17); + count += output.CopyFromAscii(value); } } @@ -7837,12 +7838,12 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { if (_rawConnection != null) { - output.CopyFrom(_rawConnection, 0, _rawConnection.Length); + count += output.CopyFrom(_rawConnection, 0, _rawConnection.Length); } else foreach(var value in _Connection) { - output.CopyFrom(_headerBytes, 17, 14); - output.CopyFromAscii(value); + count += output.CopyFrom(_headerBytes, 17, 14); + count += output.CopyFromAscii(value); } } @@ -7850,12 +7851,12 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { if (_rawDate != null) { - output.CopyFrom(_rawDate, 0, _rawDate.Length); + count += output.CopyFrom(_rawDate, 0, _rawDate.Length); } else foreach(var value in _Date) { - output.CopyFrom(_headerBytes, 31, 8); - output.CopyFromAscii(value); + count += output.CopyFrom(_headerBytes, 31, 8); + count += output.CopyFromAscii(value); } } @@ -7863,8 +7864,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { foreach(var value in _KeepAlive) { - output.CopyFrom(_headerBytes, 39, 14); - output.CopyFromAscii(value); + count += output.CopyFrom(_headerBytes, 39, 14); + count += output.CopyFromAscii(value); } } @@ -7872,8 +7873,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { foreach(var value in _Pragma) { - output.CopyFrom(_headerBytes, 53, 10); - output.CopyFromAscii(value); + count += output.CopyFrom(_headerBytes, 53, 10); + count += output.CopyFromAscii(value); } } @@ -7881,8 +7882,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { foreach(var value in _Trailer) { - output.CopyFrom(_headerBytes, 63, 11); - output.CopyFromAscii(value); + count += output.CopyFrom(_headerBytes, 63, 11); + count += output.CopyFromAscii(value); } } @@ -7890,12 +7891,12 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { if (_rawTransferEncoding != null) { - output.CopyFrom(_rawTransferEncoding, 0, _rawTransferEncoding.Length); + count += output.CopyFrom(_rawTransferEncoding, 0, _rawTransferEncoding.Length); } else foreach(var value in _TransferEncoding) { - output.CopyFrom(_headerBytes, 74, 21); - output.CopyFromAscii(value); + count += output.CopyFrom(_headerBytes, 74, 21); + count += output.CopyFromAscii(value); } } @@ -7903,8 +7904,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { foreach(var value in _Upgrade) { - output.CopyFrom(_headerBytes, 95, 11); - output.CopyFromAscii(value); + count += output.CopyFrom(_headerBytes, 95, 11); + count += output.CopyFromAscii(value); } } @@ -7912,8 +7913,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { foreach(var value in _Via) { - output.CopyFrom(_headerBytes, 106, 7); - output.CopyFromAscii(value); + count += output.CopyFrom(_headerBytes, 106, 7); + count += output.CopyFromAscii(value); } } @@ -7921,8 +7922,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { foreach(var value in _Warning) { - output.CopyFrom(_headerBytes, 113, 11); - output.CopyFromAscii(value); + count += output.CopyFrom(_headerBytes, 113, 11); + count += output.CopyFromAscii(value); } } @@ -7930,8 +7931,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { foreach(var value in _Allow) { - output.CopyFrom(_headerBytes, 124, 9); - output.CopyFromAscii(value); + count += output.CopyFrom(_headerBytes, 124, 9); + count += output.CopyFromAscii(value); } } @@ -7939,12 +7940,12 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { if (_rawContentLength != null) { - output.CopyFrom(_rawContentLength, 0, _rawContentLength.Length); + count += output.CopyFrom(_rawContentLength, 0, _rawContentLength.Length); } else foreach(var value in _ContentLength) { - output.CopyFrom(_headerBytes, 133, 18); - output.CopyFromAscii(value); + count += output.CopyFrom(_headerBytes, 133, 18); + count += output.CopyFromAscii(value); } } @@ -7952,8 +7953,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { foreach(var value in _ContentType) { - output.CopyFrom(_headerBytes, 151, 16); - output.CopyFromAscii(value); + count += output.CopyFrom(_headerBytes, 151, 16); + count += output.CopyFromAscii(value); } } @@ -7961,8 +7962,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { foreach(var value in _ContentEncoding) { - output.CopyFrom(_headerBytes, 167, 20); - output.CopyFromAscii(value); + count += output.CopyFrom(_headerBytes, 167, 20); + count += output.CopyFromAscii(value); } } @@ -7970,8 +7971,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { foreach(var value in _ContentLanguage) { - output.CopyFrom(_headerBytes, 187, 20); - output.CopyFromAscii(value); + count += output.CopyFrom(_headerBytes, 187, 20); + count += output.CopyFromAscii(value); } } @@ -7979,8 +7980,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { foreach(var value in _ContentLocation) { - output.CopyFrom(_headerBytes, 207, 20); - output.CopyFromAscii(value); + count += output.CopyFrom(_headerBytes, 207, 20); + count += output.CopyFromAscii(value); } } @@ -7988,8 +7989,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { foreach(var value in _ContentMD5) { - output.CopyFrom(_headerBytes, 227, 15); - output.CopyFromAscii(value); + count += output.CopyFrom(_headerBytes, 227, 15); + count += output.CopyFromAscii(value); } } @@ -7997,8 +7998,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { foreach(var value in _ContentRange) { - output.CopyFrom(_headerBytes, 242, 17); - output.CopyFromAscii(value); + count += output.CopyFrom(_headerBytes, 242, 17); + count += output.CopyFromAscii(value); } } @@ -8006,8 +8007,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { foreach(var value in _Expires) { - output.CopyFrom(_headerBytes, 259, 11); - output.CopyFromAscii(value); + count += output.CopyFrom(_headerBytes, 259, 11); + count += output.CopyFromAscii(value); } } @@ -8015,8 +8016,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { foreach(var value in _LastModified) { - output.CopyFrom(_headerBytes, 270, 17); - output.CopyFromAscii(value); + count += output.CopyFrom(_headerBytes, 270, 17); + count += output.CopyFromAscii(value); } } @@ -8024,8 +8025,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { foreach(var value in _AcceptRanges) { - output.CopyFrom(_headerBytes, 287, 17); - output.CopyFromAscii(value); + count += output.CopyFrom(_headerBytes, 287, 17); + count += output.CopyFromAscii(value); } } @@ -8033,8 +8034,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { foreach(var value in _Age) { - output.CopyFrom(_headerBytes, 304, 7); - output.CopyFromAscii(value); + count += output.CopyFrom(_headerBytes, 304, 7); + count += output.CopyFromAscii(value); } } @@ -8042,8 +8043,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { foreach(var value in _ETag) { - output.CopyFrom(_headerBytes, 311, 8); - output.CopyFromAscii(value); + count += output.CopyFrom(_headerBytes, 311, 8); + count += output.CopyFromAscii(value); } } @@ -8051,8 +8052,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { foreach(var value in _Location) { - output.CopyFrom(_headerBytes, 319, 12); - output.CopyFromAscii(value); + count += output.CopyFrom(_headerBytes, 319, 12); + count += output.CopyFromAscii(value); } } @@ -8060,8 +8061,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { foreach(var value in _ProxyAutheticate) { - output.CopyFrom(_headerBytes, 331, 21); - output.CopyFromAscii(value); + count += output.CopyFrom(_headerBytes, 331, 21); + count += output.CopyFromAscii(value); } } @@ -8069,8 +8070,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { foreach(var value in _RetryAfter) { - output.CopyFrom(_headerBytes, 352, 15); - output.CopyFromAscii(value); + count += output.CopyFrom(_headerBytes, 352, 15); + count += output.CopyFromAscii(value); } } @@ -8078,12 +8079,12 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { if (_rawServer != null) { - output.CopyFrom(_rawServer, 0, _rawServer.Length); + count += output.CopyFrom(_rawServer, 0, _rawServer.Length); } else foreach(var value in _Server) { - output.CopyFrom(_headerBytes, 367, 10); - output.CopyFromAscii(value); + count += output.CopyFrom(_headerBytes, 367, 10); + count += output.CopyFromAscii(value); } } @@ -8091,8 +8092,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { foreach(var value in _SetCookie) { - output.CopyFrom(_headerBytes, 377, 14); - output.CopyFromAscii(value); + count += output.CopyFrom(_headerBytes, 377, 14); + count += output.CopyFromAscii(value); } } @@ -8100,8 +8101,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { foreach(var value in _Vary) { - output.CopyFrom(_headerBytes, 391, 8); - output.CopyFromAscii(value); + count += output.CopyFrom(_headerBytes, 391, 8); + count += output.CopyFromAscii(value); } } @@ -8109,11 +8110,12 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { foreach(var value in _WWWAuthenticate) { - output.CopyFrom(_headerBytes, 399, 20); - output.CopyFromAscii(value); + count += output.CopyFrom(_headerBytes, 399, 20); + count += output.CopyFromAscii(value); } } + return count; } public unsafe void Append(byte[] keyBytes, int keyOffset, int keyLength, string value) { diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameResponseHeaders.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameResponseHeaders.cs index 86c2a18554..30c75fe4e2 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameResponseHeaders.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameResponseHeaders.cs @@ -10,7 +10,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { public partial class FrameResponseHeaders : FrameHeaders { - private static byte[] _CRLF = new[] { (byte)'\r', (byte)'\n' }; + private static byte[] _CrLf = new[] { (byte)'\r', (byte)'\n' }; private static byte[] _colonSpace = new[] { (byte)':', (byte)' ' }; public bool HasConnection => HeaderConnection.Count != 0; @@ -30,22 +30,23 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return GetEnumerator(); } - public void CopyTo(ref MemoryPoolIterator2 output) + public int CopyTo(ref MemoryPoolIterator2 output) { - CopyToFast(ref output); + var count = CopyToFast(ref output); if (MaybeUnknown != null) { foreach (var kv in MaybeUnknown) { foreach (var value in kv.Value) { - output.CopyFrom(_CRLF, 0, 2); - output.CopyFromAscii(kv.Key); - output.CopyFrom(_colonSpace, 0, 2); - output.CopyFromAscii(value); + count += output.CopyFrom(_CrLf, 0, 2); + count += output.CopyFromAscii(kv.Key); + count += output.CopyFrom(_colonSpace, 0, 2); + count += output.CopyFromAscii(value); } } } + return count; } public partial struct Enumerator : IEnumerator> diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs index 404cb601d5..5f58fac22d 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs @@ -70,11 +70,13 @@ namespace Microsoft.AspNet.Server.Kestrel.Http bool socketShutdownSend = false, bool socketDisconnect = false) { - var tail = ProducingStart(); - tail = tail.CopyFrom(buffer); - // We do our own accounting below - ProducingComplete(tail, count: 0); - + if (buffer.Count > 0) + { + var tail = ProducingStart(); + tail.CopyFrom(buffer); + // We do our own accounting below + ProducingComplete(tail, count: 0); + } TaskCompletionSource tcs = null; lock (_contextLock) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolIterator2.cs b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolIterator2.cs index a3b5e678c5..9af9d4428e 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolIterator2.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolIterator2.cs @@ -532,7 +532,17 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure } } - public MemoryPoolIterator2 CopyFrom(ArraySegment buffer) + public int CopyFrom(byte[] data) + { + return CopyFrom(new ArraySegment(data)); + } + + public int CopyFrom(byte[] data, int offset, int count) + { + return CopyFrom(new ArraySegment(data, offset, count)); + } + + public int CopyFrom(ArraySegment buffer) { Debug.Assert(_block != null); Debug.Assert(_block.Pool != null); @@ -545,11 +555,10 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure var bufferIndex = buffer.Offset; var remaining = buffer.Count; + var bytesLeftInBlock = block.Data.Offset + block.Data.Count - blockIndex; while (remaining > 0) { - var bytesLeftInBlock = block.Data.Offset + block.Data.Count - blockIndex; - if (bytesLeftInBlock == 0) { var nextBlock = pool.Lease(); @@ -560,93 +569,55 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure bytesLeftInBlock = block.Data.Count; } - var bytesToCopy = Math.Min(remaining, bytesLeftInBlock); + var bytesToCopy = remaining < bytesLeftInBlock ? remaining : bytesLeftInBlock; Buffer.BlockCopy(buffer.Array, bufferIndex, block.Array, blockIndex, bytesToCopy); blockIndex += bytesToCopy; bufferIndex += bytesToCopy; remaining -= bytesToCopy; + bytesLeftInBlock -= bytesToCopy; block.End = blockIndex; } - return new MemoryPoolIterator2(block, blockIndex); + _block = block; + _index = blockIndex; + + return buffer.Count; } - public void CopyFrom(byte[] data) - { - CopyFrom(data, 0, data.Length); - } - - public void CopyFrom(byte[] data, int offset, int count) + public unsafe int CopyFromAscii(string data) { + Debug.Assert(_block != null); + Debug.Assert(_block.Pool != null); Debug.Assert(_block.Next == null); Debug.Assert(_block.End == _index); + var pool = _block.Pool; var block = _block; + var blockIndex = _index; + var length = data.Length; - var sourceData = data; - var sourceStart = offset; - var sourceEnd = offset + count; - - var targetData = block.Array; - var targetStart = block.End; - var targetEnd = block.Data.Offset + block.Data.Count; - - while (true) - { - // actual count to copy is remaining data, or unused trailing space in the current block, whichever is smaller - var copyCount = Math.Min(sourceEnd - sourceStart, targetEnd - targetStart); - - Buffer.BlockCopy(sourceData, sourceStart, targetData, targetStart, copyCount); - sourceStart += copyCount; - targetStart += copyCount; - - // if this means all source data has been copied - if (sourceStart == sourceEnd) - { - // increase occupied space in the block, and adjust iterator at start of unused trailing space - block.End = targetStart; - _block = block; - _index = targetStart; - return; - } - - // otherwise another block needs to be allocated to follow this one - block.Next = block.Pool.Lease(); - block = block.Next; - - targetData = block.Array; - targetStart = block.End; - targetEnd = block.Data.Offset + block.Data.Count; - } - } - - public unsafe void CopyFromAscii(string data) - { - Debug.Assert(_block.Next == null); - Debug.Assert(_block.End == _index); - - var block = _block; - - var inputLength = data.Length; - var inputLengthMinusSpan = inputLength - 3; + var bytesLeftInBlock = block.Data.Offset + block.Data.Count - blockIndex; + var bytesLeftInBlockMinusSpan = bytesLeftInBlock - 3; fixed (char* pData = data) { var input = pData; - var inputEnd = pData + data.Length; - var blockRemaining = block.Data.Offset + block.Data.Count - block.End; - var blockRemainingMinusSpan = blockRemaining - 3; + var inputEnd = pData + length; + var inputEndMinusSpan = inputEnd - 3; while (input < inputEnd) { - if (blockRemaining == 0) + if (bytesLeftInBlock == 0) { - block.Next = block.Pool.Lease(); - block = block.Next; - blockRemaining = block.Data.Count; - blockRemainingMinusSpan = blockRemaining - 3; + var nextBlock = pool.Lease(); + block.Next = nextBlock; + block = nextBlock; + + blockIndex = block.Data.Offset; + bytesLeftInBlock = block.Data.Count; + bytesLeftInBlockMinusSpan = bytesLeftInBlock - 3; } fixed (byte* pOutput = block.Data.Array) @@ -654,7 +625,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure var output = pOutput + block.End; var copied = 0; - for (; copied < inputLengthMinusSpan && copied < blockRemainingMinusSpan; copied += 4) + for (; input < inputEndMinusSpan && copied < bytesLeftInBlockMinusSpan; copied += 4) { *(output) = (byte)*(input); *(output + 1) = (byte)*(input + 1); @@ -662,19 +633,24 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure *(output + 3) = (byte)*(input + 3); output += 4; input += 4; - blockRemainingMinusSpan -= 4; } - for (; copied < inputLength && copied < blockRemaining; copied++) + for (; input < inputEnd && copied < bytesLeftInBlock; copied++) { *(output++) = (byte)*(input++); - blockRemaining--; } - block.End += copied; - _block = block; - _index = block.End; + + blockIndex += copied; + bytesLeftInBlockMinusSpan -= copied; + bytesLeftInBlock -= copied; } + block.End = blockIndex; } } + + _block = block; + _index = blockIndex; + + return length; } } } diff --git a/test/Microsoft.AspNet.Server.KestrelTests/MemoryPoolBlock2Tests.cs b/test/Microsoft.AspNet.Server.KestrelTests/MemoryPoolBlock2Tests.cs index 5f445ef487..239175e198 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/MemoryPoolBlock2Tests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/MemoryPoolBlock2Tests.cs @@ -159,7 +159,8 @@ namespace Microsoft.AspNet.Server.KestrelTests using (var pool = new MemoryPool2()) { var block1 = pool.Lease(128); - var iterator = block1.GetIterator(); + var start = block1.GetIterator(); + var end = start; var bufferSize = block1.Data.Count * 3; var buffer = new byte[bufferSize]; @@ -170,18 +171,18 @@ namespace Microsoft.AspNet.Server.KestrelTests Assert.Null(block1.Next); - var end = iterator.CopyFrom(new ArraySegment(buffer)); + end.CopyFrom(new ArraySegment(buffer)); Assert.NotNull(block1.Next); for (int i = 0; i < bufferSize; i++) { - Assert.Equal(i % 73, iterator.Take()); + Assert.Equal(i % 73, start.Take()); } - Assert.Equal(-1, iterator.Take()); - Assert.Equal(iterator.Block, end.Block); - Assert.Equal(iterator.Index, end.Index); + Assert.Equal(-1, start.Take()); + Assert.Equal(start.Block, end.Block); + Assert.Equal(start.Index, end.Index); } } diff --git a/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/KnownHeaders.cs b/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/KnownHeaders.cs index ab20b6c2d9..214cf91f6b 100644 --- a/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/KnownHeaders.cs +++ b/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/KnownHeaders.cs @@ -380,22 +380,24 @@ namespace Microsoft.AspNet.Server.Kestrel.Http ((ICollection>)MaybeUnknown)?.CopyTo(array, arrayIndex); }} {(loop.ClassName == "FrameResponseHeaders" ? $@" - protected void CopyToFast(ref MemoryPoolIterator2 output) + protected int CopyToFast(ref MemoryPoolIterator2 output) {{ + var count = 0; {Each(loop.Headers, header => $@" if ({header.TestBit()}) {{ {(header.EnhancedSetter == false ? "" : $@" if (_raw{header.Identifier} != null) {{ - output.CopyFromAscii(_raw{header.Identifier}, 0, _raw{header.Identifier}.Length); + count += output.CopyFrom(_raw{header.Identifier}, 0, _raw{header.Identifier}.Length); }} else ")} foreach(var value in _{header.Identifier}) {{ - output.CopyFromAscii(_headerBytes, {header.BytesOffset}, {header.BytesCount}); - output.CopyFromAscii(value); + count += output.CopyFrom(_headerBytes, {header.BytesOffset}, {header.BytesCount}); + count += output.CopyFromAscii(value); }} }} ")} + return count; }}" : "")} public unsafe void Append(byte[] keyBytes, int keyOffset, int keyLength, string value) {{ From e4fd91bb68f535801ca8a79aa453ea3fb3f448fe Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Fri, 20 Nov 2015 14:07:40 -0800 Subject: [PATCH 0467/1662] Fix hang on Connection: close requests. (#406) --- .../Http/Frame.cs | 7 +++-- .../RequestTests.cs | 31 +++++++++++++++++++ 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs index 8dc2670a6a..2f26f68348 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs @@ -279,8 +279,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { await ProduceEnd(); - // Finish reading the request body in case the app did not. - await messageBody.Consume(); + if (_keepAlive) + { + // Finish reading the request body in case the app did not. + await messageBody.Consume(); + } } _requestBody.StopAcceptingReads(); diff --git a/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/RequestTests.cs b/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/RequestTests.cs index c125da04b5..861a2a84c3 100644 --- a/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/RequestTests.cs +++ b/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/RequestTests.cs @@ -88,6 +88,37 @@ namespace Microsoft.AspNet.Server.Kestrel.FunctionalTests return TestRemoteIPAddress("[::1]", "[::1]", "::1", "8792"); } + [ConditionalFact] + [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Test hangs after execution on Mono.")] + public async Task DoesNotHangOnConnectionCloseRequest() + { + var config = new ConfigurationBuilder().AddInMemoryCollection( + new Dictionary { + { "server.urls", "http://localhost:8791" } + }).Build(); + + var builder = new WebHostBuilder(config) + .UseServerFactory("Microsoft.AspNet.Server.Kestrel") + .UseStartup(app => + { + app.Run(async context => + { + var connection = context.Connection; + await context.Response.WriteAsync("hello, world"); + }); + }); + + using (var app = builder.Build().Start()) + using (var client = new HttpClient()) + { + client.DefaultRequestHeaders.Connection.Clear(); + client.DefaultRequestHeaders.Connection.Add("close"); + + var response = await client.GetAsync("http://localhost:8791/"); + response.EnsureSuccessStatusCode(); + } + } + private async Task TestRemoteIPAddress(string registerAddress, string requestAddress, string expectAddress, string port) { var config = new ConfigurationBuilder().AddInMemoryCollection( From c7d7f0e57514b990e1dc04dd794912c2c79965dd Mon Sep 17 00:00:00 2001 From: stephentoub Date: Sat, 21 Nov 2015 08:38:48 -0500 Subject: [PATCH 0468/1662] Lazily allocate the RequestAborted CTS Avoid allocating the CancellationTokenSource unless it's actually requested. This makes it pay-for-play with regards to code that actually asks for the RequestAborted token and requests that are aborted. --- .../Http/Frame.cs | 61 ++++++++++++++----- 1 file changed, 45 insertions(+), 16 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs index 3922f4d9d7..4d0b19af45 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs @@ -44,6 +44,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http private volatile bool _requestProcessingStopping; // volatile, see: https://msdn.microsoft.com/en-us/library/x13ttww7.aspx private volatile bool _requestAborted; private CancellationTokenSource _abortedCts; + private CancellationToken? _manuallySetRequestAbortToken; private FrameRequestStream _requestBody; private FrameResponseStream _responseBody; @@ -92,8 +93,47 @@ namespace Microsoft.AspNet.Server.Kestrel.Http public Stream DuplexStream { get; set; } - public CancellationToken RequestAborted { get; set; } + public CancellationToken RequestAborted + { + get + { + // If a request abort token was previously explicitly set, return it. + if (_manuallySetRequestAbortToken.HasValue) + return _manuallySetRequestAbortToken.Value; + // Otherwise, get the abort CTS. If we have one, which would mean that someone previously + // asked for the RequestAborted token, simply return its token. If we don't, + // check to see whether we've already aborted, in which case just return an + // already canceled token. Finally, force a source into existence if we still + // don't have one, and return its token. + var cts = _abortedCts; + return + cts != null ? cts.Token : + _requestAborted ? new CancellationToken(true) : + RequestAbortedSource.Token; + } + set + { + // Set an abort token, overriding one we create internally. This setter and associated + // field exist purely to support IHttpRequestLifetimeFeature.set_RequestAborted. + _manuallySetRequestAbortToken = value; + } + } + + private CancellationTokenSource RequestAbortedSource + { + get + { + // Get the abort token, lazily-initializing it if necessary. + // Make sure it's canceled if an abort request already came in. + var cts = LazyInitializer.EnsureInitialized(ref _abortedCts, () => new CancellationTokenSource()); + if (_requestAborted) + { + cts.Cancel(); + } + return cts; + } + } public bool HasResponseStarted { get { return _responseStarted; } @@ -145,7 +185,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http _prepareRequest?.Invoke(this); - _abortedCts?.Dispose(); + _manuallySetRequestAbortToken = null; _abortedCts = null; } @@ -198,16 +238,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { ConnectionControl.End(ProduceEndType.SocketDisconnect); SocketInput.AbortAwaiting(); - - try - { - _abortedCts?.Cancel(); - } - catch (ObjectDisposedException) - { - // Don't log ODEs thrown from _abortedCts.Cancel() - // If _abortedCts is disposed, the app has already completed. - } + RequestAbortedSource.Cancel(); } catch (Exception ex) { @@ -215,7 +246,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } finally { - _abortedCts?.Dispose(); _abortedCts = null; } } @@ -261,8 +291,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http ResponseBody = _responseBody; DuplexStream = new FrameDuplexStream(RequestBody, ResponseBody); - _abortedCts = new CancellationTokenSource(); - RequestAborted = _abortedCts.Token; + _abortedCts = null; + _manuallySetRequestAbortToken = null; var httpContext = HttpContextFactory.Create(this); try @@ -315,7 +345,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { try { - _abortedCts?.Dispose(); _abortedCts = null; // If _requestAborted is set, the connection has already been closed. From 81dba3961d809d4624677b1d87f78968e521a7fa Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Sat, 21 Nov 2015 14:13:23 +0000 Subject: [PATCH 0469/1662] less work in locks --- .../Http/SocketOutput.cs | 135 +++++++++++++----- 1 file changed, 100 insertions(+), 35 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs index 5f58fac22d..911a5a9675 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs @@ -16,6 +16,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { private const int _maxPendingWrites = 3; private const int _maxBytesPreCompleted = 65536; + private const int _initialTaskQueues = 64; + + private static WaitCallback _returnBlocks = (state) => ReturnBlocks((MemoryPoolBlock2)state); private readonly KestrelThread _thread; private readonly UvStreamHandle _socket; @@ -44,6 +47,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http private Exception _lastWriteError; private WriteContext _nextWriteContext; private readonly Queue> _tasksPending; + private readonly Queue> _tasksCompleted; public SocketOutput( KestrelThread thread, @@ -58,7 +62,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http _connection = connection; _connectionId = connectionId; _log = log; - _tasksPending = new Queue>(); + _tasksPending = new Queue>(_initialTaskQueues); + _tasksCompleted = new Queue>(_initialTaskQueues); _head = memory.Lease(); _tail = _head; @@ -79,6 +84,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } TaskCompletionSource tcs = null; + var scheduleWrite = false; + lock (_contextLock) { if (_nextWriteContext == null) @@ -118,11 +125,16 @@ namespace Microsoft.AspNet.Server.Kestrel.Http if (_writesPending < _maxPendingWrites && immediate) { - ScheduleWrite(); + scheduleWrite = true; _writesPending++; } } + if (scheduleWrite) + { + ScheduleWrite(); + } + // Return TaskCompletionSource's Task if set, otherwise completed Task return tcs?.Task ?? TaskUtilities.CompletedTask; } @@ -164,6 +176,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Http public void ProducingComplete(MemoryPoolIterator2 end, int count) { + var decreasePreCompleted = false; + MemoryPoolBlock2 blockToReturn = null; + lock (_returnLock) { Debug.Assert(_isProducing); @@ -176,26 +191,40 @@ namespace Microsoft.AspNet.Server.Kestrel.Http if (count != 0) { - lock (_contextLock) - { - _numBytesPreCompleted += count; - } + decreasePreCompleted = true; } } else { - var block = _returnFromOnProducingComplete; - while (block != null) - { - var returnBlock = block; - block = block.Next; - - returnBlock.Pool?.Return(returnBlock); - } - + blockToReturn = _returnFromOnProducingComplete; _returnFromOnProducingComplete = null; } } + + if (decreasePreCompleted) + { + lock (_contextLock) + { + _numBytesPreCompleted += count; + } + } + + + if (blockToReturn != null) + { + ThreadPool.QueueUserWorkItem(_returnBlocks, blockToReturn); + } + } + + private static void ReturnBlocks(MemoryPoolBlock2 block) + { + while(block != null) + { + var returningBlock = block; + block = returningBlock.Next; + + returningBlock.Pool?.Return(returningBlock); + } } private void ScheduleWrite() @@ -252,11 +281,13 @@ namespace Microsoft.AspNet.Server.Kestrel.Http _connection.Abort(); } + bool scheduleWrite = false; + lock (_contextLock) { if (_nextWriteContext != null) { - ScheduleWrite(); + scheduleWrite = true; } else { @@ -279,21 +310,36 @@ namespace Microsoft.AspNet.Server.Kestrel.Http _numBytesPreCompleted += bytesToWrite; bytesLeftToBuffer -= bytesToWrite; - if (_lastWriteError == null) - { - ThreadPool.QueueUserWorkItem( - (o) => ((TaskCompletionSource)o).SetResult(null), - tcs); - } - else - { - // error is closure captured - ThreadPool.QueueUserWorkItem( - (o) => ((TaskCompletionSource)o).SetException(_lastWriteError), - tcs); - } + _tasksCompleted.Enqueue(tcs); } } + + while (_tasksCompleted.Count > 0) + { + var tcs = _tasksCompleted.Dequeue(); + if (_lastWriteError == null) + { + ThreadPool.QueueUserWorkItem( + (o) => ((TaskCompletionSource)o).SetResult(null), + tcs); + } + else + { + // error is closure captured + ThreadPool.QueueUserWorkItem( + (o) => ((TaskCompletionSource)o).SetException(_lastWriteError), + tcs); + } + } + + if (scheduleWrite) + { + // ScheduleWrite(); + // on right thread, fairness issues? + WriteAllPending(); + } + + _tasksCompleted.Clear(); } // This is called on the libuv event loop @@ -345,6 +391,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http private class WriteContext { + private static WaitCallback _returnWrittenBlocks = (state) => ReturnWrittenBlocks((MemoryPoolBlock2)state); + private MemoryPoolIterator2 _lockedStart; private MemoryPoolIterator2 _lockedEnd; private int _bufferCount; @@ -385,7 +433,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { _writeReq.Dispose(); var _this = (WriteContext)state; - _this.ReturnFullyWrittenBlocks(); + _this.ScheduleReturnFullyWrittenBlocks(); _this.WriteStatus = status; _this.WriteError = error; _this.DoShutdownIfNeeded(); @@ -441,11 +489,30 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { Self.OnWriteCompleted(_byteCount, WriteStatus, WriteError); } - - private void ReturnFullyWrittenBlocks() + + private void ScheduleReturnFullyWrittenBlocks() { var block = _lockedStart.Block; - while (block != _lockedEnd.Block) + var end = _lockedEnd.Block; + if (block == end) + { + end.Unpin(); + return; + } + + while (block.Next != end) + { + block = block.Next; + block.Unpin(); + } + block.Next = null; + + ThreadPool.QueueUserWorkItem(_returnWrittenBlocks, _lockedStart.Block); + } + + private static void ReturnWrittenBlocks(MemoryPoolBlock2 block) + { + while (block != null) { var returnBlock = block; block = block.Next; @@ -453,8 +520,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Http returnBlock.Unpin(); returnBlock.Pool?.Return(returnBlock); } - - _lockedEnd.Block.Unpin(); } private void LockWrite() From 7f025a6bd4c1b79e3d64819589a5f957d057df64 Mon Sep 17 00:00:00 2001 From: Sunny Ahuwanya Date: Sat, 28 Nov 2015 20:15:17 -0500 Subject: [PATCH 0470/1662] Speed up DateHeaderValueManager Replaced PumpTimer() method with StartTimer(), introduced StopTimer() method which pauses timer when idle instead of disposing it, ISystemClock returns DateTime instead of DateTimeOffset. --- .../Http/DateHeaderValueManager.cs | 165 ++++++++++++------ .../Infrastructure/ISystemClock.cs | 2 +- .../Infrastructure/SystemClock.cs | 4 +- 3 files changed, 116 insertions(+), 55 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/DateHeaderValueManager.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/DateHeaderValueManager.cs index b85aaa2b1a..79cfbc7d92 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/DateHeaderValueManager.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/DateHeaderValueManager.cs @@ -22,10 +22,14 @@ namespace Microsoft.AspNet.Server.Kestrel.Http private readonly byte[] _dateBytes0 = Encoding.ASCII.GetBytes("\r\nDate: DDD, dd mmm yyyy hh:mm:ss GMT"); private readonly byte[] _dateBytes1 = Encoding.ASCII.GetBytes("\r\nDate: DDD, dd mmm yyyy hh:mm:ss GMT"); private object _timerLocker = new object(); - private bool _isDisposed = false; - private bool _hadRequestsSinceLastTimerTick = false; + private volatile bool _isDisposed = false; + private volatile bool _hadRequestsSinceLastTimerTick = false; private Timer _dateValueTimer; - private DateTimeOffset _lastRequestSeen = DateTimeOffset.MinValue; + private long _lastRequestSeenTicks; + private long _lastReadDateTimeTicks; + private readonly bool _is64BitSystem; + private readonly long _ticksInOneSecond; + private volatile bool _timerIsRunning; /// /// Initializes a new instance of the class. @@ -34,9 +38,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http : this( systemClock: new SystemClock(), timeWithoutRequestsUntilIdle: TimeSpan.FromSeconds(10), - timerInterval: TimeSpan.FromSeconds(1)) + timerInterval: TimeSpan.FromMilliseconds(200)) { - } // Internal for testing @@ -48,6 +51,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http _systemClock = systemClock; _timeWithoutRequestsUntilIdle = timeWithoutRequestsUntilIdle; _timerInterval = timerInterval; + _dateValueTimer = new Timer(TimerLoop, state: null, dueTime: Timeout.Infinite, period: Timeout.Infinite); + _is64BitSystem = IntPtr.Size >= 8; } /// @@ -57,103 +62,159 @@ namespace Microsoft.AspNet.Server.Kestrel.Http /// The value. public virtual string GetDateHeaderValue() { - PumpTimer(); - - // See https://msdn.microsoft.com/en-us/library/az4se3k1(v=vs.110).aspx#RFC1123 for info on the format - // string used here. - // The null-coalesce here is to protect against returning null after Dispose() is called, at which - // point _dateValue will be null forever after. - return _dateValue ?? _systemClock.UtcNow.ToString(Constants.RFC1123DateFormat); + _hadRequestsSinceLastTimerTick = true; + PrepareDateValues(); + return _dateValue; } public byte[] GetDateHeaderValueBytes() { - PumpTimer(); + _hadRequestsSinceLastTimerTick = true; + PrepareDateValues(); return _activeDateBytes ? _dateBytes0 : _dateBytes1; } + /// /// Releases all resources used by the current instance of . /// public void Dispose() { - lock (_timerLocker) + if (!_isDisposed) { - DisposeTimer(); - _isDisposed = true; + + lock (_timerLocker) + { + if (_dateValueTimer != null) + { + _timerIsRunning = false; + _dateValueTimer.Dispose(); + _dateValueTimer = null; + } + } } } - private void PumpTimer() - { - _hadRequestsSinceLastTimerTick = true; - // If we're already disposed we don't care about starting the timer again. This avoids us having to worry - // about requests in flight during dispose (not that that should actually happen) as those will just get - // SystemClock.UtcNow (aka "the slow way"). - if (!_isDisposed && _dateValueTimer == null) + /// + /// Starts the timer + /// + private void StartTimer() + { + var now = _systemClock.UtcNow; + SetDateValues(now); + WriteLongThreadSafe(ref _lastReadDateTimeTicks, now.Ticks); + + if (!_isDisposed) { lock (_timerLocker) { - if (!_isDisposed && _dateValueTimer == null) + if (!_timerIsRunning && _dateValueTimer != null) { - // Immediately assign the date value and start the timer again. We assign the value immediately - // here as the timer won't fire until the timer interval has passed and we want a value assigned - // inline now to serve requests that occur in the meantime. - _dateValue = _systemClock.UtcNow.ToString(Constants.RFC1123DateFormat); - Encoding.ASCII.GetBytes(_dateValue, 0, _dateValue.Length, !_activeDateBytes ? _dateBytes0 : _dateBytes1, "\r\nDate: ".Length); - _activeDateBytes = !_activeDateBytes; - _dateValueTimer = new Timer(UpdateDateValue, state: null, dueTime: _timerInterval, period: _timerInterval); + _timerIsRunning = true; + _dateValueTimer.Change(_timerInterval, _timerInterval); + } + } + } + } + + /// + /// Stops the timer + /// + private void StopTimer() + { + if (!_isDisposed) + { + lock (_timerLocker) + { + if (_dateValueTimer != null) + { + _timerIsRunning = false; + _dateValueTimer.Change(Timeout.Infinite, Timeout.Infinite); } } } } // Called by the Timer (background) thread - private void UpdateDateValue(object state) + private void TimerLoop(object state) { var now = _systemClock.UtcNow; + var lastReadDateTime = new DateTime(ReadLongThreadSafe(ref _lastReadDateTimeTicks)); - // See http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.18 for required format of Date header - _dateValue = now.ToString(Constants.RFC1123DateFormat); - Encoding.ASCII.GetBytes(_dateValue, 0, _dateValue.Length, !_activeDateBytes ? _dateBytes0 : _dateBytes1, "\r\nDate: ".Length); - _activeDateBytes = !_activeDateBytes; + //Are we in a new second? + if (now - lastReadDateTime >= TimeSpan.FromSeconds(1) || now.Second != lastReadDateTime.Second) + { + //Yep, Update DateValues + SetDateValues(now); + WriteLongThreadSafe(ref _lastReadDateTimeTicks, now.Ticks); + } if (_hadRequestsSinceLastTimerTick) { // We served requests since the last tick, reset the flag and return as we're still active _hadRequestsSinceLastTimerTick = false; - _lastRequestSeen = now; + WriteLongThreadSafe(ref _lastRequestSeenTicks, now.Ticks); return; } // No requests since the last timer tick, we need to check if we're beyond the idle threshold - var timeSinceLastRequestSeen = now - _lastRequestSeen; - if (timeSinceLastRequestSeen >= _timeWithoutRequestsUntilIdle) + if ((now.Ticks - ReadLongThreadSafe(ref _lastRequestSeenTicks)) >= _timeWithoutRequestsUntilIdle.Ticks) { // No requests since idle threshold so stop the timer if it's still running - if (_dateValueTimer != null) + StopTimer(); + } + } + + /// + /// Starts the timer if it's turned off, or sets the datevalues to the current time if disposed. + /// + private void PrepareDateValues() + { + if (_isDisposed) + { + SetDateValues(_systemClock.UtcNow); + } + else + { + if (!_timerIsRunning) { - lock (_timerLocker) - { - if (_dateValueTimer != null) - { - DisposeTimer(); - } - } + StartTimer(); } } } - private void DisposeTimer() + + /// + /// Sets date values from a provided ticks value + /// + /// A valid ticks value + private void SetDateValues(DateTime value) { - if (_dateValueTimer != null) + // See http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.18 for required format of Date header + _dateValue = value.ToString(Constants.RFC1123DateFormat); + Encoding.ASCII.GetBytes(_dateValue, 0, _dateValue.Length, !_activeDateBytes ? _dateBytes0 : _dateBytes1, "\r\nDate: ".Length); + _activeDateBytes = !_activeDateBytes; + } + + private void WriteLongThreadSafe(ref long location, long value) + { + Interlocked.Exchange(ref location, value); + } + + private long ReadLongThreadSafe(ref long location) + { + if (_is64BitSystem) { - _dateValueTimer.Dispose(); - _dateValueTimer = null; - _dateValue = null; + return location; + } + else + { + return Interlocked.Read(ref location); } } + } } + diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/ISystemClock.cs b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/ISystemClock.cs index c741621de4..ec3a2eb8fa 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/ISystemClock.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/ISystemClock.cs @@ -13,6 +13,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure /// /// Retrieves the current system time in UTC. /// - DateTimeOffset UtcNow { get; } + DateTime UtcNow { get; } } } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/SystemClock.cs b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/SystemClock.cs index c16d40bf6a..362be11a0a 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/SystemClock.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/SystemClock.cs @@ -13,11 +13,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure /// /// Retrieves the current system time in UTC. /// - public DateTimeOffset UtcNow + public DateTime UtcNow { get { - return DateTimeOffset.UtcNow; + return DateTime.UtcNow; } } } From 67a0f2d420a090a1d0bc74db17deff34da30cd96 Mon Sep 17 00:00:00 2001 From: Sunny Ahuwanya Date: Sat, 28 Nov 2015 21:27:51 -0500 Subject: [PATCH 0471/1662] Reverted ISystemClock to use DateTimeOffset --- .../Http/DateHeaderValueManager.cs | 7 +++---- .../Infrastructure/ISystemClock.cs | 2 +- .../Infrastructure/SystemClock.cs | 4 ++-- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/DateHeaderValueManager.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/DateHeaderValueManager.cs index 79cfbc7d92..8ca7ec12b1 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/DateHeaderValueManager.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/DateHeaderValueManager.cs @@ -28,7 +28,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Http private long _lastRequestSeenTicks; private long _lastReadDateTimeTicks; private readonly bool _is64BitSystem; - private readonly long _ticksInOneSecond; private volatile bool _timerIsRunning; /// @@ -141,7 +140,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http private void TimerLoop(object state) { var now = _systemClock.UtcNow; - var lastReadDateTime = new DateTime(ReadLongThreadSafe(ref _lastReadDateTimeTicks)); + var lastReadDateTime = new DateTimeOffset(ReadLongThreadSafe(ref _lastReadDateTimeTicks), TimeSpan.Zero); //Are we in a new second? if (now - lastReadDateTime >= TimeSpan.FromSeconds(1) || now.Second != lastReadDateTime.Second) @@ -189,8 +188,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http /// /// Sets date values from a provided ticks value /// - /// A valid ticks value - private void SetDateValues(DateTime value) + /// A DateTimeOffset value + private void SetDateValues(DateTimeOffset value) { // See http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.18 for required format of Date header _dateValue = value.ToString(Constants.RFC1123DateFormat); diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/ISystemClock.cs b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/ISystemClock.cs index ec3a2eb8fa..c741621de4 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/ISystemClock.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/ISystemClock.cs @@ -13,6 +13,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure /// /// Retrieves the current system time in UTC. /// - DateTime UtcNow { get; } + DateTimeOffset UtcNow { get; } } } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/SystemClock.cs b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/SystemClock.cs index 362be11a0a..c16d40bf6a 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/SystemClock.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/SystemClock.cs @@ -13,11 +13,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure /// /// Retrieves the current system time in UTC. /// - public DateTime UtcNow + public DateTimeOffset UtcNow { get { - return DateTime.UtcNow; + return DateTimeOffset.UtcNow; } } } From 2937fc3c98d16df2e7c11012ed72ab92a252a9be Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Sun, 29 Nov 2015 03:57:47 +0000 Subject: [PATCH 0472/1662] OnConnection->OnConnectionAsync Resolves #433 --- .../HttpsConnectionFilter.cs | 4 ++-- .../Filter/IConnectionFilter.cs | 2 +- .../Filter/LoggingConnectionFilter.cs | 4 ++-- .../Filter/NoOpConnectionFilter.cs | 2 +- src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs | 2 +- .../ConnectionFilterTests.cs | 6 +++--- 6 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel.Https/HttpsConnectionFilter.cs b/src/Microsoft.AspNet.Server.Kestrel.Https/HttpsConnectionFilter.cs index 1d13d6fb2e..615a846c1a 100644 --- a/src/Microsoft.AspNet.Server.Kestrel.Https/HttpsConnectionFilter.cs +++ b/src/Microsoft.AspNet.Server.Kestrel.Https/HttpsConnectionFilter.cs @@ -36,9 +36,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Https _previous = previous; } - public async Task OnConnection(ConnectionFilterContext context) + public async Task OnConnectionAsync(ConnectionFilterContext context) { - await _previous.OnConnection(context); + await _previous.OnConnectionAsync(context); if (string.Equals(context.Address.Scheme, "https", StringComparison.OrdinalIgnoreCase)) { diff --git a/src/Microsoft.AspNet.Server.Kestrel/Filter/IConnectionFilter.cs b/src/Microsoft.AspNet.Server.Kestrel/Filter/IConnectionFilter.cs index accaa3b9d9..437e4e3ed9 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Filter/IConnectionFilter.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Filter/IConnectionFilter.cs @@ -7,6 +7,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Filter { public interface IConnectionFilter { - Task OnConnection(ConnectionFilterContext context); + Task OnConnectionAsync(ConnectionFilterContext context); } } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Filter/LoggingConnectionFilter.cs b/src/Microsoft.AspNet.Server.Kestrel/Filter/LoggingConnectionFilter.cs index 1858715ea9..e34e4fcb50 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Filter/LoggingConnectionFilter.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Filter/LoggingConnectionFilter.cs @@ -27,9 +27,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Filter _previous = previous; } - public async Task OnConnection(ConnectionFilterContext context) + public async Task OnConnectionAsync(ConnectionFilterContext context) { - await _previous.OnConnection(context); + await _previous.OnConnectionAsync(context); context.Connection = new LoggingStream(context.Connection, _logger); } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Filter/NoOpConnectionFilter.cs b/src/Microsoft.AspNet.Server.Kestrel/Filter/NoOpConnectionFilter.cs index 95ecc7a50a..663aea65d3 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Filter/NoOpConnectionFilter.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Filter/NoOpConnectionFilter.cs @@ -9,7 +9,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Filter { public class NoOpConnectionFilter : IConnectionFilter { - public Task OnConnection(ConnectionFilterContext context) + public Task OnConnectionAsync(ConnectionFilterContext context) { return TaskUtilities.CompletedTask; } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs index 03c2a619b9..b49cb06921 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs @@ -80,7 +80,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http try { - ConnectionFilter.OnConnection(_filterContext).ContinueWith((task, state) => + ConnectionFilter.OnConnectionAsync(_filterContext).ContinueWith((task, state) => { var connection = (Connection)state; diff --git a/test/Microsoft.AspNet.Server.KestrelTests/ConnectionFilterTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/ConnectionFilterTests.cs index 5dbe530f14..d0947f8d4c 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/ConnectionFilterTests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/ConnectionFilterTests.cs @@ -118,7 +118,7 @@ namespace Microsoft.AspNet.Server.KestrelTests private RewritingStream _rewritingStream; - public Task OnConnection(ConnectionFilterContext context) + public Task OnConnectionAsync(ConnectionFilterContext context) { _rewritingStream = new RewritingStream(context.Connection); context.Connection = _rewritingStream; @@ -130,7 +130,7 @@ namespace Microsoft.AspNet.Server.KestrelTests private class AsyncConnectionFilter : IConnectionFilter { - public async Task OnConnection(ConnectionFilterContext context) + public async Task OnConnectionAsync(ConnectionFilterContext context) { var oldConnection = context.Connection; @@ -144,7 +144,7 @@ namespace Microsoft.AspNet.Server.KestrelTests private class ThrowingConnectionFilter : IConnectionFilter { - public Task OnConnection(ConnectionFilterContext context) + public Task OnConnectionAsync(ConnectionFilterContext context) { throw new Exception(); } From 9102c1bb92105f9a08ce5446a2c1514c3031eac4 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Sun, 29 Nov 2015 10:13:14 +0000 Subject: [PATCH 0473/1662] Remove unused IMemoryPool --- .../Http/IMemoryPool.cs | 35 ------------------- 1 file changed, 35 deletions(-) delete mode 100644 src/Microsoft.AspNet.Server.Kestrel/Http/IMemoryPool.cs diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/IMemoryPool.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/IMemoryPool.cs deleted file mode 100644 index 82dcc7a218..0000000000 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/IMemoryPool.cs +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; - -namespace Microsoft.AspNet.Server.Kestrel.Http -{ - public interface IMemoryPool - { - byte[] Empty { get; } - - byte[] AllocByte(int minimumSize); - void FreeByte(byte[] memory); - - char[] AllocChar(int minimumSize); - void FreeChar(char[] memory); - - /// - /// Acquires a sub-segment of a larger memory allocation. Used for async sends of write-behind - /// buffers to reduce number of array segments pinned - /// - /// The smallest length of the ArraySegment.Count that may be returned - /// An array segment which is a sub-block of a larger allocation - ArraySegment AllocSegment(int minimumSize); - - /// - /// Frees a sub-segment of a larger memory allocation produced by AllocSegment. The original ArraySegment - /// must be frees exactly once and must have the same offset and count that was returned by the Alloc. - /// If a segment is not freed it won't be re-used and has the same effect as a memory leak, so callers must be - /// implemented exactly correctly. - /// - /// The sub-block that was originally returned by a call to AllocSegment. - void FreeSegment(ArraySegment segment); - } -} \ No newline at end of file From 921c338a40843aeee2f212a2e12d54d27f027983 Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Thu, 19 Nov 2015 21:19:03 -0800 Subject: [PATCH 0474/1662] Support PathBase (#214). --- samples/SampleApp/Startup.cs | 6 +- .../Http/Frame.FeatureCollection.cs | 5 +- .../Http/Frame.cs | 44 ++++++- ...ns.cs => MemoryPoolIterator2Extensions.cs} | 2 +- .../ServerAddress.cs | 18 ++- .../PathBaseTests.cs | 113 ++++++++++++++++++ .../FrameFacts.cs | 8 +- .../FrameResponseHeadersTests.cs | 15 ++- .../ServerAddressFacts.cs | 12 +- 9 files changed, 202 insertions(+), 21 deletions(-) rename src/Microsoft.AspNet.Server.Kestrel/Infrastructure/{MemoryPoolIterator2Extenstions.cs => MemoryPoolIterator2Extensions.cs} (99%) create mode 100644 test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/PathBaseTests.cs diff --git a/samples/SampleApp/Startup.cs b/samples/SampleApp/Startup.cs index 97cca8e51e..a405f0be87 100644 --- a/samples/SampleApp/Startup.cs +++ b/samples/SampleApp/Startup.cs @@ -48,6 +48,10 @@ namespace SampleApp context.Request.PathBase, context.Request.Path, context.Request.QueryString); + Console.WriteLine($"Method: {context.Request.Method}"); + Console.WriteLine($"PathBase: {context.Request.PathBase}"); + Console.WriteLine($"Path: {context.Request.Path}"); + Console.WriteLine($"QueryString: {context.Request.QueryString}"); var connectionFeature = context.Connection; Console.WriteLine($"Peer: {connectionFeature.RemoteIpAddress?.ToString()} {connectionFeature.RemotePort}"); @@ -60,4 +64,4 @@ namespace SampleApp }); } } -} +} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.FeatureCollection.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.FeatureCollection.cs index f0406a7aa5..2de39f8aee 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.FeatureCollection.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.FeatureCollection.cs @@ -27,7 +27,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Http // then the list of `implementedFeatures` in the generated code project MUST also be updated. // See also: tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/FrameFeatureCollection.cs - private string _pathBase; private int _featureRevision; private List> MaybeExtra; @@ -118,12 +117,12 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { get { - return _pathBase ?? ""; + return PathBase ?? ""; } set { - _pathBase = value; + PathBase = value; } } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs index a738cb0c84..13b16b5634 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs @@ -11,7 +11,6 @@ using System.Threading; using System.Threading.Tasks; using Microsoft.AspNet.Http; using Microsoft.AspNet.Http.Features; -using Microsoft.AspNet.Server.Kestrel.Filter; using Microsoft.AspNet.Server.Kestrel.Infrastructure; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Primitives; @@ -70,6 +69,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http private readonly IPEndPoint _remoteEndPoint; private readonly Action _prepareRequest; + private readonly string _pathBase; + public Frame(ConnectionContext context) : this(context, remoteEndPoint: null, localEndPoint: null, prepareRequest: null) { @@ -84,6 +85,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http _remoteEndPoint = remoteEndPoint; _localEndPoint = localEndPoint; _prepareRequest = prepareRequest; + _pathBase = context.ServerAddress.PathBase; FrameControl = this; Reset(); @@ -92,6 +94,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http public string Scheme { get; set; } public string Method { get; set; } public string RequestUri { get; set; } + public string PathBase { get; set; } public string Path { get; set; } public string QueryString { get; set; } public string HttpVersion @@ -198,6 +201,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http Scheme = null; Method = null; RequestUri = null; + PathBase = null; Path = null; QueryString = null; _httpVersion = HttpVersionType.Unknown; @@ -809,7 +813,21 @@ namespace Microsoft.AspNet.Server.Kestrel.Http RequestUri = requestUrlPath; QueryString = queryString; HttpVersion = httpVersion; - Path = RequestUri; + + bool caseMatches; + + if (!string.IsNullOrEmpty(_pathBase) && + (requestUrlPath.Length == _pathBase.Length || (requestUrlPath.Length > _pathBase.Length && requestUrlPath[_pathBase.Length] == '/')) && + RequestUrlStartsWithPathBase(requestUrlPath, out caseMatches)) + { + PathBase = caseMatches ? _pathBase : requestUrlPath.Substring(0, _pathBase.Length); + Path = requestUrlPath.Substring(_pathBase.Length); + } + else + { + Path = requestUrlPath; + } + return true; } finally @@ -818,6 +836,28 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } + private bool RequestUrlStartsWithPathBase(string requestUrl, out bool caseMatches) + { + caseMatches = true; + + for (var i = 0; i < _pathBase.Length; i++) + { + if (requestUrl[i] != _pathBase[i]) + { + if (char.ToLowerInvariant(requestUrl[i]) == char.ToLowerInvariant(_pathBase[i])) + { + caseMatches = false; + } + else + { + return false; + } + } + } + + return true; + } + public static bool TakeMessageHeaders(SocketInput input, FrameRequestHeaders requestHeaders) { var scan = input.ConsumingStart(); diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolIterator2Extenstions.cs b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolIterator2Extensions.cs similarity index 99% rename from src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolIterator2Extenstions.cs rename to src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolIterator2Extensions.cs index d46eee028f..d1f83c3d6e 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolIterator2Extenstions.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolIterator2Extensions.cs @@ -6,7 +6,7 @@ using System.Text; namespace Microsoft.AspNet.Server.Kestrel.Infrastructure { - public static class MemoryPoolIterator2Extenstions + public static class MemoryPoolIterator2Extensions { private const int _maxStackAllocBytes = 16384; diff --git a/src/Microsoft.AspNet.Server.Kestrel/ServerAddress.cs b/src/Microsoft.AspNet.Server.Kestrel/ServerAddress.cs index 7f910ce959..1c2e2d00e6 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/ServerAddress.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/ServerAddress.cs @@ -11,7 +11,7 @@ namespace Microsoft.AspNet.Server.Kestrel public class ServerAddress { public string Host { get; private set; } - public string Path { get; private set; } + public string PathBase { get; private set; } public int Port { get; private set; } public string Scheme { get; private set; } @@ -35,7 +35,7 @@ namespace Microsoft.AspNet.Server.Kestrel public override string ToString() { - return Scheme.ToLowerInvariant() + "://" + Host.ToLowerInvariant() + ":" + Port.ToString(CultureInfo.InvariantCulture) + Path.ToLowerInvariant(); + return Scheme.ToLowerInvariant() + "://" + Host.ToLowerInvariant() + ":" + Port.ToString(CultureInfo.InvariantCulture) + PathBase.ToLowerInvariant(); } public override int GetHashCode() @@ -53,7 +53,7 @@ namespace Microsoft.AspNet.Server.Kestrel return string.Equals(Scheme, other.Scheme, StringComparison.OrdinalIgnoreCase) && string.Equals(Host, other.Host, StringComparison.OrdinalIgnoreCase) && Port == other.Port - && string.Equals(Path, other.Path, StringComparison.OrdinalIgnoreCase); + && string.Equals(PathBase, other.PathBase, StringComparison.OrdinalIgnoreCase); } public static ServerAddress FromUrl(string url) @@ -71,7 +71,7 @@ namespace Microsoft.AspNet.Server.Kestrel Scheme = "http", Host = "+", Port = port, - Path = "/" + PathBase = "/" }; } return null; @@ -137,7 +137,15 @@ namespace Microsoft.AspNet.Server.Kestrel serverAddress.Host = url.Substring(schemeDelimiterEnd, pathDelimiterStart - schemeDelimiterEnd); } - serverAddress.Path = url.Substring(pathDelimiterEnd); + // Path should not end with a / since it will be used as PathBase later + if (url[url.Length - 1] == '/') + { + serverAddress.PathBase = url.Substring(pathDelimiterEnd, url.Length - pathDelimiterEnd - 1); + } + else + { + serverAddress.PathBase = url.Substring(pathDelimiterEnd); + } return serverAddress; } diff --git a/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/PathBaseTests.cs b/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/PathBaseTests.cs new file mode 100644 index 0000000000..95df0477ab --- /dev/null +++ b/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/PathBaseTests.cs @@ -0,0 +1,113 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System.Collections.Generic; +using System.Net.Http; +using System.Threading.Tasks; +using Microsoft.AspNet.Builder; +using Microsoft.AspNet.Hosting; +using Microsoft.AspNet.Http; +using Microsoft.AspNet.Testing.xunit; +using Microsoft.Extensions.Configuration; +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; +using Xunit; + +namespace Microsoft.AspNet.Server.Kestrel.FunctionalTests +{ + public class PathBaseTests + { + [ConditionalTheory] + [InlineData("http://localhost:8791/base", "http://localhost:8791/base", "/base", "")] + [InlineData("http://localhost:8791/base", "http://localhost:8791/base/", "/base", "/")] + [InlineData("http://localhost:8791/base", "http://localhost:8791/base/something", "/base", "/something")] + [InlineData("http://localhost:8791/base", "http://localhost:8791/base/something/", "/base", "/something/")] + [InlineData("http://localhost:8791/base/more", "http://localhost:8791/base/more", "/base/more", "")] + [InlineData("http://localhost:8791/base/more", "http://localhost:8791/base/more/something", "/base/more", "/something")] + [InlineData("http://localhost:8791/base/more", "http://localhost:8791/base/more/something/", "/base/more", "/something/")] + [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Test hangs after execution on Mono.")] + public Task RequestPathBaseIsServerPathBase(string registerAddress, string requestAddress, string expectedPathBase, string expectedPath) + { + return TestPathBase(registerAddress, requestAddress, expectedPathBase, expectedPath); + } + + [ConditionalTheory] + [InlineData("http://localhost:8791", "http://localhost:8791/", "", "/")] + [InlineData("http://localhost:8791", "http://localhost:8791/something", "", "/something")] + [InlineData("http://localhost:8791/", "http://localhost:8791/", "", "/")] + [InlineData("http://localhost:8791/base", "http://localhost:8791/", "", "/")] + [InlineData("http://localhost:8791/base", "http://localhost:8791/something", "", "/something")] + [InlineData("http://localhost:8791/base", "http://localhost:8791/baseandsomething", "", "/baseandsomething")] + [InlineData("http://localhost:8791/base", "http://localhost:8791/ba", "", "/ba")] + [InlineData("http://localhost:8791/base", "http://localhost:8791/ba/se", "", "/ba/se")] + [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Test hangs after execution on Mono.")] + public Task DefaultPathBaseIsEmpty(string registerAddress, string requestAddress, string expectedPathBase, string expectedPath) + { + return TestPathBase(registerAddress, requestAddress, expectedPathBase, expectedPath); + } + + [ConditionalTheory] + [InlineData("http://localhost:8791", "http://localhost:8791/", "", "/")] + [InlineData("http://localhost:8791/", "http://localhost:8791/", "", "/")] + [InlineData("http://localhost:8791/base", "http://localhost:8791/base/", "/base", "/")] + [InlineData("http://localhost:8791/base/", "http://localhost:8791/base", "/base", "")] + [InlineData("http://localhost:8791/base/", "http://localhost:8791/base/", "/base", "/")] + [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Test hangs after execution on Mono.")] + public Task PathBaseNeverEndsWithSlash(string registerAddress, string requestAddress, string expectedPathBase, string expectedPath) + { + return TestPathBase(registerAddress, requestAddress, expectedPathBase, expectedPath); + } + + [ConditionalFact] + [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Test hangs after execution on Mono.")] + public Task PathBaseAndPathPreserveRequestCasing() + { + return TestPathBase("http://localhost:8791/base", "http://localhost:8791/Base/Something", "/Base", "/Something"); + } + + [ConditionalFact] + [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Test hangs after execution on Mono.")] + public Task PathBaseCanHaveUTF8Characters() + { + return TestPathBase("http://localhost:8791/b♫se", "http://localhost:8791/b♫se/something", "/b♫se", "/something"); + } + + private async Task TestPathBase(string registerAddress, string requestAddress, string expectedPathBase, string expectedPath) + { + var config = new ConfigurationBuilder().AddInMemoryCollection( + new Dictionary { + { "server.urls", registerAddress } + }).Build(); + + var builder = new WebHostBuilder(config) + .UseServerFactory("Microsoft.AspNet.Server.Kestrel") + .UseStartup(app => + { + app.Run(async context => + { + await context.Response.WriteAsync(JsonConvert.SerializeObject(new + { + PathBase = context.Request.PathBase.Value, + Path = context.Request.Path.Value + })); + }); + }); + + using (var app = builder.Build().Start()) + { + using (var client = new HttpClient()) + { + var response = await client.GetAsync(requestAddress); + response.EnsureSuccessStatusCode(); + + var responseText = await response.Content.ReadAsStringAsync(); + Assert.NotEmpty(responseText); + + var pathFacts = JsonConvert.DeserializeObject(responseText); + Assert.Equal(expectedPathBase, pathFacts["PathBase"].Value()); + Assert.Equal(expectedPath, pathFacts["Path"].Value()); + } + } + } + } +} diff --git a/test/Microsoft.AspNet.Server.KestrelTests/FrameFacts.cs b/test/Microsoft.AspNet.Server.KestrelTests/FrameFacts.cs index d76c015fae..9e3419797f 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/FrameFacts.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/FrameFacts.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using Microsoft.AspNet.Http.Features; +using Microsoft.AspNet.Server.Kestrel; using Microsoft.AspNet.Server.Kestrel.Http; using Xunit; @@ -13,7 +14,12 @@ namespace Microsoft.AspNet.Server.KestrelTests public void ResetResetsScheme() { // Arrange - var frame = new Frame(new ConnectionContext() { DateHeaderValueManager = new DateHeaderValueManager() }); + var connectionContext = new ConnectionContext() + { + DateHeaderValueManager = new DateHeaderValueManager(), + ServerAddress = ServerAddress.FromUrl("http://localhost:5000") + }; + var frame = new Frame(connectionContext); frame.Scheme = "https"; // Act diff --git a/test/Microsoft.AspNet.Server.KestrelTests/FrameResponseHeadersTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/FrameResponseHeadersTests.cs index d0e129c5f3..8082e62ed7 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/FrameResponseHeadersTests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/FrameResponseHeadersTests.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; +using Microsoft.AspNet.Server.Kestrel; using Microsoft.AspNet.Server.Kestrel.Http; using Microsoft.Extensions.Primitives; using Xunit; @@ -14,7 +15,12 @@ namespace Microsoft.AspNet.Server.KestrelTests [Fact] public void InitialDictionaryContainsServerAndDate() { - var frame = new Frame(new ConnectionContext { DateHeaderValueManager = new DateHeaderValueManager() }); + var connectionContext = new ConnectionContext + { + DateHeaderValueManager = new DateHeaderValueManager(), + ServerAddress = ServerAddress.FromUrl("http://localhost:5000") + }; + var frame = new Frame(connectionContext); IDictionary headers = frame.ResponseHeaders; Assert.Equal(2, headers.Count); @@ -37,7 +43,12 @@ namespace Microsoft.AspNet.Server.KestrelTests [Fact] public void InitialEntriesCanBeCleared() { - var frame = new Frame(new ConnectionContext { DateHeaderValueManager = new DateHeaderValueManager() }); + var connectionContext = new ConnectionContext + { + DateHeaderValueManager = new DateHeaderValueManager(), + ServerAddress = ServerAddress.FromUrl("http://localhost:5000") + }; + var frame = new Frame(connectionContext); Assert.True(frame.ResponseHeaders.Count > 0); diff --git a/test/Microsoft.AspNet.Server.KestrelTests/ServerAddressFacts.cs b/test/Microsoft.AspNet.Server.KestrelTests/ServerAddressFacts.cs index 5b280c5e68..1a77598a83 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/ServerAddressFacts.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/ServerAddressFacts.cs @@ -18,30 +18,30 @@ namespace Microsoft.AspNet.Server.KestrelTests [InlineData("http://localhost", "http", "localhost", 80, "")] [InlineData("http://www.example.com", "http", "www.example.com", 80, "")] [InlineData("https://www.example.com", "https", "www.example.com", 443, "")] - [InlineData("http://www.example.com/", "http", "www.example.com", 80, "/")] + [InlineData("http://www.example.com/", "http", "www.example.com", 80, "")] [InlineData("http://www.example.com/foo?bar=baz", "http", "www.example.com", 80, "/foo?bar=baz")] [InlineData("http://www.example.com:5000", "http", "www.example.com", 5000, "")] [InlineData("https://www.example.com:5000", "https", "www.example.com", 5000, "")] - [InlineData("http://www.example.com:5000/", "http", "www.example.com", 5000, "/")] + [InlineData("http://www.example.com:5000/", "http", "www.example.com", 5000, "")] [InlineData("http://www.example.com:NOTAPORT", "http", "www.example.com:NOTAPORT", 80, "")] [InlineData("https://www.example.com:NOTAPORT", "https", "www.example.com:NOTAPORT", 443, "")] - [InlineData("http://www.example.com:NOTAPORT/", "http", "www.example.com:NOTAPORT", 80, "/")] + [InlineData("http://www.example.com:NOTAPORT/", "http", "www.example.com:NOTAPORT", 80, "")] [InlineData("http://foo:/tmp/kestrel-test.sock:5000/doesn't/matter", "http", "foo:", 80, "/tmp/kestrel-test.sock:5000/doesn't/matter")] [InlineData("http://unix:foo/tmp/kestrel-test.sock", "http", "unix:foo", 80, "/tmp/kestrel-test.sock")] [InlineData("http://unix:5000/tmp/kestrel-test.sock", "http", "unix", 5000, "/tmp/kestrel-test.sock")] [InlineData("http://unix:/tmp/kestrel-test.sock", "http", "unix:/tmp/kestrel-test.sock", 0, "")] [InlineData("https://unix:/tmp/kestrel-test.sock", "https", "unix:/tmp/kestrel-test.sock", 0, "")] [InlineData("http://unix:/tmp/kestrel-test.sock:", "http", "unix:/tmp/kestrel-test.sock", 0, "")] - [InlineData("http://unix:/tmp/kestrel-test.sock:/", "http", "unix:/tmp/kestrel-test.sock", 0, "/")] + [InlineData("http://unix:/tmp/kestrel-test.sock:/", "http", "unix:/tmp/kestrel-test.sock", 0, "")] [InlineData("http://unix:/tmp/kestrel-test.sock:5000/doesn't/matter", "http", "unix:/tmp/kestrel-test.sock", 0, "5000/doesn't/matter")] - public void UrlsAreParsedCorrectly(string url, string scheme, string host, int port, string path) + public void UrlsAreParsedCorrectly(string url, string scheme, string host, int port, string pathBase) { var serverAddress = ServerAddress.FromUrl(url); Assert.Equal(scheme, serverAddress.Scheme); Assert.Equal(host, serverAddress.Host); Assert.Equal(port, serverAddress.Port); - Assert.Equal(path, serverAddress.Path); + Assert.Equal(pathBase, serverAddress.PathBase); } } } From 6251b8f3e6fc96b3a3c8cc77c931647bc1a7defd Mon Sep 17 00:00:00 2001 From: Sunny Ahuwanya Date: Tue, 1 Dec 2015 09:29:54 -0500 Subject: [PATCH 0475/1662] Changed timer interval to 1 second. --- .../Http/DateHeaderValueManager.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/DateHeaderValueManager.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/DateHeaderValueManager.cs index 8ca7ec12b1..e8a5d914f5 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/DateHeaderValueManager.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/DateHeaderValueManager.cs @@ -37,7 +37,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http : this( systemClock: new SystemClock(), timeWithoutRequestsUntilIdle: TimeSpan.FromSeconds(10), - timerInterval: TimeSpan.FromMilliseconds(200)) + timerInterval: TimeSpan.FromSeconds(1)) { } From 168f4770f450d3b3ca73c2330d42c8f64661b899 Mon Sep 17 00:00:00 2001 From: John Luo Date: Tue, 17 Nov 2015 16:19:36 -0800 Subject: [PATCH 0476/1662] Reacting to new IServer and IHttpApplication design --- .../Http/Connection.cs | 2 +- .../Http/Frame.cs | 155 +++--------------- .../Http/FrameOfT.cs | 153 +++++++++++++++++ .../Http/Listener.cs | 4 +- .../Http/ListenerContext.cs | 3 - .../Http/ListenerPrimary.cs | 6 +- .../Http/ListenerSecondary.cs | 4 +- .../KestrelEngine.cs | 8 +- .../KestrelServer.cs | 20 +-- .../ServerFactory.cs | 7 +- .../ServiceContext.cs | 8 +- .../DummyApplication.cs | 37 +++++ .../EngineTests.cs | 11 +- .../FrameFacts.cs | 2 +- .../FrameResponseHeadersTests.cs | 4 +- .../TestServer.cs | 8 +- .../TestServiceContext.cs | 22 ++- 17 files changed, 274 insertions(+), 180 deletions(-) create mode 100644 src/Microsoft.AspNet.Server.Kestrel/Http/FrameOfT.cs create mode 100644 test/Microsoft.AspNet.Server.KestrelTests/DummyApplication.cs diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs index 03c2a619b9..40c5c16331 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs @@ -185,7 +185,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http private Frame CreateFrame() { - return new Frame(this, _remoteEndPoint, _localEndPoint, _filterContext?.PrepareRequest); + return FrameFactory(this, _remoteEndPoint, _localEndPoint, _filterContext?.PrepareRequest); } void IConnectionControl.Pause() diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs index 13b16b5634..98dee5304c 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs @@ -19,7 +19,7 @@ using Microsoft.Extensions.Primitives; namespace Microsoft.AspNet.Server.Kestrel.Http { - public partial class Frame : FrameContext, IFrameControl + public abstract partial class Frame : FrameContext, IFrameControl { private static readonly Encoding _ascii = Encoding.ASCII; private static readonly ArraySegment _endChunkBytes = CreateAsciiByteArraySegment("\r\n"); @@ -41,7 +41,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http private readonly object _onStartingSync = new Object(); private readonly object _onCompletedSync = new Object(); - private readonly FrameRequestHeaders _requestHeaders = new FrameRequestHeaders(); + protected readonly FrameRequestHeaders _requestHeaders = new FrameRequestHeaders(); private readonly FrameResponseHeaders _responseHeaders = new FrameResponseHeaders(); private List, object>> _onStarting; @@ -50,18 +50,18 @@ namespace Microsoft.AspNet.Server.Kestrel.Http private bool _requestProcessingStarted; private Task _requestProcessingTask; - private volatile bool _requestProcessingStopping; // volatile, see: https://msdn.microsoft.com/en-us/library/x13ttww7.aspx - private volatile bool _requestAborted; - private CancellationTokenSource _abortedCts; - private CancellationToken? _manuallySetRequestAbortToken; + protected volatile bool _requestProcessingStopping; // volatile, see: https://msdn.microsoft.com/en-us/library/x13ttww7.aspx + protected volatile bool _requestAborted; + protected CancellationTokenSource _abortedCts; + protected CancellationToken? _manuallySetRequestAbortToken; - private FrameRequestStream _requestBody; - private FrameResponseStream _responseBody; + internal FrameRequestStream _requestBody; + internal FrameResponseStream _responseBody; - private bool _responseStarted; - private bool _keepAlive; + protected bool _responseStarted; + protected bool _keepAlive; private bool _autoChunk; - private Exception _applicationException; + protected Exception _applicationException; private HttpVersionType _httpVersion; @@ -306,119 +306,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http /// The resulting Task from this loop is preserved in a field which is used when the server needs /// to drain and close all currently active connections. /// - public async Task RequestProcessingAsync() - { - try - { - var terminated = false; - while (!terminated && !_requestProcessingStopping) - { - while (!terminated && !_requestProcessingStopping && !TakeStartLine(SocketInput)) - { - terminated = SocketInput.RemoteIntakeFin; - if (!terminated) - { - await SocketInput; - } - } - - while (!terminated && !_requestProcessingStopping && !TakeMessageHeaders(SocketInput, _requestHeaders)) - { - terminated = SocketInput.RemoteIntakeFin; - if (!terminated) - { - await SocketInput; - } - } - - if (!terminated && !_requestProcessingStopping) - { - var messageBody = MessageBody.For(HttpVersion, _requestHeaders, this); - _keepAlive = messageBody.RequestKeepAlive; - _requestBody = new FrameRequestStream(messageBody); - RequestBody = _requestBody; - _responseBody = new FrameResponseStream(this); - ResponseBody = _responseBody; - DuplexStream = new FrameDuplexStream(RequestBody, ResponseBody); - - _abortedCts = null; - _manuallySetRequestAbortToken = null; - - var httpContext = HttpContextFactory.Create(this); - try - { - await Application.Invoke(httpContext).ConfigureAwait(false); - } - catch (Exception ex) - { - ReportApplicationError(ex); - } - finally - { - // Trigger OnStarting if it hasn't been called yet and the app hasn't - // already failed. If an OnStarting callback throws we can go through - // our normal error handling in ProduceEnd. - // https://github.com/aspnet/KestrelHttpServer/issues/43 - if (!_responseStarted && _applicationException == null) - { - await FireOnStarting(); - } - - await FireOnCompleted(); - - HttpContextFactory.Dispose(httpContext); - - // If _requestAbort is set, the connection has already been closed. - if (!_requestAborted) - { - await ProduceEnd(); - - if (_keepAlive) - { - // Finish reading the request body in case the app did not. - await messageBody.Consume(); - } - } - - _requestBody.StopAcceptingReads(); - _responseBody.StopAcceptingWrites(); - } - - terminated = !_keepAlive; - } - - Reset(); - } - } - catch (Exception ex) - { - Log.LogWarning("Connection processing ended abnormally", ex); - } - finally - { - try - { - _abortedCts = null; - - // If _requestAborted is set, the connection has already been closed. - if (!_requestAborted) - { - // Inform client no more data will ever arrive - ConnectionControl.End(ProduceEndType.SocketShutdownSend); - - // Wait for client to either disconnect or send unexpected data - await SocketInput; - - // Dispose socket - ConnectionControl.End(ProduceEndType.SocketDisconnect); - } - } - catch (Exception ex) - { - Log.LogWarning("Connection shutdown abnormally", ex); - } - } - } + public abstract Task RequestProcessingAsync(); public void OnStarting(Func callback, object state) { @@ -444,7 +332,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } - private async Task FireOnStarting() + protected async Task FireOnStarting() { List, object>> onStarting = null; lock (_onStartingSync) @@ -468,7 +356,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } - private async Task FireOnCompleted() + protected async Task FireOnCompleted() { List, object>> onCompleted = null; lock (_onCompletedSync) @@ -633,7 +521,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return CreateResponseHeader(statusBytes, appCompleted, immediate); } - private async Task ProduceEnd() + protected async Task ProduceEnd() { if (_applicationException != null) { @@ -740,7 +628,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } - private bool TakeStartLine(SocketInput input) + protected bool TakeStartLine(SocketInput input) { var scan = input.ConsumingStart(); var consumed = scan; @@ -977,9 +865,16 @@ namespace Microsoft.AspNet.Server.Kestrel.Http statusCode != 304; } - private void ReportApplicationError(Exception ex) + protected void ReportApplicationError(Exception ex) { - _applicationException = ex; + if (_applicationException == null) + { + _applicationException = ex; + } + else + { + _applicationException = new AggregateException(_applicationException, ex); + } Log.ApplicationError(ex); } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameOfT.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameOfT.cs new file mode 100644 index 0000000000..941c75fe8e --- /dev/null +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameOfT.cs @@ -0,0 +1,153 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Net; +using System.Threading.Tasks; +using Microsoft.AspNet.Hosting.Server; +using Microsoft.AspNet.Http.Features; +using Microsoft.Extensions.Logging; + +namespace Microsoft.AspNet.Server.Kestrel.Http +{ + public class Frame : Frame + { + private readonly IHttpApplication _application; + + public Frame(IHttpApplication application, + ConnectionContext context) + : this(application, context, remoteEndPoint: null, localEndPoint: null, prepareRequest: null) + { + } + + public Frame(IHttpApplication application, + ConnectionContext context, + IPEndPoint remoteEndPoint, + IPEndPoint localEndPoint, + Action prepareRequest) + : base(context, remoteEndPoint, localEndPoint, prepareRequest) + { + _application = application; + } + + /// + /// Primary loop which consumes socket input, parses it for protocol framing, and invokes the + /// application delegate for as long as the socket is intended to remain open. + /// The resulting Task from this loop is preserved in a field which is used when the server needs + /// to drain and close all currently active connections. + /// + public override async Task RequestProcessingAsync() + { + try + { + var terminated = false; + while (!terminated && !_requestProcessingStopping) + { + while (!terminated && !_requestProcessingStopping && !TakeStartLine(SocketInput)) + { + terminated = SocketInput.RemoteIntakeFin; + if (!terminated) + { + await SocketInput; + } + } + + while (!terminated && !_requestProcessingStopping && !TakeMessageHeaders(SocketInput, _requestHeaders)) + { + terminated = SocketInput.RemoteIntakeFin; + if (!terminated) + { + await SocketInput; + } + } + + if (!terminated && !_requestProcessingStopping) + { + var messageBody = MessageBody.For(HttpVersion, _requestHeaders, this); + _keepAlive = messageBody.RequestKeepAlive; + _requestBody = new FrameRequestStream(messageBody); + RequestBody = _requestBody; + _responseBody = new FrameResponseStream(this); + ResponseBody = _responseBody; + DuplexStream = new FrameDuplexStream(RequestBody, ResponseBody); + + _abortedCts = null; + _manuallySetRequestAbortToken = null; + + var context = _application.CreateContext(this); + try + { + await _application.ProcessRequestAsync(context).ConfigureAwait(false); + } + catch (Exception ex) + { + ReportApplicationError(ex); + } + finally + { + // Trigger OnStarting if it hasn't been called yet and the app hasn't + // already failed. If an OnStarting callback throws we can go through + // our normal error handling in ProduceEnd. + // https://github.com/aspnet/KestrelHttpServer/issues/43 + if (!_responseStarted && _applicationException == null) + { + await FireOnStarting(); + } + + await FireOnCompleted(); + + _application.DisposeContext(context, _applicationException); + + // If _requestAbort is set, the connection has already been closed. + if (!_requestAborted) + { + await ProduceEnd(); + + if (_keepAlive) + { + // Finish reading the request body in case the app did not. + await messageBody.Consume(); + } + } + + _requestBody.StopAcceptingReads(); + _responseBody.StopAcceptingWrites(); + } + + terminated = !_keepAlive; + } + + Reset(); + } + } + catch (Exception ex) + { + Log.LogWarning("Connection processing ended abnormally", ex); + } + finally + { + try + { + _abortedCts = null; + + // If _requestAborted is set, the connection has already been closed. + if (!_requestAborted) + { + // Inform client no more data will ever arrive + ConnectionControl.End(ProduceEndType.SocketShutdownSend); + + // Wait for client to either disconnect or send unexpected data + await SocketInput; + + // Dispose socket + ConnectionControl.End(ProduceEndType.SocketDisconnect); + } + } + catch (Exception ex) + { + Log.LogWarning("Connection shutdown abnormally", ex); + } + } + } + } +} diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs index d1a80b7043..6721756266 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs @@ -23,12 +23,10 @@ namespace Microsoft.AspNet.Server.Kestrel.Http public Task StartAsync( ServerAddress address, - KestrelThread thread, - RequestDelegate application) + KestrelThread thread) { ServerAddress = address; Thread = thread; - Application = application; var tcs = new TaskCompletionSource(this); diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerContext.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerContext.cs index 5817200410..fecd0afa44 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerContext.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerContext.cs @@ -24,7 +24,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { ServerAddress = listenerContext.ServerAddress; Thread = listenerContext.Thread; - Application = listenerContext.Application; Memory2 = listenerContext.Memory2; Log = listenerContext.Log; } @@ -33,8 +32,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Http public KestrelThread Thread { get; set; } - public RequestDelegate Application { get; set; } - public MemoryPool2 Memory2 { get; set; } } } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerPrimary.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerPrimary.cs index c5b6321d4a..d3c344ccec 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerPrimary.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerPrimary.cs @@ -4,7 +4,6 @@ using System; using System.Collections.Generic; using System.Threading.Tasks; -using Microsoft.AspNet.Http; using Microsoft.AspNet.Server.Kestrel.Infrastructure; using Microsoft.AspNet.Server.Kestrel.Networking; using Microsoft.Extensions.Logging; @@ -34,12 +33,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http public async Task StartAsync( string pipeName, ServerAddress address, - KestrelThread thread, - RequestDelegate application) + KestrelThread thread) { _pipeName = pipeName; - await StartAsync(address, thread, application).ConfigureAwait(false); + await StartAsync(address, thread).ConfigureAwait(false); await Thread.PostAsync(_this => _this.PostCallback(), this).ConfigureAwait(false); diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerSecondary.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerSecondary.cs index 0bc8fae781..1c6ca4aea8 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerSecondary.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerSecondary.cs @@ -32,15 +32,13 @@ namespace Microsoft.AspNet.Server.Kestrel.Http public Task StartAsync( string pipeName, ServerAddress address, - KestrelThread thread, - RequestDelegate application) + KestrelThread thread) { _pipeName = pipeName; _buf = thread.Loop.Libuv.buf_init(_ptr, 4); ServerAddress = address; Thread = thread; - Application = application; DispatchPipe = new UvPipeHandle(Log); diff --git a/src/Microsoft.AspNet.Server.Kestrel/KestrelEngine.cs b/src/Microsoft.AspNet.Server.Kestrel/KestrelEngine.cs index b0150cad1d..d64f4316e9 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/KestrelEngine.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/KestrelEngine.cs @@ -48,7 +48,7 @@ namespace Microsoft.AspNet.Server.Kestrel Threads.Clear(); } - public IDisposable CreateServer(ServerAddress address, RequestDelegate application) + public IDisposable CreateServer(ServerAddress address) { var listeners = new List(); @@ -69,7 +69,7 @@ namespace Microsoft.AspNet.Server.Kestrel (Listener) new PipeListener(this) : new TcpListener(this); listeners.Add(listener); - listener.StartAsync(address, thread, application).Wait(); + listener.StartAsync(address, thread).Wait(); } else if (first) { @@ -78,7 +78,7 @@ namespace Microsoft.AspNet.Server.Kestrel : new TcpListenerPrimary(this); listeners.Add(listener); - listener.StartAsync(pipeName, address, thread, application).Wait(); + listener.StartAsync(pipeName, address, thread).Wait(); } else { @@ -86,7 +86,7 @@ namespace Microsoft.AspNet.Server.Kestrel ? (ListenerSecondary) new PipeListenerSecondary(this) : new TcpListenerSecondary(this); listeners.Add(listener); - listener.StartAsync(pipeName, address, thread, application).Wait(); + listener.StartAsync(pipeName, address, thread).Wait(); } first = false; diff --git a/src/Microsoft.AspNet.Server.Kestrel/KestrelServer.cs b/src/Microsoft.AspNet.Server.Kestrel/KestrelServer.cs index 346808ebc4..f1e3504d22 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/KestrelServer.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/KestrelServer.cs @@ -5,7 +5,6 @@ using System; using System.Collections.Generic; using Microsoft.AspNet.Hosting; using Microsoft.AspNet.Hosting.Server; -using Microsoft.AspNet.Http; using Microsoft.AspNet.Http.Features; using Microsoft.AspNet.Server.Kestrel.Http; using Microsoft.Extensions.Logging; @@ -17,9 +16,8 @@ namespace Microsoft.AspNet.Server.Kestrel private Stack _disposables; private readonly IApplicationLifetime _applicationLifetime; private readonly ILogger _logger; - private readonly IHttpContextFactory _httpContextFactory; - public KestrelServer(IFeatureCollection features, IApplicationLifetime applicationLifetime, ILogger logger, IHttpContextFactory httpContextFactory) + public KestrelServer(IFeatureCollection features, IApplicationLifetime applicationLifetime, ILogger logger) { if (features == null) { @@ -36,20 +34,14 @@ namespace Microsoft.AspNet.Server.Kestrel throw new ArgumentNullException(nameof(logger)); } - if (httpContextFactory == null) - { - throw new ArgumentNullException(nameof(httpContextFactory)); - } - _applicationLifetime = applicationLifetime; _logger = logger; Features = features; - _httpContextFactory = httpContextFactory; } public IFeatureCollection Features { get; } - public void Start(RequestDelegate requestDelegate) + public void Start(IHttpApplication application) { if (_disposables != null) { @@ -64,9 +56,12 @@ namespace Microsoft.AspNet.Server.Kestrel var dateHeaderValueManager = new DateHeaderValueManager(); var engine = new KestrelEngine(new ServiceContext { + FrameFactory = (context, remoteEP, localEP, prepareRequest) => + { + return new Frame(application, context, remoteEP, localEP, prepareRequest); + }, AppLifetime = _applicationLifetime, Log = new KestrelTrace(_logger), - HttpContextFactory = _httpContextFactory, DateHeaderValueManager = dateHeaderValueManager, ConnectionFilter = information.ConnectionFilter, NoDelay = information.NoDelay @@ -119,8 +114,7 @@ namespace Microsoft.AspNet.Server.Kestrel { atLeastOneListener = true; _disposables.Push(engine.CreateServer( - parsedAddress, - requestDelegate)); + parsedAddress)); } } diff --git a/src/Microsoft.AspNet.Server.Kestrel/ServerFactory.cs b/src/Microsoft.AspNet.Server.Kestrel/ServerFactory.cs index 158e089fee..ccde5797ce 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/ServerFactory.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/ServerFactory.cs @@ -3,7 +3,6 @@ using Microsoft.AspNet.Hosting; using Microsoft.AspNet.Hosting.Server; -using Microsoft.AspNet.Http; using Microsoft.AspNet.Http.Features; using Microsoft.AspNet.Server.Features; using Microsoft.Extensions.Configuration; @@ -18,13 +17,11 @@ namespace Microsoft.AspNet.Server.Kestrel { private readonly IApplicationLifetime _appLifetime; private readonly ILoggerFactory _loggerFactory; - private readonly IHttpContextFactory _httpContextFactory; - public ServerFactory(IApplicationLifetime appLifetime, ILoggerFactory loggerFactory, IHttpContextFactory httpContextFactory) + public ServerFactory(IApplicationLifetime appLifetime, ILoggerFactory loggerFactory) { _appLifetime = appLifetime; _loggerFactory = loggerFactory; - _httpContextFactory = httpContextFactory; } public IServer CreateServer(IConfiguration configuration) @@ -34,7 +31,7 @@ namespace Microsoft.AspNet.Server.Kestrel var serverFeatures = new FeatureCollection(); serverFeatures.Set(information); serverFeatures.Set(information); - return new KestrelServer(serverFeatures, _appLifetime, _loggerFactory.CreateLogger("Microsoft.AspNet.Server.Kestrel"), _httpContextFactory); + return new KestrelServer(serverFeatures, _appLifetime, _loggerFactory.CreateLogger("Microsoft.AspNet.Server.Kestrel")); } } } diff --git a/src/Microsoft.AspNet.Server.Kestrel/ServiceContext.cs b/src/Microsoft.AspNet.Server.Kestrel/ServiceContext.cs index 095f37f856..62d5d5d758 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/ServiceContext.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/ServiceContext.cs @@ -1,8 +1,10 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; +using System.Net; using Microsoft.AspNet.Hosting; -using Microsoft.AspNet.Http; +using Microsoft.AspNet.Http.Features; using Microsoft.AspNet.Server.Kestrel.Filter; using Microsoft.AspNet.Server.Kestrel.Http; using Microsoft.AspNet.Server.Kestrel.Infrastructure; @@ -19,7 +21,7 @@ namespace Microsoft.AspNet.Server.Kestrel { AppLifetime = context.AppLifetime; Log = context.Log; - HttpContextFactory = context.HttpContextFactory; + FrameFactory = context.FrameFactory; DateHeaderValueManager = context.DateHeaderValueManager; ConnectionFilter = context.ConnectionFilter; NoDelay = context.NoDelay; @@ -29,7 +31,7 @@ namespace Microsoft.AspNet.Server.Kestrel public IKestrelTrace Log { get; set; } - public IHttpContextFactory HttpContextFactory { get; set; } + public Func, Frame> FrameFactory { get; set; } public DateHeaderValueManager DateHeaderValueManager { get; set; } diff --git a/test/Microsoft.AspNet.Server.KestrelTests/DummyApplication.cs b/test/Microsoft.AspNet.Server.KestrelTests/DummyApplication.cs new file mode 100644 index 0000000000..540b9d2f47 --- /dev/null +++ b/test/Microsoft.AspNet.Server.KestrelTests/DummyApplication.cs @@ -0,0 +1,37 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Threading.Tasks; +using Microsoft.AspNet.Hosting.Server; +using Microsoft.AspNet.Http; +using Microsoft.AspNet.Http.Internal; +using Microsoft.AspNet.Http.Features; + +namespace Microsoft.AspNet.Server.KestrelTests +{ + public class DummyApplication : IHttpApplication + { + private readonly RequestDelegate _requestDelegate; + + public DummyApplication(RequestDelegate requestDelegate) + { + _requestDelegate = requestDelegate; + } + + public HttpContext CreateContext(IFeatureCollection contextFeatures) + { + return new DefaultHttpContext(contextFeatures); + } + + public void DisposeContext(HttpContext context, Exception exception) + { + + } + + public async Task ProcessRequestAsync(HttpContext context) + { + await _requestDelegate(context); + } + } +} diff --git a/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs index afc30af8a9..b0a8c10b51 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs @@ -12,6 +12,7 @@ using Microsoft.AspNet.Http; using Microsoft.AspNet.Http.Features; using Microsoft.AspNet.Server.Kestrel; using Microsoft.AspNet.Server.Kestrel.Filter; +using Microsoft.AspNet.Server.Kestrel.Http; using Microsoft.AspNet.Testing.xunit; using Microsoft.Extensions.Logging; using Xunit; @@ -91,12 +92,13 @@ namespace Microsoft.AspNet.Server.KestrelTests [ConditionalTheory] [MemberData(nameof(ConnectionFilterData))] [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Test hangs after execution on Mono.")] - public void ListenerCanCreateAndDispose(ServiceContext testContext) + public void ListenerCanCreateAndDispose(TestServiceContext testContext) { + testContext.App = App; var engine = new KestrelEngine(testContext); engine.Start(1); var address = ServerAddress.FromUrl("http://localhost:54321/"); - var started = engine.CreateServer(address, App); + var started = engine.CreateServer(address); started.Dispose(); engine.Dispose(); } @@ -104,12 +106,13 @@ namespace Microsoft.AspNet.Server.KestrelTests [ConditionalTheory] [MemberData(nameof(ConnectionFilterData))] [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Test hangs after execution on Mono.")] - public void ConnectionCanReadAndWrite(ServiceContext testContext) + public void ConnectionCanReadAndWrite(TestServiceContext testContext) { + testContext.App = App; var engine = new KestrelEngine(testContext); engine.Start(1); var address = ServerAddress.FromUrl("http://localhost:54321/"); - var started = engine.CreateServer(address, App); + var started = engine.CreateServer(address); Console.WriteLine("Started"); var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); diff --git a/test/Microsoft.AspNet.Server.KestrelTests/FrameFacts.cs b/test/Microsoft.AspNet.Server.KestrelTests/FrameFacts.cs index 9e3419797f..da1bc9058e 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/FrameFacts.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/FrameFacts.cs @@ -19,7 +19,7 @@ namespace Microsoft.AspNet.Server.KestrelTests DateHeaderValueManager = new DateHeaderValueManager(), ServerAddress = ServerAddress.FromUrl("http://localhost:5000") }; - var frame = new Frame(connectionContext); + var frame = new Frame(application: null, context: connectionContext); frame.Scheme = "https"; // Act diff --git a/test/Microsoft.AspNet.Server.KestrelTests/FrameResponseHeadersTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/FrameResponseHeadersTests.cs index 8082e62ed7..1526c53b26 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/FrameResponseHeadersTests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/FrameResponseHeadersTests.cs @@ -20,7 +20,7 @@ namespace Microsoft.AspNet.Server.KestrelTests DateHeaderValueManager = new DateHeaderValueManager(), ServerAddress = ServerAddress.FromUrl("http://localhost:5000") }; - var frame = new Frame(connectionContext); + var frame = new Frame(application: null, context: connectionContext); IDictionary headers = frame.ResponseHeaders; Assert.Equal(2, headers.Count); @@ -48,7 +48,7 @@ namespace Microsoft.AspNet.Server.KestrelTests DateHeaderValueManager = new DateHeaderValueManager(), ServerAddress = ServerAddress.FromUrl("http://localhost:5000") }; - var frame = new Frame(connectionContext); + var frame = new Frame(application: null, context: connectionContext); Assert.True(frame.ResponseHeaders.Count > 0); diff --git a/test/Microsoft.AspNet.Server.KestrelTests/TestServer.cs b/test/Microsoft.AspNet.Server.KestrelTests/TestServer.cs index 70f9fd1cb7..42efcb3793 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/TestServer.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/TestServer.cs @@ -4,6 +4,7 @@ using System; using Microsoft.AspNet.Http; using Microsoft.AspNet.Server.Kestrel; +using Microsoft.AspNet.Server.Kestrel.Http; namespace Microsoft.AspNet.Server.KestrelTests { @@ -32,11 +33,14 @@ namespace Microsoft.AspNet.Server.KestrelTests public void Create(RequestDelegate app, ServiceContext context, string serverAddress) { + context.FrameFactory = (connectionContext, remoteEP, localEP, prepareRequest) => + { + return new Frame(new DummyApplication(app), connectionContext, remoteEP, localEP, prepareRequest); + }; _engine = new KestrelEngine(context); _engine.Start(1); _server = _engine.CreateServer( - ServerAddress.FromUrl(serverAddress), - app); + ServerAddress.FromUrl(serverAddress)); } public void Dispose() diff --git a/test/Microsoft.AspNet.Server.KestrelTests/TestServiceContext.cs b/test/Microsoft.AspNet.Server.KestrelTests/TestServiceContext.cs index 3badc340b7..9686915699 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/TestServiceContext.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/TestServiceContext.cs @@ -1,19 +1,37 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using Microsoft.AspNet.Http.Internal; +using Microsoft.AspNet.Http; using Microsoft.AspNet.Server.Kestrel; +using Microsoft.AspNet.Server.Kestrel.Http; namespace Microsoft.AspNet.Server.KestrelTests { public class TestServiceContext : ServiceContext { + private RequestDelegate _app; + public TestServiceContext() { AppLifetime = new LifetimeNotImplemented(); Log = new TestKestrelTrace(); - HttpContextFactory = new HttpContextFactory(new HttpContextAccessor()); DateHeaderValueManager = new TestDateHeaderValueManager(); } + + public RequestDelegate App + { + get + { + return _app; + } + set + { + _app = value; + FrameFactory = (connectionContext, remoteEP, localEP, prepareRequest) => + { + return new Frame(new DummyApplication(_app), connectionContext, remoteEP, localEP, prepareRequest); + }; + } + } } } From 32a038e5ea90a3c54980436a7f5246382f422353 Mon Sep 17 00:00:00 2001 From: John Luo Date: Tue, 1 Dec 2015 15:24:36 -0800 Subject: [PATCH 0477/1662] Reacting to the removal of ILoggerFactory.MinimumLevel --- samples/SampleApp/Startup.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/samples/SampleApp/Startup.cs b/samples/SampleApp/Startup.cs index a405f0be87..72bc9e5a9c 100644 --- a/samples/SampleApp/Startup.cs +++ b/samples/SampleApp/Startup.cs @@ -22,8 +22,6 @@ namespace SampleApp //ksi.ThreadCount = 4; ksi.NoDelay = true; - loggerFactory.MinimumLevel = LogLevel.Debug; - loggerFactory.AddConsole(LogLevel.Debug); var testCertPath = Path.Combine( From b7c60de98aefe47e5d78c69d3471423b1f835b33 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Wed, 2 Dec 2015 15:01:38 +0000 Subject: [PATCH 0478/1662] Don't allocate request processing delegate --- src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs index 98dee5304c..befc6ba294 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs @@ -254,7 +254,13 @@ namespace Microsoft.AspNet.Server.Kestrel.Http if (!_requestProcessingStarted) { _requestProcessingStarted = true; - _requestProcessingTask = Task.Run(RequestProcessingAsync); + _requestProcessingTask = + Task.Factory.StartNew( + (o) => ((Frame)o).RequestProcessingAsync(), + this, + CancellationToken.None, + TaskCreationOptions.DenyChildAttach, + TaskScheduler.Default); } } From a55be214693c1ceaccd9e3c327f53b9a62a52297 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Tue, 1 Dec 2015 04:36:23 +0000 Subject: [PATCH 0479/1662] Empty buffer when null buffer --- .../Filter/StreamSocketOutput.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Filter/StreamSocketOutput.cs b/src/Microsoft.AspNet.Server.Kestrel/Filter/StreamSocketOutput.cs index e990e34ee8..d2c1deae3b 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Filter/StreamSocketOutput.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Filter/StreamSocketOutput.cs @@ -12,6 +12,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Filter { public class StreamSocketOutput : ISocketOutput { + private static readonly byte[] _nullBuffer = new byte[0]; + private readonly Stream _outputStream; private readonly MemoryPool2 _memory; private MemoryPoolBlock2 _producingBlock; @@ -24,13 +26,13 @@ namespace Microsoft.AspNet.Server.Kestrel.Filter void ISocketOutput.Write(ArraySegment buffer, bool immediate) { - _outputStream.Write(buffer.Array, buffer.Offset, buffer.Count); + _outputStream.Write(buffer.Array ?? _nullBuffer, buffer.Offset, buffer.Count); } Task ISocketOutput.WriteAsync(ArraySegment buffer, bool immediate, CancellationToken cancellationToken) { // TODO: Use _outputStream.WriteAsync - _outputStream.Write(buffer.Array, buffer.Offset, buffer.Count); + _outputStream.Write(buffer.Array ?? _nullBuffer, buffer.Offset, buffer.Count); return TaskUtilities.CompletedTask; } From a85f37697c1b689fda9f4484b014338af18d9898 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Wed, 2 Dec 2015 21:01:08 +0000 Subject: [PATCH 0480/1662] Add SSL+Upgrade regression test --- .../StreamSocketOutputTests.cs | 106 ++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 test/Microsoft.AspNet.Server.KestrelTests/StreamSocketOutputTests.cs diff --git a/test/Microsoft.AspNet.Server.KestrelTests/StreamSocketOutputTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/StreamSocketOutputTests.cs new file mode 100644 index 0000000000..7b19bf6173 --- /dev/null +++ b/test/Microsoft.AspNet.Server.KestrelTests/StreamSocketOutputTests.cs @@ -0,0 +1,106 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.IO; +using Microsoft.AspNet.Server.Kestrel.Filter; +using Microsoft.AspNet.Server.Kestrel.Http; +using Xunit; + +namespace Microsoft.AspNet.Server.KestrelTests +{ + public class StreamSocketOutputTests + { + [Fact] + public void DoesNotThrowForNullBuffers() + { + // This test was added because SslStream throws if passed null buffers with (count == 0) + // Which happens if ProduceEnd is called in Frame without _responseStarted == true + // As it calls ProduceStart with write immediate == true + // This happens in WebSocket Upgrade over SSL + + ISocketOutput socketOutput = new StreamSocketOutput(new ThrowsOnNullWriteStream(), null); + + // Should not throw + socketOutput.Write(default(ArraySegment), true); + + Assert.True(true); + } + + private class ThrowsOnNullWriteStream : Stream + { + public override bool CanRead + { + get + { + throw new NotImplementedException(); + } + } + + public override bool CanSeek + { + get + { + throw new NotImplementedException(); + } + } + + public override bool CanWrite + { + get + { + throw new NotImplementedException(); + } + } + + public override long Length + { + get + { + throw new NotImplementedException(); + } + } + + public override long Position + { + get + { + throw new NotImplementedException(); + } + + set + { + throw new NotImplementedException(); + } + } + + public override void Flush() + { + throw new NotImplementedException(); + } + + public override int Read(byte[] buffer, int offset, int count) + { + throw new NotImplementedException(); + } + + public override long Seek(long offset, SeekOrigin origin) + { + throw new NotImplementedException(); + } + + public override void SetLength(long value) + { + throw new NotImplementedException(); + } + + public override void Write(byte[] buffer, int offset, int count) + { + if (buffer == null) + { + throw new ArgumentNullException(nameof(buffer)); + } + } + } + } +} From b84d8dbd07f1bb76ac1d65b79ebc983b7443d1ba Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Wed, 2 Dec 2015 16:49:31 -0800 Subject: [PATCH 0481/1662] Minor style changes to tenor/speed-up-date - Removed some code required to support sub-second timer intervals --- .../Http/DateHeaderValueManager.cs | 39 ++----------------- 1 file changed, 3 insertions(+), 36 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/DateHeaderValueManager.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/DateHeaderValueManager.cs index e8a5d914f5..4a3cff6eb4 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/DateHeaderValueManager.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/DateHeaderValueManager.cs @@ -26,8 +26,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Http private volatile bool _hadRequestsSinceLastTimerTick = false; private Timer _dateValueTimer; private long _lastRequestSeenTicks; - private long _lastReadDateTimeTicks; - private readonly bool _is64BitSystem; private volatile bool _timerIsRunning; /// @@ -51,7 +49,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Http _timeWithoutRequestsUntilIdle = timeWithoutRequestsUntilIdle; _timerInterval = timerInterval; _dateValueTimer = new Timer(TimerLoop, state: null, dueTime: Timeout.Infinite, period: Timeout.Infinite); - _is64BitSystem = IntPtr.Size >= 8; } /// @@ -73,7 +70,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return _activeDateBytes ? _dateBytes0 : _dateBytes1; } - /// /// Releases all resources used by the current instance of . /// @@ -95,7 +91,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } - /// /// Starts the timer /// @@ -103,7 +98,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { var now = _systemClock.UtcNow; SetDateValues(now); - WriteLongThreadSafe(ref _lastReadDateTimeTicks, now.Ticks); if (!_isDisposed) { @@ -140,26 +134,19 @@ namespace Microsoft.AspNet.Server.Kestrel.Http private void TimerLoop(object state) { var now = _systemClock.UtcNow; - var lastReadDateTime = new DateTimeOffset(ReadLongThreadSafe(ref _lastReadDateTimeTicks), TimeSpan.Zero); - //Are we in a new second? - if (now - lastReadDateTime >= TimeSpan.FromSeconds(1) || now.Second != lastReadDateTime.Second) - { - //Yep, Update DateValues - SetDateValues(now); - WriteLongThreadSafe(ref _lastReadDateTimeTicks, now.Ticks); - } + SetDateValues(now); if (_hadRequestsSinceLastTimerTick) { // We served requests since the last tick, reset the flag and return as we're still active _hadRequestsSinceLastTimerTick = false; - WriteLongThreadSafe(ref _lastRequestSeenTicks, now.Ticks); + Interlocked.Exchange(ref _lastRequestSeenTicks, now.Ticks); return; } // No requests since the last timer tick, we need to check if we're beyond the idle threshold - if ((now.Ticks - ReadLongThreadSafe(ref _lastRequestSeenTicks)) >= _timeWithoutRequestsUntilIdle.Ticks) + if ((now.Ticks - Interlocked.Read(ref _lastRequestSeenTicks)) >= _timeWithoutRequestsUntilIdle.Ticks) { // No requests since idle threshold so stop the timer if it's still running StopTimer(); @@ -184,7 +171,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } - /// /// Sets date values from a provided ticks value /// @@ -196,24 +182,5 @@ namespace Microsoft.AspNet.Server.Kestrel.Http Encoding.ASCII.GetBytes(_dateValue, 0, _dateValue.Length, !_activeDateBytes ? _dateBytes0 : _dateBytes1, "\r\nDate: ".Length); _activeDateBytes = !_activeDateBytes; } - - private void WriteLongThreadSafe(ref long location, long value) - { - Interlocked.Exchange(ref location, value); - } - - private long ReadLongThreadSafe(ref long location) - { - if (_is64BitSystem) - { - return location; - } - else - { - return Interlocked.Read(ref location); - } - } - } } - From 5ae9b3c383d9d4294b476f282ad9ab59aae9ff26 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Mon, 23 Nov 2015 19:36:51 +0000 Subject: [PATCH 0482/1662] Log user code threadpool continuation execptions --- .../Filter/FilteredStreamAdapter.cs | 5 +- .../Http/Connection.cs | 6 +- .../Http/SocketInput.cs | 10 ++- .../Http/SocketOutput.cs | 18 ++--- .../Infrastructure/KestrelThread.cs | 20 ++--- .../Infrastructure/ThreadPoolActions.cs | 74 +++++++++++++++++++ .../ServiceContext.cs | 20 ++++- .../FrameTests.cs | 5 +- .../SocketOutputTests.cs | 15 ++-- .../TestInput.cs | 5 +- 10 files changed, 136 insertions(+), 42 deletions(-) create mode 100644 src/Microsoft.AspNet.Server.Kestrel/Infrastructure/ThreadPoolActions.cs diff --git a/src/Microsoft.AspNet.Server.Kestrel/Filter/FilteredStreamAdapter.cs b/src/Microsoft.AspNet.Server.Kestrel/Filter/FilteredStreamAdapter.cs index e3d2eb5603..3266d88d64 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Filter/FilteredStreamAdapter.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Filter/FilteredStreamAdapter.cs @@ -19,9 +19,10 @@ namespace Microsoft.AspNet.Server.Kestrel.Filter public FilteredStreamAdapter( Stream filteredStream, MemoryPool2 memory, - IKestrelTrace logger) + IKestrelTrace logger, + ThreadPoolActions threadPoolActions) { - SocketInput = new SocketInput(memory); + SocketInput = new SocketInput(memory, threadPoolActions); SocketOutput = new StreamSocketOutput(filteredStream, memory); _log = logger; diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs index c02e295dd3..dd7236f523 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs @@ -41,8 +41,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http _connectionId = Interlocked.Increment(ref _lastConnectionId); - _rawSocketInput = new SocketInput(Memory2); - _rawSocketOutput = new SocketOutput(Thread, _socket, Memory2, this, _connectionId, Log); + _rawSocketInput = new SocketInput(Memory2, ThreadPoolActions); + _rawSocketOutput = new SocketOutput(Thread, _socket, Memory2, this, _connectionId, Log, ThreadPoolActions); } public void Start() @@ -124,7 +124,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http private void ApplyConnectionFilter() { - var filteredStreamAdapter = new FilteredStreamAdapter(_filterContext.Connection, Memory2, Log); + var filteredStreamAdapter = new FilteredStreamAdapter(_filterContext.Connection, Memory2, Log, ThreadPoolActions); SocketInput = filteredStreamAdapter.SocketInput; SocketOutput = filteredStreamAdapter.SocketOutput; diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketInput.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketInput.cs index b13d678130..a85634331d 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketInput.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketInput.cs @@ -16,6 +16,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http private static readonly Action _awaitableIsNotCompleted = () => { }; private readonly MemoryPool2 _memory; + private readonly ThreadPoolActions _threadPoolActions; private readonly ManualResetEventSlim _manualResetEvent = new ManualResetEventSlim(false); private Action _awaitableState; @@ -26,9 +27,10 @@ namespace Microsoft.AspNet.Server.Kestrel.Http private MemoryPoolBlock2 _pinned; private readonly object _sync = new Object(); - public SocketInput(MemoryPool2 memory) + public SocketInput(MemoryPool2 memory, ThreadPoolActions threadPoolActions) { _memory = memory; + _threadPoolActions = threadPoolActions; _awaitableState = _awaitableIsNotCompleted; } @@ -128,7 +130,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http if (awaitableState != _awaitableIsCompleted && awaitableState != _awaitableIsNotCompleted) { - ThreadPool.QueueUserWorkItem((o) => ((Action)o)(), awaitableState); + _threadPoolActions.Run(awaitableState); } } @@ -188,7 +190,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http if (awaitableState != _awaitableIsCompleted && awaitableState != _awaitableIsNotCompleted) { - Task.Run(awaitableState); + _threadPoolActions.Run(awaitableState); } } @@ -210,7 +212,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } else if (awaitableState == _awaitableIsCompleted) { - ThreadPool.QueueUserWorkItem((o) => ((Action)o)(), continuation); + _threadPoolActions.Run(continuation); } else { diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs index 911a5a9675..ef6b5e4f1f 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs @@ -25,6 +25,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http private readonly Connection _connection; private readonly long _connectionId; private readonly IKestrelTrace _log; + private readonly ThreadPoolActions _threadPoolActions; // This locks all access to _tail, _isProducing and _returnFromOnProducingComplete. // _head does not require a lock, since it is only used in the ctor and uv thread. @@ -55,13 +56,15 @@ namespace Microsoft.AspNet.Server.Kestrel.Http MemoryPool2 memory, Connection connection, long connectionId, - IKestrelTrace log) + IKestrelTrace log, + ThreadPoolActions threadPoolActions) { _thread = thread; _socket = socket; _connection = connection; _connectionId = connectionId; _log = log; + _threadPoolActions = threadPoolActions; _tasksPending = new Queue>(_initialTaskQueues); _tasksCompleted = new Queue>(_initialTaskQueues); @@ -218,7 +221,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http private static void ReturnBlocks(MemoryPoolBlock2 block) { - while(block != null) + while (block != null) { var returningBlock = block; block = returningBlock.Next; @@ -319,16 +322,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http var tcs = _tasksCompleted.Dequeue(); if (_lastWriteError == null) { - ThreadPool.QueueUserWorkItem( - (o) => ((TaskCompletionSource)o).SetResult(null), - tcs); + _threadPoolActions.Complete(tcs); } else { - // error is closure captured - ThreadPool.QueueUserWorkItem( - (o) => ((TaskCompletionSource)o).SetException(_lastWriteError), - tcs); + _threadPoolActions.Error(tcs, _lastWriteError); } } @@ -462,7 +460,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http var _this = (WriteContext)state; _this.ShutdownSendStatus = status; - _this.Self._log.ConnectionWroteFin(Self._connectionId, status); + _this.Self._log.ConnectionWroteFin(_this.Self._connectionId, status); _this.DoDisconnectIfNeeded(); }, this); diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs index 93c30a55dd..98c9ef3f4f 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs @@ -33,12 +33,14 @@ namespace Microsoft.AspNet.Server.Kestrel private bool _initCompleted = false; private ExceptionDispatchInfo _closeError; private IKestrelTrace _log; + private ThreadPoolActions _threadPoolActions; public KestrelThread(KestrelEngine engine) { _engine = engine; _appLifetime = engine.AppLifetime; _log = engine.Log; + _threadPoolActions = engine.ThreadPoolActions; _loop = new UvLoopHandle(_log); _post = new UvAsyncHandle(_log); _thread = new Thread(ThreadStart); @@ -151,7 +153,7 @@ namespace Microsoft.AspNet.Server.Kestrel public Task PostAsync(Action callback, T state) { - var tcs = new TaskCompletionSource(); + var tcs = new TaskCompletionSource(); lock (_workSync) { _workAdding.Enqueue(new Work @@ -266,24 +268,14 @@ namespace Microsoft.AspNet.Server.Kestrel work.CallbackAdapter(work.Callback, work.State); if (work.Completion != null) { - ThreadPool.QueueUserWorkItem( - tcs => - { - ((TaskCompletionSource)tcs).SetResult(0); - }, - work.Completion); + _threadPoolActions.Complete(work.Completion); } } catch (Exception ex) { if (work.Completion != null) { - ThreadPool.QueueUserWorkItem( - tcs => - { - ((TaskCompletionSource)tcs).SetException(ex); - }, - work.Completion); + _threadPoolActions.Error(work.Completion, ex); } else { @@ -322,7 +314,7 @@ namespace Microsoft.AspNet.Server.Kestrel public Action CallbackAdapter; public object Callback; public object State; - public TaskCompletionSource Completion; + public TaskCompletionSource Completion; } private struct CloseHandle { diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/ThreadPoolActions.cs b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/ThreadPoolActions.cs new file mode 100644 index 0000000000..cbcba6c239 --- /dev/null +++ b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/ThreadPoolActions.cs @@ -0,0 +1,74 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Threading; +using System.Threading.Tasks; +using Microsoft.AspNet.Server.Kestrel.Http; + +namespace Microsoft.AspNet.Server.Kestrel.Infrastructure +{ + public class ThreadPoolActions + { + private readonly IKestrelTrace _log; + + private readonly WaitCallback _runAction; + private readonly WaitCallback _completeTcs; + + public ThreadPoolActions(IKestrelTrace log) + { + _log = log; + + // Curry and capture log in closures once + _runAction = (o) => + { + try + { + ((Action)o)(); + } + catch (Exception e) + { + _log.ApplicationError(e); + } + }; + + _completeTcs = (o) => + { + try + { + ((TaskCompletionSource)o).TrySetResult(null); + } + catch (Exception e) + { + _log.ApplicationError(e); + } + }; + } + + public void Run(Action action) + { + ThreadPool.QueueUserWorkItem(_runAction, action); + } + + public void Complete(TaskCompletionSource tcs) + { + ThreadPool.QueueUserWorkItem(_completeTcs, tcs); + } + + public void Error(TaskCompletionSource tcs, Exception ex) + { + // ex ang _log are closure captured + ThreadPool.QueueUserWorkItem((o) => + { + try + { + ((TaskCompletionSource)o).TrySetException(ex); + } + catch (Exception e) + { + _log.ApplicationError(e); + } + }, tcs); + } + } +} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Server.Kestrel/ServiceContext.cs b/src/Microsoft.AspNet.Server.Kestrel/ServiceContext.cs index 62d5d5d758..3be228d5a3 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/ServiceContext.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/ServiceContext.cs @@ -13,6 +13,8 @@ namespace Microsoft.AspNet.Server.Kestrel { public class ServiceContext { + private IKestrelTrace _log; + public ServiceContext() { } @@ -20,7 +22,8 @@ namespace Microsoft.AspNet.Server.Kestrel public ServiceContext(ServiceContext context) { AppLifetime = context.AppLifetime; - Log = context.Log; + _log = context.Log; + ThreadPoolActions = context.ThreadPoolActions; FrameFactory = context.FrameFactory; DateHeaderValueManager = context.DateHeaderValueManager; ConnectionFilter = context.ConnectionFilter; @@ -29,7 +32,20 @@ namespace Microsoft.AspNet.Server.Kestrel public IApplicationLifetime AppLifetime { get; set; } - public IKestrelTrace Log { get; set; } + public IKestrelTrace Log + { + get + { + return _log; + } + set + { + _log = value; + ThreadPoolActions = new ThreadPoolActions(_log); + } + } + + public ThreadPoolActions ThreadPoolActions { get; private set; } public Func, Frame> FrameFactory { get; set; } diff --git a/test/Microsoft.AspNet.Server.KestrelTests/FrameTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/FrameTests.cs index 8266a1c2e9..b6267e384c 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/FrameTests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/FrameTests.cs @@ -4,6 +4,7 @@ using System; using System.Linq; using System.Text; +using Microsoft.AspNet.Server.Kestrel; using Microsoft.AspNet.Server.Kestrel.Http; using Microsoft.AspNet.Server.Kestrel.Infrastructure; using Xunit; @@ -48,7 +49,9 @@ namespace Microsoft.AspNet.Server.KestrelTests [InlineData("Connection:\r\n \r\nCookie \r\n", 1)] public void EmptyHeaderValuesCanBeParsed(string rawHeaders, int numHeaders) { - var socketInput = new SocketInput(new MemoryPool2()); + var trace = new KestrelTrace(new TestKestrelTrace()); + var tpa = new ThreadPoolActions(trace); + var socketInput = new SocketInput(new MemoryPool2(), tpa); var headerCollection = new FrameRequestHeaders(); var headerArray = Encoding.ASCII.GetBytes(rawHeaders); diff --git a/test/Microsoft.AspNet.Server.KestrelTests/SocketOutputTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/SocketOutputTests.cs index 629c35407c..4028cfff1d 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/SocketOutputTests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/SocketOutputTests.cs @@ -41,7 +41,8 @@ namespace Microsoft.AspNet.Server.KestrelTests var kestrelThread = kestrelEngine.Threads[0]; var socket = new MockSocket(kestrelThread.Loop.ThreadId, new TestKestrelTrace()); var trace = new KestrelTrace(new TestKestrelTrace()); - var socketOutput = new SocketOutput(kestrelThread, socket, memory, null, 0, trace); + var tpa = new ThreadPoolActions(trace); + var socketOutput = new SocketOutput(kestrelThread, socket, memory, null, 0, trace, tpa); // I doubt _maxBytesPreCompleted will ever be over a MB. If it is, we should change this test. var bufferSize = 1048576; @@ -87,7 +88,8 @@ namespace Microsoft.AspNet.Server.KestrelTests var kestrelThread = kestrelEngine.Threads[0]; var socket = new MockSocket(kestrelThread.Loop.ThreadId, new TestKestrelTrace()); var trace = new KestrelTrace(new TestKestrelTrace()); - var socketOutput = new SocketOutput(kestrelThread, socket, memory, null, 0, trace); + var tpa = new ThreadPoolActions(trace); + var socketOutput = new SocketOutput(kestrelThread, socket, memory, null, 0, trace, tpa); var bufferSize = maxBytesPreCompleted; var buffer = new ArraySegment(new byte[bufferSize], 0, bufferSize); @@ -143,7 +145,8 @@ namespace Microsoft.AspNet.Server.KestrelTests var kestrelThread = kestrelEngine.Threads[0]; var socket = new MockSocket(kestrelThread.Loop.ThreadId, new TestKestrelTrace()); var trace = new KestrelTrace(new TestKestrelTrace()); - var socketOutput = new SocketOutput(kestrelThread, socket, memory, null, 0, trace); + var tpa = new ThreadPoolActions(trace); + var socketOutput = new SocketOutput(kestrelThread, socket, memory, null, 0, trace, tpa); var bufferSize = maxBytesPreCompleted; @@ -223,7 +226,8 @@ namespace Microsoft.AspNet.Server.KestrelTests var kestrelThread = kestrelEngine.Threads[0]; var socket = new MockSocket(kestrelThread.Loop.ThreadId, new TestKestrelTrace()); var trace = new KestrelTrace(new TestKestrelTrace()); - var socketOutput = new SocketOutput(kestrelThread, socket, memory, null, 0, trace); + var tpa = new ThreadPoolActions(trace); + var socketOutput = new SocketOutput(kestrelThread, socket, memory, null, 0, trace, tpa); var bufferSize = maxBytesPreCompleted; var buffer = new ArraySegment(new byte[bufferSize], 0, bufferSize); @@ -299,7 +303,8 @@ namespace Microsoft.AspNet.Server.KestrelTests var kestrelThread = kestrelEngine.Threads[0]; var socket = new MockSocket(kestrelThread.Loop.ThreadId, new TestKestrelTrace()); var trace = new KestrelTrace(new TestKestrelTrace()); - var socketOutput = new SocketOutput(kestrelThread, socket, memory, null, 0, trace); + var tpa = new ThreadPoolActions(trace); + var socketOutput = new SocketOutput(kestrelThread, socket, memory, null, 0, trace, tpa); // block 1 var start = socketOutput.ProducingStart(); diff --git a/test/Microsoft.AspNet.Server.KestrelTests/TestInput.cs b/test/Microsoft.AspNet.Server.KestrelTests/TestInput.cs index a440ea0edf..2337510d32 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/TestInput.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/TestInput.cs @@ -4,6 +4,7 @@ using System; using System.Threading; using System.Threading.Tasks; +using Microsoft.AspNet.Server.Kestrel; using Microsoft.AspNet.Server.Kestrel.Http; using Microsoft.AspNet.Server.Kestrel.Infrastructure; @@ -13,10 +14,12 @@ namespace Microsoft.AspNet.Server.KestrelTests { public TestInput() { + var trace = new KestrelTrace(new TestKestrelTrace()); + var tpa = new ThreadPoolActions(trace); var memory2 = new MemoryPool2(); FrameContext = new FrameContext { - SocketInput = new SocketInput(memory2), + SocketInput = new SocketInput(memory2, tpa), ConnectionControl = this, FrameControl = this }; From 850d2b0c7ea614ab5e81199ea94b61e9867f7502 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Thu, 3 Dec 2015 03:27:11 +0000 Subject: [PATCH 0483/1662] Construct ThreadPoolActions in KestrelServer --- .../KestrelServer.cs | 5 ++++- .../ServiceContext.cs | 19 +++---------------- 2 files changed, 7 insertions(+), 17 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/KestrelServer.cs b/src/Microsoft.AspNet.Server.Kestrel/KestrelServer.cs index f1e3504d22..00d4605ba2 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/KestrelServer.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/KestrelServer.cs @@ -7,6 +7,7 @@ using Microsoft.AspNet.Hosting; using Microsoft.AspNet.Hosting.Server; using Microsoft.AspNet.Http.Features; using Microsoft.AspNet.Server.Kestrel.Http; +using Microsoft.AspNet.Server.Kestrel.Infrastructure; using Microsoft.Extensions.Logging; namespace Microsoft.AspNet.Server.Kestrel @@ -54,6 +55,7 @@ namespace Microsoft.AspNet.Server.Kestrel { var information = (KestrelServerInformation)Features.Get(); var dateHeaderValueManager = new DateHeaderValueManager(); + var trace = new KestrelTrace(_logger); var engine = new KestrelEngine(new ServiceContext { FrameFactory = (context, remoteEP, localEP, prepareRequest) => @@ -61,7 +63,8 @@ namespace Microsoft.AspNet.Server.Kestrel return new Frame(application, context, remoteEP, localEP, prepareRequest); }, AppLifetime = _applicationLifetime, - Log = new KestrelTrace(_logger), + Log = trace, + ThreadPoolActions = new ThreadPoolActions(trace), DateHeaderValueManager = dateHeaderValueManager, ConnectionFilter = information.ConnectionFilter, NoDelay = information.NoDelay diff --git a/src/Microsoft.AspNet.Server.Kestrel/ServiceContext.cs b/src/Microsoft.AspNet.Server.Kestrel/ServiceContext.cs index 3be228d5a3..531750f3a3 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/ServiceContext.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/ServiceContext.cs @@ -13,8 +13,6 @@ namespace Microsoft.AspNet.Server.Kestrel { public class ServiceContext { - private IKestrelTrace _log; - public ServiceContext() { } @@ -22,7 +20,7 @@ namespace Microsoft.AspNet.Server.Kestrel public ServiceContext(ServiceContext context) { AppLifetime = context.AppLifetime; - _log = context.Log; + Log = context.Log; ThreadPoolActions = context.ThreadPoolActions; FrameFactory = context.FrameFactory; DateHeaderValueManager = context.DateHeaderValueManager; @@ -32,20 +30,9 @@ namespace Microsoft.AspNet.Server.Kestrel public IApplicationLifetime AppLifetime { get; set; } - public IKestrelTrace Log - { - get - { - return _log; - } - set - { - _log = value; - ThreadPoolActions = new ThreadPoolActions(_log); - } - } + public IKestrelTrace Log { get; set; } - public ThreadPoolActions ThreadPoolActions { get; private set; } + public ThreadPoolActions ThreadPoolActions { get; set; } public Func, Frame> FrameFactory { get; set; } From b1e8f0cdea2564ebbeb9dbe28f8c09f601f79ec2 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Thu, 3 Dec 2015 09:38:30 +0000 Subject: [PATCH 0484/1662] Add IThreadPool interface --- .../Filter/FilteredStreamAdapter.cs | 4 ++-- .../Http/Connection.cs | 8 ++++---- .../Http/SocketInput.cs | 12 +++++------ .../Http/SocketOutput.cs | 10 +++++----- .../Infrastructure/IThreadPool.cs | 15 ++++++++++++++ .../Infrastructure/KestrelThread.cs | 8 ++++---- ...eadPoolActions.cs => LoggingThreadPool.cs} | 5 ++--- .../KestrelServer.cs | 2 +- .../ServiceContext.cs | 4 ++-- .../FrameTests.cs | 4 ++-- .../SocketOutputTests.cs | 20 +++++++++---------- .../TestInput.cs | 4 ++-- .../TestServiceContext.cs | 2 ++ 13 files changed, 57 insertions(+), 41 deletions(-) create mode 100644 src/Microsoft.AspNet.Server.Kestrel/Infrastructure/IThreadPool.cs rename src/Microsoft.AspNet.Server.Kestrel/Infrastructure/{ThreadPoolActions.cs => LoggingThreadPool.cs} (93%) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Filter/FilteredStreamAdapter.cs b/src/Microsoft.AspNet.Server.Kestrel/Filter/FilteredStreamAdapter.cs index 3266d88d64..1409940c86 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Filter/FilteredStreamAdapter.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Filter/FilteredStreamAdapter.cs @@ -20,9 +20,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Filter Stream filteredStream, MemoryPool2 memory, IKestrelTrace logger, - ThreadPoolActions threadPoolActions) + IThreadPool threadPool) { - SocketInput = new SocketInput(memory, threadPoolActions); + SocketInput = new SocketInput(memory, threadPool); SocketOutput = new StreamSocketOutput(filteredStream, memory); _log = logger; diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs index dd7236f523..b49ffd4316 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs @@ -41,8 +41,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http _connectionId = Interlocked.Increment(ref _lastConnectionId); - _rawSocketInput = new SocketInput(Memory2, ThreadPoolActions); - _rawSocketOutput = new SocketOutput(Thread, _socket, Memory2, this, _connectionId, Log, ThreadPoolActions); + _rawSocketInput = new SocketInput(Memory2, ThreadPool); + _rawSocketOutput = new SocketOutput(Thread, _socket, Memory2, this, _connectionId, Log, ThreadPool); } public void Start() @@ -114,7 +114,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { // Frame.Abort calls user code while this method is always // called from a libuv thread. - ThreadPool.QueueUserWorkItem(state => + System.Threading.ThreadPool.QueueUserWorkItem(state => { var connection = (Connection)state; connection._frame.Abort(); @@ -124,7 +124,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http private void ApplyConnectionFilter() { - var filteredStreamAdapter = new FilteredStreamAdapter(_filterContext.Connection, Memory2, Log, ThreadPoolActions); + var filteredStreamAdapter = new FilteredStreamAdapter(_filterContext.Connection, Memory2, Log, ThreadPool); SocketInput = filteredStreamAdapter.SocketInput; SocketOutput = filteredStreamAdapter.SocketOutput; diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketInput.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketInput.cs index a85634331d..5f850b5d68 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketInput.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketInput.cs @@ -16,7 +16,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http private static readonly Action _awaitableIsNotCompleted = () => { }; private readonly MemoryPool2 _memory; - private readonly ThreadPoolActions _threadPoolActions; + private readonly IThreadPool _threadPool; private readonly ManualResetEventSlim _manualResetEvent = new ManualResetEventSlim(false); private Action _awaitableState; @@ -27,10 +27,10 @@ namespace Microsoft.AspNet.Server.Kestrel.Http private MemoryPoolBlock2 _pinned; private readonly object _sync = new Object(); - public SocketInput(MemoryPool2 memory, ThreadPoolActions threadPoolActions) + public SocketInput(MemoryPool2 memory, IThreadPool threadPool) { _memory = memory; - _threadPoolActions = threadPoolActions; + _threadPool = threadPool; _awaitableState = _awaitableIsNotCompleted; } @@ -130,7 +130,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http if (awaitableState != _awaitableIsCompleted && awaitableState != _awaitableIsNotCompleted) { - _threadPoolActions.Run(awaitableState); + _threadPool.Run(awaitableState); } } @@ -190,7 +190,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http if (awaitableState != _awaitableIsCompleted && awaitableState != _awaitableIsNotCompleted) { - _threadPoolActions.Run(awaitableState); + _threadPool.Run(awaitableState); } } @@ -212,7 +212,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } else if (awaitableState == _awaitableIsCompleted) { - _threadPoolActions.Run(continuation); + _threadPool.Run(continuation); } else { diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs index ef6b5e4f1f..64c5808efb 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs @@ -25,7 +25,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http private readonly Connection _connection; private readonly long _connectionId; private readonly IKestrelTrace _log; - private readonly ThreadPoolActions _threadPoolActions; + private readonly IThreadPool _threadPool; // This locks all access to _tail, _isProducing and _returnFromOnProducingComplete. // _head does not require a lock, since it is only used in the ctor and uv thread. @@ -57,14 +57,14 @@ namespace Microsoft.AspNet.Server.Kestrel.Http Connection connection, long connectionId, IKestrelTrace log, - ThreadPoolActions threadPoolActions) + IThreadPool threadPool) { _thread = thread; _socket = socket; _connection = connection; _connectionId = connectionId; _log = log; - _threadPoolActions = threadPoolActions; + _threadPool = threadPool; _tasksPending = new Queue>(_initialTaskQueues); _tasksCompleted = new Queue>(_initialTaskQueues); @@ -322,11 +322,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http var tcs = _tasksCompleted.Dequeue(); if (_lastWriteError == null) { - _threadPoolActions.Complete(tcs); + _threadPool.Complete(tcs); } else { - _threadPoolActions.Error(tcs, _lastWriteError); + _threadPool.Error(tcs, _lastWriteError); } } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/IThreadPool.cs b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/IThreadPool.cs new file mode 100644 index 0000000000..fde95f4241 --- /dev/null +++ b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/IThreadPool.cs @@ -0,0 +1,15 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Threading.Tasks; + +namespace Microsoft.AspNet.Server.Kestrel.Infrastructure +{ + public interface IThreadPool + { + void Complete(TaskCompletionSource tcs); + void Error(TaskCompletionSource tcs, Exception ex); + void Run(Action action); + } +} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs index 98c9ef3f4f..64a1c9b81f 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs @@ -33,14 +33,14 @@ namespace Microsoft.AspNet.Server.Kestrel private bool _initCompleted = false; private ExceptionDispatchInfo _closeError; private IKestrelTrace _log; - private ThreadPoolActions _threadPoolActions; + private IThreadPool _threadPool; public KestrelThread(KestrelEngine engine) { _engine = engine; _appLifetime = engine.AppLifetime; _log = engine.Log; - _threadPoolActions = engine.ThreadPoolActions; + _threadPool = engine.ThreadPool; _loop = new UvLoopHandle(_log); _post = new UvAsyncHandle(_log); _thread = new Thread(ThreadStart); @@ -268,14 +268,14 @@ namespace Microsoft.AspNet.Server.Kestrel work.CallbackAdapter(work.Callback, work.State); if (work.Completion != null) { - _threadPoolActions.Complete(work.Completion); + _threadPool.Complete(work.Completion); } } catch (Exception ex) { if (work.Completion != null) { - _threadPoolActions.Error(work.Completion, ex); + _threadPool.Error(work.Completion, ex); } else { diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/ThreadPoolActions.cs b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/LoggingThreadPool.cs similarity index 93% rename from src/Microsoft.AspNet.Server.Kestrel/Infrastructure/ThreadPoolActions.cs rename to src/Microsoft.AspNet.Server.Kestrel/Infrastructure/LoggingThreadPool.cs index cbcba6c239..967787dc1f 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/ThreadPoolActions.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/LoggingThreadPool.cs @@ -4,18 +4,17 @@ using System; using System.Threading; using System.Threading.Tasks; -using Microsoft.AspNet.Server.Kestrel.Http; namespace Microsoft.AspNet.Server.Kestrel.Infrastructure { - public class ThreadPoolActions + public class LoggingThreadPool : IThreadPool { private readonly IKestrelTrace _log; private readonly WaitCallback _runAction; private readonly WaitCallback _completeTcs; - public ThreadPoolActions(IKestrelTrace log) + public LoggingThreadPool(IKestrelTrace log) { _log = log; diff --git a/src/Microsoft.AspNet.Server.Kestrel/KestrelServer.cs b/src/Microsoft.AspNet.Server.Kestrel/KestrelServer.cs index 00d4605ba2..b8e9c5dd07 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/KestrelServer.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/KestrelServer.cs @@ -64,7 +64,7 @@ namespace Microsoft.AspNet.Server.Kestrel }, AppLifetime = _applicationLifetime, Log = trace, - ThreadPoolActions = new ThreadPoolActions(trace), + ThreadPool = new LoggingThreadPool(trace), DateHeaderValueManager = dateHeaderValueManager, ConnectionFilter = information.ConnectionFilter, NoDelay = information.NoDelay diff --git a/src/Microsoft.AspNet.Server.Kestrel/ServiceContext.cs b/src/Microsoft.AspNet.Server.Kestrel/ServiceContext.cs index 531750f3a3..31eeea898d 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/ServiceContext.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/ServiceContext.cs @@ -21,7 +21,7 @@ namespace Microsoft.AspNet.Server.Kestrel { AppLifetime = context.AppLifetime; Log = context.Log; - ThreadPoolActions = context.ThreadPoolActions; + ThreadPool = context.ThreadPool; FrameFactory = context.FrameFactory; DateHeaderValueManager = context.DateHeaderValueManager; ConnectionFilter = context.ConnectionFilter; @@ -32,7 +32,7 @@ namespace Microsoft.AspNet.Server.Kestrel public IKestrelTrace Log { get; set; } - public ThreadPoolActions ThreadPoolActions { get; set; } + public IThreadPool ThreadPool { get; set; } public Func, Frame> FrameFactory { get; set; } diff --git a/test/Microsoft.AspNet.Server.KestrelTests/FrameTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/FrameTests.cs index b6267e384c..cc9bc26618 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/FrameTests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/FrameTests.cs @@ -50,8 +50,8 @@ namespace Microsoft.AspNet.Server.KestrelTests public void EmptyHeaderValuesCanBeParsed(string rawHeaders, int numHeaders) { var trace = new KestrelTrace(new TestKestrelTrace()); - var tpa = new ThreadPoolActions(trace); - var socketInput = new SocketInput(new MemoryPool2(), tpa); + var ltp = new LoggingThreadPool(trace); + var socketInput = new SocketInput(new MemoryPool2(), ltp); var headerCollection = new FrameRequestHeaders(); var headerArray = Encoding.ASCII.GetBytes(rawHeaders); diff --git a/test/Microsoft.AspNet.Server.KestrelTests/SocketOutputTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/SocketOutputTests.cs index 4028cfff1d..dca77cf881 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/SocketOutputTests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/SocketOutputTests.cs @@ -41,8 +41,8 @@ namespace Microsoft.AspNet.Server.KestrelTests var kestrelThread = kestrelEngine.Threads[0]; var socket = new MockSocket(kestrelThread.Loop.ThreadId, new TestKestrelTrace()); var trace = new KestrelTrace(new TestKestrelTrace()); - var tpa = new ThreadPoolActions(trace); - var socketOutput = new SocketOutput(kestrelThread, socket, memory, null, 0, trace, tpa); + var ltp = new LoggingThreadPool(trace); + var socketOutput = new SocketOutput(kestrelThread, socket, memory, null, 0, trace, ltp); // I doubt _maxBytesPreCompleted will ever be over a MB. If it is, we should change this test. var bufferSize = 1048576; @@ -88,8 +88,8 @@ namespace Microsoft.AspNet.Server.KestrelTests var kestrelThread = kestrelEngine.Threads[0]; var socket = new MockSocket(kestrelThread.Loop.ThreadId, new TestKestrelTrace()); var trace = new KestrelTrace(new TestKestrelTrace()); - var tpa = new ThreadPoolActions(trace); - var socketOutput = new SocketOutput(kestrelThread, socket, memory, null, 0, trace, tpa); + var ltp = new LoggingThreadPool(trace); + var socketOutput = new SocketOutput(kestrelThread, socket, memory, null, 0, trace, ltp); var bufferSize = maxBytesPreCompleted; var buffer = new ArraySegment(new byte[bufferSize], 0, bufferSize); @@ -145,8 +145,8 @@ namespace Microsoft.AspNet.Server.KestrelTests var kestrelThread = kestrelEngine.Threads[0]; var socket = new MockSocket(kestrelThread.Loop.ThreadId, new TestKestrelTrace()); var trace = new KestrelTrace(new TestKestrelTrace()); - var tpa = new ThreadPoolActions(trace); - var socketOutput = new SocketOutput(kestrelThread, socket, memory, null, 0, trace, tpa); + var ltp = new LoggingThreadPool(trace); + var socketOutput = new SocketOutput(kestrelThread, socket, memory, null, 0, trace, ltp); var bufferSize = maxBytesPreCompleted; @@ -226,8 +226,8 @@ namespace Microsoft.AspNet.Server.KestrelTests var kestrelThread = kestrelEngine.Threads[0]; var socket = new MockSocket(kestrelThread.Loop.ThreadId, new TestKestrelTrace()); var trace = new KestrelTrace(new TestKestrelTrace()); - var tpa = new ThreadPoolActions(trace); - var socketOutput = new SocketOutput(kestrelThread, socket, memory, null, 0, trace, tpa); + var ltp = new LoggingThreadPool(trace); + var socketOutput = new SocketOutput(kestrelThread, socket, memory, null, 0, trace, ltp); var bufferSize = maxBytesPreCompleted; var buffer = new ArraySegment(new byte[bufferSize], 0, bufferSize); @@ -303,8 +303,8 @@ namespace Microsoft.AspNet.Server.KestrelTests var kestrelThread = kestrelEngine.Threads[0]; var socket = new MockSocket(kestrelThread.Loop.ThreadId, new TestKestrelTrace()); var trace = new KestrelTrace(new TestKestrelTrace()); - var tpa = new ThreadPoolActions(trace); - var socketOutput = new SocketOutput(kestrelThread, socket, memory, null, 0, trace, tpa); + var ltp = new LoggingThreadPool(trace); + var socketOutput = new SocketOutput(kestrelThread, socket, memory, null, 0, trace, ltp); // block 1 var start = socketOutput.ProducingStart(); diff --git a/test/Microsoft.AspNet.Server.KestrelTests/TestInput.cs b/test/Microsoft.AspNet.Server.KestrelTests/TestInput.cs index 2337510d32..827d47ba84 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/TestInput.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/TestInput.cs @@ -15,11 +15,11 @@ namespace Microsoft.AspNet.Server.KestrelTests public TestInput() { var trace = new KestrelTrace(new TestKestrelTrace()); - var tpa = new ThreadPoolActions(trace); + var ltp = new LoggingThreadPool(trace); var memory2 = new MemoryPool2(); FrameContext = new FrameContext { - SocketInput = new SocketInput(memory2, tpa), + SocketInput = new SocketInput(memory2, ltp), ConnectionControl = this, FrameControl = this }; diff --git a/test/Microsoft.AspNet.Server.KestrelTests/TestServiceContext.cs b/test/Microsoft.AspNet.Server.KestrelTests/TestServiceContext.cs index 9686915699..54dfc3c3b3 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/TestServiceContext.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/TestServiceContext.cs @@ -4,6 +4,7 @@ using Microsoft.AspNet.Http; using Microsoft.AspNet.Server.Kestrel; using Microsoft.AspNet.Server.Kestrel.Http; +using Microsoft.AspNet.Server.Kestrel.Infrastructure; namespace Microsoft.AspNet.Server.KestrelTests { @@ -15,6 +16,7 @@ namespace Microsoft.AspNet.Server.KestrelTests { AppLifetime = new LifetimeNotImplemented(); Log = new TestKestrelTrace(); + ThreadPool = new LoggingThreadPool(Log); DateHeaderValueManager = new TestDateHeaderValueManager(); } From c41b4496810bddcc3c7fde1e4a90d5bde9e32982 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Thu, 3 Dec 2015 01:36:22 +0000 Subject: [PATCH 0485/1662] Lighter & less async sMachines Selected excerpts from "Value tasks + Less Async" #432 --- .../Http/Frame.cs | 73 +++++++++++++++++-- .../Http/FrameOfT.cs | 33 +++++---- 2 files changed, 84 insertions(+), 22 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs index befc6ba294..008e1a905e 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs @@ -44,9 +44,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Http protected readonly FrameRequestHeaders _requestHeaders = new FrameRequestHeaders(); private readonly FrameResponseHeaders _responseHeaders = new FrameResponseHeaders(); - private List, object>> _onStarting; + protected List, object>> _onStarting; - private List, object>> _onCompleted; + protected List, object>> _onCompleted; private bool _requestProcessingStarted; private Task _requestProcessingTask; @@ -144,8 +144,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { // If a request abort token was previously explicitly set, return it. if (_manuallySetRequestAbortToken.HasValue) + { return _manuallySetRequestAbortToken.Value; - + } // Otherwise, get the abort CTS. If we have one, which would mean that someone previously // asked for the RequestAborted token, simply return its token. If we don't, // check to see whether we've already aborted, in which case just return an @@ -416,7 +417,28 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } - public async Task WriteAsync(ArraySegment data, CancellationToken cancellationToken) + public Task WriteAsync(ArraySegment data, CancellationToken cancellationToken) + { + if (!_responseStarted) + { + return WriteAsyncAwaited(data, cancellationToken); + } + + if (_autoChunk) + { + if (data.Count == 0) + { + return TaskUtilities.CompletedTask; + } + return WriteChunkedAsync(data, cancellationToken); + } + else + { + return SocketOutput.WriteAsync(data, immediate: true, cancellationToken: cancellationToken); + } + } + + public async Task WriteAsyncAwaited(ArraySegment data, CancellationToken cancellationToken) { await ProduceStartAndFireOnStarting(immediate: false); @@ -501,10 +523,27 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } - public async Task ProduceStartAndFireOnStarting(bool immediate = true) + public Task ProduceStartAndFireOnStarting(bool immediate = true) { - if (_responseStarted) return; + if (_responseStarted) return TaskUtilities.CompletedTask; + if (_onStarting != null) + { + return FireOnStartingProduceStart(immediate: immediate); + } + + if (_applicationException != null) + { + throw new ObjectDisposedException( + "The response has been aborted due to an unhandled application exception.", + _applicationException); + } + + return ProduceStart(immediate, appCompleted: false); + } + + private async Task FireOnStartingProduceStart(bool immediate) + { await FireOnStarting(); if (_applicationException != null) @@ -527,7 +566,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return CreateResponseHeader(statusBytes, appCompleted, immediate); } - protected async Task ProduceEnd() + protected Task ProduceEnd() { if (_applicationException != null) { @@ -535,7 +574,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { // We can no longer respond with a 500, so we simply close the connection. _requestProcessingStopping = true; - return; + return TaskUtilities.CompletedTask; } else { @@ -547,8 +586,26 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } + + if (!_responseStarted) + { + return ProduceEndAwaited(); + } + + WriteSuffix(); + + return TaskUtilities.CompletedTask; + } + + private async Task ProduceEndAwaited() + { await ProduceStart(immediate: true, appCompleted: true); + WriteSuffix(); + } + + private void WriteSuffix() + { // _autoChunk should be checked after we are sure ProduceStart() has been called // since ProduceStart() may set _autoChunk to true. if (_autoChunk) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameOfT.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameOfT.cs index 941c75fe8e..4410cdc8cd 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameOfT.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameOfT.cs @@ -40,28 +40,27 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { try { - var terminated = false; - while (!terminated && !_requestProcessingStopping) + while (!_requestProcessingStopping) { - while (!terminated && !_requestProcessingStopping && !TakeStartLine(SocketInput)) + while (!_requestProcessingStopping && !TakeStartLine(SocketInput)) { - terminated = SocketInput.RemoteIntakeFin; - if (!terminated) + if (SocketInput.RemoteIntakeFin) { - await SocketInput; + return; } + await SocketInput; } - while (!terminated && !_requestProcessingStopping && !TakeMessageHeaders(SocketInput, _requestHeaders)) + while (!_requestProcessingStopping && !TakeMessageHeaders(SocketInput, _requestHeaders)) { - terminated = SocketInput.RemoteIntakeFin; - if (!terminated) + if (SocketInput.RemoteIntakeFin) { - await SocketInput; + return; } + await SocketInput; } - if (!terminated && !_requestProcessingStopping) + if (!_requestProcessingStopping) { var messageBody = MessageBody.For(HttpVersion, _requestHeaders, this); _keepAlive = messageBody.RequestKeepAlive; @@ -89,12 +88,15 @@ namespace Microsoft.AspNet.Server.Kestrel.Http // already failed. If an OnStarting callback throws we can go through // our normal error handling in ProduceEnd. // https://github.com/aspnet/KestrelHttpServer/issues/43 - if (!_responseStarted && _applicationException == null) + if (!_responseStarted && _applicationException == null && _onStarting != null) { await FireOnStarting(); } - await FireOnCompleted(); + if (_onCompleted != null) + { + await FireOnCompleted(); + } _application.DisposeContext(context, _applicationException); @@ -114,7 +116,10 @@ namespace Microsoft.AspNet.Server.Kestrel.Http _responseBody.StopAcceptingWrites(); } - terminated = !_keepAlive; + if (!_keepAlive) + { + return; + } } Reset(); From 9af9dea72c3d42b9b94bfb1c59a03955940e312f Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Thu, 3 Dec 2015 18:46:43 +0000 Subject: [PATCH 0486/1662] Smaller default buffer --- .../Filter/FilteredStreamAdapter.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Filter/FilteredStreamAdapter.cs b/src/Microsoft.AspNet.Server.Kestrel/Filter/FilteredStreamAdapter.cs index e3d2eb5603..598620d1e6 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Filter/FilteredStreamAdapter.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Filter/FilteredStreamAdapter.cs @@ -28,7 +28,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Filter _filteredStream = filteredStream; _socketInputStream = new SocketInputStream(SocketInput); - _filteredStream.CopyToAsync(_socketInputStream).ContinueWith((task, state) => + // Don't use 81920 byte buffer + _filteredStream.CopyToAsync(_socketInputStream, 4096).ContinueWith((task, state) => { ((FilteredStreamAdapter)state).OnStreamClose(task); }, this); From 1ca67695ed7f9517e23c2ffb69bf45b150c7cb81 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Thu, 3 Dec 2015 19:17:40 +0000 Subject: [PATCH 0487/1662] Use pooled memory for filtered stream --- .../Filter/FilteredStreamAdapter.cs | 8 +++++-- .../Filter/StreamExtensions.cs | 23 +++++++++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 src/Microsoft.AspNet.Server.Kestrel/Filter/StreamExtensions.cs diff --git a/src/Microsoft.AspNet.Server.Kestrel/Filter/FilteredStreamAdapter.cs b/src/Microsoft.AspNet.Server.Kestrel/Filter/FilteredStreamAdapter.cs index 598620d1e6..beb5c3b803 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Filter/FilteredStreamAdapter.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Filter/FilteredStreamAdapter.cs @@ -28,9 +28,13 @@ namespace Microsoft.AspNet.Server.Kestrel.Filter _filteredStream = filteredStream; _socketInputStream = new SocketInputStream(SocketInput); - // Don't use 81920 byte buffer - _filteredStream.CopyToAsync(_socketInputStream, 4096).ContinueWith((task, state) => + var block = memory.Lease(); + // Use pooled block for copy + _filteredStream.CopyToAsync(_socketInputStream, block).ContinueWith((task, state) => { + var returnedBlock = task.Result; + returnedBlock.Pool?.Return(returnedBlock); + ((FilteredStreamAdapter)state).OnStreamClose(task); }, this); } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Filter/StreamExtensions.cs b/src/Microsoft.AspNet.Server.Kestrel/Filter/StreamExtensions.cs new file mode 100644 index 0000000000..af3e77d15f --- /dev/null +++ b/src/Microsoft.AspNet.Server.Kestrel/Filter/StreamExtensions.cs @@ -0,0 +1,23 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System.IO; +using System.Threading.Tasks; +using Microsoft.AspNet.Server.Kestrel.Infrastructure; + +namespace Microsoft.AspNet.Server.Kestrel.Filter +{ + public static class StreamExtensions + { + public static async Task CopyToAsync(this Stream source, Stream destination, MemoryPoolBlock2 block) + { + int bytesRead; + while ((bytesRead = await source.ReadAsync(block.Array, block.Data.Offset, block.Data.Count)) != 0) + { + await destination.WriteAsync(block.Array, block.Data.Offset, bytesRead); + } + + return block; + } + } +} From 858e5ab3a2ef74893703b9dac2ff66cac2729c5a Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Sun, 22 Nov 2015 16:11:41 +0000 Subject: [PATCH 0488/1662] Moar stopping power, Timeout is total timout --- .../Infrastructure/KestrelThread.cs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs index 93c30a55dd..a288ef49ac 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs @@ -64,16 +64,18 @@ namespace Microsoft.AspNet.Server.Kestrel return; } + var stepTimeout = (int)(timeout.TotalMilliseconds / 3); + Post(t => t.OnStop()); - if (!_thread.Join((int)timeout.TotalMilliseconds)) + if (!_thread.Join(stepTimeout)) { try { Post(t => t.OnStopRude()); - if (!_thread.Join((int)timeout.TotalMilliseconds)) + if (!_thread.Join(stepTimeout)) { Post(t => t.OnStopImmediate()); - if (!_thread.Join((int)timeout.TotalMilliseconds)) + if (!_thread.Join(stepTimeout)) { #if NET451 _thread.Abort(); @@ -85,7 +87,7 @@ namespace Microsoft.AspNet.Server.Kestrel { // REVIEW: Should we log something here? // Until we rework this logic, ODEs are bound to happen sometimes. - if (!_thread.Join((int)timeout.TotalMilliseconds)) + if (!_thread.Join(stepTimeout)) { #if NET451 _thread.Abort(); From 35a06369d766a217b37e47e1cb6dd26f639c3354 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Fri, 4 Dec 2015 08:23:12 +0000 Subject: [PATCH 0489/1662] Pooled block always has pool --- .../Filter/FilteredStreamAdapter.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Filter/FilteredStreamAdapter.cs b/src/Microsoft.AspNet.Server.Kestrel/Filter/FilteredStreamAdapter.cs index b5de5ef4fe..2697d45b71 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Filter/FilteredStreamAdapter.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Filter/FilteredStreamAdapter.cs @@ -34,7 +34,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Filter _filteredStream.CopyToAsync(_socketInputStream, block).ContinueWith((task, state) => { var returnedBlock = task.Result; - returnedBlock.Pool?.Return(returnedBlock); + returnedBlock.Pool.Return(returnedBlock); ((FilteredStreamAdapter)state).OnStreamClose(task); }, this); From 5eaa7e51c868e2b89f9c7dff4701af22ae98f0d0 Mon Sep 17 00:00:00 2001 From: Kristian Hellang Date: Mon, 23 Nov 2015 00:05:10 +0100 Subject: [PATCH 0490/1662] Initialize ThreadCount as early as possible This will allow you to inspect the property in the Configure method. Closes #404 --- .../KestrelServer.cs | 31 +++---------------- .../KestrelServerInformation.cs | 24 ++++++++++---- .../ServerFactory.cs | 29 +++++++++++++++-- 3 files changed, 50 insertions(+), 34 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/KestrelServer.cs b/src/Microsoft.AspNet.Server.Kestrel/KestrelServer.cs index b8e9c5dd07..3a1295de76 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/KestrelServer.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/KestrelServer.cs @@ -73,34 +73,13 @@ namespace Microsoft.AspNet.Server.Kestrel _disposables.Push(engine); _disposables.Push(dateHeaderValueManager); - // Actual core count would be a better number - // rather than logical cores which includes hyper-threaded cores. - // Divide by 2 for hyper-threading, and good defaults (still need threads to do webserving). - // Can be user overriden using IKestrelServerInformation.ThreadCount - var threadCount = Environment.ProcessorCount >> 1; + var threadCount = information.ThreadCount; - if (threadCount < 1) + if (threadCount <= 0) { - // Ensure shifted value is at least one - threadCount = 1; - } - else if (threadCount > 16) - { - // Receive Side Scaling RSS Processor count currently maxes out at 16 - // would be better to check the NIC's current hardware queues; but xplat... - threadCount = 16; - } - - if (information.ThreadCount < 0) - { - throw new ArgumentOutOfRangeException(nameof(information.ThreadCount), - information.ThreadCount, - "ThreadCount cannot be negative"); - } - else if (information.ThreadCount > 0) - { - // ThreadCount has been user set, use that value - threadCount = information.ThreadCount; + throw new ArgumentOutOfRangeException(nameof(threadCount), + threadCount, + "ThreadCount must be positive."); } engine.Start(threadCount); diff --git a/src/Microsoft.AspNet.Server.Kestrel/KestrelServerInformation.cs b/src/Microsoft.AspNet.Server.Kestrel/KestrelServerInformation.cs index 71e6ababcf..ec31f4fbf6 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/KestrelServerInformation.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/KestrelServerInformation.cs @@ -11,21 +11,33 @@ namespace Microsoft.AspNet.Server.Kestrel { public class KestrelServerInformation : IKestrelServerInformation, IServerAddressesFeature { - public ICollection Addresses { get; } = new List(); + public KestrelServerInformation(IConfiguration configuration, int threadCount) + { + Addresses = GetAddresses(configuration); + ThreadCount = threadCount; + NoDelay = true; + } + + public ICollection Addresses { get; } public int ThreadCount { get; set; } - public bool NoDelay { get; set; } = true; + public bool NoDelay { get; set; } public IConnectionFilter ConnectionFilter { get; set; } - public void Initialize(IConfiguration configuration) + private static ICollection GetAddresses(IConfiguration configuration) { - var urls = configuration["server.urls"] ?? string.Empty; - foreach (var url in urls.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries)) + var addresses = new List(); + + var urls = configuration["server.urls"]; + + if (!string.IsNullOrEmpty(urls)) { - Addresses.Add(url); + addresses.AddRange(urls.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries)); } + + return addresses; } } } diff --git a/src/Microsoft.AspNet.Server.Kestrel/ServerFactory.cs b/src/Microsoft.AspNet.Server.Kestrel/ServerFactory.cs index ccde5797ce..284823b849 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/ServerFactory.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/ServerFactory.cs @@ -1,6 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; using Microsoft.AspNet.Hosting; using Microsoft.AspNet.Hosting.Server; using Microsoft.AspNet.Http.Features; @@ -26,12 +27,36 @@ namespace Microsoft.AspNet.Server.Kestrel public IServer CreateServer(IConfiguration configuration) { - var information = new KestrelServerInformation(); - information.Initialize(configuration); + var threadCount = GetThreadCount(); + var information = new KestrelServerInformation(configuration, threadCount); var serverFeatures = new FeatureCollection(); serverFeatures.Set(information); serverFeatures.Set(information); return new KestrelServer(serverFeatures, _appLifetime, _loggerFactory.CreateLogger("Microsoft.AspNet.Server.Kestrel")); } + + private static int GetThreadCount() + { + // Actual core count would be a better number + // rather than logical cores which includes hyper-threaded cores. + // Divide by 2 for hyper-threading, and good defaults (still need threads to do webserving). + // Can be user overriden using IKestrelServerInformation.ThreadCount + var threadCount = Environment.ProcessorCount >> 1; + + if (threadCount < 1) + { + // Ensure shifted value is at least one + return 1; + } + + if (threadCount > 16) + { + // Receive Side Scaling RSS Processor count currently maxes out at 16 + // would be better to check the NIC's current hardware queues; but xplat... + return 16; + } + + return threadCount; + } } } From 75cfe2c3bbcf736f28e93377548668867a6d6abe Mon Sep 17 00:00:00 2001 From: Kristian Hellang Date: Mon, 7 Dec 2015 14:45:35 +0100 Subject: [PATCH 0491/1662] Moved GetThreadCount into KestrelServerInformation --- .../KestrelServerInformation.cs | 28 +++++++++++++++++-- .../ServerFactory.cs | 27 +----------------- 2 files changed, 27 insertions(+), 28 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/KestrelServerInformation.cs b/src/Microsoft.AspNet.Server.Kestrel/KestrelServerInformation.cs index ec31f4fbf6..9619df7c1d 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/KestrelServerInformation.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/KestrelServerInformation.cs @@ -11,10 +11,10 @@ namespace Microsoft.AspNet.Server.Kestrel { public class KestrelServerInformation : IKestrelServerInformation, IServerAddressesFeature { - public KestrelServerInformation(IConfiguration configuration, int threadCount) + public KestrelServerInformation(IConfiguration configuration) { Addresses = GetAddresses(configuration); - ThreadCount = threadCount; + ThreadCount = GetThreadCount(configuration); NoDelay = true; } @@ -39,5 +39,29 @@ namespace Microsoft.AspNet.Server.Kestrel return addresses; } + + private static int GetThreadCount(IConfiguration configuration) + { + // Actual core count would be a better number + // rather than logical cores which includes hyper-threaded cores. + // Divide by 2 for hyper-threading, and good defaults (still need threads to do webserving). + // Can be user overriden using IKestrelServerInformation.ThreadCount + var threadCount = Environment.ProcessorCount >> 1; + + if (threadCount < 1) + { + // Ensure shifted value is at least one + return 1; + } + + if (threadCount > 16) + { + // Receive Side Scaling RSS Processor count currently maxes out at 16 + // would be better to check the NIC's current hardware queues; but xplat... + return 16; + } + + return threadCount; + } } } diff --git a/src/Microsoft.AspNet.Server.Kestrel/ServerFactory.cs b/src/Microsoft.AspNet.Server.Kestrel/ServerFactory.cs index 284823b849..d7f95ce25c 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/ServerFactory.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/ServerFactory.cs @@ -27,36 +27,11 @@ namespace Microsoft.AspNet.Server.Kestrel public IServer CreateServer(IConfiguration configuration) { - var threadCount = GetThreadCount(); - var information = new KestrelServerInformation(configuration, threadCount); + var information = new KestrelServerInformation(configuration); var serverFeatures = new FeatureCollection(); serverFeatures.Set(information); serverFeatures.Set(information); return new KestrelServer(serverFeatures, _appLifetime, _loggerFactory.CreateLogger("Microsoft.AspNet.Server.Kestrel")); } - - private static int GetThreadCount() - { - // Actual core count would be a better number - // rather than logical cores which includes hyper-threaded cores. - // Divide by 2 for hyper-threading, and good defaults (still need threads to do webserving). - // Can be user overriden using IKestrelServerInformation.ThreadCount - var threadCount = Environment.ProcessorCount >> 1; - - if (threadCount < 1) - { - // Ensure shifted value is at least one - return 1; - } - - if (threadCount > 16) - { - // Receive Side Scaling RSS Processor count currently maxes out at 16 - // would be better to check the NIC's current hardware queues; but xplat... - return 16; - } - - return threadCount; - } } } From b6b8ea3c384c61912dd54ea79b0c3b518842a936 Mon Sep 17 00:00:00 2001 From: Kristian Hellang Date: Mon, 7 Dec 2015 14:46:53 +0100 Subject: [PATCH 0492/1662] Made ThreadCount configurable --- .../KestrelServerInformation.cs | 33 +++++++++++-------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/KestrelServerInformation.cs b/src/Microsoft.AspNet.Server.Kestrel/KestrelServerInformation.cs index 9619df7c1d..84b2fcab57 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/KestrelServerInformation.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/KestrelServerInformation.cs @@ -42,23 +42,28 @@ namespace Microsoft.AspNet.Server.Kestrel private static int GetThreadCount(IConfiguration configuration) { - // Actual core count would be a better number - // rather than logical cores which includes hyper-threaded cores. - // Divide by 2 for hyper-threading, and good defaults (still need threads to do webserving). - // Can be user overriden using IKestrelServerInformation.ThreadCount - var threadCount = Environment.ProcessorCount >> 1; + var threadCountString = configuration["server.threadCount"]; - if (threadCount < 1) + int threadCount; + if (string.IsNullOrEmpty(threadCountString) || !int.TryParse(threadCountString, out threadCount)) { - // Ensure shifted value is at least one - return 1; - } + // Actual core count would be a better number + // rather than logical cores which includes hyper-threaded cores. + // Divide by 2 for hyper-threading, and good defaults (still need threads to do webserving). + threadCount = Environment.ProcessorCount >> 1; - if (threadCount > 16) - { - // Receive Side Scaling RSS Processor count currently maxes out at 16 - // would be better to check the NIC's current hardware queues; but xplat... - return 16; + if (threadCount < 1) + { + // Ensure shifted value is at least one + return 1; + } + + if (threadCount > 16) + { + // Receive Side Scaling RSS Processor count currently maxes out at 16 + // would be better to check the NIC's current hardware queues; but xplat... + return 16; + } } return threadCount; From 50f95cbbc0737fe3807223385d98283ce4eaaffa Mon Sep 17 00:00:00 2001 From: Kristian Hellang Date: Mon, 7 Dec 2015 15:17:21 +0100 Subject: [PATCH 0493/1662] Added some tests for ThreadCount --- .../KestrelServerInformationTests.cs | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 test/Microsoft.AspNet.Server.KestrelTests/KestrelServerInformationTests.cs diff --git a/test/Microsoft.AspNet.Server.KestrelTests/KestrelServerInformationTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/KestrelServerInformationTests.cs new file mode 100644 index 0000000000..5a167adf27 --- /dev/null +++ b/test/Microsoft.AspNet.Server.KestrelTests/KestrelServerInformationTests.cs @@ -0,0 +1,51 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Collections.Generic; +using Microsoft.AspNet.Server.Kestrel; +using Microsoft.Extensions.Configuration; +using Xunit; + +namespace Microsoft.AspNet.Server.KestrelTests +{ + public class KestrelServerInformationTests + { + [Fact] + public void SetThreadCountUsingConfiguration() + { + const int expected = 42; + + var values = new Dictionary + { + { "server.threadCount", expected.ToString() } + }; + + var configuration = new ConfigurationBuilder() + .AddInMemoryCollection(values) + .Build(); + + var information = new KestrelServerInformation(configuration); + + Assert.Equal(expected, information.ThreadCount); + } + + [Fact] + public void SetThreadCountUsingProcessorCount() + { + // Ideally we'd mock Environment.ProcessorCount to test edge cases. + var expected = Clamp(Environment.ProcessorCount >> 1, 1, 16); + + var configuration = new ConfigurationBuilder().Build(); + + var information = new KestrelServerInformation(configuration); + + Assert.Equal(expected, information.ThreadCount); + } + + private static int Clamp(int value, int min, int max) + { + return value < min ? min : value > max ? max : value; + } + } +} \ No newline at end of file From bfad32f22321117e6044f3a666a935ab9adc60b2 Mon Sep 17 00:00:00 2001 From: Kristian Hellang Date: Mon, 7 Dec 2015 15:22:39 +0100 Subject: [PATCH 0494/1662] Added test for Addresses --- .../KestrelServerInformationTests.cs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/test/Microsoft.AspNet.Server.KestrelTests/KestrelServerInformationTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/KestrelServerInformationTests.cs index 5a167adf27..2a3285da9f 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/KestrelServerInformationTests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/KestrelServerInformationTests.cs @@ -43,6 +43,25 @@ namespace Microsoft.AspNet.Server.KestrelTests Assert.Equal(expected, information.ThreadCount); } + [Fact] + public void SetAddressesUsingConfiguration() + { + var expected = new List { "http://localhost:1337", "https://localhost:42" }; + + var values = new Dictionary + { + { "server.urls", string.Join(";", expected) } + }; + + var configuration = new ConfigurationBuilder() + .AddInMemoryCollection(values) + .Build(); + + var information = new KestrelServerInformation(configuration); + + Assert.Equal(expected, information.Addresses); + } + private static int Clamp(int value, int min, int max) { return value < min ? min : value > max ? max : value; From 59bfb9ba1037be348721383b1a55c9e7abdb6f24 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Mon, 7 Dec 2015 04:59:29 +0000 Subject: [PATCH 0495/1662] Trim req/resp streams by a field each --- .../Http/FrameRequestStream.cs | 66 +++++++++---------- .../Http/FrameResponseStream.cs | 66 +++++++++---------- 2 files changed, 60 insertions(+), 72 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameRequestStream.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameRequestStream.cs index 652f2bbd4b..2c19b40dd8 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameRequestStream.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameRequestStream.cs @@ -11,8 +11,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http public class FrameRequestStream : Stream { private readonly MessageBody _body; - private bool _stopped; - private bool _aborted; + private StreamState _state; public FrameRequestStream(MessageBody body) { @@ -52,14 +51,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http public override int Read(byte[] buffer, int offset, int count) { - if (_stopped) - { - throw new ObjectDisposedException(nameof(FrameRequestStream)); - } - if (_aborted) - { - throw new IOException("The request has been aborted."); - } + ValidateState(); return ReadAsync(buffer, offset, count).GetAwaiter().GetResult(); } @@ -67,14 +59,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http #if NET451 public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback callback, object state) { - if (_stopped) - { - throw new ObjectDisposedException(nameof(FrameRequestStream)); - } - if (_aborted) - { - throw new IOException("The request has been aborted."); - } + ValidateState(); var task = ReadAsync(buffer, offset, count, CancellationToken.None, state); if (callback != null) @@ -91,14 +76,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http private Task ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken, object state) { - if (_stopped) - { - throw new ObjectDisposedException(nameof(FrameRequestStream)); - } - if (_aborted) - { - throw new IOException("The request has been aborted."); - } + ValidateState(); var tcs = new TaskCompletionSource(state); var task = _body.ReadAsync(new ArraySegment(buffer, offset, count), cancellationToken); @@ -124,14 +102,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http public override Task ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) { - if (_stopped) - { - throw new ObjectDisposedException(nameof(FrameRequestStream)); - } - if (_aborted) - { - throw new IOException("The request has been aborted."); - } + ValidateState(); return _body.ReadAsync(new ArraySegment(buffer, offset, count), cancellationToken); } @@ -145,14 +116,37 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { // Can't use dispose (or close) as can be disposed too early by user code // As exampled in EngineTests.ZeroContentLengthNotSetAutomaticallyForCertainStatusCodes - _stopped = true; + _state = StreamState.Disposed; } public void Abort() { // We don't want to throw an ODE until the app func actually completes. // If the request is aborted, we throw an IOException instead. - _aborted = true; + if (_state != StreamState.Disposed) + { + _state = StreamState.Aborted; + } + } + + private void ValidateState() + { + switch (_state) + { + case StreamState.Open: + return; + case StreamState.Disposed: + throw new ObjectDisposedException(nameof(FrameRequestStream)); + case StreamState.Aborted: + throw new IOException("The request has been aborted."); + } + } + + private enum StreamState + { + Open, + Disposed, + Aborted } } } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameResponseStream.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameResponseStream.cs index 25b8a72cfe..827234f872 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameResponseStream.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameResponseStream.cs @@ -11,8 +11,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http class FrameResponseStream : Stream { private readonly FrameContext _context; - private bool _stopped; - private bool _aborted; + private StreamState _state; public FrameResponseStream(FrameContext context) { @@ -37,28 +36,14 @@ namespace Microsoft.AspNet.Server.Kestrel.Http public override void Flush() { - if (_stopped) - { - throw new ObjectDisposedException(nameof(FrameResponseStream)); - } - if (_aborted) - { - throw new IOException("The request has been aborted."); - } + ValidateState(); _context.FrameControl.Flush(); } public override Task FlushAsync(CancellationToken cancellationToken) { - if (_stopped) - { - throw new ObjectDisposedException(nameof(FrameResponseStream)); - } - if (_aborted) - { - throw new IOException("The request has been aborted."); - } + ValidateState(); return _context.FrameControl.FlushAsync(cancellationToken); } @@ -80,28 +65,14 @@ namespace Microsoft.AspNet.Server.Kestrel.Http public override void Write(byte[] buffer, int offset, int count) { - if (_stopped) - { - throw new ObjectDisposedException(nameof(FrameResponseStream)); - } - if (_aborted) - { - throw new IOException("The request has been aborted."); - } + ValidateState(); _context.FrameControl.Write(new ArraySegment(buffer, offset, count)); } public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) { - if (_stopped) - { - throw new ObjectDisposedException(nameof(FrameResponseStream)); - } - if (_aborted) - { - throw new IOException("The request has been aborted."); - } + ValidateState(); return _context.FrameControl.WriteAsync(new ArraySegment(buffer, offset, count), cancellationToken); } @@ -110,14 +81,37 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { // Can't use dispose (or close) as can be disposed too early by user code // As exampled in EngineTests.ZeroContentLengthNotSetAutomaticallyForCertainStatusCodes - _stopped = true; + _state = StreamState.Disposed; } public void Abort() { // We don't want to throw an ODE until the app func actually completes. // If the request is aborted, we throw an IOException instead. - _aborted = true; + if (_state != StreamState.Disposed) + { + _state = StreamState.Aborted; + } + } + + private void ValidateState() + { + switch (_state) + { + case StreamState.Open: + return; + case StreamState.Disposed: + throw new ObjectDisposedException(nameof(FrameResponseStream)); + case StreamState.Aborted: + throw new IOException("The request has been aborted."); + } + } + + private enum StreamState + { + Open, + Disposed, + Aborted } } } From 12ee74c09c78ba8ae2987e8ea338e9e444201baa Mon Sep 17 00:00:00 2001 From: Kristian Hellang Date: Mon, 7 Dec 2015 22:00:03 +0100 Subject: [PATCH 0496/1662] server.threadCount -> kestre.threadCount --- src/Microsoft.AspNet.Server.Kestrel/KestrelServerInformation.cs | 2 +- .../KestrelServerInformationTests.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/KestrelServerInformation.cs b/src/Microsoft.AspNet.Server.Kestrel/KestrelServerInformation.cs index 84b2fcab57..acbfc685e5 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/KestrelServerInformation.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/KestrelServerInformation.cs @@ -42,7 +42,7 @@ namespace Microsoft.AspNet.Server.Kestrel private static int GetThreadCount(IConfiguration configuration) { - var threadCountString = configuration["server.threadCount"]; + var threadCountString = configuration["kestrel.threadCount"]; int threadCount; if (string.IsNullOrEmpty(threadCountString) || !int.TryParse(threadCountString, out threadCount)) diff --git a/test/Microsoft.AspNet.Server.KestrelTests/KestrelServerInformationTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/KestrelServerInformationTests.cs index 2a3285da9f..91e9a419f0 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/KestrelServerInformationTests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/KestrelServerInformationTests.cs @@ -18,7 +18,7 @@ namespace Microsoft.AspNet.Server.KestrelTests var values = new Dictionary { - { "server.threadCount", expected.ToString() } + { "kestrel.threadCount", expected.ToString() } }; var configuration = new ConfigurationBuilder() From 8d6a999bc3c3bee6043abea3b975c4987e54fc3d Mon Sep 17 00:00:00 2001 From: Kristian Hellang Date: Mon, 7 Dec 2015 22:09:04 +0100 Subject: [PATCH 0497/1662] Made NoDelay configurable --- .../KestrelServerInformation.cs | 20 ++++++++++++++++++- .../KestrelServerInformationTests.cs | 17 ++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/KestrelServerInformation.cs b/src/Microsoft.AspNet.Server.Kestrel/KestrelServerInformation.cs index acbfc685e5..222a0991f3 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/KestrelServerInformation.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/KestrelServerInformation.cs @@ -15,7 +15,7 @@ namespace Microsoft.AspNet.Server.Kestrel { Addresses = GetAddresses(configuration); ThreadCount = GetThreadCount(configuration); - NoDelay = true; + NoDelay = GetNoDelay(configuration); } public ICollection Addresses { get; } @@ -68,5 +68,23 @@ namespace Microsoft.AspNet.Server.Kestrel return threadCount; } + + private static bool GetNoDelay(IConfiguration configuration) + { + var noDelayString = configuration["kestrel.noDelay"]; + + if (string.IsNullOrEmpty(noDelayString)) + { + return true; + } + + bool noDelay; + if (bool.TryParse(noDelayString, out noDelay)) + { + return noDelay; + } + + return true; + } } } diff --git a/test/Microsoft.AspNet.Server.KestrelTests/KestrelServerInformationTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/KestrelServerInformationTests.cs index 91e9a419f0..1c56258554 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/KestrelServerInformationTests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/KestrelServerInformationTests.cs @@ -62,6 +62,23 @@ namespace Microsoft.AspNet.Server.KestrelTests Assert.Equal(expected, information.Addresses); } + [Fact] + public void SetNoDelayUsingConfiguration() + { + var values = new Dictionary + { + { "kestrel.noDelay", "false" } + }; + + var configuration = new ConfigurationBuilder() + .AddInMemoryCollection(values) + .Build(); + + var information = new KestrelServerInformation(configuration); + + Assert.False(information.NoDelay); + } + private static int Clamp(int value, int min, int max) { return value < min ? min : value > max ? max : value; From 4c68807a0549d650c231b72f282945abd9699ce2 Mon Sep 17 00:00:00 2001 From: Kristian Hellang Date: Mon, 7 Dec 2015 22:14:05 +0100 Subject: [PATCH 0498/1662] Split out ProcessorThreadCount, added InvariantCulture to TryParse --- .../KestrelServerInformation.cs | 56 ++++++++++++------- 1 file changed, 36 insertions(+), 20 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/KestrelServerInformation.cs b/src/Microsoft.AspNet.Server.Kestrel/KestrelServerInformation.cs index 222a0991f3..3808b6144b 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/KestrelServerInformation.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/KestrelServerInformation.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; +using System.Globalization; using Microsoft.AspNet.Server.Features; using Microsoft.AspNet.Server.Kestrel.Filter; using Microsoft.Extensions.Configuration; @@ -26,6 +27,32 @@ namespace Microsoft.AspNet.Server.Kestrel public IConnectionFilter ConnectionFilter { get; set; } + private static int ProcessorThreadCount + { + get + { + // Actual core count would be a better number + // rather than logical cores which includes hyper-threaded cores. + // Divide by 2 for hyper-threading, and good defaults (still need threads to do webserving). + var threadCount = Environment.ProcessorCount >> 1; + + if (threadCount < 1) + { + // Ensure shifted value is at least one + return 1; + } + + if (threadCount > 16) + { + // Receive Side Scaling RSS Processor count currently maxes out at 16 + // would be better to check the NIC's current hardware queues; but xplat... + return 16; + } + + return threadCount; + } + } + private static ICollection GetAddresses(IConfiguration configuration) { var addresses = new List(); @@ -44,29 +71,18 @@ namespace Microsoft.AspNet.Server.Kestrel { var threadCountString = configuration["kestrel.threadCount"]; - int threadCount; - if (string.IsNullOrEmpty(threadCountString) || !int.TryParse(threadCountString, out threadCount)) + if (string.IsNullOrEmpty(threadCountString)) { - // Actual core count would be a better number - // rather than logical cores which includes hyper-threaded cores. - // Divide by 2 for hyper-threading, and good defaults (still need threads to do webserving). - threadCount = Environment.ProcessorCount >> 1; - - if (threadCount < 1) - { - // Ensure shifted value is at least one - return 1; - } - - if (threadCount > 16) - { - // Receive Side Scaling RSS Processor count currently maxes out at 16 - // would be better to check the NIC's current hardware queues; but xplat... - return 16; - } + return ProcessorThreadCount; } - return threadCount; + int threadCount; + if (int.TryParse(threadCountString, NumberStyles.Integer, CultureInfo.InvariantCulture, out threadCount)) + { + return threadCount; + } + + return ProcessorThreadCount; } private static bool GetNoDelay(IConfiguration configuration) From dff3a4f2314808b2724d73002017d6b80dd64343 Mon Sep 17 00:00:00 2001 From: John Luo Date: Mon, 7 Dec 2015 17:42:13 -0800 Subject: [PATCH 0499/1662] Reacting to verbose rename --- samples/SampleApp/Startup.cs | 2 +- src/Microsoft.AspNet.Server.Kestrel/Filter/LoggingStream.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/samples/SampleApp/Startup.cs b/samples/SampleApp/Startup.cs index 72bc9e5a9c..b6004d9c0c 100644 --- a/samples/SampleApp/Startup.cs +++ b/samples/SampleApp/Startup.cs @@ -22,7 +22,7 @@ namespace SampleApp //ksi.ThreadCount = 4; ksi.NoDelay = true; - loggerFactory.AddConsole(LogLevel.Debug); + loggerFactory.AddConsole(LogLevel.Trace); var testCertPath = Path.Combine( env.ApplicationBasePath, diff --git a/src/Microsoft.AspNet.Server.Kestrel/Filter/LoggingStream.cs b/src/Microsoft.AspNet.Server.Kestrel/Filter/LoggingStream.cs index 41787c26ca..efec582245 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Filter/LoggingStream.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Filter/LoggingStream.cs @@ -123,7 +123,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Filter builder.Append((char)buffer[i]); } - _logger.LogVerbose(builder.ToString()); + _logger.LogDebug(builder.ToString()); } } } From d0dca75241351560abef6c808ccd9aa4b5ac9d5c Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Tue, 1 Dec 2015 11:47:39 -0800 Subject: [PATCH 0500/1662] Remove count parameter from ISocketOutput.ProducingComplete - This makes the calling code cleaner with a (hopefully) minimal pref impact --- .../Filter/StreamSocketOutput.cs | 2 +- .../Http/Frame.cs | 10 +- .../Http/FrameHeaders.Generated.cs | 134 +++++++++--------- .../Http/FrameResponseHeaders.cs | 13 +- .../Http/ISocketOutput.cs | 3 +- .../Http/SocketOutput.cs | 103 +++++++------- .../Infrastructure/MemoryPoolIterator2.cs | 16 +-- .../SocketOutputTests.cs | 4 +- .../KnownHeaders.cs | 10 +- 9 files changed, 144 insertions(+), 151 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Filter/StreamSocketOutput.cs b/src/Microsoft.AspNet.Server.Kestrel/Filter/StreamSocketOutput.cs index d2c1deae3b..cbcb99f3a9 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Filter/StreamSocketOutput.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Filter/StreamSocketOutput.cs @@ -42,7 +42,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Filter return new MemoryPoolIterator2(_producingBlock); } - public void ProducingComplete(MemoryPoolIterator2 end, int count) + public void ProducingComplete(MemoryPoolIterator2 end) { var block = _producingBlock; while (block != end.Block) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs index 008e1a905e..9870a5ab46 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs @@ -674,12 +674,12 @@ namespace Microsoft.AspNet.Server.Kestrel.Http _responseHeaders.SetRawConnection("keep-alive", _bytesConnectionKeepAlive); } - count += end.CopyFrom(_httpVersion == HttpVersionType.Http1_1 ? _bytesHttpVersion1_1 : _bytesHttpVersion1_0); - count += end.CopyFrom(statusBytes); - count += _responseHeaders.CopyTo(ref end); - count += end.CopyFrom(_bytesEndHeaders, 0, _bytesEndHeaders.Length); + end.CopyFrom(_httpVersion == HttpVersionType.Http1_1 ? _bytesHttpVersion1_1 : _bytesHttpVersion1_0); + end.CopyFrom(statusBytes); + _responseHeaders.CopyTo(ref end); + end.CopyFrom(_bytesEndHeaders, 0, _bytesEndHeaders.Length); - SocketOutput.ProducingComplete(end, count); + SocketOutput.ProducingComplete(end); if (immediate) { diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameHeaders.Generated.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameHeaders.Generated.cs index bc7f4d0caa..5571e9c56b 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameHeaders.Generated.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameHeaders.Generated.cs @@ -7821,16 +7821,15 @@ namespace Microsoft.AspNet.Server.Kestrel.Http ((ICollection>)MaybeUnknown)?.CopyTo(array, arrayIndex); } - protected int CopyToFast(ref MemoryPoolIterator2 output) + protected void CopyToFast(ref MemoryPoolIterator2 output) { - var count = 0; if (((_bits & 1L) != 0)) { foreach(var value in _CacheControl) { - count += output.CopyFrom(_headerBytes, 0, 17); - count += output.CopyFromAscii(value); + output.CopyFrom(_headerBytes, 0, 17); + output.CopyFromAscii(value); } } @@ -7838,12 +7837,12 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { if (_rawConnection != null) { - count += output.CopyFrom(_rawConnection, 0, _rawConnection.Length); + output.CopyFrom(_rawConnection, 0, _rawConnection.Length); } else foreach(var value in _Connection) { - count += output.CopyFrom(_headerBytes, 17, 14); - count += output.CopyFromAscii(value); + output.CopyFrom(_headerBytes, 17, 14); + output.CopyFromAscii(value); } } @@ -7851,12 +7850,12 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { if (_rawDate != null) { - count += output.CopyFrom(_rawDate, 0, _rawDate.Length); + output.CopyFrom(_rawDate, 0, _rawDate.Length); } else foreach(var value in _Date) { - count += output.CopyFrom(_headerBytes, 31, 8); - count += output.CopyFromAscii(value); + output.CopyFrom(_headerBytes, 31, 8); + output.CopyFromAscii(value); } } @@ -7864,8 +7863,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { foreach(var value in _KeepAlive) { - count += output.CopyFrom(_headerBytes, 39, 14); - count += output.CopyFromAscii(value); + output.CopyFrom(_headerBytes, 39, 14); + output.CopyFromAscii(value); } } @@ -7873,8 +7872,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { foreach(var value in _Pragma) { - count += output.CopyFrom(_headerBytes, 53, 10); - count += output.CopyFromAscii(value); + output.CopyFrom(_headerBytes, 53, 10); + output.CopyFromAscii(value); } } @@ -7882,8 +7881,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { foreach(var value in _Trailer) { - count += output.CopyFrom(_headerBytes, 63, 11); - count += output.CopyFromAscii(value); + output.CopyFrom(_headerBytes, 63, 11); + output.CopyFromAscii(value); } } @@ -7891,12 +7890,12 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { if (_rawTransferEncoding != null) { - count += output.CopyFrom(_rawTransferEncoding, 0, _rawTransferEncoding.Length); + output.CopyFrom(_rawTransferEncoding, 0, _rawTransferEncoding.Length); } else foreach(var value in _TransferEncoding) { - count += output.CopyFrom(_headerBytes, 74, 21); - count += output.CopyFromAscii(value); + output.CopyFrom(_headerBytes, 74, 21); + output.CopyFromAscii(value); } } @@ -7904,8 +7903,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { foreach(var value in _Upgrade) { - count += output.CopyFrom(_headerBytes, 95, 11); - count += output.CopyFromAscii(value); + output.CopyFrom(_headerBytes, 95, 11); + output.CopyFromAscii(value); } } @@ -7913,8 +7912,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { foreach(var value in _Via) { - count += output.CopyFrom(_headerBytes, 106, 7); - count += output.CopyFromAscii(value); + output.CopyFrom(_headerBytes, 106, 7); + output.CopyFromAscii(value); } } @@ -7922,8 +7921,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { foreach(var value in _Warning) { - count += output.CopyFrom(_headerBytes, 113, 11); - count += output.CopyFromAscii(value); + output.CopyFrom(_headerBytes, 113, 11); + output.CopyFromAscii(value); } } @@ -7931,8 +7930,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { foreach(var value in _Allow) { - count += output.CopyFrom(_headerBytes, 124, 9); - count += output.CopyFromAscii(value); + output.CopyFrom(_headerBytes, 124, 9); + output.CopyFromAscii(value); } } @@ -7940,12 +7939,12 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { if (_rawContentLength != null) { - count += output.CopyFrom(_rawContentLength, 0, _rawContentLength.Length); + output.CopyFrom(_rawContentLength, 0, _rawContentLength.Length); } else foreach(var value in _ContentLength) { - count += output.CopyFrom(_headerBytes, 133, 18); - count += output.CopyFromAscii(value); + output.CopyFrom(_headerBytes, 133, 18); + output.CopyFromAscii(value); } } @@ -7953,8 +7952,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { foreach(var value in _ContentType) { - count += output.CopyFrom(_headerBytes, 151, 16); - count += output.CopyFromAscii(value); + output.CopyFrom(_headerBytes, 151, 16); + output.CopyFromAscii(value); } } @@ -7962,8 +7961,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { foreach(var value in _ContentEncoding) { - count += output.CopyFrom(_headerBytes, 167, 20); - count += output.CopyFromAscii(value); + output.CopyFrom(_headerBytes, 167, 20); + output.CopyFromAscii(value); } } @@ -7971,8 +7970,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { foreach(var value in _ContentLanguage) { - count += output.CopyFrom(_headerBytes, 187, 20); - count += output.CopyFromAscii(value); + output.CopyFrom(_headerBytes, 187, 20); + output.CopyFromAscii(value); } } @@ -7980,8 +7979,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { foreach(var value in _ContentLocation) { - count += output.CopyFrom(_headerBytes, 207, 20); - count += output.CopyFromAscii(value); + output.CopyFrom(_headerBytes, 207, 20); + output.CopyFromAscii(value); } } @@ -7989,8 +7988,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { foreach(var value in _ContentMD5) { - count += output.CopyFrom(_headerBytes, 227, 15); - count += output.CopyFromAscii(value); + output.CopyFrom(_headerBytes, 227, 15); + output.CopyFromAscii(value); } } @@ -7998,8 +7997,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { foreach(var value in _ContentRange) { - count += output.CopyFrom(_headerBytes, 242, 17); - count += output.CopyFromAscii(value); + output.CopyFrom(_headerBytes, 242, 17); + output.CopyFromAscii(value); } } @@ -8007,8 +8006,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { foreach(var value in _Expires) { - count += output.CopyFrom(_headerBytes, 259, 11); - count += output.CopyFromAscii(value); + output.CopyFrom(_headerBytes, 259, 11); + output.CopyFromAscii(value); } } @@ -8016,8 +8015,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { foreach(var value in _LastModified) { - count += output.CopyFrom(_headerBytes, 270, 17); - count += output.CopyFromAscii(value); + output.CopyFrom(_headerBytes, 270, 17); + output.CopyFromAscii(value); } } @@ -8025,8 +8024,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { foreach(var value in _AcceptRanges) { - count += output.CopyFrom(_headerBytes, 287, 17); - count += output.CopyFromAscii(value); + output.CopyFrom(_headerBytes, 287, 17); + output.CopyFromAscii(value); } } @@ -8034,8 +8033,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { foreach(var value in _Age) { - count += output.CopyFrom(_headerBytes, 304, 7); - count += output.CopyFromAscii(value); + output.CopyFrom(_headerBytes, 304, 7); + output.CopyFromAscii(value); } } @@ -8043,8 +8042,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { foreach(var value in _ETag) { - count += output.CopyFrom(_headerBytes, 311, 8); - count += output.CopyFromAscii(value); + output.CopyFrom(_headerBytes, 311, 8); + output.CopyFromAscii(value); } } @@ -8052,8 +8051,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { foreach(var value in _Location) { - count += output.CopyFrom(_headerBytes, 319, 12); - count += output.CopyFromAscii(value); + output.CopyFrom(_headerBytes, 319, 12); + output.CopyFromAscii(value); } } @@ -8061,8 +8060,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { foreach(var value in _ProxyAutheticate) { - count += output.CopyFrom(_headerBytes, 331, 21); - count += output.CopyFromAscii(value); + output.CopyFrom(_headerBytes, 331, 21); + output.CopyFromAscii(value); } } @@ -8070,8 +8069,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { foreach(var value in _RetryAfter) { - count += output.CopyFrom(_headerBytes, 352, 15); - count += output.CopyFromAscii(value); + output.CopyFrom(_headerBytes, 352, 15); + output.CopyFromAscii(value); } } @@ -8079,12 +8078,12 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { if (_rawServer != null) { - count += output.CopyFrom(_rawServer, 0, _rawServer.Length); + output.CopyFrom(_rawServer, 0, _rawServer.Length); } else foreach(var value in _Server) { - count += output.CopyFrom(_headerBytes, 367, 10); - count += output.CopyFromAscii(value); + output.CopyFrom(_headerBytes, 367, 10); + output.CopyFromAscii(value); } } @@ -8092,8 +8091,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { foreach(var value in _SetCookie) { - count += output.CopyFrom(_headerBytes, 377, 14); - count += output.CopyFromAscii(value); + output.CopyFrom(_headerBytes, 377, 14); + output.CopyFromAscii(value); } } @@ -8101,8 +8100,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { foreach(var value in _Vary) { - count += output.CopyFrom(_headerBytes, 391, 8); - count += output.CopyFromAscii(value); + output.CopyFrom(_headerBytes, 391, 8); + output.CopyFromAscii(value); } } @@ -8110,12 +8109,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { foreach(var value in _WWWAuthenticate) { - count += output.CopyFrom(_headerBytes, 399, 20); - count += output.CopyFromAscii(value); + output.CopyFrom(_headerBytes, 399, 20); + output.CopyFromAscii(value); } } - return count; } public unsafe void Append(byte[] keyBytes, int keyOffset, int keyLength, string value) { diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameResponseHeaders.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameResponseHeaders.cs index 30c75fe4e2..693c58e912 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameResponseHeaders.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameResponseHeaders.cs @@ -30,23 +30,22 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return GetEnumerator(); } - public int CopyTo(ref MemoryPoolIterator2 output) + public void CopyTo(ref MemoryPoolIterator2 output) { - var count = CopyToFast(ref output); + CopyToFast(ref output); if (MaybeUnknown != null) { foreach (var kv in MaybeUnknown) { foreach (var value in kv.Value) { - count += output.CopyFrom(_CrLf, 0, 2); - count += output.CopyFromAscii(kv.Key); - count += output.CopyFrom(_colonSpace, 0, 2); - count += output.CopyFromAscii(value); + output.CopyFrom(_CrLf, 0, 2); + output.CopyFromAscii(kv.Key); + output.CopyFrom(_colonSpace, 0, 2); + output.CopyFromAscii(value); } } } - return count; } public partial struct Enumerator : IEnumerator> diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/ISocketOutput.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/ISocketOutput.cs index 1ec17d269b..597326ca82 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/ISocketOutput.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/ISocketOutput.cs @@ -30,7 +30,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Http /// or is called afterwards. /// /// Points to the end of the committed data. - /// The number of bytes added to the response. - void ProducingComplete(MemoryPoolIterator2 end, int count); + void ProducingComplete(MemoryPoolIterator2 end); } } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs index 64c5808efb..82242f039a 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs @@ -19,6 +19,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http private const int _initialTaskQueues = 64; private static WaitCallback _returnBlocks = (state) => ReturnBlocks((MemoryPoolBlock2)state); + private static MemoryPoolIterator2 _defaultIterator; private readonly KestrelThread _thread; private readonly UvStreamHandle _socket; @@ -34,8 +35,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http private MemoryPoolBlock2 _head; private MemoryPoolBlock2 _tail; - private bool _isProducing; - private MemoryPoolBlock2 _returnFromOnProducingComplete; + private MemoryPoolIterator2 _lastStart; // This locks access to to all of the below fields private readonly object _contextLock = new object(); @@ -83,7 +83,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http var tail = ProducingStart(); tail.CopyFrom(buffer); // We do our own accounting below - ProducingComplete(tail, count: 0); + ProducingCompleteNoPreComplete(tail); } TaskCompletionSource tcs = null; @@ -165,54 +165,57 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { lock (_returnLock) { - Debug.Assert(!_isProducing); - _isProducing = true; + Debug.Assert(_lastStart.IsDefault); if (_tail == null) { throw new IOException("The socket has been closed."); } - return new MemoryPoolIterator2(_tail, _tail.End); + _lastStart = new MemoryPoolIterator2(_tail, _tail.End); + + return _lastStart; } } - public void ProducingComplete(MemoryPoolIterator2 end, int count) + public void ProducingComplete(MemoryPoolIterator2 end) + { + Debug.Assert(!_lastStart.IsDefault); + + int bytesProduced, buffersIncluded; + BytesBetween(_lastStart, end, out bytesProduced, out buffersIncluded); + + lock (_contextLock) + { + _numBytesPreCompleted += bytesProduced; + } + + ProducingCompleteNoPreComplete(end); + } + + private void ProducingCompleteNoPreComplete(MemoryPoolIterator2 end) { - var decreasePreCompleted = false; MemoryPoolBlock2 blockToReturn = null; lock (_returnLock) { - Debug.Assert(_isProducing); - _isProducing = false; + Debug.Assert(!_lastStart.IsDefault); - if (_returnFromOnProducingComplete == null) + // If the socket has been closed, return the produced blocks + // instead of advancing the now non-existent tail. + if (_tail != null) { _tail = end.Block; _tail.End = end.Index; - - if (count != 0) - { - decreasePreCompleted = true; - } } else { - blockToReturn = _returnFromOnProducingComplete; - _returnFromOnProducingComplete = null; + blockToReturn = _lastStart.Block; } - } - if (decreasePreCompleted) - { - lock (_contextLock) - { - _numBytesPreCompleted += count; - } + _lastStart = _defaultIterator; } - if (blockToReturn != null) { ThreadPool.QueueUserWorkItem(_returnBlocks, blockToReturn); @@ -354,11 +357,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http returnBlock.Pool?.Return(returnBlock); } - if (_isProducing) - { - _returnFromOnProducingComplete = _tail; - } - else + // Only return the _tail if we aren't between ProducingStart/Complete calls + if (_lastStart.IsDefault) { _tail.Pool?.Return(_tail); } @@ -387,6 +387,28 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return WriteAsync(buffer, immediate); } + private static void BytesBetween(MemoryPoolIterator2 start, MemoryPoolIterator2 end, out int bytes, out int buffers) + { + if (start.Block == end.Block) + { + bytes = end.Index - start.Index; + buffers = 1; + return; + } + + bytes = start.Block.Data.Offset + start.Block.Data.Count - start.Index; + buffers = 1; + + for (var block = start.Block.Next; block != end.Block; block = block.Next) + { + bytes += block.Data.Count; + buffers++; + } + + bytes += end.Index - end.Block.Data.Offset; + buffers++; + } + private class WriteContext { private static WaitCallback _returnWrittenBlocks = (state) => ReturnWrittenBlocks((MemoryPoolBlock2)state); @@ -535,24 +557,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http _lockedStart = new MemoryPoolIterator2(head, head.Start); _lockedEnd = new MemoryPoolIterator2(tail, tail.End); - if (_lockedStart.Block == _lockedEnd.Block) - { - _byteCount = _lockedEnd.Index - _lockedStart.Index; - _bufferCount = 1; - return; - } - - _byteCount = _lockedStart.Block.Data.Offset + _lockedStart.Block.Data.Count - _lockedStart.Index; - _bufferCount = 1; - - for (var block = _lockedStart.Block.Next; block != _lockedEnd.Block; block = block.Next) - { - _byteCount += block.Data.Count; - _bufferCount++; - } - - _byteCount += _lockedEnd.Index - _lockedEnd.Block.Data.Offset; - _bufferCount++; + BytesBetween(_lockedStart, _lockedEnd, out _byteCount, out _bufferCount); } } } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolIterator2.cs b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolIterator2.cs index 9af9d4428e..41551d056c 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolIterator2.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolIterator2.cs @@ -532,17 +532,17 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure } } - public int CopyFrom(byte[] data) + public void CopyFrom(byte[] data) { - return CopyFrom(new ArraySegment(data)); + CopyFrom(new ArraySegment(data)); } - public int CopyFrom(byte[] data, int offset, int count) + public void CopyFrom(byte[] data, int offset, int count) { - return CopyFrom(new ArraySegment(data, offset, count)); + CopyFrom(new ArraySegment(data, offset, count)); } - public int CopyFrom(ArraySegment buffer) + public void CopyFrom(ArraySegment buffer) { Debug.Assert(_block != null); Debug.Assert(_block.Pool != null); @@ -582,11 +582,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure _block = block; _index = blockIndex; - - return buffer.Count; } - public unsafe int CopyFromAscii(string data) + public unsafe void CopyFromAscii(string data) { Debug.Assert(_block != null); Debug.Assert(_block.Pool != null); @@ -649,8 +647,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure _block = block; _index = blockIndex; - - return length; } } } diff --git a/test/Microsoft.AspNet.Server.KestrelTests/SocketOutputTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/SocketOutputTests.cs index dca77cf881..d5f86b76aa 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/SocketOutputTests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/SocketOutputTests.cs @@ -309,17 +309,15 @@ namespace Microsoft.AspNet.Server.KestrelTests // block 1 var start = socketOutput.ProducingStart(); start.Block.End = start.Block.Data.Offset + start.Block.Data.Count; - var totalBytes = start.Block.Data.Count; // block 2 var block2 = memory.Lease(); block2.End = block2.Data.Offset + block2.Data.Count; start.Block.Next = block2; - totalBytes += block2.Data.Count; var end = new MemoryPoolIterator2(block2, block2.End); - socketOutput.ProducingComplete(end, totalBytes); + socketOutput.ProducingComplete(end); // A call to Write is required to ensure a write is scheduled socketOutput.WriteAsync(default(ArraySegment)); diff --git a/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/KnownHeaders.cs b/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/KnownHeaders.cs index 214cf91f6b..aaf19e8300 100644 --- a/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/KnownHeaders.cs +++ b/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/KnownHeaders.cs @@ -380,24 +380,22 @@ namespace Microsoft.AspNet.Server.Kestrel.Http ((ICollection>)MaybeUnknown)?.CopyTo(array, arrayIndex); }} {(loop.ClassName == "FrameResponseHeaders" ? $@" - protected int CopyToFast(ref MemoryPoolIterator2 output) + protected void CopyToFast(ref MemoryPoolIterator2 output) {{ - var count = 0; {Each(loop.Headers, header => $@" if ({header.TestBit()}) {{ {(header.EnhancedSetter == false ? "" : $@" if (_raw{header.Identifier} != null) {{ - count += output.CopyFrom(_raw{header.Identifier}, 0, _raw{header.Identifier}.Length); + output.CopyFrom(_raw{header.Identifier}, 0, _raw{header.Identifier}.Length); }} else ")} foreach(var value in _{header.Identifier}) {{ - count += output.CopyFrom(_headerBytes, {header.BytesOffset}, {header.BytesCount}); - count += output.CopyFromAscii(value); + output.CopyFrom(_headerBytes, {header.BytesOffset}, {header.BytesCount}); + output.CopyFromAscii(value); }} }} ")} - return count; }}" : "")} public unsafe void Append(byte[] keyBytes, int keyOffset, int keyLength, string value) {{ From 6fbc3b88321cae3e5b96c790c3cdbc388ccf54b1 Mon Sep 17 00:00:00 2001 From: Kristian Hellang Date: Tue, 8 Dec 2015 10:58:42 +0100 Subject: [PATCH 0501/1662] Added null check in KestrelServerInformation --- .../KestrelServerInformation.cs | 5 +++++ .../KestrelServerInformationTests.cs | 6 ++++++ 2 files changed, 11 insertions(+) diff --git a/src/Microsoft.AspNet.Server.Kestrel/KestrelServerInformation.cs b/src/Microsoft.AspNet.Server.Kestrel/KestrelServerInformation.cs index 3808b6144b..f9f4ae8c8e 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/KestrelServerInformation.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/KestrelServerInformation.cs @@ -14,6 +14,11 @@ namespace Microsoft.AspNet.Server.Kestrel { public KestrelServerInformation(IConfiguration configuration) { + if (configuration == null) + { + throw new ArgumentNullException(nameof(configuration)); + } + Addresses = GetAddresses(configuration); ThreadCount = GetThreadCount(configuration); NoDelay = GetNoDelay(configuration); diff --git a/test/Microsoft.AspNet.Server.KestrelTests/KestrelServerInformationTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/KestrelServerInformationTests.cs index 1c56258554..2513d93e84 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/KestrelServerInformationTests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/KestrelServerInformationTests.cs @@ -11,6 +11,12 @@ namespace Microsoft.AspNet.Server.KestrelTests { public class KestrelServerInformationTests { + [Fact] + public void NullConfigurationThrows() + { + Assert.Throws(() => new KestrelServerInformation(null)); + } + [Fact] public void SetThreadCountUsingConfiguration() { From dd02a1c442cd058c611a1e4703eef3bc89763421 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Tue, 8 Dec 2015 17:31:57 -0800 Subject: [PATCH 0502/1662] Fix compiler warnings --- src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs | 1 - src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs | 3 +-- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs index 9870a5ab46..ba4a7ba84d 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs @@ -625,7 +625,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Http bool immediate) { var begin = SocketOutput.ProducingStart(); - var count = 0; var end = begin; if (_keepAlive) { diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs index 82242f039a..13c690d246 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs @@ -19,7 +19,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Http private const int _initialTaskQueues = 64; private static WaitCallback _returnBlocks = (state) => ReturnBlocks((MemoryPoolBlock2)state); - private static MemoryPoolIterator2 _defaultIterator; private readonly KestrelThread _thread; private readonly UvStreamHandle _socket; @@ -213,7 +212,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http blockToReturn = _lastStart.Block; } - _lastStart = _defaultIterator; + _lastStart = default(MemoryPoolIterator2); } if (blockToReturn != null) From 4cc070fe28e9f43599c0532b1726fbcaa33b3d33 Mon Sep 17 00:00:00 2001 From: Kristian Hellang Date: Tue, 8 Dec 2015 10:59:34 +0100 Subject: [PATCH 0503/1662] Added some KestrelServer tests --- .../KestrelServerTests.cs | 82 +++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 test/Microsoft.AspNet.Server.KestrelTests/KestrelServerTests.cs diff --git a/test/Microsoft.AspNet.Server.KestrelTests/KestrelServerTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/KestrelServerTests.cs new file mode 100644 index 0000000000..23e2ff68a7 --- /dev/null +++ b/test/Microsoft.AspNet.Server.KestrelTests/KestrelServerTests.cs @@ -0,0 +1,82 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using Microsoft.AspNet.Hosting.Server; +using Microsoft.AspNet.Http.Features; +using Microsoft.AspNet.Server.Kestrel; +using Microsoft.AspNet.Server.Kestrel.Infrastructure; +using Microsoft.Extensions.Configuration; +using Xunit; + +namespace Microsoft.AspNet.Server.KestrelTests +{ + public class KestrelServerTests + { + [Theory] + [InlineData(0)] + [InlineData(-1337)] + public void StartWithNonPositiveThreadCountThrows(int threadCount) + { + var server = CreateServer(configuration => + new KestrelServerInformation(configuration) + { + ThreadCount = threadCount + }); + + var exception = Assert.Throws(() => StartDummyApplication(server)); + + Assert.Equal("threadCount", exception.ParamName); + } + + [Fact] + public void StartWithInvalidAddressThrows() + { + var server = CreateServer(configuration => + new KestrelServerInformation(configuration) + { + Addresses = {"http:/asdf"} + }); + + var exception = Assert.Throws(() => StartDummyApplication(server)); + + Assert.Contains("Unrecognized listening address", exception.Message); + } + + [Fact] + public void StartWithEmptyAddressesThrows() + { + var server = CreateServer(configuration => + { + var information = new KestrelServerInformation(configuration); + + information.Addresses.Clear(); + + return information; + }); + + var exception = Assert.Throws(() => StartDummyApplication(server)); + + Assert.Equal("No recognized listening addresses were configured.", exception.Message); + } + + private static KestrelServer CreateServer(Func serverInformationFactory) + { + var configuration = new ConfigurationBuilder().Build(); + var information = serverInformationFactory(configuration); + + var features = new FeatureCollection(); + features.Set(information); + + var lifetime = new LifetimeNotImplemented(); + var logger = new TestKestrelTrace.TestLogger(); + + return new KestrelServer(features, lifetime, logger); + } + + private static void StartDummyApplication(IServer server) + { + server.Start(new DummyApplication(context => TaskUtilities.CompletedTask)); + } + } +} From 3e2c090d7cec12cca74cf0bd906322317ce457c4 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Wed, 9 Dec 2015 15:48:04 -0800 Subject: [PATCH 0504/1662] Skip more tests on Mono to prevent hangs - It seems like I missed some FrameworkSkipConditions when I merged these tests --- test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs index b0a8c10b51..0bfa31b438 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs @@ -931,8 +931,9 @@ namespace Microsoft.AspNet.Server.KestrelTests } } - [Theory] + [ConditionalTheory] [MemberData(nameof(ConnectionFilterData))] + [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Test hangs after execution on Mono.")] public async Task RequestsCanBeAbortedMidRead(ServiceContext testContext) { var readTcs = new TaskCompletionSource(); @@ -1003,8 +1004,9 @@ namespace Microsoft.AspNet.Server.KestrelTests Assert.Equal(2, abortedRequestId); } - [Theory] + [ConditionalTheory] [MemberData(nameof(ConnectionFilterData))] + [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Test hangs after execution on Mono.")] public async Task FailedWritesResultInAbortedRequest(ServiceContext testContext) { var writeTcs = new TaskCompletionSource(); From fd33475c05ac772ddbf3f4496f8be10e9cd7631f Mon Sep 17 00:00:00 2001 From: John Luo Date: Tue, 8 Dec 2015 16:16:07 -0800 Subject: [PATCH 0505/1662] Ignore null valued headers #429 --- .../Http/FrameHeaders.Generated.cs | 210 +++++++++++++----- .../Http/FrameResponseHeaders.cs | 11 +- .../ResponseTests.cs | 73 +++++- .../KnownHeaders.cs | 7 +- 4 files changed, 234 insertions(+), 67 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameHeaders.Generated.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameHeaders.Generated.cs index 5571e9c56b..df6761e3e0 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameHeaders.Generated.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameHeaders.Generated.cs @@ -7828,8 +7828,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { foreach(var value in _CacheControl) { - output.CopyFrom(_headerBytes, 0, 17); - output.CopyFromAscii(value); + if (value != null) + { + output.CopyFrom(_headerBytes, 0, 17); + output.CopyFromAscii(value); + } } } @@ -7841,8 +7844,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } else foreach(var value in _Connection) { - output.CopyFrom(_headerBytes, 17, 14); - output.CopyFromAscii(value); + if (value != null) + { + output.CopyFrom(_headerBytes, 17, 14); + output.CopyFromAscii(value); + } } } @@ -7854,8 +7860,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } else foreach(var value in _Date) { - output.CopyFrom(_headerBytes, 31, 8); - output.CopyFromAscii(value); + if (value != null) + { + output.CopyFrom(_headerBytes, 31, 8); + output.CopyFromAscii(value); + } } } @@ -7863,8 +7872,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { foreach(var value in _KeepAlive) { - output.CopyFrom(_headerBytes, 39, 14); - output.CopyFromAscii(value); + if (value != null) + { + output.CopyFrom(_headerBytes, 39, 14); + output.CopyFromAscii(value); + } } } @@ -7872,8 +7884,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { foreach(var value in _Pragma) { - output.CopyFrom(_headerBytes, 53, 10); - output.CopyFromAscii(value); + if (value != null) + { + output.CopyFrom(_headerBytes, 53, 10); + output.CopyFromAscii(value); + } } } @@ -7881,8 +7896,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { foreach(var value in _Trailer) { - output.CopyFrom(_headerBytes, 63, 11); - output.CopyFromAscii(value); + if (value != null) + { + output.CopyFrom(_headerBytes, 63, 11); + output.CopyFromAscii(value); + } } } @@ -7894,8 +7912,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } else foreach(var value in _TransferEncoding) { - output.CopyFrom(_headerBytes, 74, 21); - output.CopyFromAscii(value); + if (value != null) + { + output.CopyFrom(_headerBytes, 74, 21); + output.CopyFromAscii(value); + } } } @@ -7903,8 +7924,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { foreach(var value in _Upgrade) { - output.CopyFrom(_headerBytes, 95, 11); - output.CopyFromAscii(value); + if (value != null) + { + output.CopyFrom(_headerBytes, 95, 11); + output.CopyFromAscii(value); + } } } @@ -7912,8 +7936,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { foreach(var value in _Via) { - output.CopyFrom(_headerBytes, 106, 7); - output.CopyFromAscii(value); + if (value != null) + { + output.CopyFrom(_headerBytes, 106, 7); + output.CopyFromAscii(value); + } } } @@ -7921,8 +7948,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { foreach(var value in _Warning) { - output.CopyFrom(_headerBytes, 113, 11); - output.CopyFromAscii(value); + if (value != null) + { + output.CopyFrom(_headerBytes, 113, 11); + output.CopyFromAscii(value); + } } } @@ -7930,8 +7960,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { foreach(var value in _Allow) { - output.CopyFrom(_headerBytes, 124, 9); - output.CopyFromAscii(value); + if (value != null) + { + output.CopyFrom(_headerBytes, 124, 9); + output.CopyFromAscii(value); + } } } @@ -7943,8 +7976,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } else foreach(var value in _ContentLength) { - output.CopyFrom(_headerBytes, 133, 18); - output.CopyFromAscii(value); + if (value != null) + { + output.CopyFrom(_headerBytes, 133, 18); + output.CopyFromAscii(value); + } } } @@ -7952,8 +7988,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { foreach(var value in _ContentType) { - output.CopyFrom(_headerBytes, 151, 16); - output.CopyFromAscii(value); + if (value != null) + { + output.CopyFrom(_headerBytes, 151, 16); + output.CopyFromAscii(value); + } } } @@ -7961,8 +8000,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { foreach(var value in _ContentEncoding) { - output.CopyFrom(_headerBytes, 167, 20); - output.CopyFromAscii(value); + if (value != null) + { + output.CopyFrom(_headerBytes, 167, 20); + output.CopyFromAscii(value); + } } } @@ -7970,8 +8012,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { foreach(var value in _ContentLanguage) { - output.CopyFrom(_headerBytes, 187, 20); - output.CopyFromAscii(value); + if (value != null) + { + output.CopyFrom(_headerBytes, 187, 20); + output.CopyFromAscii(value); + } } } @@ -7979,8 +8024,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { foreach(var value in _ContentLocation) { - output.CopyFrom(_headerBytes, 207, 20); - output.CopyFromAscii(value); + if (value != null) + { + output.CopyFrom(_headerBytes, 207, 20); + output.CopyFromAscii(value); + } } } @@ -7988,8 +8036,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { foreach(var value in _ContentMD5) { - output.CopyFrom(_headerBytes, 227, 15); - output.CopyFromAscii(value); + if (value != null) + { + output.CopyFrom(_headerBytes, 227, 15); + output.CopyFromAscii(value); + } } } @@ -7997,8 +8048,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { foreach(var value in _ContentRange) { - output.CopyFrom(_headerBytes, 242, 17); - output.CopyFromAscii(value); + if (value != null) + { + output.CopyFrom(_headerBytes, 242, 17); + output.CopyFromAscii(value); + } } } @@ -8006,8 +8060,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { foreach(var value in _Expires) { - output.CopyFrom(_headerBytes, 259, 11); - output.CopyFromAscii(value); + if (value != null) + { + output.CopyFrom(_headerBytes, 259, 11); + output.CopyFromAscii(value); + } } } @@ -8015,8 +8072,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { foreach(var value in _LastModified) { - output.CopyFrom(_headerBytes, 270, 17); - output.CopyFromAscii(value); + if (value != null) + { + output.CopyFrom(_headerBytes, 270, 17); + output.CopyFromAscii(value); + } } } @@ -8024,8 +8084,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { foreach(var value in _AcceptRanges) { - output.CopyFrom(_headerBytes, 287, 17); - output.CopyFromAscii(value); + if (value != null) + { + output.CopyFrom(_headerBytes, 287, 17); + output.CopyFromAscii(value); + } } } @@ -8033,8 +8096,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { foreach(var value in _Age) { - output.CopyFrom(_headerBytes, 304, 7); - output.CopyFromAscii(value); + if (value != null) + { + output.CopyFrom(_headerBytes, 304, 7); + output.CopyFromAscii(value); + } } } @@ -8042,8 +8108,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { foreach(var value in _ETag) { - output.CopyFrom(_headerBytes, 311, 8); - output.CopyFromAscii(value); + if (value != null) + { + output.CopyFrom(_headerBytes, 311, 8); + output.CopyFromAscii(value); + } } } @@ -8051,8 +8120,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { foreach(var value in _Location) { - output.CopyFrom(_headerBytes, 319, 12); - output.CopyFromAscii(value); + if (value != null) + { + output.CopyFrom(_headerBytes, 319, 12); + output.CopyFromAscii(value); + } } } @@ -8060,8 +8132,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { foreach(var value in _ProxyAutheticate) { - output.CopyFrom(_headerBytes, 331, 21); - output.CopyFromAscii(value); + if (value != null) + { + output.CopyFrom(_headerBytes, 331, 21); + output.CopyFromAscii(value); + } } } @@ -8069,8 +8144,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { foreach(var value in _RetryAfter) { - output.CopyFrom(_headerBytes, 352, 15); - output.CopyFromAscii(value); + if (value != null) + { + output.CopyFrom(_headerBytes, 352, 15); + output.CopyFromAscii(value); + } } } @@ -8082,8 +8160,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } else foreach(var value in _Server) { - output.CopyFrom(_headerBytes, 367, 10); - output.CopyFromAscii(value); + if (value != null) + { + output.CopyFrom(_headerBytes, 367, 10); + output.CopyFromAscii(value); + } } } @@ -8091,8 +8172,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { foreach(var value in _SetCookie) { - output.CopyFrom(_headerBytes, 377, 14); - output.CopyFromAscii(value); + if (value != null) + { + output.CopyFrom(_headerBytes, 377, 14); + output.CopyFromAscii(value); + } } } @@ -8100,8 +8184,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { foreach(var value in _Vary) { - output.CopyFrom(_headerBytes, 391, 8); - output.CopyFromAscii(value); + if (value != null) + { + output.CopyFrom(_headerBytes, 391, 8); + output.CopyFromAscii(value); + } } } @@ -8109,8 +8196,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { foreach(var value in _WWWAuthenticate) { - output.CopyFrom(_headerBytes, 399, 20); - output.CopyFromAscii(value); + if (value != null) + { + output.CopyFrom(_headerBytes, 399, 20); + output.CopyFromAscii(value); + } } } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameResponseHeaders.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameResponseHeaders.cs index 693c58e912..a5a42e6a98 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameResponseHeaders.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameResponseHeaders.cs @@ -39,10 +39,13 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { foreach (var value in kv.Value) { - output.CopyFrom(_CrLf, 0, 2); - output.CopyFromAscii(kv.Key); - output.CopyFrom(_colonSpace, 0, 2); - output.CopyFromAscii(value); + if (value != null) + { + output.CopyFrom(_CrLf, 0, 2); + output.CopyFromAscii(kv.Key); + output.CopyFrom(_colonSpace, 0, 2); + output.CopyFromAscii(value); + } } } } diff --git a/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/ResponseTests.cs b/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/ResponseTests.cs index c2479c388c..67e8203e05 100644 --- a/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/ResponseTests.cs +++ b/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/ResponseTests.cs @@ -2,12 +2,15 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Collections.Generic; +using System.Linq; using System.Net.Http; using System.Threading.Tasks; using Microsoft.AspNet.Builder; using Microsoft.AspNet.Hosting; +using Microsoft.AspNet.Http; using Microsoft.AspNet.Testing.xunit; using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Primitives; using Xunit; namespace Microsoft.AspNet.Server.Kestrel.FunctionalTests @@ -44,7 +47,7 @@ namespace Microsoft.AspNet.Server.Kestrel.FunctionalTests await context.Response.Body.WriteAsync(bytes, 0, bytes.Length); } }); - }); + }); using (var app = hostBuilder.Build().Start()) { @@ -70,5 +73,73 @@ namespace Microsoft.AspNet.Server.Kestrel.FunctionalTests } } } + + [ConditionalTheory, MemberData(nameof(NullHeaderData))] + [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Test hangs after execution on mono.")] + public async Task IgnoreNullHeaderValues(string headerName, StringValues headerValue, string expectedValue) + { + var config = new ConfigurationBuilder() + .AddInMemoryCollection(new Dictionary + { + { "server.urls", "http://localhost:8793/" } + }) + .Build(); + + var hostBuilder = new WebHostBuilder(config) + .UseServerFactory("Microsoft.AspNet.Server.Kestrel") + .UseStartup(app => + { + app.Run(async context => + { + context.Response.Headers.Add(headerName, headerValue); + + await context.Response.WriteAsync(""); + }); + }); + + using (var app = hostBuilder.Build().Start()) + { + using (var client = new HttpClient()) + { + var response = await client.GetAsync("http://localhost:8793/"); + response.EnsureSuccessStatusCode(); + + var headers = response.Headers; + + if (expectedValue == null) + { + Assert.False(headers.Contains(headerName)); + } + else + { + Assert.True(headers.Contains(headerName)); + Assert.Equal(headers.GetValues(headerName).Single(), expectedValue); + } + } + } + } + + public static TheoryData NullHeaderData + { + get + { + var dataset = new TheoryData(); + + // Unknown headers + dataset.Add("NullString", (string)null, null); + dataset.Add("EmptyString", "", ""); + dataset.Add("NullStringArray", new string[] { null }, null); + dataset.Add("EmptyStringArray", new string[] { "" }, ""); + dataset.Add("MixedStringArray", new string[] { null, "" }, ""); + // Known headers + dataset.Add("Location", (string)null, null); + dataset.Add("Location", "", ""); + dataset.Add("Location", new string[] { null }, null); + dataset.Add("Location", new string[] { "" }, ""); + dataset.Add("Location", new string[] { null, "" }, ""); + + return dataset; + } + } } } diff --git a/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/KnownHeaders.cs b/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/KnownHeaders.cs index aaf19e8300..4dd45dcfbe 100644 --- a/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/KnownHeaders.cs +++ b/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/KnownHeaders.cs @@ -391,8 +391,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http }} else ")} foreach(var value in _{header.Identifier}) {{ - output.CopyFrom(_headerBytes, {header.BytesOffset}, {header.BytesCount}); - output.CopyFromAscii(value); + if (value != null) + {{ + output.CopyFrom(_headerBytes, {header.BytesOffset}, {header.BytesCount}); + output.CopyFromAscii(value); + }} }} }} ")} From 9e8b07ecf8509d63fdc78de4b9e0bb3566b51623 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Thu, 10 Dec 2015 15:47:46 +0000 Subject: [PATCH 0506/1662] Error concurrent reads gracefully --- .../Http/SocketInput.cs | 12 ++- .../SocketInputTests.cs | 94 +++++++++++++++++++ 2 files changed, 104 insertions(+), 2 deletions(-) create mode 100644 test/Microsoft.AspNet.Server.KestrelTests/SocketInputTests.cs diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketInput.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketInput.cs index 5f850b5d68..02bb7a8f0d 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketInput.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketInput.cs @@ -216,8 +216,16 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } else { - // THIS IS AN ERROR STATE - ONLY ONE WAITER CAN WAIT - throw new InvalidOperationException("Concurrent reads are not supported."); + _awaitableError = new InvalidOperationException("Concurrent reads are not supported."); + + awaitableState = Interlocked.Exchange( + ref _awaitableState, + _awaitableIsCompleted); + + _manualResetEvent.Set(); + + _threadPool.Run(continuation); + _threadPool.Run(awaitableState); } } diff --git a/test/Microsoft.AspNet.Server.KestrelTests/SocketInputTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/SocketInputTests.cs new file mode 100644 index 0000000000..5bb02f5c0d --- /dev/null +++ b/test/Microsoft.AspNet.Server.KestrelTests/SocketInputTests.cs @@ -0,0 +1,94 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Threading.Tasks; +using Microsoft.AspNet.Server.Kestrel; +using Microsoft.AspNet.Server.Kestrel.Http; +using Microsoft.AspNet.Server.Kestrel.Infrastructure; +using Xunit; + +namespace Microsoft.AspNet.Server.KestrelTests +{ + public class SocketInputTests + { + [Fact] + public async Task ConcurrentReadsFailGracefully() + { + // Arrange + var trace = new KestrelTrace(new TestKestrelTrace()); + var ltp = new LoggingThreadPool(trace); + using (var memory2 = new MemoryPool2()) + { + var socketInput = new SocketInput(memory2, ltp); + + var task0Threw = false; + var task1Threw = false; + var task2Threw = false; + + + var task0 = AwaitAsTaskAsync(socketInput); + + Assert.False(task0.IsFaulted); + + var task = task0.ContinueWith( + (t) => + { + TestConcurrentFaultedTask(t); + task0Threw = true; + }, + TaskContinuationOptions.OnlyOnFaulted); + + Assert.False(task0.IsFaulted); + + // Awaiting/continuing two tasks faults both + + var task1 = AwaitAsTaskAsync(socketInput); + + await task1.ContinueWith( + (t) => + { + TestConcurrentFaultedTask(t); + task1Threw = true; + }, + TaskContinuationOptions.OnlyOnFaulted); + + await task; + + Assert.True(task0.IsFaulted); + Assert.True(task1.IsFaulted); + + Assert.True(task0Threw); + Assert.True(task1Threw); + + // socket stays faulted + + var task2 = AwaitAsTaskAsync(socketInput); + + await task2.ContinueWith( + (t) => + { + TestConcurrentFaultedTask(t); + task2Threw = true; + }, + TaskContinuationOptions.OnlyOnFaulted); + + Assert.True(task2.IsFaulted); + Assert.True(task2Threw); + } + } + + private static void TestConcurrentFaultedTask(Task t) + { + Assert.True(t.IsFaulted); + Assert.IsType(typeof(System.IO.IOException), t.Exception.InnerException); + Assert.Equal(t.Exception.InnerException.Message, "Concurrent reads are not supported."); + } + + private async Task AwaitAsTaskAsync(SocketInput socketInput) + { + await socketInput; + } + + } +} From f9d70e601c944d8fd1b060a3923f3d1852a8ce2e Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Thu, 10 Dec 2015 12:21:20 -0800 Subject: [PATCH 0507/1662] Set error before changing state in SocketInput.AbortAwaiting - This fixes a tight race where awaiting code might continue but not see the ODE that moved SocketInput into the completed state. --- src/Microsoft.AspNet.Server.Kestrel/Http/SocketInput.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketInput.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketInput.cs index 02bb7a8f0d..5a7a1715d7 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketInput.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketInput.cs @@ -180,11 +180,12 @@ namespace Microsoft.AspNet.Server.Kestrel.Http public void AbortAwaiting() { + _awaitableError = new ObjectDisposedException(nameof(SocketInput), "The request was aborted"); + var awaitableState = Interlocked.Exchange( ref _awaitableState, _awaitableIsCompleted); - _awaitableError = new ObjectDisposedException(nameof(SocketInput), "The request was aborted"); _manualResetEvent.Set(); if (awaitableState != _awaitableIsCompleted && From 97d33406243be0db48a57202d180a1bbb858cd4e Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Tue, 24 Nov 2015 03:20:38 +0000 Subject: [PATCH 0508/1662] Resuse writes, initalize queues --- .../Http/SocketOutput.cs | 110 +++++++++++++++--- .../Infrastructure/KestrelThread.cs | 8 +- .../Networking/UvWriteReq.cs | 4 +- 3 files changed, 98 insertions(+), 24 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs index 13c690d246..71675e5513 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs @@ -17,6 +17,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http private const int _maxPendingWrites = 3; private const int _maxBytesPreCompleted = 65536; private const int _initialTaskQueues = 64; + private const int _maxPooledWriteContexts = 32; private static WaitCallback _returnBlocks = (state) => ReturnBlocks((MemoryPoolBlock2)state); @@ -38,6 +39,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http // This locks access to to all of the below fields private readonly object _contextLock = new object(); + private bool _isDisposed = false; // The number of write operations that have been scheduled so far // but have not completed. @@ -48,6 +50,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http private WriteContext _nextWriteContext; private readonly Queue> _tasksPending; private readonly Queue> _tasksCompleted; + private readonly Queue _writeContextPool; public SocketOutput( KestrelThread thread, @@ -66,6 +69,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http _threadPool = threadPool; _tasksPending = new Queue>(_initialTaskQueues); _tasksCompleted = new Queue>(_initialTaskQueues); + _writeContextPool = new Queue(_maxPooledWriteContexts); _head = memory.Lease(); _tail = _head; @@ -92,7 +96,14 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { if (_nextWriteContext == null) { - _nextWriteContext = new WriteContext(this); + if (_writeContextPool.Count > 0) + { + _nextWriteContext = _writeContextPool.Dequeue(); + } + else + { + _nextWriteContext = new WriteContext(this); + } } if (socketShutdownSend) @@ -274,9 +285,12 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } // This is called on the libuv event loop - private void OnWriteCompleted(int bytesWritten, int status, Exception error) + private void OnWriteCompleted(WriteContext writeContext) { - _log.ConnectionWriteCallback(_connectionId, status); + var bytesWritten = writeContext.ByteCount; + var status = writeContext.WriteStatus; + var error = writeContext.WriteError; + if (error != null) { @@ -290,6 +304,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http lock (_contextLock) { + PoolWriteContext(writeContext); if (_nextWriteContext != null) { scheduleWrite = true; @@ -332,11 +347,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } + _log.ConnectionWriteCallback(_connectionId, status); + if (scheduleWrite) { - // ScheduleWrite(); - // on right thread, fairness issues? - WriteAllPending(); + ScheduleWrite(); } _tasksCompleted.Clear(); @@ -367,6 +382,32 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } + private void PoolWriteContext(WriteContext writeContext) + { + // called inside _contextLock + if (!_isDisposed && _writeContextPool.Count < _maxPooledWriteContexts) + { + writeContext.Reset(); + _writeContextPool.Enqueue(writeContext); + } + else + { + writeContext.Dispose(); + } + } + + private void Dispose() + { + lock (_contextLock) + { + _isDisposed = true; + while (_writeContextPool.Count > 0) + { + _writeContextPool.Dequeue().Dispose(); + } + } + } + void ISocketOutput.Write(ArraySegment buffer, bool immediate) { var task = WriteAsync(buffer, immediate); @@ -408,14 +449,14 @@ namespace Microsoft.AspNet.Server.Kestrel.Http buffers++; } - private class WriteContext + private class WriteContext : IDisposable { private static WaitCallback _returnWrittenBlocks = (state) => ReturnWrittenBlocks((MemoryPoolBlock2)state); private MemoryPoolIterator2 _lockedStart; private MemoryPoolIterator2 _lockedEnd; private int _bufferCount; - private int _byteCount; + public int ByteCount; public SocketOutput Self; @@ -425,11 +466,15 @@ namespace Microsoft.AspNet.Server.Kestrel.Http public int WriteStatus; public Exception WriteError; + private UvWriteReq _writeReq; + public int ShutdownSendStatus; public WriteContext(SocketOutput self) { Self = self; + _writeReq = new UvWriteReq(Self._log); + _writeReq.Init(Self._thread.Loop); } /// @@ -439,18 +484,19 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { LockWrite(); - if (_byteCount == 0 || Self._socket.IsClosed) + if (ByteCount == 0 || Self._socket.IsClosed) { DoShutdownIfNeeded(); return; } - var writeReq = new UvWriteReq(Self._log); - writeReq.Init(Self._thread.Loop); + // Sample values locally in case write completes inline + // to allow block to be Reset and still complete this function + var lockedEndBlock = _lockedEnd.Block; + var lockedEndIndex = _lockedEnd.Index; - writeReq.Write(Self._socket, _lockedStart, _lockedEnd, _bufferCount, (_writeReq, status, error, state) => + _writeReq.Write(Self._socket, _lockedStart, _lockedEnd, _bufferCount, (_writeReq, status, error, state) => { - _writeReq.Dispose(); var _this = (WriteContext)state; _this.ScheduleReturnFullyWrittenBlocks(); _this.WriteStatus = status; @@ -458,8 +504,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http _this.DoShutdownIfNeeded(); }, this); - Self._head = _lockedEnd.Block; - Self._head.Start = _lockedEnd.Index; + Self._head = lockedEndBlock; + Self._head.Start = lockedEndIndex; } /// @@ -492,21 +538,28 @@ namespace Microsoft.AspNet.Server.Kestrel.Http /// public void DoDisconnectIfNeeded() { - if (SocketDisconnect == false || Self._socket.IsClosed) + if (SocketDisconnect == false) { Complete(); return; } + else if (Self._socket.IsClosed) + { + Self.Dispose(); + Complete(); + return; + } Self._socket.Dispose(); Self.ReturnAllBlocks(); + Self.Dispose(); Self._log.ConnectionStop(Self._connectionId); Complete(); } public void Complete() { - Self.OnWriteCompleted(_byteCount, WriteStatus, WriteError); + Self.OnWriteCompleted(this); } private void ScheduleReturnFullyWrittenBlocks() @@ -555,8 +608,29 @@ namespace Microsoft.AspNet.Server.Kestrel.Http _lockedStart = new MemoryPoolIterator2(head, head.Start); _lockedEnd = new MemoryPoolIterator2(tail, tail.End); + + BytesBetween(_lockedStart, _lockedEnd, out ByteCount, out _bufferCount); + } - BytesBetween(_lockedStart, _lockedEnd, out _byteCount, out _bufferCount); + public void Reset() + { + _lockedStart = default(MemoryPoolIterator2); + _lockedEnd = default(MemoryPoolIterator2); + _bufferCount = 0; + ByteCount = 0; + + SocketShutdownSend = false; + SocketDisconnect = false; + + WriteStatus = 0; + WriteError = null; + + ShutdownSendStatus = 0; + } + + public void Dispose() + { + _writeReq.Dispose(); } } } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs index ee43b9f60b..87658395f2 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs @@ -24,10 +24,10 @@ namespace Microsoft.AspNet.Server.Kestrel private Thread _thread; private UvLoopHandle _loop; private UvAsyncHandle _post; - private Queue _workAdding = new Queue(); - private Queue _workRunning = new Queue(); - private Queue _closeHandleAdding = new Queue(); - private Queue _closeHandleRunning = new Queue(); + private Queue _workAdding = new Queue(1024); + private Queue _workRunning = new Queue(1024); + private Queue _closeHandleAdding = new Queue(256); + private Queue _closeHandleRunning = new Queue(256); private object _workSync = new Object(); private bool _stopImmediate = false; private bool _initCompleted = false; diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvWriteReq.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvWriteReq.cs index 2695036f32..21a1aaf778 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvWriteReq.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvWriteReq.cs @@ -14,7 +14,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking /// public class UvWriteReq : UvRequest { - private readonly static Libuv.uv_write_cb _uv_write_cb = UvWriteCb; + private readonly static Libuv.uv_write_cb _uv_write_cb = (IntPtr ptr, int status) => UvWriteCb(ptr, status); private IntPtr _bufs; @@ -22,7 +22,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking private object _state; private const int BUFFER_COUNT = 4; - private List _pins = new List(); + private List _pins = new List(BUFFER_COUNT + 1); public UvWriteReq(IKestrelTrace logger) : base(logger) { From 992664e0dc7ae0ff036be56eb0ca696912a97614 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Wed, 25 Nov 2015 04:44:07 +0000 Subject: [PATCH 0509/1662] Process cascaded work immediately Without waiting for next libuv pass Fix for potential regression in #363 due to bug fix. --- .../Infrastructure/KestrelThread.cs | 29 ++++++++++++++++--- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs index 87658395f2..de603b4458 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs @@ -18,6 +18,11 @@ namespace Microsoft.AspNet.Server.Kestrel /// public class KestrelThread { + // maximum times the work queues swapped and are processed in a single pass + // as completing a task may immediately have write data to put on the network + // otherwise it needs to wait till the next pass of the libuv loop + private const int _maxLoops = 8; + private static Action _threadCallbackAdapter = (callback, state) => ((Action)callback).Invoke((KestrelThread)state); private KestrelEngine _engine; private readonly IApplicationLifetime _appLifetime; @@ -249,11 +254,17 @@ namespace Microsoft.AspNet.Server.Kestrel private void OnPost() { - DoPostWork(); - DoPostCloseHandle(); + var loopsRemaining = _maxLoops; + bool wasWork; + do + { + wasWork = DoPostWork(); + wasWork = DoPostCloseHandle() || wasWork; + loopsRemaining--; + } while (wasWork && loopsRemaining > 0); } - private void DoPostWork() + private bool DoPostWork() { Queue queue; lock (_workSync) @@ -262,6 +273,9 @@ namespace Microsoft.AspNet.Server.Kestrel _workAdding = _workRunning; _workRunning = queue; } + + bool wasWork = queue.Count > 0; + while (queue.Count != 0) { var work = queue.Dequeue(); @@ -286,8 +300,10 @@ namespace Microsoft.AspNet.Server.Kestrel } } } + + return wasWork; } - private void DoPostCloseHandle() + private bool DoPostCloseHandle() { Queue queue; lock (_workSync) @@ -296,6 +312,9 @@ namespace Microsoft.AspNet.Server.Kestrel _closeHandleAdding = _closeHandleRunning; _closeHandleRunning = queue; } + + bool wasWork = queue.Count > 0; + while (queue.Count != 0) { var closeHandle = queue.Dequeue(); @@ -309,6 +328,8 @@ namespace Microsoft.AspNet.Server.Kestrel throw; } } + + return wasWork; } private struct Work From 3e42904096d6a7d1f53543ee4ad9f5e625456c6e Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Wed, 9 Dec 2015 17:12:45 -0800 Subject: [PATCH 0510/1662] Pool UvWriteReqs instead of SocketOutput.WriteContexts - This allows all connections accepted by the same thread to share a pool --- .../Http/Connection.cs | 2 +- .../Http/Listener.cs | 7 ++ .../Http/ListenerContext.cs | 7 +- .../Http/SocketOutput.cs | 111 ++++++------------ .../SocketOutputTests.cs | 10 +- 5 files changed, 57 insertions(+), 80 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs index b49ffd4316..89b9db55e8 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs @@ -42,7 +42,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http _connectionId = Interlocked.Increment(ref _lastConnectionId); _rawSocketInput = new SocketInput(Memory2, ThreadPool); - _rawSocketOutput = new SocketOutput(Thread, _socket, Memory2, this, _connectionId, Log, ThreadPool); + _rawSocketOutput = new SocketOutput(Thread, _socket, Memory2, this, _connectionId, Log, ThreadPool, WriteReqPool); } public void Start() diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs index 6721756266..5d8c4e8d0d 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs @@ -94,6 +94,13 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { var socket = (Listener)tcs2.Task.AsyncState; socket.ListenSocket.Dispose(); + + var writeReqPool = socket.WriteReqPool; + while (writeReqPool.Count > 0) + { + writeReqPool.Dequeue().Dispose(); + } + tcs2.SetResult(0); } catch (Exception ex) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerContext.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerContext.cs index fecd0afa44..7247afa2bd 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerContext.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerContext.cs @@ -1,8 +1,9 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using Microsoft.AspNet.Http; +using System.Collections.Generic; using Microsoft.AspNet.Server.Kestrel.Infrastructure; +using Microsoft.AspNet.Server.Kestrel.Networking; namespace Microsoft.AspNet.Server.Kestrel.Http { @@ -17,6 +18,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http : base(serviceContext) { Memory2 = new MemoryPool2(); + WriteReqPool = new Queue(SocketOutput.MaxPooledWriteReqs); } public ListenerContext(ListenerContext listenerContext) @@ -25,6 +27,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http ServerAddress = listenerContext.ServerAddress; Thread = listenerContext.Thread; Memory2 = listenerContext.Memory2; + WriteReqPool = listenerContext.WriteReqPool; Log = listenerContext.Log; } @@ -33,5 +36,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http public KestrelThread Thread { get; set; } public MemoryPool2 Memory2 { get; set; } + + public Queue WriteReqPool { get; set; } } } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs index 71675e5513..39dcf3c2c8 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs @@ -14,10 +14,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { public class SocketOutput : ISocketOutput { + public const int MaxPooledWriteReqs = 1024; + private const int _maxPendingWrites = 3; private const int _maxBytesPreCompleted = 65536; private const int _initialTaskQueues = 64; - private const int _maxPooledWriteContexts = 32; private static WaitCallback _returnBlocks = (state) => ReturnBlocks((MemoryPoolBlock2)state); @@ -39,7 +40,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Http // This locks access to to all of the below fields private readonly object _contextLock = new object(); - private bool _isDisposed = false; // The number of write operations that have been scheduled so far // but have not completed. @@ -50,7 +50,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http private WriteContext _nextWriteContext; private readonly Queue> _tasksPending; private readonly Queue> _tasksCompleted; - private readonly Queue _writeContextPool; + private readonly Queue _writeReqPool; public SocketOutput( KestrelThread thread, @@ -59,7 +59,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http Connection connection, long connectionId, IKestrelTrace log, - IThreadPool threadPool) + IThreadPool threadPool, + Queue writeReqPool) { _thread = thread; _socket = socket; @@ -69,7 +70,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http _threadPool = threadPool; _tasksPending = new Queue>(_initialTaskQueues); _tasksCompleted = new Queue>(_initialTaskQueues); - _writeContextPool = new Queue(_maxPooledWriteContexts); + _writeReqPool = writeReqPool; _head = memory.Lease(); _tail = _head; @@ -96,14 +97,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { if (_nextWriteContext == null) { - if (_writeContextPool.Count > 0) - { - _nextWriteContext = _writeContextPool.Dequeue(); - } - else - { - _nextWriteContext = new WriteContext(this); - } + _nextWriteContext = new WriteContext(this); } if (socketShutdownSend) @@ -304,7 +298,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Http lock (_contextLock) { - PoolWriteContext(writeContext); if (_nextWriteContext != null) { scheduleWrite = true; @@ -382,32 +375,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } - private void PoolWriteContext(WriteContext writeContext) - { - // called inside _contextLock - if (!_isDisposed && _writeContextPool.Count < _maxPooledWriteContexts) - { - writeContext.Reset(); - _writeContextPool.Enqueue(writeContext); - } - else - { - writeContext.Dispose(); - } - } - - private void Dispose() - { - lock (_contextLock) - { - _isDisposed = true; - while (_writeContextPool.Count > 0) - { - _writeContextPool.Dequeue().Dispose(); - } - } - } - void ISocketOutput.Write(ArraySegment buffer, bool immediate) { var task = WriteAsync(buffer, immediate); @@ -449,7 +416,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http buffers++; } - private class WriteContext : IDisposable + private class WriteContext { private static WaitCallback _returnWrittenBlocks = (state) => ReturnWrittenBlocks((MemoryPoolBlock2)state); @@ -473,8 +440,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Http public WriteContext(SocketOutput self) { Self = self; - _writeReq = new UvWriteReq(Self._log); - _writeReq.Init(Self._thread.Loop); } /// @@ -495,13 +460,24 @@ namespace Microsoft.AspNet.Server.Kestrel.Http var lockedEndBlock = _lockedEnd.Block; var lockedEndIndex = _lockedEnd.Index; + if (Self._writeReqPool.Count > 0) + { + _writeReq = Self._writeReqPool.Dequeue(); + } + else + { + _writeReq = new UvWriteReq(Self._log); + _writeReq.Init(Self._thread.Loop); + } + _writeReq.Write(Self._socket, _lockedStart, _lockedEnd, _bufferCount, (_writeReq, status, error, state) => { - var _this = (WriteContext)state; - _this.ScheduleReturnFullyWrittenBlocks(); - _this.WriteStatus = status; - _this.WriteError = error; - _this.DoShutdownIfNeeded(); + var writeContext = (WriteContext)state; + writeContext.PoolWriteReq(writeContext._writeReq); + writeContext.ScheduleReturnFullyWrittenBlocks(); + writeContext.WriteStatus = status; + writeContext.WriteError = error; + writeContext.DoShutdownIfNeeded(); }, this); Self._head = lockedEndBlock; @@ -545,14 +521,12 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } else if (Self._socket.IsClosed) { - Self.Dispose(); Complete(); return; } Self._socket.Dispose(); Self.ReturnAllBlocks(); - Self.Dispose(); Self._log.ConnectionStop(Self._connectionId); Complete(); } @@ -561,7 +535,19 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { Self.OnWriteCompleted(this); } - + + private void PoolWriteReq(UvWriteReq writeReq) + { + if (Self._writeReqPool.Count < MaxPooledWriteReqs) + { + Self._writeReqPool.Enqueue(writeReq); + } + else + { + writeReq.Dispose(); + } + } + private void ScheduleReturnFullyWrittenBlocks() { var block = _lockedStart.Block; @@ -608,30 +594,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Http _lockedStart = new MemoryPoolIterator2(head, head.Start); _lockedEnd = new MemoryPoolIterator2(tail, tail.End); - + BytesBetween(_lockedStart, _lockedEnd, out ByteCount, out _bufferCount); } - - public void Reset() - { - _lockedStart = default(MemoryPoolIterator2); - _lockedEnd = default(MemoryPoolIterator2); - _bufferCount = 0; - ByteCount = 0; - - SocketShutdownSend = false; - SocketDisconnect = false; - - WriteStatus = 0; - WriteError = null; - - ShutdownSendStatus = 0; - } - - public void Dispose() - { - _writeReq.Dispose(); - } } } } diff --git a/test/Microsoft.AspNet.Server.KestrelTests/SocketOutputTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/SocketOutputTests.cs index d5f86b76aa..bda6bfb651 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/SocketOutputTests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/SocketOutputTests.cs @@ -42,7 +42,7 @@ namespace Microsoft.AspNet.Server.KestrelTests var socket = new MockSocket(kestrelThread.Loop.ThreadId, new TestKestrelTrace()); var trace = new KestrelTrace(new TestKestrelTrace()); var ltp = new LoggingThreadPool(trace); - var socketOutput = new SocketOutput(kestrelThread, socket, memory, null, 0, trace, ltp); + var socketOutput = new SocketOutput(kestrelThread, socket, memory, null, 0, trace, ltp, new Queue()); // I doubt _maxBytesPreCompleted will ever be over a MB. If it is, we should change this test. var bufferSize = 1048576; @@ -89,7 +89,7 @@ namespace Microsoft.AspNet.Server.KestrelTests var socket = new MockSocket(kestrelThread.Loop.ThreadId, new TestKestrelTrace()); var trace = new KestrelTrace(new TestKestrelTrace()); var ltp = new LoggingThreadPool(trace); - var socketOutput = new SocketOutput(kestrelThread, socket, memory, null, 0, trace, ltp); + var socketOutput = new SocketOutput(kestrelThread, socket, memory, null, 0, trace, ltp, new Queue()); var bufferSize = maxBytesPreCompleted; var buffer = new ArraySegment(new byte[bufferSize], 0, bufferSize); @@ -146,7 +146,7 @@ namespace Microsoft.AspNet.Server.KestrelTests var socket = new MockSocket(kestrelThread.Loop.ThreadId, new TestKestrelTrace()); var trace = new KestrelTrace(new TestKestrelTrace()); var ltp = new LoggingThreadPool(trace); - var socketOutput = new SocketOutput(kestrelThread, socket, memory, null, 0, trace, ltp); + var socketOutput = new SocketOutput(kestrelThread, socket, memory, null, 0, trace, ltp, new Queue()); var bufferSize = maxBytesPreCompleted; @@ -227,7 +227,7 @@ namespace Microsoft.AspNet.Server.KestrelTests var socket = new MockSocket(kestrelThread.Loop.ThreadId, new TestKestrelTrace()); var trace = new KestrelTrace(new TestKestrelTrace()); var ltp = new LoggingThreadPool(trace); - var socketOutput = new SocketOutput(kestrelThread, socket, memory, null, 0, trace, ltp); + var socketOutput = new SocketOutput(kestrelThread, socket, memory, null, 0, trace, ltp, new Queue()); var bufferSize = maxBytesPreCompleted; var buffer = new ArraySegment(new byte[bufferSize], 0, bufferSize); @@ -304,7 +304,7 @@ namespace Microsoft.AspNet.Server.KestrelTests var socket = new MockSocket(kestrelThread.Loop.ThreadId, new TestKestrelTrace()); var trace = new KestrelTrace(new TestKestrelTrace()); var ltp = new LoggingThreadPool(trace); - var socketOutput = new SocketOutput(kestrelThread, socket, memory, null, 0, trace, ltp); + var socketOutput = new SocketOutput(kestrelThread, socket, memory, null, 0, trace, ltp, new Queue()); // block 1 var start = socketOutput.ProducingStart(); From 5665eba64609edbcab6be957fbae9e8f1703b54f Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Thu, 10 Dec 2015 12:45:58 +0000 Subject: [PATCH 0511/1662] Pool WriteContexts additionally --- .../Http/SocketOutput.cs | 57 ++++++++++++++----- 1 file changed, 43 insertions(+), 14 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs index 39dcf3c2c8..9a0f9f8a14 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs @@ -19,6 +19,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http private const int _maxPendingWrites = 3; private const int _maxBytesPreCompleted = 65536; private const int _initialTaskQueues = 64; + private const int _maxPooledWriteContexts = 32; private static WaitCallback _returnBlocks = (state) => ReturnBlocks((MemoryPoolBlock2)state); @@ -44,12 +45,12 @@ namespace Microsoft.AspNet.Server.Kestrel.Http // The number of write operations that have been scheduled so far // but have not completed. private int _writesPending = 0; - private int _numBytesPreCompleted = 0; private Exception _lastWriteError; private WriteContext _nextWriteContext; private readonly Queue> _tasksPending; private readonly Queue> _tasksCompleted; + private readonly Queue _writeContextPool; private readonly Queue _writeReqPool; public SocketOutput( @@ -70,6 +71,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http _threadPool = threadPool; _tasksPending = new Queue>(_initialTaskQueues); _tasksCompleted = new Queue>(_initialTaskQueues); + _writeContextPool = new Queue(_maxPooledWriteContexts); _writeReqPool = writeReqPool; _head = memory.Lease(); @@ -97,7 +99,14 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { if (_nextWriteContext == null) { - _nextWriteContext = new WriteContext(this); + if (_writeContextPool.Count > 0) + { + _nextWriteContext = _writeContextPool.Dequeue(); + } + else + { + _nextWriteContext = new WriteContext(this); + } } if (socketShutdownSend) @@ -298,6 +307,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http lock (_contextLock) { + PoolWriteContext(writeContext); if (_nextWriteContext != null) { scheduleWrite = true; @@ -375,6 +385,16 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } + private void PoolWriteContext(WriteContext writeContext) + { + // called inside _contextLock + if (_writeContextPool.Count < _maxPooledWriteContexts) + { + writeContext.Reset(); + _writeContextPool.Enqueue(writeContext); + } + } + void ISocketOutput.Write(ArraySegment buffer, bool immediate) { var task = WriteAsync(buffer, immediate); @@ -420,21 +440,18 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { private static WaitCallback _returnWrittenBlocks = (state) => ReturnWrittenBlocks((MemoryPoolBlock2)state); + private SocketOutput Self; + private UvWriteReq _writeReq; private MemoryPoolIterator2 _lockedStart; private MemoryPoolIterator2 _lockedEnd; private int _bufferCount; + public int ByteCount; - - public SocketOutput Self; - public bool SocketShutdownSend; public bool SocketDisconnect; public int WriteStatus; public Exception WriteError; - - private UvWriteReq _writeReq; - public int ShutdownSendStatus; public WriteContext(SocketOutput self) @@ -474,6 +491,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { var writeContext = (WriteContext)state; writeContext.PoolWriteReq(writeContext._writeReq); + writeContext._writeReq = null; writeContext.ScheduleReturnFullyWrittenBlocks(); writeContext.WriteStatus = status; writeContext.WriteError = error; @@ -514,12 +532,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http /// public void DoDisconnectIfNeeded() { - if (SocketDisconnect == false) - { - Complete(); - return; - } - else if (Self._socket.IsClosed) + if (SocketDisconnect == false || Self._socket.IsClosed) { Complete(); return; @@ -597,6 +610,22 @@ namespace Microsoft.AspNet.Server.Kestrel.Http BytesBetween(_lockedStart, _lockedEnd, out ByteCount, out _bufferCount); } + + public void Reset() + { + _lockedStart = default(MemoryPoolIterator2); + _lockedEnd = default(MemoryPoolIterator2); + _bufferCount = 0; + ByteCount = 0; + + SocketShutdownSend = false; + SocketDisconnect = false; + + WriteStatus = 0; + WriteError = null; + + ShutdownSendStatus = 0; + } } } } From c6d6bd7252861629046b4020c8a1fb8e27b92840 Mon Sep 17 00:00:00 2001 From: Pranav K Date: Fri, 11 Dec 2015 12:23:25 -0800 Subject: [PATCH 0512/1662] Updating to release NuGet.config. --- NuGet.config | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/NuGet.config b/NuGet.config index 03704957e8..9db87a421e 100644 --- a/NuGet.config +++ b/NuGet.config @@ -1,7 +1,7 @@ - + - + \ No newline at end of file From dc9f5c433b934bbfd75772e39013891137e77b24 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Sun, 13 Dec 2015 23:17:03 +0000 Subject: [PATCH 0513/1662] Update reason phrases to current Update HTTP reason phrases to current values; are currently original phrases. --- .../Http/ReasonPhrases.cs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/ReasonPhrases.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/ReasonPhrases.cs index 9afbe88d6c..f162ebb9fc 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/ReasonPhrases.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/ReasonPhrases.cs @@ -41,10 +41,10 @@ namespace Microsoft.AspNet.Server.Kestrel.Http private static readonly byte[] _bytesStatus410 = Encoding.ASCII.GetBytes("410 Gone"); private static readonly byte[] _bytesStatus411 = Encoding.ASCII.GetBytes("411 Length Required"); private static readonly byte[] _bytesStatus412 = Encoding.ASCII.GetBytes("412 Precondition Failed"); - private static readonly byte[] _bytesStatus413 = Encoding.ASCII.GetBytes("413 Request Entity Too Large"); - private static readonly byte[] _bytesStatus414 = Encoding.ASCII.GetBytes("414 Request-URI Too Long"); + private static readonly byte[] _bytesStatus413 = Encoding.ASCII.GetBytes("413 Payload Too Large"); + private static readonly byte[] _bytesStatus414 = Encoding.ASCII.GetBytes("414 URI Too Long"); private static readonly byte[] _bytesStatus415 = Encoding.ASCII.GetBytes("415 Unsupported Media Type"); - private static readonly byte[] _bytesStatus416 = Encoding.ASCII.GetBytes("416 Requested Range Not Satisfiable"); + private static readonly byte[] _bytesStatus416 = Encoding.ASCII.GetBytes("416 Range Not Satisfiable"); private static readonly byte[] _bytesStatus417 = Encoding.ASCII.GetBytes("417 Expectation Failed"); private static readonly byte[] _bytesStatus418 = Encoding.ASCII.GetBytes("418 I'm a Teapot"); private static readonly byte[] _bytesStatus422 = Encoding.ASCII.GetBytes("422 Unprocessable Entity"); @@ -258,13 +258,13 @@ namespace Microsoft.AspNet.Server.Kestrel.Http case 412: return "Precondition Failed"; case 413: - return "Request Entity Too Large"; + return "Payload Too Large"; case 414: - return "Request-URI Too Long"; + return "URI Too Long"; case 415: return "Unsupported Media Type"; case 416: - return "Requested Range Not Satisfiable"; + return "Range Not Satisfiable"; case 417: return "Expectation Failed"; case 418: From 83cff1671582d6fbeb0c3d9a7c206154f357c5b7 Mon Sep 17 00:00:00 2001 From: moozzyk Date: Mon, 14 Dec 2015 16:17:06 -0800 Subject: [PATCH 0514/1662] Changing the folder of ARM version of libuv to win7-arm Depends on: https://github.com/aspnet/libuv-build/pull/4 Fixes: https://github.com/aspnet/Home/issues/1111 --- src/Microsoft.AspNet.Server.Kestrel/project.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/project.json b/src/Microsoft.AspNet.Server.Kestrel/project.json index 1582dd0e1a..c95d40a6dc 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/project.json +++ b/src/Microsoft.AspNet.Server.Kestrel/project.json @@ -84,7 +84,7 @@ "/": "../../content/thirdpartynotices.txt", "runtimes/win7-x64/native/": "runtimes/win7-x64/native/*", "runtimes/win7-x86/native/": "runtimes/win7-x86/native/*", - "runtimes/win10-arm/native/": "runtimes/win10-arm/native/*", + "runtimes/win7-arm/native/": "runtimes/win7-arm/native/*", "runtimes/osx/native/": "runtimes/osx/native/*" } } From 4460cd34700ac755500cf41cc51ed5f1bf6ae3a1 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Wed, 16 Dec 2015 12:57:05 +0000 Subject: [PATCH 0515/1662] Don't use Vector.Dot --- .../Infrastructure/MemoryPoolIterator2.cs | 192 +++++++++--------- .../MemoryPoolBlock2Tests.cs | 64 ++++++ 2 files changed, 164 insertions(+), 92 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolIterator2.cs b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolIterator2.cs index 41551d056c..90b58948fe 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolIterator2.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolIterator2.cs @@ -3,25 +3,12 @@ using System; using System.Diagnostics; -using System.Linq; using System.Numerics; namespace Microsoft.AspNet.Server.Kestrel.Infrastructure { public struct MemoryPoolIterator2 { - /// - /// Array of "minus one" bytes of the length of SIMD operations on the current hardware. Used as an argument in the - /// vector dot product that counts matching character occurrence. - /// - private static Vector _dotCount = new Vector(Byte.MaxValue); - - /// - /// Array of negative numbers starting at 0 and continuing for the length of SIMD operations on the current hardware. - /// Used as an argument in the vector dot product that determines matching character index. - /// - private static Vector _dotIndex = new Vector(Enumerable.Range(0, Vector.Count).Select(x => (byte)-x).ToArray()); - private MemoryPoolBlock2 _block; private int _index; @@ -146,7 +133,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure } var byte0 = (byte)char0; - var vectorStride = Vector.Count; var ch0Vector = new Vector(byte0); var block = _block; @@ -169,27 +155,20 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure while (block.End != index) { var following = block.End - index; - if (following >= vectorStride) + if (following >= Vector.Count) { var data = new Vector(array, index); var ch0Equals = Vector.Equals(data, ch0Vector); - var ch0Count = Vector.Dot(ch0Equals, _dotCount); - if (ch0Count == 0) + if (ch0Equals.Equals(Vector.Zero)) { - index += vectorStride; + index += Vector.Count; continue; } - else if (ch0Count == 1) - { - _block = block; - _index = index + Vector.Dot(ch0Equals, _dotIndex); - return char0; - } - else - { - following = vectorStride; - } + + _block = block; + _index = index + FindFirstEqualByte(ch0Equals); + return char0; } while (following > 0) { @@ -215,7 +194,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure var byte0 = (byte)char0; var byte1 = (byte)char1; - var vectorStride = Vector.Count; var ch0Vector = new Vector(byte0); var ch1Vector = new Vector(byte1); @@ -239,40 +217,39 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure while (block.End != index) { var following = block.End - index; - if (following >= vectorStride) + if (following >= Vector.Count) { var data = new Vector(array, index); var ch0Equals = Vector.Equals(data, ch0Vector); - var ch0Count = Vector.Dot(ch0Equals, _dotCount); var ch1Equals = Vector.Equals(data, ch1Vector); - var ch1Count = Vector.Dot(ch1Equals, _dotCount); + int ch0Index = int.MaxValue; + int ch1Index = int.MaxValue; - if (ch0Count == 0 && ch1Count == 0) + if (!ch0Equals.Equals(Vector.Zero)) { - index += vectorStride; + ch0Index = FindFirstEqualByte(ch0Equals); + } + if (!ch1Equals.Equals(Vector.Zero)) + { + ch1Index = FindFirstEqualByte(ch1Equals); + } + + if (ch0Index == int.MaxValue && ch1Index == int.MaxValue) + { + index += Vector.Count; continue; } - else if (ch0Count < 2 && ch1Count < 2) + + _block = block; + + if (ch0Index < ch1Index) { - var ch0Index = ch0Count == 1 ? Vector.Dot(ch0Equals, _dotIndex) : byte.MaxValue; - var ch1Index = ch1Count == 1 ? Vector.Dot(ch1Equals, _dotIndex) : byte.MaxValue; - if (ch0Index < ch1Index) - { - _block = block; - _index = index + ch0Index; - return char0; - } - else - { - _block = block; - _index = index + ch1Index; - return char1; - } - } - else - { - following = vectorStride; + _index = index + ch0Index; + return char0; } + + _index = index + ch1Index; + return char1; } while (following > 0) { @@ -306,7 +283,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure var byte0 = (byte)char0; var byte1 = (byte)char1; var byte2 = (byte)char2; - var vectorStride = Vector.Count; var ch0Vector = new Vector(byte0); var ch1Vector = new Vector(byte1); var ch2Vector = new Vector(byte2); @@ -331,64 +307,68 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure while (block.End != index) { var following = block.End - index; - if (following >= vectorStride) + if (following >= Vector.Count) { var data = new Vector(array, index); var ch0Equals = Vector.Equals(data, ch0Vector); - var ch0Count = Vector.Dot(ch0Equals, _dotCount); var ch1Equals = Vector.Equals(data, ch1Vector); - var ch1Count = Vector.Dot(ch1Equals, _dotCount); var ch2Equals = Vector.Equals(data, ch2Vector); - var ch2Count = Vector.Dot(ch2Equals, _dotCount); + int ch0Index = int.MaxValue; + int ch1Index = int.MaxValue; + int ch2Index = int.MaxValue; - if (ch0Count == 0 && ch1Count == 0 && ch2Count == 0) + if (!ch0Equals.Equals(Vector.Zero)) { - index += vectorStride; + ch0Index = FindFirstEqualByte(ch0Equals); + } + if (!ch1Equals.Equals(Vector.Zero)) + { + ch1Index = FindFirstEqualByte(ch1Equals); + } + if (!ch2Equals.Equals(Vector.Zero)) + { + ch2Index = FindFirstEqualByte(ch2Equals); + } + + if (ch0Index == int.MaxValue && ch1Index == int.MaxValue && ch2Index == int.MaxValue) + { + index += Vector.Count; continue; } - else if (ch0Count < 2 && ch1Count < 2 && ch2Count < 2) - { - var ch0Index = ch0Count == 1 ? Vector.Dot(ch0Equals, _dotIndex) : byte.MaxValue; - var ch1Index = ch1Count == 1 ? Vector.Dot(ch1Equals, _dotIndex) : byte.MaxValue; - var ch2Index = ch2Count == 1 ? Vector.Dot(ch2Equals, _dotIndex) : byte.MaxValue; - int toReturn, toMove; - if (ch0Index < ch1Index) + int toReturn, toMove; + if (ch0Index < ch1Index) + { + if (ch0Index < ch2Index) { - if (ch0Index < ch2Index) - { - toReturn = char0; - toMove = ch0Index; - } - else - { - toReturn = char2; - toMove = ch2Index; - } + toReturn = char0; + toMove = ch0Index; } else { - if (ch1Index < ch2Index) - { - toReturn = char1; - toMove = ch1Index; - } - else - { - toReturn = char2; - toMove = ch2Index; - } + toReturn = char2; + toMove = ch2Index; } - - _block = block; - _index = index + toMove; - return toReturn; } else { - following = vectorStride; + if (ch1Index < ch2Index) + { + toReturn = char1; + toMove = ch1Index; + } + else + { + toReturn = char2; + toMove = ch2Index; + } } + + _block = block; + _index = index + toMove; + return toReturn; } + while (following > 0) { var byteIndex = block.Array[index]; @@ -417,6 +397,34 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure } } + private static int FindFirstEqualByte(Vector chEquals) + { + // Quasi-tree search + var vector64 = Vector.AsVectorInt64(chEquals); + for (var i = 0; i < Vector.Count; i++) + { + var longValue = vector64[i]; + if (longValue == 0) continue; + + var shift = i << 1; + var offset = shift << 2; + var vector32 = Vector.AsVectorInt32(chEquals); + if (vector32[shift] != 0) + { + if (chEquals[offset] != 0) return offset; + if (chEquals[++offset] != 0) return offset; + if (chEquals[++offset] != 0) return offset; + return ++offset; + } + offset += 4; + if (chEquals[offset] != 0) return offset; + if (chEquals[++offset] != 0) return offset; + if (chEquals[++offset] != 0) return offset; + return ++offset; + } + throw new InvalidOperationException(); + } + /// /// Save the data at the current location then move to the next available space. /// diff --git a/test/Microsoft.AspNet.Server.KestrelTests/MemoryPoolBlock2Tests.cs b/test/Microsoft.AspNet.Server.KestrelTests/MemoryPoolBlock2Tests.cs index 239175e198..8618564004 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/MemoryPoolBlock2Tests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/MemoryPoolBlock2Tests.cs @@ -31,6 +31,70 @@ namespace Microsoft.AspNet.Server.KestrelTests hit = iterator; hit.Seek(byte.MaxValue, ch); Assert.Equal(ch, iterator.GetLength(hit)); + + hit = iterator; + hit.Seek(ch, byte.MaxValue, byte.MaxValue); + Assert.Equal(ch, iterator.GetLength(hit)); + + hit = iterator; + hit.Seek(byte.MaxValue, ch, byte.MaxValue); + Assert.Equal(ch, iterator.GetLength(hit)); + + hit = iterator; + hit.Seek(ch, byte.MaxValue, byte.MaxValue); + Assert.Equal(ch, iterator.GetLength(hit)); + } + } + } + + [Fact] + public void SeekWorksAcrossBlocks() + { + using (var pool = new MemoryPool2()) + { + var block1 = pool.Lease(256); + var block2 = block1.Next = pool.Lease(256); + var block3 = block2.Next = pool.Lease(256); + + foreach (var ch in Enumerable.Range(0, 34).Select(x => (byte)x)) + { + block1.Array[block1.End++] = ch; + } + foreach (var ch in Enumerable.Range(34, 25).Select(x => (byte)x)) + { + block2.Array[block2.End++] = ch; + } + foreach (var ch in Enumerable.Range(59, 197).Select(x => (byte)x)) + { + block3.Array[block3.End++] = ch; + } + + var iterator = block1.GetIterator(); + foreach (var ch in Enumerable.Range(0, 256).Select(x => (char)x)) + { + var hit = iterator; + hit.Seek(ch); + Assert.Equal(ch, iterator.GetLength(hit)); + + hit = iterator; + hit.Seek(ch, byte.MaxValue); + Assert.Equal(ch, iterator.GetLength(hit)); + + hit = iterator; + hit.Seek(byte.MaxValue, ch); + Assert.Equal(ch, iterator.GetLength(hit)); + + hit = iterator; + hit.Seek(ch, byte.MaxValue, byte.MaxValue); + Assert.Equal(ch, iterator.GetLength(hit)); + + hit = iterator; + hit.Seek(byte.MaxValue, ch, byte.MaxValue); + Assert.Equal(ch, iterator.GetLength(hit)); + + hit = iterator; + hit.Seek(ch, byte.MaxValue, byte.MaxValue); + Assert.Equal(ch, iterator.GetLength(hit)); } } } From 349af5097778f9df82c8e0efbe62a9877cfbcd68 Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Tue, 1 Dec 2015 10:42:00 -0800 Subject: [PATCH 0516/1662] Pre-allocate standard method and version strings. --- .../Http/Frame.cs | 14 ++- .../Infrastructure/MemoryPoolIterator2.cs | 43 +++++++ .../MemoryPoolIterator2Extensions.cs | 108 ++++++++++++++++++ .../MemoryPoolIterator2Tests.cs | 99 ++++++++++++++++ 4 files changed, 262 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs index ba4a7ba84d..426f17b283 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs @@ -701,7 +701,12 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { return false; } - var method = begin.GetAsciiString(scan); + + string method; + if (!begin.GetKnownString(scan, out method)) + { + method = begin.GetAsciiString(scan); + } scan.Take(); begin = scan; @@ -734,7 +739,12 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { return false; } - var httpVersion = begin.GetAsciiString(scan); + + string httpVersion; + if (!begin.GetKnownString(scan, out httpVersion)) + { + httpVersion = begin.GetAsciiString(scan); + } scan.Take(); if (scan.Take() != '\n') diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolIterator2.cs b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolIterator2.cs index 41551d056c..524c7a0278 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolIterator2.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolIterator2.cs @@ -138,6 +138,49 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure } } + public unsafe long PeekLong() + { + if (_block == null) + { + return -1; + } + else if (_block.End - _index >= sizeof(long)) + { + fixed (byte* ptr = _block.Array) + { + return *(long*)(ptr + _index); + } + } + else if (_block.Next == null) + { + return -1; + } + else + { + var blockBytes = _block.End - _index; + var nextBytes = sizeof(long) - blockBytes; + + if (_block.Next.End - _block.Next.Start < nextBytes) + { + return -1; + } + + long blockLong; + fixed (byte* ptr = _block.Array) + { + blockLong = *(long*)(ptr + _block.End - sizeof(long)); + } + + long nextLong; + fixed (byte* ptr = _block.Next.Array) + { + nextLong = *(long*)(ptr + _block.Next.Start); + } + + return (blockLong >> (sizeof(long) - blockBytes) * 8) | (nextLong << (sizeof(long) - nextBytes) * 8); + } + } + public int Seek(int char0) { if (IsDefault) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolIterator2Extensions.cs b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolIterator2Extensions.cs index d1f83c3d6e..1fbd76c5a8 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolIterator2Extensions.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolIterator2Extensions.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Diagnostics; using System.Text; namespace Microsoft.AspNet.Server.Kestrel.Infrastructure @@ -12,6 +13,62 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure private static Encoding _utf8 = Encoding.UTF8; + public const string HttpConnectMethod = "CONNECT"; + public const string HttpDeleteMethod = "DELETE"; + public const string HttpGetMethod = "GET"; + public const string HttpHeadMethod = "HEAD"; + public const string HttpPatchMethod = "PATCH"; + public const string HttpPostMethod = "POST"; + public const string HttpPutMethod = "PUT"; + public const string HttpOptionsMethod = "OPTIONS"; + public const string HttpTraceMethod = "TRACE"; + + public const string Http10Version = "HTTP/1.0"; + public const string Http11Version = "HTTP/1.1"; + + private static long _httpConnectMethodLong = GetAsciiStringAsLong("CONNECT\0"); + private static long _httpDeleteMethodLong = GetAsciiStringAsLong("DELETE\0\0"); + private static long _httpGetMethodLong = GetAsciiStringAsLong("GET\0\0\0\0\0"); + private static long _httpHeadMethodLong = GetAsciiStringAsLong("HEAD\0\0\0\0"); + private static long _httpPatchMethodLong = GetAsciiStringAsLong("PATCH\0\0\0"); + private static long _httpPostMethodLong = GetAsciiStringAsLong("POST\0\0\0\0"); + private static long _httpPutMethodLong = GetAsciiStringAsLong("PUT\0\0\0\0\0"); + private static long _httpOptionsMethodLong = GetAsciiStringAsLong("OPTIONS\0"); + private static long _httpTraceMethodLong = GetAsciiStringAsLong("TRACE\0\0\0"); + + private static long _http10VersionLong = GetAsciiStringAsLong("HTTP/1.0"); + private static long _http11VersionLong = GetAsciiStringAsLong("HTTP/1.1"); + + private const int PerfectHashDivisor = 37; + private static Tuple[] _knownStrings = new Tuple[PerfectHashDivisor]; + + static MemoryPoolIterator2Extensions() + { + _knownStrings[_httpConnectMethodLong % PerfectHashDivisor] = Tuple.Create(_httpConnectMethodLong, HttpConnectMethod); + _knownStrings[_httpDeleteMethodLong % PerfectHashDivisor] = Tuple.Create(_httpDeleteMethodLong, HttpDeleteMethod); + _knownStrings[_httpGetMethodLong % PerfectHashDivisor] = Tuple.Create(_httpGetMethodLong, HttpGetMethod); + _knownStrings[_httpHeadMethodLong % PerfectHashDivisor] = Tuple.Create(_httpHeadMethodLong, HttpHeadMethod); + _knownStrings[_httpPatchMethodLong % PerfectHashDivisor] = Tuple.Create(_httpPatchMethodLong, HttpPatchMethod); + _knownStrings[_httpPostMethodLong % PerfectHashDivisor] = Tuple.Create(_httpPostMethodLong, HttpPostMethod); + _knownStrings[_httpPutMethodLong % PerfectHashDivisor] = Tuple.Create(_httpPutMethodLong, HttpPutMethod); + _knownStrings[_httpOptionsMethodLong % PerfectHashDivisor] = Tuple.Create(_httpOptionsMethodLong, HttpOptionsMethod); + _knownStrings[_httpTraceMethodLong % PerfectHashDivisor] = Tuple.Create(_httpTraceMethodLong, HttpTraceMethod); + _knownStrings[_http10VersionLong % PerfectHashDivisor] = Tuple.Create(_http10VersionLong, Http10Version); + _knownStrings[_http11VersionLong % PerfectHashDivisor] = Tuple.Create(_http11VersionLong, Http11Version); + } + + private unsafe static long GetAsciiStringAsLong(string str) + { + Debug.Assert(str.Length == 8, "String must be exactly 8 (ASCII) characters long."); + + var bytes = Encoding.ASCII.GetBytes(str); + + fixed (byte* ptr = bytes) + { + return *(long*)ptr; + } + } + private static unsafe string GetAsciiStringStack(byte[] input, int inputOffset, int length) { // avoid declaring other local vars, or doing work with stackalloc @@ -20,6 +77,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure return GetAsciiStringImplementation(output, input, inputOffset, length); } + private static unsafe string GetAsciiStringImplementation(char* output, byte[] input, int inputOffset, int length) { for (var i = 0; i < length; i++) @@ -203,5 +261,55 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure start.CopyTo(array, 0, length, out length); return new ArraySegment(array, 0, length); } + + /// + /// Checks that up to 8 bytes between and correspond to a known HTTP string. + /// + /// + /// A "known HTTP string" can be an HTTP method name defined in the HTTP/1.1 RFC or an HTTP version (HTTP/1.0 or HTTP/1.1). + /// Since all of those fit in at most 8 bytes, they can be optimally looked up by reading those bytes as a long. Once + /// in that format, uninteresting bits are cleared and the remaining long modulo 37 is looked up in a table. + /// The number 37 was chosen because that number allows for a perfect hash of the set of + /// "known strings" (CONNECT, DELETE, GET, HEAD, PATCH, POST, PUT, OPTIONS, TRACE, HTTP/1.0 and HTTP/1.1, where strings + /// with less than 8 characters have 0s appended to their ends to fill for the missing bytes). + /// + /// The iterator from which to start the known string lookup. + /// The iterator pointing to the end of the input string. + /// A reference to a pre-allocated known string, if the input matches any. + /// true if the input matches a known string, false otherwise. + public static bool GetKnownString(this MemoryPoolIterator2 begin, MemoryPoolIterator2 end, out string knownString) + { + knownString = null; + + // This optimization only works on little endian environments (for now). + if (!BitConverter.IsLittleEndian) + { + return false; + } + + var inputLength = begin.GetLength(end); + + if (inputLength > sizeof(long)) + { + return false; + } + + var inputLong = begin.PeekLong(); + + if (inputLong == -1) + { + return false; + } + + inputLong &= (long)(unchecked((ulong)~0) >> ((sizeof(long) - inputLength) * 8)); + + var value = _knownStrings[inputLong % PerfectHashDivisor]; + if (value != null && value.Item1 == inputLong) + { + knownString = value.Item2; + } + + return knownString != null; + } } } diff --git a/test/Microsoft.AspNet.Server.KestrelTests/MemoryPoolIterator2Tests.cs b/test/Microsoft.AspNet.Server.KestrelTests/MemoryPoolIterator2Tests.cs index b7d101c28c..7368bf08d9 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/MemoryPoolIterator2Tests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/MemoryPoolIterator2Tests.cs @@ -128,5 +128,104 @@ namespace Microsoft.AspNet.Server.KestrelTests // Can't put anything by the end Assert.False(head.Put(0xFF)); } + + [Fact] + public void PeekLong() + { + // Arrange + var block = _pool.Lease(); + var bytes = BitConverter.GetBytes(0x0102030405060708); + Buffer.BlockCopy(bytes, 0, block.Array, block.Start, bytes.Length); + block.End += bytes.Length; + var scan = block.GetIterator(); + var originalIndex = scan.Index; + + // Act + var result = scan.PeekLong(); + + // Assert + Assert.Equal(0x0102030405060708, result); + Assert.Equal(originalIndex, scan.Index); + } + + [Theory] + [InlineData(1)] + [InlineData(2)] + [InlineData(3)] + [InlineData(4)] + [InlineData(5)] + [InlineData(6)] + [InlineData(7)] + public void PeekLongAtBlockBoundary(int blockBytes) + { + // Arrange + var nextBlockBytes = 8 - blockBytes; + + var block = _pool.Lease(); + block.End += blockBytes; + + var nextBlock = _pool.Lease(); + nextBlock.End += nextBlockBytes; + + block.Next = nextBlock; + + var bytes = BitConverter.GetBytes(0x0102030405060708); + Buffer.BlockCopy(bytes, 0, block.Array, block.Start, blockBytes); + Buffer.BlockCopy(bytes, blockBytes, nextBlock.Array, nextBlock.Start, nextBlockBytes); + + var scan = block.GetIterator(); + var originalIndex = scan.Index; + + // Act + var result = scan.PeekLong(); + + // Assert + Assert.Equal(0x0102030405060708, result); + Assert.Equal(originalIndex, scan.Index); + } + + [Theory] + [InlineData("CONNECT / HTTP/1.1", ' ', true, MemoryPoolIterator2Extensions.HttpConnectMethod)] + [InlineData("DELETE / HTTP/1.1", ' ', true, MemoryPoolIterator2Extensions.HttpDeleteMethod)] + [InlineData("GET / HTTP/1.1", ' ', true, MemoryPoolIterator2Extensions.HttpGetMethod)] + [InlineData("HEAD / HTTP/1.1", ' ', true, MemoryPoolIterator2Extensions.HttpHeadMethod)] + [InlineData("PATCH / HTTP/1.1", ' ', true, MemoryPoolIterator2Extensions.HttpPatchMethod)] + [InlineData("POST / HTTP/1.1", ' ', true, MemoryPoolIterator2Extensions.HttpPostMethod)] + [InlineData("PUT / HTTP/1.1", ' ', true, MemoryPoolIterator2Extensions.HttpPutMethod)] + [InlineData("OPTIONS / HTTP/1.1", ' ', true, MemoryPoolIterator2Extensions.HttpOptionsMethod)] + [InlineData("TRACE / HTTP/1.1", ' ', true, MemoryPoolIterator2Extensions.HttpTraceMethod)] + [InlineData("HTTP/1.0\r", '\r', true, MemoryPoolIterator2Extensions.Http10Version)] + [InlineData("HTTP/1.1\r", '\r', true, MemoryPoolIterator2Extensions.Http11Version)] + [InlineData("GET/ HTTP/1.1", ' ', false, null)] + [InlineData("get / HTTP/1.1", ' ', false, null)] + [InlineData("GOT / HTTP/1.1", ' ', false, null)] + [InlineData("ABC / HTTP/1.1", ' ', false, null)] + [InlineData("PO / HTTP/1.1", ' ', false, null)] + [InlineData("PO ST / HTTP/1.1", ' ', false, null)] + [InlineData("HTTP/1.0_\r", '\r', false, null)] + [InlineData("HTTP/1.1_\r", '\r', false, null)] + [InlineData("HTTP/3.0\r", '\r', false, null)] + [InlineData("http/1.0\r", '\r', false, null)] + [InlineData("http/1.1\r", '\r', false, null)] + [InlineData("short ", ' ', false, null)] + public void GetsKnownString(string input, char endChar, bool expectedResult, string expectedKnownString) + { + // Arrange + var block = _pool.Lease(); + var chars = input.ToCharArray().Select(c => (byte)c).ToArray(); + Buffer.BlockCopy(chars, 0, block.Array, block.Start, chars.Length); + block.End += chars.Length; + var begin = block.GetIterator(); + var end = begin; + end.Seek(endChar); + string knownString; + + // Act + var result = begin.GetKnownString(end, out knownString); + + // Assert + Assert.Equal(expectedResult, result); + Assert.Equal(expectedKnownString, knownString); + } } } From f5e45accac52a6814af581a19ae8ed828170e44a Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Tue, 15 Dec 2015 04:24:54 +0000 Subject: [PATCH 0517/1662] Amortize Stream Costs --- .../Http/Frame.cs | 4 +++ .../Http/FrameOfT.cs | 8 +++--- .../Http/FrameRequestStream.cs | 26 ++++++++++++++----- .../Http/FrameResponseStream.cs | 20 +++++++++++--- .../MessageBodyTests.cs | 6 ++--- 5 files changed, 45 insertions(+), 19 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs index 426f17b283..5dfca52bb9 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs @@ -57,6 +57,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http internal FrameRequestStream _requestBody; internal FrameResponseStream _responseBody; + internal FrameDuplexStream _duplexStream; protected bool _responseStarted; protected bool _keepAlive; @@ -86,6 +87,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Http _localEndPoint = localEndPoint; _prepareRequest = prepareRequest; _pathBase = context.ServerAddress.PathBase; + _requestBody = new FrameRequestStream(); + _responseBody = new FrameResponseStream(this); + _duplexStream = new FrameDuplexStream(_requestBody, _responseBody); FrameControl = this; Reset(); diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameOfT.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameOfT.cs index 4410cdc8cd..9e932e2380 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameOfT.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameOfT.cs @@ -64,11 +64,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { var messageBody = MessageBody.For(HttpVersion, _requestHeaders, this); _keepAlive = messageBody.RequestKeepAlive; - _requestBody = new FrameRequestStream(messageBody); - RequestBody = _requestBody; - _responseBody = new FrameResponseStream(this); - ResponseBody = _responseBody; - DuplexStream = new FrameDuplexStream(RequestBody, ResponseBody); + RequestBody = _requestBody.StartAcceptingReads(messageBody); + ResponseBody = _responseBody.StartAcceptingWrites(); + DuplexStream = _duplexStream; _abortedCts = null; _manuallySetRequestAbortToken = null; diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameRequestStream.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameRequestStream.cs index 2c19b40dd8..c008d7cfc5 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameRequestStream.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameRequestStream.cs @@ -10,12 +10,12 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { public class FrameRequestStream : Stream { - private readonly MessageBody _body; + private MessageBody _body; private StreamState _state; - public FrameRequestStream(MessageBody body) + public FrameRequestStream() { - _body = body; + _state = StreamState.Closed; } public override bool CanRead { get { return true; } } @@ -112,18 +112,30 @@ namespace Microsoft.AspNet.Server.Kestrel.Http throw new NotImplementedException(); } + public Stream StartAcceptingReads(MessageBody body) + { + // Only start if not aborted + if (_state == StreamState.Closed) + { + _state = StreamState.Open; + _body = body; + } + return this; + } + public void StopAcceptingReads() { // Can't use dispose (or close) as can be disposed too early by user code // As exampled in EngineTests.ZeroContentLengthNotSetAutomaticallyForCertainStatusCodes - _state = StreamState.Disposed; + _state = StreamState.Closed; + _body = null; } public void Abort() { // We don't want to throw an ODE until the app func actually completes. // If the request is aborted, we throw an IOException instead. - if (_state != StreamState.Disposed) + if (_state != StreamState.Closed) { _state = StreamState.Aborted; } @@ -135,7 +147,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { case StreamState.Open: return; - case StreamState.Disposed: + case StreamState.Closed: throw new ObjectDisposedException(nameof(FrameRequestStream)); case StreamState.Aborted: throw new IOException("The request has been aborted."); @@ -145,7 +157,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http private enum StreamState { Open, - Disposed, + Closed, Aborted } } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameResponseStream.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameResponseStream.cs index 827234f872..832a112274 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameResponseStream.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameResponseStream.cs @@ -16,6 +16,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http public FrameResponseStream(FrameContext context) { _context = context; + _state = StreamState.Closed; } public override bool CanRead => false; @@ -77,18 +78,29 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return _context.FrameControl.WriteAsync(new ArraySegment(buffer, offset, count), cancellationToken); } + public Stream StartAcceptingWrites() + { + // Only start if not aborted + if (_state == StreamState.Closed) + { + _state = StreamState.Open; + } + + return this; + } + public void StopAcceptingWrites() { // Can't use dispose (or close) as can be disposed too early by user code // As exampled in EngineTests.ZeroContentLengthNotSetAutomaticallyForCertainStatusCodes - _state = StreamState.Disposed; + _state = StreamState.Closed; } public void Abort() { // We don't want to throw an ODE until the app func actually completes. // If the request is aborted, we throw an IOException instead. - if (_state != StreamState.Disposed) + if (_state != StreamState.Closed) { _state = StreamState.Aborted; } @@ -100,7 +112,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { case StreamState.Open: return; - case StreamState.Disposed: + case StreamState.Closed: throw new ObjectDisposedException(nameof(FrameResponseStream)); case StreamState.Aborted: throw new IOException("The request has been aborted."); @@ -110,7 +122,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http private enum StreamState { Open, - Disposed, + Closed, Aborted } } diff --git a/test/Microsoft.AspNet.Server.KestrelTests/MessageBodyTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/MessageBodyTests.cs index b5dbfc021a..19e7d2e9b2 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/MessageBodyTests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/MessageBodyTests.cs @@ -21,7 +21,7 @@ namespace Microsoft.AspNet.Server.KestrelTests { var input = new TestInput(); var body = MessageBody.For("HTTP/1.0", new Dictionary(), input.FrameContext); - var stream = new FrameRequestStream(body); + var stream = new FrameRequestStream().StartAcceptingReads(body); input.Add("Hello", true); @@ -39,7 +39,7 @@ namespace Microsoft.AspNet.Server.KestrelTests { var input = new TestInput(); var body = MessageBody.For("HTTP/1.0", new Dictionary(), input.FrameContext); - var stream = new FrameRequestStream(body); + var stream = new FrameRequestStream().StartAcceptingReads(body); input.Add("Hello", true); @@ -57,7 +57,7 @@ namespace Microsoft.AspNet.Server.KestrelTests { var input = new TestInput(); var body = MessageBody.For("HTTP/1.0", new Dictionary(), input.FrameContext); - var stream = new FrameRequestStream(body); + var stream = new FrameRequestStream().StartAcceptingReads(body); // Input needs to be greater than 4032 bytes to allocate a block not backed by a slab. var largeInput = new string('a', 8192); From 841ec734970b06df87d0921fc06551e3a6883cb1 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Tue, 15 Dec 2015 04:46:05 +0000 Subject: [PATCH 0518/1662] Prevent OnComplete modifying Streams --- .../Http/FrameOfT.cs | 5 +++++ .../Http/FrameRequestStream.cs | 13 +++++++++++++ .../Http/FrameResponseStream.cs | 13 +++++++++++++ 3 files changed, 31 insertions(+) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameOfT.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameOfT.cs index 9e932e2380..d9afe93d92 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameOfT.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameOfT.cs @@ -91,6 +91,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Http await FireOnStarting(); } + _requestBody.PauseAcceptingReads(); + _responseBody.PauseAcceptingWrites(); + if (_onCompleted != null) { await FireOnCompleted(); @@ -101,10 +104,12 @@ namespace Microsoft.AspNet.Server.Kestrel.Http // If _requestAbort is set, the connection has already been closed. if (!_requestAborted) { + _responseBody.ResumeAcceptingWrites(); await ProduceEnd(); if (_keepAlive) { + _requestBody.ResumeAcceptingReads(); // Finish reading the request body in case the app did not. await messageBody.Consume(); } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameRequestStream.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameRequestStream.cs index c008d7cfc5..0c8ea64e81 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameRequestStream.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameRequestStream.cs @@ -123,6 +123,19 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return this; } + public void PauseAcceptingReads() + { + _state = StreamState.Closed; + } + + public void ResumeAcceptingReads() + { + if (_state == StreamState.Closed) + { + _state = StreamState.Open; + } + } + public void StopAcceptingReads() { // Can't use dispose (or close) as can be disposed too early by user code diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameResponseStream.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameResponseStream.cs index 832a112274..9d0658f89b 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameResponseStream.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameResponseStream.cs @@ -89,6 +89,19 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return this; } + public void PauseAcceptingWrites() + { + _state = StreamState.Closed; + } + + public void ResumeAcceptingWrites() + { + if (_state == StreamState.Closed) + { + _state = StreamState.Open; + } + } + public void StopAcceptingWrites() { // Can't use dispose (or close) as can be disposed too early by user code From 9fa9c45eda32528f34e0ca564e6fe7581fc6d653 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Tue, 15 Dec 2015 06:34:30 +0000 Subject: [PATCH 0519/1662] ReuseStreams config and tests --- .../Http/Frame.cs | 9 +- .../Http/FrameOfT.cs | 9 ++ .../Http/FrameRequestStream.cs | 33 ++--- .../Http/FrameResponseStream.cs | 33 ++--- .../Http/FrameStreamState.cs | 12 ++ .../IKestrelServerInformation.cs | 13 ++ .../KestrelServer.cs | 3 +- .../KestrelServerInformation.cs | 16 +++ .../ServiceContext.cs | 3 + .../ReuseStreamsTests.cs | 127 ++++++++++++++++++ .../KestrelServerInformationTests.cs | 25 ++++ 11 files changed, 239 insertions(+), 44 deletions(-) create mode 100644 src/Microsoft.AspNet.Server.Kestrel/Http/FrameStreamState.cs create mode 100644 test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/ReuseStreamsTests.cs diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs index 5dfca52bb9..74f3ef6889 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs @@ -87,9 +87,12 @@ namespace Microsoft.AspNet.Server.Kestrel.Http _localEndPoint = localEndPoint; _prepareRequest = prepareRequest; _pathBase = context.ServerAddress.PathBase; - _requestBody = new FrameRequestStream(); - _responseBody = new FrameResponseStream(this); - _duplexStream = new FrameDuplexStream(_requestBody, _responseBody); + if (ReuseStreams) + { + _requestBody = new FrameRequestStream(); + _responseBody = new FrameResponseStream(this); + _duplexStream = new FrameDuplexStream(_requestBody, _responseBody); + } FrameControl = this; Reset(); diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameOfT.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameOfT.cs index d9afe93d92..32b067fc76 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameOfT.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameOfT.cs @@ -64,6 +64,15 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { var messageBody = MessageBody.For(HttpVersion, _requestHeaders, this); _keepAlive = messageBody.RequestKeepAlive; + + // _duplexStream may be null if flag switched while running + if (!ReuseStreams || _duplexStream == null) + { + _requestBody = new FrameRequestStream(); + _responseBody = new FrameResponseStream(this); + _duplexStream = new FrameDuplexStream(_requestBody, _responseBody); + } + RequestBody = _requestBody.StartAcceptingReads(messageBody); ResponseBody = _responseBody.StartAcceptingWrites(); DuplexStream = _duplexStream; diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameRequestStream.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameRequestStream.cs index 0c8ea64e81..f9ff5a4197 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameRequestStream.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameRequestStream.cs @@ -11,11 +11,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http public class FrameRequestStream : Stream { private MessageBody _body; - private StreamState _state; + private FrameStreamState _state; public FrameRequestStream() { - _state = StreamState.Closed; + _state = FrameStreamState.Closed; } public override bool CanRead { get { return true; } } @@ -115,9 +115,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Http public Stream StartAcceptingReads(MessageBody body) { // Only start if not aborted - if (_state == StreamState.Closed) + if (_state == FrameStreamState.Closed) { - _state = StreamState.Open; + _state = FrameStreamState.Open; _body = body; } return this; @@ -125,14 +125,14 @@ namespace Microsoft.AspNet.Server.Kestrel.Http public void PauseAcceptingReads() { - _state = StreamState.Closed; + _state = FrameStreamState.Closed; } public void ResumeAcceptingReads() { - if (_state == StreamState.Closed) + if (_state == FrameStreamState.Closed) { - _state = StreamState.Open; + _state = FrameStreamState.Open; } } @@ -140,7 +140,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { // Can't use dispose (or close) as can be disposed too early by user code // As exampled in EngineTests.ZeroContentLengthNotSetAutomaticallyForCertainStatusCodes - _state = StreamState.Closed; + _state = FrameStreamState.Closed; _body = null; } @@ -148,9 +148,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { // We don't want to throw an ODE until the app func actually completes. // If the request is aborted, we throw an IOException instead. - if (_state != StreamState.Closed) + if (_state != FrameStreamState.Closed) { - _state = StreamState.Aborted; + _state = FrameStreamState.Aborted; } } @@ -158,20 +158,13 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { switch (_state) { - case StreamState.Open: + case FrameStreamState.Open: return; - case StreamState.Closed: + case FrameStreamState.Closed: throw new ObjectDisposedException(nameof(FrameRequestStream)); - case StreamState.Aborted: + case FrameStreamState.Aborted: throw new IOException("The request has been aborted."); } } - - private enum StreamState - { - Open, - Closed, - Aborted - } } } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameResponseStream.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameResponseStream.cs index 9d0658f89b..e544723af4 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameResponseStream.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameResponseStream.cs @@ -11,12 +11,12 @@ namespace Microsoft.AspNet.Server.Kestrel.Http class FrameResponseStream : Stream { private readonly FrameContext _context; - private StreamState _state; + private FrameStreamState _state; public FrameResponseStream(FrameContext context) { _context = context; - _state = StreamState.Closed; + _state = FrameStreamState.Closed; } public override bool CanRead => false; @@ -81,9 +81,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Http public Stream StartAcceptingWrites() { // Only start if not aborted - if (_state == StreamState.Closed) + if (_state == FrameStreamState.Closed) { - _state = StreamState.Open; + _state = FrameStreamState.Open; } return this; @@ -91,14 +91,14 @@ namespace Microsoft.AspNet.Server.Kestrel.Http public void PauseAcceptingWrites() { - _state = StreamState.Closed; + _state = FrameStreamState.Closed; } public void ResumeAcceptingWrites() { - if (_state == StreamState.Closed) + if (_state == FrameStreamState.Closed) { - _state = StreamState.Open; + _state = FrameStreamState.Open; } } @@ -106,16 +106,16 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { // Can't use dispose (or close) as can be disposed too early by user code // As exampled in EngineTests.ZeroContentLengthNotSetAutomaticallyForCertainStatusCodes - _state = StreamState.Closed; + _state = FrameStreamState.Closed; } public void Abort() { // We don't want to throw an ODE until the app func actually completes. // If the request is aborted, we throw an IOException instead. - if (_state != StreamState.Closed) + if (_state != FrameStreamState.Closed) { - _state = StreamState.Aborted; + _state = FrameStreamState.Aborted; } } @@ -123,20 +123,13 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { switch (_state) { - case StreamState.Open: + case FrameStreamState.Open: return; - case StreamState.Closed: + case FrameStreamState.Closed: throw new ObjectDisposedException(nameof(FrameResponseStream)); - case StreamState.Aborted: + case FrameStreamState.Aborted: throw new IOException("The request has been aborted."); } } - - private enum StreamState - { - Open, - Closed, - Aborted - } } } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameStreamState.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameStreamState.cs new file mode 100644 index 0000000000..12c393ee1a --- /dev/null +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameStreamState.cs @@ -0,0 +1,12 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +namespace Microsoft.AspNet.Server.Kestrel.Http +{ + enum FrameStreamState + { + Open, + Closed, + Aborted + } +} diff --git a/src/Microsoft.AspNet.Server.Kestrel/IKestrelServerInformation.cs b/src/Microsoft.AspNet.Server.Kestrel/IKestrelServerInformation.cs index 870fe2e533..3a634afae8 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/IKestrelServerInformation.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/IKestrelServerInformation.cs @@ -11,6 +11,19 @@ namespace Microsoft.AspNet.Server.Kestrel bool NoDelay { get; set; } + /// + /// Gets or sets a flag that instructs whether it is safe to + /// reuse the Request and Response objects + /// for another request after the Response's OnCompleted callback has fired. + /// When this is set to true it is not safe to retain references to these streams after this event has fired. + /// It is false by default. + /// + /// + /// When this is set to true it is not safe to retain references to these streams after this event has fired. + /// It is false by default. + /// + bool ReuseStreams { get; set; } + IConnectionFilter ConnectionFilter { get; set; } } } diff --git a/src/Microsoft.AspNet.Server.Kestrel/KestrelServer.cs b/src/Microsoft.AspNet.Server.Kestrel/KestrelServer.cs index 3a1295de76..34cef6394b 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/KestrelServer.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/KestrelServer.cs @@ -67,7 +67,8 @@ namespace Microsoft.AspNet.Server.Kestrel ThreadPool = new LoggingThreadPool(trace), DateHeaderValueManager = dateHeaderValueManager, ConnectionFilter = information.ConnectionFilter, - NoDelay = information.NoDelay + NoDelay = information.NoDelay, + ReuseStreams = information.ReuseStreams }); _disposables.Push(engine); diff --git a/src/Microsoft.AspNet.Server.Kestrel/KestrelServerInformation.cs b/src/Microsoft.AspNet.Server.Kestrel/KestrelServerInformation.cs index f9f4ae8c8e..8ff73cc03e 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/KestrelServerInformation.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/KestrelServerInformation.cs @@ -22,6 +22,7 @@ namespace Microsoft.AspNet.Server.Kestrel Addresses = GetAddresses(configuration); ThreadCount = GetThreadCount(configuration); NoDelay = GetNoDelay(configuration); + ReuseStreams = GetReuseStreams(configuration); } public ICollection Addresses { get; } @@ -30,6 +31,8 @@ namespace Microsoft.AspNet.Server.Kestrel public bool NoDelay { get; set; } + public bool ReuseStreams { get; set; } + public IConnectionFilter ConnectionFilter { get; set; } private static int ProcessorThreadCount @@ -107,5 +110,18 @@ namespace Microsoft.AspNet.Server.Kestrel return true; } + + private static bool GetReuseStreams(IConfiguration configuration) + { + var reuseStreamsString = configuration["kestrel.reuseStreams"]; + + bool reuseStreams; + if (bool.TryParse(reuseStreamsString, out reuseStreams)) + { + return reuseStreams; + } + + return false; + } } } diff --git a/src/Microsoft.AspNet.Server.Kestrel/ServiceContext.cs b/src/Microsoft.AspNet.Server.Kestrel/ServiceContext.cs index 31eeea898d..4bab512ced 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/ServiceContext.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/ServiceContext.cs @@ -26,6 +26,7 @@ namespace Microsoft.AspNet.Server.Kestrel DateHeaderValueManager = context.DateHeaderValueManager; ConnectionFilter = context.ConnectionFilter; NoDelay = context.NoDelay; + ReuseStreams = context.ReuseStreams; } public IApplicationLifetime AppLifetime { get; set; } @@ -41,5 +42,7 @@ namespace Microsoft.AspNet.Server.Kestrel public IConnectionFilter ConnectionFilter { get; set; } public bool NoDelay { get; set; } + + public bool ReuseStreams { get; set; } } } diff --git a/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/ReuseStreamsTests.cs b/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/ReuseStreamsTests.cs new file mode 100644 index 0000000000..d61a2759e2 --- /dev/null +++ b/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/ReuseStreamsTests.cs @@ -0,0 +1,127 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Collections.Generic; +using System.IO; +using System.Net.Http; +using System.Threading.Tasks; +using Microsoft.AspNet.Builder; +using Microsoft.AspNet.Hosting; +using Microsoft.AspNet.Http.Features; +using Microsoft.Extensions.Configuration; +using Xunit; + +namespace Microsoft.AspNet.Server.Kestrel.FunctionalTests +{ + public class ReuseStreamsTests + { + [Fact] + public async Task ReuseStreamsOn() + { + var streamCount = 0; + var loopCount = 20; + Stream lastStream = null; + var config = new ConfigurationBuilder() + .AddInMemoryCollection(new Dictionary + { + { "server.urls", "http://localhost:8801/" }, + { "kestrel.reuseStreams", "true" } + }) + .Build(); + + var hostBuilder = new WebHostBuilder(config); + hostBuilder.UseServerFactory("Microsoft.AspNet.Server.Kestrel"); + hostBuilder.UseStartup(app => + { + var serverInfo = app.ServerFeatures.Get(); + app.Run(context => + { + if (context.Request.Body != lastStream) + { + lastStream = context.Request.Body; + streamCount++; + } + return context.Request.Body.CopyToAsync(context.Response.Body); + }); + }); + + using (var app = hostBuilder.Build().Start()) + { + using (var client = new HttpClient()) + { + for (int i = 0; i < loopCount; i++) + { + var content = $"{i} Hello World {i}"; + var request = new HttpRequestMessage() + { + RequestUri = new Uri("http://localhost:8801/"), + Method = HttpMethod.Post, + Content = new StringContent(content) + }; + request.Headers.Add("Connection", new string[] { "Keep-Alive" }); + var responseMessage = await client.SendAsync(request); + var result = await responseMessage.Content.ReadAsStringAsync(); + Assert.Equal(content, result); + } + } + } + + Assert.True(streamCount < loopCount); + } + + [Fact] + public async Task ReuseStreamsOff() + { + var streamCount = 0; + var loopCount = 20; + Stream lastStream = null; + var config = new ConfigurationBuilder() + .AddInMemoryCollection(new Dictionary + { + { "server.urls", "http://localhost:8802/" }, + { "kestrel.reuseStreams", "false" } + }) + .Build(); + + var hostBuilder = new WebHostBuilder(config); + hostBuilder.UseServerFactory("Microsoft.AspNet.Server.Kestrel"); + hostBuilder.UseStartup(app => + { + var serverInfo = app.ServerFeatures.Get(); + app.Run(context => + { + if (context.Request.Body != lastStream) + { + lastStream = context.Request.Body; + streamCount++; + } + return context.Request.Body.CopyToAsync(context.Response.Body); + }); + }); + + using (var app = hostBuilder.Build().Start()) + { + using (var client = new HttpClient()) + { + for (int i = 0; i < loopCount; i++) + { + var content = $"{i} Hello World {i}"; + var request = new HttpRequestMessage() + { + RequestUri = new Uri("http://localhost:8802/"), + Method = HttpMethod.Post, + Content = new StringContent(content) + }; + request.Headers.Add("Connection", new string[] { "Keep-Alive" }); + var responseMessage = await client.SendAsync(request); + var result = await responseMessage.Content.ReadAsStringAsync(); + Assert.Equal(content, result); + } + } + } + + Assert.Equal(loopCount, streamCount); + } + } +} diff --git a/test/Microsoft.AspNet.Server.KestrelTests/KestrelServerInformationTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/KestrelServerInformationTests.cs index 2513d93e84..e2376c0d94 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/KestrelServerInformationTests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/KestrelServerInformationTests.cs @@ -85,6 +85,31 @@ namespace Microsoft.AspNet.Server.KestrelTests Assert.False(information.NoDelay); } + [Theory] + [InlineData(null, false)] + [InlineData("", false)] + [InlineData("false", false)] + [InlineData("False", false)] + [InlineData("true", true)] + [InlineData("True", true)] + [InlineData("Foo", false)] + [InlineData("FooBar", false)] + public void SetReuseStreamsUsingConfiguration(string input, bool expected) + { + var values = new Dictionary + { + { "kestrel.reuseStreams", input } + }; + + var configuration = new ConfigurationBuilder() + .AddInMemoryCollection(values) + .Build(); + + var information = new KestrelServerInformation(configuration); + + Assert.Equal(expected, information.ReuseStreams); + } + private static int Clamp(int value, int min, int max) { return value < min ? min : value > max ? max : value; From 559cd51255a1e63726e3d67b7b65d43de56a296e Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Wed, 16 Dec 2015 20:41:01 +0000 Subject: [PATCH 0520/1662] Faster Headers.ClearFast --- .../Http/FrameHeaders.Generated.cs | 506 ++++++++++++------ .../KnownHeaders.cs | 10 +- 2 files changed, 360 insertions(+), 156 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameHeaders.Generated.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameHeaders.Generated.cs index df6761e3e0..16c80b3980 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameHeaders.Generated.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameHeaders.Generated.cs @@ -60,7 +60,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { get { - return _CacheControl; + if (((_bits & 1L) != 0)) + { + return _CacheControl; + } + return StringValues.Empty; } set { @@ -72,7 +76,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { get { - return _Connection; + if (((_bits & 2L) != 0)) + { + return _Connection; + } + return StringValues.Empty; } set { @@ -84,7 +92,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { get { - return _Date; + if (((_bits & 4L) != 0)) + { + return _Date; + } + return StringValues.Empty; } set { @@ -96,7 +108,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { get { - return _KeepAlive; + if (((_bits & 8L) != 0)) + { + return _KeepAlive; + } + return StringValues.Empty; } set { @@ -108,7 +124,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { get { - return _Pragma; + if (((_bits & 16L) != 0)) + { + return _Pragma; + } + return StringValues.Empty; } set { @@ -120,7 +140,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { get { - return _Trailer; + if (((_bits & 32L) != 0)) + { + return _Trailer; + } + return StringValues.Empty; } set { @@ -132,7 +156,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { get { - return _TransferEncoding; + if (((_bits & 64L) != 0)) + { + return _TransferEncoding; + } + return StringValues.Empty; } set { @@ -144,7 +172,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { get { - return _Upgrade; + if (((_bits & 128L) != 0)) + { + return _Upgrade; + } + return StringValues.Empty; } set { @@ -156,7 +188,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { get { - return _Via; + if (((_bits & 256L) != 0)) + { + return _Via; + } + return StringValues.Empty; } set { @@ -168,7 +204,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { get { - return _Warning; + if (((_bits & 512L) != 0)) + { + return _Warning; + } + return StringValues.Empty; } set { @@ -180,7 +220,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { get { - return _Allow; + if (((_bits & 1024L) != 0)) + { + return _Allow; + } + return StringValues.Empty; } set { @@ -192,7 +236,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { get { - return _ContentLength; + if (((_bits & 2048L) != 0)) + { + return _ContentLength; + } + return StringValues.Empty; } set { @@ -204,7 +252,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { get { - return _ContentType; + if (((_bits & 4096L) != 0)) + { + return _ContentType; + } + return StringValues.Empty; } set { @@ -216,7 +268,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { get { - return _ContentEncoding; + if (((_bits & 8192L) != 0)) + { + return _ContentEncoding; + } + return StringValues.Empty; } set { @@ -228,7 +284,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { get { - return _ContentLanguage; + if (((_bits & 16384L) != 0)) + { + return _ContentLanguage; + } + return StringValues.Empty; } set { @@ -240,7 +300,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { get { - return _ContentLocation; + if (((_bits & 32768L) != 0)) + { + return _ContentLocation; + } + return StringValues.Empty; } set { @@ -252,7 +316,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { get { - return _ContentMD5; + if (((_bits & 65536L) != 0)) + { + return _ContentMD5; + } + return StringValues.Empty; } set { @@ -264,7 +332,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { get { - return _ContentRange; + if (((_bits & 131072L) != 0)) + { + return _ContentRange; + } + return StringValues.Empty; } set { @@ -276,7 +348,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { get { - return _Expires; + if (((_bits & 262144L) != 0)) + { + return _Expires; + } + return StringValues.Empty; } set { @@ -288,7 +364,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { get { - return _LastModified; + if (((_bits & 524288L) != 0)) + { + return _LastModified; + } + return StringValues.Empty; } set { @@ -300,7 +380,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { get { - return _Accept; + if (((_bits & 1048576L) != 0)) + { + return _Accept; + } + return StringValues.Empty; } set { @@ -312,7 +396,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { get { - return _AcceptCharset; + if (((_bits & 2097152L) != 0)) + { + return _AcceptCharset; + } + return StringValues.Empty; } set { @@ -324,7 +412,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { get { - return _AcceptEncoding; + if (((_bits & 4194304L) != 0)) + { + return _AcceptEncoding; + } + return StringValues.Empty; } set { @@ -336,7 +428,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { get { - return _AcceptLanguage; + if (((_bits & 8388608L) != 0)) + { + return _AcceptLanguage; + } + return StringValues.Empty; } set { @@ -348,7 +444,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { get { - return _Authorization; + if (((_bits & 16777216L) != 0)) + { + return _Authorization; + } + return StringValues.Empty; } set { @@ -360,7 +460,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { get { - return _Cookie; + if (((_bits & 33554432L) != 0)) + { + return _Cookie; + } + return StringValues.Empty; } set { @@ -372,7 +476,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { get { - return _Expect; + if (((_bits & 67108864L) != 0)) + { + return _Expect; + } + return StringValues.Empty; } set { @@ -384,7 +492,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { get { - return _From; + if (((_bits & 134217728L) != 0)) + { + return _From; + } + return StringValues.Empty; } set { @@ -396,7 +508,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { get { - return _Host; + if (((_bits & 268435456L) != 0)) + { + return _Host; + } + return StringValues.Empty; } set { @@ -408,7 +524,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { get { - return _IfMatch; + if (((_bits & 536870912L) != 0)) + { + return _IfMatch; + } + return StringValues.Empty; } set { @@ -420,7 +540,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { get { - return _IfModifiedSince; + if (((_bits & 1073741824L) != 0)) + { + return _IfModifiedSince; + } + return StringValues.Empty; } set { @@ -432,7 +556,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { get { - return _IfNoneMatch; + if (((_bits & 2147483648L) != 0)) + { + return _IfNoneMatch; + } + return StringValues.Empty; } set { @@ -444,7 +572,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { get { - return _IfRange; + if (((_bits & 4294967296L) != 0)) + { + return _IfRange; + } + return StringValues.Empty; } set { @@ -456,7 +588,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { get { - return _IfUnmodifiedSince; + if (((_bits & 8589934592L) != 0)) + { + return _IfUnmodifiedSince; + } + return StringValues.Empty; } set { @@ -468,7 +604,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { get { - return _MaxForwards; + if (((_bits & 17179869184L) != 0)) + { + return _MaxForwards; + } + return StringValues.Empty; } set { @@ -480,7 +620,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { get { - return _ProxyAuthorization; + if (((_bits & 34359738368L) != 0)) + { + return _ProxyAuthorization; + } + return StringValues.Empty; } set { @@ -492,7 +636,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { get { - return _Referer; + if (((_bits & 68719476736L) != 0)) + { + return _Referer; + } + return StringValues.Empty; } set { @@ -504,7 +652,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { get { - return _Range; + if (((_bits & 137438953472L) != 0)) + { + return _Range; + } + return StringValues.Empty; } set { @@ -516,7 +668,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { get { - return _TE; + if (((_bits & 274877906944L) != 0)) + { + return _TE; + } + return StringValues.Empty; } set { @@ -528,7 +684,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { get { - return _Translate; + if (((_bits & 549755813888L) != 0)) + { + return _Translate; + } + return StringValues.Empty; } set { @@ -540,7 +700,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { get { - return _UserAgent; + if (((_bits & 1099511627776L) != 0)) + { + return _UserAgent; + } + return StringValues.Empty; } set { @@ -3309,49 +3473,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Http protected override void ClearFast() { _bits = 0; - - _CacheControl = StringValues.Empty; - _Connection = StringValues.Empty; - _Date = StringValues.Empty; - _KeepAlive = StringValues.Empty; - _Pragma = StringValues.Empty; - _Trailer = StringValues.Empty; - _TransferEncoding = StringValues.Empty; - _Upgrade = StringValues.Empty; - _Via = StringValues.Empty; - _Warning = StringValues.Empty; - _Allow = StringValues.Empty; - _ContentLength = StringValues.Empty; - _ContentType = StringValues.Empty; - _ContentEncoding = StringValues.Empty; - _ContentLanguage = StringValues.Empty; - _ContentLocation = StringValues.Empty; - _ContentMD5 = StringValues.Empty; - _ContentRange = StringValues.Empty; - _Expires = StringValues.Empty; - _LastModified = StringValues.Empty; - _Accept = StringValues.Empty; - _AcceptCharset = StringValues.Empty; - _AcceptEncoding = StringValues.Empty; - _AcceptLanguage = StringValues.Empty; - _Authorization = StringValues.Empty; - _Cookie = StringValues.Empty; - _Expect = StringValues.Empty; - _From = StringValues.Empty; - _Host = StringValues.Empty; - _IfMatch = StringValues.Empty; - _IfModifiedSince = StringValues.Empty; - _IfNoneMatch = StringValues.Empty; - _IfRange = StringValues.Empty; - _IfUnmodifiedSince = StringValues.Empty; - _MaxForwards = StringValues.Empty; - _ProxyAuthorization = StringValues.Empty; - _Referer = StringValues.Empty; - _Range = StringValues.Empty; - _TE = StringValues.Empty; - _Translate = StringValues.Empty; - _UserAgent = StringValues.Empty; - MaybeUnknown?.Clear(); } @@ -4992,7 +5113,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { get { - return _CacheControl; + if (((_bits & 1L) != 0)) + { + return _CacheControl; + } + return StringValues.Empty; } set { @@ -5004,7 +5129,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { get { - return _Connection; + if (((_bits & 2L) != 0)) + { + return _Connection; + } + return StringValues.Empty; } set { @@ -5017,7 +5146,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { get { - return _Date; + if (((_bits & 4L) != 0)) + { + return _Date; + } + return StringValues.Empty; } set { @@ -5030,7 +5163,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { get { - return _KeepAlive; + if (((_bits & 8L) != 0)) + { + return _KeepAlive; + } + return StringValues.Empty; } set { @@ -5042,7 +5179,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { get { - return _Pragma; + if (((_bits & 16L) != 0)) + { + return _Pragma; + } + return StringValues.Empty; } set { @@ -5054,7 +5195,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { get { - return _Trailer; + if (((_bits & 32L) != 0)) + { + return _Trailer; + } + return StringValues.Empty; } set { @@ -5066,7 +5211,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { get { - return _TransferEncoding; + if (((_bits & 64L) != 0)) + { + return _TransferEncoding; + } + return StringValues.Empty; } set { @@ -5079,7 +5228,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { get { - return _Upgrade; + if (((_bits & 128L) != 0)) + { + return _Upgrade; + } + return StringValues.Empty; } set { @@ -5091,7 +5244,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { get { - return _Via; + if (((_bits & 256L) != 0)) + { + return _Via; + } + return StringValues.Empty; } set { @@ -5103,7 +5260,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { get { - return _Warning; + if (((_bits & 512L) != 0)) + { + return _Warning; + } + return StringValues.Empty; } set { @@ -5115,7 +5276,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { get { - return _Allow; + if (((_bits & 1024L) != 0)) + { + return _Allow; + } + return StringValues.Empty; } set { @@ -5127,7 +5292,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { get { - return _ContentLength; + if (((_bits & 2048L) != 0)) + { + return _ContentLength; + } + return StringValues.Empty; } set { @@ -5140,7 +5309,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { get { - return _ContentType; + if (((_bits & 4096L) != 0)) + { + return _ContentType; + } + return StringValues.Empty; } set { @@ -5152,7 +5325,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { get { - return _ContentEncoding; + if (((_bits & 8192L) != 0)) + { + return _ContentEncoding; + } + return StringValues.Empty; } set { @@ -5164,7 +5341,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { get { - return _ContentLanguage; + if (((_bits & 16384L) != 0)) + { + return _ContentLanguage; + } + return StringValues.Empty; } set { @@ -5176,7 +5357,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { get { - return _ContentLocation; + if (((_bits & 32768L) != 0)) + { + return _ContentLocation; + } + return StringValues.Empty; } set { @@ -5188,7 +5373,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { get { - return _ContentMD5; + if (((_bits & 65536L) != 0)) + { + return _ContentMD5; + } + return StringValues.Empty; } set { @@ -5200,7 +5389,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { get { - return _ContentRange; + if (((_bits & 131072L) != 0)) + { + return _ContentRange; + } + return StringValues.Empty; } set { @@ -5212,7 +5405,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { get { - return _Expires; + if (((_bits & 262144L) != 0)) + { + return _Expires; + } + return StringValues.Empty; } set { @@ -5224,7 +5421,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { get { - return _LastModified; + if (((_bits & 524288L) != 0)) + { + return _LastModified; + } + return StringValues.Empty; } set { @@ -5236,7 +5437,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { get { - return _AcceptRanges; + if (((_bits & 1048576L) != 0)) + { + return _AcceptRanges; + } + return StringValues.Empty; } set { @@ -5248,7 +5453,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { get { - return _Age; + if (((_bits & 2097152L) != 0)) + { + return _Age; + } + return StringValues.Empty; } set { @@ -5260,7 +5469,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { get { - return _ETag; + if (((_bits & 4194304L) != 0)) + { + return _ETag; + } + return StringValues.Empty; } set { @@ -5272,7 +5485,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { get { - return _Location; + if (((_bits & 8388608L) != 0)) + { + return _Location; + } + return StringValues.Empty; } set { @@ -5284,7 +5501,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { get { - return _ProxyAutheticate; + if (((_bits & 16777216L) != 0)) + { + return _ProxyAutheticate; + } + return StringValues.Empty; } set { @@ -5296,7 +5517,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { get { - return _RetryAfter; + if (((_bits & 33554432L) != 0)) + { + return _RetryAfter; + } + return StringValues.Empty; } set { @@ -5308,7 +5533,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { get { - return _Server; + if (((_bits & 67108864L) != 0)) + { + return _Server; + } + return StringValues.Empty; } set { @@ -5321,7 +5550,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { get { - return _SetCookie; + if (((_bits & 134217728L) != 0)) + { + return _SetCookie; + } + return StringValues.Empty; } set { @@ -5333,7 +5566,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { get { - return _Vary; + if (((_bits & 268435456L) != 0)) + { + return _Vary; + } + return StringValues.Empty; } set { @@ -5345,7 +5582,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { get { - return _WWWAuthenticate; + if (((_bits & 536870912L) != 0)) + { + return _WWWAuthenticate; + } + return StringValues.Empty; } set { @@ -7441,43 +7682,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Http protected override void ClearFast() { _bits = 0; - - _CacheControl = StringValues.Empty; - _Connection = StringValues.Empty; - _Date = StringValues.Empty; - _KeepAlive = StringValues.Empty; - _Pragma = StringValues.Empty; - _Trailer = StringValues.Empty; - _TransferEncoding = StringValues.Empty; - _Upgrade = StringValues.Empty; - _Via = StringValues.Empty; - _Warning = StringValues.Empty; - _Allow = StringValues.Empty; - _ContentLength = StringValues.Empty; - _ContentType = StringValues.Empty; - _ContentEncoding = StringValues.Empty; - _ContentLanguage = StringValues.Empty; - _ContentLocation = StringValues.Empty; - _ContentMD5 = StringValues.Empty; - _ContentRange = StringValues.Empty; - _Expires = StringValues.Empty; - _LastModified = StringValues.Empty; - _AcceptRanges = StringValues.Empty; - _Age = StringValues.Empty; - _ETag = StringValues.Empty; - _Location = StringValues.Empty; - _ProxyAutheticate = StringValues.Empty; - _RetryAfter = StringValues.Empty; - _Server = StringValues.Empty; - _SetCookie = StringValues.Empty; - _Vary = StringValues.Empty; - _WWWAuthenticate = StringValues.Empty; - - _rawConnection = null; - _rawDate = null; - _rawTransferEncoding = null; - _rawContentLength = null; - _rawServer = null; MaybeUnknown?.Clear(); } diff --git a/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/KnownHeaders.cs b/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/KnownHeaders.cs index 4dd45dcfbe..df3cef0284 100644 --- a/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/KnownHeaders.cs +++ b/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/KnownHeaders.cs @@ -213,7 +213,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http {{ get {{ - return _{header.Identifier}; + if ({header.TestBit()}) + {{ + return _{header.Identifier}; + }} + return StringValues.Empty; }} set {{ @@ -352,10 +356,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Http protected override void ClearFast() {{ _bits = 0; - {Each(loop.Headers, header => $@" - _{header.Identifier} = StringValues.Empty;")} - {Each(loop.Headers.Where(header => header.EnhancedSetter), header => $@" - _raw{header.Identifier} = null;")} MaybeUnknown?.Clear(); }} From 186f6d0a05e2447e78dd1e51a0f7526dda0e2195 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Thu, 17 Dec 2015 10:18:20 +0000 Subject: [PATCH 0521/1662] Horizontal initialize repeat vectors once --- .../Http/Frame.cs | 21 ++- .../Infrastructure/MemoryPoolIterator2.cs | 146 +++++++++--------- .../MemoryPoolBlock2Tests.cs | 38 +++-- .../MemoryPoolIterator2Tests.cs | 9 +- 4 files changed, 114 insertions(+), 100 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs index 74f3ef6889..a69c5fc0d2 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs @@ -6,6 +6,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; using System.Net; +using System.Numerics; using System.Text; using System.Threading; using System.Threading.Tasks; @@ -39,6 +40,12 @@ namespace Microsoft.AspNet.Server.Kestrel.Http private static readonly byte[] _bytesDate = Encoding.ASCII.GetBytes("Date: "); private static readonly byte[] _bytesEndHeaders = Encoding.ASCII.GetBytes("\r\n\r\n"); + private static readonly Vector _vectorCRs = new Vector((byte)'\r'); + private static readonly Vector _vectorColons = new Vector((byte)':'); + private static readonly Vector _vectorSpaces = new Vector((byte)' '); + private static readonly Vector _vectorQuestionMarks = new Vector((byte)'?'); + private static readonly Vector _vectorPercentages = new Vector((byte)'%'); + private readonly object _onStartingSync = new Object(); private readonly object _onCompletedSync = new Object(); protected readonly FrameRequestHeaders _requestHeaders = new FrameRequestHeaders(); @@ -704,7 +711,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http try { var begin = scan; - if (scan.Seek(' ') == -1) + if (scan.Seek(_vectorSpaces) == -1) { return false; } @@ -719,11 +726,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http begin = scan; var needDecode = false; - var chFound = scan.Seek(' ', '?', '%'); + var chFound = scan.Seek(_vectorSpaces, _vectorQuestionMarks, _vectorPercentages); if (chFound == '%') { needDecode = true; - chFound = scan.Seek(' ', '?'); + chFound = scan.Seek(_vectorSpaces, _vectorQuestionMarks); } var pathBegin = begin; @@ -733,7 +740,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http if (chFound == '?') { begin = scan; - if (scan.Seek(' ') != ' ') + if (scan.Seek(_vectorSpaces) != ' ') { return false; } @@ -742,7 +749,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http scan.Take(); begin = scan; - if (scan.Seek('\r') == -1) + if (scan.Seek(_vectorCRs) == -1) { return false; } @@ -836,7 +843,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http while (!scan.IsEnd) { var beginName = scan; - scan.Seek(':', '\r'); + scan.Seek(_vectorColons, _vectorCRs); var endName = scan; chFirst = scan.Take(); @@ -887,7 +894,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http var wrapping = false; while (!scan.IsEnd) { - if (scan.Seek('\r') == -1) + if (scan.Seek(_vectorCRs) == -1) { // no "\r" in sight, burn used bytes and go back to await more data return false; diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolIterator2.cs b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolIterator2.cs index cab6fbe9ef..a10a2e23e7 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolIterator2.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolIterator2.cs @@ -168,16 +168,13 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure } } - public int Seek(int char0) + public int Seek(Vector byte0Vector) { if (IsDefault) { return -1; } - var byte0 = (byte)char0; - var ch0Vector = new Vector(byte0); - var block = _block; var index = _index; var array = block.Array; @@ -201,25 +198,28 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure if (following >= Vector.Count) { var data = new Vector(array, index); - var ch0Equals = Vector.Equals(data, ch0Vector); + var byte0Equals = Vector.Equals(data, byte0Vector); - if (ch0Equals.Equals(Vector.Zero)) + if (byte0Equals.Equals(Vector.Zero)) { index += Vector.Count; continue; } _block = block; - _index = index + FindFirstEqualByte(ch0Equals); - return char0; + _index = index + FindFirstEqualByte(byte0Equals); + return byte0Vector[0]; } + + var byte0 = byte0Vector[0]; + while (following > 0) { if (block.Array[index] == byte0) { _block = block; _index = index; - return char0; + return byte0; } following--; index++; @@ -228,18 +228,13 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure } } - public int Seek(int char0, int char1) + public int Seek(Vector byte0Vector, Vector byte1Vector) { if (IsDefault) { return -1; } - var byte0 = (byte)char0; - var byte1 = (byte)char1; - var ch0Vector = new Vector(byte0); - var ch1Vector = new Vector(byte1); - var block = _block; var index = _index; var array = block.Array; @@ -263,21 +258,21 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure if (following >= Vector.Count) { var data = new Vector(array, index); - var ch0Equals = Vector.Equals(data, ch0Vector); - var ch1Equals = Vector.Equals(data, ch1Vector); - int ch0Index = int.MaxValue; - int ch1Index = int.MaxValue; + var byte0Equals = Vector.Equals(data, byte0Vector); + var byte1Equals = Vector.Equals(data, byte1Vector); + int byte0Index = int.MaxValue; + int byte1Index = int.MaxValue; - if (!ch0Equals.Equals(Vector.Zero)) + if (!byte0Equals.Equals(Vector.Zero)) { - ch0Index = FindFirstEqualByte(ch0Equals); + byte0Index = FindFirstEqualByte(byte0Equals); } - if (!ch1Equals.Equals(Vector.Zero)) + if (!byte1Equals.Equals(Vector.Zero)) { - ch1Index = FindFirstEqualByte(ch1Equals); + byte1Index = FindFirstEqualByte(byte1Equals); } - if (ch0Index == int.MaxValue && ch1Index == int.MaxValue) + if (byte0Index == int.MaxValue && byte1Index == int.MaxValue) { index += Vector.Count; continue; @@ -285,15 +280,19 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure _block = block; - if (ch0Index < ch1Index) + if (byte0Index < byte1Index) { - _index = index + ch0Index; - return char0; + _index = index + byte0Index; + return byte0Vector[0]; } - _index = index + ch1Index; - return char1; + _index = index + byte1Index; + return byte1Vector[0]; } + + byte byte0 = byte0Vector[0]; + byte byte1 = byte1Vector[0]; + while (following > 0) { var byteIndex = block.Array[index]; @@ -301,13 +300,13 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure { _block = block; _index = index; - return char0; + return byte0; } else if (byteIndex == byte1) { _block = block; _index = index; - return char1; + return byte1; } following--; index++; @@ -316,20 +315,13 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure } } - public int Seek(int char0, int char1, int char2) + public int Seek(Vector byte0Vector, Vector byte1Vector, Vector byte2Vector) { if (IsDefault) { return -1; } - var byte0 = (byte)char0; - var byte1 = (byte)char1; - var byte2 = (byte)char2; - var ch0Vector = new Vector(byte0); - var ch1Vector = new Vector(byte1); - var ch2Vector = new Vector(byte2); - var block = _block; var index = _index; var array = block.Array; @@ -353,57 +345,57 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure if (following >= Vector.Count) { var data = new Vector(array, index); - var ch0Equals = Vector.Equals(data, ch0Vector); - var ch1Equals = Vector.Equals(data, ch1Vector); - var ch2Equals = Vector.Equals(data, ch2Vector); - int ch0Index = int.MaxValue; - int ch1Index = int.MaxValue; - int ch2Index = int.MaxValue; + var byte0Equals = Vector.Equals(data, byte0Vector); + var byte1Equals = Vector.Equals(data, byte1Vector); + var byte2Equals = Vector.Equals(data, byte2Vector); + int byte0Index = int.MaxValue; + int byte1Index = int.MaxValue; + int byte2Index = int.MaxValue; - if (!ch0Equals.Equals(Vector.Zero)) + if (!byte0Equals.Equals(Vector.Zero)) { - ch0Index = FindFirstEqualByte(ch0Equals); + byte0Index = FindFirstEqualByte(byte0Equals); } - if (!ch1Equals.Equals(Vector.Zero)) + if (!byte1Equals.Equals(Vector.Zero)) { - ch1Index = FindFirstEqualByte(ch1Equals); + byte1Index = FindFirstEqualByte(byte1Equals); } - if (!ch2Equals.Equals(Vector.Zero)) + if (!byte2Equals.Equals(Vector.Zero)) { - ch2Index = FindFirstEqualByte(ch2Equals); + byte2Index = FindFirstEqualByte(byte2Equals); } - if (ch0Index == int.MaxValue && ch1Index == int.MaxValue && ch2Index == int.MaxValue) + if (byte0Index == int.MaxValue && byte1Index == int.MaxValue && byte2Index == int.MaxValue) { index += Vector.Count; continue; } int toReturn, toMove; - if (ch0Index < ch1Index) + if (byte0Index < byte1Index) { - if (ch0Index < ch2Index) + if (byte0Index < byte2Index) { - toReturn = char0; - toMove = ch0Index; + toReturn = byte0Vector[0]; + toMove = byte0Index; } else { - toReturn = char2; - toMove = ch2Index; + toReturn = byte2Vector[0]; + toMove = byte2Index; } } else { - if (ch1Index < ch2Index) + if (byte1Index < byte2Index) { - toReturn = char1; - toMove = ch1Index; + toReturn = byte1Vector[0]; + toMove = byte1Index; } else { - toReturn = char2; - toMove = ch2Index; + toReturn = byte2Vector[0]; + toMove = byte2Index; } } @@ -412,6 +404,10 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure return toReturn; } + var byte0 = byte0Vector[0]; + var byte1 = byte1Vector[0]; + var byte2 = byte2Vector[0]; + while (following > 0) { var byteIndex = block.Array[index]; @@ -419,19 +415,19 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure { _block = block; _index = index; - return char0; + return byte0; } else if (byteIndex == byte1) { _block = block; _index = index; - return char1; + return byte1; } else if (byteIndex == byte2) { _block = block; _index = index; - return char2; + return byte2; } following--; index++; @@ -440,10 +436,10 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure } } - private static int FindFirstEqualByte(Vector chEquals) + private static int FindFirstEqualByte(Vector byteEquals) { // Quasi-tree search - var vector64 = Vector.AsVectorInt64(chEquals); + var vector64 = Vector.AsVectorInt64(byteEquals); for (var i = 0; i < Vector.Count; i++) { var longValue = vector64[i]; @@ -451,18 +447,18 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure var shift = i << 1; var offset = shift << 2; - var vector32 = Vector.AsVectorInt32(chEquals); + var vector32 = Vector.AsVectorInt32(byteEquals); if (vector32[shift] != 0) { - if (chEquals[offset] != 0) return offset; - if (chEquals[++offset] != 0) return offset; - if (chEquals[++offset] != 0) return offset; + if (byteEquals[offset] != 0) return offset; + if (byteEquals[++offset] != 0) return offset; + if (byteEquals[++offset] != 0) return offset; return ++offset; } offset += 4; - if (chEquals[offset] != 0) return offset; - if (chEquals[++offset] != 0) return offset; - if (chEquals[++offset] != 0) return offset; + if (byteEquals[offset] != 0) return offset; + if (byteEquals[++offset] != 0) return offset; + if (byteEquals[++offset] != 0) return offset; return ++offset; } throw new InvalidOperationException(); diff --git a/test/Microsoft.AspNet.Server.KestrelTests/MemoryPoolBlock2Tests.cs b/test/Microsoft.AspNet.Server.KestrelTests/MemoryPoolBlock2Tests.cs index 8618564004..c56f5311d5 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/MemoryPoolBlock2Tests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/MemoryPoolBlock2Tests.cs @@ -1,6 +1,7 @@ using System; using System.Linq; using Microsoft.AspNet.Server.Kestrel.Infrastructure; +using System.Numerics; using Xunit; namespace Microsoft.AspNet.Server.KestrelTests @@ -17,31 +18,36 @@ namespace Microsoft.AspNet.Server.KestrelTests { block.Array[block.End++] = ch; } + + var vectorMaxValues = new Vector(byte.MaxValue); + var iterator = block.GetIterator(); - foreach (var ch in Enumerable.Range(0, 256).Select(x => (char)x)) + foreach (var ch in Enumerable.Range(0, 256).Select(x => (byte)x)) { + var vectorCh = new Vector(ch); + var hit = iterator; - hit.Seek(ch); + hit.Seek(vectorCh); Assert.Equal(ch, iterator.GetLength(hit)); hit = iterator; - hit.Seek(ch, byte.MaxValue); + hit.Seek(vectorCh, vectorMaxValues); Assert.Equal(ch, iterator.GetLength(hit)); hit = iterator; - hit.Seek(byte.MaxValue, ch); + hit.Seek(vectorMaxValues, vectorCh); Assert.Equal(ch, iterator.GetLength(hit)); hit = iterator; - hit.Seek(ch, byte.MaxValue, byte.MaxValue); + hit.Seek(vectorCh, vectorMaxValues, vectorMaxValues); Assert.Equal(ch, iterator.GetLength(hit)); hit = iterator; - hit.Seek(byte.MaxValue, ch, byte.MaxValue); + hit.Seek(vectorMaxValues, vectorCh, vectorMaxValues); Assert.Equal(ch, iterator.GetLength(hit)); hit = iterator; - hit.Seek(ch, byte.MaxValue, byte.MaxValue); + hit.Seek(vectorCh, vectorMaxValues, vectorMaxValues); Assert.Equal(ch, iterator.GetLength(hit)); } } @@ -69,31 +75,35 @@ namespace Microsoft.AspNet.Server.KestrelTests block3.Array[block3.End++] = ch; } + var vectorMaxValues = new Vector(byte.MaxValue); + var iterator = block1.GetIterator(); - foreach (var ch in Enumerable.Range(0, 256).Select(x => (char)x)) + foreach (var ch in Enumerable.Range(0, 256).Select(x => (byte)x)) { + var vectorCh = new Vector(ch); + var hit = iterator; - hit.Seek(ch); + hit.Seek(vectorCh); Assert.Equal(ch, iterator.GetLength(hit)); hit = iterator; - hit.Seek(ch, byte.MaxValue); + hit.Seek(vectorCh, vectorMaxValues); Assert.Equal(ch, iterator.GetLength(hit)); hit = iterator; - hit.Seek(byte.MaxValue, ch); + hit.Seek(vectorMaxValues, vectorCh); Assert.Equal(ch, iterator.GetLength(hit)); hit = iterator; - hit.Seek(ch, byte.MaxValue, byte.MaxValue); + hit.Seek(vectorCh, vectorMaxValues, vectorMaxValues); Assert.Equal(ch, iterator.GetLength(hit)); hit = iterator; - hit.Seek(byte.MaxValue, ch, byte.MaxValue); + hit.Seek(vectorMaxValues, vectorCh, vectorMaxValues); Assert.Equal(ch, iterator.GetLength(hit)); hit = iterator; - hit.Seek(ch, byte.MaxValue, byte.MaxValue); + hit.Seek(vectorMaxValues, vectorMaxValues, vectorCh); Assert.Equal(ch, iterator.GetLength(hit)); } } diff --git a/test/Microsoft.AspNet.Server.KestrelTests/MemoryPoolIterator2Tests.cs b/test/Microsoft.AspNet.Server.KestrelTests/MemoryPoolIterator2Tests.cs index 7368bf08d9..67c4a7e6ae 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/MemoryPoolIterator2Tests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/MemoryPoolIterator2Tests.cs @@ -1,6 +1,7 @@ using System; using System.Linq; using Microsoft.AspNet.Server.Kestrel.Infrastructure; +using System.Numerics; using Xunit; namespace Microsoft.AspNet.Server.KestrelTests @@ -52,15 +53,15 @@ namespace Microsoft.AspNet.Server.KestrelTests int found = -1; if (searchFor.Length == 1) { - found = begin.Seek(searchFor[0]); + found = begin.Seek(new Vector((byte)searchFor[0])); } else if (searchFor.Length == 2) { - found = begin.Seek(searchFor[0], searchFor[1]); + found = begin.Seek(new Vector((byte)searchFor[0]), new Vector((byte)searchFor[1])); } else if (searchFor.Length == 3) { - found = begin.Seek(searchFor[0], searchFor[1], searchFor[2]); + found = begin.Seek(new Vector((byte)searchFor[0]), new Vector((byte)searchFor[1]), new Vector((byte)searchFor[2])); } else { @@ -217,7 +218,7 @@ namespace Microsoft.AspNet.Server.KestrelTests block.End += chars.Length; var begin = block.GetIterator(); var end = begin; - end.Seek(endChar); + end.Seek(new Vector((byte)endChar)); string knownString; // Act From 7625f65e6c5a96ba50969502134173e402fc911a Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Thu, 17 Dec 2015 11:32:01 +0000 Subject: [PATCH 0522/1662] Faster MemoryPoolIterator2.CopyFrom --- .../Infrastructure/MemoryPoolIterator2.cs | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolIterator2.cs b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolIterator2.cs index cab6fbe9ef..0e8a53cf0b 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolIterator2.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolIterator2.cs @@ -585,15 +585,15 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure public void CopyFrom(byte[] data) { - CopyFrom(new ArraySegment(data)); - } - - public void CopyFrom(byte[] data, int offset, int count) - { - CopyFrom(new ArraySegment(data, offset, count)); + CopyFrom(data, 0, data.Length); } public void CopyFrom(ArraySegment buffer) + { + CopyFrom(buffer.Array, buffer.Offset, buffer.Count); + } + + public void CopyFrom(byte[] data, int offset, int count) { Debug.Assert(_block != null); Debug.Assert(_block.Pool != null); @@ -604,8 +604,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure var block = _block; var blockIndex = _index; - var bufferIndex = buffer.Offset; - var remaining = buffer.Count; + var bufferIndex = offset; + var remaining = count; var bytesLeftInBlock = block.Data.Offset + block.Data.Count - blockIndex; while (remaining > 0) @@ -613,6 +613,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure if (bytesLeftInBlock == 0) { var nextBlock = pool.Lease(); + block.End = blockIndex; block.Next = nextBlock; block = nextBlock; @@ -622,15 +623,15 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure var bytesToCopy = remaining < bytesLeftInBlock ? remaining : bytesLeftInBlock; - Buffer.BlockCopy(buffer.Array, bufferIndex, block.Array, blockIndex, bytesToCopy); + Buffer.BlockCopy(data, bufferIndex, block.Array, blockIndex, bytesToCopy); blockIndex += bytesToCopy; bufferIndex += bytesToCopy; remaining -= bytesToCopy; bytesLeftInBlock -= bytesToCopy; - block.End = blockIndex; } + block.End = blockIndex; _block = block; _index = blockIndex; } @@ -661,6 +662,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure if (bytesLeftInBlock == 0) { var nextBlock = pool.Lease(); + block.End = blockIndex; block.Next = nextBlock; block = nextBlock; @@ -692,10 +694,10 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure bytesLeftInBlockMinusSpan -= copied; bytesLeftInBlock -= copied; } - block.End = blockIndex; } } + block.End = blockIndex; _block = block; _index = blockIndex; } From bd10d507f8d9530d601ed17edce1c6d0b0e19f15 Mon Sep 17 00:00:00 2001 From: John Luo Date: Wed, 16 Dec 2015 12:34:36 -0800 Subject: [PATCH 0523/1662] Reacting to new Hosting API --- .../Microsoft.AspNet.Hosting.ini | 3 -- samples/LargeResponseApp/Startup.cs | 13 ++++- samples/LargeResponseApp/hosting.json | 4 ++ samples/LargeResponseApp/project.json | 8 ++-- samples/SampleApp/Program.cs | 17 ------- samples/SampleApp/Startup.cs | 16 +++++++ samples/SampleApp/hosting.json | 4 ++ samples/SampleApp/project.json | 37 ++++++++------- samples/SampleApp/wwwroot/web.config | 9 ++++ .../Program.cs | 17 ------- .../AddressRegistrationTests.cs | 9 ++-- .../PathBaseTests.cs | 5 +- .../RequestTests.cs | 47 ++++++++++--------- .../ResponseTests.cs | 38 ++++++++------- .../ThreadCountTests.cs | 23 ++++----- 15 files changed, 133 insertions(+), 117 deletions(-) delete mode 100644 samples/LargeResponseApp/Microsoft.AspNet.Hosting.ini create mode 100644 samples/LargeResponseApp/hosting.json delete mode 100644 samples/SampleApp/Program.cs create mode 100644 samples/SampleApp/hosting.json create mode 100644 samples/SampleApp/wwwroot/web.config delete mode 100644 src/Microsoft.AspNet.Server.Kestrel/Program.cs diff --git a/samples/LargeResponseApp/Microsoft.AspNet.Hosting.ini b/samples/LargeResponseApp/Microsoft.AspNet.Hosting.ini deleted file mode 100644 index c566ee4f7d..0000000000 --- a/samples/LargeResponseApp/Microsoft.AspNet.Hosting.ini +++ /dev/null @@ -1,3 +0,0 @@ - -Server = Microsoft.AspNet.Server.Kestrel -Server.Urls = http://localhost:5001/ diff --git a/samples/LargeResponseApp/Startup.cs b/samples/LargeResponseApp/Startup.cs index 6bae65f890..5052e96f59 100644 --- a/samples/LargeResponseApp/Startup.cs +++ b/samples/LargeResponseApp/Startup.cs @@ -1,9 +1,10 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using Microsoft.AspNet.Builder; using System.Text; using System.Threading.Tasks; +using Microsoft.AspNet.Builder; +using Microsoft.AspNet.Hosting; namespace LargeResponseApp { @@ -34,5 +35,15 @@ namespace LargeResponseApp } }); } + + public static void Main(string[] args) + { + var application = new WebApplicationBuilder() + .UseConfiguration(WebApplicationConfiguration.GetDefault(args)) + .UseStartup() + .Build(); + + application.Run(); + } } } diff --git a/samples/LargeResponseApp/hosting.json b/samples/LargeResponseApp/hosting.json new file mode 100644 index 0000000000..7e1c57a3f0 --- /dev/null +++ b/samples/LargeResponseApp/hosting.json @@ -0,0 +1,4 @@ +{ + "server": "Microsoft.AspNet.Server.Kestrel", + "server.urls": "http://localhost:5001/" +} \ No newline at end of file diff --git a/samples/LargeResponseApp/project.json b/samples/LargeResponseApp/project.json index 7754a7b6f7..2fb9fdb1a0 100644 --- a/samples/LargeResponseApp/project.json +++ b/samples/LargeResponseApp/project.json @@ -3,14 +3,14 @@ "dependencies": { "Microsoft.AspNet.Server.Kestrel": "1.0.0-*" }, - + "compilationOptions": { + "emitEntryPoint": true + }, "frameworks": { "dnx451": { }, "dnxcore50": { } }, - "commands": { - "run": "Microsoft.AspNet.Server.Kestrel", - "web": "Microsoft.AspNet.Hosting" + "web": "LargeResponseApp" } } diff --git a/samples/SampleApp/Program.cs b/samples/SampleApp/Program.cs deleted file mode 100644 index 16e2d1f487..0000000000 --- a/samples/SampleApp/Program.cs +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using System.Linq; - -namespace SampleApp -{ - public class Program - { - public static void Main(string[] args) - { - var mergedArgs = new[] { "--server", "Microsoft.AspNet.Server.Kestrel" }.Concat(args).ToArray(); - Microsoft.AspNet.Hosting.Program.Main(mergedArgs); - } - } -} diff --git a/samples/SampleApp/Startup.cs b/samples/SampleApp/Startup.cs index b6004d9c0c..8d4b97eda7 100644 --- a/samples/SampleApp/Startup.cs +++ b/samples/SampleApp/Startup.cs @@ -5,6 +5,7 @@ using System; using System.IO; using System.Security.Cryptography.X509Certificates; using Microsoft.AspNet.Builder; +using Microsoft.AspNet.Hosting; using Microsoft.AspNet.Http; using Microsoft.AspNet.Http.Features; using Microsoft.AspNet.Server.Kestrel; @@ -61,5 +62,20 @@ namespace SampleApp await context.Response.WriteAsync("Hello world"); }); } + + public static void Main(string[] args) + { + var application = new WebApplicationBuilder() + .UseConfiguration(WebApplicationConfiguration.GetDefault(args)) + .UseStartup() + .Build(); + + // The following section should be used to demo sockets + //var addresses = application.GetAddresses(); + //addresses.Clear(); + //addresses.Add("http://unix:/tmp/kestrel-test.sock"); + + application.Run(); + } } } \ No newline at end of file diff --git a/samples/SampleApp/hosting.json b/samples/SampleApp/hosting.json new file mode 100644 index 0000000000..66f354cbc2 --- /dev/null +++ b/samples/SampleApp/hosting.json @@ -0,0 +1,4 @@ +{ + "server": "Microsoft.AspNet.Server.Kestrel", + "server.urls": "http://localhost:5000;https://localhost:5001" +} diff --git a/samples/SampleApp/project.json b/samples/SampleApp/project.json index f9e44a2a05..42f19ecb21 100644 --- a/samples/SampleApp/project.json +++ b/samples/SampleApp/project.json @@ -1,22 +1,23 @@ { - "version": "1.0.0-*", - "dependencies": { - "Microsoft.AspNet.Server.Kestrel": "1.0.0-*", - "Microsoft.AspNet.Server.Kestrel.Https": "1.0.0-*", - "Microsoft.Extensions.Logging.Console": "1.0.0-*" + "version": "1.0.0-*", + "dependencies": { + "Microsoft.AspNet.Server.Kestrel": "1.0.0-*", + "Microsoft.AspNet.Server.Kestrel.Https": "1.0.0-*", + "Microsoft.Extensions.Logging.Console": "1.0.0-*" + }, + "compilationOptions": { + "emitEntryPoint": true + }, + "frameworks": { + "dnx451": { }, - "frameworks": { - "dnx451": { - }, - "dnxcore50": { - "dependencies": { - "System.Console": "4.0.0-*" - } - } - }, - "commands": { - "web": "Microsoft.AspNet.Hosting --server Microsoft.AspNet.Server.Kestrel --server.urls http://localhost:5000;https://localhost:5001", - "kestrel": "Microsoft.AspNet.Server.Kestrel --server.urls http://localhost:5000;https://localhost:5001", - "run-socket": "Microsoft.AspNet.Server.Kestrel --server.urls http://unix:/tmp/kestrel-test.sock" + "dnxcore50": { + "dependencies": { + "System.Console": "4.0.0-*" + } } + }, + "commands": { + "web": "SampleApp" + } } diff --git a/samples/SampleApp/wwwroot/web.config b/samples/SampleApp/wwwroot/web.config new file mode 100644 index 0000000000..9a0d90abf8 --- /dev/null +++ b/samples/SampleApp/wwwroot/web.config @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/src/Microsoft.AspNet.Server.Kestrel/Program.cs b/src/Microsoft.AspNet.Server.Kestrel/Program.cs deleted file mode 100644 index b0f18d7c30..0000000000 --- a/src/Microsoft.AspNet.Server.Kestrel/Program.cs +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using System.Linq; - -namespace Microsoft.AspNet.Server.Kestrel -{ - public class Program - { - public static void Main(string[] args) - { - var mergedArgs = new[] { "--server", "Microsoft.AspNet.Server.Kestrel" }.Concat(args).ToArray(); - Microsoft.AspNet.Hosting.Program.Main(mergedArgs); - } - } -} diff --git a/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs b/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs index 9921a3d7fc..da0cd8d1f9 100644 --- a/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs +++ b/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs @@ -40,11 +40,12 @@ namespace Microsoft.AspNet.Server.Kestrel.FunctionalTests }) .Build(); - var hostBuilder = new WebHostBuilder(config); - hostBuilder.UseServerFactory("Microsoft.AspNet.Server.Kestrel"); - hostBuilder.UseStartup(ConfigureEchoAddress); + var applicationBuilder = new WebApplicationBuilder() + .UseConfiguration(config) + .UseServerFactory("Microsoft.AspNet.Server.Kestrel") + .Configure(ConfigureEchoAddress); - using (var app = hostBuilder.Build().Start()) + using (var app = applicationBuilder.Build().Start()) { using (var client = new HttpClient()) { diff --git a/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/PathBaseTests.cs b/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/PathBaseTests.cs index 95df0477ab..700150e2aa 100644 --- a/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/PathBaseTests.cs +++ b/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/PathBaseTests.cs @@ -79,9 +79,10 @@ namespace Microsoft.AspNet.Server.Kestrel.FunctionalTests { "server.urls", registerAddress } }).Build(); - var builder = new WebHostBuilder(config) + var builder = new WebApplicationBuilder() + .UseConfiguration(config) .UseServerFactory("Microsoft.AspNet.Server.Kestrel") - .UseStartup(app => + .Configure(app => { app.Run(async context => { diff --git a/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/RequestTests.cs b/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/RequestTests.cs index 861a2a84c3..a74f999eaf 100644 --- a/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/RequestTests.cs +++ b/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/RequestTests.cs @@ -29,31 +29,32 @@ namespace Microsoft.AspNet.Server.Kestrel.FunctionalTests }) .Build(); - var hostBuilder = new WebHostBuilder(config); - hostBuilder.UseServerFactory("Microsoft.AspNet.Server.Kestrel"); - hostBuilder.UseStartup(app => - { - app.Run(async context => + var applicationBuilder = new WebApplicationBuilder() + .UseConfiguration(config) + .UseServerFactory("Microsoft.AspNet.Server.Kestrel") + .Configure(app => { - // Read the full request body - var total = 0; - var bytes = new byte[1024]; - var count = await context.Request.Body.ReadAsync(bytes, 0, bytes.Length); - while (count > 0) + app.Run(async context => { - for (int i = 0; i < count; i++) + // Read the full request body + var total = 0; + var bytes = new byte[1024]; + var count = await context.Request.Body.ReadAsync(bytes, 0, bytes.Length); + while (count > 0) { - Assert.Equal(total % 256, bytes[i]); - total++; + for (int i = 0; i < count; i++) + { + Assert.Equal(total % 256, bytes[i]); + total++; + } + count = await context.Request.Body.ReadAsync(bytes, 0, bytes.Length); } - count = await context.Request.Body.ReadAsync(bytes, 0, bytes.Length); - } - await context.Response.WriteAsync(total.ToString(CultureInfo.InvariantCulture)); + await context.Response.WriteAsync(total.ToString(CultureInfo.InvariantCulture)); + }); }); - }); - using (var app = hostBuilder.Build().Start()) + using (var app = applicationBuilder.Build().Start()) { using (var client = new HttpClient()) { @@ -97,9 +98,10 @@ namespace Microsoft.AspNet.Server.Kestrel.FunctionalTests { "server.urls", "http://localhost:8791" } }).Build(); - var builder = new WebHostBuilder(config) + var builder = new WebApplicationBuilder() + .UseConfiguration(config) .UseServerFactory("Microsoft.AspNet.Server.Kestrel") - .UseStartup(app => + .Configure(app => { app.Run(async context => { @@ -126,9 +128,10 @@ namespace Microsoft.AspNet.Server.Kestrel.FunctionalTests { "server.urls", $"http://{registerAddress}:{port}" } }).Build(); - var builder = new WebHostBuilder(config) + var builder = new WebApplicationBuilder() + .UseConfiguration(config) .UseServerFactory("Microsoft.AspNet.Server.Kestrel") - .UseStartup(app => + .Configure(app => { app.Run(async context => { diff --git a/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/ResponseTests.cs b/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/ResponseTests.cs index 67e8203e05..b1db1a5091 100644 --- a/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/ResponseTests.cs +++ b/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/ResponseTests.cs @@ -28,28 +28,29 @@ namespace Microsoft.AspNet.Server.Kestrel.FunctionalTests }) .Build(); - var hostBuilder = new WebHostBuilder(config); - hostBuilder.UseServerFactory("Microsoft.AspNet.Server.Kestrel"); - hostBuilder.UseStartup(app => - { - app.Run(async context => + var applicationBuilder = new WebApplicationBuilder() + .UseConfiguration(config) + .UseServerFactory("Microsoft.AspNet.Server.Kestrel") + .Configure(app => { - var bytes = new byte[1024]; - for (int i = 0; i < bytes.Length; i++) + app.Run(async context => { - bytes[i] = (byte)i; - } + var bytes = new byte[1024]; + for (int i = 0; i < bytes.Length; i++) + { + bytes[i] = (byte)i; + } - context.Response.ContentLength = bytes.Length * 1024; + context.Response.ContentLength = bytes.Length * 1024; - for (int i = 0; i < 1024; i++) - { - await context.Response.Body.WriteAsync(bytes, 0, bytes.Length); - } + for (int i = 0; i < 1024; i++) + { + await context.Response.Body.WriteAsync(bytes, 0, bytes.Length); + } + }); }); - }); - using (var app = hostBuilder.Build().Start()) + using (var app = applicationBuilder.Build().Start()) { using (var client = new HttpClient()) { @@ -85,9 +86,10 @@ namespace Microsoft.AspNet.Server.Kestrel.FunctionalTests }) .Build(); - var hostBuilder = new WebHostBuilder(config) + var hostBuilder = new WebApplicationBuilder() + .UseConfiguration(config) .UseServerFactory("Microsoft.AspNet.Server.Kestrel") - .UseStartup(app => + .Configure(app => { app.Run(async context => { diff --git a/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/ThreadCountTests.cs b/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/ThreadCountTests.cs index 4bd434df68..f67cff786f 100644 --- a/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/ThreadCountTests.cs +++ b/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/ThreadCountTests.cs @@ -24,19 +24,20 @@ namespace Microsoft.AspNet.Server.Kestrel.FunctionalTests }) .Build(); - var hostBuilder = new WebHostBuilder(config); - hostBuilder.UseServerFactory("Microsoft.AspNet.Server.Kestrel"); - hostBuilder.UseStartup(app => - { - var serverInfo = app.ServerFeatures.Get(); - serverInfo.ThreadCount = threadCount; - app.Run(context => + var applicationBuilder = new WebApplicationBuilder() + .UseConfiguration(config) + .UseServerFactory("Microsoft.AspNet.Server.Kestrel") + .Configure(app => { - return context.Response.WriteAsync("Hello World"); - }); - }); + var serverInfo = app.ServerFeatures.Get(); + serverInfo.ThreadCount = threadCount; + app.Run(context => + { + return context.Response.WriteAsync("Hello World"); + }); + }); - using (var app = hostBuilder.Build().Start()) + using (var app = applicationBuilder.Build().Start()) { using (var client = new HttpClient()) { From 9edd6f60b9c6db2d71f0f79f5f193787180946cc Mon Sep 17 00:00:00 2001 From: John Luo Date: Fri, 18 Dec 2015 14:48:13 -0800 Subject: [PATCH 0524/1662] Missed update after rebasing --- .../ReuseStreamsTests.cs | 54 ++++++++++--------- 1 file changed, 28 insertions(+), 26 deletions(-) diff --git a/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/ReuseStreamsTests.cs b/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/ReuseStreamsTests.cs index d61a2759e2..b15c45d67b 100644 --- a/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/ReuseStreamsTests.cs +++ b/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/ReuseStreamsTests.cs @@ -30,23 +30,24 @@ namespace Microsoft.AspNet.Server.Kestrel.FunctionalTests }) .Build(); - var hostBuilder = new WebHostBuilder(config); - hostBuilder.UseServerFactory("Microsoft.AspNet.Server.Kestrel"); - hostBuilder.UseStartup(app => - { - var serverInfo = app.ServerFeatures.Get(); - app.Run(context => + var builder = new WebApplicationBuilder() + .UseConfiguration(config) + .UseServerFactory("Microsoft.AspNet.Server.Kestrel") + .Configure(app => { - if (context.Request.Body != lastStream) + var serverInfo = app.ServerFeatures.Get(); + app.Run(context => { - lastStream = context.Request.Body; - streamCount++; - } - return context.Request.Body.CopyToAsync(context.Response.Body); - }); - }); + if (context.Request.Body != lastStream) + { + lastStream = context.Request.Body; + streamCount++; + } + return context.Request.Body.CopyToAsync(context.Response.Body); + }); + }); - using (var app = hostBuilder.Build().Start()) + using (var app = builder.Build().Start()) { using (var client = new HttpClient()) { @@ -84,21 +85,22 @@ namespace Microsoft.AspNet.Server.Kestrel.FunctionalTests }) .Build(); - var hostBuilder = new WebHostBuilder(config); - hostBuilder.UseServerFactory("Microsoft.AspNet.Server.Kestrel"); - hostBuilder.UseStartup(app => - { - var serverInfo = app.ServerFeatures.Get(); - app.Run(context => + var hostBuilder = new WebApplicationBuilder() + .UseConfiguration(config) + .UseServerFactory("Microsoft.AspNet.Server.Kestrel") + .Configure(app => { - if (context.Request.Body != lastStream) + var serverInfo = app.ServerFeatures.Get(); + app.Run(context => { - lastStream = context.Request.Body; - streamCount++; - } - return context.Request.Body.CopyToAsync(context.Response.Body); + if (context.Request.Body != lastStream) + { + lastStream = context.Request.Body; + streamCount++; + } + return context.Request.Body.CopyToAsync(context.Response.Body); + }); }); - }); using (var app = hostBuilder.Build().Start()) { From 02fa0c306deaf98f85016a9d861a750e47759169 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Sun, 20 Dec 2015 00:34:42 +0000 Subject: [PATCH 0525/1662] Jit readonly static optimization --- .../MemoryPoolIterator2Extensions.cs | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolIterator2Extensions.cs b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolIterator2Extensions.cs index 1fbd76c5a8..c9a23db157 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolIterator2Extensions.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolIterator2Extensions.cs @@ -26,18 +26,19 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure public const string Http10Version = "HTTP/1.0"; public const string Http11Version = "HTTP/1.1"; - private static long _httpConnectMethodLong = GetAsciiStringAsLong("CONNECT\0"); - private static long _httpDeleteMethodLong = GetAsciiStringAsLong("DELETE\0\0"); - private static long _httpGetMethodLong = GetAsciiStringAsLong("GET\0\0\0\0\0"); - private static long _httpHeadMethodLong = GetAsciiStringAsLong("HEAD\0\0\0\0"); - private static long _httpPatchMethodLong = GetAsciiStringAsLong("PATCH\0\0\0"); - private static long _httpPostMethodLong = GetAsciiStringAsLong("POST\0\0\0\0"); - private static long _httpPutMethodLong = GetAsciiStringAsLong("PUT\0\0\0\0\0"); - private static long _httpOptionsMethodLong = GetAsciiStringAsLong("OPTIONS\0"); - private static long _httpTraceMethodLong = GetAsciiStringAsLong("TRACE\0\0\0"); + // readonly primitive statics can be Jit'd to consts https://github.com/dotnet/coreclr/issues/1079 + private readonly static long _httpConnectMethodLong = GetAsciiStringAsLong("CONNECT\0"); + private readonly static long _httpDeleteMethodLong = GetAsciiStringAsLong("DELETE\0\0"); + private readonly static long _httpGetMethodLong = GetAsciiStringAsLong("GET\0\0\0\0\0"); + private readonly static long _httpHeadMethodLong = GetAsciiStringAsLong("HEAD\0\0\0\0"); + private readonly static long _httpPatchMethodLong = GetAsciiStringAsLong("PATCH\0\0\0"); + private readonly static long _httpPostMethodLong = GetAsciiStringAsLong("POST\0\0\0\0"); + private readonly static long _httpPutMethodLong = GetAsciiStringAsLong("PUT\0\0\0\0\0"); + private readonly static long _httpOptionsMethodLong = GetAsciiStringAsLong("OPTIONS\0"); + private readonly static long _httpTraceMethodLong = GetAsciiStringAsLong("TRACE\0\0\0"); - private static long _http10VersionLong = GetAsciiStringAsLong("HTTP/1.0"); - private static long _http11VersionLong = GetAsciiStringAsLong("HTTP/1.1"); + private readonly static long _http10VersionLong = GetAsciiStringAsLong("HTTP/1.0"); + private readonly static long _http11VersionLong = GetAsciiStringAsLong("HTTP/1.1"); private const int PerfectHashDivisor = 37; private static Tuple[] _knownStrings = new Tuple[PerfectHashDivisor]; From aaf84afaffc2661337bbafd7f8501680513940b2 Mon Sep 17 00:00:00 2001 From: moozzyk Date: Fri, 18 Dec 2015 14:00:48 -0800 Subject: [PATCH 0526/1662] Don't try calling `uname` on Windows --- .../Networking/PlatformApis.cs | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/PlatformApis.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/PlatformApis.cs index 370fcb30c2..6117520b3f 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/PlatformApis.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/PlatformApis.cs @@ -14,19 +14,22 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking IsWindows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows); IsDarwin = RuntimeInformation.IsOSPlatform(OSPlatform.OSX); #else - var p = (int)System.Environment.OSVersion.Platform; + var p = (int)Environment.OSVersion.Platform; IsWindows = (p != 4) && (p != 6) && (p != 128); - - // When running on Mono in Darwin OSVersion doesn't return Darwin. It returns Unix instead. - // Fallback to use uname. - IsDarwin = string.Equals(GetUname(), "Darwin", StringComparison.Ordinal); + + if (!IsWindows) + { + // When running on Mono in Darwin OSVersion doesn't return Darwin. It returns Unix instead. + // Fallback to use uname. + IsDarwin = string.Equals(GetUname(), "Darwin", StringComparison.Ordinal); + } #endif } - + public static bool IsWindows { get; } public static bool IsDarwin { get; } - + [DllImport("libc")] static extern int uname(IntPtr buf); From 11b360b66779416b06b3763b7a68af53cf6662b5 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Sat, 26 Dec 2015 07:11:54 +0000 Subject: [PATCH 0527/1662] Faster MessageBody.For --- .../Http/MessageBody.cs | 38 ++++--------------- .../MessageBodyTests.cs | 8 ++-- 2 files changed, 10 insertions(+), 36 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/MessageBody.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/MessageBody.cs index 8edd424a10..d1b2643624 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/MessageBody.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/MessageBody.cs @@ -73,27 +73,27 @@ namespace Microsoft.AspNet.Server.Kestrel.Http public static MessageBody For( string httpVersion, - IDictionary headers, + FrameRequestHeaders headers, FrameContext context) { // see also http://tools.ietf.org/html/rfc2616#section-4.4 var keepAlive = httpVersion != "HTTP/1.0"; - string connection; - if (TryGet(headers, "Connection", out connection)) + var connection = headers.HeaderConnection.ToString(); + if (connection.Length > 0) { keepAlive = connection.Equals("keep-alive", StringComparison.OrdinalIgnoreCase); } - string transferEncoding; - if (TryGet(headers, "Transfer-Encoding", out transferEncoding)) + var transferEncoding = headers.HeaderTransferEncoding.ToString(); + if (transferEncoding.Length > 0) { return new ForChunkedEncoding(keepAlive, context); } - string contentLength; - if (TryGet(headers, "Content-Length", out contentLength)) + var contentLength = headers.HeaderContentLength.ToString(); + if (contentLength.Length > 0) { return new ForContentLength(keepAlive, int.Parse(contentLength), context); } @@ -106,30 +106,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return new ForRemainingData(context); } - public static bool TryGet(IDictionary headers, string name, out string value) - { - StringValues values; - if (!headers.TryGetValue(name, out values) || values.Count == 0) - { - value = null; - return false; - } - var count = values.Count; - if (count == 0) - { - value = null; - return false; - } - if (count == 1) - { - value = values[0]; - return true; - } - value = string.Join(",", values.ToArray()); - return true; - } - - class ForRemainingData : MessageBody { public ForRemainingData(FrameContext context) diff --git a/test/Microsoft.AspNet.Server.KestrelTests/MessageBodyTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/MessageBodyTests.cs index 19e7d2e9b2..f93c144c8f 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/MessageBodyTests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/MessageBodyTests.cs @@ -2,11 +2,9 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.Collections.Generic; using System.Text; using System.Threading.Tasks; using Microsoft.AspNet.Server.Kestrel.Http; -using Microsoft.Extensions.Primitives; using Xunit; namespace Microsoft.AspNet.Server.KestrelTests @@ -20,7 +18,7 @@ namespace Microsoft.AspNet.Server.KestrelTests public void Http10ConnectionClose() { var input = new TestInput(); - var body = MessageBody.For("HTTP/1.0", new Dictionary(), input.FrameContext); + var body = MessageBody.For("HTTP/1.0", new FrameRequestHeaders(), input.FrameContext); var stream = new FrameRequestStream().StartAcceptingReads(body); input.Add("Hello", true); @@ -38,7 +36,7 @@ namespace Microsoft.AspNet.Server.KestrelTests public async Task Http10ConnectionCloseAsync() { var input = new TestInput(); - var body = MessageBody.For("HTTP/1.0", new Dictionary(), input.FrameContext); + var body = MessageBody.For("HTTP/1.0", new FrameRequestHeaders(), input.FrameContext); var stream = new FrameRequestStream().StartAcceptingReads(body); input.Add("Hello", true); @@ -56,7 +54,7 @@ namespace Microsoft.AspNet.Server.KestrelTests public async Task CanHandleLargeBlocks() { var input = new TestInput(); - var body = MessageBody.For("HTTP/1.0", new Dictionary(), input.FrameContext); + var body = MessageBody.For("HTTP/1.0", new FrameRequestHeaders(), input.FrameContext); var stream = new FrameRequestStream().StartAcceptingReads(body); // Input needs to be greater than 4032 bytes to allocate a block not backed by a slab. From f220a9f200ace78ec963f072adc98e1c15c8049a Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Sat, 26 Dec 2015 07:38:08 +0000 Subject: [PATCH 0528/1662] Faster Peek --- .../Infrastructure/MemoryPoolIterator2.cs | 35 +++++++++---------- 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolIterator2.cs b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolIterator2.cs index 08c4a75a35..207abfba52 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolIterator2.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolIterator2.cs @@ -92,28 +92,22 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure public int Peek() { - if (_block == null) - { - return -1; - } - else if (_index < _block.End) - { - return _block.Array[_index]; - } - else if (_block.Next == null) + var block = _block; + if (block == null) { return -1; } - var block = _block.Next; - var index = block.Start; - while (true) + var index = _index; + + if (index < block.End) { - if (index < block.End) - { - return block.Array[index]; - } - else if (block.Next == null) + return block.Array[index]; + } + + do + { + if (block.Next == null) { return -1; } @@ -122,7 +116,12 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure block = block.Next; index = block.Start; } - } + + if (index < block.End) + { + return block.Array[index]; + } + } while (true); } public unsafe long PeekLong() From eb8f860bd6428ad3dda40f819ff2a7d3389f7c79 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Sat, 26 Dec 2015 15:07:00 +0000 Subject: [PATCH 0529/1662] Avoid generic boxing in Post --- .../Infrastructure/KestrelThread.cs | 47 +++++++++++++++++-- 1 file changed, 42 insertions(+), 5 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs index de603b4458..4974ba7a9f 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs @@ -9,6 +9,7 @@ using System.Threading.Tasks; using Microsoft.AspNet.Hosting; using Microsoft.AspNet.Server.Kestrel.Infrastructure; using Microsoft.AspNet.Server.Kestrel.Networking; +using Microsoft.AspNet.Server.Kestrel.Http; using Microsoft.Extensions.Logging; namespace Microsoft.AspNet.Server.Kestrel @@ -24,6 +25,11 @@ namespace Microsoft.AspNet.Server.Kestrel private const int _maxLoops = 8; private static Action _threadCallbackAdapter = (callback, state) => ((Action)callback).Invoke((KestrelThread)state); + private static Action _socketCallbackAdapter = (callback, state) => ((Action)callback).Invoke((SocketOutput)state); + private static Action _tcsCallbackAdapter = (callback, state) => ((Action>)callback).Invoke((TaskCompletionSource)state); + private static Action _listenerPrimaryCallbackAdapter = (callback, state) => ((Action)callback).Invoke((ListenerPrimary)state); + private static Action _listenerSecondaryCallbackAdapter = (callback, state) => ((Action)callback).Invoke((ListenerSecondary)state); + private KestrelEngine _engine; private readonly IApplicationLifetime _appLifetime; private Thread _thread; @@ -144,13 +150,13 @@ namespace Microsoft.AspNet.Server.Kestrel _post.Send(); } - public void Post(Action callback, T state) + public void Post(Action callback, SocketOutput state) { lock (_workSync) { _workAdding.Enqueue(new Work { - CallbackAdapter = (callback2, state2) => ((Action)callback2).Invoke((T)state2), + CallbackAdapter = _socketCallbackAdapter, Callback = callback, State = state }); @@ -158,14 +164,28 @@ namespace Microsoft.AspNet.Server.Kestrel _post.Send(); } - public Task PostAsync(Action callback, T state) + public void Post(Action> callback, TaskCompletionSource state) + { + lock (_workSync) + { + _workAdding.Enqueue(new Work + { + CallbackAdapter = _tcsCallbackAdapter, + Callback = callback, + State = state + }); + } + _post.Send(); + } + + public Task PostAsync(Action callback, ListenerPrimary state) { var tcs = new TaskCompletionSource(); lock (_workSync) { _workAdding.Enqueue(new Work { - CallbackAdapter = (state1, state2) => ((Action)state1).Invoke((T)state2), + CallbackAdapter = _listenerPrimaryCallbackAdapter, Callback = callback, State = state, Completion = tcs @@ -175,7 +195,24 @@ namespace Microsoft.AspNet.Server.Kestrel return tcs.Task; } - public void Send(Action callback, T state) + public Task PostAsync(Action callback, ListenerSecondary state) + { + var tcs = new TaskCompletionSource(); + lock (_workSync) + { + _workAdding.Enqueue(new Work + { + CallbackAdapter = _listenerSecondaryCallbackAdapter, + Callback = callback, + State = state, + Completion = tcs + }); + } + _post.Send(); + return tcs.Task; + } + + public void Send(Action callback, ListenerSecondary state) { if (_loop.ThreadId == Thread.CurrentThread.ManagedThreadId) { From 67ed24896a312712af17ad9df4f1f2bf24688448 Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Mon, 14 Dec 2015 19:42:00 -0800 Subject: [PATCH 0530/1662] Dispose socket on Accept() error. --- src/Microsoft.AspNet.Server.Kestrel/Http/PipeListener.cs | 6 +++--- .../Http/PipeListenerPrimary.cs | 6 +++--- src/Microsoft.AspNet.Server.Kestrel/Http/TcpListener.cs | 9 +++++---- .../Http/TcpListenerPrimary.cs | 9 +++++---- 4 files changed, 16 insertions(+), 14 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/PipeListener.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/PipeListener.cs index b3a15c1fe3..c7e545a549 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/PipeListener.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/PipeListener.cs @@ -37,19 +37,19 @@ namespace Microsoft.AspNet.Server.Kestrel.Http protected override void OnConnection(UvStreamHandle listenSocket, int status) { var acceptSocket = new UvPipeHandle(Log); - acceptSocket.Init(Thread.Loop, false); try { + acceptSocket.Init(Thread.Loop, false); listenSocket.Accept(acceptSocket); + DispatchConnection(acceptSocket); } catch (UvException ex) { Log.LogError("PipeListener.OnConnection", ex); + acceptSocket.Dispose(); return; } - - DispatchConnection(acceptSocket); } } } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/PipeListenerPrimary.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/PipeListenerPrimary.cs index 7f15ccb2c0..7d907e20c2 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/PipeListenerPrimary.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/PipeListenerPrimary.cs @@ -37,19 +37,19 @@ namespace Microsoft.AspNet.Server.Kestrel.Http protected override void OnConnection(UvStreamHandle listenSocket, int status) { var acceptSocket = new UvPipeHandle(Log); - acceptSocket.Init(Thread.Loop, false); try { + acceptSocket.Init(Thread.Loop, false); listenSocket.Accept(acceptSocket); + DispatchConnection(acceptSocket); } catch (UvException ex) { Log.LogError("ListenerPrimary.OnConnection", ex); + acceptSocket.Dispose(); return; } - - DispatchConnection(acceptSocket); } } } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/TcpListener.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/TcpListener.cs index 45769cc074..61f4a4fe0e 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/TcpListener.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/TcpListener.cs @@ -37,20 +37,21 @@ namespace Microsoft.AspNet.Server.Kestrel.Http protected override void OnConnection(UvStreamHandle listenSocket, int status) { var acceptSocket = new UvTcpHandle(Log); - acceptSocket.Init(Thread.Loop, Thread.QueueCloseHandle); - acceptSocket.NoDelay(NoDelay); try { + acceptSocket.Init(Thread.Loop, Thread.QueueCloseHandle); + acceptSocket.NoDelay(NoDelay); listenSocket.Accept(acceptSocket); + DispatchConnection(acceptSocket); + } catch (UvException ex) { Log.LogError("TcpListener.OnConnection", ex); + acceptSocket.Dispose(); return; } - - DispatchConnection(acceptSocket); } } } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/TcpListenerPrimary.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/TcpListenerPrimary.cs index 2116ed1ab0..98283232cd 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/TcpListenerPrimary.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/TcpListenerPrimary.cs @@ -39,20 +39,21 @@ namespace Microsoft.AspNet.Server.Kestrel.Http protected override void OnConnection(UvStreamHandle listenSocket, int status) { var acceptSocket = new UvTcpHandle(Log); - acceptSocket.Init(Thread.Loop, Thread.QueueCloseHandle); - acceptSocket.NoDelay(NoDelay); try { + acceptSocket.Init(Thread.Loop, Thread.QueueCloseHandle); + acceptSocket.NoDelay(NoDelay); listenSocket.Accept(acceptSocket); + DispatchConnection(acceptSocket); + } catch (UvException ex) { Log.LogError("TcpListenerPrimary.OnConnection", ex); + acceptSocket.Dispose(); return; } - - DispatchConnection(acceptSocket); } } } From 4e9f8366cfbc5f8154164dcba51b8f2dd3fe57b7 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Thu, 17 Dec 2015 10:36:59 +0000 Subject: [PATCH 0531/1662] Move stream reuse test to EngineTests --- .../ReuseStreamsTests.cs | 129 ------------------ .../EngineTests.cs | 87 ++++++++++++ 2 files changed, 87 insertions(+), 129 deletions(-) delete mode 100644 test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/ReuseStreamsTests.cs diff --git a/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/ReuseStreamsTests.cs b/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/ReuseStreamsTests.cs deleted file mode 100644 index b15c45d67b..0000000000 --- a/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/ReuseStreamsTests.cs +++ /dev/null @@ -1,129 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using System.Collections.Generic; -using System.IO; -using System.Net.Http; -using System.Threading.Tasks; -using Microsoft.AspNet.Builder; -using Microsoft.AspNet.Hosting; -using Microsoft.AspNet.Http.Features; -using Microsoft.Extensions.Configuration; -using Xunit; - -namespace Microsoft.AspNet.Server.Kestrel.FunctionalTests -{ - public class ReuseStreamsTests - { - [Fact] - public async Task ReuseStreamsOn() - { - var streamCount = 0; - var loopCount = 20; - Stream lastStream = null; - var config = new ConfigurationBuilder() - .AddInMemoryCollection(new Dictionary - { - { "server.urls", "http://localhost:8801/" }, - { "kestrel.reuseStreams", "true" } - }) - .Build(); - - var builder = new WebApplicationBuilder() - .UseConfiguration(config) - .UseServerFactory("Microsoft.AspNet.Server.Kestrel") - .Configure(app => - { - var serverInfo = app.ServerFeatures.Get(); - app.Run(context => - { - if (context.Request.Body != lastStream) - { - lastStream = context.Request.Body; - streamCount++; - } - return context.Request.Body.CopyToAsync(context.Response.Body); - }); - }); - - using (var app = builder.Build().Start()) - { - using (var client = new HttpClient()) - { - for (int i = 0; i < loopCount; i++) - { - var content = $"{i} Hello World {i}"; - var request = new HttpRequestMessage() - { - RequestUri = new Uri("http://localhost:8801/"), - Method = HttpMethod.Post, - Content = new StringContent(content) - }; - request.Headers.Add("Connection", new string[] { "Keep-Alive" }); - var responseMessage = await client.SendAsync(request); - var result = await responseMessage.Content.ReadAsStringAsync(); - Assert.Equal(content, result); - } - } - } - - Assert.True(streamCount < loopCount); - } - - [Fact] - public async Task ReuseStreamsOff() - { - var streamCount = 0; - var loopCount = 20; - Stream lastStream = null; - var config = new ConfigurationBuilder() - .AddInMemoryCollection(new Dictionary - { - { "server.urls", "http://localhost:8802/" }, - { "kestrel.reuseStreams", "false" } - }) - .Build(); - - var hostBuilder = new WebApplicationBuilder() - .UseConfiguration(config) - .UseServerFactory("Microsoft.AspNet.Server.Kestrel") - .Configure(app => - { - var serverInfo = app.ServerFeatures.Get(); - app.Run(context => - { - if (context.Request.Body != lastStream) - { - lastStream = context.Request.Body; - streamCount++; - } - return context.Request.Body.CopyToAsync(context.Response.Body); - }); - }); - - using (var app = hostBuilder.Build().Start()) - { - using (var client = new HttpClient()) - { - for (int i = 0; i < loopCount; i++) - { - var content = $"{i} Hello World {i}"; - var request = new HttpRequestMessage() - { - RequestUri = new Uri("http://localhost:8802/"), - Method = HttpMethod.Post, - Content = new StringContent(content) - }; - request.Headers.Add("Connection", new string[] { "Keep-Alive" }); - var responseMessage = await client.SendAsync(request); - var result = await responseMessage.Content.ReadAsStringAsync(); - Assert.Equal(content, result); - } - } - } - - Assert.Equal(loopCount, streamCount); - } - } -} diff --git a/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs index 0bfa31b438..76b65c58f1 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Linq; using System.IO; using System.Net; using System.Net.Sockets; @@ -182,6 +183,92 @@ namespace Microsoft.AspNet.Server.KestrelTests } } + [ConditionalTheory] + [MemberData(nameof(ConnectionFilterData))] + public async Task ReuseStreamsOn(ServiceContext testContext) + { + testContext.ReuseStreams = true; + + var streamCount = 0; + var loopCount = 20; + Stream lastStream = null; + + using (var server = new TestServer( + context => + { + if (context.Request.Body != lastStream) + { + lastStream = context.Request.Body; + streamCount++; + } + context.Response.Headers.Clear(); + return context.Request.Body.CopyToAsync(context.Response.Body); + }, + testContext)) + { + + using (var connection = new TestConnection()) + { + var requestData = + Enumerable.Repeat("GET / HTTP/1.1\r\n", loopCount) + .Concat(new[] { "GET / HTTP/1.1\r\nConnection: close\r\n\r\nGoodbye" }); + + var responseData = + Enumerable.Repeat("HTTP/1.1 200 OK\r\nContent-Length: 0\r\n", loopCount) + .Concat(new[] { "HTTP/1.1 200 OK\r\nConnection: close\r\n\r\nGoodbye" }); + + await connection.SendEnd(requestData.ToArray()); + + await connection.ReceiveEnd(responseData.ToArray()); + } + + Assert.Equal(1, streamCount); + } + } + + [ConditionalTheory] + [MemberData(nameof(ConnectionFilterData))] + public async Task ReuseStreamsOff(ServiceContext testContext) + { + testContext.ReuseStreams = false; + + var streamCount = 0; + var loopCount = 20; + Stream lastStream = null; + + using (var server = new TestServer( + context => + { + if (context.Request.Body != lastStream) + { + lastStream = context.Request.Body; + streamCount++; + } + context.Response.Headers.Clear(); + return context.Request.Body.CopyToAsync(context.Response.Body); + }, + testContext)) + { + + using (var connection = new TestConnection()) + { + var requestData = + Enumerable.Repeat("GET / HTTP/1.1\r\n", loopCount) + .Concat(new[] { "GET / HTTP/1.1\r\nConnection: close\r\n\r\nGoodbye" }); + + var responseData = + Enumerable.Repeat("HTTP/1.1 200 OK\r\nContent-Length: 0\r\n", loopCount) + .Concat(new[] { "HTTP/1.1 200 OK\r\nConnection: close\r\n\r\nGoodbye" }); + + await connection.SendEnd(requestData.ToArray()); + + await connection.ReceiveEnd(responseData.ToArray()); + } + + Assert.Equal(loopCount + 1, streamCount); + } + } + [ConditionalTheory] [MemberData(nameof(ConnectionFilterData))] [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Test hangs after execution on Mono.")] From 982ab99b45c044952d3e060642fb56d12dbe994b Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Mon, 28 Dec 2015 23:02:41 +0000 Subject: [PATCH 0532/1662] Make callback adapters readonly --- .../Infrastructure/KestrelThread.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs index 4974ba7a9f..4769d62d6e 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs @@ -24,11 +24,11 @@ namespace Microsoft.AspNet.Server.Kestrel // otherwise it needs to wait till the next pass of the libuv loop private const int _maxLoops = 8; - private static Action _threadCallbackAdapter = (callback, state) => ((Action)callback).Invoke((KestrelThread)state); - private static Action _socketCallbackAdapter = (callback, state) => ((Action)callback).Invoke((SocketOutput)state); - private static Action _tcsCallbackAdapter = (callback, state) => ((Action>)callback).Invoke((TaskCompletionSource)state); - private static Action _listenerPrimaryCallbackAdapter = (callback, state) => ((Action)callback).Invoke((ListenerPrimary)state); - private static Action _listenerSecondaryCallbackAdapter = (callback, state) => ((Action)callback).Invoke((ListenerSecondary)state); + private static readonly Action _threadCallbackAdapter = (callback, state) => ((Action)callback).Invoke((KestrelThread)state); + private static readonly Action _socketCallbackAdapter = (callback, state) => ((Action)callback).Invoke((SocketOutput)state); + private static readonly Action _tcsCallbackAdapter = (callback, state) => ((Action>)callback).Invoke((TaskCompletionSource)state); + private static readonly Action _listenerPrimaryCallbackAdapter = (callback, state) => ((Action)callback).Invoke((ListenerPrimary)state); + private static readonly Action _listenerSecondaryCallbackAdapter = (callback, state) => ((Action)callback).Invoke((ListenerSecondary)state); private KestrelEngine _engine; private readonly IApplicationLifetime _appLifetime; From 9019ac39ae5e359d1a576703aee3452d9308158a Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Sat, 26 Dec 2015 07:36:57 +0000 Subject: [PATCH 0533/1662] Faster Take --- .../Infrastructure/MemoryPoolIterator2.cs | 32 +++++++++++-------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolIterator2.cs b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolIterator2.cs index 08c4a75a35..465f1a7b82 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolIterator2.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolIterator2.cs @@ -59,26 +59,23 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure public int Take() { - if (_block == null) + var block = _block; + if (block == null) { return -1; } - else if (_index < _block.End) + + var index = _index; + + if (index < block.End) { - return _block.Array[_index++]; + _index = index + 1; + return block.Array[index]; } - var block = _block; - var index = _index; - while (true) + do { - if (index < block.End) - { - _block = block; - _index = index + 1; - return block.Array[index]; - } - else if (block.Next == null) + if (block.Next == null) { return -1; } @@ -87,7 +84,14 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure block = block.Next; index = block.Start; } - } + + if (index < block.End) + { + _block = block; + _index = index + 1; + return block.Array[index]; + } + } while (true); } public int Peek() From 80dc2844072ca6186d55c41b0507011c0890c498 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Tue, 29 Dec 2015 08:50:59 +0000 Subject: [PATCH 0534/1662] Checked length --- .../Infrastructure/MemoryPoolIterator2.cs | 29 ++++++++++--------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolIterator2.cs b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolIterator2.cs index 207abfba52..8b97da1eef 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolIterator2.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolIterator2.cs @@ -513,21 +513,24 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure var block = _block; var index = _index; var length = 0; - while (true) + checked { - if (block == end._block) + while (true) { - return length + end._index - index; - } - else if (block.Next == null) - { - throw new InvalidOperationException("end did not follow iterator"); - } - else - { - length += block.End - index; - block = block.Next; - index = block.Start; + if (block == end._block) + { + return length + end._index - index; + } + else if (block.Next == null) + { + throw new InvalidOperationException("end did not follow iterator"); + } + else + { + length += block.End - index; + block = block.Next; + index = block.Start; + } } } } From 8fdfef460a98dacf4a4cfc4caa2551db56c4b7bf Mon Sep 17 00:00:00 2001 From: Thom Kiesewetter Date: Tue, 29 Dec 2015 14:41:46 +0100 Subject: [PATCH 0535/1662] Faster unsafe pointers --- .../Http/FrameHeaders.Generated.cs | 2329 +++++++++-------- .../Infrastructure/MemoryPoolIterator2.cs | 17 +- .../MemoryPoolIterator2Extensions.cs | 2 +- .../KnownHeaders.cs | 74 +- 4 files changed, 1223 insertions(+), 1199 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameHeaders.Generated.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameHeaders.Generated.cs index 16c80b3980..74dbad040e 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameHeaders.Generated.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameHeaders.Generated.cs @@ -719,7 +719,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } protected override StringValues GetValueFast(string key) { - switch(key.Length) + switch (key.Length) { case 13: { @@ -1289,7 +1289,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } protected override bool TryGetValueFast(string key, out StringValues value) { - switch(key.Length) + switch (key.Length) { case 13: { @@ -1938,7 +1938,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } protected override void SetValueFast(string key, StringValues value) { - switch(key.Length) + switch (key.Length) { case 13: { @@ -2299,7 +2299,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } protected override void AddValueFast(string key, StringValues value) { - switch(key.Length) + switch (key.Length) { case 13: { @@ -2824,7 +2824,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } protected override bool RemoveFast(string key) { - switch(key.Length) + switch (key.Length) { case 13: { @@ -3939,651 +3939,657 @@ namespace Microsoft.AspNet.Server.Kestrel.Http public unsafe void Append(byte[] keyBytes, int keyOffset, int keyLength, string value) { - fixed(byte* ptr = keyBytes) { var pUB = ptr + keyOffset; var pUL = (ulong*)pUB; var pUI = (uint*)pUB; var pUS = (ushort*)pUB; - switch(keyLength) - { - case 13: - { - if ((((pUL[0] & 16131893727263186911uL) == 5711458528024281411uL) && ((pUI[2] & 3755991007u) == 1330795598u) && ((pUB[12] & 223u) == 76u))) + fixed (byte* ptr = &keyBytes[keyOffset]) + { + var pUB = ptr; + var pUL = (ulong*)pUB; + var pUI = (uint*)pUB; + var pUS = (ushort*)pUB; + switch (keyLength) + { + case 13: { - if (((_bits & 1L) != 0)) + if ((((pUL[0] & 16131893727263186911uL) == 5711458528024281411uL) && ((pUI[2] & 3755991007u) == 1330795598u) && ((pUB[12] & 223u) == 76u))) { - _CacheControl = AppendValue(_CacheControl, value); + if (((_bits & 1L) != 0)) + { + _CacheControl = AppendValue(_CacheControl, value); + } + else + { + _bits |= 1L; + _CacheControl = new StringValues(value); + } + return; } - else + + if ((((pUL[0] & 18437701552104792031uL) == 3266321689424580419uL) && ((pUI[2] & 3755991007u) == 1196310866u) && ((pUB[12] & 223u) == 69u))) { - _bits |= 1L; - _CacheControl = new StringValues(value); + if (((_bits & 131072L) != 0)) + { + _ContentRange = AppendValue(_ContentRange, value); + } + else + { + _bits |= 131072L; + _ContentRange = new StringValues(value); + } + return; + } + + if ((((pUL[0] & 16131858680330051551uL) == 4922237774822850892uL) && ((pUI[2] & 3755991007u) == 1162430025u) && ((pUB[12] & 223u) == 68u))) + { + if (((_bits & 524288L) != 0)) + { + _LastModified = AppendValue(_LastModified, value); + } + else + { + _bits |= 524288L; + _LastModified = new StringValues(value); + } + return; + } + + if ((((pUL[0] & 16131858542891098079uL) == 6505821637182772545uL) && ((pUI[2] & 3755991007u) == 1330205761u) && ((pUB[12] & 223u) == 78u))) + { + if (((_bits & 16777216L) != 0)) + { + _Authorization = AppendValue(_Authorization, value); + } + else + { + _bits |= 16777216L; + _Authorization = new StringValues(value); + } + return; + } + + if ((((pUL[0] & 18437701552106889183uL) == 3262099607620765257uL) && ((pUI[2] & 3755991007u) == 1129595213u) && ((pUB[12] & 223u) == 72u))) + { + if (((_bits & 2147483648L) != 0)) + { + _IfNoneMatch = AppendValue(_IfNoneMatch, value); + } + else + { + _bits |= 2147483648L; + _IfNoneMatch = new StringValues(value); + } + return; } - return; } - - if ((((pUL[0] & 18437701552104792031uL) == 3266321689424580419uL) && ((pUI[2] & 3755991007u) == 1196310866u) && ((pUB[12] & 223u) == 69u))) + break; + + case 10: { - if (((_bits & 131072L) != 0)) + if ((((pUL[0] & 16131858542891098079uL) == 5283922227757993795uL) && ((pUS[4] & 57311u) == 20047u))) { - _ContentRange = AppendValue(_ContentRange, value); + if (((_bits & 2L) != 0)) + { + _Connection = AppendValue(_Connection, value); + } + else + { + _bits |= 2L; + _Connection = new StringValues(value); + } + return; } - else + + if ((((pUL[0] & 16131858680330051551uL) == 5281668125874799947uL) && ((pUS[4] & 57311u) == 17750u))) { - _bits |= 131072L; - _ContentRange = new StringValues(value); + if (((_bits & 8L) != 0)) + { + _KeepAlive = AppendValue(_KeepAlive, value); + } + else + { + _bits |= 8L; + _KeepAlive = new StringValues(value); + } + return; + } + + if ((((pUL[0] & 16131858680330051551uL) == 4992030374873092949uL) && ((pUS[4] & 57311u) == 21582u))) + { + if (((_bits & 1099511627776L) != 0)) + { + _UserAgent = AppendValue(_UserAgent, value); + } + else + { + _bits |= 1099511627776L; + _UserAgent = new StringValues(value); + } + return; } - return; } - - if ((((pUL[0] & 16131858680330051551uL) == 4922237774822850892uL) && ((pUI[2] & 3755991007u) == 1162430025u) && ((pUB[12] & 223u) == 68u))) + break; + + case 4: { - if (((_bits & 524288L) != 0)) + if ((((pUI[0] & 3755991007u) == 1163149636u))) { - _LastModified = AppendValue(_LastModified, value); + if (((_bits & 4L) != 0)) + { + _Date = AppendValue(_Date, value); + } + else + { + _bits |= 4L; + _Date = new StringValues(value); + } + return; } - else + + if ((((pUI[0] & 3755991007u) == 1297044038u))) { - _bits |= 524288L; - _LastModified = new StringValues(value); + if (((_bits & 134217728L) != 0)) + { + _From = AppendValue(_From, value); + } + else + { + _bits |= 134217728L; + _From = new StringValues(value); + } + return; + } + + if ((((pUI[0] & 3755991007u) == 1414745928u))) + { + if (((_bits & 268435456L) != 0)) + { + _Host = AppendValue(_Host, value); + } + else + { + _bits |= 268435456L; + _Host = new StringValues(value); + } + return; } - return; } - - if ((((pUL[0] & 16131858542891098079uL) == 6505821637182772545uL) && ((pUI[2] & 3755991007u) == 1330205761u) && ((pUB[12] & 223u) == 78u))) + break; + + case 6: { - if (((_bits & 16777216L) != 0)) + if ((((pUI[0] & 3755991007u) == 1195463248u) && ((pUS[2] & 57311u) == 16717u))) { - _Authorization = AppendValue(_Authorization, value); + if (((_bits & 16L) != 0)) + { + _Pragma = AppendValue(_Pragma, value); + } + else + { + _bits |= 16L; + _Pragma = new StringValues(value); + } + return; } - else + + if ((((pUI[0] & 3755991007u) == 1162036033u) && ((pUS[2] & 57311u) == 21584u))) { - _bits |= 16777216L; - _Authorization = new StringValues(value); + if (((_bits & 1048576L) != 0)) + { + _Accept = AppendValue(_Accept, value); + } + else + { + _bits |= 1048576L; + _Accept = new StringValues(value); + } + return; + } + + if ((((pUI[0] & 3755991007u) == 1263488835u) && ((pUS[2] & 57311u) == 17737u))) + { + if (((_bits & 33554432L) != 0)) + { + _Cookie = AppendValue(_Cookie, value); + } + else + { + _bits |= 33554432L; + _Cookie = new StringValues(value); + } + return; + } + + if ((((pUI[0] & 3755991007u) == 1162893381u) && ((pUS[2] & 57311u) == 21571u))) + { + if (((_bits & 67108864L) != 0)) + { + _Expect = AppendValue(_Expect, value); + } + else + { + _bits |= 67108864L; + _Expect = new StringValues(value); + } + return; } - return; } - - if ((((pUL[0] & 18437701552106889183uL) == 3262099607620765257uL) && ((pUI[2] & 3755991007u) == 1129595213u) && ((pUB[12] & 223u) == 72u))) + break; + + case 7: { - if (((_bits & 2147483648L) != 0)) + if ((((pUI[0] & 3755991007u) == 1229017684u) && ((pUS[2] & 57311u) == 17740u) && ((pUB[6] & 223u) == 82u))) { - _IfNoneMatch = AppendValue(_IfNoneMatch, value); + if (((_bits & 32L) != 0)) + { + _Trailer = AppendValue(_Trailer, value); + } + else + { + _bits |= 32L; + _Trailer = new StringValues(value); + } + return; } - else + + if ((((pUI[0] & 3755991007u) == 1380405333u) && ((pUS[2] & 57311u) == 17473u) && ((pUB[6] & 223u) == 69u))) { - _bits |= 2147483648L; - _IfNoneMatch = new StringValues(value); + if (((_bits & 128L) != 0)) + { + _Upgrade = AppendValue(_Upgrade, value); + } + else + { + _bits |= 128L; + _Upgrade = new StringValues(value); + } + return; + } + + if ((((pUI[0] & 3755991007u) == 1314013527u) && ((pUS[2] & 57311u) == 20041u) && ((pUB[6] & 223u) == 71u))) + { + if (((_bits & 512L) != 0)) + { + _Warning = AppendValue(_Warning, value); + } + else + { + _bits |= 512L; + _Warning = new StringValues(value); + } + return; + } + + if ((((pUI[0] & 3755991007u) == 1230002245u) && ((pUS[2] & 57311u) == 17746u) && ((pUB[6] & 223u) == 83u))) + { + if (((_bits & 262144L) != 0)) + { + _Expires = AppendValue(_Expires, value); + } + else + { + _bits |= 262144L; + _Expires = new StringValues(value); + } + return; + } + + if ((((pUI[0] & 3755991007u) == 1162233170u) && ((pUS[2] & 57311u) == 17746u) && ((pUB[6] & 223u) == 82u))) + { + if (((_bits & 68719476736L) != 0)) + { + _Referer = AppendValue(_Referer, value); + } + else + { + _bits |= 68719476736L; + _Referer = new StringValues(value); + } + return; } - return; } - } - break; - - case 10: - { - if ((((pUL[0] & 16131858542891098079uL) == 5283922227757993795uL) && ((pUS[4] & 57311u) == 20047u))) + break; + + case 17: { - if (((_bits & 2L) != 0)) + if ((((pUL[0] & 16131858542891098079uL) == 5928221808112259668uL) && ((pUL[1] & 16131858542891098111uL) == 5641115115480565037uL) && ((pUB[16] & 223u) == 71u))) { - _Connection = AppendValue(_Connection, value); + if (((_bits & 64L) != 0)) + { + _TransferEncoding = AppendValue(_TransferEncoding, value); + } + else + { + _bits |= 64L; + _TransferEncoding = new StringValues(value); + } + return; } - else + + if ((((pUL[0] & 16131858542893195231uL) == 5064654363342751305uL) && ((pUL[1] & 16131858543427968991uL) == 4849894470315165001uL) && ((pUB[16] & 223u) == 69u))) { - _bits |= 2L; - _Connection = new StringValues(value); + if (((_bits & 1073741824L) != 0)) + { + _IfModifiedSince = AppendValue(_IfModifiedSince, value); + } + else + { + _bits |= 1073741824L; + _IfModifiedSince = new StringValues(value); + } + return; } - return; } - - if ((((pUL[0] & 16131858680330051551uL) == 5281668125874799947uL) && ((pUS[4] & 57311u) == 17750u))) + break; + + case 3: { - if (((_bits & 8L) != 0)) + if ((((pUS[0] & 57311u) == 18774u) && ((pUB[2] & 223u) == 65u))) { - _KeepAlive = AppendValue(_KeepAlive, value); + if (((_bits & 256L) != 0)) + { + _Via = AppendValue(_Via, value); + } + else + { + _bits |= 256L; + _Via = new StringValues(value); + } + return; } - else - { - _bits |= 8L; - _KeepAlive = new StringValues(value); - } - return; } - - if ((((pUL[0] & 16131858680330051551uL) == 4992030374873092949uL) && ((pUS[4] & 57311u) == 21582u))) + break; + + case 5: { - if (((_bits & 1099511627776L) != 0)) + if ((((pUI[0] & 3755991007u) == 1330400321u) && ((pUB[4] & 223u) == 87u))) { - _UserAgent = AppendValue(_UserAgent, value); + if (((_bits & 1024L) != 0)) + { + _Allow = AppendValue(_Allow, value); + } + else + { + _bits |= 1024L; + _Allow = new StringValues(value); + } + return; } - else + + if ((((pUI[0] & 3755991007u) == 1196310866u) && ((pUB[4] & 223u) == 69u))) { - _bits |= 1099511627776L; - _UserAgent = new StringValues(value); + if (((_bits & 137438953472L) != 0)) + { + _Range = AppendValue(_Range, value); + } + else + { + _bits |= 137438953472L; + _Range = new StringValues(value); + } + return; } - return; } - } - break; - - case 4: - { - if ((((pUI[0] & 3755991007u) == 1163149636u))) + break; + + case 14: { - if (((_bits & 4L) != 0)) + if ((((pUL[0] & 18437701552104792031uL) == 3266321689424580419uL) && ((pUI[2] & 3755991007u) == 1196311884u) && ((pUS[6] & 57311u) == 18516u))) { - _Date = AppendValue(_Date, value); + if (((_bits & 2048L) != 0)) + { + _ContentLength = AppendValue(_ContentLength, value); + } + else + { + _bits |= 2048L; + _ContentLength = new StringValues(value); + } + return; } - else + + if ((((pUL[0] & 16140865742145839071uL) == 4840617878229304129uL) && ((pUI[2] & 3755991007u) == 1397899592u) && ((pUS[6] & 57311u) == 21573u))) { - _bits |= 4L; - _Date = new StringValues(value); + if (((_bits & 2097152L) != 0)) + { + _AcceptCharset = AppendValue(_AcceptCharset, value); + } + else + { + _bits |= 2097152L; + _AcceptCharset = new StringValues(value); + } + return; } - return; } - - if ((((pUI[0] & 3755991007u) == 1297044038u))) + break; + + case 12: { - if (((_bits & 134217728L) != 0)) + if ((((pUL[0] & 18437701552104792031uL) == 3266321689424580419uL) && ((pUI[2] & 3755991007u) == 1162893652u))) { - _From = AppendValue(_From, value); + if (((_bits & 4096L) != 0)) + { + _ContentType = AppendValue(_ContentType, value); + } + else + { + _bits |= 4096L; + _ContentType = new StringValues(value); + } + return; } - else + + if ((((pUL[0] & 16131858543427968991uL) == 6292178792217067853uL) && ((pUI[2] & 3755991007u) == 1396986433u))) { - _bits |= 134217728L; - _From = new StringValues(value); + if (((_bits & 17179869184L) != 0)) + { + _MaxForwards = AppendValue(_MaxForwards, value); + } + else + { + _bits |= 17179869184L; + _MaxForwards = new StringValues(value); + } + return; } - return; } - - if ((((pUI[0] & 3755991007u) == 1414745928u))) + break; + + case 16: { - if (((_bits & 268435456L) != 0)) + if ((((pUL[0] & 18437701552104792031uL) == 3266321689424580419uL) && ((pUL[1] & 16131858542891098079uL) == 5138124782612729413uL))) { - _Host = AppendValue(_Host, value); + if (((_bits & 8192L) != 0)) + { + _ContentEncoding = AppendValue(_ContentEncoding, value); + } + else + { + _bits |= 8192L; + _ContentEncoding = new StringValues(value); + } + return; } - else + + if ((((pUL[0] & 18437701552104792031uL) == 3266321689424580419uL) && ((pUL[1] & 16131858542891098079uL) == 4992030546487820620uL))) { - _bits |= 268435456L; - _Host = new StringValues(value); + if (((_bits & 16384L) != 0)) + { + _ContentLanguage = AppendValue(_ContentLanguage, value); + } + else + { + _bits |= 16384L; + _ContentLanguage = new StringValues(value); + } + return; + } + + if ((((pUL[0] & 18437701552104792031uL) == 3266321689424580419uL) && ((pUL[1] & 16131858542891098079uL) == 5642809484339531596uL))) + { + if (((_bits & 32768L) != 0)) + { + _ContentLocation = AppendValue(_ContentLocation, value); + } + else + { + _bits |= 32768L; + _ContentLocation = new StringValues(value); + } + return; } - return; } - } - break; - - case 6: - { - if ((((pUI[0] & 3755991007u) == 1195463248u) && ((pUS[2] & 57311u) == 16717u))) + break; + + case 11: { - if (((_bits & 16L) != 0)) + if ((((pUL[0] & 18437701552104792031uL) == 3266321689424580419uL) && ((pUS[4] & 57311u) == 17485u) && ((pUB[10] & 255u) == 53u))) { - _Pragma = AppendValue(_Pragma, value); + if (((_bits & 65536L) != 0)) + { + _ContentMD5 = AppendValue(_ContentMD5, value); + } + else + { + _bits |= 65536L; + _ContentMD5 = new StringValues(value); + } + return; } - else - { - _bits |= 16L; - _Pragma = new StringValues(value); - } - return; } - - if ((((pUI[0] & 3755991007u) == 1162036033u) && ((pUS[2] & 57311u) == 21584u))) + break; + + case 15: { - if (((_bits & 1048576L) != 0)) + if ((((pUL[0] & 16140865742145839071uL) == 4984733066305160001uL) && ((pUI[2] & 3755991007u) == 1146045262u) && ((pUS[6] & 57311u) == 20041u) && ((pUB[14] & 223u) == 71u))) { - _Accept = AppendValue(_Accept, value); + if (((_bits & 4194304L) != 0)) + { + _AcceptEncoding = AppendValue(_AcceptEncoding, value); + } + else + { + _bits |= 4194304L; + _AcceptEncoding = new StringValues(value); + } + return; } - else + + if ((((pUL[0] & 16140865742145839071uL) == 5489136224570655553uL) && ((pUI[2] & 3755991007u) == 1430736449u) && ((pUS[6] & 57311u) == 18241u) && ((pUB[14] & 223u) == 69u))) { - _bits |= 1048576L; - _Accept = new StringValues(value); + if (((_bits & 8388608L) != 0)) + { + _AcceptLanguage = AppendValue(_AcceptLanguage, value); + } + else + { + _bits |= 8388608L; + _AcceptLanguage = new StringValues(value); + } + return; } - return; } - - if ((((pUI[0] & 3755991007u) == 1263488835u) && ((pUS[2] & 57311u) == 17737u))) + break; + + case 8: { - if (((_bits & 33554432L) != 0)) + if ((((pUL[0] & 16131858542893195231uL) == 5207098233614845513uL))) { - _Cookie = AppendValue(_Cookie, value); + if (((_bits & 536870912L) != 0)) + { + _IfMatch = AppendValue(_IfMatch, value); + } + else + { + _bits |= 536870912L; + _IfMatch = new StringValues(value); + } + return; } - else + + if ((((pUL[0] & 16131858542893195231uL) == 4992044754422023753uL))) { - _bits |= 33554432L; - _Cookie = new StringValues(value); + if (((_bits & 4294967296L) != 0)) + { + _IfRange = AppendValue(_IfRange, value); + } + else + { + _bits |= 4294967296L; + _IfRange = new StringValues(value); + } + return; } - return; } - - if ((((pUI[0] & 3755991007u) == 1162893381u) && ((pUS[2] & 57311u) == 21571u))) + break; + + case 19: { - if (((_bits & 67108864L) != 0)) + if ((((pUL[0] & 16131858542893195231uL) == 4922237916571059785uL) && ((pUL[1] & 16131893727263186911uL) == 5283616559079179849uL) && ((pUS[8] & 57311u) == 17230u) && ((pUB[18] & 223u) == 69u))) { - _Expect = AppendValue(_Expect, value); + if (((_bits & 8589934592L) != 0)) + { + _IfUnmodifiedSince = AppendValue(_IfUnmodifiedSince, value); + } + else + { + _bits |= 8589934592L; + _IfUnmodifiedSince = new StringValues(value); + } + return; } - else + + if ((((pUL[0] & 16131893727263186911uL) == 6143241228466999888uL) && ((pUL[1] & 16131858542891098079uL) == 6071233043632179284uL) && ((pUS[8] & 57311u) == 20297u) && ((pUB[18] & 223u) == 78u))) { - _bits |= 67108864L; - _Expect = new StringValues(value); + if (((_bits & 34359738368L) != 0)) + { + _ProxyAuthorization = AppendValue(_ProxyAuthorization, value); + } + else + { + _bits |= 34359738368L; + _ProxyAuthorization = new StringValues(value); + } + return; } - return; } - } - break; - - case 7: - { - if ((((pUI[0] & 3755991007u) == 1229017684u) && ((pUS[2] & 57311u) == 17740u) && ((pUB[6] & 223u) == 82u))) + break; + + case 2: { - if (((_bits & 32L) != 0)) + if ((((pUS[0] & 57311u) == 17748u))) { - _Trailer = AppendValue(_Trailer, value); + if (((_bits & 274877906944L) != 0)) + { + _TE = AppendValue(_TE, value); + } + else + { + _bits |= 274877906944L; + _TE = new StringValues(value); + } + return; } - else - { - _bits |= 32L; - _Trailer = new StringValues(value); - } - return; } - - if ((((pUI[0] & 3755991007u) == 1380405333u) && ((pUS[2] & 57311u) == 17473u) && ((pUB[6] & 223u) == 69u))) + break; + + case 9: { - if (((_bits & 128L) != 0)) + if ((((pUL[0] & 16131858542891098079uL) == 6071217693351039572uL) && ((pUB[8] & 223u) == 69u))) { - _Upgrade = AppendValue(_Upgrade, value); + if (((_bits & 549755813888L) != 0)) + { + _Translate = AppendValue(_Translate, value); + } + else + { + _bits |= 549755813888L; + _Translate = new StringValues(value); + } + return; } - else - { - _bits |= 128L; - _Upgrade = new StringValues(value); - } - return; } - - if ((((pUI[0] & 3755991007u) == 1314013527u) && ((pUS[2] & 57311u) == 20041u) && ((pUB[6] & 223u) == 71u))) - { - if (((_bits & 512L) != 0)) - { - _Warning = AppendValue(_Warning, value); - } - else - { - _bits |= 512L; - _Warning = new StringValues(value); - } - return; - } - - if ((((pUI[0] & 3755991007u) == 1230002245u) && ((pUS[2] & 57311u) == 17746u) && ((pUB[6] & 223u) == 83u))) - { - if (((_bits & 262144L) != 0)) - { - _Expires = AppendValue(_Expires, value); - } - else - { - _bits |= 262144L; - _Expires = new StringValues(value); - } - return; - } - - if ((((pUI[0] & 3755991007u) == 1162233170u) && ((pUS[2] & 57311u) == 17746u) && ((pUB[6] & 223u) == 82u))) - { - if (((_bits & 68719476736L) != 0)) - { - _Referer = AppendValue(_Referer, value); - } - else - { - _bits |= 68719476736L; - _Referer = new StringValues(value); - } - return; - } - } - break; - - case 17: - { - if ((((pUL[0] & 16131858542891098079uL) == 5928221808112259668uL) && ((pUL[1] & 16131858542891098111uL) == 5641115115480565037uL) && ((pUB[16] & 223u) == 71u))) - { - if (((_bits & 64L) != 0)) - { - _TransferEncoding = AppendValue(_TransferEncoding, value); - } - else - { - _bits |= 64L; - _TransferEncoding = new StringValues(value); - } - return; - } - - if ((((pUL[0] & 16131858542893195231uL) == 5064654363342751305uL) && ((pUL[1] & 16131858543427968991uL) == 4849894470315165001uL) && ((pUB[16] & 223u) == 69u))) - { - if (((_bits & 1073741824L) != 0)) - { - _IfModifiedSince = AppendValue(_IfModifiedSince, value); - } - else - { - _bits |= 1073741824L; - _IfModifiedSince = new StringValues(value); - } - return; - } - } - break; - - case 3: - { - if ((((pUS[0] & 57311u) == 18774u) && ((pUB[2] & 223u) == 65u))) - { - if (((_bits & 256L) != 0)) - { - _Via = AppendValue(_Via, value); - } - else - { - _bits |= 256L; - _Via = new StringValues(value); - } - return; - } - } - break; - - case 5: - { - if ((((pUI[0] & 3755991007u) == 1330400321u) && ((pUB[4] & 223u) == 87u))) - { - if (((_bits & 1024L) != 0)) - { - _Allow = AppendValue(_Allow, value); - } - else - { - _bits |= 1024L; - _Allow = new StringValues(value); - } - return; - } - - if ((((pUI[0] & 3755991007u) == 1196310866u) && ((pUB[4] & 223u) == 69u))) - { - if (((_bits & 137438953472L) != 0)) - { - _Range = AppendValue(_Range, value); - } - else - { - _bits |= 137438953472L; - _Range = new StringValues(value); - } - return; - } - } - break; - - case 14: - { - if ((((pUL[0] & 18437701552104792031uL) == 3266321689424580419uL) && ((pUI[2] & 3755991007u) == 1196311884u) && ((pUS[6] & 57311u) == 18516u))) - { - if (((_bits & 2048L) != 0)) - { - _ContentLength = AppendValue(_ContentLength, value); - } - else - { - _bits |= 2048L; - _ContentLength = new StringValues(value); - } - return; - } - - if ((((pUL[0] & 16140865742145839071uL) == 4840617878229304129uL) && ((pUI[2] & 3755991007u) == 1397899592u) && ((pUS[6] & 57311u) == 21573u))) - { - if (((_bits & 2097152L) != 0)) - { - _AcceptCharset = AppendValue(_AcceptCharset, value); - } - else - { - _bits |= 2097152L; - _AcceptCharset = new StringValues(value); - } - return; - } - } - break; - - case 12: - { - if ((((pUL[0] & 18437701552104792031uL) == 3266321689424580419uL) && ((pUI[2] & 3755991007u) == 1162893652u))) - { - if (((_bits & 4096L) != 0)) - { - _ContentType = AppendValue(_ContentType, value); - } - else - { - _bits |= 4096L; - _ContentType = new StringValues(value); - } - return; - } - - if ((((pUL[0] & 16131858543427968991uL) == 6292178792217067853uL) && ((pUI[2] & 3755991007u) == 1396986433u))) - { - if (((_bits & 17179869184L) != 0)) - { - _MaxForwards = AppendValue(_MaxForwards, value); - } - else - { - _bits |= 17179869184L; - _MaxForwards = new StringValues(value); - } - return; - } - } - break; - - case 16: - { - if ((((pUL[0] & 18437701552104792031uL) == 3266321689424580419uL) && ((pUL[1] & 16131858542891098079uL) == 5138124782612729413uL))) - { - if (((_bits & 8192L) != 0)) - { - _ContentEncoding = AppendValue(_ContentEncoding, value); - } - else - { - _bits |= 8192L; - _ContentEncoding = new StringValues(value); - } - return; - } - - if ((((pUL[0] & 18437701552104792031uL) == 3266321689424580419uL) && ((pUL[1] & 16131858542891098079uL) == 4992030546487820620uL))) - { - if (((_bits & 16384L) != 0)) - { - _ContentLanguage = AppendValue(_ContentLanguage, value); - } - else - { - _bits |= 16384L; - _ContentLanguage = new StringValues(value); - } - return; - } - - if ((((pUL[0] & 18437701552104792031uL) == 3266321689424580419uL) && ((pUL[1] & 16131858542891098079uL) == 5642809484339531596uL))) - { - if (((_bits & 32768L) != 0)) - { - _ContentLocation = AppendValue(_ContentLocation, value); - } - else - { - _bits |= 32768L; - _ContentLocation = new StringValues(value); - } - return; - } - } - break; - - case 11: - { - if ((((pUL[0] & 18437701552104792031uL) == 3266321689424580419uL) && ((pUS[4] & 57311u) == 17485u) && ((pUB[10] & 255u) == 53u))) - { - if (((_bits & 65536L) != 0)) - { - _ContentMD5 = AppendValue(_ContentMD5, value); - } - else - { - _bits |= 65536L; - _ContentMD5 = new StringValues(value); - } - return; - } - } - break; - - case 15: - { - if ((((pUL[0] & 16140865742145839071uL) == 4984733066305160001uL) && ((pUI[2] & 3755991007u) == 1146045262u) && ((pUS[6] & 57311u) == 20041u) && ((pUB[14] & 223u) == 71u))) - { - if (((_bits & 4194304L) != 0)) - { - _AcceptEncoding = AppendValue(_AcceptEncoding, value); - } - else - { - _bits |= 4194304L; - _AcceptEncoding = new StringValues(value); - } - return; - } - - if ((((pUL[0] & 16140865742145839071uL) == 5489136224570655553uL) && ((pUI[2] & 3755991007u) == 1430736449u) && ((pUS[6] & 57311u) == 18241u) && ((pUB[14] & 223u) == 69u))) - { - if (((_bits & 8388608L) != 0)) - { - _AcceptLanguage = AppendValue(_AcceptLanguage, value); - } - else - { - _bits |= 8388608L; - _AcceptLanguage = new StringValues(value); - } - return; - } - } - break; - - case 8: - { - if ((((pUL[0] & 16131858542893195231uL) == 5207098233614845513uL))) - { - if (((_bits & 536870912L) != 0)) - { - _IfMatch = AppendValue(_IfMatch, value); - } - else - { - _bits |= 536870912L; - _IfMatch = new StringValues(value); - } - return; - } - - if ((((pUL[0] & 16131858542893195231uL) == 4992044754422023753uL))) - { - if (((_bits & 4294967296L) != 0)) - { - _IfRange = AppendValue(_IfRange, value); - } - else - { - _bits |= 4294967296L; - _IfRange = new StringValues(value); - } - return; - } - } - break; - - case 19: - { - if ((((pUL[0] & 16131858542893195231uL) == 4922237916571059785uL) && ((pUL[1] & 16131893727263186911uL) == 5283616559079179849uL) && ((pUS[8] & 57311u) == 17230u) && ((pUB[18] & 223u) == 69u))) - { - if (((_bits & 8589934592L) != 0)) - { - _IfUnmodifiedSince = AppendValue(_IfUnmodifiedSince, value); - } - else - { - _bits |= 8589934592L; - _IfUnmodifiedSince = new StringValues(value); - } - return; - } - - if ((((pUL[0] & 16131893727263186911uL) == 6143241228466999888uL) && ((pUL[1] & 16131858542891098079uL) == 6071233043632179284uL) && ((pUS[8] & 57311u) == 20297u) && ((pUB[18] & 223u) == 78u))) - { - if (((_bits & 34359738368L) != 0)) - { - _ProxyAuthorization = AppendValue(_ProxyAuthorization, value); - } - else - { - _bits |= 34359738368L; - _ProxyAuthorization = new StringValues(value); - } - return; - } - } - break; - - case 2: - { - if ((((pUS[0] & 57311u) == 17748u))) - { - if (((_bits & 274877906944L) != 0)) - { - _TE = AppendValue(_TE, value); - } - else - { - _bits |= 274877906944L; - _TE = new StringValues(value); - } - return; - } - } - break; - - case 9: - { - if ((((pUL[0] & 16131858542891098079uL) == 6071217693351039572uL) && ((pUB[8] & 223u) == 69u))) - { - if (((_bits & 549755813888L) != 0)) - { - _Translate = AppendValue(_Translate, value); - } - else - { - _bits |= 549755813888L; - _Translate = new StringValues(value); - } - return; - } - } - break; - }} + break; + } + } var key = System.Text.Encoding.ASCII.GetString(keyBytes, keyOffset, keyLength); StringValues existing; Unknown.TryGetValue(key, out existing); @@ -5631,7 +5637,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } protected override StringValues GetValueFast(string key) { - switch(key.Length) + switch (key.Length) { case 13: { @@ -6053,7 +6059,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } protected override bool TryGetValueFast(string key, out StringValues value) { - switch(key.Length) + switch (key.Length) { case 13: { @@ -6532,7 +6538,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } protected override void SetValueFast(string key, StringValues value) { - switch(key.Length) + switch (key.Length) { case 13: { @@ -6805,7 +6811,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } protected override void AddValueFast(string key, StringValues value) { - switch(key.Length) + switch (key.Length) { case 13: { @@ -7198,7 +7204,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } protected override bool RemoveFast(string key) { - switch(key.Length) + switch (key.Length) { case 13: { @@ -8030,14 +8036,14 @@ namespace Microsoft.AspNet.Server.Kestrel.Http if (((_bits & 1L) != 0)) { - foreach(var value in _CacheControl) - { - if (value != null) + foreach (var value in _CacheControl) { - output.CopyFrom(_headerBytes, 0, 17); - output.CopyFromAscii(value); + if (value != null) + { + output.CopyFrom(_headerBytes, 0, 17); + output.CopyFromAscii(value); + } } - } } if (((_bits & 2L) != 0)) @@ -8045,15 +8051,16 @@ namespace Microsoft.AspNet.Server.Kestrel.Http if (_rawConnection != null) { output.CopyFrom(_rawConnection, 0, _rawConnection.Length); - } else - foreach(var value in _Connection) - { - if (value != null) + } + else + foreach (var value in _Connection) { - output.CopyFrom(_headerBytes, 17, 14); - output.CopyFromAscii(value); + if (value != null) + { + output.CopyFrom(_headerBytes, 17, 14); + output.CopyFromAscii(value); + } } - } } if (((_bits & 4L) != 0)) @@ -8061,51 +8068,52 @@ namespace Microsoft.AspNet.Server.Kestrel.Http if (_rawDate != null) { output.CopyFrom(_rawDate, 0, _rawDate.Length); - } else - foreach(var value in _Date) - { - if (value != null) + } + else + foreach (var value in _Date) { - output.CopyFrom(_headerBytes, 31, 8); - output.CopyFromAscii(value); + if (value != null) + { + output.CopyFrom(_headerBytes, 31, 8); + output.CopyFromAscii(value); + } } - } } if (((_bits & 8L) != 0)) { - foreach(var value in _KeepAlive) - { - if (value != null) + foreach (var value in _KeepAlive) { - output.CopyFrom(_headerBytes, 39, 14); - output.CopyFromAscii(value); + if (value != null) + { + output.CopyFrom(_headerBytes, 39, 14); + output.CopyFromAscii(value); + } } - } } if (((_bits & 16L) != 0)) { - foreach(var value in _Pragma) - { - if (value != null) + foreach (var value in _Pragma) { - output.CopyFrom(_headerBytes, 53, 10); - output.CopyFromAscii(value); + if (value != null) + { + output.CopyFrom(_headerBytes, 53, 10); + output.CopyFromAscii(value); + } } - } } if (((_bits & 32L) != 0)) { - foreach(var value in _Trailer) - { - if (value != null) + foreach (var value in _Trailer) { - output.CopyFrom(_headerBytes, 63, 11); - output.CopyFromAscii(value); + if (value != null) + { + output.CopyFrom(_headerBytes, 63, 11); + output.CopyFromAscii(value); + } } - } } if (((_bits & 64L) != 0)) @@ -8113,63 +8121,64 @@ namespace Microsoft.AspNet.Server.Kestrel.Http if (_rawTransferEncoding != null) { output.CopyFrom(_rawTransferEncoding, 0, _rawTransferEncoding.Length); - } else - foreach(var value in _TransferEncoding) - { - if (value != null) + } + else + foreach (var value in _TransferEncoding) { - output.CopyFrom(_headerBytes, 74, 21); - output.CopyFromAscii(value); + if (value != null) + { + output.CopyFrom(_headerBytes, 74, 21); + output.CopyFromAscii(value); + } } - } } if (((_bits & 128L) != 0)) { - foreach(var value in _Upgrade) - { - if (value != null) + foreach (var value in _Upgrade) { - output.CopyFrom(_headerBytes, 95, 11); - output.CopyFromAscii(value); + if (value != null) + { + output.CopyFrom(_headerBytes, 95, 11); + output.CopyFromAscii(value); + } } - } } if (((_bits & 256L) != 0)) { - foreach(var value in _Via) - { - if (value != null) + foreach (var value in _Via) { - output.CopyFrom(_headerBytes, 106, 7); - output.CopyFromAscii(value); + if (value != null) + { + output.CopyFrom(_headerBytes, 106, 7); + output.CopyFromAscii(value); + } } - } } if (((_bits & 512L) != 0)) { - foreach(var value in _Warning) - { - if (value != null) + foreach (var value in _Warning) { - output.CopyFrom(_headerBytes, 113, 11); - output.CopyFromAscii(value); + if (value != null) + { + output.CopyFrom(_headerBytes, 113, 11); + output.CopyFromAscii(value); + } } - } } if (((_bits & 1024L) != 0)) { - foreach(var value in _Allow) - { - if (value != null) + foreach (var value in _Allow) { - output.CopyFrom(_headerBytes, 124, 9); - output.CopyFromAscii(value); + if (value != null) + { + output.CopyFrom(_headerBytes, 124, 9); + output.CopyFromAscii(value); + } } - } } if (((_bits & 2048L) != 0)) @@ -8177,183 +8186,184 @@ namespace Microsoft.AspNet.Server.Kestrel.Http if (_rawContentLength != null) { output.CopyFrom(_rawContentLength, 0, _rawContentLength.Length); - } else - foreach(var value in _ContentLength) - { - if (value != null) + } + else + foreach (var value in _ContentLength) { - output.CopyFrom(_headerBytes, 133, 18); - output.CopyFromAscii(value); + if (value != null) + { + output.CopyFrom(_headerBytes, 133, 18); + output.CopyFromAscii(value); + } } - } } if (((_bits & 4096L) != 0)) { - foreach(var value in _ContentType) - { - if (value != null) + foreach (var value in _ContentType) { - output.CopyFrom(_headerBytes, 151, 16); - output.CopyFromAscii(value); + if (value != null) + { + output.CopyFrom(_headerBytes, 151, 16); + output.CopyFromAscii(value); + } } - } } if (((_bits & 8192L) != 0)) { - foreach(var value in _ContentEncoding) - { - if (value != null) + foreach (var value in _ContentEncoding) { - output.CopyFrom(_headerBytes, 167, 20); - output.CopyFromAscii(value); + if (value != null) + { + output.CopyFrom(_headerBytes, 167, 20); + output.CopyFromAscii(value); + } } - } } if (((_bits & 16384L) != 0)) { - foreach(var value in _ContentLanguage) - { - if (value != null) + foreach (var value in _ContentLanguage) { - output.CopyFrom(_headerBytes, 187, 20); - output.CopyFromAscii(value); + if (value != null) + { + output.CopyFrom(_headerBytes, 187, 20); + output.CopyFromAscii(value); + } } - } } if (((_bits & 32768L) != 0)) { - foreach(var value in _ContentLocation) - { - if (value != null) + foreach (var value in _ContentLocation) { - output.CopyFrom(_headerBytes, 207, 20); - output.CopyFromAscii(value); + if (value != null) + { + output.CopyFrom(_headerBytes, 207, 20); + output.CopyFromAscii(value); + } } - } } if (((_bits & 65536L) != 0)) { - foreach(var value in _ContentMD5) - { - if (value != null) + foreach (var value in _ContentMD5) { - output.CopyFrom(_headerBytes, 227, 15); - output.CopyFromAscii(value); + if (value != null) + { + output.CopyFrom(_headerBytes, 227, 15); + output.CopyFromAscii(value); + } } - } } if (((_bits & 131072L) != 0)) { - foreach(var value in _ContentRange) - { - if (value != null) + foreach (var value in _ContentRange) { - output.CopyFrom(_headerBytes, 242, 17); - output.CopyFromAscii(value); + if (value != null) + { + output.CopyFrom(_headerBytes, 242, 17); + output.CopyFromAscii(value); + } } - } } if (((_bits & 262144L) != 0)) { - foreach(var value in _Expires) - { - if (value != null) + foreach (var value in _Expires) { - output.CopyFrom(_headerBytes, 259, 11); - output.CopyFromAscii(value); + if (value != null) + { + output.CopyFrom(_headerBytes, 259, 11); + output.CopyFromAscii(value); + } } - } } if (((_bits & 524288L) != 0)) { - foreach(var value in _LastModified) - { - if (value != null) + foreach (var value in _LastModified) { - output.CopyFrom(_headerBytes, 270, 17); - output.CopyFromAscii(value); + if (value != null) + { + output.CopyFrom(_headerBytes, 270, 17); + output.CopyFromAscii(value); + } } - } } if (((_bits & 1048576L) != 0)) { - foreach(var value in _AcceptRanges) - { - if (value != null) + foreach (var value in _AcceptRanges) { - output.CopyFrom(_headerBytes, 287, 17); - output.CopyFromAscii(value); + if (value != null) + { + output.CopyFrom(_headerBytes, 287, 17); + output.CopyFromAscii(value); + } } - } } if (((_bits & 2097152L) != 0)) { - foreach(var value in _Age) - { - if (value != null) + foreach (var value in _Age) { - output.CopyFrom(_headerBytes, 304, 7); - output.CopyFromAscii(value); + if (value != null) + { + output.CopyFrom(_headerBytes, 304, 7); + output.CopyFromAscii(value); + } } - } } if (((_bits & 4194304L) != 0)) { - foreach(var value in _ETag) - { - if (value != null) + foreach (var value in _ETag) { - output.CopyFrom(_headerBytes, 311, 8); - output.CopyFromAscii(value); + if (value != null) + { + output.CopyFrom(_headerBytes, 311, 8); + output.CopyFromAscii(value); + } } - } } if (((_bits & 8388608L) != 0)) { - foreach(var value in _Location) - { - if (value != null) + foreach (var value in _Location) { - output.CopyFrom(_headerBytes, 319, 12); - output.CopyFromAscii(value); + if (value != null) + { + output.CopyFrom(_headerBytes, 319, 12); + output.CopyFromAscii(value); + } } - } } if (((_bits & 16777216L) != 0)) { - foreach(var value in _ProxyAutheticate) - { - if (value != null) + foreach (var value in _ProxyAutheticate) { - output.CopyFrom(_headerBytes, 331, 21); - output.CopyFromAscii(value); + if (value != null) + { + output.CopyFrom(_headerBytes, 331, 21); + output.CopyFromAscii(value); + } } - } } if (((_bits & 33554432L) != 0)) { - foreach(var value in _RetryAfter) - { - if (value != null) + foreach (var value in _RetryAfter) { - output.CopyFrom(_headerBytes, 352, 15); - output.CopyFromAscii(value); + if (value != null) + { + output.CopyFrom(_headerBytes, 352, 15); + output.CopyFromAscii(value); + } } - } } if (((_bits & 67108864L) != 0)) @@ -8361,536 +8371,543 @@ namespace Microsoft.AspNet.Server.Kestrel.Http if (_rawServer != null) { output.CopyFrom(_rawServer, 0, _rawServer.Length); - } else - foreach(var value in _Server) - { - if (value != null) + } + else + foreach (var value in _Server) { - output.CopyFrom(_headerBytes, 367, 10); - output.CopyFromAscii(value); + if (value != null) + { + output.CopyFrom(_headerBytes, 367, 10); + output.CopyFromAscii(value); + } } - } } if (((_bits & 134217728L) != 0)) { - foreach(var value in _SetCookie) - { - if (value != null) + foreach (var value in _SetCookie) { - output.CopyFrom(_headerBytes, 377, 14); - output.CopyFromAscii(value); + if (value != null) + { + output.CopyFrom(_headerBytes, 377, 14); + output.CopyFromAscii(value); + } } - } } if (((_bits & 268435456L) != 0)) { - foreach(var value in _Vary) - { - if (value != null) + foreach (var value in _Vary) { - output.CopyFrom(_headerBytes, 391, 8); - output.CopyFromAscii(value); + if (value != null) + { + output.CopyFrom(_headerBytes, 391, 8); + output.CopyFromAscii(value); + } } - } } if (((_bits & 536870912L) != 0)) { - foreach(var value in _WWWAuthenticate) - { - if (value != null) + foreach (var value in _WWWAuthenticate) { - output.CopyFrom(_headerBytes, 399, 20); - output.CopyFromAscii(value); + if (value != null) + { + output.CopyFrom(_headerBytes, 399, 20); + output.CopyFromAscii(value); + } } - } } } public unsafe void Append(byte[] keyBytes, int keyOffset, int keyLength, string value) { - fixed(byte* ptr = keyBytes) { var pUB = ptr + keyOffset; var pUL = (ulong*)pUB; var pUI = (uint*)pUB; var pUS = (ushort*)pUB; - switch(keyLength) - { - case 13: - { - if ((((pUL[0] & 16131893727263186911uL) == 5711458528024281411uL) && ((pUI[2] & 3755991007u) == 1330795598u) && ((pUB[12] & 223u) == 76u))) + fixed (byte* ptr = &keyBytes[keyOffset]) + { + var pUB = ptr; + var pUL = (ulong*)pUB; + var pUI = (uint*)pUB; + var pUS = (ushort*)pUB; + switch (keyLength) + { + case 13: { - if (((_bits & 1L) != 0)) + if ((((pUL[0] & 16131893727263186911uL) == 5711458528024281411uL) && ((pUI[2] & 3755991007u) == 1330795598u) && ((pUB[12] & 223u) == 76u))) { - _CacheControl = AppendValue(_CacheControl, value); + if (((_bits & 1L) != 0)) + { + _CacheControl = AppendValue(_CacheControl, value); + } + else + { + _bits |= 1L; + _CacheControl = new StringValues(value); + } + return; } - else + + if ((((pUL[0] & 18437701552104792031uL) == 3266321689424580419uL) && ((pUI[2] & 3755991007u) == 1196310866u) && ((pUB[12] & 223u) == 69u))) { - _bits |= 1L; - _CacheControl = new StringValues(value); + if (((_bits & 131072L) != 0)) + { + _ContentRange = AppendValue(_ContentRange, value); + } + else + { + _bits |= 131072L; + _ContentRange = new StringValues(value); + } + return; + } + + if ((((pUL[0] & 16131858680330051551uL) == 4922237774822850892uL) && ((pUI[2] & 3755991007u) == 1162430025u) && ((pUB[12] & 223u) == 68u))) + { + if (((_bits & 524288L) != 0)) + { + _LastModified = AppendValue(_LastModified, value); + } + else + { + _bits |= 524288L; + _LastModified = new StringValues(value); + } + return; + } + + if ((((pUL[0] & 16140865742145839071uL) == 5921481788798223169uL) && ((pUI[2] & 3755991007u) == 1162300993u) && ((pUB[12] & 223u) == 83u))) + { + if (((_bits & 1048576L) != 0)) + { + _AcceptRanges = AppendValue(_AcceptRanges, value); + } + else + { + _bits |= 1048576L; + _AcceptRanges = new StringValues(value); + } + return; } - return; } - - if ((((pUL[0] & 18437701552104792031uL) == 3266321689424580419uL) && ((pUI[2] & 3755991007u) == 1196310866u) && ((pUB[12] & 223u) == 69u))) + break; + + case 10: { - if (((_bits & 131072L) != 0)) + if ((((pUL[0] & 16131858542891098079uL) == 5283922227757993795uL) && ((pUS[4] & 57311u) == 20047u))) { - _ContentRange = AppendValue(_ContentRange, value); + if (((_bits & 2L) != 0)) + { + _Connection = AppendValue(_Connection, value); + } + else + { + _bits |= 2L; + _Connection = new StringValues(value); + _rawConnection = null; + } + return; } - else + + if ((((pUL[0] & 16131858680330051551uL) == 5281668125874799947uL) && ((pUS[4] & 57311u) == 17750u))) { - _bits |= 131072L; - _ContentRange = new StringValues(value); + if (((_bits & 8L) != 0)) + { + _KeepAlive = AppendValue(_KeepAlive, value); + } + else + { + _bits |= 8L; + _KeepAlive = new StringValues(value); + } + return; + } + + if ((((pUL[0] & 16131858543427968991uL) == 5426643225946637651uL) && ((pUS[4] & 57311u) == 17737u))) + { + if (((_bits & 134217728L) != 0)) + { + _SetCookie = AppendValue(_SetCookie, value); + } + else + { + _bits |= 134217728L; + _SetCookie = new StringValues(value); + } + return; } - return; } - - if ((((pUL[0] & 16131858680330051551uL) == 4922237774822850892uL) && ((pUI[2] & 3755991007u) == 1162430025u) && ((pUB[12] & 223u) == 68u))) + break; + + case 4: { - if (((_bits & 524288L) != 0)) + if ((((pUI[0] & 3755991007u) == 1163149636u))) { - _LastModified = AppendValue(_LastModified, value); + if (((_bits & 4L) != 0)) + { + _Date = AppendValue(_Date, value); + } + else + { + _bits |= 4L; + _Date = new StringValues(value); + _rawDate = null; + } + return; } - else + + if ((((pUI[0] & 3755991007u) == 1195463749u))) { - _bits |= 524288L; - _LastModified = new StringValues(value); + if (((_bits & 4194304L) != 0)) + { + _ETag = AppendValue(_ETag, value); + } + else + { + _bits |= 4194304L; + _ETag = new StringValues(value); + } + return; + } + + if ((((pUI[0] & 3755991007u) == 1498562902u))) + { + if (((_bits & 268435456L) != 0)) + { + _Vary = AppendValue(_Vary, value); + } + else + { + _bits |= 268435456L; + _Vary = new StringValues(value); + } + return; } - return; } - - if ((((pUL[0] & 16140865742145839071uL) == 5921481788798223169uL) && ((pUI[2] & 3755991007u) == 1162300993u) && ((pUB[12] & 223u) == 83u))) + break; + + case 6: { - if (((_bits & 1048576L) != 0)) + if ((((pUI[0] & 3755991007u) == 1195463248u) && ((pUS[2] & 57311u) == 16717u))) { - _AcceptRanges = AppendValue(_AcceptRanges, value); + if (((_bits & 16L) != 0)) + { + _Pragma = AppendValue(_Pragma, value); + } + else + { + _bits |= 16L; + _Pragma = new StringValues(value); + } + return; } - else + + if ((((pUI[0] & 3755991007u) == 1448232275u) && ((pUS[2] & 57311u) == 21061u))) { - _bits |= 1048576L; - _AcceptRanges = new StringValues(value); + if (((_bits & 67108864L) != 0)) + { + _Server = AppendValue(_Server, value); + } + else + { + _bits |= 67108864L; + _Server = new StringValues(value); + _rawServer = null; + } + return; } - return; } - } - break; - - case 10: - { - if ((((pUL[0] & 16131858542891098079uL) == 5283922227757993795uL) && ((pUS[4] & 57311u) == 20047u))) + break; + + case 7: { - if (((_bits & 2L) != 0)) + if ((((pUI[0] & 3755991007u) == 1229017684u) && ((pUS[2] & 57311u) == 17740u) && ((pUB[6] & 223u) == 82u))) { - _Connection = AppendValue(_Connection, value); + if (((_bits & 32L) != 0)) + { + _Trailer = AppendValue(_Trailer, value); + } + else + { + _bits |= 32L; + _Trailer = new StringValues(value); + } + return; } - else + + if ((((pUI[0] & 3755991007u) == 1380405333u) && ((pUS[2] & 57311u) == 17473u) && ((pUB[6] & 223u) == 69u))) { - _bits |= 2L; - _Connection = new StringValues(value); - _rawConnection = null; + if (((_bits & 128L) != 0)) + { + _Upgrade = AppendValue(_Upgrade, value); + } + else + { + _bits |= 128L; + _Upgrade = new StringValues(value); + } + return; + } + + if ((((pUI[0] & 3755991007u) == 1314013527u) && ((pUS[2] & 57311u) == 20041u) && ((pUB[6] & 223u) == 71u))) + { + if (((_bits & 512L) != 0)) + { + _Warning = AppendValue(_Warning, value); + } + else + { + _bits |= 512L; + _Warning = new StringValues(value); + } + return; + } + + if ((((pUI[0] & 3755991007u) == 1230002245u) && ((pUS[2] & 57311u) == 17746u) && ((pUB[6] & 223u) == 83u))) + { + if (((_bits & 262144L) != 0)) + { + _Expires = AppendValue(_Expires, value); + } + else + { + _bits |= 262144L; + _Expires = new StringValues(value); + } + return; } - return; } - - if ((((pUL[0] & 16131858680330051551uL) == 5281668125874799947uL) && ((pUS[4] & 57311u) == 17750u))) + break; + + case 17: { - if (((_bits & 8L) != 0)) + if ((((pUL[0] & 16131858542891098079uL) == 5928221808112259668uL) && ((pUL[1] & 16131858542891098111uL) == 5641115115480565037uL) && ((pUB[16] & 223u) == 71u))) { - _KeepAlive = AppendValue(_KeepAlive, value); + if (((_bits & 64L) != 0)) + { + _TransferEncoding = AppendValue(_TransferEncoding, value); + } + else + { + _bits |= 64L; + _TransferEncoding = new StringValues(value); + _rawTransferEncoding = null; + } + return; } - else + + if ((((pUL[0] & 16131893727263186911uL) == 6143241228466999888uL) && ((pUL[1] & 16131858542891098079uL) == 6071207754897639508uL) && ((pUB[16] & 223u) == 69u))) { - _bits |= 8L; - _KeepAlive = new StringValues(value); + if (((_bits & 16777216L) != 0)) + { + _ProxyAutheticate = AppendValue(_ProxyAutheticate, value); + } + else + { + _bits |= 16777216L; + _ProxyAutheticate = new StringValues(value); + } + return; } - return; } - - if ((((pUL[0] & 16131858543427968991uL) == 5426643225946637651uL) && ((pUS[4] & 57311u) == 17737u))) + break; + + case 3: { - if (((_bits & 134217728L) != 0)) + if ((((pUS[0] & 57311u) == 18774u) && ((pUB[2] & 223u) == 65u))) { - _SetCookie = AppendValue(_SetCookie, value); + if (((_bits & 256L) != 0)) + { + _Via = AppendValue(_Via, value); + } + else + { + _bits |= 256L; + _Via = new StringValues(value); + } + return; } - else + + if ((((pUS[0] & 57311u) == 18241u) && ((pUB[2] & 223u) == 69u))) { - _bits |= 134217728L; - _SetCookie = new StringValues(value); + if (((_bits & 2097152L) != 0)) + { + _Age = AppendValue(_Age, value); + } + else + { + _bits |= 2097152L; + _Age = new StringValues(value); + } + return; } - return; } - } - break; - - case 4: - { - if ((((pUI[0] & 3755991007u) == 1163149636u))) + break; + + case 5: { - if (((_bits & 4L) != 0)) + if ((((pUI[0] & 3755991007u) == 1330400321u) && ((pUB[4] & 223u) == 87u))) { - _Date = AppendValue(_Date, value); + if (((_bits & 1024L) != 0)) + { + _Allow = AppendValue(_Allow, value); + } + else + { + _bits |= 1024L; + _Allow = new StringValues(value); + } + return; } - else - { - _bits |= 4L; - _Date = new StringValues(value); - _rawDate = null; - } - return; } - - if ((((pUI[0] & 3755991007u) == 1195463749u))) + break; + + case 14: { - if (((_bits & 4194304L) != 0)) + if ((((pUL[0] & 18437701552104792031uL) == 3266321689424580419uL) && ((pUI[2] & 3755991007u) == 1196311884u) && ((pUS[6] & 57311u) == 18516u))) { - _ETag = AppendValue(_ETag, value); + if (((_bits & 2048L) != 0)) + { + _ContentLength = AppendValue(_ContentLength, value); + } + else + { + _bits |= 2048L; + _ContentLength = new StringValues(value); + _rawContentLength = null; + } + return; } - else - { - _bits |= 4194304L; - _ETag = new StringValues(value); - } - return; } - - if ((((pUI[0] & 3755991007u) == 1498562902u))) + break; + + case 12: { - if (((_bits & 268435456L) != 0)) + if ((((pUL[0] & 18437701552104792031uL) == 3266321689424580419uL) && ((pUI[2] & 3755991007u) == 1162893652u))) { - _Vary = AppendValue(_Vary, value); + if (((_bits & 4096L) != 0)) + { + _ContentType = AppendValue(_ContentType, value); + } + else + { + _bits |= 4096L; + _ContentType = new StringValues(value); + } + return; } - else - { - _bits |= 268435456L; - _Vary = new StringValues(value); - } - return; } - } - break; - - case 6: - { - if ((((pUI[0] & 3755991007u) == 1195463248u) && ((pUS[2] & 57311u) == 16717u))) + break; + + case 16: { - if (((_bits & 16L) != 0)) + if ((((pUL[0] & 18437701552104792031uL) == 3266321689424580419uL) && ((pUL[1] & 16131858542891098079uL) == 5138124782612729413uL))) { - _Pragma = AppendValue(_Pragma, value); + if (((_bits & 8192L) != 0)) + { + _ContentEncoding = AppendValue(_ContentEncoding, value); + } + else + { + _bits |= 8192L; + _ContentEncoding = new StringValues(value); + } + return; } - else + + if ((((pUL[0] & 18437701552104792031uL) == 3266321689424580419uL) && ((pUL[1] & 16131858542891098079uL) == 4992030546487820620uL))) { - _bits |= 16L; - _Pragma = new StringValues(value); + if (((_bits & 16384L) != 0)) + { + _ContentLanguage = AppendValue(_ContentLanguage, value); + } + else + { + _bits |= 16384L; + _ContentLanguage = new StringValues(value); + } + return; + } + + if ((((pUL[0] & 18437701552104792031uL) == 3266321689424580419uL) && ((pUL[1] & 16131858542891098079uL) == 5642809484339531596uL))) + { + if (((_bits & 32768L) != 0)) + { + _ContentLocation = AppendValue(_ContentLocation, value); + } + else + { + _bits |= 32768L; + _ContentLocation = new StringValues(value); + } + return; + } + + if ((((pUL[0] & 16131858543427968991uL) == 5211884407196440407uL) && ((pUL[1] & 16131858542891098079uL) == 4995689643909598789uL))) + { + if (((_bits & 536870912L) != 0)) + { + _WWWAuthenticate = AppendValue(_WWWAuthenticate, value); + } + else + { + _bits |= 536870912L; + _WWWAuthenticate = new StringValues(value); + } + return; } - return; } - - if ((((pUI[0] & 3755991007u) == 1448232275u) && ((pUS[2] & 57311u) == 21061u))) + break; + + case 11: { - if (((_bits & 67108864L) != 0)) + if ((((pUL[0] & 18437701552104792031uL) == 3266321689424580419uL) && ((pUS[4] & 57311u) == 17485u) && ((pUB[10] & 255u) == 53u))) { - _Server = AppendValue(_Server, value); + if (((_bits & 65536L) != 0)) + { + _ContentMD5 = AppendValue(_ContentMD5, value); + } + else + { + _bits |= 65536L; + _ContentMD5 = new StringValues(value); + } + return; } - else + + if ((((pUL[0] & 16131893727263186911uL) == 5062377317797741906uL) && ((pUS[4] & 57311u) == 17748u) && ((pUB[10] & 223u) == 82u))) { - _bits |= 67108864L; - _Server = new StringValues(value); - _rawServer = null; + if (((_bits & 33554432L) != 0)) + { + _RetryAfter = AppendValue(_RetryAfter, value); + } + else + { + _bits |= 33554432L; + _RetryAfter = new StringValues(value); + } + return; } - return; } - } - break; - - case 7: - { - if ((((pUI[0] & 3755991007u) == 1229017684u) && ((pUS[2] & 57311u) == 17740u) && ((pUB[6] & 223u) == 82u))) + break; + + case 8: { - if (((_bits & 32L) != 0)) + if ((((pUL[0] & 16131858542891098079uL) == 5642809484339531596uL))) { - _Trailer = AppendValue(_Trailer, value); + if (((_bits & 8388608L) != 0)) + { + _Location = AppendValue(_Location, value); + } + else + { + _bits |= 8388608L; + _Location = new StringValues(value); + } + return; } - else - { - _bits |= 32L; - _Trailer = new StringValues(value); - } - return; } - - if ((((pUI[0] & 3755991007u) == 1380405333u) && ((pUS[2] & 57311u) == 17473u) && ((pUB[6] & 223u) == 69u))) - { - if (((_bits & 128L) != 0)) - { - _Upgrade = AppendValue(_Upgrade, value); - } - else - { - _bits |= 128L; - _Upgrade = new StringValues(value); - } - return; - } - - if ((((pUI[0] & 3755991007u) == 1314013527u) && ((pUS[2] & 57311u) == 20041u) && ((pUB[6] & 223u) == 71u))) - { - if (((_bits & 512L) != 0)) - { - _Warning = AppendValue(_Warning, value); - } - else - { - _bits |= 512L; - _Warning = new StringValues(value); - } - return; - } - - if ((((pUI[0] & 3755991007u) == 1230002245u) && ((pUS[2] & 57311u) == 17746u) && ((pUB[6] & 223u) == 83u))) - { - if (((_bits & 262144L) != 0)) - { - _Expires = AppendValue(_Expires, value); - } - else - { - _bits |= 262144L; - _Expires = new StringValues(value); - } - return; - } - } - break; - - case 17: - { - if ((((pUL[0] & 16131858542891098079uL) == 5928221808112259668uL) && ((pUL[1] & 16131858542891098111uL) == 5641115115480565037uL) && ((pUB[16] & 223u) == 71u))) - { - if (((_bits & 64L) != 0)) - { - _TransferEncoding = AppendValue(_TransferEncoding, value); - } - else - { - _bits |= 64L; - _TransferEncoding = new StringValues(value); - _rawTransferEncoding = null; - } - return; - } - - if ((((pUL[0] & 16131893727263186911uL) == 6143241228466999888uL) && ((pUL[1] & 16131858542891098079uL) == 6071207754897639508uL) && ((pUB[16] & 223u) == 69u))) - { - if (((_bits & 16777216L) != 0)) - { - _ProxyAutheticate = AppendValue(_ProxyAutheticate, value); - } - else - { - _bits |= 16777216L; - _ProxyAutheticate = new StringValues(value); - } - return; - } - } - break; - - case 3: - { - if ((((pUS[0] & 57311u) == 18774u) && ((pUB[2] & 223u) == 65u))) - { - if (((_bits & 256L) != 0)) - { - _Via = AppendValue(_Via, value); - } - else - { - _bits |= 256L; - _Via = new StringValues(value); - } - return; - } - - if ((((pUS[0] & 57311u) == 18241u) && ((pUB[2] & 223u) == 69u))) - { - if (((_bits & 2097152L) != 0)) - { - _Age = AppendValue(_Age, value); - } - else - { - _bits |= 2097152L; - _Age = new StringValues(value); - } - return; - } - } - break; - - case 5: - { - if ((((pUI[0] & 3755991007u) == 1330400321u) && ((pUB[4] & 223u) == 87u))) - { - if (((_bits & 1024L) != 0)) - { - _Allow = AppendValue(_Allow, value); - } - else - { - _bits |= 1024L; - _Allow = new StringValues(value); - } - return; - } - } - break; - - case 14: - { - if ((((pUL[0] & 18437701552104792031uL) == 3266321689424580419uL) && ((pUI[2] & 3755991007u) == 1196311884u) && ((pUS[6] & 57311u) == 18516u))) - { - if (((_bits & 2048L) != 0)) - { - _ContentLength = AppendValue(_ContentLength, value); - } - else - { - _bits |= 2048L; - _ContentLength = new StringValues(value); - _rawContentLength = null; - } - return; - } - } - break; - - case 12: - { - if ((((pUL[0] & 18437701552104792031uL) == 3266321689424580419uL) && ((pUI[2] & 3755991007u) == 1162893652u))) - { - if (((_bits & 4096L) != 0)) - { - _ContentType = AppendValue(_ContentType, value); - } - else - { - _bits |= 4096L; - _ContentType = new StringValues(value); - } - return; - } - } - break; - - case 16: - { - if ((((pUL[0] & 18437701552104792031uL) == 3266321689424580419uL) && ((pUL[1] & 16131858542891098079uL) == 5138124782612729413uL))) - { - if (((_bits & 8192L) != 0)) - { - _ContentEncoding = AppendValue(_ContentEncoding, value); - } - else - { - _bits |= 8192L; - _ContentEncoding = new StringValues(value); - } - return; - } - - if ((((pUL[0] & 18437701552104792031uL) == 3266321689424580419uL) && ((pUL[1] & 16131858542891098079uL) == 4992030546487820620uL))) - { - if (((_bits & 16384L) != 0)) - { - _ContentLanguage = AppendValue(_ContentLanguage, value); - } - else - { - _bits |= 16384L; - _ContentLanguage = new StringValues(value); - } - return; - } - - if ((((pUL[0] & 18437701552104792031uL) == 3266321689424580419uL) && ((pUL[1] & 16131858542891098079uL) == 5642809484339531596uL))) - { - if (((_bits & 32768L) != 0)) - { - _ContentLocation = AppendValue(_ContentLocation, value); - } - else - { - _bits |= 32768L; - _ContentLocation = new StringValues(value); - } - return; - } - - if ((((pUL[0] & 16131858543427968991uL) == 5211884407196440407uL) && ((pUL[1] & 16131858542891098079uL) == 4995689643909598789uL))) - { - if (((_bits & 536870912L) != 0)) - { - _WWWAuthenticate = AppendValue(_WWWAuthenticate, value); - } - else - { - _bits |= 536870912L; - _WWWAuthenticate = new StringValues(value); - } - return; - } - } - break; - - case 11: - { - if ((((pUL[0] & 18437701552104792031uL) == 3266321689424580419uL) && ((pUS[4] & 57311u) == 17485u) && ((pUB[10] & 255u) == 53u))) - { - if (((_bits & 65536L) != 0)) - { - _ContentMD5 = AppendValue(_ContentMD5, value); - } - else - { - _bits |= 65536L; - _ContentMD5 = new StringValues(value); - } - return; - } - - if ((((pUL[0] & 16131893727263186911uL) == 5062377317797741906uL) && ((pUS[4] & 57311u) == 17748u) && ((pUB[10] & 223u) == 82u))) - { - if (((_bits & 33554432L) != 0)) - { - _RetryAfter = AppendValue(_RetryAfter, value); - } - else - { - _bits |= 33554432L; - _RetryAfter = new StringValues(value); - } - return; - } - } - break; - - case 8: - { - if ((((pUL[0] & 16131858542891098079uL) == 5642809484339531596uL))) - { - if (((_bits & 8388608L) != 0)) - { - _Location = AppendValue(_Location, value); - } - else - { - _bits |= 8388608L; - _Location = new StringValues(value); - } - return; - } - } - break; - }} + break; + } + } var key = System.Text.Encoding.ASCII.GetString(keyBytes, keyOffset, keyLength); StringValues existing; Unknown.TryGetValue(key, out existing); diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolIterator2.cs b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolIterator2.cs index 08c4a75a35..01541d9ca8 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolIterator2.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolIterator2.cs @@ -133,9 +133,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure } else if (_block.End - _index >= sizeof(long)) { - fixed (byte* ptr = _block.Array) + fixed (byte* ptr = &_block.Array[_index]) { - return *(long*)(ptr + _index); + return *(long*)(ptr); } } else if (_block.Next == null) @@ -153,15 +153,15 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure } long blockLong; - fixed (byte* ptr = _block.Array) + fixed (byte* ptr = &_block.Array[_block.End - sizeof(long)]) { - blockLong = *(long*)(ptr + _block.End - sizeof(long)); + blockLong = *(long*)(ptr); } long nextLong; - fixed (byte* ptr = _block.Next.Array) + fixed (byte* ptr = &_block.Next.Array[_block.Next.Start]) { - nextLong = *(long*)(ptr + _block.Next.Start); + nextLong = *(long*)(ptr ); } return (blockLong >> (sizeof(long) - blockBytes) * 8) | (nextLong << (sizeof(long) - nextBytes) * 8); @@ -667,9 +667,10 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure bytesLeftInBlockMinusSpan = bytesLeftInBlock - 3; } - fixed (byte* pOutput = block.Data.Array) + fixed (byte* pOutput = &block.Data.Array[block.End]) { - var output = pOutput + block.End; + //this line is needed to allow output be an register var + var output = pOutput; var copied = 0; for (; input < inputEndMinusSpan && copied < bytesLeftInBlockMinusSpan; copied += 4) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolIterator2Extensions.cs b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolIterator2Extensions.cs index 1fbd76c5a8..b4ca656adf 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolIterator2Extensions.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolIterator2Extensions.cs @@ -63,7 +63,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure var bytes = Encoding.ASCII.GetBytes(str); - fixed (byte* ptr = bytes) + fixed (byte* ptr = &bytes[0]) { return *(long*)ptr; } diff --git a/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/KnownHeaders.cs b/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/KnownHeaders.cs index df3cef0284..913fb320f4 100644 --- a/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/KnownHeaders.cs +++ b/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/KnownHeaders.cs @@ -239,7 +239,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http }} protected override StringValues GetValueFast(string key) {{ - switch(key.Length) + switch (key.Length) {{{Each(loop.HeadersByLength, byLength => $@" case {byLength.Key}: {{{Each(byLength, header => $@" @@ -265,7 +265,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http }} protected override bool TryGetValueFast(string key, out StringValues value) {{ - switch(key.Length) + switch (key.Length) {{{Each(loop.HeadersByLength, byLength => $@" case {byLength.Key}: {{{Each(byLength, header => $@" @@ -290,7 +290,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http }} protected override void SetValueFast(string key, StringValues value) {{ - switch(key.Length) + switch (key.Length) {{{Each(loop.HeadersByLength, byLength => $@" case {byLength.Key}: {{{Each(byLength, header => $@" @@ -308,7 +308,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http }} protected override void AddValueFast(string key, StringValues value) {{ - switch(key.Length) + switch (key.Length) {{{Each(loop.HeadersByLength, byLength => $@" case {byLength.Key}: {{{Each(byLength, header => $@" @@ -330,7 +330,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http }} protected override bool RemoveFast(string key) {{ - switch(key.Length) + switch (key.Length) {{{Each(loop.HeadersByLength, byLength => $@" case {byLength.Key}: {{{Each(byLength, header => $@" @@ -388,42 +388,49 @@ namespace Microsoft.AspNet.Server.Kestrel.Http if (_raw{header.Identifier} != null) {{ output.CopyFrom(_raw{header.Identifier}, 0, _raw{header.Identifier}.Length); - }} else ")} - foreach(var value in _{header.Identifier}) - {{ - if (value != null) + }} + else ")} + foreach (var value in _{header.Identifier}) {{ - output.CopyFrom(_headerBytes, {header.BytesOffset}, {header.BytesCount}); - output.CopyFromAscii(value); + if (value != null) + {{ + output.CopyFrom(_headerBytes, {header.BytesOffset}, {header.BytesCount}); + output.CopyFromAscii(value); + }} }} - }} }} ")} }}" : "")} public unsafe void Append(byte[] keyBytes, int keyOffset, int keyLength, string value) {{ - fixed(byte* ptr = keyBytes) {{ var pUB = ptr + keyOffset; var pUL = (ulong*)pUB; var pUI = (uint*)pUB; var pUS = (ushort*)pUB; - switch(keyLength) - {{{Each(loop.HeadersByLength, byLength => $@" - case {byLength.Key}: - {{{Each(byLength, header => $@" - if ({header.EqualIgnoreCaseBytes()}) - {{ - if ({header.TestBit()}) + fixed (byte* ptr = &keyBytes[keyOffset]) + {{ + var pUB = ptr; + var pUL = (ulong*)pUB; + var pUI = (uint*)pUB; + var pUS = (ushort*)pUB; + switch (keyLength) + {{{Each(loop.HeadersByLength, byLength => $@" + case {byLength.Key}: + {{{Each(byLength, header => $@" + if ({header.EqualIgnoreCaseBytes()}) {{ - _{header.Identifier} = AppendValue(_{header.Identifier}, value); + if ({header.TestBit()}) + {{ + _{header.Identifier} = AppendValue(_{header.Identifier}, value); + }} + else + {{ + {header.SetBit()}; + _{header.Identifier} = new StringValues(value);{(header.EnhancedSetter == false ? "" : $@" + _raw{header.Identifier} = null;")} + }} + return; }} - else - {{ - {header.SetBit()}; - _{header.Identifier} = new StringValues(value);{(header.EnhancedSetter == false ? "" : $@" - _raw{header.Identifier} = null;")} - }} - return; - }} - ")}}} - break; - ")}}}}} + ")}}} + break; + ")}}} + }} var key = System.Text.Encoding.ASCII.GetString(keyBytes, keyOffset, keyLength); StringValues existing; Unknown.TryGetValue(key, out existing); @@ -462,8 +469,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http }} }} }} -")}}} -"; +")}}}"; } public virtual void AfterCompile(AfterCompileContext context) { From 5c58d48272184128ed9f9d7f33d588ae58c8f7de Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Wed, 30 Dec 2015 12:51:31 +0000 Subject: [PATCH 0536/1662] Name KestrelThreads Helps with debugging, profiling --- .../Infrastructure/KestrelThread.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs index 4769d62d6e..bebacfff1a 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs @@ -55,6 +55,7 @@ namespace Microsoft.AspNet.Server.Kestrel _loop = new UvLoopHandle(_log); _post = new UvAsyncHandle(_log); _thread = new Thread(ThreadStart); + _thread.Name = "KestrelThread - libuv"; QueueCloseHandle = PostCloseHandle; } From f7ac457b40410edd688a180e46a5ec2da3502606 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Fri, 11 Dec 2015 06:42:06 +0000 Subject: [PATCH 0537/1662] Use ValueTask --- .../Filter/LibuvStream.cs | 28 +++++++++-- .../Http/FrameRequestStream.cs | 8 ++-- .../Http/MessageBody.cs | 47 ++++++++++++++----- .../Http/SocketInputExtensions.cs | 28 ++++++++++- .../project.json | 3 +- 5 files changed, 94 insertions(+), 20 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Filter/LibuvStream.cs b/src/Microsoft.AspNet.Server.Kestrel/Filter/LibuvStream.cs index b4e92b2d76..1e019c8381 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Filter/LibuvStream.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Filter/LibuvStream.cs @@ -11,9 +11,13 @@ namespace Microsoft.AspNet.Server.Kestrel.Filter { public class LibuvStream : Stream { + private readonly static Task _initialCachedTask = Task.FromResult(0); + private readonly SocketInput _input; private readonly ISocketOutput _output; + private Task _cachedTask = _initialCachedTask; + public LibuvStream(SocketInput input, ISocketOutput output) { _input = input; @@ -58,12 +62,30 @@ namespace Microsoft.AspNet.Server.Kestrel.Filter public override int Read(byte[] buffer, int offset, int count) { - return ReadAsync(new ArraySegment(buffer, offset, count)).GetAwaiter().GetResult(); + // ValueTask uses .GetAwaiter().GetResult() if necessary + // https://github.com/dotnet/corefx/blob/f9da3b4af08214764a51b2331f3595ffaf162abe/src/System.Threading.Tasks.Extensions/src/System/Threading/Tasks/ValueTask.cs#L156 + return ReadAsync(new ArraySegment(buffer, offset, count)).Result; } public override Task ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) { - return ReadAsync(new ArraySegment(buffer, offset, count)); + var task = ReadAsync(new ArraySegment(buffer, offset, count)); + + if (task.IsCompletedSuccessfully) + { + if (_cachedTask.Result != task.Result) + { + // Needs .AsTask to match Stream's Async method return types + _cachedTask = task.AsTask(); + } + } + else + { + // Needs .AsTask to match Stream's Async method return types + _cachedTask = task.AsTask(); + } + + return _cachedTask; } public override void Write(byte[] buffer, int offset, int count) @@ -99,7 +121,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Filter // No-op since writes are immediate. } - private Task ReadAsync(ArraySegment buffer) + private ValueTask ReadAsync(ArraySegment buffer) { return _input.ReadAsync(buffer.Array, buffer.Offset, buffer.Count); } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameRequestStream.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameRequestStream.cs index f9ff5a4197..ba0c2062f7 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameRequestStream.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameRequestStream.cs @@ -53,7 +53,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { ValidateState(); - return ReadAsync(buffer, offset, count).GetAwaiter().GetResult(); + // ValueTask uses .GetAwaiter().GetResult() if necessary + return ReadAsync(buffer, offset, count).Result; } #if NET451 @@ -80,7 +81,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http var tcs = new TaskCompletionSource(state); var task = _body.ReadAsync(new ArraySegment(buffer, offset, count), cancellationToken); - task.ContinueWith((task2, state2) => + task.AsTask().ContinueWith((task2, state2) => { var tcs2 = (TaskCompletionSource)state2; if (task2.IsCanceled) @@ -104,7 +105,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { ValidateState(); - return _body.ReadAsync(new ArraySegment(buffer, offset, count), cancellationToken); + // Needs .AsTask to match Stream's Async method return types + return _body.ReadAsync(new ArraySegment(buffer, offset, count), cancellationToken).AsTask(); } public override void Write(byte[] buffer, int offset, int count) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/MessageBody.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/MessageBody.cs index 8edd424a10..46b573758e 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/MessageBody.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/MessageBody.cs @@ -22,11 +22,10 @@ namespace Microsoft.AspNet.Server.Kestrel.Http public bool RequestKeepAlive { get; protected set; } - public Task ReadAsync(ArraySegment buffer, CancellationToken cancellationToken = default(CancellationToken)) + public ValueTask ReadAsync(ArraySegment buffer, CancellationToken cancellationToken = default(CancellationToken)) { - Task result = null; var send100Continue = 0; - result = ReadAsyncImplementation(buffer, cancellationToken); + var result = ReadAsyncImplementation(buffer, cancellationToken); if (!result.IsCompleted) { send100Continue = Interlocked.Exchange(ref _send100Continue, 0); @@ -40,7 +39,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http public async Task Consume(CancellationToken cancellationToken = default(CancellationToken)) { - Task result; + ValueTask result; var send100checked = false; do { @@ -56,7 +55,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http send100checked = true; } } - else if (result.GetAwaiter().GetResult() == 0) + // ValueTask uses .GetAwaiter().GetResult() if necessary + else if (result.Result == 0) { // Completed Task, end of stream return; @@ -69,7 +69,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } while (await result != 0); } - public abstract Task ReadAsyncImplementation(ArraySegment buffer, CancellationToken cancellationToken); + public abstract ValueTask ReadAsyncImplementation(ArraySegment buffer, CancellationToken cancellationToken); public static MessageBody For( string httpVersion, @@ -137,7 +137,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { } - public override Task ReadAsyncImplementation(ArraySegment buffer, CancellationToken cancellationToken) + public override ValueTask ReadAsyncImplementation(ArraySegment buffer, CancellationToken cancellationToken) { return _context.SocketInput.ReadAsync(buffer.Array, buffer.Offset, buffer.Array == null ? 8192 : buffer.Count); } @@ -156,7 +156,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http _inputLength = _contentLength; } - public override async Task ReadAsyncImplementation(ArraySegment buffer, CancellationToken cancellationToken) + public override ValueTask ReadAsyncImplementation(ArraySegment buffer, CancellationToken cancellationToken) { var input = _context.SocketInput; @@ -166,9 +166,29 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return 0; } - var actual = await _context.SocketInput.ReadAsync(buffer.Array, buffer.Offset, limit); - _inputLength -= actual; + var task = _context.SocketInput.ReadAsync(buffer.Array, buffer.Offset, limit); + if (task.IsCompleted) + { + // .GetAwaiter().GetResult() done by ValueTask if needed + var actual = task.Result; + _inputLength -= actual; + if (actual == 0) + { + throw new InvalidDataException("Unexpected end of request content"); + } + return actual; + } + else + { + return ReadAsyncAwaited(task.AsTask()); + } + } + + private async Task ReadAsyncAwaited(Task task) + { + var actual = await task; + _inputLength -= actual; if (actual == 0) { throw new InvalidDataException("Unexpected end of request content"); @@ -178,7 +198,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } - /// /// http://tools.ietf.org/html/rfc2616#section-3.6.1 /// @@ -193,8 +212,12 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { RequestKeepAlive = keepAlive; } + public override ValueTask ReadAsyncImplementation(ArraySegment buffer, CancellationToken cancellationToken) + { + return ReadAsyncAwaited(buffer, cancellationToken); + } - public override async Task ReadAsyncImplementation(ArraySegment buffer, CancellationToken cancellationToken) + private async Task ReadAsyncAwaited(ArraySegment buffer, CancellationToken cancellationToken) { var input = _context.SocketInput; diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketInputExtensions.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketInputExtensions.cs index c36d88155d..39cb3202a0 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketInputExtensions.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketInputExtensions.cs @@ -8,7 +8,33 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { public static class SocketInputExtensions { - public static async Task ReadAsync(this SocketInput input, byte[] buffer, int offset, int count) + public static ValueTask ReadAsync(this SocketInput input, byte[] buffer, int offset, int count) + { + while (true) + { + if (!input.IsCompleted) + { + return input.ReadAsyncAwaited(buffer, offset, count); + } + + var begin = input.ConsumingStart(); + + int actual; + var end = begin.CopyTo(buffer, offset, count, out actual); + input.ConsumingComplete(end, end); + + if (actual != 0) + { + return actual; + } + if (input.RemoteIntakeFin) + { + return 0; + } + } + } + + private static async Task ReadAsyncAwaited(this SocketInput input, byte[] buffer, int offset, int count) { while (true) { diff --git a/src/Microsoft.AspNet.Server.Kestrel/project.json b/src/Microsoft.AspNet.Server.Kestrel/project.json index c95d40a6dc..2e0caab7c0 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/project.json +++ b/src/Microsoft.AspNet.Server.Kestrel/project.json @@ -20,7 +20,8 @@ "Microsoft.AspNet.Internal.libuv-Windows": { "version": "1.0.0-*", "type": "build" - } + }, + "System.Threading.Tasks.Extensions": "4.0.0-*" }, "frameworks": { "dnx451": { }, From 6fbb9a0cfe4f93bb1a6270bfd996da88f226894c Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Wed, 23 Dec 2015 17:55:26 -0800 Subject: [PATCH 0538/1662] Cleanup: private embedded types and readonly where appropriate (#187). --- .../Http/FrameContext.cs | 2 -- .../Http/FrameRequestHeaders.cs | 6 +++--- .../Http/FrameResponseHeaders.cs | 10 +++++----- .../Http/Listener.cs | 1 - .../Http/ListenerPrimary.cs | 6 +++--- .../Http/MessageBody.cs | 8 ++++---- .../Http/SocketOutput.cs | 2 +- .../Infrastructure/KestrelThread.cs | 14 +++++++------- .../Infrastructure/KestrelTrace.cs | 18 +++++++++--------- .../MemoryPoolIterator2Extensions.cs | 4 ++-- .../Networking/Libuv.cs | 2 +- .../Networking/UvAsyncHandle.cs | 2 +- .../Networking/UvHandle.cs | 2 +- .../Networking/UvMemory.cs | 2 +- .../IPv6SupportedConditionAttribute.cs | 2 +- 15 files changed, 39 insertions(+), 42 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameContext.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameContext.cs index f18efc6658..ab43df6388 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameContext.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameContext.cs @@ -7,12 +7,10 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { public FrameContext() { - } public FrameContext(ConnectionContext context) : base(context) { - } public IFrameControl FrameControl { get; set; } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameRequestHeaders.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameRequestHeaders.cs index da9429ac79..731b449468 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameRequestHeaders.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameRequestHeaders.cs @@ -21,11 +21,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http public partial struct Enumerator : IEnumerator> { - private FrameRequestHeaders _collection; - private long _bits; + private readonly FrameRequestHeaders _collection; + private readonly long _bits; private int _state; private KeyValuePair _current; - private bool _hasUnknown; + private readonly bool _hasUnknown; private Dictionary.Enumerator _unknownEnumerator; internal Enumerator(FrameRequestHeaders collection) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameResponseHeaders.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameResponseHeaders.cs index a5a42e6a98..840d44ce8b 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameResponseHeaders.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameResponseHeaders.cs @@ -10,8 +10,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { public partial class FrameResponseHeaders : FrameHeaders { - private static byte[] _CrLf = new[] { (byte)'\r', (byte)'\n' }; - private static byte[] _colonSpace = new[] { (byte)':', (byte)' ' }; + private static readonly byte[] _CrLf = new[] { (byte)'\r', (byte)'\n' }; + private static readonly byte[] _colonSpace = new[] { (byte)':', (byte)' ' }; public bool HasConnection => HeaderConnection.Count != 0; @@ -53,11 +53,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http public partial struct Enumerator : IEnumerator> { - private FrameResponseHeaders _collection; - private long _bits; + private readonly FrameResponseHeaders _collection; + private readonly long _bits; private int _state; private KeyValuePair _current; - private bool _hasUnknown; + private readonly bool _hasUnknown; private Dictionary.Enumerator _unknownEnumerator; internal Enumerator(FrameResponseHeaders collection) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs index 5d8c4e8d0d..3455f93567 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs @@ -3,7 +3,6 @@ using System; using System.Threading.Tasks; -using Microsoft.AspNet.Http; using Microsoft.AspNet.Server.Kestrel.Networking; using Microsoft.Extensions.Logging; diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerPrimary.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerPrimary.cs index d3c344ccec..04257ab015 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerPrimary.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerPrimary.cs @@ -14,9 +14,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Http /// A primary listener waits for incoming connections on a specified socket. Incoming /// connections may be passed to a secondary listener to handle. /// - abstract public class ListenerPrimary : Listener + public abstract class ListenerPrimary : Listener { - private List _dispatchPipes = new List(); + private readonly List _dispatchPipes = new List(); private int _dispatchIndex; private string _pipeName; @@ -28,7 +28,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { } - UvPipeHandle ListenPipe { get; set; } + private UvPipeHandle ListenPipe { get; set; } public async Task StartAsync( string pipeName, diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/MessageBody.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/MessageBody.cs index 8edd424a10..60a9121b56 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/MessageBody.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/MessageBody.cs @@ -12,7 +12,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { public abstract class MessageBody { - private FrameContext _context; + private readonly FrameContext _context; private int _send100Continue = 1; protected MessageBody(FrameContext context) @@ -130,7 +130,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } - class ForRemainingData : MessageBody + private class ForRemainingData : MessageBody { public ForRemainingData(FrameContext context) : base(context) @@ -143,7 +143,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } - class ForContentLength : MessageBody + private class ForContentLength : MessageBody { private readonly int _contentLength; private int _inputLength; @@ -182,7 +182,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http /// /// http://tools.ietf.org/html/rfc2616#section-3.6.1 /// - class ForChunkedEncoding : MessageBody + private class ForChunkedEncoding : MessageBody { private int _inputLength; diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs index 9a0f9f8a14..5e3f8f5a68 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs @@ -21,7 +21,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http private const int _initialTaskQueues = 64; private const int _maxPooledWriteContexts = 32; - private static WaitCallback _returnBlocks = (state) => ReturnBlocks((MemoryPoolBlock2)state); + private static readonly WaitCallback _returnBlocks = (state) => ReturnBlocks((MemoryPoolBlock2)state); private readonly KestrelThread _thread; private readonly UvStreamHandle _socket; diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs index 4769d62d6e..5286c05952 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs @@ -30,21 +30,21 @@ namespace Microsoft.AspNet.Server.Kestrel private static readonly Action _listenerPrimaryCallbackAdapter = (callback, state) => ((Action)callback).Invoke((ListenerPrimary)state); private static readonly Action _listenerSecondaryCallbackAdapter = (callback, state) => ((Action)callback).Invoke((ListenerSecondary)state); - private KestrelEngine _engine; + private readonly KestrelEngine _engine; private readonly IApplicationLifetime _appLifetime; - private Thread _thread; - private UvLoopHandle _loop; - private UvAsyncHandle _post; + private readonly Thread _thread; + private readonly UvLoopHandle _loop; + private readonly UvAsyncHandle _post; private Queue _workAdding = new Queue(1024); private Queue _workRunning = new Queue(1024); private Queue _closeHandleAdding = new Queue(256); private Queue _closeHandleRunning = new Queue(256); - private object _workSync = new Object(); + private readonly object _workSync = new Object(); private bool _stopImmediate = false; private bool _initCompleted = false; private ExceptionDispatchInfo _closeError; - private IKestrelTrace _log; - private IThreadPool _threadPool; + private readonly IKestrelTrace _log; + private readonly IThreadPool _threadPool; public KestrelThread(KestrelEngine engine) { diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelTrace.cs b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelTrace.cs index 9f6d047fdd..1bfd402993 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelTrace.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelTrace.cs @@ -12,15 +12,15 @@ namespace Microsoft.AspNet.Server.Kestrel /// public class KestrelTrace : IKestrelTrace { - private static Action _connectionStart; - private static Action _connectionStop; - private static Action _connectionPause; - private static Action _connectionResume; - private static Action _connectionReadFin; - private static Action _connectionWriteFin; - private static Action _connectionWroteFin; - private static Action _connectionKeepAlive; - private static Action _connectionDisconnect; + private static readonly Action _connectionStart; + private static readonly Action _connectionStop; + private static readonly Action _connectionPause; + private static readonly Action _connectionResume; + private static readonly Action _connectionReadFin; + private static readonly Action _connectionWriteFin; + private static readonly Action _connectionWroteFin; + private static readonly Action _connectionKeepAlive; + private static readonly Action _connectionDisconnect; protected readonly ILogger _logger; diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolIterator2Extensions.cs b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolIterator2Extensions.cs index c9a23db157..b91f455cb4 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolIterator2Extensions.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolIterator2Extensions.cs @@ -11,7 +11,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure { private const int _maxStackAllocBytes = 16384; - private static Encoding _utf8 = Encoding.UTF8; + private static readonly Encoding _utf8 = Encoding.UTF8; public const string HttpConnectMethod = "CONNECT"; public const string HttpDeleteMethod = "DELETE"; @@ -41,7 +41,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure private readonly static long _http11VersionLong = GetAsciiStringAsLong("HTTP/1.1"); private const int PerfectHashDivisor = 37; - private static Tuple[] _knownStrings = new Tuple[PerfectHashDivisor]; + private static readonly Tuple[] _knownStrings = new Tuple[PerfectHashDivisor]; static MemoryPoolIterator2Extensions() { diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/Libuv.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/Libuv.cs index f00bfa586e..2f6a74fced 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/Libuv.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/Libuv.cs @@ -103,7 +103,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking } } - public bool IsWindows; + public readonly bool IsWindows; public int Check(int statusCode) { diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvAsyncHandle.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvAsyncHandle.cs index 03c6ece9e5..32f629c713 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvAsyncHandle.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvAsyncHandle.cs @@ -8,7 +8,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking { public class UvAsyncHandle : UvHandle { - private static Libuv.uv_async_cb _uv_async_cb = (handle) => AsyncCb(handle); + private static readonly Libuv.uv_async_cb _uv_async_cb = (handle) => AsyncCb(handle); private Action _callback; public UvAsyncHandle(IKestrelTrace logger) : base(logger) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvHandle.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvHandle.cs index 7fcb2106a9..60c3ba03c8 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvHandle.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvHandle.cs @@ -9,7 +9,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking { public abstract class UvHandle : UvMemory { - private static Libuv.uv_close_cb _destroyMemory = (handle) => DestroyMemory(handle); + private static readonly Libuv.uv_close_cb _destroyMemory = (handle) => DestroyMemory(handle); private Action, IntPtr> _queueCloseHandle; protected UvHandle(IKestrelTrace logger) : base (logger) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvMemory.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvMemory.cs index a8389c39a2..3f2bf13a28 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvMemory.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvMemory.cs @@ -16,7 +16,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking { protected Libuv _uv; protected int _threadId; - protected IKestrelTrace _log; + protected readonly IKestrelTrace _log; protected UvMemory(IKestrelTrace logger) : base(IntPtr.Zero, true) { diff --git a/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/IPv6SupportedConditionAttribute.cs b/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/IPv6SupportedConditionAttribute.cs index 8415f0f040..5d8d8a0d6b 100644 --- a/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/IPv6SupportedConditionAttribute.cs +++ b/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/IPv6SupportedConditionAttribute.cs @@ -11,7 +11,7 @@ namespace Microsoft.AspNet.Server.Kestrel.FunctionalTests [AttributeUsage(AttributeTargets.Method, AllowMultiple = false)] public class IPv6SupportedConditionAttribute : Attribute, ITestCondition { - private static Lazy _ipv6Supported = new Lazy(CanBindToIPv6Address); + private static readonly Lazy _ipv6Supported = new Lazy(CanBindToIPv6Address); public bool IsMet { From ea3e64ab87d728d451e5457ca6ce8f2448cbbd8a Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Thu, 17 Dec 2015 04:09:42 +0000 Subject: [PATCH 0539/1662] Loop unrolled direct string inject --- .../MemoryPoolIterator2Extensions.cs | 176 +++++++++--------- .../AsciiDecoder.cs | 4 +- 2 files changed, 93 insertions(+), 87 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolIterator2Extensions.cs b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolIterator2Extensions.cs index b91f455cb4..f4e64c4aab 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolIterator2Extensions.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolIterator2Extensions.cs @@ -9,8 +9,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure { public static class MemoryPoolIterator2Extensions { - private const int _maxStackAllocBytes = 16384; - private static readonly Encoding _utf8 = Encoding.UTF8; public const string HttpConnectMethod = "CONNECT"; @@ -70,102 +68,110 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure } } - private static unsafe string GetAsciiStringStack(byte[] input, int inputOffset, int length) - { - // avoid declaring other local vars, or doing work with stackalloc - // to prevent the .locals init cil flag , see: https://github.com/dotnet/coreclr/issues/1279 - char* output = stackalloc char[length]; - - return GetAsciiStringImplementation(output, input, inputOffset, length); - } - - private static unsafe string GetAsciiStringImplementation(char* output, byte[] input, int inputOffset, int length) - { - for (var i = 0; i < length; i++) - { - output[i] = (char)input[inputOffset + i]; - } - - return new string(output, 0, length); - } - - private static unsafe string GetAsciiStringStack(MemoryPoolBlock2 start, MemoryPoolIterator2 end, int inputOffset, int length) - { - // avoid declaring other local vars, or doing work with stackalloc - // to prevent the .locals init cil flag , see: https://github.com/dotnet/coreclr/issues/1279 - char* output = stackalloc char[length]; - - return GetAsciiStringImplementation(output, start, end, inputOffset, length); - } - - private unsafe static string GetAsciiStringHeap(MemoryPoolBlock2 start, MemoryPoolIterator2 end, int inputOffset, int length) - { - var buffer = new char[length]; - - fixed (char* output = buffer) - { - return GetAsciiStringImplementation(output, start, end, inputOffset, length); - } - } - - private static unsafe string GetAsciiStringImplementation(char* output, MemoryPoolBlock2 start, MemoryPoolIterator2 end, int inputOffset, int length) - { - var outputOffset = 0; - var block = start; - var remaining = length; - - var endBlock = end.Block; - var endIndex = end.Index; - - while (true) - { - int following = (block != endBlock ? block.End : endIndex) - inputOffset; - - if (following > 0) - { - var input = block.Array; - for (var i = 0; i < following; i++) - { - output[i + outputOffset] = (char)input[i + inputOffset]; - } - - remaining -= following; - outputOffset += following; - } - - if (remaining == 0) - { - return new string(output, 0, length); - } - - block = block.Next; - inputOffset = block.Start; - } - } - - public static string GetAsciiString(this MemoryPoolIterator2 start, MemoryPoolIterator2 end) + public unsafe static string GetAsciiString(this MemoryPoolIterator2 start, MemoryPoolIterator2 end) { if (start.IsDefault || end.IsDefault) { - return default(string); + return null; } var length = start.GetLength(end); + if (length == 0) + { + return null; + } + // Bytes out of the range of ascii are treated as "opaque data" // and kept in string as a char value that casts to same input byte value // https://tools.ietf.org/html/rfc7230#section-3.2.4 - if (end.Block == start.Block) + + var inputOffset = start.Index; + var block = start.Block; + + var asciiString = new string('\0', length); + + fixed (char* outputStart = asciiString) { - return GetAsciiStringStack(start.Block.Array, start.Index, length); + var output = outputStart; + var remaining = length; + + var endBlock = end.Block; + var endIndex = end.Index; + + while (true) + { + int following = (block != endBlock ? block.End : endIndex) - inputOffset; + + if (following > 0) + { + fixed (byte* blockStart = block.Array) + { + var input = blockStart + inputOffset; + var i = 0; + while (i < following - 11) + { + i += 12; + *(output) = (char)*(input); + *(output + 1) = (char)*(input + 1); + *(output + 2) = (char)*(input + 2); + *(output + 3) = (char)*(input + 3); + *(output + 4) = (char)*(input + 4); + *(output + 5) = (char)*(input + 5); + *(output + 6) = (char)*(input + 6); + *(output + 7) = (char)*(input + 7); + *(output + 8) = (char)*(input + 8); + *(output + 9) = (char)*(input + 9); + *(output + 10) = (char)*(input + 10); + *(output + 11) = (char)*(input + 11); + output += 12; + input += 12; + } + if (i < following - 5) + { + i += 6; + *(output) = (char)*(input); + *(output + 1) = (char)*(input + 1); + *(output + 2) = (char)*(input + 2); + *(output + 3) = (char)*(input + 3); + *(output + 4) = (char)*(input + 4); + *(output + 5) = (char)*(input + 5); + output += 6; + input += 6; + } + if (i < following - 3) + { + i += 4; + *(output) = (char)*(input); + *(output + 1) = (char)*(input + 1); + *(output + 2) = (char)*(input + 2); + *(output + 3) = (char)*(input + 3); + output += 4; + input += 4; + } + while (i < following) + { + i++; + *output = (char)*input; + output++; + input++; + } + + remaining -= following; + } + } + + if (remaining == 0) + { + break; + } + + block = block.Next; + inputOffset = block.Start; + } } - if (length > _maxStackAllocBytes) - { - return GetAsciiStringHeap(start.Block, end, start.Index, length); - } - - return GetAsciiStringStack(start.Block, end, start.Index, length); + return asciiString; } public static string GetUtf8String(this MemoryPoolIterator2 start, MemoryPoolIterator2 end) diff --git a/test/Microsoft.AspNet.Server.KestrelTests/AsciiDecoder.cs b/test/Microsoft.AspNet.Server.KestrelTests/AsciiDecoder.cs index 26c034d2d5..245eeee086 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/AsciiDecoder.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/AsciiDecoder.cs @@ -13,7 +13,7 @@ namespace Microsoft.AspNet.Server.KestrelTests [Fact] private void FullByteRangeSupported() { - var byteRange = Enumerable.Range(0, 255).Select(x => (byte)x).ToArray(); + var byteRange = Enumerable.Range(0, 256).Select(x => (byte)x).ToArray(); var mem = MemoryPoolBlock2.Create(new ArraySegment(byteRange), IntPtr.Zero, null, null); mem.End = byteRange.Length; @@ -74,7 +74,7 @@ namespace Microsoft.AspNet.Server.KestrelTests } [Fact] - private void HeapAllocationProducesCorrectResults() + private void LargeAllocationProducesCorrectResults() { var byteRange = Enumerable.Range(0, 16384 + 64).Select(x => (byte)x).ToArray(); var expectedByteRange = byteRange.Concat(byteRange).ToArray(); From 36e9e8759a579a4d3e50c70490859f9ba99a98ec Mon Sep 17 00:00:00 2001 From: Thom Kiesewetter Date: Thu, 31 Dec 2015 01:24:59 +0100 Subject: [PATCH 0540/1662] Optimize TakeFirst Line with Known method and Version --- .../Http/Frame.cs | 38 ++--- .../Infrastructure/MemoryPoolIterator2.cs | 37 +++++ .../MemoryPoolIterator2Extensions.cs | 152 +++++++++++------- .../MemoryPoolIterator2Tests.cs | 84 ++++++++-- 4 files changed, 223 insertions(+), 88 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs index a69c5fc0d2..36c93192b0 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs @@ -271,10 +271,10 @@ namespace Microsoft.AspNet.Server.Kestrel.Http _requestProcessingStarted = true; _requestProcessingTask = Task.Factory.StartNew( - (o) => ((Frame)o).RequestProcessingAsync(), - this, - CancellationToken.None, - TaskCreationOptions.DenyChildAttach, + (o) => ((Frame)o).RequestProcessingAsync(), + this, + CancellationToken.None, + TaskCreationOptions.DenyChildAttach, TaskScheduler.Default); } } @@ -710,19 +710,18 @@ namespace Microsoft.AspNet.Server.Kestrel.Http var consumed = scan; try { - var begin = scan; - if (scan.Seek(_vectorSpaces) == -1) - { - return false; - } - string method; - if (!begin.GetKnownString(scan, out method)) + var begin = scan; + if (!begin.GetKnownMethod(ref scan,out method)) { + if (scan.Seek(_vectorSpaces) == -1) + { + return false; + } method = begin.GetAsciiString(scan); + scan.Take(); } - scan.Take(); begin = scan; var needDecode = false; @@ -749,18 +748,19 @@ namespace Microsoft.AspNet.Server.Kestrel.Http scan.Take(); begin = scan; - if (scan.Seek(_vectorCRs) == -1) - { - return false; - } string httpVersion; - if (!begin.GetKnownString(scan, out httpVersion)) + if (!begin.GetKnownVersion(ref scan, out httpVersion)) { + scan = begin; + if (scan.Seek(_vectorCRs) == -1) + { + return false; + } httpVersion = begin.GetAsciiString(scan); - } - scan.Take(); + scan.Take(); + } if (scan.Take() != '\n') { return false; diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolIterator2.cs b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolIterator2.cs index a63fafc149..645e0279d7 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolIterator2.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolIterator2.cs @@ -94,6 +94,43 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure } while (true); } + public void Skip(int bytesToSkip) + { + if (_block == null) + { + return; + } + var following = _block.End - _index; + if (following >= bytesToSkip) + { + _index += bytesToSkip; + return; + } + + var block = _block; + var index = _index; + while (true) + { + if (block.Next == null) + { + return; + } + else + { + bytesToSkip -= following; + block = block.Next; + index = block.Start; + } + following = block.End - index; + if (following >= bytesToSkip) + { + _block = block; + _index = index + bytesToSkip; + return; + } + } + } + public int Peek() { var block = _block; diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolIterator2Extensions.cs b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolIterator2Extensions.cs index b91f455cb4..4b8c66dbbd 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolIterator2Extensions.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolIterator2Extensions.cs @@ -27,35 +27,37 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure public const string Http11Version = "HTTP/1.1"; // readonly primitive statics can be Jit'd to consts https://github.com/dotnet/coreclr/issues/1079 - private readonly static long _httpConnectMethodLong = GetAsciiStringAsLong("CONNECT\0"); - private readonly static long _httpDeleteMethodLong = GetAsciiStringAsLong("DELETE\0\0"); - private readonly static long _httpGetMethodLong = GetAsciiStringAsLong("GET\0\0\0\0\0"); - private readonly static long _httpHeadMethodLong = GetAsciiStringAsLong("HEAD\0\0\0\0"); - private readonly static long _httpPatchMethodLong = GetAsciiStringAsLong("PATCH\0\0\0"); - private readonly static long _httpPostMethodLong = GetAsciiStringAsLong("POST\0\0\0\0"); - private readonly static long _httpPutMethodLong = GetAsciiStringAsLong("PUT\0\0\0\0\0"); - private readonly static long _httpOptionsMethodLong = GetAsciiStringAsLong("OPTIONS\0"); - private readonly static long _httpTraceMethodLong = GetAsciiStringAsLong("TRACE\0\0\0"); + private readonly static long _httpConnectMethodLong = GetAsciiStringAsLong("CONNECT "); + private readonly static long _httpDeleteMethodLong = GetAsciiStringAsLong("DELETE \0"); + private readonly static long _httpGetMethodLong = GetAsciiStringAsLong("GET \0\0\0\0"); + private readonly static long _httpHeadMethodLong = GetAsciiStringAsLong("HEAD \0\0\0"); + private readonly static long _httpPatchMethodLong = GetAsciiStringAsLong("PATCH \0\0"); + private readonly static long _httpPostMethodLong = GetAsciiStringAsLong("POST \0\0\0"); + private readonly static long _httpPutMethodLong = GetAsciiStringAsLong("PUT \0\0\0\0"); + private readonly static long _httpOptionsMethodLong = GetAsciiStringAsLong("OPTIONS "); + private readonly static long _httpTraceMethodLong = GetAsciiStringAsLong("TRACE \0\0"); private readonly static long _http10VersionLong = GetAsciiStringAsLong("HTTP/1.0"); private readonly static long _http11VersionLong = GetAsciiStringAsLong("HTTP/1.1"); + + private readonly static long _mask8Chars = GetMaskAsLong(new byte[] { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }); + private readonly static long _mask7Chars = GetMaskAsLong(new byte[] { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00 }); + private readonly static long _mask6Chars = GetMaskAsLong(new byte[] { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00 }); + private readonly static long _mask5Chars = GetMaskAsLong(new byte[] { 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00 }); + private readonly static long _mask4Chars = GetMaskAsLong(new byte[] { 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00 }); - private const int PerfectHashDivisor = 37; - private static readonly Tuple[] _knownStrings = new Tuple[PerfectHashDivisor]; + private readonly static Tuple[] _knownMethods = new Tuple[8]; static MemoryPoolIterator2Extensions() { - _knownStrings[_httpConnectMethodLong % PerfectHashDivisor] = Tuple.Create(_httpConnectMethodLong, HttpConnectMethod); - _knownStrings[_httpDeleteMethodLong % PerfectHashDivisor] = Tuple.Create(_httpDeleteMethodLong, HttpDeleteMethod); - _knownStrings[_httpGetMethodLong % PerfectHashDivisor] = Tuple.Create(_httpGetMethodLong, HttpGetMethod); - _knownStrings[_httpHeadMethodLong % PerfectHashDivisor] = Tuple.Create(_httpHeadMethodLong, HttpHeadMethod); - _knownStrings[_httpPatchMethodLong % PerfectHashDivisor] = Tuple.Create(_httpPatchMethodLong, HttpPatchMethod); - _knownStrings[_httpPostMethodLong % PerfectHashDivisor] = Tuple.Create(_httpPostMethodLong, HttpPostMethod); - _knownStrings[_httpPutMethodLong % PerfectHashDivisor] = Tuple.Create(_httpPutMethodLong, HttpPutMethod); - _knownStrings[_httpOptionsMethodLong % PerfectHashDivisor] = Tuple.Create(_httpOptionsMethodLong, HttpOptionsMethod); - _knownStrings[_httpTraceMethodLong % PerfectHashDivisor] = Tuple.Create(_httpTraceMethodLong, HttpTraceMethod); - _knownStrings[_http10VersionLong % PerfectHashDivisor] = Tuple.Create(_http10VersionLong, Http10Version); - _knownStrings[_http11VersionLong % PerfectHashDivisor] = Tuple.Create(_http11VersionLong, Http11Version); + _knownMethods[0] = Tuple.Create(_mask4Chars, _httpPutMethodLong, HttpPutMethod); + _knownMethods[1] = Tuple.Create(_mask5Chars, _httpPostMethodLong, HttpPostMethod); + _knownMethods[2] = Tuple.Create(_mask5Chars, _httpHeadMethodLong, HttpHeadMethod); + _knownMethods[3] = Tuple.Create(_mask6Chars, _httpTraceMethodLong, HttpTraceMethod); + _knownMethods[4] = Tuple.Create(_mask6Chars, _httpPatchMethodLong, HttpPatchMethod); + _knownMethods[5] = Tuple.Create(_mask7Chars, _httpDeleteMethodLong, HttpDeleteMethod); + _knownMethods[6] = Tuple.Create(_mask8Chars, _httpConnectMethodLong, HttpConnectMethod); + _knownMethods[7] = Tuple.Create(_mask8Chars, _httpOptionsMethodLong, HttpOptionsMethod); } private unsafe static long GetAsciiStringAsLong(string str) @@ -69,6 +71,15 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure return *(long*)ptr; } } + private unsafe static long GetMaskAsLong(byte[] bytes) + { + Debug.Assert(bytes.Length == 8, "Mask must be exactly 8 bytes long."); + + fixed (byte* ptr = bytes) + { + return *(long*)ptr; + } + } private static unsafe string GetAsciiStringStack(byte[] input, int inputOffset, int length) { @@ -264,53 +275,84 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure } /// - /// Checks that up to 8 bytes between and correspond to a known HTTP string. + /// Checks that up to 8 bytes from correspond to a known HTTP method. /// /// - /// A "known HTTP string" can be an HTTP method name defined in the HTTP/1.1 RFC or an HTTP version (HTTP/1.0 or HTTP/1.1). + /// A "known HTTP method" can be an HTTP method name defined in the HTTP/1.1 RFC. /// Since all of those fit in at most 8 bytes, they can be optimally looked up by reading those bytes as a long. Once - /// in that format, uninteresting bits are cleared and the remaining long modulo 37 is looked up in a table. - /// The number 37 was chosen because that number allows for a perfect hash of the set of - /// "known strings" (CONNECT, DELETE, GET, HEAD, PATCH, POST, PUT, OPTIONS, TRACE, HTTP/1.0 and HTTP/1.1, where strings - /// with less than 8 characters have 0s appended to their ends to fill for the missing bytes). + /// in that format, it can be checked against the known method. + /// The Known Methods (CONNECT, DELETE, GET, HEAD, PATCH, POST, PUT, OPTIONS, TRACE) are all less than 8 bytes + /// and will be compared with the required space. A mask is used if the Known method is less than 8 bytes. + /// To optimize performance the GET method will be checked first. /// /// The iterator from which to start the known string lookup. - /// The iterator pointing to the end of the input string. - /// A reference to a pre-allocated known string, if the input matches any. + /// If we found a valid method, then scan will be updated to new position + /// A reference to a pre-allocated known string, if the input matches any. /// true if the input matches a known string, false otherwise. - public static bool GetKnownString(this MemoryPoolIterator2 begin, MemoryPoolIterator2 end, out string knownString) + public static bool GetKnownMethod(this MemoryPoolIterator2 begin, ref MemoryPoolIterator2 scan, out string knownMethod) { - knownString = null; + knownMethod = null; + var value = begin.PeekLong(); - // This optimization only works on little endian environments (for now). - if (!BitConverter.IsLittleEndian) + if ((value & _mask4Chars) == _httpGetMethodLong) { - return false; + knownMethod = HttpGetMethod; + scan.Skip(4); + return true; + } + foreach (var x in _knownMethods) + { + if ((value & x.Item1) == x.Item2) + { + knownMethod = x.Item3; + scan.Skip(knownMethod.Length + 1); + return true; + } } - var inputLength = begin.GetLength(end); + return false; + } - if (inputLength > sizeof(long)) + /// + /// Checks 9 bytes from correspond to a known HTTP version. + /// + /// + /// A "known HTTP version" Is is either HTTP/1.0 or HTTP/1.1. + /// Since those fit in 8 bytes, they can be optimally looked up by reading those bytes as a long. Once + /// in that format, it can be checked against the known versions. + /// The Known versions will be checked with the required '\r'. + /// To optimize performance the HTTP/1.1 will be checked first. + /// + /// The iterator from which to start the known string lookup. + /// If we found a valid method, then scan will be updated to new position + /// A reference to a pre-allocated known string, if the input matches any. + /// true if the input matches a known string, false otherwise. + public static bool GetKnownVersion(this MemoryPoolIterator2 begin, ref MemoryPoolIterator2 scan, out string knownVersion) + { + knownVersion = null; + var value = begin.PeekLong(); + + if (value == _http11VersionLong) { - return false; + knownVersion = Http11Version; + scan.Skip(8); + if (scan.Take() == '\r') + { + return true; + } + } + else if (value == _http10VersionLong) + { + knownVersion = Http10Version; + scan.Skip(8); + if (scan.Take() == '\r') + { + return true; + } } - var inputLong = begin.PeekLong(); - - if (inputLong == -1) - { - return false; - } - - inputLong &= (long)(unchecked((ulong)~0) >> ((sizeof(long) - inputLength) * 8)); - - var value = _knownStrings[inputLong % PerfectHashDivisor]; - if (value != null && value.Item1 == inputLong) - { - knownString = value.Item2; - } - - return knownString != null; + knownVersion = null; + return false; } } -} +} \ No newline at end of file diff --git a/test/Microsoft.AspNet.Server.KestrelTests/MemoryPoolIterator2Tests.cs b/test/Microsoft.AspNet.Server.KestrelTests/MemoryPoolIterator2Tests.cs index 67c4a7e6ae..d7b9f494eb 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/MemoryPoolIterator2Tests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/MemoryPoolIterator2Tests.cs @@ -164,7 +164,7 @@ namespace Microsoft.AspNet.Server.KestrelTests var block = _pool.Lease(); block.End += blockBytes; - + var nextBlock = _pool.Lease(); nextBlock.End += nextBlockBytes; @@ -185,6 +185,45 @@ namespace Microsoft.AspNet.Server.KestrelTests Assert.Equal(originalIndex, scan.Index); } + [Theory] + [InlineData(1)] + [InlineData(2)] + [InlineData(3)] + [InlineData(4)] + [InlineData(5)] + [InlineData(6)] + [InlineData(7)] + [InlineData(8)] + [InlineData(9)] + public void SkipAtBlockBoundary(int blockBytes) + { + // Arrange + var nextBlockBytes = 10 - blockBytes; + + var block = _pool.Lease(); + block.End += blockBytes; + + var nextBlock = _pool.Lease(); + nextBlock.End += nextBlockBytes; + + block.Next = nextBlock; + + var bytes = new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; + Buffer.BlockCopy(bytes, 0, block.Array, block.Start, blockBytes); + Buffer.BlockCopy(bytes, blockBytes, nextBlock.Array, nextBlock.Start, nextBlockBytes); + + var scan = block.GetIterator(); + var originalIndex = scan.Index; + + // Act + scan.Skip(8); + var result = scan.Take(); + + // Assert + Assert.Equal(0x08, result); + Assert.NotEqual(originalIndex, scan.Index); + } + [Theory] [InlineData("CONNECT / HTTP/1.1", ' ', true, MemoryPoolIterator2Extensions.HttpConnectMethod)] [InlineData("DELETE / HTTP/1.1", ' ', true, MemoryPoolIterator2Extensions.HttpDeleteMethod)] @@ -195,38 +234,55 @@ namespace Microsoft.AspNet.Server.KestrelTests [InlineData("PUT / HTTP/1.1", ' ', true, MemoryPoolIterator2Extensions.HttpPutMethod)] [InlineData("OPTIONS / HTTP/1.1", ' ', true, MemoryPoolIterator2Extensions.HttpOptionsMethod)] [InlineData("TRACE / HTTP/1.1", ' ', true, MemoryPoolIterator2Extensions.HttpTraceMethod)] - [InlineData("HTTP/1.0\r", '\r', true, MemoryPoolIterator2Extensions.Http10Version)] - [InlineData("HTTP/1.1\r", '\r', true, MemoryPoolIterator2Extensions.Http11Version)] [InlineData("GET/ HTTP/1.1", ' ', false, null)] [InlineData("get / HTTP/1.1", ' ', false, null)] [InlineData("GOT / HTTP/1.1", ' ', false, null)] [InlineData("ABC / HTTP/1.1", ' ', false, null)] [InlineData("PO / HTTP/1.1", ' ', false, null)] [InlineData("PO ST / HTTP/1.1", ' ', false, null)] - [InlineData("HTTP/1.0_\r", '\r', false, null)] - [InlineData("HTTP/1.1_\r", '\r', false, null)] - [InlineData("HTTP/3.0\r", '\r', false, null)] - [InlineData("http/1.0\r", '\r', false, null)] - [InlineData("http/1.1\r", '\r', false, null)] [InlineData("short ", ' ', false, null)] - public void GetsKnownString(string input, char endChar, bool expectedResult, string expectedKnownString) + public void GetsKnownMethod(string input, char endChar, bool expectedResult, string expectedKnownString) { // Arrange var block = _pool.Lease(); var chars = input.ToCharArray().Select(c => (byte)c).ToArray(); Buffer.BlockCopy(chars, 0, block.Array, block.Start, chars.Length); block.End += chars.Length; - var begin = block.GetIterator(); - var end = begin; - end.Seek(new Vector((byte)endChar)); + var scan = block.GetIterator(); + var begin = scan; string knownString; // Act - var result = begin.GetKnownString(end, out knownString); + var result = begin.GetKnownMethod(ref scan, out knownString); // Assert Assert.Equal(expectedResult, result); Assert.Equal(expectedKnownString, knownString); } + + [Theory] + [InlineData("HTTP/1.0\r", '\r', true, MemoryPoolIterator2Extensions.Http10Version)] + [InlineData("HTTP/1.1\r", '\r', true, MemoryPoolIterator2Extensions.Http11Version)] + [InlineData("HTTP/3.0\r", '\r', false, null)] + [InlineData("http/1.0\r", '\r', false, null)] + [InlineData("http/1.1\r", '\r', false, null)] + [InlineData("short ", ' ', false, null)] + public void GetsKnownVersion(string input, char endChar, bool expectedResult, string expectedKnownString) + { + // Arrange + var block = _pool.Lease(); + var chars = input.ToCharArray().Select(c => (byte)c).ToArray(); + Buffer.BlockCopy(chars, 0, block.Array, block.Start, chars.Length); + block.End += chars.Length; + var scan = block.GetIterator(); + var begin = scan; + string knownString; + + // Act + var result = begin.GetKnownVersion(ref scan, out knownString); + // Assert + Assert.Equal(expectedResult, result); + Assert.Equal(expectedKnownString, knownString); + } } -} +} \ No newline at end of file From 4f8ec86b54f90bac2e576708e627ec4e0e6418e0 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Thu, 31 Dec 2015 14:04:47 -0800 Subject: [PATCH 0541/1662] React to HttpAbstractions changes --- .../Http/Frame.FeatureCollection.cs | 10 ++++++++++ .../Microsoft.AspNet.Server.KestrelTests/FrameFacts.cs | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.FeatureCollection.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.FeatureCollection.cs index 2de39f8aee..22e320e72f 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.FeatureCollection.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.FeatureCollection.cs @@ -280,6 +280,16 @@ namespace Microsoft.AspNet.Server.Kestrel.Http set { FastFeatureSet(key, value); } } + TFeature IFeatureCollection.Get() + { + return (TFeature)FastFeatureGet(typeof(TFeature)); + } + + void IFeatureCollection.Set(TFeature instance) + { + FastFeatureSet(typeof(TFeature), instance); + } + void IHttpResponseFeature.OnStarting(Func callback, object state) { OnStarting(callback, state); diff --git a/test/Microsoft.AspNet.Server.KestrelTests/FrameFacts.cs b/test/Microsoft.AspNet.Server.KestrelTests/FrameFacts.cs index da1bc9058e..400b6ac42d 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/FrameFacts.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/FrameFacts.cs @@ -26,7 +26,7 @@ namespace Microsoft.AspNet.Server.KestrelTests frame.Reset(); // Assert - Assert.Equal("http", frame.Get().Scheme); + Assert.Equal("http", ((IFeatureCollection)frame).Get().Scheme); } } } From afe944c053c6c127623f5996c19a99e9fdd1f4ad Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Wed, 23 Dec 2015 07:41:34 +0000 Subject: [PATCH 0542/1662] Simplify SocketInput, remove locks, only use pooled blocks --- .../Filter/SocketInputStream.cs | 8 +- .../Http/Connection.cs | 6 +- .../Http/SocketInput.cs | 226 ++++++++---------- .../FrameTests.cs | 4 +- .../TestInput.cs | 7 +- 5 files changed, 109 insertions(+), 142 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Filter/SocketInputStream.cs b/src/Microsoft.AspNet.Server.Kestrel/Filter/SocketInputStream.cs index 26b513faa7..d6cc5748f8 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Filter/SocketInputStream.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Filter/SocketInputStream.cs @@ -74,11 +74,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Filter public override void Write(byte[] buffer, int offset, int count) { - var inputBuffer = _socketInput.IncomingStart(count); - - Buffer.BlockCopy(buffer, offset, inputBuffer.Data.Array, inputBuffer.Data.Offset, count); - - _socketInput.IncomingComplete(count, error: null); + _socketInput.IncomingData(buffer, offset, count); } public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken token) @@ -90,7 +86,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Filter protected override void Dispose(bool disposing) { // Close _socketInput with a fake zero-length write that will result in a zero-length read. - _socketInput.IncomingComplete(0, error: null); + _socketInput.IncomingData(null, 0, 0); base.Dispose(disposing); } } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs index 89b9db55e8..6f2ea40f27 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs @@ -140,11 +140,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http private Libuv.uv_buf_t OnAlloc(UvStreamHandle handle, int suggestedSize) { - var result = _rawSocketInput.IncomingStart(2048); + var result = _rawSocketInput.IncomingStart(); return handle.Libuv.buf_init( - result.DataPtr, - result.Data.Count); + result.Pin() + result.End, + result.Data.Offset + result.Data.Count - result.End); } private static void ReadCallback(UvStreamHandle handle, int status, object state) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketInput.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketInput.cs index 5a7a1715d7..3cdbba59c8 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketInput.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketInput.cs @@ -5,7 +5,6 @@ using System; using System.IO; using System.Runtime.CompilerServices; using System.Threading; -using System.Threading.Tasks; using Microsoft.AspNet.Server.Kestrel.Infrastructure; namespace Microsoft.AspNet.Server.Kestrel.Http @@ -25,7 +24,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Http private MemoryPoolBlock2 _head; private MemoryPoolBlock2 _tail; private MemoryPoolBlock2 _pinned; - private readonly object _sync = new Object(); public SocketInput(MemoryPool2 memory, IThreadPool threadPool) { @@ -34,154 +32,99 @@ namespace Microsoft.AspNet.Server.Kestrel.Http _awaitableState = _awaitableIsNotCompleted; } - public ArraySegment Buffer { get; set; } - public bool RemoteIntakeFin { get; set; } - public bool IsCompleted + public bool IsCompleted => (_awaitableState == _awaitableIsCompleted); + + public MemoryPoolBlock2 IncomingStart() { - get + const int minimumSize = 2048; + + if (_tail != null && minimumSize <= _tail.Data.Offset + _tail.Data.Count - _tail.End) { - return Equals(_awaitableState, _awaitableIsCompleted); + _pinned = _tail; } - } - - public void Skip(int count) - { - Buffer = new ArraySegment(Buffer.Array, Buffer.Offset + count, Buffer.Count - count); - } - - public ArraySegment Take(int count) - { - var taken = new ArraySegment(Buffer.Array, Buffer.Offset, count); - Skip(count); - return taken; - } - - public IncomingBuffer IncomingStart(int minimumSize) - { - lock (_sync) + else { - if (_tail != null && minimumSize <= _tail.Data.Offset + _tail.Data.Count - _tail.End) + _pinned = _memory.Lease(); + } + + return _pinned; + } + + public void IncomingData(byte[] buffer, int offset, int count) + { + if (count > 0) + { + if (_tail == null) { - _pinned = _tail; - var data = new ArraySegment(_pinned.Data.Array, _pinned.End, _pinned.Data.Offset + _pinned.Data.Count - _pinned.End); - var dataPtr = _pinned.Pin() + _pinned.End; - return new IncomingBuffer - { - Data = data, - DataPtr = dataPtr, - }; + _tail = _memory.Lease(); } + + var iterator = new MemoryPoolIterator2(_tail, _tail.End); + iterator.CopyFrom(buffer, offset, count); + + if (_head == null) + { + _head = _tail; + } + + _tail = iterator.Block; + } + else + { + RemoteIntakeFin = true; } - _pinned = _memory.Lease(minimumSize); - return new IncomingBuffer - { - Data = _pinned.Data, - DataPtr = _pinned.Pin() + _pinned.End - }; + Complete(); } public void IncomingComplete(int count, Exception error) { - Action awaitableState; - - lock (_sync) + // Unpin may called without an earlier Pin + if (_pinned != null) { - // Unpin may called without an earlier Pin - if (_pinned != null) - { - _pinned.Unpin(); - _pinned.End += count; - if (_head == null) - { - _head = _tail = _pinned; - } - else if (_tail == _pinned) - { - // NO-OP: this was a read into unoccupied tail-space - } - else - { - _tail.Next = _pinned; - _tail = _pinned; - } + _pinned.End += count; + + if (_head == null) + { + _head = _tail = _pinned; } + else if (_tail == _pinned) + { + // NO-OP: this was a read into unoccupied tail-space + } + else + { + _tail.Next = _pinned; + _tail = _pinned; + } + _pinned = null; - - if (count == 0) - { - RemoteIntakeFin = true; - } - if (error != null) - { - _awaitableError = error; - } - - awaitableState = Interlocked.Exchange( - ref _awaitableState, - _awaitableIsCompleted); - - _manualResetEvent.Set(); } - if (awaitableState != _awaitableIsCompleted && - awaitableState != _awaitableIsNotCompleted) + if (count == 0) { - _threadPool.Run(awaitableState); + RemoteIntakeFin = true; } - } - - public MemoryPoolIterator2 ConsumingStart() - { - lock (_sync) + if (error != null) { - return new MemoryPoolIterator2(_head); + _awaitableError = error; } - } - public void ConsumingComplete( - MemoryPoolIterator2 consumed, - MemoryPoolIterator2 examined) - { - MemoryPoolBlock2 returnStart = null; - MemoryPoolBlock2 returnEnd = null; - lock (_sync) - { - if (!consumed.IsDefault) - { - returnStart = _head; - returnEnd = consumed.Block; - _head = consumed.Block; - _head.Start = consumed.Index; - } - if (!examined.IsDefault && - examined.IsEnd && - RemoteIntakeFin == false && - _awaitableError == null) - { - _manualResetEvent.Reset(); - - var awaitableState = Interlocked.CompareExchange( - ref _awaitableState, - _awaitableIsNotCompleted, - _awaitableIsCompleted); - } - } - while (returnStart != returnEnd) - { - var returnBlock = returnStart; - returnStart = returnStart.Next; - returnBlock.Pool?.Return(returnBlock); - } + Complete(); } public void AbortAwaiting() { _awaitableError = new ObjectDisposedException(nameof(SocketInput), "The request was aborted"); + Complete(); + } + + private void Complete() + { var awaitableState = Interlocked.Exchange( ref _awaitableState, _awaitableIsCompleted); @@ -195,6 +138,45 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } + public MemoryPoolIterator2 ConsumingStart() + { + return new MemoryPoolIterator2(_head); + } + + public void ConsumingComplete( + MemoryPoolIterator2 consumed, + MemoryPoolIterator2 examined) + { + MemoryPoolBlock2 returnStart = null; + MemoryPoolBlock2 returnEnd = null; + if (!consumed.IsDefault) + { + returnStart = _head; + returnEnd = consumed.Block; + _head = consumed.Block; + _head.Start = consumed.Index; + } + if (!examined.IsDefault && + examined.IsEnd && + RemoteIntakeFin == false && + _awaitableError == null) + { + _manualResetEvent.Reset(); + + var awaitableState = Interlocked.CompareExchange( + ref _awaitableState, + _awaitableIsNotCompleted, + _awaitableIsCompleted); + } + + while (returnStart != returnEnd) + { + var returnBlock = returnStart; + returnStart = returnStart.Next; + returnBlock.Pool.Return(returnBlock); + } + } + public SocketInput GetAwaiter() { return this; @@ -247,11 +229,5 @@ namespace Microsoft.AspNet.Server.Kestrel.Http throw new IOException(error.Message, error); } } - - public struct IncomingBuffer - { - public ArraySegment Data; - public IntPtr DataPtr; - } } } diff --git a/test/Microsoft.AspNet.Server.KestrelTests/FrameTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/FrameTests.cs index cc9bc26618..793084ef55 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/FrameTests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/FrameTests.cs @@ -55,9 +55,7 @@ namespace Microsoft.AspNet.Server.KestrelTests var headerCollection = new FrameRequestHeaders(); var headerArray = Encoding.ASCII.GetBytes(rawHeaders); - var inputBuffer = socketInput.IncomingStart(headerArray.Length); - Buffer.BlockCopy(headerArray, 0, inputBuffer.Data.Array, inputBuffer.Data.Offset, headerArray.Length); - socketInput.IncomingComplete(headerArray.Length, null); + socketInput.IncomingData(headerArray, 0, headerArray.Length); var success = Frame.TakeMessageHeaders(socketInput, headerCollection); diff --git a/test/Microsoft.AspNet.Server.KestrelTests/TestInput.cs b/test/Microsoft.AspNet.Server.KestrelTests/TestInput.cs index 827d47ba84..14c3213903 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/TestInput.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/TestInput.cs @@ -29,11 +29,8 @@ namespace Microsoft.AspNet.Server.KestrelTests public void Add(string text, bool fin = false) { - var encoding = System.Text.Encoding.ASCII; - var count = encoding.GetByteCount(text); - var buffer = FrameContext.SocketInput.IncomingStart(text.Length); - count = encoding.GetBytes(text, 0, text.Length, buffer.Data.Array, buffer.Data.Offset); - FrameContext.SocketInput.IncomingComplete(count, null); + var data = System.Text.Encoding.ASCII.GetBytes(text); + FrameContext.SocketInput.IncomingData(data, 0, data.Length); if (fin) { FrameContext.SocketInput.RemoteIntakeFin = true; From cf77efc2ff82c40233b0737d38751171db187e43 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Wed, 23 Dec 2015 10:20:25 +0000 Subject: [PATCH 0543/1662] Fast path pre-completed Input reads --- .../Http/SocketInput.cs | 14 +++++++------- .../Http/SocketInputExtensions.cs | 12 ++++-------- .../Infrastructure/TaskUtilities.cs | 1 + 3 files changed, 12 insertions(+), 15 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketInput.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketInput.cs index 3cdbba59c8..efe431f943 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketInput.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketInput.cs @@ -116,13 +116,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Http Complete(); } - public void AbortAwaiting() - { - _awaitableError = new ObjectDisposedException(nameof(SocketInput), "The request was aborted"); - - Complete(); - } - private void Complete() { var awaitableState = Interlocked.Exchange( @@ -177,6 +170,13 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } + public void AbortAwaiting() + { + _awaitableError = new ObjectDisposedException(nameof(SocketInput), "The request was aborted"); + + Complete(); + } + public SocketInput GetAwaiter() { return this; diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketInputExtensions.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketInputExtensions.cs index 39cb3202a0..d514c3893f 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketInputExtensions.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketInputExtensions.cs @@ -1,8 +1,8 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System; using System.Threading.Tasks; +using Microsoft.AspNet.Server.Kestrel.Infrastructure; namespace Microsoft.AspNet.Server.Kestrel.Http { @@ -10,15 +10,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { public static ValueTask ReadAsync(this SocketInput input, byte[] buffer, int offset, int count) { - while (true) + while (input.IsCompleted) { - if (!input.IsCompleted) - { - return input.ReadAsyncAwaited(buffer, offset, count); - } - var begin = input.ConsumingStart(); - int actual; var end = begin.CopyTo(buffer, offset, count, out actual); input.ConsumingComplete(end, end); @@ -32,6 +26,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return 0; } } + + return input.ReadAsyncAwaited(buffer, offset, count); } private static async Task ReadAsyncAwaited(this SocketInput input, byte[] buffer, int offset, int count) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/TaskUtilities.cs b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/TaskUtilities.cs index e67ded5acb..6a56e7507a 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/TaskUtilities.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/TaskUtilities.cs @@ -12,5 +12,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure #else public static Task CompletedTask = Task.FromResult(null); #endif + public static Task ZeroTask = Task.FromResult(0); } } \ No newline at end of file From a53949c33ee7373dafd795adeddf62556e00aaa8 Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Tue, 29 Dec 2015 16:05:35 -0800 Subject: [PATCH 0544/1662] Add CORS headers to known headers (#389). --- .../Http/FrameHeaders.Generated.cs | 1241 ++++++++++++++++- .../FrameRequestHeadersTests.cs | 1 - .../KnownHeaders.cs | 21 +- 3 files changed, 1259 insertions(+), 4 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameHeaders.Generated.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameHeaders.Generated.cs index 16c80b3980..3fc1ec6b07 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameHeaders.Generated.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameHeaders.Generated.cs @@ -54,6 +54,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Http private StringValues _TE; private StringValues _Translate; private StringValues _UserAgent; + private StringValues _Origin; + private StringValues _AccessControlRequestMethod; + private StringValues _AccessControlRequestHeaders; public StringValues HeaderCacheControl @@ -712,6 +715,54 @@ namespace Microsoft.AspNet.Server.Kestrel.Http _UserAgent = value; } } + public StringValues HeaderOrigin + { + get + { + if (((_bits & 2199023255552L) != 0)) + { + return _Origin; + } + return StringValues.Empty; + } + set + { + _bits |= 2199023255552L; + _Origin = value; + } + } + public StringValues HeaderAccessControlRequestMethod + { + get + { + if (((_bits & 4398046511104L) != 0)) + { + return _AccessControlRequestMethod; + } + return StringValues.Empty; + } + set + { + _bits |= 4398046511104L; + _AccessControlRequestMethod = value; + } + } + public StringValues HeaderAccessControlRequestHeaders + { + get + { + if (((_bits & 8796093022208L) != 0)) + { + return _AccessControlRequestHeaders; + } + return StringValues.Empty; + } + set + { + _bits |= 8796093022208L; + _AccessControlRequestHeaders = value; + } + } protected override int GetCountFast() { @@ -914,6 +965,18 @@ namespace Microsoft.AspNet.Server.Kestrel.Http throw new System.Collections.Generic.KeyNotFoundException(); } } + + if ("Origin".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 2199023255552L) != 0)) + { + return _Origin; + } + else + { + throw new System.Collections.Generic.KeyNotFoundException(); + } + } } break; @@ -1280,6 +1343,38 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } break; + + case 29: + { + if ("Access-Control-Request-Method".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 4398046511104L) != 0)) + { + return _AccessControlRequestMethod; + } + else + { + throw new System.Collections.Generic.KeyNotFoundException(); + } + } + } + break; + + case 30: + { + if ("Access-Control-Request-Headers".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 8796093022208L) != 0)) + { + return _AccessControlRequestHeaders; + } + else + { + throw new System.Collections.Generic.KeyNotFoundException(); + } + } + } + break; } if (MaybeUnknown == null) { @@ -1514,6 +1609,20 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return false; } } + + if ("Origin".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 2199023255552L) != 0)) + { + value = _Origin; + return true; + } + else + { + value = StringValues.Empty; + return false; + } + } } break; @@ -1932,6 +2041,42 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } break; + + case 29: + { + if ("Access-Control-Request-Method".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 4398046511104L) != 0)) + { + value = _AccessControlRequestMethod; + return true; + } + else + { + value = StringValues.Empty; + return false; + } + } + } + break; + + case 30: + { + if ("Access-Control-Request-Headers".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 8796093022208L) != 0)) + { + value = _AccessControlRequestHeaders; + return true; + } + else + { + value = StringValues.Empty; + return false; + } + } + } + break; } value = StringValues.Empty; return MaybeUnknown?.TryGetValue(key, out value) ?? false; @@ -2058,6 +2203,13 @@ namespace Microsoft.AspNet.Server.Kestrel.Http _Expect = value; return; } + + if ("Origin".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + _bits |= 2199023255552L; + _Origin = value; + return; + } } break; @@ -2294,6 +2446,28 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } break; + + case 29: + { + if ("Access-Control-Request-Method".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + _bits |= 4398046511104L; + _AccessControlRequestMethod = value; + return; + } + } + break; + + case 30: + { + if ("Access-Control-Request-Headers".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + _bits |= 8796093022208L; + _AccessControlRequestHeaders = value; + return; + } + } + break; } Unknown[key] = value; } @@ -2479,6 +2653,17 @@ namespace Microsoft.AspNet.Server.Kestrel.Http _Expect = value; return; } + + if ("Origin".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 2199023255552L) != 0)) + { + throw new ArgumentException("An item with the same key has already been added."); + } + _bits |= 2199023255552L; + _Origin = value; + return; + } } break; @@ -2819,6 +3004,36 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } break; + + case 29: + { + if ("Access-Control-Request-Method".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 4398046511104L) != 0)) + { + throw new ArgumentException("An item with the same key has already been added."); + } + _bits |= 4398046511104L; + _AccessControlRequestMethod = value; + return; + } + } + break; + + case 30: + { + if ("Access-Control-Request-Headers".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 8796093022208L) != 0)) + { + throw new ArgumentException("An item with the same key has already been added."); + } + _bits |= 8796093022208L; + _AccessControlRequestHeaders = value; + return; + } + } + break; } Unknown.Add(key, value); } @@ -3049,6 +3264,20 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return false; } } + + if ("Origin".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 2199023255552L) != 0)) + { + _bits &= ~2199023255552L; + _Origin = StringValues.Empty; + return true; + } + else + { + return false; + } + } } break; @@ -3467,6 +3696,42 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } break; + + case 29: + { + if ("Access-Control-Request-Method".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 4398046511104L) != 0)) + { + _bits &= ~4398046511104L; + _AccessControlRequestMethod = StringValues.Empty; + return true; + } + else + { + return false; + } + } + } + break; + + case 30: + { + if ("Access-Control-Request-Headers".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 8796093022208L) != 0)) + { + _bits &= ~8796093022208L; + _AccessControlRequestHeaders = StringValues.Empty; + return true; + } + else + { + return false; + } + } + } + break; } return MaybeUnknown?.Remove(key) ?? false; } @@ -3934,6 +4199,39 @@ namespace Microsoft.AspNet.Server.Kestrel.Http ++arrayIndex; } + if (((_bits & 2199023255552L) != 0)) + { + if (arrayIndex == array.Length) + { + throw new ArgumentException(); + } + + array[arrayIndex] = new KeyValuePair("Origin", _Origin); + ++arrayIndex; + } + + if (((_bits & 4398046511104L) != 0)) + { + if (arrayIndex == array.Length) + { + throw new ArgumentException(); + } + + array[arrayIndex] = new KeyValuePair("Access-Control-Request-Method", _AccessControlRequestMethod); + ++arrayIndex; + } + + if (((_bits & 8796093022208L) != 0)) + { + if (arrayIndex == array.Length) + { + throw new ArgumentException(); + } + + array[arrayIndex] = new KeyValuePair("Access-Control-Request-Headers", _AccessControlRequestHeaders); + ++arrayIndex; + } + ((ICollection>)MaybeUnknown)?.CopyTo(array, arrayIndex); } @@ -4165,6 +4463,20 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } return; } + + if ((((pUI[0] & 3755991007u) == 1195987535u) && ((pUS[2] & 57311u) == 20041u))) + { + if (((_bits & 2199023255552L) != 0)) + { + _Origin = AppendValue(_Origin, value); + } + else + { + _bits |= 2199023255552L; + _Origin = new StringValues(value); + } + return; + } } break; @@ -4583,6 +4895,42 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } break; + + case 29: + { + if ((((pUL[0] & 16140865742145839071uL) == 4840616791602578241uL) && ((pUL[1] & 16140865742145839071uL) == 5921472988629454415uL) && ((pUL[2] & 16140865742145839071uL) == 5561193831494668613uL) && ((pUI[6] & 3755991007u) == 1330140229u) && ((pUB[28] & 223u) == 68u))) + { + if (((_bits & 4398046511104L) != 0)) + { + _AccessControlRequestMethod = AppendValue(_AccessControlRequestMethod, value); + } + else + { + _bits |= 4398046511104L; + _AccessControlRequestMethod = new StringValues(value); + } + return; + } + } + break; + + case 30: + { + if ((((pUL[0] & 16140865742145839071uL) == 4840616791602578241uL) && ((pUL[1] & 16140865742145839071uL) == 5921472988629454415uL) && ((pUL[2] & 16140865742145839071uL) == 5200905861305028933uL) && ((pUI[6] & 3755991007u) == 1162101061u) && ((pUS[14] & 57311u) == 21330u))) + { + if (((_bits & 8796093022208L) != 0)) + { + _AccessControlRequestHeaders = AppendValue(_AccessControlRequestHeaders, value); + } + else + { + _bits |= 8796093022208L; + _AccessControlRequestHeaders = new StringValues(value); + } + return; + } + } + break; }} var key = System.Text.Encoding.ASCII.GetString(keyBytes, keyOffset, keyLength); StringValues existing; @@ -4719,6 +5067,15 @@ namespace Microsoft.AspNet.Server.Kestrel.Http case 40: goto state40; + case 41: + goto state41; + + case 42: + goto state42; + + case 43: + goto state43; + default: goto state_default; } @@ -5051,6 +5408,30 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return true; } + state41: + if (((_bits & 2199023255552L) != 0)) + { + _current = new KeyValuePair("Origin", _collection._Origin); + _state = 42; + return true; + } + + state42: + if (((_bits & 4398046511104L) != 0)) + { + _current = new KeyValuePair("Access-Control-Request-Method", _collection._AccessControlRequestMethod); + _state = 43; + return true; + } + + state43: + if (((_bits & 8796093022208L) != 0)) + { + _current = new KeyValuePair("Access-Control-Request-Headers", _collection._AccessControlRequestHeaders); + _state = 44; + return true; + } + state_default: if (!_hasUnknown || !_unknownEnumerator.MoveNext()) { @@ -5067,7 +5448,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { private static byte[] _headerBytes = new byte[] { - 13,10,67,97,99,104,101,45,67,111,110,116,114,111,108,58,32,13,10,67,111,110,110,101,99,116,105,111,110,58,32,13,10,68,97,116,101,58,32,13,10,75,101,101,112,45,65,108,105,118,101,58,32,13,10,80,114,97,103,109,97,58,32,13,10,84,114,97,105,108,101,114,58,32,13,10,84,114,97,110,115,102,101,114,45,69,110,99,111,100,105,110,103,58,32,13,10,85,112,103,114,97,100,101,58,32,13,10,86,105,97,58,32,13,10,87,97,114,110,105,110,103,58,32,13,10,65,108,108,111,119,58,32,13,10,67,111,110,116,101,110,116,45,76,101,110,103,116,104,58,32,13,10,67,111,110,116,101,110,116,45,84,121,112,101,58,32,13,10,67,111,110,116,101,110,116,45,69,110,99,111,100,105,110,103,58,32,13,10,67,111,110,116,101,110,116,45,76,97,110,103,117,97,103,101,58,32,13,10,67,111,110,116,101,110,116,45,76,111,99,97,116,105,111,110,58,32,13,10,67,111,110,116,101,110,116,45,77,68,53,58,32,13,10,67,111,110,116,101,110,116,45,82,97,110,103,101,58,32,13,10,69,120,112,105,114,101,115,58,32,13,10,76,97,115,116,45,77,111,100,105,102,105,101,100,58,32,13,10,65,99,99,101,112,116,45,82,97,110,103,101,115,58,32,13,10,65,103,101,58,32,13,10,69,84,97,103,58,32,13,10,76,111,99,97,116,105,111,110,58,32,13,10,80,114,111,120,121,45,65,117,116,104,101,116,105,99,97,116,101,58,32,13,10,82,101,116,114,121,45,65,102,116,101,114,58,32,13,10,83,101,114,118,101,114,58,32,13,10,83,101,116,45,67,111,111,107,105,101,58,32,13,10,86,97,114,121,58,32,13,10,87,87,87,45,65,117,116,104,101,110,116,105,99,97,116,101,58,32, + 13,10,67,97,99,104,101,45,67,111,110,116,114,111,108,58,32,13,10,67,111,110,110,101,99,116,105,111,110,58,32,13,10,68,97,116,101,58,32,13,10,75,101,101,112,45,65,108,105,118,101,58,32,13,10,80,114,97,103,109,97,58,32,13,10,84,114,97,105,108,101,114,58,32,13,10,84,114,97,110,115,102,101,114,45,69,110,99,111,100,105,110,103,58,32,13,10,85,112,103,114,97,100,101,58,32,13,10,86,105,97,58,32,13,10,87,97,114,110,105,110,103,58,32,13,10,65,108,108,111,119,58,32,13,10,67,111,110,116,101,110,116,45,76,101,110,103,116,104,58,32,13,10,67,111,110,116,101,110,116,45,84,121,112,101,58,32,13,10,67,111,110,116,101,110,116,45,69,110,99,111,100,105,110,103,58,32,13,10,67,111,110,116,101,110,116,45,76,97,110,103,117,97,103,101,58,32,13,10,67,111,110,116,101,110,116,45,76,111,99,97,116,105,111,110,58,32,13,10,67,111,110,116,101,110,116,45,77,68,53,58,32,13,10,67,111,110,116,101,110,116,45,82,97,110,103,101,58,32,13,10,69,120,112,105,114,101,115,58,32,13,10,76,97,115,116,45,77,111,100,105,102,105,101,100,58,32,13,10,65,99,99,101,112,116,45,82,97,110,103,101,115,58,32,13,10,65,103,101,58,32,13,10,69,84,97,103,58,32,13,10,76,111,99,97,116,105,111,110,58,32,13,10,80,114,111,120,121,45,65,117,116,104,101,116,105,99,97,116,101,58,32,13,10,82,101,116,114,121,45,65,102,116,101,114,58,32,13,10,83,101,114,118,101,114,58,32,13,10,83,101,116,45,67,111,111,107,105,101,58,32,13,10,86,97,114,121,58,32,13,10,87,87,87,45,65,117,116,104,101,110,116,105,99,97,116,101,58,32,13,10,65,99,99,101,115,115,45,67,111,110,116,114,111,108,45,65,108,108,111,119,45,67,114,101,100,101,110,116,105,97,108,115,58,32,13,10,65,99,99,101,115,115,45,67,111,110,116,114,111,108,45,65,108,108,111,119,45,72,101,97,100,101,114,115,58,32,13,10,65,99,99,101,115,115,45,67,111,110,116,114,111,108,45,65,108,108,111,119,45,77,101,116,104,111,100,115,58,32,13,10,65,99,99,101,115,115,45,67,111,110,116,114,111,108,45,65,108,108,111,119,45,79,114,105,103,105,110,58,32,13,10,65,99,99,101,115,115,45,67,111,110,116,114,111,108,45,69,120,112,111,115,101,45,72,101,97,100,101,114,115,58,32,13,10,65,99,99,101,115,115,45,67,111,110,116,114,111,108,45,77,97,120,45,65,103,101,58,32, }; private long _bits = 0; @@ -5102,6 +5483,12 @@ namespace Microsoft.AspNet.Server.Kestrel.Http private StringValues _SetCookie; private StringValues _Vary; private StringValues _WWWAuthenticate; + private StringValues _AccessControlAllowCredentials; + private StringValues _AccessControlAllowHeaders; + private StringValues _AccessControlAllowMethods; + private StringValues _AccessControlAllowOrigin; + private StringValues _AccessControlExposeHeaders; + private StringValues _AccessControlMaxAge; private byte[] _rawConnection; private byte[] _rawDate; @@ -5594,6 +5981,102 @@ namespace Microsoft.AspNet.Server.Kestrel.Http _WWWAuthenticate = value; } } + public StringValues HeaderAccessControlAllowCredentials + { + get + { + if (((_bits & 1073741824L) != 0)) + { + return _AccessControlAllowCredentials; + } + return StringValues.Empty; + } + set + { + _bits |= 1073741824L; + _AccessControlAllowCredentials = value; + } + } + public StringValues HeaderAccessControlAllowHeaders + { + get + { + if (((_bits & 2147483648L) != 0)) + { + return _AccessControlAllowHeaders; + } + return StringValues.Empty; + } + set + { + _bits |= 2147483648L; + _AccessControlAllowHeaders = value; + } + } + public StringValues HeaderAccessControlAllowMethods + { + get + { + if (((_bits & 4294967296L) != 0)) + { + return _AccessControlAllowMethods; + } + return StringValues.Empty; + } + set + { + _bits |= 4294967296L; + _AccessControlAllowMethods = value; + } + } + public StringValues HeaderAccessControlAllowOrigin + { + get + { + if (((_bits & 8589934592L) != 0)) + { + return _AccessControlAllowOrigin; + } + return StringValues.Empty; + } + set + { + _bits |= 8589934592L; + _AccessControlAllowOrigin = value; + } + } + public StringValues HeaderAccessControlExposeHeaders + { + get + { + if (((_bits & 17179869184L) != 0)) + { + return _AccessControlExposeHeaders; + } + return StringValues.Empty; + } + set + { + _bits |= 17179869184L; + _AccessControlExposeHeaders = value; + } + } + public StringValues HeaderAccessControlMaxAge + { + get + { + if (((_bits & 34359738368L) != 0)) + { + return _AccessControlMaxAge; + } + return StringValues.Empty; + } + set + { + _bits |= 34359738368L; + _AccessControlMaxAge = value; + } + } public void SetRawConnection(StringValues value, byte[] raw) { @@ -6044,6 +6527,98 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } break; + + case 32: + { + if ("Access-Control-Allow-Credentials".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 1073741824L) != 0)) + { + return _AccessControlAllowCredentials; + } + else + { + throw new System.Collections.Generic.KeyNotFoundException(); + } + } + } + break; + + case 28: + { + if ("Access-Control-Allow-Headers".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 2147483648L) != 0)) + { + return _AccessControlAllowHeaders; + } + else + { + throw new System.Collections.Generic.KeyNotFoundException(); + } + } + + if ("Access-Control-Allow-Methods".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 4294967296L) != 0)) + { + return _AccessControlAllowMethods; + } + else + { + throw new System.Collections.Generic.KeyNotFoundException(); + } + } + } + break; + + case 27: + { + if ("Access-Control-Allow-Origin".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 8589934592L) != 0)) + { + return _AccessControlAllowOrigin; + } + else + { + throw new System.Collections.Generic.KeyNotFoundException(); + } + } + } + break; + + case 29: + { + if ("Access-Control-Expose-Headers".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 17179869184L) != 0)) + { + return _AccessControlExposeHeaders; + } + else + { + throw new System.Collections.Generic.KeyNotFoundException(); + } + } + } + break; + + case 22: + { + if ("Access-Control-Max-Age".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 34359738368L) != 0)) + { + return _AccessControlMaxAge; + } + else + { + throw new System.Collections.Generic.KeyNotFoundException(); + } + } + } + break; } if (MaybeUnknown == null) { @@ -6526,6 +7101,110 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } break; + + case 32: + { + if ("Access-Control-Allow-Credentials".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 1073741824L) != 0)) + { + value = _AccessControlAllowCredentials; + return true; + } + else + { + value = StringValues.Empty; + return false; + } + } + } + break; + + case 28: + { + if ("Access-Control-Allow-Headers".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 2147483648L) != 0)) + { + value = _AccessControlAllowHeaders; + return true; + } + else + { + value = StringValues.Empty; + return false; + } + } + + if ("Access-Control-Allow-Methods".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 4294967296L) != 0)) + { + value = _AccessControlAllowMethods; + return true; + } + else + { + value = StringValues.Empty; + return false; + } + } + } + break; + + case 27: + { + if ("Access-Control-Allow-Origin".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 8589934592L) != 0)) + { + value = _AccessControlAllowOrigin; + return true; + } + else + { + value = StringValues.Empty; + return false; + } + } + } + break; + + case 29: + { + if ("Access-Control-Expose-Headers".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 17179869184L) != 0)) + { + value = _AccessControlExposeHeaders; + return true; + } + else + { + value = StringValues.Empty; + return false; + } + } + } + break; + + case 22: + { + if ("Access-Control-Max-Age".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 34359738368L) != 0)) + { + value = _AccessControlMaxAge; + return true; + } + else + { + value = StringValues.Empty; + return false; + } + } + } + break; } value = StringValues.Empty; return MaybeUnknown?.TryGetValue(key, out value) ?? false; @@ -6800,6 +7479,68 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } break; + + case 32: + { + if ("Access-Control-Allow-Credentials".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + _bits |= 1073741824L; + _AccessControlAllowCredentials = value; + return; + } + } + break; + + case 28: + { + if ("Access-Control-Allow-Headers".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + _bits |= 2147483648L; + _AccessControlAllowHeaders = value; + return; + } + + if ("Access-Control-Allow-Methods".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + _bits |= 4294967296L; + _AccessControlAllowMethods = value; + return; + } + } + break; + + case 27: + { + if ("Access-Control-Allow-Origin".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + _bits |= 8589934592L; + _AccessControlAllowOrigin = value; + return; + } + } + break; + + case 29: + { + if ("Access-Control-Expose-Headers".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + _bits |= 17179869184L; + _AccessControlExposeHeaders = value; + return; + } + } + break; + + case 22: + { + if ("Access-Control-Max-Age".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + _bits |= 34359738368L; + _AccessControlMaxAge = value; + return; + } + } + break; } Unknown[key] = value; } @@ -7193,6 +7934,92 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } break; + + case 32: + { + if ("Access-Control-Allow-Credentials".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 1073741824L) != 0)) + { + throw new ArgumentException("An item with the same key has already been added."); + } + _bits |= 1073741824L; + _AccessControlAllowCredentials = value; + return; + } + } + break; + + case 28: + { + if ("Access-Control-Allow-Headers".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 2147483648L) != 0)) + { + throw new ArgumentException("An item with the same key has already been added."); + } + _bits |= 2147483648L; + _AccessControlAllowHeaders = value; + return; + } + + if ("Access-Control-Allow-Methods".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 4294967296L) != 0)) + { + throw new ArgumentException("An item with the same key has already been added."); + } + _bits |= 4294967296L; + _AccessControlAllowMethods = value; + return; + } + } + break; + + case 27: + { + if ("Access-Control-Allow-Origin".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 8589934592L) != 0)) + { + throw new ArgumentException("An item with the same key has already been added."); + } + _bits |= 8589934592L; + _AccessControlAllowOrigin = value; + return; + } + } + break; + + case 29: + { + if ("Access-Control-Expose-Headers".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 17179869184L) != 0)) + { + throw new ArgumentException("An item with the same key has already been added."); + } + _bits |= 17179869184L; + _AccessControlExposeHeaders = value; + return; + } + } + break; + + case 22: + { + if ("Access-Control-Max-Age".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 34359738368L) != 0)) + { + throw new ArgumentException("An item with the same key has already been added."); + } + _bits |= 34359738368L; + _AccessControlMaxAge = value; + return; + } + } + break; } Unknown.Add(key, value); } @@ -7676,6 +8503,110 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } break; + + case 32: + { + if ("Access-Control-Allow-Credentials".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 1073741824L) != 0)) + { + _bits &= ~1073741824L; + _AccessControlAllowCredentials = StringValues.Empty; + return true; + } + else + { + return false; + } + } + } + break; + + case 28: + { + if ("Access-Control-Allow-Headers".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 2147483648L) != 0)) + { + _bits &= ~2147483648L; + _AccessControlAllowHeaders = StringValues.Empty; + return true; + } + else + { + return false; + } + } + + if ("Access-Control-Allow-Methods".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 4294967296L) != 0)) + { + _bits &= ~4294967296L; + _AccessControlAllowMethods = StringValues.Empty; + return true; + } + else + { + return false; + } + } + } + break; + + case 27: + { + if ("Access-Control-Allow-Origin".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 8589934592L) != 0)) + { + _bits &= ~8589934592L; + _AccessControlAllowOrigin = StringValues.Empty; + return true; + } + else + { + return false; + } + } + } + break; + + case 29: + { + if ("Access-Control-Expose-Headers".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 17179869184L) != 0)) + { + _bits &= ~17179869184L; + _AccessControlExposeHeaders = StringValues.Empty; + return true; + } + else + { + return false; + } + } + } + break; + + case 22: + { + if ("Access-Control-Max-Age".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 34359738368L) != 0)) + { + _bits &= ~34359738368L; + _AccessControlMaxAge = StringValues.Empty; + return true; + } + else + { + return false; + } + } + } + break; } return MaybeUnknown?.Remove(key) ?? false; } @@ -8022,6 +8953,72 @@ namespace Microsoft.AspNet.Server.Kestrel.Http ++arrayIndex; } + if (((_bits & 1073741824L) != 0)) + { + if (arrayIndex == array.Length) + { + throw new ArgumentException(); + } + + array[arrayIndex] = new KeyValuePair("Access-Control-Allow-Credentials", _AccessControlAllowCredentials); + ++arrayIndex; + } + + if (((_bits & 2147483648L) != 0)) + { + if (arrayIndex == array.Length) + { + throw new ArgumentException(); + } + + array[arrayIndex] = new KeyValuePair("Access-Control-Allow-Headers", _AccessControlAllowHeaders); + ++arrayIndex; + } + + if (((_bits & 4294967296L) != 0)) + { + if (arrayIndex == array.Length) + { + throw new ArgumentException(); + } + + array[arrayIndex] = new KeyValuePair("Access-Control-Allow-Methods", _AccessControlAllowMethods); + ++arrayIndex; + } + + if (((_bits & 8589934592L) != 0)) + { + if (arrayIndex == array.Length) + { + throw new ArgumentException(); + } + + array[arrayIndex] = new KeyValuePair("Access-Control-Allow-Origin", _AccessControlAllowOrigin); + ++arrayIndex; + } + + if (((_bits & 17179869184L) != 0)) + { + if (arrayIndex == array.Length) + { + throw new ArgumentException(); + } + + array[arrayIndex] = new KeyValuePair("Access-Control-Expose-Headers", _AccessControlExposeHeaders); + ++arrayIndex; + } + + if (((_bits & 34359738368L) != 0)) + { + if (arrayIndex == array.Length) + { + throw new ArgumentException(); + } + + array[arrayIndex] = new KeyValuePair("Access-Control-Max-Age", _AccessControlMaxAge); + ++arrayIndex; + } + ((ICollection>)MaybeUnknown)?.CopyTo(array, arrayIndex); } @@ -8408,6 +9405,78 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } + if (((_bits & 1073741824L) != 0)) + { + foreach(var value in _AccessControlAllowCredentials) + { + if (value != null) + { + output.CopyFrom(_headerBytes, 419, 36); + output.CopyFromAscii(value); + } + } + } + + if (((_bits & 2147483648L) != 0)) + { + foreach(var value in _AccessControlAllowHeaders) + { + if (value != null) + { + output.CopyFrom(_headerBytes, 455, 32); + output.CopyFromAscii(value); + } + } + } + + if (((_bits & 4294967296L) != 0)) + { + foreach(var value in _AccessControlAllowMethods) + { + if (value != null) + { + output.CopyFrom(_headerBytes, 487, 32); + output.CopyFromAscii(value); + } + } + } + + if (((_bits & 8589934592L) != 0)) + { + foreach(var value in _AccessControlAllowOrigin) + { + if (value != null) + { + output.CopyFrom(_headerBytes, 519, 31); + output.CopyFromAscii(value); + } + } + } + + if (((_bits & 17179869184L) != 0)) + { + foreach(var value in _AccessControlExposeHeaders) + { + if (value != null) + { + output.CopyFrom(_headerBytes, 550, 33); + output.CopyFromAscii(value); + } + } + } + + if (((_bits & 34359738368L) != 0)) + { + foreach(var value in _AccessControlMaxAge) + { + if (value != null) + { + output.CopyFrom(_headerBytes, 583, 26); + output.CopyFromAscii(value); + } + } + } + } public unsafe void Append(byte[] keyBytes, int keyOffset, int keyLength, string value) { @@ -8890,6 +9959,110 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } break; + + case 32: + { + if ((((pUL[0] & 16140865742145839071uL) == 4840616791602578241uL) && ((pUL[1] & 16140865742145839071uL) == 4696493889984679503uL) && ((pUL[2] & 16131858680330051551uL) == 4995128798724705356uL) && ((pUL[3] & 16131858542891098079uL) == 6002244186580862276uL))) + { + if (((_bits & 1073741824L) != 0)) + { + _AccessControlAllowCredentials = AppendValue(_AccessControlAllowCredentials, value); + } + else + { + _bits |= 1073741824L; + _AccessControlAllowCredentials = new StringValues(value); + } + return; + } + } + break; + + case 28: + { + if ((((pUL[0] & 16140865742145839071uL) == 4840616791602578241uL) && ((pUL[1] & 16140865742145839071uL) == 4696493889984679503uL) && ((pUL[2] & 16131858680330051551uL) == 4703244745433893964uL) && ((pUI[6] & 3755991007u) == 1397900612u))) + { + if (((_bits & 2147483648L) != 0)) + { + _AccessControlAllowHeaders = AppendValue(_AccessControlAllowHeaders, value); + } + else + { + _bits |= 2147483648L; + _AccessControlAllowHeaders = new StringValues(value); + } + return; + } + + if ((((pUL[0] & 16140865742145839071uL) == 4840616791602578241uL) && ((pUL[1] & 16140865742145839071uL) == 4696493889984679503uL) && ((pUL[2] & 16131858680330051551uL) == 6072344529712663628uL) && ((pUI[6] & 3755991007u) == 1396985672u))) + { + if (((_bits & 4294967296L) != 0)) + { + _AccessControlAllowMethods = AppendValue(_AccessControlAllowMethods, value); + } + else + { + _bits |= 4294967296L; + _AccessControlAllowMethods = new StringValues(value); + } + return; + } + } + break; + + case 27: + { + if ((((pUL[0] & 16140865742145839071uL) == 4840616791602578241uL) && ((pUL[1] & 16140865742145839071uL) == 4696493889984679503uL) && ((pUL[2] & 16131858680330051551uL) == 5283372369015950412uL) && ((pUS[12] & 57311u) == 18759u) && ((pUB[26] & 223u) == 78u))) + { + if (((_bits & 8589934592L) != 0)) + { + _AccessControlAllowOrigin = AppendValue(_AccessControlAllowOrigin, value); + } + else + { + _bits |= 8589934592L; + _AccessControlAllowOrigin = new StringValues(value); + } + return; + } + } + break; + + case 29: + { + if ((((pUL[0] & 16140865742145839071uL) == 4840616791602578241uL) && ((pUL[1] & 16140865742145839071uL) == 4984724266136391247uL) && ((pUL[2] & 16131893727263186911uL) == 4992289962713895000uL) && ((pUI[6] & 3755991007u) == 1380271169u) && ((pUB[28] & 223u) == 83u))) + { + if (((_bits & 17179869184L) != 0)) + { + _AccessControlExposeHeaders = AppendValue(_AccessControlExposeHeaders, value); + } + else + { + _bits |= 17179869184L; + _AccessControlExposeHeaders = new StringValues(value); + } + return; + } + } + break; + + case 22: + { + if ((((pUL[0] & 16140865742145839071uL) == 4840616791602578241uL) && ((pUL[1] & 16140865742145839071uL) == 5561185018439814735uL) && ((pUI[4] & 3758088159u) == 1093490753u) && ((pUS[10] & 57311u) == 17735u))) + { + if (((_bits & 34359738368L) != 0)) + { + _AccessControlMaxAge = AppendValue(_AccessControlMaxAge, value); + } + else + { + _bits |= 34359738368L; + _AccessControlMaxAge = new StringValues(value); + } + return; + } + } + break; }} var key = System.Text.Encoding.ASCII.GetString(keyBytes, keyOffset, keyLength); StringValues existing; @@ -8993,6 +10166,24 @@ namespace Microsoft.AspNet.Server.Kestrel.Http case 29: goto state29; + case 30: + goto state30; + + case 31: + goto state31; + + case 32: + goto state32; + + case 33: + goto state33; + + case 34: + goto state34; + + case 35: + goto state35; + default: goto state_default; } @@ -9237,6 +10428,54 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return true; } + state30: + if (((_bits & 1073741824L) != 0)) + { + _current = new KeyValuePair("Access-Control-Allow-Credentials", _collection._AccessControlAllowCredentials); + _state = 31; + return true; + } + + state31: + if (((_bits & 2147483648L) != 0)) + { + _current = new KeyValuePair("Access-Control-Allow-Headers", _collection._AccessControlAllowHeaders); + _state = 32; + return true; + } + + state32: + if (((_bits & 4294967296L) != 0)) + { + _current = new KeyValuePair("Access-Control-Allow-Methods", _collection._AccessControlAllowMethods); + _state = 33; + return true; + } + + state33: + if (((_bits & 8589934592L) != 0)) + { + _current = new KeyValuePair("Access-Control-Allow-Origin", _collection._AccessControlAllowOrigin); + _state = 34; + return true; + } + + state34: + if (((_bits & 17179869184L) != 0)) + { + _current = new KeyValuePair("Access-Control-Expose-Headers", _collection._AccessControlExposeHeaders); + _state = 35; + return true; + } + + state35: + if (((_bits & 34359738368L) != 0)) + { + _current = new KeyValuePair("Access-Control-Max-Age", _collection._AccessControlMaxAge); + _state = 36; + return true; + } + state_default: if (!_hasUnknown || !_unknownEnumerator.MoveNext()) { diff --git a/test/Microsoft.AspNet.Server.KestrelTests/FrameRequestHeadersTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/FrameRequestHeadersTests.cs index 302eebcf29..0206fcada2 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/FrameRequestHeadersTests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/FrameRequestHeadersTests.cs @@ -114,7 +114,6 @@ namespace Microsoft.AspNet.Server.KestrelTests headers.Values); } - [Fact] public void ContainsAndContainsKeyWork() { diff --git a/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/KnownHeaders.cs b/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/KnownHeaders.cs index df3cef0284..d5be1b429c 100644 --- a/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/KnownHeaders.cs +++ b/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/KnownHeaders.cs @@ -103,6 +103,13 @@ namespace Microsoft.AspNet.Server.Kestrel.GeneratedCode "Expires", "Last-Modified" }; + // http://www.w3.org/TR/cors/#syntax + var corsRequestHeaders = new[] + { + "Origin", + "Access-Control-Request-Method", + "Access-Control-Request-Headers", + }; var requestHeaders = commonHeaders.Concat(new[] { "Accept", @@ -126,7 +133,7 @@ namespace Microsoft.AspNet.Server.Kestrel.GeneratedCode "TE", "Translate", "User-Agent", - }).Select((header, index) => new KnownHeader + }).Concat(corsRequestHeaders).Select((header, index) => new KnownHeader { Name = header, Index = index @@ -139,6 +146,16 @@ namespace Microsoft.AspNet.Server.Kestrel.GeneratedCode "Transfer-Encoding", "Content-Length", }; + // http://www.w3.org/TR/cors/#syntax + var corsResponseHeaders = new[] + { + "Access-Control-Allow-Credentials", + "Access-Control-Allow-Headers", + "Access-Control-Allow-Methods", + "Access-Control-Allow-Origin", + "Access-Control-Expose-Headers", + "Access-Control-Max-Age", + }; var responseHeaders = commonHeaders.Concat(new[] { "Accept-Ranges", @@ -151,7 +168,7 @@ namespace Microsoft.AspNet.Server.Kestrel.GeneratedCode "Set-Cookie", "Vary", "WWW-Authenticate", - }).Select((header, index) => new KnownHeader + }).Concat(corsResponseHeaders).Select((header, index) => new KnownHeader { Name = header, Index = index, From 1eda5178de1f3d737dbd661aeb23565519ef2349 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Mon, 21 Dec 2015 07:37:35 +0000 Subject: [PATCH 0545/1662] Seek perf + faster non vector path --- .../Http/Frame.cs | 24 +- .../Infrastructure/MemoryPoolIterator2.cs | 418 ++++++++++-------- .../MemoryPoolBlock2Tests.cs | 27 +- .../MemoryPoolIterator2Tests.cs | 12 +- 4 files changed, 272 insertions(+), 209 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs index 36c93192b0..8b6dd828a3 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs @@ -40,11 +40,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http private static readonly byte[] _bytesDate = Encoding.ASCII.GetBytes("Date: "); private static readonly byte[] _bytesEndHeaders = Encoding.ASCII.GetBytes("\r\n\r\n"); - private static readonly Vector _vectorCRs = new Vector((byte)'\r'); - private static readonly Vector _vectorColons = new Vector((byte)':'); - private static readonly Vector _vectorSpaces = new Vector((byte)' '); - private static readonly Vector _vectorQuestionMarks = new Vector((byte)'?'); - private static readonly Vector _vectorPercentages = new Vector((byte)'%'); + private static Vector _vectorCRs = new Vector((byte)'\r'); + private static Vector _vectorColons = new Vector((byte)':'); + private static Vector _vectorSpaces = new Vector((byte)' '); + private static Vector _vectorQuestionMarks = new Vector((byte)'?'); + private static Vector _vectorPercentages = new Vector((byte)'%'); private readonly object _onStartingSync = new Object(); private readonly object _onCompletedSync = new Object(); @@ -714,7 +714,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http var begin = scan; if (!begin.GetKnownMethod(ref scan,out method)) { - if (scan.Seek(_vectorSpaces) == -1) + if (scan.Seek(ref _vectorSpaces) == -1) { return false; } @@ -725,11 +725,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http begin = scan; var needDecode = false; - var chFound = scan.Seek(_vectorSpaces, _vectorQuestionMarks, _vectorPercentages); + var chFound = scan.Seek(ref _vectorSpaces, ref _vectorQuestionMarks, ref _vectorPercentages); if (chFound == '%') { needDecode = true; - chFound = scan.Seek(_vectorSpaces, _vectorQuestionMarks); + chFound = scan.Seek(ref _vectorSpaces, ref _vectorQuestionMarks); } var pathBegin = begin; @@ -739,7 +739,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http if (chFound == '?') { begin = scan; - if (scan.Seek(_vectorSpaces) != ' ') + if (scan.Seek(ref _vectorSpaces) != ' ') { return false; } @@ -753,7 +753,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http if (!begin.GetKnownVersion(ref scan, out httpVersion)) { scan = begin; - if (scan.Seek(_vectorCRs) == -1) + if (scan.Seek(ref _vectorCRs) == -1) { return false; } @@ -843,7 +843,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http while (!scan.IsEnd) { var beginName = scan; - scan.Seek(_vectorColons, _vectorCRs); + scan.Seek(ref _vectorColons, ref _vectorCRs); var endName = scan; chFirst = scan.Take(); @@ -894,7 +894,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http var wrapping = false; while (!scan.IsEnd) { - if (scan.Seek(_vectorCRs) == -1) + if (scan.Seek(ref _vectorCRs) == -1) { // no "\r" in sight, burn used bytes and go back to await more data return false; diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolIterator2.cs b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolIterator2.cs index 645e0279d7..70ad9221d3 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolIterator2.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolIterator2.cs @@ -9,6 +9,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure { public struct MemoryPoolIterator2 { + private readonly static int _vectorSpan = Vector.Count; + private MemoryPoolBlock2 _block; private int _index; @@ -208,275 +210,328 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure } } - public int Seek(Vector byte0Vector) + public unsafe int Seek(ref Vector byte0Vector) { if (IsDefault) { return -1; } + var following = _block.End - _index; var block = _block; var index = _index; - var array = block.Array; + byte[] array; + var byte0 = byte0Vector[0]; + while (true) { - while (block.End == index) + while (following == 0) { - if (block.Next == null) + var newBlock = block.Next; + if (newBlock == null) { _block = block; _index = index; return -1; } - block = block.Next; - index = block.Start; - array = block.Array; + index = newBlock.Start; + following = newBlock.End - index; + block = newBlock; } - while (block.End != index) + array = block.Array; + while (following > 0) { - var following = block.End - index; - if (following >= Vector.Count) +#if !DEBUG // Need unit tests to test Vector path + // Check will be Jitted away https://github.com/dotnet/coreclr/issues/1079 + if (Vector.IsHardwareAccelerated) { - var data = new Vector(array, index); - var byte0Equals = Vector.Equals(data, byte0Vector); - - if (byte0Equals.Equals(Vector.Zero)) +#endif + if (following >= _vectorSpan) { - index += Vector.Count; - continue; - } + var byte0Equals = Vector.Equals(new Vector(array, index), byte0Vector); - _block = block; - _index = index + FindFirstEqualByte(byte0Equals); - return byte0Vector[0]; - } + if (byte0Equals.Equals(Vector.Zero)) + { + following -= _vectorSpan; + index += _vectorSpan; + continue; + } - var byte0 = byte0Vector[0]; - - while (following > 0) - { - if (block.Array[index] == byte0) - { _block = block; - _index = index; + _index = index + FindFirstEqualByte(ref byte0Equals); return byte0; } - following--; - index++; +#if !DEBUG // Need unit tests to test Vector path } +#endif + fixed (byte* ptr = block.Array) + { + var pCurrent = ptr + index; + var pEnd = pCurrent + following; + do + { + if (*pCurrent == byte0) + { + _block = block; + _index = index; + return byte0; + } + pCurrent++; + index++; + } while (pCurrent < pEnd); + } + + following = 0; + break; } } } - public int Seek(Vector byte0Vector, Vector byte1Vector) + public unsafe int Seek(ref Vector byte0Vector, ref Vector byte1Vector) { if (IsDefault) { return -1; } + var following = _block.End - _index; var block = _block; var index = _index; - var array = block.Array; + byte[] array; + int byte0Index = int.MaxValue; + int byte1Index = int.MaxValue; + var byte0 = byte0Vector[0]; + var byte1 = byte1Vector[0]; + while (true) { - while (block.End == index) + while (following == 0) { - if (block.Next == null) + var newBlock = block.Next; + if (newBlock == null) { _block = block; _index = index; return -1; } - block = block.Next; - index = block.Start; - array = block.Array; + index = newBlock.Start; + following = newBlock.End - index; + block = newBlock; } - while (block.End != index) + array = block.Array; + while (following > 0) { - var following = block.End - index; - if (following >= Vector.Count) + +#if !DEBUG // Need unit tests to test Vector path + // Check will be Jitted away https://github.com/dotnet/coreclr/issues/1079 + if (Vector.IsHardwareAccelerated) { - var data = new Vector(array, index); - var byte0Equals = Vector.Equals(data, byte0Vector); - var byte1Equals = Vector.Equals(data, byte1Vector); - int byte0Index = int.MaxValue; - int byte1Index = int.MaxValue; - - if (!byte0Equals.Equals(Vector.Zero)) +#endif + if (following >= _vectorSpan) { - byte0Index = FindFirstEqualByte(byte0Equals); - } - if (!byte1Equals.Equals(Vector.Zero)) - { - byte1Index = FindFirstEqualByte(byte1Equals); - } + var data = new Vector(array, index); + var byte0Equals = Vector.Equals(data, byte0Vector); + var byte1Equals = Vector.Equals(data, byte1Vector); - if (byte0Index == int.MaxValue && byte1Index == int.MaxValue) - { - index += Vector.Count; - continue; - } + if (!byte0Equals.Equals(Vector.Zero)) + { + byte0Index = FindFirstEqualByte(ref byte0Equals); + } + if (!byte1Equals.Equals(Vector.Zero)) + { + byte1Index = FindFirstEqualByte(ref byte1Equals); + } - _block = block; + if (byte0Index == int.MaxValue && byte1Index == int.MaxValue) + { + following -= _vectorSpan; + index += _vectorSpan; + continue; + } - if (byte0Index < byte1Index) - { - _index = index + byte0Index; - return byte0Vector[0]; - } - - _index = index + byte1Index; - return byte1Vector[0]; - } - - byte byte0 = byte0Vector[0]; - byte byte1 = byte1Vector[0]; - - while (following > 0) - { - var byteIndex = block.Array[index]; - if (byteIndex == byte0) - { _block = block; - _index = index; - return byte0; - } - else if (byteIndex == byte1) - { - _block = block; - _index = index; + + if (byte0Index < byte1Index) + { + _index = index + byte0Index; + return byte0; + } + + _index = index + byte1Index; return byte1; } - following--; - index++; +#if !DEBUG // Need unit tests to test Vector path } +#endif + fixed (byte* ptr = block.Array) + { + var pCurrent = ptr + index; + var pEnd = pCurrent + following; + do + { + if (*pCurrent == byte0) + { + _block = block; + _index = index; + return byte0; + } + if (*pCurrent == byte1) + { + _block = block; + _index = index; + return byte1; + } + pCurrent++; + index++; + } while (pCurrent != pEnd); + } + + following = 0; + break; } } } - public int Seek(Vector byte0Vector, Vector byte1Vector, Vector byte2Vector) + public unsafe int Seek(ref Vector byte0Vector, ref Vector byte1Vector, ref Vector byte2Vector) { if (IsDefault) { return -1; } + var following = _block.End - _index; var block = _block; var index = _index; - var array = block.Array; + byte[] array; + int byte0Index = int.MaxValue; + int byte1Index = int.MaxValue; + int byte2Index = int.MaxValue; + var byte0 = byte0Vector[0]; + var byte1 = byte1Vector[0]; + var byte2 = byte2Vector[0]; + while (true) { - while (block.End == index) + while (following == 0) { - if (block.Next == null) + var newBlock = block.Next; + if (newBlock == null) { _block = block; _index = index; return -1; } - block = block.Next; - index = block.Start; - array = block.Array; + index = newBlock.Start; + following = newBlock.End - index; + block = newBlock; } - while (block.End != index) + array = block.Array; + while (following > 0) { - var following = block.End - index; - if (following >= Vector.Count) +#if !DEBUG // Need unit tests to test Vector path + // Check will be Jitted away https://github.com/dotnet/coreclr/issues/1079 + if (Vector.IsHardwareAccelerated) { - var data = new Vector(array, index); - var byte0Equals = Vector.Equals(data, byte0Vector); - var byte1Equals = Vector.Equals(data, byte1Vector); - var byte2Equals = Vector.Equals(data, byte2Vector); - int byte0Index = int.MaxValue; - int byte1Index = int.MaxValue; - int byte2Index = int.MaxValue; +#endif + if (following >= _vectorSpan) + { + var data = new Vector(array, index); + var byte0Equals = Vector.Equals(data, byte0Vector); + var byte1Equals = Vector.Equals(data, byte1Vector); + var byte2Equals = Vector.Equals(data, byte2Vector); - if (!byte0Equals.Equals(Vector.Zero)) - { - byte0Index = FindFirstEqualByte(byte0Equals); - } - if (!byte1Equals.Equals(Vector.Zero)) - { - byte1Index = FindFirstEqualByte(byte1Equals); - } - if (!byte2Equals.Equals(Vector.Zero)) - { - byte2Index = FindFirstEqualByte(byte2Equals); - } - - if (byte0Index == int.MaxValue && byte1Index == int.MaxValue && byte2Index == int.MaxValue) - { - index += Vector.Count; - continue; - } - - int toReturn, toMove; - if (byte0Index < byte1Index) - { - if (byte0Index < byte2Index) + if (!byte0Equals.Equals(Vector.Zero)) { - toReturn = byte0Vector[0]; - toMove = byte0Index; + byte0Index = FindFirstEqualByte(ref byte0Equals); + } + if (!byte1Equals.Equals(Vector.Zero)) + { + byte1Index = FindFirstEqualByte(ref byte1Equals); + } + if (!byte2Equals.Equals(Vector.Zero)) + { + byte2Index = FindFirstEqualByte(ref byte2Equals); + } + + if (byte0Index == int.MaxValue && byte1Index == int.MaxValue && byte2Index == int.MaxValue) + { + following -= _vectorSpan; + index += _vectorSpan; + continue; + } + + _block = block; + + int toReturn, toMove; + if (byte0Index < byte1Index) + { + if (byte0Index < byte2Index) + { + toReturn = byte0; + toMove = byte0Index; + } + else + { + toReturn = byte2; + toMove = byte2Index; + } } else { - toReturn = byte2Vector[0]; - toMove = byte2Index; + if (byte1Index < byte2Index) + { + toReturn = byte1; + toMove = byte1Index; + } + else + { + toReturn = byte2; + toMove = byte2Index; + } } - } - else - { - if (byte1Index < byte2Index) - { - toReturn = byte1Vector[0]; - toMove = byte1Index; - } - else - { - toReturn = byte2Vector[0]; - toMove = byte2Index; - } - } - _block = block; - _index = index + toMove; - return toReturn; + _index = index + toMove; + return toReturn; + } +#if !DEBUG // Need unit tests to test Vector path } - - var byte0 = byte0Vector[0]; - var byte1 = byte1Vector[0]; - var byte2 = byte2Vector[0]; - - while (following > 0) +#endif + fixed (byte* ptr = block.Array) { - var byteIndex = block.Array[index]; - if (byteIndex == byte0) + var pCurrent = ptr + index; + var pEnd = pCurrent + following; + do { - _block = block; - _index = index; - return byte0; - } - else if (byteIndex == byte1) - { - _block = block; - _index = index; - return byte1; - } - else if (byteIndex == byte2) - { - _block = block; - _index = index; - return byte2; - } - following--; - index++; + if (*pCurrent == byte0) + { + _block = block; + _index = index; + return byte0; + } + if (*pCurrent == byte1) + { + _block = block; + _index = index; + return byte1; + } + if (*pCurrent == byte2) + { + _block = block; + _index = index; + return byte2; + } + pCurrent++; + index++; + } while (pCurrent != pEnd); } + + following = 0; + break; } } } - private static int FindFirstEqualByte(Vector byteEquals) + private static int FindFirstEqualByte(ref Vector byteEquals) { // Quasi-tree search var vector64 = Vector.AsVectorInt64(byteEquals); @@ -491,15 +546,14 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure if (vector32[shift] != 0) { if (byteEquals[offset] != 0) return offset; - if (byteEquals[++offset] != 0) return offset; - if (byteEquals[++offset] != 0) return offset; - return ++offset; + if (byteEquals[offset + 1] != 0) return offset + 1; + if (byteEquals[offset + 2] != 0) return offset + 2; + return offset + 3; } - offset += 4; - if (byteEquals[offset] != 0) return offset; - if (byteEquals[++offset] != 0) return offset; - if (byteEquals[++offset] != 0) return offset; - return ++offset; + if (byteEquals[offset + 4] != 0) return offset + 4; + if (byteEquals[offset + 5] != 0) return offset + 5; + if (byteEquals[offset + 6] != 0) return offset + 6; + return offset + 7; } throw new InvalidOperationException(); } diff --git a/test/Microsoft.AspNet.Server.KestrelTests/MemoryPoolBlock2Tests.cs b/test/Microsoft.AspNet.Server.KestrelTests/MemoryPoolBlock2Tests.cs index c56f5311d5..2cbd077180 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/MemoryPoolBlock2Tests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/MemoryPoolBlock2Tests.cs @@ -27,27 +27,27 @@ namespace Microsoft.AspNet.Server.KestrelTests var vectorCh = new Vector(ch); var hit = iterator; - hit.Seek(vectorCh); + hit.Seek(ref vectorCh); Assert.Equal(ch, iterator.GetLength(hit)); hit = iterator; - hit.Seek(vectorCh, vectorMaxValues); + hit.Seek(ref vectorCh, ref vectorMaxValues); Assert.Equal(ch, iterator.GetLength(hit)); hit = iterator; - hit.Seek(vectorMaxValues, vectorCh); + hit.Seek(ref vectorMaxValues, ref vectorCh); Assert.Equal(ch, iterator.GetLength(hit)); hit = iterator; - hit.Seek(vectorCh, vectorMaxValues, vectorMaxValues); + hit.Seek(ref vectorCh, ref vectorMaxValues, ref vectorMaxValues); Assert.Equal(ch, iterator.GetLength(hit)); hit = iterator; - hit.Seek(vectorMaxValues, vectorCh, vectorMaxValues); + hit.Seek(ref vectorMaxValues, ref vectorCh, ref vectorMaxValues); Assert.Equal(ch, iterator.GetLength(hit)); hit = iterator; - hit.Seek(vectorCh, vectorMaxValues, vectorMaxValues); + hit.Seek(ref vectorCh, ref vectorMaxValues, ref vectorMaxValues); Assert.Equal(ch, iterator.GetLength(hit)); } } @@ -56,6 +56,9 @@ namespace Microsoft.AspNet.Server.KestrelTests [Fact] public void SeekWorksAcrossBlocks() { + Console.WriteLine($"Vector.IsHardwareAccelerated == {Vector.IsHardwareAccelerated}"); + Console.WriteLine($"Vector.Count == {Vector.Count}"); + using (var pool = new MemoryPool2()) { var block1 = pool.Lease(256); @@ -83,27 +86,27 @@ namespace Microsoft.AspNet.Server.KestrelTests var vectorCh = new Vector(ch); var hit = iterator; - hit.Seek(vectorCh); + hit.Seek(ref vectorCh); Assert.Equal(ch, iterator.GetLength(hit)); hit = iterator; - hit.Seek(vectorCh, vectorMaxValues); + hit.Seek(ref vectorCh, ref vectorMaxValues); Assert.Equal(ch, iterator.GetLength(hit)); hit = iterator; - hit.Seek(vectorMaxValues, vectorCh); + hit.Seek(ref vectorMaxValues, ref vectorCh); Assert.Equal(ch, iterator.GetLength(hit)); hit = iterator; - hit.Seek(vectorCh, vectorMaxValues, vectorMaxValues); + hit.Seek(ref vectorCh, ref vectorMaxValues, ref vectorMaxValues); Assert.Equal(ch, iterator.GetLength(hit)); hit = iterator; - hit.Seek(vectorMaxValues, vectorCh, vectorMaxValues); + hit.Seek(ref vectorMaxValues, ref vectorCh, ref vectorMaxValues); Assert.Equal(ch, iterator.GetLength(hit)); hit = iterator; - hit.Seek(vectorMaxValues, vectorMaxValues, vectorCh); + hit.Seek(ref vectorMaxValues, ref vectorMaxValues, ref vectorCh); Assert.Equal(ch, iterator.GetLength(hit)); } } diff --git a/test/Microsoft.AspNet.Server.KestrelTests/MemoryPoolIterator2Tests.cs b/test/Microsoft.AspNet.Server.KestrelTests/MemoryPoolIterator2Tests.cs index d7b9f494eb..2faee6f55b 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/MemoryPoolIterator2Tests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/MemoryPoolIterator2Tests.cs @@ -53,15 +53,21 @@ namespace Microsoft.AspNet.Server.KestrelTests int found = -1; if (searchFor.Length == 1) { - found = begin.Seek(new Vector((byte)searchFor[0])); + var search0 = new Vector((byte)searchFor[0]); + found = begin.Seek(ref search0); } else if (searchFor.Length == 2) { - found = begin.Seek(new Vector((byte)searchFor[0]), new Vector((byte)searchFor[1])); + var search0 = new Vector((byte)searchFor[0]); + var search1 = new Vector((byte)searchFor[1]); + found = begin.Seek(ref search0, ref search1); } else if (searchFor.Length == 3) { - found = begin.Seek(new Vector((byte)searchFor[0]), new Vector((byte)searchFor[1]), new Vector((byte)searchFor[2])); + var search0 = new Vector((byte)searchFor[0]); + var search1 = new Vector((byte)searchFor[1]); + var search2 = new Vector((byte)searchFor[2]); + found = begin.Seek(ref search0, ref search1, ref search2); } else { From 4c39800ea4ed4273ae10c33c24dcb337fdf41f9d Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Tue, 29 Dec 2015 15:36:59 +0000 Subject: [PATCH 0546/1662] Seek perf extra See https://github.com/aspnet/KestrelHttpServer/issues/541 --- .../Infrastructure/MemoryPoolIterator2.cs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolIterator2.cs b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolIterator2.cs index 70ad9221d3..d018d90b55 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolIterator2.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolIterator2.cs @@ -217,9 +217,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure return -1; } - var following = _block.End - _index; var block = _block; var index = _index; + var following = block.End - index; byte[] array; var byte0 = byte0Vector[0]; @@ -264,9 +264,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure #if !DEBUG // Need unit tests to test Vector path } #endif - fixed (byte* ptr = block.Array) + fixed (byte* ptr = &block.Array[index]) { - var pCurrent = ptr + index; + var pCurrent = ptr; var pEnd = pCurrent + following; do { @@ -294,9 +294,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure return -1; } - var following = _block.End - _index; var block = _block; var index = _index; + var following = block.End - index; byte[] array; int byte0Index = int.MaxValue; int byte1Index = int.MaxValue; @@ -363,9 +363,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure #if !DEBUG // Need unit tests to test Vector path } #endif - fixed (byte* ptr = block.Array) + fixed (byte* ptr = &block.Array[index]) { - var pCurrent = ptr + index; + var pCurrent = ptr; var pEnd = pCurrent + following; do { @@ -399,9 +399,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure return -1; } - var following = _block.End - _index; var block = _block; var index = _index; + var following = block.End - index; byte[] array; int byte0Index = int.MaxValue; int byte1Index = int.MaxValue; @@ -496,9 +496,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure #if !DEBUG // Need unit tests to test Vector path } #endif - fixed (byte* ptr = block.Array) + fixed (byte* ptr = &block.Array[index]) { - var pCurrent = ptr + index; + var pCurrent = ptr; var pEnd = pCurrent + following; do { From 480996433e5f21bd37d7c51ae2e68af52c44cc2e Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Tue, 5 Jan 2016 11:33:29 +0000 Subject: [PATCH 0547/1662] Only queue write when not queued --- .../Http/SocketOutput.cs | 31 +++++-------------- 1 file changed, 7 insertions(+), 24 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs index 5e3f8f5a68..ac79ee0983 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs @@ -16,7 +16,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { public const int MaxPooledWriteReqs = 1024; - private const int _maxPendingWrites = 3; private const int _maxBytesPreCompleted = 65536; private const int _initialTaskQueues = 64; private const int _maxPooledWriteContexts = 32; @@ -44,7 +43,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http // The number of write operations that have been scheduled so far // but have not completed. - private int _writesPending = 0; + private bool _writePending = false; private int _numBytesPreCompleted = 0; private Exception _lastWriteError; private WriteContext _nextWriteContext; @@ -139,10 +138,10 @@ namespace Microsoft.AspNet.Server.Kestrel.Http _tasksPending.Enqueue(tcs); } - if (_writesPending < _maxPendingWrites && immediate) + if (!_writePending && immediate) { + _writePending = true; scheduleWrite = true; - _writesPending++; } } @@ -258,6 +257,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http lock (_contextLock) { + _writePending = false; + if (_nextWriteContext != null) { writingContext = _nextWriteContext; @@ -265,26 +266,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } else { - _writesPending--; return; } } - try - { - writingContext.DoWriteIfNeeded(); - } - catch - { - lock (_contextLock) - { - // Lock instead of using Interlocked.Decrement so _writesSending - // doesn't change in the middle of executing other synchronized code. - _writesPending--; - } - - throw; - } + writingContext.DoWriteIfNeeded(); } // This is called on the libuv event loop @@ -311,10 +297,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http if (_nextWriteContext != null) { scheduleWrite = true; - } - else - { - _writesPending--; + _writePending = true; } // _numBytesPreCompleted can temporarily go negative in the event there are From e6bc0bc3351ec1bca33b3a6018c043253d6f9a36 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Tue, 5 Jan 2016 11:42:41 +0000 Subject: [PATCH 0548/1662] Only scheduleWrites on the threadpool --- .../Http/SocketOutput.cs | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs index ac79ee0983..42dd1300c0 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs @@ -289,16 +289,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Http _connection.Abort(); } - bool scheduleWrite = false; - lock (_contextLock) { PoolWriteContext(writeContext); - if (_nextWriteContext != null) - { - scheduleWrite = true; - _writePending = true; - } // _numBytesPreCompleted can temporarily go negative in the event there are // completed writes that we haven't triggered callbacks for yet. @@ -334,12 +327,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } _log.ConnectionWriteCallback(_connectionId, status); - - if (scheduleWrite) - { - ScheduleWrite(); - } - _tasksCompleted.Clear(); } From 406d785b5e347297167cfc4e28ebb11af1591f77 Mon Sep 17 00:00:00 2001 From: sergey-tom Date: Tue, 5 Jan 2016 15:14:49 +0100 Subject: [PATCH 0549/1662] Fix typo Looks like value from wrong variable is passed to Marshal.FreeHGlobal method. So IntPtr.Zero is passed to the method and actual pointer is lost. --- src/Microsoft.AspNet.Server.Kestrel/Http/ListenerSecondary.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerSecondary.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerSecondary.cs index 1c6ca4aea8..d3cd04a6f0 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerSecondary.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerSecondary.cs @@ -151,7 +151,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http var ptr = Interlocked.Exchange(ref _ptr, IntPtr.Zero); if (ptr != IntPtr.Zero) { - Marshal.FreeHGlobal(_ptr); + Marshal.FreeHGlobal(ptr); } } From bc19a0729137772608f278980f8fb39e1645a2af Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Sat, 2 Jan 2016 03:05:19 +0000 Subject: [PATCH 0550/1662] ifdef comments on own line --- .../Infrastructure/MemoryPoolIterator2.cs | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolIterator2.cs b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolIterator2.cs index d018d90b55..00490fe6ad 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolIterator2.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolIterator2.cs @@ -241,7 +241,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure array = block.Array; while (following > 0) { -#if !DEBUG // Need unit tests to test Vector path +// Need unit tests to test Vector path +#if !DEBUG // Check will be Jitted away https://github.com/dotnet/coreclr/issues/1079 if (Vector.IsHardwareAccelerated) { @@ -261,7 +262,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure _index = index + FindFirstEqualByte(ref byte0Equals); return byte0; } -#if !DEBUG // Need unit tests to test Vector path +// Need unit tests to test Vector path +#if !DEBUG } #endif fixed (byte* ptr = &block.Array[index]) @@ -322,7 +324,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure while (following > 0) { -#if !DEBUG // Need unit tests to test Vector path +// Need unit tests to test Vector path +#if !DEBUG // Check will be Jitted away https://github.com/dotnet/coreclr/issues/1079 if (Vector.IsHardwareAccelerated) { @@ -360,7 +363,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure _index = index + byte1Index; return byte1; } -#if !DEBUG // Need unit tests to test Vector path +// Need unit tests to test Vector path +#if !DEBUG } #endif fixed (byte* ptr = &block.Array[index]) @@ -428,7 +432,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure array = block.Array; while (following > 0) { -#if !DEBUG // Need unit tests to test Vector path +// Need unit tests to test Vector path +#if !DEBUG // Check will be Jitted away https://github.com/dotnet/coreclr/issues/1079 if (Vector.IsHardwareAccelerated) { @@ -493,7 +498,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure _index = index + toMove; return toReturn; } -#if !DEBUG // Need unit tests to test Vector path +// Need unit tests to test Vector path +#if !DEBUG } #endif fixed (byte* ptr = &block.Array[index]) From 97a5149dd99aca7fdd2ed86365b5e39d9bb80127 Mon Sep 17 00:00:00 2001 From: Henk Mollema Date: Tue, 22 Dec 2015 08:56:05 +0100 Subject: [PATCH 0551/1662] Remove dnx451 and dnxcore50 TFM's --- .../project.json | 21 ------------------- 1 file changed, 21 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/project.json b/src/Microsoft.AspNet.Server.Kestrel/project.json index 2e0caab7c0..09c6c9851c 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/project.json +++ b/src/Microsoft.AspNet.Server.Kestrel/project.json @@ -24,28 +24,7 @@ "System.Threading.Tasks.Extensions": "4.0.0-*" }, "frameworks": { - "dnx451": { }, "net451": { }, - "dnxcore50": { - "dependencies": { - "System.Collections": "4.0.11-*", - "System.Diagnostics.Debug": "4.0.11-*", - "System.Diagnostics.TraceSource": "4.0.0-*", - "System.Diagnostics.Tracing": "4.0.21-*", - "System.Globalization": "4.0.11-*", - "System.IO": "4.0.11-*", - "System.Linq": "4.0.1-*", - "System.Net.Primitives": "4.0.11-*", - "System.Runtime.Extensions": "4.0.11-*", - "System.Runtime.InteropServices": "4.0.21-*", - "System.Text.Encoding": "4.0.11-*", - "System.Threading": "4.0.11-*", - "System.Threading.Tasks": "4.0.11-*", - "System.Threading.Thread": "4.0.0-*", - "System.Threading.ThreadPool": "4.0.10-*", - "System.Threading.Timer": "4.0.1-*" - } - }, "dotnet5.4": { "dependencies": { "System.Collections": "4.0.11-*", From e81c5adce243055328aa8644a9853c196fdf9978 Mon Sep 17 00:00:00 2001 From: Henk Mollema Date: Sat, 2 Jan 2016 10:41:08 +0100 Subject: [PATCH 0552/1662] Change #ifdefs --- .../Infrastructure/TaskUtilities.cs | 2 +- src/Microsoft.AspNet.Server.Kestrel/Networking/Libuv.cs | 7 +------ .../Networking/PlatformApis.cs | 2 +- 3 files changed, 3 insertions(+), 8 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/TaskUtilities.cs b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/TaskUtilities.cs index e67ded5acb..f333e69a4b 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/TaskUtilities.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/TaskUtilities.cs @@ -7,7 +7,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure { public static class TaskUtilities { -#if DOTNET5_4 || DNXCORE50 +#if DOTNET5_4 public static Task CompletedTask = Task.CompletedTask; #else public static Task CompletedTask = Task.FromResult(null); diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/Libuv.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/Libuv.cs index 2f6a74fced..497a6c42a0 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/Libuv.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/Libuv.cs @@ -12,12 +12,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking { IsWindows = PlatformApis.IsWindows; - var isDarwinMono = -#if DNX451 - IsWindows ? false : PlatformApis.IsDarwin; -#else - false; -#endif + var isDarwinMono = !IsWindows && PlatformApis.IsDarwin; if (isDarwinMono) { diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/PlatformApis.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/PlatformApis.cs index 6117520b3f..ae8ce0383f 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/PlatformApis.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/PlatformApis.cs @@ -10,7 +10,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking { static PlatformApis() { -#if DOTNET5_4 || DNXCORE50 +#if DOTNET5_4 IsWindows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows); IsDarwin = RuntimeInformation.IsOSPlatform(OSPlatform.OSX); #else From db11368d269b57e1e51ff4393cb1a7361f4b3cda Mon Sep 17 00:00:00 2001 From: Henk Mollema Date: Sat, 2 Jan 2016 10:41:52 +0100 Subject: [PATCH 0553/1662] Remove StandardsPoliceCompileModule usage Just a test - this seems to fix the build --- .../compiler/preprocess/SPCM.cs | 6 ------ 1 file changed, 6 deletions(-) delete mode 100644 src/Microsoft.AspNet.Server.Kestrel/compiler/preprocess/SPCM.cs diff --git a/src/Microsoft.AspNet.Server.Kestrel/compiler/preprocess/SPCM.cs b/src/Microsoft.AspNet.Server.Kestrel/compiler/preprocess/SPCM.cs deleted file mode 100644 index df92e585fc..0000000000 --- a/src/Microsoft.AspNet.Server.Kestrel/compiler/preprocess/SPCM.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace Microsoft.AspNet.Server.Kestrel -{ - public class StandardsPoliceCompileModule : Microsoft.StandardsPolice.StandardsPoliceCompileModule - { - } -} From b4b5f07a080162ac905c944fe06346bd72342537 Mon Sep 17 00:00:00 2001 From: Henk Mollema Date: Thu, 7 Jan 2016 00:48:36 +0100 Subject: [PATCH 0554/1662] Detect mono using PlatformAbstractions --- src/Microsoft.AspNet.Server.Kestrel/Networking/Libuv.cs | 2 +- .../Networking/PlatformApis.cs | 5 +++++ src/Microsoft.AspNet.Server.Kestrel/project.json | 1 + 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/Libuv.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/Libuv.cs index 497a6c42a0..abe9aa1d56 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/Libuv.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/Libuv.cs @@ -12,7 +12,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking { IsWindows = PlatformApis.IsWindows; - var isDarwinMono = !IsWindows && PlatformApis.IsDarwin; + var isDarwinMono = PlatformApis.IsDarwin && PlatformApis.IsMono; if (isDarwinMono) { diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/PlatformApis.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/PlatformApis.cs index ae8ce0383f..a1915ff372 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/PlatformApis.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/PlatformApis.cs @@ -3,6 +3,7 @@ using System; using System.Runtime.InteropServices; +using Microsoft.Extensions.PlatformAbstractions; namespace Microsoft.AspNet.Server.Kestrel.Networking { @@ -24,12 +25,16 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking IsDarwin = string.Equals(GetUname(), "Darwin", StringComparison.Ordinal); } #endif + + IsMono = PlatformServices.Default.Runtime.RuntimeType == "Mono"; } public static bool IsWindows { get; } public static bool IsDarwin { get; } + public static bool IsMono { get; } + [DllImport("libc")] static extern int uname(IntPtr buf); diff --git a/src/Microsoft.AspNet.Server.Kestrel/project.json b/src/Microsoft.AspNet.Server.Kestrel/project.json index 09c6c9851c..4cb8e6bd5d 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/project.json +++ b/src/Microsoft.AspNet.Server.Kestrel/project.json @@ -8,6 +8,7 @@ "dependencies": { "Microsoft.AspNet.Hosting": "1.0.0-*", "Microsoft.Extensions.Logging.Abstractions": "1.0.0-*", + "Microsoft.Extensions.PlatformAbstractions": "1.0.0-*", "System.Numerics.Vectors": "4.1.1-*", "Microsoft.StandardsPolice": { "version": "1.0.0-*", From b82649123440f278d7d2afff36b2a71242608b0a Mon Sep 17 00:00:00 2001 From: John Luo Date: Thu, 7 Jan 2016 11:54:27 -0800 Subject: [PATCH 0555/1662] Reacting to new hosting API --- .../AddressRegistrationTests.cs | 6 ++++-- .../PathBaseTests.cs | 6 ++++-- .../RequestTests.cs | 18 ++++++++++++------ .../ResponseTests.cs | 12 ++++++++---- .../ThreadCountTests.cs | 7 ++++--- 5 files changed, 32 insertions(+), 17 deletions(-) diff --git a/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs b/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs index da0cd8d1f9..6a936ea3db 100644 --- a/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs +++ b/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs @@ -42,11 +42,13 @@ namespace Microsoft.AspNet.Server.Kestrel.FunctionalTests var applicationBuilder = new WebApplicationBuilder() .UseConfiguration(config) - .UseServerFactory("Microsoft.AspNet.Server.Kestrel") + .UseServer("Microsoft.AspNet.Server.Kestrel") .Configure(ConfigureEchoAddress); - using (var app = applicationBuilder.Build().Start()) + using (var app = applicationBuilder.Build()) { + app.Start(); + using (var client = new HttpClient()) { foreach (var testUrl in testUrls) diff --git a/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/PathBaseTests.cs b/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/PathBaseTests.cs index 700150e2aa..ddad81932e 100644 --- a/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/PathBaseTests.cs +++ b/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/PathBaseTests.cs @@ -81,7 +81,7 @@ namespace Microsoft.AspNet.Server.Kestrel.FunctionalTests var builder = new WebApplicationBuilder() .UseConfiguration(config) - .UseServerFactory("Microsoft.AspNet.Server.Kestrel") + .UseServer("Microsoft.AspNet.Server.Kestrel") .Configure(app => { app.Run(async context => @@ -94,8 +94,10 @@ namespace Microsoft.AspNet.Server.Kestrel.FunctionalTests }); }); - using (var app = builder.Build().Start()) + using (var app = builder.Build()) { + app.Start(); + using (var client = new HttpClient()) { var response = await client.GetAsync(requestAddress); diff --git a/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/RequestTests.cs b/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/RequestTests.cs index a74f999eaf..623e85c8ff 100644 --- a/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/RequestTests.cs +++ b/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/RequestTests.cs @@ -31,7 +31,7 @@ namespace Microsoft.AspNet.Server.Kestrel.FunctionalTests var applicationBuilder = new WebApplicationBuilder() .UseConfiguration(config) - .UseServerFactory("Microsoft.AspNet.Server.Kestrel") + .UseServer("Microsoft.AspNet.Server.Kestrel") .Configure(app => { app.Run(async context => @@ -54,8 +54,10 @@ namespace Microsoft.AspNet.Server.Kestrel.FunctionalTests }); }); - using (var app = applicationBuilder.Build().Start()) + using (var app = applicationBuilder.Build()) { + app.Start(); + using (var client = new HttpClient()) { var bytes = new byte[1024 * 1024]; @@ -100,7 +102,7 @@ namespace Microsoft.AspNet.Server.Kestrel.FunctionalTests var builder = new WebApplicationBuilder() .UseConfiguration(config) - .UseServerFactory("Microsoft.AspNet.Server.Kestrel") + .UseServer("Microsoft.AspNet.Server.Kestrel") .Configure(app => { app.Run(async context => @@ -110,9 +112,11 @@ namespace Microsoft.AspNet.Server.Kestrel.FunctionalTests }); }); - using (var app = builder.Build().Start()) + using (var app = builder.Build()) using (var client = new HttpClient()) { + app.Start(); + client.DefaultRequestHeaders.Connection.Clear(); client.DefaultRequestHeaders.Connection.Add("close"); @@ -130,7 +134,7 @@ namespace Microsoft.AspNet.Server.Kestrel.FunctionalTests var builder = new WebApplicationBuilder() .UseConfiguration(config) - .UseServerFactory("Microsoft.AspNet.Server.Kestrel") + .UseServer("Microsoft.AspNet.Server.Kestrel") .Configure(app => { app.Run(async context => @@ -147,9 +151,11 @@ namespace Microsoft.AspNet.Server.Kestrel.FunctionalTests }); }); - using (var app = builder.Build().Start()) + using (var app = builder.Build()) using (var client = new HttpClient()) { + app.Start(); + var response = await client.GetAsync($"http://{requestAddress}:{port}/"); response.EnsureSuccessStatusCode(); diff --git a/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/ResponseTests.cs b/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/ResponseTests.cs index b1db1a5091..0caf5e5101 100644 --- a/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/ResponseTests.cs +++ b/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/ResponseTests.cs @@ -30,7 +30,7 @@ namespace Microsoft.AspNet.Server.Kestrel.FunctionalTests var applicationBuilder = new WebApplicationBuilder() .UseConfiguration(config) - .UseServerFactory("Microsoft.AspNet.Server.Kestrel") + .UseServer("Microsoft.AspNet.Server.Kestrel") .Configure(app => { app.Run(async context => @@ -50,8 +50,10 @@ namespace Microsoft.AspNet.Server.Kestrel.FunctionalTests }); }); - using (var app = applicationBuilder.Build().Start()) + using (var app = applicationBuilder.Build()) { + app.Start(); + using (var client = new HttpClient()) { var response = await client.GetAsync("http://localhost:8792/"); @@ -88,7 +90,7 @@ namespace Microsoft.AspNet.Server.Kestrel.FunctionalTests var hostBuilder = new WebApplicationBuilder() .UseConfiguration(config) - .UseServerFactory("Microsoft.AspNet.Server.Kestrel") + .UseServer("Microsoft.AspNet.Server.Kestrel") .Configure(app => { app.Run(async context => @@ -99,8 +101,10 @@ namespace Microsoft.AspNet.Server.Kestrel.FunctionalTests }); }); - using (var app = hostBuilder.Build().Start()) + using (var app = hostBuilder.Build()) { + app.Start(); + using (var client = new HttpClient()) { var response = await client.GetAsync("http://localhost:8793/"); diff --git a/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/ThreadCountTests.cs b/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/ThreadCountTests.cs index f67cff786f..a56fa6b47c 100644 --- a/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/ThreadCountTests.cs +++ b/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/ThreadCountTests.cs @@ -7,7 +7,6 @@ using System.Threading.Tasks; using Microsoft.AspNet.Builder; using Microsoft.AspNet.Hosting; using Microsoft.AspNet.Http; -using Microsoft.AspNet.Http.Features; using Microsoft.Extensions.Configuration; using Xunit; @@ -26,7 +25,7 @@ namespace Microsoft.AspNet.Server.Kestrel.FunctionalTests var applicationBuilder = new WebApplicationBuilder() .UseConfiguration(config) - .UseServerFactory("Microsoft.AspNet.Server.Kestrel") + .UseServer("Microsoft.AspNet.Server.Kestrel") .Configure(app => { var serverInfo = app.ServerFeatures.Get(); @@ -37,8 +36,10 @@ namespace Microsoft.AspNet.Server.Kestrel.FunctionalTests }); }); - using (var app = applicationBuilder.Build().Start()) + using (var app = applicationBuilder.Build()) { + app.Start(); + using (var client = new HttpClient()) { // Send 20 requests just to make sure we don't get any failures From b63dd40efbb1a57ea1fd102d97e42650a24f6987 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Wed, 6 Jan 2016 17:08:25 -0800 Subject: [PATCH 0556/1662] Protect SocketInput against concurrent consumption --- .../Http/SocketInput.cs | 20 ++++++++++++++---- .../SocketInputTests.cs | 21 +++++++++++++++++++ 2 files changed, 37 insertions(+), 4 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketInput.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketInput.cs index efe431f943..0afad29f09 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketInput.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketInput.cs @@ -25,6 +25,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http private MemoryPoolBlock2 _tail; private MemoryPoolBlock2 _pinned; + private int _consumingState; + public SocketInput(MemoryPool2 memory, IThreadPool threadPool) { _memory = memory; @@ -81,10 +83,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http public void IncomingComplete(int count, Exception error) { - // Unpin may called without an earlier Pin if (_pinned != null) { - _pinned.End += count; if (_head == null) @@ -133,6 +133,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http public MemoryPoolIterator2 ConsumingStart() { + if (Interlocked.CompareExchange(ref _consumingState, 1, 0) != 0) + { + throw new InvalidOperationException("Already consuming input."); + } + return new MemoryPoolIterator2(_head); } @@ -142,6 +147,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { MemoryPoolBlock2 returnStart = null; MemoryPoolBlock2 returnEnd = null; + if (!consumed.IsDefault) { returnStart = _head; @@ -149,6 +155,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http _head = consumed.Block; _head.Start = consumed.Index; } + if (!examined.IsDefault && examined.IsEnd && RemoteIntakeFin == false && @@ -156,7 +163,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { _manualResetEvent.Reset(); - var awaitableState = Interlocked.CompareExchange( + Interlocked.CompareExchange( ref _awaitableState, _awaitableIsNotCompleted, _awaitableIsCompleted); @@ -168,6 +175,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http returnStart = returnStart.Next; returnBlock.Pool.Return(returnBlock); } + + if (Interlocked.CompareExchange(ref _consumingState, 0, 1) != 1) + { + throw new InvalidOperationException("No ongoing consuming operation to complete."); + } } public void AbortAwaiting() @@ -201,7 +213,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { _awaitableError = new InvalidOperationException("Concurrent reads are not supported."); - awaitableState = Interlocked.Exchange( + Interlocked.Exchange( ref _awaitableState, _awaitableIsCompleted); diff --git a/test/Microsoft.AspNet.Server.KestrelTests/SocketInputTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/SocketInputTests.cs index 5bb02f5c0d..5a38bf87ef 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/SocketInputTests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/SocketInputTests.cs @@ -78,6 +78,27 @@ namespace Microsoft.AspNet.Server.KestrelTests } } + [Fact] + public void ConsumingOutOfOrderFailsGracefully() + { + var defultIter = new MemoryPoolIterator2(); + + // Calling ConsumingComplete without a preceding calling to ConsumingStart fails + var socketInput = new SocketInput(null, null); + Assert.Throws(() => socketInput.ConsumingComplete(defultIter, defultIter)); + + // Calling ConsumingStart twice in a row fails + socketInput = new SocketInput(null, null); + socketInput.ConsumingStart(); + Assert.Throws(() => socketInput.ConsumingStart()); + + // Calling ConsumingComplete twice in a row fails + socketInput = new SocketInput(null, null); + socketInput.ConsumingStart(); + socketInput.ConsumingComplete(defultIter, defultIter); + Assert.Throws(() => socketInput.ConsumingComplete(defultIter, defultIter)); + } + private static void TestConcurrentFaultedTask(Task t) { Assert.True(t.IsFaulted); From 2ce28d8f136c8d0e3293ab2731b2947ebbf98f69 Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Thu, 7 Jan 2016 17:34:49 -0800 Subject: [PATCH 0557/1662] Verify OnComplete is called when OnStarting isn't (#470). --- .../ResponseTests.cs | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/ResponseTests.cs b/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/ResponseTests.cs index 0caf5e5101..993ea06aa7 100644 --- a/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/ResponseTests.cs +++ b/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/ResponseTests.cs @@ -1,8 +1,10 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; using System.Collections.Generic; using System.Linq; +using System.Net; using System.Net.Http; using System.Threading.Tasks; using Microsoft.AspNet.Builder; @@ -125,6 +127,50 @@ namespace Microsoft.AspNet.Server.Kestrel.FunctionalTests } } + [ConditionalFact] + [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Test hangs after execution on mono.")] + public async Task OnCompleteCalledEvenWhenOnStartingNotCalled() + { + var config = new ConfigurationBuilder() + .AddInMemoryCollection(new Dictionary + { + { "server.urls", "http://localhost:8794/" } + }) + .Build(); + + var onStartingCalled = false; + var onCompletedCalled = false; + + var hostBuilder = new WebApplicationBuilder() + .UseConfiguration(config) + .UseServer("Microsoft.AspNet.Server.Kestrel") + .Configure(app => + { + app.Run(context => + { + context.Response.OnStarting(() => Task.Run(() => onStartingCalled = true)); + context.Response.OnCompleted(() => Task.Run(() => onCompletedCalled = true)); + + // Prevent OnStarting call (see Frame.RequestProcessingAsync()). + throw new Exception(); + }); + }); + + using (var app = hostBuilder.Build()) + { + app.Start(); + + using (var client = new HttpClient()) + { + var response = await client.GetAsync("http://localhost:8794/"); + + Assert.Equal(HttpStatusCode.InternalServerError, response.StatusCode); + Assert.False(onStartingCalled); + Assert.True(onCompletedCalled); + } + } + } + public static TheoryData NullHeaderData { get From 849ff2016c12f4756cbcd5bee1de98adeaa8c876 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Wed, 6 Jan 2016 11:34:05 -0800 Subject: [PATCH 0558/1662] Use object.ReferenceEquals when comparing Actions in SocketInput --- .../Http/SocketInput.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketInput.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketInput.cs index 0afad29f09..944457af60 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketInput.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketInput.cs @@ -36,7 +36,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http public bool RemoteIntakeFin { get; set; } - public bool IsCompleted => (_awaitableState == _awaitableIsCompleted); + public bool IsCompleted => ReferenceEquals(_awaitableState, _awaitableIsCompleted); public MemoryPoolBlock2 IncomingStart() { @@ -124,8 +124,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http _manualResetEvent.Set(); - if (awaitableState != _awaitableIsCompleted && - awaitableState != _awaitableIsNotCompleted) + if (!ReferenceEquals(awaitableState, _awaitableIsCompleted) && + !ReferenceEquals(awaitableState, _awaitableIsNotCompleted)) { _threadPool.Run(awaitableState); } @@ -201,11 +201,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http continuation, _awaitableIsNotCompleted); - if (awaitableState == _awaitableIsNotCompleted) + if (ReferenceEquals(awaitableState, _awaitableIsNotCompleted)) { return; } - else if (awaitableState == _awaitableIsCompleted) + else if (ReferenceEquals(awaitableState, _awaitableIsCompleted)) { _threadPool.Run(continuation); } From 8260e5d93f34925a39eb1f1aa4e0e64e15124812 Mon Sep 17 00:00:00 2001 From: clrjunkie Date: Sat, 9 Jan 2016 19:36:26 +0200 Subject: [PATCH 0559/1662] Remove null-conditional operators and asserts (Blocks must return to pools) --- .../Filter/StreamSocketOutput.cs | 4 ++-- src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs | 8 ++++---- .../Infrastructure/MemoryPoolIterator2.cs | 2 -- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Filter/StreamSocketOutput.cs b/src/Microsoft.AspNet.Server.Kestrel/Filter/StreamSocketOutput.cs index cbcb99f3a9..f5c9795af2 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Filter/StreamSocketOutput.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Filter/StreamSocketOutput.cs @@ -51,11 +51,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Filter var returnBlock = block; block = block.Next; - returnBlock.Pool?.Return(returnBlock); + returnBlock.Pool.Return(returnBlock); } _outputStream.Write(end.Block.Array, end.Block.Data.Offset, end.Index - end.Block.Data.Offset); - end.Block.Pool?.Return(end.Block); + end.Block.Pool.Return(end.Block); } } } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs index 42dd1300c0..f3e8adc259 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs @@ -241,7 +241,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http var returningBlock = block; block = returningBlock.Next; - returningBlock.Pool?.Return(returningBlock); + returningBlock.Pool.Return(returningBlock); } } @@ -341,13 +341,13 @@ namespace Microsoft.AspNet.Server.Kestrel.Http var returnBlock = block; block = block.Next; - returnBlock.Pool?.Return(returnBlock); + returnBlock.Pool.Return(returnBlock); } // Only return the _tail if we aren't between ProducingStart/Complete calls if (_lastStart.IsDefault) { - _tail.Pool?.Return(_tail); + _tail.Pool.Return(_tail); } _head = null; @@ -559,7 +559,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http block = block.Next; returnBlock.Unpin(); - returnBlock.Pool?.Return(returnBlock); + returnBlock.Pool.Return(returnBlock); } } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolIterator2.cs b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolIterator2.cs index 265c6b5d08..c6326465f9 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolIterator2.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolIterator2.cs @@ -695,7 +695,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure public void CopyFrom(byte[] data, int offset, int count) { Debug.Assert(_block != null); - Debug.Assert(_block.Pool != null); Debug.Assert(_block.Next == null); Debug.Assert(_block.End == _index); @@ -738,7 +737,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure public unsafe void CopyFromAscii(string data) { Debug.Assert(_block != null); - Debug.Assert(_block.Pool != null); Debug.Assert(_block.Next == null); Debug.Assert(_block.End == _index); From 63e39a257e9e0cea0d47d2eec719054dc3a407ba Mon Sep 17 00:00:00 2001 From: clrjunkie Date: Sat, 9 Jan 2016 19:41:35 +0200 Subject: [PATCH 0560/1662] One-time-use allocated blocks keep reference to source pool / Assert that a block is returned to it's source pool / Managed block are only returned to active Slabs --- .../Infrastructure/MemoryPool2.cs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPool2.cs b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPool2.cs index 5c9ce81f69..f915123562 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPool2.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPool2.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Concurrent; +using System.Diagnostics; namespace Microsoft.AspNet.Server.Kestrel.Infrastructure { @@ -76,7 +77,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure return MemoryPoolBlock2.Create( new ArraySegment(new byte[minimumSize]), dataPtr: IntPtr.Zero, - pool: null, + pool: this, slab: null); } @@ -137,8 +138,13 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure /// The block to return. It must have been acquired by calling Lease on the same memory pool instance. public void Return(MemoryPoolBlock2 block) { - block.Reset(); - _blocks.Enqueue(block); + Debug.Assert(block.Pool == this, "Returned block was leased from this pool"); + + if (block.Slab != null && block.Slab.IsActive) + { + block.Reset(); + _blocks.Enqueue(block); + } } protected virtual void Dispose(bool disposing) From 1b09a76ebb6cf8226b39f8a1d2232b378da475f4 Mon Sep 17 00:00:00 2001 From: Thom Kiesewetter Date: Mon, 11 Jan 2016 08:31:52 +0100 Subject: [PATCH 0561/1662] Find First Byte Fast --- .../Infrastructure/MemoryPoolIterator2.cs | 36 +++++++++++++++++-- .../MemoryPoolIterator2Tests.cs | 28 +++++++++++++++ 2 files changed, 61 insertions(+), 3 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolIterator2.cs b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolIterator2.cs index 265c6b5d08..3386d624d0 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolIterator2.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolIterator2.cs @@ -9,7 +9,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure { public struct MemoryPoolIterator2 { - private readonly static int _vectorSpan = Vector.Count; + private static readonly int _vectorSpan = Vector.Count; private MemoryPoolBlock2 _block; private int _index; @@ -203,7 +203,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure long nextLong; fixed (byte* ptr = &_block.Next.Array[_block.Next.Start]) { - nextLong = *(long*)(ptr ); + nextLong = *(long*)(ptr); } return (blockLong >> (sizeof(long) - blockBytes) * 8) | (nextLong << (sizeof(long) - nextBytes) * 8); @@ -537,7 +537,37 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure } } - private static int FindFirstEqualByte(ref Vector byteEquals) + /// + /// Find first byte + /// + /// + /// The first index of the result vector + /// byteEquals = 0 + internal static int FindFirstEqualByte(ref Vector byteEquals) + { + if (!BitConverter.IsLittleEndian) return FindFirstEqualByteSlow(ref byteEquals); + + // Quasi-tree search + var vector64 = Vector.AsVectorInt64(byteEquals); + for (var i = 0; i < Vector.Count; i++) + { + var longValue = vector64[i]; + if (longValue == 0) continue; + + return (i << 3) + + ((longValue & 0x00000000ffffffff) > 0 + ? (longValue & 0x000000000000ffff) > 0 + ? (longValue & 0x00000000000000ff) > 0 ? 0 : 1 + : (longValue & 0x0000000000ff0000) > 0 ? 2 : 3 + : (longValue & 0x0000ffff00000000) > 0 + ? (longValue & 0x000000ff00000000) > 0 ? 4 : 5 + : (longValue & 0x00ff000000000000) > 0 ? 6 : 7); + } + throw new InvalidOperationException(); + } + + // Internal for testing + internal static int FindFirstEqualByteSlow(ref Vector byteEquals) { // Quasi-tree search var vector64 = Vector.AsVectorInt64(byteEquals); diff --git a/test/Microsoft.AspNet.Server.KestrelTests/MemoryPoolIterator2Tests.cs b/test/Microsoft.AspNet.Server.KestrelTests/MemoryPoolIterator2Tests.cs index 2faee6f55b..627cd0dfa2 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/MemoryPoolIterator2Tests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/MemoryPoolIterator2Tests.cs @@ -20,6 +20,34 @@ namespace Microsoft.AspNet.Server.KestrelTests _pool.Dispose(); } + [Fact] + public void FindFirstByte() + { + var bytes = new byte[] { + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; + for (int i = 0; i < Vector.Count; i++) + { + Vector vector = new Vector(bytes); + Assert.Equal(i, MemoryPoolIterator2.FindFirstEqualByte(ref vector)); + bytes[i] = 0; + } + } + + [Fact] + public void _FindFirstByte() + { + var bytes = new byte[] { + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; + for (int i = 0; i < Vector.Count; i++) + { + Vector vector = new Vector(bytes); + Assert.Equal(i, MemoryPoolIterator2.FindFirstEqualByteSlow(ref vector)); + bytes[i] = 0; + } + } + [Theory] [InlineData("a", "a", 'a', 0)] [InlineData("ab", "a", 'a', 0)] From 8ac119df7619fdfd0b6b79f497579c7dcfc35b05 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Mon, 11 Jan 2016 19:02:51 +0000 Subject: [PATCH 0562/1662] using reorder (nit) --- .../Infrastructure/KestrelThread.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs index d4b8751e9a..0e4548babc 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs @@ -7,9 +7,9 @@ using System.Runtime.ExceptionServices; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNet.Hosting; +using Microsoft.AspNet.Server.Kestrel.Http; using Microsoft.AspNet.Server.Kestrel.Infrastructure; using Microsoft.AspNet.Server.Kestrel.Networking; -using Microsoft.AspNet.Server.Kestrel.Http; using Microsoft.Extensions.Logging; namespace Microsoft.AspNet.Server.Kestrel From e90b61e6c51c0c7c5b05b50466d11f382ce2d563 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Thu, 7 Jan 2016 15:28:35 -0800 Subject: [PATCH 0563/1662] Move call to CopyFrom in SocketOutput.WriteAsync inside lock to make writes atomic --- .../Http/SocketOutput.cs | 35 +++++++++++-------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs index f3e8adc259..c3a5638457 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs @@ -83,19 +83,19 @@ namespace Microsoft.AspNet.Server.Kestrel.Http bool socketShutdownSend = false, bool socketDisconnect = false) { - if (buffer.Count > 0) - { - var tail = ProducingStart(); - tail.CopyFrom(buffer); - // We do our own accounting below - ProducingCompleteNoPreComplete(tail); - } TaskCompletionSource tcs = null; - var scheduleWrite = false; lock (_contextLock) { + if (buffer.Count > 0) + { + var tail = ProducingStart(); + tail.CopyFrom(buffer); + // We do our own accounting below + ProducingCompleteNoPreComplete(tail); + } + if (_nextWriteContext == null) { if (_writeContextPool.Count > 0) @@ -253,9 +253,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Http // This is called on the libuv event loop private void WriteAllPending() { - WriteContext writingContext; + WriteContext writingContext = null; - lock (_contextLock) + if (Monitor.TryEnter(_contextLock)) { _writePending = false; @@ -264,13 +264,18 @@ namespace Microsoft.AspNet.Server.Kestrel.Http writingContext = _nextWriteContext; _nextWriteContext = null; } - else - { - return; - } + + Monitor.Exit(_contextLock); + } + else + { + ScheduleWrite(); } - writingContext.DoWriteIfNeeded(); + if (writingContext != null) + { + writingContext.DoWriteIfNeeded(); + } } // This is called on the libuv event loop From df695accb0cabd78c37f453ae3eae7bfffb6bbfc Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Thu, 7 Jan 2016 15:41:40 -0800 Subject: [PATCH 0564/1662] Use TryEnter to acquire SocketOutput._contextLock on the libuv event loop --- .../Http/SocketOutput.cs | 77 +++++++++++++------ 1 file changed, 53 insertions(+), 24 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs index c3a5638457..202a340c26 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs @@ -9,6 +9,7 @@ using System.Threading; using System.Threading.Tasks; using Microsoft.AspNet.Server.Kestrel.Infrastructure; using Microsoft.AspNet.Server.Kestrel.Networking; +using Microsoft.Extensions.Logging; namespace Microsoft.AspNet.Server.Kestrel.Http { @@ -278,7 +279,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } - // This is called on the libuv event loop + // This may called on the libuv event loop + // This is always called with the _contextLock already acquired private void OnWriteCompleted(WriteContext writeContext) { var bytesWritten = writeContext.ByteCount; @@ -294,28 +296,25 @@ namespace Microsoft.AspNet.Server.Kestrel.Http _connection.Abort(); } - lock (_contextLock) + PoolWriteContext(writeContext); + + // _numBytesPreCompleted can temporarily go negative in the event there are + // completed writes that we haven't triggered callbacks for yet. + _numBytesPreCompleted -= bytesWritten; + + // bytesLeftToBuffer can be greater than _maxBytesPreCompleted + // This allows large writes to complete once they've actually finished. + var bytesLeftToBuffer = _maxBytesPreCompleted - _numBytesPreCompleted; + while (_tasksPending.Count > 0 && + (int)(_tasksPending.Peek().Task.AsyncState) <= bytesLeftToBuffer) { - PoolWriteContext(writeContext); + var tcs = _tasksPending.Dequeue(); + var bytesToWrite = (int)tcs.Task.AsyncState; - // _numBytesPreCompleted can temporarily go negative in the event there are - // completed writes that we haven't triggered callbacks for yet. - _numBytesPreCompleted -= bytesWritten; + _numBytesPreCompleted += bytesToWrite; + bytesLeftToBuffer -= bytesToWrite; - // bytesLeftToBuffer can be greater than _maxBytesPreCompleted - // This allows large writes to complete once they've actually finished. - var bytesLeftToBuffer = _maxBytesPreCompleted - _numBytesPreCompleted; - while (_tasksPending.Count > 0 && - (int)(_tasksPending.Peek().Task.AsyncState) <= bytesLeftToBuffer) - { - var tcs = _tasksPending.Dequeue(); - var bytesToWrite = (int)tcs.Task.AsyncState; - - _numBytesPreCompleted += bytesToWrite; - bytesLeftToBuffer -= bytesToWrite; - - _tasksCompleted.Enqueue(tcs); - } + _tasksCompleted.Enqueue(tcs); } while (_tasksCompleted.Count > 0) @@ -414,6 +413,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http private class WriteContext { private static WaitCallback _returnWrittenBlocks = (state) => ReturnWrittenBlocks((MemoryPoolBlock2)state); + private static WaitCallback _completeWrite = (state) => ((WriteContext)state).CompleteOnThreadPool(); private SocketOutput Self; private UvWriteReq _writeReq; @@ -509,19 +509,48 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { if (SocketDisconnect == false || Self._socket.IsClosed) { - Complete(); + CompleteOnUvThread(); return; } Self._socket.Dispose(); Self.ReturnAllBlocks(); Self._log.ConnectionStop(Self._connectionId); - Complete(); + CompleteOnUvThread(); } - public void Complete() + public void CompleteOnUvThread() { - Self.OnWriteCompleted(this); + if (Monitor.TryEnter(Self._contextLock)) + { + try + { + Self.OnWriteCompleted(this); + } + finally + { + Monitor.Exit(Self._contextLock); + } + } + else + { + ThreadPool.QueueUserWorkItem(_completeWrite, this); + } + } + + public void CompleteOnThreadPool() + { + lock (Self._contextLock) + { + try + { + Self.OnWriteCompleted(this); + } + catch (Exception ex) + { + Self._log.LogError("SocketOutput.OnWriteCompleted", ex); + } + } } private void PoolWriteReq(UvWriteReq writeReq) From daa2b7e383d22ba0bbd901ef10374fb714c2a952 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Thu, 7 Jan 2016 16:10:05 -0800 Subject: [PATCH 0565/1662] Remove _tasksCompleted from SocketOutput - _tasksCompleted no longer helps avoid locking longer --- .../Http/SocketOutput.cs | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs index 202a340c26..49f3a33eaf 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs @@ -49,7 +49,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Http private Exception _lastWriteError; private WriteContext _nextWriteContext; private readonly Queue> _tasksPending; - private readonly Queue> _tasksCompleted; private readonly Queue _writeContextPool; private readonly Queue _writeReqPool; @@ -70,7 +69,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Http _log = log; _threadPool = threadPool; _tasksPending = new Queue>(_initialTaskQueues); - _tasksCompleted = new Queue>(_initialTaskQueues); _writeContextPool = new Queue(_maxPooledWriteContexts); _writeReqPool = writeReqPool; @@ -287,7 +285,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Http var status = writeContext.WriteStatus; var error = writeContext.WriteError; - if (error != null) { _lastWriteError = new IOException(error.Message, error); @@ -314,12 +311,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Http _numBytesPreCompleted += bytesToWrite; bytesLeftToBuffer -= bytesToWrite; - _tasksCompleted.Enqueue(tcs); - } - - while (_tasksCompleted.Count > 0) - { - var tcs = _tasksCompleted.Dequeue(); if (_lastWriteError == null) { _threadPool.Complete(tcs); @@ -331,7 +322,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } _log.ConnectionWriteCallback(_connectionId, status); - _tasksCompleted.Clear(); } // This is called on the libuv event loop From ab5ef547e1ffeb3e0a68e976a94565e13cc791db Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Thu, 7 Jan 2016 20:44:21 -0800 Subject: [PATCH 0566/1662] Make chunked writes atomic --- .../Filter/StreamSocketOutput.cs | 26 ++++++-- .../Http/ChunkWriter.cs | 62 +++++++++++++++++++ .../Http/Frame.cs | 39 +----------- .../Http/ISocketOutput.cs | 4 +- .../Http/SocketOutput.cs | 23 +++++-- .../ChunkWriterTests.cs | 38 ++++++++++++ .../FrameTests.cs | 25 -------- 7 files changed, 144 insertions(+), 73 deletions(-) create mode 100644 src/Microsoft.AspNet.Server.Kestrel/Http/ChunkWriter.cs create mode 100644 test/Microsoft.AspNet.Server.KestrelTests/ChunkWriterTests.cs diff --git a/src/Microsoft.AspNet.Server.Kestrel/Filter/StreamSocketOutput.cs b/src/Microsoft.AspNet.Server.Kestrel/Filter/StreamSocketOutput.cs index f5c9795af2..6ee20338f4 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Filter/StreamSocketOutput.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Filter/StreamSocketOutput.cs @@ -3,6 +3,7 @@ using System; using System.IO; +using System.Text; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNet.Server.Kestrel.Http; @@ -12,27 +13,44 @@ namespace Microsoft.AspNet.Server.Kestrel.Filter { public class StreamSocketOutput : ISocketOutput { + private static readonly byte[] _endChunkBytes = Encoding.ASCII.GetBytes("\r\n"); private static readonly byte[] _nullBuffer = new byte[0]; private readonly Stream _outputStream; private readonly MemoryPool2 _memory; private MemoryPoolBlock2 _producingBlock; + private object _writeLock = new object(); + public StreamSocketOutput(Stream outputStream, MemoryPool2 memory) { _outputStream = outputStream; _memory = memory; } - void ISocketOutput.Write(ArraySegment buffer, bool immediate) + public void Write(ArraySegment buffer, bool immediate, bool chunk) { - _outputStream.Write(buffer.Array ?? _nullBuffer, buffer.Offset, buffer.Count); + lock (_writeLock) + { + if (chunk && buffer.Array != null) + { + var beginChunkBytes = ChunkWriter.BeginChunkBytes(buffer.Count); + _outputStream.Write(beginChunkBytes.Array, beginChunkBytes.Offset, beginChunkBytes.Count); + } + + _outputStream.Write(buffer.Array ?? _nullBuffer, buffer.Offset, buffer.Count); + + if (chunk && buffer.Array != null) + { + _outputStream.Write(_endChunkBytes, 0, _endChunkBytes.Length); + } + } } - Task ISocketOutput.WriteAsync(ArraySegment buffer, bool immediate, CancellationToken cancellationToken) + public Task WriteAsync(ArraySegment buffer, bool immediate, bool chunk, CancellationToken cancellationToken) { // TODO: Use _outputStream.WriteAsync - _outputStream.Write(buffer.Array ?? _nullBuffer, buffer.Offset, buffer.Count); + Write(buffer, immediate, chunk); return TaskUtilities.CompletedTask; } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/ChunkWriter.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/ChunkWriter.cs new file mode 100644 index 0000000000..2d38857005 --- /dev/null +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/ChunkWriter.cs @@ -0,0 +1,62 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Text; +using Microsoft.AspNet.Server.Kestrel.Infrastructure; + +namespace Microsoft.AspNet.Server.Kestrel.Http +{ + public static class ChunkWriter + { + private static readonly ArraySegment _endChunkBytes = CreateAsciiByteArraySegment("\r\n"); + private static readonly byte[] _hex = Encoding.ASCII.GetBytes("0123456789abcdef"); + + private static ArraySegment CreateAsciiByteArraySegment(string text) + { + var bytes = Encoding.ASCII.GetBytes(text); + return new ArraySegment(bytes); + } + + public static ArraySegment BeginChunkBytes(int dataCount) + { + var bytes = new byte[10] + { + _hex[((dataCount >> 0x1c) & 0x0f)], + _hex[((dataCount >> 0x18) & 0x0f)], + _hex[((dataCount >> 0x14) & 0x0f)], + _hex[((dataCount >> 0x10) & 0x0f)], + _hex[((dataCount >> 0x0c) & 0x0f)], + _hex[((dataCount >> 0x08) & 0x0f)], + _hex[((dataCount >> 0x04) & 0x0f)], + _hex[((dataCount >> 0x00) & 0x0f)], + (byte)'\r', + (byte)'\n', + }; + + // Determine the most-significant non-zero nibble + int total, shift; + total = (dataCount > 0xffff) ? 0x10 : 0x00; + dataCount >>= total; + shift = (dataCount > 0x00ff) ? 0x08 : 0x00; + dataCount >>= shift; + total |= shift; + total |= (dataCount > 0x000f) ? 0x04 : 0x00; + + var offset = 7 - (total >> 2); + return new ArraySegment(bytes, offset, 10 - offset); + } + + public static int WriteBeginChunkBytes(ref MemoryPoolIterator2 start, int dataCount) + { + var chunkSegment = BeginChunkBytes(dataCount); + start.CopyFrom(chunkSegment); + return chunkSegment.Count; + } + + public static void WriteEndChunkBytes(ref MemoryPoolIterator2 start) + { + start.CopyFrom(_endChunkBytes); + } + } +} diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs index 8b6dd828a3..f315bb702b 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs @@ -23,11 +23,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Http public abstract partial class Frame : FrameContext, IFrameControl { private static readonly Encoding _ascii = Encoding.ASCII; - private static readonly ArraySegment _endChunkBytes = CreateAsciiByteArraySegment("\r\n"); private static readonly ArraySegment _endChunkedResponseBytes = CreateAsciiByteArraySegment("0\r\n\r\n"); private static readonly ArraySegment _continueBytes = CreateAsciiByteArraySegment("HTTP/1.1 100 Continue\r\n\r\n"); private static readonly ArraySegment _emptyData = new ArraySegment(new byte[0]); - private static readonly byte[] _hex = Encoding.ASCII.GetBytes("0123456789abcdef"); private static readonly byte[] _bytesConnectionClose = Encoding.ASCII.GetBytes("\r\nConnection: close"); private static readonly byte[] _bytesConnectionKeepAlive = Encoding.ASCII.GetBytes("\r\nConnection: keep-alive"); @@ -472,45 +470,12 @@ namespace Microsoft.AspNet.Server.Kestrel.Http private void WriteChunked(ArraySegment data) { - SocketOutput.Write(BeginChunkBytes(data.Count), immediate: false); - SocketOutput.Write(data, immediate: false); - SocketOutput.Write(_endChunkBytes, immediate: true); + SocketOutput.Write(data, immediate: false, chunk: true); } private async Task WriteChunkedAsync(ArraySegment data, CancellationToken cancellationToken) { - await SocketOutput.WriteAsync(BeginChunkBytes(data.Count), immediate: false, cancellationToken: cancellationToken); - await SocketOutput.WriteAsync(data, immediate: false, cancellationToken: cancellationToken); - await SocketOutput.WriteAsync(_endChunkBytes, immediate: true, cancellationToken: cancellationToken); - } - - public static ArraySegment BeginChunkBytes(int dataCount) - { - var bytes = new byte[10] - { - _hex[((dataCount >> 0x1c) & 0x0f)], - _hex[((dataCount >> 0x18) & 0x0f)], - _hex[((dataCount >> 0x14) & 0x0f)], - _hex[((dataCount >> 0x10) & 0x0f)], - _hex[((dataCount >> 0x0c) & 0x0f)], - _hex[((dataCount >> 0x08) & 0x0f)], - _hex[((dataCount >> 0x04) & 0x0f)], - _hex[((dataCount >> 0x00) & 0x0f)], - (byte)'\r', - (byte)'\n', - }; - - // Determine the most-significant non-zero nibble - int total, shift; - total = (dataCount > 0xffff) ? 0x10 : 0x00; - dataCount >>= total; - shift = (dataCount > 0x00ff) ? 0x08 : 0x00; - dataCount >>= shift; - total |= shift; - total |= (dataCount > 0x000f) ? 0x04 : 0x00; - - var offset = 7 - (total >> 2); - return new ArraySegment(bytes, offset, 10 - offset); + await SocketOutput.WriteAsync(data, immediate: false, chunk: true, cancellationToken: cancellationToken); } private void WriteChunkedResponseSuffix() diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/ISocketOutput.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/ISocketOutput.cs index 597326ca82..4d9a083576 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/ISocketOutput.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/ISocketOutput.cs @@ -13,8 +13,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http /// public interface ISocketOutput { - void Write(ArraySegment buffer, bool immediate = true); - Task WriteAsync(ArraySegment buffer, bool immediate = true, CancellationToken cancellationToken = default(CancellationToken)); + void Write(ArraySegment buffer, bool immediate = true, bool chunk = false); + Task WriteAsync(ArraySegment buffer, bool immediate = true, bool chunk = false, CancellationToken cancellationToken = default(CancellationToken)); /// /// Returns an iterator pointing to the tail of the response buffer. Response data can be appended diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs index 49f3a33eaf..cf3f8dc528 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs @@ -30,7 +30,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http private readonly IKestrelTrace _log; private readonly IThreadPool _threadPool; - // This locks all access to _tail, _isProducing and _returnFromOnProducingComplete. + // This locks all access to _tail and _lastStart. // _head does not require a lock, since it is only used in the ctor and uv thread. private readonly object _returnLock = new object(); @@ -79,6 +79,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http public Task WriteAsync( ArraySegment buffer, bool immediate = true, + bool chunk = false, bool socketShutdownSend = false, bool socketDisconnect = false) { @@ -90,7 +91,19 @@ namespace Microsoft.AspNet.Server.Kestrel.Http if (buffer.Count > 0) { var tail = ProducingStart(); + if (chunk) + { + _numBytesPreCompleted += ChunkWriter.WriteBeginChunkBytes(ref tail, buffer.Count); + } + tail.CopyFrom(buffer); + + if (chunk) + { + ChunkWriter.WriteEndChunkBytes(ref tail); + _numBytesPreCompleted += 2; + } + // We do our own accounting below ProducingCompleteNoPreComplete(tail); } @@ -359,9 +372,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } - void ISocketOutput.Write(ArraySegment buffer, bool immediate) + void ISocketOutput.Write(ArraySegment buffer, bool immediate, bool chunk) { - var task = WriteAsync(buffer, immediate); + var task = WriteAsync(buffer, immediate, chunk); if (task.Status == TaskStatus.RanToCompletion) { @@ -373,9 +386,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } - Task ISocketOutput.WriteAsync(ArraySegment buffer, bool immediate, CancellationToken cancellationToken) + Task ISocketOutput.WriteAsync(ArraySegment buffer, bool immediate, bool chunk, CancellationToken cancellationToken) { - return WriteAsync(buffer, immediate); + return WriteAsync(buffer, immediate, chunk); } private static void BytesBetween(MemoryPoolIterator2 start, MemoryPoolIterator2 end, out int bytes, out int buffers) diff --git a/test/Microsoft.AspNet.Server.KestrelTests/ChunkWriterTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/ChunkWriterTests.cs new file mode 100644 index 0000000000..3a2dd71030 --- /dev/null +++ b/test/Microsoft.AspNet.Server.KestrelTests/ChunkWriterTests.cs @@ -0,0 +1,38 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System.Linq; +using System.Text; +using Microsoft.AspNet.Server.Kestrel.Http; +using Xunit; + +namespace Microsoft.AspNet.Server.KestrelTests +{ + public class ChunkWriterTests + { + [Theory] + [InlineData(1, "1\r\n")] + [InlineData(10, "a\r\n")] + [InlineData(0x08, "8\r\n")] + [InlineData(0x10, "10\r\n")] + [InlineData(0x080, "80\r\n")] + [InlineData(0x100, "100\r\n")] + [InlineData(0x0800, "800\r\n")] + [InlineData(0x1000, "1000\r\n")] + [InlineData(0x08000, "8000\r\n")] + [InlineData(0x10000, "10000\r\n")] + [InlineData(0x080000, "80000\r\n")] + [InlineData(0x100000, "100000\r\n")] + [InlineData(0x0800000, "800000\r\n")] + [InlineData(0x1000000, "1000000\r\n")] + [InlineData(0x08000000, "8000000\r\n")] + [InlineData(0x10000000, "10000000\r\n")] + [InlineData(0x7fffffffL, "7fffffff\r\n")] + public void ChunkedPrefixMustBeHexCrLfWithoutLeadingZeros(int dataCount, string expected) + { + var beginChunkBytes = ChunkWriter.BeginChunkBytes(dataCount); + + Assert.Equal(Encoding.ASCII.GetBytes(expected), beginChunkBytes.ToArray()); + } + } +} diff --git a/test/Microsoft.AspNet.Server.KestrelTests/FrameTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/FrameTests.cs index 793084ef55..5960510eff 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/FrameTests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/FrameTests.cs @@ -13,31 +13,6 @@ namespace Microsoft.AspNet.Server.KestrelTests { public class FrameTests { - [Theory] - [InlineData(1, "1\r\n")] - [InlineData(10, "a\r\n")] - [InlineData(0x08, "8\r\n")] - [InlineData(0x10, "10\r\n")] - [InlineData(0x080, "80\r\n")] - [InlineData(0x100, "100\r\n")] - [InlineData(0x0800, "800\r\n")] - [InlineData(0x1000, "1000\r\n")] - [InlineData(0x08000, "8000\r\n")] - [InlineData(0x10000, "10000\r\n")] - [InlineData(0x080000, "80000\r\n")] - [InlineData(0x100000, "100000\r\n")] - [InlineData(0x0800000, "800000\r\n")] - [InlineData(0x1000000, "1000000\r\n")] - [InlineData(0x08000000, "8000000\r\n")] - [InlineData(0x10000000, "10000000\r\n")] - [InlineData(0x7fffffffL, "7fffffff\r\n")] - public void ChunkedPrefixMustBeHexCrLfWithoutLeadingZeros(int dataCount, string expected) - { - var beginChunkBytes = Frame.BeginChunkBytes(dataCount); - - Assert.Equal(Encoding.ASCII.GetBytes(expected), beginChunkBytes.ToArray()); - } - [Theory] [InlineData("Cookie: \r\n\r\n", 1)] [InlineData("Cookie:\r\n\r\n", 1)] From caaf9d473b6ad48ace098e37dacea99540aecdc6 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Wed, 23 Dec 2015 08:38:48 +0000 Subject: [PATCH 0567/1662] Faster CopyFrom --- .../Http/Connection.cs | 2 +- .../Http/SocketInput.cs | 2 +- .../Http/SocketOutput.cs | 2 +- .../Infrastructure/MemoryPoolBlock2.cs | 6 + .../Infrastructure/MemoryPoolIterator2.cs | 195 ++++++++++++------ .../Networking/UvWriteReq.cs | 2 +- .../MemoryPoolBlock2Tests.cs | 2 +- .../SocketOutputTests.cs | 4 +- 8 files changed, 143 insertions(+), 72 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs index 6f2ea40f27..a93b0794ee 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs @@ -144,7 +144,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return handle.Libuv.buf_init( result.Pin() + result.End, - result.Data.Offset + result.Data.Count - result.End); + result.BlockEndOffset - result.End); } private static void ReadCallback(UvStreamHandle handle, int status, object state) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketInput.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketInput.cs index 944457af60..37641d7df4 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketInput.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketInput.cs @@ -42,7 +42,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { const int minimumSize = 2048; - if (_tail != null && minimumSize <= _tail.Data.Offset + _tail.Data.Count - _tail.End) + if (_tail != null && minimumSize <= _tail.BlockEndOffset - _tail.End) { _pinned = _tail; } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs index cf3f8dc528..c1b5bd0e63 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs @@ -400,7 +400,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return; } - bytes = start.Block.Data.Offset + start.Block.Data.Count - start.Index; + bytes = start.Block.BlockEndOffset - start.Index; buffers = 1; for (var block = start.Block.Next; block != end.Block; block = block.Next) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolBlock2.cs b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolBlock2.cs index 26156c6cc0..920b4e9e49 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolBlock2.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolBlock2.cs @@ -52,6 +52,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure /// public byte[] Array => Data.Array; + /// + /// Fixed end offset of the block + /// + public int BlockEndOffset { get; private set; } + /// /// The Start represents the offset into Array where the range of "active" bytes begins. At the point when the block is leased /// the Start is guaranteed to be equal to Array.Offset. The value of Start may be assigned anywhere between Data.Offset and @@ -144,6 +149,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure Slab = slab, Start = data.Offset, End = data.Offset, + BlockEndOffset = data.Offset + data.Count }; } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolIterator2.cs b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolIterator2.cs index c6326465f9..ec1d23d88a 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolIterator2.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolIterator2.cs @@ -692,46 +692,52 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure CopyFrom(buffer.Array, buffer.Offset, buffer.Count); } - public void CopyFrom(byte[] data, int offset, int count) + public unsafe void CopyFrom(byte[] data, int offset, int count) { Debug.Assert(_block != null); Debug.Assert(_block.Next == null); Debug.Assert(_block.End == _index); - - var pool = _block.Pool; + var block = _block; var blockIndex = _index; + var bytesLeftInBlock = block.BlockEndOffset - blockIndex; - var bufferIndex = offset; - var remaining = count; - var bytesLeftInBlock = block.Data.Offset + block.Data.Count - blockIndex; + if (bytesLeftInBlock >= count) + { + _index = blockIndex + count; + Buffer.BlockCopy(data, offset, block.Array, blockIndex, count); + block.End = _index; + return; + } - while (remaining > 0) + do { if (bytesLeftInBlock == 0) { - var nextBlock = pool.Lease(); - block.End = blockIndex; + var nextBlock = block.Pool.Lease(); + blockIndex = nextBlock.Data.Offset; + bytesLeftInBlock = nextBlock.Data.Count; block.Next = nextBlock; block = nextBlock; - - blockIndex = block.Data.Offset; - bytesLeftInBlock = block.Data.Count; } - var bytesToCopy = remaining < bytesLeftInBlock ? remaining : bytesLeftInBlock; - - Buffer.BlockCopy(data, bufferIndex, block.Array, blockIndex, bytesToCopy); - - blockIndex += bytesToCopy; - bufferIndex += bytesToCopy; - remaining -= bytesToCopy; - bytesLeftInBlock -= bytesToCopy; - } - - block.End = blockIndex; - _block = block; - _index = blockIndex; + if (count > bytesLeftInBlock) + { + count -= bytesLeftInBlock; + Buffer.BlockCopy(data, offset, block.Array, blockIndex, bytesLeftInBlock); + offset += bytesLeftInBlock; + block.End = blockIndex + bytesLeftInBlock; + bytesLeftInBlock = 0; + } + else + { + _index = blockIndex + count; + Buffer.BlockCopy(data, offset, block.Array, blockIndex, count); + block.End = _index; + _block = block; + return; + } + } while (true); } public unsafe void CopyFromAscii(string data) @@ -740,64 +746,123 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure Debug.Assert(_block.Next == null); Debug.Assert(_block.End == _index); - var pool = _block.Pool; var block = _block; var blockIndex = _index; - var length = data.Length; + var count = data.Length; - var bytesLeftInBlock = block.Data.Offset + block.Data.Count - blockIndex; - var bytesLeftInBlockMinusSpan = bytesLeftInBlock - 3; + var blockRemaining = block.BlockEndOffset - blockIndex; - fixed (char* pData = data) + fixed (char* pInput = data) { - var input = pData; - var inputEnd = pData + length; - var inputEndMinusSpan = inputEnd - 3; - - while (input < inputEnd) + if (blockRemaining >= count) { - if (bytesLeftInBlock == 0) + _index = blockIndex + count; + + fixed (byte* pOutput = &block.Data.Array[blockIndex]) { - var nextBlock = pool.Lease(); - block.End = blockIndex; + CopyFromAscii(pInput, pOutput, count); + } + + block.End = _index; + return; + } + + var input = pInput; + do + { + if (blockRemaining == 0) + { + var nextBlock = block.Pool.Lease(); + blockIndex = nextBlock.Data.Offset; + blockRemaining = nextBlock.Data.Count; block.Next = nextBlock; block = nextBlock; - - blockIndex = block.Data.Offset; - bytesLeftInBlock = block.Data.Count; - bytesLeftInBlockMinusSpan = bytesLeftInBlock - 3; } - fixed (byte* pOutput = &block.Data.Array[block.End]) + if (count > blockRemaining) { - //this line is needed to allow output be an register var - var output = pOutput; + count -= blockRemaining; - var copied = 0; - for (; input < inputEndMinusSpan && copied < bytesLeftInBlockMinusSpan; copied += 4) + fixed (byte* pOutput = &block.Data.Array[blockIndex]) { - *(output) = (byte)*(input); - *(output + 1) = (byte)*(input + 1); - *(output + 2) = (byte)*(input + 2); - *(output + 3) = (byte)*(input + 3); - output += 4; - input += 4; - } - for (; input < inputEnd && copied < bytesLeftInBlock; copied++) - { - *(output++) = (byte)*(input++); + CopyFromAscii(input, pOutput, blockRemaining); } - blockIndex += copied; - bytesLeftInBlockMinusSpan -= copied; - bytesLeftInBlock -= copied; + block.End = blockIndex + blockRemaining; + input += blockRemaining; + blockRemaining = 0; } - } - } + else + { + _index = blockIndex + count; - block.End = blockIndex; - _block = block; - _index = blockIndex; + fixed (byte* pOutput = &block.Data.Array[blockIndex]) + { + CopyFromAscii(input, pOutput, count); + } + + block.End = _index; + _block = block; + return; + } + } while (true); + } + } + + private unsafe static void CopyFromAscii(char* pInput, byte* pOutput, int count) + { + var i = 0; + //these line is needed to allow input/output be an register var + var input = pInput; + var output = pOutput; + + while (i < count - 11) + { + i += 12; + *(output) = (byte)*(input); + *(output + 1) = (byte)*(input + 1); + *(output + 2) = (byte)*(input + 2); + *(output + 3) = (byte)*(input + 3); + *(output + 4) = (byte)*(input + 4); + *(output + 5) = (byte)*(input + 5); + *(output + 6) = (byte)*(input + 6); + *(output + 7) = (byte)*(input + 7); + *(output + 8) = (byte)*(input + 8); + *(output + 9) = (byte)*(input + 9); + *(output + 10) = (byte)*(input + 10); + *(output + 11) = (byte)*(input + 11); + output += 12; + input += 12; + } + if (i < count - 5) + { + i += 6; + *(output) = (byte)*(input); + *(output + 1) = (byte)*(input + 1); + *(output + 2) = (byte)*(input + 2); + *(output + 3) = (byte)*(input + 3); + *(output + 4) = (byte)*(input + 4); + *(output + 5) = (byte)*(input + 5); + output += 6; + input += 6; + } + if (i < count - 3) + { + i += 4; + *(output) = (byte)*(input); + *(output + 1) = (byte)*(input + 1); + *(output + 2) = (byte)*(input + 2); + *(output + 3) = (byte)*(input + 3); + output += 4; + input += 4; + } + while (i < count) + { + i++; + *output = (byte)*input; + output++; + input++; + } } } } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvWriteReq.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvWriteReq.cs index 21a1aaf778..af8d334d27 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvWriteReq.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvWriteReq.cs @@ -66,7 +66,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking for (var index = 0; index < nBuffers; index++) { var blockStart = block == start.Block ? start.Index : block.Data.Offset; - var blockEnd = block == end.Block ? end.Index : block.Data.Offset + block.Data.Count; + var blockEnd = block == end.Block ? end.Index : block.BlockEndOffset; // create and pin each segment being written pBuffers[index] = Libuv.buf_init( diff --git a/test/Microsoft.AspNet.Server.KestrelTests/MemoryPoolBlock2Tests.cs b/test/Microsoft.AspNet.Server.KestrelTests/MemoryPoolBlock2Tests.cs index 2cbd077180..6edb835841 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/MemoryPoolBlock2Tests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/MemoryPoolBlock2Tests.cs @@ -248,7 +248,7 @@ namespace Microsoft.AspNet.Server.KestrelTests Assert.Null(block1.Next); - end.CopyFrom(new ArraySegment(buffer)); + end.CopyFrom(buffer, 0, buffer.Length); Assert.NotNull(block1.Next); diff --git a/test/Microsoft.AspNet.Server.KestrelTests/SocketOutputTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/SocketOutputTests.cs index bda6bfb651..927194ac5c 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/SocketOutputTests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/SocketOutputTests.cs @@ -308,11 +308,11 @@ namespace Microsoft.AspNet.Server.KestrelTests // block 1 var start = socketOutput.ProducingStart(); - start.Block.End = start.Block.Data.Offset + start.Block.Data.Count; + start.Block.End = start.Block.BlockEndOffset; // block 2 var block2 = memory.Lease(); - block2.End = block2.Data.Offset + block2.Data.Count; + block2.End = block2.BlockEndOffset; start.Block.Next = block2; var end = new MemoryPoolIterator2(block2, block2.End); From e5ad0195754f247879e0ed4d5dc43825078e1850 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Thu, 14 Jan 2016 11:47:23 -0800 Subject: [PATCH 0568/1662] Revert "Merge branch 'benaadams/copyfrom-perf' into dev" This reverts commit ce6128232091a34ae3f387087943093e68bdfb02, reversing changes made to 7ef70bc145a96c4188db22a23b8a82f665d41261. --- .../Http/Connection.cs | 2 +- .../Http/SocketInput.cs | 2 +- .../Http/SocketOutput.cs | 2 +- .../Infrastructure/MemoryPoolBlock2.cs | 6 - .../Infrastructure/MemoryPoolIterator2.cs | 195 ++++++------------ .../Networking/UvWriteReq.cs | 2 +- .../MemoryPoolBlock2Tests.cs | 2 +- .../SocketOutputTests.cs | 4 +- 8 files changed, 72 insertions(+), 143 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs index a93b0794ee..6f2ea40f27 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs @@ -144,7 +144,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return handle.Libuv.buf_init( result.Pin() + result.End, - result.BlockEndOffset - result.End); + result.Data.Offset + result.Data.Count - result.End); } private static void ReadCallback(UvStreamHandle handle, int status, object state) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketInput.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketInput.cs index 37641d7df4..944457af60 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketInput.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketInput.cs @@ -42,7 +42,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { const int minimumSize = 2048; - if (_tail != null && minimumSize <= _tail.BlockEndOffset - _tail.End) + if (_tail != null && minimumSize <= _tail.Data.Offset + _tail.Data.Count - _tail.End) { _pinned = _tail; } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs index c1b5bd0e63..cf3f8dc528 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs @@ -400,7 +400,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return; } - bytes = start.Block.BlockEndOffset - start.Index; + bytes = start.Block.Data.Offset + start.Block.Data.Count - start.Index; buffers = 1; for (var block = start.Block.Next; block != end.Block; block = block.Next) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolBlock2.cs b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolBlock2.cs index 920b4e9e49..26156c6cc0 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolBlock2.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolBlock2.cs @@ -52,11 +52,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure /// public byte[] Array => Data.Array; - /// - /// Fixed end offset of the block - /// - public int BlockEndOffset { get; private set; } - /// /// The Start represents the offset into Array where the range of "active" bytes begins. At the point when the block is leased /// the Start is guaranteed to be equal to Array.Offset. The value of Start may be assigned anywhere between Data.Offset and @@ -149,7 +144,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure Slab = slab, Start = data.Offset, End = data.Offset, - BlockEndOffset = data.Offset + data.Count }; } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolIterator2.cs b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolIterator2.cs index 193df3ea62..37e18389ff 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolIterator2.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolIterator2.cs @@ -722,52 +722,46 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure CopyFrom(buffer.Array, buffer.Offset, buffer.Count); } - public unsafe void CopyFrom(byte[] data, int offset, int count) + public void CopyFrom(byte[] data, int offset, int count) { Debug.Assert(_block != null); Debug.Assert(_block.Next == null); Debug.Assert(_block.End == _index); - + + var pool = _block.Pool; var block = _block; var blockIndex = _index; - var bytesLeftInBlock = block.BlockEndOffset - blockIndex; - if (bytesLeftInBlock >= count) - { - _index = blockIndex + count; - Buffer.BlockCopy(data, offset, block.Array, blockIndex, count); - block.End = _index; - return; - } + var bufferIndex = offset; + var remaining = count; + var bytesLeftInBlock = block.Data.Offset + block.Data.Count - blockIndex; - do + while (remaining > 0) { if (bytesLeftInBlock == 0) { - var nextBlock = block.Pool.Lease(); - blockIndex = nextBlock.Data.Offset; - bytesLeftInBlock = nextBlock.Data.Count; + var nextBlock = pool.Lease(); + block.End = blockIndex; block.Next = nextBlock; block = nextBlock; + + blockIndex = block.Data.Offset; + bytesLeftInBlock = block.Data.Count; } - if (count > bytesLeftInBlock) - { - count -= bytesLeftInBlock; - Buffer.BlockCopy(data, offset, block.Array, blockIndex, bytesLeftInBlock); - offset += bytesLeftInBlock; - block.End = blockIndex + bytesLeftInBlock; - bytesLeftInBlock = 0; - } - else - { - _index = blockIndex + count; - Buffer.BlockCopy(data, offset, block.Array, blockIndex, count); - block.End = _index; - _block = block; - return; - } - } while (true); + var bytesToCopy = remaining < bytesLeftInBlock ? remaining : bytesLeftInBlock; + + Buffer.BlockCopy(data, bufferIndex, block.Array, blockIndex, bytesToCopy); + + blockIndex += bytesToCopy; + bufferIndex += bytesToCopy; + remaining -= bytesToCopy; + bytesLeftInBlock -= bytesToCopy; + } + + block.End = blockIndex; + _block = block; + _index = blockIndex; } public unsafe void CopyFromAscii(string data) @@ -776,123 +770,64 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure Debug.Assert(_block.Next == null); Debug.Assert(_block.End == _index); + var pool = _block.Pool; var block = _block; var blockIndex = _index; - var count = data.Length; + var length = data.Length; - var blockRemaining = block.BlockEndOffset - blockIndex; + var bytesLeftInBlock = block.Data.Offset + block.Data.Count - blockIndex; + var bytesLeftInBlockMinusSpan = bytesLeftInBlock - 3; - fixed (char* pInput = data) + fixed (char* pData = data) { - if (blockRemaining >= count) + var input = pData; + var inputEnd = pData + length; + var inputEndMinusSpan = inputEnd - 3; + + while (input < inputEnd) { - _index = blockIndex + count; - - fixed (byte* pOutput = &block.Data.Array[blockIndex]) + if (bytesLeftInBlock == 0) { - CopyFromAscii(pInput, pOutput, count); - } - - block.End = _index; - return; - } - - var input = pInput; - do - { - if (blockRemaining == 0) - { - var nextBlock = block.Pool.Lease(); - blockIndex = nextBlock.Data.Offset; - blockRemaining = nextBlock.Data.Count; + var nextBlock = pool.Lease(); + block.End = blockIndex; block.Next = nextBlock; block = nextBlock; + + blockIndex = block.Data.Offset; + bytesLeftInBlock = block.Data.Count; + bytesLeftInBlockMinusSpan = bytesLeftInBlock - 3; } - if (count > blockRemaining) + fixed (byte* pOutput = &block.Data.Array[block.End]) { - count -= blockRemaining; + //this line is needed to allow output be an register var + var output = pOutput; - fixed (byte* pOutput = &block.Data.Array[blockIndex]) + var copied = 0; + for (; input < inputEndMinusSpan && copied < bytesLeftInBlockMinusSpan; copied += 4) { - CopyFromAscii(input, pOutput, blockRemaining); + *(output) = (byte)*(input); + *(output + 1) = (byte)*(input + 1); + *(output + 2) = (byte)*(input + 2); + *(output + 3) = (byte)*(input + 3); + output += 4; + input += 4; + } + for (; input < inputEnd && copied < bytesLeftInBlock; copied++) + { + *(output++) = (byte)*(input++); } - block.End = blockIndex + blockRemaining; - input += blockRemaining; - blockRemaining = 0; + blockIndex += copied; + bytesLeftInBlockMinusSpan -= copied; + bytesLeftInBlock -= copied; } - else - { - _index = blockIndex + count; + } + } - fixed (byte* pOutput = &block.Data.Array[blockIndex]) - { - CopyFromAscii(input, pOutput, count); - } - - block.End = _index; - _block = block; - return; - } - } while (true); - } - } - - private unsafe static void CopyFromAscii(char* pInput, byte* pOutput, int count) - { - var i = 0; - //these line is needed to allow input/output be an register var - var input = pInput; - var output = pOutput; - - while (i < count - 11) - { - i += 12; - *(output) = (byte)*(input); - *(output + 1) = (byte)*(input + 1); - *(output + 2) = (byte)*(input + 2); - *(output + 3) = (byte)*(input + 3); - *(output + 4) = (byte)*(input + 4); - *(output + 5) = (byte)*(input + 5); - *(output + 6) = (byte)*(input + 6); - *(output + 7) = (byte)*(input + 7); - *(output + 8) = (byte)*(input + 8); - *(output + 9) = (byte)*(input + 9); - *(output + 10) = (byte)*(input + 10); - *(output + 11) = (byte)*(input + 11); - output += 12; - input += 12; - } - if (i < count - 5) - { - i += 6; - *(output) = (byte)*(input); - *(output + 1) = (byte)*(input + 1); - *(output + 2) = (byte)*(input + 2); - *(output + 3) = (byte)*(input + 3); - *(output + 4) = (byte)*(input + 4); - *(output + 5) = (byte)*(input + 5); - output += 6; - input += 6; - } - if (i < count - 3) - { - i += 4; - *(output) = (byte)*(input); - *(output + 1) = (byte)*(input + 1); - *(output + 2) = (byte)*(input + 2); - *(output + 3) = (byte)*(input + 3); - output += 4; - input += 4; - } - while (i < count) - { - i++; - *output = (byte)*input; - output++; - input++; - } + block.End = blockIndex; + _block = block; + _index = blockIndex; } } } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvWriteReq.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvWriteReq.cs index af8d334d27..21a1aaf778 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvWriteReq.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvWriteReq.cs @@ -66,7 +66,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking for (var index = 0; index < nBuffers; index++) { var blockStart = block == start.Block ? start.Index : block.Data.Offset; - var blockEnd = block == end.Block ? end.Index : block.BlockEndOffset; + var blockEnd = block == end.Block ? end.Index : block.Data.Offset + block.Data.Count; // create and pin each segment being written pBuffers[index] = Libuv.buf_init( diff --git a/test/Microsoft.AspNet.Server.KestrelTests/MemoryPoolBlock2Tests.cs b/test/Microsoft.AspNet.Server.KestrelTests/MemoryPoolBlock2Tests.cs index 6edb835841..2cbd077180 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/MemoryPoolBlock2Tests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/MemoryPoolBlock2Tests.cs @@ -248,7 +248,7 @@ namespace Microsoft.AspNet.Server.KestrelTests Assert.Null(block1.Next); - end.CopyFrom(buffer, 0, buffer.Length); + end.CopyFrom(new ArraySegment(buffer)); Assert.NotNull(block1.Next); diff --git a/test/Microsoft.AspNet.Server.KestrelTests/SocketOutputTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/SocketOutputTests.cs index 927194ac5c..bda6bfb651 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/SocketOutputTests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/SocketOutputTests.cs @@ -308,11 +308,11 @@ namespace Microsoft.AspNet.Server.KestrelTests // block 1 var start = socketOutput.ProducingStart(); - start.Block.End = start.Block.BlockEndOffset; + start.Block.End = start.Block.Data.Offset + start.Block.Data.Count; // block 2 var block2 = memory.Lease(); - block2.End = block2.BlockEndOffset; + block2.End = block2.Data.Offset + block2.Data.Count; start.Block.Next = block2; var end = new MemoryPoolIterator2(block2, block2.End); From 129a5ad47409d0b35dee6621f876f767b7f79874 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Wed, 13 Jan 2016 10:42:42 -0800 Subject: [PATCH 0569/1662] Bypass LibuvStream if no ConnectionFilter wraps it --- .../Properties/AssemblyInfo.cs | 1 + .../Http/Connection.cs | 19 ++++++++++++++----- .../EngineTests.cs | 15 ++++++++++++--- 3 files changed, 27 insertions(+), 8 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel.Https/Properties/AssemblyInfo.cs b/src/Microsoft.AspNet.Server.Kestrel.Https/Properties/AssemblyInfo.cs index 7c3af07032..a8f71a20f0 100644 --- a/src/Microsoft.AspNet.Server.Kestrel.Https/Properties/AssemblyInfo.cs +++ b/src/Microsoft.AspNet.Server.Kestrel.Https/Properties/AssemblyInfo.cs @@ -5,5 +5,6 @@ using System.Reflection; using System.Resources; using System.Runtime.CompilerServices; +[assembly: InternalsVisibleTo("Microsoft.AspNet.Server.KestrelTests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")] [assembly: AssemblyMetadata("Serviceable", "True")] [assembly: NeutralResourcesLanguage("en-us")] diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs index 6f2ea40f27..96b6c0b93a 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs @@ -23,6 +23,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http private readonly UvStreamHandle _socket; private Frame _frame; private ConnectionFilterContext _filterContext; + private LibuvStream _libuvStream; private readonly long _connectionId; private readonly SocketInput _rawSocketInput; @@ -70,11 +71,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } else { - var libuvStream = new LibuvStream(_rawSocketInput, _rawSocketOutput); + _libuvStream = new LibuvStream(_rawSocketInput, _rawSocketOutput); _filterContext = new ConnectionFilterContext { - Connection = libuvStream, + Connection = _libuvStream, Address = ServerAddress }; @@ -124,10 +125,18 @@ namespace Microsoft.AspNet.Server.Kestrel.Http private void ApplyConnectionFilter() { - var filteredStreamAdapter = new FilteredStreamAdapter(_filterContext.Connection, Memory2, Log, ThreadPool); + if (_filterContext.Connection != _libuvStream) + { + var filteredStreamAdapter = new FilteredStreamAdapter(_filterContext.Connection, Memory2, Log, ThreadPool); - SocketInput = filteredStreamAdapter.SocketInput; - SocketOutput = filteredStreamAdapter.SocketOutput; + SocketInput = filteredStreamAdapter.SocketInput; + SocketOutput = filteredStreamAdapter.SocketOutput; + } + else + { + SocketInput = _rawSocketInput; + SocketOutput = _rawSocketOutput; + } _frame = CreateFrame(); _frame.Start(); diff --git a/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs index 76b65c58f1..b18736daa8 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs @@ -2,8 +2,8 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.Linq; using System.IO; +using System.Linq; using System.Net; using System.Net.Sockets; using System.Text; @@ -13,7 +13,7 @@ using Microsoft.AspNet.Http; using Microsoft.AspNet.Http.Features; using Microsoft.AspNet.Server.Kestrel; using Microsoft.AspNet.Server.Kestrel.Filter; -using Microsoft.AspNet.Server.Kestrel.Http; +using Microsoft.AspNet.Server.Kestrel.Infrastructure; using Microsoft.AspNet.Testing.xunit; using Microsoft.Extensions.Logging; using Xunit; @@ -37,7 +37,7 @@ namespace Microsoft.AspNet.Server.KestrelTests { new TestServiceContext { - ConnectionFilter = new NoOpConnectionFilter() + ConnectionFilter = new PassThroughConnectionFilter() } } }; @@ -1177,5 +1177,14 @@ namespace Microsoft.AspNet.Server.KestrelTests } } } + + private class PassThroughConnectionFilter : IConnectionFilter + { + public Task OnConnectionAsync(ConnectionFilterContext context) + { + context.Connection = new LoggingStream(context.Connection, new TestApplicationErrorLogger()); + return TaskUtilities.CompletedTask; + } + } } } From 9885377148e9d50ec45f9c7ca44c8b645a415f6b Mon Sep 17 00:00:00 2001 From: John Luo Date: Sun, 17 Jan 2016 16:13:21 -0800 Subject: [PATCH 0570/1662] Reacting to hosting rename --- samples/LargeResponseApp/Startup.cs | 6 +++--- samples/SampleApp/Startup.cs | 7 +++---- samples/SampleApp/wwwroot/web.config | 9 --------- .../AddressRegistrationTests.cs | 6 +++--- .../PathBaseTests.cs | 6 +++--- .../RequestTests.cs | 18 +++++++++--------- .../ResponseTests.cs | 18 +++++++++--------- .../ThreadCountTests.cs | 6 +++--- 8 files changed, 33 insertions(+), 43 deletions(-) delete mode 100644 samples/SampleApp/wwwroot/web.config diff --git a/samples/LargeResponseApp/Startup.cs b/samples/LargeResponseApp/Startup.cs index 5052e96f59..241d754a38 100644 --- a/samples/LargeResponseApp/Startup.cs +++ b/samples/LargeResponseApp/Startup.cs @@ -38,12 +38,12 @@ namespace LargeResponseApp public static void Main(string[] args) { - var application = new WebApplicationBuilder() - .UseConfiguration(WebApplicationConfiguration.GetDefault(args)) + var host = new WebHostBuilder() + .UseDefaultConfiguration(args) .UseStartup() .Build(); - application.Run(); + host.Run(); } } } diff --git a/samples/SampleApp/Startup.cs b/samples/SampleApp/Startup.cs index 8d4b97eda7..5ff5a14fa5 100644 --- a/samples/SampleApp/Startup.cs +++ b/samples/SampleApp/Startup.cs @@ -7,7 +7,6 @@ using System.Security.Cryptography.X509Certificates; using Microsoft.AspNet.Builder; using Microsoft.AspNet.Hosting; using Microsoft.AspNet.Http; -using Microsoft.AspNet.Http.Features; using Microsoft.AspNet.Server.Kestrel; using Microsoft.AspNet.Server.Kestrel.Filter; using Microsoft.Extensions.Logging; @@ -65,8 +64,8 @@ namespace SampleApp public static void Main(string[] args) { - var application = new WebApplicationBuilder() - .UseConfiguration(WebApplicationConfiguration.GetDefault(args)) + var host = new WebHostBuilder() + .UseDefaultConfiguration(args) .UseStartup() .Build(); @@ -75,7 +74,7 @@ namespace SampleApp //addresses.Clear(); //addresses.Add("http://unix:/tmp/kestrel-test.sock"); - application.Run(); + host.Run(); } } } \ No newline at end of file diff --git a/samples/SampleApp/wwwroot/web.config b/samples/SampleApp/wwwroot/web.config deleted file mode 100644 index 9a0d90abf8..0000000000 --- a/samples/SampleApp/wwwroot/web.config +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - \ No newline at end of file diff --git a/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs b/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs index 6a936ea3db..c553af03b0 100644 --- a/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs +++ b/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs @@ -40,14 +40,14 @@ namespace Microsoft.AspNet.Server.Kestrel.FunctionalTests }) .Build(); - var applicationBuilder = new WebApplicationBuilder() + var hostBuilder = new WebHostBuilder() .UseConfiguration(config) .UseServer("Microsoft.AspNet.Server.Kestrel") .Configure(ConfigureEchoAddress); - using (var app = applicationBuilder.Build()) + using (var host = hostBuilder.Build()) { - app.Start(); + host.Start(); using (var client = new HttpClient()) { diff --git a/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/PathBaseTests.cs b/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/PathBaseTests.cs index ddad81932e..e44a651c4c 100644 --- a/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/PathBaseTests.cs +++ b/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/PathBaseTests.cs @@ -79,7 +79,7 @@ namespace Microsoft.AspNet.Server.Kestrel.FunctionalTests { "server.urls", registerAddress } }).Build(); - var builder = new WebApplicationBuilder() + var builder = new WebHostBuilder() .UseConfiguration(config) .UseServer("Microsoft.AspNet.Server.Kestrel") .Configure(app => @@ -94,9 +94,9 @@ namespace Microsoft.AspNet.Server.Kestrel.FunctionalTests }); }); - using (var app = builder.Build()) + using (var host = builder.Build()) { - app.Start(); + host.Start(); using (var client = new HttpClient()) { diff --git a/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/RequestTests.cs b/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/RequestTests.cs index 623e85c8ff..fdba322cb3 100644 --- a/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/RequestTests.cs +++ b/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/RequestTests.cs @@ -29,7 +29,7 @@ namespace Microsoft.AspNet.Server.Kestrel.FunctionalTests }) .Build(); - var applicationBuilder = new WebApplicationBuilder() + var builder = new WebHostBuilder() .UseConfiguration(config) .UseServer("Microsoft.AspNet.Server.Kestrel") .Configure(app => @@ -54,9 +54,9 @@ namespace Microsoft.AspNet.Server.Kestrel.FunctionalTests }); }); - using (var app = applicationBuilder.Build()) + using (var host = builder.Build()) { - app.Start(); + host.Start(); using (var client = new HttpClient()) { @@ -100,7 +100,7 @@ namespace Microsoft.AspNet.Server.Kestrel.FunctionalTests { "server.urls", "http://localhost:8791" } }).Build(); - var builder = new WebApplicationBuilder() + var builder = new WebHostBuilder() .UseConfiguration(config) .UseServer("Microsoft.AspNet.Server.Kestrel") .Configure(app => @@ -112,10 +112,10 @@ namespace Microsoft.AspNet.Server.Kestrel.FunctionalTests }); }); - using (var app = builder.Build()) + using (var host = builder.Build()) using (var client = new HttpClient()) { - app.Start(); + host.Start(); client.DefaultRequestHeaders.Connection.Clear(); client.DefaultRequestHeaders.Connection.Add("close"); @@ -132,7 +132,7 @@ namespace Microsoft.AspNet.Server.Kestrel.FunctionalTests { "server.urls", $"http://{registerAddress}:{port}" } }).Build(); - var builder = new WebApplicationBuilder() + var builder = new WebHostBuilder() .UseConfiguration(config) .UseServer("Microsoft.AspNet.Server.Kestrel") .Configure(app => @@ -151,10 +151,10 @@ namespace Microsoft.AspNet.Server.Kestrel.FunctionalTests }); }); - using (var app = builder.Build()) + using (var host = builder.Build()) using (var client = new HttpClient()) { - app.Start(); + host.Start(); var response = await client.GetAsync($"http://{requestAddress}:{port}/"); response.EnsureSuccessStatusCode(); diff --git a/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/ResponseTests.cs b/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/ResponseTests.cs index 993ea06aa7..d4f6b529aa 100644 --- a/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/ResponseTests.cs +++ b/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/ResponseTests.cs @@ -30,7 +30,7 @@ namespace Microsoft.AspNet.Server.Kestrel.FunctionalTests }) .Build(); - var applicationBuilder = new WebApplicationBuilder() + var hostBuilder = new WebHostBuilder() .UseConfiguration(config) .UseServer("Microsoft.AspNet.Server.Kestrel") .Configure(app => @@ -52,9 +52,9 @@ namespace Microsoft.AspNet.Server.Kestrel.FunctionalTests }); }); - using (var app = applicationBuilder.Build()) + using (var host = hostBuilder.Build()) { - app.Start(); + host.Start(); using (var client = new HttpClient()) { @@ -90,7 +90,7 @@ namespace Microsoft.AspNet.Server.Kestrel.FunctionalTests }) .Build(); - var hostBuilder = new WebApplicationBuilder() + var hostBuilder = new WebHostBuilder() .UseConfiguration(config) .UseServer("Microsoft.AspNet.Server.Kestrel") .Configure(app => @@ -103,9 +103,9 @@ namespace Microsoft.AspNet.Server.Kestrel.FunctionalTests }); }); - using (var app = hostBuilder.Build()) + using (var host = hostBuilder.Build()) { - app.Start(); + host.Start(); using (var client = new HttpClient()) { @@ -141,7 +141,7 @@ namespace Microsoft.AspNet.Server.Kestrel.FunctionalTests var onStartingCalled = false; var onCompletedCalled = false; - var hostBuilder = new WebApplicationBuilder() + var hostBuilder = new WebHostBuilder() .UseConfiguration(config) .UseServer("Microsoft.AspNet.Server.Kestrel") .Configure(app => @@ -156,9 +156,9 @@ namespace Microsoft.AspNet.Server.Kestrel.FunctionalTests }); }); - using (var app = hostBuilder.Build()) + using (var host = hostBuilder.Build()) { - app.Start(); + host.Start(); using (var client = new HttpClient()) { diff --git a/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/ThreadCountTests.cs b/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/ThreadCountTests.cs index a56fa6b47c..0d4324926b 100644 --- a/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/ThreadCountTests.cs +++ b/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/ThreadCountTests.cs @@ -23,7 +23,7 @@ namespace Microsoft.AspNet.Server.Kestrel.FunctionalTests }) .Build(); - var applicationBuilder = new WebApplicationBuilder() + var hostBuilder = new WebHostBuilder() .UseConfiguration(config) .UseServer("Microsoft.AspNet.Server.Kestrel") .Configure(app => @@ -36,9 +36,9 @@ namespace Microsoft.AspNet.Server.Kestrel.FunctionalTests }); }); - using (var app = applicationBuilder.Build()) + using (var host = hostBuilder.Build()) { - app.Start(); + host.Start(); using (var client = new HttpClient()) { From d3d9c8d546cfff445ecc234b493d723a13a0a5d1 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Sat, 16 Jan 2016 23:57:59 +0000 Subject: [PATCH 0571/1662] Write async chunks async --- .../Http/Frame.cs | 37 +++++++++++-------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs index f315bb702b..54cc69855f 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs @@ -421,7 +421,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { return; } - WriteChunked(data); + WriteChunkedAsync(data, RequestAborted).GetAwaiter().GetResult(); } else { @@ -468,19 +468,14 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } - private void WriteChunked(ArraySegment data) + private Task WriteChunkedAsync(ArraySegment data, CancellationToken cancellationToken) { - SocketOutput.Write(data, immediate: false, chunk: true); + return SocketOutput.WriteAsync(data, immediate: false, chunk: true, cancellationToken: cancellationToken); } - private async Task WriteChunkedAsync(ArraySegment data, CancellationToken cancellationToken) + private Task WriteChunkedResponseSuffix() { - await SocketOutput.WriteAsync(data, immediate: false, chunk: true, cancellationToken: cancellationToken); - } - - private void WriteChunkedResponseSuffix() - { - SocketOutput.Write(_endChunkedResponseBytes, immediate: true); + return SocketOutput.WriteAsync(_endChunkedResponseBytes, immediate: true); } private static ArraySegment CreateAsciiByteArraySegment(string text) @@ -571,31 +566,41 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return ProduceEndAwaited(); } - WriteSuffix(); - - return TaskUtilities.CompletedTask; + return WriteSuffix(); } private async Task ProduceEndAwaited() { await ProduceStart(immediate: true, appCompleted: true); - WriteSuffix(); + await WriteSuffix(); } - private void WriteSuffix() + private Task WriteSuffix() { // _autoChunk should be checked after we are sure ProduceStart() has been called // since ProduceStart() may set _autoChunk to true. if (_autoChunk) { - WriteChunkedResponseSuffix(); + return WriteAutoChunkSuffixAwaited(); } if (_keepAlive) { ConnectionControl.End(ProduceEndType.ConnectionKeepAlive); } + + return TaskUtilities.CompletedTask; + } + + private async Task WriteAutoChunkSuffixAwaited() + { + await WriteChunkedResponseSuffix(); + + if (_keepAlive) + { + ConnectionControl.End(ProduceEndType.ConnectionKeepAlive); + } } private Task CreateResponseHeader( From 63cd6149d1e3ac5a38b14906a2af787b385b2768 Mon Sep 17 00:00:00 2001 From: Brennan Date: Fri, 15 Jan 2016 16:07:10 -0800 Subject: [PATCH 0572/1662] Removed IsLocal from ConnectionInfo --- samples/SampleApp/Startup.cs | 1 - .../Http/Frame.FeatureCollection.cs | 2 -- src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs | 9 --------- .../RequestTests.cs | 4 +--- 4 files changed, 1 insertion(+), 15 deletions(-) diff --git a/samples/SampleApp/Startup.cs b/samples/SampleApp/Startup.cs index 5ff5a14fa5..830e6283a6 100644 --- a/samples/SampleApp/Startup.cs +++ b/samples/SampleApp/Startup.cs @@ -54,7 +54,6 @@ namespace SampleApp var connectionFeature = context.Connection; Console.WriteLine($"Peer: {connectionFeature.RemoteIpAddress?.ToString()} {connectionFeature.RemotePort}"); Console.WriteLine($"Sock: {connectionFeature.LocalIpAddress?.ToString()} {connectionFeature.LocalPort}"); - Console.WriteLine($"IsLocal: {connectionFeature.IsLocal}"); context.Response.ContentLength = 11; context.Response.ContentType = "text/plain"; diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.FeatureCollection.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.FeatureCollection.cs index 22e320e72f..91aa90eb37 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.FeatureCollection.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.FeatureCollection.cs @@ -272,8 +272,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Http int IHttpConnectionFeature.LocalPort { get; set; } - bool IHttpConnectionFeature.IsLocal { get; set; } - object IFeatureCollection.this[Type key] { get { return FastFeatureGet(key); } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs index f315bb702b..3ea812fd14 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs @@ -233,15 +233,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Http httpConnectionFeature.LocalIpAddress = _localEndPoint?.Address; httpConnectionFeature.LocalPort = _localEndPoint?.Port ?? 0; - if (_remoteEndPoint != null && _localEndPoint != null) - { - httpConnectionFeature.IsLocal = _remoteEndPoint.Address.Equals(_localEndPoint.Address); - } - else - { - httpConnectionFeature.IsLocal = false; - } - _prepareRequest?.Invoke(this); _manuallySetRequestAbortToken = null; diff --git a/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/RequestTests.cs b/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/RequestTests.cs index fdba322cb3..1beb9fd4a5 100644 --- a/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/RequestTests.cs +++ b/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/RequestTests.cs @@ -145,8 +145,7 @@ namespace Microsoft.AspNet.Server.Kestrel.FunctionalTests RemoteIPAddress = connection.RemoteIpAddress?.ToString(), RemotePort = connection.RemotePort, LocalIPAddress = connection.LocalIpAddress?.ToString(), - LocalPort = connection.LocalPort, - IsLocal = connection.IsLocal + LocalPort = connection.LocalPort })); }); }); @@ -165,7 +164,6 @@ namespace Microsoft.AspNet.Server.Kestrel.FunctionalTests var facts = JsonConvert.DeserializeObject(connectionFacts); Assert.Equal(expectAddress, facts["RemoteIPAddress"].Value()); Assert.NotEmpty(facts["RemotePort"].Value()); - Assert.True(facts["IsLocal"].Value()); } } } From fa8fe3d085a954044bd889bb36b1d300e2523fec Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Mon, 18 Jan 2016 13:27:09 +0000 Subject: [PATCH 0573/1662] Complete sync-blocked calls directly --- .../Http/Frame.cs | 7 ++- .../Http/SocketOutput.cs | 55 ++++++++++++------- 2 files changed, 42 insertions(+), 20 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs index 54cc69855f..9d905384bf 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs @@ -421,7 +421,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { return; } - WriteChunkedAsync(data, RequestAborted).GetAwaiter().GetResult(); + WriteChunked(data); } else { @@ -468,6 +468,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } + private void WriteChunked(ArraySegment data) + { + SocketOutput.Write(data, immediate: false, chunk: true); + } + private Task WriteChunkedAsync(ArraySegment data, CancellationToken cancellationToken) { return SocketOutput.WriteAsync(data, immediate: false, chunk: true, cancellationToken: cancellationToken); diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs index cf3f8dc528..3c39954494 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs @@ -48,7 +48,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http private int _numBytesPreCompleted = 0; private Exception _lastWriteError; private WriteContext _nextWriteContext; - private readonly Queue> _tasksPending; + private readonly Queue _tasksPending; private readonly Queue _writeContextPool; private readonly Queue _writeReqPool; @@ -68,7 +68,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http _connectionId = connectionId; _log = log; _threadPool = threadPool; - _tasksPending = new Queue>(_initialTaskQueues); + _tasksPending = new Queue(_initialTaskQueues); _writeContextPool = new Queue(_maxPooledWriteContexts); _writeReqPool = writeReqPool; @@ -81,7 +81,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http bool immediate = true, bool chunk = false, bool socketShutdownSend = false, - bool socketDisconnect = false) + bool socketDisconnect = false, + bool isSync = false) { TaskCompletionSource tcs = null; var scheduleWrite = false; @@ -147,7 +148,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { // immediate write, which is not eligable for instant completion above tcs = new TaskCompletionSource(buffer.Count); - _tasksPending.Enqueue(tcs); + _tasksPending.Enqueue(new WaitingTask() { + CompletionSource = tcs, + BytesToWrite = buffer.Count, + IsSync = isSync + }); } if (!_writePending && immediate) @@ -316,21 +321,35 @@ namespace Microsoft.AspNet.Server.Kestrel.Http // This allows large writes to complete once they've actually finished. var bytesLeftToBuffer = _maxBytesPreCompleted - _numBytesPreCompleted; while (_tasksPending.Count > 0 && - (int)(_tasksPending.Peek().Task.AsyncState) <= bytesLeftToBuffer) + (_tasksPending.Peek().BytesToWrite) <= bytesLeftToBuffer) { - var tcs = _tasksPending.Dequeue(); - var bytesToWrite = (int)tcs.Task.AsyncState; + var waitingTask = _tasksPending.Dequeue(); + var bytesToWrite = waitingTask.BytesToWrite; _numBytesPreCompleted += bytesToWrite; bytesLeftToBuffer -= bytesToWrite; if (_lastWriteError == null) { - _threadPool.Complete(tcs); + if (waitingTask.IsSync) + { + waitingTask.CompletionSource.TrySetResult(null); + } + else + { + _threadPool.Complete(waitingTask.CompletionSource); + } } else { - _threadPool.Error(tcs, _lastWriteError); + if (waitingTask.IsSync) + { + waitingTask.CompletionSource.TrySetException(_lastWriteError); + } + else + { + _threadPool.Error(waitingTask.CompletionSource, _lastWriteError); + } } } @@ -374,16 +393,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http void ISocketOutput.Write(ArraySegment buffer, bool immediate, bool chunk) { - var task = WriteAsync(buffer, immediate, chunk); - - if (task.Status == TaskStatus.RanToCompletion) - { - return; - } - else - { - task.GetAwaiter().GetResult(); - } + WriteAsync(buffer, immediate, chunk, isSync: true).GetAwaiter().GetResult(); } Task ISocketOutput.WriteAsync(ArraySegment buffer, bool immediate, bool chunk, CancellationToken cancellationToken) @@ -634,5 +644,12 @@ namespace Microsoft.AspNet.Server.Kestrel.Http ShutdownSendStatus = 0; } } + + private struct WaitingTask + { + public bool IsSync; + public int BytesToWrite; + public TaskCompletionSource CompletionSource; + } } } From 40824999c61b578e7eeb322161003682d564b569 Mon Sep 17 00:00:00 2001 From: Pranav K Date: Wed, 20 Jan 2016 20:58:22 -0800 Subject: [PATCH 0574/1662] Reacting to CoreCLR package version change --- src/Microsoft.AspNet.Server.Kestrel/project.json | 4 ++-- test/Microsoft.AspNet.Server.KestrelTests/project.json | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/project.json b/src/Microsoft.AspNet.Server.Kestrel/project.json index 4cb8e6bd5d..8fce00cce0 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/project.json +++ b/src/Microsoft.AspNet.Server.Kestrel/project.json @@ -33,10 +33,10 @@ "System.Diagnostics.TraceSource": "4.0.0-*", "System.Diagnostics.Tracing": "4.0.21-*", "System.Globalization": "4.0.11-*", - "System.IO": "4.0.11-*", + "System.IO": "4.1.0-*", "System.Linq": "4.0.1-*", "System.Net.Primitives": "4.0.11-*", - "System.Runtime.Extensions": "4.0.11-*", + "System.Runtime.Extensions": "4.1.0-*", "System.Runtime.InteropServices": "4.0.21-*", "System.Text.Encoding": "4.0.11-*", "System.Threading": "4.0.11-*", diff --git a/test/Microsoft.AspNet.Server.KestrelTests/project.json b/test/Microsoft.AspNet.Server.KestrelTests/project.json index af2652e3a8..4060d91d5e 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/project.json +++ b/test/Microsoft.AspNet.Server.KestrelTests/project.json @@ -12,7 +12,6 @@ "dnxcore50": { "dependencies": { "System.Diagnostics.TraceSource": "4.0.0-*", - "System.IO": "4.0.11-*", "System.Net.Http.WinHttpHandler": "4.0.0-*", "System.Net.Sockets": "4.1.0-*", "System.Runtime.Handles": "4.0.1-*" From 3cfe2f3070854fc1f6ed585a763b0882583e1848 Mon Sep 17 00:00:00 2001 From: "N. Taylor Mullen" Date: Fri, 22 Jan 2016 12:23:44 -0800 Subject: [PATCH 0575/1662] Rename AspNet 5 folders and files. See https://github.com/aspnet/Announcements/issues/144 for more information. --- .../ClientCertificateMode.cs | 0 .../HttpsApplicationBuilderExtensions.cs | 0 .../HttpsConnectionFilter.cs | 0 .../HttpsConnectionFilterOptions.cs | 0 ...Microsoft.AspNetCore.Server.Kestrel.Https.xproj} | 0 .../Properties/AssemblyInfo.cs | 0 .../project.json | 0 .../Filter/ConnectionFilterContext.cs | 0 .../Filter/FilteredStreamAdapter.cs | 0 .../Filter/IConnectionFilter.cs | 0 .../Filter/LibuvStream.cs | 0 .../Filter/LoggingConnectionFilter.cs | 0 .../LoggingFilterApplicationBuilderExtensions.cs | 0 .../Filter/LoggingStream.cs | 0 .../Filter/NoOpConnectionFilter.cs | 0 .../Filter/SocketInputStream.cs | 0 .../Filter/StreamExtensions.cs | 0 .../Filter/StreamSocketOutput.cs | 0 .../Http/ChunkWriter.cs | 0 .../Http/Connection.cs | 0 .../Http/ConnectionContext.cs | 0 .../Http/DateHeaderValueManager.cs | 0 .../Http/Frame.FeatureCollection.cs | 0 .../Http/Frame.Generated.cs | 0 .../Http/Frame.cs | 0 .../Http/FrameContext.cs | 0 .../Http/FrameDuplexStream.cs | 0 .../Http/FrameHeaders.Generated.cs | 0 .../Http/FrameHeaders.cs | 0 .../Http/FrameOfT.cs | 0 .../Http/FrameRequestHeaders.cs | 0 .../Http/FrameRequestStream.cs | 0 .../Http/FrameResponseHeaders.cs | 0 .../Http/FrameResponseStream.cs | 0 .../Http/FrameStreamState.cs | 0 .../Http/IConnectionControl.cs | 0 .../Http/IFrameControl.cs | 0 .../Http/ISocketOutput.cs | 0 .../Http/Listener.cs | 0 .../Http/ListenerContext.cs | 0 .../Http/ListenerPrimary.cs | 0 .../Http/ListenerSecondary.cs | 0 .../Http/MessageBody.cs | 0 .../Http/PipeListener.cs | 0 .../Http/PipeListenerPrimary.cs | 0 .../Http/PipeListenerSecondary.cs | 0 .../Http/ProduceEndType.cs | 0 .../Http/ReasonPhrases.cs | 0 .../Http/SocketInput.cs | 0 .../Http/SocketInputExtensions.cs | 0 .../Http/SocketOutput.cs | 0 .../Http/TcpListener.cs | 0 .../Http/TcpListenerPrimary.cs | 0 .../Http/TcpListenerSecondary.cs | 0 .../Http/UrlPathDecoder.cs | 0 .../IKestrelServerInformation.cs | 0 .../Infrastructure/Constants.cs | 0 .../Infrastructure/Disposable.cs | 0 .../Infrastructure/IKestrelTrace.cs | 0 .../Infrastructure/ISystemClock.cs | 0 .../Infrastructure/IThreadPool.cs | 0 .../Infrastructure/KestrelThread.cs | 0 .../Infrastructure/KestrelTrace.cs | 0 .../Infrastructure/LoggingThreadPool.cs | 0 .../Infrastructure/MemoryPool2.cs | 0 .../Infrastructure/MemoryPoolBlock2.cs | 0 .../Infrastructure/MemoryPoolIterator2.cs | 0 .../Infrastructure/MemoryPoolIterator2Extensions.cs | 0 .../Infrastructure/MemoryPoolSlab2.cs | 0 .../Infrastructure/SystemClock.cs | 0 .../Infrastructure/TaskUtilities.cs | 0 .../KestrelEngine.cs | 0 .../KestrelServer.cs | 0 .../KestrelServerInformation.cs | 0 .../Microsoft.AspNetCore.Server.Kestrel.xproj} | 0 .../Networking/Libuv.cs | 0 .../Networking/PlatformApis.cs | 0 .../Networking/SockAddr.cs | 0 .../Networking/UvAsyncHandle.cs | 0 .../Networking/UvConnectRequest.cs | 0 .../Networking/UvException.cs | 0 .../Networking/UvHandle.cs | 0 .../Networking/UvLoopHandle.cs | 0 .../Networking/UvMemory.cs | 0 .../Networking/UvPipeHandle.cs | 0 .../Networking/UvRequest.cs | 0 .../Networking/UvShutdownReq.cs | 0 .../Networking/UvStreamHandle.cs | 0 .../Networking/UvTcpHandle.cs | 0 .../Networking/UvWriteReq.cs | 0 .../Properties/AssemblyInfo.cs | 0 .../ServerAddress.cs | 0 .../ServerFactory.cs | 0 .../ServiceContext.cs | 0 .../project.json | 0 .../AddressRegistrationTests.cs | 0 .../IPv6SupportedConditionAttribute.cs | 0 ...AspNetCore.Server.Kestrel.FunctionalTests.xproj} | 0 .../PathBaseTests.cs | 0 .../RequestTests.cs | 0 .../ResponseTests.cs | 0 .../ThreadCountTests.cs | 0 .../project.json | 0 .../AsciiDecoder.cs | 0 .../ChunkWriterTests.cs | 0 .../ChunkedResponseTests.cs | 0 .../ConnectionFilterTests.cs | 0 .../CreateIPEndpointTests.cs | 0 .../DateHeaderValueManagerTests.cs | 0 .../DummyApplication.cs | 0 .../EngineTests.cs | 0 .../FrameFacts.cs | 0 .../FrameRequestHeadersTests.cs | 0 .../FrameResponseHeadersTests.cs | 0 .../FrameTests.cs | 0 .../HttpsConnectionFilterTests.cs | 0 .../KestrelServerInformationTests.cs | 0 .../KestrelServerTests.cs | 0 .../LifetimeNotImplemented.cs | 0 .../MemoryPoolBlock2Tests.cs | 0 .../MemoryPoolExtensions.cs | 0 .../MemoryPoolIterator2Tests.cs | 0 .../MessageBodyTests.cs | 0 .../Microsoft.AspNetCore.Server.KestrelTests.xproj} | 0 .../MultipleLoopTests.cs | 0 .../NetworkingTests.cs | 0 .../Program.cs | 0 .../ServerAddressFacts.cs | 0 .../SocketInputTests.cs | 0 .../SocketOutputTests.cs | 0 .../StreamSocketOutputTests.cs | 0 .../TestConnection.cs | 0 .../TestDateHeaderValueManager.cs | 0 .../TestHelpers/MockLibuv.cs | 0 .../TestHelpers/MockSystemClock.cs | 0 .../TestInput.cs | 0 .../TestLogger.cs | 0 .../TestResources/testCert.pfx | Bin .../TestServer.cs | 0 .../TestServiceContext.cs | 0 .../UrlPathDecoder.cs | 0 .../project.json | 0 .../FrameFeatureCollection.cs | 0 .../KnownHeaders.cs | 0 ...t.AspNetCore.Server.Kestrel.GeneratedCode.xproj} | 0 .../Program.cs | 0 .../project.json | 0 ...oft.AspNetCore.Server.Kestrel.LibuvCopier.xproj} | 0 .../Program.cs | 0 .../project.json | 0 150 files changed, 0 insertions(+), 0 deletions(-) rename src/{Microsoft.AspNet.Server.Kestrel.Https => Microsoft.AspNetCore.Server.Kestrel.Https}/ClientCertificateMode.cs (100%) rename src/{Microsoft.AspNet.Server.Kestrel.Https => Microsoft.AspNetCore.Server.Kestrel.Https}/HttpsApplicationBuilderExtensions.cs (100%) rename src/{Microsoft.AspNet.Server.Kestrel.Https => Microsoft.AspNetCore.Server.Kestrel.Https}/HttpsConnectionFilter.cs (100%) rename src/{Microsoft.AspNet.Server.Kestrel.Https => Microsoft.AspNetCore.Server.Kestrel.Https}/HttpsConnectionFilterOptions.cs (100%) rename src/{Microsoft.AspNet.Server.Kestrel.Https/Microsoft.AspNet.Server.Kestrel.Https.xproj => Microsoft.AspNetCore.Server.Kestrel.Https/Microsoft.AspNetCore.Server.Kestrel.Https.xproj} (100%) rename src/{Microsoft.AspNet.Server.Kestrel.Https => Microsoft.AspNetCore.Server.Kestrel.Https}/Properties/AssemblyInfo.cs (100%) rename src/{Microsoft.AspNet.Server.Kestrel.Https => Microsoft.AspNetCore.Server.Kestrel.Https}/project.json (100%) rename src/{Microsoft.AspNet.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel}/Filter/ConnectionFilterContext.cs (100%) rename src/{Microsoft.AspNet.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel}/Filter/FilteredStreamAdapter.cs (100%) rename src/{Microsoft.AspNet.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel}/Filter/IConnectionFilter.cs (100%) rename src/{Microsoft.AspNet.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel}/Filter/LibuvStream.cs (100%) rename src/{Microsoft.AspNet.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel}/Filter/LoggingConnectionFilter.cs (100%) rename src/{Microsoft.AspNet.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel}/Filter/LoggingFilterApplicationBuilderExtensions.cs (100%) rename src/{Microsoft.AspNet.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel}/Filter/LoggingStream.cs (100%) rename src/{Microsoft.AspNet.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel}/Filter/NoOpConnectionFilter.cs (100%) rename src/{Microsoft.AspNet.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel}/Filter/SocketInputStream.cs (100%) rename src/{Microsoft.AspNet.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel}/Filter/StreamExtensions.cs (100%) rename src/{Microsoft.AspNet.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel}/Filter/StreamSocketOutput.cs (100%) rename src/{Microsoft.AspNet.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel}/Http/ChunkWriter.cs (100%) rename src/{Microsoft.AspNet.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel}/Http/Connection.cs (100%) rename src/{Microsoft.AspNet.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel}/Http/ConnectionContext.cs (100%) rename src/{Microsoft.AspNet.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel}/Http/DateHeaderValueManager.cs (100%) rename src/{Microsoft.AspNet.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel}/Http/Frame.FeatureCollection.cs (100%) rename src/{Microsoft.AspNet.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel}/Http/Frame.Generated.cs (100%) rename src/{Microsoft.AspNet.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel}/Http/Frame.cs (100%) rename src/{Microsoft.AspNet.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel}/Http/FrameContext.cs (100%) rename src/{Microsoft.AspNet.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel}/Http/FrameDuplexStream.cs (100%) rename src/{Microsoft.AspNet.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel}/Http/FrameHeaders.Generated.cs (100%) rename src/{Microsoft.AspNet.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel}/Http/FrameHeaders.cs (100%) rename src/{Microsoft.AspNet.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel}/Http/FrameOfT.cs (100%) rename src/{Microsoft.AspNet.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel}/Http/FrameRequestHeaders.cs (100%) rename src/{Microsoft.AspNet.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel}/Http/FrameRequestStream.cs (100%) rename src/{Microsoft.AspNet.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel}/Http/FrameResponseHeaders.cs (100%) rename src/{Microsoft.AspNet.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel}/Http/FrameResponseStream.cs (100%) rename src/{Microsoft.AspNet.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel}/Http/FrameStreamState.cs (100%) rename src/{Microsoft.AspNet.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel}/Http/IConnectionControl.cs (100%) rename src/{Microsoft.AspNet.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel}/Http/IFrameControl.cs (100%) rename src/{Microsoft.AspNet.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel}/Http/ISocketOutput.cs (100%) rename src/{Microsoft.AspNet.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel}/Http/Listener.cs (100%) rename src/{Microsoft.AspNet.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel}/Http/ListenerContext.cs (100%) rename src/{Microsoft.AspNet.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel}/Http/ListenerPrimary.cs (100%) rename src/{Microsoft.AspNet.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel}/Http/ListenerSecondary.cs (100%) rename src/{Microsoft.AspNet.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel}/Http/MessageBody.cs (100%) rename src/{Microsoft.AspNet.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel}/Http/PipeListener.cs (100%) rename src/{Microsoft.AspNet.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel}/Http/PipeListenerPrimary.cs (100%) rename src/{Microsoft.AspNet.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel}/Http/PipeListenerSecondary.cs (100%) rename src/{Microsoft.AspNet.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel}/Http/ProduceEndType.cs (100%) rename src/{Microsoft.AspNet.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel}/Http/ReasonPhrases.cs (100%) rename src/{Microsoft.AspNet.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel}/Http/SocketInput.cs (100%) rename src/{Microsoft.AspNet.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel}/Http/SocketInputExtensions.cs (100%) rename src/{Microsoft.AspNet.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel}/Http/SocketOutput.cs (100%) rename src/{Microsoft.AspNet.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel}/Http/TcpListener.cs (100%) rename src/{Microsoft.AspNet.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel}/Http/TcpListenerPrimary.cs (100%) rename src/{Microsoft.AspNet.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel}/Http/TcpListenerSecondary.cs (100%) rename src/{Microsoft.AspNet.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel}/Http/UrlPathDecoder.cs (100%) rename src/{Microsoft.AspNet.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel}/IKestrelServerInformation.cs (100%) rename src/{Microsoft.AspNet.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel}/Infrastructure/Constants.cs (100%) rename src/{Microsoft.AspNet.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel}/Infrastructure/Disposable.cs (100%) rename src/{Microsoft.AspNet.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel}/Infrastructure/IKestrelTrace.cs (100%) rename src/{Microsoft.AspNet.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel}/Infrastructure/ISystemClock.cs (100%) rename src/{Microsoft.AspNet.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel}/Infrastructure/IThreadPool.cs (100%) rename src/{Microsoft.AspNet.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel}/Infrastructure/KestrelThread.cs (100%) rename src/{Microsoft.AspNet.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel}/Infrastructure/KestrelTrace.cs (100%) rename src/{Microsoft.AspNet.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel}/Infrastructure/LoggingThreadPool.cs (100%) rename src/{Microsoft.AspNet.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel}/Infrastructure/MemoryPool2.cs (100%) rename src/{Microsoft.AspNet.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel}/Infrastructure/MemoryPoolBlock2.cs (100%) rename src/{Microsoft.AspNet.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel}/Infrastructure/MemoryPoolIterator2.cs (100%) rename src/{Microsoft.AspNet.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel}/Infrastructure/MemoryPoolIterator2Extensions.cs (100%) rename src/{Microsoft.AspNet.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel}/Infrastructure/MemoryPoolSlab2.cs (100%) rename src/{Microsoft.AspNet.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel}/Infrastructure/SystemClock.cs (100%) rename src/{Microsoft.AspNet.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel}/Infrastructure/TaskUtilities.cs (100%) rename src/{Microsoft.AspNet.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel}/KestrelEngine.cs (100%) rename src/{Microsoft.AspNet.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel}/KestrelServer.cs (100%) rename src/{Microsoft.AspNet.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel}/KestrelServerInformation.cs (100%) rename src/{Microsoft.AspNet.Server.Kestrel/Microsoft.AspNet.Server.Kestrel.xproj => Microsoft.AspNetCore.Server.Kestrel/Microsoft.AspNetCore.Server.Kestrel.xproj} (100%) rename src/{Microsoft.AspNet.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel}/Networking/Libuv.cs (100%) rename src/{Microsoft.AspNet.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel}/Networking/PlatformApis.cs (100%) rename src/{Microsoft.AspNet.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel}/Networking/SockAddr.cs (100%) rename src/{Microsoft.AspNet.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel}/Networking/UvAsyncHandle.cs (100%) rename src/{Microsoft.AspNet.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel}/Networking/UvConnectRequest.cs (100%) rename src/{Microsoft.AspNet.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel}/Networking/UvException.cs (100%) rename src/{Microsoft.AspNet.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel}/Networking/UvHandle.cs (100%) rename src/{Microsoft.AspNet.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel}/Networking/UvLoopHandle.cs (100%) rename src/{Microsoft.AspNet.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel}/Networking/UvMemory.cs (100%) rename src/{Microsoft.AspNet.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel}/Networking/UvPipeHandle.cs (100%) rename src/{Microsoft.AspNet.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel}/Networking/UvRequest.cs (100%) rename src/{Microsoft.AspNet.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel}/Networking/UvShutdownReq.cs (100%) rename src/{Microsoft.AspNet.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel}/Networking/UvStreamHandle.cs (100%) rename src/{Microsoft.AspNet.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel}/Networking/UvTcpHandle.cs (100%) rename src/{Microsoft.AspNet.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel}/Networking/UvWriteReq.cs (100%) rename src/{Microsoft.AspNet.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel}/Properties/AssemblyInfo.cs (100%) rename src/{Microsoft.AspNet.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel}/ServerAddress.cs (100%) rename src/{Microsoft.AspNet.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel}/ServerFactory.cs (100%) rename src/{Microsoft.AspNet.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel}/ServiceContext.cs (100%) rename src/{Microsoft.AspNet.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel}/project.json (100%) rename test/{Microsoft.AspNet.Server.Kestrel.FunctionalTests => Microsoft.AspNetCore.Server.Kestrel.FunctionalTests}/AddressRegistrationTests.cs (100%) rename test/{Microsoft.AspNet.Server.Kestrel.FunctionalTests => Microsoft.AspNetCore.Server.Kestrel.FunctionalTests}/IPv6SupportedConditionAttribute.cs (100%) rename test/{Microsoft.AspNet.Server.Kestrel.FunctionalTests/Microsoft.AspNet.Server.Kestrel.FunctionalTests.xproj => Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests.xproj} (100%) rename test/{Microsoft.AspNet.Server.Kestrel.FunctionalTests => Microsoft.AspNetCore.Server.Kestrel.FunctionalTests}/PathBaseTests.cs (100%) rename test/{Microsoft.AspNet.Server.Kestrel.FunctionalTests => Microsoft.AspNetCore.Server.Kestrel.FunctionalTests}/RequestTests.cs (100%) rename test/{Microsoft.AspNet.Server.Kestrel.FunctionalTests => Microsoft.AspNetCore.Server.Kestrel.FunctionalTests}/ResponseTests.cs (100%) rename test/{Microsoft.AspNet.Server.Kestrel.FunctionalTests => Microsoft.AspNetCore.Server.Kestrel.FunctionalTests}/ThreadCountTests.cs (100%) rename test/{Microsoft.AspNet.Server.Kestrel.FunctionalTests => Microsoft.AspNetCore.Server.Kestrel.FunctionalTests}/project.json (100%) rename test/{Microsoft.AspNet.Server.KestrelTests => Microsoft.AspNetCore.Server.KestrelTests}/AsciiDecoder.cs (100%) rename test/{Microsoft.AspNet.Server.KestrelTests => Microsoft.AspNetCore.Server.KestrelTests}/ChunkWriterTests.cs (100%) rename test/{Microsoft.AspNet.Server.KestrelTests => Microsoft.AspNetCore.Server.KestrelTests}/ChunkedResponseTests.cs (100%) rename test/{Microsoft.AspNet.Server.KestrelTests => Microsoft.AspNetCore.Server.KestrelTests}/ConnectionFilterTests.cs (100%) rename test/{Microsoft.AspNet.Server.KestrelTests => Microsoft.AspNetCore.Server.KestrelTests}/CreateIPEndpointTests.cs (100%) rename test/{Microsoft.AspNet.Server.KestrelTests => Microsoft.AspNetCore.Server.KestrelTests}/DateHeaderValueManagerTests.cs (100%) rename test/{Microsoft.AspNet.Server.KestrelTests => Microsoft.AspNetCore.Server.KestrelTests}/DummyApplication.cs (100%) rename test/{Microsoft.AspNet.Server.KestrelTests => Microsoft.AspNetCore.Server.KestrelTests}/EngineTests.cs (100%) rename test/{Microsoft.AspNet.Server.KestrelTests => Microsoft.AspNetCore.Server.KestrelTests}/FrameFacts.cs (100%) rename test/{Microsoft.AspNet.Server.KestrelTests => Microsoft.AspNetCore.Server.KestrelTests}/FrameRequestHeadersTests.cs (100%) rename test/{Microsoft.AspNet.Server.KestrelTests => Microsoft.AspNetCore.Server.KestrelTests}/FrameResponseHeadersTests.cs (100%) rename test/{Microsoft.AspNet.Server.KestrelTests => Microsoft.AspNetCore.Server.KestrelTests}/FrameTests.cs (100%) rename test/{Microsoft.AspNet.Server.KestrelTests => Microsoft.AspNetCore.Server.KestrelTests}/HttpsConnectionFilterTests.cs (100%) rename test/{Microsoft.AspNet.Server.KestrelTests => Microsoft.AspNetCore.Server.KestrelTests}/KestrelServerInformationTests.cs (100%) rename test/{Microsoft.AspNet.Server.KestrelTests => Microsoft.AspNetCore.Server.KestrelTests}/KestrelServerTests.cs (100%) rename test/{Microsoft.AspNet.Server.KestrelTests => Microsoft.AspNetCore.Server.KestrelTests}/LifetimeNotImplemented.cs (100%) rename test/{Microsoft.AspNet.Server.KestrelTests => Microsoft.AspNetCore.Server.KestrelTests}/MemoryPoolBlock2Tests.cs (100%) rename test/{Microsoft.AspNet.Server.KestrelTests => Microsoft.AspNetCore.Server.KestrelTests}/MemoryPoolExtensions.cs (100%) rename test/{Microsoft.AspNet.Server.KestrelTests => Microsoft.AspNetCore.Server.KestrelTests}/MemoryPoolIterator2Tests.cs (100%) rename test/{Microsoft.AspNet.Server.KestrelTests => Microsoft.AspNetCore.Server.KestrelTests}/MessageBodyTests.cs (100%) rename test/{Microsoft.AspNet.Server.KestrelTests/Microsoft.AspNet.Server.KestrelTests.xproj => Microsoft.AspNetCore.Server.KestrelTests/Microsoft.AspNetCore.Server.KestrelTests.xproj} (100%) rename test/{Microsoft.AspNet.Server.KestrelTests => Microsoft.AspNetCore.Server.KestrelTests}/MultipleLoopTests.cs (100%) rename test/{Microsoft.AspNet.Server.KestrelTests => Microsoft.AspNetCore.Server.KestrelTests}/NetworkingTests.cs (100%) rename test/{Microsoft.AspNet.Server.KestrelTests => Microsoft.AspNetCore.Server.KestrelTests}/Program.cs (100%) rename test/{Microsoft.AspNet.Server.KestrelTests => Microsoft.AspNetCore.Server.KestrelTests}/ServerAddressFacts.cs (100%) rename test/{Microsoft.AspNet.Server.KestrelTests => Microsoft.AspNetCore.Server.KestrelTests}/SocketInputTests.cs (100%) rename test/{Microsoft.AspNet.Server.KestrelTests => Microsoft.AspNetCore.Server.KestrelTests}/SocketOutputTests.cs (100%) rename test/{Microsoft.AspNet.Server.KestrelTests => Microsoft.AspNetCore.Server.KestrelTests}/StreamSocketOutputTests.cs (100%) rename test/{Microsoft.AspNet.Server.KestrelTests => Microsoft.AspNetCore.Server.KestrelTests}/TestConnection.cs (100%) rename test/{Microsoft.AspNet.Server.KestrelTests => Microsoft.AspNetCore.Server.KestrelTests}/TestDateHeaderValueManager.cs (100%) rename test/{Microsoft.AspNet.Server.KestrelTests => Microsoft.AspNetCore.Server.KestrelTests}/TestHelpers/MockLibuv.cs (100%) rename test/{Microsoft.AspNet.Server.KestrelTests => Microsoft.AspNetCore.Server.KestrelTests}/TestHelpers/MockSystemClock.cs (100%) rename test/{Microsoft.AspNet.Server.KestrelTests => Microsoft.AspNetCore.Server.KestrelTests}/TestInput.cs (100%) rename test/{Microsoft.AspNet.Server.KestrelTests => Microsoft.AspNetCore.Server.KestrelTests}/TestLogger.cs (100%) rename test/{Microsoft.AspNet.Server.KestrelTests => Microsoft.AspNetCore.Server.KestrelTests}/TestResources/testCert.pfx (100%) rename test/{Microsoft.AspNet.Server.KestrelTests => Microsoft.AspNetCore.Server.KestrelTests}/TestServer.cs (100%) rename test/{Microsoft.AspNet.Server.KestrelTests => Microsoft.AspNetCore.Server.KestrelTests}/TestServiceContext.cs (100%) rename test/{Microsoft.AspNet.Server.KestrelTests => Microsoft.AspNetCore.Server.KestrelTests}/UrlPathDecoder.cs (100%) rename test/{Microsoft.AspNet.Server.KestrelTests => Microsoft.AspNetCore.Server.KestrelTests}/project.json (100%) rename tools/{Microsoft.AspNet.Server.Kestrel.GeneratedCode => Microsoft.AspNetCore.Server.Kestrel.GeneratedCode}/FrameFeatureCollection.cs (100%) rename tools/{Microsoft.AspNet.Server.Kestrel.GeneratedCode => Microsoft.AspNetCore.Server.Kestrel.GeneratedCode}/KnownHeaders.cs (100%) rename tools/{Microsoft.AspNet.Server.Kestrel.GeneratedCode/Microsoft.AspNet.Server.Kestrel.GeneratedCode.xproj => Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode.xproj} (100%) rename tools/{Microsoft.AspNet.Server.Kestrel.GeneratedCode => Microsoft.AspNetCore.Server.Kestrel.GeneratedCode}/Program.cs (100%) rename tools/{Microsoft.AspNet.Server.Kestrel.GeneratedCode => Microsoft.AspNetCore.Server.Kestrel.GeneratedCode}/project.json (100%) rename tools/{Microsoft.AspNet.Server.Kestrel.LibuvCopier/Microsoft.AspNet.Server.Kestrel.LibuvCopier.xproj => Microsoft.AspNetCore.Server.Kestrel.LibuvCopier/Microsoft.AspNetCore.Server.Kestrel.LibuvCopier.xproj} (100%) rename tools/{Microsoft.AspNet.Server.Kestrel.LibuvCopier => Microsoft.AspNetCore.Server.Kestrel.LibuvCopier}/Program.cs (100%) rename tools/{Microsoft.AspNet.Server.Kestrel.LibuvCopier => Microsoft.AspNetCore.Server.Kestrel.LibuvCopier}/project.json (100%) diff --git a/src/Microsoft.AspNet.Server.Kestrel.Https/ClientCertificateMode.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Https/ClientCertificateMode.cs similarity index 100% rename from src/Microsoft.AspNet.Server.Kestrel.Https/ClientCertificateMode.cs rename to src/Microsoft.AspNetCore.Server.Kestrel.Https/ClientCertificateMode.cs diff --git a/src/Microsoft.AspNet.Server.Kestrel.Https/HttpsApplicationBuilderExtensions.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Https/HttpsApplicationBuilderExtensions.cs similarity index 100% rename from src/Microsoft.AspNet.Server.Kestrel.Https/HttpsApplicationBuilderExtensions.cs rename to src/Microsoft.AspNetCore.Server.Kestrel.Https/HttpsApplicationBuilderExtensions.cs diff --git a/src/Microsoft.AspNet.Server.Kestrel.Https/HttpsConnectionFilter.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Https/HttpsConnectionFilter.cs similarity index 100% rename from src/Microsoft.AspNet.Server.Kestrel.Https/HttpsConnectionFilter.cs rename to src/Microsoft.AspNetCore.Server.Kestrel.Https/HttpsConnectionFilter.cs diff --git a/src/Microsoft.AspNet.Server.Kestrel.Https/HttpsConnectionFilterOptions.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Https/HttpsConnectionFilterOptions.cs similarity index 100% rename from src/Microsoft.AspNet.Server.Kestrel.Https/HttpsConnectionFilterOptions.cs rename to src/Microsoft.AspNetCore.Server.Kestrel.Https/HttpsConnectionFilterOptions.cs diff --git a/src/Microsoft.AspNet.Server.Kestrel.Https/Microsoft.AspNet.Server.Kestrel.Https.xproj b/src/Microsoft.AspNetCore.Server.Kestrel.Https/Microsoft.AspNetCore.Server.Kestrel.Https.xproj similarity index 100% rename from src/Microsoft.AspNet.Server.Kestrel.Https/Microsoft.AspNet.Server.Kestrel.Https.xproj rename to src/Microsoft.AspNetCore.Server.Kestrel.Https/Microsoft.AspNetCore.Server.Kestrel.Https.xproj diff --git a/src/Microsoft.AspNet.Server.Kestrel.Https/Properties/AssemblyInfo.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Https/Properties/AssemblyInfo.cs similarity index 100% rename from src/Microsoft.AspNet.Server.Kestrel.Https/Properties/AssemblyInfo.cs rename to src/Microsoft.AspNetCore.Server.Kestrel.Https/Properties/AssemblyInfo.cs diff --git a/src/Microsoft.AspNet.Server.Kestrel.Https/project.json b/src/Microsoft.AspNetCore.Server.Kestrel.Https/project.json similarity index 100% rename from src/Microsoft.AspNet.Server.Kestrel.Https/project.json rename to src/Microsoft.AspNetCore.Server.Kestrel.Https/project.json diff --git a/src/Microsoft.AspNet.Server.Kestrel/Filter/ConnectionFilterContext.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Filter/ConnectionFilterContext.cs similarity index 100% rename from src/Microsoft.AspNet.Server.Kestrel/Filter/ConnectionFilterContext.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Filter/ConnectionFilterContext.cs diff --git a/src/Microsoft.AspNet.Server.Kestrel/Filter/FilteredStreamAdapter.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Filter/FilteredStreamAdapter.cs similarity index 100% rename from src/Microsoft.AspNet.Server.Kestrel/Filter/FilteredStreamAdapter.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Filter/FilteredStreamAdapter.cs diff --git a/src/Microsoft.AspNet.Server.Kestrel/Filter/IConnectionFilter.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Filter/IConnectionFilter.cs similarity index 100% rename from src/Microsoft.AspNet.Server.Kestrel/Filter/IConnectionFilter.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Filter/IConnectionFilter.cs diff --git a/src/Microsoft.AspNet.Server.Kestrel/Filter/LibuvStream.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Filter/LibuvStream.cs similarity index 100% rename from src/Microsoft.AspNet.Server.Kestrel/Filter/LibuvStream.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Filter/LibuvStream.cs diff --git a/src/Microsoft.AspNet.Server.Kestrel/Filter/LoggingConnectionFilter.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Filter/LoggingConnectionFilter.cs similarity index 100% rename from src/Microsoft.AspNet.Server.Kestrel/Filter/LoggingConnectionFilter.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Filter/LoggingConnectionFilter.cs diff --git a/src/Microsoft.AspNet.Server.Kestrel/Filter/LoggingFilterApplicationBuilderExtensions.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Filter/LoggingFilterApplicationBuilderExtensions.cs similarity index 100% rename from src/Microsoft.AspNet.Server.Kestrel/Filter/LoggingFilterApplicationBuilderExtensions.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Filter/LoggingFilterApplicationBuilderExtensions.cs diff --git a/src/Microsoft.AspNet.Server.Kestrel/Filter/LoggingStream.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Filter/LoggingStream.cs similarity index 100% rename from src/Microsoft.AspNet.Server.Kestrel/Filter/LoggingStream.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Filter/LoggingStream.cs diff --git a/src/Microsoft.AspNet.Server.Kestrel/Filter/NoOpConnectionFilter.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Filter/NoOpConnectionFilter.cs similarity index 100% rename from src/Microsoft.AspNet.Server.Kestrel/Filter/NoOpConnectionFilter.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Filter/NoOpConnectionFilter.cs diff --git a/src/Microsoft.AspNet.Server.Kestrel/Filter/SocketInputStream.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Filter/SocketInputStream.cs similarity index 100% rename from src/Microsoft.AspNet.Server.Kestrel/Filter/SocketInputStream.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Filter/SocketInputStream.cs diff --git a/src/Microsoft.AspNet.Server.Kestrel/Filter/StreamExtensions.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Filter/StreamExtensions.cs similarity index 100% rename from src/Microsoft.AspNet.Server.Kestrel/Filter/StreamExtensions.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Filter/StreamExtensions.cs diff --git a/src/Microsoft.AspNet.Server.Kestrel/Filter/StreamSocketOutput.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Filter/StreamSocketOutput.cs similarity index 100% rename from src/Microsoft.AspNet.Server.Kestrel/Filter/StreamSocketOutput.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Filter/StreamSocketOutput.cs diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/ChunkWriter.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/ChunkWriter.cs similarity index 100% rename from src/Microsoft.AspNet.Server.Kestrel/Http/ChunkWriter.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Http/ChunkWriter.cs diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Connection.cs similarity index 100% rename from src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Http/Connection.cs diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/ConnectionContext.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/ConnectionContext.cs similarity index 100% rename from src/Microsoft.AspNet.Server.Kestrel/Http/ConnectionContext.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Http/ConnectionContext.cs diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/DateHeaderValueManager.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/DateHeaderValueManager.cs similarity index 100% rename from src/Microsoft.AspNet.Server.Kestrel/Http/DateHeaderValueManager.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Http/DateHeaderValueManager.cs diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.FeatureCollection.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.FeatureCollection.cs similarity index 100% rename from src/Microsoft.AspNet.Server.Kestrel/Http/Frame.FeatureCollection.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.FeatureCollection.cs diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.Generated.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.Generated.cs similarity index 100% rename from src/Microsoft.AspNet.Server.Kestrel/Http/Frame.Generated.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.Generated.cs diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs similarity index 100% rename from src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameContext.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameContext.cs similarity index 100% rename from src/Microsoft.AspNet.Server.Kestrel/Http/FrameContext.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameContext.cs diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameDuplexStream.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameDuplexStream.cs similarity index 100% rename from src/Microsoft.AspNet.Server.Kestrel/Http/FrameDuplexStream.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameDuplexStream.cs diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameHeaders.Generated.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameHeaders.Generated.cs similarity index 100% rename from src/Microsoft.AspNet.Server.Kestrel/Http/FrameHeaders.Generated.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameHeaders.Generated.cs diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameHeaders.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameHeaders.cs similarity index 100% rename from src/Microsoft.AspNet.Server.Kestrel/Http/FrameHeaders.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameHeaders.cs diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameOfT.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameOfT.cs similarity index 100% rename from src/Microsoft.AspNet.Server.Kestrel/Http/FrameOfT.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameOfT.cs diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameRequestHeaders.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameRequestHeaders.cs similarity index 100% rename from src/Microsoft.AspNet.Server.Kestrel/Http/FrameRequestHeaders.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameRequestHeaders.cs diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameRequestStream.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameRequestStream.cs similarity index 100% rename from src/Microsoft.AspNet.Server.Kestrel/Http/FrameRequestStream.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameRequestStream.cs diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameResponseHeaders.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameResponseHeaders.cs similarity index 100% rename from src/Microsoft.AspNet.Server.Kestrel/Http/FrameResponseHeaders.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameResponseHeaders.cs diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameResponseStream.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameResponseStream.cs similarity index 100% rename from src/Microsoft.AspNet.Server.Kestrel/Http/FrameResponseStream.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameResponseStream.cs diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameStreamState.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameStreamState.cs similarity index 100% rename from src/Microsoft.AspNet.Server.Kestrel/Http/FrameStreamState.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameStreamState.cs diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/IConnectionControl.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/IConnectionControl.cs similarity index 100% rename from src/Microsoft.AspNet.Server.Kestrel/Http/IConnectionControl.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Http/IConnectionControl.cs diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/IFrameControl.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/IFrameControl.cs similarity index 100% rename from src/Microsoft.AspNet.Server.Kestrel/Http/IFrameControl.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Http/IFrameControl.cs diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/ISocketOutput.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/ISocketOutput.cs similarity index 100% rename from src/Microsoft.AspNet.Server.Kestrel/Http/ISocketOutput.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Http/ISocketOutput.cs diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Listener.cs similarity index 100% rename from src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Http/Listener.cs diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerContext.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/ListenerContext.cs similarity index 100% rename from src/Microsoft.AspNet.Server.Kestrel/Http/ListenerContext.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Http/ListenerContext.cs diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerPrimary.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/ListenerPrimary.cs similarity index 100% rename from src/Microsoft.AspNet.Server.Kestrel/Http/ListenerPrimary.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Http/ListenerPrimary.cs diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerSecondary.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/ListenerSecondary.cs similarity index 100% rename from src/Microsoft.AspNet.Server.Kestrel/Http/ListenerSecondary.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Http/ListenerSecondary.cs diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/MessageBody.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/MessageBody.cs similarity index 100% rename from src/Microsoft.AspNet.Server.Kestrel/Http/MessageBody.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Http/MessageBody.cs diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/PipeListener.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/PipeListener.cs similarity index 100% rename from src/Microsoft.AspNet.Server.Kestrel/Http/PipeListener.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Http/PipeListener.cs diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/PipeListenerPrimary.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/PipeListenerPrimary.cs similarity index 100% rename from src/Microsoft.AspNet.Server.Kestrel/Http/PipeListenerPrimary.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Http/PipeListenerPrimary.cs diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/PipeListenerSecondary.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/PipeListenerSecondary.cs similarity index 100% rename from src/Microsoft.AspNet.Server.Kestrel/Http/PipeListenerSecondary.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Http/PipeListenerSecondary.cs diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/ProduceEndType.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/ProduceEndType.cs similarity index 100% rename from src/Microsoft.AspNet.Server.Kestrel/Http/ProduceEndType.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Http/ProduceEndType.cs diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/ReasonPhrases.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/ReasonPhrases.cs similarity index 100% rename from src/Microsoft.AspNet.Server.Kestrel/Http/ReasonPhrases.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Http/ReasonPhrases.cs diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketInput.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketInput.cs similarity index 100% rename from src/Microsoft.AspNet.Server.Kestrel/Http/SocketInput.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketInput.cs diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketInputExtensions.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketInputExtensions.cs similarity index 100% rename from src/Microsoft.AspNet.Server.Kestrel/Http/SocketInputExtensions.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketInputExtensions.cs diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketOutput.cs similarity index 100% rename from src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketOutput.cs diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/TcpListener.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/TcpListener.cs similarity index 100% rename from src/Microsoft.AspNet.Server.Kestrel/Http/TcpListener.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Http/TcpListener.cs diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/TcpListenerPrimary.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/TcpListenerPrimary.cs similarity index 100% rename from src/Microsoft.AspNet.Server.Kestrel/Http/TcpListenerPrimary.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Http/TcpListenerPrimary.cs diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/TcpListenerSecondary.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/TcpListenerSecondary.cs similarity index 100% rename from src/Microsoft.AspNet.Server.Kestrel/Http/TcpListenerSecondary.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Http/TcpListenerSecondary.cs diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/UrlPathDecoder.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/UrlPathDecoder.cs similarity index 100% rename from src/Microsoft.AspNet.Server.Kestrel/Http/UrlPathDecoder.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Http/UrlPathDecoder.cs diff --git a/src/Microsoft.AspNet.Server.Kestrel/IKestrelServerInformation.cs b/src/Microsoft.AspNetCore.Server.Kestrel/IKestrelServerInformation.cs similarity index 100% rename from src/Microsoft.AspNet.Server.Kestrel/IKestrelServerInformation.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/IKestrelServerInformation.cs diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/Constants.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/Constants.cs similarity index 100% rename from src/Microsoft.AspNet.Server.Kestrel/Infrastructure/Constants.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/Constants.cs diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/Disposable.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/Disposable.cs similarity index 100% rename from src/Microsoft.AspNet.Server.Kestrel/Infrastructure/Disposable.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/Disposable.cs diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/IKestrelTrace.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/IKestrelTrace.cs similarity index 100% rename from src/Microsoft.AspNet.Server.Kestrel/Infrastructure/IKestrelTrace.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/IKestrelTrace.cs diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/ISystemClock.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/ISystemClock.cs similarity index 100% rename from src/Microsoft.AspNet.Server.Kestrel/Infrastructure/ISystemClock.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/ISystemClock.cs diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/IThreadPool.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/IThreadPool.cs similarity index 100% rename from src/Microsoft.AspNet.Server.Kestrel/Infrastructure/IThreadPool.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/IThreadPool.cs diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/KestrelThread.cs similarity index 100% rename from src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/KestrelThread.cs diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelTrace.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/KestrelTrace.cs similarity index 100% rename from src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelTrace.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/KestrelTrace.cs diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/LoggingThreadPool.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/LoggingThreadPool.cs similarity index 100% rename from src/Microsoft.AspNet.Server.Kestrel/Infrastructure/LoggingThreadPool.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/LoggingThreadPool.cs diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPool2.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPool2.cs similarity index 100% rename from src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPool2.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPool2.cs diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolBlock2.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPoolBlock2.cs similarity index 100% rename from src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolBlock2.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPoolBlock2.cs diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolIterator2.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPoolIterator2.cs similarity index 100% rename from src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolIterator2.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPoolIterator2.cs diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolIterator2Extensions.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPoolIterator2Extensions.cs similarity index 100% rename from src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolIterator2Extensions.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPoolIterator2Extensions.cs diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolSlab2.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPoolSlab2.cs similarity index 100% rename from src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolSlab2.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPoolSlab2.cs diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/SystemClock.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/SystemClock.cs similarity index 100% rename from src/Microsoft.AspNet.Server.Kestrel/Infrastructure/SystemClock.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/SystemClock.cs diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/TaskUtilities.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/TaskUtilities.cs similarity index 100% rename from src/Microsoft.AspNet.Server.Kestrel/Infrastructure/TaskUtilities.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/TaskUtilities.cs diff --git a/src/Microsoft.AspNet.Server.Kestrel/KestrelEngine.cs b/src/Microsoft.AspNetCore.Server.Kestrel/KestrelEngine.cs similarity index 100% rename from src/Microsoft.AspNet.Server.Kestrel/KestrelEngine.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/KestrelEngine.cs diff --git a/src/Microsoft.AspNet.Server.Kestrel/KestrelServer.cs b/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServer.cs similarity index 100% rename from src/Microsoft.AspNet.Server.Kestrel/KestrelServer.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/KestrelServer.cs diff --git a/src/Microsoft.AspNet.Server.Kestrel/KestrelServerInformation.cs b/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServerInformation.cs similarity index 100% rename from src/Microsoft.AspNet.Server.Kestrel/KestrelServerInformation.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/KestrelServerInformation.cs diff --git a/src/Microsoft.AspNet.Server.Kestrel/Microsoft.AspNet.Server.Kestrel.xproj b/src/Microsoft.AspNetCore.Server.Kestrel/Microsoft.AspNetCore.Server.Kestrel.xproj similarity index 100% rename from src/Microsoft.AspNet.Server.Kestrel/Microsoft.AspNet.Server.Kestrel.xproj rename to src/Microsoft.AspNetCore.Server.Kestrel/Microsoft.AspNetCore.Server.Kestrel.xproj diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/Libuv.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Networking/Libuv.cs similarity index 100% rename from src/Microsoft.AspNet.Server.Kestrel/Networking/Libuv.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Networking/Libuv.cs diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/PlatformApis.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Networking/PlatformApis.cs similarity index 100% rename from src/Microsoft.AspNet.Server.Kestrel/Networking/PlatformApis.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Networking/PlatformApis.cs diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/SockAddr.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Networking/SockAddr.cs similarity index 100% rename from src/Microsoft.AspNet.Server.Kestrel/Networking/SockAddr.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Networking/SockAddr.cs diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvAsyncHandle.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvAsyncHandle.cs similarity index 100% rename from src/Microsoft.AspNet.Server.Kestrel/Networking/UvAsyncHandle.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvAsyncHandle.cs diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvConnectRequest.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvConnectRequest.cs similarity index 100% rename from src/Microsoft.AspNet.Server.Kestrel/Networking/UvConnectRequest.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvConnectRequest.cs diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvException.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvException.cs similarity index 100% rename from src/Microsoft.AspNet.Server.Kestrel/Networking/UvException.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvException.cs diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvHandle.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvHandle.cs similarity index 100% rename from src/Microsoft.AspNet.Server.Kestrel/Networking/UvHandle.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvHandle.cs diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvLoopHandle.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvLoopHandle.cs similarity index 100% rename from src/Microsoft.AspNet.Server.Kestrel/Networking/UvLoopHandle.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvLoopHandle.cs diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvMemory.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvMemory.cs similarity index 100% rename from src/Microsoft.AspNet.Server.Kestrel/Networking/UvMemory.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvMemory.cs diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvPipeHandle.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvPipeHandle.cs similarity index 100% rename from src/Microsoft.AspNet.Server.Kestrel/Networking/UvPipeHandle.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvPipeHandle.cs diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvRequest.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvRequest.cs similarity index 100% rename from src/Microsoft.AspNet.Server.Kestrel/Networking/UvRequest.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvRequest.cs diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvShutdownReq.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvShutdownReq.cs similarity index 100% rename from src/Microsoft.AspNet.Server.Kestrel/Networking/UvShutdownReq.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvShutdownReq.cs diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvStreamHandle.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvStreamHandle.cs similarity index 100% rename from src/Microsoft.AspNet.Server.Kestrel/Networking/UvStreamHandle.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvStreamHandle.cs diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvTcpHandle.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvTcpHandle.cs similarity index 100% rename from src/Microsoft.AspNet.Server.Kestrel/Networking/UvTcpHandle.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvTcpHandle.cs diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvWriteReq.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvWriteReq.cs similarity index 100% rename from src/Microsoft.AspNet.Server.Kestrel/Networking/UvWriteReq.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvWriteReq.cs diff --git a/src/Microsoft.AspNet.Server.Kestrel/Properties/AssemblyInfo.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Properties/AssemblyInfo.cs similarity index 100% rename from src/Microsoft.AspNet.Server.Kestrel/Properties/AssemblyInfo.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Properties/AssemblyInfo.cs diff --git a/src/Microsoft.AspNet.Server.Kestrel/ServerAddress.cs b/src/Microsoft.AspNetCore.Server.Kestrel/ServerAddress.cs similarity index 100% rename from src/Microsoft.AspNet.Server.Kestrel/ServerAddress.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/ServerAddress.cs diff --git a/src/Microsoft.AspNet.Server.Kestrel/ServerFactory.cs b/src/Microsoft.AspNetCore.Server.Kestrel/ServerFactory.cs similarity index 100% rename from src/Microsoft.AspNet.Server.Kestrel/ServerFactory.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/ServerFactory.cs diff --git a/src/Microsoft.AspNet.Server.Kestrel/ServiceContext.cs b/src/Microsoft.AspNetCore.Server.Kestrel/ServiceContext.cs similarity index 100% rename from src/Microsoft.AspNet.Server.Kestrel/ServiceContext.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/ServiceContext.cs diff --git a/src/Microsoft.AspNet.Server.Kestrel/project.json b/src/Microsoft.AspNetCore.Server.Kestrel/project.json similarity index 100% rename from src/Microsoft.AspNet.Server.Kestrel/project.json rename to src/Microsoft.AspNetCore.Server.Kestrel/project.json diff --git a/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs similarity index 100% rename from test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs rename to test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs diff --git a/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/IPv6SupportedConditionAttribute.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/IPv6SupportedConditionAttribute.cs similarity index 100% rename from test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/IPv6SupportedConditionAttribute.cs rename to test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/IPv6SupportedConditionAttribute.cs diff --git a/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/Microsoft.AspNet.Server.Kestrel.FunctionalTests.xproj b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests.xproj similarity index 100% rename from test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/Microsoft.AspNet.Server.Kestrel.FunctionalTests.xproj rename to test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests.xproj diff --git a/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/PathBaseTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/PathBaseTests.cs similarity index 100% rename from test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/PathBaseTests.cs rename to test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/PathBaseTests.cs diff --git a/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/RequestTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs similarity index 100% rename from test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/RequestTests.cs rename to test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs diff --git a/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/ResponseTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs similarity index 100% rename from test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/ResponseTests.cs rename to test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs diff --git a/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/ThreadCountTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ThreadCountTests.cs similarity index 100% rename from test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/ThreadCountTests.cs rename to test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ThreadCountTests.cs diff --git a/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/project.json b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json similarity index 100% rename from test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/project.json rename to test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json diff --git a/test/Microsoft.AspNet.Server.KestrelTests/AsciiDecoder.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/AsciiDecoder.cs similarity index 100% rename from test/Microsoft.AspNet.Server.KestrelTests/AsciiDecoder.cs rename to test/Microsoft.AspNetCore.Server.KestrelTests/AsciiDecoder.cs diff --git a/test/Microsoft.AspNet.Server.KestrelTests/ChunkWriterTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkWriterTests.cs similarity index 100% rename from test/Microsoft.AspNet.Server.KestrelTests/ChunkWriterTests.cs rename to test/Microsoft.AspNetCore.Server.KestrelTests/ChunkWriterTests.cs diff --git a/test/Microsoft.AspNet.Server.KestrelTests/ChunkedResponseTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedResponseTests.cs similarity index 100% rename from test/Microsoft.AspNet.Server.KestrelTests/ChunkedResponseTests.cs rename to test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedResponseTests.cs diff --git a/test/Microsoft.AspNet.Server.KestrelTests/ConnectionFilterTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionFilterTests.cs similarity index 100% rename from test/Microsoft.AspNet.Server.KestrelTests/ConnectionFilterTests.cs rename to test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionFilterTests.cs diff --git a/test/Microsoft.AspNet.Server.KestrelTests/CreateIPEndpointTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/CreateIPEndpointTests.cs similarity index 100% rename from test/Microsoft.AspNet.Server.KestrelTests/CreateIPEndpointTests.cs rename to test/Microsoft.AspNetCore.Server.KestrelTests/CreateIPEndpointTests.cs diff --git a/test/Microsoft.AspNet.Server.KestrelTests/DateHeaderValueManagerTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/DateHeaderValueManagerTests.cs similarity index 100% rename from test/Microsoft.AspNet.Server.KestrelTests/DateHeaderValueManagerTests.cs rename to test/Microsoft.AspNetCore.Server.KestrelTests/DateHeaderValueManagerTests.cs diff --git a/test/Microsoft.AspNet.Server.KestrelTests/DummyApplication.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/DummyApplication.cs similarity index 100% rename from test/Microsoft.AspNet.Server.KestrelTests/DummyApplication.cs rename to test/Microsoft.AspNetCore.Server.KestrelTests/DummyApplication.cs diff --git a/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs similarity index 100% rename from test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs rename to test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs diff --git a/test/Microsoft.AspNet.Server.KestrelTests/FrameFacts.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameFacts.cs similarity index 100% rename from test/Microsoft.AspNet.Server.KestrelTests/FrameFacts.cs rename to test/Microsoft.AspNetCore.Server.KestrelTests/FrameFacts.cs diff --git a/test/Microsoft.AspNet.Server.KestrelTests/FrameRequestHeadersTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameRequestHeadersTests.cs similarity index 100% rename from test/Microsoft.AspNet.Server.KestrelTests/FrameRequestHeadersTests.cs rename to test/Microsoft.AspNetCore.Server.KestrelTests/FrameRequestHeadersTests.cs diff --git a/test/Microsoft.AspNet.Server.KestrelTests/FrameResponseHeadersTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameResponseHeadersTests.cs similarity index 100% rename from test/Microsoft.AspNet.Server.KestrelTests/FrameResponseHeadersTests.cs rename to test/Microsoft.AspNetCore.Server.KestrelTests/FrameResponseHeadersTests.cs diff --git a/test/Microsoft.AspNet.Server.KestrelTests/FrameTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs similarity index 100% rename from test/Microsoft.AspNet.Server.KestrelTests/FrameTests.cs rename to test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs diff --git a/test/Microsoft.AspNet.Server.KestrelTests/HttpsConnectionFilterTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/HttpsConnectionFilterTests.cs similarity index 100% rename from test/Microsoft.AspNet.Server.KestrelTests/HttpsConnectionFilterTests.cs rename to test/Microsoft.AspNetCore.Server.KestrelTests/HttpsConnectionFilterTests.cs diff --git a/test/Microsoft.AspNet.Server.KestrelTests/KestrelServerInformationTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerInformationTests.cs similarity index 100% rename from test/Microsoft.AspNet.Server.KestrelTests/KestrelServerInformationTests.cs rename to test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerInformationTests.cs diff --git a/test/Microsoft.AspNet.Server.KestrelTests/KestrelServerTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerTests.cs similarity index 100% rename from test/Microsoft.AspNet.Server.KestrelTests/KestrelServerTests.cs rename to test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerTests.cs diff --git a/test/Microsoft.AspNet.Server.KestrelTests/LifetimeNotImplemented.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/LifetimeNotImplemented.cs similarity index 100% rename from test/Microsoft.AspNet.Server.KestrelTests/LifetimeNotImplemented.cs rename to test/Microsoft.AspNetCore.Server.KestrelTests/LifetimeNotImplemented.cs diff --git a/test/Microsoft.AspNet.Server.KestrelTests/MemoryPoolBlock2Tests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolBlock2Tests.cs similarity index 100% rename from test/Microsoft.AspNet.Server.KestrelTests/MemoryPoolBlock2Tests.cs rename to test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolBlock2Tests.cs diff --git a/test/Microsoft.AspNet.Server.KestrelTests/MemoryPoolExtensions.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolExtensions.cs similarity index 100% rename from test/Microsoft.AspNet.Server.KestrelTests/MemoryPoolExtensions.cs rename to test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolExtensions.cs diff --git a/test/Microsoft.AspNet.Server.KestrelTests/MemoryPoolIterator2Tests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolIterator2Tests.cs similarity index 100% rename from test/Microsoft.AspNet.Server.KestrelTests/MemoryPoolIterator2Tests.cs rename to test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolIterator2Tests.cs diff --git a/test/Microsoft.AspNet.Server.KestrelTests/MessageBodyTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/MessageBodyTests.cs similarity index 100% rename from test/Microsoft.AspNet.Server.KestrelTests/MessageBodyTests.cs rename to test/Microsoft.AspNetCore.Server.KestrelTests/MessageBodyTests.cs diff --git a/test/Microsoft.AspNet.Server.KestrelTests/Microsoft.AspNet.Server.KestrelTests.xproj b/test/Microsoft.AspNetCore.Server.KestrelTests/Microsoft.AspNetCore.Server.KestrelTests.xproj similarity index 100% rename from test/Microsoft.AspNet.Server.KestrelTests/Microsoft.AspNet.Server.KestrelTests.xproj rename to test/Microsoft.AspNetCore.Server.KestrelTests/Microsoft.AspNetCore.Server.KestrelTests.xproj diff --git a/test/Microsoft.AspNet.Server.KestrelTests/MultipleLoopTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/MultipleLoopTests.cs similarity index 100% rename from test/Microsoft.AspNet.Server.KestrelTests/MultipleLoopTests.cs rename to test/Microsoft.AspNetCore.Server.KestrelTests/MultipleLoopTests.cs diff --git a/test/Microsoft.AspNet.Server.KestrelTests/NetworkingTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/NetworkingTests.cs similarity index 100% rename from test/Microsoft.AspNet.Server.KestrelTests/NetworkingTests.cs rename to test/Microsoft.AspNetCore.Server.KestrelTests/NetworkingTests.cs diff --git a/test/Microsoft.AspNet.Server.KestrelTests/Program.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/Program.cs similarity index 100% rename from test/Microsoft.AspNet.Server.KestrelTests/Program.cs rename to test/Microsoft.AspNetCore.Server.KestrelTests/Program.cs diff --git a/test/Microsoft.AspNet.Server.KestrelTests/ServerAddressFacts.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/ServerAddressFacts.cs similarity index 100% rename from test/Microsoft.AspNet.Server.KestrelTests/ServerAddressFacts.cs rename to test/Microsoft.AspNetCore.Server.KestrelTests/ServerAddressFacts.cs diff --git a/test/Microsoft.AspNet.Server.KestrelTests/SocketInputTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/SocketInputTests.cs similarity index 100% rename from test/Microsoft.AspNet.Server.KestrelTests/SocketInputTests.cs rename to test/Microsoft.AspNetCore.Server.KestrelTests/SocketInputTests.cs diff --git a/test/Microsoft.AspNet.Server.KestrelTests/SocketOutputTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/SocketOutputTests.cs similarity index 100% rename from test/Microsoft.AspNet.Server.KestrelTests/SocketOutputTests.cs rename to test/Microsoft.AspNetCore.Server.KestrelTests/SocketOutputTests.cs diff --git a/test/Microsoft.AspNet.Server.KestrelTests/StreamSocketOutputTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/StreamSocketOutputTests.cs similarity index 100% rename from test/Microsoft.AspNet.Server.KestrelTests/StreamSocketOutputTests.cs rename to test/Microsoft.AspNetCore.Server.KestrelTests/StreamSocketOutputTests.cs diff --git a/test/Microsoft.AspNet.Server.KestrelTests/TestConnection.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/TestConnection.cs similarity index 100% rename from test/Microsoft.AspNet.Server.KestrelTests/TestConnection.cs rename to test/Microsoft.AspNetCore.Server.KestrelTests/TestConnection.cs diff --git a/test/Microsoft.AspNet.Server.KestrelTests/TestDateHeaderValueManager.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/TestDateHeaderValueManager.cs similarity index 100% rename from test/Microsoft.AspNet.Server.KestrelTests/TestDateHeaderValueManager.cs rename to test/Microsoft.AspNetCore.Server.KestrelTests/TestDateHeaderValueManager.cs diff --git a/test/Microsoft.AspNet.Server.KestrelTests/TestHelpers/MockLibuv.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockLibuv.cs similarity index 100% rename from test/Microsoft.AspNet.Server.KestrelTests/TestHelpers/MockLibuv.cs rename to test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockLibuv.cs diff --git a/test/Microsoft.AspNet.Server.KestrelTests/TestHelpers/MockSystemClock.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockSystemClock.cs similarity index 100% rename from test/Microsoft.AspNet.Server.KestrelTests/TestHelpers/MockSystemClock.cs rename to test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockSystemClock.cs diff --git a/test/Microsoft.AspNet.Server.KestrelTests/TestInput.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/TestInput.cs similarity index 100% rename from test/Microsoft.AspNet.Server.KestrelTests/TestInput.cs rename to test/Microsoft.AspNetCore.Server.KestrelTests/TestInput.cs diff --git a/test/Microsoft.AspNet.Server.KestrelTests/TestLogger.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/TestLogger.cs similarity index 100% rename from test/Microsoft.AspNet.Server.KestrelTests/TestLogger.cs rename to test/Microsoft.AspNetCore.Server.KestrelTests/TestLogger.cs diff --git a/test/Microsoft.AspNet.Server.KestrelTests/TestResources/testCert.pfx b/test/Microsoft.AspNetCore.Server.KestrelTests/TestResources/testCert.pfx similarity index 100% rename from test/Microsoft.AspNet.Server.KestrelTests/TestResources/testCert.pfx rename to test/Microsoft.AspNetCore.Server.KestrelTests/TestResources/testCert.pfx diff --git a/test/Microsoft.AspNet.Server.KestrelTests/TestServer.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/TestServer.cs similarity index 100% rename from test/Microsoft.AspNet.Server.KestrelTests/TestServer.cs rename to test/Microsoft.AspNetCore.Server.KestrelTests/TestServer.cs diff --git a/test/Microsoft.AspNet.Server.KestrelTests/TestServiceContext.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/TestServiceContext.cs similarity index 100% rename from test/Microsoft.AspNet.Server.KestrelTests/TestServiceContext.cs rename to test/Microsoft.AspNetCore.Server.KestrelTests/TestServiceContext.cs diff --git a/test/Microsoft.AspNet.Server.KestrelTests/UrlPathDecoder.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/UrlPathDecoder.cs similarity index 100% rename from test/Microsoft.AspNet.Server.KestrelTests/UrlPathDecoder.cs rename to test/Microsoft.AspNetCore.Server.KestrelTests/UrlPathDecoder.cs diff --git a/test/Microsoft.AspNet.Server.KestrelTests/project.json b/test/Microsoft.AspNetCore.Server.KestrelTests/project.json similarity index 100% rename from test/Microsoft.AspNet.Server.KestrelTests/project.json rename to test/Microsoft.AspNetCore.Server.KestrelTests/project.json diff --git a/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/FrameFeatureCollection.cs b/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/FrameFeatureCollection.cs similarity index 100% rename from tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/FrameFeatureCollection.cs rename to tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/FrameFeatureCollection.cs diff --git a/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/KnownHeaders.cs b/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/KnownHeaders.cs similarity index 100% rename from tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/KnownHeaders.cs rename to tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/KnownHeaders.cs diff --git a/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/Microsoft.AspNet.Server.Kestrel.GeneratedCode.xproj b/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode.xproj similarity index 100% rename from tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/Microsoft.AspNet.Server.Kestrel.GeneratedCode.xproj rename to tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode.xproj diff --git a/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/Program.cs b/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/Program.cs similarity index 100% rename from tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/Program.cs rename to tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/Program.cs diff --git a/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/project.json b/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/project.json similarity index 100% rename from tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/project.json rename to tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/project.json diff --git a/tools/Microsoft.AspNet.Server.Kestrel.LibuvCopier/Microsoft.AspNet.Server.Kestrel.LibuvCopier.xproj b/tools/Microsoft.AspNetCore.Server.Kestrel.LibuvCopier/Microsoft.AspNetCore.Server.Kestrel.LibuvCopier.xproj similarity index 100% rename from tools/Microsoft.AspNet.Server.Kestrel.LibuvCopier/Microsoft.AspNet.Server.Kestrel.LibuvCopier.xproj rename to tools/Microsoft.AspNetCore.Server.Kestrel.LibuvCopier/Microsoft.AspNetCore.Server.Kestrel.LibuvCopier.xproj diff --git a/tools/Microsoft.AspNet.Server.Kestrel.LibuvCopier/Program.cs b/tools/Microsoft.AspNetCore.Server.Kestrel.LibuvCopier/Program.cs similarity index 100% rename from tools/Microsoft.AspNet.Server.Kestrel.LibuvCopier/Program.cs rename to tools/Microsoft.AspNetCore.Server.Kestrel.LibuvCopier/Program.cs diff --git a/tools/Microsoft.AspNet.Server.Kestrel.LibuvCopier/project.json b/tools/Microsoft.AspNetCore.Server.Kestrel.LibuvCopier/project.json similarity index 100% rename from tools/Microsoft.AspNet.Server.Kestrel.LibuvCopier/project.json rename to tools/Microsoft.AspNetCore.Server.Kestrel.LibuvCopier/project.json From b062f851dcb1fc9013952fe72e9a087ae36323fe Mon Sep 17 00:00:00 2001 From: "N. Taylor Mullen" Date: Fri, 22 Jan 2016 12:23:51 -0800 Subject: [PATCH 0576/1662] Rename AspNet 5 file contents. See https://github.com/aspnet/Announcements/issues/144 for more information. --- KestrelHttpServer.sln | 14 +- NuGetPackageVerifier.json | 2 +- samples/LargeResponseApp/Startup.cs | 6 +- samples/LargeResponseApp/hosting.json | 4 +- samples/LargeResponseApp/project.json | 4 +- samples/SampleApp/Startup.cs | 12 +- samples/SampleApp/hosting.json | 4 +- samples/SampleApp/project.json | 4 +- .../ClientCertificateMode.cs | 4 +- .../HttpsApplicationBuilderExtensions.cs | 10 +- .../HttpsConnectionFilter.cs | 10 +- .../HttpsConnectionFilterOptions.cs | 4 +- ...soft.AspNetCore.Server.Kestrel.Https.xproj | 4 +- .../Properties/AssemblyInfo.cs | 2 +- .../project.json | 2 +- .../Filter/ConnectionFilterContext.cs | 6 +- .../Filter/FilteredStreamAdapter.cs | 8 +- .../Filter/IConnectionFilter.cs | 4 +- .../Filter/LibuvStream.cs | 6 +- .../Filter/LoggingConnectionFilter.cs | 4 +- ...ggingFilterApplicationBuilderExtensions.cs | 8 +- .../Filter/LoggingStream.cs | 4 +- .../Filter/NoOpConnectionFilter.cs | 8 +- .../Filter/SocketInputStream.cs | 8 +- .../Filter/StreamExtensions.cs | 6 +- .../Filter/StreamSocketOutput.cs | 8 +- .../Http/ChunkWriter.cs | 6 +- .../Http/Connection.cs | 8 +- .../Http/ConnectionContext.cs | 2 +- .../Http/DateHeaderValueManager.cs | 6 +- .../Http/Frame.FeatureCollection.cs | 8 +- .../Http/Frame.Generated.cs | 130 +++++++++--------- .../Http/Frame.cs | 8 +- .../Http/FrameContext.cs | 2 +- .../Http/FrameDuplexStream.cs | 2 +- .../Http/FrameHeaders.Generated.cs | 4 +- .../Http/FrameHeaders.cs | 4 +- .../Http/FrameOfT.cs | 8 +- .../Http/FrameRequestHeaders.cs | 2 +- .../Http/FrameRequestStream.cs | 2 +- .../Http/FrameResponseHeaders.cs | 4 +- .../Http/FrameResponseStream.cs | 2 +- .../Http/FrameStreamState.cs | 4 +- .../Http/IConnectionControl.cs | 2 +- .../Http/IFrameControl.cs | 2 +- .../Http/ISocketOutput.cs | 4 +- .../Http/Listener.cs | 4 +- .../Http/ListenerContext.cs | 6 +- .../Http/ListenerPrimary.cs | 6 +- .../Http/ListenerSecondary.cs | 8 +- .../Http/MessageBody.cs | 2 +- .../Http/PipeListener.cs | 6 +- .../Http/PipeListenerPrimary.cs | 6 +- .../Http/PipeListenerSecondary.cs | 6 +- .../Http/ProduceEndType.cs | 2 +- .../Http/ReasonPhrases.cs | 2 +- .../Http/SocketInput.cs | 4 +- .../Http/SocketInputExtensions.cs | 6 +- .../Http/SocketOutput.cs | 6 +- .../Http/TcpListener.cs | 6 +- .../Http/TcpListenerPrimary.cs | 6 +- .../Http/TcpListenerSecondary.cs | 6 +- .../Http/UrlPathDecoder.cs | 6 +- .../IKestrelServerInformation.cs | 4 +- .../Infrastructure/Constants.cs | 4 +- .../Infrastructure/Disposable.cs | 2 +- .../Infrastructure/IKestrelTrace.cs | 2 +- .../Infrastructure/ISystemClock.cs | 4 +- .../Infrastructure/IThreadPool.cs | 4 +- .../Infrastructure/KestrelThread.cs | 10 +- .../Infrastructure/KestrelTrace.cs | 4 +- .../Infrastructure/LoggingThreadPool.cs | 2 +- .../Infrastructure/MemoryPool2.cs | 4 +- .../Infrastructure/MemoryPoolBlock2.cs | 4 +- .../Infrastructure/MemoryPoolIterator2.cs | 4 +- .../MemoryPoolIterator2Extensions.cs | 4 +- .../Infrastructure/MemoryPoolSlab2.cs | 4 +- .../Infrastructure/SystemClock.cs | 4 +- .../Infrastructure/TaskUtilities.cs | 2 +- .../KestrelEngine.cs | 8 +- .../KestrelServer.cs | 14 +- .../KestrelServerInformation.cs | 6 +- .../Networking/Libuv.cs | 2 +- .../Networking/PlatformApis.cs | 2 +- .../Networking/SockAddr.cs | 4 +- .../Networking/UvAsyncHandle.cs | 4 +- .../Networking/UvConnectRequest.cs | 4 +- .../Networking/UvException.cs | 4 +- .../Networking/UvHandle.cs | 4 +- .../Networking/UvLoopHandle.cs | 4 +- .../Networking/UvMemory.cs | 4 +- .../Networking/UvPipeHandle.cs | 4 +- .../Networking/UvRequest.cs | 6 +- .../Networking/UvShutdownReq.cs | 4 +- .../Networking/UvStreamHandle.cs | 4 +- .../Networking/UvTcpHandle.cs | 4 +- .../Networking/UvWriteReq.cs | 4 +- .../Properties/AssemblyInfo.cs | 2 +- .../ServerAddress.cs | 6 +- .../ServerFactory.cs | 12 +- .../ServiceContext.cs | 14 +- .../project.json | 14 +- .../AddressRegistrationTests.cs | 16 +-- .../IPv6SupportedConditionAttribute.cs | 4 +- ...tCore.Server.Kestrel.FunctionalTests.xproj | 4 +- .../PathBaseTests.cs | 14 +- .../RequestTests.cs | 18 +-- .../ResponseTests.cs | 18 +-- .../ThreadCountTests.cs | 12 +- .../project.json | 6 +- .../AsciiDecoder.cs | 6 +- .../ChunkWriterTests.cs | 6 +- .../ChunkedResponseTests.cs | 6 +- .../ConnectionFilterTests.cs | 12 +- .../CreateIPEndpointTests.cs | 8 +- .../DateHeaderValueManagerTests.cs | 10 +- .../DummyApplication.cs | 12 +- .../EngineTests.cs | 16 +-- .../FrameFacts.cs | 10 +- .../FrameRequestHeadersTests.cs | 4 +- .../FrameResponseHeadersTests.cs | 6 +- .../FrameTests.cs | 8 +- .../HttpsConnectionFilterTests.cs | 14 +- .../KestrelServerInformationTests.cs | 6 +- .../KestrelServerTests.cs | 12 +- .../LifetimeNotImplemented.cs | 6 +- .../MemoryPoolBlock2Tests.cs | 6 +- .../MemoryPoolExtensions.cs | 4 +- .../MemoryPoolIterator2Tests.cs | 6 +- .../MessageBodyTests.cs | 4 +- .../MultipleLoopTests.cs | 10 +- .../NetworkingTests.cs | 8 +- .../Program.cs | 4 +- .../ServerAddressFacts.cs | 4 +- .../SocketInputTests.cs | 10 +- .../SocketOutputTests.cs | 14 +- .../StreamSocketOutputTests.cs | 8 +- .../TestConnection.cs | 4 +- .../TestDateHeaderValueManager.cs | 6 +- .../TestHelpers/MockLibuv.cs | 4 +- .../TestHelpers/MockSystemClock.cs | 6 +- .../TestInput.cs | 10 +- .../TestLogger.cs | 4 +- .../TestServer.cs | 10 +- .../TestServiceContext.cs | 12 +- .../UrlPathDecoder.cs | 8 +- .../project.json | 8 +- .../FrameFeatureCollection.cs | 14 +- .../KnownHeaders.cs | 6 +- ...NetCore.Server.Kestrel.GeneratedCode.xproj | 4 +- .../Program.cs | 4 +- .../project.json | 6 +- ...spNetCore.Server.Kestrel.LibuvCopier.xproj | 4 +- .../Program.cs | 6 +- .../project.json | 4 +- 155 files changed, 541 insertions(+), 541 deletions(-) diff --git a/KestrelHttpServer.sln b/KestrelHttpServer.sln index a0670dfc2a..f54a7e5fa5 100644 --- a/KestrelHttpServer.sln +++ b/KestrelHttpServer.sln @@ -1,11 +1,11 @@ - + Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 14 VisualStudioVersion = 14.0.23107.0 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.Server.Kestrel", "src\Microsoft.AspNet.Server.Kestrel\Microsoft.AspNet.Server.Kestrel.xproj", "{F510611A-3BEE-4B88-A613-5F4A74ED82A1}" +Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNetCore.Server.Kestrel", "src\Microsoft.AspNetCore.Server.Kestrel\Microsoft.AspNetCore.Server.Kestrel.xproj", "{F510611A-3BEE-4B88-A613-5F4A74ED82A1}" EndProject -Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.Server.KestrelTests", "test\Microsoft.AspNet.Server.KestrelTests\Microsoft.AspNet.Server.KestrelTests.xproj", "{37F3BFB2-6454-49E5-9D7F-581BF755CCFE}" +Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNetCore.Server.KestrelTests", "test\Microsoft.AspNetCore.Server.KestrelTests\Microsoft.AspNetCore.Server.KestrelTests.xproj", "{37F3BFB2-6454-49E5-9D7F-581BF755CCFE}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{7972A5D6-3385-4127-9277-428506DD44FF}" ProjectSection(SolutionItems) = preProject @@ -25,17 +25,17 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "samples", "samples", "{8A3D EndProject Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "LargeResponseApp", "samples\LargeResponseApp\LargeResponseApp.xproj", "{B35D4D31-E74C-4646-8A11-7A7A40F0021E}" EndProject -Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.Server.Kestrel.GeneratedCode", "tools\Microsoft.AspNet.Server.Kestrel.GeneratedCode\Microsoft.AspNet.Server.Kestrel.GeneratedCode.xproj", "{BD2D4D29-1BD9-40D0-BB31-337D5416B63C}" +Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNetCore.Server.Kestrel.GeneratedCode", "tools\Microsoft.AspNetCore.Server.Kestrel.GeneratedCode\Microsoft.AspNetCore.Server.Kestrel.GeneratedCode.xproj", "{BD2D4D29-1BD9-40D0-BB31-337D5416B63C}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tools", "tools", "{327F7880-D9AF-46BD-B45C-3B7E34A01DFD}" EndProject Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.StandardsPolice", "tools\Microsoft.StandardsPolice\Microsoft.StandardsPolice.xproj", "{82295647-7C1C-4671-BAB6-0FEF58F949EC}" EndProject -Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.Server.Kestrel.LibuvCopier", "tools\Microsoft.AspNet.Server.Kestrel.LibuvCopier\Microsoft.AspNet.Server.Kestrel.LibuvCopier.xproj", "{8CBA6FE3-3CC9-4420-8AA3-123E983734C2}" +Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNetCore.Server.Kestrel.LibuvCopier", "tools\Microsoft.AspNetCore.Server.Kestrel.LibuvCopier\Microsoft.AspNetCore.Server.Kestrel.LibuvCopier.xproj", "{8CBA6FE3-3CC9-4420-8AA3-123E983734C2}" EndProject -Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.Server.Kestrel.Https", "src\Microsoft.AspNet.Server.Kestrel.Https\Microsoft.AspNet.Server.Kestrel.Https.xproj", "{5F64B3C3-0C2E-431A-B820-A81BBFC863DA}" +Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNetCore.Server.Kestrel.Https", "src\Microsoft.AspNetCore.Server.Kestrel.Https\Microsoft.AspNetCore.Server.Kestrel.Https.xproj", "{5F64B3C3-0C2E-431A-B820-A81BBFC863DA}" EndProject -Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.Server.Kestrel.FunctionalTests", "test\Microsoft.AspNet.Server.Kestrel.FunctionalTests\Microsoft.AspNet.Server.Kestrel.FunctionalTests.xproj", "{9559A5F1-080C-4909-B6CF-7E4B3DC55748}" +Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNetCore.Server.Kestrel.FunctionalTests", "test\Microsoft.AspNetCore.Server.Kestrel.FunctionalTests\Microsoft.AspNetCore.Server.Kestrel.FunctionalTests.xproj", "{9559A5F1-080C-4909-B6CF-7E4B3DC55748}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/NuGetPackageVerifier.json b/NuGetPackageVerifier.json index 1ae60f54db..a79bd3779c 100644 --- a/NuGetPackageVerifier.json +++ b/NuGetPackageVerifier.json @@ -9,7 +9,7 @@ "StrictSemanticVersionValidationRule" ], "packages": { - "Microsoft.AspNet.Server.Kestrel": { } + "Microsoft.AspNetCore.Server.Kestrel": { } } }, "Default": { // Rules to run for packages not listed in any other set. diff --git a/samples/LargeResponseApp/Startup.cs b/samples/LargeResponseApp/Startup.cs index 241d754a38..a6cba98657 100644 --- a/samples/LargeResponseApp/Startup.cs +++ b/samples/LargeResponseApp/Startup.cs @@ -1,10 +1,10 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Text; using System.Threading.Tasks; -using Microsoft.AspNet.Builder; -using Microsoft.AspNet.Hosting; +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Hosting; namespace LargeResponseApp { diff --git a/samples/LargeResponseApp/hosting.json b/samples/LargeResponseApp/hosting.json index 7e1c57a3f0..72788f30a9 100644 --- a/samples/LargeResponseApp/hosting.json +++ b/samples/LargeResponseApp/hosting.json @@ -1,4 +1,4 @@ -{ - "server": "Microsoft.AspNet.Server.Kestrel", +{ + "server": "Microsoft.AspNetCore.Server.Kestrel", "server.urls": "http://localhost:5001/" } \ No newline at end of file diff --git a/samples/LargeResponseApp/project.json b/samples/LargeResponseApp/project.json index 2fb9fdb1a0..0b96a43065 100644 --- a/samples/LargeResponseApp/project.json +++ b/samples/LargeResponseApp/project.json @@ -1,7 +1,7 @@ -{ +{ "version": "1.0.0-*", "dependencies": { - "Microsoft.AspNet.Server.Kestrel": "1.0.0-*" + "Microsoft.AspNetCore.Server.Kestrel": "1.0.0-*" }, "compilationOptions": { "emitEntryPoint": true diff --git a/samples/SampleApp/Startup.cs b/samples/SampleApp/Startup.cs index 830e6283a6..c593da33a6 100644 --- a/samples/SampleApp/Startup.cs +++ b/samples/SampleApp/Startup.cs @@ -4,11 +4,11 @@ using System; using System.IO; using System.Security.Cryptography.X509Certificates; -using Microsoft.AspNet.Builder; -using Microsoft.AspNet.Hosting; -using Microsoft.AspNet.Http; -using Microsoft.AspNet.Server.Kestrel; -using Microsoft.AspNet.Server.Kestrel.Filter; +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Server.Kestrel; +using Microsoft.AspNetCore.Server.Kestrel.Filter; using Microsoft.Extensions.Logging; using Microsoft.Extensions.PlatformAbstractions; @@ -26,7 +26,7 @@ namespace SampleApp var testCertPath = Path.Combine( env.ApplicationBasePath, - @"../../test/Microsoft.AspNet.Server.KestrelTests/TestResources/testCert.pfx"); + @"../../test/Microsoft.AspNetCore.Server.KestrelTests/TestResources/testCert.pfx"); if (File.Exists(testCertPath)) { diff --git a/samples/SampleApp/hosting.json b/samples/SampleApp/hosting.json index 66f354cbc2..5d7efdc792 100644 --- a/samples/SampleApp/hosting.json +++ b/samples/SampleApp/hosting.json @@ -1,4 +1,4 @@ -{ - "server": "Microsoft.AspNet.Server.Kestrel", +{ + "server": "Microsoft.AspNetCore.Server.Kestrel", "server.urls": "http://localhost:5000;https://localhost:5001" } diff --git a/samples/SampleApp/project.json b/samples/SampleApp/project.json index 42f19ecb21..d96001e9bd 100644 --- a/samples/SampleApp/project.json +++ b/samples/SampleApp/project.json @@ -1,8 +1,8 @@ { "version": "1.0.0-*", "dependencies": { - "Microsoft.AspNet.Server.Kestrel": "1.0.0-*", - "Microsoft.AspNet.Server.Kestrel.Https": "1.0.0-*", + "Microsoft.AspNetCore.Server.Kestrel": "1.0.0-*", + "Microsoft.AspNetCore.Server.Kestrel.Https": "1.0.0-*", "Microsoft.Extensions.Logging.Console": "1.0.0-*" }, "compilationOptions": { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Https/ClientCertificateMode.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Https/ClientCertificateMode.cs index 34e8b839eb..9697cb6476 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Https/ClientCertificateMode.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Https/ClientCertificateMode.cs @@ -1,7 +1,7 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -namespace Microsoft.AspNet.Server.Kestrel.Https +namespace Microsoft.AspNetCore.Server.Kestrel.Https { public enum ClientCertificateMode { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Https/HttpsApplicationBuilderExtensions.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Https/HttpsApplicationBuilderExtensions.cs index e31f0f6482..eb8a95862b 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Https/HttpsApplicationBuilderExtensions.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Https/HttpsApplicationBuilderExtensions.cs @@ -1,12 +1,12 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Security.Cryptography.X509Certificates; -using Microsoft.AspNet.Builder; -using Microsoft.AspNet.Http.Features; -using Microsoft.AspNet.Server.Kestrel.Https; +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Http.Features; +using Microsoft.AspNetCore.Server.Kestrel.Https; -namespace Microsoft.AspNet.Server.Kestrel.Filter +namespace Microsoft.AspNetCore.Server.Kestrel.Filter { public static class HttpsApplicationBuilderExtensions { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Https/HttpsConnectionFilter.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Https/HttpsConnectionFilter.cs index 615a846c1a..55f1fc1ab7 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Https/HttpsConnectionFilter.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Https/HttpsConnectionFilter.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -6,11 +6,11 @@ using System.Net.Security; using System.Security.Authentication; using System.Security.Cryptography.X509Certificates; using System.Threading.Tasks; -using Microsoft.AspNet.Http.Features; -using Microsoft.AspNet.Http.Features.Internal; -using Microsoft.AspNet.Server.Kestrel.Filter; +using Microsoft.AspNetCore.Http.Features; +using Microsoft.AspNetCore.Http.Features.Internal; +using Microsoft.AspNetCore.Server.Kestrel.Filter; -namespace Microsoft.AspNet.Server.Kestrel.Https +namespace Microsoft.AspNetCore.Server.Kestrel.Https { public class HttpsConnectionFilter : IConnectionFilter { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Https/HttpsConnectionFilterOptions.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Https/HttpsConnectionFilterOptions.cs index e066c17f3c..a33e3b090d 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Https/HttpsConnectionFilterOptions.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Https/HttpsConnectionFilterOptions.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -6,7 +6,7 @@ using System.Net.Security; using System.Security.Authentication; using System.Security.Cryptography.X509Certificates; -namespace Microsoft.AspNet.Server.Kestrel.Https +namespace Microsoft.AspNetCore.Server.Kestrel.Https { public class HttpsConnectionFilterOptions { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Https/Microsoft.AspNetCore.Server.Kestrel.Https.xproj b/src/Microsoft.AspNetCore.Server.Kestrel.Https/Microsoft.AspNetCore.Server.Kestrel.Https.xproj index 4ae185e402..31375db430 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Https/Microsoft.AspNetCore.Server.Kestrel.Https.xproj +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Https/Microsoft.AspNetCore.Server.Kestrel.Https.xproj @@ -1,4 +1,4 @@ - + 14.0 @@ -8,7 +8,7 @@ 5f64b3c3-0c2e-431a-b820-a81bbfc863da - Microsoft.AspNet.Server.Kestrel.Https + Microsoft.AspNetCore.Server.Kestrel.Https ..\..\artifacts\obj\$(MSBuildProjectName) ..\..\artifacts\bin\$(MSBuildProjectName)\ diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Https/Properties/AssemblyInfo.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Https/Properties/AssemblyInfo.cs index a8f71a20f0..24e236d5f2 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Https/Properties/AssemblyInfo.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Https/Properties/AssemblyInfo.cs @@ -5,6 +5,6 @@ using System.Reflection; using System.Resources; using System.Runtime.CompilerServices; -[assembly: InternalsVisibleTo("Microsoft.AspNet.Server.KestrelTests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")] +[assembly: InternalsVisibleTo("Microsoft.AspNetCore.Server.KestrelTests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")] [assembly: AssemblyMetadata("Serviceable", "True")] [assembly: NeutralResourcesLanguage("en-us")] diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Https/project.json b/src/Microsoft.AspNetCore.Server.Kestrel.Https/project.json index 9598ce03d5..d2cb35dcdb 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Https/project.json +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Https/project.json @@ -9,7 +9,7 @@ "url": "git://github.com/aspnet/kestrelhttpserver" }, "dependencies": { - "Microsoft.AspNet.Server.Kestrel": "1.0.0-*" + "Microsoft.AspNetCore.Server.Kestrel": "1.0.0-*" }, "frameworks": { "net451": { }, diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Filter/ConnectionFilterContext.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Filter/ConnectionFilterContext.cs index fc4f0384c6..386753342f 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Filter/ConnectionFilterContext.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Filter/ConnectionFilterContext.cs @@ -1,11 +1,11 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; using System.IO; -using Microsoft.AspNet.Http.Features; +using Microsoft.AspNetCore.Http.Features; -namespace Microsoft.AspNet.Server.Kestrel.Filter +namespace Microsoft.AspNetCore.Server.Kestrel.Filter { public class ConnectionFilterContext { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Filter/FilteredStreamAdapter.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Filter/FilteredStreamAdapter.cs index 2697d45b71..de144a0cc0 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Filter/FilteredStreamAdapter.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Filter/FilteredStreamAdapter.cs @@ -1,14 +1,14 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; using System.IO; using System.Threading.Tasks; -using Microsoft.AspNet.Server.Kestrel.Http; -using Microsoft.AspNet.Server.Kestrel.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Http; +using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; using Microsoft.Extensions.Logging; -namespace Microsoft.AspNet.Server.Kestrel.Filter +namespace Microsoft.AspNetCore.Server.Kestrel.Filter { public class FilteredStreamAdapter { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Filter/IConnectionFilter.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Filter/IConnectionFilter.cs index 437e4e3ed9..0447f8b07a 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Filter/IConnectionFilter.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Filter/IConnectionFilter.cs @@ -1,9 +1,9 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Threading.Tasks; -namespace Microsoft.AspNet.Server.Kestrel.Filter +namespace Microsoft.AspNetCore.Server.Kestrel.Filter { public interface IConnectionFilter { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Filter/LibuvStream.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Filter/LibuvStream.cs index 1e019c8381..081861a9ca 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Filter/LibuvStream.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Filter/LibuvStream.cs @@ -1,13 +1,13 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; using System.IO; using System.Threading; using System.Threading.Tasks; -using Microsoft.AspNet.Server.Kestrel.Http; +using Microsoft.AspNetCore.Server.Kestrel.Http; -namespace Microsoft.AspNet.Server.Kestrel.Filter +namespace Microsoft.AspNetCore.Server.Kestrel.Filter { public class LibuvStream : Stream { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Filter/LoggingConnectionFilter.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Filter/LoggingConnectionFilter.cs index e34e4fcb50..81c900d8d3 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Filter/LoggingConnectionFilter.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Filter/LoggingConnectionFilter.cs @@ -1,11 +1,11 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; using System.Threading.Tasks; using Microsoft.Extensions.Logging; -namespace Microsoft.AspNet.Server.Kestrel.Filter +namespace Microsoft.AspNetCore.Server.Kestrel.Filter { public class LoggingConnectionFilter : IConnectionFilter { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Filter/LoggingFilterApplicationBuilderExtensions.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Filter/LoggingFilterApplicationBuilderExtensions.cs index de0ffab1ac..8d373f5897 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Filter/LoggingFilterApplicationBuilderExtensions.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Filter/LoggingFilterApplicationBuilderExtensions.cs @@ -1,12 +1,12 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using Microsoft.AspNet.Builder; -using Microsoft.AspNet.Http.Features; +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Http.Features; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; -namespace Microsoft.AspNet.Server.Kestrel.Filter +namespace Microsoft.AspNetCore.Server.Kestrel.Filter { public static class LoggingFilterApplicationBuilderExtensions { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Filter/LoggingStream.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Filter/LoggingStream.cs index efec582245..a292850a82 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Filter/LoggingStream.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Filter/LoggingStream.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.IO; @@ -7,7 +7,7 @@ using System.Threading; using System.Threading.Tasks; using Microsoft.Extensions.Logging; -namespace Microsoft.AspNet.Server.Kestrel.Filter +namespace Microsoft.AspNetCore.Server.Kestrel.Filter { internal class LoggingStream : Stream { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Filter/NoOpConnectionFilter.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Filter/NoOpConnectionFilter.cs index 663aea65d3..f41316e21f 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Filter/NoOpConnectionFilter.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Filter/NoOpConnectionFilter.cs @@ -1,11 +1,11 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Threading.Tasks; -using Microsoft.AspNet.Http.Features; -using Microsoft.AspNet.Server.Kestrel.Infrastructure; +using Microsoft.AspNetCore.Http.Features; +using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; -namespace Microsoft.AspNet.Server.Kestrel.Filter +namespace Microsoft.AspNetCore.Server.Kestrel.Filter { public class NoOpConnectionFilter : IConnectionFilter { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Filter/SocketInputStream.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Filter/SocketInputStream.cs index d6cc5748f8..b10b1f9c69 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Filter/SocketInputStream.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Filter/SocketInputStream.cs @@ -1,14 +1,14 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; using System.IO; using System.Threading; using System.Threading.Tasks; -using Microsoft.AspNet.Server.Kestrel.Http; -using Microsoft.AspNet.Server.Kestrel.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Http; +using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; -namespace Microsoft.AspNet.Server.Kestrel.Filter +namespace Microsoft.AspNetCore.Server.Kestrel.Filter { /// /// This is a write-only stream that copies what is written into a diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Filter/StreamExtensions.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Filter/StreamExtensions.cs index af3e77d15f..72c3fb9fd9 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Filter/StreamExtensions.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Filter/StreamExtensions.cs @@ -1,11 +1,11 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.IO; using System.Threading.Tasks; -using Microsoft.AspNet.Server.Kestrel.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; -namespace Microsoft.AspNet.Server.Kestrel.Filter +namespace Microsoft.AspNetCore.Server.Kestrel.Filter { public static class StreamExtensions { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Filter/StreamSocketOutput.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Filter/StreamSocketOutput.cs index 6ee20338f4..ccc752ae9b 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Filter/StreamSocketOutput.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Filter/StreamSocketOutput.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -6,10 +6,10 @@ using System.IO; using System.Text; using System.Threading; using System.Threading.Tasks; -using Microsoft.AspNet.Server.Kestrel.Http; -using Microsoft.AspNet.Server.Kestrel.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Http; +using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; -namespace Microsoft.AspNet.Server.Kestrel.Filter +namespace Microsoft.AspNetCore.Server.Kestrel.Filter { public class StreamSocketOutput : ISocketOutput { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/ChunkWriter.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/ChunkWriter.cs index 2d38857005..e6f99c9d53 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/ChunkWriter.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/ChunkWriter.cs @@ -1,11 +1,11 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; using System.Text; -using Microsoft.AspNet.Server.Kestrel.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; -namespace Microsoft.AspNet.Server.Kestrel.Http +namespace Microsoft.AspNetCore.Server.Kestrel.Http { public static class ChunkWriter { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Connection.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Connection.cs index 96b6c0b93a..52790ec65a 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Connection.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Connection.cs @@ -4,12 +4,12 @@ using System; using System.Net; using System.Threading; -using Microsoft.AspNet.Server.Kestrel.Filter; -using Microsoft.AspNet.Server.Kestrel.Infrastructure; -using Microsoft.AspNet.Server.Kestrel.Networking; +using Microsoft.AspNetCore.Server.Kestrel.Filter; +using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Networking; using Microsoft.Extensions.Logging; -namespace Microsoft.AspNet.Server.Kestrel.Http +namespace Microsoft.AspNetCore.Server.Kestrel.Http { public class Connection : ConnectionContext, IConnectionControl { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/ConnectionContext.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/ConnectionContext.cs index 4720aa40e5..3a624d3659 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/ConnectionContext.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/ConnectionContext.cs @@ -1,7 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -namespace Microsoft.AspNet.Server.Kestrel.Http +namespace Microsoft.AspNetCore.Server.Kestrel.Http { public class ConnectionContext : ListenerContext { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/DateHeaderValueManager.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/DateHeaderValueManager.cs index 4a3cff6eb4..45e91194d6 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/DateHeaderValueManager.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/DateHeaderValueManager.cs @@ -1,12 +1,12 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; using System.Text; using System.Threading; -using Microsoft.AspNet.Server.Kestrel.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; -namespace Microsoft.AspNet.Server.Kestrel.Http +namespace Microsoft.AspNetCore.Server.Kestrel.Http { /// /// Manages the generation of the date header value. diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.FeatureCollection.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.FeatureCollection.cs index 91aa90eb37..8a10a7c618 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.FeatureCollection.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.FeatureCollection.cs @@ -9,12 +9,12 @@ using System.Linq; using System.Net; using System.Threading; using System.Threading.Tasks; -using Microsoft.AspNet.Http; -using Microsoft.AspNet.Http.Features; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Http.Features; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Primitives; -namespace Microsoft.AspNet.Server.Kestrel.Http +namespace Microsoft.AspNetCore.Server.Kestrel.Http { public partial class Frame : IFeatureCollection, IHttpRequestFeature, @@ -25,7 +25,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { // NOTE: When feature interfaces are added to or removed from this Frame class implementation, // then the list of `implementedFeatures` in the generated code project MUST also be updated. - // See also: tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/FrameFeatureCollection.cs + // See also: tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/FrameFeatureCollection.cs private int _featureRevision; diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.Generated.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.Generated.cs index e449f94d83..49911c71cc 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.Generated.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.Generated.cs @@ -2,26 +2,26 @@ using System; using System.Collections.Generic; -namespace Microsoft.AspNet.Server.Kestrel.Http +namespace Microsoft.AspNetCore.Server.Kestrel.Http { public partial class Frame { - private static readonly Type IHttpRequestFeatureType = typeof(global::Microsoft.AspNet.Http.Features.IHttpRequestFeature); - private static readonly Type IHttpResponseFeatureType = typeof(global::Microsoft.AspNet.Http.Features.IHttpResponseFeature); - private static readonly Type IHttpRequestIdentifierFeatureType = typeof(global::Microsoft.AspNet.Http.Features.IHttpRequestIdentifierFeature); - private static readonly Type IServiceProvidersFeatureType = typeof(global::Microsoft.AspNet.Http.Features.Internal.IServiceProvidersFeature); - private static readonly Type IHttpRequestLifetimeFeatureType = typeof(global::Microsoft.AspNet.Http.Features.IHttpRequestLifetimeFeature); - private static readonly Type IHttpConnectionFeatureType = typeof(global::Microsoft.AspNet.Http.Features.IHttpConnectionFeature); - private static readonly Type IHttpAuthenticationFeatureType = typeof(global::Microsoft.AspNet.Http.Features.Authentication.IHttpAuthenticationFeature); - private static readonly Type IQueryFeatureType = typeof(global::Microsoft.AspNet.Http.Features.Internal.IQueryFeature); - private static readonly Type IFormFeatureType = typeof(global::Microsoft.AspNet.Http.Features.Internal.IFormFeature); - private static readonly Type IHttpUpgradeFeatureType = typeof(global::Microsoft.AspNet.Http.Features.IHttpUpgradeFeature); - private static readonly Type IResponseCookiesFeatureType = typeof(global::Microsoft.AspNet.Http.Features.Internal.IResponseCookiesFeature); - private static readonly Type IItemsFeatureType = typeof(global::Microsoft.AspNet.Http.Features.Internal.IItemsFeature); - private static readonly Type ITlsConnectionFeatureType = typeof(global::Microsoft.AspNet.Http.Features.ITlsConnectionFeature); - private static readonly Type IHttpWebSocketFeatureType = typeof(global::Microsoft.AspNet.Http.Features.IHttpWebSocketFeature); - private static readonly Type ISessionFeatureType = typeof(global::Microsoft.AspNet.Http.Features.ISessionFeature); - private static readonly Type IHttpSendFileFeatureType = typeof(global::Microsoft.AspNet.Http.Features.IHttpSendFileFeature); + private static readonly Type IHttpRequestFeatureType = typeof(global::Microsoft.AspNetCore.Http.Features.IHttpRequestFeature); + private static readonly Type IHttpResponseFeatureType = typeof(global::Microsoft.AspNetCore.Http.Features.IHttpResponseFeature); + private static readonly Type IHttpRequestIdentifierFeatureType = typeof(global::Microsoft.AspNetCore.Http.Features.IHttpRequestIdentifierFeature); + private static readonly Type IServiceProvidersFeatureType = typeof(global::Microsoft.AspNetCore.Http.Features.Internal.IServiceProvidersFeature); + private static readonly Type IHttpRequestLifetimeFeatureType = typeof(global::Microsoft.AspNetCore.Http.Features.IHttpRequestLifetimeFeature); + private static readonly Type IHttpConnectionFeatureType = typeof(global::Microsoft.AspNetCore.Http.Features.IHttpConnectionFeature); + private static readonly Type IHttpAuthenticationFeatureType = typeof(global::Microsoft.AspNetCore.Http.Features.Authentication.IHttpAuthenticationFeature); + private static readonly Type IQueryFeatureType = typeof(global::Microsoft.AspNetCore.Http.Features.Internal.IQueryFeature); + private static readonly Type IFormFeatureType = typeof(global::Microsoft.AspNetCore.Http.Features.Internal.IFormFeature); + private static readonly Type IHttpUpgradeFeatureType = typeof(global::Microsoft.AspNetCore.Http.Features.IHttpUpgradeFeature); + private static readonly Type IResponseCookiesFeatureType = typeof(global::Microsoft.AspNetCore.Http.Features.Internal.IResponseCookiesFeature); + private static readonly Type IItemsFeatureType = typeof(global::Microsoft.AspNetCore.Http.Features.Internal.IItemsFeature); + private static readonly Type ITlsConnectionFeatureType = typeof(global::Microsoft.AspNetCore.Http.Features.ITlsConnectionFeature); + private static readonly Type IHttpWebSocketFeatureType = typeof(global::Microsoft.AspNetCore.Http.Features.IHttpWebSocketFeature); + private static readonly Type ISessionFeatureType = typeof(global::Microsoft.AspNetCore.Http.Features.ISessionFeature); + private static readonly Type IHttpSendFileFeatureType = typeof(global::Microsoft.AspNetCore.Http.Features.IHttpSendFileFeature); private object _currentIHttpRequestFeature; private object _currentIHttpResponseFeature; @@ -63,67 +63,67 @@ namespace Microsoft.AspNet.Server.Kestrel.Http private object FastFeatureGet(Type key) { - if (key == typeof(global::Microsoft.AspNet.Http.Features.IHttpRequestFeature)) + if (key == typeof(global::Microsoft.AspNetCore.Http.Features.IHttpRequestFeature)) { return _currentIHttpRequestFeature; } - if (key == typeof(global::Microsoft.AspNet.Http.Features.IHttpResponseFeature)) + if (key == typeof(global::Microsoft.AspNetCore.Http.Features.IHttpResponseFeature)) { return _currentIHttpResponseFeature; } - if (key == typeof(global::Microsoft.AspNet.Http.Features.IHttpRequestIdentifierFeature)) + if (key == typeof(global::Microsoft.AspNetCore.Http.Features.IHttpRequestIdentifierFeature)) { return _currentIHttpRequestIdentifierFeature; } - if (key == typeof(global::Microsoft.AspNet.Http.Features.Internal.IServiceProvidersFeature)) + if (key == typeof(global::Microsoft.AspNetCore.Http.Features.Internal.IServiceProvidersFeature)) { return _currentIServiceProvidersFeature; } - if (key == typeof(global::Microsoft.AspNet.Http.Features.IHttpRequestLifetimeFeature)) + if (key == typeof(global::Microsoft.AspNetCore.Http.Features.IHttpRequestLifetimeFeature)) { return _currentIHttpRequestLifetimeFeature; } - if (key == typeof(global::Microsoft.AspNet.Http.Features.IHttpConnectionFeature)) + if (key == typeof(global::Microsoft.AspNetCore.Http.Features.IHttpConnectionFeature)) { return _currentIHttpConnectionFeature; } - if (key == typeof(global::Microsoft.AspNet.Http.Features.Authentication.IHttpAuthenticationFeature)) + if (key == typeof(global::Microsoft.AspNetCore.Http.Features.Authentication.IHttpAuthenticationFeature)) { return _currentIHttpAuthenticationFeature; } - if (key == typeof(global::Microsoft.AspNet.Http.Features.Internal.IQueryFeature)) + if (key == typeof(global::Microsoft.AspNetCore.Http.Features.Internal.IQueryFeature)) { return _currentIQueryFeature; } - if (key == typeof(global::Microsoft.AspNet.Http.Features.Internal.IFormFeature)) + if (key == typeof(global::Microsoft.AspNetCore.Http.Features.Internal.IFormFeature)) { return _currentIFormFeature; } - if (key == typeof(global::Microsoft.AspNet.Http.Features.IHttpUpgradeFeature)) + if (key == typeof(global::Microsoft.AspNetCore.Http.Features.IHttpUpgradeFeature)) { return _currentIHttpUpgradeFeature; } - if (key == typeof(global::Microsoft.AspNet.Http.Features.Internal.IResponseCookiesFeature)) + if (key == typeof(global::Microsoft.AspNetCore.Http.Features.Internal.IResponseCookiesFeature)) { return _currentIResponseCookiesFeature; } - if (key == typeof(global::Microsoft.AspNet.Http.Features.Internal.IItemsFeature)) + if (key == typeof(global::Microsoft.AspNetCore.Http.Features.Internal.IItemsFeature)) { return _currentIItemsFeature; } - if (key == typeof(global::Microsoft.AspNet.Http.Features.ITlsConnectionFeature)) + if (key == typeof(global::Microsoft.AspNetCore.Http.Features.ITlsConnectionFeature)) { return _currentITlsConnectionFeature; } - if (key == typeof(global::Microsoft.AspNet.Http.Features.IHttpWebSocketFeature)) + if (key == typeof(global::Microsoft.AspNetCore.Http.Features.IHttpWebSocketFeature)) { return _currentIHttpWebSocketFeature; } - if (key == typeof(global::Microsoft.AspNet.Http.Features.ISessionFeature)) + if (key == typeof(global::Microsoft.AspNetCore.Http.Features.ISessionFeature)) { return _currentISessionFeature; } - if (key == typeof(global::Microsoft.AspNet.Http.Features.IHttpSendFileFeature)) + if (key == typeof(global::Microsoft.AspNetCore.Http.Features.IHttpSendFileFeature)) { return _currentIHttpSendFileFeature; } @@ -134,82 +134,82 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { _featureRevision++; - if (key == typeof(global::Microsoft.AspNet.Http.Features.IHttpRequestFeature)) + if (key == typeof(global::Microsoft.AspNetCore.Http.Features.IHttpRequestFeature)) { _currentIHttpRequestFeature = feature; return; } - if (key == typeof(global::Microsoft.AspNet.Http.Features.IHttpResponseFeature)) + if (key == typeof(global::Microsoft.AspNetCore.Http.Features.IHttpResponseFeature)) { _currentIHttpResponseFeature = feature; return; } - if (key == typeof(global::Microsoft.AspNet.Http.Features.IHttpRequestIdentifierFeature)) + if (key == typeof(global::Microsoft.AspNetCore.Http.Features.IHttpRequestIdentifierFeature)) { _currentIHttpRequestIdentifierFeature = feature; return; } - if (key == typeof(global::Microsoft.AspNet.Http.Features.Internal.IServiceProvidersFeature)) + if (key == typeof(global::Microsoft.AspNetCore.Http.Features.Internal.IServiceProvidersFeature)) { _currentIServiceProvidersFeature = feature; return; } - if (key == typeof(global::Microsoft.AspNet.Http.Features.IHttpRequestLifetimeFeature)) + if (key == typeof(global::Microsoft.AspNetCore.Http.Features.IHttpRequestLifetimeFeature)) { _currentIHttpRequestLifetimeFeature = feature; return; } - if (key == typeof(global::Microsoft.AspNet.Http.Features.IHttpConnectionFeature)) + if (key == typeof(global::Microsoft.AspNetCore.Http.Features.IHttpConnectionFeature)) { _currentIHttpConnectionFeature = feature; return; } - if (key == typeof(global::Microsoft.AspNet.Http.Features.Authentication.IHttpAuthenticationFeature)) + if (key == typeof(global::Microsoft.AspNetCore.Http.Features.Authentication.IHttpAuthenticationFeature)) { _currentIHttpAuthenticationFeature = feature; return; } - if (key == typeof(global::Microsoft.AspNet.Http.Features.Internal.IQueryFeature)) + if (key == typeof(global::Microsoft.AspNetCore.Http.Features.Internal.IQueryFeature)) { _currentIQueryFeature = feature; return; } - if (key == typeof(global::Microsoft.AspNet.Http.Features.Internal.IFormFeature)) + if (key == typeof(global::Microsoft.AspNetCore.Http.Features.Internal.IFormFeature)) { _currentIFormFeature = feature; return; } - if (key == typeof(global::Microsoft.AspNet.Http.Features.IHttpUpgradeFeature)) + if (key == typeof(global::Microsoft.AspNetCore.Http.Features.IHttpUpgradeFeature)) { _currentIHttpUpgradeFeature = feature; return; } - if (key == typeof(global::Microsoft.AspNet.Http.Features.Internal.IResponseCookiesFeature)) + if (key == typeof(global::Microsoft.AspNetCore.Http.Features.Internal.IResponseCookiesFeature)) { _currentIResponseCookiesFeature = feature; return; } - if (key == typeof(global::Microsoft.AspNet.Http.Features.Internal.IItemsFeature)) + if (key == typeof(global::Microsoft.AspNetCore.Http.Features.Internal.IItemsFeature)) { _currentIItemsFeature = feature; return; } - if (key == typeof(global::Microsoft.AspNet.Http.Features.ITlsConnectionFeature)) + if (key == typeof(global::Microsoft.AspNetCore.Http.Features.ITlsConnectionFeature)) { _currentITlsConnectionFeature = feature; return; } - if (key == typeof(global::Microsoft.AspNet.Http.Features.IHttpWebSocketFeature)) + if (key == typeof(global::Microsoft.AspNetCore.Http.Features.IHttpWebSocketFeature)) { _currentIHttpWebSocketFeature = feature; return; } - if (key == typeof(global::Microsoft.AspNet.Http.Features.ISessionFeature)) + if (key == typeof(global::Microsoft.AspNetCore.Http.Features.ISessionFeature)) { _currentISessionFeature = feature; return; } - if (key == typeof(global::Microsoft.AspNet.Http.Features.IHttpSendFileFeature)) + if (key == typeof(global::Microsoft.AspNetCore.Http.Features.IHttpSendFileFeature)) { _currentIHttpSendFileFeature = feature; return; @@ -221,67 +221,67 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { if (_currentIHttpRequestFeature != null) { - yield return new KeyValuePair(IHttpRequestFeatureType, _currentIHttpRequestFeature as global::Microsoft.AspNet.Http.Features.IHttpRequestFeature); + yield return new KeyValuePair(IHttpRequestFeatureType, _currentIHttpRequestFeature as global::Microsoft.AspNetCore.Http.Features.IHttpRequestFeature); } if (_currentIHttpResponseFeature != null) { - yield return new KeyValuePair(IHttpResponseFeatureType, _currentIHttpResponseFeature as global::Microsoft.AspNet.Http.Features.IHttpResponseFeature); + yield return new KeyValuePair(IHttpResponseFeatureType, _currentIHttpResponseFeature as global::Microsoft.AspNetCore.Http.Features.IHttpResponseFeature); } if (_currentIHttpRequestIdentifierFeature != null) { - yield return new KeyValuePair(IHttpRequestIdentifierFeatureType, _currentIHttpRequestIdentifierFeature as global::Microsoft.AspNet.Http.Features.IHttpRequestIdentifierFeature); + yield return new KeyValuePair(IHttpRequestIdentifierFeatureType, _currentIHttpRequestIdentifierFeature as global::Microsoft.AspNetCore.Http.Features.IHttpRequestIdentifierFeature); } if (_currentIServiceProvidersFeature != null) { - yield return new KeyValuePair(IServiceProvidersFeatureType, _currentIServiceProvidersFeature as global::Microsoft.AspNet.Http.Features.Internal.IServiceProvidersFeature); + yield return new KeyValuePair(IServiceProvidersFeatureType, _currentIServiceProvidersFeature as global::Microsoft.AspNetCore.Http.Features.Internal.IServiceProvidersFeature); } if (_currentIHttpRequestLifetimeFeature != null) { - yield return new KeyValuePair(IHttpRequestLifetimeFeatureType, _currentIHttpRequestLifetimeFeature as global::Microsoft.AspNet.Http.Features.IHttpRequestLifetimeFeature); + yield return new KeyValuePair(IHttpRequestLifetimeFeatureType, _currentIHttpRequestLifetimeFeature as global::Microsoft.AspNetCore.Http.Features.IHttpRequestLifetimeFeature); } if (_currentIHttpConnectionFeature != null) { - yield return new KeyValuePair(IHttpConnectionFeatureType, _currentIHttpConnectionFeature as global::Microsoft.AspNet.Http.Features.IHttpConnectionFeature); + yield return new KeyValuePair(IHttpConnectionFeatureType, _currentIHttpConnectionFeature as global::Microsoft.AspNetCore.Http.Features.IHttpConnectionFeature); } if (_currentIHttpAuthenticationFeature != null) { - yield return new KeyValuePair(IHttpAuthenticationFeatureType, _currentIHttpAuthenticationFeature as global::Microsoft.AspNet.Http.Features.Authentication.IHttpAuthenticationFeature); + yield return new KeyValuePair(IHttpAuthenticationFeatureType, _currentIHttpAuthenticationFeature as global::Microsoft.AspNetCore.Http.Features.Authentication.IHttpAuthenticationFeature); } if (_currentIQueryFeature != null) { - yield return new KeyValuePair(IQueryFeatureType, _currentIQueryFeature as global::Microsoft.AspNet.Http.Features.Internal.IQueryFeature); + yield return new KeyValuePair(IQueryFeatureType, _currentIQueryFeature as global::Microsoft.AspNetCore.Http.Features.Internal.IQueryFeature); } if (_currentIFormFeature != null) { - yield return new KeyValuePair(IFormFeatureType, _currentIFormFeature as global::Microsoft.AspNet.Http.Features.Internal.IFormFeature); + yield return new KeyValuePair(IFormFeatureType, _currentIFormFeature as global::Microsoft.AspNetCore.Http.Features.Internal.IFormFeature); } if (_currentIHttpUpgradeFeature != null) { - yield return new KeyValuePair(IHttpUpgradeFeatureType, _currentIHttpUpgradeFeature as global::Microsoft.AspNet.Http.Features.IHttpUpgradeFeature); + yield return new KeyValuePair(IHttpUpgradeFeatureType, _currentIHttpUpgradeFeature as global::Microsoft.AspNetCore.Http.Features.IHttpUpgradeFeature); } if (_currentIResponseCookiesFeature != null) { - yield return new KeyValuePair(IResponseCookiesFeatureType, _currentIResponseCookiesFeature as global::Microsoft.AspNet.Http.Features.Internal.IResponseCookiesFeature); + yield return new KeyValuePair(IResponseCookiesFeatureType, _currentIResponseCookiesFeature as global::Microsoft.AspNetCore.Http.Features.Internal.IResponseCookiesFeature); } if (_currentIItemsFeature != null) { - yield return new KeyValuePair(IItemsFeatureType, _currentIItemsFeature as global::Microsoft.AspNet.Http.Features.Internal.IItemsFeature); + yield return new KeyValuePair(IItemsFeatureType, _currentIItemsFeature as global::Microsoft.AspNetCore.Http.Features.Internal.IItemsFeature); } if (_currentITlsConnectionFeature != null) { - yield return new KeyValuePair(ITlsConnectionFeatureType, _currentITlsConnectionFeature as global::Microsoft.AspNet.Http.Features.ITlsConnectionFeature); + yield return new KeyValuePair(ITlsConnectionFeatureType, _currentITlsConnectionFeature as global::Microsoft.AspNetCore.Http.Features.ITlsConnectionFeature); } if (_currentIHttpWebSocketFeature != null) { - yield return new KeyValuePair(IHttpWebSocketFeatureType, _currentIHttpWebSocketFeature as global::Microsoft.AspNet.Http.Features.IHttpWebSocketFeature); + yield return new KeyValuePair(IHttpWebSocketFeatureType, _currentIHttpWebSocketFeature as global::Microsoft.AspNetCore.Http.Features.IHttpWebSocketFeature); } if (_currentISessionFeature != null) { - yield return new KeyValuePair(ISessionFeatureType, _currentISessionFeature as global::Microsoft.AspNet.Http.Features.ISessionFeature); + yield return new KeyValuePair(ISessionFeatureType, _currentISessionFeature as global::Microsoft.AspNetCore.Http.Features.ISessionFeature); } if (_currentIHttpSendFileFeature != null) { - yield return new KeyValuePair(IHttpSendFileFeatureType, _currentIHttpSendFileFeature as global::Microsoft.AspNet.Http.Features.IHttpSendFileFeature); + yield return new KeyValuePair(IHttpSendFileFeatureType, _currentIHttpSendFileFeature as global::Microsoft.AspNetCore.Http.Features.IHttpSendFileFeature); } if (MaybeExtra != null) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs index efbd159c7f..d5225447d1 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs @@ -10,15 +10,15 @@ using System.Numerics; using System.Text; using System.Threading; using System.Threading.Tasks; -using Microsoft.AspNet.Http; -using Microsoft.AspNet.Http.Features; -using Microsoft.AspNet.Server.Kestrel.Infrastructure; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Http.Features; +using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Primitives; // ReSharper disable AccessToModifiedClosure -namespace Microsoft.AspNet.Server.Kestrel.Http +namespace Microsoft.AspNetCore.Server.Kestrel.Http { public abstract partial class Frame : FrameContext, IFrameControl { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameContext.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameContext.cs index ab43df6388..e4db400124 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameContext.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameContext.cs @@ -1,7 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -namespace Microsoft.AspNet.Server.Kestrel.Http +namespace Microsoft.AspNetCore.Server.Kestrel.Http { public class FrameContext : ConnectionContext { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameDuplexStream.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameDuplexStream.cs index d421be7e0d..7b904b15b3 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameDuplexStream.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameDuplexStream.cs @@ -8,7 +8,7 @@ using System.IO; using System.Threading; using System.Threading.Tasks; -namespace Microsoft.AspNet.Server.Kestrel.Http +namespace Microsoft.AspNetCore.Server.Kestrel.Http { class FrameDuplexStream : Stream { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameHeaders.Generated.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameHeaders.Generated.cs index d0a5561d1f..8a36b78d50 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameHeaders.Generated.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameHeaders.Generated.cs @@ -2,10 +2,10 @@ using System; using System.Collections.Generic; using System.Text; -using Microsoft.AspNet.Server.Kestrel.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; using Microsoft.Extensions.Primitives; -namespace Microsoft.AspNet.Server.Kestrel.Http +namespace Microsoft.AspNetCore.Server.Kestrel.Http { public partial class FrameRequestHeaders diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameHeaders.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameHeaders.cs index a97a092098..45c9355349 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameHeaders.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameHeaders.cs @@ -5,10 +5,10 @@ using System; using System.Collections; using System.Collections.Generic; using System.Linq; -using Microsoft.AspNet.Http; +using Microsoft.AspNetCore.Http; using Microsoft.Extensions.Primitives; -namespace Microsoft.AspNet.Server.Kestrel.Http +namespace Microsoft.AspNetCore.Server.Kestrel.Http { public abstract class FrameHeaders : IHeaderDictionary { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameOfT.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameOfT.cs index 32b067fc76..0f3d8d48d6 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameOfT.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameOfT.cs @@ -1,14 +1,14 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; using System.Net; using System.Threading.Tasks; -using Microsoft.AspNet.Hosting.Server; -using Microsoft.AspNet.Http.Features; +using Microsoft.AspNetCore.Hosting.Server; +using Microsoft.AspNetCore.Http.Features; using Microsoft.Extensions.Logging; -namespace Microsoft.AspNet.Server.Kestrel.Http +namespace Microsoft.AspNetCore.Server.Kestrel.Http { public class Frame : Frame { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameRequestHeaders.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameRequestHeaders.cs index 731b449468..a90626f0ea 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameRequestHeaders.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameRequestHeaders.cs @@ -5,7 +5,7 @@ using Microsoft.Extensions.Primitives; using System.Collections; using System.Collections.Generic; -namespace Microsoft.AspNet.Server.Kestrel.Http +namespace Microsoft.AspNetCore.Server.Kestrel.Http { public partial class FrameRequestHeaders : FrameHeaders { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameRequestStream.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameRequestStream.cs index ba0c2062f7..dc70690b32 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameRequestStream.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameRequestStream.cs @@ -6,7 +6,7 @@ using System.IO; using System.Threading; using System.Threading.Tasks; -namespace Microsoft.AspNet.Server.Kestrel.Http +namespace Microsoft.AspNetCore.Server.Kestrel.Http { public class FrameRequestStream : Stream { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameResponseHeaders.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameResponseHeaders.cs index 840d44ce8b..08b9deca0e 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameResponseHeaders.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameResponseHeaders.cs @@ -3,10 +3,10 @@ using System.Collections; using System.Collections.Generic; -using Microsoft.AspNet.Server.Kestrel.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; using Microsoft.Extensions.Primitives; -namespace Microsoft.AspNet.Server.Kestrel.Http +namespace Microsoft.AspNetCore.Server.Kestrel.Http { public partial class FrameResponseHeaders : FrameHeaders { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameResponseStream.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameResponseStream.cs index e544723af4..f45470f555 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameResponseStream.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameResponseStream.cs @@ -6,7 +6,7 @@ using System.IO; using System.Threading; using System.Threading.Tasks; -namespace Microsoft.AspNet.Server.Kestrel.Http +namespace Microsoft.AspNetCore.Server.Kestrel.Http { class FrameResponseStream : Stream { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameStreamState.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameStreamState.cs index 12c393ee1a..8f92bad5b9 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameStreamState.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameStreamState.cs @@ -1,7 +1,7 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -namespace Microsoft.AspNet.Server.Kestrel.Http +namespace Microsoft.AspNetCore.Server.Kestrel.Http { enum FrameStreamState { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/IConnectionControl.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/IConnectionControl.cs index c6e2f7ec04..6da7cac561 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/IConnectionControl.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/IConnectionControl.cs @@ -1,7 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -namespace Microsoft.AspNet.Server.Kestrel.Http +namespace Microsoft.AspNetCore.Server.Kestrel.Http { public interface IConnectionControl { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/IFrameControl.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/IFrameControl.cs index 6871236b8b..f8ecbab894 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/IFrameControl.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/IFrameControl.cs @@ -5,7 +5,7 @@ using System; using System.Threading; using System.Threading.Tasks; -namespace Microsoft.AspNet.Server.Kestrel.Http +namespace Microsoft.AspNetCore.Server.Kestrel.Http { public interface IFrameControl { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/ISocketOutput.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/ISocketOutput.cs index 4d9a083576..20e20481d3 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/ISocketOutput.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/ISocketOutput.cs @@ -4,9 +4,9 @@ using System; using System.Threading; using System.Threading.Tasks; -using Microsoft.AspNet.Server.Kestrel.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; -namespace Microsoft.AspNet.Server.Kestrel.Http +namespace Microsoft.AspNetCore.Server.Kestrel.Http { /// /// Operations performed for buffered socket output diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Listener.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Listener.cs index 3455f93567..d4137ad369 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Listener.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Listener.cs @@ -3,10 +3,10 @@ using System; using System.Threading.Tasks; -using Microsoft.AspNet.Server.Kestrel.Networking; +using Microsoft.AspNetCore.Server.Kestrel.Networking; using Microsoft.Extensions.Logging; -namespace Microsoft.AspNet.Server.Kestrel.Http +namespace Microsoft.AspNetCore.Server.Kestrel.Http { /// /// Base class for listeners in Kestrel. Listens for incoming connections diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/ListenerContext.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/ListenerContext.cs index 7247afa2bd..692759e7d8 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/ListenerContext.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/ListenerContext.cs @@ -2,10 +2,10 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Collections.Generic; -using Microsoft.AspNet.Server.Kestrel.Infrastructure; -using Microsoft.AspNet.Server.Kestrel.Networking; +using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Networking; -namespace Microsoft.AspNet.Server.Kestrel.Http +namespace Microsoft.AspNetCore.Server.Kestrel.Http { public class ListenerContext : ServiceContext { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/ListenerPrimary.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/ListenerPrimary.cs index 04257ab015..e9af35d142 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/ListenerPrimary.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/ListenerPrimary.cs @@ -4,11 +4,11 @@ using System; using System.Collections.Generic; using System.Threading.Tasks; -using Microsoft.AspNet.Server.Kestrel.Infrastructure; -using Microsoft.AspNet.Server.Kestrel.Networking; +using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Networking; using Microsoft.Extensions.Logging; -namespace Microsoft.AspNet.Server.Kestrel.Http +namespace Microsoft.AspNetCore.Server.Kestrel.Http { /// /// A primary listener waits for incoming connections on a specified socket. Incoming diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/ListenerSecondary.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/ListenerSecondary.cs index d3cd04a6f0..b20c35ebc8 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/ListenerSecondary.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/ListenerSecondary.cs @@ -5,12 +5,12 @@ using System; using System.Runtime.InteropServices; using System.Threading; using System.Threading.Tasks; -using Microsoft.AspNet.Http; -using Microsoft.AspNet.Server.Kestrel.Infrastructure; -using Microsoft.AspNet.Server.Kestrel.Networking; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Networking; using Microsoft.Extensions.Logging; -namespace Microsoft.AspNet.Server.Kestrel.Http +namespace Microsoft.AspNetCore.Server.Kestrel.Http { /// /// A secondary listener is delegated requests from a primary listener via a named pipe or diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/MessageBody.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/MessageBody.cs index 812ea97b94..ce9f4aa9cc 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/MessageBody.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/MessageBody.cs @@ -8,7 +8,7 @@ using System.Threading; using System.Threading.Tasks; using Microsoft.Extensions.Primitives; -namespace Microsoft.AspNet.Server.Kestrel.Http +namespace Microsoft.AspNetCore.Server.Kestrel.Http { public abstract class MessageBody { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/PipeListener.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/PipeListener.cs index c7e545a549..9e6849087f 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/PipeListener.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/PipeListener.cs @@ -2,11 +2,11 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using Microsoft.AspNet.Server.Kestrel.Infrastructure; -using Microsoft.AspNet.Server.Kestrel.Networking; +using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Networking; using Microsoft.Extensions.Logging; -namespace Microsoft.AspNet.Server.Kestrel.Http +namespace Microsoft.AspNetCore.Server.Kestrel.Http { /// /// Implementation of that uses UNIX domain sockets as its transport. diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/PipeListenerPrimary.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/PipeListenerPrimary.cs index 7d907e20c2..6454fb6f58 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/PipeListenerPrimary.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/PipeListenerPrimary.cs @@ -2,11 +2,11 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using Microsoft.AspNet.Server.Kestrel.Infrastructure; -using Microsoft.AspNet.Server.Kestrel.Networking; +using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Networking; using Microsoft.Extensions.Logging; -namespace Microsoft.AspNet.Server.Kestrel.Http +namespace Microsoft.AspNetCore.Server.Kestrel.Http { /// /// An implementation of using UNIX sockets. diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/PipeListenerSecondary.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/PipeListenerSecondary.cs index a9c3f70529..3ca23ea6fc 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/PipeListenerSecondary.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/PipeListenerSecondary.cs @@ -1,9 +1,9 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using Microsoft.AspNet.Server.Kestrel.Networking; +using Microsoft.AspNetCore.Server.Kestrel.Networking; -namespace Microsoft.AspNet.Server.Kestrel.Http +namespace Microsoft.AspNetCore.Server.Kestrel.Http { /// /// An implementation of using UNIX sockets. diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/ProduceEndType.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/ProduceEndType.cs index 4df5ed4e48..8e4831ffa2 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/ProduceEndType.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/ProduceEndType.cs @@ -1,7 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -namespace Microsoft.AspNet.Server.Kestrel.Http +namespace Microsoft.AspNetCore.Server.Kestrel.Http { public enum ProduceEndType { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/ReasonPhrases.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/ReasonPhrases.cs index f162ebb9fc..7aae44b815 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/ReasonPhrases.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/ReasonPhrases.cs @@ -4,7 +4,7 @@ using System.Globalization; using System.Text; -namespace Microsoft.AspNet.Server.Kestrel.Http +namespace Microsoft.AspNetCore.Server.Kestrel.Http { public static class ReasonPhrases { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketInput.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketInput.cs index 944457af60..94e335b345 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketInput.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketInput.cs @@ -5,9 +5,9 @@ using System; using System.IO; using System.Runtime.CompilerServices; using System.Threading; -using Microsoft.AspNet.Server.Kestrel.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; -namespace Microsoft.AspNet.Server.Kestrel.Http +namespace Microsoft.AspNetCore.Server.Kestrel.Http { public class SocketInput : ICriticalNotifyCompletion { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketInputExtensions.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketInputExtensions.cs index d514c3893f..4b3beab538 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketInputExtensions.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketInputExtensions.cs @@ -1,10 +1,10 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Threading.Tasks; -using Microsoft.AspNet.Server.Kestrel.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; -namespace Microsoft.AspNet.Server.Kestrel.Http +namespace Microsoft.AspNetCore.Server.Kestrel.Http { public static class SocketInputExtensions { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketOutput.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketOutput.cs index 3c39954494..15a56f9fc8 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketOutput.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketOutput.cs @@ -7,11 +7,11 @@ using System.Diagnostics; using System.IO; using System.Threading; using System.Threading.Tasks; -using Microsoft.AspNet.Server.Kestrel.Infrastructure; -using Microsoft.AspNet.Server.Kestrel.Networking; +using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Networking; using Microsoft.Extensions.Logging; -namespace Microsoft.AspNet.Server.Kestrel.Http +namespace Microsoft.AspNetCore.Server.Kestrel.Http { public class SocketOutput : ISocketOutput { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/TcpListener.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/TcpListener.cs index 61f4a4fe0e..113f9f69b7 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/TcpListener.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/TcpListener.cs @@ -1,11 +1,11 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using Microsoft.AspNet.Server.Kestrel.Infrastructure; -using Microsoft.AspNet.Server.Kestrel.Networking; +using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Networking; using Microsoft.Extensions.Logging; -namespace Microsoft.AspNet.Server.Kestrel.Http +namespace Microsoft.AspNetCore.Server.Kestrel.Http { /// /// Implementation of that uses TCP sockets as its transport. diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/TcpListenerPrimary.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/TcpListenerPrimary.cs index 98283232cd..6721e8b012 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/TcpListenerPrimary.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/TcpListenerPrimary.cs @@ -3,11 +3,11 @@ using System; using System.Net; -using Microsoft.AspNet.Server.Kestrel.Infrastructure; -using Microsoft.AspNet.Server.Kestrel.Networking; +using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Networking; using Microsoft.Extensions.Logging; -namespace Microsoft.AspNet.Server.Kestrel.Http +namespace Microsoft.AspNetCore.Server.Kestrel.Http { /// /// An implementation of using TCP sockets. diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/TcpListenerSecondary.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/TcpListenerSecondary.cs index 9a36f2b171..ce0616171b 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/TcpListenerSecondary.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/TcpListenerSecondary.cs @@ -1,9 +1,9 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using Microsoft.AspNet.Server.Kestrel.Networking; +using Microsoft.AspNetCore.Server.Kestrel.Networking; -namespace Microsoft.AspNet.Server.Kestrel.Http +namespace Microsoft.AspNetCore.Server.Kestrel.Http { /// /// An implementation of using TCP sockets. diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/UrlPathDecoder.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/UrlPathDecoder.cs index 66608a4a22..60f83303f1 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/UrlPathDecoder.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/UrlPathDecoder.cs @@ -1,9 +1,9 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using Microsoft.AspNet.Server.Kestrel.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; -namespace Microsoft.AspNet.Server.Kestrel.Http +namespace Microsoft.AspNetCore.Server.Kestrel.Http { public class UrlPathDecoder { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/IKestrelServerInformation.cs b/src/Microsoft.AspNetCore.Server.Kestrel/IKestrelServerInformation.cs index 3a634afae8..a08db08ea6 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/IKestrelServerInformation.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/IKestrelServerInformation.cs @@ -1,9 +1,9 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using Microsoft.AspNet.Server.Kestrel.Filter; +using Microsoft.AspNetCore.Server.Kestrel.Filter; -namespace Microsoft.AspNet.Server.Kestrel +namespace Microsoft.AspNetCore.Server.Kestrel { public interface IKestrelServerInformation { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/Constants.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/Constants.cs index 9b72df3361..098db13c79 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/Constants.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/Constants.cs @@ -1,7 +1,7 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -namespace Microsoft.AspNet.Server.Kestrel.Infrastructure +namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure { internal class Constants { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/Disposable.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/Disposable.cs index 04d2dac312..5d3b53c9df 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/Disposable.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/Disposable.cs @@ -3,7 +3,7 @@ using System; -namespace Microsoft.AspNet.Server.Kestrel +namespace Microsoft.AspNetCore.Server.Kestrel { /// /// Summary description for Disposable diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/IKestrelTrace.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/IKestrelTrace.cs index 7c5776fcc4..1cab425247 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/IKestrelTrace.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/IKestrelTrace.cs @@ -1,7 +1,7 @@ using System; using Microsoft.Extensions.Logging; -namespace Microsoft.AspNet.Server.Kestrel.Infrastructure +namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure { public interface IKestrelTrace : ILogger { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/ISystemClock.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/ISystemClock.cs index c741621de4..1818f68fd2 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/ISystemClock.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/ISystemClock.cs @@ -1,9 +1,9 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -namespace Microsoft.AspNet.Server.Kestrel.Infrastructure +namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure { /// /// Abstracts the system clock to facilitate testing. diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/IThreadPool.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/IThreadPool.cs index fde95f4241..404bc01a55 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/IThreadPool.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/IThreadPool.cs @@ -1,10 +1,10 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; using System.Threading.Tasks; -namespace Microsoft.AspNet.Server.Kestrel.Infrastructure +namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure { public interface IThreadPool { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/KestrelThread.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/KestrelThread.cs index 0e4548babc..82c6f11f0a 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/KestrelThread.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/KestrelThread.cs @@ -6,13 +6,13 @@ using System.Collections.Generic; using System.Runtime.ExceptionServices; using System.Threading; using System.Threading.Tasks; -using Microsoft.AspNet.Hosting; -using Microsoft.AspNet.Server.Kestrel.Http; -using Microsoft.AspNet.Server.Kestrel.Infrastructure; -using Microsoft.AspNet.Server.Kestrel.Networking; +using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Server.Kestrel.Http; +using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Networking; using Microsoft.Extensions.Logging; -namespace Microsoft.AspNet.Server.Kestrel +namespace Microsoft.AspNetCore.Server.Kestrel { /// /// Summary description for KestrelThread diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/KestrelTrace.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/KestrelTrace.cs index 1bfd402993..f9b82ce25b 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/KestrelTrace.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/KestrelTrace.cs @@ -2,10 +2,10 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using Microsoft.AspNet.Server.Kestrel.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; using Microsoft.Extensions.Logging; -namespace Microsoft.AspNet.Server.Kestrel +namespace Microsoft.AspNetCore.Server.Kestrel { /// /// Summary description for KestrelTrace diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/LoggingThreadPool.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/LoggingThreadPool.cs index 967787dc1f..70f142f536 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/LoggingThreadPool.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/LoggingThreadPool.cs @@ -5,7 +5,7 @@ using System; using System.Threading; using System.Threading.Tasks; -namespace Microsoft.AspNet.Server.Kestrel.Infrastructure +namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure { public class LoggingThreadPool : IThreadPool { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPool2.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPool2.cs index f915123562..c7a2899b69 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPool2.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPool2.cs @@ -1,8 +1,8 @@ -using System; +using System; using System.Collections.Concurrent; using System.Diagnostics; -namespace Microsoft.AspNet.Server.Kestrel.Infrastructure +namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure { /// /// Used to allocate and distribute re-usable blocks of memory. diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPoolBlock2.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPoolBlock2.cs index 26156c6cc0..905e3c3464 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPoolBlock2.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPoolBlock2.cs @@ -1,9 +1,9 @@ -using System; +using System; using System.Diagnostics; using System.Runtime.InteropServices; using System.Text; -namespace Microsoft.AspNet.Server.Kestrel.Infrastructure +namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure { /// /// Block tracking object used by the byte buffer memory pool. A slab is a large allocation which is divided into smaller blocks. The diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPoolIterator2.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPoolIterator2.cs index 37e18389ff..62b19ced94 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPoolIterator2.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPoolIterator2.cs @@ -1,11 +1,11 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; using System.Diagnostics; using System.Numerics; -namespace Microsoft.AspNet.Server.Kestrel.Infrastructure +namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure { public struct MemoryPoolIterator2 { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPoolIterator2Extensions.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPoolIterator2Extensions.cs index 3bb2b6c8c2..70dc2cf8fc 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPoolIterator2Extensions.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPoolIterator2Extensions.cs @@ -1,11 +1,11 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; using System.Diagnostics; using System.Text; -namespace Microsoft.AspNet.Server.Kestrel.Infrastructure +namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure { public static class MemoryPoolIterator2Extensions { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPoolSlab2.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPoolSlab2.cs index 134bc147d2..c7062d0977 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPoolSlab2.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPoolSlab2.cs @@ -1,7 +1,7 @@ -using System; +using System; using System.Runtime.InteropServices; -namespace Microsoft.AspNet.Server.Kestrel.Infrastructure +namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure { /// /// Slab tracking object used by the byte buffer memory pool. A slab is a large allocation which is divided into smaller blocks. The diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/SystemClock.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/SystemClock.cs index c16d40bf6a..1718890eea 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/SystemClock.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/SystemClock.cs @@ -1,9 +1,9 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -namespace Microsoft.AspNet.Server.Kestrel.Infrastructure +namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure { /// /// Provides access to the normal system clock. diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/TaskUtilities.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/TaskUtilities.cs index c0c4c11acc..a59713eeaa 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/TaskUtilities.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/TaskUtilities.cs @@ -3,7 +3,7 @@ using System.Threading.Tasks; -namespace Microsoft.AspNet.Server.Kestrel.Infrastructure +namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure { public static class TaskUtilities { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/KestrelEngine.cs b/src/Microsoft.AspNetCore.Server.Kestrel/KestrelEngine.cs index d64f4316e9..40c3359558 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/KestrelEngine.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/KestrelEngine.cs @@ -3,11 +3,11 @@ using System; using System.Collections.Generic; -using Microsoft.AspNet.Http; -using Microsoft.AspNet.Server.Kestrel.Http; -using Microsoft.AspNet.Server.Kestrel.Networking; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Server.Kestrel.Http; +using Microsoft.AspNetCore.Server.Kestrel.Networking; -namespace Microsoft.AspNet.Server.Kestrel +namespace Microsoft.AspNetCore.Server.Kestrel { public class KestrelEngine : ServiceContext, IDisposable { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServer.cs b/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServer.cs index 34cef6394b..fed5bea660 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServer.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServer.cs @@ -1,16 +1,16 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; using System.Collections.Generic; -using Microsoft.AspNet.Hosting; -using Microsoft.AspNet.Hosting.Server; -using Microsoft.AspNet.Http.Features; -using Microsoft.AspNet.Server.Kestrel.Http; -using Microsoft.AspNet.Server.Kestrel.Infrastructure; +using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Hosting.Server; +using Microsoft.AspNetCore.Http.Features; +using Microsoft.AspNetCore.Server.Kestrel.Http; +using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; using Microsoft.Extensions.Logging; -namespace Microsoft.AspNet.Server.Kestrel +namespace Microsoft.AspNetCore.Server.Kestrel { public class KestrelServer : IServer { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServerInformation.cs b/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServerInformation.cs index 8ff73cc03e..6f05a1da58 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServerInformation.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServerInformation.cs @@ -4,11 +4,11 @@ using System; using System.Collections.Generic; using System.Globalization; -using Microsoft.AspNet.Server.Features; -using Microsoft.AspNet.Server.Kestrel.Filter; +using Microsoft.AspNetCore.Server.Features; +using Microsoft.AspNetCore.Server.Kestrel.Filter; using Microsoft.Extensions.Configuration; -namespace Microsoft.AspNet.Server.Kestrel +namespace Microsoft.AspNetCore.Server.Kestrel { public class KestrelServerInformation : IKestrelServerInformation, IServerAddressesFeature { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Networking/Libuv.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Networking/Libuv.cs index abe9aa1d56..037f77eaa2 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Networking/Libuv.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Networking/Libuv.cs @@ -4,7 +4,7 @@ using System; using System.Runtime.InteropServices; -namespace Microsoft.AspNet.Server.Kestrel.Networking +namespace Microsoft.AspNetCore.Server.Kestrel.Networking { public class Libuv { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Networking/PlatformApis.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Networking/PlatformApis.cs index a1915ff372..be22ef7120 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Networking/PlatformApis.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Networking/PlatformApis.cs @@ -5,7 +5,7 @@ using System; using System.Runtime.InteropServices; using Microsoft.Extensions.PlatformAbstractions; -namespace Microsoft.AspNet.Server.Kestrel.Networking +namespace Microsoft.AspNetCore.Server.Kestrel.Networking { public static class PlatformApis { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Networking/SockAddr.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Networking/SockAddr.cs index 762b1f5140..29c850df84 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Networking/SockAddr.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Networking/SockAddr.cs @@ -1,10 +1,10 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; using System.Net; -namespace Microsoft.AspNet.Server.Kestrel.Networking +namespace Microsoft.AspNetCore.Server.Kestrel.Networking { public struct SockAddr { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvAsyncHandle.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvAsyncHandle.cs index 32f629c713..d78973a847 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvAsyncHandle.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvAsyncHandle.cs @@ -2,9 +2,9 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using Microsoft.AspNet.Server.Kestrel.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; -namespace Microsoft.AspNet.Server.Kestrel.Networking +namespace Microsoft.AspNetCore.Server.Kestrel.Networking { public class UvAsyncHandle : UvHandle { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvConnectRequest.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvConnectRequest.cs index 086c52de77..1ceb8f9e51 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvConnectRequest.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvConnectRequest.cs @@ -2,10 +2,10 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using Microsoft.AspNet.Server.Kestrel.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; using Microsoft.Extensions.Logging; -namespace Microsoft.AspNet.Server.Kestrel.Networking +namespace Microsoft.AspNetCore.Server.Kestrel.Networking { /// /// Summary description for UvWriteRequest diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvException.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvException.cs index 2a6d5bce1d..a63da72eba 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvException.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvException.cs @@ -1,9 +1,9 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -namespace Microsoft.AspNet.Server.Kestrel.Networking +namespace Microsoft.AspNetCore.Server.Kestrel.Networking { public class UvException : Exception { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvHandle.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvHandle.cs index 60c3ba03c8..65f3c43580 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvHandle.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvHandle.cs @@ -3,9 +3,9 @@ using System; using System.Threading; -using Microsoft.AspNet.Server.Kestrel.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; -namespace Microsoft.AspNet.Server.Kestrel.Networking +namespace Microsoft.AspNetCore.Server.Kestrel.Networking { public abstract class UvHandle : UvMemory { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvLoopHandle.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvLoopHandle.cs index 75a4bbfdc4..3cf357af9b 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvLoopHandle.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvLoopHandle.cs @@ -3,9 +3,9 @@ using System; using System.Threading; -using Microsoft.AspNet.Server.Kestrel.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; -namespace Microsoft.AspNet.Server.Kestrel.Networking +namespace Microsoft.AspNetCore.Server.Kestrel.Networking { public class UvLoopHandle : UvHandle { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvMemory.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvMemory.cs index 3f2bf13a28..c9a62462cf 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvMemory.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvMemory.cs @@ -5,9 +5,9 @@ using System; using System.Diagnostics; using System.Runtime.InteropServices; using System.Threading; -using Microsoft.AspNet.Server.Kestrel.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; -namespace Microsoft.AspNet.Server.Kestrel.Networking +namespace Microsoft.AspNetCore.Server.Kestrel.Networking { /// /// Summary description for UvMemory diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvPipeHandle.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvPipeHandle.cs index 5205eb5f9b..af143536a4 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvPipeHandle.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvPipeHandle.cs @@ -3,9 +3,9 @@ using System; using System.Net; -using Microsoft.AspNet.Server.Kestrel.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; -namespace Microsoft.AspNet.Server.Kestrel.Networking +namespace Microsoft.AspNetCore.Server.Kestrel.Networking { public class UvPipeHandle : UvStreamHandle { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvRequest.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvRequest.cs index 4005129cec..87fe48c726 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvRequest.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvRequest.cs @@ -1,8 +1,8 @@ -using System; +using System; using System.Runtime.InteropServices; -using Microsoft.AspNet.Server.Kestrel.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; -namespace Microsoft.AspNet.Server.Kestrel.Networking +namespace Microsoft.AspNetCore.Server.Kestrel.Networking { public class UvRequest : UvMemory { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvShutdownReq.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvShutdownReq.cs index d6aa2c65ad..0342b3d25f 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvShutdownReq.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvShutdownReq.cs @@ -2,9 +2,9 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using Microsoft.AspNet.Server.Kestrel.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; -namespace Microsoft.AspNet.Server.Kestrel.Networking +namespace Microsoft.AspNetCore.Server.Kestrel.Networking { /// /// Summary description for UvShutdownRequest diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvStreamHandle.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvStreamHandle.cs index bfbdabfef6..e60de40d3b 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvStreamHandle.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvStreamHandle.cs @@ -3,10 +3,10 @@ using System; using System.Runtime.InteropServices; -using Microsoft.AspNet.Server.Kestrel.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; using Microsoft.Extensions.Logging; -namespace Microsoft.AspNet.Server.Kestrel.Networking +namespace Microsoft.AspNetCore.Server.Kestrel.Networking { public abstract class UvStreamHandle : UvHandle { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvTcpHandle.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvTcpHandle.cs index cc568cc503..ec201a3627 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvTcpHandle.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvTcpHandle.cs @@ -4,9 +4,9 @@ using System; using System.Net; using System.Runtime.InteropServices; -using Microsoft.AspNet.Server.Kestrel.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; -namespace Microsoft.AspNet.Server.Kestrel.Networking +namespace Microsoft.AspNetCore.Server.Kestrel.Networking { public class UvTcpHandle : UvStreamHandle { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvWriteReq.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvWriteReq.cs index 21a1aaf778..cdefbdaf9c 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvWriteReq.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvWriteReq.cs @@ -4,10 +4,10 @@ using System; using System.Collections.Generic; using System.Runtime.InteropServices; -using Microsoft.AspNet.Server.Kestrel.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; using Microsoft.Extensions.Logging; -namespace Microsoft.AspNet.Server.Kestrel.Networking +namespace Microsoft.AspNetCore.Server.Kestrel.Networking { /// /// Summary description for UvWriteRequest diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Properties/AssemblyInfo.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Properties/AssemblyInfo.cs index a8f71a20f0..24e236d5f2 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Properties/AssemblyInfo.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Properties/AssemblyInfo.cs @@ -5,6 +5,6 @@ using System.Reflection; using System.Resources; using System.Runtime.CompilerServices; -[assembly: InternalsVisibleTo("Microsoft.AspNet.Server.KestrelTests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")] +[assembly: InternalsVisibleTo("Microsoft.AspNetCore.Server.KestrelTests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")] [assembly: AssemblyMetadata("Serviceable", "True")] [assembly: NeutralResourcesLanguage("en-us")] diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/ServerAddress.cs b/src/Microsoft.AspNetCore.Server.Kestrel/ServerAddress.cs index 1c2e2d00e6..4bbc6dc9c5 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/ServerAddress.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/ServerAddress.cs @@ -1,12 +1,12 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; using System.Diagnostics; using System.Globalization; -using Microsoft.AspNet.Server.Kestrel.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; -namespace Microsoft.AspNet.Server.Kestrel +namespace Microsoft.AspNetCore.Server.Kestrel { public class ServerAddress { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/ServerFactory.cs b/src/Microsoft.AspNetCore.Server.Kestrel/ServerFactory.cs index d7f95ce25c..06a7fb3686 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/ServerFactory.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/ServerFactory.cs @@ -2,14 +2,14 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using Microsoft.AspNet.Hosting; -using Microsoft.AspNet.Hosting.Server; -using Microsoft.AspNet.Http.Features; -using Microsoft.AspNet.Server.Features; +using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Hosting.Server; +using Microsoft.AspNetCore.Http.Features; +using Microsoft.AspNetCore.Server.Features; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Logging; -namespace Microsoft.AspNet.Server.Kestrel +namespace Microsoft.AspNetCore.Server.Kestrel { /// /// Summary description for ServerFactory @@ -31,7 +31,7 @@ namespace Microsoft.AspNet.Server.Kestrel var serverFeatures = new FeatureCollection(); serverFeatures.Set(information); serverFeatures.Set(information); - return new KestrelServer(serverFeatures, _appLifetime, _loggerFactory.CreateLogger("Microsoft.AspNet.Server.Kestrel")); + return new KestrelServer(serverFeatures, _appLifetime, _loggerFactory.CreateLogger("Microsoft.AspNetCore.Server.Kestrel")); } } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/ServiceContext.cs b/src/Microsoft.AspNetCore.Server.Kestrel/ServiceContext.cs index 4bab512ced..a299ff9461 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/ServiceContext.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/ServiceContext.cs @@ -1,15 +1,15 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; using System.Net; -using Microsoft.AspNet.Hosting; -using Microsoft.AspNet.Http.Features; -using Microsoft.AspNet.Server.Kestrel.Filter; -using Microsoft.AspNet.Server.Kestrel.Http; -using Microsoft.AspNet.Server.Kestrel.Infrastructure; +using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Http.Features; +using Microsoft.AspNetCore.Server.Kestrel.Filter; +using Microsoft.AspNetCore.Server.Kestrel.Http; +using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; -namespace Microsoft.AspNet.Server.Kestrel +namespace Microsoft.AspNetCore.Server.Kestrel { public class ServiceContext { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/project.json b/src/Microsoft.AspNetCore.Server.Kestrel/project.json index 8fce00cce0..dcf935bc9f 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/project.json +++ b/src/Microsoft.AspNetCore.Server.Kestrel/project.json @@ -6,7 +6,7 @@ "url": "git://github.com/aspnet/kestrelhttpserver" }, "dependencies": { - "Microsoft.AspNet.Hosting": "1.0.0-*", + "Microsoft.AspNetCore.Hosting": "1.0.0-*", "Microsoft.Extensions.Logging.Abstractions": "1.0.0-*", "Microsoft.Extensions.PlatformAbstractions": "1.0.0-*", "System.Numerics.Vectors": "4.1.1-*", @@ -14,11 +14,11 @@ "version": "1.0.0-*", "type": "build" }, - "Microsoft.AspNet.Internal.libuv-Darwin": { + "Microsoft.AspNetCore.Internal.libuv-Darwin": { "version": "1.0.0-*", "type": "build" }, - "Microsoft.AspNet.Internal.libuv-Windows": { + "Microsoft.AspNetCore.Internal.libuv-Windows": { "version": "1.0.0-*", "type": "build" }, @@ -53,12 +53,12 @@ }, "scripts": { "prepare": [ - "dnu restore ../../tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode", - "dnx -p ../../tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode run Http/FrameHeaders.Generated.cs Http/Frame.Generated.cs" + "dnu restore ../../tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode", + "dnx -p ../../tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode run Http/FrameHeaders.Generated.cs Http/Frame.Generated.cs" ], "postrestore": [ - "dnu restore ../../tools/Microsoft.AspNet.Server.Kestrel.LibuvCopier", - "dnx -p ../../tools/Microsoft.AspNet.Server.Kestrel.LibuvCopier run" + "dnu restore ../../tools/Microsoft.AspNetCore.Server.Kestrel.LibuvCopier", + "dnx -p ../../tools/Microsoft.AspNetCore.Server.Kestrel.LibuvCopier run" ] }, "packInclude": { diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs index c553af03b0..ea09bfb879 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs @@ -1,18 +1,18 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Collections.Generic; using System.Net.Http; using System.Threading.Tasks; -using Microsoft.AspNet.Builder; -using Microsoft.AspNet.Hosting; -using Microsoft.AspNet.Http; -using Microsoft.AspNet.Http.Extensions; -using Microsoft.AspNet.Testing.xunit; +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Http.Extensions; +using Microsoft.AspNetCore.Testing.xunit; using Microsoft.Extensions.Configuration; using Xunit; -namespace Microsoft.AspNet.Server.Kestrel.FunctionalTests +namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { public class AddressRegistrationTests { @@ -42,7 +42,7 @@ namespace Microsoft.AspNet.Server.Kestrel.FunctionalTests var hostBuilder = new WebHostBuilder() .UseConfiguration(config) - .UseServer("Microsoft.AspNet.Server.Kestrel") + .UseServer("Microsoft.AspNetCore.Server.Kestrel") .Configure(ConfigureEchoAddress); using (var host = hostBuilder.Build()) diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/IPv6SupportedConditionAttribute.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/IPv6SupportedConditionAttribute.cs index 5d8d8a0d6b..cafe02d229 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/IPv6SupportedConditionAttribute.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/IPv6SupportedConditionAttribute.cs @@ -4,9 +4,9 @@ using System; using System.Net; using System.Net.Sockets; -using Microsoft.AspNet.Testing.xunit; +using Microsoft.AspNetCore.Testing.xunit; -namespace Microsoft.AspNet.Server.Kestrel.FunctionalTests +namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { [AttributeUsage(AttributeTargets.Method, AllowMultiple = false)] public class IPv6SupportedConditionAttribute : Attribute, ITestCondition diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests.xproj b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests.xproj index d8807f6583..01f50a011e 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests.xproj +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests.xproj @@ -1,4 +1,4 @@ - + 14.0 @@ -7,7 +7,7 @@ 9559a5f1-080c-4909-b6cf-7e4b3dc55748 - Microsoft.AspNet.Server.Kestrel.FunctionalTests + Microsoft.AspNetCore.Server.Kestrel.FunctionalTests ..\..\artifacts\obj\$(MSBuildProjectName) ..\..\artifacts\bin\$(MSBuildProjectName)\ diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/PathBaseTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/PathBaseTests.cs index e44a651c4c..be427bcb40 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/PathBaseTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/PathBaseTests.cs @@ -1,19 +1,19 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Collections.Generic; using System.Net.Http; using System.Threading.Tasks; -using Microsoft.AspNet.Builder; -using Microsoft.AspNet.Hosting; -using Microsoft.AspNet.Http; -using Microsoft.AspNet.Testing.xunit; +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Testing.xunit; using Microsoft.Extensions.Configuration; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using Xunit; -namespace Microsoft.AspNet.Server.Kestrel.FunctionalTests +namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { public class PathBaseTests { @@ -81,7 +81,7 @@ namespace Microsoft.AspNet.Server.Kestrel.FunctionalTests var builder = new WebHostBuilder() .UseConfiguration(config) - .UseServer("Microsoft.AspNet.Server.Kestrel") + .UseServer("Microsoft.AspNetCore.Server.Kestrel") .Configure(app => { app.Run(async context => diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs index 1beb9fd4a5..31e8ce1e22 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs @@ -1,20 +1,20 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Collections.Generic; using System.Globalization; using System.Net.Http; using System.Threading.Tasks; -using Microsoft.AspNet.Builder; -using Microsoft.AspNet.Hosting; -using Microsoft.AspNet.Http; -using Microsoft.AspNet.Testing.xunit; +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Testing.xunit; using Microsoft.Extensions.Configuration; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using Xunit; -namespace Microsoft.AspNet.Server.Kestrel.FunctionalTests +namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { public class RequestTests { @@ -31,7 +31,7 @@ namespace Microsoft.AspNet.Server.Kestrel.FunctionalTests var builder = new WebHostBuilder() .UseConfiguration(config) - .UseServer("Microsoft.AspNet.Server.Kestrel") + .UseServer("Microsoft.AspNetCore.Server.Kestrel") .Configure(app => { app.Run(async context => @@ -102,7 +102,7 @@ namespace Microsoft.AspNet.Server.Kestrel.FunctionalTests var builder = new WebHostBuilder() .UseConfiguration(config) - .UseServer("Microsoft.AspNet.Server.Kestrel") + .UseServer("Microsoft.AspNetCore.Server.Kestrel") .Configure(app => { app.Run(async context => @@ -134,7 +134,7 @@ namespace Microsoft.AspNet.Server.Kestrel.FunctionalTests var builder = new WebHostBuilder() .UseConfiguration(config) - .UseServer("Microsoft.AspNet.Server.Kestrel") + .UseServer("Microsoft.AspNetCore.Server.Kestrel") .Configure(app => { app.Run(async context => diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs index d4f6b529aa..0708c09388 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -7,15 +7,15 @@ using System.Linq; using System.Net; using System.Net.Http; using System.Threading.Tasks; -using Microsoft.AspNet.Builder; -using Microsoft.AspNet.Hosting; -using Microsoft.AspNet.Http; -using Microsoft.AspNet.Testing.xunit; +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Testing.xunit; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Primitives; using Xunit; -namespace Microsoft.AspNet.Server.Kestrel.FunctionalTests +namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { public class ResponseTests { @@ -32,7 +32,7 @@ namespace Microsoft.AspNet.Server.Kestrel.FunctionalTests var hostBuilder = new WebHostBuilder() .UseConfiguration(config) - .UseServer("Microsoft.AspNet.Server.Kestrel") + .UseServer("Microsoft.AspNetCore.Server.Kestrel") .Configure(app => { app.Run(async context => @@ -92,7 +92,7 @@ namespace Microsoft.AspNet.Server.Kestrel.FunctionalTests var hostBuilder = new WebHostBuilder() .UseConfiguration(config) - .UseServer("Microsoft.AspNet.Server.Kestrel") + .UseServer("Microsoft.AspNetCore.Server.Kestrel") .Configure(app => { app.Run(async context => @@ -143,7 +143,7 @@ namespace Microsoft.AspNet.Server.Kestrel.FunctionalTests var hostBuilder = new WebHostBuilder() .UseConfiguration(config) - .UseServer("Microsoft.AspNet.Server.Kestrel") + .UseServer("Microsoft.AspNetCore.Server.Kestrel") .Configure(app => { app.Run(context => diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ThreadCountTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ThreadCountTests.cs index 0d4324926b..cd88cf2f8c 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ThreadCountTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ThreadCountTests.cs @@ -1,16 +1,16 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Collections.Generic; using System.Net.Http; using System.Threading.Tasks; -using Microsoft.AspNet.Builder; -using Microsoft.AspNet.Hosting; -using Microsoft.AspNet.Http; +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Http; using Microsoft.Extensions.Configuration; using Xunit; -namespace Microsoft.AspNet.Server.Kestrel.FunctionalTests +namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { public class ThreadCountTests { @@ -25,7 +25,7 @@ namespace Microsoft.AspNet.Server.Kestrel.FunctionalTests var hostBuilder = new WebHostBuilder() .UseConfiguration(config) - .UseServer("Microsoft.AspNet.Server.Kestrel") + .UseServer("Microsoft.AspNetCore.Server.Kestrel") .Configure(app => { var serverInfo = app.ServerFeatures.Get(); diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json index 1e06cdc21b..cd1a77f780 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json @@ -1,9 +1,9 @@ { "version": "1.0.0-*", "dependencies": { - "Microsoft.AspNet.Http.Abstractions": "1.0.0-*", - "Microsoft.AspNet.Server.Kestrel": "1.0.0-*", - "Microsoft.AspNet.Testing": "1.0.0-*", + "Microsoft.AspNetCore.Http.Abstractions": "1.0.0-*", + "Microsoft.AspNetCore.Server.Kestrel": "1.0.0-*", + "Microsoft.AspNetCore.Testing": "1.0.0-*", "System.Net.Http": "4.0.1-*", "xunit.runner.aspnet": "2.0.0-aspnet-*" }, diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/AsciiDecoder.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/AsciiDecoder.cs index 245eeee086..4664053bf8 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/AsciiDecoder.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/AsciiDecoder.cs @@ -1,12 +1,12 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; using System.Linq; -using Microsoft.AspNet.Server.Kestrel.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; using Xunit; -namespace Microsoft.AspNet.Server.KestrelTests +namespace Microsoft.AspNetCore.Server.KestrelTests { public class AsciiDecoderTests { diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkWriterTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkWriterTests.cs index 3a2dd71030..af70086103 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkWriterTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkWriterTests.cs @@ -1,12 +1,12 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Linq; using System.Text; -using Microsoft.AspNet.Server.Kestrel.Http; +using Microsoft.AspNetCore.Server.Kestrel.Http; using Xunit; -namespace Microsoft.AspNet.Server.KestrelTests +namespace Microsoft.AspNetCore.Server.KestrelTests { public class ChunkWriterTests { diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedResponseTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedResponseTests.cs index ad0a9120c9..42a08006f2 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedResponseTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedResponseTests.cs @@ -1,13 +1,13 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; using System.Text; using System.Threading.Tasks; -using Microsoft.AspNet.Testing.xunit; +using Microsoft.AspNetCore.Testing.xunit; using Xunit; -namespace Microsoft.AspNet.Server.KestrelTests +namespace Microsoft.AspNetCore.Server.KestrelTests { public class ChunkedResponseTests { diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionFilterTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionFilterTests.cs index d0947f8d4c..1eef8a6c5c 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionFilterTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionFilterTests.cs @@ -1,16 +1,16 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; using System.IO; using System.Threading.Tasks; -using Microsoft.AspNet.Http; -using Microsoft.AspNet.Http.Features; -using Microsoft.AspNet.Server.Kestrel.Filter; -using Microsoft.AspNet.Testing.xunit; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Http.Features; +using Microsoft.AspNetCore.Server.Kestrel.Filter; +using Microsoft.AspNetCore.Testing.xunit; using Xunit; -namespace Microsoft.AspNet.Server.KestrelTests +namespace Microsoft.AspNetCore.Server.KestrelTests { public class ConnectionFilterTests { diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/CreateIPEndpointTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/CreateIPEndpointTests.cs index e8a14e55b8..7c097f66e8 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/CreateIPEndpointTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/CreateIPEndpointTests.cs @@ -1,12 +1,12 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Net; -using Microsoft.AspNet.Server.Kestrel; -using Microsoft.AspNet.Server.Kestrel.Networking; +using Microsoft.AspNetCore.Server.Kestrel; +using Microsoft.AspNetCore.Server.Kestrel.Networking; using Xunit; -namespace Microsoft.AspNet.Server.KestrelTests +namespace Microsoft.AspNetCore.Server.KestrelTests { public class CreateIPEndpointTests { diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/DateHeaderValueManagerTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/DateHeaderValueManagerTests.cs index ef5e31ca6d..d357ece6ae 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/DateHeaderValueManagerTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/DateHeaderValueManagerTests.cs @@ -1,14 +1,14 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; using System.Threading.Tasks; -using Microsoft.AspNet.Server.Kestrel.Http; -using Microsoft.AspNet.Server.Kestrel.Infrastructure; -using Microsoft.AspNet.Server.KestrelTests.TestHelpers; +using Microsoft.AspNetCore.Server.Kestrel.Http; +using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; +using Microsoft.AspNetCore.Server.KestrelTests.TestHelpers; using Xunit; -namespace Microsoft.AspNet.Server.KestrelTests +namespace Microsoft.AspNetCore.Server.KestrelTests { public class DateHeaderValueManagerTests { diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/DummyApplication.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/DummyApplication.cs index 540b9d2f47..c1ef6f86b7 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/DummyApplication.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/DummyApplication.cs @@ -1,14 +1,14 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; using System.Threading.Tasks; -using Microsoft.AspNet.Hosting.Server; -using Microsoft.AspNet.Http; -using Microsoft.AspNet.Http.Internal; -using Microsoft.AspNet.Http.Features; +using Microsoft.AspNetCore.Hosting.Server; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Http.Internal; +using Microsoft.AspNetCore.Http.Features; -namespace Microsoft.AspNet.Server.KestrelTests +namespace Microsoft.AspNetCore.Server.KestrelTests { public class DummyApplication : IHttpApplication { diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs index b18736daa8..a44f096129 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -9,16 +9,16 @@ using System.Net.Sockets; using System.Text; using System.Threading; using System.Threading.Tasks; -using Microsoft.AspNet.Http; -using Microsoft.AspNet.Http.Features; -using Microsoft.AspNet.Server.Kestrel; -using Microsoft.AspNet.Server.Kestrel.Filter; -using Microsoft.AspNet.Server.Kestrel.Infrastructure; -using Microsoft.AspNet.Testing.xunit; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Http.Features; +using Microsoft.AspNetCore.Server.Kestrel; +using Microsoft.AspNetCore.Server.Kestrel.Filter; +using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; +using Microsoft.AspNetCore.Testing.xunit; using Microsoft.Extensions.Logging; using Xunit; -namespace Microsoft.AspNet.Server.KestrelTests +namespace Microsoft.AspNetCore.Server.KestrelTests { /// /// Summary description for EngineTests diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameFacts.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameFacts.cs index 400b6ac42d..deefd5511d 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameFacts.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameFacts.cs @@ -1,12 +1,12 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using Microsoft.AspNet.Http.Features; -using Microsoft.AspNet.Server.Kestrel; -using Microsoft.AspNet.Server.Kestrel.Http; +using Microsoft.AspNetCore.Http.Features; +using Microsoft.AspNetCore.Server.Kestrel; +using Microsoft.AspNetCore.Server.Kestrel.Http; using Xunit; -namespace Microsoft.AspNet.Server.KestrelTests +namespace Microsoft.AspNetCore.Server.KestrelTests { public class FrameFacts { diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameRequestHeadersTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameRequestHeadersTests.cs index 0206fcada2..314ee32aa3 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameRequestHeadersTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameRequestHeadersTests.cs @@ -1,10 +1,10 @@ using System; using System.Collections.Generic; -using Microsoft.AspNet.Server.Kestrel.Http; +using Microsoft.AspNetCore.Server.Kestrel.Http; using Microsoft.Extensions.Primitives; using Xunit; -namespace Microsoft.AspNet.Server.KestrelTests +namespace Microsoft.AspNetCore.Server.KestrelTests { public class FrameRequestHeadersTests { diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameResponseHeadersTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameResponseHeadersTests.cs index 1526c53b26..5fa4f6bec2 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameResponseHeadersTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameResponseHeadersTests.cs @@ -3,12 +3,12 @@ using System; using System.Collections.Generic; -using Microsoft.AspNet.Server.Kestrel; -using Microsoft.AspNet.Server.Kestrel.Http; +using Microsoft.AspNetCore.Server.Kestrel; +using Microsoft.AspNetCore.Server.Kestrel.Http; using Microsoft.Extensions.Primitives; using Xunit; -namespace Microsoft.AspNet.Server.KestrelTests +namespace Microsoft.AspNetCore.Server.KestrelTests { public class FrameResponseHeadersTests { diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs index 5960510eff..20fb2ad932 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs @@ -4,12 +4,12 @@ using System; using System.Linq; using System.Text; -using Microsoft.AspNet.Server.Kestrel; -using Microsoft.AspNet.Server.Kestrel.Http; -using Microsoft.AspNet.Server.Kestrel.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel; +using Microsoft.AspNetCore.Server.Kestrel.Http; +using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; using Xunit; -namespace Microsoft.AspNet.Server.KestrelTests +namespace Microsoft.AspNetCore.Server.KestrelTests { public class FrameTests { diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/HttpsConnectionFilterTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/HttpsConnectionFilterTests.cs index 1f7ca8c4d2..7749164bd2 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/HttpsConnectionFilterTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/HttpsConnectionFilterTests.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -11,14 +11,14 @@ using System.Net.Sockets; using System.Security.Cryptography.X509Certificates; using System.Text; using System.Threading.Tasks; -using Microsoft.AspNet.Http; -using Microsoft.AspNet.Http.Features; -using Microsoft.AspNet.Server.Kestrel.Filter; -using Microsoft.AspNet.Server.Kestrel.Https; -using Microsoft.AspNet.Testing.xunit; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Http.Features; +using Microsoft.AspNetCore.Server.Kestrel.Filter; +using Microsoft.AspNetCore.Server.Kestrel.Https; +using Microsoft.AspNetCore.Testing.xunit; using Xunit; -namespace Microsoft.AspNet.Server.KestrelTests +namespace Microsoft.AspNetCore.Server.KestrelTests { public class HttpsConnectionFilterTests { diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerInformationTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerInformationTests.cs index e2376c0d94..9818d9d426 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerInformationTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerInformationTests.cs @@ -1,13 +1,13 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; using System.Collections.Generic; -using Microsoft.AspNet.Server.Kestrel; +using Microsoft.AspNetCore.Server.Kestrel; using Microsoft.Extensions.Configuration; using Xunit; -namespace Microsoft.AspNet.Server.KestrelTests +namespace Microsoft.AspNetCore.Server.KestrelTests { public class KestrelServerInformationTests { diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerTests.cs index 23e2ff68a7..d54202dc9d 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerTests.cs @@ -1,15 +1,15 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using Microsoft.AspNet.Hosting.Server; -using Microsoft.AspNet.Http.Features; -using Microsoft.AspNet.Server.Kestrel; -using Microsoft.AspNet.Server.Kestrel.Infrastructure; +using Microsoft.AspNetCore.Hosting.Server; +using Microsoft.AspNetCore.Http.Features; +using Microsoft.AspNetCore.Server.Kestrel; +using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; using Microsoft.Extensions.Configuration; using Xunit; -namespace Microsoft.AspNet.Server.KestrelTests +namespace Microsoft.AspNetCore.Server.KestrelTests { public class KestrelServerTests { diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/LifetimeNotImplemented.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/LifetimeNotImplemented.cs index e014424b41..feba1c80fd 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/LifetimeNotImplemented.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/LifetimeNotImplemented.cs @@ -1,11 +1,11 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; using System.Threading; -using Microsoft.AspNet.Hosting; +using Microsoft.AspNetCore.Hosting; -namespace Microsoft.AspNet.Server.KestrelTests +namespace Microsoft.AspNetCore.Server.KestrelTests { public class LifetimeNotImplemented : IApplicationLifetime { diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolBlock2Tests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolBlock2Tests.cs index 2cbd077180..8411df9a39 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolBlock2Tests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolBlock2Tests.cs @@ -1,10 +1,10 @@ -using System; +using System; using System.Linq; -using Microsoft.AspNet.Server.Kestrel.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; using System.Numerics; using Xunit; -namespace Microsoft.AspNet.Server.KestrelTests +namespace Microsoft.AspNetCore.Server.KestrelTests { public class MemoryPoolBlock2Tests { diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolExtensions.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolExtensions.cs index 1eb6830889..d822185aee 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolExtensions.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolExtensions.cs @@ -1,6 +1,6 @@ -using Microsoft.AspNet.Server.Kestrel.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; -namespace Microsoft.AspNet.Server.KestrelTests +namespace Microsoft.AspNetCore.Server.KestrelTests { public static class MemoryPoolExtensions { diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolIterator2Tests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolIterator2Tests.cs index 627cd0dfa2..046f032fc2 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolIterator2Tests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolIterator2Tests.cs @@ -1,10 +1,10 @@ -using System; +using System; using System.Linq; -using Microsoft.AspNet.Server.Kestrel.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; using System.Numerics; using Xunit; -namespace Microsoft.AspNet.Server.KestrelTests +namespace Microsoft.AspNetCore.Server.KestrelTests { public class MemoryPoolIterator2Tests : IDisposable { diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/MessageBodyTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/MessageBodyTests.cs index f93c144c8f..9811de2ec7 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/MessageBodyTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/MessageBodyTests.cs @@ -4,10 +4,10 @@ using System; using System.Text; using System.Threading.Tasks; -using Microsoft.AspNet.Server.Kestrel.Http; +using Microsoft.AspNetCore.Server.Kestrel.Http; using Xunit; -namespace Microsoft.AspNet.Server.KestrelTests +namespace Microsoft.AspNetCore.Server.KestrelTests { /// /// Summary description for MessageBodyTests diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/MultipleLoopTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/MultipleLoopTests.cs index 44a5757f80..6c4d2e8ed0 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/MultipleLoopTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/MultipleLoopTests.cs @@ -1,14 +1,14 @@ -using System; +using System; using System.Net; using System.Net.Sockets; using System.Runtime.InteropServices; using System.Threading; -using Microsoft.AspNet.Server.Kestrel; -using Microsoft.AspNet.Server.Kestrel.Infrastructure; -using Microsoft.AspNet.Server.Kestrel.Networking; +using Microsoft.AspNetCore.Server.Kestrel; +using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Networking; using Xunit; -namespace Microsoft.AspNet.Server.KestrelTests +namespace Microsoft.AspNetCore.Server.KestrelTests { public class MultipleLoopTests { diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/NetworkingTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/NetworkingTests.cs index edaa50870e..86b2f8fe5a 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/NetworkingTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/NetworkingTests.cs @@ -6,12 +6,12 @@ using System.Net; using System.Net.Sockets; using System.Runtime.InteropServices; using System.Threading.Tasks; -using Microsoft.AspNet.Server.Kestrel; -using Microsoft.AspNet.Server.Kestrel.Infrastructure; -using Microsoft.AspNet.Server.Kestrel.Networking; +using Microsoft.AspNetCore.Server.Kestrel; +using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Networking; using Xunit; -namespace Microsoft.AspNet.Server.KestrelTests +namespace Microsoft.AspNetCore.Server.KestrelTests { /// /// Summary description for NetworkingTests diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/Program.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/Program.cs index 0b825ad664..4f4b5827c6 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/Program.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/Program.cs @@ -1,10 +1,10 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; using Microsoft.Extensions.PlatformAbstractions; -namespace Microsoft.AspNet.Server.KestrelTests +namespace Microsoft.AspNetCore.Server.KestrelTests { /// /// Summary description for Program diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/ServerAddressFacts.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/ServerAddressFacts.cs index 1a77598a83..9738dac675 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/ServerAddressFacts.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/ServerAddressFacts.cs @@ -1,7 +1,7 @@ -using Microsoft.AspNet.Server.Kestrel; +using Microsoft.AspNetCore.Server.Kestrel; using Xunit; -namespace Microsoft.AspNet.Server.KestrelTests +namespace Microsoft.AspNetCore.Server.KestrelTests { public class ServerAddressFacts { diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/SocketInputTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/SocketInputTests.cs index 5a38bf87ef..f9d1f7ac22 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/SocketInputTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/SocketInputTests.cs @@ -1,14 +1,14 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; using System.Threading.Tasks; -using Microsoft.AspNet.Server.Kestrel; -using Microsoft.AspNet.Server.Kestrel.Http; -using Microsoft.AspNet.Server.Kestrel.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel; +using Microsoft.AspNetCore.Server.Kestrel.Http; +using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; using Xunit; -namespace Microsoft.AspNet.Server.KestrelTests +namespace Microsoft.AspNetCore.Server.KestrelTests { public class SocketInputTests { diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/SocketOutputTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/SocketOutputTests.cs index bda6bfb651..01c42c5f18 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/SocketOutputTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/SocketOutputTests.cs @@ -1,18 +1,18 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; -using Microsoft.AspNet.Server.Kestrel; -using Microsoft.AspNet.Server.Kestrel.Http; -using Microsoft.AspNet.Server.Kestrel.Infrastructure; -using Microsoft.AspNet.Server.Kestrel.Networking; -using Microsoft.AspNet.Server.KestrelTests.TestHelpers; +using Microsoft.AspNetCore.Server.Kestrel; +using Microsoft.AspNetCore.Server.Kestrel.Http; +using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Networking; +using Microsoft.AspNetCore.Server.KestrelTests.TestHelpers; using Xunit; -namespace Microsoft.AspNet.Server.KestrelTests +namespace Microsoft.AspNetCore.Server.KestrelTests { public class SocketOutputTests { diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/StreamSocketOutputTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/StreamSocketOutputTests.cs index 7b19bf6173..e787ed8589 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/StreamSocketOutputTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/StreamSocketOutputTests.cs @@ -1,13 +1,13 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; using System.IO; -using Microsoft.AspNet.Server.Kestrel.Filter; -using Microsoft.AspNet.Server.Kestrel.Http; +using Microsoft.AspNetCore.Server.Kestrel.Filter; +using Microsoft.AspNetCore.Server.Kestrel.Http; using Xunit; -namespace Microsoft.AspNet.Server.KestrelTests +namespace Microsoft.AspNetCore.Server.KestrelTests { public class StreamSocketOutputTests { diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestConnection.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/TestConnection.cs index e47c2fc319..268eaa7b78 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/TestConnection.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/TestConnection.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -10,7 +10,7 @@ using System.Text; using System.Threading.Tasks; using Xunit; -namespace Microsoft.AspNet.Server.KestrelTests +namespace Microsoft.AspNetCore.Server.KestrelTests { /// /// Summary description for TestConnection diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestDateHeaderValueManager.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/TestDateHeaderValueManager.cs index c69221b0ce..f558080e9d 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/TestDateHeaderValueManager.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/TestDateHeaderValueManager.cs @@ -1,10 +1,10 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using Microsoft.AspNet.Server.Kestrel.Http; +using Microsoft.AspNetCore.Server.Kestrel.Http; -namespace Microsoft.AspNet.Server.KestrelTests +namespace Microsoft.AspNetCore.Server.KestrelTests { public class TestDateHeaderValueManager : DateHeaderValueManager { diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockLibuv.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockLibuv.cs index 9a05659186..4cc9549d78 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockLibuv.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockLibuv.cs @@ -1,8 +1,8 @@ using System; using System.Threading; -using Microsoft.AspNet.Server.Kestrel.Networking; +using Microsoft.AspNetCore.Server.Kestrel.Networking; -namespace Microsoft.AspNet.Server.KestrelTests.TestHelpers +namespace Microsoft.AspNetCore.Server.KestrelTests.TestHelpers { public class MockLibuv : Libuv { diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockSystemClock.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockSystemClock.cs index 6dbf6e3556..75c8951e60 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockSystemClock.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockSystemClock.cs @@ -1,10 +1,10 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using Microsoft.AspNet.Server.Kestrel.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; -namespace Microsoft.AspNet.Server.KestrelTests.TestHelpers +namespace Microsoft.AspNetCore.Server.KestrelTests.TestHelpers { public class MockSystemClock : ISystemClock { diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestInput.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/TestInput.cs index 14c3213903..d1e89a85b4 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/TestInput.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/TestInput.cs @@ -1,14 +1,14 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; using System.Threading; using System.Threading.Tasks; -using Microsoft.AspNet.Server.Kestrel; -using Microsoft.AspNet.Server.Kestrel.Http; -using Microsoft.AspNet.Server.Kestrel.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel; +using Microsoft.AspNetCore.Server.Kestrel.Http; +using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; -namespace Microsoft.AspNet.Server.KestrelTests +namespace Microsoft.AspNetCore.Server.KestrelTests { class TestInput : IConnectionControl, IFrameControl { diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestLogger.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/TestLogger.cs index b9123285d9..2697a4b7ef 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/TestLogger.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/TestLogger.cs @@ -1,8 +1,8 @@ using System; -using Microsoft.AspNet.Server.Kestrel; +using Microsoft.AspNetCore.Server.Kestrel; using Microsoft.Extensions.Logging; -namespace Microsoft.AspNet.Server.KestrelTests +namespace Microsoft.AspNetCore.Server.KestrelTests { public class TestKestrelTrace : KestrelTrace { diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestServer.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/TestServer.cs index 42efcb3793..72fbf28f47 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/TestServer.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/TestServer.cs @@ -1,12 +1,12 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using Microsoft.AspNet.Http; -using Microsoft.AspNet.Server.Kestrel; -using Microsoft.AspNet.Server.Kestrel.Http; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Server.Kestrel; +using Microsoft.AspNetCore.Server.Kestrel.Http; -namespace Microsoft.AspNet.Server.KestrelTests +namespace Microsoft.AspNetCore.Server.KestrelTests { /// /// Summary description for TestServer diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestServiceContext.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/TestServiceContext.cs index 54dfc3c3b3..4224c776d3 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/TestServiceContext.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/TestServiceContext.cs @@ -1,12 +1,12 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using Microsoft.AspNet.Http; -using Microsoft.AspNet.Server.Kestrel; -using Microsoft.AspNet.Server.Kestrel.Http; -using Microsoft.AspNet.Server.Kestrel.Infrastructure; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Server.Kestrel; +using Microsoft.AspNetCore.Server.Kestrel.Http; +using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; -namespace Microsoft.AspNet.Server.KestrelTests +namespace Microsoft.AspNetCore.Server.KestrelTests { public class TestServiceContext : ServiceContext { diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/UrlPathDecoder.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/UrlPathDecoder.cs index 02769fd01f..e8a64e2497 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/UrlPathDecoder.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/UrlPathDecoder.cs @@ -1,13 +1,13 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; using System.Linq; -using Microsoft.AspNet.Server.Kestrel.Http; -using Microsoft.AspNet.Server.Kestrel.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Http; +using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; using Xunit; -namespace Microsoft.AspNet.Server.KestrelTests +namespace Microsoft.AspNetCore.Server.KestrelTests { public class UrlPathDecoderTests { diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/project.json b/test/Microsoft.AspNetCore.Server.KestrelTests/project.json index 4060d91d5e..e788721ede 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/project.json +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/project.json @@ -2,9 +2,9 @@ "version": "1.0.0-*", "dependencies": { "xunit.runner.aspnet": "2.0.0-aspnet-*", - "Microsoft.AspNet.Server.Kestrel": "1.0.0-*", - "Microsoft.AspNet.Server.Kestrel.Https": "1.0.0-*", - "Microsoft.AspNet.Testing": "1.0.0-*", + "Microsoft.AspNetCore.Server.Kestrel": "1.0.0-*", + "Microsoft.AspNetCore.Server.Kestrel.Https": "1.0.0-*", + "Microsoft.AspNetCore.Testing": "1.0.0-*", "System.Net.Http": "4.0.1-*" }, "frameworks": { @@ -23,7 +23,7 @@ "keyFile": "../../tools/Key.snk" }, "commands": { - "run": "Microsoft.AspNet.Server.KestrelTests", + "run": "Microsoft.AspNetCore.Server.KestrelTests", "test": "xunit.runner.aspnet -parallel none" } } diff --git a/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/FrameFeatureCollection.cs b/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/FrameFeatureCollection.cs index e32e54c133..a84d3a9c59 100644 --- a/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/FrameFeatureCollection.cs +++ b/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/FrameFeatureCollection.cs @@ -1,12 +1,12 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; -using Microsoft.AspNet.Http.Features; +using Microsoft.AspNetCore.Http.Features; using Microsoft.Dnx.Compilation.CSharp; -using Microsoft.AspNet.Http.Features.Internal; -using Microsoft.AspNet.Http.Features.Authentication; +using Microsoft.AspNetCore.Http.Features.Internal; +using Microsoft.AspNetCore.Http.Features.Authentication; -namespace Microsoft.AspNet.Server.Kestrel.GeneratedCode +namespace Microsoft.AspNetCore.Server.Kestrel.GeneratedCode { // This project can output the Class library as a NuGet Package. // To enable this option, right-click on the project and select the Properties menu item. In the Build tab select "Produce outputs on build". @@ -60,7 +60,7 @@ namespace Microsoft.AspNet.Server.Kestrel.GeneratedCode var allFeatures = alwaysFeatures.Concat(commonFeatures).Concat(sometimesFeatures).Concat(rareFeatures); // NOTE: This list MUST always match the set of feature interfaces implemented by Frame. - // See also: src/Microsoft.AspNet.Server.Kestrel/Http/Frame.FeatureCollection.cs + // See also: src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.FeatureCollection.cs var implementedFeatures = new[] { typeof(IHttpRequestFeature), @@ -74,7 +74,7 @@ namespace Microsoft.AspNet.Server.Kestrel.GeneratedCode using System; using System.Collections.Generic; -namespace Microsoft.AspNet.Server.Kestrel.Http +namespace Microsoft.AspNetCore.Server.Kestrel.Http {{ public partial class Frame {{{Each(allFeatures, feature => $@" diff --git a/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/KnownHeaders.cs b/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/KnownHeaders.cs index 9f7c720156..359baa98c3 100644 --- a/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/KnownHeaders.cs +++ b/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/KnownHeaders.cs @@ -4,7 +4,7 @@ using System.Linq; using Microsoft.Dnx.Compilation.CSharp; using System.Text; -namespace Microsoft.AspNet.Server.Kestrel.GeneratedCode +namespace Microsoft.AspNetCore.Server.Kestrel.GeneratedCode { // This project can output the Class library as a NuGet Package. // To enable this option, right-click on the project and select the Properties menu item. In the Build tab select "Produce outputs on build". @@ -205,10 +205,10 @@ namespace Microsoft.AspNet.Server.Kestrel.GeneratedCode using System; using System.Collections.Generic; using System.Text; -using Microsoft.AspNet.Server.Kestrel.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; using Microsoft.Extensions.Primitives; -namespace Microsoft.AspNet.Server.Kestrel.Http +namespace Microsoft.AspNetCore.Server.Kestrel.Http {{ {Each(loops, loop => $@" public partial class {loop.ClassName} diff --git a/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode.xproj b/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode.xproj index 12a75e7f62..f539350093 100644 --- a/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode.xproj +++ b/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode.xproj @@ -1,4 +1,4 @@ - + 14.0 @@ -8,7 +8,7 @@ bd2d4d29-1bd9-40d0-bb31-337d5416b63c - Microsoft.AspNet.Server.Kestrel.GeneratedCode + Microsoft.AspNetCore.Server.Kestrel.GeneratedCode ..\..\artifacts\obj\$(MSBuildProjectName) ..\..\artifacts\bin\$(MSBuildProjectName)\ diff --git a/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/Program.cs b/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/Program.cs index 3727772c03..b146bb58d1 100644 --- a/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/Program.cs +++ b/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/Program.cs @@ -1,7 +1,7 @@ -using System; +using System; using System.IO; -namespace Microsoft.AspNet.Server.Kestrel.GeneratedCode +namespace Microsoft.AspNetCore.Server.Kestrel.GeneratedCode { public class Program { diff --git a/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/project.json b/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/project.json index ede3a70f54..67117cd620 100644 --- a/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/project.json +++ b/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/project.json @@ -3,12 +3,12 @@ "dependencies": { "Microsoft.Dnx.Compilation.CSharp.Abstractions": "1.0.0-*", - "Microsoft.AspNet.Http.Features": "1.0.0-*", - "Microsoft.AspNet.Hosting": "1.0.0-*" + "Microsoft.AspNetCore.Http.Features": "1.0.0-*", + "Microsoft.AspNetCore.Hosting": "1.0.0-*" }, "commands": { - "run": "Microsoft.AspNet.Server.Kestrel.GeneratedCode" + "run": "Microsoft.AspNetCore.Server.Kestrel.GeneratedCode" }, "frameworks": { diff --git a/tools/Microsoft.AspNetCore.Server.Kestrel.LibuvCopier/Microsoft.AspNetCore.Server.Kestrel.LibuvCopier.xproj b/tools/Microsoft.AspNetCore.Server.Kestrel.LibuvCopier/Microsoft.AspNetCore.Server.Kestrel.LibuvCopier.xproj index bb7fe23a81..2e3d5e6e7b 100644 --- a/tools/Microsoft.AspNetCore.Server.Kestrel.LibuvCopier/Microsoft.AspNetCore.Server.Kestrel.LibuvCopier.xproj +++ b/tools/Microsoft.AspNetCore.Server.Kestrel.LibuvCopier/Microsoft.AspNetCore.Server.Kestrel.LibuvCopier.xproj @@ -1,4 +1,4 @@ - + 14.0 @@ -8,7 +8,7 @@ 8cba6fe3-3cc9-4420-8aa3-123e983734c2 - Microsoft.AspNet.Server.Kestrel.LibuvCopier + Microsoft.AspNetCore.Server.Kestrel.LibuvCopier ..\..\artifacts\obj\$(MSBuildProjectName) ..\..\artifacts\bin\$(MSBuildProjectName)\ diff --git a/tools/Microsoft.AspNetCore.Server.Kestrel.LibuvCopier/Program.cs b/tools/Microsoft.AspNetCore.Server.Kestrel.LibuvCopier/Program.cs index b76dd16fe8..6fb635145a 100644 --- a/tools/Microsoft.AspNetCore.Server.Kestrel.LibuvCopier/Program.cs +++ b/tools/Microsoft.AspNetCore.Server.Kestrel.LibuvCopier/Program.cs @@ -1,9 +1,9 @@ -using System; +using System; using System.IO; using System.Linq; using Newtonsoft.Json.Linq; -namespace Microsoft.AspNet.Server.Kestrel.LibuvCopier +namespace Microsoft.AspNetCore.Server.Kestrel.LibuvCopier { public class Program { @@ -41,7 +41,7 @@ namespace Microsoft.AspNet.Server.Kestrel.LibuvCopier var lockJson = JObject.Parse(File.ReadAllText("project.lock.json")); foreach (var libuvLib in lockJson["libraries"].OfType().Where( - p => p.Name.StartsWith("Microsoft.AspNet.Internal.libuv", StringComparison.Ordinal))) + p => p.Name.StartsWith("Microsoft.AspNetCore.Internal.libuv", StringComparison.Ordinal))) { foreach (var filePath in libuvLib.Value["files"].Select(v => v.Value())) { diff --git a/tools/Microsoft.AspNetCore.Server.Kestrel.LibuvCopier/project.json b/tools/Microsoft.AspNetCore.Server.Kestrel.LibuvCopier/project.json index a9b68f0ec4..76f2bc1459 100644 --- a/tools/Microsoft.AspNetCore.Server.Kestrel.LibuvCopier/project.json +++ b/tools/Microsoft.AspNetCore.Server.Kestrel.LibuvCopier/project.json @@ -1,6 +1,6 @@ { "version": "1.0.0-*", - "description": "Microsoft.AspNet.Server.Kestrel.LibuvCopier Console Application", + "description": "Microsoft.AspNetCore.Server.Kestrel.LibuvCopier Console Application", "authors": [ "pawelka" ], "tags": [ "" ], "projectUrl": "", @@ -12,7 +12,7 @@ }, "commands": { - "Microsoft.AspNet.Server.Kestrel.LibuvCopier": "Microsoft.AspNet.Server.Kestrel.LibuvCopier" + "Microsoft.AspNetCore.Server.Kestrel.LibuvCopier": "Microsoft.AspNetCore.Server.Kestrel.LibuvCopier" }, "frameworks": { From 73bb0ab5b8aabff5193f7e512de55357263f1b43 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Fri, 15 Jan 2016 13:08:40 +0000 Subject: [PATCH 0577/1662] SocketOutput Cancellation handling --- .../Http/Frame.cs | 45 +++-- .../Http/FrameOfT.cs | 5 +- .../Http/FrameRequestStream.cs | 31 +-- .../Http/FrameResponseStream.cs | 43 +++-- .../Http/MessageBody.cs | 2 - .../Http/SocketInput.cs | 7 +- .../Http/SocketOutput.cs | 177 +++++++++++++----- .../Infrastructure/IKestrelTrace.cs | 4 + .../Infrastructure/IThreadPool.cs | 1 + .../Infrastructure/KestrelTrace.cs | 14 ++ .../Infrastructure/LoggingThreadPool.cs | 18 ++ .../Infrastructure/MemoryPoolIterator2.cs | 10 + .../Infrastructure/TaskUtilities.cs | 20 ++ .../EngineTests.cs | 18 +- .../SocketInputTests.cs | 2 +- .../SocketOutputTests.cs | 132 +++++++++++-- 16 files changed, 421 insertions(+), 108 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs index d5225447d1..5cd4f8c378 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs @@ -56,7 +56,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http private bool _requestProcessingStarted; private Task _requestProcessingTask; protected volatile bool _requestProcessingStopping; // volatile, see: https://msdn.microsoft.com/en-us/library/x13ttww7.aspx - protected volatile bool _requestAborted; + protected int _requestAborted; protected CancellationTokenSource _abortedCts; protected CancellationToken? _manuallySetRequestAbortToken; @@ -167,7 +167,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http var cts = _abortedCts; return cts != null ? cts.Token : - _requestAborted ? new CancellationToken(true) : + (Volatile.Read(ref _requestAborted) == 1) ? new CancellationToken(true) : RequestAbortedSource.Token; } set @@ -185,7 +185,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http // Get the abort token, lazily-initializing it if necessary. // Make sure it's canceled if an abort request already came in. var cts = LazyInitializer.EnsureInitialized(ref _abortedCts, () => new CancellationTokenSource()); - if (_requestAborted) + if (Volatile.Read(ref _requestAborted) == 1) { cts.Cancel(); } @@ -288,24 +288,31 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http /// public void Abort() { - _requestProcessingStopping = true; - _requestAborted = true; + if (Interlocked.CompareExchange(ref _requestAborted, 1, 0) == 0) + { + _requestProcessingStopping = true; - _requestBody?.Abort(); - _responseBody?.Abort(); + _requestBody?.Abort(); + _responseBody?.Abort(); - try - { - ConnectionControl.End(ProduceEndType.SocketDisconnect); - SocketInput.AbortAwaiting(); - RequestAbortedSource.Cancel(); - } - catch (Exception ex) - { - Log.LogError("Abort", ex); - } - finally - { + try + { + ConnectionControl.End(ProduceEndType.SocketDisconnect); + SocketInput.AbortAwaiting(); + } + catch (Exception ex) + { + Log.LogError("Abort", ex); + } + + try + { + RequestAbortedSource.Cancel(); + } + catch (Exception ex) + { + Log.LogError("Abort", ex); + } _abortedCts = null; } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameOfT.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameOfT.cs index 0f3d8d48d6..e9498b1d40 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameOfT.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameOfT.cs @@ -3,6 +3,7 @@ using System; using System.Net; +using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Hosting.Server; using Microsoft.AspNetCore.Http.Features; @@ -111,7 +112,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http _application.DisposeContext(context, _applicationException); // If _requestAbort is set, the connection has already been closed. - if (!_requestAborted) + if (Volatile.Read(ref _requestAborted) == 0) { _responseBody.ResumeAcceptingWrites(); await ProduceEnd(); @@ -148,7 +149,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http _abortedCts = null; // If _requestAborted is set, the connection has already been closed. - if (!_requestAborted) + if (Volatile.Read(ref _requestAborted) == 0) { // Inform client no more data will ever arrive ConnectionControl.End(ProduceEndType.SocketShutdownSend); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameRequestStream.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameRequestStream.cs index dc70690b32..efd3669104 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameRequestStream.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameRequestStream.cs @@ -5,6 +5,7 @@ using System; using System.IO; using System.Threading; using System.Threading.Tasks; +using Microsoft.AspNet.Server.Kestrel.Infrastructure; namespace Microsoft.AspNetCore.Server.Kestrel.Http { @@ -51,8 +52,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http public override int Read(byte[] buffer, int offset, int count) { - ValidateState(); - // ValueTask uses .GetAwaiter().GetResult() if necessary return ReadAsync(buffer, offset, count).Result; } @@ -60,7 +59,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http #if NET451 public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback callback, object state) { - ValidateState(); + ValidateState(CancellationToken.None); var task = ReadAsync(buffer, offset, count, CancellationToken.None, state); if (callback != null) @@ -77,7 +76,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http private Task ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken, object state) { - ValidateState(); + ValidateState(cancellationToken); var tcs = new TaskCompletionSource(state); var task = _body.ReadAsync(new ArraySegment(buffer, offset, count), cancellationToken); @@ -103,10 +102,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http public override Task ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) { - ValidateState(); - - // Needs .AsTask to match Stream's Async method return types - return _body.ReadAsync(new ArraySegment(buffer, offset, count), cancellationToken).AsTask(); + var task = ValidateState(cancellationToken); + if (task == null) + { + // Needs .AsTask to match Stream's Async method return types + return _body.ReadAsync(new ArraySegment(buffer, offset, count), cancellationToken).AsTask(); + } + return task; } public override void Write(byte[] buffer, int offset, int count) @@ -149,24 +151,29 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http public void Abort() { // We don't want to throw an ODE until the app func actually completes. - // If the request is aborted, we throw an IOException instead. + // If the request is aborted, we throw an TaskCanceledException instead. if (_state != FrameStreamState.Closed) { _state = FrameStreamState.Aborted; } } - private void ValidateState() + private Task ValidateState(CancellationToken cancellationToken) { switch (_state) { case FrameStreamState.Open: - return; + if (cancellationToken.IsCancellationRequested) + { + return TaskUtilities.GetCancelledZeroTask(); + } + break; case FrameStreamState.Closed: throw new ObjectDisposedException(nameof(FrameRequestStream)); case FrameStreamState.Aborted: - throw new IOException("The request has been aborted."); + return TaskUtilities.GetCancelledZeroTask(); } + return null; } } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameResponseStream.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameResponseStream.cs index f45470f555..d5b4f41aea 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameResponseStream.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameResponseStream.cs @@ -5,6 +5,7 @@ using System; using System.IO; using System.Threading; using System.Threading.Tasks; +using Microsoft.AspNet.Server.Kestrel.Infrastructure; namespace Microsoft.AspNetCore.Server.Kestrel.Http { @@ -37,16 +38,19 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http public override void Flush() { - ValidateState(); + ValidateState(CancellationToken.None); _context.FrameControl.Flush(); } public override Task FlushAsync(CancellationToken cancellationToken) { - ValidateState(); - - return _context.FrameControl.FlushAsync(cancellationToken); + var task = ValidateState(cancellationToken); + if (task == null) + { + return _context.FrameControl.FlushAsync(cancellationToken); + } + return task; } public override long Seek(long offset, SeekOrigin origin) @@ -66,16 +70,19 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http public override void Write(byte[] buffer, int offset, int count) { - ValidateState(); + ValidateState(CancellationToken.None); _context.FrameControl.Write(new ArraySegment(buffer, offset, count)); } public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) { - ValidateState(); - - return _context.FrameControl.WriteAsync(new ArraySegment(buffer, offset, count), cancellationToken); + var task = ValidateState(cancellationToken); + if (task == null) + { + return _context.FrameControl.WriteAsync(new ArraySegment(buffer, offset, count), cancellationToken); + } + return task; } public Stream StartAcceptingWrites() @@ -112,24 +119,36 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http public void Abort() { // We don't want to throw an ODE until the app func actually completes. - // If the request is aborted, we throw an IOException instead. if (_state != FrameStreamState.Closed) { _state = FrameStreamState.Aborted; } } - private void ValidateState() + private Task ValidateState(CancellationToken cancellationToken) { switch (_state) { case FrameStreamState.Open: - return; + if (cancellationToken.IsCancellationRequested) + { + return TaskUtilities.GetCancelledTask(cancellationToken); + } + break; case FrameStreamState.Closed: throw new ObjectDisposedException(nameof(FrameResponseStream)); case FrameStreamState.Aborted: - throw new IOException("The request has been aborted."); + if (cancellationToken.CanBeCanceled) + { + // Aborted state only throws on write if cancellationToken requests it + return TaskUtilities.GetCancelledTask( + cancellationToken.IsCancellationRequested ? + cancellationToken : + new CancellationToken(true)); + } + break; } + return null; } } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/MessageBody.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/MessageBody.cs index ce9f4aa9cc..daeeeaa9e1 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/MessageBody.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/MessageBody.cs @@ -2,11 +2,9 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.Collections.Generic; using System.IO; using System.Threading; using System.Threading.Tasks; -using Microsoft.Extensions.Primitives; namespace Microsoft.AspNetCore.Server.Kestrel.Http { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketInput.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketInput.cs index 94e335b345..83213cbead 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketInput.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketInput.cs @@ -5,6 +5,7 @@ using System; using System.IO; using System.Runtime.CompilerServices; using System.Threading; +using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; namespace Microsoft.AspNetCore.Server.Kestrel.Http @@ -184,7 +185,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http public void AbortAwaiting() { - _awaitableError = new ObjectDisposedException(nameof(SocketInput), "The request was aborted"); + _awaitableError = new TaskCanceledException("The request was aborted"); Complete(); } @@ -238,6 +239,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http var error = _awaitableError; if (error != null) { + if (error is TaskCanceledException || error is InvalidOperationException) + { + throw error; + } throw new IOException(error.Message, error); } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketOutput.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketOutput.cs index 15a56f9fc8..38533f447b 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketOutput.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketOutput.cs @@ -4,7 +4,6 @@ using System; using System.Collections.Generic; using System.Diagnostics; -using System.IO; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; @@ -22,6 +21,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http private const int _maxPooledWriteContexts = 32; private static readonly WaitCallback _returnBlocks = (state) => ReturnBlocks((MemoryPoolBlock2)state); + private static readonly Action _connectionCancellation = (state) => ((SocketOutput)state).CancellationTriggered(); private readonly KestrelThread _thread; private readonly UvStreamHandle _socket; @@ -78,6 +78,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http public Task WriteAsync( ArraySegment buffer, + CancellationToken cancellationToken, bool immediate = true, bool chunk = false, bool socketShutdownSend = false, @@ -89,9 +90,21 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http lock (_contextLock) { + if (_lastWriteError != null || _socket.IsClosed) + { + _log.ConnectionDisconnectedWrite(_connectionId, buffer.Count, _lastWriteError); + + return TaskUtilities.CompletedTask; + } + if (buffer.Count > 0) { var tail = ProducingStart(); + if (tail.IsDefault) + { + return TaskUtilities.CompletedTask; + } + if (chunk) { _numBytesPreCompleted += ChunkWriter.WriteBeginChunkBytes(ref tail, buffer.Count); @@ -146,13 +159,36 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } else { - // immediate write, which is not eligable for instant completion above - tcs = new TaskCompletionSource(buffer.Count); - _tasksPending.Enqueue(new WaitingTask() { - CompletionSource = tcs, - BytesToWrite = buffer.Count, - IsSync = isSync - }); + if (cancellationToken.CanBeCanceled) + { + if (cancellationToken.IsCancellationRequested) + { + _connection.Abort(); + + return TaskUtilities.GetCancelledTask(cancellationToken); + } + else + { + // immediate write, which is not eligable for instant completion above + tcs = new TaskCompletionSource(); + _tasksPending.Enqueue(new WaitingTask() + { + CancellationToken = cancellationToken, + CancellationRegistration = cancellationToken.Register(_connectionCancellation, this), + BytesToWrite = buffer.Count, + CompletionSource = tcs + }); + } + } + else + { + tcs = new TaskCompletionSource(); + _tasksPending.Enqueue(new WaitingTask() { + IsSync = isSync, + BytesToWrite = buffer.Count, + CompletionSource = tcs + }); + } } if (!_writePending && immediate) @@ -177,12 +213,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { case ProduceEndType.SocketShutdownSend: WriteAsync(default(ArraySegment), + default(CancellationToken), immediate: true, socketShutdownSend: true, socketDisconnect: false); break; case ProduceEndType.SocketDisconnect: WriteAsync(default(ArraySegment), + default(CancellationToken), immediate: true, socketShutdownSend: false, socketDisconnect: true); @@ -198,7 +236,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if (_tail == null) { - throw new IOException("The socket has been closed."); + return default(MemoryPoolIterator2); } _lastStart = new MemoryPoolIterator2(_tail, _tail.End); @@ -251,6 +289,18 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } + private void CancellationTriggered() + { + lock (_contextLock) + { + // Abort the connection for any failed write + // Queued on threadpool so get it in as first op. + _connection?.Abort(); + + CompleteAllWrites(); + } + } + private static void ReturnBlocks(MemoryPoolBlock2 block) { while (block != null) @@ -305,10 +355,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if (error != null) { - _lastWriteError = new IOException(error.Message, error); - - // Abort the connection for any failed write. + // Abort the connection for any failed write + // Queued on threadpool so get it in as first op. _connection.Abort(); + _lastWriteError = error; } PoolWriteContext(writeContext); @@ -317,43 +367,78 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http // completed writes that we haven't triggered callbacks for yet. _numBytesPreCompleted -= bytesWritten; + CompleteFinishedWrites(status); + + if (error != null) + { + _log.ConnectionError(_connectionId, error); + } + else + { + _log.ConnectionWriteCallback(_connectionId, status); + } + } + + private void CompleteNextWrite(ref int bytesLeftToBuffer) + { + var waitingTask = _tasksPending.Dequeue(); + var bytesToWrite = waitingTask.BytesToWrite; + + _numBytesPreCompleted += bytesToWrite; + bytesLeftToBuffer -= bytesToWrite; + + // Dispose registration if there is one + waitingTask.CancellationRegistration?.Dispose(); + + if (waitingTask.CancellationToken.IsCancellationRequested) + { + if (waitingTask.IsSync) + { + waitingTask.CompletionSource.TrySetCanceled(); + } + else + { + _threadPool.Cancel(waitingTask.CompletionSource); + } + } + else + { + if (waitingTask.IsSync) + { + waitingTask.CompletionSource.TrySetResult(null); + } + else + { + _threadPool.Complete(waitingTask.CompletionSource); + } + } + } + + private void CompleteFinishedWrites(int status) + { // bytesLeftToBuffer can be greater than _maxBytesPreCompleted // This allows large writes to complete once they've actually finished. var bytesLeftToBuffer = _maxBytesPreCompleted - _numBytesPreCompleted; while (_tasksPending.Count > 0 && (_tasksPending.Peek().BytesToWrite) <= bytesLeftToBuffer) { - var waitingTask = _tasksPending.Dequeue(); - var bytesToWrite = waitingTask.BytesToWrite; + CompleteNextWrite(ref bytesLeftToBuffer); + } + } - _numBytesPreCompleted += bytesToWrite; - bytesLeftToBuffer -= bytesToWrite; - - if (_lastWriteError == null) - { - if (waitingTask.IsSync) - { - waitingTask.CompletionSource.TrySetResult(null); - } - else - { - _threadPool.Complete(waitingTask.CompletionSource); - } - } - else - { - if (waitingTask.IsSync) - { - waitingTask.CompletionSource.TrySetException(_lastWriteError); - } - else - { - _threadPool.Error(waitingTask.CompletionSource, _lastWriteError); - } - } + private void CompleteAllWrites() + { + var writesToComplete = _tasksPending.Count > 0; + var bytesLeftToBuffer = _maxBytesPreCompleted - _numBytesPreCompleted; + while (_tasksPending.Count > 0) + { + CompleteNextWrite(ref bytesLeftToBuffer); } - _log.ConnectionWriteCallback(_connectionId, status); + if (writesToComplete) + { + _log.ConnectionError(_connectionId, new TaskCanceledException("Connetcion")); + } } // This is called on the libuv event loop @@ -393,12 +478,18 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http void ISocketOutput.Write(ArraySegment buffer, bool immediate, bool chunk) { - WriteAsync(buffer, immediate, chunk, isSync: true).GetAwaiter().GetResult(); + WriteAsync(buffer, CancellationToken.None, immediate, chunk, isSync: true).GetAwaiter().GetResult(); } Task ISocketOutput.WriteAsync(ArraySegment buffer, bool immediate, bool chunk, CancellationToken cancellationToken) { - return WriteAsync(buffer, immediate, chunk); + if (cancellationToken.IsCancellationRequested) + { + _connection?.Abort(); + return TaskUtilities.GetCancelledTask(cancellationToken); + } + + return WriteAsync(buffer, cancellationToken, immediate, chunk); } private static void BytesBetween(MemoryPoolIterator2 start, MemoryPoolIterator2 end, out int bytes, out int buffers) @@ -649,6 +740,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { public bool IsSync; public int BytesToWrite; + public CancellationToken CancellationToken; + public IDisposable CancellationRegistration; public TaskCompletionSource CompletionSource; } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/IKestrelTrace.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/IKestrelTrace.cs index 1cab425247..0ed3c6565a 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/IKestrelTrace.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/IKestrelTrace.cs @@ -29,6 +29,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure void ConnectionWriteCallback(long connectionId, int status); + void ConnectionError(long connectionId, Exception ex); + + void ConnectionDisconnectedWrite(long connectionId, int count, Exception ex); + void ApplicationError(Exception ex); } } \ No newline at end of file diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/IThreadPool.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/IThreadPool.cs index 404bc01a55..f9217bd992 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/IThreadPool.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/IThreadPool.cs @@ -9,6 +9,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure public interface IThreadPool { void Complete(TaskCompletionSource tcs); + void Cancel(TaskCompletionSource tcs); void Error(TaskCompletionSource tcs, Exception ex); void Run(Action action); } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/KestrelTrace.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/KestrelTrace.cs index f9b82ce25b..5e8a2ee28f 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/KestrelTrace.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/KestrelTrace.cs @@ -21,6 +21,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel private static readonly Action _connectionWroteFin; private static readonly Action _connectionKeepAlive; private static readonly Action _connectionDisconnect; + private static readonly Action _connectionError; + private static readonly Action _connectionDisconnectedWrite; protected readonly ILogger _logger; @@ -39,6 +41,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel // ConnectionWrite: Reserved: 11 // ConnectionWriteCallback: Reserved: 12 // ApplicationError: Reserved: 13 - LoggerMessage.Define overload not present + _connectionError = LoggerMessage.Define(LogLevel.Information, 14, @"Connection id ""{ConnectionId}"" communication error"); + _connectionDisconnectedWrite = LoggerMessage.Define(LogLevel.Debug, 15, @"Connection id ""{ConnectionId}"" write of ""{count}"" bytes to disconnected client."); } public KestrelTrace(ILogger logger) @@ -114,6 +118,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel _logger.LogError(13, "An unhandled exception was thrown by the application.", ex); } + public virtual void ConnectionError(long connectionId, Exception ex) + { + _connectionError(_logger, connectionId, ex); + } + + public virtual void ConnectionDisconnectedWrite(long connectionId, int count, Exception ex) + { + _connectionDisconnectedWrite(_logger, connectionId, count, ex); + } + public virtual void Log(LogLevel logLevel, int eventId, object state, Exception exception, Func formatter) { _logger.Log(logLevel, eventId, state, exception, formatter); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/LoggingThreadPool.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/LoggingThreadPool.cs index 70f142f536..a5f41987d4 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/LoggingThreadPool.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/LoggingThreadPool.cs @@ -12,6 +12,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure private readonly IKestrelTrace _log; private readonly WaitCallback _runAction; + private readonly WaitCallback _cancelTcs; private readonly WaitCallback _completeTcs; public LoggingThreadPool(IKestrelTrace log) @@ -42,6 +43,18 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure _log.ApplicationError(e); } }; + + _cancelTcs = (o) => + { + try + { + ((TaskCompletionSource)o).TrySetCanceled(); + } + catch (Exception e) + { + _log.ApplicationError(e); + } + }; } public void Run(Action action) @@ -54,6 +67,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure ThreadPool.QueueUserWorkItem(_completeTcs, tcs); } + public void Cancel(TaskCompletionSource tcs) + { + ThreadPool.QueueUserWorkItem(_cancelTcs, tcs); + } + public void Error(TaskCompletionSource tcs, Exception ex) { // ex ang _log are closure captured diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPoolIterator2.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPoolIterator2.cs index 62b19ced94..8e22ee4018 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPoolIterator2.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPoolIterator2.cs @@ -724,6 +724,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure public void CopyFrom(byte[] data, int offset, int count) { + if (IsDefault) + { + return; + } + Debug.Assert(_block != null); Debug.Assert(_block.Next == null); Debug.Assert(_block.End == _index); @@ -766,6 +771,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure public unsafe void CopyFromAscii(string data) { + if (IsDefault) + { + return; + } + Debug.Assert(_block != null); Debug.Assert(_block.Next == null); Debug.Assert(_block.End == _index); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/TaskUtilities.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/TaskUtilities.cs index a59713eeaa..5e52222d3d 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/TaskUtilities.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/TaskUtilities.cs @@ -1,6 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System.Threading; using System.Threading.Tasks; namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure @@ -13,5 +14,24 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure public static Task CompletedTask = Task.FromResult(null); #endif public static Task ZeroTask = Task.FromResult(0); + + public static Task GetCancelledTask(CancellationToken cancellationToken) + { +#if DOTNET5_4 + return Task.FromCanceled(cancellationToken); +#else + var tcs = new TaskCompletionSource(); + tcs.TrySetCanceled(); + return tcs.Task; +#endif + } + + public static Task GetCancelledZeroTask() + { + // Task.FromCanceled doesn't return Task + var tcs = new TaskCompletionSource(); + tcs.TrySetCanceled(); + return tcs.Task; + } } } \ No newline at end of file diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs index a44f096129..85858ddcf5 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs @@ -1084,7 +1084,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } } - await Assert.ThrowsAsync(async () => await readTcs.Task); + await Assert.ThrowsAsync(async () => await readTcs.Task); // The cancellation token for only the last request should be triggered. var abortedRequestId = await registrationTcs.Task; @@ -1096,6 +1096,12 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Test hangs after execution on Mono.")] public async Task FailedWritesResultInAbortedRequest(ServiceContext testContext) { + const int resetEventTimeout = 2000; + // This should match _maxBytesPreCompleted in SocketOutput + const int maxBytesPreCompleted = 65536; + // Ensure string is long enough to disable write-behind buffering + var largeString = new string('a', maxBytesPreCompleted + 1); + var writeTcs = new TaskCompletionSource(); var registrationWh = new ManualResetEventSlim(); var connectionCloseWh = new ManualResetEventSlim(); @@ -1119,7 +1125,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests // Ensure write is long enough to disable write-behind buffering for (int i = 0; i < 10; i++) { - await response.WriteAsync(new string('a', 65537)); + await response.WriteAsync(largeString).ConfigureAwait(false); } } catch (Exception ex) @@ -1127,7 +1133,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests writeTcs.SetException(ex); // Give a chance for RequestAborted to trip before the app completes - registrationWh.Wait(1000); + registrationWh.Wait(resetEventTimeout); throw; } @@ -1141,16 +1147,16 @@ namespace Microsoft.AspNetCore.Server.KestrelTests "POST / HTTP/1.1", "Content-Length: 5", "", - "Hello"); + "Hello").ConfigureAwait(false); // Don't wait to receive the response. Just close the socket. } connectionCloseWh.Set(); // Write failed - await Assert.ThrowsAsync(async () => await writeTcs.Task); + await Assert.ThrowsAsync(async () => await writeTcs.Task); // RequestAborted tripped - Assert.True(registrationWh.Wait(200)); + Assert.True(registrationWh.Wait(resetEventTimeout)); } } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/SocketInputTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/SocketInputTests.cs index f9d1f7ac22..47d9eb2a87 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/SocketInputTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/SocketInputTests.cs @@ -102,7 +102,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests private static void TestConcurrentFaultedTask(Task t) { Assert.True(t.IsFaulted); - Assert.IsType(typeof(System.IO.IOException), t.Exception.InnerException); + Assert.IsType(typeof(System.InvalidOperationException), t.Exception.InnerException); Assert.Equal(t.Exception.InnerException.Message, "Concurrent reads are not supported."); } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/SocketOutputTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/SocketOutputTests.cs index 01c42c5f18..ec0fe0c9a0 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/SocketOutputTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/SocketOutputTests.cs @@ -50,7 +50,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var completedWh = new ManualResetEventSlim(); // Act - socketOutput.WriteAsync(buffer).ContinueWith( + socketOutput.WriteAsync(buffer, default(CancellationToken)).ContinueWith( (t) => { Assert.Null(t.Exception); @@ -101,14 +101,14 @@ namespace Microsoft.AspNetCore.Server.KestrelTests }; // Act - socketOutput.WriteAsync(buffer).ContinueWith(onCompleted); + socketOutput.WriteAsync(buffer, default(CancellationToken)).ContinueWith(onCompleted); // Assert // The first write should pre-complete since it is <= _maxBytesPreCompleted. Assert.True(completedWh.Wait(1000)); // Arrange completedWh.Reset(); // Act - socketOutput.WriteAsync(buffer).ContinueWith(onCompleted); + socketOutput.WriteAsync(buffer, default(CancellationToken)).ContinueWith(onCompleted); // Assert // Too many bytes are already pre-completed for the second write to pre-complete. Assert.False(completedWh.Wait(1000)); @@ -162,28 +162,28 @@ namespace Microsoft.AspNetCore.Server.KestrelTests }; // Act - socketOutput.WriteAsync(halfBuffer, false).ContinueWith(onCompleted); + socketOutput.WriteAsync(halfBuffer, default(CancellationToken), false).ContinueWith(onCompleted); // Assert // The first write should pre-complete since it is not immediate. Assert.True(completedWh.Wait(1000)); // Arrange completedWh.Reset(); // Act - socketOutput.WriteAsync(halfBuffer).ContinueWith(onCompleted); + socketOutput.WriteAsync(halfBuffer, default(CancellationToken)).ContinueWith(onCompleted); // Assert // The second write should pre-complete since it is <= _maxBytesPreCompleted. Assert.True(completedWh.Wait(1000)); // Arrange completedWh.Reset(); // Act - socketOutput.WriteAsync(halfBuffer, false).ContinueWith(onCompleted); + socketOutput.WriteAsync(halfBuffer, default(CancellationToken), false).ContinueWith(onCompleted); // Assert // The third write should pre-complete since it is not immediate, even though too many. Assert.True(completedWh.Wait(1000)); // Arrange completedWh.Reset(); // Act - socketOutput.WriteAsync(halfBuffer).ContinueWith(onCompleted); + socketOutput.WriteAsync(halfBuffer, default(CancellationToken)).ContinueWith(onCompleted); // Assert // Too many bytes are already pre-completed for the fourth write to pre-complete. Assert.False(completedWh.Wait(1000)); @@ -198,6 +198,116 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } } + [Fact] + public async Task OnlyWritesRequestingCancellationAreErroredOnCancellation() + { + // This should match _maxBytesPreCompleted in SocketOutput + var maxBytesPreCompleted = 65536; + var completeQueue = new Queue>(); + + // Arrange + var mockLibuv = new MockLibuv + { + OnWrite = (socket, buffers, triggerCompleted) => + { + completeQueue.Enqueue(triggerCompleted); + return 0; + } + }; + + using (var kestrelEngine = new KestrelEngine(mockLibuv, new TestServiceContext())) + using (var memory = new MemoryPool2()) + { + kestrelEngine.Start(count: 1); + + var kestrelThread = kestrelEngine.Threads[0]; + var socket = new MockSocket(kestrelThread.Loop.ThreadId, new TestKestrelTrace()); + var trace = new KestrelTrace(new TestKestrelTrace()); + var ltp = new LoggingThreadPool(trace); + ISocketOutput socketOutput = new SocketOutput(kestrelThread, socket, memory, null, 0, trace, ltp, new Queue()); + + var bufferSize = maxBytesPreCompleted; + + var data = new byte[bufferSize]; + var fullBuffer = new ArraySegment(data, 0, bufferSize); + + var cts = new CancellationTokenSource(); + + // Act + var task1Success = socketOutput.WriteAsync(fullBuffer, cancellationToken: cts.Token); + // task1 should complete sucessfully as < _maxBytesPreCompleted + + // First task is completed and sucessful + Assert.True(task1Success.IsCompleted); + Assert.False(task1Success.IsCanceled); + Assert.False(task1Success.IsFaulted); + + task1Success.GetAwaiter().GetResult(); + + // following tasks should wait. + + var task2Throw = socketOutput.WriteAsync(fullBuffer, cancellationToken: cts.Token); + var task3Success = socketOutput.WriteAsync(fullBuffer, cancellationToken: default(CancellationToken)); + + // Give time for tasks to perculate + await Task.Delay(2000).ConfigureAwait(false); + + // Second task is not completed + Assert.False(task2Throw.IsCompleted); + Assert.False(task2Throw.IsCanceled); + Assert.False(task2Throw.IsFaulted); + + // Third task is not completed + Assert.False(task3Success.IsCompleted); + Assert.False(task3Success.IsCanceled); + Assert.False(task3Success.IsFaulted); + + cts.Cancel(); + + // Give time for tasks to perculate + await Task.Delay(2000).ConfigureAwait(false); + + // Second task is now cancelled + Assert.True(task2Throw.IsCompleted); + Assert.True(task2Throw.IsCanceled); + Assert.False(task2Throw.IsFaulted); + + // Third task is now completed + Assert.True(task3Success.IsCompleted); + Assert.False(task3Success.IsCanceled); + Assert.False(task3Success.IsFaulted); + + // Fourth task immediately cancels as the token is cancelled + var task4Throw = socketOutput.WriteAsync(fullBuffer, cancellationToken: cts.Token); + + Assert.True(task4Throw.IsCompleted); + Assert.True(task4Throw.IsCanceled); + Assert.False(task4Throw.IsFaulted); + + Assert.Throws(() => task4Throw.GetAwaiter().GetResult()); + + var task5Success = socketOutput.WriteAsync(fullBuffer, cancellationToken: default(CancellationToken)); + // task5 should complete immedately + + Assert.True(task5Success.IsCompleted); + Assert.False(task5Success.IsCanceled); + Assert.False(task5Success.IsFaulted); + + cts = new CancellationTokenSource(); + + var task6Throw = socketOutput.WriteAsync(fullBuffer, cancellationToken: cts.Token); + // task6 should complete immedately but not cancel as its cancelation token isn't set + + Assert.True(task6Throw.IsCompleted); + Assert.False(task6Throw.IsCanceled); + Assert.False(task6Throw.IsFaulted); + + Assert.Throws(() => task6Throw.GetAwaiter().GetResult()); + + Assert.True(true); + } + } + [Fact] public void WritesDontGetCompletedTooQuickly() { @@ -247,7 +357,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests }; // Act (Pre-complete the maximum number of bytes in preparation for the rest of the test) - socketOutput.WriteAsync(buffer).ContinueWith(onCompleted); + socketOutput.WriteAsync(buffer, default(CancellationToken)).ContinueWith(onCompleted); // Assert // The first write should pre-complete since it is <= _maxBytesPreCompleted. Assert.True(completedWh.Wait(1000)); @@ -257,8 +367,8 @@ namespace Microsoft.AspNetCore.Server.KestrelTests onWriteWh.Reset(); // Act - socketOutput.WriteAsync(buffer).ContinueWith(onCompleted); - socketOutput.WriteAsync(buffer).ContinueWith(onCompleted2); + socketOutput.WriteAsync(buffer, default(CancellationToken)).ContinueWith(onCompleted); + socketOutput.WriteAsync(buffer, default(CancellationToken)).ContinueWith(onCompleted2); Assert.True(onWriteWh.Wait(1000)); completeQueue.Dequeue()(0); @@ -320,7 +430,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests socketOutput.ProducingComplete(end); // A call to Write is required to ensure a write is scheduled - socketOutput.WriteAsync(default(ArraySegment)); + socketOutput.WriteAsync(default(ArraySegment), default(CancellationToken)); Assert.True(nBufferWh.Wait(1000)); Assert.Equal(2, nBuffers); From a97cb81f9282edfccd3b6768d9c0242e85e97e6a Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Fri, 22 Jan 2016 13:59:46 +0000 Subject: [PATCH 0578/1662] MockConnection Abort --- .../Http/Connection.cs | 2 +- .../Http/SocketOutput.cs | 23 ++++++++++++++----- .../TestHelpers/MockConnection.cs | 18 +++++++++++++++ .../SocketOutputTests.cs | 4 ++-- 4 files changed, 38 insertions(+), 9 deletions(-) create mode 100644 test/Microsoft.AspNet.Server.KestrelTests/TestHelpers/MockConnection.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Connection.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Connection.cs index 52790ec65a..0708796ecb 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Connection.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Connection.cs @@ -109,7 +109,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } - public void Abort() + public virtual void Abort() { if (_frame != null) { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketOutput.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketOutput.cs index 38533f447b..b724da9e5a 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketOutput.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketOutput.cs @@ -45,6 +45,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http // The number of write operations that have been scheduled so far // but have not completed. private bool _writePending = false; + private bool _cancelled = false; private int _numBytesPreCompleted = 0; private Exception _lastWriteError; private WriteContext _nextWriteContext; @@ -90,7 +91,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http lock (_contextLock) { - if (_lastWriteError != null || _socket.IsClosed) + if (_socket.IsClosed) { _log.ConnectionDisconnectedWrite(_connectionId, buffer.Count, _lastWriteError); @@ -164,7 +165,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if (cancellationToken.IsCancellationRequested) { _connection.Abort(); - + _cancelled = true; return TaskUtilities.GetCancelledTask(cancellationToken); } else @@ -295,7 +296,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { // Abort the connection for any failed write // Queued on threadpool so get it in as first op. - _connection?.Abort(); + _connection.Abort(); + _cancelled = true; CompleteAllWrites(); } @@ -346,9 +348,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } // This may called on the libuv event loop - // This is always called with the _contextLock already acquired private void OnWriteCompleted(WriteContext writeContext) { + // Called inside _contextLock var bytesWritten = writeContext.ByteCount; var status = writeContext.WriteStatus; var error = writeContext.WriteError; @@ -358,6 +360,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http // Abort the connection for any failed write // Queued on threadpool so get it in as first op. _connection.Abort(); + _cancelled = true; _lastWriteError = error; } @@ -381,6 +384,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http private void CompleteNextWrite(ref int bytesLeftToBuffer) { + // Called inside _contextLock var waitingTask = _tasksPending.Dequeue(); var bytesToWrite = waitingTask.BytesToWrite; @@ -416,6 +420,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http private void CompleteFinishedWrites(int status) { + // Called inside _contextLock // bytesLeftToBuffer can be greater than _maxBytesPreCompleted // This allows large writes to complete once they've actually finished. var bytesLeftToBuffer = _maxBytesPreCompleted - _numBytesPreCompleted; @@ -428,6 +433,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http private void CompleteAllWrites() { + // Called inside _contextLock var writesToComplete = _tasksPending.Count > 0; var bytesLeftToBuffer = _maxBytesPreCompleted - _numBytesPreCompleted; while (_tasksPending.Count > 0) @@ -468,7 +474,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http private void PoolWriteContext(WriteContext writeContext) { - // called inside _contextLock + // Called inside _contextLock if (_writeContextPool.Count < _maxPooledWriteContexts) { writeContext.Reset(); @@ -485,9 +491,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (cancellationToken.IsCancellationRequested) { - _connection?.Abort(); + _connection.Abort(); + _cancelled = true; return TaskUtilities.GetCancelledTask(cancellationToken); } + else if (_cancelled) + { + return TaskUtilities.CompletedTask; + } return WriteAsync(buffer, cancellationToken, immediate, chunk); } diff --git a/test/Microsoft.AspNet.Server.KestrelTests/TestHelpers/MockConnection.cs b/test/Microsoft.AspNet.Server.KestrelTests/TestHelpers/MockConnection.cs new file mode 100644 index 0000000000..e11e354f60 --- /dev/null +++ b/test/Microsoft.AspNet.Server.KestrelTests/TestHelpers/MockConnection.cs @@ -0,0 +1,18 @@ +using Microsoft.AspNet.Server.Kestrel.Http; +using Microsoft.AspNet.Server.Kestrel.Networking; + +namespace Microsoft.AspNet.Server.KestrelTests.TestHelpers +{ + public class MockConnection : Connection + { + public MockConnection(UvStreamHandle socket) + : base (new ListenerContext(), socket) + { + + } + + public override void Abort() + { + } + } +} diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/SocketOutputTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/SocketOutputTests.cs index ec0fe0c9a0..4d24150567 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/SocketOutputTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/SocketOutputTests.cs @@ -224,7 +224,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var socket = new MockSocket(kestrelThread.Loop.ThreadId, new TestKestrelTrace()); var trace = new KestrelTrace(new TestKestrelTrace()); var ltp = new LoggingThreadPool(trace); - ISocketOutput socketOutput = new SocketOutput(kestrelThread, socket, memory, null, 0, trace, ltp, new Queue()); + ISocketOutput socketOutput = new SocketOutput(kestrelThread, socket, memory, new MockConnection(socket), 0, trace, ltp, new Queue()); var bufferSize = maxBytesPreCompleted; @@ -302,7 +302,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests Assert.False(task6Throw.IsCanceled); Assert.False(task6Throw.IsFaulted); - Assert.Throws(() => task6Throw.GetAwaiter().GetResult()); + task6Throw.GetAwaiter().GetResult(); Assert.True(true); } From cd621509d0b0adb09f11b27452e5e12c42298eaf Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Fri, 22 Jan 2016 18:35:58 +0000 Subject: [PATCH 0579/1662] Complete all writes after error --- .../Http/SocketOutput.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketOutput.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketOutput.cs index b724da9e5a..ebfd3cb55c 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketOutput.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketOutput.cs @@ -370,15 +370,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http // completed writes that we haven't triggered callbacks for yet. _numBytesPreCompleted -= bytesWritten; - CompleteFinishedWrites(status); - - if (error != null) + if (error == null) { - _log.ConnectionError(_connectionId, error); + CompleteFinishedWrites(status); + _log.ConnectionWriteCallback(_connectionId, status); } else { - _log.ConnectionWriteCallback(_connectionId, status); + CompleteAllWrites(); + _log.ConnectionError(_connectionId, error); } } From e5238ff38310782c4f7338fb6bb380f670a45e39 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Fri, 22 Jan 2016 23:34:28 +0000 Subject: [PATCH 0580/1662] Only log connection error once --- .../Http/SocketOutput.cs | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketOutput.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketOutput.cs index ebfd3cb55c..eed0230e3e 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketOutput.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketOutput.cs @@ -294,12 +294,17 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { lock (_contextLock) { - // Abort the connection for any failed write - // Queued on threadpool so get it in as first op. - _connection.Abort(); - _cancelled = true; + if (!_cancelled) + { + // Abort the connection for any failed write + // Queued on threadpool so get it in as first op. + _connection.Abort(); + _cancelled = true; - CompleteAllWrites(); + CompleteAllWrites(); + + _log.ConnectionError(_connectionId, new TaskCanceledException("Write operation canceled. Aborting connection.")); + } } } @@ -434,17 +439,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http private void CompleteAllWrites() { // Called inside _contextLock - var writesToComplete = _tasksPending.Count > 0; var bytesLeftToBuffer = _maxBytesPreCompleted - _numBytesPreCompleted; while (_tasksPending.Count > 0) { CompleteNextWrite(ref bytesLeftToBuffer); } - - if (writesToComplete) - { - _log.ConnectionError(_connectionId, new TaskCanceledException("Connetcion")); - } } // This is called on the libuv event loop From 735c0fbbef4321d1113d0adcfc713dfe78350357 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Fri, 22 Jan 2016 17:00:13 -0800 Subject: [PATCH 0581/1662] Added new test to verify failed writes complete all pending write tasks - Changed MockLibuv to never fall back to real libuv methods. - Fixed EngineTests.ConnectionCanReadAndWrite --- .../Networking/Libuv.cs | 5 + .../TestHelpers/MockConnection.cs | 7 ++ .../EngineTests.cs | 11 +- .../SocketOutputTests.cs | 103 ++++++++++++++++-- .../TestHelpers/MockLibuv.cs | 3 + 5 files changed, 111 insertions(+), 18 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Networking/Libuv.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Networking/Libuv.cs index 037f77eaa2..792e928878 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Networking/Libuv.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Networking/Libuv.cs @@ -98,6 +98,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Networking } } + // Second ctor that doesn't set any fields only to be used by MockLibuv + internal Libuv(bool onlyForTesting) + { + } + public readonly bool IsWindows; public int Check(int statusCode) diff --git a/test/Microsoft.AspNet.Server.KestrelTests/TestHelpers/MockConnection.cs b/test/Microsoft.AspNet.Server.KestrelTests/TestHelpers/MockConnection.cs index e11e354f60..20a937213d 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/TestHelpers/MockConnection.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/TestHelpers/MockConnection.cs @@ -1,3 +1,4 @@ +using System.Threading; using Microsoft.AspNet.Server.Kestrel.Http; using Microsoft.AspNet.Server.Kestrel.Networking; @@ -13,6 +14,12 @@ namespace Microsoft.AspNet.Server.KestrelTests.TestHelpers public override void Abort() { + if (RequestAbortedSource != null) + { + RequestAbortedSource.Cancel(); + } } + + public CancellationTokenSource RequestAbortedSource { get; set; } } } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs index 85858ddcf5..811cf121a4 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs @@ -1118,27 +1118,22 @@ namespace Microsoft.AspNetCore.Server.KestrelTests connectionCloseWh.Wait(); response.Headers.Clear(); - response.Headers["Content-Length"] = new[] { "5" }; try { // Ensure write is long enough to disable write-behind buffering - for (int i = 0; i < 10; i++) + for (int i = 0; i < 100; i++) { - await response.WriteAsync(largeString).ConfigureAwait(false); + await response.WriteAsync(largeString, lifetime.RequestAborted).ConfigureAwait(false); } } catch (Exception ex) { writeTcs.SetException(ex); - - // Give a chance for RequestAborted to trip before the app completes - registrationWh.Wait(resetEventTimeout); - throw; } - writeTcs.SetCanceled(); + writeTcs.SetException(new Exception("This shouldn't be reached.")); }, testContext)) { using (var connection = new TestConnection()) diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/SocketOutputTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/SocketOutputTests.cs index 4d24150567..974829e93b 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/SocketOutputTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/SocketOutputTests.cs @@ -235,9 +235,9 @@ namespace Microsoft.AspNetCore.Server.KestrelTests // Act var task1Success = socketOutput.WriteAsync(fullBuffer, cancellationToken: cts.Token); - // task1 should complete sucessfully as < _maxBytesPreCompleted + // task1 should complete successfully as < _maxBytesPreCompleted - // First task is completed and sucessful + // First task is completed and successful Assert.True(task1Success.IsCompleted); Assert.False(task1Success.IsCanceled); Assert.False(task1Success.IsFaulted); @@ -249,8 +249,8 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var task2Throw = socketOutput.WriteAsync(fullBuffer, cancellationToken: cts.Token); var task3Success = socketOutput.WriteAsync(fullBuffer, cancellationToken: default(CancellationToken)); - // Give time for tasks to perculate - await Task.Delay(2000).ConfigureAwait(false); + // Give time for tasks to percolate + await Task.Delay(1000).ConfigureAwait(false); // Second task is not completed Assert.False(task2Throw.IsCompleted); @@ -264,10 +264,10 @@ namespace Microsoft.AspNetCore.Server.KestrelTests cts.Cancel(); - // Give time for tasks to perculate - await Task.Delay(2000).ConfigureAwait(false); + // Give time for tasks to percolate + await Task.Delay(1000).ConfigureAwait(false); - // Second task is now cancelled + // Second task is now canceled Assert.True(task2Throw.IsCompleted); Assert.True(task2Throw.IsCanceled); Assert.False(task2Throw.IsFaulted); @@ -277,7 +277,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests Assert.False(task3Success.IsCanceled); Assert.False(task3Success.IsFaulted); - // Fourth task immediately cancels as the token is cancelled + // Fourth task immediately cancels as the token is canceled var task4Throw = socketOutput.WriteAsync(fullBuffer, cancellationToken: cts.Token); Assert.True(task4Throw.IsCompleted); @@ -287,7 +287,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests Assert.Throws(() => task4Throw.GetAwaiter().GetResult()); var task5Success = socketOutput.WriteAsync(fullBuffer, cancellationToken: default(CancellationToken)); - // task5 should complete immedately + // task5 should complete immediately Assert.True(task5Success.IsCompleted); Assert.False(task5Success.IsCanceled); @@ -296,7 +296,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests cts = new CancellationTokenSource(); var task6Throw = socketOutput.WriteAsync(fullBuffer, cancellationToken: cts.Token); - // task6 should complete immedately but not cancel as its cancelation token isn't set + // task6 should complete immediately but not cancel as its cancellation token isn't set Assert.True(task6Throw.IsCompleted); Assert.False(task6Throw.IsCanceled); @@ -308,6 +308,89 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } } + [Fact] + public async Task FailedWriteCompletesOrCancelsAllPendingTasks() + { + // This should match _maxBytesPreCompleted in SocketOutput + var maxBytesPreCompleted = 65536; + var completeQueue = new Queue>(); + + // Arrange + var mockLibuv = new MockLibuv + { + OnWrite = (socket, buffers, triggerCompleted) => + { + completeQueue.Enqueue(triggerCompleted); + return 0; + } + }; + + using (var kestrelEngine = new KestrelEngine(mockLibuv, new TestServiceContext())) + using (var memory = new MemoryPool2()) + using (var abortedSource = new CancellationTokenSource()) + { + kestrelEngine.Start(count: 1); + + var kestrelThread = kestrelEngine.Threads[0]; + var socket = new MockSocket(kestrelThread.Loop.ThreadId, new TestKestrelTrace()); + var trace = new KestrelTrace(new TestKestrelTrace()); + var ltp = new LoggingThreadPool(trace); + + var mockConnection = new MockConnection(socket); + mockConnection.RequestAbortedSource = abortedSource; + ISocketOutput socketOutput = new SocketOutput(kestrelThread, socket, memory, mockConnection, 0, trace, ltp, new Queue()); + + var bufferSize = maxBytesPreCompleted; + + var data = new byte[bufferSize]; + var fullBuffer = new ArraySegment(data, 0, bufferSize); + + // Act + var task1Success = socketOutput.WriteAsync(fullBuffer, cancellationToken: abortedSource.Token); + // task1 should complete successfully as < _maxBytesPreCompleted + + // First task is completed and successful + Assert.True(task1Success.IsCompleted); + Assert.False(task1Success.IsCanceled); + Assert.False(task1Success.IsFaulted); + + task1Success.GetAwaiter().GetResult(); + + // following tasks should wait. + var task2Success = socketOutput.WriteAsync(fullBuffer, cancellationToken: CancellationToken.None); + var task3Canceled = socketOutput.WriteAsync(fullBuffer, cancellationToken: abortedSource.Token); + + // Give time for tasks to percolate + await Task.Delay(1000).ConfigureAwait(false); + + // Second task is not completed + Assert.False(task2Success.IsCompleted); + Assert.False(task2Success.IsCanceled); + Assert.False(task2Success.IsFaulted); + + // Third task is not completed + Assert.False(task3Canceled.IsCompleted); + Assert.False(task3Canceled.IsCanceled); + Assert.False(task3Canceled.IsFaulted); + + // Cause the first write to fail. + completeQueue.Dequeue()(-1); + + // Give time for tasks to percolate + await Task.Delay(1000).ConfigureAwait(false); + + // Second task is now completed + Assert.True(task2Success.IsCompleted); + Assert.False(task2Success.IsCanceled); + Assert.False(task2Success.IsFaulted); + + // Third task is now canceled + Assert.True(task3Canceled.IsCompleted); + Assert.True(task3Canceled.IsCanceled); + Assert.False(task3Canceled.IsFaulted); + } + } + [Fact] public void WritesDontGetCompletedTooQuickly() { diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockLibuv.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockLibuv.cs index 4cc9549d78..2f2f2f1103 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockLibuv.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockLibuv.cs @@ -15,6 +15,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests.TestHelpers private Func, int> _onWrite; unsafe public MockLibuv() + : base(onlyForTesting: true) { _uv_write = UvWrite; @@ -66,6 +67,8 @@ namespace Microsoft.AspNetCore.Server.KestrelTests.TestHelpers _uv_close = (handle, callback) => callback(handle); _uv_loop_close = handle => 0; _uv_walk = (loop, callback, ignore) => 0; + _uv_err_name = errno => IntPtr.Zero; + _uv_strerror = errno => IntPtr.Zero; } public Func, int> OnWrite From 0ca8ca03286948c3cb9d1ffafed8f0dd8fb387df Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Sat, 23 Jan 2016 10:11:46 +0000 Subject: [PATCH 0582/1662] Update FrameResponseStream Cancellation --- .../Http/FrameResponseStream.cs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameResponseStream.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameResponseStream.cs index d5b4f41aea..606c112d36 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameResponseStream.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameResponseStream.cs @@ -138,13 +138,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http case FrameStreamState.Closed: throw new ObjectDisposedException(nameof(FrameResponseStream)); case FrameStreamState.Aborted: - if (cancellationToken.CanBeCanceled) + if (cancellationToken.IsCancellationRequested) { // Aborted state only throws on write if cancellationToken requests it - return TaskUtilities.GetCancelledTask( - cancellationToken.IsCancellationRequested ? - cancellationToken : - new CancellationToken(true)); + return TaskUtilities.GetCancelledTask(cancellationToken); } break; } From de34d14abb66f4ee65441e4e97fc8f2506f416e2 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Sat, 23 Jan 2016 10:12:10 +0000 Subject: [PATCH 0583/1662] WriteChunked immediate for large responses --- src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs index 5cd4f8c378..61f09dbbb1 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs @@ -468,12 +468,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http private void WriteChunked(ArraySegment data) { - SocketOutput.Write(data, immediate: false, chunk: true); + SocketOutput.Write(data, immediate: true, chunk: true); } private Task WriteChunkedAsync(ArraySegment data, CancellationToken cancellationToken) { - return SocketOutput.WriteAsync(data, immediate: false, chunk: true, cancellationToken: cancellationToken); + return SocketOutput.WriteAsync(data, immediate: true, chunk: true, cancellationToken: cancellationToken); } private Task WriteChunkedResponseSuffix() From 63e0ed8773c950c0d95ef4fa108ce8436ad8f5c1 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Sat, 23 Jan 2016 19:30:22 -0800 Subject: [PATCH 0584/1662] Use the new NuGet package location in LibuvCopier --- .../Program.cs | 26 ++----------------- 1 file changed, 2 insertions(+), 24 deletions(-) diff --git a/tools/Microsoft.AspNetCore.Server.Kestrel.LibuvCopier/Program.cs b/tools/Microsoft.AspNetCore.Server.Kestrel.LibuvCopier/Program.cs index 6fb635145a..8ed1e4df1a 100644 --- a/tools/Microsoft.AspNetCore.Server.Kestrel.LibuvCopier/Program.cs +++ b/tools/Microsoft.AspNetCore.Server.Kestrel.LibuvCopier/Program.cs @@ -11,30 +11,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.LibuvCopier { try { - var packagesFolder = Environment.GetEnvironmentVariable("DNX_PACKAGES"); - - if (string.IsNullOrEmpty(packagesFolder)) - { - var dnxFolder = Environment.GetEnvironmentVariable("DNX_HOME") ?? - Environment.GetEnvironmentVariable("DNX_USER_HOME") ?? - Environment.GetEnvironmentVariable("DNX_GLOBAL_HOME"); - - var firstCandidate = dnxFolder?.Split(';') - ?.Select(path => Environment.ExpandEnvironmentVariables(path)) - ?.Where(path => Directory.Exists(path)) - ?.FirstOrDefault(); - - if (string.IsNullOrEmpty(firstCandidate)) - { - dnxFolder = Path.Combine(GetHome(), ".dnx"); - } - else - { - dnxFolder = firstCandidate; - } - - packagesFolder = Path.Combine(dnxFolder, "packages"); - } + var packagesFolder = Environment.GetEnvironmentVariable("DNX_PACKAGES") ?? + Path.Combine(GetHome(), ".nuget", "packages"); packagesFolder = Environment.ExpandEnvironmentVariables(packagesFolder); From 3f414782b908c51bfbb99873b664f1e92a98ad33 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Sun, 24 Jan 2016 14:49:25 +0000 Subject: [PATCH 0585/1662] Remove spinning for blocked socket ops As per https://github.com/dotnet/corefx/pull/5655 --- src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketInput.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketInput.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketInput.cs index 94e335b345..3860c9b67c 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketInput.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketInput.cs @@ -16,7 +16,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http private readonly MemoryPool2 _memory; private readonly IThreadPool _threadPool; - private readonly ManualResetEventSlim _manualResetEvent = new ManualResetEventSlim(false); + private readonly ManualResetEventSlim _manualResetEvent = new ManualResetEventSlim(false, 0); private Action _awaitableState; private Exception _awaitableError; From 7570da9daa1fe1f020057b3e9d38d46a3236df5c Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Sat, 23 Jan 2016 20:29:30 -0800 Subject: [PATCH 0586/1662] Flush chunked writes before the entire response completes Ensure chunked writes force an "immediate" write by removing the now unused immediate parameter from ISocketOutput.Write --- .../Filter/StreamSocketOutput.cs | 6 +- .../Http/Frame.cs | 26 ++++---- .../Http/ISocketOutput.cs | 4 +- .../Http/SocketOutput.cs | 21 ++---- .../ChunkedResponseTests.cs | 45 +++++++++++++ .../EngineTests.cs | 1 - .../SocketOutputTests.cs | 65 ++++++++----------- 7 files changed, 96 insertions(+), 72 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Filter/StreamSocketOutput.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Filter/StreamSocketOutput.cs index ccc752ae9b..4b6b335c77 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Filter/StreamSocketOutput.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Filter/StreamSocketOutput.cs @@ -28,7 +28,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Filter _memory = memory; } - public void Write(ArraySegment buffer, bool immediate, bool chunk) + public void Write(ArraySegment buffer, bool chunk) { lock (_writeLock) { @@ -47,10 +47,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Filter } } - public Task WriteAsync(ArraySegment buffer, bool immediate, bool chunk, CancellationToken cancellationToken) + public Task WriteAsync(ArraySegment buffer, bool chunk, CancellationToken cancellationToken) { // TODO: Use _outputStream.WriteAsync - Write(buffer, immediate, chunk); + Write(buffer, chunk); return TaskUtilities.CompletedTask; } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs index d5225447d1..4c1d096e6f 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs @@ -393,13 +393,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http public void Flush() { ProduceStartAndFireOnStarting(immediate: false).GetAwaiter().GetResult(); - SocketOutput.Write(_emptyData, immediate: true); + SocketOutput.Write(_emptyData); } public async Task FlushAsync(CancellationToken cancellationToken) { await ProduceStartAndFireOnStarting(immediate: false); - await SocketOutput.WriteAsync(_emptyData, immediate: true, cancellationToken: cancellationToken); + await SocketOutput.WriteAsync(_emptyData, cancellationToken: cancellationToken); } public void Write(ArraySegment data) @@ -416,7 +416,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } else { - SocketOutput.Write(data, immediate: true); + SocketOutput.Write(data); } } @@ -437,7 +437,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } else { - return SocketOutput.WriteAsync(data, immediate: true, cancellationToken: cancellationToken); + return SocketOutput.WriteAsync(data, cancellationToken: cancellationToken); } } @@ -455,23 +455,23 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } else { - await SocketOutput.WriteAsync(data, immediate: true, cancellationToken: cancellationToken); + await SocketOutput.WriteAsync(data, cancellationToken: cancellationToken); } } private void WriteChunked(ArraySegment data) { - SocketOutput.Write(data, immediate: false, chunk: true); + SocketOutput.Write(data, chunk: true); } private Task WriteChunkedAsync(ArraySegment data, CancellationToken cancellationToken) { - return SocketOutput.WriteAsync(data, immediate: false, chunk: true, cancellationToken: cancellationToken); + return SocketOutput.WriteAsync(data, chunk: true, cancellationToken: cancellationToken); } private Task WriteChunkedResponseSuffix() { - return SocketOutput.WriteAsync(_endChunkedResponseBytes, immediate: true); + return SocketOutput.WriteAsync(_endChunkedResponseBytes); } private static ArraySegment CreateAsciiByteArraySegment(string text) @@ -493,13 +493,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } - public Task ProduceStartAndFireOnStarting(bool immediate = true) + public Task ProduceStartAndFireOnStarting(bool immediate) { if (_responseStarted) return TaskUtilities.CompletedTask; if (_onStarting != null) { - return FireOnStartingProduceStart(immediate: immediate); + return FireOnStartingProduceStart(immediate); } if (_applicationException != null) @@ -604,8 +604,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http bool appCompleted, bool immediate) { - var begin = SocketOutput.ProducingStart(); - var end = begin; + var end = SocketOutput.ProducingStart(); if (_keepAlive) { foreach (var connectionValue in _responseHeaders.HeaderConnection) @@ -662,7 +661,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if (immediate) { - return SocketOutput.WriteAsync(default(ArraySegment), immediate: true); + // Force a call to uv_write + return SocketOutput.WriteAsync(default(ArraySegment)); } else { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/ISocketOutput.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/ISocketOutput.cs index 20e20481d3..c526caedf9 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/ISocketOutput.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/ISocketOutput.cs @@ -13,8 +13,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http /// public interface ISocketOutput { - void Write(ArraySegment buffer, bool immediate = true, bool chunk = false); - Task WriteAsync(ArraySegment buffer, bool immediate = true, bool chunk = false, CancellationToken cancellationToken = default(CancellationToken)); + void Write(ArraySegment buffer, bool chunk = false); + Task WriteAsync(ArraySegment buffer, bool chunk = false, CancellationToken cancellationToken = default(CancellationToken)); /// /// Returns an iterator pointing to the tail of the response buffer. Response data can be appended diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketOutput.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketOutput.cs index 15a56f9fc8..7787c93a8f 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketOutput.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketOutput.cs @@ -78,7 +78,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http public Task WriteAsync( ArraySegment buffer, - bool immediate = true, bool chunk = false, bool socketShutdownSend = false, bool socketDisconnect = false, @@ -130,13 +129,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http _nextWriteContext.SocketDisconnect = true; } - if (!immediate) - { - // immediate==false calls always return complete tasks, because there is guaranteed - // to be a subsequent immediate==true call which will go down one of the previous code-paths - _numBytesPreCompleted += buffer.Count; - } - else if (_lastWriteError == null && + if (_lastWriteError == null && _tasksPending.Count == 0 && _numBytesPreCompleted + buffer.Count <= _maxBytesPreCompleted) { @@ -155,7 +148,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http }); } - if (!_writePending && immediate) + if (!_writePending) { _writePending = true; scheduleWrite = true; @@ -177,13 +170,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { case ProduceEndType.SocketShutdownSend: WriteAsync(default(ArraySegment), - immediate: true, socketShutdownSend: true, socketDisconnect: false); break; case ProduceEndType.SocketDisconnect: WriteAsync(default(ArraySegment), - immediate: true, socketShutdownSend: false, socketDisconnect: true); break; @@ -391,14 +382,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } - void ISocketOutput.Write(ArraySegment buffer, bool immediate, bool chunk) + void ISocketOutput.Write(ArraySegment buffer, bool chunk) { - WriteAsync(buffer, immediate, chunk, isSync: true).GetAwaiter().GetResult(); + WriteAsync(buffer, chunk, isSync: true).GetAwaiter().GetResult(); } - Task ISocketOutput.WriteAsync(ArraySegment buffer, bool immediate, bool chunk, CancellationToken cancellationToken) + Task ISocketOutput.WriteAsync(ArraySegment buffer, bool chunk, CancellationToken cancellationToken) { - return WriteAsync(buffer, immediate, chunk); + return WriteAsync(buffer, chunk); } private static void BytesBetween(MemoryPoolIterator2 start, MemoryPoolIterator2 end, out int bytes, out int buffers) diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedResponseTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedResponseTests.cs index 42a08006f2..0b325f8710 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedResponseTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedResponseTests.cs @@ -3,6 +3,7 @@ using System; using System.Text; +using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Testing.xunit; using Xunit; @@ -166,6 +167,50 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } } } + + [ConditionalFact] + [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Test hangs after execution on Mono.")] + public async Task WritesAreFlushedPriorToResponseCompletion() + { + var flushWh = new ManualResetEventSlim(); + + using (var server = new TestServer(async httpContext => + { + var response = httpContext.Response; + response.Headers.Clear(); + await response.Body.WriteAsync(Encoding.ASCII.GetBytes("Hello "), 0, 6); + + // Don't complete response until client has received the first chunk. + flushWh.Wait(); + + await response.Body.WriteAsync(Encoding.ASCII.GetBytes("World!"), 0, 6); + })) + { + using (var connection = new TestConnection()) + { + await connection.SendEnd( + "GET / HTTP/1.1", + "", + ""); + await connection.Receive( + "HTTP/1.1 200 OK", + "Transfer-Encoding: chunked", + "", + "6", + "Hello ", + ""); + + flushWh.Set(); + + await connection.ReceiveEnd( + "6", + "World!", + "0", + "", + ""); + } + } + } } } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs index a44f096129..6f36a7a2cf 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs @@ -1112,7 +1112,6 @@ namespace Microsoft.AspNetCore.Server.KestrelTests connectionCloseWh.Wait(); response.Headers.Clear(); - response.Headers["Content-Length"] = new[] { "5" }; try { diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/SocketOutputTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/SocketOutputTests.cs index 01c42c5f18..9fedc0dad4 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/SocketOutputTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/SocketOutputTests.cs @@ -121,11 +121,12 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } [Fact] - public void WritesDontCompleteImmediatelyWhenTooManyBytesIncludingNonImmediateAreAlreadyPreCompleted() + public async Task WritesDontCompleteImmediatelyWhenTooManyBytesIncludingNonImmediateAreAlreadyPreCompleted() { // This should match _maxBytesPreCompleted in SocketOutput var maxBytesPreCompleted = 65536; var completeQueue = new Queue>(); + var writeRequestedWh = new ManualResetEventSlim(); // Arrange var mockLibuv = new MockLibuv @@ -133,6 +134,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests OnWrite = (socket, buffers, triggerCompleted) => { completeQueue.Enqueue(triggerCompleted); + writeRequestedWh.Set(); return 0; } }; @@ -148,53 +150,40 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var ltp = new LoggingThreadPool(trace); var socketOutput = new SocketOutput(kestrelThread, socket, memory, null, 0, trace, ltp, new Queue()); - var bufferSize = maxBytesPreCompleted; - + var bufferSize = maxBytesPreCompleted / 2; var data = new byte[bufferSize]; - var fullBuffer = new ArraySegment(data, 0, bufferSize); - var halfBuffer = new ArraySegment(data, 0, bufferSize / 2); - - var completedWh = new ManualResetEventSlim(); - Action onCompleted = (Task t) => - { - Assert.Null(t.Exception); - completedWh.Set(); - }; + var halfWriteBehindBuffer = new ArraySegment(data, 0, bufferSize); // Act - socketOutput.WriteAsync(halfBuffer, false).ContinueWith(onCompleted); + var writeTask1 = socketOutput.WriteAsync(halfWriteBehindBuffer); // Assert - // The first write should pre-complete since it is not immediate. - Assert.True(completedWh.Wait(1000)); - // Arrange - completedWh.Reset(); - // Act - socketOutput.WriteAsync(halfBuffer).ContinueWith(onCompleted); - // Assert - // The second write should pre-complete since it is <= _maxBytesPreCompleted. - Assert.True(completedWh.Wait(1000)); - // Arrange - completedWh.Reset(); - // Act - socketOutput.WriteAsync(halfBuffer, false).ContinueWith(onCompleted); - // Assert - // The third write should pre-complete since it is not immediate, even though too many. - Assert.True(completedWh.Wait(1000)); - // Arrange - completedWh.Reset(); + // The first write should pre-complete since it is <= _maxBytesPreCompleted. + Assert.Equal(TaskStatus.RanToCompletion, writeTask1.Status); + Assert.True(writeRequestedWh.Wait(1000)); + writeRequestedWh.Reset(); + + // Add more bytes to the write-behind buffer to prevent the next write from + var iter = socketOutput.ProducingStart(); + iter.CopyFrom(halfWriteBehindBuffer); + socketOutput.ProducingComplete(iter); + // Act - socketOutput.WriteAsync(halfBuffer).ContinueWith(onCompleted); + var writeTask2 = socketOutput.WriteAsync(halfWriteBehindBuffer); + // Assert // Too many bytes are already pre-completed for the fourth write to pre-complete. - Assert.False(completedWh.Wait(1000)); + Assert.True(writeRequestedWh.Wait(1000)); + Assert.False(writeTask2.IsCompleted); + + // 2 calls have been made to uv_write + Assert.Equal(2, completeQueue.Count); + // Act - while (completeQueue.Count > 0) - { - completeQueue.Dequeue()(0); - } + completeQueue.Dequeue()(0); + // Assert // Finishing the first write should allow the second write to pre-complete. - Assert.True(completedWh.Wait(1000)); + Assert.True(writeTask2.Wait(1000)); } } From a4b8b01c997bf9da8854743ae8d9b994fbc7f2c4 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Mon, 25 Jan 2016 11:02:24 -0800 Subject: [PATCH 0587/1662] Remove immediate parameter from Frame.ProduceStart - Simply call SocketOutput.WriteAsync(_emptyData) to force headers to be flushed --- .../Http/Frame.FeatureCollection.cs | 5 +- .../Http/Frame.cs | 47 ++++++++----------- 2 files changed, 24 insertions(+), 28 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.FeatureCollection.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.FeatureCollection.cs index 8a10a7c618..f93f88915d 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.FeatureCollection.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.FeatureCollection.cs @@ -312,7 +312,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } - await ProduceStartAndFireOnStarting(immediate: true); + await ProduceStartAndFireOnStarting(); + + // Force flush + await SocketOutput.WriteAsync(_emptyData); return DuplexStream; } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs index 4c1d096e6f..7272329639 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs @@ -392,19 +392,19 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http public void Flush() { - ProduceStartAndFireOnStarting(immediate: false).GetAwaiter().GetResult(); + ProduceStartAndFireOnStarting().GetAwaiter().GetResult(); SocketOutput.Write(_emptyData); } public async Task FlushAsync(CancellationToken cancellationToken) { - await ProduceStartAndFireOnStarting(immediate: false); + await ProduceStartAndFireOnStarting(); await SocketOutput.WriteAsync(_emptyData, cancellationToken: cancellationToken); } public void Write(ArraySegment data) { - ProduceStartAndFireOnStarting(immediate: false).GetAwaiter().GetResult(); + ProduceStartAndFireOnStarting().GetAwaiter().GetResult(); if (_autoChunk) { @@ -443,7 +443,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http public async Task WriteAsyncAwaited(ArraySegment data, CancellationToken cancellationToken) { - await ProduceStartAndFireOnStarting(immediate: false); + await ProduceStartAndFireOnStarting(); if (_autoChunk) { @@ -493,13 +493,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } - public Task ProduceStartAndFireOnStarting(bool immediate) + public Task ProduceStartAndFireOnStarting() { if (_responseStarted) return TaskUtilities.CompletedTask; if (_onStarting != null) { - return FireOnStartingProduceStart(immediate); + return ProduceStartAndFireOnStartingAwaited(); } if (_applicationException != null) @@ -509,10 +509,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http _applicationException); } - return ProduceStart(immediate, appCompleted: false); + ProduceStart(appCompleted: false); + + return TaskUtilities.CompletedTask; } - private async Task FireOnStartingProduceStart(bool immediate) + private async Task ProduceStartAndFireOnStartingAwaited() { await FireOnStarting(); @@ -523,17 +525,17 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http _applicationException); } - await ProduceStart(immediate, appCompleted: false); + ProduceStart(appCompleted: false); } - private Task ProduceStart(bool immediate, bool appCompleted) + private void ProduceStart(bool appCompleted) { - if (_responseStarted) return TaskUtilities.CompletedTask; + if (_responseStarted) return; _responseStarted = true; var statusBytes = ReasonPhrases.ToStatusBytes(StatusCode, ReasonPhrase); - return CreateResponseHeader(statusBytes, appCompleted, immediate); + CreateResponseHeader(statusBytes, appCompleted); } protected Task ProduceEnd() @@ -556,7 +558,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } - if (!_responseStarted) { return ProduceEndAwaited(); @@ -567,7 +568,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http private async Task ProduceEndAwaited() { - await ProduceStart(immediate: true, appCompleted: true); + ProduceStart(appCompleted: true); + + // Force flush + await SocketOutput.WriteAsync(_emptyData); await WriteSuffix(); } @@ -599,10 +603,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } - private Task CreateResponseHeader( + private void CreateResponseHeader( byte[] statusBytes, - bool appCompleted, - bool immediate) + bool appCompleted) { var end = SocketOutput.ProducingStart(); if (_keepAlive) @@ -658,16 +661,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http end.CopyFrom(_bytesEndHeaders, 0, _bytesEndHeaders.Length); SocketOutput.ProducingComplete(end); - - if (immediate) - { - // Force a call to uv_write - return SocketOutput.WriteAsync(default(ArraySegment)); - } - else - { - return TaskUtilities.CompletedTask; - } } protected bool TakeStartLine(SocketInput input) From 00b8a13b5526bad646e35da64c00c176a942f057 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Tue, 26 Jan 2016 02:24:44 +0000 Subject: [PATCH 0588/1662] Merge+rename+rename resolve --- .../Http/Frame.FeatureCollection.cs | 5 +---- .../Http/FrameRequestStream.cs | 2 +- .../Http/FrameResponseStream.cs | 2 +- .../SocketOutputTests.cs | 4 ++-- .../TestHelpers/MockConnection.cs | 7 ++++--- 5 files changed, 9 insertions(+), 11 deletions(-) rename test/{Microsoft.AspNet.Server.KestrelTests => Microsoft.AspNetCore.Server.KestrelTests}/TestHelpers/MockConnection.cs (72%) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.FeatureCollection.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.FeatureCollection.cs index f93f88915d..f56eb2b096 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.FeatureCollection.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.FeatureCollection.cs @@ -312,10 +312,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } - await ProduceStartAndFireOnStarting(); - - // Force flush - await SocketOutput.WriteAsync(_emptyData); + await FlushAsync(CancellationToken.None); return DuplexStream; } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameRequestStream.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameRequestStream.cs index efd3669104..705045ef05 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameRequestStream.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameRequestStream.cs @@ -5,7 +5,7 @@ using System; using System.IO; using System.Threading; using System.Threading.Tasks; -using Microsoft.AspNet.Server.Kestrel.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; namespace Microsoft.AspNetCore.Server.Kestrel.Http { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameResponseStream.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameResponseStream.cs index 606c112d36..f229e39305 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameResponseStream.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameResponseStream.cs @@ -5,7 +5,7 @@ using System; using System.IO; using System.Threading; using System.Threading.Tasks; -using Microsoft.AspNet.Server.Kestrel.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; namespace Microsoft.AspNetCore.Server.Kestrel.Http { diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/SocketOutputTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/SocketOutputTests.cs index 127a79477d..824ab4378b 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/SocketOutputTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/SocketOutputTests.cs @@ -155,7 +155,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var halfWriteBehindBuffer = new ArraySegment(data, 0, bufferSize); // Act - var writeTask1 = socketOutput.WriteAsync(halfWriteBehindBuffer); + var writeTask1 = socketOutput.WriteAsync(halfWriteBehindBuffer, CancellationToken.None); // Assert // The first write should pre-complete since it is <= _maxBytesPreCompleted. Assert.Equal(TaskStatus.RanToCompletion, writeTask1.Status); @@ -168,7 +168,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests socketOutput.ProducingComplete(iter); // Act - var writeTask2 = socketOutput.WriteAsync(halfWriteBehindBuffer); + var writeTask2 = socketOutput.WriteAsync(halfWriteBehindBuffer, CancellationToken.None); // Assert // Too many bytes are already pre-completed for the fourth write to pre-complete. Assert.True(writeRequestedWh.Wait(1000)); diff --git a/test/Microsoft.AspNet.Server.KestrelTests/TestHelpers/MockConnection.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockConnection.cs similarity index 72% rename from test/Microsoft.AspNet.Server.KestrelTests/TestHelpers/MockConnection.cs rename to test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockConnection.cs index 20a937213d..74181488c2 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/TestHelpers/MockConnection.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockConnection.cs @@ -1,8 +1,9 @@ +using System; using System.Threading; -using Microsoft.AspNet.Server.Kestrel.Http; -using Microsoft.AspNet.Server.Kestrel.Networking; +using Microsoft.AspNetCore.Server.Kestrel.Networking; +using Microsoft.AspNetCore.Server.Kestrel.Http; -namespace Microsoft.AspNet.Server.KestrelTests.TestHelpers +namespace Microsoft.AspNetCore.Server.KestrelTests.TestHelpers { public class MockConnection : Connection { From a2fe59fb2c2d1c12f19dbc94f4a1ddbcd07c497c Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Wed, 27 Jan 2016 13:01:44 -0800 Subject: [PATCH 0589/1662] Speed up unit tests - Remove unnecessary uses of Task.Delay - Change all usages to CancellationToken.None to default(CancellationToken) for consistency --- .../Http/Frame.FeatureCollection.cs | 2 +- .../Http/Frame.cs | 2 +- .../Http/FrameRequestStream.cs | 4 +- .../Http/FrameResponseStream.cs | 4 +- .../Http/SocketOutput.cs | 2 +- .../EngineTests.cs | 18 +++--- .../SocketOutputTests.cs | 55 ++++++------------- .../TestConnection.cs | 3 +- 8 files changed, 34 insertions(+), 56 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.FeatureCollection.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.FeatureCollection.cs index f56eb2b096..a1d03fd2b1 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.FeatureCollection.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.FeatureCollection.cs @@ -312,7 +312,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } - await FlushAsync(CancellationToken.None); + await FlushAsync(default(CancellationToken)); return DuplexStream; } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs index 5f753a9558..c6b5fe05f0 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs @@ -262,7 +262,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http Task.Factory.StartNew( (o) => ((Frame)o).RequestProcessingAsync(), this, - CancellationToken.None, + default(CancellationToken), TaskCreationOptions.DenyChildAttach, TaskScheduler.Default); } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameRequestStream.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameRequestStream.cs index 705045ef05..f16cf244cb 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameRequestStream.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameRequestStream.cs @@ -59,9 +59,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http #if NET451 public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback callback, object state) { - ValidateState(CancellationToken.None); + ValidateState(default(CancellationToken)); - var task = ReadAsync(buffer, offset, count, CancellationToken.None, state); + var task = ReadAsync(buffer, offset, count, default(CancellationToken), state); if (callback != null) { task.ContinueWith(t => callback.Invoke(t)); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameResponseStream.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameResponseStream.cs index f229e39305..3cf9600ecc 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameResponseStream.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameResponseStream.cs @@ -38,7 +38,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http public override void Flush() { - ValidateState(CancellationToken.None); + ValidateState(default(CancellationToken)); _context.FrameControl.Flush(); } @@ -70,7 +70,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http public override void Write(byte[] buffer, int offset, int count) { - ValidateState(CancellationToken.None); + ValidateState(default(CancellationToken)); _context.FrameControl.Write(new ArraySegment(buffer, offset, count)); } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketOutput.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketOutput.cs index 7033d4a1fa..3e58a4b178 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketOutput.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketOutput.cs @@ -474,7 +474,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http void ISocketOutput.Write(ArraySegment buffer, bool chunk) { - WriteAsync(buffer, CancellationToken.None, chunk, isSync: true).GetAwaiter().GetResult(); + WriteAsync(buffer, default(CancellationToken), chunk, isSync: true).GetAwaiter().GetResult(); } Task ISocketOutput.WriteAsync(ArraySegment buffer, bool chunk, CancellationToken cancellationToken) diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs index 811cf121a4..acfa41fb36 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs @@ -209,16 +209,16 @@ namespace Microsoft.AspNetCore.Server.KestrelTests using (var connection = new TestConnection()) { - var requestData = + var requestData = Enumerable.Repeat("GET / HTTP/1.1\r\n", loopCount) .Concat(new[] { "GET / HTTP/1.1\r\nConnection: close\r\n\r\nGoodbye" }); - var responseData = + var responseData = Enumerable.Repeat("HTTP/1.1 200 OK\r\nContent-Length: 0\r\n", loopCount) .Concat(new[] { "HTTP/1.1 200 OK\r\nConnection: close\r\n\r\nGoodbye" }); await connection.SendEnd(requestData.ToArray()); - + await connection.ReceiveEnd(responseData.ToArray()); } @@ -475,7 +475,6 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { var socket = new Socket(SocketType.Stream, ProtocolType.Tcp); socket.Connect(IPAddress.Loopback, 54321); - await Task.Delay(200); socket.Dispose(); await Task.Delay(200); @@ -1096,9 +1095,8 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Test hangs after execution on Mono.")] public async Task FailedWritesResultInAbortedRequest(ServiceContext testContext) { - const int resetEventTimeout = 2000; // This should match _maxBytesPreCompleted in SocketOutput - const int maxBytesPreCompleted = 65536; + var maxBytesPreCompleted = 65536; // Ensure string is long enough to disable write-behind buffering var largeString = new string('a', maxBytesPreCompleted + 1); @@ -1122,9 +1120,9 @@ namespace Microsoft.AspNetCore.Server.KestrelTests try { // Ensure write is long enough to disable write-behind buffering - for (int i = 0; i < 100; i++) + for (int i = 0; i < 10; i++) { - await response.WriteAsync(largeString, lifetime.RequestAborted).ConfigureAwait(false); + await response.WriteAsync(largeString, lifetime.RequestAborted); } } catch (Exception ex) @@ -1142,7 +1140,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests "POST / HTTP/1.1", "Content-Length: 5", "", - "Hello").ConfigureAwait(false); + "Hello"); // Don't wait to receive the response. Just close the socket. } @@ -1151,7 +1149,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests // Write failed await Assert.ThrowsAsync(async () => await writeTcs.Task); // RequestAborted tripped - Assert.True(registrationWh.Wait(resetEventTimeout)); + Assert.True(registrationWh.Wait(1000)); } } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/SocketOutputTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/SocketOutputTests.cs index 824ab4378b..df8edab06b 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/SocketOutputTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/SocketOutputTests.cs @@ -119,9 +119,9 @@ namespace Microsoft.AspNetCore.Server.KestrelTests Assert.True(completedWh.Wait(1000)); } } - + [Fact] - public async Task WritesDontCompleteImmediatelyWhenTooManyBytesIncludingNonImmediateAreAlreadyPreCompleted() + public void WritesDontCompleteImmediatelyWhenTooManyBytesIncludingNonImmediateAreAlreadyPreCompleted() { // This should match _maxBytesPreCompleted in SocketOutput var maxBytesPreCompleted = 65536; @@ -155,7 +155,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var halfWriteBehindBuffer = new ArraySegment(data, 0, bufferSize); // Act - var writeTask1 = socketOutput.WriteAsync(halfWriteBehindBuffer, CancellationToken.None); + var writeTask1 = socketOutput.WriteAsync(halfWriteBehindBuffer, default(CancellationToken)); // Assert // The first write should pre-complete since it is <= _maxBytesPreCompleted. Assert.Equal(TaskStatus.RanToCompletion, writeTask1.Status); @@ -168,7 +168,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests socketOutput.ProducingComplete(iter); // Act - var writeTask2 = socketOutput.WriteAsync(halfWriteBehindBuffer, CancellationToken.None); + var writeTask2 = socketOutput.WriteAsync(halfWriteBehindBuffer, default(CancellationToken)); // Assert // Too many bytes are already pre-completed for the fourth write to pre-complete. Assert.True(writeRequestedWh.Wait(1000)); @@ -230,15 +230,12 @@ namespace Microsoft.AspNetCore.Server.KestrelTests Assert.False(task1Success.IsCanceled); Assert.False(task1Success.IsFaulted); - task1Success.GetAwaiter().GetResult(); - // following tasks should wait. - var task2Throw = socketOutput.WriteAsync(fullBuffer, cancellationToken: cts.Token); var task3Success = socketOutput.WriteAsync(fullBuffer, cancellationToken: default(CancellationToken)); // Give time for tasks to percolate - await Task.Delay(1000).ConfigureAwait(false); + await Task.Delay(1000); // Second task is not completed Assert.False(task2Throw.IsCompleted); @@ -252,18 +249,12 @@ namespace Microsoft.AspNetCore.Server.KestrelTests cts.Cancel(); - // Give time for tasks to percolate - await Task.Delay(1000).ConfigureAwait(false); - // Second task is now canceled - Assert.True(task2Throw.IsCompleted); + await Assert.ThrowsAsync(() => task2Throw); Assert.True(task2Throw.IsCanceled); - Assert.False(task2Throw.IsFaulted); - // Third task is now completed - Assert.True(task3Success.IsCompleted); - Assert.False(task3Success.IsCanceled); - Assert.False(task3Success.IsFaulted); + // Third task is now completed + await task3Success; // Fourth task immediately cancels as the token is canceled var task4Throw = socketOutput.WriteAsync(fullBuffer, cancellationToken: cts.Token); @@ -272,25 +263,21 @@ namespace Microsoft.AspNetCore.Server.KestrelTests Assert.True(task4Throw.IsCanceled); Assert.False(task4Throw.IsFaulted); - Assert.Throws(() => task4Throw.GetAwaiter().GetResult()); - var task5Success = socketOutput.WriteAsync(fullBuffer, cancellationToken: default(CancellationToken)); // task5 should complete immediately - + Assert.True(task5Success.IsCompleted); Assert.False(task5Success.IsCanceled); Assert.False(task5Success.IsFaulted); cts = new CancellationTokenSource(); - var task6Throw = socketOutput.WriteAsync(fullBuffer, cancellationToken: cts.Token); + var task6Success = socketOutput.WriteAsync(fullBuffer, cancellationToken: cts.Token); // task6 should complete immediately but not cancel as its cancellation token isn't set - Assert.True(task6Throw.IsCompleted); - Assert.False(task6Throw.IsCanceled); - Assert.False(task6Throw.IsFaulted); - - task6Throw.GetAwaiter().GetResult(); + Assert.True(task6Success.IsCompleted); + Assert.False(task6Success.IsCanceled); + Assert.False(task6Success.IsFaulted); Assert.True(true); } @@ -342,14 +329,12 @@ namespace Microsoft.AspNetCore.Server.KestrelTests Assert.False(task1Success.IsCanceled); Assert.False(task1Success.IsFaulted); - task1Success.GetAwaiter().GetResult(); - // following tasks should wait. - var task2Success = socketOutput.WriteAsync(fullBuffer, cancellationToken: CancellationToken.None); + var task2Success = socketOutput.WriteAsync(fullBuffer, cancellationToken: default(CancellationToken)); var task3Canceled = socketOutput.WriteAsync(fullBuffer, cancellationToken: abortedSource.Token); // Give time for tasks to percolate - await Task.Delay(1000).ConfigureAwait(false); + await Task.Delay(1000); // Second task is not completed Assert.False(task2Success.IsCompleted); @@ -364,18 +349,12 @@ namespace Microsoft.AspNetCore.Server.KestrelTests // Cause the first write to fail. completeQueue.Dequeue()(-1); - // Give time for tasks to percolate - await Task.Delay(1000).ConfigureAwait(false); - // Second task is now completed - Assert.True(task2Success.IsCompleted); - Assert.False(task2Success.IsCanceled); - Assert.False(task2Success.IsFaulted); + await task2Success; // Third task is now canceled - Assert.True(task3Canceled.IsCompleted); + await Assert.ThrowsAsync(() => task3Canceled); Assert.True(task3Canceled.IsCanceled); - Assert.False(task3Canceled.IsFaulted); } } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestConnection.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/TestConnection.cs index 268eaa7b78..b7a2a625cb 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/TestConnection.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/TestConnection.cs @@ -49,7 +49,8 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var ch = text[index]; await writer.WriteAsync(ch); await writer.FlushAsync(); - await Task.Delay(TimeSpan.FromMilliseconds(5)); + // Re-add delay to help find socket input consumption bugs more consistently + //await Task.Delay(TimeSpan.FromMilliseconds(5)); } writer.Flush(); _stream.Flush(); From 15ed03eb261f5f21d617664b71b025b3e5b30c01 Mon Sep 17 00:00:00 2001 From: Brennan Date: Thu, 21 Jan 2016 09:52:39 -0800 Subject: [PATCH 0590/1662] React to Logging API changes --- .../Filter/FilteredStreamAdapter.cs | 4 ++-- src/Microsoft.AspNetCore.Server.Kestrel/Http/Connection.cs | 4 ++-- src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs | 4 ++-- src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameOfT.cs | 4 ++-- src/Microsoft.AspNetCore.Server.Kestrel/Http/Listener.cs | 2 +- .../Http/ListenerPrimary.cs | 2 +- .../Http/ListenerSecondary.cs | 4 ++-- .../Http/PipeListener.cs | 2 +- .../Http/PipeListenerPrimary.cs | 2 +- .../Http/SocketOutput.cs | 2 +- src/Microsoft.AspNetCore.Server.Kestrel/Http/TcpListener.cs | 2 +- .../Http/TcpListenerPrimary.cs | 2 +- .../Infrastructure/KestrelThread.cs | 4 ++-- .../Infrastructure/KestrelTrace.cs | 4 ++-- .../Networking/UvConnectRequest.cs | 2 +- .../Networking/UvStreamHandle.cs | 6 +++--- .../Networking/UvWriteReq.cs | 2 +- .../Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs | 4 ++-- test/Microsoft.AspNetCore.Server.KestrelTests/TestLogger.cs | 2 +- 19 files changed, 29 insertions(+), 29 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Filter/FilteredStreamAdapter.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Filter/FilteredStreamAdapter.cs index de144a0cc0..7174f10171 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Filter/FilteredStreamAdapter.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Filter/FilteredStreamAdapter.cs @@ -48,7 +48,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Filter { if (copyAsyncTask.IsFaulted) { - _log.LogError("FilteredStreamAdapter.CopyToAsync", copyAsyncTask.Exception); + _log.LogError(0, copyAsyncTask.Exception, "FilteredStreamAdapter.CopyToAsync"); } else if (copyAsyncTask.IsCanceled) { @@ -62,7 +62,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Filter } catch (Exception ex) { - _log.LogError("FilteredStreamAdapter.OnStreamClose", ex); + _log.LogError(0, ex, "FilteredStreamAdapter.OnStreamClose"); } } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Connection.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Connection.cs index 0708796ecb..15f57a8076 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Connection.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Connection.cs @@ -87,7 +87,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if (task.IsFaulted) { - connection.Log.LogError("ConnectionFilter.OnConnection", task.Exception); + connection.Log.LogError(0, task.Exception, "ConnectionFilter.OnConnection"); connection.ConnectionControl.End(ProduceEndType.SocketDisconnect); } else if (task.IsCanceled) @@ -103,7 +103,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } catch (Exception ex) { - Log.LogError("ConnectionFilter.OnConnection", ex); + Log.LogError(0, ex, "ConnectionFilter.OnConnection"); ConnectionControl.End(ProduceEndType.SocketDisconnect); } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs index c6b5fe05f0..0c83003b88 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs @@ -302,7 +302,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } catch (Exception ex) { - Log.LogError("Abort", ex); + Log.LogError(0, ex, "Abort"); } try @@ -311,7 +311,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } catch (Exception ex) { - Log.LogError("Abort", ex); + Log.LogError(0, ex, "Abort"); } _abortedCts = null; } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameOfT.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameOfT.cs index e9498b1d40..0d9ea1d673 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameOfT.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameOfT.cs @@ -140,7 +140,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } catch (Exception ex) { - Log.LogWarning("Connection processing ended abnormally", ex); + Log.LogWarning(0, ex, "Connection processing ended abnormally"); } finally { @@ -163,7 +163,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } catch (Exception ex) { - Log.LogWarning("Connection shutdown abnormally", ex); + Log.LogWarning(0, ex, "Connection shutdown abnormally"); } } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Listener.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Listener.cs index d4137ad369..d43f54e58a 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Listener.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Listener.cs @@ -56,7 +56,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http var listener = (Listener) state; if (error != null) { - listener.Log.LogError("Listener.ConnectionCallback ", error); + listener.Log.LogError(0, error, "Listener.ConnectionCallback"); } else { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/ListenerPrimary.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/ListenerPrimary.cs index e9af35d142..58f46e14b8 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/ListenerPrimary.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/ListenerPrimary.cs @@ -69,7 +69,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http catch (UvException ex) { dispatchPipe.Dispose(); - Log.LogError("ListenerPrimary.OnListenPipe", ex); + Log.LogError(0, ex, "ListenerPrimary.OnListenPipe"); return; } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/ListenerSecondary.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/ListenerSecondary.cs index b20c35ebc8..18d69c1dd5 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/ListenerSecondary.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/ListenerSecondary.cs @@ -112,7 +112,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { Exception ex; Thread.Loop.Libuv.Check(status, out ex); - Log.LogError("DispatchPipe.ReadStart", ex); + Log.LogError(0, ex, "DispatchPipe.ReadStart"); } DispatchPipe.Dispose(); @@ -132,7 +132,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } catch (UvException ex) { - Log.LogError("DispatchPipe.Accept", ex); + Log.LogError(0, ex, "DispatchPipe.Accept"); acceptSocket.Dispose(); return; } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/PipeListener.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/PipeListener.cs index 9e6849087f..19a10c552f 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/PipeListener.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/PipeListener.cs @@ -46,7 +46,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } catch (UvException ex) { - Log.LogError("PipeListener.OnConnection", ex); + Log.LogError(0, ex, "PipeListener.OnConnection"); acceptSocket.Dispose(); return; } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/PipeListenerPrimary.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/PipeListenerPrimary.cs index 6454fb6f58..4381a43c8b 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/PipeListenerPrimary.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/PipeListenerPrimary.cs @@ -46,7 +46,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } catch (UvException ex) { - Log.LogError("ListenerPrimary.OnConnection", ex); + Log.LogError(0, ex, "ListenerPrimary.OnConnection"); acceptSocket.Dispose(); return; } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketOutput.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketOutput.cs index 3e58a4b178..bb39a268ae 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketOutput.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketOutput.cs @@ -653,7 +653,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } catch (Exception ex) { - Self._log.LogError("SocketOutput.OnWriteCompleted", ex); + Self._log.LogError(0, ex, "SocketOutput.OnWriteCompleted"); } } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/TcpListener.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/TcpListener.cs index 113f9f69b7..4c0f8f19ba 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/TcpListener.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/TcpListener.cs @@ -48,7 +48,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } catch (UvException ex) { - Log.LogError("TcpListener.OnConnection", ex); + Log.LogError(0, ex, "TcpListener.OnConnection"); acceptSocket.Dispose(); return; } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/TcpListenerPrimary.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/TcpListenerPrimary.cs index 6721e8b012..6c1697cfe8 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/TcpListenerPrimary.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/TcpListenerPrimary.cs @@ -50,7 +50,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } catch (UvException ex) { - Log.LogError("TcpListenerPrimary.OnConnection", ex); + Log.LogError(0, ex, "TcpListenerPrimary.OnConnection"); acceptSocket.Dispose(); return; } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/KestrelThread.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/KestrelThread.cs index 82c6f11f0a..bd9ac3020c 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/KestrelThread.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/KestrelThread.cs @@ -333,7 +333,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel } else { - _log.LogError("KestrelThread.DoPostWork", ex); + _log.LogError(0, ex, "KestrelThread.DoPostWork"); throw; } } @@ -362,7 +362,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel } catch (Exception ex) { - _log.LogError("KestrelThread.DoPostCloseHandle", ex); + _log.LogError(0, ex, "KestrelThread.DoPostCloseHandle"); throw; } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/KestrelTrace.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/KestrelTrace.cs index 5e8a2ee28f..9be3819e8b 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/KestrelTrace.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/KestrelTrace.cs @@ -115,7 +115,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel public virtual void ApplicationError(Exception ex) { - _logger.LogError(13, "An unhandled exception was thrown by the application.", ex); + _logger.LogError(13, ex, "An unhandled exception was thrown by the application."); } public virtual void ConnectionError(long connectionId, Exception ex) @@ -128,7 +128,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel _connectionDisconnectedWrite(_logger, connectionId, count, ex); } - public virtual void Log(LogLevel logLevel, int eventId, object state, Exception exception, Func formatter) + public virtual void Log(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func formatter) { _logger.Log(logLevel, eventId, state, exception, formatter); } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvConnectRequest.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvConnectRequest.cs index 1ceb8f9e51..bccd31a57b 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvConnectRequest.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvConnectRequest.cs @@ -66,7 +66,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Networking } catch (Exception ex) { - req._log.LogError("UvConnectRequest", ex); + req._log.LogError(0, ex, "UvConnectRequest"); throw; } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvStreamHandle.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvStreamHandle.cs index e60de40d3b..3b88c74a16 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvStreamHandle.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvStreamHandle.cs @@ -133,7 +133,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Networking } catch (Exception ex) { - stream._log.LogError("UvConnectionCb", ex); + stream._log.LogError(0, ex, "UvConnectionCb"); throw; } } @@ -147,7 +147,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Networking } catch (Exception ex) { - stream._log.LogError("UvAllocCb", ex); + stream._log.LogError(0, ex, "UvAllocCb"); buf = stream.Libuv.buf_init(IntPtr.Zero, 0); throw; } @@ -163,7 +163,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Networking } catch (Exception ex) { - stream._log.LogError("UbReadCb", ex); + stream._log.LogError(0, ex, "UbReadCb"); throw; } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvWriteReq.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvWriteReq.cs index cdefbdaf9c..576fce68c2 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvWriteReq.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvWriteReq.cs @@ -177,7 +177,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Networking } catch (Exception ex) { - req._log.LogError("UvWriteCb", ex); + req._log.LogError(0, ex, "UvWriteCb"); throw; } } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs index acfa41fb36..920e3151af 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs @@ -1167,10 +1167,10 @@ namespace Microsoft.AspNetCore.Server.KestrelTests return true; } - public void Log(LogLevel logLevel, int eventId, object state, Exception exception, Func formatter) + public void Log(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func formatter) { // Application errors are logged using 13 as the eventId. - if (eventId == 13) + if (eventId.Id == 13) { ApplicationErrorsLogged++; } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestLogger.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/TestLogger.cs index 2697a4b7ef..eead43b301 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/TestLogger.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/TestLogger.cs @@ -28,7 +28,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests public class TestLogger : ILogger { - public void Log(LogLevel logLevel, int eventId, object state, Exception exception, Func formatter) + public void Log(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func formatter) { #if false Console.WriteLine($"Log {logLevel}[{eventId}]: {formatter(state, exception)} {exception?.Message}"); From d616f0ccb0f6600a1e7005c5ce6240aaf561b138 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Wed, 27 Jan 2016 14:31:24 -0800 Subject: [PATCH 0591/1662] Fix FindFirstEqualByte tests - On some platforms, the bytes array was not large enough to fill a vector. Ex: https://travis-ci.org/aspnet/KestrelHttpServer/builds/105277870#L2633 - Additionally test FindFirstEqualByte with only one bit set in the array --- .../MemoryPoolIterator2Tests.cs | 28 +++++++++++++------ 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolIterator2Tests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolIterator2Tests.cs index 046f032fc2..cb11398a42 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolIterator2Tests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolIterator2Tests.cs @@ -21,31 +21,43 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } [Fact] - public void FindFirstByte() + public void FindFirstEqualByte() { - var bytes = new byte[] { - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; + var bytes = Enumerable.Repeat(0xff, Vector.Count).ToArray(); for (int i = 0; i < Vector.Count; i++) { Vector vector = new Vector(bytes); Assert.Equal(i, MemoryPoolIterator2.FindFirstEqualByte(ref vector)); bytes[i] = 0; } + + for (int i = 0; i < Vector.Count; i++) + { + bytes[i] = 1; + Vector vector = new Vector(bytes); + Assert.Equal(i, MemoryPoolIterator2.FindFirstEqualByte(ref vector)); + bytes[i] = 0; + } } [Fact] - public void _FindFirstByte() + public void FindFirstEqualByteSlow() { - var bytes = new byte[] { - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; + var bytes = Enumerable.Repeat(0xff, Vector.Count).ToArray(); for (int i = 0; i < Vector.Count; i++) { Vector vector = new Vector(bytes); Assert.Equal(i, MemoryPoolIterator2.FindFirstEqualByteSlow(ref vector)); bytes[i] = 0; } + + for (int i = 0; i < Vector.Count; i++) + { + bytes[i] = 1; + Vector vector = new Vector(bytes); + Assert.Equal(i, MemoryPoolIterator2.FindFirstEqualByteSlow(ref vector)); + bytes[i] = 0; + } } [Theory] From 1209eca3fa755da019244ff3da4998e253c23bae Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Fri, 8 Jan 2016 15:41:53 -0800 Subject: [PATCH 0592/1662] Normalize request path to NFC and resolve dot segments (#273). --- .../Http/Frame.cs | 3 + .../Http/PathNormalizer.cs | 132 ++++++++++++++++++ .../ServerAddress.cs | 3 + .../project.json | 1 + .../RequestTests.cs | 60 +++++++- .../EngineTests.cs | 2 +- .../PathNormalizerTests.cs | 63 +++++++++ .../ServerAddressFacts.cs | 14 ++ .../project.json | 2 + 9 files changed, 276 insertions(+), 4 deletions(-) create mode 100644 src/Microsoft.AspNetCore.Server.Kestrel/Http/PathNormalizer.cs create mode 100644 test/Microsoft.AspNetCore.Server.KestrelTests/PathNormalizerTests.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs index 0c83003b88..81aa57bb5b 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs @@ -741,6 +741,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http // URI was encoded, unescape and then parse as utf8 pathEnd = UrlPathDecoder.Unescape(pathBegin, pathEnd); requestUrlPath = pathBegin.GetUtf8String(pathEnd); + requestUrlPath = PathNormalizer.NormalizeToNFC(requestUrlPath); } else { @@ -748,6 +749,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http requestUrlPath = pathBegin.GetAsciiString(pathEnd); } + requestUrlPath = PathNormalizer.RemoveDotSegments(requestUrlPath); + consumed = scan; Method = method; RequestUri = requestUrlPath; diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/PathNormalizer.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/PathNormalizer.cs new file mode 100644 index 0000000000..e136331e22 --- /dev/null +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/PathNormalizer.cs @@ -0,0 +1,132 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Buffers; +using System.Text; + +namespace Microsoft.AspNetCore.Server.Kestrel.Http +{ + public static class PathNormalizer + { + public static string NormalizeToNFC(string path) + { + if (!path.IsNormalized(NormalizationForm.FormC)) + { + path = path.Normalize(NormalizationForm.FormC); + } + + return path; + } + + public static string RemoveDotSegments(string path) + { + if (ContainsDotSegments(path)) + { + var normalizedChars = ArrayPool.Shared.Rent(path.Length); + var normalizedIndex = normalizedChars.Length; + var pathIndex = path.Length - 1; + var skipSegments = 0; + + while (pathIndex >= 0) + { + if (pathIndex >= 2 && path[pathIndex] == '.' && path[pathIndex - 1] == '.' && path[pathIndex - 2] == '/') + { + if (normalizedIndex == normalizedChars.Length || normalizedChars[normalizedIndex] != '/') + { + normalizedChars[--normalizedIndex] = '/'; + } + + skipSegments++; + pathIndex -= 3; + } + else if (pathIndex >= 1 && path[pathIndex] == '.' && path[pathIndex - 1] == '/') + { + pathIndex -= 2; + } + else + { + while (pathIndex >= 0) + { + var lastChar = path[pathIndex]; + + if (skipSegments == 0) + { + normalizedChars[--normalizedIndex] = lastChar; + } + + pathIndex--; + + if (lastChar == '/') + { + break; + } + } + + if (skipSegments > 0) + { + skipSegments--; + } + } + } + + path = new string(normalizedChars, normalizedIndex, normalizedChars.Length - normalizedIndex); + ArrayPool.Shared.Return(normalizedChars); + } + + return path; + } + + private unsafe static bool ContainsDotSegments(string path) + { + fixed (char* ptr = path) + { + char* end = ptr + path.Length; + + for (char* p = ptr; p < end; p++) + { + if (*p == '/') + { + p++; + } + + if (p == end) + { + return false; + } + + if (*p == '.') + { + p++; + + if (p == end) + { + return true; + } + + if (*p == '.') + { + p++; + + if (p == end) + { + return true; + } + + if (*p == '/') + { + return true; + } + } + else if (*p == '/') + { + return true; + } + } + } + } + + return false; + } + } +} diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/ServerAddress.cs b/src/Microsoft.AspNetCore.Server.Kestrel/ServerAddress.cs index 4bbc6dc9c5..a41472bbdf 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/ServerAddress.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/ServerAddress.cs @@ -4,6 +4,7 @@ using System; using System.Diagnostics; using System.Globalization; +using Microsoft.AspNetCore.Server.Kestrel.Http; using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; namespace Microsoft.AspNetCore.Server.Kestrel @@ -147,6 +148,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel serverAddress.PathBase = url.Substring(pathDelimiterEnd); } + serverAddress.PathBase = PathNormalizer.NormalizeToNFC(serverAddress.PathBase); + return serverAddress; } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/project.json b/src/Microsoft.AspNetCore.Server.Kestrel/project.json index dcf935bc9f..82d6c92332 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/project.json +++ b/src/Microsoft.AspNetCore.Server.Kestrel/project.json @@ -6,6 +6,7 @@ "url": "git://github.com/aspnet/kestrelhttpserver" }, "dependencies": { + "System.Buffers": "4.0.0-*", "Microsoft.AspNetCore.Hosting": "1.0.0-*", "Microsoft.Extensions.Logging.Abstractions": "1.0.0-*", "Microsoft.Extensions.PlatformAbstractions": "1.0.0-*", diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs index 31e8ce1e22..25486918ca 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs @@ -3,7 +3,10 @@ using System.Collections.Generic; using System.Globalization; +using System.Net; using System.Net.Http; +using System.Net.Sockets; +using System.Text; using System.Threading.Tasks; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; @@ -88,7 +91,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [IPv6SupportedCondition] public Task RemoteIPv6Address() { - return TestRemoteIPAddress("[::1]", "[::1]", "::1", "8792"); + return TestRemoteIPAddress("[::1]", "[::1]", "::1", "8793"); } [ConditionalFact] @@ -97,7 +100,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { var config = new ConfigurationBuilder().AddInMemoryCollection( new Dictionary { - { "server.urls", "http://localhost:8791" } + { "server.urls", "http://localhost:8794" } }).Build(); var builder = new WebHostBuilder() @@ -120,11 +123,62 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests client.DefaultRequestHeaders.Connection.Clear(); client.DefaultRequestHeaders.Connection.Add("close"); - var response = await client.GetAsync("http://localhost:8791/"); + var response = await client.GetAsync("http://localhost:8794/"); response.EnsureSuccessStatusCode(); } } + [ConditionalFact] + [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Test hangs after execution on Mono.")] + public async Task RequestPathIsNormalized() + { + var config = new ConfigurationBuilder().AddInMemoryCollection( + new Dictionary { + { "server.urls", "http://localhost:8795/\u0041\u030A" } + }).Build(); + + var builder = new WebHostBuilder() + .UseConfiguration(config) + .UseServer("Microsoft.AspNetCore.Server.Kestrel") + .Configure(app => + { + app.Run(async context => + { + var connection = context.Connection; + Assert.Equal("/\u00C5", context.Request.PathBase.Value); + Assert.Equal("/B/\u00C5", context.Request.Path.Value); + await context.Response.WriteAsync("hello, world"); + }); + }); + + using (var host = builder.Build()) + { + host.Start(); + + using (var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)) + { + socket.Connect(new IPEndPoint(IPAddress.Loopback, 8795)); + socket.Send(Encoding.ASCII.GetBytes("GET /%41%CC%8A/A/../B/%41%CC%8A HTTP/1.1\r\n\r\n")); + socket.Shutdown(SocketShutdown.Send); + + var response = new StringBuilder(); + var buffer = new byte[4096]; + while (true) + { + var length = socket.Receive(buffer); + if (length == 0) + { + break; + } + + response.Append(Encoding.ASCII.GetString(buffer, 0, length)); + } + + Assert.StartsWith("HTTP/1.1 200 OK", response.ToString()); + } + } + } + private async Task TestRemoteIPAddress(string registerAddress, string requestAddress, string expectAddress, string port) { var config = new ConfigurationBuilder().AddInMemoryCollection( diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs index 920e3151af..95e9d304bb 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs @@ -1120,7 +1120,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests try { // Ensure write is long enough to disable write-behind buffering - for (int i = 0; i < 10; i++) + for (int i = 0; i < 100; i++) { await response.WriteAsync(largeString, lifetime.RequestAborted); } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/PathNormalizerTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/PathNormalizerTests.cs new file mode 100644 index 0000000000..a2304301e8 --- /dev/null +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/PathNormalizerTests.cs @@ -0,0 +1,63 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Text; +using Microsoft.AspNetCore.Server.Kestrel.Http; +using Xunit; + +namespace Microsoft.AspNetCore.Server.KestrelTests +{ + public class PathNormalizerTests + { + [Theory] + [InlineData("/a", "/a")] + [InlineData("/a/", "/a/")] + [InlineData("/a/b", "/a/b")] + [InlineData("/a/b/", "/a/b/")] + [InlineData("/a", "/./a")] + [InlineData("/a", "/././a")] + [InlineData("/a", "/../a")] + [InlineData("/a", "/../../a")] + [InlineData("/a/b", "/a/./b")] + [InlineData("/b", "/a/../b")] + [InlineData("/a/", "/a/./")] + [InlineData("/a", "/a/.")] + [InlineData("/", "/a/../b/../")] + [InlineData("/", "/a/../b/..")] + [InlineData("/b", "/a/../../b")] + [InlineData("/b/", "/a/../../b/")] + [InlineData("/b", "/a/.././../b")] + [InlineData("/b/", "/a/.././../b/")] + [InlineData("/a/d", "/a/b/c/./../../d")] + [InlineData("/a/d", "/./a/b/c/./../../d")] + [InlineData("/a/d", "/../a/b/c/./../../d")] + [InlineData("/a/d", "/./../a/b/c/./../../d")] + [InlineData("/a/d", "/.././a/b/c/./../../d")] + [InlineData("/.a", "/.a")] + [InlineData("/..a", "/..a")] + [InlineData("/...", "/...")] + [InlineData("/a/.../b", "/a/.../b")] + [InlineData("/b", "/a/../.../../b")] + [InlineData("/a/.b", "/a/.b")] + [InlineData("/a/..b", "/a/..b")] + [InlineData("/a/b.", "/a/b.")] + [InlineData("/a/b..", "/a/b..")] + [InlineData("a/b", "a/b")] + [InlineData("a/c", "a/b/../c")] + [InlineData("*", "*")] + public void RemovesDotSegments(string expected, string input) + { + var result = PathNormalizer.RemoveDotSegments(input); + Assert.Equal(expected, result); + } + + [Fact] + public void NormalizesToNFC() + { + var result = PathNormalizer.NormalizeToNFC("/\u0041\u030A"); + Assert.True(result.IsNormalized(NormalizationForm.FormC)); + Assert.Equal("/\u00C5", result); + } + } +} diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/ServerAddressFacts.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/ServerAddressFacts.cs index 9738dac675..c29a1fdb15 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/ServerAddressFacts.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/ServerAddressFacts.cs @@ -1,3 +1,8 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Text; using Microsoft.AspNetCore.Server.Kestrel; using Xunit; @@ -43,5 +48,14 @@ namespace Microsoft.AspNetCore.Server.KestrelTests Assert.Equal(port, serverAddress.Port); Assert.Equal(pathBase, serverAddress.PathBase); } + + [Fact] + public void PathBaseIsNormalized() + { + var serverAddres = ServerAddress.FromUrl("http://localhost:8080/p\u0041\u030Athbase"); + + Assert.True(serverAddres.PathBase.IsNormalized(NormalizationForm.FormC)); + Assert.Equal("/p\u00C5thbase", serverAddres.PathBase); + } } } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/project.json b/test/Microsoft.AspNetCore.Server.KestrelTests/project.json index e788721ede..3abc3b112b 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/project.json +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/project.json @@ -12,6 +12,8 @@ "dnxcore50": { "dependencies": { "System.Diagnostics.TraceSource": "4.0.0-*", + "System.Globalization.Extensions": "4.0.1-*", + "System.IO": "4.1.0-*", "System.Net.Http.WinHttpHandler": "4.0.0-*", "System.Net.Sockets": "4.1.0-*", "System.Runtime.Handles": "4.0.1-*" From 6757a31fd2ae035e2d2ff7e1f586b8f1498d3b60 Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Wed, 13 Jan 2016 11:01:16 -0800 Subject: [PATCH 0593/1662] Build with dotnet (#571). --- .gitattributes | 2 + .gitignore | 4 +- .travis.yml | 3 +- KestrelHttpServer.sln | 9 +- appveyor.yml | 4 +- build.cmd | 68 ++-- build.sh | 42 +-- makefile.shade | 9 +- samples/LargeResponseApp/Startup.cs | 2 + samples/LargeResponseApp/project.json | 10 +- samples/SampleApp/Startup.cs | 1 + samples/SampleApp/project.json | 8 +- .../project.json | 3 +- .../project.json | 29 +- .../AddressRegistrationTests.cs | 21 +- .../PathBaseTests.cs | 63 ++-- .../PortManager.cs | 17 + .../RequestTests.cs | 28 +- .../ResponseTests.cs | 15 +- .../ThreadCountTests.cs | 5 +- .../project.json | 19 +- .../ChunkedResponseTests.cs | 12 +- .../ConnectionFilterTests.cs | 6 +- .../EngineTests.cs | 68 ++-- .../HttpsConnectionFilterTests.cs | 13 +- .../NetworkingTests.cs | 21 +- .../Program.cs | 37 --- .../TestConnection.cs | 8 +- .../TestServer.cs | 19 +- .../project.json | 26 +- .../FrameFeatureCollection.cs | 13 +- .../KnownHeaders.cs | 12 +- .../Program.cs | 2 +- .../project.json | 20 +- .../Program.cs | 15 +- .../project.json | 26 +- .../Microsoft.StandardsPolice.xproj | 20 -- tools/Microsoft.StandardsPolice/Program.cs | 49 --- .../StandardsPoliceCompileModule.cs | 292 ------------------ tools/Microsoft.StandardsPolice/project.json | 44 --- 40 files changed, 331 insertions(+), 734 deletions(-) create mode 100644 test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/PortManager.cs delete mode 100644 test/Microsoft.AspNetCore.Server.KestrelTests/Program.cs delete mode 100644 tools/Microsoft.StandardsPolice/Microsoft.StandardsPolice.xproj delete mode 100644 tools/Microsoft.StandardsPolice/Program.cs delete mode 100644 tools/Microsoft.StandardsPolice/StandardsPoliceCompileModule.cs delete mode 100644 tools/Microsoft.StandardsPolice/project.json diff --git a/.gitattributes b/.gitattributes index bdaa5ba982..c2f0f84273 100644 --- a/.gitattributes +++ b/.gitattributes @@ -48,3 +48,5 @@ *.fsproj text=auto *.dbproj text=auto *.sln text=auto eol=crlf + +*.sh eol=lf \ No newline at end of file diff --git a/.gitignore b/.gitignore index 64f87ceb6d..b5933c6864 100644 --- a/.gitignore +++ b/.gitignore @@ -26,4 +26,6 @@ nuget.exe *.*sdf *.ipch project.lock.json -runtimes/ \ No newline at end of file +runtimes/ +.build/ +.testPublish/ \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index e9a98166a3..4e6d418f80 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,7 +11,7 @@ addons: - libunwind8 - zlib1g env: - - KOREBUILD_DNU_RESTORE_CORECLR=true KOREBUILD_TEST_DNXCORE=true + - KOREBUILD_TEST_SKIPMONO=true install: - curl -sSL https://github.com/libuv/libuv/archive/v1.4.2.tar.gz | tar zxfv - -C /tmp && cd /tmp/libuv-1.4.2/ - sh autogen.sh @@ -22,5 +22,6 @@ install: - cd $OLDPWD mono: - 4.0.5 +osx_image: xcode7.1 script: - ./build.sh --quiet verify diff --git a/KestrelHttpServer.sln b/KestrelHttpServer.sln index f54a7e5fa5..b673fbe198 100644 --- a/KestrelHttpServer.sln +++ b/KestrelHttpServer.sln @@ -1,7 +1,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 14 -VisualStudioVersion = 14.0.23107.0 +VisualStudioVersion = 14.0.24709.0 MinimumVisualStudioVersion = 10.0.40219.1 Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNetCore.Server.Kestrel", "src\Microsoft.AspNetCore.Server.Kestrel\Microsoft.AspNetCore.Server.Kestrel.xproj", "{F510611A-3BEE-4B88-A613-5F4A74ED82A1}" EndProject @@ -29,8 +29,6 @@ Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNetCore.Server EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tools", "tools", "{327F7880-D9AF-46BD-B45C-3B7E34A01DFD}" EndProject -Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.StandardsPolice", "tools\Microsoft.StandardsPolice\Microsoft.StandardsPolice.xproj", "{82295647-7C1C-4671-BAB6-0FEF58F949EC}" -EndProject Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNetCore.Server.Kestrel.LibuvCopier", "tools\Microsoft.AspNetCore.Server.Kestrel.LibuvCopier\Microsoft.AspNetCore.Server.Kestrel.LibuvCopier.xproj", "{8CBA6FE3-3CC9-4420-8AA3-123E983734C2}" EndProject Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNetCore.Server.Kestrel.Https", "src\Microsoft.AspNetCore.Server.Kestrel.Https\Microsoft.AspNetCore.Server.Kestrel.Https.xproj", "{5F64B3C3-0C2E-431A-B820-A81BBFC863DA}" @@ -63,10 +61,6 @@ Global {BD2D4D29-1BD9-40D0-BB31-337D5416B63C}.Debug|Any CPU.Build.0 = Debug|Any CPU {BD2D4D29-1BD9-40D0-BB31-337D5416B63C}.Release|Any CPU.ActiveCfg = Release|Any CPU {BD2D4D29-1BD9-40D0-BB31-337D5416B63C}.Release|Any CPU.Build.0 = Release|Any CPU - {82295647-7C1C-4671-BAB6-0FEF58F949EC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {82295647-7C1C-4671-BAB6-0FEF58F949EC}.Debug|Any CPU.Build.0 = Debug|Any CPU - {82295647-7C1C-4671-BAB6-0FEF58F949EC}.Release|Any CPU.ActiveCfg = Release|Any CPU - {82295647-7C1C-4671-BAB6-0FEF58F949EC}.Release|Any CPU.Build.0 = Release|Any CPU {8CBA6FE3-3CC9-4420-8AA3-123E983734C2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {8CBA6FE3-3CC9-4420-8AA3-123E983734C2}.Debug|Any CPU.Build.0 = Debug|Any CPU {8CBA6FE3-3CC9-4420-8AA3-123E983734C2}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -89,7 +83,6 @@ Global {2C3CB3DC-EEBF-4F52-9E1C-4F2F972E76C3} = {8A3D00B8-1CCF-4BE6-A060-11104CE2D9CE} {B35D4D31-E74C-4646-8A11-7A7A40F0021E} = {8A3D00B8-1CCF-4BE6-A060-11104CE2D9CE} {BD2D4D29-1BD9-40D0-BB31-337D5416B63C} = {327F7880-D9AF-46BD-B45C-3B7E34A01DFD} - {82295647-7C1C-4671-BAB6-0FEF58F949EC} = {327F7880-D9AF-46BD-B45C-3B7E34A01DFD} {8CBA6FE3-3CC9-4420-8AA3-123E983734C2} = {327F7880-D9AF-46BD-B45C-3B7E34A01DFD} {5F64B3C3-0C2E-431A-B820-A81BBFC863DA} = {2D5D5227-4DBD-499A-96B1-76A36B03B750} {9559A5F1-080C-4909-B6CF-7E4B3DC55748} = {D3273454-EA07-41D2-BF0B-FCC3675C2483} diff --git a/appveyor.yml b/appveyor.yml index 636a7618d3..265df8f1f5 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -4,4 +4,6 @@ build_script: - build.cmd --quiet verify clone_depth: 1 test: off -deploy: off \ No newline at end of file +deploy: off +environment: + NO_PARALLEL_TEST_PROJECTS: Microsoft.AspNetCore.Server.Kestrel.FunctionalTests \ No newline at end of file diff --git a/build.cmd b/build.cmd index 553e3929a0..ebb619e737 100644 --- a/build.cmd +++ b/build.cmd @@ -1,40 +1,40 @@ -@echo off -cd %~dp0 - +@ECHO off SETLOCAL + +SET REPO_FOLDER=%~dp0 +CD %REPO_FOLDER% + +SET BUILD_FOLDER=.build +SET KOREBUILD_FOLDER=%BUILD_FOLDER%\KoreBuild-dotnet +SET KOREBUILD_VERSION= + +SET NUGET_PATH=%BUILD_FOLDER%\NuGet.exe SET NUGET_VERSION=latest SET CACHED_NUGET=%LocalAppData%\NuGet\nuget.%NUGET_VERSION%.exe -SET BUILDCMD_KOREBUILD_VERSION= -SET BUILDCMD_DNX_VERSION= -IF EXIST %CACHED_NUGET% goto copynuget -echo Downloading latest version of NuGet.exe... -IF NOT EXIST %LocalAppData%\NuGet md %LocalAppData%\NuGet -@powershell -NoProfile -ExecutionPolicy unrestricted -Command "$ProgressPreference = 'SilentlyContinue'; Invoke-WebRequest 'https://dist.nuget.org/win-x86-commandline/%NUGET_VERSION%/nuget.exe' -OutFile '%CACHED_NUGET%'" - -:copynuget -IF EXIST .nuget\nuget.exe goto restore -md .nuget -copy %CACHED_NUGET% .nuget\nuget.exe > nul - -:restore -IF EXIST packages\Sake goto getdnx -IF "%BUILDCMD_KOREBUILD_VERSION%"=="" ( - .nuget\nuget.exe install KoreBuild -ExcludeVersion -o packages -nocache -pre -) ELSE ( - .nuget\nuget.exe install KoreBuild -version %BUILDCMD_KOREBUILD_VERSION% -ExcludeVersion -o packages -nocache -pre -) -.nuget\NuGet.exe install Sake -ExcludeVersion -Source https://www.nuget.org/api/v2/ -Out packages - -:getdnx -IF "%BUILDCMD_DNX_VERSION%"=="" ( - SET BUILDCMD_DNX_VERSION=latest -) -IF "%SKIP_DNX_INSTALL%"=="" ( - CALL packages\KoreBuild\build\dnvm install %BUILDCMD_DNX_VERSION% -runtime CoreCLR -arch x86 -alias default - CALL packages\KoreBuild\build\dnvm install default -runtime CLR -arch x86 -alias default -) ELSE ( - CALL packages\KoreBuild\build\dnvm use default -runtime CLR -arch x86 +IF NOT EXIST %BUILD_FOLDER% ( + md %BUILD_FOLDER% ) -packages\Sake\tools\Sake.exe -I packages\KoreBuild\build -f makefile.shade %* +IF NOT EXIST %NUGET_PATH% ( + IF NOT EXIST %CACHED_NUGET% ( + echo Downloading latest version of NuGet.exe... + IF NOT EXIST %LocalAppData%\NuGet ( + md %LocalAppData%\NuGet + ) + @powershell -NoProfile -ExecutionPolicy unrestricted -Command "$ProgressPreference = 'SilentlyContinue'; Invoke-WebRequest 'https://dist.nuget.org/win-x86-commandline/%NUGET_VERSION%/nuget.exe' -OutFile '%CACHED_NUGET%'" + ) + + copy %CACHED_NUGET% %NUGET_PATH% > nul +) + +IF NOT EXIST %KOREBUILD_FOLDER% ( + SET KOREBUILD_DOWNLOAD_ARGS= + IF NOT "%KOREBUILD_VERSION%"=="" ( + SET KOREBUILD_DOWNLOAD_ARGS=-version %KOREBUILD_VERSION% + ) + + %BUILD_FOLDER%\nuget.exe install KoreBuild-dotnet -ExcludeVersion -o %BUILD_FOLDER% -nocache -pre %KOREBUILD_DOWNLOAD_ARGS% +) + +"%KOREBUILD_FOLDER%\build\KoreBuild.cmd" %* diff --git a/build.sh b/build.sh index da4e3fcd1c..263fb667a8 100755 --- a/build.sh +++ b/build.sh @@ -1,5 +1,10 @@ #!/usr/bin/env bash +buildFolder=.build +koreBuildFolder=$buildFolder/KoreBuild-dotnet + +nugetPath=$buildFolder/nuget.exe + if test `uname` = Darwin; then cachedir=~/Library/Caches/KBuild else @@ -11,33 +16,30 @@ else fi mkdir -p $cachedir nugetVersion=latest -cachePath=$cachedir/nuget.$nugetVersion.exe +cacheNuget=$cachedir/nuget.$nugetVersion.exe -url=https://dist.nuget.org/win-x86-commandline/$nugetVersion/nuget.exe +nugetUrl=https://dist.nuget.org/win-x86-commandline/$nugetVersion/nuget.exe -if test ! -f $cachePath; then - wget -O $cachePath $url 2>/dev/null || curl -o $cachePath --location $url /dev/null +if test ! -d $buildFolder; then + mkdir $buildFolder fi -if test ! -e .nuget; then - mkdir .nuget - cp $cachePath .nuget/nuget.exe +if test ! -f $nugetPath; then + if test ! -f $cacheNuget; then + wget -O $cacheNuget $nugetUrl 2>/dev/null || curl -o $cacheNuget --location $nugetUrl /dev/null + fi + + cp $cacheNuget $nugetPath fi -if test ! -d packages/Sake; then - mono .nuget/nuget.exe install KoreBuild -ExcludeVersion -o packages -nocache -pre - mono .nuget/nuget.exe install Sake -ExcludeVersion -Source https://www.nuget.org/api/v2/ -Out packages +if test ! -d $koreBuildFolder; then + mono $nugetPath install KoreBuild-dotnet -ExcludeVersion -o $buildFolder -nocache -pre + chmod +x $koreBuildFolder/build/KoreBuild.sh fi -if ! type dnvm > /dev/null 2>&1; then - source packages/KoreBuild/build/dnvm.sh +makeFile=makefile.shade +if [ ! -e $makeFile ]; then + makeFile=$koreBuildFolder/build/makefile.shade fi -if ! type dnx > /dev/null 2>&1 || [ -z "$SKIP_DNX_INSTALL" ]; then - dnvm install latest -runtime coreclr -alias default - dnvm install default -runtime mono -alias default -else - dnvm use default -runtime mono -fi - -mono packages/Sake/tools/Sake.exe -I packages/KoreBuild/build -f makefile.shade "$@" +./$koreBuildFolder/build/KoreBuild.sh -n $nugetPath -m $makeFile "$@" diff --git a/makefile.shade b/makefile.shade index 0fad94bacc..c858bc893e 100644 --- a/makefile.shade +++ b/makefile.shade @@ -1,8 +1,15 @@ - var VERSION='0.1' var FULL_VERSION='0.1' var AUTHORS='Microsoft' +var kestrelSrcDir='${Path.Combine(Directory.GetCurrentDirectory(), "src/Microsoft.AspNetCore.Server.Kestrel")}' use-standard-lifecycle k-standard-goals custom-goals + +exec program='dotnet' commandline='restore ../../tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode' workingdir='${kestrelSrcDir}' +exec program='dotnet' commandline='run -p ../../tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode Http/FrameHeaders.Generated.cs Http/Frame.Generated.cs' workingdir='${kestrelSrcDir}' + +exec program='dotnet' commandline='restore' workingdir='${kestrelSrcDir}' +exec program='dotnet' commandline='restore ../../tools/Microsoft.AspNetCore.Server.Kestrel.LibuvCopier' workingdir='${kestrelSrcDir}' +exec program='dotnet' commandline='run -p ../../tools/Microsoft.AspNetCore.Server.Kestrel.LibuvCopier' workingdir='${kestrelSrcDir}' \ No newline at end of file diff --git a/samples/LargeResponseApp/Startup.cs b/samples/LargeResponseApp/Startup.cs index a6cba98657..b562ac6ebb 100644 --- a/samples/LargeResponseApp/Startup.cs +++ b/samples/LargeResponseApp/Startup.cs @@ -1,6 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System.IO; using System.Text; using System.Threading.Tasks; using Microsoft.AspNetCore.Builder; @@ -40,6 +41,7 @@ namespace LargeResponseApp { var host = new WebHostBuilder() .UseDefaultConfiguration(args) + .UseApplicationBasePath(Directory.GetCurrentDirectory()) .UseStartup() .Build(); diff --git a/samples/LargeResponseApp/project.json b/samples/LargeResponseApp/project.json index 0b96a43065..1d4253e603 100644 --- a/samples/LargeResponseApp/project.json +++ b/samples/LargeResponseApp/project.json @@ -8,9 +8,11 @@ }, "frameworks": { "dnx451": { }, - "dnxcore50": { } + "dnxcore50": { + "dependencies": { + "NETStandard.Library": "1.0.0-*" + } + } }, - "commands": { - "web": "LargeResponseApp" - } + "content": [ "hosting.json" ] } diff --git a/samples/SampleApp/Startup.cs b/samples/SampleApp/Startup.cs index c593da33a6..e2150d030b 100644 --- a/samples/SampleApp/Startup.cs +++ b/samples/SampleApp/Startup.cs @@ -65,6 +65,7 @@ namespace SampleApp { var host = new WebHostBuilder() .UseDefaultConfiguration(args) + .UseApplicationBasePath(Directory.GetCurrentDirectory()) .UseStartup() .Build(); diff --git a/samples/SampleApp/project.json b/samples/SampleApp/project.json index d96001e9bd..d6f84d15a2 100644 --- a/samples/SampleApp/project.json +++ b/samples/SampleApp/project.json @@ -9,15 +9,13 @@ "emitEntryPoint": true }, "frameworks": { - "dnx451": { - }, + "dnx451": { }, "dnxcore50": { "dependencies": { + "NETStandard.Library": "1.0.0-*", "System.Console": "4.0.0-*" } } }, - "commands": { - "web": "SampleApp" - } + "content": [ "hosting.json" ] } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Https/project.json b/src/Microsoft.AspNetCore.Server.Kestrel.Https/project.json index d2cb35dcdb..9b14714e76 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Https/project.json +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Https/project.json @@ -16,7 +16,8 @@ "dotnet5.4": { "dependencies": { "System.Net.Security": "4.0.0-*" - } + }, + "imports": "portable-net45+win8" } } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/project.json b/src/Microsoft.AspNetCore.Server.Kestrel/project.json index 82d6c92332..bfbe6d0b5a 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/project.json +++ b/src/Microsoft.AspNetCore.Server.Kestrel/project.json @@ -7,14 +7,11 @@ }, "dependencies": { "System.Buffers": "4.0.0-*", + "System.Numerics.Vectors": "4.1.1-*", + "System.Threading.Tasks.Extensions": "4.0.0-*", "Microsoft.AspNetCore.Hosting": "1.0.0-*", "Microsoft.Extensions.Logging.Abstractions": "1.0.0-*", "Microsoft.Extensions.PlatformAbstractions": "1.0.0-*", - "System.Numerics.Vectors": "4.1.1-*", - "Microsoft.StandardsPolice": { - "version": "1.0.0-*", - "type": "build" - }, "Microsoft.AspNetCore.Internal.libuv-Darwin": { "version": "1.0.0-*", "type": "build" @@ -22,11 +19,14 @@ "Microsoft.AspNetCore.Internal.libuv-Windows": { "version": "1.0.0-*", "type": "build" - }, - "System.Threading.Tasks.Extensions": "4.0.0-*" + } }, "frameworks": { - "net451": { }, + "net451": { + "frameworkAssemblies": { + "System.Threading.Tasks": "" + } + }, "dotnet5.4": { "dependencies": { "System.Collections": "4.0.11-*", @@ -45,23 +45,14 @@ "System.Threading.Thread": "4.0.0-*", "System.Threading.ThreadPool": "4.0.10-*", "System.Threading.Timer": "4.0.1-*" - } + }, + "imports": "portable-net45+win8" } }, "compilationOptions": { "allowUnsafe": true, "keyFile": "../../tools/Key.snk" }, - "scripts": { - "prepare": [ - "dnu restore ../../tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode", - "dnx -p ../../tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode run Http/FrameHeaders.Generated.cs Http/Frame.Generated.cs" - ], - "postrestore": [ - "dnu restore ../../tools/Microsoft.AspNetCore.Server.Kestrel.LibuvCopier", - "dnx -p ../../tools/Microsoft.AspNetCore.Server.Kestrel.LibuvCopier run" - ] - }, "packInclude": { "/": "../../content/thirdpartynotices.txt", "runtimes/win7-x64/native/": "runtimes/win7-x64/native/*", diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs index ea09bfb879..b7250054e6 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs @@ -64,11 +64,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { get { + var port1 = PortManager.GetPort(); + var port2 = PortManager.GetPort(); var dataset = new TheoryData(); - dataset.Add("8787", new[] { "http://localhost:8787/" }); - dataset.Add("8787;8788", new[] { "http://localhost:8787/", "http://localhost:8788/" }); - dataset.Add("http://127.0.0.1:8787/", new[] { "http://127.0.0.1:8787/", }); - dataset.Add("http://localhost:8787/base/path", new[] { "http://localhost:8787/base/path" }); + dataset.Add($"{port1}", new[] { $"http://localhost:{port1}/" }); + dataset.Add($"{port1};{port2}", new[] { $"http://localhost:{port1}/", $"http://localhost:{port2}/" }); + dataset.Add($"http://127.0.0.1:{port1}/", new[] { $"http://127.0.0.1:{port1}/", }); + dataset.Add($"http://localhost:{port1}/base/path", new[] { $"http://localhost:{port1}/base/path" }); return dataset; } @@ -78,14 +80,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { get { + var port = PortManager.GetPort(); var dataset = new TheoryData(); - dataset.Add("http://*:8787/", new[] { "http://localhost:8787/", "http://127.0.0.1:8787/", "http://[::1]:8787/" }); - dataset.Add("http://localhost:8787/", new[] { "http://localhost:8787/", "http://127.0.0.1:8787/", + dataset.Add($"http://*:{port}/", new[] { $"http://localhost:{port}/", $"http://127.0.0.1:{port}/", $"http://[::1]:{port}/" }); + dataset.Add($"http://localhost:{port}/", new[] { $"http://localhost:{port}/", $"http://127.0.0.1:{port}/", /* // https://github.com/aspnet/KestrelHttpServer/issues/231 - "http://[::1]:8787/" + $"http://[::1]:{port}/" */ }); - dataset.Add("http://[::1]:8787/", new[] { "http://[::1]:8787/", }); - dataset.Add("http://127.0.0.1:8787/;http://[::1]:8787/", new[] { "http://127.0.0.1:8787/", "http://[::1]:8787/" }); + dataset.Add($"http://[::1]:{port}/", new[] { $"http://[::1]:{port}/", }); + dataset.Add($"http://127.0.0.1:{port}/;http://[::1]:{port}/", new[] { $"http://127.0.0.1:{port}/", $"http://[::1]:{port}/" }); return dataset; } diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/PathBaseTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/PathBaseTests.cs index be427bcb40..14e8b82a06 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/PathBaseTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/PathBaseTests.cs @@ -18,65 +18,66 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests public class PathBaseTests { [ConditionalTheory] - [InlineData("http://localhost:8791/base", "http://localhost:8791/base", "/base", "")] - [InlineData("http://localhost:8791/base", "http://localhost:8791/base/", "/base", "/")] - [InlineData("http://localhost:8791/base", "http://localhost:8791/base/something", "/base", "/something")] - [InlineData("http://localhost:8791/base", "http://localhost:8791/base/something/", "/base", "/something/")] - [InlineData("http://localhost:8791/base/more", "http://localhost:8791/base/more", "/base/more", "")] - [InlineData("http://localhost:8791/base/more", "http://localhost:8791/base/more/something", "/base/more", "/something")] - [InlineData("http://localhost:8791/base/more", "http://localhost:8791/base/more/something/", "/base/more", "/something/")] + [InlineData("/base", "/base", "/base", "")] + [InlineData("/base", "/base/", "/base", "/")] + [InlineData("/base", "/base/something", "/base", "/something")] + [InlineData("/base", "/base/something/", "/base", "/something/")] + [InlineData("/base/more", "/base/more", "/base/more", "")] + [InlineData("/base/more", "/base/more/something", "/base/more", "/something")] + [InlineData("/base/more", "/base/more/something/", "/base/more", "/something/")] [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Test hangs after execution on Mono.")] - public Task RequestPathBaseIsServerPathBase(string registerAddress, string requestAddress, string expectedPathBase, string expectedPath) + public Task RequestPathBaseIsServerPathBase(string registerPathBase, string requestPath, string expectedPathBase, string expectedPath) { - return TestPathBase(registerAddress, requestAddress, expectedPathBase, expectedPath); + return TestPathBase(registerPathBase, requestPath, expectedPathBase, expectedPath); } [ConditionalTheory] - [InlineData("http://localhost:8791", "http://localhost:8791/", "", "/")] - [InlineData("http://localhost:8791", "http://localhost:8791/something", "", "/something")] - [InlineData("http://localhost:8791/", "http://localhost:8791/", "", "/")] - [InlineData("http://localhost:8791/base", "http://localhost:8791/", "", "/")] - [InlineData("http://localhost:8791/base", "http://localhost:8791/something", "", "/something")] - [InlineData("http://localhost:8791/base", "http://localhost:8791/baseandsomething", "", "/baseandsomething")] - [InlineData("http://localhost:8791/base", "http://localhost:8791/ba", "", "/ba")] - [InlineData("http://localhost:8791/base", "http://localhost:8791/ba/se", "", "/ba/se")] + [InlineData("", "/", "", "/")] + [InlineData("", "/something", "", "/something")] + [InlineData("/", "/", "", "/")] + [InlineData("/base", "/", "", "/")] + [InlineData("/base", "/something", "", "/something")] + [InlineData("/base", "/baseandsomething", "", "/baseandsomething")] + [InlineData("/base", "/ba", "", "/ba")] + [InlineData("/base", "/ba/se", "", "/ba/se")] [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Test hangs after execution on Mono.")] - public Task DefaultPathBaseIsEmpty(string registerAddress, string requestAddress, string expectedPathBase, string expectedPath) + public Task DefaultPathBaseIsEmpty(string registerPathBase, string requestPath, string expectedPathBase, string expectedPath) { - return TestPathBase(registerAddress, requestAddress, expectedPathBase, expectedPath); + return TestPathBase(registerPathBase, requestPath, expectedPathBase, expectedPath); } [ConditionalTheory] - [InlineData("http://localhost:8791", "http://localhost:8791/", "", "/")] - [InlineData("http://localhost:8791/", "http://localhost:8791/", "", "/")] - [InlineData("http://localhost:8791/base", "http://localhost:8791/base/", "/base", "/")] - [InlineData("http://localhost:8791/base/", "http://localhost:8791/base", "/base", "")] - [InlineData("http://localhost:8791/base/", "http://localhost:8791/base/", "/base", "/")] + [InlineData("", "/", "", "/")] + [InlineData("/", "/", "", "/")] + [InlineData("/base", "/base/", "/base", "/")] + [InlineData("/base/", "/base", "/base", "")] + [InlineData("/base/", "/base/", "/base", "/")] [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Test hangs after execution on Mono.")] - public Task PathBaseNeverEndsWithSlash(string registerAddress, string requestAddress, string expectedPathBase, string expectedPath) + public Task PathBaseNeverEndsWithSlash(string registerPathBase, string requestPath, string expectedPathBase, string expectedPath) { - return TestPathBase(registerAddress, requestAddress, expectedPathBase, expectedPath); + return TestPathBase(registerPathBase, requestPath, expectedPathBase, expectedPath); } [ConditionalFact] [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Test hangs after execution on Mono.")] public Task PathBaseAndPathPreserveRequestCasing() { - return TestPathBase("http://localhost:8791/base", "http://localhost:8791/Base/Something", "/Base", "/Something"); + return TestPathBase("/base", "/Base/Something", "/Base", "/Something"); } [ConditionalFact] [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Test hangs after execution on Mono.")] public Task PathBaseCanHaveUTF8Characters() { - return TestPathBase("http://localhost:8791/b♫se", "http://localhost:8791/b♫se/something", "/b♫se", "/something"); + return TestPathBase("/b♫se", "/b♫se/something", "/b♫se", "/something"); } - private async Task TestPathBase(string registerAddress, string requestAddress, string expectedPathBase, string expectedPath) + private async Task TestPathBase(string registerPathBase, string requestPath, string expectedPathBase, string expectedPath) { + var port = PortManager.GetPort(); var config = new ConfigurationBuilder().AddInMemoryCollection( new Dictionary { - { "server.urls", registerAddress } + { "server.urls", $"http://localhost:{port}{registerPathBase}" } }).Build(); var builder = new WebHostBuilder() @@ -100,7 +101,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests using (var client = new HttpClient()) { - var response = await client.GetAsync(requestAddress); + var response = await client.GetAsync($"http://localhost:{port}{requestPath}"); response.EnsureSuccessStatusCode(); var responseText = await response.Content.ReadAsStringAsync(); diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/PortManager.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/PortManager.cs new file mode 100644 index 0000000000..55ba3577df --- /dev/null +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/PortManager.cs @@ -0,0 +1,17 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System.Threading; + +namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests +{ + public static class PortManager + { + private static int _nextPort = 8001; + + public static int GetPort() + { + return Interlocked.Increment(ref _nextPort); + } + } +} diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs index 25486918ca..3f9b0870dd 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs @@ -25,10 +25,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Test hangs after execution on Mono.")] public async Task LargeUpload() { + var port = PortManager.GetPort(); var config = new ConfigurationBuilder() .AddInMemoryCollection(new Dictionary { - { "server.urls", "http://localhost:8791/" } + { "server.urls", $"http://localhost:{port}/" } }) .Build(); @@ -69,7 +70,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests bytes[i] = (byte)i; } - var response = await client.PostAsync("http://localhost:8791/", new ByteArrayContent(bytes)); + var response = await client.PostAsync($"http://localhost:{port}/", new ByteArrayContent(bytes)); response.EnsureSuccessStatusCode(); var sizeString = await response.Content.ReadAsStringAsync(); Assert.Equal(sizeString, bytes.Length.ToString(CultureInfo.InvariantCulture)); @@ -78,12 +79,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } [ConditionalTheory] - [InlineData("127.0.0.1", "127.0.0.1", "8792")] - [InlineData("localhost", "127.0.0.1", "8792")] + [InlineData("127.0.0.1", "127.0.0.1")] + [InlineData("localhost", "127.0.0.1")] [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Test hangs after execution on Mono.")] - public Task RemoteIPv4Address(string requestAddress, string expectAddress, string port) + public Task RemoteIPv4Address(string requestAddress, string expectAddress) { - return TestRemoteIPAddress("localhost", requestAddress, expectAddress, port); + return TestRemoteIPAddress("localhost", requestAddress, expectAddress); } [ConditionalFact] @@ -91,16 +92,17 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [IPv6SupportedCondition] public Task RemoteIPv6Address() { - return TestRemoteIPAddress("[::1]", "[::1]", "::1", "8793"); + return TestRemoteIPAddress("[::1]", "[::1]", "::1"); } [ConditionalFact] [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Test hangs after execution on Mono.")] public async Task DoesNotHangOnConnectionCloseRequest() { + var port = PortManager.GetPort(); var config = new ConfigurationBuilder().AddInMemoryCollection( new Dictionary { - { "server.urls", "http://localhost:8794" } + { "server.urls", $"http://localhost:{port}" } }).Build(); var builder = new WebHostBuilder() @@ -123,7 +125,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests client.DefaultRequestHeaders.Connection.Clear(); client.DefaultRequestHeaders.Connection.Add("close"); - var response = await client.GetAsync("http://localhost:8794/"); + var response = await client.GetAsync($"http://localhost:{port}/"); response.EnsureSuccessStatusCode(); } } @@ -132,9 +134,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Test hangs after execution on Mono.")] public async Task RequestPathIsNormalized() { + var port = PortManager.GetPort(); var config = new ConfigurationBuilder().AddInMemoryCollection( new Dictionary { - { "server.urls", "http://localhost:8795/\u0041\u030A" } + { "server.urls", $"http://localhost:{port}/\u0041\u030A" } }).Build(); var builder = new WebHostBuilder() @@ -157,7 +160,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests using (var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)) { - socket.Connect(new IPEndPoint(IPAddress.Loopback, 8795)); + socket.Connect(new IPEndPoint(IPAddress.Loopback, port)); socket.Send(Encoding.ASCII.GetBytes("GET /%41%CC%8A/A/../B/%41%CC%8A HTTP/1.1\r\n\r\n")); socket.Shutdown(SocketShutdown.Send); @@ -179,8 +182,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } } - private async Task TestRemoteIPAddress(string registerAddress, string requestAddress, string expectAddress, string port) + private async Task TestRemoteIPAddress(string registerAddress, string requestAddress, string expectAddress) { + var port = PortManager.GetPort(); var config = new ConfigurationBuilder().AddInMemoryCollection( new Dictionary { { "server.urls", $"http://{registerAddress}:{port}" } diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs index 0708c09388..709eac3440 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs @@ -23,10 +23,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Test hangs after execution on mono.")] public async Task LargeDownload() { + var port = PortManager.GetPort(); var config = new ConfigurationBuilder() .AddInMemoryCollection(new Dictionary { - { "server.urls", "http://localhost:8792/" } + { "server.urls", $"http://localhost:{port}/" } }) .Build(); @@ -58,7 +59,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests using (var client = new HttpClient()) { - var response = await client.GetAsync("http://localhost:8792/"); + var response = await client.GetAsync($"http://localhost:{port}/"); response.EnsureSuccessStatusCode(); var responseBody = await response.Content.ReadAsStreamAsync(); @@ -83,10 +84,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Test hangs after execution on mono.")] public async Task IgnoreNullHeaderValues(string headerName, StringValues headerValue, string expectedValue) { + var port = PortManager.GetPort(); var config = new ConfigurationBuilder() .AddInMemoryCollection(new Dictionary { - { "server.urls", "http://localhost:8793/" } + { "server.urls", $"http://localhost:{port}/" } }) .Build(); @@ -109,7 +111,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests using (var client = new HttpClient()) { - var response = await client.GetAsync("http://localhost:8793/"); + var response = await client.GetAsync($"http://localhost:{port}/"); response.EnsureSuccessStatusCode(); var headers = response.Headers; @@ -131,10 +133,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Test hangs after execution on mono.")] public async Task OnCompleteCalledEvenWhenOnStartingNotCalled() { + var port = PortManager.GetPort(); var config = new ConfigurationBuilder() .AddInMemoryCollection(new Dictionary { - { "server.urls", "http://localhost:8794/" } + { "server.urls", $"http://localhost:{port}/" } }) .Build(); @@ -162,7 +165,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests using (var client = new HttpClient()) { - var response = await client.GetAsync("http://localhost:8794/"); + var response = await client.GetAsync($"http://localhost:{port}/"); Assert.Equal(HttpStatusCode.InternalServerError, response.StatusCode); Assert.False(onStartingCalled); diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ThreadCountTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ThreadCountTests.cs index cd88cf2f8c..437bcbe66c 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ThreadCountTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ThreadCountTests.cs @@ -16,10 +16,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { public async Task ZeroToTenThreads(int threadCount) { + var port = PortManager.GetPort(); var config = new ConfigurationBuilder() .AddInMemoryCollection(new Dictionary { - { "server.urls", "http://localhost:8790/" } + { "server.urls", $"http://localhost:{port}/" } }) .Build(); @@ -46,7 +47,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests var requestTasks = new List>(); for (int i = 0; i < 20; i++) { - var requestTask = client.GetStringAsync("http://localhost:8790/"); + var requestTask = client.GetStringAsync($"http://localhost:{port}/"); requestTasks.Add(requestTask); } diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json index cd1a77f780..1a081b1e3a 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json @@ -4,17 +4,28 @@ "Microsoft.AspNetCore.Http.Abstractions": "1.0.0-*", "Microsoft.AspNetCore.Server.Kestrel": "1.0.0-*", "Microsoft.AspNetCore.Testing": "1.0.0-*", + "Microsoft.NETCore.Platforms": "1.0.1-*", "System.Net.Http": "4.0.1-*", - "xunit.runner.aspnet": "2.0.0-aspnet-*" + "xunit": "2.1.0" }, "frameworks": { - "dnx451": { }, - "dnxcore50": { } + "dnx451": { + "dependencies": { + "xunit.runner.console": "2.1.0" + } + }, + "dnxcore50": { + "dependencies": { + "xunit.runner.aspnet": "2.0.0-aspnet-*" + }, + "imports": "portable-net45+win8" + } }, "compilationOptions": { "allowUnsafe": true }, + "testRunner": "xunit", "commands": { - "test": "xunit.runner.aspnet -parallel none" + "test": "xunit.runner.aspnet" } } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedResponseTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedResponseTests.cs index 0b325f8710..0179a9fb76 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedResponseTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedResponseTests.cs @@ -24,7 +24,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests await response.Body.WriteAsync(Encoding.ASCII.GetBytes("World!"), 0, 6); })) { - using (var connection = new TestConnection()) + using (var connection = new TestConnection(server.Port)) { await connection.SendEnd( "GET / HTTP/1.1", @@ -58,7 +58,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests await response.Body.WriteAsync(Encoding.ASCII.GetBytes("World!"), 0, 6); })) { - using (var connection = new TestConnection()) + using (var connection = new TestConnection(server.Port)) { await connection.SendEnd( "GET / HTTP/1.1", @@ -90,7 +90,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests await response.Body.WriteAsync(new byte[0], 0, 0); })) { - using (var connection = new TestConnection()) + using (var connection = new TestConnection(server.Port)) { await connection.SendEnd( "GET / HTTP/1.1", @@ -119,7 +119,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests throw new Exception(); })) { - using (var connection = new TestConnection()) + using (var connection = new TestConnection(server.Port)) { // SendEnd is not called, so it isn't the client closing the connection. // client closing the connection. @@ -150,7 +150,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests throw new Exception(); })) { - using (var connection = new TestConnection()) + using (var connection = new TestConnection(server.Port)) { // SendEnd is not called, so it isn't the client closing the connection. await connection.Send( @@ -186,7 +186,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests await response.Body.WriteAsync(Encoding.ASCII.GetBytes("World!"), 0, 6); })) { - using (var connection = new TestConnection()) + using (var connection = new TestConnection(server.Port)) { await connection.SendEnd( "GET / HTTP/1.1", diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionFilterTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionFilterTests.cs index 1eef8a6c5c..353d998e5d 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionFilterTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionFilterTests.cs @@ -44,7 +44,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests using (var server = new TestServer(App, serviceContext)) { - using (var connection = new TestConnection()) + using (var connection = new TestConnection(server.Port)) { // "?" changes to "!" await connection.SendEnd(sendString); @@ -69,7 +69,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests using (var server = new TestServer(App, serviceContext)) { - using (var connection = new TestConnection()) + using (var connection = new TestConnection(server.Port)) { await connection.SendEnd( "POST / HTTP/1.0", @@ -94,7 +94,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests using (var server = new TestServer(App, serviceContext)) { - using (var connection = new TestConnection()) + using (var connection = new TestConnection(server.Port)) { try { diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs index 95e9d304bb..42315796d5 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs @@ -98,7 +98,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests testContext.App = App; var engine = new KestrelEngine(testContext); engine.Start(1); - var address = ServerAddress.FromUrl("http://localhost:54321/"); + var address = ServerAddress.FromUrl($"http://localhost:{TestServer.GetNextPort()}/"); var started = engine.CreateServer(address); started.Dispose(); engine.Dispose(); @@ -109,15 +109,16 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Test hangs after execution on Mono.")] public void ConnectionCanReadAndWrite(TestServiceContext testContext) { + var port = TestServer.GetNextPort(); testContext.App = App; var engine = new KestrelEngine(testContext); engine.Start(1); - var address = ServerAddress.FromUrl("http://localhost:54321/"); + var address = ServerAddress.FromUrl($"http://localhost:{port}/"); var started = engine.CreateServer(address); Console.WriteLine("Started"); var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); - socket.Connect(new IPEndPoint(IPAddress.Loopback, 54321)); + socket.Connect(new IPEndPoint(IPAddress.Loopback, port)); socket.Send(Encoding.ASCII.GetBytes("POST / HTTP/1.0\r\n\r\nHello World")); socket.Shutdown(SocketShutdown.Send); var buffer = new byte[8192]; @@ -139,7 +140,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { using (var server = new TestServer(App, testContext)) { - using (var connection = new TestConnection()) + using (var connection = new TestConnection(server.Port)) { await connection.SendEnd( "POST / HTTP/1.0", @@ -161,7 +162,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { using (var server = new TestServer(AppChunked, testContext)) { - using (var connection = new TestConnection()) + using (var connection = new TestConnection(server.Port)) { await connection.SendEnd( "GET / HTTP/1.1", @@ -207,7 +208,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests testContext)) { - using (var connection = new TestConnection()) + using (var connection = new TestConnection(server.Port)) { var requestData = Enumerable.Repeat("GET / HTTP/1.1\r\n", loopCount) @@ -250,7 +251,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests testContext)) { - using (var connection = new TestConnection()) + using (var connection = new TestConnection(server.Port)) { var requestData = Enumerable.Repeat("GET / HTTP/1.1\r\n", loopCount) @@ -276,7 +277,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { using (var server = new TestServer(App, testContext)) { - using (var connection = new TestConnection()) + using (var connection = new TestConnection(server.Port)) { await connection.Send( "POST / HTTP/1.0", @@ -298,7 +299,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { using (var server = new TestServer(App, testContext)) { - using (var connection = new TestConnection()) + using (var connection = new TestConnection(server.Port)) { await connection.Send( "POST / HTTP/1.0", @@ -320,7 +321,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { using (var server = new TestServer(AppChunked, testContext)) { - using (var connection = new TestConnection()) + using (var connection = new TestConnection(server.Port)) { await connection.SendEnd( "GET / HTTP/1.0", @@ -350,7 +351,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { using (var server = new TestServer(App, testContext)) { - using (var connection = new TestConnection()) + using (var connection = new TestConnection(server.Port)) { await connection.SendEnd( "GET / HTTP/1.0", @@ -381,7 +382,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { using (var server = new TestServer(AppChunked, testContext)) { - using (var connection = new TestConnection()) + using (var connection = new TestConnection(server.Port)) { await connection.SendEnd( "POST / HTTP/1.0", @@ -413,7 +414,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { using (var server = new TestServer(AppChunked, testContext)) { - using (var connection = new TestConnection()) + using (var connection = new TestConnection(server.Port)) { await connection.SendEnd( "POST / HTTP/1.0", @@ -446,7 +447,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { using (var server = new TestServer(AppChunked, testContext)) { - using (var connection = new TestConnection()) + using (var connection = new TestConnection(server.Port)) { await connection.Send( "POST / HTTP/1.1", @@ -474,11 +475,12 @@ namespace Microsoft.AspNetCore.Server.KestrelTests using (var server = new TestServer(App, testContext)) { var socket = new Socket(SocketType.Stream, ProtocolType.Tcp); - socket.Connect(IPAddress.Loopback, 54321); + socket.Connect(IPAddress.Loopback, server.Port); + await Task.Delay(200); socket.Dispose(); await Task.Delay(200); - using (var connection = new TestConnection()) + using (var connection = new TestConnection(server.Port)) { await connection.SendEnd( "GET / HTTP/1.0", @@ -497,7 +499,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { using (var server = new TestServer(EmptyApp, testContext)) { - using (var connection = new TestConnection()) + using (var connection = new TestConnection(server.Port)) { await connection.SendEnd( "GET / HTTP/1.1", @@ -526,7 +528,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { using (var server = new TestServer(EmptyApp, testContext)) { - using (var connection = new TestConnection()) + using (var connection = new TestConnection(server.Port)) { await connection.SendEnd( "GET / HTTP/1.1", @@ -540,7 +542,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests ""); } - using (var connection = new TestConnection()) + using (var connection = new TestConnection(server.Port)) { await connection.SendEnd( "GET / HTTP/1.0", @@ -561,7 +563,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { using (var server = new TestServer(EmptyApp, testContext)) { - using (var connection = new TestConnection()) + using (var connection = new TestConnection(server.Port)) { await connection.SendEnd( "HEAD / HTTP/1.1", @@ -593,7 +595,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } }, testContext)) { - using (var connection = new TestConnection()) + using (var connection = new TestConnection(server.Port)) { await connection.SendEnd( "POST / HTTP/1.1", @@ -654,7 +656,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests throw new Exception(); }, testContext)) { - using (var connection = new TestConnection()) + using (var connection = new TestConnection(server.Port)) { await connection.SendEnd( "GET / HTTP/1.1", @@ -713,7 +715,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests throw new Exception(); }, testContext)) { - using (var connection = new TestConnection()) + using (var connection = new TestConnection(server.Port)) { await connection.Send( "GET / HTTP/1.1", @@ -756,7 +758,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests throw new Exception(); }, testContext)) { - using (var connection = new TestConnection()) + using (var connection = new TestConnection(server.Port)) { await connection.Send( "GET / HTTP/1.1", @@ -781,7 +783,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { using (var server = new TestServer(AppChunked, testContext)) { - using (var connection = new TestConnection()) + using (var connection = new TestConnection(server.Port)) { await connection.SendEnd( "GET / HTTP/1.1", @@ -809,14 +811,14 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { using (var server = new TestServer(AppChunked, testContext)) { - using (var connection = new TestConnection()) + using (var connection = new TestConnection(server.Port)) { await connection.SendEnd( "GET /"); await connection.ReceiveEnd(); } - using (var connection = new TestConnection()) + using (var connection = new TestConnection(server.Port)) { await connection.SendEnd( "GET / HTTP/1.1", @@ -829,7 +831,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests ""); } - using (var connection = new TestConnection()) + using (var connection = new TestConnection(server.Port)) { await connection.SendEnd( "GET / HTTP/1.1", @@ -884,7 +886,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests failedWriteCount++; }, testContext)) { - using (var connection = new TestConnection()) + using (var connection = new TestConnection(server.Port)) { await connection.SendEnd( "GET / HTTP/1.1", @@ -950,7 +952,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests await response.Body.WriteAsync(Encoding.ASCII.GetBytes("Hello World"), 0, 11); }, testContext)) { - using (var connection = new TestConnection()) + using (var connection = new TestConnection(server.Port)) { await connection.Send( "GET / HTTP/1.1", @@ -988,7 +990,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests await response.Body.WriteAsync(Encoding.ASCII.GetBytes("Hello World"), 0, 11); }, testContext)) { - using (var connection = new TestConnection()) + using (var connection = new TestConnection(server.Port)) { await connection.SendEnd( "POST / HTTP/1.1", @@ -1063,7 +1065,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } }, testContext)) { - using (var connection = new TestConnection()) + using (var connection = new TestConnection(server.Port)) { // Never send the body so CopyToAsync always fails. await connection.Send( @@ -1134,7 +1136,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests writeTcs.SetException(new Exception("This shouldn't be reached.")); }, testContext)) { - using (var connection = new TestConnection()) + using (var connection = new TestConnection(server.Port)) { await connection.Send( "POST / HTTP/1.1", diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/HttpsConnectionFilterTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/HttpsConnectionFilterTests.cs index 7749164bd2..e3bed702bc 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/HttpsConnectionFilterTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/HttpsConnectionFilterTests.cs @@ -58,8 +58,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var handler = new WinHttpHandler(); handler.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true; #endif - - var serverAddress = "https://localhost:54321/"; + var serverAddress = $"https://localhost:{TestServer.GetNextPort()}/"; var serviceContext = new TestServiceContext() { ConnectionFilter = new HttpsConnectionFilter( @@ -108,7 +107,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests handler.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true; #endif - var serverAddress = "https://localhost:54321/"; + var serverAddress = $"https://localhost:{TestServer.GetNextPort()}/"; var serviceContext = new TestServiceContext() { ConnectionFilter = new HttpsConnectionFilter( @@ -157,7 +156,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests handler.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true; #endif - var serverAddress = "https://localhost:54321/"; + var serverAddress = $"https://localhost:{TestServer.GetNextPort()}/"; var serviceContext = new TestServiceContext() { ConnectionFilter = new HttpsConnectionFilter( @@ -209,7 +208,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests ServicePointManager.ServerCertificateValidationCallback += validationCallback; #endif - var serverAddress = "https://localhost:54321/"; + var serverAddress = $"https://localhost:{TestServer.GetNextPort()}/"; var serviceContext = new TestServiceContext() { ConnectionFilter = new HttpsConnectionFilter( @@ -238,7 +237,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests // of the certificate authorities sent by the server in the SSL handshake. using (var client = new TcpClient()) { - await client.ConnectAsync("127.0.0.1", 54321); + await client.ConnectAsync("127.0.0.1", server.Port); SslStream stream = new SslStream(client.GetStream(), false, (sender, certificate, chain, errors) => true, (sender, host, certificates, certificate, issuers) => new X509Certificate2(@"TestResources/testCert.pfx", "testPassword")); @@ -281,7 +280,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests handler.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true; #endif - var serverAddress = "https://localhost:54321/"; + var serverAddress = $"https://localhost:{TestServer.GetNextPort()}/"; var serviceContext = new TestServiceContext() { ConnectionFilter = new HttpsConnectionFilter( diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/NetworkingTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/NetworkingTests.cs index 86b2f8fe5a..642d4c7729 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/NetworkingTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/NetworkingTests.cs @@ -76,7 +76,8 @@ namespace Microsoft.AspNetCore.Server.KestrelTests loop.Init(_uv); var tcp = new UvTcpHandle(_logger); tcp.Init(loop); - var address = ServerAddress.FromUrl("http://localhost:54321/"); + var port = TestServer.GetNextPort(); + var address = ServerAddress.FromUrl($"http://localhost:{port}/"); tcp.Bind(address); tcp.Listen(10, (stream, status, error, state) => { @@ -96,11 +97,11 @@ namespace Microsoft.AspNetCore.Server.KestrelTests await Task.Factory.FromAsync( socket.BeginConnect, socket.EndConnect, - new IPEndPoint(IPAddress.Loopback, 54321), + new IPEndPoint(IPAddress.Loopback, port), null, TaskCreationOptions.None); #else - await socket.ConnectAsync(new IPEndPoint(IPAddress.Loopback, 54321)); + await socket.ConnectAsync(new IPEndPoint(IPAddress.Loopback, port)); #endif socket.Dispose(); }); @@ -117,7 +118,8 @@ namespace Microsoft.AspNetCore.Server.KestrelTests loop.Init(_uv); var tcp = new UvTcpHandle(_logger); tcp.Init(loop); - var address = ServerAddress.FromUrl("http://localhost:54321/"); + var port = TestServer.GetNextPort(); + var address = ServerAddress.FromUrl($"http://localhost:{port}/"); tcp.Bind(address); tcp.Listen(10, (_, status, error, state) => { @@ -149,7 +151,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests await Task.Factory.FromAsync( socket.BeginConnect, socket.EndConnect, - new IPEndPoint(IPAddress.Loopback, 54321), + new IPEndPoint(IPAddress.Loopback, port), null, TaskCreationOptions.None); await Task.Factory.FromAsync( @@ -160,7 +162,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests null, TaskCreationOptions.None); #else - await socket.ConnectAsync(new IPEndPoint(IPAddress.Loopback, 54321)); + await socket.ConnectAsync(new IPEndPoint(IPAddress.Loopback, port)); await socket.SendAsync(new[] { new ArraySegment(new byte[] { 1, 2, 3, 4, 5 }) }, SocketFlags.None); #endif @@ -178,7 +180,8 @@ namespace Microsoft.AspNetCore.Server.KestrelTests loop.Init(_uv); var tcp = new UvTcpHandle(_logger); tcp.Init(loop); - var address = ServerAddress.FromUrl("http://localhost:54321/"); + var port = TestServer.GetNextPort(); + var address = ServerAddress.FromUrl($"http://localhost:{port}/"); tcp.Bind(address); tcp.Listen(10, (_, status, error, state) => { @@ -235,7 +238,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests await Task.Factory.FromAsync( socket.BeginConnect, socket.EndConnect, - new IPEndPoint(IPAddress.Loopback, 54321), + new IPEndPoint(IPAddress.Loopback, port), null, TaskCreationOptions.None); await Task.Factory.FromAsync( @@ -246,7 +249,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests null, TaskCreationOptions.None); #else - await socket.ConnectAsync(new IPEndPoint(IPAddress.Loopback, 54321)); + await socket.ConnectAsync(new IPEndPoint(IPAddress.Loopback, port)); await socket.SendAsync(new[] { new ArraySegment(new byte[] { 1, 2, 3, 4, 5 }) }, SocketFlags.None); #endif diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/Program.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/Program.cs deleted file mode 100644 index 4f4b5827c6..0000000000 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/Program.cs +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using Microsoft.Extensions.PlatformAbstractions; - -namespace Microsoft.AspNetCore.Server.KestrelTests -{ - /// - /// Summary description for Program - /// - public class Program - { - private readonly IApplicationEnvironment env; - private readonly IServiceProvider sp; - private readonly ILibraryManager _libraryManager; - - public Program( - IApplicationEnvironment env, - IServiceProvider sp, - ILibraryManager libraryManager) - { - this.env = env; - this.sp = sp; - _libraryManager = libraryManager; - } - - public int Main() - { - return Xunit.Runner.Dnx.Program.Main(new string[] - { - "-class", - typeof(MultipleLoopTests).FullName - }); - } - } -} \ No newline at end of file diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestConnection.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/TestConnection.cs index b7a2a625cb..5b6e857fd0 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/TestConnection.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/TestConnection.cs @@ -21,15 +21,15 @@ namespace Microsoft.AspNetCore.Server.KestrelTests private NetworkStream _stream; private StreamReader _reader; - public TestConnection() + public TestConnection(int port) { - Create(); + Create(port); } - public void Create() + public void Create(int port) { _socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); - _socket.Connect(new IPEndPoint(IPAddress.Loopback, 54321)); + _socket.Connect(new IPEndPoint(IPAddress.Loopback, port)); _stream = new NetworkStream(_socket, false); _reader = new StreamReader(_stream, Encoding.ASCII); diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestServer.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/TestServer.cs index 72fbf28f47..1c0ff5dd1e 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/TestServer.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/TestServer.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Threading; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Server.Kestrel; using Microsoft.AspNetCore.Server.Kestrel.Http; @@ -13,8 +14,11 @@ namespace Microsoft.AspNetCore.Server.KestrelTests /// public class TestServer : IDisposable { + private static int _nextPort = 9001; + private KestrelEngine _engine; private IDisposable _server; + ServerAddress _address; public TestServer(RequestDelegate app) : this(app, new TestServiceContext()) @@ -22,15 +26,17 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } public TestServer(RequestDelegate app, ServiceContext context) - : this(app, context, "http://localhost:54321/") + : this(app, context, $"http://localhost:{GetNextPort()}/") { } + + public int Port => _address.Port; + public TestServer(RequestDelegate app, ServiceContext context, string serverAddress) { Create(app, context, serverAddress); } - public void Create(RequestDelegate app, ServiceContext context, string serverAddress) { context.FrameFactory = (connectionContext, remoteEP, localEP, prepareRequest) => @@ -39,8 +45,8 @@ namespace Microsoft.AspNetCore.Server.KestrelTests }; _engine = new KestrelEngine(context); _engine.Start(1); - _server = _engine.CreateServer( - ServerAddress.FromUrl(serverAddress)); + _address = ServerAddress.FromUrl(serverAddress); + _server = _engine.CreateServer(_address); } public void Dispose() @@ -48,5 +54,10 @@ namespace Microsoft.AspNetCore.Server.KestrelTests _server.Dispose(); _engine.Dispose(); } + + public static int GetNextPort() + { + return Interlocked.Increment(ref _nextPort); + } } } \ No newline at end of file diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/project.json b/test/Microsoft.AspNetCore.Server.KestrelTests/project.json index 3abc3b112b..e87ccc77ff 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/project.json +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/project.json @@ -1,14 +1,19 @@ { "version": "1.0.0-*", "dependencies": { - "xunit.runner.aspnet": "2.0.0-aspnet-*", "Microsoft.AspNetCore.Server.Kestrel": "1.0.0-*", "Microsoft.AspNetCore.Server.Kestrel.Https": "1.0.0-*", "Microsoft.AspNetCore.Testing": "1.0.0-*", - "System.Net.Http": "4.0.1-*" + "Microsoft.NETCore.Platforms": "1.0.1-*", + "System.Net.Http": "4.0.1-*", + "xunit": "2.1.0" }, "frameworks": { - "dnx451": { }, + "dnx451": { + "dependencies": { + "xunit.runner.console": "2.1.0" + } + }, "dnxcore50": { "dependencies": { "System.Diagnostics.TraceSource": "4.0.0-*", @@ -16,16 +21,21 @@ "System.IO": "4.1.0-*", "System.Net.Http.WinHttpHandler": "4.0.0-*", "System.Net.Sockets": "4.1.0-*", - "System.Runtime.Handles": "4.0.1-*" - } + "System.Runtime.Handles": "4.0.1-*", + "xunit.runner.aspnet": "2.0.0-aspnet-*" + }, + "imports": "portable-net45+win8" } }, "compilationOptions": { "allowUnsafe": true, "keyFile": "../../tools/Key.snk" }, + "testRunner": "xunit", "commands": { - "run": "Microsoft.AspNetCore.Server.KestrelTests", - "test": "xunit.runner.aspnet -parallel none" - } + "test": "xunit.runner.aspnet" + }, + "content": [ + "TestResources/testCert.pfx" + ] } diff --git a/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/FrameFeatureCollection.cs b/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/FrameFeatureCollection.cs index a84d3a9c59..d4504cc9ca 100644 --- a/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/FrameFeatureCollection.cs +++ b/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/FrameFeatureCollection.cs @@ -2,7 +2,6 @@ using System; using System.Collections.Generic; using System.Linq; using Microsoft.AspNetCore.Http.Features; -using Microsoft.Dnx.Compilation.CSharp; using Microsoft.AspNetCore.Http.Features.Internal; using Microsoft.AspNetCore.Http.Features.Authentication; @@ -10,19 +9,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.GeneratedCode { // This project can output the Class library as a NuGet Package. // To enable this option, right-click on the project and select the Properties menu item. In the Build tab select "Produce outputs on build". - public class FrameFeatureCollection : ICompileModule + public class FrameFeatureCollection { static string Each(IEnumerable values, Func formatter) { return values.Select(formatter).Aggregate((a, b) => a + b); } - public virtual void BeforeCompile(BeforeCompileContext context) - { - var syntaxTree = Microsoft.CodeAnalysis.CSharp.CSharpSyntaxTree.ParseText(GeneratedFile()); - context.Compilation = context.Compilation.AddSyntaxTrees(syntaxTree); - } - public static string GeneratedFile() { var alwaysFeatures = new[] @@ -129,9 +122,5 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http }} "; } - - public virtual void AfterCompile(AfterCompileContext context) - { - } } } diff --git a/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/KnownHeaders.cs b/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/KnownHeaders.cs index 359baa98c3..32a5f057e7 100644 --- a/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/KnownHeaders.cs +++ b/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/KnownHeaders.cs @@ -1,14 +1,13 @@ using System; using System.Collections.Generic; using System.Linq; -using Microsoft.Dnx.Compilation.CSharp; using System.Text; namespace Microsoft.AspNetCore.Server.Kestrel.GeneratedCode { // This project can output the Class library as a NuGet Package. // To enable this option, right-click on the project and select the Properties menu item. In the Build tab select "Produce outputs on build". - public class KnownHeaders : ICompileModule + public class KnownHeaders { static string Each(IEnumerable values, Func formatter) { @@ -73,11 +72,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.GeneratedCode return $"(({array}[{offset / count}] & {mask}{suffix}) == {comp}{suffix})"; } } - public virtual void BeforeCompile(BeforeCompileContext context) - { - var syntaxTree = Microsoft.CodeAnalysis.CSharp.CSharpSyntaxTree.ParseText(GeneratedFile()); - context.Compilation = context.Compilation.AddSyntaxTrees(syntaxTree); - } + public static string GeneratedFile() { var commonHeaders = new[] @@ -488,8 +483,5 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http }} ")}}}"; } - public virtual void AfterCompile(AfterCompileContext context) - { - } } } \ No newline at end of file diff --git a/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/Program.cs b/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/Program.cs index b146bb58d1..f0a0814b16 100644 --- a/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/Program.cs +++ b/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/Program.cs @@ -5,7 +5,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.GeneratedCode { public class Program { - public int Main(string[] args) + public static int Main(string[] args) { var text0 = KnownHeaders.GeneratedFile(); var text1 = FrameFeatureCollection.GeneratedFile(); diff --git a/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/project.json b/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/project.json index 67117cd620..cbc156008c 100644 --- a/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/project.json +++ b/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/project.json @@ -1,28 +1,24 @@ { "version": "1.0.0-*", - + "compilationOptions": { + "emitEntryPoint": true + }, "dependencies": { - "Microsoft.Dnx.Compilation.CSharp.Abstractions": "1.0.0-*", "Microsoft.AspNetCore.Http.Features": "1.0.0-*", "Microsoft.AspNetCore.Hosting": "1.0.0-*" }, - - "commands": { - "run": "Microsoft.AspNetCore.Server.Kestrel.GeneratedCode" - }, - "frameworks": { + "dnxcore50": { + "dependencies": { + "NETStandard.Library": "1.0.0-*" + } + }, "dnx451": { "frameworkAssemblies": { "System.Runtime": "", "System.Text.Encoding": "", "System.Threading.Tasks": "" } - }, - "dnxcore50": { - "dependencies": { - "System.Console": "4.0.0-*" - } } } } diff --git a/tools/Microsoft.AspNetCore.Server.Kestrel.LibuvCopier/Program.cs b/tools/Microsoft.AspNetCore.Server.Kestrel.LibuvCopier/Program.cs index 8ed1e4df1a..b7a95bb822 100644 --- a/tools/Microsoft.AspNetCore.Server.Kestrel.LibuvCopier/Program.cs +++ b/tools/Microsoft.AspNetCore.Server.Kestrel.LibuvCopier/Program.cs @@ -1,18 +1,23 @@ using System; using System.IO; using System.Linq; +using Microsoft.Extensions.PlatformAbstractions; using Newtonsoft.Json.Linq; namespace Microsoft.AspNetCore.Server.Kestrel.LibuvCopier { public class Program { - public void Main(string[] args) + public static void Main(string[] args) { try { - var packagesFolder = Environment.GetEnvironmentVariable("DNX_PACKAGES") ?? - Path.Combine(GetHome(), ".nuget", "packages"); + var packagesFolder = Environment.GetEnvironmentVariable("NUGET_PACKAGES"); + + if (string.IsNullOrEmpty(packagesFolder)) + { + packagesFolder = Path.Combine(GetHome(), ".nuget", "packages"); + } packagesFolder = Environment.ExpandEnvironmentVariables(packagesFolder); @@ -39,12 +44,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.LibuvCopier } // Copied from DNX's DnuEnvironment.cs - private string GetHome() + private static string GetHome() { #if DNX451 return Environment.GetFolderPath(Environment.SpecialFolder.UserProfile); #else - var runtimeEnv = Extensions.PlatformAbstractions.PlatformServices.Default.Runtime; + var runtimeEnv = PlatformServices.Default.Runtime; if (runtimeEnv.OperatingSystem == "Windows") { return Environment.GetEnvironmentVariable("USERPROFILE") ?? diff --git a/tools/Microsoft.AspNetCore.Server.Kestrel.LibuvCopier/project.json b/tools/Microsoft.AspNetCore.Server.Kestrel.LibuvCopier/project.json index 76f2bc1459..bc49d7a5ce 100644 --- a/tools/Microsoft.AspNetCore.Server.Kestrel.LibuvCopier/project.json +++ b/tools/Microsoft.AspNetCore.Server.Kestrel.LibuvCopier/project.json @@ -1,31 +1,19 @@ { "version": "1.0.0-*", - "description": "Microsoft.AspNetCore.Server.Kestrel.LibuvCopier Console Application", - "authors": [ "pawelka" ], - "tags": [ "" ], - "projectUrl": "", - "licenseUrl": "", - + "compilationOptions": { + "emitEntryPoint": true + }, "dependencies": { "Microsoft.Extensions.PlatformAbstractions": "1.0.0-*", "Newtonsoft.Json": "7.0.1" }, - - "commands": { - "Microsoft.AspNetCore.Server.Kestrel.LibuvCopier": "Microsoft.AspNetCore.Server.Kestrel.LibuvCopier" - }, - "frameworks": { - "dnx451": { }, "dnxcore50": { "dependencies": { - "Microsoft.CSharp": "4.0.1-*", - "System.Collections": "4.0.11-*", - "System.Console": "4.0.0-*", - "System.Linq": "4.0.1-*", - "System.Threading": "4.0.11-*", - "System.IO.FileSystem": "4.0.1-*" + "NETStandard.Library": "1.0.0-*", + "System.Dynamic.Runtime": "4.0.11-*" } - } + }, + "dnx451": { } } } diff --git a/tools/Microsoft.StandardsPolice/Microsoft.StandardsPolice.xproj b/tools/Microsoft.StandardsPolice/Microsoft.StandardsPolice.xproj deleted file mode 100644 index 83282b2e37..0000000000 --- a/tools/Microsoft.StandardsPolice/Microsoft.StandardsPolice.xproj +++ /dev/null @@ -1,20 +0,0 @@ - - - - 14.0 - $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) - - - - - 82295647-7c1c-4671-bab6-0fef58f949ec - Microsoft.StandardsPolice - ..\..\artifacts\obj\$(MSBuildProjectName) - ..\..\artifacts\bin\$(MSBuildProjectName)\ - - - - 2.0 - - - diff --git a/tools/Microsoft.StandardsPolice/Program.cs b/tools/Microsoft.StandardsPolice/Program.cs deleted file mode 100644 index 0967dbc35c..0000000000 --- a/tools/Microsoft.StandardsPolice/Program.cs +++ /dev/null @@ -1,49 +0,0 @@ -using Microsoft.CodeAnalysis; -using Microsoft.CodeAnalysis.CSharp; -using Microsoft.CodeAnalysis.CSharp.Syntax; -using System; -using System.Collections.Generic; -using System.Linq; - -namespace Microsoft.StandardsPolice -{ - public class Program - { - public int Main(string[] args) - { - var tree = CSharpSyntaxTree.ParseText(@" -public class Hello { public Hello(int foo){}; protected int _foo; int _bar; } -public class World { public World(int foo){}; protected int _foo; int _bar; static int _quux = 4; enum Blah{} class Clazz{} } -"); - var diags = new List(); - - var comp = CSharpCompilation.Create("Comp", new[] { tree }); - - StandardsPoliceCompileModule.ScanCompilation(diags, comp); - - var hello = comp.GetTypeByMetadataName("Hello"); - foreach (var f in hello.GetMembers().OfType()) - { - var syntax = f.DeclaringSyntaxReferences.Single().GetSyntax(); - Console.WriteLine($"{syntax.ToFullString()}"); - - var fds = syntax.Parent.Parent as FieldDeclarationSyntax; - var toks = syntax.DescendantTokens().ToArray(); - var nods = syntax.DescendantNodesAndSelf().ToArray(); - var mods = fds.Modifiers; - - foreach (var mod in fds.Modifiers) - { - Console.WriteLine($"{mod.Kind()} {mod.ToFullString()}"); - } - var locs = f.Locations.ToArray(); - } - - foreach(var d in diags) - { - Console.WriteLine(d); - } - return 0; - } - } -} diff --git a/tools/Microsoft.StandardsPolice/StandardsPoliceCompileModule.cs b/tools/Microsoft.StandardsPolice/StandardsPoliceCompileModule.cs deleted file mode 100644 index 5e3e5dfa06..0000000000 --- a/tools/Microsoft.StandardsPolice/StandardsPoliceCompileModule.cs +++ /dev/null @@ -1,292 +0,0 @@ -using Microsoft.Dnx.Compilation.CSharp; -using System.Collections.Generic; -using System.Linq; -using Microsoft.CodeAnalysis; -using Microsoft.CodeAnalysis.CSharp.Syntax; -using Microsoft.CodeAnalysis.CSharp; -using System; - -namespace Microsoft.StandardsPolice -{ - public class StandardsPoliceCompileModule : ICompileModule - { - public void BeforeCompile(BeforeCompileContext context) - { - ScanCompilation(context.Diagnostics, context.Compilation); - } - - internal static void ScanCompilation(IList diagnostics, CSharpCompilation compilation) - { - ScanNamespace(diagnostics, compilation.GlobalNamespace); - - foreach (var st in compilation.SyntaxTrees) - { - if (!st.FilePath.EndsWith(".Generated.cs")) - { - ScanSyntaxTree(diagnostics, st); - } - } - } - - internal static void ScanSyntaxTree(IList diagnostics, SyntaxTree syntaxTree) - { - var root = syntaxTree.GetRoot(); - - var typeDeclarations = root.DescendantNodes(descendIntoChildren: node => !(node is TypeDeclarationSyntax)) - .OfType() - .ToArray(); - - if (typeDeclarations.Length > 1) - { - foreach (var typeDeclaration in typeDeclarations) - { - diagnostics.Add(Diagnostic.Create( - "SP1002", "StandardsPolice", "more than one type per file", - DiagnosticSeverity.Warning, - DiagnosticSeverity.Warning, - false, - 3, - location: typeDeclaration.GetLocation())); - } - } - - var usingDirectives = root.DescendantNodes(descendIntoChildren: node => !(node is TypeDeclarationSyntax)) - .OfType() - .ToArray(); - - var priorUsingDirective = default(UsingDirectiveSyntax); - foreach (var usingDirective in usingDirectives) - { - var acceptableOrder = false; - if (!acceptableOrder && priorUsingDirective == null) - { - acceptableOrder = true; - } - if (!acceptableOrder && string.Compare(priorUsingDirective.Name.ToString(), usingDirective.Name.ToString(), StringComparison.OrdinalIgnoreCase) < 0) - { - acceptableOrder = true; - } - if (!acceptableOrder && priorUsingDirective.Name.ToString() == "System") - { - acceptableOrder = true; - } - if (!acceptableOrder && - priorUsingDirective.Name.ToString().StartsWith("System") && - !usingDirective.Name.ToString().StartsWith("System")) - { - acceptableOrder = true; - } - if (!acceptableOrder) - { - diagnostics.Add(Diagnostic.Create( - "SP1004", "StandardsPolice", "namespaces not alphabetized", - DiagnosticSeverity.Warning, - DiagnosticSeverity.Warning, - false, - 3, - location: usingDirective.GetLocation())); - } - priorUsingDirective = usingDirective; - } - } - - private static void ScanNamespace(IList diagnostics, INamespaceSymbol namespaceSymbol) - { - foreach (var member in namespaceSymbol.GetNamespaceMembers()) - { - ScanNamespace(diagnostics, member); - } - foreach (var member in namespaceSymbol.GetTypeMembers()) - { - ScanType(diagnostics, member); - } - } - - private static void ScanType(IList diagnostics, INamedTypeSymbol typeSymbol) - { - if (typeSymbol.Locations.Any(location => location.IsInSource)) - { - RuleFieldPrivateKeyword(diagnostics, typeSymbol); - RuleMembersAreInCorrectOrder(diagnostics, typeSymbol, MapClassMembers); - } - - foreach (var member in typeSymbol.GetTypeMembers()) - { - ScanType(diagnostics, member); - } - } - - - private static void RuleFieldPrivateKeyword(IList diagnostics, INamedTypeSymbol typeSymbol) - { - foreach (var member in typeSymbol.GetMembers().OfType()) - { - if (member.DeclaredAccessibility != Accessibility.Private) - { - continue; - } - - foreach (var syntaxReference in member.DeclaringSyntaxReferences) - { - var fieldHasPrivateKeyword = false; - var syntax = syntaxReference.GetSyntax(); - var fds = syntax?.Parent?.Parent as FieldDeclarationSyntax; - if (fds == null) - { - continue; - } - foreach (var mod in fds.Modifiers) - { - if (mod.IsKind(CodeAnalysis.CSharp.SyntaxKind.PrivateKeyword)) - { - fieldHasPrivateKeyword = true; - } - } - if (!fieldHasPrivateKeyword) - { - diagnostics.Add(Diagnostic.Create( - "SP1001", "StandardsPolice", "private keyword missing", - DiagnosticSeverity.Warning, - DiagnosticSeverity.Warning, - false, - 3, - location: member.Locations.SingleOrDefault())); - } - } - } - } - - private static void RuleMembersAreInCorrectOrder(IList diagnostics, INamedTypeSymbol typeSymbol, Func mapZone) - { - if (typeSymbol.Locations.Length >= 2 || typeSymbol.Name == "Libuv") - { - // Don't apply to partial classes. All members are enumerated, but are not merged by zone order. - return; - } - - var currentZone = ClassZone.BeforeStart; - var currentZoneExample = default(ISymbol); - foreach (var member in typeSymbol.GetMembers()) - { - var memberZone = mapZone(member); - if (memberZone == ClassZone.Ignored) - { - continue; - } - if (currentZone <= memberZone) - { - currentZone = memberZone; - currentZoneExample = member; - } - if (memberZone >= ClassZone.OtherThings) - { - continue; - } - if (memberZone < currentZone) - { - if (member.Locations.Count() == 1) - { - diagnostics.Add(Diagnostic.Create( - "SP1003", "StandardsPolice", $"{memberZone} like {typeSymbol.Name}::{member.Name} shouldn't be after {currentZone} like {currentZoneExample.Name}", - DiagnosticSeverity.Warning, - DiagnosticSeverity.Warning, - false, - 3, - location: member.Locations.Single(), - additionalLocations: currentZoneExample.Locations)); - } - } - } - currentZone = ClassZone.AfterEnd; - currentZoneExample = null; - foreach (var member in typeSymbol.GetMembers().Reverse()) - { - var memberZone = mapZone(member); - if (memberZone == ClassZone.Ignored) - { - continue; - } - if (currentZone >= memberZone) - { - currentZone = memberZone; - currentZoneExample = member; - } - if (memberZone <= ClassZone.OtherThings) - { - continue; - } - if (memberZone > currentZone) - { - if (member.Locations.Count() == 1) - { - diagnostics.Add(Diagnostic.Create( - "SP1003", "StandardsPolice", $"{memberZone} like {typeSymbol.Name}::{member.Name} shouldn't be before {currentZone} like {currentZoneExample.Name}", - DiagnosticSeverity.Warning, - DiagnosticSeverity.Warning, - false, - 3, - location: member.Locations.Single(), - additionalLocations: currentZoneExample.Locations)); - } - } - } - } - - private static ClassZone MapClassMembers(ISymbol member) - { - if (member.IsImplicitlyDeclared) - { - return ClassZone.Ignored; - } - if (member.Kind == SymbolKind.Field) - { - return ClassZone.Fields; - } - if (member.Kind == SymbolKind.Method) - { - var method = (IMethodSymbol)member; - if (method.MethodKind == MethodKind.Constructor || - method.MethodKind == MethodKind.StaticConstructor) - { - return ClassZone.Constructors; - } - if (method.MethodKind == MethodKind.PropertyGet || - method.MethodKind == MethodKind.PropertySet) - { - return ClassZone.Properties; - } - } - if (member.Kind == SymbolKind.Property) - { - return ClassZone.Properties; - } - if (member.Kind == SymbolKind.NamedType) - { - var namedType = (INamedTypeSymbol)member; - if (namedType.TypeKind == TypeKind.Class || - namedType.TypeKind == TypeKind.Enum || - namedType.TypeKind == TypeKind.Struct) - { - return ClassZone.NestedTypes; - } - } - return ClassZone.OtherThings; - } - - public void AfterCompile(AfterCompileContext context) - { - } - - private enum ClassZone - { - Ignored, - BeforeStart, - Fields, - Constructors, - Properties, - OtherThings, - NestedTypes, - AfterEnd - } - } -} diff --git a/tools/Microsoft.StandardsPolice/project.json b/tools/Microsoft.StandardsPolice/project.json deleted file mode 100644 index 7f24c4760b..0000000000 --- a/tools/Microsoft.StandardsPolice/project.json +++ /dev/null @@ -1,44 +0,0 @@ -{ - "version": "1.0.0-*", - - "compilationOptions": { - "keyFile": "../../tools/Key.snk" - }, - - "description": "Microsoft.StandardsPolice Class Library", - - "dependencies": { - "Microsoft.Dnx.Compilation.CSharp.Abstractions": "1.0.0-*" - }, - - "commands": { - "Microsoft.StandardsPolice": "Microsoft.StandardsPolice" - }, - - "frameworks": { - "net451": { - "frameworkAssemblies": { - "System.Runtime": "", - "System.Text.Encoding": "", - "System.Threading.Tasks": "" - } - }, - "dnx451": { - "frameworkAssemblies": { - "System.Runtime": "", - "System.Text.Encoding": "", - "System.Threading.Tasks": "" - } - }, - "dotnet5.4": { - "dependencies": { - "System.Console": "4.0.0-*" - } - }, - "dnxcore50": { - "dependencies": { - "System.Console": "4.0.0-*" - } - } - } -} From fa181819c1c97620d930b3006d529a2b83675815 Mon Sep 17 00:00:00 2001 From: Ajay Bhargav Baaskaran Date: Thu, 4 Feb 2016 15:33:16 -0800 Subject: [PATCH 0594/1662] Update Json.Net version --- .../project.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/Microsoft.AspNetCore.Server.Kestrel.LibuvCopier/project.json b/tools/Microsoft.AspNetCore.Server.Kestrel.LibuvCopier/project.json index bc49d7a5ce..04573cf16e 100644 --- a/tools/Microsoft.AspNetCore.Server.Kestrel.LibuvCopier/project.json +++ b/tools/Microsoft.AspNetCore.Server.Kestrel.LibuvCopier/project.json @@ -5,7 +5,7 @@ }, "dependencies": { "Microsoft.Extensions.PlatformAbstractions": "1.0.0-*", - "Newtonsoft.Json": "7.0.1" + "Newtonsoft.Json": "8.0.2" }, "frameworks": { "dnxcore50": { From c5a8792ece9157698555947f159093892929cd93 Mon Sep 17 00:00:00 2001 From: Pranav K Date: Mon, 8 Feb 2016 09:33:46 -0800 Subject: [PATCH 0595/1662] Reacting to CoreCLR package version changes --- src/Microsoft.AspNetCore.Server.Kestrel/project.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/project.json b/src/Microsoft.AspNetCore.Server.Kestrel/project.json index bfbe6d0b5a..864d8a3f26 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/project.json +++ b/src/Microsoft.AspNetCore.Server.Kestrel/project.json @@ -32,13 +32,13 @@ "System.Collections": "4.0.11-*", "System.Diagnostics.Debug": "4.0.11-*", "System.Diagnostics.TraceSource": "4.0.0-*", - "System.Diagnostics.Tracing": "4.0.21-*", + "System.Diagnostics.Tracing": "4.1.0-*", "System.Globalization": "4.0.11-*", "System.IO": "4.1.0-*", - "System.Linq": "4.0.1-*", + "System.Linq": "4.0.2-*", "System.Net.Primitives": "4.0.11-*", "System.Runtime.Extensions": "4.1.0-*", - "System.Runtime.InteropServices": "4.0.21-*", + "System.Runtime.InteropServices": "4.1.0-*", "System.Text.Encoding": "4.0.11-*", "System.Threading": "4.0.11-*", "System.Threading.Tasks": "4.0.11-*", From dfcd6a62272a58394f470d7d02ed37f89c4c83fb Mon Sep 17 00:00:00 2001 From: Kiran Challa Date: Tue, 9 Feb 2016 23:47:50 -0800 Subject: [PATCH 0596/1662] Enable tests to run using dotnet xunit runner --- .../project.json | 19 ++--- .../project.json | 75 +++++++++---------- 2 files changed, 44 insertions(+), 50 deletions(-) diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json index 1a081b1e3a..0f4db08fdb 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json @@ -9,23 +9,20 @@ "xunit": "2.1.0" }, "frameworks": { + "dnxcore50": { + "dependencies": { + "dotnet-test-xunit": "1.0.0-dev-*" + }, + "imports": "portable-net451+win8" + }, "dnx451": { "dependencies": { "xunit.runner.console": "2.1.0" } - }, - "dnxcore50": { - "dependencies": { - "xunit.runner.aspnet": "2.0.0-aspnet-*" - }, - "imports": "portable-net45+win8" } }, "compilationOptions": { "allowUnsafe": true }, - "testRunner": "xunit", - "commands": { - "test": "xunit.runner.aspnet" - } -} + "testRunner": "xunit" +} \ No newline at end of file diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/project.json b/test/Microsoft.AspNetCore.Server.KestrelTests/project.json index e87ccc77ff..1d079264a8 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/project.json +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/project.json @@ -1,41 +1,38 @@ { - "version": "1.0.0-*", - "dependencies": { - "Microsoft.AspNetCore.Server.Kestrel": "1.0.0-*", - "Microsoft.AspNetCore.Server.Kestrel.Https": "1.0.0-*", - "Microsoft.AspNetCore.Testing": "1.0.0-*", - "Microsoft.NETCore.Platforms": "1.0.1-*", - "System.Net.Http": "4.0.1-*", - "xunit": "2.1.0" + "version": "1.0.0-*", + "dependencies": { + "Microsoft.AspNetCore.Server.Kestrel": "1.0.0-*", + "Microsoft.AspNetCore.Server.Kestrel.Https": "1.0.0-*", + "Microsoft.AspNetCore.Testing": "1.0.0-*", + "Microsoft.NETCore.Platforms": "1.0.1-*", + "System.Net.Http": "4.0.1-*", + "xunit": "2.1.0" + }, + "frameworks": { + "dnxcore50": { + "dependencies": { + "System.Diagnostics.TraceSource": "4.0.0-*", + "System.Globalization.Extensions": "4.0.1-*", + "System.IO": "4.1.0-*", + "System.Net.Http.WinHttpHandler": "4.0.0-*", + "System.Net.Sockets": "4.1.0-*", + "System.Runtime.Handles": "4.0.1-*", + "dotnet-test-xunit": "1.0.0-dev-*" + }, + "imports": "portable-net451+win8" }, - "frameworks": { - "dnx451": { - "dependencies": { - "xunit.runner.console": "2.1.0" - } - }, - "dnxcore50": { - "dependencies": { - "System.Diagnostics.TraceSource": "4.0.0-*", - "System.Globalization.Extensions": "4.0.1-*", - "System.IO": "4.1.0-*", - "System.Net.Http.WinHttpHandler": "4.0.0-*", - "System.Net.Sockets": "4.1.0-*", - "System.Runtime.Handles": "4.0.1-*", - "xunit.runner.aspnet": "2.0.0-aspnet-*" - }, - "imports": "portable-net45+win8" - } - }, - "compilationOptions": { - "allowUnsafe": true, - "keyFile": "../../tools/Key.snk" - }, - "testRunner": "xunit", - "commands": { - "test": "xunit.runner.aspnet" - }, - "content": [ - "TestResources/testCert.pfx" - ] -} + "dnx451": { + "dependencies": { + "xunit.runner.console": "2.1.0" + } + } + }, + "compilationOptions": { + "allowUnsafe": true, + "keyFile": "../../tools/Key.snk" + }, + "testRunner": "xunit", + "content": [ + "TestResources/testCert.pfx" + ] +} \ No newline at end of file From fe75aa47dbe4209600511543fb5b2f9aca055c8a Mon Sep 17 00:00:00 2001 From: moozzyk Date: Thu, 11 Feb 2016 14:42:06 -0800 Subject: [PATCH 0597/1662] Enabling Kestrel on OSx Mono when not running with dnx Before moving to dotnet dnx on OSx on Mono would load libuv.dll into the process and Kestrel would use DllImport with __Internal to import functions from the native libraries loaded into the Mono process. With the move to dotnet nothing is preloading libuv to the process so Kestrel must no longer use DllImports with __Internal but the regular ones. Mono seems to load native libraries from the app folder so, the user won't have to install libuv on their own since libuv.dylib is published with the app. --- .../Networking/Libuv.cs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Networking/Libuv.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Networking/Libuv.cs index 792e928878..279d4885cf 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Networking/Libuv.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Networking/Libuv.cs @@ -12,9 +12,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Networking { IsWindows = PlatformApis.IsWindows; - var isDarwinMono = PlatformApis.IsDarwin && PlatformApis.IsMono; + var isDnxDarwinMono = +#if NET451 + PlatformApis.IsDarwin && PlatformApis.IsMono && AppDomain.CurrentDomain.GetData("DNX_SERVICEPROVIDER") != null; +#else + false; +#endif - if (isDarwinMono) + if (isDnxDarwinMono) { _uv_loop_init = NativeDarwinMonoMethods.uv_loop_init; _uv_loop_close = NativeDarwinMonoMethods.uv_loop_close; From c293bbbd1a6e49d7942dc352f31966dbc6419fba Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Mon, 1 Feb 2016 09:40:10 +0000 Subject: [PATCH 0598/1662] Reuse headers to prevent values moving to higher GC gens --- .../Http/Frame.cs | 127 ++++++++++++------ .../Http/FrameHeaders.Generated.cs | 46 +++++++ .../Http/FrameOfT.cs | 31 ++--- .../Http/FrameResponseStream.cs | 16 ++- .../Infrastructure/HttpComponentFactory.cs | 116 ++++++++++++++++ .../Infrastructure/IHttpComponentFactory.cs | 18 +++ .../KestrelServer.cs | 4 +- .../ServiceContext.cs | 3 + .../FrameResponseHeadersTests.cs | 16 ++- .../TestServiceContext.cs | 1 + .../KnownHeaders.cs | 4 +- 11 files changed, 311 insertions(+), 71 deletions(-) create mode 100644 src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/HttpComponentFactory.cs create mode 100644 src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/IHttpComponentFactory.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs index 81aa57bb5b..6ca68ad4e1 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs @@ -34,8 +34,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http private static readonly byte[] _bytesHttpVersion1_1 = Encoding.ASCII.GetBytes("HTTP/1.1 "); private static readonly byte[] _bytesContentLengthZero = Encoding.ASCII.GetBytes("\r\nContent-Length: 0"); private static readonly byte[] _bytesSpace = Encoding.ASCII.GetBytes(" "); - private static readonly byte[] _bytesServer = Encoding.ASCII.GetBytes("\r\nServer: Kestrel"); - private static readonly byte[] _bytesDate = Encoding.ASCII.GetBytes("Date: "); private static readonly byte[] _bytesEndHeaders = Encoding.ASCII.GetBytes("\r\n\r\n"); private static Vector _vectorCRs = new Vector((byte)'\r'); @@ -46,8 +44,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http private readonly object _onStartingSync = new Object(); private readonly object _onCompletedSync = new Object(); - protected readonly FrameRequestHeaders _requestHeaders = new FrameRequestHeaders(); - private readonly FrameResponseHeaders _responseHeaders = new FrameResponseHeaders(); + + private Headers _frameHeaders; + private Streams _frameStreams; protected List, object>> _onStarting; @@ -60,10 +59,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http protected CancellationTokenSource _abortedCts; protected CancellationToken? _manuallySetRequestAbortToken; - internal FrameRequestStream _requestBody; - internal FrameResponseStream _responseBody; - internal FrameDuplexStream _duplexStream; - protected bool _responseStarted; protected bool _keepAlive; private bool _autoChunk; @@ -92,12 +87,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http _localEndPoint = localEndPoint; _prepareRequest = prepareRequest; _pathBase = context.ServerAddress.PathBase; - if (ReuseStreams) - { - _requestBody = new FrameRequestStream(); - _responseBody = new FrameResponseStream(this); - _duplexStream = new FrameDuplexStream(_requestBody, _responseBody); - } FrameControl = this; Reset(); @@ -197,8 +186,48 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http get { return _responseStarted; } } + protected FrameRequestHeaders FrameRequestHeaders => _frameHeaders.RequestHeaders; + + public Frame InitializeHeaders() + { + _frameHeaders = HttpComponentFactory.CreateHeaders(DateHeaderValueManager); + RequestHeaders = _frameHeaders.RequestHeaders; + ResponseHeaders = _frameHeaders.ResponseHeaders; + return this; + } + + + public void InitializeStreams(MessageBody messageBody) + { + _frameStreams = HttpComponentFactory.CreateStreams(this); + + RequestBody = _frameStreams.RequestBody.StartAcceptingReads(messageBody); + ResponseBody = _frameStreams.ResponseBody.StartAcceptingWrites(); + DuplexStream = _frameStreams.DuplexStream; + } + + public void PauseStreams() + { + _frameStreams.RequestBody.PauseAcceptingReads(); + _frameStreams.ResponseBody.PauseAcceptingWrites(); + } + + public void ResumeStreams() + { + _frameStreams.RequestBody.ResumeAcceptingReads(); + _frameStreams.ResponseBody.ResumeAcceptingWrites(); + } + + public void StopStreams() + { + _frameStreams.RequestBody.StopAcceptingReads(); + _frameStreams.ResponseBody.StopAcceptingWrites(); + } + public void Reset() { + ResetComponents(poolingPermitted: true); + _onStarting = null; _onCompleted = null; @@ -207,8 +236,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http _autoChunk = false; _applicationException = null; - _requestHeaders.Reset(); - ResetResponseHeaders(); ResetFeatureCollection(); Scheme = null; @@ -218,13 +245,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http Path = null; QueryString = null; _httpVersion = HttpVersionType.Unknown; - RequestHeaders = _requestHeaders; - RequestBody = null; StatusCode = 200; ReasonPhrase = null; - ResponseHeaders = _responseHeaders; - ResponseBody = null; - DuplexStream = null; var httpConnectionFeature = this as IHttpConnectionFeature; httpConnectionFeature.RemoteIpAddress = _remoteEndPoint?.Address; @@ -239,15 +261,26 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http _abortedCts = null; } - public void ResetResponseHeaders() + protected void ResetComponents(bool poolingPermitted) { - _responseHeaders.Reset(); - _responseHeaders.SetRawDate( - DateHeaderValueManager.GetDateHeaderValue(), - DateHeaderValueManager.GetDateHeaderValueBytes()); - _responseHeaders.SetRawServer( - "Kestrel", - _bytesServer); + if (_frameHeaders != null) + { + RequestHeaders = null; + ResponseHeaders = null; + var frameHeaders = _frameHeaders; + _frameHeaders = null; + HttpComponentFactory.DisposeHeaders(frameHeaders, poolingPermitted); + } + + if (_frameStreams != null) + { + RequestBody = null; + ResponseBody = null; + DuplexStream = null; + var frameStreams = _frameStreams; + _frameStreams = null; + HttpComponentFactory.DisposeStreams(frameStreams, poolingPermitted: (poolingPermitted && ReuseStreams)); + } } /// @@ -292,8 +325,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { _requestProcessingStopping = true; - _requestBody?.Abort(); - _responseBody?.Abort(); + _frameStreams?.RequestBody.Abort(); + _frameStreams?.ResponseBody.Abort(); try { @@ -560,8 +593,17 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http StatusCode = 500; ReasonPhrase = null; - ResetResponseHeaders(); - _responseHeaders.SetRawContentLength("0", _bytesContentLengthZero); + var responseHeaders = _frameHeaders.ResponseHeaders; + responseHeaders.Reset(); + responseHeaders.SetRawDate( + DateHeaderValueManager.GetDateHeaderValue(), + DateHeaderValueManager.GetDateHeaderValueBytes()); + responseHeaders.SetRawServer( + "Kestrel", + Headers.BytesServer); + responseHeaders.SetRawContentLength("0", _bytesContentLengthZero); + + ResponseHeaders = responseHeaders; } } @@ -615,9 +657,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http bool appCompleted) { var end = SocketOutput.ProducingStart(); + var responseHeaders = _frameHeaders.ResponseHeaders; if (_keepAlive) { - foreach (var connectionValue in _responseHeaders.HeaderConnection) + foreach (var connectionValue in responseHeaders.HeaderConnection) { if (connectionValue.IndexOf("close", StringComparison.OrdinalIgnoreCase) != -1) { @@ -626,7 +669,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } - if (_keepAlive && !_responseHeaders.HasTransferEncoding && !_responseHeaders.HasContentLength) + if (_keepAlive && !responseHeaders.HasTransferEncoding && !responseHeaders.HasContentLength) { if (appCompleted) { @@ -636,7 +679,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { // Since the app has completed and we are only now generating // the headers we can safely set the Content-Length to 0. - _responseHeaders.SetRawContentLength("0", _bytesContentLengthZero); + responseHeaders.SetRawContentLength("0", _bytesContentLengthZero); } } else @@ -644,7 +687,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if (_httpVersion == HttpVersionType.Http1_1) { _autoChunk = true; - _responseHeaders.SetRawTransferEncoding("chunked", _bytesTransferEncodingChunked); + responseHeaders.SetRawTransferEncoding("chunked", _bytesTransferEncodingChunked); } else { @@ -653,18 +696,18 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } - if (_keepAlive == false && _responseHeaders.HasConnection == false && _httpVersion == HttpVersionType.Http1_1) + if (_keepAlive == false && responseHeaders.HasConnection == false && _httpVersion == HttpVersionType.Http1_1) { - _responseHeaders.SetRawConnection("close", _bytesConnectionClose); + responseHeaders.SetRawConnection("close", _bytesConnectionClose); } - else if (_keepAlive && _responseHeaders.HasConnection == false && _httpVersion == HttpVersionType.Http1_0) + else if (_keepAlive && responseHeaders.HasConnection == false && _httpVersion == HttpVersionType.Http1_0) { - _responseHeaders.SetRawConnection("keep-alive", _bytesConnectionKeepAlive); + responseHeaders.SetRawConnection("keep-alive", _bytesConnectionKeepAlive); } end.CopyFrom(_httpVersion == HttpVersionType.Http1_1 ? _bytesHttpVersion1_1 : _bytesHttpVersion1_0); end.CopyFrom(statusBytes); - _responseHeaders.CopyTo(ref end); + responseHeaders.CopyTo(ref end); end.CopyFrom(_bytesEndHeaders, 0, _bytesEndHeaders.Length); SocketOutput.ProducingComplete(end); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameHeaders.Generated.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameHeaders.Generated.cs index 8a36b78d50..de407741d7 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameHeaders.Generated.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameHeaders.Generated.cs @@ -3737,6 +3737,51 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } protected override void ClearFast() { + if (((_bits & 1L) != 0)) _CacheControl = default(StringValues); + if (((_bits & 2L) != 0)) _Connection = default(StringValues); + if (((_bits & 4L) != 0)) _Date = default(StringValues); + if (((_bits & 8L) != 0)) _KeepAlive = default(StringValues); + if (((_bits & 16L) != 0)) _Pragma = default(StringValues); + if (((_bits & 32L) != 0)) _Trailer = default(StringValues); + if (((_bits & 64L) != 0)) _TransferEncoding = default(StringValues); + if (((_bits & 128L) != 0)) _Upgrade = default(StringValues); + if (((_bits & 256L) != 0)) _Via = default(StringValues); + if (((_bits & 512L) != 0)) _Warning = default(StringValues); + if (((_bits & 1024L) != 0)) _Allow = default(StringValues); + if (((_bits & 2048L) != 0)) _ContentLength = default(StringValues); + if (((_bits & 4096L) != 0)) _ContentType = default(StringValues); + if (((_bits & 8192L) != 0)) _ContentEncoding = default(StringValues); + if (((_bits & 16384L) != 0)) _ContentLanguage = default(StringValues); + if (((_bits & 32768L) != 0)) _ContentLocation = default(StringValues); + if (((_bits & 65536L) != 0)) _ContentMD5 = default(StringValues); + if (((_bits & 131072L) != 0)) _ContentRange = default(StringValues); + if (((_bits & 262144L) != 0)) _Expires = default(StringValues); + if (((_bits & 524288L) != 0)) _LastModified = default(StringValues); + if (((_bits & 1048576L) != 0)) _Accept = default(StringValues); + if (((_bits & 2097152L) != 0)) _AcceptCharset = default(StringValues); + if (((_bits & 4194304L) != 0)) _AcceptEncoding = default(StringValues); + if (((_bits & 8388608L) != 0)) _AcceptLanguage = default(StringValues); + if (((_bits & 16777216L) != 0)) _Authorization = default(StringValues); + if (((_bits & 33554432L) != 0)) _Cookie = default(StringValues); + if (((_bits & 67108864L) != 0)) _Expect = default(StringValues); + if (((_bits & 134217728L) != 0)) _From = default(StringValues); + if (((_bits & 268435456L) != 0)) _Host = default(StringValues); + if (((_bits & 536870912L) != 0)) _IfMatch = default(StringValues); + if (((_bits & 1073741824L) != 0)) _IfModifiedSince = default(StringValues); + if (((_bits & 2147483648L) != 0)) _IfNoneMatch = default(StringValues); + if (((_bits & 4294967296L) != 0)) _IfRange = default(StringValues); + if (((_bits & 8589934592L) != 0)) _IfUnmodifiedSince = default(StringValues); + if (((_bits & 17179869184L) != 0)) _MaxForwards = default(StringValues); + if (((_bits & 34359738368L) != 0)) _ProxyAuthorization = default(StringValues); + if (((_bits & 68719476736L) != 0)) _Referer = default(StringValues); + if (((_bits & 137438953472L) != 0)) _Range = default(StringValues); + if (((_bits & 274877906944L) != 0)) _TE = default(StringValues); + if (((_bits & 549755813888L) != 0)) _Translate = default(StringValues); + if (((_bits & 1099511627776L) != 0)) _UserAgent = default(StringValues); + if (((_bits & 2199023255552L) != 0)) _Origin = default(StringValues); + if (((_bits & 4398046511104L) != 0)) _AccessControlRequestMethod = default(StringValues); + if (((_bits & 8796093022208L) != 0)) _AccessControlRequestHeaders = default(StringValues); + _bits = 0; MaybeUnknown?.Clear(); } @@ -8618,6 +8663,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } protected override void ClearFast() { + _bits = 0; MaybeUnknown?.Clear(); } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameOfT.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameOfT.cs index 0d9ea1d673..1c0191c6cb 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameOfT.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameOfT.cs @@ -52,7 +52,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http await SocketInput; } - while (!_requestProcessingStopping && !TakeMessageHeaders(SocketInput, _requestHeaders)) + InitializeHeaders(); + + while (!_requestProcessingStopping && !TakeMessageHeaders(SocketInput, FrameRequestHeaders)) { if (SocketInput.RemoteIntakeFin) { @@ -63,20 +65,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if (!_requestProcessingStopping) { - var messageBody = MessageBody.For(HttpVersion, _requestHeaders, this); + var messageBody = MessageBody.For(HttpVersion, FrameRequestHeaders, this); _keepAlive = messageBody.RequestKeepAlive; - // _duplexStream may be null if flag switched while running - if (!ReuseStreams || _duplexStream == null) - { - _requestBody = new FrameRequestStream(); - _responseBody = new FrameResponseStream(this); - _duplexStream = new FrameDuplexStream(_requestBody, _responseBody); - } - - RequestBody = _requestBody.StartAcceptingReads(messageBody); - ResponseBody = _responseBody.StartAcceptingWrites(); - DuplexStream = _duplexStream; + InitializeStreams(messageBody); _abortedCts = null; _manuallySetRequestAbortToken = null; @@ -101,8 +93,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http await FireOnStarting(); } - _requestBody.PauseAcceptingReads(); - _responseBody.PauseAcceptingWrites(); + PauseStreams(); if (_onCompleted != null) { @@ -114,23 +105,23 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http // If _requestAbort is set, the connection has already been closed. if (Volatile.Read(ref _requestAborted) == 0) { - _responseBody.ResumeAcceptingWrites(); + ResumeStreams(); + await ProduceEnd(); if (_keepAlive) { - _requestBody.ResumeAcceptingReads(); // Finish reading the request body in case the app did not. await messageBody.Consume(); } } - _requestBody.StopAcceptingReads(); - _responseBody.StopAcceptingWrites(); + StopStreams(); } if (!_keepAlive) { + ResetComponents(poolingPermitted: true); return; } } @@ -144,6 +135,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } finally { + // Error occurred, do not return components to pool + ResetComponents(poolingPermitted: false); try { _abortedCts = null; diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameResponseStream.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameResponseStream.cs index 3cf9600ecc..145710af24 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameResponseStream.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameResponseStream.cs @@ -11,12 +11,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { class FrameResponseStream : Stream { - private readonly FrameContext _context; + private FrameContext _context; private FrameStreamState _state; - public FrameResponseStream(FrameContext context) + public FrameResponseStream() { - _context = context; _state = FrameStreamState.Closed; } @@ -125,6 +124,17 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } + public void Initialize(FrameContext context) + { + _context = context; + } + + public void Uninitialize() + { + _context = null; + _state = FrameStreamState.Closed; + } + private Task ValidateState(CancellationToken cancellationToken) { switch (_state) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/HttpComponentFactory.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/HttpComponentFactory.cs new file mode 100644 index 0000000000..98cdfef311 --- /dev/null +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/HttpComponentFactory.cs @@ -0,0 +1,116 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System.Collections.Concurrent; +using Microsoft.AspNetCore.Server.Kestrel.Http; +using System.Text; + +namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure +{ + class HttpComponentFactory : IHttpComponentFactory + { + private const int _maxPooledComponents = 128; + private ConcurrentQueue _streamPool = new ConcurrentQueue(); + private ConcurrentQueue _headerPool = new ConcurrentQueue(); + + public Streams CreateStreams(FrameContext owner) + { + Streams streams; + + if (!_streamPool.TryDequeue(out streams)) + { + streams = new Streams(); + } + + streams.Initialize(owner); + + return streams; + } + + public void DisposeStreams(Streams streams, bool poolingPermitted) + { + if (poolingPermitted && _streamPool.Count < _maxPooledComponents) + { + streams.Uninitialize(); + + _streamPool.Enqueue(streams); + } + } + + public Headers CreateHeaders(DateHeaderValueManager dateValueManager) + { + Headers headers; + + if (!_headerPool.TryDequeue(out headers)) + { + headers = new Headers(); + } + + headers.Initialize(dateValueManager); + + return headers; + } + + public void DisposeHeaders(Headers headers, bool poolingPermitted) + { + if (poolingPermitted && _headerPool.Count < _maxPooledComponents) + { + headers.Uninitialize(); + + _headerPool.Enqueue(headers); + } + } + } + + internal class Headers + { + public static readonly byte[] BytesServer = Encoding.ASCII.GetBytes("\r\nServer: Kestrel"); + + public readonly FrameRequestHeaders RequestHeaders = new FrameRequestHeaders(); + public readonly FrameResponseHeaders ResponseHeaders = new FrameResponseHeaders(); + + public Headers() + { + RequestHeaders = new FrameRequestHeaders(); + ResponseHeaders = new FrameResponseHeaders(); + } + + public void Initialize(DateHeaderValueManager dateValueManager) + { + ResponseHeaders.SetRawDate( + dateValueManager.GetDateHeaderValue(), + dateValueManager.GetDateHeaderValueBytes()); + ResponseHeaders.SetRawServer("Kestrel", BytesServer); + } + + public void Uninitialize() + { + RequestHeaders.Reset(); + ResponseHeaders.Reset(); + } + } + + internal class Streams + { + public readonly FrameRequestStream RequestBody; + public readonly FrameResponseStream ResponseBody; + public readonly FrameDuplexStream DuplexStream; + + public Streams() + { + RequestBody = new FrameRequestStream(); + ResponseBody = new FrameResponseStream(); + DuplexStream = new FrameDuplexStream(RequestBody, ResponseBody); + } + + public void Initialize(FrameContext renter) + { + ResponseBody.Initialize(renter); + } + + public void Uninitialize() + { + ResponseBody.Uninitialize(); + } + } +} diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/IHttpComponentFactory.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/IHttpComponentFactory.cs new file mode 100644 index 0000000000..b02300774a --- /dev/null +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/IHttpComponentFactory.cs @@ -0,0 +1,18 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using Microsoft.AspNetCore.Server.Kestrel.Http; + +namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure +{ + interface IHttpComponentFactory + { + Streams CreateStreams(FrameContext owner); + + void DisposeStreams(Streams streams, bool poolingPermitted); + + Headers CreateHeaders(DateHeaderValueManager dateValueManager); + + void DisposeHeaders(Headers headers, bool poolingPermitted); + } +} diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServer.cs b/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServer.cs index fed5bea660..6e3826d971 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServer.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServer.cs @@ -56,6 +56,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel var information = (KestrelServerInformation)Features.Get(); var dateHeaderValueManager = new DateHeaderValueManager(); var trace = new KestrelTrace(_logger); + var componentFactory = new HttpComponentFactory(); var engine = new KestrelEngine(new ServiceContext { FrameFactory = (context, remoteEP, localEP, prepareRequest) => @@ -68,7 +69,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel DateHeaderValueManager = dateHeaderValueManager, ConnectionFilter = information.ConnectionFilter, NoDelay = information.NoDelay, - ReuseStreams = information.ReuseStreams + ReuseStreams = information.ReuseStreams, + HttpComponentFactory = componentFactory }); _disposables.Push(engine); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/ServiceContext.cs b/src/Microsoft.AspNetCore.Server.Kestrel/ServiceContext.cs index a299ff9461..b0d26c0953 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/ServiceContext.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/ServiceContext.cs @@ -27,6 +27,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel ConnectionFilter = context.ConnectionFilter; NoDelay = context.NoDelay; ReuseStreams = context.ReuseStreams; + HttpComponentFactory = context.HttpComponentFactory; } public IApplicationLifetime AppLifetime { get; set; } @@ -44,5 +45,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel public bool NoDelay { get; set; } public bool ReuseStreams { get; set; } + + internal IHttpComponentFactory HttpComponentFactory { get; set; } } } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameResponseHeadersTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameResponseHeadersTests.cs index 5fa4f6bec2..8bdf782e9f 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameResponseHeadersTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameResponseHeadersTests.cs @@ -5,6 +5,7 @@ using System; using System.Collections.Generic; using Microsoft.AspNetCore.Server.Kestrel; using Microsoft.AspNetCore.Server.Kestrel.Http; +using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; using Microsoft.Extensions.Primitives; using Xunit; @@ -18,9 +19,12 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var connectionContext = new ConnectionContext { DateHeaderValueManager = new DateHeaderValueManager(), - ServerAddress = ServerAddress.FromUrl("http://localhost:5000") + ServerAddress = ServerAddress.FromUrl("http://localhost:5000"), + HttpComponentFactory = new HttpComponentFactory() }; - var frame = new Frame(application: null, context: connectionContext); + var frame = new Frame(application: null, context: connectionContext) + .InitializeHeaders(); + IDictionary headers = frame.ResponseHeaders; Assert.Equal(2, headers.Count); @@ -46,10 +50,12 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var connectionContext = new ConnectionContext { DateHeaderValueManager = new DateHeaderValueManager(), - ServerAddress = ServerAddress.FromUrl("http://localhost:5000") + ServerAddress = ServerAddress.FromUrl("http://localhost:5000"), + HttpComponentFactory = new HttpComponentFactory() }; - var frame = new Frame(application: null, context: connectionContext); - + var frame = new Frame(application: null, context: connectionContext) + .InitializeHeaders(); + Assert.True(frame.ResponseHeaders.Count > 0); frame.ResponseHeaders.Clear(); diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestServiceContext.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/TestServiceContext.cs index 4224c776d3..679abaa3a7 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/TestServiceContext.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/TestServiceContext.cs @@ -18,6 +18,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests Log = new TestKestrelTrace(); ThreadPool = new LoggingThreadPool(Log); DateHeaderValueManager = new TestDateHeaderValueManager(); + HttpComponentFactory = new HttpComponentFactory(); } public RequestDelegate App diff --git a/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/KnownHeaders.cs b/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/KnownHeaders.cs index 32a5f057e7..92e133db89 100644 --- a/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/KnownHeaders.cs +++ b/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/KnownHeaders.cs @@ -366,7 +366,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http return MaybeUnknown?.Remove(key) ?? false; }} protected override void ClearFast() - {{ + {{{(loop.ClassName != "FrameRequestHeaders" ? "" : Each(loop.Headers, header => $@" + if ({header.TestBit()}) _{header.Identifier} = default(StringValues);"))} + _bits = 0; MaybeUnknown?.Clear(); }} From e533d5da8916b4d21b4bdecd930dce47b8de70b6 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Sat, 13 Feb 2016 01:52:16 +0000 Subject: [PATCH 0599/1662] Fast path Consume when already complete --- .../Http/MessageBody.cs | 37 ++++++++++++++++--- 1 file changed, 32 insertions(+), 5 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/MessageBody.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/MessageBody.cs index daeeeaa9e1..2731ec42a6 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/MessageBody.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/MessageBody.cs @@ -5,6 +5,7 @@ using System; using System.IO; using System.Threading; using System.Threading.Tasks; +using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; namespace Microsoft.AspNetCore.Server.Kestrel.Http { @@ -35,7 +36,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http return result; } - public async Task Consume(CancellationToken cancellationToken = default(CancellationToken)) + public Task Consume(CancellationToken cancellationToken = default(CancellationToken)) { ValueTask result; var send100checked = false; @@ -52,17 +53,43 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } send100checked = true; } + // Incomplete Task await result + return ConsumeAwaited(result.AsTask(), cancellationToken); } // ValueTask uses .GetAwaiter().GetResult() if necessary else if (result.Result == 0) { // Completed Task, end of stream - return; + return TaskUtilities.CompletedTask; } - else + + } while (true); + } + + private async Task ConsumeAwaited(Task currentTask, CancellationToken cancellationToken) + { + if (await currentTask == 0) + { + return; + } + + ValueTask result; + do + { + result = ReadAsyncImplementation(default(ArraySegment), cancellationToken); + if (result.IsCompleted) { - // Completed Task, get next Task rather than await - continue; + // ValueTask uses .GetAwaiter().GetResult() if necessary + if (result.Result == 0) + { + // Completed Task, end of stream + return; + } + else + { + // Completed Task, get next Task rather than await + continue; + } } } while (await result != 0); } From 460dbb15c26950541fe987d0de49bd1eaa874a80 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Sat, 13 Feb 2016 03:35:26 +0000 Subject: [PATCH 0600/1662] RO Headers & rationalise exceptions --- .../Http/Frame.cs | 4 +- .../Http/FrameHeaders.Generated.cs | 1087 ++++------------- .../Http/FrameHeaders.cs | 53 +- .../KnownHeaders.cs | 13 +- 4 files changed, 308 insertions(+), 849 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs index 6ca68ad4e1..b84f63e87f 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs @@ -656,8 +656,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http byte[] statusBytes, bool appCompleted) { - var end = SocketOutput.ProducingStart(); var responseHeaders = _frameHeaders.ResponseHeaders; + responseHeaders.SetReadOnly(); + + var end = SocketOutput.ProducingStart(); if (_keepAlive) { foreach (var connectionValue in responseHeaders.HeaderConnection) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameHeaders.Generated.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameHeaders.Generated.cs index de407741d7..b0561f2514 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameHeaders.Generated.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameHeaders.Generated.cs @@ -782,7 +782,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } else { - throw new System.Collections.Generic.KeyNotFoundException(); + ThrowKeyNotFoundException(); } } @@ -794,7 +794,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } else { - throw new System.Collections.Generic.KeyNotFoundException(); + ThrowKeyNotFoundException(); } } @@ -806,7 +806,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } else { - throw new System.Collections.Generic.KeyNotFoundException(); + ThrowKeyNotFoundException(); } } @@ -818,7 +818,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } else { - throw new System.Collections.Generic.KeyNotFoundException(); + ThrowKeyNotFoundException(); } } @@ -830,7 +830,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } else { - throw new System.Collections.Generic.KeyNotFoundException(); + ThrowKeyNotFoundException(); } } } @@ -846,7 +846,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } else { - throw new System.Collections.Generic.KeyNotFoundException(); + ThrowKeyNotFoundException(); } } @@ -858,7 +858,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } else { - throw new System.Collections.Generic.KeyNotFoundException(); + ThrowKeyNotFoundException(); } } @@ -870,7 +870,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } else { - throw new System.Collections.Generic.KeyNotFoundException(); + ThrowKeyNotFoundException(); } } } @@ -886,7 +886,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } else { - throw new System.Collections.Generic.KeyNotFoundException(); + ThrowKeyNotFoundException(); } } @@ -898,7 +898,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } else { - throw new System.Collections.Generic.KeyNotFoundException(); + ThrowKeyNotFoundException(); } } @@ -910,7 +910,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } else { - throw new System.Collections.Generic.KeyNotFoundException(); + ThrowKeyNotFoundException(); } } } @@ -926,7 +926,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } else { - throw new System.Collections.Generic.KeyNotFoundException(); + ThrowKeyNotFoundException(); } } @@ -938,7 +938,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } else { - throw new System.Collections.Generic.KeyNotFoundException(); + ThrowKeyNotFoundException(); } } @@ -950,7 +950,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } else { - throw new System.Collections.Generic.KeyNotFoundException(); + ThrowKeyNotFoundException(); } } @@ -962,7 +962,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } else { - throw new System.Collections.Generic.KeyNotFoundException(); + ThrowKeyNotFoundException(); } } @@ -974,7 +974,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } else { - throw new System.Collections.Generic.KeyNotFoundException(); + ThrowKeyNotFoundException(); } } } @@ -990,7 +990,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } else { - throw new System.Collections.Generic.KeyNotFoundException(); + ThrowKeyNotFoundException(); } } @@ -1002,7 +1002,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } else { - throw new System.Collections.Generic.KeyNotFoundException(); + ThrowKeyNotFoundException(); } } @@ -1014,7 +1014,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } else { - throw new System.Collections.Generic.KeyNotFoundException(); + ThrowKeyNotFoundException(); } } @@ -1026,7 +1026,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } else { - throw new System.Collections.Generic.KeyNotFoundException(); + ThrowKeyNotFoundException(); } } @@ -1038,7 +1038,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } else { - throw new System.Collections.Generic.KeyNotFoundException(); + ThrowKeyNotFoundException(); } } } @@ -1054,7 +1054,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } else { - throw new System.Collections.Generic.KeyNotFoundException(); + ThrowKeyNotFoundException(); } } @@ -1066,7 +1066,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } else { - throw new System.Collections.Generic.KeyNotFoundException(); + ThrowKeyNotFoundException(); } } } @@ -1082,7 +1082,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } else { - throw new System.Collections.Generic.KeyNotFoundException(); + ThrowKeyNotFoundException(); } } } @@ -1098,7 +1098,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } else { - throw new System.Collections.Generic.KeyNotFoundException(); + ThrowKeyNotFoundException(); } } @@ -1110,7 +1110,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } else { - throw new System.Collections.Generic.KeyNotFoundException(); + ThrowKeyNotFoundException(); } } } @@ -1126,7 +1126,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } else { - throw new System.Collections.Generic.KeyNotFoundException(); + ThrowKeyNotFoundException(); } } @@ -1138,7 +1138,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } else { - throw new System.Collections.Generic.KeyNotFoundException(); + ThrowKeyNotFoundException(); } } } @@ -1154,7 +1154,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } else { - throw new System.Collections.Generic.KeyNotFoundException(); + ThrowKeyNotFoundException(); } } @@ -1166,7 +1166,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } else { - throw new System.Collections.Generic.KeyNotFoundException(); + ThrowKeyNotFoundException(); } } } @@ -1182,7 +1182,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } else { - throw new System.Collections.Generic.KeyNotFoundException(); + ThrowKeyNotFoundException(); } } @@ -1194,7 +1194,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } else { - throw new System.Collections.Generic.KeyNotFoundException(); + ThrowKeyNotFoundException(); } } @@ -1206,7 +1206,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } else { - throw new System.Collections.Generic.KeyNotFoundException(); + ThrowKeyNotFoundException(); } } } @@ -1222,7 +1222,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } else { - throw new System.Collections.Generic.KeyNotFoundException(); + ThrowKeyNotFoundException(); } } } @@ -1238,7 +1238,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } else { - throw new System.Collections.Generic.KeyNotFoundException(); + ThrowKeyNotFoundException(); } } @@ -1250,7 +1250,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } else { - throw new System.Collections.Generic.KeyNotFoundException(); + ThrowKeyNotFoundException(); } } } @@ -1266,7 +1266,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } else { - throw new System.Collections.Generic.KeyNotFoundException(); + ThrowKeyNotFoundException(); } } @@ -1278,7 +1278,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } else { - throw new System.Collections.Generic.KeyNotFoundException(); + ThrowKeyNotFoundException(); } } } @@ -1294,7 +1294,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } else { - throw new System.Collections.Generic.KeyNotFoundException(); + ThrowKeyNotFoundException(); } } @@ -1306,7 +1306,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } else { - throw new System.Collections.Generic.KeyNotFoundException(); + ThrowKeyNotFoundException(); } } } @@ -1322,7 +1322,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } else { - throw new System.Collections.Generic.KeyNotFoundException(); + ThrowKeyNotFoundException(); } } } @@ -1338,7 +1338,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } else { - throw new System.Collections.Generic.KeyNotFoundException(); + ThrowKeyNotFoundException(); } } } @@ -1354,7 +1354,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } else { - throw new System.Collections.Generic.KeyNotFoundException(); + ThrowKeyNotFoundException(); } } } @@ -1370,7 +1370,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } else { - throw new System.Collections.Generic.KeyNotFoundException(); + ThrowKeyNotFoundException(); } } } @@ -1378,7 +1378,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } if (MaybeUnknown == null) { - throw new System.Collections.Generic.KeyNotFoundException(); + ThrowKeyNotFoundException(); } return MaybeUnknown[key]; } @@ -2481,7 +2481,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 1L) != 0)) { - throw new ArgumentException("An item with the same key has already been added."); + ThrowDuplicateKeyException(); } _bits |= 1L; _CacheControl = value; @@ -2492,7 +2492,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 131072L) != 0)) { - throw new ArgumentException("An item with the same key has already been added."); + ThrowDuplicateKeyException(); } _bits |= 131072L; _ContentRange = value; @@ -2503,7 +2503,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 524288L) != 0)) { - throw new ArgumentException("An item with the same key has already been added."); + ThrowDuplicateKeyException(); } _bits |= 524288L; _LastModified = value; @@ -2514,7 +2514,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 16777216L) != 0)) { - throw new ArgumentException("An item with the same key has already been added."); + ThrowDuplicateKeyException(); } _bits |= 16777216L; _Authorization = value; @@ -2525,7 +2525,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 2147483648L) != 0)) { - throw new ArgumentException("An item with the same key has already been added."); + ThrowDuplicateKeyException(); } _bits |= 2147483648L; _IfNoneMatch = value; @@ -2540,7 +2540,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 2L) != 0)) { - throw new ArgumentException("An item with the same key has already been added."); + ThrowDuplicateKeyException(); } _bits |= 2L; _Connection = value; @@ -2551,7 +2551,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 8L) != 0)) { - throw new ArgumentException("An item with the same key has already been added."); + ThrowDuplicateKeyException(); } _bits |= 8L; _KeepAlive = value; @@ -2562,7 +2562,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 1099511627776L) != 0)) { - throw new ArgumentException("An item with the same key has already been added."); + ThrowDuplicateKeyException(); } _bits |= 1099511627776L; _UserAgent = value; @@ -2577,7 +2577,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 4L) != 0)) { - throw new ArgumentException("An item with the same key has already been added."); + ThrowDuplicateKeyException(); } _bits |= 4L; _Date = value; @@ -2588,7 +2588,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 134217728L) != 0)) { - throw new ArgumentException("An item with the same key has already been added."); + ThrowDuplicateKeyException(); } _bits |= 134217728L; _From = value; @@ -2599,7 +2599,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 268435456L) != 0)) { - throw new ArgumentException("An item with the same key has already been added."); + ThrowDuplicateKeyException(); } _bits |= 268435456L; _Host = value; @@ -2614,7 +2614,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 16L) != 0)) { - throw new ArgumentException("An item with the same key has already been added."); + ThrowDuplicateKeyException(); } _bits |= 16L; _Pragma = value; @@ -2625,7 +2625,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 1048576L) != 0)) { - throw new ArgumentException("An item with the same key has already been added."); + ThrowDuplicateKeyException(); } _bits |= 1048576L; _Accept = value; @@ -2636,7 +2636,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 33554432L) != 0)) { - throw new ArgumentException("An item with the same key has already been added."); + ThrowDuplicateKeyException(); } _bits |= 33554432L; _Cookie = value; @@ -2647,7 +2647,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 67108864L) != 0)) { - throw new ArgumentException("An item with the same key has already been added."); + ThrowDuplicateKeyException(); } _bits |= 67108864L; _Expect = value; @@ -2658,7 +2658,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 2199023255552L) != 0)) { - throw new ArgumentException("An item with the same key has already been added."); + ThrowDuplicateKeyException(); } _bits |= 2199023255552L; _Origin = value; @@ -2673,7 +2673,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 32L) != 0)) { - throw new ArgumentException("An item with the same key has already been added."); + ThrowDuplicateKeyException(); } _bits |= 32L; _Trailer = value; @@ -2684,7 +2684,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 128L) != 0)) { - throw new ArgumentException("An item with the same key has already been added."); + ThrowDuplicateKeyException(); } _bits |= 128L; _Upgrade = value; @@ -2695,7 +2695,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 512L) != 0)) { - throw new ArgumentException("An item with the same key has already been added."); + ThrowDuplicateKeyException(); } _bits |= 512L; _Warning = value; @@ -2706,7 +2706,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 262144L) != 0)) { - throw new ArgumentException("An item with the same key has already been added."); + ThrowDuplicateKeyException(); } _bits |= 262144L; _Expires = value; @@ -2717,7 +2717,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 68719476736L) != 0)) { - throw new ArgumentException("An item with the same key has already been added."); + ThrowDuplicateKeyException(); } _bits |= 68719476736L; _Referer = value; @@ -2732,7 +2732,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 64L) != 0)) { - throw new ArgumentException("An item with the same key has already been added."); + ThrowDuplicateKeyException(); } _bits |= 64L; _TransferEncoding = value; @@ -2743,7 +2743,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 1073741824L) != 0)) { - throw new ArgumentException("An item with the same key has already been added."); + ThrowDuplicateKeyException(); } _bits |= 1073741824L; _IfModifiedSince = value; @@ -2758,7 +2758,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 256L) != 0)) { - throw new ArgumentException("An item with the same key has already been added."); + ThrowDuplicateKeyException(); } _bits |= 256L; _Via = value; @@ -2773,7 +2773,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 1024L) != 0)) { - throw new ArgumentException("An item with the same key has already been added."); + ThrowDuplicateKeyException(); } _bits |= 1024L; _Allow = value; @@ -2784,7 +2784,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 137438953472L) != 0)) { - throw new ArgumentException("An item with the same key has already been added."); + ThrowDuplicateKeyException(); } _bits |= 137438953472L; _Range = value; @@ -2799,7 +2799,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 2048L) != 0)) { - throw new ArgumentException("An item with the same key has already been added."); + ThrowDuplicateKeyException(); } _bits |= 2048L; _ContentLength = value; @@ -2810,7 +2810,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 2097152L) != 0)) { - throw new ArgumentException("An item with the same key has already been added."); + ThrowDuplicateKeyException(); } _bits |= 2097152L; _AcceptCharset = value; @@ -2825,7 +2825,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 4096L) != 0)) { - throw new ArgumentException("An item with the same key has already been added."); + ThrowDuplicateKeyException(); } _bits |= 4096L; _ContentType = value; @@ -2836,7 +2836,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 17179869184L) != 0)) { - throw new ArgumentException("An item with the same key has already been added."); + ThrowDuplicateKeyException(); } _bits |= 17179869184L; _MaxForwards = value; @@ -2851,7 +2851,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 8192L) != 0)) { - throw new ArgumentException("An item with the same key has already been added."); + ThrowDuplicateKeyException(); } _bits |= 8192L; _ContentEncoding = value; @@ -2862,7 +2862,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 16384L) != 0)) { - throw new ArgumentException("An item with the same key has already been added."); + ThrowDuplicateKeyException(); } _bits |= 16384L; _ContentLanguage = value; @@ -2873,7 +2873,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 32768L) != 0)) { - throw new ArgumentException("An item with the same key has already been added."); + ThrowDuplicateKeyException(); } _bits |= 32768L; _ContentLocation = value; @@ -2888,7 +2888,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 65536L) != 0)) { - throw new ArgumentException("An item with the same key has already been added."); + ThrowDuplicateKeyException(); } _bits |= 65536L; _ContentMD5 = value; @@ -2903,7 +2903,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 4194304L) != 0)) { - throw new ArgumentException("An item with the same key has already been added."); + ThrowDuplicateKeyException(); } _bits |= 4194304L; _AcceptEncoding = value; @@ -2914,7 +2914,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 8388608L) != 0)) { - throw new ArgumentException("An item with the same key has already been added."); + ThrowDuplicateKeyException(); } _bits |= 8388608L; _AcceptLanguage = value; @@ -2929,7 +2929,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 536870912L) != 0)) { - throw new ArgumentException("An item with the same key has already been added."); + ThrowDuplicateKeyException(); } _bits |= 536870912L; _IfMatch = value; @@ -2940,7 +2940,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 4294967296L) != 0)) { - throw new ArgumentException("An item with the same key has already been added."); + ThrowDuplicateKeyException(); } _bits |= 4294967296L; _IfRange = value; @@ -2955,7 +2955,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 8589934592L) != 0)) { - throw new ArgumentException("An item with the same key has already been added."); + ThrowDuplicateKeyException(); } _bits |= 8589934592L; _IfUnmodifiedSince = value; @@ -2966,7 +2966,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 34359738368L) != 0)) { - throw new ArgumentException("An item with the same key has already been added."); + ThrowDuplicateKeyException(); } _bits |= 34359738368L; _ProxyAuthorization = value; @@ -2981,7 +2981,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 274877906944L) != 0)) { - throw new ArgumentException("An item with the same key has already been added."); + ThrowDuplicateKeyException(); } _bits |= 274877906944L; _TE = value; @@ -2996,7 +2996,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 549755813888L) != 0)) { - throw new ArgumentException("An item with the same key has already been added."); + ThrowDuplicateKeyException(); } _bits |= 549755813888L; _Translate = value; @@ -3011,7 +3011,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 4398046511104L) != 0)) { - throw new ArgumentException("An item with the same key has already been added."); + ThrowDuplicateKeyException(); } _bits |= 4398046511104L; _AccessControlRequestMethod = value; @@ -3026,7 +3026,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 8796093022208L) != 0)) { - throw new ArgumentException("An item with the same key has already been added."); + ThrowDuplicateKeyException(); } _bits |= 8796093022208L; _AccessControlRequestHeaders = value; @@ -3790,14 +3790,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (arrayIndex < 0) { - throw new ArgumentException(); + ThrowArgumentException(); } if (((_bits & 1L) != 0)) { if (arrayIndex == array.Length) { - throw new ArgumentException(); + ThrowArgumentException(); } array[arrayIndex] = new KeyValuePair("Cache-Control", _CacheControl); @@ -3808,7 +3808,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (arrayIndex == array.Length) { - throw new ArgumentException(); + ThrowArgumentException(); } array[arrayIndex] = new KeyValuePair("Connection", _Connection); @@ -3819,7 +3819,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (arrayIndex == array.Length) { - throw new ArgumentException(); + ThrowArgumentException(); } array[arrayIndex] = new KeyValuePair("Date", _Date); @@ -3830,7 +3830,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (arrayIndex == array.Length) { - throw new ArgumentException(); + ThrowArgumentException(); } array[arrayIndex] = new KeyValuePair("Keep-Alive", _KeepAlive); @@ -3841,7 +3841,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (arrayIndex == array.Length) { - throw new ArgumentException(); + ThrowArgumentException(); } array[arrayIndex] = new KeyValuePair("Pragma", _Pragma); @@ -3852,7 +3852,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (arrayIndex == array.Length) { - throw new ArgumentException(); + ThrowArgumentException(); } array[arrayIndex] = new KeyValuePair("Trailer", _Trailer); @@ -3863,7 +3863,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (arrayIndex == array.Length) { - throw new ArgumentException(); + ThrowArgumentException(); } array[arrayIndex] = new KeyValuePair("Transfer-Encoding", _TransferEncoding); @@ -3874,7 +3874,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (arrayIndex == array.Length) { - throw new ArgumentException(); + ThrowArgumentException(); } array[arrayIndex] = new KeyValuePair("Upgrade", _Upgrade); @@ -3885,7 +3885,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (arrayIndex == array.Length) { - throw new ArgumentException(); + ThrowArgumentException(); } array[arrayIndex] = new KeyValuePair("Via", _Via); @@ -3896,7 +3896,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (arrayIndex == array.Length) { - throw new ArgumentException(); + ThrowArgumentException(); } array[arrayIndex] = new KeyValuePair("Warning", _Warning); @@ -3907,7 +3907,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (arrayIndex == array.Length) { - throw new ArgumentException(); + ThrowArgumentException(); } array[arrayIndex] = new KeyValuePair("Allow", _Allow); @@ -3918,7 +3918,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (arrayIndex == array.Length) { - throw new ArgumentException(); + ThrowArgumentException(); } array[arrayIndex] = new KeyValuePair("Content-Length", _ContentLength); @@ -3929,7 +3929,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (arrayIndex == array.Length) { - throw new ArgumentException(); + ThrowArgumentException(); } array[arrayIndex] = new KeyValuePair("Content-Type", _ContentType); @@ -3940,7 +3940,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (arrayIndex == array.Length) { - throw new ArgumentException(); + ThrowArgumentException(); } array[arrayIndex] = new KeyValuePair("Content-Encoding", _ContentEncoding); @@ -3951,7 +3951,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (arrayIndex == array.Length) { - throw new ArgumentException(); + ThrowArgumentException(); } array[arrayIndex] = new KeyValuePair("Content-Language", _ContentLanguage); @@ -3962,7 +3962,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (arrayIndex == array.Length) { - throw new ArgumentException(); + ThrowArgumentException(); } array[arrayIndex] = new KeyValuePair("Content-Location", _ContentLocation); @@ -3973,7 +3973,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (arrayIndex == array.Length) { - throw new ArgumentException(); + ThrowArgumentException(); } array[arrayIndex] = new KeyValuePair("Content-MD5", _ContentMD5); @@ -3984,7 +3984,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (arrayIndex == array.Length) { - throw new ArgumentException(); + ThrowArgumentException(); } array[arrayIndex] = new KeyValuePair("Content-Range", _ContentRange); @@ -3995,7 +3995,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (arrayIndex == array.Length) { - throw new ArgumentException(); + ThrowArgumentException(); } array[arrayIndex] = new KeyValuePair("Expires", _Expires); @@ -4006,7 +4006,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (arrayIndex == array.Length) { - throw new ArgumentException(); + ThrowArgumentException(); } array[arrayIndex] = new KeyValuePair("Last-Modified", _LastModified); @@ -4017,7 +4017,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (arrayIndex == array.Length) { - throw new ArgumentException(); + ThrowArgumentException(); } array[arrayIndex] = new KeyValuePair("Accept", _Accept); @@ -4028,7 +4028,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (arrayIndex == array.Length) { - throw new ArgumentException(); + ThrowArgumentException(); } array[arrayIndex] = new KeyValuePair("Accept-Charset", _AcceptCharset); @@ -4039,7 +4039,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (arrayIndex == array.Length) { - throw new ArgumentException(); + ThrowArgumentException(); } array[arrayIndex] = new KeyValuePair("Accept-Encoding", _AcceptEncoding); @@ -4050,7 +4050,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (arrayIndex == array.Length) { - throw new ArgumentException(); + ThrowArgumentException(); } array[arrayIndex] = new KeyValuePair("Accept-Language", _AcceptLanguage); @@ -4061,7 +4061,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (arrayIndex == array.Length) { - throw new ArgumentException(); + ThrowArgumentException(); } array[arrayIndex] = new KeyValuePair("Authorization", _Authorization); @@ -4072,7 +4072,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (arrayIndex == array.Length) { - throw new ArgumentException(); + ThrowArgumentException(); } array[arrayIndex] = new KeyValuePair("Cookie", _Cookie); @@ -4083,7 +4083,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (arrayIndex == array.Length) { - throw new ArgumentException(); + ThrowArgumentException(); } array[arrayIndex] = new KeyValuePair("Expect", _Expect); @@ -4094,7 +4094,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (arrayIndex == array.Length) { - throw new ArgumentException(); + ThrowArgumentException(); } array[arrayIndex] = new KeyValuePair("From", _From); @@ -4105,7 +4105,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (arrayIndex == array.Length) { - throw new ArgumentException(); + ThrowArgumentException(); } array[arrayIndex] = new KeyValuePair("Host", _Host); @@ -4116,7 +4116,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (arrayIndex == array.Length) { - throw new ArgumentException(); + ThrowArgumentException(); } array[arrayIndex] = new KeyValuePair("If-Match", _IfMatch); @@ -4127,7 +4127,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (arrayIndex == array.Length) { - throw new ArgumentException(); + ThrowArgumentException(); } array[arrayIndex] = new KeyValuePair("If-Modified-Since", _IfModifiedSince); @@ -4138,7 +4138,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (arrayIndex == array.Length) { - throw new ArgumentException(); + ThrowArgumentException(); } array[arrayIndex] = new KeyValuePair("If-None-Match", _IfNoneMatch); @@ -4149,7 +4149,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (arrayIndex == array.Length) { - throw new ArgumentException(); + ThrowArgumentException(); } array[arrayIndex] = new KeyValuePair("If-Range", _IfRange); @@ -4160,7 +4160,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (arrayIndex == array.Length) { - throw new ArgumentException(); + ThrowArgumentException(); } array[arrayIndex] = new KeyValuePair("If-Unmodified-Since", _IfUnmodifiedSince); @@ -4171,7 +4171,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (arrayIndex == array.Length) { - throw new ArgumentException(); + ThrowArgumentException(); } array[arrayIndex] = new KeyValuePair("Max-Forwards", _MaxForwards); @@ -4182,7 +4182,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (arrayIndex == array.Length) { - throw new ArgumentException(); + ThrowArgumentException(); } array[arrayIndex] = new KeyValuePair("Proxy-Authorization", _ProxyAuthorization); @@ -4193,7 +4193,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (arrayIndex == array.Length) { - throw new ArgumentException(); + ThrowArgumentException(); } array[arrayIndex] = new KeyValuePair("Referer", _Referer); @@ -4204,7 +4204,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (arrayIndex == array.Length) { - throw new ArgumentException(); + ThrowArgumentException(); } array[arrayIndex] = new KeyValuePair("Range", _Range); @@ -4215,7 +4215,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (arrayIndex == array.Length) { - throw new ArgumentException(); + ThrowArgumentException(); } array[arrayIndex] = new KeyValuePair("TE", _TE); @@ -4226,7 +4226,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (arrayIndex == array.Length) { - throw new ArgumentException(); + ThrowArgumentException(); } array[arrayIndex] = new KeyValuePair("Translate", _Translate); @@ -4237,7 +4237,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (arrayIndex == array.Length) { - throw new ArgumentException(); + ThrowArgumentException(); } array[arrayIndex] = new KeyValuePair("User-Agent", _UserAgent); @@ -4248,7 +4248,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (arrayIndex == array.Length) { - throw new ArgumentException(); + ThrowArgumentException(); } array[arrayIndex] = new KeyValuePair("Origin", _Origin); @@ -4259,7 +4259,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (arrayIndex == array.Length) { - throw new ArgumentException(); + ThrowArgumentException(); } array[arrayIndex] = new KeyValuePair("Access-Control-Request-Method", _AccessControlRequestMethod); @@ -4270,7 +4270,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (arrayIndex == array.Length) { - throw new ArgumentException(); + ThrowArgumentException(); } array[arrayIndex] = new KeyValuePair("Access-Control-Request-Headers", _AccessControlRequestHeaders); @@ -4280,6 +4280,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ((ICollection>)MaybeUnknown)?.CopyTo(array, arrayIndex); } + public unsafe void Append(byte[] keyBytes, int keyOffset, int keyLength, string value) { fixed (byte* ptr = &keyBytes[keyOffset]) @@ -6177,7 +6178,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } else { - throw new System.Collections.Generic.KeyNotFoundException(); + ThrowKeyNotFoundException(); } } @@ -6189,7 +6190,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } else { - throw new System.Collections.Generic.KeyNotFoundException(); + ThrowKeyNotFoundException(); } } @@ -6201,7 +6202,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } else { - throw new System.Collections.Generic.KeyNotFoundException(); + ThrowKeyNotFoundException(); } } @@ -6213,7 +6214,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } else { - throw new System.Collections.Generic.KeyNotFoundException(); + ThrowKeyNotFoundException(); } } } @@ -6229,7 +6230,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } else { - throw new System.Collections.Generic.KeyNotFoundException(); + ThrowKeyNotFoundException(); } } @@ -6241,7 +6242,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } else { - throw new System.Collections.Generic.KeyNotFoundException(); + ThrowKeyNotFoundException(); } } @@ -6253,7 +6254,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } else { - throw new System.Collections.Generic.KeyNotFoundException(); + ThrowKeyNotFoundException(); } } } @@ -6269,7 +6270,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } else { - throw new System.Collections.Generic.KeyNotFoundException(); + ThrowKeyNotFoundException(); } } @@ -6281,7 +6282,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } else { - throw new System.Collections.Generic.KeyNotFoundException(); + ThrowKeyNotFoundException(); } } @@ -6293,7 +6294,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } else { - throw new System.Collections.Generic.KeyNotFoundException(); + ThrowKeyNotFoundException(); } } } @@ -6309,7 +6310,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } else { - throw new System.Collections.Generic.KeyNotFoundException(); + ThrowKeyNotFoundException(); } } @@ -6321,7 +6322,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } else { - throw new System.Collections.Generic.KeyNotFoundException(); + ThrowKeyNotFoundException(); } } } @@ -6337,7 +6338,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } else { - throw new System.Collections.Generic.KeyNotFoundException(); + ThrowKeyNotFoundException(); } } @@ -6349,7 +6350,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } else { - throw new System.Collections.Generic.KeyNotFoundException(); + ThrowKeyNotFoundException(); } } @@ -6361,7 +6362,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } else { - throw new System.Collections.Generic.KeyNotFoundException(); + ThrowKeyNotFoundException(); } } @@ -6373,7 +6374,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } else { - throw new System.Collections.Generic.KeyNotFoundException(); + ThrowKeyNotFoundException(); } } } @@ -6389,7 +6390,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } else { - throw new System.Collections.Generic.KeyNotFoundException(); + ThrowKeyNotFoundException(); } } @@ -6401,7 +6402,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } else { - throw new System.Collections.Generic.KeyNotFoundException(); + ThrowKeyNotFoundException(); } } } @@ -6417,7 +6418,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } else { - throw new System.Collections.Generic.KeyNotFoundException(); + ThrowKeyNotFoundException(); } } @@ -6429,7 +6430,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } else { - throw new System.Collections.Generic.KeyNotFoundException(); + ThrowKeyNotFoundException(); } } } @@ -6445,7 +6446,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } else { - throw new System.Collections.Generic.KeyNotFoundException(); + ThrowKeyNotFoundException(); } } } @@ -6461,7 +6462,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } else { - throw new System.Collections.Generic.KeyNotFoundException(); + ThrowKeyNotFoundException(); } } } @@ -6477,7 +6478,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } else { - throw new System.Collections.Generic.KeyNotFoundException(); + ThrowKeyNotFoundException(); } } } @@ -6493,7 +6494,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } else { - throw new System.Collections.Generic.KeyNotFoundException(); + ThrowKeyNotFoundException(); } } @@ -6505,7 +6506,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } else { - throw new System.Collections.Generic.KeyNotFoundException(); + ThrowKeyNotFoundException(); } } @@ -6517,7 +6518,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } else { - throw new System.Collections.Generic.KeyNotFoundException(); + ThrowKeyNotFoundException(); } } @@ -6529,7 +6530,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } else { - throw new System.Collections.Generic.KeyNotFoundException(); + ThrowKeyNotFoundException(); } } } @@ -6545,7 +6546,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } else { - throw new System.Collections.Generic.KeyNotFoundException(); + ThrowKeyNotFoundException(); } } @@ -6557,7 +6558,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } else { - throw new System.Collections.Generic.KeyNotFoundException(); + ThrowKeyNotFoundException(); } } } @@ -6573,7 +6574,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } else { - throw new System.Collections.Generic.KeyNotFoundException(); + ThrowKeyNotFoundException(); } } } @@ -6589,7 +6590,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } else { - throw new System.Collections.Generic.KeyNotFoundException(); + ThrowKeyNotFoundException(); } } } @@ -6605,7 +6606,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } else { - throw new System.Collections.Generic.KeyNotFoundException(); + ThrowKeyNotFoundException(); } } @@ -6617,7 +6618,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } else { - throw new System.Collections.Generic.KeyNotFoundException(); + ThrowKeyNotFoundException(); } } } @@ -6633,7 +6634,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } else { - throw new System.Collections.Generic.KeyNotFoundException(); + ThrowKeyNotFoundException(); } } } @@ -6649,7 +6650,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } else { - throw new System.Collections.Generic.KeyNotFoundException(); + ThrowKeyNotFoundException(); } } } @@ -6665,7 +6666,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } else { - throw new System.Collections.Generic.KeyNotFoundException(); + ThrowKeyNotFoundException(); } } } @@ -6673,7 +6674,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } if (MaybeUnknown == null) { - throw new System.Collections.Generic.KeyNotFoundException(); + ThrowKeyNotFoundException(); } return MaybeUnknown[key]; } @@ -7605,7 +7606,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 1L) != 0)) { - throw new ArgumentException("An item with the same key has already been added."); + ThrowDuplicateKeyException(); } _bits |= 1L; _CacheControl = value; @@ -7616,7 +7617,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 131072L) != 0)) { - throw new ArgumentException("An item with the same key has already been added."); + ThrowDuplicateKeyException(); } _bits |= 131072L; _ContentRange = value; @@ -7627,7 +7628,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 524288L) != 0)) { - throw new ArgumentException("An item with the same key has already been added."); + ThrowDuplicateKeyException(); } _bits |= 524288L; _LastModified = value; @@ -7638,7 +7639,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 1048576L) != 0)) { - throw new ArgumentException("An item with the same key has already been added."); + ThrowDuplicateKeyException(); } _bits |= 1048576L; _AcceptRanges = value; @@ -7653,7 +7654,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 2L) != 0)) { - throw new ArgumentException("An item with the same key has already been added."); + ThrowDuplicateKeyException(); } _bits |= 2L; _Connection = value; @@ -7665,7 +7666,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 8L) != 0)) { - throw new ArgumentException("An item with the same key has already been added."); + ThrowDuplicateKeyException(); } _bits |= 8L; _KeepAlive = value; @@ -7676,7 +7677,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 134217728L) != 0)) { - throw new ArgumentException("An item with the same key has already been added."); + ThrowDuplicateKeyException(); } _bits |= 134217728L; _SetCookie = value; @@ -7691,7 +7692,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 4L) != 0)) { - throw new ArgumentException("An item with the same key has already been added."); + ThrowDuplicateKeyException(); } _bits |= 4L; _Date = value; @@ -7703,7 +7704,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 4194304L) != 0)) { - throw new ArgumentException("An item with the same key has already been added."); + ThrowDuplicateKeyException(); } _bits |= 4194304L; _ETag = value; @@ -7714,7 +7715,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 268435456L) != 0)) { - throw new ArgumentException("An item with the same key has already been added."); + ThrowDuplicateKeyException(); } _bits |= 268435456L; _Vary = value; @@ -7729,7 +7730,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 16L) != 0)) { - throw new ArgumentException("An item with the same key has already been added."); + ThrowDuplicateKeyException(); } _bits |= 16L; _Pragma = value; @@ -7740,7 +7741,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 67108864L) != 0)) { - throw new ArgumentException("An item with the same key has already been added."); + ThrowDuplicateKeyException(); } _bits |= 67108864L; _Server = value; @@ -7756,7 +7757,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 32L) != 0)) { - throw new ArgumentException("An item with the same key has already been added."); + ThrowDuplicateKeyException(); } _bits |= 32L; _Trailer = value; @@ -7767,7 +7768,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 128L) != 0)) { - throw new ArgumentException("An item with the same key has already been added."); + ThrowDuplicateKeyException(); } _bits |= 128L; _Upgrade = value; @@ -7778,7 +7779,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 512L) != 0)) { - throw new ArgumentException("An item with the same key has already been added."); + ThrowDuplicateKeyException(); } _bits |= 512L; _Warning = value; @@ -7789,7 +7790,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 262144L) != 0)) { - throw new ArgumentException("An item with the same key has already been added."); + ThrowDuplicateKeyException(); } _bits |= 262144L; _Expires = value; @@ -7804,7 +7805,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 64L) != 0)) { - throw new ArgumentException("An item with the same key has already been added."); + ThrowDuplicateKeyException(); } _bits |= 64L; _TransferEncoding = value; @@ -7816,7 +7817,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 16777216L) != 0)) { - throw new ArgumentException("An item with the same key has already been added."); + ThrowDuplicateKeyException(); } _bits |= 16777216L; _ProxyAutheticate = value; @@ -7831,7 +7832,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 256L) != 0)) { - throw new ArgumentException("An item with the same key has already been added."); + ThrowDuplicateKeyException(); } _bits |= 256L; _Via = value; @@ -7842,7 +7843,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 2097152L) != 0)) { - throw new ArgumentException("An item with the same key has already been added."); + ThrowDuplicateKeyException(); } _bits |= 2097152L; _Age = value; @@ -7857,7 +7858,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 1024L) != 0)) { - throw new ArgumentException("An item with the same key has already been added."); + ThrowDuplicateKeyException(); } _bits |= 1024L; _Allow = value; @@ -7872,7 +7873,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 2048L) != 0)) { - throw new ArgumentException("An item with the same key has already been added."); + ThrowDuplicateKeyException(); } _bits |= 2048L; _ContentLength = value; @@ -7888,7 +7889,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 4096L) != 0)) { - throw new ArgumentException("An item with the same key has already been added."); + ThrowDuplicateKeyException(); } _bits |= 4096L; _ContentType = value; @@ -7903,7 +7904,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 8192L) != 0)) { - throw new ArgumentException("An item with the same key has already been added."); + ThrowDuplicateKeyException(); } _bits |= 8192L; _ContentEncoding = value; @@ -7914,7 +7915,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 16384L) != 0)) { - throw new ArgumentException("An item with the same key has already been added."); + ThrowDuplicateKeyException(); } _bits |= 16384L; _ContentLanguage = value; @@ -7925,7 +7926,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 32768L) != 0)) { - throw new ArgumentException("An item with the same key has already been added."); + ThrowDuplicateKeyException(); } _bits |= 32768L; _ContentLocation = value; @@ -7936,7 +7937,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 536870912L) != 0)) { - throw new ArgumentException("An item with the same key has already been added."); + ThrowDuplicateKeyException(); } _bits |= 536870912L; _WWWAuthenticate = value; @@ -7951,7 +7952,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 65536L) != 0)) { - throw new ArgumentException("An item with the same key has already been added."); + ThrowDuplicateKeyException(); } _bits |= 65536L; _ContentMD5 = value; @@ -7962,7 +7963,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 33554432L) != 0)) { - throw new ArgumentException("An item with the same key has already been added."); + ThrowDuplicateKeyException(); } _bits |= 33554432L; _RetryAfter = value; @@ -7977,7 +7978,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 8388608L) != 0)) { - throw new ArgumentException("An item with the same key has already been added."); + ThrowDuplicateKeyException(); } _bits |= 8388608L; _Location = value; @@ -7992,7 +7993,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 1073741824L) != 0)) { - throw new ArgumentException("An item with the same key has already been added."); + ThrowDuplicateKeyException(); } _bits |= 1073741824L; _AccessControlAllowCredentials = value; @@ -8007,7 +8008,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 2147483648L) != 0)) { - throw new ArgumentException("An item with the same key has already been added."); + ThrowDuplicateKeyException(); } _bits |= 2147483648L; _AccessControlAllowHeaders = value; @@ -8018,7 +8019,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 4294967296L) != 0)) { - throw new ArgumentException("An item with the same key has already been added."); + ThrowDuplicateKeyException(); } _bits |= 4294967296L; _AccessControlAllowMethods = value; @@ -8033,7 +8034,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 8589934592L) != 0)) { - throw new ArgumentException("An item with the same key has already been added."); + ThrowDuplicateKeyException(); } _bits |= 8589934592L; _AccessControlAllowOrigin = value; @@ -8048,7 +8049,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 17179869184L) != 0)) { - throw new ArgumentException("An item with the same key has already been added."); + ThrowDuplicateKeyException(); } _bits |= 17179869184L; _AccessControlExposeHeaders = value; @@ -8063,7 +8064,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 34359738368L) != 0)) { - throw new ArgumentException("An item with the same key has already been added."); + ThrowDuplicateKeyException(); } _bits |= 34359738368L; _AccessControlMaxAge = value; @@ -8672,14 +8673,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (arrayIndex < 0) { - throw new ArgumentException(); + ThrowArgumentException(); } if (((_bits & 1L) != 0)) { if (arrayIndex == array.Length) { - throw new ArgumentException(); + ThrowArgumentException(); } array[arrayIndex] = new KeyValuePair("Cache-Control", _CacheControl); @@ -8690,7 +8691,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (arrayIndex == array.Length) { - throw new ArgumentException(); + ThrowArgumentException(); } array[arrayIndex] = new KeyValuePair("Connection", _Connection); @@ -8701,7 +8702,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (arrayIndex == array.Length) { - throw new ArgumentException(); + ThrowArgumentException(); } array[arrayIndex] = new KeyValuePair("Date", _Date); @@ -8712,7 +8713,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (arrayIndex == array.Length) { - throw new ArgumentException(); + ThrowArgumentException(); } array[arrayIndex] = new KeyValuePair("Keep-Alive", _KeepAlive); @@ -8723,7 +8724,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (arrayIndex == array.Length) { - throw new ArgumentException(); + ThrowArgumentException(); } array[arrayIndex] = new KeyValuePair("Pragma", _Pragma); @@ -8734,7 +8735,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (arrayIndex == array.Length) { - throw new ArgumentException(); + ThrowArgumentException(); } array[arrayIndex] = new KeyValuePair("Trailer", _Trailer); @@ -8745,7 +8746,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (arrayIndex == array.Length) { - throw new ArgumentException(); + ThrowArgumentException(); } array[arrayIndex] = new KeyValuePair("Transfer-Encoding", _TransferEncoding); @@ -8756,7 +8757,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (arrayIndex == array.Length) { - throw new ArgumentException(); + ThrowArgumentException(); } array[arrayIndex] = new KeyValuePair("Upgrade", _Upgrade); @@ -8767,7 +8768,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (arrayIndex == array.Length) { - throw new ArgumentException(); + ThrowArgumentException(); } array[arrayIndex] = new KeyValuePair("Via", _Via); @@ -8778,7 +8779,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (arrayIndex == array.Length) { - throw new ArgumentException(); + ThrowArgumentException(); } array[arrayIndex] = new KeyValuePair("Warning", _Warning); @@ -8789,7 +8790,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (arrayIndex == array.Length) { - throw new ArgumentException(); + ThrowArgumentException(); } array[arrayIndex] = new KeyValuePair("Allow", _Allow); @@ -8800,7 +8801,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (arrayIndex == array.Length) { - throw new ArgumentException(); + ThrowArgumentException(); } array[arrayIndex] = new KeyValuePair("Content-Length", _ContentLength); @@ -8811,7 +8812,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (arrayIndex == array.Length) { - throw new ArgumentException(); + ThrowArgumentException(); } array[arrayIndex] = new KeyValuePair("Content-Type", _ContentType); @@ -8822,7 +8823,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (arrayIndex == array.Length) { - throw new ArgumentException(); + ThrowArgumentException(); } array[arrayIndex] = new KeyValuePair("Content-Encoding", _ContentEncoding); @@ -8833,7 +8834,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (arrayIndex == array.Length) { - throw new ArgumentException(); + ThrowArgumentException(); } array[arrayIndex] = new KeyValuePair("Content-Language", _ContentLanguage); @@ -8844,7 +8845,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (arrayIndex == array.Length) { - throw new ArgumentException(); + ThrowArgumentException(); } array[arrayIndex] = new KeyValuePair("Content-Location", _ContentLocation); @@ -8855,7 +8856,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (arrayIndex == array.Length) { - throw new ArgumentException(); + ThrowArgumentException(); } array[arrayIndex] = new KeyValuePair("Content-MD5", _ContentMD5); @@ -8866,7 +8867,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (arrayIndex == array.Length) { - throw new ArgumentException(); + ThrowArgumentException(); } array[arrayIndex] = new KeyValuePair("Content-Range", _ContentRange); @@ -8877,7 +8878,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (arrayIndex == array.Length) { - throw new ArgumentException(); + ThrowArgumentException(); } array[arrayIndex] = new KeyValuePair("Expires", _Expires); @@ -8888,7 +8889,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (arrayIndex == array.Length) { - throw new ArgumentException(); + ThrowArgumentException(); } array[arrayIndex] = new KeyValuePair("Last-Modified", _LastModified); @@ -8899,7 +8900,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (arrayIndex == array.Length) { - throw new ArgumentException(); + ThrowArgumentException(); } array[arrayIndex] = new KeyValuePair("Accept-Ranges", _AcceptRanges); @@ -8910,7 +8911,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (arrayIndex == array.Length) { - throw new ArgumentException(); + ThrowArgumentException(); } array[arrayIndex] = new KeyValuePair("Age", _Age); @@ -8921,7 +8922,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (arrayIndex == array.Length) { - throw new ArgumentException(); + ThrowArgumentException(); } array[arrayIndex] = new KeyValuePair("ETag", _ETag); @@ -8932,7 +8933,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (arrayIndex == array.Length) { - throw new ArgumentException(); + ThrowArgumentException(); } array[arrayIndex] = new KeyValuePair("Location", _Location); @@ -8943,7 +8944,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (arrayIndex == array.Length) { - throw new ArgumentException(); + ThrowArgumentException(); } array[arrayIndex] = new KeyValuePair("Proxy-Autheticate", _ProxyAutheticate); @@ -8954,7 +8955,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (arrayIndex == array.Length) { - throw new ArgumentException(); + ThrowArgumentException(); } array[arrayIndex] = new KeyValuePair("Retry-After", _RetryAfter); @@ -8965,7 +8966,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (arrayIndex == array.Length) { - throw new ArgumentException(); + ThrowArgumentException(); } array[arrayIndex] = new KeyValuePair("Server", _Server); @@ -8976,7 +8977,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (arrayIndex == array.Length) { - throw new ArgumentException(); + ThrowArgumentException(); } array[arrayIndex] = new KeyValuePair("Set-Cookie", _SetCookie); @@ -8987,7 +8988,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (arrayIndex == array.Length) { - throw new ArgumentException(); + ThrowArgumentException(); } array[arrayIndex] = new KeyValuePair("Vary", _Vary); @@ -8998,7 +8999,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (arrayIndex == array.Length) { - throw new ArgumentException(); + ThrowArgumentException(); } array[arrayIndex] = new KeyValuePair("WWW-Authenticate", _WWWAuthenticate); @@ -9009,7 +9010,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (arrayIndex == array.Length) { - throw new ArgumentException(); + ThrowArgumentException(); } array[arrayIndex] = new KeyValuePair("Access-Control-Allow-Credentials", _AccessControlAllowCredentials); @@ -9020,7 +9021,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (arrayIndex == array.Length) { - throw new ArgumentException(); + ThrowArgumentException(); } array[arrayIndex] = new KeyValuePair("Access-Control-Allow-Headers", _AccessControlAllowHeaders); @@ -9031,7 +9032,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (arrayIndex == array.Length) { - throw new ArgumentException(); + ThrowArgumentException(); } array[arrayIndex] = new KeyValuePair("Access-Control-Allow-Methods", _AccessControlAllowMethods); @@ -9042,7 +9043,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (arrayIndex == array.Length) { - throw new ArgumentException(); + ThrowArgumentException(); } array[arrayIndex] = new KeyValuePair("Access-Control-Allow-Origin", _AccessControlAllowOrigin); @@ -9053,7 +9054,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (arrayIndex == array.Length) { - throw new ArgumentException(); + ThrowArgumentException(); } array[arrayIndex] = new KeyValuePair("Access-Control-Expose-Headers", _AccessControlExposeHeaders); @@ -9064,7 +9065,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (arrayIndex == array.Length) { - throw new ArgumentException(); + ThrowArgumentException(); } array[arrayIndex] = new KeyValuePair("Access-Control-Max-Age", _AccessControlMaxAge); @@ -9535,603 +9536,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } - public unsafe void Append(byte[] keyBytes, int keyOffset, int keyLength, string value) - { - fixed (byte* ptr = &keyBytes[keyOffset]) - { - var pUB = ptr; - var pUL = (ulong*)pUB; - var pUI = (uint*)pUB; - var pUS = (ushort*)pUB; - switch (keyLength) - { - case 13: - { - if ((((pUL[0] & 16131893727263186911uL) == 5711458528024281411uL) && ((pUI[2] & 3755991007u) == 1330795598u) && ((pUB[12] & 223u) == 76u))) - { - if (((_bits & 1L) != 0)) - { - _CacheControl = AppendValue(_CacheControl, value); - } - else - { - _bits |= 1L; - _CacheControl = new StringValues(value); - } - return; - } - - if ((((pUL[0] & 18437701552104792031uL) == 3266321689424580419uL) && ((pUI[2] & 3755991007u) == 1196310866u) && ((pUB[12] & 223u) == 69u))) - { - if (((_bits & 131072L) != 0)) - { - _ContentRange = AppendValue(_ContentRange, value); - } - else - { - _bits |= 131072L; - _ContentRange = new StringValues(value); - } - return; - } - - if ((((pUL[0] & 16131858680330051551uL) == 4922237774822850892uL) && ((pUI[2] & 3755991007u) == 1162430025u) && ((pUB[12] & 223u) == 68u))) - { - if (((_bits & 524288L) != 0)) - { - _LastModified = AppendValue(_LastModified, value); - } - else - { - _bits |= 524288L; - _LastModified = new StringValues(value); - } - return; - } - - if ((((pUL[0] & 16140865742145839071uL) == 5921481788798223169uL) && ((pUI[2] & 3755991007u) == 1162300993u) && ((pUB[12] & 223u) == 83u))) - { - if (((_bits & 1048576L) != 0)) - { - _AcceptRanges = AppendValue(_AcceptRanges, value); - } - else - { - _bits |= 1048576L; - _AcceptRanges = new StringValues(value); - } - return; - } - } - break; - - case 10: - { - if ((((pUL[0] & 16131858542891098079uL) == 5283922227757993795uL) && ((pUS[4] & 57311u) == 20047u))) - { - if (((_bits & 2L) != 0)) - { - _Connection = AppendValue(_Connection, value); - } - else - { - _bits |= 2L; - _Connection = new StringValues(value); - _rawConnection = null; - } - return; - } - - if ((((pUL[0] & 16131858680330051551uL) == 5281668125874799947uL) && ((pUS[4] & 57311u) == 17750u))) - { - if (((_bits & 8L) != 0)) - { - _KeepAlive = AppendValue(_KeepAlive, value); - } - else - { - _bits |= 8L; - _KeepAlive = new StringValues(value); - } - return; - } - - if ((((pUL[0] & 16131858543427968991uL) == 5426643225946637651uL) && ((pUS[4] & 57311u) == 17737u))) - { - if (((_bits & 134217728L) != 0)) - { - _SetCookie = AppendValue(_SetCookie, value); - } - else - { - _bits |= 134217728L; - _SetCookie = new StringValues(value); - } - return; - } - } - break; - - case 4: - { - if ((((pUI[0] & 3755991007u) == 1163149636u))) - { - if (((_bits & 4L) != 0)) - { - _Date = AppendValue(_Date, value); - } - else - { - _bits |= 4L; - _Date = new StringValues(value); - _rawDate = null; - } - return; - } - - if ((((pUI[0] & 3755991007u) == 1195463749u))) - { - if (((_bits & 4194304L) != 0)) - { - _ETag = AppendValue(_ETag, value); - } - else - { - _bits |= 4194304L; - _ETag = new StringValues(value); - } - return; - } - - if ((((pUI[0] & 3755991007u) == 1498562902u))) - { - if (((_bits & 268435456L) != 0)) - { - _Vary = AppendValue(_Vary, value); - } - else - { - _bits |= 268435456L; - _Vary = new StringValues(value); - } - return; - } - } - break; - - case 6: - { - if ((((pUI[0] & 3755991007u) == 1195463248u) && ((pUS[2] & 57311u) == 16717u))) - { - if (((_bits & 16L) != 0)) - { - _Pragma = AppendValue(_Pragma, value); - } - else - { - _bits |= 16L; - _Pragma = new StringValues(value); - } - return; - } - - if ((((pUI[0] & 3755991007u) == 1448232275u) && ((pUS[2] & 57311u) == 21061u))) - { - if (((_bits & 67108864L) != 0)) - { - _Server = AppendValue(_Server, value); - } - else - { - _bits |= 67108864L; - _Server = new StringValues(value); - _rawServer = null; - } - return; - } - } - break; - - case 7: - { - if ((((pUI[0] & 3755991007u) == 1229017684u) && ((pUS[2] & 57311u) == 17740u) && ((pUB[6] & 223u) == 82u))) - { - if (((_bits & 32L) != 0)) - { - _Trailer = AppendValue(_Trailer, value); - } - else - { - _bits |= 32L; - _Trailer = new StringValues(value); - } - return; - } - - if ((((pUI[0] & 3755991007u) == 1380405333u) && ((pUS[2] & 57311u) == 17473u) && ((pUB[6] & 223u) == 69u))) - { - if (((_bits & 128L) != 0)) - { - _Upgrade = AppendValue(_Upgrade, value); - } - else - { - _bits |= 128L; - _Upgrade = new StringValues(value); - } - return; - } - - if ((((pUI[0] & 3755991007u) == 1314013527u) && ((pUS[2] & 57311u) == 20041u) && ((pUB[6] & 223u) == 71u))) - { - if (((_bits & 512L) != 0)) - { - _Warning = AppendValue(_Warning, value); - } - else - { - _bits |= 512L; - _Warning = new StringValues(value); - } - return; - } - - if ((((pUI[0] & 3755991007u) == 1230002245u) && ((pUS[2] & 57311u) == 17746u) && ((pUB[6] & 223u) == 83u))) - { - if (((_bits & 262144L) != 0)) - { - _Expires = AppendValue(_Expires, value); - } - else - { - _bits |= 262144L; - _Expires = new StringValues(value); - } - return; - } - } - break; - - case 17: - { - if ((((pUL[0] & 16131858542891098079uL) == 5928221808112259668uL) && ((pUL[1] & 16131858542891098111uL) == 5641115115480565037uL) && ((pUB[16] & 223u) == 71u))) - { - if (((_bits & 64L) != 0)) - { - _TransferEncoding = AppendValue(_TransferEncoding, value); - } - else - { - _bits |= 64L; - _TransferEncoding = new StringValues(value); - _rawTransferEncoding = null; - } - return; - } - - if ((((pUL[0] & 16131893727263186911uL) == 6143241228466999888uL) && ((pUL[1] & 16131858542891098079uL) == 6071207754897639508uL) && ((pUB[16] & 223u) == 69u))) - { - if (((_bits & 16777216L) != 0)) - { - _ProxyAutheticate = AppendValue(_ProxyAutheticate, value); - } - else - { - _bits |= 16777216L; - _ProxyAutheticate = new StringValues(value); - } - return; - } - } - break; - - case 3: - { - if ((((pUS[0] & 57311u) == 18774u) && ((pUB[2] & 223u) == 65u))) - { - if (((_bits & 256L) != 0)) - { - _Via = AppendValue(_Via, value); - } - else - { - _bits |= 256L; - _Via = new StringValues(value); - } - return; - } - - if ((((pUS[0] & 57311u) == 18241u) && ((pUB[2] & 223u) == 69u))) - { - if (((_bits & 2097152L) != 0)) - { - _Age = AppendValue(_Age, value); - } - else - { - _bits |= 2097152L; - _Age = new StringValues(value); - } - return; - } - } - break; - - case 5: - { - if ((((pUI[0] & 3755991007u) == 1330400321u) && ((pUB[4] & 223u) == 87u))) - { - if (((_bits & 1024L) != 0)) - { - _Allow = AppendValue(_Allow, value); - } - else - { - _bits |= 1024L; - _Allow = new StringValues(value); - } - return; - } - } - break; - - case 14: - { - if ((((pUL[0] & 18437701552104792031uL) == 3266321689424580419uL) && ((pUI[2] & 3755991007u) == 1196311884u) && ((pUS[6] & 57311u) == 18516u))) - { - if (((_bits & 2048L) != 0)) - { - _ContentLength = AppendValue(_ContentLength, value); - } - else - { - _bits |= 2048L; - _ContentLength = new StringValues(value); - _rawContentLength = null; - } - return; - } - } - break; - - case 12: - { - if ((((pUL[0] & 18437701552104792031uL) == 3266321689424580419uL) && ((pUI[2] & 3755991007u) == 1162893652u))) - { - if (((_bits & 4096L) != 0)) - { - _ContentType = AppendValue(_ContentType, value); - } - else - { - _bits |= 4096L; - _ContentType = new StringValues(value); - } - return; - } - } - break; - - case 16: - { - if ((((pUL[0] & 18437701552104792031uL) == 3266321689424580419uL) && ((pUL[1] & 16131858542891098079uL) == 5138124782612729413uL))) - { - if (((_bits & 8192L) != 0)) - { - _ContentEncoding = AppendValue(_ContentEncoding, value); - } - else - { - _bits |= 8192L; - _ContentEncoding = new StringValues(value); - } - return; - } - - if ((((pUL[0] & 18437701552104792031uL) == 3266321689424580419uL) && ((pUL[1] & 16131858542891098079uL) == 4992030546487820620uL))) - { - if (((_bits & 16384L) != 0)) - { - _ContentLanguage = AppendValue(_ContentLanguage, value); - } - else - { - _bits |= 16384L; - _ContentLanguage = new StringValues(value); - } - return; - } - - if ((((pUL[0] & 18437701552104792031uL) == 3266321689424580419uL) && ((pUL[1] & 16131858542891098079uL) == 5642809484339531596uL))) - { - if (((_bits & 32768L) != 0)) - { - _ContentLocation = AppendValue(_ContentLocation, value); - } - else - { - _bits |= 32768L; - _ContentLocation = new StringValues(value); - } - return; - } - - if ((((pUL[0] & 16131858543427968991uL) == 5211884407196440407uL) && ((pUL[1] & 16131858542891098079uL) == 4995689643909598789uL))) - { - if (((_bits & 536870912L) != 0)) - { - _WWWAuthenticate = AppendValue(_WWWAuthenticate, value); - } - else - { - _bits |= 536870912L; - _WWWAuthenticate = new StringValues(value); - } - return; - } - } - break; - - case 11: - { - if ((((pUL[0] & 18437701552104792031uL) == 3266321689424580419uL) && ((pUS[4] & 57311u) == 17485u) && ((pUB[10] & 255u) == 53u))) - { - if (((_bits & 65536L) != 0)) - { - _ContentMD5 = AppendValue(_ContentMD5, value); - } - else - { - _bits |= 65536L; - _ContentMD5 = new StringValues(value); - } - return; - } - - if ((((pUL[0] & 16131893727263186911uL) == 5062377317797741906uL) && ((pUS[4] & 57311u) == 17748u) && ((pUB[10] & 223u) == 82u))) - { - if (((_bits & 33554432L) != 0)) - { - _RetryAfter = AppendValue(_RetryAfter, value); - } - else - { - _bits |= 33554432L; - _RetryAfter = new StringValues(value); - } - return; - } - } - break; - - case 8: - { - if ((((pUL[0] & 16131858542891098079uL) == 5642809484339531596uL))) - { - if (((_bits & 8388608L) != 0)) - { - _Location = AppendValue(_Location, value); - } - else - { - _bits |= 8388608L; - _Location = new StringValues(value); - } - return; - } - } - break; - - case 32: - { - if ((((pUL[0] & 16140865742145839071uL) == 4840616791602578241uL) && ((pUL[1] & 16140865742145839071uL) == 4696493889984679503uL) && ((pUL[2] & 16131858680330051551uL) == 4995128798724705356uL) && ((pUL[3] & 16131858542891098079uL) == 6002244186580862276uL))) - { - if (((_bits & 1073741824L) != 0)) - { - _AccessControlAllowCredentials = AppendValue(_AccessControlAllowCredentials, value); - } - else - { - _bits |= 1073741824L; - _AccessControlAllowCredentials = new StringValues(value); - } - return; - } - } - break; - - case 28: - { - if ((((pUL[0] & 16140865742145839071uL) == 4840616791602578241uL) && ((pUL[1] & 16140865742145839071uL) == 4696493889984679503uL) && ((pUL[2] & 16131858680330051551uL) == 4703244745433893964uL) && ((pUI[6] & 3755991007u) == 1397900612u))) - { - if (((_bits & 2147483648L) != 0)) - { - _AccessControlAllowHeaders = AppendValue(_AccessControlAllowHeaders, value); - } - else - { - _bits |= 2147483648L; - _AccessControlAllowHeaders = new StringValues(value); - } - return; - } - - if ((((pUL[0] & 16140865742145839071uL) == 4840616791602578241uL) && ((pUL[1] & 16140865742145839071uL) == 4696493889984679503uL) && ((pUL[2] & 16131858680330051551uL) == 6072344529712663628uL) && ((pUI[6] & 3755991007u) == 1396985672u))) - { - if (((_bits & 4294967296L) != 0)) - { - _AccessControlAllowMethods = AppendValue(_AccessControlAllowMethods, value); - } - else - { - _bits |= 4294967296L; - _AccessControlAllowMethods = new StringValues(value); - } - return; - } - } - break; - - case 27: - { - if ((((pUL[0] & 16140865742145839071uL) == 4840616791602578241uL) && ((pUL[1] & 16140865742145839071uL) == 4696493889984679503uL) && ((pUL[2] & 16131858680330051551uL) == 5283372369015950412uL) && ((pUS[12] & 57311u) == 18759u) && ((pUB[26] & 223u) == 78u))) - { - if (((_bits & 8589934592L) != 0)) - { - _AccessControlAllowOrigin = AppendValue(_AccessControlAllowOrigin, value); - } - else - { - _bits |= 8589934592L; - _AccessControlAllowOrigin = new StringValues(value); - } - return; - } - } - break; - - case 29: - { - if ((((pUL[0] & 16140865742145839071uL) == 4840616791602578241uL) && ((pUL[1] & 16140865742145839071uL) == 4984724266136391247uL) && ((pUL[2] & 16131893727263186911uL) == 4992289962713895000uL) && ((pUI[6] & 3755991007u) == 1380271169u) && ((pUB[28] & 223u) == 83u))) - { - if (((_bits & 17179869184L) != 0)) - { - _AccessControlExposeHeaders = AppendValue(_AccessControlExposeHeaders, value); - } - else - { - _bits |= 17179869184L; - _AccessControlExposeHeaders = new StringValues(value); - } - return; - } - } - break; - - case 22: - { - if ((((pUL[0] & 16140865742145839071uL) == 4840616791602578241uL) && ((pUL[1] & 16140865742145839071uL) == 5561185018439814735uL) && ((pUI[4] & 3758088159u) == 1093490753u) && ((pUS[10] & 57311u) == 17735u))) - { - if (((_bits & 34359738368L) != 0)) - { - _AccessControlMaxAge = AppendValue(_AccessControlMaxAge, value); - } - else - { - _bits |= 34359738368L; - _AccessControlMaxAge = new StringValues(value); - } - return; - } - } - break; - } - } - var key = System.Text.Encoding.ASCII.GetString(keyBytes, keyOffset, keyLength); - StringValues existing; - Unknown.TryGetValue(key, out existing); - Unknown[key] = AppendValue(existing, value); - } + public partial struct Enumerator { public bool MoveNext() diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameHeaders.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameHeaders.cs index 45c9355349..596b973575 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameHeaders.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameHeaders.cs @@ -12,6 +12,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { public abstract class FrameHeaders : IHeaderDictionary { + protected bool _isReadOnly; protected Dictionary MaybeUnknown; protected Dictionary Unknown => MaybeUnknown ?? (MaybeUnknown = new Dictionary(StringComparer.OrdinalIgnoreCase)); @@ -26,6 +27,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } set { + if (_isReadOnly) + { + ThrowReadOnlyException(); + } SetValueFast(key, value); } } @@ -38,20 +43,50 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } set { + if (_isReadOnly) + { + ThrowReadOnlyException(); + } SetValueFast(key, value); } } + protected void ThrowReadOnlyException() + { + throw new InvalidOperationException("Headers are readonly, reponse has already started."); + } + + protected void ThrowArgumentException() + { + throw new ArgumentException(); + } + + protected void ThrowKeyNotFoundException() + { + throw new KeyNotFoundException(); + } + + protected void ThrowDuplicateKeyException() + { + throw new ArgumentException("An item with the same key has already been added."); + } + int ICollection>.Count => GetCountFast(); - bool ICollection>.IsReadOnly => false; + bool ICollection>.IsReadOnly => _isReadOnly; ICollection IDictionary.Keys => ((IDictionary)this).Select(pair => pair.Key).ToList(); ICollection IDictionary.Values => ((IDictionary)this).Select(pair => pair.Value).ToList(); + public void SetReadOnly() + { + _isReadOnly = true; + } + public void Reset() { + _isReadOnly = false; ClearFast(); } @@ -105,16 +140,28 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http void ICollection>.Add(KeyValuePair item) { + if (_isReadOnly) + { + ThrowReadOnlyException(); + } AddValueFast(item.Key, item.Value); } void IDictionary.Add(string key, StringValues value) { + if (_isReadOnly) + { + ThrowReadOnlyException(); + } AddValueFast(key, value); } void ICollection>.Clear() { + if (_isReadOnly) + { + ThrowReadOnlyException(); + } ClearFast(); } @@ -158,6 +205,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http bool IDictionary.Remove(string key) { + if (_isReadOnly) + { + ThrowReadOnlyException(); + } return RemoveFast(key); } diff --git a/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/KnownHeaders.cs b/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/KnownHeaders.cs index 92e133db89..76e7610b82 100644 --- a/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/KnownHeaders.cs +++ b/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/KnownHeaders.cs @@ -263,7 +263,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http }} else {{ - throw new System.Collections.Generic.KeyNotFoundException(); + ThrowKeyNotFoundException(); }} }} ")}}} @@ -271,7 +271,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ")}}} if (MaybeUnknown == null) {{ - throw new System.Collections.Generic.KeyNotFoundException(); + ThrowKeyNotFoundException(); }} return MaybeUnknown[key]; }} @@ -328,7 +328,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http {{ if ({header.TestBit()}) {{ - throw new ArgumentException(""An item with the same key has already been added.""); + ThrowDuplicateKeyException(); }} {header.SetBit()}; _{header.Identifier} = value;{(header.EnhancedSetter == false ? "" : $@" @@ -377,14 +377,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http {{ if (arrayIndex < 0) {{ - throw new ArgumentException(); + ThrowArgumentException(); }} {Each(loop.Headers, header => $@" if ({header.TestBit()}) {{ if (arrayIndex == array.Length) {{ - throw new ArgumentException(); + ThrowArgumentException(); }} array[arrayIndex] = new KeyValuePair(""{header.Name}"", _{header.Identifier}); @@ -415,6 +415,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http }} ")} }}" : "")} + {(loop.ClassName == "FrameRequestHeaders" ? $@" public unsafe void Append(byte[] keyBytes, int keyOffset, int keyLength, string value) {{ fixed (byte* ptr = &keyBytes[keyOffset]) @@ -449,7 +450,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http StringValues existing; Unknown.TryGetValue(key, out existing); Unknown[key] = AppendValue(existing, value); - }} + }}" : "")} public partial struct Enumerator {{ public bool MoveNext() From f8aa1a676a338e8314d0aacb293fb732e3fdf174 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Sat, 13 Feb 2016 05:51:54 +0000 Subject: [PATCH 0601/1662] Pass ServerInformation as property of ServiceContext --- .../Http/Connection.cs | 4 +- .../Http/Frame.cs | 3 +- .../Http/FrameOfT.cs | 5 +- .../Http/TcpListener.cs | 4 +- .../Http/TcpListenerPrimary.cs | 4 +- .../Http/TcpListenerSecondary.cs | 2 +- .../IKestrelServerInformation.cs | 14 ++--- .../Infrastructure/HttpComponentFactory.cs | 15 +++-- .../Infrastructure/IHttpComponentFactory.cs | 2 + .../KestrelServer.cs | 6 +- .../KestrelServerInformation.cs | 17 +----- .../KestrelServerPoolingParameters.cs | 43 ++++++++++++++ .../ServerFactory.cs | 3 + .../ServiceContext.cs | 10 +--- .../RequestTests.cs | 2 +- .../ConnectionFilterTests.cs | 16 ++--- .../EngineTests.cs | 9 +-- .../FrameResponseHeadersTests.cs | 13 +++- .../HttpsConnectionFilterTests.cs | 59 ++++++++----------- .../KestrelServerInformationTests.cs | 48 +++++++++++---- .../TestServiceContext.cs | 13 +++- 21 files changed, 174 insertions(+), 118 deletions(-) create mode 100644 src/Microsoft.AspNetCore.Server.Kestrel/KestrelServerPoolingParameters.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Connection.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Connection.cs index 15f57a8076..3d335971e5 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Connection.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Connection.cs @@ -61,7 +61,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } // Don't initialize _frame until SocketInput and SocketOutput are set to their final values. - if (ConnectionFilter == null) + if (ServerInformation.ConnectionFilter == null) { SocketInput = _rawSocketInput; SocketOutput = _rawSocketOutput; @@ -81,7 +81,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http try { - ConnectionFilter.OnConnectionAsync(_filterContext).ContinueWith((task, state) => + ServerInformation.ConnectionFilter.OnConnectionAsync(_filterContext).ContinueWith((task, state) => { var connection = (Connection)state; diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs index b84f63e87f..f40d4a06ee 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs @@ -45,6 +45,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http private readonly object _onStartingSync = new Object(); private readonly object _onCompletedSync = new Object(); + protected bool _poolingPermitted = true; private Headers _frameHeaders; private Streams _frameStreams; @@ -279,7 +280,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http DuplexStream = null; var frameStreams = _frameStreams; _frameStreams = null; - HttpComponentFactory.DisposeStreams(frameStreams, poolingPermitted: (poolingPermitted && ReuseStreams)); + HttpComponentFactory.DisposeStreams(frameStreams, poolingPermitted); } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameOfT.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameOfT.cs index 1c0191c6cb..affb4d5867 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameOfT.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameOfT.cs @@ -131,14 +131,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } catch (Exception ex) { + // Error occurred, do not return components to pool + _poolingPermitted = false; Log.LogWarning(0, ex, "Connection processing ended abnormally"); } finally { - // Error occurred, do not return components to pool - ResetComponents(poolingPermitted: false); try { + ResetComponents(poolingPermitted: _poolingPermitted); _abortedCts = null; // If _requestAborted is set, the connection has already been closed. diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/TcpListener.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/TcpListener.cs index 4c0f8f19ba..fc845b5239 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/TcpListener.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/TcpListener.cs @@ -23,7 +23,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { var socket = new UvTcpHandle(Log); socket.Init(Thread.Loop, Thread.QueueCloseHandle); - socket.NoDelay(NoDelay); + socket.NoDelay(ServerInformation.NoDelay); socket.Bind(ServerAddress); socket.Listen(Constants.ListenBacklog, (stream, status, error, state) => ConnectionCallback(stream, status, error, state), this); return socket; @@ -41,7 +41,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http try { acceptSocket.Init(Thread.Loop, Thread.QueueCloseHandle); - acceptSocket.NoDelay(NoDelay); + acceptSocket.NoDelay(ServerInformation.NoDelay); listenSocket.Accept(acceptSocket); DispatchConnection(acceptSocket); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/TcpListenerPrimary.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/TcpListenerPrimary.cs index 6c1697cfe8..e791d30568 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/TcpListenerPrimary.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/TcpListenerPrimary.cs @@ -25,7 +25,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { var socket = new UvTcpHandle(Log); socket.Init(Thread.Loop, Thread.QueueCloseHandle); - socket.NoDelay(NoDelay); + socket.NoDelay(ServerInformation.NoDelay); socket.Bind(ServerAddress); socket.Listen(Constants.ListenBacklog, (stream, status, error, state) => ConnectionCallback(stream, status, error, state), this); return socket; @@ -43,7 +43,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http try { acceptSocket.Init(Thread.Loop, Thread.QueueCloseHandle); - acceptSocket.NoDelay(NoDelay); + acceptSocket.NoDelay(ServerInformation.NoDelay); listenSocket.Accept(acceptSocket); DispatchConnection(acceptSocket); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/TcpListenerSecondary.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/TcpListenerSecondary.cs index ce0616171b..d52ac62b7e 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/TcpListenerSecondary.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/TcpListenerSecondary.cs @@ -21,7 +21,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { var acceptSocket = new UvTcpHandle(Log); acceptSocket.Init(Thread.Loop, Thread.QueueCloseHandle); - acceptSocket.NoDelay(NoDelay); + acceptSocket.NoDelay(ServerInformation.NoDelay); return acceptSocket; } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/IKestrelServerInformation.cs b/src/Microsoft.AspNetCore.Server.Kestrel/IKestrelServerInformation.cs index a08db08ea6..fa81591879 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/IKestrelServerInformation.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/IKestrelServerInformation.cs @@ -12,17 +12,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel bool NoDelay { get; set; } /// - /// Gets or sets a flag that instructs whether it is safe to - /// reuse the Request and Response objects + /// Gets or sets values that instruct whether it is safe to + /// pool the Request and Response objects, Headers etc /// for another request after the Response's OnCompleted callback has fired. - /// When this is set to true it is not safe to retain references to these streams after this event has fired. - /// It is false by default. + /// When these values are greater than zero it is not safe to retain references to feature components after this event has fired. + /// They are zero by default. /// - /// - /// When this is set to true it is not safe to retain references to these streams after this event has fired. - /// It is false by default. - /// - bool ReuseStreams { get; set; } + KestrelServerPoolingParameters PoolingParameters { get; } IConnectionFilter ConnectionFilter { get; set; } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/HttpComponentFactory.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/HttpComponentFactory.cs index 98cdfef311..f58102c1bb 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/HttpComponentFactory.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/HttpComponentFactory.cs @@ -2,17 +2,24 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Collections.Concurrent; -using Microsoft.AspNetCore.Server.Kestrel.Http; using System.Text; +using Microsoft.AspNetCore.Server.Kestrel.Http; namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure { class HttpComponentFactory : IHttpComponentFactory { - private const int _maxPooledComponents = 128; + private ConcurrentQueue _streamPool = new ConcurrentQueue(); private ConcurrentQueue _headerPool = new ConcurrentQueue(); + public IKestrelServerInformation ServerInformation { get; set; } + + public HttpComponentFactory(IKestrelServerInformation serverInformation) + { + ServerInformation = serverInformation; + } + public Streams CreateStreams(FrameContext owner) { Streams streams; @@ -29,7 +36,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure public void DisposeStreams(Streams streams, bool poolingPermitted) { - if (poolingPermitted && _streamPool.Count < _maxPooledComponents) + if (poolingPermitted && _streamPool.Count < ServerInformation.PoolingParameters.MaxPooledStreams) { streams.Uninitialize(); @@ -53,7 +60,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure public void DisposeHeaders(Headers headers, bool poolingPermitted) { - if (poolingPermitted && _headerPool.Count < _maxPooledComponents) + if (poolingPermitted && _headerPool.Count < ServerInformation.PoolingParameters.MaxPooledHeaders) { headers.Uninitialize(); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/IHttpComponentFactory.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/IHttpComponentFactory.cs index b02300774a..620c663fbb 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/IHttpComponentFactory.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/IHttpComponentFactory.cs @@ -7,6 +7,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure { interface IHttpComponentFactory { + IKestrelServerInformation ServerInformation { get; set; } + Streams CreateStreams(FrameContext owner); void DisposeStreams(Streams streams, bool poolingPermitted); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServer.cs b/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServer.cs index 6e3826d971..b6768de672 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServer.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServer.cs @@ -54,9 +54,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel try { var information = (KestrelServerInformation)Features.Get(); + var componentFactory = Features.Get(); var dateHeaderValueManager = new DateHeaderValueManager(); var trace = new KestrelTrace(_logger); - var componentFactory = new HttpComponentFactory(); var engine = new KestrelEngine(new ServiceContext { FrameFactory = (context, remoteEP, localEP, prepareRequest) => @@ -67,9 +67,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel Log = trace, ThreadPool = new LoggingThreadPool(trace), DateHeaderValueManager = dateHeaderValueManager, - ConnectionFilter = information.ConnectionFilter, - NoDelay = information.NoDelay, - ReuseStreams = information.ReuseStreams, + ServerInformation = information, HttpComponentFactory = componentFactory }); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServerInformation.cs b/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServerInformation.cs index 6f05a1da58..b1d4d335ab 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServerInformation.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServerInformation.cs @@ -22,7 +22,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel Addresses = GetAddresses(configuration); ThreadCount = GetThreadCount(configuration); NoDelay = GetNoDelay(configuration); - ReuseStreams = GetReuseStreams(configuration); + PoolingParameters = new KestrelServerPoolingParameters(configuration); } public ICollection Addresses { get; } @@ -31,7 +31,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel public bool NoDelay { get; set; } - public bool ReuseStreams { get; set; } + public KestrelServerPoolingParameters PoolingParameters { get; } public IConnectionFilter ConnectionFilter { get; set; } @@ -110,18 +110,5 @@ namespace Microsoft.AspNetCore.Server.Kestrel return true; } - - private static bool GetReuseStreams(IConfiguration configuration) - { - var reuseStreamsString = configuration["kestrel.reuseStreams"]; - - bool reuseStreams; - if (bool.TryParse(reuseStreamsString, out reuseStreams)) - { - return reuseStreams; - } - - return false; - } } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServerPoolingParameters.cs b/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServerPoolingParameters.cs new file mode 100644 index 0000000000..9a019d1d94 --- /dev/null +++ b/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServerPoolingParameters.cs @@ -0,0 +1,43 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Globalization; +using Microsoft.Extensions.Configuration; + +namespace Microsoft.AspNetCore.Server.Kestrel +{ + public class KestrelServerPoolingParameters + { + public KestrelServerPoolingParameters(IConfiguration configuration) + { + if (configuration == null) + { + throw new ArgumentNullException(nameof(configuration)); + } + + MaxPooledStreams = GetPooledCount(configuration["kestrel.maxPooledStreams"]); + MaxPooledHeaders = GetPooledCount(configuration["kestrel.maxPooledHeaders"]); + } + + public int MaxPooledStreams { get; set; } + + public int MaxPooledHeaders { get; set; } + + private static int GetPooledCount(string countString) + { + if (string.IsNullOrEmpty(countString)) + { + return 0; + } + + int count; + if (int.TryParse(countString, NumberStyles.Integer, CultureInfo.InvariantCulture, out count)) + { + return count; + } + + return 0; + } + } +} diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/ServerFactory.cs b/src/Microsoft.AspNetCore.Server.Kestrel/ServerFactory.cs index 06a7fb3686..c6bf62f604 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/ServerFactory.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/ServerFactory.cs @@ -6,6 +6,7 @@ using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting.Server; using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Server.Features; +using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Logging; @@ -28,8 +29,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel public IServer CreateServer(IConfiguration configuration) { var information = new KestrelServerInformation(configuration); + var componentFactory = new HttpComponentFactory(information); var serverFeatures = new FeatureCollection(); serverFeatures.Set(information); + serverFeatures.Set(componentFactory); serverFeatures.Set(information); return new KestrelServer(serverFeatures, _appLifetime, _loggerFactory.CreateLogger("Microsoft.AspNetCore.Server.Kestrel")); } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/ServiceContext.cs b/src/Microsoft.AspNetCore.Server.Kestrel/ServiceContext.cs index b0d26c0953..f702fd1c5e 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/ServiceContext.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/ServiceContext.cs @@ -24,9 +24,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel ThreadPool = context.ThreadPool; FrameFactory = context.FrameFactory; DateHeaderValueManager = context.DateHeaderValueManager; - ConnectionFilter = context.ConnectionFilter; - NoDelay = context.NoDelay; - ReuseStreams = context.ReuseStreams; + ServerInformation = context.ServerInformation; HttpComponentFactory = context.HttpComponentFactory; } @@ -40,11 +38,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel public DateHeaderValueManager DateHeaderValueManager { get; set; } - public IConnectionFilter ConnectionFilter { get; set; } - - public bool NoDelay { get; set; } - - public bool ReuseStreams { get; set; } + public IKestrelServerInformation ServerInformation { get; set; } internal IHttpComponentFactory HttpComponentFactory { get; set; } } diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs index 3f9b0870dd..a6fac125ea 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs @@ -132,7 +132,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [ConditionalFact] [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Test hangs after execution on Mono.")] - public async Task RequestPathIsNormalized() + public void RequestPathIsNormalized() { var port = PortManager.GetPort(); var config = new ConfigurationBuilder().AddInMemoryCollection( diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionFilterTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionFilterTests.cs index 353d998e5d..dce414fa3e 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionFilterTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionFilterTests.cs @@ -36,10 +36,8 @@ namespace Microsoft.AspNetCore.Server.KestrelTests public async Task CanReadAndWriteWithRewritingConnectionFilter() { var filter = new RewritingConnectionFilter(); - var serviceContext = new TestServiceContext() - { - ConnectionFilter = filter - }; + var serviceContext = new TestServiceContext(filter); + var sendString = "POST / HTTP/1.0\r\n\r\nHello World?"; using (var server = new TestServer(App, serviceContext)) @@ -62,10 +60,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Test hangs after execution on Mono.")] public async Task CanReadAndWriteWithAsyncConnectionFilter() { - var serviceContext = new TestServiceContext() - { - ConnectionFilter = new AsyncConnectionFilter() - }; + var serviceContext = new TestServiceContext(new AsyncConnectionFilter()); using (var server = new TestServer(App, serviceContext)) { @@ -87,10 +82,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Test hangs after execution on Mono.")] public async Task ThrowingSynchronousConnectionFilterDoesNotCrashServer() { - var serviceContext = new TestServiceContext() - { - ConnectionFilter = new ThrowingConnectionFilter() - }; + var serviceContext = new TestServiceContext(new ThrowingConnectionFilter()); using (var server = new TestServer(App, serviceContext)) { diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs index 42315796d5..73c159299d 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs @@ -35,10 +35,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests new TestServiceContext() }, { - new TestServiceContext - { - ConnectionFilter = new PassThroughConnectionFilter() - } + new TestServiceContext(new PassThroughConnectionFilter()) } }; } @@ -188,7 +185,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [MemberData(nameof(ConnectionFilterData))] public async Task ReuseStreamsOn(ServiceContext testContext) { - testContext.ReuseStreams = true; + testContext.ServerInformation.PoolingParameters.MaxPooledStreams = 120; var streamCount = 0; var loopCount = 20; @@ -231,7 +228,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [MemberData(nameof(ConnectionFilterData))] public async Task ReuseStreamsOff(ServiceContext testContext) { - testContext.ReuseStreams = false; + testContext.ServerInformation.PoolingParameters.MaxPooledStreams = 0; var streamCount = 0; var loopCount = 20; diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameResponseHeadersTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameResponseHeadersTests.cs index 8bdf782e9f..30c03a0b35 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameResponseHeadersTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameResponseHeadersTests.cs @@ -6,6 +6,7 @@ using System.Collections.Generic; using Microsoft.AspNetCore.Server.Kestrel; using Microsoft.AspNetCore.Server.Kestrel.Http; using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; +using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Primitives; using Xunit; @@ -16,12 +17,15 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [Fact] public void InitialDictionaryContainsServerAndDate() { + var configuration = new ConfigurationBuilder().Build(); + var serverInformation = new KestrelServerInformation(configuration); var connectionContext = new ConnectionContext { DateHeaderValueManager = new DateHeaderValueManager(), ServerAddress = ServerAddress.FromUrl("http://localhost:5000"), - HttpComponentFactory = new HttpComponentFactory() - }; + ServerInformation = serverInformation, + HttpComponentFactory = new HttpComponentFactory(serverInformation) + }; var frame = new Frame(application: null, context: connectionContext) .InitializeHeaders(); @@ -47,11 +51,14 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [Fact] public void InitialEntriesCanBeCleared() { + var configuration = new ConfigurationBuilder().Build(); + var serverInformation = new KestrelServerInformation(configuration); var connectionContext = new ConnectionContext { DateHeaderValueManager = new DateHeaderValueManager(), ServerAddress = ServerAddress.FromUrl("http://localhost:5000"), - HttpComponentFactory = new HttpComponentFactory() + ServerInformation = serverInformation, + HttpComponentFactory = new HttpComponentFactory(serverInformation) }; var frame = new Frame(application: null, context: connectionContext) .InitializeHeaders(); diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/HttpsConnectionFilterTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/HttpsConnectionFilterTests.cs index e3bed702bc..3758a54fc3 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/HttpsConnectionFilterTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/HttpsConnectionFilterTests.cs @@ -59,13 +59,11 @@ namespace Microsoft.AspNetCore.Server.KestrelTests handler.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true; #endif var serverAddress = $"https://localhost:{TestServer.GetNextPort()}/"; - var serviceContext = new TestServiceContext() - { - ConnectionFilter = new HttpsConnectionFilter( + var serviceContext = new TestServiceContext(new HttpsConnectionFilter( new HttpsConnectionFilterOptions - { ServerCertificate = new X509Certificate2(@"TestResources/testCert.pfx", "testPassword")}, + { ServerCertificate = new X509Certificate2(@"TestResources/testCert.pfx", "testPassword") }, new NoOpConnectionFilter()) - }; + ); using (var server = new TestServer(App, serviceContext, serverAddress)) { @@ -108,16 +106,14 @@ namespace Microsoft.AspNetCore.Server.KestrelTests #endif var serverAddress = $"https://localhost:{TestServer.GetNextPort()}/"; - var serviceContext = new TestServiceContext() - { - ConnectionFilter = new HttpsConnectionFilter( + var serviceContext = new TestServiceContext(new HttpsConnectionFilter( new HttpsConnectionFilterOptions { ServerCertificate = new X509Certificate2(@"TestResources/testCert.pfx", "testPassword"), ClientCertificateMode = ClientCertificateMode.RequireCertificate }, new NoOpConnectionFilter()) - }; + ); using (var server = new TestServer(App, serviceContext, serverAddress)) { @@ -157,16 +153,14 @@ namespace Microsoft.AspNetCore.Server.KestrelTests #endif var serverAddress = $"https://localhost:{TestServer.GetNextPort()}/"; - var serviceContext = new TestServiceContext() - { - ConnectionFilter = new HttpsConnectionFilter( - new HttpsConnectionFilterOptions - { - ServerCertificate = new X509Certificate2(@"TestResources/testCert.pfx", "testPassword"), - ClientCertificateMode = ClientCertificateMode.AllowCertificate - }, - new NoOpConnectionFilter()) - }; + var serviceContext = new TestServiceContext(new HttpsConnectionFilter( + new HttpsConnectionFilterOptions + { + ServerCertificate = new X509Certificate2(@"TestResources/testCert.pfx", "testPassword"), + ClientCertificateMode = ClientCertificateMode.AllowCertificate + }, + new NoOpConnectionFilter()) + ); RequestDelegate app = context => { @@ -209,17 +203,15 @@ namespace Microsoft.AspNetCore.Server.KestrelTests #endif var serverAddress = $"https://localhost:{TestServer.GetNextPort()}/"; - var serviceContext = new TestServiceContext() - { - ConnectionFilter = new HttpsConnectionFilter( - new HttpsConnectionFilterOptions - { - ServerCertificate = new X509Certificate2(@"TestResources/testCert.pfx", "testPassword"), - ClientCertificateMode = ClientCertificateMode.RequireCertificate, - ClientCertificateValidation = (certificate, chain, sslPolicyErrors) => true - }, - new NoOpConnectionFilter()) - }; + var serviceContext = new TestServiceContext(new HttpsConnectionFilter( + new HttpsConnectionFilterOptions + { + ServerCertificate = new X509Certificate2(@"TestResources/testCert.pfx", "testPassword"), + ClientCertificateMode = ClientCertificateMode.RequireCertificate, + ClientCertificateValidation = (certificate, chain, sslPolicyErrors) => true + }, + new NoOpConnectionFilter()) + ); RequestDelegate app = context => { @@ -281,15 +273,14 @@ namespace Microsoft.AspNetCore.Server.KestrelTests #endif var serverAddress = $"https://localhost:{TestServer.GetNextPort()}/"; - var serviceContext = new TestServiceContext() - { - ConnectionFilter = new HttpsConnectionFilter( + var serviceContext = new TestServiceContext( + new HttpsConnectionFilter( new HttpsConnectionFilterOptions { ServerCertificate = new X509Certificate2(@"TestResources/testCert.pfx", "testPassword") }, new NoOpConnectionFilter()) - }; + ); RequestDelegate app = context => context.Response.WriteAsync(context.Request.Scheme); diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerInformationTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerInformationTests.cs index 9818d9d426..d8594e623c 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerInformationTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerInformationTests.cs @@ -86,19 +86,19 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } [Theory] - [InlineData(null, false)] - [InlineData("", false)] - [InlineData("false", false)] - [InlineData("False", false)] - [InlineData("true", true)] - [InlineData("True", true)] - [InlineData("Foo", false)] - [InlineData("FooBar", false)] - public void SetReuseStreamsUsingConfiguration(string input, bool expected) + [InlineData(null, 0)] + [InlineData("", 0)] + [InlineData("0", 0)] + [InlineData("00", 0)] + [InlineData("0.0", 0)] + [InlineData("1", 1)] + [InlineData("16", 16)] + [InlineData("1000", 1000)] + public void SetMaxPooledStreamsUsingConfiguration(string input, int expected) { var values = new Dictionary { - { "kestrel.reuseStreams", input } + { "kestrel.maxPooledStreams", input } }; var configuration = new ConfigurationBuilder() @@ -107,7 +107,33 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var information = new KestrelServerInformation(configuration); - Assert.Equal(expected, information.ReuseStreams); + Assert.Equal(expected, information.PoolingParameters.MaxPooledStreams); + } + + + [Theory] + [InlineData(null, 0)] + [InlineData("", 0)] + [InlineData("0", 0)] + [InlineData("00", 0)] + [InlineData("0.0", 0)] + [InlineData("1", 1)] + [InlineData("16", 16)] + [InlineData("1000", 1000)] + public void SetMaxPooledHeadersUsingConfiguration(string input, int expected) + { + var values = new Dictionary + { + { "kestrel.maxPooledHeaders", input } + }; + + var configuration = new ConfigurationBuilder() + .AddInMemoryCollection(values) + .Build(); + + var information = new KestrelServerInformation(configuration); + + Assert.Equal(expected, information.PoolingParameters.MaxPooledHeaders); } private static int Clamp(int value, int min, int max) diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestServiceContext.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/TestServiceContext.cs index 679abaa3a7..0ac9c5c76d 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/TestServiceContext.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/TestServiceContext.cs @@ -3,8 +3,10 @@ using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Server.Kestrel; +using Microsoft.AspNetCore.Server.Kestrel.Filter; using Microsoft.AspNetCore.Server.Kestrel.Http; using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; +using Microsoft.Extensions.Configuration; namespace Microsoft.AspNetCore.Server.KestrelTests { @@ -18,7 +20,16 @@ namespace Microsoft.AspNetCore.Server.KestrelTests Log = new TestKestrelTrace(); ThreadPool = new LoggingThreadPool(Log); DateHeaderValueManager = new TestDateHeaderValueManager(); - HttpComponentFactory = new HttpComponentFactory(); + + var configuration = new ConfigurationBuilder().Build(); + ServerInformation = new KestrelServerInformation(configuration); + HttpComponentFactory = new HttpComponentFactory(ServerInformation); + } + + public TestServiceContext(IConnectionFilter filter) + : base() + { + ServerInformation.ConnectionFilter = filter; } public RequestDelegate App From b473402cb1c73671444b855b105438a3cc6fff93 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Sat, 13 Feb 2016 07:27:38 +0000 Subject: [PATCH 0602/1662] Fast header clear --- .../Http/Frame.cs | 10 +- .../Http/FrameHeaders.Generated.cs | 2002 ++++++++--------- .../KnownHeaders.cs | 59 +- 3 files changed, 1020 insertions(+), 1051 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs index f40d4a06ee..e00f0579d2 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs @@ -266,20 +266,22 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (_frameHeaders != null) { - RequestHeaders = null; - ResponseHeaders = null; var frameHeaders = _frameHeaders; _frameHeaders = null; + + RequestHeaders = null; + ResponseHeaders = null; HttpComponentFactory.DisposeHeaders(frameHeaders, poolingPermitted); } if (_frameStreams != null) { + var frameStreams = _frameStreams; + _frameStreams = null; + RequestBody = null; ResponseBody = null; DuplexStream = null; - var frameStreams = _frameStreams; - _frameStreams = null; HttpComponentFactory.DisposeStreams(frameStreams, poolingPermitted); } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameHeaders.Generated.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameHeaders.Generated.cs index b0561f2514..e8a93d9b4d 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameHeaders.Generated.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameHeaders.Generated.cs @@ -12,52 +12,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { private long _bits = 0; - - private StringValues _CacheControl; - private StringValues _Connection; - private StringValues _Date; - private StringValues _KeepAlive; - private StringValues _Pragma; - private StringValues _Trailer; - private StringValues _TransferEncoding; - private StringValues _Upgrade; - private StringValues _Via; - private StringValues _Warning; - private StringValues _Allow; - private StringValues _ContentLength; - private StringValues _ContentType; - private StringValues _ContentEncoding; - private StringValues _ContentLanguage; - private StringValues _ContentLocation; - private StringValues _ContentMD5; - private StringValues _ContentRange; - private StringValues _Expires; - private StringValues _LastModified; - private StringValues _Accept; - private StringValues _AcceptCharset; - private StringValues _AcceptEncoding; - private StringValues _AcceptLanguage; - private StringValues _Authorization; - private StringValues _Cookie; - private StringValues _Expect; - private StringValues _From; - private StringValues _Host; - private StringValues _IfMatch; - private StringValues _IfModifiedSince; - private StringValues _IfNoneMatch; - private StringValues _IfRange; - private StringValues _IfUnmodifiedSince; - private StringValues _MaxForwards; - private StringValues _ProxyAuthorization; - private StringValues _Referer; - private StringValues _Range; - private StringValues _TE; - private StringValues _Translate; - private StringValues _UserAgent; - private StringValues _Origin; - private StringValues _AccessControlRequestMethod; - private StringValues _AccessControlRequestHeaders; - + private HeaderReferences _headers; public StringValues HeaderCacheControl { @@ -65,14 +20,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 1L) != 0)) { - return _CacheControl; + return _headers._CacheControl; } return StringValues.Empty; } set { _bits |= 1L; - _CacheControl = value; + _headers._CacheControl = value; } } public StringValues HeaderConnection @@ -81,14 +36,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 2L) != 0)) { - return _Connection; + return _headers._Connection; } return StringValues.Empty; } set { _bits |= 2L; - _Connection = value; + _headers._Connection = value; } } public StringValues HeaderDate @@ -97,14 +52,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 4L) != 0)) { - return _Date; + return _headers._Date; } return StringValues.Empty; } set { _bits |= 4L; - _Date = value; + _headers._Date = value; } } public StringValues HeaderKeepAlive @@ -113,14 +68,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 8L) != 0)) { - return _KeepAlive; + return _headers._KeepAlive; } return StringValues.Empty; } set { _bits |= 8L; - _KeepAlive = value; + _headers._KeepAlive = value; } } public StringValues HeaderPragma @@ -129,14 +84,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 16L) != 0)) { - return _Pragma; + return _headers._Pragma; } return StringValues.Empty; } set { _bits |= 16L; - _Pragma = value; + _headers._Pragma = value; } } public StringValues HeaderTrailer @@ -145,14 +100,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 32L) != 0)) { - return _Trailer; + return _headers._Trailer; } return StringValues.Empty; } set { _bits |= 32L; - _Trailer = value; + _headers._Trailer = value; } } public StringValues HeaderTransferEncoding @@ -161,14 +116,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 64L) != 0)) { - return _TransferEncoding; + return _headers._TransferEncoding; } return StringValues.Empty; } set { _bits |= 64L; - _TransferEncoding = value; + _headers._TransferEncoding = value; } } public StringValues HeaderUpgrade @@ -177,14 +132,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 128L) != 0)) { - return _Upgrade; + return _headers._Upgrade; } return StringValues.Empty; } set { _bits |= 128L; - _Upgrade = value; + _headers._Upgrade = value; } } public StringValues HeaderVia @@ -193,14 +148,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 256L) != 0)) { - return _Via; + return _headers._Via; } return StringValues.Empty; } set { _bits |= 256L; - _Via = value; + _headers._Via = value; } } public StringValues HeaderWarning @@ -209,14 +164,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 512L) != 0)) { - return _Warning; + return _headers._Warning; } return StringValues.Empty; } set { _bits |= 512L; - _Warning = value; + _headers._Warning = value; } } public StringValues HeaderAllow @@ -225,14 +180,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 1024L) != 0)) { - return _Allow; + return _headers._Allow; } return StringValues.Empty; } set { _bits |= 1024L; - _Allow = value; + _headers._Allow = value; } } public StringValues HeaderContentLength @@ -241,14 +196,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 2048L) != 0)) { - return _ContentLength; + return _headers._ContentLength; } return StringValues.Empty; } set { _bits |= 2048L; - _ContentLength = value; + _headers._ContentLength = value; } } public StringValues HeaderContentType @@ -257,14 +212,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 4096L) != 0)) { - return _ContentType; + return _headers._ContentType; } return StringValues.Empty; } set { _bits |= 4096L; - _ContentType = value; + _headers._ContentType = value; } } public StringValues HeaderContentEncoding @@ -273,14 +228,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 8192L) != 0)) { - return _ContentEncoding; + return _headers._ContentEncoding; } return StringValues.Empty; } set { _bits |= 8192L; - _ContentEncoding = value; + _headers._ContentEncoding = value; } } public StringValues HeaderContentLanguage @@ -289,14 +244,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 16384L) != 0)) { - return _ContentLanguage; + return _headers._ContentLanguage; } return StringValues.Empty; } set { _bits |= 16384L; - _ContentLanguage = value; + _headers._ContentLanguage = value; } } public StringValues HeaderContentLocation @@ -305,14 +260,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 32768L) != 0)) { - return _ContentLocation; + return _headers._ContentLocation; } return StringValues.Empty; } set { _bits |= 32768L; - _ContentLocation = value; + _headers._ContentLocation = value; } } public StringValues HeaderContentMD5 @@ -321,14 +276,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 65536L) != 0)) { - return _ContentMD5; + return _headers._ContentMD5; } return StringValues.Empty; } set { _bits |= 65536L; - _ContentMD5 = value; + _headers._ContentMD5 = value; } } public StringValues HeaderContentRange @@ -337,14 +292,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 131072L) != 0)) { - return _ContentRange; + return _headers._ContentRange; } return StringValues.Empty; } set { _bits |= 131072L; - _ContentRange = value; + _headers._ContentRange = value; } } public StringValues HeaderExpires @@ -353,14 +308,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 262144L) != 0)) { - return _Expires; + return _headers._Expires; } return StringValues.Empty; } set { _bits |= 262144L; - _Expires = value; + _headers._Expires = value; } } public StringValues HeaderLastModified @@ -369,14 +324,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 524288L) != 0)) { - return _LastModified; + return _headers._LastModified; } return StringValues.Empty; } set { _bits |= 524288L; - _LastModified = value; + _headers._LastModified = value; } } public StringValues HeaderAccept @@ -385,14 +340,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 1048576L) != 0)) { - return _Accept; + return _headers._Accept; } return StringValues.Empty; } set { _bits |= 1048576L; - _Accept = value; + _headers._Accept = value; } } public StringValues HeaderAcceptCharset @@ -401,14 +356,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 2097152L) != 0)) { - return _AcceptCharset; + return _headers._AcceptCharset; } return StringValues.Empty; } set { _bits |= 2097152L; - _AcceptCharset = value; + _headers._AcceptCharset = value; } } public StringValues HeaderAcceptEncoding @@ -417,14 +372,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 4194304L) != 0)) { - return _AcceptEncoding; + return _headers._AcceptEncoding; } return StringValues.Empty; } set { _bits |= 4194304L; - _AcceptEncoding = value; + _headers._AcceptEncoding = value; } } public StringValues HeaderAcceptLanguage @@ -433,14 +388,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 8388608L) != 0)) { - return _AcceptLanguage; + return _headers._AcceptLanguage; } return StringValues.Empty; } set { _bits |= 8388608L; - _AcceptLanguage = value; + _headers._AcceptLanguage = value; } } public StringValues HeaderAuthorization @@ -449,14 +404,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 16777216L) != 0)) { - return _Authorization; + return _headers._Authorization; } return StringValues.Empty; } set { _bits |= 16777216L; - _Authorization = value; + _headers._Authorization = value; } } public StringValues HeaderCookie @@ -465,14 +420,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 33554432L) != 0)) { - return _Cookie; + return _headers._Cookie; } return StringValues.Empty; } set { _bits |= 33554432L; - _Cookie = value; + _headers._Cookie = value; } } public StringValues HeaderExpect @@ -481,14 +436,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 67108864L) != 0)) { - return _Expect; + return _headers._Expect; } return StringValues.Empty; } set { _bits |= 67108864L; - _Expect = value; + _headers._Expect = value; } } public StringValues HeaderFrom @@ -497,14 +452,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 134217728L) != 0)) { - return _From; + return _headers._From; } return StringValues.Empty; } set { _bits |= 134217728L; - _From = value; + _headers._From = value; } } public StringValues HeaderHost @@ -513,14 +468,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 268435456L) != 0)) { - return _Host; + return _headers._Host; } return StringValues.Empty; } set { _bits |= 268435456L; - _Host = value; + _headers._Host = value; } } public StringValues HeaderIfMatch @@ -529,14 +484,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 536870912L) != 0)) { - return _IfMatch; + return _headers._IfMatch; } return StringValues.Empty; } set { _bits |= 536870912L; - _IfMatch = value; + _headers._IfMatch = value; } } public StringValues HeaderIfModifiedSince @@ -545,14 +500,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 1073741824L) != 0)) { - return _IfModifiedSince; + return _headers._IfModifiedSince; } return StringValues.Empty; } set { _bits |= 1073741824L; - _IfModifiedSince = value; + _headers._IfModifiedSince = value; } } public StringValues HeaderIfNoneMatch @@ -561,14 +516,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 2147483648L) != 0)) { - return _IfNoneMatch; + return _headers._IfNoneMatch; } return StringValues.Empty; } set { _bits |= 2147483648L; - _IfNoneMatch = value; + _headers._IfNoneMatch = value; } } public StringValues HeaderIfRange @@ -577,14 +532,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 4294967296L) != 0)) { - return _IfRange; + return _headers._IfRange; } return StringValues.Empty; } set { _bits |= 4294967296L; - _IfRange = value; + _headers._IfRange = value; } } public StringValues HeaderIfUnmodifiedSince @@ -593,14 +548,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 8589934592L) != 0)) { - return _IfUnmodifiedSince; + return _headers._IfUnmodifiedSince; } return StringValues.Empty; } set { _bits |= 8589934592L; - _IfUnmodifiedSince = value; + _headers._IfUnmodifiedSince = value; } } public StringValues HeaderMaxForwards @@ -609,14 +564,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 17179869184L) != 0)) { - return _MaxForwards; + return _headers._MaxForwards; } return StringValues.Empty; } set { _bits |= 17179869184L; - _MaxForwards = value; + _headers._MaxForwards = value; } } public StringValues HeaderProxyAuthorization @@ -625,14 +580,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 34359738368L) != 0)) { - return _ProxyAuthorization; + return _headers._ProxyAuthorization; } return StringValues.Empty; } set { _bits |= 34359738368L; - _ProxyAuthorization = value; + _headers._ProxyAuthorization = value; } } public StringValues HeaderReferer @@ -641,14 +596,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 68719476736L) != 0)) { - return _Referer; + return _headers._Referer; } return StringValues.Empty; } set { _bits |= 68719476736L; - _Referer = value; + _headers._Referer = value; } } public StringValues HeaderRange @@ -657,14 +612,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 137438953472L) != 0)) { - return _Range; + return _headers._Range; } return StringValues.Empty; } set { _bits |= 137438953472L; - _Range = value; + _headers._Range = value; } } public StringValues HeaderTE @@ -673,14 +628,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 274877906944L) != 0)) { - return _TE; + return _headers._TE; } return StringValues.Empty; } set { _bits |= 274877906944L; - _TE = value; + _headers._TE = value; } } public StringValues HeaderTranslate @@ -689,14 +644,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 549755813888L) != 0)) { - return _Translate; + return _headers._Translate; } return StringValues.Empty; } set { _bits |= 549755813888L; - _Translate = value; + _headers._Translate = value; } } public StringValues HeaderUserAgent @@ -705,14 +660,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 1099511627776L) != 0)) { - return _UserAgent; + return _headers._UserAgent; } return StringValues.Empty; } set { _bits |= 1099511627776L; - _UserAgent = value; + _headers._UserAgent = value; } } public StringValues HeaderOrigin @@ -721,14 +676,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 2199023255552L) != 0)) { - return _Origin; + return _headers._Origin; } return StringValues.Empty; } set { _bits |= 2199023255552L; - _Origin = value; + _headers._Origin = value; } } public StringValues HeaderAccessControlRequestMethod @@ -737,14 +692,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 4398046511104L) != 0)) { - return _AccessControlRequestMethod; + return _headers._AccessControlRequestMethod; } return StringValues.Empty; } set { _bits |= 4398046511104L; - _AccessControlRequestMethod = value; + _headers._AccessControlRequestMethod = value; } } public StringValues HeaderAccessControlRequestHeaders @@ -753,14 +708,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 8796093022208L) != 0)) { - return _AccessControlRequestHeaders; + return _headers._AccessControlRequestHeaders; } return StringValues.Empty; } set { _bits |= 8796093022208L; - _AccessControlRequestHeaders = value; + _headers._AccessControlRequestHeaders = value; } } @@ -778,7 +733,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 1L) != 0)) { - return _CacheControl; + return _headers._CacheControl; } else { @@ -790,7 +745,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 131072L) != 0)) { - return _ContentRange; + return _headers._ContentRange; } else { @@ -802,7 +757,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 524288L) != 0)) { - return _LastModified; + return _headers._LastModified; } else { @@ -814,7 +769,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 16777216L) != 0)) { - return _Authorization; + return _headers._Authorization; } else { @@ -826,7 +781,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 2147483648L) != 0)) { - return _IfNoneMatch; + return _headers._IfNoneMatch; } else { @@ -842,7 +797,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 2L) != 0)) { - return _Connection; + return _headers._Connection; } else { @@ -854,7 +809,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 8L) != 0)) { - return _KeepAlive; + return _headers._KeepAlive; } else { @@ -866,7 +821,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 1099511627776L) != 0)) { - return _UserAgent; + return _headers._UserAgent; } else { @@ -882,7 +837,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 4L) != 0)) { - return _Date; + return _headers._Date; } else { @@ -894,7 +849,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 134217728L) != 0)) { - return _From; + return _headers._From; } else { @@ -906,7 +861,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 268435456L) != 0)) { - return _Host; + return _headers._Host; } else { @@ -922,7 +877,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 16L) != 0)) { - return _Pragma; + return _headers._Pragma; } else { @@ -934,7 +889,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 1048576L) != 0)) { - return _Accept; + return _headers._Accept; } else { @@ -946,7 +901,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 33554432L) != 0)) { - return _Cookie; + return _headers._Cookie; } else { @@ -958,7 +913,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 67108864L) != 0)) { - return _Expect; + return _headers._Expect; } else { @@ -970,7 +925,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 2199023255552L) != 0)) { - return _Origin; + return _headers._Origin; } else { @@ -986,7 +941,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 32L) != 0)) { - return _Trailer; + return _headers._Trailer; } else { @@ -998,7 +953,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 128L) != 0)) { - return _Upgrade; + return _headers._Upgrade; } else { @@ -1010,7 +965,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 512L) != 0)) { - return _Warning; + return _headers._Warning; } else { @@ -1022,7 +977,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 262144L) != 0)) { - return _Expires; + return _headers._Expires; } else { @@ -1034,7 +989,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 68719476736L) != 0)) { - return _Referer; + return _headers._Referer; } else { @@ -1050,7 +1005,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 64L) != 0)) { - return _TransferEncoding; + return _headers._TransferEncoding; } else { @@ -1062,7 +1017,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 1073741824L) != 0)) { - return _IfModifiedSince; + return _headers._IfModifiedSince; } else { @@ -1078,7 +1033,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 256L) != 0)) { - return _Via; + return _headers._Via; } else { @@ -1094,7 +1049,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 1024L) != 0)) { - return _Allow; + return _headers._Allow; } else { @@ -1106,7 +1061,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 137438953472L) != 0)) { - return _Range; + return _headers._Range; } else { @@ -1122,7 +1077,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 2048L) != 0)) { - return _ContentLength; + return _headers._ContentLength; } else { @@ -1134,7 +1089,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 2097152L) != 0)) { - return _AcceptCharset; + return _headers._AcceptCharset; } else { @@ -1150,7 +1105,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 4096L) != 0)) { - return _ContentType; + return _headers._ContentType; } else { @@ -1162,7 +1117,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 17179869184L) != 0)) { - return _MaxForwards; + return _headers._MaxForwards; } else { @@ -1178,7 +1133,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 8192L) != 0)) { - return _ContentEncoding; + return _headers._ContentEncoding; } else { @@ -1190,7 +1145,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 16384L) != 0)) { - return _ContentLanguage; + return _headers._ContentLanguage; } else { @@ -1202,7 +1157,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 32768L) != 0)) { - return _ContentLocation; + return _headers._ContentLocation; } else { @@ -1218,7 +1173,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 65536L) != 0)) { - return _ContentMD5; + return _headers._ContentMD5; } else { @@ -1234,7 +1189,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 4194304L) != 0)) { - return _AcceptEncoding; + return _headers._AcceptEncoding; } else { @@ -1246,7 +1201,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 8388608L) != 0)) { - return _AcceptLanguage; + return _headers._AcceptLanguage; } else { @@ -1262,7 +1217,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 536870912L) != 0)) { - return _IfMatch; + return _headers._IfMatch; } else { @@ -1274,7 +1229,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 4294967296L) != 0)) { - return _IfRange; + return _headers._IfRange; } else { @@ -1290,7 +1245,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 8589934592L) != 0)) { - return _IfUnmodifiedSince; + return _headers._IfUnmodifiedSince; } else { @@ -1302,7 +1257,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 34359738368L) != 0)) { - return _ProxyAuthorization; + return _headers._ProxyAuthorization; } else { @@ -1318,7 +1273,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 274877906944L) != 0)) { - return _TE; + return _headers._TE; } else { @@ -1334,7 +1289,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 549755813888L) != 0)) { - return _Translate; + return _headers._Translate; } else { @@ -1350,7 +1305,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 4398046511104L) != 0)) { - return _AccessControlRequestMethod; + return _headers._AccessControlRequestMethod; } else { @@ -1366,7 +1321,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 8796093022208L) != 0)) { - return _AccessControlRequestHeaders; + return _headers._AccessControlRequestHeaders; } else { @@ -1392,7 +1347,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 1L) != 0)) { - value = _CacheControl; + value = _headers._CacheControl; return true; } else @@ -1406,7 +1361,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 131072L) != 0)) { - value = _ContentRange; + value = _headers._ContentRange; return true; } else @@ -1420,7 +1375,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 524288L) != 0)) { - value = _LastModified; + value = _headers._LastModified; return true; } else @@ -1434,7 +1389,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 16777216L) != 0)) { - value = _Authorization; + value = _headers._Authorization; return true; } else @@ -1448,7 +1403,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 2147483648L) != 0)) { - value = _IfNoneMatch; + value = _headers._IfNoneMatch; return true; } else @@ -1466,7 +1421,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 2L) != 0)) { - value = _Connection; + value = _headers._Connection; return true; } else @@ -1480,7 +1435,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 8L) != 0)) { - value = _KeepAlive; + value = _headers._KeepAlive; return true; } else @@ -1494,7 +1449,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 1099511627776L) != 0)) { - value = _UserAgent; + value = _headers._UserAgent; return true; } else @@ -1512,7 +1467,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 4L) != 0)) { - value = _Date; + value = _headers._Date; return true; } else @@ -1526,7 +1481,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 134217728L) != 0)) { - value = _From; + value = _headers._From; return true; } else @@ -1540,7 +1495,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 268435456L) != 0)) { - value = _Host; + value = _headers._Host; return true; } else @@ -1558,7 +1513,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 16L) != 0)) { - value = _Pragma; + value = _headers._Pragma; return true; } else @@ -1572,7 +1527,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 1048576L) != 0)) { - value = _Accept; + value = _headers._Accept; return true; } else @@ -1586,7 +1541,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 33554432L) != 0)) { - value = _Cookie; + value = _headers._Cookie; return true; } else @@ -1600,7 +1555,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 67108864L) != 0)) { - value = _Expect; + value = _headers._Expect; return true; } else @@ -1614,7 +1569,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 2199023255552L) != 0)) { - value = _Origin; + value = _headers._Origin; return true; } else @@ -1632,7 +1587,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 32L) != 0)) { - value = _Trailer; + value = _headers._Trailer; return true; } else @@ -1646,7 +1601,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 128L) != 0)) { - value = _Upgrade; + value = _headers._Upgrade; return true; } else @@ -1660,7 +1615,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 512L) != 0)) { - value = _Warning; + value = _headers._Warning; return true; } else @@ -1674,7 +1629,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 262144L) != 0)) { - value = _Expires; + value = _headers._Expires; return true; } else @@ -1688,7 +1643,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 68719476736L) != 0)) { - value = _Referer; + value = _headers._Referer; return true; } else @@ -1706,7 +1661,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 64L) != 0)) { - value = _TransferEncoding; + value = _headers._TransferEncoding; return true; } else @@ -1720,7 +1675,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 1073741824L) != 0)) { - value = _IfModifiedSince; + value = _headers._IfModifiedSince; return true; } else @@ -1738,7 +1693,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 256L) != 0)) { - value = _Via; + value = _headers._Via; return true; } else @@ -1756,7 +1711,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 1024L) != 0)) { - value = _Allow; + value = _headers._Allow; return true; } else @@ -1770,7 +1725,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 137438953472L) != 0)) { - value = _Range; + value = _headers._Range; return true; } else @@ -1788,7 +1743,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 2048L) != 0)) { - value = _ContentLength; + value = _headers._ContentLength; return true; } else @@ -1802,7 +1757,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 2097152L) != 0)) { - value = _AcceptCharset; + value = _headers._AcceptCharset; return true; } else @@ -1820,7 +1775,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 4096L) != 0)) { - value = _ContentType; + value = _headers._ContentType; return true; } else @@ -1834,7 +1789,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 17179869184L) != 0)) { - value = _MaxForwards; + value = _headers._MaxForwards; return true; } else @@ -1852,7 +1807,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 8192L) != 0)) { - value = _ContentEncoding; + value = _headers._ContentEncoding; return true; } else @@ -1866,7 +1821,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 16384L) != 0)) { - value = _ContentLanguage; + value = _headers._ContentLanguage; return true; } else @@ -1880,7 +1835,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 32768L) != 0)) { - value = _ContentLocation; + value = _headers._ContentLocation; return true; } else @@ -1898,7 +1853,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 65536L) != 0)) { - value = _ContentMD5; + value = _headers._ContentMD5; return true; } else @@ -1916,7 +1871,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 4194304L) != 0)) { - value = _AcceptEncoding; + value = _headers._AcceptEncoding; return true; } else @@ -1930,7 +1885,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 8388608L) != 0)) { - value = _AcceptLanguage; + value = _headers._AcceptLanguage; return true; } else @@ -1948,7 +1903,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 536870912L) != 0)) { - value = _IfMatch; + value = _headers._IfMatch; return true; } else @@ -1962,7 +1917,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 4294967296L) != 0)) { - value = _IfRange; + value = _headers._IfRange; return true; } else @@ -1980,7 +1935,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 8589934592L) != 0)) { - value = _IfUnmodifiedSince; + value = _headers._IfUnmodifiedSince; return true; } else @@ -1994,7 +1949,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 34359738368L) != 0)) { - value = _ProxyAuthorization; + value = _headers._ProxyAuthorization; return true; } else @@ -2012,7 +1967,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 274877906944L) != 0)) { - value = _TE; + value = _headers._TE; return true; } else @@ -2030,7 +1985,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 549755813888L) != 0)) { - value = _Translate; + value = _headers._Translate; return true; } else @@ -2048,7 +2003,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 4398046511104L) != 0)) { - value = _AccessControlRequestMethod; + value = _headers._AccessControlRequestMethod; return true; } else @@ -2066,7 +2021,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 8796093022208L) != 0)) { - value = _AccessControlRequestHeaders; + value = _headers._AccessControlRequestHeaders; return true; } else @@ -2090,35 +2045,35 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if ("Cache-Control".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 1L; - _CacheControl = value; + _headers._CacheControl = value; return; } if ("Content-Range".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 131072L; - _ContentRange = value; + _headers._ContentRange = value; return; } if ("Last-Modified".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 524288L; - _LastModified = value; + _headers._LastModified = value; return; } if ("Authorization".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 16777216L; - _Authorization = value; + _headers._Authorization = value; return; } if ("If-None-Match".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 2147483648L; - _IfNoneMatch = value; + _headers._IfNoneMatch = value; return; } } @@ -2129,21 +2084,21 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if ("Connection".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 2L; - _Connection = value; + _headers._Connection = value; return; } if ("Keep-Alive".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 8L; - _KeepAlive = value; + _headers._KeepAlive = value; return; } if ("User-Agent".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 1099511627776L; - _UserAgent = value; + _headers._UserAgent = value; return; } } @@ -2154,21 +2109,21 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if ("Date".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 4L; - _Date = value; + _headers._Date = value; return; } if ("From".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 134217728L; - _From = value; + _headers._From = value; return; } if ("Host".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 268435456L; - _Host = value; + _headers._Host = value; return; } } @@ -2179,35 +2134,35 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if ("Pragma".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 16L; - _Pragma = value; + _headers._Pragma = value; return; } if ("Accept".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 1048576L; - _Accept = value; + _headers._Accept = value; return; } if ("Cookie".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 33554432L; - _Cookie = value; + _headers._Cookie = value; return; } if ("Expect".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 67108864L; - _Expect = value; + _headers._Expect = value; return; } if ("Origin".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 2199023255552L; - _Origin = value; + _headers._Origin = value; return; } } @@ -2218,35 +2173,35 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if ("Trailer".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 32L; - _Trailer = value; + _headers._Trailer = value; return; } if ("Upgrade".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 128L; - _Upgrade = value; + _headers._Upgrade = value; return; } if ("Warning".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 512L; - _Warning = value; + _headers._Warning = value; return; } if ("Expires".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 262144L; - _Expires = value; + _headers._Expires = value; return; } if ("Referer".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 68719476736L; - _Referer = value; + _headers._Referer = value; return; } } @@ -2257,14 +2212,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if ("Transfer-Encoding".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 64L; - _TransferEncoding = value; + _headers._TransferEncoding = value; return; } if ("If-Modified-Since".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 1073741824L; - _IfModifiedSince = value; + _headers._IfModifiedSince = value; return; } } @@ -2275,7 +2230,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if ("Via".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 256L; - _Via = value; + _headers._Via = value; return; } } @@ -2286,14 +2241,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if ("Allow".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 1024L; - _Allow = value; + _headers._Allow = value; return; } if ("Range".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 137438953472L; - _Range = value; + _headers._Range = value; return; } } @@ -2304,14 +2259,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if ("Content-Length".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 2048L; - _ContentLength = value; + _headers._ContentLength = value; return; } if ("Accept-Charset".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 2097152L; - _AcceptCharset = value; + _headers._AcceptCharset = value; return; } } @@ -2322,14 +2277,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if ("Content-Type".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 4096L; - _ContentType = value; + _headers._ContentType = value; return; } if ("Max-Forwards".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 17179869184L; - _MaxForwards = value; + _headers._MaxForwards = value; return; } } @@ -2340,21 +2295,21 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if ("Content-Encoding".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 8192L; - _ContentEncoding = value; + _headers._ContentEncoding = value; return; } if ("Content-Language".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 16384L; - _ContentLanguage = value; + _headers._ContentLanguage = value; return; } if ("Content-Location".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 32768L; - _ContentLocation = value; + _headers._ContentLocation = value; return; } } @@ -2365,7 +2320,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if ("Content-MD5".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 65536L; - _ContentMD5 = value; + _headers._ContentMD5 = value; return; } } @@ -2376,14 +2331,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if ("Accept-Encoding".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 4194304L; - _AcceptEncoding = value; + _headers._AcceptEncoding = value; return; } if ("Accept-Language".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 8388608L; - _AcceptLanguage = value; + _headers._AcceptLanguage = value; return; } } @@ -2394,14 +2349,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if ("If-Match".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 536870912L; - _IfMatch = value; + _headers._IfMatch = value; return; } if ("If-Range".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 4294967296L; - _IfRange = value; + _headers._IfRange = value; return; } } @@ -2412,14 +2367,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if ("If-Unmodified-Since".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 8589934592L; - _IfUnmodifiedSince = value; + _headers._IfUnmodifiedSince = value; return; } if ("Proxy-Authorization".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 34359738368L; - _ProxyAuthorization = value; + _headers._ProxyAuthorization = value; return; } } @@ -2430,7 +2385,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if ("TE".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 274877906944L; - _TE = value; + _headers._TE = value; return; } } @@ -2441,7 +2396,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if ("Translate".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 549755813888L; - _Translate = value; + _headers._Translate = value; return; } } @@ -2452,7 +2407,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if ("Access-Control-Request-Method".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 4398046511104L; - _AccessControlRequestMethod = value; + _headers._AccessControlRequestMethod = value; return; } } @@ -2463,7 +2418,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if ("Access-Control-Request-Headers".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 8796093022208L; - _AccessControlRequestHeaders = value; + _headers._AccessControlRequestHeaders = value; return; } } @@ -2484,7 +2439,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowDuplicateKeyException(); } _bits |= 1L; - _CacheControl = value; + _headers._CacheControl = value; return; } @@ -2495,7 +2450,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowDuplicateKeyException(); } _bits |= 131072L; - _ContentRange = value; + _headers._ContentRange = value; return; } @@ -2506,7 +2461,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowDuplicateKeyException(); } _bits |= 524288L; - _LastModified = value; + _headers._LastModified = value; return; } @@ -2517,7 +2472,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowDuplicateKeyException(); } _bits |= 16777216L; - _Authorization = value; + _headers._Authorization = value; return; } @@ -2528,7 +2483,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowDuplicateKeyException(); } _bits |= 2147483648L; - _IfNoneMatch = value; + _headers._IfNoneMatch = value; return; } } @@ -2543,7 +2498,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowDuplicateKeyException(); } _bits |= 2L; - _Connection = value; + _headers._Connection = value; return; } @@ -2554,7 +2509,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowDuplicateKeyException(); } _bits |= 8L; - _KeepAlive = value; + _headers._KeepAlive = value; return; } @@ -2565,7 +2520,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowDuplicateKeyException(); } _bits |= 1099511627776L; - _UserAgent = value; + _headers._UserAgent = value; return; } } @@ -2580,7 +2535,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowDuplicateKeyException(); } _bits |= 4L; - _Date = value; + _headers._Date = value; return; } @@ -2591,7 +2546,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowDuplicateKeyException(); } _bits |= 134217728L; - _From = value; + _headers._From = value; return; } @@ -2602,7 +2557,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowDuplicateKeyException(); } _bits |= 268435456L; - _Host = value; + _headers._Host = value; return; } } @@ -2617,7 +2572,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowDuplicateKeyException(); } _bits |= 16L; - _Pragma = value; + _headers._Pragma = value; return; } @@ -2628,7 +2583,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowDuplicateKeyException(); } _bits |= 1048576L; - _Accept = value; + _headers._Accept = value; return; } @@ -2639,7 +2594,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowDuplicateKeyException(); } _bits |= 33554432L; - _Cookie = value; + _headers._Cookie = value; return; } @@ -2650,7 +2605,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowDuplicateKeyException(); } _bits |= 67108864L; - _Expect = value; + _headers._Expect = value; return; } @@ -2661,7 +2616,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowDuplicateKeyException(); } _bits |= 2199023255552L; - _Origin = value; + _headers._Origin = value; return; } } @@ -2676,7 +2631,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowDuplicateKeyException(); } _bits |= 32L; - _Trailer = value; + _headers._Trailer = value; return; } @@ -2687,7 +2642,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowDuplicateKeyException(); } _bits |= 128L; - _Upgrade = value; + _headers._Upgrade = value; return; } @@ -2698,7 +2653,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowDuplicateKeyException(); } _bits |= 512L; - _Warning = value; + _headers._Warning = value; return; } @@ -2709,7 +2664,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowDuplicateKeyException(); } _bits |= 262144L; - _Expires = value; + _headers._Expires = value; return; } @@ -2720,7 +2675,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowDuplicateKeyException(); } _bits |= 68719476736L; - _Referer = value; + _headers._Referer = value; return; } } @@ -2735,7 +2690,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowDuplicateKeyException(); } _bits |= 64L; - _TransferEncoding = value; + _headers._TransferEncoding = value; return; } @@ -2746,7 +2701,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowDuplicateKeyException(); } _bits |= 1073741824L; - _IfModifiedSince = value; + _headers._IfModifiedSince = value; return; } } @@ -2761,7 +2716,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowDuplicateKeyException(); } _bits |= 256L; - _Via = value; + _headers._Via = value; return; } } @@ -2776,7 +2731,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowDuplicateKeyException(); } _bits |= 1024L; - _Allow = value; + _headers._Allow = value; return; } @@ -2787,7 +2742,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowDuplicateKeyException(); } _bits |= 137438953472L; - _Range = value; + _headers._Range = value; return; } } @@ -2802,7 +2757,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowDuplicateKeyException(); } _bits |= 2048L; - _ContentLength = value; + _headers._ContentLength = value; return; } @@ -2813,7 +2768,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowDuplicateKeyException(); } _bits |= 2097152L; - _AcceptCharset = value; + _headers._AcceptCharset = value; return; } } @@ -2828,7 +2783,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowDuplicateKeyException(); } _bits |= 4096L; - _ContentType = value; + _headers._ContentType = value; return; } @@ -2839,7 +2794,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowDuplicateKeyException(); } _bits |= 17179869184L; - _MaxForwards = value; + _headers._MaxForwards = value; return; } } @@ -2854,7 +2809,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowDuplicateKeyException(); } _bits |= 8192L; - _ContentEncoding = value; + _headers._ContentEncoding = value; return; } @@ -2865,7 +2820,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowDuplicateKeyException(); } _bits |= 16384L; - _ContentLanguage = value; + _headers._ContentLanguage = value; return; } @@ -2876,7 +2831,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowDuplicateKeyException(); } _bits |= 32768L; - _ContentLocation = value; + _headers._ContentLocation = value; return; } } @@ -2891,7 +2846,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowDuplicateKeyException(); } _bits |= 65536L; - _ContentMD5 = value; + _headers._ContentMD5 = value; return; } } @@ -2906,7 +2861,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowDuplicateKeyException(); } _bits |= 4194304L; - _AcceptEncoding = value; + _headers._AcceptEncoding = value; return; } @@ -2917,7 +2872,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowDuplicateKeyException(); } _bits |= 8388608L; - _AcceptLanguage = value; + _headers._AcceptLanguage = value; return; } } @@ -2932,7 +2887,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowDuplicateKeyException(); } _bits |= 536870912L; - _IfMatch = value; + _headers._IfMatch = value; return; } @@ -2943,7 +2898,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowDuplicateKeyException(); } _bits |= 4294967296L; - _IfRange = value; + _headers._IfRange = value; return; } } @@ -2958,7 +2913,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowDuplicateKeyException(); } _bits |= 8589934592L; - _IfUnmodifiedSince = value; + _headers._IfUnmodifiedSince = value; return; } @@ -2969,7 +2924,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowDuplicateKeyException(); } _bits |= 34359738368L; - _ProxyAuthorization = value; + _headers._ProxyAuthorization = value; return; } } @@ -2984,7 +2939,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowDuplicateKeyException(); } _bits |= 274877906944L; - _TE = value; + _headers._TE = value; return; } } @@ -2999,7 +2954,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowDuplicateKeyException(); } _bits |= 549755813888L; - _Translate = value; + _headers._Translate = value; return; } } @@ -3014,7 +2969,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowDuplicateKeyException(); } _bits |= 4398046511104L; - _AccessControlRequestMethod = value; + _headers._AccessControlRequestMethod = value; return; } } @@ -3029,7 +2984,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowDuplicateKeyException(); } _bits |= 8796093022208L; - _AccessControlRequestHeaders = value; + _headers._AccessControlRequestHeaders = value; return; } } @@ -3048,7 +3003,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if (((_bits & 1L) != 0)) { _bits &= ~1L; - _CacheControl = StringValues.Empty; + _headers._CacheControl = StringValues.Empty; return true; } else @@ -3062,7 +3017,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if (((_bits & 131072L) != 0)) { _bits &= ~131072L; - _ContentRange = StringValues.Empty; + _headers._ContentRange = StringValues.Empty; return true; } else @@ -3076,7 +3031,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if (((_bits & 524288L) != 0)) { _bits &= ~524288L; - _LastModified = StringValues.Empty; + _headers._LastModified = StringValues.Empty; return true; } else @@ -3090,7 +3045,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if (((_bits & 16777216L) != 0)) { _bits &= ~16777216L; - _Authorization = StringValues.Empty; + _headers._Authorization = StringValues.Empty; return true; } else @@ -3104,7 +3059,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if (((_bits & 2147483648L) != 0)) { _bits &= ~2147483648L; - _IfNoneMatch = StringValues.Empty; + _headers._IfNoneMatch = StringValues.Empty; return true; } else @@ -3122,7 +3077,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if (((_bits & 2L) != 0)) { _bits &= ~2L; - _Connection = StringValues.Empty; + _headers._Connection = StringValues.Empty; return true; } else @@ -3136,7 +3091,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if (((_bits & 8L) != 0)) { _bits &= ~8L; - _KeepAlive = StringValues.Empty; + _headers._KeepAlive = StringValues.Empty; return true; } else @@ -3150,7 +3105,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if (((_bits & 1099511627776L) != 0)) { _bits &= ~1099511627776L; - _UserAgent = StringValues.Empty; + _headers._UserAgent = StringValues.Empty; return true; } else @@ -3168,7 +3123,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if (((_bits & 4L) != 0)) { _bits &= ~4L; - _Date = StringValues.Empty; + _headers._Date = StringValues.Empty; return true; } else @@ -3182,7 +3137,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if (((_bits & 134217728L) != 0)) { _bits &= ~134217728L; - _From = StringValues.Empty; + _headers._From = StringValues.Empty; return true; } else @@ -3196,7 +3151,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if (((_bits & 268435456L) != 0)) { _bits &= ~268435456L; - _Host = StringValues.Empty; + _headers._Host = StringValues.Empty; return true; } else @@ -3214,7 +3169,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if (((_bits & 16L) != 0)) { _bits &= ~16L; - _Pragma = StringValues.Empty; + _headers._Pragma = StringValues.Empty; return true; } else @@ -3228,7 +3183,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if (((_bits & 1048576L) != 0)) { _bits &= ~1048576L; - _Accept = StringValues.Empty; + _headers._Accept = StringValues.Empty; return true; } else @@ -3242,7 +3197,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if (((_bits & 33554432L) != 0)) { _bits &= ~33554432L; - _Cookie = StringValues.Empty; + _headers._Cookie = StringValues.Empty; return true; } else @@ -3256,7 +3211,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if (((_bits & 67108864L) != 0)) { _bits &= ~67108864L; - _Expect = StringValues.Empty; + _headers._Expect = StringValues.Empty; return true; } else @@ -3270,7 +3225,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if (((_bits & 2199023255552L) != 0)) { _bits &= ~2199023255552L; - _Origin = StringValues.Empty; + _headers._Origin = StringValues.Empty; return true; } else @@ -3288,7 +3243,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if (((_bits & 32L) != 0)) { _bits &= ~32L; - _Trailer = StringValues.Empty; + _headers._Trailer = StringValues.Empty; return true; } else @@ -3302,7 +3257,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if (((_bits & 128L) != 0)) { _bits &= ~128L; - _Upgrade = StringValues.Empty; + _headers._Upgrade = StringValues.Empty; return true; } else @@ -3316,7 +3271,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if (((_bits & 512L) != 0)) { _bits &= ~512L; - _Warning = StringValues.Empty; + _headers._Warning = StringValues.Empty; return true; } else @@ -3330,7 +3285,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if (((_bits & 262144L) != 0)) { _bits &= ~262144L; - _Expires = StringValues.Empty; + _headers._Expires = StringValues.Empty; return true; } else @@ -3344,7 +3299,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if (((_bits & 68719476736L) != 0)) { _bits &= ~68719476736L; - _Referer = StringValues.Empty; + _headers._Referer = StringValues.Empty; return true; } else @@ -3362,7 +3317,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if (((_bits & 64L) != 0)) { _bits &= ~64L; - _TransferEncoding = StringValues.Empty; + _headers._TransferEncoding = StringValues.Empty; return true; } else @@ -3376,7 +3331,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if (((_bits & 1073741824L) != 0)) { _bits &= ~1073741824L; - _IfModifiedSince = StringValues.Empty; + _headers._IfModifiedSince = StringValues.Empty; return true; } else @@ -3394,7 +3349,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if (((_bits & 256L) != 0)) { _bits &= ~256L; - _Via = StringValues.Empty; + _headers._Via = StringValues.Empty; return true; } else @@ -3412,7 +3367,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if (((_bits & 1024L) != 0)) { _bits &= ~1024L; - _Allow = StringValues.Empty; + _headers._Allow = StringValues.Empty; return true; } else @@ -3426,7 +3381,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if (((_bits & 137438953472L) != 0)) { _bits &= ~137438953472L; - _Range = StringValues.Empty; + _headers._Range = StringValues.Empty; return true; } else @@ -3444,7 +3399,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if (((_bits & 2048L) != 0)) { _bits &= ~2048L; - _ContentLength = StringValues.Empty; + _headers._ContentLength = StringValues.Empty; return true; } else @@ -3458,7 +3413,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if (((_bits & 2097152L) != 0)) { _bits &= ~2097152L; - _AcceptCharset = StringValues.Empty; + _headers._AcceptCharset = StringValues.Empty; return true; } else @@ -3476,7 +3431,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if (((_bits & 4096L) != 0)) { _bits &= ~4096L; - _ContentType = StringValues.Empty; + _headers._ContentType = StringValues.Empty; return true; } else @@ -3490,7 +3445,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if (((_bits & 17179869184L) != 0)) { _bits &= ~17179869184L; - _MaxForwards = StringValues.Empty; + _headers._MaxForwards = StringValues.Empty; return true; } else @@ -3508,7 +3463,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if (((_bits & 8192L) != 0)) { _bits &= ~8192L; - _ContentEncoding = StringValues.Empty; + _headers._ContentEncoding = StringValues.Empty; return true; } else @@ -3522,7 +3477,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if (((_bits & 16384L) != 0)) { _bits &= ~16384L; - _ContentLanguage = StringValues.Empty; + _headers._ContentLanguage = StringValues.Empty; return true; } else @@ -3536,7 +3491,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if (((_bits & 32768L) != 0)) { _bits &= ~32768L; - _ContentLocation = StringValues.Empty; + _headers._ContentLocation = StringValues.Empty; return true; } else @@ -3554,7 +3509,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if (((_bits & 65536L) != 0)) { _bits &= ~65536L; - _ContentMD5 = StringValues.Empty; + _headers._ContentMD5 = StringValues.Empty; return true; } else @@ -3572,7 +3527,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if (((_bits & 4194304L) != 0)) { _bits &= ~4194304L; - _AcceptEncoding = StringValues.Empty; + _headers._AcceptEncoding = StringValues.Empty; return true; } else @@ -3586,7 +3541,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if (((_bits & 8388608L) != 0)) { _bits &= ~8388608L; - _AcceptLanguage = StringValues.Empty; + _headers._AcceptLanguage = StringValues.Empty; return true; } else @@ -3604,7 +3559,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if (((_bits & 536870912L) != 0)) { _bits &= ~536870912L; - _IfMatch = StringValues.Empty; + _headers._IfMatch = StringValues.Empty; return true; } else @@ -3618,7 +3573,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if (((_bits & 4294967296L) != 0)) { _bits &= ~4294967296L; - _IfRange = StringValues.Empty; + _headers._IfRange = StringValues.Empty; return true; } else @@ -3636,7 +3591,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if (((_bits & 8589934592L) != 0)) { _bits &= ~8589934592L; - _IfUnmodifiedSince = StringValues.Empty; + _headers._IfUnmodifiedSince = StringValues.Empty; return true; } else @@ -3650,7 +3605,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if (((_bits & 34359738368L) != 0)) { _bits &= ~34359738368L; - _ProxyAuthorization = StringValues.Empty; + _headers._ProxyAuthorization = StringValues.Empty; return true; } else @@ -3668,7 +3623,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if (((_bits & 274877906944L) != 0)) { _bits &= ~274877906944L; - _TE = StringValues.Empty; + _headers._TE = StringValues.Empty; return true; } else @@ -3686,7 +3641,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if (((_bits & 549755813888L) != 0)) { _bits &= ~549755813888L; - _Translate = StringValues.Empty; + _headers._Translate = StringValues.Empty; return true; } else @@ -3704,7 +3659,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if (((_bits & 4398046511104L) != 0)) { _bits &= ~4398046511104L; - _AccessControlRequestMethod = StringValues.Empty; + _headers._AccessControlRequestMethod = StringValues.Empty; return true; } else @@ -3722,7 +3677,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if (((_bits & 8796093022208L) != 0)) { _bits &= ~8796093022208L; - _AccessControlRequestHeaders = StringValues.Empty; + _headers._AccessControlRequestHeaders = StringValues.Empty; return true; } else @@ -3737,52 +3692,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } protected override void ClearFast() { - if (((_bits & 1L) != 0)) _CacheControl = default(StringValues); - if (((_bits & 2L) != 0)) _Connection = default(StringValues); - if (((_bits & 4L) != 0)) _Date = default(StringValues); - if (((_bits & 8L) != 0)) _KeepAlive = default(StringValues); - if (((_bits & 16L) != 0)) _Pragma = default(StringValues); - if (((_bits & 32L) != 0)) _Trailer = default(StringValues); - if (((_bits & 64L) != 0)) _TransferEncoding = default(StringValues); - if (((_bits & 128L) != 0)) _Upgrade = default(StringValues); - if (((_bits & 256L) != 0)) _Via = default(StringValues); - if (((_bits & 512L) != 0)) _Warning = default(StringValues); - if (((_bits & 1024L) != 0)) _Allow = default(StringValues); - if (((_bits & 2048L) != 0)) _ContentLength = default(StringValues); - if (((_bits & 4096L) != 0)) _ContentType = default(StringValues); - if (((_bits & 8192L) != 0)) _ContentEncoding = default(StringValues); - if (((_bits & 16384L) != 0)) _ContentLanguage = default(StringValues); - if (((_bits & 32768L) != 0)) _ContentLocation = default(StringValues); - if (((_bits & 65536L) != 0)) _ContentMD5 = default(StringValues); - if (((_bits & 131072L) != 0)) _ContentRange = default(StringValues); - if (((_bits & 262144L) != 0)) _Expires = default(StringValues); - if (((_bits & 524288L) != 0)) _LastModified = default(StringValues); - if (((_bits & 1048576L) != 0)) _Accept = default(StringValues); - if (((_bits & 2097152L) != 0)) _AcceptCharset = default(StringValues); - if (((_bits & 4194304L) != 0)) _AcceptEncoding = default(StringValues); - if (((_bits & 8388608L) != 0)) _AcceptLanguage = default(StringValues); - if (((_bits & 16777216L) != 0)) _Authorization = default(StringValues); - if (((_bits & 33554432L) != 0)) _Cookie = default(StringValues); - if (((_bits & 67108864L) != 0)) _Expect = default(StringValues); - if (((_bits & 134217728L) != 0)) _From = default(StringValues); - if (((_bits & 268435456L) != 0)) _Host = default(StringValues); - if (((_bits & 536870912L) != 0)) _IfMatch = default(StringValues); - if (((_bits & 1073741824L) != 0)) _IfModifiedSince = default(StringValues); - if (((_bits & 2147483648L) != 0)) _IfNoneMatch = default(StringValues); - if (((_bits & 4294967296L) != 0)) _IfRange = default(StringValues); - if (((_bits & 8589934592L) != 0)) _IfUnmodifiedSince = default(StringValues); - if (((_bits & 17179869184L) != 0)) _MaxForwards = default(StringValues); - if (((_bits & 34359738368L) != 0)) _ProxyAuthorization = default(StringValues); - if (((_bits & 68719476736L) != 0)) _Referer = default(StringValues); - if (((_bits & 137438953472L) != 0)) _Range = default(StringValues); - if (((_bits & 274877906944L) != 0)) _TE = default(StringValues); - if (((_bits & 549755813888L) != 0)) _Translate = default(StringValues); - if (((_bits & 1099511627776L) != 0)) _UserAgent = default(StringValues); - if (((_bits & 2199023255552L) != 0)) _Origin = default(StringValues); - if (((_bits & 4398046511104L) != 0)) _AccessControlRequestMethod = default(StringValues); - if (((_bits & 8796093022208L) != 0)) _AccessControlRequestHeaders = default(StringValues); - _bits = 0; + _headers = default(HeaderReferences); MaybeUnknown?.Clear(); } @@ -3800,7 +3711,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowArgumentException(); } - array[arrayIndex] = new KeyValuePair("Cache-Control", _CacheControl); + array[arrayIndex] = new KeyValuePair("Cache-Control", _headers._CacheControl); ++arrayIndex; } @@ -3811,7 +3722,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowArgumentException(); } - array[arrayIndex] = new KeyValuePair("Connection", _Connection); + array[arrayIndex] = new KeyValuePair("Connection", _headers._Connection); ++arrayIndex; } @@ -3822,7 +3733,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowArgumentException(); } - array[arrayIndex] = new KeyValuePair("Date", _Date); + array[arrayIndex] = new KeyValuePair("Date", _headers._Date); ++arrayIndex; } @@ -3833,7 +3744,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowArgumentException(); } - array[arrayIndex] = new KeyValuePair("Keep-Alive", _KeepAlive); + array[arrayIndex] = new KeyValuePair("Keep-Alive", _headers._KeepAlive); ++arrayIndex; } @@ -3844,7 +3755,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowArgumentException(); } - array[arrayIndex] = new KeyValuePair("Pragma", _Pragma); + array[arrayIndex] = new KeyValuePair("Pragma", _headers._Pragma); ++arrayIndex; } @@ -3855,7 +3766,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowArgumentException(); } - array[arrayIndex] = new KeyValuePair("Trailer", _Trailer); + array[arrayIndex] = new KeyValuePair("Trailer", _headers._Trailer); ++arrayIndex; } @@ -3866,7 +3777,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowArgumentException(); } - array[arrayIndex] = new KeyValuePair("Transfer-Encoding", _TransferEncoding); + array[arrayIndex] = new KeyValuePair("Transfer-Encoding", _headers._TransferEncoding); ++arrayIndex; } @@ -3877,7 +3788,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowArgumentException(); } - array[arrayIndex] = new KeyValuePair("Upgrade", _Upgrade); + array[arrayIndex] = new KeyValuePair("Upgrade", _headers._Upgrade); ++arrayIndex; } @@ -3888,7 +3799,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowArgumentException(); } - array[arrayIndex] = new KeyValuePair("Via", _Via); + array[arrayIndex] = new KeyValuePair("Via", _headers._Via); ++arrayIndex; } @@ -3899,7 +3810,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowArgumentException(); } - array[arrayIndex] = new KeyValuePair("Warning", _Warning); + array[arrayIndex] = new KeyValuePair("Warning", _headers._Warning); ++arrayIndex; } @@ -3910,7 +3821,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowArgumentException(); } - array[arrayIndex] = new KeyValuePair("Allow", _Allow); + array[arrayIndex] = new KeyValuePair("Allow", _headers._Allow); ++arrayIndex; } @@ -3921,7 +3832,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowArgumentException(); } - array[arrayIndex] = new KeyValuePair("Content-Length", _ContentLength); + array[arrayIndex] = new KeyValuePair("Content-Length", _headers._ContentLength); ++arrayIndex; } @@ -3932,7 +3843,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowArgumentException(); } - array[arrayIndex] = new KeyValuePair("Content-Type", _ContentType); + array[arrayIndex] = new KeyValuePair("Content-Type", _headers._ContentType); ++arrayIndex; } @@ -3943,7 +3854,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowArgumentException(); } - array[arrayIndex] = new KeyValuePair("Content-Encoding", _ContentEncoding); + array[arrayIndex] = new KeyValuePair("Content-Encoding", _headers._ContentEncoding); ++arrayIndex; } @@ -3954,7 +3865,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowArgumentException(); } - array[arrayIndex] = new KeyValuePair("Content-Language", _ContentLanguage); + array[arrayIndex] = new KeyValuePair("Content-Language", _headers._ContentLanguage); ++arrayIndex; } @@ -3965,7 +3876,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowArgumentException(); } - array[arrayIndex] = new KeyValuePair("Content-Location", _ContentLocation); + array[arrayIndex] = new KeyValuePair("Content-Location", _headers._ContentLocation); ++arrayIndex; } @@ -3976,7 +3887,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowArgumentException(); } - array[arrayIndex] = new KeyValuePair("Content-MD5", _ContentMD5); + array[arrayIndex] = new KeyValuePair("Content-MD5", _headers._ContentMD5); ++arrayIndex; } @@ -3987,7 +3898,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowArgumentException(); } - array[arrayIndex] = new KeyValuePair("Content-Range", _ContentRange); + array[arrayIndex] = new KeyValuePair("Content-Range", _headers._ContentRange); ++arrayIndex; } @@ -3998,7 +3909,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowArgumentException(); } - array[arrayIndex] = new KeyValuePair("Expires", _Expires); + array[arrayIndex] = new KeyValuePair("Expires", _headers._Expires); ++arrayIndex; } @@ -4009,7 +3920,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowArgumentException(); } - array[arrayIndex] = new KeyValuePair("Last-Modified", _LastModified); + array[arrayIndex] = new KeyValuePair("Last-Modified", _headers._LastModified); ++arrayIndex; } @@ -4020,7 +3931,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowArgumentException(); } - array[arrayIndex] = new KeyValuePair("Accept", _Accept); + array[arrayIndex] = new KeyValuePair("Accept", _headers._Accept); ++arrayIndex; } @@ -4031,7 +3942,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowArgumentException(); } - array[arrayIndex] = new KeyValuePair("Accept-Charset", _AcceptCharset); + array[arrayIndex] = new KeyValuePair("Accept-Charset", _headers._AcceptCharset); ++arrayIndex; } @@ -4042,7 +3953,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowArgumentException(); } - array[arrayIndex] = new KeyValuePair("Accept-Encoding", _AcceptEncoding); + array[arrayIndex] = new KeyValuePair("Accept-Encoding", _headers._AcceptEncoding); ++arrayIndex; } @@ -4053,7 +3964,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowArgumentException(); } - array[arrayIndex] = new KeyValuePair("Accept-Language", _AcceptLanguage); + array[arrayIndex] = new KeyValuePair("Accept-Language", _headers._AcceptLanguage); ++arrayIndex; } @@ -4064,7 +3975,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowArgumentException(); } - array[arrayIndex] = new KeyValuePair("Authorization", _Authorization); + array[arrayIndex] = new KeyValuePair("Authorization", _headers._Authorization); ++arrayIndex; } @@ -4075,7 +3986,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowArgumentException(); } - array[arrayIndex] = new KeyValuePair("Cookie", _Cookie); + array[arrayIndex] = new KeyValuePair("Cookie", _headers._Cookie); ++arrayIndex; } @@ -4086,7 +3997,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowArgumentException(); } - array[arrayIndex] = new KeyValuePair("Expect", _Expect); + array[arrayIndex] = new KeyValuePair("Expect", _headers._Expect); ++arrayIndex; } @@ -4097,7 +4008,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowArgumentException(); } - array[arrayIndex] = new KeyValuePair("From", _From); + array[arrayIndex] = new KeyValuePair("From", _headers._From); ++arrayIndex; } @@ -4108,7 +4019,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowArgumentException(); } - array[arrayIndex] = new KeyValuePair("Host", _Host); + array[arrayIndex] = new KeyValuePair("Host", _headers._Host); ++arrayIndex; } @@ -4119,7 +4030,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowArgumentException(); } - array[arrayIndex] = new KeyValuePair("If-Match", _IfMatch); + array[arrayIndex] = new KeyValuePair("If-Match", _headers._IfMatch); ++arrayIndex; } @@ -4130,7 +4041,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowArgumentException(); } - array[arrayIndex] = new KeyValuePair("If-Modified-Since", _IfModifiedSince); + array[arrayIndex] = new KeyValuePair("If-Modified-Since", _headers._IfModifiedSince); ++arrayIndex; } @@ -4141,7 +4052,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowArgumentException(); } - array[arrayIndex] = new KeyValuePair("If-None-Match", _IfNoneMatch); + array[arrayIndex] = new KeyValuePair("If-None-Match", _headers._IfNoneMatch); ++arrayIndex; } @@ -4152,7 +4063,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowArgumentException(); } - array[arrayIndex] = new KeyValuePair("If-Range", _IfRange); + array[arrayIndex] = new KeyValuePair("If-Range", _headers._IfRange); ++arrayIndex; } @@ -4163,7 +4074,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowArgumentException(); } - array[arrayIndex] = new KeyValuePair("If-Unmodified-Since", _IfUnmodifiedSince); + array[arrayIndex] = new KeyValuePair("If-Unmodified-Since", _headers._IfUnmodifiedSince); ++arrayIndex; } @@ -4174,7 +4085,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowArgumentException(); } - array[arrayIndex] = new KeyValuePair("Max-Forwards", _MaxForwards); + array[arrayIndex] = new KeyValuePair("Max-Forwards", _headers._MaxForwards); ++arrayIndex; } @@ -4185,7 +4096,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowArgumentException(); } - array[arrayIndex] = new KeyValuePair("Proxy-Authorization", _ProxyAuthorization); + array[arrayIndex] = new KeyValuePair("Proxy-Authorization", _headers._ProxyAuthorization); ++arrayIndex; } @@ -4196,7 +4107,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowArgumentException(); } - array[arrayIndex] = new KeyValuePair("Referer", _Referer); + array[arrayIndex] = new KeyValuePair("Referer", _headers._Referer); ++arrayIndex; } @@ -4207,7 +4118,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowArgumentException(); } - array[arrayIndex] = new KeyValuePair("Range", _Range); + array[arrayIndex] = new KeyValuePair("Range", _headers._Range); ++arrayIndex; } @@ -4218,7 +4129,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowArgumentException(); } - array[arrayIndex] = new KeyValuePair("TE", _TE); + array[arrayIndex] = new KeyValuePair("TE", _headers._TE); ++arrayIndex; } @@ -4229,7 +4140,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowArgumentException(); } - array[arrayIndex] = new KeyValuePair("Translate", _Translate); + array[arrayIndex] = new KeyValuePair("Translate", _headers._Translate); ++arrayIndex; } @@ -4240,7 +4151,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowArgumentException(); } - array[arrayIndex] = new KeyValuePair("User-Agent", _UserAgent); + array[arrayIndex] = new KeyValuePair("User-Agent", _headers._UserAgent); ++arrayIndex; } @@ -4251,7 +4162,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowArgumentException(); } - array[arrayIndex] = new KeyValuePair("Origin", _Origin); + array[arrayIndex] = new KeyValuePair("Origin", _headers._Origin); ++arrayIndex; } @@ -4262,7 +4173,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowArgumentException(); } - array[arrayIndex] = new KeyValuePair("Access-Control-Request-Method", _AccessControlRequestMethod); + array[arrayIndex] = new KeyValuePair("Access-Control-Request-Method", _headers._AccessControlRequestMethod); ++arrayIndex; } @@ -4273,7 +4184,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowArgumentException(); } - array[arrayIndex] = new KeyValuePair("Access-Control-Request-Headers", _AccessControlRequestHeaders); + array[arrayIndex] = new KeyValuePair("Access-Control-Request-Headers", _headers._AccessControlRequestHeaders); ++arrayIndex; } @@ -4297,12 +4208,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 1L) != 0)) { - _CacheControl = AppendValue(_CacheControl, value); + _headers._CacheControl = AppendValue(_headers._CacheControl, value); } else { _bits |= 1L; - _CacheControl = new StringValues(value); + _headers._CacheControl = new StringValues(value); } return; } @@ -4311,12 +4222,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 131072L) != 0)) { - _ContentRange = AppendValue(_ContentRange, value); + _headers._ContentRange = AppendValue(_headers._ContentRange, value); } else { _bits |= 131072L; - _ContentRange = new StringValues(value); + _headers._ContentRange = new StringValues(value); } return; } @@ -4325,12 +4236,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 524288L) != 0)) { - _LastModified = AppendValue(_LastModified, value); + _headers._LastModified = AppendValue(_headers._LastModified, value); } else { _bits |= 524288L; - _LastModified = new StringValues(value); + _headers._LastModified = new StringValues(value); } return; } @@ -4339,12 +4250,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 16777216L) != 0)) { - _Authorization = AppendValue(_Authorization, value); + _headers._Authorization = AppendValue(_headers._Authorization, value); } else { _bits |= 16777216L; - _Authorization = new StringValues(value); + _headers._Authorization = new StringValues(value); } return; } @@ -4353,12 +4264,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 2147483648L) != 0)) { - _IfNoneMatch = AppendValue(_IfNoneMatch, value); + _headers._IfNoneMatch = AppendValue(_headers._IfNoneMatch, value); } else { _bits |= 2147483648L; - _IfNoneMatch = new StringValues(value); + _headers._IfNoneMatch = new StringValues(value); } return; } @@ -4371,12 +4282,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 2L) != 0)) { - _Connection = AppendValue(_Connection, value); + _headers._Connection = AppendValue(_headers._Connection, value); } else { _bits |= 2L; - _Connection = new StringValues(value); + _headers._Connection = new StringValues(value); } return; } @@ -4385,12 +4296,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 8L) != 0)) { - _KeepAlive = AppendValue(_KeepAlive, value); + _headers._KeepAlive = AppendValue(_headers._KeepAlive, value); } else { _bits |= 8L; - _KeepAlive = new StringValues(value); + _headers._KeepAlive = new StringValues(value); } return; } @@ -4399,12 +4310,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 1099511627776L) != 0)) { - _UserAgent = AppendValue(_UserAgent, value); + _headers._UserAgent = AppendValue(_headers._UserAgent, value); } else { _bits |= 1099511627776L; - _UserAgent = new StringValues(value); + _headers._UserAgent = new StringValues(value); } return; } @@ -4417,12 +4328,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 4L) != 0)) { - _Date = AppendValue(_Date, value); + _headers._Date = AppendValue(_headers._Date, value); } else { _bits |= 4L; - _Date = new StringValues(value); + _headers._Date = new StringValues(value); } return; } @@ -4431,12 +4342,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 134217728L) != 0)) { - _From = AppendValue(_From, value); + _headers._From = AppendValue(_headers._From, value); } else { _bits |= 134217728L; - _From = new StringValues(value); + _headers._From = new StringValues(value); } return; } @@ -4445,12 +4356,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 268435456L) != 0)) { - _Host = AppendValue(_Host, value); + _headers._Host = AppendValue(_headers._Host, value); } else { _bits |= 268435456L; - _Host = new StringValues(value); + _headers._Host = new StringValues(value); } return; } @@ -4463,12 +4374,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 16L) != 0)) { - _Pragma = AppendValue(_Pragma, value); + _headers._Pragma = AppendValue(_headers._Pragma, value); } else { _bits |= 16L; - _Pragma = new StringValues(value); + _headers._Pragma = new StringValues(value); } return; } @@ -4477,12 +4388,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 1048576L) != 0)) { - _Accept = AppendValue(_Accept, value); + _headers._Accept = AppendValue(_headers._Accept, value); } else { _bits |= 1048576L; - _Accept = new StringValues(value); + _headers._Accept = new StringValues(value); } return; } @@ -4491,12 +4402,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 33554432L) != 0)) { - _Cookie = AppendValue(_Cookie, value); + _headers._Cookie = AppendValue(_headers._Cookie, value); } else { _bits |= 33554432L; - _Cookie = new StringValues(value); + _headers._Cookie = new StringValues(value); } return; } @@ -4505,12 +4416,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 67108864L) != 0)) { - _Expect = AppendValue(_Expect, value); + _headers._Expect = AppendValue(_headers._Expect, value); } else { _bits |= 67108864L; - _Expect = new StringValues(value); + _headers._Expect = new StringValues(value); } return; } @@ -4519,12 +4430,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 2199023255552L) != 0)) { - _Origin = AppendValue(_Origin, value); + _headers._Origin = AppendValue(_headers._Origin, value); } else { _bits |= 2199023255552L; - _Origin = new StringValues(value); + _headers._Origin = new StringValues(value); } return; } @@ -4537,12 +4448,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 32L) != 0)) { - _Trailer = AppendValue(_Trailer, value); + _headers._Trailer = AppendValue(_headers._Trailer, value); } else { _bits |= 32L; - _Trailer = new StringValues(value); + _headers._Trailer = new StringValues(value); } return; } @@ -4551,12 +4462,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 128L) != 0)) { - _Upgrade = AppendValue(_Upgrade, value); + _headers._Upgrade = AppendValue(_headers._Upgrade, value); } else { _bits |= 128L; - _Upgrade = new StringValues(value); + _headers._Upgrade = new StringValues(value); } return; } @@ -4565,12 +4476,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 512L) != 0)) { - _Warning = AppendValue(_Warning, value); + _headers._Warning = AppendValue(_headers._Warning, value); } else { _bits |= 512L; - _Warning = new StringValues(value); + _headers._Warning = new StringValues(value); } return; } @@ -4579,12 +4490,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 262144L) != 0)) { - _Expires = AppendValue(_Expires, value); + _headers._Expires = AppendValue(_headers._Expires, value); } else { _bits |= 262144L; - _Expires = new StringValues(value); + _headers._Expires = new StringValues(value); } return; } @@ -4593,12 +4504,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 68719476736L) != 0)) { - _Referer = AppendValue(_Referer, value); + _headers._Referer = AppendValue(_headers._Referer, value); } else { _bits |= 68719476736L; - _Referer = new StringValues(value); + _headers._Referer = new StringValues(value); } return; } @@ -4611,12 +4522,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 64L) != 0)) { - _TransferEncoding = AppendValue(_TransferEncoding, value); + _headers._TransferEncoding = AppendValue(_headers._TransferEncoding, value); } else { _bits |= 64L; - _TransferEncoding = new StringValues(value); + _headers._TransferEncoding = new StringValues(value); } return; } @@ -4625,12 +4536,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 1073741824L) != 0)) { - _IfModifiedSince = AppendValue(_IfModifiedSince, value); + _headers._IfModifiedSince = AppendValue(_headers._IfModifiedSince, value); } else { _bits |= 1073741824L; - _IfModifiedSince = new StringValues(value); + _headers._IfModifiedSince = new StringValues(value); } return; } @@ -4643,12 +4554,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 256L) != 0)) { - _Via = AppendValue(_Via, value); + _headers._Via = AppendValue(_headers._Via, value); } else { _bits |= 256L; - _Via = new StringValues(value); + _headers._Via = new StringValues(value); } return; } @@ -4661,12 +4572,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 1024L) != 0)) { - _Allow = AppendValue(_Allow, value); + _headers._Allow = AppendValue(_headers._Allow, value); } else { _bits |= 1024L; - _Allow = new StringValues(value); + _headers._Allow = new StringValues(value); } return; } @@ -4675,12 +4586,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 137438953472L) != 0)) { - _Range = AppendValue(_Range, value); + _headers._Range = AppendValue(_headers._Range, value); } else { _bits |= 137438953472L; - _Range = new StringValues(value); + _headers._Range = new StringValues(value); } return; } @@ -4693,12 +4604,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 2048L) != 0)) { - _ContentLength = AppendValue(_ContentLength, value); + _headers._ContentLength = AppendValue(_headers._ContentLength, value); } else { _bits |= 2048L; - _ContentLength = new StringValues(value); + _headers._ContentLength = new StringValues(value); } return; } @@ -4707,12 +4618,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 2097152L) != 0)) { - _AcceptCharset = AppendValue(_AcceptCharset, value); + _headers._AcceptCharset = AppendValue(_headers._AcceptCharset, value); } else { _bits |= 2097152L; - _AcceptCharset = new StringValues(value); + _headers._AcceptCharset = new StringValues(value); } return; } @@ -4725,12 +4636,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 4096L) != 0)) { - _ContentType = AppendValue(_ContentType, value); + _headers._ContentType = AppendValue(_headers._ContentType, value); } else { _bits |= 4096L; - _ContentType = new StringValues(value); + _headers._ContentType = new StringValues(value); } return; } @@ -4739,12 +4650,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 17179869184L) != 0)) { - _MaxForwards = AppendValue(_MaxForwards, value); + _headers._MaxForwards = AppendValue(_headers._MaxForwards, value); } else { _bits |= 17179869184L; - _MaxForwards = new StringValues(value); + _headers._MaxForwards = new StringValues(value); } return; } @@ -4757,12 +4668,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 8192L) != 0)) { - _ContentEncoding = AppendValue(_ContentEncoding, value); + _headers._ContentEncoding = AppendValue(_headers._ContentEncoding, value); } else { _bits |= 8192L; - _ContentEncoding = new StringValues(value); + _headers._ContentEncoding = new StringValues(value); } return; } @@ -4771,12 +4682,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 16384L) != 0)) { - _ContentLanguage = AppendValue(_ContentLanguage, value); + _headers._ContentLanguage = AppendValue(_headers._ContentLanguage, value); } else { _bits |= 16384L; - _ContentLanguage = new StringValues(value); + _headers._ContentLanguage = new StringValues(value); } return; } @@ -4785,12 +4696,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 32768L) != 0)) { - _ContentLocation = AppendValue(_ContentLocation, value); + _headers._ContentLocation = AppendValue(_headers._ContentLocation, value); } else { _bits |= 32768L; - _ContentLocation = new StringValues(value); + _headers._ContentLocation = new StringValues(value); } return; } @@ -4803,12 +4714,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 65536L) != 0)) { - _ContentMD5 = AppendValue(_ContentMD5, value); + _headers._ContentMD5 = AppendValue(_headers._ContentMD5, value); } else { _bits |= 65536L; - _ContentMD5 = new StringValues(value); + _headers._ContentMD5 = new StringValues(value); } return; } @@ -4821,12 +4732,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 4194304L) != 0)) { - _AcceptEncoding = AppendValue(_AcceptEncoding, value); + _headers._AcceptEncoding = AppendValue(_headers._AcceptEncoding, value); } else { _bits |= 4194304L; - _AcceptEncoding = new StringValues(value); + _headers._AcceptEncoding = new StringValues(value); } return; } @@ -4835,12 +4746,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 8388608L) != 0)) { - _AcceptLanguage = AppendValue(_AcceptLanguage, value); + _headers._AcceptLanguage = AppendValue(_headers._AcceptLanguage, value); } else { _bits |= 8388608L; - _AcceptLanguage = new StringValues(value); + _headers._AcceptLanguage = new StringValues(value); } return; } @@ -4853,12 +4764,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 536870912L) != 0)) { - _IfMatch = AppendValue(_IfMatch, value); + _headers._IfMatch = AppendValue(_headers._IfMatch, value); } else { _bits |= 536870912L; - _IfMatch = new StringValues(value); + _headers._IfMatch = new StringValues(value); } return; } @@ -4867,12 +4778,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 4294967296L) != 0)) { - _IfRange = AppendValue(_IfRange, value); + _headers._IfRange = AppendValue(_headers._IfRange, value); } else { _bits |= 4294967296L; - _IfRange = new StringValues(value); + _headers._IfRange = new StringValues(value); } return; } @@ -4885,12 +4796,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 8589934592L) != 0)) { - _IfUnmodifiedSince = AppendValue(_IfUnmodifiedSince, value); + _headers._IfUnmodifiedSince = AppendValue(_headers._IfUnmodifiedSince, value); } else { _bits |= 8589934592L; - _IfUnmodifiedSince = new StringValues(value); + _headers._IfUnmodifiedSince = new StringValues(value); } return; } @@ -4899,12 +4810,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 34359738368L) != 0)) { - _ProxyAuthorization = AppendValue(_ProxyAuthorization, value); + _headers._ProxyAuthorization = AppendValue(_headers._ProxyAuthorization, value); } else { _bits |= 34359738368L; - _ProxyAuthorization = new StringValues(value); + _headers._ProxyAuthorization = new StringValues(value); } return; } @@ -4917,12 +4828,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 274877906944L) != 0)) { - _TE = AppendValue(_TE, value); + _headers._TE = AppendValue(_headers._TE, value); } else { _bits |= 274877906944L; - _TE = new StringValues(value); + _headers._TE = new StringValues(value); } return; } @@ -4935,12 +4846,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 549755813888L) != 0)) { - _Translate = AppendValue(_Translate, value); + _headers._Translate = AppendValue(_headers._Translate, value); } else { _bits |= 549755813888L; - _Translate = new StringValues(value); + _headers._Translate = new StringValues(value); } return; } @@ -4953,12 +4864,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 4398046511104L) != 0)) { - _AccessControlRequestMethod = AppendValue(_AccessControlRequestMethod, value); + _headers._AccessControlRequestMethod = AppendValue(_headers._AccessControlRequestMethod, value); } else { _bits |= 4398046511104L; - _AccessControlRequestMethod = new StringValues(value); + _headers._AccessControlRequestMethod = new StringValues(value); } return; } @@ -4971,12 +4882,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 8796093022208L) != 0)) { - _AccessControlRequestHeaders = AppendValue(_AccessControlRequestHeaders, value); + _headers._AccessControlRequestHeaders = AppendValue(_headers._AccessControlRequestHeaders, value); } else { _bits |= 8796093022208L; - _AccessControlRequestHeaders = new StringValues(value); + _headers._AccessControlRequestHeaders = new StringValues(value); } return; } @@ -4989,6 +4900,55 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http Unknown.TryGetValue(key, out existing); Unknown[key] = AppendValue(existing, value); } + private struct HeaderReferences + { + public StringValues _CacheControl; + public StringValues _Connection; + public StringValues _Date; + public StringValues _KeepAlive; + public StringValues _Pragma; + public StringValues _Trailer; + public StringValues _TransferEncoding; + public StringValues _Upgrade; + public StringValues _Via; + public StringValues _Warning; + public StringValues _Allow; + public StringValues _ContentLength; + public StringValues _ContentType; + public StringValues _ContentEncoding; + public StringValues _ContentLanguage; + public StringValues _ContentLocation; + public StringValues _ContentMD5; + public StringValues _ContentRange; + public StringValues _Expires; + public StringValues _LastModified; + public StringValues _Accept; + public StringValues _AcceptCharset; + public StringValues _AcceptEncoding; + public StringValues _AcceptLanguage; + public StringValues _Authorization; + public StringValues _Cookie; + public StringValues _Expect; + public StringValues _From; + public StringValues _Host; + public StringValues _IfMatch; + public StringValues _IfModifiedSince; + public StringValues _IfNoneMatch; + public StringValues _IfRange; + public StringValues _IfUnmodifiedSince; + public StringValues _MaxForwards; + public StringValues _ProxyAuthorization; + public StringValues _Referer; + public StringValues _Range; + public StringValues _TE; + public StringValues _Translate; + public StringValues _UserAgent; + public StringValues _Origin; + public StringValues _AccessControlRequestMethod; + public StringValues _AccessControlRequestHeaders; + + } + public partial struct Enumerator { public bool MoveNext() @@ -5135,7 +5095,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http state0: if (((_bits & 1L) != 0)) { - _current = new KeyValuePair("Cache-Control", _collection._CacheControl); + _current = new KeyValuePair("Cache-Control", _collection._headers._CacheControl); _state = 1; return true; } @@ -5143,7 +5103,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http state1: if (((_bits & 2L) != 0)) { - _current = new KeyValuePair("Connection", _collection._Connection); + _current = new KeyValuePair("Connection", _collection._headers._Connection); _state = 2; return true; } @@ -5151,7 +5111,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http state2: if (((_bits & 4L) != 0)) { - _current = new KeyValuePair("Date", _collection._Date); + _current = new KeyValuePair("Date", _collection._headers._Date); _state = 3; return true; } @@ -5159,7 +5119,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http state3: if (((_bits & 8L) != 0)) { - _current = new KeyValuePair("Keep-Alive", _collection._KeepAlive); + _current = new KeyValuePair("Keep-Alive", _collection._headers._KeepAlive); _state = 4; return true; } @@ -5167,7 +5127,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http state4: if (((_bits & 16L) != 0)) { - _current = new KeyValuePair("Pragma", _collection._Pragma); + _current = new KeyValuePair("Pragma", _collection._headers._Pragma); _state = 5; return true; } @@ -5175,7 +5135,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http state5: if (((_bits & 32L) != 0)) { - _current = new KeyValuePair("Trailer", _collection._Trailer); + _current = new KeyValuePair("Trailer", _collection._headers._Trailer); _state = 6; return true; } @@ -5183,7 +5143,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http state6: if (((_bits & 64L) != 0)) { - _current = new KeyValuePair("Transfer-Encoding", _collection._TransferEncoding); + _current = new KeyValuePair("Transfer-Encoding", _collection._headers._TransferEncoding); _state = 7; return true; } @@ -5191,7 +5151,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http state7: if (((_bits & 128L) != 0)) { - _current = new KeyValuePair("Upgrade", _collection._Upgrade); + _current = new KeyValuePair("Upgrade", _collection._headers._Upgrade); _state = 8; return true; } @@ -5199,7 +5159,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http state8: if (((_bits & 256L) != 0)) { - _current = new KeyValuePair("Via", _collection._Via); + _current = new KeyValuePair("Via", _collection._headers._Via); _state = 9; return true; } @@ -5207,7 +5167,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http state9: if (((_bits & 512L) != 0)) { - _current = new KeyValuePair("Warning", _collection._Warning); + _current = new KeyValuePair("Warning", _collection._headers._Warning); _state = 10; return true; } @@ -5215,7 +5175,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http state10: if (((_bits & 1024L) != 0)) { - _current = new KeyValuePair("Allow", _collection._Allow); + _current = new KeyValuePair("Allow", _collection._headers._Allow); _state = 11; return true; } @@ -5223,7 +5183,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http state11: if (((_bits & 2048L) != 0)) { - _current = new KeyValuePair("Content-Length", _collection._ContentLength); + _current = new KeyValuePair("Content-Length", _collection._headers._ContentLength); _state = 12; return true; } @@ -5231,7 +5191,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http state12: if (((_bits & 4096L) != 0)) { - _current = new KeyValuePair("Content-Type", _collection._ContentType); + _current = new KeyValuePair("Content-Type", _collection._headers._ContentType); _state = 13; return true; } @@ -5239,7 +5199,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http state13: if (((_bits & 8192L) != 0)) { - _current = new KeyValuePair("Content-Encoding", _collection._ContentEncoding); + _current = new KeyValuePair("Content-Encoding", _collection._headers._ContentEncoding); _state = 14; return true; } @@ -5247,7 +5207,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http state14: if (((_bits & 16384L) != 0)) { - _current = new KeyValuePair("Content-Language", _collection._ContentLanguage); + _current = new KeyValuePair("Content-Language", _collection._headers._ContentLanguage); _state = 15; return true; } @@ -5255,7 +5215,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http state15: if (((_bits & 32768L) != 0)) { - _current = new KeyValuePair("Content-Location", _collection._ContentLocation); + _current = new KeyValuePair("Content-Location", _collection._headers._ContentLocation); _state = 16; return true; } @@ -5263,7 +5223,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http state16: if (((_bits & 65536L) != 0)) { - _current = new KeyValuePair("Content-MD5", _collection._ContentMD5); + _current = new KeyValuePair("Content-MD5", _collection._headers._ContentMD5); _state = 17; return true; } @@ -5271,7 +5231,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http state17: if (((_bits & 131072L) != 0)) { - _current = new KeyValuePair("Content-Range", _collection._ContentRange); + _current = new KeyValuePair("Content-Range", _collection._headers._ContentRange); _state = 18; return true; } @@ -5279,7 +5239,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http state18: if (((_bits & 262144L) != 0)) { - _current = new KeyValuePair("Expires", _collection._Expires); + _current = new KeyValuePair("Expires", _collection._headers._Expires); _state = 19; return true; } @@ -5287,7 +5247,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http state19: if (((_bits & 524288L) != 0)) { - _current = new KeyValuePair("Last-Modified", _collection._LastModified); + _current = new KeyValuePair("Last-Modified", _collection._headers._LastModified); _state = 20; return true; } @@ -5295,7 +5255,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http state20: if (((_bits & 1048576L) != 0)) { - _current = new KeyValuePair("Accept", _collection._Accept); + _current = new KeyValuePair("Accept", _collection._headers._Accept); _state = 21; return true; } @@ -5303,7 +5263,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http state21: if (((_bits & 2097152L) != 0)) { - _current = new KeyValuePair("Accept-Charset", _collection._AcceptCharset); + _current = new KeyValuePair("Accept-Charset", _collection._headers._AcceptCharset); _state = 22; return true; } @@ -5311,7 +5271,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http state22: if (((_bits & 4194304L) != 0)) { - _current = new KeyValuePair("Accept-Encoding", _collection._AcceptEncoding); + _current = new KeyValuePair("Accept-Encoding", _collection._headers._AcceptEncoding); _state = 23; return true; } @@ -5319,7 +5279,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http state23: if (((_bits & 8388608L) != 0)) { - _current = new KeyValuePair("Accept-Language", _collection._AcceptLanguage); + _current = new KeyValuePair("Accept-Language", _collection._headers._AcceptLanguage); _state = 24; return true; } @@ -5327,7 +5287,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http state24: if (((_bits & 16777216L) != 0)) { - _current = new KeyValuePair("Authorization", _collection._Authorization); + _current = new KeyValuePair("Authorization", _collection._headers._Authorization); _state = 25; return true; } @@ -5335,7 +5295,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http state25: if (((_bits & 33554432L) != 0)) { - _current = new KeyValuePair("Cookie", _collection._Cookie); + _current = new KeyValuePair("Cookie", _collection._headers._Cookie); _state = 26; return true; } @@ -5343,7 +5303,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http state26: if (((_bits & 67108864L) != 0)) { - _current = new KeyValuePair("Expect", _collection._Expect); + _current = new KeyValuePair("Expect", _collection._headers._Expect); _state = 27; return true; } @@ -5351,7 +5311,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http state27: if (((_bits & 134217728L) != 0)) { - _current = new KeyValuePair("From", _collection._From); + _current = new KeyValuePair("From", _collection._headers._From); _state = 28; return true; } @@ -5359,7 +5319,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http state28: if (((_bits & 268435456L) != 0)) { - _current = new KeyValuePair("Host", _collection._Host); + _current = new KeyValuePair("Host", _collection._headers._Host); _state = 29; return true; } @@ -5367,7 +5327,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http state29: if (((_bits & 536870912L) != 0)) { - _current = new KeyValuePair("If-Match", _collection._IfMatch); + _current = new KeyValuePair("If-Match", _collection._headers._IfMatch); _state = 30; return true; } @@ -5375,7 +5335,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http state30: if (((_bits & 1073741824L) != 0)) { - _current = new KeyValuePair("If-Modified-Since", _collection._IfModifiedSince); + _current = new KeyValuePair("If-Modified-Since", _collection._headers._IfModifiedSince); _state = 31; return true; } @@ -5383,7 +5343,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http state31: if (((_bits & 2147483648L) != 0)) { - _current = new KeyValuePair("If-None-Match", _collection._IfNoneMatch); + _current = new KeyValuePair("If-None-Match", _collection._headers._IfNoneMatch); _state = 32; return true; } @@ -5391,7 +5351,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http state32: if (((_bits & 4294967296L) != 0)) { - _current = new KeyValuePair("If-Range", _collection._IfRange); + _current = new KeyValuePair("If-Range", _collection._headers._IfRange); _state = 33; return true; } @@ -5399,7 +5359,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http state33: if (((_bits & 8589934592L) != 0)) { - _current = new KeyValuePair("If-Unmodified-Since", _collection._IfUnmodifiedSince); + _current = new KeyValuePair("If-Unmodified-Since", _collection._headers._IfUnmodifiedSince); _state = 34; return true; } @@ -5407,7 +5367,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http state34: if (((_bits & 17179869184L) != 0)) { - _current = new KeyValuePair("Max-Forwards", _collection._MaxForwards); + _current = new KeyValuePair("Max-Forwards", _collection._headers._MaxForwards); _state = 35; return true; } @@ -5415,7 +5375,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http state35: if (((_bits & 34359738368L) != 0)) { - _current = new KeyValuePair("Proxy-Authorization", _collection._ProxyAuthorization); + _current = new KeyValuePair("Proxy-Authorization", _collection._headers._ProxyAuthorization); _state = 36; return true; } @@ -5423,7 +5383,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http state36: if (((_bits & 68719476736L) != 0)) { - _current = new KeyValuePair("Referer", _collection._Referer); + _current = new KeyValuePair("Referer", _collection._headers._Referer); _state = 37; return true; } @@ -5431,7 +5391,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http state37: if (((_bits & 137438953472L) != 0)) { - _current = new KeyValuePair("Range", _collection._Range); + _current = new KeyValuePair("Range", _collection._headers._Range); _state = 38; return true; } @@ -5439,7 +5399,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http state38: if (((_bits & 274877906944L) != 0)) { - _current = new KeyValuePair("TE", _collection._TE); + _current = new KeyValuePair("TE", _collection._headers._TE); _state = 39; return true; } @@ -5447,7 +5407,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http state39: if (((_bits & 549755813888L) != 0)) { - _current = new KeyValuePair("Translate", _collection._Translate); + _current = new KeyValuePair("Translate", _collection._headers._Translate); _state = 40; return true; } @@ -5455,7 +5415,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http state40: if (((_bits & 1099511627776L) != 0)) { - _current = new KeyValuePair("User-Agent", _collection._UserAgent); + _current = new KeyValuePair("User-Agent", _collection._headers._UserAgent); _state = 41; return true; } @@ -5463,7 +5423,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http state41: if (((_bits & 2199023255552L) != 0)) { - _current = new KeyValuePair("Origin", _collection._Origin); + _current = new KeyValuePair("Origin", _collection._headers._Origin); _state = 42; return true; } @@ -5471,7 +5431,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http state42: if (((_bits & 4398046511104L) != 0)) { - _current = new KeyValuePair("Access-Control-Request-Method", _collection._AccessControlRequestMethod); + _current = new KeyValuePair("Access-Control-Request-Method", _collection._headers._AccessControlRequestMethod); _state = 43; return true; } @@ -5479,7 +5439,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http state43: if (((_bits & 8796093022208L) != 0)) { - _current = new KeyValuePair("Access-Control-Request-Headers", _collection._AccessControlRequestHeaders); + _current = new KeyValuePair("Access-Control-Request-Headers", _collection._headers._AccessControlRequestHeaders); _state = 44; return true; } @@ -5504,49 +5464,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http }; private long _bits = 0; - - private StringValues _CacheControl; - private StringValues _Connection; - private StringValues _Date; - private StringValues _KeepAlive; - private StringValues _Pragma; - private StringValues _Trailer; - private StringValues _TransferEncoding; - private StringValues _Upgrade; - private StringValues _Via; - private StringValues _Warning; - private StringValues _Allow; - private StringValues _ContentLength; - private StringValues _ContentType; - private StringValues _ContentEncoding; - private StringValues _ContentLanguage; - private StringValues _ContentLocation; - private StringValues _ContentMD5; - private StringValues _ContentRange; - private StringValues _Expires; - private StringValues _LastModified; - private StringValues _AcceptRanges; - private StringValues _Age; - private StringValues _ETag; - private StringValues _Location; - private StringValues _ProxyAutheticate; - private StringValues _RetryAfter; - private StringValues _Server; - private StringValues _SetCookie; - private StringValues _Vary; - private StringValues _WWWAuthenticate; - private StringValues _AccessControlAllowCredentials; - private StringValues _AccessControlAllowHeaders; - private StringValues _AccessControlAllowMethods; - private StringValues _AccessControlAllowOrigin; - private StringValues _AccessControlExposeHeaders; - private StringValues _AccessControlMaxAge; - - private byte[] _rawConnection; - private byte[] _rawDate; - private byte[] _rawTransferEncoding; - private byte[] _rawContentLength; - private byte[] _rawServer; + private HeaderReferences _headers; public StringValues HeaderCacheControl { @@ -5554,14 +5472,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 1L) != 0)) { - return _CacheControl; + return _headers._CacheControl; } return StringValues.Empty; } set { _bits |= 1L; - _CacheControl = value; + _headers._CacheControl = value; } } public StringValues HeaderConnection @@ -5570,15 +5488,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 2L) != 0)) { - return _Connection; + return _headers._Connection; } return StringValues.Empty; } set { _bits |= 2L; - _Connection = value; - _rawConnection = null; + _headers._Connection = value; + _headers._rawConnection = null; } } public StringValues HeaderDate @@ -5587,15 +5505,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 4L) != 0)) { - return _Date; + return _headers._Date; } return StringValues.Empty; } set { _bits |= 4L; - _Date = value; - _rawDate = null; + _headers._Date = value; + _headers._rawDate = null; } } public StringValues HeaderKeepAlive @@ -5604,14 +5522,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 8L) != 0)) { - return _KeepAlive; + return _headers._KeepAlive; } return StringValues.Empty; } set { _bits |= 8L; - _KeepAlive = value; + _headers._KeepAlive = value; } } public StringValues HeaderPragma @@ -5620,14 +5538,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 16L) != 0)) { - return _Pragma; + return _headers._Pragma; } return StringValues.Empty; } set { _bits |= 16L; - _Pragma = value; + _headers._Pragma = value; } } public StringValues HeaderTrailer @@ -5636,14 +5554,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 32L) != 0)) { - return _Trailer; + return _headers._Trailer; } return StringValues.Empty; } set { _bits |= 32L; - _Trailer = value; + _headers._Trailer = value; } } public StringValues HeaderTransferEncoding @@ -5652,15 +5570,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 64L) != 0)) { - return _TransferEncoding; + return _headers._TransferEncoding; } return StringValues.Empty; } set { _bits |= 64L; - _TransferEncoding = value; - _rawTransferEncoding = null; + _headers._TransferEncoding = value; + _headers._rawTransferEncoding = null; } } public StringValues HeaderUpgrade @@ -5669,14 +5587,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 128L) != 0)) { - return _Upgrade; + return _headers._Upgrade; } return StringValues.Empty; } set { _bits |= 128L; - _Upgrade = value; + _headers._Upgrade = value; } } public StringValues HeaderVia @@ -5685,14 +5603,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 256L) != 0)) { - return _Via; + return _headers._Via; } return StringValues.Empty; } set { _bits |= 256L; - _Via = value; + _headers._Via = value; } } public StringValues HeaderWarning @@ -5701,14 +5619,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 512L) != 0)) { - return _Warning; + return _headers._Warning; } return StringValues.Empty; } set { _bits |= 512L; - _Warning = value; + _headers._Warning = value; } } public StringValues HeaderAllow @@ -5717,14 +5635,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 1024L) != 0)) { - return _Allow; + return _headers._Allow; } return StringValues.Empty; } set { _bits |= 1024L; - _Allow = value; + _headers._Allow = value; } } public StringValues HeaderContentLength @@ -5733,15 +5651,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 2048L) != 0)) { - return _ContentLength; + return _headers._ContentLength; } return StringValues.Empty; } set { _bits |= 2048L; - _ContentLength = value; - _rawContentLength = null; + _headers._ContentLength = value; + _headers._rawContentLength = null; } } public StringValues HeaderContentType @@ -5750,14 +5668,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 4096L) != 0)) { - return _ContentType; + return _headers._ContentType; } return StringValues.Empty; } set { _bits |= 4096L; - _ContentType = value; + _headers._ContentType = value; } } public StringValues HeaderContentEncoding @@ -5766,14 +5684,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 8192L) != 0)) { - return _ContentEncoding; + return _headers._ContentEncoding; } return StringValues.Empty; } set { _bits |= 8192L; - _ContentEncoding = value; + _headers._ContentEncoding = value; } } public StringValues HeaderContentLanguage @@ -5782,14 +5700,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 16384L) != 0)) { - return _ContentLanguage; + return _headers._ContentLanguage; } return StringValues.Empty; } set { _bits |= 16384L; - _ContentLanguage = value; + _headers._ContentLanguage = value; } } public StringValues HeaderContentLocation @@ -5798,14 +5716,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 32768L) != 0)) { - return _ContentLocation; + return _headers._ContentLocation; } return StringValues.Empty; } set { _bits |= 32768L; - _ContentLocation = value; + _headers._ContentLocation = value; } } public StringValues HeaderContentMD5 @@ -5814,14 +5732,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 65536L) != 0)) { - return _ContentMD5; + return _headers._ContentMD5; } return StringValues.Empty; } set { _bits |= 65536L; - _ContentMD5 = value; + _headers._ContentMD5 = value; } } public StringValues HeaderContentRange @@ -5830,14 +5748,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 131072L) != 0)) { - return _ContentRange; + return _headers._ContentRange; } return StringValues.Empty; } set { _bits |= 131072L; - _ContentRange = value; + _headers._ContentRange = value; } } public StringValues HeaderExpires @@ -5846,14 +5764,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 262144L) != 0)) { - return _Expires; + return _headers._Expires; } return StringValues.Empty; } set { _bits |= 262144L; - _Expires = value; + _headers._Expires = value; } } public StringValues HeaderLastModified @@ -5862,14 +5780,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 524288L) != 0)) { - return _LastModified; + return _headers._LastModified; } return StringValues.Empty; } set { _bits |= 524288L; - _LastModified = value; + _headers._LastModified = value; } } public StringValues HeaderAcceptRanges @@ -5878,14 +5796,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 1048576L) != 0)) { - return _AcceptRanges; + return _headers._AcceptRanges; } return StringValues.Empty; } set { _bits |= 1048576L; - _AcceptRanges = value; + _headers._AcceptRanges = value; } } public StringValues HeaderAge @@ -5894,14 +5812,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 2097152L) != 0)) { - return _Age; + return _headers._Age; } return StringValues.Empty; } set { _bits |= 2097152L; - _Age = value; + _headers._Age = value; } } public StringValues HeaderETag @@ -5910,14 +5828,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 4194304L) != 0)) { - return _ETag; + return _headers._ETag; } return StringValues.Empty; } set { _bits |= 4194304L; - _ETag = value; + _headers._ETag = value; } } public StringValues HeaderLocation @@ -5926,14 +5844,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 8388608L) != 0)) { - return _Location; + return _headers._Location; } return StringValues.Empty; } set { _bits |= 8388608L; - _Location = value; + _headers._Location = value; } } public StringValues HeaderProxyAutheticate @@ -5942,14 +5860,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 16777216L) != 0)) { - return _ProxyAutheticate; + return _headers._ProxyAutheticate; } return StringValues.Empty; } set { _bits |= 16777216L; - _ProxyAutheticate = value; + _headers._ProxyAutheticate = value; } } public StringValues HeaderRetryAfter @@ -5958,14 +5876,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 33554432L) != 0)) { - return _RetryAfter; + return _headers._RetryAfter; } return StringValues.Empty; } set { _bits |= 33554432L; - _RetryAfter = value; + _headers._RetryAfter = value; } } public StringValues HeaderServer @@ -5974,15 +5892,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 67108864L) != 0)) { - return _Server; + return _headers._Server; } return StringValues.Empty; } set { _bits |= 67108864L; - _Server = value; - _rawServer = null; + _headers._Server = value; + _headers._rawServer = null; } } public StringValues HeaderSetCookie @@ -5991,14 +5909,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 134217728L) != 0)) { - return _SetCookie; + return _headers._SetCookie; } return StringValues.Empty; } set { _bits |= 134217728L; - _SetCookie = value; + _headers._SetCookie = value; } } public StringValues HeaderVary @@ -6007,14 +5925,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 268435456L) != 0)) { - return _Vary; + return _headers._Vary; } return StringValues.Empty; } set { _bits |= 268435456L; - _Vary = value; + _headers._Vary = value; } } public StringValues HeaderWWWAuthenticate @@ -6023,14 +5941,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 536870912L) != 0)) { - return _WWWAuthenticate; + return _headers._WWWAuthenticate; } return StringValues.Empty; } set { _bits |= 536870912L; - _WWWAuthenticate = value; + _headers._WWWAuthenticate = value; } } public StringValues HeaderAccessControlAllowCredentials @@ -6039,14 +5957,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 1073741824L) != 0)) { - return _AccessControlAllowCredentials; + return _headers._AccessControlAllowCredentials; } return StringValues.Empty; } set { _bits |= 1073741824L; - _AccessControlAllowCredentials = value; + _headers._AccessControlAllowCredentials = value; } } public StringValues HeaderAccessControlAllowHeaders @@ -6055,14 +5973,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 2147483648L) != 0)) { - return _AccessControlAllowHeaders; + return _headers._AccessControlAllowHeaders; } return StringValues.Empty; } set { _bits |= 2147483648L; - _AccessControlAllowHeaders = value; + _headers._AccessControlAllowHeaders = value; } } public StringValues HeaderAccessControlAllowMethods @@ -6071,14 +5989,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 4294967296L) != 0)) { - return _AccessControlAllowMethods; + return _headers._AccessControlAllowMethods; } return StringValues.Empty; } set { _bits |= 4294967296L; - _AccessControlAllowMethods = value; + _headers._AccessControlAllowMethods = value; } } public StringValues HeaderAccessControlAllowOrigin @@ -6087,14 +6005,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 8589934592L) != 0)) { - return _AccessControlAllowOrigin; + return _headers._AccessControlAllowOrigin; } return StringValues.Empty; } set { _bits |= 8589934592L; - _AccessControlAllowOrigin = value; + _headers._AccessControlAllowOrigin = value; } } public StringValues HeaderAccessControlExposeHeaders @@ -6103,14 +6021,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 17179869184L) != 0)) { - return _AccessControlExposeHeaders; + return _headers._AccessControlExposeHeaders; } return StringValues.Empty; } set { _bits |= 17179869184L; - _AccessControlExposeHeaders = value; + _headers._AccessControlExposeHeaders = value; } } public StringValues HeaderAccessControlMaxAge @@ -6119,46 +6037,46 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 34359738368L) != 0)) { - return _AccessControlMaxAge; + return _headers._AccessControlMaxAge; } return StringValues.Empty; } set { _bits |= 34359738368L; - _AccessControlMaxAge = value; + _headers._AccessControlMaxAge = value; } } public void SetRawConnection(StringValues value, byte[] raw) { _bits |= 2L; - _Connection = value; - _rawConnection = raw; + _headers._Connection = value; + _headers._rawConnection = raw; } public void SetRawDate(StringValues value, byte[] raw) { _bits |= 4L; - _Date = value; - _rawDate = raw; + _headers._Date = value; + _headers._rawDate = raw; } public void SetRawTransferEncoding(StringValues value, byte[] raw) { _bits |= 64L; - _TransferEncoding = value; - _rawTransferEncoding = raw; + _headers._TransferEncoding = value; + _headers._rawTransferEncoding = raw; } public void SetRawContentLength(StringValues value, byte[] raw) { _bits |= 2048L; - _ContentLength = value; - _rawContentLength = raw; + _headers._ContentLength = value; + _headers._rawContentLength = raw; } public void SetRawServer(StringValues value, byte[] raw) { _bits |= 67108864L; - _Server = value; - _rawServer = raw; + _headers._Server = value; + _headers._rawServer = raw; } protected override int GetCountFast() { @@ -6174,7 +6092,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 1L) != 0)) { - return _CacheControl; + return _headers._CacheControl; } else { @@ -6186,7 +6104,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 131072L) != 0)) { - return _ContentRange; + return _headers._ContentRange; } else { @@ -6198,7 +6116,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 524288L) != 0)) { - return _LastModified; + return _headers._LastModified; } else { @@ -6210,7 +6128,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 1048576L) != 0)) { - return _AcceptRanges; + return _headers._AcceptRanges; } else { @@ -6226,7 +6144,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 2L) != 0)) { - return _Connection; + return _headers._Connection; } else { @@ -6238,7 +6156,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 8L) != 0)) { - return _KeepAlive; + return _headers._KeepAlive; } else { @@ -6250,7 +6168,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 134217728L) != 0)) { - return _SetCookie; + return _headers._SetCookie; } else { @@ -6266,7 +6184,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 4L) != 0)) { - return _Date; + return _headers._Date; } else { @@ -6278,7 +6196,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 4194304L) != 0)) { - return _ETag; + return _headers._ETag; } else { @@ -6290,7 +6208,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 268435456L) != 0)) { - return _Vary; + return _headers._Vary; } else { @@ -6306,7 +6224,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 16L) != 0)) { - return _Pragma; + return _headers._Pragma; } else { @@ -6318,7 +6236,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 67108864L) != 0)) { - return _Server; + return _headers._Server; } else { @@ -6334,7 +6252,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 32L) != 0)) { - return _Trailer; + return _headers._Trailer; } else { @@ -6346,7 +6264,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 128L) != 0)) { - return _Upgrade; + return _headers._Upgrade; } else { @@ -6358,7 +6276,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 512L) != 0)) { - return _Warning; + return _headers._Warning; } else { @@ -6370,7 +6288,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 262144L) != 0)) { - return _Expires; + return _headers._Expires; } else { @@ -6386,7 +6304,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 64L) != 0)) { - return _TransferEncoding; + return _headers._TransferEncoding; } else { @@ -6398,7 +6316,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 16777216L) != 0)) { - return _ProxyAutheticate; + return _headers._ProxyAutheticate; } else { @@ -6414,7 +6332,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 256L) != 0)) { - return _Via; + return _headers._Via; } else { @@ -6426,7 +6344,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 2097152L) != 0)) { - return _Age; + return _headers._Age; } else { @@ -6442,7 +6360,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 1024L) != 0)) { - return _Allow; + return _headers._Allow; } else { @@ -6458,7 +6376,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 2048L) != 0)) { - return _ContentLength; + return _headers._ContentLength; } else { @@ -6474,7 +6392,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 4096L) != 0)) { - return _ContentType; + return _headers._ContentType; } else { @@ -6490,7 +6408,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 8192L) != 0)) { - return _ContentEncoding; + return _headers._ContentEncoding; } else { @@ -6502,7 +6420,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 16384L) != 0)) { - return _ContentLanguage; + return _headers._ContentLanguage; } else { @@ -6514,7 +6432,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 32768L) != 0)) { - return _ContentLocation; + return _headers._ContentLocation; } else { @@ -6526,7 +6444,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 536870912L) != 0)) { - return _WWWAuthenticate; + return _headers._WWWAuthenticate; } else { @@ -6542,7 +6460,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 65536L) != 0)) { - return _ContentMD5; + return _headers._ContentMD5; } else { @@ -6554,7 +6472,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 33554432L) != 0)) { - return _RetryAfter; + return _headers._RetryAfter; } else { @@ -6570,7 +6488,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 8388608L) != 0)) { - return _Location; + return _headers._Location; } else { @@ -6586,7 +6504,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 1073741824L) != 0)) { - return _AccessControlAllowCredentials; + return _headers._AccessControlAllowCredentials; } else { @@ -6602,7 +6520,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 2147483648L) != 0)) { - return _AccessControlAllowHeaders; + return _headers._AccessControlAllowHeaders; } else { @@ -6614,7 +6532,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 4294967296L) != 0)) { - return _AccessControlAllowMethods; + return _headers._AccessControlAllowMethods; } else { @@ -6630,7 +6548,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 8589934592L) != 0)) { - return _AccessControlAllowOrigin; + return _headers._AccessControlAllowOrigin; } else { @@ -6646,7 +6564,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 17179869184L) != 0)) { - return _AccessControlExposeHeaders; + return _headers._AccessControlExposeHeaders; } else { @@ -6662,7 +6580,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 34359738368L) != 0)) { - return _AccessControlMaxAge; + return _headers._AccessControlMaxAge; } else { @@ -6688,7 +6606,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 1L) != 0)) { - value = _CacheControl; + value = _headers._CacheControl; return true; } else @@ -6702,7 +6620,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 131072L) != 0)) { - value = _ContentRange; + value = _headers._ContentRange; return true; } else @@ -6716,7 +6634,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 524288L) != 0)) { - value = _LastModified; + value = _headers._LastModified; return true; } else @@ -6730,7 +6648,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 1048576L) != 0)) { - value = _AcceptRanges; + value = _headers._AcceptRanges; return true; } else @@ -6748,7 +6666,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 2L) != 0)) { - value = _Connection; + value = _headers._Connection; return true; } else @@ -6762,7 +6680,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 8L) != 0)) { - value = _KeepAlive; + value = _headers._KeepAlive; return true; } else @@ -6776,7 +6694,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 134217728L) != 0)) { - value = _SetCookie; + value = _headers._SetCookie; return true; } else @@ -6794,7 +6712,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 4L) != 0)) { - value = _Date; + value = _headers._Date; return true; } else @@ -6808,7 +6726,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 4194304L) != 0)) { - value = _ETag; + value = _headers._ETag; return true; } else @@ -6822,7 +6740,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 268435456L) != 0)) { - value = _Vary; + value = _headers._Vary; return true; } else @@ -6840,7 +6758,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 16L) != 0)) { - value = _Pragma; + value = _headers._Pragma; return true; } else @@ -6854,7 +6772,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 67108864L) != 0)) { - value = _Server; + value = _headers._Server; return true; } else @@ -6872,7 +6790,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 32L) != 0)) { - value = _Trailer; + value = _headers._Trailer; return true; } else @@ -6886,7 +6804,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 128L) != 0)) { - value = _Upgrade; + value = _headers._Upgrade; return true; } else @@ -6900,7 +6818,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 512L) != 0)) { - value = _Warning; + value = _headers._Warning; return true; } else @@ -6914,7 +6832,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 262144L) != 0)) { - value = _Expires; + value = _headers._Expires; return true; } else @@ -6932,7 +6850,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 64L) != 0)) { - value = _TransferEncoding; + value = _headers._TransferEncoding; return true; } else @@ -6946,7 +6864,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 16777216L) != 0)) { - value = _ProxyAutheticate; + value = _headers._ProxyAutheticate; return true; } else @@ -6964,7 +6882,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 256L) != 0)) { - value = _Via; + value = _headers._Via; return true; } else @@ -6978,7 +6896,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 2097152L) != 0)) { - value = _Age; + value = _headers._Age; return true; } else @@ -6996,7 +6914,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 1024L) != 0)) { - value = _Allow; + value = _headers._Allow; return true; } else @@ -7014,7 +6932,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 2048L) != 0)) { - value = _ContentLength; + value = _headers._ContentLength; return true; } else @@ -7032,7 +6950,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 4096L) != 0)) { - value = _ContentType; + value = _headers._ContentType; return true; } else @@ -7050,7 +6968,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 8192L) != 0)) { - value = _ContentEncoding; + value = _headers._ContentEncoding; return true; } else @@ -7064,7 +6982,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 16384L) != 0)) { - value = _ContentLanguage; + value = _headers._ContentLanguage; return true; } else @@ -7078,7 +6996,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 32768L) != 0)) { - value = _ContentLocation; + value = _headers._ContentLocation; return true; } else @@ -7092,7 +7010,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 536870912L) != 0)) { - value = _WWWAuthenticate; + value = _headers._WWWAuthenticate; return true; } else @@ -7110,7 +7028,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 65536L) != 0)) { - value = _ContentMD5; + value = _headers._ContentMD5; return true; } else @@ -7124,7 +7042,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 33554432L) != 0)) { - value = _RetryAfter; + value = _headers._RetryAfter; return true; } else @@ -7142,7 +7060,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 8388608L) != 0)) { - value = _Location; + value = _headers._Location; return true; } else @@ -7160,7 +7078,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 1073741824L) != 0)) { - value = _AccessControlAllowCredentials; + value = _headers._AccessControlAllowCredentials; return true; } else @@ -7178,7 +7096,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 2147483648L) != 0)) { - value = _AccessControlAllowHeaders; + value = _headers._AccessControlAllowHeaders; return true; } else @@ -7192,7 +7110,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 4294967296L) != 0)) { - value = _AccessControlAllowMethods; + value = _headers._AccessControlAllowMethods; return true; } else @@ -7210,7 +7128,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 8589934592L) != 0)) { - value = _AccessControlAllowOrigin; + value = _headers._AccessControlAllowOrigin; return true; } else @@ -7228,7 +7146,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 17179869184L) != 0)) { - value = _AccessControlExposeHeaders; + value = _headers._AccessControlExposeHeaders; return true; } else @@ -7246,7 +7164,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (((_bits & 34359738368L) != 0)) { - value = _AccessControlMaxAge; + value = _headers._AccessControlMaxAge; return true; } else @@ -7270,28 +7188,28 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if ("Cache-Control".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 1L; - _CacheControl = value; + _headers._CacheControl = value; return; } if ("Content-Range".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 131072L; - _ContentRange = value; + _headers._ContentRange = value; return; } if ("Last-Modified".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 524288L; - _LastModified = value; + _headers._LastModified = value; return; } if ("Accept-Ranges".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 1048576L; - _AcceptRanges = value; + _headers._AcceptRanges = value; return; } } @@ -7302,22 +7220,22 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if ("Connection".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 2L; - _Connection = value; - _rawConnection = null; + _headers._Connection = value; + _headers._rawConnection = null; return; } if ("Keep-Alive".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 8L; - _KeepAlive = value; + _headers._KeepAlive = value; return; } if ("Set-Cookie".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 134217728L; - _SetCookie = value; + _headers._SetCookie = value; return; } } @@ -7328,22 +7246,22 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if ("Date".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 4L; - _Date = value; - _rawDate = null; + _headers._Date = value; + _headers._rawDate = null; return; } if ("ETag".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 4194304L; - _ETag = value; + _headers._ETag = value; return; } if ("Vary".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 268435456L; - _Vary = value; + _headers._Vary = value; return; } } @@ -7354,15 +7272,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if ("Pragma".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 16L; - _Pragma = value; + _headers._Pragma = value; return; } if ("Server".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 67108864L; - _Server = value; - _rawServer = null; + _headers._Server = value; + _headers._rawServer = null; return; } } @@ -7373,28 +7291,28 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if ("Trailer".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 32L; - _Trailer = value; + _headers._Trailer = value; return; } if ("Upgrade".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 128L; - _Upgrade = value; + _headers._Upgrade = value; return; } if ("Warning".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 512L; - _Warning = value; + _headers._Warning = value; return; } if ("Expires".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 262144L; - _Expires = value; + _headers._Expires = value; return; } } @@ -7405,15 +7323,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if ("Transfer-Encoding".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 64L; - _TransferEncoding = value; - _rawTransferEncoding = null; + _headers._TransferEncoding = value; + _headers._rawTransferEncoding = null; return; } if ("Proxy-Autheticate".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 16777216L; - _ProxyAutheticate = value; + _headers._ProxyAutheticate = value; return; } } @@ -7424,14 +7342,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if ("Via".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 256L; - _Via = value; + _headers._Via = value; return; } if ("Age".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 2097152L; - _Age = value; + _headers._Age = value; return; } } @@ -7442,7 +7360,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if ("Allow".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 1024L; - _Allow = value; + _headers._Allow = value; return; } } @@ -7453,8 +7371,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if ("Content-Length".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 2048L; - _ContentLength = value; - _rawContentLength = null; + _headers._ContentLength = value; + _headers._rawContentLength = null; return; } } @@ -7465,7 +7383,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if ("Content-Type".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 4096L; - _ContentType = value; + _headers._ContentType = value; return; } } @@ -7476,28 +7394,28 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if ("Content-Encoding".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 8192L; - _ContentEncoding = value; + _headers._ContentEncoding = value; return; } if ("Content-Language".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 16384L; - _ContentLanguage = value; + _headers._ContentLanguage = value; return; } if ("Content-Location".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 32768L; - _ContentLocation = value; + _headers._ContentLocation = value; return; } if ("WWW-Authenticate".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 536870912L; - _WWWAuthenticate = value; + _headers._WWWAuthenticate = value; return; } } @@ -7508,14 +7426,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if ("Content-MD5".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 65536L; - _ContentMD5 = value; + _headers._ContentMD5 = value; return; } if ("Retry-After".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 33554432L; - _RetryAfter = value; + _headers._RetryAfter = value; return; } } @@ -7526,7 +7444,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if ("Location".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 8388608L; - _Location = value; + _headers._Location = value; return; } } @@ -7537,7 +7455,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if ("Access-Control-Allow-Credentials".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 1073741824L; - _AccessControlAllowCredentials = value; + _headers._AccessControlAllowCredentials = value; return; } } @@ -7548,14 +7466,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if ("Access-Control-Allow-Headers".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 2147483648L; - _AccessControlAllowHeaders = value; + _headers._AccessControlAllowHeaders = value; return; } if ("Access-Control-Allow-Methods".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 4294967296L; - _AccessControlAllowMethods = value; + _headers._AccessControlAllowMethods = value; return; } } @@ -7566,7 +7484,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if ("Access-Control-Allow-Origin".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 8589934592L; - _AccessControlAllowOrigin = value; + _headers._AccessControlAllowOrigin = value; return; } } @@ -7577,7 +7495,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if ("Access-Control-Expose-Headers".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 17179869184L; - _AccessControlExposeHeaders = value; + _headers._AccessControlExposeHeaders = value; return; } } @@ -7588,7 +7506,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if ("Access-Control-Max-Age".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 34359738368L; - _AccessControlMaxAge = value; + _headers._AccessControlMaxAge = value; return; } } @@ -7609,7 +7527,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowDuplicateKeyException(); } _bits |= 1L; - _CacheControl = value; + _headers._CacheControl = value; return; } @@ -7620,7 +7538,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowDuplicateKeyException(); } _bits |= 131072L; - _ContentRange = value; + _headers._ContentRange = value; return; } @@ -7631,7 +7549,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowDuplicateKeyException(); } _bits |= 524288L; - _LastModified = value; + _headers._LastModified = value; return; } @@ -7642,7 +7560,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowDuplicateKeyException(); } _bits |= 1048576L; - _AcceptRanges = value; + _headers._AcceptRanges = value; return; } } @@ -7657,8 +7575,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowDuplicateKeyException(); } _bits |= 2L; - _Connection = value; - _rawConnection = null; + _headers._Connection = value; + _headers._rawConnection = null; return; } @@ -7669,7 +7587,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowDuplicateKeyException(); } _bits |= 8L; - _KeepAlive = value; + _headers._KeepAlive = value; return; } @@ -7680,7 +7598,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowDuplicateKeyException(); } _bits |= 134217728L; - _SetCookie = value; + _headers._SetCookie = value; return; } } @@ -7695,8 +7613,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowDuplicateKeyException(); } _bits |= 4L; - _Date = value; - _rawDate = null; + _headers._Date = value; + _headers._rawDate = null; return; } @@ -7707,7 +7625,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowDuplicateKeyException(); } _bits |= 4194304L; - _ETag = value; + _headers._ETag = value; return; } @@ -7718,7 +7636,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowDuplicateKeyException(); } _bits |= 268435456L; - _Vary = value; + _headers._Vary = value; return; } } @@ -7733,7 +7651,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowDuplicateKeyException(); } _bits |= 16L; - _Pragma = value; + _headers._Pragma = value; return; } @@ -7744,8 +7662,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowDuplicateKeyException(); } _bits |= 67108864L; - _Server = value; - _rawServer = null; + _headers._Server = value; + _headers._rawServer = null; return; } } @@ -7760,7 +7678,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowDuplicateKeyException(); } _bits |= 32L; - _Trailer = value; + _headers._Trailer = value; return; } @@ -7771,7 +7689,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowDuplicateKeyException(); } _bits |= 128L; - _Upgrade = value; + _headers._Upgrade = value; return; } @@ -7782,7 +7700,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowDuplicateKeyException(); } _bits |= 512L; - _Warning = value; + _headers._Warning = value; return; } @@ -7793,7 +7711,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowDuplicateKeyException(); } _bits |= 262144L; - _Expires = value; + _headers._Expires = value; return; } } @@ -7808,8 +7726,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowDuplicateKeyException(); } _bits |= 64L; - _TransferEncoding = value; - _rawTransferEncoding = null; + _headers._TransferEncoding = value; + _headers._rawTransferEncoding = null; return; } @@ -7820,7 +7738,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowDuplicateKeyException(); } _bits |= 16777216L; - _ProxyAutheticate = value; + _headers._ProxyAutheticate = value; return; } } @@ -7835,7 +7753,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowDuplicateKeyException(); } _bits |= 256L; - _Via = value; + _headers._Via = value; return; } @@ -7846,7 +7764,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowDuplicateKeyException(); } _bits |= 2097152L; - _Age = value; + _headers._Age = value; return; } } @@ -7861,7 +7779,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowDuplicateKeyException(); } _bits |= 1024L; - _Allow = value; + _headers._Allow = value; return; } } @@ -7876,8 +7794,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowDuplicateKeyException(); } _bits |= 2048L; - _ContentLength = value; - _rawContentLength = null; + _headers._ContentLength = value; + _headers._rawContentLength = null; return; } } @@ -7892,7 +7810,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowDuplicateKeyException(); } _bits |= 4096L; - _ContentType = value; + _headers._ContentType = value; return; } } @@ -7907,7 +7825,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowDuplicateKeyException(); } _bits |= 8192L; - _ContentEncoding = value; + _headers._ContentEncoding = value; return; } @@ -7918,7 +7836,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowDuplicateKeyException(); } _bits |= 16384L; - _ContentLanguage = value; + _headers._ContentLanguage = value; return; } @@ -7929,7 +7847,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowDuplicateKeyException(); } _bits |= 32768L; - _ContentLocation = value; + _headers._ContentLocation = value; return; } @@ -7940,7 +7858,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowDuplicateKeyException(); } _bits |= 536870912L; - _WWWAuthenticate = value; + _headers._WWWAuthenticate = value; return; } } @@ -7955,7 +7873,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowDuplicateKeyException(); } _bits |= 65536L; - _ContentMD5 = value; + _headers._ContentMD5 = value; return; } @@ -7966,7 +7884,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowDuplicateKeyException(); } _bits |= 33554432L; - _RetryAfter = value; + _headers._RetryAfter = value; return; } } @@ -7981,7 +7899,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowDuplicateKeyException(); } _bits |= 8388608L; - _Location = value; + _headers._Location = value; return; } } @@ -7996,7 +7914,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowDuplicateKeyException(); } _bits |= 1073741824L; - _AccessControlAllowCredentials = value; + _headers._AccessControlAllowCredentials = value; return; } } @@ -8011,7 +7929,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowDuplicateKeyException(); } _bits |= 2147483648L; - _AccessControlAllowHeaders = value; + _headers._AccessControlAllowHeaders = value; return; } @@ -8022,7 +7940,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowDuplicateKeyException(); } _bits |= 4294967296L; - _AccessControlAllowMethods = value; + _headers._AccessControlAllowMethods = value; return; } } @@ -8037,7 +7955,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowDuplicateKeyException(); } _bits |= 8589934592L; - _AccessControlAllowOrigin = value; + _headers._AccessControlAllowOrigin = value; return; } } @@ -8052,7 +7970,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowDuplicateKeyException(); } _bits |= 17179869184L; - _AccessControlExposeHeaders = value; + _headers._AccessControlExposeHeaders = value; return; } } @@ -8067,7 +7985,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowDuplicateKeyException(); } _bits |= 34359738368L; - _AccessControlMaxAge = value; + _headers._AccessControlMaxAge = value; return; } } @@ -8086,7 +8004,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if (((_bits & 1L) != 0)) { _bits &= ~1L; - _CacheControl = StringValues.Empty; + _headers._CacheControl = StringValues.Empty; return true; } else @@ -8100,7 +8018,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if (((_bits & 131072L) != 0)) { _bits &= ~131072L; - _ContentRange = StringValues.Empty; + _headers._ContentRange = StringValues.Empty; return true; } else @@ -8114,7 +8032,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if (((_bits & 524288L) != 0)) { _bits &= ~524288L; - _LastModified = StringValues.Empty; + _headers._LastModified = StringValues.Empty; return true; } else @@ -8128,7 +8046,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if (((_bits & 1048576L) != 0)) { _bits &= ~1048576L; - _AcceptRanges = StringValues.Empty; + _headers._AcceptRanges = StringValues.Empty; return true; } else @@ -8146,8 +8064,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if (((_bits & 2L) != 0)) { _bits &= ~2L; - _Connection = StringValues.Empty; - _rawConnection = null; + _headers._Connection = StringValues.Empty; + _headers._rawConnection = null; return true; } else @@ -8161,7 +8079,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if (((_bits & 8L) != 0)) { _bits &= ~8L; - _KeepAlive = StringValues.Empty; + _headers._KeepAlive = StringValues.Empty; return true; } else @@ -8175,7 +8093,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if (((_bits & 134217728L) != 0)) { _bits &= ~134217728L; - _SetCookie = StringValues.Empty; + _headers._SetCookie = StringValues.Empty; return true; } else @@ -8193,8 +8111,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if (((_bits & 4L) != 0)) { _bits &= ~4L; - _Date = StringValues.Empty; - _rawDate = null; + _headers._Date = StringValues.Empty; + _headers._rawDate = null; return true; } else @@ -8208,7 +8126,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if (((_bits & 4194304L) != 0)) { _bits &= ~4194304L; - _ETag = StringValues.Empty; + _headers._ETag = StringValues.Empty; return true; } else @@ -8222,7 +8140,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if (((_bits & 268435456L) != 0)) { _bits &= ~268435456L; - _Vary = StringValues.Empty; + _headers._Vary = StringValues.Empty; return true; } else @@ -8240,7 +8158,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if (((_bits & 16L) != 0)) { _bits &= ~16L; - _Pragma = StringValues.Empty; + _headers._Pragma = StringValues.Empty; return true; } else @@ -8254,8 +8172,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if (((_bits & 67108864L) != 0)) { _bits &= ~67108864L; - _Server = StringValues.Empty; - _rawServer = null; + _headers._Server = StringValues.Empty; + _headers._rawServer = null; return true; } else @@ -8273,7 +8191,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if (((_bits & 32L) != 0)) { _bits &= ~32L; - _Trailer = StringValues.Empty; + _headers._Trailer = StringValues.Empty; return true; } else @@ -8287,7 +8205,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if (((_bits & 128L) != 0)) { _bits &= ~128L; - _Upgrade = StringValues.Empty; + _headers._Upgrade = StringValues.Empty; return true; } else @@ -8301,7 +8219,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if (((_bits & 512L) != 0)) { _bits &= ~512L; - _Warning = StringValues.Empty; + _headers._Warning = StringValues.Empty; return true; } else @@ -8315,7 +8233,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if (((_bits & 262144L) != 0)) { _bits &= ~262144L; - _Expires = StringValues.Empty; + _headers._Expires = StringValues.Empty; return true; } else @@ -8333,8 +8251,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if (((_bits & 64L) != 0)) { _bits &= ~64L; - _TransferEncoding = StringValues.Empty; - _rawTransferEncoding = null; + _headers._TransferEncoding = StringValues.Empty; + _headers._rawTransferEncoding = null; return true; } else @@ -8348,7 +8266,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if (((_bits & 16777216L) != 0)) { _bits &= ~16777216L; - _ProxyAutheticate = StringValues.Empty; + _headers._ProxyAutheticate = StringValues.Empty; return true; } else @@ -8366,7 +8284,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if (((_bits & 256L) != 0)) { _bits &= ~256L; - _Via = StringValues.Empty; + _headers._Via = StringValues.Empty; return true; } else @@ -8380,7 +8298,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if (((_bits & 2097152L) != 0)) { _bits &= ~2097152L; - _Age = StringValues.Empty; + _headers._Age = StringValues.Empty; return true; } else @@ -8398,7 +8316,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if (((_bits & 1024L) != 0)) { _bits &= ~1024L; - _Allow = StringValues.Empty; + _headers._Allow = StringValues.Empty; return true; } else @@ -8416,8 +8334,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if (((_bits & 2048L) != 0)) { _bits &= ~2048L; - _ContentLength = StringValues.Empty; - _rawContentLength = null; + _headers._ContentLength = StringValues.Empty; + _headers._rawContentLength = null; return true; } else @@ -8435,7 +8353,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if (((_bits & 4096L) != 0)) { _bits &= ~4096L; - _ContentType = StringValues.Empty; + _headers._ContentType = StringValues.Empty; return true; } else @@ -8453,7 +8371,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if (((_bits & 8192L) != 0)) { _bits &= ~8192L; - _ContentEncoding = StringValues.Empty; + _headers._ContentEncoding = StringValues.Empty; return true; } else @@ -8467,7 +8385,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if (((_bits & 16384L) != 0)) { _bits &= ~16384L; - _ContentLanguage = StringValues.Empty; + _headers._ContentLanguage = StringValues.Empty; return true; } else @@ -8481,7 +8399,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if (((_bits & 32768L) != 0)) { _bits &= ~32768L; - _ContentLocation = StringValues.Empty; + _headers._ContentLocation = StringValues.Empty; return true; } else @@ -8495,7 +8413,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if (((_bits & 536870912L) != 0)) { _bits &= ~536870912L; - _WWWAuthenticate = StringValues.Empty; + _headers._WWWAuthenticate = StringValues.Empty; return true; } else @@ -8513,7 +8431,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if (((_bits & 65536L) != 0)) { _bits &= ~65536L; - _ContentMD5 = StringValues.Empty; + _headers._ContentMD5 = StringValues.Empty; return true; } else @@ -8527,7 +8445,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if (((_bits & 33554432L) != 0)) { _bits &= ~33554432L; - _RetryAfter = StringValues.Empty; + _headers._RetryAfter = StringValues.Empty; return true; } else @@ -8545,7 +8463,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if (((_bits & 8388608L) != 0)) { _bits &= ~8388608L; - _Location = StringValues.Empty; + _headers._Location = StringValues.Empty; return true; } else @@ -8563,7 +8481,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if (((_bits & 1073741824L) != 0)) { _bits &= ~1073741824L; - _AccessControlAllowCredentials = StringValues.Empty; + _headers._AccessControlAllowCredentials = StringValues.Empty; return true; } else @@ -8581,7 +8499,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if (((_bits & 2147483648L) != 0)) { _bits &= ~2147483648L; - _AccessControlAllowHeaders = StringValues.Empty; + _headers._AccessControlAllowHeaders = StringValues.Empty; return true; } else @@ -8595,7 +8513,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if (((_bits & 4294967296L) != 0)) { _bits &= ~4294967296L; - _AccessControlAllowMethods = StringValues.Empty; + _headers._AccessControlAllowMethods = StringValues.Empty; return true; } else @@ -8613,7 +8531,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if (((_bits & 8589934592L) != 0)) { _bits &= ~8589934592L; - _AccessControlAllowOrigin = StringValues.Empty; + _headers._AccessControlAllowOrigin = StringValues.Empty; return true; } else @@ -8631,7 +8549,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if (((_bits & 17179869184L) != 0)) { _bits &= ~17179869184L; - _AccessControlExposeHeaders = StringValues.Empty; + _headers._AccessControlExposeHeaders = StringValues.Empty; return true; } else @@ -8649,7 +8567,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if (((_bits & 34359738368L) != 0)) { _bits &= ~34359738368L; - _AccessControlMaxAge = StringValues.Empty; + _headers._AccessControlMaxAge = StringValues.Empty; return true; } else @@ -8664,8 +8582,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } protected override void ClearFast() { - _bits = 0; + _headers = default(HeaderReferences); MaybeUnknown?.Clear(); } @@ -8683,7 +8601,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowArgumentException(); } - array[arrayIndex] = new KeyValuePair("Cache-Control", _CacheControl); + array[arrayIndex] = new KeyValuePair("Cache-Control", _headers._CacheControl); ++arrayIndex; } @@ -8694,7 +8612,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowArgumentException(); } - array[arrayIndex] = new KeyValuePair("Connection", _Connection); + array[arrayIndex] = new KeyValuePair("Connection", _headers._Connection); ++arrayIndex; } @@ -8705,7 +8623,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowArgumentException(); } - array[arrayIndex] = new KeyValuePair("Date", _Date); + array[arrayIndex] = new KeyValuePair("Date", _headers._Date); ++arrayIndex; } @@ -8716,7 +8634,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowArgumentException(); } - array[arrayIndex] = new KeyValuePair("Keep-Alive", _KeepAlive); + array[arrayIndex] = new KeyValuePair("Keep-Alive", _headers._KeepAlive); ++arrayIndex; } @@ -8727,7 +8645,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowArgumentException(); } - array[arrayIndex] = new KeyValuePair("Pragma", _Pragma); + array[arrayIndex] = new KeyValuePair("Pragma", _headers._Pragma); ++arrayIndex; } @@ -8738,7 +8656,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowArgumentException(); } - array[arrayIndex] = new KeyValuePair("Trailer", _Trailer); + array[arrayIndex] = new KeyValuePair("Trailer", _headers._Trailer); ++arrayIndex; } @@ -8749,7 +8667,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowArgumentException(); } - array[arrayIndex] = new KeyValuePair("Transfer-Encoding", _TransferEncoding); + array[arrayIndex] = new KeyValuePair("Transfer-Encoding", _headers._TransferEncoding); ++arrayIndex; } @@ -8760,7 +8678,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowArgumentException(); } - array[arrayIndex] = new KeyValuePair("Upgrade", _Upgrade); + array[arrayIndex] = new KeyValuePair("Upgrade", _headers._Upgrade); ++arrayIndex; } @@ -8771,7 +8689,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowArgumentException(); } - array[arrayIndex] = new KeyValuePair("Via", _Via); + array[arrayIndex] = new KeyValuePair("Via", _headers._Via); ++arrayIndex; } @@ -8782,7 +8700,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowArgumentException(); } - array[arrayIndex] = new KeyValuePair("Warning", _Warning); + array[arrayIndex] = new KeyValuePair("Warning", _headers._Warning); ++arrayIndex; } @@ -8793,7 +8711,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowArgumentException(); } - array[arrayIndex] = new KeyValuePair("Allow", _Allow); + array[arrayIndex] = new KeyValuePair("Allow", _headers._Allow); ++arrayIndex; } @@ -8804,7 +8722,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowArgumentException(); } - array[arrayIndex] = new KeyValuePair("Content-Length", _ContentLength); + array[arrayIndex] = new KeyValuePair("Content-Length", _headers._ContentLength); ++arrayIndex; } @@ -8815,7 +8733,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowArgumentException(); } - array[arrayIndex] = new KeyValuePair("Content-Type", _ContentType); + array[arrayIndex] = new KeyValuePair("Content-Type", _headers._ContentType); ++arrayIndex; } @@ -8826,7 +8744,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowArgumentException(); } - array[arrayIndex] = new KeyValuePair("Content-Encoding", _ContentEncoding); + array[arrayIndex] = new KeyValuePair("Content-Encoding", _headers._ContentEncoding); ++arrayIndex; } @@ -8837,7 +8755,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowArgumentException(); } - array[arrayIndex] = new KeyValuePair("Content-Language", _ContentLanguage); + array[arrayIndex] = new KeyValuePair("Content-Language", _headers._ContentLanguage); ++arrayIndex; } @@ -8848,7 +8766,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowArgumentException(); } - array[arrayIndex] = new KeyValuePair("Content-Location", _ContentLocation); + array[arrayIndex] = new KeyValuePair("Content-Location", _headers._ContentLocation); ++arrayIndex; } @@ -8859,7 +8777,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowArgumentException(); } - array[arrayIndex] = new KeyValuePair("Content-MD5", _ContentMD5); + array[arrayIndex] = new KeyValuePair("Content-MD5", _headers._ContentMD5); ++arrayIndex; } @@ -8870,7 +8788,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowArgumentException(); } - array[arrayIndex] = new KeyValuePair("Content-Range", _ContentRange); + array[arrayIndex] = new KeyValuePair("Content-Range", _headers._ContentRange); ++arrayIndex; } @@ -8881,7 +8799,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowArgumentException(); } - array[arrayIndex] = new KeyValuePair("Expires", _Expires); + array[arrayIndex] = new KeyValuePair("Expires", _headers._Expires); ++arrayIndex; } @@ -8892,7 +8810,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowArgumentException(); } - array[arrayIndex] = new KeyValuePair("Last-Modified", _LastModified); + array[arrayIndex] = new KeyValuePair("Last-Modified", _headers._LastModified); ++arrayIndex; } @@ -8903,7 +8821,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowArgumentException(); } - array[arrayIndex] = new KeyValuePair("Accept-Ranges", _AcceptRanges); + array[arrayIndex] = new KeyValuePair("Accept-Ranges", _headers._AcceptRanges); ++arrayIndex; } @@ -8914,7 +8832,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowArgumentException(); } - array[arrayIndex] = new KeyValuePair("Age", _Age); + array[arrayIndex] = new KeyValuePair("Age", _headers._Age); ++arrayIndex; } @@ -8925,7 +8843,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowArgumentException(); } - array[arrayIndex] = new KeyValuePair("ETag", _ETag); + array[arrayIndex] = new KeyValuePair("ETag", _headers._ETag); ++arrayIndex; } @@ -8936,7 +8854,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowArgumentException(); } - array[arrayIndex] = new KeyValuePair("Location", _Location); + array[arrayIndex] = new KeyValuePair("Location", _headers._Location); ++arrayIndex; } @@ -8947,7 +8865,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowArgumentException(); } - array[arrayIndex] = new KeyValuePair("Proxy-Autheticate", _ProxyAutheticate); + array[arrayIndex] = new KeyValuePair("Proxy-Autheticate", _headers._ProxyAutheticate); ++arrayIndex; } @@ -8958,7 +8876,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowArgumentException(); } - array[arrayIndex] = new KeyValuePair("Retry-After", _RetryAfter); + array[arrayIndex] = new KeyValuePair("Retry-After", _headers._RetryAfter); ++arrayIndex; } @@ -8969,7 +8887,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowArgumentException(); } - array[arrayIndex] = new KeyValuePair("Server", _Server); + array[arrayIndex] = new KeyValuePair("Server", _headers._Server); ++arrayIndex; } @@ -8980,7 +8898,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowArgumentException(); } - array[arrayIndex] = new KeyValuePair("Set-Cookie", _SetCookie); + array[arrayIndex] = new KeyValuePair("Set-Cookie", _headers._SetCookie); ++arrayIndex; } @@ -8991,7 +8909,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowArgumentException(); } - array[arrayIndex] = new KeyValuePair("Vary", _Vary); + array[arrayIndex] = new KeyValuePair("Vary", _headers._Vary); ++arrayIndex; } @@ -9002,7 +8920,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowArgumentException(); } - array[arrayIndex] = new KeyValuePair("WWW-Authenticate", _WWWAuthenticate); + array[arrayIndex] = new KeyValuePair("WWW-Authenticate", _headers._WWWAuthenticate); ++arrayIndex; } @@ -9013,7 +8931,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowArgumentException(); } - array[arrayIndex] = new KeyValuePair("Access-Control-Allow-Credentials", _AccessControlAllowCredentials); + array[arrayIndex] = new KeyValuePair("Access-Control-Allow-Credentials", _headers._AccessControlAllowCredentials); ++arrayIndex; } @@ -9024,7 +8942,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowArgumentException(); } - array[arrayIndex] = new KeyValuePair("Access-Control-Allow-Headers", _AccessControlAllowHeaders); + array[arrayIndex] = new KeyValuePair("Access-Control-Allow-Headers", _headers._AccessControlAllowHeaders); ++arrayIndex; } @@ -9035,7 +8953,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowArgumentException(); } - array[arrayIndex] = new KeyValuePair("Access-Control-Allow-Methods", _AccessControlAllowMethods); + array[arrayIndex] = new KeyValuePair("Access-Control-Allow-Methods", _headers._AccessControlAllowMethods); ++arrayIndex; } @@ -9046,7 +8964,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowArgumentException(); } - array[arrayIndex] = new KeyValuePair("Access-Control-Allow-Origin", _AccessControlAllowOrigin); + array[arrayIndex] = new KeyValuePair("Access-Control-Allow-Origin", _headers._AccessControlAllowOrigin); ++arrayIndex; } @@ -9057,7 +8975,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowArgumentException(); } - array[arrayIndex] = new KeyValuePair("Access-Control-Expose-Headers", _AccessControlExposeHeaders); + array[arrayIndex] = new KeyValuePair("Access-Control-Expose-Headers", _headers._AccessControlExposeHeaders); ++arrayIndex; } @@ -9068,7 +8986,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowArgumentException(); } - array[arrayIndex] = new KeyValuePair("Access-Control-Max-Age", _AccessControlMaxAge); + array[arrayIndex] = new KeyValuePair("Access-Control-Max-Age", _headers._AccessControlMaxAge); ++arrayIndex; } @@ -9080,7 +8998,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if (((_bits & 1L) != 0)) { - foreach (var value in _CacheControl) + foreach (var value in _headers._CacheControl) { if (value != null) { @@ -9092,12 +9010,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if (((_bits & 2L) != 0)) { - if (_rawConnection != null) + if (_headers._rawConnection != null) { - output.CopyFrom(_rawConnection, 0, _rawConnection.Length); + output.CopyFrom(_headers._rawConnection, 0, _headers._rawConnection.Length); } else - foreach (var value in _Connection) + foreach (var value in _headers._Connection) { if (value != null) { @@ -9109,12 +9027,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if (((_bits & 4L) != 0)) { - if (_rawDate != null) + if (_headers._rawDate != null) { - output.CopyFrom(_rawDate, 0, _rawDate.Length); + output.CopyFrom(_headers._rawDate, 0, _headers._rawDate.Length); } else - foreach (var value in _Date) + foreach (var value in _headers._Date) { if (value != null) { @@ -9126,7 +9044,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if (((_bits & 8L) != 0)) { - foreach (var value in _KeepAlive) + foreach (var value in _headers._KeepAlive) { if (value != null) { @@ -9138,7 +9056,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if (((_bits & 16L) != 0)) { - foreach (var value in _Pragma) + foreach (var value in _headers._Pragma) { if (value != null) { @@ -9150,7 +9068,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if (((_bits & 32L) != 0)) { - foreach (var value in _Trailer) + foreach (var value in _headers._Trailer) { if (value != null) { @@ -9162,12 +9080,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if (((_bits & 64L) != 0)) { - if (_rawTransferEncoding != null) + if (_headers._rawTransferEncoding != null) { - output.CopyFrom(_rawTransferEncoding, 0, _rawTransferEncoding.Length); + output.CopyFrom(_headers._rawTransferEncoding, 0, _headers._rawTransferEncoding.Length); } else - foreach (var value in _TransferEncoding) + foreach (var value in _headers._TransferEncoding) { if (value != null) { @@ -9179,7 +9097,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if (((_bits & 128L) != 0)) { - foreach (var value in _Upgrade) + foreach (var value in _headers._Upgrade) { if (value != null) { @@ -9191,7 +9109,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if (((_bits & 256L) != 0)) { - foreach (var value in _Via) + foreach (var value in _headers._Via) { if (value != null) { @@ -9203,7 +9121,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if (((_bits & 512L) != 0)) { - foreach (var value in _Warning) + foreach (var value in _headers._Warning) { if (value != null) { @@ -9215,7 +9133,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if (((_bits & 1024L) != 0)) { - foreach (var value in _Allow) + foreach (var value in _headers._Allow) { if (value != null) { @@ -9227,12 +9145,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if (((_bits & 2048L) != 0)) { - if (_rawContentLength != null) + if (_headers._rawContentLength != null) { - output.CopyFrom(_rawContentLength, 0, _rawContentLength.Length); + output.CopyFrom(_headers._rawContentLength, 0, _headers._rawContentLength.Length); } else - foreach (var value in _ContentLength) + foreach (var value in _headers._ContentLength) { if (value != null) { @@ -9244,7 +9162,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if (((_bits & 4096L) != 0)) { - foreach (var value in _ContentType) + foreach (var value in _headers._ContentType) { if (value != null) { @@ -9256,7 +9174,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if (((_bits & 8192L) != 0)) { - foreach (var value in _ContentEncoding) + foreach (var value in _headers._ContentEncoding) { if (value != null) { @@ -9268,7 +9186,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if (((_bits & 16384L) != 0)) { - foreach (var value in _ContentLanguage) + foreach (var value in _headers._ContentLanguage) { if (value != null) { @@ -9280,7 +9198,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if (((_bits & 32768L) != 0)) { - foreach (var value in _ContentLocation) + foreach (var value in _headers._ContentLocation) { if (value != null) { @@ -9292,7 +9210,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if (((_bits & 65536L) != 0)) { - foreach (var value in _ContentMD5) + foreach (var value in _headers._ContentMD5) { if (value != null) { @@ -9304,7 +9222,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if (((_bits & 131072L) != 0)) { - foreach (var value in _ContentRange) + foreach (var value in _headers._ContentRange) { if (value != null) { @@ -9316,7 +9234,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if (((_bits & 262144L) != 0)) { - foreach (var value in _Expires) + foreach (var value in _headers._Expires) { if (value != null) { @@ -9328,7 +9246,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if (((_bits & 524288L) != 0)) { - foreach (var value in _LastModified) + foreach (var value in _headers._LastModified) { if (value != null) { @@ -9340,7 +9258,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if (((_bits & 1048576L) != 0)) { - foreach (var value in _AcceptRanges) + foreach (var value in _headers._AcceptRanges) { if (value != null) { @@ -9352,7 +9270,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if (((_bits & 2097152L) != 0)) { - foreach (var value in _Age) + foreach (var value in _headers._Age) { if (value != null) { @@ -9364,7 +9282,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if (((_bits & 4194304L) != 0)) { - foreach (var value in _ETag) + foreach (var value in _headers._ETag) { if (value != null) { @@ -9376,7 +9294,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if (((_bits & 8388608L) != 0)) { - foreach (var value in _Location) + foreach (var value in _headers._Location) { if (value != null) { @@ -9388,7 +9306,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if (((_bits & 16777216L) != 0)) { - foreach (var value in _ProxyAutheticate) + foreach (var value in _headers._ProxyAutheticate) { if (value != null) { @@ -9400,7 +9318,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if (((_bits & 33554432L) != 0)) { - foreach (var value in _RetryAfter) + foreach (var value in _headers._RetryAfter) { if (value != null) { @@ -9412,12 +9330,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if (((_bits & 67108864L) != 0)) { - if (_rawServer != null) + if (_headers._rawServer != null) { - output.CopyFrom(_rawServer, 0, _rawServer.Length); + output.CopyFrom(_headers._rawServer, 0, _headers._rawServer.Length); } else - foreach (var value in _Server) + foreach (var value in _headers._Server) { if (value != null) { @@ -9429,7 +9347,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if (((_bits & 134217728L) != 0)) { - foreach (var value in _SetCookie) + foreach (var value in _headers._SetCookie) { if (value != null) { @@ -9441,7 +9359,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if (((_bits & 268435456L) != 0)) { - foreach (var value in _Vary) + foreach (var value in _headers._Vary) { if (value != null) { @@ -9453,7 +9371,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if (((_bits & 536870912L) != 0)) { - foreach (var value in _WWWAuthenticate) + foreach (var value in _headers._WWWAuthenticate) { if (value != null) { @@ -9465,7 +9383,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if (((_bits & 1073741824L) != 0)) { - foreach (var value in _AccessControlAllowCredentials) + foreach (var value in _headers._AccessControlAllowCredentials) { if (value != null) { @@ -9477,7 +9395,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if (((_bits & 2147483648L) != 0)) { - foreach (var value in _AccessControlAllowHeaders) + foreach (var value in _headers._AccessControlAllowHeaders) { if (value != null) { @@ -9489,7 +9407,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if (((_bits & 4294967296L) != 0)) { - foreach (var value in _AccessControlAllowMethods) + foreach (var value in _headers._AccessControlAllowMethods) { if (value != null) { @@ -9501,7 +9419,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if (((_bits & 8589934592L) != 0)) { - foreach (var value in _AccessControlAllowOrigin) + foreach (var value in _headers._AccessControlAllowOrigin) { if (value != null) { @@ -9513,7 +9431,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if (((_bits & 17179869184L) != 0)) { - foreach (var value in _AccessControlExposeHeaders) + foreach (var value in _headers._AccessControlExposeHeaders) { if (value != null) { @@ -9525,7 +9443,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if (((_bits & 34359738368L) != 0)) { - foreach (var value in _AccessControlMaxAge) + foreach (var value in _headers._AccessControlMaxAge) { if (value != null) { @@ -9537,6 +9455,52 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } + private struct HeaderReferences + { + public StringValues _CacheControl; + public StringValues _Connection; + public StringValues _Date; + public StringValues _KeepAlive; + public StringValues _Pragma; + public StringValues _Trailer; + public StringValues _TransferEncoding; + public StringValues _Upgrade; + public StringValues _Via; + public StringValues _Warning; + public StringValues _Allow; + public StringValues _ContentLength; + public StringValues _ContentType; + public StringValues _ContentEncoding; + public StringValues _ContentLanguage; + public StringValues _ContentLocation; + public StringValues _ContentMD5; + public StringValues _ContentRange; + public StringValues _Expires; + public StringValues _LastModified; + public StringValues _AcceptRanges; + public StringValues _Age; + public StringValues _ETag; + public StringValues _Location; + public StringValues _ProxyAutheticate; + public StringValues _RetryAfter; + public StringValues _Server; + public StringValues _SetCookie; + public StringValues _Vary; + public StringValues _WWWAuthenticate; + public StringValues _AccessControlAllowCredentials; + public StringValues _AccessControlAllowHeaders; + public StringValues _AccessControlAllowMethods; + public StringValues _AccessControlAllowOrigin; + public StringValues _AccessControlExposeHeaders; + public StringValues _AccessControlMaxAge; + + public byte[] _rawConnection; + public byte[] _rawDate; + public byte[] _rawTransferEncoding; + public byte[] _rawContentLength; + public byte[] _rawServer; + } + public partial struct Enumerator { public bool MoveNext() @@ -9659,7 +9623,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http state0: if (((_bits & 1L) != 0)) { - _current = new KeyValuePair("Cache-Control", _collection._CacheControl); + _current = new KeyValuePair("Cache-Control", _collection._headers._CacheControl); _state = 1; return true; } @@ -9667,7 +9631,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http state1: if (((_bits & 2L) != 0)) { - _current = new KeyValuePair("Connection", _collection._Connection); + _current = new KeyValuePair("Connection", _collection._headers._Connection); _state = 2; return true; } @@ -9675,7 +9639,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http state2: if (((_bits & 4L) != 0)) { - _current = new KeyValuePair("Date", _collection._Date); + _current = new KeyValuePair("Date", _collection._headers._Date); _state = 3; return true; } @@ -9683,7 +9647,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http state3: if (((_bits & 8L) != 0)) { - _current = new KeyValuePair("Keep-Alive", _collection._KeepAlive); + _current = new KeyValuePair("Keep-Alive", _collection._headers._KeepAlive); _state = 4; return true; } @@ -9691,7 +9655,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http state4: if (((_bits & 16L) != 0)) { - _current = new KeyValuePair("Pragma", _collection._Pragma); + _current = new KeyValuePair("Pragma", _collection._headers._Pragma); _state = 5; return true; } @@ -9699,7 +9663,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http state5: if (((_bits & 32L) != 0)) { - _current = new KeyValuePair("Trailer", _collection._Trailer); + _current = new KeyValuePair("Trailer", _collection._headers._Trailer); _state = 6; return true; } @@ -9707,7 +9671,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http state6: if (((_bits & 64L) != 0)) { - _current = new KeyValuePair("Transfer-Encoding", _collection._TransferEncoding); + _current = new KeyValuePair("Transfer-Encoding", _collection._headers._TransferEncoding); _state = 7; return true; } @@ -9715,7 +9679,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http state7: if (((_bits & 128L) != 0)) { - _current = new KeyValuePair("Upgrade", _collection._Upgrade); + _current = new KeyValuePair("Upgrade", _collection._headers._Upgrade); _state = 8; return true; } @@ -9723,7 +9687,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http state8: if (((_bits & 256L) != 0)) { - _current = new KeyValuePair("Via", _collection._Via); + _current = new KeyValuePair("Via", _collection._headers._Via); _state = 9; return true; } @@ -9731,7 +9695,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http state9: if (((_bits & 512L) != 0)) { - _current = new KeyValuePair("Warning", _collection._Warning); + _current = new KeyValuePair("Warning", _collection._headers._Warning); _state = 10; return true; } @@ -9739,7 +9703,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http state10: if (((_bits & 1024L) != 0)) { - _current = new KeyValuePair("Allow", _collection._Allow); + _current = new KeyValuePair("Allow", _collection._headers._Allow); _state = 11; return true; } @@ -9747,7 +9711,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http state11: if (((_bits & 2048L) != 0)) { - _current = new KeyValuePair("Content-Length", _collection._ContentLength); + _current = new KeyValuePair("Content-Length", _collection._headers._ContentLength); _state = 12; return true; } @@ -9755,7 +9719,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http state12: if (((_bits & 4096L) != 0)) { - _current = new KeyValuePair("Content-Type", _collection._ContentType); + _current = new KeyValuePair("Content-Type", _collection._headers._ContentType); _state = 13; return true; } @@ -9763,7 +9727,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http state13: if (((_bits & 8192L) != 0)) { - _current = new KeyValuePair("Content-Encoding", _collection._ContentEncoding); + _current = new KeyValuePair("Content-Encoding", _collection._headers._ContentEncoding); _state = 14; return true; } @@ -9771,7 +9735,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http state14: if (((_bits & 16384L) != 0)) { - _current = new KeyValuePair("Content-Language", _collection._ContentLanguage); + _current = new KeyValuePair("Content-Language", _collection._headers._ContentLanguage); _state = 15; return true; } @@ -9779,7 +9743,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http state15: if (((_bits & 32768L) != 0)) { - _current = new KeyValuePair("Content-Location", _collection._ContentLocation); + _current = new KeyValuePair("Content-Location", _collection._headers._ContentLocation); _state = 16; return true; } @@ -9787,7 +9751,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http state16: if (((_bits & 65536L) != 0)) { - _current = new KeyValuePair("Content-MD5", _collection._ContentMD5); + _current = new KeyValuePair("Content-MD5", _collection._headers._ContentMD5); _state = 17; return true; } @@ -9795,7 +9759,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http state17: if (((_bits & 131072L) != 0)) { - _current = new KeyValuePair("Content-Range", _collection._ContentRange); + _current = new KeyValuePair("Content-Range", _collection._headers._ContentRange); _state = 18; return true; } @@ -9803,7 +9767,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http state18: if (((_bits & 262144L) != 0)) { - _current = new KeyValuePair("Expires", _collection._Expires); + _current = new KeyValuePair("Expires", _collection._headers._Expires); _state = 19; return true; } @@ -9811,7 +9775,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http state19: if (((_bits & 524288L) != 0)) { - _current = new KeyValuePair("Last-Modified", _collection._LastModified); + _current = new KeyValuePair("Last-Modified", _collection._headers._LastModified); _state = 20; return true; } @@ -9819,7 +9783,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http state20: if (((_bits & 1048576L) != 0)) { - _current = new KeyValuePair("Accept-Ranges", _collection._AcceptRanges); + _current = new KeyValuePair("Accept-Ranges", _collection._headers._AcceptRanges); _state = 21; return true; } @@ -9827,7 +9791,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http state21: if (((_bits & 2097152L) != 0)) { - _current = new KeyValuePair("Age", _collection._Age); + _current = new KeyValuePair("Age", _collection._headers._Age); _state = 22; return true; } @@ -9835,7 +9799,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http state22: if (((_bits & 4194304L) != 0)) { - _current = new KeyValuePair("ETag", _collection._ETag); + _current = new KeyValuePair("ETag", _collection._headers._ETag); _state = 23; return true; } @@ -9843,7 +9807,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http state23: if (((_bits & 8388608L) != 0)) { - _current = new KeyValuePair("Location", _collection._Location); + _current = new KeyValuePair("Location", _collection._headers._Location); _state = 24; return true; } @@ -9851,7 +9815,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http state24: if (((_bits & 16777216L) != 0)) { - _current = new KeyValuePair("Proxy-Autheticate", _collection._ProxyAutheticate); + _current = new KeyValuePair("Proxy-Autheticate", _collection._headers._ProxyAutheticate); _state = 25; return true; } @@ -9859,7 +9823,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http state25: if (((_bits & 33554432L) != 0)) { - _current = new KeyValuePair("Retry-After", _collection._RetryAfter); + _current = new KeyValuePair("Retry-After", _collection._headers._RetryAfter); _state = 26; return true; } @@ -9867,7 +9831,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http state26: if (((_bits & 67108864L) != 0)) { - _current = new KeyValuePair("Server", _collection._Server); + _current = new KeyValuePair("Server", _collection._headers._Server); _state = 27; return true; } @@ -9875,7 +9839,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http state27: if (((_bits & 134217728L) != 0)) { - _current = new KeyValuePair("Set-Cookie", _collection._SetCookie); + _current = new KeyValuePair("Set-Cookie", _collection._headers._SetCookie); _state = 28; return true; } @@ -9883,7 +9847,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http state28: if (((_bits & 268435456L) != 0)) { - _current = new KeyValuePair("Vary", _collection._Vary); + _current = new KeyValuePair("Vary", _collection._headers._Vary); _state = 29; return true; } @@ -9891,7 +9855,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http state29: if (((_bits & 536870912L) != 0)) { - _current = new KeyValuePair("WWW-Authenticate", _collection._WWWAuthenticate); + _current = new KeyValuePair("WWW-Authenticate", _collection._headers._WWWAuthenticate); _state = 30; return true; } @@ -9899,7 +9863,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http state30: if (((_bits & 1073741824L) != 0)) { - _current = new KeyValuePair("Access-Control-Allow-Credentials", _collection._AccessControlAllowCredentials); + _current = new KeyValuePair("Access-Control-Allow-Credentials", _collection._headers._AccessControlAllowCredentials); _state = 31; return true; } @@ -9907,7 +9871,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http state31: if (((_bits & 2147483648L) != 0)) { - _current = new KeyValuePair("Access-Control-Allow-Headers", _collection._AccessControlAllowHeaders); + _current = new KeyValuePair("Access-Control-Allow-Headers", _collection._headers._AccessControlAllowHeaders); _state = 32; return true; } @@ -9915,7 +9879,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http state32: if (((_bits & 4294967296L) != 0)) { - _current = new KeyValuePair("Access-Control-Allow-Methods", _collection._AccessControlAllowMethods); + _current = new KeyValuePair("Access-Control-Allow-Methods", _collection._headers._AccessControlAllowMethods); _state = 33; return true; } @@ -9923,7 +9887,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http state33: if (((_bits & 8589934592L) != 0)) { - _current = new KeyValuePair("Access-Control-Allow-Origin", _collection._AccessControlAllowOrigin); + _current = new KeyValuePair("Access-Control-Allow-Origin", _collection._headers._AccessControlAllowOrigin); _state = 34; return true; } @@ -9931,7 +9895,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http state34: if (((_bits & 17179869184L) != 0)) { - _current = new KeyValuePair("Access-Control-Expose-Headers", _collection._AccessControlExposeHeaders); + _current = new KeyValuePair("Access-Control-Expose-Headers", _collection._headers._AccessControlExposeHeaders); _state = 35; return true; } @@ -9939,7 +9903,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http state35: if (((_bits & 34359738368L) != 0)) { - _current = new KeyValuePair("Access-Control-Max-Age", _collection._AccessControlMaxAge); + _current = new KeyValuePair("Access-Control-Max-Age", _collection._headers._AccessControlMaxAge); _state = 36; return true; } diff --git a/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/KnownHeaders.cs b/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/KnownHeaders.cs index 76e7610b82..1593da3ac4 100644 --- a/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/KnownHeaders.cs +++ b/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/KnownHeaders.cs @@ -216,10 +216,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http : "")} private long _bits = 0; - {Each(loop.Headers, header => @" - private StringValues _" + header.Identifier + ";")} - {Each(loop.Headers.Where(header => header.EnhancedSetter), header => @" - private byte[] _raw" + header.Identifier + ";")} + private HeaderReferences _headers; {Each(loop.Headers, header => $@" public StringValues Header{header.Identifier} {{ @@ -227,23 +224,23 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http {{ if ({header.TestBit()}) {{ - return _{header.Identifier}; + return _headers._{header.Identifier}; }} return StringValues.Empty; }} set {{ {header.SetBit()}; - _{header.Identifier} = value; {(header.EnhancedSetter == false ? "" : $@" - _raw{header.Identifier} = null;")} + _headers._{header.Identifier} = value; {(header.EnhancedSetter == false ? "" : $@" + _headers._raw{header.Identifier} = null;")} }} }}")} {Each(loop.Headers.Where(header => header.EnhancedSetter), header => $@" public void SetRaw{header.Identifier}(StringValues value, byte[] raw) {{ {header.SetBit()}; - _{header.Identifier} = value; - _raw{header.Identifier} = raw; + _headers._{header.Identifier} = value; + _headers._raw{header.Identifier} = raw; }}")} protected override int GetCountFast() {{ @@ -259,7 +256,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http {{ if ({header.TestBit()}) {{ - return _{header.Identifier}; + return _headers._{header.Identifier}; }} else {{ @@ -285,7 +282,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http {{ if ({header.TestBit()}) {{ - value = _{header.Identifier}; + value = _headers._{header.Identifier}; return true; }} else @@ -309,8 +306,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if (""{header.Name}"".Equals(key, StringComparison.OrdinalIgnoreCase)) {{ {header.SetBit()}; - _{header.Identifier} = value;{(header.EnhancedSetter == false ? "" : $@" - _raw{header.Identifier} = null;")} + _headers._{header.Identifier} = value;{(header.EnhancedSetter == false ? "" : $@" + _headers._raw{header.Identifier} = null;")} return; }} ")}}} @@ -331,8 +328,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowDuplicateKeyException(); }} {header.SetBit()}; - _{header.Identifier} = value;{(header.EnhancedSetter == false ? "" : $@" - _raw{header.Identifier} = null;")} + _headers._{header.Identifier} = value;{(header.EnhancedSetter == false ? "" : $@" + _headers._raw{header.Identifier} = null;")} return; }} ")}}} @@ -351,8 +348,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if ({header.TestBit()}) {{ {header.ClearBit()}; - _{header.Identifier} = StringValues.Empty;{(header.EnhancedSetter == false ? "" : $@" - _raw{header.Identifier} = null;")} + _headers._{header.Identifier} = StringValues.Empty;{(header.EnhancedSetter == false ? "" : $@" + _headers._raw{header.Identifier} = null;")} return true; }} else @@ -366,10 +363,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http return MaybeUnknown?.Remove(key) ?? false; }} protected override void ClearFast() - {{{(loop.ClassName != "FrameRequestHeaders" ? "" : Each(loop.Headers, header => $@" - if ({header.TestBit()}) _{header.Identifier} = default(StringValues);"))} - + {{ _bits = 0; + _headers = default(HeaderReferences); MaybeUnknown?.Clear(); }} @@ -387,7 +383,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowArgumentException(); }} - array[arrayIndex] = new KeyValuePair(""{header.Name}"", _{header.Identifier}); + array[arrayIndex] = new KeyValuePair(""{header.Name}"", _headers._{header.Identifier}); ++arrayIndex; }} ")} @@ -399,12 +395,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http {Each(loop.Headers, header => $@" if ({header.TestBit()}) {{ {(header.EnhancedSetter == false ? "" : $@" - if (_raw{header.Identifier} != null) + if (_headers._raw{header.Identifier} != null) {{ - output.CopyFrom(_raw{header.Identifier}, 0, _raw{header.Identifier}.Length); + output.CopyFrom(_headers._raw{header.Identifier}, 0, _headers._raw{header.Identifier}.Length); }} else ")} - foreach (var value in _{header.Identifier}) + foreach (var value in _headers._{header.Identifier}) {{ if (value != null) {{ @@ -432,13 +428,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http {{ if ({header.TestBit()}) {{ - _{header.Identifier} = AppendValue(_{header.Identifier}, value); + _headers._{header.Identifier} = AppendValue(_headers._{header.Identifier}, value); }} else {{ {header.SetBit()}; - _{header.Identifier} = new StringValues(value);{(header.EnhancedSetter == false ? "" : $@" - _raw{header.Identifier} = null;")} + _headers._{header.Identifier} = new StringValues(value);{(header.EnhancedSetter == false ? "" : $@" + _headers._raw{header.Identifier} = null;")} }} return; }} @@ -451,6 +447,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http Unknown.TryGetValue(key, out existing); Unknown[key] = AppendValue(existing, value); }}" : "")} + private struct HeaderReferences + {{{Each(loop.Headers, header => @" + public StringValues _" + header.Identifier + ";")} + {Each(loop.Headers.Where(header => header.EnhancedSetter), header => @" + public byte[] _raw" + header.Identifier + ";")} + }} + public partial struct Enumerator {{ public bool MoveNext() @@ -468,7 +471,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http state{header.Index}: if ({header.TestBit()}) {{ - _current = new KeyValuePair(""{header.Name}"", _collection._{header.Identifier}); + _current = new KeyValuePair(""{header.Name}"", _collection._headers._{header.Identifier}); _state = {header.Index + 1}; return true; }} From 020e0b9dc54fa0c2034ec92dbc756a2d7ecb3c0d Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Sun, 22 Nov 2015 12:00:15 +0000 Subject: [PATCH 0603/1662] Enable TCP Loopback Fast Path (Windows) Enable TCP Loopback Fast Path; where the IP layer is skipped, for lower latency for localhost comms, like HttpPlatformHandler+IIS reverse proxy http://blogs.technet.com/b/wincat/archive/2012/12/05/fast-tcp-loopback-performance-and-low-latency-with-windows-server-2012-tcp-loopback-fast-path.aspx Have to do it this way due to open issue in libuv Loopback fast path: libuv/libuv#489 Related: "Confirm HttpPlatformHandler uses Fast TCP Loopback" aspnet/IISIntegration#29 --- .../Networking/Libuv.cs | 67 +++++++++++++++++++ .../EngineTests.cs | 33 +++++++++ .../MultipleLoopTests.cs | 16 +++++ .../NetworkingTests.cs | 48 +++++++++++++ .../TestConnection.cs | 17 +++++ 5 files changed, 181 insertions(+) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Networking/Libuv.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Networking/Libuv.cs index 279d4885cf..a7022d8fc4 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Networking/Libuv.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Networking/Libuv.cs @@ -27,6 +27,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Networking _uv_stop = NativeDarwinMonoMethods.uv_stop; _uv_ref = NativeDarwinMonoMethods.uv_ref; _uv_unref = NativeDarwinMonoMethods.uv_unref; + _uv_fileno = NativeDarwinMonoMethods.uv_fileno; _uv_close = NativeDarwinMonoMethods.uv_close; _uv_async_init = NativeDarwinMonoMethods.uv_async_init; _uv_async_send = NativeDarwinMonoMethods.uv_async_send; @@ -68,6 +69,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Networking _uv_stop = NativeMethods.uv_stop; _uv_ref = NativeMethods.uv_ref; _uv_unref = NativeMethods.uv_unref; + _uv_fileno = NativeMethods.uv_fileno; _uv_close = NativeMethods.uv_close; _uv_async_init = NativeMethods.uv_async_init; _uv_async_send = NativeMethods.uv_async_send; @@ -177,6 +179,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Networking _uv_unref(handle); } + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + protected delegate int uv_fileno_func(UvHandle handle, ref IntPtr socket); + protected uv_fileno_func _uv_fileno; + public int uv_fileno(UvHandle handle, ref IntPtr socket) + { + handle.Validate(); + return Check(_uv_fileno(handle, ref socket)); + } + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] public delegate void uv_close_cb(IntPtr handle); protected Action _uv_close; @@ -221,6 +232,40 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Networking { handle.Validate(); Check(_uv_tcp_bind(handle, ref addr, flags)); + if (PlatformApis.IsWindows) + { + tcp_bind_windows_extras(handle); + } + } + + private unsafe void tcp_bind_windows_extras(UvTcpHandle handle) + { + const int SIO_LOOPBACK_FAST_PATH = -1744830448; // IOC_IN | IOC_WS2 | 16; + const int WSAEOPNOTSUPP = 10000 + 45; // (WSABASEERR+45) + const int SOCKET_ERROR = -1; + + var socket = IntPtr.Zero; + Check(_uv_fileno(handle, ref socket)); + + // Enable loopback fast-path for lower latency for localhost comms, like HttpPlatformHandler fronting + // http://blogs.technet.com/b/wincat/archive/2012/12/05/fast-tcp-loopback-performance-and-low-latency-with-windows-server-2012-tcp-loopback-fast-path.aspx + // https://github.com/libuv/libuv/issues/489 + var optionValue = 1; + uint dwBytes = 0u; + + var result = NativeMethods.WSAIoctl(socket, SIO_LOOPBACK_FAST_PATH, &optionValue, sizeof(int), null, 0, out dwBytes, IntPtr.Zero, IntPtr.Zero); + if (result == SOCKET_ERROR) + { + var errorId = NativeMethods.WSAGetLastError(); + if (errorId == WSAEOPNOTSUPP) + { + // This system is not >= Windows Server 2012, and the call is not supported. + } + else + { + Check(errorId); + } + } } protected Func _uv_tcp_open; @@ -501,6 +546,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Networking [DllImport("libuv", CallingConvention = CallingConvention.Cdecl)] public static extern void uv_unref(UvHandle handle); + [DllImport("libuv", CallingConvention = CallingConvention.Cdecl)] + public static extern int uv_fileno(UvHandle handle, ref IntPtr socket); + [DllImport("libuv", CallingConvention = CallingConvention.Cdecl)] public static extern void uv_close(IntPtr handle, uv_close_cb close_cb); @@ -587,6 +635,22 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Networking [DllImport("libuv", CallingConvention = CallingConvention.Cdecl)] unsafe public static extern int uv_walk(UvLoopHandle loop, uv_walk_cb walk_cb, IntPtr arg); + + [DllImport("WS2_32.dll", CallingConvention = CallingConvention.Winapi)] + unsafe public static extern int WSAIoctl( + IntPtr socket, + int dwIoControlCode, + int* lpvInBuffer, + uint cbInBuffer, + int* lpvOutBuffer, + int cbOutBuffer, + out uint lpcbBytesReturned, + IntPtr lpOverlapped, + IntPtr lpCompletionRoutine + ); + + [DllImport("WS2_32.dll", CallingConvention = CallingConvention.Winapi)] + public static extern int WSAGetLastError(); } private static class NativeDarwinMonoMethods @@ -609,6 +673,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Networking [DllImport("__Internal", CallingConvention = CallingConvention.Cdecl)] public static extern void uv_unref(UvHandle handle); + [DllImport("__Internal", CallingConvention = CallingConvention.Cdecl)] + public static extern int uv_fileno(UvHandle handle, ref IntPtr socket); + [DllImport("__Internal", CallingConvention = CallingConvention.Cdecl)] public static extern void uv_close(IntPtr handle, uv_close_cb close_cb); diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs index 42315796d5..d75ec82902 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs @@ -14,6 +14,7 @@ using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Server.Kestrel; using Microsoft.AspNetCore.Server.Kestrel.Filter; using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Networking; using Microsoft.AspNetCore.Testing.xunit; using Microsoft.Extensions.Logging; using Xunit; @@ -118,6 +119,22 @@ namespace Microsoft.AspNetCore.Server.KestrelTests Console.WriteLine("Started"); var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); + if (PlatformApis.IsWindows) + { + const int SIO_LOOPBACK_FAST_PATH = (-1744830448); + var optionInValue = BitConverter.GetBytes(1); + try + { + socket.IOControl(SIO_LOOPBACK_FAST_PATH, optionInValue, null); + } + catch + { + // If the operating system version on this machine did + // not support SIO_LOOPBACK_FAST_PATH (i.e. version + // prior to Windows 8 / Windows Server 2012), handle the exception + } + } + socket.NoDelay = true; socket.Connect(new IPEndPoint(IPAddress.Loopback, port)); socket.Send(Encoding.ASCII.GetBytes("POST / HTTP/1.0\r\n\r\nHello World")); socket.Shutdown(SocketShutdown.Send); @@ -475,6 +492,22 @@ namespace Microsoft.AspNetCore.Server.KestrelTests using (var server = new TestServer(App, testContext)) { var socket = new Socket(SocketType.Stream, ProtocolType.Tcp); + if (PlatformApis.IsWindows) + { + const int SIO_LOOPBACK_FAST_PATH = (-1744830448); + var optionInValue = BitConverter.GetBytes(1); + try + { + socket.IOControl(SIO_LOOPBACK_FAST_PATH, optionInValue, null); + } + catch + { + // If the operating system version on this machine did + // not support SIO_LOOPBACK_FAST_PATH (i.e. version + // prior to Windows 8 / Windows Server 2012), handle the exception + } + } + socket.NoDelay = true; socket.Connect(IPAddress.Loopback, server.Port); await Task.Delay(200); socket.Dispose(); diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/MultipleLoopTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/MultipleLoopTests.cs index 6c4d2e8ed0..16ebbd3421 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/MultipleLoopTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/MultipleLoopTests.cs @@ -235,6 +235,22 @@ namespace Microsoft.AspNetCore.Server.KestrelTests serverConnectionPipeAcceptedEvent.WaitOne(); var socket = new Socket(SocketType.Stream, ProtocolType.IP); + if (PlatformApis.IsWindows) + { + const int SIO_LOOPBACK_FAST_PATH = (-1744830448); + var optionInValue = BitConverter.GetBytes(1); + try + { + socket.IOControl(SIO_LOOPBACK_FAST_PATH, optionInValue, null); + } + catch + { + // If the operating system version on this machine did + // not support SIO_LOOPBACK_FAST_PATH (i.e. version + // prior to Windows 8 / Windows Server 2012), handle the exception + } + } + socket.NoDelay = true; socket.Connect(IPAddress.Loopback, 54321); socket.Send(new byte[] { 6, 7, 8, 9 }); socket.Shutdown(SocketShutdown.Send); diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/NetworkingTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/NetworkingTests.cs index 642d4c7729..c8824c70c7 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/NetworkingTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/NetworkingTests.cs @@ -93,6 +93,22 @@ namespace Microsoft.AspNetCore.Server.KestrelTests AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); + if (PlatformApis.IsWindows) + { + const int SIO_LOOPBACK_FAST_PATH = (-1744830448); + var optionInValue = BitConverter.GetBytes(1); + try + { + socket.IOControl(SIO_LOOPBACK_FAST_PATH, optionInValue, null); + } + catch + { + // If the operating system version on this machine did + // not support SIO_LOOPBACK_FAST_PATH (i.e. version + // prior to Windows 8 / Windows Server 2012), handle the exception + } + } + socket.NoDelay = true; #if DNX451 await Task.Factory.FromAsync( socket.BeginConnect, @@ -147,6 +163,22 @@ namespace Microsoft.AspNetCore.Server.KestrelTests AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); + if (PlatformApis.IsWindows) + { + const int SIO_LOOPBACK_FAST_PATH = (-1744830448); + var optionInValue = BitConverter.GetBytes(1); + try + { + socket.IOControl(SIO_LOOPBACK_FAST_PATH, optionInValue, null); + } + catch + { + // If the operating system version on this machine did + // not support SIO_LOOPBACK_FAST_PATH (i.e. version + // prior to Windows 8 / Windows Server 2012), handle the exception + } + } + socket.NoDelay = true; #if DNX451 await Task.Factory.FromAsync( socket.BeginConnect, @@ -234,6 +266,22 @@ namespace Microsoft.AspNetCore.Server.KestrelTests AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); + if (PlatformApis.IsWindows) + { + const int SIO_LOOPBACK_FAST_PATH = (-1744830448); + var optionInValue = BitConverter.GetBytes(1); + try + { + socket.IOControl(SIO_LOOPBACK_FAST_PATH, optionInValue, null); + } + catch + { + // If the operating system version on this machine did + // not support SIO_LOOPBACK_FAST_PATH (i.e. version + // prior to Windows 8 / Windows Server 2012), handle the exception + } + } + socket.NoDelay = true; #if DNX451 await Task.Factory.FromAsync( socket.BeginConnect, diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestConnection.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/TestConnection.cs index 5b6e857fd0..8e2ac64f69 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/TestConnection.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/TestConnection.cs @@ -8,6 +8,7 @@ using System.Net; using System.Net.Sockets; using System.Text; using System.Threading.Tasks; +using Microsoft.AspNetCore.Server.Kestrel.Networking; using Xunit; namespace Microsoft.AspNetCore.Server.KestrelTests @@ -29,6 +30,22 @@ namespace Microsoft.AspNetCore.Server.KestrelTests public void Create(int port) { _socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); + if (PlatformApis.IsWindows) + { + const int SIO_LOOPBACK_FAST_PATH = (-1744830448); + var optionInValue = BitConverter.GetBytes(1); + try + { + _socket.IOControl(SIO_LOOPBACK_FAST_PATH, optionInValue, null); + } + catch + { + // If the operating system version on this machine did + // not support SIO_LOOPBACK_FAST_PATH (i.e. version + // prior to Windows 8 / Windows Server 2012), handle the exception + } + } + _socket.NoDelay = true; _socket.Connect(new IPEndPoint(IPAddress.Loopback, port)); _stream = new NetworkStream(_socket, false); From ffa8f3f09249af3aaa2045331aa0492281a0a4db Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Sun, 14 Feb 2016 08:11:17 +0000 Subject: [PATCH 0604/1662] Helper function for test socket creation --- .../RequestTests.cs | 3 +- .../TestConnection.cs | 35 ++++++++ .../EngineTests.cs | 38 +------- .../MultipleLoopTests.cs | 22 +---- .../NetworkingTests.cs | 89 +------------------ .../TestConnection.cs | 41 +++++---- 6 files changed, 68 insertions(+), 160 deletions(-) create mode 100644 test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/TestConnection.cs diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs index 3f9b0870dd..3f9cf20a75 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs @@ -158,9 +158,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { host.Start(); - using (var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)) + using (var socket = TestConnection.CreateConnectedLoopbackSocket(port)) { - socket.Connect(new IPEndPoint(IPAddress.Loopback, port)); socket.Send(Encoding.ASCII.GetBytes("GET /%41%CC%8A/A/../B/%41%CC%8A HTTP/1.1\r\n\r\n")); socket.Shutdown(SocketShutdown.Send); diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/TestConnection.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/TestConnection.cs new file mode 100644 index 0000000000..db602658f0 --- /dev/null +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/TestConnection.cs @@ -0,0 +1,35 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Net; +using System.Net.Sockets; +using Microsoft.AspNetCore.Server.Kestrel.Networking; + +namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests +{ + public class TestConnection + { + public static Socket CreateConnectedLoopbackSocket(int port) + { + var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); + if (PlatformApis.IsWindows) + { + const int SIO_LOOPBACK_FAST_PATH = -1744830448; + var optionInValue = BitConverter.GetBytes(1); + try + { + socket.IOControl(SIO_LOOPBACK_FAST_PATH, optionInValue, null); + } + catch + { + // If the operating system version on this machine did + // not support SIO_LOOPBACK_FAST_PATH (i.e. version + // prior to Windows 8 / Windows Server 2012), handle the exception + } + } + socket.Connect(new IPEndPoint(IPAddress.Loopback, port)); + return socket; + } + } +} diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs index d75ec82902..ea1cfe638c 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs @@ -118,24 +118,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var started = engine.CreateServer(address); Console.WriteLine("Started"); - var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); - if (PlatformApis.IsWindows) - { - const int SIO_LOOPBACK_FAST_PATH = (-1744830448); - var optionInValue = BitConverter.GetBytes(1); - try - { - socket.IOControl(SIO_LOOPBACK_FAST_PATH, optionInValue, null); - } - catch - { - // If the operating system version on this machine did - // not support SIO_LOOPBACK_FAST_PATH (i.e. version - // prior to Windows 8 / Windows Server 2012), handle the exception - } - } - socket.NoDelay = true; - socket.Connect(new IPEndPoint(IPAddress.Loopback, port)); + var socket = TestConnection.CreateConnectedLoopbackSocket(port); socket.Send(Encoding.ASCII.GetBytes("POST / HTTP/1.0\r\n\r\nHello World")); socket.Shutdown(SocketShutdown.Send); var buffer = new byte[8192]; @@ -491,24 +474,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { using (var server = new TestServer(App, testContext)) { - var socket = new Socket(SocketType.Stream, ProtocolType.Tcp); - if (PlatformApis.IsWindows) - { - const int SIO_LOOPBACK_FAST_PATH = (-1744830448); - var optionInValue = BitConverter.GetBytes(1); - try - { - socket.IOControl(SIO_LOOPBACK_FAST_PATH, optionInValue, null); - } - catch - { - // If the operating system version on this machine did - // not support SIO_LOOPBACK_FAST_PATH (i.e. version - // prior to Windows 8 / Windows Server 2012), handle the exception - } - } - socket.NoDelay = true; - socket.Connect(IPAddress.Loopback, server.Port); + var socket = TestConnection.CreateConnectedLoopbackSocket(server.Port); await Task.Delay(200); socket.Dispose(); diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/MultipleLoopTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/MultipleLoopTests.cs index 16ebbd3421..fedc72e6b0 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/MultipleLoopTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/MultipleLoopTests.cs @@ -124,6 +124,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { var pipeName = @"\\.\pipe\ServerPipeDispatchConnections" + Guid.NewGuid().ToString("n"); + var port = TestServer.GetNextPort(); var loop = new UvLoopHandle(_logger); loop.Init(_uv); @@ -153,7 +154,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var serverListenTcp = new UvTcpHandle(_logger); serverListenTcp.Init(loop); - var address = ServerAddress.FromUrl("http://localhost:54321/"); + var address = ServerAddress.FromUrl($"http://localhost:{port}/"); serverListenTcp.Bind(address); serverListenTcp.Listen(128, (_1, status, error, _2) => { @@ -234,24 +235,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { serverConnectionPipeAcceptedEvent.WaitOne(); - var socket = new Socket(SocketType.Stream, ProtocolType.IP); - if (PlatformApis.IsWindows) - { - const int SIO_LOOPBACK_FAST_PATH = (-1744830448); - var optionInValue = BitConverter.GetBytes(1); - try - { - socket.IOControl(SIO_LOOPBACK_FAST_PATH, optionInValue, null); - } - catch - { - // If the operating system version on this machine did - // not support SIO_LOOPBACK_FAST_PATH (i.e. version - // prior to Windows 8 / Windows Server 2012), handle the exception - } - } - socket.NoDelay = true; - socket.Connect(IPAddress.Loopback, 54321); + var socket = TestConnection.CreateConnectedLoopbackSocket(port); socket.Send(new byte[] { 6, 7, 8, 9 }); socket.Shutdown(SocketShutdown.Send); var cb = socket.Receive(new byte[64]); diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/NetworkingTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/NetworkingTests.cs index c8824c70c7..35faf85266 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/NetworkingTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/NetworkingTests.cs @@ -87,38 +87,9 @@ namespace Microsoft.AspNetCore.Server.KestrelTests tcp2.Dispose(); stream.Dispose(); }, null); - var t = Task.Run(async () => + var t = Task.Run(() => { - var socket = new Socket( - AddressFamily.InterNetwork, - SocketType.Stream, - ProtocolType.Tcp); - if (PlatformApis.IsWindows) - { - const int SIO_LOOPBACK_FAST_PATH = (-1744830448); - var optionInValue = BitConverter.GetBytes(1); - try - { - socket.IOControl(SIO_LOOPBACK_FAST_PATH, optionInValue, null); - } - catch - { - // If the operating system version on this machine did - // not support SIO_LOOPBACK_FAST_PATH (i.e. version - // prior to Windows 8 / Windows Server 2012), handle the exception - } - } - socket.NoDelay = true; -#if DNX451 - await Task.Factory.FromAsync( - socket.BeginConnect, - socket.EndConnect, - new IPEndPoint(IPAddress.Loopback, port), - null, - TaskCreationOptions.None); -#else - await socket.ConnectAsync(new IPEndPoint(IPAddress.Loopback, port)); -#endif + var socket = TestConnection.CreateConnectedLoopbackSocket(port); socket.Dispose(); }); loop.Run(); @@ -159,33 +130,8 @@ namespace Microsoft.AspNetCore.Server.KestrelTests Console.WriteLine("Task.Run"); var t = Task.Run(async () => { - var socket = new Socket( - AddressFamily.InterNetwork, - SocketType.Stream, - ProtocolType.Tcp); - if (PlatformApis.IsWindows) - { - const int SIO_LOOPBACK_FAST_PATH = (-1744830448); - var optionInValue = BitConverter.GetBytes(1); - try - { - socket.IOControl(SIO_LOOPBACK_FAST_PATH, optionInValue, null); - } - catch - { - // If the operating system version on this machine did - // not support SIO_LOOPBACK_FAST_PATH (i.e. version - // prior to Windows 8 / Windows Server 2012), handle the exception - } - } - socket.NoDelay = true; + var socket = TestConnection.CreateConnectedLoopbackSocket(port); #if DNX451 - await Task.Factory.FromAsync( - socket.BeginConnect, - socket.EndConnect, - new IPEndPoint(IPAddress.Loopback, port), - null, - TaskCreationOptions.None); await Task.Factory.FromAsync( socket.BeginSend, socket.EndSend, @@ -194,7 +140,6 @@ namespace Microsoft.AspNetCore.Server.KestrelTests null, TaskCreationOptions.None); #else - await socket.ConnectAsync(new IPEndPoint(IPAddress.Loopback, port)); await socket.SendAsync(new[] { new ArraySegment(new byte[] { 1, 2, 3, 4, 5 }) }, SocketFlags.None); #endif @@ -262,33 +207,8 @@ namespace Microsoft.AspNetCore.Server.KestrelTests Console.WriteLine("Task.Run"); var t = Task.Run(async () => { - var socket = new Socket( - AddressFamily.InterNetwork, - SocketType.Stream, - ProtocolType.Tcp); - if (PlatformApis.IsWindows) - { - const int SIO_LOOPBACK_FAST_PATH = (-1744830448); - var optionInValue = BitConverter.GetBytes(1); - try - { - socket.IOControl(SIO_LOOPBACK_FAST_PATH, optionInValue, null); - } - catch - { - // If the operating system version on this machine did - // not support SIO_LOOPBACK_FAST_PATH (i.e. version - // prior to Windows 8 / Windows Server 2012), handle the exception - } - } - socket.NoDelay = true; + var socket = TestConnection.CreateConnectedLoopbackSocket(port); #if DNX451 - await Task.Factory.FromAsync( - socket.BeginConnect, - socket.EndConnect, - new IPEndPoint(IPAddress.Loopback, port), - null, - TaskCreationOptions.None); await Task.Factory.FromAsync( socket.BeginSend, socket.EndSend, @@ -297,7 +217,6 @@ namespace Microsoft.AspNetCore.Server.KestrelTests null, TaskCreationOptions.None); #else - await socket.ConnectAsync(new IPEndPoint(IPAddress.Loopback, port)); await socket.SendAsync(new[] { new ArraySegment(new byte[] { 1, 2, 3, 4, 5 }) }, SocketFlags.None); #endif diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestConnection.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/TestConnection.cs index 8e2ac64f69..f7f3e36b4e 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/TestConnection.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/TestConnection.cs @@ -29,24 +29,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests public void Create(int port) { - _socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); - if (PlatformApis.IsWindows) - { - const int SIO_LOOPBACK_FAST_PATH = (-1744830448); - var optionInValue = BitConverter.GetBytes(1); - try - { - _socket.IOControl(SIO_LOOPBACK_FAST_PATH, optionInValue, null); - } - catch - { - // If the operating system version on this machine did - // not support SIO_LOOPBACK_FAST_PATH (i.e. version - // prior to Windows 8 / Windows Server 2012), handle the exception - } - } - _socket.NoDelay = true; - _socket.Connect(new IPEndPoint(IPAddress.Loopback, port)); + _socket = CreateConnectedLoopbackSocket(port); _stream = new NetworkStream(_socket, false); _reader = new StreamReader(_stream, Encoding.ASCII); @@ -142,5 +125,27 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var text = new string(ch, 0, count); Assert.Equal("", text); } + + public static Socket CreateConnectedLoopbackSocket(int port) + { + var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); + if (PlatformApis.IsWindows) + { + const int SIO_LOOPBACK_FAST_PATH = -1744830448; + var optionInValue = BitConverter.GetBytes(1); + try + { + socket.IOControl(SIO_LOOPBACK_FAST_PATH, optionInValue, null); + } + catch + { + // If the operating system version on this machine did + // not support SIO_LOOPBACK_FAST_PATH (i.e. version + // prior to Windows 8 / Windows Server 2012), handle the exception + } + } + socket.Connect(new IPEndPoint(IPAddress.Loopback, port)); + return socket; + } } } From 9c31907bacb188352f87bcd17980355b7a515165 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Tue, 26 Jan 2016 17:35:35 -0800 Subject: [PATCH 0605/1662] Don't rely on the finalizer to return blocks referenced by SocketInput --- .../Filter/FilteredStreamAdapter.cs | 2 ++ .../Http/Connection.cs | 12 +++++++++++ .../Http/Frame.cs | 1 - .../Http/FrameOfT.cs | 20 ++++++++++++------- .../Http/SocketInput.cs | 20 ++++++++++++++++++- .../Http/SocketOutput.cs | 7 ++++--- 6 files changed, 50 insertions(+), 12 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Filter/FilteredStreamAdapter.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Filter/FilteredStreamAdapter.cs index 7174f10171..519d4440af 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Filter/FilteredStreamAdapter.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Filter/FilteredStreamAdapter.cs @@ -48,10 +48,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Filter { if (copyAsyncTask.IsFaulted) { + SocketInput.AbortAwaiting(); _log.LogError(0, copyAsyncTask.Exception, "FilteredStreamAdapter.CopyToAsync"); } else if (copyAsyncTask.IsCanceled) { + SocketInput.AbortAwaiting(); _log.LogError("FilteredStreamAdapter.CopyToAsync canceled."); } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Connection.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Connection.cs index 3d335971e5..76282b9239 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Connection.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Connection.cs @@ -123,6 +123,18 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } + public void OnSocketClosed() + { + _rawSocketInput.Dispose(); + + // If a connection filter was applied there will be two SocketInputs. + // If a connection filter failed, SocketInput will be null. + if (SocketInput != null && SocketInput != _rawSocketInput) + { + SocketInput.Dispose(); + } + } + private void ApplyConnectionFilter() { if (_filterContext.Connection != _libuvStream) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs index e00f0579d2..6b99b9898f 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs @@ -334,7 +334,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http try { ConnectionControl.End(ProduceEndType.SocketDisconnect); - SocketInput.AbortAwaiting(); } catch (Exception ex) { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameOfT.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameOfT.cs index affb4d5867..68fd28bfeb 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameOfT.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameOfT.cs @@ -145,14 +145,20 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http // If _requestAborted is set, the connection has already been closed. if (Volatile.Read(ref _requestAborted) == 0) { - // Inform client no more data will ever arrive - ConnectionControl.End(ProduceEndType.SocketShutdownSend); + try + { + // Inform client no more data will ever arrive + ConnectionControl.End(ProduceEndType.SocketShutdownSend); - // Wait for client to either disconnect or send unexpected data - await SocketInput; - - // Dispose socket - ConnectionControl.End(ProduceEndType.SocketDisconnect); + // Wait for client to either disconnect or send unexpected data + await SocketInput; + } + finally + { + // Ensure we *always* disconnect the socket. + // Dispose socket + ConnectionControl.End(ProduceEndType.SocketDisconnect); + } } } catch (Exception ex) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketInput.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketInput.cs index 4191f6736d..2a3ac3d698 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketInput.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketInput.cs @@ -10,7 +10,7 @@ using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; namespace Microsoft.AspNetCore.Server.Kestrel.Http { - public class SocketInput : ICriticalNotifyCompletion + public class SocketInput : ICriticalNotifyCompletion, IDisposable { private static readonly Action _awaitableIsCompleted = () => { }; private static readonly Action _awaitableIsNotCompleted = () => { }; @@ -246,5 +246,23 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http throw new IOException(error.Message, error); } } + + public void Dispose() + { + AbortAwaiting(); + + // Return all blocks + var block = _head; + while (block != null) + { + var returnBlock = block; + block = block.Next; + + returnBlock.Pool.Return(returnBlock); + } + + _head = null; + _tail = null; + } } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketOutput.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketOutput.cs index bb39a268ae..406d0b756a 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketOutput.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketOutput.cs @@ -614,17 +614,18 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (SocketDisconnect == false || Self._socket.IsClosed) { - CompleteOnUvThread(); + CompleteWithContextLock(); return; } Self._socket.Dispose(); + Self._connection.OnSocketClosed(); Self.ReturnAllBlocks(); Self._log.ConnectionStop(Self._connectionId); - CompleteOnUvThread(); + CompleteWithContextLock(); } - public void CompleteOnUvThread() + public void CompleteWithContextLock() { if (Monitor.TryEnter(Self._contextLock)) { From 54caf3071c3fada69e12d601d266f95cd60c514a Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Tue, 9 Feb 2016 12:30:19 -0800 Subject: [PATCH 0606/1662] Close connections as quickly and gracefully as possible on shutdown - Make the time given for requests to complete gracefully configurable. - Complete all async reads so calling code can re-check whether to stop request processing and exit if in between requests. - Don't wait for a FIN from the client since some browsers (e.g. IE & Chrome) will take a long time to send one. - Ensure all ConnectionFilters complete before the memory pool is disposed. - Ensure blocks get returned even when a ConnectionFilter produces a failed read --- .../Filter/FilteredStreamAdapter.cs | 25 +-- .../Filter/StreamExtensions.cs | 4 +- .../Http/Connection.cs | 161 +++++++++++++----- .../Http/FrameOfT.cs | 15 +- .../Http/IAsyncDisposable.cs | 12 ++ .../Http/Listener.cs | 46 +++-- .../Http/ListenerContext.cs | 5 +- .../Http/ListenerPrimary.cs | 25 ++- .../Http/ListenerSecondary.cs | 22 ++- .../Http/ProduceEndType.cs | 2 +- .../Http/SocketInput.cs | 5 + .../Http/SocketOutput.cs | 18 +- .../IKestrelServerInformation.cs | 10 ++ .../Infrastructure/ConnectionManager.cs | 59 +++++++ .../Infrastructure/IKestrelTrace.cs | 2 + .../Infrastructure/KestrelThread.cs | 56 ++---- .../Infrastructure/KestrelTrace.cs | 9 +- .../KestrelEngine.cs | 30 ++-- .../KestrelServer.cs | 2 +- .../KestrelServerInformation.cs | 16 ++ .../TestServiceContext.cs | 5 +- 21 files changed, 364 insertions(+), 165 deletions(-) create mode 100644 src/Microsoft.AspNetCore.Server.Kestrel/Http/IAsyncDisposable.cs create mode 100644 src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/ConnectionManager.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Filter/FilteredStreamAdapter.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Filter/FilteredStreamAdapter.cs index 519d4440af..1e99ef698b 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Filter/FilteredStreamAdapter.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Filter/FilteredStreamAdapter.cs @@ -15,6 +15,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Filter private readonly Stream _filteredStream; private readonly Stream _socketInputStream; private readonly IKestrelTrace _log; + private readonly MemoryPool2 _memory; + private MemoryPoolBlock2 _block; public FilteredStreamAdapter( Stream filteredStream, @@ -28,24 +30,27 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Filter _log = logger; _filteredStream = filteredStream; _socketInputStream = new SocketInputStream(SocketInput); - - var block = memory.Lease(); - // Use pooled block for copy - _filteredStream.CopyToAsync(_socketInputStream, block).ContinueWith((task, state) => - { - var returnedBlock = task.Result; - returnedBlock.Pool.Return(returnedBlock); - - ((FilteredStreamAdapter)state).OnStreamClose(task); - }, this); + _memory = memory; } public SocketInput SocketInput { get; private set; } public ISocketOutput SocketOutput { get; private set; } + public Task ReadInputAsync() + { + _block = _memory.Lease(); + // Use pooled block for copy + return _filteredStream.CopyToAsync(_socketInputStream, _block).ContinueWith((task, state) => + { + ((FilteredStreamAdapter)state).OnStreamClose(task); + }, this); + } + private void OnStreamClose(Task copyAsyncTask) { + _memory.Return(_block); + if (copyAsyncTask.IsFaulted) { SocketInput.AbortAwaiting(); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Filter/StreamExtensions.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Filter/StreamExtensions.cs index 72c3fb9fd9..ccf0a47384 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Filter/StreamExtensions.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Filter/StreamExtensions.cs @@ -9,15 +9,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Filter { public static class StreamExtensions { - public static async Task CopyToAsync(this Stream source, Stream destination, MemoryPoolBlock2 block) + public static async Task CopyToAsync(this Stream source, Stream destination, MemoryPoolBlock2 block) { int bytesRead; while ((bytesRead = await source.ReadAsync(block.Array, block.Data.Offset, block.Data.Count)) != 0) { await destination.WriteAsync(block.Array, block.Data.Offset, bytesRead); } - - return block; } } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Connection.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Connection.cs index 76282b9239..6f4d79670e 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Connection.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Connection.cs @@ -4,6 +4,7 @@ using System; using System.Net; using System.Threading; +using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Filter; using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Networking; @@ -31,6 +32,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http private readonly object _stateLock = new object(); private ConnectionState _connectionState; + private TaskCompletionSource _socketClosedTcs; + private Task _readFilteredInputTask = TaskUtilities.CompletedTask; private IPEndPoint _remoteEndPoint; private IPEndPoint _localEndPoint; @@ -44,6 +47,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http _rawSocketInput = new SocketInput(Memory2, ThreadPool); _rawSocketOutput = new SocketOutput(Thread, _socket, Memory2, this, _connectionId, Log, ThreadPool, WriteReqPool); + + ConnectionManager.AddConnection(_connectionId, this); + } + + // Internal for testing + internal Connection() + { } public void Start() @@ -63,11 +73,21 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http // Don't initialize _frame until SocketInput and SocketOutput are set to their final values. if (ServerInformation.ConnectionFilter == null) { - SocketInput = _rawSocketInput; - SocketOutput = _rawSocketOutput; + lock (_stateLock) + { + if (_connectionState != ConnectionState.CreatingFrame) + { + throw new InvalidOperationException("Invalid connection state: " + _connectionState); + } - _frame = CreateFrame(); - _frame.Start(); + _connectionState = ConnectionState.Open; + + SocketInput = _rawSocketInput; + SocketOutput = _rawSocketOutput; + + _frame = CreateFrame(); + _frame.Start(); + } } else { @@ -109,21 +129,51 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } - public virtual void Abort() + public Task StopAsync() { - if (_frame != null) + lock (_stateLock) { - // Frame.Abort calls user code while this method is always - // called from a libuv thread. - System.Threading.ThreadPool.QueueUserWorkItem(state => + switch (_connectionState) { - var connection = (Connection)state; - connection._frame.Abort(); - }, this); + case ConnectionState.SocketClosed: + return _readFilteredInputTask; + case ConnectionState.CreatingFrame: + _connectionState = ConnectionState.ToDisconnect; + break; + case ConnectionState.Open: + _frame.Stop(); + SocketInput.CompleteAwaiting(); + break; + } + + _socketClosedTcs = new TaskCompletionSource(); + return Task.WhenAll(_socketClosedTcs.Task, _readFilteredInputTask); } } - public void OnSocketClosed() + public virtual void Abort() + { + lock (_stateLock) + { + if (_connectionState == ConnectionState.CreatingFrame) + { + _connectionState = ConnectionState.ToDisconnect; + } + else + { + // Frame.Abort calls user code while this method is always + // called from a libuv thread. + System.Threading.ThreadPool.QueueUserWorkItem(state => + { + var connection = (Connection)state; + connection._frame.Abort(); + }, this); + } + } + } + + // Called on Libuv thread + public virtual void OnSocketClosed() { _rawSocketInput.Dispose(); @@ -133,25 +183,64 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { SocketInput.Dispose(); } + + lock (_stateLock) + { + _connectionState = ConnectionState.SocketClosed; + + if (_socketClosedTcs != null) + { + // This is always waited on synchronously, so it's safe to + // call on the libuv thread. + _socketClosedTcs.TrySetResult(null); + } + + if (_readFilteredInputTask.IsCompleted) + { + ConnectionManager.ConnectionStopped(_connectionId); + } + else + { + _readFilteredInputTask.ContinueWith((t, state) => + { + var connection = (Connection)state; + connection.ConnectionManager.ConnectionStopped(connection._connectionId); + }, this); + } + } } private void ApplyConnectionFilter() { - if (_filterContext.Connection != _libuvStream) + lock (_stateLock) { - var filteredStreamAdapter = new FilteredStreamAdapter(_filterContext.Connection, Memory2, Log, ThreadPool); + if (_connectionState == ConnectionState.CreatingFrame) + { + _connectionState = ConnectionState.Open; - SocketInput = filteredStreamAdapter.SocketInput; - SocketOutput = filteredStreamAdapter.SocketOutput; - } - else - { - SocketInput = _rawSocketInput; - SocketOutput = _rawSocketOutput; - } + if (_filterContext.Connection != _libuvStream) + { + var filteredStreamAdapter = new FilteredStreamAdapter(_filterContext.Connection, Memory2, Log, ThreadPool); - _frame = CreateFrame(); - _frame.Start(); + SocketInput = filteredStreamAdapter.SocketInput; + SocketOutput = filteredStreamAdapter.SocketOutput; + + _readFilteredInputTask = filteredStreamAdapter.ReadInputAsync(); + } + else + { + SocketInput = _rawSocketInput; + SocketOutput = _rawSocketOutput; + } + + _frame = CreateFrame(); + _frame.Start(); + } + else + { + ConnectionControl.End(ProduceEndType.SocketDisconnect); + } + } } private static Libuv.uv_buf_t AllocCallback(UvStreamHandle handle, int suggestedSize, object state) @@ -227,16 +316,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { switch (endType) { - case ProduceEndType.SocketShutdownSend: - if (_connectionState != ConnectionState.Open) - { - return; - } - _connectionState = ConnectionState.Shutdown; - - Log.ConnectionWriteFin(_connectionId); - _rawSocketOutput.End(endType); - break; case ProduceEndType.ConnectionKeepAlive: if (_connectionState != ConnectionState.Open) { @@ -245,12 +324,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http Log.ConnectionKeepAlive(_connectionId); break; + case ProduceEndType.SocketShutdown: case ProduceEndType.SocketDisconnect: - if (_connectionState == ConnectionState.Disconnected) + if (_connectionState == ConnectionState.Disconnecting || + _connectionState == ConnectionState.SocketClosed) { return; } - _connectionState = ConnectionState.Disconnected; + _connectionState = ConnectionState.Disconnecting; Log.ConnectionDisconnect(_connectionId); _rawSocketOutput.End(endType); @@ -261,9 +342,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http private enum ConnectionState { + CreatingFrame, + ToDisconnect, Open, - Shutdown, - Disconnected + Disconnecting, + SocketClosed } } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameOfT.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameOfT.cs index 68fd28bfeb..1c54363146 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameOfT.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameOfT.cs @@ -145,20 +145,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http // If _requestAborted is set, the connection has already been closed. if (Volatile.Read(ref _requestAborted) == 0) { - try - { - // Inform client no more data will ever arrive - ConnectionControl.End(ProduceEndType.SocketShutdownSend); - - // Wait for client to either disconnect or send unexpected data - await SocketInput; - } - finally - { - // Ensure we *always* disconnect the socket. - // Dispose socket - ConnectionControl.End(ProduceEndType.SocketDisconnect); - } + ConnectionControl.End(ProduceEndType.SocketShutdown); } } catch (Exception ex) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/IAsyncDisposable.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/IAsyncDisposable.cs new file mode 100644 index 0000000000..e2fb35aef6 --- /dev/null +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/IAsyncDisposable.cs @@ -0,0 +1,12 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System.Threading.Tasks; + +namespace Microsoft.AspNetCore.Server.Kestrel.Http +{ + interface IAsyncDisposable + { + Task DisposeAsync(); + } +} diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Listener.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Listener.cs index d43f54e58a..818807a203 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Listener.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Listener.cs @@ -11,7 +11,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http /// /// Base class for listeners in Kestrel. Listens for incoming connections /// - public abstract class Listener : ListenerContext, IDisposable + public abstract class Listener : ListenerContext, IAsyncDisposable { protected Listener(ServiceContext serviceContext) : base(serviceContext) @@ -77,7 +77,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http connection.Start(); } - public void Dispose() + public virtual async Task DisposeAsync() { // Ensure the event loop is still running. // If the event loop isn't running and we try to wait on this Post @@ -85,34 +85,26 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http // the exception that stopped the event loop will never be surfaced. if (Thread.FatalError == null && ListenSocket != null) { - var tcs = new TaskCompletionSource(this); - Thread.Post( - tcs2 => + await Thread.PostAsync(state => + { + var listener = (Listener)state; + listener.ListenSocket.Dispose(); + }, this); + + await ConnectionManager.CloseConnectionsAsync(); + + await Thread.PostAsync(state => + { + var listener = (Listener)state; + var writeReqPool = listener.WriteReqPool; + while (writeReqPool.Count > 0) { - try - { - var socket = (Listener)tcs2.Task.AsyncState; - socket.ListenSocket.Dispose(); - - var writeReqPool = socket.WriteReqPool; - while (writeReqPool.Count > 0) - { - writeReqPool.Dequeue().Dispose(); - } - - tcs2.SetResult(0); - } - catch (Exception ex) - { - tcs2.SetException(ex); - } - }, - tcs); - - // REVIEW: Should we add a timeout here to be safe? - tcs.Task.Wait(); + writeReqPool.Dequeue().Dispose(); + } + }, this); } + Memory2.Dispose(); ListenSocket = null; } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/ListenerContext.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/ListenerContext.cs index 692759e7d8..1b8e090aa2 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/ListenerContext.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/ListenerContext.cs @@ -11,13 +11,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { public ListenerContext() { - Memory2 = new MemoryPool2(); } public ListenerContext(ServiceContext serviceContext) : base(serviceContext) { Memory2 = new MemoryPool2(); + ConnectionManager = new ConnectionManager(); WriteReqPool = new Queue(SocketOutput.MaxPooledWriteReqs); } @@ -27,6 +27,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ServerAddress = listenerContext.ServerAddress; Thread = listenerContext.Thread; Memory2 = listenerContext.Memory2; + ConnectionManager = listenerContext.ConnectionManager; WriteReqPool = listenerContext.WriteReqPool; Log = listenerContext.Log; } @@ -37,6 +38,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http public MemoryPool2 Memory2 { get; set; } + public ConnectionManager ConnectionManager { get; set; } + public Queue WriteReqPool { get; set; } } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/ListenerPrimary.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/ListenerPrimary.cs index 58f46e14b8..30b27342d7 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/ListenerPrimary.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/ListenerPrimary.cs @@ -39,8 +39,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http await StartAsync(address, thread).ConfigureAwait(false); - await Thread.PostAsync(_this => _this.PostCallback(), - this).ConfigureAwait(false); + await Thread.PostAsync(state => ((ListenerPrimary)state).PostCallback(), + this).ConfigureAwait(false); } private void PostCallback() @@ -100,5 +100,26 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http socket); } } + + public override async Task DisposeAsync() + { + // Call base first so the ListenSocket gets closed and doesn't + // try to dispatch connections to closed pipes. + await base.DisposeAsync(); + + if (Thread.FatalError == null && ListenPipe != null) + { + await Thread.PostAsync(state => + { + var listener = (ListenerPrimary)state; + listener.ListenPipe.Dispose(); + + foreach (var dispatchPipe in listener._dispatchPipes) + { + dispatchPipe.Dispose(); + } + }, this); + } + } } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/ListenerSecondary.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/ListenerSecondary.cs index 18d69c1dd5..a096dea1a1 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/ListenerSecondary.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/ListenerSecondary.cs @@ -5,7 +5,6 @@ using System; using System.Runtime.InteropServices; using System.Threading; using System.Threading.Tasks; -using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Networking; using Microsoft.Extensions.Logging; @@ -16,7 +15,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http /// A secondary listener is delegated requests from a primary listener via a named pipe or /// UNIX domain socket. /// - public abstract class ListenerSecondary : ListenerContext, IDisposable + public abstract class ListenerSecondary : ListenerContext, IAsyncDisposable { private string _pipeName; private IntPtr _ptr; @@ -155,7 +154,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } - public void Dispose() + public async Task DisposeAsync() { // Ensure the event loop is still running. // If the event loop isn't running and we try to wait on this Post @@ -163,16 +162,31 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http // the exception that stopped the event loop will never be surfaced. if (Thread.FatalError == null) { - Thread.Send(listener => + await Thread.PostAsync(state => { + var listener = (ListenerSecondary)state; listener.DispatchPipe.Dispose(); listener.FreeBuffer(); }, this); + + await ConnectionManager.CloseConnectionsAsync(); + + await Thread.PostAsync(state => + { + var listener = (ListenerSecondary)state; + var writeReqPool = listener.WriteReqPool; + while (writeReqPool.Count > 0) + { + writeReqPool.Dequeue().Dispose(); + } + }, this); } else { FreeBuffer(); } + + Memory2.Dispose(); } } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/ProduceEndType.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/ProduceEndType.cs index 8e4831ffa2..4099e1c864 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/ProduceEndType.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/ProduceEndType.cs @@ -5,7 +5,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { public enum ProduceEndType { - SocketShutdownSend, + SocketShutdown, SocketDisconnect, ConnectionKeepAlive, } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketInput.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketInput.cs index 2a3ac3d698..d5803f0698 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketInput.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketInput.cs @@ -183,6 +183,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } + public void CompleteAwaiting() + { + Complete(); + } + public void AbortAwaiting() { _awaitableError = new TaskCanceledException("The request was aborted"); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketOutput.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketOutput.cs index 406d0b756a..bab2689334 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketOutput.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketOutput.cs @@ -20,7 +20,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http private const int _initialTaskQueues = 64; private const int _maxPooledWriteContexts = 32; - private static readonly WaitCallback _returnBlocks = (state) => ReturnBlocks((MemoryPoolBlock2)state); private static readonly Action _connectionCancellation = (state) => ((SocketOutput)state).CancellationTriggered(); private readonly KestrelThread _thread; @@ -205,17 +204,19 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { switch (endType) { - case ProduceEndType.SocketShutdownSend: + case ProduceEndType.SocketShutdown: WriteAsync(default(ArraySegment), default(CancellationToken), socketShutdownSend: true, - socketDisconnect: false); + socketDisconnect: true, + isSync: true); break; case ProduceEndType.SocketDisconnect: WriteAsync(default(ArraySegment), default(CancellationToken), socketShutdownSend: false, - socketDisconnect: true); + socketDisconnect: true, + isSync: true); break; } } @@ -256,6 +257,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { MemoryPoolBlock2 blockToReturn = null; + lock (_returnLock) { Debug.Assert(!_lastStart.IsDefault); @@ -277,7 +279,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if (blockToReturn != null) { - ThreadPool.QueueUserWorkItem(_returnBlocks, blockToReturn); + ReturnBlocks(blockToReturn); } } @@ -593,6 +595,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http return; } + Self._log.ConnectionWriteFin(Self._connectionId); + var shutdownReq = new UvShutdownReq(Self._log); shutdownReq.Init(Self._thread.Loop); shutdownReq.Shutdown(Self._socket, (_shutdownReq, status, state) => @@ -618,9 +622,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http return; } + // Ensure all blocks are returned before calling OnSocketClosed + // to ensure the MemoryPool doesn't get disposed too soon. + Self.ReturnAllBlocks(); Self._socket.Dispose(); Self._connection.OnSocketClosed(); - Self.ReturnAllBlocks(); Self._log.ConnectionStop(Self._connectionId); CompleteWithContextLock(); } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/IKestrelServerInformation.cs b/src/Microsoft.AspNetCore.Server.Kestrel/IKestrelServerInformation.cs index fa81591879..b2ec185075 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/IKestrelServerInformation.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/IKestrelServerInformation.cs @@ -1,6 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; using Microsoft.AspNetCore.Server.Kestrel.Filter; namespace Microsoft.AspNetCore.Server.Kestrel @@ -9,6 +10,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel { int ThreadCount { get; set; } + /// + /// The amount of time after the server begins shutting down before connections will be forcefully closed. + /// By default, Kestrel will wait 5 seconds for any ongoing requests to complete before terminating + /// the connection. + /// A custom timeout can be configured using the "kestrel.shutdownTimeout" key in . + /// The value will be parsed as a float representing the timout in seconds. + /// + TimeSpan ShutdownTimeout { get; set; } + bool NoDelay { get; set; } /// diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/ConnectionManager.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/ConnectionManager.cs new file mode 100644 index 0000000000..c4a64c561c --- /dev/null +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/ConnectionManager.cs @@ -0,0 +1,59 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Collections.Concurrent; +using System.Collections.Generic; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Server.Kestrel.Http; + +namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure +{ + public class ConnectionManager + { + private bool _managerClosed; + private ConcurrentDictionary _activeConnections = new ConcurrentDictionary(); + + public void AddConnection(long connectionId, Connection connection) + { + if (_managerClosed) + { + throw new InvalidOperationException(nameof(ConnectionManager) + " closed."); + } + + if (!_activeConnections.TryAdd(connectionId, connection)) + { + throw new InvalidOperationException("Connection already added."); + } + } + + public void ConnectionStopped(long connectionId) + { + Connection removed; + _activeConnections.TryRemove(connectionId, out removed); + } + + public Task CloseConnectionsAsync() + { + if (_managerClosed) + { + throw new InvalidOperationException(nameof(ConnectionManager) + " already closed."); + } + + _managerClosed = true; + + var stopTasks = new List(); + + foreach (var connectionId in _activeConnections.Keys) + { + Connection removed; + if (_activeConnections.TryRemove(connectionId, out removed)) + { + stopTasks.Add(removed.StopAsync()); + } + } + + return Task.WhenAll(stopTasks); + } + } +} diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/IKestrelTrace.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/IKestrelTrace.cs index 0ed3c6565a..26af1717c2 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/IKestrelTrace.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/IKestrelTrace.cs @@ -33,6 +33,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure void ConnectionDisconnectedWrite(long connectionId, int count, Exception ex); + void NotAllConnectionsClosedGracefully(); + void ApplicationError(Exception ex); } } \ No newline at end of file diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/KestrelThread.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/KestrelThread.cs index bd9ac3020c..7933e11e84 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/KestrelThread.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/KestrelThread.cs @@ -27,8 +27,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel private static readonly Action _threadCallbackAdapter = (callback, state) => ((Action)callback).Invoke((KestrelThread)state); private static readonly Action _socketCallbackAdapter = (callback, state) => ((Action)callback).Invoke((SocketOutput)state); private static readonly Action _tcsCallbackAdapter = (callback, state) => ((Action>)callback).Invoke((TaskCompletionSource)state); - private static readonly Action _listenerPrimaryCallbackAdapter = (callback, state) => ((Action)callback).Invoke((ListenerPrimary)state); - private static readonly Action _listenerSecondaryCallbackAdapter = (callback, state) => ((Action)callback).Invoke((ListenerSecondary)state); + private static readonly Action _postAsyncCallbackAdapter = (callback, state) => ((Action)callback).Invoke(state); private readonly KestrelEngine _engine; private readonly IApplicationLifetime _appLifetime; @@ -78,23 +77,19 @@ namespace Microsoft.AspNetCore.Server.Kestrel return; } - var stepTimeout = (int)(timeout.TotalMilliseconds / 3); + var stepTimeout = (int)(timeout.TotalMilliseconds / 2); Post(t => t.OnStop()); if (!_thread.Join(stepTimeout)) { try { - Post(t => t.OnStopRude()); + Post(t => t.OnStopImmediate()); if (!_thread.Join(stepTimeout)) { - Post(t => t.OnStopImmediate()); - if (!_thread.Join(stepTimeout)) - { #if NET451 - _thread.Abort(); + _thread.Abort(); #endif - } } } catch (ObjectDisposedException) @@ -118,11 +113,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel private void OnStop() { - _post.Unreference(); - } - - private void OnStopRude() - { + // If the listeners were all disposed gracefully there should be no handles + // left to dispose other than _post. + // We dispose everything here in the event they are not closed gracefully. _engine.Libuv.walk( _loop, (ptr, arg) => @@ -134,6 +127,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel } }, IntPtr.Zero); + + _post.Unreference(); } private void OnStopImmediate() @@ -179,14 +174,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel _post.Send(); } - public Task PostAsync(Action callback, ListenerPrimary state) + public Task PostAsync(Action callback, object state) { var tcs = new TaskCompletionSource(); lock (_workSync) { _workAdding.Enqueue(new Work { - CallbackAdapter = _listenerPrimaryCallbackAdapter, + CallbackAdapter = _postAsyncCallbackAdapter, Callback = callback, State = state, Completion = tcs @@ -196,35 +191,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel return tcs.Task; } - public Task PostAsync(Action callback, ListenerSecondary state) - { - var tcs = new TaskCompletionSource(); - lock (_workSync) - { - _workAdding.Enqueue(new Work - { - CallbackAdapter = _listenerSecondaryCallbackAdapter, - Callback = callback, - State = state, - Completion = tcs - }); - } - _post.Send(); - return tcs.Task; - } - - public void Send(Action callback, ListenerSecondary state) - { - if (_loop.ThreadId == Thread.CurrentThread.ManagedThreadId) - { - callback.Invoke(state); - } - else - { - PostAsync(callback, state).Wait(); - } - } - private void PostCloseHandle(Action callback, IntPtr handle) { lock (_workSync) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/KestrelTrace.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/KestrelTrace.cs index 9be3819e8b..0edcd183fb 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/KestrelTrace.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/KestrelTrace.cs @@ -23,6 +23,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel private static readonly Action _connectionDisconnect; private static readonly Action _connectionError; private static readonly Action _connectionDisconnectedWrite; + private static readonly Action _notAllConnectionsClosedGracefully; protected readonly ILogger _logger; @@ -37,12 +38,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel _connectionWriteFin = LoggerMessage.Define(LogLevel.Debug, 7, @"Connection id ""{ConnectionId}"" sending FIN."); _connectionWroteFin = LoggerMessage.Define(LogLevel.Debug, 8, @"Connection id ""{ConnectionId}"" sent FIN with status ""{Status}""."); _connectionKeepAlive = LoggerMessage.Define(LogLevel.Debug, 9, @"Connection id ""{ConnectionId}"" completed keep alive response."); - _connectionDisconnect = LoggerMessage.Define(LogLevel.Debug, 10, @"Connection id ""{ConnectionId}"" disconnected."); + _connectionDisconnect = LoggerMessage.Define(LogLevel.Debug, 10, @"Connection id ""{ConnectionId}"" disconnecting."); // ConnectionWrite: Reserved: 11 // ConnectionWriteCallback: Reserved: 12 // ApplicationError: Reserved: 13 - LoggerMessage.Define overload not present _connectionError = LoggerMessage.Define(LogLevel.Information, 14, @"Connection id ""{ConnectionId}"" communication error"); _connectionDisconnectedWrite = LoggerMessage.Define(LogLevel.Debug, 15, @"Connection id ""{ConnectionId}"" write of ""{count}"" bytes to disconnected client."); + _notAllConnectionsClosedGracefully = LoggerMessage.Define(LogLevel.Debug, 16, "Some connections failed to close gracefully during server shutdown."); } public KestrelTrace(ILogger logger) @@ -128,6 +130,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel _connectionDisconnectedWrite(_logger, connectionId, count, ex); } + public virtual void NotAllConnectionsClosedGracefully() + { + _notAllConnectionsClosedGracefully(_logger, null); + } + public virtual void Log(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func formatter) { _logger.Log(logLevel, eventId, state, exception, formatter); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/KestrelEngine.cs b/src/Microsoft.AspNetCore.Server.Kestrel/KestrelEngine.cs index 40c3359558..ae4f84735c 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/KestrelEngine.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/KestrelEngine.cs @@ -3,7 +3,7 @@ using System; using System.Collections.Generic; -using Microsoft.AspNetCore.Http; +using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Http; using Microsoft.AspNetCore.Server.Kestrel.Networking; @@ -50,7 +50,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel public IDisposable CreateServer(ServerAddress address) { - var listeners = new List(); + var listeners = new List(); var usingPipes = address.IsUnixPipe; @@ -91,23 +91,33 @@ namespace Microsoft.AspNetCore.Server.Kestrel first = false; } + return new Disposable(() => { - foreach (var listener in listeners) - { - listener.Dispose(); - } + DisposeListeners(listeners); }); } catch { - foreach (var listener in listeners) - { - listener.Dispose(); - } + DisposeListeners(listeners); throw; } } + + private void DisposeListeners(List listeners) + { + var disposeTasks = new List(); + + foreach (var listener in listeners) + { + disposeTasks.Add(listener.DisposeAsync()); + } + + if (!Task.WhenAll(disposeTasks).Wait(ServerInformation.ShutdownTimeout)) + { + Log.NotAllConnectionsClosedGracefully(); + } + } } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServer.cs b/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServer.cs index b6768de672..ead9f9b2da 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServer.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServer.cs @@ -59,7 +59,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel var trace = new KestrelTrace(_logger); var engine = new KestrelEngine(new ServiceContext { - FrameFactory = (context, remoteEP, localEP, prepareRequest) => + FrameFactory = (context, remoteEP, localEP, prepareRequest) => { return new Frame(application, context, remoteEP, localEP, prepareRequest); }, diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServerInformation.cs b/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServerInformation.cs index b1d4d335ab..4e2f4b0515 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServerInformation.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServerInformation.cs @@ -21,6 +21,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel Addresses = GetAddresses(configuration); ThreadCount = GetThreadCount(configuration); + ShutdownTimeout = GetShutdownTimeout(configuration); NoDelay = GetNoDelay(configuration); PoolingParameters = new KestrelServerPoolingParameters(configuration); } @@ -29,6 +30,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel public int ThreadCount { get; set; } + public TimeSpan ShutdownTimeout { get; set; } + public bool NoDelay { get; set; } public KestrelServerPoolingParameters PoolingParameters { get; } @@ -93,6 +96,19 @@ namespace Microsoft.AspNetCore.Server.Kestrel return ProcessorThreadCount; } + private TimeSpan GetShutdownTimeout(IConfiguration configuration) + { + var shutdownTimeoutString = configuration["kestrel.shutdownTimout"]; + + float shutdownTimeout; + if (float.TryParse(shutdownTimeoutString, NumberStyles.Float, CultureInfo.InvariantCulture, out shutdownTimeout)) + { + return TimeSpan.FromSeconds(shutdownTimeout); + } + + return TimeSpan.FromSeconds(5); + } + private static bool GetNoDelay(IConfiguration configuration) { var noDelayString = configuration["kestrel.noDelay"]; diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestServiceContext.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/TestServiceContext.cs index 0ac9c5c76d..743044c2eb 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/TestServiceContext.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/TestServiceContext.cs @@ -1,6 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Server.Kestrel; using Microsoft.AspNetCore.Server.Kestrel.Filter; @@ -23,11 +24,13 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var configuration = new ConfigurationBuilder().Build(); ServerInformation = new KestrelServerInformation(configuration); + ServerInformation.ShutdownTimeout = TimeSpan.FromSeconds(5); + HttpComponentFactory = new HttpComponentFactory(ServerInformation); } public TestServiceContext(IConnectionFilter filter) - : base() + : this() { ServerInformation.ConnectionFilter = filter; } From 304016fc3bfda6dcfa6ba353210b348275b39f81 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Tue, 9 Feb 2016 15:01:04 -0800 Subject: [PATCH 0607/1662] Close UvAsyncHandle properly to avoid zombie threads - Even when safe handles are disposed explicitly, ReleaseHandle is sometimes called on another thread which breaks uv_close. - Ensure we close the UvAsyncHandle the uv loop so that the second call to uv_run always completes without a timeout/Thread.Abort. - Re-enable some tests. Add skip conditions for those that aren't passing. --- .../Http/Listener.cs | 3 +- .../Http/ListenerPrimary.cs | 4 +- .../Http/ListenerSecondary.cs | 4 +- .../Http/PipeListener.cs | 4 +- .../Http/PipeListenerPrimary.cs | 4 +- .../Http/PipeListenerSecondary.cs | 2 +- .../Http/SocketOutput.cs | 2 +- .../Infrastructure/KestrelThread.cs | 83 +++++++------------ .../Networking/Libuv.cs | 14 ++++ .../Networking/UvAsyncHandle.cs | 40 ++++++++- .../Networking/UvHandle.cs | 6 ++ .../Networking/UvLoopHandle.cs | 5 +- .../Networking/UvMemory.cs | 1 - .../Networking/UvPipeHandle.cs | 16 +--- .../Networking/UvStreamHandle.cs | 10 +-- .../Networking/UvTcpHandle.cs | 10 --- .../MultipleLoopTests.cs | 23 ++--- .../NetworkingTests.cs | 23 ++--- 18 files changed, 132 insertions(+), 122 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Listener.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Listener.cs index 818807a203..7fee42cec3 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Listener.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Listener.cs @@ -29,8 +29,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http var tcs = new TaskCompletionSource(this); - Thread.Post(tcs2 => + Thread.Post(state => { + var tcs2 = (TaskCompletionSource)state; try { var listener = ((Listener)tcs2.Task.AsyncState); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/ListenerPrimary.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/ListenerPrimary.cs index 30b27342d7..3e4c86c627 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/ListenerPrimary.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/ListenerPrimary.cs @@ -46,7 +46,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http private void PostCallback() { ListenPipe = new UvPipeHandle(Log); - ListenPipe.Init(Thread.Loop, false); + ListenPipe.Init(Thread.Loop, Thread.QueueCloseHandle, false); ListenPipe.Bind(_pipeName); ListenPipe.Listen(Constants.ListenBacklog, (pipe, status, error, state) => ((ListenerPrimary)state).OnListenPipe(pipe, status, error), this); @@ -60,7 +60,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } var dispatchPipe = new UvPipeHandle(Log); - dispatchPipe.Init(Thread.Loop, true); + dispatchPipe.Init(Thread.Loop, Thread.QueueCloseHandle, true); try { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/ListenerSecondary.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/ListenerSecondary.cs index a096dea1a1..8d21c16dcd 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/ListenerSecondary.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/ListenerSecondary.cs @@ -42,7 +42,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http DispatchPipe = new UvPipeHandle(Log); var tcs = new TaskCompletionSource(this); - Thread.Post(tcs2 => StartCallback(tcs2), tcs); + Thread.Post(state => StartCallback((TaskCompletionSource)state), tcs); return tcs.Task; } @@ -56,7 +56,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { try { - DispatchPipe.Init(Thread.Loop, true); + DispatchPipe.Init(Thread.Loop, Thread.QueueCloseHandle, true); var connect = new UvConnectRequest(Log); connect.Init(Thread.Loop); connect.Connect( diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/PipeListener.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/PipeListener.cs index 19a10c552f..3ee24032d6 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/PipeListener.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/PipeListener.cs @@ -23,7 +23,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http protected override UvStreamHandle CreateListenSocket() { var socket = new UvPipeHandle(Log); - socket.Init(Thread.Loop, false); + socket.Init(Thread.Loop, Thread.QueueCloseHandle, false); socket.Bind(ServerAddress.UnixPipePath); socket.Listen(Constants.ListenBacklog, (stream, status, error, state) => ConnectionCallback(stream, status, error, state), this); return socket; @@ -40,7 +40,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http try { - acceptSocket.Init(Thread.Loop, false); + acceptSocket.Init(Thread.Loop, Thread.QueueCloseHandle, false); listenSocket.Accept(acceptSocket); DispatchConnection(acceptSocket); } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/PipeListenerPrimary.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/PipeListenerPrimary.cs index 4381a43c8b..07d353119f 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/PipeListenerPrimary.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/PipeListenerPrimary.cs @@ -23,7 +23,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http protected override UvStreamHandle CreateListenSocket() { var socket = new UvPipeHandle(Log); - socket.Init(Thread.Loop, false); + socket.Init(Thread.Loop, Thread.QueueCloseHandle, false); socket.Bind(ServerAddress.UnixPipePath); socket.Listen(Constants.ListenBacklog, (stream, status, error, state) => ConnectionCallback(stream, status, error, state), this); return socket; @@ -40,7 +40,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http try { - acceptSocket.Init(Thread.Loop, false); + acceptSocket.Init(Thread.Loop, Thread.QueueCloseHandle, false); listenSocket.Accept(acceptSocket); DispatchConnection(acceptSocket); } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/PipeListenerSecondary.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/PipeListenerSecondary.cs index 3ca23ea6fc..1ec2373b4c 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/PipeListenerSecondary.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/PipeListenerSecondary.cs @@ -20,7 +20,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http protected override UvStreamHandle CreateAcceptSocket() { var acceptSocket = new UvPipeHandle(Log); - acceptSocket.Init(Thread.Loop, false); + acceptSocket.Init(Thread.Loop, Thread.QueueCloseHandle, false); return acceptSocket; } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketOutput.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketOutput.cs index bab2689334..4ed52a12b7 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketOutput.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketOutput.cs @@ -314,7 +314,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http private void ScheduleWrite() { - _thread.Post(_this => _this.WriteAllPending(), this); + _thread.Post(state => ((SocketOutput)state).WriteAllPending(), this); } // This is called on the libuv event loop diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/KestrelThread.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/KestrelThread.cs index 7933e11e84..e6a40d024a 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/KestrelThread.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/KestrelThread.cs @@ -24,9 +24,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel // otherwise it needs to wait till the next pass of the libuv loop private const int _maxLoops = 8; - private static readonly Action _threadCallbackAdapter = (callback, state) => ((Action)callback).Invoke((KestrelThread)state); - private static readonly Action _socketCallbackAdapter = (callback, state) => ((Action)callback).Invoke((SocketOutput)state); - private static readonly Action _tcsCallbackAdapter = (callback, state) => ((Action>)callback).Invoke((TaskCompletionSource)state); + private static readonly Action _postCallbackAdapter = (callback, state) => ((Action)callback).Invoke(state); private static readonly Action _postAsyncCallbackAdapter = (callback, state) => ((Action)callback).Invoke(state); private readonly KestrelEngine _engine; @@ -56,12 +54,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel _thread = new Thread(ThreadStart); _thread.Name = "KestrelThread - libuv"; QueueCloseHandle = PostCloseHandle; + QueueCloseAsyncHandle = EnqueueCloseHandle; } public UvLoopHandle Loop { get { return _loop; } } + public ExceptionDispatchInfo FatalError { get { return _closeError; } } - public Action, IntPtr> QueueCloseHandle { get; internal set; } + public Action, IntPtr> QueueCloseHandle { get; } + + private Action, IntPtr> QueueCloseAsyncHandle { get; } public Task StartAsync() { @@ -137,41 +139,23 @@ namespace Microsoft.AspNetCore.Server.Kestrel _loop.Stop(); } + public void Post(Action callback, object state) + { + lock (_workSync) + { + _workAdding.Enqueue(new Work + { + CallbackAdapter = _postCallbackAdapter, + Callback = callback, + State = state + }); + } + _post.Send(); + } + private void Post(Action callback) { - lock (_workSync) - { - _workAdding.Enqueue(new Work { CallbackAdapter = _threadCallbackAdapter, Callback = callback, State = this }); - } - _post.Send(); - } - - public void Post(Action callback, SocketOutput state) - { - lock (_workSync) - { - _workAdding.Enqueue(new Work - { - CallbackAdapter = _socketCallbackAdapter, - Callback = callback, - State = state - }); - } - _post.Send(); - } - - public void Post(Action> callback, TaskCompletionSource state) - { - lock (_workSync) - { - _workAdding.Enqueue(new Work - { - CallbackAdapter = _tcsCallbackAdapter, - Callback = callback, - State = state - }); - } - _post.Send(); + Post(thread => callback((KestrelThread)thread), this); } public Task PostAsync(Action callback, object state) @@ -192,12 +176,17 @@ namespace Microsoft.AspNetCore.Server.Kestrel } private void PostCloseHandle(Action callback, IntPtr handle) + { + EnqueueCloseHandle(callback, handle); + _post.Send(); + } + + private void EnqueueCloseHandle(Action callback, IntPtr handle) { lock (_workSync) { _closeHandleAdding.Enqueue(new CloseHandle { Callback = callback, Handle = handle }); } - _post.Send(); } private void ThreadStart(object parameter) @@ -206,7 +195,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel try { _loop.Init(_engine.Libuv); - _post.Init(_loop, OnPost); + _post.Init(_loop, OnPost, EnqueueCloseHandle); tcs.SetResult(0); } catch (Exception ex) @@ -230,18 +219,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel _post.Reference(); _post.Dispose(); - _engine.Libuv.walk( - _loop, - (ptr, arg) => - { - var handle = UvMemory.FromIntPtr(ptr); - if (handle != _post) - { - handle.Dispose(); - } - }, - IntPtr.Zero); - // Ensure the Dispose operations complete in the event loop. var ran2 = _loop.Run(); @@ -307,6 +284,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel return wasWork; } + private bool DoPostCloseHandle() { Queue queue; @@ -333,7 +311,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel } } - return wasWork; + return wasWork; } private struct Work @@ -343,6 +321,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel public object State; public TaskCompletionSource Completion; } + private struct CloseHandle { public Action Callback; diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Networking/Libuv.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Networking/Libuv.cs index 279d4885cf..8625350497 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Networking/Libuv.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Networking/Libuv.cs @@ -30,6 +30,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Networking _uv_close = NativeDarwinMonoMethods.uv_close; _uv_async_init = NativeDarwinMonoMethods.uv_async_init; _uv_async_send = NativeDarwinMonoMethods.uv_async_send; + _uv_unsafe_async_send = NativeDarwinMonoMethods.uv_unsafe_async_send; _uv_tcp_init = NativeDarwinMonoMethods.uv_tcp_init; _uv_tcp_bind = NativeDarwinMonoMethods.uv_tcp_bind; _uv_tcp_open = NativeDarwinMonoMethods.uv_tcp_open; @@ -71,6 +72,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Networking _uv_close = NativeMethods.uv_close; _uv_async_init = NativeMethods.uv_async_init; _uv_async_send = NativeMethods.uv_async_send; + _uv_unsafe_async_send = NativeMethods.uv_unsafe_async_send; _uv_tcp_init = NativeMethods.uv_tcp_init; _uv_tcp_bind = NativeMethods.uv_tcp_bind; _uv_tcp_open = NativeMethods.uv_tcp_open; @@ -207,6 +209,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Networking Check(_uv_async_send(handle)); } + protected Func _uv_unsafe_async_send; + public void unsafe_async_send(IntPtr handle) + { + Check(_uv_unsafe_async_send(handle)); + } + protected Func _uv_tcp_init; public void tcp_init(UvLoopHandle loop, UvTcpHandle handle) { @@ -510,6 +518,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Networking [DllImport("libuv", CallingConvention = CallingConvention.Cdecl)] public extern static int uv_async_send(UvAsyncHandle handle); + [DllImport("libuv", CallingConvention = CallingConvention.Cdecl, EntryPoint = "uv_async_send")] + public extern static int uv_unsafe_async_send(IntPtr handle); + [DllImport("libuv", CallingConvention = CallingConvention.Cdecl)] public static extern int uv_tcp_init(UvLoopHandle loop, UvTcpHandle handle); @@ -618,6 +629,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Networking [DllImport("__Internal", CallingConvention = CallingConvention.Cdecl)] public extern static int uv_async_send(UvAsyncHandle handle); + [DllImport("__Internal", CallingConvention = CallingConvention.Cdecl, EntryPoint = "uv_async_send")] + public extern static int uv_unsafe_async_send(IntPtr handle); + [DllImport("__Internal", CallingConvention = CallingConvention.Cdecl)] public static extern int uv_tcp_init(UvLoopHandle loop, UvTcpHandle handle); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvAsyncHandle.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvAsyncHandle.cs index d78973a847..3215a8730c 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvAsyncHandle.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvAsyncHandle.cs @@ -2,27 +2,33 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Diagnostics; +using System.Threading; using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; namespace Microsoft.AspNetCore.Server.Kestrel.Networking { public class UvAsyncHandle : UvHandle { + private static readonly Libuv.uv_close_cb _destroyMemory = (handle) => DestroyMemory(handle); + private static readonly Libuv.uv_async_cb _uv_async_cb = (handle) => AsyncCb(handle); private Action _callback; + private Action, IntPtr> _queueCloseHandle; public UvAsyncHandle(IKestrelTrace logger) : base(logger) { } - public void Init(UvLoopHandle loop, Action callback) + public void Init(UvLoopHandle loop, Action callback, Action, IntPtr> queueCloseHandle) { CreateMemory( - loop.Libuv, - loop.ThreadId, + loop.Libuv, + loop.ThreadId, loop.Libuv.handle_size(Libuv.HandleType.ASYNC)); _callback = callback; + _queueCloseHandle = queueCloseHandle; _uv.async_init(loop, this, _uv_async_cb); } @@ -35,5 +41,33 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Networking { FromIntPtr(handle)._callback.Invoke(); } + + protected override bool ReleaseHandle() + { + var memory = handle; + if (memory != IntPtr.Zero) + { + handle = IntPtr.Zero; + + if (Thread.CurrentThread.ManagedThreadId == ThreadId) + { + _uv.close(memory, _destroyMemory); + } + else if (_queueCloseHandle != null) + { + // This can be called from the finalizer. + // Ensure the closure doesn't reference "this". + var uv = _uv; + _queueCloseHandle(memory2 => uv.close(memory2, _destroyMemory), memory); + uv.unsafe_async_send(memory); + } + else + { + Debug.Assert(false, "UvAsyncHandle not initialized with queueCloseHandle action"); + return false; + } + } + return true; + } } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvHandle.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvHandle.cs index 65f3c43580..d672189698 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvHandle.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvHandle.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Diagnostics; using System.Threading; using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; @@ -44,6 +45,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Networking var uv = _uv; _queueCloseHandle(memory2 => uv.close(memory2, _destroyMemory), memory); } + else + { + Debug.Assert(false, "UvHandle not initialized with queueCloseHandle action"); + return false; + } } return true; } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvLoopHandle.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvLoopHandle.cs index 3cf357af9b..e368c6ea34 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvLoopHandle.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvLoopHandle.cs @@ -7,7 +7,7 @@ using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; namespace Microsoft.AspNetCore.Server.Kestrel.Networking { - public class UvLoopHandle : UvHandle + public class UvLoopHandle : UvMemory { public UvLoopHandle(IKestrelTrace logger) : base(logger) { @@ -35,7 +35,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Networking unsafe protected override bool ReleaseHandle() { - var memory = this.handle; + var memory = handle; if (memory != IntPtr.Zero) { // loop_close clears the gcHandlePtr @@ -46,6 +46,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Networking DestroyMemory(memory, gcHandlePtr); } + return true; } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvMemory.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvMemory.cs index c9a62462cf..162fed17e8 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvMemory.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvMemory.cs @@ -87,6 +87,5 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Networking GCHandle gcHandle = GCHandle.FromIntPtr(*(IntPtr*)handle); return (THandle)gcHandle.Target; } - } } \ No newline at end of file diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvPipeHandle.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvPipeHandle.cs index af143536a4..6604dfbb28 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvPipeHandle.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvPipeHandle.cs @@ -13,24 +13,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Networking { } - public void Init(UvLoopHandle loop, bool ipc) - { - CreateMemory( - loop.Libuv, - loop.ThreadId, - loop.Libuv.handle_size(Libuv.HandleType.NAMED_PIPE)); - - _uv.pipe_init(loop, this, ipc); - } - - public void Init(UvLoopHandle loop, Action, IntPtr> queueCloseHandle) + public void Init(UvLoopHandle loop, Action, IntPtr> queueCloseHandle, bool ipc = false) { CreateHandle( loop.Libuv, loop.ThreadId, - loop.Libuv.handle_size(Libuv.HandleType.TCP), queueCloseHandle); + loop.Libuv.handle_size(Libuv.HandleType.NAMED_PIPE), queueCloseHandle); - _uv.pipe_init(loop, this, false); + _uv.pipe_init(loop, this, ipc); } public void Bind(string name) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvStreamHandle.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvStreamHandle.cs index 3b88c74a16..266fd96a13 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvStreamHandle.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvStreamHandle.cs @@ -15,13 +15,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Networking private readonly static Libuv.uv_alloc_cb _uv_alloc_cb = (IntPtr handle, int suggested_size, out Libuv.uv_buf_t buf) => UvAllocCb(handle, suggested_size, out buf); private readonly static Libuv.uv_read_cb _uv_read_cb = (IntPtr handle, int status, ref Libuv.uv_buf_t buf) => UvReadCb(handle, status, ref buf); - public Action _listenCallback; - public object _listenState; + private Action _listenCallback; + private object _listenState; private GCHandle _listenVitality; - public Func _allocCallback; - public Action _readCallback; - public object _readState; + private Func _allocCallback; + private Action _readCallback; + private object _readState; private GCHandle _readVitality; protected UvStreamHandle(IKestrelTrace logger) : base(logger) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvTcpHandle.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvTcpHandle.cs index ec201a3627..6e7e9b2549 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvTcpHandle.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvTcpHandle.cs @@ -14,16 +14,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Networking { } - public void Init(UvLoopHandle loop) - { - CreateMemory( - loop.Libuv, - loop.ThreadId, - loop.Libuv.handle_size(Libuv.HandleType.TCP)); - - _uv.tcp_init(loop, this); - } - public void Init(UvLoopHandle loop, Action, IntPtr> queueCloseHandle) { CreateHandle( diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/MultipleLoopTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/MultipleLoopTests.cs index 6c4d2e8ed0..f75079f57e 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/MultipleLoopTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/MultipleLoopTests.cs @@ -21,13 +21,14 @@ namespace Microsoft.AspNetCore.Server.KestrelTests _logger = engine.Log; } + [Fact] public void InitAndCloseServerPipe() { var loop = new UvLoopHandle(_logger); var pipe = new UvPipeHandle(_logger); loop.Init(_uv); - pipe.Init(loop, true); + pipe.Init(loop, (a, b) => { }, true); pipe.Bind(@"\\.\pipe\InitAndCloseServerPipe"); pipe.Dispose(); @@ -38,18 +39,19 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } + [Fact(Skip = "Test needs to be fixed (UvException: Error -4082 EBUSY resource busy or locked from loop_close)")] public void ServerPipeListenForConnections() { var loop = new UvLoopHandle(_logger); var serverListenPipe = new UvPipeHandle(_logger); loop.Init(_uv); - serverListenPipe.Init(loop, false); + serverListenPipe.Init(loop, (a, b) => { }, false); serverListenPipe.Bind(@"\\.\pipe\ServerPipeListenForConnections"); serverListenPipe.Listen(128, (_1, status, error, _2) => { var serverConnectionPipe = new UvPipeHandle(_logger); - serverConnectionPipe.Init(loop, true); + serverConnectionPipe.Init(loop, (a, b) => { }, true); try { serverListenPipe.Accept(serverConnectionPipe); @@ -92,7 +94,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var connect = new UvConnectRequest(new KestrelTrace(new TestKestrelTrace())); loop2.Init(_uv); - clientConnectionPipe.Init(loop2, true); + clientConnectionPipe.Init(loop2, (a, b) => { }, true); connect.Init(loop2); connect.Connect(clientConnectionPipe, @"\\.\pipe\ServerPipeListenForConnections", (_1, status, error, _2) => { @@ -120,6 +122,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } + [Fact(Skip = "Test needs to be fixed (UvException: Error -4088 EAGAIN resource temporarily unavailable from accept)")] public void ServerPipeDispatchConnections() { var pipeName = @"\\.\pipe\ServerPipeDispatchConnections" + Guid.NewGuid().ToString("n"); @@ -132,12 +135,12 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var serverConnectionTcpDisposedEvent = new ManualResetEvent(false); var serverListenPipe = new UvPipeHandle(_logger); - serverListenPipe.Init(loop, false); + serverListenPipe.Init(loop, (a, b) => { }, false); serverListenPipe.Bind(pipeName); serverListenPipe.Listen(128, (_1, status, error, _2) => { serverConnectionPipe = new UvPipeHandle(_logger); - serverConnectionPipe.Init(loop, true); + serverConnectionPipe.Init(loop, (a, b) => { }, true); try { serverListenPipe.Accept(serverConnectionPipe); @@ -152,13 +155,13 @@ namespace Microsoft.AspNetCore.Server.KestrelTests }, null); var serverListenTcp = new UvTcpHandle(_logger); - serverListenTcp.Init(loop); + serverListenTcp.Init(loop, (a, b) => { }); var address = ServerAddress.FromUrl("http://localhost:54321/"); serverListenTcp.Bind(address); serverListenTcp.Listen(128, (_1, status, error, _2) => { var serverConnectionTcp = new UvTcpHandle(_logger); - serverConnectionTcp.Init(loop); + serverConnectionTcp.Init(loop, (a, b) => { }); serverListenTcp.Accept(serverConnectionTcp); serverConnectionPipeAcceptedEvent.WaitOne(); @@ -188,7 +191,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var connect = new UvConnectRequest(new KestrelTrace(new TestKestrelTrace())); loop2.Init(_uv); - clientConnectionPipe.Init(loop2, true); + clientConnectionPipe.Init(loop2, (a, b) => { }, true); connect.Init(loop2); connect.Connect(clientConnectionPipe, pipeName, (_1, status, error, _2) => { @@ -208,7 +211,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests return; } var clientConnectionTcp = new UvTcpHandle(_logger); - clientConnectionTcp.Init(loop2); + clientConnectionTcp.Init(loop2, (a, b) => { }); clientConnectionPipe.Accept(clientConnectionTcp); var buf2 = loop2.Libuv.buf_init(Marshal.AllocHGlobal(64), 64); clientConnectionTcp.ReadStart( diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/NetworkingTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/NetworkingTests.cs index 642d4c7729..7e05b5a533 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/NetworkingTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/NetworkingTests.cs @@ -47,7 +47,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { called = true; trigger.Dispose(); - }); + }, (a, b) => { }); trigger.Send(); loop.Run(); loop.Dispose(); @@ -60,7 +60,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var loop = new UvLoopHandle(_logger); loop.Init(_uv); var tcp = new UvTcpHandle(_logger); - tcp.Init(loop); + tcp.Init(loop, (a, b) => { }); var address = ServerAddress.FromUrl("http://localhost:0/"); tcp.Bind(address); tcp.Dispose(); @@ -75,14 +75,14 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var loop = new UvLoopHandle(_logger); loop.Init(_uv); var tcp = new UvTcpHandle(_logger); - tcp.Init(loop); + tcp.Init(loop, (a, b) => { }); var port = TestServer.GetNextPort(); var address = ServerAddress.FromUrl($"http://localhost:{port}/"); tcp.Bind(address); tcp.Listen(10, (stream, status, error, state) => { var tcp2 = new UvTcpHandle(_logger); - tcp2.Init(loop); + tcp2.Init(loop, (a, b) => { }); stream.Accept(tcp2); tcp2.Dispose(); stream.Dispose(); @@ -117,15 +117,14 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var loop = new UvLoopHandle(_logger); loop.Init(_uv); var tcp = new UvTcpHandle(_logger); - tcp.Init(loop); + tcp.Init(loop, (a, b) => { }); var port = TestServer.GetNextPort(); var address = ServerAddress.FromUrl($"http://localhost:{port}/"); tcp.Bind(address); tcp.Listen(10, (_, status, error, state) => { - Console.WriteLine("Connected"); var tcp2 = new UvTcpHandle(_logger); - tcp2.Init(loop); + tcp2.Init(loop, (a, b) => { }); tcp.Accept(tcp2); var data = Marshal.AllocCoTaskMem(500); tcp2.ReadStart( @@ -140,7 +139,6 @@ namespace Microsoft.AspNetCore.Server.KestrelTests null); tcp.Dispose(); }, null); - Console.WriteLine("Task.Run"); var t = Task.Run(async () => { var socket = new Socket( @@ -179,15 +177,14 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var loop = new UvLoopHandle(_logger); loop.Init(_uv); var tcp = new UvTcpHandle(_logger); - tcp.Init(loop); + tcp.Init(loop, (a, b) => { }); var port = TestServer.GetNextPort(); var address = ServerAddress.FromUrl($"http://localhost:{port}/"); tcp.Bind(address); tcp.Listen(10, (_, status, error, state) => { - Console.WriteLine("Connected"); var tcp2 = new UvTcpHandle(_logger); - tcp2.Init(loop); + tcp2.Init(loop, (a, b) => { }); tcp.Accept(tcp2); var data = Marshal.AllocCoTaskMem(500); tcp2.ReadStart( @@ -227,7 +224,6 @@ namespace Microsoft.AspNetCore.Server.KestrelTests null); tcp.Dispose(); }, null); - Console.WriteLine("Task.Run"); var t = Task.Run(async () => { var socket = new Socket( @@ -268,9 +264,6 @@ namespace Microsoft.AspNetCore.Server.KestrelTests #else var count = await socket.ReceiveAsync(new[] { buffer }, SocketFlags.None); #endif - Console.WriteLine("count {0} {1}", - count, - System.Text.Encoding.ASCII.GetString(buffer.Array, 0, count)); if (count <= 0) break; } socket.Dispose(); From f4bb8d5eff24aac7387e8dc04ee39734ecd05df1 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Tue, 9 Feb 2016 15:02:23 -0800 Subject: [PATCH 0608/1662] Verify that memory pool blocks aren't leaked in tests --- .../Infrastructure/MemoryPool2.cs | 5 + .../Infrastructure/MemoryPoolBlock2.cs | 2 +- .../ConnectionFilterTests.cs | 1 - .../EngineTests.cs | 4 +- .../FrameTests.cs | 23 +- .../MemoryPoolBlock2Tests.cs | 26 ++ .../MemoryPoolIterator2Tests.cs | 19 ++ .../MessageBodyTests.cs | 82 +++--- .../SocketInputTests.cs | 33 +-- .../SocketOutputTests.cs | 246 +++++++++++------- .../TestHelpers/MockConnection.cs | 25 +- .../TestInput.cs | 15 +- .../UrlPathDecoder.cs | 1 - 13 files changed, 311 insertions(+), 171 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPool2.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPool2.cs index c7a2899b69..5aab1ff902 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPool2.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPool2.cs @@ -161,6 +161,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure } } + foreach (var block in _blocks) + { + GC.SuppressFinalize(block); + } + // N/A: free unmanaged resources (unmanaged objects) and override a finalizer below. // N/A: set large fields to null. diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPoolBlock2.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPoolBlock2.cs index 905e3c3464..2a4a732a96 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPoolBlock2.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPoolBlock2.cs @@ -77,7 +77,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure ~MemoryPoolBlock2() { Debug.Assert(!_pinHandle.IsAllocated, "Ad-hoc memory block wasn't unpinned"); - // Debug.Assert(Slab == null || !Slab.IsActive, "Block being garbage collected instead of returned to pool"); + Debug.Assert(Slab == null, "Block being garbage collected instead of returned to pool"); if (_pinHandle.IsAllocated) { diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionFilterTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionFilterTests.cs index dce414fa3e..7e84056b6e 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionFilterTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionFilterTests.cs @@ -5,7 +5,6 @@ using System; using System.IO; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Server.Kestrel.Filter; using Microsoft.AspNetCore.Testing.xunit; using Xunit; diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs index 73c159299d..375fca9834 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs @@ -113,7 +113,6 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var address = ServerAddress.FromUrl($"http://localhost:{port}/"); var started = engine.CreateServer(address); - Console.WriteLine("Started"); var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); socket.Connect(new IPEndPoint(IPAddress.Loopback, port)); socket.Send(Encoding.ASCII.GetBytes("POST / HTTP/1.0\r\n\r\nHello World")); @@ -1058,7 +1057,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests throw; } - readTcs.SetCanceled(); + readTcs.SetException(new Exception("This shouldn't be reached.")); } }, testContext)) { @@ -1122,6 +1121,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests for (int i = 0; i < 100; i++) { await response.WriteAsync(largeString, lifetime.RequestAborted); + registrationWh.Wait(1000); } } catch (Exception ex) diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs index 20fb2ad932..70c4454b53 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs @@ -26,20 +26,23 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { var trace = new KestrelTrace(new TestKestrelTrace()); var ltp = new LoggingThreadPool(trace); - var socketInput = new SocketInput(new MemoryPool2(), ltp); - var headerCollection = new FrameRequestHeaders(); + using (var pool = new MemoryPool2()) + using (var socketInput = new SocketInput(pool, ltp)) + { + var headerCollection = new FrameRequestHeaders(); - var headerArray = Encoding.ASCII.GetBytes(rawHeaders); - socketInput.IncomingData(headerArray, 0, headerArray.Length); + var headerArray = Encoding.ASCII.GetBytes(rawHeaders); + socketInput.IncomingData(headerArray, 0, headerArray.Length); - var success = Frame.TakeMessageHeaders(socketInput, headerCollection); + var success = Frame.TakeMessageHeaders(socketInput, headerCollection); - Assert.True(success); - Assert.Equal(numHeaders, headerCollection.Count()); + Assert.True(success); + Assert.Equal(numHeaders, headerCollection.Count()); - // Assert TakeMessageHeaders consumed all the input - var scan = socketInput.ConsumingStart(); - Assert.True(scan.IsEnd); + // Assert TakeMessageHeaders consumed all the input + var scan = socketInput.ConsumingStart(); + Assert.True(scan.IsEnd); + } } } } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolBlock2Tests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolBlock2Tests.cs index 8411df9a39..f5f58465b9 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolBlock2Tests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolBlock2Tests.cs @@ -50,6 +50,8 @@ namespace Microsoft.AspNetCore.Server.KestrelTests hit.Seek(ref vectorCh, ref vectorMaxValues, ref vectorMaxValues); Assert.Equal(ch, iterator.GetLength(hit)); } + + pool.Return(block); } } @@ -109,6 +111,10 @@ namespace Microsoft.AspNetCore.Server.KestrelTests hit.Seek(ref vectorMaxValues, ref vectorMaxValues, ref vectorCh); Assert.Equal(ch, iterator.GetLength(hit)); } + + pool.Return(block1); + pool.Return(block2); + pool.Return(block3); } } @@ -192,6 +198,9 @@ namespace Microsoft.AspNetCore.Server.KestrelTests AssertIterator(iter300a2, block2, block2.End); AssertIterator(iter300b2, block2, block2.End); AssertIterator(iter300c2, block2, block2.End); + + pool.Return(block1); + pool.Return(block2); } } @@ -227,6 +236,9 @@ namespace Microsoft.AspNetCore.Server.KestrelTests endIterator.CopyTo(array, 0, 256, out actual); Assert.Equal(0, actual); + + pool.Return(block1); + pool.Return(block2); } } @@ -260,6 +272,15 @@ namespace Microsoft.AspNetCore.Server.KestrelTests Assert.Equal(-1, start.Take()); Assert.Equal(start.Block, end.Block); Assert.Equal(start.Index, end.Index); + + var block = block1; + while (block != null) + { + var returnBlock = block; + block = block.Next; + + pool.Return(returnBlock); + } } } @@ -284,6 +305,11 @@ namespace Microsoft.AspNetCore.Server.KestrelTests Assert.False(iterStart.IsEnd); Assert.False(iterMid.IsEnd); Assert.True(iterEnd.IsEnd); + + pool.Return(block1); + pool.Return(block2); + pool.Return(block3); + pool.Return(block4); } } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolIterator2Tests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolIterator2Tests.cs index cb11398a42..90d66690e9 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolIterator2Tests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolIterator2Tests.cs @@ -116,6 +116,8 @@ namespace Microsoft.AspNetCore.Server.KestrelTests Assert.Equal(expectResult, found); Assert.Equal(expectIndex, begin.Index - block.Start); + + _pool.Return(block); } [Fact] @@ -174,6 +176,11 @@ namespace Microsoft.AspNetCore.Server.KestrelTests // Can't put anything by the end Assert.False(head.Put(0xFF)); + + for (var i = 0; i < 4; ++i) + { + _pool.Return(blocks[i]); + } } [Fact] @@ -193,6 +200,8 @@ namespace Microsoft.AspNetCore.Server.KestrelTests // Assert Assert.Equal(0x0102030405060708, result); Assert.Equal(originalIndex, scan.Index); + + _pool.Return(block); } [Theory] @@ -229,6 +238,9 @@ namespace Microsoft.AspNetCore.Server.KestrelTests // Assert Assert.Equal(0x0102030405060708, result); Assert.Equal(originalIndex, scan.Index); + + _pool.Return(block); + _pool.Return(nextBlock); } [Theory] @@ -268,6 +280,9 @@ namespace Microsoft.AspNetCore.Server.KestrelTests // Assert Assert.Equal(0x08, result); Assert.NotEqual(originalIndex, scan.Index); + + _pool.Return(block); + _pool.Return(nextBlock); } [Theory] @@ -304,6 +319,8 @@ namespace Microsoft.AspNetCore.Server.KestrelTests // Assert Assert.Equal(expectedResult, result); Assert.Equal(expectedKnownString, knownString); + + _pool.Return(block); } [Theory] @@ -329,6 +346,8 @@ namespace Microsoft.AspNetCore.Server.KestrelTests // Assert Assert.Equal(expectedResult, result); Assert.Equal(expectedKnownString, knownString); + + _pool.Return(block); } } } \ No newline at end of file diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/MessageBodyTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/MessageBodyTests.cs index 9811de2ec7..97cea21c2e 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/MessageBodyTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/MessageBodyTests.cs @@ -17,66 +17,72 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [Fact] public void Http10ConnectionClose() { - var input = new TestInput(); - var body = MessageBody.For("HTTP/1.0", new FrameRequestHeaders(), input.FrameContext); - var stream = new FrameRequestStream().StartAcceptingReads(body); + using (var input = new TestInput()) + { + var body = MessageBody.For("HTTP/1.0", new FrameRequestHeaders(), input.FrameContext); + var stream = new FrameRequestStream().StartAcceptingReads(body); - input.Add("Hello", true); + input.Add("Hello", true); - var buffer1 = new byte[1024]; - var count1 = stream.Read(buffer1, 0, 1024); - AssertASCII("Hello", new ArraySegment(buffer1, 0, 5)); + var buffer1 = new byte[1024]; + var count1 = stream.Read(buffer1, 0, 1024); + AssertASCII("Hello", new ArraySegment(buffer1, 0, 5)); - var buffer2 = new byte[1024]; - var count2 = stream.Read(buffer2, 0, 1024); - Assert.Equal(0, count2); + var buffer2 = new byte[1024]; + var count2 = stream.Read(buffer2, 0, 1024); + Assert.Equal(0, count2); + } } [Fact] public async Task Http10ConnectionCloseAsync() { - var input = new TestInput(); - var body = MessageBody.For("HTTP/1.0", new FrameRequestHeaders(), input.FrameContext); - var stream = new FrameRequestStream().StartAcceptingReads(body); + using (var input = new TestInput()) + { + var body = MessageBody.For("HTTP/1.0", new FrameRequestHeaders(), input.FrameContext); + var stream = new FrameRequestStream().StartAcceptingReads(body); - input.Add("Hello", true); + input.Add("Hello", true); - var buffer1 = new byte[1024]; - var count1 = await stream.ReadAsync(buffer1, 0, 1024); - AssertASCII("Hello", new ArraySegment(buffer1, 0, 5)); + var buffer1 = new byte[1024]; + var count1 = await stream.ReadAsync(buffer1, 0, 1024); + AssertASCII("Hello", new ArraySegment(buffer1, 0, 5)); - var buffer2 = new byte[1024]; - var count2 = await stream.ReadAsync(buffer2, 0, 1024); - Assert.Equal(0, count2); + var buffer2 = new byte[1024]; + var count2 = await stream.ReadAsync(buffer2, 0, 1024); + Assert.Equal(0, count2); + } } [Fact] public async Task CanHandleLargeBlocks() { - var input = new TestInput(); - var body = MessageBody.For("HTTP/1.0", new FrameRequestHeaders(), input.FrameContext); - var stream = new FrameRequestStream().StartAcceptingReads(body); + using (var input = new TestInput()) + { + var body = MessageBody.For("HTTP/1.0", new FrameRequestHeaders(), input.FrameContext); + var stream = new FrameRequestStream().StartAcceptingReads(body); - // Input needs to be greater than 4032 bytes to allocate a block not backed by a slab. - var largeInput = new string('a', 8192); + // Input needs to be greater than 4032 bytes to allocate a block not backed by a slab. + var largeInput = new string('a', 8192); - input.Add(largeInput, true); - // Add a smaller block to the end so that SocketInput attempts to return the large - // block to the memory pool. - input.Add("Hello", true); + input.Add(largeInput, true); + // Add a smaller block to the end so that SocketInput attempts to return the large + // block to the memory pool. + input.Add("Hello", true); - var readBuffer = new byte[8192]; + var readBuffer = new byte[8192]; - var count1 = await stream.ReadAsync(readBuffer, 0, 8192); - Assert.Equal(8192, count1); - AssertASCII(largeInput, new ArraySegment(readBuffer, 0, 8192)); + var count1 = await stream.ReadAsync(readBuffer, 0, 8192); + Assert.Equal(8192, count1); + AssertASCII(largeInput, new ArraySegment(readBuffer, 0, 8192)); - var count2 = await stream.ReadAsync(readBuffer, 0, 8192); - Assert.Equal(5, count2); - AssertASCII("Hello", new ArraySegment(readBuffer, 0, 5)); + var count2 = await stream.ReadAsync(readBuffer, 0, 8192); + Assert.Equal(5, count2); + AssertASCII("Hello", new ArraySegment(readBuffer, 0, 5)); - var count3 = await stream.ReadAsync(readBuffer, 0, 8192); - Assert.Equal(0, count3); + var count3 = await stream.ReadAsync(readBuffer, 0, 8192); + Assert.Equal(0, count3); + } } private void AssertASCII(string expected, ArraySegment actual) diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/SocketInputTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/SocketInputTests.cs index 47d9eb2a87..29e2597f5f 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/SocketInputTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/SocketInputTests.cs @@ -19,14 +19,12 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var trace = new KestrelTrace(new TestKestrelTrace()); var ltp = new LoggingThreadPool(trace); using (var memory2 = new MemoryPool2()) + using (var socketInput = new SocketInput(memory2, ltp)) { - var socketInput = new SocketInput(memory2, ltp); - var task0Threw = false; var task1Threw = false; var task2Threw = false; - var task0 = AwaitAsTaskAsync(socketInput); Assert.False(task0.IsFaulted); @@ -84,19 +82,25 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var defultIter = new MemoryPoolIterator2(); // Calling ConsumingComplete without a preceding calling to ConsumingStart fails - var socketInput = new SocketInput(null, null); - Assert.Throws(() => socketInput.ConsumingComplete(defultIter, defultIter)); - - // Calling ConsumingStart twice in a row fails - socketInput = new SocketInput(null, null); - socketInput.ConsumingStart(); - Assert.Throws(() => socketInput.ConsumingStart()); + using (var socketInput = new SocketInput(null, null)) + { + Assert.Throws(() => socketInput.ConsumingComplete(defultIter, defultIter)); + } // Calling ConsumingComplete twice in a row fails - socketInput = new SocketInput(null, null); - socketInput.ConsumingStart(); - socketInput.ConsumingComplete(defultIter, defultIter); - Assert.Throws(() => socketInput.ConsumingComplete(defultIter, defultIter)); + using (var socketInput = new SocketInput(null, null)) + { + socketInput.ConsumingStart(); + socketInput.ConsumingComplete(defultIter, defultIter); + Assert.Throws(() => socketInput.ConsumingComplete(defultIter, defultIter)); + } + + // Calling ConsumingStart twice in a row fails + using (var socketInput = new SocketInput(null, null)) + { + socketInput.ConsumingStart(); + Assert.Throws(() => socketInput.ConsumingStart()); + } } private static void TestConcurrentFaultedTask(Task t) @@ -110,6 +114,5 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { await socketInput; } - } } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/SocketOutputTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/SocketOutputTests.cs index df8edab06b..7162cd0f70 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/SocketOutputTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/SocketOutputTests.cs @@ -33,8 +33,8 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } }; - using (var kestrelEngine = new KestrelEngine(mockLibuv, new TestServiceContext())) using (var memory = new MemoryPool2()) + using (var kestrelEngine = new KestrelEngine(mockLibuv, new TestServiceContext())) { kestrelEngine.Start(count: 1); @@ -42,7 +42,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var socket = new MockSocket(kestrelThread.Loop.ThreadId, new TestKestrelTrace()); var trace = new KestrelTrace(new TestKestrelTrace()); var ltp = new LoggingThreadPool(trace); - var socketOutput = new SocketOutput(kestrelThread, socket, memory, null, 0, trace, ltp, new Queue()); + var socketOutput = new SocketOutput(kestrelThread, socket, memory, new MockConnection(), 0, trace, ltp, new Queue()); // I doubt _maxBytesPreCompleted will ever be over a MB. If it is, we should change this test. var bufferSize = 1048576; @@ -60,6 +60,10 @@ namespace Microsoft.AspNetCore.Server.KestrelTests // Assert Assert.True(completedWh.Wait(1000)); + + // Cleanup + var cleanupTask = socketOutput.WriteAsync( + default(ArraySegment), default(CancellationToken), socketDisconnect: true); } } @@ -80,8 +84,8 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } }; - using (var kestrelEngine = new KestrelEngine(mockLibuv, new TestServiceContext())) using (var memory = new MemoryPool2()) + using (var kestrelEngine = new KestrelEngine(mockLibuv, new TestServiceContext())) { kestrelEngine.Start(count: 1); @@ -89,7 +93,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var socket = new MockSocket(kestrelThread.Loop.ThreadId, new TestKestrelTrace()); var trace = new KestrelTrace(new TestKestrelTrace()); var ltp = new LoggingThreadPool(trace); - var socketOutput = new SocketOutput(kestrelThread, socket, memory, null, 0, trace, ltp, new Queue()); + var socketOutput = new SocketOutput(kestrelThread, socket, memory, new MockConnection(), 0, trace, ltp, new Queue()); var bufferSize = maxBytesPreCompleted; var buffer = new ArraySegment(new byte[bufferSize], 0, bufferSize); @@ -117,6 +121,15 @@ namespace Microsoft.AspNetCore.Server.KestrelTests // Assert // Finishing the first write should allow the second write to pre-complete. Assert.True(completedWh.Wait(1000)); + + // Cleanup + var cleanupTask = socketOutput.WriteAsync( + default(ArraySegment), default(CancellationToken), socketDisconnect: true); + + foreach (var triggerCompleted in completeQueue) + { + triggerCompleted(0); + } } } @@ -139,8 +152,8 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } }; - using (var kestrelEngine = new KestrelEngine(mockLibuv, new TestServiceContext())) using (var memory = new MemoryPool2()) + using (var kestrelEngine = new KestrelEngine(mockLibuv, new TestServiceContext())) { kestrelEngine.Start(count: 1); @@ -148,7 +161,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var socket = new MockSocket(kestrelThread.Loop.ThreadId, new TestKestrelTrace()); var trace = new KestrelTrace(new TestKestrelTrace()); var ltp = new LoggingThreadPool(trace); - var socketOutput = new SocketOutput(kestrelThread, socket, memory, null, 0, trace, ltp, new Queue()); + var socketOutput = new SocketOutput(kestrelThread, socket, memory, new MockConnection(), 0, trace, ltp, new Queue()); var bufferSize = maxBytesPreCompleted / 2; var data = new byte[bufferSize]; @@ -183,6 +196,15 @@ namespace Microsoft.AspNetCore.Server.KestrelTests // Assert // Finishing the first write should allow the second write to pre-complete. Assert.True(writeTask2.Wait(1000)); + + // Cleanup + var cleanupTask = socketOutput.WriteAsync( + default(ArraySegment), default(CancellationToken), socketDisconnect: true); + + foreach (var triggerCompleted in completeQueue) + { + triggerCompleted(0); + } } } @@ -203,8 +225,8 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } }; - using (var kestrelEngine = new KestrelEngine(mockLibuv, new TestServiceContext())) using (var memory = new MemoryPool2()) + using (var kestrelEngine = new KestrelEngine(mockLibuv, new TestServiceContext())) { kestrelEngine.Start(count: 1); @@ -212,74 +234,87 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var socket = new MockSocket(kestrelThread.Loop.ThreadId, new TestKestrelTrace()); var trace = new KestrelTrace(new TestKestrelTrace()); var ltp = new LoggingThreadPool(trace); - ISocketOutput socketOutput = new SocketOutput(kestrelThread, socket, memory, new MockConnection(socket), 0, trace, ltp, new Queue()); + + using (var mockConnection = new MockConnection()) + { + ISocketOutput socketOutput = new SocketOutput(kestrelThread, socket, memory, mockConnection, 0, trace, ltp, new Queue()); - var bufferSize = maxBytesPreCompleted; + var bufferSize = maxBytesPreCompleted; - var data = new byte[bufferSize]; - var fullBuffer = new ArraySegment(data, 0, bufferSize); + var data = new byte[bufferSize]; + var fullBuffer = new ArraySegment(data, 0, bufferSize); - var cts = new CancellationTokenSource(); + var cts = new CancellationTokenSource(); - // Act - var task1Success = socketOutput.WriteAsync(fullBuffer, cancellationToken: cts.Token); - // task1 should complete successfully as < _maxBytesPreCompleted + // Act + var task1Success = socketOutput.WriteAsync(fullBuffer, cancellationToken: cts.Token); + // task1 should complete successfully as < _maxBytesPreCompleted - // First task is completed and successful - Assert.True(task1Success.IsCompleted); - Assert.False(task1Success.IsCanceled); - Assert.False(task1Success.IsFaulted); + // First task is completed and successful + Assert.True(task1Success.IsCompleted); + Assert.False(task1Success.IsCanceled); + Assert.False(task1Success.IsFaulted); - // following tasks should wait. - var task2Throw = socketOutput.WriteAsync(fullBuffer, cancellationToken: cts.Token); - var task3Success = socketOutput.WriteAsync(fullBuffer, cancellationToken: default(CancellationToken)); + // following tasks should wait. + var task2Throw = socketOutput.WriteAsync(fullBuffer, cancellationToken: cts.Token); + var task3Success = socketOutput.WriteAsync(fullBuffer, cancellationToken: default(CancellationToken)); - // Give time for tasks to percolate - await Task.Delay(1000); + // Give time for tasks to percolate + await Task.Delay(1000); - // Second task is not completed - Assert.False(task2Throw.IsCompleted); - Assert.False(task2Throw.IsCanceled); - Assert.False(task2Throw.IsFaulted); + // Second task is not completed + Assert.False(task2Throw.IsCompleted); + Assert.False(task2Throw.IsCanceled); + Assert.False(task2Throw.IsFaulted); - // Third task is not completed - Assert.False(task3Success.IsCompleted); - Assert.False(task3Success.IsCanceled); - Assert.False(task3Success.IsFaulted); + // Third task is not completed + Assert.False(task3Success.IsCompleted); + Assert.False(task3Success.IsCanceled); + Assert.False(task3Success.IsFaulted); - cts.Cancel(); + cts.Cancel(); - // Second task is now canceled - await Assert.ThrowsAsync(() => task2Throw); - Assert.True(task2Throw.IsCanceled); + // Second task is now canceled + await Assert.ThrowsAsync(() => task2Throw); + Assert.True(task2Throw.IsCanceled); - // Third task is now completed - await task3Success; + // Third task is now completed + await task3Success; - // Fourth task immediately cancels as the token is canceled - var task4Throw = socketOutput.WriteAsync(fullBuffer, cancellationToken: cts.Token); + // Fourth task immediately cancels as the token is canceled + var task4Throw = socketOutput.WriteAsync(fullBuffer, cancellationToken: cts.Token); - Assert.True(task4Throw.IsCompleted); - Assert.True(task4Throw.IsCanceled); - Assert.False(task4Throw.IsFaulted); + Assert.True(task4Throw.IsCompleted); + Assert.True(task4Throw.IsCanceled); + Assert.False(task4Throw.IsFaulted); - var task5Success = socketOutput.WriteAsync(fullBuffer, cancellationToken: default(CancellationToken)); - // task5 should complete immediately + var task5Success = socketOutput.WriteAsync(fullBuffer, cancellationToken: default(CancellationToken)); + // task5 should complete immediately - Assert.True(task5Success.IsCompleted); - Assert.False(task5Success.IsCanceled); - Assert.False(task5Success.IsFaulted); + Assert.True(task5Success.IsCompleted); + Assert.False(task5Success.IsCanceled); + Assert.False(task5Success.IsFaulted); - cts = new CancellationTokenSource(); + cts = new CancellationTokenSource(); - var task6Success = socketOutput.WriteAsync(fullBuffer, cancellationToken: cts.Token); - // task6 should complete immediately but not cancel as its cancellation token isn't set + var task6Success = socketOutput.WriteAsync(fullBuffer, cancellationToken: cts.Token); + // task6 should complete immediately but not cancel as its cancellation token isn't set - Assert.True(task6Success.IsCompleted); - Assert.False(task6Success.IsCanceled); - Assert.False(task6Success.IsFaulted); + Assert.True(task6Success.IsCompleted); + Assert.False(task6Success.IsCanceled); + Assert.False(task6Success.IsFaulted); - Assert.True(true); + Assert.True(true); + + // Cleanup + var cleanupTask = ((SocketOutput)socketOutput).WriteAsync( + default(ArraySegment), default(CancellationToken), socketDisconnect: true); + + foreach (var triggerCompleted in completeQueue) + { + triggerCompleted(0); + } + } } } @@ -300,9 +335,8 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } }; - using (var kestrelEngine = new KestrelEngine(mockLibuv, new TestServiceContext())) using (var memory = new MemoryPool2()) - using (var abortedSource = new CancellationTokenSource()) + using (var kestrelEngine = new KestrelEngine(mockLibuv, new TestServiceContext())) { kestrelEngine.Start(count: 1); @@ -311,50 +345,61 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var trace = new KestrelTrace(new TestKestrelTrace()); var ltp = new LoggingThreadPool(trace); - var mockConnection = new MockConnection(socket); - mockConnection.RequestAbortedSource = abortedSource; - ISocketOutput socketOutput = new SocketOutput(kestrelThread, socket, memory, mockConnection, 0, trace, ltp, new Queue()); + using (var mockConnection = new MockConnection()) + { + var abortedSource = mockConnection.RequestAbortedSource; + ISocketOutput socketOutput = new SocketOutput(kestrelThread, socket, memory, mockConnection, 0, trace, ltp, new Queue()); - var bufferSize = maxBytesPreCompleted; + var bufferSize = maxBytesPreCompleted; - var data = new byte[bufferSize]; - var fullBuffer = new ArraySegment(data, 0, bufferSize); + var data = new byte[bufferSize]; + var fullBuffer = new ArraySegment(data, 0, bufferSize); - // Act - var task1Success = socketOutput.WriteAsync(fullBuffer, cancellationToken: abortedSource.Token); - // task1 should complete successfully as < _maxBytesPreCompleted + // Act + var task1Success = socketOutput.WriteAsync(fullBuffer, cancellationToken: abortedSource.Token); + // task1 should complete successfully as < _maxBytesPreCompleted - // First task is completed and successful - Assert.True(task1Success.IsCompleted); - Assert.False(task1Success.IsCanceled); - Assert.False(task1Success.IsFaulted); + // First task is completed and successful + Assert.True(task1Success.IsCompleted); + Assert.False(task1Success.IsCanceled); + Assert.False(task1Success.IsFaulted); - // following tasks should wait. - var task2Success = socketOutput.WriteAsync(fullBuffer, cancellationToken: default(CancellationToken)); - var task3Canceled = socketOutput.WriteAsync(fullBuffer, cancellationToken: abortedSource.Token); + // following tasks should wait. + var task2Success = socketOutput.WriteAsync(fullBuffer, cancellationToken: default(CancellationToken)); + var task3Canceled = socketOutput.WriteAsync(fullBuffer, cancellationToken: abortedSource.Token); - // Give time for tasks to percolate - await Task.Delay(1000); + // Give time for tasks to percolate + await Task.Delay(1000); - // Second task is not completed - Assert.False(task2Success.IsCompleted); - Assert.False(task2Success.IsCanceled); - Assert.False(task2Success.IsFaulted); + // Second task is not completed + Assert.False(task2Success.IsCompleted); + Assert.False(task2Success.IsCanceled); + Assert.False(task2Success.IsFaulted); - // Third task is not completed - Assert.False(task3Canceled.IsCompleted); - Assert.False(task3Canceled.IsCanceled); - Assert.False(task3Canceled.IsFaulted); + // Third task is not completed + Assert.False(task3Canceled.IsCompleted); + Assert.False(task3Canceled.IsCanceled); + Assert.False(task3Canceled.IsFaulted); - // Cause the first write to fail. - completeQueue.Dequeue()(-1); + // Cause the first write to fail. + completeQueue.Dequeue()(-1); - // Second task is now completed - await task2Success; + // Second task is now completed + await task2Success; - // Third task is now canceled - await Assert.ThrowsAsync(() => task3Canceled); - Assert.True(task3Canceled.IsCanceled); + // Third task is now canceled + await Assert.ThrowsAsync(() => task3Canceled); + Assert.True(task3Canceled.IsCanceled); + + // Cleanup + var cleanupTask = ((SocketOutput)socketOutput).WriteAsync( + default(ArraySegment), default(CancellationToken), socketDisconnect: true); + + foreach (var triggerCompleted in completeQueue) + { + triggerCompleted(0); + } + } } } @@ -378,8 +423,8 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } }; - using (var kestrelEngine = new KestrelEngine(mockLibuv, new TestServiceContext())) using (var memory = new MemoryPool2()) + using (var kestrelEngine = new KestrelEngine(mockLibuv, new TestServiceContext())) { kestrelEngine.Start(count: 1); @@ -387,7 +432,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var socket = new MockSocket(kestrelThread.Loop.ThreadId, new TestKestrelTrace()); var trace = new KestrelTrace(new TestKestrelTrace()); var ltp = new LoggingThreadPool(trace); - var socketOutput = new SocketOutput(kestrelThread, socket, memory, null, 0, trace, ltp, new Queue()); + var socketOutput = new SocketOutput(kestrelThread, socket, memory, new MockConnection(), 0, trace, ltp, new Queue()); var bufferSize = maxBytesPreCompleted; var buffer = new ArraySegment(new byte[bufferSize], 0, bufferSize); @@ -435,6 +480,15 @@ namespace Microsoft.AspNetCore.Server.KestrelTests // Assert // Finishing the first write should allow the second write to pre-complete. Assert.True(completedWh2.Wait(1000)); + + // Cleanup + var cleanupTask = ((SocketOutput)socketOutput).WriteAsync( + default(ArraySegment), default(CancellationToken), socketDisconnect: true); + + foreach (var triggerCompleted in completeQueue) + { + triggerCompleted(0); + } } } @@ -455,8 +509,8 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } }; - using (var kestrelEngine = new KestrelEngine(mockLibuv, new TestServiceContext())) using (var memory = new MemoryPool2()) + using (var kestrelEngine = new KestrelEngine(mockLibuv, new TestServiceContext())) { kestrelEngine.Start(count: 1); @@ -464,7 +518,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var socket = new MockSocket(kestrelThread.Loop.ThreadId, new TestKestrelTrace()); var trace = new KestrelTrace(new TestKestrelTrace()); var ltp = new LoggingThreadPool(trace); - var socketOutput = new SocketOutput(kestrelThread, socket, memory, null, 0, trace, ltp, new Queue()); + var socketOutput = new SocketOutput(kestrelThread, socket, memory, new MockConnection(), 0, trace, ltp, new Queue()); // block 1 var start = socketOutput.ProducingStart(); @@ -484,6 +538,10 @@ namespace Microsoft.AspNetCore.Server.KestrelTests Assert.True(nBufferWh.Wait(1000)); Assert.Equal(2, nBuffers); + + // Cleanup + var cleanupTask = socketOutput.WriteAsync( + default(ArraySegment), default(CancellationToken), socketDisconnect: true); } } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockConnection.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockConnection.cs index 74181488c2..e667ab7783 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockConnection.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockConnection.cs @@ -1,16 +1,20 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + using System; using System.Threading; -using Microsoft.AspNetCore.Server.Kestrel.Networking; +using Microsoft.AspNetCore.Server.Kestrel; using Microsoft.AspNetCore.Server.Kestrel.Http; +using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Networking; namespace Microsoft.AspNetCore.Server.KestrelTests.TestHelpers { - public class MockConnection : Connection + public class MockConnection : Connection, IDisposable { - public MockConnection(UvStreamHandle socket) - : base (new ListenerContext(), socket) + public MockConnection() { - + RequestAbortedSource = new CancellationTokenSource(); } public override void Abort() @@ -21,6 +25,15 @@ namespace Microsoft.AspNetCore.Server.KestrelTests.TestHelpers } } - public CancellationTokenSource RequestAbortedSource { get; set; } + public override void OnSocketClosed() + { + } + + public CancellationTokenSource RequestAbortedSource { get; } + + public void Dispose() + { + RequestAbortedSource.Dispose(); + } } } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestInput.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/TestInput.cs index d1e89a85b4..ba52b21d43 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/TestInput.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/TestInput.cs @@ -10,19 +10,22 @@ using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; namespace Microsoft.AspNetCore.Server.KestrelTests { - class TestInput : IConnectionControl, IFrameControl + class TestInput : IConnectionControl, IFrameControl, IDisposable { + private MemoryPool2 _memoryPool; + public TestInput() { var trace = new KestrelTrace(new TestKestrelTrace()); var ltp = new LoggingThreadPool(trace); - var memory2 = new MemoryPool2(); FrameContext = new FrameContext { - SocketInput = new SocketInput(memory2, ltp), ConnectionControl = this, FrameControl = this }; + + _memoryPool = new MemoryPool2(); + FrameContext.SocketInput = new SocketInput(_memoryPool, ltp); } public FrameContext FrameContext { get; set; } @@ -81,6 +84,12 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { return Task.FromResult(0); } + + public void Dispose() + { + FrameContext.SocketInput.Dispose(); + _memoryPool.Dispose(); + } } } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/UrlPathDecoder.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/UrlPathDecoder.cs index e8a64e2497..aab03b1a21 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/UrlPathDecoder.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/UrlPathDecoder.cs @@ -11,7 +11,6 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { public class UrlPathDecoderTests { - [Fact] public void Empty() { From 53ecef0f9846729221118e242ba9152ee4865b7f Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Wed, 10 Feb 2016 15:27:32 -0800 Subject: [PATCH 0609/1662] Use libuv to track connections instead of ConcurrentDictionaries - This means connections become untracked sooner than before and not all blocks will necessarily be returned. - The assertion in the MemoryPoolBlock2 finalizer was weakened because FilteredStreamAdapter will continue to use blocks after libuv stops tracking the associated connection. - Make 100% sure we don't accept new connections after we dispose the listen socket by using a flag. - Add a (currently unused) AllowStop method to KestrelThread. This is meant to be called from listeners when we stop accepting new connections, but needs investigation to prevent flakiness. --- .../Filter/FilteredStreamAdapter.cs | 4 +- .../Http/Connection.cs | 23 ++------ .../Http/ConnectionManager.cs | 53 +++++++++++++++++ .../Http/Listener.cs | 15 +++-- .../Http/ListenerContext.cs | 1 - .../Http/ListenerSecondary.cs | 10 +++- .../Http/SocketOutput.cs | 3 +- .../Http/TcpListener.cs | 1 - .../Infrastructure/ConnectionManager.cs | 59 ------------------- .../Infrastructure/KestrelThread.cs | 55 ++++++++++------- .../Infrastructure/MemoryPool2.cs | 2 +- .../Infrastructure/MemoryPoolBlock2.cs | 2 +- .../Networking/UvStreamHandle.cs | 3 + 13 files changed, 119 insertions(+), 112 deletions(-) create mode 100644 src/Microsoft.AspNetCore.Server.Kestrel/Http/ConnectionManager.cs delete mode 100644 src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/ConnectionManager.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Filter/FilteredStreamAdapter.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Filter/FilteredStreamAdapter.cs index 1e99ef698b..d93888ffb5 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Filter/FilteredStreamAdapter.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Filter/FilteredStreamAdapter.cs @@ -37,11 +37,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Filter public ISocketOutput SocketOutput { get; private set; } - public Task ReadInputAsync() + public void ReadInput() { _block = _memory.Lease(); // Use pooled block for copy - return _filteredStream.CopyToAsync(_socketInputStream, _block).ContinueWith((task, state) => + _filteredStream.CopyToAsync(_socketInputStream, _block).ContinueWith((task, state) => { ((FilteredStreamAdapter)state).OnStreamClose(task); }, this); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Connection.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Connection.cs index 6f4d79670e..d49738193e 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Connection.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Connection.cs @@ -33,7 +33,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http private readonly object _stateLock = new object(); private ConnectionState _connectionState; private TaskCompletionSource _socketClosedTcs; - private Task _readFilteredInputTask = TaskUtilities.CompletedTask; private IPEndPoint _remoteEndPoint; private IPEndPoint _localEndPoint; @@ -41,14 +40,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http public Connection(ListenerContext context, UvStreamHandle socket) : base(context) { _socket = socket; + socket.Connection = this; ConnectionControl = this; _connectionId = Interlocked.Increment(ref _lastConnectionId); _rawSocketInput = new SocketInput(Memory2, ThreadPool); _rawSocketOutput = new SocketOutput(Thread, _socket, Memory2, this, _connectionId, Log, ThreadPool, WriteReqPool); - - ConnectionManager.AddConnection(_connectionId, this); } // Internal for testing @@ -136,7 +134,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http switch (_connectionState) { case ConnectionState.SocketClosed: - return _readFilteredInputTask; + return TaskUtilities.CompletedTask; case ConnectionState.CreatingFrame: _connectionState = ConnectionState.ToDisconnect; break; @@ -147,7 +145,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } _socketClosedTcs = new TaskCompletionSource(); - return Task.WhenAll(_socketClosedTcs.Task, _readFilteredInputTask); + return _socketClosedTcs.Task; } } @@ -194,19 +192,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http // call on the libuv thread. _socketClosedTcs.TrySetResult(null); } - - if (_readFilteredInputTask.IsCompleted) - { - ConnectionManager.ConnectionStopped(_connectionId); - } - else - { - _readFilteredInputTask.ContinueWith((t, state) => - { - var connection = (Connection)state; - connection.ConnectionManager.ConnectionStopped(connection._connectionId); - }, this); - } } } @@ -225,7 +210,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http SocketInput = filteredStreamAdapter.SocketInput; SocketOutput = filteredStreamAdapter.SocketOutput; - _readFilteredInputTask = filteredStreamAdapter.ReadInputAsync(); + filteredStreamAdapter.ReadInput(); } else { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/ConnectionManager.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/ConnectionManager.cs new file mode 100644 index 0000000000..0d807aed1f --- /dev/null +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/ConnectionManager.cs @@ -0,0 +1,53 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Collections.Generic; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Server.Kestrel.Networking; + +namespace Microsoft.AspNetCore.Server.Kestrel.Http +{ + public class ConnectionManager + { + private KestrelThread _thread; + private List _connectionStopTasks; + + public ConnectionManager(KestrelThread thread) + { + _thread = thread; + } + + // This must be called on the libuv event loop + public void WalkConnectionsAndClose() + { + if (_connectionStopTasks != null) + { + throw new InvalidOperationException(nameof(WalkConnectionsAndClose) + " cannot be called twice."); + } + + _connectionStopTasks = new List(); + + _thread.Walk(ptr => + { + var handle = UvMemory.FromIntPtr(ptr); + var connection = (handle as UvStreamHandle)?.Connection; + + if (connection != null) + { + _connectionStopTasks.Add(connection.StopAsync()); + } + }); + } + + public Task WaitForConnectionCloseAsync() + { + if (_connectionStopTasks == null) + { + throw new InvalidOperationException(nameof(WalkConnectionsAndClose) + " must be called first."); + } + + return Task.WhenAll(_connectionStopTasks); + } + } +} diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Listener.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Listener.cs index 7fee42cec3..76b64dacba 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Listener.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Listener.cs @@ -13,6 +13,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http /// public abstract class Listener : ListenerContext, IAsyncDisposable { + private bool _closed; + protected Listener(ServiceContext serviceContext) : base(serviceContext) { @@ -26,6 +28,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { ServerAddress = address; Thread = thread; + ConnectionManager = new ConnectionManager(thread); var tcs = new TaskCompletionSource(this); @@ -55,11 +58,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http protected static void ConnectionCallback(UvStreamHandle stream, int status, Exception error, object state) { var listener = (Listener) state; + if (error != null) { listener.Log.LogError(0, error, "Listener.ConnectionCallback"); } - else + else if (!listener._closed) { listener.OnConnection(stream, status); } @@ -90,14 +94,17 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { var listener = (Listener)state; listener.ListenSocket.Dispose(); + + listener._closed = true; + + listener.ConnectionManager.WalkConnectionsAndClose(); }, this); - await ConnectionManager.CloseConnectionsAsync(); + await ConnectionManager.WaitForConnectionCloseAsync(); await Thread.PostAsync(state => { - var listener = (Listener)state; - var writeReqPool = listener.WriteReqPool; + var writeReqPool = ((Listener)state).WriteReqPool; while (writeReqPool.Count > 0) { writeReqPool.Dequeue().Dispose(); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/ListenerContext.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/ListenerContext.cs index 1b8e090aa2..a012c15326 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/ListenerContext.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/ListenerContext.cs @@ -17,7 +17,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http : base(serviceContext) { Memory2 = new MemoryPool2(); - ConnectionManager = new ConnectionManager(); WriteReqPool = new Queue(SocketOutput.MaxPooledWriteReqs); } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/ListenerSecondary.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/ListenerSecondary.cs index 8d21c16dcd..10426c1cc9 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/ListenerSecondary.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/ListenerSecondary.cs @@ -20,6 +20,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http private string _pipeName; private IntPtr _ptr; private Libuv.uv_buf_t _buf; + private bool _closed; protected ListenerSecondary(ServiceContext serviceContext) : base(serviceContext) { @@ -38,6 +39,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ServerAddress = address; Thread = thread; + ConnectionManager = new ConnectionManager(thread); DispatchPipe = new UvPipeHandle(Log); @@ -118,7 +120,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http return; } - if (DispatchPipe.PendingCount() == 0) + if (_closed || DispatchPipe.PendingCount() == 0) { return; } @@ -167,9 +169,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http var listener = (ListenerSecondary)state; listener.DispatchPipe.Dispose(); listener.FreeBuffer(); + + listener._closed = true; + + listener.ConnectionManager.WalkConnectionsAndClose(); }, this); - await ConnectionManager.CloseConnectionsAsync(); + await ConnectionManager.WaitForConnectionCloseAsync(); await Thread.PostAsync(state => { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketOutput.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketOutput.cs index 4ed52a12b7..6e9e4bebf1 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketOutput.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketOutput.cs @@ -20,6 +20,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http private const int _initialTaskQueues = 64; private const int _maxPooledWriteContexts = 32; + private static readonly WaitCallback _returnBlocks = (state) => ReturnBlocks((MemoryPoolBlock2)state); private static readonly Action _connectionCancellation = (state) => ((SocketOutput)state).CancellationTriggered(); private readonly KestrelThread _thread; @@ -279,7 +280,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if (blockToReturn != null) { - ReturnBlocks(blockToReturn); + ThreadPool.QueueUserWorkItem(_returnBlocks, blockToReturn); } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/TcpListener.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/TcpListener.cs index fc845b5239..1b1927e27c 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/TcpListener.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/TcpListener.cs @@ -44,7 +44,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http acceptSocket.NoDelay(ServerInformation.NoDelay); listenSocket.Accept(acceptSocket); DispatchConnection(acceptSocket); - } catch (UvException ex) { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/ConnectionManager.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/ConnectionManager.cs deleted file mode 100644 index c4a64c561c..0000000000 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/ConnectionManager.cs +++ /dev/null @@ -1,59 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using System.Collections.Concurrent; -using System.Collections.Generic; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Server.Kestrel.Http; - -namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure -{ - public class ConnectionManager - { - private bool _managerClosed; - private ConcurrentDictionary _activeConnections = new ConcurrentDictionary(); - - public void AddConnection(long connectionId, Connection connection) - { - if (_managerClosed) - { - throw new InvalidOperationException(nameof(ConnectionManager) + " closed."); - } - - if (!_activeConnections.TryAdd(connectionId, connection)) - { - throw new InvalidOperationException("Connection already added."); - } - } - - public void ConnectionStopped(long connectionId) - { - Connection removed; - _activeConnections.TryRemove(connectionId, out removed); - } - - public Task CloseConnectionsAsync() - { - if (_managerClosed) - { - throw new InvalidOperationException(nameof(ConnectionManager) + " already closed."); - } - - _managerClosed = true; - - var stopTasks = new List(); - - foreach (var connectionId in _activeConnections.Keys) - { - Connection removed; - if (_activeConnections.TryRemove(connectionId, out removed)) - { - stopTasks.Add(removed.StopAsync()); - } - } - - return Task.WhenAll(stopTasks); - } - } -} diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/KestrelThread.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/KestrelThread.cs index e6a40d024a..1cbeef9fd9 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/KestrelThread.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/KestrelThread.cs @@ -7,7 +7,6 @@ using System.Runtime.ExceptionServices; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Hosting; -using Microsoft.AspNetCore.Server.Kestrel.Http; using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Networking; using Microsoft.Extensions.Logging; @@ -72,6 +71,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel return tcs.Task; } + // This must be called from the libuv event loop. + public void AllowStop() + { + _post.Unreference(); + } + public void Stop(TimeSpan timeout) { if (!_initCompleted) @@ -79,19 +84,21 @@ namespace Microsoft.AspNetCore.Server.Kestrel return; } - var stepTimeout = (int)(timeout.TotalMilliseconds / 2); - - Post(t => t.OnStop()); - if (!_thread.Join(stepTimeout)) + if (_thread.IsAlive) { + var stepTimeout = (int)(timeout.TotalMilliseconds / 2); try { - Post(t => t.OnStopImmediate()); + Post(t => t.OnStopRude()); if (!_thread.Join(stepTimeout)) { + Post(t => t.OnStopImmediate()); + if (!_thread.Join(stepTimeout)) + { #if NET451 - _thread.Abort(); + _thread.Abort(); #endif + } } } catch (ObjectDisposedException) @@ -113,23 +120,18 @@ namespace Microsoft.AspNetCore.Server.Kestrel } } - private void OnStop() + private void OnStopRude() { - // If the listeners were all disposed gracefully there should be no handles - // left to dispose other than _post. - // We dispose everything here in the event they are not closed gracefully. - _engine.Libuv.walk( - _loop, - (ptr, arg) => + Walk(ptr => + { + var handle = UvMemory.FromIntPtr(ptr); + if (handle != _post) { - var handle = UvMemory.FromIntPtr(ptr); - if (handle != _post) - { - handle.Dispose(); - } - }, - IntPtr.Zero); + handle.Dispose(); + } + }); + // uv_unref is idempotent so it's OK to call this here and in AllowStop. _post.Unreference(); } @@ -175,6 +177,17 @@ namespace Microsoft.AspNetCore.Server.Kestrel return tcs.Task; } + public void Walk(Action callback) + { + _engine.Libuv.walk( + _loop, + (ptr, arg) => + { + callback(ptr); + }, + IntPtr.Zero); + } + private void PostCloseHandle(Action callback, IntPtr handle) { EnqueueCloseHandle(callback, handle); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPool2.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPool2.cs index 5aab1ff902..9eb0ebfe60 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPool2.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPool2.cs @@ -138,7 +138,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure /// The block to return. It must have been acquired by calling Lease on the same memory pool instance. public void Return(MemoryPoolBlock2 block) { - Debug.Assert(block.Pool == this, "Returned block was leased from this pool"); + Debug.Assert(block.Pool == this, "Returned block was not leased from this pool"); if (block.Slab != null && block.Slab.IsActive) { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPoolBlock2.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPoolBlock2.cs index 2a4a732a96..0dead6c6ae 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPoolBlock2.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPoolBlock2.cs @@ -77,7 +77,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure ~MemoryPoolBlock2() { Debug.Assert(!_pinHandle.IsAllocated, "Ad-hoc memory block wasn't unpinned"); - Debug.Assert(Slab == null, "Block being garbage collected instead of returned to pool"); + Debug.Assert(Slab == null || !Slab.IsActive, "Block being garbage collected instead of returned to pool"); if (_pinHandle.IsAllocated) { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvStreamHandle.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvStreamHandle.cs index 266fd96a13..eb94d78ef0 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvStreamHandle.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvStreamHandle.cs @@ -3,6 +3,7 @@ using System; using System.Runtime.InteropServices; +using Microsoft.AspNetCore.Server.Kestrel.Http; using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; using Microsoft.Extensions.Logging; @@ -28,6 +29,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Networking { } + public Connection Connection { get; set; } + protected override bool ReleaseHandle() { if (_listenVitality.IsAllocated) From 04736e1d091bf1149e69e2c4b4ec9a0448c9f89e Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Wed, 10 Feb 2016 15:46:29 -0800 Subject: [PATCH 0610/1662] Remove FrameworkSkipConditions for Mono - Maybe things are better now with graceful shutdown *crosses fingers* --- .../AddressRegistrationTests.cs | 7 +- .../PathBaseTests.cs | 16 ++-- .../RequestTests.cs | 16 ++-- .../ResponseTests.cs | 10 +-- .../ChunkedResponseTests.cs | 19 ++-- .../ConnectionFilterTests.cs | 10 +-- .../EngineTests.cs | 86 +++++++------------ 7 files changed, 53 insertions(+), 111 deletions(-) diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs index b7250054e6..9b2689c00a 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs @@ -8,7 +8,6 @@ using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http.Extensions; -using Microsoft.AspNetCore.Testing.xunit; using Microsoft.Extensions.Configuration; using Xunit; @@ -16,15 +15,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { public class AddressRegistrationTests { - [ConditionalTheory, MemberData(nameof(AddressRegistrationDataIPv4))] - [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Test hangs after execution on Mono.")] + [Theory, MemberData(nameof(AddressRegistrationDataIPv4))] public async Task RegisterAddresses_IPv4_Success(string addressInput, string[] testUrls) { await RegisterAddresses_Success(addressInput, testUrls); } - [ConditionalTheory, MemberData(nameof(AddressRegistrationDataIPv6))] - [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Test hangs after execution on Mono.")] + [Theory, MemberData(nameof(AddressRegistrationDataIPv6))] [IPv6SupportedCondition] public async Task RegisterAddresses_IPv6_Success(string addressInput, string[] testUrls) { diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/PathBaseTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/PathBaseTests.cs index 14e8b82a06..3576bd4d8d 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/PathBaseTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/PathBaseTests.cs @@ -7,7 +7,6 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Testing.xunit; using Microsoft.Extensions.Configuration; using Newtonsoft.Json; using Newtonsoft.Json.Linq; @@ -17,7 +16,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { public class PathBaseTests { - [ConditionalTheory] + [Theory] [InlineData("/base", "/base", "/base", "")] [InlineData("/base", "/base/", "/base", "/")] [InlineData("/base", "/base/something", "/base", "/something")] @@ -25,13 +24,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [InlineData("/base/more", "/base/more", "/base/more", "")] [InlineData("/base/more", "/base/more/something", "/base/more", "/something")] [InlineData("/base/more", "/base/more/something/", "/base/more", "/something/")] - [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Test hangs after execution on Mono.")] public Task RequestPathBaseIsServerPathBase(string registerPathBase, string requestPath, string expectedPathBase, string expectedPath) { return TestPathBase(registerPathBase, requestPath, expectedPathBase, expectedPath); } - [ConditionalTheory] + [Theory] [InlineData("", "/", "", "/")] [InlineData("", "/something", "", "/something")] [InlineData("/", "/", "", "/")] @@ -40,33 +38,29 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [InlineData("/base", "/baseandsomething", "", "/baseandsomething")] [InlineData("/base", "/ba", "", "/ba")] [InlineData("/base", "/ba/se", "", "/ba/se")] - [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Test hangs after execution on Mono.")] public Task DefaultPathBaseIsEmpty(string registerPathBase, string requestPath, string expectedPathBase, string expectedPath) { return TestPathBase(registerPathBase, requestPath, expectedPathBase, expectedPath); } - [ConditionalTheory] + [Theory] [InlineData("", "/", "", "/")] [InlineData("/", "/", "", "/")] [InlineData("/base", "/base/", "/base", "/")] [InlineData("/base/", "/base", "/base", "")] [InlineData("/base/", "/base/", "/base", "/")] - [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Test hangs after execution on Mono.")] public Task PathBaseNeverEndsWithSlash(string registerPathBase, string requestPath, string expectedPathBase, string expectedPath) { return TestPathBase(registerPathBase, requestPath, expectedPathBase, expectedPath); } - [ConditionalFact] - [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Test hangs after execution on Mono.")] + [Fact] public Task PathBaseAndPathPreserveRequestCasing() { return TestPathBase("/base", "/Base/Something", "/Base", "/Something"); } - [ConditionalFact] - [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Test hangs after execution on Mono.")] + [Fact] public Task PathBaseCanHaveUTF8Characters() { return TestPathBase("/b♫se", "/b♫se/something", "/b♫se", "/something"); diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs index a6fac125ea..0cc82366b2 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs @@ -11,7 +11,6 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Testing.xunit; using Microsoft.Extensions.Configuration; using Newtonsoft.Json; using Newtonsoft.Json.Linq; @@ -21,8 +20,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { public class RequestTests { - [ConditionalFact] - [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Test hangs after execution on Mono.")] + [Fact] public async Task LargeUpload() { var port = PortManager.GetPort(); @@ -78,25 +76,22 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } } - [ConditionalTheory] + [Theory] [InlineData("127.0.0.1", "127.0.0.1")] [InlineData("localhost", "127.0.0.1")] - [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Test hangs after execution on Mono.")] public Task RemoteIPv4Address(string requestAddress, string expectAddress) { return TestRemoteIPAddress("localhost", requestAddress, expectAddress); } - [ConditionalFact] - [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Test hangs after execution on Mono.")] + [Fact] [IPv6SupportedCondition] public Task RemoteIPv6Address() { return TestRemoteIPAddress("[::1]", "[::1]", "::1"); } - [ConditionalFact] - [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Test hangs after execution on Mono.")] + [Fact] public async Task DoesNotHangOnConnectionCloseRequest() { var port = PortManager.GetPort(); @@ -130,8 +125,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } } - [ConditionalFact] - [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Test hangs after execution on Mono.")] + [Fact] public void RequestPathIsNormalized() { var port = PortManager.GetPort(); diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs index 709eac3440..a6e39a3905 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs @@ -10,7 +10,6 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Testing.xunit; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Primitives; using Xunit; @@ -19,8 +18,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { public class ResponseTests { - [ConditionalFact] - [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Test hangs after execution on mono.")] + [Fact] public async Task LargeDownload() { var port = PortManager.GetPort(); @@ -80,8 +78,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } } - [ConditionalTheory, MemberData(nameof(NullHeaderData))] - [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Test hangs after execution on mono.")] + [Theory, MemberData(nameof(NullHeaderData))] public async Task IgnoreNullHeaderValues(string headerName, StringValues headerValue, string expectedValue) { var port = PortManager.GetPort(); @@ -129,8 +126,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } } - [ConditionalFact] - [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Test hangs after execution on mono.")] + [Fact] public async Task OnCompleteCalledEvenWhenOnStartingNotCalled() { var port = PortManager.GetPort(); diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedResponseTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedResponseTests.cs index 0179a9fb76..106959057a 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedResponseTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedResponseTests.cs @@ -5,15 +5,13 @@ using System; using System.Text; using System.Threading; using System.Threading.Tasks; -using Microsoft.AspNetCore.Testing.xunit; using Xunit; namespace Microsoft.AspNetCore.Server.KestrelTests { public class ChunkedResponseTests { - [ConditionalFact] - [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Test hangs after execution on Mono.")] + [Fact] public async Task ResponsesAreChunkedAutomatically() { using (var server = new TestServer(async httpContext => @@ -45,8 +43,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } } - [ConditionalFact] - [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Test hangs after execution on Mono.")] + [Fact] public async Task ZeroLengthWritesAreIgnored() { using (var server = new TestServer(async httpContext => @@ -79,8 +76,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } } - [ConditionalFact] - [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Test hangs after execution on Mono.")] + [Fact] public async Task EmptyResponseBodyHandledCorrectlyWithZeroLengthWrite() { using (var server = new TestServer(async httpContext => @@ -107,8 +103,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } } - [ConditionalFact] - [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Test hangs after execution on Mono.")] + [Fact] public async Task ConnectionClosedIfExeptionThrownAfterWrite() { using (var server = new TestServer(async httpContext => @@ -138,8 +133,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } } - [ConditionalFact] - [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Test hangs after execution on Mono.")] + [Fact] public async Task ConnectionClosedIfExeptionThrownAfterZeroLengthWrite() { using (var server = new TestServer(async httpContext => @@ -168,8 +162,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } } - [ConditionalFact] - [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Test hangs after execution on Mono.")] + [Fact] public async Task WritesAreFlushedPriorToResponseCompletion() { var flushWh = new ManualResetEventSlim(); diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionFilterTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionFilterTests.cs index 7e84056b6e..8b9451fef8 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionFilterTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionFilterTests.cs @@ -6,7 +6,6 @@ using System.IO; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Server.Kestrel.Filter; -using Microsoft.AspNetCore.Testing.xunit; using Xunit; namespace Microsoft.AspNetCore.Server.KestrelTests @@ -30,8 +29,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } } - [ConditionalFact] - [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Test hangs after execution on Mono.")] + [Fact] public async Task CanReadAndWriteWithRewritingConnectionFilter() { var filter = new RewritingConnectionFilter(); @@ -55,8 +53,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests Assert.Equal(sendString.Length, filter.BytesRead); } - [ConditionalFact] - [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Test hangs after execution on Mono.")] + [Fact] public async Task CanReadAndWriteWithAsyncConnectionFilter() { var serviceContext = new TestServiceContext(new AsyncConnectionFilter()); @@ -77,8 +74,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } } - [ConditionalFact] - [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Test hangs after execution on Mono.")] + [Fact] public async Task ThrowingSynchronousConnectionFilterDoesNotCrashServer() { var serviceContext = new TestServiceContext(new ThrowingConnectionFilter()); diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs index 375fca9834..6e9fb671e4 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs @@ -14,7 +14,6 @@ using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Server.Kestrel; using Microsoft.AspNetCore.Server.Kestrel.Filter; using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; -using Microsoft.AspNetCore.Testing.xunit; using Microsoft.Extensions.Logging; using Xunit; @@ -77,9 +76,8 @@ namespace Microsoft.AspNetCore.Server.KestrelTests return Task.FromResult(null); } - [ConditionalTheory] + [Theory] [MemberData(nameof(ConnectionFilterData))] - [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Test hangs after execution on Mono.")] public void EngineCanStartAndStop(ServiceContext testContext) { var engine = new KestrelEngine(testContext); @@ -87,9 +85,8 @@ namespace Microsoft.AspNetCore.Server.KestrelTests engine.Dispose(); } - [ConditionalTheory] + [Theory] [MemberData(nameof(ConnectionFilterData))] - [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Test hangs after execution on Mono.")] public void ListenerCanCreateAndDispose(TestServiceContext testContext) { testContext.App = App; @@ -101,9 +98,8 @@ namespace Microsoft.AspNetCore.Server.KestrelTests engine.Dispose(); } - [ConditionalTheory] + [Theory] [MemberData(nameof(ConnectionFilterData))] - [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Test hangs after execution on Mono.")] public void ConnectionCanReadAndWrite(TestServiceContext testContext) { var port = TestServer.GetNextPort(); @@ -129,9 +125,8 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } - [ConditionalTheory] + [Theory] [MemberData(nameof(ConnectionFilterData))] - [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Test hangs after execution on Mono.")] public async Task Http10(ServiceContext testContext) { using (var server = new TestServer(App, testContext)) @@ -151,9 +146,8 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } - [ConditionalTheory] + [Theory] [MemberData(nameof(ConnectionFilterData))] - [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Test hangs after execution on Mono.")] public async Task Http11(ServiceContext testContext) { using (var server = new TestServer(AppChunked, testContext)) @@ -180,7 +174,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } } - [ConditionalTheory] + [Theory] [MemberData(nameof(ConnectionFilterData))] public async Task ReuseStreamsOn(ServiceContext testContext) { @@ -223,7 +217,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } } - [ConditionalTheory] + [Theory] [MemberData(nameof(ConnectionFilterData))] public async Task ReuseStreamsOff(ServiceContext testContext) { @@ -266,9 +260,8 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } } - [ConditionalTheory] + [Theory] [MemberData(nameof(ConnectionFilterData))] - [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Test hangs after execution on Mono.")] public async Task Http10ContentLength(ServiceContext testContext) { using (var server = new TestServer(App, testContext)) @@ -288,9 +281,8 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } } - [ConditionalTheory] + [Theory] [MemberData(nameof(ConnectionFilterData))] - [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Test hangs after execution on Mono.")] public async Task Http10TransferEncoding(ServiceContext testContext) { using (var server = new TestServer(App, testContext)) @@ -310,9 +302,8 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } } - [ConditionalTheory] + [Theory] [MemberData(nameof(ConnectionFilterData))] - [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Test hangs after execution on Mono.")] public async Task Http10KeepAlive(ServiceContext testContext) { using (var server = new TestServer(AppChunked, testContext)) @@ -340,9 +331,8 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } } - [ConditionalTheory] + [Theory] [MemberData(nameof(ConnectionFilterData))] - [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Test hangs after execution on Mono.")] public async Task Http10KeepAliveNotUsedIfResponseContentLengthNotSet(ServiceContext testContext) { using (var server = new TestServer(App, testContext)) @@ -371,9 +361,8 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } } - [ConditionalTheory] + [Theory] [MemberData(nameof(ConnectionFilterData))] - [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Test hangs after execution on Mono.")] public async Task Http10KeepAliveContentLength(ServiceContext testContext) { using (var server = new TestServer(AppChunked, testContext)) @@ -403,9 +392,8 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } } - [ConditionalTheory] + [Theory] [MemberData(nameof(ConnectionFilterData))] - [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Test hangs after execution on Mono.")] public async Task Http10KeepAliveTransferEncoding(ServiceContext testContext) { using (var server = new TestServer(AppChunked, testContext)) @@ -436,9 +424,8 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } } - [ConditionalTheory] + [Theory] [MemberData(nameof(ConnectionFilterData))] - [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Test hangs after execution on Mono.")] public async Task Expect100ContinueForBody(ServiceContext testContext) { using (var server = new TestServer(AppChunked, testContext)) @@ -463,9 +450,8 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } } - [ConditionalTheory] + [Theory] [MemberData(nameof(ConnectionFilterData))] - [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Test hangs after execution on Mono.")] public async Task DisconnectingClient(ServiceContext testContext) { using (var server = new TestServer(App, testContext)) @@ -488,9 +474,8 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } } - [ConditionalTheory] + [Theory] [MemberData(nameof(ConnectionFilterData))] - [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Test hangs after execution on Mono.")] public async Task ZeroContentLengthSetAutomaticallyAfterNoWrites(ServiceContext testContext) { using (var server = new TestServer(EmptyApp, testContext)) @@ -517,9 +502,8 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } } - [ConditionalTheory] + [Theory] [MemberData(nameof(ConnectionFilterData))] - [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Test hangs after execution on Mono.")] public async Task ZeroContentLengthNotSetAutomaticallyForNonKeepAliveRequests(ServiceContext testContext) { using (var server = new TestServer(EmptyApp, testContext)) @@ -552,9 +536,8 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } } - [ConditionalTheory] + [Theory] [MemberData(nameof(ConnectionFilterData))] - [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Test hangs after execution on Mono.")] public async Task ZeroContentLengthNotSetAutomaticallyForHeadRequests(ServiceContext testContext) { using (var server = new TestServer(EmptyApp, testContext)) @@ -573,9 +556,8 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } } - [ConditionalTheory] + [Theory] [MemberData(nameof(ConnectionFilterData))] - [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Test hangs after execution on Mono.")] public async Task ZeroContentLengthNotSetAutomaticallyForCertainStatusCodes(ServiceContext testContext) { using (var server = new TestServer(async httpContext => @@ -627,9 +609,8 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } } - [ConditionalTheory] + [Theory] [MemberData(nameof(ConnectionFilterData))] - [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Test hangs after execution on Mono.")] public async Task ThrowingResultsIn500Response(ServiceContext testContext) { bool onStartingCalled = false; @@ -686,9 +667,8 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } } - [ConditionalTheory] + [Theory] [MemberData(nameof(ConnectionFilterData))] - [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Test hangs after execution on Mono.")] public async Task ThrowingAfterWritingKillsConnection(ServiceContext testContext) { bool onStartingCalled = false; @@ -729,9 +709,8 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } } - [ConditionalTheory] + [Theory] [MemberData(nameof(ConnectionFilterData))] - [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Test hangs after execution on Mono.")] public async Task ThrowingAfterPartialWriteKillsConnection(ServiceContext testContext) { bool onStartingCalled = false; @@ -772,9 +751,8 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } } - [ConditionalTheory] + [Theory] [MemberData(nameof(ConnectionFilterData))] - [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Test hangs after execution on Mono.")] public async Task ConnectionClosesWhenFinReceived(ServiceContext testContext) { using (var server = new TestServer(AppChunked, testContext)) @@ -800,9 +778,8 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } } - [ConditionalTheory] + [Theory] [MemberData(nameof(ConnectionFilterData))] - [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Test hangs after execution on Mono.")] public async Task ConnectionClosesWhenFinReceivedBeforeRequestCompletes(ServiceContext testContext) { using (var server = new TestServer(AppChunked, testContext)) @@ -843,9 +820,8 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } } - [ConditionalTheory] + [Theory] [MemberData(nameof(ConnectionFilterData))] - [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Test hangs after execution on Mono.")] public async Task ThrowingInOnStartingResultsInFailedWritesAnd500Response(ServiceContext testContext) { var onStartingCallCount1 = 0; @@ -917,9 +893,8 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } } - [ConditionalTheory] + [Theory] [MemberData(nameof(ConnectionFilterData))] - [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Test hangs after execution on Mono.")] public async Task ThrowingInOnCompletedIsLoggedAndClosesConnection(ServiceContext testContext) { var onCompletedCalled1 = false; @@ -968,9 +943,8 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } } - [ConditionalTheory] + [Theory] [MemberData(nameof(ConnectionFilterData))] - [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Test hangs after execution on Mono.")] public async Task RequestBodyIsConsumedAutomaticallyIfAppDoesntConsumeItFully(ServiceContext testContext) { using (var server = new TestServer(async httpContext => @@ -1015,9 +989,8 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } } - [ConditionalTheory] + [Theory] [MemberData(nameof(ConnectionFilterData))] - [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Test hangs after execution on Mono.")] public async Task RequestsCanBeAbortedMidRead(ServiceContext testContext) { var readTcs = new TaskCompletionSource(); @@ -1088,9 +1061,8 @@ namespace Microsoft.AspNetCore.Server.KestrelTests Assert.Equal(2, abortedRequestId); } - [ConditionalTheory] + [Theory] [MemberData(nameof(ConnectionFilterData))] - [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Test hangs after execution on Mono.")] public async Task FailedWritesResultInAbortedRequest(ServiceContext testContext) { // This should match _maxBytesPreCompleted in SocketOutput From bc56d11d8ca9ba3e3b6a3c84900b0f8027ff2e96 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Wed, 17 Feb 2016 16:33:34 -0800 Subject: [PATCH 0611/1662] Set IsBackground property to true on libuv Threads for non-debug builds - If libuv doesn't shutdown as expected, the process will still stop. Thanks @benaadams! - Address other minor PR feedback. --- .../Http/ConnectionManager.cs | 4 ++-- src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs | 3 +-- .../Infrastructure/KestrelThread.cs | 6 ++++++ .../FrameResponseHeadersTests.cs | 8 ++++---- .../TestHelpers/MockConnection.cs | 3 --- 5 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/ConnectionManager.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/ConnectionManager.cs index 0d807aed1f..640832a412 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/ConnectionManager.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/ConnectionManager.cs @@ -23,7 +23,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (_connectionStopTasks != null) { - throw new InvalidOperationException(nameof(WalkConnectionsAndClose) + " cannot be called twice."); + throw new InvalidOperationException($"{nameof(WalkConnectionsAndClose)} cannot be called twice."); } _connectionStopTasks = new List(); @@ -44,7 +44,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (_connectionStopTasks == null) { - throw new InvalidOperationException(nameof(WalkConnectionsAndClose) + " must be called first."); + throw new InvalidOperationException($"{nameof(WalkConnectionsAndClose)} must be called first."); } return Task.WhenAll(_connectionStopTasks); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs index 6b99b9898f..c830fcc2ee 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs @@ -189,12 +189,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http protected FrameRequestHeaders FrameRequestHeaders => _frameHeaders.RequestHeaders; - public Frame InitializeHeaders() + public void InitializeHeaders() { _frameHeaders = HttpComponentFactory.CreateHeaders(DateHeaderValueManager); RequestHeaders = _frameHeaders.RequestHeaders; ResponseHeaders = _frameHeaders.ResponseHeaders; - return this; } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/KestrelThread.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/KestrelThread.cs index 1cbeef9fd9..5b7d998f8e 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/KestrelThread.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/KestrelThread.cs @@ -79,6 +79,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel public void Stop(TimeSpan timeout) { +#if !DEBUG + // Mark the thread as being as unimportant to keeping the process alive. + // Don't do this for debug builds, so we know if the thread isn't terminating. + _thread.IsBackground = true; +#endif + if (!_initCompleted) { return; diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameResponseHeadersTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameResponseHeadersTests.cs index 30c03a0b35..f03deed0e3 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameResponseHeadersTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameResponseHeadersTests.cs @@ -26,8 +26,8 @@ namespace Microsoft.AspNetCore.Server.KestrelTests ServerInformation = serverInformation, HttpComponentFactory = new HttpComponentFactory(serverInformation) }; - var frame = new Frame(application: null, context: connectionContext) - .InitializeHeaders(); + var frame = new Frame(application: null, context: connectionContext); + frame.InitializeHeaders(); IDictionary headers = frame.ResponseHeaders; @@ -60,8 +60,8 @@ namespace Microsoft.AspNetCore.Server.KestrelTests ServerInformation = serverInformation, HttpComponentFactory = new HttpComponentFactory(serverInformation) }; - var frame = new Frame(application: null, context: connectionContext) - .InitializeHeaders(); + var frame = new Frame(application: null, context: connectionContext); + frame.InitializeHeaders(); Assert.True(frame.ResponseHeaders.Count > 0); diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockConnection.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockConnection.cs index e667ab7783..3daea602c7 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockConnection.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockConnection.cs @@ -3,10 +3,7 @@ using System; using System.Threading; -using Microsoft.AspNetCore.Server.Kestrel; using Microsoft.AspNetCore.Server.Kestrel.Http; -using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; -using Microsoft.AspNetCore.Server.Kestrel.Networking; namespace Microsoft.AspNetCore.Server.KestrelTests.TestHelpers { From aef612bdac07d8cf53253b1e0c3bc364a934c199 Mon Sep 17 00:00:00 2001 From: Chris R Date: Thu, 18 Feb 2016 10:59:12 -0800 Subject: [PATCH 0612/1662] Add IHttpConnectionFeature.ConnectionId. --- .../Http/Connection.cs | 66 ++++++++++++----- .../Http/ConnectionContext.cs | 18 +++++ .../Http/Frame.FeatureCollection.cs | 2 + .../Http/Frame.cs | 27 ++----- .../Http/FrameOfT.cs | 11 +-- .../Http/SocketOutput.cs | 4 +- .../Infrastructure/IKestrelTrace.cs | 28 ++++---- .../Infrastructure/KestrelTrace.cs | 72 +++++++++---------- .../KestrelServer.cs | 4 +- .../ServiceContext.cs | 2 +- .../SocketOutputTests.cs | 14 ++-- .../TestLogger.cs | 6 +- .../TestServer.cs | 4 +- .../TestServiceContext.cs | 4 +- 14 files changed, 145 insertions(+), 117 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Connection.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Connection.cs index d49738193e..3cc06e8521 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Connection.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Connection.cs @@ -2,7 +2,6 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.Net; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Filter; @@ -14,18 +13,23 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { public class Connection : ConnectionContext, IConnectionControl { + // Base32 encoding - in ascii sort order for easy text based sorting + private static readonly string _encode32Chars = "0123456789ABCDEFGHIJKLMNOPQRSTUV"; + private static readonly Action _readCallback = (handle, status, state) => ReadCallback(handle, status, state); private static readonly Func _allocCallback = (handle, suggestedsize, state) => AllocCallback(handle, suggestedsize, state); - private static long _lastConnectionId; + // Seed the _lastConnectionId for this application instance with + // the number of 100-nanosecond intervals that have elapsed since 12:00:00 midnight, January 1, 0001 + // for a roughly increasing _requestId over restarts + private static long _lastConnectionId = DateTime.UtcNow.Ticks; private readonly UvStreamHandle _socket; private Frame _frame; private ConnectionFilterContext _filterContext; private LibuvStream _libuvStream; - private readonly long _connectionId; private readonly SocketInput _rawSocketInput; private readonly SocketOutput _rawSocketOutput; @@ -34,19 +38,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http private ConnectionState _connectionState; private TaskCompletionSource _socketClosedTcs; - private IPEndPoint _remoteEndPoint; - private IPEndPoint _localEndPoint; - public Connection(ListenerContext context, UvStreamHandle socket) : base(context) { _socket = socket; socket.Connection = this; ConnectionControl = this; - _connectionId = Interlocked.Increment(ref _lastConnectionId); + ConnectionId = GenerateConnectionId(Interlocked.Increment(ref _lastConnectionId)); _rawSocketInput = new SocketInput(Memory2, ThreadPool); - _rawSocketOutput = new SocketOutput(Thread, _socket, Memory2, this, _connectionId, Log, ThreadPool, WriteReqPool); + _rawSocketOutput = new SocketOutput(Thread, _socket, Memory2, this, ConnectionId, Log, ThreadPool, WriteReqPool); } // Internal for testing @@ -56,7 +57,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http public void Start() { - Log.ConnectionStart(_connectionId); + Log.ConnectionStart(ConnectionId); // Start socket prior to applying the ConnectionFilter _socket.ReadStart(_allocCallback, _readCallback, this); @@ -64,8 +65,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http var tcpHandle = _socket as UvTcpHandle; if (tcpHandle != null) { - _remoteEndPoint = tcpHandle.GetPeerIPEndPoint(); - _localEndPoint = tcpHandle.GetSockIPEndPoint(); + RemoteEndPoint = tcpHandle.GetPeerIPEndPoint(); + LocalEndPoint = tcpHandle.GetSockIPEndPoint(); } // Don't initialize _frame until SocketInput and SocketOutput are set to their final values. @@ -218,6 +219,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http SocketOutput = _rawSocketOutput; } + PrepareRequest = _filterContext.PrepareRequest; + _frame = CreateFrame(); _frame.Start(); } @@ -256,12 +259,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if (normalRead) { - Log.ConnectionRead(_connectionId, readCount); + Log.ConnectionRead(ConnectionId, readCount); } else { _socket.ReadStop(); - Log.ConnectionReadFin(_connectionId); + Log.ConnectionReadFin(ConnectionId); } Exception error = null; @@ -280,18 +283,18 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http private Frame CreateFrame() { - return FrameFactory(this, _remoteEndPoint, _localEndPoint, _filterContext?.PrepareRequest); + return FrameFactory(this); } void IConnectionControl.Pause() { - Log.ConnectionPause(_connectionId); + Log.ConnectionPause(ConnectionId); _socket.ReadStop(); } void IConnectionControl.Resume() { - Log.ConnectionResume(_connectionId); + Log.ConnectionResume(ConnectionId); _socket.ReadStart(_allocCallback, _readCallback, this); } @@ -307,7 +310,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http return; } - Log.ConnectionKeepAlive(_connectionId); + Log.ConnectionKeepAlive(ConnectionId); break; case ProduceEndType.SocketShutdown: case ProduceEndType.SocketDisconnect: @@ -318,13 +321,40 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } _connectionState = ConnectionState.Disconnecting; - Log.ConnectionDisconnect(_connectionId); + Log.ConnectionDisconnect(ConnectionId); _rawSocketOutput.End(endType); break; } } } + private static unsafe string GenerateConnectionId(long id) + { + // The following routine is ~310% faster than calling long.ToString() on x64 + // and ~600% faster than calling long.ToString() on x86 in tight loops of 1 million+ iterations + // See: https://github.com/aspnet/Hosting/pull/385 + + // stackalloc to allocate array on stack rather than heap + char* charBuffer = stackalloc char[13]; + + charBuffer[0] = _encode32Chars[(int)(id >> 60) & 31]; + charBuffer[1] = _encode32Chars[(int)(id >> 55) & 31]; + charBuffer[2] = _encode32Chars[(int)(id >> 50) & 31]; + charBuffer[3] = _encode32Chars[(int)(id >> 45) & 31]; + charBuffer[4] = _encode32Chars[(int)(id >> 40) & 31]; + charBuffer[5] = _encode32Chars[(int)(id >> 35) & 31]; + charBuffer[6] = _encode32Chars[(int)(id >> 30) & 31]; + charBuffer[7] = _encode32Chars[(int)(id >> 25) & 31]; + charBuffer[8] = _encode32Chars[(int)(id >> 20) & 31]; + charBuffer[9] = _encode32Chars[(int)(id >> 15) & 31]; + charBuffer[10] = _encode32Chars[(int)(id >> 10) & 31]; + charBuffer[11] = _encode32Chars[(int)(id >> 5) & 31]; + charBuffer[12] = _encode32Chars[(int)id & 31]; + + // string ctor overload that takes char* + return new string(charBuffer, 0, 13); + } + private enum ConnectionState { CreatingFrame, diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/ConnectionContext.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/ConnectionContext.cs index 3a624d3659..bea3e7c7a5 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/ConnectionContext.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/ConnectionContext.cs @@ -1,6 +1,10 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; +using System.Net; +using Microsoft.AspNetCore.Http.Features; + namespace Microsoft.AspNetCore.Server.Kestrel.Http { public class ConnectionContext : ListenerContext @@ -18,10 +22,24 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http SocketInput = context.SocketInput; SocketOutput = context.SocketOutput; ConnectionControl = context.ConnectionControl; + RemoteEndPoint = context.RemoteEndPoint; + LocalEndPoint = context.LocalEndPoint; + ConnectionId = context.ConnectionId; + PrepareRequest = context.PrepareRequest; } public SocketInput SocketInput { get; set; } + public ISocketOutput SocketOutput { get; set; } + public IConnectionControl ConnectionControl { get; set; } + + public IPEndPoint RemoteEndPoint { get; set; } + + public IPEndPoint LocalEndPoint { get; set; } + + public string ConnectionId { get; set; } + + public Action PrepareRequest { get; set; } } } \ No newline at end of file diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.FeatureCollection.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.FeatureCollection.cs index a1d03fd2b1..827398ba0c 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.FeatureCollection.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.FeatureCollection.cs @@ -272,6 +272,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http int IHttpConnectionFeature.LocalPort { get; set; } + string IHttpConnectionFeature.ConnectionId { get; set; } + object IFeatureCollection.this[Type key] { get { return FastFeatureGet(key); } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs index c830fcc2ee..2c83fc7c84 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs @@ -67,26 +67,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http private HttpVersionType _httpVersion; - private readonly IPEndPoint _localEndPoint; - private readonly IPEndPoint _remoteEndPoint; - private readonly Action _prepareRequest; - private readonly string _pathBase; public Frame(ConnectionContext context) - : this(context, remoteEndPoint: null, localEndPoint: null, prepareRequest: null) - { - } - - public Frame(ConnectionContext context, - IPEndPoint remoteEndPoint, - IPEndPoint localEndPoint, - Action prepareRequest) : base(context) { - _remoteEndPoint = remoteEndPoint; - _localEndPoint = localEndPoint; - _prepareRequest = prepareRequest; _pathBase = context.ServerAddress.PathBase; FrameControl = this; @@ -249,13 +234,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ReasonPhrase = null; var httpConnectionFeature = this as IHttpConnectionFeature; - httpConnectionFeature.RemoteIpAddress = _remoteEndPoint?.Address; - httpConnectionFeature.RemotePort = _remoteEndPoint?.Port ?? 0; + httpConnectionFeature.RemoteIpAddress = RemoteEndPoint?.Address; + httpConnectionFeature.RemotePort = RemoteEndPoint?.Port ?? 0; - httpConnectionFeature.LocalIpAddress = _localEndPoint?.Address; - httpConnectionFeature.LocalPort = _localEndPoint?.Port ?? 0; + httpConnectionFeature.LocalIpAddress = LocalEndPoint?.Address; + httpConnectionFeature.LocalPort = LocalEndPoint?.Port ?? 0; - _prepareRequest?.Invoke(this); + httpConnectionFeature.ConnectionId = ConnectionId; + + PrepareRequest?.Invoke(this); _manuallySetRequestAbortToken = null; _abortedCts = null; diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameOfT.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameOfT.cs index 1c54363146..77e7c4047b 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameOfT.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameOfT.cs @@ -17,16 +17,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http public Frame(IHttpApplication application, ConnectionContext context) - : this(application, context, remoteEndPoint: null, localEndPoint: null, prepareRequest: null) - { - } - - public Frame(IHttpApplication application, - ConnectionContext context, - IPEndPoint remoteEndPoint, - IPEndPoint localEndPoint, - Action prepareRequest) - : base(context, remoteEndPoint, localEndPoint, prepareRequest) + : base(context) { _application = application; } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketOutput.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketOutput.cs index 6e9e4bebf1..8804d0255f 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketOutput.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketOutput.cs @@ -26,7 +26,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http private readonly KestrelThread _thread; private readonly UvStreamHandle _socket; private readonly Connection _connection; - private readonly long _connectionId; + private readonly string _connectionId; private readonly IKestrelTrace _log; private readonly IThreadPool _threadPool; @@ -58,7 +58,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http UvStreamHandle socket, MemoryPool2 memory, Connection connection, - long connectionId, + string connectionId, IKestrelTrace log, IThreadPool threadPool, Queue writeReqPool) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/IKestrelTrace.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/IKestrelTrace.cs index 26af1717c2..b004cb9eee 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/IKestrelTrace.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/IKestrelTrace.cs @@ -5,33 +5,33 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure { public interface IKestrelTrace : ILogger { - void ConnectionStart(long connectionId); + void ConnectionStart(string connectionId); - void ConnectionStop(long connectionId); + void ConnectionStop(string connectionId); - void ConnectionRead(long connectionId, int count); + void ConnectionRead(string connectionId, int count); - void ConnectionPause(long connectionId); + void ConnectionPause(string connectionId); - void ConnectionResume(long connectionId); + void ConnectionResume(string connectionId); - void ConnectionReadFin(long connectionId); + void ConnectionReadFin(string connectionId); - void ConnectionWriteFin(long connectionId); + void ConnectionWriteFin(string connectionId); - void ConnectionWroteFin(long connectionId, int status); + void ConnectionWroteFin(string connectionId, int status); - void ConnectionKeepAlive(long connectionId); + void ConnectionKeepAlive(string connectionId); - void ConnectionDisconnect(long connectionId); + void ConnectionDisconnect(string connectionId); - void ConnectionWrite(long connectionId, int count); + void ConnectionWrite(string connectionId, int count); - void ConnectionWriteCallback(long connectionId, int status); + void ConnectionWriteCallback(string connectionId, int status); - void ConnectionError(long connectionId, Exception ex); + void ConnectionError(string connectionId, Exception ex); - void ConnectionDisconnectedWrite(long connectionId, int count, Exception ex); + void ConnectionDisconnectedWrite(string connectionId, int count, Exception ex); void NotAllConnectionsClosedGracefully(); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/KestrelTrace.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/KestrelTrace.cs index 0edcd183fb..3c92c771ef 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/KestrelTrace.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/KestrelTrace.cs @@ -12,38 +12,38 @@ namespace Microsoft.AspNetCore.Server.Kestrel /// public class KestrelTrace : IKestrelTrace { - private static readonly Action _connectionStart; - private static readonly Action _connectionStop; - private static readonly Action _connectionPause; - private static readonly Action _connectionResume; - private static readonly Action _connectionReadFin; - private static readonly Action _connectionWriteFin; - private static readonly Action _connectionWroteFin; - private static readonly Action _connectionKeepAlive; - private static readonly Action _connectionDisconnect; - private static readonly Action _connectionError; - private static readonly Action _connectionDisconnectedWrite; + private static readonly Action _connectionStart; + private static readonly Action _connectionStop; + private static readonly Action _connectionPause; + private static readonly Action _connectionResume; + private static readonly Action _connectionReadFin; + private static readonly Action _connectionWriteFin; + private static readonly Action _connectionWroteFin; + private static readonly Action _connectionKeepAlive; + private static readonly Action _connectionDisconnect; + private static readonly Action _connectionError; + private static readonly Action _connectionDisconnectedWrite; private static readonly Action _notAllConnectionsClosedGracefully; protected readonly ILogger _logger; static KestrelTrace() { - _connectionStart = LoggerMessage.Define(LogLevel.Debug, 1, @"Connection id ""{ConnectionId}"" started."); - _connectionStop = LoggerMessage.Define(LogLevel.Debug, 2, @"Connection id ""{ConnectionId}"" stopped."); + _connectionStart = LoggerMessage.Define(LogLevel.Debug, 1, @"Connection id ""{ConnectionId}"" started."); + _connectionStop = LoggerMessage.Define(LogLevel.Debug, 2, @"Connection id ""{ConnectionId}"" stopped."); // ConnectionRead: Reserved: 3 - _connectionPause = LoggerMessage.Define(LogLevel.Debug, 4, @"Connection id ""{ConnectionId}"" paused."); - _connectionResume = LoggerMessage.Define(LogLevel.Debug, 5, @"Connection id ""{ConnectionId}"" resumed."); - _connectionReadFin = LoggerMessage.Define(LogLevel.Debug, 6, @"Connection id ""{ConnectionId}"" received FIN."); - _connectionWriteFin = LoggerMessage.Define(LogLevel.Debug, 7, @"Connection id ""{ConnectionId}"" sending FIN."); - _connectionWroteFin = LoggerMessage.Define(LogLevel.Debug, 8, @"Connection id ""{ConnectionId}"" sent FIN with status ""{Status}""."); - _connectionKeepAlive = LoggerMessage.Define(LogLevel.Debug, 9, @"Connection id ""{ConnectionId}"" completed keep alive response."); - _connectionDisconnect = LoggerMessage.Define(LogLevel.Debug, 10, @"Connection id ""{ConnectionId}"" disconnecting."); + _connectionPause = LoggerMessage.Define(LogLevel.Debug, 4, @"Connection id ""{ConnectionId}"" paused."); + _connectionResume = LoggerMessage.Define(LogLevel.Debug, 5, @"Connection id ""{ConnectionId}"" resumed."); + _connectionReadFin = LoggerMessage.Define(LogLevel.Debug, 6, @"Connection id ""{ConnectionId}"" received FIN."); + _connectionWriteFin = LoggerMessage.Define(LogLevel.Debug, 7, @"Connection id ""{ConnectionId}"" sending FIN."); + _connectionWroteFin = LoggerMessage.Define(LogLevel.Debug, 8, @"Connection id ""{ConnectionId}"" sent FIN with status ""{Status}""."); + _connectionKeepAlive = LoggerMessage.Define(LogLevel.Debug, 9, @"Connection id ""{ConnectionId}"" completed keep alive response."); + _connectionDisconnect = LoggerMessage.Define(LogLevel.Debug, 10, @"Connection id ""{ConnectionId}"" disconnecting."); // ConnectionWrite: Reserved: 11 // ConnectionWriteCallback: Reserved: 12 // ApplicationError: Reserved: 13 - LoggerMessage.Define overload not present - _connectionError = LoggerMessage.Define(LogLevel.Information, 14, @"Connection id ""{ConnectionId}"" communication error"); - _connectionDisconnectedWrite = LoggerMessage.Define(LogLevel.Debug, 15, @"Connection id ""{ConnectionId}"" write of ""{count}"" bytes to disconnected client."); + _connectionError = LoggerMessage.Define(LogLevel.Information, 14, @"Connection id ""{ConnectionId}"" communication error"); + _connectionDisconnectedWrite = LoggerMessage.Define(LogLevel.Debug, 15, @"Connection id ""{ConnectionId}"" write of ""{count}"" bytes to disconnected client."); _notAllConnectionsClosedGracefully = LoggerMessage.Define(LogLevel.Debug, 16, "Some connections failed to close gracefully during server shutdown."); } @@ -52,64 +52,64 @@ namespace Microsoft.AspNetCore.Server.Kestrel _logger = logger; } - public virtual void ConnectionStart(long connectionId) + public virtual void ConnectionStart(string connectionId) { _connectionStart(_logger, connectionId, null); } - public virtual void ConnectionStop(long connectionId) + public virtual void ConnectionStop(string connectionId) { _connectionStop(_logger, connectionId, null); } - public virtual void ConnectionRead(long connectionId, int count) + public virtual void ConnectionRead(string connectionId, int count) { // Don't log for now since this could be *too* verbose. // Reserved: Event ID 3 } - public virtual void ConnectionPause(long connectionId) + public virtual void ConnectionPause(string connectionId) { _connectionPause(_logger, connectionId, null); } - public virtual void ConnectionResume(long connectionId) + public virtual void ConnectionResume(string connectionId) { _connectionResume(_logger, connectionId, null); } - public virtual void ConnectionReadFin(long connectionId) + public virtual void ConnectionReadFin(string connectionId) { _connectionReadFin(_logger, connectionId, null); } - public virtual void ConnectionWriteFin(long connectionId) + public virtual void ConnectionWriteFin(string connectionId) { _connectionWriteFin(_logger, connectionId, null); } - public virtual void ConnectionWroteFin(long connectionId, int status) + public virtual void ConnectionWroteFin(string connectionId, int status) { _connectionWroteFin(_logger, connectionId, status, null); } - public virtual void ConnectionKeepAlive(long connectionId) + public virtual void ConnectionKeepAlive(string connectionId) { _connectionKeepAlive(_logger, connectionId, null); } - public virtual void ConnectionDisconnect(long connectionId) + public virtual void ConnectionDisconnect(string connectionId) { _connectionDisconnect(_logger, connectionId, null); } - public virtual void ConnectionWrite(long connectionId, int count) + public virtual void ConnectionWrite(string connectionId, int count) { // Don't log for now since this could be *too* verbose. // Reserved: Event ID 11 } - public virtual void ConnectionWriteCallback(long connectionId, int status) + public virtual void ConnectionWriteCallback(string connectionId, int status) { // Don't log for now since this could be *too* verbose. // Reserved: Event ID 12 @@ -120,12 +120,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel _logger.LogError(13, ex, "An unhandled exception was thrown by the application."); } - public virtual void ConnectionError(long connectionId, Exception ex) + public virtual void ConnectionError(string connectionId, Exception ex) { _connectionError(_logger, connectionId, ex); } - public virtual void ConnectionDisconnectedWrite(long connectionId, int count, Exception ex) + public virtual void ConnectionDisconnectedWrite(string connectionId, int count, Exception ex) { _connectionDisconnectedWrite(_logger, connectionId, count, ex); } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServer.cs b/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServer.cs index ead9f9b2da..6d38e3e2b5 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServer.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServer.cs @@ -59,9 +59,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel var trace = new KestrelTrace(_logger); var engine = new KestrelEngine(new ServiceContext { - FrameFactory = (context, remoteEP, localEP, prepareRequest) => + FrameFactory = context => { - return new Frame(application, context, remoteEP, localEP, prepareRequest); + return new Frame(application, context); }, AppLifetime = _applicationLifetime, Log = trace, diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/ServiceContext.cs b/src/Microsoft.AspNetCore.Server.Kestrel/ServiceContext.cs index f702fd1c5e..a591a671ff 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/ServiceContext.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/ServiceContext.cs @@ -34,7 +34,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel public IThreadPool ThreadPool { get; set; } - public Func, Frame> FrameFactory { get; set; } + public Func FrameFactory { get; set; } public DateHeaderValueManager DateHeaderValueManager { get; set; } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/SocketOutputTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/SocketOutputTests.cs index 7162cd0f70..8fa09e4866 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/SocketOutputTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/SocketOutputTests.cs @@ -42,7 +42,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var socket = new MockSocket(kestrelThread.Loop.ThreadId, new TestKestrelTrace()); var trace = new KestrelTrace(new TestKestrelTrace()); var ltp = new LoggingThreadPool(trace); - var socketOutput = new SocketOutput(kestrelThread, socket, memory, new MockConnection(), 0, trace, ltp, new Queue()); + var socketOutput = new SocketOutput(kestrelThread, socket, memory, new MockConnection(), "0", trace, ltp, new Queue()); // I doubt _maxBytesPreCompleted will ever be over a MB. If it is, we should change this test. var bufferSize = 1048576; @@ -93,7 +93,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var socket = new MockSocket(kestrelThread.Loop.ThreadId, new TestKestrelTrace()); var trace = new KestrelTrace(new TestKestrelTrace()); var ltp = new LoggingThreadPool(trace); - var socketOutput = new SocketOutput(kestrelThread, socket, memory, new MockConnection(), 0, trace, ltp, new Queue()); + var socketOutput = new SocketOutput(kestrelThread, socket, memory, new MockConnection(), "0", trace, ltp, new Queue()); var bufferSize = maxBytesPreCompleted; var buffer = new ArraySegment(new byte[bufferSize], 0, bufferSize); @@ -161,7 +161,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var socket = new MockSocket(kestrelThread.Loop.ThreadId, new TestKestrelTrace()); var trace = new KestrelTrace(new TestKestrelTrace()); var ltp = new LoggingThreadPool(trace); - var socketOutput = new SocketOutput(kestrelThread, socket, memory, new MockConnection(), 0, trace, ltp, new Queue()); + var socketOutput = new SocketOutput(kestrelThread, socket, memory, new MockConnection(), "0", trace, ltp, new Queue()); var bufferSize = maxBytesPreCompleted / 2; var data = new byte[bufferSize]; @@ -237,7 +237,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests using (var mockConnection = new MockConnection()) { - ISocketOutput socketOutput = new SocketOutput(kestrelThread, socket, memory, mockConnection, 0, trace, ltp, new Queue()); + ISocketOutput socketOutput = new SocketOutput(kestrelThread, socket, memory, mockConnection, "0", trace, ltp, new Queue()); var bufferSize = maxBytesPreCompleted; @@ -348,7 +348,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests using (var mockConnection = new MockConnection()) { var abortedSource = mockConnection.RequestAbortedSource; - ISocketOutput socketOutput = new SocketOutput(kestrelThread, socket, memory, mockConnection, 0, trace, ltp, new Queue()); + ISocketOutput socketOutput = new SocketOutput(kestrelThread, socket, memory, mockConnection, "0", trace, ltp, new Queue()); var bufferSize = maxBytesPreCompleted; @@ -432,7 +432,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var socket = new MockSocket(kestrelThread.Loop.ThreadId, new TestKestrelTrace()); var trace = new KestrelTrace(new TestKestrelTrace()); var ltp = new LoggingThreadPool(trace); - var socketOutput = new SocketOutput(kestrelThread, socket, memory, new MockConnection(), 0, trace, ltp, new Queue()); + var socketOutput = new SocketOutput(kestrelThread, socket, memory, new MockConnection(), "0", trace, ltp, new Queue()); var bufferSize = maxBytesPreCompleted; var buffer = new ArraySegment(new byte[bufferSize], 0, bufferSize); @@ -518,7 +518,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var socket = new MockSocket(kestrelThread.Loop.ThreadId, new TestKestrelTrace()); var trace = new KestrelTrace(new TestKestrelTrace()); var ltp = new LoggingThreadPool(trace); - var socketOutput = new SocketOutput(kestrelThread, socket, memory, new MockConnection(), 0, trace, ltp, new Queue()); + var socketOutput = new SocketOutput(kestrelThread, socket, memory, new MockConnection(), "0", trace, ltp, new Queue()); // block 1 var start = socketOutput.ProducingStart(); diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestLogger.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/TestLogger.cs index eead43b301..11076560bc 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/TestLogger.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/TestLogger.cs @@ -11,17 +11,17 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } - public override void ConnectionRead(long connectionId, int count) + public override void ConnectionRead(string connectionId, int count) { //_logger.LogDebug(1, @"Connection id ""{ConnectionId}"" recv {count} bytes.", connectionId, count); } - public override void ConnectionWrite(long connectionId, int count) + public override void ConnectionWrite(string connectionId, int count) { //_logger.LogDebug(1, @"Connection id ""{ConnectionId}"" send {count} bytes.", connectionId, count); } - public override void ConnectionWriteCallback(long connectionId, int status) + public override void ConnectionWriteCallback(string connectionId, int status) { //_logger.LogDebug(1, @"Connection id ""{ConnectionId}"" send finished with status {status}.", connectionId, status); } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestServer.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/TestServer.cs index 1c0ff5dd1e..6a84a29fd5 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/TestServer.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/TestServer.cs @@ -39,9 +39,9 @@ namespace Microsoft.AspNetCore.Server.KestrelTests public void Create(RequestDelegate app, ServiceContext context, string serverAddress) { - context.FrameFactory = (connectionContext, remoteEP, localEP, prepareRequest) => + context.FrameFactory = connectionContext => { - return new Frame(new DummyApplication(app), connectionContext, remoteEP, localEP, prepareRequest); + return new Frame(new DummyApplication(app), connectionContext); }; _engine = new KestrelEngine(context); _engine.Start(1); diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestServiceContext.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/TestServiceContext.cs index 743044c2eb..ff08f19714 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/TestServiceContext.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/TestServiceContext.cs @@ -44,9 +44,9 @@ namespace Microsoft.AspNetCore.Server.KestrelTests set { _app = value; - FrameFactory = (connectionContext, remoteEP, localEP, prepareRequest) => + FrameFactory = connectionContext => { - return new Frame(new DummyApplication(_app), connectionContext, remoteEP, localEP, prepareRequest); + return new Frame(new DummyApplication(_app), connectionContext); }; } } From 795bbfce69e6cdb47567e5f04e825fda55c2071b Mon Sep 17 00:00:00 2001 From: "N. Taylor Mullen" Date: Thu, 18 Feb 2016 15:36:17 -0800 Subject: [PATCH 0613/1662] Update System.Linq 4.0.2-* => 4.1.0-*. --- src/Microsoft.AspNetCore.Server.Kestrel/project.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/project.json b/src/Microsoft.AspNetCore.Server.Kestrel/project.json index 864d8a3f26..94811df594 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/project.json +++ b/src/Microsoft.AspNetCore.Server.Kestrel/project.json @@ -35,7 +35,7 @@ "System.Diagnostics.Tracing": "4.1.0-*", "System.Globalization": "4.0.11-*", "System.IO": "4.1.0-*", - "System.Linq": "4.0.2-*", + "System.Linq": "4.1.0-*", "System.Net.Primitives": "4.0.11-*", "System.Runtime.Extensions": "4.1.0-*", "System.Runtime.InteropServices": "4.1.0-*", From e14b86ebe0fc215629e3ae489fbdeeb94354d543 Mon Sep 17 00:00:00 2001 From: Ajay Bhargav Baaskaran Date: Thu, 18 Feb 2016 16:27:55 -0800 Subject: [PATCH 0614/1662] Enabled xml doc generation --- NuGetPackageVerifier.json | 17 ++++------------- .../project.json | 4 +++- .../project.json | 4 +++- 3 files changed, 10 insertions(+), 15 deletions(-) diff --git a/NuGetPackageVerifier.json b/NuGetPackageVerifier.json index a79bd3779c..54c54dd56f 100644 --- a/NuGetPackageVerifier.json +++ b/NuGetPackageVerifier.json @@ -1,25 +1,16 @@ { "adx": { // Packages written by the ADX team and that ship on NuGet.org "rules": [ - "AssemblyHasDocumentFileRule", - "AssemblyHasVersionAttributesRule", - "AssemblyHasServicingAttributeRule", - "AssemblyHasNeutralResourcesLanguageAttributeRule", - "SatellitePackageRule", - "StrictSemanticVersionValidationRule" + "AdxVerificationCompositeRule" ], "packages": { - "Microsoft.AspNetCore.Server.Kestrel": { } + "Microsoft.AspNetCore.Server.Kestrel": { }, + "Microsoft.AspNetCore.Server.Kestrel.Https": { } } }, "Default": { // Rules to run for packages not listed in any other set. "rules": [ - "AssemblyHasDocumentFileRule", - "AssemblyHasVersionAttributesRule", - "AssemblyHasServicingAttributeRule", - "AssemblyHasNeutralResourcesLanguageAttributeRule", - "SatellitePackageRule", - "StrictSemanticVersionValidationRule" + "DefaultCompositeRule" ] } } \ No newline at end of file diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Https/project.json b/src/Microsoft.AspNetCore.Server.Kestrel.Https/project.json index 9b14714e76..3038d7e4b9 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Https/project.json +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Https/project.json @@ -1,7 +1,9 @@ { "version": "1.0.0-*", "compilationOptions": { - "keyFile": "../../tools/Key.snk" + "keyFile": "../../tools/Key.snk", + "nowarn": [ "CS1591" ], + "xmlDoc": true }, "description": "Adds HTTPS support to Kestrel", "repository": { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/project.json b/src/Microsoft.AspNetCore.Server.Kestrel/project.json index 94811df594..65fe9a1238 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/project.json +++ b/src/Microsoft.AspNetCore.Server.Kestrel/project.json @@ -51,7 +51,9 @@ }, "compilationOptions": { "allowUnsafe": true, - "keyFile": "../../tools/Key.snk" + "keyFile": "../../tools/Key.snk", + "nowarn": [ "CS1591" ], + "xmlDoc": true }, "packInclude": { "/": "../../content/thirdpartynotices.txt", From 99ccae64eb404377d5c5ba8e65971f7314d120dd Mon Sep 17 00:00:00 2001 From: John Luo Date: Thu, 18 Feb 2016 16:00:59 -0800 Subject: [PATCH 0615/1662] Updating test TFMs for custom test discovery --- .../project.json | 2 +- .../HttpsConnectionFilterTests.cs | 20 +++++++++---------- .../NetworkingTests.cs | 6 +++--- .../project.json | 2 +- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json index 0f4db08fdb..9c290eab05 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json @@ -15,7 +15,7 @@ }, "imports": "portable-net451+win8" }, - "dnx451": { + "net451": { "dependencies": { "xunit.runner.console": "2.1.0" } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/HttpsConnectionFilterTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/HttpsConnectionFilterTests.cs index 3758a54fc3..4d0d86a34d 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/HttpsConnectionFilterTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/HttpsConnectionFilterTests.cs @@ -51,7 +51,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests try { -#if DNX451 +#if NET451 var handler = new HttpClientHandler(); ServicePointManager.ServerCertificateValidationCallback += validationCallback; #else @@ -79,7 +79,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } finally { -#if DNX451 +#if NET451 ServicePointManager.ServerCertificateValidationCallback -= validationCallback; #endif } @@ -97,7 +97,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests try { -#if DNX451 +#if NET451 var handler = new HttpClientHandler(); ServicePointManager.ServerCertificateValidationCallback += validationCallback; #else @@ -126,7 +126,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } finally { -#if DNX451 +#if NET451 ServicePointManager.ServerCertificateValidationCallback -= validationCallback; #endif } @@ -144,7 +144,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests try { -#if DNX451 +#if NET451 var handler = new HttpClientHandler(); ServicePointManager.ServerCertificateValidationCallback += validationCallback; #else @@ -180,7 +180,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } finally { -#if DNX451 +#if NET451 ServicePointManager.ServerCertificateValidationCallback -= validationCallback; #endif } @@ -198,7 +198,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests try { -#if DNX451 +#if NET451 ServicePointManager.ServerCertificateValidationCallback += validationCallback; #endif @@ -246,7 +246,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } finally { -#if DNX451 +#if NET451 ServicePointManager.ServerCertificateValidationCallback -= validationCallback; #endif } @@ -264,7 +264,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests try { -#if DNX451 +#if NET451 var handler = new HttpClientHandler(); ServicePointManager.ServerCertificateValidationCallback += validationCallback; #else @@ -296,7 +296,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } finally { -#if DNX451 +#if NET451 ServicePointManager.ServerCertificateValidationCallback -= validationCallback; #endif } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/NetworkingTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/NetworkingTests.cs index 4a438f5c78..33ff9b70d9 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/NetworkingTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/NetworkingTests.cs @@ -129,7 +129,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var t = Task.Run(async () => { var socket = TestConnection.CreateConnectedLoopbackSocket(port); -#if DNX451 +#if NET451 await Task.Factory.FromAsync( socket.BeginSend, socket.EndSend, @@ -204,7 +204,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var t = Task.Run(async () => { var socket = TestConnection.CreateConnectedLoopbackSocket(port); -#if DNX451 +#if NET451 await Task.Factory.FromAsync( socket.BeginSend, socket.EndSend, @@ -220,7 +220,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var buffer = new ArraySegment(new byte[2048]); while (true) { -#if DNX451 +#if NET451 var count = await Task.Factory.FromAsync( socket.BeginReceive, socket.EndReceive, diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/project.json b/test/Microsoft.AspNetCore.Server.KestrelTests/project.json index 1d079264a8..91918db4a0 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/project.json +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/project.json @@ -21,7 +21,7 @@ }, "imports": "portable-net451+win8" }, - "dnx451": { + "net451": { "dependencies": { "xunit.runner.console": "2.1.0" } From 58e07a8b2ba4f86b752c83cd8462ce5570b4ea4e Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Fri, 19 Feb 2016 21:20:00 +0000 Subject: [PATCH 0616/1662] Put threads into background before starting --- .../Infrastructure/KestrelThread.cs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/KestrelThread.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/KestrelThread.cs index 5b7d998f8e..d8cb804fbb 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/KestrelThread.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/KestrelThread.cs @@ -52,6 +52,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel _post = new UvAsyncHandle(_log); _thread = new Thread(ThreadStart); _thread.Name = "KestrelThread - libuv"; +#if !DEBUG + // Mark the thread as being as unimportant to keeping the process alive. + // Don't do this for debug builds, so we know if the thread isn't terminating. + _thread.IsBackground = true; +#endif QueueCloseHandle = PostCloseHandle; QueueCloseAsyncHandle = EnqueueCloseHandle; } @@ -79,12 +84,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel public void Stop(TimeSpan timeout) { -#if !DEBUG - // Mark the thread as being as unimportant to keeping the process alive. - // Don't do this for debug builds, so we know if the thread isn't terminating. - _thread.IsBackground = true; -#endif - if (!_initCompleted) { return; From f6d0443692106abced8c0bda8e12cbe80fe0348b Mon Sep 17 00:00:00 2001 From: BrennanConroy Date: Mon, 22 Feb 2016 16:01:24 -0800 Subject: [PATCH 0617/1662] Add build references to tests because they don't flow up to parent anymore. See:https://github.com/NuGet/Home/issues/2153 --- .../project.json | 10 +++++++++- .../project.json | 10 +++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json index 9c290eab05..5a2e28ed55 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json @@ -6,7 +6,15 @@ "Microsoft.AspNetCore.Testing": "1.0.0-*", "Microsoft.NETCore.Platforms": "1.0.1-*", "System.Net.Http": "4.0.1-*", - "xunit": "2.1.0" + "xunit": "2.1.0", + "Microsoft.AspNetCore.Internal.libuv-Darwin": { + "version": "1.0.0-*", + "type": "build" + }, + "Microsoft.AspNetCore.Internal.libuv-Windows": { + "version": "1.0.0-*", + "type": "build" + } }, "frameworks": { "dnxcore50": { diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/project.json b/test/Microsoft.AspNetCore.Server.KestrelTests/project.json index 91918db4a0..5dd70ca224 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/project.json +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/project.json @@ -6,7 +6,15 @@ "Microsoft.AspNetCore.Testing": "1.0.0-*", "Microsoft.NETCore.Platforms": "1.0.1-*", "System.Net.Http": "4.0.1-*", - "xunit": "2.1.0" + "xunit": "2.1.0", + "Microsoft.AspNetCore.Internal.libuv-Darwin": { + "version": "1.0.0-*", + "type": "build" + }, + "Microsoft.AspNetCore.Internal.libuv-Windows": { + "version": "1.0.0-*", + "type": "build" + } }, "frameworks": { "dnxcore50": { From a23ab5bd22cce14eb9a31d8c9bd10a3ba8a96b72 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Sun, 21 Feb 2016 11:18:45 +0000 Subject: [PATCH 0618/1662] Parallel on Appveyor --- appveyor.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index 265df8f1f5..636a7618d3 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -4,6 +4,4 @@ build_script: - build.cmd --quiet verify clone_depth: 1 test: off -deploy: off -environment: - NO_PARALLEL_TEST_PROJECTS: Microsoft.AspNetCore.Server.Kestrel.FunctionalTests \ No newline at end of file +deploy: off \ No newline at end of file From c2e5124d5addfddeab8c1898d3f938a5cb8018a8 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Sun, 21 Feb 2016 12:34:51 +0000 Subject: [PATCH 0619/1662] Fix XML Comment --- .../Infrastructure/MemoryPoolIterator2Extensions.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPoolIterator2Extensions.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPoolIterator2Extensions.cs index 70dc2cf8fc..7581ff35f2 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPoolIterator2Extensions.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPoolIterator2Extensions.cs @@ -331,7 +331,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure /// /// The iterator from which to start the known string lookup. /// If we found a valid method, then scan will be updated to new position - /// A reference to a pre-allocated known string, if the input matches any. + /// A reference to a pre-allocated known string, if the input matches any. /// true if the input matches a known string, false otherwise. public static bool GetKnownVersion(this MemoryPoolIterator2 begin, ref MemoryPoolIterator2 scan, out string knownVersion) { From 638380b0bba9b4a6d2d8a5695fc3a5147460e779 Mon Sep 17 00:00:00 2001 From: BrennanConroy Date: Tue, 23 Feb 2016 08:34:55 -0800 Subject: [PATCH 0620/1662] Fix samples as well --- samples/LargeResponseApp/project.json | 8 ++++++++ samples/SampleApp/project.json | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/samples/LargeResponseApp/project.json b/samples/LargeResponseApp/project.json index 1d4253e603..b6aa0ce9e4 100644 --- a/samples/LargeResponseApp/project.json +++ b/samples/LargeResponseApp/project.json @@ -1,6 +1,14 @@ { "version": "1.0.0-*", "dependencies": { + "Microsoft.AspNetCore.Internal.libuv-Darwin": { + "version": "1.0.0-*", + "type": "build" + }, + "Microsoft.AspNetCore.Internal.libuv-Windows": { + "version": "1.0.0-*", + "type": "build" + }, "Microsoft.AspNetCore.Server.Kestrel": "1.0.0-*" }, "compilationOptions": { diff --git a/samples/SampleApp/project.json b/samples/SampleApp/project.json index d6f84d15a2..6a1bc65da8 100644 --- a/samples/SampleApp/project.json +++ b/samples/SampleApp/project.json @@ -1,6 +1,14 @@ { "version": "1.0.0-*", "dependencies": { + "Microsoft.AspNetCore.Internal.libuv-Darwin": { + "version": "1.0.0-*", + "type": "build" + }, + "Microsoft.AspNetCore.Internal.libuv-Windows": { + "version": "1.0.0-*", + "type": "build" + }, "Microsoft.AspNetCore.Server.Kestrel": "1.0.0-*", "Microsoft.AspNetCore.Server.Kestrel.Https": "1.0.0-*", "Microsoft.Extensions.Logging.Console": "1.0.0-*" From d83ad64ad6a007e55b623b407be2e42c06c91051 Mon Sep 17 00:00:00 2001 From: Doug Bunting Date: Wed, 24 Feb 2016 12:48:16 -0800 Subject: [PATCH 0621/1662] Update `build.cmd` to match latest template - aspnet/Universe#347 - `%KOREBUILD_VERSION%` doesn't work without this fix --- build.cmd | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/build.cmd b/build.cmd index ebb619e737..95b049cf63 100644 --- a/build.cmd +++ b/build.cmd @@ -2,7 +2,7 @@ SETLOCAL SET REPO_FOLDER=%~dp0 -CD %REPO_FOLDER% +CD "%REPO_FOLDER%" SET BUILD_FOLDER=.build SET KOREBUILD_FOLDER=%BUILD_FOLDER%\KoreBuild-dotnet @@ -28,12 +28,11 @@ IF NOT EXIST %NUGET_PATH% ( copy %CACHED_NUGET% %NUGET_PATH% > nul ) +SET KOREBUILD_DOWNLOAD_ARGS= +IF NOT "%KOREBUILD_VERSION%"=="" ( + SET KOREBUILD_DOWNLOAD_ARGS=-version %KOREBUILD_VERSION% +) IF NOT EXIST %KOREBUILD_FOLDER% ( - SET KOREBUILD_DOWNLOAD_ARGS= - IF NOT "%KOREBUILD_VERSION%"=="" ( - SET KOREBUILD_DOWNLOAD_ARGS=-version %KOREBUILD_VERSION% - ) - %BUILD_FOLDER%\nuget.exe install KoreBuild-dotnet -ExcludeVersion -o %BUILD_FOLDER% -nocache -pre %KOREBUILD_DOWNLOAD_ARGS% ) From 37055517eec452e0aaec5f08ae6010c99ac3fdd0 Mon Sep 17 00:00:00 2001 From: Doug Bunting Date: Wed, 24 Feb 2016 22:35:20 -0800 Subject: [PATCH 0622/1662] Correct test attributes - #654 - `[IPv6SupportedCondition]` requires `[ConditionalFact]` or `[ConditionalTheory]` --- .../AddressRegistrationTests.cs | 3 ++- .../RequestTests.cs | 8 ++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs index 9b2689c00a..6a65cb71f9 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs @@ -8,6 +8,7 @@ using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http.Extensions; +using Microsoft.AspNetCore.Testing.xunit; using Microsoft.Extensions.Configuration; using Xunit; @@ -21,7 +22,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests await RegisterAddresses_Success(addressInput, testUrls); } - [Theory, MemberData(nameof(AddressRegistrationDataIPv6))] + [ConditionalTheory, MemberData(nameof(AddressRegistrationDataIPv6))] [IPv6SupportedCondition] public async Task RegisterAddresses_IPv6_Success(string addressInput, string[] testUrls) { diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs index cdeeccca4f..5c73e751f2 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs @@ -3,7 +3,6 @@ using System.Collections.Generic; using System.Globalization; -using System.Net; using System.Net.Http; using System.Net.Sockets; using System.Text; @@ -11,6 +10,7 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Testing.xunit; using Microsoft.Extensions.Configuration; using Newtonsoft.Json; using Newtonsoft.Json.Linq; @@ -84,7 +84,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests return TestRemoteIPAddress("localhost", requestAddress, expectAddress); } - [Fact] + [ConditionalFact] [IPv6SupportedCondition] public Task RemoteIPv6Address() { @@ -166,10 +166,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { break; } - + response.Append(Encoding.ASCII.GetString(buffer, 0, length)); } - + Assert.StartsWith("HTTP/1.1 200 OK", response.ToString()); } } From e579745f93db065f8320f25055b6f860af3fd5d6 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Sun, 21 Feb 2016 12:37:50 +0000 Subject: [PATCH 0623/1662] System.Net.Http references --- .../project.json | 7 +++++-- test/Microsoft.AspNetCore.Server.KestrelTests/project.json | 5 ++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json index 5a2e28ed55..cf00be722c 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json @@ -5,7 +5,6 @@ "Microsoft.AspNetCore.Server.Kestrel": "1.0.0-*", "Microsoft.AspNetCore.Testing": "1.0.0-*", "Microsoft.NETCore.Platforms": "1.0.1-*", - "System.Net.Http": "4.0.1-*", "xunit": "2.1.0", "Microsoft.AspNetCore.Internal.libuv-Darwin": { "version": "1.0.0-*", @@ -19,13 +18,17 @@ "frameworks": { "dnxcore50": { "dependencies": { - "dotnet-test-xunit": "1.0.0-dev-*" + "dotnet-test-xunit": "1.0.0-dev-*", + "System.Net.Http": "4.0.1-*" }, "imports": "portable-net451+win8" }, "net451": { "dependencies": { "xunit.runner.console": "2.1.0" + }, + "frameworkAssemblies": { + "System.Net.Http": "4.0.0.0" } } }, diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/project.json b/test/Microsoft.AspNetCore.Server.KestrelTests/project.json index 5dd70ca224..aca952eb04 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/project.json +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/project.json @@ -5,7 +5,6 @@ "Microsoft.AspNetCore.Server.Kestrel.Https": "1.0.0-*", "Microsoft.AspNetCore.Testing": "1.0.0-*", "Microsoft.NETCore.Platforms": "1.0.1-*", - "System.Net.Http": "4.0.1-*", "xunit": "2.1.0", "Microsoft.AspNetCore.Internal.libuv-Darwin": { "version": "1.0.0-*", @@ -22,6 +21,7 @@ "System.Diagnostics.TraceSource": "4.0.0-*", "System.Globalization.Extensions": "4.0.1-*", "System.IO": "4.1.0-*", + "System.Net.Http": "4.0.1-*", "System.Net.Http.WinHttpHandler": "4.0.0-*", "System.Net.Sockets": "4.1.0-*", "System.Runtime.Handles": "4.0.1-*", @@ -32,6 +32,9 @@ "net451": { "dependencies": { "xunit.runner.console": "2.1.0" + }, + "frameworkAssemblies": { + "System.Net.Http": "4.0.0.0" } } }, From f21cb128e828053b86e033173d5921f9bd89ee3b Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Thu, 18 Feb 2016 15:48:13 -0800 Subject: [PATCH 0624/1662] Handle 0-byte reads correctly (#520). --- .../Http/Connection.cs | 16 +++++-- .../Http/SocketInput.cs | 16 +++++++ .../ConnectionTests.cs | 46 +++++++++++++++++++ .../SocketOutputTests.cs | 32 +++---------- .../TestHelpers/MockLibuv.cs | 19 ++++++++ .../TestHelpers/MockSocket.cs | 21 +++++++++ 6 files changed, 122 insertions(+), 28 deletions(-) create mode 100644 test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionTests.cs create mode 100644 test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockSocket.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Connection.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Connection.cs index 3cc06e8521..c0de2ed3b3 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Connection.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Connection.cs @@ -16,9 +16,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http // Base32 encoding - in ascii sort order for easy text based sorting private static readonly string _encode32Chars = "0123456789ABCDEFGHIJKLMNOPQRSTUV"; - private static readonly Action _readCallback = + private static readonly Action _readCallback = (handle, status, state) => ReadCallback(handle, status, state); - private static readonly Func _allocCallback = + private static readonly Func _allocCallback = (handle, suggestedsize, state) => AllocCallback(handle, suggestedsize, state); // Seed the _lastConnectionId for this application instance with @@ -252,8 +252,18 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http private void OnRead(UvStreamHandle handle, int status) { + if (status == 0) + { + // A zero status does not indicate an error or connection end. It indicates + // there is no data to be read right now. + // See the note at http://docs.libuv.org/en/v1.x/stream.html#c.uv_read_cb. + // We need to clean up whatever was allocated by OnAlloc. + _rawSocketInput.IncomingDeferred(); + return; + } + var normalRead = status > 0; - var normalDone = status == 0 || status == Constants.ECONNRESET || status == Constants.EOF; + var normalDone = status == Constants.ECONNRESET || status == Constants.EOF; var errorDone = !(normalDone || normalRead); var readCount = normalRead ? status : 0; diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketInput.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketInput.cs index d5803f0698..a534fe9261 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketInput.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketInput.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Diagnostics; using System.IO; using System.Runtime.CompilerServices; using System.Threading; @@ -117,6 +118,21 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http Complete(); } + public void IncomingDeferred() + { + Debug.Assert(_pinned != null); + + if (_pinned != null) + { + if (_pinned != _tail) + { + _memory.Return(_pinned); + } + + _pinned = null; + } + } + private void Complete() { var awaitableState = Interlocked.Exchange( diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionTests.cs new file mode 100644 index 0000000000..203a807267 --- /dev/null +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionTests.cs @@ -0,0 +1,46 @@ +using System.Threading; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Server.Kestrel; +using Microsoft.AspNetCore.Server.Kestrel.Http; +using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Networking; +using Microsoft.AspNetCore.Server.KestrelTests.TestHelpers; +using Xunit; + +namespace Microsoft.AspNetCore.Server.KestrelTests +{ + public class ConnectionTests + { + [Fact] + public void DoesNotEndConnectionOnZeroRead() + { + var mockLibuv = new MockLibuv(); + + using (var memory = new MemoryPool2()) + using (var engine = new KestrelEngine(mockLibuv, new TestServiceContext())) + { + engine.Start(count: 1); + + var trace = new TestKestrelTrace(); + var context = new ListenerContext(new TestServiceContext()) + { + FrameFactory = connectionContext => new Frame( + new DummyApplication(httpContext => TaskUtilities.CompletedTask), connectionContext), + Memory2 = memory, + ServerAddress = ServerAddress.FromUrl($"http://localhost:{TestServer.GetNextPort()}"), + Thread = engine.Threads[0] + }; + var socket = new MockSocket(mockLibuv, Thread.CurrentThread.ManagedThreadId, trace); + var connection = new Connection(context, socket); + connection.Start(); + + Libuv.uv_buf_t ignored; + mockLibuv.AllocCallback(socket.InternalGetHandle(), 2048, out ignored); + mockLibuv.ReadCallback(socket.InternalGetHandle(), 0, ref ignored); + Assert.False(connection.SocketInput.RemoteIntakeFin); + + connection.ConnectionControl.End(ProduceEndType.SocketDisconnect); + } + } + } +} diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/SocketOutputTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/SocketOutputTests.cs index 8fa09e4866..f0132e0c82 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/SocketOutputTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/SocketOutputTests.cs @@ -39,7 +39,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests kestrelEngine.Start(count: 1); var kestrelThread = kestrelEngine.Threads[0]; - var socket = new MockSocket(kestrelThread.Loop.ThreadId, new TestKestrelTrace()); + var socket = new MockSocket(mockLibuv, kestrelThread.Loop.ThreadId, new TestKestrelTrace()); var trace = new KestrelTrace(new TestKestrelTrace()); var ltp = new LoggingThreadPool(trace); var socketOutput = new SocketOutput(kestrelThread, socket, memory, new MockConnection(), "0", trace, ltp, new Queue()); @@ -90,7 +90,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests kestrelEngine.Start(count: 1); var kestrelThread = kestrelEngine.Threads[0]; - var socket = new MockSocket(kestrelThread.Loop.ThreadId, new TestKestrelTrace()); + var socket = new MockSocket(mockLibuv, kestrelThread.Loop.ThreadId, new TestKestrelTrace()); var trace = new KestrelTrace(new TestKestrelTrace()); var ltp = new LoggingThreadPool(trace); var socketOutput = new SocketOutput(kestrelThread, socket, memory, new MockConnection(), "0", trace, ltp, new Queue()); @@ -158,7 +158,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests kestrelEngine.Start(count: 1); var kestrelThread = kestrelEngine.Threads[0]; - var socket = new MockSocket(kestrelThread.Loop.ThreadId, new TestKestrelTrace()); + var socket = new MockSocket(mockLibuv, kestrelThread.Loop.ThreadId, new TestKestrelTrace()); var trace = new KestrelTrace(new TestKestrelTrace()); var ltp = new LoggingThreadPool(trace); var socketOutput = new SocketOutput(kestrelThread, socket, memory, new MockConnection(), "0", trace, ltp, new Queue()); @@ -231,7 +231,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests kestrelEngine.Start(count: 1); var kestrelThread = kestrelEngine.Threads[0]; - var socket = new MockSocket(kestrelThread.Loop.ThreadId, new TestKestrelTrace()); + var socket = new MockSocket(mockLibuv, kestrelThread.Loop.ThreadId, new TestKestrelTrace()); var trace = new KestrelTrace(new TestKestrelTrace()); var ltp = new LoggingThreadPool(trace); @@ -341,7 +341,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests kestrelEngine.Start(count: 1); var kestrelThread = kestrelEngine.Threads[0]; - var socket = new MockSocket(kestrelThread.Loop.ThreadId, new TestKestrelTrace()); + var socket = new MockSocket(mockLibuv, kestrelThread.Loop.ThreadId, new TestKestrelTrace()); var trace = new KestrelTrace(new TestKestrelTrace()); var ltp = new LoggingThreadPool(trace); @@ -429,7 +429,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests kestrelEngine.Start(count: 1); var kestrelThread = kestrelEngine.Threads[0]; - var socket = new MockSocket(kestrelThread.Loop.ThreadId, new TestKestrelTrace()); + var socket = new MockSocket(mockLibuv, kestrelThread.Loop.ThreadId, new TestKestrelTrace()); var trace = new KestrelTrace(new TestKestrelTrace()); var ltp = new LoggingThreadPool(trace); var socketOutput = new SocketOutput(kestrelThread, socket, memory, new MockConnection(), "0", trace, ltp, new Queue()); @@ -515,7 +515,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests kestrelEngine.Start(count: 1); var kestrelThread = kestrelEngine.Threads[0]; - var socket = new MockSocket(kestrelThread.Loop.ThreadId, new TestKestrelTrace()); + var socket = new MockSocket(mockLibuv, kestrelThread.Loop.ThreadId, new TestKestrelTrace()); var trace = new KestrelTrace(new TestKestrelTrace()); var ltp = new LoggingThreadPool(trace); var socketOutput = new SocketOutput(kestrelThread, socket, memory, new MockConnection(), "0", trace, ltp, new Queue()); @@ -544,23 +544,5 @@ namespace Microsoft.AspNetCore.Server.KestrelTests default(ArraySegment), default(CancellationToken), socketDisconnect: true); } } - - - private class MockSocket : UvStreamHandle - { - public MockSocket(int threadId, IKestrelTrace logger) : base(logger) - { - // Set the handle to something other than IntPtr.Zero - // so handle.Validate doesn't fail in Libuv.write - handle = (IntPtr)1; - _threadId = threadId; - } - - protected override bool ReleaseHandle() - { - // No-op - return true; - } - } } } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockLibuv.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockLibuv.cs index 2f2f2f1103..745a3eca11 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockLibuv.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockLibuv.cs @@ -17,6 +17,12 @@ namespace Microsoft.AspNetCore.Server.KestrelTests.TestHelpers unsafe public MockLibuv() : base(onlyForTesting: true) { + _onWrite = (socket, buffers, triggerCompleted) => + { + triggerCompleted(0); + return 0; + }; + _uv_write = UvWrite; _uv_async_send = postHandle => @@ -69,6 +75,8 @@ namespace Microsoft.AspNetCore.Server.KestrelTests.TestHelpers _uv_walk = (loop, callback, ignore) => 0; _uv_err_name = errno => IntPtr.Zero; _uv_strerror = errno => IntPtr.Zero; + _uv_read_start = UvReadStart; + _uv_read_stop = handle => 0; } public Func, int> OnWrite @@ -83,6 +91,17 @@ namespace Microsoft.AspNetCore.Server.KestrelTests.TestHelpers } } + public uv_alloc_cb AllocCallback { get; set; } + + public uv_read_cb ReadCallback { get; set; } + + private int UvReadStart(UvStreamHandle handle, uv_alloc_cb allocCallback, uv_read_cb readCallback) + { + AllocCallback = allocCallback; + ReadCallback = readCallback; + return 0; + } + unsafe private int UvWrite(UvRequest req, UvStreamHandle handle, uv_buf_t* bufs, int nbufs, uv_write_cb cb) { return _onWrite(handle, nbufs, status => cb(req.InternalGetHandle(), status)); diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockSocket.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockSocket.cs new file mode 100644 index 0000000000..4e41590dd9 --- /dev/null +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockSocket.cs @@ -0,0 +1,21 @@ +using System; +using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Networking; + +namespace Microsoft.AspNetCore.Server.KestrelTests.TestHelpers +{ + class MockSocket : UvStreamHandle + { + public MockSocket(Libuv uv, int threadId, IKestrelTrace logger) : base(logger) + { + CreateMemory(uv, threadId, IntPtr.Size); + } + + protected override bool ReleaseHandle() + { + DestroyMemory(handle); + handle = IntPtr.Zero; + return true; + } + } +} From 8d8176f14a11b8df95ccfd043e1610f397744f86 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Mon, 8 Feb 2016 05:18:21 +0000 Subject: [PATCH 0625/1662] Consume chunked request fully --- .../Http/MessageBody.cs | 222 +++++++++++++----- .../EngineTests.cs | 16 +- 2 files changed, 175 insertions(+), 63 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/MessageBody.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/MessageBody.cs index 2731ec42a6..9bb6f0db79 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/MessageBody.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/MessageBody.cs @@ -222,75 +222,155 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { var input = _context.SocketInput; - while (_mode != Mode.Complete) + while (_mode != Mode.Trailer && _mode != Mode.Complete) { while (_mode == Mode.ChunkPrefix) { - var chunkSize = 0; - if (!TakeChunkedLine(input, ref chunkSize)) - { - await input; - } - else if (chunkSize == 0) - { - _mode = Mode.Complete; - } - else - { - _mode = Mode.ChunkData; - } - _inputLength = chunkSize; + ReadChunkedPrefix(input); + await input; } + while (_mode == Mode.ChunkData) { - var limit = buffer.Array == null ? _inputLength : Math.Min(buffer.Count, _inputLength); - if (limit != 0) - { - await input; - } - - var begin = input.ConsumingStart(); - int actual; - var end = begin.CopyTo(buffer.Array, buffer.Offset, limit, out actual); - _inputLength -= actual; - input.ConsumingComplete(end, end); - - if (_inputLength == 0) - { - _mode = Mode.ChunkSuffix; - } + int actual = ReadChunkedData(input, buffer.Array, buffer.Offset, buffer.Count); if (actual != 0) { return actual; } + + await input; } + while (_mode == Mode.ChunkSuffix) { - var scan = input.ConsumingStart(); - var consumed = scan; - var ch1 = scan.Take(); - var ch2 = scan.Take(); - if (ch1 == -1 || ch2 == -1) - { - input.ConsumingComplete(consumed, scan); - await input; - } - else if (ch1 == '\r' && ch2 == '\n') - { - input.ConsumingComplete(scan, scan); - _mode = Mode.ChunkPrefix; - } - else - { - throw new NotImplementedException("INVALID REQUEST FORMAT"); - } + ReadChunkedSuffix(input); + await input; } } + while (_mode == Mode.Trailer) + { + ReadChunkedTrailer(input); + await input; + } + return 0; } - private static bool TakeChunkedLine(SocketInput baton, ref int chunkSizeOut) + private void ReadChunkedPrefix(SocketInput input) + { + int chunkSize; + if (TakeChunkedLine(input, out chunkSize)) + { + if (chunkSize == 0) + { + _mode = Mode.Trailer; + } + else + { + _mode = Mode.ChunkData; + } + _inputLength = chunkSize; + } + else if (input.RemoteIntakeFin) + { + ThrowChunkedRequestIncomplete(); + } + } + + private int ReadChunkedData(SocketInput input, byte[] buffer, int offset, int count) + { + var scan = input.ConsumingStart(); + int actual; + try + { + var limit = buffer == null ? _inputLength : Math.Min(count, _inputLength); + scan = scan.CopyTo(buffer, offset, limit, out actual); + _inputLength -= actual; + } + finally + { + input.ConsumingComplete(scan, scan); + } + + if (_inputLength == 0) + { + _mode = Mode.ChunkSuffix; + } + else if (actual == 0 && input.RemoteIntakeFin) + { + ThrowChunkedRequestIncomplete(); + } + + return actual; + } + + private void ReadChunkedSuffix(SocketInput input) + { + var scan = input.ConsumingStart(); + var consumed = scan; + try + { + var ch1 = scan.Take(); + var ch2 = scan.Take(); + + if (ch1 == '\r' && ch2 == '\n') + { + consumed = scan; + _mode = Mode.ChunkPrefix; + } + else if (ch1 == -1 || ch2 == -1) + { + if (input.RemoteIntakeFin) + { + ThrowChunkedRequestIncomplete(); + } + } + else + { + ThrowInvalidFormat(); + } + } + finally + { + input.ConsumingComplete(consumed, scan); + } + } + + private void ReadChunkedTrailer(SocketInput input) + { + var scan = input.ConsumingStart(); + var consumed = scan; + try + { + var ch1 = scan.Take(); + var ch2 = scan.Take(); + + if (ch1 == '\r' && ch2 == '\n') + { + consumed = scan; + _mode = Mode.Complete; + } + else if (ch1 == -1 || ch2 == -1) + { + if (input.RemoteIntakeFin) + { + ThrowChunkedRequestIncomplete(); + } + } + else + { + // Post request headers + ThrowTrailingHeadersNotSupported(); + } + } + finally + { + input.ConsumingComplete(consumed, scan); + } + } + + private static bool TakeChunkedLine(SocketInput baton, out int chunkSizeOut) { var scan = baton.ConsumingStart(); var consumed = scan; @@ -298,16 +378,17 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { var ch0 = scan.Take(); var chunkSize = 0; - var mode = 0; + var mode = Mode.ChunkPrefix; while (ch0 != -1) { var ch1 = scan.Take(); if (ch1 == -1) { + chunkSizeOut = 0; return false; } - if (mode == 0) + if (mode == Mode.ChunkPrefix) { if (ch0 >= '0' && ch0 <= '9') { @@ -323,11 +404,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } else { - throw new NotImplementedException("INVALID REQUEST FORMAT"); + ThrowInvalidFormat(); } - mode = 1; + mode = Mode.ChunkData; } - else if (mode == 1) + else if (mode == Mode.ChunkData) { if (ch0 >= '0' && ch0 <= '9') { @@ -343,7 +424,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } else if (ch0 == ';') { - mode = 2; + mode = Mode.ChunkSuffix; } else if (ch0 == '\r' && ch1 == '\n') { @@ -353,10 +434,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } else { - throw new NotImplementedException("INVALID REQUEST FORMAT"); + ThrowInvalidFormat(); } } - else if (mode == 2) + else if (mode == Mode.ChunkSuffix) { if (ch0 == '\r' && ch1 == '\n') { @@ -367,11 +448,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http else { // chunk-extensions not currently parsed + ThrowChunkedExtensionsNotSupported(); } } ch0 = ch1; } + chunkSizeOut = 0; return false; } finally @@ -380,12 +463,33 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } + private static void ThrowInvalidFormat() + { + throw new InvalidOperationException("Bad Request"); + } + + private static void ThrowChunkedRequestIncomplete() + { + throw new InvalidOperationException("Chunked request incomplete"); + } + + private static void ThrowChunkedExtensionsNotSupported() + { + throw new NotImplementedException("Chunked-extensions not supported"); + } + + private static void ThrowTrailingHeadersNotSupported() + { + throw new NotImplementedException("Trailing headers not supported"); + } + private enum Mode { ChunkPrefix, ChunkData, ChunkSuffix, - Complete, + Trailer, + Complete }; } } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs index 51b2cae261..c91e4488e0 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs @@ -290,11 +290,14 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { using (var connection = new TestConnection(server.Port)) { - await connection.Send( + await connection.SendEnd( "POST / HTTP/1.0", "Transfer-Encoding: chunked", "", - "5", "Hello", "6", " World", "0\r\n"); + "5", "Hello", + "6", " World", + "0", + ""); await connection.ReceiveEnd( "HTTP/1.0 200 OK", "", @@ -406,7 +409,10 @@ namespace Microsoft.AspNetCore.Server.KestrelTests "Transfer-Encoding: chunked", "Connection: keep-alive", "", - "5", "Hello", "6", " World", "0", + "5", "Hello", + "6", " World", + "0", + "", "POST / HTTP/1.0", "", "Goodbye"); @@ -969,7 +975,9 @@ namespace Microsoft.AspNetCore.Server.KestrelTests "HelloPOST / HTTP/1.1", "Transfer-Encoding: chunked", "", - "C", "HelloChunked", "0", + "C", "HelloChunked", + "0", + "", "POST / HTTP/1.1", "Content-Length: 7", "", From e0f7bb06dda81b3843f542202889951bc7c2a775 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Wed, 10 Feb 2016 04:29:57 +0000 Subject: [PATCH 0626/1662] Parse chunked trailing headers --- .../Http/MessageBody.cs | 33 +++++++++++++++++-- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/MessageBody.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/MessageBody.cs index 9bb6f0db79..9fa51ed40e 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/MessageBody.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/MessageBody.cs @@ -205,7 +205,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http private class ForChunkedEncoding : MessageBody { private int _inputLength; - private Mode _mode = Mode.ChunkPrefix; public ForChunkedEncoding(bool keepAlive, FrameContext context) @@ -251,7 +250,26 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http while (_mode == Mode.Trailer) { ReadChunkedTrailer(input); - await input; + + if (_mode != Mode.Complete && _mode != Mode.TrailerHeaders) + { + await input; + } + } + + if (_mode == Mode.TrailerHeaders) + { + // Take trailer headers + var frame = (Frame)_context; + while (!Frame.TakeMessageHeaders(input, frame._requestHeaders)) + { + if (input.RemoteIntakeFin) + { + ThrowChunkedRequestIncomplete(); + } + + await input; + } } return 0; @@ -270,6 +288,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { _mode = Mode.ChunkData; } + _inputLength = chunkSize; } else if (input.RemoteIntakeFin) @@ -361,7 +380,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http else { // Post request headers - ThrowTrailingHeadersNotSupported(); + if (_context is Frame) + { + _mode = Mode.TrailerHeaders; + } + else + { + ThrowTrailingHeadersNotSupported(); + } } } finally @@ -489,6 +515,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ChunkData, ChunkSuffix, Trailer, + TrailerHeaders, Complete }; } From 331d4a87acd218fb8c5cffeb203a7cddd55bb88e Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Wed, 10 Feb 2016 05:19:10 +0000 Subject: [PATCH 0627/1662] Move chunked request tests --- .../ChunkedRequestTests.cs | 288 ++++++++++++++++++ .../EngineTests.cs | 107 ------- 2 files changed, 288 insertions(+), 107 deletions(-) create mode 100644 test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedRequestTests.cs diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedRequestTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedRequestTests.cs new file mode 100644 index 0000000000..49cfc2a2e9 --- /dev/null +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedRequestTests.cs @@ -0,0 +1,288 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Server.Kestrel; +using Microsoft.AspNetCore.Server.Kestrel.Filter; +using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; +using Microsoft.AspNetCore.Testing.xunit; +using Microsoft.Extensions.Logging; +using Xunit; + +namespace Microsoft.AspNetCore.Server.KestrelTests +{ + public class ChunkedRequestTests + { + public static TheoryData ConnectionFilterData + { + get + { + return new TheoryData + { + { + new TestServiceContext() + }, + { + new TestServiceContext(new PassThroughConnectionFilter()) + } + }; + } + } + + private async Task App(HttpContext httpContext) + { + var request = httpContext.Request; + var response = httpContext.Response; + response.Headers.Clear(); + while (true) + { + var buffer = new byte[8192]; + var count = await request.Body.ReadAsync(buffer, 0, buffer.Length); + if (count == 0) + { + break; + } + await response.Body.WriteAsync(buffer, 0, count); + } + } + + private async Task AppChunked(HttpContext httpContext) + { + var request = httpContext.Request; + var response = httpContext.Response; + var data = new MemoryStream(); + await request.Body.CopyToAsync(data); + var bytes = data.ToArray(); + + response.Headers.Clear(); + response.Headers["Content-Length"] = bytes.Length.ToString(); + await response.Body.WriteAsync(bytes, 0, bytes.Length); + } + + [ConditionalTheory] + [MemberData(nameof(ConnectionFilterData))] + public async Task Http10TransferEncoding(ServiceContext testContext) + { + using (var server = new TestServer(App, testContext)) + { + using (var connection = new TestConnection(server.Port)) + { + await connection.SendEnd( + "POST / HTTP/1.0", + "Transfer-Encoding: chunked", + "", + "5", "Hello", + "6", " World", + "0", + ""); + await connection.ReceiveEnd( + "HTTP/1.0 200 OK", + "", + "Hello World"); + } + } + } + + [ConditionalTheory] + [MemberData(nameof(ConnectionFilterData))] + public async Task Http10KeepAliveTransferEncoding(ServiceContext testContext) + { + using (var server = new TestServer(AppChunked, testContext)) + { + using (var connection = new TestConnection(server.Port)) + { + await connection.SendEnd( + "POST / HTTP/1.0", + "Transfer-Encoding: chunked", + "Connection: keep-alive", + "", + "5", "Hello", + "6", " World", + "0", + "", + "POST / HTTP/1.0", + "", + "Goodbye"); + await connection.Receive( + "HTTP/1.0 200 OK", + "Connection: keep-alive", + "Content-Length: 11", + "", + "Hello World"); + await connection.ReceiveEnd( + "HTTP/1.0 200 OK", + "Content-Length: 7", + "", + "Goodbye"); + } + } + } + + [ConditionalTheory] + [MemberData(nameof(ConnectionFilterData))] + public async Task RequestBodyIsConsumedAutomaticallyIfAppDoesntConsumeItFully(ServiceContext testContext) + { + using (var server = new TestServer(async httpContext => + { + var response = httpContext.Response; + var request = httpContext.Request; + + Assert.Equal("POST", request.Method); + + response.Headers.Clear(); + response.Headers["Content-Length"] = new[] { "11" }; + + await response.Body.WriteAsync(Encoding.ASCII.GetBytes("Hello World"), 0, 11); + }, testContext)) + { + using (var connection = new TestConnection(server.Port)) + { + await connection.SendEnd( + "POST / HTTP/1.1", + "Content-Length: 5", + "", + "HelloPOST / HTTP/1.1", + "Transfer-Encoding: chunked", + "", + "C", "HelloChunked", + "0", + "", + "POST / HTTP/1.1", + "Content-Length: 7", + "", + "Goodbye"); + await connection.ReceiveEnd( + "HTTP/1.1 200 OK", + "Content-Length: 11", + "", + "Hello WorldHTTP/1.1 200 OK", + "Content-Length: 11", + "", + "Hello WorldHTTP/1.1 200 OK", + "Content-Length: 11", + "", + "Hello World"); + } + } + } + + [ConditionalTheory] + [MemberData(nameof(ConnectionFilterData))] + [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Test hangs after execution on Mono.")] + public async Task TrailingHeadersAreParsed(ServiceContext testContext) + { + var requestCount = 10; + var requestsReceived = 0; + + using (var server = new TestServer(async httpContext => + { + var response = httpContext.Response; + var request = httpContext.Request; + + var buffer = new byte[200]; + + Assert.Equal(string.Empty, request.Headers["X-Trailer-Header"]); + + while(await request.Body.ReadAsync(buffer, 0, buffer.Length) != 0) + { + // read to end + } + + if (requestsReceived < requestCount) + { + Assert.Equal(new string('a', requestsReceived), request.Headers["X-Trailer-Header"]); + } + else + { + Assert.Equal(string.Empty, request.Headers["X-Trailer-Header"]); + } + + requestsReceived++; + + response.Headers.Clear(); + response.Headers["Content-Length"] = new[] { "11" }; + + await response.Body.WriteAsync(Encoding.ASCII.GetBytes("Hello World"), 0, 11); + }, testContext)) + { + var response = string.Join("\r\n", new string[] { + "HTTP/1.1 200 OK", + "Content-Length: 11", + "", + "Hello World"}); + + var expectedFullResponse = string.Join("", Enumerable.Repeat(response, requestCount + 1)); + + using (var connection = new TestConnection(server.Port)) + { + await connection.Send( + "POST / HTTP/1.1", + "Transfer-Encoding: chunked", + "", + "C", "HelloChunked", + "0", + ""); + + for (var i = 1; i < requestCount; i++) + { + await connection.Send( + "POST / HTTP/1.1", + "Transfer-Encoding: chunked", + "", + "C", "HelloChunked", + "0", + string.Concat("X-Trailer-Header", new string('a', i)), + ""); + } + + await connection.SendEnd( + "POST / HTTP/1.1", + "Content-Length: 7", + "", + "Goodbye"); + + await connection.ReceiveEnd(expectedFullResponse); + } + } + } + + private class TestApplicationErrorLogger : ILogger + { + public int ApplicationErrorsLogged { get; set; } + + public IDisposable BeginScopeImpl(object state) + { + return new Disposable(() => { }); + } + + public bool IsEnabled(LogLevel logLevel) + { + return true; + } + + public void Log(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func formatter) + { + // Application errors are logged using 13 as the eventId. + if (eventId.Id == 13) + { + ApplicationErrorsLogged++; + } + } + } + + private class PassThroughConnectionFilter : IConnectionFilter + { + public Task OnConnectionAsync(ConnectionFilterContext context) + { + context.Connection = new LoggingStream(context.Connection, new TestApplicationErrorLogger()); + return TaskUtilities.CompletedTask; + } + } + } +} + diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs index c91e4488e0..9406282898 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs @@ -282,30 +282,6 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } } - [Theory] - [MemberData(nameof(ConnectionFilterData))] - public async Task Http10TransferEncoding(ServiceContext testContext) - { - using (var server = new TestServer(App, testContext)) - { - using (var connection = new TestConnection(server.Port)) - { - await connection.SendEnd( - "POST / HTTP/1.0", - "Transfer-Encoding: chunked", - "", - "5", "Hello", - "6", " World", - "0", - ""); - await connection.ReceiveEnd( - "HTTP/1.0 200 OK", - "", - "Hello World"); - } - } - } - [Theory] [MemberData(nameof(ConnectionFilterData))] public async Task Http10KeepAlive(ServiceContext testContext) @@ -396,41 +372,6 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } } - [Theory] - [MemberData(nameof(ConnectionFilterData))] - public async Task Http10KeepAliveTransferEncoding(ServiceContext testContext) - { - using (var server = new TestServer(AppChunked, testContext)) - { - using (var connection = new TestConnection(server.Port)) - { - await connection.SendEnd( - "POST / HTTP/1.0", - "Transfer-Encoding: chunked", - "Connection: keep-alive", - "", - "5", "Hello", - "6", " World", - "0", - "", - "POST / HTTP/1.0", - "", - "Goodbye"); - await connection.Receive( - "HTTP/1.0 200 OK", - "Connection: keep-alive", - "Content-Length: 11", - "", - "Hello World"); - await connection.ReceiveEnd( - "HTTP/1.0 200 OK", - "Content-Length: 7", - "", - "Goodbye"); - } - } - } - [Theory] [MemberData(nameof(ConnectionFilterData))] public async Task Expect100ContinueForBody(ServiceContext testContext) @@ -949,54 +890,6 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } } - [Theory] - [MemberData(nameof(ConnectionFilterData))] - public async Task RequestBodyIsConsumedAutomaticallyIfAppDoesntConsumeItFully(ServiceContext testContext) - { - using (var server = new TestServer(async httpContext => - { - var response = httpContext.Response; - var request = httpContext.Request; - - Assert.Equal("POST", request.Method); - - response.Headers.Clear(); - response.Headers["Content-Length"] = new[] { "11" }; - - await response.Body.WriteAsync(Encoding.ASCII.GetBytes("Hello World"), 0, 11); - }, testContext)) - { - using (var connection = new TestConnection(server.Port)) - { - await connection.SendEnd( - "POST / HTTP/1.1", - "Content-Length: 5", - "", - "HelloPOST / HTTP/1.1", - "Transfer-Encoding: chunked", - "", - "C", "HelloChunked", - "0", - "", - "POST / HTTP/1.1", - "Content-Length: 7", - "", - "Goodbye"); - await connection.ReceiveEnd( - "HTTP/1.1 200 OK", - "Content-Length: 11", - "", - "Hello WorldHTTP/1.1 200 OK", - "Content-Length: 11", - "", - "Hello WorldHTTP/1.1 200 OK", - "Content-Length: 11", - "", - "Hello World"); - } - } - } - [Theory] [MemberData(nameof(ConnectionFilterData))] public async Task RequestsCanBeAbortedMidRead(ServiceContext testContext) From 4bfcd7ba1fbd7985a01ded12d4c771f71d484fa7 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Thu, 11 Feb 2016 00:58:06 +0000 Subject: [PATCH 0628/1662] Drain chunked extensions + refactor --- .../Http/MessageBody.cs | 392 ++++++++++-------- .../ChunkedRequestTests.cs | 253 +++++++++-- .../TestInput.cs | 7 +- 3 files changed, 437 insertions(+), 215 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/MessageBody.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/MessageBody.cs index 9fa51ed40e..f17013c513 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/MessageBody.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/MessageBody.cs @@ -3,6 +3,7 @@ using System; using System.IO; +using System.Numerics; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; @@ -11,10 +12,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { public abstract class MessageBody { - private readonly FrameContext _context; + private readonly Frame _context; private int _send100Continue = 1; - protected MessageBody(FrameContext context) + protected MessageBody(Frame context) { _context = context; } @@ -99,7 +100,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http public static MessageBody For( string httpVersion, FrameRequestHeaders headers, - FrameContext context) + Frame context) { // see also http://tools.ietf.org/html/rfc2616#section-4.4 @@ -114,7 +115,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http var transferEncoding = headers.HeaderTransferEncoding.ToString(); if (transferEncoding.Length > 0) { - return new ForChunkedEncoding(keepAlive, context); + return new ForChunkedEncoding(keepAlive, headers, context); } var contentLength = headers.HeaderContentLength.ToString(); @@ -133,7 +134,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http private class ForRemainingData : MessageBody { - public ForRemainingData(FrameContext context) + public ForRemainingData(Frame context) : base(context) { } @@ -149,7 +150,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http private readonly int _contentLength; private int _inputLength; - public ForContentLength(bool keepAlive, int contentLength, FrameContext context) + public ForContentLength(bool keepAlive, int contentLength, Frame context) : base(context) { RequestKeepAlive = keepAlive; @@ -204,96 +205,203 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http /// private class ForChunkedEncoding : MessageBody { - private int _inputLength; - private Mode _mode = Mode.ChunkPrefix; + private static Vector _vectorCRs = new Vector((byte)'\r'); - public ForChunkedEncoding(bool keepAlive, FrameContext context) + private int _inputLength; + private Mode _mode = Mode.Prefix; + private FrameRequestHeaders _requestHeaders; + + public ForChunkedEncoding(bool keepAlive, FrameRequestHeaders headers, Frame context) : base(context) { RequestKeepAlive = keepAlive; + _requestHeaders = headers; } + public override ValueTask ReadAsyncImplementation(ArraySegment buffer, CancellationToken cancellationToken) { - return ReadAsyncAwaited(buffer, cancellationToken); + return ReadStateMachineAsync(_context.SocketInput, buffer, cancellationToken); } - private async Task ReadAsyncAwaited(ArraySegment buffer, CancellationToken cancellationToken) + private async Task ReadStateMachineAsync(SocketInput input, ArraySegment buffer, CancellationToken cancellationToken) { - var input = _context.SocketInput; - - while (_mode != Mode.Trailer && _mode != Mode.Complete) + while (_mode < Mode.Trailer) { - while (_mode == Mode.ChunkPrefix) + while (_mode == Mode.Prefix) { - ReadChunkedPrefix(input); - await input; + ParseChunkedPrefix(input); + if (_mode != Mode.Prefix) + { + break; + } + + await GetDataAsync(input); } - while (_mode == Mode.ChunkData) + while (_mode == Mode.Extension) + { + ParseExtension(input); + if (_mode != Mode.Extension) + { + break; + } + + await GetDataAsync(input); + } + + while (_mode == Mode.Data) { int actual = ReadChunkedData(input, buffer.Array, buffer.Offset, buffer.Count); if (actual != 0) { return actual; } + else if (_mode != Mode.Data) + { + break; + } - await input; + await GetDataAsync(input); } - while (_mode == Mode.ChunkSuffix) + while (_mode == Mode.Suffix) { - ReadChunkedSuffix(input); - await input; + ParseChunkedSuffix(input); + if (_mode != Mode.Suffix) + { + break; + } + + await GetDataAsync(input); } } + // Chunks finished, parse trailers while (_mode == Mode.Trailer) { - ReadChunkedTrailer(input); - - if (_mode != Mode.Complete && _mode != Mode.TrailerHeaders) + ParseChunkedTrailer(input); + if (_mode != Mode.Trailer) { - await input; + break; } + + await GetDataAsync(input); } if (_mode == Mode.TrailerHeaders) { - // Take trailer headers - var frame = (Frame)_context; - while (!Frame.TakeMessageHeaders(input, frame._requestHeaders)) + while (!Frame.TakeMessageHeaders(input, _requestHeaders)) { - if (input.RemoteIntakeFin) - { - ThrowChunkedRequestIncomplete(); - } - - await input; + await GetDataAsync(input); } + + _mode = Mode.Complete; } return 0; } - private void ReadChunkedPrefix(SocketInput input) + private void ParseChunkedPrefix(SocketInput input) { - int chunkSize; - if (TakeChunkedLine(input, out chunkSize)) + var scan = input.ConsumingStart(); + var consumed = scan; + try { - if (chunkSize == 0) + var ch1 = scan.Take(); + var ch2 = scan.Take(); + if (ch1 == -1 || ch2 == -1) { - _mode = Mode.Trailer; - } - else - { - _mode = Mode.ChunkData; + return; } - _inputLength = chunkSize; + var chunkSize = CalculateChunkSize(ch1, 0); + ch1 = ch2; + + do + { + if (ch1 == ';') + { + consumed = scan; + + _inputLength = chunkSize; + _mode = Mode.Extension; + return; + } + + ch2 = scan.Take(); + if (ch2 == -1) + { + return; + } + + if (ch1 == '\r' && ch2 == '\n') + { + consumed = scan; + _inputLength = chunkSize; + + if (chunkSize > 0) + { + _mode = Mode.Data; + } + else + { + _mode = Mode.Trailer; + } + + return; + } + + chunkSize = CalculateChunkSize(ch1, chunkSize); + ch1 = ch2; + } while (ch1 != -1); } - else if (input.RemoteIntakeFin) + finally { - ThrowChunkedRequestIncomplete(); + input.ConsumingComplete(consumed, scan); + } + } + + private void ParseExtension(SocketInput input) + { + var scan = input.ConsumingStart(); + var consumed = scan; + try + { + // Chunk-extensions not currently parsed + // Just drain the data + do + { + if (scan.Seek(ref _vectorCRs) == -1) + { + // End marker not found yet + consumed = scan; + return; + }; + + var ch1 = scan.Take(); + var ch2 = scan.Take(); + + if (ch2 == '\n') + { + consumed = scan; + if (_inputLength > 0) + { + _mode = Mode.Data; + } + else + { + _mode = Mode.Trailer; + } + } + else if (ch2 == -1) + { + return; + } + } while (_mode == Mode.Extension); + } + finally + { + input.ConsumingComplete(consumed, scan); } } @@ -314,17 +422,17 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if (_inputLength == 0) { - _mode = Mode.ChunkSuffix; + _mode = Mode.Suffix; } - else if (actual == 0 && input.RemoteIntakeFin) + else if (actual == 0) { - ThrowChunkedRequestIncomplete(); + ThrowIfRequestIncomplete(input); } return actual; } - private void ReadChunkedSuffix(SocketInput input) + private void ParseChunkedSuffix(SocketInput input) { var scan = input.ConsumingStart(); var consumed = scan; @@ -332,18 +440,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { var ch1 = scan.Take(); var ch2 = scan.Take(); - - if (ch1 == '\r' && ch2 == '\n') + if (ch1 == -1 || ch2 == -1) + { + return; + } + else if (ch1 == '\r' && ch2 == '\n') { consumed = scan; - _mode = Mode.ChunkPrefix; - } - else if (ch1 == -1 || ch2 == -1) - { - if (input.RemoteIntakeFin) - { - ThrowChunkedRequestIncomplete(); - } + _mode = Mode.Prefix; } else { @@ -356,7 +460,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } - private void ReadChunkedTrailer(SocketInput input) + private void ParseChunkedTrailer(SocketInput input) { var scan = input.ConsumingStart(); var consumed = scan; @@ -365,29 +469,18 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http var ch1 = scan.Take(); var ch2 = scan.Take(); - if (ch1 == '\r' && ch2 == '\n') + if (ch1 == -1 || ch2 == -1) + { + return; + } + else if (ch1 == '\r' && ch2 == '\n') { consumed = scan; _mode = Mode.Complete; } - else if (ch1 == -1 || ch2 == -1) - { - if (input.RemoteIntakeFin) - { - ThrowChunkedRequestIncomplete(); - } - } else { - // Post request headers - if (_context is Frame) - { - _mode = Mode.TrailerHeaders; - } - else - { - ThrowTrailingHeadersNotSupported(); - } + _mode = Mode.TrailerHeaders; } } finally @@ -396,124 +489,61 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } - private static bool TakeChunkedLine(SocketInput baton, out int chunkSizeOut) + private static int CalculateChunkSize(int extraHexDigit, int currentParsedSize) { - var scan = baton.ConsumingStart(); - var consumed = scan; - try + checked { - var ch0 = scan.Take(); - var chunkSize = 0; - var mode = Mode.ChunkPrefix; - while (ch0 != -1) + if (extraHexDigit >= '0' && extraHexDigit <= '9') { - var ch1 = scan.Take(); - if (ch1 == -1) - { - chunkSizeOut = 0; - return false; - } - - if (mode == Mode.ChunkPrefix) - { - if (ch0 >= '0' && ch0 <= '9') - { - chunkSize = chunkSize * 0x10 + (ch0 - '0'); - } - else if (ch0 >= 'A' && ch0 <= 'F') - { - chunkSize = chunkSize * 0x10 + (ch0 - ('A' - 10)); - } - else if (ch0 >= 'a' && ch0 <= 'f') - { - chunkSize = chunkSize * 0x10 + (ch0 - ('a' - 10)); - } - else - { - ThrowInvalidFormat(); - } - mode = Mode.ChunkData; - } - else if (mode == Mode.ChunkData) - { - if (ch0 >= '0' && ch0 <= '9') - { - chunkSize = chunkSize * 0x10 + (ch0 - '0'); - } - else if (ch0 >= 'A' && ch0 <= 'F') - { - chunkSize = chunkSize * 0x10 + (ch0 - ('A' - 10)); - } - else if (ch0 >= 'a' && ch0 <= 'f') - { - chunkSize = chunkSize * 0x10 + (ch0 - ('a' - 10)); - } - else if (ch0 == ';') - { - mode = Mode.ChunkSuffix; - } - else if (ch0 == '\r' && ch1 == '\n') - { - consumed = scan; - chunkSizeOut = chunkSize; - return true; - } - else - { - ThrowInvalidFormat(); - } - } - else if (mode == Mode.ChunkSuffix) - { - if (ch0 == '\r' && ch1 == '\n') - { - consumed = scan; - chunkSizeOut = chunkSize; - return true; - } - else - { - // chunk-extensions not currently parsed - ThrowChunkedExtensionsNotSupported(); - } - } - - ch0 = ch1; + return currentParsedSize * 0x10 + (extraHexDigit - '0'); + } + else if (extraHexDigit >= 'A' && extraHexDigit <= 'F') + { + return currentParsedSize * 0x10 + (extraHexDigit - ('A' - 10)); + } + else if (extraHexDigit >= 'a' && extraHexDigit <= 'f') + { + return currentParsedSize * 0x10 + (extraHexDigit - ('a' - 10)); + } + else + { + return ThrowInvalidFormat(); } - chunkSizeOut = 0; - return false; - } - finally - { - baton.ConsumingComplete(consumed, scan); } } - private static void ThrowInvalidFormat() + private static SocketInput GetDataAsync(SocketInput input) { - throw new InvalidOperationException("Bad Request"); + ThrowIfRequestIncomplete(input); + + return input; } - private static void ThrowChunkedRequestIncomplete() + private static void ThrowIfRequestIncomplete(SocketInput input) + { + if (input.RemoteIntakeFin) + { + ThrowRequestIncomplete(); + } + } + + private static int ThrowInvalidFormat() + { + // returns int so can be used as item non-void function + throw new InvalidOperationException("Bad request"); + } + + private static void ThrowRequestIncomplete() { throw new InvalidOperationException("Chunked request incomplete"); } - private static void ThrowChunkedExtensionsNotSupported() - { - throw new NotImplementedException("Chunked-extensions not supported"); - } - - private static void ThrowTrailingHeadersNotSupported() - { - throw new NotImplementedException("Trailing headers not supported"); - } - private enum Mode { - ChunkPrefix, - ChunkData, - ChunkSuffix, + Prefix, + Extension, + Data, + Suffix, Trailer, TrailerHeaders, Complete diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedRequestTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedRequestTests.cs index 49cfc2a2e9..82036269a4 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedRequestTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedRequestTests.cs @@ -2,15 +2,16 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Collections.Generic; using System.IO; using System.Linq; +using System.Net.Sockets; using System.Text; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Server.Kestrel; using Microsoft.AspNetCore.Server.Kestrel.Filter; using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; -using Microsoft.AspNetCore.Testing.xunit; using Microsoft.Extensions.Logging; using Xunit; @@ -64,7 +65,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests await response.Body.WriteAsync(bytes, 0, bytes.Length); } - [ConditionalTheory] + [Theory] [MemberData(nameof(ConnectionFilterData))] public async Task Http10TransferEncoding(ServiceContext testContext) { @@ -88,7 +89,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } } - [ConditionalTheory] + [Theory] [MemberData(nameof(ConnectionFilterData))] public async Task Http10KeepAliveTransferEncoding(ServiceContext testContext) { @@ -123,7 +124,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } } - [ConditionalTheory] + [Theory] [MemberData(nameof(ConnectionFilterData))] public async Task RequestBodyIsConsumedAutomaticallyIfAppDoesntConsumeItFully(ServiceContext testContext) { @@ -171,9 +172,8 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } } - [ConditionalTheory] + [Theory] [MemberData(nameof(ConnectionFilterData))] - [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Test hangs after execution on Mono.")] public async Task TrailingHeadersAreParsed(ServiceContext testContext) { var requestCount = 10; @@ -186,20 +186,20 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var buffer = new byte[200]; - Assert.Equal(string.Empty, request.Headers["X-Trailer-Header"]); + Assert.True(string.IsNullOrEmpty(request.Headers["X-Trailer-Header"])); - while(await request.Body.ReadAsync(buffer, 0, buffer.Length) != 0) + while (await request.Body.ReadAsync(buffer, 0, buffer.Length) != 0) { // read to end } if (requestsReceived < requestCount) { - Assert.Equal(new string('a', requestsReceived), request.Headers["X-Trailer-Header"]); + Assert.Equal(new string('a', requestsReceived), request.Headers["X-Trailer-Header"].ToString()); } else { - Assert.Equal(string.Empty, request.Headers["X-Trailer-Header"]); + Assert.True(string.IsNullOrEmpty(request.Headers["X-Trailer-Header"])); } requestsReceived++; @@ -218,41 +218,231 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var expectedFullResponse = string.Join("", Enumerable.Repeat(response, requestCount + 1)); - using (var connection = new TestConnection(server.Port)) + IEnumerable sendSequence = new string[] { + "POST / HTTP/1.1", + "Transfer-Encoding: chunked", + "", + "C", + "HelloChunked", + "0", + ""}; + + for (var i = 1; i < requestCount; i++) { - await connection.Send( + sendSequence = sendSequence.Concat(new string[] { "POST / HTTP/1.1", "Transfer-Encoding: chunked", "", - "C", "HelloChunked", + "C", + $"HelloChunk{i:00}", "0", - ""); + string.Concat("X-Trailer-Header: ", new string('a', i)), + "" }); + } - for (var i = 1; i < requestCount; i++) - { - await connection.Send( - "POST / HTTP/1.1", - "Transfer-Encoding: chunked", - "", - "C", "HelloChunked", - "0", - string.Concat("X-Trailer-Header", new string('a', i)), - ""); - } + sendSequence = sendSequence.Concat(new string[] { + "POST / HTTP/1.1", + "Content-Length: 7", + "", + "Goodbye" + }); - await connection.SendEnd( - "POST / HTTP/1.1", - "Content-Length: 7", - "", - "Goodbye"); + var fullRequest = sendSequence.ToArray(); + + using (var connection = new TestConnection(server.Port)) + { + await connection.SendEnd(fullRequest); await connection.ReceiveEnd(expectedFullResponse); } } } + [Theory] + [MemberData(nameof(ConnectionFilterData))] + public async Task ExtensionsAreIgnored(ServiceContext testContext) + { + var requestCount = 10; + var requestsReceived = 0; + + using (var server = new TestServer(async httpContext => + { + var response = httpContext.Response; + var request = httpContext.Request; + + var buffer = new byte[200]; + + Assert.True(string.IsNullOrEmpty(request.Headers["X-Trailer-Header"])); + + while (await request.Body.ReadAsync(buffer, 0, buffer.Length) != 0) + { + // read to end + } + + if (requestsReceived < requestCount) + { + Assert.Equal(new string('a', requestsReceived), request.Headers["X-Trailer-Header"].ToString()); + } + else + { + Assert.True(string.IsNullOrEmpty(request.Headers["X-Trailer-Header"])); + } + + requestsReceived++; + + response.Headers.Clear(); + response.Headers["Content-Length"] = new[] { "11" }; + + await response.Body.WriteAsync(Encoding.ASCII.GetBytes("Hello World"), 0, 11); + }, testContext)) + { + var response = string.Join("\r\n", new string[] { + "HTTP/1.1 200 OK", + "Content-Length: 11", + "", + "Hello World"}); + + var expectedFullResponse = string.Join("", Enumerable.Repeat(response, requestCount + 1)); + + IEnumerable sendSequence = new string[] { + "POST / HTTP/1.1", + "Transfer-Encoding: chunked", + "", + "C;hello there", + "HelloChunked", + "0;hello there", + ""}; + + for (var i = 1; i < requestCount; i++) + { + sendSequence = sendSequence.Concat(new string[] { + "POST / HTTP/1.1", + "Transfer-Encoding: chunked", + "", + "C;hello there", + $"HelloChunk{i:00}", + "0;hello there", + string.Concat("X-Trailer-Header: ", new string('a', i)), + "" }); + } + + sendSequence = sendSequence.Concat(new string[] { + "POST / HTTP/1.1", + "Content-Length: 7", + "", + "Goodbye" + }); + + var fullRequest = sendSequence.ToArray(); + + using (var connection = new TestConnection(server.Port)) + { + await connection.SendEnd(fullRequest); + + await connection.ReceiveEnd(expectedFullResponse); + } + } + } + + [Theory] + [MemberData(nameof(ConnectionFilterData))] + public async Task InvalidLengthResultsIn500(ServiceContext testContext) + { + using (var server = new TestServer(async httpContext => + { + var response = httpContext.Response; + var request = httpContext.Request; + + var buffer = new byte[200]; + + while (await request.Body.ReadAsync(buffer, 0, buffer.Length) != 0) + { + ;// read to end + } + + response.Headers.Clear(); + response.Headers["Content-Length"] = new[] { "11" }; + + await response.Body.WriteAsync(Encoding.ASCII.GetBytes("Hello World"), 0, 11); + }, testContext)) + { + using (var connection = new TestConnection(server.Port)) + { + await connection.Send( + "POST / HTTP/1.1", + "Transfer-Encoding: chunked", + "", + "Cio", + "HelloChunked", + "0", + ""); + + // Should really be a 40x as is bad request + await connection.Receive( + "HTTP/1.1 500 Internal Server Error", + ""); + await connection.ReceiveStartsWith("Date:"); + await connection.ReceiveEnd( + "Content-Length: 0", + "Server: Kestrel", + "", + ""); + } + } + } + + [Theory] + [MemberData(nameof(ConnectionFilterData))] + public async Task InvalidSizedDataResultsIn500(ServiceContext testContext) + { + using (var server = new TestServer(async httpContext => + { + var response = httpContext.Response; + var request = httpContext.Request; + + var buffer = new byte[200]; + + while (await request.Body.ReadAsync(buffer, 0, buffer.Length) != 0) + { + ;// read to end + } + + response.Headers.Clear(); + response.Headers["Content-Length"] = new[] { "11" }; + + await response.Body.WriteAsync(Encoding.ASCII.GetBytes("Hello World"), 0, 11); + }, testContext)) + { + using (var connection = new TestConnection(server.Port)) + { + await connection.Send( + "POST / HTTP/1.1", + "Transfer-Encoding: chunked", + "", + "C", + "HelloChunkedInvalid", + "0", + ""); + + // Should really be a 40x as is bad request + await connection.Receive( + "HTTP/1.1 500 Internal Server Error", + ""); + await connection.ReceiveStartsWith("Date:"); + await connection.ReceiveEnd( + "Content-Length: 0", + "Server: Kestrel", + "", + ""); + } + } + } + private class TestApplicationErrorLogger : ILogger { + // Application errors are logged using 13 as the eventId. + private const int ApplicationErrorEventId = 13; + public int ApplicationErrorsLogged { get; set; } public IDisposable BeginScopeImpl(object state) @@ -267,8 +457,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests public void Log(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func formatter) { - // Application errors are logged using 13 as the eventId. - if (eventId.Id == 13) + if (eventId.Id == ApplicationErrorEventId) { ApplicationErrorsLogged++; } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestInput.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/TestInput.cs index ba52b21d43..3214c94ed8 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/TestInput.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/TestInput.cs @@ -18,17 +18,20 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { var trace = new KestrelTrace(new TestKestrelTrace()); var ltp = new LoggingThreadPool(trace); - FrameContext = new FrameContext + var context = new FrameContext() { + DateHeaderValueManager = new DateHeaderValueManager(), + ServerAddress = ServerAddress.FromUrl("http://localhost:5000"), ConnectionControl = this, FrameControl = this }; + FrameContext = new Frame(null, context); _memoryPool = new MemoryPool2(); FrameContext.SocketInput = new SocketInput(_memoryPool, ltp); } - public FrameContext FrameContext { get; set; } + public Frame FrameContext { get; set; } public void Add(string text, bool fin = false) { From 48d3c63f7058a0527a36fe4176ec9067cf73c857 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Tue, 23 Feb 2016 08:20:33 +0000 Subject: [PATCH 0629/1662] TestHelper classes for shared types --- .../ChunkedRequestTests.cs | 40 ------------------- .../EngineTests.cs | 39 ------------------ .../PassThroughConnectionFilter.cs | 19 +++++++++ .../TestHelpers/TestApplicationErrorLogger.cs | 35 ++++++++++++++++ 4 files changed, 54 insertions(+), 79 deletions(-) create mode 100644 test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/PassThroughConnectionFilter.cs create mode 100644 test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/TestApplicationErrorLogger.cs diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedRequestTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedRequestTests.cs index 82036269a4..9408c44b14 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedRequestTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedRequestTests.cs @@ -1,18 +1,13 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System; using System.Collections.Generic; using System.IO; using System.Linq; -using System.Net.Sockets; using System.Text; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Server.Kestrel; -using Microsoft.AspNetCore.Server.Kestrel.Filter; -using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; -using Microsoft.Extensions.Logging; using Xunit; namespace Microsoft.AspNetCore.Server.KestrelTests @@ -437,41 +432,6 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } } } - - private class TestApplicationErrorLogger : ILogger - { - // Application errors are logged using 13 as the eventId. - private const int ApplicationErrorEventId = 13; - - public int ApplicationErrorsLogged { get; set; } - - public IDisposable BeginScopeImpl(object state) - { - return new Disposable(() => { }); - } - - public bool IsEnabled(LogLevel logLevel) - { - return true; - } - - public void Log(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func formatter) - { - if (eventId.Id == ApplicationErrorEventId) - { - ApplicationErrorsLogged++; - } - } - } - - private class PassThroughConnectionFilter : IConnectionFilter - { - public Task OnConnectionAsync(ConnectionFilterContext context) - { - context.Connection = new LoggingStream(context.Connection, new TestApplicationErrorLogger()); - return TaskUtilities.CompletedTask; - } - } } } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs index 9406282898..2a4e788c58 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs @@ -4,7 +4,6 @@ using System; using System.IO; using System.Linq; -using System.Net; using System.Net.Sockets; using System.Text; using System.Threading; @@ -12,11 +11,6 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Server.Kestrel; -using Microsoft.AspNetCore.Server.Kestrel.Filter; -using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; -using Microsoft.AspNetCore.Server.Kestrel.Networking; -using Microsoft.AspNetCore.Testing.xunit; -using Microsoft.Extensions.Logging; using Xunit; namespace Microsoft.AspNetCore.Server.KestrelTests @@ -1024,38 +1018,5 @@ namespace Microsoft.AspNetCore.Server.KestrelTests Assert.True(registrationWh.Wait(1000)); } } - - private class TestApplicationErrorLogger : ILogger - { - public int ApplicationErrorsLogged { get; set; } - - public IDisposable BeginScopeImpl(object state) - { - return new Disposable(() => { }); - } - - public bool IsEnabled(LogLevel logLevel) - { - return true; - } - - public void Log(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func formatter) - { - // Application errors are logged using 13 as the eventId. - if (eventId.Id == 13) - { - ApplicationErrorsLogged++; - } - } - } - - private class PassThroughConnectionFilter : IConnectionFilter - { - public Task OnConnectionAsync(ConnectionFilterContext context) - { - context.Connection = new LoggingStream(context.Connection, new TestApplicationErrorLogger()); - return TaskUtilities.CompletedTask; - } - } } } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/PassThroughConnectionFilter.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/PassThroughConnectionFilter.cs new file mode 100644 index 0000000000..2342536d3c --- /dev/null +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/PassThroughConnectionFilter.cs @@ -0,0 +1,19 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System.Threading.Tasks; +using Microsoft.AspNetCore.Server.Kestrel.Filter; +using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; + +namespace Microsoft.AspNetCore.Server.KestrelTests +{ + + public class PassThroughConnectionFilter : IConnectionFilter + { + public Task OnConnectionAsync(ConnectionFilterContext context) + { + context.Connection = new LoggingStream(context.Connection, new TestApplicationErrorLogger()); + return TaskUtilities.CompletedTask; + } + } +} diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/TestApplicationErrorLogger.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/TestApplicationErrorLogger.cs new file mode 100644 index 0000000000..f6e7f04169 --- /dev/null +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/TestApplicationErrorLogger.cs @@ -0,0 +1,35 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using Microsoft.AspNetCore.Server.Kestrel; +using Microsoft.Extensions.Logging; + +namespace Microsoft.AspNetCore.Server.KestrelTests +{ + public class TestApplicationErrorLogger : ILogger + { + // Application errors are logged using 13 as the eventId. + private const int ApplicationErrorEventId = 13; + + public int ApplicationErrorsLogged { get; set; } + + public IDisposable BeginScopeImpl(object state) + { + return new Disposable(() => { }); + } + + public bool IsEnabled(LogLevel logLevel) + { + return true; + } + + public void Log(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func formatter) + { + if (eventId.Id == ApplicationErrorEventId) + { + ApplicationErrorsLogged++; + } + } + } +} From 766803c573961cab131218a4b931b1203dad543e Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Tue, 23 Feb 2016 10:18:46 +0000 Subject: [PATCH 0630/1662] Return 400 for bad requests and close conn --- .../Exceptions/BadHttpRequestException.cs | 16 ++++ .../Http/Frame.cs | 58 +++++++++----- .../Http/FrameOfT.cs | 76 ++++++++++--------- .../Http/MessageBody.cs | 54 +++++++------ .../Infrastructure/HttpComponentFactory.cs | 8 +- .../Infrastructure/IHttpComponentFactory.cs | 4 +- .../Infrastructure/IKestrelTrace.cs | 3 + .../Infrastructure/KestrelTrace.cs | 8 ++ .../ChunkedRequestTests.cs | 23 ++---- .../FrameTests.cs | 8 +- 10 files changed, 160 insertions(+), 98 deletions(-) create mode 100644 src/Microsoft.AspNetCore.Server.Kestrel/Exceptions/BadHttpRequestException.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Exceptions/BadHttpRequestException.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Exceptions/BadHttpRequestException.cs new file mode 100644 index 0000000000..19c004857e --- /dev/null +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Exceptions/BadHttpRequestException.cs @@ -0,0 +1,16 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System.IO; + +namespace Microsoft.AspNetCore.Server.Kestrel.Exceptions +{ + public sealed class BadHttpRequestException : IOException + { + internal BadHttpRequestException(string message) + : base(message) + { + + } + } +} diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs index 2c83fc7c84..9d14928e16 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs @@ -5,7 +5,6 @@ using System; using System.Collections.Generic; using System.IO; using System.Linq; -using System.Net; using System.Numerics; using System.Text; using System.Threading; @@ -13,6 +12,7 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Exceptions; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Primitives; @@ -45,7 +45,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http private readonly object _onStartingSync = new Object(); private readonly object _onCompletedSync = new Object(); - protected bool _poolingPermitted = true; + protected bool _corruptedRequest = false; private Headers _frameHeaders; private Streams _frameStreams; @@ -211,7 +211,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http public void Reset() { - ResetComponents(poolingPermitted: true); + ResetComponents(); _onStarting = null; _onCompleted = null; @@ -248,27 +248,23 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http _abortedCts = null; } - protected void ResetComponents(bool poolingPermitted) + protected void ResetComponents() { - if (_frameHeaders != null) + var frameHeaders = Interlocked.Exchange(ref _frameHeaders, null); + if (frameHeaders != null) { - var frameHeaders = _frameHeaders; - _frameHeaders = null; - RequestHeaders = null; ResponseHeaders = null; - HttpComponentFactory.DisposeHeaders(frameHeaders, poolingPermitted); + HttpComponentFactory.DisposeHeaders(frameHeaders); } - if (_frameStreams != null) + var frameStreams = Interlocked.Exchange(ref _frameStreams, null); + if (frameStreams != null) { - var frameStreams = _frameStreams; - _frameStreams = null; - RequestBody = null; ResponseBody = null; DuplexStream = null; - HttpComponentFactory.DisposeStreams(frameStreams, poolingPermitted); + HttpComponentFactory.DisposeStreams(frameStreams); } } @@ -568,8 +564,19 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http protected Task ProduceEnd() { - if (_applicationException != null) + if (_corruptedRequest || _applicationException != null) { + if (_corruptedRequest) + { + // 400 Bad Request + StatusCode = 400; + } + else + { + // 500 Internal Server Error + StatusCode = 500; + } + if (_responseStarted) { // We can no longer respond with a 500, so we simply close the connection. @@ -578,7 +585,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } else { - StatusCode = 500; ReasonPhrase = null; var responseHeaders = _frameHeaders.ResponseHeaders; @@ -711,7 +717,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { string method; var begin = scan; - if (!begin.GetKnownMethod(ref scan,out method)) + if (!begin.GetKnownMethod(ref scan, out method)) { if (scan.Seek(ref _vectorSpaces) == -1) { @@ -834,7 +840,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http return true; } - public static bool TakeMessageHeaders(SocketInput input, FrameRequestHeaders requestHeaders) + public bool TakeMessageHeaders(SocketInput input, FrameRequestHeaders requestHeaders) { var scan = input.ConsumingStart(); var consumed = scan; @@ -863,7 +869,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http consumed = scan; return true; } - throw new InvalidDataException("Malformed request"); + + ReportCorruptedHttpRequest(new BadHttpRequestException("Headers corrupted, invalid header sequence.")); + // Headers corrupted, parsing headers is complete + return true; } while ( @@ -953,16 +962,27 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http statusCode != 304; } + public void ReportCorruptedHttpRequest(BadHttpRequestException ex) + { + _corruptedRequest = true; + Log.ConnectionBadRequest(ConnectionId, ex); + } + protected void ReportApplicationError(Exception ex) { if (_applicationException == null) { _applicationException = ex; } + else if (_applicationException is AggregateException) + { + _applicationException = new AggregateException(_applicationException, ex).Flatten(); + } else { _applicationException = new AggregateException(_applicationException, ex); } + Log.ApplicationError(ex); } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameOfT.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameOfT.cs index 77e7c4047b..053688b587 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameOfT.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameOfT.cs @@ -2,11 +2,10 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.Net; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Hosting.Server; -using Microsoft.AspNetCore.Http.Features; +using Microsoft.AspNetCore.Server.Kestrel.Exceptions; using Microsoft.Extensions.Logging; namespace Microsoft.AspNetCore.Server.Kestrel.Http @@ -64,55 +63,66 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http _abortedCts = null; _manuallySetRequestAbortToken = null; - var context = _application.CreateContext(this); - try + if (!_corruptedRequest) { - await _application.ProcessRequestAsync(context).ConfigureAwait(false); - } - catch (Exception ex) - { - ReportApplicationError(ex); - } - finally - { - // Trigger OnStarting if it hasn't been called yet and the app hasn't - // already failed. If an OnStarting callback throws we can go through - // our normal error handling in ProduceEnd. - // https://github.com/aspnet/KestrelHttpServer/issues/43 - if (!_responseStarted && _applicationException == null && _onStarting != null) + var context = _application.CreateContext(this); + try { - await FireOnStarting(); + await _application.ProcessRequestAsync(context).ConfigureAwait(false); } - - PauseStreams(); - - if (_onCompleted != null) + catch (Exception ex) { - await FireOnCompleted(); + ReportApplicationError(ex); } + finally + { + // Trigger OnStarting if it hasn't been called yet and the app hasn't + // already failed. If an OnStarting callback throws we can go through + // our normal error handling in ProduceEnd. + // https://github.com/aspnet/KestrelHttpServer/issues/43 + if (!_responseStarted && _applicationException == null && _onStarting != null) + { + await FireOnStarting(); + } - _application.DisposeContext(context, _applicationException); + PauseStreams(); + + if (_onCompleted != null) + { + await FireOnCompleted(); + } + + _application.DisposeContext(context, _applicationException); + } // If _requestAbort is set, the connection has already been closed. if (Volatile.Read(ref _requestAborted) == 0) { ResumeStreams(); - await ProduceEnd(); - - if (_keepAlive) + if (_keepAlive && !_corruptedRequest) { - // Finish reading the request body in case the app did not. - await messageBody.Consume(); + try + { + // Finish reading the request body in case the app did not. + await messageBody.Consume(); + } + catch (BadHttpRequestException ex) + { + ReportCorruptedHttpRequest(ex); + } } + + await ProduceEnd(); } StopStreams(); } - if (!_keepAlive) + if (!_keepAlive || _corruptedRequest) { - ResetComponents(poolingPermitted: true); + // End the connection for non keep alive and Bad Requests + // as data incoming may have been thrown off return; } } @@ -122,15 +132,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } catch (Exception ex) { - // Error occurred, do not return components to pool - _poolingPermitted = false; Log.LogWarning(0, ex, "Connection processing ended abnormally"); } finally { try { - ResetComponents(poolingPermitted: _poolingPermitted); + ResetComponents(); _abortedCts = null; // If _requestAborted is set, the connection has already been closed. diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/MessageBody.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/MessageBody.cs index f17013c513..f3f604f267 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/MessageBody.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/MessageBody.cs @@ -7,6 +7,7 @@ using System.Numerics; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Exceptions; namespace Microsoft.AspNetCore.Server.Kestrel.Http { @@ -118,10 +119,19 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http return new ForChunkedEncoding(keepAlive, headers, context); } - var contentLength = headers.HeaderContentLength.ToString(); - if (contentLength.Length > 0) + var unparsedContentLength = headers.HeaderContentLength.ToString(); + if (unparsedContentLength.Length > 0) { - return new ForContentLength(keepAlive, int.Parse(contentLength), context); + int contentLength; + if (!int.TryParse(unparsedContentLength, out contentLength) || contentLength < 0) + { + context.ReportCorruptedHttpRequest(new BadHttpRequestException("Invalid content length.")); + return new ForContentLength(keepAlive, 0, context); + } + else + { + return new ForContentLength(keepAlive, contentLength, context); + } } if (keepAlive) @@ -132,6 +142,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http return new ForRemainingData(context); } + private int ThrowBadRequestException(string message) + { + // returns int so can be used as item non-void function + var ex = new BadHttpRequestException(message); + _context.ReportCorruptedHttpRequest(ex); + + throw ex; + } + private class ForRemainingData : MessageBody { public ForRemainingData(Frame context) @@ -177,7 +196,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http _inputLength -= actual; if (actual == 0) { - throw new InvalidDataException("Unexpected end of request content"); + ThrowBadRequestException("Unexpected end of request content"); } return actual; } @@ -193,7 +212,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http _inputLength -= actual; if (actual == 0) { - throw new InvalidDataException("Unexpected end of request content"); + ThrowBadRequestException("Unexpected end of request content"); } return actual; @@ -290,7 +309,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if (_mode == Mode.TrailerHeaders) { - while (!Frame.TakeMessageHeaders(input, _requestHeaders)) + while (!_context.TakeMessageHeaders(input, _requestHeaders)) { await GetDataAsync(input); } @@ -451,7 +470,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } else { - ThrowInvalidFormat(); + ThrowBadRequestException("Bad chunk suffix"); } } finally @@ -489,7 +508,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } - private static int CalculateChunkSize(int extraHexDigit, int currentParsedSize) + private int CalculateChunkSize(int extraHexDigit, int currentParsedSize) { checked { @@ -507,37 +526,26 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } else { - return ThrowInvalidFormat(); + return ThrowBadRequestException("Bad chunk size data"); } } } - private static SocketInput GetDataAsync(SocketInput input) + private SocketInput GetDataAsync(SocketInput input) { ThrowIfRequestIncomplete(input); return input; } - private static void ThrowIfRequestIncomplete(SocketInput input) + private void ThrowIfRequestIncomplete(SocketInput input) { if (input.RemoteIntakeFin) { - ThrowRequestIncomplete(); + ThrowBadRequestException("Chunked request incomplete"); } } - private static int ThrowInvalidFormat() - { - // returns int so can be used as item non-void function - throw new InvalidOperationException("Bad request"); - } - - private static void ThrowRequestIncomplete() - { - throw new InvalidOperationException("Chunked request incomplete"); - } - private enum Mode { Prefix, diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/HttpComponentFactory.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/HttpComponentFactory.cs index f58102c1bb..5b346d73fd 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/HttpComponentFactory.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/HttpComponentFactory.cs @@ -34,9 +34,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure return streams; } - public void DisposeStreams(Streams streams, bool poolingPermitted) + public void DisposeStreams(Streams streams) { - if (poolingPermitted && _streamPool.Count < ServerInformation.PoolingParameters.MaxPooledStreams) + if (_streamPool.Count < ServerInformation.PoolingParameters.MaxPooledStreams) { streams.Uninitialize(); @@ -58,9 +58,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure return headers; } - public void DisposeHeaders(Headers headers, bool poolingPermitted) + public void DisposeHeaders(Headers headers) { - if (poolingPermitted && _headerPool.Count < ServerInformation.PoolingParameters.MaxPooledHeaders) + if (_headerPool.Count < ServerInformation.PoolingParameters.MaxPooledHeaders) { headers.Uninitialize(); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/IHttpComponentFactory.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/IHttpComponentFactory.cs index 620c663fbb..c64f039680 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/IHttpComponentFactory.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/IHttpComponentFactory.cs @@ -11,10 +11,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure Streams CreateStreams(FrameContext owner); - void DisposeStreams(Streams streams, bool poolingPermitted); + void DisposeStreams(Streams streams); Headers CreateHeaders(DateHeaderValueManager dateValueManager); - void DisposeHeaders(Headers headers, bool poolingPermitted); + void DisposeHeaders(Headers headers); } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/IKestrelTrace.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/IKestrelTrace.cs index b004cb9eee..b5460ecb4c 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/IKestrelTrace.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/IKestrelTrace.cs @@ -1,5 +1,6 @@ using System; using Microsoft.Extensions.Logging; +using Microsoft.AspNetCore.Server.Kestrel.Exceptions; namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure { @@ -33,6 +34,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure void ConnectionDisconnectedWrite(string connectionId, int count, Exception ex); + void ConnectionBadRequest(string connectionId, BadHttpRequestException ex); + void NotAllConnectionsClosedGracefully(); void ApplicationError(Exception ex); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/KestrelTrace.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/KestrelTrace.cs index 3c92c771ef..f3f12cbd1f 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/KestrelTrace.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/KestrelTrace.cs @@ -3,6 +3,7 @@ using System; using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Exceptions; using Microsoft.Extensions.Logging; namespace Microsoft.AspNetCore.Server.Kestrel @@ -24,6 +25,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel private static readonly Action _connectionError; private static readonly Action _connectionDisconnectedWrite; private static readonly Action _notAllConnectionsClosedGracefully; + private static readonly Action _connectionBadRequest; protected readonly ILogger _logger; @@ -45,6 +47,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel _connectionError = LoggerMessage.Define(LogLevel.Information, 14, @"Connection id ""{ConnectionId}"" communication error"); _connectionDisconnectedWrite = LoggerMessage.Define(LogLevel.Debug, 15, @"Connection id ""{ConnectionId}"" write of ""{count}"" bytes to disconnected client."); _notAllConnectionsClosedGracefully = LoggerMessage.Define(LogLevel.Debug, 16, "Some connections failed to close gracefully during server shutdown."); + _connectionBadRequest = LoggerMessage.Define(LogLevel.Information, 17, @"Connection id ""{ConnectionId}"" bad request data: ""{message}"""); } public KestrelTrace(ILogger logger) @@ -135,6 +138,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel _notAllConnectionsClosedGracefully(_logger, null); } + public void ConnectionBadRequest(string connectionId, BadHttpRequestException ex) + { + _connectionBadRequest(_logger, connectionId, ex.Message, ex); + } + public virtual void Log(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func formatter) { _logger.Log(logLevel, eventId, state, exception, formatter); diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedRequestTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedRequestTests.cs index 9408c44b14..f741539480 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedRequestTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedRequestTests.cs @@ -185,7 +185,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests while (await request.Body.ReadAsync(buffer, 0, buffer.Length) != 0) { - // read to end + ;// read to end } if (requestsReceived < requestCount) @@ -271,7 +271,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests while (await request.Body.ReadAsync(buffer, 0, buffer.Length) != 0) { - // read to end + ;// read to end } if (requestsReceived < requestCount) @@ -341,7 +341,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [Theory] [MemberData(nameof(ConnectionFilterData))] - public async Task InvalidLengthResultsIn500(ServiceContext testContext) + public async Task InvalidLengthResultsIn400(ServiceContext testContext) { using (var server = new TestServer(async httpContext => { @@ -367,14 +367,10 @@ namespace Microsoft.AspNetCore.Server.KestrelTests "POST / HTTP/1.1", "Transfer-Encoding: chunked", "", - "Cio", - "HelloChunked", - "0", - ""); + "Cii"); - // Should really be a 40x as is bad request await connection.Receive( - "HTTP/1.1 500 Internal Server Error", + "HTTP/1.1 400 Bad Request", ""); await connection.ReceiveStartsWith("Date:"); await connection.ReceiveEnd( @@ -388,7 +384,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [Theory] [MemberData(nameof(ConnectionFilterData))] - public async Task InvalidSizedDataResultsIn500(ServiceContext testContext) + public async Task InvalidSizedDataResultsIn400(ServiceContext testContext) { using (var server = new TestServer(async httpContext => { @@ -415,13 +411,10 @@ namespace Microsoft.AspNetCore.Server.KestrelTests "Transfer-Encoding: chunked", "", "C", - "HelloChunkedInvalid", - "0", - ""); + "HelloChunkedIn"); - // Should really be a 40x as is bad request await connection.Receive( - "HTTP/1.1 500 Internal Server Error", + "HTTP/1.1 400 Bad Request", ""); await connection.ReceiveStartsWith("Date:"); await connection.ReceiveEnd( diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs index 70c4454b53..78d46f5d6c 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs @@ -29,12 +29,18 @@ namespace Microsoft.AspNetCore.Server.KestrelTests using (var pool = new MemoryPool2()) using (var socketInput = new SocketInput(pool, ltp)) { + var connectionContext = new ConnectionContext() + { + DateHeaderValueManager = new DateHeaderValueManager(), + ServerAddress = ServerAddress.FromUrl("http://localhost:5000") + }; + var frame = new Frame(application: null, context: connectionContext); var headerCollection = new FrameRequestHeaders(); var headerArray = Encoding.ASCII.GetBytes(rawHeaders); socketInput.IncomingData(headerArray, 0, headerArray.Length); - var success = Frame.TakeMessageHeaders(socketInput, headerCollection); + var success = frame.TakeMessageHeaders(socketInput, headerCollection); Assert.True(success); Assert.Equal(numHeaders, headerCollection.Count()); From dab1a1fa8df6383c35777c27f0bb3ead68bdb0d8 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Sat, 27 Feb 2016 13:23:54 +0000 Subject: [PATCH 0631/1662] bug dodge: Invalid Program Excep on Clr --- src/Microsoft.AspNetCore.Server.Kestrel/Http/MessageBody.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/MessageBody.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/MessageBody.cs index f3f604f267..381b084048 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/MessageBody.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/MessageBody.cs @@ -224,7 +224,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http /// private class ForChunkedEncoding : MessageBody { - private static Vector _vectorCRs = new Vector((byte)'\r'); + private Vector _vectorCRs = new Vector((byte)'\r'); private int _inputLength; private Mode _mode = Mode.Prefix; From d4e20ae731d2a63d17ff381cb901e4e247820867 Mon Sep 17 00:00:00 2001 From: Victor Hurdugaci Date: Sat, 27 Feb 2016 12:51:12 -0800 Subject: [PATCH 0632/1662] Update the build scripts --- build.cmd | 41 ++----------------------------------- build.ps1 | 36 +++++++++++++++++++++++++++++++++ build.sh | 60 +++++++++++++++++++++++-------------------------------- 3 files changed, 63 insertions(+), 74 deletions(-) create mode 100644 build.ps1 diff --git a/build.cmd b/build.cmd index 95b049cf63..2fa024b15e 100644 --- a/build.cmd +++ b/build.cmd @@ -1,39 +1,2 @@ -@ECHO off -SETLOCAL - -SET REPO_FOLDER=%~dp0 -CD "%REPO_FOLDER%" - -SET BUILD_FOLDER=.build -SET KOREBUILD_FOLDER=%BUILD_FOLDER%\KoreBuild-dotnet -SET KOREBUILD_VERSION= - -SET NUGET_PATH=%BUILD_FOLDER%\NuGet.exe -SET NUGET_VERSION=latest -SET CACHED_NUGET=%LocalAppData%\NuGet\nuget.%NUGET_VERSION%.exe - -IF NOT EXIST %BUILD_FOLDER% ( - md %BUILD_FOLDER% -) - -IF NOT EXIST %NUGET_PATH% ( - IF NOT EXIST %CACHED_NUGET% ( - echo Downloading latest version of NuGet.exe... - IF NOT EXIST %LocalAppData%\NuGet ( - md %LocalAppData%\NuGet - ) - @powershell -NoProfile -ExecutionPolicy unrestricted -Command "$ProgressPreference = 'SilentlyContinue'; Invoke-WebRequest 'https://dist.nuget.org/win-x86-commandline/%NUGET_VERSION%/nuget.exe' -OutFile '%CACHED_NUGET%'" - ) - - copy %CACHED_NUGET% %NUGET_PATH% > nul -) - -SET KOREBUILD_DOWNLOAD_ARGS= -IF NOT "%KOREBUILD_VERSION%"=="" ( - SET KOREBUILD_DOWNLOAD_ARGS=-version %KOREBUILD_VERSION% -) -IF NOT EXIST %KOREBUILD_FOLDER% ( - %BUILD_FOLDER%\nuget.exe install KoreBuild-dotnet -ExcludeVersion -o %BUILD_FOLDER% -nocache -pre %KOREBUILD_DOWNLOAD_ARGS% -) - -"%KOREBUILD_FOLDER%\build\KoreBuild.cmd" %* +@ECHO OFF +PowerShell -NoProfile -NoLogo -ExecutionPolicy unrestricted -Command "[System.Threading.Thread]::CurrentThread.CurrentCulture = ''; [System.Threading.Thread]::CurrentThread.CurrentUICulture = '';& '%~dp0build.ps1' %*" \ No newline at end of file diff --git a/build.ps1 b/build.ps1 new file mode 100644 index 0000000000..4fd24a30d5 --- /dev/null +++ b/build.ps1 @@ -0,0 +1,36 @@ +cd $PSScriptRoot + +$repoFolder = $PSScriptRoot +$env:REPO_FOLDER = $repoFolder + +$koreBuildZip="https://github.com/aspnet/KoreBuild/archive/dev.zip" +if ($env:KOREBUILD_ZIP) +{ + $koreBuildZip=$env:KOREBUILD_ZIP +} + +$buildFolder = ".build" +$buildFile="$buildFolder\KoreBuild.ps1" + +if (!(Test-Path $buildFolder)) { + Write-Host "Downloading KoreBuild from $koreBuildZip" + + $tempFolder=$env:TEMP + "\KoreBuild-" + [guid]::NewGuid() + New-Item -Path "$tempFolder" -Type directory | Out-Null + + $localZipFile="$tempFolder\korebuild.zip" + + Invoke-WebRequest $koreBuildZip -OutFile $localZipFile + Add-Type -AssemblyName System.IO.Compression.FileSystem + [System.IO.Compression.ZipFile]::ExtractToDirectory($localZipFile, $tempFolder) + + New-Item -Path "$buildFolder" -Type directory | Out-Null + copy-item "$tempFolder\**\build\*" $buildFolder -Recurse + + # Cleanup + if (Test-Path $tempFolder) { + Remove-Item -Recurse -Force $tempFolder + } +} + +&"$buildFile" $args \ No newline at end of file diff --git a/build.sh b/build.sh index 263fb667a8..79638d06b6 100755 --- a/build.sh +++ b/build.sh @@ -1,45 +1,35 @@ #!/usr/bin/env bash +repoFolder="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +cd $repoFolder -buildFolder=.build -koreBuildFolder=$buildFolder/KoreBuild-dotnet - -nugetPath=$buildFolder/nuget.exe - -if test `uname` = Darwin; then - cachedir=~/Library/Caches/KBuild -else - if [ -z $XDG_DATA_HOME ]; then - cachedir=$HOME/.local/share - else - cachedir=$XDG_DATA_HOME; - fi +koreBuildZip="https://github.com/aspnet/KoreBuild/archive/dev.zip" +if [ ! -z $KOREBUILD_ZIP ]; then + koreBuildZip=$KOREBUILD_ZIP fi -mkdir -p $cachedir -nugetVersion=latest -cacheNuget=$cachedir/nuget.$nugetVersion.exe -nugetUrl=https://dist.nuget.org/win-x86-commandline/$nugetVersion/nuget.exe +buildFolder=".build" +buildFile="$buildFolder/KoreBuild.sh" if test ! -d $buildFolder; then + echo "Downloading KoreBuild from $koreBuildZip" + + tempFolder="/tmp/KoreBuild-$(uuidgen)" + mkdir $tempFolder + + localZipFile="$tempFolder/korebuild.zip" + + wget -O $localZipFile $koreBuildZip 2>/dev/null || curl -o $localZipFile --location $koreBuildZip /dev/null + unzip -q -d $tempFolder $localZipFile + mkdir $buildFolder -fi - -if test ! -f $nugetPath; then - if test ! -f $cacheNuget; then - wget -O $cacheNuget $nugetUrl 2>/dev/null || curl -o $cacheNuget --location $nugetUrl /dev/null + cp -r $tempFolder/**/build/** $buildFolder + + chmod +x $buildFile + + # Cleanup + if test ! -d $tempFolder; then + rm -rf $tempFolder fi - - cp $cacheNuget $nugetPath fi -if test ! -d $koreBuildFolder; then - mono $nugetPath install KoreBuild-dotnet -ExcludeVersion -o $buildFolder -nocache -pre - chmod +x $koreBuildFolder/build/KoreBuild.sh -fi - -makeFile=makefile.shade -if [ ! -e $makeFile ]; then - makeFile=$koreBuildFolder/build/makefile.shade -fi - -./$koreBuildFolder/build/KoreBuild.sh -n $nugetPath -m $makeFile "$@" +$buildFile -r $repoFolder "$@" From 0182e4194fc0690905c465f1ab4962bb0ec334b4 Mon Sep 17 00:00:00 2001 From: Victor Hurdugaci Date: Sun, 28 Feb 2016 10:12:15 -0800 Subject: [PATCH 0633/1662] Return the error code from build.cmd --- build.cmd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.cmd b/build.cmd index 2fa024b15e..7d4894cb4a 100644 --- a/build.cmd +++ b/build.cmd @@ -1,2 +1,2 @@ @ECHO OFF -PowerShell -NoProfile -NoLogo -ExecutionPolicy unrestricted -Command "[System.Threading.Thread]::CurrentThread.CurrentCulture = ''; [System.Threading.Thread]::CurrentThread.CurrentUICulture = '';& '%~dp0build.ps1' %*" \ No newline at end of file +PowerShell -NoProfile -NoLogo -ExecutionPolicy unrestricted -Command "[System.Threading.Thread]::CurrentThread.CurrentCulture = ''; [System.Threading.Thread]::CurrentThread.CurrentUICulture = '';& '%~dp0build.ps1' %*; exit $LASTEXITCODE" \ No newline at end of file From c33b422d7ad0c53d4653f574a956cf292bd17660 Mon Sep 17 00:00:00 2001 From: "N. Taylor Mullen" Date: Tue, 1 Mar 2016 13:36:06 -0800 Subject: [PATCH 0634/1662] Transition to netstandard. - dotnet5.X => netstandard1.y (where y = x-1). - DNXCore50 => netstandardapp1.5. - Applied the same changes to ifdefs. --- samples/LargeResponseApp/project.json | 15 ++++--- samples/SampleApp/project.json | 15 ++++--- .../HttpsConnectionFilter.cs | 2 +- .../project.json | 15 ++++--- .../Infrastructure/TaskUtilities.cs | 4 +- .../Networking/PlatformApis.cs | 2 +- .../project.json | 15 ++++--- .../project.json | 7 ++- .../project.json | 7 ++- .../project.json | 45 ++++++++++--------- .../project.json | 11 +++-- 11 files changed, 85 insertions(+), 53 deletions(-) diff --git a/samples/LargeResponseApp/project.json b/samples/LargeResponseApp/project.json index b6aa0ce9e4..47f829ef1f 100644 --- a/samples/LargeResponseApp/project.json +++ b/samples/LargeResponseApp/project.json @@ -15,12 +15,17 @@ "emitEntryPoint": true }, "frameworks": { - "dnx451": { }, - "dnxcore50": { + "dnx451": {}, + "netstandardapp1.5": { "dependencies": { "NETStandard.Library": "1.0.0-*" - } + }, + "imports": [ + "dnxcore50" + ] } }, - "content": [ "hosting.json" ] -} + "content": [ + "hosting.json" + ] +} \ No newline at end of file diff --git a/samples/SampleApp/project.json b/samples/SampleApp/project.json index 6a1bc65da8..a561218cbb 100644 --- a/samples/SampleApp/project.json +++ b/samples/SampleApp/project.json @@ -17,13 +17,18 @@ "emitEntryPoint": true }, "frameworks": { - "dnx451": { }, - "dnxcore50": { + "dnx451": {}, + "netstandardapp1.5": { "dependencies": { "NETStandard.Library": "1.0.0-*", "System.Console": "4.0.0-*" - } + }, + "imports": [ + "dnxcore50" + ] } }, - "content": [ "hosting.json" ] -} + "content": [ + "hosting.json" + ] +} \ No newline at end of file diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Https/HttpsConnectionFilter.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Https/HttpsConnectionFilter.cs index 55f1fc1ab7..4bde587233 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Https/HttpsConnectionFilter.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Https/HttpsConnectionFilter.cs @@ -71,7 +71,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Https X509Certificate2 certificate2 = certificate as X509Certificate2; if (certificate2 == null) { -#if DOTNET5_4 +#if NETSTANDARD1_3 // conversion X509Certificate to X509Certificate2 not supported // https://github.com/dotnet/corefx/issues/4510 return false; diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Https/project.json b/src/Microsoft.AspNetCore.Server.Kestrel.Https/project.json index 3038d7e4b9..ab7dfc0600 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Https/project.json +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Https/project.json @@ -2,7 +2,9 @@ "version": "1.0.0-*", "compilationOptions": { "keyFile": "../../tools/Key.snk", - "nowarn": [ "CS1591" ], + "nowarn": [ + "CS1591" + ], "xmlDoc": true }, "description": "Adds HTTPS support to Kestrel", @@ -14,12 +16,15 @@ "Microsoft.AspNetCore.Server.Kestrel": "1.0.0-*" }, "frameworks": { - "net451": { }, - "dotnet5.4": { + "net451": {}, + "netstandard1.3": { "dependencies": { "System.Net.Security": "4.0.0-*" }, - "imports": "portable-net45+win8" + "imports": [ + "dotnet5.4", + "portable-net45+win8" + ] } } -} +} \ No newline at end of file diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/TaskUtilities.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/TaskUtilities.cs index 5e52222d3d..8935ac7bda 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/TaskUtilities.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/TaskUtilities.cs @@ -8,7 +8,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure { public static class TaskUtilities { -#if DOTNET5_4 +#if NETSTANDARD1_3 public static Task CompletedTask = Task.CompletedTask; #else public static Task CompletedTask = Task.FromResult(null); @@ -17,7 +17,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure public static Task GetCancelledTask(CancellationToken cancellationToken) { -#if DOTNET5_4 +#if NETSTANDARD1_3 return Task.FromCanceled(cancellationToken); #else var tcs = new TaskCompletionSource(); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Networking/PlatformApis.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Networking/PlatformApis.cs index be22ef7120..29265b3538 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Networking/PlatformApis.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Networking/PlatformApis.cs @@ -11,7 +11,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Networking { static PlatformApis() { -#if DOTNET5_4 +#if NETSTANDARD1_3 IsWindows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows); IsDarwin = RuntimeInformation.IsOSPlatform(OSPlatform.OSX); #else diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/project.json b/src/Microsoft.AspNetCore.Server.Kestrel/project.json index 65fe9a1238..8ba4577a3a 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/project.json +++ b/src/Microsoft.AspNetCore.Server.Kestrel/project.json @@ -8,7 +8,7 @@ "dependencies": { "System.Buffers": "4.0.0-*", "System.Numerics.Vectors": "4.1.1-*", - "System.Threading.Tasks.Extensions": "4.0.0-*", + "System.Threading.Tasks.Extensions": "4.0.0-*", "Microsoft.AspNetCore.Hosting": "1.0.0-*", "Microsoft.Extensions.Logging.Abstractions": "1.0.0-*", "Microsoft.Extensions.PlatformAbstractions": "1.0.0-*", @@ -27,7 +27,7 @@ "System.Threading.Tasks": "" } }, - "dotnet5.4": { + "netstandard1.3": { "dependencies": { "System.Collections": "4.0.11-*", "System.Diagnostics.Debug": "4.0.11-*", @@ -46,13 +46,18 @@ "System.Threading.ThreadPool": "4.0.10-*", "System.Threading.Timer": "4.0.1-*" }, - "imports": "portable-net45+win8" + "imports": [ + "dotnet5.4", + "portable-net45+win8" + ] } }, "compilationOptions": { "allowUnsafe": true, "keyFile": "../../tools/Key.snk", - "nowarn": [ "CS1591" ], + "nowarn": [ + "CS1591" + ], "xmlDoc": true }, "packInclude": { @@ -62,4 +67,4 @@ "runtimes/win7-arm/native/": "runtimes/win7-arm/native/*", "runtimes/osx/native/": "runtimes/osx/native/*" } -} +} \ No newline at end of file diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json index cf00be722c..6c48e9a588 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json @@ -16,12 +16,15 @@ } }, "frameworks": { - "dnxcore50": { + "netstandardapp1.5": { "dependencies": { "dotnet-test-xunit": "1.0.0-dev-*", "System.Net.Http": "4.0.1-*" }, - "imports": "portable-net451+win8" + "imports": [ + "dnxcore50", + "portable-net451+win8" + ] }, "net451": { "dependencies": { diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/project.json b/test/Microsoft.AspNetCore.Server.KestrelTests/project.json index aca952eb04..6ccf5d02ee 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/project.json +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/project.json @@ -16,7 +16,7 @@ } }, "frameworks": { - "dnxcore50": { + "netstandardapp1.5": { "dependencies": { "System.Diagnostics.TraceSource": "4.0.0-*", "System.Globalization.Extensions": "4.0.1-*", @@ -27,7 +27,10 @@ "System.Runtime.Handles": "4.0.1-*", "dotnet-test-xunit": "1.0.0-dev-*" }, - "imports": "portable-net451+win8" + "imports": [ + "dnxcore50", + "portable-net451+win8" + ] }, "net451": { "dependencies": { diff --git a/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/project.json b/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/project.json index cbc156008c..80a11446bc 100644 --- a/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/project.json +++ b/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/project.json @@ -1,24 +1,27 @@ { - "version": "1.0.0-*", - "compilationOptions": { - "emitEntryPoint": true + "version": "1.0.0-*", + "compilationOptions": { + "emitEntryPoint": true + }, + "dependencies": { + "Microsoft.AspNetCore.Http.Features": "1.0.0-*", + "Microsoft.AspNetCore.Hosting": "1.0.0-*" + }, + "frameworks": { + "netstandardapp1.5": { + "dependencies": { + "NETStandard.Library": "1.0.0-*" + }, + "imports": [ + "dnxcore50" + ] }, - "dependencies": { - "Microsoft.AspNetCore.Http.Features": "1.0.0-*", - "Microsoft.AspNetCore.Hosting": "1.0.0-*" - }, - "frameworks": { - "dnxcore50": { - "dependencies": { - "NETStandard.Library": "1.0.0-*" - } - }, - "dnx451": { - "frameworkAssemblies": { - "System.Runtime": "", - "System.Text.Encoding": "", - "System.Threading.Tasks": "" - } - } + "dnx451": { + "frameworkAssemblies": { + "System.Runtime": "", + "System.Text.Encoding": "", + "System.Threading.Tasks": "" + } } -} + } +} \ No newline at end of file diff --git a/tools/Microsoft.AspNetCore.Server.Kestrel.LibuvCopier/project.json b/tools/Microsoft.AspNetCore.Server.Kestrel.LibuvCopier/project.json index 04573cf16e..a498a5cc58 100644 --- a/tools/Microsoft.AspNetCore.Server.Kestrel.LibuvCopier/project.json +++ b/tools/Microsoft.AspNetCore.Server.Kestrel.LibuvCopier/project.json @@ -8,12 +8,15 @@ "Newtonsoft.Json": "8.0.2" }, "frameworks": { - "dnxcore50": { + "netstandardapp1.5": { "dependencies": { "NETStandard.Library": "1.0.0-*", "System.Dynamic.Runtime": "4.0.11-*" - } + }, + "imports": [ + "dnxcore50" + ] }, - "dnx451": { } + "dnx451": {} } -} +} \ No newline at end of file From 9c64a492615e2fa9153021438fd053301e9a3d4a Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Tue, 1 Mar 2016 15:58:00 -0800 Subject: [PATCH 0635/1662] Enable OSX builds on Travis (#660). --- .travis.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.travis.yml b/.travis.yml index 4e6d418f80..36f2784903 100644 --- a/.travis.yml +++ b/.travis.yml @@ -22,6 +22,9 @@ install: - cd $OLDPWD mono: - 4.0.5 +os: + - linux + - osx osx_image: xcode7.1 script: - ./build.sh --quiet verify From 4e5920fd09eb2deb4acb04f1054f9026cb7e4d3a Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Mon, 29 Feb 2016 10:35:43 -0800 Subject: [PATCH 0636/1662] KestrelThread.Stop should wait for StartAsync to complete - Previously KestrelThread.Stop might assume start failed prematurely - This could cause a background thread to run indefinitely in the background --- .../Infrastructure/KestrelThread.cs | 36 +++++++++++-------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/KestrelThread.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/KestrelThread.cs index d8cb804fbb..2b6d2ab0a5 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/KestrelThread.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/KestrelThread.cs @@ -35,7 +35,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel private Queue _workRunning = new Queue(1024); private Queue _closeHandleAdding = new Queue(256); private Queue _closeHandleRunning = new Queue(256); - private readonly object _workSync = new Object(); + private readonly object _workSync = new object(); + private readonly object _startSync = new object(); private bool _stopImmediate = false; private bool _initCompleted = false; private ExceptionDispatchInfo _closeError; @@ -84,9 +85,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel public void Stop(TimeSpan timeout) { - if (!_initCompleted) + lock (_startSync) { - return; + if (!_initCompleted) + { + return; + } } if (_thread.IsAlive) @@ -209,20 +213,22 @@ namespace Microsoft.AspNetCore.Server.Kestrel private void ThreadStart(object parameter) { - var tcs = (TaskCompletionSource)parameter; - try + lock (_startSync) { - _loop.Init(_engine.Libuv); - _post.Init(_loop, OnPost, EnqueueCloseHandle); - tcs.SetResult(0); + var tcs = (TaskCompletionSource)parameter; + try + { + _loop.Init(_engine.Libuv); + _post.Init(_loop, OnPost, EnqueueCloseHandle); + _initCompleted = true; + tcs.SetResult(0); + } + catch (Exception ex) + { + tcs.SetException(ex); + return; + } } - catch (Exception ex) - { - tcs.SetException(ex); - return; - } - - _initCompleted = true; try { From 41f77ee3fd14df9d666efd3662803ae4294b4947 Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Fri, 26 Feb 2016 14:11:34 -0800 Subject: [PATCH 0637/1662] Handle uploads larger than 2GB. --- .../Http/MessageBody.cs | 13 +-- .../RequestTests.cs | 84 ++++++++++++------- 2 files changed, 63 insertions(+), 34 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/MessageBody.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/MessageBody.cs index 381b084048..d4072572f8 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/MessageBody.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/MessageBody.cs @@ -122,8 +122,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http var unparsedContentLength = headers.HeaderContentLength.ToString(); if (unparsedContentLength.Length > 0) { - int contentLength; - if (!int.TryParse(unparsedContentLength, out contentLength) || contentLength < 0) + long contentLength; + if (!long.TryParse(unparsedContentLength, out contentLength) || contentLength < 0) { context.ReportCorruptedHttpRequest(new BadHttpRequestException("Invalid content length.")); return new ForContentLength(keepAlive, 0, context); @@ -166,10 +166,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http private class ForContentLength : MessageBody { - private readonly int _contentLength; - private int _inputLength; + private readonly long _contentLength; + private long _inputLength; - public ForContentLength(bool keepAlive, int contentLength, Frame context) + public ForContentLength(bool keepAlive, long contentLength, Frame context) : base(context) { RequestKeepAlive = keepAlive; @@ -181,7 +181,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { var input = _context.SocketInput; - var limit = buffer.Array == null ? _inputLength : Math.Min(buffer.Count, _inputLength); + var inputLengthLimit = (int)Math.Min(_inputLength, int.MaxValue); + var limit = buffer.Array == null ? inputLengthLimit : Math.Min(buffer.Count, inputLengthLimit); if (limit == 0) { return 0; diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs index 5c73e751f2..db7a6800f2 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs @@ -1,7 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System.Collections.Generic; +using System; using System.Globalization; using System.Net.Http; using System.Net.Sockets; @@ -11,7 +11,6 @@ using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Testing.xunit; -using Microsoft.Extensions.Configuration; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using Xunit; @@ -24,16 +23,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests public async Task LargeUpload() { var port = PortManager.GetPort(); - var config = new ConfigurationBuilder() - .AddInMemoryCollection(new Dictionary - { - { "server.urls", $"http://localhost:{port}/" } - }) - .Build(); - var builder = new WebHostBuilder() - .UseConfiguration(config) .UseServer("Microsoft.AspNetCore.Server.Kestrel") + .UseUrls($"http://localhost:{port}/") .Configure(app => { app.Run(async context => @@ -76,6 +68,57 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } } + [ConditionalFact] + [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Fails on Mono on Mac because it is not 64-bit.")] + public async Task LargeMultipartUpload() + { + var port = PortManager.GetPort(); + var builder = new WebHostBuilder() + .UseServer("Microsoft.AspNetCore.Server.Kestrel") + .UseUrls($"http://localhost:{port}/") + .Configure(app => + { + app.Run(async context => + { + long total = 0; + var bytes = new byte[1024]; + var count = await context.Request.Body.ReadAsync(bytes, 0, bytes.Length); + while (count > 0) + { + total += count; + count = await context.Request.Body.ReadAsync(bytes, 0, bytes.Length); + } + await context.Response.WriteAsync(total.ToString(CultureInfo.InvariantCulture)); + }); + }); + + using (var host = builder.Build()) + { + host.Start(); + + using (var client = new HttpClient()) + { + using (var form = new MultipartFormDataContent()) + { + const int oneMegabyte = 1024 * 1024; + const int files = 2048; + var bytes = new byte[oneMegabyte]; + + for (int i = 0; i < files; i++) + { + var fileName = Guid.NewGuid().ToString(); + form.Add(new ByteArrayContent(bytes), "file", fileName); + } + + var length = form.Headers.ContentLength.Value; + var response = await client.PostAsync($"http://localhost:{port}/", form); + response.EnsureSuccessStatusCode(); + Assert.Equal(length.ToString(CultureInfo.InvariantCulture), await response.Content.ReadAsStringAsync()); + } + } + } + } + [Theory] [InlineData("127.0.0.1", "127.0.0.1")] [InlineData("localhost", "127.0.0.1")] @@ -95,14 +138,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests public async Task DoesNotHangOnConnectionCloseRequest() { var port = PortManager.GetPort(); - var config = new ConfigurationBuilder().AddInMemoryCollection( - new Dictionary { - { "server.urls", $"http://localhost:{port}" } - }).Build(); - var builder = new WebHostBuilder() - .UseConfiguration(config) .UseServer("Microsoft.AspNetCore.Server.Kestrel") + .UseUrls($"http://localhost:{port}") .Configure(app => { app.Run(async context => @@ -129,14 +167,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests public void RequestPathIsNormalized() { var port = PortManager.GetPort(); - var config = new ConfigurationBuilder().AddInMemoryCollection( - new Dictionary { - { "server.urls", $"http://localhost:{port}/\u0041\u030A" } - }).Build(); - var builder = new WebHostBuilder() - .UseConfiguration(config) .UseServer("Microsoft.AspNetCore.Server.Kestrel") + .UseUrls($"http://localhost:{port}/\u0041\u030A") .Configure(app => { app.Run(async context => @@ -178,14 +211,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests private async Task TestRemoteIPAddress(string registerAddress, string requestAddress, string expectAddress) { var port = PortManager.GetPort(); - var config = new ConfigurationBuilder().AddInMemoryCollection( - new Dictionary { - { "server.urls", $"http://{registerAddress}:{port}" } - }).Build(); - var builder = new WebHostBuilder() - .UseConfiguration(config) .UseServer("Microsoft.AspNetCore.Server.Kestrel") + .UseUrls($"http://{registerAddress}:{port}") .Configure(app => { app.Run(async context => From bb2e76c7f1a23fe4fbe0a97b29a04bfe06b7efde Mon Sep 17 00:00:00 2001 From: Doug Bunting Date: Wed, 2 Mar 2016 18:57:07 -0800 Subject: [PATCH 0638/1662] Remove project name from output path - aspnet/Coherence-Signed#187 - remove `` settings but maintain other unique aspects e.g. `` - in a few cases, standardize on VS version `14.0` and not something more specific --- samples/LargeResponseApp/LargeResponseApp.xproj | 3 +-- samples/SampleApp/SampleApp.xproj | 2 +- .../Microsoft.AspNetCore.Server.Kestrel.Https.xproj | 9 +++------ .../Microsoft.AspNetCore.Server.Kestrel.xproj | 2 +- ...osoft.AspNetCore.Server.Kestrel.FunctionalTests.xproj | 5 ++--- .../Microsoft.AspNetCore.Server.KestrelTests.xproj | 2 +- ...crosoft.AspNetCore.Server.Kestrel.GeneratedCode.xproj | 9 +++------ ...Microsoft.AspNetCore.Server.Kestrel.LibuvCopier.xproj | 9 +++------ 8 files changed, 15 insertions(+), 26 deletions(-) diff --git a/samples/LargeResponseApp/LargeResponseApp.xproj b/samples/LargeResponseApp/LargeResponseApp.xproj index 48abc5f22c..ffc0ba931a 100644 --- a/samples/LargeResponseApp/LargeResponseApp.xproj +++ b/samples/LargeResponseApp/LargeResponseApp.xproj @@ -7,9 +7,8 @@ b35d4d31-e74c-4646-8a11-7a7a40f0021e - LargeResponseApp ..\..\artifacts\obj\$(MSBuildProjectName) - ..\..\artifacts\bin\$(MSBuildProjectName)\ + ..\..\artifacts\bin\ 2.0 diff --git a/samples/SampleApp/SampleApp.xproj b/samples/SampleApp/SampleApp.xproj index 043c9b1b41..eb656e8acc 100644 --- a/samples/SampleApp/SampleApp.xproj +++ b/samples/SampleApp/SampleApp.xproj @@ -8,7 +8,7 @@ 2c3cb3dc-eebf-4f52-9e1c-4f2f972e76c3 ..\..\artifacts\obj\$(MSBuildProjectName) - ..\..\artifacts\bin\$(MSBuildProjectName)\ + ..\..\artifacts\bin\ 2.0 diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Https/Microsoft.AspNetCore.Server.Kestrel.Https.xproj b/src/Microsoft.AspNetCore.Server.Kestrel.Https/Microsoft.AspNetCore.Server.Kestrel.Https.xproj index 31375db430..0a0bc4da18 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Https/Microsoft.AspNetCore.Server.Kestrel.Https.xproj +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Https/Microsoft.AspNetCore.Server.Kestrel.Https.xproj @@ -1,20 +1,17 @@ - + 14.0 $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) - 5f64b3c3-0c2e-431a-b820-a81bbfc863da - Microsoft.AspNetCore.Server.Kestrel.Https ..\..\artifacts\obj\$(MSBuildProjectName) - ..\..\artifacts\bin\$(MSBuildProjectName)\ + ..\..\artifacts\bin\ - 2.0 - + \ No newline at end of file diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Microsoft.AspNetCore.Server.Kestrel.xproj b/src/Microsoft.AspNetCore.Server.Kestrel/Microsoft.AspNetCore.Server.Kestrel.xproj index e31ba32074..586763ad5a 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Microsoft.AspNetCore.Server.Kestrel.xproj +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Microsoft.AspNetCore.Server.Kestrel.xproj @@ -8,7 +8,7 @@ f510611a-3bee-4b88-a613-5f4a74ed82a1 ..\..\artifacts\obj\$(MSBuildProjectName) - ..\..\artifacts\bin\$(MSBuildProjectName)\ + ..\..\artifacts\bin\ 2.0 diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests.xproj b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests.xproj index 01f50a011e..2e53dbe9cb 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests.xproj +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests.xproj @@ -1,4 +1,4 @@ - + 14.0 @@ -7,9 +7,8 @@ 9559a5f1-080c-4909-b6cf-7e4b3dc55748 - Microsoft.AspNetCore.Server.Kestrel.FunctionalTests ..\..\artifacts\obj\$(MSBuildProjectName) - ..\..\artifacts\bin\$(MSBuildProjectName)\ + ..\..\artifacts\bin\ 2.0 diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/Microsoft.AspNetCore.Server.KestrelTests.xproj b/test/Microsoft.AspNetCore.Server.KestrelTests/Microsoft.AspNetCore.Server.KestrelTests.xproj index 59c2109f9e..11118f9543 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/Microsoft.AspNetCore.Server.KestrelTests.xproj +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/Microsoft.AspNetCore.Server.KestrelTests.xproj @@ -8,7 +8,7 @@ 37f3bfb2-6454-49e5-9d7f-581bf755ccfe ..\..\artifacts\obj\$(MSBuildProjectName) - ..\..\artifacts\bin\$(MSBuildProjectName)\ + ..\..\artifacts\bin\ 2.0 diff --git a/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode.xproj b/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode.xproj index f539350093..6970817548 100644 --- a/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode.xproj +++ b/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode.xproj @@ -1,20 +1,17 @@ - + 14.0 $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) - bd2d4d29-1bd9-40d0-bb31-337d5416b63c - Microsoft.AspNetCore.Server.Kestrel.GeneratedCode ..\..\artifacts\obj\$(MSBuildProjectName) - ..\..\artifacts\bin\$(MSBuildProjectName)\ + ..\..\artifacts\bin\ - 2.0 - + \ No newline at end of file diff --git a/tools/Microsoft.AspNetCore.Server.Kestrel.LibuvCopier/Microsoft.AspNetCore.Server.Kestrel.LibuvCopier.xproj b/tools/Microsoft.AspNetCore.Server.Kestrel.LibuvCopier/Microsoft.AspNetCore.Server.Kestrel.LibuvCopier.xproj index 2e3d5e6e7b..c26e1d6b79 100644 --- a/tools/Microsoft.AspNetCore.Server.Kestrel.LibuvCopier/Microsoft.AspNetCore.Server.Kestrel.LibuvCopier.xproj +++ b/tools/Microsoft.AspNetCore.Server.Kestrel.LibuvCopier/Microsoft.AspNetCore.Server.Kestrel.LibuvCopier.xproj @@ -1,20 +1,17 @@ - + 14.0 $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) - 8cba6fe3-3cc9-4420-8aa3-123e983734c2 - Microsoft.AspNetCore.Server.Kestrel.LibuvCopier ..\..\artifacts\obj\$(MSBuildProjectName) - ..\..\artifacts\bin\$(MSBuildProjectName)\ + ..\..\artifacts\bin\ - 2.0 - + \ No newline at end of file From f15471bcf251078f768c5dcfdc070ce55155becb Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Wed, 2 Mar 2016 15:18:52 -0800 Subject: [PATCH 0639/1662] Remove 2 from MemoryPool2 and related types - This was merely an artifact from when this was the second of 2 pools --- .../Filter/FilteredStreamAdapter.cs | 6 +-- .../Filter/StreamExtensions.cs | 2 +- .../Filter/StreamSocketOutput.cs | 12 ++--- .../Http/ChunkWriter.cs | 4 +- .../Http/Connection.cs | 6 +-- .../Http/FrameHeaders.Generated.cs | 2 +- .../Http/FrameResponseHeaders.cs | 2 +- .../Http/ISocketOutput.cs | 8 ++-- .../Http/Listener.cs | 2 +- .../Http/ListenerContext.cs | 6 +-- .../Http/ListenerSecondary.cs | 2 +- .../Http/SocketInput.cs | 26 +++++------ .../Http/SocketOutput.cs | 44 +++++++++---------- .../Http/UrlPathDecoder.cs | 12 ++--- .../{MemoryPool2.cs => MemoryPool.cs} | 24 +++++----- ...MemoryPoolBlock2.cs => MemoryPoolBlock.cs} | 26 +++++------ ...PoolIterator2.cs => MemoryPoolIterator.cs} | 18 ++++---- ...ons.cs => MemoryPoolIteratorExtensions.cs} | 14 +++--- .../{MemoryPoolSlab2.cs => MemoryPoolSlab.cs} | 8 ++-- .../Networking/UvWriteReq.cs | 4 +- .../AsciiDecoder.cs | 16 +++---- .../ConnectionTests.cs | 4 +- .../FrameTests.cs | 2 +- ...Block2Tests.cs => MemoryPoolBlockTests.cs} | 20 ++++----- .../MemoryPoolExtensions.cs | 2 +- ...or2Tests.cs => MemoryPoolIteratorTests.cs} | 40 ++++++++--------- .../MultipleLoopTests.cs | 6 +-- .../NetworkingTests.cs | 6 +-- .../SocketInputTests.cs | 4 +- .../SocketOutputTests.cs | 16 +++---- .../TestInput.cs | 4 +- .../UrlPathDecoder.cs | 6 +-- .../KnownHeaders.cs | 2 +- 33 files changed, 178 insertions(+), 178 deletions(-) rename src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/{MemoryPool2.cs => MemoryPool.cs} (91%) rename src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/{MemoryPoolBlock2.cs => MemoryPoolBlock.cs} (92%) rename src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/{MemoryPoolIterator2.cs => MemoryPoolIterator.cs} (97%) rename src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/{MemoryPoolIterator2Extensions.cs => MemoryPoolIteratorExtensions.cs} (97%) rename src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/{MemoryPoolSlab2.cs => MemoryPoolSlab.cs} (95%) rename test/Microsoft.AspNetCore.Server.KestrelTests/{MemoryPoolBlock2Tests.cs => MemoryPoolBlockTests.cs} (95%) rename test/Microsoft.AspNetCore.Server.KestrelTests/{MemoryPoolIterator2Tests.cs => MemoryPoolIteratorTests.cs} (92%) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Filter/FilteredStreamAdapter.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Filter/FilteredStreamAdapter.cs index d93888ffb5..2fa981ceb4 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Filter/FilteredStreamAdapter.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Filter/FilteredStreamAdapter.cs @@ -15,12 +15,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Filter private readonly Stream _filteredStream; private readonly Stream _socketInputStream; private readonly IKestrelTrace _log; - private readonly MemoryPool2 _memory; - private MemoryPoolBlock2 _block; + private readonly MemoryPool _memory; + private MemoryPoolBlock _block; public FilteredStreamAdapter( Stream filteredStream, - MemoryPool2 memory, + MemoryPool memory, IKestrelTrace logger, IThreadPool threadPool) { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Filter/StreamExtensions.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Filter/StreamExtensions.cs index ccf0a47384..c01682327d 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Filter/StreamExtensions.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Filter/StreamExtensions.cs @@ -9,7 +9,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Filter { public static class StreamExtensions { - public static async Task CopyToAsync(this Stream source, Stream destination, MemoryPoolBlock2 block) + public static async Task CopyToAsync(this Stream source, Stream destination, MemoryPoolBlock block) { int bytesRead; while ((bytesRead = await source.ReadAsync(block.Array, block.Data.Offset, block.Data.Count)) != 0) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Filter/StreamSocketOutput.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Filter/StreamSocketOutput.cs index 4b6b335c77..7460cefdb1 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Filter/StreamSocketOutput.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Filter/StreamSocketOutput.cs @@ -17,12 +17,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Filter private static readonly byte[] _nullBuffer = new byte[0]; private readonly Stream _outputStream; - private readonly MemoryPool2 _memory; - private MemoryPoolBlock2 _producingBlock; + private readonly MemoryPool _memory; + private MemoryPoolBlock _producingBlock; private object _writeLock = new object(); - public StreamSocketOutput(Stream outputStream, MemoryPool2 memory) + public StreamSocketOutput(Stream outputStream, MemoryPool memory) { _outputStream = outputStream; _memory = memory; @@ -54,13 +54,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Filter return TaskUtilities.CompletedTask; } - public MemoryPoolIterator2 ProducingStart() + public MemoryPoolIterator ProducingStart() { _producingBlock = _memory.Lease(); - return new MemoryPoolIterator2(_producingBlock); + return new MemoryPoolIterator(_producingBlock); } - public void ProducingComplete(MemoryPoolIterator2 end) + public void ProducingComplete(MemoryPoolIterator end) { var block = _producingBlock; while (block != end.Block) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/ChunkWriter.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/ChunkWriter.cs index e6f99c9d53..62dd3499ad 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/ChunkWriter.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/ChunkWriter.cs @@ -47,14 +47,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http return new ArraySegment(bytes, offset, 10 - offset); } - public static int WriteBeginChunkBytes(ref MemoryPoolIterator2 start, int dataCount) + public static int WriteBeginChunkBytes(ref MemoryPoolIterator start, int dataCount) { var chunkSegment = BeginChunkBytes(dataCount); start.CopyFrom(chunkSegment); return chunkSegment.Count; } - public static void WriteEndChunkBytes(ref MemoryPoolIterator2 start) + public static void WriteEndChunkBytes(ref MemoryPoolIterator start) { start.CopyFrom(_endChunkBytes); } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Connection.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Connection.cs index c0de2ed3b3..3280c4082a 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Connection.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Connection.cs @@ -46,8 +46,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ConnectionId = GenerateConnectionId(Interlocked.Increment(ref _lastConnectionId)); - _rawSocketInput = new SocketInput(Memory2, ThreadPool); - _rawSocketOutput = new SocketOutput(Thread, _socket, Memory2, this, ConnectionId, Log, ThreadPool, WriteReqPool); + _rawSocketInput = new SocketInput(Memory, ThreadPool); + _rawSocketOutput = new SocketOutput(Thread, _socket, Memory, this, ConnectionId, Log, ThreadPool, WriteReqPool); } // Internal for testing @@ -206,7 +206,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if (_filterContext.Connection != _libuvStream) { - var filteredStreamAdapter = new FilteredStreamAdapter(_filterContext.Connection, Memory2, Log, ThreadPool); + var filteredStreamAdapter = new FilteredStreamAdapter(_filterContext.Connection, Memory, Log, ThreadPool); SocketInput = filteredStreamAdapter.SocketInput; SocketOutput = filteredStreamAdapter.SocketOutput; diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameHeaders.Generated.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameHeaders.Generated.cs index e8a93d9b4d..3d9ccbaf3c 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameHeaders.Generated.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameHeaders.Generated.cs @@ -8993,7 +8993,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ((ICollection>)MaybeUnknown)?.CopyTo(array, arrayIndex); } - protected void CopyToFast(ref MemoryPoolIterator2 output) + protected void CopyToFast(ref MemoryPoolIterator output) { if (((_bits & 1L) != 0)) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameResponseHeaders.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameResponseHeaders.cs index 08b9deca0e..c843e96255 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameResponseHeaders.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameResponseHeaders.cs @@ -30,7 +30,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http return GetEnumerator(); } - public void CopyTo(ref MemoryPoolIterator2 output) + public void CopyTo(ref MemoryPoolIterator output) { CopyToFast(ref output); if (MaybeUnknown != null) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/ISocketOutput.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/ISocketOutput.cs index c526caedf9..51c95b13fe 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/ISocketOutput.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/ISocketOutput.cs @@ -18,10 +18,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http /// /// Returns an iterator pointing to the tail of the response buffer. Response data can be appended - /// manually or by using . - /// Be careful to ensure all appended blocks are backed by a . + /// manually or by using . + /// Be careful to ensure all appended blocks are backed by a . /// - MemoryPoolIterator2 ProducingStart(); + MemoryPoolIterator ProducingStart(); /// /// Commits the response data appended to the iterator returned from . @@ -30,6 +30,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http /// or is called afterwards. /// /// Points to the end of the committed data. - void ProducingComplete(MemoryPoolIterator2 end); + void ProducingComplete(MemoryPoolIterator end); } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Listener.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Listener.cs index 76b64dacba..1a682f9a40 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Listener.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Listener.cs @@ -112,7 +112,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http }, this); } - Memory2.Dispose(); + Memory.Dispose(); ListenSocket = null; } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/ListenerContext.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/ListenerContext.cs index a012c15326..607c347981 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/ListenerContext.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/ListenerContext.cs @@ -16,7 +16,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http public ListenerContext(ServiceContext serviceContext) : base(serviceContext) { - Memory2 = new MemoryPool2(); + Memory = new MemoryPool(); WriteReqPool = new Queue(SocketOutput.MaxPooledWriteReqs); } @@ -25,7 +25,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { ServerAddress = listenerContext.ServerAddress; Thread = listenerContext.Thread; - Memory2 = listenerContext.Memory2; + Memory = listenerContext.Memory; ConnectionManager = listenerContext.ConnectionManager; WriteReqPool = listenerContext.WriteReqPool; Log = listenerContext.Log; @@ -35,7 +35,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http public KestrelThread Thread { get; set; } - public MemoryPool2 Memory2 { get; set; } + public MemoryPool Memory { get; set; } public ConnectionManager ConnectionManager { get; set; } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/ListenerSecondary.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/ListenerSecondary.cs index 10426c1cc9..6e45fbf7ed 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/ListenerSecondary.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/ListenerSecondary.cs @@ -192,7 +192,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http FreeBuffer(); } - Memory2.Dispose(); + Memory.Dispose(); } } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketInput.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketInput.cs index a534fe9261..98efa48692 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketInput.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketInput.cs @@ -16,20 +16,20 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http private static readonly Action _awaitableIsCompleted = () => { }; private static readonly Action _awaitableIsNotCompleted = () => { }; - private readonly MemoryPool2 _memory; + private readonly MemoryPool _memory; private readonly IThreadPool _threadPool; private readonly ManualResetEventSlim _manualResetEvent = new ManualResetEventSlim(false, 0); private Action _awaitableState; private Exception _awaitableError; - private MemoryPoolBlock2 _head; - private MemoryPoolBlock2 _tail; - private MemoryPoolBlock2 _pinned; + private MemoryPoolBlock _head; + private MemoryPoolBlock _tail; + private MemoryPoolBlock _pinned; private int _consumingState; - public SocketInput(MemoryPool2 memory, IThreadPool threadPool) + public SocketInput(MemoryPool memory, IThreadPool threadPool) { _memory = memory; _threadPool = threadPool; @@ -40,7 +40,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http public bool IsCompleted => ReferenceEquals(_awaitableState, _awaitableIsCompleted); - public MemoryPoolBlock2 IncomingStart() + public MemoryPoolBlock IncomingStart() { const int minimumSize = 2048; @@ -65,7 +65,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http _tail = _memory.Lease(); } - var iterator = new MemoryPoolIterator2(_tail, _tail.End); + var iterator = new MemoryPoolIterator(_tail, _tail.End); iterator.CopyFrom(buffer, offset, count); if (_head == null) @@ -148,22 +148,22 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } - public MemoryPoolIterator2 ConsumingStart() + public MemoryPoolIterator ConsumingStart() { if (Interlocked.CompareExchange(ref _consumingState, 1, 0) != 0) { throw new InvalidOperationException("Already consuming input."); } - return new MemoryPoolIterator2(_head); + return new MemoryPoolIterator(_head); } public void ConsumingComplete( - MemoryPoolIterator2 consumed, - MemoryPoolIterator2 examined) + MemoryPoolIterator consumed, + MemoryPoolIterator examined) { - MemoryPoolBlock2 returnStart = null; - MemoryPoolBlock2 returnEnd = null; + MemoryPoolBlock returnStart = null; + MemoryPoolBlock returnEnd = null; if (!consumed.IsDefault) { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketOutput.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketOutput.cs index 8804d0255f..f424a7531c 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketOutput.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketOutput.cs @@ -20,7 +20,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http private const int _initialTaskQueues = 64; private const int _maxPooledWriteContexts = 32; - private static readonly WaitCallback _returnBlocks = (state) => ReturnBlocks((MemoryPoolBlock2)state); + private static readonly WaitCallback _returnBlocks = (state) => ReturnBlocks((MemoryPoolBlock)state); private static readonly Action _connectionCancellation = (state) => ((SocketOutput)state).CancellationTriggered(); private readonly KestrelThread _thread; @@ -34,10 +34,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http // _head does not require a lock, since it is only used in the ctor and uv thread. private readonly object _returnLock = new object(); - private MemoryPoolBlock2 _head; - private MemoryPoolBlock2 _tail; + private MemoryPoolBlock _head; + private MemoryPoolBlock _tail; - private MemoryPoolIterator2 _lastStart; + private MemoryPoolIterator _lastStart; // This locks access to to all of the below fields private readonly object _contextLock = new object(); @@ -56,7 +56,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http public SocketOutput( KestrelThread thread, UvStreamHandle socket, - MemoryPool2 memory, + MemoryPool memory, Connection connection, string connectionId, IKestrelTrace log, @@ -222,7 +222,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } - public MemoryPoolIterator2 ProducingStart() + public MemoryPoolIterator ProducingStart() { lock (_returnLock) { @@ -230,16 +230,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if (_tail == null) { - return default(MemoryPoolIterator2); + return default(MemoryPoolIterator); } - _lastStart = new MemoryPoolIterator2(_tail, _tail.End); + _lastStart = new MemoryPoolIterator(_tail, _tail.End); return _lastStart; } } - public void ProducingComplete(MemoryPoolIterator2 end) + public void ProducingComplete(MemoryPoolIterator end) { Debug.Assert(!_lastStart.IsDefault); @@ -254,9 +254,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ProducingCompleteNoPreComplete(end); } - private void ProducingCompleteNoPreComplete(MemoryPoolIterator2 end) + private void ProducingCompleteNoPreComplete(MemoryPoolIterator end) { - MemoryPoolBlock2 blockToReturn = null; + MemoryPoolBlock blockToReturn = null; lock (_returnLock) @@ -275,7 +275,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http blockToReturn = _lastStart.Block; } - _lastStart = default(MemoryPoolIterator2); + _lastStart = default(MemoryPoolIterator); } if (blockToReturn != null) @@ -302,7 +302,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } - private static void ReturnBlocks(MemoryPoolBlock2 block) + private static void ReturnBlocks(MemoryPoolBlock block) { while (block != null) { @@ -496,7 +496,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http return WriteAsync(buffer, cancellationToken, chunk); } - private static void BytesBetween(MemoryPoolIterator2 start, MemoryPoolIterator2 end, out int bytes, out int buffers) + private static void BytesBetween(MemoryPoolIterator start, MemoryPoolIterator end, out int bytes, out int buffers) { if (start.Block == end.Block) { @@ -520,13 +520,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http private class WriteContext { - private static WaitCallback _returnWrittenBlocks = (state) => ReturnWrittenBlocks((MemoryPoolBlock2)state); + private static WaitCallback _returnWrittenBlocks = (state) => ReturnWrittenBlocks((MemoryPoolBlock)state); private static WaitCallback _completeWrite = (state) => ((WriteContext)state).CompleteOnThreadPool(); private SocketOutput Self; private UvWriteReq _writeReq; - private MemoryPoolIterator2 _lockedStart; - private MemoryPoolIterator2 _lockedEnd; + private MemoryPoolIterator _lockedStart; + private MemoryPoolIterator _lockedEnd; private int _bufferCount; public int ByteCount; @@ -698,7 +698,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThreadPool.QueueUserWorkItem(_returnWrittenBlocks, _lockedStart.Block); } - private static void ReturnWrittenBlocks(MemoryPoolBlock2 block) + private static void ReturnWrittenBlocks(MemoryPoolBlock block) { while (block != null) { @@ -722,16 +722,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http return; } - _lockedStart = new MemoryPoolIterator2(head, head.Start); - _lockedEnd = new MemoryPoolIterator2(tail, tail.End); + _lockedStart = new MemoryPoolIterator(head, head.Start); + _lockedEnd = new MemoryPoolIterator(tail, tail.End); BytesBetween(_lockedStart, _lockedEnd, out ByteCount, out _bufferCount); } public void Reset() { - _lockedStart = default(MemoryPoolIterator2); - _lockedEnd = default(MemoryPoolIterator2); + _lockedStart = default(MemoryPoolIterator); + _lockedEnd = default(MemoryPoolIterator); _bufferCount = 0; ByteCount = 0; diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/UrlPathDecoder.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/UrlPathDecoder.cs index 60f83303f1..90895fe691 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/UrlPathDecoder.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/UrlPathDecoder.cs @@ -13,7 +13,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http /// The iterator points to the beginning of the sequence. /// The iterator points to the byte behind the end of the sequence. /// The iterator points to the byte behind the end of the processed sequence. - public static MemoryPoolIterator2 Unescape(MemoryPoolIterator2 start, MemoryPoolIterator2 end) + public static MemoryPoolIterator Unescape(MemoryPoolIterator start, MemoryPoolIterator end) { // the slot to read the input var reader = start; @@ -59,7 +59,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http /// The iterator point to the first % char /// The place to write to /// The end of the sequence - private static bool DecodeCore(ref MemoryPoolIterator2 reader, ref MemoryPoolIterator2 writer, MemoryPoolIterator2 end) + private static bool DecodeCore(ref MemoryPoolIterator reader, ref MemoryPoolIterator writer, MemoryPoolIterator end) { // preserves the original head. if the percent-encodings cannot be interpreted as sequence of UTF-8 octets, // bytes from this till the last scanned one will be copied to the memory pointed by writer. @@ -189,7 +189,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http return true; } - private static void Copy(MemoryPoolIterator2 head, MemoryPoolIterator2 tail, ref MemoryPoolIterator2 writer) + private static void Copy(MemoryPoolIterator head, MemoryPoolIterator tail, ref MemoryPoolIterator writer) { while (!CompareIterators(ref head, ref tail)) { @@ -216,7 +216,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http /// The value to read /// The end of the sequence /// The unescaped byte if success. Otherwise return -1. - private static int UnescapePercentEncoding(ref MemoryPoolIterator2 scan, MemoryPoolIterator2 end) + private static int UnescapePercentEncoding(ref MemoryPoolIterator scan, MemoryPoolIterator end) { if (scan.Take() != '%') { @@ -255,7 +255,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http /// The value to read /// The end of the sequence /// The hexadecimal value if successes, otherwise -1. - private static int ReadHex(ref MemoryPoolIterator2 scan, MemoryPoolIterator2 end) + private static int ReadHex(ref MemoryPoolIterator scan, MemoryPoolIterator end) { if (CompareIterators(ref scan, ref end)) { @@ -297,7 +297,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http return false; } - private static bool CompareIterators(ref MemoryPoolIterator2 lhs, ref MemoryPoolIterator2 rhs) + private static bool CompareIterators(ref MemoryPoolIterator lhs, ref MemoryPoolIterator rhs) { // uses ref parameter to save cost of copying return (lhs.Block == rhs.Block) && (lhs.Index == rhs.Index); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPool2.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPool.cs similarity index 91% rename from src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPool2.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPool.cs index 9eb0ebfe60..d5a4e59b7e 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPool2.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPool.cs @@ -7,7 +7,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure /// /// Used to allocate and distribute re-usable blocks of memory. /// - public class MemoryPool2 : IDisposable + public class MemoryPool : IDisposable { /// /// The gap between blocks' starting address. 4096 is chosen because most operating systems are 4k pages in size and alignment. @@ -47,13 +47,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure /// Thread-safe collection of blocks which are currently in the pool. A slab will pre-allocate all of the block tracking objects /// and add them to this collection. When memory is requested it is taken from here first, and when it is returned it is re-added. /// - private readonly ConcurrentQueue _blocks = new ConcurrentQueue(); + private readonly ConcurrentQueue _blocks = new ConcurrentQueue(); /// /// Thread-safe collection of slabs which have been allocated by this pool. As long as a slab is in this collection and slab.IsActive, /// the blocks will be added to _blocks when returned. /// - private readonly ConcurrentStack _slabs = new ConcurrentStack(); + private readonly ConcurrentStack _slabs = new ConcurrentStack(); /// /// This is part of implementing the IDisposable pattern. @@ -66,7 +66,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure /// The block returned must be at least this size. It may be larger than this minimum size, and if so, /// the caller may write to the block's entire size rather than being limited to the minumumSize requested. /// The block that is reserved for the called. It must be passed to Return when it is no longer being used. - public MemoryPoolBlock2 Lease(int minimumSize = MaxPooledBlockLength) + public MemoryPoolBlock Lease(int minimumSize = MaxPooledBlockLength) { if (minimumSize > _blockLength) { @@ -74,14 +74,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure // Because this is the degenerate case, a one-time-use byte[] array and tracking object are allocated. // When this block tracking object is returned it is not added to the pool - instead it will be // allowed to be garbage collected normally. - return MemoryPoolBlock2.Create( + return MemoryPoolBlock.Create( new ArraySegment(new byte[minimumSize]), dataPtr: IntPtr.Zero, pool: this, slab: null); } - MemoryPoolBlock2 block; + MemoryPoolBlock block; if (_blocks.TryDequeue(out block)) { // block successfully taken from the stack - return it @@ -95,9 +95,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure /// Internal method called when a block is requested and the pool is empty. It allocates one additional slab, creates all of the /// block tracking objects, and adds them all to the pool. /// - private MemoryPoolBlock2 AllocateSlab() + private MemoryPoolBlock AllocateSlab() { - var slab = MemoryPoolSlab2.Create(_slabLength); + var slab = MemoryPoolSlab.Create(_slabLength); _slabs.Push(slab); var basePtr = slab.ArrayPtr; @@ -110,7 +110,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure offset + _blockLength < poolAllocationLength; offset += _blockStride) { - var block = MemoryPoolBlock2.Create( + var block = MemoryPoolBlock.Create( new ArraySegment(slab.Array, offset, _blockLength), basePtr, this, @@ -119,7 +119,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure } // return last block rather than adding to pool - var newBlock = MemoryPoolBlock2.Create( + var newBlock = MemoryPoolBlock.Create( new ArraySegment(slab.Array, offset, _blockLength), basePtr, this, @@ -136,7 +136,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure /// leaving "dead zones" in the slab due to lost block tracking objects. /// /// The block to return. It must have been acquired by calling Lease on the same memory pool instance. - public void Return(MemoryPoolBlock2 block) + public void Return(MemoryPoolBlock block) { Debug.Assert(block.Pool == this, "Returned block was not leased from this pool"); @@ -153,7 +153,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure { if (disposing) { - MemoryPoolSlab2 slab; + MemoryPoolSlab slab; while (_slabs.TryPop(out slab)) { // dispose managed state (managed objects). diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPoolBlock2.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPoolBlock.cs similarity index 92% rename from src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPoolBlock2.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPoolBlock.cs index 0dead6c6ae..25cab8c4f4 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPoolBlock2.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPoolBlock.cs @@ -9,7 +9,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure /// Block tracking object used by the byte buffer memory pool. A slab is a large allocation which is divided into smaller blocks. The /// individual blocks are then treated as independant array segments. /// - public class MemoryPoolBlock2 + public class MemoryPoolBlock { /// /// If this block represents a one-time-use memory object, this GCHandle will hold that memory object at a fixed address @@ -33,19 +33,19 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure /// /// This object cannot be instantiated outside of the static Create method /// - protected MemoryPoolBlock2() + protected MemoryPoolBlock() { } /// /// Back-reference to the memory pool which this block was allocated from. It may only be returned to this pool. /// - public MemoryPool2 Pool { get; private set; } + public MemoryPool Pool { get; private set; } /// /// Back-reference to the slab from which this block was taken, or null if it is one-time-use memory. /// - public MemoryPoolSlab2 Slab { get; private set; } + public MemoryPoolSlab Slab { get; private set; } /// /// Convenience accessor @@ -72,9 +72,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure /// working memory. The "active" memory is grown when bytes are copied in, End is increased, and Next is assigned. The "active" /// memory is shrunk when bytes are consumed, Start is increased, and blocks are returned to the pool. /// - public MemoryPoolBlock2 Next { get; set; } + public MemoryPoolBlock Next { get; set; } - ~MemoryPoolBlock2() + ~MemoryPoolBlock() { Debug.Assert(!_pinHandle.IsAllocated, "Ad-hoc memory block wasn't unpinned"); Debug.Assert(Slab == null || !Slab.IsActive, "Block being garbage collected instead of returned to pool"); @@ -87,7 +87,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure if (Slab != null && Slab.IsActive) { - Pool.Return(new MemoryPoolBlock2 + Pool.Return(new MemoryPoolBlock { _dataArrayPtr = _dataArrayPtr, Data = Data, @@ -130,13 +130,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure } } - public static MemoryPoolBlock2 Create( + public static MemoryPoolBlock Create( ArraySegment data, IntPtr dataPtr, - MemoryPool2 pool, - MemoryPoolSlab2 slab) + MemoryPool pool, + MemoryPoolSlab slab) { - return new MemoryPoolBlock2 + return new MemoryPoolBlock { Data = data, _dataArrayPtr = dataPtr, @@ -170,9 +170,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure /// acquires a cursor pointing into this block at the Start of "active" byte information /// /// - public MemoryPoolIterator2 GetIterator() + public MemoryPoolIterator GetIterator() { - return new MemoryPoolIterator2(this); + return new MemoryPoolIterator(this); } } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPoolIterator2.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPoolIterator.cs similarity index 97% rename from src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPoolIterator2.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPoolIterator.cs index 8e22ee4018..286862ce4b 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPoolIterator2.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPoolIterator.cs @@ -7,19 +7,19 @@ using System.Numerics; namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure { - public struct MemoryPoolIterator2 + public struct MemoryPoolIterator { private static readonly int _vectorSpan = Vector.Count; - private MemoryPoolBlock2 _block; + private MemoryPoolBlock _block; private int _index; - public MemoryPoolIterator2(MemoryPoolBlock2 block) + public MemoryPoolIterator(MemoryPoolBlock block) { _block = block; _index = _block?.Start ?? 0; } - public MemoryPoolIterator2(MemoryPoolBlock2 block, int index) + public MemoryPoolIterator(MemoryPoolBlock block, int index) { _block = block; _index = index; @@ -55,7 +55,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure } } - public MemoryPoolBlock2 Block => _block; + public MemoryPoolBlock Block => _block; public int Index => _index; @@ -634,7 +634,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure } } - public int GetLength(MemoryPoolIterator2 end) + public int GetLength(MemoryPoolIterator end) { if (IsDefault || end.IsDefault) { @@ -666,7 +666,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure } } - public MemoryPoolIterator2 CopyTo(byte[] array, int offset, int count, out int actual) + public MemoryPoolIterator CopyTo(byte[] array, int offset, int count, out int actual) { if (IsDefault) { @@ -687,7 +687,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure { Buffer.BlockCopy(block.Array, index, array, offset, remaining); } - return new MemoryPoolIterator2(block, index + remaining); + return new MemoryPoolIterator(block, index + remaining); } else if (block.Next == null) { @@ -696,7 +696,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure { Buffer.BlockCopy(block.Array, index, array, offset, following); } - return new MemoryPoolIterator2(block, index + following); + return new MemoryPoolIterator(block, index + following); } else { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPoolIterator2Extensions.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPoolIteratorExtensions.cs similarity index 97% rename from src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPoolIterator2Extensions.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPoolIteratorExtensions.cs index 7581ff35f2..1f9b3dcd7a 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPoolIterator2Extensions.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPoolIteratorExtensions.cs @@ -7,7 +7,7 @@ using System.Text; namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure { - public static class MemoryPoolIterator2Extensions + public static class MemoryPoolIteratorExtensions { private static readonly Encoding _utf8 = Encoding.UTF8; @@ -46,7 +46,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure private readonly static Tuple[] _knownMethods = new Tuple[8]; - static MemoryPoolIterator2Extensions() + static MemoryPoolIteratorExtensions() { _knownMethods[0] = Tuple.Create(_mask4Chars, _httpPutMethodLong, HttpPutMethod); _knownMethods[1] = Tuple.Create(_mask5Chars, _httpPostMethodLong, HttpPostMethod); @@ -79,7 +79,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure } } - public unsafe static string GetAsciiString(this MemoryPoolIterator2 start, MemoryPoolIterator2 end) + public unsafe static string GetAsciiString(this MemoryPoolIterator start, MemoryPoolIterator end) { if (start.IsDefault || end.IsDefault) { @@ -185,7 +185,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure return asciiString; } - public static string GetUtf8String(this MemoryPoolIterator2 start, MemoryPoolIterator2 end) + public static string GetUtf8String(this MemoryPoolIterator start, MemoryPoolIterator end) { if (start.IsDefault || end.IsDefault) { @@ -263,7 +263,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure } } - public static ArraySegment GetArraySegment(this MemoryPoolIterator2 start, MemoryPoolIterator2 end) + public static ArraySegment GetArraySegment(this MemoryPoolIterator start, MemoryPoolIterator end) { if (start.IsDefault || end.IsDefault) { @@ -295,7 +295,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure /// If we found a valid method, then scan will be updated to new position /// A reference to a pre-allocated known string, if the input matches any. /// true if the input matches a known string, false otherwise. - public static bool GetKnownMethod(this MemoryPoolIterator2 begin, ref MemoryPoolIterator2 scan, out string knownMethod) + public static bool GetKnownMethod(this MemoryPoolIterator begin, ref MemoryPoolIterator scan, out string knownMethod) { knownMethod = null; var value = begin.PeekLong(); @@ -333,7 +333,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure /// If we found a valid method, then scan will be updated to new position /// A reference to a pre-allocated known string, if the input matches any. /// true if the input matches a known string, false otherwise. - public static bool GetKnownVersion(this MemoryPoolIterator2 begin, ref MemoryPoolIterator2 scan, out string knownVersion) + public static bool GetKnownVersion(this MemoryPoolIterator begin, ref MemoryPoolIterator scan, out string knownVersion) { knownVersion = null; var value = begin.PeekLong(); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPoolSlab2.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPoolSlab.cs similarity index 95% rename from src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPoolSlab2.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPoolSlab.cs index c7062d0977..d0acab4d6c 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPoolSlab2.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPoolSlab.cs @@ -7,7 +7,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure /// Slab tracking object used by the byte buffer memory pool. A slab is a large allocation which is divided into smaller blocks. The /// individual blocks are then treated as independant array segments. /// - public class MemoryPoolSlab2 : IDisposable + public class MemoryPoolSlab : IDisposable { /// /// This handle pins the managed array in memory until the slab is disposed. This prevents it from being @@ -41,14 +41,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure /// private bool _disposedValue = false; // To detect redundant calls - public static MemoryPoolSlab2 Create(int length) + public static MemoryPoolSlab Create(int length) { // allocate and pin requested memory length var array = new byte[length]; var gcHandle = GCHandle.Alloc(array, GCHandleType.Pinned); // allocate and return slab tracking object - return new MemoryPoolSlab2 + return new MemoryPoolSlab { Array = array, _gcHandle = gcHandle, @@ -78,7 +78,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure } // override a finalizer only if Dispose(bool disposing) above has code to free unmanaged resources. - ~MemoryPoolSlab2() + ~MemoryPoolSlab() { // Do not change this code. Put cleanup code in Dispose(bool disposing) above. Dispose(false); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvWriteReq.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvWriteReq.cs index 576fce68c2..bf088950a5 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvWriteReq.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvWriteReq.cs @@ -41,8 +41,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Networking public unsafe void Write( UvStreamHandle handle, - MemoryPoolIterator2 start, - MemoryPoolIterator2 end, + MemoryPoolIterator start, + MemoryPoolIterator end, int nBuffers, Action callback, object state) diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/AsciiDecoder.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/AsciiDecoder.cs index 4664053bf8..10e95d2e56 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/AsciiDecoder.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/AsciiDecoder.cs @@ -15,7 +15,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { var byteRange = Enumerable.Range(0, 256).Select(x => (byte)x).ToArray(); - var mem = MemoryPoolBlock2.Create(new ArraySegment(byteRange), IntPtr.Zero, null, null); + var mem = MemoryPoolBlock.Create(new ArraySegment(byteRange), IntPtr.Zero, null, null); mem.End = byteRange.Length; var begin = mem.GetIterator(); @@ -44,10 +44,10 @@ namespace Microsoft.AspNetCore.Server.KestrelTests .Concat(byteRange) .ToArray(); - var mem0 = MemoryPoolBlock2.Create(new ArraySegment(byteRange), IntPtr.Zero, null, null); - var mem1 = MemoryPoolBlock2.Create(new ArraySegment(byteRange), IntPtr.Zero, null, null); - var mem2 = MemoryPoolBlock2.Create(new ArraySegment(byteRange), IntPtr.Zero, null, null); - var mem3 = MemoryPoolBlock2.Create(new ArraySegment(byteRange), IntPtr.Zero, null, null); + var mem0 = MemoryPoolBlock.Create(new ArraySegment(byteRange), IntPtr.Zero, null, null); + var mem1 = MemoryPoolBlock.Create(new ArraySegment(byteRange), IntPtr.Zero, null, null); + var mem2 = MemoryPoolBlock.Create(new ArraySegment(byteRange), IntPtr.Zero, null, null); + var mem3 = MemoryPoolBlock.Create(new ArraySegment(byteRange), IntPtr.Zero, null, null); mem0.End = byteRange.Length; mem1.End = byteRange.Length; mem2.End = byteRange.Length; @@ -79,8 +79,8 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var byteRange = Enumerable.Range(0, 16384 + 64).Select(x => (byte)x).ToArray(); var expectedByteRange = byteRange.Concat(byteRange).ToArray(); - var mem0 = MemoryPoolBlock2.Create(new ArraySegment(byteRange), IntPtr.Zero, null, null); - var mem1 = MemoryPoolBlock2.Create(new ArraySegment(byteRange), IntPtr.Zero, null, null); + var mem0 = MemoryPoolBlock.Create(new ArraySegment(byteRange), IntPtr.Zero, null, null); + var mem1 = MemoryPoolBlock.Create(new ArraySegment(byteRange), IntPtr.Zero, null, null); mem0.End = byteRange.Length; mem1.End = byteRange.Length; @@ -102,7 +102,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } } - private MemoryPoolIterator2 GetIterator(MemoryPoolIterator2 begin, int displacement) + private MemoryPoolIterator GetIterator(MemoryPoolIterator begin, int displacement) { var result = begin; for (int i = 0; i < displacement; ++i) diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionTests.cs index 203a807267..3b710b508b 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionTests.cs @@ -16,7 +16,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { var mockLibuv = new MockLibuv(); - using (var memory = new MemoryPool2()) + using (var memory = new MemoryPool()) using (var engine = new KestrelEngine(mockLibuv, new TestServiceContext())) { engine.Start(count: 1); @@ -26,7 +26,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { FrameFactory = connectionContext => new Frame( new DummyApplication(httpContext => TaskUtilities.CompletedTask), connectionContext), - Memory2 = memory, + Memory = memory, ServerAddress = ServerAddress.FromUrl($"http://localhost:{TestServer.GetNextPort()}"), Thread = engine.Threads[0] }; diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs index 78d46f5d6c..8d6133a5f3 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs @@ -26,7 +26,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { var trace = new KestrelTrace(new TestKestrelTrace()); var ltp = new LoggingThreadPool(trace); - using (var pool = new MemoryPool2()) + using (var pool = new MemoryPool()) using (var socketInput = new SocketInput(pool, ltp)) { var connectionContext = new ConnectionContext() diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolBlock2Tests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolBlockTests.cs similarity index 95% rename from test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolBlock2Tests.cs rename to test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolBlockTests.cs index f5f58465b9..73bb3b2ef8 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolBlock2Tests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolBlockTests.cs @@ -6,12 +6,12 @@ using Xunit; namespace Microsoft.AspNetCore.Server.KestrelTests { - public class MemoryPoolBlock2Tests + public class MemoryPoolBlockTests { [Fact] public void SeekWorks() { - using (var pool = new MemoryPool2()) + using (var pool = new MemoryPool()) { var block = pool.Lease(256); foreach (var ch in Enumerable.Range(0, 256).Select(x => (byte)x)) @@ -61,7 +61,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests Console.WriteLine($"Vector.IsHardwareAccelerated == {Vector.IsHardwareAccelerated}"); Console.WriteLine($"Vector.Count == {Vector.Count}"); - using (var pool = new MemoryPool2()) + using (var pool = new MemoryPool()) { var block1 = pool.Lease(256); var block2 = block1.Next = pool.Lease(256); @@ -121,7 +121,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [Fact] public void GetLengthBetweenIteratorsWorks() { - using (var pool = new MemoryPool2()) + using (var pool = new MemoryPool()) { var block = pool.Lease(256); block.End += 256; @@ -148,7 +148,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } } - private void TestAllLengths(MemoryPoolBlock2 block, int lengths) + private void TestAllLengths(MemoryPoolBlock block, int lengths) { for (var firstIndex = 0; firstIndex <= lengths; ++firstIndex) { @@ -166,7 +166,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [Fact] public void AddDoesNotAdvanceAtEndOfCurrentBlock() { - using (var pool = new MemoryPool2()) + using (var pool = new MemoryPool()) { var block1 = pool.Lease(256); var block2 = block1.Next = pool.Lease(256); @@ -207,7 +207,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [Fact] public void CopyToCorrectlyTraversesBlocks() { - using (var pool = new MemoryPool2()) + using (var pool = new MemoryPool()) { var block1 = pool.Lease(128); var block2 = block1.Next = pool.Lease(128); @@ -245,7 +245,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [Fact] public void CopyFromCorrectlyTraversesBlocks() { - using (var pool = new MemoryPool2()) + using (var pool = new MemoryPool()) { var block1 = pool.Lease(128); var start = block1.GetIterator(); @@ -287,7 +287,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [Fact] public void IsEndCorrectlyTraversesBlocks() { - using (var pool = new MemoryPool2()) + using (var pool = new MemoryPool()) { var block1 = pool.Lease(128); var block2 = block1.Next = pool.Lease(128); @@ -313,7 +313,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } } - private void AssertIterator(MemoryPoolIterator2 iter, MemoryPoolBlock2 block, int index) + private void AssertIterator(MemoryPoolIterator iter, MemoryPoolBlock block, int index) { Assert.Same(block, iter.Block); Assert.Equal(index, iter.Index); diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolExtensions.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolExtensions.cs index d822185aee..e2cd3bdfa8 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolExtensions.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolExtensions.cs @@ -4,7 +4,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { public static class MemoryPoolExtensions { - public static MemoryPoolIterator2 Add(this MemoryPoolIterator2 iterator, int count) + public static MemoryPoolIterator Add(this MemoryPoolIterator iterator, int count) { int actual; return iterator.CopyTo(new byte[count], 0, count, out actual); diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolIterator2Tests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolIteratorTests.cs similarity index 92% rename from test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolIterator2Tests.cs rename to test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolIteratorTests.cs index 90d66690e9..18fdeb5afd 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolIterator2Tests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolIteratorTests.cs @@ -6,13 +6,13 @@ using Xunit; namespace Microsoft.AspNetCore.Server.KestrelTests { - public class MemoryPoolIterator2Tests : IDisposable + public class MemoryPoolIteratorTests : IDisposable { - private readonly MemoryPool2 _pool; + private readonly MemoryPool _pool; - public MemoryPoolIterator2Tests() + public MemoryPoolIteratorTests() { - _pool = new MemoryPool2(); + _pool = new MemoryPool(); } public void Dispose() @@ -27,7 +27,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests for (int i = 0; i < Vector.Count; i++) { Vector vector = new Vector(bytes); - Assert.Equal(i, MemoryPoolIterator2.FindFirstEqualByte(ref vector)); + Assert.Equal(i, MemoryPoolIterator.FindFirstEqualByte(ref vector)); bytes[i] = 0; } @@ -35,7 +35,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { bytes[i] = 1; Vector vector = new Vector(bytes); - Assert.Equal(i, MemoryPoolIterator2.FindFirstEqualByte(ref vector)); + Assert.Equal(i, MemoryPoolIterator.FindFirstEqualByte(ref vector)); bytes[i] = 0; } } @@ -47,7 +47,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests for (int i = 0; i < Vector.Count; i++) { Vector vector = new Vector(bytes); - Assert.Equal(i, MemoryPoolIterator2.FindFirstEqualByteSlow(ref vector)); + Assert.Equal(i, MemoryPoolIterator.FindFirstEqualByteSlow(ref vector)); bytes[i] = 0; } @@ -55,7 +55,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { bytes[i] = 1; Vector vector = new Vector(bytes); - Assert.Equal(i, MemoryPoolIterator2.FindFirstEqualByteSlow(ref vector)); + Assert.Equal(i, MemoryPoolIterator.FindFirstEqualByteSlow(ref vector)); bytes[i] = 0; } } @@ -123,7 +123,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [Fact] public void Put() { - var blocks = new MemoryPoolBlock2[4]; + var blocks = new MemoryPoolBlock[4]; for (var i = 0; i < 4; ++i) { blocks[i] = _pool.Lease(16); @@ -286,15 +286,15 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } [Theory] - [InlineData("CONNECT / HTTP/1.1", ' ', true, MemoryPoolIterator2Extensions.HttpConnectMethod)] - [InlineData("DELETE / HTTP/1.1", ' ', true, MemoryPoolIterator2Extensions.HttpDeleteMethod)] - [InlineData("GET / HTTP/1.1", ' ', true, MemoryPoolIterator2Extensions.HttpGetMethod)] - [InlineData("HEAD / HTTP/1.1", ' ', true, MemoryPoolIterator2Extensions.HttpHeadMethod)] - [InlineData("PATCH / HTTP/1.1", ' ', true, MemoryPoolIterator2Extensions.HttpPatchMethod)] - [InlineData("POST / HTTP/1.1", ' ', true, MemoryPoolIterator2Extensions.HttpPostMethod)] - [InlineData("PUT / HTTP/1.1", ' ', true, MemoryPoolIterator2Extensions.HttpPutMethod)] - [InlineData("OPTIONS / HTTP/1.1", ' ', true, MemoryPoolIterator2Extensions.HttpOptionsMethod)] - [InlineData("TRACE / HTTP/1.1", ' ', true, MemoryPoolIterator2Extensions.HttpTraceMethod)] + [InlineData("CONNECT / HTTP/1.1", ' ', true, MemoryPoolIteratorExtensions.HttpConnectMethod)] + [InlineData("DELETE / HTTP/1.1", ' ', true, MemoryPoolIteratorExtensions.HttpDeleteMethod)] + [InlineData("GET / HTTP/1.1", ' ', true, MemoryPoolIteratorExtensions.HttpGetMethod)] + [InlineData("HEAD / HTTP/1.1", ' ', true, MemoryPoolIteratorExtensions.HttpHeadMethod)] + [InlineData("PATCH / HTTP/1.1", ' ', true, MemoryPoolIteratorExtensions.HttpPatchMethod)] + [InlineData("POST / HTTP/1.1", ' ', true, MemoryPoolIteratorExtensions.HttpPostMethod)] + [InlineData("PUT / HTTP/1.1", ' ', true, MemoryPoolIteratorExtensions.HttpPutMethod)] + [InlineData("OPTIONS / HTTP/1.1", ' ', true, MemoryPoolIteratorExtensions.HttpOptionsMethod)] + [InlineData("TRACE / HTTP/1.1", ' ', true, MemoryPoolIteratorExtensions.HttpTraceMethod)] [InlineData("GET/ HTTP/1.1", ' ', false, null)] [InlineData("get / HTTP/1.1", ' ', false, null)] [InlineData("GOT / HTTP/1.1", ' ', false, null)] @@ -324,8 +324,8 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } [Theory] - [InlineData("HTTP/1.0\r", '\r', true, MemoryPoolIterator2Extensions.Http10Version)] - [InlineData("HTTP/1.1\r", '\r', true, MemoryPoolIterator2Extensions.Http11Version)] + [InlineData("HTTP/1.0\r", '\r', true, MemoryPoolIteratorExtensions.Http10Version)] + [InlineData("HTTP/1.1\r", '\r', true, MemoryPoolIteratorExtensions.Http11Version)] [InlineData("HTTP/3.0\r", '\r', false, null)] [InlineData("http/1.0\r", '\r', false, null)] [InlineData("http/1.1\r", '\r', false, null)] diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/MultipleLoopTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/MultipleLoopTests.cs index 790d654fca..c5b8c30c5b 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/MultipleLoopTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/MultipleLoopTests.cs @@ -64,13 +64,13 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var writeRequest = new UvWriteReq(new KestrelTrace(new TestKestrelTrace())); writeRequest.Init(loop); - var block = MemoryPoolBlock2.Create( + var block = MemoryPoolBlock.Create( new ArraySegment(new byte[] { 1, 2, 3, 4 }), dataPtr: IntPtr.Zero, pool: null, slab: null); - var start = new MemoryPoolIterator2(block, 0); - var end = new MemoryPoolIterator2(block, block.Data.Count); + var start = new MemoryPoolIterator(block, 0); + var end = new MemoryPoolIterator(block, block.Data.Count); writeRequest.Write( serverConnectionPipe, start, diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/NetworkingTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/NetworkingTests.cs index 33ff9b70d9..c299331818 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/NetworkingTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/NetworkingTests.cs @@ -178,13 +178,13 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { var req = new UvWriteReq(new KestrelTrace(new TestKestrelTrace())); req.Init(loop); - var block = MemoryPoolBlock2.Create( + var block = MemoryPoolBlock.Create( new ArraySegment(new byte[] { 65, 66, 67, 68, 69 }), dataPtr: IntPtr.Zero, pool: null, slab: null); - var start = new MemoryPoolIterator2(block, 0); - var end = new MemoryPoolIterator2(block, block.Data.Count); + var start = new MemoryPoolIterator(block, 0); + var end = new MemoryPoolIterator(block, block.Data.Count); req.Write( tcp2, start, diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/SocketInputTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/SocketInputTests.cs index 29e2597f5f..2a0d792051 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/SocketInputTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/SocketInputTests.cs @@ -18,7 +18,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests // Arrange var trace = new KestrelTrace(new TestKestrelTrace()); var ltp = new LoggingThreadPool(trace); - using (var memory2 = new MemoryPool2()) + using (var memory2 = new MemoryPool()) using (var socketInput = new SocketInput(memory2, ltp)) { var task0Threw = false; @@ -79,7 +79,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [Fact] public void ConsumingOutOfOrderFailsGracefully() { - var defultIter = new MemoryPoolIterator2(); + var defultIter = new MemoryPoolIterator(); // Calling ConsumingComplete without a preceding calling to ConsumingStart fails using (var socketInput = new SocketInput(null, null)) diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/SocketOutputTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/SocketOutputTests.cs index f0132e0c82..853b22f577 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/SocketOutputTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/SocketOutputTests.cs @@ -33,7 +33,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } }; - using (var memory = new MemoryPool2()) + using (var memory = new MemoryPool()) using (var kestrelEngine = new KestrelEngine(mockLibuv, new TestServiceContext())) { kestrelEngine.Start(count: 1); @@ -84,7 +84,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } }; - using (var memory = new MemoryPool2()) + using (var memory = new MemoryPool()) using (var kestrelEngine = new KestrelEngine(mockLibuv, new TestServiceContext())) { kestrelEngine.Start(count: 1); @@ -152,7 +152,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } }; - using (var memory = new MemoryPool2()) + using (var memory = new MemoryPool()) using (var kestrelEngine = new KestrelEngine(mockLibuv, new TestServiceContext())) { kestrelEngine.Start(count: 1); @@ -225,7 +225,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } }; - using (var memory = new MemoryPool2()) + using (var memory = new MemoryPool()) using (var kestrelEngine = new KestrelEngine(mockLibuv, new TestServiceContext())) { kestrelEngine.Start(count: 1); @@ -335,7 +335,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } }; - using (var memory = new MemoryPool2()) + using (var memory = new MemoryPool()) using (var kestrelEngine = new KestrelEngine(mockLibuv, new TestServiceContext())) { kestrelEngine.Start(count: 1); @@ -423,7 +423,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } }; - using (var memory = new MemoryPool2()) + using (var memory = new MemoryPool()) using (var kestrelEngine = new KestrelEngine(mockLibuv, new TestServiceContext())) { kestrelEngine.Start(count: 1); @@ -509,7 +509,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } }; - using (var memory = new MemoryPool2()) + using (var memory = new MemoryPool()) using (var kestrelEngine = new KestrelEngine(mockLibuv, new TestServiceContext())) { kestrelEngine.Start(count: 1); @@ -529,7 +529,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests block2.End = block2.Data.Offset + block2.Data.Count; start.Block.Next = block2; - var end = new MemoryPoolIterator2(block2, block2.End); + var end = new MemoryPoolIterator(block2, block2.End); socketOutput.ProducingComplete(end); diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestInput.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/TestInput.cs index 3214c94ed8..764e0a521c 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/TestInput.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/TestInput.cs @@ -12,7 +12,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { class TestInput : IConnectionControl, IFrameControl, IDisposable { - private MemoryPool2 _memoryPool; + private MemoryPool _memoryPool; public TestInput() { @@ -27,7 +27,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests }; FrameContext = new Frame(null, context); - _memoryPool = new MemoryPool2(); + _memoryPool = new MemoryPool(); FrameContext.SocketInput = new SocketInput(_memoryPool, ltp); } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/UrlPathDecoder.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/UrlPathDecoder.cs index aab03b1a21..711297fd95 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/UrlPathDecoder.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/UrlPathDecoder.cs @@ -120,16 +120,16 @@ namespace Microsoft.AspNetCore.Server.KestrelTests Assert.Equal(expect, result); } - private MemoryPoolIterator2 BuildSample(string data) + private MemoryPoolIterator BuildSample(string data) { var store = data.Select(c => (byte)c).ToArray(); - var mem = MemoryPoolBlock2.Create(new ArraySegment(store), IntPtr.Zero, null, null); + var mem = MemoryPoolBlock.Create(new ArraySegment(store), IntPtr.Zero, null, null); mem.End = store.Length; return mem.GetIterator(); } - private MemoryPoolIterator2 GetIterator(MemoryPoolIterator2 begin, int displacement) + private MemoryPoolIterator GetIterator(MemoryPoolIterator begin, int displacement) { var result = begin; for (int i = 0; i < displacement; ++i) diff --git a/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/KnownHeaders.cs b/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/KnownHeaders.cs index 1593da3ac4..9f47fdfae0 100644 --- a/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/KnownHeaders.cs +++ b/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/KnownHeaders.cs @@ -390,7 +390,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ((ICollection>)MaybeUnknown)?.CopyTo(array, arrayIndex); }} {(loop.ClassName == "FrameResponseHeaders" ? $@" - protected void CopyToFast(ref MemoryPoolIterator2 output) + protected void CopyToFast(ref MemoryPoolIterator output) {{ {Each(loop.Headers, header => $@" if ({header.TestBit()}) From 65f83015e373445d8b6caa8894ae722ff10f22ad Mon Sep 17 00:00:00 2001 From: Ajay Bhargav Baaskaran Date: Thu, 3 Mar 2016 17:32:50 -0800 Subject: [PATCH 0640/1662] Added Company, Copyright and Product attributes to AssemblyInfo --- .../Properties/AssemblyInfo.cs | 3 +++ .../Properties/AssemblyInfo.cs | 3 +++ 2 files changed, 6 insertions(+) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Https/Properties/AssemblyInfo.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Https/Properties/AssemblyInfo.cs index 24e236d5f2..603dc45398 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Https/Properties/AssemblyInfo.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Https/Properties/AssemblyInfo.cs @@ -8,3 +8,6 @@ using System.Runtime.CompilerServices; [assembly: InternalsVisibleTo("Microsoft.AspNetCore.Server.KestrelTests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")] [assembly: AssemblyMetadata("Serviceable", "True")] [assembly: NeutralResourcesLanguage("en-us")] +[assembly: AssemblyCompany("Microsoft Corporation.")] +[assembly: AssemblyCopyright("© Microsoft Corporation. All rights reserved.")] +[assembly: AssemblyProduct("Microsoft ASP.NET Core")] diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Properties/AssemblyInfo.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Properties/AssemblyInfo.cs index 24e236d5f2..603dc45398 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Properties/AssemblyInfo.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Properties/AssemblyInfo.cs @@ -8,3 +8,6 @@ using System.Runtime.CompilerServices; [assembly: InternalsVisibleTo("Microsoft.AspNetCore.Server.KestrelTests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")] [assembly: AssemblyMetadata("Serviceable", "True")] [assembly: NeutralResourcesLanguage("en-us")] +[assembly: AssemblyCompany("Microsoft Corporation.")] +[assembly: AssemblyCopyright("© Microsoft Corporation. All rights reserved.")] +[assembly: AssemblyProduct("Microsoft ASP.NET Core")] From cd8e8f0a11cd29df8688cd1a14ef86236b087b28 Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Thu, 3 Mar 2016 08:56:22 -0800 Subject: [PATCH 0641/1662] Prevent DebugAssertException from blocks not returned by non-graceful shutdowns (#667). --- src/Microsoft.AspNetCore.Server.Kestrel/Http/Listener.cs | 6 +++--- .../Http/ListenerPrimary.cs | 4 ++-- .../Http/ListenerSecondary.cs | 6 +++--- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Listener.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Listener.cs index 1a682f9a40..063d0a2f5f 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Listener.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Listener.cs @@ -98,9 +98,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http listener._closed = true; listener.ConnectionManager.WalkConnectionsAndClose(); - }, this); + }, this).ConfigureAwait(false); - await ConnectionManager.WaitForConnectionCloseAsync(); + await ConnectionManager.WaitForConnectionCloseAsync().ConfigureAwait(false); await Thread.PostAsync(state => { @@ -109,7 +109,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { writeReqPool.Dequeue().Dispose(); } - }, this); + }, this).ConfigureAwait(false); } Memory.Dispose(); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/ListenerPrimary.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/ListenerPrimary.cs index 3e4c86c627..f2d9c2f3a9 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/ListenerPrimary.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/ListenerPrimary.cs @@ -105,7 +105,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { // Call base first so the ListenSocket gets closed and doesn't // try to dispatch connections to closed pipes. - await base.DisposeAsync(); + await base.DisposeAsync().ConfigureAwait(false); if (Thread.FatalError == null && ListenPipe != null) { @@ -118,7 +118,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { dispatchPipe.Dispose(); } - }, this); + }, this).ConfigureAwait(false); } } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/ListenerSecondary.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/ListenerSecondary.cs index 6e45fbf7ed..2e8e89911b 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/ListenerSecondary.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/ListenerSecondary.cs @@ -173,9 +173,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http listener._closed = true; listener.ConnectionManager.WalkConnectionsAndClose(); - }, this); + }, this).ConfigureAwait(false); - await ConnectionManager.WaitForConnectionCloseAsync(); + await ConnectionManager.WaitForConnectionCloseAsync().ConfigureAwait(false); await Thread.PostAsync(state => { @@ -185,7 +185,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { writeReqPool.Dequeue().Dispose(); } - }, this); + }, this).ConfigureAwait(false); } else { From 5f6293110cbde66efd1c73572882206fd1d8af3a Mon Sep 17 00:00:00 2001 From: moozzyk Date: Mon, 7 Mar 2016 13:21:35 -0800 Subject: [PATCH 0642/1662] Adding libuv.so to the package --- src/Microsoft.AspNetCore.Server.Kestrel/project.json | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/project.json b/src/Microsoft.AspNetCore.Server.Kestrel/project.json index 8ba4577a3a..c1024d14ae 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/project.json +++ b/src/Microsoft.AspNetCore.Server.Kestrel/project.json @@ -16,6 +16,10 @@ "version": "1.0.0-*", "type": "build" }, + "Microsoft.AspNetCore.Internal.libuv-Linux": { + "version": "1.0.0-*", + "type": "build" + }, "Microsoft.AspNetCore.Internal.libuv-Windows": { "version": "1.0.0-*", "type": "build" @@ -65,6 +69,8 @@ "runtimes/win7-x64/native/": "runtimes/win7-x64/native/*", "runtimes/win7-x86/native/": "runtimes/win7-x86/native/*", "runtimes/win7-arm/native/": "runtimes/win7-arm/native/*", - "runtimes/osx/native/": "runtimes/osx/native/*" + "runtimes/osx/native/": "runtimes/osx/native/*", + "runtimes/rhel-x64/native/": "runtimes/rhel-x64/native/*", + "runtimes/debian-x64/native/": "runtimes/debian-x64/native/*" } } \ No newline at end of file From 1562360e18ebd2b5f8489f325c7cfd46e8774ffd Mon Sep 17 00:00:00 2001 From: Victor Hurdugaci Date: Mon, 7 Mar 2016 20:55:00 -0800 Subject: [PATCH 0643/1662] Update the build scripts to the latest version --- build.ps1 | 33 ++++++++++++++++++++++++++++++++- build.sh | 15 +++++++++++++-- 2 files changed, 45 insertions(+), 3 deletions(-) diff --git a/build.ps1 b/build.ps1 index 4fd24a30d5..8f2f99691a 100644 --- a/build.ps1 +++ b/build.ps1 @@ -1,3 +1,33 @@ +$ErrorActionPreference = "Stop" + +function DownloadWithRetry([string] $url, [string] $downloadLocation, [int] $retries) +{ + while($true) + { + try + { + Invoke-WebRequest $url -OutFile $downloadLocation + break + } + catch + { + $exceptionMessage = $_.Exception.Message + Write-Host "Failed to download '$url': $exceptionMessage" + if ($retries -gt 0) { + $retries-- + Write-Host "Waiting 10 seconds before retrying. Retries left: $retries" + Start-Sleep -Seconds 10 + + } + else + { + $exception = $_.Exception + throw $exception + } + } + } +} + cd $PSScriptRoot $repoFolder = $PSScriptRoot @@ -20,7 +50,8 @@ if (!(Test-Path $buildFolder)) { $localZipFile="$tempFolder\korebuild.zip" - Invoke-WebRequest $koreBuildZip -OutFile $localZipFile + DownloadWithRetry -url $koreBuildZip -downloadLocation $localZipFile -retries 6 + Add-Type -AssemblyName System.IO.Compression.FileSystem [System.IO.Compression.ZipFile]::ExtractToDirectory($localZipFile, $tempFolder) diff --git a/build.sh b/build.sh index 79638d06b6..f4208100eb 100755 --- a/build.sh +++ b/build.sh @@ -18,7 +18,18 @@ if test ! -d $buildFolder; then localZipFile="$tempFolder/korebuild.zip" - wget -O $localZipFile $koreBuildZip 2>/dev/null || curl -o $localZipFile --location $koreBuildZip /dev/null + retries=6 + until (wget -O $localZipFile $koreBuildZip 2>/dev/null || curl -o $localZipFile --location $koreBuildZip 2>/dev/null) + do + echo "Failed to download '$koreBuildZip'" + if [ "$retries" -le 0 ]; then + exit 1 + fi + retries=$((retries - 1)) + echo "Waiting 10 seconds before retrying. Retries left: $retries" + sleep 10s + done + unzip -q -d $tempFolder $localZipFile mkdir $buildFolder @@ -32,4 +43,4 @@ if test ! -d $buildFolder; then fi fi -$buildFile -r $repoFolder "$@" +$buildFile -r $repoFolder "$@" \ No newline at end of file From 197a775f0d9bbf9726fcd772e9abd449a49a3786 Mon Sep 17 00:00:00 2001 From: Mike Harder Date: Tue, 8 Mar 2016 16:10:14 -0800 Subject: [PATCH 0644/1662] Add launchSettings.json to .gitignore --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index b5933c6864..6acc284439 100644 --- a/.gitignore +++ b/.gitignore @@ -28,4 +28,5 @@ nuget.exe project.lock.json runtimes/ .build/ -.testPublish/ \ No newline at end of file +.testPublish/ +launchSettings.json From 37b0917ac19cd9f895f9dab3a26ea415cc828819 Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Fri, 4 Mar 2016 12:20:23 -0800 Subject: [PATCH 0645/1662] Use TLS 1.1 or 1.2 only (#637). --- .../HttpsConnectionFilterOptions.cs | 2 +- .../HttpsConnectionFilterTests.cs | 68 ++++++++++++++++++- 2 files changed, 67 insertions(+), 3 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Https/HttpsConnectionFilterOptions.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Https/HttpsConnectionFilterOptions.cs index a33e3b090d..93eab7158d 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Https/HttpsConnectionFilterOptions.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Https/HttpsConnectionFilterOptions.cs @@ -13,7 +13,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Https public HttpsConnectionFilterOptions() { ClientCertificateMode = ClientCertificateMode.NoCertificate; - SslProtocols = SslProtocols.Tls12 | SslProtocols.Tls11 | SslProtocols.Tls; + SslProtocols = SslProtocols.Tls12 | SslProtocols.Tls11; } public X509Certificate2 ServerCertificate { get; set; } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/HttpsConnectionFilterTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/HttpsConnectionFilterTests.cs index 4d0d86a34d..32aaa453e4 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/HttpsConnectionFilterTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/HttpsConnectionFilterTests.cs @@ -8,6 +8,7 @@ using System.Net; using System.Net.Http; using System.Net.Security; using System.Net.Sockets; +using System.Security.Authentication; using System.Security.Cryptography.X509Certificates; using System.Text; using System.Threading.Tasks; @@ -22,6 +23,16 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { public class HttpsConnectionFilterTests { +#if NET451 + static HttpsConnectionFilterTests() + { + // SecurityProtocolType values below not available in Mono < 4.3 + const int SecurityProtocolTypeTls11 = 768; + const int SecurityProtocolTypeTls12 = 3072; + ServicePointManager.SecurityProtocol |= (SecurityProtocolType)(SecurityProtocolTypeTls12 | SecurityProtocolTypeTls11); + } +#endif + private async Task App(HttpContext httpContext) { var request = httpContext.Request; @@ -231,9 +242,9 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { await client.ConnectAsync("127.0.0.1", server.Port); - SslStream stream = new SslStream(client.GetStream(), false, (sender, certificate, chain, errors) => true, + var stream = new SslStream(client.GetStream(), false, (sender, certificate, chain, errors) => true, (sender, host, certificates, certificate, issuers) => new X509Certificate2(@"TestResources/testCert.pfx", "testPassword")); - await stream.AuthenticateAsClientAsync("localhost"); + await stream.AuthenticateAsClientAsync("localhost", new X509CertificateCollection(), SslProtocols.Tls12 | SslProtocols.Tls11, false); var request = Encoding.UTF8.GetBytes("GET / HTTP/1.0\r\n\r\n"); await stream.WriteAsync(request, 0, request.Length); @@ -301,5 +312,58 @@ namespace Microsoft.AspNetCore.Server.KestrelTests #endif } } + + + [Fact] + public async Task DoesNotSupportTls10() + { + RemoteCertificateValidationCallback validationCallback = + (sender, cert, chain, sslPolicyErrors) => true; + + try + { +#if NET451 + ServicePointManager.ServerCertificateValidationCallback += validationCallback; +#endif + + var serverAddress = $"https://localhost:{TestServer.GetNextPort()}/"; + var serviceContext = new TestServiceContext(new HttpsConnectionFilter( + new HttpsConnectionFilterOptions + { + ServerCertificate = new X509Certificate2(@"TestResources/testCert.pfx", "testPassword"), + ClientCertificateMode = ClientCertificateMode.RequireCertificate, + ClientCertificateValidation = (certificate, chain, sslPolicyErrors) => true + }, + new NoOpConnectionFilter()) + ); + + RequestDelegate app = context => + { + return context.Response.WriteAsync("hello world"); + }; + + using (var server = new TestServer(app, serviceContext, serverAddress)) + { + // SslStream is used to ensure the certificate is actually passed to the server + // HttpClient might not send the certificate because it is invalid or it doesn't match any + // of the certificate authorities sent by the server in the SSL handshake. + using (var client = new TcpClient()) + { + await client.ConnectAsync("127.0.0.1", server.Port); + + var stream = new SslStream(client.GetStream(), false, (sender, certificate, chain, errors) => true, + (sender, host, certificates, certificate, issuers) => new X509Certificate2(@"TestResources/testCert.pfx", "testPassword")); + await Assert.ThrowsAsync(typeof(IOException), async () => + await stream.AuthenticateAsClientAsync("localhost", new X509CertificateCollection(), SslProtocols.Tls, false)); + } + } + } + finally + { +#if NET451 + ServicePointManager.ServerCertificateValidationCallback -= validationCallback; +#endif + } + } } } From 88367ccf2da6ba92ea218243a6eb613d8b82a7fb Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Tue, 8 Mar 2016 15:18:26 -0800 Subject: [PATCH 0646/1662] Wait for more input while request hasn't finished (#672). --- .../Http/Frame.cs | 52 +++++++++++++++---- 1 file changed, 42 insertions(+), 10 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs index 9d14928e16..d1f87f0a36 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs @@ -731,10 +731,18 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http var needDecode = false; var chFound = scan.Seek(ref _vectorSpaces, ref _vectorQuestionMarks, ref _vectorPercentages); - if (chFound == '%') + if (chFound == -1) + { + return false; + } + else if (chFound == '%') { needDecode = true; chFound = scan.Seek(ref _vectorSpaces, ref _vectorQuestionMarks); + if (chFound == -1) + { + return false; + } } var pathBegin = begin; @@ -851,7 +859,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http while (!scan.IsEnd) { var beginName = scan; - scan.Seek(ref _vectorColons, ref _vectorCRs); + if (scan.Seek(ref _vectorColons, ref _vectorCRs) == -1) + { + return false; + } var endName = scan; chFirst = scan.Take(); @@ -885,13 +896,21 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { var scanAhead = scan; var chAhead = scanAhead.Take(); - if (chAhead == '\n') + if (chAhead == -1) + { + return false; + } + else if (chAhead == '\n') { chAhead = scanAhead.Take(); - // If the "\r\n" isn't part of "linear whitespace", - // then this header has no value. - if (chAhead != ' ' && chAhead != '\t') + if (chAhead == -1) { + return false; + } + else if (chAhead != ' ' && chAhead != '\t') + { + // If the "\r\n" isn't part of "linear whitespace", + // then this header has no value. break; } } @@ -899,6 +918,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http beginValue = scan; chSecond = scan.Take(); + + if (chSecond == -1) + { + return false; + } } scan = beginValue; @@ -912,10 +936,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } var endValue = scan; - chFirst = scan.Take(); // expecting: /r - chSecond = scan.Take(); // expecting: /n + chFirst = scan.Take(); // expecting: \r + chSecond = scan.Take(); // expecting: \n - if (chSecond != '\n') + if (chSecond == -1) + { + return false; + } + else if (chSecond != '\n') { // "\r" was all by itself, move just after it and try again scan = endValue; @@ -924,7 +952,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } var chThird = scan.Peek(); - if (chThird == ' ' || chThird == '\t') + if (chThird == -1) + { + return false; + } + else if (chThird == ' ' || chThird == '\t') { // special case, "\r\n " or "\r\n\t". // this is considered wrapping"linear whitespace" and is actually part of the header value From b61942a559cf52bc92ee8748c88a4a1da635a05d Mon Sep 17 00:00:00 2001 From: Nate McMaster Date: Wed, 9 Mar 2016 16:35:07 -0800 Subject: [PATCH 0647/1662] Limit the branches that build on our public CI. [ci skip] --- .travis.yml | 6 ++++++ appveyor.yml | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/.travis.yml b/.travis.yml index 36f2784903..08f30d7f07 100644 --- a/.travis.yml +++ b/.travis.yml @@ -26,5 +26,11 @@ os: - linux - osx osx_image: xcode7.1 +branches: + only: + - master + - release + - dev + - /^(.*\\/)?ci-.*$/ script: - ./build.sh --quiet verify diff --git a/appveyor.yml b/appveyor.yml index 636a7618d3..15ffe737a5 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,5 +1,11 @@ init: - git config --global core.autocrlf true +branches: + only: + - master + - release + - dev + - /^(.*\\/)?ci-.*$/ build_script: - build.cmd --quiet verify clone_depth: 1 From 6493bd76783465d123461311481531c15b42b983 Mon Sep 17 00:00:00 2001 From: Nate McMaster Date: Wed, 9 Mar 2016 17:44:48 -0800 Subject: [PATCH 0648/1662] Fix backslashes in yml config. [ci skip] --- .travis.yml | 2 +- appveyor.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 08f30d7f07..6108295a27 100644 --- a/.travis.yml +++ b/.travis.yml @@ -31,6 +31,6 @@ branches: - master - release - dev - - /^(.*\\/)?ci-.*$/ + - /^(.*\/)?ci-.*$/ script: - ./build.sh --quiet verify diff --git a/appveyor.yml b/appveyor.yml index 15ffe737a5..be95b88d6f 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -5,7 +5,7 @@ branches: - master - release - dev - - /^(.*\\/)?ci-.*$/ + - /^(.*\/)?ci-.*$/ build_script: - build.cmd --quiet verify clone_depth: 1 From ca75eed5d287c9df8958217453727f62ac19a019 Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Thu, 10 Mar 2016 19:05:20 -0800 Subject: [PATCH 0649/1662] Update README.md --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 854a25705f..a693db070f 100644 --- a/README.md +++ b/README.md @@ -3,8 +3,8 @@ KestrelHttpServer AppVeyor: [![AppVeyor](https://ci.appveyor.com/api/projects/status/nr0s92ykm57q0bjv/branch/dev?svg=true)](https://ci.appveyor.com/project/aspnetci/KestrelHttpServer/branch/dev) -Travis: [![Travis](https://travis-ci.org/aspnet/KestrelHttpServer.svg?branch=dev)](https://travis-ci.org/aspnet/KestrelHttpServer) +Travis: [![Travis](https://travis-ci.org/aspnet/KestrelHttpServer.svg?branch=dev)](https://travis-ci.org/aspnet/KestrelHttpServer) -This repo contains a web server for ASP.NET 5 based on [libuv](https://github.com/libuv/libuv). +This repo contains a web server for ASP.NET Core based on [libuv](https://github.com/libuv/libuv). -This project is part of ASP.NET 5. You can find samples, documentation and getting started instructions for ASP.NET 5 at the [Home](https://github.com/aspnet/home) repo. +This project is part of ASP.NET Core. You can find samples, documentation and getting started instructions for ASP.NET Core at the [Home](https://github.com/aspnet/home) repo. From fb8cf86f715ff8f865ba077117558b22fdeffe50 Mon Sep 17 00:00:00 2001 From: Brice Lambson Date: Thu, 10 Mar 2016 10:32:26 -0800 Subject: [PATCH 0650/1662] Don't reference facades in NuSpec These can be removed entirely after dotnet/cli#164 --- src/Microsoft.AspNetCore.Server.Kestrel/project.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/project.json b/src/Microsoft.AspNetCore.Server.Kestrel/project.json index c1024d14ae..ff0115f2c4 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/project.json +++ b/src/Microsoft.AspNetCore.Server.Kestrel/project.json @@ -28,7 +28,7 @@ "frameworks": { "net451": { "frameworkAssemblies": { - "System.Threading.Tasks": "" + "System.Threading.Tasks": { "type": "build" } } }, "netstandard1.3": { From 7c67366e8460818168a46ed69a6407c44af32faf Mon Sep 17 00:00:00 2001 From: Pranav K Date: Fri, 11 Mar 2016 21:40:48 -0800 Subject: [PATCH 0651/1662] Fix CI build failure --- src/Microsoft.AspNetCore.Server.Kestrel/project.json | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/project.json b/src/Microsoft.AspNetCore.Server.Kestrel/project.json index ff0115f2c4..dd0812020e 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/project.json +++ b/src/Microsoft.AspNetCore.Server.Kestrel/project.json @@ -28,6 +28,7 @@ "frameworks": { "net451": { "frameworkAssemblies": { + "System.Runtime": { "type": "build" }, "System.Threading.Tasks": { "type": "build" } } }, From 8e24c3a7089b9edf20498f22a1e387e2b87de307 Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Thu, 10 Mar 2016 14:06:59 -0800 Subject: [PATCH 0652/1662] Fix deadlock when connection is simultaneously aborted and ended (#684). --- .../Http/Connection.cs | 25 ++++++++++--------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Connection.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Connection.cs index 3280c4082a..a5ede79183 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Connection.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Connection.cs @@ -152,23 +152,24 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http public virtual void Abort() { - lock (_stateLock) + // Frame.Abort calls user code while this method is always + // called from a libuv thread. + System.Threading.ThreadPool.QueueUserWorkItem(state => { - if (_connectionState == ConnectionState.CreatingFrame) + var connection = (Connection)state; + + lock (connection._stateLock) { - _connectionState = ConnectionState.ToDisconnect; - } - else - { - // Frame.Abort calls user code while this method is always - // called from a libuv thread. - System.Threading.ThreadPool.QueueUserWorkItem(state => + if (connection._connectionState == ConnectionState.CreatingFrame) + { + connection._connectionState = ConnectionState.ToDisconnect; + } + else { - var connection = (Connection)state; connection._frame.Abort(); - }, this); + } } - } + }, this); } // Called on Libuv thread From bd1c815340f3b76fbd0bf4492d1b9889cf327a2a Mon Sep 17 00:00:00 2001 From: Ajay Bhargav Baaskaran Date: Mon, 14 Mar 2016 14:43:20 -0700 Subject: [PATCH 0653/1662] Updated Json.Net version --- .../project.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/Microsoft.AspNetCore.Server.Kestrel.LibuvCopier/project.json b/tools/Microsoft.AspNetCore.Server.Kestrel.LibuvCopier/project.json index a498a5cc58..28c3538249 100644 --- a/tools/Microsoft.AspNetCore.Server.Kestrel.LibuvCopier/project.json +++ b/tools/Microsoft.AspNetCore.Server.Kestrel.LibuvCopier/project.json @@ -5,7 +5,7 @@ }, "dependencies": { "Microsoft.Extensions.PlatformAbstractions": "1.0.0-*", - "Newtonsoft.Json": "8.0.2" + "Newtonsoft.Json": "8.0.3" }, "frameworks": { "netstandardapp1.5": { From 65299175301b60298158e7f8a50669d96369ef4f Mon Sep 17 00:00:00 2001 From: Pranav K Date: Mon, 14 Mar 2016 17:53:37 -0700 Subject: [PATCH 0654/1662] Reacting to Hosting changes --- samples/LargeResponseApp/Startup.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/LargeResponseApp/Startup.cs b/samples/LargeResponseApp/Startup.cs index b562ac6ebb..6c947fea22 100644 --- a/samples/LargeResponseApp/Startup.cs +++ b/samples/LargeResponseApp/Startup.cs @@ -41,7 +41,7 @@ namespace LargeResponseApp { var host = new WebHostBuilder() .UseDefaultConfiguration(args) - .UseApplicationBasePath(Directory.GetCurrentDirectory()) + .UseContentRoot(Directory.GetCurrentDirectory()) .UseStartup() .Build(); From 0cffed76df2c33cb93173256b0744a585a958250 Mon Sep 17 00:00:00 2001 From: Pranav K Date: Mon, 14 Mar 2016 18:11:55 -0700 Subject: [PATCH 0655/1662] Fixing missed sample --- samples/SampleApp/Startup.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/SampleApp/Startup.cs b/samples/SampleApp/Startup.cs index e2150d030b..9225f7d9ae 100644 --- a/samples/SampleApp/Startup.cs +++ b/samples/SampleApp/Startup.cs @@ -65,7 +65,7 @@ namespace SampleApp { var host = new WebHostBuilder() .UseDefaultConfiguration(args) - .UseApplicationBasePath(Directory.GetCurrentDirectory()) + .UseContentRoot(Directory.GetCurrentDirectory()) .UseStartup() .Build(); From a220948c8faa2dab5d653d768fcde405518d74db Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Tue, 15 Mar 2016 05:49:31 -0700 Subject: [PATCH 0656/1662] Don't break build if src folder is not present (#701). --- makefile.shade | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/makefile.shade b/makefile.shade index c858bc893e..730b193323 100644 --- a/makefile.shade +++ b/makefile.shade @@ -7,9 +7,9 @@ use-standard-lifecycle k-standard-goals custom-goals -exec program='dotnet' commandline='restore ../../tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode' workingdir='${kestrelSrcDir}' -exec program='dotnet' commandline='run -p ../../tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode Http/FrameHeaders.Generated.cs Http/Frame.Generated.cs' workingdir='${kestrelSrcDir}' - -exec program='dotnet' commandline='restore' workingdir='${kestrelSrcDir}' -exec program='dotnet' commandline='restore ../../tools/Microsoft.AspNetCore.Server.Kestrel.LibuvCopier' workingdir='${kestrelSrcDir}' -exec program='dotnet' commandline='run -p ../../tools/Microsoft.AspNetCore.Server.Kestrel.LibuvCopier' workingdir='${kestrelSrcDir}' \ No newline at end of file +#initialize if='Directory.Exists("src")' + exec program='dotnet' commandline='restore ../../tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode' workingdir='${kestrelSrcDir}' + exec program='dotnet' commandline='run -p ../../tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode Http/FrameHeaders.Generated.cs Http/Frame.Generated.cs' workingdir='${kestrelSrcDir}' + exec program='dotnet' commandline='restore' workingdir='${kestrelSrcDir}' + exec program='dotnet' commandline='restore ../../tools/Microsoft.AspNetCore.Server.Kestrel.LibuvCopier' workingdir='${kestrelSrcDir}' + exec program='dotnet' commandline='run -p ../../tools/Microsoft.AspNetCore.Server.Kestrel.LibuvCopier' workingdir='${kestrelSrcDir}' From b55bef20aa8ca7e5c14b06a4d89d7ba192029891 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Fri, 4 Mar 2016 14:47:35 -0800 Subject: [PATCH 0657/1662] Allow the server to forcefully close socket it tests with connection failures - This is a delayed reaction to 54caf30 which causes connections closed from the server to be closed less gracefully due to no longer waiting for a FIN from the client --- .../ChunkedRequestTests.cs | 4 ++-- .../ChunkedResponseTests.cs | 4 ++-- .../EngineTests.cs | 10 +++++----- .../TestConnection.cs | 19 +++++++++++++++++++ 4 files changed, 28 insertions(+), 9 deletions(-) diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedRequestTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedRequestTests.cs index f741539480..8b34273913 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedRequestTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedRequestTests.cs @@ -373,7 +373,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests "HTTP/1.1 400 Bad Request", ""); await connection.ReceiveStartsWith("Date:"); - await connection.ReceiveEnd( + await connection.ReceiveForcedEnd( "Content-Length: 0", "Server: Kestrel", "", @@ -417,7 +417,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests "HTTP/1.1 400 Bad Request", ""); await connection.ReceiveStartsWith("Date:"); - await connection.ReceiveEnd( + await connection.ReceiveForcedEnd( "Content-Length: 0", "Server: Kestrel", "", diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedResponseTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedResponseTests.cs index 106959057a..59b2e16e10 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedResponseTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedResponseTests.cs @@ -122,7 +122,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests "GET / HTTP/1.1", "", ""); - await connection.ReceiveEnd( + await connection.ReceiveForcedEnd( "HTTP/1.1 200 OK", "Transfer-Encoding: chunked", "", @@ -153,7 +153,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests ""); // Headers are sent before connection is closed, but chunked body terminator isn't sent - await connection.ReceiveEnd( + await connection.ReceiveForcedEnd( "HTTP/1.1 200 OK", "Transfer-Encoding: chunked", "", diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs index 2a4e788c58..9c42dac2af 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs @@ -263,7 +263,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { using (var connection = new TestConnection(server.Port)) { - await connection.Send( + await connection.SendEnd( "POST / HTTP/1.0", "Content-Length: 11", "", @@ -638,7 +638,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests "GET / HTTP/1.1", "", ""); - await connection.ReceiveEnd( + await connection.ReceiveForcedEnd( "HTTP/1.1 200 OK", "Content-Length: 11", "", @@ -680,7 +680,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests "GET / HTTP/1.1", "", ""); - await connection.ReceiveEnd( + await connection.ReceiveForcedEnd( "HTTP/1.1 200 OK", "Content-Length: 11", "", @@ -870,7 +870,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests "GET / HTTP/1.1", "", ""); - await connection.ReceiveEnd( + await connection.ReceiveForcedEnd( "HTTP/1.1 200 OK", "Content-Length: 11", "", @@ -941,7 +941,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests "", ""); - await connection.ReceiveEnd( + await connection.ReceiveForcedEnd( "HTTP/1.1 200 OK", "Content-Length: 5", "", diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestConnection.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/TestConnection.cs index f7f3e36b4e..1c929bcb57 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/TestConnection.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/TestConnection.cs @@ -126,6 +126,25 @@ namespace Microsoft.AspNetCore.Server.KestrelTests Assert.Equal("", text); } + public async Task ReceiveForcedEnd(params string[] lines) + { + await Receive(lines); + + try + { + var ch = new char[128]; + var count = await _reader.ReadAsync(ch, 0, 128); + var text = new string(ch, 0, count); + Assert.Equal("", text); + } + catch (IOException) + { + // The server is forcefully closing the connection so an IOException: + // "Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host." + // isn't guaranteed but not unexpected. + } + } + public static Socket CreateConnectedLoopbackSocket(int port) { var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); From 850632a09101ce9c4baf04af2b294962efcf0b0a Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Fri, 4 Mar 2016 15:22:52 -0800 Subject: [PATCH 0658/1662] Ensure KestrelThreads get stopped in tests if there is a startup failure --- .../TestServer.cs | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestServer.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/TestServer.cs index 6a84a29fd5..2e51e27b3e 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/TestServer.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/TestServer.cs @@ -33,20 +33,25 @@ namespace Microsoft.AspNetCore.Server.KestrelTests public int Port => _address.Port; public TestServer(RequestDelegate app, ServiceContext context, string serverAddress) - { - Create(app, context, serverAddress); - } - - public void Create(RequestDelegate app, ServiceContext context, string serverAddress) { context.FrameFactory = connectionContext => { return new Frame(new DummyApplication(app), connectionContext); }; - _engine = new KestrelEngine(context); - _engine.Start(1); - _address = ServerAddress.FromUrl(serverAddress); - _server = _engine.CreateServer(_address); + + try + { + _engine = new KestrelEngine(context); + _engine.Start(1); + _address = ServerAddress.FromUrl(serverAddress); + _server = _engine.CreateServer(_address); + } + catch + { + _server?.Dispose(); + _engine?.Dispose(); + throw; + } } public void Dispose() From 84a68208d0b32d227a547daa32d2b25cad48ee92 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Thu, 10 Mar 2016 09:14:36 -0800 Subject: [PATCH 0659/1662] Remove race condition from socket input that could stall reads - Without the _sync lock, if new data was produced as ConsumingComplete was called, the next "await SocketInput" might never complete despite not all data being examined. - If more data is produced afterward, the stall would be prevented, but this isn't always the case such as during the end of the request. --- .../Http/SocketInput.cs | 154 ++++++++++-------- 1 file changed, 82 insertions(+), 72 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketInput.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketInput.cs index 98efa48692..f57d3f6289 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketInput.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketInput.cs @@ -28,6 +28,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http private MemoryPoolBlock _pinned; private int _consumingState; + private object _sync = new object(); public SocketInput(MemoryPool memory, IThreadPool threadPool) { @@ -58,64 +59,70 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http public void IncomingData(byte[] buffer, int offset, int count) { - if (count > 0) + lock (_sync) { - if (_tail == null) + if (count > 0) { - _tail = _memory.Lease(); + if (_tail == null) + { + _tail = _memory.Lease(); + } + + var iterator = new MemoryPoolIterator(_tail, _tail.End); + iterator.CopyFrom(buffer, offset, count); + + if (_head == null) + { + _head = _tail; + } + + _tail = iterator.Block; + } + else + { + RemoteIntakeFin = true; } - var iterator = new MemoryPoolIterator(_tail, _tail.End); - iterator.CopyFrom(buffer, offset, count); - - if (_head == null) - { - _head = _tail; - } - - _tail = iterator.Block; + Complete(); } - else - { - RemoteIntakeFin = true; - } - - Complete(); } public void IncomingComplete(int count, Exception error) { - if (_pinned != null) + lock (_sync) { - _pinned.End += count; + if (_pinned != null) + { + _pinned.End += count; - if (_head == null) - { - _head = _tail = _pinned; - } - else if (_tail == _pinned) - { - // NO-OP: this was a read into unoccupied tail-space - } - else - { - _tail.Next = _pinned; - _tail = _pinned; + if (_head == null) + { + _head = _tail = _pinned; + } + else if (_tail == _pinned) + { + // NO-OP: this was a read into unoccupied tail-space + } + else + { + _tail.Next = _pinned; + _tail = _pinned; + } + + _pinned = null; } - _pinned = null; - } + if (count == 0) + { + RemoteIntakeFin = true; + } + if (error != null) + { + _awaitableError = error; + } - if (count == 0) - { - RemoteIntakeFin = true; + Complete(); } - if (error != null) - { - _awaitableError = error; - } - - Complete(); } public void IncomingDeferred() @@ -162,40 +169,43 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http MemoryPoolIterator consumed, MemoryPoolIterator examined) { - MemoryPoolBlock returnStart = null; - MemoryPoolBlock returnEnd = null; - - if (!consumed.IsDefault) + lock (_sync) { - returnStart = _head; - returnEnd = consumed.Block; - _head = consumed.Block; - _head.Start = consumed.Index; - } + MemoryPoolBlock returnStart = null; + MemoryPoolBlock returnEnd = null; - if (!examined.IsDefault && - examined.IsEnd && - RemoteIntakeFin == false && - _awaitableError == null) - { - _manualResetEvent.Reset(); + if (!consumed.IsDefault) + { + returnStart = _head; + returnEnd = consumed.Block; + _head = consumed.Block; + _head.Start = consumed.Index; + } - Interlocked.CompareExchange( - ref _awaitableState, - _awaitableIsNotCompleted, - _awaitableIsCompleted); - } + if (!examined.IsDefault && + examined.IsEnd && + RemoteIntakeFin == false && + _awaitableError == null) + { + _manualResetEvent.Reset(); - while (returnStart != returnEnd) - { - var returnBlock = returnStart; - returnStart = returnStart.Next; - returnBlock.Pool.Return(returnBlock); - } + Interlocked.CompareExchange( + ref _awaitableState, + _awaitableIsNotCompleted, + _awaitableIsCompleted); + } - if (Interlocked.CompareExchange(ref _consumingState, 0, 1) != 1) - { - throw new InvalidOperationException("No ongoing consuming operation to complete."); + while (returnStart != returnEnd) + { + var returnBlock = returnStart; + returnStart = returnStart.Next; + returnBlock.Pool.Return(returnBlock); + } + + if (Interlocked.CompareExchange(ref _consumingState, 0, 1) != 1) + { + throw new InvalidOperationException("No ongoing consuming operation to complete."); + } } } From 792f3ad08909c4ecd872eea043076447f1d70ae4 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Thu, 17 Mar 2016 23:01:42 -0700 Subject: [PATCH 0660/1662] Fix race preventing handling of the last request sent over a connection We need to attempt to consume start lines and headers even after SocketInput.RemoteIntakeFin is set to true to ensure we don't close a connection without giving the application a chance to respond to a request sent immediately before the a FIN from the client. --- .../Http/FrameOfT.cs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameOfT.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameOfT.cs index 053688b587..40a160a0fe 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameOfT.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameOfT.cs @@ -37,8 +37,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (SocketInput.RemoteIntakeFin) { + if (TakeStartLine(SocketInput)) + { + break; + } + return; } + await SocketInput; } @@ -48,8 +54,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (SocketInput.RemoteIntakeFin) { + if (TakeMessageHeaders(SocketInput, FrameRequestHeaders)) + { + break; + } + return; } + await SocketInput; } From f13c418a65db4426ebf265fa7eb34fe741b4163b Mon Sep 17 00:00:00 2001 From: Doug Bunting Date: Thu, 17 Mar 2016 22:17:29 -0700 Subject: [PATCH 0661/1662] React to HttpAbstractions change: No features in `.Internal` namespace - see issue aspnet/HttpAbstractions#561 and pull aspnet/HttpAbstractions#589 --- .../Http/Frame.Generated.cs | 42 +++++++++---------- .../FrameFeatureCollection.cs | 3 +- 2 files changed, 22 insertions(+), 23 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.Generated.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.Generated.cs index 49911c71cc..cadd574717 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.Generated.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.Generated.cs @@ -2,22 +2,22 @@ using System; using System.Collections.Generic; -namespace Microsoft.AspNetCore.Server.Kestrel.Http +namespace Microsoft.AspNetCore.Server.Kestrel.Http { public partial class Frame { private static readonly Type IHttpRequestFeatureType = typeof(global::Microsoft.AspNetCore.Http.Features.IHttpRequestFeature); private static readonly Type IHttpResponseFeatureType = typeof(global::Microsoft.AspNetCore.Http.Features.IHttpResponseFeature); private static readonly Type IHttpRequestIdentifierFeatureType = typeof(global::Microsoft.AspNetCore.Http.Features.IHttpRequestIdentifierFeature); - private static readonly Type IServiceProvidersFeatureType = typeof(global::Microsoft.AspNetCore.Http.Features.Internal.IServiceProvidersFeature); + private static readonly Type IServiceProvidersFeatureType = typeof(global::Microsoft.AspNetCore.Http.Features.IServiceProvidersFeature); private static readonly Type IHttpRequestLifetimeFeatureType = typeof(global::Microsoft.AspNetCore.Http.Features.IHttpRequestLifetimeFeature); private static readonly Type IHttpConnectionFeatureType = typeof(global::Microsoft.AspNetCore.Http.Features.IHttpConnectionFeature); private static readonly Type IHttpAuthenticationFeatureType = typeof(global::Microsoft.AspNetCore.Http.Features.Authentication.IHttpAuthenticationFeature); - private static readonly Type IQueryFeatureType = typeof(global::Microsoft.AspNetCore.Http.Features.Internal.IQueryFeature); - private static readonly Type IFormFeatureType = typeof(global::Microsoft.AspNetCore.Http.Features.Internal.IFormFeature); + private static readonly Type IQueryFeatureType = typeof(global::Microsoft.AspNetCore.Http.Features.IQueryFeature); + private static readonly Type IFormFeatureType = typeof(global::Microsoft.AspNetCore.Http.Features.IFormFeature); private static readonly Type IHttpUpgradeFeatureType = typeof(global::Microsoft.AspNetCore.Http.Features.IHttpUpgradeFeature); - private static readonly Type IResponseCookiesFeatureType = typeof(global::Microsoft.AspNetCore.Http.Features.Internal.IResponseCookiesFeature); - private static readonly Type IItemsFeatureType = typeof(global::Microsoft.AspNetCore.Http.Features.Internal.IItemsFeature); + private static readonly Type IResponseCookiesFeatureType = typeof(global::Microsoft.AspNetCore.Http.Features.IResponseCookiesFeature); + private static readonly Type IItemsFeatureType = typeof(global::Microsoft.AspNetCore.Http.Features.IItemsFeature); private static readonly Type ITlsConnectionFeatureType = typeof(global::Microsoft.AspNetCore.Http.Features.ITlsConnectionFeature); private static readonly Type IHttpWebSocketFeatureType = typeof(global::Microsoft.AspNetCore.Http.Features.IHttpWebSocketFeature); private static readonly Type ISessionFeatureType = typeof(global::Microsoft.AspNetCore.Http.Features.ISessionFeature); @@ -75,7 +75,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { return _currentIHttpRequestIdentifierFeature; } - if (key == typeof(global::Microsoft.AspNetCore.Http.Features.Internal.IServiceProvidersFeature)) + if (key == typeof(global::Microsoft.AspNetCore.Http.Features.IServiceProvidersFeature)) { return _currentIServiceProvidersFeature; } @@ -91,11 +91,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { return _currentIHttpAuthenticationFeature; } - if (key == typeof(global::Microsoft.AspNetCore.Http.Features.Internal.IQueryFeature)) + if (key == typeof(global::Microsoft.AspNetCore.Http.Features.IQueryFeature)) { return _currentIQueryFeature; } - if (key == typeof(global::Microsoft.AspNetCore.Http.Features.Internal.IFormFeature)) + if (key == typeof(global::Microsoft.AspNetCore.Http.Features.IFormFeature)) { return _currentIFormFeature; } @@ -103,11 +103,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { return _currentIHttpUpgradeFeature; } - if (key == typeof(global::Microsoft.AspNetCore.Http.Features.Internal.IResponseCookiesFeature)) + if (key == typeof(global::Microsoft.AspNetCore.Http.Features.IResponseCookiesFeature)) { return _currentIResponseCookiesFeature; } - if (key == typeof(global::Microsoft.AspNetCore.Http.Features.Internal.IItemsFeature)) + if (key == typeof(global::Microsoft.AspNetCore.Http.Features.IItemsFeature)) { return _currentIItemsFeature; } @@ -149,7 +149,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http _currentIHttpRequestIdentifierFeature = feature; return; } - if (key == typeof(global::Microsoft.AspNetCore.Http.Features.Internal.IServiceProvidersFeature)) + if (key == typeof(global::Microsoft.AspNetCore.Http.Features.IServiceProvidersFeature)) { _currentIServiceProvidersFeature = feature; return; @@ -169,12 +169,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http _currentIHttpAuthenticationFeature = feature; return; } - if (key == typeof(global::Microsoft.AspNetCore.Http.Features.Internal.IQueryFeature)) + if (key == typeof(global::Microsoft.AspNetCore.Http.Features.IQueryFeature)) { _currentIQueryFeature = feature; return; } - if (key == typeof(global::Microsoft.AspNetCore.Http.Features.Internal.IFormFeature)) + if (key == typeof(global::Microsoft.AspNetCore.Http.Features.IFormFeature)) { _currentIFormFeature = feature; return; @@ -184,12 +184,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http _currentIHttpUpgradeFeature = feature; return; } - if (key == typeof(global::Microsoft.AspNetCore.Http.Features.Internal.IResponseCookiesFeature)) + if (key == typeof(global::Microsoft.AspNetCore.Http.Features.IResponseCookiesFeature)) { _currentIResponseCookiesFeature = feature; return; } - if (key == typeof(global::Microsoft.AspNetCore.Http.Features.Internal.IItemsFeature)) + if (key == typeof(global::Microsoft.AspNetCore.Http.Features.IItemsFeature)) { _currentIItemsFeature = feature; return; @@ -233,7 +233,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } if (_currentIServiceProvidersFeature != null) { - yield return new KeyValuePair(IServiceProvidersFeatureType, _currentIServiceProvidersFeature as global::Microsoft.AspNetCore.Http.Features.Internal.IServiceProvidersFeature); + yield return new KeyValuePair(IServiceProvidersFeatureType, _currentIServiceProvidersFeature as global::Microsoft.AspNetCore.Http.Features.IServiceProvidersFeature); } if (_currentIHttpRequestLifetimeFeature != null) { @@ -249,11 +249,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } if (_currentIQueryFeature != null) { - yield return new KeyValuePair(IQueryFeatureType, _currentIQueryFeature as global::Microsoft.AspNetCore.Http.Features.Internal.IQueryFeature); + yield return new KeyValuePair(IQueryFeatureType, _currentIQueryFeature as global::Microsoft.AspNetCore.Http.Features.IQueryFeature); } if (_currentIFormFeature != null) { - yield return new KeyValuePair(IFormFeatureType, _currentIFormFeature as global::Microsoft.AspNetCore.Http.Features.Internal.IFormFeature); + yield return new KeyValuePair(IFormFeatureType, _currentIFormFeature as global::Microsoft.AspNetCore.Http.Features.IFormFeature); } if (_currentIHttpUpgradeFeature != null) { @@ -261,11 +261,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } if (_currentIResponseCookiesFeature != null) { - yield return new KeyValuePair(IResponseCookiesFeatureType, _currentIResponseCookiesFeature as global::Microsoft.AspNetCore.Http.Features.Internal.IResponseCookiesFeature); + yield return new KeyValuePair(IResponseCookiesFeatureType, _currentIResponseCookiesFeature as global::Microsoft.AspNetCore.Http.Features.IResponseCookiesFeature); } if (_currentIItemsFeature != null) { - yield return new KeyValuePair(IItemsFeatureType, _currentIItemsFeature as global::Microsoft.AspNetCore.Http.Features.Internal.IItemsFeature); + yield return new KeyValuePair(IItemsFeatureType, _currentIItemsFeature as global::Microsoft.AspNetCore.Http.Features.IItemsFeature); } if (_currentITlsConnectionFeature != null) { diff --git a/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/FrameFeatureCollection.cs b/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/FrameFeatureCollection.cs index d4504cc9ca..33e1e083d3 100644 --- a/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/FrameFeatureCollection.cs +++ b/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/FrameFeatureCollection.cs @@ -2,7 +2,6 @@ using System; using System.Collections.Generic; using System.Linq; using Microsoft.AspNetCore.Http.Features; -using Microsoft.AspNetCore.Http.Features.Internal; using Microsoft.AspNetCore.Http.Features.Authentication; namespace Microsoft.AspNetCore.Server.Kestrel.GeneratedCode @@ -67,7 +66,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.GeneratedCode using System; using System.Collections.Generic; -namespace Microsoft.AspNetCore.Server.Kestrel.Http +namespace Microsoft.AspNetCore.Server.Kestrel.Http {{ public partial class Frame {{{Each(allFeatures, feature => $@" From fd70fb732d28d2c8a2ef871f6ef0d9487a6de46e Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Tue, 22 Mar 2016 17:55:21 -0700 Subject: [PATCH 0662/1662] Add explanatory comments for previous commit. --- src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameOfT.cs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameOfT.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameOfT.cs index 40a160a0fe..21eeaa1c6a 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameOfT.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameOfT.cs @@ -37,6 +37,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (SocketInput.RemoteIntakeFin) { + // We need to attempt to consume start lines and headers even after + // SocketInput.RemoteIntakeFin is set to true to ensure we don't close a + // connection without giving the application a chance to respond to a request + // sent immediately before the a FIN from the client. if (TakeStartLine(SocketInput)) { break; @@ -54,6 +58,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (SocketInput.RemoteIntakeFin) { + // We need to attempt to consume start lines and headers even after + // SocketInput.RemoteIntakeFin is set to true to ensure we don't close a + // connection without giving the application a chance to respond to a request + // sent immediately before the a FIN from the client. if (TakeMessageHeaders(SocketInput, FrameRequestHeaders)) { break; From 4b214115ca5f06a0c1009816a86c60e929f73482 Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Thu, 17 Mar 2016 22:22:49 -0700 Subject: [PATCH 0663/1662] Proper skip reasons for HttpsConnectionFilter tests (#677). --- .../HttpsConnectionFilterTests.cs | 27 +++++++------------ 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/HttpsConnectionFilterTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/HttpsConnectionFilterTests.cs index 32aaa453e4..6666335258 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/HttpsConnectionFilterTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/HttpsConnectionFilterTests.cs @@ -53,8 +53,8 @@ namespace Microsoft.AspNetCore.Server.KestrelTests // https://github.com/aspnet/KestrelHttpServer/issues/240 // This test currently fails on mono because of an issue with SslStream. [ConditionalFact] - [OSSkipCondition(OperatingSystems.Linux)] - [OSSkipCondition(OperatingSystems.MacOSX)] + [OSSkipCondition(OperatingSystems.Linux, SkipReason = "WinHttpHandler not available on non-Windows.")] + [OSSkipCondition(OperatingSystems.MacOSX, SkipReason = "WinHttpHandler not available on non-Windows.")] public async Task CanReadAndWriteWithHttpsConnectionFilter() { RemoteCertificateValidationCallback validationCallback = @@ -96,11 +96,9 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } } - // https://github.com/aspnet/KestrelHttpServer/issues/240 - // This test currently fails on mono because of an issue with SslStream. [ConditionalFact] - [OSSkipCondition(OperatingSystems.Linux)] - [OSSkipCondition(OperatingSystems.MacOSX)] + [OSSkipCondition(OperatingSystems.Linux, SkipReason = "WinHttpHandler not available on non-Windows.")] + [OSSkipCondition(OperatingSystems.MacOSX, SkipReason = "WinHttpHandler not available on non-Windows.")] public async Task RequireCertificateFailsWhenNoCertificate() { RemoteCertificateValidationCallback validationCallback = @@ -143,11 +141,9 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } } - // https://github.com/aspnet/KestrelHttpServer/issues/240 - // This test currently fails on mono because of an issue with SslStream. [ConditionalFact] - [OSSkipCondition(OperatingSystems.Linux)] - [OSSkipCondition(OperatingSystems.MacOSX)] + [OSSkipCondition(OperatingSystems.Linux, SkipReason = "WinHttpHandler not available on non-Windows.")] + [OSSkipCondition(OperatingSystems.MacOSX, SkipReason = "WinHttpHandler not available on non-Windows.")] public async Task AllowCertificateContinuesWhenNoCertificate() { RemoteCertificateValidationCallback validationCallback = @@ -197,11 +193,8 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } } - // https://github.com/aspnet/KestrelHttpServer/issues/240 - // This test currently fails on mono because of an issue with SslStream. [ConditionalFact] - [OSSkipCondition(OperatingSystems.Linux)] - [OSSkipCondition(OperatingSystems.MacOSX)] + [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "This test currently fails on Mono because of an issue with SslStream (https://github.com/aspnet/KestrelHttpServer/issues/240).")] public async Task CertificatePassedToHttpContext() { RemoteCertificateValidationCallback validationCallback = @@ -263,11 +256,9 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } } - // https://github.com/aspnet/KestrelHttpServer/issues/240 - // This test currently fails on mono because of an issue with SslStream. [ConditionalFact] - [OSSkipCondition(OperatingSystems.Linux)] - [OSSkipCondition(OperatingSystems.MacOSX)] + [OSSkipCondition(OperatingSystems.Linux, SkipReason = "WinHttpHandler not available on non-Windows.")] + [OSSkipCondition(OperatingSystems.MacOSX, SkipReason = "WinHttpHandler not available on non-Windows.")] public async Task HttpsSchemePassedToRequestFeature() { RemoteCertificateValidationCallback validationCallback = From 528832fc043b89f1ce706fc2d544e01f0a1d8d97 Mon Sep 17 00:00:00 2001 From: John Luo Date: Tue, 22 Mar 2016 11:45:34 -0700 Subject: [PATCH 0664/1662] Reacting to Hosting changes --- samples/LargeResponseApp/Startup.cs | 2 +- samples/SampleApp/Startup.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/samples/LargeResponseApp/Startup.cs b/samples/LargeResponseApp/Startup.cs index 6c947fea22..a45f95e715 100644 --- a/samples/LargeResponseApp/Startup.cs +++ b/samples/LargeResponseApp/Startup.cs @@ -40,7 +40,7 @@ namespace LargeResponseApp public static void Main(string[] args) { var host = new WebHostBuilder() - .UseDefaultConfiguration(args) + .UseDefaultHostingConfiguration(args) .UseContentRoot(Directory.GetCurrentDirectory()) .UseStartup() .Build(); diff --git a/samples/SampleApp/Startup.cs b/samples/SampleApp/Startup.cs index 9225f7d9ae..54ef0b80ce 100644 --- a/samples/SampleApp/Startup.cs +++ b/samples/SampleApp/Startup.cs @@ -64,7 +64,7 @@ namespace SampleApp public static void Main(string[] args) { var host = new WebHostBuilder() - .UseDefaultConfiguration(args) + .UseDefaultHostingConfiguration(args) .UseContentRoot(Directory.GetCurrentDirectory()) .UseStartup() .Build(); From 084bd6af3603029c2df6750f8d6d63ea4d726cc3 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Tue, 29 Mar 2016 12:45:23 -0700 Subject: [PATCH 0665/1662] Fix sample apps Fixes #714 --- samples/LargeResponseApp/project.json | 2 +- samples/SampleApp/Startup.cs | 4 +--- samples/SampleApp/project.json | 5 +++-- samples/SampleApp/testCert.pfx | Bin 0 -> 2483 bytes 4 files changed, 5 insertions(+), 6 deletions(-) create mode 100644 samples/SampleApp/testCert.pfx diff --git a/samples/LargeResponseApp/project.json b/samples/LargeResponseApp/project.json index 47f829ef1f..5988d499f6 100644 --- a/samples/LargeResponseApp/project.json +++ b/samples/LargeResponseApp/project.json @@ -18,7 +18,7 @@ "dnx451": {}, "netstandardapp1.5": { "dependencies": { - "NETStandard.Library": "1.0.0-*" + "NETStandard.Library": "1.5.0-*" }, "imports": [ "dnxcore50" diff --git a/samples/SampleApp/Startup.cs b/samples/SampleApp/Startup.cs index 54ef0b80ce..b7735816d6 100644 --- a/samples/SampleApp/Startup.cs +++ b/samples/SampleApp/Startup.cs @@ -24,9 +24,7 @@ namespace SampleApp loggerFactory.AddConsole(LogLevel.Trace); - var testCertPath = Path.Combine( - env.ApplicationBasePath, - @"../../test/Microsoft.AspNetCore.Server.KestrelTests/TestResources/testCert.pfx"); + var testCertPath = Path.Combine(env.ApplicationBasePath, "testCert.pfx"); if (File.Exists(testCertPath)) { diff --git a/samples/SampleApp/project.json b/samples/SampleApp/project.json index a561218cbb..86356d30af 100644 --- a/samples/SampleApp/project.json +++ b/samples/SampleApp/project.json @@ -20,7 +20,7 @@ "dnx451": {}, "netstandardapp1.5": { "dependencies": { - "NETStandard.Library": "1.0.0-*", + "NETStandard.Library": "1.5.0-*", "System.Console": "4.0.0-*" }, "imports": [ @@ -29,6 +29,7 @@ } }, "content": [ - "hosting.json" + "hosting.json", + "testCert.pfx" ] } \ No newline at end of file diff --git a/samples/SampleApp/testCert.pfx b/samples/SampleApp/testCert.pfx new file mode 100644 index 0000000000000000000000000000000000000000..7118908c2d730670c16e9f8b2c532a262c951989 GIT binary patch literal 2483 zcmaKuc|27A8pqF>IWr86E&Q@(n=B)p$ug!;QVB6xij*z;uPLG!yCz#DQB)+9G$9m9 zQU)=DWXU?*EZIwG!+0d++P@yZ4Xhoagg?p6B~|Ue7tN=Ny=UD?x#1n1MTq z#c9MHh+D#gd|(a(cN}8i91v^=GcdgW3SmA$49p~gM-dys3jVWdg8+!iVL)pz1LDE5 zSb=|GAn(@R=(Ux!MfS9@}sFu-xDd zIt2+mqSq$glwy_6UNs<2?(qERU!gJ;5j}Pp&6trxG=wi)=@k(w2+fJVnc+qvXVzy(>Om4;L|^)R`t*3nTpAmEmTl(#i!RV#a0t#u6>Q9mY`-Nmcs7$XjXT7 zUmCD`O~_j7!%R#I?cG-7C^hcH)@l?WC1vyw$FFu_(r)jhOq6p}W8sG7NO{YTy8tG4 zrb$tTkag*G?(7lfoGx$4YWui>{{@}-FB2ub=}RX{1zx?j)s-##J9|G7E1@-;7Nuln z9MQoX7FJ76+D#XXT@ZZmLZCufIdf3@OigG6m8I7!GT=7VD|>?6e!z9=eT}*E_tSn6 zl+clHCZ-kcIR#gen#LjMJW8>0QtViaQB#FhqsCb0YPYr3;jRITl@V9Aph24D?r2d` zetCyyCg<*O-u+M& zW^ptmT|}p$VAOZpmbQ1{5fK-6ytEvre#Po}6c2URn`viQAF2+e?Z~PK2&pd>7=7)I zTCYm)@3PFRu_6a6Kb)IpCzQ%e3l%O#SDA+$Pq{Dk{HCqi7z>qd{nVpebffL7h{c4( zmhXn~G+C27S3(IfC)q2KON=YwqHXEo%zc40DgWLzF{%RIdr@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E{Wj5lgLJr9HLB8S9CgOm*>XA8*y4`JE;^s$=bqD#U4;e5C&x&ggKIAVL zrQ)Yd8|{>7Z(6*B&7&4&9(*vDOfHMuR-Dk1IZia*XM^EZUD^{?cWG>J>KrtElc*{K zaVl(7SN2cH4I6Q$bZOpJ8e5LKaG7p;?tJ~#+9QrTYU@f#5`Vo7cEX!szCT}iX-K^2 w#3o+=C+lQz2J+SOEzVX(eJ)e7=eicC{rr9U2VGDcdH?_b literal 0 HcmV?d00001 From f1f185fd2191c964ee90ef6a318031315ad728bc Mon Sep 17 00:00:00 2001 From: Pranav K Date: Wed, 30 Mar 2016 00:38:02 -0700 Subject: [PATCH 0666/1662] Using NetStandard.Library 1.5.0 --- .../project.json | 4 ++-- .../project.json | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/project.json b/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/project.json index 80a11446bc..d248f225e3 100644 --- a/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/project.json +++ b/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/project.json @@ -10,13 +10,13 @@ "frameworks": { "netstandardapp1.5": { "dependencies": { - "NETStandard.Library": "1.0.0-*" + "NETStandard.Library": "1.5.0-*" }, "imports": [ "dnxcore50" ] }, - "dnx451": { + "net451": { "frameworkAssemblies": { "System.Runtime": "", "System.Text.Encoding": "", diff --git a/tools/Microsoft.AspNetCore.Server.Kestrel.LibuvCopier/project.json b/tools/Microsoft.AspNetCore.Server.Kestrel.LibuvCopier/project.json index 28c3538249..1a593a4610 100644 --- a/tools/Microsoft.AspNetCore.Server.Kestrel.LibuvCopier/project.json +++ b/tools/Microsoft.AspNetCore.Server.Kestrel.LibuvCopier/project.json @@ -10,13 +10,13 @@ "frameworks": { "netstandardapp1.5": { "dependencies": { - "NETStandard.Library": "1.0.0-*", + "NETStandard.Library": "1.5.0-*", "System.Dynamic.Runtime": "4.0.11-*" }, "imports": [ "dnxcore50" ] }, - "dnx451": {} + "net451": {} } } \ No newline at end of file From a8e5c0ce30c13cd5227e7cfde9fb7baf5894ac16 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Thu, 3 Mar 2016 15:21:04 -0800 Subject: [PATCH 0667/1662] Log connection id in KestrelTrace.ApplicationError --- .../Http/Frame.cs | 2 +- .../Infrastructure/IKestrelTrace.cs | 2 ++ .../Infrastructure/KestrelTrace.cs | 12 ++++++++++-- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs index d1f87f0a36..4ed675767c 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs @@ -1015,7 +1015,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http _applicationException = new AggregateException(_applicationException, ex); } - Log.ApplicationError(ex); + Log.ApplicationError(ConnectionId, ex); } private enum HttpVersionType diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/IKestrelTrace.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/IKestrelTrace.cs index b5460ecb4c..1b61c3acc9 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/IKestrelTrace.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/IKestrelTrace.cs @@ -39,5 +39,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure void NotAllConnectionsClosedGracefully(); void ApplicationError(Exception ex); + + void ApplicationError(string connectionId, Exception ex); } } \ No newline at end of file diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/KestrelTrace.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/KestrelTrace.cs index f3f12cbd1f..9562b202b5 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/KestrelTrace.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/KestrelTrace.cs @@ -22,6 +22,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel private static readonly Action _connectionWroteFin; private static readonly Action _connectionKeepAlive; private static readonly Action _connectionDisconnect; + private static readonly Action _applicationError; + private static readonly Action _applicationErrorWithId; private static readonly Action _connectionError; private static readonly Action _connectionDisconnectedWrite; private static readonly Action _notAllConnectionsClosedGracefully; @@ -43,7 +45,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel _connectionDisconnect = LoggerMessage.Define(LogLevel.Debug, 10, @"Connection id ""{ConnectionId}"" disconnecting."); // ConnectionWrite: Reserved: 11 // ConnectionWriteCallback: Reserved: 12 - // ApplicationError: Reserved: 13 - LoggerMessage.Define overload not present + _applicationError = LoggerMessage.Define(LogLevel.Error, 13, "An unhandled exception thrown by the application."); + _applicationErrorWithId = LoggerMessage.Define(LogLevel.Error, 13, @"Connection id ""{ConnectionId}"" unhandled exception thrown by the application."); _connectionError = LoggerMessage.Define(LogLevel.Information, 14, @"Connection id ""{ConnectionId}"" communication error"); _connectionDisconnectedWrite = LoggerMessage.Define(LogLevel.Debug, 15, @"Connection id ""{ConnectionId}"" write of ""{count}"" bytes to disconnected client."); _notAllConnectionsClosedGracefully = LoggerMessage.Define(LogLevel.Debug, 16, "Some connections failed to close gracefully during server shutdown."); @@ -120,7 +123,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel public virtual void ApplicationError(Exception ex) { - _logger.LogError(13, ex, "An unhandled exception was thrown by the application."); + _applicationError(_logger, ex); + } + + public virtual void ApplicationError(string connectionId, Exception ex) + { + _applicationErrorWithId(_logger, connectionId, ex); } public virtual void ConnectionError(string connectionId, Exception ex) From f0e438f65f208ba59293331df9fbbf9b925f35cf Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Wed, 30 Mar 2016 11:13:13 -0700 Subject: [PATCH 0668/1662] Remove IKestrelTrace.ApplicationError overload without connection id Add test verifying that exceptions thrown from application tcs continuations run by the LoggingThreadPool don't get logged as general exceptions. --- .../Infrastructure/IKestrelTrace.cs | 2 - .../Infrastructure/KestrelTrace.cs | 13 ++--- .../Infrastructure/LoggingThreadPool.cs | 11 +++-- .../KestrelServerTests.cs | 2 +- .../LoggingThreadPoolTests.cs | 49 +++++++++++++++++++ .../TestHelpers/TestApplicationErrorLogger.cs | 8 +++ .../TestKestrelTrace.cs} | 25 ++-------- 7 files changed, 71 insertions(+), 39 deletions(-) create mode 100644 test/Microsoft.AspNetCore.Server.KestrelTests/LoggingThreadPoolTests.cs rename test/Microsoft.AspNetCore.Server.KestrelTests/{TestLogger.cs => TestHelpers/TestKestrelTrace.cs} (57%) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/IKestrelTrace.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/IKestrelTrace.cs index 1b61c3acc9..4dd0beb17d 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/IKestrelTrace.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/IKestrelTrace.cs @@ -38,8 +38,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure void NotAllConnectionsClosedGracefully(); - void ApplicationError(Exception ex); - void ApplicationError(string connectionId, Exception ex); } } \ No newline at end of file diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/KestrelTrace.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/KestrelTrace.cs index 9562b202b5..6dae29ed37 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/KestrelTrace.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/KestrelTrace.cs @@ -22,8 +22,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel private static readonly Action _connectionWroteFin; private static readonly Action _connectionKeepAlive; private static readonly Action _connectionDisconnect; - private static readonly Action _applicationError; - private static readonly Action _applicationErrorWithId; + private static readonly Action _applicationError; private static readonly Action _connectionError; private static readonly Action _connectionDisconnectedWrite; private static readonly Action _notAllConnectionsClosedGracefully; @@ -45,8 +44,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel _connectionDisconnect = LoggerMessage.Define(LogLevel.Debug, 10, @"Connection id ""{ConnectionId}"" disconnecting."); // ConnectionWrite: Reserved: 11 // ConnectionWriteCallback: Reserved: 12 - _applicationError = LoggerMessage.Define(LogLevel.Error, 13, "An unhandled exception thrown by the application."); - _applicationErrorWithId = LoggerMessage.Define(LogLevel.Error, 13, @"Connection id ""{ConnectionId}"" unhandled exception thrown by the application."); + _applicationError = LoggerMessage.Define(LogLevel.Error, 13, @"Connection id ""{ConnectionId}"": An unhandled exception was thrown by the application."); _connectionError = LoggerMessage.Define(LogLevel.Information, 14, @"Connection id ""{ConnectionId}"" communication error"); _connectionDisconnectedWrite = LoggerMessage.Define(LogLevel.Debug, 15, @"Connection id ""{ConnectionId}"" write of ""{count}"" bytes to disconnected client."); _notAllConnectionsClosedGracefully = LoggerMessage.Define(LogLevel.Debug, 16, "Some connections failed to close gracefully during server shutdown."); @@ -121,14 +119,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel // Reserved: Event ID 12 } - public virtual void ApplicationError(Exception ex) - { - _applicationError(_logger, ex); - } - public virtual void ApplicationError(string connectionId, Exception ex) { - _applicationErrorWithId(_logger, connectionId, ex); + _applicationError(_logger, connectionId, ex); } public virtual void ConnectionError(string connectionId, Exception ex) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/LoggingThreadPool.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/LoggingThreadPool.cs index a5f41987d4..e9625cffec 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/LoggingThreadPool.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/LoggingThreadPool.cs @@ -4,6 +4,7 @@ using System; using System.Threading; using System.Threading.Tasks; +using Microsoft.Extensions.Logging; namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure { @@ -28,7 +29,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure } catch (Exception e) { - _log.ApplicationError(e); + _log.LogError(0, e, "LoggingThreadPool.Run"); } }; @@ -40,7 +41,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure } catch (Exception e) { - _log.ApplicationError(e); + _log.LogError(0, e, "LoggingThreadPool.Complete"); } }; @@ -52,7 +53,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure } catch (Exception e) { - _log.ApplicationError(e); + _log.LogError(0, e, "LoggingThreadPool.Cancel"); } }; } @@ -74,7 +75,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure public void Error(TaskCompletionSource tcs, Exception ex) { - // ex ang _log are closure captured + // ex and _log are closure captured ThreadPool.QueueUserWorkItem((o) => { try @@ -83,7 +84,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure } catch (Exception e) { - _log.ApplicationError(e); + _log.LogError(0, e, "LoggingThreadPool.Error"); } }, tcs); } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerTests.cs index d54202dc9d..8c4e8c1490 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerTests.cs @@ -69,7 +69,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests features.Set(information); var lifetime = new LifetimeNotImplemented(); - var logger = new TestKestrelTrace.TestLogger(); + var logger = new TestApplicationErrorLogger(); return new KestrelServer(features, lifetime, logger); } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/LoggingThreadPoolTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/LoggingThreadPoolTests.cs new file mode 100644 index 0000000000..92b8c2c94f --- /dev/null +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/LoggingThreadPoolTests.cs @@ -0,0 +1,49 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; +using Xunit; + +namespace Microsoft.AspNetCore.Server.KestrelTests +{ + public class LoggingThreadPoolTests + { + [Fact] + public void TcsContinuationErrorsDontGetLoggedAsGeneralErrors() + { + var testLogger = new TestApplicationErrorLogger(); + var testKestrelTrace = new TestKestrelTrace(testLogger); + var threadPool = new LoggingThreadPool(testKestrelTrace); + + var completeTcs = new TaskCompletionSource(); + ThrowSynchronously(completeTcs.Task); + threadPool.Complete(completeTcs); + + var errorTcs = new TaskCompletionSource(); + ThrowSynchronously(errorTcs.Task); + threadPool.Error(errorTcs, new Exception()); + + var cancelTcs = new TaskCompletionSource(); + ThrowSynchronously(cancelTcs.Task); + threadPool.Cancel(cancelTcs); + + Assert.Throws(() => + Task.WhenAll(completeTcs.Task, errorTcs.Task, cancelTcs.Task).Wait()); + + Assert.Equal(0, testLogger.TotalErrorsLogged); + } + + private void ThrowSynchronously(Task task) + { + task.ContinueWith(_ => + { + throw new Exception(); + }, TaskContinuationOptions.ExecuteSynchronously); + } + } +} diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/TestApplicationErrorLogger.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/TestApplicationErrorLogger.cs index f6e7f04169..eb48a70890 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/TestApplicationErrorLogger.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/TestApplicationErrorLogger.cs @@ -12,6 +12,8 @@ namespace Microsoft.AspNetCore.Server.KestrelTests // Application errors are logged using 13 as the eventId. private const int ApplicationErrorEventId = 13; + public int TotalErrorsLogged { get; set; } + public int ApplicationErrorsLogged { get; set; } public IDisposable BeginScopeImpl(object state) @@ -26,6 +28,12 @@ namespace Microsoft.AspNetCore.Server.KestrelTests public void Log(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func formatter) { +#if false + Console.WriteLine($"Log {logLevel}[{eventId}]: {formatter(state, exception)} {exception?.Message}"); +#endif + + TotalErrorsLogged++; + if (eventId.Id == ApplicationErrorEventId) { ApplicationErrorsLogged++; diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestLogger.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/TestKestrelTrace.cs similarity index 57% rename from test/Microsoft.AspNetCore.Server.KestrelTests/TestLogger.cs rename to test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/TestKestrelTrace.cs index 11076560bc..5d811063b1 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/TestLogger.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/TestKestrelTrace.cs @@ -6,9 +6,12 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { public class TestKestrelTrace : KestrelTrace { - public TestKestrelTrace() : base(new TestLogger()) + public TestKestrelTrace() : this(new TestApplicationErrorLogger()) { + } + public TestKestrelTrace(ILogger testLogger) : base(testLogger) + { } public override void ConnectionRead(string connectionId, int count) @@ -25,25 +28,5 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { //_logger.LogDebug(1, @"Connection id ""{ConnectionId}"" send finished with status {status}.", connectionId, status); } - - public class TestLogger : ILogger - { - public void Log(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func formatter) - { -#if false - Console.WriteLine($"Log {logLevel}[{eventId}]: {formatter(state, exception)} {exception?.Message}"); -#endif - } - - public bool IsEnabled(LogLevel logLevel) - { - return true; - } - - public IDisposable BeginScopeImpl(object state) - { - return new Disposable(() => { }); - } - } } } \ No newline at end of file From aa17125f9ec3a6070ed46da7c9ca138c1905b049 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Mon, 14 Mar 2016 11:55:48 -0700 Subject: [PATCH 0669/1662] Fix spelling of "timeout" in kestrel.shutdownTimeout --- .../IKestrelServerInformation.cs | 2 +- .../KestrelServerInformation.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/IKestrelServerInformation.cs b/src/Microsoft.AspNetCore.Server.Kestrel/IKestrelServerInformation.cs index b2ec185075..87a6b645b2 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/IKestrelServerInformation.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/IKestrelServerInformation.cs @@ -15,7 +15,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel /// By default, Kestrel will wait 5 seconds for any ongoing requests to complete before terminating /// the connection. /// A custom timeout can be configured using the "kestrel.shutdownTimeout" key in . - /// The value will be parsed as a float representing the timout in seconds. + /// The value will be parsed as a float representing the timeout in seconds. /// TimeSpan ShutdownTimeout { get; set; } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServerInformation.cs b/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServerInformation.cs index 4e2f4b0515..58f44cede3 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServerInformation.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServerInformation.cs @@ -98,7 +98,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel private TimeSpan GetShutdownTimeout(IConfiguration configuration) { - var shutdownTimeoutString = configuration["kestrel.shutdownTimout"]; + var shutdownTimeoutString = configuration["kestrel.shutdownTimeout"]; float shutdownTimeout; if (float.TryParse(shutdownTimeoutString, NumberStyles.Float, CultureInfo.InvariantCulture, out shutdownTimeout)) From 088b7e5779f9171ce46352d24320bcdf0ba03be5 Mon Sep 17 00:00:00 2001 From: Mike Harder Date: Wed, 30 Mar 2016 12:08:32 -0700 Subject: [PATCH 0670/1662] Add UseKestrel() extension method to IWebHostBuilder (#713) --- samples/LargeResponseApp/Startup.cs | 2 ++ samples/LargeResponseApp/hosting.json | 4 ---- samples/SampleApp/Startup.cs | 2 ++ samples/SampleApp/hosting.json | 4 ---- .../KestrelWebHostBuilderExtensions.cs | 16 ++++++++++++++++ .../AddressRegistrationTests.cs | 2 +- .../PathBaseTests.cs | 2 +- .../RequestTests.cs | 10 +++++----- .../ResponseTests.cs | 6 +++--- .../ThreadCountTests.cs | 2 +- 10 files changed, 31 insertions(+), 19 deletions(-) delete mode 100644 samples/LargeResponseApp/hosting.json delete mode 100644 samples/SampleApp/hosting.json create mode 100644 src/Microsoft.AspNetCore.Server.Kestrel/KestrelWebHostBuilderExtensions.cs diff --git a/samples/LargeResponseApp/Startup.cs b/samples/LargeResponseApp/Startup.cs index a45f95e715..6408c0bd61 100644 --- a/samples/LargeResponseApp/Startup.cs +++ b/samples/LargeResponseApp/Startup.cs @@ -41,6 +41,8 @@ namespace LargeResponseApp { var host = new WebHostBuilder() .UseDefaultHostingConfiguration(args) + .UseKestrel() + .UseUrls("http://localhost:5001/") .UseContentRoot(Directory.GetCurrentDirectory()) .UseStartup() .Build(); diff --git a/samples/LargeResponseApp/hosting.json b/samples/LargeResponseApp/hosting.json deleted file mode 100644 index 72788f30a9..0000000000 --- a/samples/LargeResponseApp/hosting.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "server": "Microsoft.AspNetCore.Server.Kestrel", - "server.urls": "http://localhost:5001/" -} \ No newline at end of file diff --git a/samples/SampleApp/Startup.cs b/samples/SampleApp/Startup.cs index b7735816d6..1590a8dac3 100644 --- a/samples/SampleApp/Startup.cs +++ b/samples/SampleApp/Startup.cs @@ -63,6 +63,8 @@ namespace SampleApp { var host = new WebHostBuilder() .UseDefaultHostingConfiguration(args) + .UseKestrel() + .UseUrls("http://localhost:5000", "https://localhost:5001") .UseContentRoot(Directory.GetCurrentDirectory()) .UseStartup() .Build(); diff --git a/samples/SampleApp/hosting.json b/samples/SampleApp/hosting.json deleted file mode 100644 index 5d7efdc792..0000000000 --- a/samples/SampleApp/hosting.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "server": "Microsoft.AspNetCore.Server.Kestrel", - "server.urls": "http://localhost:5000;https://localhost:5001" -} diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/KestrelWebHostBuilderExtensions.cs b/src/Microsoft.AspNetCore.Server.Kestrel/KestrelWebHostBuilderExtensions.cs new file mode 100644 index 0000000000..aa6115094e --- /dev/null +++ b/src/Microsoft.AspNetCore.Server.Kestrel/KestrelWebHostBuilderExtensions.cs @@ -0,0 +1,16 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System.Reflection; +using Microsoft.AspNetCore.Server.Kestrel; + +namespace Microsoft.AspNetCore.Hosting +{ + public static class KestrelWebHostBuilderExtensions + { + public static IWebHostBuilder UseKestrel(this IWebHostBuilder hostBuilder) + { + return hostBuilder.UseServer(typeof(KestrelServer).GetTypeInfo().Assembly.FullName); + } + } +} diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs index 6a65cb71f9..2422eb527f 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs @@ -40,7 +40,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests var hostBuilder = new WebHostBuilder() .UseConfiguration(config) - .UseServer("Microsoft.AspNetCore.Server.Kestrel") + .UseKestrel() .Configure(ConfigureEchoAddress); using (var host = hostBuilder.Build()) diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/PathBaseTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/PathBaseTests.cs index 3576bd4d8d..12baa2731d 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/PathBaseTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/PathBaseTests.cs @@ -76,7 +76,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests var builder = new WebHostBuilder() .UseConfiguration(config) - .UseServer("Microsoft.AspNetCore.Server.Kestrel") + .UseKestrel() .Configure(app => { app.Run(async context => diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs index db7a6800f2..63f4415042 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs @@ -24,7 +24,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { var port = PortManager.GetPort(); var builder = new WebHostBuilder() - .UseServer("Microsoft.AspNetCore.Server.Kestrel") + .UseKestrel() .UseUrls($"http://localhost:{port}/") .Configure(app => { @@ -74,7 +74,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { var port = PortManager.GetPort(); var builder = new WebHostBuilder() - .UseServer("Microsoft.AspNetCore.Server.Kestrel") + .UseKestrel() .UseUrls($"http://localhost:{port}/") .Configure(app => { @@ -139,7 +139,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { var port = PortManager.GetPort(); var builder = new WebHostBuilder() - .UseServer("Microsoft.AspNetCore.Server.Kestrel") + .UseKestrel() .UseUrls($"http://localhost:{port}") .Configure(app => { @@ -168,7 +168,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { var port = PortManager.GetPort(); var builder = new WebHostBuilder() - .UseServer("Microsoft.AspNetCore.Server.Kestrel") + .UseKestrel() .UseUrls($"http://localhost:{port}/\u0041\u030A") .Configure(app => { @@ -212,7 +212,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { var port = PortManager.GetPort(); var builder = new WebHostBuilder() - .UseServer("Microsoft.AspNetCore.Server.Kestrel") + .UseKestrel() .UseUrls($"http://{registerAddress}:{port}") .Configure(app => { diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs index a6e39a3905..a1dfe66ab1 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs @@ -31,7 +31,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests var hostBuilder = new WebHostBuilder() .UseConfiguration(config) - .UseServer("Microsoft.AspNetCore.Server.Kestrel") + .UseKestrel() .Configure(app => { app.Run(async context => @@ -91,7 +91,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests var hostBuilder = new WebHostBuilder() .UseConfiguration(config) - .UseServer("Microsoft.AspNetCore.Server.Kestrel") + .UseKestrel() .Configure(app => { app.Run(async context => @@ -142,7 +142,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests var hostBuilder = new WebHostBuilder() .UseConfiguration(config) - .UseServer("Microsoft.AspNetCore.Server.Kestrel") + .UseKestrel() .Configure(app => { app.Run(context => diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ThreadCountTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ThreadCountTests.cs index 437bcbe66c..fff6fb4497 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ThreadCountTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ThreadCountTests.cs @@ -26,7 +26,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests var hostBuilder = new WebHostBuilder() .UseConfiguration(config) - .UseServer("Microsoft.AspNetCore.Server.Kestrel") + .UseKestrel() .Configure(app => { var serverInfo = app.ServerFeatures.Get(); From 9584f42f35dd52d560a8197ce7b28ea2c8bee334 Mon Sep 17 00:00:00 2001 From: John Luo Date: Wed, 30 Mar 2016 15:49:13 -0700 Subject: [PATCH 0671/1662] Update samples --- samples/LargeResponseApp/project.json | 3 ++- samples/SampleApp/project.json | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/samples/LargeResponseApp/project.json b/samples/LargeResponseApp/project.json index 5988d499f6..d25c094244 100644 --- a/samples/LargeResponseApp/project.json +++ b/samples/LargeResponseApp/project.json @@ -9,7 +9,8 @@ "version": "1.0.0-*", "type": "build" }, - "Microsoft.AspNetCore.Server.Kestrel": "1.0.0-*" + "Microsoft.AspNetCore.Server.Kestrel": "1.0.0-*", + "Microsoft.NETCore.Platforms": "1.0.1-*" }, "compilationOptions": { "emitEntryPoint": true diff --git a/samples/SampleApp/project.json b/samples/SampleApp/project.json index 86356d30af..2e217c4e86 100644 --- a/samples/SampleApp/project.json +++ b/samples/SampleApp/project.json @@ -11,7 +11,8 @@ }, "Microsoft.AspNetCore.Server.Kestrel": "1.0.0-*", "Microsoft.AspNetCore.Server.Kestrel.Https": "1.0.0-*", - "Microsoft.Extensions.Logging.Console": "1.0.0-*" + "Microsoft.Extensions.Logging.Console": "1.0.0-*", + "Microsoft.NETCore.Platforms": "1.0.1-*" }, "compilationOptions": { "emitEntryPoint": true From c828fafe1b39279d590ad1a18b62844bae76d77b Mon Sep 17 00:00:00 2001 From: Doug Bunting Date: Sun, 27 Mar 2016 12:08:07 -0700 Subject: [PATCH 0672/1662] React to HttpAbstractions namespace changes - aspnet/HttpAbstractions#549 and aspnet/HttpAbstractions#592 - clean up `using`s --- .../HttpsConnectionFilter.cs | 2 -- .../DummyApplication.cs | 1 - 2 files changed, 3 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Https/HttpsConnectionFilter.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Https/HttpsConnectionFilter.cs index 4bde587233..0992d229e5 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Https/HttpsConnectionFilter.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Https/HttpsConnectionFilter.cs @@ -3,11 +3,9 @@ using System; using System.Net.Security; -using System.Security.Authentication; using System.Security.Cryptography.X509Certificates; using System.Threading.Tasks; using Microsoft.AspNetCore.Http.Features; -using Microsoft.AspNetCore.Http.Features.Internal; using Microsoft.AspNetCore.Server.Kestrel.Filter; namespace Microsoft.AspNetCore.Server.Kestrel.Https diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/DummyApplication.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/DummyApplication.cs index c1ef6f86b7..842c1156dd 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/DummyApplication.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/DummyApplication.cs @@ -5,7 +5,6 @@ using System; using System.Threading.Tasks; using Microsoft.AspNetCore.Hosting.Server; using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Http.Internal; using Microsoft.AspNetCore.Http.Features; namespace Microsoft.AspNetCore.Server.KestrelTests From c567e4814a162b0434084436b15dfb5d53920e7a Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Wed, 30 Mar 2016 12:01:53 -0700 Subject: [PATCH 0673/1662] Clean up Travis builds - No longer build libuv in .travis.yml - The Ubuntu libuv build should now be taken from http://github.com/aspnet/libuv-build - Remove unneeded packages from .travis.yml - Stop skipping mono tests --- .travis.yml | 15 --------------- samples/LargeResponseApp/project.json | 4 ++++ samples/SampleApp/project.json | 4 ++++ .../project.json | 4 ++++ .../project.json | 4 ++++ 5 files changed, 16 insertions(+), 15 deletions(-) diff --git a/.travis.yml b/.travis.yml index 6108295a27..16c27f88b9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,22 +4,7 @@ dist: trusty addons: apt: packages: - - gettext - - libcurl4-openssl-dev - - libicu-dev - - libssl-dev - libunwind8 - - zlib1g -env: - - KOREBUILD_TEST_SKIPMONO=true -install: - - curl -sSL https://github.com/libuv/libuv/archive/v1.4.2.tar.gz | tar zxfv - -C /tmp && cd /tmp/libuv-1.4.2/ - - sh autogen.sh - - ./configure --prefix=$HOME/libuvinstall - - make - - make install - - export LD_LIBRARY_PATH="$HOME/libuvinstall/lib" - - cd $OLDPWD mono: - 4.0.5 os: diff --git a/samples/LargeResponseApp/project.json b/samples/LargeResponseApp/project.json index d25c094244..e5d75bf37b 100644 --- a/samples/LargeResponseApp/project.json +++ b/samples/LargeResponseApp/project.json @@ -5,6 +5,10 @@ "version": "1.0.0-*", "type": "build" }, + "Microsoft.AspNetCore.Internal.libuv-Linux": { + "version": "1.0.0-*", + "type": "build" + }, "Microsoft.AspNetCore.Internal.libuv-Windows": { "version": "1.0.0-*", "type": "build" diff --git a/samples/SampleApp/project.json b/samples/SampleApp/project.json index 2e217c4e86..546670be0b 100644 --- a/samples/SampleApp/project.json +++ b/samples/SampleApp/project.json @@ -5,6 +5,10 @@ "version": "1.0.0-*", "type": "build" }, + "Microsoft.AspNetCore.Internal.libuv-Linux": { + "version": "1.0.0-*", + "type": "build" + }, "Microsoft.AspNetCore.Internal.libuv-Windows": { "version": "1.0.0-*", "type": "build" diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json index 6c48e9a588..deaf0e6415 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json @@ -10,6 +10,10 @@ "version": "1.0.0-*", "type": "build" }, + "Microsoft.AspNetCore.Internal.libuv-Linux": { + "version": "1.0.0-*", + "type": "build" + }, "Microsoft.AspNetCore.Internal.libuv-Windows": { "version": "1.0.0-*", "type": "build" diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/project.json b/test/Microsoft.AspNetCore.Server.KestrelTests/project.json index 6ccf5d02ee..9d1bad57b0 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/project.json +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/project.json @@ -10,6 +10,10 @@ "version": "1.0.0-*", "type": "build" }, + "Microsoft.AspNetCore.Internal.libuv-Linux": { + "version": "1.0.0-*", + "type": "build" + }, "Microsoft.AspNetCore.Internal.libuv-Windows": { "version": "1.0.0-*", "type": "build" From 228c34b500bca4b91a2861ef7e6270e784425046 Mon Sep 17 00:00:00 2001 From: Mike Harder Date: Thu, 31 Mar 2016 15:34:52 -0700 Subject: [PATCH 0674/1662] Remove duplicate calls to FrameRequestHeaders and FrameResponseHeaders ctors (#695) --- .../Infrastructure/HttpComponentFactory.cs | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/HttpComponentFactory.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/HttpComponentFactory.cs index 5b346d73fd..b0be4ad410 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/HttpComponentFactory.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/HttpComponentFactory.cs @@ -76,12 +76,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure public readonly FrameRequestHeaders RequestHeaders = new FrameRequestHeaders(); public readonly FrameResponseHeaders ResponseHeaders = new FrameResponseHeaders(); - public Headers() - { - RequestHeaders = new FrameRequestHeaders(); - ResponseHeaders = new FrameResponseHeaders(); - } - public void Initialize(DateHeaderValueManager dateValueManager) { ResponseHeaders.SetRawDate( From 63ac7210cee5384c0a651e5922a9de9a2ab447ec Mon Sep 17 00:00:00 2001 From: Pranav K Date: Thu, 31 Mar 2016 22:23:19 -0700 Subject: [PATCH 0675/1662] Don't run restore in #initialize --- makefile.shade | 3 --- 1 file changed, 3 deletions(-) diff --git a/makefile.shade b/makefile.shade index 730b193323..210744dcab 100644 --- a/makefile.shade +++ b/makefile.shade @@ -8,8 +8,5 @@ k-standard-goals custom-goals #initialize if='Directory.Exists("src")' - exec program='dotnet' commandline='restore ../../tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode' workingdir='${kestrelSrcDir}' exec program='dotnet' commandline='run -p ../../tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode Http/FrameHeaders.Generated.cs Http/Frame.Generated.cs' workingdir='${kestrelSrcDir}' - exec program='dotnet' commandline='restore' workingdir='${kestrelSrcDir}' - exec program='dotnet' commandline='restore ../../tools/Microsoft.AspNetCore.Server.Kestrel.LibuvCopier' workingdir='${kestrelSrcDir}' exec program='dotnet' commandline='run -p ../../tools/Microsoft.AspNetCore.Server.Kestrel.LibuvCopier' workingdir='${kestrelSrcDir}' From 109c56713ac8e56e7f405d4a6e961be5f7b68287 Mon Sep 17 00:00:00 2001 From: BrennanConroy Date: Fri, 1 Apr 2016 11:53:47 -0700 Subject: [PATCH 0676/1662] React to logging changes --- .../Infrastructure/KestrelTrace.cs | 4 ++-- .../TestHelpers/TestApplicationErrorLogger.cs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/KestrelTrace.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/KestrelTrace.cs index 6dae29ed37..1869e3446e 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/KestrelTrace.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/KestrelTrace.cs @@ -154,9 +154,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel return _logger.IsEnabled(logLevel); } - public virtual IDisposable BeginScopeImpl(object state) + public virtual IDisposable BeginScope(TState state) { - return _logger.BeginScopeImpl(state); + return _logger.BeginScope(state); } } } \ No newline at end of file diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/TestApplicationErrorLogger.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/TestApplicationErrorLogger.cs index eb48a70890..de8d462ed9 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/TestApplicationErrorLogger.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/TestApplicationErrorLogger.cs @@ -16,7 +16,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests public int ApplicationErrorsLogged { get; set; } - public IDisposable BeginScopeImpl(object state) + public IDisposable BeginScope(TState state) { return new Disposable(() => { }); } From 21de2aee1300c454b9393de1cff220e31203a571 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Mon, 4 Apr 2016 20:04:17 -0700 Subject: [PATCH 0677/1662] Remove unused dependency on TraceSource - TraceSource is RID specific (see https://github.com/dotnet/corefx/issues/7480) and it causes 2 dlls to end up in the output of every ASP.NET application. We don't even use it anymore. --- src/Microsoft.AspNetCore.Server.Kestrel/project.json | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/project.json b/src/Microsoft.AspNetCore.Server.Kestrel/project.json index dd0812020e..cbf33f93e1 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/project.json +++ b/src/Microsoft.AspNetCore.Server.Kestrel/project.json @@ -36,8 +36,6 @@ "dependencies": { "System.Collections": "4.0.11-*", "System.Diagnostics.Debug": "4.0.11-*", - "System.Diagnostics.TraceSource": "4.0.0-*", - "System.Diagnostics.Tracing": "4.1.0-*", "System.Globalization": "4.0.11-*", "System.IO": "4.1.0-*", "System.Linq": "4.1.0-*", From 50f187aa3e1c877370dac1c415e96aa00115b748 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Fri, 1 Apr 2016 12:38:26 -0700 Subject: [PATCH 0678/1662] Ensure entire request body is consumed before handling fin This completes the fix for #704 --- .../Http/MessageBody.cs | 77 +++++++++++++------ .../Http/SocketInputExtensions.cs | 8 +- 2 files changed, 61 insertions(+), 24 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/MessageBody.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/MessageBody.cs index d4072572f8..3a151fc560 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/MessageBody.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/MessageBody.cs @@ -249,29 +249,46 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { while (_mode == Mode.Prefix) { + var fin = input.RemoteIntakeFin; + ParseChunkedPrefix(input); + if (_mode != Mode.Prefix) { break; } + else if (fin) + { + ThrowChunkedRequestIncomplete(); + } - await GetDataAsync(input); + await input; } while (_mode == Mode.Extension) { + var fin = input.RemoteIntakeFin; + ParseExtension(input); + if (_mode != Mode.Extension) { break; } + else if (fin) + { + ThrowChunkedRequestIncomplete(); + } - await GetDataAsync(input); + await input; } while (_mode == Mode.Data) { + var fin = input.RemoteIntakeFin; + int actual = ReadChunkedData(input, buffer.Array, buffer.Offset, buffer.Count); + if (actual != 0) { return actual; @@ -280,39 +297,69 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { break; } + else if (fin) + { + ThrowChunkedRequestIncomplete(); + } - await GetDataAsync(input); + await input; } while (_mode == Mode.Suffix) { + var fin = input.RemoteIntakeFin; + ParseChunkedSuffix(input); + if (_mode != Mode.Suffix) { break; } + else if (fin) + { + ThrowChunkedRequestIncomplete(); + } - await GetDataAsync(input); + await input; } } // Chunks finished, parse trailers while (_mode == Mode.Trailer) { + var fin = input.RemoteIntakeFin; + ParseChunkedTrailer(input); + if (_mode != Mode.Trailer) { break; } + else if (fin) + { + ThrowChunkedRequestIncomplete(); + } - await GetDataAsync(input); + await input; } if (_mode == Mode.TrailerHeaders) { while (!_context.TakeMessageHeaders(input, _requestHeaders)) { - await GetDataAsync(input); + if (input.RemoteIntakeFin) + { + if (_context.TakeMessageHeaders(input, _requestHeaders)) + { + break; + } + else + { + ThrowChunkedRequestIncomplete(); + } + } + + await input; } _mode = Mode.Complete; @@ -444,10 +491,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { _mode = Mode.Suffix; } - else if (actual == 0) - { - ThrowIfRequestIncomplete(input); - } return actual; } @@ -532,19 +575,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } - private SocketInput GetDataAsync(SocketInput input) + private void ThrowChunkedRequestIncomplete() { - ThrowIfRequestIncomplete(input); - - return input; - } - - private void ThrowIfRequestIncomplete(SocketInput input) - { - if (input.RemoteIntakeFin) - { - ThrowBadRequestException("Chunked request incomplete"); - } + ThrowBadRequestException("Chunked request incomplete"); } private enum Mode diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketInputExtensions.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketInputExtensions.cs index 4b3beab538..9b647c4c91 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketInputExtensions.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketInputExtensions.cs @@ -12,6 +12,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { while (input.IsCompleted) { + var fin = input.RemoteIntakeFin; + var begin = input.ConsumingStart(); int actual; var end = begin.CopyTo(buffer, offset, count, out actual); @@ -21,7 +23,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { return actual; } - if (input.RemoteIntakeFin) + else if (fin) { return 0; } @@ -36,6 +38,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { await input; + var fin = input.RemoteIntakeFin; + var begin = input.ConsumingStart(); int actual; var end = begin.CopyTo(buffer, offset, count, out actual); @@ -45,7 +49,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { return actual; } - if (input.RemoteIntakeFin) + else if (fin) { return 0; } From 151f87e9275b3a36f410cf0a60b506203efbcaf9 Mon Sep 17 00:00:00 2001 From: Pranav K Date: Wed, 6 Apr 2016 09:47:00 -0700 Subject: [PATCH 0679/1662] Updating to release. --- NuGet.config | 4 ++-- build.ps1 | 2 +- build.sh | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/NuGet.config b/NuGet.config index 03704957e8..9db87a421e 100644 --- a/NuGet.config +++ b/NuGet.config @@ -1,7 +1,7 @@ - + - + \ No newline at end of file diff --git a/build.ps1 b/build.ps1 index 8f2f99691a..cf8bff13bb 100644 --- a/build.ps1 +++ b/build.ps1 @@ -33,7 +33,7 @@ cd $PSScriptRoot $repoFolder = $PSScriptRoot $env:REPO_FOLDER = $repoFolder -$koreBuildZip="https://github.com/aspnet/KoreBuild/archive/dev.zip" +$koreBuildZip="https://github.com/aspnet/KoreBuild/archive/release.zip" if ($env:KOREBUILD_ZIP) { $koreBuildZip=$env:KOREBUILD_ZIP diff --git a/build.sh b/build.sh index f4208100eb..f88fe4052e 100755 --- a/build.sh +++ b/build.sh @@ -2,7 +2,7 @@ repoFolder="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" cd $repoFolder -koreBuildZip="https://github.com/aspnet/KoreBuild/archive/dev.zip" +koreBuildZip="https://github.com/aspnet/KoreBuild/archive/release.zip" if [ ! -z $KOREBUILD_ZIP ]; then koreBuildZip=$KOREBUILD_ZIP fi From 056b4ac41de946caef82ad22caf59aa39db1c3d9 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Mon, 4 Apr 2016 17:40:00 -0700 Subject: [PATCH 0680/1662] Never call Thread.Abort - This API isn't available on .NET Core so we should rely entirely on our other methods of terminating the libuv threads. --- .../Infrastructure/KestrelThread.cs | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/KestrelThread.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/KestrelThread.cs index 2b6d2ab0a5..20183d92da 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/KestrelThread.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/KestrelThread.cs @@ -104,9 +104,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel Post(t => t.OnStopImmediate()); if (!_thread.Join(stepTimeout)) { -#if NET451 - _thread.Abort(); -#endif + _log.LogError(0, null, "KestrelThread.Stop failed to terminate libuv thread."); } } } @@ -116,9 +114,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel // Until we rework this logic, ODEs are bound to happen sometimes. if (!_thread.Join(stepTimeout)) { -#if NET451 - _thread.Abort(); -#endif + _log.LogError(0, null, "KestrelThread.Stop failed to terminate libuv thread."); } } } From 29a8d5b7c539ff07b0fa9abd0f4fe9090605f865 Mon Sep 17 00:00:00 2001 From: Pranav K Date: Thu, 7 Apr 2016 15:40:33 -0700 Subject: [PATCH 0681/1662] Removing imports from src projects --- .../project.json | 1 - src/Microsoft.AspNetCore.Server.Kestrel/project.json | 9 ++++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Https/project.json b/src/Microsoft.AspNetCore.Server.Kestrel.Https/project.json index ab7dfc0600..57199e79fd 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Https/project.json +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Https/project.json @@ -22,7 +22,6 @@ "System.Net.Security": "4.0.0-*" }, "imports": [ - "dotnet5.4", "portable-net45+win8" ] } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/project.json b/src/Microsoft.AspNetCore.Server.Kestrel/project.json index cbf33f93e1..84cc1e688a 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/project.json +++ b/src/Microsoft.AspNetCore.Server.Kestrel/project.json @@ -28,8 +28,12 @@ "frameworks": { "net451": { "frameworkAssemblies": { - "System.Runtime": { "type": "build" }, - "System.Threading.Tasks": { "type": "build" } + "System.Runtime": { + "type": "build" + }, + "System.Threading.Tasks": { + "type": "build" + } } }, "netstandard1.3": { @@ -50,7 +54,6 @@ "System.Threading.Timer": "4.0.1-*" }, "imports": [ - "dotnet5.4", "portable-net45+win8" ] } From 7d4fcfeb2310caab798591c6b9ffcb4d3a4778b2 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Tue, 5 Apr 2016 16:40:39 -0700 Subject: [PATCH 0682/1662] Depend on separate libuv package --- content/thirdpartynotices.txt | 32 --------- global.json | 5 +- makefile.shade | 1 - samples/LargeResponseApp/project.json | 12 ---- samples/SampleApp/project.json | 12 ---- .../project.json | 24 +------ .../project.json | 14 +--- .../project.json | 14 +--- ...spNetCore.Server.Kestrel.LibuvCopier.xproj | 17 ----- .../Program.cs | 72 ------------------- .../project.json | 22 ------ 11 files changed, 5 insertions(+), 220 deletions(-) delete mode 100644 content/thirdpartynotices.txt delete mode 100644 tools/Microsoft.AspNetCore.Server.Kestrel.LibuvCopier/Microsoft.AspNetCore.Server.Kestrel.LibuvCopier.xproj delete mode 100644 tools/Microsoft.AspNetCore.Server.Kestrel.LibuvCopier/Program.cs delete mode 100644 tools/Microsoft.AspNetCore.Server.Kestrel.LibuvCopier/project.json diff --git a/content/thirdpartynotices.txt b/content/thirdpartynotices.txt deleted file mode 100644 index 155e2b5486..0000000000 --- a/content/thirdpartynotices.txt +++ /dev/null @@ -1,32 +0,0 @@ -This file is based on or incorporates material from the projects listed below -(Third Party IP). The original copyright notice and the license under which -Microsoft received such Third Party IP, are set forth below. Such licenses and -notices are provided for informational purposes only. Microsoft licenses the -Third Party IP to you under the licensing terms for the Microsoft product. -Microsoft reserves all other rights not expressly granted under this agreement, -whether by implication, estoppel or otherwise. - -libuv v. 1.7.3 - -Copyright Joyent, Inc. and other Node contributors. All rights reserved. - Provided for Informational Purposes Only - -MIT License - -Permission is hereby granted, free of charge, to any person obtaining a copy of -this software and associated documentation files (the Software), to deal in the -Software without restriction, including without limitation the rights to use, -copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the -Software, and to permit persons to whom the Software is furnished to do so, -subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/global.json b/global.json index aa789b9c9c..983ba0401e 100644 --- a/global.json +++ b/global.json @@ -1,6 +1,3 @@ { - "projects": [ - "src", - "tools" - ] + "projects": ["src"] } diff --git a/makefile.shade b/makefile.shade index 210744dcab..c47d059fb9 100644 --- a/makefile.shade +++ b/makefile.shade @@ -9,4 +9,3 @@ custom-goals #initialize if='Directory.Exists("src")' exec program='dotnet' commandline='run -p ../../tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode Http/FrameHeaders.Generated.cs Http/Frame.Generated.cs' workingdir='${kestrelSrcDir}' - exec program='dotnet' commandline='run -p ../../tools/Microsoft.AspNetCore.Server.Kestrel.LibuvCopier' workingdir='${kestrelSrcDir}' diff --git a/samples/LargeResponseApp/project.json b/samples/LargeResponseApp/project.json index e5d75bf37b..f28fba77ce 100644 --- a/samples/LargeResponseApp/project.json +++ b/samples/LargeResponseApp/project.json @@ -1,18 +1,6 @@ { "version": "1.0.0-*", "dependencies": { - "Microsoft.AspNetCore.Internal.libuv-Darwin": { - "version": "1.0.0-*", - "type": "build" - }, - "Microsoft.AspNetCore.Internal.libuv-Linux": { - "version": "1.0.0-*", - "type": "build" - }, - "Microsoft.AspNetCore.Internal.libuv-Windows": { - "version": "1.0.0-*", - "type": "build" - }, "Microsoft.AspNetCore.Server.Kestrel": "1.0.0-*", "Microsoft.NETCore.Platforms": "1.0.1-*" }, diff --git a/samples/SampleApp/project.json b/samples/SampleApp/project.json index 546670be0b..554a04841f 100644 --- a/samples/SampleApp/project.json +++ b/samples/SampleApp/project.json @@ -1,18 +1,6 @@ { "version": "1.0.0-*", "dependencies": { - "Microsoft.AspNetCore.Internal.libuv-Darwin": { - "version": "1.0.0-*", - "type": "build" - }, - "Microsoft.AspNetCore.Internal.libuv-Linux": { - "version": "1.0.0-*", - "type": "build" - }, - "Microsoft.AspNetCore.Internal.libuv-Windows": { - "version": "1.0.0-*", - "type": "build" - }, "Microsoft.AspNetCore.Server.Kestrel": "1.0.0-*", "Microsoft.AspNetCore.Server.Kestrel.Https": "1.0.0-*", "Microsoft.Extensions.Logging.Console": "1.0.0-*", diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/project.json b/src/Microsoft.AspNetCore.Server.Kestrel/project.json index 84cc1e688a..54d7529341 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/project.json +++ b/src/Microsoft.AspNetCore.Server.Kestrel/project.json @@ -9,21 +9,10 @@ "System.Buffers": "4.0.0-*", "System.Numerics.Vectors": "4.1.1-*", "System.Threading.Tasks.Extensions": "4.0.0-*", + "Libuv": "1.9.0-*", "Microsoft.AspNetCore.Hosting": "1.0.0-*", "Microsoft.Extensions.Logging.Abstractions": "1.0.0-*", - "Microsoft.Extensions.PlatformAbstractions": "1.0.0-*", - "Microsoft.AspNetCore.Internal.libuv-Darwin": { - "version": "1.0.0-*", - "type": "build" - }, - "Microsoft.AspNetCore.Internal.libuv-Linux": { - "version": "1.0.0-*", - "type": "build" - }, - "Microsoft.AspNetCore.Internal.libuv-Windows": { - "version": "1.0.0-*", - "type": "build" - } + "Microsoft.Extensions.PlatformAbstractions": "1.0.0-*" }, "frameworks": { "net451": { @@ -65,14 +54,5 @@ "CS1591" ], "xmlDoc": true - }, - "packInclude": { - "/": "../../content/thirdpartynotices.txt", - "runtimes/win7-x64/native/": "runtimes/win7-x64/native/*", - "runtimes/win7-x86/native/": "runtimes/win7-x86/native/*", - "runtimes/win7-arm/native/": "runtimes/win7-arm/native/*", - "runtimes/osx/native/": "runtimes/osx/native/*", - "runtimes/rhel-x64/native/": "runtimes/rhel-x64/native/*", - "runtimes/debian-x64/native/": "runtimes/debian-x64/native/*" } } \ No newline at end of file diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json index deaf0e6415..326bc458a6 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json @@ -5,19 +5,7 @@ "Microsoft.AspNetCore.Server.Kestrel": "1.0.0-*", "Microsoft.AspNetCore.Testing": "1.0.0-*", "Microsoft.NETCore.Platforms": "1.0.1-*", - "xunit": "2.1.0", - "Microsoft.AspNetCore.Internal.libuv-Darwin": { - "version": "1.0.0-*", - "type": "build" - }, - "Microsoft.AspNetCore.Internal.libuv-Linux": { - "version": "1.0.0-*", - "type": "build" - }, - "Microsoft.AspNetCore.Internal.libuv-Windows": { - "version": "1.0.0-*", - "type": "build" - } + "xunit": "2.1.0" }, "frameworks": { "netstandardapp1.5": { diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/project.json b/test/Microsoft.AspNetCore.Server.KestrelTests/project.json index 9d1bad57b0..8123f3e0a2 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/project.json +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/project.json @@ -5,19 +5,7 @@ "Microsoft.AspNetCore.Server.Kestrel.Https": "1.0.0-*", "Microsoft.AspNetCore.Testing": "1.0.0-*", "Microsoft.NETCore.Platforms": "1.0.1-*", - "xunit": "2.1.0", - "Microsoft.AspNetCore.Internal.libuv-Darwin": { - "version": "1.0.0-*", - "type": "build" - }, - "Microsoft.AspNetCore.Internal.libuv-Linux": { - "version": "1.0.0-*", - "type": "build" - }, - "Microsoft.AspNetCore.Internal.libuv-Windows": { - "version": "1.0.0-*", - "type": "build" - } + "xunit": "2.1.0" }, "frameworks": { "netstandardapp1.5": { diff --git a/tools/Microsoft.AspNetCore.Server.Kestrel.LibuvCopier/Microsoft.AspNetCore.Server.Kestrel.LibuvCopier.xproj b/tools/Microsoft.AspNetCore.Server.Kestrel.LibuvCopier/Microsoft.AspNetCore.Server.Kestrel.LibuvCopier.xproj deleted file mode 100644 index c26e1d6b79..0000000000 --- a/tools/Microsoft.AspNetCore.Server.Kestrel.LibuvCopier/Microsoft.AspNetCore.Server.Kestrel.LibuvCopier.xproj +++ /dev/null @@ -1,17 +0,0 @@ - - - - 14.0 - $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) - - - - 8cba6fe3-3cc9-4420-8aa3-123e983734c2 - ..\..\artifacts\obj\$(MSBuildProjectName) - ..\..\artifacts\bin\ - - - 2.0 - - - \ No newline at end of file diff --git a/tools/Microsoft.AspNetCore.Server.Kestrel.LibuvCopier/Program.cs b/tools/Microsoft.AspNetCore.Server.Kestrel.LibuvCopier/Program.cs deleted file mode 100644 index b7a95bb822..0000000000 --- a/tools/Microsoft.AspNetCore.Server.Kestrel.LibuvCopier/Program.cs +++ /dev/null @@ -1,72 +0,0 @@ -using System; -using System.IO; -using System.Linq; -using Microsoft.Extensions.PlatformAbstractions; -using Newtonsoft.Json.Linq; - -namespace Microsoft.AspNetCore.Server.Kestrel.LibuvCopier -{ - public class Program - { - public static void Main(string[] args) - { - try - { - var packagesFolder = Environment.GetEnvironmentVariable("NUGET_PACKAGES"); - - if (string.IsNullOrEmpty(packagesFolder)) - { - packagesFolder = Path.Combine(GetHome(), ".nuget", "packages"); - } - - packagesFolder = Environment.ExpandEnvironmentVariables(packagesFolder); - - var lockJson = JObject.Parse(File.ReadAllText("project.lock.json")); - - foreach (var libuvLib in lockJson["libraries"].OfType().Where( - p => p.Name.StartsWith("Microsoft.AspNetCore.Internal.libuv", StringComparison.Ordinal))) - { - foreach (var filePath in libuvLib.Value["files"].Select(v => v.Value())) - { - if (filePath.ToString().StartsWith("runtimes/", StringComparison.Ordinal)) - { - Directory.CreateDirectory(Path.GetDirectoryName(filePath)); - File.Copy(Path.Combine(packagesFolder, libuvLib.Name, filePath), filePath, overwrite: true); - } - } - } - } - catch (Exception ex) - { - Console.WriteLine(ex); - throw; - } - } - - // Copied from DNX's DnuEnvironment.cs - private static string GetHome() - { -#if DNX451 - return Environment.GetFolderPath(Environment.SpecialFolder.UserProfile); -#else - var runtimeEnv = PlatformServices.Default.Runtime; - if (runtimeEnv.OperatingSystem == "Windows") - { - return Environment.GetEnvironmentVariable("USERPROFILE") ?? - Environment.GetEnvironmentVariable("HOMEDRIVE") + Environment.GetEnvironmentVariable("HOMEPATH"); - } - else - { - var home = Environment.GetEnvironmentVariable("HOME"); - - if (string.IsNullOrEmpty(home)) - { - throw new Exception("Home directory not found. The HOME environment variable is not set."); - } - - return home; - } -#endif - } - } -} diff --git a/tools/Microsoft.AspNetCore.Server.Kestrel.LibuvCopier/project.json b/tools/Microsoft.AspNetCore.Server.Kestrel.LibuvCopier/project.json deleted file mode 100644 index 1a593a4610..0000000000 --- a/tools/Microsoft.AspNetCore.Server.Kestrel.LibuvCopier/project.json +++ /dev/null @@ -1,22 +0,0 @@ -{ - "version": "1.0.0-*", - "compilationOptions": { - "emitEntryPoint": true - }, - "dependencies": { - "Microsoft.Extensions.PlatformAbstractions": "1.0.0-*", - "Newtonsoft.Json": "8.0.3" - }, - "frameworks": { - "netstandardapp1.5": { - "dependencies": { - "NETStandard.Library": "1.5.0-*", - "System.Dynamic.Runtime": "4.0.11-*" - }, - "imports": [ - "dnxcore50" - ] - }, - "net451": {} - } -} \ No newline at end of file From 7b6384635796d99bdb74ba24d80dbdc50731fd5e Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Tue, 12 Apr 2016 14:18:41 -0700 Subject: [PATCH 0683/1662] Prevent crash when aborting connection before Frame is created (#738). --- .../Http/Connection.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Connection.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Connection.cs index a5ede79183..fbd690eea7 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Connection.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Connection.cs @@ -154,9 +154,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { // Frame.Abort calls user code while this method is always // called from a libuv thread. - System.Threading.ThreadPool.QueueUserWorkItem(state => + ThreadPool.Run(() => { - var connection = (Connection)state; + var connection = this; lock (connection._stateLock) { @@ -166,10 +166,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } else { - connection._frame.Abort(); + connection._frame?.Abort(); } } - }, this); + }); } // Called on Libuv thread From 795fc36cde3a3ec23f57c867862ed48412783f70 Mon Sep 17 00:00:00 2001 From: Eilon Lipton Date: Tue, 12 Apr 2016 18:47:35 -0700 Subject: [PATCH 0684/1662] Fix package metadata --- .../project.json | 8 ++++++-- src/Microsoft.AspNetCore.Server.Kestrel/project.json | 6 +++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Https/project.json b/src/Microsoft.AspNetCore.Server.Kestrel.Https/project.json index 57199e79fd..521d8b09c4 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Https/project.json +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Https/project.json @@ -1,5 +1,10 @@ { "version": "1.0.0-*", + "description": "HTTPS support for the ASP.NET Core Kestrel cross-platform web server.", + "tags": [ + "aspnetcore", + "kestrel" + ], "compilationOptions": { "keyFile": "../../tools/Key.snk", "nowarn": [ @@ -7,7 +12,6 @@ ], "xmlDoc": true }, - "description": "Adds HTTPS support to Kestrel", "repository": { "type": "git", "url": "git://github.com/aspnet/kestrelhttpserver" @@ -16,7 +20,7 @@ "Microsoft.AspNetCore.Server.Kestrel": "1.0.0-*" }, "frameworks": { - "net451": {}, + "net451": { }, "netstandard1.3": { "dependencies": { "System.Net.Security": "4.0.0-*" diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/project.json b/src/Microsoft.AspNetCore.Server.Kestrel/project.json index 54d7529341..3b56f01b17 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/project.json +++ b/src/Microsoft.AspNetCore.Server.Kestrel/project.json @@ -1,6 +1,10 @@ { "version": "1.0.0-*", - "description": "ASP.NET 5 cross platform web server.", + "description": "ASP.NET Core Kestrel cross-platform web server.", + "tags": [ + "aspnetcore", + "kestrel" + ], "repository": { "type": "git", "url": "git://github.com/aspnet/kestrelhttpserver" From 5354005a1a86886fbd71eef2c2745979db15bf5c Mon Sep 17 00:00:00 2001 From: David Fowler Date: Tue, 12 Apr 2016 23:47:36 -0700 Subject: [PATCH 0685/1662] Remove support for DNX on osx on mono - Remove mono osx specific PInvokes - Use PlatformAbstractions to detect darwin instead of direct pinvoke #742 --- .../Networking/Libuv.cs | 245 +++--------------- .../Networking/PlatformApis.cs | 30 +-- 2 files changed, 40 insertions(+), 235 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Networking/Libuv.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Networking/Libuv.cs index ad5beb9d4f..1bbb502a7f 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Networking/Libuv.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Networking/Libuv.cs @@ -12,99 +12,46 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Networking { IsWindows = PlatformApis.IsWindows; - var isDnxDarwinMono = -#if NET451 - PlatformApis.IsDarwin && PlatformApis.IsMono && AppDomain.CurrentDomain.GetData("DNX_SERVICEPROVIDER") != null; -#else - false; -#endif - - if (isDnxDarwinMono) + _uv_loop_init = NativeMethods.uv_loop_init; + _uv_loop_close = NativeMethods.uv_loop_close; + _uv_run = NativeMethods.uv_run; + _uv_stop = NativeMethods.uv_stop; + _uv_ref = NativeMethods.uv_ref; + _uv_unref = NativeMethods.uv_unref; + _uv_fileno = NativeMethods.uv_fileno; + _uv_close = NativeMethods.uv_close; + _uv_async_init = NativeMethods.uv_async_init; + _uv_async_send = NativeMethods.uv_async_send; + _uv_unsafe_async_send = NativeMethods.uv_unsafe_async_send; + _uv_tcp_init = NativeMethods.uv_tcp_init; + _uv_tcp_bind = NativeMethods.uv_tcp_bind; + _uv_tcp_open = NativeMethods.uv_tcp_open; + _uv_tcp_nodelay = NativeMethods.uv_tcp_nodelay; + _uv_pipe_init = NativeMethods.uv_pipe_init; + _uv_pipe_bind = NativeMethods.uv_pipe_bind; + _uv_listen = NativeMethods.uv_listen; + _uv_accept = NativeMethods.uv_accept; + _uv_pipe_connect = NativeMethods.uv_pipe_connect; + _uv_pipe_pending_count = NativeMethods.uv_pipe_pending_count; + _uv_read_start = NativeMethods.uv_read_start; + _uv_read_stop = NativeMethods.uv_read_stop; + _uv_try_write = NativeMethods.uv_try_write; + unsafe { - _uv_loop_init = NativeDarwinMonoMethods.uv_loop_init; - _uv_loop_close = NativeDarwinMonoMethods.uv_loop_close; - _uv_run = NativeDarwinMonoMethods.uv_run; - _uv_stop = NativeDarwinMonoMethods.uv_stop; - _uv_ref = NativeDarwinMonoMethods.uv_ref; - _uv_unref = NativeDarwinMonoMethods.uv_unref; - _uv_fileno = NativeDarwinMonoMethods.uv_fileno; - _uv_close = NativeDarwinMonoMethods.uv_close; - _uv_async_init = NativeDarwinMonoMethods.uv_async_init; - _uv_async_send = NativeDarwinMonoMethods.uv_async_send; - _uv_unsafe_async_send = NativeDarwinMonoMethods.uv_unsafe_async_send; - _uv_tcp_init = NativeDarwinMonoMethods.uv_tcp_init; - _uv_tcp_bind = NativeDarwinMonoMethods.uv_tcp_bind; - _uv_tcp_open = NativeDarwinMonoMethods.uv_tcp_open; - _uv_tcp_nodelay = NativeDarwinMonoMethods.uv_tcp_nodelay; - _uv_pipe_init = NativeDarwinMonoMethods.uv_pipe_init; - _uv_pipe_bind = NativeDarwinMonoMethods.uv_pipe_bind; - _uv_listen = NativeDarwinMonoMethods.uv_listen; - _uv_accept = NativeDarwinMonoMethods.uv_accept; - _uv_pipe_connect = NativeDarwinMonoMethods.uv_pipe_connect; - _uv_pipe_pending_count = NativeDarwinMonoMethods.uv_pipe_pending_count; - _uv_read_start = NativeDarwinMonoMethods.uv_read_start; - _uv_read_stop = NativeDarwinMonoMethods.uv_read_stop; - _uv_try_write = NativeDarwinMonoMethods.uv_try_write; - unsafe - { - _uv_write = NativeDarwinMonoMethods.uv_write; - _uv_write2 = NativeDarwinMonoMethods.uv_write2; - } - _uv_shutdown = NativeDarwinMonoMethods.uv_shutdown; - _uv_err_name = NativeDarwinMonoMethods.uv_err_name; - _uv_strerror = NativeDarwinMonoMethods.uv_strerror; - _uv_loop_size = NativeDarwinMonoMethods.uv_loop_size; - _uv_handle_size = NativeDarwinMonoMethods.uv_handle_size; - _uv_req_size = NativeDarwinMonoMethods.uv_req_size; - _uv_ip4_addr = NativeDarwinMonoMethods.uv_ip4_addr; - _uv_ip6_addr = NativeDarwinMonoMethods.uv_ip6_addr; - _uv_tcp_getpeername = NativeDarwinMonoMethods.uv_tcp_getpeername; - _uv_tcp_getsockname = NativeDarwinMonoMethods.uv_tcp_getsockname; - _uv_walk = NativeDarwinMonoMethods.uv_walk; - } - else - { - _uv_loop_init = NativeMethods.uv_loop_init; - _uv_loop_close = NativeMethods.uv_loop_close; - _uv_run = NativeMethods.uv_run; - _uv_stop = NativeMethods.uv_stop; - _uv_ref = NativeMethods.uv_ref; - _uv_unref = NativeMethods.uv_unref; - _uv_fileno = NativeMethods.uv_fileno; - _uv_close = NativeMethods.uv_close; - _uv_async_init = NativeMethods.uv_async_init; - _uv_async_send = NativeMethods.uv_async_send; - _uv_unsafe_async_send = NativeMethods.uv_unsafe_async_send; - _uv_tcp_init = NativeMethods.uv_tcp_init; - _uv_tcp_bind = NativeMethods.uv_tcp_bind; - _uv_tcp_open = NativeMethods.uv_tcp_open; - _uv_tcp_nodelay = NativeMethods.uv_tcp_nodelay; - _uv_pipe_init = NativeMethods.uv_pipe_init; - _uv_pipe_bind = NativeMethods.uv_pipe_bind; - _uv_listen = NativeMethods.uv_listen; - _uv_accept = NativeMethods.uv_accept; - _uv_pipe_connect = NativeMethods.uv_pipe_connect; - _uv_pipe_pending_count = NativeMethods.uv_pipe_pending_count; - _uv_read_start = NativeMethods.uv_read_start; - _uv_read_stop = NativeMethods.uv_read_stop; - _uv_try_write = NativeMethods.uv_try_write; - unsafe - { - _uv_write = NativeMethods.uv_write; - _uv_write2 = NativeMethods.uv_write2; - } - _uv_shutdown = NativeMethods.uv_shutdown; - _uv_err_name = NativeMethods.uv_err_name; - _uv_strerror = NativeMethods.uv_strerror; - _uv_loop_size = NativeMethods.uv_loop_size; - _uv_handle_size = NativeMethods.uv_handle_size; - _uv_req_size = NativeMethods.uv_req_size; - _uv_ip4_addr = NativeMethods.uv_ip4_addr; - _uv_ip6_addr = NativeMethods.uv_ip6_addr; - _uv_tcp_getpeername = NativeMethods.uv_tcp_getpeername; - _uv_tcp_getsockname = NativeMethods.uv_tcp_getsockname; - _uv_walk = NativeMethods.uv_walk; + _uv_write = NativeMethods.uv_write; + _uv_write2 = NativeMethods.uv_write2; } + _uv_shutdown = NativeMethods.uv_shutdown; + _uv_err_name = NativeMethods.uv_err_name; + _uv_strerror = NativeMethods.uv_strerror; + _uv_loop_size = NativeMethods.uv_loop_size; + _uv_handle_size = NativeMethods.uv_handle_size; + _uv_req_size = NativeMethods.uv_req_size; + _uv_ip4_addr = NativeMethods.uv_ip4_addr; + _uv_ip6_addr = NativeMethods.uv_ip6_addr; + _uv_tcp_getpeername = NativeMethods.uv_tcp_getpeername; + _uv_tcp_getsockname = NativeMethods.uv_tcp_getsockname; + _uv_walk = NativeMethods.uv_walk; } // Second ctor that doesn't set any fields only to be used by MockLibuv @@ -659,123 +606,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Networking IntPtr lpOverlapped, IntPtr lpCompletionRoutine ); - + [DllImport("WS2_32.dll", CallingConvention = CallingConvention.Winapi)] public static extern int WSAGetLastError(); } - - private static class NativeDarwinMonoMethods - { - [DllImport("__Internal", CallingConvention = CallingConvention.Cdecl)] - public static extern int uv_loop_init(UvLoopHandle handle); - - [DllImport("__Internal", CallingConvention = CallingConvention.Cdecl)] - public static extern int uv_loop_close(IntPtr a0); - - [DllImport("__Internal", CallingConvention = CallingConvention.Cdecl)] - public static extern int uv_run(UvLoopHandle handle, int mode); - - [DllImport("__Internal", CallingConvention = CallingConvention.Cdecl)] - public static extern void uv_stop(UvLoopHandle handle); - - [DllImport("__Internal", CallingConvention = CallingConvention.Cdecl)] - public static extern void uv_ref(UvHandle handle); - - [DllImport("__Internal", CallingConvention = CallingConvention.Cdecl)] - public static extern void uv_unref(UvHandle handle); - - [DllImport("__Internal", CallingConvention = CallingConvention.Cdecl)] - public static extern int uv_fileno(UvHandle handle, ref IntPtr socket); - - [DllImport("__Internal", CallingConvention = CallingConvention.Cdecl)] - public static extern void uv_close(IntPtr handle, uv_close_cb close_cb); - - [DllImport("__Internal", CallingConvention = CallingConvention.Cdecl)] - public static extern int uv_async_init(UvLoopHandle loop, UvAsyncHandle handle, uv_async_cb cb); - - [DllImport("__Internal", CallingConvention = CallingConvention.Cdecl)] - public extern static int uv_async_send(UvAsyncHandle handle); - - [DllImport("__Internal", CallingConvention = CallingConvention.Cdecl, EntryPoint = "uv_async_send")] - public extern static int uv_unsafe_async_send(IntPtr handle); - - [DllImport("__Internal", CallingConvention = CallingConvention.Cdecl)] - public static extern int uv_tcp_init(UvLoopHandle loop, UvTcpHandle handle); - - [DllImport("__Internal", CallingConvention = CallingConvention.Cdecl)] - public static extern int uv_tcp_bind(UvTcpHandle handle, ref SockAddr addr, int flags); - - [DllImport("__Internal", CallingConvention = CallingConvention.Cdecl)] - public static extern int uv_tcp_open(UvTcpHandle handle, IntPtr hSocket); - - [DllImport("__Internal", CallingConvention = CallingConvention.Cdecl)] - public static extern int uv_tcp_nodelay(UvTcpHandle handle, int enable); - - [DllImport("__Internal", CallingConvention = CallingConvention.Cdecl)] - public static extern int uv_pipe_init(UvLoopHandle loop, UvPipeHandle handle, int ipc); - - [DllImport("__Internal", CallingConvention = CallingConvention.Cdecl)] - public static extern int uv_pipe_bind(UvPipeHandle loop, string name); - - [DllImport("__Internal", CallingConvention = CallingConvention.Cdecl)] - public static extern int uv_listen(UvStreamHandle handle, int backlog, uv_connection_cb cb); - - [DllImport("__Internal", CallingConvention = CallingConvention.Cdecl)] - public static extern int uv_accept(UvStreamHandle server, UvStreamHandle client); - - [DllImport("__Internal", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)] - public static extern void uv_pipe_connect(UvConnectRequest req, UvPipeHandle handle, string name, uv_connect_cb cb); - - [DllImport("__Internal", CallingConvention = CallingConvention.Cdecl)] - public extern static int uv_pipe_pending_count(UvPipeHandle handle); - - [DllImport("__Internal", CallingConvention = CallingConvention.Cdecl)] - public extern static int uv_read_start(UvStreamHandle handle, uv_alloc_cb alloc_cb, uv_read_cb read_cb); - - [DllImport("__Internal", CallingConvention = CallingConvention.Cdecl)] - public static extern int uv_read_stop(UvStreamHandle handle); - - [DllImport("__Internal", CallingConvention = CallingConvention.Cdecl)] - public static extern int uv_try_write(UvStreamHandle handle, uv_buf_t[] bufs, int nbufs); - - [DllImport("__Internal", CallingConvention = CallingConvention.Cdecl)] - unsafe public static extern int uv_write(UvRequest req, UvStreamHandle handle, uv_buf_t* bufs, int nbufs, uv_write_cb cb); - - [DllImport("__Internal", CallingConvention = CallingConvention.Cdecl)] - unsafe public static extern int uv_write2(UvRequest req, UvStreamHandle handle, uv_buf_t* bufs, int nbufs, UvStreamHandle sendHandle, uv_write_cb cb); - - [DllImport("__Internal", CallingConvention = CallingConvention.Cdecl)] - public static extern int uv_shutdown(UvShutdownReq req, UvStreamHandle handle, uv_shutdown_cb cb); - - [DllImport("__Internal", CallingConvention = CallingConvention.Cdecl)] - public extern static IntPtr uv_err_name(int err); - - [DllImport("__Internal", CallingConvention = CallingConvention.Cdecl)] - public static extern IntPtr uv_strerror(int err); - - [DllImport("__Internal", CallingConvention = CallingConvention.Cdecl)] - public static extern int uv_loop_size(); - - [DllImport("__Internal", CallingConvention = CallingConvention.Cdecl)] - public static extern int uv_handle_size(HandleType handleType); - - [DllImport("__Internal", CallingConvention = CallingConvention.Cdecl)] - public static extern int uv_req_size(RequestType reqType); - - [DllImport("__Internal", CallingConvention = CallingConvention.Cdecl)] - public static extern int uv_ip4_addr(string ip, int port, out SockAddr addr); - - [DllImport("__Internal", CallingConvention = CallingConvention.Cdecl)] - public static extern int uv_ip6_addr(string ip, int port, out SockAddr addr); - - [DllImport("__Internal", CallingConvention = CallingConvention.Cdecl)] - public static extern int uv_tcp_getsockname(UvTcpHandle handle, out SockAddr name, ref int namelen); - - [DllImport("__Internal", CallingConvention = CallingConvention.Cdecl)] - public static extern int uv_tcp_getpeername(UvTcpHandle handle, out SockAddr name, ref int namelen); - - [DllImport("__Internal", CallingConvention = CallingConvention.Cdecl)] - unsafe public static extern int uv_walk(UvLoopHandle loop, uv_walk_cb walk_cb, IntPtr arg); - } } } \ No newline at end of file diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Networking/PlatformApis.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Networking/PlatformApis.cs index 29265b3538..f485665bf9 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Networking/PlatformApis.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Networking/PlatformApis.cs @@ -21,41 +21,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Networking if (!IsWindows) { // When running on Mono in Darwin OSVersion doesn't return Darwin. It returns Unix instead. - // Fallback to use uname. - IsDarwin = string.Equals(GetUname(), "Darwin", StringComparison.Ordinal); + IsDarwin = PlatformServices.Default.Runtime.OperatingSystemPlatform == Platform.Darwin; } #endif - - IsMono = PlatformServices.Default.Runtime.RuntimeType == "Mono"; } public static bool IsWindows { get; } public static bool IsDarwin { get; } - - public static bool IsMono { get; } - - [DllImport("libc")] - static extern int uname(IntPtr buf); - - static unsafe string GetUname() - { - var buffer = new byte[8192]; - try - { - fixed (byte* buf = buffer) - { - if (uname((IntPtr)buf) == 0) - { - return Marshal.PtrToStringAnsi((IntPtr)buf); - } - } - return string.Empty; - } - catch - { - return string.Empty; - } - } } } From 6047a62c070780ca960f84d60c918ee464d3f319 Mon Sep 17 00:00:00 2001 From: Mike Harder Date: Wed, 13 Apr 2016 14:57:54 -0700 Subject: [PATCH 0686/1662] Add IWebHostBuilder.UseKestrel(options) overload to configure Kestrel (#720) - Replace KestrelServerInformation with KestrelServerOptions. - Move properties from KestrelServerPoolingParameters to KestrelServerOptions. - Stop reading default options from "kestrel.*" config settings. - Move extension method IApplicatonBuilder.UseKestrelConnectionLogging() to KestrelServerOptions.UseConnectionLogging() --- samples/SampleApp/Startup.cs | 28 +--- .../HttpsApplicationBuilderExtensions.cs | 34 ----- .../KestrelServerOptionsHttpsExtensions.cs | 90 +++++++++++ ...erverOptionsConnectionLoggingExtensions.cs | 39 +++++ ...ggingFilterApplicationBuilderExtensions.cs | 39 ----- .../Http/Connection.cs | 4 +- .../Http/TcpListener.cs | 4 +- .../Http/TcpListenerPrimary.cs | 4 +- .../Http/TcpListenerSecondary.cs | 2 +- .../IKestrelServerInformation.cs | 35 ----- .../Infrastructure/HttpComponentFactory.cs | 10 +- .../Infrastructure/IHttpComponentFactory.cs | 2 +- .../Internal/KestrelServerOptionsSetup.cs | 23 +++ .../Internal/ServerAddressesFeature.cs | 13 ++ .../KestrelEngine.cs | 2 +- .../KestrelServer.cs | 24 ++- .../KestrelServerInformation.cs | 130 ---------------- .../KestrelServerOptions.cs | 70 +++++++++ .../KestrelServerPoolingParameters.cs | 43 ------ .../KestrelWebHostBuilderExtensions.cs | 16 -- .../ServerFactory.cs | 29 +++- .../ServiceContext.cs | 4 +- .../WebHostBuilderKestrelExtensions.cs | 52 +++++++ .../ThreadCountTests.cs | 7 +- .../EngineTests.cs | 4 +- .../FrameResponseHeadersTests.cs | 16 +- .../KestrelServerInformationTests.cs | 144 ------------------ .../KestrelServerOptionsTests.cs | 30 ++++ .../KestrelServerTests.cs | 38 ++--- .../TestServiceContext.cs | 9 +- 30 files changed, 412 insertions(+), 533 deletions(-) delete mode 100644 src/Microsoft.AspNetCore.Server.Kestrel.Https/HttpsApplicationBuilderExtensions.cs create mode 100644 src/Microsoft.AspNetCore.Server.Kestrel.Https/KestrelServerOptionsHttpsExtensions.cs create mode 100644 src/Microsoft.AspNetCore.Server.Kestrel/Filter/KestrelServerOptionsConnectionLoggingExtensions.cs delete mode 100644 src/Microsoft.AspNetCore.Server.Kestrel/Filter/LoggingFilterApplicationBuilderExtensions.cs delete mode 100644 src/Microsoft.AspNetCore.Server.Kestrel/IKestrelServerInformation.cs create mode 100644 src/Microsoft.AspNetCore.Server.Kestrel/Internal/KestrelServerOptionsSetup.cs create mode 100644 src/Microsoft.AspNetCore.Server.Kestrel/Internal/ServerAddressesFeature.cs delete mode 100644 src/Microsoft.AspNetCore.Server.Kestrel/KestrelServerInformation.cs create mode 100644 src/Microsoft.AspNetCore.Server.Kestrel/KestrelServerOptions.cs delete mode 100644 src/Microsoft.AspNetCore.Server.Kestrel/KestrelServerPoolingParameters.cs delete mode 100644 src/Microsoft.AspNetCore.Server.Kestrel/KestrelWebHostBuilderExtensions.cs create mode 100644 src/Microsoft.AspNetCore.Server.Kestrel/WebHostBuilderKestrelExtensions.cs delete mode 100644 test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerInformationTests.cs create mode 100644 test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerOptionsTests.cs diff --git a/samples/SampleApp/Startup.cs b/samples/SampleApp/Startup.cs index 1590a8dac3..7baa8d1c22 100644 --- a/samples/SampleApp/Startup.cs +++ b/samples/SampleApp/Startup.cs @@ -3,12 +3,9 @@ using System; using System.IO; -using System.Security.Cryptography.X509Certificates; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Server.Kestrel; -using Microsoft.AspNetCore.Server.Kestrel.Filter; using Microsoft.Extensions.Logging; using Microsoft.Extensions.PlatformAbstractions; @@ -18,25 +15,8 @@ namespace SampleApp { public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory, IApplicationEnvironment env) { - var ksi = app.ServerFeatures.Get(); - //ksi.ThreadCount = 4; - ksi.NoDelay = true; - loggerFactory.AddConsole(LogLevel.Trace); - var testCertPath = Path.Combine(env.ApplicationBasePath, "testCert.pfx"); - - if (File.Exists(testCertPath)) - { - app.UseKestrelHttps(new X509Certificate2(testCertPath, "testPassword")); - } - else - { - Console.WriteLine("Could not find certificate at '{0}'. HTTPS is not enabled.", testCertPath); - } - - app.UseKestrelConnectionLogging(); - app.Run(async context => { Console.WriteLine("{0} {1}{2}{3}", @@ -63,7 +43,13 @@ namespace SampleApp { var host = new WebHostBuilder() .UseDefaultHostingConfiguration(args) - .UseKestrel() + .UseKestrel(options => + { + // options.ThreadCount = 4; + options.NoDelay = true; + options.UseHttps("testCert.pfx", "testPassword"); + options.UseConnectionLogging(); + }) .UseUrls("http://localhost:5000", "https://localhost:5001") .UseContentRoot(Directory.GetCurrentDirectory()) .UseStartup() diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Https/HttpsApplicationBuilderExtensions.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Https/HttpsApplicationBuilderExtensions.cs deleted file mode 100644 index eb8a95862b..0000000000 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Https/HttpsApplicationBuilderExtensions.cs +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System.Security.Cryptography.X509Certificates; -using Microsoft.AspNetCore.Builder; -using Microsoft.AspNetCore.Http.Features; -using Microsoft.AspNetCore.Server.Kestrel.Https; - -namespace Microsoft.AspNetCore.Server.Kestrel.Filter -{ - public static class HttpsApplicationBuilderExtensions - { - public static IApplicationBuilder UseKestrelHttps(this IApplicationBuilder app, X509Certificate2 cert) - { - return app.UseKestrelHttps(new HttpsConnectionFilterOptions { ServerCertificate = cert}); - } - - public static IApplicationBuilder UseKestrelHttps(this IApplicationBuilder app, HttpsConnectionFilterOptions options) - { - var serverInfo = app.ServerFeatures.Get(); - - if (serverInfo == null) - { - return app; - } - - var prevFilter = serverInfo.ConnectionFilter ?? new NoOpConnectionFilter(); - - serverInfo.ConnectionFilter = new HttpsConnectionFilter(options, prevFilter); - - return app; - } - } -} diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Https/KestrelServerOptionsHttpsExtensions.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Https/KestrelServerOptionsHttpsExtensions.cs new file mode 100644 index 0000000000..db1d28bd6a --- /dev/null +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Https/KestrelServerOptionsHttpsExtensions.cs @@ -0,0 +1,90 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System.IO; +using System.Security.Cryptography.X509Certificates; +using Microsoft.AspNetCore.Server.Kestrel; +using Microsoft.AspNetCore.Server.Kestrel.Filter; +using Microsoft.AspNetCore.Server.Kestrel.Https; +using Microsoft.Extensions.DependencyInjection; + +namespace Microsoft.AspNetCore.Hosting +{ + public static class KestrelServerOptionsHttpsExtensions + { + /// + /// Configure Kestrel to use HTTPS. + /// + /// + /// The Microsoft.AspNetCore.Server.KestrelServerOptions to configure. + /// + /// + /// The name of a certificate file, relative to the directory that contains the application content files. + /// + /// + /// The Microsoft.AspNetCore.Server.KestrelServerOptions. + /// + public static KestrelServerOptions UseHttps(this KestrelServerOptions options, string fileName) + { + var env = options.ApplicationServices.GetRequiredService(); + return options.UseHttps(new X509Certificate2(Path.Combine(env.ContentRootPath, fileName))); + } + + /// + /// Configure Kestrel to use HTTPS. + /// + /// + /// The Microsoft.AspNetCore.Server.KestrelServerOptions to configure. + /// + /// + /// The name of a certificate file, relative to the directory that contains the application content files. + /// + /// + /// The password required to access the X.509 certificate data. + /// + /// + /// The Microsoft.AspNetCore.Server.KestrelServerOptions. + /// + public static KestrelServerOptions UseHttps(this KestrelServerOptions options, string fileName, string password) + { + var env = options.ApplicationServices.GetRequiredService(); + return options.UseHttps(new X509Certificate2(Path.Combine(env.ContentRootPath, fileName), password)); + } + + /// + /// Configure Kestrel to use HTTPS. + /// + /// + /// The Microsoft.AspNetCore.Server.KestrelServerOptions to configure. + /// + /// + /// The X.509 certificate. + /// + /// + /// The Microsoft.AspNetCore.Server.KestrelServerOptions. + /// + public static KestrelServerOptions UseHttps(this KestrelServerOptions options, X509Certificate2 serverCertificate) + { + return options.UseHttps(new HttpsConnectionFilterOptions { ServerCertificate = serverCertificate }); + } + + /// + /// Configure Kestrel to use HTTPS. + /// + /// + /// The Microsoft.AspNetCore.Server.KestrelServerOptions to configure. + /// + /// + /// Options to configure HTTPS. + /// + /// + /// The Microsoft.AspNetCore.Server.KestrelServerOptions. + /// + public static KestrelServerOptions UseHttps(this KestrelServerOptions options, HttpsConnectionFilterOptions httpsOptions) + { + var prevFilter = options.ConnectionFilter ?? new NoOpConnectionFilter(); + options.ConnectionFilter = new HttpsConnectionFilter(httpsOptions, prevFilter); + return options; + } + } +} diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Filter/KestrelServerOptionsConnectionLoggingExtensions.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Filter/KestrelServerOptionsConnectionLoggingExtensions.cs new file mode 100644 index 0000000000..a46d0646eb --- /dev/null +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Filter/KestrelServerOptionsConnectionLoggingExtensions.cs @@ -0,0 +1,39 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using Microsoft.AspNetCore.Server.Kestrel; +using Microsoft.AspNetCore.Server.Kestrel.Filter; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; + +namespace Microsoft.AspNetCore.Hosting +{ + public static class KestrelServerOptionsConnectionLoggingExtensions + { + /// + /// Emits verbose logs for bytes read from and written to the connection. + /// + /// + /// The Microsoft.AspNetCore.Server.KestrelServerOptions. + /// + public static KestrelServerOptions UseConnectionLogging(this KestrelServerOptions options) + { + return options.UseConnectionLogging(nameof(LoggingConnectionFilter)); + } + + /// + /// Emits verbose logs for bytes read from and written to the connection. + /// + /// + /// The Microsoft.AspNetCore.Server.KestrelServerOptions. + /// + public static KestrelServerOptions UseConnectionLogging(this KestrelServerOptions options, string loggerName) + { + var prevFilter = options.ConnectionFilter ?? new NoOpConnectionFilter(); + var loggerFactory = options.ApplicationServices.GetRequiredService(); + var logger = loggerFactory.CreateLogger(loggerName ?? nameof(LoggingConnectionFilter)); + options.ConnectionFilter = new LoggingConnectionFilter(logger, prevFilter); + return options; + } + } +} diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Filter/LoggingFilterApplicationBuilderExtensions.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Filter/LoggingFilterApplicationBuilderExtensions.cs deleted file mode 100644 index 8d373f5897..0000000000 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Filter/LoggingFilterApplicationBuilderExtensions.cs +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using Microsoft.AspNetCore.Builder; -using Microsoft.AspNetCore.Http.Features; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Logging; - -namespace Microsoft.AspNetCore.Server.Kestrel.Filter -{ - public static class LoggingFilterApplicationBuilderExtensions - { - /// - /// Emits verbose logs for bytes read from and written to the connection. - /// - /// - public static IApplicationBuilder UseKestrelConnectionLogging(this IApplicationBuilder app) - { - return app.UseKestrelConnectionLogging(nameof(LoggingConnectionFilter)); - } - - /// - /// Emits verbose logs for bytes read from and written to the connection. - /// - /// - public static IApplicationBuilder UseKestrelConnectionLogging(this IApplicationBuilder app, string loggerName) - { - var serverInfo = app.ServerFeatures.Get(); - if (serverInfo != null) - { - var prevFilter = serverInfo.ConnectionFilter ?? new NoOpConnectionFilter(); - var loggerFactory = app.ApplicationServices.GetRequiredService(); - var logger = loggerFactory.CreateLogger(loggerName ?? nameof(LoggingConnectionFilter)); - serverInfo.ConnectionFilter = new LoggingConnectionFilter(logger, prevFilter); - } - return app; - } - } -} diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Connection.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Connection.cs index fbd690eea7..71a40284b0 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Connection.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Connection.cs @@ -70,7 +70,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } // Don't initialize _frame until SocketInput and SocketOutput are set to their final values. - if (ServerInformation.ConnectionFilter == null) + if (ServerOptions.ConnectionFilter == null) { lock (_stateLock) { @@ -100,7 +100,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http try { - ServerInformation.ConnectionFilter.OnConnectionAsync(_filterContext).ContinueWith((task, state) => + ServerOptions.ConnectionFilter.OnConnectionAsync(_filterContext).ContinueWith((task, state) => { var connection = (Connection)state; diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/TcpListener.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/TcpListener.cs index 1b1927e27c..94c7cdecd9 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/TcpListener.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/TcpListener.cs @@ -23,7 +23,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { var socket = new UvTcpHandle(Log); socket.Init(Thread.Loop, Thread.QueueCloseHandle); - socket.NoDelay(ServerInformation.NoDelay); + socket.NoDelay(ServerOptions.NoDelay); socket.Bind(ServerAddress); socket.Listen(Constants.ListenBacklog, (stream, status, error, state) => ConnectionCallback(stream, status, error, state), this); return socket; @@ -41,7 +41,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http try { acceptSocket.Init(Thread.Loop, Thread.QueueCloseHandle); - acceptSocket.NoDelay(ServerInformation.NoDelay); + acceptSocket.NoDelay(ServerOptions.NoDelay); listenSocket.Accept(acceptSocket); DispatchConnection(acceptSocket); } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/TcpListenerPrimary.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/TcpListenerPrimary.cs index e791d30568..80691b51ec 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/TcpListenerPrimary.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/TcpListenerPrimary.cs @@ -25,7 +25,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { var socket = new UvTcpHandle(Log); socket.Init(Thread.Loop, Thread.QueueCloseHandle); - socket.NoDelay(ServerInformation.NoDelay); + socket.NoDelay(ServerOptions.NoDelay); socket.Bind(ServerAddress); socket.Listen(Constants.ListenBacklog, (stream, status, error, state) => ConnectionCallback(stream, status, error, state), this); return socket; @@ -43,7 +43,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http try { acceptSocket.Init(Thread.Loop, Thread.QueueCloseHandle); - acceptSocket.NoDelay(ServerInformation.NoDelay); + acceptSocket.NoDelay(ServerOptions.NoDelay); listenSocket.Accept(acceptSocket); DispatchConnection(acceptSocket); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/TcpListenerSecondary.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/TcpListenerSecondary.cs index d52ac62b7e..1a19445d50 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/TcpListenerSecondary.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/TcpListenerSecondary.cs @@ -21,7 +21,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { var acceptSocket = new UvTcpHandle(Log); acceptSocket.Init(Thread.Loop, Thread.QueueCloseHandle); - acceptSocket.NoDelay(ServerInformation.NoDelay); + acceptSocket.NoDelay(ServerOptions.NoDelay); return acceptSocket; } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/IKestrelServerInformation.cs b/src/Microsoft.AspNetCore.Server.Kestrel/IKestrelServerInformation.cs deleted file mode 100644 index 87a6b645b2..0000000000 --- a/src/Microsoft.AspNetCore.Server.Kestrel/IKestrelServerInformation.cs +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using Microsoft.AspNetCore.Server.Kestrel.Filter; - -namespace Microsoft.AspNetCore.Server.Kestrel -{ - public interface IKestrelServerInformation - { - int ThreadCount { get; set; } - - /// - /// The amount of time after the server begins shutting down before connections will be forcefully closed. - /// By default, Kestrel will wait 5 seconds for any ongoing requests to complete before terminating - /// the connection. - /// A custom timeout can be configured using the "kestrel.shutdownTimeout" key in . - /// The value will be parsed as a float representing the timeout in seconds. - /// - TimeSpan ShutdownTimeout { get; set; } - - bool NoDelay { get; set; } - - /// - /// Gets or sets values that instruct whether it is safe to - /// pool the Request and Response objects, Headers etc - /// for another request after the Response's OnCompleted callback has fired. - /// When these values are greater than zero it is not safe to retain references to feature components after this event has fired. - /// They are zero by default. - /// - KestrelServerPoolingParameters PoolingParameters { get; } - - IConnectionFilter ConnectionFilter { get; set; } - } -} diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/HttpComponentFactory.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/HttpComponentFactory.cs index b0be4ad410..cacd005b55 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/HttpComponentFactory.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/HttpComponentFactory.cs @@ -13,11 +13,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure private ConcurrentQueue _streamPool = new ConcurrentQueue(); private ConcurrentQueue _headerPool = new ConcurrentQueue(); - public IKestrelServerInformation ServerInformation { get; set; } + public KestrelServerOptions ServerOptions { get; set; } - public HttpComponentFactory(IKestrelServerInformation serverInformation) + public HttpComponentFactory(KestrelServerOptions serverOptions) { - ServerInformation = serverInformation; + ServerOptions = serverOptions; } public Streams CreateStreams(FrameContext owner) @@ -36,7 +36,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure public void DisposeStreams(Streams streams) { - if (_streamPool.Count < ServerInformation.PoolingParameters.MaxPooledStreams) + if (_streamPool.Count < ServerOptions.MaxPooledStreams) { streams.Uninitialize(); @@ -60,7 +60,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure public void DisposeHeaders(Headers headers) { - if (_headerPool.Count < ServerInformation.PoolingParameters.MaxPooledHeaders) + if (_headerPool.Count < ServerOptions.MaxPooledHeaders) { headers.Uninitialize(); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/IHttpComponentFactory.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/IHttpComponentFactory.cs index c64f039680..926d9cfd26 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/IHttpComponentFactory.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/IHttpComponentFactory.cs @@ -7,7 +7,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure { interface IHttpComponentFactory { - IKestrelServerInformation ServerInformation { get; set; } + KestrelServerOptions ServerOptions { get; set; } Streams CreateStreams(FrameContext owner); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/KestrelServerOptionsSetup.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/KestrelServerOptionsSetup.cs new file mode 100644 index 0000000000..93fda55f07 --- /dev/null +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/KestrelServerOptionsSetup.cs @@ -0,0 +1,23 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using Microsoft.Extensions.Options; + +namespace Microsoft.AspNetCore.Server.Kestrel.Internal +{ + public class KestrelServerOptionsSetup : IConfigureOptions + { + private IServiceProvider _services; + + public KestrelServerOptionsSetup(IServiceProvider services) + { + _services = services; + } + + public void Configure(KestrelServerOptions options) + { + options.ApplicationServices = _services; + } + } +} diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/ServerAddressesFeature.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/ServerAddressesFeature.cs new file mode 100644 index 0000000000..6294923d6f --- /dev/null +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/ServerAddressesFeature.cs @@ -0,0 +1,13 @@ +//// Copyright (c) .NET Foundation. All rights reserved. +//// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System.Collections.Generic; +using Microsoft.AspNetCore.Server.Features; + +namespace Microsoft.AspNetCore.Server.Kestrel.Internal +{ + public class ServerAddressesFeature : IServerAddressesFeature + { + public ICollection Addresses { get; } = new List(); + } +} diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/KestrelEngine.cs b/src/Microsoft.AspNetCore.Server.Kestrel/KestrelEngine.cs index ae4f84735c..db0e28956d 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/KestrelEngine.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/KestrelEngine.cs @@ -114,7 +114,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel disposeTasks.Add(listener.DisposeAsync()); } - if (!Task.WhenAll(disposeTasks).Wait(ServerInformation.ShutdownTimeout)) + if (!Task.WhenAll(disposeTasks).Wait(ServerOptions.ShutdownTimeout)) { Log.NotAllConnectionsClosedGracefully(); } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServer.cs b/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServer.cs index 6d38e3e2b5..636710dd72 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServer.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServer.cs @@ -6,6 +6,7 @@ using System.Collections.Generic; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting.Server; using Microsoft.AspNetCore.Http.Features; +using Microsoft.AspNetCore.Server.Features; using Microsoft.AspNetCore.Server.Kestrel.Http; using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; using Microsoft.Extensions.Logging; @@ -18,13 +19,18 @@ namespace Microsoft.AspNetCore.Server.Kestrel private readonly IApplicationLifetime _applicationLifetime; private readonly ILogger _logger; - public KestrelServer(IFeatureCollection features, IApplicationLifetime applicationLifetime, ILogger logger) + public KestrelServer(IFeatureCollection features, KestrelServerOptions options, IApplicationLifetime applicationLifetime, ILogger logger) { if (features == null) { throw new ArgumentNullException(nameof(features)); } + if (options == null) + { + throw new ArgumentNullException(nameof(options)); + } + if (applicationLifetime == null) { throw new ArgumentNullException(nameof(applicationLifetime)); @@ -38,10 +44,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel _applicationLifetime = applicationLifetime; _logger = logger; Features = features; + Options = options; } public IFeatureCollection Features { get; } + public KestrelServerOptions Options { get; } + public void Start(IHttpApplication application) { if (_disposables != null) @@ -53,7 +62,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel try { - var information = (KestrelServerInformation)Features.Get(); var componentFactory = Features.Get(); var dateHeaderValueManager = new DateHeaderValueManager(); var trace = new KestrelTrace(_logger); @@ -67,14 +75,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel Log = trace, ThreadPool = new LoggingThreadPool(trace), DateHeaderValueManager = dateHeaderValueManager, - ServerInformation = information, + ServerOptions = Options, HttpComponentFactory = componentFactory }); _disposables.Push(engine); _disposables.Push(dateHeaderValueManager); - var threadCount = information.ThreadCount; + var threadCount = Options.ThreadCount; if (threadCount <= 0) { @@ -86,7 +94,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel engine.Start(threadCount); var atLeastOneListener = false; - foreach (var address in information.Addresses) + var addressesFeature = Features.Get(); + if (addressesFeature == null) + { + throw new InvalidOperationException($"{nameof(IServerAddressesFeature)} is missing."); + } + + foreach (var address in addressesFeature.Addresses) { var parsedAddress = ServerAddress.FromUrl(address); if (parsedAddress == null) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServerInformation.cs b/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServerInformation.cs deleted file mode 100644 index 58f44cede3..0000000000 --- a/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServerInformation.cs +++ /dev/null @@ -1,130 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using System.Collections.Generic; -using System.Globalization; -using Microsoft.AspNetCore.Server.Features; -using Microsoft.AspNetCore.Server.Kestrel.Filter; -using Microsoft.Extensions.Configuration; - -namespace Microsoft.AspNetCore.Server.Kestrel -{ - public class KestrelServerInformation : IKestrelServerInformation, IServerAddressesFeature - { - public KestrelServerInformation(IConfiguration configuration) - { - if (configuration == null) - { - throw new ArgumentNullException(nameof(configuration)); - } - - Addresses = GetAddresses(configuration); - ThreadCount = GetThreadCount(configuration); - ShutdownTimeout = GetShutdownTimeout(configuration); - NoDelay = GetNoDelay(configuration); - PoolingParameters = new KestrelServerPoolingParameters(configuration); - } - - public ICollection Addresses { get; } - - public int ThreadCount { get; set; } - - public TimeSpan ShutdownTimeout { get; set; } - - public bool NoDelay { get; set; } - - public KestrelServerPoolingParameters PoolingParameters { get; } - - public IConnectionFilter ConnectionFilter { get; set; } - - private static int ProcessorThreadCount - { - get - { - // Actual core count would be a better number - // rather than logical cores which includes hyper-threaded cores. - // Divide by 2 for hyper-threading, and good defaults (still need threads to do webserving). - var threadCount = Environment.ProcessorCount >> 1; - - if (threadCount < 1) - { - // Ensure shifted value is at least one - return 1; - } - - if (threadCount > 16) - { - // Receive Side Scaling RSS Processor count currently maxes out at 16 - // would be better to check the NIC's current hardware queues; but xplat... - return 16; - } - - return threadCount; - } - } - - private static ICollection GetAddresses(IConfiguration configuration) - { - var addresses = new List(); - - var urls = configuration["server.urls"]; - - if (!string.IsNullOrEmpty(urls)) - { - addresses.AddRange(urls.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries)); - } - - return addresses; - } - - private static int GetThreadCount(IConfiguration configuration) - { - var threadCountString = configuration["kestrel.threadCount"]; - - if (string.IsNullOrEmpty(threadCountString)) - { - return ProcessorThreadCount; - } - - int threadCount; - if (int.TryParse(threadCountString, NumberStyles.Integer, CultureInfo.InvariantCulture, out threadCount)) - { - return threadCount; - } - - return ProcessorThreadCount; - } - - private TimeSpan GetShutdownTimeout(IConfiguration configuration) - { - var shutdownTimeoutString = configuration["kestrel.shutdownTimeout"]; - - float shutdownTimeout; - if (float.TryParse(shutdownTimeoutString, NumberStyles.Float, CultureInfo.InvariantCulture, out shutdownTimeout)) - { - return TimeSpan.FromSeconds(shutdownTimeout); - } - - return TimeSpan.FromSeconds(5); - } - - private static bool GetNoDelay(IConfiguration configuration) - { - var noDelayString = configuration["kestrel.noDelay"]; - - if (string.IsNullOrEmpty(noDelayString)) - { - return true; - } - - bool noDelay; - if (bool.TryParse(noDelayString, out noDelay)) - { - return noDelay; - } - - return true; - } - } -} diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServerOptions.cs b/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServerOptions.cs new file mode 100644 index 0000000000..ddf85f9a27 --- /dev/null +++ b/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServerOptions.cs @@ -0,0 +1,70 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using Microsoft.AspNetCore.Server.Kestrel.Filter; + +namespace Microsoft.AspNetCore.Server.Kestrel +{ + public class KestrelServerOptions + { + public IServiceProvider ApplicationServices { get; set; } + + public IConnectionFilter ConnectionFilter { get; set; } + + /// + /// Gets or sets value that instructs whether it is safe to + /// pool the Request and Response objects + /// for another request after the Response's OnCompleted callback has fired. + /// When this values is greater than zero, it is not safe to retain references to feature components after this event has fired. + /// Value is zero by default. + /// + public int MaxPooledStreams { get; set; } + + /// + /// Gets or sets value that instructs whether it is safe to + /// pool the Request and Response headers + /// for another request after the Response's OnCompleted callback has fired. + /// When this values is greater than zero, it is not safe to retain references to feature components after this event has fired. + /// Value is zero by default. + /// + public int MaxPooledHeaders { get; set; } + + public bool NoDelay { get; set; } = true; + + /// + /// The amount of time after the server begins shutting down before connections will be forcefully closed. + /// By default, Kestrel will wait 5 seconds for any ongoing requests to complete before terminating + /// the connection. + /// + public TimeSpan ShutdownTimeout { get; set; } = TimeSpan.FromSeconds(5); + + public int ThreadCount { get; set; } = ProcessorThreadCount; + + private static int ProcessorThreadCount + { + get + { + // Actual core count would be a better number + // rather than logical cores which includes hyper-threaded cores. + // Divide by 2 for hyper-threading, and good defaults (still need threads to do webserving). + var threadCount = Environment.ProcessorCount >> 1; + + if (threadCount < 1) + { + // Ensure shifted value is at least one + return 1; + } + + if (threadCount > 16) + { + // Receive Side Scaling RSS Processor count currently maxes out at 16 + // would be better to check the NIC's current hardware queues; but xplat... + return 16; + } + + return threadCount; + } + } + } +} diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServerPoolingParameters.cs b/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServerPoolingParameters.cs deleted file mode 100644 index 9a019d1d94..0000000000 --- a/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServerPoolingParameters.cs +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using System.Globalization; -using Microsoft.Extensions.Configuration; - -namespace Microsoft.AspNetCore.Server.Kestrel -{ - public class KestrelServerPoolingParameters - { - public KestrelServerPoolingParameters(IConfiguration configuration) - { - if (configuration == null) - { - throw new ArgumentNullException(nameof(configuration)); - } - - MaxPooledStreams = GetPooledCount(configuration["kestrel.maxPooledStreams"]); - MaxPooledHeaders = GetPooledCount(configuration["kestrel.maxPooledHeaders"]); - } - - public int MaxPooledStreams { get; set; } - - public int MaxPooledHeaders { get; set; } - - private static int GetPooledCount(string countString) - { - if (string.IsNullOrEmpty(countString)) - { - return 0; - } - - int count; - if (int.TryParse(countString, NumberStyles.Integer, CultureInfo.InvariantCulture, out count)) - { - return count; - } - - return 0; - } - } -} diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/KestrelWebHostBuilderExtensions.cs b/src/Microsoft.AspNetCore.Server.Kestrel/KestrelWebHostBuilderExtensions.cs deleted file mode 100644 index aa6115094e..0000000000 --- a/src/Microsoft.AspNetCore.Server.Kestrel/KestrelWebHostBuilderExtensions.cs +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System.Reflection; -using Microsoft.AspNetCore.Server.Kestrel; - -namespace Microsoft.AspNetCore.Hosting -{ - public static class KestrelWebHostBuilderExtensions - { - public static IWebHostBuilder UseKestrel(this IWebHostBuilder hostBuilder) - { - return hostBuilder.UseServer(typeof(KestrelServer).GetTypeInfo().Assembly.FullName); - } - } -} diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/ServerFactory.cs b/src/Microsoft.AspNetCore.Server.Kestrel/ServerFactory.cs index c6bf62f604..ada5a92948 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/ServerFactory.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/ServerFactory.cs @@ -7,8 +7,10 @@ using Microsoft.AspNetCore.Hosting.Server; using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Server.Features; using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Internal; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Options; namespace Microsoft.AspNetCore.Server.Kestrel { @@ -19,22 +21,37 @@ namespace Microsoft.AspNetCore.Server.Kestrel { private readonly IApplicationLifetime _appLifetime; private readonly ILoggerFactory _loggerFactory; + private readonly KestrelServerOptions _options; - public ServerFactory(IApplicationLifetime appLifetime, ILoggerFactory loggerFactory) + public ServerFactory(IApplicationLifetime appLifetime, ILoggerFactory loggerFactory, IOptions optionsAccessor) { _appLifetime = appLifetime; _loggerFactory = loggerFactory; + _options = optionsAccessor.Value; } public IServer CreateServer(IConfiguration configuration) { - var information = new KestrelServerInformation(configuration); - var componentFactory = new HttpComponentFactory(information); + var componentFactory = new HttpComponentFactory(_options); var serverFeatures = new FeatureCollection(); - serverFeatures.Set(information); serverFeatures.Set(componentFactory); - serverFeatures.Set(information); - return new KestrelServer(serverFeatures, _appLifetime, _loggerFactory.CreateLogger("Microsoft.AspNetCore.Server.Kestrel")); + serverFeatures.Set(GetAddresses(configuration)); + return new KestrelServer(serverFeatures, _options, _appLifetime, _loggerFactory.CreateLogger("Microsoft.AspNetCore.Server.Kestrel")); } + + private static IServerAddressesFeature GetAddresses(IConfiguration configuration) + { + var addressesFeature = new ServerAddressesFeature(); + var urls = configuration["server.urls"]; + if (!string.IsNullOrEmpty(urls)) + { + foreach (var value in urls.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries)) + { + addressesFeature.Addresses.Add(value); + } + } + return addressesFeature; + } + } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/ServiceContext.cs b/src/Microsoft.AspNetCore.Server.Kestrel/ServiceContext.cs index a591a671ff..72103028d1 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/ServiceContext.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/ServiceContext.cs @@ -24,7 +24,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel ThreadPool = context.ThreadPool; FrameFactory = context.FrameFactory; DateHeaderValueManager = context.DateHeaderValueManager; - ServerInformation = context.ServerInformation; + ServerOptions = context.ServerOptions; HttpComponentFactory = context.HttpComponentFactory; } @@ -38,7 +38,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel public DateHeaderValueManager DateHeaderValueManager { get; set; } - public IKestrelServerInformation ServerInformation { get; set; } + public KestrelServerOptions ServerOptions { get; set; } internal IHttpComponentFactory HttpComponentFactory { get; set; } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/WebHostBuilderKestrelExtensions.cs b/src/Microsoft.AspNetCore.Server.Kestrel/WebHostBuilderKestrelExtensions.cs new file mode 100644 index 0000000000..7632647d03 --- /dev/null +++ b/src/Microsoft.AspNetCore.Server.Kestrel/WebHostBuilderKestrelExtensions.cs @@ -0,0 +1,52 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using Microsoft.AspNetCore.Hosting.Server; +using Microsoft.AspNetCore.Server.Kestrel; +using Microsoft.AspNetCore.Server.Kestrel.Internal; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Options; + +namespace Microsoft.AspNetCore.Hosting +{ + public static class WebHostBuilderKestrelExtensions + { + /// + /// Specify Kestrel as the server to be used by the web host. + /// + /// + /// The Microsoft.AspNetCore.Hosting.IWebHostBuilder to configure. + /// + /// + /// The Microsoft.AspNetCore.Hosting.IWebHostBuilder. + /// + public static IWebHostBuilder UseKestrel(this IWebHostBuilder hostBuilder) + { + return hostBuilder.ConfigureServices(services => services.AddSingleton()); + } + + /// + /// Specify Kestrel as the server to be used by the web host. + /// + /// + /// The Microsoft.AspNetCore.Hosting.IWebHostBuilder to configure. + /// + /// + /// A callback to configure Kestrel options. + /// + /// + /// The Microsoft.AspNetCore.Hosting.IWebHostBuilder. + /// + public static IWebHostBuilder UseKestrel(this IWebHostBuilder hostBuilder, Action options) + { + hostBuilder.ConfigureServices(services => + { + services.AddTransient, KestrelServerOptionsSetup>(); + services.Configure(options); + }); + + return hostBuilder.UseKestrel(); + } + } +} diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ThreadCountTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ThreadCountTests.cs index fff6fb4497..543d1d2a4e 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ThreadCountTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ThreadCountTests.cs @@ -26,11 +26,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests var hostBuilder = new WebHostBuilder() .UseConfiguration(config) - .UseKestrel() + .UseKestrel(options => + { + options.ThreadCount = threadCount; + }) .Configure(app => { - var serverInfo = app.ServerFeatures.Get(); - serverInfo.ThreadCount = threadCount; app.Run(context => { return context.Response.WriteAsync("Hello World"); diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs index 9c42dac2af..c068803b40 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs @@ -173,7 +173,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [MemberData(nameof(ConnectionFilterData))] public async Task ReuseStreamsOn(ServiceContext testContext) { - testContext.ServerInformation.PoolingParameters.MaxPooledStreams = 120; + testContext.ServerOptions.MaxPooledStreams = 120; var streamCount = 0; var loopCount = 20; @@ -216,7 +216,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [MemberData(nameof(ConnectionFilterData))] public async Task ReuseStreamsOff(ServiceContext testContext) { - testContext.ServerInformation.PoolingParameters.MaxPooledStreams = 0; + testContext.ServerOptions.MaxPooledStreams = 0; var streamCount = 0; var loopCount = 20; diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameResponseHeadersTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameResponseHeadersTests.cs index f03deed0e3..88ea59e93e 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameResponseHeadersTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameResponseHeadersTests.cs @@ -17,15 +17,14 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [Fact] public void InitialDictionaryContainsServerAndDate() { - var configuration = new ConfigurationBuilder().Build(); - var serverInformation = new KestrelServerInformation(configuration); + var serverOptions = new KestrelServerOptions(); var connectionContext = new ConnectionContext { DateHeaderValueManager = new DateHeaderValueManager(), ServerAddress = ServerAddress.FromUrl("http://localhost:5000"), - ServerInformation = serverInformation, - HttpComponentFactory = new HttpComponentFactory(serverInformation) - }; + ServerOptions = serverOptions, + HttpComponentFactory = new HttpComponentFactory(serverOptions) + }; var frame = new Frame(application: null, context: connectionContext); frame.InitializeHeaders(); @@ -51,14 +50,13 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [Fact] public void InitialEntriesCanBeCleared() { - var configuration = new ConfigurationBuilder().Build(); - var serverInformation = new KestrelServerInformation(configuration); + var serverOptions = new KestrelServerOptions(); var connectionContext = new ConnectionContext { DateHeaderValueManager = new DateHeaderValueManager(), ServerAddress = ServerAddress.FromUrl("http://localhost:5000"), - ServerInformation = serverInformation, - HttpComponentFactory = new HttpComponentFactory(serverInformation) + ServerOptions = serverOptions, + HttpComponentFactory = new HttpComponentFactory(serverOptions) }; var frame = new Frame(application: null, context: connectionContext); frame.InitializeHeaders(); diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerInformationTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerInformationTests.cs deleted file mode 100644 index d8594e623c..0000000000 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerInformationTests.cs +++ /dev/null @@ -1,144 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using System.Collections.Generic; -using Microsoft.AspNetCore.Server.Kestrel; -using Microsoft.Extensions.Configuration; -using Xunit; - -namespace Microsoft.AspNetCore.Server.KestrelTests -{ - public class KestrelServerInformationTests - { - [Fact] - public void NullConfigurationThrows() - { - Assert.Throws(() => new KestrelServerInformation(null)); - } - - [Fact] - public void SetThreadCountUsingConfiguration() - { - const int expected = 42; - - var values = new Dictionary - { - { "kestrel.threadCount", expected.ToString() } - }; - - var configuration = new ConfigurationBuilder() - .AddInMemoryCollection(values) - .Build(); - - var information = new KestrelServerInformation(configuration); - - Assert.Equal(expected, information.ThreadCount); - } - - [Fact] - public void SetThreadCountUsingProcessorCount() - { - // Ideally we'd mock Environment.ProcessorCount to test edge cases. - var expected = Clamp(Environment.ProcessorCount >> 1, 1, 16); - - var configuration = new ConfigurationBuilder().Build(); - - var information = new KestrelServerInformation(configuration); - - Assert.Equal(expected, information.ThreadCount); - } - - [Fact] - public void SetAddressesUsingConfiguration() - { - var expected = new List { "http://localhost:1337", "https://localhost:42" }; - - var values = new Dictionary - { - { "server.urls", string.Join(";", expected) } - }; - - var configuration = new ConfigurationBuilder() - .AddInMemoryCollection(values) - .Build(); - - var information = new KestrelServerInformation(configuration); - - Assert.Equal(expected, information.Addresses); - } - - [Fact] - public void SetNoDelayUsingConfiguration() - { - var values = new Dictionary - { - { "kestrel.noDelay", "false" } - }; - - var configuration = new ConfigurationBuilder() - .AddInMemoryCollection(values) - .Build(); - - var information = new KestrelServerInformation(configuration); - - Assert.False(information.NoDelay); - } - - [Theory] - [InlineData(null, 0)] - [InlineData("", 0)] - [InlineData("0", 0)] - [InlineData("00", 0)] - [InlineData("0.0", 0)] - [InlineData("1", 1)] - [InlineData("16", 16)] - [InlineData("1000", 1000)] - public void SetMaxPooledStreamsUsingConfiguration(string input, int expected) - { - var values = new Dictionary - { - { "kestrel.maxPooledStreams", input } - }; - - var configuration = new ConfigurationBuilder() - .AddInMemoryCollection(values) - .Build(); - - var information = new KestrelServerInformation(configuration); - - Assert.Equal(expected, information.PoolingParameters.MaxPooledStreams); - } - - - [Theory] - [InlineData(null, 0)] - [InlineData("", 0)] - [InlineData("0", 0)] - [InlineData("00", 0)] - [InlineData("0.0", 0)] - [InlineData("1", 1)] - [InlineData("16", 16)] - [InlineData("1000", 1000)] - public void SetMaxPooledHeadersUsingConfiguration(string input, int expected) - { - var values = new Dictionary - { - { "kestrel.maxPooledHeaders", input } - }; - - var configuration = new ConfigurationBuilder() - .AddInMemoryCollection(values) - .Build(); - - var information = new KestrelServerInformation(configuration); - - Assert.Equal(expected, information.PoolingParameters.MaxPooledHeaders); - } - - private static int Clamp(int value, int min, int max) - { - return value < min ? min : value > max ? max : value; - } - } -} \ No newline at end of file diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerOptionsTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerOptionsTests.cs new file mode 100644 index 0000000000..ff03086b71 --- /dev/null +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerOptionsTests.cs @@ -0,0 +1,30 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Collections.Generic; +using Microsoft.AspNetCore.Server.Kestrel; +using Microsoft.Extensions.Configuration; +using Xunit; + +namespace Microsoft.AspNetCore.Server.KestrelTests +{ + public class KestrelServerInformationTests + { + [Fact] + public void SetThreadCountUsingProcessorCount() + { + // Ideally we'd mock Environment.ProcessorCount to test edge cases. + var expected = Clamp(Environment.ProcessorCount >> 1, 1, 16); + + var information = new KestrelServerOptions(); + + Assert.Equal(expected, information.ThreadCount); + } + + private static int Clamp(int value, int min, int max) + { + return value < min ? min : value > max ? max : value; + } + } +} \ No newline at end of file diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerTests.cs index 8c4e8c1490..89b828f468 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerTests.cs @@ -4,9 +4,10 @@ using System; using Microsoft.AspNetCore.Hosting.Server; using Microsoft.AspNetCore.Http.Features; +using Microsoft.AspNetCore.Server.Features; using Microsoft.AspNetCore.Server.Kestrel; using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; -using Microsoft.Extensions.Configuration; +using Microsoft.AspNetCore.Server.Kestrel.Internal; using Xunit; namespace Microsoft.AspNetCore.Server.KestrelTests @@ -18,11 +19,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [InlineData(-1337)] public void StartWithNonPositiveThreadCountThrows(int threadCount) { - var server = CreateServer(configuration => - new KestrelServerInformation(configuration) - { - ThreadCount = threadCount - }); + var server = CreateServer(new KestrelServerOptions() { ThreadCount = threadCount }); var exception = Assert.Throws(() => StartDummyApplication(server)); @@ -32,11 +29,9 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [Fact] public void StartWithInvalidAddressThrows() { - var server = CreateServer(configuration => - new KestrelServerInformation(configuration) - { - Addresses = {"http:/asdf"} - }); + var addressesFeature = new ServerAddressesFeature(); + addressesFeature.Addresses.Add("http:/asdf"); + var server = CreateServer(new KestrelServerOptions(), addressesFeature); var exception = Assert.Throws(() => StartDummyApplication(server)); @@ -46,32 +41,25 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [Fact] public void StartWithEmptyAddressesThrows() { - var server = CreateServer(configuration => - { - var information = new KestrelServerInformation(configuration); - - information.Addresses.Clear(); - - return information; - }); + var server = CreateServer(new KestrelServerOptions(), new ServerAddressesFeature()); var exception = Assert.Throws(() => StartDummyApplication(server)); Assert.Equal("No recognized listening addresses were configured.", exception.Message); } - private static KestrelServer CreateServer(Func serverInformationFactory) + private static KestrelServer CreateServer(KestrelServerOptions options, IServerAddressesFeature addressesFeature = null) { - var configuration = new ConfigurationBuilder().Build(); - var information = serverInformationFactory(configuration); - var features = new FeatureCollection(); - features.Set(information); + if (addressesFeature != null) + { + features.Set(addressesFeature); + } var lifetime = new LifetimeNotImplemented(); var logger = new TestApplicationErrorLogger(); - return new KestrelServer(features, lifetime, logger); + return new KestrelServer(features, options, lifetime, logger); } private static void StartDummyApplication(IServer server) diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestServiceContext.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/TestServiceContext.cs index ff08f19714..7cfe7df885 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/TestServiceContext.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/TestServiceContext.cs @@ -22,17 +22,16 @@ namespace Microsoft.AspNetCore.Server.KestrelTests ThreadPool = new LoggingThreadPool(Log); DateHeaderValueManager = new TestDateHeaderValueManager(); - var configuration = new ConfigurationBuilder().Build(); - ServerInformation = new KestrelServerInformation(configuration); - ServerInformation.ShutdownTimeout = TimeSpan.FromSeconds(5); + ServerOptions = new KestrelServerOptions(); + ServerOptions.ShutdownTimeout = TimeSpan.FromSeconds(5); - HttpComponentFactory = new HttpComponentFactory(ServerInformation); + HttpComponentFactory = new HttpComponentFactory(ServerOptions); } public TestServiceContext(IConnectionFilter filter) : this() { - ServerInformation.ConnectionFilter = filter; + ServerOptions.ConnectionFilter = filter; } public RequestDelegate App From f61af9a74658f95a058ddcc3690f172e82fcf5ec Mon Sep 17 00:00:00 2001 From: Pavel Krymets Date: Thu, 14 Apr 2016 15:47:59 -0700 Subject: [PATCH 0687/1662] Migrate tests, tools and samples to portable --- samples/LargeResponseApp/project.json | 12 +++++++----- samples/SampleApp/project.json | 12 +++++++----- .../project.json | 10 +++++++--- .../project.json | 7 +++++-- .../project.json | 7 +++++-- 5 files changed, 31 insertions(+), 17 deletions(-) diff --git a/samples/LargeResponseApp/project.json b/samples/LargeResponseApp/project.json index f28fba77ce..d151c46a70 100644 --- a/samples/LargeResponseApp/project.json +++ b/samples/LargeResponseApp/project.json @@ -1,17 +1,19 @@ { "version": "1.0.0-*", "dependencies": { - "Microsoft.AspNetCore.Server.Kestrel": "1.0.0-*", - "Microsoft.NETCore.Platforms": "1.0.1-*" + "Microsoft.AspNetCore.Server.Kestrel": "1.0.0-*" }, "compilationOptions": { "emitEntryPoint": true }, "frameworks": { - "dnx451": {}, - "netstandardapp1.5": { + "net451": {}, + "netcoreapp1.0": { "dependencies": { - "NETStandard.Library": "1.5.0-*" + "Microsoft.NETCore.App": { + "version": "1.0.0-*", + "type": "platform" + } }, "imports": [ "dnxcore50" diff --git a/samples/SampleApp/project.json b/samples/SampleApp/project.json index 554a04841f..8124cb3449 100644 --- a/samples/SampleApp/project.json +++ b/samples/SampleApp/project.json @@ -3,17 +3,19 @@ "dependencies": { "Microsoft.AspNetCore.Server.Kestrel": "1.0.0-*", "Microsoft.AspNetCore.Server.Kestrel.Https": "1.0.0-*", - "Microsoft.Extensions.Logging.Console": "1.0.0-*", - "Microsoft.NETCore.Platforms": "1.0.1-*" + "Microsoft.Extensions.Logging.Console": "1.0.0-*" }, "compilationOptions": { "emitEntryPoint": true }, "frameworks": { - "dnx451": {}, - "netstandardapp1.5": { + "net451": {}, + "netcoreapp1.0": { "dependencies": { - "NETStandard.Library": "1.5.0-*", + "Microsoft.NETCore.App": { + "version": "1.0.0-*", + "type": "platform" + }, "System.Console": "4.0.0-*" }, "imports": [ diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json index 326bc458a6..37adcae1d9 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json @@ -4,14 +4,18 @@ "Microsoft.AspNetCore.Http.Abstractions": "1.0.0-*", "Microsoft.AspNetCore.Server.Kestrel": "1.0.0-*", "Microsoft.AspNetCore.Testing": "1.0.0-*", - "Microsoft.NETCore.Platforms": "1.0.1-*", "xunit": "2.1.0" }, "frameworks": { - "netstandardapp1.5": { + "netcoreapp1.0": { "dependencies": { + "Microsoft.NETCore.App": { + "version": "1.0.0-*", + "type": "platform" + }, "dotnet-test-xunit": "1.0.0-dev-*", - "System.Net.Http": "4.0.1-*" + "System.Net.Http": "4.0.1-*", + "System.Runtime.Serialization.Primitives": "4.1.1-*" }, "imports": [ "dnxcore50", diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/project.json b/test/Microsoft.AspNetCore.Server.KestrelTests/project.json index 8123f3e0a2..1c4ac041c9 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/project.json +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/project.json @@ -4,12 +4,15 @@ "Microsoft.AspNetCore.Server.Kestrel": "1.0.0-*", "Microsoft.AspNetCore.Server.Kestrel.Https": "1.0.0-*", "Microsoft.AspNetCore.Testing": "1.0.0-*", - "Microsoft.NETCore.Platforms": "1.0.1-*", "xunit": "2.1.0" }, "frameworks": { - "netstandardapp1.5": { + "netcoreapp1.0": { "dependencies": { + "Microsoft.NETCore.App": { + "version": "1.0.0-*", + "type": "platform" + }, "System.Diagnostics.TraceSource": "4.0.0-*", "System.Globalization.Extensions": "4.0.1-*", "System.IO": "4.1.0-*", diff --git a/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/project.json b/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/project.json index d248f225e3..9250329b1b 100644 --- a/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/project.json +++ b/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/project.json @@ -8,9 +8,12 @@ "Microsoft.AspNetCore.Hosting": "1.0.0-*" }, "frameworks": { - "netstandardapp1.5": { + "netcoreapp1.0": { "dependencies": { - "NETStandard.Library": "1.5.0-*" + "Microsoft.NETCore.App": { + "version": "1.0.0-*", + "type": "platform" + } }, "imports": [ "dnxcore50" From c48353f4ef1150b3197246de94a343ae8d9b29d4 Mon Sep 17 00:00:00 2001 From: Chris R Date: Thu, 14 Apr 2016 14:07:11 -0700 Subject: [PATCH 0688/1662] Hosting#698 Remove IServerFactory --- .../Internal/ServerAddressesFeature.cs | 13 ----- .../KestrelServer.cs | 34 +++++------ .../ServerFactory.cs | 57 ------------------- .../WebHostBuilderKestrelExtensions.cs | 2 +- .../KestrelServerTests.cs | 23 +++----- 5 files changed, 25 insertions(+), 104 deletions(-) delete mode 100644 src/Microsoft.AspNetCore.Server.Kestrel/Internal/ServerAddressesFeature.cs delete mode 100644 src/Microsoft.AspNetCore.Server.Kestrel/ServerFactory.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/ServerAddressesFeature.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/ServerAddressesFeature.cs deleted file mode 100644 index 6294923d6f..0000000000 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/ServerAddressesFeature.cs +++ /dev/null @@ -1,13 +0,0 @@ -//// Copyright (c) .NET Foundation. All rights reserved. -//// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System.Collections.Generic; -using Microsoft.AspNetCore.Server.Features; - -namespace Microsoft.AspNetCore.Server.Kestrel.Internal -{ - public class ServerAddressesFeature : IServerAddressesFeature - { - public ICollection Addresses { get; } = new List(); - } -} diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServer.cs b/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServer.cs index 636710dd72..1a2b97f68d 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServer.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServer.cs @@ -3,13 +3,15 @@ using System; using System.Collections.Generic; +using System.Reflection; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting.Server; +using Microsoft.AspNetCore.Hosting.Server.Features; using Microsoft.AspNetCore.Http.Features; -using Microsoft.AspNetCore.Server.Features; using Microsoft.AspNetCore.Server.Kestrel.Http; using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Options; namespace Microsoft.AspNetCore.Server.Kestrel { @@ -18,14 +20,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel private Stack _disposables; private readonly IApplicationLifetime _applicationLifetime; private readonly ILogger _logger; + private readonly IServerAddressesFeature _serverAddresses; - public KestrelServer(IFeatureCollection features, KestrelServerOptions options, IApplicationLifetime applicationLifetime, ILogger logger) + public KestrelServer(IOptions options, IApplicationLifetime applicationLifetime, ILoggerFactory loggerFactory) { - if (features == null) - { - throw new ArgumentNullException(nameof(features)); - } - if (options == null) { throw new ArgumentNullException(nameof(options)); @@ -36,15 +34,19 @@ namespace Microsoft.AspNetCore.Server.Kestrel throw new ArgumentNullException(nameof(applicationLifetime)); } - if (logger == null) + if (loggerFactory == null) { - throw new ArgumentNullException(nameof(logger)); + throw new ArgumentNullException(nameof(loggerFactory)); } + Options = options.Value ?? new KestrelServerOptions(); _applicationLifetime = applicationLifetime; - _logger = logger; - Features = features; - Options = options; + _logger = loggerFactory.CreateLogger(typeof(KestrelServer).GetTypeInfo().Assembly.FullName); + Features = new FeatureCollection(); + var componentFactory = new HttpComponentFactory(Options); + Features.Set(componentFactory); + _serverAddresses = new ServerAddressesFeature(); + Features.Set(_serverAddresses); } public IFeatureCollection Features { get; } @@ -94,13 +96,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel engine.Start(threadCount); var atLeastOneListener = false; - var addressesFeature = Features.Get(); - if (addressesFeature == null) - { - throw new InvalidOperationException($"{nameof(IServerAddressesFeature)} is missing."); - } - - foreach (var address in addressesFeature.Addresses) + foreach (var address in _serverAddresses.Addresses) { var parsedAddress = ServerAddress.FromUrl(address); if (parsedAddress == null) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/ServerFactory.cs b/src/Microsoft.AspNetCore.Server.Kestrel/ServerFactory.cs deleted file mode 100644 index ada5a92948..0000000000 --- a/src/Microsoft.AspNetCore.Server.Kestrel/ServerFactory.cs +++ /dev/null @@ -1,57 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using Microsoft.AspNetCore.Hosting; -using Microsoft.AspNetCore.Hosting.Server; -using Microsoft.AspNetCore.Http.Features; -using Microsoft.AspNetCore.Server.Features; -using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; -using Microsoft.AspNetCore.Server.Kestrel.Internal; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.Logging; -using Microsoft.Extensions.Options; - -namespace Microsoft.AspNetCore.Server.Kestrel -{ - /// - /// Summary description for ServerFactory - /// - public class ServerFactory : IServerFactory - { - private readonly IApplicationLifetime _appLifetime; - private readonly ILoggerFactory _loggerFactory; - private readonly KestrelServerOptions _options; - - public ServerFactory(IApplicationLifetime appLifetime, ILoggerFactory loggerFactory, IOptions optionsAccessor) - { - _appLifetime = appLifetime; - _loggerFactory = loggerFactory; - _options = optionsAccessor.Value; - } - - public IServer CreateServer(IConfiguration configuration) - { - var componentFactory = new HttpComponentFactory(_options); - var serverFeatures = new FeatureCollection(); - serverFeatures.Set(componentFactory); - serverFeatures.Set(GetAddresses(configuration)); - return new KestrelServer(serverFeatures, _options, _appLifetime, _loggerFactory.CreateLogger("Microsoft.AspNetCore.Server.Kestrel")); - } - - private static IServerAddressesFeature GetAddresses(IConfiguration configuration) - { - var addressesFeature = new ServerAddressesFeature(); - var urls = configuration["server.urls"]; - if (!string.IsNullOrEmpty(urls)) - { - foreach (var value in urls.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries)) - { - addressesFeature.Addresses.Add(value); - } - } - return addressesFeature; - } - - } -} diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/WebHostBuilderKestrelExtensions.cs b/src/Microsoft.AspNetCore.Server.Kestrel/WebHostBuilderKestrelExtensions.cs index 7632647d03..edebf2a94b 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/WebHostBuilderKestrelExtensions.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/WebHostBuilderKestrelExtensions.cs @@ -23,7 +23,7 @@ namespace Microsoft.AspNetCore.Hosting /// public static IWebHostBuilder UseKestrel(this IWebHostBuilder hostBuilder) { - return hostBuilder.ConfigureServices(services => services.AddSingleton()); + return hostBuilder.ConfigureServices(services => services.AddSingleton()); } /// diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerTests.cs index 89b828f468..7db58f52a6 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerTests.cs @@ -3,11 +3,13 @@ using System; using Microsoft.AspNetCore.Hosting.Server; +using Microsoft.AspNetCore.Hosting.Server.Features; using Microsoft.AspNetCore.Http.Features; -using Microsoft.AspNetCore.Server.Features; using Microsoft.AspNetCore.Server.Kestrel; using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Internal; +using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Options; using Xunit; namespace Microsoft.AspNetCore.Server.KestrelTests @@ -29,9 +31,8 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [Fact] public void StartWithInvalidAddressThrows() { - var addressesFeature = new ServerAddressesFeature(); - addressesFeature.Addresses.Add("http:/asdf"); - var server = CreateServer(new KestrelServerOptions(), addressesFeature); + var server = CreateServer(new KestrelServerOptions()); + server.Features.Get().Addresses.Add("http:/asdf"); var exception = Assert.Throws(() => StartDummyApplication(server)); @@ -41,25 +42,19 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [Fact] public void StartWithEmptyAddressesThrows() { - var server = CreateServer(new KestrelServerOptions(), new ServerAddressesFeature()); + var server = CreateServer(new KestrelServerOptions()); var exception = Assert.Throws(() => StartDummyApplication(server)); Assert.Equal("No recognized listening addresses were configured.", exception.Message); } - private static KestrelServer CreateServer(KestrelServerOptions options, IServerAddressesFeature addressesFeature = null) + private static KestrelServer CreateServer(KestrelServerOptions options) { - var features = new FeatureCollection(); - if (addressesFeature != null) - { - features.Set(addressesFeature); - } - var lifetime = new LifetimeNotImplemented(); - var logger = new TestApplicationErrorLogger(); + var logger = new LoggerFactory(); - return new KestrelServer(features, options, lifetime, logger); + return new KestrelServer(Options.Create(options), lifetime, logger); } private static void StartDummyApplication(IServer server) From bbf2c83a7dd427a4101a6ec6f11ea0a736032e25 Mon Sep 17 00:00:00 2001 From: Mike Harder Date: Mon, 18 Apr 2016 15:32:09 -0700 Subject: [PATCH 0689/1662] Add KestrelServerOptionsSetup to IServiceCollection in UseKestrel() (#755) - Previously, KestrelServerOptionsSetup was only added to IServiceCollection in UseKestrel(options) - Required to ensure that options.ApplicationServices is available after calling UseKestrel() --- .../WebHostBuilderKestrelExtensions.cs | 7 ++-- .../WebHostBuilderKestrelExtensionsTests.cs | 35 +++++++++++++++++++ 2 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 test/Microsoft.AspNetCore.Server.KestrelTests/WebHostBuilderKestrelExtensionsTests.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/WebHostBuilderKestrelExtensions.cs b/src/Microsoft.AspNetCore.Server.Kestrel/WebHostBuilderKestrelExtensions.cs index edebf2a94b..44c733b776 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/WebHostBuilderKestrelExtensions.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/WebHostBuilderKestrelExtensions.cs @@ -23,7 +23,11 @@ namespace Microsoft.AspNetCore.Hosting /// public static IWebHostBuilder UseKestrel(this IWebHostBuilder hostBuilder) { - return hostBuilder.ConfigureServices(services => services.AddSingleton()); + return hostBuilder.ConfigureServices(services => + { + services.AddTransient, KestrelServerOptionsSetup>(); + services.AddSingleton(); + }); } /// @@ -42,7 +46,6 @@ namespace Microsoft.AspNetCore.Hosting { hostBuilder.ConfigureServices(services => { - services.AddTransient, KestrelServerOptionsSetup>(); services.Configure(options); }); diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/WebHostBuilderKestrelExtensionsTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/WebHostBuilderKestrelExtensionsTests.cs new file mode 100644 index 0000000000..7253c4a465 --- /dev/null +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/WebHostBuilderKestrelExtensionsTests.cs @@ -0,0 +1,35 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Server.Kestrel; +using Microsoft.Extensions.DependencyInjection; +using Xunit; + +namespace Microsoft.AspNetCore.Server.KestrelTests +{ + public class WebHostBuilderKestrelExtensionsTests + { + [Fact] + public void ApplicationServicesNotNullAfterUseKestrelWithoutOptions() + { + // Arrange + var hostBuilder = new WebHostBuilder() + .UseKestrel() + .Configure(app => { }); + + hostBuilder.ConfigureServices(services => + { + services.Configure(options => + { + // Assert + Assert.NotNull(options.ApplicationServices); + }); + }); + + // Act + var host = hostBuilder.Build(); + } + } +} From 0453e4af703b0761a1bb004b2d5069ad4a26f31e Mon Sep 17 00:00:00 2001 From: Mike Harder Date: Mon, 18 Apr 2016 16:57:59 -0700 Subject: [PATCH 0690/1662] Add KestrelServerOptionsSetup before KestrelServerOptions (#755) (#757) - Required to ensure that options.ApplicationServices is available after during UseKestrel(options) --- .../WebHostBuilderKestrelExtensions.cs | 4 +--- .../WebHostBuilderKestrelExtensionsTests.cs | 18 +++++++++++++++++- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/WebHostBuilderKestrelExtensions.cs b/src/Microsoft.AspNetCore.Server.Kestrel/WebHostBuilderKestrelExtensions.cs index 44c733b776..8d26d2deaa 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/WebHostBuilderKestrelExtensions.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/WebHostBuilderKestrelExtensions.cs @@ -44,12 +44,10 @@ namespace Microsoft.AspNetCore.Hosting /// public static IWebHostBuilder UseKestrel(this IWebHostBuilder hostBuilder, Action options) { - hostBuilder.ConfigureServices(services => + return hostBuilder.UseKestrel().ConfigureServices(services => { services.Configure(options); }); - - return hostBuilder.UseKestrel(); } } } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/WebHostBuilderKestrelExtensionsTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/WebHostBuilderKestrelExtensionsTests.cs index 7253c4a465..12e1d9e350 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/WebHostBuilderKestrelExtensionsTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/WebHostBuilderKestrelExtensionsTests.cs @@ -29,7 +29,23 @@ namespace Microsoft.AspNetCore.Server.KestrelTests }); // Act - var host = hostBuilder.Build(); + hostBuilder.Build(); + } + + [Fact] + public void ApplicationServicesNotNullDuringUseKestrelWithOptions() + { + // Arrange + var hostBuilder = new WebHostBuilder() + .UseKestrel(options => + { + // Assert + Assert.NotNull(options.ApplicationServices); + }) + .Configure(app => { }); + + // Act + hostBuilder.Build(); } } } From 5273e0e768b82d3dfb8c6de3e297f7e9848bd96c Mon Sep 17 00:00:00 2001 From: Pavel Krymets Date: Mon, 18 Apr 2016 17:01:20 -0700 Subject: [PATCH 0691/1662] Bring Microsoft.NETCore.Platforms dependency back --- samples/LargeResponseApp/project.json | 1 + samples/SampleApp/project.json | 1 + .../project.json | 1 + test/Microsoft.AspNetCore.Server.KestrelTests/project.json | 1 + .../project.json | 1 + 5 files changed, 5 insertions(+) diff --git a/samples/LargeResponseApp/project.json b/samples/LargeResponseApp/project.json index d151c46a70..6a7fff4784 100644 --- a/samples/LargeResponseApp/project.json +++ b/samples/LargeResponseApp/project.json @@ -1,6 +1,7 @@ { "version": "1.0.0-*", "dependencies": { + "Microsoft.NETCore.Platforms": "1.0.1-*", "Microsoft.AspNetCore.Server.Kestrel": "1.0.0-*" }, "compilationOptions": { diff --git a/samples/SampleApp/project.json b/samples/SampleApp/project.json index 8124cb3449..846c49eb07 100644 --- a/samples/SampleApp/project.json +++ b/samples/SampleApp/project.json @@ -1,6 +1,7 @@ { "version": "1.0.0-*", "dependencies": { + "Microsoft.NETCore.Platforms": "1.0.1-*", "Microsoft.AspNetCore.Server.Kestrel": "1.0.0-*", "Microsoft.AspNetCore.Server.Kestrel.Https": "1.0.0-*", "Microsoft.Extensions.Logging.Console": "1.0.0-*" diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json index 37adcae1d9..8c48b84f24 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json @@ -1,6 +1,7 @@ { "version": "1.0.0-*", "dependencies": { + "Microsoft.NETCore.Platforms": "1.0.1-*", "Microsoft.AspNetCore.Http.Abstractions": "1.0.0-*", "Microsoft.AspNetCore.Server.Kestrel": "1.0.0-*", "Microsoft.AspNetCore.Testing": "1.0.0-*", diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/project.json b/test/Microsoft.AspNetCore.Server.KestrelTests/project.json index 1c4ac041c9..53448f33b3 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/project.json +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/project.json @@ -1,6 +1,7 @@ { "version": "1.0.0-*", "dependencies": { + "Microsoft.NETCore.Platforms": "1.0.1-*", "Microsoft.AspNetCore.Server.Kestrel": "1.0.0-*", "Microsoft.AspNetCore.Server.Kestrel.Https": "1.0.0-*", "Microsoft.AspNetCore.Testing": "1.0.0-*", diff --git a/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/project.json b/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/project.json index 9250329b1b..03b787a99e 100644 --- a/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/project.json +++ b/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/project.json @@ -4,6 +4,7 @@ "emitEntryPoint": true }, "dependencies": { + "Microsoft.NETCore.Platforms": "1.0.1-*", "Microsoft.AspNetCore.Http.Features": "1.0.0-*", "Microsoft.AspNetCore.Hosting": "1.0.0-*" }, From 33ad35511463eec4e95f7ee0f1176afc2379e9cc Mon Sep 17 00:00:00 2001 From: Pranav K Date: Tue, 19 Apr 2016 14:54:04 -0700 Subject: [PATCH 0692/1662] Use latest build of dotnet-test-xunit --- .../project.json | 2 +- test/Microsoft.AspNetCore.Server.KestrelTests/project.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json index 8c48b84f24..f925e40df7 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json @@ -14,7 +14,7 @@ "version": "1.0.0-*", "type": "platform" }, - "dotnet-test-xunit": "1.0.0-dev-*", + "dotnet-test-xunit": "1.0.0-*", "System.Net.Http": "4.0.1-*", "System.Runtime.Serialization.Primitives": "4.1.1-*" }, diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/project.json b/test/Microsoft.AspNetCore.Server.KestrelTests/project.json index 53448f33b3..44cbe4df45 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/project.json +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/project.json @@ -21,7 +21,7 @@ "System.Net.Http.WinHttpHandler": "4.0.0-*", "System.Net.Sockets": "4.1.0-*", "System.Runtime.Handles": "4.0.1-*", - "dotnet-test-xunit": "1.0.0-dev-*" + "dotnet-test-xunit": "1.0.0-*" }, "imports": [ "dnxcore50", From f29dd60999a2800cd2d2901b72ef29d3271d1a01 Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Sun, 10 Apr 2016 21:14:08 -0700 Subject: [PATCH 0693/1662] Fix connection termination issues when using connection filters (#737, #747). - If we're done before the client sends a FIN, force a FIN into the raw SocketInput so the task in FileteredStreamAdapter finishes gracefully and we dispose everything in proper order. - If there's an error while writing to a stream (like ObjectDisposedException), log it once and prevent further write attempts. This means the client closed the connection while we were still writing output. - This also fixes a bug related to the point above, where memory blocks were being leaked instead of returned to the pool (because we weren't catching the exception from Write()). --- .../Filter/FilteredStreamAdapter.cs | 27 ++++++-- .../Filter/SocketInputStream.cs | 2 +- .../Filter/StreamSocketOutput.cs | 68 ++++++++++++++++--- .../Http/Connection.cs | 29 +++++--- .../Http/SocketInput.cs | 6 ++ .../ChunkedResponseTests.cs | 59 +++++++++++----- .../EngineTests.cs | 32 +++++++++ .../StreamSocketOutputTests.cs | 2 +- .../TestHelpers/TestApplicationErrorLogger.cs | 7 +- 9 files changed, 185 insertions(+), 47 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Filter/FilteredStreamAdapter.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Filter/FilteredStreamAdapter.cs index 2fa981ceb4..357f6175f8 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Filter/FilteredStreamAdapter.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Filter/FilteredStreamAdapter.cs @@ -10,23 +10,27 @@ using Microsoft.Extensions.Logging; namespace Microsoft.AspNetCore.Server.Kestrel.Filter { - public class FilteredStreamAdapter + public class FilteredStreamAdapter : IDisposable { + private readonly string _connectionId; private readonly Stream _filteredStream; private readonly Stream _socketInputStream; private readonly IKestrelTrace _log; private readonly MemoryPool _memory; private MemoryPoolBlock _block; + private bool _aborted = false; public FilteredStreamAdapter( + string connectionId, Stream filteredStream, MemoryPool memory, IKestrelTrace logger, IThreadPool threadPool) { SocketInput = new SocketInput(memory, threadPool); - SocketOutput = new StreamSocketOutput(filteredStream, memory); + SocketOutput = new StreamSocketOutput(connectionId, filteredStream, memory, logger); + _connectionId = connectionId; _log = logger; _filteredStream = filteredStream; _socketInputStream = new SocketInputStream(SocketInput); @@ -37,16 +41,26 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Filter public ISocketOutput SocketOutput { get; private set; } - public void ReadInput() + public Task ReadInputAsync() { _block = _memory.Lease(); // Use pooled block for copy - _filteredStream.CopyToAsync(_socketInputStream, _block).ContinueWith((task, state) => + return _filteredStream.CopyToAsync(_socketInputStream, _block).ContinueWith((task, state) => { ((FilteredStreamAdapter)state).OnStreamClose(task); }, this); } + public void Abort() + { + _aborted = true; + } + + public void Dispose() + { + SocketInput.Dispose(); + } + private void OnStreamClose(Task copyAsyncTask) { _memory.Return(_block); @@ -61,10 +75,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Filter SocketInput.AbortAwaiting(); _log.LogError("FilteredStreamAdapter.CopyToAsync canceled."); } + else if (_aborted) + { + SocketInput.AbortAwaiting(); + } try { - _filteredStream.Dispose(); _socketInputStream.Dispose(); } catch (Exception ex) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Filter/SocketInputStream.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Filter/SocketInputStream.cs index b10b1f9c69..d2d90b2f2d 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Filter/SocketInputStream.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Filter/SocketInputStream.cs @@ -86,7 +86,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Filter protected override void Dispose(bool disposing) { // Close _socketInput with a fake zero-length write that will result in a zero-length read. - _socketInput.IncomingData(null, 0, 0); + _socketInput.IncomingFin(); base.Dispose(disposing); } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Filter/StreamSocketOutput.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Filter/StreamSocketOutput.cs index 7460cefdb1..f9ba1e42e0 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Filter/StreamSocketOutput.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Filter/StreamSocketOutput.cs @@ -16,33 +16,57 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Filter private static readonly byte[] _endChunkBytes = Encoding.ASCII.GetBytes("\r\n"); private static readonly byte[] _nullBuffer = new byte[0]; + private readonly string _connectionId; private readonly Stream _outputStream; private readonly MemoryPool _memory; + private readonly IKestrelTrace _logger; private MemoryPoolBlock _producingBlock; + private bool _canWrite = true; + private object _writeLock = new object(); - public StreamSocketOutput(Stream outputStream, MemoryPool memory) + public StreamSocketOutput(string connectionId, Stream outputStream, MemoryPool memory, IKestrelTrace logger) { + _connectionId = connectionId; _outputStream = outputStream; _memory = memory; + _logger = logger; } public void Write(ArraySegment buffer, bool chunk) { lock (_writeLock) { - if (chunk && buffer.Array != null) + if (buffer.Count == 0 ) { - var beginChunkBytes = ChunkWriter.BeginChunkBytes(buffer.Count); - _outputStream.Write(beginChunkBytes.Array, beginChunkBytes.Offset, beginChunkBytes.Count); + return; } - _outputStream.Write(buffer.Array ?? _nullBuffer, buffer.Offset, buffer.Count); - - if (chunk && buffer.Array != null) + try { - _outputStream.Write(_endChunkBytes, 0, _endChunkBytes.Length); + if (!_canWrite) + { + return; + } + + if (chunk && buffer.Array != null) + { + var beginChunkBytes = ChunkWriter.BeginChunkBytes(buffer.Count); + _outputStream.Write(beginChunkBytes.Array, beginChunkBytes.Offset, beginChunkBytes.Count); + } + + _outputStream.Write(buffer.Array ?? _nullBuffer, buffer.Offset, buffer.Count); + + if (chunk && buffer.Array != null) + { + _outputStream.Write(_endChunkBytes, 0, _endChunkBytes.Length); + } + } + catch (Exception ex) + { + _canWrite = false; + _logger.ConnectionError(_connectionId, ex); } } } @@ -65,14 +89,38 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Filter var block = _producingBlock; while (block != end.Block) { - _outputStream.Write(block.Data.Array, block.Data.Offset, block.Data.Count); + // If we don't handle an exception from _outputStream.Write() here, we'll leak memory blocks. + if (_canWrite) + { + try + { + _outputStream.Write(block.Data.Array, block.Data.Offset, block.Data.Count); + } + catch (Exception ex) + { + _canWrite = false; + _logger.ConnectionError(_connectionId, ex); + } + } var returnBlock = block; block = block.Next; returnBlock.Pool.Return(returnBlock); } + + if (_canWrite) + { + try + { + _outputStream.Write(end.Block.Array, end.Block.Data.Offset, end.Index - end.Block.Data.Offset); + } + catch (Exception ex) + { + _canWrite = false; + _logger.ConnectionError(_connectionId, ex); + } + } - _outputStream.Write(end.Block.Array, end.Block.Data.Offset, end.Index - end.Block.Data.Offset); end.Block.Pool.Return(end.Block); } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Connection.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Connection.cs index 71a40284b0..83ede18be7 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Connection.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Connection.cs @@ -30,6 +30,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http private Frame _frame; private ConnectionFilterContext _filterContext; private LibuvStream _libuvStream; + private FilteredStreamAdapter _filteredStreamAdapter; + private Task _readInputContinuation; private readonly SocketInput _rawSocketInput; private readonly SocketOutput _rawSocketOutput; @@ -175,13 +177,20 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http // Called on Libuv thread public virtual void OnSocketClosed() { - _rawSocketInput.Dispose(); - - // If a connection filter was applied there will be two SocketInputs. - // If a connection filter failed, SocketInput will be null. - if (SocketInput != null && SocketInput != _rawSocketInput) + if (_filteredStreamAdapter != null) { - SocketInput.Dispose(); + _filteredStreamAdapter.Abort(); + _rawSocketInput.IncomingFin(); + _readInputContinuation.ContinueWith((task, state) => + { + ((Connection)state)._filterContext.Connection.Dispose(); + ((Connection)state)._filteredStreamAdapter.Dispose(); + ((Connection)state)._rawSocketInput.Dispose(); + }, this); + } + else + { + _rawSocketInput.Dispose(); } lock (_stateLock) @@ -207,12 +216,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if (_filterContext.Connection != _libuvStream) { - var filteredStreamAdapter = new FilteredStreamAdapter(_filterContext.Connection, Memory, Log, ThreadPool); + _filteredStreamAdapter = new FilteredStreamAdapter(ConnectionId, _filterContext.Connection, Memory, Log, ThreadPool); - SocketInput = filteredStreamAdapter.SocketInput; - SocketOutput = filteredStreamAdapter.SocketOutput; + SocketInput = _filteredStreamAdapter.SocketInput; + SocketOutput = _filteredStreamAdapter.SocketOutput; - filteredStreamAdapter.ReadInput(); + _readInputContinuation = _filteredStreamAdapter.ReadInputAsync(); } else { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketInput.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketInput.cs index f57d3f6289..1588e83011 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketInput.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketInput.cs @@ -140,6 +140,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } + public void IncomingFin() + { + // Force a FIN + IncomingData(null, 0, 0); + } + private void Complete() { var awaitableState = Interlocked.Exchange( diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedResponseTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedResponseTests.cs index 59b2e16e10..fd4035cc3a 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedResponseTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedResponseTests.cs @@ -5,14 +5,32 @@ using System; using System.Text; using System.Threading; using System.Threading.Tasks; +using Microsoft.AspNetCore.Server.Kestrel; using Xunit; namespace Microsoft.AspNetCore.Server.KestrelTests { public class ChunkedResponseTests { - [Fact] - public async Task ResponsesAreChunkedAutomatically() + public static TheoryData ConnectionFilterData + { + get + { + return new TheoryData + { + { + new TestServiceContext() + }, + { + new TestServiceContext(new PassThroughConnectionFilter()) + } + }; + } + } + + [Theory] + [MemberData(nameof(ConnectionFilterData))] + public async Task ResponsesAreChunkedAutomatically(ServiceContext testContext) { using (var server = new TestServer(async httpContext => { @@ -20,7 +38,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests response.Headers.Clear(); await response.Body.WriteAsync(Encoding.ASCII.GetBytes("Hello "), 0, 6); await response.Body.WriteAsync(Encoding.ASCII.GetBytes("World!"), 0, 6); - })) + }, testContext)) { using (var connection = new TestConnection(server.Port)) { @@ -43,8 +61,9 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } } - [Fact] - public async Task ZeroLengthWritesAreIgnored() + [Theory] + [MemberData(nameof(ConnectionFilterData))] + public async Task ZeroLengthWritesAreIgnored(ServiceContext testContext) { using (var server = new TestServer(async httpContext => { @@ -53,7 +72,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests await response.Body.WriteAsync(Encoding.ASCII.GetBytes("Hello "), 0, 6); await response.Body.WriteAsync(new byte[0], 0, 0); await response.Body.WriteAsync(Encoding.ASCII.GetBytes("World!"), 0, 6); - })) + }, testContext)) { using (var connection = new TestConnection(server.Port)) { @@ -76,15 +95,16 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } } - [Fact] - public async Task EmptyResponseBodyHandledCorrectlyWithZeroLengthWrite() + [Theory] + [MemberData(nameof(ConnectionFilterData))] + public async Task EmptyResponseBodyHandledCorrectlyWithZeroLengthWrite(ServiceContext testContext) { using (var server = new TestServer(async httpContext => { var response = httpContext.Response; response.Headers.Clear(); await response.Body.WriteAsync(new byte[0], 0, 0); - })) + }, testContext)) { using (var connection = new TestConnection(server.Port)) { @@ -103,8 +123,9 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } } - [Fact] - public async Task ConnectionClosedIfExeptionThrownAfterWrite() + [Theory] + [MemberData(nameof(ConnectionFilterData))] + public async Task ConnectionClosedIfExeptionThrownAfterWrite(ServiceContext testContext) { using (var server = new TestServer(async httpContext => { @@ -112,7 +133,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests response.Headers.Clear(); await response.Body.WriteAsync(Encoding.ASCII.GetBytes("Hello World!"), 0, 12); throw new Exception(); - })) + }, testContext)) { using (var connection = new TestConnection(server.Port)) { @@ -133,8 +154,9 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } } - [Fact] - public async Task ConnectionClosedIfExeptionThrownAfterZeroLengthWrite() + [Theory] + [MemberData(nameof(ConnectionFilterData))] + public async Task ConnectionClosedIfExeptionThrownAfterZeroLengthWrite(ServiceContext testContext) { using (var server = new TestServer(async httpContext => { @@ -142,7 +164,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests response.Headers.Clear(); await response.Body.WriteAsync(new byte[0], 0, 0); throw new Exception(); - })) + }, testContext)) { using (var connection = new TestConnection(server.Port)) { @@ -162,8 +184,9 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } } - [Fact] - public async Task WritesAreFlushedPriorToResponseCompletion() + [Theory] + [MemberData(nameof(ConnectionFilterData))] + public async Task WritesAreFlushedPriorToResponseCompletion(ServiceContext testContext) { var flushWh = new ManualResetEventSlim(); @@ -177,7 +200,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests flushWh.Wait(); await response.Body.WriteAsync(Encoding.ASCII.GetBytes("World!"), 0, 6); - })) + }, testContext)) { using (var connection = new TestConnection(server.Port)) { diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs index c068803b40..aadf9361c1 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs @@ -1018,5 +1018,37 @@ namespace Microsoft.AspNetCore.Server.KestrelTests Assert.True(registrationWh.Wait(1000)); } } + + [Theory] + [MemberData(nameof(ConnectionFilterData))] + public async Task NoErrorsLoggedWhenServerEndsConnectionBeforeClient(ServiceContext testContext) + { + var testLogger = new TestApplicationErrorLogger(); + testContext.Log = new KestrelTrace(testLogger); + + using (var server = new TestServer(async httpContext => + { + var response = httpContext.Response; + response.Headers.Clear(); + response.Headers["Content-Length"] = new[] { "11" }; + await response.Body.WriteAsync(Encoding.ASCII.GetBytes("Hello World"), 0, 11); + }, testContext)) + { + using (var connection = new TestConnection(server.Port)) + { + await connection.Send( + "GET / HTTP/1.0", + "", + ""); + await connection.ReceiveForcedEnd( + "HTTP/1.0 200 OK", + "Content-Length: 11", + "", + "Hello World"); + } + } + + Assert.Equal(0, testLogger.TotalErrorsLogged); + } } } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/StreamSocketOutputTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/StreamSocketOutputTests.cs index e787ed8589..46c0384f30 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/StreamSocketOutputTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/StreamSocketOutputTests.cs @@ -19,7 +19,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests // As it calls ProduceStart with write immediate == true // This happens in WebSocket Upgrade over SSL - ISocketOutput socketOutput = new StreamSocketOutput(new ThrowsOnNullWriteStream(), null); + ISocketOutput socketOutput = new StreamSocketOutput("id", new ThrowsOnNullWriteStream(), null, new TestKestrelTrace()); // Should not throw socketOutput.Write(default(ArraySegment), true); diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/TestApplicationErrorLogger.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/TestApplicationErrorLogger.cs index de8d462ed9..ea02bb3c64 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/TestApplicationErrorLogger.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/TestApplicationErrorLogger.cs @@ -32,12 +32,15 @@ namespace Microsoft.AspNetCore.Server.KestrelTests Console.WriteLine($"Log {logLevel}[{eventId}]: {formatter(state, exception)} {exception?.Message}"); #endif - TotalErrorsLogged++; - if (eventId.Id == ApplicationErrorEventId) { ApplicationErrorsLogged++; } + + if (logLevel == LogLevel.Error) + { + TotalErrorsLogged++; + } } } } From 95722670c14855e3d5a59d482f01b9b38ed9dff1 Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Wed, 20 Apr 2016 17:25:50 -0700 Subject: [PATCH 0694/1662] More robust port assignment for tests. --- .../PortManager.cs | 4 +- .../project.json | 1 + .../PortManager.cs | 38 +++++++++++++++++++ .../project.json | 18 +++++++++ .../TestServer.cs | 5 +-- .../project.json | 1 + 6 files changed, 61 insertions(+), 6 deletions(-) create mode 100644 test/Microsoft.AspNetCore.Server.Kestrel.TestCommon/PortManager.cs create mode 100644 test/Microsoft.AspNetCore.Server.Kestrel.TestCommon/project.json diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/PortManager.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/PortManager.cs index 55ba3577df..62e019d4be 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/PortManager.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/PortManager.cs @@ -7,11 +7,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { public static class PortManager { - private static int _nextPort = 8001; - public static int GetPort() { - return Interlocked.Increment(ref _nextPort); + return TestCommon.PortManager.GetNextPort(); } } } diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json index f925e40df7..5eab8dffcd 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json @@ -4,6 +4,7 @@ "Microsoft.NETCore.Platforms": "1.0.1-*", "Microsoft.AspNetCore.Http.Abstractions": "1.0.0-*", "Microsoft.AspNetCore.Server.Kestrel": "1.0.0-*", + "Microsoft.AspNetCore.Server.Kestrel.TestCommon": "1.0.0-*", "Microsoft.AspNetCore.Testing": "1.0.0-*", "xunit": "2.1.0" }, diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.TestCommon/PortManager.cs b/test/Microsoft.AspNetCore.Server.Kestrel.TestCommon/PortManager.cs new file mode 100644 index 0000000000..a90f229963 --- /dev/null +++ b/test/Microsoft.AspNetCore.Server.Kestrel.TestCommon/PortManager.cs @@ -0,0 +1,38 @@ +using System.Net; +using System.Net.Sockets; + +namespace Microsoft.AspNetCore.Server.Kestrel.TestCommon +{ + public static class PortManager + { + public static int _nextPort = 8001; + public static object _portLock = new object(); + + public static int GetNextPort() + { + lock (_portLock) + { + using (var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)) + { + while (true) + { + try + { + var port = _nextPort++; + socket.Bind(new IPEndPoint(IPAddress.Loopback, port)); + return port; + } + catch (SocketException) + { + // Retry unless exhausted + if (_nextPort == 65536) + { + throw; + } + } + } + } + } + } + } +} \ No newline at end of file diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.TestCommon/project.json b/test/Microsoft.AspNetCore.Server.Kestrel.TestCommon/project.json new file mode 100644 index 0000000000..2795fb5773 --- /dev/null +++ b/test/Microsoft.AspNetCore.Server.Kestrel.TestCommon/project.json @@ -0,0 +1,18 @@ +{ + "version": "1.0.0-*", + "frameworks": { + "net451": { }, + "netstandard1.3": { + "dependencies": { + "System.Threading": "4.0.11-*", + "System.Net.Sockets": "4.1.0-*" + }, + "imports": [ + "portable-net45+win8" + ] + } + }, + "compilationOptions": { + "keyFile": "../../tools/Key.snk" + } +} \ No newline at end of file diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestServer.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/TestServer.cs index 2e51e27b3e..69b876cbf1 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/TestServer.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/TestServer.cs @@ -6,6 +6,7 @@ using System.Threading; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Server.Kestrel; using Microsoft.AspNetCore.Server.Kestrel.Http; +using Microsoft.AspNetCore.Server.Kestrel.TestCommon; namespace Microsoft.AspNetCore.Server.KestrelTests { @@ -14,8 +15,6 @@ namespace Microsoft.AspNetCore.Server.KestrelTests /// public class TestServer : IDisposable { - private static int _nextPort = 9001; - private KestrelEngine _engine; private IDisposable _server; ServerAddress _address; @@ -62,7 +61,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests public static int GetNextPort() { - return Interlocked.Increment(ref _nextPort); + return PortManager.GetNextPort(); } } } \ No newline at end of file diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/project.json b/test/Microsoft.AspNetCore.Server.KestrelTests/project.json index 44cbe4df45..c0237faec2 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/project.json +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/project.json @@ -4,6 +4,7 @@ "Microsoft.NETCore.Platforms": "1.0.1-*", "Microsoft.AspNetCore.Server.Kestrel": "1.0.0-*", "Microsoft.AspNetCore.Server.Kestrel.Https": "1.0.0-*", + "Microsoft.AspNetCore.Server.Kestrel.TestCommon": "1.0.0-*", "Microsoft.AspNetCore.Testing": "1.0.0-*", "xunit": "2.1.0" }, From 00ee2145fcc4630d8dbd4fef38831c0aa62dbf73 Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Thu, 21 Apr 2016 14:51:37 -0700 Subject: [PATCH 0695/1662] Add xproj for Microsoft.AspNetCore.Server.Kestrel.TestCommon. --- KestrelHttpServer.sln | 10 ++++++++-- ...t.AspNetCore.Server.Kestrel.TestCommon.xproj | 17 +++++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 test/Microsoft.AspNetCore.Server.Kestrel.TestCommon/Microsoft.AspNetCore.Server.Kestrel.TestCommon.xproj diff --git a/KestrelHttpServer.sln b/KestrelHttpServer.sln index b673fbe198..4a215770d9 100644 --- a/KestrelHttpServer.sln +++ b/KestrelHttpServer.sln @@ -1,7 +1,6 @@ - Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 14 -VisualStudioVersion = 14.0.24709.0 +VisualStudioVersion = 14.0.25123.0 MinimumVisualStudioVersion = 10.0.40219.1 Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNetCore.Server.Kestrel", "src\Microsoft.AspNetCore.Server.Kestrel\Microsoft.AspNetCore.Server.Kestrel.xproj", "{F510611A-3BEE-4B88-A613-5F4A74ED82A1}" EndProject @@ -35,6 +34,8 @@ Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNetCore.Server EndProject Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNetCore.Server.Kestrel.FunctionalTests", "test\Microsoft.AspNetCore.Server.Kestrel.FunctionalTests\Microsoft.AspNetCore.Server.Kestrel.FunctionalTests.xproj", "{9559A5F1-080C-4909-B6CF-7E4B3DC55748}" EndProject +Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNetCore.Server.Kestrel.TestCommon", "test\Microsoft.AspNetCore.Server.Kestrel.TestCommon\Microsoft.AspNetCore.Server.Kestrel.TestCommon.xproj", "{A485B4F9-0392-478C-B19A-F4DE6B17F491}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -73,6 +74,10 @@ Global {9559A5F1-080C-4909-B6CF-7E4B3DC55748}.Debug|Any CPU.Build.0 = Debug|Any CPU {9559A5F1-080C-4909-B6CF-7E4B3DC55748}.Release|Any CPU.ActiveCfg = Release|Any CPU {9559A5F1-080C-4909-B6CF-7E4B3DC55748}.Release|Any CPU.Build.0 = Release|Any CPU + {A485B4F9-0392-478C-B19A-F4DE6B17F491}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A485B4F9-0392-478C-B19A-F4DE6B17F491}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A485B4F9-0392-478C-B19A-F4DE6B17F491}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A485B4F9-0392-478C-B19A-F4DE6B17F491}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -86,5 +91,6 @@ Global {8CBA6FE3-3CC9-4420-8AA3-123E983734C2} = {327F7880-D9AF-46BD-B45C-3B7E34A01DFD} {5F64B3C3-0C2E-431A-B820-A81BBFC863DA} = {2D5D5227-4DBD-499A-96B1-76A36B03B750} {9559A5F1-080C-4909-B6CF-7E4B3DC55748} = {D3273454-EA07-41D2-BF0B-FCC3675C2483} + {A485B4F9-0392-478C-B19A-F4DE6B17F491} = {D3273454-EA07-41D2-BF0B-FCC3675C2483} EndGlobalSection EndGlobal diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.TestCommon/Microsoft.AspNetCore.Server.Kestrel.TestCommon.xproj b/test/Microsoft.AspNetCore.Server.Kestrel.TestCommon/Microsoft.AspNetCore.Server.Kestrel.TestCommon.xproj new file mode 100644 index 0000000000..fbee634344 --- /dev/null +++ b/test/Microsoft.AspNetCore.Server.Kestrel.TestCommon/Microsoft.AspNetCore.Server.Kestrel.TestCommon.xproj @@ -0,0 +1,17 @@ + + + + 14.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + + + + a485b4f9-0392-478c-b19a-f4de6b17f491 + ..\..\artifacts\obj\$(MSBuildProjectName) + ..\..\artifacts\bin\ + + + 2.0 + + + \ No newline at end of file From 179b57b01f73b7b10ddce87cd0e57d196922462b Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Thu, 21 Apr 2016 14:35:55 -0700 Subject: [PATCH 0696/1662] Remove SocketInputStream (#753). --- .../Filter/FilteredStreamAdapter.cs | 15 ++- .../Filter/SocketInputStream.cs | 93 ------------------- .../Filter/StreamExtensions.cs | 21 ----- .../Http/Connection.cs | 6 +- 4 files changed, 14 insertions(+), 121 deletions(-) delete mode 100644 src/Microsoft.AspNetCore.Server.Kestrel/Filter/SocketInputStream.cs delete mode 100644 src/Microsoft.AspNetCore.Server.Kestrel/Filter/StreamExtensions.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Filter/FilteredStreamAdapter.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Filter/FilteredStreamAdapter.cs index 357f6175f8..8c721c5f91 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Filter/FilteredStreamAdapter.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Filter/FilteredStreamAdapter.cs @@ -14,7 +14,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Filter { private readonly string _connectionId; private readonly Stream _filteredStream; - private readonly Stream _socketInputStream; private readonly IKestrelTrace _log; private readonly MemoryPool _memory; private MemoryPoolBlock _block; @@ -33,7 +32,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Filter _connectionId = connectionId; _log = logger; _filteredStream = filteredStream; - _socketInputStream = new SocketInputStream(SocketInput); _memory = memory; } @@ -45,7 +43,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Filter { _block = _memory.Lease(); // Use pooled block for copy - return _filteredStream.CopyToAsync(_socketInputStream, _block).ContinueWith((task, state) => + return FilterInputAsync(_block).ContinueWith((task, state) => { ((FilteredStreamAdapter)state).OnStreamClose(task); }, this); @@ -60,6 +58,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Filter { SocketInput.Dispose(); } + + private async Task FilterInputAsync(MemoryPoolBlock block) + { + int bytesRead; + while ((bytesRead = await _filteredStream.ReadAsync(block.Array, block.Data.Offset, block.Data.Count)) != 0) + { + SocketInput.IncomingData(block.Array, block.Data.Offset, bytesRead); + } + } private void OnStreamClose(Task copyAsyncTask) { @@ -82,7 +89,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Filter try { - _socketInputStream.Dispose(); + SocketInput.IncomingFin(); } catch (Exception ex) { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Filter/SocketInputStream.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Filter/SocketInputStream.cs deleted file mode 100644 index d2d90b2f2d..0000000000 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Filter/SocketInputStream.cs +++ /dev/null @@ -1,93 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using System.IO; -using System.Threading; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Server.Kestrel.Http; -using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; - -namespace Microsoft.AspNetCore.Server.Kestrel.Filter -{ - /// - /// This is a write-only stream that copies what is written into a - /// object. This is used as an argument to - /// so input filtered by a - /// ConnectionFilter (e.g. SslStream) can be consumed by . - /// - public class SocketInputStream : Stream - { - private readonly SocketInput _socketInput; - - public SocketInputStream(SocketInput socketInput) - { - _socketInput = socketInput; - } - - public override bool CanRead => false; - - public override bool CanSeek => false; - - public override bool CanWrite => true; - - public override long Length - { - get - { - throw new NotSupportedException(); - } - } - - public override long Position - { - get - { - throw new NotSupportedException(); - } - - set - { - throw new NotSupportedException(); - } - } - - public override void Flush() - { - // No-op - } - - public override int Read(byte[] buffer, int offset, int count) - { - throw new NotSupportedException(); - } - - public override long Seek(long offset, SeekOrigin origin) - { - throw new NotSupportedException(); - } - - public override void SetLength(long value) - { - throw new NotSupportedException(); - } - - public override void Write(byte[] buffer, int offset, int count) - { - _socketInput.IncomingData(buffer, offset, count); - } - - public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken token) - { - Write(buffer, offset, count); - return TaskUtilities.CompletedTask; - } - - protected override void Dispose(bool disposing) - { - // Close _socketInput with a fake zero-length write that will result in a zero-length read. - _socketInput.IncomingFin(); - base.Dispose(disposing); - } - } -} diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Filter/StreamExtensions.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Filter/StreamExtensions.cs deleted file mode 100644 index c01682327d..0000000000 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Filter/StreamExtensions.cs +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System.IO; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; - -namespace Microsoft.AspNetCore.Server.Kestrel.Filter -{ - public static class StreamExtensions - { - public static async Task CopyToAsync(this Stream source, Stream destination, MemoryPoolBlock block) - { - int bytesRead; - while ((bytesRead = await source.ReadAsync(block.Array, block.Data.Offset, block.Data.Count)) != 0) - { - await destination.WriteAsync(block.Array, block.Data.Offset, bytesRead); - } - } - } -} diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Connection.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Connection.cs index 83ede18be7..4c0668698a 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Connection.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Connection.cs @@ -31,7 +31,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http private ConnectionFilterContext _filterContext; private LibuvStream _libuvStream; private FilteredStreamAdapter _filteredStreamAdapter; - private Task _readInputContinuation; + private Task _readInputTask; private readonly SocketInput _rawSocketInput; private readonly SocketOutput _rawSocketOutput; @@ -181,7 +181,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { _filteredStreamAdapter.Abort(); _rawSocketInput.IncomingFin(); - _readInputContinuation.ContinueWith((task, state) => + _readInputTask.ContinueWith((task, state) => { ((Connection)state)._filterContext.Connection.Dispose(); ((Connection)state)._filteredStreamAdapter.Dispose(); @@ -221,7 +221,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http SocketInput = _filteredStreamAdapter.SocketInput; SocketOutput = _filteredStreamAdapter.SocketOutput; - _readInputContinuation = _filteredStreamAdapter.ReadInputAsync(); + _readInputTask = _filteredStreamAdapter.ReadInputAsync(); } else { From 0a21b9460955b89bda68d08978709ca81298e81b Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Thu, 21 Apr 2016 16:17:09 -0700 Subject: [PATCH 0697/1662] Make ECONNRESET value platform-specific (#649). --- .../Http/Connection.cs | 8 ++++++++ .../Infrastructure/Constants.cs | 20 ++++++++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Connection.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Connection.cs index 4c0668698a..814da8143b 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Connection.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Connection.cs @@ -40,6 +40,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http private ConnectionState _connectionState; private TaskCompletionSource _socketClosedTcs; + bool _eConnResetChecked = false; + public Connection(ListenerContext context, UvStreamHandle socket) : base(context) { _socket = socket; @@ -272,6 +274,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http return; } + if (!_eConnResetChecked && !Constants.ECONNRESET.HasValue) + { + Log.LogWarning("Unable to determine ECONNRESET value on this platform."); + _eConnResetChecked = true; + } + var normalRead = status > 0; var normalDone = status == Constants.ECONNRESET || status == Constants.EOF; var errorDone = !(normalDone || normalRead); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/Constants.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/Constants.cs index 098db13c79..dcbd4cb5f3 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/Constants.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/Constants.cs @@ -1,6 +1,9 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; +using Microsoft.Extensions.PlatformAbstractions; + namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure { internal class Constants @@ -8,7 +11,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure public const int ListenBacklog = 128; public const int EOF = -4095; - public const int ECONNRESET = -4077; + public static readonly int? ECONNRESET = GetECONNRESET(); /// /// Prefix of host name used to specify Unix sockets in the configuration. @@ -20,5 +23,20 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure /// for info on the format. /// public const string RFC1123DateFormat = "r"; + + private static int? GetECONNRESET() + { + switch (PlatformServices.Default.Runtime.OperatingSystemPlatform) + { + case Platform.Windows: + return -4077; + case Platform.Linux: + return -104; + case Platform.Darwin: + return -54; + default: + return null; + } + } } } From 4626833e51da941a5fccb04f4d5127389272c452 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Mon, 25 Apr 2016 09:52:33 +0100 Subject: [PATCH 0698/1662] StreamSocketOutput WriteAsync as async --- .../Filter/StreamSocketOutput.cs | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Filter/StreamSocketOutput.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Filter/StreamSocketOutput.cs index f9ba1e42e0..f45daec8b7 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Filter/StreamSocketOutput.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Filter/StreamSocketOutput.cs @@ -73,9 +73,26 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Filter public Task WriteAsync(ArraySegment buffer, bool chunk, CancellationToken cancellationToken) { - // TODO: Use _outputStream.WriteAsync +#if NET451 Write(buffer, chunk); return TaskUtilities.CompletedTask; +#else + if (chunk && buffer.Array != null) + { + return WriteAsyncChunked(buffer, cancellationToken); + } + + return _outputStream.WriteAsync(buffer.Array ?? _nullBuffer, buffer.Offset, buffer.Count, cancellationToken); +#endif + } + + private async Task WriteAsyncChunked(ArraySegment buffer, CancellationToken cancellationToken) + { + var beginChunkBytes = ChunkWriter.BeginChunkBytes(buffer.Count); + + await _outputStream.WriteAsync(beginChunkBytes.Array, beginChunkBytes.Offset, beginChunkBytes.Count, cancellationToken); + await _outputStream.WriteAsync(buffer.Array ?? _nullBuffer, buffer.Offset, buffer.Count, cancellationToken); + await _outputStream.WriteAsync(_endChunkBytes, 0, _endChunkBytes.Length, cancellationToken); } public MemoryPoolIterator ProducingStart() From 216aa9343e597791348541342c3bf25531e4cb00 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Mon, 25 Apr 2016 11:49:48 +0100 Subject: [PATCH 0699/1662] Remove redundent null coalesce --- .../Filter/StreamSocketOutput.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Filter/StreamSocketOutput.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Filter/StreamSocketOutput.cs index f45daec8b7..0fce7a4760 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Filter/StreamSocketOutput.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Filter/StreamSocketOutput.cs @@ -91,7 +91,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Filter var beginChunkBytes = ChunkWriter.BeginChunkBytes(buffer.Count); await _outputStream.WriteAsync(beginChunkBytes.Array, beginChunkBytes.Offset, beginChunkBytes.Count, cancellationToken); - await _outputStream.WriteAsync(buffer.Array ?? _nullBuffer, buffer.Offset, buffer.Count, cancellationToken); + await _outputStream.WriteAsync(buffer.Array, buffer.Offset, buffer.Count, cancellationToken); await _outputStream.WriteAsync(_endChunkBytes, 0, _endChunkBytes.Length, cancellationToken); } From 0ed14a02005f972aad142a17cf4945398c6a284c Mon Sep 17 00:00:00 2001 From: Pranav K Date: Mon, 25 Apr 2016 14:38:45 -0700 Subject: [PATCH 0700/1662] Remove use of IApplicationEnvironment --- samples/LargeResponseApp/project.json | 2 +- samples/SampleApp/Startup.cs | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/samples/LargeResponseApp/project.json b/samples/LargeResponseApp/project.json index 6a7fff4784..c6690d651d 100644 --- a/samples/LargeResponseApp/project.json +++ b/samples/LargeResponseApp/project.json @@ -17,7 +17,7 @@ } }, "imports": [ - "dnxcore50" + "portable-dnxcore50+net45+win8+wp8+wpa81" ] } }, diff --git a/samples/SampleApp/Startup.cs b/samples/SampleApp/Startup.cs index 7baa8d1c22..eb63506f3b 100644 --- a/samples/SampleApp/Startup.cs +++ b/samples/SampleApp/Startup.cs @@ -7,13 +7,12 @@ using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; using Microsoft.Extensions.Logging; -using Microsoft.Extensions.PlatformAbstractions; namespace SampleApp { public class Startup { - public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory, IApplicationEnvironment env) + public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory) { loggerFactory.AddConsole(LogLevel.Trace); From 8f7c0ff0412b3c2d3acfe333992154989363d834 Mon Sep 17 00:00:00 2001 From: Justin Van Patten Date: Mon, 25 Apr 2016 16:59:16 -0700 Subject: [PATCH 0701/1662] Minor Stream improvements - Unsupported members should throw NotSupportedException instead of NotImplementedException per MSDN docs for CanRead/CanSeek/CanWrite. - Position should throw NotSupportedException when CanSeek is false. - FrameRequestStream.Flush/FlushAsync should not throw NotImplementedException. - Use expression-bodied members for CanRead/CanSeek/CanWrite on FrameRequestStream to match FrameResponseStream. - Provide no-op override of LibuvStream.FlushAsync to match Flush. --- .../Filter/LibuvStream.cs | 7 ++ .../Http/FrameRequestStream.cs | 34 ++++-- .../Http/FrameResponseStream.cs | 20 +++- .../FrameRequestStreamTests.cs | 108 ++++++++++++++++++ .../FrameResponseStreamTests.cs | 94 +++++++++++++++ 5 files changed, 249 insertions(+), 14 deletions(-) create mode 100644 test/Microsoft.AspNetCore.Server.KestrelTests/FrameRequestStreamTests.cs create mode 100644 test/Microsoft.AspNetCore.Server.KestrelTests/FrameResponseStreamTests.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Filter/LibuvStream.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Filter/LibuvStream.cs index 081861a9ca..bf2c2c65e7 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Filter/LibuvStream.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Filter/LibuvStream.cs @@ -6,6 +6,7 @@ using System.IO; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Http; +using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; namespace Microsoft.AspNetCore.Server.Kestrel.Filter { @@ -121,6 +122,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Filter // No-op since writes are immediate. } + public override Task FlushAsync(CancellationToken cancellationToken) + { + // No-op since writes are immediate. + return TaskUtilities.CompletedTask; + } + private ValueTask ReadAsync(ArraySegment buffer) { return _input.ReadAsync(buffer.Array, buffer.Offset, buffer.Count); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameRequestStream.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameRequestStream.cs index f16cf244cb..09c8957edd 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameRequestStream.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameRequestStream.cs @@ -19,35 +19,51 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http _state = FrameStreamState.Closed; } - public override bool CanRead { get { return true; } } + public override bool CanRead => true; - public override bool CanSeek { get { return false; } } + public override bool CanSeek => false; - public override bool CanWrite { get { return false; } } + public override bool CanWrite => false; public override long Length { get { - throw new NotImplementedException(); + throw new NotSupportedException(); } } - public override long Position { get; set; } + public override long Position + { + get + { + throw new NotSupportedException(); + } + set + { + throw new NotSupportedException(); + } + } public override void Flush() { - throw new NotImplementedException(); + // No-op. + } + + public override Task FlushAsync(CancellationToken cancellationToken) + { + // No-op. + return TaskUtilities.CompletedTask; } public override long Seek(long offset, SeekOrigin origin) { - throw new NotImplementedException(); + throw new NotSupportedException(); } public override void SetLength(long value) { - throw new NotImplementedException(); + throw new NotSupportedException(); } public override int Read(byte[] buffer, int offset, int count) @@ -113,7 +129,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http public override void Write(byte[] buffer, int offset, int count) { - throw new NotImplementedException(); + throw new NotSupportedException(); } public Stream StartAcceptingReads(MessageBody body) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameResponseStream.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameResponseStream.cs index 145710af24..c7568bed36 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameResponseStream.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameResponseStream.cs @@ -29,11 +29,21 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { get { - throw new NotImplementedException(); + throw new NotSupportedException(); } } - public override long Position { get; set; } + public override long Position + { + get + { + throw new NotSupportedException(); + } + set + { + throw new NotSupportedException(); + } + } public override void Flush() { @@ -54,17 +64,17 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http public override long Seek(long offset, SeekOrigin origin) { - throw new NotImplementedException(); + throw new NotSupportedException(); } public override void SetLength(long value) { - throw new NotImplementedException(); + throw new NotSupportedException(); } public override int Read(byte[] buffer, int offset, int count) { - throw new NotImplementedException(); + throw new NotSupportedException(); } public override void Write(byte[] buffer, int offset, int count) diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameRequestStreamTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameRequestStreamTests.cs new file mode 100644 index 0000000000..10bdbf452c --- /dev/null +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameRequestStreamTests.cs @@ -0,0 +1,108 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.IO; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Server.Kestrel.Http; +using Xunit; + +namespace Microsoft.AspNetCore.Server.KestrelTests +{ + public class FrameRequestStreamTests + { + [Fact] + public void CanReadReturnsTrue() + { + var stream = new FrameRequestStream(); + Assert.True(stream.CanRead); + } + + [Fact] + public void CanSeekReturnsFalse() + { + var stream = new FrameRequestStream(); + Assert.False(stream.CanSeek); + } + + [Fact] + public void CanWriteReturnsFalse() + { + var stream = new FrameRequestStream(); + Assert.False(stream.CanWrite); + } + + [Fact] + public void SeekThrows() + { + var stream = new FrameRequestStream(); + Assert.Throws(() => stream.Seek(0, SeekOrigin.Begin)); + } + + [Fact] + public void LengthThrows() + { + var stream = new FrameRequestStream(); + Assert.Throws(() => stream.Length); + } + + [Fact] + public void SetLengthThrows() + { + var stream = new FrameRequestStream(); + Assert.Throws(() => stream.SetLength(0)); + } + + [Fact] + public void PositionThrows() + { + var stream = new FrameRequestStream(); + Assert.Throws(() => stream.Position); + Assert.Throws(() => stream.Position = 0); + } + + [Fact] + public void WriteThrows() + { + var stream = new FrameRequestStream(); + Assert.Throws(() => stream.Write(new byte[1], 0, 1)); + } + + [Fact] + public void WriteByteThrows() + { + var stream = new FrameRequestStream(); + Assert.Throws(() => stream.WriteByte(0)); + } + + [Fact] + public async Task WriteAsyncThrows() + { + var stream = new FrameRequestStream(); + await Assert.ThrowsAsync(() => stream.WriteAsync(new byte[1], 0, 1)); + } + +#if NET451 + [Fact] + public void BeginWriteThrows() + { + var stream = new FrameRequestStream(); + Assert.Throws(() => stream.BeginWrite(new byte[1], 0, 1, null, null)); + } +#endif + + [Fact] + public void FlushDoesNotThrow() + { + var stream = new FrameRequestStream(); + stream.Flush(); + } + + [Fact] + public async Task FlushAsyncDoesNotThrow() + { + var stream = new FrameRequestStream(); + await stream.FlushAsync(); + } + } +} diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameResponseStreamTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameResponseStreamTests.cs new file mode 100644 index 0000000000..d8d1dbcad4 --- /dev/null +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameResponseStreamTests.cs @@ -0,0 +1,94 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.IO; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Server.Kestrel.Http; +using Xunit; + +namespace Microsoft.AspNetCore.Server.KestrelTests +{ + public class FrameResponseStreamTests + { + [Fact] + public void CanReadReturnsFalse() + { + var stream = new FrameResponseStream(); + Assert.False(stream.CanRead); + } + + [Fact] + public void CanSeekReturnsFalse() + { + var stream = new FrameResponseStream(); + Assert.False(stream.CanSeek); + } + + [Fact] + public void CanWriteReturnsTrue() + { + var stream = new FrameResponseStream(); + Assert.True(stream.CanWrite); + } + + [Fact] + public void ReadThrows() + { + var stream = new FrameResponseStream(); + Assert.Throws(() => stream.Read(new byte[1], 0, 1)); + } + + [Fact] + public void ReadByteThrows() + { + var stream = new FrameResponseStream(); + Assert.Throws(() => stream.ReadByte()); + } + + [Fact] + public async Task ReadAsyncThrows() + { + var stream = new FrameResponseStream(); + await Assert.ThrowsAsync(() => stream.ReadAsync(new byte[1], 0, 1)); + } + +#if NET451 + [Fact] + public void BeginReadThrows() + { + var stream = new FrameResponseStream(); + Assert.Throws(() => stream.BeginRead(new byte[1], 0, 1, null, null)); + } +#endif + + [Fact] + public void SeekThrows() + { + var stream = new FrameResponseStream(); + Assert.Throws(() => stream.Seek(0, SeekOrigin.Begin)); + } + + [Fact] + public void LengthThrows() + { + var stream = new FrameResponseStream(); + Assert.Throws(() => stream.Length); + } + + [Fact] + public void SetLengthThrows() + { + var stream = new FrameResponseStream(); + Assert.Throws(() => stream.SetLength(0)); + } + + [Fact] + public void PositionThrows() + { + var stream = new FrameResponseStream(); + Assert.Throws(() => stream.Position); + Assert.Throws(() => stream.Position = 0); + } + } +} From 5135ee9d2d8165e3fa20c60c33b2f455c63dccdc Mon Sep 17 00:00:00 2001 From: Pranav K Date: Wed, 27 Apr 2016 17:34:01 -0700 Subject: [PATCH 0702/1662] Fixing CI build break --- .../project.json | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json index 5eab8dffcd..51e8e7d344 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json @@ -6,6 +6,7 @@ "Microsoft.AspNetCore.Server.Kestrel": "1.0.0-*", "Microsoft.AspNetCore.Server.Kestrel.TestCommon": "1.0.0-*", "Microsoft.AspNetCore.Testing": "1.0.0-*", + "Newtonsoft.Json": "8.0.3", "xunit": "2.1.0" }, "frameworks": { @@ -20,8 +21,9 @@ "System.Runtime.Serialization.Primitives": "4.1.1-*" }, "imports": [ - "dnxcore50", - "portable-net451+win8" + "portable-dnxcore50+net45+win8+wp8+wpa81", + "dotnet", + "portable-net45+win8" ] }, "net451": { From 0a538c563be6ab8a28022d58a9e5762d1995e0ea Mon Sep 17 00:00:00 2001 From: BrennanConroy Date: Wed, 27 Apr 2016 18:57:52 -0700 Subject: [PATCH 0703/1662] Remove reference to UseDefaultHostConfiguration --- samples/LargeResponseApp/Startup.cs | 1 - samples/SampleApp/Startup.cs | 1 - 2 files changed, 2 deletions(-) diff --git a/samples/LargeResponseApp/Startup.cs b/samples/LargeResponseApp/Startup.cs index 6408c0bd61..bc02662832 100644 --- a/samples/LargeResponseApp/Startup.cs +++ b/samples/LargeResponseApp/Startup.cs @@ -40,7 +40,6 @@ namespace LargeResponseApp public static void Main(string[] args) { var host = new WebHostBuilder() - .UseDefaultHostingConfiguration(args) .UseKestrel() .UseUrls("http://localhost:5001/") .UseContentRoot(Directory.GetCurrentDirectory()) diff --git a/samples/SampleApp/Startup.cs b/samples/SampleApp/Startup.cs index eb63506f3b..c93e2cb1e9 100644 --- a/samples/SampleApp/Startup.cs +++ b/samples/SampleApp/Startup.cs @@ -41,7 +41,6 @@ namespace SampleApp public static void Main(string[] args) { var host = new WebHostBuilder() - .UseDefaultHostingConfiguration(args) .UseKestrel(options => { // options.ThreadCount = 4; From 68f14c06cb621f362628823ea622d9dc7cc2bfa7 Mon Sep 17 00:00:00 2001 From: Justin Van Patten Date: Tue, 26 Apr 2016 00:33:53 -0700 Subject: [PATCH 0704/1662] Use Task.FromCanceled() on NETSTANDARD1_3 Task.FromCanceled(cancellationToken) can be used on NETSTANDARD1_3 in TaskUtilities.GetCancelledZeroTask(). --- .../Http/FrameRequestStream.cs | 2 +- .../Infrastructure/TaskUtilities.cs | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameRequestStream.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameRequestStream.cs index f16cf244cb..dd36f28c28 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameRequestStream.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameRequestStream.cs @@ -165,7 +165,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http case FrameStreamState.Open: if (cancellationToken.IsCancellationRequested) { - return TaskUtilities.GetCancelledZeroTask(); + return TaskUtilities.GetCancelledZeroTask(cancellationToken); } break; case FrameStreamState.Closed: diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/TaskUtilities.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/TaskUtilities.cs index 8935ac7bda..97f64e3e21 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/TaskUtilities.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/TaskUtilities.cs @@ -26,12 +26,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure #endif } - public static Task GetCancelledZeroTask() + public static Task GetCancelledZeroTask(CancellationToken cancellationToken = default(CancellationToken)) { - // Task.FromCanceled doesn't return Task +#if NETSTANDARD1_3 + return Task.FromCanceled(cancellationToken); +#else var tcs = new TaskCompletionSource(); tcs.TrySetCanceled(); return tcs.Task; +#endif } } } \ No newline at end of file From 75adbc18a2b6fda212322e3068b6e9f99d64cdd8 Mon Sep 17 00:00:00 2001 From: moozzyk Date: Fri, 25 Mar 2016 09:48:29 -0700 Subject: [PATCH 0705/1662] Use IOCP on secondary listener threads on Windows Addresses #679 --- .../Http/ListenerPrimary.cs | 64 ++++++++++++++++++- 1 file changed, 61 insertions(+), 3 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/ListenerPrimary.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/ListenerPrimary.cs index f2d9c2f3a9..4f5bb907fb 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/ListenerPrimary.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/ListenerPrimary.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; +using System.Runtime.InteropServices; using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Networking; @@ -11,7 +12,7 @@ using Microsoft.Extensions.Logging; namespace Microsoft.AspNetCore.Server.Kestrel.Http { /// - /// A primary listener waits for incoming connections on a specified socket. Incoming + /// A primary listener waits for incoming connections on a specified socket. Incoming /// connections may be passed to a secondary listener to handle. /// public abstract class ListenerPrimary : Listener @@ -19,8 +20,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http private readonly List _dispatchPipes = new List(); private int _dispatchIndex; private string _pipeName; + private IntPtr _fileCompletionInfoPtr; + private bool _tryDetachFromIOCP = PlatformApis.IsWindows; - // this message is passed to write2 because it must be non-zero-length, + // this message is passed to write2 because it must be non-zero-length, // but it has no other functional significance private readonly ArraySegment> _dummyMessage = new ArraySegment>(new[] { new ArraySegment(new byte[] { 1, 2, 3, 4 }) }); @@ -37,6 +40,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { _pipeName = pipeName; + if (_fileCompletionInfoPtr == IntPtr.Zero) + { + var fileCompletionInfo = new FILE_COMPLETION_INFORMATION() { Key = IntPtr.Zero, Port = IntPtr.Zero }; + _fileCompletionInfoPtr = Marshal.AllocHGlobal(Marshal.SizeOf(fileCompletionInfo)); + Marshal.StructureToPtr(fileCompletionInfo, _fileCompletionInfoPtr, false); + } + await StartAsync(address, thread).ConfigureAwait(false); await Thread.PostAsync(state => ((ListenerPrimary)state).PostCallback(), @@ -85,6 +95,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } else { + DetachFromIOCP(socket); var dispatchPipe = _dispatchPipes[index]; var write = new UvWriteReq(Log); write.Init(Thread.Loop); @@ -92,7 +103,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http dispatchPipe, _dummyMessage, socket, - (write2, status, error, state) => + (write2, status, error, state) => { write2.Dispose(); ((UvStreamHandle)state).Dispose(); @@ -101,12 +112,59 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } + private void DetachFromIOCP(UvHandle handle) + { + if (!_tryDetachFromIOCP) + { + return; + } + + // https://msdn.microsoft.com/en-us/library/windows/hardware/ff728840(v=vs.85).aspx + const int FileReplaceCompletionInformation = 61; + // https://msdn.microsoft.com/en-us/library/cc704588.aspx + const uint STATUS_INVALID_INFO_CLASS = 0xC0000003; + + var statusBlock = new IO_STATUS_BLOCK(); + var socket = IntPtr.Zero; + Thread.Loop.Libuv.uv_fileno(handle, ref socket); + + if (NtSetInformationFile(socket, out statusBlock, _fileCompletionInfoPtr, + (uint)Marshal.SizeOf(), FileReplaceCompletionInformation) == STATUS_INVALID_INFO_CLASS) + { + // Replacing IOCP information is only supported on Windows 8.1 or newer + _tryDetachFromIOCP = false; + } + } + + private struct IO_STATUS_BLOCK + { + uint status; + ulong information; + } + + private struct FILE_COMPLETION_INFORMATION + { + public IntPtr Port; + public IntPtr Key; + } + + [DllImport("NtDll.dll")] + private static extern uint NtSetInformationFile(IntPtr FileHandle, + out IO_STATUS_BLOCK IoStatusBlock, IntPtr FileInformation, uint Length, + int FileInformationClass); + public override async Task DisposeAsync() { // Call base first so the ListenSocket gets closed and doesn't // try to dispatch connections to closed pipes. await base.DisposeAsync().ConfigureAwait(false); + if (_fileCompletionInfoPtr != IntPtr.Zero) + { + Marshal.FreeHGlobal(_fileCompletionInfoPtr); + _fileCompletionInfoPtr = IntPtr.Zero; + } + if (Thread.FatalError == null && ListenPipe != null) { await Thread.PostAsync(state => From 8a9840216c0793789e444f490009afe0a72acbb1 Mon Sep 17 00:00:00 2001 From: Kristian Hellang Date: Wed, 27 Apr 2016 10:05:20 +0200 Subject: [PATCH 0706/1662] Use type's namespace instead of assembly FullName --- src/Microsoft.AspNetCore.Server.Kestrel/KestrelServer.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServer.cs b/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServer.cs index 1a2b97f68d..a1b1b01947 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServer.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServer.cs @@ -41,7 +41,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel Options = options.Value ?? new KestrelServerOptions(); _applicationLifetime = applicationLifetime; - _logger = loggerFactory.CreateLogger(typeof(KestrelServer).GetTypeInfo().Assembly.FullName); + _logger = loggerFactory.CreateLogger(typeof(KestrelServer).GetTypeInfo().Namespace); Features = new FeatureCollection(); var componentFactory = new HttpComponentFactory(Options); Features.Set(componentFactory); From a31d847719dcc16507a8c387650f44c64aeae12b Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Sat, 30 Apr 2016 11:16:24 +0100 Subject: [PATCH 0707/1662] Tests only to use pooled blocks --- .../AsciiDecoder.cs | 146 +++++++++++------- .../MemoryPoolBlockTests.cs | 30 ++-- .../MemoryPoolIteratorTests.cs | 4 +- .../MultipleLoopTests.cs | 13 +- .../NetworkingTests.cs | 13 +- .../UrlPathDecoder.cs | 99 +++++++++--- 6 files changed, 195 insertions(+), 110 deletions(-) diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/AsciiDecoder.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/AsciiDecoder.cs index 10e95d2e56..634efc65db 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/AsciiDecoder.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/AsciiDecoder.cs @@ -14,23 +14,27 @@ namespace Microsoft.AspNetCore.Server.KestrelTests private void FullByteRangeSupported() { var byteRange = Enumerable.Range(0, 256).Select(x => (byte)x).ToArray(); - - var mem = MemoryPoolBlock.Create(new ArraySegment(byteRange), IntPtr.Zero, null, null); - mem.End = byteRange.Length; - - var begin = mem.GetIterator(); - var end = GetIterator(begin, byteRange.Length); - - var s = begin.GetAsciiString(end); - - Assert.Equal(s.Length, byteRange.Length); - - for (var i = 0; i < byteRange.Length; i++) + using (var pool = new MemoryPool()) { - var sb = (byte)s[i]; - var b = byteRange[i]; + var mem = pool.Lease(); + mem.GetIterator().CopyFrom(byteRange); - Assert.Equal(sb, b); + var begin = mem.GetIterator(); + var end = GetIterator(begin, byteRange.Length); + + var s = begin.GetAsciiString(end); + + Assert.Equal(s.Length, byteRange.Length); + + for (var i = 0; i < byteRange.Length; i++) + { + var sb = (byte)s[i]; + var b = byteRange[i]; + + Assert.Equal(sb, b); + } + + pool.Return(mem); } } @@ -44,32 +48,40 @@ namespace Microsoft.AspNetCore.Server.KestrelTests .Concat(byteRange) .ToArray(); - var mem0 = MemoryPoolBlock.Create(new ArraySegment(byteRange), IntPtr.Zero, null, null); - var mem1 = MemoryPoolBlock.Create(new ArraySegment(byteRange), IntPtr.Zero, null, null); - var mem2 = MemoryPoolBlock.Create(new ArraySegment(byteRange), IntPtr.Zero, null, null); - var mem3 = MemoryPoolBlock.Create(new ArraySegment(byteRange), IntPtr.Zero, null, null); - mem0.End = byteRange.Length; - mem1.End = byteRange.Length; - mem2.End = byteRange.Length; - mem3.End = byteRange.Length; - - mem0.Next = mem1; - mem1.Next = mem2; - mem2.Next = mem3; - - var begin = mem0.GetIterator(); - var end = GetIterator(begin, expectedByteRange.Length); - - var s = begin.GetAsciiString(end); - - Assert.Equal(s.Length, expectedByteRange.Length); - - for (var i = 0; i < expectedByteRange.Length; i++) + using (var pool = new MemoryPool()) { - var sb = (byte)s[i]; - var b = expectedByteRange[i]; + var mem0 = pool.Lease(); + var mem1 = pool.Lease(); + var mem2 = pool.Lease(); + var mem3 = pool.Lease(); + mem0.GetIterator().CopyFrom(byteRange); + mem1.GetIterator().CopyFrom(byteRange); + mem2.GetIterator().CopyFrom(byteRange); + mem3.GetIterator().CopyFrom(byteRange); - Assert.Equal(sb, b); + mem0.Next = mem1; + mem1.Next = mem2; + mem2.Next = mem3; + + var begin = mem0.GetIterator(); + var end = GetIterator(begin, expectedByteRange.Length); + + var s = begin.GetAsciiString(end); + + Assert.Equal(s.Length, expectedByteRange.Length); + + for (var i = 0; i < expectedByteRange.Length; i++) + { + var sb = (byte)s[i]; + var b = expectedByteRange[i]; + + Assert.Equal(sb, b); + } + + pool.Return(mem0); + pool.Return(mem1); + pool.Return(mem2); + pool.Return(mem3); } } @@ -78,27 +90,45 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { var byteRange = Enumerable.Range(0, 16384 + 64).Select(x => (byte)x).ToArray(); var expectedByteRange = byteRange.Concat(byteRange).ToArray(); - - var mem0 = MemoryPoolBlock.Create(new ArraySegment(byteRange), IntPtr.Zero, null, null); - var mem1 = MemoryPoolBlock.Create(new ArraySegment(byteRange), IntPtr.Zero, null, null); - mem0.End = byteRange.Length; - mem1.End = byteRange.Length; - - mem0.Next = mem1; - - var begin = mem0.GetIterator(); - var end = GetIterator(begin, expectedByteRange.Length); - - var s = begin.GetAsciiString(end); - - Assert.Equal(s.Length, expectedByteRange.Length); - - for (var i = 0; i < expectedByteRange.Length; i++) + using (var pool = new MemoryPool()) { - var sb = (byte)s[i]; - var b = expectedByteRange[i]; + var mem0 = pool.Lease(); + var mem1 = pool.Lease(); + mem0.GetIterator().CopyFrom(byteRange); + mem1.GetIterator().CopyFrom(byteRange); - Assert.Equal(sb, b); + var lastBlock = mem0; + while (lastBlock.Next != null) + { + lastBlock = lastBlock.Next; + } + lastBlock.Next = mem1; + + var begin = mem0.GetIterator(); + var end = GetIterator(begin, expectedByteRange.Length); + + var s = begin.GetAsciiString(end); + + Assert.Equal(expectedByteRange.Length, s.Length); + + for (var i = 0; i < expectedByteRange.Length; i++) + { + var sb = (byte)s[i]; + var b = expectedByteRange[i]; + + Assert.Equal(sb, b); + } + + var block = mem0; + while (block != null) + { + var returnBlock = block; + block = block.Next; + pool.Return(returnBlock); + } + + pool.Return(mem0); + pool.Return(mem1); } } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolBlockTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolBlockTests.cs index 73bb3b2ef8..748a0ecf34 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolBlockTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolBlockTests.cs @@ -13,7 +13,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { using (var pool = new MemoryPool()) { - var block = pool.Lease(256); + var block = pool.Lease(); foreach (var ch in Enumerable.Range(0, 256).Select(x => (byte)x)) { block.Array[block.End++] = ch; @@ -63,9 +63,9 @@ namespace Microsoft.AspNetCore.Server.KestrelTests using (var pool = new MemoryPool()) { - var block1 = pool.Lease(256); - var block2 = block1.Next = pool.Lease(256); - var block3 = block2.Next = pool.Lease(256); + var block1 = pool.Lease(); + var block2 = block1.Next = pool.Lease(); + var block3 = block2.Next = pool.Lease(); foreach (var ch in Enumerable.Range(0, 34).Select(x => (byte)x)) { @@ -123,7 +123,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { using (var pool = new MemoryPool()) { - var block = pool.Lease(256); + var block = pool.Lease(); block.End += 256; TestAllLengths(block, 256); pool.Return(block); @@ -132,7 +132,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests for (var fragment = 0; fragment < 256; fragment += 4) { var next = block; - block = pool.Lease(4); + block = pool.Lease(); block.Next = next; block.End += 4; } @@ -168,8 +168,8 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { using (var pool = new MemoryPool()) { - var block1 = pool.Lease(256); - var block2 = block1.Next = pool.Lease(256); + var block1 = pool.Lease(); + var block2 = block1.Next = pool.Lease(); block1.End += 100; block2.End += 200; @@ -209,8 +209,8 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { using (var pool = new MemoryPool()) { - var block1 = pool.Lease(128); - var block2 = block1.Next = pool.Lease(128); + var block1 = pool.Lease(); + var block2 = block1.Next = pool.Lease(); for (int i = 0; i < 128; i++) { @@ -247,7 +247,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { using (var pool = new MemoryPool()) { - var block1 = pool.Lease(128); + var block1 = pool.Lease(); var start = block1.GetIterator(); var end = start; var bufferSize = block1.Data.Count * 3; @@ -289,10 +289,10 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { using (var pool = new MemoryPool()) { - var block1 = pool.Lease(128); - var block2 = block1.Next = pool.Lease(128); - var block3 = block2.Next = pool.Lease(128); - var block4 = block3.Next = pool.Lease(128); + var block1 = pool.Lease(); + var block2 = block1.Next = pool.Lease(); + var block3 = block2.Next = pool.Lease(); + var block4 = block3.Next = pool.Lease(); // There is no data in block2 or block4, so IsEnd should be true after 256 bytes are read. block1.End += 128; diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolIteratorTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolIteratorTests.cs index 18fdeb5afd..834c99baad 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolIteratorTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolIteratorTests.cs @@ -82,7 +82,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [InlineData("/localhost:5000/PATH/PATH2/ HTTP/1.1", " %?", ' ', 27)] public void MemorySeek(string raw, string search, char expectResult, int expectIndex) { - var block = _pool.Lease(256); + var block = _pool.Lease(); var chars = raw.ToCharArray().Select(c => (byte)c).ToArray(); Buffer.BlockCopy(chars, 0, block.Array, block.Start, chars.Length); block.End += chars.Length; @@ -126,7 +126,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var blocks = new MemoryPoolBlock[4]; for (var i = 0; i < 4; ++i) { - blocks[i] = _pool.Lease(16); + blocks[i] = _pool.Lease(); blocks[i].End += 16; for (var j = 0; j < blocks.Length; ++j) diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/MultipleLoopTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/MultipleLoopTests.cs index c5b8c30c5b..af50bba928 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/MultipleLoopTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/MultipleLoopTests.cs @@ -64,11 +64,11 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var writeRequest = new UvWriteReq(new KestrelTrace(new TestKestrelTrace())); writeRequest.Init(loop); - var block = MemoryPoolBlock.Create( - new ArraySegment(new byte[] { 1, 2, 3, 4 }), - dataPtr: IntPtr.Zero, - pool: null, - slab: null); + + var pool = new MemoryPool(); + var block = pool.Lease(); + block.GetIterator().CopyFrom(new ArraySegment(new byte[] { 1, 2, 3, 4 })); + var start = new MemoryPoolIterator(block, 0); var end = new MemoryPoolIterator(block, block.Data.Count); writeRequest.Write( @@ -81,7 +81,8 @@ namespace Microsoft.AspNetCore.Server.KestrelTests writeRequest.Dispose(); serverConnectionPipe.Dispose(); serverListenPipe.Dispose(); - block.Unpin(); + pool.Return(block); + pool.Dispose(); }, null); diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/NetworkingTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/NetworkingTests.cs index c299331818..dd5c5044fc 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/NetworkingTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/NetworkingTests.cs @@ -177,12 +177,10 @@ namespace Microsoft.AspNetCore.Server.KestrelTests for (var x = 0; x < 2; x++) { var req = new UvWriteReq(new KestrelTrace(new TestKestrelTrace())); - req.Init(loop); - var block = MemoryPoolBlock.Create( - new ArraySegment(new byte[] { 65, 66, 67, 68, 69 }), - dataPtr: IntPtr.Zero, - pool: null, - slab: null); + req.Init(loop); var pool = new MemoryPool(); + var block = pool.Lease(); + block.GetIterator().CopyFrom(new ArraySegment(new byte[] { 65, 66, 67, 68, 69 })); + var start = new MemoryPoolIterator(block, 0); var end = new MemoryPoolIterator(block, block.Data.Count); req.Write( @@ -192,7 +190,8 @@ namespace Microsoft.AspNetCore.Server.KestrelTests 1, (_1, _2, _3, _4) => { - block.Unpin(); + pool.Return(block); + pool.Dispose(); }, null); } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/UrlPathDecoder.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/UrlPathDecoder.cs index 711297fd95..31e1ccdbc9 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/UrlPathDecoder.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/UrlPathDecoder.cs @@ -14,13 +14,27 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [Fact] public void Empty() { - PositiveAssert(string.Empty, string.Empty); + using (var pool = new MemoryPool()) + { + var mem = pool.Lease(); + + PositiveAssert(mem, string.Empty, string.Empty); + + pool.Return(mem); + } } [Fact] public void WhiteSpace() { - PositiveAssert(" ", " "); + using (var pool = new MemoryPool()) + { + var mem = pool.Lease(); + + PositiveAssert(mem, " ", " "); + + pool.Return(mem); + } } [Theory] @@ -30,7 +44,14 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [InlineData("/", "/")] public void NormalCases(string raw, string expect) { - PositiveAssert(raw, expect); + using (var pool = new MemoryPool()) + { + var mem = pool.Lease(); + + PositiveAssert(mem, raw, expect); + + pool.Return(mem); + } } [Theory] @@ -39,7 +60,14 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [InlineData("/foo%2F%20bar", "/foo%2F bar")] public void SkipForwardSlash(string raw, string expect) { - PositiveAssert(raw, expect); + using (var pool = new MemoryPool()) + { + var mem = pool.Lease(); + + PositiveAssert(mem, raw, expect); + + pool.Return(mem); + } } [Theory] @@ -60,7 +88,14 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [InlineData("%20", " ")] public void ValidUTF8(string raw, string expect) { - PositiveAssert(raw, expect); + using (var pool = new MemoryPool()) + { + var mem = pool.Lease(); + + PositiveAssert(mem, raw, expect); + + pool.Return(mem); + } } [Theory] @@ -68,7 +103,14 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [InlineData("%E6%88%91%E8%87%AA%E6%A8%AA%E5%88%80%E5%90%91%E5%A4%A9%E7%AC%91%E5%8E%BB%E7%95%99%E8%82%9D%E8%83%86%E4%B8%A4%E6%98%86%E4%BB%91", "我自横刀向天笑去留肝胆两昆仑")] public void Internationalized(string raw, string expect) { - PositiveAssert(raw, expect); + using (var pool = new MemoryPool()) + { + var mem = pool.Lease(); + + PositiveAssert(mem, raw, expect); + + pool.Return(mem); + } } [Theory] @@ -92,7 +134,14 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [InlineData("%C0%32%A4", "%C02%A4")] public void InvalidUTF8(string raw, string expect) { - PositiveAssert(raw, expect); + using (var pool = new MemoryPool()) + { + var mem = pool.Lease(); + + PositiveAssert(mem, raw, expect); + + pool.Return(mem); + } } [Theory] @@ -110,21 +159,27 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [InlineData("%C2%B5%40%C3%9F%C3%B6%C3%A4%C3%BC%C3%A0%C3%A1", 44, "µ@ßöäüà%C3%A", 12)] public void DecodeWithBoundary(string raw, int rawLength, string expect, int expectLength) { - var begin = BuildSample(raw); - var end = GetIterator(begin, rawLength); + using (var pool = new MemoryPool()) + { + var mem = pool.Lease(); - var end2 = UrlPathDecoder.Unescape(begin, end); - var result = begin.GetUtf8String(end2); + var begin = BuildSample(mem, raw); + var end = GetIterator(begin, rawLength); - Assert.Equal(expectLength, result.Length); - Assert.Equal(expect, result); + var end2 = UrlPathDecoder.Unescape(begin, end); + var result = begin.GetUtf8String(end2); + + Assert.Equal(expectLength, result.Length); + Assert.Equal(expect, result); + + pool.Return(mem); + } } - private MemoryPoolIterator BuildSample(string data) + private MemoryPoolIterator BuildSample(MemoryPoolBlock mem, string data) { var store = data.Select(c => (byte)c).ToArray(); - var mem = MemoryPoolBlock.Create(new ArraySegment(store), IntPtr.Zero, null, null); - mem.End = store.Length; + mem.GetIterator().CopyFrom(new ArraySegment(store)); return mem.GetIterator(); } @@ -140,27 +195,27 @@ namespace Microsoft.AspNetCore.Server.KestrelTests return result; } - private void PositiveAssert(string raw, string expect) + private void PositiveAssert(MemoryPoolBlock mem, string raw, string expect) { - var begin = BuildSample(raw); + var begin = BuildSample(mem, raw); var end = GetIterator(begin, raw.Length); var result = UrlPathDecoder.Unescape(begin, end); Assert.Equal(expect, begin.GetUtf8String(result)); } - private void PositiveAssert(string raw) + private void PositiveAssert(MemoryPoolBlock mem, string raw) { - var begin = BuildSample(raw); + var begin = BuildSample(mem, raw); var end = GetIterator(begin, raw.Length); var result = UrlPathDecoder.Unescape(begin, end); Assert.NotEqual(raw.Length, begin.GetUtf8String(result).Length); } - private void NegativeAssert(string raw) + private void NegativeAssert(MemoryPoolBlock mem, string raw) { - var begin = BuildSample(raw); + var begin = BuildSample(mem, raw); var end = GetIterator(begin, raw.Length); var resultEnd = UrlPathDecoder.Unescape(begin, end); From 2aa10a64a270eaef9c1324173717a437402fba69 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Sat, 30 Apr 2016 10:01:39 +0100 Subject: [PATCH 0708/1662] Remove noop pin+unpin w/ memory blocks + Only use pooled blocks in tests --- .../Http/Connection.cs | 2 +- .../Http/SocketOutput.cs | 3 - .../Infrastructure/MemoryPool.cs | 17 +----- .../Infrastructure/MemoryPoolBlock.cs | 61 +++---------------- .../Networking/UvWriteReq.cs | 3 +- 5 files changed, 10 insertions(+), 76 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Connection.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Connection.cs index 814da8143b..add23c4389 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Connection.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Connection.cs @@ -253,7 +253,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http var result = _rawSocketInput.IncomingStart(); return handle.Libuv.buf_init( - result.Pin() + result.End, + result.DataArrayPtr + result.End, result.Data.Offset + result.Data.Count - result.End); } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketOutput.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketOutput.cs index f424a7531c..5db2fb3ebc 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketOutput.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketOutput.cs @@ -684,14 +684,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http var end = _lockedEnd.Block; if (block == end) { - end.Unpin(); return; } while (block.Next != end) { block = block.Next; - block.Unpin(); } block.Next = null; @@ -705,7 +703,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http var returnBlock = block; block = block.Next; - returnBlock.Unpin(); returnBlock.Pool.Return(returnBlock); } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPool.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPool.cs index d5a4e59b7e..6fd37f8a9c 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPool.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPool.cs @@ -63,24 +63,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure /// /// Called to take a block from the pool. /// - /// The block returned must be at least this size. It may be larger than this minimum size, and if so, - /// the caller may write to the block's entire size rather than being limited to the minumumSize requested. /// The block that is reserved for the called. It must be passed to Return when it is no longer being used. - public MemoryPoolBlock Lease(int minimumSize = MaxPooledBlockLength) + public MemoryPoolBlock Lease() { - if (minimumSize > _blockLength) - { - // The requested minimumSize is actually larger then the usable memory of a single block. - // Because this is the degenerate case, a one-time-use byte[] array and tracking object are allocated. - // When this block tracking object is returned it is not added to the pool - instead it will be - // allowed to be garbage collected normally. - return MemoryPoolBlock.Create( - new ArraySegment(new byte[minimumSize]), - dataPtr: IntPtr.Zero, - pool: this, - slab: null); - } - MemoryPoolBlock block; if (_blocks.TryDequeue(out block)) { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPoolBlock.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPoolBlock.cs index 25cab8c4f4..362165ee12 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPoolBlock.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPoolBlock.cs @@ -11,18 +11,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure /// public class MemoryPoolBlock { - /// - /// If this block represents a one-time-use memory object, this GCHandle will hold that memory object at a fixed address - /// so it can be used in native operations. - /// - private GCHandle _pinHandle; - /// /// Native address of the first byte of this block's Data memory. It is null for one-time-use memory, or copied from /// the Slab's ArrayPtr for a slab-block segment. The byte it points to corresponds to Data.Array[0], and in practice you will always - /// use the _dataArrayPtr + Start or _dataArrayPtr + End, which point to the start of "active" bytes, or point to just after the "active" bytes. + /// use the DataArrayPtr + Start or DataArrayPtr + End, which point to the start of "active" bytes, or point to just after the "active" bytes. /// - private IntPtr _dataArrayPtr; + public readonly IntPtr DataArrayPtr; /// /// The array segment describing the range of memory this block is tracking. The caller which has leased this block may only read and @@ -33,8 +27,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure /// /// This object cannot be instantiated outside of the static Create method /// - protected MemoryPoolBlock() + protected MemoryPoolBlock(IntPtr dataArrayPtr) { + DataArrayPtr = dataArrayPtr; } /// @@ -76,20 +71,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure ~MemoryPoolBlock() { - Debug.Assert(!_pinHandle.IsAllocated, "Ad-hoc memory block wasn't unpinned"); Debug.Assert(Slab == null || !Slab.IsActive, "Block being garbage collected instead of returned to pool"); - if (_pinHandle.IsAllocated) - { - // if this is a one-time-use block, ensure that the GCHandle does not leak - _pinHandle.Free(); - } - if (Slab != null && Slab.IsActive) { - Pool.Return(new MemoryPoolBlock + Pool.Return(new MemoryPoolBlock(DataArrayPtr) { - _dataArrayPtr = _dataArrayPtr, Data = Data, Pool = Pool, Slab = Slab, @@ -97,49 +84,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure } } - /// - /// Called to ensure that a block is pinned, and return the pointer to the native address - /// of the first byte of this block's Data memory. Arriving data is read into Pin() + End. - /// Outgoing data is read from Pin() + Start. - /// - /// - public IntPtr Pin() - { - Debug.Assert(!_pinHandle.IsAllocated); - - if (_dataArrayPtr != IntPtr.Zero) - { - // this is a slab managed block - use the native address of the slab which is always locked - return _dataArrayPtr; - } - else - { - // this is one-time-use memory - lock the managed memory until Unpin is called - _pinHandle = GCHandle.Alloc(Data.Array, GCHandleType.Pinned); - return _pinHandle.AddrOfPinnedObject(); - } - } - - public void Unpin() - { - if (_dataArrayPtr == IntPtr.Zero) - { - // this is one-time-use memory - unlock the managed memory - Debug.Assert(_pinHandle.IsAllocated); - _pinHandle.Free(); - } - } - - public static MemoryPoolBlock Create( + internal static MemoryPoolBlock Create( ArraySegment data, IntPtr dataPtr, MemoryPool pool, MemoryPoolSlab slab) { - return new MemoryPoolBlock + return new MemoryPoolBlock(dataPtr) { Data = data, - _dataArrayPtr = dataPtr, Pool = pool, Slab = slab, Start = data.Offset, diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvWriteReq.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvWriteReq.cs index bf088950a5..bc776767a6 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvWriteReq.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvWriteReq.cs @@ -70,7 +70,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Networking // create and pin each segment being written pBuffers[index] = Libuv.buf_init( - block.Pin() + blockStart, + block.DataArrayPtr + blockStart, blockEnd - blockStart); block = block.Next; @@ -89,7 +89,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Networking var block = start.Block; for (var index = 0; index < nBuffers; index++) { - block.Unpin(); block = block.Next; } From 3a424f6abac6a019da4d00c32e98880c0f99e8d7 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Sat, 30 Apr 2016 10:13:50 +0100 Subject: [PATCH 0709/1662] Remove unnecessary fixed blocks --- .../Infrastructure/MemoryPoolBlock.cs | 5 +- .../Infrastructure/MemoryPoolIterator.cs | 168 ++++++++---------- .../MemoryPoolIteratorExtensions.cs | 7 +- 3 files changed, 78 insertions(+), 102 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPoolBlock.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPoolBlock.cs index 362165ee12..3badd57fce 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPoolBlock.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPoolBlock.cs @@ -18,6 +18,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure /// public readonly IntPtr DataArrayPtr; + internal unsafe readonly byte* DataFixedPtr; + /// /// The array segment describing the range of memory this block is tracking. The caller which has leased this block may only read and /// modify the memory in this range. @@ -27,9 +29,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure /// /// This object cannot be instantiated outside of the static Create method /// - protected MemoryPoolBlock(IntPtr dataArrayPtr) + unsafe protected MemoryPoolBlock(IntPtr dataArrayPtr) { DataArrayPtr = dataArrayPtr; + DataFixedPtr = (byte*)dataArrayPtr.ToPointer(); } /// diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPoolIterator.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPoolIterator.cs index 286862ce4b..0fcfe7f434 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPoolIterator.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPoolIterator.cs @@ -175,10 +175,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure } else if (_block.End - _index >= sizeof(long)) { - fixed (byte* ptr = &_block.Array[_index]) - { - return *(long*)(ptr); - } + return *(long*)(_block.DataFixedPtr + _index); } else if (_block.Next == null) { @@ -194,17 +191,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure return -1; } - long blockLong; - fixed (byte* ptr = &_block.Array[_block.End - sizeof(long)]) - { - blockLong = *(long*)(ptr); - } + var blockLong = *(long*)(_block.DataFixedPtr + _block.End - sizeof(long)); - long nextLong; - fixed (byte* ptr = &_block.Next.Array[_block.Next.Start]) - { - nextLong = *(long*)(ptr); - } + var nextLong = *(long*)(_block.Next.DataFixedPtr + _block.Next.Start); return (blockLong >> (sizeof(long) - blockBytes) * 8) | (nextLong << (sizeof(long) - nextBytes) * 8); } @@ -266,22 +255,20 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure #if !DEBUG } #endif - fixed (byte* ptr = &block.Array[index]) + + var pCurrent = (block.DataFixedPtr + index); + var pEnd = pCurrent + following; + do { - var pCurrent = ptr; - var pEnd = pCurrent + following; - do + if (*pCurrent == byte0) { - if (*pCurrent == byte0) - { - _block = block; - _index = index; - return byte0; - } - pCurrent++; - index++; - } while (pCurrent < pEnd); - } + _block = block; + _index = index; + return byte0; + } + pCurrent++; + index++; + } while (pCurrent < pEnd); following = 0; break; @@ -367,28 +354,25 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure #if !DEBUG } #endif - fixed (byte* ptr = &block.Array[index]) + var pCurrent = (block.DataFixedPtr + index); + var pEnd = pCurrent + following; + do { - var pCurrent = ptr; - var pEnd = pCurrent + following; - do + if (*pCurrent == byte0) { - if (*pCurrent == byte0) - { - _block = block; - _index = index; - return byte0; - } - if (*pCurrent == byte1) - { - _block = block; - _index = index; - return byte1; - } - pCurrent++; - index++; - } while (pCurrent != pEnd); - } + _block = block; + _index = index; + return byte0; + } + if (*pCurrent == byte1) + { + _block = block; + _index = index; + return byte1; + } + pCurrent++; + index++; + } while (pCurrent != pEnd); following = 0; break; @@ -502,34 +486,31 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure #if !DEBUG } #endif - fixed (byte* ptr = &block.Array[index]) + var pCurrent = (block.DataFixedPtr + index); + var pEnd = pCurrent + following; + do { - var pCurrent = ptr; - var pEnd = pCurrent + following; - do + if (*pCurrent == byte0) { - if (*pCurrent == byte0) - { - _block = block; - _index = index; - return byte0; - } - if (*pCurrent == byte1) - { - _block = block; - _index = index; - return byte1; - } - if (*pCurrent == byte2) - { - _block = block; - _index = index; - return byte2; - } - pCurrent++; - index++; - } while (pCurrent != pEnd); - } + _block = block; + _index = index; + return byte0; + } + if (*pCurrent == byte1) + { + _block = block; + _index = index; + return byte1; + } + if (*pCurrent == byte2) + { + _block = block; + _index = index; + return byte2; + } + pCurrent++; + index++; + } while (pCurrent != pEnd); following = 0; break; @@ -808,30 +789,25 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure bytesLeftInBlockMinusSpan = bytesLeftInBlock - 3; } - fixed (byte* pOutput = &block.Data.Array[block.End]) + var output = (block.DataFixedPtr + block.End); + var copied = 0; + for (; input < inputEndMinusSpan && copied < bytesLeftInBlockMinusSpan; copied += 4) { - //this line is needed to allow output be an register var - var output = pOutput; - - var copied = 0; - for (; input < inputEndMinusSpan && copied < bytesLeftInBlockMinusSpan; copied += 4) - { - *(output) = (byte)*(input); - *(output + 1) = (byte)*(input + 1); - *(output + 2) = (byte)*(input + 2); - *(output + 3) = (byte)*(input + 3); - output += 4; - input += 4; - } - for (; input < inputEnd && copied < bytesLeftInBlock; copied++) - { - *(output++) = (byte)*(input++); - } - - blockIndex += copied; - bytesLeftInBlockMinusSpan -= copied; - bytesLeftInBlock -= copied; + *(output) = (byte)*(input); + *(output + 1) = (byte)*(input + 1); + *(output + 2) = (byte)*(input + 2); + *(output + 3) = (byte)*(input + 3); + output += 4; + input += 4; } + for (; input < inputEnd && copied < bytesLeftInBlock; copied++) + { + *(output++) = (byte)*(input++); + } + + blockIndex += copied; + bytesLeftInBlockMinusSpan -= copied; + bytesLeftInBlock -= copied; } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPoolIteratorExtensions.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPoolIteratorExtensions.cs index 1f9b3dcd7a..f17dab1394 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPoolIteratorExtensions.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPoolIteratorExtensions.cs @@ -116,9 +116,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure if (following > 0) { - fixed (byte* blockStart = block.Array) - { - var input = blockStart + inputOffset; + var input = block.DataFixedPtr + inputOffset; var i = 0; while (i < following - 11) { @@ -167,9 +165,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure output++; input++; } - + remaining -= following; - } } if (remaining == 0) From f0358182e48403a1ba410a3f098e4afe3a8ca686 Mon Sep 17 00:00:00 2001 From: Pranav K Date: Mon, 2 May 2016 11:27:18 -0700 Subject: [PATCH 0710/1662] Fix build warnings --- samples/LargeResponseApp/project.json | 10 ++++++---- samples/SampleApp/project.json | 12 ++++++----- .../project.json | 20 ++++++++++--------- .../project.json | 18 +++++++++-------- .../project.json | 4 ++-- .../project.json | 4 ++-- .../project.json | 14 +++++++------ .../project.json | 2 +- 8 files changed, 47 insertions(+), 37 deletions(-) diff --git a/samples/LargeResponseApp/project.json b/samples/LargeResponseApp/project.json index c6690d651d..4c284fa6ed 100644 --- a/samples/LargeResponseApp/project.json +++ b/samples/LargeResponseApp/project.json @@ -4,7 +4,7 @@ "Microsoft.NETCore.Platforms": "1.0.1-*", "Microsoft.AspNetCore.Server.Kestrel": "1.0.0-*" }, - "compilationOptions": { + "buildOptions": { "emitEntryPoint": true }, "frameworks": { @@ -21,7 +21,9 @@ ] } }, - "content": [ - "hosting.json" - ] + "publishOptions": { + "include": [ + "hosting.json" + ] + } } \ No newline at end of file diff --git a/samples/SampleApp/project.json b/samples/SampleApp/project.json index 846c49eb07..1ee872316f 100644 --- a/samples/SampleApp/project.json +++ b/samples/SampleApp/project.json @@ -6,7 +6,7 @@ "Microsoft.AspNetCore.Server.Kestrel.Https": "1.0.0-*", "Microsoft.Extensions.Logging.Console": "1.0.0-*" }, - "compilationOptions": { + "buildOptions": { "emitEntryPoint": true }, "frameworks": { @@ -24,8 +24,10 @@ ] } }, - "content": [ - "hosting.json", - "testCert.pfx" - ] + "publishOptions": { + "include": [ + "hosting.json", + "testCert.pfx" + ] + } } \ No newline at end of file diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Https/project.json b/src/Microsoft.AspNetCore.Server.Kestrel.Https/project.json index 521d8b09c4..3c74d74e93 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Https/project.json +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Https/project.json @@ -1,26 +1,28 @@ { "version": "1.0.0-*", "description": "HTTPS support for the ASP.NET Core Kestrel cross-platform web server.", - "tags": [ - "aspnetcore", - "kestrel" - ], - "compilationOptions": { + "buildOptions": { "keyFile": "../../tools/Key.snk", "nowarn": [ "CS1591" ], "xmlDoc": true }, - "repository": { - "type": "git", - "url": "git://github.com/aspnet/kestrelhttpserver" + "packOptions": { + "repository": { + "type": "git", + "url": "git://github.com/aspnet/kestrelhttpserver" + }, + "tags": [ + "aspnetcore", + "kestrel" + ] }, "dependencies": { "Microsoft.AspNetCore.Server.Kestrel": "1.0.0-*" }, "frameworks": { - "net451": { }, + "net451": {}, "netstandard1.3": { "dependencies": { "System.Net.Security": "4.0.0-*" diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/project.json b/src/Microsoft.AspNetCore.Server.Kestrel/project.json index 3b56f01b17..4d875358f5 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/project.json +++ b/src/Microsoft.AspNetCore.Server.Kestrel/project.json @@ -1,13 +1,15 @@ { "version": "1.0.0-*", "description": "ASP.NET Core Kestrel cross-platform web server.", - "tags": [ - "aspnetcore", - "kestrel" - ], - "repository": { - "type": "git", - "url": "git://github.com/aspnet/kestrelhttpserver" + "packOptions": { + "repository": { + "type": "git", + "url": "git://github.com/aspnet/kestrelhttpserver" + }, + "tags": [ + "aspnetcore", + "kestrel" + ] }, "dependencies": { "System.Buffers": "4.0.0-*", @@ -51,7 +53,7 @@ ] } }, - "compilationOptions": { + "buildOptions": { "allowUnsafe": true, "keyFile": "../../tools/Key.snk", "nowarn": [ diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json index 51e8e7d344..ca59561e28 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json @@ -1,6 +1,7 @@ { "version": "1.0.0-*", "dependencies": { + "dotnet-test-xunit": "1.0.0-*", "Microsoft.NETCore.Platforms": "1.0.1-*", "Microsoft.AspNetCore.Http.Abstractions": "1.0.0-*", "Microsoft.AspNetCore.Server.Kestrel": "1.0.0-*", @@ -16,7 +17,6 @@ "version": "1.0.0-*", "type": "platform" }, - "dotnet-test-xunit": "1.0.0-*", "System.Net.Http": "4.0.1-*", "System.Runtime.Serialization.Primitives": "4.1.1-*" }, @@ -35,7 +35,7 @@ } } }, - "compilationOptions": { + "buildOptions": { "allowUnsafe": true }, "testRunner": "xunit" diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.TestCommon/project.json b/test/Microsoft.AspNetCore.Server.Kestrel.TestCommon/project.json index 2795fb5773..c6f9341a65 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.TestCommon/project.json +++ b/test/Microsoft.AspNetCore.Server.Kestrel.TestCommon/project.json @@ -1,7 +1,7 @@ { "version": "1.0.0-*", "frameworks": { - "net451": { }, + "net451": {}, "netstandard1.3": { "dependencies": { "System.Threading": "4.0.11-*", @@ -12,7 +12,7 @@ ] } }, - "compilationOptions": { + "buildOptions": { "keyFile": "../../tools/Key.snk" } } \ No newline at end of file diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/project.json b/test/Microsoft.AspNetCore.Server.KestrelTests/project.json index c0237faec2..22fb7428be 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/project.json +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/project.json @@ -1,6 +1,7 @@ { "version": "1.0.0-*", "dependencies": { + "dotnet-test-xunit": "1.0.0-*", "Microsoft.NETCore.Platforms": "1.0.1-*", "Microsoft.AspNetCore.Server.Kestrel": "1.0.0-*", "Microsoft.AspNetCore.Server.Kestrel.Https": "1.0.0-*", @@ -21,8 +22,7 @@ "System.Net.Http": "4.0.1-*", "System.Net.Http.WinHttpHandler": "4.0.0-*", "System.Net.Sockets": "4.1.0-*", - "System.Runtime.Handles": "4.0.1-*", - "dotnet-test-xunit": "1.0.0-*" + "System.Runtime.Handles": "4.0.1-*" }, "imports": [ "dnxcore50", @@ -38,12 +38,14 @@ } } }, - "compilationOptions": { + "buildOptions": { "allowUnsafe": true, "keyFile": "../../tools/Key.snk" }, "testRunner": "xunit", - "content": [ - "TestResources/testCert.pfx" - ] + "publishOptions": { + "include": [ + "TestResources/testCert.pfx" + ] + } } \ No newline at end of file diff --git a/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/project.json b/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/project.json index 03b787a99e..1682d3763a 100644 --- a/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/project.json +++ b/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/project.json @@ -1,6 +1,6 @@ { "version": "1.0.0-*", - "compilationOptions": { + "buildOptions": { "emitEntryPoint": true }, "dependencies": { From 296ca0f94865aa49744b3b0a309525a7899f63c8 Mon Sep 17 00:00:00 2001 From: Pranav K Date: Mon, 2 May 2016 16:22:54 -0700 Subject: [PATCH 0711/1662] Fix build break --- test/Microsoft.AspNetCore.Server.KestrelTests/project.json | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/project.json b/test/Microsoft.AspNetCore.Server.KestrelTests/project.json index 22fb7428be..998df18145 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/project.json +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/project.json @@ -40,7 +40,10 @@ }, "buildOptions": { "allowUnsafe": true, - "keyFile": "../../tools/Key.snk" + "keyFile": "../../tools/Key.snk", + "copyToOutput": { + "include": "TestResources/testCert.pfx" + } }, "testRunner": "xunit", "publishOptions": { From 14bbba06418234f1f6d41eb2540ca26f8598fd23 Mon Sep 17 00:00:00 2001 From: Mike Harder Date: Wed, 4 May 2016 11:27:23 -0700 Subject: [PATCH 0712/1662] Update addresses in IServerAddressesFeature with assigned dynamic ports (#758) - Change most tests to use dynamic ports, rather than a fixed port obtained from GetNextPort(). - Add several new cases to `AddressRegistrationTests` and `ServerAddressFacts`. - Remove project `test\Microsoft.AspNetCore.Server.Kestrel.TestCommon`. It's not longer needed, since only `AddressRegistrationTests` uses `GetNextPort()`. --- KestrelHttpServer.sln | 7 - .../Http/TcpListener.cs | 4 + .../Http/TcpListenerPrimary.cs | 4 + .../KestrelServer.cs | 7 +- .../ServerAddress.cs | 18 +- .../AddressRegistrationTests.cs | 216 ++++++++++++++++-- .../IWebHostPortExtensions.cs | 25 ++ .../PathBaseTests.cs | 5 +- .../PortManager.cs | 15 -- .../RequestTests.cs | 25 +- .../ResponseTests.cs | 15 +- .../ThreadCountTests.cs | 5 +- .../project.json | 3 +- ...AspNetCore.Server.Kestrel.TestCommon.xproj | 17 -- .../PortManager.cs | 38 --- .../project.json | 18 -- .../ConnectionTests.cs | 2 +- .../EngineTests.cs | 7 +- .../HttpsConnectionFilterTests.cs | 26 +-- .../MultipleLoopTests.cs | 4 +- .../NetworkingTests.cs | 12 +- .../ServerAddressFacts.cs | 45 ++-- .../TestServer.cs | 8 +- .../project.json | 1 - 24 files changed, 316 insertions(+), 211 deletions(-) create mode 100644 test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/IWebHostPortExtensions.cs delete mode 100644 test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/PortManager.cs delete mode 100644 test/Microsoft.AspNetCore.Server.Kestrel.TestCommon/Microsoft.AspNetCore.Server.Kestrel.TestCommon.xproj delete mode 100644 test/Microsoft.AspNetCore.Server.Kestrel.TestCommon/PortManager.cs delete mode 100644 test/Microsoft.AspNetCore.Server.Kestrel.TestCommon/project.json diff --git a/KestrelHttpServer.sln b/KestrelHttpServer.sln index 4a215770d9..a9155550a7 100644 --- a/KestrelHttpServer.sln +++ b/KestrelHttpServer.sln @@ -34,8 +34,6 @@ Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNetCore.Server EndProject Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNetCore.Server.Kestrel.FunctionalTests", "test\Microsoft.AspNetCore.Server.Kestrel.FunctionalTests\Microsoft.AspNetCore.Server.Kestrel.FunctionalTests.xproj", "{9559A5F1-080C-4909-B6CF-7E4B3DC55748}" EndProject -Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNetCore.Server.Kestrel.TestCommon", "test\Microsoft.AspNetCore.Server.Kestrel.TestCommon\Microsoft.AspNetCore.Server.Kestrel.TestCommon.xproj", "{A485B4F9-0392-478C-B19A-F4DE6B17F491}" -EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -74,10 +72,6 @@ Global {9559A5F1-080C-4909-B6CF-7E4B3DC55748}.Debug|Any CPU.Build.0 = Debug|Any CPU {9559A5F1-080C-4909-B6CF-7E4B3DC55748}.Release|Any CPU.ActiveCfg = Release|Any CPU {9559A5F1-080C-4909-B6CF-7E4B3DC55748}.Release|Any CPU.Build.0 = Release|Any CPU - {A485B4F9-0392-478C-B19A-F4DE6B17F491}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {A485B4F9-0392-478C-B19A-F4DE6B17F491}.Debug|Any CPU.Build.0 = Debug|Any CPU - {A485B4F9-0392-478C-B19A-F4DE6B17F491}.Release|Any CPU.ActiveCfg = Release|Any CPU - {A485B4F9-0392-478C-B19A-F4DE6B17F491}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -91,6 +85,5 @@ Global {8CBA6FE3-3CC9-4420-8AA3-123E983734C2} = {327F7880-D9AF-46BD-B45C-3B7E34A01DFD} {5F64B3C3-0C2E-431A-B820-A81BBFC863DA} = {2D5D5227-4DBD-499A-96B1-76A36B03B750} {9559A5F1-080C-4909-B6CF-7E4B3DC55748} = {D3273454-EA07-41D2-BF0B-FCC3675C2483} - {A485B4F9-0392-478C-B19A-F4DE6B17F491} = {D3273454-EA07-41D2-BF0B-FCC3675C2483} EndGlobalSection EndGlobal diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/TcpListener.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/TcpListener.cs index 94c7cdecd9..cc7e3f9aff 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/TcpListener.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/TcpListener.cs @@ -25,6 +25,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http socket.Init(Thread.Loop, Thread.QueueCloseHandle); socket.NoDelay(ServerOptions.NoDelay); socket.Bind(ServerAddress); + + // If requested port was "0", replace with assigned dynamic port. + ServerAddress.Port = socket.GetSockIPEndPoint().Port; + socket.Listen(Constants.ListenBacklog, (stream, status, error, state) => ConnectionCallback(stream, status, error, state), this); return socket; } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/TcpListenerPrimary.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/TcpListenerPrimary.cs index 80691b51ec..926cd014b2 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/TcpListenerPrimary.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/TcpListenerPrimary.cs @@ -27,6 +27,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http socket.Init(Thread.Loop, Thread.QueueCloseHandle); socket.NoDelay(ServerOptions.NoDelay); socket.Bind(ServerAddress); + + // If requested port was "0", replace with assigned dynamic port. + ServerAddress.Port = socket.GetSockIPEndPoint().Port; + socket.Listen(Constants.ListenBacklog, (stream, status, error, state) => ConnectionCallback(stream, status, error, state), this); return socket; } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServer.cs b/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServer.cs index a1b1b01947..19068784a4 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServer.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServer.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; +using System.Linq; using System.Reflection; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting.Server; @@ -96,7 +97,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel engine.Start(threadCount); var atLeastOneListener = false; - foreach (var address in _serverAddresses.Addresses) + foreach (var address in _serverAddresses.Addresses.ToArray()) { var parsedAddress = ServerAddress.FromUrl(address); if (parsedAddress == null) @@ -108,6 +109,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel atLeastOneListener = true; _disposables.Push(engine.CreateServer( parsedAddress)); + + // If requested port was "0", replace with assigned dynamic port. + _serverAddresses.Addresses.Remove(address); + _serverAddresses.Addresses.Add(parsedAddress.ToString()); } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/ServerAddress.cs b/src/Microsoft.AspNetCore.Server.Kestrel/ServerAddress.cs index a41472bbdf..536492dfb1 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/ServerAddress.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/ServerAddress.cs @@ -13,7 +13,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel { public string Host { get; private set; } public string PathBase { get; private set; } - public int Port { get; private set; } + public int Port { get; internal set; } public string Scheme { get; private set; } public bool IsUnixPipe @@ -36,7 +36,21 @@ namespace Microsoft.AspNetCore.Server.Kestrel public override string ToString() { - return Scheme.ToLowerInvariant() + "://" + Host.ToLowerInvariant() + ":" + Port.ToString(CultureInfo.InvariantCulture) + PathBase.ToLowerInvariant(); + if (IsUnixPipe) + { + if (String.IsNullOrEmpty(PathBase)) + { + return Scheme.ToLowerInvariant() + "://" + Host.ToLowerInvariant(); + } + else + { + return Scheme.ToLowerInvariant() + "://" + Host.ToLowerInvariant() + ":" + PathBase.ToLowerInvariant(); + } + } + else + { + return Scheme.ToLowerInvariant() + "://" + Host.ToLowerInvariant() + ":" + Port.ToString(CultureInfo.InvariantCulture) + PathBase.ToLowerInvariant(); + } } public override int GetHashCode() diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs index 2422eb527f..1f5fb0a61c 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs @@ -1,11 +1,16 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; using System.Collections.Generic; +using System.Linq; +using System.Net; using System.Net.Http; +using System.Net.Sockets; using System.Threading.Tasks; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Hosting.Server.Features; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http.Extensions; using Microsoft.AspNetCore.Testing.xunit; @@ -16,20 +21,36 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { public class AddressRegistrationTests { + [Theory, MemberData(nameof(AddressRegistrationDataIPv4))] - public async Task RegisterAddresses_IPv4_Success(string addressInput, string[] testUrls) + public async Task RegisterAddresses_IPv4_Success(string addressInput, Func testUrls) + { + await RegisterAddresses_Success(addressInput, testUrls); + } + + [ConditionalTheory, MemberData(nameof(AddressRegistrationDataIPv4Port80))] + [Port80SupportedCondition] + public async Task RegisterAddresses_IPv4Port80_Success(string addressInput, Func testUrls) { await RegisterAddresses_Success(addressInput, testUrls); } [ConditionalTheory, MemberData(nameof(AddressRegistrationDataIPv6))] [IPv6SupportedCondition] - public async Task RegisterAddresses_IPv6_Success(string addressInput, string[] testUrls) + public async Task RegisterAddresses_IPv6_Success(string addressInput, Func testUrls) { await RegisterAddresses_Success(addressInput, testUrls); } - public async Task RegisterAddresses_Success(string addressInput, string[] testUrls) + [ConditionalTheory, MemberData(nameof(AddressRegistrationDataIPv6ScopeId))] + [OSSkipCondition(OperatingSystems.Linux, SkipReason = "HttpClient does not support IPv6 with scope ID on Linux (https://github.com/dotnet/corefx/issues/8235).")] + [OSSkipCondition(OperatingSystems.MacOSX, SkipReason = "HttpClient does not support IPv6 with scope ID on Mac (https://github.com/dotnet/corefx/issues/8235).")] + public async Task RegisterAddresses_IPv6ScopeId_Success(string addressInput, Func testUrls) + { + await RegisterAddresses_Success(addressInput, testUrls); + } + + public async Task RegisterAddresses_Success(string addressInput, Func testUrls) { var config = new ConfigurationBuilder() .AddInMemoryCollection(new Dictionary @@ -49,49 +70,129 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests using (var client = new HttpClient()) { - foreach (var testUrl in testUrls) + foreach (var testUrl in testUrls(host.ServerFeatures.Get())) { - var responseText = await client.GetStringAsync(testUrl); - Assert.Equal(testUrl, responseText); + var response = await client.GetAsync(testUrl); + + // Compare the response with the RequestMessage.RequestUri, rather than testUrl directly. + // Required to handle IPv6 addresses with zone index, like "fe80::3%1" + Assert.Equal( + response.RequestMessage.RequestUri.ToString(), + await response.Content.ReadAsStringAsync()); } } } } - public static TheoryData AddressRegistrationDataIPv4 + public static TheoryData> AddressRegistrationDataIPv4 { get { - var port1 = PortManager.GetPort(); - var port2 = PortManager.GetPort(); - var dataset = new TheoryData(); - dataset.Add($"{port1}", new[] { $"http://localhost:{port1}/" }); - dataset.Add($"{port1};{port2}", new[] { $"http://localhost:{port1}/", $"http://localhost:{port2}/" }); - dataset.Add($"http://127.0.0.1:{port1}/", new[] { $"http://127.0.0.1:{port1}/", }); - dataset.Add($"http://localhost:{port1}/base/path", new[] { $"http://localhost:{port1}/base/path" }); + var dataset = new TheoryData>(); + + // Default host and port + dataset.Add(null, _ => new[] { "http://localhost:5000/" }); + dataset.Add(string.Empty, _ => new[] { "http://localhost:5000/" }); + + // Static port + var port1 = GetNextPort(); + var port2 = GetNextPort(); + dataset.Add($"{port1}", _ => new[] { $"http://localhost:{port1}/" }); + dataset.Add($"{port1};{port2}", _ => new[] { $"http://localhost:{port1}/", $"http://localhost:{port2}/" }); + + // Ensure "localhost" and "127.0.0.1" are equivalent + dataset.Add($"http://localhost:{port1}", _ => new[] { $"http://localhost:{port1}/", $"http://127.0.0.1:{port1}/" }); + dataset.Add($"http://127.0.0.1:{port1}", _ => new[] { $"http://localhost:{port1}/", $"http://127.0.0.1:{port1}/" }); + + // Path after port + dataset.Add($"http://localhost:{port1}/base/path", _ => new[] { $"http://localhost:{port1}/base/path" }); + + // Dynamic port + dataset.Add("0", GetTestUrls); + dataset.Add("http://localhost:0/", GetTestUrls); + dataset.Add($"http://{Dns.GetHostName()}:0/", GetTestUrls); + + var ipv4Addresses = Dns.GetHostAddressesAsync(Dns.GetHostName()).Result + .Where(ip => ip.AddressFamily == AddressFamily.InterNetwork); + foreach (var ip in ipv4Addresses) + { + dataset.Add($"http://{ip}:0/", GetTestUrls); + } return dataset; } } - public static TheoryData AddressRegistrationDataIPv6 + public static TheoryData> AddressRegistrationDataIPv4Port80 { get { - var port = PortManager.GetPort(); - var dataset = new TheoryData(); - dataset.Add($"http://*:{port}/", new[] { $"http://localhost:{port}/", $"http://127.0.0.1:{port}/", $"http://[::1]:{port}/" }); - dataset.Add($"http://localhost:{port}/", new[] { $"http://localhost:{port}/", $"http://127.0.0.1:{port}/", - /* // https://github.com/aspnet/KestrelHttpServer/issues/231 - $"http://[::1]:{port}/" - */ }); - dataset.Add($"http://[::1]:{port}/", new[] { $"http://[::1]:{port}/", }); - dataset.Add($"http://127.0.0.1:{port}/;http://[::1]:{port}/", new[] { $"http://127.0.0.1:{port}/", $"http://[::1]:{port}/" }); + var dataset = new TheoryData>(); + + // Default port for HTTP (80) + dataset.Add("http://*", _ => new[] { "http://localhost/" }); + dataset.Add("http://localhost", _ => new[] { "http://localhost/" }); return dataset; } } + public static TheoryData> AddressRegistrationDataIPv6 + { + get + { + var dataset = new TheoryData>(); + + // Static port + var port = GetNextPort(); + dataset.Add($"http://*:{port}/", _ => new[] { $"http://localhost:{port}/", $"http://127.0.0.1:{port}/", $"http://[::1]:{port}/" }); + dataset.Add($"http://localhost:{port}/", _ => new[] { $"http://localhost:{port}/", $"http://127.0.0.1:{port}/", + /* // https://github.com/aspnet/KestrelHttpServer/issues/231 + $"http://[::1]:{port}/" + */ }); + dataset.Add($"http://[::1]:{port}/", _ => new[] { $"http://[::1]:{port}/", }); + dataset.Add($"http://127.0.0.1:{port}/;http://[::1]:{port}/", _ => new[] { $"http://127.0.0.1:{port}/", $"http://[::1]:{port}/" }); + + // Dynamic port + var ipv6Addresses = Dns.GetHostAddressesAsync(Dns.GetHostName()).Result + .Where(ip => ip.AddressFamily == AddressFamily.InterNetworkV6) + .Where(ip => ip.ScopeId == 0); + foreach (var ip in ipv6Addresses) + { + dataset.Add($"http://[{ip}]:0/", GetTestUrls); + } + + return dataset; + } + } + + public static TheoryData> AddressRegistrationDataIPv6ScopeId + { + get + { + var dataset = new TheoryData>(); + + // Dynamic port + var ipv6Addresses = Dns.GetHostAddressesAsync(Dns.GetHostName()).Result + .Where(ip => ip.AddressFamily == AddressFamily.InterNetworkV6) + .Where(ip => ip.ScopeId != 0); + foreach (var ip in ipv6Addresses) + { + dataset.Add($"http://[{ip}]:0/", GetTestUrls); + } + + return dataset; + } + } + + private static string[] GetTestUrls(IServerAddressesFeature addressesFeature) + { + return addressesFeature.Addresses + .Select(a => a.Replace("://+", "://localhost")) + .Select(a => a.EndsWith("/") ? a : a + "/") + .ToArray(); + } + private void ConfigureEchoAddress(IApplicationBuilder app) { app.Run(context => @@ -99,5 +200,72 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests return context.Response.WriteAsync(context.Request.GetDisplayUrl()); }); } + + private static int _nextPort = 8001; + private static object _portLock = new object(); + private static int GetNextPort() + { + lock (_portLock) + { + using (var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)) + { + while (true) + { + try + { + var port = _nextPort++; + socket.Bind(new IPEndPoint(IPAddress.Loopback, port)); + return port; + } + catch (SocketException) + { + // Retry unless exhausted + if (_nextPort == 65536) + { + throw; + } + } + } + } + } + } + + [AttributeUsage(AttributeTargets.Method, AllowMultiple = false)] + private class Port80SupportedConditionAttribute : Attribute, ITestCondition + { + private static readonly Lazy _port80Supported = new Lazy(CanBindToPort80); + + public bool IsMet + { + get + { + return _port80Supported.Value; + } + } + + public string SkipReason + { + get + { + return "Cannot bind to port 80 on the host."; + } + } + + private static bool CanBindToPort80() + { + try + { + using (var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)) + { + socket.Bind(new IPEndPoint(IPAddress.Loopback, 80)); + return true; + } + } + catch (SocketException) + { + return false; + } + } + } } } diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/IWebHostPortExtensions.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/IWebHostPortExtensions.cs new file mode 100644 index 0000000000..9b3509503e --- /dev/null +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/IWebHostPortExtensions.cs @@ -0,0 +1,25 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Collections.Generic; +using System.Linq; +using Microsoft.AspNetCore.Hosting.Server.Features; + +namespace Microsoft.AspNetCore.Hosting +{ + public static class IWebHostPortExtensions + { + public static int GetPort(this IWebHost host) + { + return host.GetPorts().First(); + } + + public static IEnumerable GetPorts(this IWebHost host) + { + return host.ServerFeatures.Get().Addresses + .Select(a => a.Replace("://+", "://localhost")) + .Select(a => (new Uri(a)).Port); + } + } +} diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/PathBaseTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/PathBaseTests.cs index 12baa2731d..6520d73eb5 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/PathBaseTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/PathBaseTests.cs @@ -68,10 +68,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests private async Task TestPathBase(string registerPathBase, string requestPath, string expectedPathBase, string expectedPath) { - var port = PortManager.GetPort(); var config = new ConfigurationBuilder().AddInMemoryCollection( new Dictionary { - { "server.urls", $"http://localhost:{port}{registerPathBase}" } + { "server.urls", $"http://localhost:0{registerPathBase}" } }).Build(); var builder = new WebHostBuilder() @@ -95,7 +94,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests using (var client = new HttpClient()) { - var response = await client.GetAsync($"http://localhost:{port}{requestPath}"); + var response = await client.GetAsync($"http://localhost:{host.GetPort()}{requestPath}"); response.EnsureSuccessStatusCode(); var responseText = await response.Content.ReadAsStringAsync(); diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/PortManager.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/PortManager.cs deleted file mode 100644 index 62e019d4be..0000000000 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/PortManager.cs +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System.Threading; - -namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests -{ - public static class PortManager - { - public static int GetPort() - { - return TestCommon.PortManager.GetNextPort(); - } - } -} diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs index 63f4415042..3a032767ac 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs @@ -22,10 +22,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [Fact] public async Task LargeUpload() { - var port = PortManager.GetPort(); var builder = new WebHostBuilder() .UseKestrel() - .UseUrls($"http://localhost:{port}/") + .UseUrls($"http://localhost:0/") .Configure(app => { app.Run(async context => @@ -60,7 +59,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests bytes[i] = (byte)i; } - var response = await client.PostAsync($"http://localhost:{port}/", new ByteArrayContent(bytes)); + var response = await client.PostAsync($"http://localhost:{host.GetPort()}/", new ByteArrayContent(bytes)); response.EnsureSuccessStatusCode(); var sizeString = await response.Content.ReadAsStringAsync(); Assert.Equal(sizeString, bytes.Length.ToString(CultureInfo.InvariantCulture)); @@ -72,10 +71,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Fails on Mono on Mac because it is not 64-bit.")] public async Task LargeMultipartUpload() { - var port = PortManager.GetPort(); var builder = new WebHostBuilder() .UseKestrel() - .UseUrls($"http://localhost:{port}/") + .UseUrls($"http://localhost:0/") .Configure(app => { app.Run(async context => @@ -111,7 +109,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } var length = form.Headers.ContentLength.Value; - var response = await client.PostAsync($"http://localhost:{port}/", form); + var response = await client.PostAsync($"http://localhost:{host.GetPort()}/", form); response.EnsureSuccessStatusCode(); Assert.Equal(length.ToString(CultureInfo.InvariantCulture), await response.Content.ReadAsStringAsync()); } @@ -137,10 +135,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [Fact] public async Task DoesNotHangOnConnectionCloseRequest() { - var port = PortManager.GetPort(); var builder = new WebHostBuilder() .UseKestrel() - .UseUrls($"http://localhost:{port}") + .UseUrls($"http://localhost:0") .Configure(app => { app.Run(async context => @@ -158,7 +155,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests client.DefaultRequestHeaders.Connection.Clear(); client.DefaultRequestHeaders.Connection.Add("close"); - var response = await client.GetAsync($"http://localhost:{port}/"); + var response = await client.GetAsync($"http://localhost:{host.GetPort()}/"); response.EnsureSuccessStatusCode(); } } @@ -166,10 +163,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [Fact] public void RequestPathIsNormalized() { - var port = PortManager.GetPort(); var builder = new WebHostBuilder() .UseKestrel() - .UseUrls($"http://localhost:{port}/\u0041\u030A") + .UseUrls($"http://localhost:0/\u0041\u030A") .Configure(app => { app.Run(async context => @@ -185,7 +181,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { host.Start(); - using (var socket = TestConnection.CreateConnectedLoopbackSocket(port)) + using (var socket = TestConnection.CreateConnectedLoopbackSocket(host.GetPort())) { socket.Send(Encoding.ASCII.GetBytes("GET /%41%CC%8A/A/../B/%41%CC%8A HTTP/1.1\r\n\r\n")); socket.Shutdown(SocketShutdown.Send); @@ -210,10 +206,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests private async Task TestRemoteIPAddress(string registerAddress, string requestAddress, string expectAddress) { - var port = PortManager.GetPort(); var builder = new WebHostBuilder() .UseKestrel() - .UseUrls($"http://{registerAddress}:{port}") + .UseUrls($"http://{registerAddress}:0") .Configure(app => { app.Run(async context => @@ -234,7 +229,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { host.Start(); - var response = await client.GetAsync($"http://{requestAddress}:{port}/"); + var response = await client.GetAsync($"http://{requestAddress}:{host.GetPort()}/"); response.EnsureSuccessStatusCode(); var connectionFacts = await response.Content.ReadAsStringAsync(); diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs index a1dfe66ab1..2d3c70aff2 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs @@ -21,11 +21,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [Fact] public async Task LargeDownload() { - var port = PortManager.GetPort(); var config = new ConfigurationBuilder() .AddInMemoryCollection(new Dictionary { - { "server.urls", $"http://localhost:{port}/" } + { "server.urls", $"http://localhost:0/" } }) .Build(); @@ -57,7 +56,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests using (var client = new HttpClient()) { - var response = await client.GetAsync($"http://localhost:{port}/"); + var response = await client.GetAsync($"http://localhost:{host.GetPort()}/"); response.EnsureSuccessStatusCode(); var responseBody = await response.Content.ReadAsStreamAsync(); @@ -81,11 +80,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [Theory, MemberData(nameof(NullHeaderData))] public async Task IgnoreNullHeaderValues(string headerName, StringValues headerValue, string expectedValue) { - var port = PortManager.GetPort(); var config = new ConfigurationBuilder() .AddInMemoryCollection(new Dictionary { - { "server.urls", $"http://localhost:{port}/" } + { "server.urls", $"http://localhost:0/" } }) .Build(); @@ -108,7 +106,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests using (var client = new HttpClient()) { - var response = await client.GetAsync($"http://localhost:{port}/"); + var response = await client.GetAsync($"http://localhost:{host.GetPort()}/"); response.EnsureSuccessStatusCode(); var headers = response.Headers; @@ -129,11 +127,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [Fact] public async Task OnCompleteCalledEvenWhenOnStartingNotCalled() { - var port = PortManager.GetPort(); var config = new ConfigurationBuilder() .AddInMemoryCollection(new Dictionary { - { "server.urls", $"http://localhost:{port}/" } + { "server.urls", $"http://localhost:0/" } }) .Build(); @@ -161,7 +158,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests using (var client = new HttpClient()) { - var response = await client.GetAsync($"http://localhost:{port}/"); + var response = await client.GetAsync($"http://localhost:{host.GetPort()}/"); Assert.Equal(HttpStatusCode.InternalServerError, response.StatusCode); Assert.False(onStartingCalled); diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ThreadCountTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ThreadCountTests.cs index 543d1d2a4e..2c10fd96a2 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ThreadCountTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ThreadCountTests.cs @@ -16,11 +16,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { public async Task ZeroToTenThreads(int threadCount) { - var port = PortManager.GetPort(); var config = new ConfigurationBuilder() .AddInMemoryCollection(new Dictionary { - { "server.urls", $"http://localhost:{port}/" } + { "server.urls", $"http://localhost:0/" } }) .Build(); @@ -48,7 +47,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests var requestTasks = new List>(); for (int i = 0; i < 20; i++) { - var requestTask = client.GetStringAsync($"http://localhost:{port}/"); + var requestTask = client.GetStringAsync($"http://localhost:{host.GetPort()}/"); requestTasks.Add(requestTask); } diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json index ca59561e28..35ae2f4011 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json @@ -5,7 +5,7 @@ "Microsoft.NETCore.Platforms": "1.0.1-*", "Microsoft.AspNetCore.Http.Abstractions": "1.0.0-*", "Microsoft.AspNetCore.Server.Kestrel": "1.0.0-*", - "Microsoft.AspNetCore.Server.Kestrel.TestCommon": "1.0.0-*", + "Microsoft.AspNetCore.Server.Kestrel.Https": "1.0.0-*", "Microsoft.AspNetCore.Testing": "1.0.0-*", "Newtonsoft.Json": "8.0.3", "xunit": "2.1.0" @@ -18,6 +18,7 @@ "type": "platform" }, "System.Net.Http": "4.0.1-*", + "System.Net.Http.WinHttpHandler": "4.0.0-*", "System.Runtime.Serialization.Primitives": "4.1.1-*" }, "imports": [ diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.TestCommon/Microsoft.AspNetCore.Server.Kestrel.TestCommon.xproj b/test/Microsoft.AspNetCore.Server.Kestrel.TestCommon/Microsoft.AspNetCore.Server.Kestrel.TestCommon.xproj deleted file mode 100644 index fbee634344..0000000000 --- a/test/Microsoft.AspNetCore.Server.Kestrel.TestCommon/Microsoft.AspNetCore.Server.Kestrel.TestCommon.xproj +++ /dev/null @@ -1,17 +0,0 @@ - - - - 14.0 - $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) - - - - a485b4f9-0392-478c-b19a-f4de6b17f491 - ..\..\artifacts\obj\$(MSBuildProjectName) - ..\..\artifacts\bin\ - - - 2.0 - - - \ No newline at end of file diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.TestCommon/PortManager.cs b/test/Microsoft.AspNetCore.Server.Kestrel.TestCommon/PortManager.cs deleted file mode 100644 index a90f229963..0000000000 --- a/test/Microsoft.AspNetCore.Server.Kestrel.TestCommon/PortManager.cs +++ /dev/null @@ -1,38 +0,0 @@ -using System.Net; -using System.Net.Sockets; - -namespace Microsoft.AspNetCore.Server.Kestrel.TestCommon -{ - public static class PortManager - { - public static int _nextPort = 8001; - public static object _portLock = new object(); - - public static int GetNextPort() - { - lock (_portLock) - { - using (var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)) - { - while (true) - { - try - { - var port = _nextPort++; - socket.Bind(new IPEndPoint(IPAddress.Loopback, port)); - return port; - } - catch (SocketException) - { - // Retry unless exhausted - if (_nextPort == 65536) - { - throw; - } - } - } - } - } - } - } -} \ No newline at end of file diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.TestCommon/project.json b/test/Microsoft.AspNetCore.Server.Kestrel.TestCommon/project.json deleted file mode 100644 index c6f9341a65..0000000000 --- a/test/Microsoft.AspNetCore.Server.Kestrel.TestCommon/project.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "version": "1.0.0-*", - "frameworks": { - "net451": {}, - "netstandard1.3": { - "dependencies": { - "System.Threading": "4.0.11-*", - "System.Net.Sockets": "4.1.0-*" - }, - "imports": [ - "portable-net45+win8" - ] - } - }, - "buildOptions": { - "keyFile": "../../tools/Key.snk" - } -} \ No newline at end of file diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionTests.cs index 3b710b508b..97dde60c89 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionTests.cs @@ -27,7 +27,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests FrameFactory = connectionContext => new Frame( new DummyApplication(httpContext => TaskUtilities.CompletedTask), connectionContext), Memory = memory, - ServerAddress = ServerAddress.FromUrl($"http://localhost:{TestServer.GetNextPort()}"), + ServerAddress = ServerAddress.FromUrl($"http://localhost:0"), Thread = engine.Threads[0] }; var socket = new MockSocket(mockLibuv, Thread.CurrentThread.ManagedThreadId, trace); diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs index aadf9361c1..b8bdffeebf 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs @@ -88,7 +88,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests testContext.App = App; var engine = new KestrelEngine(testContext); engine.Start(1); - var address = ServerAddress.FromUrl($"http://localhost:{TestServer.GetNextPort()}/"); + var address = ServerAddress.FromUrl($"http://localhost:0/"); var started = engine.CreateServer(address); started.Dispose(); engine.Dispose(); @@ -98,14 +98,13 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [MemberData(nameof(ConnectionFilterData))] public void ConnectionCanReadAndWrite(TestServiceContext testContext) { - var port = TestServer.GetNextPort(); testContext.App = App; var engine = new KestrelEngine(testContext); engine.Start(1); - var address = ServerAddress.FromUrl($"http://localhost:{port}/"); + var address = ServerAddress.FromUrl($"http://localhost:0/"); var started = engine.CreateServer(address); - var socket = TestConnection.CreateConnectedLoopbackSocket(port); + var socket = TestConnection.CreateConnectedLoopbackSocket(address.Port); socket.Send(Encoding.ASCII.GetBytes("POST / HTTP/1.0\r\n\r\nHello World")); socket.Shutdown(SocketShutdown.Send); var buffer = new byte[8192]; diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/HttpsConnectionFilterTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/HttpsConnectionFilterTests.cs index 6666335258..e41bced2e6 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/HttpsConnectionFilterTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/HttpsConnectionFilterTests.cs @@ -69,18 +69,17 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var handler = new WinHttpHandler(); handler.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true; #endif - var serverAddress = $"https://localhost:{TestServer.GetNextPort()}/"; var serviceContext = new TestServiceContext(new HttpsConnectionFilter( new HttpsConnectionFilterOptions { ServerCertificate = new X509Certificate2(@"TestResources/testCert.pfx", "testPassword") }, new NoOpConnectionFilter()) ); - using (var server = new TestServer(App, serviceContext, serverAddress)) + using (var server = new TestServer(App, serviceContext, "https://localhost:0/")) { using (var client = new HttpClient(handler)) { - var result = await client.PostAsync(serverAddress, new FormUrlEncodedContent(new[] { + var result = await client.PostAsync($"https://localhost:{server.Port}/", new FormUrlEncodedContent(new[] { new KeyValuePair("content", "Hello World?") })); @@ -114,7 +113,6 @@ namespace Microsoft.AspNetCore.Server.KestrelTests handler.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true; #endif - var serverAddress = $"https://localhost:{TestServer.GetNextPort()}/"; var serviceContext = new TestServiceContext(new HttpsConnectionFilter( new HttpsConnectionFilterOptions { @@ -124,12 +122,12 @@ namespace Microsoft.AspNetCore.Server.KestrelTests new NoOpConnectionFilter()) ); - using (var server = new TestServer(App, serviceContext, serverAddress)) + using (var server = new TestServer(App, serviceContext, "https://localhost:0/")) { using (var client = new HttpClient(handler)) { await Assert.ThrowsAnyAsync( - () => client.GetAsync(serverAddress)); + () => client.GetAsync($"https://localhost:{server.Port}/")); } } } @@ -159,7 +157,6 @@ namespace Microsoft.AspNetCore.Server.KestrelTests handler.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true; #endif - var serverAddress = $"https://localhost:{TestServer.GetNextPort()}/"; var serviceContext = new TestServiceContext(new HttpsConnectionFilter( new HttpsConnectionFilterOptions { @@ -175,11 +172,11 @@ namespace Microsoft.AspNetCore.Server.KestrelTests return context.Response.WriteAsync("hello world"); }; - using (var server = new TestServer(app, serviceContext, serverAddress)) + using (var server = new TestServer(app, serviceContext, "https://localhost:0/")) { using (var client = new HttpClient(handler)) { - var result = await client.GetAsync(serverAddress); + var result = await client.GetAsync($"https://localhost:{server.Port}/"); Assert.Equal("hello world", await result.Content.ReadAsStringAsync()); } @@ -206,7 +203,6 @@ namespace Microsoft.AspNetCore.Server.KestrelTests ServicePointManager.ServerCertificateValidationCallback += validationCallback; #endif - var serverAddress = $"https://localhost:{TestServer.GetNextPort()}/"; var serviceContext = new TestServiceContext(new HttpsConnectionFilter( new HttpsConnectionFilterOptions { @@ -226,7 +222,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests return context.Response.WriteAsync("hello world"); }; - using (var server = new TestServer(app, serviceContext, serverAddress)) + using (var server = new TestServer(app, serviceContext, "https://localhost:0/")) { // SslStream is used to ensure the certificate is actually passed to the server // HttpClient might not send the certificate because it is invalid or it doesn't match any @@ -274,7 +270,6 @@ namespace Microsoft.AspNetCore.Server.KestrelTests handler.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true; #endif - var serverAddress = $"https://localhost:{TestServer.GetNextPort()}/"; var serviceContext = new TestServiceContext( new HttpsConnectionFilter( new HttpsConnectionFilterOptions @@ -286,11 +281,11 @@ namespace Microsoft.AspNetCore.Server.KestrelTests RequestDelegate app = context => context.Response.WriteAsync(context.Request.Scheme); - using (var server = new TestServer(app, serviceContext, serverAddress)) + using (var server = new TestServer(app, serviceContext, "https://localhost:0/")) { using (var client = new HttpClient(handler)) { - var result = await client.GetAsync(serverAddress); + var result = await client.GetAsync($"https://localhost:{server.Port}/"); Assert.Equal("https", await result.Content.ReadAsStringAsync()); } @@ -317,7 +312,6 @@ namespace Microsoft.AspNetCore.Server.KestrelTests ServicePointManager.ServerCertificateValidationCallback += validationCallback; #endif - var serverAddress = $"https://localhost:{TestServer.GetNextPort()}/"; var serviceContext = new TestServiceContext(new HttpsConnectionFilter( new HttpsConnectionFilterOptions { @@ -333,7 +327,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests return context.Response.WriteAsync("hello world"); }; - using (var server = new TestServer(app, serviceContext, serverAddress)) + using (var server = new TestServer(app, serviceContext, "https://localhost:0/")) { // SslStream is used to ensure the certificate is actually passed to the server // HttpClient might not send the certificate because it is invalid or it doesn't match any diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/MultipleLoopTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/MultipleLoopTests.cs index af50bba928..ead65ada56 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/MultipleLoopTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/MultipleLoopTests.cs @@ -128,7 +128,6 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { var pipeName = @"\\.\pipe\ServerPipeDispatchConnections" + Guid.NewGuid().ToString("n"); - var port = TestServer.GetNextPort(); var loop = new UvLoopHandle(_logger); loop.Init(_uv); @@ -158,8 +157,9 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var serverListenTcp = new UvTcpHandle(_logger); serverListenTcp.Init(loop, (a, b) => { }); - var address = ServerAddress.FromUrl($"http://localhost:{port}/"); + var address = ServerAddress.FromUrl($"http://localhost:0/"); serverListenTcp.Bind(address); + var port = serverListenTcp.GetSockIPEndPoint().Port; serverListenTcp.Listen(128, (_1, status, error, _2) => { var serverConnectionTcp = new UvTcpHandle(_logger); diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/NetworkingTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/NetworkingTests.cs index dd5c5044fc..d1baa5c785 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/NetworkingTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/NetworkingTests.cs @@ -76,9 +76,9 @@ namespace Microsoft.AspNetCore.Server.KestrelTests loop.Init(_uv); var tcp = new UvTcpHandle(_logger); tcp.Init(loop, (a, b) => { }); - var port = TestServer.GetNextPort(); - var address = ServerAddress.FromUrl($"http://localhost:{port}/"); + var address = ServerAddress.FromUrl($"http://localhost:0/"); tcp.Bind(address); + var port = tcp.GetSockIPEndPoint().Port; tcp.Listen(10, (stream, status, error, state) => { var tcp2 = new UvTcpHandle(_logger); @@ -105,9 +105,9 @@ namespace Microsoft.AspNetCore.Server.KestrelTests loop.Init(_uv); var tcp = new UvTcpHandle(_logger); tcp.Init(loop, (a, b) => { }); - var port = TestServer.GetNextPort(); - var address = ServerAddress.FromUrl($"http://localhost:{port}/"); + var address = ServerAddress.FromUrl($"http://localhost:0/"); tcp.Bind(address); + var port = tcp.GetSockIPEndPoint().Port; tcp.Listen(10, (_, status, error, state) => { var tcp2 = new UvTcpHandle(_logger); @@ -155,9 +155,9 @@ namespace Microsoft.AspNetCore.Server.KestrelTests loop.Init(_uv); var tcp = new UvTcpHandle(_logger); tcp.Init(loop, (a, b) => { }); - var port = TestServer.GetNextPort(); - var address = ServerAddress.FromUrl($"http://localhost:{port}/"); + var address = ServerAddress.FromUrl($"http://localhost:0/"); tcp.Bind(address); + var port = tcp.GetSockIPEndPoint().Port; tcp.Listen(10, (_, status, error, state) => { var tcp2 = new UvTcpHandle(_logger); diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/ServerAddressFacts.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/ServerAddressFacts.cs index c29a1fdb15..d9beaa05b3 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/ServerAddressFacts.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/ServerAddressFacts.cs @@ -19,27 +19,28 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } [Theory] - [InlineData("://emptyscheme", "", "emptyscheme", 0, "")] - [InlineData("http://localhost", "http", "localhost", 80, "")] - [InlineData("http://www.example.com", "http", "www.example.com", 80, "")] - [InlineData("https://www.example.com", "https", "www.example.com", 443, "")] - [InlineData("http://www.example.com/", "http", "www.example.com", 80, "")] - [InlineData("http://www.example.com/foo?bar=baz", "http", "www.example.com", 80, "/foo?bar=baz")] - [InlineData("http://www.example.com:5000", "http", "www.example.com", 5000, "")] - [InlineData("https://www.example.com:5000", "https", "www.example.com", 5000, "")] - [InlineData("http://www.example.com:5000/", "http", "www.example.com", 5000, "")] - [InlineData("http://www.example.com:NOTAPORT", "http", "www.example.com:NOTAPORT", 80, "")] - [InlineData("https://www.example.com:NOTAPORT", "https", "www.example.com:NOTAPORT", 443, "")] - [InlineData("http://www.example.com:NOTAPORT/", "http", "www.example.com:NOTAPORT", 80, "")] - [InlineData("http://foo:/tmp/kestrel-test.sock:5000/doesn't/matter", "http", "foo:", 80, "/tmp/kestrel-test.sock:5000/doesn't/matter")] - [InlineData("http://unix:foo/tmp/kestrel-test.sock", "http", "unix:foo", 80, "/tmp/kestrel-test.sock")] - [InlineData("http://unix:5000/tmp/kestrel-test.sock", "http", "unix", 5000, "/tmp/kestrel-test.sock")] - [InlineData("http://unix:/tmp/kestrel-test.sock", "http", "unix:/tmp/kestrel-test.sock", 0, "")] - [InlineData("https://unix:/tmp/kestrel-test.sock", "https", "unix:/tmp/kestrel-test.sock", 0, "")] - [InlineData("http://unix:/tmp/kestrel-test.sock:", "http", "unix:/tmp/kestrel-test.sock", 0, "")] - [InlineData("http://unix:/tmp/kestrel-test.sock:/", "http", "unix:/tmp/kestrel-test.sock", 0, "")] - [InlineData("http://unix:/tmp/kestrel-test.sock:5000/doesn't/matter", "http", "unix:/tmp/kestrel-test.sock", 0, "5000/doesn't/matter")] - public void UrlsAreParsedCorrectly(string url, string scheme, string host, int port, string pathBase) + [InlineData("5000", "http", "+", 5000, "/", "http://+:5000/")] + [InlineData("://emptyscheme", "", "emptyscheme", 0, "", "://emptyscheme:0")] + [InlineData("http://localhost", "http", "localhost", 80, "", "http://localhost:80")] + [InlineData("http://www.example.com", "http", "www.example.com", 80, "", "http://www.example.com:80")] + [InlineData("https://www.example.com", "https", "www.example.com", 443, "", "https://www.example.com:443")] + [InlineData("http://www.example.com/", "http", "www.example.com", 80, "", "http://www.example.com:80")] + [InlineData("http://www.example.com/foo?bar=baz", "http", "www.example.com", 80, "/foo?bar=baz", "http://www.example.com:80/foo?bar=baz")] + [InlineData("http://www.example.com:5000", "http", "www.example.com", 5000, "", null)] + [InlineData("https://www.example.com:5000", "https", "www.example.com", 5000, "", null)] + [InlineData("http://www.example.com:5000/", "http", "www.example.com", 5000, "", "http://www.example.com:5000")] + [InlineData("http://www.example.com:NOTAPORT", "http", "www.example.com:NOTAPORT", 80, "", "http://www.example.com:notaport:80")] + [InlineData("https://www.example.com:NOTAPORT", "https", "www.example.com:NOTAPORT", 443, "", "https://www.example.com:notaport:443")] + [InlineData("http://www.example.com:NOTAPORT/", "http", "www.example.com:NOTAPORT", 80, "", "http://www.example.com:notaport:80")] + [InlineData("http://foo:/tmp/kestrel-test.sock:5000/doesn't/matter", "http", "foo:", 80, "/tmp/kestrel-test.sock:5000/doesn't/matter", "http://foo::80/tmp/kestrel-test.sock:5000/doesn't/matter")] + [InlineData("http://unix:foo/tmp/kestrel-test.sock", "http", "unix:foo", 80, "/tmp/kestrel-test.sock", "http://unix:foo:80/tmp/kestrel-test.sock")] + [InlineData("http://unix:5000/tmp/kestrel-test.sock", "http", "unix", 5000, "/tmp/kestrel-test.sock", null)] + [InlineData("http://unix:/tmp/kestrel-test.sock", "http", "unix:/tmp/kestrel-test.sock", 0, "", null)] + [InlineData("https://unix:/tmp/kestrel-test.sock", "https", "unix:/tmp/kestrel-test.sock", 0, "", null)] + [InlineData("http://unix:/tmp/kestrel-test.sock:", "http", "unix:/tmp/kestrel-test.sock", 0, "", "http://unix:/tmp/kestrel-test.sock")] + [InlineData("http://unix:/tmp/kestrel-test.sock:/", "http", "unix:/tmp/kestrel-test.sock", 0, "", "http://unix:/tmp/kestrel-test.sock")] + [InlineData("http://unix:/tmp/kestrel-test.sock:5000/doesn't/matter", "http", "unix:/tmp/kestrel-test.sock", 0, "5000/doesn't/matter", null)] + public void UrlsAreParsedCorrectly(string url, string scheme, string host, int port, string pathBase, string toString) { var serverAddress = ServerAddress.FromUrl(url); @@ -47,6 +48,8 @@ namespace Microsoft.AspNetCore.Server.KestrelTests Assert.Equal(host, serverAddress.Host); Assert.Equal(port, serverAddress.Port); Assert.Equal(pathBase, serverAddress.PathBase); + + Assert.Equal(toString ?? url, serverAddress.ToString()); } [Fact] diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestServer.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/TestServer.cs index 69b876cbf1..c041f5f437 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/TestServer.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/TestServer.cs @@ -6,7 +6,6 @@ using System.Threading; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Server.Kestrel; using Microsoft.AspNetCore.Server.Kestrel.Http; -using Microsoft.AspNetCore.Server.Kestrel.TestCommon; namespace Microsoft.AspNetCore.Server.KestrelTests { @@ -25,7 +24,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } public TestServer(RequestDelegate app, ServiceContext context) - : this(app, context, $"http://localhost:{GetNextPort()}/") + : this(app, context, "http://localhost:0/") { } @@ -58,10 +57,5 @@ namespace Microsoft.AspNetCore.Server.KestrelTests _server.Dispose(); _engine.Dispose(); } - - public static int GetNextPort() - { - return PortManager.GetNextPort(); - } } } \ No newline at end of file diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/project.json b/test/Microsoft.AspNetCore.Server.KestrelTests/project.json index 998df18145..6bb0db82a1 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/project.json +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/project.json @@ -5,7 +5,6 @@ "Microsoft.NETCore.Platforms": "1.0.1-*", "Microsoft.AspNetCore.Server.Kestrel": "1.0.0-*", "Microsoft.AspNetCore.Server.Kestrel.Https": "1.0.0-*", - "Microsoft.AspNetCore.Server.Kestrel.TestCommon": "1.0.0-*", "Microsoft.AspNetCore.Testing": "1.0.0-*", "xunit": "2.1.0" }, From c1e5640a656ddfe6d478cb54a30002de41c25180 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Thu, 21 Apr 2016 14:17:38 -0700 Subject: [PATCH 0713/1662] Don't allow response headers to contain control characters - For the purposes of this commit, control characters are everything < 0x20. - Immediately throw an InvalidOperationException when the header is added to the IHttpResponseFeature.Headers dictionary. --- .../Http/FrameHeaders.Generated.cs | 8 ++++ .../Http/FrameHeaders.cs | 37 +++++++++++++------ .../KnownHeaders.cs | 4 ++ 3 files changed, 38 insertions(+), 11 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameHeaders.Generated.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameHeaders.Generated.cs index 3d9ccbaf3c..bf47376156 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameHeaders.Generated.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameHeaders.Generated.cs @@ -2038,6 +2038,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } protected override void SetValueFast(string key, StringValues value) { + switch (key.Length) { case 13: @@ -2424,10 +2425,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } break; } + Unknown[key] = value; } protected override void AddValueFast(string key, StringValues value) { + switch (key.Length) { case 13: @@ -2990,6 +2993,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } break; } + Unknown.Add(key, value); } protected override bool RemoveFast(string key) @@ -7181,6 +7185,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } protected override void SetValueFast(string key, StringValues value) { + ValidateHeaderCharacters(value); switch (key.Length) { case 13: @@ -7512,10 +7517,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } break; } + ValidateHeaderCharacters(key); Unknown[key] = value; } protected override void AddValueFast(string key, StringValues value) { + ValidateHeaderCharacters(value); switch (key.Length) { case 13: @@ -7991,6 +7998,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } break; } + ValidateHeaderCharacters(key); Unknown.Add(key, value); } protected override bool RemoveFast(string key) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameHeaders.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameHeaders.cs index 596b973575..4bba23dbd3 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameHeaders.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameHeaders.cs @@ -39,21 +39,18 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { get { + // Unlike the IHeaderDictionary version, this getter will throw a KeyNotFoundException. return GetValueFast(key); } set { - if (_isReadOnly) - { - ThrowReadOnlyException(); - } - SetValueFast(key, value); + ((IHeaderDictionary)this)[key] = value; } } protected void ThrowReadOnlyException() { - throw new InvalidOperationException("Headers are readonly, reponse has already started."); + throw new InvalidOperationException("Headers are read-only, response has already started."); } protected void ThrowArgumentException() @@ -140,11 +137,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http void ICollection>.Add(KeyValuePair item) { - if (_isReadOnly) - { - ThrowReadOnlyException(); - } - AddValueFast(item.Key, item.Value); + ((IDictionary)this).Add(item.Key, item.Value); } void IDictionary.Add(string key, StringValues value) @@ -216,5 +209,27 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { return TryGetValueFast(key, out value); } + + public static void ValidateHeaderCharacters(StringValues headerValues) + { + foreach (var value in headerValues) + { + ValidateHeaderCharacters(value); + } + } + + public static void ValidateHeaderCharacters(string headerCharacters) + { + if (headerCharacters != null) + { + foreach (var ch in headerCharacters) + { + if (ch < 0x20) + { + throw new InvalidOperationException(string.Format("Invalid control character in header: 0x{0:X2}", (byte)ch)); + } + } + } + } } } diff --git a/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/KnownHeaders.cs b/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/KnownHeaders.cs index 9f47fdfae0..a51039d540 100644 --- a/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/KnownHeaders.cs +++ b/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/KnownHeaders.cs @@ -299,6 +299,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http }} protected override void SetValueFast(string key, StringValues value) {{ + {(loop.ClassName == "FrameResponseHeaders" ? "ValidateHeaderCharacters(value);" : "")} switch (key.Length) {{{Each(loop.HeadersByLength, byLength => $@" case {byLength.Key}: @@ -313,10 +314,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ")}}} break; ")}}} + {(loop.ClassName == "FrameResponseHeaders" ? "ValidateHeaderCharacters(key);" : "")} Unknown[key] = value; }} protected override void AddValueFast(string key, StringValues value) {{ + {(loop.ClassName == "FrameResponseHeaders" ? "ValidateHeaderCharacters(value);" : "")} switch (key.Length) {{{Each(loop.HeadersByLength, byLength => $@" case {byLength.Key}: @@ -335,6 +338,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ")}}} break; ")}}} + {(loop.ClassName == "FrameResponseHeaders" ? "ValidateHeaderCharacters(key);" : "")} Unknown.Add(key, value); }} protected override bool RemoveFast(string key) From faf81f11f540c5459e222d1fc49dee2209d03fe3 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Mon, 2 May 2016 16:55:41 -0700 Subject: [PATCH 0714/1662] Add response header validation tests --- .../FrameResponseHeadersTests.cs | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameResponseHeadersTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameResponseHeadersTests.cs index 88ea59e93e..07be384d2c 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameResponseHeadersTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameResponseHeadersTests.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; +using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Server.Kestrel; using Microsoft.AspNetCore.Server.Kestrel.Http; using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; @@ -69,5 +70,51 @@ namespace Microsoft.AspNetCore.Server.KestrelTests Assert.False(frame.ResponseHeaders.ContainsKey("Server")); Assert.False(frame.ResponseHeaders.ContainsKey("Date")); } + + [Theory] + [InlineData("Server", "\r\nData")] + [InlineData("Server", "\0Data")] + [InlineData("Server", "Data\r")] + [InlineData("Server", "Da\0ta")] + [InlineData("Server", "Da\u001Fta")] + [InlineData("Unknown-Header", "\r\nData")] + [InlineData("Unknown-Header", "\0Data")] + [InlineData("Unknown-Header", "Data\0")] + [InlineData("Unknown-Header", "Da\nta")] + [InlineData("\r\nServer", "Data")] + [InlineData("Server\r", "Data")] + [InlineData("Ser\0ver", "Data")] + [InlineData("Server\r\n", "Data")] + [InlineData("\u001FServer", "Data")] + [InlineData("Unknown-Header\r\n", "Data")] + [InlineData("\0Unknown-Header", "Data")] + [InlineData("Unknown\r-Header", "Data")] + [InlineData("Unk\nown-Header", "Data")] + public void AddingControlCharactersToHeadersThrows(string key, string value) + { + var responseHeaders = new FrameResponseHeaders(); + + Assert.Throws(() => { + ((IHeaderDictionary)responseHeaders)[key] = value; + }); + + Assert.Throws(() => { + ((IHeaderDictionary)responseHeaders)[key] = new StringValues(new[] { "valid", value }); + }); + + Assert.Throws(() => { + ((IDictionary)responseHeaders)[key] = value; + }); + + Assert.Throws(() => { + var kvp = new KeyValuePair(key, value); + ((ICollection>)responseHeaders).Add(kvp); + }); + + Assert.Throws(() => { + var kvp = new KeyValuePair(key, value); + ((IDictionary)responseHeaders).Add(key, value); + }); + } } } From 132263e767092fc49b6993850a44a55ead702785 Mon Sep 17 00:00:00 2001 From: Nathan Anderson Date: Wed, 4 May 2016 16:50:08 -0700 Subject: [PATCH 0715/1662] narrow lock scope when connections end --- .../Http/Connection.cs | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Connection.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Connection.cs index add23c4389..be6b7a347e 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Connection.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Connection.cs @@ -328,20 +328,20 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http void IConnectionControl.End(ProduceEndType endType) { - lock (_stateLock) + switch (endType) { - switch (endType) - { - case ProduceEndType.ConnectionKeepAlive: - if (_connectionState != ConnectionState.Open) - { - return; - } + case ProduceEndType.ConnectionKeepAlive: + if (_connectionState != ConnectionState.Open) + { + return; + } - Log.ConnectionKeepAlive(ConnectionId); - break; - case ProduceEndType.SocketShutdown: - case ProduceEndType.SocketDisconnect: + Log.ConnectionKeepAlive(ConnectionId); + break; + case ProduceEndType.SocketShutdown: + case ProduceEndType.SocketDisconnect: + lock (_stateLock) + { if (_connectionState == ConnectionState.Disconnecting || _connectionState == ConnectionState.SocketClosed) { @@ -352,7 +352,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http Log.ConnectionDisconnect(ConnectionId); _rawSocketOutput.End(endType); break; - } + } } } From 4c39374dc063487886f93cc2460a03e26a213a2f Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Wed, 4 May 2016 16:45:59 -0700 Subject: [PATCH 0716/1662] Always check if block is last in linked list before consuming it - This prevents a race where we could read into the "Next" Block without completely consuming the previous one. --- .../Infrastructure/MemoryPoolIterator.cs | 74 ++++++++++++------- 1 file changed, 47 insertions(+), 27 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPoolIterator.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPoolIterator.cs index 286862ce4b..8d65c5c377 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPoolIterator.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPoolIterator.cs @@ -68,6 +68,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure } var index = _index; + var wasLastBlock = block.Next == null; if (index < block.End) { @@ -77,7 +78,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure do { - if (block.Next == null) + if (wasLastBlock) { return -1; } @@ -87,6 +88,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure index = block.Start; } + wasLastBlock = block.Next == null; + if (index < block.End) { _block = block; @@ -102,7 +105,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure { return; } + + var wasLastBlock = _block.Next == null; var following = _block.End - _index; + if (following >= bytesToSkip) { _index += bytesToSkip; @@ -113,7 +119,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure var index = _index; while (true) { - if (block.Next == null) + if (wasLastBlock) { return; } @@ -123,7 +129,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure block = block.Next; index = block.Start; } + + wasLastBlock = block.Next == null; following = block.End - index; + if (following >= bytesToSkip) { _block = block; @@ -141,6 +150,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure return -1; } + var wasLastBlock = _block.Next == null; var index = _index; if (index < block.End) @@ -150,7 +160,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure do { - if (block.Next == null) + if (wasLastBlock) { return -1; } @@ -160,6 +170,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure index = block.Start; } + wasLastBlock = block.Next == null; + if (index < block.End) { return block.Array[index]; @@ -173,14 +185,17 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure { return -1; } - else if (_block.End - _index >= sizeof(long)) + + var wasLastBlock = _block.Next == null; + + if (_block.End - _index >= sizeof(long)) { fixed (byte* ptr = &_block.Array[_index]) { return *(long*)(ptr); } } - else if (_block.Next == null) + else if (wasLastBlock) { return -1; } @@ -219,6 +234,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure var block = _block; var index = _index; + var wasLastBlock = block.Next == null; var following = block.End - index; byte[] array; var byte0 = byte0Vector[0]; @@ -227,16 +243,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure { while (following == 0) { - var newBlock = block.Next; - if (newBlock == null) + if (wasLastBlock) { _block = block; _index = index; return -1; } - index = newBlock.Start; - following = newBlock.End - index; - block = newBlock; + block = block.Next; + index = block.Start; + wasLastBlock = block.Next == null; + following = block.End - index; } array = block.Array; while (following > 0) @@ -298,6 +314,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure var block = _block; var index = _index; + var wasLastBlock = block.Next == null; var following = block.End - index; byte[] array; int byte0Index = int.MaxValue; @@ -309,16 +326,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure { while (following == 0) { - var newBlock = block.Next; - if (newBlock == null) + if (wasLastBlock) { _block = block; _index = index; return -1; } - index = newBlock.Start; - following = newBlock.End - index; - block = newBlock; + block = block.Next; + index = block.Start; + wasLastBlock = block.Next == null; + following = block.End - index; } array = block.Array; while (following > 0) @@ -405,6 +422,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure var block = _block; var index = _index; + var wasLastBlock = block.Next == null; var following = block.End - index; byte[] array; int byte0Index = int.MaxValue; @@ -418,16 +436,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure { while (following == 0) { - var newBlock = block.Next; - if (newBlock == null) + if (wasLastBlock) { _block = block; _index = index; return -1; } - index = newBlock.Start; - following = newBlock.End - index; - block = newBlock; + block = block.Next; + index = block.Start; + wasLastBlock = block.Next == null; + following = block.End - index; } array = block.Array; while (following > 0) @@ -605,16 +623,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure { return false; } - else if (_index < _block.End) - { - _block.Array[_index++] = data; - return true; - } var block = _block; var index = _index; while (true) { + var wasLastBlock = block.Next == null; + if (index < block.End) { _block = block; @@ -622,7 +637,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure block.Array[index] = data; return true; } - else if (block.Next == null) + else if (wasLastBlock) { return false; } @@ -679,6 +694,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure var remaining = count; while (true) { + // Determine if we might attempt to copy data from block.Next before + // calculating "following" so we don't risk skipping data that could + // be added after block.End when we decide to copy from block.Next. + // block.End will always be advanced before block.Next is set. + var wasLastBlock = block.Next == null; var following = block.End - index; if (remaining <= following) { @@ -689,7 +709,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure } return new MemoryPoolIterator(block, index + remaining); } - else if (block.Next == null) + else if (wasLastBlock) { actual = count - remaining + following; if (array != null) From 12a3816c122f0d86968922480bd2e53f42bde365 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Thu, 5 May 2016 15:00:58 -0700 Subject: [PATCH 0717/1662] Make some MemoryPoolBlock operations volatile - Making MemoryPoolBlock.End volatile and using Volatile.Write for MemoryPoolBlock.Next prevents a race that could cause threads consuming blocks to skip produced bytes. --- src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketInput.cs | 2 +- .../Infrastructure/MemoryPoolBlock.cs | 6 +++--- .../Infrastructure/MemoryPoolIterator.cs | 5 +++-- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketInput.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketInput.cs index 1588e83011..40532e17b4 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketInput.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketInput.cs @@ -105,7 +105,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } else { - _tail.Next = _pinned; + Volatile.Write(ref _tail.Next, _pinned); _tail = _pinned; } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPoolBlock.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPoolBlock.cs index 25cab8c4f4..1bcd60ecaa 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPoolBlock.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPoolBlock.cs @@ -57,14 +57,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure /// the Start is guaranteed to be equal to Array.Offset. The value of Start may be assigned anywhere between Data.Offset and /// Data.Offset + Data.Count, and must be equal to or less than End. /// - public int Start { get; set; } + public int Start; /// /// The End represents the offset into Array where the range of "active" bytes ends. At the point when the block is leased /// the End is guaranteed to be equal to Array.Offset. The value of Start may be assigned anywhere between Data.Offset and /// Data.Offset + Data.Count, and must be equal to or less than End. /// - public int End { get; set; } + public volatile int End; /// /// Reference to the next block of data when the overall "active" bytes spans multiple blocks. At the point when the block is @@ -72,7 +72,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure /// working memory. The "active" memory is grown when bytes are copied in, End is increased, and Next is assigned. The "active" /// memory is shrunk when bytes are consumed, Start is increased, and blocks are returned to the pool. /// - public MemoryPoolBlock Next { get; set; } + public MemoryPoolBlock Next; ~MemoryPoolBlock() { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPoolIterator.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPoolIterator.cs index 8d65c5c377..202d15191f 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPoolIterator.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPoolIterator.cs @@ -4,6 +4,7 @@ using System; using System.Diagnostics; using System.Numerics; +using System.Threading; namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure { @@ -767,7 +768,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure { var nextBlock = pool.Lease(); block.End = blockIndex; - block.Next = nextBlock; + Volatile.Write(ref block.Next, nextBlock); block = nextBlock; blockIndex = block.Data.Offset; @@ -820,7 +821,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure { var nextBlock = pool.Lease(); block.End = blockIndex; - block.Next = nextBlock; + Volatile.Write(ref block.Next, nextBlock); block = nextBlock; blockIndex = block.Data.Offset; From 0e8cbe5df668ef5f1b0d32c8473f73cb0d56e515 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Tue, 10 May 2016 01:18:24 +0100 Subject: [PATCH 0718/1662] Return SocketInput blocks out of lock --- .../Http/SocketInput.cs | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketInput.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketInput.cs index 40532e17b4..1b49246b92 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketInput.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketInput.cs @@ -175,11 +175,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http MemoryPoolIterator consumed, MemoryPoolIterator examined) { + MemoryPoolBlock returnStart = null; + MemoryPoolBlock returnEnd = null; + lock (_sync) { - MemoryPoolBlock returnStart = null; - MemoryPoolBlock returnEnd = null; - if (!consumed.IsDefault) { returnStart = _head; @@ -200,18 +200,18 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http _awaitableIsNotCompleted, _awaitableIsCompleted); } + } - while (returnStart != returnEnd) - { - var returnBlock = returnStart; - returnStart = returnStart.Next; - returnBlock.Pool.Return(returnBlock); - } + while (returnStart != returnEnd) + { + var returnBlock = returnStart; + returnStart = returnStart.Next; + returnBlock.Pool.Return(returnBlock); + } - if (Interlocked.CompareExchange(ref _consumingState, 0, 1) != 1) - { - throw new InvalidOperationException("No ongoing consuming operation to complete."); - } + if (Interlocked.CompareExchange(ref _consumingState, 0, 1) != 1) + { + throw new InvalidOperationException("No ongoing consuming operation to complete."); } } From a3b0f809de3b8568d0e98208d4e1eb1acebec63c Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Sat, 7 May 2016 01:28:24 +0100 Subject: [PATCH 0719/1662] Only call PrepareDateValues if not already called for tick --- .../Http/DateHeaderValueManager.cs | 62 ++++++++++--------- .../Http/Frame.cs | 9 +-- .../Infrastructure/HttpComponentFactory.cs | 5 +- .../DateHeaderValueManagerTests.cs | 14 ++--- .../TestDateHeaderValueManager.cs | 16 ----- .../TestServiceContext.cs | 2 +- 6 files changed, 47 insertions(+), 61 deletions(-) delete mode 100644 test/Microsoft.AspNetCore.Server.KestrelTests/TestDateHeaderValueManager.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/DateHeaderValueManager.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/DateHeaderValueManager.cs index 45e91194d6..d7022ab2dd 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/DateHeaderValueManager.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/DateHeaderValueManager.cs @@ -13,15 +13,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http /// public class DateHeaderValueManager : IDisposable { + private static readonly byte[] _datePreambleBytes = Encoding.ASCII.GetBytes("\r\nDate: "); + private readonly ISystemClock _systemClock; private readonly TimeSpan _timeWithoutRequestsUntilIdle; private readonly TimeSpan _timerInterval; + private readonly object _timerLocker = new object(); + + private DateHeaderValues _dateValues; - private volatile string _dateValue; - private volatile bool _activeDateBytes; - private readonly byte[] _dateBytes0 = Encoding.ASCII.GetBytes("\r\nDate: DDD, dd mmm yyyy hh:mm:ss GMT"); - private readonly byte[] _dateBytes1 = Encoding.ASCII.GetBytes("\r\nDate: DDD, dd mmm yyyy hh:mm:ss GMT"); - private object _timerLocker = new object(); private volatile bool _isDisposed = false; private volatile bool _hadRequestsSinceLastTimerTick = false; private Timer _dateValueTimer; @@ -55,19 +55,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http /// Returns a value representing the current server date/time for use in the HTTP "Date" response header /// in accordance with http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.18 /// - /// The value. - public virtual string GetDateHeaderValue() + /// The value in string and byte[] format. + public DateHeaderValues GetDateHeaderValues() { - _hadRequestsSinceLastTimerTick = true; - PrepareDateValues(); - return _dateValue; - } + if (!_hadRequestsSinceLastTimerTick) + { + PrepareDateValues(); + } - public byte[] GetDateHeaderValueBytes() - { - _hadRequestsSinceLastTimerTick = true; - PrepareDateValues(); - return _activeDateBytes ? _dateBytes0 : _dateBytes1; + return _dateValues; } /// @@ -78,6 +74,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if (!_isDisposed) { _isDisposed = true; + _hadRequestsSinceLastTimerTick = false; lock (_timerLocker) { @@ -125,6 +122,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { _timerIsRunning = false; _dateValueTimer.Change(Timeout.Infinite, Timeout.Infinite); + _hadRequestsSinceLastTimerTick = false; } } } @@ -158,16 +156,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http /// private void PrepareDateValues() { - if (_isDisposed) + _hadRequestsSinceLastTimerTick = !_isDisposed; + if (!_timerIsRunning) { - SetDateValues(_systemClock.UtcNow); - } - else - { - if (!_timerIsRunning) - { - StartTimer(); - } + StartTimer(); } } @@ -178,9 +170,23 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http private void SetDateValues(DateTimeOffset value) { // See http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.18 for required format of Date header - _dateValue = value.ToString(Constants.RFC1123DateFormat); - Encoding.ASCII.GetBytes(_dateValue, 0, _dateValue.Length, !_activeDateBytes ? _dateBytes0 : _dateBytes1, "\r\nDate: ".Length); - _activeDateBytes = !_activeDateBytes; + var dateValue = value.ToString(Constants.RFC1123DateFormat); + var dateBytes = new byte[_datePreambleBytes.Length + dateValue.Length]; + Buffer.BlockCopy(_datePreambleBytes, 0, dateBytes, 0, _datePreambleBytes.Length); + Encoding.ASCII.GetBytes(dateValue, 0, dateValue.Length, dateBytes, _datePreambleBytes.Length); + + var dateValues = new DateHeaderValues() + { + Bytes = dateBytes, + String = dateValue + }; + Volatile.Write(ref _dateValues, dateValues); + } + + public class DateHeaderValues + { + public byte[] Bytes; + public string String; } } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs index 4ed675767c..bbae130ad0 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs @@ -589,12 +589,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http var responseHeaders = _frameHeaders.ResponseHeaders; responseHeaders.Reset(); - responseHeaders.SetRawDate( - DateHeaderValueManager.GetDateHeaderValue(), - DateHeaderValueManager.GetDateHeaderValueBytes()); - responseHeaders.SetRawServer( - "Kestrel", - Headers.BytesServer); + var dateHeaderValues = DateHeaderValueManager.GetDateHeaderValues(); + responseHeaders.SetRawDate(dateHeaderValues.String, dateHeaderValues.Bytes); + responseHeaders.SetRawServer("Kestrel", Headers.BytesServer); responseHeaders.SetRawContentLength("0", _bytesContentLengthZero); ResponseHeaders = responseHeaders; diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/HttpComponentFactory.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/HttpComponentFactory.cs index cacd005b55..2669471cd9 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/HttpComponentFactory.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/HttpComponentFactory.cs @@ -78,9 +78,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure public void Initialize(DateHeaderValueManager dateValueManager) { - ResponseHeaders.SetRawDate( - dateValueManager.GetDateHeaderValue(), - dateValueManager.GetDateHeaderValueBytes()); + var dateHeaderValues = dateValueManager.GetDateHeaderValues(); + ResponseHeaders.SetRawDate(dateHeaderValues.String, dateHeaderValues.Bytes); ResponseHeaders.SetRawServer("Kestrel", BytesServer); } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/DateHeaderValueManagerTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/DateHeaderValueManagerTests.cs index d357ece6ae..0c221cba52 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/DateHeaderValueManagerTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/DateHeaderValueManagerTests.cs @@ -27,7 +27,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests try { - result = dateHeaderValueManager.GetDateHeaderValue(); + result = dateHeaderValueManager.GetDateHeaderValues().String; } finally { @@ -54,9 +54,9 @@ namespace Microsoft.AspNetCore.Server.KestrelTests try { - result1 = dateHeaderValueManager.GetDateHeaderValue(); + result1 = dateHeaderValueManager.GetDateHeaderValues().String; systemClock.UtcNow = future; - result2 = dateHeaderValueManager.GetDateHeaderValue(); + result2 = dateHeaderValueManager.GetDateHeaderValues().String; } finally { @@ -85,11 +85,11 @@ namespace Microsoft.AspNetCore.Server.KestrelTests try { - result1 = dateHeaderValueManager.GetDateHeaderValue(); + result1 = dateHeaderValueManager.GetDateHeaderValues().String; systemClock.UtcNow = future; // Wait for longer than the idle timeout to ensure the timer is stopped await Task.Delay(TimeSpan.FromSeconds(1)); - result2 = dateHeaderValueManager.GetDateHeaderValue(); + result2 = dateHeaderValueManager.GetDateHeaderValues().String; } finally { @@ -114,10 +114,10 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var timerInterval = TimeSpan.FromSeconds(10); var dateHeaderValueManager = new DateHeaderValueManager(systemClock, timeWithoutRequestsUntilIdle, timerInterval); - var result1 = dateHeaderValueManager.GetDateHeaderValue(); + var result1 = dateHeaderValueManager.GetDateHeaderValues().String; dateHeaderValueManager.Dispose(); systemClock.UtcNow = future; - var result2 = dateHeaderValueManager.GetDateHeaderValue(); + var result2 = dateHeaderValueManager.GetDateHeaderValues().String; Assert.Equal(now.ToString(Constants.RFC1123DateFormat), result1); Assert.Equal(future.ToString(Constants.RFC1123DateFormat), result2); diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestDateHeaderValueManager.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/TestDateHeaderValueManager.cs deleted file mode 100644 index f558080e9d..0000000000 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/TestDateHeaderValueManager.cs +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using Microsoft.AspNetCore.Server.Kestrel.Http; - -namespace Microsoft.AspNetCore.Server.KestrelTests -{ - public class TestDateHeaderValueManager : DateHeaderValueManager - { - public override string GetDateHeaderValue() - { - return DateTimeOffset.UtcNow.ToString("r"); - } - } -} diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestServiceContext.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/TestServiceContext.cs index 7cfe7df885..0457345450 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/TestServiceContext.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/TestServiceContext.cs @@ -20,7 +20,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests AppLifetime = new LifetimeNotImplemented(); Log = new TestKestrelTrace(); ThreadPool = new LoggingThreadPool(Log); - DateHeaderValueManager = new TestDateHeaderValueManager(); + DateHeaderValueManager = new DateHeaderValueManager(); ServerOptions = new KestrelServerOptions(); ServerOptions.ShutdownTimeout = TimeSpan.FromSeconds(5); From 3186e1bd72df577274f0e8bd63aa50c511bff4b4 Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Thu, 28 Apr 2016 17:39:02 -0700 Subject: [PATCH 0720/1662] Make TakeStartLine more robust (#683). --- .../Http/Frame.cs | 175 +++++++++++++----- .../Http/FrameOfT.cs | 113 ++++++----- .../Http/MessageBody.cs | 29 +-- .../Infrastructure/MemoryPoolIterator.cs | 14 +- .../MemoryPoolIteratorExtensions.cs | 35 ++-- .../BadHttpRequestTests.cs | 72 +++++++ .../ChunkedRequestTests.cs | 10 +- .../EngineTests.cs | 78 ++++++-- .../MemoryPoolIteratorTests.cs | 44 ++++- 9 files changed, 397 insertions(+), 173 deletions(-) create mode 100644 test/Microsoft.AspNetCore.Server.KestrelTests/BadHttpRequestTests.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs index 4ed675767c..feeca29db9 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs @@ -35,6 +35,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http private static readonly byte[] _bytesContentLengthZero = Encoding.ASCII.GetBytes("\r\nContent-Length: 0"); private static readonly byte[] _bytesSpace = Encoding.ASCII.GetBytes(" "); private static readonly byte[] _bytesEndHeaders = Encoding.ASCII.GetBytes("\r\n\r\n"); + private static readonly int _httpVersionLength = "HTTP/1.*".Length; private static Vector _vectorCRs = new Vector((byte)'\r'); private static Vector _vectorColons = new Vector((byte)':'); @@ -45,7 +46,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http private readonly object _onStartingSync = new Object(); private readonly object _onCompletedSync = new Object(); - protected bool _corruptedRequest = false; + private bool _requestRejected; private Headers _frameHeaders; private Streams _frameStreams; @@ -60,7 +61,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http protected CancellationTokenSource _abortedCts; protected CancellationToken? _manuallySetRequestAbortToken; - protected bool _responseStarted; + protected RequestProcessingStatus _requestProcessingStatus; protected bool _keepAlive; private bool _autoChunk; protected Exception _applicationException; @@ -96,7 +97,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { return "HTTP/1.0"; } - return ""; + return string.Empty; } set { @@ -167,9 +168,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http return cts; } } + public bool HasResponseStarted { - get { return _responseStarted; } + get { return _requestProcessingStatus == RequestProcessingStatus.ResponseStarted; } } protected FrameRequestHeaders FrameRequestHeaders => _frameHeaders.RequestHeaders; @@ -216,7 +218,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http _onStarting = null; _onCompleted = null; - _responseStarted = false; + _requestProcessingStatus = RequestProcessingStatus.RequestPending; _keepAlive = false; _autoChunk = false; _applicationException = null; @@ -446,7 +448,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http public Task WriteAsync(ArraySegment data, CancellationToken cancellationToken) { - if (!_responseStarted) + if (!HasResponseStarted) { return WriteAsyncAwaited(data, cancellationToken); } @@ -506,7 +508,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http public void ProduceContinue() { - if (_responseStarted) return; + if (HasResponseStarted) + { + return; + } StringValues expect; if (_httpVersion == HttpVersionType.Http1_1 && @@ -519,7 +524,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http public Task ProduceStartAndFireOnStarting() { - if (_responseStarted) return TaskUtilities.CompletedTask; + if (HasResponseStarted) + { + return TaskUtilities.CompletedTask; + } if (_onStarting != null) { @@ -554,30 +562,49 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http private void ProduceStart(bool appCompleted) { - if (_responseStarted) return; - _responseStarted = true; + if (HasResponseStarted) + { + return; + } + + _requestProcessingStatus = RequestProcessingStatus.ResponseStarted; var statusBytes = ReasonPhrases.ToStatusBytes(StatusCode, ReasonPhrase); CreateResponseHeader(statusBytes, appCompleted); } + protected Task TryProduceInvalidRequestResponse() + { + if (_requestProcessingStatus == RequestProcessingStatus.RequestStarted && _requestRejected) + { + if (_frameHeaders == null) + { + InitializeHeaders(); + } + + return ProduceEnd(); + } + + return TaskUtilities.CompletedTask; + } + protected Task ProduceEnd() { - if (_corruptedRequest || _applicationException != null) + if (_requestRejected || _applicationException != null) { - if (_corruptedRequest) + if (_requestRejected) { // 400 Bad Request StatusCode = 400; - } + } else { // 500 Internal Server Error StatusCode = 500; } - if (_responseStarted) + if (HasResponseStarted) { // We can no longer respond with a 500, so we simply close the connection. _requestProcessingStopping = true; @@ -601,7 +628,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } - if (!_responseStarted) + if (!HasResponseStarted) { return ProduceEndAwaited(); } @@ -709,31 +736,50 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http SocketOutput.ProducingComplete(end); } - protected bool TakeStartLine(SocketInput input) + protected RequestLineStatus TakeStartLine(SocketInput input) { var scan = input.ConsumingStart(); var consumed = scan; + try { + // We may hit this when the client has stopped sending data but + // the connection hasn't closed yet, and therefore Frame.Stop() + // hasn't been called yet. + if (scan.Peek() == -1) + { + return RequestLineStatus.Empty; + } + + _requestProcessingStatus = RequestProcessingStatus.RequestStarted; + string method; var begin = scan; - if (!begin.GetKnownMethod(ref scan, out method)) + if (!begin.GetKnownMethod(out method)) { if (scan.Seek(ref _vectorSpaces) == -1) { - return false; + return RequestLineStatus.MethodIncomplete; } + method = begin.GetAsciiString(scan); - scan.Take(); + if (method == null) + { + RejectRequest("Missing method."); + } + } + else + { + scan.Skip(method.Length); } + scan.Take(); begin = scan; - var needDecode = false; var chFound = scan.Seek(ref _vectorSpaces, ref _vectorQuestionMarks, ref _vectorPercentages); if (chFound == -1) { - return false; + return RequestLineStatus.TargetIncomplete; } else if (chFound == '%') { @@ -741,7 +787,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http chFound = scan.Seek(ref _vectorSpaces, ref _vectorQuestionMarks); if (chFound == -1) { - return false; + return RequestLineStatus.TargetIncomplete; } } @@ -752,35 +798,61 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if (chFound == '?') { begin = scan; - if (scan.Seek(ref _vectorSpaces) != ' ') + if (scan.Seek(ref _vectorSpaces) == -1) { - return false; + return RequestLineStatus.TargetIncomplete; } queryString = begin.GetAsciiString(scan); } + if (pathBegin.Peek() == ' ') + { + RejectRequest("Missing request target."); + } + scan.Take(); begin = scan; + if (scan.Seek(ref _vectorCRs) == -1) + { + return RequestLineStatus.VersionIncomplete; + } string httpVersion; - if (!begin.GetKnownVersion(ref scan, out httpVersion)) + if (!begin.GetKnownVersion(out httpVersion)) { - scan = begin; - if (scan.Seek(ref _vectorCRs) == -1) - { - return false; - } + // A slower fallback is necessary since the iterator's PeekLong() method + // used in GetKnownVersion() only examines two memory blocks at most. + // Although unlikely, it is possible that the 8 bytes forming the version + // could be spread out on more than two blocks, if the connection + // happens to be unusually slow. httpVersion = begin.GetAsciiString(scan); - scan.Take(); - } - if (scan.Take() != '\n') - { - return false; + if (httpVersion == null) + { + RejectRequest("Missing HTTP version."); + } + else if (httpVersion != "HTTP/1.0" && httpVersion != "HTTP/1.1") + { + RejectRequest("Malformed request."); + } } - // URIs are always encoded/escaped to ASCII https://tools.ietf.org/html/rfc3986#page-11 - // Multibyte Internationalized Resource Identifiers (IRIs) are first converted to utf8; + // HttpVersion must be set here to send correct response when request is rejected + HttpVersion = httpVersion; + + scan.Take(); + var next = scan.Take(); + if (next == -1) + { + return RequestLineStatus.Incomplete; + } + else if (next != '\n') + { + RejectRequest("Missing LF in request line."); + } + + // URIs are always encoded/escaped to ASCII https://tools.ietf.org/html/rfc3986#page-11 + // Multibyte Internationalized Resource Identifiers (IRIs) are first converted to utf8; // then encoded/escaped to ASCII https://www.ietf.org/rfc/rfc3987.txt "Mapping of IRIs to URIs" string requestUrlPath; if (needDecode) @@ -802,7 +874,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http Method = method; RequestUri = requestUrlPath; QueryString = queryString; - HttpVersion = httpVersion; bool caseMatches; @@ -818,7 +889,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http Path = requestUrlPath; } - return true; + return RequestLineStatus.Done; } finally { @@ -881,7 +952,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http return true; } - ReportCorruptedHttpRequest(new BadHttpRequestException("Headers corrupted, invalid header sequence.")); + RejectRequest("Headers corrupted, invalid header sequence."); // Headers corrupted, parsing headers is complete return true; } @@ -994,10 +1065,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http statusCode != 304; } - public void ReportCorruptedHttpRequest(BadHttpRequestException ex) + public void RejectRequest(string message) { - _corruptedRequest = true; + _requestProcessingStopping = true; + _requestRejected = true; + var ex = new BadHttpRequestException(message); Log.ConnectionBadRequest(ConnectionId, ex); + throw ex; } protected void ReportApplicationError(Exception ex) @@ -1024,5 +1098,22 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http Http1_0 = 0, Http1_1 = 1 } + + protected enum RequestLineStatus + { + Empty, + MethodIncomplete, + TargetIncomplete, + VersionIncomplete, + Incomplete, + Done + } + + protected enum RequestProcessingStatus + { + RequestPending, + RequestStarted, + ResponseStarted + } } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameOfT.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameOfT.cs index 21eeaa1c6a..6c03a812d2 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameOfT.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameOfT.cs @@ -5,7 +5,6 @@ using System; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Hosting.Server; -using Microsoft.AspNetCore.Server.Kestrel.Exceptions; using Microsoft.Extensions.Logging; namespace Microsoft.AspNetCore.Server.Kestrel.Http @@ -33,7 +32,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { while (!_requestProcessingStopping) { - while (!_requestProcessingStopping && !TakeStartLine(SocketInput)) + while (!_requestProcessingStopping && TakeStartLine(SocketInput) != RequestLineStatus.Done) { if (SocketInput.RemoteIntakeFin) { @@ -41,12 +40,19 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http // SocketInput.RemoteIntakeFin is set to true to ensure we don't close a // connection without giving the application a chance to respond to a request // sent immediately before the a FIN from the client. - if (TakeStartLine(SocketInput)) + var requestLineStatus = TakeStartLine(SocketInput); + + if (requestLineStatus == RequestLineStatus.Empty) { - break; + return; } - return; + if (requestLineStatus != RequestLineStatus.Done) + { + RejectRequest($"Malformed request: {requestLineStatus}"); + } + + break; } await SocketInput; @@ -62,12 +68,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http // SocketInput.RemoteIntakeFin is set to true to ensure we don't close a // connection without giving the application a chance to respond to a request // sent immediately before the a FIN from the client. - if (TakeMessageHeaders(SocketInput, FrameRequestHeaders)) + if (!TakeMessageHeaders(SocketInput, FrameRequestHeaders)) { - break; + RejectRequest($"Malformed request: invalid headers."); } - return; + break; } await SocketInput; @@ -83,66 +89,55 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http _abortedCts = null; _manuallySetRequestAbortToken = null; - if (!_corruptedRequest) + var context = _application.CreateContext(this); + try { - var context = _application.CreateContext(this); - try + await _application.ProcessRequestAsync(context).ConfigureAwait(false); + } + catch (Exception ex) + { + ReportApplicationError(ex); + } + finally + { + // Trigger OnStarting if it hasn't been called yet and the app hasn't + // already failed. If an OnStarting callback throws we can go through + // our normal error handling in ProduceEnd. + // https://github.com/aspnet/KestrelHttpServer/issues/43 + if (!HasResponseStarted && _applicationException == null && _onStarting != null) { - await _application.ProcessRequestAsync(context).ConfigureAwait(false); - } - catch (Exception ex) - { - ReportApplicationError(ex); - } - finally - { - // Trigger OnStarting if it hasn't been called yet and the app hasn't - // already failed. If an OnStarting callback throws we can go through - // our normal error handling in ProduceEnd. - // https://github.com/aspnet/KestrelHttpServer/issues/43 - if (!_responseStarted && _applicationException == null && _onStarting != null) - { - await FireOnStarting(); - } - - PauseStreams(); - - if (_onCompleted != null) - { - await FireOnCompleted(); - } - - _application.DisposeContext(context, _applicationException); + await FireOnStarting(); } - // If _requestAbort is set, the connection has already been closed. - if (Volatile.Read(ref _requestAborted) == 0) + PauseStreams(); + + if (_onCompleted != null) { - ResumeStreams(); - - if (_keepAlive && !_corruptedRequest) - { - try - { - // Finish reading the request body in case the app did not. - await messageBody.Consume(); - } - catch (BadHttpRequestException ex) - { - ReportCorruptedHttpRequest(ex); - } - } - - await ProduceEnd(); + await FireOnCompleted(); } - StopStreams(); + _application.DisposeContext(context, _applicationException); } - if (!_keepAlive || _corruptedRequest) + // If _requestAbort is set, the connection has already been closed. + if (Volatile.Read(ref _requestAborted) == 0) { - // End the connection for non keep alive and Bad Requests - // as data incoming may have been thrown off + ResumeStreams(); + + if (_keepAlive) + { + // Finish reading the request body in case the app did not. + await messageBody.Consume(); + } + + await ProduceEnd(); + } + + StopStreams(); + + if (!_keepAlive) + { + // End the connection for non keep alive as data incoming may have been thrown off return; } } @@ -158,6 +153,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { try { + await TryProduceInvalidRequestResponse(); + ResetComponents(); _abortedCts = null; diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/MessageBody.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/MessageBody.cs index 3a151fc560..7bf6c1d7e6 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/MessageBody.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/MessageBody.cs @@ -59,7 +59,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http return ConsumeAwaited(result.AsTask(), cancellationToken); } // ValueTask uses .GetAwaiter().GetResult() if necessary - else if (result.Result == 0) + else if (result.Result == 0) { // Completed Task, end of stream return TaskUtilities.CompletedTask; @@ -125,8 +125,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http long contentLength; if (!long.TryParse(unparsedContentLength, out contentLength) || contentLength < 0) { - context.ReportCorruptedHttpRequest(new BadHttpRequestException("Invalid content length.")); - return new ForContentLength(keepAlive, 0, context); + context.RejectRequest($"Invalid content length: {unparsedContentLength}"); } else { @@ -142,15 +141,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http return new ForRemainingData(context); } - private int ThrowBadRequestException(string message) - { - // returns int so can be used as item non-void function - var ex = new BadHttpRequestException(message); - _context.ReportCorruptedHttpRequest(ex); - - throw ex; - } - private class ForRemainingData : MessageBody { public ForRemainingData(Frame context) @@ -197,7 +187,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http _inputLength -= actual; if (actual == 0) { - ThrowBadRequestException("Unexpected end of request content"); + _context.RejectRequest("Unexpected end of request content"); } return actual; } @@ -213,7 +203,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http _inputLength -= actual; if (actual == 0) { - ThrowBadRequestException("Unexpected end of request content"); + _context.RejectRequest("Unexpected end of request content"); } return actual; @@ -514,7 +504,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } else { - ThrowBadRequestException("Bad chunk suffix"); + _context.RejectRequest("Bad chunk suffix"); } } finally @@ -568,16 +558,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { return currentParsedSize * 0x10 + (extraHexDigit - ('a' - 10)); } - else - { - return ThrowBadRequestException("Bad chunk size data"); - } } + + _context.RejectRequest("Bad chunk size data"); + return -1; // can't happen, but compiler complains } private void ThrowChunkedRequestIncomplete() { - ThrowBadRequestException("Chunked request incomplete"); + _context.RejectRequest("Chunked request incomplete"); } private enum Mode diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPoolIterator.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPoolIterator.cs index 3d42fba3b9..3e17b6c4b8 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPoolIterator.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPoolIterator.cs @@ -122,7 +122,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure { if (wasLastBlock) { - return; + throw new InvalidOperationException("Attempted to skip more bytes than available."); } else { @@ -248,7 +248,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure while (following > 0) { // Need unit tests to test Vector path -#if !DEBUG +#if !DEBUG // Check will be Jitted away https://github.com/dotnet/coreclr/issues/1079 if (Vector.IsHardwareAccelerated) { @@ -269,7 +269,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure return byte0; } // Need unit tests to test Vector path -#if !DEBUG +#if !DEBUG } #endif @@ -330,7 +330,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure { // Need unit tests to test Vector path -#if !DEBUG +#if !DEBUG // Check will be Jitted away https://github.com/dotnet/coreclr/issues/1079 if (Vector.IsHardwareAccelerated) { @@ -369,7 +369,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure return byte1; } // Need unit tests to test Vector path -#if !DEBUG +#if !DEBUG } #endif var pCurrent = (block.DataFixedPtr + index); @@ -436,7 +436,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure while (following > 0) { // Need unit tests to test Vector path -#if !DEBUG +#if !DEBUG // Check will be Jitted away https://github.com/dotnet/coreclr/issues/1079 if (Vector.IsHardwareAccelerated) { @@ -502,7 +502,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure return toReturn; } // Need unit tests to test Vector path -#if !DEBUG +#if !DEBUG } #endif var pCurrent = (block.DataFixedPtr + index); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPoolIteratorExtensions.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPoolIteratorExtensions.cs index f17dab1394..47410277fd 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPoolIteratorExtensions.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPoolIteratorExtensions.cs @@ -37,7 +37,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure private readonly static long _http10VersionLong = GetAsciiStringAsLong("HTTP/1.0"); private readonly static long _http11VersionLong = GetAsciiStringAsLong("HTTP/1.1"); - + private readonly static long _mask8Chars = GetMaskAsLong(new byte[] { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }); private readonly static long _mask7Chars = GetMaskAsLong(new byte[] { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00 }); private readonly static long _mask6Chars = GetMaskAsLong(new byte[] { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00 }); @@ -93,7 +93,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure return null; } - // Bytes out of the range of ascii are treated as "opaque data" + // Bytes out of the range of ascii are treated as "opaque data" // and kept in string as a char value that casts to same input byte value // https://tools.ietf.org/html/rfc7230#section-3.2.4 @@ -283,16 +283,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure /// /// A "known HTTP method" can be an HTTP method name defined in the HTTP/1.1 RFC. /// Since all of those fit in at most 8 bytes, they can be optimally looked up by reading those bytes as a long. Once - /// in that format, it can be checked against the known method. - /// The Known Methods (CONNECT, DELETE, GET, HEAD, PATCH, POST, PUT, OPTIONS, TRACE) are all less than 8 bytes + /// in that format, it can be checked against the known method. + /// The Known Methods (CONNECT, DELETE, GET, HEAD, PATCH, POST, PUT, OPTIONS, TRACE) are all less than 8 bytes /// and will be compared with the required space. A mask is used if the Known method is less than 8 bytes. /// To optimize performance the GET method will be checked first. /// /// The iterator from which to start the known string lookup. - /// If we found a valid method, then scan will be updated to new position /// A reference to a pre-allocated known string, if the input matches any. /// true if the input matches a known string, false otherwise. - public static bool GetKnownMethod(this MemoryPoolIterator begin, ref MemoryPoolIterator scan, out string knownMethod) + public static bool GetKnownMethod(this MemoryPoolIterator begin, out string knownMethod) { knownMethod = null; var value = begin.PeekLong(); @@ -300,7 +299,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure if ((value & _mask4Chars) == _httpGetMethodLong) { knownMethod = HttpGetMethod; - scan.Skip(4); return true; } foreach (var x in _knownMethods) @@ -308,7 +306,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure if ((value & x.Item1) == x.Item2) { knownMethod = x.Item3; - scan.Skip(knownMethod.Length + 1); return true; } } @@ -327,10 +324,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure /// To optimize performance the HTTP/1.1 will be checked first. /// /// The iterator from which to start the known string lookup. - /// If we found a valid method, then scan will be updated to new position /// A reference to a pre-allocated known string, if the input matches any. /// true if the input matches a known string, false otherwise. - public static bool GetKnownVersion(this MemoryPoolIterator begin, ref MemoryPoolIterator scan, out string knownVersion) + public static bool GetKnownVersion(this MemoryPoolIterator begin, out string knownVersion) { knownVersion = null; var value = begin.PeekLong(); @@ -338,24 +334,23 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure if (value == _http11VersionLong) { knownVersion = Http11Version; - scan.Skip(8); - if (scan.Take() == '\r') - { - return true; - } } else if (value == _http10VersionLong) { knownVersion = Http10Version; - scan.Skip(8); - if (scan.Take() == '\r') + } + + if (knownVersion != null) + { + begin.Skip(knownVersion.Length); + + if (begin.Peek() != '\r') { - return true; + knownVersion = null; } } - knownVersion = null; - return false; + return knownVersion != null; } } } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/BadHttpRequestTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/BadHttpRequestTests.cs new file mode 100644 index 0000000000..8ff6648b0a --- /dev/null +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/BadHttpRequestTests.cs @@ -0,0 +1,72 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Threading.Tasks; +using Xunit; + +namespace Microsoft.AspNetCore.Server.KestrelTests +{ + public class BadHttpRequestTests + { + [Theory] + [InlineData("/ HTTP/1.1\r\n\r\n")] + [InlineData(" / HTTP/1.1\r\n\r\n")] + [InlineData(" / HTTP/1.1\r\n\r\n")] + [InlineData("GET / HTTP/1.1\r\n\r\n")] + [InlineData("GET / HTTP/1.1\r\n\r\n")] + [InlineData("GET HTTP/1.1\r\n\r\n")] + [InlineData("GET /")] + [InlineData("GET / ")] + [InlineData("GET / H")] + [InlineData("GET / HTTP/1.")] + [InlineData("GET /\r\n")] + [InlineData("GET / \r\n")] + [InlineData("GET / \n")] + [InlineData("GET / http/1.0\r\n\r\n")] + [InlineData("GET / http/1.1\r\n\r\n")] + [InlineData("GET / HTTP/1.1 \r\n\r\n")] + [InlineData("GET / HTTP/1.1a\r\n\r\n")] + [InlineData("GET / HTTP/1.0\n\r\n")] + [InlineData("GET / HTTP/3.0\r\n\r\n")] + [InlineData("GET / H\r\n\r\n")] + [InlineData("GET / HTTP/1.\r\n\r\n")] + [InlineData("GET / hello\r\n\r\n")] + [InlineData("GET / 8charact\r\n\r\n")] + public async Task TestBadRequests(string request) + { + using (var server = new TestServer(context => { return Task.FromResult(0); })) + { + using (var connection = new TestConnection(server.Port)) + { + var receiveTask = Task.Run(async () => + { + await connection.Receive( + "HTTP/1.0 400 Bad Request", + ""); + await connection.ReceiveStartsWith("Date: "); + await connection.ReceiveForcedEnd( + "Content-Length: 0", + "Server: Kestrel", + "", + ""); + }); + + try + { + await connection.SendEnd(request).ConfigureAwait(false); + } + catch (Exception) + { + // TestConnection.SendEnd will start throwing while sending characters + // in cases where the server rejects the request as soon as it + // determines the request line is malformed, even though there + // are more characters following. + } + + await receiveTask; + } + } + } + } +} \ No newline at end of file diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedRequestTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedRequestTests.cs index 8b34273913..6cbe46b947 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedRequestTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedRequestTests.cs @@ -217,7 +217,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests "POST / HTTP/1.1", "Transfer-Encoding: chunked", "", - "C", + "C", "HelloChunked", "0", ""}; @@ -364,10 +364,10 @@ namespace Microsoft.AspNetCore.Server.KestrelTests using (var connection = new TestConnection(server.Port)) { await connection.Send( - "POST / HTTP/1.1", - "Transfer-Encoding: chunked", - "", - "Cii"); + "POST / HTTP/1.1", + "Transfer-Encoding: chunked", + "", + "Cii"); await connection.Receive( "HTTP/1.1 400 Bad Request", diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs index b8bdffeebf..a4508b8893 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs @@ -728,18 +728,13 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { await connection.SendEnd( "GET /"); - await connection.ReceiveEnd(); - } - - using (var connection = new TestConnection(server.Port)) - { - await connection.SendEnd( - "GET / HTTP/1.1", - "", - "Post / HTTP/1.1"); - await connection.ReceiveEnd( - "HTTP/1.1 200 OK", + await connection.Receive( + "HTTP/1.0 400 Bad Request", + ""); + await connection.ReceiveStartsWith("Date:"); + await connection.ReceiveForcedEnd( "Content-Length: 0", + "Server: Kestrel", "", ""); } @@ -749,12 +744,40 @@ namespace Microsoft.AspNetCore.Server.KestrelTests await connection.SendEnd( "GET / HTTP/1.1", "", - "Post / HTTP/1.1", - "Content-Length: 7"); - await connection.ReceiveEnd( + "POST / HTTP/1.1"); + await connection.Receive( "HTTP/1.1 200 OK", "Content-Length: 0", "", + "HTTP/1.0 400 Bad Request", + ""); + await connection.ReceiveStartsWith("Date:"); + await connection.ReceiveForcedEnd( + "Content-Length: 0", + "Server: Kestrel", + "", + ""); + } + + using (var connection = new TestConnection(server.Port)) + { + await connection.SendEnd( + "GET / HTTP/1.1", + "", + "POST / HTTP/1.1", + "Content-Length: 7"); + await connection.Receive( + "HTTP/1.1 200 OK", + "Content-Length: 0", + "", + "HTTP/1.1 400 Bad Request", + "Connection: close", + ""); + await connection.ReceiveStartsWith("Date:"); + await connection.ReceiveForcedEnd( + "Content-Length: 0", + "Server: Kestrel", + "", ""); } } @@ -1017,7 +1040,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests Assert.True(registrationWh.Wait(1000)); } } - + [Theory] [MemberData(nameof(ConnectionFilterData))] public async Task NoErrorsLoggedWhenServerEndsConnectionBeforeClient(ServiceContext testContext) @@ -1049,5 +1072,30 @@ namespace Microsoft.AspNetCore.Server.KestrelTests Assert.Equal(0, testLogger.TotalErrorsLogged); } + + [Theory] + [MemberData(nameof(ConnectionFilterData))] + public async Task NoResponseSentWhenConnectionIsClosedByServerBeforeClientFinishesSendingRequest(ServiceContext testContext) + { + var testLogger = new TestApplicationErrorLogger(); + testContext.Log = new KestrelTrace(testLogger); + + using (var server = new TestServer(httpContext => + { + httpContext.Abort(); + return Task.FromResult(0); + }, testContext)) + { + using (var connection = new TestConnection(server.Port)) + { + await connection.Send( + "POST / HTTP/1.0", + "Content-Length: 1", + "", + ""); + await connection.ReceiveEnd(); + } + } + } } } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolIteratorTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolIteratorTests.cs index 834c99baad..4e8a02c365 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolIteratorTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolIteratorTests.cs @@ -285,6 +285,40 @@ namespace Microsoft.AspNetCore.Server.KestrelTests _pool.Return(nextBlock); } + [Fact] + public void SkipThrowsWhenSkippingMoreBytesThanAvailableInSingleBlock() + { + // Arrange + var block = _pool.Lease(); + block.End += 5; + + var scan = block.GetIterator(); + + // Act/Assert + Assert.ThrowsAny(() => scan.Skip(8)); + + _pool.Return(block); + } + + [Fact] + public void SkipThrowsWhenSkippingMoreBytesThanAvailableInMultipleBlocks() + { + // Arrange + var block = _pool.Lease(); + block.End += 3; + + var nextBlock = _pool.Lease(); + nextBlock.End += 2; + block.Next = nextBlock; + + var scan = block.GetIterator(); + + // Act/Assert + Assert.ThrowsAny(() => scan.Skip(8)); + + _pool.Return(block); + } + [Theory] [InlineData("CONNECT / HTTP/1.1", ' ', true, MemoryPoolIteratorExtensions.HttpConnectMethod)] [InlineData("DELETE / HTTP/1.1", ' ', true, MemoryPoolIteratorExtensions.HttpDeleteMethod)] @@ -309,12 +343,11 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var chars = input.ToCharArray().Select(c => (byte)c).ToArray(); Buffer.BlockCopy(chars, 0, block.Array, block.Start, chars.Length); block.End += chars.Length; - var scan = block.GetIterator(); - var begin = scan; + var begin = block.GetIterator(); string knownString; // Act - var result = begin.GetKnownMethod(ref scan, out knownString); + var result = begin.GetKnownMethod(out knownString); // Assert Assert.Equal(expectedResult, result); @@ -337,12 +370,11 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var chars = input.ToCharArray().Select(c => (byte)c).ToArray(); Buffer.BlockCopy(chars, 0, block.Array, block.Start, chars.Length); block.End += chars.Length; - var scan = block.GetIterator(); - var begin = scan; + var begin = block.GetIterator(); string knownString; // Act - var result = begin.GetKnownVersion(ref scan, out knownString); + var result = begin.GetKnownVersion(out knownString); // Assert Assert.Equal(expectedResult, result); Assert.Equal(expectedKnownString, knownString); From 2cd86a272443394fc9d790777a38d25ddd4be7be Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Thu, 12 May 2016 14:55:56 -0700 Subject: [PATCH 0721/1662] Temporarily disable BadHttpRequestTests. --- .../BadHttpRequestTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/BadHttpRequestTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/BadHttpRequestTests.cs index 8ff6648b0a..af5b238e80 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/BadHttpRequestTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/BadHttpRequestTests.cs @@ -9,7 +9,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { public class BadHttpRequestTests { - [Theory] + [Theory(Skip = "This test fails intermittently and needs to be investigated.")] [InlineData("/ HTTP/1.1\r\n\r\n")] [InlineData(" / HTTP/1.1\r\n\r\n")] [InlineData(" / HTTP/1.1\r\n\r\n")] From 3e841ccba1846f028324ccc13b747f5cfa17e4a3 Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Mon, 16 May 2016 16:11:37 -0700 Subject: [PATCH 0722/1662] Always send HTTP/1.1 responses (#792). --- .../Http/Frame.cs | 11 +++++-- .../BadHttpRequestTests.cs | 2 +- .../ChunkedRequestTests.cs | 6 ++-- .../ConnectionFilterTests.cs | 4 +-- .../EngineTests.cs | 30 +++++++++---------- .../HttpsConnectionFilterTests.cs | 2 +- 6 files changed, 30 insertions(+), 25 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs index feeca29db9..e0696f82f6 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs @@ -30,12 +30,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http private static readonly byte[] _bytesConnectionClose = Encoding.ASCII.GetBytes("\r\nConnection: close"); private static readonly byte[] _bytesConnectionKeepAlive = Encoding.ASCII.GetBytes("\r\nConnection: keep-alive"); private static readonly byte[] _bytesTransferEncodingChunked = Encoding.ASCII.GetBytes("\r\nTransfer-Encoding: chunked"); - private static readonly byte[] _bytesHttpVersion1_0 = Encoding.ASCII.GetBytes("HTTP/1.0 "); private static readonly byte[] _bytesHttpVersion1_1 = Encoding.ASCII.GetBytes("HTTP/1.1 "); private static readonly byte[] _bytesContentLengthZero = Encoding.ASCII.GetBytes("\r\nContent-Length: 0"); private static readonly byte[] _bytesSpace = Encoding.ASCII.GetBytes(" "); private static readonly byte[] _bytesEndHeaders = Encoding.ASCII.GetBytes("\r\n\r\n"); - private static readonly int _httpVersionLength = "HTTP/1.*".Length; private static Vector _vectorCRs = new Vector((byte)'\r'); private static Vector _vectorColons = new Vector((byte)':'); @@ -707,6 +705,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } else { + // Note for future reference: never change this to set _autoChunk to true on HTTP/1.0 + // connections, even if we were to infer the client supports it because an HTTP/1.0 request + // was received that used chunked encoding. Sending a chunked response to an HTTP/1.0 + // client would break compliance with RFC 7230 (section 3.3.1): + // + // A server MUST NOT send a response containing Transfer-Encoding unless the corresponding + // request indicates HTTP/1.1 (or later). if (_httpVersion == HttpVersionType.Http1_1) { _autoChunk = true; @@ -728,7 +733,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http responseHeaders.SetRawConnection("keep-alive", _bytesConnectionKeepAlive); } - end.CopyFrom(_httpVersion == HttpVersionType.Http1_1 ? _bytesHttpVersion1_1 : _bytesHttpVersion1_0); + end.CopyFrom(_bytesHttpVersion1_1); end.CopyFrom(statusBytes); responseHeaders.CopyTo(ref end); end.CopyFrom(_bytesEndHeaders, 0, _bytesEndHeaders.Length); diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/BadHttpRequestTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/BadHttpRequestTests.cs index af5b238e80..512e366688 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/BadHttpRequestTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/BadHttpRequestTests.cs @@ -42,7 +42,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var receiveTask = Task.Run(async () => { await connection.Receive( - "HTTP/1.0 400 Bad Request", + "HTTP/1.1 400 Bad Request", ""); await connection.ReceiveStartsWith("Date: "); await connection.ReceiveForcedEnd( diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedRequestTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedRequestTests.cs index 6cbe46b947..7acafa9883 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedRequestTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedRequestTests.cs @@ -77,7 +77,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests "0", ""); await connection.ReceiveEnd( - "HTTP/1.0 200 OK", + "HTTP/1.1 200 OK", "", "Hello World"); } @@ -105,13 +105,13 @@ namespace Microsoft.AspNetCore.Server.KestrelTests "", "Goodbye"); await connection.Receive( - "HTTP/1.0 200 OK", + "HTTP/1.1 200 OK", "Connection: keep-alive", "Content-Length: 11", "", "Hello World"); await connection.ReceiveEnd( - "HTTP/1.0 200 OK", + "HTTP/1.1 200 OK", "Content-Length: 7", "", "Goodbye"); diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionFilterTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionFilterTests.cs index 8b9451fef8..cb1a7fa182 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionFilterTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionFilterTests.cs @@ -44,7 +44,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests // "?" changes to "!" await connection.SendEnd(sendString); await connection.ReceiveEnd( - "HTTP/1.0 200 OK", + "HTTP/1.1 200 OK", "", "Hello World!"); } @@ -67,7 +67,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests "", "Hello World?"); await connection.ReceiveEnd( - "HTTP/1.0 200 OK", + "HTTP/1.1 200 OK", "", "Hello World!"); } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs index a4508b8893..3432a75de3 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs @@ -121,7 +121,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [Theory] [MemberData(nameof(ConnectionFilterData))] - public async Task Http10(ServiceContext testContext) + public async Task Http10RequestReceivesHttp11Response(ServiceContext testContext) { using (var server = new TestServer(App, testContext)) { @@ -132,7 +132,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests "", "Hello World"); await connection.ReceiveEnd( - "HTTP/1.0 200 OK", + "HTTP/1.1 200 OK", "", "Hello World"); } @@ -268,7 +268,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests "", "Hello World"); await connection.ReceiveEnd( - "HTTP/1.0 200 OK", + "HTTP/1.1 200 OK", "", "Hello World"); } @@ -291,12 +291,12 @@ namespace Microsoft.AspNetCore.Server.KestrelTests "", "Goodbye"); await connection.Receive( - "HTTP/1.0 200 OK", + "HTTP/1.1 200 OK", "Connection: keep-alive", "Content-Length: 0", "\r\n"); await connection.ReceiveEnd( - "HTTP/1.0 200 OK", + "HTTP/1.1 200 OK", "Content-Length: 7", "", "Goodbye"); @@ -322,12 +322,12 @@ namespace Microsoft.AspNetCore.Server.KestrelTests "", "Goodbye"); await connection.Receive( - "HTTP/1.0 200 OK", + "HTTP/1.1 200 OK", "Connection: keep-alive", "Content-Length: 0", "\r\n"); await connection.ReceiveEnd( - "HTTP/1.0 200 OK", + "HTTP/1.1 200 OK", "", "Goodbye"); } @@ -351,13 +351,13 @@ namespace Microsoft.AspNetCore.Server.KestrelTests "", "Goodbye"); await connection.Receive( - "HTTP/1.0 200 OK", + "HTTP/1.1 200 OK", "Connection: keep-alive", "Content-Length: 11", "", "Hello World"); await connection.ReceiveEnd( - "HTTP/1.0 200 OK", + "HTTP/1.1 200 OK", "Content-Length: 7", "", "Goodbye"); @@ -408,7 +408,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests "GET / HTTP/1.0", "\r\n"); await connection.ReceiveEnd( - "HTTP/1.0 200 OK", + "HTTP/1.1 200 OK", "\r\n"); } } @@ -433,7 +433,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests "HTTP/1.1 200 OK", "Content-Length: 0", "", - "HTTP/1.0 200 OK", + "HTTP/1.1 200 OK", "Connection: keep-alive", "Content-Length: 0", "", @@ -469,7 +469,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests "", ""); await connection.ReceiveEnd( - "HTTP/1.0 200 OK", + "HTTP/1.1 200 OK", "", ""); } @@ -729,7 +729,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests await connection.SendEnd( "GET /"); await connection.Receive( - "HTTP/1.0 400 Bad Request", + "HTTP/1.1 400 Bad Request", ""); await connection.ReceiveStartsWith("Date:"); await connection.ReceiveForcedEnd( @@ -749,7 +749,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests "HTTP/1.1 200 OK", "Content-Length: 0", "", - "HTTP/1.0 400 Bad Request", + "HTTP/1.1 400 Bad Request", ""); await connection.ReceiveStartsWith("Date:"); await connection.ReceiveForcedEnd( @@ -1063,7 +1063,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests "", ""); await connection.ReceiveForcedEnd( - "HTTP/1.0 200 OK", + "HTTP/1.1 200 OK", "Content-Length: 11", "", "Hello World"); diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/HttpsConnectionFilterTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/HttpsConnectionFilterTests.cs index e41bced2e6..c0da2cbc5b 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/HttpsConnectionFilterTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/HttpsConnectionFilterTests.cs @@ -240,7 +240,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var reader = new StreamReader(stream); var line = await reader.ReadLineAsync(); - Assert.Equal("HTTP/1.0 200 OK", line); + Assert.Equal("HTTP/1.1 200 OK", line); } } } From 8c8ee150f79d0ed16a14ece21d05e3736dbb83e9 Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Tue, 17 May 2016 10:09:55 -0700 Subject: [PATCH 0723/1662] Send 'Connection: close' in all 400 responses to HTTP/1.1 requests (#840). --- .../Http/Frame.cs | 38 ++--- .../BadHttpRequestTests.cs | 134 ++++++++++++------ .../ChunkedRequestTests.cs | 2 + .../EngineTests.cs | 16 +-- 4 files changed, 110 insertions(+), 80 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs index e0696f82f6..4cb38f317b 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs @@ -30,7 +30,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http private static readonly byte[] _bytesConnectionClose = Encoding.ASCII.GetBytes("\r\nConnection: close"); private static readonly byte[] _bytesConnectionKeepAlive = Encoding.ASCII.GetBytes("\r\nConnection: keep-alive"); private static readonly byte[] _bytesTransferEncodingChunked = Encoding.ASCII.GetBytes("\r\nTransfer-Encoding: chunked"); - private static readonly byte[] _bytesHttpVersion1_1 = Encoding.ASCII.GetBytes("HTTP/1.1 "); + private static readonly byte[] _bytesHttpVersion11 = Encoding.ASCII.GetBytes("HTTP/1.1 "); private static readonly byte[] _bytesContentLengthZero = Encoding.ASCII.GetBytes("\r\nContent-Length: 0"); private static readonly byte[] _bytesSpace = Encoding.ASCII.GetBytes(" "); private static readonly byte[] _bytesEndHeaders = Encoding.ASCII.GetBytes("\r\n\r\n"); @@ -87,29 +87,30 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { get { - if (_httpVersion == HttpVersionType.Http1_1) + if (_httpVersion == HttpVersionType.Http11) { return "HTTP/1.1"; } - if (_httpVersion == HttpVersionType.Http1_0) + if (_httpVersion == HttpVersionType.Http10) { return "HTTP/1.0"; } + return string.Empty; } set { if (value == "HTTP/1.1") { - _httpVersion = HttpVersionType.Http1_1; + _httpVersion = HttpVersionType.Http11; } else if (value == "HTTP/1.0") { - _httpVersion = HttpVersionType.Http1_0; + _httpVersion = HttpVersionType.Http10; } else { - _httpVersion = HttpVersionType.Unknown; + _httpVersion = HttpVersionType.Unset; } } } @@ -229,7 +230,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http PathBase = null; Path = null; QueryString = null; - _httpVersion = HttpVersionType.Unknown; + _httpVersion = HttpVersionType.Unset; StatusCode = 200; ReasonPhrase = null; @@ -512,7 +513,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } StringValues expect; - if (_httpVersion == HttpVersionType.Http1_1 && + if (_httpVersion == HttpVersionType.Http11 && RequestHeaders.TryGetValue("Expect", out expect) && (expect.FirstOrDefault() ?? "").Equals("100-continue", StringComparison.OrdinalIgnoreCase)) { @@ -595,6 +596,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { // 400 Bad Request StatusCode = 400; + _keepAlive = false; } else { @@ -712,7 +714,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http // // A server MUST NOT send a response containing Transfer-Encoding unless the corresponding // request indicates HTTP/1.1 (or later). - if (_httpVersion == HttpVersionType.Http1_1) + if (_httpVersion == HttpVersionType.Http11) { _autoChunk = true; responseHeaders.SetRawTransferEncoding("chunked", _bytesTransferEncodingChunked); @@ -724,16 +726,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } - if (_keepAlive == false && responseHeaders.HasConnection == false && _httpVersion == HttpVersionType.Http1_1) + if (!_keepAlive && !responseHeaders.HasConnection && _httpVersion != HttpVersionType.Http10) { responseHeaders.SetRawConnection("close", _bytesConnectionClose); } - else if (_keepAlive && responseHeaders.HasConnection == false && _httpVersion == HttpVersionType.Http1_0) + else if (_keepAlive && !responseHeaders.HasConnection && _httpVersion == HttpVersionType.Http10) { responseHeaders.SetRawConnection("keep-alive", _bytesConnectionKeepAlive); } - end.CopyFrom(_bytesHttpVersion1_1); + end.CopyFrom(_bytesHttpVersion11); end.CopyFrom(statusBytes); responseHeaders.CopyTo(ref end); end.CopyFrom(_bytesEndHeaders, 0, _bytesEndHeaders.Length); @@ -838,13 +840,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } else if (httpVersion != "HTTP/1.0" && httpVersion != "HTTP/1.1") { - RejectRequest("Malformed request."); + RejectRequest("Unrecognized HTTP version."); } } - // HttpVersion must be set here to send correct response when request is rejected - HttpVersion = httpVersion; - scan.Take(); var next = scan.Take(); if (next == -1) @@ -879,6 +878,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http Method = method; RequestUri = requestUrlPath; QueryString = queryString; + HttpVersion = httpVersion; bool caseMatches; @@ -1099,9 +1099,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http private enum HttpVersionType { - Unknown = -1, - Http1_0 = 0, - Http1_1 = 1 + Unset = -1, + Http10 = 0, + Http11 = 1 } protected enum RequestLineStatus diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/BadHttpRequestTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/BadHttpRequestTests.cs index 512e366688..adc90857db 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/BadHttpRequestTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/BadHttpRequestTests.cs @@ -1,7 +1,6 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System; using System.Threading.Tasks; using Xunit; @@ -9,64 +8,107 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { public class BadHttpRequestTests { - [Theory(Skip = "This test fails intermittently and needs to be investigated.")] - [InlineData("/ HTTP/1.1\r\n\r\n")] - [InlineData(" / HTTP/1.1\r\n\r\n")] - [InlineData(" / HTTP/1.1\r\n\r\n")] - [InlineData("GET / HTTP/1.1\r\n\r\n")] - [InlineData("GET / HTTP/1.1\r\n\r\n")] - [InlineData("GET HTTP/1.1\r\n\r\n")] + // Don't send more data than necessary to fail, otherwise the test throws trying to + // send data after the server has already closed the connection. This would cause the + // test to fail on Windows, due to a winsock limitation: after the error when trying + // to write to the socket closed by the server, winsock disposes all resources used + // by that socket. The test then fails when we try to read the expected response + // from the server because, although it would have been buffered, it got discarded + // by winsock on the send() error. + // The solution for this is for the client to always try to receive before doing + // any sends, that way it can detect that the connection has been closed by the server + // and not try to send() on the closed connection, triggering the error that would cause + // any buffered received data to be lost. + // We do not deem necessary to mitigate this issue in TestConnection, since it would only + // be ensuring that we have a properly implemented HTTP client that can handle the + // winsock issue. There is nothing to be verified in Kestrel in this situation. + [Theory] + // Incomplete request lines + [InlineData("G")] + [InlineData("GE")] + [InlineData("GET")] + [InlineData("GET ")] [InlineData("GET /")] [InlineData("GET / ")] [InlineData("GET / H")] + [InlineData("GET / HT")] + [InlineData("GET / HTT")] + [InlineData("GET / HTTP")] + [InlineData("GET / HTTP/")] + [InlineData("GET / HTTP/1")] [InlineData("GET / HTTP/1.")] + [InlineData("GET / HTTP/1.1")] + [InlineData("GET / HTTP/1.1\r")] + [InlineData("GET / HTTP/1.0")] + [InlineData("GET / HTTP/1.0\r")] + // Missing method + [InlineData(" ")] + // Missing second space + [InlineData("/ HTTP/1.1\r\n\r\n")] [InlineData("GET /\r\n")] - [InlineData("GET / \r\n")] + // Missing target + [InlineData("GET ")] + // Missing version + [InlineData("GET / \r")] + // Missing CR [InlineData("GET / \n")] - [InlineData("GET / http/1.0\r\n\r\n")] - [InlineData("GET / http/1.1\r\n\r\n")] - [InlineData("GET / HTTP/1.1 \r\n\r\n")] - [InlineData("GET / HTTP/1.1a\r\n\r\n")] - [InlineData("GET / HTTP/1.0\n\r\n")] - [InlineData("GET / HTTP/3.0\r\n\r\n")] - [InlineData("GET / H\r\n\r\n")] - [InlineData("GET / HTTP/1.\r\n\r\n")] - [InlineData("GET / hello\r\n\r\n")] - [InlineData("GET / 8charact\r\n\r\n")] - public async Task TestBadRequests(string request) + // Unrecognized HTTP version + [InlineData("GET / http/1.0\r")] + [InlineData("GET / http/1.1\r")] + [InlineData("GET / HTTP/1.1 \r")] + [InlineData("GET / HTTP/1.1a\r")] + [InlineData("GET / HTTP/1.0\n\r")] + [InlineData("GET / HTTP/1.2\r")] + [InlineData("GET / HTTP/3.0\r")] + [InlineData("GET / H\r")] + [InlineData("GET / HTTP/1.\r")] + [InlineData("GET / hello\r")] + [InlineData("GET / 8charact\r")] + // Missing LF + [InlineData("GET / HTTP/1.0\rA")] + public async Task TestBadRequestLines(string request) { using (var server = new TestServer(context => { return Task.FromResult(0); })) { using (var connection = new TestConnection(server.Port)) { - var receiveTask = Task.Run(async () => - { - await connection.Receive( - "HTTP/1.1 400 Bad Request", - ""); - await connection.ReceiveStartsWith("Date: "); - await connection.ReceiveForcedEnd( - "Content-Length: 0", - "Server: Kestrel", - "", - ""); - }); - - try - { - await connection.SendEnd(request).ConfigureAwait(false); - } - catch (Exception) - { - // TestConnection.SendEnd will start throwing while sending characters - // in cases where the server rejects the request as soon as it - // determines the request line is malformed, even though there - // are more characters following. - } - - await receiveTask; + await connection.SendEnd(request); + await ReceiveBadRequestResponse(connection); } } } + + [Theory] + [InlineData(" ")] + [InlineData("GET ")] + [InlineData("GET / HTTP/1.2\r")] + [InlineData("GET / HTTP/1.0\rA")] + public async Task ServerClosesConnectionAsSoonAsBadRequestLineIsDetected(string request) + { + using (var server = new TestServer(context => { return Task.FromResult(0); })) + { + using (var connection = new TestConnection(server.Port)) + { + await connection.Send(request); + await ReceiveBadRequestResponse(connection); + } + } + } + + private async Task ReceiveBadRequestResponse(TestConnection connection) + { + await connection.Receive( + "HTTP/1.1 400 Bad Request", + ""); + await connection.Receive( + "Connection: close", + ""); + await connection.ReceiveStartsWith("Date: "); + await connection.ReceiveEnd( + "Content-Length: 0", + "Server: Kestrel", + "", + ""); + } } } \ No newline at end of file diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedRequestTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedRequestTests.cs index 7acafa9883..217af83a6b 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedRequestTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedRequestTests.cs @@ -371,6 +371,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests await connection.Receive( "HTTP/1.1 400 Bad Request", + "Connection: close", ""); await connection.ReceiveStartsWith("Date:"); await connection.ReceiveForcedEnd( @@ -415,6 +416,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests await connection.Receive( "HTTP/1.1 400 Bad Request", + "Connection: close", ""); await connection.ReceiveStartsWith("Date:"); await connection.ReceiveForcedEnd( diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs index 3432a75de3..270a93d998 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs @@ -724,21 +724,6 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { using (var server = new TestServer(AppChunked, testContext)) { - using (var connection = new TestConnection(server.Port)) - { - await connection.SendEnd( - "GET /"); - await connection.Receive( - "HTTP/1.1 400 Bad Request", - ""); - await connection.ReceiveStartsWith("Date:"); - await connection.ReceiveForcedEnd( - "Content-Length: 0", - "Server: Kestrel", - "", - ""); - } - using (var connection = new TestConnection(server.Port)) { await connection.SendEnd( @@ -750,6 +735,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests "Content-Length: 0", "", "HTTP/1.1 400 Bad Request", + "Connection: close", ""); await connection.ReceiveStartsWith("Date:"); await connection.ReceiveForcedEnd( From 185ad000bbf1e11b8573fed14581e18c71f9d104 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Thu, 12 May 2016 15:43:29 -0700 Subject: [PATCH 0724/1662] Prevent NullReferenceException in KestrelThread.OnStopRude - UvMemory.FromIntPtr looks up a weak reference so we need to null check. --- .../Infrastructure/KestrelThread.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/KestrelThread.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/KestrelThread.cs index 20183d92da..b176cfa697 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/KestrelThread.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/KestrelThread.cs @@ -132,7 +132,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel var handle = UvMemory.FromIntPtr(ptr); if (handle != _post) { - handle.Dispose(); + // handle can be null because UvMemory.FromIntPtr looks up a weak reference + handle?.Dispose(); } }); From e1c64d2119f04c126069d58d4cd1708246a7c82e Mon Sep 17 00:00:00 2001 From: Nathan Anderson Date: Thu, 12 May 2016 11:44:05 -0700 Subject: [PATCH 0725/1662] reuse typeof results in generated Frame code --- .../Http/Frame.Generated.cs | 64 +++++++++---------- .../FrameFeatureCollection.cs | 4 +- 2 files changed, 34 insertions(+), 34 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.Generated.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.Generated.cs index cadd574717..160304dcfc 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.Generated.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.Generated.cs @@ -63,67 +63,67 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http private object FastFeatureGet(Type key) { - if (key == typeof(global::Microsoft.AspNetCore.Http.Features.IHttpRequestFeature)) + if (key == IHttpRequestFeatureType) { return _currentIHttpRequestFeature; } - if (key == typeof(global::Microsoft.AspNetCore.Http.Features.IHttpResponseFeature)) + if (key == IHttpResponseFeatureType) { return _currentIHttpResponseFeature; } - if (key == typeof(global::Microsoft.AspNetCore.Http.Features.IHttpRequestIdentifierFeature)) + if (key == IHttpRequestIdentifierFeatureType) { return _currentIHttpRequestIdentifierFeature; } - if (key == typeof(global::Microsoft.AspNetCore.Http.Features.IServiceProvidersFeature)) + if (key == IServiceProvidersFeatureType) { return _currentIServiceProvidersFeature; } - if (key == typeof(global::Microsoft.AspNetCore.Http.Features.IHttpRequestLifetimeFeature)) + if (key == IHttpRequestLifetimeFeatureType) { return _currentIHttpRequestLifetimeFeature; } - if (key == typeof(global::Microsoft.AspNetCore.Http.Features.IHttpConnectionFeature)) + if (key == IHttpConnectionFeatureType) { return _currentIHttpConnectionFeature; } - if (key == typeof(global::Microsoft.AspNetCore.Http.Features.Authentication.IHttpAuthenticationFeature)) + if (key == IHttpAuthenticationFeatureType) { return _currentIHttpAuthenticationFeature; } - if (key == typeof(global::Microsoft.AspNetCore.Http.Features.IQueryFeature)) + if (key == IQueryFeatureType) { return _currentIQueryFeature; } - if (key == typeof(global::Microsoft.AspNetCore.Http.Features.IFormFeature)) + if (key == IFormFeatureType) { return _currentIFormFeature; } - if (key == typeof(global::Microsoft.AspNetCore.Http.Features.IHttpUpgradeFeature)) + if (key == IHttpUpgradeFeatureType) { return _currentIHttpUpgradeFeature; } - if (key == typeof(global::Microsoft.AspNetCore.Http.Features.IResponseCookiesFeature)) + if (key == IResponseCookiesFeatureType) { return _currentIResponseCookiesFeature; } - if (key == typeof(global::Microsoft.AspNetCore.Http.Features.IItemsFeature)) + if (key == IItemsFeatureType) { return _currentIItemsFeature; } - if (key == typeof(global::Microsoft.AspNetCore.Http.Features.ITlsConnectionFeature)) + if (key == ITlsConnectionFeatureType) { return _currentITlsConnectionFeature; } - if (key == typeof(global::Microsoft.AspNetCore.Http.Features.IHttpWebSocketFeature)) + if (key == IHttpWebSocketFeatureType) { return _currentIHttpWebSocketFeature; } - if (key == typeof(global::Microsoft.AspNetCore.Http.Features.ISessionFeature)) + if (key == ISessionFeatureType) { return _currentISessionFeature; } - if (key == typeof(global::Microsoft.AspNetCore.Http.Features.IHttpSendFileFeature)) + if (key == IHttpSendFileFeatureType) { return _currentIHttpSendFileFeature; } @@ -134,82 +134,82 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { _featureRevision++; - if (key == typeof(global::Microsoft.AspNetCore.Http.Features.IHttpRequestFeature)) + if (key == IHttpRequestFeatureType) { _currentIHttpRequestFeature = feature; return; } - if (key == typeof(global::Microsoft.AspNetCore.Http.Features.IHttpResponseFeature)) + if (key == IHttpResponseFeatureType) { _currentIHttpResponseFeature = feature; return; } - if (key == typeof(global::Microsoft.AspNetCore.Http.Features.IHttpRequestIdentifierFeature)) + if (key == IHttpRequestIdentifierFeatureType) { _currentIHttpRequestIdentifierFeature = feature; return; } - if (key == typeof(global::Microsoft.AspNetCore.Http.Features.IServiceProvidersFeature)) + if (key == IServiceProvidersFeatureType) { _currentIServiceProvidersFeature = feature; return; } - if (key == typeof(global::Microsoft.AspNetCore.Http.Features.IHttpRequestLifetimeFeature)) + if (key == IHttpRequestLifetimeFeatureType) { _currentIHttpRequestLifetimeFeature = feature; return; } - if (key == typeof(global::Microsoft.AspNetCore.Http.Features.IHttpConnectionFeature)) + if (key == IHttpConnectionFeatureType) { _currentIHttpConnectionFeature = feature; return; } - if (key == typeof(global::Microsoft.AspNetCore.Http.Features.Authentication.IHttpAuthenticationFeature)) + if (key == IHttpAuthenticationFeatureType) { _currentIHttpAuthenticationFeature = feature; return; } - if (key == typeof(global::Microsoft.AspNetCore.Http.Features.IQueryFeature)) + if (key == IQueryFeatureType) { _currentIQueryFeature = feature; return; } - if (key == typeof(global::Microsoft.AspNetCore.Http.Features.IFormFeature)) + if (key == IFormFeatureType) { _currentIFormFeature = feature; return; } - if (key == typeof(global::Microsoft.AspNetCore.Http.Features.IHttpUpgradeFeature)) + if (key == IHttpUpgradeFeatureType) { _currentIHttpUpgradeFeature = feature; return; } - if (key == typeof(global::Microsoft.AspNetCore.Http.Features.IResponseCookiesFeature)) + if (key == IResponseCookiesFeatureType) { _currentIResponseCookiesFeature = feature; return; } - if (key == typeof(global::Microsoft.AspNetCore.Http.Features.IItemsFeature)) + if (key == IItemsFeatureType) { _currentIItemsFeature = feature; return; } - if (key == typeof(global::Microsoft.AspNetCore.Http.Features.ITlsConnectionFeature)) + if (key == ITlsConnectionFeatureType) { _currentITlsConnectionFeature = feature; return; } - if (key == typeof(global::Microsoft.AspNetCore.Http.Features.IHttpWebSocketFeature)) + if (key == IHttpWebSocketFeatureType) { _currentIHttpWebSocketFeature = feature; return; } - if (key == typeof(global::Microsoft.AspNetCore.Http.Features.ISessionFeature)) + if (key == ISessionFeatureType) { _currentISessionFeature = feature; return; } - if (key == typeof(global::Microsoft.AspNetCore.Http.Features.IHttpSendFileFeature)) + if (key == IHttpSendFileFeatureType) { _currentIHttpSendFileFeature = feature; return; diff --git a/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/FrameFeatureCollection.cs b/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/FrameFeatureCollection.cs index 33e1e083d3..2eb781cde6 100644 --- a/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/FrameFeatureCollection.cs +++ b/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/FrameFeatureCollection.cs @@ -83,7 +83,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http private object FastFeatureGet(Type key) {{{Each(allFeatures, feature => $@" - if (key == typeof(global::{feature.FullName})) + if (key == {feature.Name}Type) {{ return _current{feature.Name}; }}")} @@ -94,7 +94,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http {{ _featureRevision++; {Each(allFeatures, feature => $@" - if (key == typeof(global::{feature.FullName})) + if (key == {feature.Name}Type) {{ _current{feature.Name} = feature; return; From 9a06bf39ab1736c4739b13b93a552ec83dcb3b35 Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Wed, 18 May 2016 22:11:10 -0700 Subject: [PATCH 0726/1662] Move ECONNRESET value check to server initialization. --- .../Http/Connection.cs | 10 +--------- .../Infrastructure/Constants.cs | 1 - .../KestrelServer.cs | 5 +++++ 3 files changed, 6 insertions(+), 10 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Connection.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Connection.cs index be6b7a347e..1bfd927772 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Connection.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Connection.cs @@ -40,8 +40,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http private ConnectionState _connectionState; private TaskCompletionSource _socketClosedTcs; - bool _eConnResetChecked = false; - public Connection(ListenerContext context, UvStreamHandle socket) : base(context) { _socket = socket; @@ -202,7 +200,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if (_socketClosedTcs != null) { // This is always waited on synchronously, so it's safe to - // call on the libuv thread. + // call on the libuv thread. _socketClosedTcs.TrySetResult(null); } } @@ -274,12 +272,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http return; } - if (!_eConnResetChecked && !Constants.ECONNRESET.HasValue) - { - Log.LogWarning("Unable to determine ECONNRESET value on this platform."); - _eConnResetChecked = true; - } - var normalRead = status > 0; var normalDone = status == Constants.ECONNRESET || status == Constants.EOF; var errorDone = !(normalDone || normalRead); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/Constants.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/Constants.cs index dcbd4cb5f3..b7dcc01a41 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/Constants.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/Constants.cs @@ -1,7 +1,6 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System; using Microsoft.Extensions.PlatformAbstractions; namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServer.cs b/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServer.cs index 19068784a4..35b134d152 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServer.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServer.cs @@ -94,6 +94,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel "ThreadCount must be positive."); } + if (!Constants.ECONNRESET.HasValue) + { + _logger.LogWarning("Unable to determine ECONNRESET value on this platform."); + } + engine.Start(threadCount); var atLeastOneListener = false; From 92320299503db604f27db2c64ac256aa8574e190 Mon Sep 17 00:00:00 2001 From: shanewalters Date: Thu, 19 May 2016 12:17:23 -0600 Subject: [PATCH 0727/1662] Use SslStream.RemoteCertificate to recreate disposed certificate. --- .../HttpsConnectionFilter.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Https/HttpsConnectionFilter.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Https/HttpsConnectionFilter.cs index 0992d229e5..b4f2d33c1e 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Https/HttpsConnectionFilter.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Https/HttpsConnectionFilter.cs @@ -40,7 +40,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Https if (string.Equals(context.Address.Scheme, "https", StringComparison.OrdinalIgnoreCase)) { - X509Certificate2 clientCertificate = null; + var certificateHandle = IntPtr.Zero; SslStream sslStream; if (_options.ClientCertificateMode == ClientCertificateMode.NoCertificate) { @@ -86,7 +86,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Https } } - clientCertificate = certificate2; + certificateHandle = certificate2.Handle; return true; }); await sslStream.AuthenticateAsServerAsync(_options.ServerCertificate, clientCertificateRequired: true, @@ -98,9 +98,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Https { previousPrepareRequest?.Invoke(features); - if (clientCertificate != null) + if (certificateHandle != IntPtr.Zero) { - features.Set(new TlsConnectionFeature { ClientCertificate = clientCertificate }); + features.Set(new TlsConnectionFeature { ClientCertificate = new X509Certificate2(sslStream.RemoteCertificate.Handle) }); } features.Get().Scheme = "https"; From e8647c0cb4e1b66ab15c997c1a997fc4df93bef2 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Thu, 19 May 2016 02:16:09 +0100 Subject: [PATCH 0728/1662] Remove extra FrameContext class Resolves #837 --- .../Http/Frame.FeatureCollection.cs | 1 + .../Http/Frame.cs | 2 +- .../Http/FrameContext.cs | 18 ------------------ .../Http/FrameResponseStream.cs | 16 ++++++++-------- .../Infrastructure/HttpComponentFactory.cs | 8 ++++---- .../Infrastructure/IHttpComponentFactory.cs | 2 +- .../TestInput.cs | 4 ++-- 7 files changed, 17 insertions(+), 34 deletions(-) delete mode 100644 src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameContext.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.FeatureCollection.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.FeatureCollection.cs index 827398ba0c..4e44236545 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.FeatureCollection.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.FeatureCollection.cs @@ -73,6 +73,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http MaybeExtra.Add(new KeyValuePair(key, value)); } + public IFrameControl FrameControl { get; set; } string IHttpRequestFeature.Protocol { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs index c117709f36..fe4b11fccf 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs @@ -20,7 +20,7 @@ using Microsoft.Extensions.Primitives; namespace Microsoft.AspNetCore.Server.Kestrel.Http { - public abstract partial class Frame : FrameContext, IFrameControl + public abstract partial class Frame : ConnectionContext, IFrameControl { private static readonly Encoding _ascii = Encoding.ASCII; private static readonly ArraySegment _endChunkedResponseBytes = CreateAsciiByteArraySegment("0\r\n\r\n"); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameContext.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameContext.cs deleted file mode 100644 index e4db400124..0000000000 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameContext.cs +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -namespace Microsoft.AspNetCore.Server.Kestrel.Http -{ - public class FrameContext : ConnectionContext - { - public FrameContext() - { - } - - public FrameContext(ConnectionContext context) : base(context) - { - } - - public IFrameControl FrameControl { get; set; } - } -} \ No newline at end of file diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameResponseStream.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameResponseStream.cs index c7568bed36..522e805e10 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameResponseStream.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameResponseStream.cs @@ -11,7 +11,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { class FrameResponseStream : Stream { - private FrameContext _context; + private IFrameControl _frameControl; private FrameStreamState _state; public FrameResponseStream() @@ -49,7 +49,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { ValidateState(default(CancellationToken)); - _context.FrameControl.Flush(); + _frameControl.Flush(); } public override Task FlushAsync(CancellationToken cancellationToken) @@ -57,7 +57,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http var task = ValidateState(cancellationToken); if (task == null) { - return _context.FrameControl.FlushAsync(cancellationToken); + return _frameControl.FlushAsync(cancellationToken); } return task; } @@ -81,7 +81,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { ValidateState(default(CancellationToken)); - _context.FrameControl.Write(new ArraySegment(buffer, offset, count)); + _frameControl.Write(new ArraySegment(buffer, offset, count)); } public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) @@ -89,7 +89,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http var task = ValidateState(cancellationToken); if (task == null) { - return _context.FrameControl.WriteAsync(new ArraySegment(buffer, offset, count), cancellationToken); + return _frameControl.WriteAsync(new ArraySegment(buffer, offset, count), cancellationToken); } return task; } @@ -134,14 +134,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } - public void Initialize(FrameContext context) + public void Initialize(IFrameControl frameControl) { - _context = context; + _frameControl = frameControl; } public void Uninitialize() { - _context = null; + _frameControl = null; _state = FrameStreamState.Closed; } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/HttpComponentFactory.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/HttpComponentFactory.cs index 2669471cd9..4d647e2caa 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/HttpComponentFactory.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/HttpComponentFactory.cs @@ -20,7 +20,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure ServerOptions = serverOptions; } - public Streams CreateStreams(FrameContext owner) + public Streams CreateStreams(IFrameControl frameControl) { Streams streams; @@ -29,7 +29,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure streams = new Streams(); } - streams.Initialize(owner); + streams.Initialize(frameControl); return streams; } @@ -103,9 +103,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure DuplexStream = new FrameDuplexStream(RequestBody, ResponseBody); } - public void Initialize(FrameContext renter) + public void Initialize(IFrameControl frameControl) { - ResponseBody.Initialize(renter); + ResponseBody.Initialize(frameControl); } public void Uninitialize() diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/IHttpComponentFactory.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/IHttpComponentFactory.cs index 926d9cfd26..3dcb234bbd 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/IHttpComponentFactory.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/IHttpComponentFactory.cs @@ -9,7 +9,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure { KestrelServerOptions ServerOptions { get; set; } - Streams CreateStreams(FrameContext owner); + Streams CreateStreams(IFrameControl frameControl); void DisposeStreams(Streams streams); diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestInput.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/TestInput.cs index 764e0a521c..d841e180f7 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/TestInput.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/TestInput.cs @@ -18,14 +18,14 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { var trace = new KestrelTrace(new TestKestrelTrace()); var ltp = new LoggingThreadPool(trace); - var context = new FrameContext() + var context = new Frame(null, new ConnectionContext() { ServerAddress = new ServerAddress() }) { DateHeaderValueManager = new DateHeaderValueManager(), ServerAddress = ServerAddress.FromUrl("http://localhost:5000"), ConnectionControl = this, FrameControl = this }; - FrameContext = new Frame(null, context); + FrameContext = context; _memoryPool = new MemoryPool(); FrameContext.SocketInput = new SocketInput(_memoryPool, ltp); From 8e9df409c4b79379dd4b7cdd29f813e4585b8b0d Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Wed, 18 May 2016 21:55:38 -0700 Subject: [PATCH 0729/1662] Remove dead code in ReasonPhrases. --- .../Http/ReasonPhrases.cs | 235 ------------------ 1 file changed, 235 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/ReasonPhrases.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/ReasonPhrases.cs index 7aae44b815..df007f573e 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/ReasonPhrases.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/ReasonPhrases.cs @@ -61,15 +61,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http private static readonly byte[] _bytesStatus507 = Encoding.ASCII.GetBytes("507 Insufficient Storage"); private static readonly byte[] _bytesStatus510 = Encoding.ASCII.GetBytes("510 Not Extended"); - public static string ToStatus(int statusCode, string reasonPhrase = null) - { - if (string.IsNullOrEmpty(reasonPhrase)) - { - return ToStatusPhrase(statusCode); - } - return statusCode.ToString(CultureInfo.InvariantCulture) + " " + reasonPhrase; - } - public static byte[] ToStatusBytes(int statusCode, string reasonPhrase = null) { if (string.IsNullOrEmpty(reasonPhrase)) @@ -186,231 +177,5 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } return Encoding.ASCII.GetBytes(statusCode.ToString(CultureInfo.InvariantCulture) + " " + reasonPhrase); } - - public static string ToReasonPhrase(int statusCode) - { - switch (statusCode) - { - case 100: - return "Continue"; - case 101: - return "Switching Protocols"; - case 102: - return "Processing"; - case 200: - return "OK"; - case 201: - return "Created"; - case 202: - return "Accepted"; - case 203: - return "Non-Authoritative Information"; - case 204: - return "No Content"; - case 205: - return "Reset Content"; - case 206: - return "Partial Content"; - case 207: - return "Multi-Status"; - case 226: - return "IM Used"; - case 300: - return "Multiple Choices"; - case 301: - return "Moved Permanently"; - case 302: - return "Found"; - case 303: - return "See Other"; - case 304: - return "Not Modified"; - case 305: - return "Use Proxy"; - case 306: - return "Reserved"; - case 307: - return "Temporary Redirect"; - case 400: - return "Bad Request"; - case 401: - return "Unauthorized"; - case 402: - return "Payment Required"; - case 403: - return "Forbidden"; - case 404: - return "Not Found"; - case 405: - return "Method Not Allowed"; - case 406: - return "Not Acceptable"; - case 407: - return "Proxy Authentication Required"; - case 408: - return "Request Timeout"; - case 409: - return "Conflict"; - case 410: - return "Gone"; - case 411: - return "Length Required"; - case 412: - return "Precondition Failed"; - case 413: - return "Payload Too Large"; - case 414: - return "URI Too Long"; - case 415: - return "Unsupported Media Type"; - case 416: - return "Range Not Satisfiable"; - case 417: - return "Expectation Failed"; - case 418: - return "I'm a Teapot"; - case 422: - return "Unprocessable Entity"; - case 423: - return "Locked"; - case 424: - return "Failed Dependency"; - case 426: - return "Upgrade Required"; - case 500: - return "Internal Server Error"; - case 501: - return "Not Implemented"; - case 502: - return "Bad Gateway"; - case 503: - return "Service Unavailable"; - case 504: - return "Gateway Timeout"; - case 505: - return "HTTP Version Not Supported"; - case 506: - return "Variant Also Negotiates"; - case 507: - return "Insufficient Storage"; - case 510: - return "Not Extended"; - default: - return null; - } - } - - public static string ToStatusPhrase(int statusCode) - { - switch (statusCode) - { - case 100: - return "100 Continue"; - case 101: - return "101 Switching Protocols"; - case 102: - return "102 Processing"; - case 200: - return "200 OK"; - case 201: - return "201 Created"; - case 202: - return "202 Accepted"; - case 203: - return "203 Non-Authoritative Information"; - case 204: - return "204 No Content"; - case 205: - return "205 Reset Content"; - case 206: - return "206 Partial Content"; - case 207: - return "207 Multi-Status"; - case 226: - return "226 IM Used"; - case 300: - return "300 Multiple Choices"; - case 301: - return "301 Moved Permanently"; - case 302: - return "302 Found"; - case 303: - return "303 See Other"; - case 304: - return "304 Not Modified"; - case 305: - return "305 Use Proxy"; - case 306: - return "306 Reserved"; - case 307: - return "307 Temporary Redirect"; - case 400: - return "400 Bad Request"; - case 401: - return "401 Unauthorized"; - case 402: - return "402 Payment Required"; - case 403: - return "403 Forbidden"; - case 404: - return "404 Not Found"; - case 405: - return "405 Method Not Allowed"; - case 406: - return "406 Not Acceptable"; - case 407: - return "407 Proxy Authentication Required"; - case 408: - return "408 Request Timeout"; - case 409: - return "409 Conflict"; - case 410: - return "410 Gone"; - case 411: - return "411 Length Required"; - case 412: - return "412 Precondition Failed"; - case 413: - return "413 Request Entity Too Large"; - case 414: - return "414 Request-URI Too Long"; - case 415: - return "415 Unsupported Media Type"; - case 416: - return "416 Requested Range Not Satisfiable"; - case 417: - return "417 Expectation Failed"; - case 418: - return "418 I'm a Teapot"; - case 422: - return "422 Unprocessable Entity"; - case 423: - return "423 Locked"; - case 424: - return "424 Failed Dependency"; - case 426: - return "426 Upgrade Required"; - case 500: - return "500 Internal Server Error"; - case 501: - return "501 Not Implemented"; - case 502: - return "502 Bad Gateway"; - case 503: - return "503 Service Unavailable"; - case 504: - return "504 Gateway Timeout"; - case 505: - return "505 HTTP Version Not Supported"; - case 506: - return "506 Variant Also Negotiates"; - case 507: - return "507 Insufficient Storage"; - case 510: - return "510 Not Extended"; - default: - return statusCode.ToString(CultureInfo.InvariantCulture) + " Unknown"; - } - } } } \ No newline at end of file From 9960cb8c2388f049360bd04ba37baba120209fde Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Wed, 18 May 2016 21:46:35 -0700 Subject: [PATCH 0730/1662] Remove unused Frame static fields. --- src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs index c117709f36..b1d6bf5faf 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs @@ -22,7 +22,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { public abstract partial class Frame : FrameContext, IFrameControl { - private static readonly Encoding _ascii = Encoding.ASCII; private static readonly ArraySegment _endChunkedResponseBytes = CreateAsciiByteArraySegment("0\r\n\r\n"); private static readonly ArraySegment _continueBytes = CreateAsciiByteArraySegment("HTTP/1.1 100 Continue\r\n\r\n"); private static readonly ArraySegment _emptyData = new ArraySegment(new byte[0]); @@ -32,7 +31,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http private static readonly byte[] _bytesTransferEncodingChunked = Encoding.ASCII.GetBytes("\r\nTransfer-Encoding: chunked"); private static readonly byte[] _bytesHttpVersion11 = Encoding.ASCII.GetBytes("HTTP/1.1 "); private static readonly byte[] _bytesContentLengthZero = Encoding.ASCII.GetBytes("\r\nContent-Length: 0"); - private static readonly byte[] _bytesSpace = Encoding.ASCII.GetBytes(" "); private static readonly byte[] _bytesEndHeaders = Encoding.ASCII.GetBytes("\r\n\r\n"); private static Vector _vectorCRs = new Vector((byte)'\r'); From 1f494b168b8f6ca6e0ce980f165af537dfb32052 Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Wed, 18 May 2016 21:41:38 -0700 Subject: [PATCH 0731/1662] Remove Frame._requestProcessingStarted field. --- .../Http/Frame.cs | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs index b1d6bf5faf..63f7f7033b 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs @@ -50,7 +50,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http protected List, object>> _onCompleted; - private bool _requestProcessingStarted; private Task _requestProcessingTask; protected volatile bool _requestProcessingStopping; // volatile, see: https://msdn.microsoft.com/en-us/library/x13ttww7.aspx protected int _requestAborted; @@ -272,17 +271,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http /// public void Start() { - if (!_requestProcessingStarted) - { - _requestProcessingStarted = true; - _requestProcessingTask = - Task.Factory.StartNew( - (o) => ((Frame)o).RequestProcessingAsync(), - this, - default(CancellationToken), - TaskCreationOptions.DenyChildAttach, - TaskScheduler.Default); - } + _requestProcessingTask = + Task.Factory.StartNew( + (o) => ((Frame)o).RequestProcessingAsync(), + this, + default(CancellationToken), + TaskCreationOptions.DenyChildAttach, + TaskScheduler.Default); } /// From b17c070e1c2eef429213e8972a34293fb42f0ccb Mon Sep 17 00:00:00 2001 From: shanewalters Date: Thu, 19 May 2016 14:40:29 -0600 Subject: [PATCH 0732/1662] Updated to not use handle, centralize conversion logic. --- .../HttpsConnectionFilter.cs | 37 +++++++---- .../HttpsConnectionFilterTests.cs | 63 +++++++++++++++++++ 2 files changed, 89 insertions(+), 11 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Https/HttpsConnectionFilter.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Https/HttpsConnectionFilter.cs index b4f2d33c1e..f8efc1abbb 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Https/HttpsConnectionFilter.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Https/HttpsConnectionFilter.cs @@ -40,7 +40,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Https if (string.Equals(context.Address.Scheme, "https", StringComparison.OrdinalIgnoreCase)) { - var certificateHandle = IntPtr.Zero; SslStream sslStream; if (_options.ClientCertificateMode == ClientCertificateMode.NoCertificate) { @@ -66,16 +65,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Https } } - X509Certificate2 certificate2 = certificate as X509Certificate2; + var certificate2 = ConvertToX509Certificate2(certificate); if (certificate2 == null) { -#if NETSTANDARD1_3 - // conversion X509Certificate to X509Certificate2 not supported - // https://github.com/dotnet/corefx/issues/4510 return false; -#else - certificate2 = new X509Certificate2(certificate); -#endif } if (_options.ClientCertificateValidation != null) @@ -86,7 +79,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Https } } - certificateHandle = certificate2.Handle; return true; }); await sslStream.AuthenticateAsServerAsync(_options.ServerCertificate, clientCertificateRequired: true, @@ -98,9 +90,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Https { previousPrepareRequest?.Invoke(features); - if (certificateHandle != IntPtr.Zero) + var clientCertificate = ConvertToX509Certificate2(sslStream.RemoteCertificate); + if (clientCertificate != null) { - features.Set(new TlsConnectionFeature { ClientCertificate = new X509Certificate2(sslStream.RemoteCertificate.Handle) }); + features.Set(new TlsConnectionFeature { ClientCertificate = clientCertificate }); } features.Get().Scheme = "https"; @@ -108,5 +101,27 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Https context.Connection = sslStream; } } + + private X509Certificate2 ConvertToX509Certificate2(X509Certificate certificate) + { + if (certificate == null) + { + return null; + } + + X509Certificate2 certificate2 = certificate as X509Certificate2; + if (certificate2 != null) + { + return certificate2; + } + +#if NETSTANDARD1_3 + // conversion X509Certificate to X509Certificate2 not supported + // https://github.com/dotnet/corefx/issues/4510 + return null; +#else + return new X509Certificate2(certificate); +#endif + } } } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/HttpsConnectionFilterTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/HttpsConnectionFilterTests.cs index c0da2cbc5b..50b89a0416 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/HttpsConnectionFilterTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/HttpsConnectionFilterTests.cs @@ -347,6 +347,69 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { #if NET451 ServicePointManager.ServerCertificateValidationCallback -= validationCallback; +#endif + } + } + + [ConditionalFact] + [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "This test currently fails on Mono because of an issue with SslStream (https://github.com/aspnet/KestrelHttpServer/issues/240).")] + public async Task CertificatePassedToHttpContextIsNotDisposed() + { + RemoteCertificateValidationCallback validationCallback = + (sender, cert, chain, sslPolicyErrors) => true; + + try + { +#if NET451 + ServicePointManager.ServerCertificateValidationCallback += validationCallback; +#endif + + var serviceContext = new TestServiceContext(new HttpsConnectionFilter( + new HttpsConnectionFilterOptions + { + ServerCertificate = new X509Certificate2(@"TestResources/testCert.pfx", "testPassword"), + ClientCertificateMode = ClientCertificateMode.RequireCertificate, + ClientCertificateValidation = (certificate, chain, sslPolicyErrors) => true + }, + new NoOpConnectionFilter()) + ); + + RequestDelegate app = context => + { + var tlsFeature = context.Features.Get(); + Assert.NotNull(tlsFeature); + Assert.NotNull(tlsFeature.ClientCertificate); + Assert.NotNull(context.Connection.ClientCertificate); + Assert.NotNull(context.Connection.ClientCertificate.PublicKey); + return context.Response.WriteAsync("hello world"); + }; + + using (var server = new TestServer(app, serviceContext, "https://localhost:0/")) + { + // SslStream is used to ensure the certificate is actually passed to the server + // HttpClient might not send the certificate because it is invalid or it doesn't match any + // of the certificate authorities sent by the server in the SSL handshake. + using (var client = new TcpClient()) + { + await client.ConnectAsync("127.0.0.1", server.Port); + + var stream = new SslStream(client.GetStream(), false, (sender, certificate, chain, errors) => true, + (sender, host, certificates, certificate, issuers) => new X509Certificate2(@"TestResources/testCert.pfx", "testPassword")); + await stream.AuthenticateAsClientAsync("localhost", new X509CertificateCollection(), SslProtocols.Tls12 | SslProtocols.Tls11, false); + + var request = Encoding.UTF8.GetBytes("GET / HTTP/1.0\r\n\r\n"); + await stream.WriteAsync(request, 0, request.Length); + + var reader = new StreamReader(stream); + var line = await reader.ReadLineAsync(); + Assert.Equal("HTTP/1.1 200 OK", line); + } + } + } + finally + { +#if NET451 + ServicePointManager.ServerCertificateValidationCallback -= validationCallback; #endif } } From 86567e1d939e7bc78c478f6f29bce3f5a9e472fa Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Thu, 19 May 2016 12:15:35 -0700 Subject: [PATCH 0733/1662] Fix engine test. --- test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs index 270a93d998..413a3c64f2 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs @@ -1079,7 +1079,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests "Content-Length: 1", "", ""); - await connection.ReceiveEnd(); + await connection.ReceiveForcedEnd(); } } } From 5eb14664876e904aec3cb43514407320785bdc8f Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Thu, 19 May 2016 00:13:33 +0100 Subject: [PATCH 0734/1662] Fast-path response header connection check --- src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs index 467b841fd6..0c5deb9937 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs @@ -670,14 +670,17 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http var responseHeaders = _frameHeaders.ResponseHeaders; responseHeaders.SetReadOnly(); + var hasConnection = responseHeaders.HasConnection; + var end = SocketOutput.ProducingStart(); - if (_keepAlive) + if (_keepAlive && hasConnection) { foreach (var connectionValue in responseHeaders.HeaderConnection) { if (connectionValue.IndexOf("close", StringComparison.OrdinalIgnoreCase) != -1) { _keepAlive = false; + break; } } } @@ -716,11 +719,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } - if (!_keepAlive && !responseHeaders.HasConnection && _httpVersion != HttpVersionType.Http10) + if (!_keepAlive && !hasConnection && _httpVersion != HttpVersionType.Http10) { responseHeaders.SetRawConnection("close", _bytesConnectionClose); } - else if (_keepAlive && !responseHeaders.HasConnection && _httpVersion == HttpVersionType.Http10) + else if (_keepAlive && !hasConnection && _httpVersion == HttpVersionType.Http10) { responseHeaders.SetRawConnection("keep-alive", _bytesConnectionKeepAlive); } From 2ab01c09fdf6958f25196018d8fc8922f570415f Mon Sep 17 00:00:00 2001 From: Kristian Hellang Date: Fri, 20 May 2016 13:12:32 +0200 Subject: [PATCH 0735/1662] Add option to remove the Server header --- .../Http/Frame.cs | 7 ++++- .../Infrastructure/Constants.cs | 2 ++ .../Infrastructure/HttpComponentFactory.cs | 16 ++++++++-- .../KestrelServerOptions.cs | 5 ++++ .../FrameResponseHeadersTests.cs | 29 ++++++++++++++----- 5 files changed, 48 insertions(+), 11 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs index 467b841fd6..d50aa1b613 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs @@ -610,10 +610,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http var responseHeaders = _frameHeaders.ResponseHeaders; responseHeaders.Reset(); var dateHeaderValues = DateHeaderValueManager.GetDateHeaderValues(); + responseHeaders.SetRawDate(dateHeaderValues.String, dateHeaderValues.Bytes); - responseHeaders.SetRawServer("Kestrel", Headers.BytesServer); responseHeaders.SetRawContentLength("0", _bytesContentLengthZero); + if (ServerOptions.AddServerHeader) + { + responseHeaders.SetRawServer(Constants.ServerName, Headers.BytesServer); + } + ResponseHeaders = responseHeaders; } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/Constants.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/Constants.cs index b7dcc01a41..3031b022dc 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/Constants.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/Constants.cs @@ -23,6 +23,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure /// public const string RFC1123DateFormat = "r"; + public const string ServerName = "Kestrel"; + private static int? GetECONNRESET() { switch (PlatformServices.Default.Runtime.OperatingSystemPlatform) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/HttpComponentFactory.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/HttpComponentFactory.cs index 4d647e2caa..baeb975233 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/HttpComponentFactory.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/HttpComponentFactory.cs @@ -50,7 +50,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure if (!_headerPool.TryDequeue(out headers)) { - headers = new Headers(); + headers = new Headers(ServerOptions); } headers.Initialize(dateValueManager); @@ -76,11 +76,23 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure public readonly FrameRequestHeaders RequestHeaders = new FrameRequestHeaders(); public readonly FrameResponseHeaders ResponseHeaders = new FrameResponseHeaders(); + private readonly KestrelServerOptions _options; + + public Headers(KestrelServerOptions options) + { + _options = options; + } + public void Initialize(DateHeaderValueManager dateValueManager) { var dateHeaderValues = dateValueManager.GetDateHeaderValues(); + ResponseHeaders.SetRawDate(dateHeaderValues.String, dateHeaderValues.Bytes); - ResponseHeaders.SetRawServer("Kestrel", BytesServer); + + if (_options.AddServerHeader) + { + ResponseHeaders.SetRawServer(Constants.ServerName, BytesServer); + } } public void Uninitialize() diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServerOptions.cs b/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServerOptions.cs index ddf85f9a27..708eb240b2 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServerOptions.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServerOptions.cs @@ -32,6 +32,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel public bool NoDelay { get; set; } = true; + /// + /// Gets or sets whether the Server header should be included in each response. + /// + public bool AddServerHeader { get; set; } = true; + /// /// The amount of time after the server begins shutting down before connections will be forcefully closed. /// By default, Kestrel will wait 5 seconds for any ongoing requests to complete before terminating diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameResponseHeadersTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameResponseHeadersTests.cs index 07be384d2c..097d4dac9a 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameResponseHeadersTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameResponseHeadersTests.cs @@ -15,10 +15,13 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { public class FrameResponseHeadersTests { - [Fact] - public void InitialDictionaryContainsServerAndDate() + [Theory] + [InlineData(true)] + [InlineData(false)] + public void InitialDictionaryContainsServerAndDate(bool addServerHeader) { - var serverOptions = new KestrelServerOptions(); + var serverOptions = new KestrelServerOptions { AddServerHeader = addServerHeader }; + var connectionContext = new ConnectionContext { DateHeaderValueManager = new DateHeaderValueManager(), @@ -31,12 +34,22 @@ namespace Microsoft.AspNetCore.Server.KestrelTests IDictionary headers = frame.ResponseHeaders; - Assert.Equal(2, headers.Count); + if (addServerHeader) + { + Assert.Equal(2, headers.Count); - StringValues serverHeader; - Assert.True(headers.TryGetValue("Server", out serverHeader)); - Assert.Equal(1, serverHeader.Count); - Assert.Equal("Kestrel", serverHeader[0]); + StringValues serverHeader; + Assert.True(headers.TryGetValue("Server", out serverHeader)); + Assert.Equal(1, serverHeader.Count); + Assert.Equal("Kestrel", serverHeader[0]); + } + else + { + Assert.Equal(1, headers.Count); + + StringValues serverHeader; + Assert.False(headers.TryGetValue("Server", out serverHeader)); + } StringValues dateHeader; DateTime date; From 67ed6c59584f122984e06007e801d5d7c28eb044 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Fri, 20 May 2016 16:07:24 -0700 Subject: [PATCH 0736/1662] Remove LibuvCopier from KestrelHttpServer.sln - This has been moved to https://github.com/aspnet/libuv-package --- KestrelHttpServer.sln | 7 ------- 1 file changed, 7 deletions(-) diff --git a/KestrelHttpServer.sln b/KestrelHttpServer.sln index a9155550a7..c55af22354 100644 --- a/KestrelHttpServer.sln +++ b/KestrelHttpServer.sln @@ -28,8 +28,6 @@ Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNetCore.Server EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tools", "tools", "{327F7880-D9AF-46BD-B45C-3B7E34A01DFD}" EndProject -Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNetCore.Server.Kestrel.LibuvCopier", "tools\Microsoft.AspNetCore.Server.Kestrel.LibuvCopier\Microsoft.AspNetCore.Server.Kestrel.LibuvCopier.xproj", "{8CBA6FE3-3CC9-4420-8AA3-123E983734C2}" -EndProject Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNetCore.Server.Kestrel.Https", "src\Microsoft.AspNetCore.Server.Kestrel.Https\Microsoft.AspNetCore.Server.Kestrel.Https.xproj", "{5F64B3C3-0C2E-431A-B820-A81BBFC863DA}" EndProject Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNetCore.Server.Kestrel.FunctionalTests", "test\Microsoft.AspNetCore.Server.Kestrel.FunctionalTests\Microsoft.AspNetCore.Server.Kestrel.FunctionalTests.xproj", "{9559A5F1-080C-4909-B6CF-7E4B3DC55748}" @@ -60,10 +58,6 @@ Global {BD2D4D29-1BD9-40D0-BB31-337D5416B63C}.Debug|Any CPU.Build.0 = Debug|Any CPU {BD2D4D29-1BD9-40D0-BB31-337D5416B63C}.Release|Any CPU.ActiveCfg = Release|Any CPU {BD2D4D29-1BD9-40D0-BB31-337D5416B63C}.Release|Any CPU.Build.0 = Release|Any CPU - {8CBA6FE3-3CC9-4420-8AA3-123E983734C2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {8CBA6FE3-3CC9-4420-8AA3-123E983734C2}.Debug|Any CPU.Build.0 = Debug|Any CPU - {8CBA6FE3-3CC9-4420-8AA3-123E983734C2}.Release|Any CPU.ActiveCfg = Release|Any CPU - {8CBA6FE3-3CC9-4420-8AA3-123E983734C2}.Release|Any CPU.Build.0 = Release|Any CPU {5F64B3C3-0C2E-431A-B820-A81BBFC863DA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {5F64B3C3-0C2E-431A-B820-A81BBFC863DA}.Debug|Any CPU.Build.0 = Debug|Any CPU {5F64B3C3-0C2E-431A-B820-A81BBFC863DA}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -82,7 +76,6 @@ Global {2C3CB3DC-EEBF-4F52-9E1C-4F2F972E76C3} = {8A3D00B8-1CCF-4BE6-A060-11104CE2D9CE} {B35D4D31-E74C-4646-8A11-7A7A40F0021E} = {8A3D00B8-1CCF-4BE6-A060-11104CE2D9CE} {BD2D4D29-1BD9-40D0-BB31-337D5416B63C} = {327F7880-D9AF-46BD-B45C-3B7E34A01DFD} - {8CBA6FE3-3CC9-4420-8AA3-123E983734C2} = {327F7880-D9AF-46BD-B45C-3B7E34A01DFD} {5F64B3C3-0C2E-431A-B820-A81BBFC863DA} = {2D5D5227-4DBD-499A-96B1-76A36B03B750} {9559A5F1-080C-4909-B6CF-7E4B3DC55748} = {D3273454-EA07-41D2-BF0B-FCC3675C2483} EndGlobalSection From 925d8e0200f9dc06b77e6f8c444c4accc9cf86f9 Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Thu, 19 May 2016 15:24:36 -0700 Subject: [PATCH 0737/1662] Always cache headers and streams across frames (#754). --- .../Http/Frame.cs | 46 +++---- .../Http/FrameOfT.cs | 1 - .../Http/FrameRequestStream.cs | 5 +- .../Http/FrameResponseStream.cs | 18 +-- .../Infrastructure/Headers.cs | 40 ++++++ .../Infrastructure/HttpComponentFactory.cs | 128 ------------------ .../Infrastructure/IHttpComponentFactory.cs | 20 --- .../Infrastructure/Streams.cs | 21 +++ .../KestrelServer.cs | 6 +- .../KestrelServerOptions.cs | 18 --- .../ServiceContext.cs | 6 - .../EngineTests.cs | 63 +++------ .../FrameResponseHeadersTests.cs | 4 - .../FrameResponseStreamTests.cs | 23 ++-- .../MessageBodyTests.cs | 9 +- .../TestHelpers/MockFrameControl.cs | 35 +++++ .../TestServiceContext.cs | 3 - 17 files changed, 155 insertions(+), 291 deletions(-) create mode 100644 src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/Headers.cs delete mode 100644 src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/HttpComponentFactory.cs delete mode 100644 src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/IHttpComponentFactory.cs create mode 100644 src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/Streams.cs create mode 100644 test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockFrameControl.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs index fb35280475..3b7e861ff7 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs @@ -174,19 +174,29 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http public void InitializeHeaders() { - _frameHeaders = HttpComponentFactory.CreateHeaders(DateHeaderValueManager); - RequestHeaders = _frameHeaders.RequestHeaders; - ResponseHeaders = _frameHeaders.ResponseHeaders; + if (_frameHeaders == null) + { + _frameHeaders = new Headers(ServerOptions); + RequestHeaders = _frameHeaders.RequestHeaders; + ResponseHeaders = _frameHeaders.ResponseHeaders; + } + + _frameHeaders.Initialize(DateHeaderValueManager); } public void InitializeStreams(MessageBody messageBody) { - _frameStreams = HttpComponentFactory.CreateStreams(this); + if (_frameStreams == null) + { + _frameStreams = new Streams(this); + RequestBody = _frameStreams.RequestBody; + ResponseBody = _frameStreams.ResponseBody; + DuplexStream = _frameStreams.DuplexStream; + } - RequestBody = _frameStreams.RequestBody.StartAcceptingReads(messageBody); - ResponseBody = _frameStreams.ResponseBody.StartAcceptingWrites(); - DuplexStream = _frameStreams.DuplexStream; + _frameStreams.RequestBody.StartAcceptingReads(messageBody); + _frameStreams.ResponseBody.StartAcceptingWrites(); } public void PauseStreams() @@ -209,7 +219,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http public void Reset() { - ResetComponents(); + _frameHeaders?.Reset(); _onStarting = null; _onCompleted = null; @@ -246,26 +256,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http _abortedCts = null; } - protected void ResetComponents() - { - var frameHeaders = Interlocked.Exchange(ref _frameHeaders, null); - if (frameHeaders != null) - { - RequestHeaders = null; - ResponseHeaders = null; - HttpComponentFactory.DisposeHeaders(frameHeaders); - } - - var frameStreams = Interlocked.Exchange(ref _frameStreams, null); - if (frameStreams != null) - { - RequestBody = null; - ResponseBody = null; - DuplexStream = null; - HttpComponentFactory.DisposeStreams(frameStreams); - } - } - /// /// Called once by Connection class to begin the RequestProcessingAsync loop. /// diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameOfT.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameOfT.cs index 6c03a812d2..c0181c5463 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameOfT.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameOfT.cs @@ -155,7 +155,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { await TryProduceInvalidRequestResponse(); - ResetComponents(); _abortedCts = null; // If _requestAborted is set, the connection has already been closed. diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameRequestStream.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameRequestStream.cs index a02413fdb9..c19a10a5dc 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameRequestStream.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameRequestStream.cs @@ -9,7 +9,7 @@ using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; namespace Microsoft.AspNetCore.Server.Kestrel.Http { - public class FrameRequestStream : Stream + class FrameRequestStream : Stream { private MessageBody _body; private FrameStreamState _state; @@ -132,7 +132,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http throw new NotSupportedException(); } - public Stream StartAcceptingReads(MessageBody body) + public void StartAcceptingReads(MessageBody body) { // Only start if not aborted if (_state == FrameStreamState.Closed) @@ -140,7 +140,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http _state = FrameStreamState.Open; _body = body; } - return this; } public void PauseAcceptingReads() diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameResponseStream.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameResponseStream.cs index 522e805e10..82edafb318 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameResponseStream.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameResponseStream.cs @@ -14,8 +14,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http private IFrameControl _frameControl; private FrameStreamState _state; - public FrameResponseStream() + public FrameResponseStream(IFrameControl frameControl) { + _frameControl = frameControl; _state = FrameStreamState.Closed; } @@ -94,15 +95,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http return task; } - public Stream StartAcceptingWrites() + public void StartAcceptingWrites() { // Only start if not aborted if (_state == FrameStreamState.Closed) { _state = FrameStreamState.Open; } - - return this; } public void PauseAcceptingWrites() @@ -134,17 +133,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } - public void Initialize(IFrameControl frameControl) - { - _frameControl = frameControl; - } - - public void Uninitialize() - { - _frameControl = null; - _state = FrameStreamState.Closed; - } - private Task ValidateState(CancellationToken cancellationToken) { switch (_state) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/Headers.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/Headers.cs new file mode 100644 index 0000000000..1f81dcdea8 --- /dev/null +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/Headers.cs @@ -0,0 +1,40 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System.Text; +using Microsoft.AspNetCore.Server.Kestrel.Http; + +namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure +{ + class Headers + { + public static readonly byte[] BytesServer = Encoding.ASCII.GetBytes("\r\nServer: Kestrel"); + + private readonly KestrelServerOptions _options; + + public Headers(KestrelServerOptions options) + { + _options = options; + } + + public void Initialize(DateHeaderValueManager dateValueManager) + { + var dateHeaderValues = dateValueManager.GetDateHeaderValues(); + ResponseHeaders.SetRawDate(dateHeaderValues.String, dateHeaderValues.Bytes); + + if (_options.AddServerHeader) + { + ResponseHeaders.SetRawServer("Kestrel", BytesServer); + } + } + + public FrameRequestHeaders RequestHeaders { get; } = new FrameRequestHeaders(); + public FrameResponseHeaders ResponseHeaders { get; } = new FrameResponseHeaders(); + + public void Reset() + { + RequestHeaders.Reset(); + ResponseHeaders.Reset(); + } + } +} diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/HttpComponentFactory.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/HttpComponentFactory.cs deleted file mode 100644 index baeb975233..0000000000 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/HttpComponentFactory.cs +++ /dev/null @@ -1,128 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System.Collections.Concurrent; -using System.Text; -using Microsoft.AspNetCore.Server.Kestrel.Http; - -namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure -{ - class HttpComponentFactory : IHttpComponentFactory - { - - private ConcurrentQueue _streamPool = new ConcurrentQueue(); - private ConcurrentQueue _headerPool = new ConcurrentQueue(); - - public KestrelServerOptions ServerOptions { get; set; } - - public HttpComponentFactory(KestrelServerOptions serverOptions) - { - ServerOptions = serverOptions; - } - - public Streams CreateStreams(IFrameControl frameControl) - { - Streams streams; - - if (!_streamPool.TryDequeue(out streams)) - { - streams = new Streams(); - } - - streams.Initialize(frameControl); - - return streams; - } - - public void DisposeStreams(Streams streams) - { - if (_streamPool.Count < ServerOptions.MaxPooledStreams) - { - streams.Uninitialize(); - - _streamPool.Enqueue(streams); - } - } - - public Headers CreateHeaders(DateHeaderValueManager dateValueManager) - { - Headers headers; - - if (!_headerPool.TryDequeue(out headers)) - { - headers = new Headers(ServerOptions); - } - - headers.Initialize(dateValueManager); - - return headers; - } - - public void DisposeHeaders(Headers headers) - { - if (_headerPool.Count < ServerOptions.MaxPooledHeaders) - { - headers.Uninitialize(); - - _headerPool.Enqueue(headers); - } - } - } - - internal class Headers - { - public static readonly byte[] BytesServer = Encoding.ASCII.GetBytes("\r\nServer: Kestrel"); - - public readonly FrameRequestHeaders RequestHeaders = new FrameRequestHeaders(); - public readonly FrameResponseHeaders ResponseHeaders = new FrameResponseHeaders(); - - private readonly KestrelServerOptions _options; - - public Headers(KestrelServerOptions options) - { - _options = options; - } - - public void Initialize(DateHeaderValueManager dateValueManager) - { - var dateHeaderValues = dateValueManager.GetDateHeaderValues(); - - ResponseHeaders.SetRawDate(dateHeaderValues.String, dateHeaderValues.Bytes); - - if (_options.AddServerHeader) - { - ResponseHeaders.SetRawServer(Constants.ServerName, BytesServer); - } - } - - public void Uninitialize() - { - RequestHeaders.Reset(); - ResponseHeaders.Reset(); - } - } - - internal class Streams - { - public readonly FrameRequestStream RequestBody; - public readonly FrameResponseStream ResponseBody; - public readonly FrameDuplexStream DuplexStream; - - public Streams() - { - RequestBody = new FrameRequestStream(); - ResponseBody = new FrameResponseStream(); - DuplexStream = new FrameDuplexStream(RequestBody, ResponseBody); - } - - public void Initialize(IFrameControl frameControl) - { - ResponseBody.Initialize(frameControl); - } - - public void Uninitialize() - { - ResponseBody.Uninitialize(); - } - } -} diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/IHttpComponentFactory.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/IHttpComponentFactory.cs deleted file mode 100644 index 3dcb234bbd..0000000000 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/IHttpComponentFactory.cs +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using Microsoft.AspNetCore.Server.Kestrel.Http; - -namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure -{ - interface IHttpComponentFactory - { - KestrelServerOptions ServerOptions { get; set; } - - Streams CreateStreams(IFrameControl frameControl); - - void DisposeStreams(Streams streams); - - Headers CreateHeaders(DateHeaderValueManager dateValueManager); - - void DisposeHeaders(Headers headers); - } -} diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/Streams.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/Streams.cs new file mode 100644 index 0000000000..af0a3384c2 --- /dev/null +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/Streams.cs @@ -0,0 +1,21 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using Microsoft.AspNetCore.Server.Kestrel.Http; + +namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure +{ + class Streams + { + public Streams(IFrameControl frameControl) + { + RequestBody = new FrameRequestStream(); + ResponseBody = new FrameResponseStream(frameControl); + DuplexStream = new FrameDuplexStream(RequestBody, ResponseBody); + } + + public FrameRequestStream RequestBody { get; } + public FrameResponseStream ResponseBody { get; } + public FrameDuplexStream DuplexStream { get; } + } +} diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServer.cs b/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServer.cs index 35b134d152..558794bf6a 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServer.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServer.cs @@ -44,8 +44,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel _applicationLifetime = applicationLifetime; _logger = loggerFactory.CreateLogger(typeof(KestrelServer).GetTypeInfo().Namespace); Features = new FeatureCollection(); - var componentFactory = new HttpComponentFactory(Options); - Features.Set(componentFactory); _serverAddresses = new ServerAddressesFeature(); Features.Set(_serverAddresses); } @@ -65,7 +63,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel try { - var componentFactory = Features.Get(); var dateHeaderValueManager = new DateHeaderValueManager(); var trace = new KestrelTrace(_logger); var engine = new KestrelEngine(new ServiceContext @@ -78,8 +75,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel Log = trace, ThreadPool = new LoggingThreadPool(trace), DateHeaderValueManager = dateHeaderValueManager, - ServerOptions = Options, - HttpComponentFactory = componentFactory + ServerOptions = Options }); _disposables.Push(engine); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServerOptions.cs b/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServerOptions.cs index 708eb240b2..7a6c7953e7 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServerOptions.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServerOptions.cs @@ -12,24 +12,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel public IConnectionFilter ConnectionFilter { get; set; } - /// - /// Gets or sets value that instructs whether it is safe to - /// pool the Request and Response objects - /// for another request after the Response's OnCompleted callback has fired. - /// When this values is greater than zero, it is not safe to retain references to feature components after this event has fired. - /// Value is zero by default. - /// - public int MaxPooledStreams { get; set; } - - /// - /// Gets or sets value that instructs whether it is safe to - /// pool the Request and Response headers - /// for another request after the Response's OnCompleted callback has fired. - /// When this values is greater than zero, it is not safe to retain references to feature components after this event has fired. - /// Value is zero by default. - /// - public int MaxPooledHeaders { get; set; } - public bool NoDelay { get; set; } = true; /// diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/ServiceContext.cs b/src/Microsoft.AspNetCore.Server.Kestrel/ServiceContext.cs index 72103028d1..a2e1aa4f53 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/ServiceContext.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/ServiceContext.cs @@ -2,10 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.Net; using Microsoft.AspNetCore.Hosting; -using Microsoft.AspNetCore.Http.Features; -using Microsoft.AspNetCore.Server.Kestrel.Filter; using Microsoft.AspNetCore.Server.Kestrel.Http; using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; @@ -25,7 +22,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel FrameFactory = context.FrameFactory; DateHeaderValueManager = context.DateHeaderValueManager; ServerOptions = context.ServerOptions; - HttpComponentFactory = context.HttpComponentFactory; } public IApplicationLifetime AppLifetime { get; set; } @@ -39,7 +35,5 @@ namespace Microsoft.AspNetCore.Server.Kestrel public DateHeaderValueManager DateHeaderValueManager { get; set; } public KestrelServerOptions ServerOptions { get; set; } - - internal IHttpComponentFactory HttpComponentFactory { get; set; } } } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs index 413a3c64f2..a7c88d914e 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs @@ -170,13 +170,15 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [Theory] [MemberData(nameof(ConnectionFilterData))] - public async Task ReuseStreamsOn(ServiceContext testContext) + public async Task HeadersAndStreamsAreReused(ServiceContext testContext) { - testContext.ServerOptions.MaxPooledStreams = 120; - var streamCount = 0; + var requestHeadersCount = 0; + var responseHeadersCount = 0; var loopCount = 20; Stream lastStream = null; + IHeaderDictionary lastRequestHeaders = null; + IHeaderDictionary lastResponseHeaders = null; using (var server = new TestServer( context => @@ -186,6 +188,16 @@ namespace Microsoft.AspNetCore.Server.KestrelTests lastStream = context.Request.Body; streamCount++; } + if (context.Request.Headers != lastRequestHeaders) + { + lastRequestHeaders = context.Request.Headers; + requestHeadersCount++; + } + if (context.Response.Headers != lastResponseHeaders) + { + lastResponseHeaders = context.Response.Headers; + responseHeadersCount++; + } context.Response.Headers.Clear(); return context.Request.Body.CopyToAsync(context.Response.Body); }, @@ -208,49 +220,8 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } Assert.Equal(1, streamCount); - } - } - - [Theory] - [MemberData(nameof(ConnectionFilterData))] - public async Task ReuseStreamsOff(ServiceContext testContext) - { - testContext.ServerOptions.MaxPooledStreams = 0; - - var streamCount = 0; - var loopCount = 20; - Stream lastStream = null; - - using (var server = new TestServer( - context => - { - if (context.Request.Body != lastStream) - { - lastStream = context.Request.Body; - streamCount++; - } - context.Response.Headers.Clear(); - return context.Request.Body.CopyToAsync(context.Response.Body); - }, - testContext)) - { - - using (var connection = new TestConnection(server.Port)) - { - var requestData = - Enumerable.Repeat("GET / HTTP/1.1\r\n", loopCount) - .Concat(new[] { "GET / HTTP/1.1\r\nConnection: close\r\n\r\nGoodbye" }); - - var responseData = - Enumerable.Repeat("HTTP/1.1 200 OK\r\nContent-Length: 0\r\n", loopCount) - .Concat(new[] { "HTTP/1.1 200 OK\r\nConnection: close\r\n\r\nGoodbye" }); - - await connection.SendEnd(requestData.ToArray()); - - await connection.ReceiveEnd(responseData.ToArray()); - } - - Assert.Equal(loopCount + 1, streamCount); + Assert.Equal(1, requestHeadersCount); + Assert.Equal(1, responseHeadersCount); } } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameResponseHeadersTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameResponseHeadersTests.cs index 097d4dac9a..41f3fd3f78 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameResponseHeadersTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameResponseHeadersTests.cs @@ -6,8 +6,6 @@ using System.Collections.Generic; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Server.Kestrel; using Microsoft.AspNetCore.Server.Kestrel.Http; -using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; -using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Primitives; using Xunit; @@ -27,7 +25,6 @@ namespace Microsoft.AspNetCore.Server.KestrelTests DateHeaderValueManager = new DateHeaderValueManager(), ServerAddress = ServerAddress.FromUrl("http://localhost:5000"), ServerOptions = serverOptions, - HttpComponentFactory = new HttpComponentFactory(serverOptions) }; var frame = new Frame(application: null, context: connectionContext); frame.InitializeHeaders(); @@ -70,7 +67,6 @@ namespace Microsoft.AspNetCore.Server.KestrelTests DateHeaderValueManager = new DateHeaderValueManager(), ServerAddress = ServerAddress.FromUrl("http://localhost:5000"), ServerOptions = serverOptions, - HttpComponentFactory = new HttpComponentFactory(serverOptions) }; var frame = new Frame(application: null, context: connectionContext); frame.InitializeHeaders(); diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameResponseStreamTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameResponseStreamTests.cs index d8d1dbcad4..556fc6701f 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameResponseStreamTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameResponseStreamTests.cs @@ -5,6 +5,7 @@ using System; using System.IO; using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Http; +using Microsoft.AspNetCore.Server.KestrelTests.TestHelpers; using Xunit; namespace Microsoft.AspNetCore.Server.KestrelTests @@ -14,42 +15,42 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [Fact] public void CanReadReturnsFalse() { - var stream = new FrameResponseStream(); + var stream = new FrameResponseStream(new MockFrameControl()); Assert.False(stream.CanRead); } [Fact] public void CanSeekReturnsFalse() { - var stream = new FrameResponseStream(); + var stream = new FrameResponseStream(new MockFrameControl()); Assert.False(stream.CanSeek); } [Fact] public void CanWriteReturnsTrue() { - var stream = new FrameResponseStream(); + var stream = new FrameResponseStream(new MockFrameControl()); Assert.True(stream.CanWrite); } [Fact] public void ReadThrows() { - var stream = new FrameResponseStream(); + var stream = new FrameResponseStream(new MockFrameControl()); Assert.Throws(() => stream.Read(new byte[1], 0, 1)); } [Fact] public void ReadByteThrows() { - var stream = new FrameResponseStream(); + var stream = new FrameResponseStream(new MockFrameControl()); Assert.Throws(() => stream.ReadByte()); } [Fact] public async Task ReadAsyncThrows() { - var stream = new FrameResponseStream(); + var stream = new FrameResponseStream(new MockFrameControl()); await Assert.ThrowsAsync(() => stream.ReadAsync(new byte[1], 0, 1)); } @@ -57,7 +58,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [Fact] public void BeginReadThrows() { - var stream = new FrameResponseStream(); + var stream = new FrameResponseStream(new MockFrameControl()); Assert.Throws(() => stream.BeginRead(new byte[1], 0, 1, null, null)); } #endif @@ -65,28 +66,28 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [Fact] public void SeekThrows() { - var stream = new FrameResponseStream(); + var stream = new FrameResponseStream(new MockFrameControl()); Assert.Throws(() => stream.Seek(0, SeekOrigin.Begin)); } [Fact] public void LengthThrows() { - var stream = new FrameResponseStream(); + var stream = new FrameResponseStream(new MockFrameControl()); Assert.Throws(() => stream.Length); } [Fact] public void SetLengthThrows() { - var stream = new FrameResponseStream(); + var stream = new FrameResponseStream(new MockFrameControl()); Assert.Throws(() => stream.SetLength(0)); } [Fact] public void PositionThrows() { - var stream = new FrameResponseStream(); + var stream = new FrameResponseStream(new MockFrameControl()); Assert.Throws(() => stream.Position); Assert.Throws(() => stream.Position = 0); } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/MessageBodyTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/MessageBodyTests.cs index 97cea21c2e..fafeaca0ed 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/MessageBodyTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/MessageBodyTests.cs @@ -20,7 +20,8 @@ namespace Microsoft.AspNetCore.Server.KestrelTests using (var input = new TestInput()) { var body = MessageBody.For("HTTP/1.0", new FrameRequestHeaders(), input.FrameContext); - var stream = new FrameRequestStream().StartAcceptingReads(body); + var stream = new FrameRequestStream(); + stream.StartAcceptingReads(body); input.Add("Hello", true); @@ -40,7 +41,8 @@ namespace Microsoft.AspNetCore.Server.KestrelTests using (var input = new TestInput()) { var body = MessageBody.For("HTTP/1.0", new FrameRequestHeaders(), input.FrameContext); - var stream = new FrameRequestStream().StartAcceptingReads(body); + var stream = new FrameRequestStream(); + stream.StartAcceptingReads(body); input.Add("Hello", true); @@ -60,7 +62,8 @@ namespace Microsoft.AspNetCore.Server.KestrelTests using (var input = new TestInput()) { var body = MessageBody.For("HTTP/1.0", new FrameRequestHeaders(), input.FrameContext); - var stream = new FrameRequestStream().StartAcceptingReads(body); + var stream = new FrameRequestStream(); + stream.StartAcceptingReads(body); // Input needs to be greater than 4032 bytes to allocate a block not backed by a slab. var largeInput = new string('a', 8192); diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockFrameControl.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockFrameControl.cs new file mode 100644 index 0000000000..d6d0596b02 --- /dev/null +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockFrameControl.cs @@ -0,0 +1,35 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Threading; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Server.Kestrel.Http; + +namespace Microsoft.AspNetCore.Server.KestrelTests.TestHelpers +{ + public class MockFrameControl : IFrameControl + { + public void Flush() + { + } + + public Task FlushAsync(CancellationToken cancellationToken) + { + return Task.FromResult(0); + } + + public void ProduceContinue() + { + } + + public void Write(ArraySegment data) + { + } + + public Task WriteAsync(ArraySegment data, CancellationToken cancellationToken) + { + return Task.FromResult(0); + } + } +} diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestServiceContext.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/TestServiceContext.cs index 0457345450..12238ae2de 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/TestServiceContext.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/TestServiceContext.cs @@ -7,7 +7,6 @@ using Microsoft.AspNetCore.Server.Kestrel; using Microsoft.AspNetCore.Server.Kestrel.Filter; using Microsoft.AspNetCore.Server.Kestrel.Http; using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; -using Microsoft.Extensions.Configuration; namespace Microsoft.AspNetCore.Server.KestrelTests { @@ -24,8 +23,6 @@ namespace Microsoft.AspNetCore.Server.KestrelTests ServerOptions = new KestrelServerOptions(); ServerOptions.ShutdownTimeout = TimeSpan.FromSeconds(5); - - HttpComponentFactory = new HttpComponentFactory(ServerOptions); } public TestServiceContext(IConnectionFilter filter) From 60988801324cc918c9f589fe08b7a4bbc491ac79 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Thu, 19 May 2016 00:56:50 +0100 Subject: [PATCH 0738/1662] Reset connection info not using interface --- .../Http/Frame.FeatureCollection.cs | 31 +++++++++++++++---- .../Http/Frame.cs | 18 ++++++----- 2 files changed, 36 insertions(+), 13 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.FeatureCollection.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.FeatureCollection.cs index 4e44236545..fbd2c43cde 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.FeatureCollection.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.FeatureCollection.cs @@ -11,7 +11,6 @@ using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http.Features; -using Microsoft.Extensions.Logging; using Microsoft.Extensions.Primitives; namespace Microsoft.AspNetCore.Server.Kestrel.Http @@ -265,15 +264,35 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http int IFeatureCollection.Revision => _featureRevision; - IPAddress IHttpConnectionFeature.RemoteIpAddress { get; set; } + IPAddress IHttpConnectionFeature.RemoteIpAddress + { + get { return RemoteIpAddress; } + set { RemoteIpAddress = value; } + } - IPAddress IHttpConnectionFeature.LocalIpAddress { get; set; } + IPAddress IHttpConnectionFeature.LocalIpAddress + { + get { return LocalIpAddress; } + set { LocalIpAddress = value; } + } - int IHttpConnectionFeature.RemotePort { get; set; } + int IHttpConnectionFeature.RemotePort + { + get { return RemotePort; } + set { RemotePort = value; } + } - int IHttpConnectionFeature.LocalPort { get; set; } + int IHttpConnectionFeature.LocalPort + { + get { return LocalPort; } + set { LocalPort = value; } + } - string IHttpConnectionFeature.ConnectionId { get; set; } + string IHttpConnectionFeature.ConnectionId + { + get { return ConnectionIdFeature; } + set { ConnectionIdFeature = value; } + } object IFeatureCollection.this[Type key] { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs index 3b7e861ff7..16c431445a 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs @@ -5,6 +5,7 @@ using System; using System.Collections.Generic; using System.IO; using System.Linq; +using System.Net; using System.Numerics; using System.Text; using System.Threading; @@ -74,6 +75,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http Reset(); } + public string ConnectionIdFeature { get; set; } + public IPAddress RemoteIpAddress { get; set; } + public int RemotePort { get; set; } + public IPAddress LocalIpAddress { get; set; } + public int LocalPort { get; set; } public string Scheme { get; set; } public string Method { get; set; } public string RequestUri { get; set; } @@ -241,14 +247,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http StatusCode = 200; ReasonPhrase = null; - var httpConnectionFeature = this as IHttpConnectionFeature; - httpConnectionFeature.RemoteIpAddress = RemoteEndPoint?.Address; - httpConnectionFeature.RemotePort = RemoteEndPoint?.Port ?? 0; + RemoteIpAddress = RemoteEndPoint?.Address; + RemotePort = RemoteEndPoint?.Port ?? 0; - httpConnectionFeature.LocalIpAddress = LocalEndPoint?.Address; - httpConnectionFeature.LocalPort = LocalEndPoint?.Port ?? 0; - - httpConnectionFeature.ConnectionId = ConnectionId; + LocalIpAddress = LocalEndPoint?.Address; + LocalPort = LocalEndPoint?.Port ?? 0; + ConnectionIdFeature = ConnectionId; PrepareRequest?.Invoke(this); From 5ca6592677bc70c5c9f624a9a775e040e4753d38 Mon Sep 17 00:00:00 2001 From: Mike Harder Date: Mon, 23 May 2016 14:06:46 -0700 Subject: [PATCH 0739/1662] Don't bind if only port is specified (#814) (#861) - Also renamed ServerAddressFacts to ServerAddressTests to match existing test classes --- .../ServerAddress.cs | 11 ----------- .../AddressRegistrationTests.cs | 7 ++++--- .../{ServerAddressFacts.cs => ServerAddressTests.cs} | 4 ++-- 3 files changed, 6 insertions(+), 16 deletions(-) rename test/Microsoft.AspNetCore.Server.KestrelTests/{ServerAddressFacts.cs => ServerAddressTests.cs} (97%) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/ServerAddress.cs b/src/Microsoft.AspNetCore.Server.Kestrel/ServerAddress.cs index 536492dfb1..ce35ff39ce 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/ServerAddress.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/ServerAddress.cs @@ -78,17 +78,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel int schemeDelimiterStart = url.IndexOf("://", StringComparison.Ordinal); if (schemeDelimiterStart < 0) { - int port; - if (int.TryParse(url, NumberStyles.None, CultureInfo.InvariantCulture, out port)) - { - return new ServerAddress() - { - Scheme = "http", - Host = "+", - Port = port, - PathBase = "/" - }; - } return null; } int schemeDelimiterEnd = schemeDelimiterStart + "://".Length; diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs index 1f5fb0a61c..aa966d8298 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs @@ -97,8 +97,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests // Static port var port1 = GetNextPort(); var port2 = GetNextPort(); - dataset.Add($"{port1}", _ => new[] { $"http://localhost:{port1}/" }); - dataset.Add($"{port1};{port2}", _ => new[] { $"http://localhost:{port1}/", $"http://localhost:{port2}/" }); + + // Ensure multiple addresses can be separated by semicolon + dataset.Add($"http://localhost:{port1};http://localhost:{port2}", + _ => new[] { $"http://localhost:{port1}/", $"http://localhost:{port2}/" }); // Ensure "localhost" and "127.0.0.1" are equivalent dataset.Add($"http://localhost:{port1}", _ => new[] { $"http://localhost:{port1}/", $"http://127.0.0.1:{port1}/" }); @@ -108,7 +110,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests dataset.Add($"http://localhost:{port1}/base/path", _ => new[] { $"http://localhost:{port1}/base/path" }); // Dynamic port - dataset.Add("0", GetTestUrls); dataset.Add("http://localhost:0/", GetTestUrls); dataset.Add($"http://{Dns.GetHostName()}:0/", GetTestUrls); diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/ServerAddressFacts.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/ServerAddressTests.cs similarity index 97% rename from test/Microsoft.AspNetCore.Server.KestrelTests/ServerAddressFacts.cs rename to test/Microsoft.AspNetCore.Server.KestrelTests/ServerAddressTests.cs index d9beaa05b3..8aa99d1917 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/ServerAddressFacts.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/ServerAddressTests.cs @@ -8,10 +8,11 @@ using Xunit; namespace Microsoft.AspNetCore.Server.KestrelTests { - public class ServerAddressFacts + public class ServerAddressTests { [Theory] [InlineData("")] + [InlineData("5000")] [InlineData("//noscheme")] public void FromUriReturnsNullForSchemelessUrls(string url) { @@ -19,7 +20,6 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } [Theory] - [InlineData("5000", "http", "+", 5000, "/", "http://+:5000/")] [InlineData("://emptyscheme", "", "emptyscheme", 0, "", "://emptyscheme:0")] [InlineData("http://localhost", "http", "localhost", 80, "", "http://localhost:80")] [InlineData("http://www.example.com", "http", "www.example.com", 80, "", "http://www.example.com:80")] From 58070099fccea99c36167237ace8fb731e77dcc4 Mon Sep 17 00:00:00 2001 From: Mike Harder Date: Tue, 24 May 2016 11:38:24 -0700 Subject: [PATCH 0740/1662] Remove Console.WriteLine() from MemoryPoolBlockTests (#868) - Causes noise in test results --- .../MemoryPoolBlockTests.cs | 3 --- 1 file changed, 3 deletions(-) diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolBlockTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolBlockTests.cs index 748a0ecf34..0e86d2d7d6 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolBlockTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolBlockTests.cs @@ -58,9 +58,6 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [Fact] public void SeekWorksAcrossBlocks() { - Console.WriteLine($"Vector.IsHardwareAccelerated == {Vector.IsHardwareAccelerated}"); - Console.WriteLine($"Vector.Count == {Vector.Count}"); - using (var pool = new MemoryPool()) { var block1 = pool.Lease(); From d164f350b4dd83f127fb6d6d6e74548cef06cd3e Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Tue, 24 May 2016 15:59:35 -0700 Subject: [PATCH 0741/1662] Add comment explaining why ForChunkedEncoding._vectorCRs is not static --- src/Microsoft.AspNetCore.Server.Kestrel/Http/MessageBody.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/MessageBody.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/MessageBody.cs index 7bf6c1d7e6..940196ff87 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/MessageBody.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/MessageBody.cs @@ -215,6 +215,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http /// private class ForChunkedEncoding : MessageBody { + // This causes an InvalidProgramException if made static + // https://github.com/dotnet/corefx/issues/8825 private Vector _vectorCRs = new Vector((byte)'\r'); private int _inputLength; From cb284b9d5813a86d83b3f19c62ffbed00dfea4e3 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Mon, 23 May 2016 20:38:51 -0700 Subject: [PATCH 0742/1662] Fix race that would allow GetDateHeaderValues to return null --- .../Http/DateHeaderValueManager.cs | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/DateHeaderValueManager.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/DateHeaderValueManager.cs index d7022ab2dd..87a2e60de3 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/DateHeaderValueManager.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/DateHeaderValueManager.cs @@ -58,9 +58,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http /// The value in string and byte[] format. public DateHeaderValues GetDateHeaderValues() { - if (!_hadRequestsSinceLastTimerTick) + _hadRequestsSinceLastTimerTick = !_isDisposed; + + if (!_timerIsRunning) { - PrepareDateValues(); + StartTimer(); } return _dateValues; @@ -151,18 +153,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } - /// - /// Starts the timer if it's turned off, or sets the datevalues to the current time if disposed. - /// - private void PrepareDateValues() - { - _hadRequestsSinceLastTimerTick = !_isDisposed; - if (!_timerIsRunning) - { - StartTimer(); - } - } - /// /// Sets date values from a provided ticks value /// From 3f4e2323f4f577d782e30481be7b6f2081d480ad Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Fri, 20 May 2016 12:12:28 -0700 Subject: [PATCH 0743/1662] Throw when setting Frame.StatusCode or Frame.ReasonPhrase after response has already started (#805). --- .../Http/Frame.cs | 78 +++++++++++++------ .../FrameFacts.cs | 32 -------- .../FrameResponseHeadersTests.cs | 42 ++++++++++ .../FrameTests.cs | 65 ++++++++++++++++ .../TestHelpers/MockSocketOuptut.cs | 32 ++++++++ 5 files changed, 194 insertions(+), 55 deletions(-) delete mode 100644 test/Microsoft.AspNetCore.Server.KestrelTests/FrameFacts.cs create mode 100644 test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockSocketOuptut.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs index 16c431445a..2716a94e52 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs @@ -121,8 +121,42 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http public IHeaderDictionary RequestHeaders { get; set; } public Stream RequestBody { get; set; } - public int StatusCode { get; set; } - public string ReasonPhrase { get; set; } + private int _statusCode; + public int StatusCode + { + get + { + return _statusCode; + } + set + { + if (HasResponseStarted) + { + throw new InvalidOperationException("Status code cannot be set, response has already started."); + } + + _statusCode = value; + } + } + + private string _reasonPhrase; + public string ReasonPhrase + { + get + { + return _reasonPhrase; + } + set + { + if (HasResponseStarted) + { + throw new InvalidOperationException("Reason phrase cannot be set, response had already started."); + } + + _reasonPhrase = value; + } + } + public IHeaderDictionary ResponseHeaders { get; set; } public Stream ResponseBody { get; set; } @@ -579,6 +613,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (_requestRejected || _applicationException != null) { + if (HasResponseStarted) + { + // We can no longer change the response, so we simply close the connection. + _requestProcessingStopping = true; + return TaskUtilities.CompletedTask; + } + if (_requestRejected) { // 400 Bad Request @@ -591,30 +632,21 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http StatusCode = 500; } - if (HasResponseStarted) + ReasonPhrase = null; + + var responseHeaders = _frameHeaders.ResponseHeaders; + responseHeaders.Reset(); + var dateHeaderValues = DateHeaderValueManager.GetDateHeaderValues(); + + responseHeaders.SetRawDate(dateHeaderValues.String, dateHeaderValues.Bytes); + responseHeaders.SetRawContentLength("0", _bytesContentLengthZero); + + if (ServerOptions.AddServerHeader) { - // We can no longer respond with a 500, so we simply close the connection. - _requestProcessingStopping = true; - return TaskUtilities.CompletedTask; + responseHeaders.SetRawServer(Constants.ServerName, Headers.BytesServer); } - else - { - ReasonPhrase = null; - var responseHeaders = _frameHeaders.ResponseHeaders; - responseHeaders.Reset(); - var dateHeaderValues = DateHeaderValueManager.GetDateHeaderValues(); - - responseHeaders.SetRawDate(dateHeaderValues.String, dateHeaderValues.Bytes); - responseHeaders.SetRawContentLength("0", _bytesContentLengthZero); - - if (ServerOptions.AddServerHeader) - { - responseHeaders.SetRawServer(Constants.ServerName, Headers.BytesServer); - } - - ResponseHeaders = responseHeaders; - } + ResponseHeaders = responseHeaders; } if (!HasResponseStarted) diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameFacts.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameFacts.cs deleted file mode 100644 index deefd5511d..0000000000 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameFacts.cs +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using Microsoft.AspNetCore.Http.Features; -using Microsoft.AspNetCore.Server.Kestrel; -using Microsoft.AspNetCore.Server.Kestrel.Http; -using Xunit; - -namespace Microsoft.AspNetCore.Server.KestrelTests -{ - public class FrameFacts - { - [Fact] - public void ResetResetsScheme() - { - // Arrange - var connectionContext = new ConnectionContext() - { - DateHeaderValueManager = new DateHeaderValueManager(), - ServerAddress = ServerAddress.FromUrl("http://localhost:5000") - }; - var frame = new Frame(application: null, context: connectionContext); - frame.Scheme = "https"; - - // Act - frame.Reset(); - - // Assert - Assert.Equal("http", ((IFeatureCollection)frame).Get().Scheme); - } - } -} diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameResponseHeadersTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameResponseHeadersTests.cs index 41f3fd3f78..ce6098a5b2 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameResponseHeadersTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameResponseHeadersTests.cs @@ -125,5 +125,47 @@ namespace Microsoft.AspNetCore.Server.KestrelTests ((IDictionary)responseHeaders).Add(key, value); }); } + + [Fact] + public void ThrowsWhenAddingHeaderAfterReadOnlyIsSet() + { + var headers = new FrameResponseHeaders(); + headers.SetReadOnly(); + + Assert.Throws(() => ((IDictionary)headers).Add("my-header", new[] { "value" })); + } + + [Fact] + public void ThrowsWhenChangingHeaderAfterReadOnlyIsSet() + { + var headers = new FrameResponseHeaders(); + var dictionary = (IDictionary)headers; + dictionary.Add("my-header", new[] { "value" }); + headers.SetReadOnly(); + + Assert.Throws(() => dictionary["my-header"] = "other-value"); + } + + [Fact] + public void ThrowsWhenRemovingHeaderAfterReadOnlyIsSet() + { + var headers = new FrameResponseHeaders(); + var dictionary = (IDictionary)headers; + dictionary.Add("my-header", new[] { "value" }); + headers.SetReadOnly(); + + Assert.Throws(() => dictionary.Remove("my-header")); + } + + [Fact] + public void ThrowsWhenClearingHeadersAfterReadOnlyIsSet() + { + var headers = new FrameResponseHeaders(); + var dictionary = (IDictionary)headers; + dictionary.Add("my-header", new[] { "value" }); + headers.SetReadOnly(); + + Assert.Throws(() => dictionary.Clear()); + } } } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs index 8d6133a5f3..809dde54ab 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs @@ -4,9 +4,11 @@ using System; using System.Linq; using System.Text; +using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Server.Kestrel; using Microsoft.AspNetCore.Server.Kestrel.Http; using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; +using Microsoft.AspNetCore.Server.KestrelTests.TestHelpers; using Xunit; namespace Microsoft.AspNetCore.Server.KestrelTests @@ -50,5 +52,68 @@ namespace Microsoft.AspNetCore.Server.KestrelTests Assert.True(scan.IsEnd); } } + + [Fact] + public void ResetResetsScheme() + { + // Arrange + var connectionContext = new ConnectionContext() + { + DateHeaderValueManager = new DateHeaderValueManager(), + ServerAddress = ServerAddress.FromUrl("http://localhost:5000") + }; + var frame = new Frame(application: null, context: connectionContext); + frame.Scheme = "https"; + + // Act + frame.Reset(); + + // Assert + Assert.Equal("http", ((IFeatureCollection)frame).Get().Scheme); + } + + [Fact] + public void ThrowsWhenStatusCodeIsSetAfterResponseStarted() + { + // Arrange + var connectionContext = new ConnectionContext() + { + DateHeaderValueManager = new DateHeaderValueManager(), + ServerAddress = ServerAddress.FromUrl("http://localhost:5000"), + ServerOptions = new KestrelServerOptions(), + SocketOutput = new MockSocketOuptut() + }; + var frame = new Frame(application: null, context: connectionContext); + frame.InitializeHeaders(); + + // Act + frame.Write(new ArraySegment(new byte[1])); + + // Assert + Assert.True(frame.HasResponseStarted); + Assert.Throws(() => ((IHttpResponseFeature)frame).StatusCode = 404); + } + + [Fact] + public void ThrowsWhenReasonPhraseIsSetAfterResponseStarted() + { + // Arrange + var connectionContext = new ConnectionContext() + { + DateHeaderValueManager = new DateHeaderValueManager(), + ServerAddress = ServerAddress.FromUrl("http://localhost:5000"), + ServerOptions = new KestrelServerOptions(), + SocketOutput = new MockSocketOuptut() + }; + var frame = new Frame(application: null, context: connectionContext); + frame.InitializeHeaders(); + + // Act + frame.Write(new ArraySegment(new byte[1])); + + // Assert + Assert.True(frame.HasResponseStarted); + Assert.Throws(() => ((IHttpResponseFeature)frame).ReasonPhrase = "Reason phrase"); + } } } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockSocketOuptut.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockSocketOuptut.cs new file mode 100644 index 0000000000..051074c7d8 --- /dev/null +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockSocketOuptut.cs @@ -0,0 +1,32 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Threading; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Server.Kestrel.Http; +using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; + +namespace Microsoft.AspNetCore.Server.KestrelTests.TestHelpers +{ + public class MockSocketOuptut : ISocketOutput + { + public void ProducingComplete(MemoryPoolIterator end) + { + } + + public MemoryPoolIterator ProducingStart() + { + return new MemoryPoolIterator(); + } + + public void Write(ArraySegment buffer, bool chunk = false) + { + } + + public Task WriteAsync(ArraySegment buffer, bool chunk = false, CancellationToken cancellationToken = default(CancellationToken)) + { + return Task.FromResult(0); + } + } +} From a3d0bd0ec413d5a6563807925ba0bd11ad3eaba2 Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Mon, 23 May 2016 17:22:08 -0700 Subject: [PATCH 0744/1662] Bind to both IPv4 and IPv6 when localhost is specified (#231). --- .../Infrastructure/Constants.cs | 16 ++ .../KestrelServer.cs | 71 +++++++- .../Networking/Libuv.cs | 2 +- .../Networking/UvException.cs | 7 +- .../ServerAddress.cs | 11 ++ .../AddressRegistrationTests.cs | 152 ++++++++++++++---- .../IPv6SupportedConditionAttribute.cs | 2 +- .../PathBaseTests.cs | 9 +- .../RequestTests.cs | 16 +- .../ResponseTests.cs | 29 +--- .../ThreadCountTests.cs | 14 +- .../ConnectionTests.cs | 2 +- .../EngineTests.cs | 4 +- .../HttpsConnectionFilterTests.cs | 14 +- .../MultipleLoopTests.cs | 2 +- .../NetworkingTests.cs | 8 +- .../ServerAddressTests.cs | 10 ++ .../TestServer.cs | 5 +- 18 files changed, 264 insertions(+), 110 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/Constants.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/Constants.cs index 3031b022dc..de6294fee4 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/Constants.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/Constants.cs @@ -11,6 +11,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure public const int EOF = -4095; public static readonly int? ECONNRESET = GetECONNRESET(); + public static readonly int? EADDRINUSE = GetEADDRINUSE(); /// /// Prefix of host name used to specify Unix sockets in the configuration. @@ -39,5 +40,20 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure return null; } } + + private static int? GetEADDRINUSE() + { + switch (PlatformServices.Default.Runtime.OperatingSystemPlatform) + { + case Platform.Windows: + return -4091; + case Platform.Linux: + return -98; + case Platform.Darwin: + return -48; + default: + return null; + } + } } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServer.cs b/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServer.cs index 558794bf6a..50b873c265 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServer.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServer.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Net; using System.Reflection; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting.Server; @@ -11,6 +12,7 @@ using Microsoft.AspNetCore.Hosting.Server.Features; using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Server.Kestrel.Http; using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Networking; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; @@ -94,6 +96,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel { _logger.LogWarning("Unable to determine ECONNRESET value on this platform."); } + if (!Constants.EADDRINUSE.HasValue) + { + _logger.LogWarning("Unable to determine EADDRINUSE value on this platform."); + } engine.Start(threadCount); var atLeastOneListener = false; @@ -108,8 +114,69 @@ namespace Microsoft.AspNetCore.Server.Kestrel else { atLeastOneListener = true; - _disposables.Push(engine.CreateServer( - parsedAddress)); + + if (!parsedAddress.Host.Equals("localhost", StringComparison.OrdinalIgnoreCase)) + { + _disposables.Push(engine.CreateServer( + parsedAddress)); + } + else + { + if (parsedAddress.Port == 0) + { + throw new InvalidOperationException("Dynamic port binding is not supported when binding to localhost. You must either bind to 127.0.0.1:0 or [::1]:0, or both."); + } + + var ipv4Address = parsedAddress.WithHost("127.0.0.1"); + var exceptions = new List(); + + try + { + _disposables.Push(engine.CreateServer(ipv4Address)); + } + catch (AggregateException ex) + { + var uvException = ex.InnerException as UvException; + + if (uvException != null && uvException.StatusCode != Constants.EADDRINUSE) + { + _logger.LogWarning(0, ex, $"Unable to bind to {parsedAddress.ToString()} on the IPv4 loopback interface."); + exceptions.Add(uvException); + } + else + { + throw; + } + } + + var ipv6Address = parsedAddress.WithHost("[::1]"); + + try + { + _disposables.Push(engine.CreateServer(ipv6Address)); + } + catch (AggregateException ex) + { + var uvException = ex.InnerException as UvException; + + if (uvException != null && uvException.StatusCode != Constants.EADDRINUSE) + { + _logger.LogWarning(0, ex, $"Unable to bind to {parsedAddress.ToString()} on the IPv6 loopback interface."); + exceptions.Add(uvException); + } + else + { + throw; + } + } + + if (exceptions.Count == 2) + { + var ex = new AggregateException(exceptions); + _logger.LogError(0, ex, $"Unable to bind to {parsedAddress.ToString()} on any loopback interface."); + throw ex; + } + } // If requested port was "0", replace with assigned dynamic port. _serverAddresses.Addresses.Remove(address); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Networking/Libuv.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Networking/Libuv.cs index 1bbb502a7f..a5028b136c 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Networking/Libuv.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Networking/Libuv.cs @@ -78,7 +78,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Networking { var errorName = err_name(statusCode); var errorDescription = strerror(statusCode); - error = new UvException("Error " + statusCode + " " + errorName + " " + errorDescription); + error = new UvException("Error " + statusCode + " " + errorName + " " + errorDescription, statusCode); } else { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvException.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvException.cs index a63da72eba..791c1f95ac 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvException.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvException.cs @@ -7,6 +7,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Networking { public class UvException : Exception { - public UvException(string message) : base(message) { } + public UvException(string message, int statusCode) : base(message) + { + StatusCode = statusCode; + } + + public int StatusCode { get; } } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/ServerAddress.cs b/src/Microsoft.AspNetCore.Server.Kestrel/ServerAddress.cs index ce35ff39ce..528a39edb8 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/ServerAddress.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/ServerAddress.cs @@ -155,5 +155,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel return serverAddress; } + + internal ServerAddress WithHost(string host) + { + return new ServerAddress + { + Scheme = Scheme, + Host = host, + Port = Port, + PathBase = PathBase + }; + } } } \ No newline at end of file diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs index aa966d8298..c5f90cf61b 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs @@ -2,7 +2,6 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.Collections.Generic; using System.Linq; using System.Net; using System.Net.Http; @@ -13,8 +12,8 @@ using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting.Server.Features; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http.Extensions; +using Microsoft.AspNetCore.Server.Kestrel.Networking; using Microsoft.AspNetCore.Testing.xunit; -using Microsoft.Extensions.Configuration; using Xunit; namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests @@ -42,7 +41,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests await RegisterAddresses_Success(addressInput, testUrls); } + [ConditionalTheory, MemberData(nameof(AddressRegistrationDataIPv6Port80))] + [IPv6SupportedCondition] + [Port80SupportedCondition] + public async Task RegisterAddresses_IPv6Port80_Success(string addressInput, Func testUrls) + { + await RegisterAddresses_Success(addressInput, testUrls); + } + [ConditionalTheory, MemberData(nameof(AddressRegistrationDataIPv6ScopeId))] + [IPv6SupportedCondition] [OSSkipCondition(OperatingSystems.Linux, SkipReason = "HttpClient does not support IPv6 with scope ID on Linux (https://github.com/dotnet/corefx/issues/8235).")] [OSSkipCondition(OperatingSystems.MacOSX, SkipReason = "HttpClient does not support IPv6 with scope ID on Mac (https://github.com/dotnet/corefx/issues/8235).")] public async Task RegisterAddresses_IPv6ScopeId_Success(string addressInput, Func testUrls) @@ -50,18 +58,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests await RegisterAddresses_Success(addressInput, testUrls); } - public async Task RegisterAddresses_Success(string addressInput, Func testUrls) + private async Task RegisterAddresses_Success(string addressInput, Func testUrls) { - var config = new ConfigurationBuilder() - .AddInMemoryCollection(new Dictionary - { - { "server.urls", addressInput } - }) - .Build(); - var hostBuilder = new WebHostBuilder() - .UseConfiguration(config) .UseKestrel() + .UseUrls(addressInput) .Configure(ConfigureEchoAddress); using (var host = hostBuilder.Build()) @@ -84,6 +85,53 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } } + [Fact] + public void ThrowsWhenBindingLocalhostToIPv4AddressInUse() + { + ThrowsWhenBindingLocalhostToAddressInUse(AddressFamily.InterNetwork, IPAddress.Loopback); + } + + [ConditionalFact] + [IPv6SupportedCondition] + public void ThrowsWhenBindingLocalhostToIPv6AddressInUse() + { + ThrowsWhenBindingLocalhostToAddressInUse(AddressFamily.InterNetworkV6, IPAddress.IPv6Loopback); + } + + [Fact] + public void ThrowsWhenBindingLocalhostToDynamicPort() + { + var hostBuilder = new WebHostBuilder() + .UseKestrel() + .UseUrls("http://localhost:0") + .Configure(ConfigureEchoAddress); + + using (var host = hostBuilder.Build()) + { + Assert.Throws(() => host.Start()); + } + } + + private void ThrowsWhenBindingLocalhostToAddressInUse(AddressFamily addressFamily, IPAddress address) + { + using (var socket = new Socket(addressFamily, SocketType.Stream, ProtocolType.Tcp)) + { + var port = GetNextPort(); + socket.Bind(new IPEndPoint(address, port)); + + var hostBuilder = new WebHostBuilder() + .UseKestrel() + .UseUrls($"http://localhost:{port}") + .Configure(ConfigureEchoAddress); + + using (var host = hostBuilder.Build()) + { + var exception = Assert.Throws(() => host.Start()); + Assert.Contains(exception.InnerExceptions, ex => ex is UvException); + } + } + } + public static TheoryData> AddressRegistrationDataIPv4 { get @@ -91,26 +139,31 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests var dataset = new TheoryData>(); // Default host and port - dataset.Add(null, _ => new[] { "http://localhost:5000/" }); - dataset.Add(string.Empty, _ => new[] { "http://localhost:5000/" }); + dataset.Add(null, _ => new[] { "http://127.0.0.1:5000/" }); + dataset.Add(string.Empty, _ => new[] { "http://127.0.0.1:5000/" }); - // Static port + // Static ports var port1 = GetNextPort(); var port2 = GetNextPort(); - // Ensure multiple addresses can be separated by semicolon - dataset.Add($"http://localhost:{port1};http://localhost:{port2}", - _ => new[] { $"http://localhost:{port1}/", $"http://localhost:{port2}/" }); + // Loopback + dataset.Add($"http://127.0.0.1:{port1}", _ => new[] { $"http://127.0.0.1:{port1}/" }); - // Ensure "localhost" and "127.0.0.1" are equivalent + // Localhost dataset.Add($"http://localhost:{port1}", _ => new[] { $"http://localhost:{port1}/", $"http://127.0.0.1:{port1}/" }); - dataset.Add($"http://127.0.0.1:{port1}", _ => new[] { $"http://localhost:{port1}/", $"http://127.0.0.1:{port1}/" }); + + // Any + dataset.Add($"http://*:{port1}/", _ => new[] { $"http://127.0.0.1:{port1}/" }); + dataset.Add($"http://+:{port1}/", _ => new[] { $"http://127.0.0.1:{port1}/" }); + + // Multiple addresses + dataset.Add($"http://127.0.0.1:{port1};http://127.0.0.1:{port2}", _ => new[] { $"http://127.0.0.1:{port1}/", $"http://127.0.0.1:{port2}/" }); // Path after port - dataset.Add($"http://localhost:{port1}/base/path", _ => new[] { $"http://localhost:{port1}/base/path" }); + dataset.Add($"http://127.0.0.1:{port1}/base/path", _ => new[] { $"http://127.0.0.1:{port1}/base/path" }); - // Dynamic port - dataset.Add("http://localhost:0/", GetTestUrls); + // Dynamic port and non-loopback addresses + dataset.Add("http://127.0.0.1:0/", GetTestUrls); dataset.Add($"http://{Dns.GetHostName()}:0/", GetTestUrls); var ipv4Addresses = Dns.GetHostAddressesAsync(Dns.GetHostName()).Result @@ -131,8 +184,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests var dataset = new TheoryData>(); // Default port for HTTP (80) - dataset.Add("http://*", _ => new[] { "http://localhost/" }); - dataset.Add("http://localhost", _ => new[] { "http://localhost/" }); + dataset.Add("http://127.0.0.1", _ => new[] { "http://127.0.0.1/" }); + dataset.Add("http://localhost", _ => new[] { "http://127.0.0.1/" }); + dataset.Add("http://*", _ => new[] { "http://127.0.0.1/" }); return dataset; } @@ -144,17 +198,32 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { var dataset = new TheoryData>(); - // Static port - var port = GetNextPort(); - dataset.Add($"http://*:{port}/", _ => new[] { $"http://localhost:{port}/", $"http://127.0.0.1:{port}/", $"http://[::1]:{port}/" }); - dataset.Add($"http://localhost:{port}/", _ => new[] { $"http://localhost:{port}/", $"http://127.0.0.1:{port}/", - /* // https://github.com/aspnet/KestrelHttpServer/issues/231 - $"http://[::1]:{port}/" - */ }); - dataset.Add($"http://[::1]:{port}/", _ => new[] { $"http://[::1]:{port}/", }); - dataset.Add($"http://127.0.0.1:{port}/;http://[::1]:{port}/", _ => new[] { $"http://127.0.0.1:{port}/", $"http://[::1]:{port}/" }); + // Default host and port + dataset.Add(null, _ => new[] { "http://127.0.0.1:5000/", "http://[::1]:5000/" }); + dataset.Add(string.Empty, _ => new[] { "http://127.0.0.1:5000/", "http://[::1]:5000/" }); - // Dynamic port + // Static ports + var port1 = GetNextPort(); + var port2 = GetNextPort(); + + // Loopback + dataset.Add($"http://[::1]:{port1}/", _ => new[] { $"http://[::1]:{port1}/" }); + + // Localhost + dataset.Add($"http://localhost:{port1}", _ => new[] { $"http://localhost:{port1}/", $"http://127.0.0.1:{port1}/", $"http://[::1]:{port1}/" }); + + // Any + dataset.Add($"http://*:{port1}/", _ => new[] { $"http://127.0.0.1:{port1}/", $"http://[::1]:{port1}/" }); + dataset.Add($"http://+:{port1}/", _ => new[] { $"http://127.0.0.1:{port1}/", $"http://[::1]:{port1}/" }); + + // Multiple addresses + dataset.Add($"http://127.0.0.1:{port1}/;http://[::1]:{port1}/", _ => new[] { $"http://127.0.0.1:{port1}/", $"http://[::1]:{port1}/" }); + dataset.Add($"http://[::1]:{port1};http://[::1]:{port2}", _ => new[] { $"http://[::1]:{port1}/", $"http://[::1]:{port2}/" }); + + // Path after port + dataset.Add($"http://[::1]:{port1}/base/path", _ => new[] { $"http://[::1]:{port1}/base/path" }); + + // Dynamic port and non-loopback addresses var ipv6Addresses = Dns.GetHostAddressesAsync(Dns.GetHostName()).Result .Where(ip => ip.AddressFamily == AddressFamily.InterNetworkV6) .Where(ip => ip.ScopeId == 0); @@ -167,6 +236,21 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } } + public static TheoryData> AddressRegistrationDataIPv6Port80 + { + get + { + var dataset = new TheoryData>(); + + // Default port for HTTP (80) + dataset.Add("http://[::1]", _ => new[] { "http://[::1]/" }); + dataset.Add("http://localhost", _ => new[] { "http://127.0.0.1/", "http://[::1]/" }); + dataset.Add("http://*", _ => new[] { "http://[::1]/" }); + + return dataset; + } + } + public static TheoryData> AddressRegistrationDataIPv6ScopeId { get diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/IPv6SupportedConditionAttribute.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/IPv6SupportedConditionAttribute.cs index cafe02d229..8889c3b2d5 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/IPv6SupportedConditionAttribute.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/IPv6SupportedConditionAttribute.cs @@ -35,7 +35,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { using (var socket = new Socket(AddressFamily.InterNetworkV6, SocketType.Stream, ProtocolType.Tcp)) { - socket.Bind(new IPEndPoint(IPAddress.IPv6Loopback, 8787)); + socket.Bind(new IPEndPoint(IPAddress.IPv6Any, 0)); return true; } } diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/PathBaseTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/PathBaseTests.cs index 6520d73eb5..0e6045f101 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/PathBaseTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/PathBaseTests.cs @@ -1,13 +1,11 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System.Collections.Generic; using System.Net.Http; using System.Threading.Tasks; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; -using Microsoft.Extensions.Configuration; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using Xunit; @@ -68,14 +66,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests private async Task TestPathBase(string registerPathBase, string requestPath, string expectedPathBase, string expectedPath) { - var config = new ConfigurationBuilder().AddInMemoryCollection( - new Dictionary { - { "server.urls", $"http://localhost:0{registerPathBase}" } - }).Build(); - var builder = new WebHostBuilder() - .UseConfiguration(config) .UseKestrel() + .UseUrls($"http://127.0.0.1:0{registerPathBase}") .Configure(app => { app.Run(async context => diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs index 3a032767ac..3ec8eead7d 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs @@ -24,7 +24,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { var builder = new WebHostBuilder() .UseKestrel() - .UseUrls($"http://localhost:0/") + .UseUrls("http://127.0.0.1:0/") .Configure(app => { app.Run(async context => @@ -73,7 +73,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { var builder = new WebHostBuilder() .UseKestrel() - .UseUrls($"http://localhost:0/") + .UseUrls("http://127.0.0.1:0/") .Configure(app => { app.Run(async context => @@ -117,12 +117,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } } - [Theory] - [InlineData("127.0.0.1", "127.0.0.1")] - [InlineData("localhost", "127.0.0.1")] - public Task RemoteIPv4Address(string requestAddress, string expectAddress) + [Fact] + public Task RemoteIPv4Address() { - return TestRemoteIPAddress("localhost", requestAddress, expectAddress); + return TestRemoteIPAddress("127.0.0.1", "127.0.0.1", "127.0.0.1"); } [ConditionalFact] @@ -137,7 +135,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { var builder = new WebHostBuilder() .UseKestrel() - .UseUrls($"http://localhost:0") + .UseUrls($"http://127.0.0.1:0") .Configure(app => { app.Run(async context => @@ -165,7 +163,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { var builder = new WebHostBuilder() .UseKestrel() - .UseUrls($"http://localhost:0/\u0041\u030A") + .UseUrls($"http://127.0.0.1:0/\u0041\u030A") .Configure(app => { app.Run(async context => diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs index 2d3c70aff2..f4bf6c323f 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs @@ -2,7 +2,6 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.Collections.Generic; using System.Linq; using System.Net; using System.Net.Http; @@ -10,7 +9,6 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; -using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Primitives; using Xunit; @@ -21,16 +19,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [Fact] public async Task LargeDownload() { - var config = new ConfigurationBuilder() - .AddInMemoryCollection(new Dictionary - { - { "server.urls", $"http://localhost:0/" } - }) - .Build(); - var hostBuilder = new WebHostBuilder() - .UseConfiguration(config) .UseKestrel() + .UseUrls("http://127.0.0.1:0/") .Configure(app => { app.Run(async context => @@ -80,16 +71,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [Theory, MemberData(nameof(NullHeaderData))] public async Task IgnoreNullHeaderValues(string headerName, StringValues headerValue, string expectedValue) { - var config = new ConfigurationBuilder() - .AddInMemoryCollection(new Dictionary - { - { "server.urls", $"http://localhost:0/" } - }) - .Build(); - var hostBuilder = new WebHostBuilder() - .UseConfiguration(config) .UseKestrel() + .UseUrls("http://127.0.0.1:0/") .Configure(app => { app.Run(async context => @@ -127,19 +111,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [Fact] public async Task OnCompleteCalledEvenWhenOnStartingNotCalled() { - var config = new ConfigurationBuilder() - .AddInMemoryCollection(new Dictionary - { - { "server.urls", $"http://localhost:0/" } - }) - .Build(); - var onStartingCalled = false; var onCompletedCalled = false; var hostBuilder = new WebHostBuilder() - .UseConfiguration(config) .UseKestrel() + .UseUrls("http://127.0.0.1:0/") .Configure(app => { app.Run(context => diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ThreadCountTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ThreadCountTests.cs index 2c10fd96a2..b185406de6 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ThreadCountTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ThreadCountTests.cs @@ -7,28 +7,22 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; -using Microsoft.Extensions.Configuration; using Xunit; namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { public class ThreadCountTests { - public async Task ZeroToTenThreads(int threadCount) + [Theory] + [MemberData(nameof(OneToTen))] + public async Task OneToTenThreads(int threadCount) { - var config = new ConfigurationBuilder() - .AddInMemoryCollection(new Dictionary - { - { "server.urls", $"http://localhost:0/" } - }) - .Build(); - var hostBuilder = new WebHostBuilder() - .UseConfiguration(config) .UseKestrel(options => { options.ThreadCount = threadCount; }) + .UseUrls("http://127.0.0.1:0/") .Configure(app => { app.Run(context => diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionTests.cs index 97dde60c89..f5313a6f10 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionTests.cs @@ -27,7 +27,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests FrameFactory = connectionContext => new Frame( new DummyApplication(httpContext => TaskUtilities.CompletedTask), connectionContext), Memory = memory, - ServerAddress = ServerAddress.FromUrl($"http://localhost:0"), + ServerAddress = ServerAddress.FromUrl("http://127.0.0.1:0"), Thread = engine.Threads[0] }; var socket = new MockSocket(mockLibuv, Thread.CurrentThread.ManagedThreadId, trace); diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs index a7c88d914e..f6894e7dfb 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs @@ -88,7 +88,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests testContext.App = App; var engine = new KestrelEngine(testContext); engine.Start(1); - var address = ServerAddress.FromUrl($"http://localhost:0/"); + var address = ServerAddress.FromUrl("http://127.0.0.1:0/"); var started = engine.CreateServer(address); started.Dispose(); engine.Dispose(); @@ -101,7 +101,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests testContext.App = App; var engine = new KestrelEngine(testContext); engine.Start(1); - var address = ServerAddress.FromUrl($"http://localhost:0/"); + var address = ServerAddress.FromUrl("http://127.0.0.1:0/"); var started = engine.CreateServer(address); var socket = TestConnection.CreateConnectedLoopbackSocket(address.Port); diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/HttpsConnectionFilterTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/HttpsConnectionFilterTests.cs index 50b89a0416..61998ef317 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/HttpsConnectionFilterTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/HttpsConnectionFilterTests.cs @@ -75,7 +75,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests new NoOpConnectionFilter()) ); - using (var server = new TestServer(App, serviceContext, "https://localhost:0/")) + using (var server = new TestServer(App, serviceContext, "https://127.0.0.1:0/")) { using (var client = new HttpClient(handler)) { @@ -122,7 +122,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests new NoOpConnectionFilter()) ); - using (var server = new TestServer(App, serviceContext, "https://localhost:0/")) + using (var server = new TestServer(App, serviceContext, "https://127.0.0.1:0/")) { using (var client = new HttpClient(handler)) { @@ -172,7 +172,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests return context.Response.WriteAsync("hello world"); }; - using (var server = new TestServer(app, serviceContext, "https://localhost:0/")) + using (var server = new TestServer(app, serviceContext, "https://127.0.0.1:0/")) { using (var client = new HttpClient(handler)) { @@ -222,7 +222,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests return context.Response.WriteAsync("hello world"); }; - using (var server = new TestServer(app, serviceContext, "https://localhost:0/")) + using (var server = new TestServer(app, serviceContext, "https://127.0.0.1:0/")) { // SslStream is used to ensure the certificate is actually passed to the server // HttpClient might not send the certificate because it is invalid or it doesn't match any @@ -281,7 +281,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests RequestDelegate app = context => context.Response.WriteAsync(context.Request.Scheme); - using (var server = new TestServer(app, serviceContext, "https://localhost:0/")) + using (var server = new TestServer(app, serviceContext, "https://127.0.0.1:0/")) { using (var client = new HttpClient(handler)) { @@ -327,7 +327,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests return context.Response.WriteAsync("hello world"); }; - using (var server = new TestServer(app, serviceContext, "https://localhost:0/")) + using (var server = new TestServer(app, serviceContext, "https://127.0.0.1:0/")) { // SslStream is used to ensure the certificate is actually passed to the server // HttpClient might not send the certificate because it is invalid or it doesn't match any @@ -384,7 +384,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests return context.Response.WriteAsync("hello world"); }; - using (var server = new TestServer(app, serviceContext, "https://localhost:0/")) + using (var server = new TestServer(app, serviceContext, "https://127.0.0.1:0/")) { // SslStream is used to ensure the certificate is actually passed to the server // HttpClient might not send the certificate because it is invalid or it doesn't match any diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/MultipleLoopTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/MultipleLoopTests.cs index ead65ada56..1752f4f40f 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/MultipleLoopTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/MultipleLoopTests.cs @@ -157,7 +157,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var serverListenTcp = new UvTcpHandle(_logger); serverListenTcp.Init(loop, (a, b) => { }); - var address = ServerAddress.FromUrl($"http://localhost:0/"); + var address = ServerAddress.FromUrl($"http://127.0.0.1:0/"); serverListenTcp.Bind(address); var port = serverListenTcp.GetSockIPEndPoint().Port; serverListenTcp.Listen(128, (_1, status, error, _2) => diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/NetworkingTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/NetworkingTests.cs index d1baa5c785..e8d3f66fcd 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/NetworkingTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/NetworkingTests.cs @@ -61,7 +61,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests loop.Init(_uv); var tcp = new UvTcpHandle(_logger); tcp.Init(loop, (a, b) => { }); - var address = ServerAddress.FromUrl("http://localhost:0/"); + var address = ServerAddress.FromUrl("http://127.0.0.1:0/"); tcp.Bind(address); tcp.Dispose(); loop.Run(); @@ -76,7 +76,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests loop.Init(_uv); var tcp = new UvTcpHandle(_logger); tcp.Init(loop, (a, b) => { }); - var address = ServerAddress.FromUrl($"http://localhost:0/"); + var address = ServerAddress.FromUrl($"http://127.0.0.1:0/"); tcp.Bind(address); var port = tcp.GetSockIPEndPoint().Port; tcp.Listen(10, (stream, status, error, state) => @@ -105,7 +105,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests loop.Init(_uv); var tcp = new UvTcpHandle(_logger); tcp.Init(loop, (a, b) => { }); - var address = ServerAddress.FromUrl($"http://localhost:0/"); + var address = ServerAddress.FromUrl($"http://127.0.0.1:0/"); tcp.Bind(address); var port = tcp.GetSockIPEndPoint().Port; tcp.Listen(10, (_, status, error, state) => @@ -155,7 +155,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests loop.Init(_uv); var tcp = new UvTcpHandle(_logger); tcp.Init(loop, (a, b) => { }); - var address = ServerAddress.FromUrl($"http://localhost:0/"); + var address = ServerAddress.FromUrl($"http://127.0.0.1:0/"); tcp.Bind(address); var port = tcp.GetSockIPEndPoint().Port; tcp.Listen(10, (_, status, error, state) => diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/ServerAddressTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/ServerAddressTests.cs index 8aa99d1917..50c96cc9c4 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/ServerAddressTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/ServerAddressTests.cs @@ -60,5 +60,15 @@ namespace Microsoft.AspNetCore.Server.KestrelTests Assert.True(serverAddres.PathBase.IsNormalized(NormalizationForm.FormC)); Assert.Equal("/p\u00C5thbase", serverAddres.PathBase); } + + [Fact] + public void WithHostReturnsNewInstanceWithDifferentHost() + { + var serverAddress = ServerAddress.FromUrl("http://localhost:8080"); + var newAddress = serverAddress.WithHost("otherhost"); + Assert.NotSame(serverAddress, newAddress); + Assert.Equal("otherhost", newAddress.Host); + Assert.Equal("localhost", serverAddress.Host); + } } } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestServer.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/TestServer.cs index c041f5f437..9719999265 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/TestServer.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/TestServer.cs @@ -2,7 +2,6 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.Threading; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Server.Kestrel; using Microsoft.AspNetCore.Server.Kestrel.Http; @@ -16,7 +15,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { private KestrelEngine _engine; private IDisposable _server; - ServerAddress _address; + private ServerAddress _address; public TestServer(RequestDelegate app) : this(app, new TestServiceContext()) @@ -24,7 +23,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } public TestServer(RequestDelegate app, ServiceContext context) - : this(app, context, "http://localhost:0/") + : this(app, context, "http://127.0.0.1:0/") { } From 71ecf5612f1ad73317d6a4a7758636dc567b3f3d Mon Sep 17 00:00:00 2001 From: Pavel Krymets Date: Tue, 24 May 2016 10:46:27 -0700 Subject: [PATCH 0745/1662] Refactor and add ssl tests --- .../HttpsConnectionFilterTests.cs | 405 ++++++++++-------- 1 file changed, 219 insertions(+), 186 deletions(-) diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/HttpsConnectionFilterTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/HttpsConnectionFilterTests.cs index 61998ef317..f0046dee4e 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/HttpsConnectionFilterTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/HttpsConnectionFilterTests.cs @@ -21,8 +21,15 @@ using Xunit; namespace Microsoft.AspNetCore.Server.KestrelTests { - public class HttpsConnectionFilterTests + public class HttpsConnectionFilterTests: IDisposable { + private static string _serverAddress = "https://127.0.0.1:0/"; + private static RemoteCertificateValidationCallback _alwaysValidCallback = + (sender, cert, chain, sslPolicyErrors) => true; + private static X509Certificate2 _x509Certificate2 = new X509Certificate2(@"TestResources/testCert.pfx", "testPassword"); + + private HttpMessageHandler _handler; + #if NET451 static HttpsConnectionFilterTests() { @@ -33,23 +40,25 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } #endif - private async Task App(HttpContext httpContext) + public HttpsConnectionFilterTests() { - var request = httpContext.Request; - var response = httpContext.Response; - response.Headers.Clear(); - while (true) - { - var buffer = new byte[8192]; - var count = await request.Body.ReadAsync(buffer, 0, buffer.Length); - if (count == 0) - { - break; - } - await response.Body.WriteAsync(buffer, 0, count); - } +#if NET451 + _handler = new HttpClientHandler(); + ServicePointManager.ServerCertificateValidationCallback += _alwaysValidCallback; +#else + var handler = new WinHttpHandler(); + handler.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true; + _handler = handler; +#endif } + public void Dispose() + { +#if NET451 + ServicePointManager.ServerCertificateValidationCallback -= _alwaysValidCallback; +#endif + } + // https://github.com/aspnet/KestrelHttpServer/issues/240 // This test currently fails on mono because of an issue with SslStream. [ConditionalFact] @@ -57,27 +66,15 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [OSSkipCondition(OperatingSystems.MacOSX, SkipReason = "WinHttpHandler not available on non-Windows.")] public async Task CanReadAndWriteWithHttpsConnectionFilter() { - RemoteCertificateValidationCallback validationCallback = - (sender, cert, chain, sslPolicyErrors) => true; - - try - { -#if NET451 - var handler = new HttpClientHandler(); - ServicePointManager.ServerCertificateValidationCallback += validationCallback; -#else - var handler = new WinHttpHandler(); - handler.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true; -#endif var serviceContext = new TestServiceContext(new HttpsConnectionFilter( new HttpsConnectionFilterOptions - { ServerCertificate = new X509Certificate2(@"TestResources/testCert.pfx", "testPassword") }, + { ServerCertificate = _x509Certificate2 }, new NoOpConnectionFilter()) ); - using (var server = new TestServer(App, serviceContext, "https://127.0.0.1:0/")) + using (var server = new TestServer(App, serviceContext, _serverAddress)) { - using (var client = new HttpClient(handler)) + using (var client = new HttpClient(_handler)) { var result = await client.PostAsync($"https://localhost:{server.Port}/", new FormUrlEncodedContent(new[] { new KeyValuePair("content", "Hello World?") @@ -87,80 +84,40 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } } } - finally - { -#if NET451 - ServicePointManager.ServerCertificateValidationCallback -= validationCallback; -#endif - } - } [ConditionalFact] [OSSkipCondition(OperatingSystems.Linux, SkipReason = "WinHttpHandler not available on non-Windows.")] [OSSkipCondition(OperatingSystems.MacOSX, SkipReason = "WinHttpHandler not available on non-Windows.")] public async Task RequireCertificateFailsWhenNoCertificate() { - RemoteCertificateValidationCallback validationCallback = - (sender, cert, chain, sslPolicyErrors) => true; - - try - { -#if NET451 - var handler = new HttpClientHandler(); - ServicePointManager.ServerCertificateValidationCallback += validationCallback; -#else - var handler = new WinHttpHandler(); - handler.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true; -#endif - var serviceContext = new TestServiceContext(new HttpsConnectionFilter( new HttpsConnectionFilterOptions { - ServerCertificate = new X509Certificate2(@"TestResources/testCert.pfx", "testPassword"), + ServerCertificate = _x509Certificate2, ClientCertificateMode = ClientCertificateMode.RequireCertificate }, new NoOpConnectionFilter()) ); - using (var server = new TestServer(App, serviceContext, "https://127.0.0.1:0/")) + using (var server = new TestServer(App, serviceContext, _serverAddress)) { - using (var client = new HttpClient(handler)) + using (var client = new HttpClient(_handler)) { await Assert.ThrowsAnyAsync( () => client.GetAsync($"https://localhost:{server.Port}/")); } } } - finally - { -#if NET451 - ServicePointManager.ServerCertificateValidationCallback -= validationCallback; -#endif - } - } [ConditionalFact] [OSSkipCondition(OperatingSystems.Linux, SkipReason = "WinHttpHandler not available on non-Windows.")] [OSSkipCondition(OperatingSystems.MacOSX, SkipReason = "WinHttpHandler not available on non-Windows.")] public async Task AllowCertificateContinuesWhenNoCertificate() { - RemoteCertificateValidationCallback validationCallback = - (sender, cert, chain, sslPolicyErrors) => true; - - try - { -#if NET451 - var handler = new HttpClientHandler(); - ServicePointManager.ServerCertificateValidationCallback += validationCallback; -#else - var handler = new WinHttpHandler(); - handler.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true; -#endif - var serviceContext = new TestServiceContext(new HttpsConnectionFilter( new HttpsConnectionFilterOptions { - ServerCertificate = new X509Certificate2(@"TestResources/testCert.pfx", "testPassword"), + ServerCertificate = _x509Certificate2, ClientCertificateMode = ClientCertificateMode.AllowCertificate }, new NoOpConnectionFilter()) @@ -172,9 +129,9 @@ namespace Microsoft.AspNetCore.Server.KestrelTests return context.Response.WriteAsync("hello world"); }; - using (var server = new TestServer(app, serviceContext, "https://127.0.0.1:0/")) + using (var server = new TestServer(app, serviceContext, _serverAddress)) { - using (var client = new HttpClient(handler)) + using (var client = new HttpClient(_handler)) { var result = await client.GetAsync($"https://localhost:{server.Port}/"); @@ -182,31 +139,50 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } } } - finally + + [Fact] + public void ThrowsWhenNoServerCertificateIsProvided() { -#if NET451 - ServicePointManager.ServerCertificateValidationCallback -= validationCallback; -#endif + Assert.Throws(() => new HttpsConnectionFilter( + new HttpsConnectionFilterOptions(), + new NoOpConnectionFilter()) + ); + } + + [Fact] + public async Task UsesProvidedServerCertificate() + { + var serviceContext = new TestServiceContext(new HttpsConnectionFilter( + new HttpsConnectionFilterOptions + { + ServerCertificate = _x509Certificate2 + }, + new NoOpConnectionFilter()) + ); + + RequestDelegate app = context => Task.FromResult(0); + using (var server = new TestServer(app, serviceContext, _serverAddress)) + { + using (var client = new TcpClient()) + { + // SslStream is used to ensure the certificate is actually passed to the server + // HttpClient might not send the certificate because it is invalid or it doesn't match any + // of the certificate authorities sent by the server in the SSL handshake. + var stream = await OpenSslStream(client, server); + await stream.AuthenticateAsClientAsync("localhost", new X509CertificateCollection(), SslProtocols.Tls12 | SslProtocols.Tls11, false); + Assert.True(stream.RemoteCertificate.Equals(_x509Certificate2)); + } } } - [ConditionalFact] - [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "This test currently fails on Mono because of an issue with SslStream (https://github.com/aspnet/KestrelHttpServer/issues/240).")] + + [Fact] public async Task CertificatePassedToHttpContext() { - RemoteCertificateValidationCallback validationCallback = - (sender, cert, chain, sslPolicyErrors) => true; - - try - { -#if NET451 - ServicePointManager.ServerCertificateValidationCallback += validationCallback; -#endif - var serviceContext = new TestServiceContext(new HttpsConnectionFilter( new HttpsConnectionFilterOptions { - ServerCertificate = new X509Certificate2(@"TestResources/testCert.pfx", "testPassword"), + ServerCertificate = _x509Certificate2, ClientCertificateMode = ClientCertificateMode.RequireCertificate, ClientCertificateValidation = (certificate, chain, sslPolicyErrors) => true }, @@ -222,68 +198,39 @@ namespace Microsoft.AspNetCore.Server.KestrelTests return context.Response.WriteAsync("hello world"); }; - using (var server = new TestServer(app, serviceContext, "https://127.0.0.1:0/")) + using (var server = new TestServer(app, serviceContext, _serverAddress)) + { + using (var client = new TcpClient()) { // SslStream is used to ensure the certificate is actually passed to the server // HttpClient might not send the certificate because it is invalid or it doesn't match any // of the certificate authorities sent by the server in the SSL handshake. - using (var client = new TcpClient()) - { - await client.ConnectAsync("127.0.0.1", server.Port); - - var stream = new SslStream(client.GetStream(), false, (sender, certificate, chain, errors) => true, - (sender, host, certificates, certificate, issuers) => new X509Certificate2(@"TestResources/testCert.pfx", "testPassword")); + var stream = await OpenSslStream(client, server); await stream.AuthenticateAsClientAsync("localhost", new X509CertificateCollection(), SslProtocols.Tls12 | SslProtocols.Tls11, false); - - var request = Encoding.UTF8.GetBytes("GET / HTTP/1.0\r\n\r\n"); - await stream.WriteAsync(request, 0, request.Length); - - var reader = new StreamReader(stream); - var line = await reader.ReadLineAsync(); - Assert.Equal("HTTP/1.1 200 OK", line); + await AssertConnectionResult(stream, true); } } } - finally - { -#if NET451 - ServicePointManager.ServerCertificateValidationCallback -= validationCallback; -#endif - } - } [ConditionalFact] [OSSkipCondition(OperatingSystems.Linux, SkipReason = "WinHttpHandler not available on non-Windows.")] [OSSkipCondition(OperatingSystems.MacOSX, SkipReason = "WinHttpHandler not available on non-Windows.")] public async Task HttpsSchemePassedToRequestFeature() { - RemoteCertificateValidationCallback validationCallback = - (sender, cert, chain, sslPolicyErrors) => true; - - try - { -#if NET451 - var handler = new HttpClientHandler(); - ServicePointManager.ServerCertificateValidationCallback += validationCallback; -#else - var handler = new WinHttpHandler(); - handler.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true; -#endif - var serviceContext = new TestServiceContext( new HttpsConnectionFilter( new HttpsConnectionFilterOptions { - ServerCertificate = new X509Certificate2(@"TestResources/testCert.pfx", "testPassword") + ServerCertificate = _x509Certificate2 }, new NoOpConnectionFilter()) ); RequestDelegate app = context => context.Response.WriteAsync(context.Request.Scheme); - using (var server = new TestServer(app, serviceContext, "https://127.0.0.1:0/")) + using (var server = new TestServer(app, serviceContext, _serverAddress)) { - using (var client = new HttpClient(handler)) + using (var client = new HttpClient(_handler)) { var result = await client.GetAsync($"https://localhost:{server.Port}/"); @@ -291,31 +238,14 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } } } - finally - { -#if NET451 - ServicePointManager.ServerCertificateValidationCallback -= validationCallback; -#endif - } - } - [Fact] public async Task DoesNotSupportTls10() { - RemoteCertificateValidationCallback validationCallback = - (sender, cert, chain, sslPolicyErrors) => true; - - try - { -#if NET451 - ServicePointManager.ServerCertificateValidationCallback += validationCallback; -#endif - var serviceContext = new TestServiceContext(new HttpsConnectionFilter( new HttpsConnectionFilterOptions { - ServerCertificate = new X509Certificate2(@"TestResources/testCert.pfx", "testPassword"), + ServerCertificate = _x509Certificate2, ClientCertificateMode = ClientCertificateMode.RequireCertificate, ClientCertificateValidation = (certificate, chain, sslPolicyErrors) => true }, @@ -327,47 +257,118 @@ namespace Microsoft.AspNetCore.Server.KestrelTests return context.Response.WriteAsync("hello world"); }; - using (var server = new TestServer(app, serviceContext, "https://127.0.0.1:0/")) + using (var server = new TestServer(app, serviceContext, _serverAddress)) { // SslStream is used to ensure the certificate is actually passed to the server // HttpClient might not send the certificate because it is invalid or it doesn't match any // of the certificate authorities sent by the server in the SSL handshake. using (var client = new TcpClient()) { - await client.ConnectAsync("127.0.0.1", server.Port); - - var stream = new SslStream(client.GetStream(), false, (sender, certificate, chain, errors) => true, - (sender, host, certificates, certificate, issuers) => new X509Certificate2(@"TestResources/testCert.pfx", "testPassword")); - await Assert.ThrowsAsync(typeof(IOException), async () => + var stream = await OpenSslStream(client, server); + var ex = await Assert.ThrowsAsync(typeof(IOException), async () => await stream.AuthenticateAsClientAsync("localhost", new X509CertificateCollection(), SslProtocols.Tls, false)); } } } - finally + + [Theory] + [InlineData(ClientCertificateMode.AllowCertificate)] + [InlineData(ClientCertificateMode.RequireCertificate)] + public async Task ClientCertificateValidationGetsCalledWithNotNullParameters(ClientCertificateMode mode) { -#if NET451 - ServicePointManager.ServerCertificateValidationCallback -= validationCallback; -#endif + var clientCertificateValidationCalled = false; + var serviceContext = new TestServiceContext(new HttpsConnectionFilter( + new HttpsConnectionFilterOptions + { + ServerCertificate = _x509Certificate2, + ClientCertificateMode = mode, + ClientCertificateValidation = (certificate, chain, sslPolicyErrors) => + { + clientCertificateValidationCalled = true; + Assert.NotNull(certificate); + Assert.NotNull(chain); + return true; + } + }, + new NoOpConnectionFilter()) + ); + + RequestDelegate app = context => Task.FromResult(0); + + using (var server = new TestServer(app, serviceContext, _serverAddress)) + { + using (var client = new TcpClient()) + { + var stream = await OpenSslStream(client, server); + await stream.AuthenticateAsClientAsync("localhost", new X509CertificateCollection(), SslProtocols.Tls12 | SslProtocols.Tls11, false); + await AssertConnectionResult(stream, true); + Assert.True(clientCertificateValidationCalled); + } } } - [ConditionalFact] - [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "This test currently fails on Mono because of an issue with SslStream (https://github.com/aspnet/KestrelHttpServer/issues/240).")] - public async Task CertificatePassedToHttpContextIsNotDisposed() + [Theory] + [InlineData(ClientCertificateMode.AllowCertificate)] + [InlineData(ClientCertificateMode.RequireCertificate)] + public async Task ValidationFailureRejectsConnection(ClientCertificateMode mode) { - RemoteCertificateValidationCallback validationCallback = - (sender, cert, chain, sslPolicyErrors) => true; + var serviceContext = new TestServiceContext(new HttpsConnectionFilter( + new HttpsConnectionFilterOptions + { + ServerCertificate = _x509Certificate2, + ClientCertificateMode = mode, + ClientCertificateValidation = (certificate, chain, sslPolicyErrors) => false + }, + new NoOpConnectionFilter()) + ); - try + RequestDelegate app = context => Task.FromResult(0); + + using (var server = new TestServer(app, serviceContext, _serverAddress)) { -#if NET451 - ServicePointManager.ServerCertificateValidationCallback += validationCallback; -#endif + using (var client = new TcpClient()) + { + var stream = await OpenSslStream(client, server); + await stream.AuthenticateAsClientAsync("localhost", new X509CertificateCollection(), SslProtocols.Tls12 | SslProtocols.Tls11, false); + await AssertConnectionResult(stream, false); + } + } + } + [Theory] + [InlineData(ClientCertificateMode.AllowCertificate)] + [InlineData(ClientCertificateMode.RequireCertificate)] + public async Task RejectsConnectionOnSslPolicyErrorsWhenNoValidation(ClientCertificateMode mode) + { var serviceContext = new TestServiceContext(new HttpsConnectionFilter( new HttpsConnectionFilterOptions { - ServerCertificate = new X509Certificate2(@"TestResources/testCert.pfx", "testPassword"), + ServerCertificate = _x509Certificate2, + ClientCertificateMode = mode, + }, + new NoOpConnectionFilter()) + ); + + RequestDelegate app = context => Task.FromResult(0); + + using (var server = new TestServer(app, serviceContext, _serverAddress)) + { + using (var client = new TcpClient()) + { + var stream = await OpenSslStream(client, server); + await stream.AuthenticateAsClientAsync("localhost", new X509CertificateCollection(), SslProtocols.Tls12 | SslProtocols.Tls11, false); + await AssertConnectionResult(stream, false); + } + } + } + + [Fact] + public async Task CertificatePassedToHttpContextIsNotDisposed() + { + var serviceContext = new TestServiceContext(new HttpsConnectionFilter( + new HttpsConnectionFilterOptions + { + ServerCertificate = _x509Certificate2, ClientCertificateMode = ClientCertificateMode.RequireCertificate, ClientCertificateValidation = (certificate, chain, sslPolicyErrors) => true }, @@ -384,34 +385,66 @@ namespace Microsoft.AspNetCore.Server.KestrelTests return context.Response.WriteAsync("hello world"); }; - using (var server = new TestServer(app, serviceContext, "https://127.0.0.1:0/")) + using (var server = new TestServer(app, serviceContext, _serverAddress)) { // SslStream is used to ensure the certificate is actually passed to the server // HttpClient might not send the certificate because it is invalid or it doesn't match any // of the certificate authorities sent by the server in the SSL handshake. using (var client = new TcpClient()) { - await client.ConnectAsync("127.0.0.1", server.Port); - - var stream = new SslStream(client.GetStream(), false, (sender, certificate, chain, errors) => true, - (sender, host, certificates, certificate, issuers) => new X509Certificate2(@"TestResources/testCert.pfx", "testPassword")); - await stream.AuthenticateAsClientAsync("localhost", new X509CertificateCollection(), SslProtocols.Tls12 | SslProtocols.Tls11, false); - - var request = Encoding.UTF8.GetBytes("GET / HTTP/1.0\r\n\r\n"); - await stream.WriteAsync(request, 0, request.Length); - - var reader = new StreamReader(stream); - var line = await reader.ReadLineAsync(); - Assert.Equal("HTTP/1.1 200 OK", line); - } + var stream = await OpenSslStream(client, server); + await stream.AuthenticateAsClientAsync("localhost", new X509CertificateCollection(), SslProtocols.Tls12 | SslProtocols.Tls11, false); + await AssertConnectionResult(stream, true); } } - finally + } + + private static async Task App(HttpContext httpContext) + { + var request = httpContext.Request; + var response = httpContext.Response; + response.Headers.Clear(); + while (true) { -#if NET451 - ServicePointManager.ServerCertificateValidationCallback -= validationCallback; -#endif + var buffer = new byte[8192]; + var count = await request.Body.ReadAsync(buffer, 0, buffer.Length); + if (count == 0) + { + break; + } + await response.Body.WriteAsync(buffer, 0, count); + } + } + + private static async Task OpenSslStream(TcpClient client, TestServer server, X509Certificate2 clientCertificate = null) + { + await client.ConnectAsync("127.0.0.1", server.Port); + var stream = new SslStream(client.GetStream(), false, (sender, certificate, chain, errors) => true, + (sender, host, certificates, certificate, issuers) => clientCertificate ?? _x509Certificate2); + + return stream; + } + + private static async Task AssertConnectionResult(SslStream stream, bool success) + { + var request = Encoding.UTF8.GetBytes("GET / HTTP/1.0\r\n\r\n"); + await stream.WriteAsync(request, 0, request.Length); + var reader = new StreamReader(stream); + string line = null; + if (success) + { + line = await reader.ReadLineAsync(); + Assert.Equal("HTTP/1.1 200 OK", line); + } + else + { + try + { + line = await reader.ReadLineAsync(); + } + catch (IOException) { } + Assert.Null(line); + } } } } -} From 72cc0ffbd530dba319e32e5e0a90ac64d1df41b9 Mon Sep 17 00:00:00 2001 From: Kristian Hellang Date: Sat, 21 May 2016 02:14:31 +0200 Subject: [PATCH 0746/1662] Set Date and Server headers at response start Closes #223 --- .../Http/DateHeaderValueManager.cs | 18 +- .../Http/Frame.cs | 40 ++-- .../Http/FrameResponseHeaders.cs | 3 + .../Infrastructure/Headers.cs | 40 ---- .../BadHttpRequestTests.cs | 7 +- .../ChunkedRequestTests.cs | 53 +++-- .../ChunkedResponseTests.cs | 40 ++-- .../ConnectionFilterTests.cs | 9 +- .../DefaultHeaderTests.cs | 41 ++++ .../EngineTests.cs | 196 ++++++++++-------- .../FrameResponseHeadersTests.cs | 57 +---- .../HttpsConnectionFilterTests.cs | 1 - .../TestConnection.cs | 39 +--- .../TestServer.cs | 17 +- .../TestServiceContext.cs | 9 +- 15 files changed, 274 insertions(+), 296 deletions(-) delete mode 100644 src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/Headers.cs create mode 100644 test/Microsoft.AspNetCore.Server.KestrelTests/DefaultHeaderTests.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/DateHeaderValueManager.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/DateHeaderValueManager.cs index 87a2e60de3..42f3de4d73 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/DateHeaderValueManager.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/DateHeaderValueManager.cs @@ -32,22 +32,24 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http /// Initializes a new instance of the class. /// public DateHeaderValueManager() - : this( - systemClock: new SystemClock(), - timeWithoutRequestsUntilIdle: TimeSpan.FromSeconds(10), - timerInterval: TimeSpan.FromSeconds(1)) + : this(systemClock: new SystemClock()) { } // Internal for testing internal DateHeaderValueManager( ISystemClock systemClock, - TimeSpan timeWithoutRequestsUntilIdle, - TimeSpan timerInterval) + TimeSpan? timeWithoutRequestsUntilIdle = null, + TimeSpan? timerInterval = null) { + if (systemClock == null) + { + throw new ArgumentNullException(nameof(systemClock)); + } + _systemClock = systemClock; - _timeWithoutRequestsUntilIdle = timeWithoutRequestsUntilIdle; - _timerInterval = timerInterval; + _timeWithoutRequestsUntilIdle = timeWithoutRequestsUntilIdle ?? TimeSpan.FromSeconds(10); + _timerInterval = timerInterval ?? TimeSpan.FromSeconds(1); _dateValueTimer = new Timer(TimerLoop, state: null, dueTime: Timeout.Infinite, period: Timeout.Infinite); } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs index 2716a94e52..63ada04463 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs @@ -33,6 +33,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http private static readonly byte[] _bytesHttpVersion11 = Encoding.ASCII.GetBytes("HTTP/1.1 "); private static readonly byte[] _bytesContentLengthZero = Encoding.ASCII.GetBytes("\r\nContent-Length: 0"); private static readonly byte[] _bytesEndHeaders = Encoding.ASCII.GetBytes("\r\n\r\n"); + private static readonly byte[] _bytesServer = Encoding.ASCII.GetBytes("\r\nServer: Kestrel"); private static Vector _vectorCRs = new Vector((byte)'\r'); private static Vector _vectorColons = new Vector((byte)':'); @@ -44,7 +45,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http private readonly object _onCompletedSync = new Object(); private bool _requestRejected; - private Headers _frameHeaders; private Streams _frameStreams; protected List, object>> _onStarting; @@ -210,21 +210,23 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http get { return _requestProcessingStatus == RequestProcessingStatus.ResponseStarted; } } - protected FrameRequestHeaders FrameRequestHeaders => _frameHeaders.RequestHeaders; + protected FrameRequestHeaders FrameRequestHeaders { get; private set; } + + protected FrameResponseHeaders FrameResponseHeaders { get; private set; } public void InitializeHeaders() { - if (_frameHeaders == null) + if (FrameRequestHeaders == null) { - _frameHeaders = new Headers(ServerOptions); - RequestHeaders = _frameHeaders.RequestHeaders; - ResponseHeaders = _frameHeaders.ResponseHeaders; + RequestHeaders = FrameRequestHeaders = new FrameRequestHeaders(); } - _frameHeaders.Initialize(DateHeaderValueManager); + if (FrameResponseHeaders == null) + { + ResponseHeaders = FrameResponseHeaders = new FrameResponseHeaders(); + } } - public void InitializeStreams(MessageBody messageBody) { if (_frameStreams == null) @@ -259,7 +261,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http public void Reset() { - _frameHeaders?.Reset(); + FrameRequestHeaders?.Reset(); + FrameResponseHeaders?.Reset(); _onStarting = null; _onCompleted = null; @@ -598,7 +601,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (_requestProcessingStatus == RequestProcessingStatus.RequestStarted && _requestRejected) { - if (_frameHeaders == null) + if (FrameRequestHeaders == null || FrameResponseHeaders == null) { InitializeHeaders(); } @@ -634,7 +637,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ReasonPhrase = null; - var responseHeaders = _frameHeaders.ResponseHeaders; + var responseHeaders = FrameResponseHeaders; responseHeaders.Reset(); var dateHeaderValues = DateHeaderValueManager.GetDateHeaderValues(); @@ -643,7 +646,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if (ServerOptions.AddServerHeader) { - responseHeaders.SetRawServer(Constants.ServerName, Headers.BytesServer); + responseHeaders.SetRawServer(Constants.ServerName, _bytesServer); } ResponseHeaders = responseHeaders; @@ -698,7 +701,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http byte[] statusBytes, bool appCompleted) { - var responseHeaders = _frameHeaders.ResponseHeaders; + var responseHeaders = FrameResponseHeaders; responseHeaders.SetReadOnly(); var hasConnection = responseHeaders.HasConnection; @@ -759,6 +762,17 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http responseHeaders.SetRawConnection("keep-alive", _bytesConnectionKeepAlive); } + if (ServerOptions.AddServerHeader && !responseHeaders.HasServer) + { + responseHeaders.SetRawServer(Constants.ServerName, _bytesServer); + } + + if (!responseHeaders.HasDate) + { + var dateHeaderValues = DateHeaderValueManager.GetDateHeaderValues(); + responseHeaders.SetRawDate(dateHeaderValues.String, dateHeaderValues.Bytes); + } + end.CopyFrom(_bytesHttpVersion11); end.CopyFrom(statusBytes); responseHeaders.CopyTo(ref end); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameResponseHeaders.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameResponseHeaders.cs index c843e96255..9697ad0e6d 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameResponseHeaders.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameResponseHeaders.cs @@ -19,6 +19,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http public bool HasContentLength => HeaderContentLength.Count != 0; + public bool HasServer => HeaderServer.Count != 0; + + public bool HasDate => HeaderDate.Count != 0; public Enumerator GetEnumerator() { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/Headers.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/Headers.cs deleted file mode 100644 index 1f81dcdea8..0000000000 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/Headers.cs +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System.Text; -using Microsoft.AspNetCore.Server.Kestrel.Http; - -namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure -{ - class Headers - { - public static readonly byte[] BytesServer = Encoding.ASCII.GetBytes("\r\nServer: Kestrel"); - - private readonly KestrelServerOptions _options; - - public Headers(KestrelServerOptions options) - { - _options = options; - } - - public void Initialize(DateHeaderValueManager dateValueManager) - { - var dateHeaderValues = dateValueManager.GetDateHeaderValues(); - ResponseHeaders.SetRawDate(dateHeaderValues.String, dateHeaderValues.Bytes); - - if (_options.AddServerHeader) - { - ResponseHeaders.SetRawServer("Kestrel", BytesServer); - } - } - - public FrameRequestHeaders RequestHeaders { get; } = new FrameRequestHeaders(); - public FrameResponseHeaders ResponseHeaders { get; } = new FrameResponseHeaders(); - - public void Reset() - { - RequestHeaders.Reset(); - ResponseHeaders.Reset(); - } - } -} diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/BadHttpRequestTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/BadHttpRequestTests.cs index adc90857db..a239e7102c 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/BadHttpRequestTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/BadHttpRequestTests.cs @@ -70,7 +70,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { using (var server = new TestServer(context => { return Task.FromResult(0); })) { - using (var connection = new TestConnection(server.Port)) + using (var connection = server.CreateConnection()) { await connection.SendEnd(request); await ReceiveBadRequestResponse(connection); @@ -87,7 +87,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { using (var server = new TestServer(context => { return Task.FromResult(0); })) { - using (var connection = new TestConnection(server.Port)) + using (var connection = server.CreateConnection()) { await connection.Send(request); await ReceiveBadRequestResponse(connection); @@ -103,10 +103,9 @@ namespace Microsoft.AspNetCore.Server.KestrelTests await connection.Receive( "Connection: close", ""); - await connection.ReceiveStartsWith("Date: "); await connection.ReceiveEnd( + $"Date: {connection.Server.Context.DateHeaderValue}", "Content-Length: 0", - "Server: Kestrel", "", ""); } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedRequestTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedRequestTests.cs index 217af83a6b..173912d594 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedRequestTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedRequestTests.cs @@ -14,11 +14,11 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { public class ChunkedRequestTests { - public static TheoryData ConnectionFilterData + public static TheoryData ConnectionFilterData { get { - return new TheoryData + return new TheoryData { { new TestServiceContext() @@ -34,7 +34,6 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { var request = httpContext.Request; var response = httpContext.Response; - response.Headers.Clear(); while (true) { var buffer = new byte[8192]; @@ -55,18 +54,17 @@ namespace Microsoft.AspNetCore.Server.KestrelTests await request.Body.CopyToAsync(data); var bytes = data.ToArray(); - response.Headers.Clear(); response.Headers["Content-Length"] = bytes.Length.ToString(); await response.Body.WriteAsync(bytes, 0, bytes.Length); } [Theory] [MemberData(nameof(ConnectionFilterData))] - public async Task Http10TransferEncoding(ServiceContext testContext) + public async Task Http10TransferEncoding(TestServiceContext testContext) { using (var server = new TestServer(App, testContext)) { - using (var connection = new TestConnection(server.Port)) + using (var connection = server.CreateConnection()) { await connection.SendEnd( "POST / HTTP/1.0", @@ -78,6 +76,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests ""); await connection.ReceiveEnd( "HTTP/1.1 200 OK", + $"Date: {testContext.DateHeaderValue}", "", "Hello World"); } @@ -86,11 +85,11 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [Theory] [MemberData(nameof(ConnectionFilterData))] - public async Task Http10KeepAliveTransferEncoding(ServiceContext testContext) + public async Task Http10KeepAliveTransferEncoding(TestServiceContext testContext) { using (var server = new TestServer(AppChunked, testContext)) { - using (var connection = new TestConnection(server.Port)) + using (var connection = server.CreateConnection()) { await connection.SendEnd( "POST / HTTP/1.0", @@ -107,11 +106,13 @@ namespace Microsoft.AspNetCore.Server.KestrelTests await connection.Receive( "HTTP/1.1 200 OK", "Connection: keep-alive", + $"Date: {testContext.DateHeaderValue}", "Content-Length: 11", "", "Hello World"); await connection.ReceiveEnd( "HTTP/1.1 200 OK", + $"Date: {testContext.DateHeaderValue}", "Content-Length: 7", "", "Goodbye"); @@ -121,7 +122,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [Theory] [MemberData(nameof(ConnectionFilterData))] - public async Task RequestBodyIsConsumedAutomaticallyIfAppDoesntConsumeItFully(ServiceContext testContext) + public async Task RequestBodyIsConsumedAutomaticallyIfAppDoesntConsumeItFully(TestServiceContext testContext) { using (var server = new TestServer(async httpContext => { @@ -130,13 +131,12 @@ namespace Microsoft.AspNetCore.Server.KestrelTests Assert.Equal("POST", request.Method); - response.Headers.Clear(); response.Headers["Content-Length"] = new[] { "11" }; await response.Body.WriteAsync(Encoding.ASCII.GetBytes("Hello World"), 0, 11); }, testContext)) { - using (var connection = new TestConnection(server.Port)) + using (var connection = server.CreateConnection()) { await connection.SendEnd( "POST / HTTP/1.1", @@ -154,12 +154,15 @@ namespace Microsoft.AspNetCore.Server.KestrelTests "Goodbye"); await connection.ReceiveEnd( "HTTP/1.1 200 OK", + $"Date: {testContext.DateHeaderValue}", "Content-Length: 11", "", "Hello WorldHTTP/1.1 200 OK", + $"Date: {testContext.DateHeaderValue}", "Content-Length: 11", "", "Hello WorldHTTP/1.1 200 OK", + $"Date: {testContext.DateHeaderValue}", "Content-Length: 11", "", "Hello World"); @@ -169,7 +172,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [Theory] [MemberData(nameof(ConnectionFilterData))] - public async Task TrailingHeadersAreParsed(ServiceContext testContext) + public async Task TrailingHeadersAreParsed(TestServiceContext testContext) { var requestCount = 10; var requestsReceived = 0; @@ -199,7 +202,6 @@ namespace Microsoft.AspNetCore.Server.KestrelTests requestsReceived++; - response.Headers.Clear(); response.Headers["Content-Length"] = new[] { "11" }; await response.Body.WriteAsync(Encoding.ASCII.GetBytes("Hello World"), 0, 11); @@ -207,6 +209,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { var response = string.Join("\r\n", new string[] { "HTTP/1.1 200 OK", + $"Date: {testContext.DateHeaderValue}", "Content-Length: 11", "", "Hello World"}); @@ -244,7 +247,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var fullRequest = sendSequence.ToArray(); - using (var connection = new TestConnection(server.Port)) + using (var connection = server.CreateConnection()) { await connection.SendEnd(fullRequest); @@ -255,7 +258,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [Theory] [MemberData(nameof(ConnectionFilterData))] - public async Task ExtensionsAreIgnored(ServiceContext testContext) + public async Task ExtensionsAreIgnored(TestServiceContext testContext) { var requestCount = 10; var requestsReceived = 0; @@ -285,7 +288,6 @@ namespace Microsoft.AspNetCore.Server.KestrelTests requestsReceived++; - response.Headers.Clear(); response.Headers["Content-Length"] = new[] { "11" }; await response.Body.WriteAsync(Encoding.ASCII.GetBytes("Hello World"), 0, 11); @@ -293,6 +295,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { var response = string.Join("\r\n", new string[] { "HTTP/1.1 200 OK", + $"Date: {testContext.DateHeaderValue}", "Content-Length: 11", "", "Hello World"}); @@ -330,7 +333,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var fullRequest = sendSequence.ToArray(); - using (var connection = new TestConnection(server.Port)) + using (var connection = server.CreateConnection()) { await connection.SendEnd(fullRequest); @@ -341,7 +344,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [Theory] [MemberData(nameof(ConnectionFilterData))] - public async Task InvalidLengthResultsIn400(ServiceContext testContext) + public async Task InvalidLengthResultsIn400(TestServiceContext testContext) { using (var server = new TestServer(async httpContext => { @@ -355,13 +358,12 @@ namespace Microsoft.AspNetCore.Server.KestrelTests ;// read to end } - response.Headers.Clear(); response.Headers["Content-Length"] = new[] { "11" }; await response.Body.WriteAsync(Encoding.ASCII.GetBytes("Hello World"), 0, 11); }, testContext)) { - using (var connection = new TestConnection(server.Port)) + using (var connection = server.CreateConnection()) { await connection.Send( "POST / HTTP/1.1", @@ -373,10 +375,9 @@ namespace Microsoft.AspNetCore.Server.KestrelTests "HTTP/1.1 400 Bad Request", "Connection: close", ""); - await connection.ReceiveStartsWith("Date:"); await connection.ReceiveForcedEnd( + $"Date: {testContext.DateHeaderValue}", "Content-Length: 0", - "Server: Kestrel", "", ""); } @@ -385,7 +386,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [Theory] [MemberData(nameof(ConnectionFilterData))] - public async Task InvalidSizedDataResultsIn400(ServiceContext testContext) + public async Task InvalidSizedDataResultsIn400(TestServiceContext testContext) { using (var server = new TestServer(async httpContext => { @@ -399,13 +400,12 @@ namespace Microsoft.AspNetCore.Server.KestrelTests ;// read to end } - response.Headers.Clear(); response.Headers["Content-Length"] = new[] { "11" }; await response.Body.WriteAsync(Encoding.ASCII.GetBytes("Hello World"), 0, 11); }, testContext)) { - using (var connection = new TestConnection(server.Port)) + using (var connection = server.CreateConnection()) { await connection.Send( "POST / HTTP/1.1", @@ -418,10 +418,9 @@ namespace Microsoft.AspNetCore.Server.KestrelTests "HTTP/1.1 400 Bad Request", "Connection: close", ""); - await connection.ReceiveStartsWith("Date:"); await connection.ReceiveForcedEnd( + $"Date: {testContext.DateHeaderValue}", "Content-Length: 0", - "Server: Kestrel", "", ""); } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedResponseTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedResponseTests.cs index fd4035cc3a..62758e36a1 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedResponseTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedResponseTests.cs @@ -12,11 +12,11 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { public class ChunkedResponseTests { - public static TheoryData ConnectionFilterData + public static TheoryData ConnectionFilterData { get { - return new TheoryData + return new TheoryData { { new TestServiceContext() @@ -30,17 +30,16 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [Theory] [MemberData(nameof(ConnectionFilterData))] - public async Task ResponsesAreChunkedAutomatically(ServiceContext testContext) + public async Task ResponsesAreChunkedAutomatically(TestServiceContext testContext) { using (var server = new TestServer(async httpContext => { var response = httpContext.Response; - response.Headers.Clear(); await response.Body.WriteAsync(Encoding.ASCII.GetBytes("Hello "), 0, 6); await response.Body.WriteAsync(Encoding.ASCII.GetBytes("World!"), 0, 6); }, testContext)) { - using (var connection = new TestConnection(server.Port)) + using (var connection = server.CreateConnection()) { await connection.SendEnd( "GET / HTTP/1.1", @@ -48,6 +47,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests ""); await connection.ReceiveEnd( "HTTP/1.1 200 OK", + $"Date: {testContext.DateHeaderValue}", "Transfer-Encoding: chunked", "", "6", @@ -63,18 +63,17 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [Theory] [MemberData(nameof(ConnectionFilterData))] - public async Task ZeroLengthWritesAreIgnored(ServiceContext testContext) + public async Task ZeroLengthWritesAreIgnored(TestServiceContext testContext) { using (var server = new TestServer(async httpContext => { var response = httpContext.Response; - response.Headers.Clear(); await response.Body.WriteAsync(Encoding.ASCII.GetBytes("Hello "), 0, 6); await response.Body.WriteAsync(new byte[0], 0, 0); await response.Body.WriteAsync(Encoding.ASCII.GetBytes("World!"), 0, 6); }, testContext)) { - using (var connection = new TestConnection(server.Port)) + using (var connection = server.CreateConnection()) { await connection.SendEnd( "GET / HTTP/1.1", @@ -82,6 +81,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests ""); await connection.ReceiveEnd( "HTTP/1.1 200 OK", + $"Date: {testContext.DateHeaderValue}", "Transfer-Encoding: chunked", "", "6", @@ -97,16 +97,15 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [Theory] [MemberData(nameof(ConnectionFilterData))] - public async Task EmptyResponseBodyHandledCorrectlyWithZeroLengthWrite(ServiceContext testContext) + public async Task EmptyResponseBodyHandledCorrectlyWithZeroLengthWrite(TestServiceContext testContext) { using (var server = new TestServer(async httpContext => { var response = httpContext.Response; - response.Headers.Clear(); await response.Body.WriteAsync(new byte[0], 0, 0); }, testContext)) { - using (var connection = new TestConnection(server.Port)) + using (var connection = server.CreateConnection()) { await connection.SendEnd( "GET / HTTP/1.1", @@ -114,6 +113,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests ""); await connection.ReceiveEnd( "HTTP/1.1 200 OK", + $"Date: {testContext.DateHeaderValue}", "Transfer-Encoding: chunked", "", "0", @@ -125,17 +125,16 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [Theory] [MemberData(nameof(ConnectionFilterData))] - public async Task ConnectionClosedIfExeptionThrownAfterWrite(ServiceContext testContext) + public async Task ConnectionClosedIfExeptionThrownAfterWrite(TestServiceContext testContext) { using (var server = new TestServer(async httpContext => { var response = httpContext.Response; - response.Headers.Clear(); await response.Body.WriteAsync(Encoding.ASCII.GetBytes("Hello World!"), 0, 12); throw new Exception(); }, testContext)) { - using (var connection = new TestConnection(server.Port)) + using (var connection = server.CreateConnection()) { // SendEnd is not called, so it isn't the client closing the connection. // client closing the connection. @@ -145,6 +144,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests ""); await connection.ReceiveForcedEnd( "HTTP/1.1 200 OK", + $"Date: {testContext.DateHeaderValue}", "Transfer-Encoding: chunked", "", "c", @@ -156,17 +156,16 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [Theory] [MemberData(nameof(ConnectionFilterData))] - public async Task ConnectionClosedIfExeptionThrownAfterZeroLengthWrite(ServiceContext testContext) + public async Task ConnectionClosedIfExeptionThrownAfterZeroLengthWrite(TestServiceContext testContext) { using (var server = new TestServer(async httpContext => { var response = httpContext.Response; - response.Headers.Clear(); await response.Body.WriteAsync(new byte[0], 0, 0); throw new Exception(); }, testContext)) { - using (var connection = new TestConnection(server.Port)) + using (var connection = server.CreateConnection()) { // SendEnd is not called, so it isn't the client closing the connection. await connection.Send( @@ -177,6 +176,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests // Headers are sent before connection is closed, but chunked body terminator isn't sent await connection.ReceiveForcedEnd( "HTTP/1.1 200 OK", + $"Date: {testContext.DateHeaderValue}", "Transfer-Encoding: chunked", "", ""); @@ -186,14 +186,13 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [Theory] [MemberData(nameof(ConnectionFilterData))] - public async Task WritesAreFlushedPriorToResponseCompletion(ServiceContext testContext) + public async Task WritesAreFlushedPriorToResponseCompletion(TestServiceContext testContext) { var flushWh = new ManualResetEventSlim(); using (var server = new TestServer(async httpContext => { var response = httpContext.Response; - response.Headers.Clear(); await response.Body.WriteAsync(Encoding.ASCII.GetBytes("Hello "), 0, 6); // Don't complete response until client has received the first chunk. @@ -202,7 +201,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests await response.Body.WriteAsync(Encoding.ASCII.GetBytes("World!"), 0, 6); }, testContext)) { - using (var connection = new TestConnection(server.Port)) + using (var connection = server.CreateConnection()) { await connection.SendEnd( "GET / HTTP/1.1", @@ -210,6 +209,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests ""); await connection.Receive( "HTTP/1.1 200 OK", + $"Date: {testContext.DateHeaderValue}", "Transfer-Encoding: chunked", "", "6", diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionFilterTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionFilterTests.cs index cb1a7fa182..2d32fd6c6e 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionFilterTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionFilterTests.cs @@ -16,7 +16,6 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { var request = httpContext.Request; var response = httpContext.Response; - response.Headers.Clear(); while (true) { var buffer = new byte[8192]; @@ -39,12 +38,13 @@ namespace Microsoft.AspNetCore.Server.KestrelTests using (var server = new TestServer(App, serviceContext)) { - using (var connection = new TestConnection(server.Port)) + using (var connection = server.CreateConnection()) { // "?" changes to "!" await connection.SendEnd(sendString); await connection.ReceiveEnd( "HTTP/1.1 200 OK", + $"Date: {serviceContext.DateHeaderValue}", "", "Hello World!"); } @@ -60,7 +60,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests using (var server = new TestServer(App, serviceContext)) { - using (var connection = new TestConnection(server.Port)) + using (var connection = server.CreateConnection()) { await connection.SendEnd( "POST / HTTP/1.0", @@ -68,6 +68,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests "Hello World?"); await connection.ReceiveEnd( "HTTP/1.1 200 OK", + $"Date: {serviceContext.DateHeaderValue}", "", "Hello World!"); } @@ -81,7 +82,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests using (var server = new TestServer(App, serviceContext)) { - using (var connection = new TestConnection(server.Port)) + using (var connection = server.CreateConnection()) { try { diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/DefaultHeaderTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/DefaultHeaderTests.cs new file mode 100644 index 0000000000..b682dd35de --- /dev/null +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/DefaultHeaderTests.cs @@ -0,0 +1,41 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System.Threading.Tasks; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Server.Kestrel; +using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; +using Xunit; + +namespace Microsoft.AspNetCore.Server.KestrelTests +{ + public class DefaultHeaderTests + { + [Fact] + public async Task TestDefaultHeaders() + { + var testContext = new TestServiceContext() + { + ServerOptions = { AddServerHeader = true } + }; + + using (var server = new TestServer(ctx => TaskUtilities.CompletedTask, testContext)) + { + using (var connection = server.CreateConnection()) + { + await connection.SendEnd( + "GET / HTTP/1.0", + "", + ""); + + await connection.ReceiveEnd( + "HTTP/1.1 200 OK", + $"Date: {testContext.DateHeaderValue}", + "Server: Kestrel", + "", + ""); + } + } + } + } +} \ No newline at end of file diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs index f6894e7dfb..a611f8305b 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs @@ -20,11 +20,11 @@ namespace Microsoft.AspNetCore.Server.KestrelTests /// public class EngineTests { - public static TheoryData ConnectionFilterData + public static TheoryData ConnectionFilterData { get { - return new TheoryData + return new TheoryData { { new TestServiceContext() @@ -40,7 +40,6 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { var request = httpContext.Request; var response = httpContext.Response; - response.Headers.Clear(); while (true) { var buffer = new byte[8192]; @@ -61,20 +60,18 @@ namespace Microsoft.AspNetCore.Server.KestrelTests await request.Body.CopyToAsync(data); var bytes = data.ToArray(); - response.Headers.Clear(); response.Headers["Content-Length"] = bytes.Length.ToString(); await response.Body.WriteAsync(bytes, 0, bytes.Length); } private Task EmptyApp(HttpContext httpContext) { - httpContext.Response.Headers.Clear(); return Task.FromResult(null); } [Theory] [MemberData(nameof(ConnectionFilterData))] - public void EngineCanStartAndStop(ServiceContext testContext) + public void EngineCanStartAndStop(TestServiceContext testContext) { var engine = new KestrelEngine(testContext); engine.Start(1); @@ -121,11 +118,11 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [Theory] [MemberData(nameof(ConnectionFilterData))] - public async Task Http10RequestReceivesHttp11Response(ServiceContext testContext) + public async Task Http10RequestReceivesHttp11Response(TestServiceContext testContext) { using (var server = new TestServer(App, testContext)) { - using (var connection = new TestConnection(server.Port)) + using (var connection = server.CreateConnection()) { await connection.SendEnd( "POST / HTTP/1.0", @@ -133,6 +130,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests "Hello World"); await connection.ReceiveEnd( "HTTP/1.1 200 OK", + $"Date: {testContext.DateHeaderValue}", "", "Hello World"); } @@ -142,11 +140,11 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [Theory] [MemberData(nameof(ConnectionFilterData))] - public async Task Http11(ServiceContext testContext) + public async Task Http11(TestServiceContext testContext) { using (var server = new TestServer(AppChunked, testContext)) { - using (var connection = new TestConnection(server.Port)) + using (var connection = server.CreateConnection()) { await connection.SendEnd( "GET / HTTP/1.1", @@ -157,10 +155,12 @@ namespace Microsoft.AspNetCore.Server.KestrelTests "Goodbye"); await connection.ReceiveEnd( "HTTP/1.1 200 OK", + $"Date: {testContext.DateHeaderValue}", "Content-Length: 0", "", "HTTP/1.1 200 OK", "Connection: close", + $"Date: {testContext.DateHeaderValue}", "Content-Length: 7", "", "Goodbye"); @@ -170,7 +170,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [Theory] [MemberData(nameof(ConnectionFilterData))] - public async Task HeadersAndStreamsAreReused(ServiceContext testContext) + public async Task HeadersAndStreamsAreReused(TestServiceContext testContext) { var streamCount = 0; var requestHeadersCount = 0; @@ -198,21 +198,35 @@ namespace Microsoft.AspNetCore.Server.KestrelTests lastResponseHeaders = context.Response.Headers; responseHeadersCount++; } - context.Response.Headers.Clear(); return context.Request.Body.CopyToAsync(context.Response.Body); }, testContext)) { - using (var connection = new TestConnection(server.Port)) + using (var connection = server.CreateConnection()) { var requestData = Enumerable.Repeat("GET / HTTP/1.1\r\n", loopCount) .Concat(new[] { "GET / HTTP/1.1\r\nConnection: close\r\n\r\nGoodbye" }); + var response = string.Join("\r\n", new string[] { + "HTTP/1.1 200 OK", + $"Date: {testContext.DateHeaderValue}", + "Content-Length: 0", + ""}); + + var lastResponse = string.Join("\r\n", new string[] + { + "HTTP/1.1 200 OK", + "Connection: close", + $"Date: {testContext.DateHeaderValue}", + "", + "Goodbye" + }); + var responseData = - Enumerable.Repeat("HTTP/1.1 200 OK\r\nContent-Length: 0\r\n", loopCount) - .Concat(new[] { "HTTP/1.1 200 OK\r\nConnection: close\r\n\r\nGoodbye" }); + Enumerable.Repeat(response, loopCount) + .Concat(new[] { lastResponse }); await connection.SendEnd(requestData.ToArray()); @@ -227,11 +241,11 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [Theory] [MemberData(nameof(ConnectionFilterData))] - public async Task Http10ContentLength(ServiceContext testContext) + public async Task Http10ContentLength(TestServiceContext testContext) { using (var server = new TestServer(App, testContext)) { - using (var connection = new TestConnection(server.Port)) + using (var connection = server.CreateConnection()) { await connection.SendEnd( "POST / HTTP/1.0", @@ -240,6 +254,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests "Hello World"); await connection.ReceiveEnd( "HTTP/1.1 200 OK", + $"Date: {testContext.DateHeaderValue}", "", "Hello World"); } @@ -248,11 +263,11 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [Theory] [MemberData(nameof(ConnectionFilterData))] - public async Task Http10KeepAlive(ServiceContext testContext) + public async Task Http10KeepAlive(TestServiceContext testContext) { using (var server = new TestServer(AppChunked, testContext)) { - using (var connection = new TestConnection(server.Port)) + using (var connection = server.CreateConnection()) { await connection.SendEnd( "GET / HTTP/1.0", @@ -264,10 +279,12 @@ namespace Microsoft.AspNetCore.Server.KestrelTests await connection.Receive( "HTTP/1.1 200 OK", "Connection: keep-alive", + $"Date: {testContext.DateHeaderValue}", "Content-Length: 0", "\r\n"); await connection.ReceiveEnd( "HTTP/1.1 200 OK", + $"Date: {testContext.DateHeaderValue}", "Content-Length: 7", "", "Goodbye"); @@ -277,11 +294,11 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [Theory] [MemberData(nameof(ConnectionFilterData))] - public async Task Http10KeepAliveNotUsedIfResponseContentLengthNotSet(ServiceContext testContext) + public async Task Http10KeepAliveNotUsedIfResponseContentLengthNotSet(TestServiceContext testContext) { using (var server = new TestServer(App, testContext)) { - using (var connection = new TestConnection(server.Port)) + using (var connection = server.CreateConnection()) { await connection.SendEnd( "GET / HTTP/1.0", @@ -295,10 +312,12 @@ namespace Microsoft.AspNetCore.Server.KestrelTests await connection.Receive( "HTTP/1.1 200 OK", "Connection: keep-alive", + $"Date: {testContext.DateHeaderValue}", "Content-Length: 0", "\r\n"); await connection.ReceiveEnd( "HTTP/1.1 200 OK", + $"Date: {testContext.DateHeaderValue}", "", "Goodbye"); } @@ -307,11 +326,11 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [Theory] [MemberData(nameof(ConnectionFilterData))] - public async Task Http10KeepAliveContentLength(ServiceContext testContext) + public async Task Http10KeepAliveContentLength(TestServiceContext testContext) { using (var server = new TestServer(AppChunked, testContext)) { - using (var connection = new TestConnection(server.Port)) + using (var connection = server.CreateConnection()) { await connection.SendEnd( "POST / HTTP/1.0", @@ -324,11 +343,13 @@ namespace Microsoft.AspNetCore.Server.KestrelTests await connection.Receive( "HTTP/1.1 200 OK", "Connection: keep-alive", + $"Date: {testContext.DateHeaderValue}", "Content-Length: 11", "", "Hello World"); await connection.ReceiveEnd( "HTTP/1.1 200 OK", + $"Date: {testContext.DateHeaderValue}", "Content-Length: 7", "", "Goodbye"); @@ -338,11 +359,11 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [Theory] [MemberData(nameof(ConnectionFilterData))] - public async Task Expect100ContinueForBody(ServiceContext testContext) + public async Task Expect100ContinueForBody(TestServiceContext testContext) { using (var server = new TestServer(AppChunked, testContext)) { - using (var connection = new TestConnection(server.Port)) + using (var connection = server.CreateConnection()) { await connection.Send( "POST / HTTP/1.1", @@ -355,6 +376,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests await connection.Receive( "HTTP/1.1 200 OK", "Connection: close", + $"Date: {testContext.DateHeaderValue}", "Content-Length: 11", "", "Hello World"); @@ -364,7 +386,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [Theory] [MemberData(nameof(ConnectionFilterData))] - public async Task DisconnectingClient(ServiceContext testContext) + public async Task DisconnectingClient(TestServiceContext testContext) { using (var server = new TestServer(App, testContext)) { @@ -373,13 +395,14 @@ namespace Microsoft.AspNetCore.Server.KestrelTests socket.Dispose(); await Task.Delay(200); - using (var connection = new TestConnection(server.Port)) + using (var connection = server.CreateConnection()) { await connection.SendEnd( "GET / HTTP/1.0", "\r\n"); await connection.ReceiveEnd( "HTTP/1.1 200 OK", + $"Date: {testContext.DateHeaderValue}", "\r\n"); } } @@ -387,11 +410,11 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [Theory] [MemberData(nameof(ConnectionFilterData))] - public async Task ZeroContentLengthSetAutomaticallyAfterNoWrites(ServiceContext testContext) + public async Task ZeroContentLengthSetAutomaticallyAfterNoWrites(TestServiceContext testContext) { using (var server = new TestServer(EmptyApp, testContext)) { - using (var connection = new TestConnection(server.Port)) + using (var connection = server.CreateConnection()) { await connection.SendEnd( "GET / HTTP/1.1", @@ -402,10 +425,12 @@ namespace Microsoft.AspNetCore.Server.KestrelTests ""); await connection.ReceiveEnd( "HTTP/1.1 200 OK", + $"Date: {testContext.DateHeaderValue}", "Content-Length: 0", "", "HTTP/1.1 200 OK", "Connection: keep-alive", + $"Date: {testContext.DateHeaderValue}", "Content-Length: 0", "", ""); @@ -415,11 +440,11 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [Theory] [MemberData(nameof(ConnectionFilterData))] - public async Task ZeroContentLengthNotSetAutomaticallyForNonKeepAliveRequests(ServiceContext testContext) + public async Task ZeroContentLengthNotSetAutomaticallyForNonKeepAliveRequests(TestServiceContext testContext) { using (var server = new TestServer(EmptyApp, testContext)) { - using (var connection = new TestConnection(server.Port)) + using (var connection = server.CreateConnection()) { await connection.SendEnd( "GET / HTTP/1.1", @@ -429,11 +454,12 @@ namespace Microsoft.AspNetCore.Server.KestrelTests await connection.ReceiveEnd( "HTTP/1.1 200 OK", "Connection: close", + $"Date: {testContext.DateHeaderValue}", "", ""); } - using (var connection = new TestConnection(server.Port)) + using (var connection = server.CreateConnection()) { await connection.SendEnd( "GET / HTTP/1.0", @@ -441,6 +467,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests ""); await connection.ReceiveEnd( "HTTP/1.1 200 OK", + $"Date: {testContext.DateHeaderValue}", "", ""); } @@ -449,11 +476,11 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [Theory] [MemberData(nameof(ConnectionFilterData))] - public async Task ZeroContentLengthNotSetAutomaticallyForHeadRequests(ServiceContext testContext) + public async Task ZeroContentLengthNotSetAutomaticallyForHeadRequests(TestServiceContext testContext) { using (var server = new TestServer(EmptyApp, testContext)) { - using (var connection = new TestConnection(server.Port)) + using (var connection = server.CreateConnection()) { await connection.SendEnd( "HEAD / HTTP/1.1", @@ -461,6 +488,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests ""); await connection.ReceiveEnd( "HTTP/1.1 200 OK", + $"Date: {testContext.DateHeaderValue}", "", ""); } @@ -469,13 +497,12 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [Theory] [MemberData(nameof(ConnectionFilterData))] - public async Task ZeroContentLengthNotSetAutomaticallyForCertainStatusCodes(ServiceContext testContext) + public async Task ZeroContentLengthNotSetAutomaticallyForCertainStatusCodes(TestServiceContext testContext) { using (var server = new TestServer(async httpContext => { var request = httpContext.Request; var response = httpContext.Response; - response.Headers.Clear(); using (var reader = new StreamReader(request.Body, Encoding.ASCII)) { @@ -484,7 +511,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } }, testContext)) { - using (var connection = new TestConnection(server.Port)) + using (var connection = server.CreateConnection()) { await connection.SendEnd( "POST / HTTP/1.1", @@ -505,14 +532,19 @@ namespace Microsoft.AspNetCore.Server.KestrelTests "200"); await connection.ReceiveEnd( "HTTP/1.1 101 Switching Protocols", + $"Date: {testContext.DateHeaderValue}", "", "HTTP/1.1 204 No Content", + $"Date: {testContext.DateHeaderValue}", "", "HTTP/1.1 205 Reset Content", + $"Date: {testContext.DateHeaderValue}", "", "HTTP/1.1 304 Not Modified", + $"Date: {testContext.DateHeaderValue}", "", "HTTP/1.1 200 OK", + $"Date: {testContext.DateHeaderValue}", "Content-Length: 0", "", ""); @@ -522,7 +554,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [Theory] [MemberData(nameof(ConnectionFilterData))] - public async Task ThrowingResultsIn500Response(ServiceContext testContext) + public async Task ThrowingResultsIn500Response(TestServiceContext testContext) { bool onStartingCalled = false; @@ -539,12 +571,11 @@ namespace Microsoft.AspNetCore.Server.KestrelTests }, null); // Anything added to the ResponseHeaders dictionary is ignored - response.Headers.Clear(); response.Headers["Content-Length"] = "11"; throw new Exception(); }, testContext)) { - using (var connection = new TestConnection(server.Port)) + using (var connection = server.CreateConnection()) { await connection.SendEnd( "GET / HTTP/1.1", @@ -556,19 +587,17 @@ namespace Microsoft.AspNetCore.Server.KestrelTests await connection.Receive( "HTTP/1.1 500 Internal Server Error", ""); - await connection.ReceiveStartsWith("Date:"); await connection.Receive( + $"Date: {testContext.DateHeaderValue}", "Content-Length: 0", - "Server: Kestrel", "", "HTTP/1.1 500 Internal Server Error", ""); await connection.Receive("Connection: close", ""); - await connection.ReceiveStartsWith("Date:"); await connection.ReceiveEnd( + $"Date: {testContext.DateHeaderValue}", "Content-Length: 0", - "Server: Kestrel", "", ""); @@ -580,7 +609,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [Theory] [MemberData(nameof(ConnectionFilterData))] - public async Task ThrowingAfterWritingKillsConnection(ServiceContext testContext) + public async Task ThrowingAfterWritingKillsConnection(TestServiceContext testContext) { bool onStartingCalled = false; @@ -596,13 +625,12 @@ namespace Microsoft.AspNetCore.Server.KestrelTests return Task.FromResult(null); }, null); - response.Headers.Clear(); response.Headers["Content-Length"] = new[] { "11" }; await response.Body.WriteAsync(Encoding.ASCII.GetBytes("Hello World"), 0, 11); throw new Exception(); }, testContext)) { - using (var connection = new TestConnection(server.Port)) + using (var connection = server.CreateConnection()) { await connection.Send( "GET / HTTP/1.1", @@ -610,6 +638,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests ""); await connection.ReceiveForcedEnd( "HTTP/1.1 200 OK", + $"Date: {testContext.DateHeaderValue}", "Content-Length: 11", "", "Hello World"); @@ -622,7 +651,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [Theory] [MemberData(nameof(ConnectionFilterData))] - public async Task ThrowingAfterPartialWriteKillsConnection(ServiceContext testContext) + public async Task ThrowingAfterPartialWriteKillsConnection(TestServiceContext testContext) { bool onStartingCalled = false; @@ -638,13 +667,12 @@ namespace Microsoft.AspNetCore.Server.KestrelTests return Task.FromResult(null); }, null); - response.Headers.Clear(); response.Headers["Content-Length"] = new[] { "11" }; await response.Body.WriteAsync(Encoding.ASCII.GetBytes("Hello"), 0, 5); throw new Exception(); }, testContext)) { - using (var connection = new TestConnection(server.Port)) + using (var connection = server.CreateConnection()) { await connection.Send( "GET / HTTP/1.1", @@ -652,6 +680,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests ""); await connection.ReceiveForcedEnd( "HTTP/1.1 200 OK", + $"Date: {testContext.DateHeaderValue}", "Content-Length: 11", "", "Hello"); @@ -664,11 +693,11 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [Theory] [MemberData(nameof(ConnectionFilterData))] - public async Task ConnectionClosesWhenFinReceived(ServiceContext testContext) + public async Task ConnectionClosesWhenFinReceived(TestServiceContext testContext) { using (var server = new TestServer(AppChunked, testContext)) { - using (var connection = new TestConnection(server.Port)) + using (var connection = server.CreateConnection()) { await connection.SendEnd( "GET / HTTP/1.1", @@ -679,9 +708,11 @@ namespace Microsoft.AspNetCore.Server.KestrelTests "Goodbye"); await connection.ReceiveEnd( "HTTP/1.1 200 OK", + $"Date: {testContext.DateHeaderValue}", "Content-Length: 0", "", "HTTP/1.1 200 OK", + $"Date: {testContext.DateHeaderValue}", "Content-Length: 7", "", "Goodbye"); @@ -691,49 +722,45 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [Theory] [MemberData(nameof(ConnectionFilterData))] - public async Task ConnectionClosesWhenFinReceivedBeforeRequestCompletes(ServiceContext testContext) + public async Task ConnectionClosesWhenFinReceivedBeforeRequestCompletes(TestServiceContext testContext) { using (var server = new TestServer(AppChunked, testContext)) { - using (var connection = new TestConnection(server.Port)) + using (var connection = server.CreateConnection()) { await connection.SendEnd( "GET / HTTP/1.1", "", "POST / HTTP/1.1"); - await connection.Receive( + await connection.ReceiveForcedEnd( "HTTP/1.1 200 OK", + $"Date: {testContext.DateHeaderValue}", "Content-Length: 0", "", "HTTP/1.1 400 Bad Request", "Connection: close", - ""); - await connection.ReceiveStartsWith("Date:"); - await connection.ReceiveForcedEnd( + $"Date: {testContext.DateHeaderValue}", "Content-Length: 0", - "Server: Kestrel", "", ""); } - using (var connection = new TestConnection(server.Port)) + using (var connection = server.CreateConnection()) { await connection.SendEnd( "GET / HTTP/1.1", "", "POST / HTTP/1.1", "Content-Length: 7"); - await connection.Receive( + await connection.ReceiveForcedEnd( "HTTP/1.1 200 OK", + $"Date: {testContext.DateHeaderValue}", "Content-Length: 0", "", "HTTP/1.1 400 Bad Request", "Connection: close", - ""); - await connection.ReceiveStartsWith("Date:"); - await connection.ReceiveForcedEnd( + $"Date: {testContext.DateHeaderValue}", "Content-Length: 0", - "Server: Kestrel", "", ""); } @@ -742,7 +769,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [Theory] [MemberData(nameof(ConnectionFilterData))] - public async Task ThrowingInOnStartingResultsInFailedWritesAnd500Response(ServiceContext testContext) + public async Task ThrowingInOnStartingResultsInFailedWritesAnd500Response(TestServiceContext testContext) { var onStartingCallCount1 = 0; var onStartingCallCount2 = 0; @@ -767,7 +794,6 @@ namespace Microsoft.AspNetCore.Server.KestrelTests throw onStartingException; }, null); - response.Headers.Clear(); response.Headers["Content-Length"] = new[] { "11" }; var writeException = await Assert.ThrowsAsync(async () => @@ -778,7 +804,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests failedWriteCount++; }, testContext)) { - using (var connection = new TestConnection(server.Port)) + using (var connection = server.CreateConnection()) { await connection.SendEnd( "GET / HTTP/1.1", @@ -790,18 +816,16 @@ namespace Microsoft.AspNetCore.Server.KestrelTests await connection.Receive( "HTTP/1.1 500 Internal Server Error", ""); - await connection.ReceiveStartsWith("Date:"); await connection.Receive( + $"Date: {testContext.DateHeaderValue}", "Content-Length: 0", - "Server: Kestrel", "", "HTTP/1.1 500 Internal Server Error", "Connection: close", ""); - await connection.ReceiveStartsWith("Date:"); await connection.ReceiveEnd( + $"Date: {testContext.DateHeaderValue}", "Content-Length: 0", - "Server: Kestrel", "", ""); @@ -815,7 +839,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [Theory] [MemberData(nameof(ConnectionFilterData))] - public async Task ThrowingInOnCompletedIsLoggedAndClosesConnection(ServiceContext testContext) + public async Task ThrowingInOnCompletedIsLoggedAndClosesConnection(TestServiceContext testContext) { var onCompletedCalled1 = false; var onCompletedCalled2 = false; @@ -837,13 +861,12 @@ namespace Microsoft.AspNetCore.Server.KestrelTests throw new Exception(); }, null); - response.Headers.Clear(); response.Headers["Content-Length"] = new[] { "11" }; await response.Body.WriteAsync(Encoding.ASCII.GetBytes("Hello World"), 0, 11); }, testContext)) { - using (var connection = new TestConnection(server.Port)) + using (var connection = server.CreateConnection()) { await connection.Send( "GET / HTTP/1.1", @@ -851,6 +874,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests ""); await connection.ReceiveForcedEnd( "HTTP/1.1 200 OK", + $"Date: {testContext.DateHeaderValue}", "Content-Length: 11", "", "Hello World"); @@ -865,7 +889,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [Theory] [MemberData(nameof(ConnectionFilterData))] - public async Task RequestsCanBeAbortedMidRead(ServiceContext testContext) + public async Task RequestsCanBeAbortedMidRead(TestServiceContext testContext) { var readTcs = new TaskCompletionSource(); var registrationTcs = new TaskCompletionSource(); @@ -883,7 +907,6 @@ namespace Microsoft.AspNetCore.Server.KestrelTests if (requestId == 1) { - response.Headers.Clear(); response.Headers["Content-Length"] = new[] { "5" }; await response.WriteAsync("World"); @@ -908,7 +931,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } }, testContext)) { - using (var connection = new TestConnection(server.Port)) + using (var connection = server.CreateConnection()) { // Never send the body so CopyToAsync always fails. await connection.Send( @@ -922,6 +945,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests await connection.ReceiveForcedEnd( "HTTP/1.1 200 OK", + $"Date: {testContext.DateHeaderValue}", "Content-Length: 5", "", "World"); @@ -937,7 +961,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [Theory] [MemberData(nameof(ConnectionFilterData))] - public async Task FailedWritesResultInAbortedRequest(ServiceContext testContext) + public async Task FailedWritesResultInAbortedRequest(TestServiceContext testContext) { // This should match _maxBytesPreCompleted in SocketOutput var maxBytesPreCompleted = 65536; @@ -959,8 +983,6 @@ namespace Microsoft.AspNetCore.Server.KestrelTests await request.Body.CopyToAsync(Stream.Null); connectionCloseWh.Wait(); - response.Headers.Clear(); - try { // Ensure write is long enough to disable write-behind buffering @@ -979,7 +1001,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests writeTcs.SetException(new Exception("This shouldn't be reached.")); }, testContext)) { - using (var connection = new TestConnection(server.Port)) + using (var connection = server.CreateConnection()) { await connection.Send( "POST / HTTP/1.1", @@ -1000,7 +1022,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [Theory] [MemberData(nameof(ConnectionFilterData))] - public async Task NoErrorsLoggedWhenServerEndsConnectionBeforeClient(ServiceContext testContext) + public async Task NoErrorsLoggedWhenServerEndsConnectionBeforeClient(TestServiceContext testContext) { var testLogger = new TestApplicationErrorLogger(); testContext.Log = new KestrelTrace(testLogger); @@ -1008,12 +1030,11 @@ namespace Microsoft.AspNetCore.Server.KestrelTests using (var server = new TestServer(async httpContext => { var response = httpContext.Response; - response.Headers.Clear(); response.Headers["Content-Length"] = new[] { "11" }; await response.Body.WriteAsync(Encoding.ASCII.GetBytes("Hello World"), 0, 11); }, testContext)) { - using (var connection = new TestConnection(server.Port)) + using (var connection = server.CreateConnection()) { await connection.Send( "GET / HTTP/1.0", @@ -1021,6 +1042,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests ""); await connection.ReceiveForcedEnd( "HTTP/1.1 200 OK", + $"Date: {testContext.DateHeaderValue}", "Content-Length: 11", "", "Hello World"); @@ -1032,7 +1054,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [Theory] [MemberData(nameof(ConnectionFilterData))] - public async Task NoResponseSentWhenConnectionIsClosedByServerBeforeClientFinishesSendingRequest(ServiceContext testContext) + public async Task NoResponseSentWhenConnectionIsClosedByServerBeforeClientFinishesSendingRequest(TestServiceContext testContext) { var testLogger = new TestApplicationErrorLogger(); testContext.Log = new KestrelTrace(testLogger); @@ -1043,7 +1065,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests return Task.FromResult(0); }, testContext)) { - using (var connection = new TestConnection(server.Port)) + using (var connection = server.CreateConnection()) { await connection.Send( "POST / HTTP/1.0", diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameResponseHeadersTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameResponseHeadersTests.cs index ce6098a5b2..fa5f446267 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameResponseHeadersTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameResponseHeadersTests.cs @@ -13,12 +13,10 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { public class FrameResponseHeadersTests { - [Theory] - [InlineData(true)] - [InlineData(false)] - public void InitialDictionaryContainsServerAndDate(bool addServerHeader) + [Fact] + public void InitialDictionaryIsEmpty() { - var serverOptions = new KestrelServerOptions { AddServerHeader = addServerHeader }; + var serverOptions = new KestrelServerOptions(); var connectionContext = new ConnectionContext { @@ -26,60 +24,17 @@ namespace Microsoft.AspNetCore.Server.KestrelTests ServerAddress = ServerAddress.FromUrl("http://localhost:5000"), ServerOptions = serverOptions, }; + var frame = new Frame(application: null, context: connectionContext); + frame.InitializeHeaders(); IDictionary headers = frame.ResponseHeaders; - if (addServerHeader) - { - Assert.Equal(2, headers.Count); - - StringValues serverHeader; - Assert.True(headers.TryGetValue("Server", out serverHeader)); - Assert.Equal(1, serverHeader.Count); - Assert.Equal("Kestrel", serverHeader[0]); - } - else - { - Assert.Equal(1, headers.Count); - - StringValues serverHeader; - Assert.False(headers.TryGetValue("Server", out serverHeader)); - } - - StringValues dateHeader; - DateTime date; - Assert.True(headers.TryGetValue("Date", out dateHeader)); - Assert.Equal(1, dateHeader.Count); - Assert.True(DateTime.TryParse(dateHeader[0], out date)); - Assert.True(DateTime.Now - date <= TimeSpan.FromMinutes(1)); - + Assert.Equal(0, headers.Count); Assert.False(headers.IsReadOnly); } - [Fact] - public void InitialEntriesCanBeCleared() - { - var serverOptions = new KestrelServerOptions(); - var connectionContext = new ConnectionContext - { - DateHeaderValueManager = new DateHeaderValueManager(), - ServerAddress = ServerAddress.FromUrl("http://localhost:5000"), - ServerOptions = serverOptions, - }; - var frame = new Frame(application: null, context: connectionContext); - frame.InitializeHeaders(); - - Assert.True(frame.ResponseHeaders.Count > 0); - - frame.ResponseHeaders.Clear(); - - Assert.Equal(0, frame.ResponseHeaders.Count); - Assert.False(frame.ResponseHeaders.ContainsKey("Server")); - Assert.False(frame.ResponseHeaders.ContainsKey("Date")); - } - [Theory] [InlineData("Server", "\r\nData")] [InlineData("Server", "\0Data")] diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/HttpsConnectionFilterTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/HttpsConnectionFilterTests.cs index f0046dee4e..0afa5216fe 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/HttpsConnectionFilterTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/HttpsConnectionFilterTests.cs @@ -403,7 +403,6 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { var request = httpContext.Request; var response = httpContext.Response; - response.Headers.Clear(); while (true) { var buffer = new byte[8192]; diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestConnection.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/TestConnection.cs index 1c929bcb57..f9974bef04 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/TestConnection.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/TestConnection.cs @@ -22,11 +22,14 @@ namespace Microsoft.AspNetCore.Server.KestrelTests private NetworkStream _stream; private StreamReader _reader; - public TestConnection(int port) + public TestConnection(TestServer server) { - Create(port); + Server = server; + Create(server.Port); } + public TestServer Server { get; } + public void Create(int port) { _socket = CreateConnectedLoopbackSocket(port); @@ -85,38 +88,6 @@ namespace Microsoft.AspNetCore.Server.KestrelTests Assert.Equal(expected, new String(actual, 0, offset)); } - public async Task ReceiveStartsWith(string prefix, int maxLineLength = 1024) - { - var actual = new char[maxLineLength]; - var offset = 0; - - while (offset < maxLineLength) - { - // Read one char at a time so we don't read past the end of the line. - var task = _reader.ReadAsync(actual, offset, 1); - if (!Debugger.IsAttached) - { - Assert.True(task.Wait(4000), "timeout"); - } - var count = await task; - if (count == 0) - { - break; - } - - Assert.True(count == 1); - offset++; - - if (actual[offset - 1] == '\n') - { - break; - } - } - - var actualLine = new string(actual, 0, offset); - Assert.StartsWith(prefix, actualLine); - } - public async Task ReceiveEnd(params string[] lines) { await Receive(lines); diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestServer.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/TestServer.cs index 9719999265..2a3deab41f 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/TestServer.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/TestServer.cs @@ -22,15 +22,15 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { } - public TestServer(RequestDelegate app, ServiceContext context) + public TestServer(RequestDelegate app, TestServiceContext context) : this(app, context, "http://127.0.0.1:0/") { } - public int Port => _address.Port; - - public TestServer(RequestDelegate app, ServiceContext context, string serverAddress) + public TestServer(RequestDelegate app, TestServiceContext context, string serverAddress) { + Context = context; + context.FrameFactory = connectionContext => { return new Frame(new DummyApplication(app), connectionContext); @@ -51,6 +51,15 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } } + public int Port => _address.Port; + + public TestServiceContext Context { get; } + + public TestConnection CreateConnection() + { + return new TestConnection(this); + } + public void Dispose() { _server.Dispose(); diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestServiceContext.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/TestServiceContext.cs index 12238ae2de..3c3cf36c77 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/TestServiceContext.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/TestServiceContext.cs @@ -7,6 +7,7 @@ using Microsoft.AspNetCore.Server.Kestrel; using Microsoft.AspNetCore.Server.Kestrel.Filter; using Microsoft.AspNetCore.Server.Kestrel.Http; using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; +using Microsoft.AspNetCore.Server.KestrelTests.TestHelpers; namespace Microsoft.AspNetCore.Server.KestrelTests { @@ -19,9 +20,9 @@ namespace Microsoft.AspNetCore.Server.KestrelTests AppLifetime = new LifetimeNotImplemented(); Log = new TestKestrelTrace(); ThreadPool = new LoggingThreadPool(Log); - DateHeaderValueManager = new DateHeaderValueManager(); - - ServerOptions = new KestrelServerOptions(); + DateHeaderValueManager = new DateHeaderValueManager(systemClock: new MockSystemClock()); + DateHeaderValue = DateHeaderValueManager.GetDateHeaderValues().String; + ServerOptions = new KestrelServerOptions { AddServerHeader = false }; ServerOptions.ShutdownTimeout = TimeSpan.FromSeconds(5); } @@ -31,6 +32,8 @@ namespace Microsoft.AspNetCore.Server.KestrelTests ServerOptions.ConnectionFilter = filter; } + public string DateHeaderValue { get; } + public RequestDelegate App { get From ef8b0a90d8d0536de768b1d9c947ee6c2fd67601 Mon Sep 17 00:00:00 2001 From: Pavel Krymets Date: Thu, 26 May 2016 10:34:25 -0700 Subject: [PATCH 0747/1662] Fix merge formatting issues and cross plat tests --- .../HttpsConnectionFilterTests.cs | 278 +++++++++--------- 1 file changed, 141 insertions(+), 137 deletions(-) diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/HttpsConnectionFilterTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/HttpsConnectionFilterTests.cs index f0046dee4e..5fb3784171 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/HttpsConnectionFilterTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/HttpsConnectionFilterTests.cs @@ -21,15 +21,13 @@ using Xunit; namespace Microsoft.AspNetCore.Server.KestrelTests { - public class HttpsConnectionFilterTests: IDisposable + public class HttpsConnectionFilterTests : IDisposable { private static string _serverAddress = "https://127.0.0.1:0/"; private static RemoteCertificateValidationCallback _alwaysValidCallback = (sender, cert, chain, sslPolicyErrors) => true; private static X509Certificate2 _x509Certificate2 = new X509Certificate2(@"TestResources/testCert.pfx", "testPassword"); - private HttpMessageHandler _handler; - #if NET451 static HttpsConnectionFilterTests() { @@ -43,21 +41,16 @@ namespace Microsoft.AspNetCore.Server.KestrelTests public HttpsConnectionFilterTests() { #if NET451 - _handler = new HttpClientHandler(); ServicePointManager.ServerCertificateValidationCallback += _alwaysValidCallback; -#else - var handler = new WinHttpHandler(); - handler.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true; - _handler = handler; #endif } public void Dispose() - { + { #if NET451 ServicePointManager.ServerCertificateValidationCallback -= _alwaysValidCallback; #endif - } + } // https://github.com/aspnet/KestrelHttpServer/issues/240 // This test currently fails on mono because of an issue with SslStream. @@ -66,88 +59,88 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [OSSkipCondition(OperatingSystems.MacOSX, SkipReason = "WinHttpHandler not available on non-Windows.")] public async Task CanReadAndWriteWithHttpsConnectionFilter() { - var serviceContext = new TestServiceContext(new HttpsConnectionFilter( - new HttpsConnectionFilterOptions + var serviceContext = new TestServiceContext(new HttpsConnectionFilter( + new HttpsConnectionFilterOptions { ServerCertificate = _x509Certificate2 }, - new NoOpConnectionFilter()) - ); + new NoOpConnectionFilter()) + ); using (var server = new TestServer(App, serviceContext, _serverAddress)) + { + using (var client = new HttpClient(GetHandler())) { - using (var client = new HttpClient(_handler)) - { - var result = await client.PostAsync($"https://localhost:{server.Port}/", new FormUrlEncodedContent(new[] { + var result = await client.PostAsync($"https://localhost:{server.Port}/", new FormUrlEncodedContent(new[] { new KeyValuePair("content", "Hello World?") })); - Assert.Equal("content=Hello+World%3F", await result.Content.ReadAsStringAsync()); - } + Assert.Equal("content=Hello+World%3F", await result.Content.ReadAsStringAsync()); } } + } [ConditionalFact] [OSSkipCondition(OperatingSystems.Linux, SkipReason = "WinHttpHandler not available on non-Windows.")] [OSSkipCondition(OperatingSystems.MacOSX, SkipReason = "WinHttpHandler not available on non-Windows.")] public async Task RequireCertificateFailsWhenNoCertificate() { - var serviceContext = new TestServiceContext(new HttpsConnectionFilter( - new HttpsConnectionFilterOptions - { + var serviceContext = new TestServiceContext(new HttpsConnectionFilter( + new HttpsConnectionFilterOptions + { ServerCertificate = _x509Certificate2, - ClientCertificateMode = ClientCertificateMode.RequireCertificate - }, - new NoOpConnectionFilter()) - ); + ClientCertificateMode = ClientCertificateMode.RequireCertificate + }, + new NoOpConnectionFilter()) + ); using (var server = new TestServer(App, serviceContext, _serverAddress)) + { + using (var client = new HttpClient(GetHandler())) { - using (var client = new HttpClient(_handler)) - { - await Assert.ThrowsAnyAsync( - () => client.GetAsync($"https://localhost:{server.Port}/")); - } + await Assert.ThrowsAnyAsync( + () => client.GetAsync($"https://localhost:{server.Port}/")); } } + } [ConditionalFact] [OSSkipCondition(OperatingSystems.Linux, SkipReason = "WinHttpHandler not available on non-Windows.")] [OSSkipCondition(OperatingSystems.MacOSX, SkipReason = "WinHttpHandler not available on non-Windows.")] public async Task AllowCertificateContinuesWhenNoCertificate() { - var serviceContext = new TestServiceContext(new HttpsConnectionFilter( - new HttpsConnectionFilterOptions - { - ServerCertificate = _x509Certificate2, - ClientCertificateMode = ClientCertificateMode.AllowCertificate - }, - new NoOpConnectionFilter()) - ); - - RequestDelegate app = context => + var serviceContext = new TestServiceContext(new HttpsConnectionFilter( + new HttpsConnectionFilterOptions { - Assert.Equal(context.Features.Get(), null); - return context.Response.WriteAsync("hello world"); - }; + ServerCertificate = _x509Certificate2, + ClientCertificateMode = ClientCertificateMode.AllowCertificate + }, + new NoOpConnectionFilter()) + ); + + RequestDelegate app = context => + { + Assert.Equal(context.Features.Get(), null); + return context.Response.WriteAsync("hello world"); + }; using (var server = new TestServer(app, serviceContext, _serverAddress)) + { + using (var client = new HttpClient(GetHandler())) { - using (var client = new HttpClient(_handler)) - { - var result = await client.GetAsync($"https://localhost:{server.Port}/"); + var result = await client.GetAsync($"https://localhost:{server.Port}/"); - Assert.Equal("hello world", await result.Content.ReadAsStringAsync()); - } + Assert.Equal("hello world", await result.Content.ReadAsStringAsync()); } } + } [Fact] public void ThrowsWhenNoServerCertificateIsProvided() - { + { Assert.Throws(() => new HttpsConnectionFilter( new HttpsConnectionFilterOptions(), new NoOpConnectionFilter()) ); - } + } [Fact] public async Task UsesProvidedServerCertificate() @@ -179,103 +172,103 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [Fact] public async Task CertificatePassedToHttpContext() { - var serviceContext = new TestServiceContext(new HttpsConnectionFilter( - new HttpsConnectionFilterOptions - { - ServerCertificate = _x509Certificate2, - ClientCertificateMode = ClientCertificateMode.RequireCertificate, - ClientCertificateValidation = (certificate, chain, sslPolicyErrors) => true - }, - new NoOpConnectionFilter()) - ); - - RequestDelegate app = context => + var serviceContext = new TestServiceContext(new HttpsConnectionFilter( + new HttpsConnectionFilterOptions { - var tlsFeature = context.Features.Get(); - Assert.NotNull(tlsFeature); - Assert.NotNull(tlsFeature.ClientCertificate); - Assert.NotNull(context.Connection.ClientCertificate); - return context.Response.WriteAsync("hello world"); - }; + ServerCertificate = _x509Certificate2, + ClientCertificateMode = ClientCertificateMode.RequireCertificate, + ClientCertificateValidation = (certificate, chain, sslPolicyErrors) => true + }, + new NoOpConnectionFilter()) + ); + + RequestDelegate app = context => + { + var tlsFeature = context.Features.Get(); + Assert.NotNull(tlsFeature); + Assert.NotNull(tlsFeature.ClientCertificate); + Assert.NotNull(context.Connection.ClientCertificate); + return context.Response.WriteAsync("hello world"); + }; using (var server = new TestServer(app, serviceContext, _serverAddress)) - { + { using (var client = new TcpClient()) { // SslStream is used to ensure the certificate is actually passed to the server // HttpClient might not send the certificate because it is invalid or it doesn't match any // of the certificate authorities sent by the server in the SSL handshake. var stream = await OpenSslStream(client, server); - await stream.AuthenticateAsClientAsync("localhost", new X509CertificateCollection(), SslProtocols.Tls12 | SslProtocols.Tls11, false); + await stream.AuthenticateAsClientAsync("localhost", new X509CertificateCollection(), SslProtocols.Tls12 | SslProtocols.Tls11, false); await AssertConnectionResult(stream, true); - } } } + } [ConditionalFact] [OSSkipCondition(OperatingSystems.Linux, SkipReason = "WinHttpHandler not available on non-Windows.")] [OSSkipCondition(OperatingSystems.MacOSX, SkipReason = "WinHttpHandler not available on non-Windows.")] public async Task HttpsSchemePassedToRequestFeature() { - var serviceContext = new TestServiceContext( - new HttpsConnectionFilter( - new HttpsConnectionFilterOptions - { + var serviceContext = new TestServiceContext( + new HttpsConnectionFilter( + new HttpsConnectionFilterOptions + { ServerCertificate = _x509Certificate2 - }, - new NoOpConnectionFilter()) - ); + }, + new NoOpConnectionFilter()) + ); - RequestDelegate app = context => context.Response.WriteAsync(context.Request.Scheme); + RequestDelegate app = context => context.Response.WriteAsync(context.Request.Scheme); using (var server = new TestServer(app, serviceContext, _serverAddress)) + { + using (var client = new HttpClient(GetHandler())) { - using (var client = new HttpClient(_handler)) - { - var result = await client.GetAsync($"https://localhost:{server.Port}/"); + var result = await client.GetAsync($"https://localhost:{server.Port}/"); - Assert.Equal("https", await result.Content.ReadAsStringAsync()); - } + Assert.Equal("https", await result.Content.ReadAsStringAsync()); } } + } [Fact] public async Task DoesNotSupportTls10() { - var serviceContext = new TestServiceContext(new HttpsConnectionFilter( - new HttpsConnectionFilterOptions - { - ServerCertificate = _x509Certificate2, - ClientCertificateMode = ClientCertificateMode.RequireCertificate, - ClientCertificateValidation = (certificate, chain, sslPolicyErrors) => true - }, - new NoOpConnectionFilter()) - ); - - RequestDelegate app = context => + var serviceContext = new TestServiceContext(new HttpsConnectionFilter( + new HttpsConnectionFilterOptions { - return context.Response.WriteAsync("hello world"); - }; + ServerCertificate = _x509Certificate2, + ClientCertificateMode = ClientCertificateMode.RequireCertificate, + ClientCertificateValidation = (certificate, chain, sslPolicyErrors) => true + }, + new NoOpConnectionFilter()) + ); + + RequestDelegate app = context => + { + return context.Response.WriteAsync("hello world"); + }; using (var server = new TestServer(app, serviceContext, _serverAddress)) + { + // SslStream is used to ensure the certificate is actually passed to the server + // HttpClient might not send the certificate because it is invalid or it doesn't match any + // of the certificate authorities sent by the server in the SSL handshake. + using (var client = new TcpClient()) { - // SslStream is used to ensure the certificate is actually passed to the server - // HttpClient might not send the certificate because it is invalid or it doesn't match any - // of the certificate authorities sent by the server in the SSL handshake. - using (var client = new TcpClient()) - { var stream = await OpenSslStream(client, server); - var ex = await Assert.ThrowsAsync(typeof(IOException), async () => - await stream.AuthenticateAsClientAsync("localhost", new X509CertificateCollection(), SslProtocols.Tls, false)); - } + var ex = await Assert.ThrowsAsync(typeof(IOException), + async () => await stream.AuthenticateAsClientAsync("localhost", new X509CertificateCollection(), SslProtocols.Tls, false)); } } + } [Theory] [InlineData(ClientCertificateMode.AllowCertificate)] [InlineData(ClientCertificateMode.RequireCertificate)] public async Task ClientCertificateValidationGetsCalledWithNotNullParameters(ClientCertificateMode mode) - { + { var clientCertificateValidationCalled = false; var serviceContext = new TestServiceContext(new HttpsConnectionFilter( new HttpsConnectionFilterOptions @@ -288,7 +281,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests Assert.NotNull(certificate); Assert.NotNull(chain); return true; - } + } }, new NoOpConnectionFilter()) ); @@ -303,7 +296,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests await stream.AuthenticateAsClientAsync("localhost", new X509CertificateCollection(), SslProtocols.Tls12 | SslProtocols.Tls11, false); await AssertConnectionResult(stream, true); Assert.True(clientCertificateValidationCalled); - } + } } } @@ -340,9 +333,9 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [InlineData(ClientCertificateMode.RequireCertificate)] public async Task RejectsConnectionOnSslPolicyErrorsWhenNoValidation(ClientCertificateMode mode) { - var serviceContext = new TestServiceContext(new HttpsConnectionFilter( - new HttpsConnectionFilterOptions - { + var serviceContext = new TestServiceContext(new HttpsConnectionFilter( + new HttpsConnectionFilterOptions + { ServerCertificate = _x509Certificate2, ClientCertificateMode = mode, }, @@ -369,29 +362,29 @@ namespace Microsoft.AspNetCore.Server.KestrelTests new HttpsConnectionFilterOptions { ServerCertificate = _x509Certificate2, - ClientCertificateMode = ClientCertificateMode.RequireCertificate, - ClientCertificateValidation = (certificate, chain, sslPolicyErrors) => true - }, - new NoOpConnectionFilter()) + ClientCertificateMode = ClientCertificateMode.RequireCertificate, + ClientCertificateValidation = (certificate, chain, sslPolicyErrors) => true + }, + new NoOpConnectionFilter()) ); - RequestDelegate app = context => - { - var tlsFeature = context.Features.Get(); - Assert.NotNull(tlsFeature); - Assert.NotNull(tlsFeature.ClientCertificate); - Assert.NotNull(context.Connection.ClientCertificate); - Assert.NotNull(context.Connection.ClientCertificate.PublicKey); - return context.Response.WriteAsync("hello world"); - }; + RequestDelegate app = context => + { + var tlsFeature = context.Features.Get(); + Assert.NotNull(tlsFeature); + Assert.NotNull(tlsFeature.ClientCertificate); + Assert.NotNull(context.Connection.ClientCertificate); + Assert.NotNull(context.Connection.ClientCertificate.PublicKey); + return context.Response.WriteAsync("hello world"); + }; using (var server = new TestServer(app, serviceContext, _serverAddress)) + { + // SslStream is used to ensure the certificate is actually passed to the server + // HttpClient might not send the certificate because it is invalid or it doesn't match any + // of the certificate authorities sent by the server in the SSL handshake. + using (var client = new TcpClient()) { - // SslStream is used to ensure the certificate is actually passed to the server - // HttpClient might not send the certificate because it is invalid or it doesn't match any - // of the certificate authorities sent by the server in the SSL handshake. - using (var client = new TcpClient()) - { var stream = await OpenSslStream(client, server); await stream.AuthenticateAsClientAsync("localhost", new X509CertificateCollection(), SslProtocols.Tls12 | SslProtocols.Tls11, false); await AssertConnectionResult(stream, true); @@ -418,8 +411,8 @@ namespace Microsoft.AspNetCore.Server.KestrelTests private static async Task OpenSslStream(TcpClient client, TestServer server, X509Certificate2 clientCertificate = null) { - await client.ConnectAsync("127.0.0.1", server.Port); - var stream = new SslStream(client.GetStream(), false, (sender, certificate, chain, errors) => true, + await client.ConnectAsync("127.0.0.1", server.Port); + var stream = new SslStream(client.GetStream(), false, (sender, certificate, chain, errors) => true, (sender, host, certificates, certificate, issuers) => clientCertificate ?? _x509Certificate2); return stream; @@ -427,15 +420,15 @@ namespace Microsoft.AspNetCore.Server.KestrelTests private static async Task AssertConnectionResult(SslStream stream, bool success) { - var request = Encoding.UTF8.GetBytes("GET / HTTP/1.0\r\n\r\n"); - await stream.WriteAsync(request, 0, request.Length); - var reader = new StreamReader(stream); + var request = Encoding.UTF8.GetBytes("GET / HTTP/1.0\r\n\r\n"); + await stream.WriteAsync(request, 0, request.Length); + var reader = new StreamReader(stream); string line = null; if (success) { line = await reader.ReadLineAsync(); - Assert.Equal("HTTP/1.1 200 OK", line); - } + Assert.Equal("HTTP/1.1 200 OK", line); + } else { try @@ -445,6 +438,17 @@ namespace Microsoft.AspNetCore.Server.KestrelTests catch (IOException) { } Assert.Null(line); } - } + } + + private HttpMessageHandler GetHandler() + { +#if NET451 + return new HttpClientHandler(); +#else + var handler = new WinHttpHandler(); + handler.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true; + return handler; +#endif } } +} From 8df6fbc5009a6963864f042d552f3c4fdea4f2d7 Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Thu, 26 May 2016 22:13:28 -0700 Subject: [PATCH 0748/1662] Fix Travis build on OSX. --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index 16c27f88b9..a3b3853ed7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,5 +17,7 @@ branches: - release - dev - /^(.*\/)?ci-.*$/ +before_install: + - if test "$TRAVIS_OS_NAME" == "osx"; then brew update; brew install openssl; brew link --force openssl; fi script: - ./build.sh --quiet verify From 69d8b17095a9d54a47198c1e8cfc42314fce0e05 Mon Sep 17 00:00:00 2001 From: Stephen Toub Date: Fri, 27 May 2016 10:28:24 -0400 Subject: [PATCH 0749/1662] Remove uses of ValueTask's implicit casts These are being removed. --- .../Http/MessageBody.cs | 8 ++++---- .../Http/SocketInputExtensions.cs | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/MessageBody.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/MessageBody.cs index 940196ff87..bd2a9ba2e5 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/MessageBody.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/MessageBody.cs @@ -175,7 +175,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http var limit = buffer.Array == null ? inputLengthLimit : Math.Min(buffer.Count, inputLengthLimit); if (limit == 0) { - return 0; + return new ValueTask(0); } var task = _context.SocketInput.ReadAsync(buffer.Array, buffer.Offset, limit); @@ -189,11 +189,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { _context.RejectRequest("Unexpected end of request content"); } - return actual; + return new ValueTask(actual); } else { - return ReadAsyncAwaited(task.AsTask()); + return new ValueTask(ReadAsyncAwaited(task.AsTask())); } } @@ -232,7 +232,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http public override ValueTask ReadAsyncImplementation(ArraySegment buffer, CancellationToken cancellationToken) { - return ReadStateMachineAsync(_context.SocketInput, buffer, cancellationToken); + return new ValueTask(ReadStateMachineAsync(_context.SocketInput, buffer, cancellationToken)); } private async Task ReadStateMachineAsync(SocketInput input, ArraySegment buffer, CancellationToken cancellationToken) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketInputExtensions.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketInputExtensions.cs index 9b647c4c91..7a74140435 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketInputExtensions.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketInputExtensions.cs @@ -21,15 +21,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if (actual != 0) { - return actual; + return new ValueTask(actual); } else if (fin) { - return 0; + return new ValueTask(0); } } - return input.ReadAsyncAwaited(buffer, offset, count); + return new ValueTask(input.ReadAsyncAwaited(buffer, offset, count)); } private static async Task ReadAsyncAwaited(this SocketInput input, byte[] buffer, int offset, int count) From 2453047fe2ff151c61fbef1aa3e15cd0411b026b Mon Sep 17 00:00:00 2001 From: Mike Harder Date: Fri, 27 May 2016 12:02:30 -0700 Subject: [PATCH 0750/1662] ServerAddress.FromUrl() should throw for invalid url (#875) --- .../KestrelServer.cs | 115 ++++++++---------- .../ServerAddress.cs | 2 +- .../KestrelServerTests.cs | 2 +- .../ServerAddressTests.cs | 4 +- 4 files changed, 58 insertions(+), 65 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServer.cs b/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServer.cs index 50b873c265..1770678b29 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServer.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServer.cs @@ -107,81 +107,74 @@ namespace Microsoft.AspNetCore.Server.Kestrel foreach (var address in _serverAddresses.Addresses.ToArray()) { var parsedAddress = ServerAddress.FromUrl(address); - if (parsedAddress == null) + atLeastOneListener = true; + + if (!parsedAddress.Host.Equals("localhost", StringComparison.OrdinalIgnoreCase)) { - throw new FormatException("Unrecognized listening address: " + address); + _disposables.Push(engine.CreateServer( + parsedAddress)); } else { - atLeastOneListener = true; - - if (!parsedAddress.Host.Equals("localhost", StringComparison.OrdinalIgnoreCase)) + if (parsedAddress.Port == 0) { - _disposables.Push(engine.CreateServer( - parsedAddress)); + throw new InvalidOperationException("Dynamic port binding is not supported when binding to localhost. You must either bind to 127.0.0.1:0 or [::1]:0, or both."); } - else + + var ipv4Address = parsedAddress.WithHost("127.0.0.1"); + var exceptions = new List(); + + try { - if (parsedAddress.Port == 0) + _disposables.Push(engine.CreateServer(ipv4Address)); + } + catch (AggregateException ex) + { + var uvException = ex.InnerException as UvException; + + if (uvException != null && uvException.StatusCode != Constants.EADDRINUSE) { - throw new InvalidOperationException("Dynamic port binding is not supported when binding to localhost. You must either bind to 127.0.0.1:0 or [::1]:0, or both."); + _logger.LogWarning(0, ex, $"Unable to bind to {parsedAddress.ToString()} on the IPv4 loopback interface."); + exceptions.Add(uvException); } - - var ipv4Address = parsedAddress.WithHost("127.0.0.1"); - var exceptions = new List(); - - try + else { - _disposables.Push(engine.CreateServer(ipv4Address)); - } - catch (AggregateException ex) - { - var uvException = ex.InnerException as UvException; - - if (uvException != null && uvException.StatusCode != Constants.EADDRINUSE) - { - _logger.LogWarning(0, ex, $"Unable to bind to {parsedAddress.ToString()} on the IPv4 loopback interface."); - exceptions.Add(uvException); - } - else - { - throw; - } - } - - var ipv6Address = parsedAddress.WithHost("[::1]"); - - try - { - _disposables.Push(engine.CreateServer(ipv6Address)); - } - catch (AggregateException ex) - { - var uvException = ex.InnerException as UvException; - - if (uvException != null && uvException.StatusCode != Constants.EADDRINUSE) - { - _logger.LogWarning(0, ex, $"Unable to bind to {parsedAddress.ToString()} on the IPv6 loopback interface."); - exceptions.Add(uvException); - } - else - { - throw; - } - } - - if (exceptions.Count == 2) - { - var ex = new AggregateException(exceptions); - _logger.LogError(0, ex, $"Unable to bind to {parsedAddress.ToString()} on any loopback interface."); - throw ex; + throw; } } - // If requested port was "0", replace with assigned dynamic port. - _serverAddresses.Addresses.Remove(address); - _serverAddresses.Addresses.Add(parsedAddress.ToString()); + var ipv6Address = parsedAddress.WithHost("[::1]"); + + try + { + _disposables.Push(engine.CreateServer(ipv6Address)); + } + catch (AggregateException ex) + { + var uvException = ex.InnerException as UvException; + + if (uvException != null && uvException.StatusCode != Constants.EADDRINUSE) + { + _logger.LogWarning(0, ex, $"Unable to bind to {parsedAddress.ToString()} on the IPv6 loopback interface."); + exceptions.Add(uvException); + } + else + { + throw; + } + } + + if (exceptions.Count == 2) + { + var ex = new AggregateException(exceptions); + _logger.LogError(0, ex, $"Unable to bind to {parsedAddress.ToString()} on any loopback interface."); + throw ex; + } } + + // If requested port was "0", replace with assigned dynamic port. + _serverAddresses.Addresses.Remove(address); + _serverAddresses.Addresses.Add(parsedAddress.ToString()); } if (!atLeastOneListener) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/ServerAddress.cs b/src/Microsoft.AspNetCore.Server.Kestrel/ServerAddress.cs index 528a39edb8..8f7b19c634 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/ServerAddress.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/ServerAddress.cs @@ -78,7 +78,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel int schemeDelimiterStart = url.IndexOf("://", StringComparison.Ordinal); if (schemeDelimiterStart < 0) { - return null; + throw new FormatException($"Invalid URL: {url}"); } int schemeDelimiterEnd = schemeDelimiterStart + "://".Length; diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerTests.cs index 7db58f52a6..f83e6bcc0a 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerTests.cs @@ -36,7 +36,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var exception = Assert.Throws(() => StartDummyApplication(server)); - Assert.Contains("Unrecognized listening address", exception.Message); + Assert.Contains("Invalid URL", exception.Message); } [Fact] diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/ServerAddressTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/ServerAddressTests.cs index 50c96cc9c4..9e113d7978 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/ServerAddressTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/ServerAddressTests.cs @@ -14,9 +14,9 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [InlineData("")] [InlineData("5000")] [InlineData("//noscheme")] - public void FromUriReturnsNullForSchemelessUrls(string url) + public void FromUriThrowsForSchemelessUrls(string url) { - Assert.Null(ServerAddress.FromUrl(url)); + Assert.Throws(() => ServerAddress.FromUrl(url)); } [Theory] From 80a2bc124d42b757b378661f693d208cf514dcb3 Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Thu, 26 May 2016 21:22:00 -0700 Subject: [PATCH 0751/1662] Remove Frame.RequestUri. --- src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs index 63ada04463..ad73c82d45 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs @@ -82,7 +82,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http public int LocalPort { get; set; } public string Scheme { get; set; } public string Method { get; set; } - public string RequestUri { get; set; } public string PathBase { get; set; } public string Path { get; set; } public string QueryString { get; set; } @@ -276,7 +275,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http Scheme = null; Method = null; - RequestUri = null; PathBase = null; Path = null; QueryString = null; @@ -914,7 +912,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http consumed = scan; Method = method; - RequestUri = requestUrlPath; QueryString = queryString; HttpVersion = httpVersion; From cea5fbbafa4f4e633d2e7c45044fc0dda1cf7088 Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Thu, 26 May 2016 21:46:47 -0700 Subject: [PATCH 0752/1662] Fix disabled tests in MultipleLoopTests. --- .../MultipleLoopTests.cs | 55 ++++++++++--------- 1 file changed, 30 insertions(+), 25 deletions(-) diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/MultipleLoopTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/MultipleLoopTests.cs index 1752f4f40f..c5a6f0ee10 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/MultipleLoopTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/MultipleLoopTests.cs @@ -1,5 +1,7 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + using System; -using System.Net; using System.Net.Sockets; using System.Runtime.InteropServices; using System.Threading; @@ -39,19 +41,22 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } - [Fact(Skip = "Test needs to be fixed (UvException: Error -4082 EBUSY resource busy or locked from loop_close)")] + [Fact] public void ServerPipeListenForConnections() { + const string pipeName = @"\\.\pipe\ServerPipeListenForConnections"; + var loop = new UvLoopHandle(_logger); var serverListenPipe = new UvPipeHandle(_logger); loop.Init(_uv); serverListenPipe.Init(loop, (a, b) => { }, false); - serverListenPipe.Bind(@"\\.\pipe\ServerPipeListenForConnections"); - serverListenPipe.Listen(128, (_1, status, error, _2) => + serverListenPipe.Bind(pipeName); + serverListenPipe.Listen(128, (backlog, status, error, state) => { var serverConnectionPipe = new UvPipeHandle(_logger); serverConnectionPipe.Init(loop, (a, b) => { }, true); + try { serverListenPipe.Accept(serverConnectionPipe); @@ -73,10 +78,10 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var end = new MemoryPoolIterator(block, block.Data.Count); writeRequest.Write( serverConnectionPipe, - start, + start, end, 1, - (_3, status2, error2, _4) => + (handle, status2, error2, state2) => { writeRequest.Dispose(); serverConnectionPipe.Dispose(); @@ -85,7 +90,6 @@ namespace Microsoft.AspNetCore.Server.KestrelTests pool.Dispose(); }, null); - }, null); var worker = new Thread(() => @@ -97,16 +101,16 @@ namespace Microsoft.AspNetCore.Server.KestrelTests loop2.Init(_uv); clientConnectionPipe.Init(loop2, (a, b) => { }, true); connect.Init(loop2); - connect.Connect(clientConnectionPipe, @"\\.\pipe\ServerPipeListenForConnections", (_1, status, error, _2) => + connect.Connect(clientConnectionPipe, pipeName, (handle, status, error, state) => { var buf = loop2.Libuv.buf_init(Marshal.AllocHGlobal(8192), 8192); - connect.Dispose(); + clientConnectionPipe.ReadStart( - (_3, cb, _4) => buf, - (_3, status2, _4) => + (handle2, cb, state2) => buf, + (handle2, status2, state2) => { - if (status2 == 0) + if (status2 == Constants.EOF) { clientConnectionPipe.Dispose(); } @@ -122,8 +126,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests worker.Join(); } - - [Fact(Skip = "Test needs to be fixed (UvException: Error -4088 EAGAIN resource temporarily unavailable from accept)")] + [Fact] public void ServerPipeDispatchConnections() { var pipeName = @"\\.\pipe\ServerPipeDispatchConnections" + Guid.NewGuid().ToString("n"); @@ -138,10 +141,11 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var serverListenPipe = new UvPipeHandle(_logger); serverListenPipe.Init(loop, (a, b) => { }, false); serverListenPipe.Bind(pipeName); - serverListenPipe.Listen(128, (_1, status, error, _2) => + serverListenPipe.Listen(128, (handle, status, error, state) => { serverConnectionPipe = new UvPipeHandle(_logger); serverConnectionPipe.Init(loop, (a, b) => { }, true); + try { serverListenPipe.Accept(serverConnectionPipe); @@ -160,7 +164,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var address = ServerAddress.FromUrl($"http://127.0.0.1:0/"); serverListenTcp.Bind(address); var port = serverListenTcp.GetSockIPEndPoint().Port; - serverListenTcp.Listen(128, (_1, status, error, _2) => + serverListenTcp.Listen(128, (handle, status, error, state) => { var serverConnectionTcp = new UvTcpHandle(_logger); serverConnectionTcp.Init(loop, (a, b) => { }); @@ -174,7 +178,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests serverConnectionPipe, new ArraySegment>(new ArraySegment[] { new ArraySegment(new byte[] { 1, 2, 3, 4 }) }), serverConnectionTcp, - (_3, status2, error2, _4) => + (handle2, status2, error2, state2) => { writeRequest.Dispose(); serverConnectionTcp.Dispose(); @@ -195,7 +199,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests loop2.Init(_uv); clientConnectionPipe.Init(loop2, (a, b) => { }, true); connect.Init(loop2); - connect.Connect(clientConnectionPipe, pipeName, (_1, status, error, _2) => + connect.Connect(clientConnectionPipe, pipeName, (handle, status, error, state) => { connect.Dispose(); @@ -204,23 +208,24 @@ namespace Microsoft.AspNetCore.Server.KestrelTests serverConnectionTcpDisposedEvent.WaitOne(); clientConnectionPipe.ReadStart( - (_3, cb, _4) => buf, - (_3, status2, _4) => + (handle2, cb, state2) => buf, + (handle2, status2, state2) => { - if (status2 == 0) + if (status2 == Constants.EOF) { clientConnectionPipe.Dispose(); return; } + var clientConnectionTcp = new UvTcpHandle(_logger); clientConnectionTcp.Init(loop2, (a, b) => { }); clientConnectionPipe.Accept(clientConnectionTcp); var buf2 = loop2.Libuv.buf_init(Marshal.AllocHGlobal(64), 64); clientConnectionTcp.ReadStart( - (_5, cb, _6) => buf2, - (_5, status3, _6) => + (handle3, cb, state3) => buf2, + (handle3, status3, state3) => { - if (status3 == 0) + if (status3 == Constants.EOF) { clientConnectionTcp.Dispose(); } @@ -245,7 +250,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var cb = socket.Receive(new byte[64]); socket.Dispose(); } - catch(Exception ex) + catch (Exception ex) { Console.WriteLine(ex); } From 6d3a416f0eed0962e682f9aea9d247e75c425ce5 Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Thu, 26 May 2016 20:34:46 -0700 Subject: [PATCH 0753/1662] Test code nitpicks. --- .../BadHttpRequestTests.cs | 5 +- .../EngineTests.cs | 3 +- .../HttpsConnectionFilterTests.cs | 59 +++++++------------ .../TestHelpers/MockFrameControl.cs | 5 +- .../TestHelpers/MockSocketOuptut.cs | 2 +- .../TestInput.cs | 4 +- 6 files changed, 33 insertions(+), 45 deletions(-) diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/BadHttpRequestTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/BadHttpRequestTests.cs index a239e7102c..7b750066ac 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/BadHttpRequestTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/BadHttpRequestTests.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Threading.Tasks; +using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; using Xunit; namespace Microsoft.AspNetCore.Server.KestrelTests @@ -68,7 +69,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [InlineData("GET / HTTP/1.0\rA")] public async Task TestBadRequestLines(string request) { - using (var server = new TestServer(context => { return Task.FromResult(0); })) + using (var server = new TestServer(context => TaskUtilities.CompletedTask)) { using (var connection = server.CreateConnection()) { @@ -85,7 +86,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [InlineData("GET / HTTP/1.0\rA")] public async Task ServerClosesConnectionAsSoonAsBadRequestLineIsDetected(string request) { - using (var server = new TestServer(context => { return Task.FromResult(0); })) + using (var server = new TestServer(context => TaskUtilities.CompletedTask)) { using (var connection = server.CreateConnection()) { diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs index a611f8305b..1ff2116bb7 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs @@ -11,6 +11,7 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Server.Kestrel; +using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; using Xunit; namespace Microsoft.AspNetCore.Server.KestrelTests @@ -1062,7 +1063,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests using (var server = new TestServer(httpContext => { httpContext.Abort(); - return Task.FromResult(0); + return TaskUtilities.CompletedTask; }, testContext)) { using (var connection = server.CreateConnection()) diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/HttpsConnectionFilterTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/HttpsConnectionFilterTests.cs index 894fc37b3e..0d5113ab5b 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/HttpsConnectionFilterTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/HttpsConnectionFilterTests.cs @@ -16,6 +16,7 @@ using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Server.Kestrel.Filter; using Microsoft.AspNetCore.Server.Kestrel.Https; +using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; using Microsoft.AspNetCore.Testing.xunit; using Xunit; @@ -116,13 +117,12 @@ namespace Microsoft.AspNetCore.Server.KestrelTests new NoOpConnectionFilter()) ); - RequestDelegate app = context => - { - Assert.Equal(context.Features.Get(), null); - return context.Response.WriteAsync("hello world"); - }; - - using (var server = new TestServer(app, serviceContext, _serverAddress)) + using (var server = new TestServer(context => + { + Assert.Equal(context.Features.Get(), null); + return context.Response.WriteAsync("hello world"); + }, + serviceContext, _serverAddress)) { using (var client = new HttpClient(GetHandler())) { @@ -153,8 +153,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests new NoOpConnectionFilter()) ); - RequestDelegate app = context => Task.FromResult(0); - using (var server = new TestServer(app, serviceContext, _serverAddress)) + using (var server = new TestServer(context => TaskUtilities.CompletedTask, serviceContext, _serverAddress)) { using (var client = new TcpClient()) { @@ -182,16 +181,15 @@ namespace Microsoft.AspNetCore.Server.KestrelTests new NoOpConnectionFilter()) ); - RequestDelegate app = context => - { - var tlsFeature = context.Features.Get(); - Assert.NotNull(tlsFeature); - Assert.NotNull(tlsFeature.ClientCertificate); - Assert.NotNull(context.Connection.ClientCertificate); - return context.Response.WriteAsync("hello world"); - }; - - using (var server = new TestServer(app, serviceContext, _serverAddress)) + using (var server = new TestServer(context => + { + var tlsFeature = context.Features.Get(); + Assert.NotNull(tlsFeature); + Assert.NotNull(tlsFeature.ClientCertificate); + Assert.NotNull(context.Connection.ClientCertificate); + return context.Response.WriteAsync("hello world"); + }, + serviceContext, _serverAddress)) { using (var client = new TcpClient()) { @@ -219,9 +217,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests new NoOpConnectionFilter()) ); - RequestDelegate app = context => context.Response.WriteAsync(context.Request.Scheme); - - using (var server = new TestServer(app, serviceContext, _serverAddress)) + using (var server = new TestServer(context => context.Response.WriteAsync(context.Request.Scheme), serviceContext, _serverAddress)) { using (var client = new HttpClient(GetHandler())) { @@ -245,12 +241,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests new NoOpConnectionFilter()) ); - RequestDelegate app = context => - { - return context.Response.WriteAsync("hello world"); - }; - - using (var server = new TestServer(app, serviceContext, _serverAddress)) + using (var server = new TestServer(context => context.Response.WriteAsync("hello world"), serviceContext, _serverAddress)) { // SslStream is used to ensure the certificate is actually passed to the server // HttpClient might not send the certificate because it is invalid or it doesn't match any @@ -286,9 +277,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests new NoOpConnectionFilter()) ); - RequestDelegate app = context => Task.FromResult(0); - - using (var server = new TestServer(app, serviceContext, _serverAddress)) + using (var server = new TestServer(context => TaskUtilities.CompletedTask, serviceContext, _serverAddress)) { using (var client = new TcpClient()) { @@ -315,9 +304,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests new NoOpConnectionFilter()) ); - RequestDelegate app = context => Task.FromResult(0); - - using (var server = new TestServer(app, serviceContext, _serverAddress)) + using (var server = new TestServer(context => TaskUtilities.CompletedTask, serviceContext, _serverAddress)) { using (var client = new TcpClient()) { @@ -342,9 +329,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests new NoOpConnectionFilter()) ); - RequestDelegate app = context => Task.FromResult(0); - - using (var server = new TestServer(app, serviceContext, _serverAddress)) + using (var server = new TestServer(context => TaskUtilities.CompletedTask, serviceContext, _serverAddress)) { using (var client = new TcpClient()) { diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockFrameControl.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockFrameControl.cs index d6d0596b02..0f5faf7148 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockFrameControl.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockFrameControl.cs @@ -5,6 +5,7 @@ using System; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Http; +using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; namespace Microsoft.AspNetCore.Server.KestrelTests.TestHelpers { @@ -16,7 +17,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests.TestHelpers public Task FlushAsync(CancellationToken cancellationToken) { - return Task.FromResult(0); + return TaskUtilities.CompletedTask; } public void ProduceContinue() @@ -29,7 +30,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests.TestHelpers public Task WriteAsync(ArraySegment data, CancellationToken cancellationToken) { - return Task.FromResult(0); + return TaskUtilities.CompletedTask; } } } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockSocketOuptut.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockSocketOuptut.cs index 051074c7d8..8a516c4174 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockSocketOuptut.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockSocketOuptut.cs @@ -26,7 +26,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests.TestHelpers public Task WriteAsync(ArraySegment buffer, bool chunk = false, CancellationToken cancellationToken = default(CancellationToken)) { - return Task.FromResult(0); + return TaskUtilities.CompletedTask; } } } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestInput.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/TestInput.cs index d841e180f7..4c73c043b0 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/TestInput.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/TestInput.cs @@ -76,7 +76,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests Task IFrameControl.WriteAsync(ArraySegment data, CancellationToken cancellationToken) { - return Task.FromResult(0); + return TaskUtilities.CompletedTask; } void IFrameControl.Flush() @@ -85,7 +85,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests Task IFrameControl.FlushAsync(CancellationToken cancellationToken) { - return Task.FromResult(0); + return TaskUtilities.CompletedTask; } public void Dispose() From 0a181b1f3f38a35a9bd30df04171cbc0a814322f Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Thu, 26 May 2016 21:07:42 -0700 Subject: [PATCH 0754/1662] Reset Frame's IHttpRequestFeature.Headers and IHttpResponseFeature.Headers between requests (#879). --- .../Http/Frame.cs | 11 ++- .../EngineTests.cs | 98 ++++++++++++++++++- .../FrameTests.cs | 47 +++++++++ 3 files changed, 148 insertions(+), 8 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs index ad73c82d45..df750a344a 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs @@ -11,7 +11,6 @@ using System.Text; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Exceptions; using Microsoft.Extensions.Logging; @@ -217,13 +216,17 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (FrameRequestHeaders == null) { - RequestHeaders = FrameRequestHeaders = new FrameRequestHeaders(); + FrameRequestHeaders = new FrameRequestHeaders(); } + RequestHeaders = FrameRequestHeaders; + if (FrameResponseHeaders == null) { - ResponseHeaders = FrameResponseHeaders = new FrameResponseHeaders(); + FrameResponseHeaders = new FrameResponseHeaders(); } + + ResponseHeaders = FrameResponseHeaders; } public void InitializeStreams(MessageBody messageBody) @@ -646,8 +649,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { responseHeaders.SetRawServer(Constants.ServerName, _bytesServer); } - - ResponseHeaders = responseHeaders; } if (!HasResponseStarted) diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs index 1ff2116bb7..d90c38ad6c 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs @@ -11,6 +11,7 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Server.Kestrel; +using Microsoft.AspNetCore.Server.Kestrel.Http; using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; using Xunit; @@ -1057,9 +1058,6 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [MemberData(nameof(ConnectionFilterData))] public async Task NoResponseSentWhenConnectionIsClosedByServerBeforeClientFinishesSendingRequest(TestServiceContext testContext) { - var testLogger = new TestApplicationErrorLogger(); - testContext.Log = new KestrelTrace(testLogger); - using (var server = new TestServer(httpContext => { httpContext.Abort(); @@ -1077,5 +1075,99 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } } } + + [Theory] + [MemberData(nameof(ConnectionFilterData))] + public async Task RequestHeadersAreResetOnEachRequest(TestServiceContext testContext) + { + IHeaderDictionary originalRequestHeaders = null; + var firstRequest = true; + + using (var server = new TestServer(httpContext => + { + var requestFeature = httpContext.Features.Get(); + + if (firstRequest) + { + originalRequestHeaders = requestFeature.Headers; + requestFeature.Headers = new FrameRequestHeaders(); + firstRequest = false; + } + else + { + Assert.Same(originalRequestHeaders, requestFeature.Headers); + } + + return TaskUtilities.CompletedTask; + }, testContext)) + { + using (var connection = server.CreateConnection()) + { + await connection.SendEnd( + "GET / HTTP/1.1", + "", + "GET / HTTP/1.1", + "", + ""); + await connection.ReceiveEnd( + "HTTP/1.1 200 OK", + $"Date: {testContext.DateHeaderValue}", + "Content-Length: 0", + "", + "HTTP/1.1 200 OK", + $"Date: {testContext.DateHeaderValue}", + "Content-Length: 0", + "", + ""); + } + } + } + + [Theory] + [MemberData(nameof(ConnectionFilterData))] + public async Task ResponseHeadersAreResetOnEachRequest(TestServiceContext testContext) + { + IHeaderDictionary originalResponseHeaders = null; + var firstRequest = true; + + using (var server = new TestServer(httpContext => + { + var responseFeature = httpContext.Features.Get(); + + if (firstRequest) + { + originalResponseHeaders = responseFeature.Headers; + responseFeature.Headers = new FrameResponseHeaders(); + firstRequest = false; + } + else + { + Assert.Same(originalResponseHeaders, responseFeature.Headers); + } + + return TaskUtilities.CompletedTask; + }, testContext)) + { + using (var connection = server.CreateConnection()) + { + await connection.SendEnd( + "GET / HTTP/1.1", + "", + "GET / HTTP/1.1", + "", + ""); + await connection.ReceiveEnd( + "HTTP/1.1 200 OK", + $"Date: {testContext.DateHeaderValue}", + "Content-Length: 0", + "", + "HTTP/1.1 200 OK", + $"Date: {testContext.DateHeaderValue}", + "Content-Length: 0", + "", + ""); + } + } + } } } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs index 809dde54ab..5146a9040e 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs @@ -4,6 +4,7 @@ using System; using System.Linq; using System.Text; +using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Server.Kestrel; using Microsoft.AspNetCore.Server.Kestrel.Http; @@ -115,5 +116,51 @@ namespace Microsoft.AspNetCore.Server.KestrelTests Assert.True(frame.HasResponseStarted); Assert.Throws(() => ((IHttpResponseFeature)frame).ReasonPhrase = "Reason phrase"); } + + [Fact] + public void InitializeHeadersResetsRequestHeaders() + { + // Arrange + var connectionContext = new ConnectionContext() + { + DateHeaderValueManager = new DateHeaderValueManager(), + ServerAddress = ServerAddress.FromUrl("http://localhost:5000"), + ServerOptions = new KestrelServerOptions(), + SocketOutput = new MockSocketOuptut() + }; + var frame = new Frame(application: null, context: connectionContext); + frame.InitializeHeaders(); + + // Act + var originalRequestHeaders = frame.RequestHeaders; + frame.RequestHeaders = new FrameRequestHeaders(); + frame.InitializeHeaders(); + + // Assert + Assert.Same(originalRequestHeaders, frame.RequestHeaders); + } + + [Fact] + public void InitializeHeadersResetsResponseHeaders() + { + // Arrange + var connectionContext = new ConnectionContext() + { + DateHeaderValueManager = new DateHeaderValueManager(), + ServerAddress = ServerAddress.FromUrl("http://localhost:5000"), + ServerOptions = new KestrelServerOptions(), + SocketOutput = new MockSocketOuptut() + }; + var frame = new Frame(application: null, context: connectionContext); + frame.InitializeHeaders(); + + // Act + var originalResponseHeaders = frame.ResponseHeaders; + frame.ResponseHeaders = new FrameResponseHeaders(); + frame.InitializeHeaders(); + + // Assert + Assert.Same(originalResponseHeaders, frame.ResponseHeaders); + } } } From 50e140da4330a1ede82c3bae2efd6b3f22a0c105 Mon Sep 17 00:00:00 2001 From: John Luo Date: Fri, 27 May 2016 17:51:51 -0700 Subject: [PATCH 0755/1662] React to update CoreCLR packages https://github.com/aspnet/Coherence/issues/97 --- .../project.json | 2 +- test/Microsoft.AspNetCore.Server.KestrelTests/project.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json index 35ae2f4011..d95ae5926c 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json @@ -17,7 +17,7 @@ "version": "1.0.0-*", "type": "platform" }, - "System.Net.Http": "4.0.1-*", + "System.Net.Http": "4.1.0-*", "System.Net.Http.WinHttpHandler": "4.0.0-*", "System.Runtime.Serialization.Primitives": "4.1.1-*" }, diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/project.json b/test/Microsoft.AspNetCore.Server.KestrelTests/project.json index 6bb0db82a1..3f64d5ae48 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/project.json +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/project.json @@ -18,7 +18,7 @@ "System.Diagnostics.TraceSource": "4.0.0-*", "System.Globalization.Extensions": "4.0.1-*", "System.IO": "4.1.0-*", - "System.Net.Http": "4.0.1-*", + "System.Net.Http": "4.1.0-*", "System.Net.Http.WinHttpHandler": "4.0.0-*", "System.Net.Sockets": "4.1.0-*", "System.Runtime.Handles": "4.0.1-*" From 6b25ee73432dca85b7de7dc97377733e0318b0a2 Mon Sep 17 00:00:00 2001 From: BrennanConroy Date: Fri, 27 May 2016 11:02:20 -0700 Subject: [PATCH 0756/1662] Replace PlatformAbstractions with RuntimeInformation --- .../Infrastructure/Constants.cs | 42 ++++++++++--------- .../Networking/PlatformApis.cs | 12 ------ .../project.json | 4 +- 3 files changed, 25 insertions(+), 33 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/Constants.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/Constants.cs index de6294fee4..bbe6442f87 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/Constants.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/Constants.cs @@ -1,7 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using Microsoft.Extensions.PlatformAbstractions; +using System.Runtime.InteropServices; namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure { @@ -28,32 +28,36 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure private static int? GetECONNRESET() { - switch (PlatformServices.Default.Runtime.OperatingSystemPlatform) + if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { - case Platform.Windows: - return -4077; - case Platform.Linux: - return -104; - case Platform.Darwin: - return -54; - default: - return null; + return -4077; } + else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) + { + return -104; + } + else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) + { + return -54; + } + return null; } private static int? GetEADDRINUSE() { - switch (PlatformServices.Default.Runtime.OperatingSystemPlatform) + if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { - case Platform.Windows: - return -4091; - case Platform.Linux: - return -98; - case Platform.Darwin: - return -48; - default: - return null; + return -4091; } + else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) + { + return -98; + } + else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) + { + return -48; + } + return null; } } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Networking/PlatformApis.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Networking/PlatformApis.cs index f485665bf9..17985da608 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Networking/PlatformApis.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Networking/PlatformApis.cs @@ -3,7 +3,6 @@ using System; using System.Runtime.InteropServices; -using Microsoft.Extensions.PlatformAbstractions; namespace Microsoft.AspNetCore.Server.Kestrel.Networking { @@ -11,19 +10,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Networking { static PlatformApis() { -#if NETSTANDARD1_3 IsWindows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows); IsDarwin = RuntimeInformation.IsOSPlatform(OSPlatform.OSX); -#else - var p = (int)Environment.OSVersion.Platform; - IsWindows = (p != 4) && (p != 6) && (p != 128); - - if (!IsWindows) - { - // When running on Mono in Darwin OSVersion doesn't return Darwin. It returns Unix instead. - IsDarwin = PlatformServices.Default.Runtime.OperatingSystemPlatform == Platform.Darwin; - } -#endif } public static bool IsWindows { get; } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/project.json b/src/Microsoft.AspNetCore.Server.Kestrel/project.json index 4d875358f5..f6aeb0f17b 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/project.json +++ b/src/Microsoft.AspNetCore.Server.Kestrel/project.json @@ -14,11 +14,11 @@ "dependencies": { "System.Buffers": "4.0.0-*", "System.Numerics.Vectors": "4.1.1-*", + "System.Runtime.InteropServices.RuntimeInformation": "4.0.0-*", "System.Threading.Tasks.Extensions": "4.0.0-*", "Libuv": "1.9.0-*", "Microsoft.AspNetCore.Hosting": "1.0.0-*", - "Microsoft.Extensions.Logging.Abstractions": "1.0.0-*", - "Microsoft.Extensions.PlatformAbstractions": "1.0.0-*" + "Microsoft.Extensions.Logging.Abstractions": "1.0.0-*" }, "frameworks": { "net451": { From 306084356eec18176bb7c9eaa1b0666a77d2ccd5 Mon Sep 17 00:00:00 2001 From: Mike Harder Date: Tue, 31 May 2016 11:54:38 -0700 Subject: [PATCH 0757/1662] ServerAddress.FromUrl() should throw if Host is missing (#860) --- .../ServerAddress.cs | 5 +++++ .../ServerAddressTests.cs | 18 +++++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/ServerAddress.cs b/src/Microsoft.AspNetCore.Server.Kestrel/ServerAddress.cs index 8f7b19c634..4dd7ffb0cf 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/ServerAddress.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/ServerAddress.cs @@ -141,6 +141,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel serverAddress.Host = url.Substring(schemeDelimiterEnd, pathDelimiterStart - schemeDelimiterEnd); } + if (string.IsNullOrEmpty(serverAddress.Host)) + { + throw new FormatException($"Invalid URL: {url}"); + } + // Path should not end with a / since it will be used as PathBase later if (url[url.Length - 1] == '/') { diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/ServerAddressTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/ServerAddressTests.cs index 9e113d7978..f38ec1d367 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/ServerAddressTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/ServerAddressTests.cs @@ -14,13 +14,29 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [InlineData("")] [InlineData("5000")] [InlineData("//noscheme")] - public void FromUriThrowsForSchemelessUrls(string url) + public void FromUriThrowsForUrlsWithoutSchemeDelimiter(string url) + { + Assert.Throws(() => ServerAddress.FromUrl(url)); + } + + [Theory] + [InlineData("://")] + [InlineData("://:5000")] + [InlineData("http://")] + [InlineData("http://:5000")] + [InlineData("http:///")] + [InlineData("http:///:5000")] + [InlineData("http:////")] + [InlineData("http:////:5000")] + public void FromUriThrowsForUrlsWithoutHost(string url) { Assert.Throws(() => ServerAddress.FromUrl(url)); } [Theory] [InlineData("://emptyscheme", "", "emptyscheme", 0, "", "://emptyscheme:0")] + [InlineData("http://+", "http", "+", 80, "", "http://+:80")] + [InlineData("http://*", "http", "*", 80, "", "http://*:80")] [InlineData("http://localhost", "http", "localhost", 80, "", "http://localhost:80")] [InlineData("http://www.example.com", "http", "www.example.com", 80, "", "http://www.example.com:80")] [InlineData("https://www.example.com", "https", "www.example.com", 443, "", "https://www.example.com:443")] From 290e1e3f3f11f7077b0386528b7a0dfd48bab1f5 Mon Sep 17 00:00:00 2001 From: Andrew Stanton-Nurse Date: Fri, 27 May 2016 10:44:02 -0700 Subject: [PATCH 0758/1662] improve validation of HTTP methods --- .../Http/Frame.cs | 36 +++++++++++++++ .../BadHttpRequestTests.cs | 44 ++++++++++++++++++- .../TestConnection.cs | 15 +++++++ 3 files changed, 93 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs index df750a344a..c9f77bc273 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs @@ -807,10 +807,21 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } method = begin.GetAsciiString(scan); + if (method == null) { RejectRequest("Missing method."); } + + // Note: We're not in the fast path any more (GetKnownMethod should have handled any HTTP Method we're aware of) + // So we can be a tiny bit slower and more careful here. + for (int i = 0; i < method.Length; i++) + { + if (!IsValidTokenChar(method[i])) + { + RejectRequest("Invalid method."); + } + } } else { @@ -938,6 +949,31 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } + private static bool IsValidTokenChar(char c) + { + // Determines if a character is valid as a 'token' as defined in the + // HTTP spec: https://tools.ietf.org/html/rfc7230#section-3.2.6 + return + (c >= '0' && c <= '9') || + (c >= 'A' && c <= 'Z') || + (c >= 'a' && c <= 'z') || + c == '!' || + c == '#' || + c == '$' || + c == '%' || + c == '&' || + c == '\'' || + c == '*' || + c == '+' || + c == '-' || + c == '.' || + c == '^' || + c == '_' || + c == '`' || + c == '|' || + c == '~'; + } + private bool RequestUrlStartsWithPathBase(string requestUrl, out bool caseMatches) { caseMatches = true; diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/BadHttpRequestTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/BadHttpRequestTests.cs index 7b750066ac..e8baf36f10 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/BadHttpRequestTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/BadHttpRequestTests.cs @@ -45,7 +45,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests // Missing method [InlineData(" ")] // Missing second space - [InlineData("/ HTTP/1.1\r\n\r\n")] + [InlineData("/ ")] // This fails trying to read the '/' because that's invalid for an HTTP method [InlineData("GET /\r\n")] // Missing target [InlineData("GET ")] @@ -67,13 +67,33 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [InlineData("GET / 8charact\r")] // Missing LF [InlineData("GET / HTTP/1.0\rA")] + // Bad HTTP Methods (invalid according to RFC) + [InlineData("( / HTTP/1.0\r\n")] + [InlineData(") / HTTP/1.0\r\n")] + [InlineData("< / HTTP/1.0\r\n")] + [InlineData("> / HTTP/1.0\r\n")] + [InlineData("@ / HTTP/1.0\r\n")] + [InlineData(", / HTTP/1.0\r\n")] + [InlineData("; / HTTP/1.0\r\n")] + [InlineData(": / HTTP/1.0\r\n")] + [InlineData("\\ / HTTP/1.0\r\n")] + [InlineData("\" / HTTP/1.0\r\n")] + [InlineData("/ / HTTP/1.0\r\n")] + [InlineData("[ / HTTP/1.0\r\n")] + [InlineData("] / HTTP/1.0\r\n")] + [InlineData("? / HTTP/1.0\r\n")] + [InlineData("= / HTTP/1.0\r\n")] + [InlineData("{ / HTTP/1.0\r\n")] + [InlineData("} / HTTP/1.0\r\n")] + [InlineData("get@ / HTTP/1.0\r\n")] + [InlineData("post= / HTTP/1.0\r\n")] public async Task TestBadRequestLines(string request) { using (var server = new TestServer(context => TaskUtilities.CompletedTask)) { using (var connection = server.CreateConnection()) { - await connection.SendEnd(request); + await connection.SendAllEnd(request); await ReceiveBadRequestResponse(connection); } } @@ -84,6 +104,26 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [InlineData("GET ")] [InlineData("GET / HTTP/1.2\r")] [InlineData("GET / HTTP/1.0\rA")] + // Bad HTTP Methods (invalid according to RFC) + [InlineData("( ")] + [InlineData(") ")] + [InlineData("< ")] + [InlineData("> ")] + [InlineData("@ ")] + [InlineData(", ")] + [InlineData("; ")] + [InlineData(": ")] + [InlineData("\\ ")] + [InlineData("\" ")] + [InlineData("/ ")] + [InlineData("[ ")] + [InlineData("] ")] + [InlineData("? ")] + [InlineData("= ")] + [InlineData("{ ")] + [InlineData("} ")] + [InlineData("get@ ")] + [InlineData("post= ")] public async Task ServerClosesConnectionAsSoonAsBadRequestLineIsDetected(string request) { using (var server = new TestServer(context => TaskUtilities.CompletedTask)) diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestConnection.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/TestConnection.cs index f9974bef04..39cefb305f 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/TestConnection.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/TestConnection.cs @@ -43,6 +43,21 @@ namespace Microsoft.AspNetCore.Server.KestrelTests _socket.Dispose(); } + public async Task SendAll(params string[] lines) + { + var text = String.Join("\r\n", lines); + var writer = new StreamWriter(_stream, Encoding.ASCII); + await writer.WriteAsync(text); + writer.Flush(); + _stream.Flush(); + } + + public async Task SendAllEnd(params string[] lines) + { + await SendAll(lines); + _socket.Shutdown(SocketShutdown.Send); + } + public async Task Send(params string[] lines) { var text = String.Join("\r\n", lines); From 50208a3a79a2171ef03eea85e9c779af4916bca9 Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Wed, 25 May 2016 15:55:07 -0700 Subject: [PATCH 0759/1662] Implement IHttpRequestFeature.RawTarget (aspnet/HttpAbstractions#596). --- .../Http/Frame.FeatureCollection.cs | 12 ++ .../Http/Frame.cs | 48 +++++-- .../RequestTests.cs | 46 ------ .../TestConnection.cs | 35 ----- .../RequestTargetProcessingTests.cs | 131 ++++++++++++++++++ 5 files changed, 183 insertions(+), 89 deletions(-) delete mode 100644 test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/TestConnection.cs create mode 100644 test/Microsoft.AspNetCore.Server.KestrelTests/RequestTargetProcessingTests.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.FeatureCollection.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.FeatureCollection.cs index fbd2c43cde..dc452096c3 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.FeatureCollection.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.FeatureCollection.cs @@ -152,6 +152,18 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } + string IHttpRequestFeature.RawTarget + { + get + { + return RawTarget; + } + set + { + RawTarget = value; + } + } + IHeaderDictionary IHttpRequestFeature.Headers { get diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs index c9f77bc273..7868964958 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs @@ -84,6 +84,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http public string PathBase { get; set; } public string Path { get; set; } public string QueryString { get; set; } + public string RawTarget { get; set; } public string HttpVersion { get @@ -860,6 +861,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http queryString = begin.GetAsciiString(scan); } + var queryEnd = scan; + if (pathBegin.Peek() == ' ') { RejectRequest("Missing request target."); @@ -907,8 +910,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http // Multibyte Internationalized Resource Identifiers (IRIs) are first converted to utf8; // then encoded/escaped to ASCII https://www.ietf.org/rfc/rfc3987.txt "Mapping of IRIs to URIs" string requestUrlPath; + string rawTarget; if (needDecode) { + // Read raw target before mutating memory. + rawTarget = pathBegin.GetAsciiString(queryEnd); + // URI was encoded, unescape and then parse as utf8 pathEnd = UrlPathDecoder.Unescape(pathBegin, pathEnd); requestUrlPath = pathBegin.GetUtf8String(pathEnd); @@ -918,27 +925,42 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { // URI wasn't encoded, parse as ASCII requestUrlPath = pathBegin.GetAsciiString(pathEnd); + + if (queryString.Length == 0) + { + // No need to allocate an extra string if the path didn't need + // decoding and there's no query string following it. + rawTarget = requestUrlPath; + } + else + { + rawTarget = pathBegin.GetAsciiString(queryEnd); + } } - requestUrlPath = PathNormalizer.RemoveDotSegments(requestUrlPath); + var normalizedTarget = PathNormalizer.RemoveDotSegments(requestUrlPath); consumed = scan; Method = method; QueryString = queryString; + RawTarget = rawTarget; HttpVersion = httpVersion; bool caseMatches; - - if (!string.IsNullOrEmpty(_pathBase) && - (requestUrlPath.Length == _pathBase.Length || (requestUrlPath.Length > _pathBase.Length && requestUrlPath[_pathBase.Length] == '/')) && - RequestUrlStartsWithPathBase(requestUrlPath, out caseMatches)) + if (RequestUrlStartsWithPathBase(normalizedTarget, out caseMatches)) { - PathBase = caseMatches ? _pathBase : requestUrlPath.Substring(0, _pathBase.Length); - Path = requestUrlPath.Substring(_pathBase.Length); + PathBase = caseMatches ? _pathBase : normalizedTarget.Substring(0, _pathBase.Length); + Path = normalizedTarget.Substring(_pathBase.Length); + } + else if (rawTarget[0] == '/') // check rawTarget since normalizedTarget can be "" or "/" after dot segment removal + { + Path = normalizedTarget; } else { - Path = requestUrlPath; + Path = string.Empty; + PathBase = string.Empty; + QueryString = string.Empty; } return RequestLineStatus.Done; @@ -978,6 +1000,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { caseMatches = true; + if (string.IsNullOrEmpty(_pathBase)) + { + return false; + } + + if (requestUrl.Length < _pathBase.Length || (requestUrl.Length > _pathBase.Length && requestUrl[_pathBase.Length] != '/')) + { + return false; + } + for (var i = 0; i < _pathBase.Length; i++) { if (requestUrl[i] != _pathBase[i]) diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs index 3ec8eead7d..6f4f3a2d45 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs @@ -4,8 +4,6 @@ using System; using System.Globalization; using System.Net.Http; -using System.Net.Sockets; -using System.Text; using System.Threading.Tasks; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; @@ -158,50 +156,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } } - [Fact] - public void RequestPathIsNormalized() - { - var builder = new WebHostBuilder() - .UseKestrel() - .UseUrls($"http://127.0.0.1:0/\u0041\u030A") - .Configure(app => - { - app.Run(async context => - { - var connection = context.Connection; - Assert.Equal("/\u00C5", context.Request.PathBase.Value); - Assert.Equal("/B/\u00C5", context.Request.Path.Value); - await context.Response.WriteAsync("hello, world"); - }); - }); - - using (var host = builder.Build()) - { - host.Start(); - - using (var socket = TestConnection.CreateConnectedLoopbackSocket(host.GetPort())) - { - socket.Send(Encoding.ASCII.GetBytes("GET /%41%CC%8A/A/../B/%41%CC%8A HTTP/1.1\r\n\r\n")); - socket.Shutdown(SocketShutdown.Send); - - var response = new StringBuilder(); - var buffer = new byte[4096]; - while (true) - { - var length = socket.Receive(buffer); - if (length == 0) - { - break; - } - - response.Append(Encoding.ASCII.GetString(buffer, 0, length)); - } - - Assert.StartsWith("HTTP/1.1 200 OK", response.ToString()); - } - } - } - private async Task TestRemoteIPAddress(string registerAddress, string requestAddress, string expectAddress) { var builder = new WebHostBuilder() diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/TestConnection.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/TestConnection.cs deleted file mode 100644 index db602658f0..0000000000 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/TestConnection.cs +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using System.Net; -using System.Net.Sockets; -using Microsoft.AspNetCore.Server.Kestrel.Networking; - -namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests -{ - public class TestConnection - { - public static Socket CreateConnectedLoopbackSocket(int port) - { - var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); - if (PlatformApis.IsWindows) - { - const int SIO_LOOPBACK_FAST_PATH = -1744830448; - var optionInValue = BitConverter.GetBytes(1); - try - { - socket.IOControl(SIO_LOOPBACK_FAST_PATH, optionInValue, null); - } - catch - { - // If the operating system version on this machine did - // not support SIO_LOOPBACK_FAST_PATH (i.e. version - // prior to Windows 8 / Windows Server 2012), handle the exception - } - } - socket.Connect(new IPEndPoint(IPAddress.Loopback, port)); - return socket; - } - } -} diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/RequestTargetProcessingTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/RequestTargetProcessingTests.cs new file mode 100644 index 0000000000..ac2327cea6 --- /dev/null +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/RequestTargetProcessingTests.cs @@ -0,0 +1,131 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System.Threading.Tasks; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Http.Features; +using Xunit; + +namespace Microsoft.AspNetCore.Server.KestrelTests +{ + public class RequestTargetProcessingTests + { + [Fact] + public async Task RequestPathIsNormalized() + { + var testContext = new TestServiceContext(); + + using (var server = new TestServer(async context => + { + Assert.Equal("/\u00C5", context.Request.PathBase.Value); + Assert.Equal("/B/\u00C5", context.Request.Path.Value); + + context.Response.Headers["Content-Length"] = new[] { "11" }; + await context.Response.WriteAsync("Hello World"); + }, testContext, "http://127.0.0.1/\u0041\u030A")) + { + using (var connection = server.CreateConnection()) + { + await connection.SendEnd( + "GET /%41%CC%8A/A/../B/%41%CC%8A HTTP/1.0", + "", + ""); + await connection.ReceiveEnd( + "HTTP/1.1 200 OK", + $"Date: {testContext.DateHeaderValue}", + "Content-Length: 11", + "", + "Hello World"); + } + } + } + + [Theory] + [InlineData("/")] + [InlineData("/.")] + [InlineData("/..")] + [InlineData("/./.")] + [InlineData("/./..")] + [InlineData("/../.")] + [InlineData("/../..")] + [InlineData("/path")] + [InlineData("/path?foo=1&bar=2")] + [InlineData("/hello%20world")] + [InlineData("/hello%20world?foo=1&bar=2")] + [InlineData("/base/path")] + [InlineData("/base/path?foo=1&bar=2")] + [InlineData("/base/hello%20world")] + [InlineData("/base/hello%20world?foo=1&bar=2")] + public async Task RequestFeatureContainsRawTarget(string requestTarget) + { + var testContext = new TestServiceContext(); + + using (var server = new TestServer(async context => + { + Assert.Equal(requestTarget, context.Features.Get().RawTarget); + + context.Response.Headers["Content-Length"] = new[] { "11" }; + await context.Response.WriteAsync("Hello World"); + }, testContext)) + { + using (var connection = server.CreateConnection()) + { + await connection.SendEnd( + $"GET {requestTarget} HTTP/1.0", + "", + ""); + await connection.ReceiveEnd( + "HTTP/1.1 200 OK", + $"Date: {testContext.DateHeaderValue}", + "Content-Length: 11", + "", + "Hello World"); + } + } + } + + [Theory] + [InlineData("*")] + [InlineData("*/?arg=value")] + [InlineData("*?arg=value")] + [InlineData("DoesNotStartWith/")] + [InlineData("DoesNotStartWith/?arg=value")] + [InlineData("DoesNotStartWithSlash?arg=value")] + [InlineData("./")] + [InlineData("../")] + [InlineData("../.")] + [InlineData(".././")] + [InlineData("../..")] + [InlineData("../../")] + public async Task NonPathRequestTargetSetInRawTarget(string requestTarget) + { + var testContext = new TestServiceContext(); + + using (var server = new TestServer(async context => + { + Assert.Equal(requestTarget, context.Features.Get().RawTarget); + Assert.Empty(context.Request.Path.Value); + Assert.Empty(context.Request.PathBase.Value); + Assert.Empty(context.Request.QueryString.Value); + + context.Response.Headers["Content-Length"] = new[] { "11" }; + await context.Response.WriteAsync("Hello World"); + }, testContext)) + { + using (var connection = server.CreateConnection()) + { + await connection.SendEnd( + $"GET {requestTarget} HTTP/1.0", + "", + ""); + await connection.ReceiveEnd( + "HTTP/1.1 200 OK", + $"Date: {testContext.DateHeaderValue}", + "Content-Length: 11", + "", + "Hello World"); + } + } + } + } +} From 5d77ad24c2887ae88c5822f5e06b3eaa218a16cb Mon Sep 17 00:00:00 2001 From: moozzyk Date: Thu, 26 May 2016 16:38:47 -0700 Subject: [PATCH 0760/1662] Refactoring out GetAsciiString from MemoryPoolIteratorExtensions --- .../Infrastructure/AsciiUtilities.cs | 60 +++++++++++++++++++ .../MemoryPoolIteratorExtensions.cs | 55 ++--------------- 2 files changed, 64 insertions(+), 51 deletions(-) create mode 100644 src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/AsciiUtilities.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/AsciiUtilities.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/AsciiUtilities.cs new file mode 100644 index 0000000000..e75c547864 --- /dev/null +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/AsciiUtilities.cs @@ -0,0 +1,60 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure +{ + internal class AsciiUtilities + { + public static unsafe void GetAsciiString(byte* input, char* output, int count) + { + var i = 0; + while (i < count - 11) + { + i += 12; + *(output) = (char)*(input); + *(output + 1) = (char)*(input + 1); + *(output + 2) = (char)*(input + 2); + *(output + 3) = (char)*(input + 3); + *(output + 4) = (char)*(input + 4); + *(output + 5) = (char)*(input + 5); + *(output + 6) = (char)*(input + 6); + *(output + 7) = (char)*(input + 7); + *(output + 8) = (char)*(input + 8); + *(output + 9) = (char)*(input + 9); + *(output + 10) = (char)*(input + 10); + *(output + 11) = (char)*(input + 11); + output += 12; + input += 12; + } + if (i < count - 5) + { + i += 6; + *(output) = (char)*(input); + *(output + 1) = (char)*(input + 1); + *(output + 2) = (char)*(input + 2); + *(output + 3) = (char)*(input + 3); + *(output + 4) = (char)*(input + 4); + *(output + 5) = (char)*(input + 5); + output += 6; + input += 6; + } + if (i < count - 3) + { + i += 4; + *(output) = (char)*(input); + *(output + 1) = (char)*(input + 1); + *(output + 2) = (char)*(input + 2); + *(output + 3) = (char)*(input + 3); + output += 4; + input += 4; + } + while (i < count) + { + i++; + *output = (char)*input; + output++; + input++; + } + } + } +} diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPoolIteratorExtensions.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPoolIteratorExtensions.cs index 47410277fd..315b332fb2 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPoolIteratorExtensions.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPoolIteratorExtensions.cs @@ -110,63 +110,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure var endBlock = end.Block; var endIndex = end.Index; + var outputOffset = 0; while (true) { int following = (block != endBlock ? block.End : endIndex) - inputOffset; if (following > 0) { - var input = block.DataFixedPtr + inputOffset; - var i = 0; - while (i < following - 11) - { - i += 12; - *(output) = (char)*(input); - *(output + 1) = (char)*(input + 1); - *(output + 2) = (char)*(input + 2); - *(output + 3) = (char)*(input + 3); - *(output + 4) = (char)*(input + 4); - *(output + 5) = (char)*(input + 5); - *(output + 6) = (char)*(input + 6); - *(output + 7) = (char)*(input + 7); - *(output + 8) = (char)*(input + 8); - *(output + 9) = (char)*(input + 9); - *(output + 10) = (char)*(input + 10); - *(output + 11) = (char)*(input + 11); - output += 12; - input += 12; - } - if (i < following - 5) - { - i += 6; - *(output) = (char)*(input); - *(output + 1) = (char)*(input + 1); - *(output + 2) = (char)*(input + 2); - *(output + 3) = (char)*(input + 3); - *(output + 4) = (char)*(input + 4); - *(output + 5) = (char)*(input + 5); - output += 6; - input += 6; - } - if (i < following - 3) - { - i += 4; - *(output) = (char)*(input); - *(output + 1) = (char)*(input + 1); - *(output + 2) = (char)*(input + 2); - *(output + 3) = (char)*(input + 3); - output += 4; - input += 4; - } - while (i < following) - { - i++; - *output = (char)*input; - output++; - input++; - } - - remaining -= following; + AsciiUtilities.GetAsciiString(block.DataFixedPtr + inputOffset, output + outputOffset, following); + outputOffset += following; + remaining -= following; } if (remaining == 0) From 0753f06c284dc0635484bb27a1a76858af9eeb27 Mon Sep 17 00:00:00 2001 From: moozzyk Date: Fri, 27 May 2016 10:32:51 -0700 Subject: [PATCH 0761/1662] Aborting request if a string can't be converted to ASCII --- .../Http/Frame.cs | 11 +++-- .../Http/FrameOfT.cs | 9 ++++ .../Infrastructure/AsciiUtilities.cs | 22 +++++++++- .../MemoryPoolIteratorExtensions.cs | 11 ++--- .../{AsciiDecoder.cs => AsciiDecoding.cs} | 43 +++++++++++++++---- 5 files changed, 79 insertions(+), 17 deletions(-) rename test/Microsoft.AspNetCore.Server.KestrelTests/{AsciiDecoder.cs => AsciiDecoding.cs} (75%) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs index 7868964958..dbf7463dfe 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs @@ -43,7 +43,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http private readonly object _onStartingSync = new Object(); private readonly object _onCompletedSync = new Object(); - private bool _requestRejected; + protected bool _requestRejected; private Streams _frameStreams; protected List, object>> _onStarting; @@ -1175,12 +1175,17 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } public void RejectRequest(string message) + { + var ex = new BadHttpRequestException(message); + SetBadRequestState(ex); + throw ex; + } + + public void SetBadRequestState(BadHttpRequestException ex) { _requestProcessingStopping = true; _requestRejected = true; - var ex = new BadHttpRequestException(message); Log.ConnectionBadRequest(ConnectionId, ex); - throw ex; } protected void ReportApplicationError(Exception ex) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameOfT.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameOfT.cs index c0181c5463..13a04dea49 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameOfT.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameOfT.cs @@ -5,6 +5,7 @@ using System; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Hosting.Server; +using Microsoft.AspNetCore.Server.Kestrel.Exceptions; using Microsoft.Extensions.Logging; namespace Microsoft.AspNetCore.Server.Kestrel.Http @@ -145,6 +146,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http Reset(); } } + catch (BadHttpRequestException ex) + { + if (!_requestRejected) + { + SetBadRequestState(ex); + Log.LogWarning(0, ex, "Connection processing ended abnormally"); + } + } catch (Exception ex) { Log.LogWarning(0, ex, "Connection processing ended abnormally"); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/AsciiUtilities.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/AsciiUtilities.cs index e75c547864..69d6fda2aa 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/AsciiUtilities.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/AsciiUtilities.cs @@ -5,11 +5,19 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure { internal class AsciiUtilities { - public static unsafe void GetAsciiString(byte* input, char* output, int count) + public static unsafe bool TryGetAsciiString(byte* input, char* output, int count) { var i = 0; + int orValue = 0; + bool hasZero = false; while (i < count - 11) { + orValue |= *input | *(input + 1) | *(input + 2) | *(input + 3) | *(input + 4) | *(input + 5) | + *(input + 6) | *(input + 7) | *(input + 8) | *(input + 9) | *(input + 10) | *(input + 11); + hasZero = hasZero || *input == 0 || *(input + 1) == 0 || *(input + 2) == 0 || *(input + 3) == 0 || + *(input + 4) == 0 || *(input + 5) == 0 || *(input + 6) == 0 || *(input + 7) == 0 || + *(input + 8) == 0 || *(input + 9) == 0 || *(input + 10) == 0 || *(input + 11) == 0; + i += 12; *(output) = (char)*(input); *(output + 1) = (char)*(input + 1); @@ -28,6 +36,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure } if (i < count - 5) { + orValue |= *input | *(input + 1) | *(input + 2) | *(input + 3) | *(input + 4) | *(input + 5); + hasZero = hasZero || *input == 0 || *(input + 1) == 0 || *(input + 2) == 0 || *(input + 3) == 0 || + *(input + 4) == 0 || *(input + 5) == 0; + i += 6; *(output) = (char)*(input); *(output + 1) = (char)*(input + 1); @@ -40,6 +52,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure } if (i < count - 3) { + orValue |= *input | *(input + 1) | *(input + 2) | *(input + 3); + hasZero = hasZero || *input == 0 || *(input + 1) == 0 || *(input + 2) == 0 || *(input + 3) == 0; + i += 4; *(output) = (char)*(input); *(output + 1) = (char)*(input + 1); @@ -48,13 +63,18 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure output += 4; input += 4; } + while (i < count) { + orValue |= *input; + hasZero = hasZero || *input == 0; i++; *output = (char)*input; output++; input++; } + + return (orValue & 0x80) == 0 && !hasZero; } } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPoolIteratorExtensions.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPoolIteratorExtensions.cs index 315b332fb2..5d1953166e 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPoolIteratorExtensions.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPoolIteratorExtensions.cs @@ -4,6 +4,7 @@ using System; using System.Diagnostics; using System.Text; +using Microsoft.AspNetCore.Server.Kestrel.Exceptions; namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure { @@ -93,10 +94,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure return null; } - // Bytes out of the range of ascii are treated as "opaque data" - // and kept in string as a char value that casts to same input byte value - // https://tools.ietf.org/html/rfc7230#section-3.2.4 - var inputOffset = start.Index; var block = start.Block; @@ -117,7 +114,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure if (following > 0) { - AsciiUtilities.GetAsciiString(block.DataFixedPtr + inputOffset, output + outputOffset, following); + if (!AsciiUtilities.TryGetAsciiString(block.DataFixedPtr + inputOffset, output + outputOffset, following)) + { + throw new BadHttpRequestException("The input string contains non-ASCII or null characters."); + } + outputOffset += following; remaining -= following; } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/AsciiDecoder.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/AsciiDecoding.cs similarity index 75% rename from test/Microsoft.AspNetCore.Server.KestrelTests/AsciiDecoder.cs rename to test/Microsoft.AspNetCore.Server.KestrelTests/AsciiDecoding.cs index 634efc65db..8d62e034c5 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/AsciiDecoder.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/AsciiDecoding.cs @@ -3,17 +3,18 @@ using System; using System.Linq; +using Microsoft.AspNetCore.Server.Kestrel.Exceptions; using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; using Xunit; namespace Microsoft.AspNetCore.Server.KestrelTests { - public class AsciiDecoderTests + public class AsciiDecodingTests { [Fact] - private void FullByteRangeSupported() + private void FullAsciiRangeSupported() { - var byteRange = Enumerable.Range(0, 256).Select(x => (byte)x).ToArray(); + var byteRange = Enumerable.Range(1, 127).Select(x => (byte)x).ToArray(); using (var pool = new MemoryPool()) { var mem = pool.Lease(); @@ -26,7 +27,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests Assert.Equal(s.Length, byteRange.Length); - for (var i = 0; i < byteRange.Length; i++) + for (var i = 1; i < byteRange.Length; i++) { var sb = (byte)s[i]; var b = byteRange[i]; @@ -38,10 +39,36 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } } + [Theory] + [InlineData(0x00)] + [InlineData(0x80)] + private void ExceptionThrownForZeroOrNonAscii(byte b) + { + for (var length = 1; length < 16; length++) + { + for (var position = 0; position < length; position++) + { + var byteRange = Enumerable.Range(1, length).Select(x => (byte)x).ToArray(); + byteRange[position] = b; + + using (var pool = new MemoryPool()) + { + var mem = pool.Lease(); + mem.GetIterator().CopyFrom(byteRange); + + var begin = mem.GetIterator(); + var end = GetIterator(begin, byteRange.Length); + + Assert.Throws(() => begin.GetAsciiString(end)); + } + } + } + } + [Fact] private void MultiBlockProducesCorrectResults() { - var byteRange = Enumerable.Range(0, 512 + 64).Select(x => (byte)x).ToArray(); + var byteRange = Enumerable.Range(0, 512 + 64).Select(x => (byte)((x & 0x7f) | 0x01)).ToArray(); var expectedByteRange = byteRange .Concat(byteRange) .Concat(byteRange) @@ -72,7 +99,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests for (var i = 0; i < expectedByteRange.Length; i++) { - var sb = (byte)s[i]; + var sb = (byte)((s[i] & 0x7f) | 0x01); var b = expectedByteRange[i]; Assert.Equal(sb, b); @@ -88,7 +115,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [Fact] private void LargeAllocationProducesCorrectResults() { - var byteRange = Enumerable.Range(0, 16384 + 64).Select(x => (byte)x).ToArray(); + var byteRange = Enumerable.Range(0, 16384 + 64).Select(x => (byte)((x & 0x7f) | 0x01)).ToArray(); var expectedByteRange = byteRange.Concat(byteRange).ToArray(); using (var pool = new MemoryPool()) { @@ -113,7 +140,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests for (var i = 0; i < expectedByteRange.Length; i++) { - var sb = (byte)s[i]; + var sb = (byte)((s[i] & 0x7f) | 0x01); var b = expectedByteRange[i]; Assert.Equal(sb, b); From bcdd3147a156a5866f480bba009960d09a2fc998 Mon Sep 17 00:00:00 2001 From: moozzyk Date: Tue, 31 May 2016 18:55:29 -0700 Subject: [PATCH 0762/1662] Fixing "Error -4092 EACCES permission denied" in tests A test is trying to bind to port 80 which fails if IIS is running on the machine --- .../RequestTargetProcessingTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/RequestTargetProcessingTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/RequestTargetProcessingTests.cs index ac2327cea6..8910e8f768 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/RequestTargetProcessingTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/RequestTargetProcessingTests.cs @@ -22,7 +22,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests context.Response.Headers["Content-Length"] = new[] { "11" }; await context.Response.WriteAsync("Hello World"); - }, testContext, "http://127.0.0.1/\u0041\u030A")) + }, testContext, "http://127.0.0.1:0/\u0041\u030A")) { using (var connection = server.CreateConnection()) { From 6224f5b6e8368985cce8016f7d158535a4f4cd81 Mon Sep 17 00:00:00 2001 From: Chris R Date: Wed, 1 Jun 2016 11:16:43 -0700 Subject: [PATCH 0763/1662] Perf: Remove unnecessary path checks --- src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs | 1 - .../Http/PathNormalizer.cs | 10 ---------- .../ServerAddress.cs | 2 -- .../PathNormalizerTests.cs | 8 -------- .../RequestTargetProcessingTests.cs | 8 ++++---- .../ServerAddressTests.cs | 10 ---------- 6 files changed, 4 insertions(+), 35 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs index dbf7463dfe..9db412405a 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs @@ -919,7 +919,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http // URI was encoded, unescape and then parse as utf8 pathEnd = UrlPathDecoder.Unescape(pathBegin, pathEnd); requestUrlPath = pathBegin.GetUtf8String(pathEnd); - requestUrlPath = PathNormalizer.NormalizeToNFC(requestUrlPath); } else { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/PathNormalizer.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/PathNormalizer.cs index e136331e22..65b59e4a0e 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/PathNormalizer.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/PathNormalizer.cs @@ -9,16 +9,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { public static class PathNormalizer { - public static string NormalizeToNFC(string path) - { - if (!path.IsNormalized(NormalizationForm.FormC)) - { - path = path.Normalize(NormalizationForm.FormC); - } - - return path; - } - public static string RemoveDotSegments(string path) { if (ContainsDotSegments(path)) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/ServerAddress.cs b/src/Microsoft.AspNetCore.Server.Kestrel/ServerAddress.cs index 4dd7ffb0cf..17258184dd 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/ServerAddress.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/ServerAddress.cs @@ -156,8 +156,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel serverAddress.PathBase = url.Substring(pathDelimiterEnd); } - serverAddress.PathBase = PathNormalizer.NormalizeToNFC(serverAddress.PathBase); - return serverAddress; } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/PathNormalizerTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/PathNormalizerTests.cs index a2304301e8..d19eb63705 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/PathNormalizerTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/PathNormalizerTests.cs @@ -51,13 +51,5 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var result = PathNormalizer.RemoveDotSegments(input); Assert.Equal(expected, result); } - - [Fact] - public void NormalizesToNFC() - { - var result = PathNormalizer.NormalizeToNFC("/\u0041\u030A"); - Assert.True(result.IsNormalized(NormalizationForm.FormC)); - Assert.Equal("/\u00C5", result); - } } } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/RequestTargetProcessingTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/RequestTargetProcessingTests.cs index 8910e8f768..a3c37ff19a 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/RequestTargetProcessingTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/RequestTargetProcessingTests.cs @@ -17,17 +17,17 @@ namespace Microsoft.AspNetCore.Server.KestrelTests using (var server = new TestServer(async context => { - Assert.Equal("/\u00C5", context.Request.PathBase.Value); - Assert.Equal("/B/\u00C5", context.Request.Path.Value); + Assert.Equal("/A", context.Request.PathBase.Value); + Assert.Equal("/B/C", context.Request.Path.Value); context.Response.Headers["Content-Length"] = new[] { "11" }; await context.Response.WriteAsync("Hello World"); - }, testContext, "http://127.0.0.1:0/\u0041\u030A")) + }, testContext, "http://127.0.0.1:0/A")) { using (var connection = server.CreateConnection()) { await connection.SendEnd( - "GET /%41%CC%8A/A/../B/%41%CC%8A HTTP/1.0", + "GET /A/0/../B/C HTTP/1.0", "", ""); await connection.ReceiveEnd( diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/ServerAddressTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/ServerAddressTests.cs index f38ec1d367..ee40a855e2 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/ServerAddressTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/ServerAddressTests.cs @@ -2,7 +2,6 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.Text; using Microsoft.AspNetCore.Server.Kestrel; using Xunit; @@ -68,15 +67,6 @@ namespace Microsoft.AspNetCore.Server.KestrelTests Assert.Equal(toString ?? url, serverAddress.ToString()); } - [Fact] - public void PathBaseIsNormalized() - { - var serverAddres = ServerAddress.FromUrl("http://localhost:8080/p\u0041\u030Athbase"); - - Assert.True(serverAddres.PathBase.IsNormalized(NormalizationForm.FormC)); - Assert.Equal("/p\u00C5thbase", serverAddres.PathBase); - } - [Fact] public void WithHostReturnsNewInstanceWithDifferentHost() { From bb92cc1c291cfe6e612b2ed1fb1f940745b60125 Mon Sep 17 00:00:00 2001 From: Pavel Krymets Date: Tue, 31 May 2016 09:24:46 -0700 Subject: [PATCH 0764/1662] Fix NRE when aborting connection or client disconects --- .../Http/SocketInput.cs | 96 +++++++++++-------- .../Infrastructure/TaskUtilities.cs | 5 + .../FrameRequestStreamTests.cs | 10 ++ 3 files changed, 73 insertions(+), 38 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketInput.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketInput.cs index 1b49246b92..87f82474c8 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketInput.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketInput.cs @@ -27,9 +27,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http private MemoryPoolBlock _tail; private MemoryPoolBlock _pinned; - private int _consumingState; private object _sync = new object(); + private bool _consuming; + private bool _disposed; + public SocketInput(MemoryPool memory, IThreadPool threadPool) { _memory = memory; @@ -163,12 +165,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http public MemoryPoolIterator ConsumingStart() { - if (Interlocked.CompareExchange(ref _consumingState, 1, 0) != 0) + lock (_sync) { - throw new InvalidOperationException("Already consuming input."); + if (_consuming) + { + throw new InvalidOperationException("Already consuming input."); + } + _consuming = true; + return new MemoryPoolIterator(_head); } - - return new MemoryPoolIterator(_head); } public void ConsumingComplete( @@ -180,38 +185,44 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http lock (_sync) { - if (!consumed.IsDefault) + if (!_disposed) + { + if (!consumed.IsDefault) + { + returnStart = _head; + returnEnd = consumed.Block; + _head = consumed.Block; + _head.Start = consumed.Index; + } + + if (!examined.IsDefault && + examined.IsEnd && + RemoteIntakeFin == false && + _awaitableError == null) + { + _manualResetEvent.Reset(); + + Interlocked.CompareExchange( + ref _awaitableState, + _awaitableIsNotCompleted, + _awaitableIsCompleted); + } + } + else { returnStart = _head; - returnEnd = consumed.Block; - _head = consumed.Block; - _head.Start = consumed.Index; + returnEnd = null; + _head = null; + _tail = null; } - if (!examined.IsDefault && - examined.IsEnd && - RemoteIntakeFin == false && - _awaitableError == null) + ReturnBlocks(returnStart, returnEnd); + + if (!_consuming) { - _manualResetEvent.Reset(); - - Interlocked.CompareExchange( - ref _awaitableState, - _awaitableIsNotCompleted, - _awaitableIsCompleted); + throw new InvalidOperationException("No ongoing consuming operation to complete."); } - } - - while (returnStart != returnEnd) - { - var returnBlock = returnStart; - returnStart = returnStart.Next; - returnBlock.Pool.Return(returnBlock); - } - - if (Interlocked.CompareExchange(ref _consumingState, 0, 1) != 1) - { - throw new InvalidOperationException("No ongoing consuming operation to complete."); + _consuming = false; } } @@ -286,20 +297,29 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http public void Dispose() { - AbortAwaiting(); + lock (_sync) + { + AbortAwaiting(); - // Return all blocks - var block = _head; - while (block != null) + if (!_consuming) + { + ReturnBlocks(_head, null); + _head = null; + _tail = null; + } + _disposed = true; + } + } + + private static void ReturnBlocks(MemoryPoolBlock block, MemoryPoolBlock end) + { + while (block != end) { var returnBlock = block; block = block.Next; returnBlock.Pool.Return(returnBlock); } - - _head = null; - _tail = null; } } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/TaskUtilities.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/TaskUtilities.cs index 97f64e3e21..328c8ecb05 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/TaskUtilities.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/TaskUtilities.cs @@ -29,6 +29,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure public static Task GetCancelledZeroTask(CancellationToken cancellationToken = default(CancellationToken)) { #if NETSTANDARD1_3 + // Make sure cancellationToken is cancelled before passing to Task.FromCanceled + if (!cancellationToken.IsCancellationRequested) + { + cancellationToken = new CancellationToken(true); + } return Task.FromCanceled(cancellationToken); #else var tcs = new TaskCompletionSource(); diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameRequestStreamTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameRequestStreamTests.cs index 10bdbf452c..b201db9b99 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameRequestStreamTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameRequestStreamTests.cs @@ -104,5 +104,15 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var stream = new FrameRequestStream(); await stream.FlushAsync(); } + + [Fact] + public void AbortCausesReadToCancel() + { + var stream = new FrameRequestStream(); + stream.StartAcceptingReads(null); + stream.Abort(); + var task = stream.ReadAsync(new byte[1], 0, 1); + Assert.True(task.IsCanceled); + } } } From f609f41a7cb32114277f61c9a527d6cac71af754 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Tue, 31 May 2016 15:53:20 -0700 Subject: [PATCH 0765/1662] Reject non-ASCII chars in headers in addition to control chars --- .../Http/FrameHeaders.cs | 4 ++-- .../FrameResponseHeadersTests.cs | 17 ++++++++++++++++- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameHeaders.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameHeaders.cs index 4bba23dbd3..ee7c1c562b 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameHeaders.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameHeaders.cs @@ -224,9 +224,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { foreach (var ch in headerCharacters) { - if (ch < 0x20) + if (ch < 0x20 || ch > 0x7E) { - throw new InvalidOperationException(string.Format("Invalid control character in header: 0x{0:X2}", (byte)ch)); + throw new InvalidOperationException(string.Format("Invalid non-ASCII or control character in header: 0x{0:X4}", (ushort)ch)); } } } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameResponseHeadersTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameResponseHeadersTests.cs index fa5f446267..3118a008f1 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameResponseHeadersTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameResponseHeadersTests.cs @@ -49,12 +49,27 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [InlineData("Server\r", "Data")] [InlineData("Ser\0ver", "Data")] [InlineData("Server\r\n", "Data")] + [InlineData("\u0000Server", "Data")] + [InlineData("Server", "Data\u0000")] [InlineData("\u001FServer", "Data")] [InlineData("Unknown-Header\r\n", "Data")] [InlineData("\0Unknown-Header", "Data")] [InlineData("Unknown\r-Header", "Data")] [InlineData("Unk\nown-Header", "Data")] - public void AddingControlCharactersToHeadersThrows(string key, string value) + [InlineData("Server", "Da\u007Fta")] + [InlineData("Unknown\u007F-Header", "Data")] + [InlineData("Ser\u0080ver", "Data")] + [InlineData("Server", "Da\u0080ta")] + [InlineData("Unknown\u0080-Header", "Data")] + [InlineData("Server", "Data")] + [InlineData("Server", "Data")] + [InlineData("Unknown-Header", "Data")] + [InlineData("Server", "Data")] + [InlineData("erver", "Data")] + [InlineData("Server", "Data")] + [InlineData("Unknown-Header", "Data")] + [InlineData("Server", "Data")] + public void AddingControlOrNonAsciiCharactersToHeadersThrows(string key, string value) { var responseHeaders = new FrameResponseHeaders(); From 58410bf0161485b10ba58e805b6cc1adef823666 Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Wed, 1 Jun 2016 15:53:32 -0700 Subject: [PATCH 0766/1662] Fix Travis build. --- .../IPv6SupportedConditionAttribute.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/IPv6SupportedConditionAttribute.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/IPv6SupportedConditionAttribute.cs index 8889c3b2d5..ca2f2bc6b9 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/IPv6SupportedConditionAttribute.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/IPv6SupportedConditionAttribute.cs @@ -35,7 +35,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { using (var socket = new Socket(AddressFamily.InterNetworkV6, SocketType.Stream, ProtocolType.Tcp)) { - socket.Bind(new IPEndPoint(IPAddress.IPv6Any, 0)); + socket.Bind(new IPEndPoint(IPAddress.IPv6Loopback, 0)); return true; } } From 6e36bbe32c4764799d0e5dee1cac98b48b71c7f8 Mon Sep 17 00:00:00 2001 From: Chris R Date: Wed, 1 Jun 2016 15:58:49 -0700 Subject: [PATCH 0767/1662] Add negative path tests. --- .../RequestTargetProcessingTests.cs | 10 +++++----- .../ServerAddressTests.cs | 10 ++++++++++ 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/RequestTargetProcessingTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/RequestTargetProcessingTests.cs index a3c37ff19a..6d6a82ce3b 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/RequestTargetProcessingTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/RequestTargetProcessingTests.cs @@ -11,23 +11,23 @@ namespace Microsoft.AspNetCore.Server.KestrelTests public class RequestTargetProcessingTests { [Fact] - public async Task RequestPathIsNormalized() + public async Task RequestPathIsNotNormalized() { var testContext = new TestServiceContext(); using (var server = new TestServer(async context => { - Assert.Equal("/A", context.Request.PathBase.Value); - Assert.Equal("/B/C", context.Request.Path.Value); + Assert.Equal("/\u0041\u030A", context.Request.PathBase.Value); + Assert.Equal("/B/\u0041\u030A", context.Request.Path.Value); context.Response.Headers["Content-Length"] = new[] { "11" }; await context.Response.WriteAsync("Hello World"); - }, testContext, "http://127.0.0.1:0/A")) + }, testContext, "http://127.0.0.1:0/\u0041\u030A")) { using (var connection = server.CreateConnection()) { await connection.SendEnd( - "GET /A/0/../B/C HTTP/1.0", + "GET /%41%CC%8A/A/../B/%41%CC%8A HTTP/1.0", "", ""); await connection.ReceiveEnd( diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/ServerAddressTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/ServerAddressTests.cs index ee40a855e2..c8920d384b 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/ServerAddressTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/ServerAddressTests.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Text; using Microsoft.AspNetCore.Server.Kestrel; using Xunit; @@ -67,6 +68,15 @@ namespace Microsoft.AspNetCore.Server.KestrelTests Assert.Equal(toString ?? url, serverAddress.ToString()); } + [Fact] + public void PathBaseIsNotNormalized() + { + var serverAddres = ServerAddress.FromUrl("http://localhost:8080/p\u0041\u030Athbase"); + + Assert.False(serverAddres.PathBase.IsNormalized(NormalizationForm.FormC)); + Assert.Equal("/p\u0041\u030Athbase", serverAddres.PathBase); + } + [Fact] public void WithHostReturnsNewInstanceWithDifferentHost() { From 9667907515d8530d8fe4ee7c7a51523c9f8ccb37 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Wed, 1 Jun 2016 15:58:46 -0700 Subject: [PATCH 0768/1662] Prevent IOException from incorrectly failing test expecting 400 response --- .../BadHttpRequestTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/BadHttpRequestTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/BadHttpRequestTests.cs index e8baf36f10..dd3380be64 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/BadHttpRequestTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/BadHttpRequestTests.cs @@ -144,7 +144,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests await connection.Receive( "Connection: close", ""); - await connection.ReceiveEnd( + await connection.ReceiveForcedEnd( $"Date: {connection.Server.Context.DateHeaderValue}", "Content-Length: 0", "", From 6e46d9757dc92a2a48834d8a8ba72201fd9721db Mon Sep 17 00:00:00 2001 From: moozzyk Date: Wed, 1 Jun 2016 16:17:56 -0700 Subject: [PATCH 0769/1662] Improve perf of TryGetAsciiString --- .../Infrastructure/AsciiUtilities.cs | 83 +++++++++---------- 1 file changed, 41 insertions(+), 42 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/AsciiUtilities.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/AsciiUtilities.cs index 69d6fda2aa..2d9a04ee5b 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/AsciiUtilities.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/AsciiUtilities.cs @@ -8,73 +8,72 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure public static unsafe bool TryGetAsciiString(byte* input, char* output, int count) { var i = 0; - int orValue = 0; - bool hasZero = false; + sbyte* signedInput = (sbyte*)input; + + bool isValid = true; while (i < count - 11) { - orValue |= *input | *(input + 1) | *(input + 2) | *(input + 3) | *(input + 4) | *(input + 5) | - *(input + 6) | *(input + 7) | *(input + 8) | *(input + 9) | *(input + 10) | *(input + 11); - hasZero = hasZero || *input == 0 || *(input + 1) == 0 || *(input + 2) == 0 || *(input + 3) == 0 || - *(input + 4) == 0 || *(input + 5) == 0 || *(input + 6) == 0 || *(input + 7) == 0 || - *(input + 8) == 0 || *(input + 9) == 0 || *(input + 10) == 0 || *(input + 11) == 0; + isValid = isValid && *signedInput > 0 && *(signedInput + 1) > 0 && *(signedInput + 2) > 0 && + *(signedInput + 3) > 0 && *(signedInput + 4) > 0 && *(signedInput + 5) > 0 && *(signedInput + 6) > 0 && + *(signedInput + 7) > 0 && *(signedInput + 8) > 0 && *(signedInput + 9) > 0 && *(signedInput + 10) > 0 && + *(signedInput + 11) > 0; i += 12; - *(output) = (char)*(input); - *(output + 1) = (char)*(input + 1); - *(output + 2) = (char)*(input + 2); - *(output + 3) = (char)*(input + 3); - *(output + 4) = (char)*(input + 4); - *(output + 5) = (char)*(input + 5); - *(output + 6) = (char)*(input + 6); - *(output + 7) = (char)*(input + 7); - *(output + 8) = (char)*(input + 8); - *(output + 9) = (char)*(input + 9); - *(output + 10) = (char)*(input + 10); - *(output + 11) = (char)*(input + 11); + *(output) = (char)*(signedInput); + *(output + 1) = (char)*(signedInput + 1); + *(output + 2) = (char)*(signedInput + 2); + *(output + 3) = (char)*(signedInput + 3); + *(output + 4) = (char)*(signedInput + 4); + *(output + 5) = (char)*(signedInput + 5); + *(output + 6) = (char)*(signedInput + 6); + *(output + 7) = (char)*(signedInput + 7); + *(output + 8) = (char)*(signedInput + 8); + *(output + 9) = (char)*(signedInput + 9); + *(output + 10) = (char)*(signedInput + 10); + *(output + 11) = (char)*(signedInput + 11); output += 12; - input += 12; + signedInput += 12; } if (i < count - 5) { - orValue |= *input | *(input + 1) | *(input + 2) | *(input + 3) | *(input + 4) | *(input + 5); - hasZero = hasZero || *input == 0 || *(input + 1) == 0 || *(input + 2) == 0 || *(input + 3) == 0 || - *(input + 4) == 0 || *(input + 5) == 0; + isValid = isValid && *signedInput > 0 && *(signedInput + 1) > 0 && *(signedInput + 2) > 0 && + *(signedInput + 3) > 0 && *(signedInput + 4) > 0 && *(signedInput + 5) > 0; i += 6; - *(output) = (char)*(input); - *(output + 1) = (char)*(input + 1); - *(output + 2) = (char)*(input + 2); - *(output + 3) = (char)*(input + 3); - *(output + 4) = (char)*(input + 4); - *(output + 5) = (char)*(input + 5); + *(output) = (char)*(signedInput); + *(output + 1) = (char)*(signedInput + 1); + *(output + 2) = (char)*(signedInput + 2); + *(output + 3) = (char)*(signedInput + 3); + *(output + 4) = (char)*(signedInput + 4); + *(output + 5) = (char)*(signedInput + 5); output += 6; - input += 6; + signedInput += 6; } if (i < count - 3) { - orValue |= *input | *(input + 1) | *(input + 2) | *(input + 3); - hasZero = hasZero || *input == 0 || *(input + 1) == 0 || *(input + 2) == 0 || *(input + 3) == 0; + isValid = isValid && *signedInput > 0 && *(signedInput + 1) > 0 && *(signedInput + 2) > 0 && + *(signedInput + 3) > 0; i += 4; - *(output) = (char)*(input); - *(output + 1) = (char)*(input + 1); - *(output + 2) = (char)*(input + 2); - *(output + 3) = (char)*(input + 3); + *(output) = (char)*(signedInput); + *(output + 1) = (char)*(signedInput + 1); + *(output + 2) = (char)*(signedInput + 2); + *(output + 3) = (char)*(signedInput + 3); output += 4; - input += 4; + signedInput += 4; } while (i < count) { - orValue |= *input; - hasZero = hasZero || *input == 0; + isValid = isValid && *signedInput > 0; + i++; - *output = (char)*input; + *output = (char)*signedInput; output++; - input++; + signedInput++; } - return (orValue & 0x80) == 0 && !hasZero; + return isValid; } } } From de022b605146e5436369700c82a1cda65fc44711 Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Wed, 1 Jun 2016 14:30:28 -0700 Subject: [PATCH 0770/1662] Improved handling of whitespace in headers. --- .../Http/Frame.cs | 221 +++++++----- .../BadHttpRequestTests.cs | 36 ++ .../FrameTests.cs | 338 +++++++++++++++++- 3 files changed, 489 insertions(+), 106 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs index 9db412405a..0a9eb6870c 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs @@ -37,6 +37,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http private static Vector _vectorCRs = new Vector((byte)'\r'); private static Vector _vectorColons = new Vector((byte)':'); private static Vector _vectorSpaces = new Vector((byte)' '); + private static Vector _vectorTabs = new Vector((byte)'\t'); private static Vector _vectorQuestionMarks = new Vector((byte)'?'); private static Vector _vectorPercentages = new Vector((byte)'%'); @@ -1033,10 +1034,37 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http var consumed = scan; try { - int chFirst; - int chSecond; while (!scan.IsEnd) { + var ch = scan.Peek(); + if (ch == -1) + { + return false; + } + else if (ch == '\r') + { + // Check for final CRLF. + scan.Take(); + ch = scan.Take(); + + if (ch == -1) + { + return false; + } + else if (ch == '\n') + { + consumed = scan; + return true; + } + + // Headers don't end in CRLF line. + RejectRequest("Headers corrupted, invalid header sequence."); + } + else if (ch == ' ' || ch == '\t') + { + RejectRequest("Header line must not start with whitespace."); + } + var beginName = scan; if (scan.Seek(ref _vectorColons, ref _vectorCRs) == -1) { @@ -1044,118 +1072,113 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } var endName = scan; - chFirst = scan.Take(); - var beginValue = scan; - chSecond = scan.Take(); + ch = scan.Take(); + if (ch != ':') + { + RejectRequest("No ':' character found in header line."); + } - if (chFirst == -1 || chSecond == -1) + var validateName = beginName; + if (validateName.Seek(ref _vectorSpaces, ref _vectorTabs, ref _vectorColons) != ':') + { + RejectRequest("Whitespace is not allowed in header name."); + } + + var beginValue = scan; + ch = scan.Peek(); + + if (ch == -1) { return false; } - if (chFirst == '\r') + + // Skip header value leading whitespace. + while (ch == ' ' || ch == '\t') { - if (chSecond == '\n') - { - consumed = scan; - return true; - } - - RejectRequest("Headers corrupted, invalid header sequence."); - // Headers corrupted, parsing headers is complete - return true; - } - - while ( - chSecond == ' ' || - chSecond == '\t' || - chSecond == '\r' || - chSecond == '\n') - { - if (chSecond == '\r') - { - var scanAhead = scan; - var chAhead = scanAhead.Take(); - if (chAhead == -1) - { - return false; - } - else if (chAhead == '\n') - { - chAhead = scanAhead.Take(); - if (chAhead == -1) - { - return false; - } - else if (chAhead != ' ' && chAhead != '\t') - { - // If the "\r\n" isn't part of "linear whitespace", - // then this header has no value. - break; - } - } - } - + scan.Take(); beginValue = scan; - chSecond = scan.Take(); - if (chSecond == -1) + ch = scan.Peek(); + if (ch == -1) { return false; } } + scan = beginValue; - - var wrapping = false; - while (!scan.IsEnd) + if (scan.Seek(ref _vectorCRs) == -1) { - if (scan.Seek(ref _vectorCRs) == -1) - { - // no "\r" in sight, burn used bytes and go back to await more data - return false; - } - - var endValue = scan; - chFirst = scan.Take(); // expecting: \r - chSecond = scan.Take(); // expecting: \n - - if (chSecond == -1) - { - return false; - } - else if (chSecond != '\n') - { - // "\r" was all by itself, move just after it and try again - scan = endValue; - scan.Take(); - continue; - } - - var chThird = scan.Peek(); - if (chThird == -1) - { - return false; - } - else if (chThird == ' ' || chThird == '\t') - { - // special case, "\r\n " or "\r\n\t". - // this is considered wrapping"linear whitespace" and is actually part of the header value - // continue past this for the next - wrapping = true; - continue; - } - - var name = beginName.GetArraySegment(endName); - var value = beginValue.GetAsciiString(endValue); - if (wrapping) - { - value = value.Replace("\r\n", " "); - } - - consumed = scan; - requestHeaders.Append(name.Array, name.Offset, name.Count, value); - break; + // no "\r" in sight, burn used bytes and go back to await more data + return false; } + + scan.Take(); // we know this is '\r' + ch = scan.Take(); // expecting '\n' + + if (ch == -1) + { + return false; + } + else if (ch != '\n') + { + RejectRequest("Header line must end in CRLF; only CR found."); + } + + var next = scan.Peek(); + if (next == -1) + { + return false; + } + else if (next == ' ' || next == '\t') + { + // From https://tools.ietf.org/html/rfc7230#section-3.2.4: + // + // Historically, HTTP header field values could be extended over + // multiple lines by preceding each extra line with at least one space + // or horizontal tab (obs-fold). This specification deprecates such + // line folding except within the message/http media type + // (Section 8.3.1). A sender MUST NOT generate a message that includes + // line folding (i.e., that has any field-value that contains a match to + // the obs-fold rule) unless the message is intended for packaging + // within the message/http media type. + // + // A server that receives an obs-fold in a request message that is not + // within a message/http container MUST either reject the message by + // sending a 400 (Bad Request), preferably with a representation + // explaining that obsolete line folding is unacceptable, or replace + // each received obs-fold with one or more SP octets prior to + // interpreting the field value or forwarding the message downstream. + RejectRequest("Header value line folding not supported."); + } + + // Trim trailing whitespace from header value by repeatedly advancing to next + // whitespace or CR. + // + // - If CR is found, this is the end of the header value. + // - If whitespace is found, this is the _tentative_ end of the header value. + // If non-whitespace is found after it and it's not CR, seek again to the next + // whitespace or CR for a new (possibly tentative) end of value. + var ws = beginValue; + var endValue = scan; + do + { + ws.Seek(ref _vectorSpaces, ref _vectorTabs, ref _vectorCRs); + endValue = ws; + + ch = ws.Take(); + while (ch == ' ' || ch == '\t') + { + ch = ws.Take(); + } + } while (ch != '\r'); + + var name = beginName.GetArraySegment(endName); + var value = beginValue.GetAsciiString(endValue); + + consumed = scan; + requestHeaders.Append(name.Array, name.Offset, name.Count, value); } + return false; } finally diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/BadHttpRequestTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/BadHttpRequestTests.cs index dd3380be64..8d1a0574a6 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/BadHttpRequestTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/BadHttpRequestTests.cs @@ -136,6 +136,42 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } } + [Theory] + // Missing final CRLF + [InlineData("Header-1: value1\r\nHeader-2: value2\r\n")] + // Leading whitespace + [InlineData(" Header-1: value1\r\nHeader-2: value2\r\n\r\n")] + [InlineData("\tHeader-1: value1\r\nHeader-2: value2\r\n\r\n")] + [InlineData("Header-1: value1\r\n Header-2: value2\r\n\r\n")] + [InlineData("Header-1: value1\r\n\tHeader-2: value2\r\n\r\n")] + // Missing LF + [InlineData("Header-1: value1\rHeader-2: value2\r\n\r\n")] + [InlineData("Header-1: value1\r\nHeader-2: value2\r\r\n")] + // Line folding + [InlineData("Header-1: multi\r\n line\r\nHeader-2: value2\r\n\r\n")] + [InlineData("Header-1: value1\r\nHeader-2: multi\r\n line\r\n\r\n")] + // Missing ':' + [InlineData("Header-1 value1\r\nHeader-2: value2\r\n\r\n")] + [InlineData("Header-1: value1\r\nHeader-2 value2\r\n\r\n")] + // Whitespace in header name + [InlineData("Header 1: value1\r\nHeader-2: value2\r\n\r\n")] + [InlineData("Header-1: value1\r\nHeader 2: value2\r\n\r\n")] + [InlineData("Header-1 : value1\r\nHeader-2: value2\r\n\r\n")] + [InlineData("Header-1\t: value1\r\nHeader-2: value2\r\n\r\n")] + [InlineData("Header-1: value1\r\nHeader-2 : value2\r\n\r\n")] + [InlineData("Header-1: value1\r\nHeader-2\t: value2\r\n\r\n")] + public async Task TestInvalidHeaders(string rawHeaders) + { + using (var server = new TestServer(context => TaskUtilities.CompletedTask)) + { + using (var connection = server.CreateConnection()) + { + await connection.SendAllEnd($"GET / HTTP/1.1\r\n{rawHeaders}"); + await ReceiveBadRequestResponse(connection); + } + } + } + private async Task ReceiveBadRequestResponse(TestConnection connection) { await connection.Receive( diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs index 5146a9040e..62ac9c5164 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs @@ -7,6 +7,7 @@ using System.Text; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Server.Kestrel; +using Microsoft.AspNetCore.Server.Kestrel.Exceptions; using Microsoft.AspNetCore.Server.Kestrel.Http; using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; using Microsoft.AspNetCore.Server.KestrelTests.TestHelpers; @@ -16,15 +17,338 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { public class FrameTests { + [Fact] + public void CanReadHeaderValueWithoutLeadingWhitespace() + { + var trace = new KestrelTrace(new TestKestrelTrace()); + var ltp = new LoggingThreadPool(trace); + using (var pool = new MemoryPool()) + using (var socketInput = new SocketInput(pool, ltp)) + { + var connectionContext = new ConnectionContext() + { + DateHeaderValueManager = new DateHeaderValueManager(), + ServerAddress = ServerAddress.FromUrl("http://localhost:5000") + }; + var frame = new Frame(application: null, context: connectionContext); + frame.InitializeHeaders(); + + var headerArray = Encoding.ASCII.GetBytes("Header:value\r\n\r\n"); + socketInput.IncomingData(headerArray, 0, headerArray.Length); + + var success = frame.TakeMessageHeaders(socketInput, (FrameRequestHeaders)frame.RequestHeaders); + + Assert.True(success); + Assert.Equal(1, frame.RequestHeaders.Count); + Assert.Equal("value", frame.RequestHeaders["Header"]); + + // Assert TakeMessageHeaders consumed all the input + var scan = socketInput.ConsumingStart(); + Assert.True(scan.IsEnd); + } + } + + [Theory] + [InlineData("Header: value\r\n\r\n")] + [InlineData("Header: value\r\n\r\n")] + [InlineData("Header:\tvalue\r\n\r\n")] + [InlineData("Header: \tvalue\r\n\r\n")] + [InlineData("Header:\t value\r\n\r\n")] + [InlineData("Header:\t\tvalue\r\n\r\n")] + [InlineData("Header:\t\t value\r\n\r\n")] + [InlineData("Header: \t\tvalue\r\n\r\n")] + [InlineData("Header: \t\t value\r\n\r\n")] + [InlineData("Header: \t \t value\r\n\r\n")] + public void LeadingWhitespaceIsNotIncludedInHeaderValue(string rawHeaders) + { + var trace = new KestrelTrace(new TestKestrelTrace()); + var ltp = new LoggingThreadPool(trace); + using (var pool = new MemoryPool()) + using (var socketInput = new SocketInput(pool, ltp)) + { + var connectionContext = new ConnectionContext() + { + DateHeaderValueManager = new DateHeaderValueManager(), + ServerAddress = ServerAddress.FromUrl("http://localhost:5000") + }; + var frame = new Frame(application: null, context: connectionContext); + frame.InitializeHeaders(); + + var headerArray = Encoding.ASCII.GetBytes(rawHeaders); + socketInput.IncomingData(headerArray, 0, headerArray.Length); + + var success = frame.TakeMessageHeaders(socketInput, (FrameRequestHeaders)frame.RequestHeaders); + + Assert.True(success); + Assert.Equal(1, frame.RequestHeaders.Count); + Assert.Equal("value", frame.RequestHeaders["Header"]); + + // Assert TakeMessageHeaders consumed all the input + var scan = socketInput.ConsumingStart(); + Assert.True(scan.IsEnd); + } + } + + [Theory] + [InlineData("Header: value \r\n\r\n")] + [InlineData("Header: value\t\r\n\r\n")] + [InlineData("Header: value \t\r\n\r\n")] + [InlineData("Header: value\t \r\n\r\n")] + [InlineData("Header: value\t\t\r\n\r\n")] + [InlineData("Header: value\t\t \r\n\r\n")] + [InlineData("Header: value \t\t\r\n\r\n")] + [InlineData("Header: value \t\t \r\n\r\n")] + [InlineData("Header: value \t \t \r\n\r\n")] + public void TrailingWhitespaceIsNotIncludedInHeaderValue(string rawHeaders) + { + var trace = new KestrelTrace(new TestKestrelTrace()); + var ltp = new LoggingThreadPool(trace); + using (var pool = new MemoryPool()) + using (var socketInput = new SocketInput(pool, ltp)) + { + var connectionContext = new ConnectionContext() + { + DateHeaderValueManager = new DateHeaderValueManager(), + ServerAddress = ServerAddress.FromUrl("http://localhost:5000"), + }; + var frame = new Frame(application: null, context: connectionContext); + frame.InitializeHeaders(); + + var headerArray = Encoding.ASCII.GetBytes(rawHeaders); + socketInput.IncomingData(headerArray, 0, headerArray.Length); + + var success = frame.TakeMessageHeaders(socketInput, (FrameRequestHeaders)frame.RequestHeaders); + + Assert.True(success); + Assert.Equal(1, frame.RequestHeaders.Count); + Assert.Equal("value", frame.RequestHeaders["Header"]); + + // Assert TakeMessageHeaders consumed all the input + var scan = socketInput.ConsumingStart(); + Assert.True(scan.IsEnd); + } + } + + [Theory] + [InlineData("Header: one two three\r\n\r\n", "one two three")] + [InlineData("Header: one two three\r\n\r\n", "one two three")] + [InlineData("Header: one\ttwo\tthree\r\n\r\n", "one\ttwo\tthree")] + [InlineData("Header: one two\tthree\r\n\r\n", "one two\tthree")] + [InlineData("Header: one\ttwo three\r\n\r\n", "one\ttwo three")] + [InlineData("Header: one \ttwo \tthree\r\n\r\n", "one \ttwo \tthree")] + [InlineData("Header: one\t two\t three\r\n\r\n", "one\t two\t three")] + [InlineData("Header: one \ttwo\t three\r\n\r\n", "one \ttwo\t three")] + public void WhitespaceWithinHeaderValueIsPreserved(string rawHeaders, string expectedValue) + { + var trace = new KestrelTrace(new TestKestrelTrace()); + var ltp = new LoggingThreadPool(trace); + using (var pool = new MemoryPool()) + using (var socketInput = new SocketInput(pool, ltp)) + { + var connectionContext = new ConnectionContext() + { + DateHeaderValueManager = new DateHeaderValueManager(), + ServerAddress = ServerAddress.FromUrl("http://localhost:5000"), + }; + var frame = new Frame(application: null, context: connectionContext); + frame.InitializeHeaders(); + + var headerArray = Encoding.ASCII.GetBytes(rawHeaders); + socketInput.IncomingData(headerArray, 0, headerArray.Length); + + var success = frame.TakeMessageHeaders(socketInput, (FrameRequestHeaders)frame.RequestHeaders); + + Assert.True(success); + Assert.Equal(1, frame.RequestHeaders.Count); + Assert.Equal(expectedValue, frame.RequestHeaders["Header"]); + + // Assert TakeMessageHeaders consumed all the input + var scan = socketInput.ConsumingStart(); + Assert.True(scan.IsEnd); + } + } + + [Theory] + [InlineData("Header: line1\r\n line2\r\n\r\n")] + [InlineData("Header: line1\r\n\tline2\r\n\r\n")] + [InlineData("Header: line1\r\n line2\r\n\r\n")] + [InlineData("Header: line1\r\n \tline2\r\n\r\n")] + [InlineData("Header: line1\r\n\t line2\r\n\r\n")] + [InlineData("Header: line1\r\n\t\tline2\r\n\r\n")] + [InlineData("Header: line1\r\n \t\t line2\r\n\r\n")] + [InlineData("Header: line1\r\n \t \t line2\r\n\r\n")] + public void ThrowsOnHeaderValueWithLineFolding(string rawHeaders) + { + var trace = new KestrelTrace(new TestKestrelTrace()); + var ltp = new LoggingThreadPool(trace); + using (var pool = new MemoryPool()) + using (var socketInput = new SocketInput(pool, ltp)) + { + var connectionContext = new ConnectionContext() + { + DateHeaderValueManager = new DateHeaderValueManager(), + ServerAddress = ServerAddress.FromUrl("http://localhost:5000"), + Log = trace + }; + var frame = new Frame(application: null, context: connectionContext); + frame.InitializeHeaders(); + + var headerArray = Encoding.ASCII.GetBytes(rawHeaders); + socketInput.IncomingData(headerArray, 0, headerArray.Length); + + Assert.Throws(() => frame.TakeMessageHeaders(socketInput, (FrameRequestHeaders)frame.RequestHeaders)); + } + } + + [Theory] + [InlineData("Header-1: value1\r\r\n")] + [InlineData("Header-1: value1\rHeader-2: value2\r\n\r\n")] + [InlineData("Header-1: value1\r\nHeader-2: value2\r\r\n")] + public void ThrowsOnHeaderLineNotEndingInCRLF(string rawHeaders) + { + var trace = new KestrelTrace(new TestKestrelTrace()); + var ltp = new LoggingThreadPool(trace); + using (var pool = new MemoryPool()) + using (var socketInput = new SocketInput(pool, ltp)) + { + var connectionContext = new ConnectionContext() + { + DateHeaderValueManager = new DateHeaderValueManager(), + ServerAddress = ServerAddress.FromUrl("http://localhost:5000"), + Log = trace + }; + var frame = new Frame(application: null, context: connectionContext); + frame.InitializeHeaders(); + + var headerArray = Encoding.ASCII.GetBytes(rawHeaders); + socketInput.IncomingData(headerArray, 0, headerArray.Length); + + Assert.Throws(() => frame.TakeMessageHeaders(socketInput, (FrameRequestHeaders)frame.RequestHeaders)); + } + } + + [Theory] + [InlineData("Header-1 value1\r\n\r\n")] + [InlineData("Header-1 value1\r\nHeader-2: value2\r\n\r\n")] + [InlineData("Header-1: value1\r\nHeader-2 value2\r\n\r\n")] + public void ThrowsOnHeaderLineMissingColon(string rawHeaders) + { + var trace = new KestrelTrace(new TestKestrelTrace()); + var ltp = new LoggingThreadPool(trace); + using (var pool = new MemoryPool()) + using (var socketInput = new SocketInput(pool, ltp)) + { + var connectionContext = new ConnectionContext() + { + DateHeaderValueManager = new DateHeaderValueManager(), + ServerAddress = ServerAddress.FromUrl("http://localhost:5000"), + Log = trace + }; + var frame = new Frame(application: null, context: connectionContext); + frame.InitializeHeaders(); + + var headerArray = Encoding.ASCII.GetBytes(rawHeaders); + socketInput.IncomingData(headerArray, 0, headerArray.Length); + + Assert.Throws(() => frame.TakeMessageHeaders(socketInput, (FrameRequestHeaders)frame.RequestHeaders)); + } + } + + [Theory] + [InlineData(" Header: value\r\n\r\n")] + [InlineData("\tHeader: value\r\n\r\n")] + [InlineData(" Header-1: value1\r\nHeader-2: value2\r\n\r\n")] + [InlineData("\tHeader-1: value1\r\nHeader-2: value2\r\n\r\n")] + [InlineData("Header-1: value1\r\n Header-2: value2\r\n\r\n")] + [InlineData("Header-1: value1\r\n\tHeader-2: value2\r\n\r\n")] + public void ThrowsOnHeaderLineStartingWithWhitespace(string rawHeaders) + { + var trace = new KestrelTrace(new TestKestrelTrace()); + var ltp = new LoggingThreadPool(trace); + using (var pool = new MemoryPool()) + using (var socketInput = new SocketInput(pool, ltp)) + { + var connectionContext = new ConnectionContext() + { + DateHeaderValueManager = new DateHeaderValueManager(), + ServerAddress = ServerAddress.FromUrl("http://localhost:5000"), + Log = trace + }; + var frame = new Frame(application: null, context: connectionContext); + frame.InitializeHeaders(); + + var headerArray = Encoding.ASCII.GetBytes(rawHeaders); + socketInput.IncomingData(headerArray, 0, headerArray.Length); + + Assert.Throws(() => frame.TakeMessageHeaders(socketInput, (FrameRequestHeaders)frame.RequestHeaders)); + } + } + + [Theory] + [InlineData("Header : value\r\n\r\n")] + [InlineData("Header\t: value\r\n\r\n")] + [InlineData("Header 1: value1\r\nHeader-2: value2\r\n\r\n")] + [InlineData("Header 1 : value1\r\nHeader-2: value2\r\n\r\n")] + [InlineData("Header 1\t: value1\r\nHeader-2: value2\r\n\r\n")] + [InlineData("Header-1: value1\r\nHeader 2: value2\r\n\r\n")] + [InlineData("Header-1: value1\r\nHeader-2 : value2\r\n\r\n")] + [InlineData("Header-1: value1\r\nHeader-2\t: value2\r\n\r\n")] + public void ThrowsOnWhitespaceInHeaderName(string rawHeaders) + { + var trace = new KestrelTrace(new TestKestrelTrace()); + var ltp = new LoggingThreadPool(trace); + using (var pool = new MemoryPool()) + using (var socketInput = new SocketInput(pool, ltp)) + { + var connectionContext = new ConnectionContext() + { + DateHeaderValueManager = new DateHeaderValueManager(), + ServerAddress = ServerAddress.FromUrl("http://localhost:5000"), + Log = trace + }; + var frame = new Frame(application: null, context: connectionContext); + frame.InitializeHeaders(); + + var headerArray = Encoding.ASCII.GetBytes(rawHeaders); + socketInput.IncomingData(headerArray, 0, headerArray.Length); + + Assert.Throws(() => frame.TakeMessageHeaders(socketInput, (FrameRequestHeaders)frame.RequestHeaders)); + } + } + + [Theory] + [InlineData("Header-1: value1\r\nHeader-2: value2\r\n\r ")] + [InlineData("Header-1: value1\r\nHeader-2: value2\r\nEnd\r\n")] + public void ThrowsOnHeadersNotEndingInCRLFLine(string rawHeaders) + { + var trace = new KestrelTrace(new TestKestrelTrace()); + var ltp = new LoggingThreadPool(trace); + using (var pool = new MemoryPool()) + using (var socketInput = new SocketInput(pool, ltp)) + { + var connectionContext = new ConnectionContext() + { + DateHeaderValueManager = new DateHeaderValueManager(), + ServerAddress = ServerAddress.FromUrl("http://localhost:5000"), + Log = trace + }; + var frame = new Frame(application: null, context: connectionContext); + frame.InitializeHeaders(); + + var headerArray = Encoding.ASCII.GetBytes(rawHeaders); + socketInput.IncomingData(headerArray, 0, headerArray.Length); + + Assert.Throws(() => frame.TakeMessageHeaders(socketInput, (FrameRequestHeaders)frame.RequestHeaders)); + } + } + [Theory] [InlineData("Cookie: \r\n\r\n", 1)] [InlineData("Cookie:\r\n\r\n", 1)] - [InlineData("Cookie:\r\n value\r\n\r\n", 1)] - [InlineData("Cookie\r\n", 0)] [InlineData("Cookie: \r\nConnection: close\r\n\r\n", 2)] + [InlineData("Cookie:\r\nConnection: close\r\n\r\n", 2)] [InlineData("Connection: close\r\nCookie: \r\n\r\n", 2)] - [InlineData("Connection: close\r\nCookie \r\n", 1)] - [InlineData("Connection:\r\n \r\nCookie \r\n", 1)] + [InlineData("Connection: close\r\nCookie:\r\n\r\n", 2)] public void EmptyHeaderValuesCanBeParsed(string rawHeaders, int numHeaders) { var trace = new KestrelTrace(new TestKestrelTrace()); @@ -38,15 +362,15 @@ namespace Microsoft.AspNetCore.Server.KestrelTests ServerAddress = ServerAddress.FromUrl("http://localhost:5000") }; var frame = new Frame(application: null, context: connectionContext); - var headerCollection = new FrameRequestHeaders(); + frame.InitializeHeaders(); var headerArray = Encoding.ASCII.GetBytes(rawHeaders); socketInput.IncomingData(headerArray, 0, headerArray.Length); - var success = frame.TakeMessageHeaders(socketInput, headerCollection); + var success = frame.TakeMessageHeaders(socketInput, (FrameRequestHeaders)frame.RequestHeaders); Assert.True(success); - Assert.Equal(numHeaders, headerCollection.Count()); + Assert.Equal(numHeaders, frame.RequestHeaders.Count); // Assert TakeMessageHeaders consumed all the input var scan = socketInput.ConsumingStart(); From 0342754c5770e1512b6d77979a6a2ba9937b76bc Mon Sep 17 00:00:00 2001 From: moozzyk Date: Fri, 27 May 2016 11:03:05 -0700 Subject: [PATCH 0771/1662] Using the optimized method for converting header name to ASCII --- .../Http/FrameHeaders.Generated.cs | 867 +++++++++--------- .../BadHttpRequestTests.cs | 17 + .../FrameRequestHeadersTests.cs | 13 + .../TestConnection.cs | 2 +- .../KnownHeaders.cs | 51 +- 5 files changed, 499 insertions(+), 451 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameHeaders.Generated.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameHeaders.Generated.cs index bf47376156..804b9a9228 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameHeaders.Generated.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameHeaders.Generated.cs @@ -1,16 +1,16 @@ using System; using System.Collections.Generic; -using System.Text; +using Microsoft.AspNetCore.Server.Kestrel.Exceptions; using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; using Microsoft.Extensions.Primitives; -namespace Microsoft.AspNetCore.Server.Kestrel.Http +namespace Microsoft.AspNetCore.Server.Kestrel.Http { public partial class FrameRequestHeaders { - + private long _bits = 0; private HeaderReferences _headers; @@ -1331,7 +1331,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } break; } - if (MaybeUnknown == null) + if (MaybeUnknown == null) { ThrowKeyNotFoundException(); } @@ -1343,7 +1343,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { case 13: { - if ("Cache-Control".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Cache-Control".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 1L) != 0)) { @@ -1357,7 +1357,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } - if ("Content-Range".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Content-Range".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 131072L) != 0)) { @@ -1371,7 +1371,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } - if ("Last-Modified".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Last-Modified".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 524288L) != 0)) { @@ -1385,7 +1385,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } - if ("Authorization".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Authorization".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 16777216L) != 0)) { @@ -1399,7 +1399,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } - if ("If-None-Match".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("If-None-Match".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 2147483648L) != 0)) { @@ -1417,7 +1417,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http case 10: { - if ("Connection".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Connection".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 2L) != 0)) { @@ -1431,7 +1431,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } - if ("Keep-Alive".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Keep-Alive".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 8L) != 0)) { @@ -1445,7 +1445,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } - if ("User-Agent".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("User-Agent".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 1099511627776L) != 0)) { @@ -1463,7 +1463,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http case 4: { - if ("Date".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Date".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 4L) != 0)) { @@ -1477,7 +1477,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } - if ("From".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("From".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 134217728L) != 0)) { @@ -1491,7 +1491,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } - if ("Host".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Host".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 268435456L) != 0)) { @@ -1509,7 +1509,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http case 6: { - if ("Pragma".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Pragma".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 16L) != 0)) { @@ -1523,7 +1523,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } - if ("Accept".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Accept".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 1048576L) != 0)) { @@ -1537,7 +1537,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } - if ("Cookie".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Cookie".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 33554432L) != 0)) { @@ -1551,7 +1551,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } - if ("Expect".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Expect".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 67108864L) != 0)) { @@ -1565,7 +1565,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } - if ("Origin".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Origin".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 2199023255552L) != 0)) { @@ -1583,7 +1583,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http case 7: { - if ("Trailer".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Trailer".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 32L) != 0)) { @@ -1597,7 +1597,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } - if ("Upgrade".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Upgrade".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 128L) != 0)) { @@ -1611,7 +1611,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } - if ("Warning".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Warning".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 512L) != 0)) { @@ -1625,7 +1625,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } - if ("Expires".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Expires".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 262144L) != 0)) { @@ -1639,7 +1639,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } - if ("Referer".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Referer".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 68719476736L) != 0)) { @@ -1657,7 +1657,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http case 17: { - if ("Transfer-Encoding".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Transfer-Encoding".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 64L) != 0)) { @@ -1671,7 +1671,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } - if ("If-Modified-Since".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("If-Modified-Since".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 1073741824L) != 0)) { @@ -1689,7 +1689,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http case 3: { - if ("Via".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Via".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 256L) != 0)) { @@ -1707,7 +1707,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http case 5: { - if ("Allow".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Allow".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 1024L) != 0)) { @@ -1721,7 +1721,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } - if ("Range".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Range".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 137438953472L) != 0)) { @@ -1739,7 +1739,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http case 14: { - if ("Content-Length".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Content-Length".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 2048L) != 0)) { @@ -1753,7 +1753,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } - if ("Accept-Charset".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Accept-Charset".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 2097152L) != 0)) { @@ -1771,7 +1771,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http case 12: { - if ("Content-Type".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Content-Type".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 4096L) != 0)) { @@ -1785,7 +1785,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } - if ("Max-Forwards".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Max-Forwards".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 17179869184L) != 0)) { @@ -1803,7 +1803,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http case 16: { - if ("Content-Encoding".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Content-Encoding".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 8192L) != 0)) { @@ -1817,7 +1817,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } - if ("Content-Language".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Content-Language".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 16384L) != 0)) { @@ -1831,7 +1831,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } - if ("Content-Location".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Content-Location".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 32768L) != 0)) { @@ -1849,7 +1849,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http case 11: { - if ("Content-MD5".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Content-MD5".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 65536L) != 0)) { @@ -1867,7 +1867,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http case 15: { - if ("Accept-Encoding".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Accept-Encoding".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 4194304L) != 0)) { @@ -1881,7 +1881,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } - if ("Accept-Language".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Accept-Language".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 8388608L) != 0)) { @@ -1899,7 +1899,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http case 8: { - if ("If-Match".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("If-Match".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 536870912L) != 0)) { @@ -1913,7 +1913,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } - if ("If-Range".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("If-Range".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 4294967296L) != 0)) { @@ -1931,7 +1931,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http case 19: { - if ("If-Unmodified-Since".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("If-Unmodified-Since".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 8589934592L) != 0)) { @@ -1945,7 +1945,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } - if ("Proxy-Authorization".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Proxy-Authorization".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 34359738368L) != 0)) { @@ -1963,7 +1963,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http case 2: { - if ("TE".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("TE".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 274877906944L) != 0)) { @@ -1981,7 +1981,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http case 9: { - if ("Translate".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Translate".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 549755813888L) != 0)) { @@ -1999,7 +1999,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http case 29: { - if ("Access-Control-Request-Method".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Access-Control-Request-Method".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 4398046511104L) != 0)) { @@ -2017,7 +2017,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http case 30: { - if ("Access-Control-Request-Headers".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Access-Control-Request-Headers".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 8796093022208L) != 0)) { @@ -2043,35 +2043,35 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { case 13: { - if ("Cache-Control".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Cache-Control".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 1L; _headers._CacheControl = value; return; } - if ("Content-Range".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Content-Range".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 131072L; _headers._ContentRange = value; return; } - if ("Last-Modified".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Last-Modified".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 524288L; _headers._LastModified = value; return; } - if ("Authorization".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Authorization".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 16777216L; _headers._Authorization = value; return; } - if ("If-None-Match".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("If-None-Match".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 2147483648L; _headers._IfNoneMatch = value; @@ -2082,21 +2082,21 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http case 10: { - if ("Connection".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Connection".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 2L; _headers._Connection = value; return; } - if ("Keep-Alive".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Keep-Alive".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 8L; _headers._KeepAlive = value; return; } - if ("User-Agent".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("User-Agent".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 1099511627776L; _headers._UserAgent = value; @@ -2107,21 +2107,21 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http case 4: { - if ("Date".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Date".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 4L; _headers._Date = value; return; } - if ("From".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("From".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 134217728L; _headers._From = value; return; } - if ("Host".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Host".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 268435456L; _headers._Host = value; @@ -2132,35 +2132,35 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http case 6: { - if ("Pragma".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Pragma".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 16L; _headers._Pragma = value; return; } - if ("Accept".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Accept".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 1048576L; _headers._Accept = value; return; } - if ("Cookie".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Cookie".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 33554432L; _headers._Cookie = value; return; } - if ("Expect".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Expect".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 67108864L; _headers._Expect = value; return; } - if ("Origin".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Origin".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 2199023255552L; _headers._Origin = value; @@ -2171,35 +2171,35 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http case 7: { - if ("Trailer".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Trailer".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 32L; _headers._Trailer = value; return; } - if ("Upgrade".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Upgrade".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 128L; _headers._Upgrade = value; return; } - if ("Warning".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Warning".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 512L; _headers._Warning = value; return; } - if ("Expires".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Expires".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 262144L; _headers._Expires = value; return; } - if ("Referer".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Referer".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 68719476736L; _headers._Referer = value; @@ -2210,14 +2210,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http case 17: { - if ("Transfer-Encoding".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Transfer-Encoding".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 64L; _headers._TransferEncoding = value; return; } - if ("If-Modified-Since".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("If-Modified-Since".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 1073741824L; _headers._IfModifiedSince = value; @@ -2228,7 +2228,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http case 3: { - if ("Via".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Via".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 256L; _headers._Via = value; @@ -2239,14 +2239,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http case 5: { - if ("Allow".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Allow".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 1024L; _headers._Allow = value; return; } - if ("Range".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Range".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 137438953472L; _headers._Range = value; @@ -2257,14 +2257,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http case 14: { - if ("Content-Length".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Content-Length".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 2048L; _headers._ContentLength = value; return; } - if ("Accept-Charset".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Accept-Charset".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 2097152L; _headers._AcceptCharset = value; @@ -2275,14 +2275,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http case 12: { - if ("Content-Type".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Content-Type".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 4096L; _headers._ContentType = value; return; } - if ("Max-Forwards".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Max-Forwards".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 17179869184L; _headers._MaxForwards = value; @@ -2293,21 +2293,21 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http case 16: { - if ("Content-Encoding".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Content-Encoding".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 8192L; _headers._ContentEncoding = value; return; } - if ("Content-Language".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Content-Language".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 16384L; _headers._ContentLanguage = value; return; } - if ("Content-Location".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Content-Location".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 32768L; _headers._ContentLocation = value; @@ -2318,7 +2318,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http case 11: { - if ("Content-MD5".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Content-MD5".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 65536L; _headers._ContentMD5 = value; @@ -2329,14 +2329,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http case 15: { - if ("Accept-Encoding".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Accept-Encoding".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 4194304L; _headers._AcceptEncoding = value; return; } - if ("Accept-Language".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Accept-Language".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 8388608L; _headers._AcceptLanguage = value; @@ -2347,14 +2347,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http case 8: { - if ("If-Match".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("If-Match".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 536870912L; _headers._IfMatch = value; return; } - if ("If-Range".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("If-Range".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 4294967296L; _headers._IfRange = value; @@ -2365,14 +2365,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http case 19: { - if ("If-Unmodified-Since".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("If-Unmodified-Since".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 8589934592L; _headers._IfUnmodifiedSince = value; return; } - if ("Proxy-Authorization".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Proxy-Authorization".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 34359738368L; _headers._ProxyAuthorization = value; @@ -2383,7 +2383,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http case 2: { - if ("TE".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("TE".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 274877906944L; _headers._TE = value; @@ -2394,7 +2394,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http case 9: { - if ("Translate".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Translate".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 549755813888L; _headers._Translate = value; @@ -2405,7 +2405,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http case 29: { - if ("Access-Control-Request-Method".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Access-Control-Request-Method".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 4398046511104L; _headers._AccessControlRequestMethod = value; @@ -2416,7 +2416,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http case 30: { - if ("Access-Control-Request-Headers".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Access-Control-Request-Headers".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 8796093022208L; _headers._AccessControlRequestHeaders = value; @@ -3002,7 +3002,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { case 13: { - if ("Cache-Control".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Cache-Control".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 1L) != 0)) { @@ -3016,7 +3016,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } - if ("Content-Range".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Content-Range".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 131072L) != 0)) { @@ -3030,7 +3030,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } - if ("Last-Modified".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Last-Modified".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 524288L) != 0)) { @@ -3044,7 +3044,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } - if ("Authorization".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Authorization".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 16777216L) != 0)) { @@ -3058,7 +3058,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } - if ("If-None-Match".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("If-None-Match".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 2147483648L) != 0)) { @@ -3076,7 +3076,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http case 10: { - if ("Connection".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Connection".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 2L) != 0)) { @@ -3090,7 +3090,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } - if ("Keep-Alive".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Keep-Alive".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 8L) != 0)) { @@ -3104,7 +3104,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } - if ("User-Agent".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("User-Agent".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 1099511627776L) != 0)) { @@ -3122,7 +3122,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http case 4: { - if ("Date".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Date".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 4L) != 0)) { @@ -3136,7 +3136,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } - if ("From".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("From".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 134217728L) != 0)) { @@ -3150,7 +3150,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } - if ("Host".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Host".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 268435456L) != 0)) { @@ -3168,7 +3168,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http case 6: { - if ("Pragma".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Pragma".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 16L) != 0)) { @@ -3182,7 +3182,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } - if ("Accept".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Accept".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 1048576L) != 0)) { @@ -3196,7 +3196,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } - if ("Cookie".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Cookie".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 33554432L) != 0)) { @@ -3210,7 +3210,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } - if ("Expect".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Expect".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 67108864L) != 0)) { @@ -3224,7 +3224,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } - if ("Origin".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Origin".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 2199023255552L) != 0)) { @@ -3242,7 +3242,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http case 7: { - if ("Trailer".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Trailer".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 32L) != 0)) { @@ -3256,7 +3256,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } - if ("Upgrade".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Upgrade".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 128L) != 0)) { @@ -3270,7 +3270,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } - if ("Warning".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Warning".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 512L) != 0)) { @@ -3284,7 +3284,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } - if ("Expires".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Expires".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 262144L) != 0)) { @@ -3298,7 +3298,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } - if ("Referer".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Referer".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 68719476736L) != 0)) { @@ -3316,7 +3316,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http case 17: { - if ("Transfer-Encoding".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Transfer-Encoding".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 64L) != 0)) { @@ -3330,7 +3330,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } - if ("If-Modified-Since".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("If-Modified-Since".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 1073741824L) != 0)) { @@ -3348,7 +3348,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http case 3: { - if ("Via".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Via".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 256L) != 0)) { @@ -3366,7 +3366,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http case 5: { - if ("Allow".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Allow".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 1024L) != 0)) { @@ -3380,7 +3380,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } - if ("Range".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Range".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 137438953472L) != 0)) { @@ -3398,7 +3398,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http case 14: { - if ("Content-Length".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Content-Length".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 2048L) != 0)) { @@ -3412,7 +3412,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } - if ("Accept-Charset".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Accept-Charset".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 2097152L) != 0)) { @@ -3430,7 +3430,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http case 12: { - if ("Content-Type".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Content-Type".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 4096L) != 0)) { @@ -3444,7 +3444,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } - if ("Max-Forwards".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Max-Forwards".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 17179869184L) != 0)) { @@ -3462,7 +3462,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http case 16: { - if ("Content-Encoding".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Content-Encoding".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 8192L) != 0)) { @@ -3476,7 +3476,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } - if ("Content-Language".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Content-Language".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 16384L) != 0)) { @@ -3490,7 +3490,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } - if ("Content-Location".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Content-Location".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 32768L) != 0)) { @@ -3508,7 +3508,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http case 11: { - if ("Content-MD5".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Content-MD5".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 65536L) != 0)) { @@ -3526,7 +3526,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http case 15: { - if ("Accept-Encoding".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Accept-Encoding".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 4194304L) != 0)) { @@ -3540,7 +3540,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } - if ("Accept-Language".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Accept-Language".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 8388608L) != 0)) { @@ -3558,7 +3558,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http case 8: { - if ("If-Match".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("If-Match".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 536870912L) != 0)) { @@ -3572,7 +3572,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } - if ("If-Range".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("If-Range".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 4294967296L) != 0)) { @@ -3590,7 +3590,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http case 19: { - if ("If-Unmodified-Since".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("If-Unmodified-Since".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 8589934592L) != 0)) { @@ -3604,7 +3604,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } - if ("Proxy-Authorization".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Proxy-Authorization".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 34359738368L) != 0)) { @@ -3622,7 +3622,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http case 2: { - if ("TE".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("TE".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 274877906944L) != 0)) { @@ -3640,7 +3640,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http case 9: { - if ("Translate".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Translate".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 549755813888L) != 0)) { @@ -3658,7 +3658,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http case 29: { - if ("Access-Control-Request-Method".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Access-Control-Request-Method".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 4398046511104L) != 0)) { @@ -3676,7 +3676,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http case 30: { - if ("Access-Control-Request-Headers".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Access-Control-Request-Headers".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 8796093022208L) != 0)) { @@ -3700,7 +3700,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http _headers = default(HeaderReferences); MaybeUnknown?.Clear(); } - + protected override void CopyToFast(KeyValuePair[] array, int arrayIndex) { if (arrayIndex < 0) @@ -3708,7 +3708,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowArgumentException(); } - if (((_bits & 1L) != 0)) + if (((_bits & 1L) != 0)) { if (arrayIndex == array.Length) { @@ -3719,7 +3719,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ++arrayIndex; } - if (((_bits & 2L) != 0)) + if (((_bits & 2L) != 0)) { if (arrayIndex == array.Length) { @@ -3730,7 +3730,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ++arrayIndex; } - if (((_bits & 4L) != 0)) + if (((_bits & 4L) != 0)) { if (arrayIndex == array.Length) { @@ -3741,7 +3741,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ++arrayIndex; } - if (((_bits & 8L) != 0)) + if (((_bits & 8L) != 0)) { if (arrayIndex == array.Length) { @@ -3752,7 +3752,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ++arrayIndex; } - if (((_bits & 16L) != 0)) + if (((_bits & 16L) != 0)) { if (arrayIndex == array.Length) { @@ -3763,7 +3763,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ++arrayIndex; } - if (((_bits & 32L) != 0)) + if (((_bits & 32L) != 0)) { if (arrayIndex == array.Length) { @@ -3774,7 +3774,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ++arrayIndex; } - if (((_bits & 64L) != 0)) + if (((_bits & 64L) != 0)) { if (arrayIndex == array.Length) { @@ -3785,7 +3785,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ++arrayIndex; } - if (((_bits & 128L) != 0)) + if (((_bits & 128L) != 0)) { if (arrayIndex == array.Length) { @@ -3796,7 +3796,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ++arrayIndex; } - if (((_bits & 256L) != 0)) + if (((_bits & 256L) != 0)) { if (arrayIndex == array.Length) { @@ -3807,7 +3807,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ++arrayIndex; } - if (((_bits & 512L) != 0)) + if (((_bits & 512L) != 0)) { if (arrayIndex == array.Length) { @@ -3818,7 +3818,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ++arrayIndex; } - if (((_bits & 1024L) != 0)) + if (((_bits & 1024L) != 0)) { if (arrayIndex == array.Length) { @@ -3829,7 +3829,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ++arrayIndex; } - if (((_bits & 2048L) != 0)) + if (((_bits & 2048L) != 0)) { if (arrayIndex == array.Length) { @@ -3840,7 +3840,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ++arrayIndex; } - if (((_bits & 4096L) != 0)) + if (((_bits & 4096L) != 0)) { if (arrayIndex == array.Length) { @@ -3851,7 +3851,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ++arrayIndex; } - if (((_bits & 8192L) != 0)) + if (((_bits & 8192L) != 0)) { if (arrayIndex == array.Length) { @@ -3862,7 +3862,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ++arrayIndex; } - if (((_bits & 16384L) != 0)) + if (((_bits & 16384L) != 0)) { if (arrayIndex == array.Length) { @@ -3873,7 +3873,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ++arrayIndex; } - if (((_bits & 32768L) != 0)) + if (((_bits & 32768L) != 0)) { if (arrayIndex == array.Length) { @@ -3884,7 +3884,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ++arrayIndex; } - if (((_bits & 65536L) != 0)) + if (((_bits & 65536L) != 0)) { if (arrayIndex == array.Length) { @@ -3895,7 +3895,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ++arrayIndex; } - if (((_bits & 131072L) != 0)) + if (((_bits & 131072L) != 0)) { if (arrayIndex == array.Length) { @@ -3906,7 +3906,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ++arrayIndex; } - if (((_bits & 262144L) != 0)) + if (((_bits & 262144L) != 0)) { if (arrayIndex == array.Length) { @@ -3917,7 +3917,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ++arrayIndex; } - if (((_bits & 524288L) != 0)) + if (((_bits & 524288L) != 0)) { if (arrayIndex == array.Length) { @@ -3928,7 +3928,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ++arrayIndex; } - if (((_bits & 1048576L) != 0)) + if (((_bits & 1048576L) != 0)) { if (arrayIndex == array.Length) { @@ -3939,7 +3939,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ++arrayIndex; } - if (((_bits & 2097152L) != 0)) + if (((_bits & 2097152L) != 0)) { if (arrayIndex == array.Length) { @@ -3950,7 +3950,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ++arrayIndex; } - if (((_bits & 4194304L) != 0)) + if (((_bits & 4194304L) != 0)) { if (arrayIndex == array.Length) { @@ -3961,7 +3961,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ++arrayIndex; } - if (((_bits & 8388608L) != 0)) + if (((_bits & 8388608L) != 0)) { if (arrayIndex == array.Length) { @@ -3972,7 +3972,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ++arrayIndex; } - if (((_bits & 16777216L) != 0)) + if (((_bits & 16777216L) != 0)) { if (arrayIndex == array.Length) { @@ -3983,7 +3983,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ++arrayIndex; } - if (((_bits & 33554432L) != 0)) + if (((_bits & 33554432L) != 0)) { if (arrayIndex == array.Length) { @@ -3994,7 +3994,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ++arrayIndex; } - if (((_bits & 67108864L) != 0)) + if (((_bits & 67108864L) != 0)) { if (arrayIndex == array.Length) { @@ -4005,7 +4005,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ++arrayIndex; } - if (((_bits & 134217728L) != 0)) + if (((_bits & 134217728L) != 0)) { if (arrayIndex == array.Length) { @@ -4016,7 +4016,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ++arrayIndex; } - if (((_bits & 268435456L) != 0)) + if (((_bits & 268435456L) != 0)) { if (arrayIndex == array.Length) { @@ -4027,7 +4027,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ++arrayIndex; } - if (((_bits & 536870912L) != 0)) + if (((_bits & 536870912L) != 0)) { if (arrayIndex == array.Length) { @@ -4038,7 +4038,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ++arrayIndex; } - if (((_bits & 1073741824L) != 0)) + if (((_bits & 1073741824L) != 0)) { if (arrayIndex == array.Length) { @@ -4049,7 +4049,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ++arrayIndex; } - if (((_bits & 2147483648L) != 0)) + if (((_bits & 2147483648L) != 0)) { if (arrayIndex == array.Length) { @@ -4060,7 +4060,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ++arrayIndex; } - if (((_bits & 4294967296L) != 0)) + if (((_bits & 4294967296L) != 0)) { if (arrayIndex == array.Length) { @@ -4071,7 +4071,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ++arrayIndex; } - if (((_bits & 8589934592L) != 0)) + if (((_bits & 8589934592L) != 0)) { if (arrayIndex == array.Length) { @@ -4082,7 +4082,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ++arrayIndex; } - if (((_bits & 17179869184L) != 0)) + if (((_bits & 17179869184L) != 0)) { if (arrayIndex == array.Length) { @@ -4093,7 +4093,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ++arrayIndex; } - if (((_bits & 34359738368L) != 0)) + if (((_bits & 34359738368L) != 0)) { if (arrayIndex == array.Length) { @@ -4104,7 +4104,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ++arrayIndex; } - if (((_bits & 68719476736L) != 0)) + if (((_bits & 68719476736L) != 0)) { if (arrayIndex == array.Length) { @@ -4115,7 +4115,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ++arrayIndex; } - if (((_bits & 137438953472L) != 0)) + if (((_bits & 137438953472L) != 0)) { if (arrayIndex == array.Length) { @@ -4126,7 +4126,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ++arrayIndex; } - if (((_bits & 274877906944L) != 0)) + if (((_bits & 274877906944L) != 0)) { if (arrayIndex == array.Length) { @@ -4137,7 +4137,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ++arrayIndex; } - if (((_bits & 549755813888L) != 0)) + if (((_bits & 549755813888L) != 0)) { if (arrayIndex == array.Length) { @@ -4148,7 +4148,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ++arrayIndex; } - if (((_bits & 1099511627776L) != 0)) + if (((_bits & 1099511627776L) != 0)) { if (arrayIndex == array.Length) { @@ -4159,7 +4159,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ++arrayIndex; } - if (((_bits & 2199023255552L) != 0)) + if (((_bits & 2199023255552L) != 0)) { if (arrayIndex == array.Length) { @@ -4170,7 +4170,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ++arrayIndex; } - if (((_bits & 4398046511104L) != 0)) + if (((_bits & 4398046511104L) != 0)) { if (arrayIndex == array.Length) { @@ -4181,7 +4181,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ++arrayIndex; } - if (((_bits & 8796093022208L) != 0)) + if (((_bits & 8796093022208L) != 0)) { if (arrayIndex == array.Length) { @@ -4198,17 +4198,18 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http public unsafe void Append(byte[] keyBytes, int keyOffset, int keyLength, string value) { - fixed (byte* ptr = &keyBytes[keyOffset]) - { - var pUB = ptr; - var pUL = (ulong*)pUB; - var pUI = (uint*)pUB; + var key = new string('\0', keyLength); + fixed (byte* ptr = &keyBytes[keyOffset]) + { + var pUB = ptr; + var pUL = (ulong*)pUB; + var pUI = (uint*)pUB; var pUS = (ushort*)pUB; switch (keyLength) { case 13: { - if ((((pUL[0] & 16131893727263186911uL) == 5711458528024281411uL) && ((pUI[2] & 3755991007u) == 1330795598u) && ((pUB[12] & 223u) == 76u))) + if ((((pUL[0] & 16131893727263186911uL) == 5711458528024281411uL) && ((pUI[2] & 3755991007u) == 1330795598u) && ((pUB[12] & 223u) == 76u))) { if (((_bits & 1L) != 0)) { @@ -4222,7 +4223,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http return; } - if ((((pUL[0] & 18437701552104792031uL) == 3266321689424580419uL) && ((pUI[2] & 3755991007u) == 1196310866u) && ((pUB[12] & 223u) == 69u))) + if ((((pUL[0] & 18437701552104792031uL) == 3266321689424580419uL) && ((pUI[2] & 3755991007u) == 1196310866u) && ((pUB[12] & 223u) == 69u))) { if (((_bits & 131072L) != 0)) { @@ -4236,7 +4237,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http return; } - if ((((pUL[0] & 16131858680330051551uL) == 4922237774822850892uL) && ((pUI[2] & 3755991007u) == 1162430025u) && ((pUB[12] & 223u) == 68u))) + if ((((pUL[0] & 16131858680330051551uL) == 4922237774822850892uL) && ((pUI[2] & 3755991007u) == 1162430025u) && ((pUB[12] & 223u) == 68u))) { if (((_bits & 524288L) != 0)) { @@ -4250,7 +4251,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http return; } - if ((((pUL[0] & 16131858542891098079uL) == 6505821637182772545uL) && ((pUI[2] & 3755991007u) == 1330205761u) && ((pUB[12] & 223u) == 78u))) + if ((((pUL[0] & 16131858542891098079uL) == 6505821637182772545uL) && ((pUI[2] & 3755991007u) == 1330205761u) && ((pUB[12] & 223u) == 78u))) { if (((_bits & 16777216L) != 0)) { @@ -4264,7 +4265,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http return; } - if ((((pUL[0] & 18437701552106889183uL) == 3262099607620765257uL) && ((pUI[2] & 3755991007u) == 1129595213u) && ((pUB[12] & 223u) == 72u))) + if ((((pUL[0] & 18437701552106889183uL) == 3262099607620765257uL) && ((pUI[2] & 3755991007u) == 1129595213u) && ((pUB[12] & 223u) == 72u))) { if (((_bits & 2147483648L) != 0)) { @@ -4282,7 +4283,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http case 10: { - if ((((pUL[0] & 16131858542891098079uL) == 5283922227757993795uL) && ((pUS[4] & 57311u) == 20047u))) + if ((((pUL[0] & 16131858542891098079uL) == 5283922227757993795uL) && ((pUS[4] & 57311u) == 20047u))) { if (((_bits & 2L) != 0)) { @@ -4296,7 +4297,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http return; } - if ((((pUL[0] & 16131858680330051551uL) == 5281668125874799947uL) && ((pUS[4] & 57311u) == 17750u))) + if ((((pUL[0] & 16131858680330051551uL) == 5281668125874799947uL) && ((pUS[4] & 57311u) == 17750u))) { if (((_bits & 8L) != 0)) { @@ -4310,7 +4311,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http return; } - if ((((pUL[0] & 16131858680330051551uL) == 4992030374873092949uL) && ((pUS[4] & 57311u) == 21582u))) + if ((((pUL[0] & 16131858680330051551uL) == 4992030374873092949uL) && ((pUS[4] & 57311u) == 21582u))) { if (((_bits & 1099511627776L) != 0)) { @@ -4328,7 +4329,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http case 4: { - if ((((pUI[0] & 3755991007u) == 1163149636u))) + if ((((pUI[0] & 3755991007u) == 1163149636u))) { if (((_bits & 4L) != 0)) { @@ -4342,7 +4343,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http return; } - if ((((pUI[0] & 3755991007u) == 1297044038u))) + if ((((pUI[0] & 3755991007u) == 1297044038u))) { if (((_bits & 134217728L) != 0)) { @@ -4356,7 +4357,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http return; } - if ((((pUI[0] & 3755991007u) == 1414745928u))) + if ((((pUI[0] & 3755991007u) == 1414745928u))) { if (((_bits & 268435456L) != 0)) { @@ -4374,7 +4375,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http case 6: { - if ((((pUI[0] & 3755991007u) == 1195463248u) && ((pUS[2] & 57311u) == 16717u))) + if ((((pUI[0] & 3755991007u) == 1195463248u) && ((pUS[2] & 57311u) == 16717u))) { if (((_bits & 16L) != 0)) { @@ -4388,7 +4389,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http return; } - if ((((pUI[0] & 3755991007u) == 1162036033u) && ((pUS[2] & 57311u) == 21584u))) + if ((((pUI[0] & 3755991007u) == 1162036033u) && ((pUS[2] & 57311u) == 21584u))) { if (((_bits & 1048576L) != 0)) { @@ -4402,7 +4403,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http return; } - if ((((pUI[0] & 3755991007u) == 1263488835u) && ((pUS[2] & 57311u) == 17737u))) + if ((((pUI[0] & 3755991007u) == 1263488835u) && ((pUS[2] & 57311u) == 17737u))) { if (((_bits & 33554432L) != 0)) { @@ -4416,7 +4417,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http return; } - if ((((pUI[0] & 3755991007u) == 1162893381u) && ((pUS[2] & 57311u) == 21571u))) + if ((((pUI[0] & 3755991007u) == 1162893381u) && ((pUS[2] & 57311u) == 21571u))) { if (((_bits & 67108864L) != 0)) { @@ -4430,7 +4431,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http return; } - if ((((pUI[0] & 3755991007u) == 1195987535u) && ((pUS[2] & 57311u) == 20041u))) + if ((((pUI[0] & 3755991007u) == 1195987535u) && ((pUS[2] & 57311u) == 20041u))) { if (((_bits & 2199023255552L) != 0)) { @@ -4448,7 +4449,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http case 7: { - if ((((pUI[0] & 3755991007u) == 1229017684u) && ((pUS[2] & 57311u) == 17740u) && ((pUB[6] & 223u) == 82u))) + if ((((pUI[0] & 3755991007u) == 1229017684u) && ((pUS[2] & 57311u) == 17740u) && ((pUB[6] & 223u) == 82u))) { if (((_bits & 32L) != 0)) { @@ -4462,7 +4463,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http return; } - if ((((pUI[0] & 3755991007u) == 1380405333u) && ((pUS[2] & 57311u) == 17473u) && ((pUB[6] & 223u) == 69u))) + if ((((pUI[0] & 3755991007u) == 1380405333u) && ((pUS[2] & 57311u) == 17473u) && ((pUB[6] & 223u) == 69u))) { if (((_bits & 128L) != 0)) { @@ -4476,7 +4477,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http return; } - if ((((pUI[0] & 3755991007u) == 1314013527u) && ((pUS[2] & 57311u) == 20041u) && ((pUB[6] & 223u) == 71u))) + if ((((pUI[0] & 3755991007u) == 1314013527u) && ((pUS[2] & 57311u) == 20041u) && ((pUB[6] & 223u) == 71u))) { if (((_bits & 512L) != 0)) { @@ -4490,7 +4491,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http return; } - if ((((pUI[0] & 3755991007u) == 1230002245u) && ((pUS[2] & 57311u) == 17746u) && ((pUB[6] & 223u) == 83u))) + if ((((pUI[0] & 3755991007u) == 1230002245u) && ((pUS[2] & 57311u) == 17746u) && ((pUB[6] & 223u) == 83u))) { if (((_bits & 262144L) != 0)) { @@ -4504,7 +4505,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http return; } - if ((((pUI[0] & 3755991007u) == 1162233170u) && ((pUS[2] & 57311u) == 17746u) && ((pUB[6] & 223u) == 82u))) + if ((((pUI[0] & 3755991007u) == 1162233170u) && ((pUS[2] & 57311u) == 17746u) && ((pUB[6] & 223u) == 82u))) { if (((_bits & 68719476736L) != 0)) { @@ -4522,7 +4523,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http case 17: { - if ((((pUL[0] & 16131858542891098079uL) == 5928221808112259668uL) && ((pUL[1] & 16131858542891098111uL) == 5641115115480565037uL) && ((pUB[16] & 223u) == 71u))) + if ((((pUL[0] & 16131858542891098079uL) == 5928221808112259668uL) && ((pUL[1] & 16131858542891098111uL) == 5641115115480565037uL) && ((pUB[16] & 223u) == 71u))) { if (((_bits & 64L) != 0)) { @@ -4536,7 +4537,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http return; } - if ((((pUL[0] & 16131858542893195231uL) == 5064654363342751305uL) && ((pUL[1] & 16131858543427968991uL) == 4849894470315165001uL) && ((pUB[16] & 223u) == 69u))) + if ((((pUL[0] & 16131858542893195231uL) == 5064654363342751305uL) && ((pUL[1] & 16131858543427968991uL) == 4849894470315165001uL) && ((pUB[16] & 223u) == 69u))) { if (((_bits & 1073741824L) != 0)) { @@ -4554,7 +4555,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http case 3: { - if ((((pUS[0] & 57311u) == 18774u) && ((pUB[2] & 223u) == 65u))) + if ((((pUS[0] & 57311u) == 18774u) && ((pUB[2] & 223u) == 65u))) { if (((_bits & 256L) != 0)) { @@ -4572,7 +4573,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http case 5: { - if ((((pUI[0] & 3755991007u) == 1330400321u) && ((pUB[4] & 223u) == 87u))) + if ((((pUI[0] & 3755991007u) == 1330400321u) && ((pUB[4] & 223u) == 87u))) { if (((_bits & 1024L) != 0)) { @@ -4586,7 +4587,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http return; } - if ((((pUI[0] & 3755991007u) == 1196310866u) && ((pUB[4] & 223u) == 69u))) + if ((((pUI[0] & 3755991007u) == 1196310866u) && ((pUB[4] & 223u) == 69u))) { if (((_bits & 137438953472L) != 0)) { @@ -4604,7 +4605,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http case 14: { - if ((((pUL[0] & 18437701552104792031uL) == 3266321689424580419uL) && ((pUI[2] & 3755991007u) == 1196311884u) && ((pUS[6] & 57311u) == 18516u))) + if ((((pUL[0] & 18437701552104792031uL) == 3266321689424580419uL) && ((pUI[2] & 3755991007u) == 1196311884u) && ((pUS[6] & 57311u) == 18516u))) { if (((_bits & 2048L) != 0)) { @@ -4618,7 +4619,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http return; } - if ((((pUL[0] & 16140865742145839071uL) == 4840617878229304129uL) && ((pUI[2] & 3755991007u) == 1397899592u) && ((pUS[6] & 57311u) == 21573u))) + if ((((pUL[0] & 16140865742145839071uL) == 4840617878229304129uL) && ((pUI[2] & 3755991007u) == 1397899592u) && ((pUS[6] & 57311u) == 21573u))) { if (((_bits & 2097152L) != 0)) { @@ -4636,7 +4637,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http case 12: { - if ((((pUL[0] & 18437701552104792031uL) == 3266321689424580419uL) && ((pUI[2] & 3755991007u) == 1162893652u))) + if ((((pUL[0] & 18437701552104792031uL) == 3266321689424580419uL) && ((pUI[2] & 3755991007u) == 1162893652u))) { if (((_bits & 4096L) != 0)) { @@ -4650,7 +4651,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http return; } - if ((((pUL[0] & 16131858543427968991uL) == 6292178792217067853uL) && ((pUI[2] & 3755991007u) == 1396986433u))) + if ((((pUL[0] & 16131858543427968991uL) == 6292178792217067853uL) && ((pUI[2] & 3755991007u) == 1396986433u))) { if (((_bits & 17179869184L) != 0)) { @@ -4668,7 +4669,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http case 16: { - if ((((pUL[0] & 18437701552104792031uL) == 3266321689424580419uL) && ((pUL[1] & 16131858542891098079uL) == 5138124782612729413uL))) + if ((((pUL[0] & 18437701552104792031uL) == 3266321689424580419uL) && ((pUL[1] & 16131858542891098079uL) == 5138124782612729413uL))) { if (((_bits & 8192L) != 0)) { @@ -4682,7 +4683,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http return; } - if ((((pUL[0] & 18437701552104792031uL) == 3266321689424580419uL) && ((pUL[1] & 16131858542891098079uL) == 4992030546487820620uL))) + if ((((pUL[0] & 18437701552104792031uL) == 3266321689424580419uL) && ((pUL[1] & 16131858542891098079uL) == 4992030546487820620uL))) { if (((_bits & 16384L) != 0)) { @@ -4696,7 +4697,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http return; } - if ((((pUL[0] & 18437701552104792031uL) == 3266321689424580419uL) && ((pUL[1] & 16131858542891098079uL) == 5642809484339531596uL))) + if ((((pUL[0] & 18437701552104792031uL) == 3266321689424580419uL) && ((pUL[1] & 16131858542891098079uL) == 5642809484339531596uL))) { if (((_bits & 32768L) != 0)) { @@ -4714,7 +4715,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http case 11: { - if ((((pUL[0] & 18437701552104792031uL) == 3266321689424580419uL) && ((pUS[4] & 57311u) == 17485u) && ((pUB[10] & 255u) == 53u))) + if ((((pUL[0] & 18437701552104792031uL) == 3266321689424580419uL) && ((pUS[4] & 57311u) == 17485u) && ((pUB[10] & 255u) == 53u))) { if (((_bits & 65536L) != 0)) { @@ -4732,7 +4733,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http case 15: { - if ((((pUL[0] & 16140865742145839071uL) == 4984733066305160001uL) && ((pUI[2] & 3755991007u) == 1146045262u) && ((pUS[6] & 57311u) == 20041u) && ((pUB[14] & 223u) == 71u))) + if ((((pUL[0] & 16140865742145839071uL) == 4984733066305160001uL) && ((pUI[2] & 3755991007u) == 1146045262u) && ((pUS[6] & 57311u) == 20041u) && ((pUB[14] & 223u) == 71u))) { if (((_bits & 4194304L) != 0)) { @@ -4746,7 +4747,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http return; } - if ((((pUL[0] & 16140865742145839071uL) == 5489136224570655553uL) && ((pUI[2] & 3755991007u) == 1430736449u) && ((pUS[6] & 57311u) == 18241u) && ((pUB[14] & 223u) == 69u))) + if ((((pUL[0] & 16140865742145839071uL) == 5489136224570655553uL) && ((pUI[2] & 3755991007u) == 1430736449u) && ((pUS[6] & 57311u) == 18241u) && ((pUB[14] & 223u) == 69u))) { if (((_bits & 8388608L) != 0)) { @@ -4764,7 +4765,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http case 8: { - if ((((pUL[0] & 16131858542893195231uL) == 5207098233614845513uL))) + if ((((pUL[0] & 16131858542893195231uL) == 5207098233614845513uL))) { if (((_bits & 536870912L) != 0)) { @@ -4778,7 +4779,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http return; } - if ((((pUL[0] & 16131858542893195231uL) == 4992044754422023753uL))) + if ((((pUL[0] & 16131858542893195231uL) == 4992044754422023753uL))) { if (((_bits & 4294967296L) != 0)) { @@ -4796,7 +4797,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http case 19: { - if ((((pUL[0] & 16131858542893195231uL) == 4922237916571059785uL) && ((pUL[1] & 16131893727263186911uL) == 5283616559079179849uL) && ((pUS[8] & 57311u) == 17230u) && ((pUB[18] & 223u) == 69u))) + if ((((pUL[0] & 16131858542893195231uL) == 4922237916571059785uL) && ((pUL[1] & 16131893727263186911uL) == 5283616559079179849uL) && ((pUS[8] & 57311u) == 17230u) && ((pUB[18] & 223u) == 69u))) { if (((_bits & 8589934592L) != 0)) { @@ -4810,7 +4811,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http return; } - if ((((pUL[0] & 16131893727263186911uL) == 6143241228466999888uL) && ((pUL[1] & 16131858542891098079uL) == 6071233043632179284uL) && ((pUS[8] & 57311u) == 20297u) && ((pUB[18] & 223u) == 78u))) + if ((((pUL[0] & 16131893727263186911uL) == 6143241228466999888uL) && ((pUL[1] & 16131858542891098079uL) == 6071233043632179284uL) && ((pUS[8] & 57311u) == 20297u) && ((pUB[18] & 223u) == 78u))) { if (((_bits & 34359738368L) != 0)) { @@ -4828,7 +4829,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http case 2: { - if ((((pUS[0] & 57311u) == 17748u))) + if ((((pUS[0] & 57311u) == 17748u))) { if (((_bits & 274877906944L) != 0)) { @@ -4846,7 +4847,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http case 9: { - if ((((pUL[0] & 16131858542891098079uL) == 6071217693351039572uL) && ((pUB[8] & 223u) == 69u))) + if ((((pUL[0] & 16131858542891098079uL) == 6071217693351039572uL) && ((pUB[8] & 223u) == 69u))) { if (((_bits & 549755813888L) != 0)) { @@ -4864,7 +4865,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http case 29: { - if ((((pUL[0] & 16140865742145839071uL) == 4840616791602578241uL) && ((pUL[1] & 16140865742145839071uL) == 5921472988629454415uL) && ((pUL[2] & 16140865742145839071uL) == 5561193831494668613uL) && ((pUI[6] & 3755991007u) == 1330140229u) && ((pUB[28] & 223u) == 68u))) + if ((((pUL[0] & 16140865742145839071uL) == 4840616791602578241uL) && ((pUL[1] & 16140865742145839071uL) == 5921472988629454415uL) && ((pUL[2] & 16140865742145839071uL) == 5561193831494668613uL) && ((pUI[6] & 3755991007u) == 1330140229u) && ((pUB[28] & 223u) == 68u))) { if (((_bits & 4398046511104L) != 0)) { @@ -4882,7 +4883,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http case 30: { - if ((((pUL[0] & 16140865742145839071uL) == 4840616791602578241uL) && ((pUL[1] & 16140865742145839071uL) == 5921472988629454415uL) && ((pUL[2] & 16140865742145839071uL) == 5200905861305028933uL) && ((pUI[6] & 3755991007u) == 1162101061u) && ((pUS[14] & 57311u) == 21330u))) + if ((((pUL[0] & 16140865742145839071uL) == 4840616791602578241uL) && ((pUL[1] & 16140865742145839071uL) == 5921472988629454415uL) && ((pUL[2] & 16140865742145839071uL) == 5200905861305028933uL) && ((pUI[6] & 3755991007u) == 1162101061u) && ((pUS[14] & 57311u) == 21330u))) { if (((_bits & 8796093022208L) != 0)) { @@ -4898,8 +4899,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } break; } + + fixed(char *keyBuffer = key) + { + if (!AsciiUtilities.TryGetAsciiString(ptr, keyBuffer, keyLength)) + { + throw new BadHttpRequestException("Invalid characters in header name"); + } + } } - var key = System.Text.Encoding.ASCII.GetString(keyBytes, keyOffset, keyLength); + StringValues existing; Unknown.TryGetValue(key, out existing); Unknown[key] = AppendValue(existing, value); @@ -5466,7 +5475,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { 13,10,67,97,99,104,101,45,67,111,110,116,114,111,108,58,32,13,10,67,111,110,110,101,99,116,105,111,110,58,32,13,10,68,97,116,101,58,32,13,10,75,101,101,112,45,65,108,105,118,101,58,32,13,10,80,114,97,103,109,97,58,32,13,10,84,114,97,105,108,101,114,58,32,13,10,84,114,97,110,115,102,101,114,45,69,110,99,111,100,105,110,103,58,32,13,10,85,112,103,114,97,100,101,58,32,13,10,86,105,97,58,32,13,10,87,97,114,110,105,110,103,58,32,13,10,65,108,108,111,119,58,32,13,10,67,111,110,116,101,110,116,45,76,101,110,103,116,104,58,32,13,10,67,111,110,116,101,110,116,45,84,121,112,101,58,32,13,10,67,111,110,116,101,110,116,45,69,110,99,111,100,105,110,103,58,32,13,10,67,111,110,116,101,110,116,45,76,97,110,103,117,97,103,101,58,32,13,10,67,111,110,116,101,110,116,45,76,111,99,97,116,105,111,110,58,32,13,10,67,111,110,116,101,110,116,45,77,68,53,58,32,13,10,67,111,110,116,101,110,116,45,82,97,110,103,101,58,32,13,10,69,120,112,105,114,101,115,58,32,13,10,76,97,115,116,45,77,111,100,105,102,105,101,100,58,32,13,10,65,99,99,101,112,116,45,82,97,110,103,101,115,58,32,13,10,65,103,101,58,32,13,10,69,84,97,103,58,32,13,10,76,111,99,97,116,105,111,110,58,32,13,10,80,114,111,120,121,45,65,117,116,104,101,116,105,99,97,116,101,58,32,13,10,82,101,116,114,121,45,65,102,116,101,114,58,32,13,10,83,101,114,118,101,114,58,32,13,10,83,101,116,45,67,111,111,107,105,101,58,32,13,10,86,97,114,121,58,32,13,10,87,87,87,45,65,117,116,104,101,110,116,105,99,97,116,101,58,32,13,10,65,99,99,101,115,115,45,67,111,110,116,114,111,108,45,65,108,108,111,119,45,67,114,101,100,101,110,116,105,97,108,115,58,32,13,10,65,99,99,101,115,115,45,67,111,110,116,114,111,108,45,65,108,108,111,119,45,72,101,97,100,101,114,115,58,32,13,10,65,99,99,101,115,115,45,67,111,110,116,114,111,108,45,65,108,108,111,119,45,77,101,116,104,111,100,115,58,32,13,10,65,99,99,101,115,115,45,67,111,110,116,114,111,108,45,65,108,108,111,119,45,79,114,105,103,105,110,58,32,13,10,65,99,99,101,115,115,45,67,111,110,116,114,111,108,45,69,120,112,111,115,101,45,72,101,97,100,101,114,115,58,32,13,10,65,99,99,101,115,115,45,67,111,110,116,114,111,108,45,77,97,120,45,65,103,101,58,32, }; - + private long _bits = 0; private HeaderReferences _headers; @@ -6055,31 +6064,31 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http public void SetRawConnection(StringValues value, byte[] raw) { _bits |= 2L; - _headers._Connection = value; + _headers._Connection = value; _headers._rawConnection = raw; } public void SetRawDate(StringValues value, byte[] raw) { _bits |= 4L; - _headers._Date = value; + _headers._Date = value; _headers._rawDate = raw; } public void SetRawTransferEncoding(StringValues value, byte[] raw) { _bits |= 64L; - _headers._TransferEncoding = value; + _headers._TransferEncoding = value; _headers._rawTransferEncoding = raw; } public void SetRawContentLength(StringValues value, byte[] raw) { _bits |= 2048L; - _headers._ContentLength = value; + _headers._ContentLength = value; _headers._rawContentLength = raw; } public void SetRawServer(StringValues value, byte[] raw) { _bits |= 67108864L; - _headers._Server = value; + _headers._Server = value; _headers._rawServer = raw; } protected override int GetCountFast() @@ -6594,7 +6603,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } break; } - if (MaybeUnknown == null) + if (MaybeUnknown == null) { ThrowKeyNotFoundException(); } @@ -6606,7 +6615,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { case 13: { - if ("Cache-Control".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Cache-Control".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 1L) != 0)) { @@ -6620,7 +6629,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } - if ("Content-Range".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Content-Range".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 131072L) != 0)) { @@ -6634,7 +6643,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } - if ("Last-Modified".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Last-Modified".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 524288L) != 0)) { @@ -6648,7 +6657,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } - if ("Accept-Ranges".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Accept-Ranges".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 1048576L) != 0)) { @@ -6666,7 +6675,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http case 10: { - if ("Connection".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Connection".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 2L) != 0)) { @@ -6680,7 +6689,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } - if ("Keep-Alive".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Keep-Alive".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 8L) != 0)) { @@ -6694,7 +6703,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } - if ("Set-Cookie".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Set-Cookie".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 134217728L) != 0)) { @@ -6712,7 +6721,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http case 4: { - if ("Date".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Date".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 4L) != 0)) { @@ -6726,7 +6735,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } - if ("ETag".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("ETag".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 4194304L) != 0)) { @@ -6740,7 +6749,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } - if ("Vary".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Vary".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 268435456L) != 0)) { @@ -6758,7 +6767,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http case 6: { - if ("Pragma".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Pragma".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 16L) != 0)) { @@ -6772,7 +6781,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } - if ("Server".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Server".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 67108864L) != 0)) { @@ -6790,7 +6799,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http case 7: { - if ("Trailer".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Trailer".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 32L) != 0)) { @@ -6804,7 +6813,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } - if ("Upgrade".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Upgrade".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 128L) != 0)) { @@ -6818,7 +6827,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } - if ("Warning".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Warning".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 512L) != 0)) { @@ -6832,7 +6841,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } - if ("Expires".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Expires".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 262144L) != 0)) { @@ -6850,7 +6859,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http case 17: { - if ("Transfer-Encoding".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Transfer-Encoding".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 64L) != 0)) { @@ -6864,7 +6873,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } - if ("Proxy-Autheticate".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Proxy-Autheticate".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 16777216L) != 0)) { @@ -6882,7 +6891,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http case 3: { - if ("Via".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Via".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 256L) != 0)) { @@ -6896,7 +6905,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } - if ("Age".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Age".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 2097152L) != 0)) { @@ -6914,7 +6923,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http case 5: { - if ("Allow".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Allow".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 1024L) != 0)) { @@ -6932,7 +6941,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http case 14: { - if ("Content-Length".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Content-Length".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 2048L) != 0)) { @@ -6950,7 +6959,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http case 12: { - if ("Content-Type".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Content-Type".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 4096L) != 0)) { @@ -6968,7 +6977,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http case 16: { - if ("Content-Encoding".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Content-Encoding".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 8192L) != 0)) { @@ -6982,7 +6991,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } - if ("Content-Language".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Content-Language".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 16384L) != 0)) { @@ -6996,7 +7005,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } - if ("Content-Location".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Content-Location".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 32768L) != 0)) { @@ -7010,7 +7019,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } - if ("WWW-Authenticate".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("WWW-Authenticate".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 536870912L) != 0)) { @@ -7028,7 +7037,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http case 11: { - if ("Content-MD5".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Content-MD5".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 65536L) != 0)) { @@ -7042,7 +7051,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } - if ("Retry-After".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Retry-After".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 33554432L) != 0)) { @@ -7060,7 +7069,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http case 8: { - if ("Location".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Location".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 8388608L) != 0)) { @@ -7078,7 +7087,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http case 32: { - if ("Access-Control-Allow-Credentials".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Access-Control-Allow-Credentials".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 1073741824L) != 0)) { @@ -7096,7 +7105,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http case 28: { - if ("Access-Control-Allow-Headers".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Access-Control-Allow-Headers".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 2147483648L) != 0)) { @@ -7110,7 +7119,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } - if ("Access-Control-Allow-Methods".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Access-Control-Allow-Methods".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 4294967296L) != 0)) { @@ -7128,7 +7137,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http case 27: { - if ("Access-Control-Allow-Origin".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Access-Control-Allow-Origin".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 8589934592L) != 0)) { @@ -7146,7 +7155,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http case 29: { - if ("Access-Control-Expose-Headers".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Access-Control-Expose-Headers".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 17179869184L) != 0)) { @@ -7164,7 +7173,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http case 22: { - if ("Access-Control-Max-Age".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Access-Control-Max-Age".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 34359738368L) != 0)) { @@ -7190,28 +7199,28 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { case 13: { - if ("Cache-Control".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Cache-Control".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 1L; _headers._CacheControl = value; return; } - if ("Content-Range".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Content-Range".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 131072L; _headers._ContentRange = value; return; } - if ("Last-Modified".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Last-Modified".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 524288L; _headers._LastModified = value; return; } - if ("Accept-Ranges".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Accept-Ranges".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 1048576L; _headers._AcceptRanges = value; @@ -7222,7 +7231,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http case 10: { - if ("Connection".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Connection".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 2L; _headers._Connection = value; @@ -7230,14 +7239,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http return; } - if ("Keep-Alive".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Keep-Alive".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 8L; _headers._KeepAlive = value; return; } - if ("Set-Cookie".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Set-Cookie".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 134217728L; _headers._SetCookie = value; @@ -7248,7 +7257,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http case 4: { - if ("Date".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Date".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 4L; _headers._Date = value; @@ -7256,14 +7265,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http return; } - if ("ETag".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("ETag".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 4194304L; _headers._ETag = value; return; } - if ("Vary".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Vary".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 268435456L; _headers._Vary = value; @@ -7274,14 +7283,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http case 6: { - if ("Pragma".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Pragma".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 16L; _headers._Pragma = value; return; } - if ("Server".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Server".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 67108864L; _headers._Server = value; @@ -7293,28 +7302,28 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http case 7: { - if ("Trailer".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Trailer".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 32L; _headers._Trailer = value; return; } - if ("Upgrade".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Upgrade".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 128L; _headers._Upgrade = value; return; } - if ("Warning".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Warning".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 512L; _headers._Warning = value; return; } - if ("Expires".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Expires".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 262144L; _headers._Expires = value; @@ -7325,7 +7334,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http case 17: { - if ("Transfer-Encoding".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Transfer-Encoding".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 64L; _headers._TransferEncoding = value; @@ -7333,7 +7342,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http return; } - if ("Proxy-Autheticate".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Proxy-Autheticate".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 16777216L; _headers._ProxyAutheticate = value; @@ -7344,14 +7353,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http case 3: { - if ("Via".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Via".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 256L; _headers._Via = value; return; } - if ("Age".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Age".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 2097152L; _headers._Age = value; @@ -7362,7 +7371,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http case 5: { - if ("Allow".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Allow".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 1024L; _headers._Allow = value; @@ -7373,7 +7382,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http case 14: { - if ("Content-Length".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Content-Length".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 2048L; _headers._ContentLength = value; @@ -7385,7 +7394,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http case 12: { - if ("Content-Type".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Content-Type".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 4096L; _headers._ContentType = value; @@ -7396,28 +7405,28 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http case 16: { - if ("Content-Encoding".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Content-Encoding".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 8192L; _headers._ContentEncoding = value; return; } - if ("Content-Language".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Content-Language".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 16384L; _headers._ContentLanguage = value; return; } - if ("Content-Location".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Content-Location".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 32768L; _headers._ContentLocation = value; return; } - if ("WWW-Authenticate".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("WWW-Authenticate".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 536870912L; _headers._WWWAuthenticate = value; @@ -7428,14 +7437,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http case 11: { - if ("Content-MD5".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Content-MD5".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 65536L; _headers._ContentMD5 = value; return; } - if ("Retry-After".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Retry-After".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 33554432L; _headers._RetryAfter = value; @@ -7446,7 +7455,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http case 8: { - if ("Location".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Location".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 8388608L; _headers._Location = value; @@ -7457,7 +7466,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http case 32: { - if ("Access-Control-Allow-Credentials".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Access-Control-Allow-Credentials".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 1073741824L; _headers._AccessControlAllowCredentials = value; @@ -7468,14 +7477,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http case 28: { - if ("Access-Control-Allow-Headers".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Access-Control-Allow-Headers".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 2147483648L; _headers._AccessControlAllowHeaders = value; return; } - if ("Access-Control-Allow-Methods".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Access-Control-Allow-Methods".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 4294967296L; _headers._AccessControlAllowMethods = value; @@ -7486,7 +7495,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http case 27: { - if ("Access-Control-Allow-Origin".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Access-Control-Allow-Origin".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 8589934592L; _headers._AccessControlAllowOrigin = value; @@ -7497,7 +7506,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http case 29: { - if ("Access-Control-Expose-Headers".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Access-Control-Expose-Headers".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 17179869184L; _headers._AccessControlExposeHeaders = value; @@ -7508,7 +7517,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http case 22: { - if ("Access-Control-Max-Age".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Access-Control-Max-Age".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 34359738368L; _headers._AccessControlMaxAge = value; @@ -8007,7 +8016,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { case 13: { - if ("Cache-Control".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Cache-Control".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 1L) != 0)) { @@ -8021,7 +8030,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } - if ("Content-Range".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Content-Range".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 131072L) != 0)) { @@ -8035,7 +8044,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } - if ("Last-Modified".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Last-Modified".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 524288L) != 0)) { @@ -8049,7 +8058,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } - if ("Accept-Ranges".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Accept-Ranges".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 1048576L) != 0)) { @@ -8067,7 +8076,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http case 10: { - if ("Connection".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Connection".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 2L) != 0)) { @@ -8082,7 +8091,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } - if ("Keep-Alive".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Keep-Alive".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 8L) != 0)) { @@ -8096,7 +8105,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } - if ("Set-Cookie".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Set-Cookie".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 134217728L) != 0)) { @@ -8114,7 +8123,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http case 4: { - if ("Date".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Date".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 4L) != 0)) { @@ -8129,7 +8138,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } - if ("ETag".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("ETag".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 4194304L) != 0)) { @@ -8143,7 +8152,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } - if ("Vary".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Vary".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 268435456L) != 0)) { @@ -8161,7 +8170,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http case 6: { - if ("Pragma".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Pragma".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 16L) != 0)) { @@ -8175,7 +8184,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } - if ("Server".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Server".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 67108864L) != 0)) { @@ -8194,7 +8203,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http case 7: { - if ("Trailer".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Trailer".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 32L) != 0)) { @@ -8208,7 +8217,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } - if ("Upgrade".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Upgrade".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 128L) != 0)) { @@ -8222,7 +8231,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } - if ("Warning".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Warning".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 512L) != 0)) { @@ -8236,7 +8245,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } - if ("Expires".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Expires".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 262144L) != 0)) { @@ -8254,7 +8263,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http case 17: { - if ("Transfer-Encoding".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Transfer-Encoding".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 64L) != 0)) { @@ -8269,7 +8278,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } - if ("Proxy-Autheticate".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Proxy-Autheticate".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 16777216L) != 0)) { @@ -8287,7 +8296,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http case 3: { - if ("Via".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Via".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 256L) != 0)) { @@ -8301,7 +8310,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } - if ("Age".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Age".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 2097152L) != 0)) { @@ -8319,7 +8328,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http case 5: { - if ("Allow".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Allow".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 1024L) != 0)) { @@ -8337,7 +8346,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http case 14: { - if ("Content-Length".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Content-Length".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 2048L) != 0)) { @@ -8356,7 +8365,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http case 12: { - if ("Content-Type".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Content-Type".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 4096L) != 0)) { @@ -8374,7 +8383,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http case 16: { - if ("Content-Encoding".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Content-Encoding".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 8192L) != 0)) { @@ -8388,7 +8397,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } - if ("Content-Language".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Content-Language".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 16384L) != 0)) { @@ -8402,7 +8411,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } - if ("Content-Location".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Content-Location".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 32768L) != 0)) { @@ -8416,7 +8425,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } - if ("WWW-Authenticate".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("WWW-Authenticate".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 536870912L) != 0)) { @@ -8434,7 +8443,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http case 11: { - if ("Content-MD5".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Content-MD5".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 65536L) != 0)) { @@ -8448,7 +8457,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } - if ("Retry-After".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Retry-After".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 33554432L) != 0)) { @@ -8466,7 +8475,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http case 8: { - if ("Location".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Location".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 8388608L) != 0)) { @@ -8484,7 +8493,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http case 32: { - if ("Access-Control-Allow-Credentials".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Access-Control-Allow-Credentials".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 1073741824L) != 0)) { @@ -8502,7 +8511,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http case 28: { - if ("Access-Control-Allow-Headers".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Access-Control-Allow-Headers".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 2147483648L) != 0)) { @@ -8516,7 +8525,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } - if ("Access-Control-Allow-Methods".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Access-Control-Allow-Methods".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 4294967296L) != 0)) { @@ -8534,7 +8543,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http case 27: { - if ("Access-Control-Allow-Origin".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Access-Control-Allow-Origin".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 8589934592L) != 0)) { @@ -8552,7 +8561,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http case 29: { - if ("Access-Control-Expose-Headers".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Access-Control-Expose-Headers".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 17179869184L) != 0)) { @@ -8570,7 +8579,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http case 22: { - if ("Access-Control-Max-Age".Equals(key, StringComparison.OrdinalIgnoreCase)) + if ("Access-Control-Max-Age".Equals(key, StringComparison.OrdinalIgnoreCase)) { if (((_bits & 34359738368L) != 0)) { @@ -8594,7 +8603,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http _headers = default(HeaderReferences); MaybeUnknown?.Clear(); } - + protected override void CopyToFast(KeyValuePair[] array, int arrayIndex) { if (arrayIndex < 0) @@ -8602,7 +8611,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowArgumentException(); } - if (((_bits & 1L) != 0)) + if (((_bits & 1L) != 0)) { if (arrayIndex == array.Length) { @@ -8613,7 +8622,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ++arrayIndex; } - if (((_bits & 2L) != 0)) + if (((_bits & 2L) != 0)) { if (arrayIndex == array.Length) { @@ -8624,7 +8633,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ++arrayIndex; } - if (((_bits & 4L) != 0)) + if (((_bits & 4L) != 0)) { if (arrayIndex == array.Length) { @@ -8635,7 +8644,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ++arrayIndex; } - if (((_bits & 8L) != 0)) + if (((_bits & 8L) != 0)) { if (arrayIndex == array.Length) { @@ -8646,7 +8655,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ++arrayIndex; } - if (((_bits & 16L) != 0)) + if (((_bits & 16L) != 0)) { if (arrayIndex == array.Length) { @@ -8657,7 +8666,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ++arrayIndex; } - if (((_bits & 32L) != 0)) + if (((_bits & 32L) != 0)) { if (arrayIndex == array.Length) { @@ -8668,7 +8677,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ++arrayIndex; } - if (((_bits & 64L) != 0)) + if (((_bits & 64L) != 0)) { if (arrayIndex == array.Length) { @@ -8679,7 +8688,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ++arrayIndex; } - if (((_bits & 128L) != 0)) + if (((_bits & 128L) != 0)) { if (arrayIndex == array.Length) { @@ -8690,7 +8699,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ++arrayIndex; } - if (((_bits & 256L) != 0)) + if (((_bits & 256L) != 0)) { if (arrayIndex == array.Length) { @@ -8701,7 +8710,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ++arrayIndex; } - if (((_bits & 512L) != 0)) + if (((_bits & 512L) != 0)) { if (arrayIndex == array.Length) { @@ -8712,7 +8721,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ++arrayIndex; } - if (((_bits & 1024L) != 0)) + if (((_bits & 1024L) != 0)) { if (arrayIndex == array.Length) { @@ -8723,7 +8732,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ++arrayIndex; } - if (((_bits & 2048L) != 0)) + if (((_bits & 2048L) != 0)) { if (arrayIndex == array.Length) { @@ -8734,7 +8743,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ++arrayIndex; } - if (((_bits & 4096L) != 0)) + if (((_bits & 4096L) != 0)) { if (arrayIndex == array.Length) { @@ -8745,7 +8754,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ++arrayIndex; } - if (((_bits & 8192L) != 0)) + if (((_bits & 8192L) != 0)) { if (arrayIndex == array.Length) { @@ -8756,7 +8765,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ++arrayIndex; } - if (((_bits & 16384L) != 0)) + if (((_bits & 16384L) != 0)) { if (arrayIndex == array.Length) { @@ -8767,7 +8776,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ++arrayIndex; } - if (((_bits & 32768L) != 0)) + if (((_bits & 32768L) != 0)) { if (arrayIndex == array.Length) { @@ -8778,7 +8787,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ++arrayIndex; } - if (((_bits & 65536L) != 0)) + if (((_bits & 65536L) != 0)) { if (arrayIndex == array.Length) { @@ -8789,7 +8798,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ++arrayIndex; } - if (((_bits & 131072L) != 0)) + if (((_bits & 131072L) != 0)) { if (arrayIndex == array.Length) { @@ -8800,7 +8809,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ++arrayIndex; } - if (((_bits & 262144L) != 0)) + if (((_bits & 262144L) != 0)) { if (arrayIndex == array.Length) { @@ -8811,7 +8820,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ++arrayIndex; } - if (((_bits & 524288L) != 0)) + if (((_bits & 524288L) != 0)) { if (arrayIndex == array.Length) { @@ -8822,7 +8831,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ++arrayIndex; } - if (((_bits & 1048576L) != 0)) + if (((_bits & 1048576L) != 0)) { if (arrayIndex == array.Length) { @@ -8833,7 +8842,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ++arrayIndex; } - if (((_bits & 2097152L) != 0)) + if (((_bits & 2097152L) != 0)) { if (arrayIndex == array.Length) { @@ -8844,7 +8853,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ++arrayIndex; } - if (((_bits & 4194304L) != 0)) + if (((_bits & 4194304L) != 0)) { if (arrayIndex == array.Length) { @@ -8855,7 +8864,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ++arrayIndex; } - if (((_bits & 8388608L) != 0)) + if (((_bits & 8388608L) != 0)) { if (arrayIndex == array.Length) { @@ -8866,7 +8875,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ++arrayIndex; } - if (((_bits & 16777216L) != 0)) + if (((_bits & 16777216L) != 0)) { if (arrayIndex == array.Length) { @@ -8877,7 +8886,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ++arrayIndex; } - if (((_bits & 33554432L) != 0)) + if (((_bits & 33554432L) != 0)) { if (arrayIndex == array.Length) { @@ -8888,7 +8897,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ++arrayIndex; } - if (((_bits & 67108864L) != 0)) + if (((_bits & 67108864L) != 0)) { if (arrayIndex == array.Length) { @@ -8899,7 +8908,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ++arrayIndex; } - if (((_bits & 134217728L) != 0)) + if (((_bits & 134217728L) != 0)) { if (arrayIndex == array.Length) { @@ -8910,7 +8919,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ++arrayIndex; } - if (((_bits & 268435456L) != 0)) + if (((_bits & 268435456L) != 0)) { if (arrayIndex == array.Length) { @@ -8921,7 +8930,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ++arrayIndex; } - if (((_bits & 536870912L) != 0)) + if (((_bits & 536870912L) != 0)) { if (arrayIndex == array.Length) { @@ -8932,7 +8941,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ++arrayIndex; } - if (((_bits & 1073741824L) != 0)) + if (((_bits & 1073741824L) != 0)) { if (arrayIndex == array.Length) { @@ -8943,7 +8952,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ++arrayIndex; } - if (((_bits & 2147483648L) != 0)) + if (((_bits & 2147483648L) != 0)) { if (arrayIndex == array.Length) { @@ -8954,7 +8963,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ++arrayIndex; } - if (((_bits & 4294967296L) != 0)) + if (((_bits & 4294967296L) != 0)) { if (arrayIndex == array.Length) { @@ -8965,7 +8974,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ++arrayIndex; } - if (((_bits & 8589934592L) != 0)) + if (((_bits & 8589934592L) != 0)) { if (arrayIndex == array.Length) { @@ -8976,7 +8985,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ++arrayIndex; } - if (((_bits & 17179869184L) != 0)) + if (((_bits & 17179869184L) != 0)) { if (arrayIndex == array.Length) { @@ -8987,7 +8996,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ++arrayIndex; } - if (((_bits & 34359738368L) != 0)) + if (((_bits & 34359738368L) != 0)) { if (arrayIndex == array.Length) { @@ -9004,7 +9013,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http protected void CopyToFast(ref MemoryPoolIterator output) { - if (((_bits & 1L) != 0)) + if (((_bits & 1L) != 0)) { foreach (var value in _headers._CacheControl) { @@ -9016,12 +9025,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } - if (((_bits & 2L) != 0)) + if (((_bits & 2L) != 0)) { - if (_headers._rawConnection != null) + if (_headers._rawConnection != null) { output.CopyFrom(_headers._rawConnection, 0, _headers._rawConnection.Length); - } + } else foreach (var value in _headers._Connection) { @@ -9033,12 +9042,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } - if (((_bits & 4L) != 0)) + if (((_bits & 4L) != 0)) { - if (_headers._rawDate != null) + if (_headers._rawDate != null) { output.CopyFrom(_headers._rawDate, 0, _headers._rawDate.Length); - } + } else foreach (var value in _headers._Date) { @@ -9050,7 +9059,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } - if (((_bits & 8L) != 0)) + if (((_bits & 8L) != 0)) { foreach (var value in _headers._KeepAlive) { @@ -9062,7 +9071,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } - if (((_bits & 16L) != 0)) + if (((_bits & 16L) != 0)) { foreach (var value in _headers._Pragma) { @@ -9074,7 +9083,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } - if (((_bits & 32L) != 0)) + if (((_bits & 32L) != 0)) { foreach (var value in _headers._Trailer) { @@ -9086,12 +9095,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } - if (((_bits & 64L) != 0)) + if (((_bits & 64L) != 0)) { - if (_headers._rawTransferEncoding != null) + if (_headers._rawTransferEncoding != null) { output.CopyFrom(_headers._rawTransferEncoding, 0, _headers._rawTransferEncoding.Length); - } + } else foreach (var value in _headers._TransferEncoding) { @@ -9103,7 +9112,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } - if (((_bits & 128L) != 0)) + if (((_bits & 128L) != 0)) { foreach (var value in _headers._Upgrade) { @@ -9115,7 +9124,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } - if (((_bits & 256L) != 0)) + if (((_bits & 256L) != 0)) { foreach (var value in _headers._Via) { @@ -9127,7 +9136,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } - if (((_bits & 512L) != 0)) + if (((_bits & 512L) != 0)) { foreach (var value in _headers._Warning) { @@ -9139,7 +9148,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } - if (((_bits & 1024L) != 0)) + if (((_bits & 1024L) != 0)) { foreach (var value in _headers._Allow) { @@ -9151,12 +9160,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } - if (((_bits & 2048L) != 0)) + if (((_bits & 2048L) != 0)) { - if (_headers._rawContentLength != null) + if (_headers._rawContentLength != null) { output.CopyFrom(_headers._rawContentLength, 0, _headers._rawContentLength.Length); - } + } else foreach (var value in _headers._ContentLength) { @@ -9168,7 +9177,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } - if (((_bits & 4096L) != 0)) + if (((_bits & 4096L) != 0)) { foreach (var value in _headers._ContentType) { @@ -9180,7 +9189,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } - if (((_bits & 8192L) != 0)) + if (((_bits & 8192L) != 0)) { foreach (var value in _headers._ContentEncoding) { @@ -9192,7 +9201,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } - if (((_bits & 16384L) != 0)) + if (((_bits & 16384L) != 0)) { foreach (var value in _headers._ContentLanguage) { @@ -9204,7 +9213,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } - if (((_bits & 32768L) != 0)) + if (((_bits & 32768L) != 0)) { foreach (var value in _headers._ContentLocation) { @@ -9216,7 +9225,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } - if (((_bits & 65536L) != 0)) + if (((_bits & 65536L) != 0)) { foreach (var value in _headers._ContentMD5) { @@ -9228,7 +9237,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } - if (((_bits & 131072L) != 0)) + if (((_bits & 131072L) != 0)) { foreach (var value in _headers._ContentRange) { @@ -9240,7 +9249,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } - if (((_bits & 262144L) != 0)) + if (((_bits & 262144L) != 0)) { foreach (var value in _headers._Expires) { @@ -9252,7 +9261,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } - if (((_bits & 524288L) != 0)) + if (((_bits & 524288L) != 0)) { foreach (var value in _headers._LastModified) { @@ -9264,7 +9273,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } - if (((_bits & 1048576L) != 0)) + if (((_bits & 1048576L) != 0)) { foreach (var value in _headers._AcceptRanges) { @@ -9276,7 +9285,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } - if (((_bits & 2097152L) != 0)) + if (((_bits & 2097152L) != 0)) { foreach (var value in _headers._Age) { @@ -9288,7 +9297,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } - if (((_bits & 4194304L) != 0)) + if (((_bits & 4194304L) != 0)) { foreach (var value in _headers._ETag) { @@ -9300,7 +9309,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } - if (((_bits & 8388608L) != 0)) + if (((_bits & 8388608L) != 0)) { foreach (var value in _headers._Location) { @@ -9312,7 +9321,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } - if (((_bits & 16777216L) != 0)) + if (((_bits & 16777216L) != 0)) { foreach (var value in _headers._ProxyAutheticate) { @@ -9324,7 +9333,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } - if (((_bits & 33554432L) != 0)) + if (((_bits & 33554432L) != 0)) { foreach (var value in _headers._RetryAfter) { @@ -9336,12 +9345,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } - if (((_bits & 67108864L) != 0)) + if (((_bits & 67108864L) != 0)) { - if (_headers._rawServer != null) + if (_headers._rawServer != null) { output.CopyFrom(_headers._rawServer, 0, _headers._rawServer.Length); - } + } else foreach (var value in _headers._Server) { @@ -9353,7 +9362,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } - if (((_bits & 134217728L) != 0)) + if (((_bits & 134217728L) != 0)) { foreach (var value in _headers._SetCookie) { @@ -9365,7 +9374,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } - if (((_bits & 268435456L) != 0)) + if (((_bits & 268435456L) != 0)) { foreach (var value in _headers._Vary) { @@ -9377,7 +9386,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } - if (((_bits & 536870912L) != 0)) + if (((_bits & 536870912L) != 0)) { foreach (var value in _headers._WWWAuthenticate) { @@ -9389,7 +9398,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } - if (((_bits & 1073741824L) != 0)) + if (((_bits & 1073741824L) != 0)) { foreach (var value in _headers._AccessControlAllowCredentials) { @@ -9401,7 +9410,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } - if (((_bits & 2147483648L) != 0)) + if (((_bits & 2147483648L) != 0)) { foreach (var value in _headers._AccessControlAllowHeaders) { @@ -9413,7 +9422,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } - if (((_bits & 4294967296L) != 0)) + if (((_bits & 4294967296L) != 0)) { foreach (var value in _headers._AccessControlAllowMethods) { @@ -9425,7 +9434,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } - if (((_bits & 8589934592L) != 0)) + if (((_bits & 8589934592L) != 0)) { foreach (var value in _headers._AccessControlAllowOrigin) { @@ -9437,7 +9446,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } - if (((_bits & 17179869184L) != 0)) + if (((_bits & 17179869184L) != 0)) { foreach (var value in _headers._AccessControlExposeHeaders) { @@ -9449,7 +9458,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } - if (((_bits & 34359738368L) != 0)) + if (((_bits & 34359738368L) != 0)) { foreach (var value in _headers._AccessControlMaxAge) { diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/BadHttpRequestTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/BadHttpRequestTests.cs index 8d1a0574a6..1f2a5e6413 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/BadHttpRequestTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/BadHttpRequestTests.cs @@ -172,6 +172,23 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } } + [Fact] + public async Task BadRequestWhenNameHeaderNamesContainsNonASCIICharacters() + { + using (var server = new TestServer(context => { return Task.FromResult(0); })) + { + using (var connection = server.CreateConnection()) + { + await connection.SendEnd( + "GET / HTTP/1.1", + "Hdr: value", + "", + ""); + await ReceiveBadRequestResponse(connection); + } + } + } + private async Task ReceiveBadRequestResponse(TestConnection connection) { await connection.Receive( diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameRequestHeadersTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameRequestHeadersTests.cs index 314ee32aa3..14ef396c1e 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameRequestHeadersTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameRequestHeadersTests.cs @@ -1,5 +1,7 @@ using System; using System.Collections.Generic; +using System.Text; +using Microsoft.AspNetCore.Server.Kestrel.Exceptions; using Microsoft.AspNetCore.Server.Kestrel.Http; using Microsoft.Extensions.Primitives; using Xunit; @@ -233,5 +235,16 @@ namespace Microsoft.AspNetCore.Server.KestrelTests Assert.Null(entries[3].Key); Assert.Equal(new StringValues(), entries[0].Value); } + + [Fact] + public void AppendThrowsWhenHeaderValueContainsNonASCIICharacters() + { + var headers = new FrameRequestHeaders(); + const string key = "\u00141d\017c"; + + var encoding = Encoding.GetEncoding("iso-8859-1"); + Assert.Throws( + () => headers.Append(encoding.GetBytes(key), 0, encoding.GetByteCount(key), key)); + } } } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestConnection.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/TestConnection.cs index 39cefb305f..30ec6f4879 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/TestConnection.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/TestConnection.cs @@ -61,7 +61,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests public async Task Send(params string[] lines) { var text = String.Join("\r\n", lines); - var writer = new StreamWriter(_stream, Encoding.ASCII); + var writer = new StreamWriter(_stream, Encoding.GetEncoding("iso-8859-1")); for (var index = 0; index < text.Length; index++) { var ch = text[index]; diff --git a/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/KnownHeaders.cs b/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/KnownHeaders.cs index a51039d540..ca9073e9da 100644 --- a/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/KnownHeaders.cs +++ b/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/KnownHeaders.cs @@ -72,7 +72,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.GeneratedCode return $"(({array}[{offset / count}] & {mask}{suffix}) == {comp}{suffix})"; } } - + public static string GeneratedFile() { var commonHeaders = new[] @@ -199,11 +199,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.GeneratedCode return $@" using System; using System.Collections.Generic; -using System.Text; +using Microsoft.AspNetCore.Server.Kestrel.Exceptions; using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; using Microsoft.Extensions.Primitives; -namespace Microsoft.AspNetCore.Server.Kestrel.Http +namespace Microsoft.AspNetCore.Server.Kestrel.Http {{ {Each(loops, loop => $@" public partial class {loop.ClassName} @@ -214,7 +214,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http {Each(loop.Bytes, b => $"{b},")} }};" : "")} - + private long _bits = 0; private HeaderReferences _headers; {Each(loop.Headers, header => $@" @@ -239,7 +239,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http public void SetRaw{header.Identifier}(StringValues value, byte[] raw) {{ {header.SetBit()}; - _headers._{header.Identifier} = value; + _headers._{header.Identifier} = value; _headers._raw{header.Identifier} = raw; }}")} protected override int GetCountFast() @@ -266,7 +266,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ")}}} break; ")}}} - if (MaybeUnknown == null) + if (MaybeUnknown == null) {{ ThrowKeyNotFoundException(); }} @@ -278,7 +278,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http {{{Each(loop.HeadersByLength, byLength => $@" case {byLength.Key}: {{{Each(byLength, header => $@" - if (""{header.Name}"".Equals(key, StringComparison.OrdinalIgnoreCase)) + if (""{header.Name}"".Equals(key, StringComparison.OrdinalIgnoreCase)) {{ if ({header.TestBit()}) {{ @@ -304,7 +304,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http {{{Each(loop.HeadersByLength, byLength => $@" case {byLength.Key}: {{{Each(byLength, header => $@" - if (""{header.Name}"".Equals(key, StringComparison.OrdinalIgnoreCase)) + if (""{header.Name}"".Equals(key, StringComparison.OrdinalIgnoreCase)) {{ {header.SetBit()}; _headers._{header.Identifier} = value;{(header.EnhancedSetter == false ? "" : $@" @@ -347,7 +347,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http {{{Each(loop.HeadersByLength, byLength => $@" case {byLength.Key}: {{{Each(byLength, header => $@" - if (""{header.Name}"".Equals(key, StringComparison.OrdinalIgnoreCase)) + if (""{header.Name}"".Equals(key, StringComparison.OrdinalIgnoreCase)) {{ if ({header.TestBit()}) {{ @@ -372,7 +372,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http _headers = default(HeaderReferences); MaybeUnknown?.Clear(); }} - + protected override void CopyToFast(KeyValuePair[] array, int arrayIndex) {{ if (arrayIndex < 0) @@ -380,7 +380,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThrowArgumentException(); }} {Each(loop.Headers, header => $@" - if ({header.TestBit()}) + if ({header.TestBit()}) {{ if (arrayIndex == array.Length) {{ @@ -397,12 +397,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http protected void CopyToFast(ref MemoryPoolIterator output) {{ {Each(loop.Headers, header => $@" - if ({header.TestBit()}) + if ({header.TestBit()}) {{ {(header.EnhancedSetter == false ? "" : $@" - if (_headers._raw{header.Identifier} != null) + if (_headers._raw{header.Identifier} != null) {{ output.CopyFrom(_headers._raw{header.Identifier}, 0, _headers._raw{header.Identifier}.Length); - }} + }} else ")} foreach (var value in _headers._{header.Identifier}) {{ @@ -418,17 +418,18 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http {(loop.ClassName == "FrameRequestHeaders" ? $@" public unsafe void Append(byte[] keyBytes, int keyOffset, int keyLength, string value) {{ - fixed (byte* ptr = &keyBytes[keyOffset]) - {{ - var pUB = ptr; - var pUL = (ulong*)pUB; - var pUI = (uint*)pUB; + var key = new string('\0', keyLength); + fixed (byte* ptr = &keyBytes[keyOffset]) + {{ + var pUB = ptr; + var pUL = (ulong*)pUB; + var pUI = (uint*)pUB; var pUS = (ushort*)pUB; switch (keyLength) {{{Each(loop.HeadersByLength, byLength => $@" case {byLength.Key}: {{{Each(byLength, header => $@" - if ({header.EqualIgnoreCaseBytes()}) + if ({header.EqualIgnoreCaseBytes()}) {{ if ({header.TestBit()}) {{ @@ -445,8 +446,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ")}}} break; ")}}} + + fixed(char *keyBuffer = key) + {{ + if (!AsciiUtilities.TryGetAsciiString(ptr, keyBuffer, keyLength)) + {{ + throw new BadHttpRequestException(""Invalid characters in header name""); + }} + }} }} - var key = System.Text.Encoding.ASCII.GetString(keyBytes, keyOffset, keyLength); + StringValues existing; Unknown.TryGetValue(key, out existing); Unknown[key] = AppendValue(existing, value); From 2d229e898042eea36d179dc5583c1d62e758922d Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Tue, 31 May 2016 17:20:04 -0700 Subject: [PATCH 0772/1662] Allow a maximum of 3 concurrent uv_write operations per connection - Keep logic to prevent unnecessary calls to KestrelThread.Post - This partially reverts commit 480996433e5f21bd37d7c51ae2e68af52c44cc2e. --- .../Http/SocketOutput.cs | 29 ++++- .../SocketOutputTests.cs | 117 ++++++++++++++++++ .../TestHelpers/MockLibuv.cs | 3 + 3 files changed, 145 insertions(+), 4 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketOutput.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketOutput.cs index 5db2fb3ebc..894da621aa 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketOutput.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketOutput.cs @@ -16,6 +16,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { public const int MaxPooledWriteReqs = 1024; + private const int _maxPendingWrites = 3; private const int _maxBytesPreCompleted = 65536; private const int _initialTaskQueues = 64; private const int _maxPooledWriteContexts = 32; @@ -44,7 +45,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http // The number of write operations that have been scheduled so far // but have not completed. - private bool _writePending = false; + private int _ongoingWrites = 0; + // Whether or not a write operation is pending to start on the uv thread. + // If this is true, there is no reason to schedule another write even if + // there aren't yet three ongoing write operations. + private bool _postingWrite = false; + private bool _cancelled = false; private int _numBytesPreCompleted = 0; private Exception _lastWriteError; @@ -185,9 +191,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } - if (!_writePending) + if (!_postingWrite && _ongoingWrites < _maxPendingWrites) { - _writePending = true; + _postingWrite = true; + _ongoingWrites++; scheduleWrite = true; } } @@ -325,13 +332,17 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if (Monitor.TryEnter(_contextLock)) { - _writePending = false; + _postingWrite = false; if (_nextWriteContext != null) { writingContext = _nextWriteContext; _nextWriteContext = null; } + else + { + _ongoingWrites--; + } Monitor.Exit(_contextLock); } @@ -379,6 +390,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http CompleteAllWrites(); _log.ConnectionError(_connectionId, error); } + + if (!_postingWrite && _nextWriteContext != null) + { + _postingWrite = true; + ScheduleWrite(); + } + else + { + _ongoingWrites--; + } } private void CompleteNextWrite(ref int bytesLeftToBuffer) diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/SocketOutputTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/SocketOutputTests.cs index 853b22f577..ccab2eafc3 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/SocketOutputTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/SocketOutputTests.cs @@ -544,5 +544,122 @@ namespace Microsoft.AspNetCore.Server.KestrelTests default(ArraySegment), default(CancellationToken), socketDisconnect: true); } } + + [Fact] + public void OnlyAllowsUpToThreeConcurrentWrites() + { + var writeWh = new ManualResetEventSlim(); + var completeQueue = new Queue>(); + + var mockLibuv = new MockLibuv + { + OnWrite = (socket, buffers, triggerCompleted) => + { + writeWh.Set(); + completeQueue.Enqueue(triggerCompleted); + return 0; + } + }; + + using (var memory = new MemoryPool()) + using (var kestrelEngine = new KestrelEngine(mockLibuv, new TestServiceContext())) + { + kestrelEngine.Start(count: 1); + + var kestrelThread = kestrelEngine.Threads[0]; + var socket = new MockSocket(mockLibuv, kestrelThread.Loop.ThreadId, new TestKestrelTrace()); + var trace = new KestrelTrace(new TestKestrelTrace()); + var ltp = new LoggingThreadPool(trace); + var socketOutput = new SocketOutput(kestrelThread, socket, memory, new MockConnection(), "0", trace, ltp, new Queue()); + + var buffer = new ArraySegment(new byte[1]); + + // First three writes trigger uv_write + socketOutput.WriteAsync(buffer, CancellationToken.None); + Assert.True(writeWh.Wait(1000)); + writeWh.Reset(); + socketOutput.WriteAsync(buffer, CancellationToken.None); + Assert.True(writeWh.Wait(1000)); + writeWh.Reset(); + socketOutput.WriteAsync(buffer, CancellationToken.None); + Assert.True(writeWh.Wait(1000)); + writeWh.Reset(); + + // The fourth write won't trigger uv_write since the first three haven't completed + socketOutput.WriteAsync(buffer, CancellationToken.None); + Assert.False(writeWh.Wait(1000)); + + // Complete 1st write allowing uv_write to be triggered again + completeQueue.Dequeue()(0); + Assert.True(writeWh.Wait(1000)); + + // Cleanup + var cleanupTask = socketOutput.WriteAsync( + default(ArraySegment), default(CancellationToken), socketDisconnect: true); + + foreach (var triggerCompleted in completeQueue) + { + triggerCompleted(0); + } + } + } + + [Fact] + public void WritesAreAggregated() + { + var writeWh = new ManualResetEventSlim(); + var writeCount = 0; + + var mockLibuv = new MockLibuv + { + OnWrite = (socket, buffers, triggerCompleted) => + { + writeCount++; + triggerCompleted(0); + writeWh.Set(); + return 0; + } + }; + + using (var memory = new MemoryPool()) + using (var kestrelEngine = new KestrelEngine(mockLibuv, new TestServiceContext())) + { + kestrelEngine.Start(count: 1); + + var kestrelThread = kestrelEngine.Threads[0]; + var socket = new MockSocket(mockLibuv, kestrelThread.Loop.ThreadId, new TestKestrelTrace()); + var trace = new KestrelTrace(new TestKestrelTrace()); + var ltp = new LoggingThreadPool(trace); + var socketOutput = new SocketOutput(kestrelThread, socket, memory, new MockConnection(), "0", trace, ltp, new Queue()); + + var blockThreadWh = new ManualResetEventSlim(); + kestrelThread.Post(_ => + { + blockThreadWh.Wait(); + }, state: null); + + var buffer = new ArraySegment(new byte[1]); + + // Two calls to WriteAsync trigger uv_write once if both calls + // are made before write is scheduled + socketOutput.WriteAsync(buffer, CancellationToken.None); + socketOutput.WriteAsync(buffer, CancellationToken.None); + + blockThreadWh.Set(); + + Assert.True(writeWh.Wait(1000)); + writeWh.Reset(); + + // Write isn't called twice after the thread is unblocked + Assert.False(writeWh.Wait(1000)); + Assert.Equal(1, writeCount); + // One call to ScheduleWrite + One call to Post to block the thread + Assert.Equal(2, mockLibuv.PostCount); + + // Cleanup + var cleanupTask = socketOutput.WriteAsync( + default(ArraySegment), default(CancellationToken), socketDisconnect: true); + } + } } } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockLibuv.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockLibuv.cs index 745a3eca11..80b4befc3f 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockLibuv.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockLibuv.cs @@ -27,6 +27,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests.TestHelpers _uv_async_send = postHandle => { + PostCount++; _loopWh.Set(); return 0; @@ -95,6 +96,8 @@ namespace Microsoft.AspNetCore.Server.KestrelTests.TestHelpers public uv_read_cb ReadCallback { get; set; } + public int PostCount { get; set; } + private int UvReadStart(UvStreamHandle handle, uv_alloc_cb allocCallback, uv_read_cb readCallback) { AllocCallback = allocCallback; From 07744e75d90b9c3a9542492306940c391082b889 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Wed, 1 Jun 2016 10:47:34 -0700 Subject: [PATCH 0773/1662] Gracefully handle connection close in SocketOutput.ProducingComplete --- .../Http/SocketOutput.cs | 8 +++- .../SocketOutputTests.cs | 41 +++++++++++++++---- .../TestHelpers/MockConnection.cs | 12 ++++++ .../TestHelpers/MockLibuv.cs | 18 ++------ 4 files changed, 54 insertions(+), 25 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketOutput.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketOutput.cs index 894da621aa..f0b23651e7 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketOutput.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketOutput.cs @@ -248,7 +248,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http public void ProducingComplete(MemoryPoolIterator end) { - Debug.Assert(!_lastStart.IsDefault); + if(_lastStart.IsDefault) + { + return; + } int bytesProduced, buffersIncluded; BytesBetween(_lastStart, end, out bytesProduced, out buffersIncluded); @@ -265,9 +268,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { MemoryPoolBlock blockToReturn = null; - lock (_returnLock) { + // Both ProducingComplete and WriteAsync should not call this method + // if _lastStart was not set. Debug.Assert(!_lastStart.IsDefault); // If the socket has been closed, return the produced blocks diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/SocketOutputTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/SocketOutputTests.cs index ccab2eafc3..ab29f4cc4b 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/SocketOutputTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/SocketOutputTests.cs @@ -24,14 +24,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests // _maxBytesPreCompleted even after the write actually completed. // Arrange - var mockLibuv = new MockLibuv - { - OnWrite = (socket, buffers, triggerCompleted) => - { - triggerCompleted(0); - return 0; - } - }; + var mockLibuv = new MockLibuv(); using (var memory = new MemoryPool()) using (var kestrelEngine = new KestrelEngine(mockLibuv, new TestServiceContext())) @@ -661,5 +654,37 @@ namespace Microsoft.AspNetCore.Server.KestrelTests default(ArraySegment), default(CancellationToken), socketDisconnect: true); } } + + [Fact] + public void ProducingStartAndProducingCompleteCanBeCalledAfterConnectionClose() + { + var mockLibuv = new MockLibuv(); + + using (var memory = new MemoryPool()) + using (var kestrelEngine = new KestrelEngine(mockLibuv, new TestServiceContext())) + { + kestrelEngine.Start(count: 1); + + var kestrelThread = kestrelEngine.Threads[0]; + var socket = new MockSocket(mockLibuv, kestrelThread.Loop.ThreadId, new TestKestrelTrace()); + var trace = new KestrelTrace(new TestKestrelTrace()); + var ltp = new LoggingThreadPool(trace); + var connection = new MockConnection(); + var socketOutput = new SocketOutput(kestrelThread, socket, memory, connection, "0", trace, ltp, new Queue()); + + // Close SocketOutput + var cleanupTask = socketOutput.WriteAsync( + default(ArraySegment), default(CancellationToken), socketDisconnect: true); + + Assert.True(connection.SocketClosed.Wait(1000)); + + var start = socketOutput.ProducingStart(); + + Assert.True(start.IsDefault); + // ProducingComplete should not throw given a default iterator + socketOutput.ProducingComplete(start); + + } + } } } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockConnection.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockConnection.cs index 3daea602c7..7181507494 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockConnection.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockConnection.cs @@ -3,12 +3,15 @@ using System; using System.Threading; +using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Http; namespace Microsoft.AspNetCore.Server.KestrelTests.TestHelpers { public class MockConnection : Connection, IDisposable { + private TaskCompletionSource _socketClosedTcs = new TaskCompletionSource(); + public MockConnection() { RequestAbortedSource = new CancellationTokenSource(); @@ -24,10 +27,19 @@ namespace Microsoft.AspNetCore.Server.KestrelTests.TestHelpers public override void OnSocketClosed() { + _socketClosedTcs.SetResult(null); } public CancellationTokenSource RequestAbortedSource { get; } + public Task SocketClosed + { + get + { + return _socketClosedTcs.Task; + } + } + public void Dispose() { RequestAbortedSource.Dispose(); diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockLibuv.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockLibuv.cs index 80b4befc3f..aa9c35523c 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockLibuv.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockLibuv.cs @@ -12,12 +12,10 @@ namespace Microsoft.AspNetCore.Server.KestrelTests.TestHelpers private bool _stopLoop; private readonly ManualResetEventSlim _loopWh = new ManualResetEventSlim(); - private Func, int> _onWrite; - unsafe public MockLibuv() : base(onlyForTesting: true) { - _onWrite = (socket, buffers, triggerCompleted) => + OnWrite = (socket, buffers, triggerCompleted) => { triggerCompleted(0); return 0; @@ -80,17 +78,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests.TestHelpers _uv_read_stop = handle => 0; } - public Func, int> OnWrite - { - get - { - return _onWrite; - } - set - { - _onWrite = value; - } - } + public Func, int> OnWrite { get; set; } public uv_alloc_cb AllocCallback { get; set; } @@ -107,7 +95,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests.TestHelpers unsafe private int UvWrite(UvRequest req, UvStreamHandle handle, uv_buf_t* bufs, int nbufs, uv_write_cb cb) { - return _onWrite(handle, nbufs, status => cb(req.InternalGetHandle(), status)); + return OnWrite(handle, nbufs, status => cb(req.InternalGetHandle(), status)); } } } From 6bff2ecb3420084c34563ceb3cbae448d0c86ca0 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Wed, 1 Jun 2016 12:04:48 -0700 Subject: [PATCH 0774/1662] Small cleanup to SocketOutput's shutdown logic --- .../Http/SocketOutput.cs | 17 ++++++----------- .../SocketOutputTests.cs | 1 - 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketOutput.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketOutput.cs index f0b23651e7..8b3ec4f042 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketOutput.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketOutput.cs @@ -248,7 +248,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http public void ProducingComplete(MemoryPoolIterator end) { - if(_lastStart.IsDefault) + if (_lastStart.IsDefault) { return; } @@ -560,7 +560,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http public int WriteStatus; public Exception WriteError; - public int ShutdownSendStatus; public WriteContext(SocketOutput self) { @@ -625,15 +624,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http var shutdownReq = new UvShutdownReq(Self._log); shutdownReq.Init(Self._thread.Loop); - shutdownReq.Shutdown(Self._socket, (_shutdownReq, status, state) => + shutdownReq.Shutdown(Self._socket, (req, status, state) => { - _shutdownReq.Dispose(); - var _this = (WriteContext)state; - _this.ShutdownSendStatus = status; + req.Dispose(); - _this.Self._log.ConnectionWroteFin(_this.Self._connectionId, status); - - _this.DoDisconnectIfNeeded(); + var writeContext = (WriteContext)state; + writeContext.Self._log.ConnectionWroteFin(writeContext.Self._connectionId, status); + writeContext.DoDisconnectIfNeeded(); }, this); } @@ -762,8 +759,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http WriteStatus = 0; WriteError = null; - - ShutdownSendStatus = 0; } } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/SocketOutputTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/SocketOutputTests.cs index ab29f4cc4b..a398c5cb66 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/SocketOutputTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/SocketOutputTests.cs @@ -683,7 +683,6 @@ namespace Microsoft.AspNetCore.Server.KestrelTests Assert.True(start.IsDefault); // ProducingComplete should not throw given a default iterator socketOutput.ProducingComplete(start); - } } } From d14f18012a18c2b959a89ffa3038b7113e854c54 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Wed, 1 Jun 2016 16:51:41 -0700 Subject: [PATCH 0775/1662] Avoid Null ReferenceException in Frame.RequestAbortedSource - Avoid unneeded resetting of _abortedCts and _manuallySetRequestAbortToken --- .../Http/Frame.cs | 13 ++++++++++--- .../Http/FrameOfT.cs | 5 ----- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs index 0a9eb6870c..e4f0b419ec 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs @@ -54,8 +54,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http private Task _requestProcessingTask; protected volatile bool _requestProcessingStopping; // volatile, see: https://msdn.microsoft.com/en-us/library/x13ttww7.aspx protected int _requestAborted; - protected CancellationTokenSource _abortedCts; - protected CancellationToken? _manuallySetRequestAbortToken; + private CancellationTokenSource _abortedCts; + private CancellationToken? _manuallySetRequestAbortToken; protected RequestProcessingStatus _requestProcessingStatus; protected bool _keepAlive; @@ -196,7 +196,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { // Get the abort token, lazily-initializing it if necessary. // Make sure it's canceled if an abort request already came in. - var cts = LazyInitializer.EnsureInitialized(ref _abortedCts, () => new CancellationTokenSource()); + + // EnsureInitialized can return null since _abortedCts is reset to null + // after it's already been initialized to a non-null value. + // If EnsureInitialized does return null, this property was accessed between + // requests so it's safe to return an ephemeral CancellationTokenSource. + var cts = LazyInitializer.EnsureInitialized(ref _abortedCts, () => new CancellationTokenSource()) + ?? new CancellationTokenSource(); + if (Volatile.Read(ref _requestAborted) == 1) { cts.Cancel(); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameOfT.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameOfT.cs index 13a04dea49..c11150fadc 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameOfT.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameOfT.cs @@ -87,9 +87,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http InitializeStreams(messageBody); - _abortedCts = null; - _manuallySetRequestAbortToken = null; - var context = _application.CreateContext(this); try { @@ -164,8 +161,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { await TryProduceInvalidRequestResponse(); - _abortedCts = null; - // If _requestAborted is set, the connection has already been closed. if (Volatile.Read(ref _requestAborted) == 0) { From ef74926463fa040b789c86aa244ae131a146db1c Mon Sep 17 00:00:00 2001 From: moozzyk Date: Fri, 3 Jun 2016 12:19:45 -0700 Subject: [PATCH 0776/1662] Fixing a test failing on Mac and Linux --- .../BadHttpRequestTests.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/BadHttpRequestTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/BadHttpRequestTests.cs index 1f2a5e6413..e4b9686157 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/BadHttpRequestTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/BadHttpRequestTests.cs @@ -181,7 +181,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { await connection.SendEnd( "GET / HTTP/1.1", - "Hdr: value", + "H\u00eb\u00e4d\u00ebr: value", "", ""); await ReceiveBadRequestResponse(connection); @@ -204,4 +204,4 @@ namespace Microsoft.AspNetCore.Server.KestrelTests ""); } } -} \ No newline at end of file +} From 09f5be1434257948414ae993f52f975f99bf26cd Mon Sep 17 00:00:00 2001 From: Andrew Stanton-Nurse Date: Fri, 3 Jun 2016 11:32:55 -0700 Subject: [PATCH 0777/1662] fix #909 by moving most classes to Internal ns --- makefile.shade | 2 +- .../{Exceptions => }/BadHttpRequestException.cs | 2 +- .../Filter/{ => Internal}/FilteredStreamAdapter.cs | 8 ++++---- .../Filter/{ => Internal}/LibuvStream.cs | 6 +++--- .../Filter/{ => Internal}/LoggingStream.cs | 2 +- .../Filter/{ => Internal}/StreamSocketOutput.cs | 6 +++--- .../Filter/LoggingConnectionFilter.cs | 1 + .../Filter/NoOpConnectionFilter.cs | 3 +-- .../{ => Internal}/Http/ChunkWriter.cs | 4 ++-- .../{ => Internal}/Http/Connection.cs | 7 ++++--- .../{ => Internal}/Http/ConnectionContext.cs | 2 +- .../{ => Internal}/Http/ConnectionManager.cs | 4 ++-- .../{ => Internal}/Http/DateHeaderValueManager.cs | 4 ++-- .../{ => Internal}/Http/Frame.FeatureCollection.cs | 2 +- .../{ => Internal}/Http/Frame.Generated.cs | 2 +- .../{ => Internal}/Http/Frame.cs | 5 ++--- .../{ => Internal}/Http/FrameDuplexStream.cs | 2 +- .../{ => Internal}/Http/FrameHeaders.Generated.cs | 5 ++--- .../{ => Internal}/Http/FrameHeaders.cs | 2 +- .../{ => Internal}/Http/FrameOfT.cs | 3 +-- .../{ => Internal}/Http/FrameRequestHeaders.cs | 4 ++-- .../{ => Internal}/Http/FrameRequestStream.cs | 4 ++-- .../{ => Internal}/Http/FrameResponseHeaders.cs | 4 ++-- .../{ => Internal}/Http/FrameResponseStream.cs | 4 ++-- .../{ => Internal}/Http/FrameStreamState.cs | 2 +- .../{ => Internal}/Http/IAsyncDisposable.cs | 2 +- .../{ => Internal}/Http/IConnectionControl.cs | 2 +- .../{ => Internal}/Http/IFrameControl.cs | 2 +- .../{ => Internal}/Http/ISocketOutput.cs | 4 ++-- .../{ => Internal}/Http/Listener.cs | 4 ++-- .../{ => Internal}/Http/ListenerContext.cs | 6 +++--- .../{ => Internal}/Http/ListenerPrimary.cs | 6 +++--- .../{ => Internal}/Http/ListenerSecondary.cs | 6 +++--- .../{ => Internal}/Http/MessageBody.cs | 6 ++---- .../{ => Internal}/Http/PathNormalizer.cs | 4 +--- .../{ => Internal}/Http/PipeListener.cs | 7 +++---- .../{ => Internal}/Http/PipeListenerPrimary.cs | 7 +++---- .../{ => Internal}/Http/PipeListenerSecondary.cs | 4 ++-- .../{ => Internal}/Http/ProduceEndType.cs | 2 +- .../{ => Internal}/Http/ReasonPhrases.cs | 2 +- .../{ => Internal}/Http/SocketInput.cs | 4 ++-- .../{ => Internal}/Http/SocketInputExtensions.cs | 3 +-- .../{ => Internal}/Http/SocketOutput.cs | 6 +++--- .../{ => Internal}/Http/TcpListener.cs | 6 +++--- .../{ => Internal}/Http/TcpListenerPrimary.cs | 8 +++----- .../{ => Internal}/Http/TcpListenerSecondary.cs | 4 ++-- .../{ => Internal}/Http/UrlPathDecoder.cs | 4 ++-- .../{ => Internal}/Infrastructure/AsciiUtilities.cs | 2 +- .../{ => Internal}/Infrastructure/Constants.cs | 2 +- .../{ => Internal}/Infrastructure/Disposable.cs | 2 +- .../{ => Internal}/Infrastructure/IKestrelTrace.cs | 3 +-- .../{ => Internal}/Infrastructure/ISystemClock.cs | 2 +- .../{ => Internal}/Infrastructure/IThreadPool.cs | 2 +- .../{ => Internal}/Infrastructure/KestrelThread.cs | 6 +++--- .../{ => Internal}/Infrastructure/KestrelTrace.cs | 5 ++--- .../{ => Internal}/Infrastructure/LoggingThreadPool.cs | 2 +- .../{ => Internal}/Infrastructure/MemoryPool.cs | 2 +- .../{ => Internal}/Infrastructure/MemoryPoolBlock.cs | 3 +-- .../{ => Internal}/Infrastructure/MemoryPoolIterator.cs | 2 +- .../Infrastructure/MemoryPoolIteratorExtensions.cs | 3 +-- .../{ => Internal}/Infrastructure/MemoryPoolSlab.cs | 2 +- .../{ => Internal}/Infrastructure/Streams.cs | 4 ++-- .../{ => Internal}/Infrastructure/SystemClock.cs | 2 +- .../{ => Internal}/Infrastructure/TaskUtilities.cs | 2 +- .../{ => Internal}/KestrelEngine.cs | 6 +++--- .../{ => Internal}/Networking/Libuv.cs | 2 +- .../{ => Internal}/Networking/PlatformApis.cs | 3 +-- .../{ => Internal}/Networking/SockAddr.cs | 2 +- .../{ => Internal}/Networking/UvAsyncHandle.cs | 4 ++-- .../{ => Internal}/Networking/UvConnectRequest.cs | 4 ++-- .../{ => Internal}/Networking/UvException.cs | 2 +- .../{ => Internal}/Networking/UvHandle.cs | 4 ++-- .../{ => Internal}/Networking/UvLoopHandle.cs | 4 ++-- .../{ => Internal}/Networking/UvMemory.cs | 4 ++-- .../{ => Internal}/Networking/UvPipeHandle.cs | 5 ++--- .../{ => Internal}/Networking/UvRequest.cs | 4 ++-- .../{ => Internal}/Networking/UvShutdownReq.cs | 4 ++-- .../{ => Internal}/Networking/UvStreamHandle.cs | 6 +++--- .../{ => Internal}/Networking/UvTcpHandle.cs | 4 ++-- .../{ => Internal}/Networking/UvWriteReq.cs | 4 ++-- .../{ => Internal}/ServiceContext.cs | 6 +++--- src/Microsoft.AspNetCore.Server.Kestrel/KestrelServer.cs | 8 ++++---- src/Microsoft.AspNetCore.Server.Kestrel/ServerAddress.cs | 3 +-- .../AddressRegistrationTests.cs | 2 +- .../AsciiDecoding.cs | 5 ++--- .../BadHttpRequestTests.cs | 2 +- .../ChunkWriterTests.cs | 2 +- .../ConnectionTests.cs | 9 +++++---- .../CreateIPEndpointTests.cs | 2 +- .../DateHeaderValueManagerTests.cs | 4 ++-- .../DefaultHeaderTests.cs | 2 +- .../EngineTests.cs | 5 +++-- .../FrameRequestHeadersTests.cs | 4 ++-- .../FrameRequestStreamTests.cs | 2 +- .../FrameResponseHeadersTests.cs | 2 +- .../FrameResponseStreamTests.cs | 2 +- .../FrameTests.cs | 8 +++----- .../HttpsConnectionFilterTests.cs | 6 +++--- .../KestrelServerTests.cs | 2 +- .../LoggingThreadPoolTests.cs | 2 +- .../MemoryPoolBlockTests.cs | 2 +- .../MemoryPoolExtensions.cs | 2 +- .../MemoryPoolIteratorTests.cs | 2 +- .../MessageBodyTests.cs | 2 +- .../MultipleLoopTests.cs | 5 +++-- .../NetworkingTests.cs | 5 +++-- .../PathNormalizerTests.cs | 2 +- .../SocketInputTests.cs | 5 +++-- .../SocketOutputTests.cs | 7 ++++--- .../StreamSocketOutputTests.cs | 3 ++- .../TestConnection.cs | 2 +- .../TestHelpers/MockConnection.cs | 2 +- .../TestHelpers/MockFrameControl.cs | 4 ++-- .../TestHelpers/MockLibuv.cs | 2 +- .../TestHelpers/MockSocket.cs | 4 ++-- .../TestHelpers/MockSocketOuptut.cs | 4 ++-- .../TestHelpers/MockSystemClock.cs | 2 +- .../TestHelpers/PassThroughConnectionFilter.cs | 3 ++- .../TestHelpers/TestApplicationErrorLogger.cs | 1 + .../TestHelpers/TestKestrelTrace.cs | 3 +-- .../TestInput.cs | 5 +++-- .../TestServer.cs | 3 ++- .../TestServiceContext.cs | 5 +++-- .../UrlPathDecoder.cs | 4 ++-- .../FrameFeatureCollection.cs | 2 +- .../KnownHeaders.cs | 5 ++--- 126 files changed, 225 insertions(+), 236 deletions(-) rename src/Microsoft.AspNetCore.Server.Kestrel/{Exceptions => }/BadHttpRequestException.cs (86%) rename src/Microsoft.AspNetCore.Server.Kestrel/Filter/{ => Internal}/FilteredStreamAdapter.cs (94%) rename src/Microsoft.AspNetCore.Server.Kestrel/Filter/{ => Internal}/LibuvStream.cs (95%) rename src/Microsoft.AspNetCore.Server.Kestrel/Filter/{ => Internal}/LoggingStream.cs (98%) rename src/Microsoft.AspNetCore.Server.Kestrel/Filter/{ => Internal}/StreamSocketOutput.cs (96%) rename src/Microsoft.AspNetCore.Server.Kestrel/{ => Internal}/Http/ChunkWriter.cs (94%) rename src/Microsoft.AspNetCore.Server.Kestrel/{ => Internal}/Http/Connection.cs (98%) rename src/Microsoft.AspNetCore.Server.Kestrel/{ => Internal}/Http/ConnectionContext.cs (95%) rename src/Microsoft.AspNetCore.Server.Kestrel/{ => Internal}/Http/ConnectionManager.cs (92%) rename src/Microsoft.AspNetCore.Server.Kestrel/{ => Internal}/Http/DateHeaderValueManager.cs (98%) rename src/Microsoft.AspNetCore.Server.Kestrel/{ => Internal}/Http/Frame.FeatureCollection.cs (99%) rename src/Microsoft.AspNetCore.Server.Kestrel/{ => Internal}/Http/Frame.Generated.cs (99%) rename src/Microsoft.AspNetCore.Server.Kestrel/{ => Internal}/Http/Frame.cs (99%) rename src/Microsoft.AspNetCore.Server.Kestrel/{ => Internal}/Http/FrameDuplexStream.cs (98%) rename src/Microsoft.AspNetCore.Server.Kestrel/{ => Internal}/Http/FrameHeaders.Generated.cs (99%) rename src/Microsoft.AspNetCore.Server.Kestrel/{ => Internal}/Http/FrameHeaders.cs (99%) rename src/Microsoft.AspNetCore.Server.Kestrel/{ => Internal}/Http/FrameOfT.cs (98%) rename src/Microsoft.AspNetCore.Server.Kestrel/{ => Internal}/Http/FrameRequestHeaders.cs (96%) rename src/Microsoft.AspNetCore.Server.Kestrel/{ => Internal}/Http/FrameRequestStream.cs (97%) rename src/Microsoft.AspNetCore.Server.Kestrel/{ => Internal}/Http/FrameResponseHeaders.cs (95%) rename src/Microsoft.AspNetCore.Server.Kestrel/{ => Internal}/Http/FrameResponseStream.cs (97%) rename src/Microsoft.AspNetCore.Server.Kestrel/{ => Internal}/Http/FrameStreamState.cs (81%) rename src/Microsoft.AspNetCore.Server.Kestrel/{ => Internal}/Http/IAsyncDisposable.cs (82%) rename src/Microsoft.AspNetCore.Server.Kestrel/{ => Internal}/Http/IConnectionControl.cs (83%) rename src/Microsoft.AspNetCore.Server.Kestrel/{ => Internal}/Http/IFrameControl.cs (89%) rename src/Microsoft.AspNetCore.Server.Kestrel/{ => Internal}/Http/ISocketOutput.cs (92%) rename src/Microsoft.AspNetCore.Server.Kestrel/{ => Internal}/Http/Listener.cs (96%) rename src/Microsoft.AspNetCore.Server.Kestrel/{ => Internal}/Http/ListenerContext.cs (87%) rename src/Microsoft.AspNetCore.Server.Kestrel/{ => Internal}/Http/ListenerPrimary.cs (97%) rename src/Microsoft.AspNetCore.Server.Kestrel/{ => Internal}/Http/ListenerSecondary.cs (97%) rename src/Microsoft.AspNetCore.Server.Kestrel/{ => Internal}/Http/MessageBody.cs (99%) rename src/Microsoft.AspNetCore.Server.Kestrel/{ => Internal}/Http/PathNormalizer.cs (97%) rename src/Microsoft.AspNetCore.Server.Kestrel/{ => Internal}/Http/PipeListener.cs (90%) rename src/Microsoft.AspNetCore.Server.Kestrel/{ => Internal}/Http/PipeListenerPrimary.cs (90%) rename src/Microsoft.AspNetCore.Server.Kestrel/{ => Internal}/Http/PipeListenerSecondary.cs (87%) rename src/Microsoft.AspNetCore.Server.Kestrel/{ => Internal}/Http/ProduceEndType.cs (82%) rename src/Microsoft.AspNetCore.Server.Kestrel/{ => Internal}/Http/ReasonPhrases.cs (99%) rename src/Microsoft.AspNetCore.Server.Kestrel/{ => Internal}/Http/SocketInput.cs (98%) rename src/Microsoft.AspNetCore.Server.Kestrel/{ => Internal}/Http/SocketInputExtensions.cs (94%) rename src/Microsoft.AspNetCore.Server.Kestrel/{ => Internal}/Http/SocketOutput.cs (99%) rename src/Microsoft.AspNetCore.Server.Kestrel/{ => Internal}/Http/TcpListener.cs (91%) rename src/Microsoft.AspNetCore.Server.Kestrel/{ => Internal}/Http/TcpListenerPrimary.cs (91%) rename src/Microsoft.AspNetCore.Server.Kestrel/{ => Internal}/Http/TcpListenerSecondary.cs (87%) rename src/Microsoft.AspNetCore.Server.Kestrel/{ => Internal}/Http/UrlPathDecoder.cs (98%) rename src/Microsoft.AspNetCore.Server.Kestrel/{ => Internal}/Infrastructure/AsciiUtilities.cs (97%) rename src/Microsoft.AspNetCore.Server.Kestrel/{ => Internal}/Infrastructure/Constants.cs (96%) rename src/Microsoft.AspNetCore.Server.Kestrel/{ => Internal}/Infrastructure/Disposable.cs (95%) rename src/Microsoft.AspNetCore.Server.Kestrel/{ => Internal}/Infrastructure/IKestrelTrace.cs (90%) rename src/Microsoft.AspNetCore.Server.Kestrel/{ => Internal}/Infrastructure/ISystemClock.cs (86%) rename src/Microsoft.AspNetCore.Server.Kestrel/{ => Internal}/Infrastructure/IThreadPool.cs (86%) rename src/Microsoft.AspNetCore.Server.Kestrel/{ => Internal}/Infrastructure/KestrelThread.cs (98%) rename src/Microsoft.AspNetCore.Server.Kestrel/{ => Internal}/Infrastructure/KestrelTrace.cs (97%) rename src/Microsoft.AspNetCore.Server.Kestrel/{ => Internal}/Infrastructure/LoggingThreadPool.cs (97%) rename src/Microsoft.AspNetCore.Server.Kestrel/{ => Internal}/Infrastructure/MemoryPool.cs (99%) rename src/Microsoft.AspNetCore.Server.Kestrel/{ => Internal}/Infrastructure/MemoryPoolBlock.cs (98%) rename src/Microsoft.AspNetCore.Server.Kestrel/{ => Internal}/Infrastructure/MemoryPoolIterator.cs (99%) rename src/Microsoft.AspNetCore.Server.Kestrel/{ => Internal}/Infrastructure/MemoryPoolIteratorExtensions.cs (99%) rename src/Microsoft.AspNetCore.Server.Kestrel/{ => Internal}/Infrastructure/MemoryPoolSlab.cs (98%) rename src/Microsoft.AspNetCore.Server.Kestrel/{ => Internal}/Infrastructure/Streams.cs (83%) rename src/Microsoft.AspNetCore.Server.Kestrel/{ => Internal}/Infrastructure/SystemClock.cs (89%) rename src/Microsoft.AspNetCore.Server.Kestrel/{ => Internal}/Infrastructure/TaskUtilities.cs (95%) rename src/Microsoft.AspNetCore.Server.Kestrel/{ => Internal}/KestrelEngine.cs (95%) rename src/Microsoft.AspNetCore.Server.Kestrel/{ => Internal}/Networking/Libuv.cs (99%) rename src/Microsoft.AspNetCore.Server.Kestrel/{ => Internal}/Networking/PlatformApis.cs (88%) rename src/Microsoft.AspNetCore.Server.Kestrel/{ => Internal}/Networking/SockAddr.cs (98%) rename src/Microsoft.AspNetCore.Server.Kestrel/{ => Internal}/Networking/UvAsyncHandle.cs (94%) rename src/Microsoft.AspNetCore.Server.Kestrel/{ => Internal}/Networking/UvConnectRequest.cs (93%) rename src/Microsoft.AspNetCore.Server.Kestrel/{ => Internal}/Networking/UvException.cs (86%) rename src/Microsoft.AspNetCore.Server.Kestrel/{ => Internal}/Networking/UvHandle.cs (93%) rename src/Microsoft.AspNetCore.Server.Kestrel/{ => Internal}/Networking/UvLoopHandle.cs (89%) rename src/Microsoft.AspNetCore.Server.Kestrel/{ => Internal}/Networking/UvMemory.cs (94%) rename src/Microsoft.AspNetCore.Server.Kestrel/{ => Internal}/Networking/UvPipeHandle.cs (86%) rename src/Microsoft.AspNetCore.Server.Kestrel/{ => Internal}/Networking/UvRequest.cs (81%) rename src/Microsoft.AspNetCore.Server.Kestrel/{ => Internal}/Networking/UvShutdownReq.cs (91%) rename src/Microsoft.AspNetCore.Server.Kestrel/{ => Internal}/Networking/UvStreamHandle.cs (96%) rename src/Microsoft.AspNetCore.Server.Kestrel/{ => Internal}/Networking/UvTcpHandle.cs (95%) rename src/Microsoft.AspNetCore.Server.Kestrel/{ => Internal}/Networking/UvWriteReq.cs (97%) rename src/Microsoft.AspNetCore.Server.Kestrel/{ => Internal}/ServiceContext.cs (85%) diff --git a/makefile.shade b/makefile.shade index c47d059fb9..a712540a3f 100644 --- a/makefile.shade +++ b/makefile.shade @@ -8,4 +8,4 @@ k-standard-goals custom-goals #initialize if='Directory.Exists("src")' - exec program='dotnet' commandline='run -p ../../tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode Http/FrameHeaders.Generated.cs Http/Frame.Generated.cs' workingdir='${kestrelSrcDir}' + exec program='dotnet' commandline='run -p ../../tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode Internal/Http/FrameHeaders.Generated.cs Internal/Http/Frame.Generated.cs' workingdir='${kestrelSrcDir}' diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Exceptions/BadHttpRequestException.cs b/src/Microsoft.AspNetCore.Server.Kestrel/BadHttpRequestException.cs similarity index 86% rename from src/Microsoft.AspNetCore.Server.Kestrel/Exceptions/BadHttpRequestException.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/BadHttpRequestException.cs index 19c004857e..f9ef840b12 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Exceptions/BadHttpRequestException.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/BadHttpRequestException.cs @@ -3,7 +3,7 @@ using System.IO; -namespace Microsoft.AspNetCore.Server.Kestrel.Exceptions +namespace Microsoft.AspNetCore.Server.Kestrel { public sealed class BadHttpRequestException : IOException { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Filter/FilteredStreamAdapter.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Filter/Internal/FilteredStreamAdapter.cs similarity index 94% rename from src/Microsoft.AspNetCore.Server.Kestrel/Filter/FilteredStreamAdapter.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Filter/Internal/FilteredStreamAdapter.cs index 8c721c5f91..bcd6b709e7 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Filter/FilteredStreamAdapter.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Filter/Internal/FilteredStreamAdapter.cs @@ -4,11 +4,11 @@ using System; using System.IO; using System.Threading.Tasks; -using Microsoft.AspNetCore.Server.Kestrel.Http; -using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.Extensions.Logging; -namespace Microsoft.AspNetCore.Server.Kestrel.Filter +namespace Microsoft.AspNetCore.Server.Kestrel.Filter.Internal { public class FilteredStreamAdapter : IDisposable { @@ -58,7 +58,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Filter { SocketInput.Dispose(); } - + private async Task FilterInputAsync(MemoryPoolBlock block) { int bytesRead; diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Filter/LibuvStream.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Filter/Internal/LibuvStream.cs similarity index 95% rename from src/Microsoft.AspNetCore.Server.Kestrel/Filter/LibuvStream.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Filter/Internal/LibuvStream.cs index bf2c2c65e7..3ae1ddbd69 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Filter/LibuvStream.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Filter/Internal/LibuvStream.cs @@ -5,10 +5,10 @@ using System; using System.IO; using System.Threading; using System.Threading.Tasks; -using Microsoft.AspNetCore.Server.Kestrel.Http; -using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; -namespace Microsoft.AspNetCore.Server.Kestrel.Filter +namespace Microsoft.AspNetCore.Server.Kestrel.Filter.Internal { public class LibuvStream : Stream { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Filter/LoggingStream.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Filter/Internal/LoggingStream.cs similarity index 98% rename from src/Microsoft.AspNetCore.Server.Kestrel/Filter/LoggingStream.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Filter/Internal/LoggingStream.cs index a292850a82..e43d1c7f2d 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Filter/LoggingStream.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Filter/Internal/LoggingStream.cs @@ -7,7 +7,7 @@ using System.Threading; using System.Threading.Tasks; using Microsoft.Extensions.Logging; -namespace Microsoft.AspNetCore.Server.Kestrel.Filter +namespace Microsoft.AspNetCore.Server.Kestrel.Filter.Internal { internal class LoggingStream : Stream { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Filter/StreamSocketOutput.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Filter/Internal/StreamSocketOutput.cs similarity index 96% rename from src/Microsoft.AspNetCore.Server.Kestrel/Filter/StreamSocketOutput.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Filter/Internal/StreamSocketOutput.cs index 0fce7a4760..bfd7d5201b 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Filter/StreamSocketOutput.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Filter/Internal/StreamSocketOutput.cs @@ -6,10 +6,10 @@ using System.IO; using System.Text; using System.Threading; using System.Threading.Tasks; -using Microsoft.AspNetCore.Server.Kestrel.Http; -using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; -namespace Microsoft.AspNetCore.Server.Kestrel.Filter +namespace Microsoft.AspNetCore.Server.Kestrel.Filter.Internal { public class StreamSocketOutput : ISocketOutput { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Filter/LoggingConnectionFilter.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Filter/LoggingConnectionFilter.cs index 81c900d8d3..fd77be1295 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Filter/LoggingConnectionFilter.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Filter/LoggingConnectionFilter.cs @@ -3,6 +3,7 @@ using System; using System.Threading.Tasks; +using Microsoft.AspNetCore.Server.Kestrel.Filter.Internal; using Microsoft.Extensions.Logging; namespace Microsoft.AspNetCore.Server.Kestrel.Filter diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Filter/NoOpConnectionFilter.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Filter/NoOpConnectionFilter.cs index f41316e21f..6aa78fc5fc 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Filter/NoOpConnectionFilter.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Filter/NoOpConnectionFilter.cs @@ -2,8 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Threading.Tasks; -using Microsoft.AspNetCore.Http.Features; -using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; namespace Microsoft.AspNetCore.Server.Kestrel.Filter { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/ChunkWriter.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ChunkWriter.cs similarity index 94% rename from src/Microsoft.AspNetCore.Server.Kestrel/Http/ChunkWriter.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ChunkWriter.cs index 62dd3499ad..51f9d9f58e 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/ChunkWriter.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ChunkWriter.cs @@ -3,9 +3,9 @@ using System; using System.Text; -using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; -namespace Microsoft.AspNetCore.Server.Kestrel.Http +namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { public static class ChunkWriter { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Connection.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Connection.cs similarity index 98% rename from src/Microsoft.AspNetCore.Server.Kestrel/Http/Connection.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Connection.cs index 1bfd927772..6472543165 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Connection.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Connection.cs @@ -5,11 +5,12 @@ using System; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Filter; -using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; -using Microsoft.AspNetCore.Server.Kestrel.Networking; +using Microsoft.AspNetCore.Server.Kestrel.Filter.Internal; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; using Microsoft.Extensions.Logging; -namespace Microsoft.AspNetCore.Server.Kestrel.Http +namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { public class Connection : ConnectionContext, IConnectionControl { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/ConnectionContext.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ConnectionContext.cs similarity index 95% rename from src/Microsoft.AspNetCore.Server.Kestrel/Http/ConnectionContext.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ConnectionContext.cs index bea3e7c7a5..f66f95d5ab 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/ConnectionContext.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ConnectionContext.cs @@ -5,7 +5,7 @@ using System; using System.Net; using Microsoft.AspNetCore.Http.Features; -namespace Microsoft.AspNetCore.Server.Kestrel.Http +namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { public class ConnectionContext : ListenerContext { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/ConnectionManager.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ConnectionManager.cs similarity index 92% rename from src/Microsoft.AspNetCore.Server.Kestrel/Http/ConnectionManager.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ConnectionManager.cs index 640832a412..f546a6c87e 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/ConnectionManager.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ConnectionManager.cs @@ -4,9 +4,9 @@ using System; using System.Collections.Generic; using System.Threading.Tasks; -using Microsoft.AspNetCore.Server.Kestrel.Networking; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; -namespace Microsoft.AspNetCore.Server.Kestrel.Http +namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { public class ConnectionManager { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/DateHeaderValueManager.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/DateHeaderValueManager.cs similarity index 98% rename from src/Microsoft.AspNetCore.Server.Kestrel/Http/DateHeaderValueManager.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/DateHeaderValueManager.cs index 57b0168364..b5fc6730e6 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/DateHeaderValueManager.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/DateHeaderValueManager.cs @@ -4,9 +4,9 @@ using System; using System.Text; using System.Threading; -using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; -namespace Microsoft.AspNetCore.Server.Kestrel.Http +namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { /// /// Manages the generation of the date header value. diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.FeatureCollection.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.FeatureCollection.cs similarity index 99% rename from src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.FeatureCollection.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.FeatureCollection.cs index dc452096c3..75c1404ba5 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.FeatureCollection.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.FeatureCollection.cs @@ -13,7 +13,7 @@ using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http.Features; using Microsoft.Extensions.Primitives; -namespace Microsoft.AspNetCore.Server.Kestrel.Http +namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { public partial class Frame : IFeatureCollection, IHttpRequestFeature, diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.Generated.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.Generated.cs similarity index 99% rename from src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.Generated.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.Generated.cs index 160304dcfc..adef63eee8 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.Generated.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.Generated.cs @@ -2,7 +2,7 @@ using System; using System.Collections.Generic; -namespace Microsoft.AspNetCore.Server.Kestrel.Http +namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { public partial class Frame { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs similarity index 99% rename from src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs index e4f0b419ec..9e45c3f695 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs @@ -11,14 +11,13 @@ using System.Text; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; -using Microsoft.AspNetCore.Server.Kestrel.Exceptions; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Primitives; // ReSharper disable AccessToModifiedClosure -namespace Microsoft.AspNetCore.Server.Kestrel.Http +namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { public abstract partial class Frame : ConnectionContext, IFrameControl { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameDuplexStream.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameDuplexStream.cs similarity index 98% rename from src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameDuplexStream.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameDuplexStream.cs index 7b904b15b3..7ec8b9a9bf 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameDuplexStream.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameDuplexStream.cs @@ -8,7 +8,7 @@ using System.IO; using System.Threading; using System.Threading.Tasks; -namespace Microsoft.AspNetCore.Server.Kestrel.Http +namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { class FrameDuplexStream : Stream { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameHeaders.Generated.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameHeaders.Generated.cs similarity index 99% rename from src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameHeaders.Generated.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameHeaders.Generated.cs index 804b9a9228..d72bc25e78 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameHeaders.Generated.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameHeaders.Generated.cs @@ -1,11 +1,10 @@ using System; using System.Collections.Generic; -using Microsoft.AspNetCore.Server.Kestrel.Exceptions; -using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.Extensions.Primitives; -namespace Microsoft.AspNetCore.Server.Kestrel.Http +namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { public partial class FrameRequestHeaders diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameHeaders.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameHeaders.cs similarity index 99% rename from src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameHeaders.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameHeaders.cs index ee7c1c562b..ba96ba8a47 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameHeaders.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameHeaders.cs @@ -8,7 +8,7 @@ using System.Linq; using Microsoft.AspNetCore.Http; using Microsoft.Extensions.Primitives; -namespace Microsoft.AspNetCore.Server.Kestrel.Http +namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { public abstract class FrameHeaders : IHeaderDictionary { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameOfT.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameOfT.cs similarity index 98% rename from src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameOfT.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameOfT.cs index c11150fadc..f19f287075 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameOfT.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameOfT.cs @@ -5,10 +5,9 @@ using System; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Hosting.Server; -using Microsoft.AspNetCore.Server.Kestrel.Exceptions; using Microsoft.Extensions.Logging; -namespace Microsoft.AspNetCore.Server.Kestrel.Http +namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { public class Frame : Frame { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameRequestHeaders.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameRequestHeaders.cs similarity index 96% rename from src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameRequestHeaders.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameRequestHeaders.cs index a90626f0ea..7d24bf3d8e 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameRequestHeaders.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameRequestHeaders.cs @@ -1,11 +1,11 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using Microsoft.Extensions.Primitives; using System.Collections; using System.Collections.Generic; +using Microsoft.Extensions.Primitives; -namespace Microsoft.AspNetCore.Server.Kestrel.Http +namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { public partial class FrameRequestHeaders : FrameHeaders { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameRequestStream.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameRequestStream.cs similarity index 97% rename from src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameRequestStream.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameRequestStream.cs index c19a10a5dc..f2f7b379be 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameRequestStream.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameRequestStream.cs @@ -5,9 +5,9 @@ using System; using System.IO; using System.Threading; using System.Threading.Tasks; -using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; -namespace Microsoft.AspNetCore.Server.Kestrel.Http +namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { class FrameRequestStream : Stream { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameResponseHeaders.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameResponseHeaders.cs similarity index 95% rename from src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameResponseHeaders.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameResponseHeaders.cs index 9697ad0e6d..9ea8056f27 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameResponseHeaders.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameResponseHeaders.cs @@ -3,10 +3,10 @@ using System.Collections; using System.Collections.Generic; -using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.Extensions.Primitives; -namespace Microsoft.AspNetCore.Server.Kestrel.Http +namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { public partial class FrameResponseHeaders : FrameHeaders { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameResponseStream.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameResponseStream.cs similarity index 97% rename from src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameResponseStream.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameResponseStream.cs index 82edafb318..61013ac16c 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameResponseStream.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameResponseStream.cs @@ -5,9 +5,9 @@ using System; using System.IO; using System.Threading; using System.Threading.Tasks; -using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; -namespace Microsoft.AspNetCore.Server.Kestrel.Http +namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { class FrameResponseStream : Stream { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameStreamState.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameStreamState.cs similarity index 81% rename from src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameStreamState.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameStreamState.cs index 8f92bad5b9..8e1e26eaa5 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameStreamState.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameStreamState.cs @@ -1,7 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -namespace Microsoft.AspNetCore.Server.Kestrel.Http +namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { enum FrameStreamState { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/IAsyncDisposable.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/IAsyncDisposable.cs similarity index 82% rename from src/Microsoft.AspNetCore.Server.Kestrel/Http/IAsyncDisposable.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/IAsyncDisposable.cs index e2fb35aef6..0a6115a6dd 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/IAsyncDisposable.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/IAsyncDisposable.cs @@ -3,7 +3,7 @@ using System.Threading.Tasks; -namespace Microsoft.AspNetCore.Server.Kestrel.Http +namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { interface IAsyncDisposable { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/IConnectionControl.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/IConnectionControl.cs similarity index 83% rename from src/Microsoft.AspNetCore.Server.Kestrel/Http/IConnectionControl.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/IConnectionControl.cs index 6da7cac561..fbc181bce3 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/IConnectionControl.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/IConnectionControl.cs @@ -1,7 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -namespace Microsoft.AspNetCore.Server.Kestrel.Http +namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { public interface IConnectionControl { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/IFrameControl.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/IFrameControl.cs similarity index 89% rename from src/Microsoft.AspNetCore.Server.Kestrel/Http/IFrameControl.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/IFrameControl.cs index f8ecbab894..0303188e3a 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/IFrameControl.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/IFrameControl.cs @@ -5,7 +5,7 @@ using System; using System.Threading; using System.Threading.Tasks; -namespace Microsoft.AspNetCore.Server.Kestrel.Http +namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { public interface IFrameControl { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/ISocketOutput.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ISocketOutput.cs similarity index 92% rename from src/Microsoft.AspNetCore.Server.Kestrel/Http/ISocketOutput.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ISocketOutput.cs index 51c95b13fe..29b57b8c90 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/ISocketOutput.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ISocketOutput.cs @@ -4,9 +4,9 @@ using System; using System.Threading; using System.Threading.Tasks; -using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; -namespace Microsoft.AspNetCore.Server.Kestrel.Http +namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { /// /// Operations performed for buffered socket output diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Listener.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Listener.cs similarity index 96% rename from src/Microsoft.AspNetCore.Server.Kestrel/Http/Listener.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Listener.cs index 063d0a2f5f..a44c1b87bf 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Listener.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Listener.cs @@ -3,10 +3,10 @@ using System; using System.Threading.Tasks; -using Microsoft.AspNetCore.Server.Kestrel.Networking; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; using Microsoft.Extensions.Logging; -namespace Microsoft.AspNetCore.Server.Kestrel.Http +namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { /// /// Base class for listeners in Kestrel. Listens for incoming connections diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/ListenerContext.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ListenerContext.cs similarity index 87% rename from src/Microsoft.AspNetCore.Server.Kestrel/Http/ListenerContext.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ListenerContext.cs index 607c347981..83e9956e48 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/ListenerContext.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ListenerContext.cs @@ -2,10 +2,10 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Collections.Generic; -using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; -using Microsoft.AspNetCore.Server.Kestrel.Networking; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; -namespace Microsoft.AspNetCore.Server.Kestrel.Http +namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { public class ListenerContext : ServiceContext { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/ListenerPrimary.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ListenerPrimary.cs similarity index 97% rename from src/Microsoft.AspNetCore.Server.Kestrel/Http/ListenerPrimary.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ListenerPrimary.cs index 4f5bb907fb..a9b938d158 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/ListenerPrimary.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ListenerPrimary.cs @@ -5,11 +5,11 @@ using System; using System.Collections.Generic; using System.Runtime.InteropServices; using System.Threading.Tasks; -using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; -using Microsoft.AspNetCore.Server.Kestrel.Networking; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; using Microsoft.Extensions.Logging; -namespace Microsoft.AspNetCore.Server.Kestrel.Http +namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { /// /// A primary listener waits for incoming connections on a specified socket. Incoming diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/ListenerSecondary.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ListenerSecondary.cs similarity index 97% rename from src/Microsoft.AspNetCore.Server.Kestrel/Http/ListenerSecondary.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ListenerSecondary.cs index 2e8e89911b..1a6ea958b4 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/ListenerSecondary.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ListenerSecondary.cs @@ -5,11 +5,11 @@ using System; using System.Runtime.InteropServices; using System.Threading; using System.Threading.Tasks; -using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; -using Microsoft.AspNetCore.Server.Kestrel.Networking; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; using Microsoft.Extensions.Logging; -namespace Microsoft.AspNetCore.Server.Kestrel.Http +namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { /// /// A secondary listener is delegated requests from a primary listener via a named pipe or diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/MessageBody.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/MessageBody.cs similarity index 99% rename from src/Microsoft.AspNetCore.Server.Kestrel/Http/MessageBody.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/MessageBody.cs index bd2a9ba2e5..5d0e37c29e 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/MessageBody.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/MessageBody.cs @@ -2,14 +2,12 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.IO; using System.Numerics; using System.Threading; using System.Threading.Tasks; -using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; -using Microsoft.AspNetCore.Server.Kestrel.Exceptions; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; -namespace Microsoft.AspNetCore.Server.Kestrel.Http +namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { public abstract class MessageBody { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/PathNormalizer.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/PathNormalizer.cs similarity index 97% rename from src/Microsoft.AspNetCore.Server.Kestrel/Http/PathNormalizer.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/PathNormalizer.cs index 65b59e4a0e..191eeb885e 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/PathNormalizer.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/PathNormalizer.cs @@ -1,11 +1,9 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System; using System.Buffers; -using System.Text; -namespace Microsoft.AspNetCore.Server.Kestrel.Http +namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { public static class PathNormalizer { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/PipeListener.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/PipeListener.cs similarity index 90% rename from src/Microsoft.AspNetCore.Server.Kestrel/Http/PipeListener.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/PipeListener.cs index 3ee24032d6..cb79dadd07 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/PipeListener.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/PipeListener.cs @@ -1,12 +1,11 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System; -using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; -using Microsoft.AspNetCore.Server.Kestrel.Networking; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; using Microsoft.Extensions.Logging; -namespace Microsoft.AspNetCore.Server.Kestrel.Http +namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { /// /// Implementation of that uses UNIX domain sockets as its transport. diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/PipeListenerPrimary.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/PipeListenerPrimary.cs similarity index 90% rename from src/Microsoft.AspNetCore.Server.Kestrel/Http/PipeListenerPrimary.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/PipeListenerPrimary.cs index 07d353119f..65b9521f1f 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/PipeListenerPrimary.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/PipeListenerPrimary.cs @@ -1,12 +1,11 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System; -using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; -using Microsoft.AspNetCore.Server.Kestrel.Networking; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; using Microsoft.Extensions.Logging; -namespace Microsoft.AspNetCore.Server.Kestrel.Http +namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { /// /// An implementation of using UNIX sockets. diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/PipeListenerSecondary.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/PipeListenerSecondary.cs similarity index 87% rename from src/Microsoft.AspNetCore.Server.Kestrel/Http/PipeListenerSecondary.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/PipeListenerSecondary.cs index 1ec2373b4c..be9879f13b 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/PipeListenerSecondary.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/PipeListenerSecondary.cs @@ -1,9 +1,9 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using Microsoft.AspNetCore.Server.Kestrel.Networking; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; -namespace Microsoft.AspNetCore.Server.Kestrel.Http +namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { /// /// An implementation of using UNIX sockets. diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/ProduceEndType.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ProduceEndType.cs similarity index 82% rename from src/Microsoft.AspNetCore.Server.Kestrel/Http/ProduceEndType.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ProduceEndType.cs index 4099e1c864..06da2e11e6 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/ProduceEndType.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ProduceEndType.cs @@ -1,7 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -namespace Microsoft.AspNetCore.Server.Kestrel.Http +namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { public enum ProduceEndType { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/ReasonPhrases.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ReasonPhrases.cs similarity index 99% rename from src/Microsoft.AspNetCore.Server.Kestrel/Http/ReasonPhrases.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ReasonPhrases.cs index df007f573e..e78847e300 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/ReasonPhrases.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ReasonPhrases.cs @@ -4,7 +4,7 @@ using System.Globalization; using System.Text; -namespace Microsoft.AspNetCore.Server.Kestrel.Http +namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { public static class ReasonPhrases { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketInput.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/SocketInput.cs similarity index 98% rename from src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketInput.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/SocketInput.cs index 87f82474c8..3082edf708 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketInput.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/SocketInput.cs @@ -7,9 +7,9 @@ using System.IO; using System.Runtime.CompilerServices; using System.Threading; using System.Threading.Tasks; -using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; -namespace Microsoft.AspNetCore.Server.Kestrel.Http +namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { public class SocketInput : ICriticalNotifyCompletion, IDisposable { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketInputExtensions.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/SocketInputExtensions.cs similarity index 94% rename from src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketInputExtensions.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/SocketInputExtensions.cs index 7a74140435..af16744bf5 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketInputExtensions.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/SocketInputExtensions.cs @@ -2,9 +2,8 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Threading.Tasks; -using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; -namespace Microsoft.AspNetCore.Server.Kestrel.Http +namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { public static class SocketInputExtensions { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketOutput.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/SocketOutput.cs similarity index 99% rename from src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketOutput.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/SocketOutput.cs index 8b3ec4f042..fc43cd67fa 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketOutput.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/SocketOutput.cs @@ -6,11 +6,11 @@ using System.Collections.Generic; using System.Diagnostics; using System.Threading; using System.Threading.Tasks; -using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; -using Microsoft.AspNetCore.Server.Kestrel.Networking; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; using Microsoft.Extensions.Logging; -namespace Microsoft.AspNetCore.Server.Kestrel.Http +namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { public class SocketOutput : ISocketOutput { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/TcpListener.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/TcpListener.cs similarity index 91% rename from src/Microsoft.AspNetCore.Server.Kestrel/Http/TcpListener.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/TcpListener.cs index cc7e3f9aff..353afad609 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/TcpListener.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/TcpListener.cs @@ -1,11 +1,11 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; -using Microsoft.AspNetCore.Server.Kestrel.Networking; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; using Microsoft.Extensions.Logging; -namespace Microsoft.AspNetCore.Server.Kestrel.Http +namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { /// /// Implementation of that uses TCP sockets as its transport. diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/TcpListenerPrimary.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/TcpListenerPrimary.cs similarity index 91% rename from src/Microsoft.AspNetCore.Server.Kestrel/Http/TcpListenerPrimary.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/TcpListenerPrimary.cs index 926cd014b2..dc47a375c5 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/TcpListenerPrimary.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/TcpListenerPrimary.cs @@ -1,13 +1,11 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System; -using System.Net; -using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; -using Microsoft.AspNetCore.Server.Kestrel.Networking; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; using Microsoft.Extensions.Logging; -namespace Microsoft.AspNetCore.Server.Kestrel.Http +namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { /// /// An implementation of using TCP sockets. diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/TcpListenerSecondary.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/TcpListenerSecondary.cs similarity index 87% rename from src/Microsoft.AspNetCore.Server.Kestrel/Http/TcpListenerSecondary.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/TcpListenerSecondary.cs index 1a19445d50..0a34eb7202 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/TcpListenerSecondary.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/TcpListenerSecondary.cs @@ -1,9 +1,9 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using Microsoft.AspNetCore.Server.Kestrel.Networking; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; -namespace Microsoft.AspNetCore.Server.Kestrel.Http +namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { /// /// An implementation of using TCP sockets. diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/UrlPathDecoder.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/UrlPathDecoder.cs similarity index 98% rename from src/Microsoft.AspNetCore.Server.Kestrel/Http/UrlPathDecoder.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/UrlPathDecoder.cs index 90895fe691..7ce0ce8990 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/UrlPathDecoder.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/UrlPathDecoder.cs @@ -1,9 +1,9 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; -namespace Microsoft.AspNetCore.Server.Kestrel.Http +namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { public class UrlPathDecoder { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/AsciiUtilities.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/AsciiUtilities.cs similarity index 97% rename from src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/AsciiUtilities.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/AsciiUtilities.cs index 2d9a04ee5b..1959ca23d9 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/AsciiUtilities.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/AsciiUtilities.cs @@ -1,7 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure +namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure { internal class AsciiUtilities { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/Constants.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/Constants.cs similarity index 96% rename from src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/Constants.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/Constants.cs index bbe6442f87..2d270d9955 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/Constants.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/Constants.cs @@ -3,7 +3,7 @@ using System.Runtime.InteropServices; -namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure +namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure { internal class Constants { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/Disposable.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/Disposable.cs similarity index 95% rename from src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/Disposable.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/Disposable.cs index 5d3b53c9df..fb0e68855f 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/Disposable.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/Disposable.cs @@ -3,7 +3,7 @@ using System; -namespace Microsoft.AspNetCore.Server.Kestrel +namespace Microsoft.AspNetCore.Server.Kestrel.Internal { /// /// Summary description for Disposable diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/IKestrelTrace.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/IKestrelTrace.cs similarity index 90% rename from src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/IKestrelTrace.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/IKestrelTrace.cs index 4dd0beb17d..e18a99ce21 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/IKestrelTrace.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/IKestrelTrace.cs @@ -1,8 +1,7 @@ using System; using Microsoft.Extensions.Logging; -using Microsoft.AspNetCore.Server.Kestrel.Exceptions; -namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure +namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure { public interface IKestrelTrace : ILogger { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/ISystemClock.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/ISystemClock.cs similarity index 86% rename from src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/ISystemClock.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/ISystemClock.cs index 1818f68fd2..0cf54d7e64 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/ISystemClock.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/ISystemClock.cs @@ -3,7 +3,7 @@ using System; -namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure +namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure { /// /// Abstracts the system clock to facilitate testing. diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/IThreadPool.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/IThreadPool.cs similarity index 86% rename from src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/IThreadPool.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/IThreadPool.cs index f9217bd992..e4fe4eb40a 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/IThreadPool.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/IThreadPool.cs @@ -4,7 +4,7 @@ using System; using System.Threading.Tasks; -namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure +namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure { public interface IThreadPool { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/KestrelThread.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/KestrelThread.cs similarity index 98% rename from src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/KestrelThread.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/KestrelThread.cs index b176cfa697..3813d75980 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/KestrelThread.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/KestrelThread.cs @@ -7,11 +7,11 @@ using System.Runtime.ExceptionServices; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Hosting; -using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; -using Microsoft.AspNetCore.Server.Kestrel.Networking; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; using Microsoft.Extensions.Logging; -namespace Microsoft.AspNetCore.Server.Kestrel +namespace Microsoft.AspNetCore.Server.Kestrel.Internal { /// /// Summary description for KestrelThread diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/KestrelTrace.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/KestrelTrace.cs similarity index 97% rename from src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/KestrelTrace.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/KestrelTrace.cs index 1869e3446e..0215b45374 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/KestrelTrace.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/KestrelTrace.cs @@ -2,11 +2,10 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; -using Microsoft.AspNetCore.Server.Kestrel.Exceptions; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.Extensions.Logging; -namespace Microsoft.AspNetCore.Server.Kestrel +namespace Microsoft.AspNetCore.Server.Kestrel.Internal { /// /// Summary description for KestrelTrace diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/LoggingThreadPool.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/LoggingThreadPool.cs similarity index 97% rename from src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/LoggingThreadPool.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/LoggingThreadPool.cs index e9625cffec..6cdf0014c2 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/LoggingThreadPool.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/LoggingThreadPool.cs @@ -6,7 +6,7 @@ using System.Threading; using System.Threading.Tasks; using Microsoft.Extensions.Logging; -namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure +namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure { public class LoggingThreadPool : IThreadPool { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPool.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPool.cs similarity index 99% rename from src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPool.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPool.cs index 6fd37f8a9c..4641206872 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPool.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPool.cs @@ -2,7 +2,7 @@ using System; using System.Collections.Concurrent; using System.Diagnostics; -namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure +namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure { /// /// Used to allocate and distribute re-usable blocks of memory. diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPoolBlock.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolBlock.cs similarity index 98% rename from src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPoolBlock.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolBlock.cs index a57332a839..52f6825a77 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPoolBlock.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolBlock.cs @@ -1,9 +1,8 @@ using System; using System.Diagnostics; -using System.Runtime.InteropServices; using System.Text; -namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure +namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure { /// /// Block tracking object used by the byte buffer memory pool. A slab is a large allocation which is divided into smaller blocks. The diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPoolIterator.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolIterator.cs similarity index 99% rename from src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPoolIterator.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolIterator.cs index 3e17b6c4b8..68397406bb 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPoolIterator.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolIterator.cs @@ -6,7 +6,7 @@ using System.Diagnostics; using System.Numerics; using System.Threading; -namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure +namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure { public struct MemoryPoolIterator { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPoolIteratorExtensions.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolIteratorExtensions.cs similarity index 99% rename from src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPoolIteratorExtensions.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolIteratorExtensions.cs index 5d1953166e..5845c4fa1e 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPoolIteratorExtensions.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolIteratorExtensions.cs @@ -4,9 +4,8 @@ using System; using System.Diagnostics; using System.Text; -using Microsoft.AspNetCore.Server.Kestrel.Exceptions; -namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure +namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure { public static class MemoryPoolIteratorExtensions { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPoolSlab.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolSlab.cs similarity index 98% rename from src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPoolSlab.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolSlab.cs index d0acab4d6c..e61b12c6ca 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPoolSlab.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolSlab.cs @@ -1,7 +1,7 @@ using System; using System.Runtime.InteropServices; -namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure +namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure { /// /// Slab tracking object used by the byte buffer memory pool. A slab is a large allocation which is divided into smaller blocks. The diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/Streams.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/Streams.cs similarity index 83% rename from src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/Streams.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/Streams.cs index af0a3384c2..18712eed2f 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/Streams.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/Streams.cs @@ -1,9 +1,9 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using Microsoft.AspNetCore.Server.Kestrel.Http; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; -namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure +namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure { class Streams { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/SystemClock.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/SystemClock.cs similarity index 89% rename from src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/SystemClock.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/SystemClock.cs index 1718890eea..eb4e7e099e 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/SystemClock.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/SystemClock.cs @@ -3,7 +3,7 @@ using System; -namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure +namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure { /// /// Provides access to the normal system clock. diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/TaskUtilities.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/TaskUtilities.cs similarity index 95% rename from src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/TaskUtilities.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/TaskUtilities.cs index 328c8ecb05..139411bca0 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/TaskUtilities.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/TaskUtilities.cs @@ -4,7 +4,7 @@ using System.Threading; using System.Threading.Tasks; -namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure +namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure { public static class TaskUtilities { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/KestrelEngine.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/KestrelEngine.cs similarity index 95% rename from src/Microsoft.AspNetCore.Server.Kestrel/KestrelEngine.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Internal/KestrelEngine.cs index db0e28956d..a3faaad6a4 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/KestrelEngine.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/KestrelEngine.cs @@ -4,10 +4,10 @@ using System; using System.Collections.Generic; using System.Threading.Tasks; -using Microsoft.AspNetCore.Server.Kestrel.Http; -using Microsoft.AspNetCore.Server.Kestrel.Networking; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; -namespace Microsoft.AspNetCore.Server.Kestrel +namespace Microsoft.AspNetCore.Server.Kestrel.Internal { public class KestrelEngine : ServiceContext, IDisposable { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Networking/Libuv.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/Libuv.cs similarity index 99% rename from src/Microsoft.AspNetCore.Server.Kestrel/Networking/Libuv.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/Libuv.cs index a5028b136c..ee2a25855e 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Networking/Libuv.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/Libuv.cs @@ -4,7 +4,7 @@ using System; using System.Runtime.InteropServices; -namespace Microsoft.AspNetCore.Server.Kestrel.Networking +namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking { public class Libuv { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Networking/PlatformApis.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/PlatformApis.cs similarity index 88% rename from src/Microsoft.AspNetCore.Server.Kestrel/Networking/PlatformApis.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/PlatformApis.cs index 17985da608..e81974adb2 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Networking/PlatformApis.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/PlatformApis.cs @@ -1,10 +1,9 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System; using System.Runtime.InteropServices; -namespace Microsoft.AspNetCore.Server.Kestrel.Networking +namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking { public static class PlatformApis { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Networking/SockAddr.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/SockAddr.cs similarity index 98% rename from src/Microsoft.AspNetCore.Server.Kestrel/Networking/SockAddr.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/SockAddr.cs index 29c850df84..d2d14774ef 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Networking/SockAddr.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/SockAddr.cs @@ -4,7 +4,7 @@ using System; using System.Net; -namespace Microsoft.AspNetCore.Server.Kestrel.Networking +namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking { public struct SockAddr { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvAsyncHandle.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/UvAsyncHandle.cs similarity index 94% rename from src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvAsyncHandle.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/UvAsyncHandle.cs index 3215a8730c..93c1efcc64 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvAsyncHandle.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/UvAsyncHandle.cs @@ -4,9 +4,9 @@ using System; using System.Diagnostics; using System.Threading; -using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; -namespace Microsoft.AspNetCore.Server.Kestrel.Networking +namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking { public class UvAsyncHandle : UvHandle { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvConnectRequest.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/UvConnectRequest.cs similarity index 93% rename from src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvConnectRequest.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/UvConnectRequest.cs index bccd31a57b..85df07621d 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvConnectRequest.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/UvConnectRequest.cs @@ -2,10 +2,10 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.Extensions.Logging; -namespace Microsoft.AspNetCore.Server.Kestrel.Networking +namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking { /// /// Summary description for UvWriteRequest diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvException.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/UvException.cs similarity index 86% rename from src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvException.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/UvException.cs index 791c1f95ac..5e7b26e998 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvException.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/UvException.cs @@ -3,7 +3,7 @@ using System; -namespace Microsoft.AspNetCore.Server.Kestrel.Networking +namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking { public class UvException : Exception { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvHandle.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/UvHandle.cs similarity index 93% rename from src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvHandle.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/UvHandle.cs index d672189698..3db7dc21a3 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvHandle.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/UvHandle.cs @@ -4,9 +4,9 @@ using System; using System.Diagnostics; using System.Threading; -using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; -namespace Microsoft.AspNetCore.Server.Kestrel.Networking +namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking { public abstract class UvHandle : UvMemory { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvLoopHandle.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/UvLoopHandle.cs similarity index 89% rename from src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvLoopHandle.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/UvLoopHandle.cs index e368c6ea34..0d92f89770 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvLoopHandle.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/UvLoopHandle.cs @@ -3,9 +3,9 @@ using System; using System.Threading; -using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; -namespace Microsoft.AspNetCore.Server.Kestrel.Networking +namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking { public class UvLoopHandle : UvMemory { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvMemory.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/UvMemory.cs similarity index 94% rename from src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvMemory.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/UvMemory.cs index 162fed17e8..ecd15751e5 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvMemory.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/UvMemory.cs @@ -5,9 +5,9 @@ using System; using System.Diagnostics; using System.Runtime.InteropServices; using System.Threading; -using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; -namespace Microsoft.AspNetCore.Server.Kestrel.Networking +namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking { /// /// Summary description for UvMemory diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvPipeHandle.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/UvPipeHandle.cs similarity index 86% rename from src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvPipeHandle.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/UvPipeHandle.cs index 6604dfbb28..ef2d2d9bea 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvPipeHandle.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/UvPipeHandle.cs @@ -2,10 +2,9 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.Net; -using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; -namespace Microsoft.AspNetCore.Server.Kestrel.Networking +namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking { public class UvPipeHandle : UvStreamHandle { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvRequest.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/UvRequest.cs similarity index 81% rename from src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvRequest.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/UvRequest.cs index 87fe48c726..bffeb5d5e2 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvRequest.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/UvRequest.cs @@ -1,8 +1,8 @@ using System; using System.Runtime.InteropServices; -using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; -namespace Microsoft.AspNetCore.Server.Kestrel.Networking +namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking { public class UvRequest : UvMemory { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvShutdownReq.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/UvShutdownReq.cs similarity index 91% rename from src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvShutdownReq.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/UvShutdownReq.cs index 0342b3d25f..f69937e5b8 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvShutdownReq.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/UvShutdownReq.cs @@ -2,9 +2,9 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; -namespace Microsoft.AspNetCore.Server.Kestrel.Networking +namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking { /// /// Summary description for UvShutdownRequest diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvStreamHandle.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/UvStreamHandle.cs similarity index 96% rename from src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvStreamHandle.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/UvStreamHandle.cs index eb94d78ef0..bc0bbc64a9 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvStreamHandle.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/UvStreamHandle.cs @@ -3,11 +3,11 @@ using System; using System.Runtime.InteropServices; -using Microsoft.AspNetCore.Server.Kestrel.Http; -using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.Extensions.Logging; -namespace Microsoft.AspNetCore.Server.Kestrel.Networking +namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking { public abstract class UvStreamHandle : UvHandle { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvTcpHandle.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/UvTcpHandle.cs similarity index 95% rename from src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvTcpHandle.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/UvTcpHandle.cs index 6e7e9b2549..3684f4f412 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvTcpHandle.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/UvTcpHandle.cs @@ -4,9 +4,9 @@ using System; using System.Net; using System.Runtime.InteropServices; -using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; -namespace Microsoft.AspNetCore.Server.Kestrel.Networking +namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking { public class UvTcpHandle : UvStreamHandle { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvWriteReq.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/UvWriteReq.cs similarity index 97% rename from src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvWriteReq.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/UvWriteReq.cs index bc776767a6..4a0aec28bc 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvWriteReq.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/UvWriteReq.cs @@ -4,10 +4,10 @@ using System; using System.Collections.Generic; using System.Runtime.InteropServices; -using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.Extensions.Logging; -namespace Microsoft.AspNetCore.Server.Kestrel.Networking +namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking { /// /// Summary description for UvWriteRequest diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/ServiceContext.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/ServiceContext.cs similarity index 85% rename from src/Microsoft.AspNetCore.Server.Kestrel/ServiceContext.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Internal/ServiceContext.cs index a2e1aa4f53..77932ecf15 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/ServiceContext.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/ServiceContext.cs @@ -3,10 +3,10 @@ using System; using Microsoft.AspNetCore.Hosting; -using Microsoft.AspNetCore.Server.Kestrel.Http; -using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; -namespace Microsoft.AspNetCore.Server.Kestrel +namespace Microsoft.AspNetCore.Server.Kestrel.Internal { public class ServiceContext { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServer.cs b/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServer.cs index 1770678b29..3a38ce6df6 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServer.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServer.cs @@ -4,15 +4,15 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Net; using System.Reflection; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting.Server; using Microsoft.AspNetCore.Hosting.Server.Features; using Microsoft.AspNetCore.Http.Features; -using Microsoft.AspNetCore.Server.Kestrel.Http; -using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; -using Microsoft.AspNetCore.Server.Kestrel.Networking; +using Microsoft.AspNetCore.Server.Kestrel.Internal; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/ServerAddress.cs b/src/Microsoft.AspNetCore.Server.Kestrel/ServerAddress.cs index 17258184dd..67d00e1700 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/ServerAddress.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/ServerAddress.cs @@ -4,8 +4,7 @@ using System; using System.Diagnostics; using System.Globalization; -using Microsoft.AspNetCore.Server.Kestrel.Http; -using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; namespace Microsoft.AspNetCore.Server.Kestrel { diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs index c5f90cf61b..ee0651920c 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs @@ -12,7 +12,7 @@ using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting.Server.Features; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http.Extensions; -using Microsoft.AspNetCore.Server.Kestrel.Networking; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; using Microsoft.AspNetCore.Testing.xunit; using Xunit; diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/AsciiDecoding.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/AsciiDecoding.cs index 8d62e034c5..91d368a90b 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/AsciiDecoding.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/AsciiDecoding.cs @@ -1,10 +1,9 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System; using System.Linq; -using Microsoft.AspNetCore.Server.Kestrel.Exceptions; -using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Xunit; namespace Microsoft.AspNetCore.Server.KestrelTests diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/BadHttpRequestTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/BadHttpRequestTests.cs index e4b9686157..77a6db674f 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/BadHttpRequestTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/BadHttpRequestTests.cs @@ -2,7 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Threading.Tasks; -using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Xunit; namespace Microsoft.AspNetCore.Server.KestrelTests diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkWriterTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkWriterTests.cs index af70086103..d66ac3f60b 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkWriterTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkWriterTests.cs @@ -3,7 +3,7 @@ using System.Linq; using System.Text; -using Microsoft.AspNetCore.Server.Kestrel.Http; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; using Xunit; namespace Microsoft.AspNetCore.Server.KestrelTests diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionTests.cs index f5313a6f10..f6b43c2d13 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionTests.cs @@ -1,9 +1,10 @@ using System.Threading; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Server.Kestrel; -using Microsoft.AspNetCore.Server.Kestrel.Http; -using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; -using Microsoft.AspNetCore.Server.Kestrel.Networking; +using Microsoft.AspNetCore.Server.Kestrel.Internal; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; using Microsoft.AspNetCore.Server.KestrelTests.TestHelpers; using Xunit; @@ -15,7 +16,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests public void DoesNotEndConnectionOnZeroRead() { var mockLibuv = new MockLibuv(); - + using (var memory = new MemoryPool()) using (var engine = new KestrelEngine(mockLibuv, new TestServiceContext())) { diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/CreateIPEndpointTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/CreateIPEndpointTests.cs index 7c097f66e8..7a8742e864 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/CreateIPEndpointTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/CreateIPEndpointTests.cs @@ -3,7 +3,7 @@ using System.Net; using Microsoft.AspNetCore.Server.Kestrel; -using Microsoft.AspNetCore.Server.Kestrel.Networking; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; using Xunit; namespace Microsoft.AspNetCore.Server.KestrelTests diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/DateHeaderValueManagerTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/DateHeaderValueManagerTests.cs index 0c221cba52..0d3e4dc133 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/DateHeaderValueManagerTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/DateHeaderValueManagerTests.cs @@ -3,8 +3,8 @@ using System; using System.Threading.Tasks; -using Microsoft.AspNetCore.Server.Kestrel.Http; -using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.AspNetCore.Server.KestrelTests.TestHelpers; using Xunit; diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/DefaultHeaderTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/DefaultHeaderTests.cs index b682dd35de..890f663d12 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/DefaultHeaderTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/DefaultHeaderTests.cs @@ -4,7 +4,7 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Server.Kestrel; -using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Xunit; namespace Microsoft.AspNetCore.Server.KestrelTests diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs index d90c38ad6c..c2b1a7aa37 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs @@ -11,8 +11,9 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Server.Kestrel; -using Microsoft.AspNetCore.Server.Kestrel.Http; -using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Internal; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Xunit; namespace Microsoft.AspNetCore.Server.KestrelTests diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameRequestHeadersTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameRequestHeadersTests.cs index 14ef396c1e..6f07dd90ac 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameRequestHeadersTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameRequestHeadersTests.cs @@ -1,8 +1,8 @@ using System; using System.Collections.Generic; using System.Text; -using Microsoft.AspNetCore.Server.Kestrel.Exceptions; -using Microsoft.AspNetCore.Server.Kestrel.Http; +using Microsoft.AspNetCore.Server.Kestrel; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; using Microsoft.Extensions.Primitives; using Xunit; diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameRequestStreamTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameRequestStreamTests.cs index b201db9b99..80368ee5d2 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameRequestStreamTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameRequestStreamTests.cs @@ -4,7 +4,7 @@ using System; using System.IO; using System.Threading.Tasks; -using Microsoft.AspNetCore.Server.Kestrel.Http; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; using Xunit; namespace Microsoft.AspNetCore.Server.KestrelTests diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameResponseHeadersTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameResponseHeadersTests.cs index 3118a008f1..bfca1e9158 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameResponseHeadersTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameResponseHeadersTests.cs @@ -5,7 +5,7 @@ using System; using System.Collections.Generic; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Server.Kestrel; -using Microsoft.AspNetCore.Server.Kestrel.Http; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; using Microsoft.Extensions.Primitives; using Xunit; diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameResponseStreamTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameResponseStreamTests.cs index 556fc6701f..64590151bc 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameResponseStreamTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameResponseStreamTests.cs @@ -4,7 +4,7 @@ using System; using System.IO; using System.Threading.Tasks; -using Microsoft.AspNetCore.Server.Kestrel.Http; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; using Microsoft.AspNetCore.Server.KestrelTests.TestHelpers; using Xunit; diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs index 62ac9c5164..52c44bb2b4 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs @@ -2,14 +2,12 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.Linq; using System.Text; -using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Server.Kestrel; -using Microsoft.AspNetCore.Server.Kestrel.Exceptions; -using Microsoft.AspNetCore.Server.Kestrel.Http; -using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Internal; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.AspNetCore.Server.KestrelTests.TestHelpers; using Xunit; diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/HttpsConnectionFilterTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/HttpsConnectionFilterTests.cs index 0d5113ab5b..7946845290 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/HttpsConnectionFilterTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/HttpsConnectionFilterTests.cs @@ -16,7 +16,7 @@ using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Server.Kestrel.Filter; using Microsoft.AspNetCore.Server.Kestrel.Https; -using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.AspNetCore.Testing.xunit; using Xunit; @@ -32,10 +32,10 @@ namespace Microsoft.AspNetCore.Server.KestrelTests #if NET451 static HttpsConnectionFilterTests() { - // SecurityProtocolType values below not available in Mono < 4.3 + // SecurityProtocolType values below not available in Mono < 4.3 const int SecurityProtocolTypeTls11 = 768; const int SecurityProtocolTypeTls12 = 3072; - ServicePointManager.SecurityProtocol |= (SecurityProtocolType)(SecurityProtocolTypeTls12 | SecurityProtocolTypeTls11); + ServicePointManager.SecurityProtocol |= (SecurityProtocolType)(SecurityProtocolTypeTls12 | SecurityProtocolTypeTls11); } #endif diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerTests.cs index f83e6bcc0a..556d6f848e 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerTests.cs @@ -6,7 +6,7 @@ using Microsoft.AspNetCore.Hosting.Server; using Microsoft.AspNetCore.Hosting.Server.Features; using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Server.Kestrel; -using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Internal; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/LoggingThreadPoolTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/LoggingThreadPoolTests.cs index 92b8c2c94f..431e79b119 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/LoggingThreadPoolTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/LoggingThreadPoolTests.cs @@ -6,7 +6,7 @@ using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; -using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Xunit; namespace Microsoft.AspNetCore.Server.KestrelTests diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolBlockTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolBlockTests.cs index 0e86d2d7d6..a9c5652e4e 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolBlockTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolBlockTests.cs @@ -1,6 +1,6 @@ using System; using System.Linq; -using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using System.Numerics; using Xunit; diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolExtensions.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolExtensions.cs index e2cd3bdfa8..6348258ce9 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolExtensions.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolExtensions.cs @@ -1,4 +1,4 @@ -using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; namespace Microsoft.AspNetCore.Server.KestrelTests { diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolIteratorTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolIteratorTests.cs index 4e8a02c365..803cf52d61 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolIteratorTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolIteratorTests.cs @@ -1,6 +1,6 @@ using System; using System.Linq; -using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using System.Numerics; using Xunit; diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/MessageBodyTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/MessageBodyTests.cs index fafeaca0ed..f8dba124ef 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/MessageBodyTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/MessageBodyTests.cs @@ -4,7 +4,7 @@ using System; using System.Text; using System.Threading.Tasks; -using Microsoft.AspNetCore.Server.Kestrel.Http; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; using Xunit; namespace Microsoft.AspNetCore.Server.KestrelTests diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/MultipleLoopTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/MultipleLoopTests.cs index c5a6f0ee10..a57eb55f6b 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/MultipleLoopTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/MultipleLoopTests.cs @@ -6,8 +6,9 @@ using System.Net.Sockets; using System.Runtime.InteropServices; using System.Threading; using Microsoft.AspNetCore.Server.Kestrel; -using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; -using Microsoft.AspNetCore.Server.Kestrel.Networking; +using Microsoft.AspNetCore.Server.Kestrel.Internal; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; using Xunit; namespace Microsoft.AspNetCore.Server.KestrelTests diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/NetworkingTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/NetworkingTests.cs index e8d3f66fcd..aff4f2e212 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/NetworkingTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/NetworkingTests.cs @@ -7,8 +7,9 @@ using System.Net.Sockets; using System.Runtime.InteropServices; using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel; -using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; -using Microsoft.AspNetCore.Server.Kestrel.Networking; +using Microsoft.AspNetCore.Server.Kestrel.Internal; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; using Xunit; namespace Microsoft.AspNetCore.Server.KestrelTests diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/PathNormalizerTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/PathNormalizerTests.cs index d19eb63705..92c0b3f688 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/PathNormalizerTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/PathNormalizerTests.cs @@ -3,7 +3,7 @@ using System; using System.Text; -using Microsoft.AspNetCore.Server.Kestrel.Http; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; using Xunit; namespace Microsoft.AspNetCore.Server.KestrelTests diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/SocketInputTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/SocketInputTests.cs index 2a0d792051..15c7bc0c24 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/SocketInputTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/SocketInputTests.cs @@ -4,8 +4,9 @@ using System; using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel; -using Microsoft.AspNetCore.Server.Kestrel.Http; -using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Internal; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Xunit; namespace Microsoft.AspNetCore.Server.KestrelTests diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/SocketOutputTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/SocketOutputTests.cs index a398c5cb66..639d52741f 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/SocketOutputTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/SocketOutputTests.cs @@ -6,9 +6,10 @@ using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel; -using Microsoft.AspNetCore.Server.Kestrel.Http; -using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; -using Microsoft.AspNetCore.Server.Kestrel.Networking; +using Microsoft.AspNetCore.Server.Kestrel.Internal; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; using Microsoft.AspNetCore.Server.KestrelTests.TestHelpers; using Xunit; diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/StreamSocketOutputTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/StreamSocketOutputTests.cs index 46c0384f30..f01397fc0f 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/StreamSocketOutputTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/StreamSocketOutputTests.cs @@ -4,7 +4,8 @@ using System; using System.IO; using Microsoft.AspNetCore.Server.Kestrel.Filter; -using Microsoft.AspNetCore.Server.Kestrel.Http; +using Microsoft.AspNetCore.Server.Kestrel.Filter.Internal; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; using Xunit; namespace Microsoft.AspNetCore.Server.KestrelTests diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestConnection.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/TestConnection.cs index 30ec6f4879..7bae6b888b 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/TestConnection.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/TestConnection.cs @@ -8,7 +8,7 @@ using System.Net; using System.Net.Sockets; using System.Text; using System.Threading.Tasks; -using Microsoft.AspNetCore.Server.Kestrel.Networking; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; using Xunit; namespace Microsoft.AspNetCore.Server.KestrelTests diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockConnection.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockConnection.cs index 7181507494..efe612c47e 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockConnection.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockConnection.cs @@ -4,7 +4,7 @@ using System; using System.Threading; using System.Threading.Tasks; -using Microsoft.AspNetCore.Server.Kestrel.Http; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; namespace Microsoft.AspNetCore.Server.KestrelTests.TestHelpers { diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockFrameControl.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockFrameControl.cs index 0f5faf7148..1ec4ec728b 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockFrameControl.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockFrameControl.cs @@ -4,8 +4,8 @@ using System; using System.Threading; using System.Threading.Tasks; -using Microsoft.AspNetCore.Server.Kestrel.Http; -using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; namespace Microsoft.AspNetCore.Server.KestrelTests.TestHelpers { diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockLibuv.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockLibuv.cs index aa9c35523c..254ce726b2 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockLibuv.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockLibuv.cs @@ -1,6 +1,6 @@ using System; using System.Threading; -using Microsoft.AspNetCore.Server.Kestrel.Networking; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; namespace Microsoft.AspNetCore.Server.KestrelTests.TestHelpers { diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockSocket.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockSocket.cs index 4e41590dd9..7b398464d1 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockSocket.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockSocket.cs @@ -1,6 +1,6 @@ using System; -using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; -using Microsoft.AspNetCore.Server.Kestrel.Networking; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; namespace Microsoft.AspNetCore.Server.KestrelTests.TestHelpers { diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockSocketOuptut.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockSocketOuptut.cs index 8a516c4174..07af801aa7 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockSocketOuptut.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockSocketOuptut.cs @@ -4,8 +4,8 @@ using System; using System.Threading; using System.Threading.Tasks; -using Microsoft.AspNetCore.Server.Kestrel.Http; -using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; namespace Microsoft.AspNetCore.Server.KestrelTests.TestHelpers { diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockSystemClock.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockSystemClock.cs index 75c8951e60..d18e114f5c 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockSystemClock.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockSystemClock.cs @@ -2,7 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; namespace Microsoft.AspNetCore.Server.KestrelTests.TestHelpers { diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/PassThroughConnectionFilter.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/PassThroughConnectionFilter.cs index 2342536d3c..561609899a 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/PassThroughConnectionFilter.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/PassThroughConnectionFilter.cs @@ -3,7 +3,8 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Filter; -using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Filter.Internal; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; namespace Microsoft.AspNetCore.Server.KestrelTests { diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/TestApplicationErrorLogger.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/TestApplicationErrorLogger.cs index ea02bb3c64..2534de82da 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/TestApplicationErrorLogger.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/TestApplicationErrorLogger.cs @@ -3,6 +3,7 @@ using System; using Microsoft.AspNetCore.Server.Kestrel; +using Microsoft.AspNetCore.Server.Kestrel.Internal; using Microsoft.Extensions.Logging; namespace Microsoft.AspNetCore.Server.KestrelTests diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/TestKestrelTrace.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/TestKestrelTrace.cs index 5d811063b1..741ec54a0b 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/TestKestrelTrace.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/TestKestrelTrace.cs @@ -1,5 +1,4 @@ -using System; -using Microsoft.AspNetCore.Server.Kestrel; +using Microsoft.AspNetCore.Server.Kestrel.Internal; using Microsoft.Extensions.Logging; namespace Microsoft.AspNetCore.Server.KestrelTests diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestInput.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/TestInput.cs index 4c73c043b0..a868068b5c 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/TestInput.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/TestInput.cs @@ -5,8 +5,9 @@ using System; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel; -using Microsoft.AspNetCore.Server.Kestrel.Http; -using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Internal; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; namespace Microsoft.AspNetCore.Server.KestrelTests { diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestServer.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/TestServer.cs index 2a3deab41f..f4a840d967 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/TestServer.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/TestServer.cs @@ -4,7 +4,8 @@ using System; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Server.Kestrel; -using Microsoft.AspNetCore.Server.Kestrel.Http; +using Microsoft.AspNetCore.Server.Kestrel.Internal; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; namespace Microsoft.AspNetCore.Server.KestrelTests { diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestServiceContext.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/TestServiceContext.cs index 3c3cf36c77..10049f461c 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/TestServiceContext.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/TestServiceContext.cs @@ -5,8 +5,9 @@ using System; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Server.Kestrel; using Microsoft.AspNetCore.Server.Kestrel.Filter; -using Microsoft.AspNetCore.Server.Kestrel.Http; -using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Internal; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.AspNetCore.Server.KestrelTests.TestHelpers; namespace Microsoft.AspNetCore.Server.KestrelTests diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/UrlPathDecoder.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/UrlPathDecoder.cs index 31e1ccdbc9..c33c8e5168 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/UrlPathDecoder.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/UrlPathDecoder.cs @@ -3,8 +3,8 @@ using System; using System.Linq; -using Microsoft.AspNetCore.Server.Kestrel.Http; -using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Xunit; namespace Microsoft.AspNetCore.Server.KestrelTests diff --git a/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/FrameFeatureCollection.cs b/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/FrameFeatureCollection.cs index 2eb781cde6..950f06b730 100644 --- a/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/FrameFeatureCollection.cs +++ b/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/FrameFeatureCollection.cs @@ -66,7 +66,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.GeneratedCode using System; using System.Collections.Generic; -namespace Microsoft.AspNetCore.Server.Kestrel.Http +namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http {{ public partial class Frame {{{Each(allFeatures, feature => $@" diff --git a/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/KnownHeaders.cs b/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/KnownHeaders.cs index ca9073e9da..53dff0dd53 100644 --- a/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/KnownHeaders.cs +++ b/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/KnownHeaders.cs @@ -199,11 +199,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.GeneratedCode return $@" using System; using System.Collections.Generic; -using Microsoft.AspNetCore.Server.Kestrel.Exceptions; -using Microsoft.AspNetCore.Server.Kestrel.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.Extensions.Primitives; -namespace Microsoft.AspNetCore.Server.Kestrel.Http +namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http {{ {Each(loops, loop => $@" public partial class {loop.ClassName} From 17a41597a6e62829b33510c025c281cf3759f159 Mon Sep 17 00:00:00 2001 From: Pranav K Date: Fri, 3 Jun 2016 18:24:35 -0700 Subject: [PATCH 0778/1662] Reacting to Hosting changes --- .../HttpsConnectionFilter.cs | 2 +- src/Microsoft.AspNetCore.Server.Kestrel.Https/project.json | 2 +- .../Internal/Infrastructure/TaskUtilities.cs | 6 +++--- src/Microsoft.AspNetCore.Server.Kestrel/project.json | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Https/HttpsConnectionFilter.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Https/HttpsConnectionFilter.cs index f8efc1abbb..f553c825e5 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Https/HttpsConnectionFilter.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Https/HttpsConnectionFilter.cs @@ -115,7 +115,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Https return certificate2; } -#if NETSTANDARD1_3 +#if NETSTANDARD1_5 // conversion X509Certificate to X509Certificate2 not supported // https://github.com/dotnet/corefx/issues/4510 return null; diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Https/project.json b/src/Microsoft.AspNetCore.Server.Kestrel.Https/project.json index 3c74d74e93..9d4d5909a0 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Https/project.json +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Https/project.json @@ -23,7 +23,7 @@ }, "frameworks": { "net451": {}, - "netstandard1.3": { + "netstandard1.5": { "dependencies": { "System.Net.Security": "4.0.0-*" }, diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/TaskUtilities.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/TaskUtilities.cs index 139411bca0..4242379271 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/TaskUtilities.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/TaskUtilities.cs @@ -8,7 +8,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure { public static class TaskUtilities { -#if NETSTANDARD1_3 +#if NETSTANDARD1_5 public static Task CompletedTask = Task.CompletedTask; #else public static Task CompletedTask = Task.FromResult(null); @@ -17,7 +17,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure public static Task GetCancelledTask(CancellationToken cancellationToken) { -#if NETSTANDARD1_3 +#if NETSTANDARD1_5 return Task.FromCanceled(cancellationToken); #else var tcs = new TaskCompletionSource(); @@ -28,7 +28,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure public static Task GetCancelledZeroTask(CancellationToken cancellationToken = default(CancellationToken)) { -#if NETSTANDARD1_3 +#if NETSTANDARD1_5 // Make sure cancellationToken is cancelled before passing to Task.FromCanceled if (!cancellationToken.IsCancellationRequested) { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/project.json b/src/Microsoft.AspNetCore.Server.Kestrel/project.json index f6aeb0f17b..7c187970ee 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/project.json +++ b/src/Microsoft.AspNetCore.Server.Kestrel/project.json @@ -31,7 +31,7 @@ } } }, - "netstandard1.3": { + "netstandard1.5": { "dependencies": { "System.Collections": "4.0.11-*", "System.Diagnostics.Debug": "4.0.11-*", From 2bbaa52b08dbbd9cb926fefee8cd209b03c2a18a Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Fri, 3 Jun 2016 17:45:06 -0700 Subject: [PATCH 0779/1662] Disable ThreadCountTests on Mac. --- .../ThreadCountTests.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ThreadCountTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ThreadCountTests.cs index b185406de6..ebcf01b09a 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ThreadCountTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ThreadCountTests.cs @@ -7,14 +7,16 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Testing.xunit; using Xunit; namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { public class ThreadCountTests { - [Theory] + [ConditionalTheory] [MemberData(nameof(OneToTen))] + [OSSkipCondition(OperatingSystems.MacOSX, SkipReason = "Test failures pending investigation.")] public async Task OneToTenThreads(int threadCount) { var hostBuilder = new WebHostBuilder() From 69bd0dc4beed0ae8fffe09abc80189115155a795 Mon Sep 17 00:00:00 2001 From: moozzyk Date: Wed, 1 Jun 2016 14:19:17 -0700 Subject: [PATCH 0780/1662] Reject requests that have null characters in path --- .../Internal/Http/UrlPathDecoder.cs | 6 ++++ .../RequestTests.cs | 1 - .../BadHttpRequestTests.cs | 30 +++++++++++++++++++ .../EngineTests.cs | 28 +++++++++++++++++ 4 files changed, 64 insertions(+), 1 deletion(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/UrlPathDecoder.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/UrlPathDecoder.cs index 7ce0ce8990..5b639fe3c0 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/UrlPathDecoder.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/UrlPathDecoder.cs @@ -64,6 +64,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http // preserves the original head. if the percent-encodings cannot be interpreted as sequence of UTF-8 octets, // bytes from this till the last scanned one will be copied to the memory pointed by writer. var byte1 = UnescapePercentEncoding(ref reader, end); + + if (byte1 == 0) + { + throw new BadHttpRequestException("The path contains null characters."); + } + if (byte1 == -1) { return false; diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs index 6f4f3a2d45..e269fe21f0 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs @@ -138,7 +138,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { app.Run(async context => { - var connection = context.Connection; await context.Response.WriteAsync("hello, world"); }); }); diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/BadHttpRequestTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/BadHttpRequestTests.cs index 77a6db674f..b566c6e488 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/BadHttpRequestTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/BadHttpRequestTests.cs @@ -189,6 +189,36 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } } + [Theory] + [InlineData("\0")] + [InlineData("%00")] + [InlineData("/\0")] + [InlineData("/%00")] + [InlineData("/\0\0")] + [InlineData("/%00%00")] + [InlineData("/%C8\0")] + [InlineData("/%E8%00%84")] + [InlineData("/%E8%85%00")] + [InlineData("/%F3%00%82%86")] + [InlineData("/%F3%85%00%82")] + [InlineData("/%F3%85%82%00")] + [InlineData("/%E8%85%00")] + [InlineData("/%E8%01%00")] + public async Task BadRequestIfPathContainsNullCharacters(string path) + { + using (var server = new TestServer(context => { return Task.FromResult(0); })) + { + using (var connection = server.CreateConnection()) + { + await connection.SendEnd( + $"GET {path} HTTP/1.1", + "", + ""); + await ReceiveBadRequestResponse(connection); + } + } + } + private async Task ReceiveBadRequestResponse(TestConnection connection) { await connection.Receive( diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs index c2b1a7aa37..1c9eefb324 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs @@ -1170,5 +1170,33 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } } } + + [Theory] + [InlineData("/%%2000", "/% 00")] + [InlineData("/%25%30%30", "/%00")] + public async Task PathEscapeTests(string inputPath, string expectedPath) + { + using (var server = new TestServer(async httpContext => + { + var path = httpContext.Request.Path.Value; + httpContext.Response.Headers["Content-Length"] = new[] {path.Length.ToString() }; + await httpContext.Response.WriteAsync(path); + })) + { + using (var connection = server.CreateConnection()) + { + await connection.SendEnd( + $"GET {inputPath} HTTP/1.1", + "", + ""); + await connection.ReceiveEnd( + "HTTP/1.1 200 OK", + $"Date: {connection.Server.Context.DateHeaderValue}", + $"Content-Length: {expectedPath.Length.ToString()}", + "", + $"{expectedPath}"); + } + } + } } } From 50e8948bb985d7e299a1c0eb79bcd71e0b13d78a Mon Sep 17 00:00:00 2001 From: moozzyk Date: Mon, 6 Jun 2016 15:10:55 -0700 Subject: [PATCH 0781/1662] Fixing BadRequest tests to not try sending data after Bad Request --- .../BadHttpRequestTests.cs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/BadHttpRequestTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/BadHttpRequestTests.cs index b566c6e488..591fac9c22 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/BadHttpRequestTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/BadHttpRequestTests.cs @@ -210,10 +210,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { using (var connection = server.CreateConnection()) { - await connection.SendEnd( - $"GET {path} HTTP/1.1", - "", - ""); + await connection.SendEnd($"GET {path} HTTP/1.1\r\n"); await ReceiveBadRequestResponse(connection); } } From b6ceac559a9a91cb9ade554d6e6ff2f19bce8f08 Mon Sep 17 00:00:00 2001 From: jacalvar Date: Fri, 3 Jun 2016 13:08:21 -0700 Subject: [PATCH 0782/1662] Update Json.NET to 9.0.1-beta1 --- .../project.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json index d95ae5926c..ac30597ea2 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json @@ -7,7 +7,7 @@ "Microsoft.AspNetCore.Server.Kestrel": "1.0.0-*", "Microsoft.AspNetCore.Server.Kestrel.Https": "1.0.0-*", "Microsoft.AspNetCore.Testing": "1.0.0-*", - "Newtonsoft.Json": "8.0.3", + "Newtonsoft.Json": "9.0.1-beta1", "xunit": "2.1.0" }, "frameworks": { From badbc7c8f77f33212eaece76f5c3aa648bf54ce9 Mon Sep 17 00:00:00 2001 From: Mukul Sabharwal Date: Mon, 6 Jun 2016 21:37:44 -0700 Subject: [PATCH 0783/1662] Downtarget Kestrel to NETStandard 1.3 --- .../HttpsConnectionFilter.cs | 2 +- src/Microsoft.AspNetCore.Server.Kestrel.Https/project.json | 2 +- .../Internal/Infrastructure/TaskUtilities.cs | 6 +++--- src/Microsoft.AspNetCore.Server.Kestrel/project.json | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Https/HttpsConnectionFilter.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Https/HttpsConnectionFilter.cs index f553c825e5..f8efc1abbb 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Https/HttpsConnectionFilter.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Https/HttpsConnectionFilter.cs @@ -115,7 +115,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Https return certificate2; } -#if NETSTANDARD1_5 +#if NETSTANDARD1_3 // conversion X509Certificate to X509Certificate2 not supported // https://github.com/dotnet/corefx/issues/4510 return null; diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Https/project.json b/src/Microsoft.AspNetCore.Server.Kestrel.Https/project.json index 9d4d5909a0..3c74d74e93 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Https/project.json +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Https/project.json @@ -23,7 +23,7 @@ }, "frameworks": { "net451": {}, - "netstandard1.5": { + "netstandard1.3": { "dependencies": { "System.Net.Security": "4.0.0-*" }, diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/TaskUtilities.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/TaskUtilities.cs index 4242379271..139411bca0 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/TaskUtilities.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/TaskUtilities.cs @@ -8,7 +8,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure { public static class TaskUtilities { -#if NETSTANDARD1_5 +#if NETSTANDARD1_3 public static Task CompletedTask = Task.CompletedTask; #else public static Task CompletedTask = Task.FromResult(null); @@ -17,7 +17,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure public static Task GetCancelledTask(CancellationToken cancellationToken) { -#if NETSTANDARD1_5 +#if NETSTANDARD1_3 return Task.FromCanceled(cancellationToken); #else var tcs = new TaskCompletionSource(); @@ -28,7 +28,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure public static Task GetCancelledZeroTask(CancellationToken cancellationToken = default(CancellationToken)) { -#if NETSTANDARD1_5 +#if NETSTANDARD1_3 // Make sure cancellationToken is cancelled before passing to Task.FromCanceled if (!cancellationToken.IsCancellationRequested) { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/project.json b/src/Microsoft.AspNetCore.Server.Kestrel/project.json index 7c187970ee..f6aeb0f17b 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/project.json +++ b/src/Microsoft.AspNetCore.Server.Kestrel/project.json @@ -31,7 +31,7 @@ } } }, - "netstandard1.5": { + "netstandard1.3": { "dependencies": { "System.Collections": "4.0.11-*", "System.Diagnostics.Debug": "4.0.11-*", From c1dadbd7234ed4023adfaf8e1d859d8d6bf6d35e Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Mon, 6 Jun 2016 15:10:41 -0700 Subject: [PATCH 0784/1662] Make Bad Request tests more reliable - Avoid calling write again after the request is already rejected - Don't try to close a socket from the client if we already expect the server to forcefully close the socket --- .../BadHttpRequestTests.cs | 10 +++++----- .../ChunkedRequestTests.cs | 5 ++--- .../TestConnection.cs | 16 +++++++++++++--- 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/BadHttpRequestTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/BadHttpRequestTests.cs index 591fac9c22..1849541e23 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/BadHttpRequestTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/BadHttpRequestTests.cs @@ -93,7 +93,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { using (var connection = server.CreateConnection()) { - await connection.SendAllEnd(request); + await connection.SendAllTryEnd(request); await ReceiveBadRequestResponse(connection); } } @@ -130,7 +130,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { using (var connection = server.CreateConnection()) { - await connection.Send(request); + await connection.SendAll(request); await ReceiveBadRequestResponse(connection); } } @@ -166,7 +166,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { using (var connection = server.CreateConnection()) { - await connection.SendAllEnd($"GET / HTTP/1.1\r\n{rawHeaders}"); + await connection.SendAllTryEnd($"GET / HTTP/1.1\r\n{rawHeaders}"); await ReceiveBadRequestResponse(connection); } } @@ -179,7 +179,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { using (var connection = server.CreateConnection()) { - await connection.SendEnd( + await connection.SendAllTryEnd( "GET / HTTP/1.1", "H\u00eb\u00e4d\u00ebr: value", "", @@ -210,7 +210,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { using (var connection = server.CreateConnection()) { - await connection.SendEnd($"GET {path} HTTP/1.1\r\n"); + await connection.SendAllTryEnd($"GET {path} HTTP/1.1\r\n"); await ReceiveBadRequestResponse(connection); } } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedRequestTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedRequestTests.cs index 173912d594..e3ef2109df 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedRequestTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedRequestTests.cs @@ -7,7 +7,6 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Server.Kestrel; using Xunit; namespace Microsoft.AspNetCore.Server.KestrelTests @@ -365,7 +364,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { using (var connection = server.CreateConnection()) { - await connection.Send( + await connection.SendAll( "POST / HTTP/1.1", "Transfer-Encoding: chunked", "", @@ -407,7 +406,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { using (var connection = server.CreateConnection()) { - await connection.Send( + await connection.SendAll( "POST / HTTP/1.1", "Transfer-Encoding: chunked", "", diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestConnection.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/TestConnection.cs index 7bae6b888b..41ed1501f6 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/TestConnection.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/TestConnection.cs @@ -46,16 +46,26 @@ namespace Microsoft.AspNetCore.Server.KestrelTests public async Task SendAll(params string[] lines) { var text = String.Join("\r\n", lines); - var writer = new StreamWriter(_stream, Encoding.ASCII); + var writer = new StreamWriter(_stream, Encoding.GetEncoding("iso-8859-1")); await writer.WriteAsync(text); writer.Flush(); _stream.Flush(); } - public async Task SendAllEnd(params string[] lines) + public async Task SendAllTryEnd(params string[] lines) { await SendAll(lines); - _socket.Shutdown(SocketShutdown.Send); + + try + { + _socket.Shutdown(SocketShutdown.Send); + } + catch (IOException) + { + // The server may forcefully close the connection (usually due to a bad request), + // so an IOException: "An existing connection was forcibly closed by the remote host" + // isn't guaranteed but not unexpected. + } } public async Task Send(params string[] lines) From 8dbdc0294f598da636d08443fc07b66bf306cd95 Mon Sep 17 00:00:00 2001 From: jacalvar Date: Tue, 7 Jun 2016 22:09:34 -0700 Subject: [PATCH 0785/1662] Remove unncessary imports --- samples/LargeResponseApp/project.json | 5 +---- samples/SampleApp/project.json | 5 +---- src/Microsoft.AspNetCore.Server.Kestrel.Https/project.json | 5 +---- src/Microsoft.AspNetCore.Server.Kestrel/project.json | 5 +---- .../project.json | 5 +---- 5 files changed, 5 insertions(+), 20 deletions(-) diff --git a/samples/LargeResponseApp/project.json b/samples/LargeResponseApp/project.json index 4c284fa6ed..e32c20a66c 100644 --- a/samples/LargeResponseApp/project.json +++ b/samples/LargeResponseApp/project.json @@ -15,10 +15,7 @@ "version": "1.0.0-*", "type": "platform" } - }, - "imports": [ - "portable-dnxcore50+net45+win8+wp8+wpa81" - ] + } } }, "publishOptions": { diff --git a/samples/SampleApp/project.json b/samples/SampleApp/project.json index 1ee872316f..0058a88f97 100644 --- a/samples/SampleApp/project.json +++ b/samples/SampleApp/project.json @@ -18,10 +18,7 @@ "type": "platform" }, "System.Console": "4.0.0-*" - }, - "imports": [ - "dnxcore50" - ] + } } }, "publishOptions": { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Https/project.json b/src/Microsoft.AspNetCore.Server.Kestrel.Https/project.json index 3c74d74e93..14a8744538 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Https/project.json +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Https/project.json @@ -26,10 +26,7 @@ "netstandard1.3": { "dependencies": { "System.Net.Security": "4.0.0-*" - }, - "imports": [ - "portable-net45+win8" - ] + } } } } \ No newline at end of file diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/project.json b/src/Microsoft.AspNetCore.Server.Kestrel/project.json index f6aeb0f17b..ce435f46d7 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/project.json +++ b/src/Microsoft.AspNetCore.Server.Kestrel/project.json @@ -47,10 +47,7 @@ "System.Threading.Thread": "4.0.0-*", "System.Threading.ThreadPool": "4.0.10-*", "System.Threading.Timer": "4.0.1-*" - }, - "imports": [ - "portable-net45+win8" - ] + } } }, "buildOptions": { diff --git a/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/project.json b/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/project.json index 1682d3763a..e363e128ec 100644 --- a/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/project.json +++ b/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/project.json @@ -15,10 +15,7 @@ "version": "1.0.0-*", "type": "platform" } - }, - "imports": [ - "dnxcore50" - ] + } }, "net451": { "frameworkAssemblies": { From b4632c273edf15f627df18d964baf5f4479c8285 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Tue, 7 Jun 2016 17:07:14 -0700 Subject: [PATCH 0786/1662] Handle exceptions thrown from Connection.Start in ListenerSecondary - This is already done for primary listeners --- .../Internal/Http/ListenerSecondary.cs | 12 ++++++++++-- .../Internal/Http/PipeListener.cs | 1 - .../Internal/Http/PipeListenerPrimary.cs | 1 - .../Internal/Http/TcpListener.cs | 1 - .../Internal/Http/TcpListenerPrimary.cs | 2 -- 5 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ListenerSecondary.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ListenerSecondary.cs index 1a6ea958b4..e11729200f 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ListenerSecondary.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ListenerSecondary.cs @@ -138,8 +138,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http return; } - var connection = new Connection(this, acceptSocket); - connection.Start(); + try + { + var connection = new Connection(this, acceptSocket); + connection.Start(); + } + catch (UvException ex) + { + Log.LogError(0, ex, "ListenerSecondary.OnConnection"); + acceptSocket.Dispose(); + } } /// diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/PipeListener.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/PipeListener.cs index cb79dadd07..0b01438870 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/PipeListener.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/PipeListener.cs @@ -47,7 +47,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { Log.LogError(0, ex, "PipeListener.OnConnection"); acceptSocket.Dispose(); - return; } } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/PipeListenerPrimary.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/PipeListenerPrimary.cs index 65b9521f1f..3011a26616 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/PipeListenerPrimary.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/PipeListenerPrimary.cs @@ -47,7 +47,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { Log.LogError(0, ex, "ListenerPrimary.OnConnection"); acceptSocket.Dispose(); - return; } } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/TcpListener.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/TcpListener.cs index 353afad609..8f3b664105 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/TcpListener.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/TcpListener.cs @@ -53,7 +53,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { Log.LogError(0, ex, "TcpListener.OnConnection"); acceptSocket.Dispose(); - return; } } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/TcpListenerPrimary.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/TcpListenerPrimary.cs index dc47a375c5..b442deb42e 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/TcpListenerPrimary.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/TcpListenerPrimary.cs @@ -48,13 +48,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http acceptSocket.NoDelay(ServerOptions.NoDelay); listenSocket.Accept(acceptSocket); DispatchConnection(acceptSocket); - } catch (UvException ex) { Log.LogError(0, ex, "TcpListenerPrimary.OnConnection"); acceptSocket.Dispose(); - return; } } } From 917c3e0987ca3bf8cf0c7cac8f92349d429ee151 Mon Sep 17 00:00:00 2001 From: "N. Taylor Mullen" Date: Mon, 13 Jun 2016 15:29:13 -0700 Subject: [PATCH 0787/1662] Remove direct Microsoft.NETCore.Platforms dependency. - Microsoft.NETCore.App now pulls this package in. aspnet/Coherence-Signed#344 --- samples/LargeResponseApp/project.json | 1 - samples/SampleApp/project.json | 1 - .../project.json | 1 - test/Microsoft.AspNetCore.Server.KestrelTests/project.json | 1 - .../project.json | 1 - 5 files changed, 5 deletions(-) diff --git a/samples/LargeResponseApp/project.json b/samples/LargeResponseApp/project.json index e32c20a66c..b18eadc779 100644 --- a/samples/LargeResponseApp/project.json +++ b/samples/LargeResponseApp/project.json @@ -1,7 +1,6 @@ { "version": "1.0.0-*", "dependencies": { - "Microsoft.NETCore.Platforms": "1.0.1-*", "Microsoft.AspNetCore.Server.Kestrel": "1.0.0-*" }, "buildOptions": { diff --git a/samples/SampleApp/project.json b/samples/SampleApp/project.json index 0058a88f97..91b041cb63 100644 --- a/samples/SampleApp/project.json +++ b/samples/SampleApp/project.json @@ -1,7 +1,6 @@ { "version": "1.0.0-*", "dependencies": { - "Microsoft.NETCore.Platforms": "1.0.1-*", "Microsoft.AspNetCore.Server.Kestrel": "1.0.0-*", "Microsoft.AspNetCore.Server.Kestrel.Https": "1.0.0-*", "Microsoft.Extensions.Logging.Console": "1.0.0-*" diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json index ac30597ea2..4494310104 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json @@ -2,7 +2,6 @@ "version": "1.0.0-*", "dependencies": { "dotnet-test-xunit": "1.0.0-*", - "Microsoft.NETCore.Platforms": "1.0.1-*", "Microsoft.AspNetCore.Http.Abstractions": "1.0.0-*", "Microsoft.AspNetCore.Server.Kestrel": "1.0.0-*", "Microsoft.AspNetCore.Server.Kestrel.Https": "1.0.0-*", diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/project.json b/test/Microsoft.AspNetCore.Server.KestrelTests/project.json index 3f64d5ae48..2078e08390 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/project.json +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/project.json @@ -2,7 +2,6 @@ "version": "1.0.0-*", "dependencies": { "dotnet-test-xunit": "1.0.0-*", - "Microsoft.NETCore.Platforms": "1.0.1-*", "Microsoft.AspNetCore.Server.Kestrel": "1.0.0-*", "Microsoft.AspNetCore.Server.Kestrel.Https": "1.0.0-*", "Microsoft.AspNetCore.Testing": "1.0.0-*", diff --git a/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/project.json b/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/project.json index e363e128ec..51b52cf788 100644 --- a/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/project.json +++ b/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/project.json @@ -4,7 +4,6 @@ "emitEntryPoint": true }, "dependencies": { - "Microsoft.NETCore.Platforms": "1.0.1-*", "Microsoft.AspNetCore.Http.Features": "1.0.0-*", "Microsoft.AspNetCore.Hosting": "1.0.0-*" }, From 98feee9dbd87c69c87fb07f2b451abbbdec236db Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Mon, 13 Jun 2016 12:54:33 -0700 Subject: [PATCH 0788/1662] Combine LargeMultipartUpload and LargeUpload into one test. --- .../RequestTests.cs | 122 ++++++++---------- 1 file changed, 52 insertions(+), 70 deletions(-) diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs index e269fe21f0..487306a386 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs @@ -1,9 +1,11 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System; using System.Globalization; +using System.Net; using System.Net.Http; +using System.Net.Sockets; +using System.Text; using System.Threading.Tasks; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; @@ -17,9 +19,19 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { public class RequestTests { - [Fact] - public async Task LargeUpload() + [Theory] + [InlineData(10 * 1024 * 1024, true)] + // In the following dataset, send at least 2GB. + // Never change to a lower value, otherwise regression testing for + // https://github.com/aspnet/KestrelHttpServer/issues/520#issuecomment-188591242 + // will be lost. + [InlineData((long)int.MaxValue + 1, false)] + public void LargeUpload(long contentLength, bool checkBytes) { + const int bufferLength = 1024 * 1024; + Assert.True(contentLength % bufferLength == 0, $"{nameof(contentLength)} sent must be evenly divisible by {bufferLength}."); + Assert.True(bufferLength % 256 == 0, $"{nameof(bufferLength)} must be evenly divisible by 256"); + var builder = new WebHostBuilder() .UseKestrel() .UseUrls("http://127.0.0.1:0/") @@ -28,62 +40,22 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests app.Run(async context => { // Read the full request body - var total = 0; - var bytes = new byte[1024]; - var count = await context.Request.Body.ReadAsync(bytes, 0, bytes.Length); - while (count > 0) - { - for (int i = 0; i < count; i++) - { - Assert.Equal(total % 256, bytes[i]); - total++; - } - count = await context.Request.Body.ReadAsync(bytes, 0, bytes.Length); - } - - await context.Response.WriteAsync(total.ToString(CultureInfo.InvariantCulture)); - }); - }); - - using (var host = builder.Build()) - { - host.Start(); - - using (var client = new HttpClient()) - { - var bytes = new byte[1024 * 1024]; - for (int i = 0; i < bytes.Length; i++) - { - bytes[i] = (byte)i; - } - - var response = await client.PostAsync($"http://localhost:{host.GetPort()}/", new ByteArrayContent(bytes)); - response.EnsureSuccessStatusCode(); - var sizeString = await response.Content.ReadAsStringAsync(); - Assert.Equal(sizeString, bytes.Length.ToString(CultureInfo.InvariantCulture)); - } - } - } - - [ConditionalFact] - [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Fails on Mono on Mac because it is not 64-bit.")] - public async Task LargeMultipartUpload() - { - var builder = new WebHostBuilder() - .UseKestrel() - .UseUrls("http://127.0.0.1:0/") - .Configure(app => - { - app.Run(async context => - { long total = 0; - var bytes = new byte[1024]; - var count = await context.Request.Body.ReadAsync(bytes, 0, bytes.Length); - while (count > 0) + var receivedBytes = new byte[bufferLength]; + var received = 0; + while ((received = await context.Request.Body.ReadAsync(receivedBytes, 0, receivedBytes.Length)) > 0) { - total += count; - count = await context.Request.Body.ReadAsync(bytes, 0, bytes.Length); + if (checkBytes) + { + for (var i = 0; i < received; i++) + { + Assert.Equal((byte)((total + i) % 256), receivedBytes[i]); + } + } + + total += received; } + await context.Response.WriteAsync(total.ToString(CultureInfo.InvariantCulture)); }); }); @@ -92,25 +64,35 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { host.Start(); - using (var client = new HttpClient()) + using (var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)) { - using (var form = new MultipartFormDataContent()) + socket.Connect(new IPEndPoint(IPAddress.Loopback, host.GetPort())); + socket.Send(Encoding.ASCII.GetBytes($"POST / HTTP/1.0\r\nContent-Length: {contentLength}\r\n\r\n")); + + var contentBytes = new byte[bufferLength]; + + if (checkBytes) { - const int oneMegabyte = 1024 * 1024; - const int files = 2048; - var bytes = new byte[oneMegabyte]; - - for (int i = 0; i < files; i++) + for (var i = 0; i < contentBytes.Length; i++) { - var fileName = Guid.NewGuid().ToString(); - form.Add(new ByteArrayContent(bytes), "file", fileName); + contentBytes[i] = (byte)i; } - - var length = form.Headers.ContentLength.Value; - var response = await client.PostAsync($"http://localhost:{host.GetPort()}/", form); - response.EnsureSuccessStatusCode(); - Assert.Equal(length.ToString(CultureInfo.InvariantCulture), await response.Content.ReadAsStringAsync()); } + + for (var i = 0; i < contentLength / contentBytes.Length; i++) + { + socket.Send(contentBytes); + } + + var response = new StringBuilder(); + var responseBytes = new byte[4096]; + var received = 0; + while ((received = socket.Receive(responseBytes)) > 0) + { + response.Append(Encoding.ASCII.GetString(responseBytes, 0, received)); + } + + Assert.Contains(contentLength.ToString(CultureInfo.InvariantCulture), response.ToString()); } } } From 5ecb1f59a45f7f5af056f46e44d5d65d2db9a053 Mon Sep 17 00:00:00 2001 From: Mike Harder Date: Mon, 13 Jun 2016 18:52:20 -0700 Subject: [PATCH 0789/1662] Limit size of memory buffer when reading request (#304) - Added property `KestrelServerOptions.MaxRequestBufferSize` - Default is 1,048,576 bytes (1MB) - If value is null, the size of the request buffer is unlimited. - Fixed bug in `IConnectionControl.Resume()` where `_socket.ReadStart()` can throw if the socket is already disconnected. - Made `UvStreamHandle.ReadStop()` idempotent, to match `uv_read_stop()`. --- .../Filter/Internal/FilteredStreamAdapter.cs | 5 +- .../Internal/Http/BufferSizeControl.cs | 83 ++++++ .../Internal/Http/Connection.cs | 24 +- .../Internal/Http/IBufferSizeControl.cs | 13 + .../Internal/Http/SocketInput.cs | 21 +- .../Internal/Networking/UvStreamHandle.cs | 6 +- .../KestrelServerOptions.cs | 34 ++- .../IWebHostPortExtensions.cs | 21 +- .../MaxRequestBufferSizeTests.cs | 263 ++++++++++++++++++ .../TestResources/testCert.pfx | Bin 0 -> 2483 bytes .../project.json | 13 +- .../KestrelServerOptionsTests.cs | 27 ++ .../SocketInputTests.cs | 51 +++- .../UvStreamHandleTests.cs | 26 ++ .../project.json | 6 +- 15 files changed, 573 insertions(+), 20 deletions(-) create mode 100644 src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/BufferSizeControl.cs create mode 100644 src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/IBufferSizeControl.cs create mode 100644 test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/MaxRequestBufferSizeTests.cs create mode 100644 test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/TestResources/testCert.pfx create mode 100644 test/Microsoft.AspNetCore.Server.KestrelTests/UvStreamHandleTests.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Filter/Internal/FilteredStreamAdapter.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Filter/Internal/FilteredStreamAdapter.cs index bcd6b709e7..e17a988b45 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Filter/Internal/FilteredStreamAdapter.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Filter/Internal/FilteredStreamAdapter.cs @@ -24,9 +24,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Filter.Internal Stream filteredStream, MemoryPool memory, IKestrelTrace logger, - IThreadPool threadPool) + IThreadPool threadPool, + IBufferSizeControl bufferSizeControl) { - SocketInput = new SocketInput(memory, threadPool); + SocketInput = new SocketInput(memory, threadPool, bufferSizeControl); SocketOutput = new StreamSocketOutput(connectionId, filteredStream, memory, logger); _connectionId = connectionId; diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/BufferSizeControl.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/BufferSizeControl.cs new file mode 100644 index 0000000000..7fbec15ec2 --- /dev/null +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/BufferSizeControl.cs @@ -0,0 +1,83 @@ +using System.Diagnostics; + +namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http +{ + public class BufferSizeControl : IBufferSizeControl + { + private readonly long _maxSize; + private readonly IConnectionControl _connectionControl; + private readonly KestrelThread _connectionThread; + + private readonly object _lock = new object(); + + private long _size; + private bool _connectionPaused; + + public BufferSizeControl(long maxSize, IConnectionControl connectionControl, KestrelThread connectionThread) + { + _maxSize = maxSize; + _connectionControl = connectionControl; + _connectionThread = connectionThread; + } + + private long Size + { + get + { + return _size; + } + set + { + // Caller should ensure that bytes are never consumed before the producer has called Add() + Debug.Assert(value >= 0); + _size = value; + } + } + + public void Add(int count) + { + Debug.Assert(count >= 0); + + if (count == 0) + { + // No-op and avoid taking lock to reduce contention + return; + } + + lock (_lock) + { + Size += count; + if (!_connectionPaused && Size >= _maxSize) + { + _connectionPaused = true; + _connectionThread.Post( + (connectionControl) => ((IConnectionControl)connectionControl).Pause(), + _connectionControl); + } + } + } + + public void Subtract(int count) + { + Debug.Assert(count >= 0); + + if (count == 0) + { + // No-op and avoid taking lock to reduce contention + return; + } + + lock (_lock) + { + Size -= count; + if (_connectionPaused && Size < _maxSize) + { + _connectionPaused = false; + _connectionThread.Post( + (connectionControl) => ((IConnectionControl)connectionControl).Resume(), + _connectionControl); + } + } + } + } +} diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Connection.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Connection.cs index 6472543165..f3eeac1bdd 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Connection.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Connection.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Diagnostics; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Filter; @@ -41,6 +42,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http private ConnectionState _connectionState; private TaskCompletionSource _socketClosedTcs; + private BufferSizeControl _bufferSizeControl; + public Connection(ListenerContext context, UvStreamHandle socket) : base(context) { _socket = socket; @@ -49,7 +52,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http ConnectionId = GenerateConnectionId(Interlocked.Increment(ref _lastConnectionId)); - _rawSocketInput = new SocketInput(Memory, ThreadPool); + if (ServerOptions.MaxRequestBufferSize.HasValue) + { + _bufferSizeControl = new BufferSizeControl(ServerOptions.MaxRequestBufferSize.Value, this, Thread); + } + + _rawSocketInput = new SocketInput(Memory, ThreadPool, _bufferSizeControl); _rawSocketOutput = new SocketOutput(Thread, _socket, Memory, this, ConnectionId, Log, ThreadPool, WriteReqPool); } @@ -217,7 +225,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if (_filterContext.Connection != _libuvStream) { - _filteredStreamAdapter = new FilteredStreamAdapter(ConnectionId, _filterContext.Connection, Memory, Log, ThreadPool); + _filteredStreamAdapter = new FilteredStreamAdapter(ConnectionId, _filterContext.Connection, Memory, Log, ThreadPool, _bufferSizeControl); SocketInput = _filteredStreamAdapter.SocketInput; SocketOutput = _filteredStreamAdapter.SocketOutput; @@ -316,7 +324,17 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http void IConnectionControl.Resume() { Log.ConnectionResume(ConnectionId); - _socket.ReadStart(_allocCallback, _readCallback, this); + try + { + _socket.ReadStart(_allocCallback, _readCallback, this); + } + catch (UvException) + { + // ReadStart() can throw a UvException in some cases (e.g. socket is no longer connected). + // This should be treated the same as OnRead() seeing a "normalDone" condition. + Log.ConnectionReadFin(ConnectionId); + _rawSocketInput.IncomingComplete(0, null); + } } void IConnectionControl.End(ProduceEndType endType) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/IBufferSizeControl.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/IBufferSizeControl.cs new file mode 100644 index 0000000000..3d05cfe4f0 --- /dev/null +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/IBufferSizeControl.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http +{ + public interface IBufferSizeControl + { + void Add(int count); + void Subtract(int count); + } +} diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/SocketInput.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/SocketInput.cs index 3082edf708..e093df9c8a 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/SocketInput.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/SocketInput.cs @@ -18,6 +18,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http private readonly MemoryPool _memory; private readonly IThreadPool _threadPool; + private readonly IBufferSizeControl _bufferSizeControl; private readonly ManualResetEventSlim _manualResetEvent = new ManualResetEventSlim(false, 0); private Action _awaitableState; @@ -32,10 +33,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http private bool _consuming; private bool _disposed; - public SocketInput(MemoryPool memory, IThreadPool threadPool) + public SocketInput(MemoryPool memory, IThreadPool threadPool, IBufferSizeControl bufferSizeControl = null) { _memory = memory; _threadPool = threadPool; + _bufferSizeControl = bufferSizeControl; _awaitableState = _awaitableIsNotCompleted; } @@ -63,6 +65,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { lock (_sync) { + // Must call Add() before bytes are available to consumer, to ensure that Length is >= 0 + _bufferSizeControl?.Add(count); + if (count > 0) { if (_tail == null) @@ -93,6 +98,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { lock (_sync) { + // Must call Add() before bytes are available to consumer, to ensure that Length is >= 0 + _bufferSizeControl?.Add(count); + if (_pinned != null) { _pinned.End += count; @@ -189,10 +197,21 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { if (!consumed.IsDefault) { + // Compute lengthConsumed before modifying _head or consumed + var lengthConsumed = 0; + if (_bufferSizeControl != null) + { + lengthConsumed = new MemoryPoolIterator(_head).GetLength(consumed); + } + returnStart = _head; returnEnd = consumed.Block; _head = consumed.Block; _head.Start = consumed.Index; + + // Must call Subtract() after _head has been advanced, to avoid producer starting too early and growing + // buffer beyond max length. + _bufferSizeControl?.Subtract(lengthConsumed); } if (!examined.IsDefault && diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/UvStreamHandle.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/UvStreamHandle.cs index bc0bbc64a9..1a930f604d 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/UvStreamHandle.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/UvStreamHandle.cs @@ -105,16 +105,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking } } + // UvStreamHandle.ReadStop() should be idempotent to match uv_read_stop() public void ReadStop() { - if (!_readVitality.IsAllocated) + if (_readVitality.IsAllocated) { - throw new InvalidOperationException("TODO: ReadStart must be called before ReadStop may be called"); + _readVitality.Free(); } _allocCallback = null; _readCallback = null; _readState = null; - _readVitality.Free(); _uv.read_stop(this); } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServerOptions.cs b/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServerOptions.cs index 7a6c7953e7..3591408bbb 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServerOptions.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServerOptions.cs @@ -8,17 +8,41 @@ namespace Microsoft.AspNetCore.Server.Kestrel { public class KestrelServerOptions { - public IServiceProvider ApplicationServices { get; set; } - - public IConnectionFilter ConnectionFilter { get; set; } - - public bool NoDelay { get; set; } = true; + // Matches the default client_max_body_size in nginx. Also large enough that most requests + // should be under the limit. + private long? _maxRequestBufferSize = 1024 * 1024; /// /// Gets or sets whether the Server header should be included in each response. /// public bool AddServerHeader { get; set; } = true; + public IServiceProvider ApplicationServices { get; set; } + + public IConnectionFilter ConnectionFilter { get; set; } + + /// + /// Maximum size of the request buffer. Default is 1,048,576 bytes (1 MB). + /// If value is null, the size of the request buffer is unlimited. + /// + public long? MaxRequestBufferSize + { + get + { + return _maxRequestBufferSize; + } + set + { + if (value.HasValue && value.Value <= 0) + { + throw new ArgumentOutOfRangeException("value", "Value must be null or a positive integer."); + } + _maxRequestBufferSize = value; + } + } + + public bool NoDelay { get; set; } = true; + /// /// The amount of time after the server begins shutting down before connections will be forcefully closed. /// By default, Kestrel will wait 5 seconds for any ongoing requests to complete before terminating diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/IWebHostPortExtensions.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/IWebHostPortExtensions.cs index 9b3509503e..625a10a7af 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/IWebHostPortExtensions.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/IWebHostPortExtensions.cs @@ -10,16 +10,35 @@ namespace Microsoft.AspNetCore.Hosting { public static class IWebHostPortExtensions { + public static string GetHost(this IWebHost host) + { + return host.GetUris().First().Host; + } + public static int GetPort(this IWebHost host) { return host.GetPorts().First(); } + public static int GetPort(this IWebHost host, string scheme) + { + return host.GetUris() + .Where(u => u.Scheme.Equals(scheme, StringComparison.OrdinalIgnoreCase)) + .Select(u => u.Port) + .First(); + } + public static IEnumerable GetPorts(this IWebHost host) + { + return host.GetUris() + .Select(u => u.Port); + } + + public static IEnumerable GetUris(this IWebHost host) { return host.ServerFeatures.Get().Addresses .Select(a => a.Replace("://+", "://localhost")) - .Select(a => (new Uri(a)).Port); + .Select(a => new Uri(a)); } } } diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/MaxRequestBufferSizeTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/MaxRequestBufferSizeTests.cs new file mode 100644 index 0000000000..70bbf876f8 --- /dev/null +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/MaxRequestBufferSizeTests.cs @@ -0,0 +1,263 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Net; +using System.Net.Security; +using System.Net.Sockets; +using System.Security.Authentication; +using System.Text; +using System.Threading; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Http; +using Xunit; + +namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests +{ + public class MaxRequestBufferSizeTests + { + private const int _dataLength = 20 * 1024 * 1024; + + public static IEnumerable LargeUploadData + { + get + { + var maxRequestBufferSizeValues = new Tuple[] { + // Smallest allowed buffer. Server should call pause/resume between each read. + Tuple.Create((long?)1, true), + + // Small buffer, but large enough to hold all request headers. + Tuple.Create((long?)16 * 1024, true), + + // Default buffer. + Tuple.Create((long?)1024 * 1024, true), + + // Larger than default, but still significantly lower than data, so client should be paused. + // On Windows, the client is usually paused around (MaxRequestBufferSize + 700,000). + // On Linux, the client is usually paused around (MaxRequestBufferSize + 10,000,000). + Tuple.Create((long?)5 * 1024 * 1024, true), + + // Even though maxRequestBufferSize < _dataLength, client should not be paused since the + // OS-level buffers in client and/or server will handle the overflow. + Tuple.Create((long?)_dataLength - 1, false), + + // Buffer is exactly the same size as data. Exposed race condition where + // IConnectionControl.Resume() was called after socket was disconnected. + Tuple.Create((long?)_dataLength, false), + + // Largest possible buffer, should never trigger backpressure. + Tuple.Create((long?)long.MaxValue, false), + + // Disables all code related to computing and limiting the size of the input buffer. + Tuple.Create((long?)null, false) + }; + var sendContentLengthHeaderValues = new[] { true, false }; + var sslValues = new[] { true, false }; + + return from maxRequestBufferSize in maxRequestBufferSizeValues + from sendContentLengthHeader in sendContentLengthHeaderValues + from ssl in sslValues + select new object[] { + maxRequestBufferSize.Item1, + sendContentLengthHeader, + ssl, + maxRequestBufferSize.Item2 + }; + } + } + + [Theory] + [MemberData("LargeUploadData")] + public async Task LargeUpload(long? maxRequestBufferSize, bool sendContentLengthHeader, bool ssl, bool expectPause) + { + // Parameters + var data = new byte[_dataLength]; + var bytesWrittenTimeout = TimeSpan.FromMilliseconds(100); + var bytesWrittenPollingInterval = TimeSpan.FromMilliseconds(bytesWrittenTimeout.TotalMilliseconds / 10); + var maxSendSize = 4096; + + // Initialize data with random bytes + (new Random()).NextBytes(data); + + var startReadingRequestBody = new ManualResetEvent(false); + var clientFinishedSendingRequestBody = new ManualResetEvent(false); + var lastBytesWritten = DateTime.MaxValue; + + using (var host = StartWebHost(maxRequestBufferSize, data, startReadingRequestBody, clientFinishedSendingRequestBody)) + { + var port = host.GetPort(ssl ? "https" : "http"); + using (var socket = CreateSocket(port)) + using (var stream = await CreateStreamAsync(socket, ssl, host.GetHost())) + { + await WritePostRequestHeaders(stream, sendContentLengthHeader ? (int?)data.Length : null); + + var bytesWritten = 0; + + Func sendFunc = async () => + { + while (bytesWritten < data.Length) + { + var size = Math.Min(data.Length - bytesWritten, maxSendSize); + await stream.WriteAsync(data, bytesWritten, size); + bytesWritten += size; + lastBytesWritten = DateTime.Now; + } + + Assert.Equal(data.Length, bytesWritten); + socket.Shutdown(SocketShutdown.Send); + clientFinishedSendingRequestBody.Set(); + }; + + var sendTask = sendFunc(); + + if (expectPause) + { + // The minimum is (maxRequestBufferSize - maxSendSize + 1), since if bytesWritten is + // (maxRequestBufferSize - maxSendSize) or smaller, the client should be able to + // complete another send. + var minimumExpectedBytesWritten = maxRequestBufferSize.Value - maxSendSize + 1; + + // The maximum is harder to determine, since there can be OS-level buffers in both the client + // and server, which allow the client to send more than maxRequestBufferSize before getting + // paused. We assume the combined buffers are smaller than the difference between + // data.Length and maxRequestBufferSize. + var maximumExpectedBytesWritten = data.Length - 1; + + // Block until the send task has gone a while without writing bytes AND + // the bytes written exceeds the minimum expected. This indicates the server buffer + // is full. + // + // If the send task is paused before the expected number of bytes have been + // written, keep waiting since the pause may have been caused by something else + // like a slow machine. + while ((DateTime.Now - lastBytesWritten) < bytesWrittenTimeout || + bytesWritten < minimumExpectedBytesWritten) + { + await Task.Delay(bytesWrittenPollingInterval); + } + + // Verify the number of bytes written before the client was paused. + Assert.InRange(bytesWritten, minimumExpectedBytesWritten, maximumExpectedBytesWritten); + + // Tell server to start reading request body + startReadingRequestBody.Set(); + + // Wait for sendTask to finish sending the remaining bytes + await sendTask; + } + else + { + // Ensure all bytes can be sent before the server starts reading + await sendTask; + + // Tell server to start reading request body + startReadingRequestBody.Set(); + } + + using (var reader = new StreamReader(stream, Encoding.ASCII)) + { + var response = reader.ReadToEnd(); + Assert.Contains($"bytesRead: {data.Length}", response); + } + } + } + } + + private static IWebHost StartWebHost(long? maxRequestBufferSize, byte[] expectedBody, ManualResetEvent startReadingRequestBody, + ManualResetEvent clientFinishedSendingRequestBody) + { + var host = new WebHostBuilder() + .UseKestrel(options => + { + options.MaxRequestBufferSize = maxRequestBufferSize; + options.UseHttps(@"TestResources/testCert.pfx", "testPassword"); + }) + .UseUrls("http://127.0.0.1:0/", "https://127.0.0.1:0/") + .UseContentRoot(Directory.GetCurrentDirectory()) + .Configure(app => app.Run(async context => + { + startReadingRequestBody.WaitOne(); + + var buffer = new byte[expectedBody.Length]; + var bytesRead = 0; + while (bytesRead < buffer.Length) + { + bytesRead += await context.Request.Body.ReadAsync(buffer, bytesRead, buffer.Length - bytesRead); + } + + clientFinishedSendingRequestBody.WaitOne(); + + // Verify client didn't send extra bytes + if (context.Request.Body.ReadByte() != -1) + { + context.Response.StatusCode = 500; + await context.Response.WriteAsync("Client sent more bytes than expectedBody.Length"); + return; + } + + // Verify bytes received match expectedBody + for (int i = 0; i < expectedBody.Length; i++) + { + if (buffer[i] != expectedBody[i]) + { + context.Response.StatusCode = 500; + await context.Response.WriteAsync($"Bytes received do not match expectedBody at position {i}"); + return; + } + } + + await context.Response.WriteAsync($"bytesRead: {bytesRead.ToString()}"); + })) + .Build(); + + host.Start(); + + return host; + } + + private static Socket CreateSocket(int port) + { + var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); + + // Timeouts large enough to prevent false positives, but small enough to fail quickly. + socket.SendTimeout = 10 * 1000; + socket.ReceiveTimeout = 10 * 1000; + + socket.Connect(IPAddress.Loopback, port); + + return socket; + } + + private static async Task WritePostRequestHeaders(Stream stream, int? contentLength) + { + using (var writer = new StreamWriter(stream, Encoding.ASCII, bufferSize: 1024, leaveOpen: true)) + { + await writer.WriteAsync("POST / HTTP/1.0\r\n"); + if (contentLength.HasValue) + { + await writer.WriteAsync($"Content-Length: {contentLength.Value}\r\n"); + } + await writer.WriteAsync("\r\n"); + } + } + + private static async Task CreateStreamAsync(Socket socket, bool ssl, string targetHost) + { + var networkStream = new NetworkStream(socket); + if (ssl) + { + var sslStream = new SslStream(networkStream, leaveInnerStreamOpen: false, + userCertificateValidationCallback: (a, b, c, d) => true); + await sslStream.AuthenticateAsClientAsync(targetHost, clientCertificates: null, + enabledSslProtocols: SslProtocols.Tls11 | SslProtocols.Tls12, checkCertificateRevocation: false); + return sslStream; + } + else + { + return networkStream; + } + } + } +} diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/TestResources/testCert.pfx b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/TestResources/testCert.pfx new file mode 100644 index 0000000000000000000000000000000000000000..7118908c2d730670c16e9f8b2c532a262c951989 GIT binary patch literal 2483 zcmaKuc|27A8pqF>IWr86E&Q@(n=B)p$ug!;QVB6xij*z;uPLG!yCz#DQB)+9G$9m9 zQU)=DWXU?*EZIwG!+0d++P@yZ4Xhoagg?p6B~|Ue7tN=Ny=UD?x#1n1MTq z#c9MHh+D#gd|(a(cN}8i91v^=GcdgW3SmA$49p~gM-dys3jVWdg8+!iVL)pz1LDE5 zSb=|GAn(@R=(Ux!MfS9@}sFu-xDd zIt2+mqSq$glwy_6UNs<2?(qERU!gJ;5j}Pp&6trxG=wi)=@k(w2+fJVnc+qvXVzy(>Om4;L|^)R`t*3nTpAmEmTl(#i!RV#a0t#u6>Q9mY`-Nmcs7$XjXT7 zUmCD`O~_j7!%R#I?cG-7C^hcH)@l?WC1vyw$FFu_(r)jhOq6p}W8sG7NO{YTy8tG4 zrb$tTkag*G?(7lfoGx$4YWui>{{@}-FB2ub=}RX{1zx?j)s-##J9|G7E1@-;7Nuln z9MQoX7FJ76+D#XXT@ZZmLZCufIdf3@OigG6m8I7!GT=7VD|>?6e!z9=eT}*E_tSn6 zl+clHCZ-kcIR#gen#LjMJW8>0QtViaQB#FhqsCb0YPYr3;jRITl@V9Aph24D?r2d` zetCyyCg<*O-u+M& zW^ptmT|}p$VAOZpmbQ1{5fK-6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Y?-V&VquSN%3FJ2~ZGweP~iLs|w=l@9yu$tj@}Dp?e-2JUsqOoswdXb=E%&0te_ zA2M+{5Hf-dqD7=yw*r@A*xkn(1IS~nfP}k}e?4Bt|9g(eph4hFX_|S6nj1&Sz9z^= zRw~<&-9d@FzTn6S*RVE{Wj5lgLJr9HLB8S9CgOm*>XA8*y4`JE;^s$=bqD#U4;e5C&x&ggKIAVL zrQ)Yd8|{>7Z(6*B&7&4&9(*vDOfHMuR-Dk1IZia*XM^EZUD^{?cWG>J>KrtElc*{K zaVl(7SN2cH4I6Q$bZOpJ8e5LKaG7p;?tJ~#+9QrTYU@f#5`Vo7cEX!szCT}iX-K^2 w#3o+=C+lQz2J+SOEzVX(eJ)e7=eicC{rr9U2VGDcdH?_b literal 0 HcmV?d00001 diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json index 4494310104..51a86e1a76 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json @@ -6,6 +6,7 @@ "Microsoft.AspNetCore.Server.Kestrel": "1.0.0-*", "Microsoft.AspNetCore.Server.Kestrel.Https": "1.0.0-*", "Microsoft.AspNetCore.Testing": "1.0.0-*", + "Microsoft.Extensions.Logging.Console": "1.0.0-*", "Newtonsoft.Json": "9.0.1-beta1", "xunit": "2.1.0" }, @@ -36,7 +37,15 @@ } }, "buildOptions": { - "allowUnsafe": true + "allowUnsafe": true, + "copyToOutput": { + "include": "TestResources/testCert.pfx" + } }, - "testRunner": "xunit" + "testRunner": "xunit", + "publishOptions": { + "include": [ + "TestResources/testCert.pfx" + ] + } } \ No newline at end of file diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerOptionsTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerOptionsTests.cs index ff03086b71..9b05072c27 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerOptionsTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerOptionsTests.cs @@ -11,6 +11,33 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { public class KestrelServerInformationTests { + [Fact] + public void MaxRequestBufferSizeDefault() + { + Assert.Equal(1024 * 1024, (new KestrelServerOptions()).MaxRequestBufferSize); + } + + [Theory] + [InlineData(-1)] + [InlineData(0)] + public void MaxRequestBufferSizeInvalid(int value) + { + Assert.Throws(() => + { + (new KestrelServerOptions()).MaxRequestBufferSize = value; + }); + } + + [Theory] + [InlineData(null)] + [InlineData(1)] + public void MaxRequestBufferSizeValid(int? value) + { + var o = new KestrelServerOptions(); + o.MaxRequestBufferSize = value; + Assert.Equal(value, o.MaxRequestBufferSize); + } + [Fact] public void SetThreadCountUsingProcessorCount() { diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/SocketInputTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/SocketInputTests.cs index 15c7bc0c24..ecef0c1538 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/SocketInputTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/SocketInputTests.cs @@ -3,16 +3,65 @@ using System; using System.Threading.Tasks; -using Microsoft.AspNetCore.Server.Kestrel; using Microsoft.AspNetCore.Server.Kestrel.Internal; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; +using Microsoft.AspNetCore.Server.KestrelTests.TestHelpers; +using Moq; using Xunit; namespace Microsoft.AspNetCore.Server.KestrelTests { public class SocketInputTests { + public static readonly TheoryData> MockBufferSizeControlData = + new TheoryData>() { new Mock(), null }; + + [Theory] + [MemberData("MockBufferSizeControlData")] + public void IncomingDataCallsBufferSizeControlAdd(Mock mockBufferSizeControl) + { + using (var memory = new MemoryPool()) + using (var socketInput = new SocketInput(memory, null, mockBufferSizeControl?.Object)) + { + socketInput.IncomingData(new byte[5], 0, 5); + mockBufferSizeControl?.Verify(b => b.Add(5)); + } + } + + [Theory] + [MemberData("MockBufferSizeControlData")] + public void IncomingCompleteCallsBufferSizeControlAdd(Mock mockBufferSizeControl) + { + using (var memory = new MemoryPool()) + using (var socketInput = new SocketInput(memory, null, mockBufferSizeControl?.Object)) + { + socketInput.IncomingComplete(5, null); + mockBufferSizeControl?.Verify(b => b.Add(5)); + } + } + + [Theory] + [MemberData("MockBufferSizeControlData")] + public void ConsumingCompleteCallsBufferSizeControlSubtract(Mock mockBufferSizeControl) + { + using (var kestrelEngine = new KestrelEngine(new MockLibuv(), new TestServiceContext())) + { + kestrelEngine.Start(1); + + using (var memory = new MemoryPool()) + using (var socketInput = new SocketInput(memory, null, mockBufferSizeControl?.Object)) + { + socketInput.IncomingData(new byte[20], 0, 20); + + var iterator = socketInput.ConsumingStart(); + iterator.Skip(5); + socketInput.ConsumingComplete(iterator, iterator); + mockBufferSizeControl?.Verify(b => b.Subtract(5)); + } + } + } + [Fact] public async Task ConcurrentReadsFailGracefully() { diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/UvStreamHandleTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/UvStreamHandleTests.cs new file mode 100644 index 0000000000..51dbce5b5d --- /dev/null +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/UvStreamHandleTests.cs @@ -0,0 +1,26 @@ +using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; +using Microsoft.AspNetCore.Server.KestrelTests.TestHelpers; +using Moq; +using Xunit; + +namespace Microsoft.AspNetCore.Server.KestrelTests +{ + public class UvStreamHandleTests + { + [Fact] + public void ReadStopIsIdempotent() + { + var mockKestrelTrace = Mock.Of(); + var mockUvLoopHandle = new Mock(mockKestrelTrace).Object; + mockUvLoopHandle.Init(new MockLibuv()); + + // Need to mock UvTcpHandle instead of UvStreamHandle, since the latter lacks an Init() method + var mockUvStreamHandle = new Mock(mockKestrelTrace).Object; + mockUvStreamHandle.Init(mockUvLoopHandle, null); + + mockUvStreamHandle.ReadStop(); + mockUvStreamHandle.ReadStop(); + } + } +} diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/project.json b/test/Microsoft.AspNetCore.Server.KestrelTests/project.json index 2078e08390..89561cace8 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/project.json +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/project.json @@ -20,7 +20,8 @@ "System.Net.Http": "4.1.0-*", "System.Net.Http.WinHttpHandler": "4.0.0-*", "System.Net.Sockets": "4.1.0-*", - "System.Runtime.Handles": "4.0.1-*" + "System.Runtime.Handles": "4.0.1-*", + "moq.netcore": "4.4.0-beta8" }, "imports": [ "dnxcore50", @@ -29,7 +30,8 @@ }, "net451": { "dependencies": { - "xunit.runner.console": "2.1.0" + "xunit.runner.console": "2.1.0", + "Moq": "4.2.1312.1622" }, "frameworkAssemblies": { "System.Net.Http": "4.0.0.0" From 01e9101543906ffd39239efd2f7bb41dbd879902 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Mon, 13 Jun 2016 15:23:38 -0700 Subject: [PATCH 0790/1662] Add more doc comments to KestrelServerOptions --- .../KestrelServerOptions.cs | 43 +++++++++++++++++-- 1 file changed, 40 insertions(+), 3 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServerOptions.cs b/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServerOptions.cs index 3591408bbb..6ae42f48a8 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServerOptions.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServerOptions.cs @@ -6,6 +6,9 @@ using Microsoft.AspNetCore.Server.Kestrel.Filter; namespace Microsoft.AspNetCore.Server.Kestrel { + /// + /// Provides programmatic configuration of Kestrel-specific features. + /// public class KestrelServerOptions { // Matches the default client_max_body_size in nginx. Also large enough that most requests @@ -15,16 +18,35 @@ namespace Microsoft.AspNetCore.Server.Kestrel /// /// Gets or sets whether the Server header should be included in each response. /// + /// + /// Defaults to true. + /// public bool AddServerHeader { get; set; } = true; + /// + /// Enables the UseKestrel options callback to resolve and use services registered by the application during startup. + /// Typically initialized by . + /// public IServiceProvider ApplicationServices { get; set; } + /// + /// Gets or sets an that allows each connection + /// to be intercepted and transformed. + /// Configured by the UseHttps() and + /// extension methods. + /// + /// + /// Defaults to null. + /// public IConnectionFilter ConnectionFilter { get; set; } /// - /// Maximum size of the request buffer. Default is 1,048,576 bytes (1 MB). + /// Maximum size of the request buffer. /// If value is null, the size of the request buffer is unlimited. /// + /// + /// Defaults to 1,048,576 bytes (1 MB). + /// public long? MaxRequestBufferSize { get @@ -41,15 +63,30 @@ namespace Microsoft.AspNetCore.Server.Kestrel } } + /// + /// Set to false to enable Nagle's algorithm for all connections. + /// + /// + /// Defaults to true. + /// public bool NoDelay { get; set; } = true; /// /// The amount of time after the server begins shutting down before connections will be forcefully closed. - /// By default, Kestrel will wait 5 seconds for any ongoing requests to complete before terminating - /// the connection. + /// Kestrel will wait for the duration of the timeout for any ongoing request processing to complete before + /// terminating the connection. No new connections or requests will be accepted during this time. /// + /// + /// Defaults to 5 seconds. + /// public TimeSpan ShutdownTimeout { get; set; } = TimeSpan.FromSeconds(5); + /// + /// The number of libuv I/O threads used to process requests. + /// + /// + /// Defaults to half of rounded down and clamped between 1 and 16. + /// public int ThreadCount { get; set; } = ProcessorThreadCount; private static int ProcessorThreadCount From de53e7566e49f0a628048dcf201a95eda23b5502 Mon Sep 17 00:00:00 2001 From: Pranav K Date: Tue, 14 Jun 2016 16:22:44 -0700 Subject: [PATCH 0791/1662] Updating to release. --- NuGet.config | 4 ++-- build.ps1 | 2 +- build.sh | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/NuGet.config b/NuGet.config index 03704957e8..9db87a421e 100644 --- a/NuGet.config +++ b/NuGet.config @@ -1,7 +1,7 @@ - + - + \ No newline at end of file diff --git a/build.ps1 b/build.ps1 index 8f2f99691a..cf8bff13bb 100644 --- a/build.ps1 +++ b/build.ps1 @@ -33,7 +33,7 @@ cd $PSScriptRoot $repoFolder = $PSScriptRoot $env:REPO_FOLDER = $repoFolder -$koreBuildZip="https://github.com/aspnet/KoreBuild/archive/dev.zip" +$koreBuildZip="https://github.com/aspnet/KoreBuild/archive/release.zip" if ($env:KOREBUILD_ZIP) { $koreBuildZip=$env:KOREBUILD_ZIP diff --git a/build.sh b/build.sh index f4208100eb..f88fe4052e 100755 --- a/build.sh +++ b/build.sh @@ -2,7 +2,7 @@ repoFolder="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" cd $repoFolder -koreBuildZip="https://github.com/aspnet/KoreBuild/archive/dev.zip" +koreBuildZip="https://github.com/aspnet/KoreBuild/archive/release.zip" if [ ! -z $KOREBUILD_ZIP ]; then koreBuildZip=$KOREBUILD_ZIP fi From 6b7e27269c7d6419f160eda09bc90fb9aaa28540 Mon Sep 17 00:00:00 2001 From: jacalvar Date: Mon, 13 Jun 2016 14:24:32 -0700 Subject: [PATCH 0792/1662] Update Json.NET to 9.0.1 --- .../project.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json index 51a86e1a76..6c94ac48f0 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json @@ -7,7 +7,7 @@ "Microsoft.AspNetCore.Server.Kestrel.Https": "1.0.0-*", "Microsoft.AspNetCore.Testing": "1.0.0-*", "Microsoft.Extensions.Logging.Console": "1.0.0-*", - "Newtonsoft.Json": "9.0.1-beta1", + "Newtonsoft.Json": "9.0.1", "xunit": "2.1.0" }, "frameworks": { From 6414ccc2fdd299737689afe92f8dc8c5ef2a4726 Mon Sep 17 00:00:00 2001 From: Kristian Hellang Date: Mon, 13 Jun 2016 14:12:33 +0200 Subject: [PATCH 0793/1662] Added "308 Permanent Redirect" to ReasonPhrases From RFC7538 - https://tools.ietf.org/html/rfc7538 --- .../Internal/Http/ReasonPhrases.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ReasonPhrases.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ReasonPhrases.cs index e78847e300..9bfa85d631 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ReasonPhrases.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ReasonPhrases.cs @@ -28,6 +28,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http private static readonly byte[] _bytesStatus305 = Encoding.ASCII.GetBytes("305 Use Proxy"); private static readonly byte[] _bytesStatus306 = Encoding.ASCII.GetBytes("306 Reserved"); private static readonly byte[] _bytesStatus307 = Encoding.ASCII.GetBytes("307 Temporary Redirect"); + private static readonly byte[] _bytesStatus308 = Encoding.ASCII.GetBytes("308 Permanent Redirect"); private static readonly byte[] _bytesStatus400 = Encoding.ASCII.GetBytes("400 Bad Request"); private static readonly byte[] _bytesStatus401 = Encoding.ASCII.GetBytes("401 Unauthorized"); private static readonly byte[] _bytesStatus402 = Encoding.ASCII.GetBytes("402 Payment Required"); @@ -107,6 +108,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http return _bytesStatus306; case 307: return _bytesStatus307; + case 308: + return _bytesStatus308; case 400: return _bytesStatus400; case 401: @@ -178,4 +181,4 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http return Encoding.ASCII.GetBytes(statusCode.ToString(CultureInfo.InvariantCulture) + " " + reasonPhrase); } } -} \ No newline at end of file +} From eb74a19f9a343ff7911352337d00c6d0621b1e93 Mon Sep 17 00:00:00 2001 From: Kristian Hellang Date: Tue, 14 Jun 2016 11:25:22 +0200 Subject: [PATCH 0794/1662] Added "451 Unavailable For Legal Reasons" to ReasonPhrases From RFC7725 - https://tools.ietf.org/html/rfc7725 --- .../Internal/Http/ReasonPhrases.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ReasonPhrases.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ReasonPhrases.cs index e78847e300..035cbf1b06 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ReasonPhrases.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ReasonPhrases.cs @@ -51,6 +51,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http private static readonly byte[] _bytesStatus423 = Encoding.ASCII.GetBytes("423 Locked"); private static readonly byte[] _bytesStatus424 = Encoding.ASCII.GetBytes("424 Failed Dependency"); private static readonly byte[] _bytesStatus426 = Encoding.ASCII.GetBytes("426 Upgrade Required"); + private static readonly byte[] _bytesStatus451 = Encoding.ASCII.GetBytes("451 Unavailable For Legal Reasons"); private static readonly byte[] _bytesStatus500 = Encoding.ASCII.GetBytes("500 Internal Server Error"); private static readonly byte[] _bytesStatus501 = Encoding.ASCII.GetBytes("501 Not Implemented"); private static readonly byte[] _bytesStatus502 = Encoding.ASCII.GetBytes("502 Bad Gateway"); @@ -153,6 +154,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http return _bytesStatus424; case 426: return _bytesStatus426; + case 451: + return _bytesStatus451; case 500: return _bytesStatus500; case 501: @@ -178,4 +181,4 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http return Encoding.ASCII.GetBytes(statusCode.ToString(CultureInfo.InvariantCulture) + " " + reasonPhrase); } } -} \ No newline at end of file +} From de668c2ebd5a7c7cb2eff2a95835f2a08475be1a Mon Sep 17 00:00:00 2001 From: Pranav K Date: Thu, 16 Jun 2016 10:18:08 -0700 Subject: [PATCH 0795/1662] Updating to dev versions # Conflicts: # test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json --- samples/LargeResponseApp/project.json | 4 ++-- samples/SampleApp/project.json | 8 ++++---- .../project.json | 4 ++-- src/Microsoft.AspNetCore.Server.Kestrel/project.json | 6 +++--- .../project.json | 12 ++++++------ .../project.json | 8 ++++---- .../project.json | 6 +++--- 7 files changed, 24 insertions(+), 24 deletions(-) diff --git a/samples/LargeResponseApp/project.json b/samples/LargeResponseApp/project.json index b18eadc779..1483d74322 100644 --- a/samples/LargeResponseApp/project.json +++ b/samples/LargeResponseApp/project.json @@ -1,7 +1,7 @@ { - "version": "1.0.0-*", + "version": "1.1.0-*", "dependencies": { - "Microsoft.AspNetCore.Server.Kestrel": "1.0.0-*" + "Microsoft.AspNetCore.Server.Kestrel": "1.1.0-*" }, "buildOptions": { "emitEntryPoint": true diff --git a/samples/SampleApp/project.json b/samples/SampleApp/project.json index 91b041cb63..77e80450f2 100644 --- a/samples/SampleApp/project.json +++ b/samples/SampleApp/project.json @@ -1,9 +1,9 @@ { - "version": "1.0.0-*", + "version": "1.1.0-*", "dependencies": { - "Microsoft.AspNetCore.Server.Kestrel": "1.0.0-*", - "Microsoft.AspNetCore.Server.Kestrel.Https": "1.0.0-*", - "Microsoft.Extensions.Logging.Console": "1.0.0-*" + "Microsoft.AspNetCore.Server.Kestrel": "1.1.0-*", + "Microsoft.AspNetCore.Server.Kestrel.Https": "1.1.0-*", + "Microsoft.Extensions.Logging.Console": "1.1.0-*" }, "buildOptions": { "emitEntryPoint": true diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Https/project.json b/src/Microsoft.AspNetCore.Server.Kestrel.Https/project.json index 14a8744538..c619c52a35 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Https/project.json +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Https/project.json @@ -1,5 +1,5 @@ { - "version": "1.0.0-*", + "version": "1.1.0-*", "description": "HTTPS support for the ASP.NET Core Kestrel cross-platform web server.", "buildOptions": { "keyFile": "../../tools/Key.snk", @@ -19,7 +19,7 @@ ] }, "dependencies": { - "Microsoft.AspNetCore.Server.Kestrel": "1.0.0-*" + "Microsoft.AspNetCore.Server.Kestrel": "1.1.0-*" }, "frameworks": { "net451": {}, diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/project.json b/src/Microsoft.AspNetCore.Server.Kestrel/project.json index ce435f46d7..2208ce2684 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/project.json +++ b/src/Microsoft.AspNetCore.Server.Kestrel/project.json @@ -1,5 +1,5 @@ { - "version": "1.0.0-*", + "version": "1.1.0-*", "description": "ASP.NET Core Kestrel cross-platform web server.", "packOptions": { "repository": { @@ -17,8 +17,8 @@ "System.Runtime.InteropServices.RuntimeInformation": "4.0.0-*", "System.Threading.Tasks.Extensions": "4.0.0-*", "Libuv": "1.9.0-*", - "Microsoft.AspNetCore.Hosting": "1.0.0-*", - "Microsoft.Extensions.Logging.Abstractions": "1.0.0-*" + "Microsoft.AspNetCore.Hosting": "1.1.0-*", + "Microsoft.Extensions.Logging.Abstractions": "1.1.0-*" }, "frameworks": { "net451": { diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json index 6c94ac48f0..499aeb8887 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json @@ -1,12 +1,12 @@ { - "version": "1.0.0-*", + "version": "1.1.0-*", "dependencies": { "dotnet-test-xunit": "1.0.0-*", - "Microsoft.AspNetCore.Http.Abstractions": "1.0.0-*", - "Microsoft.AspNetCore.Server.Kestrel": "1.0.0-*", - "Microsoft.AspNetCore.Server.Kestrel.Https": "1.0.0-*", - "Microsoft.AspNetCore.Testing": "1.0.0-*", - "Microsoft.Extensions.Logging.Console": "1.0.0-*", + "Microsoft.AspNetCore.Http.Abstractions": "1.1.0-*", + "Microsoft.AspNetCore.Server.Kestrel": "1.1.0-*", + "Microsoft.AspNetCore.Server.Kestrel.Https": "1.1.0-*", + "Microsoft.AspNetCore.Testing": "1.1.0-*", + "Microsoft.Extensions.Logging.Console": "1.1.0-*", "Newtonsoft.Json": "9.0.1", "xunit": "2.1.0" }, diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/project.json b/test/Microsoft.AspNetCore.Server.KestrelTests/project.json index 89561cace8..db582a885c 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/project.json +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/project.json @@ -1,10 +1,10 @@ { - "version": "1.0.0-*", + "version": "1.1.0-*", "dependencies": { "dotnet-test-xunit": "1.0.0-*", - "Microsoft.AspNetCore.Server.Kestrel": "1.0.0-*", - "Microsoft.AspNetCore.Server.Kestrel.Https": "1.0.0-*", - "Microsoft.AspNetCore.Testing": "1.0.0-*", + "Microsoft.AspNetCore.Server.Kestrel": "1.1.0-*", + "Microsoft.AspNetCore.Server.Kestrel.Https": "1.1.0-*", + "Microsoft.AspNetCore.Testing": "1.1.0-*", "xunit": "2.1.0" }, "frameworks": { diff --git a/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/project.json b/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/project.json index 51b52cf788..81b8fc282a 100644 --- a/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/project.json +++ b/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/project.json @@ -1,11 +1,11 @@ { - "version": "1.0.0-*", + "version": "1.1.0-*", "buildOptions": { "emitEntryPoint": true }, "dependencies": { - "Microsoft.AspNetCore.Http.Features": "1.0.0-*", - "Microsoft.AspNetCore.Hosting": "1.0.0-*" + "Microsoft.AspNetCore.Http.Features": "1.1.0-*", + "Microsoft.AspNetCore.Hosting": "1.1.0-*" }, "frameworks": { "netcoreapp1.0": { From 3db95ddcde5acfcbc2c8ae2c8c24e46f21841151 Mon Sep 17 00:00:00 2001 From: Nicholas Ventimiglia Date: Tue, 21 Jun 2016 11:08:40 -0700 Subject: [PATCH 0796/1662] As an American, I had to correct the spelling of 'independent' --- .../Internal/Infrastructure/MemoryPoolBlock.cs | 4 ++-- .../Internal/Infrastructure/MemoryPoolSlab.cs | 2 +- .../Internal/Infrastructure/TaskUtilities.cs | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolBlock.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolBlock.cs index 52f6825a77..e60bb4a338 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolBlock.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolBlock.cs @@ -6,7 +6,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure { /// /// Block tracking object used by the byte buffer memory pool. A slab is a large allocation which is divided into smaller blocks. The - /// individual blocks are then treated as independant array segments. + /// individual blocks are then treated as independent array segments. /// public class MemoryPoolBlock { @@ -65,7 +65,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure /// /// Reference to the next block of data when the overall "active" bytes spans multiple blocks. At the point when the block is - /// leased Next is guaranteed to be null. Start, End, and Next are used together in order to create a linked-list of discontiguous + /// leased Next is guaranteed to be null. Start, End, and Next are used together in order to create a linked-list of discontinuous /// working memory. The "active" memory is grown when bytes are copied in, End is increased, and Next is assigned. The "active" /// memory is shrunk when bytes are consumed, Start is increased, and blocks are returned to the pool. /// diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolSlab.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolSlab.cs index e61b12c6ca..cd8d65476d 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolSlab.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolSlab.cs @@ -5,7 +5,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure { /// /// Slab tracking object used by the byte buffer memory pool. A slab is a large allocation which is divided into smaller blocks. The - /// individual blocks are then treated as independant array segments. + /// individual blocks are then treated as independent array segments. /// public class MemoryPoolSlab : IDisposable { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/TaskUtilities.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/TaskUtilities.cs index 139411bca0..cff575e053 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/TaskUtilities.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/TaskUtilities.cs @@ -29,7 +29,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure public static Task GetCancelledZeroTask(CancellationToken cancellationToken = default(CancellationToken)) { #if NETSTANDARD1_3 - // Make sure cancellationToken is cancelled before passing to Task.FromCanceled + // Make sure cancellationToken is canceled before passing to Task.FromCanceled if (!cancellationToken.IsCancellationRequested) { cancellationToken = new CancellationToken(true); From 6a8a4e866936746a3f839cb2e260ffb529863ce4 Mon Sep 17 00:00:00 2001 From: Nicholas Ventimiglia Date: Tue, 21 Jun 2016 17:00:59 -0700 Subject: [PATCH 0797/1662] Update MemoryPoolBlock.cs --- .../Internal/Infrastructure/MemoryPoolBlock.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolBlock.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolBlock.cs index e60bb4a338..f2ad31cf58 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolBlock.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolBlock.cs @@ -65,7 +65,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure /// /// Reference to the next block of data when the overall "active" bytes spans multiple blocks. At the point when the block is - /// leased Next is guaranteed to be null. Start, End, and Next are used together in order to create a linked-list of discontinuous + /// leased Next is guaranteed to be null. Start, End, and Next are used together in order to create a linked-list of discontiguous /// working memory. The "active" memory is grown when bytes are copied in, End is increased, and Next is assigned. The "active" /// memory is shrunk when bytes are consumed, Start is increased, and blocks are returned to the pool. /// From 4c4167b6cb9dfe9a7701da9da62706eb13f222e1 Mon Sep 17 00:00:00 2001 From: Pranav K Date: Mon, 27 Jun 2016 13:50:13 -0700 Subject: [PATCH 0798/1662] Updating NuGet.config --- NuGet.config | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/NuGet.config b/NuGet.config index 9db87a421e..adbb3c1710 100644 --- a/NuGet.config +++ b/NuGet.config @@ -1,7 +1,8 @@ - + + \ No newline at end of file From fb777b13bee3c10ba971bddfc259c8f7018f547d Mon Sep 17 00:00:00 2001 From: Pranav K Date: Mon, 27 Jun 2016 13:51:08 -0700 Subject: [PATCH 0799/1662] Updating json files to pin versions and build files to pin KoreBuild --- build.ps1 | 2 +- build.sh | 2 +- samples/LargeResponseApp/project.json | 4 +- samples/SampleApp/project.json | 10 ++--- .../project.json | 6 +-- .../project.json | 44 +++++++++---------- .../project.json | 20 ++++----- .../project.json | 24 +++++----- .../project.json | 6 +-- 9 files changed, 59 insertions(+), 59 deletions(-) diff --git a/build.ps1 b/build.ps1 index cf8bff13bb..6d49c4dccd 100644 --- a/build.ps1 +++ b/build.ps1 @@ -33,7 +33,7 @@ cd $PSScriptRoot $repoFolder = $PSScriptRoot $env:REPO_FOLDER = $repoFolder -$koreBuildZip="https://github.com/aspnet/KoreBuild/archive/release.zip" +$koreBuildZip="https://github.com/aspnet/KoreBuild/archive/1.0.0.zip" if ($env:KOREBUILD_ZIP) { $koreBuildZip=$env:KOREBUILD_ZIP diff --git a/build.sh b/build.sh index f88fe4052e..a55d3ebc12 100755 --- a/build.sh +++ b/build.sh @@ -2,7 +2,7 @@ repoFolder="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" cd $repoFolder -koreBuildZip="https://github.com/aspnet/KoreBuild/archive/release.zip" +koreBuildZip="https://github.com/aspnet/KoreBuild/archive/1.0.0.zip" if [ ! -z $KOREBUILD_ZIP ]; then koreBuildZip=$KOREBUILD_ZIP fi diff --git a/samples/LargeResponseApp/project.json b/samples/LargeResponseApp/project.json index b18eadc779..564a1b623a 100644 --- a/samples/LargeResponseApp/project.json +++ b/samples/LargeResponseApp/project.json @@ -1,7 +1,7 @@ { "version": "1.0.0-*", "dependencies": { - "Microsoft.AspNetCore.Server.Kestrel": "1.0.0-*" + "Microsoft.AspNetCore.Server.Kestrel": "1.0.0" }, "buildOptions": { "emitEntryPoint": true @@ -11,7 +11,7 @@ "netcoreapp1.0": { "dependencies": { "Microsoft.NETCore.App": { - "version": "1.0.0-*", + "version": "1.0.0", "type": "platform" } } diff --git a/samples/SampleApp/project.json b/samples/SampleApp/project.json index 91b041cb63..721f53351c 100644 --- a/samples/SampleApp/project.json +++ b/samples/SampleApp/project.json @@ -1,9 +1,9 @@ { "version": "1.0.0-*", "dependencies": { - "Microsoft.AspNetCore.Server.Kestrel": "1.0.0-*", - "Microsoft.AspNetCore.Server.Kestrel.Https": "1.0.0-*", - "Microsoft.Extensions.Logging.Console": "1.0.0-*" + "Microsoft.AspNetCore.Server.Kestrel": "1.0.0", + "Microsoft.AspNetCore.Server.Kestrel.Https": "1.0.0", + "Microsoft.Extensions.Logging.Console": "1.0.0" }, "buildOptions": { "emitEntryPoint": true @@ -13,10 +13,10 @@ "netcoreapp1.0": { "dependencies": { "Microsoft.NETCore.App": { - "version": "1.0.0-*", + "version": "1.0.0", "type": "platform" }, - "System.Console": "4.0.0-*" + "System.Console": "4.0.0" } } }, diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Https/project.json b/src/Microsoft.AspNetCore.Server.Kestrel.Https/project.json index 14a8744538..f8ee43e9a7 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Https/project.json +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Https/project.json @@ -1,5 +1,5 @@ { - "version": "1.0.0-*", + "version": "1.0.0", "description": "HTTPS support for the ASP.NET Core Kestrel cross-platform web server.", "buildOptions": { "keyFile": "../../tools/Key.snk", @@ -19,13 +19,13 @@ ] }, "dependencies": { - "Microsoft.AspNetCore.Server.Kestrel": "1.0.0-*" + "Microsoft.AspNetCore.Server.Kestrel": "1.0.0" }, "frameworks": { "net451": {}, "netstandard1.3": { "dependencies": { - "System.Net.Security": "4.0.0-*" + "System.Net.Security": "4.0.0" } } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/project.json b/src/Microsoft.AspNetCore.Server.Kestrel/project.json index ce435f46d7..b6ca5d51c7 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/project.json +++ b/src/Microsoft.AspNetCore.Server.Kestrel/project.json @@ -1,5 +1,5 @@ { - "version": "1.0.0-*", + "version": "1.0.0", "description": "ASP.NET Core Kestrel cross-platform web server.", "packOptions": { "repository": { @@ -12,13 +12,13 @@ ] }, "dependencies": { - "System.Buffers": "4.0.0-*", - "System.Numerics.Vectors": "4.1.1-*", - "System.Runtime.InteropServices.RuntimeInformation": "4.0.0-*", - "System.Threading.Tasks.Extensions": "4.0.0-*", - "Libuv": "1.9.0-*", - "Microsoft.AspNetCore.Hosting": "1.0.0-*", - "Microsoft.Extensions.Logging.Abstractions": "1.0.0-*" + "System.Buffers": "4.0.0", + "System.Numerics.Vectors": "4.1.1", + "System.Runtime.InteropServices.RuntimeInformation": "4.0.0", + "System.Threading.Tasks.Extensions": "4.0.0", + "Libuv": "1.9.0", + "Microsoft.AspNetCore.Hosting": "1.0.0", + "Microsoft.Extensions.Logging.Abstractions": "1.0.0" }, "frameworks": { "net451": { @@ -33,20 +33,20 @@ }, "netstandard1.3": { "dependencies": { - "System.Collections": "4.0.11-*", - "System.Diagnostics.Debug": "4.0.11-*", - "System.Globalization": "4.0.11-*", - "System.IO": "4.1.0-*", - "System.Linq": "4.1.0-*", - "System.Net.Primitives": "4.0.11-*", - "System.Runtime.Extensions": "4.1.0-*", - "System.Runtime.InteropServices": "4.1.0-*", - "System.Text.Encoding": "4.0.11-*", - "System.Threading": "4.0.11-*", - "System.Threading.Tasks": "4.0.11-*", - "System.Threading.Thread": "4.0.0-*", - "System.Threading.ThreadPool": "4.0.10-*", - "System.Threading.Timer": "4.0.1-*" + "System.Collections": "4.0.11", + "System.Diagnostics.Debug": "4.0.11", + "System.Globalization": "4.0.11", + "System.IO": "4.1.0", + "System.Linq": "4.1.0", + "System.Net.Primitives": "4.0.11", + "System.Runtime.Extensions": "4.1.0", + "System.Runtime.InteropServices": "4.1.0", + "System.Text.Encoding": "4.0.11", + "System.Threading": "4.0.11", + "System.Threading.Tasks": "4.0.11", + "System.Threading.Thread": "4.0.0", + "System.Threading.ThreadPool": "4.0.10", + "System.Threading.Timer": "4.0.1" } } }, diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json index 6c94ac48f0..b1cebed064 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json @@ -1,12 +1,12 @@ { "version": "1.0.0-*", "dependencies": { - "dotnet-test-xunit": "1.0.0-*", - "Microsoft.AspNetCore.Http.Abstractions": "1.0.0-*", - "Microsoft.AspNetCore.Server.Kestrel": "1.0.0-*", - "Microsoft.AspNetCore.Server.Kestrel.Https": "1.0.0-*", - "Microsoft.AspNetCore.Testing": "1.0.0-*", - "Microsoft.Extensions.Logging.Console": "1.0.0-*", + "dotnet-test-xunit": "1.0.0-rc3-000000-00", + "Microsoft.AspNetCore.Http.Abstractions": "1.0.0", + "Microsoft.AspNetCore.Server.Kestrel": "1.0.0", + "Microsoft.AspNetCore.Server.Kestrel.Https": "1.0.0", + "Microsoft.AspNetCore.Testing": "1.0.0-rtm-21431", + "Microsoft.Extensions.Logging.Console": "1.0.0", "Newtonsoft.Json": "9.0.1", "xunit": "2.1.0" }, @@ -14,12 +14,12 @@ "netcoreapp1.0": { "dependencies": { "Microsoft.NETCore.App": { - "version": "1.0.0-*", + "version": "1.0.0", "type": "platform" }, - "System.Net.Http": "4.1.0-*", - "System.Net.Http.WinHttpHandler": "4.0.0-*", - "System.Runtime.Serialization.Primitives": "4.1.1-*" + "System.Net.Http": "4.1.0", + "System.Net.Http.WinHttpHandler": "4.0.0", + "System.Runtime.Serialization.Primitives": "4.1.1" }, "imports": [ "portable-dnxcore50+net45+win8+wp8+wpa81", diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/project.json b/test/Microsoft.AspNetCore.Server.KestrelTests/project.json index 89561cace8..5656d4e573 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/project.json +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/project.json @@ -1,26 +1,26 @@ { "version": "1.0.0-*", "dependencies": { - "dotnet-test-xunit": "1.0.0-*", - "Microsoft.AspNetCore.Server.Kestrel": "1.0.0-*", - "Microsoft.AspNetCore.Server.Kestrel.Https": "1.0.0-*", - "Microsoft.AspNetCore.Testing": "1.0.0-*", + "dotnet-test-xunit": "1.0.0-rc3-000000-00", + "Microsoft.AspNetCore.Server.Kestrel": "1.0.0", + "Microsoft.AspNetCore.Server.Kestrel.Https": "1.0.0", + "Microsoft.AspNetCore.Testing": "1.0.0-rtm-21431", "xunit": "2.1.0" }, "frameworks": { "netcoreapp1.0": { "dependencies": { "Microsoft.NETCore.App": { - "version": "1.0.0-*", + "version": "1.0.0", "type": "platform" }, - "System.Diagnostics.TraceSource": "4.0.0-*", - "System.Globalization.Extensions": "4.0.1-*", - "System.IO": "4.1.0-*", - "System.Net.Http": "4.1.0-*", - "System.Net.Http.WinHttpHandler": "4.0.0-*", - "System.Net.Sockets": "4.1.0-*", - "System.Runtime.Handles": "4.0.1-*", + "System.Diagnostics.TraceSource": "4.0.0", + "System.Globalization.Extensions": "4.0.1", + "System.IO": "4.1.0", + "System.Net.Http": "4.1.0", + "System.Net.Http.WinHttpHandler": "4.0.0", + "System.Net.Sockets": "4.1.0", + "System.Runtime.Handles": "4.0.1", "moq.netcore": "4.4.0-beta8" }, "imports": [ diff --git a/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/project.json b/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/project.json index 51b52cf788..d9e3e04305 100644 --- a/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/project.json +++ b/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/project.json @@ -4,14 +4,14 @@ "emitEntryPoint": true }, "dependencies": { - "Microsoft.AspNetCore.Http.Features": "1.0.0-*", - "Microsoft.AspNetCore.Hosting": "1.0.0-*" + "Microsoft.AspNetCore.Http.Features": "1.0.0", + "Microsoft.AspNetCore.Hosting": "1.0.0" }, "frameworks": { "netcoreapp1.0": { "dependencies": { "Microsoft.NETCore.App": { - "version": "1.0.0-*", + "version": "1.0.0", "type": "platform" } } From a09bce0c0795e2c396fae191141a0007b3eb96dc Mon Sep 17 00:00:00 2001 From: Pranav K Date: Thu, 30 Jun 2016 16:00:14 -0700 Subject: [PATCH 0800/1662] Updating to RTM builds of xunit and Moq --- .../project.json | 14 +++----------- .../project.json | 17 +++++------------ 2 files changed, 8 insertions(+), 23 deletions(-) diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json index 499aeb8887..3b8c4e3337 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json @@ -1,14 +1,14 @@ { "version": "1.1.0-*", "dependencies": { - "dotnet-test-xunit": "1.0.0-*", + "dotnet-test-xunit": "2.2.0-*", "Microsoft.AspNetCore.Http.Abstractions": "1.1.0-*", "Microsoft.AspNetCore.Server.Kestrel": "1.1.0-*", "Microsoft.AspNetCore.Server.Kestrel.Https": "1.1.0-*", "Microsoft.AspNetCore.Testing": "1.1.0-*", "Microsoft.Extensions.Logging.Console": "1.1.0-*", "Newtonsoft.Json": "9.0.1", - "xunit": "2.1.0" + "xunit": "2.2.0-*" }, "frameworks": { "netcoreapp1.0": { @@ -20,17 +20,9 @@ "System.Net.Http": "4.1.0-*", "System.Net.Http.WinHttpHandler": "4.0.0-*", "System.Runtime.Serialization.Primitives": "4.1.1-*" - }, - "imports": [ - "portable-dnxcore50+net45+win8+wp8+wpa81", - "dotnet", - "portable-net45+win8" - ] + } }, "net451": { - "dependencies": { - "xunit.runner.console": "2.1.0" - }, "frameworkAssemblies": { "System.Net.Http": "4.0.0.0" } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/project.json b/test/Microsoft.AspNetCore.Server.KestrelTests/project.json index db582a885c..9f10bec8ec 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/project.json +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/project.json @@ -1,11 +1,12 @@ { "version": "1.1.0-*", "dependencies": { - "dotnet-test-xunit": "1.0.0-*", + "dotnet-test-xunit": "2.2.0-*", "Microsoft.AspNetCore.Server.Kestrel": "1.1.0-*", "Microsoft.AspNetCore.Server.Kestrel.Https": "1.1.0-*", "Microsoft.AspNetCore.Testing": "1.1.0-*", - "xunit": "2.1.0" + "Moq": "4.6.25-*", + "xunit": "2.2.0-*" }, "frameworks": { "netcoreapp1.0": { @@ -20,19 +21,11 @@ "System.Net.Http": "4.1.0-*", "System.Net.Http.WinHttpHandler": "4.0.0-*", "System.Net.Sockets": "4.1.0-*", - "System.Runtime.Handles": "4.0.1-*", - "moq.netcore": "4.4.0-beta8" + "System.Runtime.Handles": "4.0.1-*" }, - "imports": [ - "dnxcore50", - "portable-net451+win8" - ] + "imports": "dotnet5.4" }, "net451": { - "dependencies": { - "xunit.runner.console": "2.1.0", - "Moq": "4.2.1312.1622" - }, "frameworkAssemblies": { "System.Net.Http": "4.0.0.0" } From 9f720eda900c91168617894485c9b58bd5af1d0d Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Tue, 5 Jul 2016 17:57:21 -0700 Subject: [PATCH 0801/1662] Reset frame streams on each request (#940). --- .../Internal/Http/Frame.cs | 7 +-- .../RequestTests.cs | 47 +++++++++++++++++++ .../FrameTests.cs | 40 +++++++++++++++- 3 files changed, 89 insertions(+), 5 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs index 9e45c3f695..d014f3d2b9 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs @@ -242,11 +242,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if (_frameStreams == null) { _frameStreams = new Streams(this); - RequestBody = _frameStreams.RequestBody; - ResponseBody = _frameStreams.ResponseBody; - DuplexStream = _frameStreams.DuplexStream; } + RequestBody = _frameStreams.RequestBody; + ResponseBody = _frameStreams.ResponseBody; + DuplexStream = _frameStreams.DuplexStream; + _frameStreams.RequestBody.StartAcceptingReads(messageBody); _frameStreams.ResponseBody.StartAcceptingWrites(); } diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs index 487306a386..a01b84f7b8 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs @@ -1,7 +1,9 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; using System.Globalization; +using System.IO; using System.Net; using System.Net.Http; using System.Net.Sockets; @@ -137,6 +139,51 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } } + [Fact] + public async Task StreamsAreNotPersistedAcrossRequests() + { + var requestBodyPersisted = false; + var responseBodyPersisted = false; + + var builder = new WebHostBuilder() + .UseKestrel() + .UseUrls($"http://127.0.0.1:0") + .Configure(app => + { + app.Run(async context => + { + if (context.Request.Body is MemoryStream) + { + requestBodyPersisted = true; + } + + if (context.Response.Body is MemoryStream) + { + responseBodyPersisted = true; + } + + context.Request.Body = new MemoryStream(); + context.Response.Body = new MemoryStream(); + + await context.Response.WriteAsync("hello, world"); + }); + }); + + using (var host = builder.Build()) + { + host.Start(); + + using (var client = new HttpClient { BaseAddress = new Uri($"http://127.0.0.1:{host.GetPort()}") }) + { + await client.GetAsync("/"); + await client.GetAsync("/"); + + Assert.False(requestBodyPersisted); + Assert.False(responseBodyPersisted); + } + } + } + private async Task TestRemoteIPAddress(string registerAddress, string requestAddress, string expectAddress) { var builder = new WebHostBuilder() diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs index 52c44bb2b4..c7ada35248 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.IO; using System.Text; using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Server.Kestrel; @@ -453,9 +454,10 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var frame = new Frame(application: null, context: connectionContext); frame.InitializeHeaders(); - // Act var originalRequestHeaders = frame.RequestHeaders; frame.RequestHeaders = new FrameRequestHeaders(); + + // Act frame.InitializeHeaders(); // Assert @@ -476,13 +478,47 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var frame = new Frame(application: null, context: connectionContext); frame.InitializeHeaders(); - // Act var originalResponseHeaders = frame.ResponseHeaders; frame.ResponseHeaders = new FrameResponseHeaders(); + + // Act frame.InitializeHeaders(); // Assert Assert.Same(originalResponseHeaders, frame.ResponseHeaders); } + + [Fact] + public void InitializeStreamsResetsStreams() + { + // Arrange + var connectionContext = new ConnectionContext() + { + DateHeaderValueManager = new DateHeaderValueManager(), + ServerAddress = ServerAddress.FromUrl("http://localhost:5000"), + ServerOptions = new KestrelServerOptions(), + SocketOutput = new MockSocketOuptut() + }; + var frame = new Frame(application: null, context: connectionContext); + frame.InitializeHeaders(); + + var messageBody = MessageBody.For("HTTP/1.1", (FrameRequestHeaders)frame.RequestHeaders, frame); + frame.InitializeStreams(messageBody); + + var originalRequestBody = frame.RequestBody; + var originalResponseBody = frame.ResponseBody; + var originalDuplexStream = frame.DuplexStream; + frame.RequestBody = new MemoryStream(); + frame.ResponseBody = new MemoryStream(); + frame.DuplexStream = new MemoryStream(); + + // Act + frame.InitializeStreams(messageBody); + + // Assert + Assert.Same(originalRequestBody, frame.RequestBody); + Assert.Same(originalResponseBody, frame.ResponseBody); + Assert.Same(originalDuplexStream, frame.DuplexStream); + } } } From efa37e55903c276951d1cf6561abee4d4e6b3393 Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Tue, 5 Jul 2016 16:08:42 -0700 Subject: [PATCH 0802/1662] Tidy up SampleApp. --- samples/SampleApp/Startup.cs | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/samples/SampleApp/Startup.cs b/samples/SampleApp/Startup.cs index c93e2cb1e9..84bb918a99 100644 --- a/samples/SampleApp/Startup.cs +++ b/samples/SampleApp/Startup.cs @@ -15,26 +15,19 @@ namespace SampleApp public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory) { loggerFactory.AddConsole(LogLevel.Trace); + var logger = loggerFactory.CreateLogger("Default"); app.Run(async context => { - Console.WriteLine("{0} {1}{2}{3}", - context.Request.Method, - context.Request.PathBase, - context.Request.Path, - context.Request.QueryString); - Console.WriteLine($"Method: {context.Request.Method}"); - Console.WriteLine($"PathBase: {context.Request.PathBase}"); - Console.WriteLine($"Path: {context.Request.Path}"); - Console.WriteLine($"QueryString: {context.Request.QueryString}"); - var connectionFeature = context.Connection; - Console.WriteLine($"Peer: {connectionFeature.RemoteIpAddress?.ToString()} {connectionFeature.RemotePort}"); - Console.WriteLine($"Sock: {connectionFeature.LocalIpAddress?.ToString()} {connectionFeature.LocalPort}"); + logger.LogDebug($"Peer: {connectionFeature.RemoteIpAddress?.ToString()}:{connectionFeature.RemotePort}" + + $"{Environment.NewLine}" + + $"Sock: {connectionFeature.LocalIpAddress?.ToString()}:{connectionFeature.LocalPort}"); - context.Response.ContentLength = 11; + var response = $"hello, world{Environment.NewLine}"; + context.Response.ContentLength = response.Length; context.Response.ContentType = "text/plain"; - await context.Response.WriteAsync("Hello world"); + await context.Response.WriteAsync(response); }); } From 82a0a991079722c0a7ce28c2919a9a33e5301477 Mon Sep 17 00:00:00 2001 From: Doug Bunting Date: Thu, 7 Jul 2016 12:07:14 -0700 Subject: [PATCH 0803/1662] One build to rule them all - well, at least VS and command-line builds will share output - part of aspnet/Coherence-Signed#277 --- samples/LargeResponseApp/LargeResponseApp.xproj | 4 ++-- samples/SampleApp/SampleApp.xproj | 4 ++-- .../Microsoft.AspNetCore.Server.Kestrel.Https.xproj | 4 ++-- .../Microsoft.AspNetCore.Server.Kestrel.xproj | 4 ++-- .../Microsoft.AspNetCore.Server.Kestrel.FunctionalTests.xproj | 4 ++-- .../Microsoft.AspNetCore.Server.KestrelTests.xproj | 4 ++-- .../Microsoft.AspNetCore.Server.Kestrel.GeneratedCode.xproj | 4 ++-- 7 files changed, 14 insertions(+), 14 deletions(-) diff --git a/samples/LargeResponseApp/LargeResponseApp.xproj b/samples/LargeResponseApp/LargeResponseApp.xproj index ffc0ba931a..3f742acc02 100644 --- a/samples/LargeResponseApp/LargeResponseApp.xproj +++ b/samples/LargeResponseApp/LargeResponseApp.xproj @@ -7,8 +7,8 @@ b35d4d31-e74c-4646-8a11-7a7a40f0021e - ..\..\artifacts\obj\$(MSBuildProjectName) - ..\..\artifacts\bin\ + .\obj + .\bin\ 2.0 diff --git a/samples/SampleApp/SampleApp.xproj b/samples/SampleApp/SampleApp.xproj index eb656e8acc..7728a1cab2 100644 --- a/samples/SampleApp/SampleApp.xproj +++ b/samples/SampleApp/SampleApp.xproj @@ -7,8 +7,8 @@ 2c3cb3dc-eebf-4f52-9e1c-4f2f972e76c3 - ..\..\artifacts\obj\$(MSBuildProjectName) - ..\..\artifacts\bin\ + .\obj + .\bin\ 2.0 diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Https/Microsoft.AspNetCore.Server.Kestrel.Https.xproj b/src/Microsoft.AspNetCore.Server.Kestrel.Https/Microsoft.AspNetCore.Server.Kestrel.Https.xproj index 0a0bc4da18..fb3eb70783 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Https/Microsoft.AspNetCore.Server.Kestrel.Https.xproj +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Https/Microsoft.AspNetCore.Server.Kestrel.Https.xproj @@ -7,8 +7,8 @@ 5f64b3c3-0c2e-431a-b820-a81bbfc863da - ..\..\artifacts\obj\$(MSBuildProjectName) - ..\..\artifacts\bin\ + .\obj + .\bin\ 2.0 diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Microsoft.AspNetCore.Server.Kestrel.xproj b/src/Microsoft.AspNetCore.Server.Kestrel/Microsoft.AspNetCore.Server.Kestrel.xproj index 586763ad5a..1e2963de0d 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Microsoft.AspNetCore.Server.Kestrel.xproj +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Microsoft.AspNetCore.Server.Kestrel.xproj @@ -7,8 +7,8 @@ f510611a-3bee-4b88-a613-5f4a74ed82a1 - ..\..\artifacts\obj\$(MSBuildProjectName) - ..\..\artifacts\bin\ + .\obj + .\bin\ 2.0 diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests.xproj b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests.xproj index 2e53dbe9cb..4c5139d367 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests.xproj +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests.xproj @@ -7,8 +7,8 @@ 9559a5f1-080c-4909-b6cf-7e4b3dc55748 - ..\..\artifacts\obj\$(MSBuildProjectName) - ..\..\artifacts\bin\ + .\obj + .\bin\ 2.0 diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/Microsoft.AspNetCore.Server.KestrelTests.xproj b/test/Microsoft.AspNetCore.Server.KestrelTests/Microsoft.AspNetCore.Server.KestrelTests.xproj index 11118f9543..148f89093b 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/Microsoft.AspNetCore.Server.KestrelTests.xproj +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/Microsoft.AspNetCore.Server.KestrelTests.xproj @@ -7,8 +7,8 @@ 37f3bfb2-6454-49e5-9d7f-581bf755ccfe - ..\..\artifacts\obj\$(MSBuildProjectName) - ..\..\artifacts\bin\ + .\obj + .\bin\ 2.0 diff --git a/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode.xproj b/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode.xproj index 6970817548..eb41dbdbb4 100644 --- a/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode.xproj +++ b/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode.xproj @@ -7,8 +7,8 @@ bd2d4d29-1bd9-40d0-bb31-337d5416b63c - ..\..\artifacts\obj\$(MSBuildProjectName) - ..\..\artifacts\bin\ + .\obj + .\bin\ 2.0 From 8a43be94efca3397f70ec20865d70862d5b94e9e Mon Sep 17 00:00:00 2001 From: Mike Harder Date: Mon, 11 Jul 2016 14:40:12 -0700 Subject: [PATCH 0804/1662] AddressRegistrationTests should get local IPs from System.Net.NetworkInformation (#796) --- .../AddressRegistrationTests.cs | 15 ++++++++++++--- .../project.json | 1 + 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs index ee0651920c..b105a35044 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs @@ -2,9 +2,11 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Collections.Generic; using System.Linq; using System.Net; using System.Net.Http; +using System.Net.NetworkInformation; using System.Net.Sockets; using System.Threading.Tasks; using Microsoft.AspNetCore.Builder; @@ -166,7 +168,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests dataset.Add("http://127.0.0.1:0/", GetTestUrls); dataset.Add($"http://{Dns.GetHostName()}:0/", GetTestUrls); - var ipv4Addresses = Dns.GetHostAddressesAsync(Dns.GetHostName()).Result + var ipv4Addresses = GetIPAddresses() .Where(ip => ip.AddressFamily == AddressFamily.InterNetwork); foreach (var ip in ipv4Addresses) { @@ -224,7 +226,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests dataset.Add($"http://[::1]:{port1}/base/path", _ => new[] { $"http://[::1]:{port1}/base/path" }); // Dynamic port and non-loopback addresses - var ipv6Addresses = Dns.GetHostAddressesAsync(Dns.GetHostName()).Result + var ipv6Addresses = GetIPAddresses() .Where(ip => ip.AddressFamily == AddressFamily.InterNetworkV6) .Where(ip => ip.ScopeId == 0); foreach (var ip in ipv6Addresses) @@ -258,7 +260,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests var dataset = new TheoryData>(); // Dynamic port - var ipv6Addresses = Dns.GetHostAddressesAsync(Dns.GetHostName()).Result + var ipv6Addresses = GetIPAddresses() .Where(ip => ip.AddressFamily == AddressFamily.InterNetworkV6) .Where(ip => ip.ScopeId != 0); foreach (var ip in ipv6Addresses) @@ -270,6 +272,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } } + private static IEnumerable GetIPAddresses() + { + return NetworkInterface.GetAllNetworkInterfaces() + .SelectMany(i => i.GetIPProperties().UnicastAddresses) + .Select(a => a.Address); + } + private static string[] GetTestUrls(IServerAddressesFeature addressesFeature) { return addressesFeature.Addresses diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json index 3b8c4e3337..9b247ae340 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json @@ -19,6 +19,7 @@ }, "System.Net.Http": "4.1.0-*", "System.Net.Http.WinHttpHandler": "4.0.0-*", + "System.Net.NetworkInformation": "4.1.0-*", "System.Runtime.Serialization.Primitives": "4.1.1-*" } }, From 2f36c80970e7a114959f450676a898ede559cfd3 Mon Sep 17 00:00:00 2001 From: Mike Harder Date: Mon, 11 Jul 2016 17:53:59 -0700 Subject: [PATCH 0805/1662] Remove skip condition for IPv6 with scope ID on Linux and Mac (#964) - Was required to workaround https://github.com/dotnet/corefx/issues/8235 which is now fixed. --- .../AddressRegistrationTests.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs index b105a35044..c429dcfc49 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs @@ -53,8 +53,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [ConditionalTheory, MemberData(nameof(AddressRegistrationDataIPv6ScopeId))] [IPv6SupportedCondition] - [OSSkipCondition(OperatingSystems.Linux, SkipReason = "HttpClient does not support IPv6 with scope ID on Linux (https://github.com/dotnet/corefx/issues/8235).")] - [OSSkipCondition(OperatingSystems.MacOSX, SkipReason = "HttpClient does not support IPv6 with scope ID on Mac (https://github.com/dotnet/corefx/issues/8235).")] public async Task RegisterAddresses_IPv6ScopeId_Success(string addressInput, Func testUrls) { await RegisterAddresses_Success(addressInput, testUrls); From 7e1aa4e1d0990371428650d4fa723c672d0006f8 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Thu, 14 Jul 2016 16:08:39 -0700 Subject: [PATCH 0806/1662] Only test binding to "operational" network interfaces --- .../AddressRegistrationTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs index c429dcfc49..2199de4bb0 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs @@ -22,7 +22,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { public class AddressRegistrationTests { - [Theory, MemberData(nameof(AddressRegistrationDataIPv4))] public async Task RegisterAddresses_IPv4_Success(string addressInput, Func testUrls) { @@ -273,6 +272,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests private static IEnumerable GetIPAddresses() { return NetworkInterface.GetAllNetworkInterfaces() + .Where(i => i.OperationalStatus == OperationalStatus.Up) .SelectMany(i => i.GetIPProperties().UnicastAddresses) .Select(a => a.Address); } From 0c52529b97791471a4b91150889a821ffcd19b62 Mon Sep 17 00:00:00 2001 From: Mike Harder Date: Thu, 14 Jul 2016 18:35:47 -0700 Subject: [PATCH 0807/1662] Add tests for HTTPS urls to AddressRegistrationTests (#794) - Added HttpClientSlim, a lightweight version of HttpClient implemented using Socket and SslStream. --- .../AddressRegistrationTests.cs | 146 +++++++++++++----- .../HttpClientSlim.cs | 88 +++++++++++ 2 files changed, 192 insertions(+), 42 deletions(-) create mode 100644 test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/HttpClientSlim.cs diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs index 2199de4bb0..24ed52ff81 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs @@ -5,7 +5,6 @@ using System; using System.Collections.Generic; using System.Linq; using System.Net; -using System.Net.Http; using System.Net.NetworkInformation; using System.Net.Sockets; using System.Threading.Tasks; @@ -29,12 +28,19 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } [ConditionalTheory, MemberData(nameof(AddressRegistrationDataIPv4Port80))] - [Port80SupportedCondition] + [PortSupportedCondition(80)] public async Task RegisterAddresses_IPv4Port80_Success(string addressInput, Func testUrls) { await RegisterAddresses_Success(addressInput, testUrls); } + [ConditionalTheory, MemberData(nameof(AddressRegistrationDataIPv4Port443))] + [PortSupportedCondition(443)] + public async Task RegisterAddresses_IPv4Port443_Success(string addressInput, Func testUrls) + { + await RegisterAddresses_Success(addressInput, testUrls); + } + [ConditionalTheory, MemberData(nameof(AddressRegistrationDataIPv6))] [IPv6SupportedCondition] public async Task RegisterAddresses_IPv6_Success(string addressInput, Func testUrls) @@ -44,12 +50,20 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [ConditionalTheory, MemberData(nameof(AddressRegistrationDataIPv6Port80))] [IPv6SupportedCondition] - [Port80SupportedCondition] + [PortSupportedCondition(80)] public async Task RegisterAddresses_IPv6Port80_Success(string addressInput, Func testUrls) { await RegisterAddresses_Success(addressInput, testUrls); } + [ConditionalTheory, MemberData(nameof(AddressRegistrationDataIPv6Port443))] + [IPv6SupportedCondition] + [PortSupportedCondition(443)] + public async Task RegisterAddresses_IPv6Port443_Success(string addressInput, Func testUrls) + { + await RegisterAddresses_Success(addressInput, testUrls); + } + [ConditionalTheory, MemberData(nameof(AddressRegistrationDataIPv6ScopeId))] [IPv6SupportedCondition] public async Task RegisterAddresses_IPv6ScopeId_Success(string addressInput, Func testUrls) @@ -60,7 +74,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests private async Task RegisterAddresses_Success(string addressInput, Func testUrls) { var hostBuilder = new WebHostBuilder() - .UseKestrel() + .UseKestrel(options => + { + options.UseHttps(@"TestResources/testCert.pfx", "testPassword"); + }) .UseUrls(addressInput) .Configure(ConfigureEchoAddress); @@ -68,18 +85,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { host.Start(); - using (var client = new HttpClient()) + var client = new HttpClientSlim() { ValidateCertificate = false }; + foreach (var testUrl in testUrls(host.ServerFeatures.Get())) { - foreach (var testUrl in testUrls(host.ServerFeatures.Get())) - { - var response = await client.GetAsync(testUrl); - - // Compare the response with the RequestMessage.RequestUri, rather than testUrl directly. - // Required to handle IPv6 addresses with zone index, like "fe80::3%1" - Assert.Equal( - response.RequestMessage.RequestUri.ToString(), - await response.Content.ReadAsStringAsync()); - } + var response = await client.GetStringAsync(testUrl); + + // Compare the response with Uri.ToString(), rather than testUrl directly. + // Required to handle IPv6 addresses with zone index, like "fe80::3%1" + Assert.Equal(new Uri(testUrl).ToString(), response); } } } @@ -146,30 +159,33 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests var port2 = GetNextPort(); // Loopback - dataset.Add($"http://127.0.0.1:{port1}", _ => new[] { $"http://127.0.0.1:{port1}/" }); + dataset.Add($"http://127.0.0.1:{port1};https://127.0.0.1:{port2}", + _ => new[] { $"http://127.0.0.1:{port1}/", $"https://127.0.0.1:{port2}/" }); // Localhost - dataset.Add($"http://localhost:{port1}", _ => new[] { $"http://localhost:{port1}/", $"http://127.0.0.1:{port1}/" }); + dataset.Add($"http://localhost:{port1};https://localhost:{port2}", + _ => new[] { $"http://localhost:{port1}/", $"http://127.0.0.1:{port1}/", + $"https://localhost:{port2}/", $"https://127.0.0.1:{port2}/" }); // Any - dataset.Add($"http://*:{port1}/", _ => new[] { $"http://127.0.0.1:{port1}/" }); - dataset.Add($"http://+:{port1}/", _ => new[] { $"http://127.0.0.1:{port1}/" }); - - // Multiple addresses - dataset.Add($"http://127.0.0.1:{port1};http://127.0.0.1:{port2}", _ => new[] { $"http://127.0.0.1:{port1}/", $"http://127.0.0.1:{port2}/" }); + dataset.Add($"http://*:{port1}/;https://*:{port2}/", + _ => new[] { $"http://127.0.0.1:{port1}/", $"https://127.0.0.1:{port2}/" }); + dataset.Add($"http://+:{port1}/;https://+:{port2}/", + _ => new[] { $"http://127.0.0.1:{port1}/", $"https://127.0.0.1:{port2}/" }); // Path after port - dataset.Add($"http://127.0.0.1:{port1}/base/path", _ => new[] { $"http://127.0.0.1:{port1}/base/path" }); + dataset.Add($"http://127.0.0.1:{port1}/base/path;https://127.0.0.1:{port2}/base/path", + _ => new[] { $"http://127.0.0.1:{port1}/base/path", $"https://127.0.0.1:{port2}/base/path" }); // Dynamic port and non-loopback addresses - dataset.Add("http://127.0.0.1:0/", GetTestUrls); - dataset.Add($"http://{Dns.GetHostName()}:0/", GetTestUrls); + dataset.Add("http://127.0.0.1:0/;https://127.0.0.1:0/", GetTestUrls); + dataset.Add($"http://{Dns.GetHostName()}:0/;https://{Dns.GetHostName()}:0/", GetTestUrls); var ipv4Addresses = GetIPAddresses() .Where(ip => ip.AddressFamily == AddressFamily.InterNetwork); foreach (var ip in ipv4Addresses) { - dataset.Add($"http://{ip}:0/", GetTestUrls); + dataset.Add($"http://{ip}:0/;https://{ip}:0/", GetTestUrls); } return dataset; @@ -191,6 +207,21 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } } + public static TheoryData> AddressRegistrationDataIPv4Port443 + { + get + { + var dataset = new TheoryData>(); + + // Default port for HTTPS (443) + dataset.Add("https://127.0.0.1", _ => new[] { "https://127.0.0.1/" }); + dataset.Add("https://localhost", _ => new[] { "https://127.0.0.1/" }); + dataset.Add("https://*", _ => new[] { "https://127.0.0.1/" }); + + return dataset; + } + } + public static TheoryData> AddressRegistrationDataIPv6 { get @@ -206,21 +237,30 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests var port2 = GetNextPort(); // Loopback - dataset.Add($"http://[::1]:{port1}/", _ => new[] { $"http://[::1]:{port1}/" }); + dataset.Add($"http://[::1]:{port1}/;https://[::1]:{port2}/", + _ => new[] { $"http://[::1]:{port1}/", $"https://[::1]:{port2}/" }); // Localhost - dataset.Add($"http://localhost:{port1}", _ => new[] { $"http://localhost:{port1}/", $"http://127.0.0.1:{port1}/", $"http://[::1]:{port1}/" }); + dataset.Add($"http://localhost:{port1};https://localhost:{port2}", + _ => new[] { $"http://localhost:{port1}/", $"http://127.0.0.1:{port1}/", $"http://[::1]:{port1}/", + $"https://localhost:{port2}/", $"https://127.0.0.1:{port2}/", $"https://[::1]:{port2}/" }); // Any - dataset.Add($"http://*:{port1}/", _ => new[] { $"http://127.0.0.1:{port1}/", $"http://[::1]:{port1}/" }); - dataset.Add($"http://+:{port1}/", _ => new[] { $"http://127.0.0.1:{port1}/", $"http://[::1]:{port1}/" }); + dataset.Add($"http://*:{port1}/;https://*:{port2}/", + _ => new[] { $"http://127.0.0.1:{port1}/", $"http://[::1]:{port1}/", + $"https://127.0.0.1:{port2}/", $"https://[::1]:{port2}/" }); + dataset.Add($"http://+:{port1}/;https://+:{port2}/", + _ => new[] { $"http://127.0.0.1:{port1}/", $"http://[::1]:{port1}/", + $"https://127.0.0.1:{port2}/", $"https://[::1]:{port2}/" }); - // Multiple addresses - dataset.Add($"http://127.0.0.1:{port1}/;http://[::1]:{port1}/", _ => new[] { $"http://127.0.0.1:{port1}/", $"http://[::1]:{port1}/" }); - dataset.Add($"http://[::1]:{port1};http://[::1]:{port2}", _ => new[] { $"http://[::1]:{port1}/", $"http://[::1]:{port2}/" }); + // Explicit IPv4 and IPv6 on same port + dataset.Add($"http://127.0.0.1:{port1}/;http://[::1]:{port1}/;https://127.0.0.1:{port2}/;https://[::1]:{port2}/", + _ => new[] { $"http://127.0.0.1:{port1}/", $"http://[::1]:{port1}/", + $"https://127.0.0.1:{port2}/", $"https://[::1]:{port2}/" }); // Path after port - dataset.Add($"http://[::1]:{port1}/base/path", _ => new[] { $"http://[::1]:{port1}/base/path" }); + dataset.Add($"http://[::1]:{port1}/base/path;https://[::1]:{port2}/base/path", + _ => new[] { $"http://[::1]:{port1}/base/path", $"https://[::1]:{port2}/base/path" }); // Dynamic port and non-loopback addresses var ipv6Addresses = GetIPAddresses() @@ -228,7 +268,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests .Where(ip => ip.ScopeId == 0); foreach (var ip in ipv6Addresses) { - dataset.Add($"http://[{ip}]:0/", GetTestUrls); + dataset.Add($"http://[{ip}]:0/;https://[{ip}]:0/", GetTestUrls); } return dataset; @@ -250,6 +290,21 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } } + public static TheoryData> AddressRegistrationDataIPv6Port443 + { + get + { + var dataset = new TheoryData>(); + + // Default port for HTTPS (443) + dataset.Add("https://[::1]", _ => new[] { "https://[::1]/" }); + dataset.Add("https://localhost", _ => new[] { "https://127.0.0.1/", "https://[::1]/" }); + dataset.Add("https://*", _ => new[] { "https://[::1]/" }); + + return dataset; + } + } + public static TheoryData> AddressRegistrationDataIPv6ScopeId { get @@ -262,7 +317,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests .Where(ip => ip.ScopeId != 0); foreach (var ip in ipv6Addresses) { - dataset.Add($"http://[{ip}]:0/", GetTestUrls); + dataset.Add($"http://[{ip}]:0/;https://[{ip}]:0/", GetTestUrls); } return dataset; @@ -323,15 +378,22 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } [AttributeUsage(AttributeTargets.Method, AllowMultiple = false)] - private class Port80SupportedConditionAttribute : Attribute, ITestCondition + private class PortSupportedConditionAttribute : Attribute, ITestCondition { - private static readonly Lazy _port80Supported = new Lazy(CanBindToPort80); + private readonly int _port; + private readonly Lazy _portSupported; + + public PortSupportedConditionAttribute(int port) + { + _port = port; + _portSupported = new Lazy(CanBindToPort); + } public bool IsMet { get { - return _port80Supported.Value; + return _portSupported.Value; } } @@ -339,17 +401,17 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { get { - return "Cannot bind to port 80 on the host."; + return $"Cannot bind to port {_port} on the host."; } } - private static bool CanBindToPort80() + private bool CanBindToPort() { try { using (var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)) { - socket.Bind(new IPEndPoint(IPAddress.Loopback, 80)); + socket.Bind(new IPEndPoint(IPAddress.Loopback, _port)); return true; } } diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/HttpClientSlim.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/HttpClientSlim.cs new file mode 100644 index 0000000000..8775f93eff --- /dev/null +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/HttpClientSlim.cs @@ -0,0 +1,88 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.IO; +using System.Net; +using System.Net.Security; +using System.Net.Sockets; +using System.Security.Authentication; +using System.Text; +using System.Threading.Tasks; + +namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests +{ + // Lightweight version of HttpClient implemented using Socket and SslStream + public class HttpClientSlim + { + public bool ValidateCertificate { get; set; } = true; + + public Task GetStringAsync(string requestUri) => GetStringAsync(new Uri(requestUri)); + + public async Task GetStringAsync(Uri requestUri) + { + using (var stream = await GetStream(requestUri)) + { + using (var writer = new StreamWriter(stream, Encoding.ASCII, bufferSize: 1024, leaveOpen: true)) + { + await writer.WriteAsync($"GET {requestUri.PathAndQuery} HTTP/1.0\r\n"); + await writer.WriteAsync($"Host: {requestUri.Authority}\r\n"); + await writer.WriteAsync("\r\n"); + } + + using (var reader = new StreamReader(stream, Encoding.ASCII)) + { + var response = await reader.ReadToEndAsync(); + var body = response.Substring(response.IndexOf("\r\n\r\n") + 4); + return body; + } + } + } + + private async Task GetStream(Uri requestUri) + { + var socket = await GetSocket(requestUri); + Stream stream = new NetworkStream(socket, ownsSocket: true); + + if (requestUri.Scheme.Equals("https", StringComparison.OrdinalIgnoreCase)) + { + var sslStream = new SslStream(stream, leaveInnerStreamOpen: false, userCertificateValidationCallback: + ValidateCertificate ? null : (RemoteCertificateValidationCallback)((a, b, c, d) => true)); + await sslStream.AuthenticateAsClientAsync(requestUri.Host, clientCertificates: null, + enabledSslProtocols: SslProtocols.Tls11 | SslProtocols.Tls12, + checkCertificateRevocation: ValidateCertificate); + return sslStream; + } + else + { + return stream; + } + } + + private static async Task GetSocket(Uri requestUri) + { + var tcs = new TaskCompletionSource(); + + var socketArgs = new SocketAsyncEventArgs(); + socketArgs.RemoteEndPoint = new DnsEndPoint(requestUri.DnsSafeHost, requestUri.Port); + socketArgs.Completed += (s, e) => tcs.TrySetResult(e.ConnectSocket); + + // Must use static ConnectAsync(), since instance Connect() does not support DNS names on OSX/Linux. + if (Socket.ConnectAsync(SocketType.Stream, ProtocolType.Tcp, socketArgs)) + { + await tcs.Task; + } + + var socket = socketArgs.ConnectSocket; + + if (socket == null) + { + throw new SocketException((int)socketArgs.SocketError); + } + else + { + return socket; + } + } + } +} From fbcb5dcb1b7dbaef6dc97cdbc9ab94cb57c61c12 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Thu, 14 Jul 2016 15:12:47 -0700 Subject: [PATCH 0808/1662] Prevent enumeration of queue during modification in SocketOutputTests --- .../SocketOutputTests.cs | 79 ++++++++++++++----- 1 file changed, 60 insertions(+), 19 deletions(-) diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/SocketOutputTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/SocketOutputTests.cs index 639d52741f..ff26864bc5 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/SocketOutputTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/SocketOutputTests.cs @@ -2,10 +2,10 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Collections.Concurrent; using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; -using Microsoft.AspNetCore.Server.Kestrel; using Microsoft.AspNetCore.Server.Kestrel.Internal; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; @@ -66,7 +66,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { // This should match _maxBytesPreCompleted in SocketOutput var maxBytesPreCompleted = 65536; - var completeQueue = new Queue>(); + var completeQueue = new ConcurrentQueue>(); // Arrange var mockLibuv = new MockLibuv @@ -87,7 +87,8 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var socket = new MockSocket(mockLibuv, kestrelThread.Loop.ThreadId, new TestKestrelTrace()); var trace = new KestrelTrace(new TestKestrelTrace()); var ltp = new LoggingThreadPool(trace); - var socketOutput = new SocketOutput(kestrelThread, socket, memory, new MockConnection(), "0", trace, ltp, new Queue()); + var mockConnection = new MockConnection(); + var socketOutput = new SocketOutput(kestrelThread, socket, memory, mockConnection, "0", trace, ltp, new Queue()); var bufferSize = maxBytesPreCompleted; var buffer = new ArraySegment(new byte[bufferSize], 0, bufferSize); @@ -111,7 +112,9 @@ namespace Microsoft.AspNetCore.Server.KestrelTests // Too many bytes are already pre-completed for the second write to pre-complete. Assert.False(completedWh.Wait(1000)); // Act - completeQueue.Dequeue()(0); + Action triggerNextCompleted; + Assert.True(completeQueue.TryDequeue(out triggerNextCompleted)); + triggerNextCompleted(0); // Assert // Finishing the first write should allow the second write to pre-complete. Assert.True(completedWh.Wait(1000)); @@ -120,6 +123,9 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var cleanupTask = socketOutput.WriteAsync( default(ArraySegment), default(CancellationToken), socketDisconnect: true); + // Wait for all writes to complete so the completeQueue isn't modified during enumeration. + Assert.True(mockConnection.SocketClosed.Wait(1000)); + foreach (var triggerCompleted in completeQueue) { triggerCompleted(0); @@ -132,7 +138,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { // This should match _maxBytesPreCompleted in SocketOutput var maxBytesPreCompleted = 65536; - var completeQueue = new Queue>(); + var completeQueue = new ConcurrentQueue>(); var writeRequestedWh = new ManualResetEventSlim(); // Arrange @@ -155,7 +161,8 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var socket = new MockSocket(mockLibuv, kestrelThread.Loop.ThreadId, new TestKestrelTrace()); var trace = new KestrelTrace(new TestKestrelTrace()); var ltp = new LoggingThreadPool(trace); - var socketOutput = new SocketOutput(kestrelThread, socket, memory, new MockConnection(), "0", trace, ltp, new Queue()); + var mockConnection = new MockConnection(); + var socketOutput = new SocketOutput(kestrelThread, socket, memory, mockConnection, "0", trace, ltp, new Queue()); var bufferSize = maxBytesPreCompleted / 2; var data = new byte[bufferSize]; @@ -185,7 +192,9 @@ namespace Microsoft.AspNetCore.Server.KestrelTests Assert.Equal(2, completeQueue.Count); // Act - completeQueue.Dequeue()(0); + Action triggerNextCompleted; + Assert.True(completeQueue.TryDequeue(out triggerNextCompleted)); + triggerNextCompleted(0); // Assert // Finishing the first write should allow the second write to pre-complete. @@ -195,6 +204,9 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var cleanupTask = socketOutput.WriteAsync( default(ArraySegment), default(CancellationToken), socketDisconnect: true); + // Wait for all writes to complete so the completeQueue isn't modified during enumeration. + Assert.True(mockConnection.SocketClosed.Wait(1000)); + foreach (var triggerCompleted in completeQueue) { triggerCompleted(0); @@ -207,7 +219,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { // This should match _maxBytesPreCompleted in SocketOutput var maxBytesPreCompleted = 65536; - var completeQueue = new Queue>(); + var completeQueue = new ConcurrentQueue>(); // Arrange var mockLibuv = new MockLibuv @@ -298,12 +310,19 @@ namespace Microsoft.AspNetCore.Server.KestrelTests Assert.False(task6Success.IsCanceled); Assert.False(task6Success.IsFaulted); - Assert.True(true); - // Cleanup var cleanupTask = ((SocketOutput)socketOutput).WriteAsync( default(ArraySegment), default(CancellationToken), socketDisconnect: true); + // Allow for the socketDisconnect command to get posted to the libuv thread. + // Right now, the up to three pending writes are holding it up. + Action triggerNextCompleted; + Assert.True(completeQueue.TryDequeue(out triggerNextCompleted)); + triggerNextCompleted(0); + + // Wait for all writes to complete so the completeQueue isn't modified during enumeration. + Assert.True(mockConnection.SocketClosed.Wait(1000)); + foreach (var triggerCompleted in completeQueue) { triggerCompleted(0); @@ -317,7 +336,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { // This should match _maxBytesPreCompleted in SocketOutput var maxBytesPreCompleted = 65536; - var completeQueue = new Queue>(); + var completeQueue = new ConcurrentQueue>(); // Arrange var mockLibuv = new MockLibuv @@ -376,7 +395,9 @@ namespace Microsoft.AspNetCore.Server.KestrelTests Assert.False(task3Canceled.IsFaulted); // Cause the first write to fail. - completeQueue.Dequeue()(-1); + Action triggerNextCompleted; + Assert.True(completeQueue.TryDequeue(out triggerNextCompleted)); + triggerNextCompleted(-1); // Second task is now completed await task2Success; @@ -389,6 +410,9 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var cleanupTask = ((SocketOutput)socketOutput).WriteAsync( default(ArraySegment), default(CancellationToken), socketDisconnect: true); + // Wait for all writes to complete so the completeQueue isn't modified during enumeration. + Assert.True(mockConnection.SocketClosed.Wait(1000)); + foreach (var triggerCompleted in completeQueue) { triggerCompleted(0); @@ -402,7 +426,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { // This should match _maxBytesPreCompleted in SocketOutput var maxBytesPreCompleted = 65536; - var completeQueue = new Queue>(); + var completeQueue = new ConcurrentQueue>(); var onWriteWh = new ManualResetEventSlim(); // Arrange @@ -426,7 +450,8 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var socket = new MockSocket(mockLibuv, kestrelThread.Loop.ThreadId, new TestKestrelTrace()); var trace = new KestrelTrace(new TestKestrelTrace()); var ltp = new LoggingThreadPool(trace); - var socketOutput = new SocketOutput(kestrelThread, socket, memory, new MockConnection(), "0", trace, ltp, new Queue()); + var mockConnection = new MockConnection(); + var socketOutput = new SocketOutput(kestrelThread, socket, memory, mockConnection, "0", trace, ltp, new Queue()); var bufferSize = maxBytesPreCompleted; var buffer = new ArraySegment(new byte[bufferSize], 0, bufferSize); @@ -460,7 +485,9 @@ namespace Microsoft.AspNetCore.Server.KestrelTests socketOutput.WriteAsync(buffer, default(CancellationToken)).ContinueWith(onCompleted2); Assert.True(onWriteWh.Wait(1000)); - completeQueue.Dequeue()(0); + Action triggerNextCompleted; + Assert.True(completeQueue.TryDequeue(out triggerNextCompleted)); + triggerNextCompleted(0); // Assert // Too many bytes are already pre-completed for the third but not the second write to pre-complete. @@ -469,7 +496,8 @@ namespace Microsoft.AspNetCore.Server.KestrelTests Assert.False(completedWh2.Wait(1000)); // Act - completeQueue.Dequeue()(0); + Assert.True(completeQueue.TryDequeue(out triggerNextCompleted)); + triggerNextCompleted(0); // Assert // Finishing the first write should allow the second write to pre-complete. @@ -479,6 +507,9 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var cleanupTask = ((SocketOutput)socketOutput).WriteAsync( default(ArraySegment), default(CancellationToken), socketDisconnect: true); + // Wait for all writes to complete so the completeQueue isn't modified during enumeration. + Assert.True(mockConnection.SocketClosed.Wait(1000)); + foreach (var triggerCompleted in completeQueue) { triggerCompleted(0); @@ -543,7 +574,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests public void OnlyAllowsUpToThreeConcurrentWrites() { var writeWh = new ManualResetEventSlim(); - var completeQueue = new Queue>(); + var completeQueue = new ConcurrentQueue>(); var mockLibuv = new MockLibuv { @@ -564,7 +595,8 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var socket = new MockSocket(mockLibuv, kestrelThread.Loop.ThreadId, new TestKestrelTrace()); var trace = new KestrelTrace(new TestKestrelTrace()); var ltp = new LoggingThreadPool(trace); - var socketOutput = new SocketOutput(kestrelThread, socket, memory, new MockConnection(), "0", trace, ltp, new Queue()); + var mockConnection = new MockConnection(); + var socketOutput = new SocketOutput(kestrelThread, socket, memory, mockConnection, "0", trace, ltp, new Queue()); var buffer = new ArraySegment(new byte[1]); @@ -584,13 +616,22 @@ namespace Microsoft.AspNetCore.Server.KestrelTests Assert.False(writeWh.Wait(1000)); // Complete 1st write allowing uv_write to be triggered again - completeQueue.Dequeue()(0); + Action triggerNextCompleted; + Assert.True(completeQueue.TryDequeue(out triggerNextCompleted)); + triggerNextCompleted(0); Assert.True(writeWh.Wait(1000)); // Cleanup var cleanupTask = socketOutput.WriteAsync( default(ArraySegment), default(CancellationToken), socketDisconnect: true); + // Allow for the socketDisconnect command to get posted to the libuv thread. + // Right now, the three pending writes are holding it up. + Assert.True(completeQueue.TryDequeue(out triggerNextCompleted)); + triggerNextCompleted(0); + // Wait for all writes to complete so the completeQueue isn't modified during enumeration. + Assert.True(mockConnection.SocketClosed.Wait(1000)); + foreach (var triggerCompleted in completeQueue) { triggerCompleted(0); From 3bb7f4e2c407be65323150fe769613ae2edcbf9e Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Thu, 30 Jun 2016 15:48:32 -0700 Subject: [PATCH 0809/1662] Treat ECONNRESET as a connection error (#934). --- .../Internal/Http/Connection.cs | 9 +- .../Internal/Http/FrameOfT.cs | 4 +- .../Internal/Http/MessageBody.cs | 12 +- .../Internal/Http/SocketInput.cs | 67 ++++++--- .../Internal/Http/SocketInputExtensions.cs | 4 +- .../Internal/Infrastructure/Constants.cs | 18 --- .../KestrelServer.cs | 4 - .../RequestTests.cs | 139 +++++++++++++++++- .../project.json | 2 +- .../ConnectionTests.cs | 2 +- .../TestInput.cs | 2 +- 11 files changed, 202 insertions(+), 61 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Connection.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Connection.cs index f3eeac1bdd..c16ef2e652 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Connection.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Connection.cs @@ -282,7 +282,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } var normalRead = status > 0; - var normalDone = status == Constants.ECONNRESET || status == Constants.EOF; + var normalDone = status == Constants.EOF; var errorDone = !(normalDone || normalRead); var readCount = normalRead ? status : 0; @@ -293,13 +293,18 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http else { _socket.ReadStop(); - Log.ConnectionReadFin(ConnectionId); + + if (normalDone) + { + Log.ConnectionReadFin(ConnectionId); + } } Exception error = null; if (errorDone) { handle.Libuv.Check(status, out error); + Log.ConnectionError(ConnectionId, error); } _rawSocketInput.IncomingComplete(readCount, error); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameOfT.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameOfT.cs index f19f287075..ae77ca679b 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameOfT.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameOfT.cs @@ -34,7 +34,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { while (!_requestProcessingStopping && TakeStartLine(SocketInput) != RequestLineStatus.Done) { - if (SocketInput.RemoteIntakeFin) + if (SocketInput.CheckFinOrThrow()) { // We need to attempt to consume start lines and headers even after // SocketInput.RemoteIntakeFin is set to true to ensure we don't close a @@ -62,7 +62,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http while (!_requestProcessingStopping && !TakeMessageHeaders(SocketInput, FrameRequestHeaders)) { - if (SocketInput.RemoteIntakeFin) + if (SocketInput.CheckFinOrThrow()) { // We need to attempt to consume start lines and headers even after // SocketInput.RemoteIntakeFin is set to true to ensure we don't close a diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/MessageBody.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/MessageBody.cs index 5d0e37c29e..a96119cb58 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/MessageBody.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/MessageBody.cs @@ -239,7 +239,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { while (_mode == Mode.Prefix) { - var fin = input.RemoteIntakeFin; + var fin = input.CheckFinOrThrow(); ParseChunkedPrefix(input); @@ -257,7 +257,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http while (_mode == Mode.Extension) { - var fin = input.RemoteIntakeFin; + var fin = input.CheckFinOrThrow(); ParseExtension(input); @@ -275,7 +275,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http while (_mode == Mode.Data) { - var fin = input.RemoteIntakeFin; + var fin = input.CheckFinOrThrow(); int actual = ReadChunkedData(input, buffer.Array, buffer.Offset, buffer.Count); @@ -297,7 +297,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http while (_mode == Mode.Suffix) { - var fin = input.RemoteIntakeFin; + var fin = input.CheckFinOrThrow(); ParseChunkedSuffix(input); @@ -317,7 +317,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http // Chunks finished, parse trailers while (_mode == Mode.Trailer) { - var fin = input.RemoteIntakeFin; + var fin = input.CheckFinOrThrow(); ParseChunkedTrailer(input); @@ -337,7 +337,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { while (!_context.TakeMessageHeaders(input, _requestHeaders)) { - if (input.RemoteIntakeFin) + if (input.CheckFinOrThrow()) { if (_context.TakeMessageHeaders(input, _requestHeaders)) { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/SocketInput.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/SocketInput.cs index e093df9c8a..dae06a5ce0 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/SocketInput.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/SocketInput.cs @@ -22,7 +22,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http private readonly ManualResetEventSlim _manualResetEvent = new ManualResetEventSlim(false, 0); private Action _awaitableState; - private Exception _awaitableError; private MemoryPoolBlock _head; private MemoryPoolBlock _tail; @@ -33,6 +32,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http private bool _consuming; private bool _disposed; + private TaskCompletionSource _tcs = new TaskCompletionSource(); + public SocketInput(MemoryPool memory, IThreadPool threadPool, IBufferSizeControl bufferSizeControl = null) { _memory = memory; @@ -41,10 +42,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _awaitableState = _awaitableIsNotCompleted; } - public bool RemoteIntakeFin { get; set; } - public bool IsCompleted => ReferenceEquals(_awaitableState, _awaitableIsCompleted); + private bool ReadingInput => _tcs.Task.Status == TaskStatus.WaitingForActivation; + + public bool CheckFinOrThrow() + { + CheckConnectionError(); + return _tcs.Task.Status == TaskStatus.RanToCompletion; + } + public MemoryPoolBlock IncomingStart() { const int minimumSize = 2048; @@ -87,7 +94,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } else { - RemoteIntakeFin = true; + FinReceived(); } Complete(); @@ -122,13 +129,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _pinned = null; } - if (count == 0) - { - RemoteIntakeFin = true; - } if (error != null) { - _awaitableError = error; + SetConnectionError(error); + } + else if (count == 0) + { + FinReceived(); } Complete(); @@ -216,8 +223,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if (!examined.IsDefault && examined.IsEnd && - RemoteIntakeFin == false && - _awaitableError == null) + ReadingInput) { _manualResetEvent.Reset(); @@ -252,8 +258,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http public void AbortAwaiting() { - _awaitableError = new TaskCanceledException("The request was aborted"); - + SetConnectionError(new TaskCanceledException("The request was aborted")); Complete(); } @@ -279,7 +284,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } else { - _awaitableError = new InvalidOperationException("Concurrent reads are not supported."); + SetConnectionError(new InvalidOperationException("Concurrent reads are not supported.")); Interlocked.Exchange( ref _awaitableState, @@ -303,15 +308,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { _manualResetEvent.Wait(); } - var error = _awaitableError; - if (error != null) - { - if (error is TaskCanceledException || error is InvalidOperationException) - { - throw error; - } - throw new IOException(error.Message, error); - } + + CheckConnectionError(); } public void Dispose() @@ -340,5 +338,28 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http returnBlock.Pool.Return(returnBlock); } } + + private void SetConnectionError(Exception error) + { + _tcs.TrySetException(error); + } + + private void FinReceived() + { + _tcs.TrySetResult(null); + } + + private void CheckConnectionError() + { + var error = _tcs.Task.Exception?.InnerException; + if (error != null) + { + if (error is TaskCanceledException || error is InvalidOperationException) + { + throw error; + } + throw new IOException(error.Message, error); + } + } } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/SocketInputExtensions.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/SocketInputExtensions.cs index af16744bf5..2ff1f4c037 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/SocketInputExtensions.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/SocketInputExtensions.cs @@ -11,7 +11,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { while (input.IsCompleted) { - var fin = input.RemoteIntakeFin; + var fin = input.CheckFinOrThrow(); var begin = input.ConsumingStart(); int actual; @@ -37,7 +37,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { await input; - var fin = input.RemoteIntakeFin; + var fin = input.CheckFinOrThrow(); var begin = input.ConsumingStart(); int actual; diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/Constants.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/Constants.cs index 2d270d9955..90f228de31 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/Constants.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/Constants.cs @@ -10,7 +10,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure public const int ListenBacklog = 128; public const int EOF = -4095; - public static readonly int? ECONNRESET = GetECONNRESET(); public static readonly int? EADDRINUSE = GetEADDRINUSE(); /// @@ -26,23 +25,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure public const string ServerName = "Kestrel"; - private static int? GetECONNRESET() - { - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) - { - return -4077; - } - else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) - { - return -104; - } - else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) - { - return -54; - } - return null; - } - private static int? GetEADDRINUSE() { if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServer.cs b/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServer.cs index 3a38ce6df6..034d41e29e 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServer.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServer.cs @@ -92,10 +92,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel "ThreadCount must be positive."); } - if (!Constants.ECONNRESET.HasValue) - { - _logger.LogWarning("Unable to determine ECONNRESET value on this platform."); - } if (!Constants.EADDRINUSE.HasValue) { _logger.LogWarning("Unable to determine EADDRINUSE value on this platform."); diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs index a01b84f7b8..4459423a3d 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs @@ -2,17 +2,23 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Collections.Generic; using System.Globalization; using System.IO; +using System.Linq; using System.Net; using System.Net.Http; using System.Net.Sockets; using System.Text; +using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; +using Microsoft.AspNetCore.Testing; using Microsoft.AspNetCore.Testing.xunit; +using Microsoft.Extensions.Logging.Testing; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using Xunit; @@ -184,6 +190,102 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } } + [Fact] + public async Task ConnectionResetAbortsRequest() + { + var connectionErrorLogged = new SemaphoreSlim(0); + var testSink = new ConnectionErrorTestSink(() => connectionErrorLogged.Release()); + var builder = new WebHostBuilder() + .UseLoggerFactory(new TestLoggerFactory(testSink, true)) + .UseKestrel() + .UseUrls($"http://127.0.0.1:0") + .Configure(app => app.Run(context => + { + return Task.FromResult(0); + })); + + using (var host = builder.Build()) + { + host.Start(); + + using (var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)) + { + socket.Connect(new IPEndPoint(IPAddress.Loopback, host.GetPort())); + socket.LingerState = new LingerOption(true, 0); + } + + // Wait until connection error is logged + Assert.True(await connectionErrorLogged.WaitAsync(2500)); + + // Check for expected message + Assert.NotNull(testSink.ConnectionErrorMessage); + Assert.Contains("ECONNRESET", testSink.ConnectionErrorMessage); + } + } + + [Fact] + public async Task ThrowsOnReadAfterConnectionError() + { + var requestStarted = new SemaphoreSlim(0); + var connectionReset = new SemaphoreSlim(0); + var appDone = new SemaphoreSlim(0); + var expectedExceptionThrown = false; + + var builder = new WebHostBuilder() + .UseKestrel() + .UseUrls($"http://127.0.0.1:0") + .Configure(app => app.Run(async context => + { + requestStarted.Release(); + Assert.True(await connectionReset.WaitAsync(2500)); + + try + { + await context.Request.Body.ReadAsync(new byte[1], 0, 1); + } + catch (BadHttpRequestException) + { + // We need this here because BadHttpRequestException derives from IOException, + // and we're looking for an actual IOException. + } + catch (IOException ex) + { + // This is one of two exception types that might thrown in this scenario. + // An IOException is thrown if ReadAsync is awaiting on SocketInput when + // the connection is aborted. + expectedExceptionThrown = ex.InnerException is UvException; + } + catch (TaskCanceledException) + { + // This is the other exception type that might be thrown here. + // A TaskCanceledException is thrown if ReadAsync is called when the + // connection has already been aborted, since FrameRequestStream is + // aborted and returns a canceled task from ReadAsync. + expectedExceptionThrown = true; + } + + appDone.Release(); + })); + + using (var host = builder.Build()) + { + host.Start(); + + using (var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)) + { + socket.Connect(new IPEndPoint(IPAddress.Loopback, host.GetPort())); + socket.LingerState = new LingerOption(true, 0); + socket.Send(Encoding.ASCII.GetBytes("GET / HTTP/1.1\r\nContent-Length: 1\r\n\r\n")); + Assert.True(await requestStarted.WaitAsync(2500)); + } + + connectionReset.Release(); + + Assert.True(await appDone.WaitAsync(2500)); + Assert.True(expectedExceptionThrown); + } + } + private async Task TestRemoteIPAddress(string registerAddress, string requestAddress, string expectAddress) { var builder = new WebHostBuilder() @@ -220,5 +322,40 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests Assert.NotEmpty(facts["RemotePort"].Value()); } } + + private class ConnectionErrorTestSink : ITestSink + { + private readonly Action _connectionErrorLogged; + + public ConnectionErrorTestSink(Action connectionErrorLogged) + { + _connectionErrorLogged = connectionErrorLogged; + } + + public string ConnectionErrorMessage { get; set; } + + public Func BeginEnabled { get; set; } + + public List Scopes { get; set; } + + public Func WriteEnabled { get; set; } + + public List Writes { get; set; } + + public void Begin(BeginScopeContext context) + { + } + + public void Write(WriteContext context) + { + const int connectionErrorEventId = 14; + + if (context.EventId.Id == connectionErrorEventId) + { + ConnectionErrorMessage = context.Exception?.Message; + _connectionErrorLogged(); + } + } + } } -} +} \ No newline at end of file diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json index 9b247ae340..c2d82b3f4c 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json @@ -6,7 +6,7 @@ "Microsoft.AspNetCore.Server.Kestrel": "1.1.0-*", "Microsoft.AspNetCore.Server.Kestrel.Https": "1.1.0-*", "Microsoft.AspNetCore.Testing": "1.1.0-*", - "Microsoft.Extensions.Logging.Console": "1.1.0-*", + "Microsoft.Extensions.Logging.Testing": "1.1.0-*", "Newtonsoft.Json": "9.0.1", "xunit": "2.2.0-*" }, diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionTests.cs index f6b43c2d13..261bb47068 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionTests.cs @@ -38,7 +38,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests Libuv.uv_buf_t ignored; mockLibuv.AllocCallback(socket.InternalGetHandle(), 2048, out ignored); mockLibuv.ReadCallback(socket.InternalGetHandle(), 0, ref ignored); - Assert.False(connection.SocketInput.RemoteIntakeFin); + Assert.False(connection.SocketInput.CheckFinOrThrow()); connection.ConnectionControl.End(ProduceEndType.SocketDisconnect); } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestInput.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/TestInput.cs index a868068b5c..08106ed1c0 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/TestInput.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/TestInput.cs @@ -40,7 +40,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests FrameContext.SocketInput.IncomingData(data, 0, data.Length); if (fin) { - FrameContext.SocketInput.RemoteIntakeFin = true; + FrameContext.SocketInput.IncomingFin(); } } From 142685c0fb8b219574377da01f9c2819f52ae094 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Fri, 15 Jul 2016 00:48:01 -0700 Subject: [PATCH 0810/1662] Remove state lock from Connection - Remove the state lock by creating the frame earlier - Set properties on the frame that need to be set before calling start. - Don't rely on the copy ctor of the *Context hierarchy to set *everything* --- .../Internal/Http/Connection.cs | 178 +++++------------- 1 file changed, 50 insertions(+), 128 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Connection.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Connection.cs index c16ef2e652..f2c0233744 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Connection.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Connection.cs @@ -35,13 +35,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http private FilteredStreamAdapter _filteredStreamAdapter; private Task _readInputTask; - private readonly SocketInput _rawSocketInput; - private readonly SocketOutput _rawSocketOutput; - - private readonly object _stateLock = new object(); - private ConnectionState _connectionState; private TaskCompletionSource _socketClosedTcs; - private BufferSizeControl _bufferSizeControl; public Connection(ListenerContext context, UvStreamHandle socket) : base(context) @@ -57,8 +51,17 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _bufferSizeControl = new BufferSizeControl(ServerOptions.MaxRequestBufferSize.Value, this, Thread); } - _rawSocketInput = new SocketInput(Memory, ThreadPool, _bufferSizeControl); - _rawSocketOutput = new SocketOutput(Thread, _socket, Memory, this, ConnectionId, Log, ThreadPool, WriteReqPool); + SocketInput = new SocketInput(Memory, ThreadPool, _bufferSizeControl); + SocketOutput = new SocketOutput(Thread, _socket, Memory, this, ConnectionId, Log, ThreadPool, WriteReqPool); + + var tcpHandle = _socket as UvTcpHandle; + if (tcpHandle != null) + { + RemoteEndPoint = tcpHandle.GetPeerIPEndPoint(); + LocalEndPoint = tcpHandle.GetSockIPEndPoint(); + } + + _frame = FrameFactory(this); } // Internal for testing @@ -73,35 +76,18 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http // Start socket prior to applying the ConnectionFilter _socket.ReadStart(_allocCallback, _readCallback, this); - var tcpHandle = _socket as UvTcpHandle; - if (tcpHandle != null) - { - RemoteEndPoint = tcpHandle.GetPeerIPEndPoint(); - LocalEndPoint = tcpHandle.GetSockIPEndPoint(); - } - // Don't initialize _frame until SocketInput and SocketOutput are set to their final values. if (ServerOptions.ConnectionFilter == null) { - lock (_stateLock) - { - if (_connectionState != ConnectionState.CreatingFrame) - { - throw new InvalidOperationException("Invalid connection state: " + _connectionState); - } + _frame.SocketInput = SocketInput; + _frame.SocketOutput = SocketOutput; - _connectionState = ConnectionState.Open; + _frame.Start(); - SocketInput = _rawSocketInput; - SocketOutput = _rawSocketOutput; - - _frame = CreateFrame(); - _frame.Start(); - } } else { - _libuvStream = new LibuvStream(_rawSocketInput, _rawSocketOutput); + _libuvStream = new LibuvStream(SocketInput, SocketOutput); _filterContext = new ConnectionFilterContext { @@ -141,24 +127,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http public Task StopAsync() { - lock (_stateLock) + if (_socketClosedTcs == null) { - switch (_connectionState) - { - case ConnectionState.SocketClosed: - return TaskUtilities.CompletedTask; - case ConnectionState.CreatingFrame: - _connectionState = ConnectionState.ToDisconnect; - break; - case ConnectionState.Open: - _frame.Stop(); - SocketInput.CompleteAwaiting(); - break; - } - _socketClosedTcs = new TaskCompletionSource(); - return _socketClosedTcs.Task; + + _frame.Stop(); + _frame.SocketInput.CompleteAwaiting(); } + + return _socketClosedTcs.Task; } public virtual void Abort() @@ -168,18 +145,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http ThreadPool.Run(() => { var connection = this; - - lock (connection._stateLock) - { - if (connection._connectionState == ConnectionState.CreatingFrame) - { - connection._connectionState = ConnectionState.ToDisconnect; - } - else - { - connection._frame?.Abort(); - } - } + connection._frame.Abort(); }); } @@ -189,65 +155,45 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if (_filteredStreamAdapter != null) { _filteredStreamAdapter.Abort(); - _rawSocketInput.IncomingFin(); + SocketInput.IncomingFin(); _readInputTask.ContinueWith((task, state) => { ((Connection)state)._filterContext.Connection.Dispose(); ((Connection)state)._filteredStreamAdapter.Dispose(); - ((Connection)state)._rawSocketInput.Dispose(); + ((Connection)state).SocketInput.Dispose(); }, this); } else { - _rawSocketInput.Dispose(); + SocketInput.Dispose(); } - lock (_stateLock) - { - _connectionState = ConnectionState.SocketClosed; - - if (_socketClosedTcs != null) - { - // This is always waited on synchronously, so it's safe to - // call on the libuv thread. - _socketClosedTcs.TrySetResult(null); - } - } + _socketClosedTcs?.TrySetResult(null); } private void ApplyConnectionFilter() { - lock (_stateLock) + if (_filterContext.Connection != _libuvStream) { - if (_connectionState == ConnectionState.CreatingFrame) - { - _connectionState = ConnectionState.Open; + _filteredStreamAdapter = new FilteredStreamAdapter(ConnectionId, _filterContext.Connection, Memory, Log, ThreadPool, _bufferSizeControl); - if (_filterContext.Connection != _libuvStream) - { - _filteredStreamAdapter = new FilteredStreamAdapter(ConnectionId, _filterContext.Connection, Memory, Log, ThreadPool, _bufferSizeControl); + _frame.SocketInput = _filteredStreamAdapter.SocketInput; + _frame.SocketOutput = _filteredStreamAdapter.SocketOutput; - SocketInput = _filteredStreamAdapter.SocketInput; - SocketOutput = _filteredStreamAdapter.SocketOutput; - - _readInputTask = _filteredStreamAdapter.ReadInputAsync(); - } - else - { - SocketInput = _rawSocketInput; - SocketOutput = _rawSocketOutput; - } - - PrepareRequest = _filterContext.PrepareRequest; - - _frame = CreateFrame(); - _frame.Start(); - } - else - { - ConnectionControl.End(ProduceEndType.SocketDisconnect); - } + _readInputTask = _filteredStreamAdapter.ReadInputAsync(); } + else + { + _frame.SocketInput = SocketInput; + _frame.SocketOutput = SocketOutput; + } + + _frame.PrepareRequest = _filterContext.PrepareRequest; + + // Reset needs to be called here so prepare request gets applied + _frame.Reset(); + + _frame.Start(); } private static Libuv.uv_buf_t AllocCallback(UvStreamHandle handle, int suggestedSize, object state) @@ -257,7 +203,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http private Libuv.uv_buf_t OnAlloc(UvStreamHandle handle, int suggestedSize) { - var result = _rawSocketInput.IncomingStart(); + var result = SocketInput.IncomingStart(); return handle.Libuv.buf_init( result.DataArrayPtr + result.End, @@ -277,7 +223,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http // there is no data to be read right now. // See the note at http://docs.libuv.org/en/v1.x/stream.html#c.uv_read_cb. // We need to clean up whatever was allocated by OnAlloc. - _rawSocketInput.IncomingDeferred(); + SocketInput.IncomingDeferred(); return; } @@ -307,7 +253,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http Log.ConnectionError(ConnectionId, error); } - _rawSocketInput.IncomingComplete(readCount, error); + SocketInput.IncomingComplete(readCount, error); if (errorDone) { @@ -338,7 +284,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http // ReadStart() can throw a UvException in some cases (e.g. socket is no longer connected). // This should be treated the same as OnRead() seeing a "normalDone" condition. Log.ConnectionReadFin(ConnectionId); - _rawSocketInput.IncomingComplete(0, null); + SocketInput.IncomingComplete(0, null); } } @@ -347,28 +293,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http switch (endType) { case ProduceEndType.ConnectionKeepAlive: - if (_connectionState != ConnectionState.Open) - { - return; - } - Log.ConnectionKeepAlive(ConnectionId); break; case ProduceEndType.SocketShutdown: case ProduceEndType.SocketDisconnect: - lock (_stateLock) - { - if (_connectionState == ConnectionState.Disconnecting || - _connectionState == ConnectionState.SocketClosed) - { - return; - } - _connectionState = ConnectionState.Disconnecting; - - Log.ConnectionDisconnect(ConnectionId); - _rawSocketOutput.End(endType); - break; - } + Log.ConnectionDisconnect(ConnectionId); + ((SocketOutput)SocketOutput).End(endType); + break; } } @@ -398,14 +329,5 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http // string ctor overload that takes char* return new string(charBuffer, 0, 13); } - - private enum ConnectionState - { - CreatingFrame, - ToDisconnect, - Open, - Disconnecting, - SocketClosed - } } } From 14717f2a3ffbd5bb624c69fab42701e06ce05871 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Fri, 15 Jul 2016 00:58:59 -0700 Subject: [PATCH 0811/1662] Always allocate the socket closed tcs --- .../Internal/Http/Connection.cs | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Connection.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Connection.cs index f2c0233744..82bff4c48e 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Connection.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Connection.cs @@ -35,7 +35,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http private FilteredStreamAdapter _filteredStreamAdapter; private Task _readInputTask; - private TaskCompletionSource _socketClosedTcs; + private TaskCompletionSource _socketClosedTcs = new TaskCompletionSource(); private BufferSizeControl _bufferSizeControl; public Connection(ListenerContext context, UvStreamHandle socket) : base(context) @@ -127,13 +127,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http public Task StopAsync() { - if (_socketClosedTcs == null) - { - _socketClosedTcs = new TaskCompletionSource(); - - _frame.Stop(); - _frame.SocketInput.CompleteAwaiting(); - } + _frame.Stop(); + _frame.SocketInput.CompleteAwaiting(); return _socketClosedTcs.Task; } @@ -168,7 +163,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http SocketInput.Dispose(); } - _socketClosedTcs?.TrySetResult(null); + _socketClosedTcs.TrySetResult(null); } private void ApplyConnectionFilter() From 8399910a6e4826902c512d0ffb7c1890670bbf83 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Fri, 15 Jul 2016 15:14:25 -0700 Subject: [PATCH 0812/1662] PR feedback --- .../Internal/Http/Connection.cs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Connection.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Connection.cs index 82bff4c48e..024e79246b 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Connection.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Connection.cs @@ -29,7 +29,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http private static long _lastConnectionId = DateTime.UtcNow.Ticks; private readonly UvStreamHandle _socket; - private Frame _frame; + private readonly Frame _frame; private ConnectionFilterContext _filterContext; private LibuvStream _libuvStream; private FilteredStreamAdapter _filteredStreamAdapter; @@ -83,7 +83,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _frame.SocketOutput = SocketOutput; _frame.Start(); - } else { @@ -139,8 +138,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http // called from a libuv thread. ThreadPool.Run(() => { - var connection = this; - connection._frame.Abort(); + _frame.Abort(); }); } From 41e50ba688c740f54a855c4b9893b42c29ac7040 Mon Sep 17 00:00:00 2001 From: Mike Harder Date: Mon, 18 Jul 2016 12:38:19 -0700 Subject: [PATCH 0813/1662] Enable all tests in HttpsConnectionFilterTests to run on all platforms - Move HttpClientSlim.cs to test\shared - Change HttpClientSlim to static class to simplify calling code - Add HttpClientSlim.PostAsync() --- KestrelHttpServer.sln | 8 +- .../AddressRegistrationTests.cs | 4 +- .../HttpClientSlim.cs | 88 ------------ .../HttpClientSlimTests.cs | 106 ++++++++++++++ .../IWebHostPortExtensions.cs | 7 +- .../project.json | 5 + .../HttpsConnectionFilterTests.cs | 94 +++---------- .../project.json | 5 + test/shared/HttpClientSlim.cs | 129 ++++++++++++++++++ 9 files changed, 278 insertions(+), 168 deletions(-) delete mode 100644 test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/HttpClientSlim.cs create mode 100644 test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/HttpClientSlimTests.cs create mode 100644 test/shared/HttpClientSlim.cs diff --git a/KestrelHttpServer.sln b/KestrelHttpServer.sln index c55af22354..7615861212 100644 --- a/KestrelHttpServer.sln +++ b/KestrelHttpServer.sln @@ -1,6 +1,6 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 14 -VisualStudioVersion = 14.0.25123.0 +VisualStudioVersion = 14.0.25420.1 MinimumVisualStudioVersion = 10.0.40219.1 Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNetCore.Server.Kestrel", "src\Microsoft.AspNetCore.Server.Kestrel\Microsoft.AspNetCore.Server.Kestrel.xproj", "{F510611A-3BEE-4B88-A613-5F4A74ED82A1}" EndProject @@ -32,6 +32,11 @@ Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNetCore.Server EndProject Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNetCore.Server.Kestrel.FunctionalTests", "test\Microsoft.AspNetCore.Server.Kestrel.FunctionalTests\Microsoft.AspNetCore.Server.Kestrel.FunctionalTests.xproj", "{9559A5F1-080C-4909-B6CF-7E4B3DC55748}" EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "shared", "shared", "{0EF2ACDF-012F-4472-A13A-4272419E2903}" + ProjectSection(SolutionItems) = preProject + test\shared\HttpClientSlim.cs = test\shared\HttpClientSlim.cs + EndProjectSection +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -78,5 +83,6 @@ Global {BD2D4D29-1BD9-40D0-BB31-337D5416B63C} = {327F7880-D9AF-46BD-B45C-3B7E34A01DFD} {5F64B3C3-0C2E-431A-B820-A81BBFC863DA} = {2D5D5227-4DBD-499A-96B1-76A36B03B750} {9559A5F1-080C-4909-B6CF-7E4B3DC55748} = {D3273454-EA07-41D2-BF0B-FCC3675C2483} + {0EF2ACDF-012F-4472-A13A-4272419E2903} = {D3273454-EA07-41D2-BF0B-FCC3675C2483} EndGlobalSection EndGlobal diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs index 24ed52ff81..a438309246 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs @@ -14,6 +14,7 @@ using Microsoft.AspNetCore.Hosting.Server.Features; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http.Extensions; using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; +using Microsoft.AspNetCore.Testing; using Microsoft.AspNetCore.Testing.xunit; using Xunit; @@ -85,10 +86,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { host.Start(); - var client = new HttpClientSlim() { ValidateCertificate = false }; foreach (var testUrl in testUrls(host.ServerFeatures.Get())) { - var response = await client.GetStringAsync(testUrl); + var response = await HttpClientSlim.GetStringAsync(testUrl, validateCertificate: false); // Compare the response with Uri.ToString(), rather than testUrl directly. // Required to handle IPv6 addresses with zone index, like "fe80::3%1" diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/HttpClientSlim.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/HttpClientSlim.cs deleted file mode 100644 index 8775f93eff..0000000000 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/HttpClientSlim.cs +++ /dev/null @@ -1,88 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using System.IO; -using System.Net; -using System.Net.Security; -using System.Net.Sockets; -using System.Security.Authentication; -using System.Text; -using System.Threading.Tasks; - -namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests -{ - // Lightweight version of HttpClient implemented using Socket and SslStream - public class HttpClientSlim - { - public bool ValidateCertificate { get; set; } = true; - - public Task GetStringAsync(string requestUri) => GetStringAsync(new Uri(requestUri)); - - public async Task GetStringAsync(Uri requestUri) - { - using (var stream = await GetStream(requestUri)) - { - using (var writer = new StreamWriter(stream, Encoding.ASCII, bufferSize: 1024, leaveOpen: true)) - { - await writer.WriteAsync($"GET {requestUri.PathAndQuery} HTTP/1.0\r\n"); - await writer.WriteAsync($"Host: {requestUri.Authority}\r\n"); - await writer.WriteAsync("\r\n"); - } - - using (var reader = new StreamReader(stream, Encoding.ASCII)) - { - var response = await reader.ReadToEndAsync(); - var body = response.Substring(response.IndexOf("\r\n\r\n") + 4); - return body; - } - } - } - - private async Task GetStream(Uri requestUri) - { - var socket = await GetSocket(requestUri); - Stream stream = new NetworkStream(socket, ownsSocket: true); - - if (requestUri.Scheme.Equals("https", StringComparison.OrdinalIgnoreCase)) - { - var sslStream = new SslStream(stream, leaveInnerStreamOpen: false, userCertificateValidationCallback: - ValidateCertificate ? null : (RemoteCertificateValidationCallback)((a, b, c, d) => true)); - await sslStream.AuthenticateAsClientAsync(requestUri.Host, clientCertificates: null, - enabledSslProtocols: SslProtocols.Tls11 | SslProtocols.Tls12, - checkCertificateRevocation: ValidateCertificate); - return sslStream; - } - else - { - return stream; - } - } - - private static async Task GetSocket(Uri requestUri) - { - var tcs = new TaskCompletionSource(); - - var socketArgs = new SocketAsyncEventArgs(); - socketArgs.RemoteEndPoint = new DnsEndPoint(requestUri.DnsSafeHost, requestUri.Port); - socketArgs.Completed += (s, e) => tcs.TrySetResult(e.ConnectSocket); - - // Must use static ConnectAsync(), since instance Connect() does not support DNS names on OSX/Linux. - if (Socket.ConnectAsync(SocketType.Stream, ProtocolType.Tcp, socketArgs)) - { - await tcs.Task; - } - - var socket = socketArgs.ConnectSocket; - - if (socket == null) - { - throw new SocketException((int)socketArgs.SocketError); - } - else - { - return socket; - } - } - } -} diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/HttpClientSlimTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/HttpClientSlimTests.cs new file mode 100644 index 0000000000..913f160902 --- /dev/null +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/HttpClientSlimTests.cs @@ -0,0 +1,106 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.IO; +using System.Linq; +using System.Net.Http; +using System.Text; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Testing; +using Xunit; + +namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests +{ + public class HttpClientSlimTests + { + [Fact] + public async Task GetStringAsyncHttp() + { + using (var host = StartHost()) + { + Assert.Equal("test", await HttpClientSlim.GetStringAsync(host.GetUri())); + } + } + + [Fact] + public async Task GetStringAsyncHttps() + { + using (var host = StartHost(protocol: "https")) + { + Assert.Equal("test", await HttpClientSlim.GetStringAsync(host.GetUri(), validateCertificate: false)); + } + } + + [Fact] + public async Task GetStringAsyncThrowsForErrorResponse() + { + using (var host = StartHost(statusCode: 500)) + { + await Assert.ThrowsAnyAsync(() => HttpClientSlim.GetStringAsync(host.GetUri())); + } + } + + [Fact] + public async Task PostAsyncHttp() + { + using (var host = StartHost(handler: (context) => context.Request.Body.CopyToAsync(context.Response.Body))) + { + Assert.Equal("test post", await HttpClientSlim.PostAsync(host.GetUri(), new StringContent("test post"))); + } + } + + [Fact] + public async Task PostAsyncHttps() + { + using (var host = StartHost(protocol: "https", + handler: (context) => context.Request.Body.CopyToAsync(context.Response.Body))) + { + Assert.Equal("test post", await HttpClientSlim.PostAsync(host.GetUri(), + new StringContent("test post"), validateCertificate: false)); + } + } + + [Fact] + public async Task PostAsyncThrowsForErrorResponse() + { + using (var host = StartHost(statusCode: 500)) + { + await Assert.ThrowsAnyAsync( + () => HttpClientSlim.PostAsync(host.GetUri(), new StringContent(""))); + } + } + + private IWebHost StartHost(string protocol = "http", int statusCode = 200, Func handler = null) + { + var host = new WebHostBuilder() + .UseUrls($"{protocol}://127.0.0.1:0") + .UseKestrel(options => + { + options.UseHttps(@"TestResources/testCert.pfx", "testPassword"); + }) + .Configure((app) => + { + app.Run(context => + { + context.Response.StatusCode = statusCode; + if (handler == null) + { + return context.Response.WriteAsync("test"); + } + else + { + return handler(context); + } + }); + }) + .Build(); + + host.Start(); + return host; + } + } +} diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/IWebHostPortExtensions.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/IWebHostPortExtensions.cs index 625a10a7af..f2702be8f7 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/IWebHostPortExtensions.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/IWebHostPortExtensions.cs @@ -12,7 +12,7 @@ namespace Microsoft.AspNetCore.Hosting { public static string GetHost(this IWebHost host) { - return host.GetUris().First().Host; + return host.GetUri().Host; } public static int GetPort(this IWebHost host) @@ -40,5 +40,10 @@ namespace Microsoft.AspNetCore.Hosting .Select(a => a.Replace("://+", "://localhost")) .Select(a => new Uri(a)); } + + public static Uri GetUri(this IWebHost host) + { + return host.GetUris().First(); + } } } diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json index c2d82b3f4c..07b88977b3 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json @@ -31,6 +31,11 @@ }, "buildOptions": { "allowUnsafe": true, + "compile": { + "include": [ + "../shared/**/*.cs" + ] + }, "copyToOutput": { "include": "TestResources/testCert.pfx" } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/HttpsConnectionFilterTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/HttpsConnectionFilterTests.cs index 7946845290..a0ae26490b 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/HttpsConnectionFilterTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/HttpsConnectionFilterTests.cs @@ -4,7 +4,6 @@ using System; using System.Collections.Generic; using System.IO; -using System.Net; using System.Net.Http; using System.Net.Security; using System.Net.Sockets; @@ -17,47 +16,19 @@ using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Server.Kestrel.Filter; using Microsoft.AspNetCore.Server.Kestrel.Https; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; -using Microsoft.AspNetCore.Testing.xunit; +using Microsoft.AspNetCore.Testing; using Xunit; namespace Microsoft.AspNetCore.Server.KestrelTests { - public class HttpsConnectionFilterTests : IDisposable + public class HttpsConnectionFilterTests { private static string _serverAddress = "https://127.0.0.1:0/"; - private static RemoteCertificateValidationCallback _alwaysValidCallback = - (sender, cert, chain, sslPolicyErrors) => true; private static X509Certificate2 _x509Certificate2 = new X509Certificate2(@"TestResources/testCert.pfx", "testPassword"); -#if NET451 - static HttpsConnectionFilterTests() - { - // SecurityProtocolType values below not available in Mono < 4.3 - const int SecurityProtocolTypeTls11 = 768; - const int SecurityProtocolTypeTls12 = 3072; - ServicePointManager.SecurityProtocol |= (SecurityProtocolType)(SecurityProtocolTypeTls12 | SecurityProtocolTypeTls11); - } -#endif - - public HttpsConnectionFilterTests() - { -#if NET451 - ServicePointManager.ServerCertificateValidationCallback += _alwaysValidCallback; -#endif - } - - public void Dispose() - { -#if NET451 - ServicePointManager.ServerCertificateValidationCallback -= _alwaysValidCallback; -#endif - } - // https://github.com/aspnet/KestrelHttpServer/issues/240 // This test currently fails on mono because of an issue with SslStream. - [ConditionalFact] - [OSSkipCondition(OperatingSystems.Linux, SkipReason = "WinHttpHandler not available on non-Windows.")] - [OSSkipCondition(OperatingSystems.MacOSX, SkipReason = "WinHttpHandler not available on non-Windows.")] + [Fact] public async Task CanReadAndWriteWithHttpsConnectionFilter() { var serviceContext = new TestServiceContext(new HttpsConnectionFilter( @@ -68,20 +39,17 @@ namespace Microsoft.AspNetCore.Server.KestrelTests using (var server = new TestServer(App, serviceContext, _serverAddress)) { - using (var client = new HttpClient(GetHandler())) - { - var result = await client.PostAsync($"https://localhost:{server.Port}/", new FormUrlEncodedContent(new[] { - new KeyValuePair("content", "Hello World?") - })); + var result = await HttpClientSlim.PostAsync($"https://localhost:{server.Port}/", + new FormUrlEncodedContent(new[] { + new KeyValuePair("content", "Hello World?") + }), + validateCertificate: false); - Assert.Equal("content=Hello+World%3F", await result.Content.ReadAsStringAsync()); - } + Assert.Equal("content=Hello+World%3F", result); } } - [ConditionalFact] - [OSSkipCondition(OperatingSystems.Linux, SkipReason = "WinHttpHandler not available on non-Windows.")] - [OSSkipCondition(OperatingSystems.MacOSX, SkipReason = "WinHttpHandler not available on non-Windows.")] + [Fact] public async Task RequireCertificateFailsWhenNoCertificate() { var serviceContext = new TestServiceContext(new HttpsConnectionFilter( @@ -95,17 +63,12 @@ namespace Microsoft.AspNetCore.Server.KestrelTests using (var server = new TestServer(App, serviceContext, _serverAddress)) { - using (var client = new HttpClient(GetHandler())) - { - await Assert.ThrowsAnyAsync( - () => client.GetAsync($"https://localhost:{server.Port}/")); - } + await Assert.ThrowsAnyAsync( + () => HttpClientSlim.GetStringAsync($"https://localhost:{server.Port}/")); } } - [ConditionalFact] - [OSSkipCondition(OperatingSystems.Linux, SkipReason = "WinHttpHandler not available on non-Windows.")] - [OSSkipCondition(OperatingSystems.MacOSX, SkipReason = "WinHttpHandler not available on non-Windows.")] + [Fact] public async Task AllowCertificateContinuesWhenNoCertificate() { var serviceContext = new TestServiceContext(new HttpsConnectionFilter( @@ -124,12 +87,8 @@ namespace Microsoft.AspNetCore.Server.KestrelTests }, serviceContext, _serverAddress)) { - using (var client = new HttpClient(GetHandler())) - { - var result = await client.GetAsync($"https://localhost:{server.Port}/"); - - Assert.Equal("hello world", await result.Content.ReadAsStringAsync()); - } + var result = await HttpClientSlim.GetStringAsync($"https://localhost:{server.Port}/", validateCertificate: false); + Assert.Equal("hello world", result); } } @@ -203,9 +162,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } } - [ConditionalFact] - [OSSkipCondition(OperatingSystems.Linux, SkipReason = "WinHttpHandler not available on non-Windows.")] - [OSSkipCondition(OperatingSystems.MacOSX, SkipReason = "WinHttpHandler not available on non-Windows.")] + [Fact] public async Task HttpsSchemePassedToRequestFeature() { var serviceContext = new TestServiceContext( @@ -219,12 +176,8 @@ namespace Microsoft.AspNetCore.Server.KestrelTests using (var server = new TestServer(context => context.Response.WriteAsync(context.Request.Scheme), serviceContext, _serverAddress)) { - using (var client = new HttpClient(GetHandler())) - { - var result = await client.GetAsync($"https://localhost:{server.Port}/"); - - Assert.Equal("https", await result.Content.ReadAsStringAsync()); - } + var result = await HttpClientSlim.GetStringAsync($"https://localhost:{server.Port}/", validateCertificate: false); + Assert.Equal("https", result); } } @@ -423,16 +376,5 @@ namespace Microsoft.AspNetCore.Server.KestrelTests Assert.Null(line); } } - - private HttpMessageHandler GetHandler() - { -#if NET451 - return new HttpClientHandler(); -#else - var handler = new WinHttpHandler(); - handler.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true; - return handler; -#endif - } } } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/project.json b/test/Microsoft.AspNetCore.Server.KestrelTests/project.json index 9f10bec8ec..9354978969 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/project.json +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/project.json @@ -33,6 +33,11 @@ }, "buildOptions": { "allowUnsafe": true, + "compile": { + "include": [ + "../shared/**/*.cs" + ] + }, "keyFile": "../../tools/Key.snk", "copyToOutput": { "include": "TestResources/testCert.pfx" diff --git a/test/shared/HttpClientSlim.cs b/test/shared/HttpClientSlim.cs new file mode 100644 index 0000000000..a5d4d9caa2 --- /dev/null +++ b/test/shared/HttpClientSlim.cs @@ -0,0 +1,129 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.IO; +using System.Net; +using System.Net.Http; +using System.Net.Security; +using System.Net.Sockets; +using System.Security.Authentication; +using System.Text; +using System.Threading.Tasks; + +namespace Microsoft.AspNetCore.Testing +{ + // Lightweight version of HttpClient implemented using Socket and SslStream + public static class HttpClientSlim + { + public static Task GetStringAsync(string requestUri, bool validateCertificate = true) + => GetStringAsync(new Uri(requestUri), validateCertificate); + + public static async Task GetStringAsync(Uri requestUri, bool validateCertificate = true) + { + using (var stream = await GetStream(requestUri, validateCertificate)) + { + using (var writer = new StreamWriter(stream, Encoding.ASCII, bufferSize: 1024, leaveOpen: true)) + { + await writer.WriteAsync($"GET {requestUri.PathAndQuery} HTTP/1.0\r\n"); + await writer.WriteAsync($"Host: {requestUri.Authority}\r\n"); + await writer.WriteAsync("\r\n"); + } + + return await ReadResponse(stream); + } + } + + public static Task PostAsync(string requestUri, HttpContent content, bool validateCertificate = true) + => PostAsync(new Uri(requestUri), content, validateCertificate); + + public static async Task PostAsync(Uri requestUri, HttpContent content, bool validateCertificate = true) + { + using (var stream = await GetStream(requestUri, validateCertificate)) + { + using (var writer = new StreamWriter(stream, Encoding.ASCII, bufferSize: 1024, leaveOpen: true)) + { + await writer.WriteAsync($"POST {requestUri.PathAndQuery} HTTP/1.0\r\n"); + await writer.WriteAsync($"Host: {requestUri.Authority}\r\n"); + await writer.WriteAsync($"Content-Type: {content.Headers.ContentType}\r\n"); + await writer.WriteAsync($"Content-Length: {content.Headers.ContentLength}\r\n"); + await writer.WriteAsync("\r\n"); + } + + await content.CopyToAsync(stream); + + return await ReadResponse(stream); + } + } + + private static async Task ReadResponse(Stream stream) + { + using (var reader = new StreamReader(stream, Encoding.ASCII, detectEncodingFromByteOrderMarks: true, + bufferSize: 1024, leaveOpen: true)) + { + var response = await reader.ReadToEndAsync(); + + var status = GetStatus(response); + new HttpResponseMessage(status).EnsureSuccessStatusCode(); + + var body = response.Substring(response.IndexOf("\r\n\r\n") + 4); + return body; + } + + } + + private static HttpStatusCode GetStatus(string response) + { + var statusStart = response.IndexOf(' ') + 1; + var statusEnd = response.IndexOf(' ', statusStart) - 1; + var statusLength = statusEnd - statusStart + 1; + return (HttpStatusCode)int.Parse(response.Substring(statusStart, statusLength)); + } + + private static async Task GetStream(Uri requestUri, bool validateCertificate) + { + var socket = await GetSocket(requestUri); + Stream stream = new NetworkStream(socket, ownsSocket: true); + + if (requestUri.Scheme.Equals("https", StringComparison.OrdinalIgnoreCase)) + { + var sslStream = new SslStream(stream, leaveInnerStreamOpen: false, userCertificateValidationCallback: + validateCertificate ? null : (RemoteCertificateValidationCallback)((a, b, c, d) => true)); + await sslStream.AuthenticateAsClientAsync(requestUri.Host, clientCertificates: null, + enabledSslProtocols: SslProtocols.Tls11 | SslProtocols.Tls12, + checkCertificateRevocation: validateCertificate); + return sslStream; + } + else + { + return stream; + } + } + + private static async Task GetSocket(Uri requestUri) + { + var tcs = new TaskCompletionSource(); + + var socketArgs = new SocketAsyncEventArgs(); + socketArgs.RemoteEndPoint = new DnsEndPoint(requestUri.DnsSafeHost, requestUri.Port); + socketArgs.Completed += (s, e) => tcs.TrySetResult(e.ConnectSocket); + + // Must use static ConnectAsync(), since instance Connect() does not support DNS names on OSX/Linux. + if (Socket.ConnectAsync(SocketType.Stream, ProtocolType.Tcp, socketArgs)) + { + await tcs.Task; + } + + var socket = socketArgs.ConnectSocket; + + if (socket == null) + { + throw new SocketException((int)socketArgs.SocketError); + } + else + { + return socket; + } + } + } +} From bdf9f8dd4e27621c05fbfa302d96b719afc18ebd Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Sun, 17 Jul 2016 14:51:04 -0700 Subject: [PATCH 0814/1662] Wait for connection in RequestTests.ConnectionResetAbortsRequest (#978). --- .../RequestTests.cs | 30 +++++++++++++------ 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs index 4459423a3d..2040f5de35 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs @@ -5,7 +5,6 @@ using System; using System.Collections.Generic; using System.Globalization; using System.IO; -using System.Linq; using System.Net; using System.Net.Http; using System.Net.Sockets; @@ -16,7 +15,6 @@ using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; -using Microsoft.AspNetCore.Testing; using Microsoft.AspNetCore.Testing.xunit; using Microsoft.Extensions.Logging.Testing; using Newtonsoft.Json; @@ -27,6 +25,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { public class RequestTests { + private const int _semaphoreWaitTimeout = 2500; + [Theory] [InlineData(10 * 1024 * 1024, true)] // In the following dataset, send at least 2GB. @@ -193,8 +193,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [Fact] public async Task ConnectionResetAbortsRequest() { + var connectionStarted = new SemaphoreSlim(0); var connectionErrorLogged = new SemaphoreSlim(0); - var testSink = new ConnectionErrorTestSink(() => connectionErrorLogged.Release()); + var testSink = new ConnectionErrorTestSink( + () => connectionStarted.Release(), () => connectionErrorLogged.Release()); var builder = new WebHostBuilder() .UseLoggerFactory(new TestLoggerFactory(testSink, true)) .UseKestrel() @@ -211,11 +213,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests using (var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)) { socket.Connect(new IPEndPoint(IPAddress.Loopback, host.GetPort())); + // Wait until connection is established + Assert.True(await connectionStarted.WaitAsync(_semaphoreWaitTimeout)); + // Force a reset socket.LingerState = new LingerOption(true, 0); } // Wait until connection error is logged - Assert.True(await connectionErrorLogged.WaitAsync(2500)); + Assert.True(await connectionErrorLogged.WaitAsync(_semaphoreWaitTimeout)); // Check for expected message Assert.NotNull(testSink.ConnectionErrorMessage); @@ -237,7 +242,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests .Configure(app => app.Run(async context => { requestStarted.Release(); - Assert.True(await connectionReset.WaitAsync(2500)); + Assert.True(await connectionReset.WaitAsync(_semaphoreWaitTimeout)); try { @@ -276,12 +281,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests socket.Connect(new IPEndPoint(IPAddress.Loopback, host.GetPort())); socket.LingerState = new LingerOption(true, 0); socket.Send(Encoding.ASCII.GetBytes("GET / HTTP/1.1\r\nContent-Length: 1\r\n\r\n")); - Assert.True(await requestStarted.WaitAsync(2500)); + Assert.True(await requestStarted.WaitAsync(_semaphoreWaitTimeout)); } connectionReset.Release(); - Assert.True(await appDone.WaitAsync(2500)); + Assert.True(await appDone.WaitAsync(_semaphoreWaitTimeout)); Assert.True(expectedExceptionThrown); } } @@ -325,10 +330,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests private class ConnectionErrorTestSink : ITestSink { + private readonly Action _connectionStarted; private readonly Action _connectionErrorLogged; - public ConnectionErrorTestSink(Action connectionErrorLogged) + public ConnectionErrorTestSink(Action connectionStarted, Action connectionErrorLogged) { + _connectionStarted = connectionStarted; _connectionErrorLogged = connectionErrorLogged; } @@ -348,9 +355,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests public void Write(WriteContext context) { + const int connectionStartEventId = 1; const int connectionErrorEventId = 14; - if (context.EventId.Id == connectionErrorEventId) + if (context.EventId.Id == connectionStartEventId) + { + _connectionStarted(); + } + else if (context.EventId.Id == connectionErrorEventId) { ConnectionErrorMessage = context.Exception?.Message; _connectionErrorLogged(); From 3078f4914ce2511ae9105892fd93c02969756828 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Mon, 18 Jul 2016 22:19:45 -0700 Subject: [PATCH 0815/1662] Removed unneeded things from Connection --- .../Internal/Http/Connection.cs | 21 ++++--------------- 1 file changed, 4 insertions(+), 17 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Connection.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Connection.cs index 024e79246b..da2d7f9bc6 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Connection.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Connection.cs @@ -76,12 +76,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http // Start socket prior to applying the ConnectionFilter _socket.ReadStart(_allocCallback, _readCallback, this); - // Don't initialize _frame until SocketInput and SocketOutput are set to their final values. if (ServerOptions.ConnectionFilter == null) { - _frame.SocketInput = SocketInput; - _frame.SocketOutput = SocketOutput; - _frame.Start(); } else @@ -151,9 +147,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http SocketInput.IncomingFin(); _readInputTask.ContinueWith((task, state) => { - ((Connection)state)._filterContext.Connection.Dispose(); - ((Connection)state)._filteredStreamAdapter.Dispose(); - ((Connection)state).SocketInput.Dispose(); + var connection = (Connection)state; + connection._filterContext.Connection.Dispose(); + connection._filteredStreamAdapter.Dispose(); + connection.SocketInput.Dispose(); }, this); } else @@ -175,11 +172,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _readInputTask = _filteredStreamAdapter.ReadInputAsync(); } - else - { - _frame.SocketInput = SocketInput; - _frame.SocketOutput = SocketOutput; - } _frame.PrepareRequest = _filterContext.PrepareRequest; @@ -254,11 +246,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } } - private Frame CreateFrame() - { - return FrameFactory(this); - } - void IConnectionControl.Pause() { Log.ConnectionPause(ConnectionId); From 22f75a1e0027d1b141849dc3202d10ef3c0dbdb3 Mon Sep 17 00:00:00 2001 From: Pranav K Date: Tue, 19 Jul 2016 11:14:33 -0700 Subject: [PATCH 0816/1662] Pin the version of dotnet-test-xunit to 1.0.0-rc3-00000-01 --- .../project.json | 2 +- test/Microsoft.AspNetCore.Server.KestrelTests/project.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json index b1cebed064..d21afa6546 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json @@ -1,7 +1,7 @@ { "version": "1.0.0-*", "dependencies": { - "dotnet-test-xunit": "1.0.0-rc3-000000-00", + "dotnet-test-xunit": "1.0.0-rc3-000000-01", "Microsoft.AspNetCore.Http.Abstractions": "1.0.0", "Microsoft.AspNetCore.Server.Kestrel": "1.0.0", "Microsoft.AspNetCore.Server.Kestrel.Https": "1.0.0", diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/project.json b/test/Microsoft.AspNetCore.Server.KestrelTests/project.json index 5656d4e573..7928752b7e 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/project.json +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/project.json @@ -1,7 +1,7 @@ { "version": "1.0.0-*", "dependencies": { - "dotnet-test-xunit": "1.0.0-rc3-000000-00", + "dotnet-test-xunit": "1.0.0-rc3-000000-01", "Microsoft.AspNetCore.Server.Kestrel": "1.0.0", "Microsoft.AspNetCore.Server.Kestrel.Https": "1.0.0", "Microsoft.AspNetCore.Testing": "1.0.0-rtm-21431", From 7b8abf5a3e48bec80de26b91b2be39bfe83f45d4 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Wed, 20 Jul 2016 11:55:14 +0100 Subject: [PATCH 0817/1662] Improved Memoryblock tracking Also fixed 3 tests that weren't handling block properly --- .../Internal/Infrastructure/MemoryPool.cs | 49 +++++++++++++++++-- .../Infrastructure/MemoryPoolBlock.cs | 11 ++++- .../Internal/Infrastructure/MemoryPoolSlab.cs | 4 +- .../Internal/KestrelEngine.cs | 5 ++ .../AsciiDecoding.cs | 7 ++- .../MemoryPoolIteratorTests.cs | 1 + 6 files changed, 69 insertions(+), 8 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPool.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPool.cs index 4641206872..589efeba3f 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPool.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPool.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Concurrent; using System.Diagnostics; +using System.Runtime.CompilerServices; namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure { @@ -60,20 +61,44 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure /// private bool _disposedValue = false; // To detect redundant calls +#if DEBUG + public MemoryPoolBlock Lease([CallerMemberName] string memberName = "", + [CallerFilePath] string sourceFilePath = "", + [CallerLineNumber] int sourceLineNumber = 0) + { + Debug.Assert(!_disposedValue, "Block being leased from disposed pool!"); +#else + /// /// Called to take a block from the pool. /// /// The block that is reserved for the called. It must be passed to Return when it is no longer being used. public MemoryPoolBlock Lease() { +#endif MemoryPoolBlock block; if (_blocks.TryDequeue(out block)) { // block successfully taken from the stack - return it +#if DEBUG + block.Leaser = memberName + ", " + sourceFilePath + ", " + sourceLineNumber; + block.IsLeased = true; +#if !NETSTANDARD1_3 + block.StackTrace = new StackTrace(true).ToString(); +#endif +#endif return block; } // no blocks available - grow the pool - return AllocateSlab(); + block = AllocateSlab(); +#if DEBUG + block.Leaser = memberName + ", " + sourceFilePath + ", " + sourceLineNumber; + block.IsLeased = true; +#if !NETSTANDARD1_3 + block.StackTrace = new StackTrace(true).ToString(); +#endif +#endif + return block; } /// @@ -100,6 +125,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure basePtr, this, slab); +#if DEBUG + block.IsLeased = true; +#endif Return(block); } @@ -123,19 +151,33 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure /// The block to return. It must have been acquired by calling Lease on the same memory pool instance. public void Return(MemoryPoolBlock block) { +#if DEBUG Debug.Assert(block.Pool == this, "Returned block was not leased from this pool"); + Debug.Assert(block.IsLeased, "Block being returned to pool twice: " + block.Leaser + "\n" + block.StackTrace); + block.IsLeased = false; +#endif if (block.Slab != null && block.Slab.IsActive) { block.Reset(); _blocks.Enqueue(block); } + else + { + GC.SuppressFinalize(block); + } } protected virtual void Dispose(bool disposing) { if (!_disposedValue) { + _disposedValue = true; +#if DEBUG + GC.Collect(); + GC.WaitForPendingFinalizers(); + GC.Collect(); +#endif if (disposing) { MemoryPoolSlab slab; @@ -146,7 +188,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure } } - foreach (var block in _blocks) + // Discard blocks in pool + MemoryPoolBlock block; + while (_blocks.TryDequeue(out block)) { GC.SuppressFinalize(block); } @@ -155,7 +199,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure // N/A: set large fields to null. - _disposedValue = true; } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolBlock.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolBlock.cs index 52f6825a77..8b03dee1da 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolBlock.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolBlock.cs @@ -71,10 +71,17 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure /// public MemoryPoolBlock Next; +#if DEBUG + public bool IsLeased { get; set; } + public string Leaser { get; set; } + public string StackTrace { get; set; } +#endif + ~MemoryPoolBlock() { - Debug.Assert(Slab == null || !Slab.IsActive, "Block being garbage collected instead of returned to pool"); - +#if DEBUG + Debug.Assert(Slab == null || !Slab.IsActive, "Block being garbage collected instead of returned to pool: " + Leaser + "\n" + StackTrace); +#endif if (Slab != null && Slab.IsActive) { Pool.Return(new MemoryPoolBlock(DataArrayPtr) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolSlab.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolSlab.cs index e61b12c6ca..610f3987f7 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolSlab.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolSlab.cs @@ -61,6 +61,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure { if (!_disposedValue) { + _disposedValue = true; + if (disposing) { // N/A: dispose managed state (managed objects). @@ -72,8 +74,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure // set large fields to null. Array = null; - - _disposedValue = true; } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/KestrelEngine.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/KestrelEngine.cs index a3faaad6a4..5f879b445d 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/KestrelEngine.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/KestrelEngine.cs @@ -46,6 +46,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal thread.Stop(TimeSpan.FromSeconds(2.5)); } Threads.Clear(); +#if DEBUG + GC.Collect(); + GC.WaitForPendingFinalizers(); + GC.Collect(); +#endif } public IDisposable CreateServer(ServerAddress address) diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/AsciiDecoding.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/AsciiDecoding.cs index 91d368a90b..a4497cb0b6 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/AsciiDecoding.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/AsciiDecoding.cs @@ -59,6 +59,8 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var end = GetIterator(begin, byteRange.Length); Assert.Throws(() => begin.GetAsciiString(end)); + + pool.Return(mem); } } } @@ -150,7 +152,10 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { var returnBlock = block; block = block.Next; - pool.Return(returnBlock); + if (returnBlock != mem0 && returnBlock != mem1) + { + pool.Return(returnBlock); + } } pool.Return(mem0); diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolIteratorTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolIteratorTests.cs index 803cf52d61..dd2beec97f 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolIteratorTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolIteratorTests.cs @@ -317,6 +317,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests Assert.ThrowsAny(() => scan.Skip(8)); _pool.Return(block); + _pool.Return(nextBlock); } [Theory] From aa385a1317ac4d5a63a76542c7829c303652e095 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Wed, 20 Jul 2016 22:28:47 +0100 Subject: [PATCH 0818/1662] Use Environment.NewLine and Environment.StackTrace --- .../Internal/Infrastructure/MemoryPool.cs | 19 +++++++------------ .../Infrastructure/MemoryPoolBlock.cs | 2 +- 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPool.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPool.cs index 589efeba3f..b361be5477 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPool.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPool.cs @@ -61,6 +61,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure /// private bool _disposedValue = false; // To detect redundant calls + /// + /// Called to take a block from the pool. + /// + /// The block that is reserved for the called. It must be passed to Return when it is no longer being used. #if DEBUG public MemoryPoolBlock Lease([CallerMemberName] string memberName = "", [CallerFilePath] string sourceFilePath = "", @@ -68,11 +72,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure { Debug.Assert(!_disposedValue, "Block being leased from disposed pool!"); #else - - /// - /// Called to take a block from the pool. - /// - /// The block that is reserved for the called. It must be passed to Return when it is no longer being used. public MemoryPoolBlock Lease() { #endif @@ -83,9 +82,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure #if DEBUG block.Leaser = memberName + ", " + sourceFilePath + ", " + sourceLineNumber; block.IsLeased = true; -#if !NETSTANDARD1_3 - block.StackTrace = new StackTrace(true).ToString(); -#endif + block.StackTrace = Environment.StackTrace; #endif return block; } @@ -94,9 +91,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure #if DEBUG block.Leaser = memberName + ", " + sourceFilePath + ", " + sourceLineNumber; block.IsLeased = true; -#if !NETSTANDARD1_3 - block.StackTrace = new StackTrace(true).ToString(); -#endif + block.StackTrace = Environment.StackTrace; #endif return block; } @@ -153,7 +148,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure { #if DEBUG Debug.Assert(block.Pool == this, "Returned block was not leased from this pool"); - Debug.Assert(block.IsLeased, "Block being returned to pool twice: " + block.Leaser + "\n" + block.StackTrace); + Debug.Assert(block.IsLeased, $"Block being returned to pool twice: {block.Leaser}{Environment.NewLine}{block.StackTrace}"); block.IsLeased = false; #endif diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolBlock.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolBlock.cs index 8b03dee1da..5ce1ce4122 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolBlock.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolBlock.cs @@ -80,7 +80,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure ~MemoryPoolBlock() { #if DEBUG - Debug.Assert(Slab == null || !Slab.IsActive, "Block being garbage collected instead of returned to pool: " + Leaser + "\n" + StackTrace); + Debug.Assert(Slab == null || !Slab.IsActive, $"{Environment.NewLine}{Environment.NewLine}*** Block being garbage collected instead of returned to pool: {Leaser} ***{Environment.NewLine}Allocation StackTrace:{Environment.NewLine}{StackTrace}"); #endif if (Slab != null && Slab.IsActive) { From f42316af7f0bf048b4ad032bf7bd6c60b5f6aea8 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Thu, 21 Jul 2016 01:44:23 +0100 Subject: [PATCH 0819/1662] Remove Environment.StackTrace as crashing tests --- .../Internal/Infrastructure/MemoryPool.cs | 4 +--- .../Internal/Infrastructure/MemoryPoolBlock.cs | 3 +-- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPool.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPool.cs index b361be5477..814d7c2c47 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPool.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPool.cs @@ -82,7 +82,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure #if DEBUG block.Leaser = memberName + ", " + sourceFilePath + ", " + sourceLineNumber; block.IsLeased = true; - block.StackTrace = Environment.StackTrace; #endif return block; } @@ -91,7 +90,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure #if DEBUG block.Leaser = memberName + ", " + sourceFilePath + ", " + sourceLineNumber; block.IsLeased = true; - block.StackTrace = Environment.StackTrace; #endif return block; } @@ -148,7 +146,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure { #if DEBUG Debug.Assert(block.Pool == this, "Returned block was not leased from this pool"); - Debug.Assert(block.IsLeased, $"Block being returned to pool twice: {block.Leaser}{Environment.NewLine}{block.StackTrace}"); + Debug.Assert(block.IsLeased, $"Block being returned to pool twice: {block.Leaser}{Environment.NewLine}"); block.IsLeased = false; #endif diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolBlock.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolBlock.cs index 5ce1ce4122..c23030ac38 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolBlock.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolBlock.cs @@ -74,13 +74,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure #if DEBUG public bool IsLeased { get; set; } public string Leaser { get; set; } - public string StackTrace { get; set; } #endif ~MemoryPoolBlock() { #if DEBUG - Debug.Assert(Slab == null || !Slab.IsActive, $"{Environment.NewLine}{Environment.NewLine}*** Block being garbage collected instead of returned to pool: {Leaser} ***{Environment.NewLine}Allocation StackTrace:{Environment.NewLine}{StackTrace}"); + Debug.Assert(Slab == null || !Slab.IsActive, $"{Environment.NewLine}{Environment.NewLine}*** Block being garbage collected instead of returned to pool: {Leaser} ***{Environment.NewLine}"); #endif if (Slab != null && Slab.IsActive) { From 7b7e2889ce3e0d55fc913a42b8fa7c153e4a8a33 Mon Sep 17 00:00:00 2001 From: Pavel Krymets Date: Thu, 21 Jul 2016 12:17:55 -0700 Subject: [PATCH 0820/1662] Allocate less in GetIPEndPoint (#1004) --- .../Internal/Networking/SockAddr.cs | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/SockAddr.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/SockAddr.cs index d2d14774ef..a5d5338bab 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/SockAddr.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/SockAddr.cs @@ -22,7 +22,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking _field3 = _field0 = _field1 = _field2 = _field3 = 0; } - public IPEndPoint GetIPEndPoint() + public unsafe IPEndPoint GetIPEndPoint() { // The bytes are represented in network byte order. // @@ -84,14 +84,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking else { // otherwise IPv6 - var bytes1 = BitConverter.GetBytes(_field1); - var bytes2 = BitConverter.GetBytes(_field2); - var bytes = new byte[16]; - for (int i = 0; i < 8; ++i) + fixed (byte* b = bytes) { - bytes[i] = bytes1[i]; - bytes[i + 8] = bytes2[i]; + *((long*)b) = _field1; + *((long*)(b + 8)) = _field2; } return new IPEndPoint(new IPAddress(bytes), port); From 6bcf7643df43e06fde17f5ebfd1a677ff116d8c0 Mon Sep 17 00:00:00 2001 From: Pavel Krymets Date: Thu, 21 Jul 2016 16:05:50 -0700 Subject: [PATCH 0821/1662] Do not allocate large write task queues (#1005) --- .../Internal/Http/SocketOutput.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/SocketOutput.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/SocketOutput.cs index fc43cd67fa..7c6be2e7b0 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/SocketOutput.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/SocketOutput.cs @@ -18,7 +18,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http private const int _maxPendingWrites = 3; private const int _maxBytesPreCompleted = 65536; - private const int _initialTaskQueues = 64; + // Well behaved WriteAsync users should await returned task, so there is no need to allocate more per connection by default + private const int _initialTaskQueues = 1; private const int _maxPooledWriteContexts = 32; private static readonly WaitCallback _returnBlocks = (state) => ReturnBlocks((MemoryPoolBlock)state); From 3c0e0f8d889a5d3341a45a1fc5dadbedbead0bb6 Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Fri, 15 Jul 2016 16:51:28 -0700 Subject: [PATCH 0822/1662] Always throw same exception type on read after connection error (#975). --- .../Internal/Http/Connection.cs | 15 +++++++++------ .../Internal/Http/Frame.cs | 4 ++-- .../Internal/Http/FrameRequestStream.cs | 11 ++++++++--- .../Internal/Http/SocketInput.cs | 7 +------ .../Internal/Infrastructure/TaskUtilities.cs | 12 ++++++++++++ .../RequestTests.cs | 18 +----------------- .../FrameRequestStreamTests.cs | 12 ++++++++++++ .../TestHelpers/MockConnection.cs | 2 +- 8 files changed, 46 insertions(+), 35 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Connection.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Connection.cs index da2d7f9bc6..0976a37746 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Connection.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Connection.cs @@ -3,6 +3,7 @@ using System; using System.Diagnostics; +using System.IO; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Filter; @@ -128,13 +129,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http return _socketClosedTcs.Task; } - public virtual void Abort() + public virtual void Abort(Exception error = null) { // Frame.Abort calls user code while this method is always // called from a libuv thread. ThreadPool.Run(() => { - _frame.Abort(); + _frame.Abort(error); }); } @@ -231,18 +232,20 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } } - Exception error = null; + IOException error = null; if (errorDone) { - handle.Libuv.Check(status, out error); - Log.ConnectionError(ConnectionId, error); + Exception uvError; + handle.Libuv.Check(status, out uvError); + Log.ConnectionError(ConnectionId, uvError); + error = new IOException(uvError.Message, uvError); } SocketInput.IncomingComplete(readCount, error); if (errorDone) { - Abort(); + Abort(error); } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs index d014f3d2b9..894b185dd5 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs @@ -339,13 +339,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http /// /// Immediate kill the connection and poison the request and response streams. /// - public void Abort() + public void Abort(Exception error = null) { if (Interlocked.CompareExchange(ref _requestAborted, 1, 0) == 0) { _requestProcessingStopping = true; - _frameStreams?.RequestBody.Abort(); + _frameStreams?.RequestBody.Abort(error); _frameStreams?.ResponseBody.Abort(); try diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameRequestStream.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameRequestStream.cs index f2f7b379be..e9e295a593 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameRequestStream.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameRequestStream.cs @@ -13,6 +13,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { private MessageBody _body; private FrameStreamState _state; + private Exception _error; public FrameRequestStream() { @@ -163,13 +164,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _body = null; } - public void Abort() + public void Abort(Exception error = null) { // We don't want to throw an ODE until the app func actually completes. - // If the request is aborted, we throw an TaskCanceledException instead. + // If the request is aborted, we throw an TaskCanceledException instead, + // unless error is not null, in which case we throw it. if (_state != FrameStreamState.Closed) { _state = FrameStreamState.Aborted; + _error = error; } } @@ -186,7 +189,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http case FrameStreamState.Closed: throw new ObjectDisposedException(nameof(FrameRequestStream)); case FrameStreamState.Aborted: - return TaskUtilities.GetCancelledZeroTask(); + return _error != null ? + TaskUtilities.GetFaultedTask(_error) : + TaskUtilities.GetCancelledZeroTask(); } return null; } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/SocketInput.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/SocketInput.cs index dae06a5ce0..9c7f43031e 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/SocketInput.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/SocketInput.cs @@ -3,7 +3,6 @@ using System; using System.Diagnostics; -using System.IO; using System.Runtime.CompilerServices; using System.Threading; using System.Threading.Tasks; @@ -354,11 +353,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var error = _tcs.Task.Exception?.InnerException; if (error != null) { - if (error is TaskCanceledException || error is InvalidOperationException) - { - throw error; - } - throw new IOException(error.Message, error); + throw error; } } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/TaskUtilities.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/TaskUtilities.cs index 139411bca0..d5e828f0ee 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/TaskUtilities.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/TaskUtilities.cs @@ -1,6 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; using System.Threading; using System.Threading.Tasks; @@ -39,6 +40,17 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure var tcs = new TaskCompletionSource(); tcs.TrySetCanceled(); return tcs.Task; +#endif + } + + public static Task GetFaultedTask(Exception error) + { +#if NETSTANDARD1_3 + return Task.FromException(error); +#else + var tcs = new TaskCompletionSource(); + tcs.SetException(error); + return tcs.Task; #endif } } diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs index 2040f5de35..0d803c45da 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs @@ -248,25 +248,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { await context.Request.Body.ReadAsync(new byte[1], 0, 1); } - catch (BadHttpRequestException) - { - // We need this here because BadHttpRequestException derives from IOException, - // and we're looking for an actual IOException. - } catch (IOException ex) { - // This is one of two exception types that might thrown in this scenario. - // An IOException is thrown if ReadAsync is awaiting on SocketInput when - // the connection is aborted. - expectedExceptionThrown = ex.InnerException is UvException; - } - catch (TaskCanceledException) - { - // This is the other exception type that might be thrown here. - // A TaskCanceledException is thrown if ReadAsync is called when the - // connection has already been aborted, since FrameRequestStream is - // aborted and returns a canceled task from ReadAsync. - expectedExceptionThrown = true; + expectedExceptionThrown = ex.InnerException is UvException && ex.InnerException.Message.Contains("ECONNRESET"); } appDone.Release(); diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameRequestStreamTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameRequestStreamTests.cs index 80368ee5d2..cbe4c4ccb6 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameRequestStreamTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameRequestStreamTests.cs @@ -114,5 +114,17 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var task = stream.ReadAsync(new byte[1], 0, 1); Assert.True(task.IsCanceled); } + + [Fact] + public void AbortWithErrorCausesReadToCancel() + { + var stream = new FrameRequestStream(); + stream.StartAcceptingReads(null); + var error = new Exception(); + stream.Abort(error); + var task = stream.ReadAsync(new byte[1], 0, 1); + Assert.True(task.IsFaulted); + Assert.Same(error, task.Exception.InnerException); + } } } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockConnection.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockConnection.cs index efe612c47e..619d4d5b7b 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockConnection.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockConnection.cs @@ -17,7 +17,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests.TestHelpers RequestAbortedSource = new CancellationTokenSource(); } - public override void Abort() + public override void Abort(Exception error = null) { if (RequestAbortedSource != null) { From 0e7967a7fcf932724ec43ed883ff86786aad8409 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Fri, 15 Jul 2016 00:48:01 -0700 Subject: [PATCH 0823/1662] Allocate things per KestrelThread instead of per listener - Moved things that have loop affinity to KestrelThread like WriteReqPool, MemoryPool and the ConnectionManager - Changed on the listeners to only kill the ListenSocket, not the connections on dispose - Moved connection disposal to KestrelThread.Stop - Simplify the connection manager logic so it's possible to walk and wait in a single call --- .../Internal/Http/Connection.cs | 6 +- .../Internal/Http/ConnectionManager.cs | 40 +++++----- .../Internal/Http/Listener.cs | 18 +---- .../Internal/Http/ListenerContext.cs | 12 --- .../Internal/Http/ListenerSecondary.cs | 17 ----- .../Internal/Http/SocketOutput.cs | 31 ++------ .../Internal/Infrastructure/KestrelThread.cs | 44 +++++++++++ .../Internal/Infrastructure/WriteReqPool.cs | 73 +++++++++++++++++++ .../ConnectionTests.cs | 2 - .../SocketOutputTests.cs | 35 +++------ 10 files changed, 161 insertions(+), 117 deletions(-) create mode 100644 src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/WriteReqPool.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Connection.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Connection.cs index 0976a37746..0c73c35c7c 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Connection.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Connection.cs @@ -52,8 +52,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _bufferSizeControl = new BufferSizeControl(ServerOptions.MaxRequestBufferSize.Value, this, Thread); } - SocketInput = new SocketInput(Memory, ThreadPool, _bufferSizeControl); - SocketOutput = new SocketOutput(Thread, _socket, Memory, this, ConnectionId, Log, ThreadPool, WriteReqPool); + SocketInput = new SocketInput(Thread.Memory, ThreadPool, _bufferSizeControl); + SocketOutput = new SocketOutput(Thread, _socket, this, ConnectionId, Log, ThreadPool); var tcpHandle = _socket as UvTcpHandle; if (tcpHandle != null) @@ -166,7 +166,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { if (_filterContext.Connection != _libuvStream) { - _filteredStreamAdapter = new FilteredStreamAdapter(ConnectionId, _filterContext.Connection, Memory, Log, ThreadPool, _bufferSizeControl); + _filteredStreamAdapter = new FilteredStreamAdapter(ConnectionId, _filterContext.Connection, Thread.Memory, Log, ThreadPool, _bufferSizeControl); _frame.SocketInput = _filteredStreamAdapter.SocketInput; _frame.SocketOutput = _filteredStreamAdapter.SocketOutput; diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ConnectionManager.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ConnectionManager.cs index f546a6c87e..a936855a09 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ConnectionManager.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ConnectionManager.cs @@ -3,30 +3,36 @@ using System; using System.Collections.Generic; +using System.Threading; using System.Threading.Tasks; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { public class ConnectionManager { - private KestrelThread _thread; - private List _connectionStopTasks; + private readonly KestrelThread _thread; + private readonly IThreadPool _threadPool; - public ConnectionManager(KestrelThread thread) + public ConnectionManager(KestrelThread thread, IThreadPool threadPool) { _thread = thread; + _threadPool = threadPool; } - // This must be called on the libuv event loop - public void WalkConnectionsAndClose() + public bool WalkConnectionsAndClose(TimeSpan timeout) { - if (_connectionStopTasks != null) - { - throw new InvalidOperationException($"{nameof(WalkConnectionsAndClose)} cannot be called twice."); - } + var wh = new ManualResetEventSlim(); - _connectionStopTasks = new List(); + _thread.Post(state => ((ConnectionManager)state).WalkConnectionsAndCloseCore(wh), this); + + return wh.Wait(timeout); + } + + private void WalkConnectionsAndCloseCore(ManualResetEventSlim wh) + { + var connectionStopTasks = new List(); _thread.Walk(ptr => { @@ -35,19 +41,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if (connection != null) { - _connectionStopTasks.Add(connection.StopAsync()); + connectionStopTasks.Add(connection.StopAsync()); } }); - } - public Task WaitForConnectionCloseAsync() - { - if (_connectionStopTasks == null) + _threadPool.Run(() => { - throw new InvalidOperationException($"{nameof(WalkConnectionsAndClose)} must be called first."); - } - - return Task.WhenAll(_connectionStopTasks); + Task.WaitAll(connectionStopTasks.ToArray()); + wh.Set(); + }); } } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Listener.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Listener.cs index a44c1b87bf..abd9c46216 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Listener.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Listener.cs @@ -15,7 +15,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { private bool _closed; - protected Listener(ServiceContext serviceContext) + protected Listener(ServiceContext serviceContext) : base(serviceContext) { } @@ -28,7 +28,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { ServerAddress = address; Thread = thread; - ConnectionManager = new ConnectionManager(thread); var tcs = new TaskCompletionSource(this); @@ -57,7 +56,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http protected static void ConnectionCallback(UvStreamHandle stream, int status, Exception error, object state) { - var listener = (Listener) state; + var listener = (Listener)state; if (error != null) { @@ -97,22 +96,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http listener._closed = true; - listener.ConnectionManager.WalkConnectionsAndClose(); - }, this).ConfigureAwait(false); - - await ConnectionManager.WaitForConnectionCloseAsync().ConfigureAwait(false); - - await Thread.PostAsync(state => - { - var writeReqPool = ((Listener)state).WriteReqPool; - while (writeReqPool.Count > 0) - { - writeReqPool.Dequeue().Dispose(); - } }, this).ConfigureAwait(false); } - Memory.Dispose(); ListenSocket = null; } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ListenerContext.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ListenerContext.cs index 83e9956e48..f7c0dd1dac 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ListenerContext.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ListenerContext.cs @@ -16,8 +16,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http public ListenerContext(ServiceContext serviceContext) : base(serviceContext) { - Memory = new MemoryPool(); - WriteReqPool = new Queue(SocketOutput.MaxPooledWriteReqs); } public ListenerContext(ListenerContext listenerContext) @@ -25,20 +23,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { ServerAddress = listenerContext.ServerAddress; Thread = listenerContext.Thread; - Memory = listenerContext.Memory; - ConnectionManager = listenerContext.ConnectionManager; - WriteReqPool = listenerContext.WriteReqPool; - Log = listenerContext.Log; } public ServerAddress ServerAddress { get; set; } public KestrelThread Thread { get; set; } - - public MemoryPool Memory { get; set; } - - public ConnectionManager ConnectionManager { get; set; } - - public Queue WriteReqPool { get; set; } } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ListenerSecondary.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ListenerSecondary.cs index e11729200f..f3acef1f1d 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ListenerSecondary.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ListenerSecondary.cs @@ -39,8 +39,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http ServerAddress = address; Thread = thread; - ConnectionManager = new ConnectionManager(thread); - DispatchPipe = new UvPipeHandle(Log); var tcs = new TaskCompletionSource(this); @@ -180,27 +178,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http listener._closed = true; - listener.ConnectionManager.WalkConnectionsAndClose(); - }, this).ConfigureAwait(false); - - await ConnectionManager.WaitForConnectionCloseAsync().ConfigureAwait(false); - - await Thread.PostAsync(state => - { - var listener = (ListenerSecondary)state; - var writeReqPool = listener.WriteReqPool; - while (writeReqPool.Count > 0) - { - writeReqPool.Dequeue().Dispose(); - } }, this).ConfigureAwait(false); } else { FreeBuffer(); } - - Memory.Dispose(); } } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/SocketOutput.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/SocketOutput.cs index 7c6be2e7b0..daed0694e5 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/SocketOutput.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/SocketOutput.cs @@ -14,8 +14,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { public class SocketOutput : ISocketOutput { - public const int MaxPooledWriteReqs = 1024; - private const int _maxPendingWrites = 3; private const int _maxBytesPreCompleted = 65536; // Well behaved WriteAsync users should await returned task, so there is no need to allocate more per connection by default @@ -58,17 +56,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http private WriteContext _nextWriteContext; private readonly Queue _tasksPending; private readonly Queue _writeContextPool; - private readonly Queue _writeReqPool; + private readonly WriteReqPool _writeReqPool; public SocketOutput( KestrelThread thread, UvStreamHandle socket, - MemoryPool memory, Connection connection, string connectionId, IKestrelTrace log, - IThreadPool threadPool, - Queue writeReqPool) + IThreadPool threadPool) { _thread = thread; _socket = socket; @@ -78,9 +74,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _threadPool = threadPool; _tasksPending = new Queue(_initialTaskQueues); _writeContextPool = new Queue(_maxPooledWriteContexts); - _writeReqPool = writeReqPool; + _writeReqPool = thread.WriteReqPool; - _head = memory.Lease(); + _head = thread.Memory.Lease(); _tail = _head; } @@ -585,15 +581,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var lockedEndBlock = _lockedEnd.Block; var lockedEndIndex = _lockedEnd.Index; - if (Self._writeReqPool.Count > 0) - { - _writeReq = Self._writeReqPool.Dequeue(); - } - else - { - _writeReq = new UvWriteReq(Self._log); - _writeReq.Init(Self._thread.Loop); - } + _writeReq = Self._writeReqPool.Allocate(); _writeReq.Write(Self._socket, _lockedStart, _lockedEnd, _bufferCount, (_writeReq, status, error, state) => { @@ -691,14 +679,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http private void PoolWriteReq(UvWriteReq writeReq) { - if (Self._writeReqPool.Count < MaxPooledWriteReqs) - { - Self._writeReqPool.Enqueue(writeReq); - } - else - { - writeReq.Dispose(); - } + Self._writeReqPool.Return(writeReq); } private void ScheduleReturnFullyWrittenBlocks() diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/KestrelThread.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/KestrelThread.cs index 3813d75980..47f56ef229 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/KestrelThread.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/KestrelThread.cs @@ -7,6 +7,7 @@ using System.Runtime.ExceptionServices; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; using Microsoft.Extensions.Logging; @@ -42,6 +43,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal private ExceptionDispatchInfo _closeError; private readonly IKestrelTrace _log; private readonly IThreadPool _threadPool; + private readonly TimeSpan _shutdownTimeout; public KestrelThread(KestrelEngine engine) { @@ -49,6 +51,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal _appLifetime = engine.AppLifetime; _log = engine.Log; _threadPool = engine.ThreadPool; + _shutdownTimeout = engine.ServerOptions.ShutdownTimeout; _loop = new UvLoopHandle(_log); _post = new UvAsyncHandle(_log); _thread = new Thread(ThreadStart); @@ -60,10 +63,19 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal #endif QueueCloseHandle = PostCloseHandle; QueueCloseAsyncHandle = EnqueueCloseHandle; + Memory = new MemoryPool(); + WriteReqPool = new WriteReqPool(this, _log); + ConnectionManager = new ConnectionManager(this, _threadPool); } public UvLoopHandle Loop { get { return _loop; } } + public MemoryPool Memory { get; } + + public ConnectionManager ConnectionManager { get; } + + public WriteReqPool WriteReqPool { get; } + public ExceptionDispatchInfo FatalError { get { return _closeError; } } public Action, IntPtr> QueueCloseHandle { get; } @@ -95,6 +107,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal if (_thread.IsAlive) { + // These operations need to run on the libuv thread so it only makes + // sense to attempt execution if it's still running + DisposeConnections(); + var stepTimeout = (int)(timeout.TotalMilliseconds / 2); try { @@ -125,6 +141,34 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal } } + private void DisposeConnections() + { + try + { + // Close and wait for all connections + if (!ConnectionManager.WalkConnectionsAndClose(_shutdownTimeout)) + { + _log.LogError(0, null, "Waiting for connections timed out"); + } + + var result = PostAsync(state => + { + var listener = (KestrelThread)state; + listener.WriteReqPool.Dispose(); + }, + this).Wait(_shutdownTimeout); + + if (!result) + { + _log.LogError(0, null, "Disposing write requests failed"); + } + } + finally + { + Memory.Dispose(); + } + } + private void OnStopRude() { Walk(ptr => diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/WriteReqPool.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/WriteReqPool.cs new file mode 100644 index 0000000000..1f89ec17e2 --- /dev/null +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/WriteReqPool.cs @@ -0,0 +1,73 @@ +using System; +using System.Collections.Generic; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; + +namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure +{ + public class WriteReqPool + { + private const int _maxPooledWriteReqs = 1024; + + private readonly KestrelThread _thread; + private readonly Queue _pool = new Queue(_maxPooledWriteReqs); + private readonly IKestrelTrace _log; + private bool _disposed; + + public WriteReqPool(KestrelThread thread, IKestrelTrace log) + { + _thread = thread; + _log = log; + } + + public UvWriteReq Allocate() + { + if (_disposed) + { + throw new ObjectDisposedException(GetType().Name); + } + + UvWriteReq req; + if (_pool.Count > 0) + { + req = _pool.Dequeue(); + } + else + { + req = new UvWriteReq(_log); + req.Init(_thread.Loop); + } + + return req; + } + + public void Return(UvWriteReq req) + { + if (_disposed) + { + throw new ObjectDisposedException(GetType().Name); + } + + if (_pool.Count < _maxPooledWriteReqs) + { + _pool.Enqueue(req); + } + else + { + req.Dispose(); + } + } + + public void Dispose() + { + if (!_disposed) + { + _disposed = true; + + while (_pool.Count > 0) + { + _pool.Dequeue().Dispose(); + } + } + } + } +} diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionTests.cs index 261bb47068..cdcacc071c 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionTests.cs @@ -17,7 +17,6 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { var mockLibuv = new MockLibuv(); - using (var memory = new MemoryPool()) using (var engine = new KestrelEngine(mockLibuv, new TestServiceContext())) { engine.Start(count: 1); @@ -27,7 +26,6 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { FrameFactory = connectionContext => new Frame( new DummyApplication(httpContext => TaskUtilities.CompletedTask), connectionContext), - Memory = memory, ServerAddress = ServerAddress.FromUrl("http://127.0.0.1:0"), Thread = engine.Threads[0] }; diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/SocketOutputTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/SocketOutputTests.cs index ff26864bc5..c6cd758d1d 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/SocketOutputTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/SocketOutputTests.cs @@ -26,8 +26,6 @@ namespace Microsoft.AspNetCore.Server.KestrelTests // Arrange var mockLibuv = new MockLibuv(); - - using (var memory = new MemoryPool()) using (var kestrelEngine = new KestrelEngine(mockLibuv, new TestServiceContext())) { kestrelEngine.Start(count: 1); @@ -36,7 +34,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var socket = new MockSocket(mockLibuv, kestrelThread.Loop.ThreadId, new TestKestrelTrace()); var trace = new KestrelTrace(new TestKestrelTrace()); var ltp = new LoggingThreadPool(trace); - var socketOutput = new SocketOutput(kestrelThread, socket, memory, new MockConnection(), "0", trace, ltp, new Queue()); + var socketOutput = new SocketOutput(kestrelThread, socket, new MockConnection(), "0", trace, ltp); // I doubt _maxBytesPreCompleted will ever be over a MB. If it is, we should change this test. var bufferSize = 1048576; @@ -78,7 +76,6 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } }; - using (var memory = new MemoryPool()) using (var kestrelEngine = new KestrelEngine(mockLibuv, new TestServiceContext())) { kestrelEngine.Start(count: 1); @@ -88,7 +85,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var trace = new KestrelTrace(new TestKestrelTrace()); var ltp = new LoggingThreadPool(trace); var mockConnection = new MockConnection(); - var socketOutput = new SocketOutput(kestrelThread, socket, memory, mockConnection, "0", trace, ltp, new Queue()); + var socketOutput = new SocketOutput(kestrelThread, socket, mockConnection, "0", trace, ltp); var bufferSize = maxBytesPreCompleted; var buffer = new ArraySegment(new byte[bufferSize], 0, bufferSize); @@ -152,7 +149,6 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } }; - using (var memory = new MemoryPool()) using (var kestrelEngine = new KestrelEngine(mockLibuv, new TestServiceContext())) { kestrelEngine.Start(count: 1); @@ -162,7 +158,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var trace = new KestrelTrace(new TestKestrelTrace()); var ltp = new LoggingThreadPool(trace); var mockConnection = new MockConnection(); - var socketOutput = new SocketOutput(kestrelThread, socket, memory, mockConnection, "0", trace, ltp, new Queue()); + var socketOutput = new SocketOutput(kestrelThread, socket, mockConnection, "0", trace, ltp); var bufferSize = maxBytesPreCompleted / 2; var data = new byte[bufferSize]; @@ -231,7 +227,6 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } }; - using (var memory = new MemoryPool()) using (var kestrelEngine = new KestrelEngine(mockLibuv, new TestServiceContext())) { kestrelEngine.Start(count: 1); @@ -240,10 +235,10 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var socket = new MockSocket(mockLibuv, kestrelThread.Loop.ThreadId, new TestKestrelTrace()); var trace = new KestrelTrace(new TestKestrelTrace()); var ltp = new LoggingThreadPool(trace); - + using (var mockConnection = new MockConnection()) { - ISocketOutput socketOutput = new SocketOutput(kestrelThread, socket, memory, mockConnection, "0", trace, ltp, new Queue()); + ISocketOutput socketOutput = new SocketOutput(kestrelThread, socket, mockConnection, "0", trace, ltp); var bufferSize = maxBytesPreCompleted; @@ -348,7 +343,6 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } }; - using (var memory = new MemoryPool()) using (var kestrelEngine = new KestrelEngine(mockLibuv, new TestServiceContext())) { kestrelEngine.Start(count: 1); @@ -361,7 +355,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests using (var mockConnection = new MockConnection()) { var abortedSource = mockConnection.RequestAbortedSource; - ISocketOutput socketOutput = new SocketOutput(kestrelThread, socket, memory, mockConnection, "0", trace, ltp, new Queue()); + ISocketOutput socketOutput = new SocketOutput(kestrelThread, socket, mockConnection, "0", trace, ltp); var bufferSize = maxBytesPreCompleted; @@ -441,7 +435,6 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } }; - using (var memory = new MemoryPool()) using (var kestrelEngine = new KestrelEngine(mockLibuv, new TestServiceContext())) { kestrelEngine.Start(count: 1); @@ -451,7 +444,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var trace = new KestrelTrace(new TestKestrelTrace()); var ltp = new LoggingThreadPool(trace); var mockConnection = new MockConnection(); - var socketOutput = new SocketOutput(kestrelThread, socket, memory, mockConnection, "0", trace, ltp, new Queue()); + var socketOutput = new SocketOutput(kestrelThread, socket, mockConnection, "0", trace, ltp); var bufferSize = maxBytesPreCompleted; var buffer = new ArraySegment(new byte[bufferSize], 0, bufferSize); @@ -534,7 +527,6 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } }; - using (var memory = new MemoryPool()) using (var kestrelEngine = new KestrelEngine(mockLibuv, new TestServiceContext())) { kestrelEngine.Start(count: 1); @@ -543,14 +535,14 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var socket = new MockSocket(mockLibuv, kestrelThread.Loop.ThreadId, new TestKestrelTrace()); var trace = new KestrelTrace(new TestKestrelTrace()); var ltp = new LoggingThreadPool(trace); - var socketOutput = new SocketOutput(kestrelThread, socket, memory, new MockConnection(), "0", trace, ltp, new Queue()); + var socketOutput = new SocketOutput(kestrelThread, socket, new MockConnection(), "0", trace, ltp); // block 1 var start = socketOutput.ProducingStart(); start.Block.End = start.Block.Data.Offset + start.Block.Data.Count; // block 2 - var block2 = memory.Lease(); + var block2 = kestrelThread.Memory.Lease(); block2.End = block2.Data.Offset + block2.Data.Count; start.Block.Next = block2; @@ -586,7 +578,6 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } }; - using (var memory = new MemoryPool()) using (var kestrelEngine = new KestrelEngine(mockLibuv, new TestServiceContext())) { kestrelEngine.Start(count: 1); @@ -596,7 +587,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var trace = new KestrelTrace(new TestKestrelTrace()); var ltp = new LoggingThreadPool(trace); var mockConnection = new MockConnection(); - var socketOutput = new SocketOutput(kestrelThread, socket, memory, mockConnection, "0", trace, ltp, new Queue()); + var socketOutput = new SocketOutput(kestrelThread, socket, mockConnection, "0", trace, ltp); var buffer = new ArraySegment(new byte[1]); @@ -656,7 +647,6 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } }; - using (var memory = new MemoryPool()) using (var kestrelEngine = new KestrelEngine(mockLibuv, new TestServiceContext())) { kestrelEngine.Start(count: 1); @@ -665,7 +655,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var socket = new MockSocket(mockLibuv, kestrelThread.Loop.ThreadId, new TestKestrelTrace()); var trace = new KestrelTrace(new TestKestrelTrace()); var ltp = new LoggingThreadPool(trace); - var socketOutput = new SocketOutput(kestrelThread, socket, memory, new MockConnection(), "0", trace, ltp, new Queue()); + var socketOutput = new SocketOutput(kestrelThread, socket, new MockConnection(), "0", trace, ltp); var blockThreadWh = new ManualResetEventSlim(); kestrelThread.Post(_ => @@ -702,7 +692,6 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { var mockLibuv = new MockLibuv(); - using (var memory = new MemoryPool()) using (var kestrelEngine = new KestrelEngine(mockLibuv, new TestServiceContext())) { kestrelEngine.Start(count: 1); @@ -712,7 +701,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var trace = new KestrelTrace(new TestKestrelTrace()); var ltp = new LoggingThreadPool(trace); var connection = new MockConnection(); - var socketOutput = new SocketOutput(kestrelThread, socket, memory, connection, "0", trace, ltp, new Queue()); + var socketOutput = new SocketOutput(kestrelThread, socket, connection, "0", trace, ltp); // Close SocketOutput var cleanupTask = socketOutput.WriteAsync( From 27f8c8dca292684b0c6e7e11ca3b10518c258303 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Fri, 22 Jul 2016 12:26:13 -0700 Subject: [PATCH 0824/1662] Ensure libuv handles get disposed properly after binding errors --- .../Internal/Http/Listener.cs | 4 +++- .../Internal/Http/ListenerPrimary.cs | 2 +- .../Internal/Http/PipeListener.cs | 16 ++++++++++---- .../Internal/Http/PipeListenerPrimary.cs | 15 ++++++++++--- .../Internal/Http/SocketOutput.cs | 2 +- .../Internal/Http/TcpListener.cs | 21 +++++++++++++------ .../Internal/Http/TcpListenerPrimary.cs | 21 +++++++++++++------ 7 files changed, 59 insertions(+), 22 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Listener.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Listener.cs index abd9c46216..a40515d66f 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Listener.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Listener.cs @@ -3,6 +3,7 @@ using System; using System.Threading.Tasks; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; using Microsoft.Extensions.Logging; @@ -38,6 +39,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { var listener = ((Listener)tcs2.Task.AsyncState); listener.ListenSocket = listener.CreateListenSocket(); + ListenSocket.Listen(Constants.ListenBacklog, ConnectionCallback, this); tcs2.SetResult(0); } catch (Exception ex) @@ -54,7 +56,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http /// protected abstract UvStreamHandle CreateListenSocket(); - protected static void ConnectionCallback(UvStreamHandle stream, int status, Exception error, object state) + private static void ConnectionCallback(UvStreamHandle stream, int status, Exception error, object state) { var listener = (Listener)state; diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ListenerPrimary.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ListenerPrimary.cs index a9b938d158..9e40e6b549 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ListenerPrimary.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ListenerPrimary.cs @@ -70,10 +70,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } var dispatchPipe = new UvPipeHandle(Log); - dispatchPipe.Init(Thread.Loop, Thread.QueueCloseHandle, true); try { + dispatchPipe.Init(Thread.Loop, Thread.QueueCloseHandle, true); pipe.Accept(dispatchPipe); } catch (UvException ex) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/PipeListener.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/PipeListener.cs index 0b01438870..8ef9e38683 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/PipeListener.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/PipeListener.cs @@ -1,7 +1,6 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; using Microsoft.Extensions.Logging; @@ -22,9 +21,18 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http protected override UvStreamHandle CreateListenSocket() { var socket = new UvPipeHandle(Log); - socket.Init(Thread.Loop, Thread.QueueCloseHandle, false); - socket.Bind(ServerAddress.UnixPipePath); - socket.Listen(Constants.ListenBacklog, (stream, status, error, state) => ConnectionCallback(stream, status, error, state), this); + + try + { + socket.Init(Thread.Loop, Thread.QueueCloseHandle, false); + socket.Bind(ServerAddress.UnixPipePath); + } + catch + { + socket.Dispose(); + throw; + } + return socket; } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/PipeListenerPrimary.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/PipeListenerPrimary.cs index 3011a26616..ebc59cfadb 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/PipeListenerPrimary.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/PipeListenerPrimary.cs @@ -22,9 +22,18 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http protected override UvStreamHandle CreateListenSocket() { var socket = new UvPipeHandle(Log); - socket.Init(Thread.Loop, Thread.QueueCloseHandle, false); - socket.Bind(ServerAddress.UnixPipePath); - socket.Listen(Constants.ListenBacklog, (stream, status, error, state) => ConnectionCallback(stream, status, error, state), this); + + try + { + socket.Init(Thread.Loop, Thread.QueueCloseHandle, false); + socket.Bind(ServerAddress.UnixPipePath); + } + catch + { + socket.Dispose(); + throw; + } + return socket; } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/SocketOutput.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/SocketOutput.cs index daed0694e5..0b02da9748 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/SocketOutput.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/SocketOutput.cs @@ -583,7 +583,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _writeReq = Self._writeReqPool.Allocate(); - _writeReq.Write(Self._socket, _lockedStart, _lockedEnd, _bufferCount, (_writeReq, status, error, state) => + _writeReq.Write(Self._socket, _lockedStart, _lockedEnd, _bufferCount, (req, status, error, state) => { var writeContext = (WriteContext)state; writeContext.PoolWriteReq(writeContext._writeReq); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/TcpListener.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/TcpListener.cs index 8f3b664105..fd69130fb8 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/TcpListener.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/TcpListener.cs @@ -1,6 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; using Microsoft.Extensions.Logging; @@ -22,14 +23,22 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http protected override UvStreamHandle CreateListenSocket() { var socket = new UvTcpHandle(Log); - socket.Init(Thread.Loop, Thread.QueueCloseHandle); - socket.NoDelay(ServerOptions.NoDelay); - socket.Bind(ServerAddress); - // If requested port was "0", replace with assigned dynamic port. - ServerAddress.Port = socket.GetSockIPEndPoint().Port; + try + { + socket.Init(Thread.Loop, Thread.QueueCloseHandle); + socket.NoDelay(ServerOptions.NoDelay); + socket.Bind(ServerAddress); + + // If requested port was "0", replace with assigned dynamic port. + ServerAddress.Port = socket.GetSockIPEndPoint().Port; + } + catch + { + socket.Dispose(); + throw; + } - socket.Listen(Constants.ListenBacklog, (stream, status, error, state) => ConnectionCallback(stream, status, error, state), this); return socket; } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/TcpListenerPrimary.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/TcpListenerPrimary.cs index b442deb42e..09b856438a 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/TcpListenerPrimary.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/TcpListenerPrimary.cs @@ -1,6 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; using Microsoft.Extensions.Logging; @@ -22,14 +23,22 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http protected override UvStreamHandle CreateListenSocket() { var socket = new UvTcpHandle(Log); - socket.Init(Thread.Loop, Thread.QueueCloseHandle); - socket.NoDelay(ServerOptions.NoDelay); - socket.Bind(ServerAddress); - // If requested port was "0", replace with assigned dynamic port. - ServerAddress.Port = socket.GetSockIPEndPoint().Port; + try + { + socket.Init(Thread.Loop, Thread.QueueCloseHandle); + socket.NoDelay(ServerOptions.NoDelay); + socket.Bind(ServerAddress); + + // If requested port was "0", replace with assigned dynamic port. + ServerAddress.Port = socket.GetSockIPEndPoint().Port; + } + catch + { + socket.Dispose(); + throw; + } - socket.Listen(Constants.ListenBacklog, (stream, status, error, state) => ConnectionCallback(stream, status, error, state), this); return socket; } From 7c811ff56854c4ed5759447a402218e8566e4d92 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Fri, 22 Jul 2016 12:29:28 +0100 Subject: [PATCH 0825/1662] Only allocate key string when unknown --- .../Internal/Http/FrameHeaders.Generated.cs | 3 ++- .../KnownHeaders.cs | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameHeaders.Generated.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameHeaders.Generated.cs index d72bc25e78..39f032ea07 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameHeaders.Generated.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameHeaders.Generated.cs @@ -4197,7 +4197,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http public unsafe void Append(byte[] keyBytes, int keyOffset, int keyLength, string value) { - var key = new string('\0', keyLength); + string key; fixed (byte* ptr = &keyBytes[keyOffset]) { var pUB = ptr; @@ -4899,6 +4899,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http break; } + key = new string('\0', keyLength); fixed(char *keyBuffer = key) { if (!AsciiUtilities.TryGetAsciiString(ptr, keyBuffer, keyLength)) diff --git a/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/KnownHeaders.cs b/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/KnownHeaders.cs index 53dff0dd53..ed126ec58b 100644 --- a/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/KnownHeaders.cs +++ b/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/KnownHeaders.cs @@ -417,7 +417,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http {(loop.ClassName == "FrameRequestHeaders" ? $@" public unsafe void Append(byte[] keyBytes, int keyOffset, int keyLength, string value) {{ - var key = new string('\0', keyLength); + string key; fixed (byte* ptr = &keyBytes[keyOffset]) {{ var pUB = ptr; @@ -446,6 +446,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http break; ")}}} + key = new string('\0', keyLength); fixed(char *keyBuffer = key) {{ if (!AsciiUtilities.TryGetAsciiString(ptr, keyBuffer, keyLength)) From 0620ce5a2f56a7daf27810e57801261662b0958f Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Tue, 19 Jul 2016 16:51:04 +0100 Subject: [PATCH 0826/1662] Consolidate BadHttpRequestException messages --- .../BadHttpRequestException.cs | 93 ++++++++++++++++++- .../Internal/Http/Frame.cs | 60 +++++++----- .../Internal/Http/FrameHeaders.Generated.cs | 2 +- .../Internal/Http/FrameHeaders.cs | 17 ++-- .../Internal/Http/FrameOfT.cs | 4 +- .../Internal/Http/MessageBody.cs | 27 +++--- .../Internal/Http/RequestRejectionReasons.cs | 31 +++++++ .../Internal/Http/UrlPathDecoder.cs | 2 +- .../MemoryPoolIteratorExtensions.cs | 3 +- .../KnownHeaders.cs | 2 +- 10 files changed, 189 insertions(+), 52 deletions(-) create mode 100644 src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/RequestRejectionReasons.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/BadHttpRequestException.cs b/src/Microsoft.AspNetCore.Server.Kestrel/BadHttpRequestException.cs index f9ef840b12..e227882f7b 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/BadHttpRequestException.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/BadHttpRequestException.cs @@ -2,15 +2,106 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.IO; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; namespace Microsoft.AspNetCore.Server.Kestrel { public sealed class BadHttpRequestException : IOException { - internal BadHttpRequestException(string message) + private BadHttpRequestException(string message) : base(message) { } + + internal static BadHttpRequestException GetException(RequestRejectionReasons reason) + { + BadHttpRequestException ex; + switch (reason) + { + case RequestRejectionReasons.MissingMethod: + ex = new BadHttpRequestException("Missing method."); + break; + case RequestRejectionReasons.InvalidMethod: + ex = new BadHttpRequestException("Invalid method."); + break; + case RequestRejectionReasons.MissingRequestTarget: + ex = new BadHttpRequestException("Missing request target."); + break; + case RequestRejectionReasons.MissingHTTPVersion: + ex = new BadHttpRequestException("Missing HTTP version."); + break; + case RequestRejectionReasons.UnrecognizedHTTPVersion: + ex = new BadHttpRequestException("Unrecognized HTTP version."); + break; + case RequestRejectionReasons.MissingLFInRequestLine: + ex = new BadHttpRequestException("Missing LF in request line."); + break; + case RequestRejectionReasons.HeadersCorruptedInvalidHeaderSequence: + ex = new BadHttpRequestException("Headers corrupted, invalid header sequence."); + break; + case RequestRejectionReasons.HeaderLineMustNotStartWithWhitespace: + ex = new BadHttpRequestException("Header line must not start with whitespace."); + break; + case RequestRejectionReasons.NoColonCharacterFoundInHeaderLine: + ex = new BadHttpRequestException("No ':' character found in header line."); + break; + case RequestRejectionReasons.WhitespaceIsNotAllowedInHeaderName: + ex = new BadHttpRequestException("Whitespace is not allowed in header name."); + break; + case RequestRejectionReasons.HeaderLineMustEndInCRLFOnlyCRFound: + ex = new BadHttpRequestException("Header line must end in CRLF; only CR found."); + break; + case RequestRejectionReasons.HeaderValueLineFoldingNotSupported: + ex = new BadHttpRequestException("Header value line folding not supported."); + break; + case RequestRejectionReasons.MalformedRequestInvalidHeaders: + ex = new BadHttpRequestException("Malformed request: invalid headers."); + break; + case RequestRejectionReasons.UnexpectedEndOfRequestContent: + ex = new BadHttpRequestException("Unexpected end of request content"); + break; + case RequestRejectionReasons.BadChunkSuffix: + ex = new BadHttpRequestException("Bad chunk suffix"); + break; + case RequestRejectionReasons.BadChunkSizeData: + ex = new BadHttpRequestException("Bad chunk size data"); + break; + case RequestRejectionReasons.ChunkedRequestIncomplete: + ex = new BadHttpRequestException("Chunked request incomplete"); + break; + case RequestRejectionReasons.PathContainsNullCharacters: + ex = new BadHttpRequestException("The path contains null characters."); + break; + case RequestRejectionReasons.InvalidCharactersInHeaderName: + ex = new BadHttpRequestException("Invalid characters in header name."); + break; + case RequestRejectionReasons.NonAsciiOrNullCharactersInInputString: + ex = new BadHttpRequestException("The input string contains non-ASCII or null characters."); + break; + default: + ex = new BadHttpRequestException("Bad request."); + break; + } + return ex; + } + + internal static BadHttpRequestException GetException(RequestRejectionReasons reason, string value) + { + BadHttpRequestException ex; + switch (reason) + { + case RequestRejectionReasons.MalformedRequestLineStatus: + ex = new BadHttpRequestException($"Malformed request: {value}"); + break; + case RequestRejectionReasons.InvalidContentLength: + ex = new BadHttpRequestException($"Invalid content length: {value}"); + break; + default: + ex = new BadHttpRequestException("Bad request."); + break; + } + return ex; + } } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs index 894b185dd5..cc9806a1a9 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs @@ -131,7 +131,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { if (HasResponseStarted) { - throw new InvalidOperationException("Status code cannot be set, response has already started."); + ThrowResponseAlreadyStartedException(nameof(StatusCode)); } _statusCode = value; @@ -149,7 +149,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { if (HasResponseStarted) { - throw new InvalidOperationException("Reason phrase cannot be set, response had already started."); + ThrowResponseAlreadyStartedException(nameof(ReasonPhrase)); } _reasonPhrase = value; @@ -569,13 +569,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if (_applicationException != null) { - throw new ObjectDisposedException( - "The response has been aborted due to an unhandled application exception.", - _applicationException); + ThrowResponseAbortedException(); } ProduceStart(appCompleted: false); - return TaskUtilities.CompletedTask; } @@ -585,9 +582,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if (_applicationException != null) { - throw new ObjectDisposedException( - "The response has been aborted due to an unhandled application exception.", - _applicationException); + ThrowResponseAbortedException(); } ProduceStart(appCompleted: false); @@ -819,7 +814,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if (method == null) { - RejectRequest("Missing method."); + RejectRequest(RequestRejectionReasons.MissingMethod); } // Note: We're not in the fast path any more (GetKnownMethod should have handled any HTTP Method we're aware of) @@ -828,7 +823,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { if (!IsValidTokenChar(method[i])) { - RejectRequest("Invalid method."); + RejectRequest(RequestRejectionReasons.InvalidMethod); } } } @@ -873,7 +868,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if (pathBegin.Peek() == ' ') { - RejectRequest("Missing request target."); + RejectRequest(RequestRejectionReasons.MissingRequestTarget); } scan.Take(); @@ -895,11 +890,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if (httpVersion == null) { - RejectRequest("Missing HTTP version."); + RejectRequest(RequestRejectionReasons.MissingHTTPVersion); } else if (httpVersion != "HTTP/1.0" && httpVersion != "HTTP/1.1") { - RejectRequest("Unrecognized HTTP version."); + RejectRequest(RequestRejectionReasons.UnrecognizedHTTPVersion); } } @@ -911,7 +906,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } else if (next != '\n') { - RejectRequest("Missing LF in request line."); + RejectRequest(RequestRejectionReasons.MissingLFInRequestLine); } // URIs are always encoded/escaped to ASCII https://tools.ietf.org/html/rfc3986#page-11 @@ -1065,11 +1060,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } // Headers don't end in CRLF line. - RejectRequest("Headers corrupted, invalid header sequence."); + RejectRequest(RequestRejectionReasons.HeadersCorruptedInvalidHeaderSequence); } else if (ch == ' ' || ch == '\t') { - RejectRequest("Header line must not start with whitespace."); + RejectRequest(RequestRejectionReasons.HeaderLineMustNotStartWithWhitespace); } var beginName = scan; @@ -1082,13 +1077,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http ch = scan.Take(); if (ch != ':') { - RejectRequest("No ':' character found in header line."); + RejectRequest(RequestRejectionReasons.NoColonCharacterFoundInHeaderLine); } var validateName = beginName; if (validateName.Seek(ref _vectorSpaces, ref _vectorTabs, ref _vectorColons) != ':') { - RejectRequest("Whitespace is not allowed in header name."); + RejectRequest(RequestRejectionReasons.WhitespaceIsNotAllowedInHeaderName); } var beginValue = scan; @@ -1128,7 +1123,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } else if (ch != '\n') { - RejectRequest("Header line must end in CRLF; only CR found."); + RejectRequest(RequestRejectionReasons.HeaderLineMustEndInCRLFOnlyCRFound); } var next = scan.Peek(); @@ -1155,7 +1150,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http // explaining that obsolete line folding is unacceptable, or replace // each received obs-fold with one or more SP octets prior to // interpreting the field value or forwarding the message downstream. - RejectRequest("Header value line folding not supported."); + RejectRequest(RequestRejectionReasons.HeaderValueLineFoldingNotSupported); } // Trim trailing whitespace from header value by repeatedly advancing to next @@ -1203,9 +1198,28 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http statusCode != 304; } - public void RejectRequest(string message) + private void ThrowResponseAlreadyStartedException(string value) { - var ex = new BadHttpRequestException(message); + throw new InvalidOperationException(value + " cannot be set, response had already started."); + } + + private void ThrowResponseAbortedException() + { + throw new ObjectDisposedException( + "The response has been aborted due to an unhandled application exception.", + _applicationException); + } + + public void RejectRequest(RequestRejectionReasons reason) + { + var ex = BadHttpRequestException.GetException(reason); + SetBadRequestState(ex); + throw ex; + } + + public void RejectRequest(RequestRejectionReasons reason, string value) + { + var ex = BadHttpRequestException.GetException(reason, value); SetBadRequestState(ex); throw ex; } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameHeaders.Generated.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameHeaders.Generated.cs index d72bc25e78..57da772b26 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameHeaders.Generated.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameHeaders.Generated.cs @@ -4903,7 +4903,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { if (!AsciiUtilities.TryGetAsciiString(ptr, keyBuffer, keyLength)) { - throw new BadHttpRequestException("Invalid characters in header name"); + throw BadHttpRequestException.GetException(RequestRejectionReasons.InvalidCharactersInHeaderName); } } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameHeaders.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameHeaders.cs index ba96ba8a47..ac283a006c 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameHeaders.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameHeaders.cs @@ -29,7 +29,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { if (_isReadOnly) { - ThrowReadOnlyException(); + ThrowHeadersReadOnlyException(); } SetValueFast(key, value); } @@ -48,7 +48,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } } - protected void ThrowReadOnlyException() + protected void ThrowHeadersReadOnlyException() { throw new InvalidOperationException("Headers are read-only, response has already started."); } @@ -144,7 +144,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { if (_isReadOnly) { - ThrowReadOnlyException(); + ThrowHeadersReadOnlyException(); } AddValueFast(key, value); } @@ -153,7 +153,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { if (_isReadOnly) { - ThrowReadOnlyException(); + ThrowHeadersReadOnlyException(); } ClearFast(); } @@ -200,7 +200,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { if (_isReadOnly) { - ThrowReadOnlyException(); + ThrowHeadersReadOnlyException(); } return RemoveFast(key); } @@ -226,10 +226,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { if (ch < 0x20 || ch > 0x7E) { - throw new InvalidOperationException(string.Format("Invalid non-ASCII or control character in header: 0x{0:X4}", (ushort)ch)); + ThrowInvalidHeaderCharacter(ch); } } } } + + private static void ThrowInvalidHeaderCharacter(char ch) + { + throw new InvalidOperationException(string.Format("Invalid non-ASCII or control character in header: 0x{0:X4}", (ushort)ch)); + } } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameOfT.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameOfT.cs index ae77ca679b..926cb62354 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameOfT.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameOfT.cs @@ -49,7 +49,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if (requestLineStatus != RequestLineStatus.Done) { - RejectRequest($"Malformed request: {requestLineStatus}"); + RejectRequest(RequestRejectionReasons.MalformedRequestLineStatus, requestLineStatus.ToString()); } break; @@ -70,7 +70,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http // sent immediately before the a FIN from the client. if (!TakeMessageHeaders(SocketInput, FrameRequestHeaders)) { - RejectRequest($"Malformed request: invalid headers."); + RejectRequest(RequestRejectionReasons.MalformedRequestInvalidHeaders); } break; diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/MessageBody.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/MessageBody.cs index a96119cb58..eb24417197 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/MessageBody.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/MessageBody.cs @@ -123,7 +123,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http long contentLength; if (!long.TryParse(unparsedContentLength, out contentLength) || contentLength < 0) { - context.RejectRequest($"Invalid content length: {unparsedContentLength}"); + context.RejectRequest(RequestRejectionReasons.InvalidContentLength, unparsedContentLength); } else { @@ -185,7 +185,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _inputLength -= actual; if (actual == 0) { - _context.RejectRequest("Unexpected end of request content"); + _context.RejectRequest(RequestRejectionReasons.UnexpectedEndOfRequestContent); } return new ValueTask(actual); } @@ -201,7 +201,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _inputLength -= actual; if (actual == 0) { - _context.RejectRequest("Unexpected end of request content"); + _context.RejectRequest(RequestRejectionReasons.UnexpectedEndOfRequestContent); } return actual; @@ -249,7 +249,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } else if (fin) { - ThrowChunkedRequestIncomplete(); + _context.RejectRequest(RequestRejectionReasons.ChunkedRequestIncomplete); } await input; @@ -267,7 +267,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } else if (fin) { - ThrowChunkedRequestIncomplete(); + _context.RejectRequest(RequestRejectionReasons.ChunkedRequestIncomplete); } await input; @@ -289,7 +289,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } else if (fin) { - ThrowChunkedRequestIncomplete(); + _context.RejectRequest(RequestRejectionReasons.ChunkedRequestIncomplete); } await input; @@ -307,7 +307,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } else if (fin) { - ThrowChunkedRequestIncomplete(); + _context.RejectRequest(RequestRejectionReasons.ChunkedRequestIncomplete); } await input; @@ -327,7 +327,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } else if (fin) { - ThrowChunkedRequestIncomplete(); + _context.RejectRequest(RequestRejectionReasons.ChunkedRequestIncomplete); } await input; @@ -345,7 +345,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } else { - ThrowChunkedRequestIncomplete(); + _context.RejectRequest(RequestRejectionReasons.ChunkedRequestIncomplete); } } @@ -504,7 +504,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } else { - _context.RejectRequest("Bad chunk suffix"); + _context.RejectRequest(RequestRejectionReasons.BadChunkSuffix); } } finally @@ -560,15 +560,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } } - _context.RejectRequest("Bad chunk size data"); + _context.RejectRequest(RequestRejectionReasons.BadChunkSizeData); return -1; // can't happen, but compiler complains } - private void ThrowChunkedRequestIncomplete() - { - _context.RejectRequest("Chunked request incomplete"); - } - private enum Mode { Prefix, diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/RequestRejectionReasons.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/RequestRejectionReasons.cs new file mode 100644 index 0000000000..223f6e2cf9 --- /dev/null +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/RequestRejectionReasons.cs @@ -0,0 +1,31 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http +{ + public enum RequestRejectionReasons + { + MissingMethod, + InvalidMethod, + MissingRequestTarget, + MissingHTTPVersion, + UnrecognizedHTTPVersion, + MissingLFInRequestLine, + HeadersCorruptedInvalidHeaderSequence, + HeaderLineMustNotStartWithWhitespace, + NoColonCharacterFoundInHeaderLine, + WhitespaceIsNotAllowedInHeaderName, + HeaderLineMustEndInCRLFOnlyCRFound, + HeaderValueLineFoldingNotSupported, + MalformedRequestLineStatus, + MalformedRequestInvalidHeaders, + InvalidContentLength, + UnexpectedEndOfRequestContent, + BadChunkSuffix, + BadChunkSizeData, + ChunkedRequestIncomplete, + PathContainsNullCharacters, + InvalidCharactersInHeaderName, + NonAsciiOrNullCharactersInInputString + } +} diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/UrlPathDecoder.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/UrlPathDecoder.cs index 5b639fe3c0..e40736ac20 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/UrlPathDecoder.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/UrlPathDecoder.cs @@ -67,7 +67,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if (byte1 == 0) { - throw new BadHttpRequestException("The path contains null characters."); + throw BadHttpRequestException.GetException(RequestRejectionReasons.PathContainsNullCharacters); } if (byte1 == -1) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolIteratorExtensions.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolIteratorExtensions.cs index 5845c4fa1e..a22bde2327 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolIteratorExtensions.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolIteratorExtensions.cs @@ -4,6 +4,7 @@ using System; using System.Diagnostics; using System.Text; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure { @@ -115,7 +116,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure { if (!AsciiUtilities.TryGetAsciiString(block.DataFixedPtr + inputOffset, output + outputOffset, following)) { - throw new BadHttpRequestException("The input string contains non-ASCII or null characters."); + throw BadHttpRequestException.GetException(RequestRejectionReasons.NonAsciiOrNullCharactersInInputString); } outputOffset += following; diff --git a/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/KnownHeaders.cs b/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/KnownHeaders.cs index 53dff0dd53..ca222eeb1f 100644 --- a/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/KnownHeaders.cs +++ b/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/KnownHeaders.cs @@ -450,7 +450,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http {{ if (!AsciiUtilities.TryGetAsciiString(ptr, keyBuffer, keyLength)) {{ - throw new BadHttpRequestException(""Invalid characters in header name""); + throw BadHttpRequestException.GetException(RequestRejectionReasons.InvalidCharactersInHeaderName); }} }} }} From 0a1ea124ee379bf75785e8294b1d8db365df55cc Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Thu, 21 Jul 2016 22:51:53 +0100 Subject: [PATCH 0827/1662] Use HttpVersionType enum rather than string compare --- .../Internal/Http/Frame.cs | 29 +++++++------------ .../Internal/Http/FrameOfT.cs | 2 +- .../Internal/Http/HttpVersion.cs | 12 ++++++++ .../Internal/Http/MessageBody.cs | 5 ++-- .../FrameTests.cs | 2 +- .../MessageBodyTests.cs | 6 ++-- 6 files changed, 30 insertions(+), 26 deletions(-) create mode 100644 src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/HttpVersion.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs index 894b185dd5..e5c41fa0dd 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs @@ -61,7 +61,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http private bool _autoChunk; protected Exception _applicationException; - private HttpVersionType _httpVersion; + protected HttpVersion _httpVersion; private readonly string _pathBase; @@ -89,11 +89,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { get { - if (_httpVersion == HttpVersionType.Http11) + if (_httpVersion == Http.HttpVersion.Http11) { return "HTTP/1.1"; } - if (_httpVersion == HttpVersionType.Http10) + if (_httpVersion == Http.HttpVersion.Http10) { return "HTTP/1.0"; } @@ -104,15 +104,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { if (value == "HTTP/1.1") { - _httpVersion = HttpVersionType.Http11; + _httpVersion = Http.HttpVersion.Http11; } else if (value == "HTTP/1.0") { - _httpVersion = HttpVersionType.Http10; + _httpVersion = Http.HttpVersion.Http10; } else { - _httpVersion = HttpVersionType.Unset; + _httpVersion = Http.HttpVersion.Unset; } } } @@ -290,7 +290,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http PathBase = null; Path = null; QueryString = null; - _httpVersion = HttpVersionType.Unset; + _httpVersion = Http.HttpVersion.Unset; StatusCode = 200; ReasonPhrase = null; @@ -547,7 +547,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } StringValues expect; - if (_httpVersion == HttpVersionType.Http11 && + if (_httpVersion == Http.HttpVersion.Http11 && RequestHeaders.TryGetValue("Expect", out expect) && (expect.FirstOrDefault() ?? "").Equals("100-continue", StringComparison.OrdinalIgnoreCase)) { @@ -749,7 +749,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http // // A server MUST NOT send a response containing Transfer-Encoding unless the corresponding // request indicates HTTP/1.1 (or later). - if (_httpVersion == HttpVersionType.Http11) + if (_httpVersion == Http.HttpVersion.Http11) { _autoChunk = true; responseHeaders.SetRawTransferEncoding("chunked", _bytesTransferEncodingChunked); @@ -761,11 +761,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } } - if (!_keepAlive && !hasConnection && _httpVersion != HttpVersionType.Http10) + if (!_keepAlive && !hasConnection && _httpVersion != Http.HttpVersion.Http10) { responseHeaders.SetRawConnection("close", _bytesConnectionClose); } - else if (_keepAlive && !hasConnection && _httpVersion == HttpVersionType.Http10) + else if (_keepAlive && !hasConnection && _httpVersion == Http.HttpVersion.Http10) { responseHeaders.SetRawConnection("keep-alive", _bytesConnectionKeepAlive); } @@ -1235,13 +1235,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http Log.ApplicationError(ConnectionId, ex); } - private enum HttpVersionType - { - Unset = -1, - Http10 = 0, - Http11 = 1 - } - protected enum RequestLineStatus { Empty, diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameOfT.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameOfT.cs index ae77ca679b..bc6cb8ad45 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameOfT.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameOfT.cs @@ -81,7 +81,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if (!_requestProcessingStopping) { - var messageBody = MessageBody.For(HttpVersion, FrameRequestHeaders, this); + var messageBody = MessageBody.For(_httpVersion, FrameRequestHeaders, this); _keepAlive = messageBody.RequestKeepAlive; InitializeStreams(messageBody); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/HttpVersion.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/HttpVersion.cs new file mode 100644 index 0000000000..67712ec54d --- /dev/null +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/HttpVersion.cs @@ -0,0 +1,12 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http +{ + public enum HttpVersion + { + Unset = -1, + Http10 = 0, + Http11 = 1 + } +} diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/MessageBody.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/MessageBody.cs index a96119cb58..d7b8430d28 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/MessageBody.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/MessageBody.cs @@ -97,13 +97,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http public abstract ValueTask ReadAsyncImplementation(ArraySegment buffer, CancellationToken cancellationToken); public static MessageBody For( - string httpVersion, + HttpVersion httpVersion, FrameRequestHeaders headers, Frame context) { // see also http://tools.ietf.org/html/rfc2616#section-4.4 - - var keepAlive = httpVersion != "HTTP/1.0"; + var keepAlive = httpVersion != HttpVersion.Http10; var connection = headers.HeaderConnection.ToString(); if (connection.Length > 0) diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs index c7ada35248..876b0279f5 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs @@ -502,7 +502,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var frame = new Frame(application: null, context: connectionContext); frame.InitializeHeaders(); - var messageBody = MessageBody.For("HTTP/1.1", (FrameRequestHeaders)frame.RequestHeaders, frame); + var messageBody = MessageBody.For(HttpVersion.Http11, (FrameRequestHeaders)frame.RequestHeaders, frame); frame.InitializeStreams(messageBody); var originalRequestBody = frame.RequestBody; diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/MessageBodyTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/MessageBodyTests.cs index f8dba124ef..2dcb19ffef 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/MessageBodyTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/MessageBodyTests.cs @@ -19,7 +19,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { using (var input = new TestInput()) { - var body = MessageBody.For("HTTP/1.0", new FrameRequestHeaders(), input.FrameContext); + var body = MessageBody.For(HttpVersion.Http10, new FrameRequestHeaders(), input.FrameContext); var stream = new FrameRequestStream(); stream.StartAcceptingReads(body); @@ -40,7 +40,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { using (var input = new TestInput()) { - var body = MessageBody.For("HTTP/1.0", new FrameRequestHeaders(), input.FrameContext); + var body = MessageBody.For(HttpVersion.Http10, new FrameRequestHeaders(), input.FrameContext); var stream = new FrameRequestStream(); stream.StartAcceptingReads(body); @@ -61,7 +61,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { using (var input = new TestInput()) { - var body = MessageBody.For("HTTP/1.0", new FrameRequestHeaders(), input.FrameContext); + var body = MessageBody.For(HttpVersion.Http10, new FrameRequestHeaders(), input.FrameContext); var stream = new FrameRequestStream(); stream.StartAcceptingReads(body); From 51288e13f85f98dd290164297b64ba771fea0fc4 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Fri, 22 Jul 2016 22:19:50 +0100 Subject: [PATCH 0828/1662] Enum to singular --- .../BadHttpRequestException.cs | 56 +++++++++---------- .../Internal/Http/Frame.cs | 32 +++++------ .../Internal/Http/FrameHeaders.Generated.cs | 2 +- .../Internal/Http/FrameOfT.cs | 4 +- .../Internal/Http/MessageBody.cs | 22 ++++---- ...onReasons.cs => RequestRejectionReason.cs} | 2 +- .../Internal/Http/UrlPathDecoder.cs | 2 +- .../MemoryPoolIteratorExtensions.cs | 2 +- .../KnownHeaders.cs | 2 +- 9 files changed, 62 insertions(+), 62 deletions(-) rename src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/{RequestRejectionReasons.cs => RequestRejectionReason.cs} (96%) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/BadHttpRequestException.cs b/src/Microsoft.AspNetCore.Server.Kestrel/BadHttpRequestException.cs index e227882f7b..95ecedb930 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/BadHttpRequestException.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/BadHttpRequestException.cs @@ -14,69 +14,69 @@ namespace Microsoft.AspNetCore.Server.Kestrel } - internal static BadHttpRequestException GetException(RequestRejectionReasons reason) + internal static BadHttpRequestException GetException(RequestRejectionReason reason) { BadHttpRequestException ex; switch (reason) { - case RequestRejectionReasons.MissingMethod: + case RequestRejectionReason.MissingMethod: ex = new BadHttpRequestException("Missing method."); break; - case RequestRejectionReasons.InvalidMethod: + case RequestRejectionReason.InvalidMethod: ex = new BadHttpRequestException("Invalid method."); break; - case RequestRejectionReasons.MissingRequestTarget: + case RequestRejectionReason.MissingRequestTarget: ex = new BadHttpRequestException("Missing request target."); break; - case RequestRejectionReasons.MissingHTTPVersion: + case RequestRejectionReason.MissingHTTPVersion: ex = new BadHttpRequestException("Missing HTTP version."); break; - case RequestRejectionReasons.UnrecognizedHTTPVersion: + case RequestRejectionReason.UnrecognizedHTTPVersion: ex = new BadHttpRequestException("Unrecognized HTTP version."); break; - case RequestRejectionReasons.MissingLFInRequestLine: + case RequestRejectionReason.MissingLFInRequestLine: ex = new BadHttpRequestException("Missing LF in request line."); break; - case RequestRejectionReasons.HeadersCorruptedInvalidHeaderSequence: + case RequestRejectionReason.HeadersCorruptedInvalidHeaderSequence: ex = new BadHttpRequestException("Headers corrupted, invalid header sequence."); break; - case RequestRejectionReasons.HeaderLineMustNotStartWithWhitespace: + case RequestRejectionReason.HeaderLineMustNotStartWithWhitespace: ex = new BadHttpRequestException("Header line must not start with whitespace."); break; - case RequestRejectionReasons.NoColonCharacterFoundInHeaderLine: + case RequestRejectionReason.NoColonCharacterFoundInHeaderLine: ex = new BadHttpRequestException("No ':' character found in header line."); break; - case RequestRejectionReasons.WhitespaceIsNotAllowedInHeaderName: + case RequestRejectionReason.WhitespaceIsNotAllowedInHeaderName: ex = new BadHttpRequestException("Whitespace is not allowed in header name."); break; - case RequestRejectionReasons.HeaderLineMustEndInCRLFOnlyCRFound: + case RequestRejectionReason.HeaderLineMustEndInCRLFOnlyCRFound: ex = new BadHttpRequestException("Header line must end in CRLF; only CR found."); break; - case RequestRejectionReasons.HeaderValueLineFoldingNotSupported: + case RequestRejectionReason.HeaderValueLineFoldingNotSupported: ex = new BadHttpRequestException("Header value line folding not supported."); break; - case RequestRejectionReasons.MalformedRequestInvalidHeaders: + case RequestRejectionReason.MalformedRequestInvalidHeaders: ex = new BadHttpRequestException("Malformed request: invalid headers."); break; - case RequestRejectionReasons.UnexpectedEndOfRequestContent: - ex = new BadHttpRequestException("Unexpected end of request content"); + case RequestRejectionReason.UnexpectedEndOfRequestContent: + ex = new BadHttpRequestException("Unexpected end of request content."); break; - case RequestRejectionReasons.BadChunkSuffix: - ex = new BadHttpRequestException("Bad chunk suffix"); + case RequestRejectionReason.BadChunkSuffix: + ex = new BadHttpRequestException("Bad chunk suffix."); break; - case RequestRejectionReasons.BadChunkSizeData: - ex = new BadHttpRequestException("Bad chunk size data"); + case RequestRejectionReason.BadChunkSizeData: + ex = new BadHttpRequestException("Bad chunk size data."); break; - case RequestRejectionReasons.ChunkedRequestIncomplete: - ex = new BadHttpRequestException("Chunked request incomplete"); + case RequestRejectionReason.ChunkedRequestIncomplete: + ex = new BadHttpRequestException("Chunked request incomplete."); break; - case RequestRejectionReasons.PathContainsNullCharacters: + case RequestRejectionReason.PathContainsNullCharacters: ex = new BadHttpRequestException("The path contains null characters."); break; - case RequestRejectionReasons.InvalidCharactersInHeaderName: + case RequestRejectionReason.InvalidCharactersInHeaderName: ex = new BadHttpRequestException("Invalid characters in header name."); break; - case RequestRejectionReasons.NonAsciiOrNullCharactersInInputString: + case RequestRejectionReason.NonAsciiOrNullCharactersInInputString: ex = new BadHttpRequestException("The input string contains non-ASCII or null characters."); break; default: @@ -86,15 +86,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel return ex; } - internal static BadHttpRequestException GetException(RequestRejectionReasons reason, string value) + internal static BadHttpRequestException GetException(RequestRejectionReason reason, string value) { BadHttpRequestException ex; switch (reason) { - case RequestRejectionReasons.MalformedRequestLineStatus: + case RequestRejectionReason.MalformedRequestLineStatus: ex = new BadHttpRequestException($"Malformed request: {value}"); break; - case RequestRejectionReasons.InvalidContentLength: + case RequestRejectionReason.InvalidContentLength: ex = new BadHttpRequestException($"Invalid content length: {value}"); break; default: diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs index cc9806a1a9..636c3f28b0 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs @@ -814,7 +814,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if (method == null) { - RejectRequest(RequestRejectionReasons.MissingMethod); + RejectRequest(RequestRejectionReason.MissingMethod); } // Note: We're not in the fast path any more (GetKnownMethod should have handled any HTTP Method we're aware of) @@ -823,7 +823,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { if (!IsValidTokenChar(method[i])) { - RejectRequest(RequestRejectionReasons.InvalidMethod); + RejectRequest(RequestRejectionReason.InvalidMethod); } } } @@ -868,7 +868,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if (pathBegin.Peek() == ' ') { - RejectRequest(RequestRejectionReasons.MissingRequestTarget); + RejectRequest(RequestRejectionReason.MissingRequestTarget); } scan.Take(); @@ -890,11 +890,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if (httpVersion == null) { - RejectRequest(RequestRejectionReasons.MissingHTTPVersion); + RejectRequest(RequestRejectionReason.MissingHTTPVersion); } else if (httpVersion != "HTTP/1.0" && httpVersion != "HTTP/1.1") { - RejectRequest(RequestRejectionReasons.UnrecognizedHTTPVersion); + RejectRequest(RequestRejectionReason.UnrecognizedHTTPVersion); } } @@ -906,7 +906,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } else if (next != '\n') { - RejectRequest(RequestRejectionReasons.MissingLFInRequestLine); + RejectRequest(RequestRejectionReason.MissingLFInRequestLine); } // URIs are always encoded/escaped to ASCII https://tools.ietf.org/html/rfc3986#page-11 @@ -1060,11 +1060,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } // Headers don't end in CRLF line. - RejectRequest(RequestRejectionReasons.HeadersCorruptedInvalidHeaderSequence); + RejectRequest(RequestRejectionReason.HeadersCorruptedInvalidHeaderSequence); } else if (ch == ' ' || ch == '\t') { - RejectRequest(RequestRejectionReasons.HeaderLineMustNotStartWithWhitespace); + RejectRequest(RequestRejectionReason.HeaderLineMustNotStartWithWhitespace); } var beginName = scan; @@ -1077,13 +1077,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http ch = scan.Take(); if (ch != ':') { - RejectRequest(RequestRejectionReasons.NoColonCharacterFoundInHeaderLine); + RejectRequest(RequestRejectionReason.NoColonCharacterFoundInHeaderLine); } var validateName = beginName; if (validateName.Seek(ref _vectorSpaces, ref _vectorTabs, ref _vectorColons) != ':') { - RejectRequest(RequestRejectionReasons.WhitespaceIsNotAllowedInHeaderName); + RejectRequest(RequestRejectionReason.WhitespaceIsNotAllowedInHeaderName); } var beginValue = scan; @@ -1123,7 +1123,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } else if (ch != '\n') { - RejectRequest(RequestRejectionReasons.HeaderLineMustEndInCRLFOnlyCRFound); + RejectRequest(RequestRejectionReason.HeaderLineMustEndInCRLFOnlyCRFound); } var next = scan.Peek(); @@ -1150,7 +1150,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http // explaining that obsolete line folding is unacceptable, or replace // each received obs-fold with one or more SP octets prior to // interpreting the field value or forwarding the message downstream. - RejectRequest(RequestRejectionReasons.HeaderValueLineFoldingNotSupported); + RejectRequest(RequestRejectionReason.HeaderValueLineFoldingNotSupported); } // Trim trailing whitespace from header value by repeatedly advancing to next @@ -1206,18 +1206,18 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http private void ThrowResponseAbortedException() { throw new ObjectDisposedException( - "The response has been aborted due to an unhandled application exception.", - _applicationException); + "The response has been aborted due to an unhandled application exception.", + _applicationException); } - public void RejectRequest(RequestRejectionReasons reason) + public void RejectRequest(RequestRejectionReason reason) { var ex = BadHttpRequestException.GetException(reason); SetBadRequestState(ex); throw ex; } - public void RejectRequest(RequestRejectionReasons reason, string value) + public void RejectRequest(RequestRejectionReason reason, string value) { var ex = BadHttpRequestException.GetException(reason, value); SetBadRequestState(ex); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameHeaders.Generated.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameHeaders.Generated.cs index 57da772b26..d49d47deef 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameHeaders.Generated.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameHeaders.Generated.cs @@ -4903,7 +4903,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { if (!AsciiUtilities.TryGetAsciiString(ptr, keyBuffer, keyLength)) { - throw BadHttpRequestException.GetException(RequestRejectionReasons.InvalidCharactersInHeaderName); + throw BadHttpRequestException.GetException(RequestRejectionReason.InvalidCharactersInHeaderName); } } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameOfT.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameOfT.cs index 926cb62354..e4ff9d7e75 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameOfT.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameOfT.cs @@ -49,7 +49,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if (requestLineStatus != RequestLineStatus.Done) { - RejectRequest(RequestRejectionReasons.MalformedRequestLineStatus, requestLineStatus.ToString()); + RejectRequest(RequestRejectionReason.MalformedRequestLineStatus, requestLineStatus.ToString()); } break; @@ -70,7 +70,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http // sent immediately before the a FIN from the client. if (!TakeMessageHeaders(SocketInput, FrameRequestHeaders)) { - RejectRequest(RequestRejectionReasons.MalformedRequestInvalidHeaders); + RejectRequest(RequestRejectionReason.MalformedRequestInvalidHeaders); } break; diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/MessageBody.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/MessageBody.cs index eb24417197..1d34c2fe28 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/MessageBody.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/MessageBody.cs @@ -123,7 +123,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http long contentLength; if (!long.TryParse(unparsedContentLength, out contentLength) || contentLength < 0) { - context.RejectRequest(RequestRejectionReasons.InvalidContentLength, unparsedContentLength); + context.RejectRequest(RequestRejectionReason.InvalidContentLength, unparsedContentLength); } else { @@ -185,7 +185,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _inputLength -= actual; if (actual == 0) { - _context.RejectRequest(RequestRejectionReasons.UnexpectedEndOfRequestContent); + _context.RejectRequest(RequestRejectionReason.UnexpectedEndOfRequestContent); } return new ValueTask(actual); } @@ -201,7 +201,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _inputLength -= actual; if (actual == 0) { - _context.RejectRequest(RequestRejectionReasons.UnexpectedEndOfRequestContent); + _context.RejectRequest(RequestRejectionReason.UnexpectedEndOfRequestContent); } return actual; @@ -249,7 +249,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } else if (fin) { - _context.RejectRequest(RequestRejectionReasons.ChunkedRequestIncomplete); + _context.RejectRequest(RequestRejectionReason.ChunkedRequestIncomplete); } await input; @@ -267,7 +267,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } else if (fin) { - _context.RejectRequest(RequestRejectionReasons.ChunkedRequestIncomplete); + _context.RejectRequest(RequestRejectionReason.ChunkedRequestIncomplete); } await input; @@ -289,7 +289,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } else if (fin) { - _context.RejectRequest(RequestRejectionReasons.ChunkedRequestIncomplete); + _context.RejectRequest(RequestRejectionReason.ChunkedRequestIncomplete); } await input; @@ -307,7 +307,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } else if (fin) { - _context.RejectRequest(RequestRejectionReasons.ChunkedRequestIncomplete); + _context.RejectRequest(RequestRejectionReason.ChunkedRequestIncomplete); } await input; @@ -327,7 +327,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } else if (fin) { - _context.RejectRequest(RequestRejectionReasons.ChunkedRequestIncomplete); + _context.RejectRequest(RequestRejectionReason.ChunkedRequestIncomplete); } await input; @@ -345,7 +345,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } else { - _context.RejectRequest(RequestRejectionReasons.ChunkedRequestIncomplete); + _context.RejectRequest(RequestRejectionReason.ChunkedRequestIncomplete); } } @@ -504,7 +504,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } else { - _context.RejectRequest(RequestRejectionReasons.BadChunkSuffix); + _context.RejectRequest(RequestRejectionReason.BadChunkSuffix); } } finally @@ -560,7 +560,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } } - _context.RejectRequest(RequestRejectionReasons.BadChunkSizeData); + _context.RejectRequest(RequestRejectionReason.BadChunkSizeData); return -1; // can't happen, but compiler complains } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/RequestRejectionReasons.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/RequestRejectionReason.cs similarity index 96% rename from src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/RequestRejectionReasons.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/RequestRejectionReason.cs index 223f6e2cf9..83ea024a5d 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/RequestRejectionReasons.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/RequestRejectionReason.cs @@ -3,7 +3,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { - public enum RequestRejectionReasons + public enum RequestRejectionReason { MissingMethod, InvalidMethod, diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/UrlPathDecoder.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/UrlPathDecoder.cs index e40736ac20..67004cf24f 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/UrlPathDecoder.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/UrlPathDecoder.cs @@ -67,7 +67,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if (byte1 == 0) { - throw BadHttpRequestException.GetException(RequestRejectionReasons.PathContainsNullCharacters); + throw BadHttpRequestException.GetException(RequestRejectionReason.PathContainsNullCharacters); } if (byte1 == -1) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolIteratorExtensions.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolIteratorExtensions.cs index a22bde2327..dcaf4f0fcf 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolIteratorExtensions.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolIteratorExtensions.cs @@ -116,7 +116,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure { if (!AsciiUtilities.TryGetAsciiString(block.DataFixedPtr + inputOffset, output + outputOffset, following)) { - throw BadHttpRequestException.GetException(RequestRejectionReasons.NonAsciiOrNullCharactersInInputString); + throw BadHttpRequestException.GetException(RequestRejectionReason.NonAsciiOrNullCharactersInInputString); } outputOffset += following; diff --git a/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/KnownHeaders.cs b/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/KnownHeaders.cs index ca222eeb1f..b88e75d79b 100644 --- a/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/KnownHeaders.cs +++ b/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/KnownHeaders.cs @@ -450,7 +450,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http {{ if (!AsciiUtilities.TryGetAsciiString(ptr, keyBuffer, keyLength)) {{ - throw BadHttpRequestException.GetException(RequestRejectionReasons.InvalidCharactersInHeaderName); + throw BadHttpRequestException.GetException(RequestRejectionReason.InvalidCharactersInHeaderName); }} }} }} From 0ab04d7e738afb0957bef86b8cc7196608349755 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Fri, 22 Jul 2016 22:44:38 +0100 Subject: [PATCH 0829/1662] Tests to makes sure known strings are interned --- .../MemoryPoolIteratorTests.cs | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolIteratorTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolIteratorTests.cs index 803cf52d61..b415cda7a3 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolIteratorTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolIteratorTests.cs @@ -381,5 +381,58 @@ namespace Microsoft.AspNetCore.Server.KestrelTests _pool.Return(block); } + + [Theory] + [InlineData("HTTP/1.0\r", "HTTP/1.0")] + [InlineData("HTTP/1.1\r", "HTTP/1.1")] + public void KnownVersionsAreInterned(string input, string expected) + { + TestKnownStringsInterning(input, expected, MemoryPoolIteratorExtensions.GetKnownVersion); + } + + [Theory] + [InlineData("CONNECT / HTTP/1.1", "CONNECT")] + [InlineData("DELETE / HTTP/1.1", "DELETE")] + [InlineData("GET / HTTP/1.1", "GET")] + [InlineData("HEAD / HTTP/1.1", "HEAD")] + [InlineData("PATCH / HTTP/1.1", "PATCH")] + [InlineData("POST / HTTP/1.1", "POST")] + [InlineData("PUT / HTTP/1.1", "PUT")] + [InlineData("OPTIONS / HTTP/1.1", "OPTIONS")] + [InlineData("TRACE / HTTP/1.1", "TRACE")] + public void KnownMethodsAreInterned(string input, string expected) + { + TestKnownStringsInterning(input, expected, MemoryPoolIteratorExtensions.GetKnownMethod); + } + + private delegate bool GetKnownString(MemoryPoolIterator iter, out string result); + + private void TestKnownStringsInterning(string input, string expected, GetKnownString action) + { + // Arrange + var chars = input.ToCharArray().Select(c => (byte)c).ToArray(); + var block1 = _pool.Lease(); + var block2 = _pool.Lease(); + Buffer.BlockCopy(chars, 0, block1.Array, block1.Start, chars.Length); + Buffer.BlockCopy(chars, 0, block2.Array, block2.Start, chars.Length); + block1.End += chars.Length; + block2.End += chars.Length; + var begin1 = block1.GetIterator(); + var begin2 = block2.GetIterator(); + + // Act + string knownString1, knownString2; + var result1 = action(begin1, out knownString1); + var result2 = action(begin2, out knownString2); + + _pool.Return(block1); + _pool.Return(block2); + + // Assert + Assert.True(result1); + Assert.True(result2); + Assert.Equal(knownString1, expected); + Assert.Same(knownString1, knownString2); + } } } \ No newline at end of file From dc12f3150ee04f1edf808d4a805b7f995a7cb4a7 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Tue, 19 Jul 2016 16:49:19 -0700 Subject: [PATCH 0830/1662] Wait for graceful shutdown now that it usually works - Unreference the async handle to allow the loop to stop without walking first - Wait before walking open handles to allow earlier uv_close calls to complete --- .../Internal/Infrastructure/KestrelThread.cs | 34 +++++++++++-------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/KestrelThread.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/KestrelThread.cs index 47f56ef229..02ad95bd75 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/KestrelThread.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/KestrelThread.cs @@ -105,34 +105,40 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal } } + var stepTimeout = (int)(timeout.TotalMilliseconds / 3); + if (_thread.IsAlive) { // These operations need to run on the libuv thread so it only makes // sense to attempt execution if it's still running DisposeConnections(); - var stepTimeout = (int)(timeout.TotalMilliseconds / 2); - try + Post(t => t.AllowStop()); + if (!_thread.Join(stepTimeout)) { - Post(t => t.OnStopRude()); - if (!_thread.Join(stepTimeout)) + + try { - Post(t => t.OnStopImmediate()); + Post(t => t.OnStopRude()); + if (!_thread.Join(stepTimeout)) + { + Post(t => t.OnStopImmediate()); + if (!_thread.Join(stepTimeout)) + { + _log.LogError(0, null, "KestrelThread.Stop failed to terminate libuv thread."); + } + } + } + catch (ObjectDisposedException) + { + // REVIEW: Should we log something here? + // Until we rework this logic, ODEs are bound to happen sometimes. if (!_thread.Join(stepTimeout)) { _log.LogError(0, null, "KestrelThread.Stop failed to terminate libuv thread."); } } } - catch (ObjectDisposedException) - { - // REVIEW: Should we log something here? - // Until we rework this logic, ODEs are bound to happen sometimes. - if (!_thread.Join(stepTimeout)) - { - _log.LogError(0, null, "KestrelThread.Stop failed to terminate libuv thread."); - } - } } if (_closeError != null) From b5c117695eb818578e40140256e4778510c7686d Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Fri, 22 Jul 2016 14:58:45 -0700 Subject: [PATCH 0831/1662] Stop KestrelThreads in parallel --- .../Internal/Http/ConnectionManager.cs | 12 ++-- .../Internal/Infrastructure/KestrelThread.cs | 57 +++++++++++-------- .../Internal/KestrelEngine.cs | 19 +++---- 3 files changed, 46 insertions(+), 42 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ConnectionManager.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ConnectionManager.cs index a936855a09..561f45ee06 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ConnectionManager.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ConnectionManager.cs @@ -21,16 +21,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _threadPool = threadPool; } - public bool WalkConnectionsAndClose(TimeSpan timeout) + public async Task WalkConnectionsAndCloseAsync(TimeSpan timeout) { - var wh = new ManualResetEventSlim(); + var tcs = new TaskCompletionSource(); - _thread.Post(state => ((ConnectionManager)state).WalkConnectionsAndCloseCore(wh), this); + _thread.Post(state => ((ConnectionManager)state).WalkConnectionsAndCloseCore(tcs), this); - return wh.Wait(timeout); + return await Task.WhenAny(tcs.Task, Task.Delay(timeout)).ConfigureAwait(false) == tcs.Task; } - private void WalkConnectionsAndCloseCore(ManualResetEventSlim wh) + private void WalkConnectionsAndCloseCore(TaskCompletionSource tcs) { var connectionStopTasks = new List(); @@ -48,7 +48,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _threadPool.Run(() => { Task.WaitAll(connectionStopTasks.ToArray()); - wh.Set(); + tcs.SetResult(null); }); } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/KestrelThread.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/KestrelThread.cs index 02ad95bd75..083ecf29f6 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/KestrelThread.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/KestrelThread.cs @@ -30,6 +30,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal private readonly KestrelEngine _engine; private readonly IApplicationLifetime _appLifetime; private readonly Thread _thread; + private readonly TaskCompletionSource _threadTcs = new TaskCompletionSource(); private readonly UvLoopHandle _loop; private readonly UvAsyncHandle _post; private Queue _workAdding = new Queue(1024); @@ -89,13 +90,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal return tcs.Task; } - // This must be called from the libuv event loop. - public void AllowStop() - { - _post.Unreference(); - } - - public void Stop(TimeSpan timeout) + public async Task StopAsync(TimeSpan timeout) { lock (_startSync) { @@ -105,27 +100,26 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal } } - var stepTimeout = (int)(timeout.TotalMilliseconds / 3); - - if (_thread.IsAlive) + if (!_threadTcs.Task.IsCompleted) { // These operations need to run on the libuv thread so it only makes // sense to attempt execution if it's still running - DisposeConnections(); + await DisposeConnectionsAsync().ConfigureAwait(false); + + var stepTimeout = TimeSpan.FromTicks(timeout.Ticks / 3); Post(t => t.AllowStop()); - if (!_thread.Join(stepTimeout)) + if (!await WaitAsync(_threadTcs.Task, stepTimeout).ConfigureAwait(false)) { - try { Post(t => t.OnStopRude()); - if (!_thread.Join(stepTimeout)) + if (!await WaitAsync(_threadTcs.Task, stepTimeout).ConfigureAwait(false)) { Post(t => t.OnStopImmediate()); - if (!_thread.Join(stepTimeout)) + if (!await WaitAsync(_threadTcs.Task, stepTimeout).ConfigureAwait(false)) { - _log.LogError(0, null, "KestrelThread.Stop failed to terminate libuv thread."); + _log.LogError(0, null, "KestrelThread.StopAsync failed to terminate libuv thread."); } } } @@ -133,9 +127,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal { // REVIEW: Should we log something here? // Until we rework this logic, ODEs are bound to happen sometimes. - if (!_thread.Join(stepTimeout)) + if (!await WaitAsync(_threadTcs.Task, stepTimeout).ConfigureAwait(false)) { - _log.LogError(0, null, "KestrelThread.Stop failed to terminate libuv thread."); + _log.LogError(0, null, "KestrelThread.StopAsync failed to terminate libuv thread."); } } } @@ -147,22 +141,22 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal } } - private void DisposeConnections() + private async Task DisposeConnectionsAsync() { try { // Close and wait for all connections - if (!ConnectionManager.WalkConnectionsAndClose(_shutdownTimeout)) + if (!await ConnectionManager.WalkConnectionsAndCloseAsync(_shutdownTimeout).ConfigureAwait(false)) { - _log.LogError(0, null, "Waiting for connections timed out"); + _log.NotAllConnectionsClosedGracefully(); } - var result = PostAsync(state => + var result = await WaitAsync(PostAsync(state => { var listener = (KestrelThread)state; listener.WriteReqPool.Dispose(); }, - this).Wait(_shutdownTimeout); + this), _shutdownTimeout).ConfigureAwait(false); if (!result) { @@ -175,6 +169,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal } } + + private void AllowStop() + { + _post.Unreference(); + } + private void OnStopRude() { Walk(ptr => @@ -262,7 +262,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal { lock (_startSync) { - var tcs = (TaskCompletionSource)parameter; + var tcs = (TaskCompletionSource) parameter; try { _loop.Init(_engine.Libuv); @@ -302,6 +302,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal // in Stop which should be observable. _appLifetime.StopApplication(); } + finally + { + _threadTcs.SetResult(null); + } } private void OnPost() @@ -385,6 +389,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal return wasWork; } + private static async Task WaitAsync(Task task, TimeSpan timeout) + { + return await Task.WhenAny(task, Task.Delay(timeout)).ConfigureAwait(false) == task; + } + private struct Work { public Action CallbackAdapter; diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/KestrelEngine.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/KestrelEngine.cs index a3faaad6a4..bdc9c70862 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/KestrelEngine.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/KestrelEngine.cs @@ -3,9 +3,11 @@ using System; using System.Collections.Generic; +using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; +using Microsoft.Extensions.Logging; namespace Microsoft.AspNetCore.Server.Kestrel.Internal { @@ -41,10 +43,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal public void Dispose() { - foreach (var thread in Threads) - { - thread.Stop(TimeSpan.FromSeconds(2.5)); - } + Task.WaitAll(Threads.Select(thread => thread.StopAsync(TimeSpan.FromSeconds(2.5))).ToArray()); + Threads.Clear(); } @@ -107,16 +107,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal private void DisposeListeners(List listeners) { - var disposeTasks = new List(); + var disposeTasks = listeners.Select(listener => listener.DisposeAsync()).ToArray(); - foreach (var listener in listeners) + if (!Task.WaitAll(disposeTasks, TimeSpan.FromSeconds(2.5))) { - disposeTasks.Add(listener.DisposeAsync()); - } - - if (!Task.WhenAll(disposeTasks).Wait(ServerOptions.ShutdownTimeout)) - { - Log.NotAllConnectionsClosedGracefully(); + Log.LogError(0, null, "Disposing listeners failed"); } } } From 5d6da35cb921f0defc55b854079ad7dded4da333 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Tue, 26 Jul 2016 11:45:57 -0700 Subject: [PATCH 0832/1662] Add test verifying a chunked response can be written manually --- .../ChunkedResponseTests.cs | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedResponseTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedResponseTests.cs index 62758e36a1..1427cfc90a 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedResponseTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedResponseTests.cs @@ -227,6 +227,42 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } } } + + [Theory] + [MemberData(nameof(ConnectionFilterData))] + public async Task ChunksCanBeWrittenManually(TestServiceContext testContext) + { + using (var server = new TestServer(async httpContext => + { + var response = httpContext.Response; + response.Headers["Transfer-Encoding"] = "chunked"; + + await response.Body.WriteAsync(Encoding.ASCII.GetBytes("6\r\nHello \r\n"), 0, 11); + await response.Body.WriteAsync(Encoding.ASCII.GetBytes("6\r\nWorld!\r\n"), 0, 11); + await response.Body.WriteAsync(Encoding.ASCII.GetBytes("0\r\n\r\n"), 0, 5); + }, testContext)) + { + using (var connection = server.CreateConnection()) + { + await connection.SendEnd( + "GET / HTTP/1.1", + "", + ""); + await connection.ReceiveEnd( + "HTTP/1.1 200 OK", + $"Date: {testContext.DateHeaderValue}", + "Transfer-Encoding: chunked", + "", + "6", + "Hello ", + "6", + "World!", + "0", + "", + ""); + } + } + } } } From 4ece3f4b68d7d754adbd07bd70f4869e39679dd7 Mon Sep 17 00:00:00 2001 From: Mike Harder Date: Mon, 1 Aug 2016 11:09:31 -0700 Subject: [PATCH 0833/1662] Change "String." to "string." to match coding convention --- src/Microsoft.AspNetCore.Server.Kestrel/ServerAddress.cs | 2 +- .../TestConnection.cs | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/ServerAddress.cs b/src/Microsoft.AspNetCore.Server.Kestrel/ServerAddress.cs index 67d00e1700..4771fe54f7 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/ServerAddress.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/ServerAddress.cs @@ -37,7 +37,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel { if (IsUnixPipe) { - if (String.IsNullOrEmpty(PathBase)) + if (string.IsNullOrEmpty(PathBase)) { return Scheme.ToLowerInvariant() + "://" + Host.ToLowerInvariant(); } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestConnection.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/TestConnection.cs index 41ed1501f6..5c54ca7d13 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/TestConnection.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/TestConnection.cs @@ -45,7 +45,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests public async Task SendAll(params string[] lines) { - var text = String.Join("\r\n", lines); + var text = string.Join("\r\n", lines); var writer = new StreamWriter(_stream, Encoding.GetEncoding("iso-8859-1")); await writer.WriteAsync(text); writer.Flush(); @@ -70,7 +70,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests public async Task Send(params string[] lines) { - var text = String.Join("\r\n", lines); + var text = string.Join("\r\n", lines); var writer = new StreamWriter(_stream, Encoding.GetEncoding("iso-8859-1")); for (var index = 0; index < text.Length; index++) { @@ -92,7 +92,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests public async Task Receive(params string[] lines) { - var expected = String.Join("\r\n", lines); + var expected = string.Join("\r\n", lines); var actual = new char[expected.Length]; var offset = 0; while (offset < expected.Length) From 138f23b24645c1dfe0f0077f3b89584cff4da854 Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Tue, 2 Aug 2016 12:26:17 -0700 Subject: [PATCH 0834/1662] Remove TestServer dependency from TestConnection. --- .../BadHttpRequestTests.cs | 14 +++++++------- .../EngineTests.cs | 2 +- .../TestConnection.cs | 7 ++----- .../TestServer.cs | 2 +- 4 files changed, 11 insertions(+), 14 deletions(-) diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/BadHttpRequestTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/BadHttpRequestTests.cs index 1849541e23..4f2de8644d 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/BadHttpRequestTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/BadHttpRequestTests.cs @@ -94,7 +94,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests using (var connection = server.CreateConnection()) { await connection.SendAllTryEnd(request); - await ReceiveBadRequestResponse(connection); + await ReceiveBadRequestResponse(connection, server.Context.DateHeaderValue); } } } @@ -131,7 +131,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests using (var connection = server.CreateConnection()) { await connection.SendAll(request); - await ReceiveBadRequestResponse(connection); + await ReceiveBadRequestResponse(connection, server.Context.DateHeaderValue); } } } @@ -167,7 +167,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests using (var connection = server.CreateConnection()) { await connection.SendAllTryEnd($"GET / HTTP/1.1\r\n{rawHeaders}"); - await ReceiveBadRequestResponse(connection); + await ReceiveBadRequestResponse(connection, server.Context.DateHeaderValue); } } } @@ -184,7 +184,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests "H\u00eb\u00e4d\u00ebr: value", "", ""); - await ReceiveBadRequestResponse(connection); + await ReceiveBadRequestResponse(connection, server.Context.DateHeaderValue); } } } @@ -211,12 +211,12 @@ namespace Microsoft.AspNetCore.Server.KestrelTests using (var connection = server.CreateConnection()) { await connection.SendAllTryEnd($"GET {path} HTTP/1.1\r\n"); - await ReceiveBadRequestResponse(connection); + await ReceiveBadRequestResponse(connection, server.Context.DateHeaderValue); } } } - private async Task ReceiveBadRequestResponse(TestConnection connection) + private async Task ReceiveBadRequestResponse(TestConnection connection, string expectedDateHeaderValue) { await connection.Receive( "HTTP/1.1 400 Bad Request", @@ -225,7 +225,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests "Connection: close", ""); await connection.ReceiveForcedEnd( - $"Date: {connection.Server.Context.DateHeaderValue}", + $"Date: {expectedDateHeaderValue}", "Content-Length: 0", "", ""); diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs index 1c9eefb324..e9cca977c8 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs @@ -1191,7 +1191,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests ""); await connection.ReceiveEnd( "HTTP/1.1 200 OK", - $"Date: {connection.Server.Context.DateHeaderValue}", + $"Date: {server.Context.DateHeaderValue}", $"Content-Length: {expectedPath.Length.ToString()}", "", $"{expectedPath}"); diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestConnection.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/TestConnection.cs index 5c54ca7d13..64a6586913 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/TestConnection.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/TestConnection.cs @@ -22,14 +22,11 @@ namespace Microsoft.AspNetCore.Server.KestrelTests private NetworkStream _stream; private StreamReader _reader; - public TestConnection(TestServer server) + public TestConnection(int port) { - Server = server; - Create(server.Port); + Create(port); } - public TestServer Server { get; } - public void Create(int port) { _socket = CreateConnectedLoopbackSocket(port); diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestServer.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/TestServer.cs index f4a840d967..e05b526735 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/TestServer.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/TestServer.cs @@ -58,7 +58,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests public TestConnection CreateConnection() { - return new TestConnection(this); + return new TestConnection(Port); } public void Dispose() From 5876e1983aae9f434f6673aaaf2d13d017267764 Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Tue, 2 Aug 2016 12:30:53 -0700 Subject: [PATCH 0835/1662] Move TestConnection to shared directory. --- .../TestConnection.cs | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename test/{Microsoft.AspNetCore.Server.KestrelTests => shared}/TestConnection.cs (100%) diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestConnection.cs b/test/shared/TestConnection.cs similarity index 100% rename from test/Microsoft.AspNetCore.Server.KestrelTests/TestConnection.cs rename to test/shared/TestConnection.cs From 20c1bb567dbe42fff6b11f0fce9cf5bd3fe614c3 Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Tue, 2 Aug 2016 12:47:06 -0700 Subject: [PATCH 0836/1662] Move TestConnection to the Microsoft.AspNetCore.Testing namespace. --- .../BadHttpRequestTests.cs | 1 + test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs | 1 + .../MultipleLoopTests.cs | 1 + .../Microsoft.AspNetCore.Server.KestrelTests/NetworkingTests.cs | 1 + test/Microsoft.AspNetCore.Server.KestrelTests/TestServer.cs | 1 + test/shared/TestConnection.cs | 2 +- 6 files changed, 6 insertions(+), 1 deletion(-) diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/BadHttpRequestTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/BadHttpRequestTests.cs index 4f2de8644d..78f8e8d50f 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/BadHttpRequestTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/BadHttpRequestTests.cs @@ -3,6 +3,7 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; +using Microsoft.AspNetCore.Testing; using Xunit; namespace Microsoft.AspNetCore.Server.KestrelTests diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs index e9cca977c8..71e04123e5 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs @@ -14,6 +14,7 @@ using Microsoft.AspNetCore.Server.Kestrel; using Microsoft.AspNetCore.Server.Kestrel.Internal; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; +using Microsoft.AspNetCore.Testing; using Xunit; namespace Microsoft.AspNetCore.Server.KestrelTests diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/MultipleLoopTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/MultipleLoopTests.cs index a57eb55f6b..d5926a14ec 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/MultipleLoopTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/MultipleLoopTests.cs @@ -9,6 +9,7 @@ using Microsoft.AspNetCore.Server.Kestrel; using Microsoft.AspNetCore.Server.Kestrel.Internal; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; +using Microsoft.AspNetCore.Testing; using Xunit; namespace Microsoft.AspNetCore.Server.KestrelTests diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/NetworkingTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/NetworkingTests.cs index aff4f2e212..ccd320a220 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/NetworkingTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/NetworkingTests.cs @@ -10,6 +10,7 @@ using Microsoft.AspNetCore.Server.Kestrel; using Microsoft.AspNetCore.Server.Kestrel.Internal; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; +using Microsoft.AspNetCore.Testing; using Xunit; namespace Microsoft.AspNetCore.Server.KestrelTests diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestServer.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/TestServer.cs index e05b526735..e01d35fa70 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/TestServer.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/TestServer.cs @@ -6,6 +6,7 @@ using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Server.Kestrel; using Microsoft.AspNetCore.Server.Kestrel.Internal; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; +using Microsoft.AspNetCore.Testing; namespace Microsoft.AspNetCore.Server.KestrelTests { diff --git a/test/shared/TestConnection.cs b/test/shared/TestConnection.cs index 64a6586913..a27ccb29a9 100644 --- a/test/shared/TestConnection.cs +++ b/test/shared/TestConnection.cs @@ -11,7 +11,7 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; using Xunit; -namespace Microsoft.AspNetCore.Server.KestrelTests +namespace Microsoft.AspNetCore.Testing { /// /// Summary description for TestConnection From 7704ddfc7f3aaff00e9754ed32e2398d300fd842 Mon Sep 17 00:00:00 2001 From: BrennanConroy Date: Tue, 2 Aug 2016 13:16:23 -0700 Subject: [PATCH 0837/1662] Update .travis.yml --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index a3b3853ed7..150cf03a06 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,6 +18,6 @@ branches: - dev - /^(.*\/)?ci-.*$/ before_install: - - if test "$TRAVIS_OS_NAME" == "osx"; then brew update; brew install openssl; brew link --force openssl; fi + - if test "$TRAVIS_OS_NAME" == "osx"; then brew update; brew install openssl; ln -s /usr/local/opt/openssl/lib/libcrypto.1.0.0.dylib /usr/local/lib/; ln -s /usr/local/opt/openssl/lib/libssl.1.0.0.dylib /usr/local/lib/; fi script: - ./build.sh --quiet verify From 1020d691716744c42962c24ffd6da1f7473a892e Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Mon, 25 Jul 2016 16:44:05 -0700 Subject: [PATCH 0838/1662] Better logging for connection errors during HTTPS handshake --- .../HttpsConnectionFilter.cs | 32 +++++++++-- .../KestrelServerOptionsHttpsExtensions.cs | 4 +- .../Internal/Http/FrameOfT.cs | 2 +- .../HttpsConnectionFilterTests.cs | 57 ++++++++++++++++++- test/shared/HttpClientSlim.cs | 2 +- 5 files changed, 87 insertions(+), 10 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Https/HttpsConnectionFilter.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Https/HttpsConnectionFilter.cs index f8efc1abbb..270d0e7297 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Https/HttpsConnectionFilter.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Https/HttpsConnectionFilter.cs @@ -2,11 +2,13 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.IO; using System.Net.Security; using System.Security.Cryptography.X509Certificates; using System.Threading.Tasks; using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Server.Kestrel.Filter; +using Microsoft.Extensions.Logging; namespace Microsoft.AspNetCore.Server.Kestrel.Https { @@ -14,8 +16,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Https { private readonly HttpsConnectionFilterOptions _options; private readonly IConnectionFilter _previous; + private readonly ILogger _logger; public HttpsConnectionFilter(HttpsConnectionFilterOptions options, IConnectionFilter previous) + : this(options, previous, loggerFactory: null) + { + } + + public HttpsConnectionFilter(HttpsConnectionFilterOptions options, IConnectionFilter previous, ILoggerFactory loggerFactory) { if (options == null) { @@ -32,6 +40,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Https _options = options; _previous = previous; + _logger = loggerFactory?.CreateLogger(nameof(HttpsConnectionFilter)); } public async Task OnConnectionAsync(ConnectionFilterContext context) @@ -41,11 +50,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Https if (string.Equals(context.Address.Scheme, "https", StringComparison.OrdinalIgnoreCase)) { SslStream sslStream; + bool certificateRequired; + if (_options.ClientCertificateMode == ClientCertificateMode.NoCertificate) { sslStream = new SslStream(context.Connection); - await sslStream.AuthenticateAsServerAsync(_options.ServerCertificate, clientCertificateRequired: false, - enabledSslProtocols: _options.SslProtocols, checkCertificateRevocation: _options.CheckCertificateRevocation); + certificateRequired = false; } else { @@ -81,8 +91,21 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Https return true; }); - await sslStream.AuthenticateAsServerAsync(_options.ServerCertificate, clientCertificateRequired: true, - enabledSslProtocols: _options.SslProtocols, checkCertificateRevocation: _options.CheckCertificateRevocation); + + certificateRequired = true; + } + + context.Connection = sslStream; + + try + { + await sslStream.AuthenticateAsServerAsync(_options.ServerCertificate, certificateRequired, + _options.SslProtocols, _options.CheckCertificateRevocation); + } + catch (IOException ex) + { + _logger?.LogInformation(1, ex, "Failed to authenticate HTTPS connection."); + return; } var previousPrepareRequest = context.PrepareRequest; @@ -98,7 +121,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Https features.Get().Scheme = "https"; }; - context.Connection = sslStream; } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Https/KestrelServerOptionsHttpsExtensions.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Https/KestrelServerOptionsHttpsExtensions.cs index db1d28bd6a..d4036985f5 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Https/KestrelServerOptionsHttpsExtensions.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Https/KestrelServerOptionsHttpsExtensions.cs @@ -7,6 +7,7 @@ using Microsoft.AspNetCore.Server.Kestrel; using Microsoft.AspNetCore.Server.Kestrel.Filter; using Microsoft.AspNetCore.Server.Kestrel.Https; using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; namespace Microsoft.AspNetCore.Hosting { @@ -83,7 +84,8 @@ namespace Microsoft.AspNetCore.Hosting public static KestrelServerOptions UseHttps(this KestrelServerOptions options, HttpsConnectionFilterOptions httpsOptions) { var prevFilter = options.ConnectionFilter ?? new NoOpConnectionFilter(); - options.ConnectionFilter = new HttpsConnectionFilter(httpsOptions, prevFilter); + var loggerFactory = options.ApplicationServices.GetRequiredService(); + options.ConnectionFilter = new HttpsConnectionFilter(httpsOptions, prevFilter, loggerFactory); return options; } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameOfT.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameOfT.cs index 0c33487b86..85a0832467 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameOfT.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameOfT.cs @@ -146,8 +146,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { if (!_requestRejected) { + // SetBadRequestState logs the error. SetBadRequestState(ex); - Log.LogWarning(0, ex, "Connection processing ended abnormally"); } } catch (Exception ex) diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/HttpsConnectionFilterTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/HttpsConnectionFilterTests.cs index a0ae26490b..5212b709c1 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/HttpsConnectionFilterTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/HttpsConnectionFilterTests.cs @@ -17,6 +17,8 @@ using Microsoft.AspNetCore.Server.Kestrel.Filter; using Microsoft.AspNetCore.Server.Kestrel.Https; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.AspNetCore.Testing; +using Microsoft.Extensions.Logging; +using Moq; using Xunit; namespace Microsoft.AspNetCore.Server.KestrelTests @@ -32,8 +34,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests public async Task CanReadAndWriteWithHttpsConnectionFilter() { var serviceContext = new TestServiceContext(new HttpsConnectionFilter( - new HttpsConnectionFilterOptions - { ServerCertificate = _x509Certificate2 }, + new HttpsConnectionFilterOptions { ServerCertificate = _x509Certificate2 }, new NoOpConnectionFilter()) ); @@ -330,6 +331,34 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } } + [Fact] + public async Task ClientHandshakeFailureLoggedAsInformation() + { + var logger = new HandshakerErrorLogger(); + var mockLoggerFactory = new Mock(MockBehavior.Strict); + mockLoggerFactory.Setup(m => m.CreateLogger(nameof(HttpsConnectionFilter))).Returns(logger); + + var serviceContext = new TestServiceContext(new HttpsConnectionFilter( + new HttpsConnectionFilterOptions { ServerCertificate = _x509Certificate2 }, + new NoOpConnectionFilter(), + mockLoggerFactory.Object) + ); + + using (var server = new TestServer(App, serviceContext, _serverAddress)) + { + using (await HttpClientSlim.GetSocket(new Uri($"https://localhost:{server.Port}/"))) + { + // Close socket immediately + } + + await logger.LogTcs.Task; + + Assert.Equal(1, logger.LastEventId.Id); + Assert.Equal(LogLevel.Information, logger.LastLogLevel); + mockLoggerFactory.VerifyAll(); + } + } + private static async Task App(HttpContext httpContext) { var request = httpContext.Request; @@ -376,5 +405,29 @@ namespace Microsoft.AspNetCore.Server.KestrelTests Assert.Null(line); } } + + private class HandshakerErrorLogger : ILogger + { + public LogLevel LastLogLevel { get; set; } + public EventId LastEventId { get; set; } + public TaskCompletionSource LogTcs { get; } = new TaskCompletionSource(); + + public void Log(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func formatter) + { + LastLogLevel = logLevel; + LastEventId = eventId; + LogTcs.SetResult(null); + } + + public bool IsEnabled(LogLevel logLevel) + { + throw new NotImplementedException(); + } + + public IDisposable BeginScope(TState state) + { + throw new NotImplementedException(); + } + } } } diff --git a/test/shared/HttpClientSlim.cs b/test/shared/HttpClientSlim.cs index a5d4d9caa2..02cf1880fe 100644 --- a/test/shared/HttpClientSlim.cs +++ b/test/shared/HttpClientSlim.cs @@ -100,7 +100,7 @@ namespace Microsoft.AspNetCore.Testing } } - private static async Task GetSocket(Uri requestUri) + public static async Task GetSocket(Uri requestUri) { var tcs = new TaskCompletionSource(); From dfe12223b89916b0e16800f02e4d120afc1c500c Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Wed, 3 Aug 2016 15:00:56 -0700 Subject: [PATCH 0839/1662] Ensure HTTPS handshake errors aren't logged on socket close --- .../HttpsConnectionFilter.cs | 11 +- .../Internal/ClosedStream.cs | 66 ++++++++ .../HttpsTests.cs | 157 ++++++++++++++++++ .../HttpsConnectionFilterTests.cs | 52 ------ 4 files changed, 232 insertions(+), 54 deletions(-) create mode 100644 src/Microsoft.AspNetCore.Server.Kestrel.Https/Internal/ClosedStream.cs create mode 100644 test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/HttpsTests.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Https/HttpsConnectionFilter.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Https/HttpsConnectionFilter.cs index 270d0e7297..30a34cfb91 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Https/HttpsConnectionFilter.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Https/HttpsConnectionFilter.cs @@ -8,12 +8,15 @@ using System.Security.Cryptography.X509Certificates; using System.Threading.Tasks; using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Server.Kestrel.Filter; +using Microsoft.AspNetCore.Server.Kestrel.Https.Internal; using Microsoft.Extensions.Logging; namespace Microsoft.AspNetCore.Server.Kestrel.Https { public class HttpsConnectionFilter : IConnectionFilter { + private static readonly ClosedStream _closedStream = new ClosedStream(); + private readonly HttpsConnectionFilterOptions _options; private readonly IConnectionFilter _previous; private readonly ILogger _logger; @@ -95,8 +98,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Https certificateRequired = true; } - context.Connection = sslStream; - try { await sslStream.AuthenticateAsServerAsync(_options.ServerCertificate, certificateRequired, @@ -105,6 +106,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Https catch (IOException ex) { _logger?.LogInformation(1, ex, "Failed to authenticate HTTPS connection."); + + sslStream.Dispose(); + context.Connection = _closedStream; + return; } @@ -121,6 +126,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Https features.Get().Scheme = "https"; }; + + context.Connection = sslStream; } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Https/Internal/ClosedStream.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Https/Internal/ClosedStream.cs new file mode 100644 index 0000000000..c9d030cd87 --- /dev/null +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Https/Internal/ClosedStream.cs @@ -0,0 +1,66 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.IO; +using System.Threading; +using System.Threading.Tasks; + +namespace Microsoft.AspNetCore.Server.Kestrel.Https.Internal +{ + internal class ClosedStream : Stream + { + public override bool CanRead => true; + public override bool CanSeek => false; + public override bool CanWrite => false; + + public override long Length + { + get + { + throw new NotSupportedException(); + } + } + + public override long Position + { + get + { + throw new NotSupportedException(); + } + set + { + throw new NotSupportedException(); + } + } + + public override void Flush() + { + } + + public override long Seek(long offset, SeekOrigin origin) + { + throw new NotSupportedException(); + } + + public override void SetLength(long value) + { + throw new NotSupportedException(); + } + + public override int Read(byte[] buffer, int offset, int count) + { + return 0; + } + + public override Task ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) + { + return Task.FromResult(0); + } + + public override void Write(byte[] buffer, int offset, int count) + { + throw new NotSupportedException(); + } + } +} diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/HttpsTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/HttpsTests.cs new file mode 100644 index 0000000000..2fa1838195 --- /dev/null +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/HttpsTests.cs @@ -0,0 +1,157 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Net.Sockets; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Server.Kestrel.Https; +using Microsoft.AspNetCore.Testing; +using Microsoft.Extensions.Logging; +using Xunit; + +namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests +{ + public class HttpsTests + { + [Fact] + public async Task EmptyRequestLoggedAsInformation() + { + var loggerFactory = new HandshakeErrorLoggerFactory(); + + var hostBuilder = new WebHostBuilder() + .UseKestrel(options => + { + options.UseHttps(@"TestResources/testCert.pfx", "testPassword"); + }) + .UseUrls("https://127.0.0.1:0/") + .UseLoggerFactory(loggerFactory) + .Configure(app => { }); + + using (var host = hostBuilder.Build()) + { + host.Start(); + + using (await HttpClientSlim.GetSocket(new Uri($"http://127.0.0.1:{host.GetPort()}/"))) + { + // Close socket immediately + } + } + + await loggerFactory.FilterLogger.LogTcs.Task; + + Assert.Equal(1, loggerFactory.FilterLogger.LastEventId.Id); + Assert.Equal(LogLevel.Information, loggerFactory.FilterLogger.LastLogLevel); + Assert.Equal(0, loggerFactory.ErrorLogger.TotalErrorsLogged); + } + + + [Fact] + public async Task ClientHandshakeFailureLoggedAsInformation() + { + var loggerFactory = new HandshakeErrorLoggerFactory(); + + var hostBuilder = new WebHostBuilder() + .UseKestrel(options => + { + options.UseHttps(@"TestResources/testCert.pfx", "testPassword"); + }) + .UseUrls("https://127.0.0.1:0/") + .UseLoggerFactory(loggerFactory) + .Configure(app => { }); + + using (var host = hostBuilder.Build()) + { + host.Start(); + + using (var socket = await HttpClientSlim.GetSocket(new Uri($"https://127.0.0.1:{host.GetPort()}/"))) + using (var stream = new NetworkStream(socket)) + { + // Send null bytes and close socket + await stream.WriteAsync(new byte[10], 0, 10); + } + } + + await loggerFactory.FilterLogger.LogTcs.Task; + + Assert.Equal(1, loggerFactory.FilterLogger.LastEventId.Id); + Assert.Equal(LogLevel.Information, loggerFactory.FilterLogger.LastLogLevel); + Assert.Equal(0, loggerFactory.ErrorLogger.TotalErrorsLogged); + } + + private class HandshakeErrorLoggerFactory : ILoggerFactory + { + public HttpsConnectionFilterLogger FilterLogger { get; } = new HttpsConnectionFilterLogger(); + public ApplicationErrorLogger ErrorLogger { get; } = new ApplicationErrorLogger(); + + public ILogger CreateLogger(string categoryName) + { + if (categoryName == nameof(HttpsConnectionFilter)) + { + return FilterLogger; + } + else + { + return ErrorLogger; + } + + } + + public void AddProvider(ILoggerProvider provider) + { + throw new NotImplementedException(); + } + + public void Dispose() + { + } + } + + private class HttpsConnectionFilterLogger : ILogger + { + public LogLevel LastLogLevel { get; set; } + public EventId LastEventId { get; set; } + public TaskCompletionSource LogTcs { get; } = new TaskCompletionSource(); + + public void Log(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func formatter) + { + LastLogLevel = logLevel; + LastEventId = eventId; + LogTcs.SetResult(null); + } + + public bool IsEnabled(LogLevel logLevel) + { + throw new NotImplementedException(); + } + + public IDisposable BeginScope(TState state) + { + throw new NotImplementedException(); + } + } + + private class ApplicationErrorLogger : ILogger + { + public int TotalErrorsLogged { get; set; } + + public void Log(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func formatter) + { + if (logLevel == LogLevel.Error) + { + TotalErrorsLogged++; + } + } + + public bool IsEnabled(LogLevel logLevel) + { + return true; + } + + public IDisposable BeginScope(TState state) + { + throw new NotImplementedException(); + } + } + } +} diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/HttpsConnectionFilterTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/HttpsConnectionFilterTests.cs index 5212b709c1..2e5ad48707 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/HttpsConnectionFilterTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/HttpsConnectionFilterTests.cs @@ -331,34 +331,6 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } } - [Fact] - public async Task ClientHandshakeFailureLoggedAsInformation() - { - var logger = new HandshakerErrorLogger(); - var mockLoggerFactory = new Mock(MockBehavior.Strict); - mockLoggerFactory.Setup(m => m.CreateLogger(nameof(HttpsConnectionFilter))).Returns(logger); - - var serviceContext = new TestServiceContext(new HttpsConnectionFilter( - new HttpsConnectionFilterOptions { ServerCertificate = _x509Certificate2 }, - new NoOpConnectionFilter(), - mockLoggerFactory.Object) - ); - - using (var server = new TestServer(App, serviceContext, _serverAddress)) - { - using (await HttpClientSlim.GetSocket(new Uri($"https://localhost:{server.Port}/"))) - { - // Close socket immediately - } - - await logger.LogTcs.Task; - - Assert.Equal(1, logger.LastEventId.Id); - Assert.Equal(LogLevel.Information, logger.LastLogLevel); - mockLoggerFactory.VerifyAll(); - } - } - private static async Task App(HttpContext httpContext) { var request = httpContext.Request; @@ -405,29 +377,5 @@ namespace Microsoft.AspNetCore.Server.KestrelTests Assert.Null(line); } } - - private class HandshakerErrorLogger : ILogger - { - public LogLevel LastLogLevel { get; set; } - public EventId LastEventId { get; set; } - public TaskCompletionSource LogTcs { get; } = new TaskCompletionSource(); - - public void Log(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func formatter) - { - LastLogLevel = logLevel; - LastEventId = eventId; - LogTcs.SetResult(null); - } - - public bool IsEnabled(LogLevel logLevel) - { - throw new NotImplementedException(); - } - - public IDisposable BeginScope(TState state) - { - throw new NotImplementedException(); - } - } } } From 8836eec7d886fcbcb918c43fa20b66bcc8199874 Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Tue, 26 Jul 2016 20:42:49 -0700 Subject: [PATCH 0840/1662] Limit request line length (#784). --- .../BadHttpRequestException.cs | 14 +- .../Internal/Http/Connection.cs | 4 +- .../Internal/Http/Frame.cs | 47 ++- .../Internal/Http/RequestRejectionReason.cs | 6 +- .../Infrastructure/MemoryPoolIterator.cs | 225 ++++++++++- .../KestrelServer.cs | 12 + .../KestrelServerLimits.cs | 62 +++ .../KestrelServerOptions.cs | 31 +- .../MaxRequestBufferSizeTests.cs | 12 +- .../MaxRequestLineSizeTests.cs | 99 +++++ .../BadHttpRequestTests.cs | 92 ++--- .../KestrelServerLimitsTests.cs | 67 +++ .../KestrelServerOptionsTests.cs | 43 +- .../MemoryPoolIteratorTests.cs | 382 +++++++++++++++++- test/shared/TestConnection.cs | 2 +- 15 files changed, 968 insertions(+), 130 deletions(-) create mode 100644 src/Microsoft.AspNetCore.Server.Kestrel/KestrelServerLimits.cs create mode 100644 test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/MaxRequestLineSizeTests.cs create mode 100644 test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerLimitsTests.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/BadHttpRequestException.cs b/src/Microsoft.AspNetCore.Server.Kestrel/BadHttpRequestException.cs index 95ecedb930..9a435392ff 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/BadHttpRequestException.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/BadHttpRequestException.cs @@ -79,6 +79,18 @@ namespace Microsoft.AspNetCore.Server.Kestrel case RequestRejectionReason.NonAsciiOrNullCharactersInInputString: ex = new BadHttpRequestException("The input string contains non-ASCII or null characters."); break; + case RequestRejectionReason.RequestLineTooLong: + ex = new BadHttpRequestException("Request line too long."); + break; + case RequestRejectionReason.MissingSpaceAfterMethod: + ex = new BadHttpRequestException("No space character found after method in request line."); + break; + case RequestRejectionReason.MissingSpaceAfterTarget: + ex = new BadHttpRequestException("No space character found after target in request line."); + break; + case RequestRejectionReason.MissingCrAfterVersion: + ex = new BadHttpRequestException("Missing CR in request line."); + break; default: ex = new BadHttpRequestException("Bad request."); break; @@ -92,7 +104,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel switch (reason) { case RequestRejectionReason.MalformedRequestLineStatus: - ex = new BadHttpRequestException($"Malformed request: {value}"); + ex = new BadHttpRequestException($"Invalid request line: {value}"); break; case RequestRejectionReason.InvalidContentLength: ex = new BadHttpRequestException($"Invalid content length: {value}"); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Connection.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Connection.cs index 0c73c35c7c..09a8c73d15 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Connection.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Connection.cs @@ -47,9 +47,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http ConnectionId = GenerateConnectionId(Interlocked.Increment(ref _lastConnectionId)); - if (ServerOptions.MaxRequestBufferSize.HasValue) + if (ServerOptions.Limits.MaxRequestBufferSize.HasValue) { - _bufferSizeControl = new BufferSizeControl(ServerOptions.MaxRequestBufferSize.Value, this, Thread); + _bufferSizeControl = new BufferSizeControl(ServerOptions.Limits.MaxRequestBufferSize.Value, this, Thread); } SocketInput = new SocketInput(Thread.Memory, ThreadPool, _bufferSizeControl); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs index 9d700f0e82..ad46367135 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs @@ -34,6 +34,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http private static readonly byte[] _bytesServer = Encoding.ASCII.GetBytes("\r\nServer: Kestrel"); private static Vector _vectorCRs = new Vector((byte)'\r'); + private static Vector _vectorLFs = new Vector((byte)'\n'); private static Vector _vectorColons = new Vector((byte)':'); private static Vector _vectorSpaces = new Vector((byte)' '); private static Vector _vectorTabs = new Vector((byte)'\t'); @@ -801,13 +802,27 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _requestProcessingStatus = RequestProcessingStatus.RequestStarted; + var end = scan; + int bytesScanned; + if (end.Seek(ref _vectorLFs, out bytesScanned, ServerOptions.Limits.MaxRequestLineSize) == -1) + { + if (bytesScanned >= ServerOptions.Limits.MaxRequestLineSize) + { + RejectRequest(RequestRejectionReason.RequestLineTooLong); + } + else + { + return RequestLineStatus.Incomplete; + } + } + string method; var begin = scan; if (!begin.GetKnownMethod(out method)) { - if (scan.Seek(ref _vectorSpaces) == -1) + if (scan.Seek(ref _vectorSpaces, ref end) == -1) { - return RequestLineStatus.MethodIncomplete; + RejectRequest(RequestRejectionReason.MissingSpaceAfterMethod); } method = begin.GetAsciiString(scan); @@ -835,18 +850,18 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http scan.Take(); begin = scan; var needDecode = false; - var chFound = scan.Seek(ref _vectorSpaces, ref _vectorQuestionMarks, ref _vectorPercentages); + var chFound = scan.Seek(ref _vectorSpaces, ref _vectorQuestionMarks, ref _vectorPercentages, ref end); if (chFound == -1) { - return RequestLineStatus.TargetIncomplete; + RejectRequest(RequestRejectionReason.MissingSpaceAfterTarget); } else if (chFound == '%') { needDecode = true; - chFound = scan.Seek(ref _vectorSpaces, ref _vectorQuestionMarks); + chFound = scan.Seek(ref _vectorSpaces, ref _vectorQuestionMarks, ref end); if (chFound == -1) { - return RequestLineStatus.TargetIncomplete; + RejectRequest(RequestRejectionReason.MissingSpaceAfterTarget); } } @@ -857,9 +872,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if (chFound == '?') { begin = scan; - if (scan.Seek(ref _vectorSpaces) == -1) + if (scan.Seek(ref _vectorSpaces, ref end) == -1) { - return RequestLineStatus.TargetIncomplete; + RejectRequest(RequestRejectionReason.MissingSpaceAfterTarget); } queryString = begin.GetAsciiString(scan); } @@ -873,9 +888,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http scan.Take(); begin = scan; - if (scan.Seek(ref _vectorCRs) == -1) + if (scan.Seek(ref _vectorCRs, ref end) == -1) { - return RequestLineStatus.VersionIncomplete; + RejectRequest(RequestRejectionReason.MissingCrAfterVersion); } string httpVersion; @@ -898,16 +913,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } } - scan.Take(); - var next = scan.Take(); - if (next == -1) - { - return RequestLineStatus.Incomplete; - } - else if (next != '\n') + scan.Take(); // consume CR + if (scan.Block != end.Block || scan.Index != end.Index) { RejectRequest(RequestRejectionReason.MissingLFInRequestLine); } + scan.Take(); // consume LF // URIs are always encoded/escaped to ASCII https://tools.ietf.org/html/rfc3986#page-11 // Multibyte Internationalized Resource Identifiers (IRIs) are first converted to utf8; @@ -1155,7 +1166,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http // Trim trailing whitespace from header value by repeatedly advancing to next // whitespace or CR. - // + // // - If CR is found, this is the end of the header value. // - If whitespace is found, this is the _tentative_ end of the header value. // If non-whitespace is found after it and it's not CR, seek again to the next diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/RequestRejectionReason.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/RequestRejectionReason.cs index 83ea024a5d..d71ff5b414 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/RequestRejectionReason.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/RequestRejectionReason.cs @@ -26,6 +26,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http ChunkedRequestIncomplete, PathContainsNullCharacters, InvalidCharactersInHeaderName, - NonAsciiOrNullCharactersInInputString + NonAsciiOrNullCharactersInInputString, + RequestLineTooLong, + MissingSpaceAfterMethod, + MissingSpaceAfterTarget, + MissingCrAfterVersion, } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolIterator.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolIterator.cs index 68397406bb..78efd5adca 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolIterator.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolIterator.cs @@ -216,6 +216,123 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure } public unsafe int Seek(ref Vector byte0Vector) + { + int bytesScanned; + return Seek(ref byte0Vector, out bytesScanned); + } + + public unsafe int Seek( + ref Vector byte0Vector, + out int bytesScanned, + int limit = int.MaxValue) + { + bytesScanned = 0; + + if (IsDefault || limit <= 0) + { + return -1; + } + + var block = _block; + var index = _index; + var wasLastBlock = block.Next == null; + var following = block.End - index; + byte[] array; + var byte0 = byte0Vector[0]; + + while (true) + { + while (following == 0) + { + if (bytesScanned >= limit || wasLastBlock) + { + _block = block; + _index = index; + return -1; + } + + block = block.Next; + index = block.Start; + wasLastBlock = block.Next == null; + following = block.End - index; + } + array = block.Array; + while (following > 0) + { + // Need unit tests to test Vector path +#if !DEBUG + // Check will be Jitted away https://github.com/dotnet/coreclr/issues/1079 + if (Vector.IsHardwareAccelerated) + { +#endif + if (following >= _vectorSpan) + { + var byte0Equals = Vector.Equals(new Vector(array, index), byte0Vector); + + if (byte0Equals.Equals(Vector.Zero)) + { + if (bytesScanned + _vectorSpan >= limit) + { + _block = block; + // Ensure iterator is left at limit position + _index = index + (limit - bytesScanned); + bytesScanned = limit; + return -1; + } + + bytesScanned += _vectorSpan; + following -= _vectorSpan; + index += _vectorSpan; + continue; + } + + _block = block; + + var firstEqualByteIndex = FindFirstEqualByte(ref byte0Equals); + var vectorBytesScanned = firstEqualByteIndex + 1; + + if (bytesScanned + vectorBytesScanned > limit) + { + // Ensure iterator is left at limit position + _index = index + (limit - bytesScanned); + bytesScanned = limit; + return -1; + } + + _index = index + firstEqualByteIndex; + bytesScanned += vectorBytesScanned; + + return byte0; + } + // Need unit tests to test Vector path +#if !DEBUG + } +#endif + + var pCurrent = (block.DataFixedPtr + index); + var pEnd = pCurrent + Math.Min(following, limit - bytesScanned); + do + { + bytesScanned++; + if (*pCurrent == byte0) + { + _block = block; + _index = index; + return byte0; + } + pCurrent++; + index++; + } while (pCurrent < pEnd); + + following = 0; + break; + } + } + } + + public unsafe int Seek( + ref Vector byte0Vector, + ref MemoryPoolIterator limit) { if (IsDefault) { @@ -233,12 +350,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure { while (following == 0) { - if (wasLastBlock) + if ((block == limit.Block && index > limit.Index) || + wasLastBlock) { _block = block; - _index = index; + // Ensure iterator is left at limit position + _index = limit.Index; return -1; } + block = block.Next; index = block.Start; wasLastBlock = block.Next == null; @@ -259,13 +379,33 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure if (byte0Equals.Equals(Vector.Zero)) { + if (block == limit.Block && index + _vectorSpan > limit.Index) + { + _block = block; + // Ensure iterator is left at limit position + _index = limit.Index; + return -1; + } + following -= _vectorSpan; index += _vectorSpan; continue; } _block = block; - _index = index + FindFirstEqualByte(ref byte0Equals); + + var firstEqualByteIndex = FindFirstEqualByte(ref byte0Equals); + var vectorBytesScanned = firstEqualByteIndex + 1; + + if (_block == limit.Block && index + firstEqualByteIndex > limit.Index) + { + // Ensure iterator is left at limit position + _index = limit.Index; + return -1; + } + + _index = index + firstEqualByteIndex; + return byte0; } // Need unit tests to test Vector path @@ -274,7 +414,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure #endif var pCurrent = (block.DataFixedPtr + index); - var pEnd = pCurrent + following; + var pEnd = block == limit.Block ? block.DataFixedPtr + limit.Index + 1 : pCurrent + following; do { if (*pCurrent == byte0) @@ -294,6 +434,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure } public unsafe int Seek(ref Vector byte0Vector, ref Vector byte1Vector) + { + var limit = new MemoryPoolIterator(); + return Seek(ref byte0Vector, ref byte1Vector, ref limit); + } + + public unsafe int Seek( + ref Vector byte0Vector, + ref Vector byte1Vector, + ref MemoryPoolIterator limit) { if (IsDefault) { @@ -314,10 +463,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure { while (following == 0) { - if (wasLastBlock) + if ((block == limit.Block && index > limit.Index) || + wasLastBlock) { _block = block; - _index = index; + // Ensure iterator is left at limit position + _index = limit.Index; return -1; } block = block.Next; @@ -354,6 +505,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure { following -= _vectorSpan; index += _vectorSpan; + + if (block == limit.Block && index > limit.Index) + { + _block = block; + // Ensure iterator is left at limit position + _index = limit.Index; + return -1; + } + continue; } @@ -362,10 +522,26 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure if (byte0Index < byte1Index) { _index = index + byte0Index; + + if (block == limit.Block && _index > limit.Index) + { + // Ensure iterator is left at limit position + _index = limit.Index; + return -1; + } + return byte0; } _index = index + byte1Index; + + if (block == limit.Block && _index > limit.Index) + { + // Ensure iterator is left at limit position + _index = limit.Index; + return -1; + } + return byte1; } // Need unit tests to test Vector path @@ -373,7 +549,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure } #endif var pCurrent = (block.DataFixedPtr + index); - var pEnd = pCurrent + following; + var pEnd = block == limit.Block ? block.DataFixedPtr + limit.Index + 1 : pCurrent + following; do { if (*pCurrent == byte0) @@ -399,6 +575,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure } public unsafe int Seek(ref Vector byte0Vector, ref Vector byte1Vector, ref Vector byte2Vector) + { + var limit = new MemoryPoolIterator(); + return Seek(ref byte0Vector, ref byte1Vector, ref byte2Vector, ref limit); + } + + public unsafe int Seek( + ref Vector byte0Vector, + ref Vector byte1Vector, + ref Vector byte2Vector, + ref MemoryPoolIterator limit) { if (IsDefault) { @@ -421,10 +607,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure { while (following == 0) { - if (wasLastBlock) + if ((block == limit.Block && index > limit.Index) || + wasLastBlock) { _block = block; - _index = index; + // Ensure iterator is left at limit position + _index = limit.Index; return -1; } block = block.Next; @@ -465,6 +653,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure { following -= _vectorSpan; index += _vectorSpan; + + if (block == limit.Block && index > limit.Index) + { + _block = block; + // Ensure iterator is left at limit position + _index = limit.Index; + return -1; + } + continue; } @@ -499,6 +696,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure } _index = index + toMove; + + if (block == limit.Block && _index > limit.Index) + { + // Ensure iterator is left at limit position + _index = limit.Index; + return -1; + } + return toReturn; } // Need unit tests to test Vector path @@ -506,7 +711,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure } #endif var pCurrent = (block.DataFixedPtr + index); - var pEnd = pCurrent + following; + var pEnd = block == limit.Block ? block.DataFixedPtr + limit.Index + 1 : pCurrent + following; do { if (*pCurrent == byte0) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServer.cs b/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServer.cs index 034d41e29e..09ddb1a6b5 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServer.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServer.cs @@ -56,6 +56,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel public void Start(IHttpApplication application) { + ValidateOptions(); + if (_disposables != null) { // The server has already started and/or has not been cleaned up yet @@ -196,5 +198,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel _disposables = null; } } + + private void ValidateOptions() + { + if (Options.Limits.MaxRequestBufferSize.HasValue && + Options.Limits.MaxRequestBufferSize < Options.Limits.MaxRequestLineSize) + { + throw new InvalidOperationException( + $"Maximum request buffer size ({Options.Limits.MaxRequestBufferSize.Value}) must be greater than or equal to maximum request line size ({Options.Limits.MaxRequestLineSize})."); + } + } } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServerLimits.cs b/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServerLimits.cs new file mode 100644 index 0000000000..02afceca2b --- /dev/null +++ b/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServerLimits.cs @@ -0,0 +1,62 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; + +namespace Microsoft.AspNetCore.Server.Kestrel +{ + public class KestrelServerLimits + { + // Matches the default client_max_body_size in nginx. Also large enough that most requests + // should be under the limit. + private long? _maxRequestBufferSize = 1024 * 1024; + + // Matches the default large_client_header_buffers in nginx. + private int _maxRequestLineSize = 8 * 1024; + + /// + /// Gets or sets the maximum size of the request buffer. + /// + /// + /// When set to null, the size of the request buffer is unlimited. + /// Defaults to 1,048,576 bytes (1 MB). + /// + public long? MaxRequestBufferSize + { + get + { + return _maxRequestBufferSize; + } + set + { + if (value.HasValue && value.Value <= 0) + { + throw new ArgumentOutOfRangeException(nameof(value), "Value must be null or a positive integer."); + } + _maxRequestBufferSize = value; + } + } + + /// + /// Gets or sets the maximum allowed size for the HTTP request line. + /// + /// + /// Defaults to 8,192 bytes (8 KB). + /// + public int MaxRequestLineSize + { + get + { + return _maxRequestLineSize; + } + set + { + if (value <= 0) + { + throw new ArgumentOutOfRangeException(nameof(value), "Value must be a positive integer."); + } + _maxRequestLineSize = value; + } + } + } +} diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServerOptions.cs b/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServerOptions.cs index 6ae42f48a8..9e4331cbbd 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServerOptions.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServerOptions.cs @@ -1,6 +1,3 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - using System; using Microsoft.AspNetCore.Server.Kestrel.Filter; @@ -11,10 +8,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel /// public class KestrelServerOptions { - // Matches the default client_max_body_size in nginx. Also large enough that most requests - // should be under the limit. - private long? _maxRequestBufferSize = 1024 * 1024; - /// /// Gets or sets whether the Server header should be included in each response. /// @@ -41,28 +34,36 @@ namespace Microsoft.AspNetCore.Server.Kestrel public IConnectionFilter ConnectionFilter { get; set; } /// - /// Maximum size of the request buffer. - /// If value is null, the size of the request buffer is unlimited. + /// + /// This property is obsolete and will be removed in a future version. + /// Use Limits.MaxRequestBufferSize instead. + /// + /// + /// Gets or sets the maximum size of the request buffer. + /// /// /// + /// When set to null, the size of the request buffer is unlimited. /// Defaults to 1,048,576 bytes (1 MB). /// + [Obsolete] public long? MaxRequestBufferSize { get { - return _maxRequestBufferSize; + return Limits.MaxRequestBufferSize; } set { - if (value.HasValue && value.Value <= 0) - { - throw new ArgumentOutOfRangeException("value", "Value must be null or a positive integer."); - } - _maxRequestBufferSize = value; + Limits.MaxRequestBufferSize = value; } } + /// + /// Provides access to request limit options. + /// + public KestrelServerLimits Limits { get; } = new KestrelServerLimits(); + /// /// Set to false to enable Nagle's algorithm for all connections. /// diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/MaxRequestBufferSizeTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/MaxRequestBufferSizeTests.cs index 70bbf876f8..463a11145c 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/MaxRequestBufferSizeTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/MaxRequestBufferSizeTests.cs @@ -25,8 +25,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests get { var maxRequestBufferSizeValues = new Tuple[] { - // Smallest allowed buffer. Server should call pause/resume between each read. - Tuple.Create((long?)1, true), + // Smallest buffer that can hold a POST request line to the root. + Tuple.Create((long?)"POST / HTTP/1.1\r\n".Length, true), // Small buffer, but large enough to hold all request headers. Tuple.Create((long?)16 * 1024, true), @@ -171,8 +171,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests var host = new WebHostBuilder() .UseKestrel(options => { - options.MaxRequestBufferSize = maxRequestBufferSize; + options.Limits.MaxRequestBufferSize = maxRequestBufferSize; options.UseHttps(@"TestResources/testCert.pfx", "testPassword"); + + if (maxRequestBufferSize.HasValue && + maxRequestBufferSize.Value < options.Limits.MaxRequestLineSize) + { + options.Limits.MaxRequestLineSize = (int)maxRequestBufferSize; + } }) .UseUrls("http://127.0.0.1:0/", "https://127.0.0.1:0/") .UseContentRoot(Directory.GetCurrentDirectory()) diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/MaxRequestLineSizeTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/MaxRequestLineSizeTests.cs new file mode 100644 index 0000000000..644fef0687 --- /dev/null +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/MaxRequestLineSizeTests.cs @@ -0,0 +1,99 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Testing; +using Xunit; + +namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests +{ + public class MaxRequestLineSizeTests + { + [Theory] + [InlineData("GET / HTTP/1.1\r\n", 16)] + [InlineData("GET / HTTP/1.1\r\n", 17)] + [InlineData("GET / HTTP/1.1\r\n", 137)] + [InlineData("POST /abc/de HTTP/1.1\r\n", 23)] + [InlineData("POST /abc/de HTTP/1.1\r\n", 24)] + [InlineData("POST /abc/de HTTP/1.1\r\n", 287)] + [InlineData("PUT /abc/de?f=ghi HTTP/1.1\r\n", 28)] + [InlineData("PUT /abc/de?f=ghi HTTP/1.1\r\n", 29)] + [InlineData("PUT /abc/de?f=ghi HTTP/1.1\r\n", 589)] + [InlineData("DELETE /a%20b%20c/d%20e?f=ghi HTTP/1.1\r\n", 40)] + [InlineData("DELETE /a%20b%20c/d%20e?f=ghi HTTP/1.1\r\n", 41)] + [InlineData("DELETE /a%20b%20c/d%20e?f=ghi HTTP/1.1\r\n", 1027)] + public async Task ServerAcceptsRequestLineWithinLimit(string requestLine, int limit) + { + var maxRequestLineSize = limit; + + using (var host = BuildWebHost(options => + { + options.Limits.MaxRequestLineSize = maxRequestLineSize; + })) + { + host.Start(); + + using (var connection = new TestConnection(host.GetPort())) + { + await connection.SendEnd($"{requestLine}\r\n"); + await connection.Receive($"HTTP/1.1 200 OK\r\n"); + } + } + } + + [Theory] + [InlineData("GET / HTTP/1.1\r\n")] + [InlineData("POST /abc/de HTTP/1.1\r\n")] + [InlineData("PUT /abc/de?f=ghi HTTP/1.1\r\n")] + [InlineData("DELETE /a%20b%20c/d%20e?f=ghi HTTP/1.1\r\n")] + public async Task ServerRejectsRequestLineExceedingLimit(string requestLine) + { + using (var host = BuildWebHost(options => + { + options.Limits.MaxRequestLineSize = requestLine.Length - 1; // stop short of the '\n' + })) + { + host.Start(); + + using (var connection = new TestConnection(host.GetPort())) + { + await connection.SendAllTryEnd($"{requestLine}\r\n"); + await connection.Receive($"HTTP/1.1 400 Bad Request\r\n"); + } + } + } + + [Theory] + [InlineData(1, 2)] + [InlineData(int.MaxValue - 1, int.MaxValue)] + public void ServerFailsToStartWhenMaxRequestBufferSizeIsLessThanMaxRequestLineSize(long maxRequestBufferSize, int maxRequestLineSize) + { + using (var host = BuildWebHost(options => + { + options.Limits.MaxRequestBufferSize = maxRequestBufferSize; + options.Limits.MaxRequestLineSize = maxRequestLineSize; + })) + { + Assert.Throws(() => host.Start()); + } + } + + private IWebHost BuildWebHost(Action options) + { + var host = new WebHostBuilder() + .UseKestrel(options) + .UseUrls("http://127.0.0.1:0/") + .Configure(app => app.Run(async context => + { + await context.Response.WriteAsync("hello, world"); + })) + .Build(); + + return host; + } + } +} diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/BadHttpRequestTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/BadHttpRequestTests.cs index 78f8e8d50f..ee41be7d46 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/BadHttpRequestTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/BadHttpRequestTests.cs @@ -10,64 +10,47 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { public class BadHttpRequestTests { - // Don't send more data than necessary to fail, otherwise the test throws trying to - // send data after the server has already closed the connection. This would cause the - // test to fail on Windows, due to a winsock limitation: after the error when trying - // to write to the socket closed by the server, winsock disposes all resources used - // by that socket. The test then fails when we try to read the expected response - // from the server because, although it would have been buffered, it got discarded - // by winsock on the send() error. - // The solution for this is for the client to always try to receive before doing - // any sends, that way it can detect that the connection has been closed by the server - // and not try to send() on the closed connection, triggering the error that would cause - // any buffered received data to be lost. - // We do not deem necessary to mitigate this issue in TestConnection, since it would only - // be ensuring that we have a properly implemented HTTP client that can handle the - // winsock issue. There is nothing to be verified in Kestrel in this situation. + // All test cases for this theory must end in '\n', otherwise the server will spin forever [Theory] // Incomplete request lines - [InlineData("G")] - [InlineData("GE")] - [InlineData("GET")] - [InlineData("GET ")] - [InlineData("GET /")] - [InlineData("GET / ")] - [InlineData("GET / H")] - [InlineData("GET / HT")] - [InlineData("GET / HTT")] - [InlineData("GET / HTTP")] - [InlineData("GET / HTTP/")] - [InlineData("GET / HTTP/1")] - [InlineData("GET / HTTP/1.")] - [InlineData("GET / HTTP/1.1")] - [InlineData("GET / HTTP/1.1\r")] - [InlineData("GET / HTTP/1.0")] - [InlineData("GET / HTTP/1.0\r")] + [InlineData("G\r\n")] + [InlineData("GE\r\n")] + [InlineData("GET\r\n")] + [InlineData("GET \r\n")] + [InlineData("GET /\r\n")] + [InlineData("GET / \r\n")] + [InlineData("GET / H\r\n")] + [InlineData("GET / HT\r\n")] + [InlineData("GET / HTT\r\n")] + [InlineData("GET / HTTP\r\n")] + [InlineData("GET / HTTP/\r\n")] + [InlineData("GET / HTTP/1\r\n")] + [InlineData("GET / HTTP/1.\r\n")] // Missing method - [InlineData(" ")] + [InlineData(" \r\n")] // Missing second space - [InlineData("/ ")] // This fails trying to read the '/' because that's invalid for an HTTP method + [InlineData("/ \r\n")] // This fails trying to read the '/' because that's invalid for an HTTP method [InlineData("GET /\r\n")] // Missing target - [InlineData("GET ")] + [InlineData("GET \r\n")] // Missing version - [InlineData("GET / \r")] + [InlineData("GET / \r\n")] // Missing CR [InlineData("GET / \n")] // Unrecognized HTTP version - [InlineData("GET / http/1.0\r")] - [InlineData("GET / http/1.1\r")] - [InlineData("GET / HTTP/1.1 \r")] - [InlineData("GET / HTTP/1.1a\r")] - [InlineData("GET / HTTP/1.0\n\r")] - [InlineData("GET / HTTP/1.2\r")] - [InlineData("GET / HTTP/3.0\r")] - [InlineData("GET / H\r")] - [InlineData("GET / HTTP/1.\r")] - [InlineData("GET / hello\r")] - [InlineData("GET / 8charact\r")] - // Missing LF - [InlineData("GET / HTTP/1.0\rA")] + [InlineData("GET / http/1.0\r\n")] + [InlineData("GET / http/1.1\r\n")] + [InlineData("GET / HTTP/1.1 \r\n")] + [InlineData("GET / HTTP/1.1a\r\n")] + [InlineData("GET / HTTP/1.0\n\r\n")] + [InlineData("GET / HTTP/1.2\r\n")] + [InlineData("GET / HTTP/3.0\r\n")] + [InlineData("GET / H\r\n")] + [InlineData("GET / HTTP/1.\r\n")] + [InlineData("GET / hello\r\n")] + [InlineData("GET / 8charact\r\n")] + // Missing LF after CR + [InlineData("GET / HTTP/1.0\rA\n")] // Bad HTTP Methods (invalid according to RFC) [InlineData("( / HTTP/1.0\r\n")] [InlineData(") / HTTP/1.0\r\n")] @@ -88,7 +71,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [InlineData("} / HTTP/1.0\r\n")] [InlineData("get@ / HTTP/1.0\r\n")] [InlineData("post= / HTTP/1.0\r\n")] - public async Task TestBadRequestLines(string request) + public async Task TestInvalidRequestLines(string request) { using (var server = new TestServer(context => TaskUtilities.CompletedTask)) { @@ -100,6 +83,8 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } } + // TODO: remove test once people agree to change this behavior + /* [Theory] [InlineData(" ")] [InlineData("GET ")] @@ -136,6 +121,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } } } + */ [Theory] // Missing final CRLF @@ -219,13 +205,9 @@ namespace Microsoft.AspNetCore.Server.KestrelTests private async Task ReceiveBadRequestResponse(TestConnection connection, string expectedDateHeaderValue) { - await connection.Receive( - "HTTP/1.1 400 Bad Request", - ""); - await connection.Receive( - "Connection: close", - ""); await connection.ReceiveForcedEnd( + "HTTP/1.1 400 Bad Request", + "Connection: close", $"Date: {expectedDateHeaderValue}", "Content-Length: 0", "", diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerLimitsTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerLimitsTests.cs new file mode 100644 index 0000000000..15a216130a --- /dev/null +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerLimitsTests.cs @@ -0,0 +1,67 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using Microsoft.AspNetCore.Server.Kestrel; +using Xunit; + +namespace Microsoft.AspNetCore.Server.KestrelTests +{ + public class KestrelServerLimitsTests + { + [Fact] + public void MaxRequestBufferSizeDefault() + { + Assert.Equal(1024 * 1024, (new KestrelServerLimits()).MaxRequestBufferSize); + } + + [Theory] + [InlineData(-1)] + [InlineData(0)] + public void MaxRequestBufferSizeInvalid(int value) + { + Assert.Throws(() => + { + (new KestrelServerLimits()).MaxRequestBufferSize = value; + }); + } + + [Theory] + [InlineData(null)] + [InlineData(1)] + public void MaxRequestBufferSizeValid(int? value) + { + var o = new KestrelServerLimits(); + o.MaxRequestBufferSize = value; + Assert.Equal(value, o.MaxRequestBufferSize); + } + + [Fact] + public void MaxRequestLineSizeDefault() + { + Assert.Equal(8 * 1024, (new KestrelServerLimits()).MaxRequestLineSize); + } + + [Theory] + [InlineData(int.MinValue)] + [InlineData(-1)] + [InlineData(0)] + public void MaxRequestLineSizeInvalid(int value) + { + Assert.Throws(() => + { + (new KestrelServerLimits()).MaxRequestLineSize = value; + }); + } + + [Theory] + [InlineData(1)] + [InlineData(int.MaxValue)] + public void MaxRequestLineSizeValid(int value) + { + var o = new KestrelServerLimits(); + o.MaxRequestLineSize = value; + Assert.Equal(value, o.MaxRequestLineSize); + } + } +} diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerOptionsTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerOptionsTests.cs index 9b05072c27..8beb1f7d59 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerOptionsTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerOptionsTests.cs @@ -2,42 +2,43 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.Collections.Generic; +using System.Linq; +using System.Reflection; using Microsoft.AspNetCore.Server.Kestrel; -using Microsoft.Extensions.Configuration; using Xunit; namespace Microsoft.AspNetCore.Server.KestrelTests { public class KestrelServerInformationTests { +#pragma warning disable CS0612 [Fact] - public void MaxRequestBufferSizeDefault() + public void MaxRequestBufferSizeIsMarkedObsolete() { - Assert.Equal(1024 * 1024, (new KestrelServerOptions()).MaxRequestBufferSize); + Assert.NotNull(typeof(KestrelServerOptions) + .GetProperty(nameof(KestrelServerOptions.MaxRequestBufferSize)) + .GetCustomAttributes(false) + .OfType() + .SingleOrDefault()); } - [Theory] - [InlineData(-1)] - [InlineData(0)] - public void MaxRequestBufferSizeInvalid(int value) - { - Assert.Throws(() => - { - (new KestrelServerOptions()).MaxRequestBufferSize = value; - }); - } - - [Theory] - [InlineData(null)] - [InlineData(1)] - public void MaxRequestBufferSizeValid(int? value) + [Fact] + public void MaxRequestBufferSizeGetsLimitsProperty() { var o = new KestrelServerOptions(); - o.MaxRequestBufferSize = value; - Assert.Equal(value, o.MaxRequestBufferSize); + o.Limits.MaxRequestBufferSize = 42; + Assert.Equal(42, o.MaxRequestBufferSize); } + [Fact] + public void MaxRequestBufferSizeSetsLimitsProperty() + { + var o = new KestrelServerOptions(); + o.MaxRequestBufferSize = 42; + Assert.Equal(42, o.Limits.MaxRequestBufferSize); + } +#pragma warning restore CS0612 + [Fact] public void SetThreadCountUsingProcessorCount() { diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolIteratorTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolIteratorTests.cs index a8c7e69510..fe450431e6 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolIteratorTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolIteratorTests.cs @@ -1,7 +1,12 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + using System; +using System.Collections.Generic; using System.Linq; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using System.Numerics; +using System.Text; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Xunit; namespace Microsoft.AspNetCore.Server.KestrelTests @@ -21,7 +26,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } [Fact] - public void FindFirstEqualByte() + public void TestFindFirstEqualByte() { var bytes = Enumerable.Repeat(0xff, Vector.Count).ToArray(); for (int i = 0; i < Vector.Count; i++) @@ -41,7 +46,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } [Fact] - public void FindFirstEqualByteSlow() + public void TestFindFirstEqualByteSlow() { var bytes = Enumerable.Repeat(0xff, Vector.Count).ToArray(); for (int i = 0; i < Vector.Count; i++) @@ -406,6 +411,255 @@ namespace Microsoft.AspNetCore.Server.KestrelTests TestKnownStringsInterning(input, expected, MemoryPoolIteratorExtensions.GetKnownMethod); } + [Theory] + [MemberData(nameof(SeekByteLimitData))] + public void TestSeekByteLimitWithinSameBlock(string input, char seek, int limit, int expectedBytesScanned, int expectedReturnValue) + { + MemoryPoolBlock block = null; + + try + { + // Arrange + var seekVector = new Vector((byte)seek); + + block = _pool.Lease(); + var chars = input.ToString().ToCharArray().Select(c => (byte)c).ToArray(); + Buffer.BlockCopy(chars, 0, block.Array, block.Start, chars.Length); + block.End += chars.Length; + var scan = block.GetIterator(); + + // Act + int bytesScanned; + var returnValue = scan.Seek(ref seekVector, out bytesScanned, limit); + + // Assert + Assert.Equal(expectedBytesScanned, bytesScanned); + Assert.Equal(expectedReturnValue, returnValue); + + Assert.Same(block, scan.Block); + var expectedEndIndex = expectedReturnValue != -1 ? + block.Start + input.IndexOf(seek) : + block.Start + expectedBytesScanned; + Assert.Equal(expectedEndIndex, scan.Index); + } + finally + { + // Cleanup + if (block != null) _pool.Return(block); + } + } + + [Theory] + [MemberData(nameof(SeekByteLimitData))] + public void TestSeekByteLimitAcrossBlocks(string input, char seek, int limit, int expectedBytesScanned, int expectedReturnValue) + { + MemoryPoolBlock block1 = null; + MemoryPoolBlock block2 = null; + MemoryPoolBlock emptyBlock = null; + + try + { + // Arrange + var seekVector = new Vector((byte)seek); + + var input1 = input.Substring(0, input.Length / 2); + block1 = _pool.Lease(); + var chars1 = input1.ToCharArray().Select(c => (byte)c).ToArray(); + Buffer.BlockCopy(chars1, 0, block1.Array, block1.Start, chars1.Length); + block1.End += chars1.Length; + + emptyBlock = _pool.Lease(); + block1.Next = emptyBlock; + + var input2 = input.Substring(input.Length / 2); + block2 = _pool.Lease(); + var chars2 = input2.ToCharArray().Select(c => (byte)c).ToArray(); + Buffer.BlockCopy(chars2, 0, block2.Array, block2.Start, chars2.Length); + block2.End += chars2.Length; + emptyBlock.Next = block2; + + var scan = block1.GetIterator(); + + // Act + int bytesScanned; + var returnValue = scan.Seek(ref seekVector, out bytesScanned, limit); + + // Assert + Assert.Equal(expectedBytesScanned, bytesScanned); + Assert.Equal(expectedReturnValue, returnValue); + + var seekCharIndex = input.IndexOf(seek); + var expectedEndBlock = limit <= input.Length / 2 ? + block1 : + (seekCharIndex != -1 && seekCharIndex < input.Length / 2 ? block1 : block2); + Assert.Same(expectedEndBlock, scan.Block); + var expectedEndIndex = expectedReturnValue != -1 ? + expectedEndBlock.Start + (expectedEndBlock == block1 ? input1.IndexOf(seek) : input2.IndexOf(seek)) : + expectedEndBlock.Start + (expectedEndBlock == block1 ? expectedBytesScanned : expectedBytesScanned - (input.Length / 2)); + Assert.Equal(expectedEndIndex, scan.Index); + } + finally + { + // Cleanup + if (block1 != null) _pool.Return(block1); + if (emptyBlock != null) _pool.Return(emptyBlock); + if (block2 != null) _pool.Return(block2); + } + } + + [Theory] + [MemberData(nameof(SeekIteratorLimitData))] + public void TestSeekIteratorLimitWithinSameBlock(string input, char seek, char limitAt, int expectedReturnValue) + { + MemoryPoolBlock block = null; + + try + { + // Arrange + var seekVector = new Vector((byte)seek); + var limitAtVector = new Vector((byte)limitAt); + var afterSeekVector = new Vector((byte)'B'); + + block = _pool.Lease(); + var chars = input.ToCharArray().Select(c => (byte)c).ToArray(); + Buffer.BlockCopy(chars, 0, block.Array, block.Start, chars.Length); + block.End += chars.Length; + var scan1 = block.GetIterator(); + var scan2_1 = scan1; + var scan2_2 = scan1; + var scan3_1 = scan1; + var scan3_2 = scan1; + var scan3_3 = scan1; + var end = scan1; + + // Act + var endReturnValue = end.Seek(ref limitAtVector); + var returnValue1 = scan1.Seek(ref seekVector, ref end); + var returnValue2_1 = scan2_1.Seek(ref seekVector, ref afterSeekVector, ref end); + var returnValue2_2 = scan2_2.Seek(ref afterSeekVector, ref seekVector, ref end); + var returnValue3_1 = scan3_1.Seek(ref seekVector, ref afterSeekVector, ref afterSeekVector, ref end); + var returnValue3_2 = scan3_2.Seek(ref afterSeekVector, ref seekVector, ref afterSeekVector, ref end); + var returnValue3_3 = scan3_3.Seek(ref afterSeekVector, ref afterSeekVector, ref seekVector, ref end); + + // Assert + Assert.Equal(input.Contains(limitAt) ? limitAt : -1, endReturnValue); + Assert.Equal(expectedReturnValue, returnValue1); + Assert.Equal(expectedReturnValue, returnValue2_1); + Assert.Equal(expectedReturnValue, returnValue2_2); + Assert.Equal(expectedReturnValue, returnValue3_1); + Assert.Equal(expectedReturnValue, returnValue3_2); + Assert.Equal(expectedReturnValue, returnValue3_3); + + Assert.Same(block, scan1.Block); + Assert.Same(block, scan2_1.Block); + Assert.Same(block, scan2_2.Block); + Assert.Same(block, scan3_1.Block); + Assert.Same(block, scan3_2.Block); + Assert.Same(block, scan3_3.Block); + + var expectedEndIndex = expectedReturnValue != -1 ? block.Start + input.IndexOf(seek) : end.Index; + Assert.Equal(expectedEndIndex, scan1.Index); + Assert.Equal(expectedEndIndex, scan2_1.Index); + Assert.Equal(expectedEndIndex, scan2_2.Index); + Assert.Equal(expectedEndIndex, scan3_1.Index); + Assert.Equal(expectedEndIndex, scan3_2.Index); + Assert.Equal(expectedEndIndex, scan3_3.Index); + } + finally + { + // Cleanup + if (block != null) _pool.Return(block); + } + } + + [Theory] + [MemberData(nameof(SeekIteratorLimitData))] + public void TestSeekIteratorLimitAcrossBlocks(string input, char seek, char limitAt, int expectedReturnValue) + { + MemoryPoolBlock block1 = null; + MemoryPoolBlock block2 = null; + MemoryPoolBlock emptyBlock = null; + + try + { + // Arrange + var seekVector = new Vector((byte)seek); + var limitAtVector = new Vector((byte)limitAt); + var afterSeekVector = new Vector((byte)'B'); + + var input1 = input.Substring(0, input.Length / 2); + block1 = _pool.Lease(); + var chars1 = input1.ToCharArray().Select(c => (byte)c).ToArray(); + Buffer.BlockCopy(chars1, 0, block1.Array, block1.Start, chars1.Length); + block1.End += chars1.Length; + + emptyBlock = _pool.Lease(); + block1.Next = emptyBlock; + + var input2 = input.Substring(input.Length / 2); + block2 = _pool.Lease(); + var chars2 = input2.ToCharArray().Select(c => (byte)c).ToArray(); + Buffer.BlockCopy(chars2, 0, block2.Array, block2.Start, chars2.Length); + block2.End += chars2.Length; + emptyBlock.Next = block2; + + var scan1 = block1.GetIterator(); + var scan2_1 = scan1; + var scan2_2 = scan1; + var scan3_1 = scan1; + var scan3_2 = scan1; + var scan3_3 = scan1; + var end = scan1; + + // Act + var endReturnValue = end.Seek(ref limitAtVector); + var returnValue1 = scan1.Seek(ref seekVector, ref end); + var returnValue2_1 = scan2_1.Seek(ref seekVector, ref afterSeekVector, ref end); + var returnValue2_2 = scan2_2.Seek(ref afterSeekVector, ref seekVector, ref end); + var returnValue3_1 = scan3_1.Seek(ref seekVector, ref afterSeekVector, ref afterSeekVector, ref end); + var returnValue3_2 = scan3_2.Seek(ref afterSeekVector, ref seekVector, ref afterSeekVector, ref end); + var returnValue3_3 = scan3_3.Seek(ref afterSeekVector, ref afterSeekVector, ref seekVector, ref end); + + // Assert + Assert.Equal(input.Contains(limitAt) ? limitAt : -1, endReturnValue); + Assert.Equal(expectedReturnValue, returnValue1); + Assert.Equal(expectedReturnValue, returnValue2_1); + Assert.Equal(expectedReturnValue, returnValue2_2); + Assert.Equal(expectedReturnValue, returnValue3_1); + Assert.Equal(expectedReturnValue, returnValue3_2); + Assert.Equal(expectedReturnValue, returnValue3_3); + + var seekCharIndex = input.IndexOf(seek); + var limitAtIndex = input.IndexOf(limitAt); + var expectedEndBlock = seekCharIndex != -1 && seekCharIndex < input.Length / 2 ? + block1 : + (limitAtIndex != -1 && limitAtIndex < input.Length / 2 ? block1 : block2); + Assert.Same(expectedEndBlock, scan1.Block); + Assert.Same(expectedEndBlock, scan2_1.Block); + Assert.Same(expectedEndBlock, scan2_2.Block); + Assert.Same(expectedEndBlock, scan3_1.Block); + Assert.Same(expectedEndBlock, scan3_2.Block); + Assert.Same(expectedEndBlock, scan3_3.Block); + + var expectedEndIndex = expectedReturnValue != -1 ? + expectedEndBlock.Start + (expectedEndBlock == block1 ? input1.IndexOf(seek) : input2.IndexOf(seek)) : + end.Index; + Assert.Equal(expectedEndIndex, scan1.Index); + Assert.Equal(expectedEndIndex, scan2_1.Index); + Assert.Equal(expectedEndIndex, scan2_2.Index); + Assert.Equal(expectedEndIndex, scan3_1.Index); + Assert.Equal(expectedEndIndex, scan3_2.Index); + Assert.Equal(expectedEndIndex, scan3_3.Index); + } + finally + { + // Cleanup + if (block1 != null) _pool.Return(block1); + if (emptyBlock != null) _pool.Return(emptyBlock); + if (block2 != null) _pool.Return(block2); + } + } + private delegate bool GetKnownString(MemoryPoolIterator iter, out string result); private void TestKnownStringsInterning(string input, string expected, GetKnownString action) @@ -435,5 +689,127 @@ namespace Microsoft.AspNetCore.Server.KestrelTests Assert.Equal(knownString1, expected); Assert.Same(knownString1, knownString2); } + + public static IEnumerable SeekByteLimitData + { + get + { + var vectorSpan = Vector.Count; + + // string input, char seek, int limit, int expectedBytesScanned, int expectedReturnValue + var data = new List(); + + // Non-vector inputs + + data.Add(new object[] { "hello, world", 'h', 12, 1, 'h' }); + data.Add(new object[] { "hello, world", ' ', 12, 7, ' ' }); + data.Add(new object[] { "hello, world", 'd', 12, 12, 'd' }); + data.Add(new object[] { "hello, world", '!', 12, 12, -1 }); + data.Add(new object[] { "hello, world", 'h', 13, 1, 'h' }); + data.Add(new object[] { "hello, world", ' ', 13, 7, ' ' }); + data.Add(new object[] { "hello, world", 'd', 13, 12, 'd' }); + data.Add(new object[] { "hello, world", '!', 13, 12, -1 }); + data.Add(new object[] { "hello, world", 'h', 5, 1, 'h' }); + data.Add(new object[] { "hello, world", 'o', 5, 5, 'o' }); + data.Add(new object[] { "hello, world", ',', 5, 5, -1 }); + data.Add(new object[] { "hello, world", 'd', 5, 5, -1 }); + data.Add(new object[] { "abba", 'a', 4, 1, 'a' }); + data.Add(new object[] { "abba", 'b', 4, 2, 'b' }); + + // Vector inputs + + // Single vector, no seek char in input, expect failure + data.Add(new object[] { new string('a', vectorSpan), 'b', vectorSpan, vectorSpan, -1 }); + // Two vectors, no seek char in input, expect failure + data.Add(new object[] { new string('a', vectorSpan * 2), 'b', vectorSpan * 2, vectorSpan * 2, -1 }); + // Two vectors plus non vector length (thus hitting slow path too), no seek char in input, expect failure + data.Add(new object[] { new string('a', vectorSpan * 2 + vectorSpan / 2), 'b', vectorSpan * 2 + vectorSpan / 2, vectorSpan * 2 + vectorSpan / 2, -1 }); + + // For each input length from 1/2 to 3 1/2 vector spans in 1/2 vector span increments... + for (var length = vectorSpan / 2; length <= vectorSpan * 3 + vectorSpan / 2; length += vectorSpan / 2) + { + // ...place the seek char at vector and input boundaries... + for (var i = Math.Min(vectorSpan - 1, length - 1); i < length; i += ((i + 1) % vectorSpan == 0) ? 1 : Math.Min(i + (vectorSpan - 1), length - 1)) + { + var input = new StringBuilder(new string('a', length)); + input[i] = 'b'; + + // ...and check with a seek byte limit before, at, and past the seek char position... + for (var limitOffset = -1; limitOffset <= 1; limitOffset++) + { + var limit = (i + 1) + limitOffset; + + if (limit >= i + 1) + { + // ...that Seek() succeeds when the seek char is within that limit... + data.Add(new object[] { input.ToString(), 'b', limit, i + 1, 'b' }); + } + else + { + // ...and fails when it's not. + data.Add(new object[] { input.ToString(), 'b', limit, Math.Min(length, limit), -1 }); + } + } + } + } + + return data; + } + } + + public static IEnumerable SeekIteratorLimitData + { + get + { + var vectorSpan = Vector.Count; + + // string input, char seek, char limitAt, int expectedReturnValue + var data = new List(); + + // Non-vector inputs + + data.Add(new object[] { "hello, world", 'h', 'd', 'h' }); + data.Add(new object[] { "hello, world", ' ', 'd', ' ' }); + data.Add(new object[] { "hello, world", 'd', 'd', 'd' }); + data.Add(new object[] { "hello, world", '!', 'd', -1 }); + data.Add(new object[] { "hello, world", 'h', 'w', 'h' }); + data.Add(new object[] { "hello, world", 'o', 'w', 'o' }); + data.Add(new object[] { "hello, world", 'r', 'w', -1 }); + data.Add(new object[] { "hello, world", 'd', 'w', -1 }); + + // Vector inputs + + // Single vector, no seek char in input, expect failure + data.Add(new object[] { new string('a', vectorSpan), 'b', 'b', -1 }); + // Two vectors, no seek char in input, expect failure + data.Add(new object[] { new string('a', vectorSpan * 2), 'b', 'b', -1 }); + // Two vectors plus non vector length (thus hitting slow path too), no seek char in input, expect failure + data.Add(new object[] { new string('a', vectorSpan * 2 + vectorSpan / 2), 'b', 'b', -1 }); + + // For each input length from 1/2 to 3 1/2 vector spans in 1/2 vector span increments... + for (var length = vectorSpan / 2; length <= vectorSpan * 3 + vectorSpan / 2; length += vectorSpan / 2) + { + // ...place the seek char at vector and input boundaries... + for (var i = Math.Min(vectorSpan - 1, length - 1); i < length; i += ((i + 1) % vectorSpan == 0) ? 1 : Math.Min(i + (vectorSpan - 1), length - 1)) + { + var input = new StringBuilder(new string('a', length)); + input[i] = 'b'; + + // ...along with sentinel characters to seek the limit iterator to... + input[i - 1] = 'A'; + if (i < length - 1) input[i + 1] = 'B'; + + // ...and check that Seek() succeeds with a limit iterator at or past the seek char position... + data.Add(new object[] { input.ToString(), 'b', 'b', 'b' }); + if (i < length - 1) data.Add(new object[] { input.ToString(), 'b', 'B', 'b' }); + + // ...and fails with a limit iterator before the seek char position. + data.Add(new object[] { input.ToString(), 'b', 'A', -1 }); + } + } + + return data; + } + } } } \ No newline at end of file diff --git a/test/shared/TestConnection.cs b/test/shared/TestConnection.cs index a27ccb29a9..4accbe0ed1 100644 --- a/test/shared/TestConnection.cs +++ b/test/shared/TestConnection.cs @@ -97,7 +97,7 @@ namespace Microsoft.AspNetCore.Testing var task = _reader.ReadAsync(actual, offset, actual.Length - offset); if (!Debugger.IsAttached) { - Assert.True(task.Wait(4000), "timeout"); + Assert.True(await Task.WhenAny(task, Task.Delay(10000)) == task, "TestConnection.Receive timed out."); } var count = await task; if (count == 0) From 4337d2a4a751ee7ccb0e0c460670c0abd044d040 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Thu, 28 Jul 2016 16:02:30 -0700 Subject: [PATCH 0841/1662] Implement Begin/End Read/Write methods in LibuvStream --- .../Filter/Internal/LibuvStream.cs | 78 +++++++++++++++++++ .../Filter/Internal/StreamSocketOutput.cs | 47 +++-------- 2 files changed, 90 insertions(+), 35 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Filter/Internal/LibuvStream.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Filter/Internal/LibuvStream.cs index 3ae1ddbd69..0127d156a0 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Filter/Internal/LibuvStream.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Filter/Internal/LibuvStream.cs @@ -132,5 +132,83 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Filter.Internal { return _input.ReadAsync(buffer.Array, buffer.Offset, buffer.Count); } + +#if NET451 + public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback callback, object state) + { + var task = ReadAsync(buffer, offset, count, default(CancellationToken), state); + if (callback != null) + { + task.ContinueWith(t => callback.Invoke(t)); + } + return task; + } + + public override int EndRead(IAsyncResult asyncResult) + { + return ((Task)asyncResult).GetAwaiter().GetResult(); + } + + private Task ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken, object state) + { + var tcs = new TaskCompletionSource(state); + var task = ReadAsync(buffer, offset, count, cancellationToken); + task.ContinueWith((task2, state2) => + { + var tcs2 = (TaskCompletionSource)state2; + if (task2.IsCanceled) + { + tcs2.SetCanceled(); + } + else if (task2.IsFaulted) + { + tcs2.SetException(task2.Exception); + } + else + { + tcs2.SetResult(task2.Result); + } + }, tcs, cancellationToken); + return tcs.Task; + } + + public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback callback, object state) + { + var task = WriteAsync(buffer, offset, count, default(CancellationToken), state); + if (callback != null) + { + task.ContinueWith(t => callback.Invoke(t)); + } + return task; + } + + public override void EndWrite(IAsyncResult asyncResult) + { + ((Task)asyncResult).GetAwaiter().GetResult(); + } + + private Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken, object state) + { + var tcs = new TaskCompletionSource(state); + var task = WriteAsync(buffer, offset, count, cancellationToken); + task.ContinueWith((task2, state2) => + { + var tcs2 = (TaskCompletionSource)state2; + if (task2.IsCanceled) + { + tcs2.SetCanceled(); + } + else if (task2.IsFaulted) + { + tcs2.SetException(task2.Exception); + } + else + { + tcs2.SetResult(null); + } + }, tcs, cancellationToken); + return tcs.Task; + } +#endif } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Filter/Internal/StreamSocketOutput.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Filter/Internal/StreamSocketOutput.cs index bfd7d5201b..52397633fc 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Filter/Internal/StreamSocketOutput.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Filter/Internal/StreamSocketOutput.cs @@ -24,8 +24,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Filter.Internal private bool _canWrite = true; - private object _writeLock = new object(); - public StreamSocketOutput(string connectionId, Stream outputStream, MemoryPool memory, IKestrelTrace logger) { _connectionId = connectionId; @@ -36,54 +34,33 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Filter.Internal public void Write(ArraySegment buffer, bool chunk) { - lock (_writeLock) + if (buffer.Count == 0 ) { - if (buffer.Count == 0 ) - { - return; - } + return; + } - try - { - if (!_canWrite) - { - return; - } + if (chunk && buffer.Array != null) + { + var beginChunkBytes = ChunkWriter.BeginChunkBytes(buffer.Count); + _outputStream.Write(beginChunkBytes.Array, beginChunkBytes.Offset, beginChunkBytes.Count); + } - if (chunk && buffer.Array != null) - { - var beginChunkBytes = ChunkWriter.BeginChunkBytes(buffer.Count); - _outputStream.Write(beginChunkBytes.Array, beginChunkBytes.Offset, beginChunkBytes.Count); - } + _outputStream.Write(buffer.Array ?? _nullBuffer, buffer.Offset, buffer.Count); - _outputStream.Write(buffer.Array ?? _nullBuffer, buffer.Offset, buffer.Count); - - if (chunk && buffer.Array != null) - { - _outputStream.Write(_endChunkBytes, 0, _endChunkBytes.Length); - } - } - catch (Exception ex) - { - _canWrite = false; - _logger.ConnectionError(_connectionId, ex); - } + if (chunk && buffer.Array != null) + { + _outputStream.Write(_endChunkBytes, 0, _endChunkBytes.Length); } } public Task WriteAsync(ArraySegment buffer, bool chunk, CancellationToken cancellationToken) { -#if NET451 - Write(buffer, chunk); - return TaskUtilities.CompletedTask; -#else if (chunk && buffer.Array != null) { return WriteAsyncChunked(buffer, cancellationToken); } return _outputStream.WriteAsync(buffer.Array ?? _nullBuffer, buffer.Offset, buffer.Count, cancellationToken); -#endif } private async Task WriteAsyncChunked(ArraySegment buffer, CancellationToken cancellationToken) From 5aee5247685b3e3f9157e229dfc2c7ba9248dcb3 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Thu, 28 Jul 2016 16:15:12 -0700 Subject: [PATCH 0842/1662] Ensure Begin/End Read/Write methods are correctly implemented - Add Begin/End Write methods to FrameResponseStream - Fix state check of Begin/End Read methods in FrameRequestStream --- .../Internal/Http/FrameRequestStream.cs | 8 +--- .../Internal/Http/FrameResponseStream.cs | 40 +++++++++++++++++++ 2 files changed, 42 insertions(+), 6 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameRequestStream.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameRequestStream.cs index e9e295a593..09a4834ef8 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameRequestStream.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameRequestStream.cs @@ -76,8 +76,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http #if NET451 public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback callback, object state) { - ValidateState(default(CancellationToken)); - var task = ReadAsync(buffer, offset, count, default(CancellationToken), state); if (callback != null) { @@ -93,11 +91,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http private Task ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken, object state) { - ValidateState(cancellationToken); - var tcs = new TaskCompletionSource(state); - var task = _body.ReadAsync(new ArraySegment(buffer, offset, count), cancellationToken); - task.AsTask().ContinueWith((task2, state2) => + var task = ReadAsync(buffer, offset, count, cancellationToken); + task.ContinueWith((task2, state2) => { var tcs2 = (TaskCompletionSource)state2; if (task2.IsCanceled) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameResponseStream.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameResponseStream.cs index 61013ac16c..5a3c9159d5 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameResponseStream.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameResponseStream.cs @@ -85,6 +85,46 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _frameControl.Write(new ArraySegment(buffer, offset, count)); } +#if NET451 + public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback callback, object state) + { + var task = WriteAsync(buffer, offset, count, default(CancellationToken), state); + if (callback != null) + { + task.ContinueWith(t => callback.Invoke(t)); + } + return task; + } + + public override void EndWrite(IAsyncResult asyncResult) + { + ((Task)asyncResult).GetAwaiter().GetResult(); + } + + private Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken, object state) + { + var tcs = new TaskCompletionSource(state); + var task = WriteAsync(buffer, offset, count, cancellationToken); + task.ContinueWith((task2, state2) => + { + var tcs2 = (TaskCompletionSource)state2; + if (task2.IsCanceled) + { + tcs2.SetCanceled(); + } + else if (task2.IsFaulted) + { + tcs2.SetException(task2.Exception); + } + else + { + tcs2.SetResult(null); + } + }, tcs, cancellationToken); + return tcs.Task; + } +#endif + public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) { var task = ValidateState(cancellationToken); From 9727a4db865780904f88b18a2636826dd45671d1 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Thu, 28 Jul 2016 16:34:12 -0700 Subject: [PATCH 0843/1662] Improve the performance of connection filters - Buffer connection filter input less by using ProducingStart/Complete - Simplify FilteredStreamAdapter --- .../Filter/Internal/FilteredStreamAdapter.cs | 75 +++++-------------- .../Internal/Http/Connection.cs | 11 +-- .../Internal/Http/Frame.cs | 2 +- .../Internal/Http/SocketInput.cs | 39 ---------- .../TestHelpers/SocketInputExtensions.cs | 37 +++++++++ .../TestInput.cs | 1 + 6 files changed, 58 insertions(+), 107 deletions(-) create mode 100644 test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/SocketInputExtensions.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Filter/Internal/FilteredStreamAdapter.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Filter/Internal/FilteredStreamAdapter.cs index e17a988b45..4f4a0f9405 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Filter/Internal/FilteredStreamAdapter.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Filter/Internal/FilteredStreamAdapter.cs @@ -6,18 +6,12 @@ using System.IO; using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; -using Microsoft.Extensions.Logging; namespace Microsoft.AspNetCore.Server.Kestrel.Filter.Internal { public class FilteredStreamAdapter : IDisposable { - private readonly string _connectionId; private readonly Stream _filteredStream; - private readonly IKestrelTrace _log; - private readonly MemoryPool _memory; - private MemoryPoolBlock _block; - private bool _aborted = false; public FilteredStreamAdapter( string connectionId, @@ -30,72 +24,39 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Filter.Internal SocketInput = new SocketInput(memory, threadPool, bufferSizeControl); SocketOutput = new StreamSocketOutput(connectionId, filteredStream, memory, logger); - _connectionId = connectionId; - _log = logger; _filteredStream = filteredStream; - _memory = memory; } - public SocketInput SocketInput { get; private set; } + public SocketInput SocketInput { get; } - public ISocketOutput SocketOutput { get; private set; } - - public Task ReadInputAsync() - { - _block = _memory.Lease(); - // Use pooled block for copy - return FilterInputAsync(_block).ContinueWith((task, state) => - { - ((FilteredStreamAdapter)state).OnStreamClose(task); - }, this); - } - - public void Abort() - { - _aborted = true; - } + public ISocketOutput SocketOutput { get; } public void Dispose() { SocketInput.Dispose(); } - private async Task FilterInputAsync(MemoryPoolBlock block) + public async Task ReadInputAsync() { int bytesRead; - while ((bytesRead = await _filteredStream.ReadAsync(block.Array, block.Data.Offset, block.Data.Count)) != 0) - { - SocketInput.IncomingData(block.Array, block.Data.Offset, bytesRead); - } - } - private void OnStreamClose(Task copyAsyncTask) - { - _memory.Return(_block); + do + { + var block = SocketInput.IncomingStart(); - if (copyAsyncTask.IsFaulted) - { - SocketInput.AbortAwaiting(); - _log.LogError(0, copyAsyncTask.Exception, "FilteredStreamAdapter.CopyToAsync"); - } - else if (copyAsyncTask.IsCanceled) - { - SocketInput.AbortAwaiting(); - _log.LogError("FilteredStreamAdapter.CopyToAsync canceled."); - } - else if (_aborted) - { - SocketInput.AbortAwaiting(); - } + try + { + var count = block.Data.Offset + block.Data.Count - block.End; + bytesRead = await _filteredStream.ReadAsync(block.Array, block.End, count); + } + catch (Exception ex) + { + SocketInput.IncomingComplete(0, ex); + throw; + } - try - { - SocketInput.IncomingFin(); - } - catch (Exception ex) - { - _log.LogError(0, ex, "FilteredStreamAdapter.OnStreamClose"); - } + SocketInput.IncomingComplete(bytesRead, error: null); + } while (bytesRead != 0); } } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Connection.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Connection.cs index 09a8c73d15..53de8bb857 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Connection.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Connection.cs @@ -144,21 +144,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { if (_filteredStreamAdapter != null) { - _filteredStreamAdapter.Abort(); - SocketInput.IncomingFin(); _readInputTask.ContinueWith((task, state) => { var connection = (Connection)state; connection._filterContext.Connection.Dispose(); connection._filteredStreamAdapter.Dispose(); - connection.SocketInput.Dispose(); }, this); } - else - { - SocketInput.Dispose(); - } + SocketInput.Dispose(); _socketClosedTcs.TrySetResult(null); } @@ -176,9 +170,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _frame.PrepareRequest = _filterContext.PrepareRequest; - // Reset needs to be called here so prepare request gets applied - _frame.Reset(); - _frame.Start(); } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs index ad46367135..447a437ca3 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs @@ -72,7 +72,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _pathBase = context.ServerAddress.PathBase; FrameControl = this; - Reset(); } public string ConnectionIdFeature { get; set; } @@ -313,6 +312,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http /// public void Start() { + Reset(); _requestProcessingTask = Task.Factory.StartNew( (o) => ((Frame)o).RequestProcessingAsync(), diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/SocketInput.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/SocketInput.cs index 9c7f43031e..61f477ea4a 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/SocketInput.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/SocketInput.cs @@ -67,39 +67,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http return _pinned; } - public void IncomingData(byte[] buffer, int offset, int count) - { - lock (_sync) - { - // Must call Add() before bytes are available to consumer, to ensure that Length is >= 0 - _bufferSizeControl?.Add(count); - - if (count > 0) - { - if (_tail == null) - { - _tail = _memory.Lease(); - } - - var iterator = new MemoryPoolIterator(_tail, _tail.End); - iterator.CopyFrom(buffer, offset, count); - - if (_head == null) - { - _head = _tail; - } - - _tail = iterator.Block; - } - else - { - FinReceived(); - } - - Complete(); - } - } - public void IncomingComplete(int count, Exception error) { lock (_sync) @@ -156,12 +123,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } } - public void IncomingFin() - { - // Force a FIN - IncomingData(null, 0, 0); - } - private void Complete() { var awaitableState = Interlocked.Exchange( diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/SocketInputExtensions.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/SocketInputExtensions.cs new file mode 100644 index 0000000000..998e0552c5 --- /dev/null +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/SocketInputExtensions.cs @@ -0,0 +1,37 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; + +namespace Microsoft.AspNetCore.Server.KestrelTests.TestHelpers +{ + public static class SocketInputExtensions + { + public static void IncomingData(this SocketInput input, byte[] buffer, int offset, int count) + { + var bufferIndex = offset; + var remaining = count; + + while (remaining > 0) + { + var block = input.IncomingStart(); + + var bytesLeftInBlock = block.Data.Offset + block.Data.Count - block.End; + var bytesToCopy = remaining < bytesLeftInBlock ? remaining : bytesLeftInBlock; + + Buffer.BlockCopy(buffer, bufferIndex, block.Array, block.End, bytesToCopy); + + bufferIndex += bytesToCopy; + remaining -= bytesToCopy; + + input.IncomingComplete(bytesToCopy, null); + } + } + + public static void IncomingFin(this SocketInput input) + { + input.IncomingComplete(0, null); + } + } +} diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestInput.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/TestInput.cs index 08106ed1c0..955cb088b9 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/TestInput.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/TestInput.cs @@ -8,6 +8,7 @@ using Microsoft.AspNetCore.Server.Kestrel; using Microsoft.AspNetCore.Server.Kestrel.Internal; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; +using Microsoft.AspNetCore.Server.KestrelTests.TestHelpers; namespace Microsoft.AspNetCore.Server.KestrelTests { From 140dc6fcf5e7d34c0627c100712922e987bb371e Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Thu, 4 Aug 2016 10:46:42 -0700 Subject: [PATCH 0844/1662] Add obsoletion reason for KestrelServerOptions.MaxRequestBufferSize. --- src/Microsoft.AspNetCore.Server.Kestrel/KestrelServerOptions.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServerOptions.cs b/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServerOptions.cs index 9e4331cbbd..7fe386e34c 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServerOptions.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServerOptions.cs @@ -46,7 +46,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel /// When set to null, the size of the request buffer is unlimited. /// Defaults to 1,048,576 bytes (1 MB). /// - [Obsolete] + [Obsolete("This property is obsolete and will be removed in a future version. Use Limits.MaxRequestBufferSize instead.")] public long? MaxRequestBufferSize { get From b8f21bee0313c747bc7482dc313a7ea87f6d7bf6 Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Thu, 4 Aug 2016 14:05:16 -0700 Subject: [PATCH 0845/1662] Update warning code for obsolete property in #pragma. --- .../KestrelServerOptionsTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerOptionsTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerOptionsTests.cs index 8beb1f7d59..540922a009 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerOptionsTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerOptionsTests.cs @@ -11,7 +11,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { public class KestrelServerInformationTests { -#pragma warning disable CS0612 +#pragma warning disable CS0618 [Fact] public void MaxRequestBufferSizeIsMarkedObsolete() { From fa41588779c8559d12e734ff86a941b7e74567b4 Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Thu, 4 Aug 2016 14:07:21 -0700 Subject: [PATCH 0846/1662] Move server start failure test in MaxRequestLineSizeTests to KestrelServerTests. --- .../MaxRequestLineSizeTests.cs | 15 --------------- .../KestrelServerTests.cs | 18 ++++++++++++++++++ 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/MaxRequestLineSizeTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/MaxRequestLineSizeTests.cs index 644fef0687..1e582f0bce 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/MaxRequestLineSizeTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/MaxRequestLineSizeTests.cs @@ -67,21 +67,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } } - [Theory] - [InlineData(1, 2)] - [InlineData(int.MaxValue - 1, int.MaxValue)] - public void ServerFailsToStartWhenMaxRequestBufferSizeIsLessThanMaxRequestLineSize(long maxRequestBufferSize, int maxRequestLineSize) - { - using (var host = BuildWebHost(options => - { - options.Limits.MaxRequestBufferSize = maxRequestBufferSize; - options.Limits.MaxRequestLineSize = maxRequestLineSize; - })) - { - Assert.Throws(() => host.Start()); - } - } - private IWebHost BuildWebHost(Action options) { var host = new WebHostBuilder() diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerTests.cs index 556d6f848e..d14df869a1 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerTests.cs @@ -49,6 +49,24 @@ namespace Microsoft.AspNetCore.Server.KestrelTests Assert.Equal("No recognized listening addresses were configured.", exception.Message); } + [Theory] + [InlineData(1, 2)] + [InlineData(int.MaxValue - 1, int.MaxValue)] + public void StartWithMaxRequestBufferSizeLessThanMaxRequestLineSizeThrows(long maxRequestBufferSize, int maxRequestLineSize) + { + var options = new KestrelServerOptions(); + options.Limits.MaxRequestBufferSize = maxRequestBufferSize; + options.Limits.MaxRequestLineSize = maxRequestLineSize; + + var server = CreateServer(options); + + var exception = Assert.Throws(() => StartDummyApplication(server)); + + Assert.Equal( + $"Maximum request buffer size ({maxRequestBufferSize}) must be greater than or equal to maximum request line size ({maxRequestLineSize}).", + exception.Message); + } + private static KestrelServer CreateServer(KestrelServerOptions options) { var lifetime = new LifetimeNotImplemented(); From 55f409b38b43b870c3a4c907ed5c9c0a8f9a2c52 Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Fri, 5 Aug 2016 16:46:34 -0700 Subject: [PATCH 0847/1662] Fix hanging functional tests. --- .../HttpsTests.cs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/HttpsTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/HttpsTests.cs index 2fa1838195..775e2c6a01 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/HttpsTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/HttpsTests.cs @@ -36,16 +36,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { // Close socket immediately } - } - await loggerFactory.FilterLogger.LogTcs.Task; + await loggerFactory.FilterLogger.LogTcs.Task.TimeoutAfter(TimeSpan.FromSeconds(10)); + } Assert.Equal(1, loggerFactory.FilterLogger.LastEventId.Id); Assert.Equal(LogLevel.Information, loggerFactory.FilterLogger.LastLogLevel); Assert.Equal(0, loggerFactory.ErrorLogger.TotalErrorsLogged); } - [Fact] public async Task ClientHandshakeFailureLoggedAsInformation() { @@ -70,9 +69,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests // Send null bytes and close socket await stream.WriteAsync(new byte[10], 0, 10); } - } - await loggerFactory.FilterLogger.LogTcs.Task; + await loggerFactory.FilterLogger.LogTcs.Task.TimeoutAfter(TimeSpan.FromSeconds(10)); + } Assert.Equal(1, loggerFactory.FilterLogger.LastEventId.Id); Assert.Equal(LogLevel.Information, loggerFactory.FilterLogger.LastLogLevel); @@ -94,7 +93,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { return ErrorLogger; } - } public void AddProvider(ILoggerProvider provider) From a5aacd6307231a6da5d27fdccc41e3b51740b97a Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Mon, 8 Aug 2016 11:38:06 -0700 Subject: [PATCH 0848/1662] Throw when setting OnStarting after response has already started (#806). --- .../Internal/Http/Frame.cs | 5 +++++ .../FrameTests.cs | 20 +++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs index 447a437ca3..70e5bce881 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs @@ -382,6 +382,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { lock (_onStartingSync) { + if (HasResponseStarted) + { + ThrowResponseAlreadyStartedException(nameof(OnStarting)); + } + if (_onStarting == null) { _onStarting = new List, object>>(); diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs index 876b0279f5..7b1af2b94f 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs @@ -440,6 +440,26 @@ namespace Microsoft.AspNetCore.Server.KestrelTests Assert.Throws(() => ((IHttpResponseFeature)frame).ReasonPhrase = "Reason phrase"); } + [Fact] + public void ThrowsWhenOnStartingIsSetAfterResponseStarted() + { + // Arrange + var connectionContext = new ConnectionContext() + { + DateHeaderValueManager = new DateHeaderValueManager(), + ServerAddress = ServerAddress.FromUrl("http://localhost:5000"), + ServerOptions = new KestrelServerOptions(), + SocketOutput = new MockSocketOuptut() + }; + var frame = new Frame(application: null, context: connectionContext); + frame.InitializeHeaders(); + frame.Write(new ArraySegment(new byte[1])); + + // Act/Assert + Assert.True(frame.HasResponseStarted); + Assert.Throws(() => ((IHttpResponseFeature)frame).OnStarting(_ => TaskUtilities.CompletedTask, null)); + } + [Fact] public void InitializeHeadersResetsRequestHeaders() { From f2fa8b566007eefccd2058496d06bcbf9be418be Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Mon, 8 Aug 2016 11:58:37 -0700 Subject: [PATCH 0849/1662] Add functional test. --- .../ResponseTests.cs | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs index f4bf6c323f..54ee883656 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs @@ -9,6 +9,7 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.Extensions.Primitives; using Xunit; @@ -144,6 +145,39 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } } + [Fact] + public async Task OnStartingThrowsWhenSetAfterResponseHasAlreadyStarted() + { + InvalidOperationException ex = null; + + var hostBuilder = new WebHostBuilder() + .UseKestrel() + .UseUrls("http://127.0.0.1:0/") + .Configure(app => + { + app.Run(async context => + { + await context.Response.WriteAsync("hello, world"); + await context.Response.Body.FlushAsync(); + ex = Assert.Throws(() => context.Response.OnStarting(_ => TaskUtilities.CompletedTask, null)); + }); + }); + + using (var host = hostBuilder.Build()) + { + host.Start(); + + using (var client = new HttpClient()) + { + var response = await client.GetAsync($"http://localhost:{host.GetPort()}/"); + + // Despite the error, the response had already started + Assert.Equal(HttpStatusCode.OK, response.StatusCode); + Assert.NotNull(ex); + } + } + } + public static TheoryData NullHeaderData { get From 2f9bf9bb871e7f9a38924e9f302ead8840ba697f Mon Sep 17 00:00:00 2001 From: Pranav K Date: Mon, 8 Aug 2016 14:34:35 -0700 Subject: [PATCH 0850/1662] Updating to Moq \ Castle.Core that does not require imports --- test/Microsoft.AspNetCore.Server.KestrelTests/project.json | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/project.json b/test/Microsoft.AspNetCore.Server.KestrelTests/project.json index 9354978969..1584bc0e99 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/project.json +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/project.json @@ -5,7 +5,7 @@ "Microsoft.AspNetCore.Server.Kestrel": "1.1.0-*", "Microsoft.AspNetCore.Server.Kestrel.Https": "1.1.0-*", "Microsoft.AspNetCore.Testing": "1.1.0-*", - "Moq": "4.6.25-*", + "Moq": "4.6.36-*", "xunit": "2.2.0-*" }, "frameworks": { @@ -22,8 +22,7 @@ "System.Net.Http.WinHttpHandler": "4.0.0-*", "System.Net.Sockets": "4.1.0-*", "System.Runtime.Handles": "4.0.1-*" - }, - "imports": "dotnet5.4" + } }, "net451": { "frameworkAssemblies": { From 08f98f479068340396111016b961b73fe9001d4c Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Thu, 4 Aug 2016 16:26:53 -0700 Subject: [PATCH 0851/1662] Add header limit options (#475). --- .../BadHttpRequestException.cs | 13 +- .../Internal/Http/Frame.cs | 91 ++++---- .../Internal/Http/RequestRejectionReason.cs | 5 +- .../KestrelServerLimits.cs | 50 +++++ .../RequestHeaderLimitsTests.cs | 140 ++++++++++++ .../ChunkedRequestTests.cs | 83 +++++++ .../FrameTests.cs | 207 ++++++++++++++++-- .../KestrelServerLimitsTests.cs | 56 +++++ 8 files changed, 583 insertions(+), 62 deletions(-) create mode 100644 test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestHeaderLimitsTests.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/BadHttpRequestException.cs b/src/Microsoft.AspNetCore.Server.Kestrel/BadHttpRequestException.cs index 9a435392ff..64365e486e 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/BadHttpRequestException.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/BadHttpRequestException.cs @@ -49,8 +49,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel case RequestRejectionReason.WhitespaceIsNotAllowedInHeaderName: ex = new BadHttpRequestException("Whitespace is not allowed in header name."); break; - case RequestRejectionReason.HeaderLineMustEndInCRLFOnlyCRFound: - ex = new BadHttpRequestException("Header line must end in CRLF; only CR found."); + case RequestRejectionReason.HeaderValueMustNotContainCR: + ex = new BadHttpRequestException("Header value must not contain CR characters."); break; case RequestRejectionReason.HeaderValueLineFoldingNotSupported: ex = new BadHttpRequestException("Header value line folding not supported."); @@ -91,6 +91,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel case RequestRejectionReason.MissingCrAfterVersion: ex = new BadHttpRequestException("Missing CR in request line."); break; + case RequestRejectionReason.HeadersExceedMaxTotalSize: + ex = new BadHttpRequestException("Request headers too long."); + break; + case RequestRejectionReason.MissingCRInHeaderLine: + ex = new BadHttpRequestException("No CR character found in header line."); + break; + case RequestRejectionReason.TooManyHeaders: + ex = new BadHttpRequestException("Request contains too many headers."); + break; default: ex = new BadHttpRequestException("Bad request."); break; diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs index 70e5bce881..f6415b2bb1 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs @@ -66,6 +66,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http private readonly string _pathBase; + private int _remainingRequestHeadersBytesAllowed; + private int _requestHeadersParsed; + public Frame(ConnectionContext context) : base(context) { @@ -305,6 +308,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _manuallySetRequestAbortToken = null; _abortedCts = null; + + _remainingRequestHeadersBytesAllowed = ServerOptions.Limits.MaxRequestHeadersTotalSize; + _requestHeadersParsed = 0; } /// @@ -1083,63 +1089,63 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http RejectRequest(RequestRejectionReason.HeaderLineMustNotStartWithWhitespace); } - var beginName = scan; - if (scan.Seek(ref _vectorColons, ref _vectorCRs) == -1) + // If we've parsed the max allowed numbers of headers and we're starting a new + // one, we've gone over the limit. + if (_requestHeadersParsed == ServerOptions.Limits.MaxRequestHeaderCount) { - return false; - } - var endName = scan; - - ch = scan.Take(); - if (ch != ':') - { - RejectRequest(RequestRejectionReason.NoColonCharacterFoundInHeaderLine); + RejectRequest(RequestRejectionReason.TooManyHeaders); } - var validateName = beginName; - if (validateName.Seek(ref _vectorSpaces, ref _vectorTabs, ref _vectorColons) != ':') + var end = scan; + int bytesScanned; + if (end.Seek(ref _vectorLFs, out bytesScanned, _remainingRequestHeadersBytesAllowed) == -1) { - RejectRequest(RequestRejectionReason.WhitespaceIsNotAllowedInHeaderName); - } - - var beginValue = scan; - ch = scan.Peek(); - - if (ch == -1) - { - return false; - } - - // Skip header value leading whitespace. - while (ch == ' ' || ch == '\t') - { - scan.Take(); - beginValue = scan; - - ch = scan.Peek(); - if (ch == -1) + if (bytesScanned >= _remainingRequestHeadersBytesAllowed) + { + RejectRequest(RequestRejectionReason.HeadersExceedMaxTotalSize); + } + else { return false; } } - scan = beginValue; - if (scan.Seek(ref _vectorCRs) == -1) + var beginName = scan; + if (scan.Seek(ref _vectorColons, ref end) == -1) { - // no "\r" in sight, burn used bytes and go back to await more data - return false; + RejectRequest(RequestRejectionReason.NoColonCharacterFoundInHeaderLine); + } + var endName = scan; + + scan.Take(); + + var validateName = beginName; + if (validateName.Seek(ref _vectorSpaces, ref _vectorTabs, ref endName) != -1) + { + RejectRequest(RequestRejectionReason.WhitespaceIsNotAllowedInHeaderName); + } + + var beginValue = scan; + ch = scan.Take(); + + while (ch == ' ' || ch == '\t') + { + beginValue = scan; + ch = scan.Take(); + } + + scan = beginValue; + if (scan.Seek(ref _vectorCRs, ref end) == -1) + { + RejectRequest(RequestRejectionReason.MissingCRInHeaderLine); } scan.Take(); // we know this is '\r' ch = scan.Take(); // expecting '\n' - if (ch == -1) + if (ch != '\n') { - return false; - } - else if (ch != '\n') - { - RejectRequest(RequestRejectionReason.HeaderLineMustEndInCRLFOnlyCRFound); + RejectRequest(RequestRejectionReason.HeaderValueMustNotContainCR); } var next = scan.Peek(); @@ -1195,6 +1201,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http consumed = scan; requestHeaders.Append(name.Array, name.Offset, name.Count, value); + + _remainingRequestHeadersBytesAllowed -= bytesScanned; + _requestHeadersParsed++; } return false; diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/RequestRejectionReason.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/RequestRejectionReason.cs index d71ff5b414..a0d04ed0fc 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/RequestRejectionReason.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/RequestRejectionReason.cs @@ -15,7 +15,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http HeaderLineMustNotStartWithWhitespace, NoColonCharacterFoundInHeaderLine, WhitespaceIsNotAllowedInHeaderName, - HeaderLineMustEndInCRLFOnlyCRFound, + HeaderValueMustNotContainCR, HeaderValueLineFoldingNotSupported, MalformedRequestLineStatus, MalformedRequestInvalidHeaders, @@ -31,5 +31,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http MissingSpaceAfterMethod, MissingSpaceAfterTarget, MissingCrAfterVersion, + HeadersExceedMaxTotalSize, + MissingCRInHeaderLine, + TooManyHeaders, } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServerLimits.cs b/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServerLimits.cs index 02afceca2b..d59bcd75e9 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServerLimits.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServerLimits.cs @@ -14,6 +14,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel // Matches the default large_client_header_buffers in nginx. private int _maxRequestLineSize = 8 * 1024; + // Matches the default large_client_header_buffers in nginx. + private int _maxRequestHeadersTotalSize = 32 * 1024; + + // Matches the default LimitRequestFields in Apache httpd. + private int _maxRequestHeaderCount = 100; + /// /// Gets or sets the maximum size of the request buffer. /// @@ -58,5 +64,49 @@ namespace Microsoft.AspNetCore.Server.Kestrel _maxRequestLineSize = value; } } + + /// + /// Gets or sets the maximum allowed size for the HTTP request headers. + /// + /// + /// Defaults to 32,768 bytes (32 KB). + /// + public int MaxRequestHeadersTotalSize + { + get + { + return _maxRequestHeadersTotalSize; + } + set + { + if (value <= 0) + { + throw new ArgumentOutOfRangeException(nameof(value), "Value must a positive integer."); + } + _maxRequestHeadersTotalSize = value; + } + } + + /// + /// Gets or sets the maximum allowed number of headers per HTTP request. + /// + /// + /// Defaults to 100. + /// + public int MaxRequestHeaderCount + { + get + { + return _maxRequestHeaderCount; + } + set + { + if (value <= 0) + { + throw new ArgumentOutOfRangeException(nameof(value), "Value must a positive integer."); + } + _maxRequestHeaderCount = value; + } + } } } diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestHeaderLimitsTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestHeaderLimitsTests.cs new file mode 100644 index 0000000000..2c7eec616e --- /dev/null +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestHeaderLimitsTests.cs @@ -0,0 +1,140 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Linq; +using System.Net.Http; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Testing; +using Xunit; + +namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests +{ + public class RequestHeaderLimitsTests + { + [Theory] + [InlineData(0, 1)] + [InlineData(0, 1337)] + [InlineData(1, 0)] + [InlineData(1, 1)] + [InlineData(1, 1337)] + [InlineData(5, 0)] + [InlineData(5, 1)] + [InlineData(5, 1337)] + public async Task ServerAcceptsRequestWithHeaderTotalSizeWithinLimit(int headerCount, int extraLimit) + { + var headers = MakeHeaders(headerCount); + + using (var host = BuildWebHost(options => + { + options.Limits.MaxRequestHeadersTotalSize = headers.Length + extraLimit; + })) + { + host.Start(); + + using (var connection = new TestConnection(host.GetPort())) + { + await connection.SendEnd($"GET / HTTP/1.1\r\n{headers}\r\n"); + await connection.Receive($"HTTP/1.1 200 OK\r\n"); + } + } + } + + [Theory] + [InlineData(0, 1)] + [InlineData(0, 1337)] + [InlineData(1, 1)] + [InlineData(1, 2)] + [InlineData(1, 1337)] + [InlineData(5, 5)] + [InlineData(5, 6)] + [InlineData(5, 1337)] + public async Task ServerAcceptsRequestWithHeaderCountWithinLimit(int headerCount, int maxHeaderCount) + { + var headers = MakeHeaders(headerCount); + + using (var host = BuildWebHost(options => + { + options.Limits.MaxRequestHeaderCount = maxHeaderCount; + })) + { + host.Start(); + + using (var connection = new TestConnection(host.GetPort())) + { + await connection.SendEnd($"GET / HTTP/1.1\r\n{headers}\r\n"); + await connection.Receive($"HTTP/1.1 200 OK\r\n"); + } + } + } + + [Theory] + [InlineData(1)] + [InlineData(5)] + public async Task ServerRejectsRequestWithHeaderTotalSizeOverLimit(int headerCount) + { + var headers = MakeHeaders(headerCount); + + using (var host = BuildWebHost(options => + { + options.Limits.MaxRequestHeadersTotalSize = headers.Length - 1; + })) + { + host.Start(); + + using (var connection = new TestConnection(host.GetPort())) + { + await connection.SendAllTryEnd($"GET / HTTP/1.1\r\n{headers}\r\n"); + await connection.Receive($"HTTP/1.1 400 Bad Request\r\n"); + } + } + } + + [Theory] + [InlineData(2, 1)] + [InlineData(5, 1)] + [InlineData(5, 4)] + public async Task ServerRejectsRequestWithHeaderCountOverLimit(int headerCount, int maxHeaderCount) + { + var headers = MakeHeaders(headerCount); + + using (var host = BuildWebHost(options => + { + options.Limits.MaxRequestHeaderCount = maxHeaderCount; + })) + { + host.Start(); + + using (var connection = new TestConnection(host.GetPort())) + { + await connection.SendAllTryEnd($"GET / HTTP/1.1\r\n{headers}\r\n"); + await connection.Receive($"HTTP/1.1 400 Bad Request\r\n"); + } + } + } + + private static string MakeHeaders(int count) + { + return string.Join("", Enumerable + .Range(0, count) + .Select(i => $"Header-{i}: value{i}\r\n")); + } + + private static IWebHost BuildWebHost(Action options) + { + var host = new WebHostBuilder() + .UseKestrel(options) + .UseUrls("http://127.0.0.1:0/") + .Configure(app => app.Run(async context => + { + await context.Response.WriteAsync("hello, world"); + })) + .Build(); + + return host; + } + } +} \ No newline at end of file diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedRequestTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedRequestTests.cs index e3ef2109df..c6de0ab0e3 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedRequestTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedRequestTests.cs @@ -255,6 +255,89 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } } + [Theory] + [MemberData(nameof(ConnectionFilterData))] + public async Task TrailingHeadersCountTowardsHeadersTotalSizeLimit(TestServiceContext testContext) + { + const string transferEncodingHeaderLine = "Transfer-Encoding: chunked"; + const string headerLine = "Header: value"; + const string trailingHeaderLine = "Trailing-Header: trailing-value"; + + testContext.ServerOptions.Limits.MaxRequestHeadersTotalSize = + transferEncodingHeaderLine.Length + 2 + + headerLine.Length + 2 + + trailingHeaderLine.Length + 1; + + using (var server = new TestServer(async context => + { + var buffer = new byte[128]; + while (await context.Request.Body.ReadAsync(buffer, 0, buffer.Length) != 0) ; // read to end + }, testContext)) + { + using (var connection = server.CreateConnection()) + { + await connection.SendAllTryEnd( + "POST / HTTP/1.1", + $"{transferEncodingHeaderLine}", + $"{headerLine}", + "", + "2", + "42", + "0", + $"{trailingHeaderLine}", + "", + ""); + await connection.ReceiveForcedEnd( + "HTTP/1.1 400 Bad Request", + "Connection: close", + $"Date: {testContext.DateHeaderValue}", + "Content-Length: 0", + "", + ""); + } + } + } + + [Theory] + [MemberData(nameof(ConnectionFilterData))] + public async Task TrailingHeadersCountTowardsHeaderCountLimit(TestServiceContext testContext) + { + const string transferEncodingHeaderLine = "Transfer-Encoding: chunked"; + const string headerLine = "Header: value"; + const string trailingHeaderLine = "Trailing-Header: trailing-value"; + + testContext.ServerOptions.Limits.MaxRequestHeaderCount = 2; + + using (var server = new TestServer(async context => + { + var buffer = new byte[128]; + while (await context.Request.Body.ReadAsync(buffer, 0, buffer.Length) != 0) ; // read to end + }, testContext)) + { + using (var connection = server.CreateConnection()) + { + await connection.SendAllTryEnd( + "POST / HTTP/1.1", + $"{transferEncodingHeaderLine}", + $"{headerLine}", + "", + "2", + "42", + "0", + $"{trailingHeaderLine}", + "", + ""); + await connection.ReceiveForcedEnd( + "HTTP/1.1 400 Bad Request", + "Connection: close", + $"Date: {testContext.DateHeaderValue}", + "Content-Length: 0", + "", + ""); + } + } + } + [Theory] [MemberData(nameof(ConnectionFilterData))] public async Task ExtensionsAreIgnored(TestServiceContext testContext) diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs index 7b1af2b94f..5a0492ea19 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs @@ -27,9 +27,11 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var connectionContext = new ConnectionContext() { DateHeaderValueManager = new DateHeaderValueManager(), - ServerAddress = ServerAddress.FromUrl("http://localhost:5000") + ServerAddress = ServerAddress.FromUrl("http://localhost:5000"), + ServerOptions = new KestrelServerOptions(), }; var frame = new Frame(application: null, context: connectionContext); + frame.Reset(); frame.InitializeHeaders(); var headerArray = Encoding.ASCII.GetBytes("Header:value\r\n\r\n"); @@ -68,9 +70,11 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var connectionContext = new ConnectionContext() { DateHeaderValueManager = new DateHeaderValueManager(), - ServerAddress = ServerAddress.FromUrl("http://localhost:5000") + ServerAddress = ServerAddress.FromUrl("http://localhost:5000"), + ServerOptions = new KestrelServerOptions(), }; var frame = new Frame(application: null, context: connectionContext); + frame.Reset(); frame.InitializeHeaders(); var headerArray = Encoding.ASCII.GetBytes(rawHeaders); @@ -109,8 +113,10 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { DateHeaderValueManager = new DateHeaderValueManager(), ServerAddress = ServerAddress.FromUrl("http://localhost:5000"), + ServerOptions = new KestrelServerOptions(), }; var frame = new Frame(application: null, context: connectionContext); + frame.Reset(); frame.InitializeHeaders(); var headerArray = Encoding.ASCII.GetBytes(rawHeaders); @@ -148,8 +154,10 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { DateHeaderValueManager = new DateHeaderValueManager(), ServerAddress = ServerAddress.FromUrl("http://localhost:5000"), + ServerOptions = new KestrelServerOptions(), }; var frame = new Frame(application: null, context: connectionContext); + frame.Reset(); frame.InitializeHeaders(); var headerArray = Encoding.ASCII.GetBytes(rawHeaders); @@ -187,23 +195,23 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { DateHeaderValueManager = new DateHeaderValueManager(), ServerAddress = ServerAddress.FromUrl("http://localhost:5000"), + ServerOptions = new KestrelServerOptions(), Log = trace }; var frame = new Frame(application: null, context: connectionContext); + frame.Reset(); frame.InitializeHeaders(); var headerArray = Encoding.ASCII.GetBytes(rawHeaders); socketInput.IncomingData(headerArray, 0, headerArray.Length); - Assert.Throws(() => frame.TakeMessageHeaders(socketInput, (FrameRequestHeaders)frame.RequestHeaders)); + var exception = Assert.Throws(() => frame.TakeMessageHeaders(socketInput, (FrameRequestHeaders)frame.RequestHeaders)); + Assert.Equal("Header value line folding not supported.", exception.Message); } } - [Theory] - [InlineData("Header-1: value1\r\r\n")] - [InlineData("Header-1: value1\rHeader-2: value2\r\n\r\n")] - [InlineData("Header-1: value1\r\nHeader-2: value2\r\r\n")] - public void ThrowsOnHeaderLineNotEndingInCRLF(string rawHeaders) + [Fact] + public void ThrowsOnHeaderValueWithLineFolding_CharacterNotAvailableOnFirstAttempt() { var trace = new KestrelTrace(new TestKestrelTrace()); var ltp = new LoggingThreadPool(trace); @@ -214,15 +222,54 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { DateHeaderValueManager = new DateHeaderValueManager(), ServerAddress = ServerAddress.FromUrl("http://localhost:5000"), + ServerOptions = new KestrelServerOptions(), Log = trace }; var frame = new Frame(application: null, context: connectionContext); + frame.Reset(); + frame.InitializeHeaders(); + + var headerArray = Encoding.ASCII.GetBytes("Header-1: value1\r\n"); + socketInput.IncomingData(headerArray, 0, headerArray.Length); + + Assert.False(frame.TakeMessageHeaders(socketInput, (FrameRequestHeaders)frame.RequestHeaders)); + + socketInput.IncomingData(Encoding.ASCII.GetBytes(" "), 0, 1); + + var exception = Assert.Throws(() => frame.TakeMessageHeaders(socketInput, (FrameRequestHeaders)frame.RequestHeaders)); + Assert.Equal("Header value line folding not supported.", exception.Message); + } + } + + [Theory] + [InlineData("Header-1: value1\r\r\n")] + [InlineData("Header-1: val\rue1\r\n")] + [InlineData("Header-1: value1\rHeader-2: value2\r\n\r\n")] + [InlineData("Header-1: value1\r\nHeader-2: value2\r\r\n")] + [InlineData("Header-1: value1\r\nHeader-2: v\ralue2\r\n")] + public void ThrowsOnHeaderValueContainingCR(string rawHeaders) + { + var trace = new KestrelTrace(new TestKestrelTrace()); + var ltp = new LoggingThreadPool(trace); + using (var pool = new MemoryPool()) + using (var socketInput = new SocketInput(pool, ltp)) + { + var connectionContext = new ConnectionContext() + { + DateHeaderValueManager = new DateHeaderValueManager(), + ServerAddress = ServerAddress.FromUrl("http://localhost:5000"), + ServerOptions = new KestrelServerOptions(), + Log = trace + }; + var frame = new Frame(application: null, context: connectionContext); + frame.Reset(); frame.InitializeHeaders(); var headerArray = Encoding.ASCII.GetBytes(rawHeaders); socketInput.IncomingData(headerArray, 0, headerArray.Length); - Assert.Throws(() => frame.TakeMessageHeaders(socketInput, (FrameRequestHeaders)frame.RequestHeaders)); + var exception = Assert.Throws(() => frame.TakeMessageHeaders(socketInput, (FrameRequestHeaders)frame.RequestHeaders)); + Assert.Equal("Header value must not contain CR characters.", exception.Message); } } @@ -241,15 +288,18 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { DateHeaderValueManager = new DateHeaderValueManager(), ServerAddress = ServerAddress.FromUrl("http://localhost:5000"), + ServerOptions = new KestrelServerOptions(), Log = trace }; var frame = new Frame(application: null, context: connectionContext); + frame.Reset(); frame.InitializeHeaders(); var headerArray = Encoding.ASCII.GetBytes(rawHeaders); socketInput.IncomingData(headerArray, 0, headerArray.Length); - Assert.Throws(() => frame.TakeMessageHeaders(socketInput, (FrameRequestHeaders)frame.RequestHeaders)); + var exception = Assert.Throws(() => frame.TakeMessageHeaders(socketInput, (FrameRequestHeaders)frame.RequestHeaders)); + Assert.Equal("No ':' character found in header line.", exception.Message); } } @@ -258,8 +308,6 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [InlineData("\tHeader: value\r\n\r\n")] [InlineData(" Header-1: value1\r\nHeader-2: value2\r\n\r\n")] [InlineData("\tHeader-1: value1\r\nHeader-2: value2\r\n\r\n")] - [InlineData("Header-1: value1\r\n Header-2: value2\r\n\r\n")] - [InlineData("Header-1: value1\r\n\tHeader-2: value2\r\n\r\n")] public void ThrowsOnHeaderLineStartingWithWhitespace(string rawHeaders) { var trace = new KestrelTrace(new TestKestrelTrace()); @@ -271,15 +319,18 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { DateHeaderValueManager = new DateHeaderValueManager(), ServerAddress = ServerAddress.FromUrl("http://localhost:5000"), + ServerOptions = new KestrelServerOptions(), Log = trace }; var frame = new Frame(application: null, context: connectionContext); + frame.Reset(); frame.InitializeHeaders(); var headerArray = Encoding.ASCII.GetBytes(rawHeaders); socketInput.IncomingData(headerArray, 0, headerArray.Length); - Assert.Throws(() => frame.TakeMessageHeaders(socketInput, (FrameRequestHeaders)frame.RequestHeaders)); + var exception = Assert.Throws(() => frame.TakeMessageHeaders(socketInput, (FrameRequestHeaders)frame.RequestHeaders)); + Assert.Equal("Header line must not start with whitespace.", exception.Message); } } @@ -303,21 +354,25 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { DateHeaderValueManager = new DateHeaderValueManager(), ServerAddress = ServerAddress.FromUrl("http://localhost:5000"), + ServerOptions = new KestrelServerOptions(), Log = trace }; var frame = new Frame(application: null, context: connectionContext); + frame.Reset(); frame.InitializeHeaders(); var headerArray = Encoding.ASCII.GetBytes(rawHeaders); socketInput.IncomingData(headerArray, 0, headerArray.Length); - Assert.Throws(() => frame.TakeMessageHeaders(socketInput, (FrameRequestHeaders)frame.RequestHeaders)); + var exception = Assert.Throws(() => frame.TakeMessageHeaders(socketInput, (FrameRequestHeaders)frame.RequestHeaders)); + Assert.Equal("Whitespace is not allowed in header name.", exception.Message); } } [Theory] + [InlineData("Header-1: value1\r\nHeader-2: value2\r\n\r\r")] [InlineData("Header-1: value1\r\nHeader-2: value2\r\n\r ")] - [InlineData("Header-1: value1\r\nHeader-2: value2\r\nEnd\r\n")] + [InlineData("Header-1: value1\r\nHeader-2: value2\r\n\r \n")] public void ThrowsOnHeadersNotEndingInCRLFLine(string rawHeaders) { var trace = new KestrelTrace(new TestKestrelTrace()); @@ -329,15 +384,84 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { DateHeaderValueManager = new DateHeaderValueManager(), ServerAddress = ServerAddress.FromUrl("http://localhost:5000"), + ServerOptions = new KestrelServerOptions(), Log = trace }; var frame = new Frame(application: null, context: connectionContext); + frame.Reset(); frame.InitializeHeaders(); var headerArray = Encoding.ASCII.GetBytes(rawHeaders); socketInput.IncomingData(headerArray, 0, headerArray.Length); - Assert.Throws(() => frame.TakeMessageHeaders(socketInput, (FrameRequestHeaders)frame.RequestHeaders)); + var exception = Assert.Throws(() => frame.TakeMessageHeaders(socketInput, (FrameRequestHeaders)frame.RequestHeaders)); + Assert.Equal("Headers corrupted, invalid header sequence.", exception.Message); + } + } + + [Fact] + public void ThrowsWhenHeadersExceedTotalSizeLimit() + { + var trace = new KestrelTrace(new TestKestrelTrace()); + var ltp = new LoggingThreadPool(trace); + using (var pool = new MemoryPool()) + using (var socketInput = new SocketInput(pool, ltp)) + { + const string headerLine = "Header: value\r\n"; + + var options = new KestrelServerOptions(); + options.Limits.MaxRequestHeadersTotalSize = headerLine.Length - 1; + + var connectionContext = new ConnectionContext() + { + DateHeaderValueManager = new DateHeaderValueManager(), + ServerAddress = ServerAddress.FromUrl("http://localhost:5000"), + ServerOptions = options, + Log = trace + }; + + var frame = new Frame(application: null, context: connectionContext); + frame.Reset(); + frame.InitializeHeaders(); + + var headerArray = Encoding.ASCII.GetBytes($"{headerLine}\r\n"); + socketInput.IncomingData(headerArray, 0, headerArray.Length); + + var exception = Assert.Throws(() => frame.TakeMessageHeaders(socketInput, (FrameRequestHeaders)frame.RequestHeaders)); + Assert.Equal("Request headers too long.", exception.Message); + } + } + + [Fact] + public void ThrowsWhenHeadersExceedCountLimit() + { + var trace = new KestrelTrace(new TestKestrelTrace()); + var ltp = new LoggingThreadPool(trace); + using (var pool = new MemoryPool()) + using (var socketInput = new SocketInput(pool, ltp)) + { + const string headerLines = "Header-1: value1\r\nHeader-2: value2\r\n"; + + var options = new KestrelServerOptions(); + options.Limits.MaxRequestHeaderCount = 1; + + var connectionContext = new ConnectionContext() + { + DateHeaderValueManager = new DateHeaderValueManager(), + ServerAddress = ServerAddress.FromUrl("http://localhost:5000"), + ServerOptions = options, + Log = trace + }; + + var frame = new Frame(application: null, context: connectionContext); + frame.Reset(); + frame.InitializeHeaders(); + + var headerArray = Encoding.ASCII.GetBytes($"{headerLines}\r\n"); + socketInput.IncomingData(headerArray, 0, headerArray.Length); + + var exception = Assert.Throws(() => frame.TakeMessageHeaders(socketInput, (FrameRequestHeaders)frame.RequestHeaders)); + Assert.Equal("Request contains too many headers.", exception.Message); } } @@ -358,9 +482,11 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var connectionContext = new ConnectionContext() { DateHeaderValueManager = new DateHeaderValueManager(), - ServerAddress = ServerAddress.FromUrl("http://localhost:5000") + ServerAddress = ServerAddress.FromUrl("http://localhost:5000"), + ServerOptions = new KestrelServerOptions(), }; var frame = new Frame(application: null, context: connectionContext); + frame.Reset(); frame.InitializeHeaders(); var headerArray = Encoding.ASCII.GetBytes(rawHeaders); @@ -384,7 +510,8 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var connectionContext = new ConnectionContext() { DateHeaderValueManager = new DateHeaderValueManager(), - ServerAddress = ServerAddress.FromUrl("http://localhost:5000") + ServerAddress = ServerAddress.FromUrl("http://localhost:5000"), + ServerOptions = new KestrelServerOptions(), }; var frame = new Frame(application: null, context: connectionContext); frame.Scheme = "https"; @@ -396,6 +523,50 @@ namespace Microsoft.AspNetCore.Server.KestrelTests Assert.Equal("http", ((IFeatureCollection)frame).Get().Scheme); } + [Fact] + public void ResetResetsHeaderLimits() + { + var trace = new KestrelTrace(new TestKestrelTrace()); + var ltp = new LoggingThreadPool(trace); + using (var pool = new MemoryPool()) + using (var socketInput = new SocketInput(pool, ltp)) + { + const string headerLine1 = "Header-1: value1\r\n"; + const string headerLine2 = "Header-2: value2\r\n"; + + var options = new KestrelServerOptions(); + options.Limits.MaxRequestHeadersTotalSize = headerLine1.Length; + options.Limits.MaxRequestHeaderCount = 1; + + var connectionContext = new ConnectionContext() + { + DateHeaderValueManager = new DateHeaderValueManager(), + ServerAddress = ServerAddress.FromUrl("http://localhost:5000"), + ServerOptions = options + }; + + var frame = new Frame(application: null, context: connectionContext); + frame.Reset(); + frame.InitializeHeaders(); + + var headerArray1 = Encoding.ASCII.GetBytes($"{headerLine1}\r\n"); + socketInput.IncomingData(headerArray1, 0, headerArray1.Length); + + Assert.True(frame.TakeMessageHeaders(socketInput, (FrameRequestHeaders)frame.RequestHeaders)); + Assert.Equal(1, frame.RequestHeaders.Count); + Assert.Equal("value1", frame.RequestHeaders["Header-1"]); + + frame.Reset(); + + var headerArray2 = Encoding.ASCII.GetBytes($"{headerLine2}\r\n"); + socketInput.IncomingData(headerArray2, 0, headerArray1.Length); + + Assert.True(frame.TakeMessageHeaders(socketInput, (FrameRequestHeaders)frame.RequestHeaders)); + Assert.Equal(1, frame.RequestHeaders.Count); + Assert.Equal("value2", frame.RequestHeaders["Header-2"]); + } + } + [Fact] public void ThrowsWhenStatusCodeIsSetAfterResponseStarted() { diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerLimitsTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerLimitsTests.cs index 15a216130a..111f97193c 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerLimitsTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerLimitsTests.cs @@ -63,5 +63,61 @@ namespace Microsoft.AspNetCore.Server.KestrelTests o.MaxRequestLineSize = value; Assert.Equal(value, o.MaxRequestLineSize); } + + [Fact] + public void MaxRequestHeaderTotalSizeDefault() + { + Assert.Equal(32 * 1024, (new KestrelServerLimits()).MaxRequestHeadersTotalSize); + } + + [Theory] + [InlineData(int.MinValue)] + [InlineData(-1)] + [InlineData(0)] + public void MaxRequestHeaderTotalSizeInvalid(int value) + { + Assert.Throws(() => + { + (new KestrelServerLimits()).MaxRequestHeadersTotalSize = value; + }); + } + + [Theory] + [InlineData(1)] + [InlineData(int.MaxValue)] + public void MaxRequestHeaderTotalSizeValid(int value) + { + var o = new KestrelServerLimits(); + o.MaxRequestHeadersTotalSize = value; + Assert.Equal(value, o.MaxRequestHeadersTotalSize); + } + + [Fact] + public void MaxRequestHeadersDefault() + { + Assert.Equal(100, (new KestrelServerLimits()).MaxRequestHeaderCount); + } + + [Theory] + [InlineData(int.MinValue)] + [InlineData(-1)] + [InlineData(0)] + public void MaxRequestHeadersInvalid(int value) + { + Assert.Throws(() => + { + (new KestrelServerLimits()).MaxRequestHeaderCount = value; + }); + } + + [Theory] + [InlineData(1)] + [InlineData(int.MaxValue)] + public void MaxRequestHeadersValid(int value) + { + var o = new KestrelServerLimits(); + o.MaxRequestHeaderCount = value; + Assert.Equal(value, o.MaxRequestHeaderCount); + } } } From 56d09500a6bae662704b19013a17b7a86f861b65 Mon Sep 17 00:00:00 2001 From: Pranav K Date: Tue, 9 Aug 2016 15:04:31 -0700 Subject: [PATCH 0852/1662] Switching to dotnet.myget.org feed --- NuGet.config | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NuGet.config b/NuGet.config index 03704957e8..826a1f9035 100644 --- a/NuGet.config +++ b/NuGet.config @@ -1,7 +1,7 @@  - + \ No newline at end of file From 5181e4196ca5525f86a897242b681a8d26e9721c Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Mon, 8 Aug 2016 15:21:19 -0700 Subject: [PATCH 0853/1662] Trace call to _uv_unsafe_async_send in MockLibuv. --- .../TestHelpers/MockLibuv.cs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockLibuv.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockLibuv.cs index 254ce726b2..64e4470649 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockLibuv.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockLibuv.cs @@ -1,3 +1,6 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + using System; using System.Threading; using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; @@ -12,9 +15,13 @@ namespace Microsoft.AspNetCore.Server.KestrelTests.TestHelpers private bool _stopLoop; private readonly ManualResetEventSlim _loopWh = new ManualResetEventSlim(); + private readonly string _stackTrace; + unsafe public MockLibuv() : base(onlyForTesting: true) { + _stackTrace = Environment.StackTrace; + OnWrite = (socket, buffers, triggerCompleted) => { triggerCompleted(0); @@ -76,6 +83,10 @@ namespace Microsoft.AspNetCore.Server.KestrelTests.TestHelpers _uv_strerror = errno => IntPtr.Zero; _uv_read_start = UvReadStart; _uv_read_stop = handle => 0; + _uv_unsafe_async_send = handle => + { + throw new Exception($"Why is this getting called?{Environment.NewLine}{_stackTrace}"); + }; } public Func, int> OnWrite { get; set; } From 08a91f17bfd593fcaaac486846b5bdb1da06e86c Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Wed, 10 Aug 2016 11:09:24 -0700 Subject: [PATCH 0854/1662] Call OnStarting and OnCompleted callbacks in LIFO order (#1042). --- .../Internal/Http/Frame.cs | 17 ++-- .../EngineTests.cs | 98 ++++++++++++++++++- 2 files changed, 103 insertions(+), 12 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs index f6415b2bb1..3f1c805dcf 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs @@ -47,9 +47,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http protected bool _requestRejected; private Streams _frameStreams; - protected List, object>> _onStarting; - - protected List, object>> _onCompleted; + protected Stack, object>> _onStarting; + protected Stack, object>> _onCompleted; private Task _requestProcessingTask; protected volatile bool _requestProcessingStopping; // volatile, see: https://msdn.microsoft.com/en-us/library/x13ttww7.aspx @@ -395,9 +394,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if (_onStarting == null) { - _onStarting = new List, object>>(); + _onStarting = new Stack, object>>(); } - _onStarting.Add(new KeyValuePair, object>(callback, state)); + _onStarting.Push(new KeyValuePair, object>(callback, state)); } } @@ -407,15 +406,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { if (_onCompleted == null) { - _onCompleted = new List, object>>(); + _onCompleted = new Stack, object>>(); } - _onCompleted.Add(new KeyValuePair, object>(callback, state)); + _onCompleted.Push(new KeyValuePair, object>(callback, state)); } } protected async Task FireOnStarting() { - List, object>> onStarting = null; + Stack, object>> onStarting = null; lock (_onStartingSync) { onStarting = _onStarting; @@ -439,7 +438,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http protected async Task FireOnCompleted() { - List, object>> onCompleted = null; + Stack, object>> onCompleted = null; lock (_onCompletedSync) { onCompleted = _onCompleted; diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs index 71e04123e5..81b6b96b8b 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Collections.Generic; using System.IO; using System.Linq; using System.Net.Sockets; @@ -833,9 +834,12 @@ namespace Microsoft.AspNetCore.Server.KestrelTests "", ""); - Assert.Equal(2, onStartingCallCount1); - // The second OnStarting callback should not be called since the first failed. - Assert.Equal(0, onStartingCallCount2); + Assert.Equal(2, onStartingCallCount2); + + // The first registered OnStarting callback should not be called, + // since they are called LIFO and the other one failed. + Assert.Equal(0, onStartingCallCount1); + Assert.Equal(2, testLogger.ApplicationErrorsLogged); } } @@ -1199,5 +1203,93 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } } } + + [Theory] + [MemberData(nameof(ConnectionFilterData))] + public async Task OnStartingCallbacksAreCalledInLastInFirstOutOrder(TestServiceContext testContext) + { + const string response = "hello, world"; + + var callOrder = new Stack(); + + using (var server = new TestServer(async context => + { + context.Response.OnStarting(_ => + { + callOrder.Push(1); + return TaskUtilities.CompletedTask; + }, null); + context.Response.OnStarting(_ => + { + callOrder.Push(2); + return TaskUtilities.CompletedTask; + }, null); + + context.Response.ContentLength = response.Length; + await context.Response.WriteAsync(response); + }, testContext)) + { + using (var connection = server.CreateConnection()) + { + await connection.SendEnd( + "GET / HTTP/1.1", + "", + ""); + await connection.ReceiveEnd( + "HTTP/1.1 200 OK", + $"Date: {testContext.DateHeaderValue}", + $"Content-Length: {response.Length}", + "", + "hello, world"); + + Assert.Equal(1, callOrder.Pop()); + Assert.Equal(2, callOrder.Pop()); + } + } + } + + [Theory] + [MemberData(nameof(ConnectionFilterData))] + public async Task OnCompletedCallbacksAreCalledInLastInFirstOutOrder(TestServiceContext testContext) + { + const string response = "hello, world"; + + var callOrder = new Stack(); + + using (var server = new TestServer(async context => + { + context.Response.OnCompleted(_ => + { + callOrder.Push(1); + return TaskUtilities.CompletedTask; + }, null); + context.Response.OnCompleted(_ => + { + callOrder.Push(2); + return TaskUtilities.CompletedTask; + }, null); + + context.Response.ContentLength = response.Length; + await context.Response.WriteAsync(response); + }, testContext)) + { + using (var connection = server.CreateConnection()) + { + await connection.SendEnd( + "GET / HTTP/1.1", + "", + ""); + await connection.ReceiveEnd( + "HTTP/1.1 200 OK", + $"Date: {testContext.DateHeaderValue}", + $"Content-Length: {response.Length}", + "", + "hello, world"); + + Assert.Equal(1, callOrder.Pop()); + Assert.Equal(2, callOrder.Pop()); + } + } + } } } From 8f4cc3003b55ed8e9249aae1dd7829339d5198a5 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Mon, 15 Aug 2016 10:58:32 -0700 Subject: [PATCH 0855/1662] Improve SocketOutputTests - This should increase reliability/determinism by removing timeouts. --- .../SocketOutputTests.cs | 227 ++++++++---------- .../TestHelpers/MockLibuv.cs | 30 ++- .../TestHelpers/SynchronousThreadPool.cs | 32 +++ 3 files changed, 163 insertions(+), 126 deletions(-) create mode 100644 test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/SynchronousThreadPool.cs diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/SocketOutputTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/SocketOutputTests.cs index c6cd758d1d..e180dc77a3 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/SocketOutputTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/SocketOutputTests.cs @@ -3,13 +3,11 @@ using System; using System.Collections.Concurrent; -using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Internal; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; using Microsoft.AspNetCore.Server.KestrelTests.TestHelpers; using Xunit; @@ -18,7 +16,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests public class SocketOutputTests { [Fact] - public void CanWrite1MB() + public async Task CanWrite1MB() { // This test was added because when initially implementing write-behind buffering in // SocketOutput, the write callback would never be invoked for writes larger than @@ -33,25 +31,19 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var kestrelThread = kestrelEngine.Threads[0]; var socket = new MockSocket(mockLibuv, kestrelThread.Loop.ThreadId, new TestKestrelTrace()); var trace = new KestrelTrace(new TestKestrelTrace()); - var ltp = new LoggingThreadPool(trace); + var ltp = new SynchronousThreadPool(); var socketOutput = new SocketOutput(kestrelThread, socket, new MockConnection(), "0", trace, ltp); // I doubt _maxBytesPreCompleted will ever be over a MB. If it is, we should change this test. var bufferSize = 1048576; var buffer = new ArraySegment(new byte[bufferSize], 0, bufferSize); - var completedWh = new ManualResetEventSlim(); // Act - socketOutput.WriteAsync(buffer, default(CancellationToken)).ContinueWith( - (t) => - { - Assert.Null(t.Exception); - completedWh.Set(); - } - ); + var writeTask = socketOutput.WriteAsync(buffer, default(CancellationToken)); + await mockLibuv.OnPostTask; // Assert - Assert.True(completedWh.Wait(1000)); + Assert.Equal(TaskStatus.RanToCompletion, writeTask.Status); // Cleanup var cleanupTask = socketOutput.WriteAsync( @@ -60,7 +52,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } [Fact] - public void WritesDontCompleteImmediatelyWhenTooManyBytesAreAlreadyPreCompleted() + public async Task WritesDontCompleteImmediatelyWhenTooManyBytesAreAlreadyBuffered() { // This should match _maxBytesPreCompleted in SocketOutput var maxBytesPreCompleted = 65536; @@ -83,45 +75,43 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var kestrelThread = kestrelEngine.Threads[0]; var socket = new MockSocket(mockLibuv, kestrelThread.Loop.ThreadId, new TestKestrelTrace()); var trace = new KestrelTrace(new TestKestrelTrace()); - var ltp = new LoggingThreadPool(trace); + var ltp = new SynchronousThreadPool(); var mockConnection = new MockConnection(); var socketOutput = new SocketOutput(kestrelThread, socket, mockConnection, "0", trace, ltp); var bufferSize = maxBytesPreCompleted; var buffer = new ArraySegment(new byte[bufferSize], 0, bufferSize); - var completedWh = new ManualResetEventSlim(); - Action onCompleted = (Task t) => - { - Assert.Null(t.Exception); - completedWh.Set(); - }; // Act - socketOutput.WriteAsync(buffer, default(CancellationToken)).ContinueWith(onCompleted); + var writeTask1 = socketOutput.WriteAsync(buffer, default(CancellationToken)); + // Assert // The first write should pre-complete since it is <= _maxBytesPreCompleted. - Assert.True(completedWh.Wait(1000)); - // Arrange - completedWh.Reset(); + Assert.Equal(TaskStatus.RanToCompletion, writeTask1.Status); + // Act - socketOutput.WriteAsync(buffer, default(CancellationToken)).ContinueWith(onCompleted); + var writeTask2 = socketOutput.WriteAsync(buffer, default(CancellationToken)); + await mockLibuv.OnPostTask; + // Assert // Too many bytes are already pre-completed for the second write to pre-complete. - Assert.False(completedWh.Wait(1000)); + Assert.False(writeTask2.IsCompleted); + // Act Action triggerNextCompleted; Assert.True(completeQueue.TryDequeue(out triggerNextCompleted)); triggerNextCompleted(0); + // Assert // Finishing the first write should allow the second write to pre-complete. - Assert.True(completedWh.Wait(1000)); + Assert.Equal(TaskStatus.RanToCompletion, writeTask2.Status); // Cleanup var cleanupTask = socketOutput.WriteAsync( default(ArraySegment), default(CancellationToken), socketDisconnect: true); // Wait for all writes to complete so the completeQueue isn't modified during enumeration. - Assert.True(mockConnection.SocketClosed.Wait(1000)); + await mockLibuv.OnPostTask; foreach (var triggerCompleted in completeQueue) { @@ -131,12 +121,12 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } [Fact] - public void WritesDontCompleteImmediatelyWhenTooManyBytesIncludingNonImmediateAreAlreadyPreCompleted() + public async Task WritesDontCompleteImmediatelyWhenTooManyBytesIncludingNonImmediateAreAlreadyBuffered() { // This should match _maxBytesPreCompleted in SocketOutput var maxBytesPreCompleted = 65536; var completeQueue = new ConcurrentQueue>(); - var writeRequestedWh = new ManualResetEventSlim(); + var writeRequested = false; // Arrange var mockLibuv = new MockLibuv @@ -144,7 +134,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests OnWrite = (socket, buffers, triggerCompleted) => { completeQueue.Enqueue(triggerCompleted); - writeRequestedWh.Set(); + writeRequested = true; return 0; } }; @@ -156,7 +146,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var kestrelThread = kestrelEngine.Threads[0]; var socket = new MockSocket(mockLibuv, kestrelThread.Loop.ThreadId, new TestKestrelTrace()); var trace = new KestrelTrace(new TestKestrelTrace()); - var ltp = new LoggingThreadPool(trace); + var ltp = new SynchronousThreadPool(); var mockConnection = new MockConnection(); var socketOutput = new SocketOutput(kestrelThread, socket, mockConnection, "0", trace, ltp); @@ -166,11 +156,13 @@ namespace Microsoft.AspNetCore.Server.KestrelTests // Act var writeTask1 = socketOutput.WriteAsync(halfWriteBehindBuffer, default(CancellationToken)); + // Assert // The first write should pre-complete since it is <= _maxBytesPreCompleted. Assert.Equal(TaskStatus.RanToCompletion, writeTask1.Status); - Assert.True(writeRequestedWh.Wait(1000)); - writeRequestedWh.Reset(); + await mockLibuv.OnPostTask; + Assert.True(writeRequested); + writeRequested = false; // Add more bytes to the write-behind buffer to prevent the next write from var iter = socketOutput.ProducingStart(); @@ -179,9 +171,11 @@ namespace Microsoft.AspNetCore.Server.KestrelTests // Act var writeTask2 = socketOutput.WriteAsync(halfWriteBehindBuffer, default(CancellationToken)); + // Assert // Too many bytes are already pre-completed for the fourth write to pre-complete. - Assert.True(writeRequestedWh.Wait(1000)); + await mockLibuv.OnPostTask; + Assert.True(writeRequested); Assert.False(writeTask2.IsCompleted); // 2 calls have been made to uv_write @@ -194,14 +188,14 @@ namespace Microsoft.AspNetCore.Server.KestrelTests // Assert // Finishing the first write should allow the second write to pre-complete. - Assert.True(writeTask2.Wait(1000)); + Assert.Equal(TaskStatus.RanToCompletion, writeTask2.Status); // Cleanup var cleanupTask = socketOutput.WriteAsync( default(ArraySegment), default(CancellationToken), socketDisconnect: true); // Wait for all writes to complete so the completeQueue isn't modified during enumeration. - Assert.True(mockConnection.SocketClosed.Wait(1000)); + await mockLibuv.OnPostTask; foreach (var triggerCompleted in completeQueue) { @@ -234,7 +228,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var kestrelThread = kestrelEngine.Threads[0]; var socket = new MockSocket(mockLibuv, kestrelThread.Loop.ThreadId, new TestKestrelTrace()); var trace = new KestrelTrace(new TestKestrelTrace()); - var ltp = new LoggingThreadPool(trace); + var ltp = new SynchronousThreadPool(); using (var mockConnection = new MockConnection()) { @@ -261,7 +255,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var task3Success = socketOutput.WriteAsync(fullBuffer, cancellationToken: default(CancellationToken)); // Give time for tasks to percolate - await Task.Delay(1000); + await mockLibuv.OnPostTask; // Second task is not completed Assert.False(task2Throw.IsCompleted); @@ -316,7 +310,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests triggerNextCompleted(0); // Wait for all writes to complete so the completeQueue isn't modified during enumeration. - Assert.True(mockConnection.SocketClosed.Wait(1000)); + await mockLibuv.OnPostTask; foreach (var triggerCompleted in completeQueue) { @@ -350,7 +344,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var kestrelThread = kestrelEngine.Threads[0]; var socket = new MockSocket(mockLibuv, kestrelThread.Loop.ThreadId, new TestKestrelTrace()); var trace = new KestrelTrace(new TestKestrelTrace()); - var ltp = new LoggingThreadPool(trace); + var ltp = new SynchronousThreadPool(); using (var mockConnection = new MockConnection()) { @@ -376,7 +370,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var task3Canceled = socketOutput.WriteAsync(fullBuffer, cancellationToken: abortedSource.Token); // Give time for tasks to percolate - await Task.Delay(1000); + await mockLibuv.OnPostTask; // Second task is not completed Assert.False(task2Success.IsCompleted); @@ -405,7 +399,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests default(ArraySegment), default(CancellationToken), socketDisconnect: true); // Wait for all writes to complete so the completeQueue isn't modified during enumeration. - Assert.True(mockConnection.SocketClosed.Wait(1000)); + await mockLibuv.OnPostTask; foreach (var triggerCompleted in completeQueue) { @@ -416,12 +410,12 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } [Fact] - public void WritesDontGetCompletedTooQuickly() + public async Task WritesDontGetCompletedTooQuickly() { // This should match _maxBytesPreCompleted in SocketOutput var maxBytesPreCompleted = 65536; var completeQueue = new ConcurrentQueue>(); - var onWriteWh = new ManualResetEventSlim(); + var writeCalled = false; // Arrange var mockLibuv = new MockLibuv @@ -429,7 +423,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests OnWrite = (socket, buffers, triggerCompleted) => { completeQueue.Enqueue(triggerCompleted); - onWriteWh.Set(); + writeCalled = true; return 0; } @@ -442,42 +436,30 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var kestrelThread = kestrelEngine.Threads[0]; var socket = new MockSocket(mockLibuv, kestrelThread.Loop.ThreadId, new TestKestrelTrace()); var trace = new KestrelTrace(new TestKestrelTrace()); - var ltp = new LoggingThreadPool(trace); + var ltp = new SynchronousThreadPool(); var mockConnection = new MockConnection(); var socketOutput = new SocketOutput(kestrelThread, socket, mockConnection, "0", trace, ltp); var bufferSize = maxBytesPreCompleted; var buffer = new ArraySegment(new byte[bufferSize], 0, bufferSize); - var completedWh = new ManualResetEventSlim(); - Action onCompleted = (Task t) => - { - Assert.Null(t.Exception); - completedWh.Set(); - }; - - var completedWh2 = new ManualResetEventSlim(); - Action onCompleted2 = (Task t) => - { - Assert.Null(t.Exception); - completedWh2.Set(); - }; - // Act (Pre-complete the maximum number of bytes in preparation for the rest of the test) - socketOutput.WriteAsync(buffer, default(CancellationToken)).ContinueWith(onCompleted); + var writeTask1 = socketOutput.WriteAsync(buffer, default(CancellationToken)); + // Assert // The first write should pre-complete since it is <= _maxBytesPreCompleted. - Assert.True(completedWh.Wait(1000)); - Assert.True(onWriteWh.Wait(1000)); + await mockLibuv.OnPostTask; + Assert.Equal(TaskStatus.RanToCompletion, writeTask1.Status); + Assert.True(writeCalled); // Arrange - completedWh.Reset(); - onWriteWh.Reset(); + writeCalled = false; // Act - socketOutput.WriteAsync(buffer, default(CancellationToken)).ContinueWith(onCompleted); - socketOutput.WriteAsync(buffer, default(CancellationToken)).ContinueWith(onCompleted2); + var writeTask2 = socketOutput.WriteAsync(buffer, default(CancellationToken)); + var writeTask3 = socketOutput.WriteAsync(buffer, default(CancellationToken)); - Assert.True(onWriteWh.Wait(1000)); + await mockLibuv.OnPostTask; + Assert.True(writeCalled); Action triggerNextCompleted; Assert.True(completeQueue.TryDequeue(out triggerNextCompleted)); triggerNextCompleted(0); @@ -485,23 +467,23 @@ namespace Microsoft.AspNetCore.Server.KestrelTests // Assert // Too many bytes are already pre-completed for the third but not the second write to pre-complete. // https://github.com/aspnet/KestrelHttpServer/issues/356 - Assert.True(completedWh.Wait(1000)); - Assert.False(completedWh2.Wait(1000)); + Assert.Equal(TaskStatus.RanToCompletion, writeTask2.Status); + Assert.False(writeTask3.IsCompleted); // Act Assert.True(completeQueue.TryDequeue(out triggerNextCompleted)); triggerNextCompleted(0); // Assert - // Finishing the first write should allow the second write to pre-complete. - Assert.True(completedWh2.Wait(1000)); + // Finishing the first write should allow the third write to pre-complete. + Assert.Equal(TaskStatus.RanToCompletion, writeTask3.Status); // Cleanup var cleanupTask = ((SocketOutput)socketOutput).WriteAsync( default(ArraySegment), default(CancellationToken), socketDisconnect: true); // Wait for all writes to complete so the completeQueue isn't modified during enumeration. - Assert.True(mockConnection.SocketClosed.Wait(1000)); + await mockLibuv.OnPostTask; foreach (var triggerCompleted in completeQueue) { @@ -511,17 +493,15 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } [Fact] - public void ProducingStartAndProducingCompleteCanBeUsedDirectly() + public async Task ProducingStartAndProducingCompleteCanBeUsedDirectly() { int nBuffers = 0; - var nBufferWh = new ManualResetEventSlim(); var mockLibuv = new MockLibuv { OnWrite = (socket, buffers, triggerCompleted) => { nBuffers = buffers; - nBufferWh.Set(); triggerCompleted(0); return 0; } @@ -534,7 +514,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var kestrelThread = kestrelEngine.Threads[0]; var socket = new MockSocket(mockLibuv, kestrelThread.Loop.ThreadId, new TestKestrelTrace()); var trace = new KestrelTrace(new TestKestrelTrace()); - var ltp = new LoggingThreadPool(trace); + var ltp = new SynchronousThreadPool(); var socketOutput = new SocketOutput(kestrelThread, socket, new MockConnection(), "0", trace, ltp); // block 1 @@ -551,9 +531,9 @@ namespace Microsoft.AspNetCore.Server.KestrelTests socketOutput.ProducingComplete(end); // A call to Write is required to ensure a write is scheduled - socketOutput.WriteAsync(default(ArraySegment), default(CancellationToken)); + var ignore = socketOutput.WriteAsync(default(ArraySegment), default(CancellationToken)); - Assert.True(nBufferWh.Wait(1000)); + await mockLibuv.OnPostTask; Assert.Equal(2, nBuffers); // Cleanup @@ -563,16 +543,16 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } [Fact] - public void OnlyAllowsUpToThreeConcurrentWrites() + public async Task OnlyAllowsUpToThreeConcurrentWrites() { - var writeWh = new ManualResetEventSlim(); + var writeCalled = false; var completeQueue = new ConcurrentQueue>(); var mockLibuv = new MockLibuv { OnWrite = (socket, buffers, triggerCompleted) => { - writeWh.Set(); + writeCalled = true; completeQueue.Enqueue(triggerCompleted); return 0; } @@ -585,43 +565,44 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var kestrelThread = kestrelEngine.Threads[0]; var socket = new MockSocket(mockLibuv, kestrelThread.Loop.ThreadId, new TestKestrelTrace()); var trace = new KestrelTrace(new TestKestrelTrace()); - var ltp = new LoggingThreadPool(trace); + var ltp = new SynchronousThreadPool(); var mockConnection = new MockConnection(); var socketOutput = new SocketOutput(kestrelThread, socket, mockConnection, "0", trace, ltp); var buffer = new ArraySegment(new byte[1]); // First three writes trigger uv_write - socketOutput.WriteAsync(buffer, CancellationToken.None); - Assert.True(writeWh.Wait(1000)); - writeWh.Reset(); - socketOutput.WriteAsync(buffer, CancellationToken.None); - Assert.True(writeWh.Wait(1000)); - writeWh.Reset(); - socketOutput.WriteAsync(buffer, CancellationToken.None); - Assert.True(writeWh.Wait(1000)); - writeWh.Reset(); + var ignore = socketOutput.WriteAsync(buffer, CancellationToken.None); + await mockLibuv.OnPostTask; + Assert.True(writeCalled); + writeCalled = false; + ignore = socketOutput.WriteAsync(buffer, CancellationToken.None); + await mockLibuv.OnPostTask; + Assert.True(writeCalled); + writeCalled = false; + ignore = socketOutput.WriteAsync(buffer, CancellationToken.None); + await mockLibuv.OnPostTask; + Assert.True(writeCalled); + writeCalled = false; // The fourth write won't trigger uv_write since the first three haven't completed - socketOutput.WriteAsync(buffer, CancellationToken.None); - Assert.False(writeWh.Wait(1000)); + ignore = socketOutput.WriteAsync(buffer, CancellationToken.None); + await mockLibuv.OnPostTask; + Assert.False(writeCalled); // Complete 1st write allowing uv_write to be triggered again Action triggerNextCompleted; Assert.True(completeQueue.TryDequeue(out triggerNextCompleted)); triggerNextCompleted(0); - Assert.True(writeWh.Wait(1000)); + await mockLibuv.OnPostTask; + Assert.True(writeCalled); // Cleanup var cleanupTask = socketOutput.WriteAsync( default(ArraySegment), default(CancellationToken), socketDisconnect: true); - // Allow for the socketDisconnect command to get posted to the libuv thread. - // Right now, the three pending writes are holding it up. - Assert.True(completeQueue.TryDequeue(out triggerNextCompleted)); - triggerNextCompleted(0); // Wait for all writes to complete so the completeQueue isn't modified during enumeration. - Assert.True(mockConnection.SocketClosed.Wait(1000)); + await mockLibuv.OnPostTask; foreach (var triggerCompleted in completeQueue) { @@ -631,9 +612,9 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } [Fact] - public void WritesAreAggregated() + public async Task WritesAreAggregated() { - var writeWh = new ManualResetEventSlim(); + var writeCalled = false; var writeCount = 0; var mockLibuv = new MockLibuv @@ -642,7 +623,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { writeCount++; triggerCompleted(0); - writeWh.Set(); + writeCalled = true; return 0; } }; @@ -654,32 +635,32 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var kestrelThread = kestrelEngine.Threads[0]; var socket = new MockSocket(mockLibuv, kestrelThread.Loop.ThreadId, new TestKestrelTrace()); var trace = new KestrelTrace(new TestKestrelTrace()); - var ltp = new LoggingThreadPool(trace); + var ltp = new SynchronousThreadPool(); var socketOutput = new SocketOutput(kestrelThread, socket, new MockConnection(), "0", trace, ltp); - var blockThreadWh = new ManualResetEventSlim(); - kestrelThread.Post(_ => - { - blockThreadWh.Wait(); - }, state: null); + mockLibuv.KestrelThreadBlocker.Reset(); var buffer = new ArraySegment(new byte[1]); // Two calls to WriteAsync trigger uv_write once if both calls // are made before write is scheduled - socketOutput.WriteAsync(buffer, CancellationToken.None); - socketOutput.WriteAsync(buffer, CancellationToken.None); + var ignore = socketOutput.WriteAsync(buffer, CancellationToken.None); + ignore = socketOutput.WriteAsync(buffer, CancellationToken.None); - blockThreadWh.Set(); + mockLibuv.KestrelThreadBlocker.Set(); - Assert.True(writeWh.Wait(1000)); - writeWh.Reset(); + await mockLibuv.OnPostTask; + + Assert.True(writeCalled); + writeCalled = false; // Write isn't called twice after the thread is unblocked - Assert.False(writeWh.Wait(1000)); + await mockLibuv.OnPostTask; + Assert.False(writeCalled); + // One call to ScheduleWrite + Assert.Equal(1, mockLibuv.PostCount); + // One call to uv_write Assert.Equal(1, writeCount); - // One call to ScheduleWrite + One call to Post to block the thread - Assert.Equal(2, mockLibuv.PostCount); // Cleanup var cleanupTask = socketOutput.WriteAsync( @@ -688,7 +669,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } [Fact] - public void ProducingStartAndProducingCompleteCanBeCalledAfterConnectionClose() + public async Task ProducingStartAndProducingCompleteCanBeCalledAfterConnectionClose() { var mockLibuv = new MockLibuv(); @@ -699,7 +680,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var kestrelThread = kestrelEngine.Threads[0]; var socket = new MockSocket(mockLibuv, kestrelThread.Loop.ThreadId, new TestKestrelTrace()); var trace = new KestrelTrace(new TestKestrelTrace()); - var ltp = new LoggingThreadPool(trace); + var ltp = new SynchronousThreadPool(); var connection = new MockConnection(); var socketOutput = new SocketOutput(kestrelThread, socket, connection, "0", trace, ltp); @@ -707,7 +688,9 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var cleanupTask = socketOutput.WriteAsync( default(ArraySegment), default(CancellationToken), socketDisconnect: true); - Assert.True(connection.SocketClosed.Wait(1000)); + await mockLibuv.OnPostTask; + + Assert.Equal(TaskStatus.RanToCompletion, connection.SocketClosed.Status); var start = socketOutput.ProducingStart(); diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockLibuv.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockLibuv.cs index 64e4470649..a832fbdf9f 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockLibuv.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockLibuv.cs @@ -3,6 +3,7 @@ using System; using System.Threading; +using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; namespace Microsoft.AspNetCore.Server.KestrelTests.TestHelpers @@ -11,6 +12,8 @@ namespace Microsoft.AspNetCore.Server.KestrelTests.TestHelpers { private UvAsyncHandle _postHandle; private uv_async_cb _onPost; + private TaskCompletionSource _onPostTcs; + private object _postLock = new object(); private bool _stopLoop; private readonly ManualResetEventSlim _loopWh = new ManualResetEventSlim(); @@ -32,8 +35,17 @@ namespace Microsoft.AspNetCore.Server.KestrelTests.TestHelpers _uv_async_send = postHandle => { - PostCount++; - _loopWh.Set(); + lock (_postLock) + { + if (_onPostTcs == null || _onPostTcs.Task.IsCompleted) + { + _onPostTcs = new TaskCompletionSource(); + } + + PostCount++; + + _loopWh.Set(); + } return 0; }; @@ -51,8 +63,14 @@ namespace Microsoft.AspNetCore.Server.KestrelTests.TestHelpers while (!_stopLoop) { _loopWh.Wait(); - _loopWh.Reset(); - _onPost(_postHandle.InternalGetHandle()); + KestrelThreadBlocker.Wait(); + + lock (_postLock) + { + _loopWh.Reset(); + _onPost(_postHandle.InternalGetHandle()); + _onPostTcs.TrySetResult(null); + } } return 0; @@ -97,6 +115,10 @@ namespace Microsoft.AspNetCore.Server.KestrelTests.TestHelpers public int PostCount { get; set; } + public Task OnPostTask => _onPostTcs.Task; + + public ManualResetEventSlim KestrelThreadBlocker { get; } = new ManualResetEventSlim(true); + private int UvReadStart(UvStreamHandle handle, uv_alloc_cb allocCallback, uv_read_cb readCallback) { AllocCallback = allocCallback; diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/SynchronousThreadPool.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/SynchronousThreadPool.cs new file mode 100644 index 0000000000..ac7e2717e4 --- /dev/null +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/SynchronousThreadPool.cs @@ -0,0 +1,32 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; + +namespace Microsoft.AspNetCore.Server.KestrelTests.TestHelpers +{ + public class SynchronousThreadPool : IThreadPool + { + public void Complete(TaskCompletionSource tcs) + { + tcs.TrySetResult(null); + } + + public void Cancel(TaskCompletionSource tcs) + { + tcs.TrySetCanceled(); + } + + public void Error(TaskCompletionSource tcs, Exception ex) + { + tcs.TrySetException(ex); + } + + public void Run(Action action) + { + action(); + } + } +} From 5f4e60bf8df17ac45c01d55adf8e416646e96b37 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Tue, 9 Aug 2016 17:35:01 -0700 Subject: [PATCH 0856/1662] Always set "Connection: close" header for non keep-alive responses --- .../Internal/Http/Frame.cs | 2 +- .../ChunkedRequestTests.cs | 2 ++ .../ConnectionFilterTests.cs | 2 ++ .../DefaultHeaderTests.cs | 8 ++++++++ .../EngineTests.cs | 8 ++++++++ .../RequestTargetProcessingTests.cs | 6 +++--- 6 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs index 3f1c805dcf..f657864302 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs @@ -767,7 +767,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } } - if (!_keepAlive && !hasConnection && _httpVersion != Http.HttpVersion.Http10) + if (!_keepAlive && !hasConnection) { responseHeaders.SetRawConnection("close", _bytesConnectionClose); } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedRequestTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedRequestTests.cs index c6de0ab0e3..476cddae2c 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedRequestTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedRequestTests.cs @@ -75,6 +75,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests ""); await connection.ReceiveEnd( "HTTP/1.1 200 OK", + "Connection: close", $"Date: {testContext.DateHeaderValue}", "", "Hello World"); @@ -111,6 +112,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests "Hello World"); await connection.ReceiveEnd( "HTTP/1.1 200 OK", + "Connection: close", $"Date: {testContext.DateHeaderValue}", "Content-Length: 7", "", diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionFilterTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionFilterTests.cs index 2d32fd6c6e..965a427b97 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionFilterTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionFilterTests.cs @@ -44,6 +44,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests await connection.SendEnd(sendString); await connection.ReceiveEnd( "HTTP/1.1 200 OK", + "Connection: close", $"Date: {serviceContext.DateHeaderValue}", "", "Hello World!"); @@ -68,6 +69,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests "Hello World?"); await connection.ReceiveEnd( "HTTP/1.1 200 OK", + "Connection: close", $"Date: {serviceContext.DateHeaderValue}", "", "Hello World!"); diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/DefaultHeaderTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/DefaultHeaderTests.cs index 890f663d12..a8818d80fe 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/DefaultHeaderTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/DefaultHeaderTests.cs @@ -24,6 +24,8 @@ namespace Microsoft.AspNetCore.Server.KestrelTests using (var connection = server.CreateConnection()) { await connection.SendEnd( + "GET / HTTP/1.1", + "", "GET / HTTP/1.0", "", ""); @@ -31,6 +33,12 @@ namespace Microsoft.AspNetCore.Server.KestrelTests await connection.ReceiveEnd( "HTTP/1.1 200 OK", $"Date: {testContext.DateHeaderValue}", + "Content-Length: 0", + "Server: Kestrel", + "", + "HTTP/1.1 200 OK", + "Connection: close", + $"Date: {testContext.DateHeaderValue}", "Server: Kestrel", "", ""); diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs index 81b6b96b8b..59f713fe41 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs @@ -135,6 +135,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests "Hello World"); await connection.ReceiveEnd( "HTTP/1.1 200 OK", + "Connection: close", $"Date: {testContext.DateHeaderValue}", "", "Hello World"); @@ -259,6 +260,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests "Hello World"); await connection.ReceiveEnd( "HTTP/1.1 200 OK", + "Connection: close", $"Date: {testContext.DateHeaderValue}", "", "Hello World"); @@ -289,6 +291,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests "\r\n"); await connection.ReceiveEnd( "HTTP/1.1 200 OK", + "Connection: close", $"Date: {testContext.DateHeaderValue}", "Content-Length: 7", "", @@ -322,6 +325,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests "\r\n"); await connection.ReceiveEnd( "HTTP/1.1 200 OK", + "Connection: close", $"Date: {testContext.DateHeaderValue}", "", "Goodbye"); @@ -354,6 +358,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests "Hello World"); await connection.ReceiveEnd( "HTTP/1.1 200 OK", + "Connection: close", $"Date: {testContext.DateHeaderValue}", "Content-Length: 7", "", @@ -407,6 +412,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests "\r\n"); await connection.ReceiveEnd( "HTTP/1.1 200 OK", + "Connection: close", $"Date: {testContext.DateHeaderValue}", "\r\n"); } @@ -472,6 +478,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests ""); await connection.ReceiveEnd( "HTTP/1.1 200 OK", + "Connection: close", $"Date: {testContext.DateHeaderValue}", "", ""); @@ -1050,6 +1057,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests ""); await connection.ReceiveForcedEnd( "HTTP/1.1 200 OK", + "Connection: close", $"Date: {testContext.DateHeaderValue}", "Content-Length: 11", "", diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/RequestTargetProcessingTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/RequestTargetProcessingTests.cs index 6d6a82ce3b..5c1c25d373 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/RequestTargetProcessingTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/RequestTargetProcessingTests.cs @@ -27,7 +27,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests using (var connection = server.CreateConnection()) { await connection.SendEnd( - "GET /%41%CC%8A/A/../B/%41%CC%8A HTTP/1.0", + "GET /%41%CC%8A/A/../B/%41%CC%8A HTTP/1.1", "", ""); await connection.ReceiveEnd( @@ -71,7 +71,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests using (var connection = server.CreateConnection()) { await connection.SendEnd( - $"GET {requestTarget} HTTP/1.0", + $"GET {requestTarget} HTTP/1.1", "", ""); await connection.ReceiveEnd( @@ -115,7 +115,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests using (var connection = server.CreateConnection()) { await connection.SendEnd( - $"GET {requestTarget} HTTP/1.0", + $"GET {requestTarget} HTTP/1.1", "", ""); await connection.ReceiveEnd( From 16fbb94c4451453aa1eaefd83e56d86903378f5d Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Wed, 10 Aug 2016 16:58:17 -0700 Subject: [PATCH 0857/1662] Automatically chunk and set 0 Content-Length for non keep-alive responses --- .../Internal/Http/Frame.cs | 2 +- .../ChunkedResponseTests.cs | 62 +++++++++++++++++++ .../DefaultHeaderTests.cs | 1 + .../EngineTests.cs | 17 ++++- 4 files changed, 78 insertions(+), 4 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs index f657864302..aad34b77dd 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs @@ -733,7 +733,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } } - if (_keepAlive && !responseHeaders.HasTransferEncoding && !responseHeaders.HasContentLength) + if (!responseHeaders.HasTransferEncoding && !responseHeaders.HasContentLength) { if (appCompleted) { diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedResponseTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedResponseTests.cs index 1427cfc90a..1f970fa9cf 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedResponseTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedResponseTests.cs @@ -61,6 +61,68 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } } + [Theory] + [MemberData(nameof(ConnectionFilterData))] + public async Task ResponsesAreChunkedAutomaticallyForHttp11NonKeepAliveRequests(TestServiceContext testContext) + { + using (var server = new TestServer(async httpContext => + { + var response = httpContext.Response; + await response.Body.WriteAsync(Encoding.ASCII.GetBytes("Hello "), 0, 6); + await response.Body.WriteAsync(Encoding.ASCII.GetBytes("World!"), 0, 6); + }, testContext)) + { + using (var connection = server.CreateConnection()) + { + await connection.SendEnd( + "GET / HTTP/1.1", + "Connection: close", + "", + ""); + await connection.ReceiveEnd( + "HTTP/1.1 200 OK", + "Connection: close", + $"Date: {testContext.DateHeaderValue}", + "Transfer-Encoding: chunked", + "", + "6", + "Hello ", + "6", + "World!", + "0", + "", + ""); + } + } + } + + [Theory] + [MemberData(nameof(ConnectionFilterData))] + public async Task ResponsesAreNotChunkedAutomaticallyForHttp10Requests(TestServiceContext testContext) + { + using (var server = new TestServer(async httpContext => + { + var response = httpContext.Response; + await response.Body.WriteAsync(Encoding.ASCII.GetBytes("Hello "), 0, 6); + await response.Body.WriteAsync(Encoding.ASCII.GetBytes("World!"), 0, 6); + }, testContext)) + { + using (var connection = server.CreateConnection()) + { + await connection.SendEnd( + "GET / HTTP/1.0", + "", + ""); + await connection.ReceiveEnd( + "HTTP/1.1 200 OK", + "Connection: close", + $"Date: {testContext.DateHeaderValue}", + "", + "Hello World!"); + } + } + } + [Theory] [MemberData(nameof(ConnectionFilterData))] public async Task ZeroLengthWritesAreIgnored(TestServiceContext testContext) diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/DefaultHeaderTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/DefaultHeaderTests.cs index a8818d80fe..964345b48a 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/DefaultHeaderTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/DefaultHeaderTests.cs @@ -39,6 +39,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests "HTTP/1.1 200 OK", "Connection: close", $"Date: {testContext.DateHeaderValue}", + "Content-Length: 0", "Server: Kestrel", "", ""); diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs index 59f713fe41..80e59304f8 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs @@ -187,7 +187,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests IHeaderDictionary lastResponseHeaders = null; using (var server = new TestServer( - context => + async context => { if (context.Request.Body != lastStream) { @@ -204,7 +204,14 @@ namespace Microsoft.AspNetCore.Server.KestrelTests lastResponseHeaders = context.Response.Headers; responseHeadersCount++; } - return context.Request.Body.CopyToAsync(context.Response.Body); + + var ms = new MemoryStream(); + await context.Request.Body.CopyToAsync(ms); + var request = ms.ToArray(); + + context.Response.ContentLength = request.Length; + + await context.Response.Body.WriteAsync(request, 0, request.Length); }, testContext)) { @@ -226,6 +233,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests "HTTP/1.1 200 OK", "Connection: close", $"Date: {testContext.DateHeaderValue}", + "Content-Length: 7", "", "Goodbye" }); @@ -414,6 +422,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests "HTTP/1.1 200 OK", "Connection: close", $"Date: {testContext.DateHeaderValue}", + "Content-Length: 0", "\r\n"); } } @@ -451,7 +460,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [Theory] [MemberData(nameof(ConnectionFilterData))] - public async Task ZeroContentLengthNotSetAutomaticallyForNonKeepAliveRequests(TestServiceContext testContext) + public async Task ZeroContentLengthSetAutomaticallyForNonKeepAliveRequests(TestServiceContext testContext) { using (var server = new TestServer(EmptyApp, testContext)) { @@ -466,6 +475,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests "HTTP/1.1 200 OK", "Connection: close", $"Date: {testContext.DateHeaderValue}", + "Content-Length: 0", "", ""); } @@ -480,6 +490,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests "HTTP/1.1 200 OK", "Connection: close", $"Date: {testContext.DateHeaderValue}", + "Content-Length: 0", "", ""); } From 972be6e8c18d1ca1b0b8435dd6ba4526154df100 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Wed, 17 Aug 2016 11:10:39 -0700 Subject: [PATCH 0858/1662] Disable automatic chunking for all non keep-alive requests - Fixes a bug where Upgrade requests (e.g. WebSockets) would be chunked - Allows chunking to be disabled by setting "Connection: close" on the response --- .../Internal/Http/Frame.cs | 12 +-- .../ChunkedResponseTests.cs | 82 +++++++++++-------- .../EngineTests.cs | 40 ++++++++- 3 files changed, 87 insertions(+), 47 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs index aad34b77dd..7cc160f0ff 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs @@ -723,14 +723,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var end = SocketOutput.ProducingStart(); if (_keepAlive && hasConnection) { - foreach (var connectionValue in responseHeaders.HeaderConnection) - { - if (connectionValue.IndexOf("close", StringComparison.OrdinalIgnoreCase) != -1) - { - _keepAlive = false; - break; - } - } + var connectionValue = responseHeaders.HeaderConnection.ToString(); + _keepAlive = connectionValue.Equals("keep-alive", StringComparison.OrdinalIgnoreCase); } if (!responseHeaders.HasTransferEncoding && !responseHeaders.HasContentLength) @@ -746,7 +740,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http responseHeaders.SetRawContentLength("0", _bytesContentLengthZero); } } - else + else if(_keepAlive) { // Note for future reference: never change this to set _autoChunk to true on HTTP/1.0 // connections, even if we were to infer the client supports it because an HTTP/1.0 request diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedResponseTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedResponseTests.cs index 1f970fa9cf..8e9d12e4dd 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedResponseTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedResponseTests.cs @@ -63,42 +63,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [Theory] [MemberData(nameof(ConnectionFilterData))] - public async Task ResponsesAreChunkedAutomaticallyForHttp11NonKeepAliveRequests(TestServiceContext testContext) - { - using (var server = new TestServer(async httpContext => - { - var response = httpContext.Response; - await response.Body.WriteAsync(Encoding.ASCII.GetBytes("Hello "), 0, 6); - await response.Body.WriteAsync(Encoding.ASCII.GetBytes("World!"), 0, 6); - }, testContext)) - { - using (var connection = server.CreateConnection()) - { - await connection.SendEnd( - "GET / HTTP/1.1", - "Connection: close", - "", - ""); - await connection.ReceiveEnd( - "HTTP/1.1 200 OK", - "Connection: close", - $"Date: {testContext.DateHeaderValue}", - "Transfer-Encoding: chunked", - "", - "6", - "Hello ", - "6", - "World!", - "0", - "", - ""); - } - } - } - - [Theory] - [MemberData(nameof(ConnectionFilterData))] - public async Task ResponsesAreNotChunkedAutomaticallyForHttp10Requests(TestServiceContext testContext) + public async Task ResponsesAreNotChunkedAutomaticallyForHttp10RequestsAndHttp11NonKeepAliveRequests(TestServiceContext testContext) { using (var server = new TestServer(async httpContext => { @@ -111,6 +76,51 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { await connection.SendEnd( "GET / HTTP/1.0", + "Connection: keep-alive", + "", + ""); + await connection.ReceiveEnd( + "HTTP/1.1 200 OK", + "Connection: close", + $"Date: {testContext.DateHeaderValue}", + "", + "Hello World!"); + } + + using (var connection = server.CreateConnection()) + { + await connection.SendEnd( + "GET / HTTP/1.1", + "Connection: close", + "", + ""); + await connection.ReceiveEnd( + "HTTP/1.1 200 OK", + "Connection: close", + $"Date: {testContext.DateHeaderValue}", + "", + "Hello World!"); + } + } + } + + + [Theory] + [MemberData(nameof(ConnectionFilterData))] + public async Task SettingConnectionCloseHeaderInAppDisablesChunking(TestServiceContext testContext) + { + using (var server = new TestServer(async httpContext => + { + var response = httpContext.Response; + response.Headers["Connection"] = "close"; + await response.Body.WriteAsync(Encoding.ASCII.GetBytes("Hello "), 0, 6); + await response.Body.WriteAsync(Encoding.ASCII.GetBytes("World!"), 0, 6); + }, testContext)) + { + using (var connection = server.CreateConnection()) + { + await connection.SendEnd( + "GET / HTTP/1.1", "", ""); await connection.ReceiveEnd( diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs index 80e59304f8..eb295aadb2 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs @@ -120,7 +120,6 @@ namespace Microsoft.AspNetCore.Server.KestrelTests engine.Dispose(); } - [Theory] [MemberData(nameof(ConnectionFilterData))] public async Task Http10RequestReceivesHttp11Response(TestServiceContext testContext) @@ -143,7 +142,6 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } } - [Theory] [MemberData(nameof(ConnectionFilterData))] public async Task Http11(TestServiceContext testContext) @@ -1310,5 +1308,43 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } } } + + [Theory] + [MemberData(nameof(ConnectionFilterData))] + public async Task UpgradeRequestIsNotKeptAliveOrChunked(TestServiceContext testContext) + { + using (var server = new TestServer(async context => + { + var upgradeFeature = context.Features.Get(); + var duplexStream = await upgradeFeature.UpgradeAsync(); + + while (true) + { + var buffer = new byte[8192]; + var count = await duplexStream.ReadAsync(buffer, 0, buffer.Length); + if (count == 0) + { + break; + } + await duplexStream.WriteAsync(buffer, 0, count); + } + }, testContext)) + { + using (var connection = server.CreateConnection()) + { + await connection.SendEnd( + "GET / HTTP/1.1", + "Connection: Upgrade", + "", + "Hello World"); + await connection.ReceiveEnd( + "HTTP/1.1 101 Switching Protocols", + "Connection: Upgrade", + $"Date: {testContext.DateHeaderValue}", + "", + "Hello World"); + } + } + } } } From 7bd30ea693df64ae75271a256c08b2b968239bf3 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Thu, 18 Aug 2016 10:42:01 -0700 Subject: [PATCH 0859/1662] Log all startup errors in KestrelServer --- .../KestrelServer.cs | 21 +++++---- .../KestrelServerTests.cs | 46 ++++++++++++++++--- .../TestHelpers/TestApplicationErrorLogger.cs | 7 +++ 3 files changed, 57 insertions(+), 17 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServer.cs b/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServer.cs index 09ddb1a6b5..0bf4baf9c9 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServer.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServer.cs @@ -56,17 +56,17 @@ namespace Microsoft.AspNetCore.Server.Kestrel public void Start(IHttpApplication application) { - ValidateOptions(); - - if (_disposables != null) - { - // The server has already started and/or has not been cleaned up yet - throw new InvalidOperationException("Server has already started."); - } - _disposables = new Stack(); - try { + ValidateOptions(); + + if (_disposables != null) + { + // The server has already started and/or has not been cleaned up yet + throw new InvalidOperationException("Server has already started."); + } + _disposables = new Stack(); + var dateHeaderValueManager = new DateHeaderValueManager(); var trace = new KestrelTrace(_logger); var engine = new KestrelEngine(new ServiceContext @@ -180,8 +180,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel throw new InvalidOperationException("No recognized listening addresses were configured."); } } - catch + catch (Exception ex) { + _logger.LogCritical(0, ex, "Unable to start Kestrel."); Dispose(); throw; } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerTests.cs index d14df869a1..b93e4a0450 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerTests.cs @@ -21,32 +21,38 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [InlineData(-1337)] public void StartWithNonPositiveThreadCountThrows(int threadCount) { - var server = CreateServer(new KestrelServerOptions() { ThreadCount = threadCount }); + var testLogger = new TestApplicationErrorLogger(); + var server = CreateServer(new KestrelServerOptions() { ThreadCount = threadCount }, testLogger); var exception = Assert.Throws(() => StartDummyApplication(server)); Assert.Equal("threadCount", exception.ParamName); + Assert.Equal(1, testLogger.CriticalErrorsLogged); } [Fact] public void StartWithInvalidAddressThrows() { - var server = CreateServer(new KestrelServerOptions()); + var testLogger = new TestApplicationErrorLogger(); + var server = CreateServer(new KestrelServerOptions(), testLogger); server.Features.Get().Addresses.Add("http:/asdf"); var exception = Assert.Throws(() => StartDummyApplication(server)); Assert.Contains("Invalid URL", exception.Message); + Assert.Equal(1, testLogger.CriticalErrorsLogged); } [Fact] public void StartWithEmptyAddressesThrows() { - var server = CreateServer(new KestrelServerOptions()); + var testLogger = new TestApplicationErrorLogger(); + var server = CreateServer(new KestrelServerOptions(), testLogger); var exception = Assert.Throws(() => StartDummyApplication(server)); Assert.Equal("No recognized listening addresses were configured.", exception.Message); + Assert.Equal(1, testLogger.CriticalErrorsLogged); } [Theory] @@ -54,30 +60,56 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [InlineData(int.MaxValue - 1, int.MaxValue)] public void StartWithMaxRequestBufferSizeLessThanMaxRequestLineSizeThrows(long maxRequestBufferSize, int maxRequestLineSize) { + var testLogger = new TestApplicationErrorLogger(); var options = new KestrelServerOptions(); options.Limits.MaxRequestBufferSize = maxRequestBufferSize; options.Limits.MaxRequestLineSize = maxRequestLineSize; - var server = CreateServer(options); + var server = CreateServer(options, testLogger); var exception = Assert.Throws(() => StartDummyApplication(server)); Assert.Equal( $"Maximum request buffer size ({maxRequestBufferSize}) must be greater than or equal to maximum request line size ({maxRequestLineSize}).", exception.Message); + Assert.Equal(1, testLogger.CriticalErrorsLogged); } - private static KestrelServer CreateServer(KestrelServerOptions options) + private static KestrelServer CreateServer(KestrelServerOptions options, ILogger testLogger) { var lifetime = new LifetimeNotImplemented(); - var logger = new LoggerFactory(); - return new KestrelServer(Options.Create(options), lifetime, logger); + return new KestrelServer(Options.Create(options), lifetime, new TestLoggerFactory(testLogger)); } private static void StartDummyApplication(IServer server) { server.Start(new DummyApplication(context => TaskUtilities.CompletedTask)); } + + private class TestLoggerFactory : ILoggerFactory + { + private readonly ILogger _testLogger; + + public TestLoggerFactory(ILogger testLogger) + { + _testLogger = testLogger; + } + + public ILogger CreateLogger(string categoryName) + { + return _testLogger; + } + + public void AddProvider(ILoggerProvider provider) + { + throw new NotImplementedException(); + } + + public void Dispose() + { + throw new NotImplementedException(); + } + } } } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/TestApplicationErrorLogger.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/TestApplicationErrorLogger.cs index 2534de82da..419a617407 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/TestApplicationErrorLogger.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/TestApplicationErrorLogger.cs @@ -15,6 +15,8 @@ namespace Microsoft.AspNetCore.Server.KestrelTests public int TotalErrorsLogged { get; set; } + public int CriticalErrorsLogged { get; set; } + public int ApplicationErrorsLogged { get; set; } public IDisposable BeginScope(TState state) @@ -42,6 +44,11 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { TotalErrorsLogged++; } + + if (logLevel == LogLevel.Critical) + { + CriticalErrorsLogged++; + } } } } From 40636998d7f1c71141a7486947fbd928ef8fff97 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Sun, 21 Aug 2016 13:48:35 +0100 Subject: [PATCH 0860/1662] Improve inlinability of libuv success checking --- .../Internal/Infrastructure/KestrelThread.cs | 4 +- .../Internal/Networking/Libuv.cs | 105 +++++++++--------- .../Internal/Networking/UvLoopHandle.cs | 4 +- .../Internal/Networking/UvStreamHandle.cs | 6 +- 4 files changed, 60 insertions(+), 59 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/KestrelThread.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/KestrelThread.cs index 083ecf29f6..4d76a18c67 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/KestrelThread.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/KestrelThread.cs @@ -279,7 +279,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal try { - var ran1 = _loop.Run(); + _loop.Run(); if (_stopImmediate) { // thread-abort form of exit, resources will be leaked @@ -291,7 +291,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal _post.Dispose(); // Ensure the Dispose operations complete in the event loop. - var ran2 = _loop.Run(); + _loop.Run(); _loop.Dispose(); } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/Libuv.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/Libuv.cs index ee2a25855e..9b37adce59 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/Libuv.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/Libuv.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Runtime.CompilerServices; using System.Runtime.InteropServices; namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking @@ -61,50 +62,50 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking public readonly bool IsWindows; - public int Check(int statusCode) - { - Exception error; - var result = Check(statusCode, out error); - if (error != null) - { - throw error; - } - return statusCode; - } - - public int Check(int statusCode, out Exception error) + public void ThrowIfErrored(int statusCode) { if (statusCode < 0) { - var errorName = err_name(statusCode); - var errorDescription = strerror(statusCode); - error = new UvException("Error " + statusCode + " " + errorName + " " + errorDescription, statusCode); + ThrowError(statusCode); } - else - { - error = null; - } - return statusCode; + } + + private void ThrowError(int statusCode) + { + throw GetError(statusCode); + } + + public void Check(int statusCode, out Exception error) + { + error = statusCode < 0 ? GetError(statusCode) : null; + } + + [MethodImpl(MethodImplOptions.NoInlining)] + private UvException GetError(int statusCode) + { + var errorName = err_name(statusCode); + var errorDescription = strerror(statusCode); + return new UvException("Error " + statusCode + " " + errorName + " " + errorDescription, statusCode); } protected Func _uv_loop_init; public void loop_init(UvLoopHandle handle) { - Check(_uv_loop_init(handle)); + ThrowIfErrored(_uv_loop_init(handle)); } protected Func _uv_loop_close; public void loop_close(UvLoopHandle handle) { handle.Validate(closed: true); - Check(_uv_loop_close(handle.InternalGetHandle())); + ThrowIfErrored(_uv_loop_close(handle.InternalGetHandle())); } protected Func _uv_run; - public int run(UvLoopHandle handle, int mode) + public void run(UvLoopHandle handle, int mode) { handle.Validate(); - return Check(_uv_run(handle, mode)); + ThrowIfErrored(_uv_run(handle, mode)); } protected Action _uv_stop; @@ -131,10 +132,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking [UnmanagedFunctionPointer(CallingConvention.Cdecl)] protected delegate int uv_fileno_func(UvHandle handle, ref IntPtr socket); protected uv_fileno_func _uv_fileno; - public int uv_fileno(UvHandle handle, ref IntPtr socket) + public void uv_fileno(UvHandle handle, ref IntPtr socket) { handle.Validate(); - return Check(_uv_fileno(handle, ref socket)); + ThrowIfErrored(_uv_fileno(handle, ref socket)); } [UnmanagedFunctionPointer(CallingConvention.Cdecl)] @@ -158,19 +159,19 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking { loop.Validate(); handle.Validate(); - Check(_uv_async_init(loop, handle, cb)); + ThrowIfErrored(_uv_async_init(loop, handle, cb)); } protected Func _uv_async_send; public void async_send(UvAsyncHandle handle) { - Check(_uv_async_send(handle)); + ThrowIfErrored(_uv_async_send(handle)); } protected Func _uv_unsafe_async_send; public void unsafe_async_send(IntPtr handle) { - Check(_uv_unsafe_async_send(handle)); + ThrowIfErrored(_uv_unsafe_async_send(handle)); } protected Func _uv_tcp_init; @@ -178,7 +179,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking { loop.Validate(); handle.Validate(); - Check(_uv_tcp_init(loop, handle)); + ThrowIfErrored(_uv_tcp_init(loop, handle)); } protected delegate int uv_tcp_bind_func(UvTcpHandle handle, ref SockAddr addr, int flags); @@ -186,7 +187,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking public void tcp_bind(UvTcpHandle handle, ref SockAddr addr, int flags) { handle.Validate(); - Check(_uv_tcp_bind(handle, ref addr, flags)); + ThrowIfErrored(_uv_tcp_bind(handle, ref addr, flags)); if (PlatformApis.IsWindows) { tcp_bind_windows_extras(handle); @@ -200,7 +201,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking const int SOCKET_ERROR = -1; var socket = IntPtr.Zero; - Check(_uv_fileno(handle, ref socket)); + ThrowIfErrored(_uv_fileno(handle, ref socket)); // Enable loopback fast-path for lower latency for localhost comms, like HttpPlatformHandler fronting // http://blogs.technet.com/b/wincat/archive/2012/12/05/fast-tcp-loopback-performance-and-low-latency-with-windows-server-2012-tcp-loopback-fast-path.aspx @@ -218,7 +219,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking } else { - Check(errorId); + ThrowIfErrored(errorId); } } } @@ -227,14 +228,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking public void tcp_open(UvTcpHandle handle, IntPtr hSocket) { handle.Validate(); - Check(_uv_tcp_open(handle, hSocket)); + ThrowIfErrored(_uv_tcp_open(handle, hSocket)); } protected Func _uv_tcp_nodelay; public void tcp_nodelay(UvTcpHandle handle, bool enable) { handle.Validate(); - Check(_uv_tcp_nodelay(handle, enable ? 1 : 0)); + ThrowIfErrored(_uv_tcp_nodelay(handle, enable ? 1 : 0)); } protected Func _uv_pipe_init; @@ -242,14 +243,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking { loop.Validate(); handle.Validate(); - Check(_uv_pipe_init(loop, handle, ipc ? -1 : 0)); + ThrowIfErrored(_uv_pipe_init(loop, handle, ipc ? -1 : 0)); } protected Func _uv_pipe_bind; public void pipe_bind(UvPipeHandle handle, string name) { handle.Validate(); - Check(_uv_pipe_bind(handle, name)); + ThrowIfErrored(_uv_pipe_bind(handle, name)); } [UnmanagedFunctionPointer(CallingConvention.Cdecl)] @@ -258,7 +259,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking public void listen(UvStreamHandle handle, int backlog, uv_connection_cb cb) { handle.Validate(); - Check(_uv_listen(handle, backlog, cb)); + ThrowIfErrored(_uv_listen(handle, backlog, cb)); } protected Func _uv_accept; @@ -266,7 +267,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking { server.Validate(); client.Validate(); - Check(_uv_accept(server, client)); + ThrowIfErrored(_uv_accept(server, client)); } [UnmanagedFunctionPointer(CallingConvention.Cdecl)] @@ -294,21 +295,21 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking public void read_start(UvStreamHandle handle, uv_alloc_cb alloc_cb, uv_read_cb read_cb) { handle.Validate(); - Check(_uv_read_start(handle, alloc_cb, read_cb)); + ThrowIfErrored(_uv_read_start(handle, alloc_cb, read_cb)); } protected Func _uv_read_stop; public void read_stop(UvStreamHandle handle) { handle.Validate(); - Check(_uv_read_stop(handle)); + ThrowIfErrored(_uv_read_stop(handle)); } protected Func _uv_try_write; - public int try_write(UvStreamHandle handle, uv_buf_t[] bufs, int nbufs) + public void try_write(UvStreamHandle handle, uv_buf_t[] bufs, int nbufs) { handle.Validate(); - return Check(_uv_try_write(handle, bufs, nbufs)); + ThrowIfErrored(_uv_try_write(handle, bufs, nbufs)); } [UnmanagedFunctionPointer(CallingConvention.Cdecl)] @@ -320,7 +321,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking { req.Validate(); handle.Validate(); - Check(_uv_write(req, handle, bufs, nbufs, cb)); + ThrowIfErrored(_uv_write(req, handle, bufs, nbufs, cb)); } unsafe protected delegate int uv_write2_func(UvRequest req, UvStreamHandle handle, uv_buf_t* bufs, int nbufs, UvStreamHandle sendHandle, uv_write_cb cb); @@ -329,7 +330,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking { req.Validate(); handle.Validate(); - Check(_uv_write2(req, handle, bufs, nbufs, sendHandle, cb)); + ThrowIfErrored(_uv_write2(req, handle, bufs, nbufs, sendHandle, cb)); } [UnmanagedFunctionPointer(CallingConvention.Cdecl)] @@ -339,7 +340,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking { req.Validate(); handle.Validate(); - Check(_uv_shutdown(req, handle, cb)); + ThrowIfErrored(_uv_shutdown(req, handle, cb)); } protected Func _uv_err_name; @@ -376,16 +377,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking protected delegate int uv_ip4_addr_func(string ip, int port, out SockAddr addr); protected uv_ip4_addr_func _uv_ip4_addr; - public int ip4_addr(string ip, int port, out SockAddr addr, out Exception error) + public void ip4_addr(string ip, int port, out SockAddr addr, out Exception error) { - return Check(_uv_ip4_addr(ip, port, out addr), out error); + Check(_uv_ip4_addr(ip, port, out addr), out error); } protected delegate int uv_ip6_addr_func(string ip, int port, out SockAddr addr); protected uv_ip6_addr_func _uv_ip6_addr; - public int ip6_addr(string ip, int port, out SockAddr addr, out Exception error) + public void ip6_addr(string ip, int port, out SockAddr addr, out Exception error) { - return Check(_uv_ip6_addr(ip, port, out addr), out error); + Check(_uv_ip6_addr(ip, port, out addr), out error); } [UnmanagedFunctionPointer(CallingConvention.Cdecl)] @@ -402,7 +403,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking public void tcp_getsockname(UvTcpHandle handle, out SockAddr addr, ref int namelen) { handle.Validate(); - Check(_uv_tcp_getsockname(handle, out addr, ref namelen)); + ThrowIfErrored(_uv_tcp_getsockname(handle, out addr, ref namelen)); } public delegate int uv_tcp_getpeername_func(UvTcpHandle handle, out SockAddr addr, ref int namelen); @@ -410,7 +411,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking public void tcp_getpeername(UvTcpHandle handle, out SockAddr addr, ref int namelen) { handle.Validate(); - Check(_uv_tcp_getpeername(handle, out addr, ref namelen)); + ThrowIfErrored(_uv_tcp_getpeername(handle, out addr, ref namelen)); } public uv_buf_t buf_init(IntPtr memory, int len) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/UvLoopHandle.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/UvLoopHandle.cs index 0d92f89770..25bb3701b0 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/UvLoopHandle.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/UvLoopHandle.cs @@ -23,9 +23,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking _uv.loop_init(this); } - public int Run(int mode = 0) + public void Run(int mode = 0) { - return _uv.run(this, mode); + _uv.run(this, mode); } public void Stop() diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/UvStreamHandle.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/UvStreamHandle.cs index 1a930f604d..32604a08ce 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/UvStreamHandle.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/UvStreamHandle.cs @@ -118,9 +118,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking _uv.read_stop(this); } - public int TryWrite(Libuv.uv_buf_t buf) + public void TryWrite(Libuv.uv_buf_t buf) { - return _uv.try_write(this, new[] { buf }, 1); + _uv.try_write(this, new[] { buf }, 1); } private static void UvConnectionCb(IntPtr handle, int status) @@ -128,7 +128,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking var stream = FromIntPtr(handle); Exception error; - status = stream.Libuv.Check(status, out error); + stream.Libuv.Check(status, out error); try { From ca9935943d2641c7b5658d786b4a86f191e34cbf Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Mon, 22 Aug 2016 14:29:08 -0700 Subject: [PATCH 0861/1662] Updating to version 1.0.1. --- src/Microsoft.AspNetCore.Server.Kestrel.Https/project.json | 2 +- src/Microsoft.AspNetCore.Server.Kestrel/project.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Https/project.json b/src/Microsoft.AspNetCore.Server.Kestrel.Https/project.json index f8ee43e9a7..cfad9e7217 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Https/project.json +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Https/project.json @@ -1,5 +1,5 @@ { - "version": "1.0.0", + "version": "1.0.1", "description": "HTTPS support for the ASP.NET Core Kestrel cross-platform web server.", "buildOptions": { "keyFile": "../../tools/Key.snk", diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/project.json b/src/Microsoft.AspNetCore.Server.Kestrel/project.json index b6ca5d51c7..4cf319e351 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/project.json +++ b/src/Microsoft.AspNetCore.Server.Kestrel/project.json @@ -1,5 +1,5 @@ { - "version": "1.0.0", + "version": "1.0.1", "description": "ASP.NET Core Kestrel cross-platform web server.", "packOptions": { "repository": { From ddf5b44de6cca9e419a2a9d4aa252d5e83c13c22 Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Mon, 22 Aug 2016 14:58:31 -0700 Subject: [PATCH 0862/1662] Updating to version 1.0.1. --- samples/LargeResponseApp/project.json | 2 +- samples/SampleApp/project.json | 4 ++-- src/Microsoft.AspNetCore.Server.Kestrel.Https/project.json | 4 ++-- src/Microsoft.AspNetCore.Server.Kestrel/project.json | 2 +- .../project.json | 4 ++-- test/Microsoft.AspNetCore.Server.KestrelTests/project.json | 4 ++-- 6 files changed, 10 insertions(+), 10 deletions(-) diff --git a/samples/LargeResponseApp/project.json b/samples/LargeResponseApp/project.json index 564a1b623a..dbf8d5adcb 100644 --- a/samples/LargeResponseApp/project.json +++ b/samples/LargeResponseApp/project.json @@ -1,7 +1,7 @@ { "version": "1.0.0-*", "dependencies": { - "Microsoft.AspNetCore.Server.Kestrel": "1.0.0" + "Microsoft.AspNetCore.Server.Kestrel": "1.0.1" }, "buildOptions": { "emitEntryPoint": true diff --git a/samples/SampleApp/project.json b/samples/SampleApp/project.json index 721f53351c..e6b62ac106 100644 --- a/samples/SampleApp/project.json +++ b/samples/SampleApp/project.json @@ -1,8 +1,8 @@ { "version": "1.0.0-*", "dependencies": { - "Microsoft.AspNetCore.Server.Kestrel": "1.0.0", - "Microsoft.AspNetCore.Server.Kestrel.Https": "1.0.0", + "Microsoft.AspNetCore.Server.Kestrel": "1.0.1", + "Microsoft.AspNetCore.Server.Kestrel.Https": "1.0.1", "Microsoft.Extensions.Logging.Console": "1.0.0" }, "buildOptions": { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Https/project.json b/src/Microsoft.AspNetCore.Server.Kestrel.Https/project.json index f8ee43e9a7..42633e4761 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Https/project.json +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Https/project.json @@ -1,5 +1,5 @@ { - "version": "1.0.0", + "version": "1.0.1", "description": "HTTPS support for the ASP.NET Core Kestrel cross-platform web server.", "buildOptions": { "keyFile": "../../tools/Key.snk", @@ -19,7 +19,7 @@ ] }, "dependencies": { - "Microsoft.AspNetCore.Server.Kestrel": "1.0.0" + "Microsoft.AspNetCore.Server.Kestrel": "1.0.1" }, "frameworks": { "net451": {}, diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/project.json b/src/Microsoft.AspNetCore.Server.Kestrel/project.json index b6ca5d51c7..4cf319e351 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/project.json +++ b/src/Microsoft.AspNetCore.Server.Kestrel/project.json @@ -1,5 +1,5 @@ { - "version": "1.0.0", + "version": "1.0.1", "description": "ASP.NET Core Kestrel cross-platform web server.", "packOptions": { "repository": { diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json index d21afa6546..12ce280144 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json @@ -3,8 +3,8 @@ "dependencies": { "dotnet-test-xunit": "1.0.0-rc3-000000-01", "Microsoft.AspNetCore.Http.Abstractions": "1.0.0", - "Microsoft.AspNetCore.Server.Kestrel": "1.0.0", - "Microsoft.AspNetCore.Server.Kestrel.Https": "1.0.0", + "Microsoft.AspNetCore.Server.Kestrel": "1.0.1", + "Microsoft.AspNetCore.Server.Kestrel.Https": "1.0.1", "Microsoft.AspNetCore.Testing": "1.0.0-rtm-21431", "Microsoft.Extensions.Logging.Console": "1.0.0", "Newtonsoft.Json": "9.0.1", diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/project.json b/test/Microsoft.AspNetCore.Server.KestrelTests/project.json index 7928752b7e..125f43cbc6 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/project.json +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/project.json @@ -2,8 +2,8 @@ "version": "1.0.0-*", "dependencies": { "dotnet-test-xunit": "1.0.0-rc3-000000-01", - "Microsoft.AspNetCore.Server.Kestrel": "1.0.0", - "Microsoft.AspNetCore.Server.Kestrel.Https": "1.0.0", + "Microsoft.AspNetCore.Server.Kestrel": "1.0.1", + "Microsoft.AspNetCore.Server.Kestrel.Https": "1.0.1", "Microsoft.AspNetCore.Testing": "1.0.0-rtm-21431", "xunit": "2.1.0" }, From 8a30c1f804f10bd054c0ebcfa26ba9219c35c224 Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Mon, 22 Aug 2016 15:03:54 -0700 Subject: [PATCH 0863/1662] Reset frame streams on each request (#1028). --- .../Internal/Http/Frame.cs | 7 +-- .../RequestTests.cs | 47 +++++++++++++++++++ .../FrameTests.cs | 40 +++++++++++++++- 3 files changed, 89 insertions(+), 5 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs index 9e45c3f695..d014f3d2b9 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs @@ -242,11 +242,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if (_frameStreams == null) { _frameStreams = new Streams(this); - RequestBody = _frameStreams.RequestBody; - ResponseBody = _frameStreams.ResponseBody; - DuplexStream = _frameStreams.DuplexStream; } + RequestBody = _frameStreams.RequestBody; + ResponseBody = _frameStreams.ResponseBody; + DuplexStream = _frameStreams.DuplexStream; + _frameStreams.RequestBody.StartAcceptingReads(messageBody); _frameStreams.ResponseBody.StartAcceptingWrites(); } diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs index 487306a386..a01b84f7b8 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs @@ -1,7 +1,9 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; using System.Globalization; +using System.IO; using System.Net; using System.Net.Http; using System.Net.Sockets; @@ -137,6 +139,51 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } } + [Fact] + public async Task StreamsAreNotPersistedAcrossRequests() + { + var requestBodyPersisted = false; + var responseBodyPersisted = false; + + var builder = new WebHostBuilder() + .UseKestrel() + .UseUrls($"http://127.0.0.1:0") + .Configure(app => + { + app.Run(async context => + { + if (context.Request.Body is MemoryStream) + { + requestBodyPersisted = true; + } + + if (context.Response.Body is MemoryStream) + { + responseBodyPersisted = true; + } + + context.Request.Body = new MemoryStream(); + context.Response.Body = new MemoryStream(); + + await context.Response.WriteAsync("hello, world"); + }); + }); + + using (var host = builder.Build()) + { + host.Start(); + + using (var client = new HttpClient { BaseAddress = new Uri($"http://127.0.0.1:{host.GetPort()}") }) + { + await client.GetAsync("/"); + await client.GetAsync("/"); + + Assert.False(requestBodyPersisted); + Assert.False(responseBodyPersisted); + } + } + } + private async Task TestRemoteIPAddress(string registerAddress, string requestAddress, string expectAddress) { var builder = new WebHostBuilder() diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs index 52c44bb2b4..c7ada35248 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.IO; using System.Text; using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Server.Kestrel; @@ -453,9 +454,10 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var frame = new Frame(application: null, context: connectionContext); frame.InitializeHeaders(); - // Act var originalRequestHeaders = frame.RequestHeaders; frame.RequestHeaders = new FrameRequestHeaders(); + + // Act frame.InitializeHeaders(); // Assert @@ -476,13 +478,47 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var frame = new Frame(application: null, context: connectionContext); frame.InitializeHeaders(); - // Act var originalResponseHeaders = frame.ResponseHeaders; frame.ResponseHeaders = new FrameResponseHeaders(); + + // Act frame.InitializeHeaders(); // Assert Assert.Same(originalResponseHeaders, frame.ResponseHeaders); } + + [Fact] + public void InitializeStreamsResetsStreams() + { + // Arrange + var connectionContext = new ConnectionContext() + { + DateHeaderValueManager = new DateHeaderValueManager(), + ServerAddress = ServerAddress.FromUrl("http://localhost:5000"), + ServerOptions = new KestrelServerOptions(), + SocketOutput = new MockSocketOuptut() + }; + var frame = new Frame(application: null, context: connectionContext); + frame.InitializeHeaders(); + + var messageBody = MessageBody.For("HTTP/1.1", (FrameRequestHeaders)frame.RequestHeaders, frame); + frame.InitializeStreams(messageBody); + + var originalRequestBody = frame.RequestBody; + var originalResponseBody = frame.ResponseBody; + var originalDuplexStream = frame.DuplexStream; + frame.RequestBody = new MemoryStream(); + frame.ResponseBody = new MemoryStream(); + frame.DuplexStream = new MemoryStream(); + + // Act + frame.InitializeStreams(messageBody); + + // Assert + Assert.Same(originalRequestBody, frame.RequestBody); + Assert.Same(originalResponseBody, frame.ResponseBody); + Assert.Same(originalDuplexStream, frame.DuplexStream); + } } } From af73e519c1872553fde3fe523690b9925a947249 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Thu, 25 Aug 2016 07:53:01 +0100 Subject: [PATCH 0864/1662] Comment inlinability changes --- .../Internal/Networking/Libuv.cs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/Libuv.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/Libuv.cs index 9b37adce59..986b406003 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/Libuv.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/Libuv.cs @@ -64,6 +64,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking public void ThrowIfErrored(int statusCode) { + // Note: method is explicitly small so the success case is easily inlined if (statusCode < 0) { ThrowError(statusCode); @@ -72,17 +73,23 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking private void ThrowError(int statusCode) { + // Note: only has one throw block so it will marked as "Does not return" by the jit + // and not inlined into previous function, while also marking as a function + // that does not need cpu register prep to call (see: https://github.com/dotnet/coreclr/pull/6103) throw GetError(statusCode); } public void Check(int statusCode, out Exception error) { + // Note: method is explicitly small so the success case is easily inlined error = statusCode < 0 ? GetError(statusCode) : null; } [MethodImpl(MethodImplOptions.NoInlining)] private UvException GetError(int statusCode) { + // Note: method marked as NoInlining so it doesn't bloat either of the two preceeding functions + // Check and ThrowError and alter their jit heuristics. var errorName = err_name(statusCode); var errorDescription = strerror(statusCode); return new UvException("Error " + statusCode + " " + errorName + " " + errorDescription, statusCode); From 7dc0a8c7bdccfc027b05434c2b5fce9237ec9025 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Thu, 25 Aug 2016 07:58:36 +0100 Subject: [PATCH 0865/1662] Return count from trywrite --- .../Internal/Networking/Libuv.cs | 6 ++++-- .../Internal/Networking/UvStreamHandle.cs | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/Libuv.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/Libuv.cs index 986b406003..9c918491cc 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/Libuv.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/Libuv.cs @@ -313,10 +313,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking } protected Func _uv_try_write; - public void try_write(UvStreamHandle handle, uv_buf_t[] bufs, int nbufs) + public int try_write(UvStreamHandle handle, uv_buf_t[] bufs, int nbufs) { handle.Validate(); - ThrowIfErrored(_uv_try_write(handle, bufs, nbufs)); + var count = _uv_try_write(handle, bufs, nbufs); + ThrowIfErrored(count); + return count; } [UnmanagedFunctionPointer(CallingConvention.Cdecl)] diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/UvStreamHandle.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/UvStreamHandle.cs index 32604a08ce..698a693c60 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/UvStreamHandle.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/UvStreamHandle.cs @@ -118,9 +118,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking _uv.read_stop(this); } - public void TryWrite(Libuv.uv_buf_t buf) + public int TryWrite(Libuv.uv_buf_t buf) { - _uv.try_write(this, new[] { buf }, 1); + return _uv.try_write(this, new[] { buf }, 1); } private static void UvConnectionCb(IntPtr handle, int status) From be51e5aecbc12056a15e01f852af6c2bcb999dc1 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Thu, 25 Aug 2016 08:07:15 +0100 Subject: [PATCH 0866/1662] Remove unneeded unsafe modifiers --- .../Infrastructure/MemoryPoolIterator.cs | 6 +++--- .../Internal/Networking/Libuv.cs | 16 ++++++++-------- .../Internal/Networking/UvAsyncHandle.cs | 2 +- .../Internal/Networking/UvHandle.cs | 2 +- .../Internal/Networking/UvMemory.cs | 2 +- 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolIterator.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolIterator.cs index 78efd5adca..ccc54cf52a 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolIterator.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolIterator.cs @@ -215,7 +215,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure } } - public unsafe int Seek(ref Vector byte0Vector) + public int Seek(ref Vector byte0Vector) { int bytesScanned; return Seek(ref byte0Vector, out bytesScanned); @@ -433,7 +433,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure } } - public unsafe int Seek(ref Vector byte0Vector, ref Vector byte1Vector) + public int Seek(ref Vector byte0Vector, ref Vector byte1Vector) { var limit = new MemoryPoolIterator(); return Seek(ref byte0Vector, ref byte1Vector, ref limit); @@ -574,7 +574,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure } } - public unsafe int Seek(ref Vector byte0Vector, ref Vector byte1Vector, ref Vector byte2Vector) + public int Seek(ref Vector byte0Vector, ref Vector byte1Vector, ref Vector byte2Vector) { var limit = new MemoryPoolIterator(); return Seek(ref byte0Vector, ref byte1Vector, ref byte2Vector, ref limit); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/Libuv.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/Libuv.cs index ee2a25855e..1e57f836c9 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/Libuv.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/Libuv.cs @@ -272,7 +272,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking [UnmanagedFunctionPointer(CallingConvention.Cdecl)] public delegate void uv_connect_cb(IntPtr req, int status); protected Action _uv_pipe_connect; - unsafe public void pipe_connect(UvConnectRequest req, UvPipeHandle handle, string name, uv_connect_cb cb) + public void pipe_connect(UvConnectRequest req, UvPipeHandle handle, string name, uv_connect_cb cb) { req.Validate(); handle.Validate(); @@ -280,7 +280,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking } protected Func _uv_pipe_pending_count; - unsafe public int pipe_pending_count(UvPipeHandle handle) + public int pipe_pending_count(UvPipeHandle handle) { handle.Validate(); return _uv_pipe_pending_count(handle); @@ -315,7 +315,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking public delegate void uv_write_cb(IntPtr req, int status); unsafe protected delegate int uv_write_func(UvRequest req, UvStreamHandle handle, uv_buf_t* bufs, int nbufs, uv_write_cb cb); - unsafe protected uv_write_func _uv_write; + protected uv_write_func _uv_write; unsafe public void write(UvRequest req, UvStreamHandle handle, uv_buf_t* bufs, int nbufs, uv_write_cb cb) { req.Validate(); @@ -324,7 +324,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking } unsafe protected delegate int uv_write2_func(UvRequest req, UvStreamHandle handle, uv_buf_t* bufs, int nbufs, UvStreamHandle sendHandle, uv_write_cb cb); - unsafe protected uv_write2_func _uv_write2; + protected uv_write2_func _uv_write2; unsafe public void write2(UvRequest req, UvStreamHandle handle, Libuv.uv_buf_t* bufs, int nbufs, UvStreamHandle sendHandle, uv_write_cb cb) { req.Validate(); @@ -343,14 +343,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking } protected Func _uv_err_name; - public unsafe string err_name(int err) + public string err_name(int err) { IntPtr ptr = _uv_err_name(err); return ptr == IntPtr.Zero ? null : Marshal.PtrToStringAnsi(ptr); } protected Func _uv_strerror; - public unsafe string strerror(int err) + public string strerror(int err) { IntPtr ptr = _uv_strerror(err); return ptr == IntPtr.Zero ? null : Marshal.PtrToStringAnsi(ptr); @@ -391,7 +391,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking [UnmanagedFunctionPointer(CallingConvention.Cdecl)] public delegate void uv_walk_cb(IntPtr handle, IntPtr arg); protected Func _uv_walk; - unsafe public void walk(UvLoopHandle loop, uv_walk_cb walk_cb, IntPtr arg) + public void walk(UvLoopHandle loop, uv_walk_cb walk_cb, IntPtr arg) { loop.Validate(); _uv_walk(loop, walk_cb, arg); @@ -592,7 +592,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking public static extern int uv_tcp_getpeername(UvTcpHandle handle, out SockAddr name, ref int namelen); [DllImport("libuv", CallingConvention = CallingConvention.Cdecl)] - unsafe public static extern int uv_walk(UvLoopHandle loop, uv_walk_cb walk_cb, IntPtr arg); + public static extern int uv_walk(UvLoopHandle loop, uv_walk_cb walk_cb, IntPtr arg); [DllImport("WS2_32.dll", CallingConvention = CallingConvention.Winapi)] unsafe public static extern int WSAIoctl( diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/UvAsyncHandle.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/UvAsyncHandle.cs index 93c1efcc64..da0ae7c3d4 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/UvAsyncHandle.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/UvAsyncHandle.cs @@ -37,7 +37,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking _uv.async_send(this); } - unsafe private static void AsyncCb(IntPtr handle) + private static void AsyncCb(IntPtr handle) { FromIntPtr(handle)._callback.Invoke(); } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/UvHandle.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/UvHandle.cs index 3db7dc21a3..0203ac610c 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/UvHandle.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/UvHandle.cs @@ -17,7 +17,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking { } - unsafe protected void CreateHandle( + protected void CreateHandle( Libuv uv, int threadId, int size, diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/UvMemory.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/UvMemory.cs index ecd15751e5..5b490ada94 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/UvMemory.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/UvMemory.cs @@ -60,7 +60,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking DestroyMemory(memory, gcHandlePtr); } - unsafe protected static void DestroyMemory(IntPtr memory, IntPtr gcHandlePtr) + protected static void DestroyMemory(IntPtr memory, IntPtr gcHandlePtr) { if (gcHandlePtr != IntPtr.Zero) { From b6a177ef0b5ff27ebc1a49e7d1ad24f88a8b129a Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Thu, 25 Aug 2016 11:53:16 -0700 Subject: [PATCH 0867/1662] Test for categoryName passed to ILoggerFactory.CreateLogger() in KestrelServer.ctor() (#797) --- .../KestrelServerTests.cs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerTests.cs index b93e4a0450..ae4f63828d 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerTests.cs @@ -2,14 +2,14 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Reflection; using Microsoft.AspNetCore.Hosting.Server; using Microsoft.AspNetCore.Hosting.Server.Features; -using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Server.Kestrel; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; -using Microsoft.AspNetCore.Server.Kestrel.Internal; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; +using Moq; using Xunit; namespace Microsoft.AspNetCore.Server.KestrelTests @@ -75,6 +75,14 @@ namespace Microsoft.AspNetCore.Server.KestrelTests Assert.Equal(1, testLogger.CriticalErrorsLogged); } + [Fact] + public void LoggerCategoryNameIsKestrelServerNamespace() + { + var mockLoggerFactory = new Mock(); + new KestrelServer(Options.Create(null), new LifetimeNotImplemented(), mockLoggerFactory.Object); + mockLoggerFactory.Verify(factory => factory.CreateLogger("Microsoft.AspNetCore.Server.Kestrel")); + } + private static KestrelServer CreateServer(KestrelServerOptions options, ILogger testLogger) { var lifetime = new LifetimeNotImplemented(); From 4587a0fc95a0c6de4f4b2da6c3534f53b7bc2fe4 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Mon, 29 Aug 2016 12:14:19 -0700 Subject: [PATCH 0868/1662] Prevent possible deadlocks when using MockLibuv.OnPostTask --- .../TestHelpers/MockLibuv.cs | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockLibuv.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockLibuv.cs index a832fbdf9f..a2e34385ad 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockLibuv.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockLibuv.cs @@ -12,8 +12,10 @@ namespace Microsoft.AspNetCore.Server.KestrelTests.TestHelpers { private UvAsyncHandle _postHandle; private uv_async_cb _onPost; - private TaskCompletionSource _onPostTcs; - private object _postLock = new object(); + + private readonly object _postLock = new object(); + private TaskCompletionSource _onPostTcs = new TaskCompletionSource(); + private bool _completedOnPostTcs; private bool _stopLoop; private readonly ManualResetEventSlim _loopWh = new ManualResetEventSlim(); @@ -37,9 +39,10 @@ namespace Microsoft.AspNetCore.Server.KestrelTests.TestHelpers { lock (_postLock) { - if (_onPostTcs == null || _onPostTcs.Task.IsCompleted) + if (_completedOnPostTcs) { _onPostTcs = new TaskCompletionSource(); + _completedOnPostTcs = false; } PostCount++; @@ -64,13 +67,23 @@ namespace Microsoft.AspNetCore.Server.KestrelTests.TestHelpers { _loopWh.Wait(); KestrelThreadBlocker.Wait(); + TaskCompletionSource onPostTcs; lock (_postLock) { _loopWh.Reset(); _onPost(_postHandle.InternalGetHandle()); - _onPostTcs.TrySetResult(null); + + // Ensure any subsequent calls to uv_async_send + // create a new _onPostTcs to be completed. + onPostTcs = _onPostTcs; + _completedOnPostTcs = true; } + + // Calling TrySetResult outside the lock to avoid deadlock + // when the code attempts to call uv_async_send after awaiting + // OnPostTask. + onPostTcs.TrySetResult(null); } return 0; From 0742d113bedaaff35bd0159a5d8c33aacc38d3cd Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Mon, 29 Aug 2016 16:32:03 -0700 Subject: [PATCH 0869/1662] Make all calls to ThreadPool.QueueUserWorkItem through IThreadPool - This allows SocketOutputTests to cause QUWI to exec synchronously - To avoid allocations, the logger can't be captured making it "unsafe" --- .../Internal/Http/SocketOutput.cs | 10 +++++----- .../Internal/Infrastructure/IThreadPool.cs | 2 ++ .../Internal/Infrastructure/LoggingThreadPool.cs | 5 +++++ .../TestHelpers/SynchronousThreadPool.cs | 6 ++++++ 4 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/SocketOutput.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/SocketOutput.cs index 0b02da9748..d3064e27e9 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/SocketOutput.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/SocketOutput.cs @@ -288,7 +288,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if (blockToReturn != null) { - ThreadPool.QueueUserWorkItem(_returnBlocks, blockToReturn); + _threadPool.UnsafeRun(_returnBlocks, blockToReturn); } } @@ -542,8 +542,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http private class WriteContext { - private static WaitCallback _returnWrittenBlocks = (state) => ReturnWrittenBlocks((MemoryPoolBlock)state); - private static WaitCallback _completeWrite = (state) => ((WriteContext)state).CompleteOnThreadPool(); + private static readonly WaitCallback _returnWrittenBlocks = (state) => ReturnWrittenBlocks((MemoryPoolBlock)state); + private static readonly WaitCallback _completeWrite = (state) => ((WriteContext)state).CompleteOnThreadPool(); private SocketOutput Self; private UvWriteReq _writeReq; @@ -658,7 +658,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } else { - ThreadPool.QueueUserWorkItem(_completeWrite, this); + Self._threadPool.UnsafeRun(_completeWrite, this); } } @@ -697,7 +697,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } block.Next = null; - ThreadPool.QueueUserWorkItem(_returnWrittenBlocks, _lockedStart.Block); + Self._threadPool.UnsafeRun(_returnWrittenBlocks, _lockedStart.Block); } private static void ReturnWrittenBlocks(MemoryPoolBlock block) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/IThreadPool.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/IThreadPool.cs index e4fe4eb40a..af5b6df175 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/IThreadPool.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/IThreadPool.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Threading; using System.Threading.Tasks; namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure @@ -12,5 +13,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure void Cancel(TaskCompletionSource tcs); void Error(TaskCompletionSource tcs, Exception ex); void Run(Action action); + void UnsafeRun(WaitCallback action, object state); } } \ No newline at end of file diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/LoggingThreadPool.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/LoggingThreadPool.cs index 6cdf0014c2..bbbac1b6f7 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/LoggingThreadPool.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/LoggingThreadPool.cs @@ -63,6 +63,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure ThreadPool.QueueUserWorkItem(_runAction, action); } + public void UnsafeRun(WaitCallback action, object state) + { + ThreadPool.QueueUserWorkItem(action, state); + } + public void Complete(TaskCompletionSource tcs) { ThreadPool.QueueUserWorkItem(_completeTcs, tcs); diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/SynchronousThreadPool.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/SynchronousThreadPool.cs index ac7e2717e4..15994044d2 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/SynchronousThreadPool.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/SynchronousThreadPool.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; @@ -28,5 +29,10 @@ namespace Microsoft.AspNetCore.Server.KestrelTests.TestHelpers { action(); } + + public void UnsafeRun(WaitCallback action, object state) + { + action(state); + } } } From acfcafb6e1ce4a11dd23f09e38b7f46ef3fdc50f Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Mon, 29 Aug 2016 17:01:11 -0700 Subject: [PATCH 0870/1662] Ensure MockLibuv.OnPostTask doesn't complete too early --- .../Internal/Infrastructure/KestrelThread.cs | 15 ++++-- .../SocketOutputTests.cs | 50 +++++++++++-------- .../TestHelpers/MockLibuv.cs | 20 +++++--- 3 files changed, 55 insertions(+), 30 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/KestrelThread.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/KestrelThread.cs index 4d76a18c67..6d46aba889 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/KestrelThread.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/KestrelThread.cs @@ -19,13 +19,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal /// public class KestrelThread { + private static readonly Action _postCallbackAdapter = (callback, state) => ((Action)callback).Invoke(state); + private static readonly Action _postAsyncCallbackAdapter = (callback, state) => ((Action)callback).Invoke(state); + // maximum times the work queues swapped and are processed in a single pass // as completing a task may immediately have write data to put on the network // otherwise it needs to wait till the next pass of the libuv loop - private const int _maxLoops = 8; - - private static readonly Action _postCallbackAdapter = (callback, state) => ((Action)callback).Invoke(state); - private static readonly Action _postAsyncCallbackAdapter = (callback, state) => ((Action)callback).Invoke(state); + private readonly int _maxLoops = 8; private readonly KestrelEngine _engine; private readonly IApplicationLifetime _appLifetime; @@ -69,6 +69,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal ConnectionManager = new ConnectionManager(this, _threadPool); } + // For testing + internal KestrelThread(KestrelEngine engine, int maxLoops) + : this(engine) + { + _maxLoops = maxLoops; + } + public UvLoopHandle Loop { get { return _loop; } } public MemoryPool Memory { get; } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/SocketOutputTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/SocketOutputTests.cs index e180dc77a3..2f16107a8a 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/SocketOutputTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/SocketOutputTests.cs @@ -26,9 +26,10 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var mockLibuv = new MockLibuv(); using (var kestrelEngine = new KestrelEngine(mockLibuv, new TestServiceContext())) { - kestrelEngine.Start(count: 1); + var kestrelThread = new KestrelThread(kestrelEngine, maxLoops: 1); + kestrelEngine.Threads.Add(kestrelThread); + await kestrelThread.StartAsync(); - var kestrelThread = kestrelEngine.Threads[0]; var socket = new MockSocket(mockLibuv, kestrelThread.Loop.ThreadId, new TestKestrelTrace()); var trace = new KestrelTrace(new TestKestrelTrace()); var ltp = new SynchronousThreadPool(); @@ -70,9 +71,10 @@ namespace Microsoft.AspNetCore.Server.KestrelTests using (var kestrelEngine = new KestrelEngine(mockLibuv, new TestServiceContext())) { - kestrelEngine.Start(count: 1); + var kestrelThread = new KestrelThread(kestrelEngine, maxLoops: 1); + kestrelEngine.Threads.Add(kestrelThread); + await kestrelThread.StartAsync(); - var kestrelThread = kestrelEngine.Threads[0]; var socket = new MockSocket(mockLibuv, kestrelThread.Loop.ThreadId, new TestKestrelTrace()); var trace = new KestrelTrace(new TestKestrelTrace()); var ltp = new SynchronousThreadPool(); @@ -141,9 +143,10 @@ namespace Microsoft.AspNetCore.Server.KestrelTests using (var kestrelEngine = new KestrelEngine(mockLibuv, new TestServiceContext())) { - kestrelEngine.Start(count: 1); + var kestrelThread = new KestrelThread(kestrelEngine, maxLoops: 1); + kestrelEngine.Threads.Add(kestrelThread); + await kestrelThread.StartAsync(); - var kestrelThread = kestrelEngine.Threads[0]; var socket = new MockSocket(mockLibuv, kestrelThread.Loop.ThreadId, new TestKestrelTrace()); var trace = new KestrelTrace(new TestKestrelTrace()); var ltp = new SynchronousThreadPool(); @@ -223,9 +226,10 @@ namespace Microsoft.AspNetCore.Server.KestrelTests using (var kestrelEngine = new KestrelEngine(mockLibuv, new TestServiceContext())) { - kestrelEngine.Start(count: 1); + var kestrelThread = new KestrelThread(kestrelEngine, maxLoops: 1); + kestrelEngine.Threads.Add(kestrelThread); + await kestrelThread.StartAsync(); - var kestrelThread = kestrelEngine.Threads[0]; var socket = new MockSocket(mockLibuv, kestrelThread.Loop.ThreadId, new TestKestrelTrace()); var trace = new KestrelTrace(new TestKestrelTrace()); var ltp = new SynchronousThreadPool(); @@ -339,9 +343,10 @@ namespace Microsoft.AspNetCore.Server.KestrelTests using (var kestrelEngine = new KestrelEngine(mockLibuv, new TestServiceContext())) { - kestrelEngine.Start(count: 1); + var kestrelThread = new KestrelThread(kestrelEngine, maxLoops: 1); + kestrelEngine.Threads.Add(kestrelThread); + await kestrelThread.StartAsync(); - var kestrelThread = kestrelEngine.Threads[0]; var socket = new MockSocket(mockLibuv, kestrelThread.Loop.ThreadId, new TestKestrelTrace()); var trace = new KestrelTrace(new TestKestrelTrace()); var ltp = new SynchronousThreadPool(); @@ -431,9 +436,10 @@ namespace Microsoft.AspNetCore.Server.KestrelTests using (var kestrelEngine = new KestrelEngine(mockLibuv, new TestServiceContext())) { - kestrelEngine.Start(count: 1); + var kestrelThread = new KestrelThread(kestrelEngine, maxLoops: 1); + kestrelEngine.Threads.Add(kestrelThread); + await kestrelThread.StartAsync(); - var kestrelThread = kestrelEngine.Threads[0]; var socket = new MockSocket(mockLibuv, kestrelThread.Loop.ThreadId, new TestKestrelTrace()); var trace = new KestrelTrace(new TestKestrelTrace()); var ltp = new SynchronousThreadPool(); @@ -509,9 +515,10 @@ namespace Microsoft.AspNetCore.Server.KestrelTests using (var kestrelEngine = new KestrelEngine(mockLibuv, new TestServiceContext())) { - kestrelEngine.Start(count: 1); + var kestrelThread = new KestrelThread(kestrelEngine, maxLoops: 1); + kestrelEngine.Threads.Add(kestrelThread); + await kestrelThread.StartAsync(); - var kestrelThread = kestrelEngine.Threads[0]; var socket = new MockSocket(mockLibuv, kestrelThread.Loop.ThreadId, new TestKestrelTrace()); var trace = new KestrelTrace(new TestKestrelTrace()); var ltp = new SynchronousThreadPool(); @@ -560,9 +567,10 @@ namespace Microsoft.AspNetCore.Server.KestrelTests using (var kestrelEngine = new KestrelEngine(mockLibuv, new TestServiceContext())) { - kestrelEngine.Start(count: 1); + var kestrelThread = new KestrelThread(kestrelEngine, maxLoops: 1); + kestrelEngine.Threads.Add(kestrelThread); + await kestrelThread.StartAsync(); - var kestrelThread = kestrelEngine.Threads[0]; var socket = new MockSocket(mockLibuv, kestrelThread.Loop.ThreadId, new TestKestrelTrace()); var trace = new KestrelTrace(new TestKestrelTrace()); var ltp = new SynchronousThreadPool(); @@ -630,9 +638,10 @@ namespace Microsoft.AspNetCore.Server.KestrelTests using (var kestrelEngine = new KestrelEngine(mockLibuv, new TestServiceContext())) { - kestrelEngine.Start(count: 1); + var kestrelThread = new KestrelThread(kestrelEngine, maxLoops: 1); + kestrelEngine.Threads.Add(kestrelThread); + await kestrelThread.StartAsync(); - var kestrelThread = kestrelEngine.Threads[0]; var socket = new MockSocket(mockLibuv, kestrelThread.Loop.ThreadId, new TestKestrelTrace()); var trace = new KestrelTrace(new TestKestrelTrace()); var ltp = new SynchronousThreadPool(); @@ -675,9 +684,10 @@ namespace Microsoft.AspNetCore.Server.KestrelTests using (var kestrelEngine = new KestrelEngine(mockLibuv, new TestServiceContext())) { - kestrelEngine.Start(count: 1); + var kestrelThread = new KestrelThread(kestrelEngine, maxLoops: 1); + kestrelEngine.Threads.Add(kestrelThread); + await kestrelThread.StartAsync(); - var kestrelThread = kestrelEngine.Threads[0]; var socket = new MockSocket(mockLibuv, kestrelThread.Loop.ThreadId, new TestKestrelTrace()); var trace = new KestrelTrace(new TestKestrelTrace()); var ltp = new SynchronousThreadPool(); diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockLibuv.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockLibuv.cs index a2e34385ad..fcdf349003 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockLibuv.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockLibuv.cs @@ -16,6 +16,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests.TestHelpers private readonly object _postLock = new object(); private TaskCompletionSource _onPostTcs = new TaskCompletionSource(); private bool _completedOnPostTcs; + private bool _sendCalled; private bool _stopLoop; private readonly ManualResetEventSlim _loopWh = new ManualResetEventSlim(); @@ -47,6 +48,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests.TestHelpers PostCount++; + _sendCalled = true; _loopWh.Set(); } @@ -67,23 +69,29 @@ namespace Microsoft.AspNetCore.Server.KestrelTests.TestHelpers { _loopWh.Wait(); KestrelThreadBlocker.Wait(); - TaskCompletionSource onPostTcs; + TaskCompletionSource onPostTcs = null; lock (_postLock) { + _sendCalled = false; _loopWh.Reset(); _onPost(_postHandle.InternalGetHandle()); - // Ensure any subsequent calls to uv_async_send - // create a new _onPostTcs to be completed. - onPostTcs = _onPostTcs; - _completedOnPostTcs = true; + // Allow the loop to be run again before completing + // _onPostTcs given a nested uv_async_send call. + if (!_sendCalled) + { + // Ensure any subsequent calls to uv_async_send + // create a new _onPostTcs to be completed. + _completedOnPostTcs = true; + onPostTcs = _onPostTcs; + } } // Calling TrySetResult outside the lock to avoid deadlock // when the code attempts to call uv_async_send after awaiting // OnPostTask. - onPostTcs.TrySetResult(null); + onPostTcs?.TrySetResult(null); } return 0; From bfa10db25837c9b5aee1f96235ed484a410ccd76 Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Mon, 29 Aug 2016 17:18:35 -0700 Subject: [PATCH 0871/1662] Run functional tests sequentially to mitigate flakiness on OS X. --- .../Properties/AssemblyInfo.cs | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/Properties/AssemblyInfo.cs diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/Properties/AssemblyInfo.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/Properties/AssemblyInfo.cs new file mode 100644 index 0000000000..b1fa884228 --- /dev/null +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/Properties/AssemblyInfo.cs @@ -0,0 +1,3 @@ +using Xunit; + +[assembly: CollectionBehavior(CollectionBehavior.CollectionPerAssembly)] \ No newline at end of file From 1ecef8094a11614b4c4b79485f9859e5aa34dd95 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Wed, 24 Aug 2016 17:09:34 -0700 Subject: [PATCH 0872/1662] Make Kestrel's response buffer limit configurable --- .../Internal/Http/SocketOutput.cs | 27 ++- .../KestrelServerLimits.cs | 30 +++ .../KestrelServerLimitsTests.cs | 29 +++ .../SocketOutputTests.cs | 229 +++++++++++++++--- .../TestHelpers/MockConnection.cs | 19 +- 5 files changed, 274 insertions(+), 60 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/SocketOutput.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/SocketOutput.cs index d3064e27e9..8a3f9e5890 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/SocketOutput.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/SocketOutput.cs @@ -15,7 +15,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http public class SocketOutput : ISocketOutput { private const int _maxPendingWrites = 3; - private const int _maxBytesPreCompleted = 65536; // Well behaved WriteAsync users should await returned task, so there is no need to allocate more per connection by default private const int _initialTaskQueues = 1; private const int _maxPooledWriteContexts = 32; @@ -26,6 +25,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http private readonly KestrelThread _thread; private readonly UvStreamHandle _socket; private readonly Connection _connection; + private readonly long? _maxBytesPreCompleted; private readonly string _connectionId; private readonly IKestrelTrace _log; private readonly IThreadPool _threadPool; @@ -51,7 +51,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http private bool _postingWrite = false; private bool _cancelled = false; - private int _numBytesPreCompleted = 0; + private long _numBytesPreCompleted = 0; private Exception _lastWriteError; private WriteContext _nextWriteContext; private readonly Queue _tasksPending; @@ -75,6 +75,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _tasksPending = new Queue(_initialTaskQueues); _writeContextPool = new Queue(_maxPooledWriteContexts); _writeReqPool = thread.WriteReqPool; + _maxBytesPreCompleted = connection.ServerOptions.Limits.MaxResponseBufferSize; _head = thread.Memory.Lease(); _tail = _head; @@ -146,9 +147,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _nextWriteContext.SocketDisconnect = true; } - if (_lastWriteError == null && - _tasksPending.Count == 0 && - _numBytesPreCompleted + buffer.Count <= _maxBytesPreCompleted) + if (!_maxBytesPreCompleted.HasValue || _numBytesPreCompleted + buffer.Count <= _maxBytesPreCompleted.Value) { // Complete the write task immediately if all previous write tasks have been completed, // the buffers haven't grown too large, and the last write to the socket succeeded. @@ -403,7 +402,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } } - private void CompleteNextWrite(ref int bytesLeftToBuffer) + private void CompleteNextWrite(ref long bytesLeftToBuffer) { // Called inside _contextLock var waitingTask = _tasksPending.Dequeue(); @@ -441,10 +440,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http private void CompleteFinishedWrites(int status) { + if (!_maxBytesPreCompleted.HasValue) + { + Debug.Assert(_tasksPending.Count == 0); + return; + } + // Called inside _contextLock // bytesLeftToBuffer can be greater than _maxBytesPreCompleted // This allows large writes to complete once they've actually finished. - var bytesLeftToBuffer = _maxBytesPreCompleted - _numBytesPreCompleted; + var bytesLeftToBuffer = _maxBytesPreCompleted.Value - _numBytesPreCompleted; while (_tasksPending.Count > 0 && (_tasksPending.Peek().BytesToWrite) <= bytesLeftToBuffer) { @@ -454,8 +459,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http private void CompleteAllWrites() { + if (!_maxBytesPreCompleted.HasValue) + { + Debug.Assert(_tasksPending.Count == 0); + return; + } + // Called inside _contextLock - var bytesLeftToBuffer = _maxBytesPreCompleted - _numBytesPreCompleted; + var bytesLeftToBuffer = _maxBytesPreCompleted.Value - _numBytesPreCompleted; while (_tasksPending.Count > 0) { CompleteNextWrite(ref bytesLeftToBuffer); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServerLimits.cs b/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServerLimits.cs index d59bcd75e9..6cfac04635 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServerLimits.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServerLimits.cs @@ -7,6 +7,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel { public class KestrelServerLimits { + // Matches the non-configurable default response buffer size for Kestrel in 1.0.0 + private long? _maxResponseBufferSize = 64 * 1024; + // Matches the default client_max_body_size in nginx. Also large enough that most requests // should be under the limit. private long? _maxRequestBufferSize = 1024 * 1024; @@ -20,6 +23,33 @@ namespace Microsoft.AspNetCore.Server.Kestrel // Matches the default LimitRequestFields in Apache httpd. private int _maxRequestHeaderCount = 100; + /// + /// Gets or sets the maximum size of the response buffer before write + /// calls begin to block or return tasks that don't complete until the + /// buffer size drops below the configured limit. + /// + /// + /// When set to null, the size of the response buffer is unlimited. + /// When set to zero, all write calls will block or return tasks that + /// don't complete until the entire response buffer is flushed. + /// Defaults to 65,536 bytes (64 KB). + /// + public long? MaxResponseBufferSize + { + get + { + return _maxResponseBufferSize; + } + set + { + if (value.HasValue && value.Value < 0) + { + throw new ArgumentOutOfRangeException(nameof(value), "Value must be null or a non-negative integer."); + } + _maxResponseBufferSize = value; + } + } + /// /// Gets or sets the maximum size of the request buffer. /// diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerLimitsTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerLimitsTests.cs index 111f97193c..5199a16941 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerLimitsTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerLimitsTests.cs @@ -9,6 +9,35 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { public class KestrelServerLimitsTests { + [Fact] + public void MaxResponseBufferSizeDefault() + { + Assert.Equal(64 * 1024, (new KestrelServerLimits()).MaxResponseBufferSize); + } + + [Theory] + [InlineData((long)-1)] + [InlineData(long.MinValue)] + public void MaxResponseBufferSizeInvalid(long value) + { + Assert.Throws(() => + { + (new KestrelServerLimits()).MaxResponseBufferSize = value; + }); + } + + [Theory] + [InlineData(null)] + [InlineData((long)0)] + [InlineData((long)1)] + [InlineData(long.MaxValue)] + public void MaxResponseBufferSizeValid(long? value) + { + var o = new KestrelServerLimits(); + o.MaxResponseBufferSize = value; + Assert.Equal(value, o.MaxResponseBufferSize); + } + [Fact] public void MaxRequestBufferSizeDefault() { diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/SocketOutputTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/SocketOutputTests.cs index 2f16107a8a..31ae21dbe6 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/SocketOutputTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/SocketOutputTests.cs @@ -5,6 +5,7 @@ using System; using System.Collections.Concurrent; using System.Threading; using System.Threading.Tasks; +using Microsoft.AspNetCore.Server.Kestrel; using Microsoft.AspNetCore.Server.Kestrel.Internal; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; @@ -15,8 +16,43 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { public class SocketOutputTests { - [Fact] - public async Task CanWrite1MB() + public static TheoryData MaxResponseBufferSizeData => new TheoryData + { + new KestrelServerOptions(), + new KestrelServerOptions + { + Limits = { MaxResponseBufferSize = 0 } + }, + new KestrelServerOptions + { + Limits = { MaxResponseBufferSize = 1024 } + }, + new KestrelServerOptions + { + Limits = { MaxResponseBufferSize = 1024 * 1024 } + }, + new KestrelServerOptions + { + Limits = { MaxResponseBufferSize = null } + }, + }; + + public static TheoryData PositiveMaxResponseBufferSizeData => new TheoryData + { + new KestrelServerOptions(), + new KestrelServerOptions + { + Limits = { MaxResponseBufferSize = 1024 } + }, + new KestrelServerOptions + { + Limits = { MaxResponseBufferSize = 1024 * 1024 } + } + }; + + [Theory] + [MemberData(nameof(MaxResponseBufferSizeData))] + public async Task CanWrite1MB(KestrelServerOptions options) { // This test was added because when initially implementing write-behind buffering in // SocketOutput, the write callback would never be invoked for writes larger than @@ -33,10 +69,10 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var socket = new MockSocket(mockLibuv, kestrelThread.Loop.ThreadId, new TestKestrelTrace()); var trace = new KestrelTrace(new TestKestrelTrace()); var ltp = new SynchronousThreadPool(); - var socketOutput = new SocketOutput(kestrelThread, socket, new MockConnection(), "0", trace, ltp); + var socketOutput = new SocketOutput(kestrelThread, socket, new MockConnection(options), "0", trace, ltp); - // I doubt _maxBytesPreCompleted will ever be over a MB. If it is, we should change this test. - var bufferSize = 1048576; + // At least one run of this test should have a MaxResponseBufferSize < 1 MB. + var bufferSize = 1024 * 1024; var buffer = new ArraySegment(new byte[bufferSize], 0, bufferSize); // Act @@ -53,10 +89,8 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } [Fact] - public async Task WritesDontCompleteImmediatelyWhenTooManyBytesAreAlreadyBuffered() + public async Task NullMaxResponseBufferSizeAllowsUnlimitedBuffer() { - // This should match _maxBytesPreCompleted in SocketOutput - var maxBytesPreCompleted = 65536; var completeQueue = new ConcurrentQueue>(); // Arrange @@ -78,7 +112,121 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var socket = new MockSocket(mockLibuv, kestrelThread.Loop.ThreadId, new TestKestrelTrace()); var trace = new KestrelTrace(new TestKestrelTrace()); var ltp = new SynchronousThreadPool(); - var mockConnection = new MockConnection(); + var options = new KestrelServerOptions { Limits = { MaxResponseBufferSize = null } }; + var socketOutput = new SocketOutput(kestrelThread, socket, new MockConnection(options), "0", trace, ltp); + + // Don't want to allocate anything too huge for perf. This is at least larger than the default buffer. + var bufferSize = 1024 * 1024; + var buffer = new ArraySegment(new byte[bufferSize], 0, bufferSize); + + // Act + var writeTask = socketOutput.WriteAsync(buffer, default(CancellationToken)); + + // Assert + Assert.Equal(TaskStatus.RanToCompletion, writeTask.Status); + + // Cleanup + var cleanupTask = socketOutput.WriteAsync( + default(ArraySegment), default(CancellationToken), socketDisconnect: true); + + // Wait for all writes to complete so the completeQueue isn't modified during enumeration. + await mockLibuv.OnPostTask; + + foreach (var triggerCompleted in completeQueue) + { + triggerCompleted(0); + } + } + } + + [Fact] + public async Task ZeroMaxResponseBufferSizeDisablesBuffering() + { + var completeQueue = new ConcurrentQueue>(); + + // Arrange + var mockLibuv = new MockLibuv + { + OnWrite = (socket, buffers, triggerCompleted) => + { + completeQueue.Enqueue(triggerCompleted); + return 0; + } + }; + + using (var kestrelEngine = new KestrelEngine(mockLibuv, new TestServiceContext())) + { + var kestrelThread = new KestrelThread(kestrelEngine, maxLoops: 1); + kestrelEngine.Threads.Add(kestrelThread); + await kestrelThread.StartAsync(); + + var socket = new MockSocket(mockLibuv, kestrelThread.Loop.ThreadId, new TestKestrelTrace()); + var trace = new KestrelTrace(new TestKestrelTrace()); + var ltp = new SynchronousThreadPool(); + var options = new KestrelServerOptions { Limits = { MaxResponseBufferSize = 0 } }; + var socketOutput = new SocketOutput(kestrelThread, socket, new MockConnection(options), "0", trace, ltp); + + var bufferSize = 1; + var buffer = new ArraySegment(new byte[bufferSize], 0, bufferSize); + + // Act + var writeTask = socketOutput.WriteAsync(buffer, default(CancellationToken)); + + // Assert + Assert.False(writeTask.IsCompleted); + + // Act + await mockLibuv.OnPostTask; + + // Finishing the write should allow the task to complete. + Action triggerNextCompleted; + Assert.True(completeQueue.TryDequeue(out triggerNextCompleted)); + triggerNextCompleted(0); + + // Assert + Assert.Equal(TaskStatus.RanToCompletion, writeTask.Status); + + // Cleanup + var cleanupTask = socketOutput.WriteAsync( + default(ArraySegment), default(CancellationToken), socketDisconnect: true); + + // Wait for all writes to complete so the completeQueue isn't modified during enumeration. + await mockLibuv.OnPostTask; + + foreach (var triggerCompleted in completeQueue) + { + triggerCompleted(0); + } + } + } + + [Theory] + [MemberData(nameof(PositiveMaxResponseBufferSizeData))] + public async Task WritesDontCompleteImmediatelyWhenTooManyBytesAreAlreadyBuffered(KestrelServerOptions options) + { + var maxBytesPreCompleted = (int)options.Limits.MaxResponseBufferSize.Value; + var completeQueue = new ConcurrentQueue>(); + + // Arrange + var mockLibuv = new MockLibuv + { + OnWrite = (socket, buffers, triggerCompleted) => + { + completeQueue.Enqueue(triggerCompleted); + return 0; + } + }; + + using (var kestrelEngine = new KestrelEngine(mockLibuv, new TestServiceContext())) + { + var kestrelThread = new KestrelThread(kestrelEngine, maxLoops: 1); + kestrelEngine.Threads.Add(kestrelThread); + await kestrelThread.StartAsync(); + + var socket = new MockSocket(mockLibuv, kestrelThread.Loop.ThreadId, new TestKestrelTrace()); + var trace = new KestrelTrace(new TestKestrelTrace()); + var ltp = new SynchronousThreadPool(); + var mockConnection = new MockConnection(options); var socketOutput = new SocketOutput(kestrelThread, socket, mockConnection, "0", trace, ltp); var bufferSize = maxBytesPreCompleted; @@ -122,11 +270,11 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } } - [Fact] - public async Task WritesDontCompleteImmediatelyWhenTooManyBytesIncludingNonImmediateAreAlreadyBuffered() + [Theory] + [MemberData(nameof(PositiveMaxResponseBufferSizeData))] + public async Task WritesDontCompleteImmediatelyWhenTooManyBytesIncludingNonImmediateAreAlreadyBuffered(KestrelServerOptions options) { - // This should match _maxBytesPreCompleted in SocketOutput - var maxBytesPreCompleted = 65536; + var maxBytesPreCompleted = (int)options.Limits.MaxResponseBufferSize.Value; var completeQueue = new ConcurrentQueue>(); var writeRequested = false; @@ -150,7 +298,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var socket = new MockSocket(mockLibuv, kestrelThread.Loop.ThreadId, new TestKestrelTrace()); var trace = new KestrelTrace(new TestKestrelTrace()); var ltp = new SynchronousThreadPool(); - var mockConnection = new MockConnection(); + var mockConnection = new MockConnection(options); var socketOutput = new SocketOutput(kestrelThread, socket, mockConnection, "0", trace, ltp); var bufferSize = maxBytesPreCompleted / 2; @@ -207,11 +355,11 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } } - [Fact] - public async Task OnlyWritesRequestingCancellationAreErroredOnCancellation() + [Theory] + [MemberData(nameof(PositiveMaxResponseBufferSizeData))] + public async Task OnlyWritesRequestingCancellationAreErroredOnCancellation(KestrelServerOptions options) { - // This should match _maxBytesPreCompleted in SocketOutput - var maxBytesPreCompleted = 65536; + var maxBytesPreCompleted = (int)options.Limits.MaxResponseBufferSize.Value; var completeQueue = new ConcurrentQueue>(); // Arrange @@ -234,7 +382,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var trace = new KestrelTrace(new TestKestrelTrace()); var ltp = new SynchronousThreadPool(); - using (var mockConnection = new MockConnection()) + using (var mockConnection = new MockConnection(options)) { ISocketOutput socketOutput = new SocketOutput(kestrelThread, socket, mockConnection, "0", trace, ltp); @@ -324,11 +472,11 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } } - [Fact] - public async Task FailedWriteCompletesOrCancelsAllPendingTasks() + [Theory] + [MemberData(nameof(PositiveMaxResponseBufferSizeData))] + public async Task FailedWriteCompletesOrCancelsAllPendingTasks(KestrelServerOptions options) { - // This should match _maxBytesPreCompleted in SocketOutput - var maxBytesPreCompleted = 65536; + var maxBytesPreCompleted = (int)options.Limits.MaxResponseBufferSize.Value; var completeQueue = new ConcurrentQueue>(); // Arrange @@ -351,7 +499,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var trace = new KestrelTrace(new TestKestrelTrace()); var ltp = new SynchronousThreadPool(); - using (var mockConnection = new MockConnection()) + using (var mockConnection = new MockConnection(options)) { var abortedSource = mockConnection.RequestAbortedSource; ISocketOutput socketOutput = new SocketOutput(kestrelThread, socket, mockConnection, "0", trace, ltp); @@ -414,11 +562,11 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } } - [Fact] - public async Task WritesDontGetCompletedTooQuickly() + [Theory] + [MemberData(nameof(PositiveMaxResponseBufferSizeData))] + public async Task WritesDontGetCompletedTooQuickly(KestrelServerOptions options) { - // This should match _maxBytesPreCompleted in SocketOutput - var maxBytesPreCompleted = 65536; + var maxBytesPreCompleted = (int)options.Limits.MaxResponseBufferSize.Value; var completeQueue = new ConcurrentQueue>(); var writeCalled = false; @@ -443,7 +591,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var socket = new MockSocket(mockLibuv, kestrelThread.Loop.ThreadId, new TestKestrelTrace()); var trace = new KestrelTrace(new TestKestrelTrace()); var ltp = new SynchronousThreadPool(); - var mockConnection = new MockConnection(); + var mockConnection = new MockConnection(options); var socketOutput = new SocketOutput(kestrelThread, socket, mockConnection, "0", trace, ltp); var bufferSize = maxBytesPreCompleted; @@ -498,8 +646,9 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } } - [Fact] - public async Task ProducingStartAndProducingCompleteCanBeUsedDirectly() + [Theory] + [MemberData(nameof(MaxResponseBufferSizeData))] + public async Task ProducingStartAndProducingCompleteCanBeUsedDirectly(KestrelServerOptions options) { int nBuffers = 0; @@ -522,7 +671,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var socket = new MockSocket(mockLibuv, kestrelThread.Loop.ThreadId, new TestKestrelTrace()); var trace = new KestrelTrace(new TestKestrelTrace()); var ltp = new SynchronousThreadPool(); - var socketOutput = new SocketOutput(kestrelThread, socket, new MockConnection(), "0", trace, ltp); + var socketOutput = new SocketOutput(kestrelThread, socket, new MockConnection(options), "0", trace, ltp); // block 1 var start = socketOutput.ProducingStart(); @@ -549,8 +698,9 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } } - [Fact] - public async Task OnlyAllowsUpToThreeConcurrentWrites() + [Theory] + [MemberData(nameof(MaxResponseBufferSizeData))] + public async Task OnlyAllowsUpToThreeConcurrentWrites(KestrelServerOptions options) { var writeCalled = false; var completeQueue = new ConcurrentQueue>(); @@ -574,7 +724,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var socket = new MockSocket(mockLibuv, kestrelThread.Loop.ThreadId, new TestKestrelTrace()); var trace = new KestrelTrace(new TestKestrelTrace()); var ltp = new SynchronousThreadPool(); - var mockConnection = new MockConnection(); + var mockConnection = new MockConnection(options); var socketOutput = new SocketOutput(kestrelThread, socket, mockConnection, "0", trace, ltp); var buffer = new ArraySegment(new byte[1]); @@ -619,8 +769,9 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } } - [Fact] - public async Task WritesAreAggregated() + [Theory] + [MemberData(nameof(MaxResponseBufferSizeData))] + public async Task WritesAreAggregated(KestrelServerOptions options) { var writeCalled = false; var writeCount = 0; @@ -645,7 +796,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var socket = new MockSocket(mockLibuv, kestrelThread.Loop.ThreadId, new TestKestrelTrace()); var trace = new KestrelTrace(new TestKestrelTrace()); var ltp = new SynchronousThreadPool(); - var socketOutput = new SocketOutput(kestrelThread, socket, new MockConnection(), "0", trace, ltp); + var socketOutput = new SocketOutput(kestrelThread, socket, new MockConnection(new KestrelServerOptions()), "0", trace, ltp); mockLibuv.KestrelThreadBlocker.Reset(); @@ -691,7 +842,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var socket = new MockSocket(mockLibuv, kestrelThread.Loop.ThreadId, new TestKestrelTrace()); var trace = new KestrelTrace(new TestKestrelTrace()); var ltp = new SynchronousThreadPool(); - var connection = new MockConnection(); + var connection = new MockConnection(new KestrelServerOptions()); var socketOutput = new SocketOutput(kestrelThread, socket, connection, "0", trace, ltp); // Close SocketOutput diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockConnection.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockConnection.cs index 619d4d5b7b..930c1ec6d8 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockConnection.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockConnection.cs @@ -4,25 +4,24 @@ using System; using System.Threading; using System.Threading.Tasks; +using Microsoft.AspNetCore.Server.Kestrel; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; namespace Microsoft.AspNetCore.Server.KestrelTests.TestHelpers { public class MockConnection : Connection, IDisposable { - private TaskCompletionSource _socketClosedTcs = new TaskCompletionSource(); + private readonly TaskCompletionSource _socketClosedTcs = new TaskCompletionSource(); - public MockConnection() + public MockConnection(KestrelServerOptions options) { RequestAbortedSource = new CancellationTokenSource(); + ServerOptions = options; } public override void Abort(Exception error = null) { - if (RequestAbortedSource != null) - { - RequestAbortedSource.Cancel(); - } + RequestAbortedSource?.Cancel(); } public override void OnSocketClosed() @@ -32,13 +31,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests.TestHelpers public CancellationTokenSource RequestAbortedSource { get; } - public Task SocketClosed - { - get - { - return _socketClosedTcs.Task; - } - } + public Task SocketClosed => _socketClosedTcs.Task; public void Dispose() { From 6795ca2f78e6fe2cd1d90b1419677b6f64404cf5 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Wed, 31 Aug 2016 01:17:56 -0700 Subject: [PATCH 0873/1662] Make the char array for utf8 decoding smaller --- .../Internal/Infrastructure/MemoryPoolIteratorExtensions.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolIteratorExtensions.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolIteratorExtensions.cs index dcaf4f0fcf..6bb47c0578 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolIteratorExtensions.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolIteratorExtensions.cs @@ -150,7 +150,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure var decoder = _utf8.GetDecoder(); var length = start.GetLength(end); - var charLength = length * 2; + var charLength = length; + // Worse case is 1 byte = 1 char var chars = new char[charLength]; var charIndex = 0; From 5512516ee8b9cd567ae33d50c109e85350e7a88b Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Thu, 1 Sep 2016 17:18:59 -0700 Subject: [PATCH 0874/1662] Remove commented test. --- .../BadHttpRequestTests.cs | 40 ------------------- 1 file changed, 40 deletions(-) diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/BadHttpRequestTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/BadHttpRequestTests.cs index ee41be7d46..a1d21078d0 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/BadHttpRequestTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/BadHttpRequestTests.cs @@ -83,46 +83,6 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } } - // TODO: remove test once people agree to change this behavior - /* - [Theory] - [InlineData(" ")] - [InlineData("GET ")] - [InlineData("GET / HTTP/1.2\r")] - [InlineData("GET / HTTP/1.0\rA")] - // Bad HTTP Methods (invalid according to RFC) - [InlineData("( ")] - [InlineData(") ")] - [InlineData("< ")] - [InlineData("> ")] - [InlineData("@ ")] - [InlineData(", ")] - [InlineData("; ")] - [InlineData(": ")] - [InlineData("\\ ")] - [InlineData("\" ")] - [InlineData("/ ")] - [InlineData("[ ")] - [InlineData("] ")] - [InlineData("? ")] - [InlineData("= ")] - [InlineData("{ ")] - [InlineData("} ")] - [InlineData("get@ ")] - [InlineData("post= ")] - public async Task ServerClosesConnectionAsSoonAsBadRequestLineIsDetected(string request) - { - using (var server = new TestServer(context => TaskUtilities.CompletedTask)) - { - using (var connection = server.CreateConnection()) - { - await connection.SendAll(request); - await ReceiveBadRequestResponse(connection, server.Context.DateHeaderValue); - } - } - } - */ - [Theory] // Missing final CRLF [InlineData("Header-1: value1\r\nHeader-2: value2\r\n")] From 7d1a03f51d64f09371f0ae4dbfb6bc32089f1e37 Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Mon, 29 Aug 2016 17:18:35 -0700 Subject: [PATCH 0875/1662] Serialize functional tests on OS X. --- makefile.shade | 48 +++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 45 insertions(+), 3 deletions(-) diff --git a/makefile.shade b/makefile.shade index a712540a3f..afc4c24b2a 100644 --- a/makefile.shade +++ b/makefile.shade @@ -1,11 +1,53 @@ +use namespace="System.Diagnostics" +use namespace="System.IO" + var VERSION='0.1' var FULL_VERSION='0.1' var AUTHORS='Microsoft' -var kestrelSrcDir='${Path.Combine(Directory.GetCurrentDirectory(), "src/Microsoft.AspNetCore.Server.Kestrel")}' use-standard-lifecycle k-standard-goals custom-goals -#initialize if='Directory.Exists("src")' - exec program='dotnet' commandline='run -p ../../tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode Internal/Http/FrameHeaders.Generated.cs Internal/Http/Frame.Generated.cs' workingdir='${kestrelSrcDir}' +#initialize + @{ + if (Directory.Exists("src")) + { + Exec("dotnet", + commandline: "run -p ../../tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode Internal/Http/FrameHeaders.Generated.cs Internal/Http/Frame.Generated.cs", + workingdir: Path.Combine(Directory.GetCurrentDirectory(), "src/Microsoft.AspNetCore.Server.Kestrel")); + } + + if (IsOSX()) + { + var noParallelTestProjects = Environment.GetEnvironmentVariable("NO_PARALLEL_TEST_PROJECTS") ?? string.Empty; + noParallelTestProjects += ",Microsoft.AspNetCore.Server.Kestrel.FunctionalTests"; + Environment.SetEnvironmentVariable("NO_PARALLEL_TEST_PROJECTS", noParallelTestProjects); + } + } + +functions @{ + bool IsOSX() + { + if (!IsLinux) + { + return false; + } + + var processStartInfo = new ProcessStartInfo + { + FileName = "uname", + RedirectStandardOutput = true, + UseShellExecute = false + }; + var output = string.Empty; + + using (var process = Process.Start(processStartInfo)) + { + output = process.StandardOutput.ReadToEnd(); + process.WaitForExit(); + } + + return output.StartsWith("Darwin"); + } +} \ No newline at end of file From 4dc2a38af247e15430a410dbcfc5dbbfdaa9f08a Mon Sep 17 00:00:00 2001 From: Doug Bunting Date: Sun, 4 Sep 2016 15:49:24 -0700 Subject: [PATCH 0876/1662] Increase .travis.yml consistency between repos - aspnet/Universe#349 - minimize `dotnet` setup time; no need for caching - install packages used in other repos; explicit and avoids issues as (Beta) Trusty image changes --- .travis.yml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.travis.yml b/.travis.yml index 150cf03a06..d7636fa329 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,7 +4,16 @@ dist: trusty addons: apt: packages: + - gettext + - libcurl4-openssl-dev + - libicu-dev + - libssl-dev - libunwind8 + - zlib1g +env: + global: + - DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true + - DOTNET_CLI_TELEMETRY_OPTOUT: 1 mono: - 4.0.5 os: From 19f8958fa84b7caa15c8727f7379cb069298c910 Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Tue, 30 Aug 2016 15:57:18 -0700 Subject: [PATCH 0877/1662] Move TestServer to shared directory. --- KestrelHttpServer.sln | 8 ++++++++ .../Properties/AssemblyInfo.cs | 1 + .../project.json | 1 + .../ChunkedRequestTests.cs | 1 + .../ChunkedResponseTests.cs | 2 +- .../ConnectionFilterTests.cs | 1 + .../ConnectionTests.cs | 1 + .../DateHeaderValueManagerTests.cs | 2 +- .../DefaultHeaderTests.cs | 3 +-- .../FrameTests.cs | 1 + .../KestrelServerTests.cs | 2 +- .../LoggingThreadPoolTests.cs | 3 +-- .../RequestTargetProcessingTests.cs | 1 + .../SocketInputTests.cs | 1 + .../SocketOutputTests.cs | 1 + .../StreamSocketOutputTests.cs | 2 +- .../TestHelpers/PassThroughConnectionFilter.cs | 1 + .../Microsoft.AspNetCore.Server.KestrelTests/TestInput.cs | 1 + .../DummyApplication.cs | 2 +- .../LifetimeNotImplemented.cs | 2 +- .../TestHelpers => shared}/MockSystemClock.cs | 2 +- .../TestHelpers => shared}/TestApplicationErrorLogger.cs | 3 +-- .../TestHelpers => shared}/TestKestrelTrace.cs | 2 +- .../TestServer.cs | 3 +-- .../TestServiceContext.cs | 3 +-- 25 files changed, 32 insertions(+), 18 deletions(-) rename test/{Microsoft.AspNetCore.Server.KestrelTests => shared}/DummyApplication.cs (95%) rename test/{Microsoft.AspNetCore.Server.KestrelTests => shared}/LifetimeNotImplemented.cs (94%) rename test/{Microsoft.AspNetCore.Server.KestrelTests/TestHelpers => shared}/MockSystemClock.cs (91%) rename test/{Microsoft.AspNetCore.Server.KestrelTests/TestHelpers => shared}/TestApplicationErrorLogger.cs (94%) rename test/{Microsoft.AspNetCore.Server.KestrelTests/TestHelpers => shared}/TestKestrelTrace.cs (95%) rename test/{Microsoft.AspNetCore.Server.KestrelTests => shared}/TestServer.cs (95%) rename test/{Microsoft.AspNetCore.Server.KestrelTests => shared}/TestServiceContext.cs (93%) diff --git a/KestrelHttpServer.sln b/KestrelHttpServer.sln index 7615861212..1a5cda8a81 100644 --- a/KestrelHttpServer.sln +++ b/KestrelHttpServer.sln @@ -34,7 +34,15 @@ Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNetCore.Server EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "shared", "shared", "{0EF2ACDF-012F-4472-A13A-4272419E2903}" ProjectSection(SolutionItems) = preProject + test\shared\DummyApplication.cs = test\shared\DummyApplication.cs test\shared\HttpClientSlim.cs = test\shared\HttpClientSlim.cs + test\shared\LifetimeNotImplemented.cs = test\shared\LifetimeNotImplemented.cs + test\shared\MockSystemClock.cs = test\shared\MockSystemClock.cs + test\shared\TestApplicationErrorLogger.cs = test\shared\TestApplicationErrorLogger.cs + test\shared\TestConnection.cs = test\shared\TestConnection.cs + test\shared\TestKestrelTrace.cs = test\shared\TestKestrelTrace.cs + test\shared\TestServer.cs = test\shared\TestServer.cs + test\shared\TestServiceContext.cs = test\shared\TestServiceContext.cs EndProjectSection EndProject Global diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Properties/AssemblyInfo.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Properties/AssemblyInfo.cs index 603dc45398..8989a4b649 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Properties/AssemblyInfo.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Properties/AssemblyInfo.cs @@ -5,6 +5,7 @@ using System.Reflection; using System.Resources; using System.Runtime.CompilerServices; +[assembly: InternalsVisibleTo("Microsoft.AspNetCore.Server.Kestrel.FunctionalTests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")] [assembly: InternalsVisibleTo("Microsoft.AspNetCore.Server.KestrelTests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")] [assembly: AssemblyMetadata("Serviceable", "True")] [assembly: NeutralResourcesLanguage("en-us")] diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json index 07b88977b3..e90217c86f 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json @@ -36,6 +36,7 @@ "../shared/**/*.cs" ] }, + "keyFile": "../../tools/Key.snk", "copyToOutput": { "include": "TestResources/testCert.pfx" } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedRequestTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedRequestTests.cs index 476cddae2c..6ef64cf30e 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedRequestTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedRequestTests.cs @@ -7,6 +7,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Testing; using Xunit; namespace Microsoft.AspNetCore.Server.KestrelTests diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedResponseTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedResponseTests.cs index 8e9d12e4dd..d4936ba0c9 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedResponseTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedResponseTests.cs @@ -5,7 +5,7 @@ using System; using System.Text; using System.Threading; using System.Threading.Tasks; -using Microsoft.AspNetCore.Server.Kestrel; +using Microsoft.AspNetCore.Testing; using Xunit; namespace Microsoft.AspNetCore.Server.KestrelTests diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionFilterTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionFilterTests.cs index 965a427b97..d2a3b7cc22 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionFilterTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionFilterTests.cs @@ -6,6 +6,7 @@ using System.IO; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Server.Kestrel.Filter; +using Microsoft.AspNetCore.Testing; using Xunit; namespace Microsoft.AspNetCore.Server.KestrelTests diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionTests.cs index cdcacc071c..d6fdadf968 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionTests.cs @@ -6,6 +6,7 @@ using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; using Microsoft.AspNetCore.Server.KestrelTests.TestHelpers; +using Microsoft.AspNetCore.Testing; using Xunit; namespace Microsoft.AspNetCore.Server.KestrelTests diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/DateHeaderValueManagerTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/DateHeaderValueManagerTests.cs index 0d3e4dc133..ddfce0d3a6 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/DateHeaderValueManagerTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/DateHeaderValueManagerTests.cs @@ -5,7 +5,7 @@ using System; using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; -using Microsoft.AspNetCore.Server.KestrelTests.TestHelpers; +using Microsoft.AspNetCore.Testing; using Xunit; namespace Microsoft.AspNetCore.Server.KestrelTests diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/DefaultHeaderTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/DefaultHeaderTests.cs index 964345b48a..127aa2b221 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/DefaultHeaderTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/DefaultHeaderTests.cs @@ -2,9 +2,8 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Threading.Tasks; -using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Server.Kestrel; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; +using Microsoft.AspNetCore.Testing; using Xunit; namespace Microsoft.AspNetCore.Server.KestrelTests diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs index 5a0492ea19..ecd438a5c5 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs @@ -10,6 +10,7 @@ using Microsoft.AspNetCore.Server.Kestrel.Internal; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.AspNetCore.Server.KestrelTests.TestHelpers; +using Microsoft.AspNetCore.Testing; using Xunit; namespace Microsoft.AspNetCore.Server.KestrelTests diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerTests.cs index ae4f63828d..c7edfe82f9 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerTests.cs @@ -2,11 +2,11 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.Reflection; using Microsoft.AspNetCore.Hosting.Server; using Microsoft.AspNetCore.Hosting.Server.Features; using Microsoft.AspNetCore.Server.Kestrel; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; +using Microsoft.AspNetCore.Testing; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using Moq; diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/LoggingThreadPoolTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/LoggingThreadPoolTests.cs index 431e79b119..65f37daf44 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/LoggingThreadPoolTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/LoggingThreadPoolTests.cs @@ -3,10 +3,9 @@ using System; -using System.Collections.Generic; -using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; +using Microsoft.AspNetCore.Testing; using Xunit; namespace Microsoft.AspNetCore.Server.KestrelTests diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/RequestTargetProcessingTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/RequestTargetProcessingTests.cs index 5c1c25d373..e01610a93d 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/RequestTargetProcessingTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/RequestTargetProcessingTests.cs @@ -4,6 +4,7 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http.Features; +using Microsoft.AspNetCore.Testing; using Xunit; namespace Microsoft.AspNetCore.Server.KestrelTests diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/SocketInputTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/SocketInputTests.cs index ecef0c1538..b2bb528649 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/SocketInputTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/SocketInputTests.cs @@ -7,6 +7,7 @@ using Microsoft.AspNetCore.Server.Kestrel.Internal; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.AspNetCore.Server.KestrelTests.TestHelpers; +using Microsoft.AspNetCore.Testing; using Moq; using Xunit; diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/SocketOutputTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/SocketOutputTests.cs index 31ae21dbe6..bcd15a643c 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/SocketOutputTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/SocketOutputTests.cs @@ -10,6 +10,7 @@ using Microsoft.AspNetCore.Server.Kestrel.Internal; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.AspNetCore.Server.KestrelTests.TestHelpers; +using Microsoft.AspNetCore.Testing; using Xunit; namespace Microsoft.AspNetCore.Server.KestrelTests diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/StreamSocketOutputTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/StreamSocketOutputTests.cs index f01397fc0f..ab8f83e46e 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/StreamSocketOutputTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/StreamSocketOutputTests.cs @@ -3,9 +3,9 @@ using System; using System.IO; -using Microsoft.AspNetCore.Server.Kestrel.Filter; using Microsoft.AspNetCore.Server.Kestrel.Filter.Internal; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; +using Microsoft.AspNetCore.Testing; using Xunit; namespace Microsoft.AspNetCore.Server.KestrelTests diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/PassThroughConnectionFilter.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/PassThroughConnectionFilter.cs index 561609899a..b398021e7d 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/PassThroughConnectionFilter.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/PassThroughConnectionFilter.cs @@ -5,6 +5,7 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Filter; using Microsoft.AspNetCore.Server.Kestrel.Filter.Internal; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; +using Microsoft.AspNetCore.Testing; namespace Microsoft.AspNetCore.Server.KestrelTests { diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestInput.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/TestInput.cs index 955cb088b9..de0edf5020 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/TestInput.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/TestInput.cs @@ -9,6 +9,7 @@ using Microsoft.AspNetCore.Server.Kestrel.Internal; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.AspNetCore.Server.KestrelTests.TestHelpers; +using Microsoft.AspNetCore.Testing; namespace Microsoft.AspNetCore.Server.KestrelTests { diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/DummyApplication.cs b/test/shared/DummyApplication.cs similarity index 95% rename from test/Microsoft.AspNetCore.Server.KestrelTests/DummyApplication.cs rename to test/shared/DummyApplication.cs index 842c1156dd..a4b3eb4b1a 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/DummyApplication.cs +++ b/test/shared/DummyApplication.cs @@ -7,7 +7,7 @@ using Microsoft.AspNetCore.Hosting.Server; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http.Features; -namespace Microsoft.AspNetCore.Server.KestrelTests +namespace Microsoft.AspNetCore.Testing { public class DummyApplication : IHttpApplication { diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/LifetimeNotImplemented.cs b/test/shared/LifetimeNotImplemented.cs similarity index 94% rename from test/Microsoft.AspNetCore.Server.KestrelTests/LifetimeNotImplemented.cs rename to test/shared/LifetimeNotImplemented.cs index feba1c80fd..df5253cc62 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/LifetimeNotImplemented.cs +++ b/test/shared/LifetimeNotImplemented.cs @@ -5,7 +5,7 @@ using System; using System.Threading; using Microsoft.AspNetCore.Hosting; -namespace Microsoft.AspNetCore.Server.KestrelTests +namespace Microsoft.AspNetCore.Testing { public class LifetimeNotImplemented : IApplicationLifetime { diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockSystemClock.cs b/test/shared/MockSystemClock.cs similarity index 91% rename from test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockSystemClock.cs rename to test/shared/MockSystemClock.cs index d18e114f5c..5a903c1f2e 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockSystemClock.cs +++ b/test/shared/MockSystemClock.cs @@ -4,7 +4,7 @@ using System; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; -namespace Microsoft.AspNetCore.Server.KestrelTests.TestHelpers +namespace Microsoft.AspNetCore.Testing { public class MockSystemClock : ISystemClock { diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/TestApplicationErrorLogger.cs b/test/shared/TestApplicationErrorLogger.cs similarity index 94% rename from test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/TestApplicationErrorLogger.cs rename to test/shared/TestApplicationErrorLogger.cs index 419a617407..d2d3731a9d 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/TestApplicationErrorLogger.cs +++ b/test/shared/TestApplicationErrorLogger.cs @@ -2,11 +2,10 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using Microsoft.AspNetCore.Server.Kestrel; using Microsoft.AspNetCore.Server.Kestrel.Internal; using Microsoft.Extensions.Logging; -namespace Microsoft.AspNetCore.Server.KestrelTests +namespace Microsoft.AspNetCore.Testing { public class TestApplicationErrorLogger : ILogger { diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/TestKestrelTrace.cs b/test/shared/TestKestrelTrace.cs similarity index 95% rename from test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/TestKestrelTrace.cs rename to test/shared/TestKestrelTrace.cs index 741ec54a0b..814005d4d1 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/TestKestrelTrace.cs +++ b/test/shared/TestKestrelTrace.cs @@ -1,7 +1,7 @@ using Microsoft.AspNetCore.Server.Kestrel.Internal; using Microsoft.Extensions.Logging; -namespace Microsoft.AspNetCore.Server.KestrelTests +namespace Microsoft.AspNetCore.Testing { public class TestKestrelTrace : KestrelTrace { diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestServer.cs b/test/shared/TestServer.cs similarity index 95% rename from test/Microsoft.AspNetCore.Server.KestrelTests/TestServer.cs rename to test/shared/TestServer.cs index e01d35fa70..738b0b10df 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/TestServer.cs +++ b/test/shared/TestServer.cs @@ -6,9 +6,8 @@ using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Server.Kestrel; using Microsoft.AspNetCore.Server.Kestrel.Internal; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; -using Microsoft.AspNetCore.Testing; -namespace Microsoft.AspNetCore.Server.KestrelTests +namespace Microsoft.AspNetCore.Testing { /// /// Summary description for TestServer diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestServiceContext.cs b/test/shared/TestServiceContext.cs similarity index 93% rename from test/Microsoft.AspNetCore.Server.KestrelTests/TestServiceContext.cs rename to test/shared/TestServiceContext.cs index 10049f461c..9da3e8811b 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/TestServiceContext.cs +++ b/test/shared/TestServiceContext.cs @@ -8,9 +8,8 @@ using Microsoft.AspNetCore.Server.Kestrel.Filter; using Microsoft.AspNetCore.Server.Kestrel.Internal; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; -using Microsoft.AspNetCore.Server.KestrelTests.TestHelpers; -namespace Microsoft.AspNetCore.Server.KestrelTests +namespace Microsoft.AspNetCore.Testing { public class TestServiceContext : ServiceContext { From f2085b196860fd6206bb586bfc41af7cfdb5ddc3 Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Thu, 18 Aug 2016 16:40:46 -0700 Subject: [PATCH 0878/1662] Add keep-alive timeout (#464). --- .../Internal/Http/Connection.cs | 12 +- .../Internal/Http/Frame.cs | 30 ++- .../Internal/Http/IConnectionControl.cs | 1 + .../Internal/Http/MessageBody.cs | 16 ++ .../Internal/Infrastructure/KestrelThread.cs | 19 +- .../Internal/Networking/Libuv.cs | 36 +++ .../Internal/Networking/UvTimerHandle.cs | 57 +++++ .../KestrelServerLimits.cs | 21 ++ .../KeepAliveTimeoutTests.cs | 209 ++++++++++++++++++ .../KestrelServerLimitsTests.cs | 25 ++- .../TestHelpers/MockLibuv.cs | 4 + .../TestInput.cs | 11 +- .../UvTimerHandleTests.cs | 72 ++++++ test/shared/TestConnection.cs | 3 +- 14 files changed, 501 insertions(+), 15 deletions(-) create mode 100644 src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/UvTimerHandle.cs create mode 100644 test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/KeepAliveTimeoutTests.cs create mode 100644 test/Microsoft.AspNetCore.Server.KestrelTests/UvTimerHandleTests.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Connection.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Connection.cs index 53de8bb857..84e70e1811 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Connection.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Connection.cs @@ -2,7 +2,6 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.Diagnostics; using System.IO; using System.Threading; using System.Threading.Tasks; @@ -156,6 +155,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _socketClosedTcs.TrySetResult(null); } + // Called on Libuv thread + public void Tick() + { + _frame.Tick(); + } + private void ApplyConnectionFilter() { if (_filterContext.Connection != _libuvStream) @@ -277,6 +282,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } } + void IConnectionControl.Stop() + { + StopAsync(); + } + private static unsafe string GenerateConnectionId(long id) { // The following routine is ~310% faster than calling long.ToString() on x64 diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs index 7cc160f0ff..ea969d1225 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs @@ -56,7 +56,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http private CancellationTokenSource _abortedCts; private CancellationToken? _manuallySetRequestAbortToken; - protected RequestProcessingStatus _requestProcessingStatus; + private RequestProcessingStatus _requestProcessingStatus; protected bool _keepAlive; private bool _autoChunk; protected Exception _applicationException; @@ -68,6 +68,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http private int _remainingRequestHeadersBytesAllowed; private int _requestHeadersParsed; + private int _secondsSinceLastRequest; + public Frame(ConnectionContext context) : base(context) { @@ -213,10 +215,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } } - public bool HasResponseStarted - { - get { return _requestProcessingStatus == RequestProcessingStatus.ResponseStarted; } - } + public bool HasResponseStarted => _requestProcessingStatus == RequestProcessingStatus.ResponseStarted; protected FrameRequestHeaders FrameRequestHeaders { get; private set; } @@ -1267,6 +1266,25 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http Log.ApplicationError(ConnectionId, ex); } + public void Tick() + { + // we're in between requests and not about to start processing a new one + if (_requestProcessingStatus == RequestProcessingStatus.RequestPending && !SocketInput.IsCompleted) + { + if (_secondsSinceLastRequest > ServerOptions.Limits.KeepAliveTimeout.TotalSeconds) + { + ConnectionControl.Stop(); + } + + _secondsSinceLastRequest++; + } + } + + public void RequestFinished() + { + _secondsSinceLastRequest = 0; + } + protected enum RequestLineStatus { Empty, @@ -1277,7 +1295,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http Done } - protected enum RequestProcessingStatus + private enum RequestProcessingStatus { RequestPending, RequestStarted, diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/IConnectionControl.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/IConnectionControl.cs index fbc181bce3..0c174ca86a 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/IConnectionControl.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/IConnectionControl.cs @@ -8,5 +8,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http void Pause(); void Resume(); void End(ProduceEndType endType); + void Stop(); } } \ No newline at end of file diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/MessageBody.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/MessageBody.cs index 752ddcffb8..1e760bdb5b 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/MessageBody.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/MessageBody.cs @@ -172,6 +172,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var limit = buffer.Array == null ? inputLengthLimit : Math.Min(buffer.Count, inputLengthLimit); if (limit == 0) { + _context.RequestFinished(); return new ValueTask(0); } @@ -182,10 +183,17 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http // .GetAwaiter().GetResult() done by ValueTask if needed var actual = task.Result; _inputLength -= actual; + if (actual == 0) { _context.RejectRequest(RequestRejectionReason.UnexpectedEndOfRequestContent); } + + if (_inputLength == 0) + { + _context.RequestFinished(); + } + return new ValueTask(actual); } else @@ -198,11 +206,17 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { var actual = await task; _inputLength -= actual; + if (actual == 0) { _context.RejectRequest(RequestRejectionReason.UnexpectedEndOfRequestContent); } + if (_inputLength == 0) + { + _context.RequestFinished(); + } + return actual; } } @@ -354,6 +368,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _mode = Mode.Complete; } + _context.RequestFinished(); + return 0; } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/KestrelThread.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/KestrelThread.cs index 6d46aba889..08e5773083 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/KestrelThread.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/KestrelThread.cs @@ -27,12 +27,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal // otherwise it needs to wait till the next pass of the libuv loop private readonly int _maxLoops = 8; + // how often the heartbeat timer will tick connections + private const int _heartbeatMilliseconds = 1000; + private readonly KestrelEngine _engine; private readonly IApplicationLifetime _appLifetime; private readonly Thread _thread; private readonly TaskCompletionSource _threadTcs = new TaskCompletionSource(); private readonly UvLoopHandle _loop; private readonly UvAsyncHandle _post; + private readonly UvTimerHandle _heartbeatTimer; private Queue _workAdding = new Queue(1024); private Queue _workRunning = new Queue(1024); private Queue _closeHandleAdding = new Queue(256); @@ -57,6 +61,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal _post = new UvAsyncHandle(_log); _thread = new Thread(ThreadStart); _thread.Name = "KestrelThread - libuv"; + _heartbeatTimer = new UvTimerHandle(_log); #if !DEBUG // Mark the thread as being as unimportant to keeping the process alive. // Don't do this for debug builds, so we know if the thread isn't terminating. @@ -176,9 +181,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal } } - private void AllowStop() { + _heartbeatTimer.Stop(); _post.Unreference(); } @@ -274,6 +279,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal { _loop.Init(_engine.Libuv); _post.Init(_loop, OnPost, EnqueueCloseHandle); + _heartbeatTimer.Init(_loop, EnqueueCloseHandle); + _heartbeatTimer.Start(OnHeartbeat, timeout: 1000, repeat: 1000); _initCompleted = true; tcs.SetResult(0); } @@ -296,6 +303,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal // run the loop one more time to delete the open handles _post.Reference(); _post.Dispose(); + _heartbeatTimer.Dispose(); // Ensure the Dispose operations complete in the event loop. _loop.Run(); @@ -327,6 +335,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal } while (wasWork && loopsRemaining > 0); } + private void OnHeartbeat(UvTimerHandle timer) + { + Walk(ptr => + { + var handle = UvMemory.FromIntPtr(ptr); + (handle as UvStreamHandle)?.Connection?.Tick(); + }); + } + private bool DoPostWork() { Queue queue; diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/Libuv.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/Libuv.cs index 8901af40e2..9b1fada8f5 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/Libuv.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/Libuv.cs @@ -53,6 +53,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking _uv_tcp_getpeername = NativeMethods.uv_tcp_getpeername; _uv_tcp_getsockname = NativeMethods.uv_tcp_getsockname; _uv_walk = NativeMethods.uv_walk; + _uv_timer_init = NativeMethods.uv_timer_init; + _uv_timer_start = NativeMethods.uv_timer_start; + _uv_timer_stop = NativeMethods.uv_timer_stop; } // Second ctor that doesn't set any fields only to be used by MockLibuv @@ -407,6 +410,30 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking _uv_walk(loop, walk_cb, arg); } + protected Func _uv_timer_init; + unsafe public void timer_init(UvLoopHandle loop, UvTimerHandle handle) + { + loop.Validate(); + handle.Validate(); + ThrowIfErrored(_uv_timer_init(loop, handle)); + } + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + public delegate void uv_timer_cb(IntPtr handle); + protected Func _uv_timer_start; + unsafe public void timer_start(UvTimerHandle handle, uv_timer_cb cb, long timeout, long repeat) + { + handle.Validate(); + ThrowIfErrored(_uv_timer_start(handle, cb, timeout, repeat)); + } + + protected Func _uv_timer_stop; + unsafe public void timer_stop(UvTimerHandle handle) + { + handle.Validate(); + ThrowIfErrored(_uv_timer_stop(handle)); + } + public delegate int uv_tcp_getsockname_func(UvTcpHandle handle, out SockAddr addr, ref int namelen); protected uv_tcp_getsockname_func _uv_tcp_getsockname; public void tcp_getsockname(UvTcpHandle handle, out SockAddr addr, ref int namelen) @@ -604,6 +631,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking [DllImport("libuv", CallingConvention = CallingConvention.Cdecl)] public static extern int uv_walk(UvLoopHandle loop, uv_walk_cb walk_cb, IntPtr arg); + [DllImport("libuv", CallingConvention = CallingConvention.Cdecl)] + unsafe public static extern int uv_timer_init(UvLoopHandle loop, UvTimerHandle handle); + + [DllImport("libuv", CallingConvention = CallingConvention.Cdecl)] + unsafe public static extern int uv_timer_start(UvTimerHandle handle, uv_timer_cb cb, long timeout, long repeat); + + [DllImport("libuv", CallingConvention = CallingConvention.Cdecl)] + unsafe public static extern int uv_timer_stop(UvTimerHandle handle); + [DllImport("WS2_32.dll", CallingConvention = CallingConvention.Winapi)] unsafe public static extern int WSAIoctl( IntPtr socket, diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/UvTimerHandle.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/UvTimerHandle.cs new file mode 100644 index 0000000000..efed9ab59c --- /dev/null +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/UvTimerHandle.cs @@ -0,0 +1,57 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; +using Microsoft.Extensions.Logging; + +namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking +{ + public class UvTimerHandle : UvHandle + { + private readonly static Libuv.uv_timer_cb _uv_timer_cb = UvTimerCb; + + private Action _callback; + + public UvTimerHandle(IKestrelTrace logger) : base(logger) + { + } + + public void Init(UvLoopHandle loop, Action, IntPtr> queueCloseHandle) + { + CreateHandle( + loop.Libuv, + loop.ThreadId, + loop.Libuv.handle_size(Libuv.HandleType.TIMER), + queueCloseHandle); + + _uv.timer_init(loop, this); + } + + public void Start(Action callback, long timeout, long repeat) + { + _callback = callback; + _uv.timer_start(this, _uv_timer_cb, timeout, repeat); + } + + public void Stop() + { + _uv.timer_stop(this); + } + + private static void UvTimerCb(IntPtr handle) + { + var timer = FromIntPtr(handle); + + try + { + timer._callback(timer); + } + catch (Exception ex) + { + timer._log.LogError(0, ex, nameof(UvTimerCb)); + throw; + } + } + } +} diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServerLimits.cs b/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServerLimits.cs index 6cfac04635..7682e015ae 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServerLimits.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServerLimits.cs @@ -23,6 +23,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel // Matches the default LimitRequestFields in Apache httpd. private int _maxRequestHeaderCount = 100; + // Matches the default http.sys keep-alive timouet. + private TimeSpan _keepAliveTimeout = TimeSpan.FromMinutes(2); + /// /// Gets or sets the maximum size of the response buffer before write /// calls begin to block or return tasks that don't complete until the @@ -138,5 +141,23 @@ namespace Microsoft.AspNetCore.Server.Kestrel _maxRequestHeaderCount = value; } } + + /// + /// Gets or sets the keep-alive timeout. + /// + /// + /// Defaults to 2 minutes. Timeout granularity is in seconds. Sub-second values will be rounded to the next second. + /// + public TimeSpan KeepAliveTimeout + { + get + { + return _keepAliveTimeout; + } + set + { + _keepAliveTimeout = TimeSpan.FromSeconds(Math.Ceiling(value.TotalSeconds)); + } + } } } diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/KeepAliveTimeoutTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/KeepAliveTimeoutTests.cs new file mode 100644 index 0000000000..f4bf8ba357 --- /dev/null +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/KeepAliveTimeoutTests.cs @@ -0,0 +1,209 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.IO; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Testing; +using Xunit; + +namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests +{ + public class KeepAliveTimeoutTests + { + private static readonly TimeSpan KeepAliveTimeout = TimeSpan.FromSeconds(10); + private static readonly int LongDelay = (int)TimeSpan.FromSeconds(30).TotalMilliseconds; + private static readonly int ShortDelay = LongDelay / 10; + + [Fact] + public async Task TestKeepAliveTimeout() + { + using (var server = CreateServer()) + { + var tasks = new[] + { + ConnectionClosedWhenKeepAliveTimeoutExpires(server), + ConnectionClosedWhenKeepAliveTimeoutExpiresAfterChunkedRequest(server), + KeepAliveTimeoutResetsBetweenContentLengthRequests(server), + KeepAliveTimeoutResetsBetweenChunkedRequests(server), + KeepAliveTimeoutNotTriggeredMidContentLengthRequest(server), + KeepAliveTimeoutNotTriggeredMidChunkedRequest(server), + ConnectionTimesOutWhenOpenedButNoRequestSent(server) + }; + + await Task.WhenAll(tasks); + } + } + + private async Task ConnectionClosedWhenKeepAliveTimeoutExpires(TestServer server) + { + using (var connection = new TestConnection(server.Port)) + { + await connection.Send( + "GET / HTTP/1.1", + "", + ""); + await ReceiveResponse(connection, server.Context); + + await Task.Delay(LongDelay); + + await Assert.ThrowsAsync(async () => + { + await connection.Send( + "GET / HTTP/1.1", + "", + ""); + await ReceiveResponse(connection, server.Context); + }); + } + } + + private async Task ConnectionClosedWhenKeepAliveTimeoutExpiresAfterChunkedRequest(TestServer server) + { + using (var connection = new TestConnection(server.Port)) + { + await connection.Send( + "POST / HTTP/1.1", + "Transfer-Encoding: chunked", + "", + "5", "hello", + "6", " world", + "0", + "", + ""); + await ReceiveResponse(connection, server.Context); + + await Task.Delay(LongDelay); + + await Assert.ThrowsAsync(async () => + { + await connection.Send( + "GET / HTTP/1.1", + "", + ""); + await ReceiveResponse(connection, server.Context); + }); + } + } + + private async Task KeepAliveTimeoutResetsBetweenContentLengthRequests(TestServer server) + { + using (var connection = new TestConnection(server.Port)) + { + for (var i = 0; i < 10; i++) + { + await connection.Send( + "GET / HTTP/1.1", + "", + ""); + await ReceiveResponse(connection, server.Context); + await Task.Delay(ShortDelay); + } + } + } + + private async Task KeepAliveTimeoutResetsBetweenChunkedRequests(TestServer server) + { + using (var connection = new TestConnection(server.Port)) + { + for (var i = 0; i < 5; i++) + { + await connection.Send( + "POST / HTTP/1.1", + "Transfer-Encoding: chunked", + "", + "5", "hello", + "6", " world", + "0", + "", + ""); + await ReceiveResponse(connection, server.Context); + await Task.Delay(ShortDelay); + } + } + } + + private async Task KeepAliveTimeoutNotTriggeredMidContentLengthRequest(TestServer server) + { + using (var connection = new TestConnection(server.Port)) + { + await connection.Send( + "POST / HTTP/1.1", + "Content-Length: 8", + "", + "a"); + await Task.Delay(LongDelay); + await connection.Send("bcdefgh"); + await ReceiveResponse(connection, server.Context); + } + } + + private async Task KeepAliveTimeoutNotTriggeredMidChunkedRequest(TestServer server) + { + using (var connection = new TestConnection(server.Port)) + { + await connection.Send( + "POST / HTTP/1.1", + "Transfer-Encoding: chunked", + "", + "5", "hello", + ""); + await Task.Delay(LongDelay); + await connection.Send( + "6", " world", + "0", + "", + ""); + await ReceiveResponse(connection, server.Context); + } + } + + private async Task ConnectionTimesOutWhenOpenedButNoRequestSent(TestServer server) + { + using (var connection = new TestConnection(server.Port)) + { + await Task.Delay(LongDelay); + await Assert.ThrowsAsync(async () => + { + await connection.Send( + "GET / HTTP/1.1", + "", + ""); + }); + } + } + + private TestServer CreateServer() + { + return new TestServer(App, new TestServiceContext + { + ServerOptions = new KestrelServerOptions + { + AddServerHeader = false, + Limits = + { + KeepAliveTimeout = KeepAliveTimeout + } + } + }); + } + + private async Task App(HttpContext httpContext) + { + const string response = "hello, world"; + httpContext.Response.ContentLength = response.Length; + await httpContext.Response.WriteAsync(response); + } + + private async Task ReceiveResponse(TestConnection connection, TestServiceContext testServiceContext) + { + await connection.Receive( + "HTTP/1.1 200 OK", + $"Date: {testServiceContext.DateHeaderValue}", + "Content-Length: 12", + "", + "hello, world"); + } + } +} diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerLimitsTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerLimitsTests.cs index 5199a16941..9edfd5d3c9 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerLimitsTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerLimitsTests.cs @@ -122,7 +122,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } [Fact] - public void MaxRequestHeadersDefault() + public void MaxRequestHeaderCountDefault() { Assert.Equal(100, (new KestrelServerLimits()).MaxRequestHeaderCount); } @@ -131,7 +131,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [InlineData(int.MinValue)] [InlineData(-1)] [InlineData(0)] - public void MaxRequestHeadersInvalid(int value) + public void MaxRequestHeaderCountInvalid(int value) { Assert.Throws(() => { @@ -142,11 +142,30 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [Theory] [InlineData(1)] [InlineData(int.MaxValue)] - public void MaxRequestHeadersValid(int value) + public void MaxRequestHeaderCountValid(int value) { var o = new KestrelServerLimits(); o.MaxRequestHeaderCount = value; Assert.Equal(value, o.MaxRequestHeaderCount); } + + [Fact] + public void KeepAliveTimeoutDefault() + { + Assert.Equal(TimeSpan.FromMinutes(2), new KestrelServerLimits().KeepAliveTimeout); + } + + [Theory] + [InlineData(0)] + [InlineData(0.5)] + [InlineData(2.1)] + [InlineData(2.5)] + [InlineData(2.9)] + public void KeepAliveTimeoutIsRoundedToTheNextSecond(double seconds) + { + var o = new KestrelServerLimits(); + o.KeepAliveTimeout = TimeSpan.FromSeconds(seconds); + Assert.Equal(Math.Ceiling(seconds), o.KeepAliveTimeout.TotalSeconds); + } } } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockLibuv.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockLibuv.cs index fcdf349003..c56dc3c491 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockLibuv.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockLibuv.cs @@ -126,6 +126,10 @@ namespace Microsoft.AspNetCore.Server.KestrelTests.TestHelpers { throw new Exception($"Why is this getting called?{Environment.NewLine}{_stackTrace}"); }; + + _uv_timer_init = (loop, handle) => 0; + _uv_timer_start = (handle, callback, timeout, repeat) => 0; + _uv_timer_stop = handle => 0; } public Func, int> OnWrite { get; set; } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestInput.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/TestInput.cs index de0edf5020..81c03056ac 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/TestInput.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/TestInput.cs @@ -58,6 +58,14 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { } + public void End(ProduceEndType endType) + { + } + + public void Stop() + { + } + public void Abort() { } @@ -65,9 +73,6 @@ namespace Microsoft.AspNetCore.Server.KestrelTests public void Write(ArraySegment data, Action callback, object state) { } - public void End(ProduceEndType endType) - { - } void IFrameControl.ProduceContinue() { diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/UvTimerHandleTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/UvTimerHandleTests.cs new file mode 100644 index 0000000000..b81d14d89a --- /dev/null +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/UvTimerHandleTests.cs @@ -0,0 +1,72 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; +using Microsoft.AspNetCore.Testing; +using Xunit; + +namespace Microsoft.AspNetCore.Server.KestrelTests +{ + public class UvTimerHandleTests + { + [Fact] + public void TestTimeout() + { + var trace = new TestKestrelTrace(); + + var loop = new UvLoopHandle(trace); + loop.Init(new Libuv()); + + var timer = new UvTimerHandle(trace); + timer.Init(loop, (a, b) => { }); + + var callbackInvoked = false; + timer.Start(_ => + { + callbackInvoked = true; + }, 1, 0); + loop.Run(); + + timer.Dispose(); + loop.Run(); + + loop.Dispose(); + + Assert.True(callbackInvoked); + } + + [Fact] + public void TestRepeat() + { + var trace = new TestKestrelTrace(); + + var loop = new UvLoopHandle(trace); + loop.Init(new Libuv()); + + var timer = new UvTimerHandle(trace); + timer.Init(loop, (callback, handle) => { }); + + var callbackCount = 0; + timer.Start(_ => + { + if (callbackCount < 2) + { + callbackCount++; + } + else + { + timer.Stop(); + } + }, 1, 1); + + loop.Run(); + + timer.Dispose(); + loop.Run(); + + loop.Dispose(); + + Assert.Equal(2, callbackCount); + } + } +} diff --git a/test/shared/TestConnection.cs b/test/shared/TestConnection.cs index 4accbe0ed1..a382cac84d 100644 --- a/test/shared/TestConnection.cs +++ b/test/shared/TestConnection.cs @@ -34,6 +34,7 @@ namespace Microsoft.AspNetCore.Testing _stream = new NetworkStream(_socket, false); _reader = new StreamReader(_stream, Encoding.ASCII); } + public void Dispose() { _stream.Dispose(); @@ -97,7 +98,7 @@ namespace Microsoft.AspNetCore.Testing var task = _reader.ReadAsync(actual, offset, actual.Length - offset); if (!Debugger.IsAttached) { - Assert.True(await Task.WhenAny(task, Task.Delay(10000)) == task, "TestConnection.Receive timed out."); + Assert.True(await Task.WhenAny(task, Task.Delay(TimeSpan.FromMinutes(1))) == task, "TestConnection.Receive timed out."); } var count = await task; if (count == 0) From 0491b492685ac07cc000169ae93d5cf0761b4ee5 Mon Sep 17 00:00:00 2001 From: DamirAinullin Date: Wed, 7 Sep 2016 14:23:06 +0300 Subject: [PATCH 0879/1662] Remove double initializing of variable _field3 --- .../Internal/Networking/SockAddr.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/SockAddr.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/SockAddr.cs index a5d5338bab..7c2962b12b 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/SockAddr.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/SockAddr.cs @@ -1,7 +1,6 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System; using System.Net; namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking @@ -19,7 +18,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking public SockAddr(long ignored) { - _field3 = _field0 = _field1 = _field2 = _field3 = 0; + _field0 = _field1 = _field2 = _field3 = 0; } public unsafe IPEndPoint GetIPEndPoint() From 5b2065230dbb83ab47c4360de2b2a315fecdee88 Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Wed, 7 Sep 2016 13:22:52 -0700 Subject: [PATCH 0880/1662] Fix failing keep-alive timeout tests. --- .../KeepAliveTimeoutTests.cs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/KeepAliveTimeoutTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/KeepAliveTimeoutTests.cs index f4bf8ba357..60be92f163 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/KeepAliveTimeoutTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/KeepAliveTimeoutTests.cs @@ -97,9 +97,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests "GET / HTTP/1.1", "", ""); - await ReceiveResponse(connection, server.Context); await Task.Delay(ShortDelay); } + + for (var i = 0; i < 10; i++) + { + await ReceiveResponse(connection, server.Context); + } } } @@ -107,7 +111,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { using (var connection = new TestConnection(server.Port)) { - for (var i = 0; i < 5; i++) + for (var i = 0; i < 10; i++) { await connection.Send( "POST / HTTP/1.1", @@ -118,9 +122,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests "0", "", ""); - await ReceiveResponse(connection, server.Context); await Task.Delay(ShortDelay); } + + for (var i = 0; i < 10; i++) + { + await ReceiveResponse(connection, server.Context); + } } } From c777a9efea7e8d633f8900cb2f55b0e56e569596 Mon Sep 17 00:00:00 2001 From: Pavel Krymets Date: Fri, 9 Sep 2016 15:57:33 -0700 Subject: [PATCH 0881/1662] Use TaskCache class from Microsoft.Extensions.TaskCache.Sources (#1089) Instead of Task.FromResult(0) --- .../Internal/ClosedStream.cs | 3 ++- .../Properties/AssemblyInfo.cs | 2 -- .../project.json | 6 +++++- .../Filter/Internal/LibuvStream.cs | 8 +++----- .../Filter/NoOpConnectionFilter.cs | 4 ++-- .../Internal/Http/Frame.cs | 15 ++++++++------- .../Internal/Http/FrameRequestStream.cs | 3 ++- .../Internal/Http/MessageBody.cs | 4 ++-- .../Internal/Http/SocketOutput.cs | 9 +++++---- .../Internal/Infrastructure/TaskUtilities.cs | 7 ------- .../project.json | 6 +++++- .../ResponseTests.cs | 4 ++-- .../BadHttpRequestTests.cs | 6 +++--- .../ConnectionTests.cs | 4 ++-- .../DefaultHeaderTests.cs | 4 ++-- .../EngineTests.cs | 15 ++++++++------- .../FrameTests.cs | 3 ++- .../HttpsConnectionFilterTests.cs | 9 +++++---- .../KestrelServerTests.cs | 4 ++-- .../TestHelpers/MockFrameControl.cs | 6 +++--- .../TestHelpers/MockSocketOuptut.cs | 3 ++- .../TestHelpers/PassThroughConnectionFilter.cs | 4 ++-- .../TestInput.cs | 5 +++-- 23 files changed, 70 insertions(+), 64 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Https/Internal/ClosedStream.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Https/Internal/ClosedStream.cs index c9d030cd87..3e63d4d69b 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Https/Internal/ClosedStream.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Https/Internal/ClosedStream.cs @@ -5,6 +5,7 @@ using System; using System.IO; using System.Threading; using System.Threading.Tasks; +using Microsoft.Extensions.Internal; namespace Microsoft.AspNetCore.Server.Kestrel.Https.Internal { @@ -55,7 +56,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Https.Internal public override Task ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) { - return Task.FromResult(0); + return TaskCache.DefaultCompletedTask; } public override void Write(byte[] buffer, int offset, int count) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Https/Properties/AssemblyInfo.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Https/Properties/AssemblyInfo.cs index 603dc45398..76feceeff0 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Https/Properties/AssemblyInfo.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Https/Properties/AssemblyInfo.cs @@ -3,9 +3,7 @@ using System.Reflection; using System.Resources; -using System.Runtime.CompilerServices; -[assembly: InternalsVisibleTo("Microsoft.AspNetCore.Server.KestrelTests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")] [assembly: AssemblyMetadata("Serviceable", "True")] [assembly: NeutralResourcesLanguage("en-us")] [assembly: AssemblyCompany("Microsoft Corporation.")] diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Https/project.json b/src/Microsoft.AspNetCore.Server.Kestrel.Https/project.json index c619c52a35..05d95e5e65 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Https/project.json +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Https/project.json @@ -19,7 +19,11 @@ ] }, "dependencies": { - "Microsoft.AspNetCore.Server.Kestrel": "1.1.0-*" + "Microsoft.AspNetCore.Server.Kestrel": "1.1.0-*", + "Microsoft.Extensions.TaskCache.Sources": { + "version": "1.1.0-*", + "type": "build" + } }, "frameworks": { "net451": {}, diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Filter/Internal/LibuvStream.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Filter/Internal/LibuvStream.cs index 0127d156a0..b8bc766f94 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Filter/Internal/LibuvStream.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Filter/Internal/LibuvStream.cs @@ -6,18 +6,16 @@ using System.IO; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; +using Microsoft.Extensions.Internal; namespace Microsoft.AspNetCore.Server.Kestrel.Filter.Internal { public class LibuvStream : Stream { - private readonly static Task _initialCachedTask = Task.FromResult(0); - private readonly SocketInput _input; private readonly ISocketOutput _output; - private Task _cachedTask = _initialCachedTask; + private Task _cachedTask = TaskCache.DefaultCompletedTask; public LibuvStream(SocketInput input, ISocketOutput output) { @@ -125,7 +123,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Filter.Internal public override Task FlushAsync(CancellationToken cancellationToken) { // No-op since writes are immediate. - return TaskUtilities.CompletedTask; + return TaskCache.CompletedTask; } private ValueTask ReadAsync(ArraySegment buffer) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Filter/NoOpConnectionFilter.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Filter/NoOpConnectionFilter.cs index 6aa78fc5fc..a41bd9313e 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Filter/NoOpConnectionFilter.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Filter/NoOpConnectionFilter.cs @@ -2,7 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Threading.Tasks; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; +using Microsoft.Extensions.Internal; namespace Microsoft.AspNetCore.Server.Kestrel.Filter { @@ -10,7 +10,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Filter { public Task OnConnectionAsync(ConnectionFilterContext context) { - return TaskUtilities.CompletedTask; + return TaskCache.CompletedTask; } } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs index ea969d1225..6a6e7f148c 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs @@ -12,6 +12,7 @@ using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; +using Microsoft.Extensions.Internal; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Primitives; @@ -338,7 +339,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { _requestProcessingStopping = true; } - return _requestProcessingTask ?? TaskUtilities.CompletedTask; + return _requestProcessingTask ?? TaskCache.CompletedTask; } /// @@ -500,7 +501,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { if (data.Count == 0) { - return TaskUtilities.CompletedTask; + return TaskCache.CompletedTask; } return WriteChunkedAsync(data, cancellationToken); } @@ -569,7 +570,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { if (HasResponseStarted) { - return TaskUtilities.CompletedTask; + return TaskCache.CompletedTask; } if (_onStarting != null) @@ -583,7 +584,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } ProduceStart(appCompleted: false); - return TaskUtilities.CompletedTask; + return TaskCache.CompletedTask; } private async Task ProduceStartAndFireOnStartingAwaited() @@ -624,7 +625,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http return ProduceEnd(); } - return TaskUtilities.CompletedTask; + return TaskCache.CompletedTask; } protected Task ProduceEnd() @@ -635,7 +636,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { // We can no longer change the response, so we simply close the connection. _requestProcessingStopping = true; - return TaskUtilities.CompletedTask; + return TaskCache.CompletedTask; } if (_requestRejected) @@ -697,7 +698,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http ConnectionControl.End(ProduceEndType.ConnectionKeepAlive); } - return TaskUtilities.CompletedTask; + return TaskCache.CompletedTask; } private async Task WriteAutoChunkSuffixAwaited() diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameRequestStream.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameRequestStream.cs index 09a4834ef8..3889a02db5 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameRequestStream.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameRequestStream.cs @@ -6,6 +6,7 @@ using System.IO; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; +using Microsoft.Extensions.Internal; namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { @@ -54,7 +55,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http public override Task FlushAsync(CancellationToken cancellationToken) { // No-op. - return TaskUtilities.CompletedTask; + return TaskCache.CompletedTask; } public override long Seek(long offset, SeekOrigin origin) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/MessageBody.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/MessageBody.cs index 1e760bdb5b..584b6d79ec 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/MessageBody.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/MessageBody.cs @@ -5,7 +5,7 @@ using System; using System.Numerics; using System.Threading; using System.Threading.Tasks; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; +using Microsoft.Extensions.Internal; namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { @@ -60,7 +60,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http else if (result.Result == 0) { // Completed Task, end of stream - return TaskUtilities.CompletedTask; + return TaskCache.CompletedTask; } } while (true); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/SocketOutput.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/SocketOutput.cs index 8a3f9e5890..26621f4022 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/SocketOutput.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/SocketOutput.cs @@ -8,6 +8,7 @@ using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; +using Microsoft.Extensions.Internal; using Microsoft.Extensions.Logging; namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http @@ -98,7 +99,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { _log.ConnectionDisconnectedWrite(_connectionId, buffer.Count, _lastWriteError); - return TaskUtilities.CompletedTask; + return TaskCache.CompletedTask; } if (buffer.Count > 0) @@ -106,7 +107,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var tail = ProducingStart(); if (tail.IsDefault) { - return TaskUtilities.CompletedTask; + return TaskCache.CompletedTask; } if (chunk) @@ -201,7 +202,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } // Return TaskCompletionSource's Task if set, otherwise completed Task - return tcs?.Task ?? TaskUtilities.CompletedTask; + return tcs?.Task ?? TaskCache.CompletedTask; } public void End(ProduceEndType endType) @@ -523,7 +524,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } else if (_cancelled) { - return TaskUtilities.CompletedTask; + return TaskCache.CompletedTask; } return WriteAsync(buffer, cancellationToken, chunk); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/TaskUtilities.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/TaskUtilities.cs index 193e2fdf6e..6ee8e895df 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/TaskUtilities.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/TaskUtilities.cs @@ -9,13 +9,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure { public static class TaskUtilities { -#if NETSTANDARD1_3 - public static Task CompletedTask = Task.CompletedTask; -#else - public static Task CompletedTask = Task.FromResult(null); -#endif - public static Task ZeroTask = Task.FromResult(0); - public static Task GetCancelledTask(CancellationToken cancellationToken) { #if NETSTANDARD1_3 diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/project.json b/src/Microsoft.AspNetCore.Server.Kestrel/project.json index 2208ce2684..a83047073a 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/project.json +++ b/src/Microsoft.AspNetCore.Server.Kestrel/project.json @@ -18,7 +18,11 @@ "System.Threading.Tasks.Extensions": "4.0.0-*", "Libuv": "1.9.0-*", "Microsoft.AspNetCore.Hosting": "1.1.0-*", - "Microsoft.Extensions.Logging.Abstractions": "1.1.0-*" + "Microsoft.Extensions.Logging.Abstractions": "1.1.0-*", + "Microsoft.Extensions.TaskCache.Sources": { + "version": "1.1.0-*", + "type": "build" + } }, "frameworks": { "net451": { diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs index 54ee883656..736807ac62 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs @@ -9,7 +9,7 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; +using Microsoft.Extensions.Internal; using Microsoft.Extensions.Primitives; using Xunit; @@ -159,7 +159,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { await context.Response.WriteAsync("hello, world"); await context.Response.Body.FlushAsync(); - ex = Assert.Throws(() => context.Response.OnStarting(_ => TaskUtilities.CompletedTask, null)); + ex = Assert.Throws(() => context.Response.OnStarting(_ => TaskCache.CompletedTask, null)); }); }); diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/BadHttpRequestTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/BadHttpRequestTests.cs index a1d21078d0..74cbb05230 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/BadHttpRequestTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/BadHttpRequestTests.cs @@ -2,8 +2,8 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Threading.Tasks; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.AspNetCore.Testing; +using Microsoft.Extensions.Internal; using Xunit; namespace Microsoft.AspNetCore.Server.KestrelTests @@ -73,7 +73,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [InlineData("post= / HTTP/1.0\r\n")] public async Task TestInvalidRequestLines(string request) { - using (var server = new TestServer(context => TaskUtilities.CompletedTask)) + using (var server = new TestServer(context => TaskCache.CompletedTask)) { using (var connection = server.CreateConnection()) { @@ -109,7 +109,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [InlineData("Header-1: value1\r\nHeader-2\t: value2\r\n\r\n")] public async Task TestInvalidHeaders(string rawHeaders) { - using (var server = new TestServer(context => TaskUtilities.CompletedTask)) + using (var server = new TestServer(context => TaskCache.CompletedTask)) { using (var connection = server.CreateConnection()) { diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionTests.cs index d6fdadf968..59f8c012a9 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionTests.cs @@ -3,10 +3,10 @@ using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Server.Kestrel; using Microsoft.AspNetCore.Server.Kestrel.Internal; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; using Microsoft.AspNetCore.Server.KestrelTests.TestHelpers; using Microsoft.AspNetCore.Testing; +using Microsoft.Extensions.Internal; using Xunit; namespace Microsoft.AspNetCore.Server.KestrelTests @@ -26,7 +26,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var context = new ListenerContext(new TestServiceContext()) { FrameFactory = connectionContext => new Frame( - new DummyApplication(httpContext => TaskUtilities.CompletedTask), connectionContext), + new DummyApplication(httpContext => TaskCache.CompletedTask), connectionContext), ServerAddress = ServerAddress.FromUrl("http://127.0.0.1:0"), Thread = engine.Threads[0] }; diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/DefaultHeaderTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/DefaultHeaderTests.cs index 127aa2b221..3070332da9 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/DefaultHeaderTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/DefaultHeaderTests.cs @@ -2,8 +2,8 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Threading.Tasks; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.AspNetCore.Testing; +using Microsoft.Extensions.Internal; using Xunit; namespace Microsoft.AspNetCore.Server.KestrelTests @@ -18,7 +18,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests ServerOptions = { AddServerHeader = true } }; - using (var server = new TestServer(ctx => TaskUtilities.CompletedTask, testContext)) + using (var server = new TestServer(ctx => TaskCache.CompletedTask, testContext)) { using (var connection = server.CreateConnection()) { diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs index eb295aadb2..2fdb63a220 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs @@ -16,6 +16,7 @@ using Microsoft.AspNetCore.Server.Kestrel.Internal; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.AspNetCore.Testing; +using Microsoft.Extensions.Internal; using Xunit; namespace Microsoft.AspNetCore.Server.KestrelTests @@ -1084,7 +1085,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests using (var server = new TestServer(httpContext => { httpContext.Abort(); - return TaskUtilities.CompletedTask; + return TaskCache.CompletedTask; }, testContext)) { using (var connection = server.CreateConnection()) @@ -1121,7 +1122,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests Assert.Same(originalRequestHeaders, requestFeature.Headers); } - return TaskUtilities.CompletedTask; + return TaskCache.CompletedTask; }, testContext)) { using (var connection = server.CreateConnection()) @@ -1168,7 +1169,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests Assert.Same(originalResponseHeaders, responseFeature.Headers); } - return TaskUtilities.CompletedTask; + return TaskCache.CompletedTask; }, testContext)) { using (var connection = server.CreateConnection()) @@ -1234,12 +1235,12 @@ namespace Microsoft.AspNetCore.Server.KestrelTests context.Response.OnStarting(_ => { callOrder.Push(1); - return TaskUtilities.CompletedTask; + return TaskCache.CompletedTask; }, null); context.Response.OnStarting(_ => { callOrder.Push(2); - return TaskUtilities.CompletedTask; + return TaskCache.CompletedTask; }, null); context.Response.ContentLength = response.Length; @@ -1278,12 +1279,12 @@ namespace Microsoft.AspNetCore.Server.KestrelTests context.Response.OnCompleted(_ => { callOrder.Push(1); - return TaskUtilities.CompletedTask; + return TaskCache.CompletedTask; }, null); context.Response.OnCompleted(_ => { callOrder.Push(2); - return TaskUtilities.CompletedTask; + return TaskCache.CompletedTask; }, null); context.Response.ContentLength = response.Length; diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs index ecd438a5c5..a6bd8bb501 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs @@ -11,6 +11,7 @@ using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.AspNetCore.Server.KestrelTests.TestHelpers; using Microsoft.AspNetCore.Testing; +using Microsoft.Extensions.Internal; using Xunit; namespace Microsoft.AspNetCore.Server.KestrelTests @@ -629,7 +630,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests // Act/Assert Assert.True(frame.HasResponseStarted); - Assert.Throws(() => ((IHttpResponseFeature)frame).OnStarting(_ => TaskUtilities.CompletedTask, null)); + Assert.Throws(() => ((IHttpResponseFeature)frame).OnStarting(_ => TaskCache.CompletedTask, null)); } [Fact] diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/HttpsConnectionFilterTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/HttpsConnectionFilterTests.cs index 2e5ad48707..1b5354acb2 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/HttpsConnectionFilterTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/HttpsConnectionFilterTests.cs @@ -17,6 +17,7 @@ using Microsoft.AspNetCore.Server.Kestrel.Filter; using Microsoft.AspNetCore.Server.Kestrel.Https; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.AspNetCore.Testing; +using Microsoft.Extensions.Internal; using Microsoft.Extensions.Logging; using Moq; using Xunit; @@ -113,7 +114,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests new NoOpConnectionFilter()) ); - using (var server = new TestServer(context => TaskUtilities.CompletedTask, serviceContext, _serverAddress)) + using (var server = new TestServer(context => TaskCache.CompletedTask, serviceContext, _serverAddress)) { using (var client = new TcpClient()) { @@ -231,7 +232,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests new NoOpConnectionFilter()) ); - using (var server = new TestServer(context => TaskUtilities.CompletedTask, serviceContext, _serverAddress)) + using (var server = new TestServer(context => TaskCache.CompletedTask, serviceContext, _serverAddress)) { using (var client = new TcpClient()) { @@ -258,7 +259,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests new NoOpConnectionFilter()) ); - using (var server = new TestServer(context => TaskUtilities.CompletedTask, serviceContext, _serverAddress)) + using (var server = new TestServer(context => TaskCache.CompletedTask, serviceContext, _serverAddress)) { using (var client = new TcpClient()) { @@ -283,7 +284,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests new NoOpConnectionFilter()) ); - using (var server = new TestServer(context => TaskUtilities.CompletedTask, serviceContext, _serverAddress)) + using (var server = new TestServer(context => TaskCache.CompletedTask, serviceContext, _serverAddress)) { using (var client = new TcpClient()) { diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerTests.cs index c7edfe82f9..773d5180e9 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerTests.cs @@ -5,8 +5,8 @@ using System; using Microsoft.AspNetCore.Hosting.Server; using Microsoft.AspNetCore.Hosting.Server.Features; using Microsoft.AspNetCore.Server.Kestrel; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.AspNetCore.Testing; +using Microsoft.Extensions.Internal; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using Moq; @@ -92,7 +92,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests private static void StartDummyApplication(IServer server) { - server.Start(new DummyApplication(context => TaskUtilities.CompletedTask)); + server.Start(new DummyApplication(context => TaskCache.CompletedTask)); } private class TestLoggerFactory : ILoggerFactory diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockFrameControl.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockFrameControl.cs index 1ec4ec728b..09cec798a4 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockFrameControl.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockFrameControl.cs @@ -5,7 +5,7 @@ using System; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; +using Microsoft.Extensions.Internal; namespace Microsoft.AspNetCore.Server.KestrelTests.TestHelpers { @@ -17,7 +17,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests.TestHelpers public Task FlushAsync(CancellationToken cancellationToken) { - return TaskUtilities.CompletedTask; + return TaskCache.CompletedTask; } public void ProduceContinue() @@ -30,7 +30,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests.TestHelpers public Task WriteAsync(ArraySegment data, CancellationToken cancellationToken) { - return TaskUtilities.CompletedTask; + return TaskCache.CompletedTask; } } } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockSocketOuptut.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockSocketOuptut.cs index 07af801aa7..bdddcd1504 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockSocketOuptut.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockSocketOuptut.cs @@ -6,6 +6,7 @@ using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; +using Microsoft.Extensions.Internal; namespace Microsoft.AspNetCore.Server.KestrelTests.TestHelpers { @@ -26,7 +27,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests.TestHelpers public Task WriteAsync(ArraySegment buffer, bool chunk = false, CancellationToken cancellationToken = default(CancellationToken)) { - return TaskUtilities.CompletedTask; + return TaskCache.CompletedTask; } } } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/PassThroughConnectionFilter.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/PassThroughConnectionFilter.cs index b398021e7d..bab4e24987 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/PassThroughConnectionFilter.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/PassThroughConnectionFilter.cs @@ -4,8 +4,8 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Filter; using Microsoft.AspNetCore.Server.Kestrel.Filter.Internal; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.AspNetCore.Testing; +using Microsoft.Extensions.Internal; namespace Microsoft.AspNetCore.Server.KestrelTests { @@ -15,7 +15,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests public Task OnConnectionAsync(ConnectionFilterContext context) { context.Connection = new LoggingStream(context.Connection, new TestApplicationErrorLogger()); - return TaskUtilities.CompletedTask; + return TaskCache.CompletedTask; } } } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestInput.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/TestInput.cs index 81c03056ac..5bb230ab4a 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/TestInput.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/TestInput.cs @@ -10,6 +10,7 @@ using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.AspNetCore.Server.KestrelTests.TestHelpers; using Microsoft.AspNetCore.Testing; +using Microsoft.Extensions.Internal; namespace Microsoft.AspNetCore.Server.KestrelTests { @@ -84,7 +85,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests Task IFrameControl.WriteAsync(ArraySegment data, CancellationToken cancellationToken) { - return TaskUtilities.CompletedTask; + return TaskCache.CompletedTask; } void IFrameControl.Flush() @@ -93,7 +94,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests Task IFrameControl.FlushAsync(CancellationToken cancellationToken) { - return TaskUtilities.CompletedTask; + return TaskCache.CompletedTask; } public void Dispose() From 8c513402a342c4c39f410e02b9e0d2edee088fe0 Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Thu, 8 Sep 2016 16:44:07 -0700 Subject: [PATCH 0882/1662] Always call ConsumingComplete() with furthest examined position (#1095). --- .../Internal/Http/Frame.cs | 27 ++-- .../FrameTests.cs | 151 ++++++++++++++++++ 2 files changed, 164 insertions(+), 14 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs index 6a6e7f148c..c065abba57 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs @@ -789,10 +789,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http SocketOutput.ProducingComplete(end); } - protected RequestLineStatus TakeStartLine(SocketInput input) + public RequestLineStatus TakeStartLine(SocketInput input) { var scan = input.ConsumingStart(); var consumed = scan; + var end = scan; try { @@ -806,7 +807,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _requestProcessingStatus = RequestProcessingStatus.RequestStarted; - var end = scan; int bytesScanned; if (end.Seek(ref _vectorLFs, out bytesScanned, ServerOptions.Limits.MaxRequestLineSize) == -1) { @@ -923,6 +923,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http RejectRequest(RequestRejectionReason.MissingLFInRequestLine); } scan.Take(); // consume LF + end = scan; // URIs are always encoded/escaped to ASCII https://tools.ietf.org/html/rfc3986#page-11 // Multibyte Internationalized Resource Identifiers (IRIs) are first converted to utf8; @@ -984,7 +985,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } finally { - input.ConsumingComplete(consumed, scan); + input.ConsumingComplete(consumed, end); } } @@ -1049,11 +1050,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { var scan = input.ConsumingStart(); var consumed = scan; + var end = scan; try { - while (!scan.IsEnd) + while (!end.IsEnd) { - var ch = scan.Peek(); + var ch = end.Peek(); if (ch == -1) { return false; @@ -1061,8 +1063,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http else if (ch == '\r') { // Check for final CRLF. - scan.Take(); - ch = scan.Take(); + end.Take(); + ch = end.Take(); if (ch == -1) { @@ -1070,7 +1072,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } else if (ch == '\n') { - consumed = scan; + consumed = end; return true; } @@ -1089,7 +1091,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http RejectRequest(RequestRejectionReason.TooManyHeaders); } - var end = scan; int bytesScanned; if (end.Seek(ref _vectorLFs, out bytesScanned, _remainingRequestHeadersBytesAllowed) == -1) { @@ -1135,6 +1136,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http scan.Take(); // we know this is '\r' ch = scan.Take(); // expecting '\n' + end = scan; if (ch != '\n') { @@ -1203,7 +1205,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } finally { - input.ConsumingComplete(consumed, scan); + input.ConsumingComplete(consumed, end); } } @@ -1286,12 +1288,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _secondsSinceLastRequest = 0; } - protected enum RequestLineStatus + public enum RequestLineStatus { Empty, - MethodIncomplete, - TargetIncomplete, - VersionIncomplete, Incomplete, Done } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs index a6bd8bb501..18c0039860 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs @@ -713,5 +713,156 @@ namespace Microsoft.AspNetCore.Server.KestrelTests Assert.Same(originalResponseBody, frame.ResponseBody); Assert.Same(originalDuplexStream, frame.DuplexStream); } + + [Fact] + public void TakeStartLineCallsConsumingCompleteWithFurthestExamined() + { + var trace = new KestrelTrace(new TestKestrelTrace()); + var ltp = new LoggingThreadPool(trace); + using (var pool = new MemoryPool()) + using (var socketInput = new SocketInput(pool, ltp)) + { + var connectionContext = new ConnectionContext() + { + DateHeaderValueManager = new DateHeaderValueManager(), + ServerAddress = ServerAddress.FromUrl("http://localhost:5000"), + ServerOptions = new KestrelServerOptions(), + Log = trace + }; + var frame = new Frame(application: null, context: connectionContext); + frame.Reset(); + + var requestLineBytes = Encoding.ASCII.GetBytes("GET / "); + socketInput.IncomingData(requestLineBytes, 0, requestLineBytes.Length); + frame.TakeStartLine(socketInput); + Assert.False(socketInput.IsCompleted); + + requestLineBytes = Encoding.ASCII.GetBytes("HTTP/1.1\r\n"); + socketInput.IncomingData(requestLineBytes, 0, requestLineBytes.Length); + frame.TakeStartLine(socketInput); + Assert.False(socketInput.IsCompleted); + } + } + + [Theory] + [InlineData("", Frame.RequestLineStatus.Empty)] + [InlineData("G", Frame.RequestLineStatus.Incomplete)] + [InlineData("GE", Frame.RequestLineStatus.Incomplete)] + [InlineData("GET", Frame.RequestLineStatus.Incomplete)] + [InlineData("GET ", Frame.RequestLineStatus.Incomplete)] + [InlineData("GET /", Frame.RequestLineStatus.Incomplete)] + [InlineData("GET / ", Frame.RequestLineStatus.Incomplete)] + [InlineData("GET / H", Frame.RequestLineStatus.Incomplete)] + [InlineData("GET / HT", Frame.RequestLineStatus.Incomplete)] + [InlineData("GET / HTT", Frame.RequestLineStatus.Incomplete)] + [InlineData("GET / HTTP", Frame.RequestLineStatus.Incomplete)] + [InlineData("GET / HTTP/", Frame.RequestLineStatus.Incomplete)] + [InlineData("GET / HTTP/1", Frame.RequestLineStatus.Incomplete)] + [InlineData("GET / HTTP/1.", Frame.RequestLineStatus.Incomplete)] + [InlineData("GET / HTTP/1.1", Frame.RequestLineStatus.Incomplete)] + [InlineData("GET / HTTP/1.1\r", Frame.RequestLineStatus.Incomplete)] + public void TakeStartLineReturnsWhenGivenIncompleteRequestLines(string requestLine, Frame.RequestLineStatus expectedReturnValue) + { + var trace = new KestrelTrace(new TestKestrelTrace()); + var ltp = new LoggingThreadPool(trace); + using (var pool = new MemoryPool()) + using (var socketInput = new SocketInput(pool, ltp)) + { + var connectionContext = new ConnectionContext() + { + DateHeaderValueManager = new DateHeaderValueManager(), + ServerAddress = ServerAddress.FromUrl("http://localhost:5000"), + ServerOptions = new KestrelServerOptions(), + Log = trace + }; + var frame = new Frame(application: null, context: connectionContext); + frame.Reset(); + + var requestLineBytes = Encoding.ASCII.GetBytes(requestLine); + socketInput.IncomingData(requestLineBytes, 0, requestLineBytes.Length); + + var returnValue = frame.TakeStartLine(socketInput); + Assert.Equal(expectedReturnValue, returnValue); + } + } + + [Fact] + public void TakeMessageHeadersCallsConsumingCompleteWithFurthestExamined() + { + var trace = new KestrelTrace(new TestKestrelTrace()); + var ltp = new LoggingThreadPool(trace); + using (var pool = new MemoryPool()) + using (var socketInput = new SocketInput(pool, ltp)) + { + var connectionContext = new ConnectionContext() + { + DateHeaderValueManager = new DateHeaderValueManager(), + ServerAddress = ServerAddress.FromUrl("http://localhost:5000"), + ServerOptions = new KestrelServerOptions(), + Log = trace + }; + var frame = new Frame(application: null, context: connectionContext); + frame.Reset(); + frame.InitializeHeaders(); + + var headersBytes = Encoding.ASCII.GetBytes("Header: "); + socketInput.IncomingData(headersBytes, 0, headersBytes.Length); + frame.TakeMessageHeaders(socketInput, (FrameRequestHeaders)frame.RequestHeaders); + Assert.False(socketInput.IsCompleted); + + headersBytes = Encoding.ASCII.GetBytes("value\r\n"); + socketInput.IncomingData(headersBytes, 0, headersBytes.Length); + frame.TakeMessageHeaders(socketInput, (FrameRequestHeaders)frame.RequestHeaders); + Assert.False(socketInput.IsCompleted); + + headersBytes = Encoding.ASCII.GetBytes("\r\n"); + socketInput.IncomingData(headersBytes, 0, headersBytes.Length); + frame.TakeMessageHeaders(socketInput, (FrameRequestHeaders)frame.RequestHeaders); + Assert.False(socketInput.IsCompleted); + } + } + + [Theory] + [InlineData("\r")] + [InlineData("H")] + [InlineData("He")] + [InlineData("Hea")] + [InlineData("Head")] + [InlineData("Heade")] + [InlineData("Header")] + [InlineData("Header:")] + [InlineData("Header: ")] + [InlineData("Header: v")] + [InlineData("Header: va")] + [InlineData("Header: val")] + [InlineData("Header: valu")] + [InlineData("Header: value")] + [InlineData("Header: value\r")] + [InlineData("Header: value\r\n")] + [InlineData("Header: value\r\n\r")] + public void TakeMessageHeadersReturnsWhenGivenIncompleteHeaders(string headers) + { + var trace = new KestrelTrace(new TestKestrelTrace()); + var ltp = new LoggingThreadPool(trace); + using (var pool = new MemoryPool()) + using (var socketInput = new SocketInput(pool, ltp)) + { + var connectionContext = new ConnectionContext() + { + DateHeaderValueManager = new DateHeaderValueManager(), + ServerAddress = ServerAddress.FromUrl("http://localhost:5000"), + ServerOptions = new KestrelServerOptions(), + Log = trace + }; + var frame = new Frame(application: null, context: connectionContext); + frame.Reset(); + frame.InitializeHeaders(); + + var headerBytes = Encoding.ASCII.GetBytes(headers); + socketInput.IncomingData(headerBytes, 0, headerBytes.Length); + + Assert.Equal(false, frame.TakeMessageHeaders(socketInput, (FrameRequestHeaders)frame.RequestHeaders)); + } + } } } From 39bd49ea1ae9418d1b8b7aeb6eff2f3e01ba15a7 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Fri, 9 Sep 2016 11:28:49 -0700 Subject: [PATCH 0883/1662] Avoid blocking the MockLibuv loop with test code - This allows for a graceful shutdown with dotnet test -Parallel None - By default, the xunit synccontext will dispatch automatically off the KestrelThread, but it's best not to rely on this behavior. --- .../TestHelpers/MockLibuv.cs | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockLibuv.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockLibuv.cs index c56dc3c491..80584f65be 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockLibuv.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockLibuv.cs @@ -69,7 +69,6 @@ namespace Microsoft.AspNetCore.Server.KestrelTests.TestHelpers { _loopWh.Wait(); KestrelThreadBlocker.Wait(); - TaskCompletionSource onPostTcs = null; lock (_postLock) { @@ -84,14 +83,14 @@ namespace Microsoft.AspNetCore.Server.KestrelTests.TestHelpers // Ensure any subsequent calls to uv_async_send // create a new _onPostTcs to be completed. _completedOnPostTcs = true; - onPostTcs = _onPostTcs; + + // Calling TrySetResult outside the lock to avoid deadlock + // when the code attempts to call uv_async_send after awaiting + // OnPostTask. Task.Run so the run loop doesn't block either. + var onPostTcs = _onPostTcs; + Task.Run(() => onPostTcs.TrySetResult(null)); } } - - // Calling TrySetResult outside the lock to avoid deadlock - // when the code attempts to call uv_async_send after awaiting - // OnPostTask. - onPostTcs?.TrySetResult(null); } return 0; From 84efe624a627e767f08d5a6f263bd40bd7e80fed Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Fri, 9 Sep 2016 16:09:23 -0700 Subject: [PATCH 0884/1662] Fix deadlock in HttpsTests - The xunit synccontext was saving us again --- .../HttpsTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/HttpsTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/HttpsTests.cs index 775e2c6a01..1fd4889a4e 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/HttpsTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/HttpsTests.cs @@ -115,7 +115,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { LastLogLevel = logLevel; LastEventId = eventId; - LogTcs.SetResult(null); + Task.Run(() => LogTcs.SetResult(null)); } public bool IsEnabled(LogLevel logLevel) From 1a273f5a34cae8ea39d99bd5e7ff64eb6057d142 Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Mon, 12 Sep 2016 11:40:30 -0700 Subject: [PATCH 0885/1662] Improve keep-alive timeout. - Track time more accurately - Control timeout in Connection instead of Frame --- .../Internal/Http/Connection.cs | 27 ++- .../Internal/Http/Frame.cs | 24 +- .../Internal/Http/FrameOfT.cs | 2 + .../Internal/Http/IConnectionControl.cs | 3 +- .../Internal/Http/MessageBody.cs | 13 - .../Internal/Infrastructure/KestrelThread.cs | 11 +- .../Internal/Networking/Libuv.cs | 11 + .../Internal/Networking/UvLoopHandle.cs | 5 + .../KestrelServerLimits.cs | 10 +- .../KeepAliveTimeoutTests.cs | 229 ++++++++++-------- .../ConnectionTests.cs | 27 ++- .../FrameTests.cs | 86 +++++++ .../KestrelServerLimitsTests.cs | 4 +- .../TestHelpers/MockConnection.cs | 1 + .../TestHelpers/MockLibuv.cs | 1 + .../TestInput.cs | 13 +- 16 files changed, 304 insertions(+), 163 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Connection.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Connection.cs index 84e70e1811..7494362185 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Connection.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Connection.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Diagnostics; using System.IO; using System.Threading; using System.Threading.Tasks; @@ -38,6 +39,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http private TaskCompletionSource _socketClosedTcs = new TaskCompletionSource(); private BufferSizeControl _bufferSizeControl; + private long _lastTimestamp; + private long _timeoutTimestamp = long.MaxValue; + public Connection(ListenerContext context, UvStreamHandle socket) : base(context) { _socket = socket; @@ -62,6 +66,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } _frame = FrameFactory(this); + + _lastTimestamp = Thread.Loop.Now(); } // Internal for testing @@ -156,9 +162,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } // Called on Libuv thread - public void Tick() + public void Tick(long timestamp) { - _frame.Tick(); + if (timestamp > _timeoutTimestamp) + { + StopAsync(); + } + + Interlocked.Exchange(ref _lastTimestamp, timestamp); } private void ApplyConnectionFilter() @@ -282,9 +293,17 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } } - void IConnectionControl.Stop() + void IConnectionControl.SetTimeout(long milliseconds) { - StopAsync(); + Debug.Assert(_timeoutTimestamp == long.MaxValue, "Concurrent timeouts are not supported"); + + // Add KestrelThread.HeartbeatMilliseconds extra milliseconds since this can be called right before the next heartbeat. + Interlocked.Exchange(ref _timeoutTimestamp, _lastTimestamp + milliseconds + KestrelThread.HeartbeatMilliseconds); + } + + void IConnectionControl.CancelTimeout() + { + Interlocked.Exchange(ref _timeoutTimestamp, long.MaxValue); } private static unsafe string GenerateConnectionId(long id) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs index c065abba57..2e17305777 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs @@ -69,7 +69,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http private int _remainingRequestHeadersBytesAllowed; private int _requestHeadersParsed; - private int _secondsSinceLastRequest; + protected readonly long _keepAliveMilliseconds; public Frame(ConnectionContext context) : base(context) @@ -77,6 +77,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _pathBase = context.ServerAddress.PathBase; FrameControl = this; + _keepAliveMilliseconds = (long)ServerOptions.Limits.KeepAliveTimeout.TotalMilliseconds; } public string ConnectionIdFeature { get; set; } @@ -805,6 +806,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http return RequestLineStatus.Empty; } + ConnectionControl.CancelTimeout(); + _requestProcessingStatus = RequestProcessingStatus.RequestStarted; int bytesScanned; @@ -1269,25 +1272,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http Log.ApplicationError(ConnectionId, ex); } - public void Tick() - { - // we're in between requests and not about to start processing a new one - if (_requestProcessingStatus == RequestProcessingStatus.RequestPending && !SocketInput.IsCompleted) - { - if (_secondsSinceLastRequest > ServerOptions.Limits.KeepAliveTimeout.TotalSeconds) - { - ConnectionControl.Stop(); - } - - _secondsSinceLastRequest++; - } - } - - public void RequestFinished() - { - _secondsSinceLastRequest = 0; - } - public enum RequestLineStatus { Empty, diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameOfT.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameOfT.cs index 85a0832467..99d56f1fbf 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameOfT.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameOfT.cs @@ -32,6 +32,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { while (!_requestProcessingStopping) { + ConnectionControl.SetTimeout(_keepAliveMilliseconds); + while (!_requestProcessingStopping && TakeStartLine(SocketInput) != RequestLineStatus.Done) { if (SocketInput.CheckFinOrThrow()) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/IConnectionControl.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/IConnectionControl.cs index 0c174ca86a..f7de78dfcf 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/IConnectionControl.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/IConnectionControl.cs @@ -8,6 +8,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http void Pause(); void Resume(); void End(ProduceEndType endType); - void Stop(); + void SetTimeout(long milliseconds); + void CancelTimeout(); } } \ No newline at end of file diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/MessageBody.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/MessageBody.cs index 584b6d79ec..65bbe9a808 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/MessageBody.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/MessageBody.cs @@ -172,7 +172,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var limit = buffer.Array == null ? inputLengthLimit : Math.Min(buffer.Count, inputLengthLimit); if (limit == 0) { - _context.RequestFinished(); return new ValueTask(0); } @@ -189,11 +188,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _context.RejectRequest(RequestRejectionReason.UnexpectedEndOfRequestContent); } - if (_inputLength == 0) - { - _context.RequestFinished(); - } - return new ValueTask(actual); } else @@ -212,11 +206,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _context.RejectRequest(RequestRejectionReason.UnexpectedEndOfRequestContent); } - if (_inputLength == 0) - { - _context.RequestFinished(); - } - return actual; } } @@ -368,8 +357,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _mode = Mode.Complete; } - _context.RequestFinished(); - return 0; } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/KestrelThread.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/KestrelThread.cs index 08e5773083..ec8394be20 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/KestrelThread.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/KestrelThread.cs @@ -19,6 +19,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal /// public class KestrelThread { + public const long HeartbeatMilliseconds = 1000; + private static readonly Action _postCallbackAdapter = (callback, state) => ((Action)callback).Invoke(state); private static readonly Action _postAsyncCallbackAdapter = (callback, state) => ((Action)callback).Invoke(state); @@ -27,9 +29,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal // otherwise it needs to wait till the next pass of the libuv loop private readonly int _maxLoops = 8; - // how often the heartbeat timer will tick connections - private const int _heartbeatMilliseconds = 1000; - private readonly KestrelEngine _engine; private readonly IApplicationLifetime _appLifetime; private readonly Thread _thread; @@ -280,7 +279,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal _loop.Init(_engine.Libuv); _post.Init(_loop, OnPost, EnqueueCloseHandle); _heartbeatTimer.Init(_loop, EnqueueCloseHandle); - _heartbeatTimer.Start(OnHeartbeat, timeout: 1000, repeat: 1000); + _heartbeatTimer.Start(OnHeartbeat, timeout: HeartbeatMilliseconds, repeat: HeartbeatMilliseconds); _initCompleted = true; tcs.SetResult(0); } @@ -337,10 +336,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal private void OnHeartbeat(UvTimerHandle timer) { + var now = Loop.Now(); + Walk(ptr => { var handle = UvMemory.FromIntPtr(ptr); - (handle as UvStreamHandle)?.Connection?.Tick(); + (handle as UvStreamHandle)?.Connection?.Tick(now); }); } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/Libuv.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/Libuv.cs index 9b1fada8f5..aaf1a00eba 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/Libuv.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/Libuv.cs @@ -56,6 +56,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking _uv_timer_init = NativeMethods.uv_timer_init; _uv_timer_start = NativeMethods.uv_timer_start; _uv_timer_stop = NativeMethods.uv_timer_stop; + _uv_now = NativeMethods.uv_now; } // Second ctor that doesn't set any fields only to be used by MockLibuv @@ -434,6 +435,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking ThrowIfErrored(_uv_timer_stop(handle)); } + protected Func _uv_now; + unsafe public long now(UvLoopHandle loop) + { + loop.Validate(); + return _uv_now(loop); + } + public delegate int uv_tcp_getsockname_func(UvTcpHandle handle, out SockAddr addr, ref int namelen); protected uv_tcp_getsockname_func _uv_tcp_getsockname; public void tcp_getsockname(UvTcpHandle handle, out SockAddr addr, ref int namelen) @@ -640,6 +648,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking [DllImport("libuv", CallingConvention = CallingConvention.Cdecl)] unsafe public static extern int uv_timer_stop(UvTimerHandle handle); + [DllImport("libuv", CallingConvention = CallingConvention.Cdecl)] + unsafe public static extern long uv_now(UvLoopHandle loop); + [DllImport("WS2_32.dll", CallingConvention = CallingConvention.Winapi)] unsafe public static extern int WSAIoctl( IntPtr socket, diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/UvLoopHandle.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/UvLoopHandle.cs index 25bb3701b0..cbb654ccd1 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/UvLoopHandle.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/UvLoopHandle.cs @@ -33,6 +33,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking _uv.stop(this); } + public long Now() + { + return _uv.now(this); + } + unsafe protected override bool ReleaseHandle() { var memory = handle; diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServerLimits.cs b/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServerLimits.cs index 7682e015ae..57aaa031b9 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServerLimits.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServerLimits.cs @@ -23,8 +23,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel // Matches the default LimitRequestFields in Apache httpd. private int _maxRequestHeaderCount = 100; - // Matches the default http.sys keep-alive timouet. - private TimeSpan _keepAliveTimeout = TimeSpan.FromMinutes(2); + // Matches the default http.sys connection timeout. + private TimeSpan _connectionTimeout = TimeSpan.FromMinutes(2); /// /// Gets or sets the maximum size of the response buffer before write @@ -146,17 +146,17 @@ namespace Microsoft.AspNetCore.Server.Kestrel /// Gets or sets the keep-alive timeout. /// /// - /// Defaults to 2 minutes. Timeout granularity is in seconds. Sub-second values will be rounded to the next second. + /// Defaults to 2 minutes. /// public TimeSpan KeepAliveTimeout { get { - return _keepAliveTimeout; + return _connectionTimeout; } set { - _keepAliveTimeout = TimeSpan.FromSeconds(Math.Ceiling(value.TotalSeconds)); + _connectionTimeout = value; } } } diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/KeepAliveTimeoutTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/KeepAliveTimeoutTests.cs index 60be92f163..f5c202a4dd 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/KeepAliveTimeoutTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/KeepAliveTimeoutTests.cs @@ -3,8 +3,11 @@ using System; using System.IO; +using System.Text; +using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Testing; using Xunit; @@ -13,23 +16,25 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests public class KeepAliveTimeoutTests { private static readonly TimeSpan KeepAliveTimeout = TimeSpan.FromSeconds(10); - private static readonly int LongDelay = (int)TimeSpan.FromSeconds(30).TotalMilliseconds; - private static readonly int ShortDelay = LongDelay / 10; + private static readonly TimeSpan LongDelay = TimeSpan.FromSeconds(30); + private static readonly TimeSpan ShortDelay = TimeSpan.FromSeconds(LongDelay.TotalSeconds / 10); [Fact] public async Task TestKeepAliveTimeout() { - using (var server = CreateServer()) + var longRunningCancellationTokenSource = new CancellationTokenSource(); + var upgradeCancellationTokenSource = new CancellationTokenSource(); + + using (var server = CreateServer(longRunningCancellationTokenSource.Token, upgradeCancellationTokenSource.Token)) { var tasks = new[] { ConnectionClosedWhenKeepAliveTimeoutExpires(server), - ConnectionClosedWhenKeepAliveTimeoutExpiresAfterChunkedRequest(server), - KeepAliveTimeoutResetsBetweenContentLengthRequests(server), - KeepAliveTimeoutResetsBetweenChunkedRequests(server), - KeepAliveTimeoutNotTriggeredMidContentLengthRequest(server), - KeepAliveTimeoutNotTriggeredMidChunkedRequest(server), - ConnectionTimesOutWhenOpenedButNoRequestSent(server) + ConnectionKeptAliveBetweenRequests(server), + ConnectionNotTimedOutWhileRequestBeingSent(server), + ConnectionNotTimedOutWhileAppIsRunning(server, longRunningCancellationTokenSource), + ConnectionTimesOutWhenOpenedButNoRequestSent(server), + KeepAliveTimeoutDoesNotApplyToUpgradedConnections(server, upgradeCancellationTokenSource) }; await Task.WhenAll(tasks); @@ -59,110 +64,76 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } } - private async Task ConnectionClosedWhenKeepAliveTimeoutExpiresAfterChunkedRequest(TestServer server) + private async Task ConnectionKeptAliveBetweenRequests(TestServer server) { using (var connection = new TestConnection(server.Port)) { + for (var i = 0; i < 10; i++) + { + await connection.Send( + "GET / HTTP/1.1", + "", + ""); + await Task.Delay(ShortDelay); + } + + for (var i = 0; i < 10; i++) + { + await ReceiveResponse(connection, server.Context); + } + } + } + + private async Task ConnectionNotTimedOutWhileRequestBeingSent(TestServer server) + { + using (var connection = new TestConnection(server.Port)) + { + var cts = new CancellationTokenSource(); + cts.CancelAfter(LongDelay); + await connection.Send( "POST / HTTP/1.1", "Transfer-Encoding: chunked", "", - "5", "hello", - "6", " world", + ""); + + while (!cts.IsCancellationRequested) + { + await connection.Send( + "1", + "a", + ""); + } + + await connection.Send( "0", - "", - ""); + "", + ""); await ReceiveResponse(connection, server.Context); - - await Task.Delay(LongDelay); - - await Assert.ThrowsAsync(async () => - { - await connection.Send( - "GET / HTTP/1.1", - "", - ""); - await ReceiveResponse(connection, server.Context); - }); } } - private async Task KeepAliveTimeoutResetsBetweenContentLengthRequests(TestServer server) - { - using (var connection = new TestConnection(server.Port)) - { - for (var i = 0; i < 10; i++) - { - await connection.Send( - "GET / HTTP/1.1", - "", - ""); - await Task.Delay(ShortDelay); - } - - for (var i = 0; i < 10; i++) - { - await ReceiveResponse(connection, server.Context); - } - } - } - - private async Task KeepAliveTimeoutResetsBetweenChunkedRequests(TestServer server) - { - using (var connection = new TestConnection(server.Port)) - { - for (var i = 0; i < 10; i++) - { - await connection.Send( - "POST / HTTP/1.1", - "Transfer-Encoding: chunked", - "", - "5", "hello", - "6", " world", - "0", - "", - ""); - await Task.Delay(ShortDelay); - } - - for (var i = 0; i < 10; i++) - { - await ReceiveResponse(connection, server.Context); - } - } - } - - private async Task KeepAliveTimeoutNotTriggeredMidContentLengthRequest(TestServer server) + private async Task ConnectionNotTimedOutWhileAppIsRunning(TestServer server, CancellationTokenSource cts) { using (var connection = new TestConnection(server.Port)) { await connection.Send( - "POST / HTTP/1.1", - "Content-Length: 8", + "GET /longrunning HTTP/1.1", "", - "a"); - await Task.Delay(LongDelay); - await connection.Send("bcdefgh"); - await ReceiveResponse(connection, server.Context); - } - } + ""); + cts.CancelAfter(LongDelay); + + while (!cts.IsCancellationRequested) + { + await Task.Delay(1000); + } + + await ReceiveResponse(connection, server.Context); - private async Task KeepAliveTimeoutNotTriggeredMidChunkedRequest(TestServer server) - { - using (var connection = new TestConnection(server.Port)) - { await connection.Send( - "POST / HTTP/1.1", - "Transfer-Encoding: chunked", - "", - "5", "hello", - ""); - await Task.Delay(LongDelay); - await connection.Send( - "6", " world", - "0", - "", - ""); + "GET / HTTP/1.1", + "", + ""); await ReceiveResponse(connection, server.Context); } } @@ -182,9 +153,34 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } } - private TestServer CreateServer() + private async Task KeepAliveTimeoutDoesNotApplyToUpgradedConnections(TestServer server, CancellationTokenSource cts) { - return new TestServer(App, new TestServiceContext + using (var connection = new TestConnection(server.Port)) + { + await connection.Send( + "GET /upgrade HTTP/1.1", + "", + ""); + await connection.Receive( + "HTTP/1.1 101 Switching Protocols", + "Connection: Upgrade", + $"Date: {server.Context.DateHeaderValue}", + "", + ""); + cts.CancelAfter(LongDelay); + + while (!cts.IsCancellationRequested) + { + await Task.Delay(1000); + } + + await connection.Receive("hello, world"); + } + } + + private TestServer CreateServer(CancellationToken longRunningCt, CancellationToken upgradeCt) + { + return new TestServer(httpContext => App(httpContext, longRunningCt, upgradeCt), new TestServiceContext { ServerOptions = new KestrelServerOptions { @@ -197,11 +193,36 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests }); } - private async Task App(HttpContext httpContext) + private async Task App(HttpContext httpContext, CancellationToken longRunningCt, CancellationToken upgradeCt) { - const string response = "hello, world"; - httpContext.Response.ContentLength = response.Length; - await httpContext.Response.WriteAsync(response); + var ct = httpContext.RequestAborted; + + if (httpContext.Request.Path == "/longrunning") + { + while (!longRunningCt.IsCancellationRequested) + { + await Task.Delay(1000); + } + + await httpContext.Response.WriteAsync("hello, world"); + } + else if (httpContext.Request.Path == "/upgrade") + { + using (var stream = await httpContext.Features.Get().UpgradeAsync()) + { + while (!upgradeCt.IsCancellationRequested) + { + await Task.Delay(LongDelay); + } + + var responseBytes = Encoding.ASCII.GetBytes("hello, world"); + await stream.WriteAsync(responseBytes, 0, responseBytes.Length); + } + } + else + { + await httpContext.Response.WriteAsync("hello, world"); + } } private async Task ReceiveResponse(TestConnection connection, TestServiceContext testServiceContext) @@ -209,9 +230,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests await connection.Receive( "HTTP/1.1 200 OK", $"Date: {testServiceContext.DateHeaderValue}", - "Content-Length: 12", + "Transfer-Encoding: chunked", "", - "hello, world"); + "c", + "hello, world", + "0", + "", + ""); } } } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionTests.cs index 59f8c012a9..0d42df12f0 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionTests.cs @@ -1,4 +1,8 @@ -using System.Threading; +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System.Threading; +using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Server.Kestrel; using Microsoft.AspNetCore.Server.Kestrel.Internal; @@ -14,7 +18,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests public class ConnectionTests { [Fact] - public void DoesNotEndConnectionOnZeroRead() + public async Task DoesNotEndConnectionOnZeroRead() { var mockLibuv = new MockLibuv(); @@ -30,14 +34,19 @@ namespace Microsoft.AspNetCore.Server.KestrelTests ServerAddress = ServerAddress.FromUrl("http://127.0.0.1:0"), Thread = engine.Threads[0] }; - var socket = new MockSocket(mockLibuv, Thread.CurrentThread.ManagedThreadId, trace); - var connection = new Connection(context, socket); - connection.Start(); - Libuv.uv_buf_t ignored; - mockLibuv.AllocCallback(socket.InternalGetHandle(), 2048, out ignored); - mockLibuv.ReadCallback(socket.InternalGetHandle(), 0, ref ignored); - Assert.False(connection.SocketInput.CheckFinOrThrow()); + Connection connection = null; + await context.Thread.PostAsync(_ => + { + var socket = new MockSocket(mockLibuv, Thread.CurrentThread.ManagedThreadId, trace); + connection = new Connection(context, socket); + connection.Start(); + + Libuv.uv_buf_t ignored; + mockLibuv.AllocCallback(socket.InternalGetHandle(), 2048, out ignored); + mockLibuv.ReadCallback(socket.InternalGetHandle(), 0, ref ignored); + Assert.False(connection.SocketInput.CheckFinOrThrow()); + }, null); connection.ConnectionControl.End(ProduceEndType.SocketDisconnect); } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs index 18c0039860..66c0941c2b 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs @@ -12,6 +12,7 @@ using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.AspNetCore.Server.KestrelTests.TestHelpers; using Microsoft.AspNetCore.Testing; using Microsoft.Extensions.Internal; +using Moq; using Xunit; namespace Microsoft.AspNetCore.Server.KestrelTests @@ -724,6 +725,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { var connectionContext = new ConnectionContext() { + ConnectionControl = new Mock().Object, DateHeaderValueManager = new DateHeaderValueManager(), ServerAddress = ServerAddress.FromUrl("http://localhost:5000"), ServerOptions = new KestrelServerOptions(), @@ -770,6 +772,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { var connectionContext = new ConnectionContext() { + ConnectionControl = new Mock().Object, DateHeaderValueManager = new DateHeaderValueManager(), ServerAddress = ServerAddress.FromUrl("http://localhost:5000"), ServerOptions = new KestrelServerOptions(), @@ -786,6 +789,59 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } } + [Fact] + public void TakeStartLineDisablesKeepAliveTimeoutOnFirstByteAvailable() + { + var trace = new KestrelTrace(new TestKestrelTrace()); + var ltp = new LoggingThreadPool(trace); + using (var pool = new MemoryPool()) + using (var socketInput = new SocketInput(pool, ltp)) + { + var connectionControl = new Mock(); + var connectionContext = new ConnectionContext() + { + ConnectionControl = connectionControl.Object, + DateHeaderValueManager = new DateHeaderValueManager(), + ServerAddress = ServerAddress.FromUrl("http://localhost:5000"), + ServerOptions = new KestrelServerOptions(), + Log = trace + }; + var frame = new Frame(application: null, context: connectionContext); + frame.Reset(); + + var requestLineBytes = Encoding.ASCII.GetBytes("G"); + socketInput.IncomingData(requestLineBytes, 0, requestLineBytes.Length); + + frame.TakeStartLine(socketInput); + connectionControl.Verify(cc => cc.CancelTimeout()); + } + } + + [Fact] + public void TakeStartLineDoesNotDisableKeepAliveTimeoutIfNoDataAvailable() + { + var trace = new KestrelTrace(new TestKestrelTrace()); + var ltp = new LoggingThreadPool(trace); + using (var pool = new MemoryPool()) + using (var socketInput = new SocketInput(pool, ltp)) + { + var connectionControl = new Mock(); + var connectionContext = new ConnectionContext() + { + ConnectionControl = connectionControl.Object, + DateHeaderValueManager = new DateHeaderValueManager(), + ServerAddress = ServerAddress.FromUrl("http://localhost:5000"), + ServerOptions = new KestrelServerOptions(), + Log = trace + }; + var frame = new Frame(application: null, context: connectionContext); + frame.Reset(); + + frame.TakeStartLine(socketInput); + connectionControl.Verify(cc => cc.CancelTimeout(), Times.Never); + } + } + [Fact] public void TakeMessageHeadersCallsConsumingCompleteWithFurthestExamined() { @@ -864,5 +920,35 @@ namespace Microsoft.AspNetCore.Server.KestrelTests Assert.Equal(false, frame.TakeMessageHeaders(socketInput, (FrameRequestHeaders)frame.RequestHeaders)); } } + + [Fact] + public void RequestProcessingAsyncEnablesKeepAliveTimeout() + { + var trace = new KestrelTrace(new TestKestrelTrace()); + var ltp = new LoggingThreadPool(trace); + using (var pool = new MemoryPool()) + using (var socketInput = new SocketInput(pool, ltp)) + { + var connectionControl = new Mock(); + var connectionContext = new ConnectionContext() + { + ConnectionControl = connectionControl.Object, + DateHeaderValueManager = new DateHeaderValueManager(), + ServerAddress = ServerAddress.FromUrl("http://localhost:5000"), + ServerOptions = new KestrelServerOptions(), + Log = trace + }; + var frame = new Frame(application: null, context: connectionContext); + frame.Reset(); + + var requestProcessingTask = frame.RequestProcessingAsync(); + connectionControl.Verify(cc => cc.SetTimeout((long)connectionContext.ServerOptions.Limits.KeepAliveTimeout.TotalMilliseconds)); + + frame.Stop(); + socketInput.IncomingFin(); + + requestProcessingTask.Wait(); + } + } } } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerLimitsTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerLimitsTests.cs index 9edfd5d3c9..8481fc258d 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerLimitsTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerLimitsTests.cs @@ -161,11 +161,11 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [InlineData(2.1)] [InlineData(2.5)] [InlineData(2.9)] - public void KeepAliveTimeoutIsRoundedToTheNextSecond(double seconds) + public void KeepAliveTimeoutValid(double seconds) { var o = new KestrelServerLimits(); o.KeepAliveTimeout = TimeSpan.FromSeconds(seconds); - Assert.Equal(Math.Ceiling(seconds), o.KeepAliveTimeout.TotalSeconds); + Assert.Equal(seconds, o.KeepAliveTimeout.TotalSeconds); } } } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockConnection.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockConnection.cs index 930c1ec6d8..7a095cfcff 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockConnection.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockConnection.cs @@ -15,6 +15,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests.TestHelpers public MockConnection(KestrelServerOptions options) { + ConnectionControl = this; RequestAbortedSource = new CancellationTokenSource(); ServerOptions = options; } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockLibuv.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockLibuv.cs index 80584f65be..55ad9161d4 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockLibuv.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockLibuv.cs @@ -129,6 +129,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests.TestHelpers _uv_timer_init = (loop, handle) => 0; _uv_timer_start = (handle, callback, timeout, repeat) => 0; _uv_timer_stop = handle => 0; + _uv_now = (loop) => DateTime.UtcNow.Ticks / TimeSpan.TicksPerMillisecond; } public Func, int> OnWrite { get; set; } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestInput.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/TestInput.cs index 5bb230ab4a..a9b357d139 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/TestInput.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/TestInput.cs @@ -22,7 +22,12 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { var trace = new KestrelTrace(new TestKestrelTrace()); var ltp = new LoggingThreadPool(trace); - var context = new Frame(null, new ConnectionContext() { ServerAddress = new ServerAddress() }) + var connectionContext = new ConnectionContext() + { + ServerAddress = new ServerAddress(), + ServerOptions = new KestrelServerOptions() + }; + var context = new Frame(null, connectionContext) { DateHeaderValueManager = new DateHeaderValueManager(), ServerAddress = ServerAddress.FromUrl("http://localhost:5000"), @@ -63,7 +68,11 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { } - public void Stop() + public void SetTimeout(long milliseconds) + { + } + + public void CancelTimeout() { } From afa89b39932f3f0a9567779029d996f5e78b210a Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Fri, 16 Sep 2016 09:09:26 -0700 Subject: [PATCH 0886/1662] Change SkipReason for ThreadCountTests on OS X. --- .../ThreadCountTests.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ThreadCountTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ThreadCountTests.cs index ebcf01b09a..e4a723a9d1 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ThreadCountTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ThreadCountTests.cs @@ -16,7 +16,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { [ConditionalTheory] [MemberData(nameof(OneToTen))] - [OSSkipCondition(OperatingSystems.MacOSX, SkipReason = "Test failures pending investigation.")] + [OSSkipCondition(OperatingSystems.MacOSX, SkipReason = "Tests fail on OS X due to low file descriptor limit.")] public async Task OneToTenThreads(int threadCount) { var hostBuilder = new WebHostBuilder() @@ -31,7 +31,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { return context.Response.WriteAsync("Hello World"); }); - }); + }); using (var host = hostBuilder.Build()) { @@ -46,7 +46,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests var requestTask = client.GetStringAsync($"http://localhost:{host.GetPort()}/"); requestTasks.Add(requestTask); } - + foreach (var result in await Task.WhenAll(requestTasks)) { Assert.Equal("Hello World", result); From 63509b9e1076c3039ea61e6c3d10a05bde2296dd Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Tue, 13 Sep 2016 11:03:12 -0700 Subject: [PATCH 0887/1662] Make FrameRequestStream.CopyToAsync(...) copyless - Add tests for when the CopyToAsync destinationStream throws. - Add test to verify the destination stream sees the same array written to by the producer. --- .../Internal/Http/FrameRequestStream.cs | 22 +- .../Internal/Http/MessageBody.cs | 404 ++++++++++++------ .../Internal/Http/SocketInputExtensions.cs | 48 ++- .../MemoryPoolIteratorExtensions.cs | 26 ++ .../FrameRequestStreamTests.cs | 57 +++ .../MemoryPoolIteratorTests.cs | 122 +++++- .../MessageBodyTests.cs | 205 ++++++++- .../SocketInputTests.cs | 80 +++- 8 files changed, 806 insertions(+), 158 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameRequestStream.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameRequestStream.cs index 3889a02db5..b75effe5e8 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameRequestStream.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameRequestStream.cs @@ -119,8 +119,26 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var task = ValidateState(cancellationToken); if (task == null) { - // Needs .AsTask to match Stream's Async method return types - return _body.ReadAsync(new ArraySegment(buffer, offset, count), cancellationToken).AsTask(); + return _body.ReadAsync(new ArraySegment(buffer, offset, count), cancellationToken); + } + return task; + } + + public override Task CopyToAsync(Stream destination, int bufferSize, CancellationToken cancellationToken) + { + if (destination == null) + { + throw new ArgumentNullException(nameof(destination)); + } + if (bufferSize <= 0) + { + throw new ArgumentException($"{nameof(bufferSize)} must be positive.", nameof(bufferSize)); + } + + var task = ValidateState(cancellationToken); + if (task == null) + { + return _body.CopyToAsync(destination, cancellationToken); } return task; } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/MessageBody.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/MessageBody.cs index 65bbe9a808..784f8d97de 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/MessageBody.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/MessageBody.cs @@ -2,9 +2,11 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.IO; using System.Numerics; using System.Threading; using System.Threading.Tasks; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.Extensions.Internal; namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http @@ -12,7 +14,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http public abstract class MessageBody { private readonly Frame _context; - private int _send100Continue = 1; + private bool _send100Continue = true; protected MessageBody(Frame context) { @@ -21,80 +23,205 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http public bool RequestKeepAlive { get; protected set; } - public ValueTask ReadAsync(ArraySegment buffer, CancellationToken cancellationToken = default(CancellationToken)) + public Task ReadAsync(ArraySegment buffer, CancellationToken cancellationToken = default(CancellationToken)) { - var send100Continue = 0; - var result = ReadAsyncImplementation(buffer, cancellationToken); - if (!result.IsCompleted) + var task = PeekAsync(cancellationToken); + + if (!task.IsCompleted) { - send100Continue = Interlocked.Exchange(ref _send100Continue, 0); + TryProduceContinue(); + + // Incomplete Task await result + return ReadAsyncAwaited(task, buffer); } - if (send100Continue == 1) + else { - _context.FrameControl.ProduceContinue(); + var readSegment = task.Result; + var consumed = CopyReadSegment(readSegment, buffer); + + return consumed == 0 ? TaskCache.DefaultCompletedTask : Task.FromResult(consumed); } - return result; + } + + private async Task ReadAsyncAwaited(ValueTask> currentTask, ArraySegment buffer) + { + return CopyReadSegment(await currentTask, buffer); + } + + private int CopyReadSegment(ArraySegment readSegment, ArraySegment buffer) + { + var consumed = Math.Min(readSegment.Count, buffer.Count); + + if (consumed != 0) + { + Buffer.BlockCopy(readSegment.Array, readSegment.Offset, buffer.Array, buffer.Offset, consumed); + ConsumedBytes(consumed); + } + + return consumed; + } + + public Task CopyToAsync(Stream destination, CancellationToken cancellationToken = default(CancellationToken)) + { + var peekTask = PeekAsync(cancellationToken); + + while (peekTask.IsCompleted) + { + // ValueTask uses .GetAwaiter().GetResult() if necessary + var segment = peekTask.Result; + + if (segment.Count == 0) + { + return TaskCache.CompletedTask; + } + + Task destinationTask; + try + { + destinationTask = destination.WriteAsync(segment.Array, segment.Offset, segment.Count, cancellationToken); + } + catch + { + ConsumedBytes(segment.Count); + throw; + } + + if (!destinationTask.IsCompleted) + { + return CopyToAsyncDestinationAwaited(destinationTask, segment.Count, destination, cancellationToken); + } + + ConsumedBytes(segment.Count); + + // Surface errors if necessary + destinationTask.GetAwaiter().GetResult(); + + peekTask = PeekAsync(cancellationToken); + } + + TryProduceContinue(); + + return CopyToAsyncPeekAwaited(peekTask, destination, cancellationToken); + } + + private async Task CopyToAsyncPeekAwaited( + ValueTask> peekTask, + Stream destination, + CancellationToken cancellationToken = default(CancellationToken)) + { + while (true) + { + var segment = await peekTask; + + if (segment.Count == 0) + { + return; + } + + try + { + await destination.WriteAsync(segment.Array, segment.Offset, segment.Count, cancellationToken); + } + finally + { + ConsumedBytes(segment.Count); + } + + peekTask = PeekAsync(cancellationToken); + } + } + + private async Task CopyToAsyncDestinationAwaited( + Task destinationTask, + int bytesConsumed, + Stream destination, + CancellationToken cancellationToken = default(CancellationToken)) + { + try + { + await destinationTask; + } + finally + { + ConsumedBytes(bytesConsumed); + } + + var peekTask = PeekAsync(cancellationToken); + + if (!peekTask.IsCompleted) + { + TryProduceContinue(); + } + + await CopyToAsyncPeekAwaited(peekTask, destination, cancellationToken); } public Task Consume(CancellationToken cancellationToken = default(CancellationToken)) { - ValueTask result; - var send100checked = false; - do + while (true) { - result = ReadAsyncImplementation(default(ArraySegment), cancellationToken); - if (!result.IsCompleted) + var task = PeekAsync(cancellationToken); + if (!task.IsCompleted) { - if (!send100checked) - { - if (Interlocked.Exchange(ref _send100Continue, 0) == 1) - { - _context.FrameControl.ProduceContinue(); - } - send100checked = true; - } + TryProduceContinue(); + // Incomplete Task await result - return ConsumeAwaited(result.AsTask(), cancellationToken); + return ConsumeAwaited(task, cancellationToken); } - // ValueTask uses .GetAwaiter().GetResult() if necessary - else if (result.Result == 0) - { - // Completed Task, end of stream - return TaskCache.CompletedTask; - } - - } while (true); - } - - private async Task ConsumeAwaited(Task currentTask, CancellationToken cancellationToken) - { - if (await currentTask == 0) - { - return; - } - - ValueTask result; - do - { - result = ReadAsyncImplementation(default(ArraySegment), cancellationToken); - if (result.IsCompleted) + else { // ValueTask uses .GetAwaiter().GetResult() if necessary - if (result.Result == 0) + if (task.Result.Count == 0) { // Completed Task, end of stream - return; - } - else - { - // Completed Task, get next Task rather than await - continue; + return TaskCache.CompletedTask; } + + ConsumedBytes(task.Result.Count); } - } while (await result != 0); + } } - public abstract ValueTask ReadAsyncImplementation(ArraySegment buffer, CancellationToken cancellationToken); + private async Task ConsumeAwaited(ValueTask> currentTask, CancellationToken cancellationToken) + { + while (true) + { + var count = (await currentTask).Count; + + if (count == 0) + { + // Completed Task, end of stream + return; + } + + ConsumedBytes(count); + currentTask = PeekAsync(cancellationToken); + } + } + + private void TryProduceContinue() + { + if (_send100Continue) + { + _context.FrameControl.ProduceContinue(); + _send100Continue = false; + } + } + + private void ConsumedBytes(int count) + { + var scan = _context.SocketInput.ConsumingStart(); + scan.Skip(count); + _context.SocketInput.ConsumingComplete(scan, scan); + + OnConsumedBytes(count); + } + + protected abstract ValueTask> PeekAsync(CancellationToken cancellationToken); + + protected virtual void OnConsumedBytes(int count) + { + } public static MessageBody For( HttpVersion httpVersion, @@ -145,9 +272,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { } - public override ValueTask ReadAsyncImplementation(ArraySegment buffer, CancellationToken cancellationToken) + protected override ValueTask> PeekAsync(CancellationToken cancellationToken) { - return _context.SocketInput.ReadAsync(buffer.Array, buffer.Offset, buffer.Array == null ? 8192 : buffer.Count); + return _context.SocketInput.PeekAsync(); } } @@ -164,49 +291,65 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _inputLength = _contentLength; } - public override ValueTask ReadAsyncImplementation(ArraySegment buffer, CancellationToken cancellationToken) + protected override ValueTask> PeekAsync(CancellationToken cancellationToken) { - var input = _context.SocketInput; - - var inputLengthLimit = (int)Math.Min(_inputLength, int.MaxValue); - var limit = buffer.Array == null ? inputLengthLimit : Math.Min(buffer.Count, inputLengthLimit); + var limit = (int)Math.Min(_inputLength, int.MaxValue); if (limit == 0) { - return new ValueTask(0); + return new ValueTask>(); } - var task = _context.SocketInput.ReadAsync(buffer.Array, buffer.Offset, limit); + var task = _context.SocketInput.PeekAsync(); if (task.IsCompleted) { // .GetAwaiter().GetResult() done by ValueTask if needed - var actual = task.Result; - _inputLength -= actual; + var actual = Math.Min(task.Result.Count, limit); - if (actual == 0) + if (task.Result.Count == 0) { _context.RejectRequest(RequestRejectionReason.UnexpectedEndOfRequestContent); } - return new ValueTask(actual); + if (task.Result.Count < _inputLength) + { + return task; + } + else + { + var result = task.Result; + var part = new ArraySegment(result.Array, result.Offset, (int)_inputLength); + return new ValueTask>(part); + } } else { - return new ValueTask(ReadAsyncAwaited(task.AsTask())); + return new ValueTask>(PeekAsyncAwaited(task)); } } - private async Task ReadAsyncAwaited(Task task) + private async Task> PeekAsyncAwaited(ValueTask> task) { - var actual = await task; - _inputLength -= actual; + var segment = await task; - if (actual == 0) + if (segment.Count == 0) { _context.RejectRequest(RequestRejectionReason.UnexpectedEndOfRequestContent); } - return actual; + if (segment.Count <= _inputLength) + { + return segment; + } + else + { + return new ArraySegment(segment.Array, segment.Offset, (int)_inputLength); + } + } + + protected override void OnConsumedBytes(int count) + { + _inputLength -= count; } } @@ -219,31 +362,39 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http // https://github.com/dotnet/corefx/issues/8825 private Vector _vectorCRs = new Vector((byte)'\r'); + private readonly SocketInput _input; + private readonly FrameRequestHeaders _requestHeaders; private int _inputLength; + private Mode _mode = Mode.Prefix; - private FrameRequestHeaders _requestHeaders; public ForChunkedEncoding(bool keepAlive, FrameRequestHeaders headers, Frame context) : base(context) { RequestKeepAlive = keepAlive; + _input = _context.SocketInput; _requestHeaders = headers; } - public override ValueTask ReadAsyncImplementation(ArraySegment buffer, CancellationToken cancellationToken) + protected override ValueTask> PeekAsync(CancellationToken cancellationToken) { - return new ValueTask(ReadStateMachineAsync(_context.SocketInput, buffer, cancellationToken)); + return new ValueTask>(PeekStateMachineAsync()); } - private async Task ReadStateMachineAsync(SocketInput input, ArraySegment buffer, CancellationToken cancellationToken) + protected override void OnConsumedBytes(int count) + { + _inputLength -= count; + } + + private async Task> PeekStateMachineAsync() { while (_mode < Mode.Trailer) { while (_mode == Mode.Prefix) { - var fin = input.CheckFinOrThrow(); + var fin = _input.CheckFinOrThrow(); - ParseChunkedPrefix(input); + ParseChunkedPrefix(); if (_mode != Mode.Prefix) { @@ -254,14 +405,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _context.RejectRequest(RequestRejectionReason.ChunkedRequestIncomplete); } - await input; + await _input; } while (_mode == Mode.Extension) { - var fin = input.CheckFinOrThrow(); + var fin = _input.CheckFinOrThrow(); - ParseExtension(input); + ParseExtension(); if (_mode != Mode.Extension) { @@ -272,18 +423,18 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _context.RejectRequest(RequestRejectionReason.ChunkedRequestIncomplete); } - await input; + await _input; } while (_mode == Mode.Data) { - var fin = input.CheckFinOrThrow(); + var fin = _input.CheckFinOrThrow(); - int actual = ReadChunkedData(input, buffer.Array, buffer.Offset, buffer.Count); + var segment = PeekChunkedData(); - if (actual != 0) + if (segment.Count != 0) { - return actual; + return segment; } else if (_mode != Mode.Data) { @@ -294,14 +445,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _context.RejectRequest(RequestRejectionReason.ChunkedRequestIncomplete); } - await input; + await _input; } while (_mode == Mode.Suffix) { - var fin = input.CheckFinOrThrow(); + var fin = _input.CheckFinOrThrow(); - ParseChunkedSuffix(input); + ParseChunkedSuffix(); if (_mode != Mode.Suffix) { @@ -312,16 +463,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _context.RejectRequest(RequestRejectionReason.ChunkedRequestIncomplete); } - await input; + await _input; } } // Chunks finished, parse trailers while (_mode == Mode.Trailer) { - var fin = input.CheckFinOrThrow(); + var fin = _input.CheckFinOrThrow(); - ParseChunkedTrailer(input); + ParseChunkedTrailer(); if (_mode != Mode.Trailer) { @@ -332,16 +483,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _context.RejectRequest(RequestRejectionReason.ChunkedRequestIncomplete); } - await input; + await _input; } if (_mode == Mode.TrailerHeaders) { - while (!_context.TakeMessageHeaders(input, _requestHeaders)) + while (!_context.TakeMessageHeaders(_input, _requestHeaders)) { - if (input.CheckFinOrThrow()) + if (_input.CheckFinOrThrow()) { - if (_context.TakeMessageHeaders(input, _requestHeaders)) + if (_context.TakeMessageHeaders(_input, _requestHeaders)) { break; } @@ -351,18 +502,18 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } } - await input; + await _input; } _mode = Mode.Complete; } - return 0; + return default(ArraySegment); } - private void ParseChunkedPrefix(SocketInput input) + private void ParseChunkedPrefix() { - var scan = input.ConsumingStart(); + var scan = _input.ConsumingStart(); var consumed = scan; try { @@ -416,13 +567,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } finally { - input.ConsumingComplete(consumed, scan); + _input.ConsumingComplete(consumed, scan); } } - private void ParseExtension(SocketInput input) + private void ParseExtension() { - var scan = input.ConsumingStart(); + var scan = _input.ConsumingStart(); var consumed = scan; try { @@ -460,36 +611,37 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } finally { - input.ConsumingComplete(consumed, scan); + _input.ConsumingComplete(consumed, scan); } } - private int ReadChunkedData(SocketInput input, byte[] buffer, int offset, int count) + private ArraySegment PeekChunkedData() { - var scan = input.ConsumingStart(); - int actual; - try - { - var limit = buffer == null ? _inputLength : Math.Min(count, _inputLength); - scan = scan.CopyTo(buffer, offset, limit, out actual); - _inputLength -= actual; - } - finally - { - input.ConsumingComplete(scan, scan); - } - if (_inputLength == 0) { _mode = Mode.Suffix; + return default(ArraySegment); } - return actual; + var scan = _input.ConsumingStart(); + var segment = scan.PeekArraySegment(); + int actual = Math.Min(segment.Count, _inputLength); + // Nothing is consumed yet. ConsumedBytes(int) will move the iterator. + _input.ConsumingComplete(scan, scan); + + if (actual == segment.Count) + { + return segment; + } + else + { + return new ArraySegment(segment.Array, segment.Offset, actual); + } } - private void ParseChunkedSuffix(SocketInput input) + private void ParseChunkedSuffix() { - var scan = input.ConsumingStart(); + var scan = _input.ConsumingStart(); var consumed = scan; try { @@ -511,13 +663,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } finally { - input.ConsumingComplete(consumed, scan); + _input.ConsumingComplete(consumed, scan); } } - private void ParseChunkedTrailer(SocketInput input) + private void ParseChunkedTrailer() { - var scan = input.ConsumingStart(); + var scan = _input.ConsumingStart(); var consumed = scan; try { @@ -540,7 +692,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } finally { - input.ConsumingComplete(consumed, scan); + _input.ConsumingComplete(consumed, scan); } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/SocketInputExtensions.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/SocketInputExtensions.cs index 2ff1f4c037..8dd26803ab 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/SocketInputExtensions.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/SocketInputExtensions.cs @@ -1,7 +1,9 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; using System.Threading.Tasks; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { @@ -18,14 +20,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var end = begin.CopyTo(buffer, offset, count, out actual); input.ConsumingComplete(end, end); - if (actual != 0) + if (actual != 0 || fin) { return new ValueTask(actual); } - else if (fin) - { - return new ValueTask(0); - } } return new ValueTask(input.ReadAsyncAwaited(buffer, offset, count)); @@ -44,13 +42,47 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var end = begin.CopyTo(buffer, offset, count, out actual); input.ConsumingComplete(end, end); - if (actual != 0) + if (actual != 0 || fin) { return actual; } - else if (fin) + } + } + + public static ValueTask> PeekAsync(this SocketInput input) + { + while (input.IsCompleted) + { + var fin = input.CheckFinOrThrow(); + + var begin = input.ConsumingStart(); + var segment = begin.PeekArraySegment(); + input.ConsumingComplete(begin, begin); + + if (segment.Count != 0 || fin) { - return 0; + return new ValueTask>(segment); + } + } + + return new ValueTask>(input.PeekAsyncAwaited()); + } + + private static async Task> PeekAsyncAwaited(this SocketInput input) + { + while (true) + { + await input; + + var fin = input.CheckFinOrThrow(); + + var begin = input.ConsumingStart(); + var segment = begin.PeekArraySegment(); + input.ConsumingComplete(begin, begin); + + if (segment.Count != 0 || fin) + { + return segment; } } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolIteratorExtensions.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolIteratorExtensions.cs index 6bb47c0578..6cc8f38bce 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolIteratorExtensions.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolIteratorExtensions.cs @@ -232,6 +232,32 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure return new ArraySegment(array, 0, length); } + public static ArraySegment PeekArraySegment(this MemoryPoolIterator iter) + { + if (iter.IsDefault || iter.IsEnd) + { + return default(ArraySegment); + } + + if (iter.Index < iter.Block.End) + { + return new ArraySegment(iter.Block.Array, iter.Index, iter.Block.End - iter.Index); + } + + var block = iter.Block.Next; + while (block != null) + { + if (block.Start < block.End) + { + return new ArraySegment(block.Array, block.Start, block.End - block.Start); + } + block = block.Next; + } + + // The following should be unreachable due to the IsEnd check above. + throw new InvalidOperationException("This should be unreachable!"); + } + /// /// Checks that up to 8 bytes from correspond to a known HTTP method. /// diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameRequestStreamTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameRequestStreamTests.cs index cbe4c4ccb6..5d1c96e0f8 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameRequestStreamTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameRequestStreamTests.cs @@ -5,6 +5,7 @@ using System; using System.IO; using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; +using Moq; using Xunit; namespace Microsoft.AspNetCore.Server.KestrelTests @@ -126,5 +127,61 @@ namespace Microsoft.AspNetCore.Server.KestrelTests Assert.True(task.IsFaulted); Assert.Same(error, task.Exception.InnerException); } + + [Fact] + public void StopAcceptingReadsCausesReadToThrowObjectDisposedException() + { + var stream = new FrameRequestStream(); + stream.StartAcceptingReads(null); + stream.StopAcceptingReads(); + Assert.Throws(() => { stream.ReadAsync(new byte[1], 0, 1); }); + } + + [Fact] + public void AbortCausesCopyToAsyncToCancel() + { + var stream = new FrameRequestStream(); + stream.StartAcceptingReads(null); + stream.Abort(); + var task = stream.CopyToAsync(Mock.Of()); + Assert.True(task.IsCanceled); + } + + [Fact] + public void AbortWithErrorCausesCopyToAsyncToCancel() + { + var stream = new FrameRequestStream(); + stream.StartAcceptingReads(null); + var error = new Exception(); + stream.Abort(error); + var task = stream.CopyToAsync(Mock.Of()); + Assert.True(task.IsFaulted); + Assert.Same(error, task.Exception.InnerException); + } + + [Fact] + public void StopAcceptingReadsCausesCopyToAsyncToThrowObjectDisposedException() + { + var stream = new FrameRequestStream(); + stream.StartAcceptingReads(null); + stream.StopAcceptingReads(); + Assert.Throws(() => { stream.CopyToAsync(Mock.Of()); }); + } + + [Fact] + public void NullDestinationCausesCopyToAsyncToThrowArgumentNullException() + { + var stream = new FrameRequestStream(); + stream.StartAcceptingReads(null); + Assert.Throws(() => { stream.CopyToAsync(null); }); + } + + [Fact] + public void ZeroBufferSizeCausesCopyToAsyncToThrowArgumentException() + { + var stream = new FrameRequestStream(); + stream.StartAcceptingReads(null); + Assert.Throws(() => { stream.CopyToAsync(Mock.Of(), 0); }); + } } } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolIteratorTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolIteratorTests.cs index fe450431e6..5424514870 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolIteratorTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolIteratorTests.cs @@ -88,7 +88,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests public void MemorySeek(string raw, string search, char expectResult, int expectIndex) { var block = _pool.Lease(); - var chars = raw.ToCharArray().Select(c => (byte)c).ToArray(); + var chars = raw.ToCharArray().Select(c => (byte) c).ToArray(); Buffer.BlockCopy(chars, 0, block.Array, block.Start, chars.Length); block.End += chars.Length; @@ -98,20 +98,20 @@ namespace Microsoft.AspNetCore.Server.KestrelTests int found = -1; if (searchFor.Length == 1) { - var search0 = new Vector((byte)searchFor[0]); + var search0 = new Vector((byte) searchFor[0]); found = begin.Seek(ref search0); } else if (searchFor.Length == 2) { - var search0 = new Vector((byte)searchFor[0]); - var search1 = new Vector((byte)searchFor[1]); + var search0 = new Vector((byte) searchFor[0]); + var search1 = new Vector((byte) searchFor[1]); found = begin.Seek(ref search0, ref search1); } else if (searchFor.Length == 3) { - var search0 = new Vector((byte)searchFor[0]); - var search1 = new Vector((byte)searchFor[1]); - var search2 = new Vector((byte)searchFor[2]); + var search0 = new Vector((byte) searchFor[0]); + var search1 = new Vector((byte) searchFor[1]); + var search2 = new Vector((byte) searchFor[2]); found = begin.Seek(ref search0, ref search1, ref search2); } else @@ -176,7 +176,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests head = blocks[0].GetIterator(); for (var i = 0; i < 64; ++i) { - Assert.True(head.Put((byte)i), $"Fail to put data at {i}."); + Assert.True(head.Put((byte) i), $"Fail to put data at {i}."); } // Can't put anything by the end @@ -188,6 +188,112 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } } + [Fact] + public void PeekArraySegment() + { + // Arrange + var block = _pool.Lease(); + var bytes = new byte[] {0, 1, 2, 3, 4, 5, 6, 7}; + Buffer.BlockCopy(bytes, 0, block.Array, block.Start, bytes.Length); + block.End += bytes.Length; + var scan = block.GetIterator(); + var originalIndex = scan.Index; + + // Act + var result = scan.PeekArraySegment(); + + // Assert + Assert.Equal(new byte[] {0, 1, 2, 3, 4, 5, 6, 7}, result); + Assert.Equal(originalIndex, scan.Index); + + _pool.Return(block); + } + + [Fact] + public void PeekArraySegmentOnDefaultIteratorReturnsDefaultArraySegment() + { + // Assert.Equals doesn't work since xunit tries to access the underlying array. + Assert.True(default(ArraySegment).Equals(default(MemoryPoolIterator).PeekArraySegment())); + } + + [Fact] + public void PeekArraySegmentAtEndOfDataReturnsDefaultArraySegment() + { + // Arrange + var block = _pool.Lease(); + var bytes = new byte[] {0, 1, 2, 3, 4, 5, 6, 7}; + Buffer.BlockCopy(bytes, 0, block.Array, block.Start, bytes.Length); + block.End += bytes.Length; + block.Start = block.End; + + var scan = block.GetIterator(); + + // Act + var result = scan.PeekArraySegment(); + + // Assert + // Assert.Equals doesn't work since xunit tries to access the underlying array. + Assert.True(default(ArraySegment).Equals(result)); + + _pool.Return(block); + } + + [Fact] + public void PeekArraySegmentAtBlockBoundary() + { + // Arrange + var firstBlock = _pool.Lease(); + var lastBlock = _pool.Lease(); + + var firstBytes = new byte[] { 0, 1, 2, 3, 4, 5, 6, 7 }; + var lastBytes = new byte[] { 8, 9, 10, 11, 12, 13, 14, 15 }; + + Buffer.BlockCopy(firstBytes, 0, firstBlock.Array, firstBlock.Start, firstBytes.Length); + firstBlock.End += lastBytes.Length; + + firstBlock.Next = lastBlock; + Buffer.BlockCopy(lastBytes, 0, lastBlock.Array, lastBlock.Start, lastBytes.Length); + lastBlock.End += lastBytes.Length; + + var scan = firstBlock.GetIterator(); + var originalIndex = scan.Index; + var originalBlock = scan.Block; + + // Act + var result = scan.PeekArraySegment(); + + // Assert + Assert.Equal(new byte[] { 0, 1, 2, 3, 4, 5, 6, 7 }, result); + Assert.Equal(originalBlock, scan.Block); + Assert.Equal(originalIndex, scan.Index); + + // Act + // Advance past the data in the first block + scan.Skip(8); + result = scan.PeekArraySegment(); + + // Assert + Assert.Equal(new byte[] { 8, 9, 10, 11, 12, 13, 14, 15 }, result); + Assert.Equal(originalBlock, scan.Block); + Assert.Equal(originalIndex + 8, scan.Index); + + // Act + // Add anther empty block between the first and last block + var middleBlock = _pool.Lease(); + firstBlock.Next = middleBlock; + middleBlock.Next = lastBlock; + result = scan.PeekArraySegment(); + + // Assert + Assert.Equal(new byte[] { 8, 9, 10, 11, 12, 13, 14, 15 }, result); + Assert.Equal(originalBlock, scan.Block); + Assert.Equal(originalIndex + 8, scan.Index); + + _pool.Return(firstBlock); + _pool.Return(middleBlock); + _pool.Return(lastBlock); + } + [Fact] public void PeekLong() { diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/MessageBodyTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/MessageBodyTests.cs index 2dcb19ffef..9dd54a75d0 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/MessageBodyTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/MessageBodyTests.cs @@ -2,10 +2,18 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; using System.Text; +using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; +using Microsoft.AspNetCore.Server.KestrelTests.TestHelpers; +using Microsoft.Extensions.Internal; +using Moq; using Xunit; +using Xunit.Sdk; namespace Microsoft.AspNetCore.Server.KestrelTests { @@ -68,23 +76,119 @@ namespace Microsoft.AspNetCore.Server.KestrelTests // Input needs to be greater than 4032 bytes to allocate a block not backed by a slab. var largeInput = new string('a', 8192); - input.Add(largeInput, true); + input.Add(largeInput); // Add a smaller block to the end so that SocketInput attempts to return the large // block to the memory pool. - input.Add("Hello", true); + input.Add("Hello", fin: true); - var readBuffer = new byte[8192]; + var ms = new MemoryStream(); - var count1 = await stream.ReadAsync(readBuffer, 0, 8192); - Assert.Equal(8192, count1); - AssertASCII(largeInput, new ArraySegment(readBuffer, 0, 8192)); + await stream.CopyToAsync(ms); + var requestArray = ms.ToArray(); + Assert.Equal(8197, requestArray.Length); + AssertASCII(largeInput + "Hello", new ArraySegment(requestArray, 0, requestArray.Length)); - var count2 = await stream.ReadAsync(readBuffer, 0, 8192); - Assert.Equal(5, count2); - AssertASCII("Hello", new ArraySegment(readBuffer, 0, 5)); + var count = await stream.ReadAsync(new byte[1], 0, 1); + Assert.Equal(0, count); + } + } - var count3 = await stream.ReadAsync(readBuffer, 0, 8192); - Assert.Equal(0, count3); + public static IEnumerable StreamData => new[] + { + new object[] { new ThrowOnWriteSynchronousStream() }, + new object[] { new ThrowOnWriteAsynchronousStream() }, + }; + + public static IEnumerable RequestData => new[] + { + // Remaining Data + new object[] { new FrameRequestHeaders { HeaderConnection = "close" }, new[] { "Hello ", "World!" } }, + // Content-Length + new object[] { new FrameRequestHeaders { HeaderContentLength = "12" }, new[] { "Hello ", "World!" } }, + // Chunked + new object[] { new FrameRequestHeaders { HeaderTransferEncoding = "chunked" }, new[] { "6\r\nHello \r\n", "6\r\nWorld!\r\n0\r\n\r\n" } }, + }; + + public static IEnumerable CombinedData => + from stream in StreamData + from request in RequestData + select new[] { stream[0], request[0], request[1] }; + + [Theory] + [MemberData(nameof(RequestData))] + public async Task CopyToAsyncDoesNotCopyBlocks(FrameRequestHeaders headers, string[] data) + { + var writeCount = 0; + var writeTcs = new TaskCompletionSource(); + var mockDestination = new Mock(); + + mockDestination + .Setup(m => m.WriteAsync(It.IsAny(), It.IsAny(), It.IsAny(), CancellationToken.None)) + .Callback((byte[] buffer, int offset, int count, CancellationToken cancellationToken) => + { + writeTcs.SetResult(buffer); + writeCount++; + }) + .Returns(TaskCache.CompletedTask); + + using (var input = new TestInput()) + { + var body = MessageBody.For(HttpVersion.Http11, headers, input.FrameContext); + + var copyToAsyncTask = body.CopyToAsync(mockDestination.Object); + + // The block returned by IncomingStart always has at least 2048 available bytes, + // so no need to bounds check in this test. + var socketInput = input.FrameContext.SocketInput; + var bytes = Encoding.ASCII.GetBytes(data[0]); + var block = socketInput.IncomingStart(); + Buffer.BlockCopy(bytes, 0, block.Array, block.End, bytes.Length); + socketInput.IncomingComplete(bytes.Length, null); + + // Verify the block passed to WriteAsync is the same one incoming data was written into. + Assert.Same(block.Array, await writeTcs.Task); + + writeTcs = new TaskCompletionSource(); + bytes = Encoding.ASCII.GetBytes(data[1]); + block = socketInput.IncomingStart(); + Buffer.BlockCopy(bytes, 0, block.Array, block.End, bytes.Length); + socketInput.IncomingComplete(bytes.Length, null); + + Assert.Same(block.Array, await writeTcs.Task); + + if (headers.HeaderConnection == "close") + { + socketInput.IncomingFin(); + } + + await copyToAsyncTask; + + Assert.Equal(2, writeCount); + } + } + + [Theory] + [MemberData(nameof(CombinedData))] + public async Task CopyToAsyncAdvancesRequestStreamWhenDestinationWriteAsyncThrows(Stream writeStream, FrameRequestHeaders headers, string[] data) + { + using (var input = new TestInput()) + { + var body = MessageBody.For(HttpVersion.Http11, headers, input.FrameContext); + + input.Add(data[0]); + + await Assert.ThrowsAsync(() => body.CopyToAsync(writeStream)); + + input.Add(data[1], fin: headers.HeaderConnection == "close"); + + // "Hello " should have been consumed + var readBuffer = new byte[6]; + var count = await body.ReadAsync(new ArraySegment(readBuffer, 0, readBuffer.Length)); + Assert.Equal(6, count); + AssertASCII("World!", new ArraySegment(readBuffer, 0, 6)); + + count = await body.ReadAsync(new ArraySegment(readBuffer, 0, readBuffer.Length)); + Assert.Equal(0, count); } } @@ -98,5 +202,84 @@ namespace Microsoft.AspNetCore.Server.KestrelTests Assert.Equal(bytes[index], actual.Array[actual.Offset + index]); } } + + private class ThrowOnWriteSynchronousStream : Stream + { + public override void Flush() + { + throw new NotImplementedException(); + } + + public override int Read(byte[] buffer, int offset, int count) + { + throw new NotImplementedException(); + } + + public override long Seek(long offset, SeekOrigin origin) + { + throw new NotImplementedException(); + } + + public override void SetLength(long value) + { + throw new NotImplementedException(); + } + + public override void Write(byte[] buffer, int offset, int count) + { + throw new NotImplementedException(); + } + + public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) + { + throw new XunitException(); + } + + public override bool CanRead { get; } + public override bool CanSeek { get; } + public override bool CanWrite => true; + public override long Length { get; } + public override long Position { get; set; } + } + + private class ThrowOnWriteAsynchronousStream : Stream + { + public override void Flush() + { + throw new NotImplementedException(); + } + + public override int Read(byte[] buffer, int offset, int count) + { + throw new NotImplementedException(); + } + + public override long Seek(long offset, SeekOrigin origin) + { + throw new NotImplementedException(); + } + + public override void SetLength(long value) + { + throw new NotImplementedException(); + } + + public override void Write(byte[] buffer, int offset, int count) + { + throw new NotImplementedException(); + } + + public override async Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) + { + await Task.Delay(1); + throw new XunitException(); + } + + public override bool CanRead { get; } + public override bool CanSeek { get; } + public override bool CanWrite => true; + public override long Length { get; } + public override long Position { get; set; } + } } } \ No newline at end of file diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/SocketInputTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/SocketInputTests.cs index b2bb528649..a751bbe342 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/SocketInputTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/SocketInputTests.cs @@ -19,7 +19,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests new TheoryData>() { new Mock(), null }; [Theory] - [MemberData("MockBufferSizeControlData")] + [MemberData(nameof(MockBufferSizeControlData))] public void IncomingDataCallsBufferSizeControlAdd(Mock mockBufferSizeControl) { using (var memory = new MemoryPool()) @@ -31,7 +31,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } [Theory] - [MemberData("MockBufferSizeControlData")] + [MemberData(nameof(MockBufferSizeControlData))] public void IncomingCompleteCallsBufferSizeControlAdd(Mock mockBufferSizeControl) { using (var memory = new MemoryPool()) @@ -43,7 +43,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } [Theory] - [MemberData("MockBufferSizeControlData")] + [MemberData(nameof(MockBufferSizeControlData))] public void ConsumingCompleteCallsBufferSizeControlSubtract(Mock mockBufferSizeControl) { using (var kestrelEngine = new KestrelEngine(new MockLibuv(), new TestServiceContext())) @@ -154,6 +154,80 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } } + [Fact] + public async Task PeekAsyncRereturnsTheSameData() + { + using (var memory = new MemoryPool()) + using (var socketInput = new SocketInput(memory, new SynchronousThreadPool())) + { + socketInput.IncomingData(new byte[5], 0, 5); + + Assert.True(socketInput.IsCompleted); + Assert.Equal(5, (await socketInput.PeekAsync()).Count); + + // The same 5 bytes will be returned again since it hasn't been consumed. + Assert.True(socketInput.IsCompleted); + Assert.Equal(5, (await socketInput.PeekAsync()).Count); + + var scan = socketInput.ConsumingStart(); + scan.Skip(3); + socketInput.ConsumingComplete(scan, scan); + + // The remaining 2 unconsumed bytes will be returned. + Assert.True(socketInput.IsCompleted); + Assert.Equal(2, (await socketInput.PeekAsync()).Count); + + scan = socketInput.ConsumingStart(); + scan.Skip(2); + socketInput.ConsumingComplete(scan, scan); + + // Everything has been consume so socketInput is no longer in the completed state + Assert.False(socketInput.IsCompleted); + } + } + + [Fact] + public async Task CompleteAwaitingDoesNotCauseZeroLengthRead() + { + using (var memory = new MemoryPool()) + using (var socketInput = new SocketInput(memory, new SynchronousThreadPool())) + { + var readBuffer = new byte[20]; + + socketInput.IncomingData(new byte[5], 0, 5); + Assert.Equal(5, await socketInput.ReadAsync(readBuffer, 0, 20)); + + var readTask = socketInput.ReadAsync(readBuffer, 0, 20); + socketInput.CompleteAwaiting(); + Assert.False(readTask.IsCompleted); + + socketInput.IncomingData(new byte[5], 0, 5); + Assert.Equal(5, await readTask); + } + } + + [Fact] + public async Task CompleteAwaitingDoesNotCauseZeroLengthPeek() + { + using (var memory = new MemoryPool()) + using (var socketInput = new SocketInput(memory, new SynchronousThreadPool())) + { + socketInput.IncomingData(new byte[5], 0, 5); + Assert.Equal(5, (await socketInput.PeekAsync()).Count); + + var scan = socketInput.ConsumingStart(); + scan.Skip(5); + socketInput.ConsumingComplete(scan, scan); + + var peekTask = socketInput.PeekAsync(); + socketInput.CompleteAwaiting(); + Assert.False(peekTask.IsCompleted); + + socketInput.IncomingData(new byte[5], 0, 5); + Assert.Equal(5, (await socketInput.PeekAsync()).Count); + } + } + private static void TestConcurrentFaultedTask(Task t) { Assert.True(t.IsFaulted); From 49ff98f8cbcf511c343a7076ecdaece2b5306462 Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Wed, 21 Sep 2016 11:08:47 -0700 Subject: [PATCH 0888/1662] More specific response status codes for errors (#653). - 414 when request line exceeds size limit - 431 when request headers exceed size or count limits - 505 when request line contains unsupported HTTP version --- .../BadHttpRequestException.cs | 68 +++++----- .../Internal/Http/Frame.cs | 11 +- .../Internal/Http/ReasonPhrases.cs | 3 + .../MaxRequestLineSizeTests.cs | 61 +++++---- .../RequestHeaderLimitsTests.cs | 104 +++++++------- .../BadHttpRequestTests.cs | 61 +++++---- .../ChunkedRequestTests.cs | 4 +- .../FrameRequestHeadersTests.cs | 6 +- .../FrameTests.cs | 128 ++++++++++++++++-- 9 files changed, 294 insertions(+), 152 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/BadHttpRequestException.cs b/src/Microsoft.AspNetCore.Server.Kestrel/BadHttpRequestException.cs index 64365e486e..196a6e941f 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/BadHttpRequestException.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/BadHttpRequestException.cs @@ -8,100 +8,102 @@ namespace Microsoft.AspNetCore.Server.Kestrel { public sealed class BadHttpRequestException : IOException { - private BadHttpRequestException(string message) + private BadHttpRequestException(string message, int statusCode) : base(message) { - + StatusCode = statusCode; } + internal int StatusCode { get; } + internal static BadHttpRequestException GetException(RequestRejectionReason reason) { BadHttpRequestException ex; switch (reason) { case RequestRejectionReason.MissingMethod: - ex = new BadHttpRequestException("Missing method."); + ex = new BadHttpRequestException("Missing method.", 400); break; case RequestRejectionReason.InvalidMethod: - ex = new BadHttpRequestException("Invalid method."); + ex = new BadHttpRequestException("Invalid method.", 400); break; case RequestRejectionReason.MissingRequestTarget: - ex = new BadHttpRequestException("Missing request target."); + ex = new BadHttpRequestException("Missing request target.", 400); break; case RequestRejectionReason.MissingHTTPVersion: - ex = new BadHttpRequestException("Missing HTTP version."); + ex = new BadHttpRequestException("Missing HTTP version.", 400); break; case RequestRejectionReason.UnrecognizedHTTPVersion: - ex = new BadHttpRequestException("Unrecognized HTTP version."); + ex = new BadHttpRequestException("Unrecognized HTTP version.", 505); break; case RequestRejectionReason.MissingLFInRequestLine: - ex = new BadHttpRequestException("Missing LF in request line."); + ex = new BadHttpRequestException("Missing LF in request line.", 400); break; case RequestRejectionReason.HeadersCorruptedInvalidHeaderSequence: - ex = new BadHttpRequestException("Headers corrupted, invalid header sequence."); + ex = new BadHttpRequestException("Headers corrupted, invalid header sequence.", 400); break; case RequestRejectionReason.HeaderLineMustNotStartWithWhitespace: - ex = new BadHttpRequestException("Header line must not start with whitespace."); + ex = new BadHttpRequestException("Header line must not start with whitespace.", 400); break; case RequestRejectionReason.NoColonCharacterFoundInHeaderLine: - ex = new BadHttpRequestException("No ':' character found in header line."); + ex = new BadHttpRequestException("No ':' character found in header line.", 400); break; case RequestRejectionReason.WhitespaceIsNotAllowedInHeaderName: - ex = new BadHttpRequestException("Whitespace is not allowed in header name."); + ex = new BadHttpRequestException("Whitespace is not allowed in header name.", 400); break; case RequestRejectionReason.HeaderValueMustNotContainCR: - ex = new BadHttpRequestException("Header value must not contain CR characters."); + ex = new BadHttpRequestException("Header value must not contain CR characters.", 400); break; case RequestRejectionReason.HeaderValueLineFoldingNotSupported: - ex = new BadHttpRequestException("Header value line folding not supported."); + ex = new BadHttpRequestException("Header value line folding not supported.", 400); break; case RequestRejectionReason.MalformedRequestInvalidHeaders: - ex = new BadHttpRequestException("Malformed request: invalid headers."); + ex = new BadHttpRequestException("Malformed request: invalid headers.", 400); break; case RequestRejectionReason.UnexpectedEndOfRequestContent: - ex = new BadHttpRequestException("Unexpected end of request content."); + ex = new BadHttpRequestException("Unexpected end of request content.", 400); break; case RequestRejectionReason.BadChunkSuffix: - ex = new BadHttpRequestException("Bad chunk suffix."); + ex = new BadHttpRequestException("Bad chunk suffix.", 400); break; case RequestRejectionReason.BadChunkSizeData: - ex = new BadHttpRequestException("Bad chunk size data."); + ex = new BadHttpRequestException("Bad chunk size data.", 400); break; case RequestRejectionReason.ChunkedRequestIncomplete: - ex = new BadHttpRequestException("Chunked request incomplete."); + ex = new BadHttpRequestException("Chunked request incomplete.", 400); break; case RequestRejectionReason.PathContainsNullCharacters: - ex = new BadHttpRequestException("The path contains null characters."); + ex = new BadHttpRequestException("The path contains null characters.", 400); break; case RequestRejectionReason.InvalidCharactersInHeaderName: - ex = new BadHttpRequestException("Invalid characters in header name."); + ex = new BadHttpRequestException("Invalid characters in header name.", 400); break; case RequestRejectionReason.NonAsciiOrNullCharactersInInputString: - ex = new BadHttpRequestException("The input string contains non-ASCII or null characters."); + ex = new BadHttpRequestException("The input string contains non-ASCII or null characters.", 400); break; case RequestRejectionReason.RequestLineTooLong: - ex = new BadHttpRequestException("Request line too long."); + ex = new BadHttpRequestException("Request line too long.", 414); break; case RequestRejectionReason.MissingSpaceAfterMethod: - ex = new BadHttpRequestException("No space character found after method in request line."); + ex = new BadHttpRequestException("No space character found after method in request line.", 400); break; case RequestRejectionReason.MissingSpaceAfterTarget: - ex = new BadHttpRequestException("No space character found after target in request line."); + ex = new BadHttpRequestException("No space character found after target in request line.", 400); break; case RequestRejectionReason.MissingCrAfterVersion: - ex = new BadHttpRequestException("Missing CR in request line."); + ex = new BadHttpRequestException("Missing CR in request line.", 400); break; case RequestRejectionReason.HeadersExceedMaxTotalSize: - ex = new BadHttpRequestException("Request headers too long."); + ex = new BadHttpRequestException("Request headers too long.", 431); break; case RequestRejectionReason.MissingCRInHeaderLine: - ex = new BadHttpRequestException("No CR character found in header line."); + ex = new BadHttpRequestException("No CR character found in header line.", 400); break; case RequestRejectionReason.TooManyHeaders: - ex = new BadHttpRequestException("Request contains too many headers."); + ex = new BadHttpRequestException("Request contains too many headers.", 431); break; default: - ex = new BadHttpRequestException("Bad request."); + ex = new BadHttpRequestException("Bad request.", 400); break; } return ex; @@ -113,13 +115,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel switch (reason) { case RequestRejectionReason.MalformedRequestLineStatus: - ex = new BadHttpRequestException($"Invalid request line: {value}"); + ex = new BadHttpRequestException($"Invalid request line: {value}", 400); break; case RequestRejectionReason.InvalidContentLength: - ex = new BadHttpRequestException($"Invalid content length: {value}"); + ex = new BadHttpRequestException($"Invalid content length: {value}", 400); break; default: - ex = new BadHttpRequestException("Bad request."); + ex = new BadHttpRequestException("Bad request.", 400); break; } return ex; diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs index 2e17305777..af4d8882ef 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs @@ -640,13 +640,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http return TaskCache.CompletedTask; } - if (_requestRejected) - { - // 400 Bad Request - StatusCode = 400; - _keepAlive = false; - } - else + // If the request was rejected, StatusCode has already been set by SetBadRequestState + if (!_requestRejected) { // 500 Internal Server Error StatusCode = 500; @@ -1249,6 +1244,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http public void SetBadRequestState(BadHttpRequestException ex) { + StatusCode = ex.StatusCode; + _keepAlive = false; _requestProcessingStopping = true; _requestRejected = true; Log.ConnectionBadRequest(ConnectionId, ex); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ReasonPhrases.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ReasonPhrases.cs index cc01b728f4..c7d52fc91c 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ReasonPhrases.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ReasonPhrases.cs @@ -52,6 +52,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http private static readonly byte[] _bytesStatus423 = Encoding.ASCII.GetBytes("423 Locked"); private static readonly byte[] _bytesStatus424 = Encoding.ASCII.GetBytes("424 Failed Dependency"); private static readonly byte[] _bytesStatus426 = Encoding.ASCII.GetBytes("426 Upgrade Required"); + private static readonly byte[] _bytesStatus431 = Encoding.ASCII.GetBytes("431 Request Header Fields Too Large"); private static readonly byte[] _bytesStatus451 = Encoding.ASCII.GetBytes("451 Unavailable For Legal Reasons"); private static readonly byte[] _bytesStatus500 = Encoding.ASCII.GetBytes("500 Internal Server Error"); private static readonly byte[] _bytesStatus501 = Encoding.ASCII.GetBytes("501 Not Implemented"); @@ -157,6 +158,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http return _bytesStatus424; case 426: return _bytesStatus426; + case 431: + return _bytesStatus431; case 451: return _bytesStatus451; case 500: diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/MaxRequestLineSizeTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/MaxRequestLineSizeTests.cs index 1e582f0bce..35b66ed5b5 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/MaxRequestLineSizeTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/MaxRequestLineSizeTests.cs @@ -1,10 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System; using System.Threading.Tasks; -using Microsoft.AspNetCore.Builder; -using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Testing; using Xunit; @@ -30,17 +27,21 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { var maxRequestLineSize = limit; - using (var host = BuildWebHost(options => + using (var server = CreateServer(limit)) { - options.Limits.MaxRequestLineSize = maxRequestLineSize; - })) - { - host.Start(); - - using (var connection = new TestConnection(host.GetPort())) + using (var connection = new TestConnection(server.Port)) { await connection.SendEnd($"{requestLine}\r\n"); - await connection.Receive($"HTTP/1.1 200 OK\r\n"); + await connection.ReceiveEnd( + "HTTP/1.1 200 OK", + $"Date: {server.Context.DateHeaderValue}", + "Transfer-Encoding: chunked", + "", + "c", + "hello, world", + "0", + "", + ""); } } } @@ -52,33 +53,35 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [InlineData("DELETE /a%20b%20c/d%20e?f=ghi HTTP/1.1\r\n")] public async Task ServerRejectsRequestLineExceedingLimit(string requestLine) { - using (var host = BuildWebHost(options => + using (var server = CreateServer(requestLine.Length - 1)) { - options.Limits.MaxRequestLineSize = requestLine.Length - 1; // stop short of the '\n' - })) - { - host.Start(); - - using (var connection = new TestConnection(host.GetPort())) + using (var connection = new TestConnection(server.Port)) { await connection.SendAllTryEnd($"{requestLine}\r\n"); - await connection.Receive($"HTTP/1.1 400 Bad Request\r\n"); + await connection.Receive( + "HTTP/1.1 414 URI Too Long", + "Connection: close", + $"Date: {server.Context.DateHeaderValue}", + "Content-Length: 0", + "", + ""); } } } - private IWebHost BuildWebHost(Action options) + private TestServer CreateServer(int maxRequestLineSize) { - var host = new WebHostBuilder() - .UseKestrel(options) - .UseUrls("http://127.0.0.1:0/") - .Configure(app => app.Run(async context => + return new TestServer(async httpContext => await httpContext.Response.WriteAsync("hello, world"), new TestServiceContext + { + ServerOptions = new KestrelServerOptions { - await context.Response.WriteAsync("hello, world"); - })) - .Build(); - - return host; + AddServerHeader = false, + Limits = + { + MaxRequestLineSize = maxRequestLineSize + } + } + }); } } } diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestHeaderLimitsTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestHeaderLimitsTests.cs index 2c7eec616e..712407f76c 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestHeaderLimitsTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestHeaderLimitsTests.cs @@ -1,12 +1,8 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System; using System.Linq; -using System.Net.Http; using System.Threading.Tasks; -using Microsoft.AspNetCore.Builder; -using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Testing; using Xunit; @@ -28,17 +24,21 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { var headers = MakeHeaders(headerCount); - using (var host = BuildWebHost(options => + using (var server = CreateServer(maxRequestHeadersTotalSize: headers.Length + extraLimit)) { - options.Limits.MaxRequestHeadersTotalSize = headers.Length + extraLimit; - })) - { - host.Start(); - - using (var connection = new TestConnection(host.GetPort())) + using (var connection = new TestConnection(server.Port)) { await connection.SendEnd($"GET / HTTP/1.1\r\n{headers}\r\n"); - await connection.Receive($"HTTP/1.1 200 OK\r\n"); + await connection.ReceiveEnd( + "HTTP/1.1 200 OK", + $"Date: {server.Context.DateHeaderValue}", + "Transfer-Encoding: chunked", + "", + "c", + "hello, world", + "0", + "", + ""); } } } @@ -56,17 +56,21 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { var headers = MakeHeaders(headerCount); - using (var host = BuildWebHost(options => + using (var server = CreateServer(maxRequestHeaderCount: maxHeaderCount)) { - options.Limits.MaxRequestHeaderCount = maxHeaderCount; - })) - { - host.Start(); - - using (var connection = new TestConnection(host.GetPort())) + using (var connection = new TestConnection(server.Port)) { await connection.SendEnd($"GET / HTTP/1.1\r\n{headers}\r\n"); - await connection.Receive($"HTTP/1.1 200 OK\r\n"); + await connection.ReceiveEnd( + "HTTP/1.1 200 OK", + $"Date: {server.Context.DateHeaderValue}", + "Transfer-Encoding: chunked", + "", + "c", + "hello, world", + "0", + "", + ""); } } } @@ -78,17 +82,18 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { var headers = MakeHeaders(headerCount); - using (var host = BuildWebHost(options => + using (var server = CreateServer(maxRequestHeadersTotalSize: headers.Length - 1)) { - options.Limits.MaxRequestHeadersTotalSize = headers.Length - 1; - })) - { - host.Start(); - - using (var connection = new TestConnection(host.GetPort())) + using (var connection = new TestConnection(server.Port)) { await connection.SendAllTryEnd($"GET / HTTP/1.1\r\n{headers}\r\n"); - await connection.Receive($"HTTP/1.1 400 Bad Request\r\n"); + await connection.ReceiveForcedEnd( + "HTTP/1.1 431 Request Header Fields Too Large", + "Connection: close", + $"Date: {server.Context.DateHeaderValue}", + "Content-Length: 0", + "", + ""); } } } @@ -101,17 +106,18 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { var headers = MakeHeaders(headerCount); - using (var host = BuildWebHost(options => + using (var server = CreateServer(maxRequestHeaderCount: maxHeaderCount)) { - options.Limits.MaxRequestHeaderCount = maxHeaderCount; - })) - { - host.Start(); - - using (var connection = new TestConnection(host.GetPort())) + using (var connection = new TestConnection(server.Port)) { await connection.SendAllTryEnd($"GET / HTTP/1.1\r\n{headers}\r\n"); - await connection.Receive($"HTTP/1.1 400 Bad Request\r\n"); + await connection.ReceiveForcedEnd( + "HTTP/1.1 431 Request Header Fields Too Large", + "Connection: close", + $"Date: {server.Context.DateHeaderValue}", + "Content-Length: 0", + "", + ""); } } } @@ -123,18 +129,24 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests .Select(i => $"Header-{i}: value{i}\r\n")); } - private static IWebHost BuildWebHost(Action options) + private TestServer CreateServer(int? maxRequestHeaderCount = null, int? maxRequestHeadersTotalSize = null) { - var host = new WebHostBuilder() - .UseKestrel(options) - .UseUrls("http://127.0.0.1:0/") - .Configure(app => app.Run(async context => - { - await context.Response.WriteAsync("hello, world"); - })) - .Build(); + var options = new KestrelServerOptions { AddServerHeader = false }; - return host; + if (maxRequestHeaderCount.HasValue) + { + options.Limits.MaxRequestHeaderCount = maxRequestHeaderCount.Value; + } + + if (maxRequestHeadersTotalSize.HasValue) + { + options.Limits.MaxRequestHeadersTotalSize = maxRequestHeadersTotalSize.Value; + } + + return new TestServer(async httpContext => await httpContext.Response.WriteAsync("hello, world"), new TestServiceContext + { + ServerOptions = options + }); } } } \ No newline at end of file diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/BadHttpRequestTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/BadHttpRequestTests.cs index 74cbb05230..a4e0f11169 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/BadHttpRequestTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/BadHttpRequestTests.cs @@ -19,13 +19,6 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [InlineData("GET \r\n")] [InlineData("GET /\r\n")] [InlineData("GET / \r\n")] - [InlineData("GET / H\r\n")] - [InlineData("GET / HT\r\n")] - [InlineData("GET / HTT\r\n")] - [InlineData("GET / HTTP\r\n")] - [InlineData("GET / HTTP/\r\n")] - [InlineData("GET / HTTP/1\r\n")] - [InlineData("GET / HTTP/1.\r\n")] // Missing method [InlineData(" \r\n")] // Missing second space @@ -37,18 +30,6 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [InlineData("GET / \r\n")] // Missing CR [InlineData("GET / \n")] - // Unrecognized HTTP version - [InlineData("GET / http/1.0\r\n")] - [InlineData("GET / http/1.1\r\n")] - [InlineData("GET / HTTP/1.1 \r\n")] - [InlineData("GET / HTTP/1.1a\r\n")] - [InlineData("GET / HTTP/1.0\n\r\n")] - [InlineData("GET / HTTP/1.2\r\n")] - [InlineData("GET / HTTP/3.0\r\n")] - [InlineData("GET / H\r\n")] - [InlineData("GET / HTTP/1.\r\n")] - [InlineData("GET / hello\r\n")] - [InlineData("GET / 8charact\r\n")] // Missing LF after CR [InlineData("GET / HTTP/1.0\rA\n")] // Bad HTTP Methods (invalid according to RFC) @@ -78,7 +59,37 @@ namespace Microsoft.AspNetCore.Server.KestrelTests using (var connection = server.CreateConnection()) { await connection.SendAllTryEnd(request); - await ReceiveBadRequestResponse(connection, server.Context.DateHeaderValue); + await ReceiveBadRequestResponse(connection, "400 Bad Request", server.Context.DateHeaderValue); + } + } + } + + [Theory] + [InlineData("GET / H\r\n")] + [InlineData("GET / HT\r\n")] + [InlineData("GET / HTT\r\n")] + [InlineData("GET / HTTP\r\n")] + [InlineData("GET / HTTP/\r\n")] + [InlineData("GET / HTTP/1\r\n")] + [InlineData("GET / HTTP/1.\r\n")] + [InlineData("GET / http/1.0\r\n")] + [InlineData("GET / http/1.1\r\n")] + [InlineData("GET / HTTP/1.1 \r\n")] + [InlineData("GET / HTTP/1.1a\r\n")] + [InlineData("GET / HTTP/1.2\r\n")] + [InlineData("GET / HTTP/3.0\r\n")] + [InlineData("GET / H\r\n")] + [InlineData("GET / HTTP/1.\r\n")] + [InlineData("GET / hello\r\n")] + [InlineData("GET / 8charact\r\n")] + public async Task TestInvalidRequestLinesWithUnsupportedVersion(string request) + { + using (var server = new TestServer(context => TaskCache.CompletedTask)) + { + using (var connection = server.CreateConnection()) + { + await connection.SendAllTryEnd(request); + await ReceiveBadRequestResponse(connection, "505 HTTP Version Not Supported", server.Context.DateHeaderValue); } } } @@ -114,7 +125,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests using (var connection = server.CreateConnection()) { await connection.SendAllTryEnd($"GET / HTTP/1.1\r\n{rawHeaders}"); - await ReceiveBadRequestResponse(connection, server.Context.DateHeaderValue); + await ReceiveBadRequestResponse(connection, "400 Bad Request", server.Context.DateHeaderValue); } } } @@ -131,7 +142,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests "H\u00eb\u00e4d\u00ebr: value", "", ""); - await ReceiveBadRequestResponse(connection, server.Context.DateHeaderValue); + await ReceiveBadRequestResponse(connection, "400 Bad Request", server.Context.DateHeaderValue); } } } @@ -158,15 +169,15 @@ namespace Microsoft.AspNetCore.Server.KestrelTests using (var connection = server.CreateConnection()) { await connection.SendAllTryEnd($"GET {path} HTTP/1.1\r\n"); - await ReceiveBadRequestResponse(connection, server.Context.DateHeaderValue); + await ReceiveBadRequestResponse(connection, "400 Bad Request", server.Context.DateHeaderValue); } } } - private async Task ReceiveBadRequestResponse(TestConnection connection, string expectedDateHeaderValue) + private async Task ReceiveBadRequestResponse(TestConnection connection, string expectedResponseStatusCode, string expectedDateHeaderValue) { await connection.ReceiveForcedEnd( - "HTTP/1.1 400 Bad Request", + $"HTTP/1.1 {expectedResponseStatusCode}", "Connection: close", $"Date: {expectedDateHeaderValue}", "Content-Length: 0", diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedRequestTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedRequestTests.cs index 6ef64cf30e..9214b5b1f7 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedRequestTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedRequestTests.cs @@ -291,7 +291,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests "", ""); await connection.ReceiveForcedEnd( - "HTTP/1.1 400 Bad Request", + "HTTP/1.1 431 Request Header Fields Too Large", "Connection: close", $"Date: {testContext.DateHeaderValue}", "Content-Length: 0", @@ -331,7 +331,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests "", ""); await connection.ReceiveForcedEnd( - "HTTP/1.1 400 Bad Request", + "HTTP/1.1 431 Request Header Fields Too Large", "Connection: close", $"Date: {testContext.DateHeaderValue}", "Content-Length: 0", diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameRequestHeadersTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameRequestHeadersTests.cs index 6f07dd90ac..44e421191d 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameRequestHeadersTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameRequestHeadersTests.cs @@ -1,3 +1,6 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + using System; using System.Collections.Generic; using System.Text; @@ -243,8 +246,9 @@ namespace Microsoft.AspNetCore.Server.KestrelTests const string key = "\u00141d\017c"; var encoding = Encoding.GetEncoding("iso-8859-1"); - Assert.Throws( + var exception = Assert.Throws( () => headers.Append(encoding.GetBytes(key), 0, encoding.GetByteCount(key), key)); + Assert.Equal(400, exception.StatusCode); } } } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs index 66c0941c2b..09bffeee85 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs @@ -187,7 +187,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [InlineData("Header: line1\r\n\t\tline2\r\n\r\n")] [InlineData("Header: line1\r\n \t\t line2\r\n\r\n")] [InlineData("Header: line1\r\n \t \t line2\r\n\r\n")] - public void ThrowsOnHeaderValueWithLineFolding(string rawHeaders) + public void TakeMessageHeadersThrowsOnHeaderValueWithLineFolding(string rawHeaders) { var trace = new KestrelTrace(new TestKestrelTrace()); var ltp = new LoggingThreadPool(trace); @@ -210,11 +210,12 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var exception = Assert.Throws(() => frame.TakeMessageHeaders(socketInput, (FrameRequestHeaders)frame.RequestHeaders)); Assert.Equal("Header value line folding not supported.", exception.Message); + Assert.Equal(400, exception.StatusCode); } } [Fact] - public void ThrowsOnHeaderValueWithLineFolding_CharacterNotAvailableOnFirstAttempt() + public void TakeMessageHeadersThrowsOnHeaderValueWithLineFolding_CharacterNotAvailableOnFirstAttempt() { var trace = new KestrelTrace(new TestKestrelTrace()); var ltp = new LoggingThreadPool(trace); @@ -241,6 +242,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var exception = Assert.Throws(() => frame.TakeMessageHeaders(socketInput, (FrameRequestHeaders)frame.RequestHeaders)); Assert.Equal("Header value line folding not supported.", exception.Message); + Assert.Equal(400, exception.StatusCode); } } @@ -250,7 +252,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [InlineData("Header-1: value1\rHeader-2: value2\r\n\r\n")] [InlineData("Header-1: value1\r\nHeader-2: value2\r\r\n")] [InlineData("Header-1: value1\r\nHeader-2: v\ralue2\r\n")] - public void ThrowsOnHeaderValueContainingCR(string rawHeaders) + public void TakeMessageHeadersThrowsOnHeaderValueContainingCR(string rawHeaders) { var trace = new KestrelTrace(new TestKestrelTrace()); var ltp = new LoggingThreadPool(trace); @@ -273,6 +275,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var exception = Assert.Throws(() => frame.TakeMessageHeaders(socketInput, (FrameRequestHeaders)frame.RequestHeaders)); Assert.Equal("Header value must not contain CR characters.", exception.Message); + Assert.Equal(400, exception.StatusCode); } } @@ -280,7 +283,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [InlineData("Header-1 value1\r\n\r\n")] [InlineData("Header-1 value1\r\nHeader-2: value2\r\n\r\n")] [InlineData("Header-1: value1\r\nHeader-2 value2\r\n\r\n")] - public void ThrowsOnHeaderLineMissingColon(string rawHeaders) + public void TakeMessageHeadersThrowsOnHeaderLineMissingColon(string rawHeaders) { var trace = new KestrelTrace(new TestKestrelTrace()); var ltp = new LoggingThreadPool(trace); @@ -303,6 +306,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var exception = Assert.Throws(() => frame.TakeMessageHeaders(socketInput, (FrameRequestHeaders)frame.RequestHeaders)); Assert.Equal("No ':' character found in header line.", exception.Message); + Assert.Equal(400, exception.StatusCode); } } @@ -311,7 +315,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [InlineData("\tHeader: value\r\n\r\n")] [InlineData(" Header-1: value1\r\nHeader-2: value2\r\n\r\n")] [InlineData("\tHeader-1: value1\r\nHeader-2: value2\r\n\r\n")] - public void ThrowsOnHeaderLineStartingWithWhitespace(string rawHeaders) + public void TakeMessageHeadersThrowsOnHeaderLineStartingWithWhitespace(string rawHeaders) { var trace = new KestrelTrace(new TestKestrelTrace()); var ltp = new LoggingThreadPool(trace); @@ -334,6 +338,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var exception = Assert.Throws(() => frame.TakeMessageHeaders(socketInput, (FrameRequestHeaders)frame.RequestHeaders)); Assert.Equal("Header line must not start with whitespace.", exception.Message); + Assert.Equal(400, exception.StatusCode); } } @@ -346,7 +351,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [InlineData("Header-1: value1\r\nHeader 2: value2\r\n\r\n")] [InlineData("Header-1: value1\r\nHeader-2 : value2\r\n\r\n")] [InlineData("Header-1: value1\r\nHeader-2\t: value2\r\n\r\n")] - public void ThrowsOnWhitespaceInHeaderName(string rawHeaders) + public void TakeMessageHeadersThrowsOnWhitespaceInHeaderName(string rawHeaders) { var trace = new KestrelTrace(new TestKestrelTrace()); var ltp = new LoggingThreadPool(trace); @@ -369,6 +374,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var exception = Assert.Throws(() => frame.TakeMessageHeaders(socketInput, (FrameRequestHeaders)frame.RequestHeaders)); Assert.Equal("Whitespace is not allowed in header name.", exception.Message); + Assert.Equal(400, exception.StatusCode); } } @@ -376,7 +382,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [InlineData("Header-1: value1\r\nHeader-2: value2\r\n\r\r")] [InlineData("Header-1: value1\r\nHeader-2: value2\r\n\r ")] [InlineData("Header-1: value1\r\nHeader-2: value2\r\n\r \n")] - public void ThrowsOnHeadersNotEndingInCRLFLine(string rawHeaders) + public void TakeMessageHeadersThrowsOnHeadersNotEndingInCRLFLine(string rawHeaders) { var trace = new KestrelTrace(new TestKestrelTrace()); var ltp = new LoggingThreadPool(trace); @@ -399,11 +405,12 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var exception = Assert.Throws(() => frame.TakeMessageHeaders(socketInput, (FrameRequestHeaders)frame.RequestHeaders)); Assert.Equal("Headers corrupted, invalid header sequence.", exception.Message); + Assert.Equal(400, exception.StatusCode); } } [Fact] - public void ThrowsWhenHeadersExceedTotalSizeLimit() + public void TakeMessageHeadersThrowsWhenHeadersExceedTotalSizeLimit() { var trace = new KestrelTrace(new TestKestrelTrace()); var ltp = new LoggingThreadPool(trace); @@ -432,11 +439,12 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var exception = Assert.Throws(() => frame.TakeMessageHeaders(socketInput, (FrameRequestHeaders)frame.RequestHeaders)); Assert.Equal("Request headers too long.", exception.Message); + Assert.Equal(431, exception.StatusCode); } } [Fact] - public void ThrowsWhenHeadersExceedCountLimit() + public void TakeMessageHeadersThrowsWhenHeadersExceedCountLimit() { var trace = new KestrelTrace(new TestKestrelTrace()); var ltp = new LoggingThreadPool(trace); @@ -465,6 +473,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var exception = Assert.Throws(() => frame.TakeMessageHeaders(socketInput, (FrameRequestHeaders)frame.RequestHeaders)); Assert.Equal("Request contains too many headers.", exception.Message); + Assert.Equal(431, exception.StatusCode); } } @@ -842,6 +851,107 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } } + [Fact] + public void TakeStartLineThrowsWhenTooLong() + { + var trace = new KestrelTrace(new TestKestrelTrace()); + var ltp = new LoggingThreadPool(trace); + using (var pool = new MemoryPool()) + using (var socketInput = new SocketInput(pool, ltp)) + { + var connectionContext = new ConnectionContext() + { + ConnectionControl = Mock.Of(), + DateHeaderValueManager = new DateHeaderValueManager(), + ServerAddress = ServerAddress.FromUrl("http://localhost:5000"), + ServerOptions = new KestrelServerOptions() + { + Limits = + { + MaxRequestLineSize = "GET / HTTP/1.1\r\n".Length + } + }, + Log = trace + }; + var frame = new Frame(application: null, context: connectionContext); + frame.Reset(); + + var requestLineBytes = Encoding.ASCII.GetBytes("GET /a HTTP/1.1\r\n"); + socketInput.IncomingData(requestLineBytes, 0, requestLineBytes.Length); + + var exception = Assert.Throws(() => frame.TakeStartLine(socketInput)); + Assert.Equal("Request line too long.", exception.Message); + Assert.Equal(414, exception.StatusCode); + } + } + + [Theory] + [InlineData("GET/HTTP/1.1\r\n", "No space character found after method in request line.")] + [InlineData(" / HTTP/1.1\r\n", "Missing method.")] + [InlineData("GET? / HTTP/1.1\r\n", "Invalid method.")] + [InlineData("GET /HTTP/1.1\r\n", "No space character found after target in request line.")] + [InlineData("GET /a?b=cHTTP/1.1\r\n", "No space character found after target in request line.")] + [InlineData("GET /a%20bHTTP/1.1\r\n", "No space character found after target in request line.")] + [InlineData("GET /a%20b?c=dHTTP/1.1\r\n", "No space character found after target in request line.")] + [InlineData("GET HTTP/1.1\r\n", "Missing request target.")] + [InlineData("GET / HTTP/1.1\n", "Missing CR in request line.")] + [InlineData("GET / \r\n", "Missing HTTP version.")] + [InlineData("GET / HTTP/1.1\ra\n", "Missing LF in request line.")] + public void TakeStartLineThrowsWhenInvalid(string requestLine, string expectedExceptionMessage) + { + var trace = new KestrelTrace(new TestKestrelTrace()); + var ltp = new LoggingThreadPool(trace); + using (var pool = new MemoryPool()) + using (var socketInput = new SocketInput(pool, ltp)) + { + var connectionContext = new ConnectionContext() + { + ConnectionControl = Mock.Of(), + DateHeaderValueManager = new DateHeaderValueManager(), + ServerAddress = ServerAddress.FromUrl("http://localhost:5000"), + ServerOptions = new KestrelServerOptions(), + Log = trace + }; + var frame = new Frame(application: null, context: connectionContext); + frame.Reset(); + + var requestLineBytes = Encoding.ASCII.GetBytes(requestLine); + socketInput.IncomingData(requestLineBytes, 0, requestLineBytes.Length); + + var exception = Assert.Throws(() => frame.TakeStartLine(socketInput)); + Assert.Equal(expectedExceptionMessage, exception.Message); + Assert.Equal(400, exception.StatusCode); + } + } + + [Fact] + public void TakeStartLineThrowsOnUnsupportedHttpVersion() + { + var trace = new KestrelTrace(new TestKestrelTrace()); + var ltp = new LoggingThreadPool(trace); + using (var pool = new MemoryPool()) + using (var socketInput = new SocketInput(pool, ltp)) + { + var connectionContext = new ConnectionContext() + { + ConnectionControl = Mock.Of(), + DateHeaderValueManager = new DateHeaderValueManager(), + ServerAddress = ServerAddress.FromUrl("http://localhost:5000"), + ServerOptions = new KestrelServerOptions(), + Log = trace + }; + var frame = new Frame(application: null, context: connectionContext); + frame.Reset(); + + var requestLineBytes = Encoding.ASCII.GetBytes("GET / HTTP/1.2\r\n"); + socketInput.IncomingData(requestLineBytes, 0, requestLineBytes.Length); + + var exception = Assert.Throws(() => frame.TakeStartLine(socketInput)); + Assert.Equal("Unrecognized HTTP version.", exception.Message); + Assert.Equal(505, exception.StatusCode); + } + } + [Fact] public void TakeMessageHeadersCallsConsumingCompleteWithFurthestExamined() { From 782f96572dc871d7506829a908bec183325d5978 Mon Sep 17 00:00:00 2001 From: Petr Onderka Date: Sun, 25 Sep 2016 18:13:42 +0200 Subject: [PATCH 0889/1662] Specify sequential layout to avoid warning --- .../Internal/Networking/SockAddr.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/SockAddr.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/SockAddr.cs index 7c2962b12b..ae4196153f 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/SockAddr.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/SockAddr.cs @@ -2,9 +2,11 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Net; +using System.Runtime.InteropServices; namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking { + [StructLayout(LayoutKind.Sequential)] public struct SockAddr { // this type represents native memory occupied by sockaddr struct From 78c859d7ea47cc77b62f1af3b06d4c3c6d441a46 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Sun, 25 Sep 2016 12:25:12 -0700 Subject: [PATCH 0890/1662] Turn on warnings as errors --- src/Microsoft.AspNetCore.Server.Kestrel.Https/project.json | 1 + src/Microsoft.AspNetCore.Server.Kestrel/project.json | 1 + 2 files changed, 2 insertions(+) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Https/project.json b/src/Microsoft.AspNetCore.Server.Kestrel.Https/project.json index 05d95e5e65..9300fd626a 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Https/project.json +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Https/project.json @@ -6,6 +6,7 @@ "nowarn": [ "CS1591" ], + "warningsAsErrors": true, "xmlDoc": true }, "packOptions": { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/project.json b/src/Microsoft.AspNetCore.Server.Kestrel/project.json index a83047073a..6305b879f8 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/project.json +++ b/src/Microsoft.AspNetCore.Server.Kestrel/project.json @@ -56,6 +56,7 @@ }, "buildOptions": { "allowUnsafe": true, + "warningsAsErrors": true, "keyFile": "../../tools/Key.snk", "nowarn": [ "CS1591" From 375e8b702226206b3e300d5f93d8e781a2419723 Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Mon, 5 Sep 2016 20:41:43 -0700 Subject: [PATCH 0891/1662] Change context relationships from inheritance to composition. --- .../Internal/Http/Connection.cs | 8 +- .../Internal/Http/ConnectionContext.cs | 16 +- .../Internal/Http/Frame.cs | 40 +- .../Internal/Http/Listener.cs | 2 + .../Internal/Http/ListenerContext.cs | 23 +- .../Internal/Http/ListenerSecondary.cs | 4 +- .../Internal/KestrelEngine.cs | 24 +- .../Internal/ServiceContext.cs | 14 - .../ConnectionTests.cs | 5 +- .../FrameResponseHeadersTests.cs | 11 +- .../FrameTests.cs | 350 +++++++++++++----- .../TestHelpers/MockConnection.cs | 3 +- .../TestInput.cs | 21 +- 13 files changed, 363 insertions(+), 158 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Connection.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Connection.cs index 7494362185..877e66fac0 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Connection.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Connection.cs @@ -66,7 +66,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } _frame = FrameFactory(this); - _lastTimestamp = Thread.Loop.Now(); } @@ -75,6 +74,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { } + public KestrelServerOptions ServerOptions => ListenerContext.ServiceContext.ServerOptions; + private Func FrameFactory => ListenerContext.ServiceContext.FrameFactory; + private IKestrelTrace Log => ListenerContext.ServiceContext.Log; + private IThreadPool ThreadPool => ListenerContext.ServiceContext.ThreadPool; + private ServerAddress ServerAddress => ListenerContext.ServerAddress; + private KestrelThread Thread => ListenerContext.Thread; + public void Start() { Log.ConnectionStart(ConnectionId); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ConnectionContext.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ConnectionContext.cs index f66f95d5ab..7ee603e4c5 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ConnectionContext.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ConnectionContext.cs @@ -7,26 +7,18 @@ using Microsoft.AspNetCore.Http.Features; namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { - public class ConnectionContext : ListenerContext + public class ConnectionContext { public ConnectionContext() { } - public ConnectionContext(ListenerContext context) : base(context) + public ConnectionContext(ListenerContext context) { + ListenerContext = context; } - public ConnectionContext(ConnectionContext context) : base(context) - { - SocketInput = context.SocketInput; - SocketOutput = context.SocketOutput; - ConnectionControl = context.ConnectionControl; - RemoteEndPoint = context.RemoteEndPoint; - LocalEndPoint = context.LocalEndPoint; - ConnectionId = context.ConnectionId; - PrepareRequest = context.PrepareRequest; - } + public ListenerContext ListenerContext { get; set; } public SocketInput SocketInput { get; set; } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs index af4d8882ef..dde74b0f56 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs @@ -11,6 +11,7 @@ using System.Text; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.Extensions.Internal; using Microsoft.Extensions.Logging; @@ -20,7 +21,7 @@ using Microsoft.Extensions.Primitives; namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { - public abstract partial class Frame : ConnectionContext, IFrameControl + public abstract partial class Frame : IFrameControl { private static readonly ArraySegment _endChunkedResponseBytes = CreateAsciiByteArraySegment("0\r\n\r\n"); private static readonly ArraySegment _continueBytes = CreateAsciiByteArraySegment("HTTP/1.1 100 Continue\r\n\r\n"); @@ -72,14 +73,45 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http protected readonly long _keepAliveMilliseconds; public Frame(ConnectionContext context) - : base(context) { - _pathBase = context.ServerAddress.PathBase; + ConnectionContext = context; + SocketInput = context.SocketInput; + SocketOutput = context.SocketOutput; + + ServerOptions = context.ListenerContext.ServiceContext.ServerOptions; + + _pathBase = ServerAddress.PathBase; FrameControl = this; _keepAliveMilliseconds = (long)ServerOptions.Limits.KeepAliveTimeout.TotalMilliseconds; } + public ConnectionContext ConnectionContext { get; } + public SocketInput SocketInput { get; set; } + public ISocketOutput SocketOutput { get; set; } + public Action PrepareRequest + { + get + { + return ConnectionContext.PrepareRequest; + } + set + { + ConnectionContext.PrepareRequest = value; + } + } + + protected IConnectionControl ConnectionControl => ConnectionContext.ConnectionControl; + protected IKestrelTrace Log => ConnectionContext.ListenerContext.ServiceContext.Log; + + private DateHeaderValueManager DateHeaderValueManager => ConnectionContext.ListenerContext.ServiceContext.DateHeaderValueManager; + private ServerAddress ServerAddress => ConnectionContext.ListenerContext.ServerAddress; + // Hold direct reference to ServerOptions since this is used very often in the request processing path + private KestrelServerOptions ServerOptions { get; } + private IPEndPoint LocalEndPoint => ConnectionContext.LocalEndPoint; + private IPEndPoint RemoteEndPoint => ConnectionContext.RemoteEndPoint; + private string ConnectionId => ConnectionContext.ConnectionId; + public string ConnectionIdFeature { get; set; } public IPAddress RemoteIpAddress { get; set; } public int RemotePort { get; set; } @@ -736,7 +768,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http responseHeaders.SetRawContentLength("0", _bytesContentLengthZero); } } - else if(_keepAlive) + else if (_keepAlive) { // Note for future reference: never change this to set _autoChunk to true on HTTP/1.0 // connections, even if we were to infer the client supports it because an HTTP/1.0 request diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Listener.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Listener.cs index a40515d66f..f66485a5ed 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Listener.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Listener.cs @@ -23,6 +23,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http protected UvStreamHandle ListenSocket { get; private set; } + public IKestrelTrace Log => ServiceContext.Log; + public Task StartAsync( ServerAddress address, KestrelThread thread) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ListenerContext.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ListenerContext.cs index f7c0dd1dac..8ecee653f0 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ListenerContext.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ListenerContext.cs @@ -1,32 +1,21 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System.Collections.Generic; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; - namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { - public class ListenerContext : ServiceContext + public class ListenerContext { - public ListenerContext() + public ListenerContext(ServiceContext serviceContext) { + ServiceContext = serviceContext; } - public ListenerContext(ServiceContext serviceContext) - : base(serviceContext) - { - } - - public ListenerContext(ListenerContext listenerContext) - : base(listenerContext) - { - ServerAddress = listenerContext.ServerAddress; - Thread = listenerContext.Thread; - } + public ServiceContext ServiceContext { get; set; } public ServerAddress ServerAddress { get; set; } public KestrelThread Thread { get; set; } + + public KestrelServerOptions ServerOptions => ServiceContext.ServerOptions; } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ListenerSecondary.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ListenerSecondary.cs index f3acef1f1d..3fd1db29be 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ListenerSecondary.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ListenerSecondary.cs @@ -12,7 +12,7 @@ using Microsoft.Extensions.Logging; namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { /// - /// A secondary listener is delegated requests from a primary listener via a named pipe or + /// A secondary listener is delegated requests from a primary listener via a named pipe or /// UNIX domain socket. /// public abstract class ListenerSecondary : ListenerContext, IAsyncDisposable @@ -29,6 +29,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http UvPipeHandle DispatchPipe { get; set; } + public IKestrelTrace Log => ServiceContext.Log; + public Task StartAsync( string pipeName, ServerAddress address, diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/KestrelEngine.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/KestrelEngine.cs index c611580ae4..1f7c4c7a3c 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/KestrelEngine.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/KestrelEngine.cs @@ -5,13 +5,15 @@ using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; +using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; using Microsoft.Extensions.Logging; namespace Microsoft.AspNetCore.Server.Kestrel.Internal { - public class KestrelEngine : ServiceContext, IDisposable + public class KestrelEngine : IDisposable { public KestrelEngine(ServiceContext context) : this(new Libuv(), context) @@ -19,15 +21,21 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal // For testing internal KestrelEngine(Libuv uv, ServiceContext context) - : base(context) { Libuv = uv; + ServiceContext = context; Threads = new List(); } public Libuv Libuv { get; private set; } + public ServiceContext ServiceContext { get; set; } public List Threads { get; private set; } + public IApplicationLifetime AppLifetime => ServiceContext.AppLifetime; + public IKestrelTrace Log => ServiceContext.Log; + public IThreadPool ThreadPool => ServiceContext.ThreadPool; + public KestrelServerOptions ServerOptions => ServiceContext.ServerOptions; + public void Start(int count) { for (var index = 0; index < count; index++) @@ -71,16 +79,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal if (single) { var listener = usingPipes ? - (Listener) new PipeListener(this) : - new TcpListener(this); + (Listener) new PipeListener(ServiceContext) : + new TcpListener(ServiceContext); listeners.Add(listener); listener.StartAsync(address, thread).Wait(); } else if (first) { var listener = usingPipes - ? (ListenerPrimary) new PipeListenerPrimary(this) - : new TcpListenerPrimary(this); + ? (ListenerPrimary) new PipeListenerPrimary(ServiceContext) + : new TcpListenerPrimary(ServiceContext); listeners.Add(listener); listener.StartAsync(pipeName, address, thread).Wait(); @@ -88,8 +96,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal else { var listener = usingPipes - ? (ListenerSecondary) new PipeListenerSecondary(this) - : new TcpListenerSecondary(this); + ? (ListenerSecondary) new PipeListenerSecondary(ServiceContext) + : new TcpListenerSecondary(ServiceContext); listeners.Add(listener); listener.StartAsync(pipeName, address, thread).Wait(); } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/ServiceContext.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/ServiceContext.cs index 77932ecf15..10ee1378f7 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/ServiceContext.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/ServiceContext.cs @@ -10,20 +10,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal { public class ServiceContext { - public ServiceContext() - { - } - - public ServiceContext(ServiceContext context) - { - AppLifetime = context.AppLifetime; - Log = context.Log; - ThreadPool = context.ThreadPool; - FrameFactory = context.FrameFactory; - DateHeaderValueManager = context.DateHeaderValueManager; - ServerOptions = context.ServerOptions; - } - public IApplicationLifetime AppLifetime { get; set; } public IKestrelTrace Log { get; set; } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionTests.cs index 0d42df12f0..a987904831 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionTests.cs @@ -27,10 +27,13 @@ namespace Microsoft.AspNetCore.Server.KestrelTests engine.Start(count: 1); var trace = new TestKestrelTrace(); - var context = new ListenerContext(new TestServiceContext()) + var serviceContext = new TestServiceContext { FrameFactory = connectionContext => new Frame( new DummyApplication(httpContext => TaskCache.CompletedTask), connectionContext), + }; + var context = new ListenerContext(serviceContext) + { ServerAddress = ServerAddress.FromUrl("http://127.0.0.1:0"), Thread = engine.Threads[0] }; diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameResponseHeadersTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameResponseHeadersTests.cs index bfca1e9158..c57ddff257 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameResponseHeadersTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameResponseHeadersTests.cs @@ -5,6 +5,7 @@ using System; using System.Collections.Generic; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Server.Kestrel; +using Microsoft.AspNetCore.Server.Kestrel.Internal; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; using Microsoft.Extensions.Primitives; using Xunit; @@ -18,12 +19,16 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { var serverOptions = new KestrelServerOptions(); - var connectionContext = new ConnectionContext + var serviceContext = new ServiceContext { DateHeaderValueManager = new DateHeaderValueManager(), - ServerAddress = ServerAddress.FromUrl("http://localhost:5000"), - ServerOptions = serverOptions, + ServerOptions = serverOptions }; + var listenerContext = new ListenerContext(serviceContext) + { + ServerAddress = ServerAddress.FromUrl("http://localhost:5000") + }; + var connectionContext = new ConnectionContext(listenerContext); var frame = new Frame(application: null, context: connectionContext); diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs index 09bffeee85..4854a2d369 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs @@ -27,12 +27,17 @@ namespace Microsoft.AspNetCore.Server.KestrelTests using (var pool = new MemoryPool()) using (var socketInput = new SocketInput(pool, ltp)) { - var connectionContext = new ConnectionContext() + var serviceContext = new ServiceContext { DateHeaderValueManager = new DateHeaderValueManager(), - ServerAddress = ServerAddress.FromUrl("http://localhost:5000"), - ServerOptions = new KestrelServerOptions(), + ServerOptions = new KestrelServerOptions() }; + var listenerContext = new ListenerContext(serviceContext) + { + ServerAddress = ServerAddress.FromUrl("http://localhost:5000") + }; + var connectionContext = new ConnectionContext(listenerContext); + var frame = new Frame(application: null, context: connectionContext); frame.Reset(); frame.InitializeHeaders(); @@ -70,12 +75,17 @@ namespace Microsoft.AspNetCore.Server.KestrelTests using (var pool = new MemoryPool()) using (var socketInput = new SocketInput(pool, ltp)) { - var connectionContext = new ConnectionContext() + var serviceContext = new ServiceContext { DateHeaderValueManager = new DateHeaderValueManager(), - ServerAddress = ServerAddress.FromUrl("http://localhost:5000"), - ServerOptions = new KestrelServerOptions(), + ServerOptions = new KestrelServerOptions() }; + var listenerContext = new ListenerContext(serviceContext) + { + ServerAddress = ServerAddress.FromUrl("http://localhost:5000") + }; + var connectionContext = new ConnectionContext(listenerContext); + var frame = new Frame(application: null, context: connectionContext); frame.Reset(); frame.InitializeHeaders(); @@ -112,12 +122,17 @@ namespace Microsoft.AspNetCore.Server.KestrelTests using (var pool = new MemoryPool()) using (var socketInput = new SocketInput(pool, ltp)) { - var connectionContext = new ConnectionContext() + var serviceContext = new ServiceContext { DateHeaderValueManager = new DateHeaderValueManager(), - ServerAddress = ServerAddress.FromUrl("http://localhost:5000"), - ServerOptions = new KestrelServerOptions(), + ServerOptions = new KestrelServerOptions() }; + var listenerContext = new ListenerContext(serviceContext) + { + ServerAddress = ServerAddress.FromUrl("http://localhost:5000") + }; + var connectionContext = new ConnectionContext(listenerContext); + var frame = new Frame(application: null, context: connectionContext); frame.Reset(); frame.InitializeHeaders(); @@ -153,12 +168,18 @@ namespace Microsoft.AspNetCore.Server.KestrelTests using (var pool = new MemoryPool()) using (var socketInput = new SocketInput(pool, ltp)) { - var connectionContext = new ConnectionContext() + var serviceContext = new ServiceContext { DateHeaderValueManager = new DateHeaderValueManager(), - ServerAddress = ServerAddress.FromUrl("http://localhost:5000"), ServerOptions = new KestrelServerOptions(), + Log = trace }; + var listenerContext = new ListenerContext(serviceContext) + { + ServerAddress = ServerAddress.FromUrl("http://localhost:5000") + }; + var connectionContext = new ConnectionContext(listenerContext); + var frame = new Frame(application: null, context: connectionContext); frame.Reset(); frame.InitializeHeaders(); @@ -194,13 +215,18 @@ namespace Microsoft.AspNetCore.Server.KestrelTests using (var pool = new MemoryPool()) using (var socketInput = new SocketInput(pool, ltp)) { - var connectionContext = new ConnectionContext() + var serviceContext = new ServiceContext { DateHeaderValueManager = new DateHeaderValueManager(), - ServerAddress = ServerAddress.FromUrl("http://localhost:5000"), ServerOptions = new KestrelServerOptions(), Log = trace }; + var listenerContext = new ListenerContext(serviceContext) + { + ServerAddress = ServerAddress.FromUrl("http://localhost:5000") + }; + var connectionContext = new ConnectionContext(listenerContext); + var frame = new Frame(application: null, context: connectionContext); frame.Reset(); frame.InitializeHeaders(); @@ -222,13 +248,18 @@ namespace Microsoft.AspNetCore.Server.KestrelTests using (var pool = new MemoryPool()) using (var socketInput = new SocketInput(pool, ltp)) { - var connectionContext = new ConnectionContext() + var serviceContext = new ServiceContext { DateHeaderValueManager = new DateHeaderValueManager(), - ServerAddress = ServerAddress.FromUrl("http://localhost:5000"), ServerOptions = new KestrelServerOptions(), Log = trace }; + var listenerContext = new ListenerContext(serviceContext) + { + ServerAddress = ServerAddress.FromUrl("http://localhost:5000") + }; + var connectionContext = new ConnectionContext(listenerContext); + var frame = new Frame(application: null, context: connectionContext); frame.Reset(); frame.InitializeHeaders(); @@ -259,13 +290,18 @@ namespace Microsoft.AspNetCore.Server.KestrelTests using (var pool = new MemoryPool()) using (var socketInput = new SocketInput(pool, ltp)) { - var connectionContext = new ConnectionContext() + var serviceContext = new ServiceContext { DateHeaderValueManager = new DateHeaderValueManager(), - ServerAddress = ServerAddress.FromUrl("http://localhost:5000"), ServerOptions = new KestrelServerOptions(), Log = trace }; + var listenerContext = new ListenerContext(serviceContext) + { + ServerAddress = ServerAddress.FromUrl("http://localhost:5000") + }; + var connectionContext = new ConnectionContext(listenerContext); + var frame = new Frame(application: null, context: connectionContext); frame.Reset(); frame.InitializeHeaders(); @@ -290,13 +326,18 @@ namespace Microsoft.AspNetCore.Server.KestrelTests using (var pool = new MemoryPool()) using (var socketInput = new SocketInput(pool, ltp)) { - var connectionContext = new ConnectionContext() + var serviceContext = new ServiceContext { DateHeaderValueManager = new DateHeaderValueManager(), - ServerAddress = ServerAddress.FromUrl("http://localhost:5000"), ServerOptions = new KestrelServerOptions(), Log = trace }; + var listenerContext = new ListenerContext(serviceContext) + { + ServerAddress = ServerAddress.FromUrl("http://localhost:5000") + }; + var connectionContext = new ConnectionContext(listenerContext); + var frame = new Frame(application: null, context: connectionContext); frame.Reset(); frame.InitializeHeaders(); @@ -322,13 +363,18 @@ namespace Microsoft.AspNetCore.Server.KestrelTests using (var pool = new MemoryPool()) using (var socketInput = new SocketInput(pool, ltp)) { - var connectionContext = new ConnectionContext() + var serviceContext = new ServiceContext { DateHeaderValueManager = new DateHeaderValueManager(), - ServerAddress = ServerAddress.FromUrl("http://localhost:5000"), ServerOptions = new KestrelServerOptions(), Log = trace }; + var listenerContext = new ListenerContext(serviceContext) + { + ServerAddress = ServerAddress.FromUrl("http://localhost:5000") + }; + var connectionContext = new ConnectionContext(listenerContext); + var frame = new Frame(application: null, context: connectionContext); frame.Reset(); frame.InitializeHeaders(); @@ -358,13 +404,18 @@ namespace Microsoft.AspNetCore.Server.KestrelTests using (var pool = new MemoryPool()) using (var socketInput = new SocketInput(pool, ltp)) { - var connectionContext = new ConnectionContext() + var serviceContext = new ServiceContext { DateHeaderValueManager = new DateHeaderValueManager(), - ServerAddress = ServerAddress.FromUrl("http://localhost:5000"), ServerOptions = new KestrelServerOptions(), Log = trace }; + var listenerContext = new ListenerContext(serviceContext) + { + ServerAddress = ServerAddress.FromUrl("http://localhost:5000") + }; + var connectionContext = new ConnectionContext(listenerContext); + var frame = new Frame(application: null, context: connectionContext); frame.Reset(); frame.InitializeHeaders(); @@ -389,13 +440,18 @@ namespace Microsoft.AspNetCore.Server.KestrelTests using (var pool = new MemoryPool()) using (var socketInput = new SocketInput(pool, ltp)) { - var connectionContext = new ConnectionContext() + var serviceContext = new ServiceContext { DateHeaderValueManager = new DateHeaderValueManager(), - ServerAddress = ServerAddress.FromUrl("http://localhost:5000"), ServerOptions = new KestrelServerOptions(), Log = trace }; + var listenerContext = new ListenerContext(serviceContext) + { + ServerAddress = ServerAddress.FromUrl("http://localhost:5000") + }; + var connectionContext = new ConnectionContext(listenerContext); + var frame = new Frame(application: null, context: connectionContext); frame.Reset(); frame.InitializeHeaders(); @@ -422,13 +478,17 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var options = new KestrelServerOptions(); options.Limits.MaxRequestHeadersTotalSize = headerLine.Length - 1; - var connectionContext = new ConnectionContext() + var serviceContext = new ServiceContext { DateHeaderValueManager = new DateHeaderValueManager(), - ServerAddress = ServerAddress.FromUrl("http://localhost:5000"), ServerOptions = options, Log = trace }; + var listenerContext = new ListenerContext(serviceContext) + { + ServerAddress = ServerAddress.FromUrl("http://localhost:5000") + }; + var connectionContext = new ConnectionContext(listenerContext); var frame = new Frame(application: null, context: connectionContext); frame.Reset(); @@ -456,13 +516,17 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var options = new KestrelServerOptions(); options.Limits.MaxRequestHeaderCount = 1; - var connectionContext = new ConnectionContext() + var serviceContext = new ServiceContext { DateHeaderValueManager = new DateHeaderValueManager(), - ServerAddress = ServerAddress.FromUrl("http://localhost:5000"), ServerOptions = options, Log = trace }; + var listenerContext = new ListenerContext(serviceContext) + { + ServerAddress = ServerAddress.FromUrl("http://localhost:5000") + }; + var connectionContext = new ConnectionContext(listenerContext); var frame = new Frame(application: null, context: connectionContext); frame.Reset(); @@ -491,12 +555,17 @@ namespace Microsoft.AspNetCore.Server.KestrelTests using (var pool = new MemoryPool()) using (var socketInput = new SocketInput(pool, ltp)) { - var connectionContext = new ConnectionContext() + var serviceContext = new ServiceContext { DateHeaderValueManager = new DateHeaderValueManager(), - ServerAddress = ServerAddress.FromUrl("http://localhost:5000"), - ServerOptions = new KestrelServerOptions(), + ServerOptions = new KestrelServerOptions() }; + var listenerContext = new ListenerContext(serviceContext) + { + ServerAddress = ServerAddress.FromUrl("http://localhost:5000") + }; + var connectionContext = new ConnectionContext(listenerContext); + var frame = new Frame(application: null, context: connectionContext); frame.Reset(); frame.InitializeHeaders(); @@ -519,12 +588,17 @@ namespace Microsoft.AspNetCore.Server.KestrelTests public void ResetResetsScheme() { // Arrange - var connectionContext = new ConnectionContext() + var serviceContext = new ServiceContext { DateHeaderValueManager = new DateHeaderValueManager(), - ServerAddress = ServerAddress.FromUrl("http://localhost:5000"), - ServerOptions = new KestrelServerOptions(), + ServerOptions = new KestrelServerOptions() }; + var listenerContext = new ListenerContext(serviceContext) + { + ServerAddress = ServerAddress.FromUrl("http://localhost:5000") + }; + var connectionContext = new ConnectionContext(listenerContext); + var frame = new Frame(application: null, context: connectionContext); frame.Scheme = "https"; @@ -550,12 +624,16 @@ namespace Microsoft.AspNetCore.Server.KestrelTests options.Limits.MaxRequestHeadersTotalSize = headerLine1.Length; options.Limits.MaxRequestHeaderCount = 1; - var connectionContext = new ConnectionContext() + var serviceContext = new ServiceContext { DateHeaderValueManager = new DateHeaderValueManager(), - ServerAddress = ServerAddress.FromUrl("http://localhost:5000"), ServerOptions = options }; + var listenerContext = new ListenerContext(serviceContext) + { + ServerAddress = ServerAddress.FromUrl("http://localhost:5000") + }; + var connectionContext = new ConnectionContext(listenerContext); var frame = new Frame(application: null, context: connectionContext); frame.Reset(); @@ -583,13 +661,20 @@ namespace Microsoft.AspNetCore.Server.KestrelTests public void ThrowsWhenStatusCodeIsSetAfterResponseStarted() { // Arrange - var connectionContext = new ConnectionContext() + var serviceContext = new ServiceContext { DateHeaderValueManager = new DateHeaderValueManager(), - ServerAddress = ServerAddress.FromUrl("http://localhost:5000"), - ServerOptions = new KestrelServerOptions(), + ServerOptions = new KestrelServerOptions() + }; + var listenerContext = new ListenerContext(serviceContext) + { + ServerAddress = ServerAddress.FromUrl("http://localhost:5000") + }; + var connectionContext = new ConnectionContext(listenerContext) + { SocketOutput = new MockSocketOuptut() }; + var frame = new Frame(application: null, context: connectionContext); frame.InitializeHeaders(); @@ -605,13 +690,20 @@ namespace Microsoft.AspNetCore.Server.KestrelTests public void ThrowsWhenReasonPhraseIsSetAfterResponseStarted() { // Arrange - var connectionContext = new ConnectionContext() + var serviceContext = new ServiceContext { DateHeaderValueManager = new DateHeaderValueManager(), - ServerAddress = ServerAddress.FromUrl("http://localhost:5000"), - ServerOptions = new KestrelServerOptions(), + ServerOptions = new KestrelServerOptions() + }; + var listenerContext = new ListenerContext(serviceContext) + { + ServerAddress = ServerAddress.FromUrl("http://localhost:5000") + }; + var connectionContext = new ConnectionContext(listenerContext) + { SocketOutput = new MockSocketOuptut() }; + var frame = new Frame(application: null, context: connectionContext); frame.InitializeHeaders(); @@ -627,13 +719,20 @@ namespace Microsoft.AspNetCore.Server.KestrelTests public void ThrowsWhenOnStartingIsSetAfterResponseStarted() { // Arrange - var connectionContext = new ConnectionContext() + var serviceContext = new ServiceContext { DateHeaderValueManager = new DateHeaderValueManager(), - ServerAddress = ServerAddress.FromUrl("http://localhost:5000"), - ServerOptions = new KestrelServerOptions(), + ServerOptions = new KestrelServerOptions() + }; + var listenerContext = new ListenerContext(serviceContext) + { + ServerAddress = ServerAddress.FromUrl("http://localhost:5000") + }; + var connectionContext = new ConnectionContext(listenerContext) + { SocketOutput = new MockSocketOuptut() }; + var frame = new Frame(application: null, context: connectionContext); frame.InitializeHeaders(); frame.Write(new ArraySegment(new byte[1])); @@ -647,13 +746,20 @@ namespace Microsoft.AspNetCore.Server.KestrelTests public void InitializeHeadersResetsRequestHeaders() { // Arrange - var connectionContext = new ConnectionContext() + var serviceContext = new ServiceContext { DateHeaderValueManager = new DateHeaderValueManager(), - ServerAddress = ServerAddress.FromUrl("http://localhost:5000"), - ServerOptions = new KestrelServerOptions(), + ServerOptions = new KestrelServerOptions() + }; + var listenerContext = new ListenerContext(serviceContext) + { + ServerAddress = ServerAddress.FromUrl("http://localhost:5000") + }; + var connectionContext = new ConnectionContext(listenerContext) + { SocketOutput = new MockSocketOuptut() }; + var frame = new Frame(application: null, context: connectionContext); frame.InitializeHeaders(); @@ -671,13 +777,20 @@ namespace Microsoft.AspNetCore.Server.KestrelTests public void InitializeHeadersResetsResponseHeaders() { // Arrange - var connectionContext = new ConnectionContext() + var serviceContext = new ServiceContext { DateHeaderValueManager = new DateHeaderValueManager(), - ServerAddress = ServerAddress.FromUrl("http://localhost:5000"), - ServerOptions = new KestrelServerOptions(), + ServerOptions = new KestrelServerOptions() + }; + var listenerContext = new ListenerContext(serviceContext) + { + ServerAddress = ServerAddress.FromUrl("http://localhost:5000") + }; + var connectionContext = new ConnectionContext(listenerContext) + { SocketOutput = new MockSocketOuptut() }; + var frame = new Frame(application: null, context: connectionContext); frame.InitializeHeaders(); @@ -695,13 +808,20 @@ namespace Microsoft.AspNetCore.Server.KestrelTests public void InitializeStreamsResetsStreams() { // Arrange - var connectionContext = new ConnectionContext() + var serviceContext = new ServiceContext { DateHeaderValueManager = new DateHeaderValueManager(), - ServerAddress = ServerAddress.FromUrl("http://localhost:5000"), - ServerOptions = new KestrelServerOptions(), + ServerOptions = new KestrelServerOptions() + }; + var listenerContext = new ListenerContext(serviceContext) + { + ServerAddress = ServerAddress.FromUrl("http://localhost:5000") + }; + var connectionContext = new ConnectionContext(listenerContext) + { SocketOutput = new MockSocketOuptut() }; + var frame = new Frame(application: null, context: connectionContext); frame.InitializeHeaders(); @@ -732,14 +852,20 @@ namespace Microsoft.AspNetCore.Server.KestrelTests using (var pool = new MemoryPool()) using (var socketInput = new SocketInput(pool, ltp)) { - var connectionContext = new ConnectionContext() + var serviceContext = new ServiceContext { - ConnectionControl = new Mock().Object, DateHeaderValueManager = new DateHeaderValueManager(), - ServerAddress = ServerAddress.FromUrl("http://localhost:5000"), ServerOptions = new KestrelServerOptions(), Log = trace }; + var listenerContext = new ListenerContext(serviceContext) + { + ServerAddress = ServerAddress.FromUrl("http://localhost:5000"), + }; + var connectionContext = new ConnectionContext(listenerContext) + { + ConnectionControl = new Mock().Object + }; var frame = new Frame(application: null, context: connectionContext); frame.Reset(); @@ -779,14 +905,20 @@ namespace Microsoft.AspNetCore.Server.KestrelTests using (var pool = new MemoryPool()) using (var socketInput = new SocketInput(pool, ltp)) { - var connectionContext = new ConnectionContext() + var serviceContext = new ServiceContext { - ConnectionControl = new Mock().Object, DateHeaderValueManager = new DateHeaderValueManager(), - ServerAddress = ServerAddress.FromUrl("http://localhost:5000"), ServerOptions = new KestrelServerOptions(), Log = trace }; + var listenerContext = new ListenerContext(serviceContext) + { + ServerAddress = ServerAddress.FromUrl("http://localhost:5000"), + }; + var connectionContext = new ConnectionContext(listenerContext) + { + ConnectionControl = new Mock().Object + }; var frame = new Frame(application: null, context: connectionContext); frame.Reset(); @@ -806,15 +938,21 @@ namespace Microsoft.AspNetCore.Server.KestrelTests using (var pool = new MemoryPool()) using (var socketInput = new SocketInput(pool, ltp)) { - var connectionControl = new Mock(); - var connectionContext = new ConnectionContext() + var serviceContext = new ServiceContext { - ConnectionControl = connectionControl.Object, DateHeaderValueManager = new DateHeaderValueManager(), - ServerAddress = ServerAddress.FromUrl("http://localhost:5000"), ServerOptions = new KestrelServerOptions(), Log = trace }; + var listenerContext = new ListenerContext(serviceContext) + { + ServerAddress = ServerAddress.FromUrl("http://localhost:5000"), + }; + var connectionControl = new Mock(); + var connectionContext = new ConnectionContext(listenerContext) + { + ConnectionControl = connectionControl.Object + }; var frame = new Frame(application: null, context: connectionContext); frame.Reset(); @@ -834,15 +972,21 @@ namespace Microsoft.AspNetCore.Server.KestrelTests using (var pool = new MemoryPool()) using (var socketInput = new SocketInput(pool, ltp)) { - var connectionControl = new Mock(); - var connectionContext = new ConnectionContext() + var serviceContext = new ServiceContext { - ConnectionControl = connectionControl.Object, DateHeaderValueManager = new DateHeaderValueManager(), - ServerAddress = ServerAddress.FromUrl("http://localhost:5000"), ServerOptions = new KestrelServerOptions(), Log = trace }; + var listenerContext = new ListenerContext(serviceContext) + { + ServerAddress = ServerAddress.FromUrl("http://localhost:5000") + }; + var connectionControl = new Mock(); + var connectionContext = new ConnectionContext(listenerContext) + { + ConnectionControl = connectionControl.Object + }; var frame = new Frame(application: null, context: connectionContext); frame.Reset(); @@ -859,11 +1003,9 @@ namespace Microsoft.AspNetCore.Server.KestrelTests using (var pool = new MemoryPool()) using (var socketInput = new SocketInput(pool, ltp)) { - var connectionContext = new ConnectionContext() + var serviceContext = new ServiceContext { - ConnectionControl = Mock.Of(), DateHeaderValueManager = new DateHeaderValueManager(), - ServerAddress = ServerAddress.FromUrl("http://localhost:5000"), ServerOptions = new KestrelServerOptions() { Limits = @@ -873,6 +1015,14 @@ namespace Microsoft.AspNetCore.Server.KestrelTests }, Log = trace }; + var listenerContext = new ListenerContext(serviceContext) + { + ServerAddress = ServerAddress.FromUrl("http://localhost:5000") + }; + var connectionContext = new ConnectionContext(listenerContext) + { + ConnectionControl = Mock.Of() + }; var frame = new Frame(application: null, context: connectionContext); frame.Reset(); @@ -904,14 +1054,20 @@ namespace Microsoft.AspNetCore.Server.KestrelTests using (var pool = new MemoryPool()) using (var socketInput = new SocketInput(pool, ltp)) { - var connectionContext = new ConnectionContext() + var serviceContext = new ServiceContext { - ConnectionControl = Mock.Of(), DateHeaderValueManager = new DateHeaderValueManager(), - ServerAddress = ServerAddress.FromUrl("http://localhost:5000"), ServerOptions = new KestrelServerOptions(), Log = trace }; + var listenerContext = new ListenerContext(serviceContext) + { + ServerAddress = ServerAddress.FromUrl("http://localhost:5000") + }; + var connectionContext = new ConnectionContext(listenerContext) + { + ConnectionControl = Mock.Of() + }; var frame = new Frame(application: null, context: connectionContext); frame.Reset(); @@ -932,14 +1088,20 @@ namespace Microsoft.AspNetCore.Server.KestrelTests using (var pool = new MemoryPool()) using (var socketInput = new SocketInput(pool, ltp)) { - var connectionContext = new ConnectionContext() + var serviceContext = new ServiceContext { - ConnectionControl = Mock.Of(), DateHeaderValueManager = new DateHeaderValueManager(), - ServerAddress = ServerAddress.FromUrl("http://localhost:5000"), ServerOptions = new KestrelServerOptions(), Log = trace }; + var listenerContext = new ListenerContext(serviceContext) + { + ServerAddress = ServerAddress.FromUrl("http://localhost:5000") + }; + var connectionContext = new ConnectionContext(listenerContext) + { + ConnectionControl = Mock.Of(), + }; var frame = new Frame(application: null, context: connectionContext); frame.Reset(); @@ -960,13 +1122,17 @@ namespace Microsoft.AspNetCore.Server.KestrelTests using (var pool = new MemoryPool()) using (var socketInput = new SocketInput(pool, ltp)) { - var connectionContext = new ConnectionContext() + var serviceContext = new ServiceContext { DateHeaderValueManager = new DateHeaderValueManager(), - ServerAddress = ServerAddress.FromUrl("http://localhost:5000"), ServerOptions = new KestrelServerOptions(), Log = trace }; + var listenerContext = new ListenerContext(serviceContext) + { + ServerAddress = ServerAddress.FromUrl("http://localhost:5000") + }; + var connectionContext = new ConnectionContext(listenerContext); var frame = new Frame(application: null, context: connectionContext); frame.Reset(); frame.InitializeHeaders(); @@ -1013,13 +1179,17 @@ namespace Microsoft.AspNetCore.Server.KestrelTests using (var pool = new MemoryPool()) using (var socketInput = new SocketInput(pool, ltp)) { - var connectionContext = new ConnectionContext() + var serviceContext = new ServiceContext { DateHeaderValueManager = new DateHeaderValueManager(), - ServerAddress = ServerAddress.FromUrl("http://localhost:5000"), ServerOptions = new KestrelServerOptions(), Log = trace }; + var listenerContext = new ListenerContext(serviceContext) + { + ServerAddress = ServerAddress.FromUrl("http://localhost:5000"), + }; + var connectionContext = new ConnectionContext(listenerContext); var frame = new Frame(application: null, context: connectionContext); frame.Reset(); frame.InitializeHeaders(); @@ -1039,20 +1209,26 @@ namespace Microsoft.AspNetCore.Server.KestrelTests using (var pool = new MemoryPool()) using (var socketInput = new SocketInput(pool, ltp)) { - var connectionControl = new Mock(); - var connectionContext = new ConnectionContext() + var serviceContext = new ServiceContext { - ConnectionControl = connectionControl.Object, DateHeaderValueManager = new DateHeaderValueManager(), - ServerAddress = ServerAddress.FromUrl("http://localhost:5000"), ServerOptions = new KestrelServerOptions(), Log = trace }; + var listenerContext = new ListenerContext(serviceContext) + { + ServerAddress = ServerAddress.FromUrl("http://localhost:5000") + }; + var connectionControl = new Mock(); + var connectionContext = new ConnectionContext(listenerContext) + { + ConnectionControl = connectionControl.Object + }; var frame = new Frame(application: null, context: connectionContext); frame.Reset(); var requestProcessingTask = frame.RequestProcessingAsync(); - connectionControl.Verify(cc => cc.SetTimeout((long)connectionContext.ServerOptions.Limits.KeepAliveTimeout.TotalMilliseconds)); + connectionControl.Verify(cc => cc.SetTimeout((long)serviceContext.ServerOptions.Limits.KeepAliveTimeout.TotalMilliseconds)); frame.Stop(); socketInput.IncomingFin(); diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockConnection.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockConnection.cs index 7a095cfcff..ee781a3935 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockConnection.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockConnection.cs @@ -5,6 +5,7 @@ using System; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel; +using Microsoft.AspNetCore.Server.Kestrel.Internal; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; namespace Microsoft.AspNetCore.Server.KestrelTests.TestHelpers @@ -17,7 +18,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests.TestHelpers { ConnectionControl = this; RequestAbortedSource = new CancellationTokenSource(); - ServerOptions = options; + ListenerContext = new ListenerContext(new ServiceContext { ServerOptions = options }); } public override void Abort(Exception error = null) diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestInput.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/TestInput.cs index a9b357d139..47fb05c169 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/TestInput.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/TestInput.cs @@ -22,19 +22,22 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { var trace = new KestrelTrace(new TestKestrelTrace()); var ltp = new LoggingThreadPool(trace); - var connectionContext = new ConnectionContext() - { - ServerAddress = new ServerAddress(), - ServerOptions = new KestrelServerOptions() - }; - var context = new Frame(null, connectionContext) + var serviceContext = new ServiceContext { DateHeaderValueManager = new DateHeaderValueManager(), - ServerAddress = ServerAddress.FromUrl("http://localhost:5000"), - ConnectionControl = this, - FrameControl = this + ServerOptions = new KestrelServerOptions() }; + var listenerContext = new ListenerContext(serviceContext) + { + ServerAddress = ServerAddress.FromUrl("http://localhost:5000") + }; + var connectionContext = new ConnectionContext(listenerContext) + { + ConnectionControl = this + }; + var context = new Frame(null, connectionContext); FrameContext = context; + FrameContext.FrameControl = this; _memoryPool = new MemoryPool(); FrameContext.SocketInput = new SocketInput(_memoryPool, ltp); From 0edf36bd2159a69bbdcab5a806be904b4649d2fd Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Tue, 9 Aug 2016 14:49:03 -0700 Subject: [PATCH 0892/1662] Return last block from SocketInput when data is fully consumed - This reduces Kestrel's memory usage for idle connections. --- .../Internal/Http/SocketInput.cs | 61 ++++++++++++------- 1 file changed, 40 insertions(+), 21 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/SocketInput.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/SocketInput.cs index 61f477ea4a..e73b72b77e 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/SocketInput.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/SocketInput.cs @@ -53,18 +53,21 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http public MemoryPoolBlock IncomingStart() { - const int minimumSize = 2048; - - if (_tail != null && minimumSize <= _tail.Data.Offset + _tail.Data.Count - _tail.End) + lock (_sync) { - _pinned = _tail; - } - else - { - _pinned = _memory.Lease(); - } + const int minimumSize = 2048; - return _pinned; + if (_tail != null && minimumSize <= _tail.Data.Offset + _tail.Data.Count - _tail.End) + { + _pinned = _tail; + } + else + { + _pinned = _memory.Lease(); + } + + return _pinned; + } } public void IncomingComplete(int count, Exception error) @@ -112,14 +115,17 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { Debug.Assert(_pinned != null); - if (_pinned != null) + lock (_sync) { - if (_pinned != _tail) + if (_pinned != null) { - _memory.Return(_pinned); - } + if (_pinned != _tail) + { + _memory.Return(_pinned); + } - _pinned = null; + _pinned = null; + } } } @@ -172,18 +178,31 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } returnStart = _head; - returnEnd = consumed.Block; - _head = consumed.Block; - _head.Start = consumed.Index; + + var consumedAll = !consumed.IsDefault && consumed.IsEnd; + if (consumedAll && _pinned != _tail) + { + // Everything has been consumed and no data is being written to the + // _tail block, so return all blocks between _head and _tail inclusive. + returnEnd = null; + _head = null; + _tail = null; + } + else + { + returnEnd = consumed.Block; + _head = consumed.Block; + _head.Start = consumed.Index; + } // Must call Subtract() after _head has been advanced, to avoid producer starting too early and growing // buffer beyond max length. _bufferSizeControl?.Subtract(lengthConsumed); } - if (!examined.IsDefault && - examined.IsEnd && - ReadingInput) + // If _head is null, everything has been consumed and examined. + var examinedAll = (!examined.IsDefault && examined.IsEnd) || _head == null; + if (examinedAll && ReadingInput) { _manualResetEvent.Reset(); From 7b2f7b94ab56dd78411d6d29e3a5d9598e042c0f Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Thu, 22 Sep 2016 16:29:42 -0700 Subject: [PATCH 0893/1662] Return last block from SocketOutput when data is fully written - This reduces Kestrel's memory usage for idle connections. --- .../Internal/Http/SocketOutput.cs | 124 +++++++++++------- 1 file changed, 73 insertions(+), 51 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/SocketOutput.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/SocketOutput.cs index 26621f4022..29124e0039 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/SocketOutput.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/SocketOutput.cs @@ -16,9 +16,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http public class SocketOutput : ISocketOutput { private const int _maxPendingWrites = 3; + // There should be never be more WriteContexts than the max ongoing writes + 1 for the next write to be scheduled. + private const int _maxPooledWriteContexts = _maxPendingWrites + 1; // Well behaved WriteAsync users should await returned task, so there is no need to allocate more per connection by default private const int _initialTaskQueues = 1; - private const int _maxPooledWriteContexts = 32; private static readonly WaitCallback _returnBlocks = (state) => ReturnBlocks((MemoryPoolBlock)state); private static readonly Action _connectionCancellation = (state) => ((SocketOutput)state).CancellationTriggered(); @@ -31,13 +32,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http private readonly IKestrelTrace _log; private readonly IThreadPool _threadPool; - // This locks all access to _tail and _lastStart. - // _head does not require a lock, since it is only used in the ctor and uv thread. + // This locks all access to _tail, _head, _lastStart and _closed. private readonly object _returnLock = new object(); + private bool _closed; private MemoryPoolBlock _head; private MemoryPoolBlock _tail; - private MemoryPoolIterator _lastStart; // This locks access to to all of the below fields @@ -77,9 +77,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _writeContextPool = new Queue(_maxPooledWriteContexts); _writeReqPool = thread.WriteReqPool; _maxBytesPreCompleted = connection.ServerOptions.Limits.MaxResponseBufferSize; - - _head = thread.Memory.Lease(); - _tail = _head; } public Task WriteAsync( @@ -232,11 +229,17 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { Debug.Assert(_lastStart.IsDefault); - if (_tail == null) + if (_closed) { return default(MemoryPoolIterator); } + if (_tail == null) + { + _head = _thread.Memory.Lease(); + _tail = _head; + } + _lastStart = new MemoryPoolIterator(_tail, _tail.End); return _lastStart; @@ -375,8 +378,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _lastWriteError = error; } - PoolWriteContext(writeContext); - // _numBytesPreCompleted can temporarily go negative in the event there are // completed writes that we haven't triggered callbacks for yet. _numBytesPreCompleted -= bytesWritten; @@ -491,21 +492,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http // Only return the _tail if we aren't between ProducingStart/Complete calls if (_lastStart.IsDefault) { - _tail.Pool.Return(_tail); + _tail?.Pool.Return(_tail); } _head = null; _tail = null; - } - } - - private void PoolWriteContext(WriteContext writeContext) - { - // Called inside _contextLock - if (_writeContextPool.Count < _maxPooledWriteContexts) - { - writeContext.Reset(); - _writeContextPool.Enqueue(writeContext); + _closed = true; } } @@ -554,7 +546,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http private class WriteContext { - private static readonly WaitCallback _returnWrittenBlocks = (state) => ReturnWrittenBlocks((MemoryPoolBlock)state); + private static readonly WaitCallback _returnWrittenBlocks = (state) => ((WriteContext)state).ReturnWrittenBlocks(); private static readonly WaitCallback _completeWrite = (state) => ((WriteContext)state).CompleteOnThreadPool(); private SocketOutput Self; @@ -563,6 +555,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http private MemoryPoolIterator _lockedEnd; private int _bufferCount; + // _returnBlocksCompleted and _writeCompleted help determine when it's safe to pool the WriteContext + // These are both guarded by the _contextLock. + private bool _returnBlocksCompleted; + private bool _writeCompleted; + public int ByteCount; public bool SocketShutdownSend; public bool SocketDisconnect; @@ -588,10 +585,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http return; } - // Sample values locally in case write completes inline - // to allow block to be Reset and still complete this function - var lockedEndBlock = _lockedEnd.Block; - var lockedEndIndex = _lockedEnd.Index; + // Update _head immediate after write is "locked", so the block returning logic + // works correctly when run inline in the write callback. + Self._head = _lockedEnd.Block; + Self._head.Start = _lockedEnd.Index; _writeReq = Self._writeReqPool.Allocate(); @@ -600,14 +597,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var writeContext = (WriteContext)state; writeContext.PoolWriteReq(writeContext._writeReq); writeContext._writeReq = null; - writeContext.ScheduleReturnFullyWrittenBlocks(); + writeContext.ScheduleReturnWrittenBlocks(); writeContext.WriteStatus = status; writeContext.WriteError = error; writeContext.DoShutdownIfNeeded(); }, this); - - Self._head = lockedEndBlock; - Self._head.Start = lockedEndIndex; } /// @@ -638,7 +632,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http /// /// Third step: disconnect socket if needed, otherwise this work item is complete /// - public void DoDisconnectIfNeeded() + private void DoDisconnectIfNeeded() { if (SocketDisconnect == false || Self._socket.IsClosed) { @@ -655,13 +649,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http CompleteWithContextLock(); } - public void CompleteWithContextLock() + private void CompleteWithContextLock() { if (Monitor.TryEnter(Self._contextLock)) { try { Self.OnWriteCompleted(this); + _writeCompleted = true; + TryPool(); } finally { @@ -674,13 +670,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } } - public void CompleteOnThreadPool() + private void CompleteOnThreadPool() { lock (Self._contextLock) { try { Self.OnWriteCompleted(this); + _writeCompleted = true; + TryPool(); } catch (Exception ex) { @@ -694,33 +692,43 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http Self._writeReqPool.Return(writeReq); } - private void ScheduleReturnFullyWrittenBlocks() + private void ScheduleReturnWrittenBlocks() { - var block = _lockedStart.Block; - var end = _lockedEnd.Block; - if (block == end) - { - return; - } - - while (block.Next != end) - { - block = block.Next; - } - block.Next = null; - - Self._threadPool.UnsafeRun(_returnWrittenBlocks, _lockedStart.Block); + Self._threadPool.UnsafeRun(_returnWrittenBlocks, this); } - private static void ReturnWrittenBlocks(MemoryPoolBlock block) + private void ReturnWrittenBlocks() { - while (block != null) + var block = _lockedStart.Block; + while (block != _lockedEnd.Block) { var returnBlock = block; block = block.Next; returnBlock.Pool.Return(returnBlock); } + + lock (Self._returnLock) + { + // If everything has been fully written, return _tail. + if (_lockedEnd.Block == Self._tail && + _lockedEnd.Index == Self._tail.End && + Self._lastStart.IsDefault) + { + Debug.Assert(Self._head == Self._tail); + Debug.Assert(Self._tail.Start == Self._tail.End); + + _lockedEnd.Block.Pool.Return(_lockedEnd.Block); + Self._head = null; + Self._tail = null; + } + } + + lock (Self._contextLock) + { + _returnBlocksCompleted = true; + TryPool(); + } } private void LockWrite() @@ -741,12 +749,26 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http BytesBetween(_lockedStart, _lockedEnd, out ByteCount, out _bufferCount); } - public void Reset() + private void TryPool() + { + // Called inside _contextLock + if (_writeCompleted && + _returnBlocksCompleted && + Self._writeContextPool.Count < _maxPooledWriteContexts) + { + Reset(); + Self._writeContextPool.Enqueue(this); + } + } + + private void Reset() { _lockedStart = default(MemoryPoolIterator); _lockedEnd = default(MemoryPoolIterator); _bufferCount = 0; ByteCount = 0; + _writeCompleted = false; + _returnBlocksCompleted = false; SocketShutdownSend = false; SocketDisconnect = false; From 0312da7df39874e7f3554ec556d3203f1385e343 Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Fri, 16 Sep 2016 09:46:57 -0700 Subject: [PATCH 0894/1662] Add request headers timeout (#1110). --- .../BadHttpRequestException.cs | 3 + .../Internal/Http/Connection.cs | 28 +++- .../Internal/Http/Frame.cs | 24 +++- .../Internal/Http/FrameOfT.cs | 8 +- .../Internal/Http/IConnectionControl.cs | 3 +- .../Internal/Http/RequestRejectionReason.cs | 1 + .../Internal/Http/TimeoutAction.cs | 11 ++ .../KestrelServerLimits.cs | 28 +++- .../KeepAliveTimeoutTests.cs | 21 +-- .../RequestHeadersTimeoutTests.cs | 135 ++++++++++++++++++ .../ResponseTests.cs | 35 +++++ .../FrameTests.cs | 48 +++++-- .../KestrelServerLimitsTests.cs | 20 +++ .../TestInput.cs | 6 +- test/shared/TestConnection.cs | 25 ++++ 15 files changed, 350 insertions(+), 46 deletions(-) create mode 100644 src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/TimeoutAction.cs create mode 100644 test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestHeadersTimeoutTests.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/BadHttpRequestException.cs b/src/Microsoft.AspNetCore.Server.Kestrel/BadHttpRequestException.cs index 196a6e941f..f5981b5607 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/BadHttpRequestException.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/BadHttpRequestException.cs @@ -102,6 +102,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel case RequestRejectionReason.TooManyHeaders: ex = new BadHttpRequestException("Request contains too many headers.", 431); break; + case RequestRejectionReason.RequestTimeout: + ex = new BadHttpRequestException("Request timed out.", 408); + break; default: ex = new BadHttpRequestException("Bad request.", 400); break; diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Connection.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Connection.cs index 877e66fac0..2ba693ef73 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Connection.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Connection.cs @@ -41,6 +41,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http private long _lastTimestamp; private long _timeoutTimestamp = long.MaxValue; + private TimeoutAction _timeoutAction; public Connection(ListenerContext context, UvStreamHandle socket) : base(context) { @@ -170,8 +171,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http // Called on Libuv thread public void Tick(long timestamp) { - if (timestamp > _timeoutTimestamp) + if (timestamp > Interlocked.Read(ref _timeoutTimestamp)) { + ConnectionControl.CancelTimeout(); + + if (_timeoutAction == TimeoutAction.SendTimeoutResponse) + { + _frame.SetBadRequestState(RequestRejectionReason.RequestTimeout); + } + StopAsync(); } @@ -299,12 +307,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } } - void IConnectionControl.SetTimeout(long milliseconds) + void IConnectionControl.SetTimeout(long milliseconds, TimeoutAction timeoutAction) { Debug.Assert(_timeoutTimestamp == long.MaxValue, "Concurrent timeouts are not supported"); - // Add KestrelThread.HeartbeatMilliseconds extra milliseconds since this can be called right before the next heartbeat. - Interlocked.Exchange(ref _timeoutTimestamp, _lastTimestamp + milliseconds + KestrelThread.HeartbeatMilliseconds); + AssignTimeout(milliseconds, timeoutAction); + } + + void IConnectionControl.ResetTimeout(long milliseconds, TimeoutAction timeoutAction) + { + AssignTimeout(milliseconds, timeoutAction); } void IConnectionControl.CancelTimeout() @@ -312,6 +324,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http Interlocked.Exchange(ref _timeoutTimestamp, long.MaxValue); } + private void AssignTimeout(long milliseconds, TimeoutAction timeoutAction) + { + _timeoutAction = timeoutAction; + + // Add KestrelThread.HeartbeatMilliseconds extra milliseconds since this can be called right before the next heartbeat. + Interlocked.Exchange(ref _timeoutTimestamp, _lastTimestamp + milliseconds + KestrelThread.HeartbeatMilliseconds); + } + private static unsafe string GenerateConnectionId(long id) { // The following routine is ~310% faster than calling long.ToString() on x64 diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs index dde74b0f56..767130fd03 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs @@ -71,6 +71,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http private int _requestHeadersParsed; protected readonly long _keepAliveMilliseconds; + private readonly long _requestHeadersTimeoutMilliseconds; public Frame(ConnectionContext context) { @@ -84,6 +85,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http FrameControl = this; _keepAliveMilliseconds = (long)ServerOptions.Limits.KeepAliveTimeout.TotalMilliseconds; + _requestHeadersTimeoutMilliseconds = (long)ServerOptions.Limits.RequestHeadersTimeout.TotalMilliseconds; } public ConnectionContext ConnectionContext { get; } @@ -372,6 +374,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { _requestProcessingStopping = true; } + return _requestProcessingTask ?? TaskCache.CompletedTask; } @@ -648,7 +651,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http protected Task TryProduceInvalidRequestResponse() { - if (_requestProcessingStatus == RequestProcessingStatus.RequestStarted && _requestRejected) + if (_requestRejected) { if (FrameRequestHeaders == null || FrameResponseHeaders == null) { @@ -833,7 +836,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http return RequestLineStatus.Empty; } - ConnectionControl.CancelTimeout(); + if (_requestProcessingStatus == RequestProcessingStatus.RequestPending) + { + ConnectionControl.ResetTimeout(_requestHeadersTimeoutMilliseconds, TimeoutAction.SendTimeoutResponse); + } _requestProcessingStatus = RequestProcessingStatus.RequestStarted; @@ -1102,6 +1108,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } else if (ch == '\n') { + ConnectionControl.CancelTimeout(); consumed = end; return true; } @@ -1274,12 +1281,23 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http throw ex; } + public void SetBadRequestState(RequestRejectionReason reason) + { + SetBadRequestState(BadHttpRequestException.GetException(reason)); + } + public void SetBadRequestState(BadHttpRequestException ex) { - StatusCode = ex.StatusCode; + // Setting status code will throw if response has already started + if (!HasResponseStarted) + { + StatusCode = ex.StatusCode; + } + _keepAlive = false; _requestProcessingStopping = true; _requestRejected = true; + Log.ConnectionBadRequest(ConnectionId, ex); } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameOfT.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameOfT.cs index 99d56f1fbf..fd8306baf7 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameOfT.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameOfT.cs @@ -32,7 +32,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { while (!_requestProcessingStopping) { - ConnectionControl.SetTimeout(_keepAliveMilliseconds); + ConnectionControl.SetTimeout(_keepAliveMilliseconds, TimeoutAction.CloseConnection); while (!_requestProcessingStopping && TakeStartLine(SocketInput) != RequestLineStatus.Done) { @@ -141,7 +141,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } } - Reset(); + // Don't lose request rejection state + if (!_requestRejected) + { + Reset(); + } } } catch (BadHttpRequestException ex) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/IConnectionControl.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/IConnectionControl.cs index f7de78dfcf..2905913040 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/IConnectionControl.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/IConnectionControl.cs @@ -8,7 +8,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http void Pause(); void Resume(); void End(ProduceEndType endType); - void SetTimeout(long milliseconds); + void SetTimeout(long milliseconds, TimeoutAction timeoutAction); + void ResetTimeout(long milliseconds, TimeoutAction timeoutAction); void CancelTimeout(); } } \ No newline at end of file diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/RequestRejectionReason.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/RequestRejectionReason.cs index a0d04ed0fc..3bd3aecaf5 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/RequestRejectionReason.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/RequestRejectionReason.cs @@ -34,5 +34,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http HeadersExceedMaxTotalSize, MissingCRInHeaderLine, TooManyHeaders, + RequestTimeout, } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/TimeoutAction.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/TimeoutAction.cs new file mode 100644 index 0000000000..33d832ce01 --- /dev/null +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/TimeoutAction.cs @@ -0,0 +1,11 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http +{ + public enum TimeoutAction + { + CloseConnection, + SendTimeoutResponse + } +} diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServerLimits.cs b/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServerLimits.cs index 57aaa031b9..ac8a047542 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServerLimits.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServerLimits.cs @@ -23,8 +23,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel // Matches the default LimitRequestFields in Apache httpd. private int _maxRequestHeaderCount = 100; - // Matches the default http.sys connection timeout. - private TimeSpan _connectionTimeout = TimeSpan.FromMinutes(2); + // Matches the default http.sys connectionTimeout. + private TimeSpan _keepAliveTimeout = TimeSpan.FromMinutes(2); + + private TimeSpan _requestHeadersTimeout = TimeSpan.FromSeconds(30); /// /// Gets or sets the maximum size of the response buffer before write @@ -152,11 +154,29 @@ namespace Microsoft.AspNetCore.Server.Kestrel { get { - return _connectionTimeout; + return _keepAliveTimeout; } set { - _connectionTimeout = value; + _keepAliveTimeout = value; + } + } + + /// + /// Gets or sets the maximum amount of time the server will spend receiving request headers. + /// + /// + /// Defaults to 30 seconds. + /// + public TimeSpan RequestHeadersTimeout + { + get + { + return _requestHeadersTimeout; + } + set + { + _requestHeadersTimeout = value; } } } diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/KeepAliveTimeoutTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/KeepAliveTimeoutTests.cs index f5c202a4dd..ce2bcc631c 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/KeepAliveTimeoutTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/KeepAliveTimeoutTests.cs @@ -2,7 +2,6 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.IO; using System.Text; using System.Threading; using System.Threading.Tasks; @@ -50,17 +49,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests "", ""); await ReceiveResponse(connection, server.Context); - - await Task.Delay(LongDelay); - - await Assert.ThrowsAsync(async () => - { - await connection.Send( - "GET / HTTP/1.1", - "", - ""); - await ReceiveResponse(connection, server.Context); - }); + await connection.WaitForConnectionClose().TimeoutAfter(LongDelay); } } @@ -143,13 +132,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests using (var connection = new TestConnection(server.Port)) { await Task.Delay(LongDelay); - await Assert.ThrowsAsync(async () => - { - await connection.Send( - "GET / HTTP/1.1", - "", - ""); - }); + await connection.WaitForConnectionClose().TimeoutAfter(LongDelay); } } diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestHeadersTimeoutTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestHeadersTimeoutTests.cs new file mode 100644 index 0000000000..b80a637058 --- /dev/null +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestHeadersTimeoutTests.cs @@ -0,0 +1,135 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.IO; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Testing; +using Xunit; + +namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests +{ + public class RequestHeadersTimeoutTests + { + private static readonly TimeSpan RequestHeadersTimeout = TimeSpan.FromSeconds(10); + private static readonly TimeSpan LongDelay = TimeSpan.FromSeconds(30); + private static readonly TimeSpan ShortDelay = TimeSpan.FromSeconds(LongDelay.TotalSeconds / 10); + + [Fact] + public async Task TestRequestHeadersTimeout() + { + using (var server = CreateServer()) + { + var tasks = new[] + { + ConnectionAbortedWhenRequestHeadersNotReceivedInTime(server, ""), + ConnectionAbortedWhenRequestHeadersNotReceivedInTime(server, "Content-Length: 1\r\n"), + ConnectionAbortedWhenRequestHeadersNotReceivedInTime(server, "Content-Length: 1\r\n\r"), + RequestHeadersTimeoutCanceledAfterHeadersReceived(server), + ConnectionAbortedWhenRequestLineNotReceivedInTime(server, "P"), + ConnectionAbortedWhenRequestLineNotReceivedInTime(server, "POST / HTTP/1.1\r"), + TimeoutNotResetOnEachRequestLineCharacterReceived(server) + }; + + await Task.WhenAll(tasks); + } + } + + private async Task ConnectionAbortedWhenRequestHeadersNotReceivedInTime(TestServer server, string headers) + { + using (var connection = server.CreateConnection()) + { + await connection.Send( + "GET / HTTP/1.1", + headers); + await ReceiveTimeoutResponse(connection, server.Context); + } + } + + private async Task RequestHeadersTimeoutCanceledAfterHeadersReceived(TestServer server) + { + using (var connection = server.CreateConnection()) + { + await connection.Send( + "POST / HTTP/1.1", + "Content-Length: 1", + "", + ""); + await Task.Delay(RequestHeadersTimeout); + await connection.Send( + "a"); + await ReceiveResponse(connection, server.Context); + } + } + + private async Task ConnectionAbortedWhenRequestLineNotReceivedInTime(TestServer server, string requestLine) + { + using (var connection = server.CreateConnection()) + { + await connection.Send(requestLine); + await ReceiveTimeoutResponse(connection, server.Context); + } + } + + private async Task TimeoutNotResetOnEachRequestLineCharacterReceived(TestServer server) + { + using (var connection = server.CreateConnection()) + { + await Assert.ThrowsAsync(async () => + { + foreach (var ch in "POST / HTTP/1.1\r\n\r\n") + { + await connection.Send(ch.ToString()); + await Task.Delay(ShortDelay); + } + }); + } + } + + private TestServer CreateServer() + { + return new TestServer(async httpContext => + { + await httpContext.Request.Body.ReadAsync(new byte[1], 0, 1); + await httpContext.Response.WriteAsync("hello, world"); + }, + new TestServiceContext + { + ServerOptions = new KestrelServerOptions + { + AddServerHeader = false, + Limits = + { + RequestHeadersTimeout = RequestHeadersTimeout + } + } + }); + } + + private async Task ReceiveResponse(TestConnection connection, TestServiceContext testServiceContext) + { + await connection.Receive( + "HTTP/1.1 200 OK", + $"Date: {testServiceContext.DateHeaderValue}", + "Transfer-Encoding: chunked", + "", + "c", + "hello, world", + "0", + "", + ""); + } + + private async Task ReceiveTimeoutResponse(TestConnection connection, TestServiceContext testServiceContext) + { + await connection.ReceiveForcedEnd( + "HTTP/1.1 408 Request Timeout", + "Connection: close", + $"Date: {testServiceContext.DateHeaderValue}", + "Content-Length: 0", + "", + ""); + } + } +} \ No newline at end of file diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs index 736807ac62..4bdf8940f1 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs @@ -9,6 +9,7 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Testing; using Microsoft.Extensions.Internal; using Microsoft.Extensions.Primitives; using Xunit; @@ -178,6 +179,40 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } } + // https://github.com/aspnet/KestrelHttpServer/pull/1111/files#r80584475 explains the reason for this test. + [Fact] + public async Task SingleErrorResponseSentWhenAppSwallowsBadRequestException() + { + using (var server = new TestServer(async httpContext => + { + try + { + await httpContext.Request.Body.ReadAsync(new byte[1], 0, 1); + } + catch (BadHttpRequestException) + { + } + }, new TestServiceContext())) + { + using (var connection = server.CreateConnection()) + { + await connection.Send( + "POST / HTTP/1.1", + "Transfer-Encoding: chunked", + "", + "g", + ""); + await connection.ReceiveForcedEnd( + "HTTP/1.1 400 Bad Request", + "Connection: close", + $"Date: {server.Context.DateHeaderValue}", + "Content-Length: 0", + "", + ""); + } + } + } + public static TheoryData NullHeaderData { get diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs index 4854a2d369..c59e74160b 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs @@ -36,7 +36,10 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { ServerAddress = ServerAddress.FromUrl("http://localhost:5000") }; - var connectionContext = new ConnectionContext(listenerContext); + var connectionContext = new ConnectionContext(listenerContext) + { + ConnectionControl = Mock.Of() + }; var frame = new Frame(application: null, context: connectionContext); frame.Reset(); @@ -84,7 +87,10 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { ServerAddress = ServerAddress.FromUrl("http://localhost:5000") }; - var connectionContext = new ConnectionContext(listenerContext); + var connectionContext = new ConnectionContext(listenerContext) + { + ConnectionControl = Mock.Of() + }; var frame = new Frame(application: null, context: connectionContext); frame.Reset(); @@ -131,7 +137,10 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { ServerAddress = ServerAddress.FromUrl("http://localhost:5000") }; - var connectionContext = new ConnectionContext(listenerContext); + var connectionContext = new ConnectionContext(listenerContext) + { + ConnectionControl = Mock.Of() + }; var frame = new Frame(application: null, context: connectionContext); frame.Reset(); @@ -178,7 +187,10 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { ServerAddress = ServerAddress.FromUrl("http://localhost:5000") }; - var connectionContext = new ConnectionContext(listenerContext); + var connectionContext = new ConnectionContext(listenerContext) + { + ConnectionControl = Mock.Of() + }; var frame = new Frame(application: null, context: connectionContext); frame.Reset(); @@ -564,7 +576,10 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { ServerAddress = ServerAddress.FromUrl("http://localhost:5000") }; - var connectionContext = new ConnectionContext(listenerContext); + var connectionContext = new ConnectionContext(listenerContext) + { + ConnectionControl = Mock.Of() + }; var frame = new Frame(application: null, context: connectionContext); frame.Reset(); @@ -633,7 +648,10 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { ServerAddress = ServerAddress.FromUrl("http://localhost:5000") }; - var connectionContext = new ConnectionContext(listenerContext); + var connectionContext = new ConnectionContext(listenerContext) + { + ConnectionControl = Mock.Of() + }; var frame = new Frame(application: null, context: connectionContext); frame.Reset(); @@ -931,7 +949,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } [Fact] - public void TakeStartLineDisablesKeepAliveTimeoutOnFirstByteAvailable() + public void TakeStartLineStartsRequestHeadersTimeoutOnFirstByteAvailable() { var trace = new KestrelTrace(new TestKestrelTrace()); var ltp = new LoggingThreadPool(trace); @@ -960,12 +978,13 @@ namespace Microsoft.AspNetCore.Server.KestrelTests socketInput.IncomingData(requestLineBytes, 0, requestLineBytes.Length); frame.TakeStartLine(socketInput); - connectionControl.Verify(cc => cc.CancelTimeout()); + var expectedRequestHeadersTimeout = (long)serviceContext.ServerOptions.Limits.RequestHeadersTimeout.TotalMilliseconds; + connectionControl.Verify(cc => cc.ResetTimeout(expectedRequestHeadersTimeout, TimeoutAction.SendTimeoutResponse)); } } [Fact] - public void TakeStartLineDoesNotDisableKeepAliveTimeoutIfNoDataAvailable() + public void TakeStartLineDoesNotStartRequestHeadersTimeoutIfNoDataAvailable() { var trace = new KestrelTrace(new TestKestrelTrace()); var ltp = new LoggingThreadPool(trace); @@ -991,7 +1010,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests frame.Reset(); frame.TakeStartLine(socketInput); - connectionControl.Verify(cc => cc.CancelTimeout(), Times.Never); + connectionControl.Verify(cc => cc.ResetTimeout(It.IsAny(), It.IsAny()), Times.Never); } } @@ -1132,7 +1151,10 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { ServerAddress = ServerAddress.FromUrl("http://localhost:5000") }; - var connectionContext = new ConnectionContext(listenerContext); + var connectionContext = new ConnectionContext(listenerContext) + { + ConnectionControl = Mock.Of() + }; var frame = new Frame(application: null, context: connectionContext); frame.Reset(); frame.InitializeHeaders(); @@ -1228,7 +1250,9 @@ namespace Microsoft.AspNetCore.Server.KestrelTests frame.Reset(); var requestProcessingTask = frame.RequestProcessingAsync(); - connectionControl.Verify(cc => cc.SetTimeout((long)serviceContext.ServerOptions.Limits.KeepAliveTimeout.TotalMilliseconds)); + + var expectedKeepAliveTimeout = (long)serviceContext.ServerOptions.Limits.KeepAliveTimeout.TotalMilliseconds; + connectionControl.Verify(cc => cc.SetTimeout(expectedKeepAliveTimeout, TimeoutAction.CloseConnection)); frame.Stop(); socketInput.IncomingFin(); diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerLimitsTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerLimitsTests.cs index 8481fc258d..0b9363b58f 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerLimitsTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerLimitsTests.cs @@ -167,5 +167,25 @@ namespace Microsoft.AspNetCore.Server.KestrelTests o.KeepAliveTimeout = TimeSpan.FromSeconds(seconds); Assert.Equal(seconds, o.KeepAliveTimeout.TotalSeconds); } + + [Fact] + public void RequestHeadersTimeoutDefault() + { + Assert.Equal(TimeSpan.FromSeconds(30), new KestrelServerLimits().RequestHeadersTimeout); + } + + [Theory] + [InlineData(0)] + [InlineData(0.5)] + [InlineData(1.0)] + [InlineData(2.5)] + [InlineData(10)] + [InlineData(60)] + public void RequestHeadersTimeoutValid(double seconds) + { + var o = new KestrelServerLimits(); + o.KeepAliveTimeout = TimeSpan.FromSeconds(seconds); + Assert.Equal(seconds, o.KeepAliveTimeout.TotalSeconds); + } } } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestInput.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/TestInput.cs index 47fb05c169..3de1e92e07 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/TestInput.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/TestInput.cs @@ -71,7 +71,11 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { } - public void SetTimeout(long milliseconds) + public void SetTimeout(long milliseconds, TimeoutAction timeoutAction) + { + } + + public void ResetTimeout(long milliseconds, TimeoutAction timeoutAction) { } diff --git a/test/shared/TestConnection.cs b/test/shared/TestConnection.cs index a382cac84d..cdb7e40ec5 100644 --- a/test/shared/TestConnection.cs +++ b/test/shared/TestConnection.cs @@ -139,6 +139,31 @@ namespace Microsoft.AspNetCore.Testing } } + public Task WaitForConnectionClose() + { + var tcs = new TaskCompletionSource(); + var eventArgs = new SocketAsyncEventArgs(); + eventArgs.SetBuffer(new byte[1], 0, 1); + eventArgs.Completed += ReceiveAsyncCompleted; + eventArgs.UserToken = tcs; + + if (!_socket.ReceiveAsync(eventArgs)) + { + ReceiveAsyncCompleted(this, eventArgs); + } + + return tcs.Task; + } + + private void ReceiveAsyncCompleted(object sender, SocketAsyncEventArgs e) + { + if (e.BytesTransferred == 0) + { + var tcs = (TaskCompletionSource)e.UserToken; + tcs.SetResult(null); + } + } + public static Socket CreateConnectedLoopbackSocket(int port) { var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); From 73656f6503688b6eb47ed7a5e93b3db76cbb2280 Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Tue, 27 Sep 2016 16:42:13 -0700 Subject: [PATCH 0895/1662] Assume zero length on non-keepalive requests without Content-Length or Transfer-Encoding (#1104). --- .../Internal/Http/MessageBody.cs | 12 +- .../MaxRequestBufferSizeTests.cs | 14 +-- .../ChunkedRequestTests.cs | 1 + .../ConnectionFilterTests.cs | 4 +- .../EngineTests.cs | 23 ++-- .../MessageBodyTests.cs | 104 +++++++++++++++++- 6 files changed, 129 insertions(+), 29 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/MessageBody.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/MessageBody.cs index 784f8d97de..bff4ba622f 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/MessageBody.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/MessageBody.cs @@ -234,6 +234,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var connection = headers.HeaderConnection.ToString(); if (connection.Length > 0) { + if (connection.Equals("upgrade", StringComparison.OrdinalIgnoreCase)) + { + return new ForRemainingData(context); + } + keepAlive = connection.Equals("keep-alive", StringComparison.OrdinalIgnoreCase); } @@ -257,12 +262,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } } - if (keepAlive) - { - return new ForContentLength(true, 0, context); - } - - return new ForRemainingData(context); + return new ForContentLength(keepAlive, 0, context); } private class ForRemainingData : MessageBody diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/MaxRequestBufferSizeTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/MaxRequestBufferSizeTests.cs index 463a11145c..d78f60a7cd 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/MaxRequestBufferSizeTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/MaxRequestBufferSizeTests.cs @@ -53,15 +53,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests // Disables all code related to computing and limiting the size of the input buffer. Tuple.Create((long?)null, false) }; - var sendContentLengthHeaderValues = new[] { true, false }; var sslValues = new[] { true, false }; return from maxRequestBufferSize in maxRequestBufferSizeValues - from sendContentLengthHeader in sendContentLengthHeaderValues from ssl in sslValues select new object[] { maxRequestBufferSize.Item1, - sendContentLengthHeader, ssl, maxRequestBufferSize.Item2 }; @@ -70,7 +67,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [Theory] [MemberData("LargeUploadData")] - public async Task LargeUpload(long? maxRequestBufferSize, bool sendContentLengthHeader, bool ssl, bool expectPause) + public async Task LargeUpload(long? maxRequestBufferSize, bool ssl, bool expectPause) { // Parameters var data = new byte[_dataLength]; @@ -91,7 +88,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests using (var socket = CreateSocket(port)) using (var stream = await CreateStreamAsync(socket, ssl, host.GetHost())) { - await WritePostRequestHeaders(stream, sendContentLengthHeader ? (int?)data.Length : null); + await WritePostRequestHeaders(stream, data.Length); var bytesWritten = 0; @@ -236,15 +233,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests return socket; } - private static async Task WritePostRequestHeaders(Stream stream, int? contentLength) + private static async Task WritePostRequestHeaders(Stream stream, int contentLength) { using (var writer = new StreamWriter(stream, Encoding.ASCII, bufferSize: 1024, leaveOpen: true)) { await writer.WriteAsync("POST / HTTP/1.0\r\n"); - if (contentLength.HasValue) - { - await writer.WriteAsync($"Content-Length: {contentLength.Value}\r\n"); - } + await writer.WriteAsync($"Content-Length: {contentLength}\r\n"); await writer.WriteAsync("\r\n"); } } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedRequestTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedRequestTests.cs index 9214b5b1f7..221922a050 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedRequestTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedRequestTests.cs @@ -102,6 +102,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests "0", "", "POST / HTTP/1.0", + "Content-Length: 7", "", "Goodbye"); await connection.Receive( diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionFilterTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionFilterTests.cs index d2a3b7cc22..3d1423dc2b 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionFilterTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionFilterTests.cs @@ -35,7 +35,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var filter = new RewritingConnectionFilter(); var serviceContext = new TestServiceContext(filter); - var sendString = "POST / HTTP/1.0\r\n\r\nHello World?"; + var sendString = "POST / HTTP/1.0\r\nContent-Length: 12\r\n\r\nHello World?"; using (var server = new TestServer(App, serviceContext)) { @@ -66,6 +66,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { await connection.SendEnd( "POST / HTTP/1.0", + "Content-Length: 12", "", "Hello World?"); await connection.ReceiveEnd( @@ -91,6 +92,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { await connection.SendEnd( "POST / HTTP/1.0", + "Content-Length: 12", "", "Hello World?"); } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs index 2fdb63a220..21ecb56a19 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs @@ -14,7 +14,6 @@ using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Server.Kestrel; using Microsoft.AspNetCore.Server.Kestrel.Internal; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.AspNetCore.Testing; using Microsoft.Extensions.Internal; using Xunit; @@ -108,7 +107,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var started = engine.CreateServer(address); var socket = TestConnection.CreateConnectedLoopbackSocket(address.Port); - socket.Send(Encoding.ASCII.GetBytes("POST / HTTP/1.0\r\n\r\nHello World")); + socket.Send(Encoding.ASCII.GetBytes("POST / HTTP/1.0\r\nContent-Length: 11\r\n\r\nHello World")); socket.Shutdown(SocketShutdown.Send); var buffer = new byte[8192]; while (true) @@ -131,6 +130,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { await connection.SendEnd( "POST / HTTP/1.0", + "Content-Length: 11", "", "Hello World"); await connection.ReceiveEnd( @@ -156,6 +156,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests "", "GET / HTTP/1.1", "Connection: close", + "Content-Length: 7", "", "Goodbye"); await connection.ReceiveEnd( @@ -219,7 +220,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { var requestData = Enumerable.Repeat("GET / HTTP/1.1\r\n", loopCount) - .Concat(new[] { "GET / HTTP/1.1\r\nConnection: close\r\n\r\nGoodbye" }); + .Concat(new[] { "GET / HTTP/1.1\r\nContent-Length: 7\r\nConnection: close\r\n\r\nGoodbye" }); var response = string.Join("\r\n", new string[] { "HTTP/1.1 200 OK", @@ -288,6 +289,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests "Connection: keep-alive", "", "POST / HTTP/1.0", + "Content-Length: 7", "", "Goodbye"); await connection.Receive( @@ -320,8 +322,8 @@ namespace Microsoft.AspNetCore.Server.KestrelTests "Connection: keep-alive", "", "POST / HTTP/1.0", - "Content-Length: 7", "Connection: keep-alive", + "Content-Length: 7", "", "Goodbye"); await connection.Receive( @@ -354,6 +356,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests "Connection: keep-alive", "", "Hello WorldPOST / HTTP/1.0", + "Content-Length: 7", "", "Goodbye"); await connection.Receive( @@ -461,11 +464,17 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [MemberData(nameof(ConnectionFilterData))] public async Task ZeroContentLengthSetAutomaticallyForNonKeepAliveRequests(TestServiceContext testContext) { - using (var server = new TestServer(EmptyApp, testContext)) + using (var server = new TestServer(async httpContext => + { + Assert.Equal(0, await httpContext.Request.Body.ReadAsync(new byte[1], 0, 1).TimeoutAfter(TimeSpan.FromSeconds(10))); + }, testContext)) { using (var connection = server.CreateConnection()) { - await connection.SendEnd( + // Use Send instead of SendEnd to ensure the connection will remain open while + // the app runs and reads 0 bytes from the body nonetheless. This checks that + // https://github.com/aspnet/KestrelHttpServer/issues/1104 is not regressing. + await connection.Send( "GET / HTTP/1.1", "Connection: close", "", @@ -481,7 +490,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests using (var connection = server.CreateConnection()) { - await connection.SendEnd( + await connection.Send( "GET / HTTP/1.0", "", ""); diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/MessageBodyTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/MessageBodyTests.cs index 9dd54a75d0..1790cf8094 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/MessageBodyTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/MessageBodyTests.cs @@ -27,7 +27,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { using (var input = new TestInput()) { - var body = MessageBody.For(HttpVersion.Http10, new FrameRequestHeaders(), input.FrameContext); + var body = MessageBody.For(HttpVersion.Http10, new FrameRequestHeaders { HeaderContentLength = "5" }, input.FrameContext); var stream = new FrameRequestStream(); stream.StartAcceptingReads(body); @@ -48,7 +48,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { using (var input = new TestInput()) { - var body = MessageBody.For(HttpVersion.Http10, new FrameRequestHeaders(), input.FrameContext); + var body = MessageBody.For(HttpVersion.Http10, new FrameRequestHeaders { HeaderContentLength = "5" }, input.FrameContext); var stream = new FrameRequestStream(); stream.StartAcceptingReads(body); @@ -65,7 +65,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } [Fact] - public async Task CanHandleLargeBlocks() + public void Http10NoContentLength() { using (var input = new TestInput()) { @@ -73,6 +73,102 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var stream = new FrameRequestStream(); stream.StartAcceptingReads(body); + input.Add("Hello", true); + + var buffer1 = new byte[1024]; + Assert.Equal(0, stream.Read(buffer1, 0, 1024)); + } + } + + [Fact] + public async Task Http10NoContentLengthAsync() + { + using (var input = new TestInput()) + { + var body = MessageBody.For(HttpVersion.Http10, new FrameRequestHeaders(), input.FrameContext); + var stream = new FrameRequestStream(); + stream.StartAcceptingReads(body); + + input.Add("Hello", true); + + var buffer1 = new byte[1024]; + Assert.Equal(0, await stream.ReadAsync(buffer1, 0, 1024)); + } + } + + [Fact] + public void Http11NoContentLength() + { + using (var input = new TestInput()) + { + var body = MessageBody.For(HttpVersion.Http11, new FrameRequestHeaders(), input.FrameContext); + var stream = new FrameRequestStream(); + stream.StartAcceptingReads(body); + + input.Add("Hello", true); + + var buffer1 = new byte[1024]; + Assert.Equal(0, stream.Read(buffer1, 0, 1024)); + } + } + + [Fact] + public async Task Http11NoContentLengthAsync() + { + using (var input = new TestInput()) + { + var body = MessageBody.For(HttpVersion.Http11, new FrameRequestHeaders(), input.FrameContext); + var stream = new FrameRequestStream(); + stream.StartAcceptingReads(body); + + input.Add("Hello", true); + + var buffer1 = new byte[1024]; + Assert.Equal(0, await stream.ReadAsync(buffer1, 0, 1024)); + } + } + + [Fact] + public void Http11NoContentLengthConnectionClose() + { + using (var input = new TestInput()) + { + var body = MessageBody.For(HttpVersion.Http11, new FrameRequestHeaders { HeaderConnection = "close" }, input.FrameContext); + var stream = new FrameRequestStream(); + stream.StartAcceptingReads(body); + + input.Add("Hello", true); + + var buffer1 = new byte[1024]; + Assert.Equal(0, stream.Read(buffer1, 0, 1024)); + } + } + + [Fact] + public async Task Http11NoContentLengthConnectionCloseAsync() + { + using (var input = new TestInput()) + { + var body = MessageBody.For(HttpVersion.Http11, new FrameRequestHeaders { HeaderConnection = "close" }, input.FrameContext); + var stream = new FrameRequestStream(); + stream.StartAcceptingReads(body); + + input.Add("Hello", true); + + var buffer1 = new byte[1024]; + Assert.Equal(0, await stream.ReadAsync(buffer1, 0, 1024)); + } + } + + [Fact] + public async Task CanHandleLargeBlocks() + { + using (var input = new TestInput()) + { + var body = MessageBody.For(HttpVersion.Http10, new FrameRequestHeaders { HeaderContentLength = "8197" }, input.FrameContext); + var stream = new FrameRequestStream(); + stream.StartAcceptingReads(body); + // Input needs to be greater than 4032 bytes to allocate a block not backed by a slab. var largeInput = new string('a', 8192); @@ -101,8 +197,6 @@ namespace Microsoft.AspNetCore.Server.KestrelTests public static IEnumerable RequestData => new[] { - // Remaining Data - new object[] { new FrameRequestHeaders { HeaderConnection = "close" }, new[] { "Hello ", "World!" } }, // Content-Length new object[] { new FrameRequestHeaders { HeaderContentLength = "12" }, new[] { "Hello ", "World!" } }, // Chunked From 09fda749b07e1ea5f9b9922483a0ed6553867346 Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Wed, 28 Sep 2016 10:38:15 -0700 Subject: [PATCH 0896/1662] Don't reset frame state when connection is aborted (#1103). --- .../Internal/Http/FrameOfT.cs | 7 +- .../HttpsTests.cs | 67 ++++++++++++++++++- 2 files changed, 71 insertions(+), 3 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameOfT.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameOfT.cs index fd8306baf7..203e97152c 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameOfT.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameOfT.cs @@ -141,8 +141,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } } - // Don't lose request rejection state - if (!_requestRejected) + // Don't reset frame state if we're exiting the loop. This avoids losing request rejection + // information (for 4xx response), and prevents ObjectDisposedException on HTTPS (ODEs + // will be thrown if PrepareRequest is not null and references objects disposed on connection + // close - see https://github.com/aspnet/KestrelHttpServer/issues/1103#issuecomment-250237677). + if (!_requestProcessingStopping) { Reset(); } diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/HttpsTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/HttpsTests.cs index 1fd4889a4e..716c71e7b0 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/HttpsTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/HttpsTests.cs @@ -2,12 +2,19 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Net.Security; using System.Net.Sockets; +using System.Security.Authentication; +using System.Security.Cryptography.X509Certificates; +using System.Text; using System.Threading.Tasks; +using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Server.Kestrel.Https; using Microsoft.AspNetCore.Testing; using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Logging.Abstractions.Internal; using Xunit; namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests @@ -78,6 +85,57 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests Assert.Equal(0, loggerFactory.ErrorLogger.TotalErrorsLogged); } + // Regression test for https://github.com/aspnet/KestrelHttpServer/issues/1103#issuecomment-246971172 + [Fact] + public async Task DoesNotThrowObjectDisposedExceptionOnConnectionAbort() + { + var x509Certificate2 = new X509Certificate2(@"TestResources/testCert.pfx", "testPassword"); + var loggerFactory = new HandshakeErrorLoggerFactory(); + var hostBuilder = new WebHostBuilder() + .UseKestrel(options => + { + options.UseHttps(@"TestResources/testCert.pfx", "testPassword"); + }) + .UseUrls("https://127.0.0.1:0/") + .UseLoggerFactory(loggerFactory) + .Configure(app => app.Run(async httpContext => + { + var ct = httpContext.RequestAborted; + while (!ct.IsCancellationRequested) + { + try + { + await httpContext.Response.WriteAsync($"hello, world\r\r", ct); + await Task.Delay(1000, ct); + } + catch (TaskCanceledException) + { + // Don't regard connection abort as an error + } + } + })); + + using (var host = hostBuilder.Build()) + { + host.Start(); + + using (var socket = await HttpClientSlim.GetSocket(new Uri($"https://127.0.0.1:{host.GetPort()}/"))) + using (var stream = new NetworkStream(socket, ownsSocket: false)) + using (var sslStream = new SslStream(stream, true, (sender, certificate, chain, errors) => true)) + { + await sslStream.AuthenticateAsClientAsync("127.0.0.1", clientCertificates: null, + enabledSslProtocols: SslProtocols.Tls11 | SslProtocols.Tls12, + checkCertificateRevocation: false); + + var request = Encoding.ASCII.GetBytes("GET / HTTP/1.1\r\n\r\n"); + await sslStream.WriteAsync(request, 0, request.Length); + await sslStream.ReadAsync(new byte[32], 0, 32); + } + } + + Assert.False(loggerFactory.ErrorLogger.ObjectDisposedExceptionLogged); + } + private class HandshakeErrorLoggerFactory : ILoggerFactory { public HttpsConnectionFilterLogger FilterLogger { get; } = new HttpsConnectionFilterLogger(); @@ -133,12 +191,19 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { public int TotalErrorsLogged { get; set; } + public bool ObjectDisposedExceptionLogged { get; set; } + public void Log(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func formatter) { if (logLevel == LogLevel.Error) { TotalErrorsLogged++; } + + if (exception is ObjectDisposedException) + { + ObjectDisposedExceptionLogged = true; + } } public bool IsEnabled(LogLevel logLevel) @@ -148,7 +213,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests public IDisposable BeginScope(TState state) { - throw new NotImplementedException(); + return NullScope.Instance; } } } From 310411075f74a5c26ea197252765b96d9189e0dc Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Sun, 4 Sep 2016 09:05:27 +0100 Subject: [PATCH 0897/1662] Slimmer locks --- .../Internal/Http/Frame.cs | 2 +- .../Internal/Http/SocketInput.cs | 71 +++++++++++-------- 2 files changed, 42 insertions(+), 31 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs index 767130fd03..7b0c22dbd9 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs @@ -383,7 +383,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http /// public void Abort(Exception error = null) { - if (Interlocked.CompareExchange(ref _requestAborted, 1, 0) == 0) + if (Interlocked.Exchange(ref _requestAborted, 1) == 0) { _requestProcessingStopping = true; diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/SocketInput.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/SocketInput.cs index e73b72b77e..a89fff7bff 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/SocketInput.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/SocketInput.cs @@ -72,6 +72,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http public void IncomingComplete(int count, Exception error) { + Action awaitableState; + lock (_sync) { // Must call Add() before bytes are available to consumer, to ensure that Length is >= 0 @@ -107,8 +109,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http FinReceived(); } - Complete(); + awaitableState = Interlocked.Exchange(ref _awaitableState, _awaitableIsCompleted); } + + Complete(awaitableState); } public void IncomingDeferred() @@ -129,12 +133,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } } - private void Complete() + private void Complete(Action awaitableState) { - var awaitableState = Interlocked.Exchange( - ref _awaitableState, - _awaitableIsCompleted); - _manualResetEvent.Set(); if (!ReferenceEquals(awaitableState, _awaitableIsCompleted) && @@ -146,21 +146,29 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http public MemoryPoolIterator ConsumingStart() { + MemoryPoolBlock head; + bool isAlreadyConsuming; + lock (_sync) { - if (_consuming) - { - throw new InvalidOperationException("Already consuming input."); - } + isAlreadyConsuming = _consuming; + head = _head; _consuming = true; - return new MemoryPoolIterator(_head); } + + if (isAlreadyConsuming) + { + throw new InvalidOperationException("Already consuming input."); + } + + return new MemoryPoolIterator(head); } public void ConsumingComplete( MemoryPoolIterator consumed, MemoryPoolIterator examined) { + bool isConsuming; MemoryPoolBlock returnStart = null; MemoryPoolBlock returnEnd = null; @@ -184,7 +192,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { // Everything has been consumed and no data is being written to the // _tail block, so return all blocks between _head and _tail inclusive. - returnEnd = null; _head = null; _tail = null; } @@ -214,31 +221,34 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } else { + // Dispose won't have returned the blocks if we were consuming, so return them now returnStart = _head; - returnEnd = null; _head = null; _tail = null; } - ReturnBlocks(returnStart, returnEnd); - - if (!_consuming) - { - throw new InvalidOperationException("No ongoing consuming operation to complete."); - } + isConsuming = _consuming; _consuming = false; } + + ReturnBlocks(returnStart, returnEnd); + + if (!isConsuming) + { + throw new InvalidOperationException("No ongoing consuming operation to complete."); + } } public void CompleteAwaiting() { - Complete(); + Complete(Interlocked.Exchange(ref _awaitableState, _awaitableIsCompleted)); } public void AbortAwaiting() { SetConnectionError(new TaskCanceledException("The request was aborted")); - Complete(); + + CompleteAwaiting(); } public SocketInput GetAwaiter() @@ -253,15 +263,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http continuation, _awaitableIsNotCompleted); - if (ReferenceEquals(awaitableState, _awaitableIsNotCompleted)) - { - return; - } - else if (ReferenceEquals(awaitableState, _awaitableIsCompleted)) + if (ReferenceEquals(awaitableState, _awaitableIsCompleted)) { _threadPool.Run(continuation); } - else + else if (!ReferenceEquals(awaitableState, _awaitableIsNotCompleted)) { SetConnectionError(new InvalidOperationException("Concurrent reads are not supported.")); @@ -293,18 +299,23 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http public void Dispose() { + AbortAwaiting(); + + MemoryPoolBlock block = null; + lock (_sync) { - AbortAwaiting(); - if (!_consuming) { - ReturnBlocks(_head, null); + block = _head; _head = null; _tail = null; } + _disposed = true; } + + ReturnBlocks(block, null); } private static void ReturnBlocks(MemoryPoolBlock block, MemoryPoolBlock end) From 12adc7de9dfe6e325626dc930429749bd6964527 Mon Sep 17 00:00:00 2001 From: Mikael Mengistu Date: Thu, 29 Sep 2016 12:19:26 -0700 Subject: [PATCH 0898/1662] Refactored to use the fields from the HttpMethods class * Reacting to PR comments --- .../MemoryPoolIteratorExtensions.cs | 29 +++++++------------ .../MemoryPoolIteratorTests.cs | 18 ++++++------ 2 files changed, 19 insertions(+), 28 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolIteratorExtensions.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolIteratorExtensions.cs index 6cc8f38bce..59978837fd 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolIteratorExtensions.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolIteratorExtensions.cs @@ -4,6 +4,7 @@ using System; using System.Diagnostics; using System.Text; +using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure @@ -12,16 +13,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure { private static readonly Encoding _utf8 = Encoding.UTF8; - public const string HttpConnectMethod = "CONNECT"; - public const string HttpDeleteMethod = "DELETE"; - public const string HttpGetMethod = "GET"; - public const string HttpHeadMethod = "HEAD"; - public const string HttpPatchMethod = "PATCH"; - public const string HttpPostMethod = "POST"; - public const string HttpPutMethod = "PUT"; - public const string HttpOptionsMethod = "OPTIONS"; - public const string HttpTraceMethod = "TRACE"; - public const string Http10Version = "HTTP/1.0"; public const string Http11Version = "HTTP/1.1"; @@ -49,14 +40,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure static MemoryPoolIteratorExtensions() { - _knownMethods[0] = Tuple.Create(_mask4Chars, _httpPutMethodLong, HttpPutMethod); - _knownMethods[1] = Tuple.Create(_mask5Chars, _httpPostMethodLong, HttpPostMethod); - _knownMethods[2] = Tuple.Create(_mask5Chars, _httpHeadMethodLong, HttpHeadMethod); - _knownMethods[3] = Tuple.Create(_mask6Chars, _httpTraceMethodLong, HttpTraceMethod); - _knownMethods[4] = Tuple.Create(_mask6Chars, _httpPatchMethodLong, HttpPatchMethod); - _knownMethods[5] = Tuple.Create(_mask7Chars, _httpDeleteMethodLong, HttpDeleteMethod); - _knownMethods[6] = Tuple.Create(_mask8Chars, _httpConnectMethodLong, HttpConnectMethod); - _knownMethods[7] = Tuple.Create(_mask8Chars, _httpOptionsMethodLong, HttpOptionsMethod); + _knownMethods[0] = Tuple.Create(_mask4Chars, _httpPutMethodLong, HttpMethods.Put); + _knownMethods[1] = Tuple.Create(_mask5Chars, _httpPostMethodLong, HttpMethods.Post); + _knownMethods[2] = Tuple.Create(_mask5Chars, _httpHeadMethodLong, HttpMethods.Head); + _knownMethods[3] = Tuple.Create(_mask6Chars, _httpTraceMethodLong, HttpMethods.Trace); + _knownMethods[4] = Tuple.Create(_mask6Chars, _httpPatchMethodLong, HttpMethods.Patch); + _knownMethods[5] = Tuple.Create(_mask7Chars, _httpDeleteMethodLong, HttpMethods.Delete); + _knownMethods[6] = Tuple.Create(_mask8Chars, _httpConnectMethodLong, HttpMethods.Connect); + _knownMethods[7] = Tuple.Create(_mask8Chars, _httpOptionsMethodLong, HttpMethods.Options); } private unsafe static long GetAsciiStringAsLong(string str) @@ -279,7 +270,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure if ((value & _mask4Chars) == _httpGetMethodLong) { - knownMethod = HttpGetMethod; + knownMethod = HttpMethods.Get; return true; } foreach (var x in _knownMethods) diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolIteratorTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolIteratorTests.cs index 5424514870..dd4edd4529 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolIteratorTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolIteratorTests.cs @@ -432,15 +432,15 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } [Theory] - [InlineData("CONNECT / HTTP/1.1", ' ', true, MemoryPoolIteratorExtensions.HttpConnectMethod)] - [InlineData("DELETE / HTTP/1.1", ' ', true, MemoryPoolIteratorExtensions.HttpDeleteMethod)] - [InlineData("GET / HTTP/1.1", ' ', true, MemoryPoolIteratorExtensions.HttpGetMethod)] - [InlineData("HEAD / HTTP/1.1", ' ', true, MemoryPoolIteratorExtensions.HttpHeadMethod)] - [InlineData("PATCH / HTTP/1.1", ' ', true, MemoryPoolIteratorExtensions.HttpPatchMethod)] - [InlineData("POST / HTTP/1.1", ' ', true, MemoryPoolIteratorExtensions.HttpPostMethod)] - [InlineData("PUT / HTTP/1.1", ' ', true, MemoryPoolIteratorExtensions.HttpPutMethod)] - [InlineData("OPTIONS / HTTP/1.1", ' ', true, MemoryPoolIteratorExtensions.HttpOptionsMethod)] - [InlineData("TRACE / HTTP/1.1", ' ', true, MemoryPoolIteratorExtensions.HttpTraceMethod)] + [InlineData("CONNECT / HTTP/1.1", ' ', true, "CONNECT")] + [InlineData("DELETE / HTTP/1.1", ' ', true, "DELETE")] + [InlineData("GET / HTTP/1.1", ' ', true, "GET")] + [InlineData("HEAD / HTTP/1.1", ' ', true, "HEAD")] + [InlineData("PATCH / HTTP/1.1", ' ', true, "PATCH")] + [InlineData("POST / HTTP/1.1", ' ', true, "POST")] + [InlineData("PUT / HTTP/1.1", ' ', true, "PUT")] + [InlineData("OPTIONS / HTTP/1.1", ' ', true, "OPTIONS")] + [InlineData("TRACE / HTTP/1.1", ' ', true, "TRACE")] [InlineData("GET/ HTTP/1.1", ' ', false, null)] [InlineData("get / HTTP/1.1", ' ', false, null)] [InlineData("GOT / HTTP/1.1", ' ', false, null)] From e8fa40235b06427e51e6a4db09b2d35778c3235f Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Mon, 3 Oct 2016 14:21:45 -0700 Subject: [PATCH 0899/1662] Remove unused variable in MemoryPoolIterator.Seek() (#1137). --- .../Internal/Infrastructure/MemoryPoolIterator.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolIterator.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolIterator.cs index ccc54cf52a..b0b6837f65 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolIterator.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolIterator.cs @@ -395,7 +395,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure _block = block; var firstEqualByteIndex = FindFirstEqualByte(ref byte0Equals); - var vectorBytesScanned = firstEqualByteIndex + 1; if (_block == limit.Block && index + firstEqualByteIndex > limit.Index) { From e7e6b896ba5e5c201b61f70fa4ea352027bd6bd8 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Sat, 9 Jul 2016 08:48:36 +0100 Subject: [PATCH 0900/1662] Don't emit TE header or body for non-body responses --- .../BadHttpResponse.cs | 75 ++++++ .../Internal/Http/Frame.cs | 199 +++++++++++----- .../Internal/Http/FrameHeaders.cs | 13 +- .../Internal/Http/ResponseRejectionReasons.cs | 22 ++ .../Internal/Infrastructure/IKestrelTrace.cs | 2 + .../Internal/Infrastructure/KestrelTrace.cs | 7 + .../FrameTests.cs | 224 ++++++++++++++++++ .../TestFrameProtectedMembers.cs | 23 ++ 8 files changed, 493 insertions(+), 72 deletions(-) create mode 100644 src/Microsoft.AspNetCore.Server.Kestrel/BadHttpResponse.cs create mode 100644 src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ResponseRejectionReasons.cs create mode 100644 test/Microsoft.AspNetCore.Server.KestrelTests/TestFrameProtectedMembers.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/BadHttpResponse.cs b/src/Microsoft.AspNetCore.Server.Kestrel/BadHttpResponse.cs new file mode 100644 index 0000000000..2e953b46ca --- /dev/null +++ b/src/Microsoft.AspNetCore.Server.Kestrel/BadHttpResponse.cs @@ -0,0 +1,75 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Runtime.CompilerServices; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; + +namespace Microsoft.AspNetCore.Server.Kestrel +{ + public static class BadHttpResponse + { + internal static void ThrowException(ResponseRejectionReasons reason) + { + throw GetException(reason); + } + + internal static void ThrowException(ResponseRejectionReasons reason, int value) + { + throw GetException(reason, value.ToString()); + } + + internal static void ThrowException(ResponseRejectionReasons reason, ResponseRejectionParameter parameter) + { + throw GetException(reason, parameter.ToString()); + } + + internal static InvalidOperationException GetException(ResponseRejectionReasons reason, int value) + { + return GetException(reason, value.ToString()); + } + + [MethodImpl(MethodImplOptions.NoInlining)] + internal static InvalidOperationException GetException(ResponseRejectionReasons reason) + { + InvalidOperationException ex; + switch (reason) + { + case ResponseRejectionReasons.HeadersReadonlyResponseStarted: + ex = new InvalidOperationException("Headers are read-only, response has already started."); + break; + case ResponseRejectionReasons.OnStartingCannotBeSetResponseStarted: + ex = new InvalidOperationException("OnStarting cannot be set, response has already started."); + break; + default: + ex = new InvalidOperationException("Bad response."); + break; + } + + return ex; + } + + [MethodImpl(MethodImplOptions.NoInlining)] + private static InvalidOperationException GetException(ResponseRejectionReasons reason, string value) + { + InvalidOperationException ex; + switch (reason) + { + case ResponseRejectionReasons.ValueCannotBeSetResponseStarted: + ex = new InvalidOperationException(value + " cannot be set, response had already started."); + break; + case ResponseRejectionReasons.TransferEncodingSetOnNonBodyResponse: + ex = new InvalidOperationException($"Transfer-Encoding set on a {value} non-body request."); + break; + case ResponseRejectionReasons.WriteToNonBodyResponse: + ex = new InvalidOperationException($"Write to non-body {value} response."); + break; + default: + ex = new InvalidOperationException("Bad response."); + break; + } + + return ex; + } + } +} diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs index 7b0c22dbd9..0ab83b51ea 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs @@ -60,6 +60,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http private RequestProcessingStatus _requestProcessingStatus; protected bool _keepAlive; + private bool _canHaveBody; private bool _autoChunk; protected Exception _applicationException; @@ -171,7 +172,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { if (HasResponseStarted) { - ThrowResponseAlreadyStartedException(nameof(StatusCode)); + BadHttpResponse.ThrowException(ResponseRejectionReasons.ValueCannotBeSetResponseStarted, ResponseRejectionParameter.StatusCode); } _statusCode = value; @@ -189,7 +190,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { if (HasResponseStarted) { - ThrowResponseAlreadyStartedException(nameof(ReasonPhrase)); + BadHttpResponse.ThrowException(ResponseRejectionReasons.ValueCannotBeSetResponseStarted, ResponseRejectionParameter.ReasonPhrase); } _reasonPhrase = value; @@ -425,7 +426,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { if (HasResponseStarted) { - ThrowResponseAlreadyStartedException(nameof(OnStarting)); + BadHttpResponse.ThrowException(ResponseRejectionReasons.OnStartingCannotBeSetResponseStarted, ResponseRejectionParameter.OnStarting); } if (_onStarting == null) @@ -512,17 +513,24 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { ProduceStartAndFireOnStarting().GetAwaiter().GetResult(); - if (_autoChunk) + if (_canHaveBody) { - if (data.Count == 0) + if (_autoChunk) { - return; + if (data.Count == 0) + { + return; + } + WriteChunked(data); + } + else + { + SocketOutput.Write(data); } - WriteChunked(data); } else { - SocketOutput.Write(data); + HandleNonBodyResponseWrite(data.Count); } } @@ -533,17 +541,25 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http return WriteAsyncAwaited(data, cancellationToken); } - if (_autoChunk) + if (_canHaveBody) { - if (data.Count == 0) + if (_autoChunk) { - return TaskCache.CompletedTask; + if (data.Count == 0) + { + return TaskCache.CompletedTask; + } + return WriteChunkedAsync(data, cancellationToken); + } + else + { + return SocketOutput.WriteAsync(data, cancellationToken: cancellationToken); } - return WriteChunkedAsync(data, cancellationToken); } else { - return SocketOutput.WriteAsync(data, cancellationToken: cancellationToken); + HandleNonBodyResponseWrite(data.Count); + return TaskCache.CompletedTask; } } @@ -551,18 +567,27 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { await ProduceStartAndFireOnStarting(); - if (_autoChunk) + if (_canHaveBody) { - if (data.Count == 0) + if (_autoChunk) { - return; + if (data.Count == 0) + { + return; + } + await WriteChunkedAsync(data, cancellationToken); + } + else + { + await SocketOutput.WriteAsync(data, cancellationToken: cancellationToken); } - await WriteChunkedAsync(data, cancellationToken); } else { - await SocketOutput.WriteAsync(data, cancellationToken: cancellationToken); + HandleNonBodyResponseWrite(data.Count); + return; } + } private void WriteChunked(ArraySegment data) @@ -679,21 +704,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if (!_requestRejected) { // 500 Internal Server Error - StatusCode = 500; - } - - ReasonPhrase = null; - - var responseHeaders = FrameResponseHeaders; - responseHeaders.Reset(); - var dateHeaderValues = DateHeaderValueManager.GetDateHeaderValues(); - - responseHeaders.SetRawDate(dateHeaderValues.String, dateHeaderValues.Bytes); - responseHeaders.SetRawContentLength("0", _bytesContentLengthZero); - - if (ServerOptions.AddServerHeader) - { - responseHeaders.SetRawServer(Constants.ServerName, _bytesServer); + ErrorResetHeadersToDefaults(statusCode: 500); } } @@ -747,50 +758,61 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http bool appCompleted) { var responseHeaders = FrameResponseHeaders; - responseHeaders.SetReadOnly(); var hasConnection = responseHeaders.HasConnection; + // Set whether response can have body + _canHaveBody = StatusCanHaveBody(StatusCode) && Method != "HEAD"; + var end = SocketOutput.ProducingStart(); if (_keepAlive && hasConnection) { var connectionValue = responseHeaders.HeaderConnection.ToString(); _keepAlive = connectionValue.Equals("keep-alive", StringComparison.OrdinalIgnoreCase); } - - if (!responseHeaders.HasTransferEncoding && !responseHeaders.HasContentLength) + + if (_canHaveBody) { - if (appCompleted) + if (!responseHeaders.HasTransferEncoding && !responseHeaders.HasContentLength) { - // Don't set the Content-Length or Transfer-Encoding headers - // automatically for HEAD requests or 101, 204, 205, 304 responses. - if (Method != "HEAD" && StatusCanHaveBody(StatusCode)) + if (appCompleted) { // Since the app has completed and we are only now generating // the headers we can safely set the Content-Length to 0. responseHeaders.SetRawContentLength("0", _bytesContentLengthZero); } - } - else if (_keepAlive) - { - // Note for future reference: never change this to set _autoChunk to true on HTTP/1.0 - // connections, even if we were to infer the client supports it because an HTTP/1.0 request - // was received that used chunked encoding. Sending a chunked response to an HTTP/1.0 - // client would break compliance with RFC 7230 (section 3.3.1): - // - // A server MUST NOT send a response containing Transfer-Encoding unless the corresponding - // request indicates HTTP/1.1 (or later). - if (_httpVersion == Http.HttpVersion.Http11) - { - _autoChunk = true; - responseHeaders.SetRawTransferEncoding("chunked", _bytesTransferEncodingChunked); - } else { - _keepAlive = false; + // Note for future reference: never change this to set _autoChunk to true on HTTP/1.0 + // connections, even if we were to infer the client supports it because an HTTP/1.0 request + // was received that used chunked encoding. Sending a chunked response to an HTTP/1.0 + // client would break compliance with RFC 7230 (section 3.3.1): + // + // A server MUST NOT send a response containing Transfer-Encoding unless the corresponding + // request indicates HTTP/1.1 (or later). + if (_httpVersion == Http.HttpVersion.Http11) + { + _autoChunk = true; + responseHeaders.SetRawTransferEncoding("chunked", _bytesTransferEncodingChunked); + } + else + { + _keepAlive = false; + } } } } + else + { + // Don't set the Content-Length or Transfer-Encoding headers + // automatically for HEAD requests or 101, 204, 205, 304 responses. + if (responseHeaders.HasTransferEncoding) + { + RejectNonBodyTransferEncodingResponse(appCompleted); + } + } + + responseHeaders.SetReadOnly(); if (!_keepAlive && !hasConnection) { @@ -1255,12 +1277,67 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http statusCode != 304; } - private void ThrowResponseAlreadyStartedException(string value) + private void RejectNonBodyTransferEncodingResponse(bool appCompleted) { - throw new InvalidOperationException(value + " cannot be set, response had already started."); + var ex = BadHttpResponse.GetException(ResponseRejectionReasons.TransferEncodingSetOnNonBodyResponse, StatusCode); + if (!appCompleted) + { + // Back out of header creation surface exeception in user code + _requestProcessingStatus = RequestProcessingStatus.RequestStarted; + throw ex; + } + else + { + ReportApplicationError(ex); + // 500 Internal Server Error + ErrorResetHeadersToDefaults(statusCode: 500); + } + } + + private void ErrorResetHeadersToDefaults(int statusCode) + { + // Setting status code will throw if response has already started + if (!HasResponseStarted) + { + StatusCode = statusCode; + ReasonPhrase = null; + } + + var responseHeaders = FrameResponseHeaders; + responseHeaders.Reset(); + var dateHeaderValues = DateHeaderValueManager.GetDateHeaderValues(); + + responseHeaders.SetRawDate(dateHeaderValues.String, dateHeaderValues.Bytes); + responseHeaders.SetRawContentLength("0", _bytesContentLengthZero); + + if (ServerOptions.AddServerHeader) + { + responseHeaders.SetRawServer(Constants.ServerName, _bytesServer); + } + } + + public void HandleNonBodyResponseWrite(int count) + { + if (Method == "HEAD") + { + // Don't write to body for HEAD requests. + Log.ConnectionHeadResponseBodyWrite(ConnectionId, count); + } + else + { + // Throw Exception for 101, 204, 205, 304 responses. + BadHttpResponse.ThrowException(ResponseRejectionReasons.WriteToNonBodyResponse, StatusCode); + } } private void ThrowResponseAbortedException() + { + throw new ObjectDisposedException( + "The response has been aborted due to an unhandled application exception.", + _applicationException); + } + + public void RejectRequest(string message) { throw new ObjectDisposedException( "The response has been aborted due to an unhandled application exception.", @@ -1288,11 +1365,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http public void SetBadRequestState(BadHttpRequestException ex) { - // Setting status code will throw if response has already started - if (!HasResponseStarted) - { - StatusCode = ex.StatusCode; - } + ErrorResetHeadersToDefaults(statusCode: ex.StatusCode); _keepAlive = false; _requestProcessingStopping = true; diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameHeaders.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameHeaders.cs index ac283a006c..d91aec8d6d 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameHeaders.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameHeaders.cs @@ -29,7 +29,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { if (_isReadOnly) { - ThrowHeadersReadOnlyException(); + BadHttpResponse.ThrowException(ResponseRejectionReasons.HeadersReadonlyResponseStarted); } SetValueFast(key, value); } @@ -48,11 +48,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } } - protected void ThrowHeadersReadOnlyException() - { - throw new InvalidOperationException("Headers are read-only, response has already started."); - } - protected void ThrowArgumentException() { throw new ArgumentException(); @@ -144,7 +139,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { if (_isReadOnly) { - ThrowHeadersReadOnlyException(); + BadHttpResponse.ThrowException(ResponseRejectionReasons.HeadersReadonlyResponseStarted); } AddValueFast(key, value); } @@ -153,7 +148,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { if (_isReadOnly) { - ThrowHeadersReadOnlyException(); + BadHttpResponse.ThrowException(ResponseRejectionReasons.HeadersReadonlyResponseStarted); } ClearFast(); } @@ -200,7 +195,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { if (_isReadOnly) { - ThrowHeadersReadOnlyException(); + BadHttpResponse.ThrowException(ResponseRejectionReasons.HeadersReadonlyResponseStarted); } return RemoveFast(key); } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ResponseRejectionReasons.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ResponseRejectionReasons.cs new file mode 100644 index 0000000000..4ccc699020 --- /dev/null +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ResponseRejectionReasons.cs @@ -0,0 +1,22 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http +{ + public enum ResponseRejectionReasons + { + HeadersReadonlyResponseStarted, + ValueCannotBeSetResponseStarted, + TransferEncodingSetOnNonBodyResponse, + WriteToNonBodyResponse, + OnStartingCannotBeSetResponseStarted + } + + public enum ResponseRejectionParameter + { + StatusCode, + ReasonPhrase, + OnStarting + } + +} diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/IKestrelTrace.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/IKestrelTrace.cs index e18a99ce21..900adc8766 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/IKestrelTrace.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/IKestrelTrace.cs @@ -33,6 +33,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure void ConnectionDisconnectedWrite(string connectionId, int count, Exception ex); + void ConnectionHeadResponseBodyWrite(string connectionId, int count); + void ConnectionBadRequest(string connectionId, BadHttpRequestException ex); void NotAllConnectionsClosedGracefully(); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/KestrelTrace.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/KestrelTrace.cs index 0215b45374..5d3ecff7bd 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/KestrelTrace.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/KestrelTrace.cs @@ -24,6 +24,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal private static readonly Action _applicationError; private static readonly Action _connectionError; private static readonly Action _connectionDisconnectedWrite; + private static readonly Action _connectionHeadResponseBodyWrite; private static readonly Action _notAllConnectionsClosedGracefully; private static readonly Action _connectionBadRequest; @@ -48,6 +49,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal _connectionDisconnectedWrite = LoggerMessage.Define(LogLevel.Debug, 15, @"Connection id ""{ConnectionId}"" write of ""{count}"" bytes to disconnected client."); _notAllConnectionsClosedGracefully = LoggerMessage.Define(LogLevel.Debug, 16, "Some connections failed to close gracefully during server shutdown."); _connectionBadRequest = LoggerMessage.Define(LogLevel.Information, 17, @"Connection id ""{ConnectionId}"" bad request data: ""{message}"""); + _connectionHeadResponseBodyWrite = LoggerMessage.Define(LogLevel.Debug, 18, @"Connection id ""{ConnectionId}"" write of ""{count}"" body bytes to non-body HEAD response."); } public KestrelTrace(ILogger logger) @@ -133,6 +135,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal _connectionDisconnectedWrite(_logger, connectionId, count, ex); } + public virtual void ConnectionHeadResponseBodyWrite(string connectionId, int count) + { + _connectionHeadResponseBodyWrite(_logger, connectionId, count, null); + } + public virtual void NotAllConnectionsClosedGracefully() { _notAllConnectionsClosedGracefully(_logger, null); diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs index c59e74160b..86962eccd5 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs @@ -4,6 +4,7 @@ using System; using System.IO; using System.Text; +using System.Threading; using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Server.Kestrel; using Microsoft.AspNetCore.Server.Kestrel.Internal; @@ -1260,5 +1261,228 @@ namespace Microsoft.AspNetCore.Server.KestrelTests requestProcessingTask.Wait(); } } + + [Fact] + public void FlushSetsTransferEncodingSetForUnknownLengthBodyResponse() + { + // Arrange + var serviceContext = new ServiceContext + { + DateHeaderValueManager = new DateHeaderValueManager(), + ServerOptions = new KestrelServerOptions(), + Log = new TestKestrelTrace() + }; + var listenerContext = new ListenerContext(serviceContext) + { + ServerAddress = ServerAddress.FromUrl("http://localhost:5000") + }; + var connectionContext = new ConnectionContext(listenerContext) + { + SocketOutput = new MockSocketOuptut(), + }; + var frame = new TestFrameProtectedMembers(application: null, context: connectionContext); + frame.InitializeHeaders(); + frame.KeepAlive = true; + frame.HttpVersion = "HTTP/1.1"; + + // Act + frame.Flush(); + + // Assert + Assert.True(frame.HasResponseStarted); + Assert.True(frame.ResponseHeaders.ContainsKey("Transfer-Encoding")); + } + + [Fact] + public void FlushDoesNotSetTransferEncodingSetForNoBodyResponse() + { + // Arrange + var serviceContext = new ServiceContext + { + DateHeaderValueManager = new DateHeaderValueManager(), + ServerOptions = new KestrelServerOptions(), + Log = new TestKestrelTrace() + }; + var listenerContext = new ListenerContext(serviceContext) + { + ServerAddress = ServerAddress.FromUrl("http://localhost:5000") + }; + var connectionContext = new ConnectionContext(listenerContext) + { + SocketOutput = new MockSocketOuptut(), + }; + var frame = new TestFrameProtectedMembers(application: null, context: connectionContext); + frame.InitializeHeaders(); + frame.KeepAlive = true; + frame.HttpVersion = "HTTP/1.1"; + ((IHttpResponseFeature)frame).StatusCode = 304; + + // Act + frame.Flush(); + + // Assert + Assert.True(frame.HasResponseStarted); + Assert.False(frame.ResponseHeaders.ContainsKey("Transfer-Encoding")); + } + + [Fact] + public void FlushDoesNotSetTransferEncodingSetForHeadResponse() + { + // Arrange + var serviceContext = new ServiceContext + { + DateHeaderValueManager = new DateHeaderValueManager(), + ServerOptions = new KestrelServerOptions(), + Log = new TestKestrelTrace() + }; + var listenerContext = new ListenerContext(serviceContext) + { + ServerAddress = ServerAddress.FromUrl("http://localhost:5000") + }; + var connectionContext = new ConnectionContext(listenerContext) + { + SocketOutput = new MockSocketOuptut(), + }; + var frame = new TestFrameProtectedMembers(application: null, context: connectionContext); + frame.InitializeHeaders(); + frame.KeepAlive = true; + frame.HttpVersion = "HTTP/1.1"; + ((IHttpRequestFeature)frame).Method = "HEAD"; + + // Act + frame.Flush(); + + // Assert + Assert.True(frame.HasResponseStarted); + Assert.False(frame.ResponseHeaders.ContainsKey("Transfer-Encoding")); + } + + [Fact] + public void WriteThrowsForNoBodyResponse() + { + // Arrange + var serviceContext = new ServiceContext + { + DateHeaderValueManager = new DateHeaderValueManager(), + ServerOptions = new KestrelServerOptions(), + Log = new TestKestrelTrace() + }; + var listenerContext = new ListenerContext(serviceContext) + { + ServerAddress = ServerAddress.FromUrl("http://localhost:5000") + }; + var connectionContext = new ConnectionContext(listenerContext) + { + SocketOutput = new MockSocketOuptut(), + }; + var frame = new TestFrameProtectedMembers(application: null, context: connectionContext); + frame.InitializeHeaders(); + frame.KeepAlive = true; + frame.HttpVersion = "HTTP/1.1"; + ((IHttpResponseFeature)frame).StatusCode = 304; + + // Assert + frame.Flush(); // Does not throw + + Assert.Throws(() => frame.Write(new ArraySegment(new byte[1]))); + Assert.ThrowsAsync(() => frame.WriteAsync(new ArraySegment(new byte[1]), default(CancellationToken))); + + frame.Flush(); // Does not throw + } + + [Fact] + public void WriteDoesNotThrowForHeadResponse() + { + // Arrange + var serviceContext = new ServiceContext + { + DateHeaderValueManager = new DateHeaderValueManager(), + ServerOptions = new KestrelServerOptions(), + Log = new TestKestrelTrace() + }; + var listenerContext = new ListenerContext(serviceContext) + { + ServerAddress = ServerAddress.FromUrl("http://localhost:5000") + }; + var connectionContext = new ConnectionContext(listenerContext) + { + SocketOutput = new MockSocketOuptut(), + }; + var frame = new TestFrameProtectedMembers(application: null, context: connectionContext); + frame.InitializeHeaders(); + frame.KeepAlive = true; + frame.HttpVersion = "HTTP/1.1"; + ((IHttpRequestFeature)frame).Method = "HEAD"; + + // Assert + frame.Flush(); // Does not throw + + frame.Write(new ArraySegment(new byte[1])); + + frame.Flush(); // Does not throw + } + + + [Fact] + public void ManuallySettingTransferEncodingThrowsForHeadResponse() + { + // Arrange + var serviceContext = new ServiceContext + { + DateHeaderValueManager = new DateHeaderValueManager(), + ServerOptions = new KestrelServerOptions(), + Log = new TestKestrelTrace() + }; + var listenerContext = new ListenerContext(serviceContext) + { + ServerAddress = ServerAddress.FromUrl("http://localhost:5000") + }; + var connectionContext = new ConnectionContext(listenerContext) + { + SocketOutput = new MockSocketOuptut(), + }; + var frame = new TestFrameProtectedMembers(application: null, context: connectionContext); + frame.InitializeHeaders(); + frame.KeepAlive = true; + frame.HttpVersion = "HTTP/1.1"; + ((IHttpRequestFeature)frame).Method = "HEAD"; + + //Act + frame.ResponseHeaders.Add("Transfer-Encoding", "chunked"); + + // Assert + Assert.Throws(() => frame.Flush()); + } + + [Fact] + public void ManuallySettingTransferEncodingThrowsForNoBodyResponse() + { + // Arrange + var serviceContext = new ServiceContext + { + DateHeaderValueManager = new DateHeaderValueManager(), + ServerOptions = new KestrelServerOptions(), + Log = new TestKestrelTrace() + }; + var listenerContext = new ListenerContext(serviceContext) + { + ServerAddress = ServerAddress.FromUrl("http://localhost:5000") + }; + var connectionContext = new ConnectionContext(listenerContext) + { + SocketOutput = new MockSocketOuptut(), + }; + var frame = new TestFrameProtectedMembers(application: null, context: connectionContext); + frame.InitializeHeaders(); + frame.KeepAlive = true; + frame.HttpVersion = "HTTP/1.1"; + ((IHttpResponseFeature)frame).StatusCode = 304; + + //Act + frame.ResponseHeaders.Add("Transfer-Encoding", "chunked"); + + // Assert + Assert.Throws(() => frame.Flush()); + } } } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestFrameProtectedMembers.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/TestFrameProtectedMembers.cs new file mode 100644 index 0000000000..01d6418cec --- /dev/null +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/TestFrameProtectedMembers.cs @@ -0,0 +1,23 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + + +using Microsoft.AspNetCore.Hosting.Server; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; + +namespace Microsoft.AspNetCore.Server.KestrelTests +{ + public class TestFrameProtectedMembers : Frame + { + public TestFrameProtectedMembers(IHttpApplication application, ConnectionContext context) + : base(application, context) + { + } + + public bool KeepAlive + { + get { return _keepAlive; } + set { _keepAlive = value; } + } + } +} From 4117ad8a1ee9b0ea532884fd1f9e0c437f246569 Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Fri, 30 Sep 2016 12:17:31 -0700 Subject: [PATCH 0901/1662] Refactor non-body response handling. - Add functional tests - Remove BadHttpResponse, ResponseRejectionReasons and TestFrameProtectedMembers - Chunk non-keepalive HTTP/1.1 responses - Set _canHaveBody to true when StatusCode == 101 - Add test to check that upgraded connections are always closed when the app is done - Log writes on responses to HEAD requests only once. --- .../BadHttpResponse.cs | 75 -------- .../Internal/Http/Frame.cs | 95 ++++++---- .../Internal/Http/FrameHeaders.cs | 13 +- .../Internal/Http/ResponseRejectionReasons.cs | 22 --- .../ResponseTests.cs | 114 +++++++++++ .../project.json | 1 + .../ChunkedResponseTests.cs | 48 +++-- .../EngineTests.cs | 78 +++++++- .../FrameTests.cs | 178 ++++++------------ .../TestFrameProtectedMembers.cs | 23 --- test/shared/TestKestrelTrace.cs | 10 + 11 files changed, 362 insertions(+), 295 deletions(-) delete mode 100644 src/Microsoft.AspNetCore.Server.Kestrel/BadHttpResponse.cs delete mode 100644 src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ResponseRejectionReasons.cs delete mode 100644 test/Microsoft.AspNetCore.Server.KestrelTests/TestFrameProtectedMembers.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/BadHttpResponse.cs b/src/Microsoft.AspNetCore.Server.Kestrel/BadHttpResponse.cs deleted file mode 100644 index 2e953b46ca..0000000000 --- a/src/Microsoft.AspNetCore.Server.Kestrel/BadHttpResponse.cs +++ /dev/null @@ -1,75 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using System.Runtime.CompilerServices; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; - -namespace Microsoft.AspNetCore.Server.Kestrel -{ - public static class BadHttpResponse - { - internal static void ThrowException(ResponseRejectionReasons reason) - { - throw GetException(reason); - } - - internal static void ThrowException(ResponseRejectionReasons reason, int value) - { - throw GetException(reason, value.ToString()); - } - - internal static void ThrowException(ResponseRejectionReasons reason, ResponseRejectionParameter parameter) - { - throw GetException(reason, parameter.ToString()); - } - - internal static InvalidOperationException GetException(ResponseRejectionReasons reason, int value) - { - return GetException(reason, value.ToString()); - } - - [MethodImpl(MethodImplOptions.NoInlining)] - internal static InvalidOperationException GetException(ResponseRejectionReasons reason) - { - InvalidOperationException ex; - switch (reason) - { - case ResponseRejectionReasons.HeadersReadonlyResponseStarted: - ex = new InvalidOperationException("Headers are read-only, response has already started."); - break; - case ResponseRejectionReasons.OnStartingCannotBeSetResponseStarted: - ex = new InvalidOperationException("OnStarting cannot be set, response has already started."); - break; - default: - ex = new InvalidOperationException("Bad response."); - break; - } - - return ex; - } - - [MethodImpl(MethodImplOptions.NoInlining)] - private static InvalidOperationException GetException(ResponseRejectionReasons reason, string value) - { - InvalidOperationException ex; - switch (reason) - { - case ResponseRejectionReasons.ValueCannotBeSetResponseStarted: - ex = new InvalidOperationException(value + " cannot be set, response had already started."); - break; - case ResponseRejectionReasons.TransferEncodingSetOnNonBodyResponse: - ex = new InvalidOperationException($"Transfer-Encoding set on a {value} non-body request."); - break; - case ResponseRejectionReasons.WriteToNonBodyResponse: - ex = new InvalidOperationException($"Write to non-body {value} response."); - break; - default: - ex = new InvalidOperationException("Bad response."); - break; - } - - return ex; - } - } -} diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs index 0ab83b51ea..f3c8dc8dbb 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using System.IO; using System.Linq; using System.Net; @@ -74,6 +75,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http protected readonly long _keepAliveMilliseconds; private readonly long _requestHeadersTimeoutMilliseconds; + private int _responseBytesWritten; + public Frame(ConnectionContext context) { ConnectionContext = context; @@ -172,7 +175,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { if (HasResponseStarted) { - BadHttpResponse.ThrowException(ResponseRejectionReasons.ValueCannotBeSetResponseStarted, ResponseRejectionParameter.StatusCode); + ThrowResponseAlreadyStartedException(nameof(StatusCode)); } _statusCode = value; @@ -190,7 +193,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { if (HasResponseStarted) { - BadHttpResponse.ThrowException(ResponseRejectionReasons.ValueCannotBeSetResponseStarted, ResponseRejectionParameter.ReasonPhrase); + ThrowResponseAlreadyStartedException(nameof(ReasonPhrase)); } _reasonPhrase = value; @@ -346,6 +349,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _remainingRequestHeadersBytesAllowed = ServerOptions.Limits.MaxRequestHeadersTotalSize; _requestHeadersParsed = 0; + + _responseBytesWritten = 0; } /// @@ -426,7 +431,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { if (HasResponseStarted) { - BadHttpResponse.ThrowException(ResponseRejectionReasons.OnStartingCannotBeSetResponseStarted, ResponseRejectionParameter.OnStarting); + ThrowResponseAlreadyStartedException(nameof(OnStarting)); } if (_onStarting == null) @@ -512,6 +517,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http public void Write(ArraySegment data) { ProduceStartAndFireOnStarting().GetAwaiter().GetResult(); + _responseBytesWritten += data.Count; if (_canHaveBody) { @@ -530,7 +536,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } else { - HandleNonBodyResponseWrite(data.Count); + HandleNonBodyResponseWrite(); } } @@ -541,6 +547,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http return WriteAsyncAwaited(data, cancellationToken); } + _responseBytesWritten += data.Count; + if (_canHaveBody) { if (_autoChunk) @@ -558,7 +566,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } else { - HandleNonBodyResponseWrite(data.Count); + HandleNonBodyResponseWrite(); return TaskCache.CompletedTask; } } @@ -566,6 +574,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http public async Task WriteAsyncAwaited(ArraySegment data, CancellationToken cancellationToken) { await ProduceStartAndFireOnStarting(); + _responseBytesWritten += data.Count; if (_canHaveBody) { @@ -584,10 +593,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } else { - HandleNonBodyResponseWrite(data.Count); + HandleNonBodyResponseWrite(); return; } - } private void WriteChunked(ArraySegment data) @@ -700,11 +708,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http return TaskCache.CompletedTask; } - // If the request was rejected, StatusCode has already been set by SetBadRequestState + // If the request was rejected, the error state has already been set by SetBadRequestState if (!_requestRejected) { // 500 Internal Server Error - ErrorResetHeadersToDefaults(statusCode: 500); + SetErrorResponseHeaders(statusCode: 500); } } @@ -740,6 +748,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http ConnectionControl.End(ProduceEndType.ConnectionKeepAlive); } + if (HttpMethods.IsHead(Method) && _responseBytesWritten > 0) + { + Log.ConnectionHeadResponseBodyWrite(ConnectionId, _responseBytesWritten); + } + return TaskCache.CompletedTask; } @@ -758,24 +771,26 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http bool appCompleted) { var responseHeaders = FrameResponseHeaders; - var hasConnection = responseHeaders.HasConnection; - // Set whether response can have body - _canHaveBody = StatusCanHaveBody(StatusCode) && Method != "HEAD"; - var end = SocketOutput.ProducingStart(); + if (_keepAlive && hasConnection) { var connectionValue = responseHeaders.HeaderConnection.ToString(); _keepAlive = connectionValue.Equals("keep-alive", StringComparison.OrdinalIgnoreCase); } - + + // Set whether response can have body + _canHaveBody = StatusCanHaveBody(StatusCode) && Method != "HEAD"; + + // Don't set the Content-Length or Transfer-Encoding headers + // automatically for HEAD requests or 204, 205, 304 responses. if (_canHaveBody) { if (!responseHeaders.HasTransferEncoding && !responseHeaders.HasContentLength) { - if (appCompleted) + if (appCompleted && StatusCode != 101) { // Since the app has completed and we are only now generating // the headers we can safely set the Content-Length to 0. @@ -790,7 +805,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http // // A server MUST NOT send a response containing Transfer-Encoding unless the corresponding // request indicates HTTP/1.1 (or later). - if (_httpVersion == Http.HttpVersion.Http11) + if (_httpVersion == Http.HttpVersion.Http11 && StatusCode != 101) { _autoChunk = true; responseHeaders.SetRawTransferEncoding("chunked", _bytesTransferEncodingChunked); @@ -804,8 +819,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } else { - // Don't set the Content-Length or Transfer-Encoding headers - // automatically for HEAD requests or 101, 204, 205, 304 responses. if (responseHeaders.HasTransferEncoding) { RejectNonBodyTransferEncodingResponse(appCompleted); @@ -1271,15 +1284,19 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http public bool StatusCanHaveBody(int statusCode) { // List of status codes taken from Microsoft.Net.Http.Server.Response - return statusCode != 101 && - statusCode != 204 && + return statusCode != 204 && statusCode != 205 && statusCode != 304; } + private void ThrowResponseAlreadyStartedException(string value) + { + throw new InvalidOperationException($"{value} cannot be set, response has already started."); + } + private void RejectNonBodyTransferEncodingResponse(bool appCompleted) { - var ex = BadHttpResponse.GetException(ResponseRejectionReasons.TransferEncodingSetOnNonBodyResponse, StatusCode); + var ex = new InvalidOperationException($"Transfer-Encoding set on a {StatusCode} non-body request."); if (!appCompleted) { // Back out of header creation surface exeception in user code @@ -1289,18 +1306,22 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http else { ReportApplicationError(ex); + // 500 Internal Server Error - ErrorResetHeadersToDefaults(statusCode: 500); + SetErrorResponseHeaders(statusCode: 500); } } - private void ErrorResetHeadersToDefaults(int statusCode) + private void SetErrorResponseHeaders(int statusCode) { - // Setting status code will throw if response has already started - if (!HasResponseStarted) + Debug.Assert(!HasResponseStarted, $"{nameof(SetErrorResponseHeaders)} called after response had already started."); + + StatusCode = statusCode; + ReasonPhrase = null; + + if (FrameResponseHeaders == null) { - StatusCode = statusCode; - ReasonPhrase = null; + InitializeHeaders(); } var responseHeaders = FrameResponseHeaders; @@ -1316,17 +1337,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } } - public void HandleNonBodyResponseWrite(int count) + public void HandleNonBodyResponseWrite() { - if (Method == "HEAD") + // Writes to HEAD response are ignored and logged at the end of the request + if (Method != "HEAD") { - // Don't write to body for HEAD requests. - Log.ConnectionHeadResponseBodyWrite(ConnectionId, count); - } - else - { - // Throw Exception for 101, 204, 205, 304 responses. - BadHttpResponse.ThrowException(ResponseRejectionReasons.WriteToNonBodyResponse, StatusCode); + // Throw Exception for 204, 205, 304 responses. + throw new InvalidOperationException($"Write to non-body {StatusCode} response."); } } @@ -1365,7 +1382,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http public void SetBadRequestState(BadHttpRequestException ex) { - ErrorResetHeadersToDefaults(statusCode: ex.StatusCode); + // Setting status code will throw if response has already started + if (!HasResponseStarted) + { + SetErrorResponseHeaders(statusCode: ex.StatusCode); + } _keepAlive = false; _requestProcessingStopping = true; diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameHeaders.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameHeaders.cs index d91aec8d6d..ac283a006c 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameHeaders.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameHeaders.cs @@ -29,7 +29,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { if (_isReadOnly) { - BadHttpResponse.ThrowException(ResponseRejectionReasons.HeadersReadonlyResponseStarted); + ThrowHeadersReadOnlyException(); } SetValueFast(key, value); } @@ -48,6 +48,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } } + protected void ThrowHeadersReadOnlyException() + { + throw new InvalidOperationException("Headers are read-only, response has already started."); + } + protected void ThrowArgumentException() { throw new ArgumentException(); @@ -139,7 +144,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { if (_isReadOnly) { - BadHttpResponse.ThrowException(ResponseRejectionReasons.HeadersReadonlyResponseStarted); + ThrowHeadersReadOnlyException(); } AddValueFast(key, value); } @@ -148,7 +153,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { if (_isReadOnly) { - BadHttpResponse.ThrowException(ResponseRejectionReasons.HeadersReadonlyResponseStarted); + ThrowHeadersReadOnlyException(); } ClearFast(); } @@ -195,7 +200,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { if (_isReadOnly) { - BadHttpResponse.ThrowException(ResponseRejectionReasons.HeadersReadonlyResponseStarted); + ThrowHeadersReadOnlyException(); } return RemoveFast(key); } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ResponseRejectionReasons.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ResponseRejectionReasons.cs deleted file mode 100644 index 4ccc699020..0000000000 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ResponseRejectionReasons.cs +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http -{ - public enum ResponseRejectionReasons - { - HeadersReadonlyResponseStarted, - ValueCannotBeSetResponseStarted, - TransferEncodingSetOnNonBodyResponse, - WriteToNonBodyResponse, - OnStartingCannotBeSetResponseStarted - } - - public enum ResponseRejectionParameter - { - StatusCode, - ReasonPhrase, - OnStarting - } - -} diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs index 4bdf8940f1..bcd2e7ecfd 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs @@ -5,13 +5,17 @@ using System; using System.Linq; using System.Net; using System.Net.Http; +using System.Text; using System.Threading.Tasks; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.AspNetCore.Testing; using Microsoft.Extensions.Internal; using Microsoft.Extensions.Primitives; +using Moq; using Xunit; namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests @@ -213,6 +217,116 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } } + [Fact] + public async Task TransferEncodingChunkedSetOnUnknownLengthHttp11Response() + { + using (var server = new TestServer(async httpContext => + { + await httpContext.Response.WriteAsync("hello, "); + await httpContext.Response.WriteAsync("world"); + }, new TestServiceContext())) + { + using (var connection = server.CreateConnection()) + { + await connection.Send( + "GET / HTTP/1.1", + "", + ""); + await connection.Receive( + "HTTP/1.1 200 OK", + $"Date: {server.Context.DateHeaderValue}", + "Transfer-Encoding: chunked", + "", + "7", + "hello, ", + "5", + "world", + "0", + "", + ""); + } + } + } + + [Theory] + [InlineData(204)] + [InlineData(205)] + [InlineData(304)] + public async Task TransferEncodingChunkedNotSetOnNonBodyResponse(int statusCode) + { + using (var server = new TestServer(httpContext => + { + httpContext.Response.StatusCode = statusCode; + return TaskCache.CompletedTask; + }, new TestServiceContext())) + { + using (var connection = server.CreateConnection()) + { + await connection.Send( + "GET / HTTP/1.1", + "", + ""); + await connection.Receive( + $"HTTP/1.1 {Encoding.ASCII.GetString(ReasonPhrases.ToStatusBytes(statusCode))}", + $"Date: {server.Context.DateHeaderValue}", + "", + ""); + } + } + } + + [Fact] + public async Task TransferEncodingNotSetOnHeadResponse() + { + using (var server = new TestServer(httpContext => + { + return TaskCache.CompletedTask; + }, new TestServiceContext())) + { + using (var connection = server.CreateConnection()) + { + await connection.Send( + "HEAD / HTTP/1.1", + "", + ""); + await connection.Receive( + $"HTTP/1.1 200 OK", + $"Date: {server.Context.DateHeaderValue}", + "", + ""); + } + } + } + + [Fact] + public async Task ResponseBodyNotWrittenOnHeadResponse() + { + var mockKestrelTrace = new Mock(); + + using (var server = new TestServer(async httpContext => + { + await httpContext.Response.WriteAsync("hello, world"); + await httpContext.Response.Body.FlushAsync(); + }, new TestServiceContext { Log = mockKestrelTrace.Object })) + { + using (var connection = server.CreateConnection()) + { + await connection.Send( + "HEAD / HTTP/1.1", + "", + ""); + await connection.Receive( + $"HTTP/1.1 200 OK", + $"Date: {server.Context.DateHeaderValue}", + "", + ""); + } + } + + mockKestrelTrace.Verify(kestrelTrace => + kestrelTrace.ConnectionHeadResponseBodyWrite(It.IsAny(), "hello, world".Length)); + } + public static TheoryData NullHeaderData { get diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json index e90217c86f..a1e32897e4 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json @@ -7,6 +7,7 @@ "Microsoft.AspNetCore.Server.Kestrel.Https": "1.1.0-*", "Microsoft.AspNetCore.Testing": "1.1.0-*", "Microsoft.Extensions.Logging.Testing": "1.1.0-*", + "Moq": "4.6.36-*", "Newtonsoft.Json": "9.0.1", "xunit": "2.2.0-*" }, diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedResponseTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedResponseTests.cs index d4936ba0c9..b6e59342fb 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedResponseTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedResponseTests.cs @@ -5,6 +5,7 @@ using System; using System.Text; using System.Threading; using System.Threading.Tasks; +using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Testing; using Xunit; @@ -63,13 +64,12 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [Theory] [MemberData(nameof(ConnectionFilterData))] - public async Task ResponsesAreNotChunkedAutomaticallyForHttp10RequestsAndHttp11NonKeepAliveRequests(TestServiceContext testContext) + public async Task ResponsesAreNotChunkedAutomaticallyForHttp10Requests(TestServiceContext testContext) { using (var server = new TestServer(async httpContext => { - var response = httpContext.Response; - await response.Body.WriteAsync(Encoding.ASCII.GetBytes("Hello "), 0, 6); - await response.Body.WriteAsync(Encoding.ASCII.GetBytes("World!"), 0, 6); + await httpContext.Response.WriteAsync("Hello "); + await httpContext.Response.WriteAsync("World!"); }, testContext)) { using (var connection = server.CreateConnection()) @@ -86,7 +86,19 @@ namespace Microsoft.AspNetCore.Server.KestrelTests "", "Hello World!"); } + } + } + [Theory] + [MemberData(nameof(ConnectionFilterData))] + public async Task ResponsesAreChunkedAutomaticallyForHttp11NonKeepAliveRequests(TestServiceContext testContext) + { + using (var server = new TestServer(async httpContext => + { + await httpContext.Response.WriteAsync("Hello "); + await httpContext.Response.WriteAsync("World!"); + }, testContext)) + { using (var connection = server.CreateConnection()) { await connection.SendEnd( @@ -98,23 +110,28 @@ namespace Microsoft.AspNetCore.Server.KestrelTests "HTTP/1.1 200 OK", "Connection: close", $"Date: {testContext.DateHeaderValue}", + "Transfer-Encoding: chunked", "", - "Hello World!"); + "6", + "Hello ", + "6", + "World!", + "0", + "", + ""); } } } - [Theory] [MemberData(nameof(ConnectionFilterData))] - public async Task SettingConnectionCloseHeaderInAppDisablesChunking(TestServiceContext testContext) + public async Task SettingConnectionCloseHeaderInAppDoesNotDisableChunking(TestServiceContext testContext) { using (var server = new TestServer(async httpContext => { - var response = httpContext.Response; - response.Headers["Connection"] = "close"; - await response.Body.WriteAsync(Encoding.ASCII.GetBytes("Hello "), 0, 6); - await response.Body.WriteAsync(Encoding.ASCII.GetBytes("World!"), 0, 6); + httpContext.Response.Headers["Connection"] = "close"; + await httpContext.Response.WriteAsync("Hello "); + await httpContext.Response.WriteAsync("World!"); }, testContext)) { using (var connection = server.CreateConnection()) @@ -127,8 +144,15 @@ namespace Microsoft.AspNetCore.Server.KestrelTests "HTTP/1.1 200 OK", "Connection: close", $"Date: {testContext.DateHeaderValue}", + "Transfer-Encoding: chunked", "", - "Hello World!"); + "6", + "Hello ", + "6", + "World!", + "0", + "", + ""); } } } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs index 21ecb56a19..a23a063d12 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs @@ -548,9 +548,6 @@ namespace Microsoft.AspNetCore.Server.KestrelTests "POST / HTTP/1.1", "Content-Length: 3", "", - "101POST / HTTP/1.1", - "Content-Length: 3", - "", "204POST / HTTP/1.1", "Content-Length: 3", "", @@ -562,9 +559,6 @@ namespace Microsoft.AspNetCore.Server.KestrelTests "", "200"); await connection.ReceiveEnd( - "HTTP/1.1 101 Switching Protocols", - $"Date: {testContext.DateHeaderValue}", - "", "HTTP/1.1 204 No Content", $"Date: {testContext.DateHeaderValue}", "", @@ -583,6 +577,78 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } } + [Theory] + [MemberData(nameof(ConnectionFilterData))] + public async Task ConnectionClosedAfter101Response(TestServiceContext testContext) + { + using (var server = new TestServer(async httpContext => + { + var request = httpContext.Request; + var stream = await httpContext.Features.Get().UpgradeAsync(); + var response = Encoding.ASCII.GetBytes("hello, world"); + await stream.WriteAsync(response, 0, response.Length); + }, testContext)) + { + using (var connection = server.CreateConnection()) + { + await connection.Send( + "GET / HTTP/1.1", + "", + ""); + await connection.ReceiveEnd( + "HTTP/1.1 101 Switching Protocols", + "Connection: Upgrade", + $"Date: {testContext.DateHeaderValue}", + "", + "hello, world"); + } + + using (var connection = server.CreateConnection()) + { + await connection.Send( + "GET / HTTP/1.0", + "Connection: keep-alive", + "", + ""); + await connection.ReceiveEnd( + "HTTP/1.1 101 Switching Protocols", + "Connection: Upgrade", + $"Date: {testContext.DateHeaderValue}", + "", + "hello, world"); + } + } + } + + [Theory] + [MemberData(nameof(ConnectionFilterData))] + public async Task WriteOnHeadResponseLoggedOnlyOnce(TestServiceContext testContext) + { + using (var server = new TestServer(async httpContext => + { + await httpContext.Response.WriteAsync("hello, "); + await httpContext.Response.WriteAsync("world"); + await httpContext.Response.WriteAsync("!"); + }, testContext)) + { + using (var connection = server.CreateConnection()) + { + await connection.SendEnd( + "HEAD / HTTP/1.1", + "", + ""); + await connection.ReceiveEnd( + "HTTP/1.1 200 OK", + $"Date: {testContext.DateHeaderValue}", + "", + ""); + } + + Assert.Equal(1, ((TestKestrelTrace)testContext.Log).HeadResponseWrites); + Assert.Equal(13, ((TestKestrelTrace)testContext.Log).HeadResponseWriteByteCount); + } + } + [Theory] [MemberData(nameof(ConnectionFilterData))] public async Task ThrowingResultsIn500Response(TestServiceContext testContext) diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs index 86962eccd5..a131af3e48 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs @@ -5,6 +5,7 @@ using System; using System.IO; using System.Text; using System.Threading; +using System.Threading.Tasks; using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Server.Kestrel; using Microsoft.AspNetCore.Server.Kestrel.Internal; @@ -1263,7 +1264,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } [Fact] - public void FlushSetsTransferEncodingSetForUnknownLengthBodyResponse() + public void WriteThrowsForNonBodyResponse() { // Arrange var serviceContext = new ServiceContext @@ -1280,114 +1281,40 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { SocketOutput = new MockSocketOuptut(), }; - var frame = new TestFrameProtectedMembers(application: null, context: connectionContext); + var frame = new Frame(application: null, context: connectionContext); frame.InitializeHeaders(); - frame.KeepAlive = true; - frame.HttpVersion = "HTTP/1.1"; - - // Act - frame.Flush(); - - // Assert - Assert.True(frame.HasResponseStarted); - Assert.True(frame.ResponseHeaders.ContainsKey("Transfer-Encoding")); - } - - [Fact] - public void FlushDoesNotSetTransferEncodingSetForNoBodyResponse() - { - // Arrange - var serviceContext = new ServiceContext - { - DateHeaderValueManager = new DateHeaderValueManager(), - ServerOptions = new KestrelServerOptions(), - Log = new TestKestrelTrace() - }; - var listenerContext = new ListenerContext(serviceContext) - { - ServerAddress = ServerAddress.FromUrl("http://localhost:5000") - }; - var connectionContext = new ConnectionContext(listenerContext) - { - SocketOutput = new MockSocketOuptut(), - }; - var frame = new TestFrameProtectedMembers(application: null, context: connectionContext); - frame.InitializeHeaders(); - frame.KeepAlive = true; frame.HttpVersion = "HTTP/1.1"; ((IHttpResponseFeature)frame).StatusCode = 304; - // Act - frame.Flush(); - - // Assert - Assert.True(frame.HasResponseStarted); - Assert.False(frame.ResponseHeaders.ContainsKey("Transfer-Encoding")); - } - - [Fact] - public void FlushDoesNotSetTransferEncodingSetForHeadResponse() - { - // Arrange - var serviceContext = new ServiceContext - { - DateHeaderValueManager = new DateHeaderValueManager(), - ServerOptions = new KestrelServerOptions(), - Log = new TestKestrelTrace() - }; - var listenerContext = new ListenerContext(serviceContext) - { - ServerAddress = ServerAddress.FromUrl("http://localhost:5000") - }; - var connectionContext = new ConnectionContext(listenerContext) - { - SocketOutput = new MockSocketOuptut(), - }; - var frame = new TestFrameProtectedMembers(application: null, context: connectionContext); - frame.InitializeHeaders(); - frame.KeepAlive = true; - frame.HttpVersion = "HTTP/1.1"; - ((IHttpRequestFeature)frame).Method = "HEAD"; - - // Act - frame.Flush(); - - // Assert - Assert.True(frame.HasResponseStarted); - Assert.False(frame.ResponseHeaders.ContainsKey("Transfer-Encoding")); - } - - [Fact] - public void WriteThrowsForNoBodyResponse() - { - // Arrange - var serviceContext = new ServiceContext - { - DateHeaderValueManager = new DateHeaderValueManager(), - ServerOptions = new KestrelServerOptions(), - Log = new TestKestrelTrace() - }; - var listenerContext = new ListenerContext(serviceContext) - { - ServerAddress = ServerAddress.FromUrl("http://localhost:5000") - }; - var connectionContext = new ConnectionContext(listenerContext) - { - SocketOutput = new MockSocketOuptut(), - }; - var frame = new TestFrameProtectedMembers(application: null, context: connectionContext); - frame.InitializeHeaders(); - frame.KeepAlive = true; - frame.HttpVersion = "HTTP/1.1"; - ((IHttpResponseFeature)frame).StatusCode = 304; - - // Assert - frame.Flush(); // Does not throw - + // Act/Assert Assert.Throws(() => frame.Write(new ArraySegment(new byte[1]))); - Assert.ThrowsAsync(() => frame.WriteAsync(new ArraySegment(new byte[1]), default(CancellationToken))); + } - frame.Flush(); // Does not throw + [Fact] + public async Task WriteAsyncThrowsForNonBodyResponse() + { + // Arrange + var serviceContext = new ServiceContext + { + DateHeaderValueManager = new DateHeaderValueManager(), + ServerOptions = new KestrelServerOptions(), + Log = new TestKestrelTrace() + }; + var listenerContext = new ListenerContext(serviceContext) + { + ServerAddress = ServerAddress.FromUrl("http://localhost:5000") + }; + var connectionContext = new ConnectionContext(listenerContext) + { + SocketOutput = new MockSocketOuptut(), + }; + var frame = new Frame(application: null, context: connectionContext); + frame.InitializeHeaders(); + frame.HttpVersion = "HTTP/1.1"; + ((IHttpResponseFeature)frame).StatusCode = 304; + + // Act/Assert + await Assert.ThrowsAsync(() => frame.WriteAsync(new ArraySegment(new byte[1]), default(CancellationToken))); } [Fact] @@ -1408,20 +1335,41 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { SocketOutput = new MockSocketOuptut(), }; - var frame = new TestFrameProtectedMembers(application: null, context: connectionContext); + var frame = new Frame(application: null, context: connectionContext); frame.InitializeHeaders(); - frame.KeepAlive = true; frame.HttpVersion = "HTTP/1.1"; ((IHttpRequestFeature)frame).Method = "HEAD"; - // Assert - frame.Flush(); // Does not throw - + // Act/Assert frame.Write(new ArraySegment(new byte[1])); - - frame.Flush(); // Does not throw } + [Fact] + public async Task WriteAsyncDoesNotThrowForHeadResponse() + { + // Arrange + var serviceContext = new ServiceContext + { + DateHeaderValueManager = new DateHeaderValueManager(), + ServerOptions = new KestrelServerOptions(), + Log = new TestKestrelTrace() + }; + var listenerContext = new ListenerContext(serviceContext) + { + ServerAddress = ServerAddress.FromUrl("http://localhost:5000") + }; + var connectionContext = new ConnectionContext(listenerContext) + { + SocketOutput = new MockSocketOuptut(), + }; + var frame = new Frame(application: null, context: connectionContext); + frame.InitializeHeaders(); + frame.HttpVersion = "HTTP/1.1"; + ((IHttpRequestFeature)frame).Method = "HEAD"; + + // Act/Assert + await frame.WriteAsync(new ArraySegment(new byte[1]), default(CancellationToken)); + } [Fact] public void ManuallySettingTransferEncodingThrowsForHeadResponse() @@ -1441,13 +1389,12 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { SocketOutput = new MockSocketOuptut(), }; - var frame = new TestFrameProtectedMembers(application: null, context: connectionContext); + var frame = new Frame(application: null, context: connectionContext); frame.InitializeHeaders(); - frame.KeepAlive = true; frame.HttpVersion = "HTTP/1.1"; ((IHttpRequestFeature)frame).Method = "HEAD"; - //Act + // Act frame.ResponseHeaders.Add("Transfer-Encoding", "chunked"); // Assert @@ -1472,13 +1419,12 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { SocketOutput = new MockSocketOuptut(), }; - var frame = new TestFrameProtectedMembers(application: null, context: connectionContext); + var frame = new Frame(application: null, context: connectionContext); frame.InitializeHeaders(); - frame.KeepAlive = true; frame.HttpVersion = "HTTP/1.1"; ((IHttpResponseFeature)frame).StatusCode = 304; - //Act + // Act frame.ResponseHeaders.Add("Transfer-Encoding", "chunked"); // Assert diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestFrameProtectedMembers.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/TestFrameProtectedMembers.cs deleted file mode 100644 index 01d6418cec..0000000000 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/TestFrameProtectedMembers.cs +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - - -using Microsoft.AspNetCore.Hosting.Server; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; - -namespace Microsoft.AspNetCore.Server.KestrelTests -{ - public class TestFrameProtectedMembers : Frame - { - public TestFrameProtectedMembers(IHttpApplication application, ConnectionContext context) - : base(application, context) - { - } - - public bool KeepAlive - { - get { return _keepAlive; } - set { _keepAlive = value; } - } - } -} diff --git a/test/shared/TestKestrelTrace.cs b/test/shared/TestKestrelTrace.cs index 814005d4d1..63dbfc0f73 100644 --- a/test/shared/TestKestrelTrace.cs +++ b/test/shared/TestKestrelTrace.cs @@ -13,6 +13,10 @@ namespace Microsoft.AspNetCore.Testing { } + public int HeadResponseWrites { get; set; } + + public int HeadResponseWriteByteCount { get; set; } + public override void ConnectionRead(string connectionId, int count) { //_logger.LogDebug(1, @"Connection id ""{ConnectionId}"" recv {count} bytes.", connectionId, count); @@ -27,5 +31,11 @@ namespace Microsoft.AspNetCore.Testing { //_logger.LogDebug(1, @"Connection id ""{ConnectionId}"" send finished with status {status}.", connectionId, status); } + + public override void ConnectionHeadResponseBodyWrite(string connectionId, int count) + { + HeadResponseWrites++; + HeadResponseWriteByteCount = count; + } } } \ No newline at end of file From a2439105ae360110457b1910832df2ae200327de Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Fri, 23 Sep 2016 17:08:30 -0700 Subject: [PATCH 0902/1662] Refactor request line validation and error reporting (#1116). --- .../BadHttpRequestException.cs | 32 +------- .../Internal/Http/Frame.cs | 51 ++++++------ .../Internal/Http/FrameOfT.cs | 2 +- .../Internal/Http/RequestRejectionReason.cs | 10 +-- .../MemoryPoolIteratorExtensions.cs | 20 +++++ .../FrameTests.cs | 58 +++++++++++--- .../MemoryPoolIteratorTests.cs | 79 +++++++++++++++++++ 7 files changed, 180 insertions(+), 72 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/BadHttpRequestException.cs b/src/Microsoft.AspNetCore.Server.Kestrel/BadHttpRequestException.cs index f5981b5607..775fb2344d 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/BadHttpRequestException.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/BadHttpRequestException.cs @@ -21,24 +21,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel BadHttpRequestException ex; switch (reason) { - case RequestRejectionReason.MissingMethod: - ex = new BadHttpRequestException("Missing method.", 400); - break; - case RequestRejectionReason.InvalidMethod: - ex = new BadHttpRequestException("Invalid method.", 400); - break; - case RequestRejectionReason.MissingRequestTarget: - ex = new BadHttpRequestException("Missing request target.", 400); - break; - case RequestRejectionReason.MissingHTTPVersion: - ex = new BadHttpRequestException("Missing HTTP version.", 400); - break; - case RequestRejectionReason.UnrecognizedHTTPVersion: - ex = new BadHttpRequestException("Unrecognized HTTP version.", 505); - break; - case RequestRejectionReason.MissingLFInRequestLine: - ex = new BadHttpRequestException("Missing LF in request line.", 400); - break; case RequestRejectionReason.HeadersCorruptedInvalidHeaderSequence: ex = new BadHttpRequestException("Headers corrupted, invalid header sequence.", 400); break; @@ -84,15 +66,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel case RequestRejectionReason.RequestLineTooLong: ex = new BadHttpRequestException("Request line too long.", 414); break; - case RequestRejectionReason.MissingSpaceAfterMethod: - ex = new BadHttpRequestException("No space character found after method in request line.", 400); - break; - case RequestRejectionReason.MissingSpaceAfterTarget: - ex = new BadHttpRequestException("No space character found after target in request line.", 400); - break; - case RequestRejectionReason.MissingCrAfterVersion: - ex = new BadHttpRequestException("Missing CR in request line.", 400); - break; case RequestRejectionReason.HeadersExceedMaxTotalSize: ex = new BadHttpRequestException("Request headers too long.", 431); break; @@ -117,12 +90,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel BadHttpRequestException ex; switch (reason) { - case RequestRejectionReason.MalformedRequestLineStatus: + case RequestRejectionReason.InvalidRequestLine: ex = new BadHttpRequestException($"Invalid request line: {value}", 400); break; case RequestRejectionReason.InvalidContentLength: ex = new BadHttpRequestException($"Invalid content length: {value}", 400); break; + case RequestRejectionReason.UnrecognizedHTTPVersion: + ex = new BadHttpRequestException($"Unrecognized HTTP version: {value}", 505); + break; default: ex = new BadHttpRequestException("Bad request.", 400); break; diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs index f3c8dc8dbb..9a13ab2cb7 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs @@ -857,7 +857,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http public RequestLineStatus TakeStartLine(SocketInput input) { + const int MaxInvalidRequestLineChars = 32; + var scan = input.ConsumingStart(); + var start = scan; var consumed = scan; var end = scan; @@ -890,6 +893,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http return RequestLineStatus.Incomplete; } } + end.Take(); string method; var begin = scan; @@ -897,14 +901,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { if (scan.Seek(ref _vectorSpaces, ref end) == -1) { - RejectRequest(RequestRejectionReason.MissingSpaceAfterMethod); + RejectRequest(RequestRejectionReason.InvalidRequestLine, + Log.IsEnabled(LogLevel.Information) ? start.GetAsciiStringEscaped(end, MaxInvalidRequestLineChars) : string.Empty); } method = begin.GetAsciiString(scan); if (method == null) { - RejectRequest(RequestRejectionReason.MissingMethod); + RejectRequest(RequestRejectionReason.InvalidRequestLine, + Log.IsEnabled(LogLevel.Information) ? start.GetAsciiStringEscaped(end, MaxInvalidRequestLineChars) : string.Empty); } // Note: We're not in the fast path any more (GetKnownMethod should have handled any HTTP Method we're aware of) @@ -913,7 +919,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { if (!IsValidTokenChar(method[i])) { - RejectRequest(RequestRejectionReason.InvalidMethod); + RejectRequest(RequestRejectionReason.InvalidRequestLine, + Log.IsEnabled(LogLevel.Information) ? start.GetAsciiStringEscaped(end, MaxInvalidRequestLineChars) : string.Empty); } } } @@ -928,7 +935,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var chFound = scan.Seek(ref _vectorSpaces, ref _vectorQuestionMarks, ref _vectorPercentages, ref end); if (chFound == -1) { - RejectRequest(RequestRejectionReason.MissingSpaceAfterTarget); + RejectRequest(RequestRejectionReason.InvalidRequestLine, + Log.IsEnabled(LogLevel.Information) ? start.GetAsciiStringEscaped(end, MaxInvalidRequestLineChars) : string.Empty); } else if (chFound == '%') { @@ -936,7 +944,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http chFound = scan.Seek(ref _vectorSpaces, ref _vectorQuestionMarks, ref end); if (chFound == -1) { - RejectRequest(RequestRejectionReason.MissingSpaceAfterTarget); + RejectRequest(RequestRejectionReason.InvalidRequestLine, + Log.IsEnabled(LogLevel.Information) ? start.GetAsciiStringEscaped(end, MaxInvalidRequestLineChars) : string.Empty); } } @@ -949,7 +958,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http begin = scan; if (scan.Seek(ref _vectorSpaces, ref end) == -1) { - RejectRequest(RequestRejectionReason.MissingSpaceAfterTarget); + RejectRequest(RequestRejectionReason.InvalidRequestLine, + Log.IsEnabled(LogLevel.Information) ? start.GetAsciiStringEscaped(end, MaxInvalidRequestLineChars) : string.Empty); } queryString = begin.GetAsciiString(scan); } @@ -958,43 +968,40 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if (pathBegin.Peek() == ' ') { - RejectRequest(RequestRejectionReason.MissingRequestTarget); + RejectRequest(RequestRejectionReason.InvalidRequestLine, + Log.IsEnabled(LogLevel.Information) ? start.GetAsciiStringEscaped(end, MaxInvalidRequestLineChars) : string.Empty); } scan.Take(); begin = scan; if (scan.Seek(ref _vectorCRs, ref end) == -1) { - RejectRequest(RequestRejectionReason.MissingCrAfterVersion); + RejectRequest(RequestRejectionReason.InvalidRequestLine, + Log.IsEnabled(LogLevel.Information) ? start.GetAsciiStringEscaped(end, MaxInvalidRequestLineChars) : string.Empty); } string httpVersion; if (!begin.GetKnownVersion(out httpVersion)) { - // A slower fallback is necessary since the iterator's PeekLong() method - // used in GetKnownVersion() only examines two memory blocks at most. - // Although unlikely, it is possible that the 8 bytes forming the version - // could be spread out on more than two blocks, if the connection - // happens to be unusually slow. - httpVersion = begin.GetAsciiString(scan); + httpVersion = begin.GetAsciiStringEscaped(scan, 9); - if (httpVersion == null) + if (httpVersion == string.Empty) { - RejectRequest(RequestRejectionReason.MissingHTTPVersion); + RejectRequest(RequestRejectionReason.InvalidRequestLine, + Log.IsEnabled(LogLevel.Information) ? start.GetAsciiStringEscaped(end, MaxInvalidRequestLineChars) : string.Empty); } - else if (httpVersion != "HTTP/1.0" && httpVersion != "HTTP/1.1") + else { - RejectRequest(RequestRejectionReason.UnrecognizedHTTPVersion); + RejectRequest(RequestRejectionReason.UnrecognizedHTTPVersion, httpVersion); } } scan.Take(); // consume CR - if (scan.Block != end.Block || scan.Index != end.Index) + if (scan.Take() != '\n') { - RejectRequest(RequestRejectionReason.MissingLFInRequestLine); + RejectRequest(RequestRejectionReason.InvalidRequestLine, + Log.IsEnabled(LogLevel.Information) ? start.GetAsciiStringEscaped(end, MaxInvalidRequestLineChars) : string.Empty); } - scan.Take(); // consume LF - end = scan; // URIs are always encoded/escaped to ASCII https://tools.ietf.org/html/rfc3986#page-11 // Multibyte Internationalized Resource Identifiers (IRIs) are first converted to utf8; diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameOfT.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameOfT.cs index 203e97152c..eeba9695df 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameOfT.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameOfT.cs @@ -51,7 +51,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if (requestLineStatus != RequestLineStatus.Done) { - RejectRequest(RequestRejectionReason.MalformedRequestLineStatus, requestLineStatus.ToString()); + RejectRequest(RequestRejectionReason.InvalidRequestLine, requestLineStatus.ToString()); } break; diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/RequestRejectionReason.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/RequestRejectionReason.cs index 3bd3aecaf5..07ed7444e4 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/RequestRejectionReason.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/RequestRejectionReason.cs @@ -5,19 +5,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { public enum RequestRejectionReason { - MissingMethod, - InvalidMethod, - MissingRequestTarget, - MissingHTTPVersion, UnrecognizedHTTPVersion, - MissingLFInRequestLine, HeadersCorruptedInvalidHeaderSequence, HeaderLineMustNotStartWithWhitespace, NoColonCharacterFoundInHeaderLine, WhitespaceIsNotAllowedInHeaderName, HeaderValueMustNotContainCR, HeaderValueLineFoldingNotSupported, - MalformedRequestLineStatus, + InvalidRequestLine, MalformedRequestInvalidHeaders, InvalidContentLength, UnexpectedEndOfRequestContent, @@ -28,9 +23,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http InvalidCharactersInHeaderName, NonAsciiOrNullCharactersInInputString, RequestLineTooLong, - MissingSpaceAfterMethod, - MissingSpaceAfterTarget, - MissingCrAfterVersion, HeadersExceedMaxTotalSize, MissingCRInHeaderLine, TooManyHeaders, diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolIteratorExtensions.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolIteratorExtensions.cs index 59978837fd..146d9f127a 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolIteratorExtensions.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolIteratorExtensions.cs @@ -127,6 +127,26 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure return asciiString; } + public static string GetAsciiStringEscaped(this MemoryPoolIterator start, MemoryPoolIterator end, int maxChars) + { + var sb = new StringBuilder(); + var scan = start; + + while (maxChars > 0 && (scan.Block != end.Block || scan.Index != end.Index)) + { + var ch = scan.Take(); + sb.Append(ch < 0x20 || ch >= 0x7F ? $"<0x{ch.ToString("X2")}>" : ((char)ch).ToString()); + maxChars--; + } + + if (scan.Block != end.Block || scan.Index != end.Index) + { + sb.Append("..."); + } + + return sb.ToString(); + } + public static string GetUtf8String(this MemoryPoolIterator start, MemoryPoolIterator end) { if (start.IsDefault || end.IsDefault) diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs index a131af3e48..b411dc6b8f 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs @@ -1057,17 +1057,17 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } [Theory] - [InlineData("GET/HTTP/1.1\r\n", "No space character found after method in request line.")] - [InlineData(" / HTTP/1.1\r\n", "Missing method.")] - [InlineData("GET? / HTTP/1.1\r\n", "Invalid method.")] - [InlineData("GET /HTTP/1.1\r\n", "No space character found after target in request line.")] - [InlineData("GET /a?b=cHTTP/1.1\r\n", "No space character found after target in request line.")] - [InlineData("GET /a%20bHTTP/1.1\r\n", "No space character found after target in request line.")] - [InlineData("GET /a%20b?c=dHTTP/1.1\r\n", "No space character found after target in request line.")] - [InlineData("GET HTTP/1.1\r\n", "Missing request target.")] - [InlineData("GET / HTTP/1.1\n", "Missing CR in request line.")] - [InlineData("GET / \r\n", "Missing HTTP version.")] - [InlineData("GET / HTTP/1.1\ra\n", "Missing LF in request line.")] + [InlineData("GET/HTTP/1.1\r\n", "Invalid request line: GET/HTTP/1.1<0x0D><0x0A>")] + [InlineData(" / HTTP/1.1\r\n", "Invalid request line: / HTTP/1.1<0x0D><0x0A>")] + [InlineData("GET? / HTTP/1.1\r\n", "Invalid request line: GET? / HTTP/1.1<0x0D><0x0A>")] + [InlineData("GET /HTTP/1.1\r\n", "Invalid request line: GET /HTTP/1.1<0x0D><0x0A>")] + [InlineData("GET /a?b=cHTTP/1.1\r\n", "Invalid request line: GET /a?b=cHTTP/1.1<0x0D><0x0A>")] + [InlineData("GET /a%20bHTTP/1.1\r\n", "Invalid request line: GET /a%20bHTTP/1.1<0x0D><0x0A>")] + [InlineData("GET /a%20b?c=dHTTP/1.1\r\n", "Invalid request line: GET /a%20b?c=dHTTP/1.1<0x0D><0x0A>")] + [InlineData("GET HTTP/1.1\r\n", "Invalid request line: GET HTTP/1.1<0x0D><0x0A>")] + [InlineData("GET / HTTP/1.1\n", "Invalid request line: GET / HTTP/1.1<0x0A>")] + [InlineData("GET / \r\n", "Invalid request line: GET / <0x0D><0x0A>")] + [InlineData("GET / HTTP/1.1\ra\n", "Invalid request line: GET / HTTP/1.1<0x0D>a<0x0A>")] public void TakeStartLineThrowsWhenInvalid(string requestLine, string expectedExceptionMessage) { var trace = new KestrelTrace(new TestKestrelTrace()); @@ -1130,7 +1130,41 @@ namespace Microsoft.AspNetCore.Server.KestrelTests socketInput.IncomingData(requestLineBytes, 0, requestLineBytes.Length); var exception = Assert.Throws(() => frame.TakeStartLine(socketInput)); - Assert.Equal("Unrecognized HTTP version.", exception.Message); + Assert.Equal("Unrecognized HTTP version: HTTP/1.2", exception.Message); + Assert.Equal(505, exception.StatusCode); + } + } + + [Fact] + public void TakeStartLineThrowsOnUnsupportedHttpVersionLongerThanEigthCharacters() + { + var trace = new KestrelTrace(new TestKestrelTrace()); + var ltp = new LoggingThreadPool(trace); + using (var pool = new MemoryPool()) + using (var socketInput = new SocketInput(pool, ltp)) + { + var serviceContext = new ServiceContext + { + DateHeaderValueManager = new DateHeaderValueManager(), + ServerOptions = new KestrelServerOptions(), + Log = trace + }; + var listenerContext = new ListenerContext(serviceContext) + { + ServerAddress = ServerAddress.FromUrl("http://localhost:5000") + }; + var connectionContext = new ConnectionContext(listenerContext) + { + ConnectionControl = Mock.Of(), + }; + var frame = new Frame(application: null, context: connectionContext); + frame.Reset(); + + var requestLineBytes = Encoding.ASCII.GetBytes("GET / HTTP/1.1ab\r\n"); + socketInput.IncomingData(requestLineBytes, 0, requestLineBytes.Length); + + var exception = Assert.Throws(() => frame.TakeStartLine(socketInput)); + Assert.Equal("Unrecognized HTTP version: HTTP/1.1a...", exception.Message); Assert.Equal(505, exception.StatusCode); } } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolIteratorTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolIteratorTests.cs index dd4edd4529..ae539b10f5 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolIteratorTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolIteratorTests.cs @@ -502,6 +502,52 @@ namespace Microsoft.AspNetCore.Server.KestrelTests TestKnownStringsInterning(input, expected, MemoryPoolIteratorExtensions.GetKnownVersion); } + [Theory] + [InlineData("", "HTTP/1.1\r")] + [InlineData("H", "TTP/1.1\r")] + [InlineData("HT", "TP/1.1\r")] + [InlineData("HTT", "P/1.1\r")] + [InlineData("HTTP", "/1.1\r")] + [InlineData("HTTP/", "1.1\r")] + [InlineData("HTTP/1", ".1\r")] + [InlineData("HTTP/1.", "1\r")] + [InlineData("HTTP/1.1", "\r")] + [InlineData("HTTP/1.1\r", "")] + public void KnownVersionCanBeReadAtAnyBlockBoundary(string block1Input, string block2Input) + { + MemoryPoolBlock block1 = null; + MemoryPoolBlock block2 = null; + + try + { + // Arrange + var chars1 = block1Input.ToCharArray().Select(c => (byte)c).ToArray(); + var chars2 = block2Input.ToCharArray().Select(c => (byte)c).ToArray(); + block1 = _pool.Lease(); + block2 = _pool.Lease(); + Buffer.BlockCopy(chars1, 0, block1.Array, block1.Start, chars1.Length); + Buffer.BlockCopy(chars2, 0, block2.Array, block2.Start, chars2.Length); + block1.End += chars1.Length; + block2.End += chars2.Length; + block1.Next = block2; + var iterator = block1.GetIterator(); + + // Act + string knownVersion; + var result = iterator.GetKnownVersion(out knownVersion); + + // Assert + Assert.True(result); + Assert.Equal("HTTP/1.1", knownVersion); + } + finally + { + // Cleanup + if (block1 != null) _pool.Return(block1); + if (block2 != null) _pool.Return(block2); + } + } + [Theory] [InlineData("CONNECT / HTTP/1.1", "CONNECT")] [InlineData("DELETE / HTTP/1.1", "DELETE")] @@ -766,6 +812,39 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } } + [Theory] + [InlineData("a", "a", 1)] + [InlineData("ab", "a...", 1)] + [InlineData("abcde", "abcde", 5)] + [InlineData("abcde", "abcd...", 4)] + [InlineData("abcde", "abcde", 6)] + public void TestGetAsciiStringEscaped(string input, string expected, int maxChars) + { + MemoryPoolBlock block = null; + + try + { + // Arrange + block = _pool.Lease(); + var chars = input.ToCharArray().Select(c => (byte)c).ToArray(); + Buffer.BlockCopy(chars, 0, block.Array, block.Start, chars.Length); + block.End += chars.Length; + var start = block.GetIterator(); + var end = start; + end.Skip(input.Length); + + // Act + var result = start.GetAsciiStringEscaped(end, maxChars); + + // Assert + Assert.Equal(expected, result); + } + finally + { + if (block != null) _pool.Return(block); + } + } + private delegate bool GetKnownString(MemoryPoolIterator iter, out string result); private void TestKnownStringsInterning(string input, string expected, GetKnownString action) From 91497621c9c34f258f3734da0738555cebc78bca Mon Sep 17 00:00:00 2001 From: Pranav K Date: Wed, 28 Sep 2016 11:51:09 -0700 Subject: [PATCH 0903/1662] Updating partner package versions --- samples/LargeResponseApp/project.json | 2 +- samples/SampleApp/project.json | 5 ++-- .../project.json | 5 ++-- .../project.json | 26 +++++-------------- .../project.json | 9 +++---- .../project.json | 11 +++----- .../project.json | 6 ++--- 7 files changed, 23 insertions(+), 41 deletions(-) diff --git a/samples/LargeResponseApp/project.json b/samples/LargeResponseApp/project.json index 1483d74322..886ce0d4aa 100644 --- a/samples/LargeResponseApp/project.json +++ b/samples/LargeResponseApp/project.json @@ -11,7 +11,7 @@ "netcoreapp1.0": { "dependencies": { "Microsoft.NETCore.App": { - "version": "1.0.0-*", + "version": "1.1.0-*", "type": "platform" } } diff --git a/samples/SampleApp/project.json b/samples/SampleApp/project.json index 77e80450f2..73d36ceffa 100644 --- a/samples/SampleApp/project.json +++ b/samples/SampleApp/project.json @@ -13,10 +13,9 @@ "netcoreapp1.0": { "dependencies": { "Microsoft.NETCore.App": { - "version": "1.0.0-*", + "version": "1.1.0-*", "type": "platform" - }, - "System.Console": "4.0.0-*" + } } } }, diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Https/project.json b/src/Microsoft.AspNetCore.Server.Kestrel.Https/project.json index 9300fd626a..5c23958fbd 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Https/project.json +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Https/project.json @@ -24,13 +24,14 @@ "Microsoft.Extensions.TaskCache.Sources": { "version": "1.1.0-*", "type": "build" - } + }, + "NETStandard.Library": "1.6.1-*" }, "frameworks": { "net451": {}, "netstandard1.3": { "dependencies": { - "System.Net.Security": "4.0.0-*" + "System.Net.Security": "4.3.0-*" } } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/project.json b/src/Microsoft.AspNetCore.Server.Kestrel/project.json index 6305b879f8..d523f7e261 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/project.json +++ b/src/Microsoft.AspNetCore.Server.Kestrel/project.json @@ -12,17 +12,17 @@ ] }, "dependencies": { - "System.Buffers": "4.0.0-*", - "System.Numerics.Vectors": "4.1.1-*", - "System.Runtime.InteropServices.RuntimeInformation": "4.0.0-*", - "System.Threading.Tasks.Extensions": "4.0.0-*", "Libuv": "1.9.0-*", "Microsoft.AspNetCore.Hosting": "1.1.0-*", "Microsoft.Extensions.Logging.Abstractions": "1.1.0-*", "Microsoft.Extensions.TaskCache.Sources": { "version": "1.1.0-*", "type": "build" - } + }, + "NETStandard.Library": "1.6.1-*", + "System.Buffers": "4.3.0-*", + "System.Numerics.Vectors": "4.3.0-*", + "System.Threading.Tasks.Extensions": "4.3.0-*" }, "frameworks": { "net451": { @@ -37,20 +37,8 @@ }, "netstandard1.3": { "dependencies": { - "System.Collections": "4.0.11-*", - "System.Diagnostics.Debug": "4.0.11-*", - "System.Globalization": "4.0.11-*", - "System.IO": "4.1.0-*", - "System.Linq": "4.1.0-*", - "System.Net.Primitives": "4.0.11-*", - "System.Runtime.Extensions": "4.1.0-*", - "System.Runtime.InteropServices": "4.1.0-*", - "System.Text.Encoding": "4.0.11-*", - "System.Threading": "4.0.11-*", - "System.Threading.Tasks": "4.0.11-*", - "System.Threading.Thread": "4.0.0-*", - "System.Threading.ThreadPool": "4.0.10-*", - "System.Threading.Timer": "4.0.1-*" + "System.Threading.Thread": "4.3.0-*", + "System.Threading.ThreadPool": "4.3.0-*" } } }, diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json index a1e32897e4..857860ce59 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json @@ -15,13 +15,12 @@ "netcoreapp1.0": { "dependencies": { "Microsoft.NETCore.App": { - "version": "1.0.0-*", + "version": "1.1.0-*", "type": "platform" }, - "System.Net.Http": "4.1.0-*", - "System.Net.Http.WinHttpHandler": "4.0.0-*", - "System.Net.NetworkInformation": "4.1.0-*", - "System.Runtime.Serialization.Primitives": "4.1.1-*" + "System.Net.Http.WinHttpHandler": "4.3.0-*", + "System.Net.NetworkInformation": "4.3.0-*", + "System.Runtime.Serialization.Primitives": "4.3.0-*" } }, "net451": { diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/project.json b/test/Microsoft.AspNetCore.Server.KestrelTests/project.json index 1584bc0e99..38aaafbfe8 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/project.json +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/project.json @@ -12,16 +12,11 @@ "netcoreapp1.0": { "dependencies": { "Microsoft.NETCore.App": { - "version": "1.0.0-*", + "version": "1.1.0-*", "type": "platform" }, - "System.Diagnostics.TraceSource": "4.0.0-*", - "System.Globalization.Extensions": "4.0.1-*", - "System.IO": "4.1.0-*", - "System.Net.Http": "4.1.0-*", - "System.Net.Http.WinHttpHandler": "4.0.0-*", - "System.Net.Sockets": "4.1.0-*", - "System.Runtime.Handles": "4.0.1-*" + "System.Diagnostics.TraceSource": "4.3.0-*", + "System.Net.Http.WinHttpHandler": "4.3.0-*" } }, "net451": { diff --git a/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/project.json b/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/project.json index 81b8fc282a..950691be17 100644 --- a/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/project.json +++ b/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/project.json @@ -4,14 +4,14 @@ "emitEntryPoint": true }, "dependencies": { - "Microsoft.AspNetCore.Http.Features": "1.1.0-*", - "Microsoft.AspNetCore.Hosting": "1.1.0-*" + "Microsoft.AspNetCore.Hosting": "1.1.0-*", + "Microsoft.AspNetCore.Http.Features": "1.1.0-*" }, "frameworks": { "netcoreapp1.0": { "dependencies": { "Microsoft.NETCore.App": { - "version": "1.0.0-*", + "version": "1.1.0-*", "type": "platform" } } From f1f66448f484d99dd1edd816c92b50f6e2090ef5 Mon Sep 17 00:00:00 2001 From: Pranav K Date: Wed, 5 Oct 2016 12:02:23 -0700 Subject: [PATCH 0904/1662] Revert to Microsoft.NETCore.App to 1.0.0 --- .../project.json | 2 +- test/Microsoft.AspNetCore.Server.KestrelTests/project.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json index 857860ce59..72a9016507 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json @@ -15,7 +15,7 @@ "netcoreapp1.0": { "dependencies": { "Microsoft.NETCore.App": { - "version": "1.1.0-*", + "version": "1.0.0", "type": "platform" }, "System.Net.Http.WinHttpHandler": "4.3.0-*", diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/project.json b/test/Microsoft.AspNetCore.Server.KestrelTests/project.json index 38aaafbfe8..1dacc0516a 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/project.json +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/project.json @@ -12,7 +12,7 @@ "netcoreapp1.0": { "dependencies": { "Microsoft.NETCore.App": { - "version": "1.1.0-*", + "version": "1.0.0", "type": "platform" }, "System.Diagnostics.TraceSource": "4.3.0-*", From 2708b8a5347d150c47ef0928659e02511acbb635 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Wed, 5 Oct 2016 21:42:31 +0100 Subject: [PATCH 0905/1662] Add CodeCoverage to tests --- .../project.json | 12 +++++++++--- .../project.json | 12 +++++++++--- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json index 72a9016507..1e756c894d 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json @@ -9,7 +9,11 @@ "Microsoft.Extensions.Logging.Testing": "1.1.0-*", "Moq": "4.6.36-*", "Newtonsoft.Json": "9.0.1", - "xunit": "2.2.0-*" + "xunit": "2.2.0-*", + "Microsoft.CodeCoverage": { + "type": "build", + "version": "1.0.1" + } }, "frameworks": { "netcoreapp1.0": { @@ -21,12 +25,14 @@ "System.Net.Http.WinHttpHandler": "4.3.0-*", "System.Net.NetworkInformation": "4.3.0-*", "System.Runtime.Serialization.Primitives": "4.3.0-*" - } + }, + "imports": "dnxcore50" }, "net451": { "frameworkAssemblies": { "System.Net.Http": "4.0.0.0" - } + }, + "imports": "dnx451" } }, "buildOptions": { diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/project.json b/test/Microsoft.AspNetCore.Server.KestrelTests/project.json index 1dacc0516a..7d6403ffcf 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/project.json +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/project.json @@ -6,7 +6,11 @@ "Microsoft.AspNetCore.Server.Kestrel.Https": "1.1.0-*", "Microsoft.AspNetCore.Testing": "1.1.0-*", "Moq": "4.6.36-*", - "xunit": "2.2.0-*" + "xunit": "2.2.0-*", + "Microsoft.CodeCoverage": { + "type": "build", + "version": "1.0.1" + } }, "frameworks": { "netcoreapp1.0": { @@ -17,12 +21,14 @@ }, "System.Diagnostics.TraceSource": "4.3.0-*", "System.Net.Http.WinHttpHandler": "4.3.0-*" - } + }, + "imports": "dnxcore50" }, "net451": { "frameworkAssemblies": { "System.Net.Http": "4.0.0.0" - } + }, + "imports": "dnx451" } }, "buildOptions": { From 2c94884da9a2bd7943e425105435596166508589 Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Mon, 3 Oct 2016 15:12:47 -0700 Subject: [PATCH 0906/1662] Include address in error message when address already in use (#1086). --- .../KestrelServer.cs | 46 +++++++++-------- .../AddressRegistrationTests.cs | 50 ++++++++++++++++++- 2 files changed, 74 insertions(+), 22 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServer.cs b/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServer.cs index 0bf4baf9c9..d9844714de 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServer.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServer.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; +using System.IO; using System.Linq; using System.Reflection; using Microsoft.AspNetCore.Hosting; @@ -109,8 +110,19 @@ namespace Microsoft.AspNetCore.Server.Kestrel if (!parsedAddress.Host.Equals("localhost", StringComparison.OrdinalIgnoreCase)) { - _disposables.Push(engine.CreateServer( - parsedAddress)); + try + { + _disposables.Push(engine.CreateServer(parsedAddress)); + } + catch (AggregateException ex) + { + if ((ex.InnerException as UvException)?.StatusCode == Constants.EADDRINUSE) + { + throw new IOException($"Failed to bind to address {parsedAddress}: address already in use.", ex); + } + + throw; + } } else { @@ -120,24 +132,22 @@ namespace Microsoft.AspNetCore.Server.Kestrel } var ipv4Address = parsedAddress.WithHost("127.0.0.1"); - var exceptions = new List(); + var exceptions = new List(); try { _disposables.Push(engine.CreateServer(ipv4Address)); } - catch (AggregateException ex) + catch (AggregateException ex) when (ex.InnerException is UvException) { - var uvException = ex.InnerException as UvException; - - if (uvException != null && uvException.StatusCode != Constants.EADDRINUSE) + if ((ex.InnerException as UvException).StatusCode == Constants.EADDRINUSE) { - _logger.LogWarning(0, ex, $"Unable to bind to {parsedAddress.ToString()} on the IPv4 loopback interface."); - exceptions.Add(uvException); + throw new IOException($"Failed to bind to address {parsedAddress.ToString()} on the IPv4 loopback interface: port already in use.", ex); } else { - throw; + _logger.LogWarning(0, ex, $"Unable to bind to {parsedAddress.ToString()} on the IPv4 loopback interface."); + exceptions.Add(ex.InnerException); } } @@ -147,26 +157,22 @@ namespace Microsoft.AspNetCore.Server.Kestrel { _disposables.Push(engine.CreateServer(ipv6Address)); } - catch (AggregateException ex) + catch (AggregateException ex) when (ex.InnerException is UvException) { - var uvException = ex.InnerException as UvException; - - if (uvException != null && uvException.StatusCode != Constants.EADDRINUSE) + if ((ex.InnerException as UvException).StatusCode == Constants.EADDRINUSE) { - _logger.LogWarning(0, ex, $"Unable to bind to {parsedAddress.ToString()} on the IPv6 loopback interface."); - exceptions.Add(uvException); + throw new IOException($"Failed to bind to address {parsedAddress.ToString()} on the IPv6 loopback interface: port already in use.", ex); } else { - throw; + _logger.LogWarning(0, ex, $"Unable to bind to {parsedAddress.ToString()} on the IPv6 loopback interface."); + exceptions.Add(ex.InnerException); } } if (exceptions.Count == 2) { - var ex = new AggregateException(exceptions); - _logger.LogError(0, ex, $"Unable to bind to {parsedAddress.ToString()} on any loopback interface."); - throw ex; + throw new IOException($"Failed to bind to address {parsedAddress.ToString()}.", new AggregateException(exceptions)); } } diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs index a438309246..be37bf0674 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; +using System.IO; using System.Linq; using System.Net; using System.Net.NetworkInformation; @@ -97,6 +98,49 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } } + [Fact] + public void ThrowsWhenBindingToIPv4AddressInUse() + { + using (var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)) + { + var port = GetNextPort(); + socket.Bind(new IPEndPoint(IPAddress.Loopback, port)); + + var hostBuilder = new WebHostBuilder() + .UseKestrel() + .UseUrls($"http://127.0.0.1:{port}") + .Configure(ConfigureEchoAddress); + + using (var host = hostBuilder.Build()) + { + var exception = Assert.Throws(() => host.Start()); + Assert.Equal($"Failed to bind to address http://127.0.0.1:{port}: address already in use.", exception.Message); + } + } + } + + [ConditionalFact] + [IPv6SupportedCondition] + public void ThrowsWhenBindingToIPv6AddressInUse() + { + using (var socket = new Socket(AddressFamily.InterNetworkV6, SocketType.Stream, ProtocolType.Tcp)) + { + var port = GetNextPort(); + socket.Bind(new IPEndPoint(IPAddress.IPv6Loopback, port)); + + var hostBuilder = new WebHostBuilder() + .UseKestrel() + .UseUrls($"http://[::1]:{port}") + .Configure(ConfigureEchoAddress); + + using (var host = hostBuilder.Build()) + { + var exception = Assert.Throws(() => host.Start()); + Assert.Equal($"Failed to bind to address http://[::1]:{port}: address already in use.", exception.Message); + } + } + } + [Fact] public void ThrowsWhenBindingLocalhostToIPv4AddressInUse() { @@ -138,8 +182,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests using (var host = hostBuilder.Build()) { - var exception = Assert.Throws(() => host.Start()); - Assert.Contains(exception.InnerExceptions, ex => ex is UvException); + var exception = Assert.Throws(() => host.Start()); + Assert.Equal( + $"Failed to bind to address http://localhost:{port} on the {(addressFamily == AddressFamily.InterNetwork ? "IPv4" : "IPv6")} loopback interface: port already in use.", + exception.Message); } } } From 03f8a7a21723c6169003d8cf0ecd78530e9c1cb2 Mon Sep 17 00:00:00 2001 From: Kristian Hellang Date: Thu, 6 Oct 2016 20:56:49 +0200 Subject: [PATCH 0907/1662] Use HeaderUtilities.FormatDate in DateHeaderValueManager (#1132) --- .../Internal/Http/DateHeaderValueManager.cs | 4 ++-- .../Internal/Infrastructure/Constants.cs | 6 ----- .../DateHeaderValueManagerTests.cs | 23 ++++++++++++------- 3 files changed, 17 insertions(+), 16 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/DateHeaderValueManager.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/DateHeaderValueManager.cs index b5fc6730e6..b824fb606d 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/DateHeaderValueManager.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/DateHeaderValueManager.cs @@ -5,6 +5,7 @@ using System; using System.Text; using System.Threading; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; +using Microsoft.Net.Http.Headers; namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { @@ -170,8 +171,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http /// A DateTimeOffset value private void SetDateValues(DateTimeOffset value) { - // See http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.18 for required format of Date header - var dateValue = value.ToString(Constants.RFC1123DateFormat); + var dateValue = HeaderUtilities.FormatDate(value); var dateBytes = new byte[_datePreambleBytes.Length + dateValue.Length]; Buffer.BlockCopy(_datePreambleBytes, 0, dateBytes, 0, _datePreambleBytes.Length); Encoding.ASCII.GetBytes(dateValue, 0, dateValue.Length, dateBytes, _datePreambleBytes.Length); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/Constants.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/Constants.cs index 90f228de31..ddc9f767b9 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/Constants.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/Constants.cs @@ -17,12 +17,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure /// public const string UnixPipeHostPrefix = "unix:/"; - /// - /// DateTime format string for RFC1123. See https://msdn.microsoft.com/en-us/library/az4se3k1(v=vs.110).aspx#RFC1123 - /// for info on the format. - /// - public const string RFC1123DateFormat = "r"; - public const string ServerName = "Kestrel"; private static int? GetEADDRINUSE() diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/DateHeaderValueManagerTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/DateHeaderValueManagerTests.cs index ddfce0d3a6..8e9802600b 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/DateHeaderValueManagerTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/DateHeaderValueManagerTests.cs @@ -4,7 +4,6 @@ using System; using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.AspNetCore.Testing; using Xunit; @@ -12,6 +11,14 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { public class DateHeaderValueManagerTests { + /// + /// DateTime format string for RFC1123. + /// + /// + /// See https://msdn.microsoft.com/en-us/library/az4se3k1(v=vs.110).aspx#RFC1123 for info on the format. + /// + private const string Rfc1123DateFormat = "r"; + [Fact] public void GetDateHeaderValue_ReturnsDateValueInRFC1123Format() { @@ -34,7 +41,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests dateHeaderValueManager.Dispose(); } - Assert.Equal(now.ToString(Constants.RFC1123DateFormat), result); + Assert.Equal(now.ToString(Rfc1123DateFormat), result); } [Fact] @@ -63,8 +70,8 @@ namespace Microsoft.AspNetCore.Server.KestrelTests dateHeaderValueManager.Dispose(); } - Assert.Equal(now.ToString(Constants.RFC1123DateFormat), result1); - Assert.Equal(now.ToString(Constants.RFC1123DateFormat), result2); + Assert.Equal(now.ToString(Rfc1123DateFormat), result1); + Assert.Equal(now.ToString(Rfc1123DateFormat), result2); Assert.Equal(1, systemClock.UtcNowCalled); } @@ -96,8 +103,8 @@ namespace Microsoft.AspNetCore.Server.KestrelTests dateHeaderValueManager.Dispose(); } - Assert.Equal(now.ToString(Constants.RFC1123DateFormat), result1); - Assert.Equal(future.ToString(Constants.RFC1123DateFormat), result2); + Assert.Equal(now.ToString(Rfc1123DateFormat), result1); + Assert.Equal(future.ToString(Rfc1123DateFormat), result2); Assert.True(systemClock.UtcNowCalled >= 2); } @@ -119,8 +126,8 @@ namespace Microsoft.AspNetCore.Server.KestrelTests systemClock.UtcNow = future; var result2 = dateHeaderValueManager.GetDateHeaderValues().String; - Assert.Equal(now.ToString(Constants.RFC1123DateFormat), result1); - Assert.Equal(future.ToString(Constants.RFC1123DateFormat), result2); + Assert.Equal(now.ToString(Rfc1123DateFormat), result1); + Assert.Equal(future.ToString(Rfc1123DateFormat), result2); } } } From adc3e63ecca020b7a05996f85071ad7061c33cce Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Sat, 8 Oct 2016 05:11:22 +0100 Subject: [PATCH 0908/1662] Improve callstack for LoggingThreadPool --- .../Infrastructure/LoggingThreadPool.cs | 25 ++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/LoggingThreadPool.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/LoggingThreadPool.cs index bbbac1b6f7..1cc2f52491 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/LoggingThreadPool.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/LoggingThreadPool.cs @@ -12,15 +12,26 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure { private readonly IKestrelTrace _log; - private readonly WaitCallback _runAction; - private readonly WaitCallback _cancelTcs; - private readonly WaitCallback _completeTcs; + private WaitCallback _runAction; + private WaitCallback _cancelTcs; + private WaitCallback _completeTcs; public LoggingThreadPool(IKestrelTrace log) { _log = log; // Curry and capture log in closures once + // The currying is done in functions of the same name to improve the + // call stack for exceptions and profiling else it shows up as LoggingThreadPool.ctor>b__4_0 + // and you aren't sure which of the 3 functions was called. + RunAction(); + CompleteTcs(); + CancelTcs(); + } + + private void RunAction() + { + // Capture _log in a singleton closure _runAction = (o) => { try @@ -32,7 +43,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure _log.LogError(0, e, "LoggingThreadPool.Run"); } }; + } + private void CompleteTcs() + { + // Capture _log in a singleton closure _completeTcs = (o) => { try @@ -44,7 +59,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure _log.LogError(0, e, "LoggingThreadPool.Complete"); } }; + } + private void CancelTcs() + { + // Capture _log in a singleton closure _cancelTcs = (o) => { try From 3177ba0aaeb775e8347ebdc103b12c37f5e6cf44 Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Mon, 10 Oct 2016 10:16:03 -0700 Subject: [PATCH 0909/1662] Wait for frame loop completion to dispose connection stream (#1156). --- .../Internal/Http/Connection.cs | 4 +- .../Internal/Http/Frame.cs | 4 +- .../HttpsTests.cs | 50 ++++++++++++++++++- .../FrameTests.cs | 42 +++++++++++++++- 4 files changed, 94 insertions(+), 6 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Connection.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Connection.cs index 2ba693ef73..9c9e225a9f 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Connection.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Connection.cs @@ -135,7 +135,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http public Task StopAsync() { - _frame.Stop(); + _frame.StopAsync(); _frame.SocketInput.CompleteAwaiting(); return _socketClosedTcs.Task; @@ -156,7 +156,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { if (_filteredStreamAdapter != null) { - _readInputTask.ContinueWith((task, state) => + Task.WhenAll(_readInputTask, _frame.StopAsync()).ContinueWith((task, state) => { var connection = (Connection)state; connection._filterContext.Connection.Dispose(); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs index 9a13ab2cb7..f85940605c 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs @@ -365,7 +365,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http this, default(CancellationToken), TaskCreationOptions.DenyChildAttach, - TaskScheduler.Default); + TaskScheduler.Default).Unwrap(); } /// @@ -374,7 +374,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http /// Stop will be called on all active connections, and Task.WaitAll() will be called on every /// return value. /// - public Task Stop() + public Task StopAsync() { if (!_requestProcessingStopping) { diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/HttpsTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/HttpsTests.cs index 716c71e7b0..8f3a624406 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/HttpsTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/HttpsTests.cs @@ -105,7 +105,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { try { - await httpContext.Response.WriteAsync($"hello, world\r\r", ct); + await httpContext.Response.WriteAsync($"hello, world", ct); await Task.Delay(1000, ct); } catch (TaskCanceledException) @@ -136,6 +136,54 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests Assert.False(loggerFactory.ErrorLogger.ObjectDisposedExceptionLogged); } + [Fact] + public async Task DoesNotThrowObjectDisposedExceptionFromWriteAsyncAfterConnectionIsAborted() + { + var tcs = new TaskCompletionSource(); + var x509Certificate2 = new X509Certificate2(@"TestResources/testCert.pfx", "testPassword"); + var loggerFactory = new HandshakeErrorLoggerFactory(); + var hostBuilder = new WebHostBuilder() + .UseKestrel(options => + { + options.UseHttps(@"TestResources/testCert.pfx", "testPassword"); + }) + .UseUrls("https://127.0.0.1:0/") + .UseLoggerFactory(loggerFactory) + .Configure(app => app.Run(async httpContext => + { + httpContext.Abort(); + try + { + await httpContext.Response.WriteAsync($"hello, world"); + tcs.SetResult(null); + } + catch (Exception ex) + { + tcs.SetException(ex); + } + })); + + using (var host = hostBuilder.Build()) + { + host.Start(); + + using (var socket = await HttpClientSlim.GetSocket(new Uri($"https://127.0.0.1:{host.GetPort()}/"))) + using (var stream = new NetworkStream(socket, ownsSocket: false)) + using (var sslStream = new SslStream(stream, true, (sender, certificate, chain, errors) => true)) + { + await sslStream.AuthenticateAsClientAsync("127.0.0.1", clientCertificates: null, + enabledSslProtocols: SslProtocols.Tls11 | SslProtocols.Tls12, + checkCertificateRevocation: false); + + var request = Encoding.ASCII.GetBytes("GET / HTTP/1.1\r\n\r\n"); + await sslStream.WriteAsync(request, 0, request.Length); + await sslStream.ReadAsync(new byte[32], 0, 32); + } + } + + await tcs.Task.TimeoutAfter(TimeSpan.FromSeconds(10)); + } + private class HandshakeErrorLoggerFactory : ILoggerFactory { public HttpsConnectionFilterLogger FilterLogger { get; } = new HttpsConnectionFilterLogger(); diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs index b411dc6b8f..be5c3e9348 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs @@ -6,6 +6,8 @@ using System.IO; using System.Text; using System.Threading; using System.Threading.Tasks; +using Microsoft.AspNetCore.Hosting.Server; +using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Server.Kestrel; using Microsoft.AspNetCore.Server.Kestrel.Internal; @@ -1290,7 +1292,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var expectedKeepAliveTimeout = (long)serviceContext.ServerOptions.Limits.KeepAliveTimeout.TotalMilliseconds; connectionControl.Verify(cc => cc.SetTimeout(expectedKeepAliveTimeout, TimeoutAction.CloseConnection)); - frame.Stop(); + frame.StopAsync(); socketInput.IncomingFin(); requestProcessingTask.Wait(); @@ -1464,5 +1466,43 @@ namespace Microsoft.AspNetCore.Server.KestrelTests // Assert Assert.Throws(() => frame.Flush()); } + + [Fact] + public async Task RequestProcessingTaskIsUnwrapped() + { + var trace = new KestrelTrace(new TestKestrelTrace()); + var ltp = new LoggingThreadPool(trace); + using (var pool = new MemoryPool()) + using (var socketInput = new SocketInput(pool, ltp)) + { + var serviceContext = new ServiceContext + { + DateHeaderValueManager = new DateHeaderValueManager(), + ServerOptions = new KestrelServerOptions(), + Log = trace + }; + var listenerContext = new ListenerContext(serviceContext) + { + ServerAddress = ServerAddress.FromUrl("http://localhost:5000") + }; + var connectionContext = new ConnectionContext(listenerContext) + { + ConnectionControl = Mock.Of(), + SocketInput = socketInput + }; + + var frame = new Frame(application: null, context: connectionContext); + frame.Start(); + + var data = Encoding.ASCII.GetBytes("GET / HTTP/1.1\r\n\r\n"); + socketInput.IncomingData(data, 0, data.Length); + + var requestProcessingTask = frame.StopAsync(); + Assert.IsNotType(typeof(Task), requestProcessingTask); + + await requestProcessingTask.TimeoutAfter(TimeSpan.FromSeconds(10)); + socketInput.IncomingFin(); + } + } } } From 8c103f0f23691d8ac10ccbf15436e36bb2715562 Mon Sep 17 00:00:00 2001 From: Pranav K Date: Mon, 10 Oct 2016 19:23:37 -0700 Subject: [PATCH 0910/1662] Revert "Revert to Microsoft.NETCore.App to 1.0.0" This reverts commit f1f66448f484d99dd1edd816c92b50f6e2090ef5. --- .../project.json | 2 +- test/Microsoft.AspNetCore.Server.KestrelTests/project.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json index 1e756c894d..beabf3d299 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json @@ -19,7 +19,7 @@ "netcoreapp1.0": { "dependencies": { "Microsoft.NETCore.App": { - "version": "1.0.0", + "version": "1.1.0-*", "type": "platform" }, "System.Net.Http.WinHttpHandler": "4.3.0-*", diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/project.json b/test/Microsoft.AspNetCore.Server.KestrelTests/project.json index 7d6403ffcf..6fdb968ff2 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/project.json +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/project.json @@ -16,7 +16,7 @@ "netcoreapp1.0": { "dependencies": { "Microsoft.NETCore.App": { - "version": "1.0.0", + "version": "1.1.0-*", "type": "platform" }, "System.Diagnostics.TraceSource": "4.3.0-*", From f8813a600df30e018a6224048b31244be3d456b9 Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Fri, 7 Oct 2016 10:23:07 -0700 Subject: [PATCH 0911/1662] Handle response content length mismatches (#175). --- .../Internal/Http/Frame.cs | 27 +- .../Internal/Http/FrameHeaders.Generated.cs | 6 + .../Internal/Http/FrameHeaders.cs | 13 + .../Internal/Http/FrameOfT.cs | 10 + .../Internal/Http/FrameResponseHeaders.cs | 4 + .../Internal/Infrastructure/IKestrelTrace.cs | 2 +- .../Internal/Infrastructure/KestrelTrace.cs | 6 +- .../ResponseTests.cs | 286 +++++++++++++++++- .../EngineTests.cs | 71 ++--- .../FrameResponseHeadersTests.cs | 93 +++++- test/shared/TestApplicationErrorLogger.cs | 30 +- test/shared/TestKestrelTrace.cs | 10 - .../KnownHeaders.cs | 22 +- 13 files changed, 482 insertions(+), 98 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs index f85940605c..8312e88bef 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using System.Diagnostics; +using System.Globalization; using System.IO; using System.Linq; using System.Net; @@ -75,7 +76,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http protected readonly long _keepAliveMilliseconds; private readonly long _requestHeadersTimeoutMilliseconds; - private int _responseBytesWritten; + protected long _responseBytesWritten; public Frame(ConnectionContext context) { @@ -516,8 +517,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http public void Write(ArraySegment data) { + VerifyAndUpdateWrite(data.Count); ProduceStartAndFireOnStarting().GetAwaiter().GetResult(); - _responseBytesWritten += data.Count; if (_canHaveBody) { @@ -547,7 +548,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http return WriteAsyncAwaited(data, cancellationToken); } - _responseBytesWritten += data.Count; + VerifyAndUpdateWrite(data.Count); if (_canHaveBody) { @@ -573,8 +574,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http public async Task WriteAsyncAwaited(ArraySegment data, CancellationToken cancellationToken) { + VerifyAndUpdateWrite(data.Count); + await ProduceStartAndFireOnStarting(); - _responseBytesWritten += data.Count; if (_canHaveBody) { @@ -598,6 +600,23 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } } + private void VerifyAndUpdateWrite(int count) + { + var responseHeaders = FrameResponseHeaders; + + if (responseHeaders != null && + !responseHeaders.HasTransferEncoding && + responseHeaders.HasContentLength && + _responseBytesWritten + count > responseHeaders.HeaderContentLengthValue.Value) + { + _keepAlive = false; + throw new InvalidOperationException( + $"Response Content-Length mismatch: too many bytes written ({_responseBytesWritten + count} of {responseHeaders.HeaderContentLengthValue.Value})."); + } + + _responseBytesWritten += count; + } + private void WriteChunked(ArraySegment data) { SocketOutput.Write(data, chunk: true); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameHeaders.Generated.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameHeaders.Generated.cs index d37c1c8cb6..88fa8d6ac7 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameHeaders.Generated.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameHeaders.Generated.cs @@ -3697,6 +3697,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { _bits = 0; _headers = default(HeaderReferences); + MaybeUnknown?.Clear(); } @@ -5670,6 +5671,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } set { + _contentLength = ParseContentLength(value); _bits |= 2048L; _headers._ContentLength = value; _headers._rawContentLength = null; @@ -7384,6 +7386,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { if ("Content-Length".Equals(key, StringComparison.OrdinalIgnoreCase)) { + _contentLength = ParseContentLength(value); _bits |= 2048L; _headers._ContentLength = value; _headers._rawContentLength = null; @@ -7809,6 +7812,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { ThrowDuplicateKeyException(); } + _contentLength = ParseContentLength(value); _bits |= 2048L; _headers._ContentLength = value; _headers._rawContentLength = null; @@ -8350,6 +8354,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { if (((_bits & 2048L) != 0)) { + _contentLength = null; _bits &= ~2048L; _headers._ContentLength = StringValues.Empty; _headers._rawContentLength = null; @@ -8601,6 +8606,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { _bits = 0; _headers = default(HeaderReferences); + _contentLength = null; MaybeUnknown?.Clear(); } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameHeaders.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameHeaders.cs index ac283a006c..c6b9d0c59d 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameHeaders.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameHeaders.cs @@ -4,6 +4,7 @@ using System; using System.Collections; using System.Collections.Generic; +using System.Globalization; using System.Linq; using Microsoft.AspNetCore.Http; using Microsoft.Extensions.Primitives; @@ -232,6 +233,18 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } } + public static long ParseContentLength(StringValues value) + { + try + { + return long.Parse(value, NumberStyles.AllowLeadingWhite | NumberStyles.AllowTrailingWhite, CultureInfo.InvariantCulture); + } + catch (FormatException ex) + { + throw new InvalidOperationException("Content-Length value must be an integral number.", ex); + } + } + private static void ThrowInvalidHeaderCharacter(char ch) { throw new InvalidOperationException(string.Format("Invalid non-ASCII or control character in header: 0x{0:X4}", (ushort)ch)); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameOfT.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameOfT.cs index eeba9695df..5fc2a56d2f 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameOfT.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameOfT.cs @@ -92,6 +92,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http try { await _application.ProcessRequestAsync(context).ConfigureAwait(false); + + var responseHeaders = FrameResponseHeaders; + if (!responseHeaders.HasTransferEncoding && + responseHeaders.HasContentLength && + _responseBytesWritten < responseHeaders.HeaderContentLengthValue.Value) + { + _keepAlive = false; + ReportApplicationError(new InvalidOperationException( + $"Response Content-Length mismatch: too few bytes written ({_responseBytesWritten} of {responseHeaders.HeaderContentLengthValue.Value}).")); + } } catch (Exception ex) { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameResponseHeaders.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameResponseHeaders.cs index 9ea8056f27..ccb5e0d463 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameResponseHeaders.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameResponseHeaders.cs @@ -13,6 +13,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http private static readonly byte[] _CrLf = new[] { (byte)'\r', (byte)'\n' }; private static readonly byte[] _colonSpace = new[] { (byte)':', (byte)' ' }; + private long? _contentLength; + public bool HasConnection => HeaderConnection.Count != 0; public bool HasTransferEncoding => HeaderTransferEncoding.Count != 0; @@ -23,6 +25,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http public bool HasDate => HeaderDate.Count != 0; + public long? HeaderContentLengthValue => _contentLength; + public Enumerator GetEnumerator() { return new Enumerator(this); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/IKestrelTrace.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/IKestrelTrace.cs index 900adc8766..2be2acbfc3 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/IKestrelTrace.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/IKestrelTrace.cs @@ -33,7 +33,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure void ConnectionDisconnectedWrite(string connectionId, int count, Exception ex); - void ConnectionHeadResponseBodyWrite(string connectionId, int count); + void ConnectionHeadResponseBodyWrite(string connectionId, long count); void ConnectionBadRequest(string connectionId, BadHttpRequestException ex); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/KestrelTrace.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/KestrelTrace.cs index 5d3ecff7bd..fcdc3f9208 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/KestrelTrace.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/KestrelTrace.cs @@ -24,7 +24,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal private static readonly Action _applicationError; private static readonly Action _connectionError; private static readonly Action _connectionDisconnectedWrite; - private static readonly Action _connectionHeadResponseBodyWrite; + private static readonly Action _connectionHeadResponseBodyWrite; private static readonly Action _notAllConnectionsClosedGracefully; private static readonly Action _connectionBadRequest; @@ -49,7 +49,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal _connectionDisconnectedWrite = LoggerMessage.Define(LogLevel.Debug, 15, @"Connection id ""{ConnectionId}"" write of ""{count}"" bytes to disconnected client."); _notAllConnectionsClosedGracefully = LoggerMessage.Define(LogLevel.Debug, 16, "Some connections failed to close gracefully during server shutdown."); _connectionBadRequest = LoggerMessage.Define(LogLevel.Information, 17, @"Connection id ""{ConnectionId}"" bad request data: ""{message}"""); - _connectionHeadResponseBodyWrite = LoggerMessage.Define(LogLevel.Debug, 18, @"Connection id ""{ConnectionId}"" write of ""{count}"" body bytes to non-body HEAD response."); + _connectionHeadResponseBodyWrite = LoggerMessage.Define(LogLevel.Debug, 18, @"Connection id ""{ConnectionId}"" write of ""{count}"" body bytes to non-body HEAD response."); } public KestrelTrace(ILogger logger) @@ -135,7 +135,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal _connectionDisconnectedWrite(_logger, connectionId, count, ex); } - public virtual void ConnectionHeadResponseBodyWrite(string connectionId, int count) + public virtual void ConnectionHeadResponseBodyWrite(string connectionId, long count) { _connectionHeadResponseBodyWrite(_logger, connectionId, count, null); } diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs index bcd2e7ecfd..57e753d071 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.IO; using System.Linq; using System.Net; using System.Net.Http; @@ -14,6 +15,7 @@ using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.AspNetCore.Testing; using Microsoft.Extensions.Internal; +using Microsoft.Extensions.Logging; using Microsoft.Extensions.Primitives; using Moq; using Xunit; @@ -85,7 +87,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests app.Run(async context => { context.Response.Headers.Add(headerName, headerValue); - + await context.Response.WriteAsync(""); }); }); @@ -299,7 +301,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } [Fact] - public async Task ResponseBodyNotWrittenOnHeadResponse() + public async Task ResponseBodyNotWrittenOnHeadResponseAndLoggedOnlyOnce() { var mockKestrelTrace = new Mock(); @@ -324,7 +326,285 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } mockKestrelTrace.Verify(kestrelTrace => - kestrelTrace.ConnectionHeadResponseBodyWrite(It.IsAny(), "hello, world".Length)); + kestrelTrace.ConnectionHeadResponseBodyWrite(It.IsAny(), "hello, world".Length), Times.Once); + } + + [Fact] + public async Task WhenAppWritesMoreThanContentLengthWriteThrowsAndConnectionCloses() + { + var testLogger = new TestApplicationErrorLogger(); + var serviceContext = new TestServiceContext { Log = new TestKestrelTrace(testLogger) }; + + using (var server = new TestServer(httpContext => + { + httpContext.Response.ContentLength = 11; + httpContext.Response.Body.Write(Encoding.ASCII.GetBytes("hello,"), 0, 6); + httpContext.Response.Body.Write(Encoding.ASCII.GetBytes(" world"), 0, 6); + return TaskCache.CompletedTask; + }, serviceContext)) + { + using (var connection = server.CreateConnection()) + { + await connection.Send( + "GET / HTTP/1.1", + "", + ""); + await connection.ReceiveEnd( + $"HTTP/1.1 200 OK", + $"Date: {server.Context.DateHeaderValue}", + "Content-Length: 11", + "", + "hello,"); + } + } + + var logMessage = Assert.Single(testLogger.Messages, message => message.LogLevel == LogLevel.Error); + Assert.Equal( + $"Response Content-Length mismatch: too many bytes written (12 of 11).", + logMessage.Exception.Message); + } + + [Fact] + public async Task WhenAppWritesMoreThanContentLengthWriteAsyncThrowsAndConnectionCloses() + { + var testLogger = new TestApplicationErrorLogger(); + var serviceContext = new TestServiceContext { Log = new TestKestrelTrace(testLogger) }; + + using (var server = new TestServer(async httpContext => + { + httpContext.Response.ContentLength = 11; + await httpContext.Response.WriteAsync("hello,"); + await httpContext.Response.WriteAsync(" world"); + }, serviceContext)) + { + using (var connection = server.CreateConnection()) + { + await connection.Send( + "GET / HTTP/1.1", + "", + ""); + await connection.ReceiveEnd( + $"HTTP/1.1 200 OK", + $"Date: {server.Context.DateHeaderValue}", + "Content-Length: 11", + "", + "hello,"); + } + } + + var logMessage = Assert.Single(testLogger.Messages, message => message.LogLevel == LogLevel.Error); + Assert.Equal( + $"Response Content-Length mismatch: too many bytes written (12 of 11).", + logMessage.Exception.Message); + } + + [Fact] + public async Task WhenAppWritesMoreThanContentLengthAndResponseNotStarted500ResponseSentAndConnectionCloses() + { + var testLogger = new TestApplicationErrorLogger(); + var serviceContext = new TestServiceContext { Log = new TestKestrelTrace(testLogger) }; + + using (var server = new TestServer(async httpContext => + { + httpContext.Response.ContentLength = 5; + await httpContext.Response.WriteAsync("hello, world"); + }, serviceContext)) + { + using (var connection = server.CreateConnection()) + { + await connection.Send( + "GET / HTTP/1.1", + "", + ""); + await connection.ReceiveEnd( + $"HTTP/1.1 500 Internal Server Error", + "Connection: close", + $"Date: {server.Context.DateHeaderValue}", + "Content-Length: 0", + "", + ""); + } + } + + var logMessage = Assert.Single(testLogger.Messages, message => message.LogLevel == LogLevel.Error); + Assert.Equal( + $"Response Content-Length mismatch: too many bytes written (12 of 5).", + logMessage.Exception.Message); + } + + [Fact] + public async Task WhenAppWritesLessThanContentLengthErrorLogged() + { + var testLogger = new TestApplicationErrorLogger(); + var serviceContext = new TestServiceContext { Log = new TestKestrelTrace(testLogger) }; + + using (var server = new TestServer(async httpContext => + { + httpContext.Response.ContentLength = 13; + await httpContext.Response.WriteAsync("hello, world"); + }, serviceContext)) + { + using (var connection = server.CreateConnection()) + { + await connection.Send( + "GET / HTTP/1.1", + "", + ""); + await connection.ReceiveEnd( + $"HTTP/1.1 200 OK", + $"Date: {server.Context.DateHeaderValue}", + "Content-Length: 13", + "", + "hello, world"); + } + } + + var errorMessage = Assert.Single(testLogger.Messages, message => message.LogLevel == LogLevel.Error); + Assert.Equal( + $"Response Content-Length mismatch: too few bytes written (12 of 13).", + errorMessage.Exception.Message); + } + + [Fact] + public async Task WhenAppSetsContentLengthButDoesNotWriteBody500ResponseSentAndConnectionCloses() + { + var testLogger = new TestApplicationErrorLogger(); + var serviceContext = new TestServiceContext { Log = new TestKestrelTrace(testLogger) }; + + using (var server = new TestServer(httpContext => + { + httpContext.Response.ContentLength = 5; + return TaskCache.CompletedTask; + }, serviceContext)) + { + using (var connection = server.CreateConnection()) + { + await connection.Send( + "GET / HTTP/1.1", + "", + ""); + await connection.ReceiveEnd( + $"HTTP/1.1 500 Internal Server Error", + "Connection: close", + $"Date: {server.Context.DateHeaderValue}", + "Content-Length: 0", + "", + ""); + } + } + + var errorMessage = Assert.Single(testLogger.Messages, message => message.LogLevel == LogLevel.Error); + Assert.Equal( + $"Response Content-Length mismatch: too few bytes written (0 of 5).", + errorMessage.Exception.Message); + } + + [Theory] + [InlineData(false)] + [InlineData(true)] + public async Task WhenAppSetsContentLengthToZeroAndDoesNotWriteNoErrorIsThrown(bool flushResponse) + { + var testLogger = new TestApplicationErrorLogger(); + var serviceContext = new TestServiceContext { Log = new TestKestrelTrace(testLogger) }; + + using (var server = new TestServer(async httpContext => + { + httpContext.Response.ContentLength = 0; + + if (flushResponse) + { + await httpContext.Response.Body.FlushAsync(); + } + }, serviceContext)) + { + using (var connection = server.CreateConnection()) + { + await connection.Send( + "GET / HTTP/1.1", + "", + ""); + await connection.Receive( + $"HTTP/1.1 200 OK", + $"Date: {server.Context.DateHeaderValue}", + "Content-Length: 0", + "", + ""); + } + } + + Assert.Equal(0, testLogger.ApplicationErrorsLogged); + } + + // https://tools.ietf.org/html/rfc7230#section-3.3.3 + // If a message is received with both a Transfer-Encoding and a + // Content-Length header field, the Transfer-Encoding overrides the + // Content-Length. + [Fact] + public async Task WhenAppSetsTransferEncodingAndContentLengthWritingLessIsNotAnError() + { + var testLogger = new TestApplicationErrorLogger(); + var serviceContext = new TestServiceContext { Log = new TestKestrelTrace(testLogger) }; + + using (var server = new TestServer(async httpContext => + { + httpContext.Response.Headers["Transfer-Encoding"] = "chunked"; + httpContext.Response.ContentLength = 13; + await httpContext.Response.WriteAsync("hello, world"); + }, serviceContext)) + { + using (var connection = server.CreateConnection()) + { + await connection.Send( + "GET / HTTP/1.1", + "", + ""); + await connection.Receive( + $"HTTP/1.1 200 OK", + $"Date: {server.Context.DateHeaderValue}", + "Transfer-Encoding: chunked", + "Content-Length: 13", + "", + "hello, world"); + } + } + + Assert.Equal(0, testLogger.ApplicationErrorsLogged); + } + + // https://tools.ietf.org/html/rfc7230#section-3.3.3 + // If a message is received with both a Transfer-Encoding and a + // Content-Length header field, the Transfer-Encoding overrides the + // Content-Length. + [Fact] + public async Task WhenAppSetsTransferEncodingAndContentLengthWritingMoreIsNotAnError() + { + var testLogger = new TestApplicationErrorLogger(); + var serviceContext = new TestServiceContext { Log = new TestKestrelTrace(testLogger) }; + + using (var server = new TestServer(async httpContext => + { + httpContext.Response.Headers["Transfer-Encoding"] = "chunked"; + httpContext.Response.ContentLength = 11; + await httpContext.Response.WriteAsync("hello, world"); + }, serviceContext)) + { + using (var connection = server.CreateConnection()) + { + await connection.Send( + "GET / HTTP/1.1", + "", + ""); + await connection.Receive( + $"HTTP/1.1 200 OK", + $"Date: {server.Context.DateHeaderValue}", + "Transfer-Encoding: chunked", + "Content-Length: 11", + "", + "hello, world"); + } + } + + Assert.Equal(0, testLogger.ApplicationErrorsLogged); } public static TheoryData NullHeaderData diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs index a23a063d12..f9a8b8677d 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs @@ -620,35 +620,6 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } } - [Theory] - [MemberData(nameof(ConnectionFilterData))] - public async Task WriteOnHeadResponseLoggedOnlyOnce(TestServiceContext testContext) - { - using (var server = new TestServer(async httpContext => - { - await httpContext.Response.WriteAsync("hello, "); - await httpContext.Response.WriteAsync("world"); - await httpContext.Response.WriteAsync("!"); - }, testContext)) - { - using (var connection = server.CreateConnection()) - { - await connection.SendEnd( - "HEAD / HTTP/1.1", - "", - ""); - await connection.ReceiveEnd( - "HTTP/1.1 200 OK", - $"Date: {testContext.DateHeaderValue}", - "", - ""); - } - - Assert.Equal(1, ((TestKestrelTrace)testContext.Log).HeadResponseWrites); - Assert.Equal(13, ((TestKestrelTrace)testContext.Log).HeadResponseWriteByteCount); - } - } - [Theory] [MemberData(nameof(ConnectionFilterData))] public async Task ThrowingResultsIn500Response(TestServiceContext testContext) @@ -697,11 +668,11 @@ namespace Microsoft.AspNetCore.Server.KestrelTests "Content-Length: 0", "", ""); - - Assert.False(onStartingCalled); - Assert.Equal(2, testLogger.ApplicationErrorsLogged); } } + + Assert.False(onStartingCalled); + Assert.Equal(2, testLogger.ApplicationErrorsLogged); } [Theory] @@ -739,11 +710,11 @@ namespace Microsoft.AspNetCore.Server.KestrelTests "Content-Length: 11", "", "Hello World"); - - Assert.True(onStartingCalled); - Assert.Equal(1, testLogger.ApplicationErrorsLogged); } } + + Assert.True(onStartingCalled); + Assert.Equal(1, testLogger.ApplicationErrorsLogged); } [Theory] @@ -781,11 +752,11 @@ namespace Microsoft.AspNetCore.Server.KestrelTests "Content-Length: 11", "", "Hello"); - - Assert.True(onStartingCalled); - Assert.Equal(1, testLogger.ApplicationErrorsLogged); } } + + Assert.True(onStartingCalled); + Assert.Equal(1, testLogger.ApplicationErrorsLogged); } [Theory] @@ -925,16 +896,14 @@ namespace Microsoft.AspNetCore.Server.KestrelTests "Content-Length: 0", "", ""); - - Assert.Equal(2, onStartingCallCount2); - - // The first registered OnStarting callback should not be called, - // since they are called LIFO and the other one failed. - Assert.Equal(0, onStartingCallCount1); - - Assert.Equal(2, testLogger.ApplicationErrorsLogged); } } + + // The first registered OnStarting callback should not be called, + // since they are called LIFO and the other one failed. + Assert.Equal(0, onStartingCallCount1); + Assert.Equal(2, onStartingCallCount2); + Assert.Equal(2, testLogger.ApplicationErrorsLogged); } [Theory] @@ -979,12 +948,12 @@ namespace Microsoft.AspNetCore.Server.KestrelTests "", "Hello World"); } - - // All OnCompleted callbacks should be called even if they throw. - Assert.Equal(2, testLogger.ApplicationErrorsLogged); - Assert.True(onCompletedCalled1); - Assert.True(onCompletedCalled2); } + + // All OnCompleted callbacks should be called even if they throw. + Assert.Equal(2, testLogger.ApplicationErrorsLogged); + Assert.True(onCompletedCalled1); + Assert.True(onCompletedCalled2); } [Theory] diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameResponseHeadersTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameResponseHeadersTests.cs index c57ddff257..ff27b37cf9 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameResponseHeadersTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameResponseHeadersTests.cs @@ -78,24 +78,29 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { var responseHeaders = new FrameResponseHeaders(); - Assert.Throws(() => { + Assert.Throws(() => + { ((IHeaderDictionary)responseHeaders)[key] = value; }); - Assert.Throws(() => { + Assert.Throws(() => + { ((IHeaderDictionary)responseHeaders)[key] = new StringValues(new[] { "valid", value }); }); - Assert.Throws(() => { + Assert.Throws(() => + { ((IDictionary)responseHeaders)[key] = value; }); - Assert.Throws(() => { + Assert.Throws(() => + { var kvp = new KeyValuePair(key, value); ((ICollection>)responseHeaders).Add(kvp); }); - Assert.Throws(() => { + Assert.Throws(() => + { var kvp = new KeyValuePair(key, value); ((IDictionary)responseHeaders).Add(key, value); }); @@ -142,5 +147,83 @@ namespace Microsoft.AspNetCore.Server.KestrelTests Assert.Throws(() => dictionary.Clear()); } + + [Fact] + public void ThrowsWhenAddingContentLengthWithNonNumericValue() + { + var headers = new FrameResponseHeaders(); + var dictionary = (IDictionary)headers; + + Assert.Throws(() => dictionary.Add("Content-Length", new[] { "bad" })); + } + + [Fact] + public void ThrowsWhenSettingContentLengthToNonNumericValue() + { + var headers = new FrameResponseHeaders(); + var dictionary = (IDictionary)headers; + + Assert.Throws(() => ((IHeaderDictionary)headers)["Content-Length"] = "bad"); + } + + [Fact] + public void ThrowsWhenAssigningHeaderContentLengthToNonNumericValue() + { + var headers = new FrameResponseHeaders(); + Assert.Throws(() => headers.HeaderContentLength = "bad"); + } + + [Fact] + public void ContentLengthValueCanBeReadAsLongAfterAddingHeader() + { + var headers = new FrameResponseHeaders(); + var dictionary = (IDictionary)headers; + dictionary.Add("Content-Length", "42"); + + Assert.Equal(42, headers.HeaderContentLengthValue); + } + + [Fact] + public void ContentLengthValueCanBeReadAsLongAfterSettingHeader() + { + var headers = new FrameResponseHeaders(); + var dictionary = (IDictionary)headers; + dictionary["Content-Length"] = "42"; + + Assert.Equal(42, headers.HeaderContentLengthValue); + } + + [Fact] + public void ContentLengthValueCanBeReadAsLongAfterAssigningHeader() + { + var headers = new FrameResponseHeaders(); + headers.HeaderContentLength = "42"; + + Assert.Equal(42, headers.HeaderContentLengthValue); + } + + [Fact] + public void ContentLengthValueClearedWhenHeaderIsRemoved() + { + var headers = new FrameResponseHeaders(); + headers.HeaderContentLength = "42"; + var dictionary = (IDictionary)headers; + + dictionary.Remove("Content-Length"); + + Assert.Equal(null, headers.HeaderContentLengthValue); + } + + [Fact] + public void ContentLengthValueClearedWhenHeadersCleared() + { + var headers = new FrameResponseHeaders(); + headers.HeaderContentLength = "42"; + var dictionary = (IDictionary)headers; + + dictionary.Clear(); + + Assert.Equal(null, headers.HeaderContentLengthValue); + } } } diff --git a/test/shared/TestApplicationErrorLogger.cs b/test/shared/TestApplicationErrorLogger.cs index d2d3731a9d..5036f1cec9 100644 --- a/test/shared/TestApplicationErrorLogger.cs +++ b/test/shared/TestApplicationErrorLogger.cs @@ -2,6 +2,8 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Collections.Generic; +using System.Linq; using Microsoft.AspNetCore.Server.Kestrel.Internal; using Microsoft.Extensions.Logging; @@ -12,11 +14,13 @@ namespace Microsoft.AspNetCore.Testing // Application errors are logged using 13 as the eventId. private const int ApplicationErrorEventId = 13; - public int TotalErrorsLogged { get; set; } + public List Messages { get; } = new List(); - public int CriticalErrorsLogged { get; set; } + public int TotalErrorsLogged => Messages.Count(message => message.LogLevel == LogLevel.Error); - public int ApplicationErrorsLogged { get; set; } + public int CriticalErrorsLogged => Messages.Count(message => message.LogLevel == LogLevel.Critical); + + public int ApplicationErrorsLogged => Messages.Count(message => message.EventId.Id == ApplicationErrorEventId); public IDisposable BeginScope(TState state) { @@ -34,20 +38,14 @@ namespace Microsoft.AspNetCore.Testing Console.WriteLine($"Log {logLevel}[{eventId}]: {formatter(state, exception)} {exception?.Message}"); #endif - if (eventId.Id == ApplicationErrorEventId) - { - ApplicationErrorsLogged++; - } + Messages.Add(new LogMessage { LogLevel = logLevel, EventId = eventId, Exception = exception }); + } - if (logLevel == LogLevel.Error) - { - TotalErrorsLogged++; - } - - if (logLevel == LogLevel.Critical) - { - CriticalErrorsLogged++; - } + public class LogMessage + { + public LogLevel LogLevel { get; set; } + public EventId EventId { get; set; } + public Exception Exception { get; set; } } } } diff --git a/test/shared/TestKestrelTrace.cs b/test/shared/TestKestrelTrace.cs index 63dbfc0f73..814005d4d1 100644 --- a/test/shared/TestKestrelTrace.cs +++ b/test/shared/TestKestrelTrace.cs @@ -13,10 +13,6 @@ namespace Microsoft.AspNetCore.Testing { } - public int HeadResponseWrites { get; set; } - - public int HeadResponseWriteByteCount { get; set; } - public override void ConnectionRead(string connectionId, int count) { //_logger.LogDebug(1, @"Connection id ""{ConnectionId}"" recv {count} bytes.", connectionId, count); @@ -31,11 +27,5 @@ namespace Microsoft.AspNetCore.Testing { //_logger.LogDebug(1, @"Connection id ""{ConnectionId}"" send finished with status {status}.", connectionId, status); } - - public override void ConnectionHeadResponseBodyWrite(string connectionId, int count) - { - HeadResponseWrites++; - HeadResponseWriteByteCount = count; - } } } \ No newline at end of file diff --git a/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/KnownHeaders.cs b/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/KnownHeaders.cs index bb4f4485a0..7d8b57256f 100644 --- a/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/KnownHeaders.cs +++ b/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/KnownHeaders.cs @@ -14,6 +14,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.GeneratedCode return values.Any() ? values.Select(formatter).Aggregate((a, b) => a + b) : ""; } + static string If(bool condition, Func formatter) + { + return condition ? formatter() : ""; + } + class KnownHeader { public string Name { get; set; } @@ -228,7 +233,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http return StringValues.Empty; }} set - {{ + {{{If(loop.ClassName == "FrameResponseHeaders" && header.Identifier == "ContentLength", () => @" + _contentLength = ParseContentLength(value);")} {header.SetBit()}; _headers._{header.Identifier} = value; {(header.EnhancedSetter == false ? "" : $@" _headers._raw{header.Identifier} = null;")} @@ -304,7 +310,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http case {byLength.Key}: {{{Each(byLength, header => $@" if (""{header.Name}"".Equals(key, StringComparison.OrdinalIgnoreCase)) - {{ + {{{If(loop.ClassName == "FrameResponseHeaders" && header.Identifier == "ContentLength", () => @" + _contentLength = ParseContentLength(value);")} {header.SetBit()}; _headers._{header.Identifier} = value;{(header.EnhancedSetter == false ? "" : $@" _headers._raw{header.Identifier} = null;")} @@ -328,7 +335,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if ({header.TestBit()}) {{ ThrowDuplicateKeyException(); - }} + }}{ + If(loop.ClassName == "FrameResponseHeaders" && header.Identifier == "ContentLength", () => @" + _contentLength = ParseContentLength(value);")} {header.SetBit()}; _headers._{header.Identifier} = value;{(header.EnhancedSetter == false ? "" : $@" _headers._raw{header.Identifier} = null;")} @@ -349,7 +358,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if (""{header.Name}"".Equals(key, StringComparison.OrdinalIgnoreCase)) {{ if ({header.TestBit()}) - {{ + {{{If(loop.ClassName == "FrameResponseHeaders" && header.Identifier == "ContentLength", () => @" + _contentLength = null;")} {header.ClearBit()}; _headers._{header.Identifier} = StringValues.Empty;{(header.EnhancedSetter == false ? "" : $@" _headers._raw{header.Identifier} = null;")} @@ -369,6 +379,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http {{ _bits = 0; _headers = default(HeaderReferences); + {(loop.ClassName == "FrameResponseHeaders" ? "_contentLength = null;" : "")} MaybeUnknown?.Clear(); }} @@ -435,7 +446,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _headers._{header.Identifier} = AppendValue(_headers._{header.Identifier}, value); }} else - {{ + {{{If(loop.ClassName == "FrameResponseHeaders" && header.Identifier == "ContentLength", () => @" + _contentLength = ParseContentLength(value);")} {header.SetBit()}; _headers._{header.Identifier} = new StringValues(value);{(header.EnhancedSetter == false ? "" : $@" _headers._raw{header.Identifier} = null;")} From a15b1e28055cdc16f3c2d5424c21925266b84001 Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Tue, 11 Oct 2016 13:55:05 -0700 Subject: [PATCH 0912/1662] Update cached Content-Length when setting raw header. --- .../Internal/Http/FrameHeaders.Generated.cs | 1 + .../FrameResponseHeadersTests.cs | 18 ++++++++++++++++++ .../KnownHeaders.cs | 3 ++- 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameHeaders.Generated.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameHeaders.Generated.cs index 88fa8d6ac7..82931f5681 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameHeaders.Generated.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameHeaders.Generated.cs @@ -6083,6 +6083,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } public void SetRawContentLength(StringValues value, byte[] raw) { + _contentLength = ParseContentLength(value); _bits |= 2048L; _headers._ContentLength = value; _headers._rawContentLength = raw; diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameResponseHeadersTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameResponseHeadersTests.cs index ff27b37cf9..c21d6b2423 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameResponseHeadersTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameResponseHeadersTests.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; +using System.Text; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Server.Kestrel; using Microsoft.AspNetCore.Server.Kestrel.Internal; @@ -166,6 +167,14 @@ namespace Microsoft.AspNetCore.Server.KestrelTests Assert.Throws(() => ((IHeaderDictionary)headers)["Content-Length"] = "bad"); } + [Fact] + public void ThrowsWhenSettingRawContentLengthToNonNumericValue() + { + var headers = new FrameResponseHeaders(); + + Assert.Throws(() => headers.SetRawContentLength("bad", Encoding.ASCII.GetBytes("bad"))); + } + [Fact] public void ThrowsWhenAssigningHeaderContentLengthToNonNumericValue() { @@ -193,6 +202,15 @@ namespace Microsoft.AspNetCore.Server.KestrelTests Assert.Equal(42, headers.HeaderContentLengthValue); } + [Fact] + public void ContentLengthValueCanBeReadAsLongAfterSettingRawHeader() + { + var headers = new FrameResponseHeaders(); + headers.SetRawContentLength("42", Encoding.ASCII.GetBytes("42")); + + Assert.Equal(42, headers.HeaderContentLengthValue); + } + [Fact] public void ContentLengthValueCanBeReadAsLongAfterAssigningHeader() { diff --git a/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/KnownHeaders.cs b/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/KnownHeaders.cs index 7d8b57256f..8cb51355ac 100644 --- a/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/KnownHeaders.cs +++ b/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/KnownHeaders.cs @@ -242,7 +242,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http }}")} {Each(loop.Headers.Where(header => header.EnhancedSetter), header => $@" public void SetRaw{header.Identifier}(StringValues value, byte[] raw) - {{ + {{{If(loop.ClassName == "FrameResponseHeaders" && header.Identifier == "ContentLength", () => @" + _contentLength = ParseContentLength(value);")} {header.SetBit()}; _headers._{header.Identifier} = value; _headers._raw{header.Identifier} = raw; From 7ee13875b1b3e87bb04f4069f0d50d0624761902 Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Tue, 11 Oct 2016 10:44:36 -0700 Subject: [PATCH 0913/1662] Reduce delay variability in KeepAliveTimeoutTests.ConnectionKeptAliveBetweenRequests() (#1157). --- .../KeepAliveTimeoutTests.cs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/KeepAliveTimeoutTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/KeepAliveTimeoutTests.cs index ce2bcc631c..ee4a72cc57 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/KeepAliveTimeoutTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/KeepAliveTimeoutTests.cs @@ -21,6 +21,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [Fact] public async Task TestKeepAliveTimeout() { + // Delays in these tests cannot be much longer than expected. + // Call ConfigureAwait(false) to get rid of Xunit's synchronization context, + // otherwise it can cause unexpectedly longer delays when multiple tests + // are running in parallel. These tests becomes flaky on slower + // hardware because the continuations for the delay tasks might take too long to be + // scheduled if running on Xunit's synchronization context. + await Task.Delay(1).ConfigureAwait(false); + var longRunningCancellationTokenSource = new CancellationTokenSource(); var upgradeCancellationTokenSource = new CancellationTokenSource(); From ce6e65b1d75480ca38cf83d6b8550dafffccb73d Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Mon, 3 Oct 2016 19:38:21 -0700 Subject: [PATCH 0914/1662] Don't take SocketOutput's _contextLock to return written blocks --- .../Internal/Http/SocketOutput.cs | 90 ++++++++++--------- 1 file changed, 47 insertions(+), 43 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/SocketOutput.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/SocketOutput.cs index 29124e0039..a926230b83 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/SocketOutput.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/SocketOutput.cs @@ -378,6 +378,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _lastWriteError = error; } + PoolWriteContext(writeContext); + // _numBytesPreCompleted can temporarily go negative in the event there are // completed writes that we haven't triggered callbacks for yet. _numBytesPreCompleted -= bytesWritten; @@ -501,6 +503,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } } + private void PoolWriteContext(WriteContext writeContext) + { + // Called inside _contextLock + if (_writeContextPool.Count < _maxPooledWriteContexts) + { + writeContext.Reset(); + _writeContextPool.Enqueue(writeContext); + } + } + void ISocketOutput.Write(ArraySegment buffer, bool chunk) { WriteAsync(buffer, default(CancellationToken), chunk, isSync: true).GetAwaiter().GetResult(); @@ -546,7 +558,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http private class WriteContext { - private static readonly WaitCallback _returnWrittenBlocks = (state) => ((WriteContext)state).ReturnWrittenBlocks(); + private static readonly WaitCallback _returnWrittenBlocks = (state) => ReturnWrittenBlocks((MemoryPoolBlock)state); private static readonly WaitCallback _completeWrite = (state) => ((WriteContext)state).CompleteOnThreadPool(); private SocketOutput Self; @@ -555,11 +567,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http private MemoryPoolIterator _lockedEnd; private int _bufferCount; - // _returnBlocksCompleted and _writeCompleted help determine when it's safe to pool the WriteContext - // These are both guarded by the _contextLock. - private bool _returnBlocksCompleted; - private bool _writeCompleted; - public int ByteCount; public bool SocketShutdownSend; public bool SocketDisconnect; @@ -656,8 +663,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http try { Self.OnWriteCompleted(this); - _writeCompleted = true; - TryPool(); } finally { @@ -677,8 +682,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http try { Self.OnWriteCompleted(this); - _writeCompleted = true; - TryPool(); } catch (Exception ex) { @@ -694,23 +697,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http private void ScheduleReturnWrittenBlocks() { - Self._threadPool.UnsafeRun(_returnWrittenBlocks, this); - } - - private void ReturnWrittenBlocks() - { - var block = _lockedStart.Block; - while (block != _lockedEnd.Block) - { - var returnBlock = block; - block = block.Next; - - returnBlock.Pool.Return(returnBlock); - } + var returnAll = false; lock (Self._returnLock) { - // If everything has been fully written, return _tail. + // If everything has been fully written, return _tail/_lockedEnd. if (_lockedEnd.Block == Self._tail && _lockedEnd.Index == Self._tail.End && Self._lastStart.IsDefault) @@ -718,16 +709,43 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http Debug.Assert(Self._head == Self._tail); Debug.Assert(Self._tail.Start == Self._tail.End); - _lockedEnd.Block.Pool.Return(_lockedEnd.Block); Self._head = null; Self._tail = null; + returnAll = true; } } - lock (Self._contextLock) + if (!returnAll) { - _returnBlocksCompleted = true; - TryPool(); + var block = _lockedStart.Block; + var end = _lockedEnd.Block; + if (block == end) + { + return; + } + + while (block.Next != end) + { + block = block.Next; + } + + // Set the Next pointer in the block before _lockedEnd.Block to null. + // This prevents _lockedEnd.Block from being returned if it isn't fully + // written, or it's still being written to. + block.Next = null; + } + + Self._threadPool.UnsafeRun(_returnWrittenBlocks, _lockedStart.Block); + } + + private static void ReturnWrittenBlocks(MemoryPoolBlock block) + { + while (block != null) + { + var returnBlock = block; + block = block.Next; + + returnBlock.Pool.Return(returnBlock); } } @@ -749,26 +767,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http BytesBetween(_lockedStart, _lockedEnd, out ByteCount, out _bufferCount); } - private void TryPool() - { - // Called inside _contextLock - if (_writeCompleted && - _returnBlocksCompleted && - Self._writeContextPool.Count < _maxPooledWriteContexts) - { - Reset(); - Self._writeContextPool.Enqueue(this); - } - } - - private void Reset() + public void Reset() { _lockedStart = default(MemoryPoolIterator); _lockedEnd = default(MemoryPoolIterator); _bufferCount = 0; ByteCount = 0; - _writeCompleted = false; - _returnBlocksCompleted = false; SocketShutdownSend = false; SocketDisconnect = false; From ffc3eb3afd790f9faa1f49001d2bf09863bd8aa3 Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Wed, 12 Oct 2016 10:30:53 -0700 Subject: [PATCH 0915/1662] HEAD response can include Content-Length header. --- .../Internal/Http/Frame.cs | 15 +++++ .../Internal/Http/FrameOfT.cs | 12 +--- .../ResponseTests.cs | 56 +++++++++++++++++++ 3 files changed, 73 insertions(+), 10 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs index 8312e88bef..e31bd4777a 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs @@ -617,6 +617,21 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _responseBytesWritten += count; } + protected void VerifyResponseContentLength() + { + var responseHeaders = FrameResponseHeaders; + + if (!HttpMethods.IsHead(Method) && + !responseHeaders.HasTransferEncoding && + responseHeaders.HeaderContentLengthValue.HasValue && + _responseBytesWritten < responseHeaders.HeaderContentLengthValue.Value) + { + _keepAlive = false; + ReportApplicationError(new InvalidOperationException( + $"Response Content-Length mismatch: too few bytes written ({_responseBytesWritten} of {responseHeaders.HeaderContentLengthValue.Value}).")); + } + } + private void WriteChunked(ArraySegment data) { SocketOutput.Write(data, chunk: true); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameOfT.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameOfT.cs index 5fc2a56d2f..f2b0dac367 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameOfT.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameOfT.cs @@ -5,6 +5,7 @@ using System; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Hosting.Server; +using Microsoft.AspNetCore.Http; using Microsoft.Extensions.Logging; namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http @@ -92,16 +93,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http try { await _application.ProcessRequestAsync(context).ConfigureAwait(false); - - var responseHeaders = FrameResponseHeaders; - if (!responseHeaders.HasTransferEncoding && - responseHeaders.HasContentLength && - _responseBytesWritten < responseHeaders.HeaderContentLengthValue.Value) - { - _keepAlive = false; - ReportApplicationError(new InvalidOperationException( - $"Response Content-Length mismatch: too few bytes written ({_responseBytesWritten} of {responseHeaders.HeaderContentLengthValue.Value}).")); - } + VerifyResponseContentLength(); } catch (Exception ex) { diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs index 57e753d071..719b61cab1 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs @@ -607,6 +607,62 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests Assert.Equal(0, testLogger.ApplicationErrorsLogged); } + [Fact] + public async Task HeadResponseCanContainContentLengthHeader() + { + var testLogger = new TestApplicationErrorLogger(); + var serviceContext = new TestServiceContext { Log = new TestKestrelTrace(testLogger) }; + + using (var server = new TestServer(httpContext => + { + httpContext.Response.ContentLength = 42; + return TaskCache.CompletedTask; + }, serviceContext)) + { + using (var connection = server.CreateConnection()) + { + await connection.SendEnd( + "HEAD / HTTP/1.1", + "", + ""); + await connection.ReceiveEnd( + $"HTTP/1.1 200 OK", + $"Date: {server.Context.DateHeaderValue}", + "Content-Length: 42", + "", + ""); + } + } + } + + [Fact] + public async Task HeadResponseCanContainContentLengthHeaderButBodyNotWritten() + { + var testLogger = new TestApplicationErrorLogger(); + var serviceContext = new TestServiceContext { Log = new TestKestrelTrace(testLogger) }; + + using (var server = new TestServer(async httpContext => + { + httpContext.Response.ContentLength = 12; + await httpContext.Response.WriteAsync("hello, world"); + }, serviceContext)) + { + using (var connection = server.CreateConnection()) + { + await connection.SendEnd( + "HEAD / HTTP/1.1", + "", + ""); + await connection.ReceiveEnd( + $"HTTP/1.1 200 OK", + $"Date: {server.Context.DateHeaderValue}", + "Content-Length: 12", + "", + ""); + } + } + } + public static TheoryData NullHeaderData { get From bf94f8526a5e64e00a848a7b7e4fe21babac9ea8 Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Wed, 5 Oct 2016 15:36:14 -0700 Subject: [PATCH 0916/1662] Remove TCP Loopback Fast Path code (#1147). --- .../Internal/Networking/Libuv.cs | 34 ------------ .../EngineTests.cs | 52 +++++++++++++++++-- test/shared/TestConnection.cs | 15 ------ 3 files changed, 47 insertions(+), 54 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/Libuv.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/Libuv.cs index aaf1a00eba..21ed915e9f 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/Libuv.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/Libuv.cs @@ -199,40 +199,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking { handle.Validate(); ThrowIfErrored(_uv_tcp_bind(handle, ref addr, flags)); - if (PlatformApis.IsWindows) - { - tcp_bind_windows_extras(handle); - } - } - - private unsafe void tcp_bind_windows_extras(UvTcpHandle handle) - { - const int SIO_LOOPBACK_FAST_PATH = -1744830448; // IOC_IN | IOC_WS2 | 16; - const int WSAEOPNOTSUPP = 10000 + 45; // (WSABASEERR+45) - const int SOCKET_ERROR = -1; - - var socket = IntPtr.Zero; - ThrowIfErrored(_uv_fileno(handle, ref socket)); - - // Enable loopback fast-path for lower latency for localhost comms, like HttpPlatformHandler fronting - // http://blogs.technet.com/b/wincat/archive/2012/12/05/fast-tcp-loopback-performance-and-low-latency-with-windows-server-2012-tcp-loopback-fast-path.aspx - // https://github.com/libuv/libuv/issues/489 - var optionValue = 1; - uint dwBytes = 0u; - - var result = NativeMethods.WSAIoctl(socket, SIO_LOOPBACK_FAST_PATH, &optionValue, sizeof(int), null, 0, out dwBytes, IntPtr.Zero, IntPtr.Zero); - if (result == SOCKET_ERROR) - { - var errorId = NativeMethods.WSAGetLastError(); - if (errorId == WSAEOPNOTSUPP) - { - // This system is not >= Windows Server 2012, and the call is not supported. - } - else - { - ThrowIfErrored(errorId); - } - } } protected Func _uv_tcp_open; diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs index f9a8b8677d..8c961f81ec 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs @@ -471,10 +471,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { using (var connection = server.CreateConnection()) { - // Use Send instead of SendEnd to ensure the connection will remain open while - // the app runs and reads 0 bytes from the body nonetheless. This checks that - // https://github.com/aspnet/KestrelHttpServer/issues/1104 is not regressing. - await connection.Send( + await connection.SendEnd( "GET / HTTP/1.1", "Connection: close", "", @@ -490,7 +487,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests using (var connection = server.CreateConnection()) { - await connection.Send( + await connection.SendEnd( "GET / HTTP/1.0", "", ""); @@ -577,6 +574,51 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } } + [Theory] + [MemberData(nameof(ConnectionFilterData))] + public async Task ZeroContentLengthAssumedOnNonKeepAliveRequestsWithoutContentLengthOrTransferEncodingHeader(TestServiceContext testContext) + { + using (var server = new TestServer(async httpContext => + { + Assert.Equal(0, await httpContext.Request.Body.ReadAsync(new byte[1], 0, 1).TimeoutAfter(TimeSpan.FromSeconds(10))); + }, testContext)) + { + using (var connection = server.CreateConnection()) + { + // Use Send instead of SendEnd to ensure the connection will remain open while + // the app runs and reads 0 bytes from the body nonetheless. This checks that + // https://github.com/aspnet/KestrelHttpServer/issues/1104 is not regressing. + await connection.Send( + "GET / HTTP/1.1", + "Connection: close", + "", + "a"); + await connection.ReceiveEnd( + "HTTP/1.1 200 OK", + "Connection: close", + $"Date: {testContext.DateHeaderValue}", + "Content-Length: 0", + "", + ""); + } + + using (var connection = server.CreateConnection()) + { + await connection.Send( + "GET / HTTP/1.0", + "", + "a"); + await connection.ReceiveEnd( + "HTTP/1.1 200 OK", + "Connection: close", + $"Date: {testContext.DateHeaderValue}", + "Content-Length: 0", + "", + ""); + } + } + } + [Theory] [MemberData(nameof(ConnectionFilterData))] public async Task ConnectionClosedAfter101Response(TestServiceContext testContext) diff --git a/test/shared/TestConnection.cs b/test/shared/TestConnection.cs index cdb7e40ec5..3b00841109 100644 --- a/test/shared/TestConnection.cs +++ b/test/shared/TestConnection.cs @@ -167,21 +167,6 @@ namespace Microsoft.AspNetCore.Testing public static Socket CreateConnectedLoopbackSocket(int port) { var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); - if (PlatformApis.IsWindows) - { - const int SIO_LOOPBACK_FAST_PATH = -1744830448; - var optionInValue = BitConverter.GetBytes(1); - try - { - socket.IOControl(SIO_LOOPBACK_FAST_PATH, optionInValue, null); - } - catch - { - // If the operating system version on this machine did - // not support SIO_LOOPBACK_FAST_PATH (i.e. version - // prior to Windows 8 / Windows Server 2012), handle the exception - } - } socket.Connect(new IPEndPoint(IPAddress.Loopback, port)); return socket; } From dd23f242418203fdb7b28a17185876870ec0d7b8 Mon Sep 17 00:00:00 2001 From: Pranav K Date: Wed, 12 Oct 2016 13:45:43 -0700 Subject: [PATCH 0917/1662] Updating to netcoreapp1.1 --- samples/LargeResponseApp/project.json | 2 +- samples/SampleApp/project.json | 2 +- .../project.json | 2 +- test/Microsoft.AspNetCore.Server.KestrelTests/project.json | 2 +- .../project.json | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/samples/LargeResponseApp/project.json b/samples/LargeResponseApp/project.json index 886ce0d4aa..d2305ee97e 100644 --- a/samples/LargeResponseApp/project.json +++ b/samples/LargeResponseApp/project.json @@ -8,7 +8,7 @@ }, "frameworks": { "net451": {}, - "netcoreapp1.0": { + "netcoreapp1.1": { "dependencies": { "Microsoft.NETCore.App": { "version": "1.1.0-*", diff --git a/samples/SampleApp/project.json b/samples/SampleApp/project.json index 73d36ceffa..c3314ee4f9 100644 --- a/samples/SampleApp/project.json +++ b/samples/SampleApp/project.json @@ -10,7 +10,7 @@ }, "frameworks": { "net451": {}, - "netcoreapp1.0": { + "netcoreapp1.1": { "dependencies": { "Microsoft.NETCore.App": { "version": "1.1.0-*", diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json index beabf3d299..9444a422fd 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json @@ -16,7 +16,7 @@ } }, "frameworks": { - "netcoreapp1.0": { + "netcoreapp1.1": { "dependencies": { "Microsoft.NETCore.App": { "version": "1.1.0-*", diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/project.json b/test/Microsoft.AspNetCore.Server.KestrelTests/project.json index 6fdb968ff2..54537f5e83 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/project.json +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/project.json @@ -13,7 +13,7 @@ } }, "frameworks": { - "netcoreapp1.0": { + "netcoreapp1.1": { "dependencies": { "Microsoft.NETCore.App": { "version": "1.1.0-*", diff --git a/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/project.json b/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/project.json index 950691be17..f22ca3b7d6 100644 --- a/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/project.json +++ b/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/project.json @@ -8,7 +8,7 @@ "Microsoft.AspNetCore.Http.Features": "1.1.0-*" }, "frameworks": { - "netcoreapp1.0": { + "netcoreapp1.1": { "dependencies": { "Microsoft.NETCore.App": { "version": "1.1.0-*", From e2f11ebd3830ad808357d7aaaaf8b50eb409950a Mon Sep 17 00:00:00 2001 From: Pranav K Date: Wed, 12 Oct 2016 16:08:56 -0700 Subject: [PATCH 0918/1662] Revert "Updating to netcoreapp1.1" This reverts commit dd23f242418203fdb7b28a17185876870ec0d7b8. --- samples/LargeResponseApp/project.json | 2 +- samples/SampleApp/project.json | 2 +- .../project.json | 2 +- test/Microsoft.AspNetCore.Server.KestrelTests/project.json | 2 +- .../project.json | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/samples/LargeResponseApp/project.json b/samples/LargeResponseApp/project.json index d2305ee97e..886ce0d4aa 100644 --- a/samples/LargeResponseApp/project.json +++ b/samples/LargeResponseApp/project.json @@ -8,7 +8,7 @@ }, "frameworks": { "net451": {}, - "netcoreapp1.1": { + "netcoreapp1.0": { "dependencies": { "Microsoft.NETCore.App": { "version": "1.1.0-*", diff --git a/samples/SampleApp/project.json b/samples/SampleApp/project.json index c3314ee4f9..73d36ceffa 100644 --- a/samples/SampleApp/project.json +++ b/samples/SampleApp/project.json @@ -10,7 +10,7 @@ }, "frameworks": { "net451": {}, - "netcoreapp1.1": { + "netcoreapp1.0": { "dependencies": { "Microsoft.NETCore.App": { "version": "1.1.0-*", diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json index 9444a422fd..beabf3d299 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json @@ -16,7 +16,7 @@ } }, "frameworks": { - "netcoreapp1.1": { + "netcoreapp1.0": { "dependencies": { "Microsoft.NETCore.App": { "version": "1.1.0-*", diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/project.json b/test/Microsoft.AspNetCore.Server.KestrelTests/project.json index 54537f5e83..6fdb968ff2 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/project.json +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/project.json @@ -13,7 +13,7 @@ } }, "frameworks": { - "netcoreapp1.1": { + "netcoreapp1.0": { "dependencies": { "Microsoft.NETCore.App": { "version": "1.1.0-*", diff --git a/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/project.json b/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/project.json index f22ca3b7d6..950691be17 100644 --- a/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/project.json +++ b/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/project.json @@ -8,7 +8,7 @@ "Microsoft.AspNetCore.Http.Features": "1.1.0-*" }, "frameworks": { - "netcoreapp1.1": { + "netcoreapp1.0": { "dependencies": { "Microsoft.NETCore.App": { "version": "1.1.0-*", From 2876f825217544335120e97f1742070e5d78117c Mon Sep 17 00:00:00 2001 From: Pranav K Date: Thu, 13 Oct 2016 11:19:16 -0700 Subject: [PATCH 0919/1662] Updating to netcoreapp1.1 --- samples/LargeResponseApp/project.json | 2 +- samples/SampleApp/project.json | 2 +- .../project.json | 2 +- test/Microsoft.AspNetCore.Server.KestrelTests/project.json | 2 +- .../project.json | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/samples/LargeResponseApp/project.json b/samples/LargeResponseApp/project.json index 886ce0d4aa..d2305ee97e 100644 --- a/samples/LargeResponseApp/project.json +++ b/samples/LargeResponseApp/project.json @@ -8,7 +8,7 @@ }, "frameworks": { "net451": {}, - "netcoreapp1.0": { + "netcoreapp1.1": { "dependencies": { "Microsoft.NETCore.App": { "version": "1.1.0-*", diff --git a/samples/SampleApp/project.json b/samples/SampleApp/project.json index 73d36ceffa..c3314ee4f9 100644 --- a/samples/SampleApp/project.json +++ b/samples/SampleApp/project.json @@ -10,7 +10,7 @@ }, "frameworks": { "net451": {}, - "netcoreapp1.0": { + "netcoreapp1.1": { "dependencies": { "Microsoft.NETCore.App": { "version": "1.1.0-*", diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json index beabf3d299..9444a422fd 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json @@ -16,7 +16,7 @@ } }, "frameworks": { - "netcoreapp1.0": { + "netcoreapp1.1": { "dependencies": { "Microsoft.NETCore.App": { "version": "1.1.0-*", diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/project.json b/test/Microsoft.AspNetCore.Server.KestrelTests/project.json index 6fdb968ff2..54537f5e83 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/project.json +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/project.json @@ -13,7 +13,7 @@ } }, "frameworks": { - "netcoreapp1.0": { + "netcoreapp1.1": { "dependencies": { "Microsoft.NETCore.App": { "version": "1.1.0-*", diff --git a/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/project.json b/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/project.json index 950691be17..f22ca3b7d6 100644 --- a/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/project.json +++ b/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/project.json @@ -8,7 +8,7 @@ "Microsoft.AspNetCore.Http.Features": "1.1.0-*" }, "frameworks": { - "netcoreapp1.0": { + "netcoreapp1.1": { "dependencies": { "Microsoft.NETCore.App": { "version": "1.1.0-*", From bcb731e50cb97817a9e4e79dca95aac9e8f29b89 Mon Sep 17 00:00:00 2001 From: Pranav K Date: Mon, 17 Oct 2016 09:49:19 -0700 Subject: [PATCH 0920/1662] Branching for 1.1.0-preview1 --- NuGet.config | 4 ++-- build.ps1 | 2 +- build.sh | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/NuGet.config b/NuGet.config index 826a1f9035..6197c93176 100644 --- a/NuGet.config +++ b/NuGet.config @@ -1,7 +1,7 @@ - + - + \ No newline at end of file diff --git a/build.ps1 b/build.ps1 index 8f2f99691a..787f63ac02 100644 --- a/build.ps1 +++ b/build.ps1 @@ -33,7 +33,7 @@ cd $PSScriptRoot $repoFolder = $PSScriptRoot $env:REPO_FOLDER = $repoFolder -$koreBuildZip="https://github.com/aspnet/KoreBuild/archive/dev.zip" +$koreBuildZip="https://github.com/aspnet/KoreBuild/archive/rel/1.1.0-preview1.zip" if ($env:KOREBUILD_ZIP) { $koreBuildZip=$env:KOREBUILD_ZIP diff --git a/build.sh b/build.sh index f4208100eb..355c682856 100755 --- a/build.sh +++ b/build.sh @@ -2,7 +2,7 @@ repoFolder="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" cd $repoFolder -koreBuildZip="https://github.com/aspnet/KoreBuild/archive/dev.zip" +koreBuildZip="https://github.com/aspnet/KoreBuild/archive/rel/1.1.0-preview1.zip" if [ ! -z $KOREBUILD_ZIP ]; then koreBuildZip=$KOREBUILD_ZIP fi From f1071dea50d03b4bad0577aa402811f92b3471b5 Mon Sep 17 00:00:00 2001 From: Mike Harder Date: Tue, 19 Jul 2016 12:25:55 -0700 Subject: [PATCH 0921/1662] Set StatusCode before disposing HttpContext (#876) --- .../Internal/Http/Frame.cs | 1 - .../Internal/Http/FrameOfT.cs | 98 ++++++++------ .../ResponseTests.cs | 120 ++++++++++++++++++ 3 files changed, 176 insertions(+), 43 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs index e31bd4777a..e2c0d88b68 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs @@ -4,7 +4,6 @@ using System; using System.Collections.Generic; using System.Diagnostics; -using System.Globalization; using System.IO; using System.Linq; using System.Net; diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameOfT.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameOfT.cs index f2b0dac367..b71f94dbd3 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameOfT.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameOfT.cs @@ -92,55 +92,69 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var context = _application.CreateContext(this); try { - await _application.ProcessRequestAsync(context).ConfigureAwait(false); - VerifyResponseContentLength(); - } - catch (Exception ex) - { - ReportApplicationError(ex); + try + { + await _application.ProcessRequestAsync(context).ConfigureAwait(false); + VerifyResponseContentLength(); + } + catch (Exception ex) + { + ReportApplicationError(ex); + } + finally + { + // Trigger OnStarting if it hasn't been called yet and the app hasn't + // already failed. If an OnStarting callback throws we can go through + // our normal error handling in ProduceEnd. + // https://github.com/aspnet/KestrelHttpServer/issues/43 + if (!HasResponseStarted && _applicationException == null && _onStarting != null) + { + await FireOnStarting(); + } + + PauseStreams(); + + if (_onCompleted != null) + { + await FireOnCompleted(); + } + + // If _requestAbort is set, the connection has already been closed. + if (Volatile.Read(ref _requestAborted) == 0) + { + ResumeStreams(); + + if (_keepAlive) + { + // Finish reading the request body in case the app did not. + await messageBody.Consume(); + } + + // ProduceEnd() must be called before _application.DisposeContext(), to ensure + // HttpContext.Response.StatusCode is correctly set when + // IHttpContextFactory.Dispose(HttpContext) is called. + await ProduceEnd(); + } + else if (!HasResponseStarted) + { + // If the request was aborted and no response was sent, there's no + // meaningful status code to log. + StatusCode = 0; + } + } } finally { - // Trigger OnStarting if it hasn't been called yet and the app hasn't - // already failed. If an OnStarting callback throws we can go through - // our normal error handling in ProduceEnd. - // https://github.com/aspnet/KestrelHttpServer/issues/43 - if (!HasResponseStarted && _applicationException == null && _onStarting != null) - { - await FireOnStarting(); - } - - PauseStreams(); - - if (_onCompleted != null) - { - await FireOnCompleted(); - } - _application.DisposeContext(context, _applicationException); } + } - // If _requestAbort is set, the connection has already been closed. - if (Volatile.Read(ref _requestAborted) == 0) - { - ResumeStreams(); + StopStreams(); - if (_keepAlive) - { - // Finish reading the request body in case the app did not. - await messageBody.Consume(); - } - - await ProduceEnd(); - } - - StopStreams(); - - if (!_keepAlive) - { - // End the connection for non keep alive as data incoming may have been thrown off - return; - } + if (!_keepAlive) + { + // End the connection for non keep alive as data incoming may have been thrown off + return; } // Don't reset frame state if we're exiting the loop. This avoids losing request rejection diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs index 719b61cab1..336be582ee 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs @@ -6,14 +6,17 @@ using System.IO; using System.Linq; using System.Net; using System.Net.Http; +using System.Net.Sockets; using System.Text; using System.Threading.Tasks; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.AspNetCore.Testing; +using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Internal; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Primitives; @@ -185,6 +188,123 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } } + [Fact] + public Task ResponseStatusCodeSetBeforeHttpContextDisposeAppException() + { + return ResponseStatusCodeSetBeforeHttpContextDispose( + context => + { + throw new Exception(); + }, + expectedClientStatusCode: HttpStatusCode.InternalServerError, + expectedServerStatusCode: HttpStatusCode.InternalServerError); + } + + [Fact] + public Task ResponseStatusCodeSetBeforeHttpContextDisposeRequestAborted() + { + return ResponseStatusCodeSetBeforeHttpContextDispose( + context => + { + context.Abort(); + return TaskCache.CompletedTask; + }, + expectedClientStatusCode: null, + expectedServerStatusCode: 0); + } + + [Fact] + public Task ResponseStatusCodeSetBeforeHttpContextDisposeRequestAbortedAppException() + { + return ResponseStatusCodeSetBeforeHttpContextDispose( + context => + { + context.Abort(); + throw new Exception(); + }, + expectedClientStatusCode: null, + expectedServerStatusCode: 0); + } + + [Fact] + public Task ResponseStatusCodeSetBeforeHttpContextDisposedRequestMalformed() + { + return ResponseStatusCodeSetBeforeHttpContextDispose( + context => + { + return TaskCache.CompletedTask; + }, + expectedClientStatusCode: null, + expectedServerStatusCode: HttpStatusCode.BadRequest, + sendMalformedRequest: true); + } + + private static async Task ResponseStatusCodeSetBeforeHttpContextDispose( + RequestDelegate handler, + HttpStatusCode? expectedClientStatusCode, + HttpStatusCode expectedServerStatusCode, + bool sendMalformedRequest = false) + { + var mockHttpContextFactory = new Mock(); + mockHttpContextFactory.Setup(f => f.Create(It.IsAny())) + .Returns(fc => new DefaultHttpContext(fc)); + + var disposedTcs = new TaskCompletionSource(); + mockHttpContextFactory.Setup(f => f.Dispose(It.IsAny())) + .Callback(c => + { + disposedTcs.TrySetResult(c.Response.StatusCode); + }); + + var hostBuilder = new WebHostBuilder() + .UseKestrel() + .UseUrls("http://127.0.0.1:0") + .ConfigureServices(services => services.AddSingleton(mockHttpContextFactory.Object)) + .Configure(app => + { + app.Run(handler); + }); + + using (var host = hostBuilder.Build()) + { + host.Start(); + + if (!sendMalformedRequest) + { + using (var client = new HttpClient()) + { + try + { + var response = await client.GetAsync($"http://localhost:{host.GetPort()}/"); + Assert.Equal(expectedClientStatusCode, response.StatusCode); + } + catch + { + if (expectedClientStatusCode != null) + { + throw; + } + } + } + } + else + { + using (var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)) + { + socket.Connect(new IPEndPoint(IPAddress.Loopback, host.GetPort())); + socket.Send(Encoding.ASCII.GetBytes( + "POST / HTTP/1.1\r\n" + + "Transfer-Encoding: chunked\r\n" + + "\r\n" + + "wrong")); + } + } + + var disposedStatusCode = await disposedTcs.Task.TimeoutAfter(TimeSpan.FromSeconds(10)); + Assert.Equal(expectedServerStatusCode, (HttpStatusCode)disposedStatusCode); + } + } + // https://github.com/aspnet/KestrelHttpServer/pull/1111/files#r80584475 explains the reason for this test. [Fact] public async Task SingleErrorResponseSentWhenAppSwallowsBadRequestException() From 78584799a412ef24327dca5b3c62315d708bb44c Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Wed, 12 Oct 2016 10:12:01 -0700 Subject: [PATCH 0922/1662] Separate request rejection from bad request state setting. --- .../Internal/Http/Frame.cs | 41 ++++----- .../Internal/Http/FrameOfT.cs | 69 ++++++++------- .../ResponseTests.cs | 87 ++++++++++++++++--- 3 files changed, 134 insertions(+), 63 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs index e2c0d88b68..0953726458 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs @@ -47,7 +47,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http private readonly object _onStartingSync = new Object(); private readonly object _onCompletedSync = new Object(); - protected bool _requestRejected; private Streams _frameStreams; protected Stack, object>> _onStarting; @@ -64,6 +63,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http private bool _canHaveBody; private bool _autoChunk; protected Exception _applicationException; + private BadHttpRequestException _requestRejectedException; protected HttpVersion _httpVersion; @@ -717,7 +717,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http protected Task TryProduceInvalidRequestResponse() { - if (_requestRejected) + if (_requestRejectedException != null) { if (FrameRequestHeaders == null || FrameResponseHeaders == null) { @@ -732,7 +732,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http protected Task ProduceEnd() { - if (_requestRejected || _applicationException != null) + if (_requestRejectedException != null || _applicationException != null) { if (HasResponseStarted) { @@ -741,8 +741,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http return TaskCache.CompletedTask; } - // If the request was rejected, the error state has already been set by SetBadRequestState - if (!_requestRejected) + // If the request was rejected, the error state has already been set by SetBadRequestState and + // that should take precedence. + if (_requestRejectedException != null) + { + SetErrorResponseHeaders(statusCode: _requestRejectedException.StatusCode); + } + else { // 500 Internal Server Error SetErrorResponseHeaders(statusCode: 500); @@ -1394,24 +1399,19 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _applicationException); } - public void RejectRequest(string message) - { - throw new ObjectDisposedException( - "The response has been aborted due to an unhandled application exception.", - _applicationException); - } - public void RejectRequest(RequestRejectionReason reason) { - var ex = BadHttpRequestException.GetException(reason); - SetBadRequestState(ex); - throw ex; + RejectRequest(BadHttpRequestException.GetException(reason)); } public void RejectRequest(RequestRejectionReason reason, string value) { - var ex = BadHttpRequestException.GetException(reason, value); - SetBadRequestState(ex); + RejectRequest(BadHttpRequestException.GetException(reason, value)); + } + + private void RejectRequest(BadHttpRequestException ex) + { + Log.ConnectionBadRequest(ConnectionId, ex); throw ex; } @@ -1422,17 +1422,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http public void SetBadRequestState(BadHttpRequestException ex) { - // Setting status code will throw if response has already started if (!HasResponseStarted) { - SetErrorResponseHeaders(statusCode: ex.StatusCode); + SetErrorResponseHeaders(ex.StatusCode); } _keepAlive = false; _requestProcessingStopping = true; - _requestRejected = true; - - Log.ConnectionBadRequest(ConnectionId, ex); + _requestRejectedException = ex; } protected void ReportApplicationError(Exception ex) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameOfT.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameOfT.cs index b71f94dbd3..cfdc1fc556 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameOfT.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameOfT.cs @@ -100,6 +100,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http catch (Exception ex) { ReportApplicationError(ex); + + if (ex is BadHttpRequestException) + { + throw; + } } finally { @@ -118,30 +123,37 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { await FireOnCompleted(); } - - // If _requestAbort is set, the connection has already been closed. - if (Volatile.Read(ref _requestAborted) == 0) - { - ResumeStreams(); - - if (_keepAlive) - { - // Finish reading the request body in case the app did not. - await messageBody.Consume(); - } - - // ProduceEnd() must be called before _application.DisposeContext(), to ensure - // HttpContext.Response.StatusCode is correctly set when - // IHttpContextFactory.Dispose(HttpContext) is called. - await ProduceEnd(); - } - else if (!HasResponseStarted) - { - // If the request was aborted and no response was sent, there's no - // meaningful status code to log. - StatusCode = 0; - } } + + // If _requestAbort is set, the connection has already been closed. + if (Volatile.Read(ref _requestAborted) == 0) + { + ResumeStreams(); + + if (_keepAlive) + { + // Finish reading the request body in case the app did not. + await messageBody.Consume(); + } + + // ProduceEnd() must be called before _application.DisposeContext(), to ensure + // HttpContext.Response.StatusCode is correctly set when + // IHttpContextFactory.Dispose(HttpContext) is called. + await ProduceEnd(); + } + else if (!HasResponseStarted) + { + // If the request was aborted and no response was sent, there's no + // meaningful status code to log. + StatusCode = 0; + } + } + catch (BadHttpRequestException ex) + { + // Handle BadHttpRequestException thrown during app execution or remaining message body consumption. + // This has to be caught here so StatusCode is set properly before disposing the HttpContext + // (DisposeContext logs StatusCode). + SetBadRequestState(ex); } finally { @@ -169,11 +181,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } catch (BadHttpRequestException ex) { - if (!_requestRejected) - { - // SetBadRequestState logs the error. - SetBadRequestState(ex); - } + // Handle BadHttpRequestException thrown during request line or header parsing. + // SetBadRequestState logs the error. + SetBadRequestState(ex); } catch (Exception ex) { @@ -183,11 +193,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { try { - await TryProduceInvalidRequestResponse(); - // If _requestAborted is set, the connection has already been closed. if (Volatile.Read(ref _requestAborted) == 0) { + await TryProduceInvalidRequestResponse(); ConnectionControl.End(ProduceEndType.SocketShutdown); } } diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs index 336be582ee..6140e6ea0a 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs @@ -2,7 +2,6 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.IO; using System.Linq; using System.Net; using System.Net.Http; @@ -239,6 +238,38 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests sendMalformedRequest: true); } + [Fact] + public Task ResponseStatusCodeSetBeforeHttpContextDisposedRequestMalformedRead() + { + return ResponseStatusCodeSetBeforeHttpContextDispose( + async context => + { + await context.Request.Body.ReadAsync(new byte[1], 0, 1); + }, + expectedClientStatusCode: null, + expectedServerStatusCode: HttpStatusCode.BadRequest, + sendMalformedRequest: true); + } + + [Fact] + public Task ResponseStatusCodeSetBeforeHttpContextDisposedRequestMalformedReadIgnored() + { + return ResponseStatusCodeSetBeforeHttpContextDispose( + async context => + { + try + { + await context.Request.Body.ReadAsync(new byte[1], 0, 1); + } + catch (BadHttpRequestException) + { + } + }, + expectedClientStatusCode: null, + expectedServerStatusCode: HttpStatusCode.BadRequest, + sendMalformedRequest: true); + } + private static async Task ResponseStatusCodeSetBeforeHttpContextDispose( RequestDelegate handler, HttpStatusCode? expectedClientStatusCode, @@ -730,14 +761,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [Fact] public async Task HeadResponseCanContainContentLengthHeader() { - var testLogger = new TestApplicationErrorLogger(); - var serviceContext = new TestServiceContext { Log = new TestKestrelTrace(testLogger) }; - using (var server = new TestServer(httpContext => { httpContext.Response.ContentLength = 42; return TaskCache.CompletedTask; - }, serviceContext)) + }, new TestServiceContext())) { using (var connection = server.CreateConnection()) { @@ -746,7 +774,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests "", ""); await connection.ReceiveEnd( - $"HTTP/1.1 200 OK", + "HTTP/1.1 200 OK", $"Date: {server.Context.DateHeaderValue}", "Content-Length: 42", "", @@ -758,14 +786,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [Fact] public async Task HeadResponseCanContainContentLengthHeaderButBodyNotWritten() { - var testLogger = new TestApplicationErrorLogger(); - var serviceContext = new TestServiceContext { Log = new TestKestrelTrace(testLogger) }; - using (var server = new TestServer(async httpContext => { httpContext.Response.ContentLength = 12; await httpContext.Response.WriteAsync("hello, world"); - }, serviceContext)) + }, new TestServiceContext())) { using (var connection = server.CreateConnection()) { @@ -774,7 +799,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests "", ""); await connection.ReceiveEnd( - $"HTTP/1.1 200 OK", + "HTTP/1.1 200 OK", $"Date: {server.Context.DateHeaderValue}", "Content-Length: 12", "", @@ -783,6 +808,46 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } } + [Fact] + public async Task AppCanWriteOwnBadRequestResponse() + { + var expectedResponse = string.Empty; + var responseWrittenTcs = new TaskCompletionSource(); + + using (var server = new TestServer(async httpContext => + { + try + { + await httpContext.Request.Body.ReadAsync(new byte[1], 0, 1); + } + catch (BadHttpRequestException ex) + { + expectedResponse = ex.Message; + httpContext.Response.StatusCode = 400; + httpContext.Response.ContentLength = ex.Message.Length; + await httpContext.Response.WriteAsync(ex.Message); + responseWrittenTcs.SetResult(null); + } + }, new TestServiceContext())) + { + using (var connection = server.CreateConnection()) + { + await connection.SendEnd( + "POST / HTTP/1.1", + "Transfer-Encoding: chunked", + "", + "bad"); + await responseWrittenTcs.Task; + await connection.ReceiveEnd( + "HTTP/1.1 400 Bad Request", + $"Date: {server.Context.DateHeaderValue}", + $"Content-Length: {expectedResponse.Length}", + "", + expectedResponse); + } + } + } + public static TheoryData NullHeaderData { get From fff0adeaaf55b23f2173be25c59202a322f8eda6 Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Thu, 13 Oct 2016 15:05:54 -0700 Subject: [PATCH 0923/1662] Faster response Content-Length parsing. --- .../Internal/Http/FrameHeaders.cs | 39 +++++-- .../FrameResponseHeadersTests.cs | 100 +++++++++++++----- 2 files changed, 103 insertions(+), 36 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameHeaders.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameHeaders.cs index c6b9d0c59d..4d234322a5 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameHeaders.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameHeaders.cs @@ -233,16 +233,41 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } } - public static long ParseContentLength(StringValues value) + public static unsafe long ParseContentLength(StringValues value) { - try + var input = value.ToString(); + var parsed = 0L; + + fixed (char* ptr = input) { - return long.Parse(value, NumberStyles.AllowLeadingWhite | NumberStyles.AllowTrailingWhite, CultureInfo.InvariantCulture); - } - catch (FormatException ex) - { - throw new InvalidOperationException("Content-Length value must be an integral number.", ex); + var ch = (ushort*)ptr; + var end = ch + input.Length; + + if (ch == end) + { + ThrowInvalidContentLengthException(value); + } + + ushort digit = 0; + while (ch < end && (digit = (ushort)(*ch - 0x30)) <= 9) + { + parsed *= 10; + parsed += digit; + ch++; + } + + if (ch != end) + { + ThrowInvalidContentLengthException(value); + } } + + return parsed; + } + + private static void ThrowInvalidContentLengthException(string value) + { + throw new InvalidOperationException($"Invalid Content-Length: \"{value}\". Value must be a positive integral number."); } private static void ThrowInvalidHeaderCharacter(char ch) diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameResponseHeadersTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameResponseHeadersTests.cs index c21d6b2423..bc76f2c09f 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameResponseHeadersTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameResponseHeadersTests.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; +using System.Globalization; using System.Text; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Server.Kestrel; @@ -149,75 +150,88 @@ namespace Microsoft.AspNetCore.Server.KestrelTests Assert.Throws(() => dictionary.Clear()); } - [Fact] - public void ThrowsWhenAddingContentLengthWithNonNumericValue() + [Theory] + [MemberData(nameof(BadContentLengths))] + public void ThrowsWhenAddingContentLengthWithNonNumericValue(string contentLength) { var headers = new FrameResponseHeaders(); var dictionary = (IDictionary)headers; - Assert.Throws(() => dictionary.Add("Content-Length", new[] { "bad" })); + var exception = Assert.Throws(() => dictionary.Add("Content-Length", new[] { contentLength })); + Assert.Equal($"Invalid Content-Length: \"{contentLength}\". Value must be a positive integral number.", exception.Message); } - [Fact] - public void ThrowsWhenSettingContentLengthToNonNumericValue() + [Theory] + [MemberData(nameof(BadContentLengths))] + public void ThrowsWhenSettingContentLengthToNonNumericValue(string contentLength) { var headers = new FrameResponseHeaders(); var dictionary = (IDictionary)headers; - Assert.Throws(() => ((IHeaderDictionary)headers)["Content-Length"] = "bad"); + var exception = Assert.Throws(() => ((IHeaderDictionary)headers)["Content-Length"] = contentLength); + Assert.Equal($"Invalid Content-Length: \"{contentLength}\". Value must be a positive integral number.", exception.Message); } - [Fact] - public void ThrowsWhenSettingRawContentLengthToNonNumericValue() + [Theory] + [MemberData(nameof(BadContentLengths))] + public void ThrowsWhenSettingRawContentLengthToNonNumericValue(string contentLength) { var headers = new FrameResponseHeaders(); - Assert.Throws(() => headers.SetRawContentLength("bad", Encoding.ASCII.GetBytes("bad"))); + var exception = Assert.Throws(() => headers.SetRawContentLength(contentLength, Encoding.ASCII.GetBytes(contentLength))); + Assert.Equal($"Invalid Content-Length: \"{contentLength}\". Value must be a positive integral number.", exception.Message); } - [Fact] - public void ThrowsWhenAssigningHeaderContentLengthToNonNumericValue() + [Theory] + [MemberData(nameof(BadContentLengths))] + public void ThrowsWhenAssigningHeaderContentLengthToNonNumericValue(string contentLength) { var headers = new FrameResponseHeaders(); - Assert.Throws(() => headers.HeaderContentLength = "bad"); + + var exception = Assert.Throws(() => headers.HeaderContentLength = contentLength); + Assert.Equal($"Invalid Content-Length: \"{contentLength}\". Value must be a positive integral number.", exception.Message); } - [Fact] - public void ContentLengthValueCanBeReadAsLongAfterAddingHeader() + [Theory] + [MemberData(nameof(GoodContentLengths))] + public void ContentLengthValueCanBeReadAsLongAfterAddingHeader(string contentLength) { var headers = new FrameResponseHeaders(); var dictionary = (IDictionary)headers; - dictionary.Add("Content-Length", "42"); + dictionary.Add("Content-Length", contentLength); - Assert.Equal(42, headers.HeaderContentLengthValue); + Assert.Equal(ParseLong(contentLength), headers.HeaderContentLengthValue); } - [Fact] - public void ContentLengthValueCanBeReadAsLongAfterSettingHeader() + [Theory] + [MemberData(nameof(GoodContentLengths))] + public void ContentLengthValueCanBeReadAsLongAfterSettingHeader(string contentLength) { var headers = new FrameResponseHeaders(); var dictionary = (IDictionary)headers; - dictionary["Content-Length"] = "42"; + dictionary["Content-Length"] = contentLength; - Assert.Equal(42, headers.HeaderContentLengthValue); + Assert.Equal(ParseLong(contentLength), headers.HeaderContentLengthValue); } - [Fact] - public void ContentLengthValueCanBeReadAsLongAfterSettingRawHeader() + [Theory] + [MemberData(nameof(GoodContentLengths))] + public void ContentLengthValueCanBeReadAsLongAfterSettingRawHeader(string contentLength) { var headers = new FrameResponseHeaders(); - headers.SetRawContentLength("42", Encoding.ASCII.GetBytes("42")); + headers.SetRawContentLength(contentLength, Encoding.ASCII.GetBytes(contentLength)); - Assert.Equal(42, headers.HeaderContentLengthValue); + Assert.Equal(ParseLong(contentLength), headers.HeaderContentLengthValue); } - [Fact] - public void ContentLengthValueCanBeReadAsLongAfterAssigningHeader() + [Theory] + [MemberData(nameof(GoodContentLengths))] + public void ContentLengthValueCanBeReadAsLongAfterAssigningHeader(string contentLength) { var headers = new FrameResponseHeaders(); - headers.HeaderContentLength = "42"; + headers.HeaderContentLength = contentLength; - Assert.Equal(42, headers.HeaderContentLengthValue); + Assert.Equal(ParseLong(contentLength), headers.HeaderContentLengthValue); } [Fact] @@ -243,5 +257,33 @@ namespace Microsoft.AspNetCore.Server.KestrelTests Assert.Equal(null, headers.HeaderContentLengthValue); } + + private static long ParseLong(string value) + { + return long.Parse(value, NumberStyles.AllowLeadingWhite | NumberStyles.AllowTrailingWhite, CultureInfo.InvariantCulture); + } + + public static TheoryData GoodContentLengths => new TheoryData + { + "0", + "00", + "042", + "42", + long.MaxValue.ToString(CultureInfo.InvariantCulture) + }; + + public static TheoryData BadContentLengths => new TheoryData + { + "", + " ", + " 42", + "42 ", + "bad", + "!", + "!42", + "42!", + "42,000", + "42.000", + }; } -} +} \ No newline at end of file From 11ed34f229ac178db8fecbf45c14db4954219a2a Mon Sep 17 00:00:00 2001 From: Nathan Anderson Date: Thu, 29 Sep 2016 15:56:47 -0700 Subject: [PATCH 0924/1662] add header ordering and short circuits to known headers refactor known header changes - create template string from Append switch - add a check to ClearFast to bail out if too many headers are set --- .../Internal/Http/FrameHeaders.Generated.cs | 1796 ++++++++++++++--- .../KnownHeaders.cs | 151 +- 2 files changed, 1578 insertions(+), 369 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameHeaders.Generated.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameHeaders.Generated.cs index 82931f5681..217f47e7ba 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameHeaders.Generated.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameHeaders.Generated.cs @@ -3694,11 +3694,457 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http return MaybeUnknown?.Remove(key) ?? false; } protected override void ClearFast() - { - _bits = 0; - _headers = default(HeaderReferences); - + { MaybeUnknown?.Clear(); + + if(FrameHeaders.BitCount(_bits) > 12) + { + _headers = default(HeaderReferences); + _bits = 0; + return; + } + + + if (((_bits & 1048576L) != 0)) + { + _headers._Accept = default(StringValues); + _bits &= ~1048576L; + if(_bits == 0) + { + return; + } + } + + if (((_bits & 268435456L) != 0)) + { + _headers._Host = default(StringValues); + _bits &= ~268435456L; + if(_bits == 0) + { + return; + } + } + + if (((_bits & 1099511627776L) != 0)) + { + _headers._UserAgent = default(StringValues); + _bits &= ~1099511627776L; + if(_bits == 0) + { + return; + } + } + + if (((_bits & 1L) != 0)) + { + _headers._CacheControl = default(StringValues); + _bits &= ~1L; + if(_bits == 0) + { + return; + } + } + + if (((_bits & 2L) != 0)) + { + _headers._Connection = default(StringValues); + _bits &= ~2L; + if(_bits == 0) + { + return; + } + } + + if (((_bits & 4L) != 0)) + { + _headers._Date = default(StringValues); + _bits &= ~4L; + if(_bits == 0) + { + return; + } + } + + if (((_bits & 8L) != 0)) + { + _headers._KeepAlive = default(StringValues); + _bits &= ~8L; + if(_bits == 0) + { + return; + } + } + + if (((_bits & 16L) != 0)) + { + _headers._Pragma = default(StringValues); + _bits &= ~16L; + if(_bits == 0) + { + return; + } + } + + if (((_bits & 32L) != 0)) + { + _headers._Trailer = default(StringValues); + _bits &= ~32L; + if(_bits == 0) + { + return; + } + } + + if (((_bits & 64L) != 0)) + { + _headers._TransferEncoding = default(StringValues); + _bits &= ~64L; + if(_bits == 0) + { + return; + } + } + + if (((_bits & 128L) != 0)) + { + _headers._Upgrade = default(StringValues); + _bits &= ~128L; + if(_bits == 0) + { + return; + } + } + + if (((_bits & 256L) != 0)) + { + _headers._Via = default(StringValues); + _bits &= ~256L; + if(_bits == 0) + { + return; + } + } + + if (((_bits & 512L) != 0)) + { + _headers._Warning = default(StringValues); + _bits &= ~512L; + if(_bits == 0) + { + return; + } + } + + if (((_bits & 1024L) != 0)) + { + _headers._Allow = default(StringValues); + _bits &= ~1024L; + if(_bits == 0) + { + return; + } + } + + if (((_bits & 2048L) != 0)) + { + _headers._ContentLength = default(StringValues); + _bits &= ~2048L; + if(_bits == 0) + { + return; + } + } + + if (((_bits & 4096L) != 0)) + { + _headers._ContentType = default(StringValues); + _bits &= ~4096L; + if(_bits == 0) + { + return; + } + } + + if (((_bits & 8192L) != 0)) + { + _headers._ContentEncoding = default(StringValues); + _bits &= ~8192L; + if(_bits == 0) + { + return; + } + } + + if (((_bits & 16384L) != 0)) + { + _headers._ContentLanguage = default(StringValues); + _bits &= ~16384L; + if(_bits == 0) + { + return; + } + } + + if (((_bits & 32768L) != 0)) + { + _headers._ContentLocation = default(StringValues); + _bits &= ~32768L; + if(_bits == 0) + { + return; + } + } + + if (((_bits & 65536L) != 0)) + { + _headers._ContentMD5 = default(StringValues); + _bits &= ~65536L; + if(_bits == 0) + { + return; + } + } + + if (((_bits & 131072L) != 0)) + { + _headers._ContentRange = default(StringValues); + _bits &= ~131072L; + if(_bits == 0) + { + return; + } + } + + if (((_bits & 262144L) != 0)) + { + _headers._Expires = default(StringValues); + _bits &= ~262144L; + if(_bits == 0) + { + return; + } + } + + if (((_bits & 524288L) != 0)) + { + _headers._LastModified = default(StringValues); + _bits &= ~524288L; + if(_bits == 0) + { + return; + } + } + + if (((_bits & 2097152L) != 0)) + { + _headers._AcceptCharset = default(StringValues); + _bits &= ~2097152L; + if(_bits == 0) + { + return; + } + } + + if (((_bits & 4194304L) != 0)) + { + _headers._AcceptEncoding = default(StringValues); + _bits &= ~4194304L; + if(_bits == 0) + { + return; + } + } + + if (((_bits & 8388608L) != 0)) + { + _headers._AcceptLanguage = default(StringValues); + _bits &= ~8388608L; + if(_bits == 0) + { + return; + } + } + + if (((_bits & 16777216L) != 0)) + { + _headers._Authorization = default(StringValues); + _bits &= ~16777216L; + if(_bits == 0) + { + return; + } + } + + if (((_bits & 33554432L) != 0)) + { + _headers._Cookie = default(StringValues); + _bits &= ~33554432L; + if(_bits == 0) + { + return; + } + } + + if (((_bits & 67108864L) != 0)) + { + _headers._Expect = default(StringValues); + _bits &= ~67108864L; + if(_bits == 0) + { + return; + } + } + + if (((_bits & 134217728L) != 0)) + { + _headers._From = default(StringValues); + _bits &= ~134217728L; + if(_bits == 0) + { + return; + } + } + + if (((_bits & 536870912L) != 0)) + { + _headers._IfMatch = default(StringValues); + _bits &= ~536870912L; + if(_bits == 0) + { + return; + } + } + + if (((_bits & 1073741824L) != 0)) + { + _headers._IfModifiedSince = default(StringValues); + _bits &= ~1073741824L; + if(_bits == 0) + { + return; + } + } + + if (((_bits & 2147483648L) != 0)) + { + _headers._IfNoneMatch = default(StringValues); + _bits &= ~2147483648L; + if(_bits == 0) + { + return; + } + } + + if (((_bits & 4294967296L) != 0)) + { + _headers._IfRange = default(StringValues); + _bits &= ~4294967296L; + if(_bits == 0) + { + return; + } + } + + if (((_bits & 8589934592L) != 0)) + { + _headers._IfUnmodifiedSince = default(StringValues); + _bits &= ~8589934592L; + if(_bits == 0) + { + return; + } + } + + if (((_bits & 17179869184L) != 0)) + { + _headers._MaxForwards = default(StringValues); + _bits &= ~17179869184L; + if(_bits == 0) + { + return; + } + } + + if (((_bits & 34359738368L) != 0)) + { + _headers._ProxyAuthorization = default(StringValues); + _bits &= ~34359738368L; + if(_bits == 0) + { + return; + } + } + + if (((_bits & 68719476736L) != 0)) + { + _headers._Referer = default(StringValues); + _bits &= ~68719476736L; + if(_bits == 0) + { + return; + } + } + + if (((_bits & 137438953472L) != 0)) + { + _headers._Range = default(StringValues); + _bits &= ~137438953472L; + if(_bits == 0) + { + return; + } + } + + if (((_bits & 274877906944L) != 0)) + { + _headers._TE = default(StringValues); + _bits &= ~274877906944L; + if(_bits == 0) + { + return; + } + } + + if (((_bits & 549755813888L) != 0)) + { + _headers._Translate = default(StringValues); + _bits &= ~549755813888L; + if(_bits == 0) + { + return; + } + } + + if (((_bits & 2199023255552L) != 0)) + { + _headers._Origin = default(StringValues); + _bits &= ~2199023255552L; + if(_bits == 0) + { + return; + } + } + + if (((_bits & 4398046511104L) != 0)) + { + _headers._AccessControlRequestMethod = default(StringValues); + _bits &= ~4398046511104L; + if(_bits == 0) + { + return; + } + } + + if (((_bits & 8796093022208L) != 0)) + { + _headers._AccessControlRequestHeaders = default(StringValues); + _bits &= ~8796093022208L; + if(_bits == 0) + { + return; + } + } + } protected override void CopyToFast(KeyValuePair[] array, int arrayIndex) @@ -4197,6 +4643,86 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http public unsafe void Append(byte[] keyBytes, int keyOffset, int keyLength, string value) + { + fixed (byte* ptr = &keyBytes[keyOffset]) + { + var pUB = ptr; + var pUL = (ulong*)pUB; + var pUI = (uint*)pUB; + var pUS = (ushort*)pUB; + switch (keyLength) + { + case 6: + { + if ((((pUI[0] & 3755991007u) == 1162036033u) && ((pUS[2] & 57311u) == 21584u))) + { + if (((_bits & 1048576L) != 0)) + { + _headers._Accept = AppendValue(_headers._Accept, value); + } + else + { + _bits |= 1048576L; + _headers._Accept = new StringValues(value); + } + return; + + } + } + break; + + + + case 4: + { + if ((((pUI[0] & 3755991007u) == 1414745928u))) + { + if (((_bits & 268435456L) != 0)) + { + _headers._Host = AppendValue(_headers._Host, value); + } + else + { + _bits |= 268435456L; + _headers._Host = new StringValues(value); + } + return; + + } + } + break; + + + + case 10: + { + if ((((pUL[0] & 16131858680330051551uL) == 4992030374873092949uL) && ((pUS[4] & 57311u) == 21582u))) + { + if (((_bits & 1099511627776L) != 0)) + { + _headers._UserAgent = AppendValue(_headers._UserAgent, value); + } + else + { + _bits |= 1099511627776L; + _headers._UserAgent = new StringValues(value); + } + return; + + } + } + break; + + + } + + + } + + AppendNonPrimaryHeaders(keyBytes, keyOffset, keyLength, value); + } + + private unsafe void AppendNonPrimaryHeaders(byte[] keyBytes, int keyOffset, int keyLength, string value) { string key; fixed (byte* ptr = &keyBytes[keyOffset]) @@ -4221,6 +4747,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _headers._CacheControl = new StringValues(value); } return; + } if ((((pUL[0] & 18437701552104792031uL) == 3266321689424580419uL) && ((pUI[2] & 3755991007u) == 1196310866u) && ((pUB[12] & 223u) == 69u))) @@ -4235,6 +4762,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _headers._ContentRange = new StringValues(value); } return; + } if ((((pUL[0] & 16131858680330051551uL) == 4922237774822850892uL) && ((pUI[2] & 3755991007u) == 1162430025u) && ((pUB[12] & 223u) == 68u))) @@ -4249,6 +4777,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _headers._LastModified = new StringValues(value); } return; + } if ((((pUL[0] & 16131858542891098079uL) == 6505821637182772545uL) && ((pUI[2] & 3755991007u) == 1330205761u) && ((pUB[12] & 223u) == 78u))) @@ -4263,6 +4792,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _headers._Authorization = new StringValues(value); } return; + } if ((((pUL[0] & 18437701552106889183uL) == 3262099607620765257uL) && ((pUI[2] & 3755991007u) == 1129595213u) && ((pUB[12] & 223u) == 72u))) @@ -4277,9 +4807,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _headers._IfNoneMatch = new StringValues(value); } return; + } } break; + + case 10: { @@ -4295,6 +4828,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _headers._Connection = new StringValues(value); } return; + } if ((((pUL[0] & 16131858680330051551uL) == 5281668125874799947uL) && ((pUS[4] & 57311u) == 17750u))) @@ -4309,23 +4843,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _headers._KeepAlive = new StringValues(value); } return; - } - - if ((((pUL[0] & 16131858680330051551uL) == 4992030374873092949uL) && ((pUS[4] & 57311u) == 21582u))) - { - if (((_bits & 1099511627776L) != 0)) - { - _headers._UserAgent = AppendValue(_headers._UserAgent, value); - } - else - { - _bits |= 1099511627776L; - _headers._UserAgent = new StringValues(value); - } - return; + } } break; + + case 4: { @@ -4341,6 +4864,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _headers._Date = new StringValues(value); } return; + } if ((((pUI[0] & 3755991007u) == 1297044038u))) @@ -4355,23 +4879,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _headers._From = new StringValues(value); } return; - } - - if ((((pUI[0] & 3755991007u) == 1414745928u))) - { - if (((_bits & 268435456L) != 0)) - { - _headers._Host = AppendValue(_headers._Host, value); - } - else - { - _bits |= 268435456L; - _headers._Host = new StringValues(value); - } - return; + } } break; + + case 6: { @@ -4387,20 +4900,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _headers._Pragma = new StringValues(value); } return; - } - - if ((((pUI[0] & 3755991007u) == 1162036033u) && ((pUS[2] & 57311u) == 21584u))) - { - if (((_bits & 1048576L) != 0)) - { - _headers._Accept = AppendValue(_headers._Accept, value); - } - else - { - _bits |= 1048576L; - _headers._Accept = new StringValues(value); - } - return; + } if ((((pUI[0] & 3755991007u) == 1263488835u) && ((pUS[2] & 57311u) == 17737u))) @@ -4415,6 +4915,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _headers._Cookie = new StringValues(value); } return; + } if ((((pUI[0] & 3755991007u) == 1162893381u) && ((pUS[2] & 57311u) == 21571u))) @@ -4429,6 +4930,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _headers._Expect = new StringValues(value); } return; + } if ((((pUI[0] & 3755991007u) == 1195987535u) && ((pUS[2] & 57311u) == 20041u))) @@ -4443,9 +4945,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _headers._Origin = new StringValues(value); } return; + } } break; + + case 7: { @@ -4461,6 +4966,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _headers._Trailer = new StringValues(value); } return; + } if ((((pUI[0] & 3755991007u) == 1380405333u) && ((pUS[2] & 57311u) == 17473u) && ((pUB[6] & 223u) == 69u))) @@ -4475,6 +4981,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _headers._Upgrade = new StringValues(value); } return; + } if ((((pUI[0] & 3755991007u) == 1314013527u) && ((pUS[2] & 57311u) == 20041u) && ((pUB[6] & 223u) == 71u))) @@ -4489,6 +4996,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _headers._Warning = new StringValues(value); } return; + } if ((((pUI[0] & 3755991007u) == 1230002245u) && ((pUS[2] & 57311u) == 17746u) && ((pUB[6] & 223u) == 83u))) @@ -4503,6 +5011,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _headers._Expires = new StringValues(value); } return; + } if ((((pUI[0] & 3755991007u) == 1162233170u) && ((pUS[2] & 57311u) == 17746u) && ((pUB[6] & 223u) == 82u))) @@ -4517,9 +5026,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _headers._Referer = new StringValues(value); } return; + } } break; + + case 17: { @@ -4535,6 +5047,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _headers._TransferEncoding = new StringValues(value); } return; + } if ((((pUL[0] & 16131858542893195231uL) == 5064654363342751305uL) && ((pUL[1] & 16131858543427968991uL) == 4849894470315165001uL) && ((pUB[16] & 223u) == 69u))) @@ -4549,9 +5062,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _headers._IfModifiedSince = new StringValues(value); } return; + } } break; + + case 3: { @@ -4567,9 +5083,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _headers._Via = new StringValues(value); } return; + } } break; + + case 5: { @@ -4585,6 +5104,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _headers._Allow = new StringValues(value); } return; + } if ((((pUI[0] & 3755991007u) == 1196310866u) && ((pUB[4] & 223u) == 69u))) @@ -4599,9 +5119,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _headers._Range = new StringValues(value); } return; + } } break; + + case 14: { @@ -4617,6 +5140,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _headers._ContentLength = new StringValues(value); } return; + } if ((((pUL[0] & 16140865742145839071uL) == 4840617878229304129uL) && ((pUI[2] & 3755991007u) == 1397899592u) && ((pUS[6] & 57311u) == 21573u))) @@ -4631,9 +5155,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _headers._AcceptCharset = new StringValues(value); } return; + } } break; + + case 12: { @@ -4649,6 +5176,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _headers._ContentType = new StringValues(value); } return; + } if ((((pUL[0] & 16131858543427968991uL) == 6292178792217067853uL) && ((pUI[2] & 3755991007u) == 1396986433u))) @@ -4663,9 +5191,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _headers._MaxForwards = new StringValues(value); } return; + } } break; + + case 16: { @@ -4681,6 +5212,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _headers._ContentEncoding = new StringValues(value); } return; + } if ((((pUL[0] & 18437701552104792031uL) == 3266321689424580419uL) && ((pUL[1] & 16131858542891098079uL) == 4992030546487820620uL))) @@ -4695,6 +5227,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _headers._ContentLanguage = new StringValues(value); } return; + } if ((((pUL[0] & 18437701552104792031uL) == 3266321689424580419uL) && ((pUL[1] & 16131858542891098079uL) == 5642809484339531596uL))) @@ -4709,9 +5242,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _headers._ContentLocation = new StringValues(value); } return; + } } break; + + case 11: { @@ -4727,9 +5263,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _headers._ContentMD5 = new StringValues(value); } return; + } } break; + + case 15: { @@ -4745,6 +5284,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _headers._AcceptEncoding = new StringValues(value); } return; + } if ((((pUL[0] & 16140865742145839071uL) == 5489136224570655553uL) && ((pUI[2] & 3755991007u) == 1430736449u) && ((pUS[6] & 57311u) == 18241u) && ((pUB[14] & 223u) == 69u))) @@ -4759,9 +5299,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _headers._AcceptLanguage = new StringValues(value); } return; + } } break; + + case 8: { @@ -4777,6 +5320,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _headers._IfMatch = new StringValues(value); } return; + } if ((((pUL[0] & 16131858542893195231uL) == 4992044754422023753uL))) @@ -4791,9 +5335,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _headers._IfRange = new StringValues(value); } return; + } } break; + + case 19: { @@ -4809,6 +5356,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _headers._IfUnmodifiedSince = new StringValues(value); } return; + } if ((((pUL[0] & 16131893727263186911uL) == 6143241228466999888uL) && ((pUL[1] & 16131858542891098079uL) == 6071233043632179284uL) && ((pUS[8] & 57311u) == 20297u) && ((pUB[18] & 223u) == 78u))) @@ -4823,9 +5371,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _headers._ProxyAuthorization = new StringValues(value); } return; + } } break; + + case 2: { @@ -4841,9 +5392,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _headers._TE = new StringValues(value); } return; + } } break; + + case 9: { @@ -4859,9 +5413,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _headers._Translate = new StringValues(value); } return; + } } break; + + case 29: { @@ -4877,9 +5434,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _headers._AccessControlRequestMethod = new StringValues(value); } return; + } } break; + + case 30: { @@ -4895,19 +5455,24 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _headers._AccessControlRequestHeaders = new StringValues(value); } return; + } } break; + + } - key = new string('\0', keyLength); - fixed(char *keyBuffer = key) - { - if (!AsciiUtilities.TryGetAsciiString(ptr, keyBuffer, keyLength)) + + key = new string('\0', keyLength); + fixed(char *keyBuffer = key) { - throw BadHttpRequestException.GetException(RequestRejectionReason.InvalidCharactersInHeaderName); + if (!AsciiUtilities.TryGetAsciiString(ptr, keyBuffer, keyLength)) + { + throw BadHttpRequestException.GetException(RequestRejectionReason.InvalidCharactersInHeaderName); + } } - } + } StringValues existing; @@ -8604,11 +9169,377 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http return MaybeUnknown?.Remove(key) ?? false; } protected override void ClearFast() - { - _bits = 0; - _headers = default(HeaderReferences); - _contentLength = null; + { MaybeUnknown?.Clear(); + _contentLength = null; + if(FrameHeaders.BitCount(_bits) > 12) + { + _headers = default(HeaderReferences); + _bits = 0; + return; + } + + + if (((_bits & 2L) != 0)) + { + _headers._Connection = default(StringValues); + _bits &= ~2L; + if(_bits == 0) + { + return; + } + } + + if (((_bits & 4L) != 0)) + { + _headers._Date = default(StringValues); + _bits &= ~4L; + if(_bits == 0) + { + return; + } + } + + if (((_bits & 2048L) != 0)) + { + _headers._ContentLength = default(StringValues); + _bits &= ~2048L; + if(_bits == 0) + { + return; + } + } + + if (((_bits & 4096L) != 0)) + { + _headers._ContentType = default(StringValues); + _bits &= ~4096L; + if(_bits == 0) + { + return; + } + } + + if (((_bits & 67108864L) != 0)) + { + _headers._Server = default(StringValues); + _bits &= ~67108864L; + if(_bits == 0) + { + return; + } + } + + if (((_bits & 1L) != 0)) + { + _headers._CacheControl = default(StringValues); + _bits &= ~1L; + if(_bits == 0) + { + return; + } + } + + if (((_bits & 8L) != 0)) + { + _headers._KeepAlive = default(StringValues); + _bits &= ~8L; + if(_bits == 0) + { + return; + } + } + + if (((_bits & 16L) != 0)) + { + _headers._Pragma = default(StringValues); + _bits &= ~16L; + if(_bits == 0) + { + return; + } + } + + if (((_bits & 32L) != 0)) + { + _headers._Trailer = default(StringValues); + _bits &= ~32L; + if(_bits == 0) + { + return; + } + } + + if (((_bits & 64L) != 0)) + { + _headers._TransferEncoding = default(StringValues); + _bits &= ~64L; + if(_bits == 0) + { + return; + } + } + + if (((_bits & 128L) != 0)) + { + _headers._Upgrade = default(StringValues); + _bits &= ~128L; + if(_bits == 0) + { + return; + } + } + + if (((_bits & 256L) != 0)) + { + _headers._Via = default(StringValues); + _bits &= ~256L; + if(_bits == 0) + { + return; + } + } + + if (((_bits & 512L) != 0)) + { + _headers._Warning = default(StringValues); + _bits &= ~512L; + if(_bits == 0) + { + return; + } + } + + if (((_bits & 1024L) != 0)) + { + _headers._Allow = default(StringValues); + _bits &= ~1024L; + if(_bits == 0) + { + return; + } + } + + if (((_bits & 8192L) != 0)) + { + _headers._ContentEncoding = default(StringValues); + _bits &= ~8192L; + if(_bits == 0) + { + return; + } + } + + if (((_bits & 16384L) != 0)) + { + _headers._ContentLanguage = default(StringValues); + _bits &= ~16384L; + if(_bits == 0) + { + return; + } + } + + if (((_bits & 32768L) != 0)) + { + _headers._ContentLocation = default(StringValues); + _bits &= ~32768L; + if(_bits == 0) + { + return; + } + } + + if (((_bits & 65536L) != 0)) + { + _headers._ContentMD5 = default(StringValues); + _bits &= ~65536L; + if(_bits == 0) + { + return; + } + } + + if (((_bits & 131072L) != 0)) + { + _headers._ContentRange = default(StringValues); + _bits &= ~131072L; + if(_bits == 0) + { + return; + } + } + + if (((_bits & 262144L) != 0)) + { + _headers._Expires = default(StringValues); + _bits &= ~262144L; + if(_bits == 0) + { + return; + } + } + + if (((_bits & 524288L) != 0)) + { + _headers._LastModified = default(StringValues); + _bits &= ~524288L; + if(_bits == 0) + { + return; + } + } + + if (((_bits & 1048576L) != 0)) + { + _headers._AcceptRanges = default(StringValues); + _bits &= ~1048576L; + if(_bits == 0) + { + return; + } + } + + if (((_bits & 2097152L) != 0)) + { + _headers._Age = default(StringValues); + _bits &= ~2097152L; + if(_bits == 0) + { + return; + } + } + + if (((_bits & 4194304L) != 0)) + { + _headers._ETag = default(StringValues); + _bits &= ~4194304L; + if(_bits == 0) + { + return; + } + } + + if (((_bits & 8388608L) != 0)) + { + _headers._Location = default(StringValues); + _bits &= ~8388608L; + if(_bits == 0) + { + return; + } + } + + if (((_bits & 16777216L) != 0)) + { + _headers._ProxyAutheticate = default(StringValues); + _bits &= ~16777216L; + if(_bits == 0) + { + return; + } + } + + if (((_bits & 33554432L) != 0)) + { + _headers._RetryAfter = default(StringValues); + _bits &= ~33554432L; + if(_bits == 0) + { + return; + } + } + + if (((_bits & 134217728L) != 0)) + { + _headers._SetCookie = default(StringValues); + _bits &= ~134217728L; + if(_bits == 0) + { + return; + } + } + + if (((_bits & 268435456L) != 0)) + { + _headers._Vary = default(StringValues); + _bits &= ~268435456L; + if(_bits == 0) + { + return; + } + } + + if (((_bits & 536870912L) != 0)) + { + _headers._WWWAuthenticate = default(StringValues); + _bits &= ~536870912L; + if(_bits == 0) + { + return; + } + } + + if (((_bits & 1073741824L) != 0)) + { + _headers._AccessControlAllowCredentials = default(StringValues); + _bits &= ~1073741824L; + if(_bits == 0) + { + return; + } + } + + if (((_bits & 2147483648L) != 0)) + { + _headers._AccessControlAllowHeaders = default(StringValues); + _bits &= ~2147483648L; + if(_bits == 0) + { + return; + } + } + + if (((_bits & 4294967296L) != 0)) + { + _headers._AccessControlAllowMethods = default(StringValues); + _bits &= ~4294967296L; + if(_bits == 0) + { + return; + } + } + + if (((_bits & 8589934592L) != 0)) + { + _headers._AccessControlAllowOrigin = default(StringValues); + _bits &= ~8589934592L; + if(_bits == 0) + { + return; + } + } + + if (((_bits & 17179869184L) != 0)) + { + _headers._AccessControlExposeHeaders = default(StringValues); + _bits &= ~17179869184L; + if(_bits == 0) + { + return; + } + } + + if (((_bits & 34359738368L) != 0)) + { + _headers._AccessControlMaxAge = default(StringValues); + _bits &= ~34359738368L; + if(_bits == 0) + { + return; + } + } + } protected override void CopyToFast(KeyValuePair[] array, int arrayIndex) @@ -9019,18 +9950,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http protected void CopyToFast(ref MemoryPoolIterator output) { - - if (((_bits & 1L) != 0)) - { - foreach (var value in _headers._CacheControl) - { - if (value != null) - { - output.CopyFrom(_headerBytes, 0, 17); - output.CopyFromAscii(value); - } - } - } + var tempBits = _bits; if (((_bits & 2L) != 0)) { @@ -9047,6 +9967,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http output.CopyFromAscii(value); } } + + tempBits &= ~2L; + if(tempBits == 0) + { + return; + } } if (((_bits & 4L) != 0)) @@ -9064,107 +9990,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http output.CopyFromAscii(value); } } - } - - if (((_bits & 8L) != 0)) - { - foreach (var value in _headers._KeepAlive) - { - if (value != null) - { - output.CopyFrom(_headerBytes, 39, 14); - output.CopyFromAscii(value); - } - } - } - - if (((_bits & 16L) != 0)) - { - foreach (var value in _headers._Pragma) - { - if (value != null) - { - output.CopyFrom(_headerBytes, 53, 10); - output.CopyFromAscii(value); - } - } - } - - if (((_bits & 32L) != 0)) - { - foreach (var value in _headers._Trailer) - { - if (value != null) - { - output.CopyFrom(_headerBytes, 63, 11); - output.CopyFromAscii(value); - } - } - } - - if (((_bits & 64L) != 0)) - { - if (_headers._rawTransferEncoding != null) + + tempBits &= ~4L; + if(tempBits == 0) { - output.CopyFrom(_headers._rawTransferEncoding, 0, _headers._rawTransferEncoding.Length); + return; } - else - foreach (var value in _headers._TransferEncoding) - { - if (value != null) - { - output.CopyFrom(_headerBytes, 74, 21); - output.CopyFromAscii(value); - } - } - } - - if (((_bits & 128L) != 0)) - { - foreach (var value in _headers._Upgrade) - { - if (value != null) - { - output.CopyFrom(_headerBytes, 95, 11); - output.CopyFromAscii(value); - } - } - } - - if (((_bits & 256L) != 0)) - { - foreach (var value in _headers._Via) - { - if (value != null) - { - output.CopyFrom(_headerBytes, 106, 7); - output.CopyFromAscii(value); - } - } - } - - if (((_bits & 512L) != 0)) - { - foreach (var value in _headers._Warning) - { - if (value != null) - { - output.CopyFrom(_headerBytes, 113, 11); - output.CopyFromAscii(value); - } - } - } - - if (((_bits & 1024L) != 0)) - { - foreach (var value in _headers._Allow) - { - if (value != null) - { - output.CopyFrom(_headerBytes, 124, 9); - output.CopyFromAscii(value); - } - } } if (((_bits & 2048L) != 0)) @@ -9182,6 +10013,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http output.CopyFromAscii(value); } } + + tempBits &= ~2048L; + if(tempBits == 0) + { + return; + } } if (((_bits & 4096L) != 0)) @@ -9194,162 +10031,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http output.CopyFromAscii(value); } } - } - - if (((_bits & 8192L) != 0)) - { - foreach (var value in _headers._ContentEncoding) - { - if (value != null) - { - output.CopyFrom(_headerBytes, 167, 20); - output.CopyFromAscii(value); - } - } - } - - if (((_bits & 16384L) != 0)) - { - foreach (var value in _headers._ContentLanguage) - { - if (value != null) - { - output.CopyFrom(_headerBytes, 187, 20); - output.CopyFromAscii(value); - } - } - } - - if (((_bits & 32768L) != 0)) - { - foreach (var value in _headers._ContentLocation) - { - if (value != null) - { - output.CopyFrom(_headerBytes, 207, 20); - output.CopyFromAscii(value); - } - } - } - - if (((_bits & 65536L) != 0)) - { - foreach (var value in _headers._ContentMD5) - { - if (value != null) - { - output.CopyFrom(_headerBytes, 227, 15); - output.CopyFromAscii(value); - } - } - } - - if (((_bits & 131072L) != 0)) - { - foreach (var value in _headers._ContentRange) - { - if (value != null) - { - output.CopyFrom(_headerBytes, 242, 17); - output.CopyFromAscii(value); - } - } - } - - if (((_bits & 262144L) != 0)) - { - foreach (var value in _headers._Expires) - { - if (value != null) - { - output.CopyFrom(_headerBytes, 259, 11); - output.CopyFromAscii(value); - } - } - } - - if (((_bits & 524288L) != 0)) - { - foreach (var value in _headers._LastModified) - { - if (value != null) - { - output.CopyFrom(_headerBytes, 270, 17); - output.CopyFromAscii(value); - } - } - } - - if (((_bits & 1048576L) != 0)) - { - foreach (var value in _headers._AcceptRanges) - { - if (value != null) - { - output.CopyFrom(_headerBytes, 287, 17); - output.CopyFromAscii(value); - } - } - } - - if (((_bits & 2097152L) != 0)) - { - foreach (var value in _headers._Age) - { - if (value != null) - { - output.CopyFrom(_headerBytes, 304, 7); - output.CopyFromAscii(value); - } - } - } - - if (((_bits & 4194304L) != 0)) - { - foreach (var value in _headers._ETag) - { - if (value != null) - { - output.CopyFrom(_headerBytes, 311, 8); - output.CopyFromAscii(value); - } - } - } - - if (((_bits & 8388608L) != 0)) - { - foreach (var value in _headers._Location) - { - if (value != null) - { - output.CopyFrom(_headerBytes, 319, 12); - output.CopyFromAscii(value); - } - } - } - - if (((_bits & 16777216L) != 0)) - { - foreach (var value in _headers._ProxyAutheticate) - { - if (value != null) - { - output.CopyFrom(_headerBytes, 331, 21); - output.CopyFromAscii(value); - } - } - } - - if (((_bits & 33554432L) != 0)) - { - foreach (var value in _headers._RetryAfter) - { - if (value != null) - { - output.CopyFrom(_headerBytes, 352, 15); - output.CopyFromAscii(value); - } - } + + tempBits &= ~4096L; + if(tempBits == 0) + { + return; + } } if (((_bits & 67108864L) != 0)) @@ -9367,6 +10054,413 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http output.CopyFromAscii(value); } } + + tempBits &= ~67108864L; + if(tempBits == 0) + { + return; + } + } + + if (((_bits & 1L) != 0)) + { + foreach (var value in _headers._CacheControl) + { + if (value != null) + { + output.CopyFrom(_headerBytes, 0, 17); + output.CopyFromAscii(value); + } + } + + tempBits &= ~1L; + if(tempBits == 0) + { + return; + } + } + + if (((_bits & 8L) != 0)) + { + foreach (var value in _headers._KeepAlive) + { + if (value != null) + { + output.CopyFrom(_headerBytes, 39, 14); + output.CopyFromAscii(value); + } + } + + tempBits &= ~8L; + if(tempBits == 0) + { + return; + } + } + + if (((_bits & 16L) != 0)) + { + foreach (var value in _headers._Pragma) + { + if (value != null) + { + output.CopyFrom(_headerBytes, 53, 10); + output.CopyFromAscii(value); + } + } + + tempBits &= ~16L; + if(tempBits == 0) + { + return; + } + } + + if (((_bits & 32L) != 0)) + { + foreach (var value in _headers._Trailer) + { + if (value != null) + { + output.CopyFrom(_headerBytes, 63, 11); + output.CopyFromAscii(value); + } + } + + tempBits &= ~32L; + if(tempBits == 0) + { + return; + } + } + + if (((_bits & 64L) != 0)) + { + if (_headers._rawTransferEncoding != null) + { + output.CopyFrom(_headers._rawTransferEncoding, 0, _headers._rawTransferEncoding.Length); + } + else + foreach (var value in _headers._TransferEncoding) + { + if (value != null) + { + output.CopyFrom(_headerBytes, 74, 21); + output.CopyFromAscii(value); + } + } + + tempBits &= ~64L; + if(tempBits == 0) + { + return; + } + } + + if (((_bits & 128L) != 0)) + { + foreach (var value in _headers._Upgrade) + { + if (value != null) + { + output.CopyFrom(_headerBytes, 95, 11); + output.CopyFromAscii(value); + } + } + + tempBits &= ~128L; + if(tempBits == 0) + { + return; + } + } + + if (((_bits & 256L) != 0)) + { + foreach (var value in _headers._Via) + { + if (value != null) + { + output.CopyFrom(_headerBytes, 106, 7); + output.CopyFromAscii(value); + } + } + + tempBits &= ~256L; + if(tempBits == 0) + { + return; + } + } + + if (((_bits & 512L) != 0)) + { + foreach (var value in _headers._Warning) + { + if (value != null) + { + output.CopyFrom(_headerBytes, 113, 11); + output.CopyFromAscii(value); + } + } + + tempBits &= ~512L; + if(tempBits == 0) + { + return; + } + } + + if (((_bits & 1024L) != 0)) + { + foreach (var value in _headers._Allow) + { + if (value != null) + { + output.CopyFrom(_headerBytes, 124, 9); + output.CopyFromAscii(value); + } + } + + tempBits &= ~1024L; + if(tempBits == 0) + { + return; + } + } + + if (((_bits & 8192L) != 0)) + { + foreach (var value in _headers._ContentEncoding) + { + if (value != null) + { + output.CopyFrom(_headerBytes, 167, 20); + output.CopyFromAscii(value); + } + } + + tempBits &= ~8192L; + if(tempBits == 0) + { + return; + } + } + + if (((_bits & 16384L) != 0)) + { + foreach (var value in _headers._ContentLanguage) + { + if (value != null) + { + output.CopyFrom(_headerBytes, 187, 20); + output.CopyFromAscii(value); + } + } + + tempBits &= ~16384L; + if(tempBits == 0) + { + return; + } + } + + if (((_bits & 32768L) != 0)) + { + foreach (var value in _headers._ContentLocation) + { + if (value != null) + { + output.CopyFrom(_headerBytes, 207, 20); + output.CopyFromAscii(value); + } + } + + tempBits &= ~32768L; + if(tempBits == 0) + { + return; + } + } + + if (((_bits & 65536L) != 0)) + { + foreach (var value in _headers._ContentMD5) + { + if (value != null) + { + output.CopyFrom(_headerBytes, 227, 15); + output.CopyFromAscii(value); + } + } + + tempBits &= ~65536L; + if(tempBits == 0) + { + return; + } + } + + if (((_bits & 131072L) != 0)) + { + foreach (var value in _headers._ContentRange) + { + if (value != null) + { + output.CopyFrom(_headerBytes, 242, 17); + output.CopyFromAscii(value); + } + } + + tempBits &= ~131072L; + if(tempBits == 0) + { + return; + } + } + + if (((_bits & 262144L) != 0)) + { + foreach (var value in _headers._Expires) + { + if (value != null) + { + output.CopyFrom(_headerBytes, 259, 11); + output.CopyFromAscii(value); + } + } + + tempBits &= ~262144L; + if(tempBits == 0) + { + return; + } + } + + if (((_bits & 524288L) != 0)) + { + foreach (var value in _headers._LastModified) + { + if (value != null) + { + output.CopyFrom(_headerBytes, 270, 17); + output.CopyFromAscii(value); + } + } + + tempBits &= ~524288L; + if(tempBits == 0) + { + return; + } + } + + if (((_bits & 1048576L) != 0)) + { + foreach (var value in _headers._AcceptRanges) + { + if (value != null) + { + output.CopyFrom(_headerBytes, 287, 17); + output.CopyFromAscii(value); + } + } + + tempBits &= ~1048576L; + if(tempBits == 0) + { + return; + } + } + + if (((_bits & 2097152L) != 0)) + { + foreach (var value in _headers._Age) + { + if (value != null) + { + output.CopyFrom(_headerBytes, 304, 7); + output.CopyFromAscii(value); + } + } + + tempBits &= ~2097152L; + if(tempBits == 0) + { + return; + } + } + + if (((_bits & 4194304L) != 0)) + { + foreach (var value in _headers._ETag) + { + if (value != null) + { + output.CopyFrom(_headerBytes, 311, 8); + output.CopyFromAscii(value); + } + } + + tempBits &= ~4194304L; + if(tempBits == 0) + { + return; + } + } + + if (((_bits & 8388608L) != 0)) + { + foreach (var value in _headers._Location) + { + if (value != null) + { + output.CopyFrom(_headerBytes, 319, 12); + output.CopyFromAscii(value); + } + } + + tempBits &= ~8388608L; + if(tempBits == 0) + { + return; + } + } + + if (((_bits & 16777216L) != 0)) + { + foreach (var value in _headers._ProxyAutheticate) + { + if (value != null) + { + output.CopyFrom(_headerBytes, 331, 21); + output.CopyFromAscii(value); + } + } + + tempBits &= ~16777216L; + if(tempBits == 0) + { + return; + } + } + + if (((_bits & 33554432L) != 0)) + { + foreach (var value in _headers._RetryAfter) + { + if (value != null) + { + output.CopyFrom(_headerBytes, 352, 15); + output.CopyFromAscii(value); + } + } + + tempBits &= ~33554432L; + if(tempBits == 0) + { + return; + } } if (((_bits & 134217728L) != 0)) @@ -9379,6 +10473,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http output.CopyFromAscii(value); } } + + tempBits &= ~134217728L; + if(tempBits == 0) + { + return; + } } if (((_bits & 268435456L) != 0)) @@ -9391,6 +10491,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http output.CopyFromAscii(value); } } + + tempBits &= ~268435456L; + if(tempBits == 0) + { + return; + } } if (((_bits & 536870912L) != 0)) @@ -9403,6 +10509,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http output.CopyFromAscii(value); } } + + tempBits &= ~536870912L; + if(tempBits == 0) + { + return; + } } if (((_bits & 1073741824L) != 0)) @@ -9415,6 +10527,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http output.CopyFromAscii(value); } } + + tempBits &= ~1073741824L; + if(tempBits == 0) + { + return; + } } if (((_bits & 2147483648L) != 0)) @@ -9427,6 +10545,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http output.CopyFromAscii(value); } } + + tempBits &= ~2147483648L; + if(tempBits == 0) + { + return; + } } if (((_bits & 4294967296L) != 0)) @@ -9439,6 +10563,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http output.CopyFromAscii(value); } } + + tempBits &= ~4294967296L; + if(tempBits == 0) + { + return; + } } if (((_bits & 8589934592L) != 0)) @@ -9451,6 +10581,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http output.CopyFromAscii(value); } } + + tempBits &= ~8589934592L; + if(tempBits == 0) + { + return; + } } if (((_bits & 17179869184L) != 0)) @@ -9463,6 +10599,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http output.CopyFromAscii(value); } } + + tempBits &= ~17179869184L; + if(tempBits == 0) + { + return; + } } if (((_bits & 34359738368L) != 0)) @@ -9475,10 +10617,18 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http output.CopyFromAscii(value); } } + + tempBits &= ~34359738368L; + if(tempBits == 0) + { + return; + } } } + + private struct HeaderReferences { public StringValues _CacheControl; diff --git a/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/KnownHeaders.cs b/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/KnownHeaders.cs index 8cb51355ac..a062349f74 100644 --- a/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/KnownHeaders.cs +++ b/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/KnownHeaders.cs @@ -19,6 +19,51 @@ namespace Microsoft.AspNetCore.Server.Kestrel.GeneratedCode return condition ? formatter() : ""; } + static string AppendSwitch(IEnumerable> values, string className, bool handleUnknown = false) => + $@"fixed (byte* ptr = &keyBytes[keyOffset]) + {{ + var pUB = ptr; + var pUL = (ulong*)pUB; + var pUI = (uint*)pUB; + var pUS = (ushort*)pUB; + switch (keyLength) + {{{Each(values, byLength => $@" + case {byLength.Key}: + {{{Each(byLength, header => $@" + if ({header.EqualIgnoreCaseBytes()}) + {{ + if ({header.TestBit()}) + {{ + _headers._{header.Identifier} = AppendValue(_headers._{header.Identifier}, value); + }} + else + {{{If(className == "FrameResponseHeaders" && header.Identifier == "ContentLength", () => @" + _contentLength = ParseContentLength(value);")} + {header.SetBit()}; + _headers._{header.Identifier} = new StringValues(value);{(header.EnhancedSetter == false ? "" : $@" + _headers._raw{header.Identifier} = null;")} + }} + return; + + }} + ")}}} + break; + + + ")}}} + + {(handleUnknown ? $@" + key = new string('\0', keyLength); + fixed(char *keyBuffer = key) + {{ + if (!AsciiUtilities.TryGetAsciiString(ptr, keyBuffer, keyLength)) + {{ + throw BadHttpRequestException.GetException(RequestRejectionReason.InvalidCharactersInHeaderName); + }} + }} + ": "")} + }}"; + class KnownHeader { public string Name { get; set; } @@ -29,9 +74,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.GeneratedCode public int BytesOffset { get; set; } public int BytesCount { get; set; } public bool EnhancedSetter { get; set; } + public bool PrimaryHeader { get; set; } public string TestBit() => $"((_bits & {1L << Index}L) != 0)"; public string SetBit() => $"_bits |= {1L << Index}L"; public string ClearBit() => $"_bits &= ~{1L << Index}L"; + public string EqualIgnoreCaseBytes() { var result = ""; @@ -80,6 +127,21 @@ namespace Microsoft.AspNetCore.Server.Kestrel.GeneratedCode public static string GeneratedFile() { + var requestPrimaryHeaders = new[] + { + "Accept", + "Host", + "User-Agent" + + }; + var responsePrimaryHeaders = new[] + { + "Connection", + "Date", + "Content-Length", + "Content-Type", + "Server", + }; var commonHeaders = new[] { "Cache-Control", @@ -136,7 +198,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.GeneratedCode }).Concat(corsRequestHeaders).Select((header, index) => new KnownHeader { Name = header, - Index = index + Index = index, + PrimaryHeader = requestPrimaryHeaders.Contains(header) }).ToArray(); var enhancedHeaders = new[] { @@ -172,7 +235,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.GeneratedCode { Name = header, Index = index, - EnhancedSetter = enhancedHeaders.Contains(header) + EnhancedSetter = enhancedHeaders.Contains(header), + PrimaryHeader = responsePrimaryHeaders.Contains(header) }).ToArray(); var loops = new[] { @@ -377,11 +441,27 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http return MaybeUnknown?.Remove(key) ?? false; }} protected override void ClearFast() - {{ - _bits = 0; - _headers = default(HeaderReferences); - {(loop.ClassName == "FrameResponseHeaders" ? "_contentLength = null;" : "")} + {{ MaybeUnknown?.Clear(); + {(loop.ClassName == "FrameResponseHeaders" ? "_contentLength = null;" : "")} + if(FrameHeaders.BitCount(_bits) > 12) + {{ + _headers = default(HeaderReferences); + _bits = 0; + return; + }} + + {Each(loop.Headers.OrderBy(h => !h.PrimaryHeader), header => $@" + if ({header.TestBit()}) + {{ + _headers._{header.Identifier} = default(StringValues); + {header.ClearBit()}; + if(_bits == 0) + {{ + return; + }} + }} + ")} }} protected override void CopyToFast(KeyValuePair[] array, int arrayIndex) @@ -407,7 +487,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http {(loop.ClassName == "FrameResponseHeaders" ? $@" protected void CopyToFast(ref MemoryPoolIterator output) {{ - {Each(loop.Headers, header => $@" + var tempBits = _bits; + {Each(loop.Headers.OrderBy(h => !h.PrimaryHeader), header => $@" if ({header.TestBit()}) {{ {(header.EnhancedSetter == false ? "" : $@" if (_headers._raw{header.Identifier} != null) @@ -423,51 +504,29 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http output.CopyFromAscii(value); }} }} + + tempBits &= ~{1L << header.Index}L; + if(tempBits == 0) + {{ + return; + }} }} ")} - }}" : "")} + }} + + " : "")} {(loop.ClassName == "FrameRequestHeaders" ? $@" public unsafe void Append(byte[] keyBytes, int keyOffset, int keyLength, string value) + {{ + {AppendSwitch(loop.Headers.Where(h => h.PrimaryHeader).GroupBy(x => x.Name.Length), loop.ClassName)} + + AppendNonPrimaryHeaders(keyBytes, keyOffset, keyLength, value); + }} + + private unsafe void AppendNonPrimaryHeaders(byte[] keyBytes, int keyOffset, int keyLength, string value) {{ string key; - fixed (byte* ptr = &keyBytes[keyOffset]) - {{ - var pUB = ptr; - var pUL = (ulong*)pUB; - var pUI = (uint*)pUB; - var pUS = (ushort*)pUB; - switch (keyLength) - {{{Each(loop.HeadersByLength, byLength => $@" - case {byLength.Key}: - {{{Each(byLength, header => $@" - if ({header.EqualIgnoreCaseBytes()}) - {{ - if ({header.TestBit()}) - {{ - _headers._{header.Identifier} = AppendValue(_headers._{header.Identifier}, value); - }} - else - {{{If(loop.ClassName == "FrameResponseHeaders" && header.Identifier == "ContentLength", () => @" - _contentLength = ParseContentLength(value);")} - {header.SetBit()}; - _headers._{header.Identifier} = new StringValues(value);{(header.EnhancedSetter == false ? "" : $@" - _headers._raw{header.Identifier} = null;")} - }} - return; - }} - ")}}} - break; - ")}}} - - key = new string('\0', keyLength); - fixed(char *keyBuffer = key) - {{ - if (!AsciiUtilities.TryGetAsciiString(ptr, keyBuffer, keyLength)) - {{ - throw BadHttpRequestException.GetException(RequestRejectionReason.InvalidCharactersInHeaderName); - }} - }} - }} + {AppendSwitch(loop.Headers.Where(h => !h.PrimaryHeader).GroupBy(x => x.Name.Length), loop.ClassName, true)} StringValues existing; Unknown.TryGetValue(key, out existing); From 610601cc6e77ce91d85a8e238e57b3dc57809d61 Mon Sep 17 00:00:00 2001 From: Nathan Anderson Date: Thu, 20 Oct 2016 15:23:03 -0700 Subject: [PATCH 0925/1662] test fixes and whitespace changes to generated code --- .../Internal/Http/FrameHeaders.Generated.cs | 1210 ++++++++--------- .../ResponseTests.cs | 4 +- .../KnownHeaders.cs | 18 +- 3 files changed, 569 insertions(+), 663 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameHeaders.Generated.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameHeaders.Generated.cs index 217f47e7ba..c7502e61af 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameHeaders.Generated.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameHeaders.Generated.cs @@ -3703,447 +3703,446 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _bits = 0; return; } - - if (((_bits & 1048576L) != 0)) + if (((_bits & 1048576L) != 0)) + { + _headers._Accept = default(StringValues); + _bits &= ~1048576L; + if(_bits == 0) { - _headers._Accept = default(StringValues); - _bits &= ~1048576L; - if(_bits == 0) - { - return; - } + return; } + } - if (((_bits & 268435456L) != 0)) + if (((_bits & 268435456L) != 0)) + { + _headers._Host = default(StringValues); + _bits &= ~268435456L; + if(_bits == 0) { - _headers._Host = default(StringValues); - _bits &= ~268435456L; - if(_bits == 0) - { - return; - } + return; } + } - if (((_bits & 1099511627776L) != 0)) + if (((_bits & 1099511627776L) != 0)) + { + _headers._UserAgent = default(StringValues); + _bits &= ~1099511627776L; + if(_bits == 0) { - _headers._UserAgent = default(StringValues); - _bits &= ~1099511627776L; - if(_bits == 0) - { - return; - } + return; } + } - if (((_bits & 1L) != 0)) + if (((_bits & 1L) != 0)) + { + _headers._CacheControl = default(StringValues); + _bits &= ~1L; + if(_bits == 0) { - _headers._CacheControl = default(StringValues); - _bits &= ~1L; - if(_bits == 0) - { - return; - } + return; } + } - if (((_bits & 2L) != 0)) + if (((_bits & 2L) != 0)) + { + _headers._Connection = default(StringValues); + _bits &= ~2L; + if(_bits == 0) { - _headers._Connection = default(StringValues); - _bits &= ~2L; - if(_bits == 0) - { - return; - } + return; } + } - if (((_bits & 4L) != 0)) + if (((_bits & 4L) != 0)) + { + _headers._Date = default(StringValues); + _bits &= ~4L; + if(_bits == 0) { - _headers._Date = default(StringValues); - _bits &= ~4L; - if(_bits == 0) - { - return; - } + return; } + } - if (((_bits & 8L) != 0)) + if (((_bits & 8L) != 0)) + { + _headers._KeepAlive = default(StringValues); + _bits &= ~8L; + if(_bits == 0) { - _headers._KeepAlive = default(StringValues); - _bits &= ~8L; - if(_bits == 0) - { - return; - } + return; } + } - if (((_bits & 16L) != 0)) + if (((_bits & 16L) != 0)) + { + _headers._Pragma = default(StringValues); + _bits &= ~16L; + if(_bits == 0) { - _headers._Pragma = default(StringValues); - _bits &= ~16L; - if(_bits == 0) - { - return; - } + return; } + } - if (((_bits & 32L) != 0)) + if (((_bits & 32L) != 0)) + { + _headers._Trailer = default(StringValues); + _bits &= ~32L; + if(_bits == 0) { - _headers._Trailer = default(StringValues); - _bits &= ~32L; - if(_bits == 0) - { - return; - } + return; } + } - if (((_bits & 64L) != 0)) + if (((_bits & 64L) != 0)) + { + _headers._TransferEncoding = default(StringValues); + _bits &= ~64L; + if(_bits == 0) { - _headers._TransferEncoding = default(StringValues); - _bits &= ~64L; - if(_bits == 0) - { - return; - } + return; } + } - if (((_bits & 128L) != 0)) + if (((_bits & 128L) != 0)) + { + _headers._Upgrade = default(StringValues); + _bits &= ~128L; + if(_bits == 0) { - _headers._Upgrade = default(StringValues); - _bits &= ~128L; - if(_bits == 0) - { - return; - } + return; } + } - if (((_bits & 256L) != 0)) + if (((_bits & 256L) != 0)) + { + _headers._Via = default(StringValues); + _bits &= ~256L; + if(_bits == 0) { - _headers._Via = default(StringValues); - _bits &= ~256L; - if(_bits == 0) - { - return; - } + return; } + } - if (((_bits & 512L) != 0)) + if (((_bits & 512L) != 0)) + { + _headers._Warning = default(StringValues); + _bits &= ~512L; + if(_bits == 0) { - _headers._Warning = default(StringValues); - _bits &= ~512L; - if(_bits == 0) - { - return; - } + return; } + } - if (((_bits & 1024L) != 0)) + if (((_bits & 1024L) != 0)) + { + _headers._Allow = default(StringValues); + _bits &= ~1024L; + if(_bits == 0) { - _headers._Allow = default(StringValues); - _bits &= ~1024L; - if(_bits == 0) - { - return; - } + return; } + } - if (((_bits & 2048L) != 0)) + if (((_bits & 2048L) != 0)) + { + _headers._ContentLength = default(StringValues); + _bits &= ~2048L; + if(_bits == 0) { - _headers._ContentLength = default(StringValues); - _bits &= ~2048L; - if(_bits == 0) - { - return; - } + return; } + } - if (((_bits & 4096L) != 0)) + if (((_bits & 4096L) != 0)) + { + _headers._ContentType = default(StringValues); + _bits &= ~4096L; + if(_bits == 0) { - _headers._ContentType = default(StringValues); - _bits &= ~4096L; - if(_bits == 0) - { - return; - } + return; } + } - if (((_bits & 8192L) != 0)) + if (((_bits & 8192L) != 0)) + { + _headers._ContentEncoding = default(StringValues); + _bits &= ~8192L; + if(_bits == 0) { - _headers._ContentEncoding = default(StringValues); - _bits &= ~8192L; - if(_bits == 0) - { - return; - } + return; } + } - if (((_bits & 16384L) != 0)) + if (((_bits & 16384L) != 0)) + { + _headers._ContentLanguage = default(StringValues); + _bits &= ~16384L; + if(_bits == 0) { - _headers._ContentLanguage = default(StringValues); - _bits &= ~16384L; - if(_bits == 0) - { - return; - } + return; } + } - if (((_bits & 32768L) != 0)) + if (((_bits & 32768L) != 0)) + { + _headers._ContentLocation = default(StringValues); + _bits &= ~32768L; + if(_bits == 0) { - _headers._ContentLocation = default(StringValues); - _bits &= ~32768L; - if(_bits == 0) - { - return; - } + return; } + } - if (((_bits & 65536L) != 0)) + if (((_bits & 65536L) != 0)) + { + _headers._ContentMD5 = default(StringValues); + _bits &= ~65536L; + if(_bits == 0) { - _headers._ContentMD5 = default(StringValues); - _bits &= ~65536L; - if(_bits == 0) - { - return; - } + return; } + } - if (((_bits & 131072L) != 0)) + if (((_bits & 131072L) != 0)) + { + _headers._ContentRange = default(StringValues); + _bits &= ~131072L; + if(_bits == 0) { - _headers._ContentRange = default(StringValues); - _bits &= ~131072L; - if(_bits == 0) - { - return; - } + return; } + } - if (((_bits & 262144L) != 0)) + if (((_bits & 262144L) != 0)) + { + _headers._Expires = default(StringValues); + _bits &= ~262144L; + if(_bits == 0) { - _headers._Expires = default(StringValues); - _bits &= ~262144L; - if(_bits == 0) - { - return; - } + return; } + } - if (((_bits & 524288L) != 0)) + if (((_bits & 524288L) != 0)) + { + _headers._LastModified = default(StringValues); + _bits &= ~524288L; + if(_bits == 0) { - _headers._LastModified = default(StringValues); - _bits &= ~524288L; - if(_bits == 0) - { - return; - } + return; } + } - if (((_bits & 2097152L) != 0)) + if (((_bits & 2097152L) != 0)) + { + _headers._AcceptCharset = default(StringValues); + _bits &= ~2097152L; + if(_bits == 0) { - _headers._AcceptCharset = default(StringValues); - _bits &= ~2097152L; - if(_bits == 0) - { - return; - } + return; } + } - if (((_bits & 4194304L) != 0)) + if (((_bits & 4194304L) != 0)) + { + _headers._AcceptEncoding = default(StringValues); + _bits &= ~4194304L; + if(_bits == 0) { - _headers._AcceptEncoding = default(StringValues); - _bits &= ~4194304L; - if(_bits == 0) - { - return; - } + return; } + } - if (((_bits & 8388608L) != 0)) + if (((_bits & 8388608L) != 0)) + { + _headers._AcceptLanguage = default(StringValues); + _bits &= ~8388608L; + if(_bits == 0) { - _headers._AcceptLanguage = default(StringValues); - _bits &= ~8388608L; - if(_bits == 0) - { - return; - } + return; } + } - if (((_bits & 16777216L) != 0)) + if (((_bits & 16777216L) != 0)) + { + _headers._Authorization = default(StringValues); + _bits &= ~16777216L; + if(_bits == 0) { - _headers._Authorization = default(StringValues); - _bits &= ~16777216L; - if(_bits == 0) - { - return; - } + return; } + } - if (((_bits & 33554432L) != 0)) + if (((_bits & 33554432L) != 0)) + { + _headers._Cookie = default(StringValues); + _bits &= ~33554432L; + if(_bits == 0) { - _headers._Cookie = default(StringValues); - _bits &= ~33554432L; - if(_bits == 0) - { - return; - } + return; } + } - if (((_bits & 67108864L) != 0)) + if (((_bits & 67108864L) != 0)) + { + _headers._Expect = default(StringValues); + _bits &= ~67108864L; + if(_bits == 0) { - _headers._Expect = default(StringValues); - _bits &= ~67108864L; - if(_bits == 0) - { - return; - } + return; } + } - if (((_bits & 134217728L) != 0)) + if (((_bits & 134217728L) != 0)) + { + _headers._From = default(StringValues); + _bits &= ~134217728L; + if(_bits == 0) { - _headers._From = default(StringValues); - _bits &= ~134217728L; - if(_bits == 0) - { - return; - } + return; } + } - if (((_bits & 536870912L) != 0)) + if (((_bits & 536870912L) != 0)) + { + _headers._IfMatch = default(StringValues); + _bits &= ~536870912L; + if(_bits == 0) { - _headers._IfMatch = default(StringValues); - _bits &= ~536870912L; - if(_bits == 0) - { - return; - } + return; } + } - if (((_bits & 1073741824L) != 0)) + if (((_bits & 1073741824L) != 0)) + { + _headers._IfModifiedSince = default(StringValues); + _bits &= ~1073741824L; + if(_bits == 0) { - _headers._IfModifiedSince = default(StringValues); - _bits &= ~1073741824L; - if(_bits == 0) - { - return; - } + return; } + } - if (((_bits & 2147483648L) != 0)) + if (((_bits & 2147483648L) != 0)) + { + _headers._IfNoneMatch = default(StringValues); + _bits &= ~2147483648L; + if(_bits == 0) { - _headers._IfNoneMatch = default(StringValues); - _bits &= ~2147483648L; - if(_bits == 0) - { - return; - } + return; } + } - if (((_bits & 4294967296L) != 0)) + if (((_bits & 4294967296L) != 0)) + { + _headers._IfRange = default(StringValues); + _bits &= ~4294967296L; + if(_bits == 0) { - _headers._IfRange = default(StringValues); - _bits &= ~4294967296L; - if(_bits == 0) - { - return; - } + return; } + } - if (((_bits & 8589934592L) != 0)) + if (((_bits & 8589934592L) != 0)) + { + _headers._IfUnmodifiedSince = default(StringValues); + _bits &= ~8589934592L; + if(_bits == 0) { - _headers._IfUnmodifiedSince = default(StringValues); - _bits &= ~8589934592L; - if(_bits == 0) - { - return; - } + return; } + } - if (((_bits & 17179869184L) != 0)) + if (((_bits & 17179869184L) != 0)) + { + _headers._MaxForwards = default(StringValues); + _bits &= ~17179869184L; + if(_bits == 0) { - _headers._MaxForwards = default(StringValues); - _bits &= ~17179869184L; - if(_bits == 0) - { - return; - } + return; } + } - if (((_bits & 34359738368L) != 0)) + if (((_bits & 34359738368L) != 0)) + { + _headers._ProxyAuthorization = default(StringValues); + _bits &= ~34359738368L; + if(_bits == 0) { - _headers._ProxyAuthorization = default(StringValues); - _bits &= ~34359738368L; - if(_bits == 0) - { - return; - } + return; } + } - if (((_bits & 68719476736L) != 0)) + if (((_bits & 68719476736L) != 0)) + { + _headers._Referer = default(StringValues); + _bits &= ~68719476736L; + if(_bits == 0) { - _headers._Referer = default(StringValues); - _bits &= ~68719476736L; - if(_bits == 0) - { - return; - } + return; } + } - if (((_bits & 137438953472L) != 0)) + if (((_bits & 137438953472L) != 0)) + { + _headers._Range = default(StringValues); + _bits &= ~137438953472L; + if(_bits == 0) { - _headers._Range = default(StringValues); - _bits &= ~137438953472L; - if(_bits == 0) - { - return; - } + return; } + } - if (((_bits & 274877906944L) != 0)) + if (((_bits & 274877906944L) != 0)) + { + _headers._TE = default(StringValues); + _bits &= ~274877906944L; + if(_bits == 0) { - _headers._TE = default(StringValues); - _bits &= ~274877906944L; - if(_bits == 0) - { - return; - } + return; } + } - if (((_bits & 549755813888L) != 0)) + if (((_bits & 549755813888L) != 0)) + { + _headers._Translate = default(StringValues); + _bits &= ~549755813888L; + if(_bits == 0) { - _headers._Translate = default(StringValues); - _bits &= ~549755813888L; - if(_bits == 0) - { - return; - } + return; } + } - if (((_bits & 2199023255552L) != 0)) + if (((_bits & 2199023255552L) != 0)) + { + _headers._Origin = default(StringValues); + _bits &= ~2199023255552L; + if(_bits == 0) { - _headers._Origin = default(StringValues); - _bits &= ~2199023255552L; - if(_bits == 0) - { - return; - } + return; } + } - if (((_bits & 4398046511104L) != 0)) + if (((_bits & 4398046511104L) != 0)) + { + _headers._AccessControlRequestMethod = default(StringValues); + _bits &= ~4398046511104L; + if(_bits == 0) { - _headers._AccessControlRequestMethod = default(StringValues); - _bits &= ~4398046511104L; - if(_bits == 0) - { - return; - } + return; } + } - if (((_bits & 8796093022208L) != 0)) + if (((_bits & 8796093022208L) != 0)) + { + _headers._AccessControlRequestHeaders = default(StringValues); + _bits &= ~8796093022208L; + if(_bits == 0) { - _headers._AccessControlRequestHeaders = default(StringValues); - _bits &= ~8796093022208L; - if(_bits == 0) - { - return; - } + return; } + } } @@ -4666,12 +4665,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _headers._Accept = new StringValues(value); } return; - } } break; - - case 4: { @@ -4687,12 +4683,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _headers._Host = new StringValues(value); } return; - } } break; - - case 10: { @@ -4708,12 +4701,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _headers._UserAgent = new StringValues(value); } return; - } } break; - - } @@ -4747,7 +4737,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _headers._CacheControl = new StringValues(value); } return; - } if ((((pUL[0] & 18437701552104792031uL) == 3266321689424580419uL) && ((pUI[2] & 3755991007u) == 1196310866u) && ((pUB[12] & 223u) == 69u))) @@ -4762,7 +4751,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _headers._ContentRange = new StringValues(value); } return; - } if ((((pUL[0] & 16131858680330051551uL) == 4922237774822850892uL) && ((pUI[2] & 3755991007u) == 1162430025u) && ((pUB[12] & 223u) == 68u))) @@ -4777,7 +4765,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _headers._LastModified = new StringValues(value); } return; - } if ((((pUL[0] & 16131858542891098079uL) == 6505821637182772545uL) && ((pUI[2] & 3755991007u) == 1330205761u) && ((pUB[12] & 223u) == 78u))) @@ -4792,7 +4779,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _headers._Authorization = new StringValues(value); } return; - } if ((((pUL[0] & 18437701552106889183uL) == 3262099607620765257uL) && ((pUI[2] & 3755991007u) == 1129595213u) && ((pUB[12] & 223u) == 72u))) @@ -4807,12 +4793,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _headers._IfNoneMatch = new StringValues(value); } return; - } } break; - - case 10: { @@ -4828,7 +4811,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _headers._Connection = new StringValues(value); } return; - } if ((((pUL[0] & 16131858680330051551uL) == 5281668125874799947uL) && ((pUS[4] & 57311u) == 17750u))) @@ -4843,12 +4825,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _headers._KeepAlive = new StringValues(value); } return; - } } break; - - case 4: { @@ -4864,7 +4843,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _headers._Date = new StringValues(value); } return; - } if ((((pUI[0] & 3755991007u) == 1297044038u))) @@ -4879,12 +4857,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _headers._From = new StringValues(value); } return; - } } break; - - case 6: { @@ -4900,7 +4875,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _headers._Pragma = new StringValues(value); } return; - } if ((((pUI[0] & 3755991007u) == 1263488835u) && ((pUS[2] & 57311u) == 17737u))) @@ -4915,7 +4889,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _headers._Cookie = new StringValues(value); } return; - } if ((((pUI[0] & 3755991007u) == 1162893381u) && ((pUS[2] & 57311u) == 21571u))) @@ -4930,7 +4903,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _headers._Expect = new StringValues(value); } return; - } if ((((pUI[0] & 3755991007u) == 1195987535u) && ((pUS[2] & 57311u) == 20041u))) @@ -4945,12 +4917,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _headers._Origin = new StringValues(value); } return; - } } break; - - case 7: { @@ -4966,7 +4935,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _headers._Trailer = new StringValues(value); } return; - } if ((((pUI[0] & 3755991007u) == 1380405333u) && ((pUS[2] & 57311u) == 17473u) && ((pUB[6] & 223u) == 69u))) @@ -4981,7 +4949,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _headers._Upgrade = new StringValues(value); } return; - } if ((((pUI[0] & 3755991007u) == 1314013527u) && ((pUS[2] & 57311u) == 20041u) && ((pUB[6] & 223u) == 71u))) @@ -4996,7 +4963,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _headers._Warning = new StringValues(value); } return; - } if ((((pUI[0] & 3755991007u) == 1230002245u) && ((pUS[2] & 57311u) == 17746u) && ((pUB[6] & 223u) == 83u))) @@ -5011,7 +4977,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _headers._Expires = new StringValues(value); } return; - } if ((((pUI[0] & 3755991007u) == 1162233170u) && ((pUS[2] & 57311u) == 17746u) && ((pUB[6] & 223u) == 82u))) @@ -5026,12 +4991,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _headers._Referer = new StringValues(value); } return; - } } break; - - case 17: { @@ -5047,7 +5009,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _headers._TransferEncoding = new StringValues(value); } return; - } if ((((pUL[0] & 16131858542893195231uL) == 5064654363342751305uL) && ((pUL[1] & 16131858543427968991uL) == 4849894470315165001uL) && ((pUB[16] & 223u) == 69u))) @@ -5062,12 +5023,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _headers._IfModifiedSince = new StringValues(value); } return; - } } break; - - case 3: { @@ -5083,12 +5041,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _headers._Via = new StringValues(value); } return; - } } break; - - case 5: { @@ -5104,7 +5059,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _headers._Allow = new StringValues(value); } return; - } if ((((pUI[0] & 3755991007u) == 1196310866u) && ((pUB[4] & 223u) == 69u))) @@ -5119,12 +5073,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _headers._Range = new StringValues(value); } return; - } } break; - - case 14: { @@ -5140,7 +5091,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _headers._ContentLength = new StringValues(value); } return; - } if ((((pUL[0] & 16140865742145839071uL) == 4840617878229304129uL) && ((pUI[2] & 3755991007u) == 1397899592u) && ((pUS[6] & 57311u) == 21573u))) @@ -5155,12 +5105,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _headers._AcceptCharset = new StringValues(value); } return; - } } break; - - case 12: { @@ -5176,7 +5123,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _headers._ContentType = new StringValues(value); } return; - } if ((((pUL[0] & 16131858543427968991uL) == 6292178792217067853uL) && ((pUI[2] & 3755991007u) == 1396986433u))) @@ -5191,12 +5137,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _headers._MaxForwards = new StringValues(value); } return; - } } break; - - case 16: { @@ -5212,7 +5155,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _headers._ContentEncoding = new StringValues(value); } return; - } if ((((pUL[0] & 18437701552104792031uL) == 3266321689424580419uL) && ((pUL[1] & 16131858542891098079uL) == 4992030546487820620uL))) @@ -5227,7 +5169,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _headers._ContentLanguage = new StringValues(value); } return; - } if ((((pUL[0] & 18437701552104792031uL) == 3266321689424580419uL) && ((pUL[1] & 16131858542891098079uL) == 5642809484339531596uL))) @@ -5242,12 +5183,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _headers._ContentLocation = new StringValues(value); } return; - } } break; - - case 11: { @@ -5263,12 +5201,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _headers._ContentMD5 = new StringValues(value); } return; - } } break; - - case 15: { @@ -5284,7 +5219,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _headers._AcceptEncoding = new StringValues(value); } return; - } if ((((pUL[0] & 16140865742145839071uL) == 5489136224570655553uL) && ((pUI[2] & 3755991007u) == 1430736449u) && ((pUS[6] & 57311u) == 18241u) && ((pUB[14] & 223u) == 69u))) @@ -5299,12 +5233,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _headers._AcceptLanguage = new StringValues(value); } return; - } } break; - - case 8: { @@ -5320,7 +5251,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _headers._IfMatch = new StringValues(value); } return; - } if ((((pUL[0] & 16131858542893195231uL) == 4992044754422023753uL))) @@ -5335,12 +5265,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _headers._IfRange = new StringValues(value); } return; - } } break; - - case 19: { @@ -5356,7 +5283,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _headers._IfUnmodifiedSince = new StringValues(value); } return; - } if ((((pUL[0] & 16131893727263186911uL) == 6143241228466999888uL) && ((pUL[1] & 16131858542891098079uL) == 6071233043632179284uL) && ((pUS[8] & 57311u) == 20297u) && ((pUB[18] & 223u) == 78u))) @@ -5371,12 +5297,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _headers._ProxyAuthorization = new StringValues(value); } return; - } } break; - - case 2: { @@ -5392,12 +5315,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _headers._TE = new StringValues(value); } return; - } } break; - - case 9: { @@ -5413,12 +5333,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _headers._Translate = new StringValues(value); } return; - } } break; - - case 29: { @@ -5434,12 +5351,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _headers._AccessControlRequestMethod = new StringValues(value); } return; - } } break; - - case 30: { @@ -5455,12 +5369,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _headers._AccessControlRequestHeaders = new StringValues(value); } return; - } } break; - - } @@ -9178,367 +9089,366 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _bits = 0; return; } - - if (((_bits & 2L) != 0)) + if (((_bits & 2L) != 0)) + { + _headers._Connection = default(StringValues); + _bits &= ~2L; + if(_bits == 0) { - _headers._Connection = default(StringValues); - _bits &= ~2L; - if(_bits == 0) - { - return; - } + return; } + } - if (((_bits & 4L) != 0)) + if (((_bits & 4L) != 0)) + { + _headers._Date = default(StringValues); + _bits &= ~4L; + if(_bits == 0) { - _headers._Date = default(StringValues); - _bits &= ~4L; - if(_bits == 0) - { - return; - } + return; } + } - if (((_bits & 2048L) != 0)) + if (((_bits & 2048L) != 0)) + { + _headers._ContentLength = default(StringValues); + _bits &= ~2048L; + if(_bits == 0) { - _headers._ContentLength = default(StringValues); - _bits &= ~2048L; - if(_bits == 0) - { - return; - } + return; } + } - if (((_bits & 4096L) != 0)) + if (((_bits & 4096L) != 0)) + { + _headers._ContentType = default(StringValues); + _bits &= ~4096L; + if(_bits == 0) { - _headers._ContentType = default(StringValues); - _bits &= ~4096L; - if(_bits == 0) - { - return; - } + return; } + } - if (((_bits & 67108864L) != 0)) + if (((_bits & 67108864L) != 0)) + { + _headers._Server = default(StringValues); + _bits &= ~67108864L; + if(_bits == 0) { - _headers._Server = default(StringValues); - _bits &= ~67108864L; - if(_bits == 0) - { - return; - } + return; } + } - if (((_bits & 1L) != 0)) + if (((_bits & 1L) != 0)) + { + _headers._CacheControl = default(StringValues); + _bits &= ~1L; + if(_bits == 0) { - _headers._CacheControl = default(StringValues); - _bits &= ~1L; - if(_bits == 0) - { - return; - } + return; } + } - if (((_bits & 8L) != 0)) + if (((_bits & 8L) != 0)) + { + _headers._KeepAlive = default(StringValues); + _bits &= ~8L; + if(_bits == 0) { - _headers._KeepAlive = default(StringValues); - _bits &= ~8L; - if(_bits == 0) - { - return; - } + return; } + } - if (((_bits & 16L) != 0)) + if (((_bits & 16L) != 0)) + { + _headers._Pragma = default(StringValues); + _bits &= ~16L; + if(_bits == 0) { - _headers._Pragma = default(StringValues); - _bits &= ~16L; - if(_bits == 0) - { - return; - } + return; } + } - if (((_bits & 32L) != 0)) + if (((_bits & 32L) != 0)) + { + _headers._Trailer = default(StringValues); + _bits &= ~32L; + if(_bits == 0) { - _headers._Trailer = default(StringValues); - _bits &= ~32L; - if(_bits == 0) - { - return; - } + return; } + } - if (((_bits & 64L) != 0)) + if (((_bits & 64L) != 0)) + { + _headers._TransferEncoding = default(StringValues); + _bits &= ~64L; + if(_bits == 0) { - _headers._TransferEncoding = default(StringValues); - _bits &= ~64L; - if(_bits == 0) - { - return; - } + return; } + } - if (((_bits & 128L) != 0)) + if (((_bits & 128L) != 0)) + { + _headers._Upgrade = default(StringValues); + _bits &= ~128L; + if(_bits == 0) { - _headers._Upgrade = default(StringValues); - _bits &= ~128L; - if(_bits == 0) - { - return; - } + return; } + } - if (((_bits & 256L) != 0)) + if (((_bits & 256L) != 0)) + { + _headers._Via = default(StringValues); + _bits &= ~256L; + if(_bits == 0) { - _headers._Via = default(StringValues); - _bits &= ~256L; - if(_bits == 0) - { - return; - } + return; } + } - if (((_bits & 512L) != 0)) + if (((_bits & 512L) != 0)) + { + _headers._Warning = default(StringValues); + _bits &= ~512L; + if(_bits == 0) { - _headers._Warning = default(StringValues); - _bits &= ~512L; - if(_bits == 0) - { - return; - } + return; } + } - if (((_bits & 1024L) != 0)) + if (((_bits & 1024L) != 0)) + { + _headers._Allow = default(StringValues); + _bits &= ~1024L; + if(_bits == 0) { - _headers._Allow = default(StringValues); - _bits &= ~1024L; - if(_bits == 0) - { - return; - } + return; } + } - if (((_bits & 8192L) != 0)) + if (((_bits & 8192L) != 0)) + { + _headers._ContentEncoding = default(StringValues); + _bits &= ~8192L; + if(_bits == 0) { - _headers._ContentEncoding = default(StringValues); - _bits &= ~8192L; - if(_bits == 0) - { - return; - } + return; } + } - if (((_bits & 16384L) != 0)) + if (((_bits & 16384L) != 0)) + { + _headers._ContentLanguage = default(StringValues); + _bits &= ~16384L; + if(_bits == 0) { - _headers._ContentLanguage = default(StringValues); - _bits &= ~16384L; - if(_bits == 0) - { - return; - } + return; } + } - if (((_bits & 32768L) != 0)) + if (((_bits & 32768L) != 0)) + { + _headers._ContentLocation = default(StringValues); + _bits &= ~32768L; + if(_bits == 0) { - _headers._ContentLocation = default(StringValues); - _bits &= ~32768L; - if(_bits == 0) - { - return; - } + return; } + } - if (((_bits & 65536L) != 0)) + if (((_bits & 65536L) != 0)) + { + _headers._ContentMD5 = default(StringValues); + _bits &= ~65536L; + if(_bits == 0) { - _headers._ContentMD5 = default(StringValues); - _bits &= ~65536L; - if(_bits == 0) - { - return; - } + return; } + } - if (((_bits & 131072L) != 0)) + if (((_bits & 131072L) != 0)) + { + _headers._ContentRange = default(StringValues); + _bits &= ~131072L; + if(_bits == 0) { - _headers._ContentRange = default(StringValues); - _bits &= ~131072L; - if(_bits == 0) - { - return; - } + return; } + } - if (((_bits & 262144L) != 0)) + if (((_bits & 262144L) != 0)) + { + _headers._Expires = default(StringValues); + _bits &= ~262144L; + if(_bits == 0) { - _headers._Expires = default(StringValues); - _bits &= ~262144L; - if(_bits == 0) - { - return; - } + return; } + } - if (((_bits & 524288L) != 0)) + if (((_bits & 524288L) != 0)) + { + _headers._LastModified = default(StringValues); + _bits &= ~524288L; + if(_bits == 0) { - _headers._LastModified = default(StringValues); - _bits &= ~524288L; - if(_bits == 0) - { - return; - } + return; } + } - if (((_bits & 1048576L) != 0)) + if (((_bits & 1048576L) != 0)) + { + _headers._AcceptRanges = default(StringValues); + _bits &= ~1048576L; + if(_bits == 0) { - _headers._AcceptRanges = default(StringValues); - _bits &= ~1048576L; - if(_bits == 0) - { - return; - } + return; } + } - if (((_bits & 2097152L) != 0)) + if (((_bits & 2097152L) != 0)) + { + _headers._Age = default(StringValues); + _bits &= ~2097152L; + if(_bits == 0) { - _headers._Age = default(StringValues); - _bits &= ~2097152L; - if(_bits == 0) - { - return; - } + return; } + } - if (((_bits & 4194304L) != 0)) + if (((_bits & 4194304L) != 0)) + { + _headers._ETag = default(StringValues); + _bits &= ~4194304L; + if(_bits == 0) { - _headers._ETag = default(StringValues); - _bits &= ~4194304L; - if(_bits == 0) - { - return; - } + return; } + } - if (((_bits & 8388608L) != 0)) + if (((_bits & 8388608L) != 0)) + { + _headers._Location = default(StringValues); + _bits &= ~8388608L; + if(_bits == 0) { - _headers._Location = default(StringValues); - _bits &= ~8388608L; - if(_bits == 0) - { - return; - } + return; } + } - if (((_bits & 16777216L) != 0)) + if (((_bits & 16777216L) != 0)) + { + _headers._ProxyAutheticate = default(StringValues); + _bits &= ~16777216L; + if(_bits == 0) { - _headers._ProxyAutheticate = default(StringValues); - _bits &= ~16777216L; - if(_bits == 0) - { - return; - } + return; } + } - if (((_bits & 33554432L) != 0)) + if (((_bits & 33554432L) != 0)) + { + _headers._RetryAfter = default(StringValues); + _bits &= ~33554432L; + if(_bits == 0) { - _headers._RetryAfter = default(StringValues); - _bits &= ~33554432L; - if(_bits == 0) - { - return; - } + return; } + } - if (((_bits & 134217728L) != 0)) + if (((_bits & 134217728L) != 0)) + { + _headers._SetCookie = default(StringValues); + _bits &= ~134217728L; + if(_bits == 0) { - _headers._SetCookie = default(StringValues); - _bits &= ~134217728L; - if(_bits == 0) - { - return; - } + return; } + } - if (((_bits & 268435456L) != 0)) + if (((_bits & 268435456L) != 0)) + { + _headers._Vary = default(StringValues); + _bits &= ~268435456L; + if(_bits == 0) { - _headers._Vary = default(StringValues); - _bits &= ~268435456L; - if(_bits == 0) - { - return; - } + return; } + } - if (((_bits & 536870912L) != 0)) + if (((_bits & 536870912L) != 0)) + { + _headers._WWWAuthenticate = default(StringValues); + _bits &= ~536870912L; + if(_bits == 0) { - _headers._WWWAuthenticate = default(StringValues); - _bits &= ~536870912L; - if(_bits == 0) - { - return; - } + return; } + } - if (((_bits & 1073741824L) != 0)) + if (((_bits & 1073741824L) != 0)) + { + _headers._AccessControlAllowCredentials = default(StringValues); + _bits &= ~1073741824L; + if(_bits == 0) { - _headers._AccessControlAllowCredentials = default(StringValues); - _bits &= ~1073741824L; - if(_bits == 0) - { - return; - } + return; } + } - if (((_bits & 2147483648L) != 0)) + if (((_bits & 2147483648L) != 0)) + { + _headers._AccessControlAllowHeaders = default(StringValues); + _bits &= ~2147483648L; + if(_bits == 0) { - _headers._AccessControlAllowHeaders = default(StringValues); - _bits &= ~2147483648L; - if(_bits == 0) - { - return; - } + return; } + } - if (((_bits & 4294967296L) != 0)) + if (((_bits & 4294967296L) != 0)) + { + _headers._AccessControlAllowMethods = default(StringValues); + _bits &= ~4294967296L; + if(_bits == 0) { - _headers._AccessControlAllowMethods = default(StringValues); - _bits &= ~4294967296L; - if(_bits == 0) - { - return; - } + return; } + } - if (((_bits & 8589934592L) != 0)) + if (((_bits & 8589934592L) != 0)) + { + _headers._AccessControlAllowOrigin = default(StringValues); + _bits &= ~8589934592L; + if(_bits == 0) { - _headers._AccessControlAllowOrigin = default(StringValues); - _bits &= ~8589934592L; - if(_bits == 0) - { - return; - } + return; } + } - if (((_bits & 17179869184L) != 0)) + if (((_bits & 17179869184L) != 0)) + { + _headers._AccessControlExposeHeaders = default(StringValues); + _bits &= ~17179869184L; + if(_bits == 0) { - _headers._AccessControlExposeHeaders = default(StringValues); - _bits &= ~17179869184L; - if(_bits == 0) - { - return; - } + return; } + } - if (((_bits & 34359738368L) != 0)) + if (((_bits & 34359738368L) != 0)) + { + _headers._AccessControlMaxAge = default(StringValues); + _bits &= ~34359738368L; + if(_bits == 0) { - _headers._AccessControlMaxAge = default(StringValues); - _bits &= ~34359738368L; - if(_bits == 0) - { - return; - } + return; } + } } diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs index 6140e6ea0a..f62dfc8e17 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs @@ -712,8 +712,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests await connection.Receive( $"HTTP/1.1 200 OK", $"Date: {server.Context.DateHeaderValue}", - "Transfer-Encoding: chunked", "Content-Length: 13", + "Transfer-Encoding: chunked", "", "hello, world"); } @@ -748,8 +748,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests await connection.Receive( $"HTTP/1.1 200 OK", $"Date: {server.Context.DateHeaderValue}", - "Transfer-Encoding: chunked", "Content-Length: 11", + "Transfer-Encoding: chunked", "", "hello, world"); } diff --git a/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/KnownHeaders.cs b/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/KnownHeaders.cs index a062349f74..fef4219b12 100644 --- a/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/KnownHeaders.cs +++ b/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/KnownHeaders.cs @@ -44,12 +44,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.GeneratedCode _headers._raw{header.Identifier} = null;")} }} return; - }} ")}}} break; - - ")}}} {(handleUnknown ? $@" @@ -450,17 +447,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _bits = 0; return; }} - {Each(loop.Headers.OrderBy(h => !h.PrimaryHeader), header => $@" - if ({header.TestBit()}) + if ({header.TestBit()}) + {{ + _headers._{header.Identifier} = default(StringValues); + {header.ClearBit()}; + if(_bits == 0) {{ - _headers._{header.Identifier} = default(StringValues); - {header.ClearBit()}; - if(_bits == 0) - {{ - return; - }} + return; }} + }} ")} }} From d64b4c7acb5840fbd279faa8362e1da84df8c16b Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Mon, 24 Oct 2016 11:07:06 -0700 Subject: [PATCH 0926/1662] Control-flow simplification in Frame.CreateResponseHeader() (#1168). --- .../Internal/Http/Frame.cs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs index 0953726458..8f996d0c71 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs @@ -865,13 +865,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http responseHeaders.SetReadOnly(); - if (!_keepAlive && !hasConnection) + if (!hasConnection) { - responseHeaders.SetRawConnection("close", _bytesConnectionClose); - } - else if (_keepAlive && !hasConnection && _httpVersion == Http.HttpVersion.Http10) - { - responseHeaders.SetRawConnection("keep-alive", _bytesConnectionKeepAlive); + if (!_keepAlive) + { + responseHeaders.SetRawConnection("close", _bytesConnectionClose); + } + else if (_httpVersion == Http.HttpVersion.Http10) + { + responseHeaders.SetRawConnection("keep-alive", _bytesConnectionKeepAlive); + } } if (ServerOptions.AddServerHeader && !responseHeaders.HasServer) From 1ffad5ca3832090570197c02cb4ff0ac2d9f6eb5 Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Mon, 24 Oct 2016 14:57:24 -0700 Subject: [PATCH 0927/1662] Handle multiple tokens in Connection header (#1170). --- .../Internal/Http/ConnectionOptions.cs | 16 ++ .../Internal/Http/Frame.FeatureCollection.cs | 13 +- .../Internal/Http/Frame.cs | 5 +- .../Internal/Http/FrameHeaders.cs | 101 +++++++++++- .../Internal/Http/FrameOfT.cs | 1 + .../Internal/Http/MessageBody.cs | 18 +- .../FrameHeadersTests.cs | 155 ++++++++++++++++++ .../MessageBodyTests.cs | 21 +++ 8 files changed, 309 insertions(+), 21 deletions(-) create mode 100644 src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ConnectionOptions.cs create mode 100644 test/Microsoft.AspNetCore.Server.KestrelTests/FrameHeadersTests.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ConnectionOptions.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ConnectionOptions.cs new file mode 100644 index 0000000000..72d4eeb5d1 --- /dev/null +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ConnectionOptions.cs @@ -0,0 +1,16 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; + +namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http +{ + [Flags] + public enum ConnectionOptions + { + None = 0, + Close = 1, + KeepAlive = 2, + Upgrade = 4 + } +} diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.FeatureCollection.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.FeatureCollection.cs index 75c1404ba5..9480147f95 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.FeatureCollection.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.FeatureCollection.cs @@ -259,18 +259,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http get { return HasResponseStarted; } } - bool IHttpUpgradeFeature.IsUpgradableRequest - { - get - { - StringValues values; - if (RequestHeaders.TryGetValue("Connection", out values)) - { - return values.Any(value => value.IndexOf("upgrade", StringComparison.OrdinalIgnoreCase) != -1); - } - return false; - } - } + bool IHttpUpgradeFeature.IsUpgradableRequest => _upgrade; bool IFeatureCollection.IsReadOnly => false; diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs index 8f996d0c71..c6f90a2858 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs @@ -60,6 +60,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http private RequestProcessingStatus _requestProcessingStatus; protected bool _keepAlive; + protected bool _upgrade; private bool _canHaveBody; private bool _autoChunk; protected Exception _applicationException; @@ -810,13 +811,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { var responseHeaders = FrameResponseHeaders; var hasConnection = responseHeaders.HasConnection; + var connectionOptions = hasConnection ? FrameHeaders.ParseConnection(responseHeaders.HeaderConnection) : ConnectionOptions.None; var end = SocketOutput.ProducingStart(); if (_keepAlive && hasConnection) { - var connectionValue = responseHeaders.HeaderConnection.ToString(); - _keepAlive = connectionValue.Equals("keep-alive", StringComparison.OrdinalIgnoreCase); + _keepAlive = (connectionOptions & ConnectionOptions.KeepAlive) == ConnectionOptions.KeepAlive; } // Set whether response can have body diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameHeaders.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameHeaders.cs index 4d234322a5..d0d3114268 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameHeaders.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameHeaders.cs @@ -4,7 +4,6 @@ using System; using System.Collections; using System.Collections.Generic; -using System.Globalization; using System.Linq; using Microsoft.AspNetCore.Http; using Microsoft.Extensions.Primitives; @@ -265,6 +264,106 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http return parsed; } + public static unsafe ConnectionOptions ParseConnection(StringValues connection) + { + var connectionOptions = ConnectionOptions.None; + + foreach (var value in connection) + { + fixed (char* ptr = value) + { + var ch = ptr; + var tokenEnd = ch; + var end = ch + value.Length; + + while (ch < end) + { + while (tokenEnd < end && *tokenEnd != ',') + { + tokenEnd++; + } + + while (ch < tokenEnd && *ch == ' ') + { + ch++; + } + + var tokenLength = tokenEnd - ch; + + if (tokenLength >= 9 && (*ch | 0x20) == 'k') + { + if ((*++ch | 0x20) == 'e' && + (*++ch | 0x20) == 'e' && + (*++ch | 0x20) == 'p' && + *++ch == '-' && + (*++ch | 0x20) == 'a' && + (*++ch | 0x20) == 'l' && + (*++ch | 0x20) == 'i' && + (*++ch | 0x20) == 'v' && + (*++ch | 0x20) == 'e') + { + ch++; + while (ch < tokenEnd && *ch == ' ') + { + ch++; + } + + if (ch == tokenEnd || *ch == ',') + { + connectionOptions |= ConnectionOptions.KeepAlive; + } + } + } + else if (tokenLength >= 7 && (*ch | 0x20) == 'u') + { + if ((*++ch | 0x20) == 'p' && + (*++ch | 0x20) == 'g' && + (*++ch | 0x20) == 'r' && + (*++ch | 0x20) == 'a' && + (*++ch | 0x20) == 'd' && + (*++ch | 0x20) == 'e') + { + ch++; + while (ch < tokenEnd && *ch == ' ') + { + ch++; + } + + if (ch == tokenEnd || *ch == ',') + { + connectionOptions |= ConnectionOptions.Upgrade; + } + } + } + else if (tokenLength >= 5 && (*ch | 0x20) == 'c') + { + if ((*++ch | 0x20) == 'l' && + (*++ch | 0x20) == 'o' && + (*++ch | 0x20) == 's' && + (*++ch | 0x20) == 'e') + { + ch++; + while (ch < tokenEnd && *ch == ' ') + { + ch++; + } + + if (ch == tokenEnd || *ch == ',') + { + connectionOptions |= ConnectionOptions.Close; + } + } + } + + tokenEnd++; + ch = tokenEnd; + } + } + } + + return connectionOptions; + } + private static void ThrowInvalidContentLengthException(string value) { throw new InvalidOperationException($"Invalid Content-Length: \"{value}\". Value must be a positive integral number."); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameOfT.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameOfT.cs index cfdc1fc556..6925c13bea 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameOfT.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameOfT.cs @@ -86,6 +86,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { var messageBody = MessageBody.For(_httpVersion, FrameRequestHeaders, this); _keepAlive = messageBody.RequestKeepAlive; + _upgrade = messageBody.RequestUpgrade; InitializeStreams(messageBody); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/MessageBody.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/MessageBody.cs index bff4ba622f..a3e0093089 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/MessageBody.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/MessageBody.cs @@ -8,6 +8,7 @@ using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.Extensions.Internal; +using Microsoft.Extensions.Primitives; namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { @@ -23,6 +24,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http public bool RequestKeepAlive { get; protected set; } + public bool RequestUpgrade { get; protected set; } + public Task ReadAsync(ArraySegment buffer, CancellationToken cancellationToken = default(CancellationToken)) { var task = PeekAsync(cancellationToken); @@ -231,15 +234,17 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http // see also http://tools.ietf.org/html/rfc2616#section-4.4 var keepAlive = httpVersion != HttpVersion.Http10; - var connection = headers.HeaderConnection.ToString(); - if (connection.Length > 0) + var connection = headers.HeaderConnection; + if (connection.Count > 0) { - if (connection.Equals("upgrade", StringComparison.OrdinalIgnoreCase)) + var connectionOptions = FrameHeaders.ParseConnection(connection); + + if ((connectionOptions & ConnectionOptions.Upgrade) == ConnectionOptions.Upgrade) { - return new ForRemainingData(context); + return new ForRemainingData(true, context); } - keepAlive = connection.Equals("keep-alive", StringComparison.OrdinalIgnoreCase); + keepAlive = (connectionOptions & ConnectionOptions.KeepAlive) == ConnectionOptions.KeepAlive; } var transferEncoding = headers.HeaderTransferEncoding.ToString(); @@ -267,9 +272,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http private class ForRemainingData : MessageBody { - public ForRemainingData(Frame context) + public ForRemainingData(bool upgrade, Frame context) : base(context) { + RequestUpgrade = upgrade; } protected override ValueTask> PeekAsync(CancellationToken cancellationToken) diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameHeadersTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameHeadersTests.cs new file mode 100644 index 0000000000..c8cc648376 --- /dev/null +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameHeadersTests.cs @@ -0,0 +1,155 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; +using Microsoft.Extensions.Primitives; +using Xunit; + +namespace Microsoft.AspNetCore.Server.KestrelTests +{ + public class FrameHeadersTests + { + [Theory] + [InlineData("keep-alive", ConnectionOptions.KeepAlive)] + [InlineData("keep-alive, upgrade", ConnectionOptions.KeepAlive | ConnectionOptions.Upgrade)] + [InlineData("keep-alive,upgrade", ConnectionOptions.KeepAlive | ConnectionOptions.Upgrade)] + [InlineData("upgrade, keep-alive", ConnectionOptions.KeepAlive | ConnectionOptions.Upgrade)] + [InlineData("upgrade,keep-alive", ConnectionOptions.KeepAlive | ConnectionOptions.Upgrade)] + [InlineData("upgrade,,keep-alive", ConnectionOptions.KeepAlive | ConnectionOptions.Upgrade)] + [InlineData("keep-alive,", ConnectionOptions.KeepAlive)] + [InlineData("keep-alive,,", ConnectionOptions.KeepAlive)] + [InlineData(",keep-alive", ConnectionOptions.KeepAlive)] + [InlineData(",,keep-alive", ConnectionOptions.KeepAlive)] + [InlineData("keep-alive, ", ConnectionOptions.KeepAlive)] + [InlineData("keep-alive, ,", ConnectionOptions.KeepAlive)] + [InlineData("keep-alive, , ", ConnectionOptions.KeepAlive)] + [InlineData("keep-alive ,", ConnectionOptions.KeepAlive)] + [InlineData(",keep-alive", ConnectionOptions.KeepAlive)] + [InlineData(", keep-alive", ConnectionOptions.KeepAlive)] + [InlineData(",,keep-alive", ConnectionOptions.KeepAlive)] + [InlineData(", ,keep-alive", ConnectionOptions.KeepAlive)] + [InlineData(",, keep-alive", ConnectionOptions.KeepAlive)] + [InlineData(", , keep-alive", ConnectionOptions.KeepAlive)] + [InlineData("upgrade,", ConnectionOptions.Upgrade)] + [InlineData("upgrade,,", ConnectionOptions.Upgrade)] + [InlineData(",upgrade", ConnectionOptions.Upgrade)] + [InlineData(",,upgrade", ConnectionOptions.Upgrade)] + [InlineData("upgrade, ", ConnectionOptions.Upgrade)] + [InlineData("upgrade, ,", ConnectionOptions.Upgrade)] + [InlineData("upgrade, , ", ConnectionOptions.Upgrade)] + [InlineData("upgrade ,", ConnectionOptions.Upgrade)] + [InlineData(",upgrade", ConnectionOptions.Upgrade)] + [InlineData(", upgrade", ConnectionOptions.Upgrade)] + [InlineData(",,upgrade", ConnectionOptions.Upgrade)] + [InlineData(", ,upgrade", ConnectionOptions.Upgrade)] + [InlineData(",, upgrade", ConnectionOptions.Upgrade)] + [InlineData(", , upgrade", ConnectionOptions.Upgrade)] + [InlineData("close,", ConnectionOptions.Close)] + [InlineData("close,,", ConnectionOptions.Close)] + [InlineData(",close", ConnectionOptions.Close)] + [InlineData(",,close", ConnectionOptions.Close)] + [InlineData("close, ", ConnectionOptions.Close)] + [InlineData("close, ,", ConnectionOptions.Close)] + [InlineData("close, , ", ConnectionOptions.Close)] + [InlineData("close ,", ConnectionOptions.Close)] + [InlineData(",close", ConnectionOptions.Close)] + [InlineData(", close", ConnectionOptions.Close)] + [InlineData(",,close", ConnectionOptions.Close)] + [InlineData(", ,close", ConnectionOptions.Close)] + [InlineData(",, close", ConnectionOptions.Close)] + [InlineData(", , close", ConnectionOptions.Close)] + [InlineData("kupgrade", ConnectionOptions.None)] + [InlineData("keupgrade", ConnectionOptions.None)] + [InlineData("ukeep-alive", ConnectionOptions.None)] + [InlineData("upkeep-alive", ConnectionOptions.None)] + [InlineData("k,upgrade", ConnectionOptions.Upgrade)] + [InlineData("u,keep-alive", ConnectionOptions.KeepAlive)] + [InlineData("ke,upgrade", ConnectionOptions.Upgrade)] + [InlineData("up,keep-alive", ConnectionOptions.KeepAlive)] + [InlineData("close", ConnectionOptions.Close)] + [InlineData("upgrade,close", ConnectionOptions.Close | ConnectionOptions.Upgrade)] + [InlineData("close,upgrade", ConnectionOptions.Close | ConnectionOptions.Upgrade)] + [InlineData("keep-alive2", ConnectionOptions.None)] + [InlineData("keep-alive2,", ConnectionOptions.None)] + [InlineData("keep-alive2 ", ConnectionOptions.None)] + [InlineData("keep-alive2 ,", ConnectionOptions.None)] + [InlineData("keep-alive2,", ConnectionOptions.None)] + [InlineData("upgrade2", ConnectionOptions.None)] + [InlineData("upgrade2,", ConnectionOptions.None)] + [InlineData("upgrade2 ", ConnectionOptions.None)] + [InlineData("upgrade2 ,", ConnectionOptions.None)] + [InlineData("upgrade2,", ConnectionOptions.None)] + [InlineData("close2", ConnectionOptions.None)] + [InlineData("close2,", ConnectionOptions.None)] + [InlineData("close2 ", ConnectionOptions.None)] + [InlineData("close2 ,", ConnectionOptions.None)] + [InlineData("close2,", ConnectionOptions.None)] + [InlineData("keep-alivekeep-alive", ConnectionOptions.None)] + [InlineData("keep-aliveupgrade", ConnectionOptions.None)] + [InlineData("upgradeupgrade", ConnectionOptions.None)] + [InlineData("upgradekeep-alive", ConnectionOptions.None)] + [InlineData("closeclose", ConnectionOptions.None)] + [InlineData("closeupgrade", ConnectionOptions.None)] + [InlineData("upgradeclose", ConnectionOptions.None)] + [InlineData("keep-alive 2", ConnectionOptions.None)] + [InlineData("upgrade 2", ConnectionOptions.None)] + [InlineData("keep-alive 2, close", ConnectionOptions.Close)] + [InlineData("upgrade 2, close", ConnectionOptions.Close)] + [InlineData("close, keep-alive 2", ConnectionOptions.Close)] + [InlineData("close, upgrade 2", ConnectionOptions.Close)] + [InlineData("close 2, upgrade", ConnectionOptions.Upgrade)] + [InlineData("upgrade, close 2", ConnectionOptions.Upgrade)] + [InlineData("k2ep-alive", ConnectionOptions.None)] + [InlineData("ke2p-alive", ConnectionOptions.None)] + [InlineData("u2grade", ConnectionOptions.None)] + [InlineData("up2rade", ConnectionOptions.None)] + [InlineData("c2ose", ConnectionOptions.None)] + [InlineData("cl2se", ConnectionOptions.None)] + [InlineData("k2ep-alive,", ConnectionOptions.None)] + [InlineData("ke2p-alive,", ConnectionOptions.None)] + [InlineData("u2grade,", ConnectionOptions.None)] + [InlineData("up2rade,", ConnectionOptions.None)] + [InlineData("c2ose,", ConnectionOptions.None)] + [InlineData("cl2se,", ConnectionOptions.None)] + [InlineData("k2ep-alive ", ConnectionOptions.None)] + [InlineData("ke2p-alive ", ConnectionOptions.None)] + [InlineData("u2grade ", ConnectionOptions.None)] + [InlineData("up2rade ", ConnectionOptions.None)] + [InlineData("c2ose ", ConnectionOptions.None)] + [InlineData("cl2se ", ConnectionOptions.None)] + [InlineData("k2ep-alive ,", ConnectionOptions.None)] + [InlineData("ke2p-alive ,", ConnectionOptions.None)] + [InlineData("u2grade ,", ConnectionOptions.None)] + [InlineData("up2rade ,", ConnectionOptions.None)] + [InlineData("c2ose ,", ConnectionOptions.None)] + [InlineData("cl2se ,", ConnectionOptions.None)] + public void TestParseConnection(string connection, ConnectionOptions expectedConnectionOptionss) + { + var connectionOptions = FrameHeaders.ParseConnection(connection); + Assert.Equal(expectedConnectionOptionss, connectionOptions); + } + + [Theory] + [InlineData("keep-alive", "upgrade", ConnectionOptions.KeepAlive | ConnectionOptions.Upgrade)] + [InlineData("upgrade", "keep-alive", ConnectionOptions.KeepAlive | ConnectionOptions.Upgrade)] + [InlineData("keep-alive", "", ConnectionOptions.KeepAlive)] + [InlineData("", "keep-alive", ConnectionOptions.KeepAlive)] + [InlineData("upgrade", "", ConnectionOptions.Upgrade)] + [InlineData("", "upgrade", ConnectionOptions.Upgrade)] + [InlineData("keep-alive, upgrade", "", ConnectionOptions.KeepAlive | ConnectionOptions.Upgrade)] + [InlineData("upgrade, keep-alive", "", ConnectionOptions.KeepAlive | ConnectionOptions.Upgrade)] + [InlineData("", "keep-alive, upgrade", ConnectionOptions.KeepAlive | ConnectionOptions.Upgrade)] + [InlineData("", "upgrade, keep-alive", ConnectionOptions.KeepAlive | ConnectionOptions.Upgrade)] + [InlineData("", "", ConnectionOptions.None)] + [InlineData("close", "", ConnectionOptions.Close)] + [InlineData("", "close", ConnectionOptions.Close)] + [InlineData("close", "upgrade", ConnectionOptions.Close | ConnectionOptions.Upgrade)] + [InlineData("upgrade", "close", ConnectionOptions.Close | ConnectionOptions.Upgrade)] + public void TestParseConnectionMultipleValues(string value1, string value2, ConnectionOptions expectedConnectionOptionss) + { + var connection = new StringValues(new[] { value1, value2 }); + var connectionOptions = FrameHeaders.ParseConnection(connection); + Assert.Equal(expectedConnectionOptionss, connectionOptions); + } + } +} diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/MessageBodyTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/MessageBodyTests.cs index 1790cf8094..427189fd1b 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/MessageBodyTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/MessageBodyTests.cs @@ -286,6 +286,27 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } } + [Theory] + [InlineData("keep-alive, upgrade")] + [InlineData("Keep-Alive, Upgrade")] + [InlineData("upgrade, keep-alive")] + [InlineData("Upgrade, Keep-Alive")] + public void ConnectionUpgradeKeepAlive(string headerConnection) + { + using (var input = new TestInput()) + { + var body = MessageBody.For(HttpVersion.Http11, new FrameRequestHeaders { HeaderConnection = headerConnection }, input.FrameContext); + var stream = new FrameRequestStream(); + stream.StartAcceptingReads(body); + + input.Add("Hello", true); + + var buffer = new byte[1024]; + Assert.Equal(5, stream.Read(buffer, 0, 1024)); + AssertASCII("Hello", new ArraySegment(buffer, 0, 5)); + } + } + private void AssertASCII(string expected, ArraySegment actual) { var encoding = Encoding.ASCII; From d475d41f7117f3820d422829d6a02952a91f5754 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Wed, 26 Oct 2016 17:44:44 -0700 Subject: [PATCH 0928/1662] Fix boundary cases in MemoryPoolIterator.(Try)PeekLong() - Fix edge case where the iterator is at the very end of a block. - Fix edge case where one bits where improperly filled in on a right shift. - Don't use -1 to represent failure. Use bool and an out parameter instead. --- .../Infrastructure/MemoryPoolIterator.cs | 41 ++- .../MemoryPoolIteratorExtensions.cs | 56 ++-- .../MemoryPoolIteratorTests.cs | 265 +++++++++++++++--- 3 files changed, 289 insertions(+), 73 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolIterator.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolIterator.cs index b0b6837f65..5f7e908c36 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolIterator.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolIterator.cs @@ -180,38 +180,57 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure } while (true); } - public unsafe long PeekLong() + // NOTE: Little-endian only! + public unsafe bool TryPeekLong(out ulong longValue) { + longValue = 0; + if (_block == null) { - return -1; + return false; } var wasLastBlock = _block.Next == null; + var blockBytes = _block.End - _index; - if (_block.End - _index >= sizeof(long)) + if (blockBytes >= sizeof(ulong)) { - return *(long*)(_block.DataFixedPtr + _index); + longValue = *(ulong*)(_block.DataFixedPtr + _index); + return true; } else if (wasLastBlock) { - return -1; + return false; } else { - var blockBytes = _block.End - _index; - var nextBytes = sizeof(long) - blockBytes; + // Each block will be filled with at least 2048 bytes before the Next pointer is set, so a long + // will cross at most one block boundary assuming there are at least 8 bytes following the iterator. + var nextBytes = sizeof(ulong) - blockBytes; if (_block.Next.End - _block.Next.Start < nextBytes) { - return -1; + return false; } - var blockLong = *(long*)(_block.DataFixedPtr + _block.End - sizeof(long)); + var nextLong = *(ulong*)(_block.Next.DataFixedPtr + _block.Next.Start); - var nextLong = *(long*)(_block.Next.DataFixedPtr + _block.Next.Start); + if (blockBytes == 0) + { + // This case can not fall through to the else block since that would cause a 64-bit right shift + // on blockLong which is equivalent to no shift at all instead of shifting in all zeros. + // https://msdn.microsoft.com/en-us/library/xt18et0d.aspx + longValue = nextLong; + } + else + { + var blockLong = *(ulong*)(_block.DataFixedPtr + _block.End - sizeof(ulong)); - return (blockLong >> (sizeof(long) - blockBytes) * 8) | (nextLong << (sizeof(long) - nextBytes) * 8); + // Ensure that the right shift has a ulong operand so a logical shift is performed. + longValue = (blockLong >> nextBytes * 8) | (nextLong << blockBytes * 8); + } + + return true; } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolIteratorExtensions.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolIteratorExtensions.cs index 146d9f127a..d59f689662 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolIteratorExtensions.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolIteratorExtensions.cs @@ -17,26 +17,26 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure public const string Http11Version = "HTTP/1.1"; // readonly primitive statics can be Jit'd to consts https://github.com/dotnet/coreclr/issues/1079 - private readonly static long _httpConnectMethodLong = GetAsciiStringAsLong("CONNECT "); - private readonly static long _httpDeleteMethodLong = GetAsciiStringAsLong("DELETE \0"); - private readonly static long _httpGetMethodLong = GetAsciiStringAsLong("GET \0\0\0\0"); - private readonly static long _httpHeadMethodLong = GetAsciiStringAsLong("HEAD \0\0\0"); - private readonly static long _httpPatchMethodLong = GetAsciiStringAsLong("PATCH \0\0"); - private readonly static long _httpPostMethodLong = GetAsciiStringAsLong("POST \0\0\0"); - private readonly static long _httpPutMethodLong = GetAsciiStringAsLong("PUT \0\0\0\0"); - private readonly static long _httpOptionsMethodLong = GetAsciiStringAsLong("OPTIONS "); - private readonly static long _httpTraceMethodLong = GetAsciiStringAsLong("TRACE \0\0"); + private readonly static ulong _httpConnectMethodLong = GetAsciiStringAsLong("CONNECT "); + private readonly static ulong _httpDeleteMethodLong = GetAsciiStringAsLong("DELETE \0"); + private readonly static ulong _httpGetMethodLong = GetAsciiStringAsLong("GET \0\0\0\0"); + private readonly static ulong _httpHeadMethodLong = GetAsciiStringAsLong("HEAD \0\0\0"); + private readonly static ulong _httpPatchMethodLong = GetAsciiStringAsLong("PATCH \0\0"); + private readonly static ulong _httpPostMethodLong = GetAsciiStringAsLong("POST \0\0\0"); + private readonly static ulong _httpPutMethodLong = GetAsciiStringAsLong("PUT \0\0\0\0"); + private readonly static ulong _httpOptionsMethodLong = GetAsciiStringAsLong("OPTIONS "); + private readonly static ulong _httpTraceMethodLong = GetAsciiStringAsLong("TRACE \0\0"); - private readonly static long _http10VersionLong = GetAsciiStringAsLong("HTTP/1.0"); - private readonly static long _http11VersionLong = GetAsciiStringAsLong("HTTP/1.1"); + private readonly static ulong _http10VersionLong = GetAsciiStringAsLong("HTTP/1.0"); + private readonly static ulong _http11VersionLong = GetAsciiStringAsLong("HTTP/1.1"); - private readonly static long _mask8Chars = GetMaskAsLong(new byte[] { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }); - private readonly static long _mask7Chars = GetMaskAsLong(new byte[] { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00 }); - private readonly static long _mask6Chars = GetMaskAsLong(new byte[] { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00 }); - private readonly static long _mask5Chars = GetMaskAsLong(new byte[] { 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00 }); - private readonly static long _mask4Chars = GetMaskAsLong(new byte[] { 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00 }); + private readonly static ulong _mask8Chars = GetMaskAsLong(new byte[] { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }); + private readonly static ulong _mask7Chars = GetMaskAsLong(new byte[] { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00 }); + private readonly static ulong _mask6Chars = GetMaskAsLong(new byte[] { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00 }); + private readonly static ulong _mask5Chars = GetMaskAsLong(new byte[] { 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00 }); + private readonly static ulong _mask4Chars = GetMaskAsLong(new byte[] { 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00 }); - private readonly static Tuple[] _knownMethods = new Tuple[8]; + private readonly static Tuple[] _knownMethods = new Tuple[8]; static MemoryPoolIteratorExtensions() { @@ -50,7 +50,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure _knownMethods[7] = Tuple.Create(_mask8Chars, _httpOptionsMethodLong, HttpMethods.Options); } - private unsafe static long GetAsciiStringAsLong(string str) + private unsafe static ulong GetAsciiStringAsLong(string str) { Debug.Assert(str.Length == 8, "String must be exactly 8 (ASCII) characters long."); @@ -58,16 +58,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure fixed (byte* ptr = &bytes[0]) { - return *(long*)ptr; + return *(ulong*)ptr; } } - private unsafe static long GetMaskAsLong(byte[] bytes) + private unsafe static ulong GetMaskAsLong(byte[] bytes) { Debug.Assert(bytes.Length == 8, "Mask must be exactly 8 bytes long."); fixed (byte* ptr = bytes) { - return *(long*)ptr; + return *(ulong*)ptr; } } @@ -286,7 +286,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure public static bool GetKnownMethod(this MemoryPoolIterator begin, out string knownMethod) { knownMethod = null; - var value = begin.PeekLong(); + + ulong value; + if (!begin.TryPeekLong(out value)) + { + return false; + } if ((value & _mask4Chars) == _httpGetMethodLong) { @@ -321,7 +326,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure public static bool GetKnownVersion(this MemoryPoolIterator begin, out string knownVersion) { knownVersion = null; - var value = begin.PeekLong(); + + ulong value; + if (!begin.TryPeekLong(out value)) + { + return false; + } if (value == _http11VersionLong) { diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolIteratorTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolIteratorTests.cs index ae539b10f5..454f66291f 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolIteratorTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolIteratorTests.cs @@ -299,23 +299,23 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { // Arrange var block = _pool.Lease(); - var bytes = BitConverter.GetBytes(0x0102030405060708); + var bytes = BitConverter.GetBytes(0x0102030405060708UL); Buffer.BlockCopy(bytes, 0, block.Array, block.Start, bytes.Length); block.End += bytes.Length; var scan = block.GetIterator(); var originalIndex = scan.Index; - // Act - var result = scan.PeekLong(); - // Assert - Assert.Equal(0x0102030405060708, result); + ulong result; + Assert.True(scan.TryPeekLong(out result)); + Assert.Equal(0x0102030405060708UL, result); Assert.Equal(originalIndex, scan.Index); _pool.Return(block); } [Theory] + [InlineData(0)] [InlineData(1)] [InlineData(2)] [InlineData(3)] @@ -323,31 +323,57 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [InlineData(5)] [InlineData(6)] [InlineData(7)] - public void PeekLongAtBlockBoundary(int blockBytes) + public void PeekLongNotEnoughBytes(int totalBytes) { // Arrange - var nextBlockBytes = 8 - blockBytes; + var block = _pool.Lease(); + var bytes = BitConverter.GetBytes(0x0102030405060708UL); + var bytesLength = totalBytes; + Buffer.BlockCopy(bytes, 0, block.Array, block.Start, bytesLength); + block.End += bytesLength; + var scan = block.GetIterator(); + var originalIndex = scan.Index; + + // Assert + ulong result; + Assert.False(scan.TryPeekLong(out result)); + Assert.Equal(originalIndex, scan.Index); + _pool.Return(block); + } + + [Theory] + [InlineData(0)] + [InlineData(1)] + [InlineData(2)] + [InlineData(3)] + [InlineData(4)] + [InlineData(5)] + [InlineData(6)] + [InlineData(7)] + public void PeekLongNotEnoughBytesAtBlockBoundary(int firstBlockBytes) + { + // Arrange + var expectedResult = 0x0102030405060708UL; + var nextBlockBytes = 7 - firstBlockBytes; var block = _pool.Lease(); - block.End += blockBytes; + block.End += firstBlockBytes; var nextBlock = _pool.Lease(); nextBlock.End += nextBlockBytes; block.Next = nextBlock; - var bytes = BitConverter.GetBytes(0x0102030405060708); - Buffer.BlockCopy(bytes, 0, block.Array, block.Start, blockBytes); - Buffer.BlockCopy(bytes, blockBytes, nextBlock.Array, nextBlock.Start, nextBlockBytes); + var bytes = BitConverter.GetBytes(expectedResult); + Buffer.BlockCopy(bytes, 0, block.Array, block.Start, firstBlockBytes); + Buffer.BlockCopy(bytes, firstBlockBytes, nextBlock.Array, nextBlock.Start, nextBlockBytes); var scan = block.GetIterator(); var originalIndex = scan.Index; - // Act - var result = scan.PeekLong(); - // Assert - Assert.Equal(0x0102030405060708, result); + ulong result; + Assert.False(scan.TryPeekLong(out result)); Assert.Equal(originalIndex, scan.Index); _pool.Return(block); @@ -355,6 +381,109 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } [Theory] + [InlineData(0)] + [InlineData(1)] + [InlineData(2)] + [InlineData(3)] + [InlineData(4)] + [InlineData(5)] + [InlineData(6)] + [InlineData(7)] + [InlineData(8)] + public void PeekLongAtBlockBoundary(int firstBlockBytes) + { + // Arrange + var expectedResult = 0x0102030405060708UL; + var nonZeroData = 0xFF00FFFF0000FFFFUL; + var nextBlockBytes = 8 - firstBlockBytes; + + var block = _pool.Lease(); + block.Start += 8; + block.End = block.Start + firstBlockBytes; + + var nextBlock = _pool.Lease(); + nextBlock.Start += 8; + nextBlock.End = nextBlock.Start + nextBlockBytes; + + block.Next = nextBlock; + + var bytes = BitConverter.GetBytes(expectedResult); + Buffer.BlockCopy(bytes, 0, block.Array, block.Start, firstBlockBytes); + Buffer.BlockCopy(bytes, firstBlockBytes, nextBlock.Array, nextBlock.Start, nextBlockBytes); + + // Fill in surrounding bytes with non-zero data + var nonZeroBytes = BitConverter.GetBytes(nonZeroData); + Buffer.BlockCopy(nonZeroBytes, 0, block.Array, block.Start - 8, 8); + Buffer.BlockCopy(nonZeroBytes, 0, block.Array, block.End, 8); + Buffer.BlockCopy(nonZeroBytes, 0, nextBlock.Array, nextBlock.Start - 8, 8); + Buffer.BlockCopy(nonZeroBytes, 0, nextBlock.Array, nextBlock.End, 8); + + var scan = block.GetIterator(); + var originalIndex = scan.Index; + + // Assert + ulong result; + Assert.True(scan.TryPeekLong(out result)); + Assert.Equal(expectedResult, result); + Assert.Equal(originalIndex, scan.Index); + + _pool.Return(block); + _pool.Return(nextBlock); + } + + [Theory] + [InlineData(0)] + [InlineData(1)] + [InlineData(2)] + [InlineData(3)] + [InlineData(4)] + [InlineData(5)] + [InlineData(6)] + [InlineData(7)] + [InlineData(8)] + public void PeekLongAtBlockBoundarayWithMostSignificatBitsSet(int firstBlockBytes) + { + // Arrange + var expectedResult = 0xFF02030405060708UL; + var nonZeroData = 0xFF00FFFF0000FFFFUL; + var nextBlockBytes = 8 - firstBlockBytes; + + var block = _pool.Lease(); + block.Start += 8; + block.End = block.Start + firstBlockBytes; + + var nextBlock = _pool.Lease(); + nextBlock.Start += 8; + nextBlock.End = nextBlock.Start + nextBlockBytes; + + block.Next = nextBlock; + + var expectedBytes = BitConverter.GetBytes(expectedResult); + Buffer.BlockCopy(expectedBytes, 0, block.Array, block.Start, firstBlockBytes); + Buffer.BlockCopy(expectedBytes, firstBlockBytes, nextBlock.Array, nextBlock.Start, nextBlockBytes); + + // Fill in surrounding bytes with non-zero data + var nonZeroBytes = BitConverter.GetBytes(nonZeroData); + Buffer.BlockCopy(nonZeroBytes, 0, block.Array, block.Start - 8, 8); + Buffer.BlockCopy(nonZeroBytes, 0, block.Array, block.End, 8); + Buffer.BlockCopy(nonZeroBytes, 0, nextBlock.Array, nextBlock.Start - 8, 8); + Buffer.BlockCopy(nonZeroBytes, 0, nextBlock.Array, nextBlock.End, 8); + + var scan = block.GetIterator(); + var originalIndex = scan.Index; + + // Assert + ulong result; + Assert.True(scan.TryPeekLong(out result)); + Assert.Equal(expectedResult, result); + Assert.Equal(originalIndex, scan.Index); + + _pool.Return(block); + _pool.Return(nextBlock); + } + + [Theory] + [InlineData(0)] [InlineData(1)] [InlineData(2)] [InlineData(3)] @@ -432,23 +561,23 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } [Theory] - [InlineData("CONNECT / HTTP/1.1", ' ', true, "CONNECT")] - [InlineData("DELETE / HTTP/1.1", ' ', true, "DELETE")] - [InlineData("GET / HTTP/1.1", ' ', true, "GET")] - [InlineData("HEAD / HTTP/1.1", ' ', true, "HEAD")] - [InlineData("PATCH / HTTP/1.1", ' ', true, "PATCH")] - [InlineData("POST / HTTP/1.1", ' ', true, "POST")] - [InlineData("PUT / HTTP/1.1", ' ', true, "PUT")] - [InlineData("OPTIONS / HTTP/1.1", ' ', true, "OPTIONS")] - [InlineData("TRACE / HTTP/1.1", ' ', true, "TRACE")] - [InlineData("GET/ HTTP/1.1", ' ', false, null)] - [InlineData("get / HTTP/1.1", ' ', false, null)] - [InlineData("GOT / HTTP/1.1", ' ', false, null)] - [InlineData("ABC / HTTP/1.1", ' ', false, null)] - [InlineData("PO / HTTP/1.1", ' ', false, null)] - [InlineData("PO ST / HTTP/1.1", ' ', false, null)] - [InlineData("short ", ' ', false, null)] - public void GetsKnownMethod(string input, char endChar, bool expectedResult, string expectedKnownString) + [InlineData("CONNECT / HTTP/1.1", true, "CONNECT")] + [InlineData("DELETE / HTTP/1.1", true, "DELETE")] + [InlineData("GET / HTTP/1.1", true, "GET")] + [InlineData("HEAD / HTTP/1.1", true, "HEAD")] + [InlineData("PATCH / HTTP/1.1", true, "PATCH")] + [InlineData("POST / HTTP/1.1", true, "POST")] + [InlineData("PUT / HTTP/1.1", true, "PUT")] + [InlineData("OPTIONS / HTTP/1.1", true, "OPTIONS")] + [InlineData("TRACE / HTTP/1.1", true, "TRACE")] + [InlineData("GET/ HTTP/1.1", false, null)] + [InlineData("get / HTTP/1.1", false, null)] + [InlineData("GOT / HTTP/1.1", false, null)] + [InlineData("ABC / HTTP/1.1", false, null)] + [InlineData("PO / HTTP/1.1", false, null)] + [InlineData("PO ST / HTTP/1.1", false, null)] + [InlineData("short ", false, null)] + public void GetsKnownMethod(string input, bool expectedResult, string expectedKnownString) { // Arrange var block = _pool.Lease(); @@ -465,17 +594,46 @@ namespace Microsoft.AspNetCore.Server.KestrelTests Assert.Equal(expectedResult, result); Assert.Equal(expectedKnownString, knownString); + // Test at boundary + var maxSplit = Math.Min(input.Length, 8); + var nextBlock = _pool.Lease(); + + for (var split = 0; split <= maxSplit; split++) + { + // Arrange + block.Reset(); + nextBlock.Reset(); + + Buffer.BlockCopy(chars, 0, block.Array, block.Start, split); + Buffer.BlockCopy(chars, split, nextBlock.Array, nextBlock.Start, chars.Length - split); + + block.End += split; + nextBlock.End += chars.Length - split; + block.Next = nextBlock; + + var boundaryBegin = block.GetIterator(); + string boundaryKnownString; + + // Act + var boundaryResult = boundaryBegin.GetKnownMethod(out boundaryKnownString); + + // Assert + Assert.Equal(expectedResult, boundaryResult); + Assert.Equal(expectedKnownString, boundaryKnownString); + } + _pool.Return(block); + _pool.Return(nextBlock); } [Theory] - [InlineData("HTTP/1.0\r", '\r', true, MemoryPoolIteratorExtensions.Http10Version)] - [InlineData("HTTP/1.1\r", '\r', true, MemoryPoolIteratorExtensions.Http11Version)] - [InlineData("HTTP/3.0\r", '\r', false, null)] - [InlineData("http/1.0\r", '\r', false, null)] - [InlineData("http/1.1\r", '\r', false, null)] - [InlineData("short ", ' ', false, null)] - public void GetsKnownVersion(string input, char endChar, bool expectedResult, string expectedKnownString) + [InlineData("HTTP/1.0\r", true, MemoryPoolIteratorExtensions.Http10Version)] + [InlineData("HTTP/1.1\r", true, MemoryPoolIteratorExtensions.Http11Version)] + [InlineData("HTTP/3.0\r", false, null)] + [InlineData("http/1.0\r", false, null)] + [InlineData("http/1.1\r", false, null)] + [InlineData("short ", false, null)] + public void GetsKnownVersion(string input, bool expectedResult, string expectedKnownString) { // Arrange var block = _pool.Lease(); @@ -491,7 +649,36 @@ namespace Microsoft.AspNetCore.Server.KestrelTests Assert.Equal(expectedResult, result); Assert.Equal(expectedKnownString, knownString); + // Test at boundary + var maxSplit = Math.Min(input.Length, 9); + var nextBlock = _pool.Lease(); + + for (var split = 0; split <= maxSplit; split++) + { + // Arrange + block.Reset(); + nextBlock.Reset(); + + Buffer.BlockCopy(chars, 0, block.Array, block.Start, split); + Buffer.BlockCopy(chars, split, nextBlock.Array, nextBlock.Start, chars.Length - split); + + block.End += split; + nextBlock.End += chars.Length - split; + block.Next = nextBlock; + + var boundaryBegin = block.GetIterator(); + string boundaryKnownString; + + // Act + var boundaryResult = boundaryBegin.GetKnownVersion(out boundaryKnownString); + + // Assert + Assert.Equal(expectedResult, boundaryResult); + Assert.Equal(expectedKnownString, boundaryKnownString); + } + _pool.Return(block); + _pool.Return(nextBlock); } [Theory] From 5e97c634679591d889a8d3bb554ce8cfccbe42dc Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Thu, 27 Oct 2016 15:29:29 -0700 Subject: [PATCH 0929/1662] Throw PlatformNotSupportedException on big-endian platforms --- src/Microsoft.AspNetCore.Server.Kestrel/KestrelServer.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServer.cs b/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServer.cs index d9844714de..d26fa002b0 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServer.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServer.cs @@ -59,6 +59,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel { try { + if (!BitConverter.IsLittleEndian) + { + throw new PlatformNotSupportedException("Kestrel does not support big-endian architectures."); + } + ValidateOptions(); if (_disposables != null) From cc05e36dc628ef3f99446195f12def4db2712401 Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Fri, 28 Oct 2016 17:03:11 -0700 Subject: [PATCH 0930/1662] Fix test failures caused by connection resets (#1167). --- .../EngineTests.cs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs index 8c961f81ec..ef73602834 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs @@ -580,6 +580,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { using (var server = new TestServer(async httpContext => { + // This will hang if 0 content length is not assumed by the server Assert.Equal(0, await httpContext.Request.Body.ReadAsync(new byte[1], 0, 1).TimeoutAfter(TimeSpan.FromSeconds(10))); }, testContext)) { @@ -592,8 +593,8 @@ namespace Microsoft.AspNetCore.Server.KestrelTests "GET / HTTP/1.1", "Connection: close", "", - "a"); - await connection.ReceiveEnd( + ""); + await connection.ReceiveForcedEnd( "HTTP/1.1 200 OK", "Connection: close", $"Date: {testContext.DateHeaderValue}", @@ -607,8 +608,8 @@ namespace Microsoft.AspNetCore.Server.KestrelTests await connection.Send( "GET / HTTP/1.0", "", - "a"); - await connection.ReceiveEnd( + ""); + await connection.ReceiveForcedEnd( "HTTP/1.1 200 OK", "Connection: close", $"Date: {testContext.DateHeaderValue}", From 29408956f990efba5a04e8b9c6c210058b5e19a3 Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Thu, 27 Oct 2016 15:54:23 -0700 Subject: [PATCH 0931/1662] Handle tokens in Transfer-Encoding header (#1181). --- .../BadHttpRequestException.cs | 3 + .../Internal/Http/Frame.cs | 23 ++- .../Internal/Http/FrameHeaders.cs | 68 ++++++++- .../Internal/Http/MessageBody.cs | 17 ++- .../Internal/Http/RequestRejectionReason.cs | 1 + .../Internal/Http/TransferCoding.cs | 15 ++ .../ResponseTests.cs | 134 ++++++++++++++++++ .../ChunkedRequestTests.cs | 101 +++++++++++++ .../FrameHeadersTests.cs | 80 ++++++++++- .../MessageBodyTests.cs | 14 ++ .../TestInput.cs | 1 + test/shared/TestConnection.cs | 4 +- 12 files changed, 443 insertions(+), 18 deletions(-) create mode 100644 src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/TransferCoding.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/BadHttpRequestException.cs b/src/Microsoft.AspNetCore.Server.Kestrel/BadHttpRequestException.cs index 775fb2344d..2b4aa25f12 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/BadHttpRequestException.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/BadHttpRequestException.cs @@ -99,6 +99,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel case RequestRejectionReason.UnrecognizedHTTPVersion: ex = new BadHttpRequestException($"Unrecognized HTTP version: {value}", 505); break; + case RequestRejectionReason.FinalTransferCodingNotChunked: + ex = new BadHttpRequestException($"Final transfer coding is not \"chunked\": \"{value}\"", 400); + break; default: ex = new BadHttpRequestException("Bad request.", 400); break; diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs index c6f90a2858..be3f0f083b 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs @@ -811,7 +811,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { var responseHeaders = FrameResponseHeaders; var hasConnection = responseHeaders.HasConnection; - var connectionOptions = hasConnection ? FrameHeaders.ParseConnection(responseHeaders.HeaderConnection) : ConnectionOptions.None; + var connectionOptions = FrameHeaders.ParseConnection(responseHeaders.HeaderConnection); + var hasTransferEncoding = responseHeaders.HasTransferEncoding; + var transferCoding = FrameHeaders.GetFinalTransferCoding(responseHeaders.HeaderTransferEncoding); var end = SocketOutput.ProducingStart(); @@ -820,6 +822,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _keepAlive = (connectionOptions & ConnectionOptions.KeepAlive) == ConnectionOptions.KeepAlive; } + // https://tools.ietf.org/html/rfc7230#section-3.3.1 + // If any transfer coding other than + // chunked is applied to a response payload body, the sender MUST either + // apply chunked as the final transfer coding or terminate the message + // by closing the connection. + if (hasTransferEncoding && transferCoding != TransferCoding.Chunked) + { + _keepAlive = false; + } + // Set whether response can have body _canHaveBody = StatusCanHaveBody(StatusCode) && Method != "HEAD"; @@ -827,7 +839,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http // automatically for HEAD requests or 204, 205, 304 responses. if (_canHaveBody) { - if (!responseHeaders.HasTransferEncoding && !responseHeaders.HasContentLength) + if (!hasTransferEncoding && !responseHeaders.HasContentLength) { if (appCompleted && StatusCode != 101) { @@ -856,12 +868,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } } } - else + else if (hasTransferEncoding) { - if (responseHeaders.HasTransferEncoding) - { - RejectNonBodyTransferEncodingResponse(appCompleted); - } + RejectNonBodyTransferEncodingResponse(appCompleted); } responseHeaders.SetReadOnly(); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameHeaders.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameHeaders.cs index d0d3114268..e4d42e1eaa 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameHeaders.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameHeaders.cs @@ -308,7 +308,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http ch++; } - if (ch == tokenEnd || *ch == ',') + if (ch == tokenEnd) { connectionOptions |= ConnectionOptions.KeepAlive; } @@ -329,7 +329,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http ch++; } - if (ch == tokenEnd || *ch == ',') + if (ch == tokenEnd) { connectionOptions |= ConnectionOptions.Upgrade; } @@ -348,7 +348,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http ch++; } - if (ch == tokenEnd || *ch == ',') + if (ch == tokenEnd) { connectionOptions |= ConnectionOptions.Close; } @@ -364,6 +364,68 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http return connectionOptions; } + public static unsafe TransferCoding GetFinalTransferCoding(StringValues transferEncoding) + { + var transferEncodingOptions = TransferCoding.None; + + foreach (var value in transferEncoding) + { + fixed (char* ptr = value) + { + var ch = ptr; + var tokenEnd = ch; + var end = ch + value.Length; + + while (ch < end) + { + while (tokenEnd < end && *tokenEnd != ',') + { + tokenEnd++; + } + + while (ch < tokenEnd && *ch == ' ') + { + ch++; + } + + var tokenLength = tokenEnd - ch; + + if (tokenLength >= 7 && (*ch | 0x20) == 'c') + { + if ((*++ch | 0x20) == 'h' && + (*++ch | 0x20) == 'u' && + (*++ch | 0x20) == 'n' && + (*++ch | 0x20) == 'k' && + (*++ch | 0x20) == 'e' && + (*++ch | 0x20) == 'd') + { + ch++; + while (ch < tokenEnd && *ch == ' ') + { + ch++; + } + + if (ch == tokenEnd) + { + transferEncodingOptions = TransferCoding.Chunked; + } + } + } + + if (tokenLength > 0 && ch != tokenEnd) + { + transferEncodingOptions = TransferCoding.Other; + } + + tokenEnd++; + ch = tokenEnd; + } + } + } + + return transferEncodingOptions; + } + private static void ThrowInvalidContentLengthException(string value) { throw new InvalidOperationException($"Invalid Content-Length: \"{value}\". Value must be a positive integral number."); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/MessageBody.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/MessageBody.cs index a3e0093089..c2843a2d00 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/MessageBody.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/MessageBody.cs @@ -247,9 +247,22 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http keepAlive = (connectionOptions & ConnectionOptions.KeepAlive) == ConnectionOptions.KeepAlive; } - var transferEncoding = headers.HeaderTransferEncoding.ToString(); - if (transferEncoding.Length > 0) + var transferEncoding = headers.HeaderTransferEncoding; + if (transferEncoding.Count > 0) { + var transferCoding = FrameHeaders.GetFinalTransferCoding(headers.HeaderTransferEncoding); + + // https://tools.ietf.org/html/rfc7230#section-3.3.3 + // If a Transfer-Encoding header field + // is present in a request and the chunked transfer coding is not + // the final encoding, the message body length cannot be determined + // reliably; the server MUST respond with the 400 (Bad Request) + // status code and then close the connection. + if (transferCoding != TransferCoding.Chunked) + { + context.RejectRequest(RequestRejectionReason.FinalTransferCodingNotChunked, transferEncoding.ToString()); + } + return new ForChunkedEncoding(keepAlive, headers, context); } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/RequestRejectionReason.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/RequestRejectionReason.cs index 07ed7444e4..68693304e0 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/RequestRejectionReason.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/RequestRejectionReason.cs @@ -27,5 +27,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http MissingCRInHeaderLine, TooManyHeaders, RequestTimeout, + FinalTransferCodingNotChunked } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/TransferCoding.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/TransferCoding.cs new file mode 100644 index 0000000000..3bfa8cc74b --- /dev/null +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/TransferCoding.cs @@ -0,0 +1,15 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; + +namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http +{ + [Flags] + public enum TransferCoding + { + None, + Chunked, + Other + } +} diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs index f62dfc8e17..d25b55e06f 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs @@ -848,6 +848,140 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } } + [Theory] + [InlineData("gzip")] + [InlineData("chunked, gzip")] + [InlineData("gzip")] + [InlineData("chunked, gzip")] + public async Task ConnectionClosedWhenChunkedIsNotFinalTransferCoding(string responseTransferEncoding) + { + using (var server = new TestServer(async httpContext => + { + httpContext.Response.Headers["Transfer-Encoding"] = responseTransferEncoding; + await httpContext.Response.WriteAsync("hello, world"); + }, new TestServiceContext())) + { + using (var connection = server.CreateConnection()) + { + await connection.Send( + "GET / HTTP/1.1", + "", + ""); + await connection.ReceiveEnd( + "HTTP/1.1 200 OK", + "Connection: close", + $"Date: {server.Context.DateHeaderValue}", + $"Transfer-Encoding: {responseTransferEncoding}", + "", + "hello, world"); + } + + using (var connection = server.CreateConnection()) + { + await connection.Send( + "GET / HTTP/1.0", + "Connection: keep-alive", + "", + ""); + await connection.ReceiveEnd( + "HTTP/1.1 200 OK", + "Connection: close", + $"Date: {server.Context.DateHeaderValue}", + $"Transfer-Encoding: {responseTransferEncoding}", + "", + "hello, world"); + } + } + } + + [Theory] + [InlineData("gzip")] + [InlineData("chunked, gzip")] + [InlineData("gzip")] + [InlineData("chunked, gzip")] + public async Task ConnectionClosedWhenChunkedIsNotFinalTransferCodingEvenIfConnectionKeepAliveSetInResponse(string responseTransferEncoding) + { + using (var server = new TestServer(async httpContext => + { + httpContext.Response.Headers["Connection"] = "keep-alive"; + httpContext.Response.Headers["Transfer-Encoding"] = responseTransferEncoding; + await httpContext.Response.WriteAsync("hello, world"); + }, new TestServiceContext())) + { + using (var connection = server.CreateConnection()) + { + await connection.Send( + "GET / HTTP/1.1", + "", + ""); + await connection.ReceiveEnd( + "HTTP/1.1 200 OK", + "Connection: keep-alive", + $"Date: {server.Context.DateHeaderValue}", + $"Transfer-Encoding: {responseTransferEncoding}", + "", + "hello, world"); + } + + using (var connection = server.CreateConnection()) + { + await connection.Send( + "GET / HTTP/1.0", + "Connection: keep-alive", + "", + ""); + await connection.ReceiveEnd( + "HTTP/1.1 200 OK", + "Connection: keep-alive", + $"Date: {server.Context.DateHeaderValue}", + $"Transfer-Encoding: {responseTransferEncoding}", + "", + "hello, world"); + } + } + } + + [Theory] + [InlineData("chunked")] + [InlineData("gzip, chunked")] + public async Task ConnectionKeptAliveWhenChunkedIsFinalTransferCoding(string responseTransferEncoding) + { + using (var server = new TestServer(async httpContext => + { + httpContext.Response.Headers["Transfer-Encoding"] = responseTransferEncoding; + + // App would have to chunk manually, but here we don't care + await httpContext.Response.WriteAsync("hello, world"); + }, new TestServiceContext())) + { + using (var connection = server.CreateConnection()) + { + await connection.Send( + "GET / HTTP/1.1", + "", + ""); + await connection.Receive( + "HTTP/1.1 200 OK", + $"Date: {server.Context.DateHeaderValue}", + $"Transfer-Encoding: {responseTransferEncoding}", + "", + "hello, world"); + + // Make sure connection was kept open + await connection.SendEnd( + "GET / HTTP/1.1", + "", + ""); + await connection.ReceiveEnd( + "HTTP/1.1 200 OK", + $"Date: {server.Context.DateHeaderValue}", + $"Transfer-Encoding: {responseTransferEncoding}", + "", + "hello, world"); + } + } + } + public static TheoryData NullHeaderData { get diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedRequestTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedRequestTests.cs index 221922a050..30f4ecd9d6 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedRequestTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedRequestTests.cs @@ -8,6 +8,7 @@ using System.Text; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Testing; +using Microsoft.Extensions.Internal; using Xunit; namespace Microsoft.AspNetCore.Server.KestrelTests @@ -512,6 +513,106 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } } } + + + [Theory] + [MemberData(nameof(ConnectionFilterData))] + public async Task ChunkedNotFinalTransferCodingResultsIn400(TestServiceContext testContext) + { + using (var server = new TestServer(httpContext => + { + return TaskCache.CompletedTask; + }, testContext)) + { + using (var connection = server.CreateConnection()) + { + await connection.SendAll( + "POST / HTTP/1.1", + "Transfer-Encoding: not-chunked", + "", + "C", + "hello, world", + "0", + "", + ""); + + await connection.ReceiveForcedEnd( + "HTTP/1.1 400 Bad Request", + "Connection: close", + $"Date: {testContext.DateHeaderValue}", + "Content-Length: 0", + "", + ""); + } + + // Content-Length should not affect this + using (var connection = server.CreateConnection()) + { + await connection.SendAll( + "POST / HTTP/1.1", + "Transfer-Encoding: not-chunked", + "Content-Length: 22", + "", + "C", + "hello, world", + "0", + "", + ""); + + await connection.ReceiveForcedEnd( + "HTTP/1.1 400 Bad Request", + "Connection: close", + $"Date: {testContext.DateHeaderValue}", + "Content-Length: 0", + "", + ""); + } + + using (var connection = server.CreateConnection()) + { + await connection.SendAll( + "POST / HTTP/1.1", + "Transfer-Encoding: chunked, not-chunked", + "", + "C", + "hello, world", + "0", + "", + ""); + + await connection.ReceiveForcedEnd( + "HTTP/1.1 400 Bad Request", + "Connection: close", + $"Date: {testContext.DateHeaderValue}", + "Content-Length: 0", + "", + ""); + } + + // Content-Length should not affect this + using (var connection = server.CreateConnection()) + { + await connection.SendAll( + "POST / HTTP/1.1", + "Transfer-Encoding: chunked, not-chunked", + "Content-Length: 22", + "", + "C", + "hello, world", + "0", + "", + ""); + + await connection.ReceiveForcedEnd( + "HTTP/1.1 400 Bad Request", + "Connection: close", + $"Date: {testContext.DateHeaderValue}", + "Content-Length: 0", + "", + ""); + } + } + } } } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameHeadersTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameHeadersTests.cs index c8cc648376..6e41b778e2 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameHeadersTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameHeadersTests.cs @@ -10,6 +10,16 @@ namespace Microsoft.AspNetCore.Server.KestrelTests public class FrameHeadersTests { [Theory] + [InlineData("", ConnectionOptions.None)] + [InlineData(",", ConnectionOptions.None)] + [InlineData(" ,", ConnectionOptions.None)] + [InlineData(" , ", ConnectionOptions.None)] + [InlineData(",,", ConnectionOptions.None)] + [InlineData(" ,,", ConnectionOptions.None)] + [InlineData(",, ", ConnectionOptions.None)] + [InlineData(" , ,", ConnectionOptions.None)] + [InlineData(" , ,", ConnectionOptions.None)] + [InlineData(" , , ", ConnectionOptions.None)] [InlineData("keep-alive", ConnectionOptions.KeepAlive)] [InlineData("keep-alive, upgrade", ConnectionOptions.KeepAlive | ConnectionOptions.Upgrade)] [InlineData("keep-alive,upgrade", ConnectionOptions.KeepAlive | ConnectionOptions.Upgrade)] @@ -123,10 +133,10 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [InlineData("up2rade ,", ConnectionOptions.None)] [InlineData("c2ose ,", ConnectionOptions.None)] [InlineData("cl2se ,", ConnectionOptions.None)] - public void TestParseConnection(string connection, ConnectionOptions expectedConnectionOptionss) + public void TestParseConnection(string connection, ConnectionOptions expectedConnectionOptions) { var connectionOptions = FrameHeaders.ParseConnection(connection); - Assert.Equal(expectedConnectionOptionss, connectionOptions); + Assert.Equal(expectedConnectionOptions, connectionOptions); } [Theory] @@ -145,11 +155,73 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [InlineData("", "close", ConnectionOptions.Close)] [InlineData("close", "upgrade", ConnectionOptions.Close | ConnectionOptions.Upgrade)] [InlineData("upgrade", "close", ConnectionOptions.Close | ConnectionOptions.Upgrade)] - public void TestParseConnectionMultipleValues(string value1, string value2, ConnectionOptions expectedConnectionOptionss) + public void TestParseConnectionMultipleValues(string value1, string value2, ConnectionOptions expectedConnectionOptions) { var connection = new StringValues(new[] { value1, value2 }); var connectionOptions = FrameHeaders.ParseConnection(connection); - Assert.Equal(expectedConnectionOptionss, connectionOptions); + Assert.Equal(expectedConnectionOptions, connectionOptions); + } + + [Theory] + [InlineData("", TransferCoding.None)] + [InlineData(",,", TransferCoding.None)] + [InlineData(" ,,", TransferCoding.None)] + [InlineData(",, ", TransferCoding.None)] + [InlineData(" , ,", TransferCoding.None)] + [InlineData(" , ,", TransferCoding.None)] + [InlineData(" , , ", TransferCoding.None)] + [InlineData("chunked,", TransferCoding.Chunked)] + [InlineData("chunked,,", TransferCoding.Chunked)] + [InlineData(",chunked", TransferCoding.Chunked)] + [InlineData(",,chunked", TransferCoding.Chunked)] + [InlineData("chunked, ", TransferCoding.Chunked)] + [InlineData("chunked, ,", TransferCoding.Chunked)] + [InlineData("chunked, , ", TransferCoding.Chunked)] + [InlineData("chunked ,", TransferCoding.Chunked)] + [InlineData(",chunked", TransferCoding.Chunked)] + [InlineData(", chunked", TransferCoding.Chunked)] + [InlineData(",,chunked", TransferCoding.Chunked)] + [InlineData(", ,chunked", TransferCoding.Chunked)] + [InlineData(",, chunked", TransferCoding.Chunked)] + [InlineData(", , chunked", TransferCoding.Chunked)] + [InlineData("chunked, gzip", TransferCoding.Other)] + [InlineData("chunked,compress", TransferCoding.Other)] + [InlineData("deflate, chunked", TransferCoding.Chunked)] + [InlineData("gzip,chunked", TransferCoding.Chunked)] + [InlineData("compress,,chunked", TransferCoding.Chunked)] + [InlineData("chunkedchunked", TransferCoding.Other)] + [InlineData("chunked2", TransferCoding.Other)] + [InlineData("chunked 2", TransferCoding.Other)] + [InlineData("2chunked", TransferCoding.Other)] + [InlineData("c2unked", TransferCoding.Other)] + [InlineData("ch2nked", TransferCoding.Other)] + [InlineData("chunked 2, gzip", TransferCoding.Other)] + [InlineData("chunked2, gzip", TransferCoding.Other)] + [InlineData("gzip, chunked 2", TransferCoding.Other)] + [InlineData("gzip, chunked2", TransferCoding.Other)] + public void TestParseTransferEncoding(string transferEncoding, TransferCoding expectedTransferEncodingOptions) + { + var transferEncodingOptions = FrameHeaders.GetFinalTransferCoding(transferEncoding); + Assert.Equal(expectedTransferEncodingOptions, transferEncodingOptions); + } + + [Theory] + [InlineData("chunked", "gzip", TransferCoding.Other)] + [InlineData("compress", "chunked", TransferCoding.Chunked)] + [InlineData("chunked", "", TransferCoding.Chunked)] + [InlineData("", "chunked", TransferCoding.Chunked)] + [InlineData("chunked, deflate", "", TransferCoding.Other)] + [InlineData("gzip, chunked", "", TransferCoding.Chunked)] + [InlineData("", "chunked, compress", TransferCoding.Other)] + [InlineData("", "compress, chunked", TransferCoding.Chunked)] + [InlineData("", "", TransferCoding.None)] + [InlineData("deflate", "", TransferCoding.Other)] + [InlineData("", "gzip", TransferCoding.Other)] + public void TestParseTransferEncodingMultipleValues(string value1, string value2, TransferCoding expectedTransferEncodingOptions) + { + var transferEncoding = new StringValues(new[] { value1, value2 }); + var transferEncodingOptions = FrameHeaders.GetFinalTransferCoding(transferEncoding); + Assert.Equal(expectedTransferEncodingOptions, transferEncodingOptions); } } } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/MessageBodyTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/MessageBodyTests.cs index 427189fd1b..4ada15b2c5 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/MessageBodyTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/MessageBodyTests.cs @@ -8,6 +8,7 @@ using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; +using Microsoft.AspNetCore.Server.Kestrel; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; using Microsoft.AspNetCore.Server.KestrelTests.TestHelpers; using Microsoft.Extensions.Internal; @@ -189,6 +190,19 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } } + [Fact] + public void ForThrowsWhenFinalTransferCodingIsNotChunked() + { + using (var input = new TestInput()) + { + var ex = Assert.Throws(() => + MessageBody.For(HttpVersion.Http10, new FrameRequestHeaders { HeaderTransferEncoding = "chunked, not-chunked" }, input.FrameContext)); + + Assert.Equal(400, ex.StatusCode); + Assert.Equal("Final transfer coding is not \"chunked\": \"chunked, not-chunked\"", ex.Message); + } + } + public static IEnumerable StreamData => new[] { new object[] { new ThrowOnWriteSynchronousStream() }, diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestInput.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/TestInput.cs index 3de1e92e07..872e4512f4 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/TestInput.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/TestInput.cs @@ -38,6 +38,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var context = new Frame(null, connectionContext); FrameContext = context; FrameContext.FrameControl = this; + FrameContext.ConnectionContext.ListenerContext.ServiceContext.Log = trace; _memoryPool = new MemoryPool(); FrameContext.SocketInput = new SocketInput(_memoryPool, ltp); diff --git a/test/shared/TestConnection.cs b/test/shared/TestConnection.cs index 3b00841109..56e6c53ce2 100644 --- a/test/shared/TestConnection.cs +++ b/test/shared/TestConnection.cs @@ -115,7 +115,7 @@ namespace Microsoft.AspNetCore.Testing { await Receive(lines); var ch = new char[128]; - var count = await _reader.ReadAsync(ch, 0, 128); + var count = await _reader.ReadAsync(ch, 0, 128).TimeoutAfter(TimeSpan.FromMinutes(1)); var text = new string(ch, 0, count); Assert.Equal("", text); } @@ -127,7 +127,7 @@ namespace Microsoft.AspNetCore.Testing try { var ch = new char[128]; - var count = await _reader.ReadAsync(ch, 0, 128); + var count = await _reader.ReadAsync(ch, 0, 128).TimeoutAfter(TimeSpan.FromMinutes(1)); var text = new string(ch, 0, count); Assert.Equal("", text); } From 2adb6ff955ac9bc84d0ff7556536acd3aff3a138 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Fri, 7 Oct 2016 00:59:31 +0100 Subject: [PATCH 0932/1662] Interlocked.Read -> Volatile.Read --- .../Internal/Http/Connection.cs | 2 +- .../Internal/Http/DateHeaderValueManager.cs | 3 ++- .../Internal/Networking/PlatformApis.cs | 17 +++++++++++++++++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Connection.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Connection.cs index 9c9e225a9f..d48bc08944 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Connection.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Connection.cs @@ -171,7 +171,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http // Called on Libuv thread public void Tick(long timestamp) { - if (timestamp > Interlocked.Read(ref _timeoutTimestamp)) + if (timestamp > PlatformApis.VolatileRead(ref _timeoutTimestamp)) { ConnectionControl.CancelTimeout(); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/DateHeaderValueManager.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/DateHeaderValueManager.cs index b824fb606d..cb36c22d34 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/DateHeaderValueManager.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/DateHeaderValueManager.cs @@ -6,6 +6,7 @@ using System.Text; using System.Threading; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.Net.Http.Headers; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { @@ -158,7 +159,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } // No requests since the last timer tick, we need to check if we're beyond the idle threshold - if ((now.Ticks - Interlocked.Read(ref _lastRequestSeenTicks)) >= _timeWithoutRequestsUntilIdle.Ticks) + if ((now.Ticks - PlatformApis.VolatileRead(ref _lastRequestSeenTicks)) >= _timeWithoutRequestsUntilIdle.Ticks) { // No requests since idle threshold so stop the timer if it's still running StopTimer(); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/PlatformApis.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/PlatformApis.cs index e81974adb2..6cd2341815 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/PlatformApis.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/PlatformApis.cs @@ -1,7 +1,10 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; +using System.Runtime.CompilerServices; using System.Runtime.InteropServices; +using System.Threading; namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking { @@ -16,5 +19,19 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking public static bool IsWindows { get; } public static bool IsDarwin { get; } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static long VolatileRead(ref long value) + { + if (IntPtr.Size == 8) + { + return Volatile.Read(ref value); + } + else + { + // Avoid torn long reads on 32-bit + return Interlocked.Read(ref value); + } + } } } From 7bf6f0d2ab18b176e40aa42d84b75d7af58721a0 Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Wed, 2 Nov 2016 12:27:25 -0700 Subject: [PATCH 0933/1662] Updating to version 1.0.2. --- samples/LargeResponseApp/project.json | 2 +- samples/SampleApp/project.json | 4 ++-- src/Microsoft.AspNetCore.Server.Kestrel.Https/project.json | 4 ++-- src/Microsoft.AspNetCore.Server.Kestrel/project.json | 2 +- .../project.json | 4 ++-- test/Microsoft.AspNetCore.Server.KestrelTests/project.json | 4 ++-- 6 files changed, 10 insertions(+), 10 deletions(-) diff --git a/samples/LargeResponseApp/project.json b/samples/LargeResponseApp/project.json index dbf8d5adcb..c0999b69c9 100644 --- a/samples/LargeResponseApp/project.json +++ b/samples/LargeResponseApp/project.json @@ -1,7 +1,7 @@ { "version": "1.0.0-*", "dependencies": { - "Microsoft.AspNetCore.Server.Kestrel": "1.0.1" + "Microsoft.AspNetCore.Server.Kestrel": "1.0.2" }, "buildOptions": { "emitEntryPoint": true diff --git a/samples/SampleApp/project.json b/samples/SampleApp/project.json index e6b62ac106..6822d6300b 100644 --- a/samples/SampleApp/project.json +++ b/samples/SampleApp/project.json @@ -1,8 +1,8 @@ { "version": "1.0.0-*", "dependencies": { - "Microsoft.AspNetCore.Server.Kestrel": "1.0.1", - "Microsoft.AspNetCore.Server.Kestrel.Https": "1.0.1", + "Microsoft.AspNetCore.Server.Kestrel": "1.0.2", + "Microsoft.AspNetCore.Server.Kestrel.Https": "1.0.2", "Microsoft.Extensions.Logging.Console": "1.0.0" }, "buildOptions": { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Https/project.json b/src/Microsoft.AspNetCore.Server.Kestrel.Https/project.json index 42633e4761..dcb023542c 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Https/project.json +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Https/project.json @@ -1,5 +1,5 @@ { - "version": "1.0.1", + "version": "1.0.2", "description": "HTTPS support for the ASP.NET Core Kestrel cross-platform web server.", "buildOptions": { "keyFile": "../../tools/Key.snk", @@ -19,7 +19,7 @@ ] }, "dependencies": { - "Microsoft.AspNetCore.Server.Kestrel": "1.0.1" + "Microsoft.AspNetCore.Server.Kestrel": "1.0.2" }, "frameworks": { "net451": {}, diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/project.json b/src/Microsoft.AspNetCore.Server.Kestrel/project.json index 4cf319e351..a8cc228482 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/project.json +++ b/src/Microsoft.AspNetCore.Server.Kestrel/project.json @@ -1,5 +1,5 @@ { - "version": "1.0.1", + "version": "1.0.2", "description": "ASP.NET Core Kestrel cross-platform web server.", "packOptions": { "repository": { diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json index 12ce280144..16bdbf98ea 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json @@ -3,8 +3,8 @@ "dependencies": { "dotnet-test-xunit": "1.0.0-rc3-000000-01", "Microsoft.AspNetCore.Http.Abstractions": "1.0.0", - "Microsoft.AspNetCore.Server.Kestrel": "1.0.1", - "Microsoft.AspNetCore.Server.Kestrel.Https": "1.0.1", + "Microsoft.AspNetCore.Server.Kestrel": "1.0.2", + "Microsoft.AspNetCore.Server.Kestrel.Https": "1.0.2", "Microsoft.AspNetCore.Testing": "1.0.0-rtm-21431", "Microsoft.Extensions.Logging.Console": "1.0.0", "Newtonsoft.Json": "9.0.1", diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/project.json b/test/Microsoft.AspNetCore.Server.KestrelTests/project.json index 125f43cbc6..0509e08481 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/project.json +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/project.json @@ -2,8 +2,8 @@ "version": "1.0.0-*", "dependencies": { "dotnet-test-xunit": "1.0.0-rc3-000000-01", - "Microsoft.AspNetCore.Server.Kestrel": "1.0.1", - "Microsoft.AspNetCore.Server.Kestrel.Https": "1.0.1", + "Microsoft.AspNetCore.Server.Kestrel": "1.0.2", + "Microsoft.AspNetCore.Server.Kestrel.Https": "1.0.2", "Microsoft.AspNetCore.Testing": "1.0.0-rtm-21431", "xunit": "2.1.0" }, From e57abc7762e149f467ab47c2bf43cbfa46db26b3 Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Wed, 2 Nov 2016 15:34:49 -0700 Subject: [PATCH 0934/1662] Update .travis.yml. --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index a3b3853ed7..150cf03a06 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,6 +18,6 @@ branches: - dev - /^(.*\/)?ci-.*$/ before_install: - - if test "$TRAVIS_OS_NAME" == "osx"; then brew update; brew install openssl; brew link --force openssl; fi + - if test "$TRAVIS_OS_NAME" == "osx"; then brew update; brew install openssl; ln -s /usr/local/opt/openssl/lib/libcrypto.1.0.0.dylib /usr/local/lib/; ln -s /usr/local/opt/openssl/lib/libssl.1.0.0.dylib /usr/local/lib/; fi script: - ./build.sh --quiet verify From 0dcfa2a3fd0d1df070d40a32019ebe8cbc0fff9f Mon Sep 17 00:00:00 2001 From: Pranav K Date: Wed, 2 Nov 2016 16:41:53 -0700 Subject: [PATCH 0935/1662] Updating to Libuv 1.9.1 --- src/Microsoft.AspNetCore.Server.Kestrel/project.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/project.json b/src/Microsoft.AspNetCore.Server.Kestrel/project.json index d523f7e261..4db40355f9 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/project.json +++ b/src/Microsoft.AspNetCore.Server.Kestrel/project.json @@ -12,7 +12,7 @@ ] }, "dependencies": { - "Libuv": "1.9.0-*", + "Libuv": "1.9.1", "Microsoft.AspNetCore.Hosting": "1.1.0-*", "Microsoft.Extensions.Logging.Abstractions": "1.1.0-*", "Microsoft.Extensions.TaskCache.Sources": { From 25d647c40086a1c94495e9ed4ce919e50b510fa7 Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Thu, 3 Nov 2016 11:42:39 -0700 Subject: [PATCH 0936/1662] Update Microsoft.AspNetCore.Hosting dependency to 1.0.1. --- src/Microsoft.AspNetCore.Server.Kestrel/project.json | 2 +- .../project.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/project.json b/src/Microsoft.AspNetCore.Server.Kestrel/project.json index a8cc228482..0c2bc1ebc9 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/project.json +++ b/src/Microsoft.AspNetCore.Server.Kestrel/project.json @@ -17,7 +17,7 @@ "System.Runtime.InteropServices.RuntimeInformation": "4.0.0", "System.Threading.Tasks.Extensions": "4.0.0", "Libuv": "1.9.0", - "Microsoft.AspNetCore.Hosting": "1.0.0", + "Microsoft.AspNetCore.Hosting": "1.0.1", "Microsoft.Extensions.Logging.Abstractions": "1.0.0" }, "frameworks": { diff --git a/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/project.json b/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/project.json index d9e3e04305..0ef1ca51fe 100644 --- a/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/project.json +++ b/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/project.json @@ -5,7 +5,7 @@ }, "dependencies": { "Microsoft.AspNetCore.Http.Features": "1.0.0", - "Microsoft.AspNetCore.Hosting": "1.0.0" + "Microsoft.AspNetCore.Hosting": "1.0.1" }, "frameworks": { "netcoreapp1.0": { From a4398aa8b39756dcb66a824d4521058301600720 Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Thu, 3 Nov 2016 15:34:55 -0700 Subject: [PATCH 0937/1662] Add regression tests for 'Connection: keep-alive, upgrade' request header (#1171). --- .../RequestTests.cs | 42 +++++++++++++++++++ .../MessageBodyTests.cs | 21 ++++++++++ 2 files changed, 63 insertions(+) diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs index a01b84f7b8..2c3aabf5e5 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs @@ -12,6 +12,7 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Testing.xunit; using Newtonsoft.Json; using Newtonsoft.Json.Linq; @@ -184,6 +185,47 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } } + [Fact] + public void CanUpgradeRequestWithConnectionKeepAliveUpgradeHeader() + { + var dataRead = false; + var builder = new WebHostBuilder() + .UseKestrel() + .UseUrls($"http://127.0.0.1:0") + .Configure(app => + { + app.Run(async context => + { + var stream = await context.Features.Get().UpgradeAsync(); + var data = new byte[3]; + var bytesRead = 0; + + while (bytesRead < 3) + { + bytesRead += await stream.ReadAsync(data, bytesRead, data.Length - bytesRead); + } + + dataRead = Encoding.ASCII.GetString(data, 0, 3) == "abc"; + }); + }); + + using (var host = builder.Build()) + { + host.Start(); + + using (var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)) + { + socket.Connect(new IPEndPoint(IPAddress.Loopback, host.GetPort())); + socket.Send(Encoding.ASCII.GetBytes("GET / HTTP/1.1\r\nConnection: keep-alive, upgrade\r\n\r\n")); + socket.Send(Encoding.ASCII.GetBytes("abc")); + + while (socket.Receive(new byte[1024]) > 0) ; + } + } + + Assert.True(dataRead); + } + private async Task TestRemoteIPAddress(string registerAddress, string requestAddress, string expectAddress) { var builder = new WebHostBuilder() diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/MessageBodyTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/MessageBodyTests.cs index f8dba124ef..96a1239ee3 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/MessageBodyTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/MessageBodyTests.cs @@ -88,6 +88,27 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } } + [Theory] + [InlineData("keep-alive, upgrade")] + [InlineData("Keep-Alive, Upgrade")] + [InlineData("upgrade, keep-alive")] + [InlineData("Upgrade, Keep-Alive")] + public void ConnectionUpgradeKeepAlive(string headerConnection) + { + using (var input = new TestInput()) + { + var body = MessageBody.For("HTTP/1.1", new FrameRequestHeaders { HeaderConnection = headerConnection }, input.FrameContext); + var stream = new FrameRequestStream(); + stream.StartAcceptingReads(body); + + input.Add("Hello", true); + + var buffer = new byte[1024]; + Assert.Equal(5, stream.Read(buffer, 0, 1024)); + AssertASCII("Hello", new ArraySegment(buffer, 0, 5)); + } + } + private void AssertASCII(string expected, ArraySegment actual) { var encoding = Encoding.ASCII; From b3aca0413c20226694502deb8649abf4e909ce0f Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Fri, 4 Nov 2016 15:09:51 -0700 Subject: [PATCH 0938/1662] Avoid zero-length writes to flush connection filter stream - This works around a zero-length write bug in SslStream. - We already assume connection filter streams auto flush. #1195 --- .../Filter/Internal/StreamSocketOutput.cs | 16 +++++++++++----- .../Internal/Http/Frame.cs | 7 +++---- .../Internal/Http/ISocketOutput.cs | 2 ++ .../Internal/Http/SocketOutput.cs | 11 +++++++++++ .../TestHelpers/MockSocketOuptut.cs | 9 +++++++++ 5 files changed, 36 insertions(+), 9 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Filter/Internal/StreamSocketOutput.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Filter/Internal/StreamSocketOutput.cs index 52397633fc..bce699f693 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Filter/Internal/StreamSocketOutput.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Filter/Internal/StreamSocketOutput.cs @@ -8,6 +8,7 @@ using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; +using Microsoft.Extensions.Internal; namespace Microsoft.AspNetCore.Server.Kestrel.Filter.Internal { @@ -34,11 +35,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Filter.Internal public void Write(ArraySegment buffer, bool chunk) { - if (buffer.Count == 0 ) - { - return; - } - if (chunk && buffer.Array != null) { var beginChunkBytes = ChunkWriter.BeginChunkBytes(buffer.Count); @@ -117,5 +113,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Filter.Internal end.Block.Pool.Return(end.Block); } + + // Flush no-ops. We rely on connection filter streams to auto-flush. + public void Flush() + { + } + + public Task FlushAsync(CancellationToken cancellationToken) + { + return TaskCache.CompletedTask; + } } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs index be3f0f083b..c4a0c50d85 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs @@ -26,7 +26,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { private static readonly ArraySegment _endChunkedResponseBytes = CreateAsciiByteArraySegment("0\r\n\r\n"); private static readonly ArraySegment _continueBytes = CreateAsciiByteArraySegment("HTTP/1.1 100 Continue\r\n\r\n"); - private static readonly ArraySegment _emptyData = new ArraySegment(new byte[0]); private static readonly byte[] _bytesConnectionClose = Encoding.ASCII.GetBytes("\r\nConnection: close"); private static readonly byte[] _bytesConnectionKeepAlive = Encoding.ASCII.GetBytes("\r\nConnection: keep-alive"); @@ -506,13 +505,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http public void Flush() { ProduceStartAndFireOnStarting().GetAwaiter().GetResult(); - SocketOutput.Write(_emptyData); + SocketOutput.Flush(); } public async Task FlushAsync(CancellationToken cancellationToken) { await ProduceStartAndFireOnStarting(); - await SocketOutput.WriteAsync(_emptyData, cancellationToken: cancellationToken); + await SocketOutput.FlushAsync(cancellationToken); } public void Write(ArraySegment data) @@ -768,7 +767,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http ProduceStart(appCompleted: true); // Force flush - await SocketOutput.WriteAsync(_emptyData); + await SocketOutput.FlushAsync(); await WriteSuffix(); } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ISocketOutput.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ISocketOutput.cs index 29b57b8c90..e5c4e4102e 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ISocketOutput.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ISocketOutput.cs @@ -15,6 +15,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { void Write(ArraySegment buffer, bool chunk = false); Task WriteAsync(ArraySegment buffer, bool chunk = false, CancellationToken cancellationToken = default(CancellationToken)); + void Flush(); + Task FlushAsync(CancellationToken cancellationToken = default(CancellationToken)); /// /// Returns an iterator pointing to the tail of the response buffer. Response data can be appended diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/SocketOutput.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/SocketOutput.cs index a926230b83..86b274dd12 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/SocketOutput.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/SocketOutput.cs @@ -21,6 +21,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http // Well behaved WriteAsync users should await returned task, so there is no need to allocate more per connection by default private const int _initialTaskQueues = 1; + private static readonly ArraySegment _emptyData = new ArraySegment(new byte[0]); private static readonly WaitCallback _returnBlocks = (state) => ReturnBlocks((MemoryPoolBlock)state); private static readonly Action _connectionCancellation = (state) => ((SocketOutput)state).CancellationTriggered(); @@ -534,6 +535,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http return WriteAsync(buffer, cancellationToken, chunk); } + void ISocketOutput.Flush() + { + WriteAsync(_emptyData, default(CancellationToken), isSync: true).GetAwaiter().GetResult(); + } + + Task ISocketOutput.FlushAsync(CancellationToken cancellationToken) + { + return WriteAsync(_emptyData, cancellationToken); + } + private static void BytesBetween(MemoryPoolIterator start, MemoryPoolIterator end, out int bytes, out int buffers) { if (start.Block == end.Block) diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockSocketOuptut.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockSocketOuptut.cs index bdddcd1504..b5f65900b4 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockSocketOuptut.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockSocketOuptut.cs @@ -29,5 +29,14 @@ namespace Microsoft.AspNetCore.Server.KestrelTests.TestHelpers { return TaskCache.CompletedTask; } + + public void Flush() + { + } + + public Task FlushAsync(CancellationToken cancellationToken = new CancellationToken()) + { + return TaskCache.CompletedTask; + } } } From 6cbbb73ca77a12402fcc043ef8239e88c2c75bb2 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Tue, 1 Nov 2016 16:24:15 -0700 Subject: [PATCH 0939/1662] Protect against NullReferenceException in Frame.StopStreams() --- .../Internal/Http/FrameOfT.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameOfT.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameOfT.cs index 6925c13bea..2d0eecad6e 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameOfT.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameOfT.cs @@ -159,11 +159,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http finally { _application.DisposeContext(context, _applicationException); + + // StopStreams should be called before the end of the "if (!_requestProcessingStopping)" block + // to ensure InitializeStreams has been called. + StopStreams(); } } - StopStreams(); - if (!_keepAlive) { // End the connection for non keep alive as data incoming may have been thrown off From 85919008499eaaeac532abe995b291604138abba Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Wed, 2 Nov 2016 11:15:37 -0700 Subject: [PATCH 0940/1662] Fix more test failures caused by connection resets - Avoid sending data that won't be processed. --- .../ResponseTests.cs | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs index d25b55e06f..5b4b5b73fe 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs @@ -340,15 +340,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [Fact] public async Task SingleErrorResponseSentWhenAppSwallowsBadRequestException() { + BadHttpRequestException readException = null; + using (var server = new TestServer(async httpContext => { - try - { - await httpContext.Request.Body.ReadAsync(new byte[1], 0, 1); - } - catch (BadHttpRequestException) - { - } + readException = await Assert.ThrowsAsync( + async () => await httpContext.Request.Body.ReadAsync(new byte[1], 0, 1)); }, new TestServiceContext())) { using (var connection = server.CreateConnection()) @@ -357,8 +354,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests "POST / HTTP/1.1", "Transfer-Encoding: chunked", "", - "g", - ""); + "gg"); await connection.ReceiveForcedEnd( "HTTP/1.1 400 Bad Request", "Connection: close", @@ -368,6 +364,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests ""); } } + + Assert.NotNull(readException); } [Fact] From ed98894c93f561346f84676f5ecb14854a6c7ffc Mon Sep 17 00:00:00 2001 From: jacalvar Date: Fri, 4 Nov 2016 17:11:23 -0700 Subject: [PATCH 0941/1662] Created public API baselines --- .../baseline.net45.json | 292 + .../baseline.netcore.json | 292 + .../baseline.net45.json | 12700 ++++++++++++++++ .../baseline.netcore.json | 12700 ++++++++++++++++ 4 files changed, 25984 insertions(+) create mode 100644 src/Microsoft.AspNetCore.Server.Kestrel.Https/baseline.net45.json create mode 100644 src/Microsoft.AspNetCore.Server.Kestrel.Https/baseline.netcore.json create mode 100644 src/Microsoft.AspNetCore.Server.Kestrel/baseline.net45.json create mode 100644 src/Microsoft.AspNetCore.Server.Kestrel/baseline.netcore.json diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Https/baseline.net45.json b/src/Microsoft.AspNetCore.Server.Kestrel.Https/baseline.net45.json new file mode 100644 index 0000000000..f6e1715d55 --- /dev/null +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Https/baseline.net45.json @@ -0,0 +1,292 @@ +{ + "AssemblyIdentity": "Microsoft.AspNetCore.Server.Kestrel.Https, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60", + "Types": [ + { + "Name": "Microsoft.AspNetCore.Hosting.KestrelServerOptionsHttpsExtensions", + "Visibility": "Public", + "Kind": "Class", + "Abstract": true, + "Static": true, + "Sealed": true, + "ImplementedInterfaces": [], + "Members": [ + { + "Kind": "Method", + "Name": "UseHttps", + "Parameters": [ + { + "Name": "options", + "Type": "Microsoft.AspNetCore.Server.Kestrel.KestrelServerOptions" + }, + { + "Name": "fileName", + "Type": "System.String" + } + ], + "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.KestrelServerOptions", + "Static": true, + "Extension": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "UseHttps", + "Parameters": [ + { + "Name": "options", + "Type": "Microsoft.AspNetCore.Server.Kestrel.KestrelServerOptions" + }, + { + "Name": "fileName", + "Type": "System.String" + }, + { + "Name": "password", + "Type": "System.String" + } + ], + "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.KestrelServerOptions", + "Static": true, + "Extension": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "UseHttps", + "Parameters": [ + { + "Name": "options", + "Type": "Microsoft.AspNetCore.Server.Kestrel.KestrelServerOptions" + }, + { + "Name": "serverCertificate", + "Type": "System.Security.Cryptography.X509Certificates.X509Certificate2" + } + ], + "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.KestrelServerOptions", + "Static": true, + "Extension": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "UseHttps", + "Parameters": [ + { + "Name": "options", + "Type": "Microsoft.AspNetCore.Server.Kestrel.KestrelServerOptions" + }, + { + "Name": "httpsOptions", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Https.HttpsConnectionFilterOptions" + } + ], + "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.KestrelServerOptions", + "Static": true, + "Extension": true, + "Visibility": "Public", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Https.ClientCertificateMode", + "Visibility": "Public", + "Kind": "Enumeration", + "Sealed": true, + "ImplementedInterfaces": [], + "Members": [ + { + "Kind": "Field", + "Name": "NoCertificate", + "Parameters": [], + "GenericParameter": [], + "Literal": "0" + }, + { + "Kind": "Field", + "Name": "AllowCertificate", + "Parameters": [], + "GenericParameter": [], + "Literal": "1" + }, + { + "Kind": "Field", + "Name": "RequireCertificate", + "Parameters": [], + "GenericParameter": [], + "Literal": "2" + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Https.HttpsConnectionFilter", + "Visibility": "Public", + "Kind": "Class", + "ImplementedInterfaces": [ + "Microsoft.AspNetCore.Server.Kestrel.Filter.IConnectionFilter" + ], + "Members": [ + { + "Kind": "Method", + "Name": "OnConnectionAsync", + "Parameters": [ + { + "Name": "context", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Filter.ConnectionFilterContext" + } + ], + "ReturnType": "System.Threading.Tasks.Task", + "Sealed": true, + "Virtual": true, + "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Filter.IConnectionFilter", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [ + { + "Name": "options", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Https.HttpsConnectionFilterOptions" + }, + { + "Name": "previous", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Filter.IConnectionFilter" + } + ], + "Visibility": "Public", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Https.HttpsConnectionFilterOptions", + "Visibility": "Public", + "Kind": "Class", + "ImplementedInterfaces": [], + "Members": [ + { + "Kind": "Method", + "Name": "get_ServerCertificate", + "Parameters": [], + "ReturnType": "System.Security.Cryptography.X509Certificates.X509Certificate2", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_ServerCertificate", + "Parameters": [ + { + "Name": "value", + "Type": "System.Security.Cryptography.X509Certificates.X509Certificate2" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_ClientCertificateMode", + "Parameters": [], + "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Https.ClientCertificateMode", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_ClientCertificateMode", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Https.ClientCertificateMode" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_ClientCertificateValidation", + "Parameters": [], + "ReturnType": "System.Func", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_ClientCertificateValidation", + "Parameters": [ + { + "Name": "value", + "Type": "System.Func" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_SslProtocols", + "Parameters": [], + "ReturnType": "System.Security.Authentication.SslProtocols", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_SslProtocols", + "Parameters": [ + { + "Name": "value", + "Type": "System.Security.Authentication.SslProtocols" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_CheckCertificateRevocation", + "Parameters": [], + "ReturnType": "System.Boolean", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_CheckCertificateRevocation", + "Parameters": [ + { + "Name": "value", + "Type": "System.Boolean" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [], + "Visibility": "Public", + "GenericParameter": [] + } + ], + "GenericParameters": [] + } + ] +} \ No newline at end of file diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Https/baseline.netcore.json b/src/Microsoft.AspNetCore.Server.Kestrel.Https/baseline.netcore.json new file mode 100644 index 0000000000..f6e1715d55 --- /dev/null +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Https/baseline.netcore.json @@ -0,0 +1,292 @@ +{ + "AssemblyIdentity": "Microsoft.AspNetCore.Server.Kestrel.Https, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60", + "Types": [ + { + "Name": "Microsoft.AspNetCore.Hosting.KestrelServerOptionsHttpsExtensions", + "Visibility": "Public", + "Kind": "Class", + "Abstract": true, + "Static": true, + "Sealed": true, + "ImplementedInterfaces": [], + "Members": [ + { + "Kind": "Method", + "Name": "UseHttps", + "Parameters": [ + { + "Name": "options", + "Type": "Microsoft.AspNetCore.Server.Kestrel.KestrelServerOptions" + }, + { + "Name": "fileName", + "Type": "System.String" + } + ], + "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.KestrelServerOptions", + "Static": true, + "Extension": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "UseHttps", + "Parameters": [ + { + "Name": "options", + "Type": "Microsoft.AspNetCore.Server.Kestrel.KestrelServerOptions" + }, + { + "Name": "fileName", + "Type": "System.String" + }, + { + "Name": "password", + "Type": "System.String" + } + ], + "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.KestrelServerOptions", + "Static": true, + "Extension": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "UseHttps", + "Parameters": [ + { + "Name": "options", + "Type": "Microsoft.AspNetCore.Server.Kestrel.KestrelServerOptions" + }, + { + "Name": "serverCertificate", + "Type": "System.Security.Cryptography.X509Certificates.X509Certificate2" + } + ], + "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.KestrelServerOptions", + "Static": true, + "Extension": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "UseHttps", + "Parameters": [ + { + "Name": "options", + "Type": "Microsoft.AspNetCore.Server.Kestrel.KestrelServerOptions" + }, + { + "Name": "httpsOptions", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Https.HttpsConnectionFilterOptions" + } + ], + "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.KestrelServerOptions", + "Static": true, + "Extension": true, + "Visibility": "Public", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Https.ClientCertificateMode", + "Visibility": "Public", + "Kind": "Enumeration", + "Sealed": true, + "ImplementedInterfaces": [], + "Members": [ + { + "Kind": "Field", + "Name": "NoCertificate", + "Parameters": [], + "GenericParameter": [], + "Literal": "0" + }, + { + "Kind": "Field", + "Name": "AllowCertificate", + "Parameters": [], + "GenericParameter": [], + "Literal": "1" + }, + { + "Kind": "Field", + "Name": "RequireCertificate", + "Parameters": [], + "GenericParameter": [], + "Literal": "2" + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Https.HttpsConnectionFilter", + "Visibility": "Public", + "Kind": "Class", + "ImplementedInterfaces": [ + "Microsoft.AspNetCore.Server.Kestrel.Filter.IConnectionFilter" + ], + "Members": [ + { + "Kind": "Method", + "Name": "OnConnectionAsync", + "Parameters": [ + { + "Name": "context", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Filter.ConnectionFilterContext" + } + ], + "ReturnType": "System.Threading.Tasks.Task", + "Sealed": true, + "Virtual": true, + "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Filter.IConnectionFilter", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [ + { + "Name": "options", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Https.HttpsConnectionFilterOptions" + }, + { + "Name": "previous", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Filter.IConnectionFilter" + } + ], + "Visibility": "Public", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Https.HttpsConnectionFilterOptions", + "Visibility": "Public", + "Kind": "Class", + "ImplementedInterfaces": [], + "Members": [ + { + "Kind": "Method", + "Name": "get_ServerCertificate", + "Parameters": [], + "ReturnType": "System.Security.Cryptography.X509Certificates.X509Certificate2", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_ServerCertificate", + "Parameters": [ + { + "Name": "value", + "Type": "System.Security.Cryptography.X509Certificates.X509Certificate2" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_ClientCertificateMode", + "Parameters": [], + "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Https.ClientCertificateMode", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_ClientCertificateMode", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Https.ClientCertificateMode" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_ClientCertificateValidation", + "Parameters": [], + "ReturnType": "System.Func", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_ClientCertificateValidation", + "Parameters": [ + { + "Name": "value", + "Type": "System.Func" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_SslProtocols", + "Parameters": [], + "ReturnType": "System.Security.Authentication.SslProtocols", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_SslProtocols", + "Parameters": [ + { + "Name": "value", + "Type": "System.Security.Authentication.SslProtocols" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_CheckCertificateRevocation", + "Parameters": [], + "ReturnType": "System.Boolean", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_CheckCertificateRevocation", + "Parameters": [ + { + "Name": "value", + "Type": "System.Boolean" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [], + "Visibility": "Public", + "GenericParameter": [] + } + ], + "GenericParameters": [] + } + ] +} \ No newline at end of file diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/baseline.net45.json b/src/Microsoft.AspNetCore.Server.Kestrel/baseline.net45.json new file mode 100644 index 0000000000..f8ee9ee327 --- /dev/null +++ b/src/Microsoft.AspNetCore.Server.Kestrel/baseline.net45.json @@ -0,0 +1,12700 @@ +{ + "AssemblyIdentity": "Microsoft.AspNetCore.Server.Kestrel, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60", + "Types": [ + { + "Name": "Microsoft.AspNetCore.Hosting.WebHostBuilderKestrelExtensions", + "Visibility": "Public", + "Kind": "Class", + "Abstract": true, + "Static": true, + "Sealed": true, + "ImplementedInterfaces": [], + "Members": [ + { + "Kind": "Method", + "Name": "UseKestrel", + "Parameters": [ + { + "Name": "hostBuilder", + "Type": "Microsoft.AspNetCore.Hosting.IWebHostBuilder" + } + ], + "ReturnType": "Microsoft.AspNetCore.Hosting.IWebHostBuilder", + "Static": true, + "Extension": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "UseKestrel", + "Parameters": [ + { + "Name": "hostBuilder", + "Type": "Microsoft.AspNetCore.Hosting.IWebHostBuilder" + }, + { + "Name": "options", + "Type": "System.Action" + } + ], + "ReturnType": "Microsoft.AspNetCore.Hosting.IWebHostBuilder", + "Static": true, + "Extension": true, + "Visibility": "Public", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Hosting.KestrelServerOptionsConnectionLoggingExtensions", + "Visibility": "Public", + "Kind": "Class", + "Abstract": true, + "Static": true, + "Sealed": true, + "ImplementedInterfaces": [], + "Members": [ + { + "Kind": "Method", + "Name": "UseConnectionLogging", + "Parameters": [ + { + "Name": "options", + "Type": "Microsoft.AspNetCore.Server.Kestrel.KestrelServerOptions" + } + ], + "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.KestrelServerOptions", + "Static": true, + "Extension": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "UseConnectionLogging", + "Parameters": [ + { + "Name": "options", + "Type": "Microsoft.AspNetCore.Server.Kestrel.KestrelServerOptions" + }, + { + "Name": "loggerName", + "Type": "System.String" + } + ], + "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.KestrelServerOptions", + "Static": true, + "Extension": true, + "Visibility": "Public", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.BadHttpRequestException", + "Visibility": "Public", + "Kind": "Class", + "Sealed": true, + "BaseType": "System.IO.IOException", + "ImplementedInterfaces": [], + "Members": [], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.KestrelServer", + "Visibility": "Public", + "Kind": "Class", + "ImplementedInterfaces": [ + "Microsoft.AspNetCore.Hosting.Server.IServer" + ], + "Members": [ + { + "Kind": "Method", + "Name": "get_Features", + "Parameters": [], + "ReturnType": "Microsoft.AspNetCore.Http.Features.IFeatureCollection", + "Sealed": true, + "Virtual": true, + "ImplementedInterface": "Microsoft.AspNetCore.Hosting.Server.IServer", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_Options", + "Parameters": [], + "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.KestrelServerOptions", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "Start", + "Parameters": [ + { + "Name": "application", + "Type": "Microsoft.AspNetCore.Hosting.Server.IHttpApplication" + } + ], + "ReturnType": "System.Void", + "Sealed": true, + "Virtual": true, + "ImplementedInterface": "Microsoft.AspNetCore.Hosting.Server.IServer", + "Visibility": "Public", + "GenericParameter": [ + { + "ParameterName": "TContext", + "ParameterPosition": 0, + "BaseTypeOrInterfaces": [] + } + ] + }, + { + "Kind": "Method", + "Name": "Dispose", + "Parameters": [], + "ReturnType": "System.Void", + "Sealed": true, + "Virtual": true, + "ImplementedInterface": "System.IDisposable", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [ + { + "Name": "options", + "Type": "Microsoft.Extensions.Options.IOptions" + }, + { + "Name": "applicationLifetime", + "Type": "Microsoft.AspNetCore.Hosting.IApplicationLifetime" + }, + { + "Name": "loggerFactory", + "Type": "Microsoft.Extensions.Logging.ILoggerFactory" + } + ], + "Visibility": "Public", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.KestrelServerOptions", + "Visibility": "Public", + "Kind": "Class", + "ImplementedInterfaces": [], + "Members": [ + { + "Kind": "Method", + "Name": "get_AddServerHeader", + "Parameters": [], + "ReturnType": "System.Boolean", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_AddServerHeader", + "Parameters": [ + { + "Name": "value", + "Type": "System.Boolean" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_ApplicationServices", + "Parameters": [], + "ReturnType": "System.IServiceProvider", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_ApplicationServices", + "Parameters": [ + { + "Name": "value", + "Type": "System.IServiceProvider" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_ConnectionFilter", + "Parameters": [], + "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Filter.IConnectionFilter", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_ConnectionFilter", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Filter.IConnectionFilter" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_MaxRequestBufferSize", + "Parameters": [], + "ReturnType": "System.Nullable", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_MaxRequestBufferSize", + "Parameters": [ + { + "Name": "value", + "Type": "System.Nullable" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_NoDelay", + "Parameters": [], + "ReturnType": "System.Boolean", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_NoDelay", + "Parameters": [ + { + "Name": "value", + "Type": "System.Boolean" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_ShutdownTimeout", + "Parameters": [], + "ReturnType": "System.TimeSpan", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_ShutdownTimeout", + "Parameters": [ + { + "Name": "value", + "Type": "System.TimeSpan" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_ThreadCount", + "Parameters": [], + "ReturnType": "System.Int32", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_ThreadCount", + "Parameters": [ + { + "Name": "value", + "Type": "System.Int32" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [], + "Visibility": "Public", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.ServerAddress", + "Visibility": "Public", + "Kind": "Class", + "ImplementedInterfaces": [], + "Members": [ + { + "Kind": "Method", + "Name": "get_Host", + "Parameters": [], + "ReturnType": "System.String", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_PathBase", + "Parameters": [], + "ReturnType": "System.String", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_Port", + "Parameters": [], + "ReturnType": "System.Int32", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_Scheme", + "Parameters": [], + "ReturnType": "System.String", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_IsUnixPipe", + "Parameters": [], + "ReturnType": "System.Boolean", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_UnixPipePath", + "Parameters": [], + "ReturnType": "System.String", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "ToString", + "Parameters": [], + "ReturnType": "System.String", + "Virtual": true, + "Override": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "GetHashCode", + "Parameters": [], + "ReturnType": "System.Int32", + "Virtual": true, + "Override": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "Equals", + "Parameters": [ + { + "Name": "obj", + "Type": "System.Object" + } + ], + "ReturnType": "System.Boolean", + "Virtual": true, + "Override": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "FromUrl", + "Parameters": [ + { + "Name": "url", + "Type": "System.String" + } + ], + "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.ServerAddress", + "Static": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [], + "Visibility": "Public", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.KestrelEngine", + "Visibility": "Public", + "Kind": "Class", + "BaseType": "Microsoft.AspNetCore.Server.Kestrel.Internal.ServiceContext", + "ImplementedInterfaces": [ + "System.IDisposable" + ], + "Members": [ + { + "Kind": "Method", + "Name": "get_Libuv", + "Parameters": [], + "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_Threads", + "Parameters": [], + "ReturnType": "System.Collections.Generic.List", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "Start", + "Parameters": [ + { + "Name": "count", + "Type": "System.Int32" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "Dispose", + "Parameters": [], + "ReturnType": "System.Void", + "Sealed": true, + "Virtual": true, + "ImplementedInterface": "System.IDisposable", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "CreateServer", + "Parameters": [ + { + "Name": "address", + "Type": "Microsoft.AspNetCore.Server.Kestrel.ServerAddress" + } + ], + "ReturnType": "System.IDisposable", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [ + { + "Name": "context", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.ServiceContext" + } + ], + "Visibility": "Public", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.KestrelServerOptionsSetup", + "Visibility": "Public", + "Kind": "Class", + "ImplementedInterfaces": [ + "Microsoft.Extensions.Options.IConfigureOptions" + ], + "Members": [ + { + "Kind": "Method", + "Name": "Configure", + "Parameters": [ + { + "Name": "options", + "Type": "Microsoft.AspNetCore.Server.Kestrel.KestrelServerOptions" + } + ], + "ReturnType": "System.Void", + "Sealed": true, + "Virtual": true, + "ImplementedInterface": "Microsoft.Extensions.Options.IConfigureOptions", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [ + { + "Name": "services", + "Type": "System.IServiceProvider" + } + ], + "Visibility": "Public", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.ServiceContext", + "Visibility": "Public", + "Kind": "Class", + "ImplementedInterfaces": [], + "Members": [ + { + "Kind": "Method", + "Name": "get_AppLifetime", + "Parameters": [], + "ReturnType": "Microsoft.AspNetCore.Hosting.IApplicationLifetime", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_AppLifetime", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.AspNetCore.Hosting.IApplicationLifetime" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_Log", + "Parameters": [], + "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IKestrelTrace", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_Log", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IKestrelTrace" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_ThreadPool", + "Parameters": [], + "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IThreadPool", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_ThreadPool", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IThreadPool" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_FrameFactory", + "Parameters": [], + "ReturnType": "System.Func", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_FrameFactory", + "Parameters": [ + { + "Name": "value", + "Type": "System.Func" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_DateHeaderValueManager", + "Parameters": [], + "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.DateHeaderValueManager", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_DateHeaderValueManager", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.DateHeaderValueManager" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_ServerOptions", + "Parameters": [], + "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.KestrelServerOptions", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_ServerOptions", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.AspNetCore.Server.Kestrel.KestrelServerOptions" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [], + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [ + { + "Name": "context", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.ServiceContext" + } + ], + "Visibility": "Public", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Disposable", + "Visibility": "Public", + "Kind": "Class", + "ImplementedInterfaces": [ + "System.IDisposable" + ], + "Members": [ + { + "Kind": "Method", + "Name": "Dispose", + "Parameters": [ + { + "Name": "disposing", + "Type": "System.Boolean" + } + ], + "ReturnType": "System.Void", + "Virtual": true, + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "Dispose", + "Parameters": [], + "ReturnType": "System.Void", + "Sealed": true, + "Virtual": true, + "ImplementedInterface": "System.IDisposable", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [ + { + "Name": "dispose", + "Type": "System.Action" + } + ], + "Visibility": "Public", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.KestrelThread", + "Visibility": "Public", + "Kind": "Class", + "ImplementedInterfaces": [], + "Members": [ + { + "Kind": "Method", + "Name": "get_Loop", + "Parameters": [], + "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvLoopHandle", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_FatalError", + "Parameters": [], + "ReturnType": "System.Runtime.ExceptionServices.ExceptionDispatchInfo", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_QueueCloseHandle", + "Parameters": [], + "ReturnType": "System.Action, System.IntPtr>", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "StartAsync", + "Parameters": [], + "ReturnType": "System.Threading.Tasks.Task", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "AllowStop", + "Parameters": [], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "Stop", + "Parameters": [ + { + "Name": "timeout", + "Type": "System.TimeSpan" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "Post", + "Parameters": [ + { + "Name": "callback", + "Type": "System.Action" + }, + { + "Name": "state", + "Type": "System.Object" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "PostAsync", + "Parameters": [ + { + "Name": "callback", + "Type": "System.Action" + }, + { + "Name": "state", + "Type": "System.Object" + } + ], + "ReturnType": "System.Threading.Tasks.Task", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "Walk", + "Parameters": [ + { + "Name": "callback", + "Type": "System.Action" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [ + { + "Name": "engine", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.KestrelEngine" + } + ], + "Visibility": "Public", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.KestrelTrace", + "Visibility": "Public", + "Kind": "Class", + "ImplementedInterfaces": [ + "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IKestrelTrace" + ], + "Members": [ + { + "Kind": "Method", + "Name": "ConnectionStart", + "Parameters": [ + { + "Name": "connectionId", + "Type": "System.String" + } + ], + "ReturnType": "System.Void", + "Virtual": true, + "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IKestrelTrace", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "ConnectionStop", + "Parameters": [ + { + "Name": "connectionId", + "Type": "System.String" + } + ], + "ReturnType": "System.Void", + "Virtual": true, + "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IKestrelTrace", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "ConnectionRead", + "Parameters": [ + { + "Name": "connectionId", + "Type": "System.String" + }, + { + "Name": "count", + "Type": "System.Int32" + } + ], + "ReturnType": "System.Void", + "Virtual": true, + "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IKestrelTrace", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "ConnectionPause", + "Parameters": [ + { + "Name": "connectionId", + "Type": "System.String" + } + ], + "ReturnType": "System.Void", + "Virtual": true, + "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IKestrelTrace", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "ConnectionResume", + "Parameters": [ + { + "Name": "connectionId", + "Type": "System.String" + } + ], + "ReturnType": "System.Void", + "Virtual": true, + "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IKestrelTrace", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "ConnectionReadFin", + "Parameters": [ + { + "Name": "connectionId", + "Type": "System.String" + } + ], + "ReturnType": "System.Void", + "Virtual": true, + "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IKestrelTrace", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "ConnectionWriteFin", + "Parameters": [ + { + "Name": "connectionId", + "Type": "System.String" + } + ], + "ReturnType": "System.Void", + "Virtual": true, + "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IKestrelTrace", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "ConnectionWroteFin", + "Parameters": [ + { + "Name": "connectionId", + "Type": "System.String" + }, + { + "Name": "status", + "Type": "System.Int32" + } + ], + "ReturnType": "System.Void", + "Virtual": true, + "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IKestrelTrace", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "ConnectionKeepAlive", + "Parameters": [ + { + "Name": "connectionId", + "Type": "System.String" + } + ], + "ReturnType": "System.Void", + "Virtual": true, + "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IKestrelTrace", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "ConnectionDisconnect", + "Parameters": [ + { + "Name": "connectionId", + "Type": "System.String" + } + ], + "ReturnType": "System.Void", + "Virtual": true, + "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IKestrelTrace", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "ConnectionWrite", + "Parameters": [ + { + "Name": "connectionId", + "Type": "System.String" + }, + { + "Name": "count", + "Type": "System.Int32" + } + ], + "ReturnType": "System.Void", + "Virtual": true, + "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IKestrelTrace", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "ConnectionWriteCallback", + "Parameters": [ + { + "Name": "connectionId", + "Type": "System.String" + }, + { + "Name": "status", + "Type": "System.Int32" + } + ], + "ReturnType": "System.Void", + "Virtual": true, + "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IKestrelTrace", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "ApplicationError", + "Parameters": [ + { + "Name": "connectionId", + "Type": "System.String" + }, + { + "Name": "ex", + "Type": "System.Exception" + } + ], + "ReturnType": "System.Void", + "Virtual": true, + "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IKestrelTrace", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "ConnectionError", + "Parameters": [ + { + "Name": "connectionId", + "Type": "System.String" + }, + { + "Name": "ex", + "Type": "System.Exception" + } + ], + "ReturnType": "System.Void", + "Virtual": true, + "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IKestrelTrace", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "ConnectionDisconnectedWrite", + "Parameters": [ + { + "Name": "connectionId", + "Type": "System.String" + }, + { + "Name": "count", + "Type": "System.Int32" + }, + { + "Name": "ex", + "Type": "System.Exception" + } + ], + "ReturnType": "System.Void", + "Virtual": true, + "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IKestrelTrace", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "NotAllConnectionsClosedGracefully", + "Parameters": [], + "ReturnType": "System.Void", + "Virtual": true, + "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IKestrelTrace", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "ConnectionBadRequest", + "Parameters": [ + { + "Name": "connectionId", + "Type": "System.String" + }, + { + "Name": "ex", + "Type": "Microsoft.AspNetCore.Server.Kestrel.BadHttpRequestException" + } + ], + "ReturnType": "System.Void", + "Sealed": true, + "Virtual": true, + "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IKestrelTrace", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "Log", + "Parameters": [ + { + "Name": "logLevel", + "Type": "Microsoft.Extensions.Logging.LogLevel" + }, + { + "Name": "eventId", + "Type": "Microsoft.Extensions.Logging.EventId" + }, + { + "Name": "state", + "Type": "T0" + }, + { + "Name": "exception", + "Type": "System.Exception" + }, + { + "Name": "formatter", + "Type": "System.Func" + } + ], + "ReturnType": "System.Void", + "Virtual": true, + "ImplementedInterface": "Microsoft.Extensions.Logging.ILogger", + "Visibility": "Public", + "GenericParameter": [ + { + "ParameterName": "TState", + "ParameterPosition": 0, + "BaseTypeOrInterfaces": [] + } + ] + }, + { + "Kind": "Method", + "Name": "IsEnabled", + "Parameters": [ + { + "Name": "logLevel", + "Type": "Microsoft.Extensions.Logging.LogLevel" + } + ], + "ReturnType": "System.Boolean", + "Virtual": true, + "ImplementedInterface": "Microsoft.Extensions.Logging.ILogger", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "BeginScope", + "Parameters": [ + { + "Name": "state", + "Type": "T0" + } + ], + "ReturnType": "System.IDisposable", + "Virtual": true, + "ImplementedInterface": "Microsoft.Extensions.Logging.ILogger", + "Visibility": "Public", + "GenericParameter": [ + { + "ParameterName": "TState", + "ParameterPosition": 0, + "BaseTypeOrInterfaces": [] + } + ] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [ + { + "Name": "logger", + "Type": "Microsoft.Extensions.Logging.ILogger" + } + ], + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Field", + "Name": "_logger", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Logging.ILogger", + "ReadOnly": true, + "Visibility": "Protected", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv", + "Visibility": "Public", + "Kind": "Class", + "ImplementedInterfaces": [], + "Members": [ + { + "Kind": "Method", + "Name": "Check", + "Parameters": [ + { + "Name": "statusCode", + "Type": "System.Int32" + } + ], + "ReturnType": "System.Int32", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "Check", + "Parameters": [ + { + "Name": "statusCode", + "Type": "System.Int32" + }, + { + "Name": "error", + "Type": "System.Exception", + "Direction": "Out" + } + ], + "ReturnType": "System.Int32", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "loop_init", + "Parameters": [ + { + "Name": "handle", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvLoopHandle" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "loop_close", + "Parameters": [ + { + "Name": "handle", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvLoopHandle" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "run", + "Parameters": [ + { + "Name": "handle", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvLoopHandle" + }, + { + "Name": "mode", + "Type": "System.Int32" + } + ], + "ReturnType": "System.Int32", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "stop", + "Parameters": [ + { + "Name": "handle", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvLoopHandle" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "ref", + "Parameters": [ + { + "Name": "handle", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvHandle" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "unref", + "Parameters": [ + { + "Name": "handle", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvHandle" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "uv_fileno", + "Parameters": [ + { + "Name": "handle", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvHandle" + }, + { + "Name": "socket", + "Type": "System.IntPtr", + "Direction": "Ref" + } + ], + "ReturnType": "System.Int32", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "close", + "Parameters": [ + { + "Name": "handle", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvHandle" + }, + { + "Name": "close_cb", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_close_cb" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "close", + "Parameters": [ + { + "Name": "handle", + "Type": "System.IntPtr" + }, + { + "Name": "close_cb", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_close_cb" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "async_init", + "Parameters": [ + { + "Name": "loop", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvLoopHandle" + }, + { + "Name": "handle", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvAsyncHandle" + }, + { + "Name": "cb", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_async_cb" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "async_send", + "Parameters": [ + { + "Name": "handle", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvAsyncHandle" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "unsafe_async_send", + "Parameters": [ + { + "Name": "handle", + "Type": "System.IntPtr" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "tcp_init", + "Parameters": [ + { + "Name": "loop", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvLoopHandle" + }, + { + "Name": "handle", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvTcpHandle" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "tcp_bind", + "Parameters": [ + { + "Name": "handle", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvTcpHandle" + }, + { + "Name": "addr", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.SockAddr", + "Direction": "Ref" + }, + { + "Name": "flags", + "Type": "System.Int32" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "tcp_open", + "Parameters": [ + { + "Name": "handle", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvTcpHandle" + }, + { + "Name": "hSocket", + "Type": "System.IntPtr" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "tcp_nodelay", + "Parameters": [ + { + "Name": "handle", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvTcpHandle" + }, + { + "Name": "enable", + "Type": "System.Boolean" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "pipe_init", + "Parameters": [ + { + "Name": "loop", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvLoopHandle" + }, + { + "Name": "handle", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvPipeHandle" + }, + { + "Name": "ipc", + "Type": "System.Boolean" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "pipe_bind", + "Parameters": [ + { + "Name": "handle", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvPipeHandle" + }, + { + "Name": "name", + "Type": "System.String" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "listen", + "Parameters": [ + { + "Name": "handle", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle" + }, + { + "Name": "backlog", + "Type": "System.Int32" + }, + { + "Name": "cb", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_connection_cb" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "accept", + "Parameters": [ + { + "Name": "server", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle" + }, + { + "Name": "client", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "pipe_connect", + "Parameters": [ + { + "Name": "req", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvConnectRequest" + }, + { + "Name": "handle", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvPipeHandle" + }, + { + "Name": "name", + "Type": "System.String" + }, + { + "Name": "cb", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_connect_cb" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "pipe_pending_count", + "Parameters": [ + { + "Name": "handle", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvPipeHandle" + } + ], + "ReturnType": "System.Int32", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "read_start", + "Parameters": [ + { + "Name": "handle", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle" + }, + { + "Name": "alloc_cb", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_alloc_cb" + }, + { + "Name": "read_cb", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_read_cb" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "read_stop", + "Parameters": [ + { + "Name": "handle", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "try_write", + "Parameters": [ + { + "Name": "handle", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle" + }, + { + "Name": "bufs", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_buf_t[]" + }, + { + "Name": "nbufs", + "Type": "System.Int32" + } + ], + "ReturnType": "System.Int32", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "write", + "Parameters": [ + { + "Name": "req", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvRequest" + }, + { + "Name": "handle", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle" + }, + { + "Name": "bufs", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_buf_t*" + }, + { + "Name": "nbufs", + "Type": "System.Int32" + }, + { + "Name": "cb", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_write_cb" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "write2", + "Parameters": [ + { + "Name": "req", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvRequest" + }, + { + "Name": "handle", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle" + }, + { + "Name": "bufs", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_buf_t*" + }, + { + "Name": "nbufs", + "Type": "System.Int32" + }, + { + "Name": "sendHandle", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle" + }, + { + "Name": "cb", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_write_cb" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "shutdown", + "Parameters": [ + { + "Name": "req", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvShutdownReq" + }, + { + "Name": "handle", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle" + }, + { + "Name": "cb", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_shutdown_cb" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "err_name", + "Parameters": [ + { + "Name": "err", + "Type": "System.Int32" + } + ], + "ReturnType": "System.String", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "strerror", + "Parameters": [ + { + "Name": "err", + "Type": "System.Int32" + } + ], + "ReturnType": "System.String", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "loop_size", + "Parameters": [], + "ReturnType": "System.Int32", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "handle_size", + "Parameters": [ + { + "Name": "handleType", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+HandleType" + } + ], + "ReturnType": "System.Int32", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "req_size", + "Parameters": [ + { + "Name": "reqType", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+RequestType" + } + ], + "ReturnType": "System.Int32", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "ip4_addr", + "Parameters": [ + { + "Name": "ip", + "Type": "System.String" + }, + { + "Name": "port", + "Type": "System.Int32" + }, + { + "Name": "addr", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.SockAddr", + "Direction": "Out" + }, + { + "Name": "error", + "Type": "System.Exception", + "Direction": "Out" + } + ], + "ReturnType": "System.Int32", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "ip6_addr", + "Parameters": [ + { + "Name": "ip", + "Type": "System.String" + }, + { + "Name": "port", + "Type": "System.Int32" + }, + { + "Name": "addr", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.SockAddr", + "Direction": "Out" + }, + { + "Name": "error", + "Type": "System.Exception", + "Direction": "Out" + } + ], + "ReturnType": "System.Int32", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "walk", + "Parameters": [ + { + "Name": "loop", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvLoopHandle" + }, + { + "Name": "walk_cb", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_walk_cb" + }, + { + "Name": "arg", + "Type": "System.IntPtr" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "tcp_getsockname", + "Parameters": [ + { + "Name": "handle", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvTcpHandle" + }, + { + "Name": "addr", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.SockAddr", + "Direction": "Out" + }, + { + "Name": "namelen", + "Type": "System.Int32", + "Direction": "Ref" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "tcp_getpeername", + "Parameters": [ + { + "Name": "handle", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvTcpHandle" + }, + { + "Name": "addr", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.SockAddr", + "Direction": "Out" + }, + { + "Name": "namelen", + "Type": "System.Int32", + "Direction": "Ref" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "buf_init", + "Parameters": [ + { + "Name": "memory", + "Type": "System.IntPtr" + }, + { + "Name": "len", + "Type": "System.Int32" + } + ], + "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_buf_t", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [], + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Field", + "Name": "IsWindows", + "Parameters": [], + "ReturnType": "System.Boolean", + "ReadOnly": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Field", + "Name": "_uv_loop_init", + "Parameters": [], + "ReturnType": "System.Func", + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Field", + "Name": "_uv_loop_close", + "Parameters": [], + "ReturnType": "System.Func", + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Field", + "Name": "_uv_run", + "Parameters": [], + "ReturnType": "System.Func", + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Field", + "Name": "_uv_stop", + "Parameters": [], + "ReturnType": "System.Action", + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Field", + "Name": "_uv_ref", + "Parameters": [], + "ReturnType": "System.Action", + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Field", + "Name": "_uv_unref", + "Parameters": [], + "ReturnType": "System.Action", + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Field", + "Name": "_uv_fileno", + "Parameters": [], + "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_fileno_func", + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Field", + "Name": "_uv_close", + "Parameters": [], + "ReturnType": "System.Action", + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Field", + "Name": "_uv_async_init", + "Parameters": [], + "ReturnType": "System.Func", + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Field", + "Name": "_uv_async_send", + "Parameters": [], + "ReturnType": "System.Func", + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Field", + "Name": "_uv_unsafe_async_send", + "Parameters": [], + "ReturnType": "System.Func", + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Field", + "Name": "_uv_tcp_init", + "Parameters": [], + "ReturnType": "System.Func", + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Field", + "Name": "_uv_tcp_bind", + "Parameters": [], + "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_tcp_bind_func", + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Field", + "Name": "_uv_tcp_open", + "Parameters": [], + "ReturnType": "System.Func", + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Field", + "Name": "_uv_tcp_nodelay", + "Parameters": [], + "ReturnType": "System.Func", + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Field", + "Name": "_uv_pipe_init", + "Parameters": [], + "ReturnType": "System.Func", + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Field", + "Name": "_uv_pipe_bind", + "Parameters": [], + "ReturnType": "System.Func", + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Field", + "Name": "_uv_listen", + "Parameters": [], + "ReturnType": "System.Func", + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Field", + "Name": "_uv_accept", + "Parameters": [], + "ReturnType": "System.Func", + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Field", + "Name": "_uv_pipe_connect", + "Parameters": [], + "ReturnType": "System.Action", + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Field", + "Name": "_uv_pipe_pending_count", + "Parameters": [], + "ReturnType": "System.Func", + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Field", + "Name": "_uv_read_start", + "Parameters": [], + "ReturnType": "System.Func", + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Field", + "Name": "_uv_read_stop", + "Parameters": [], + "ReturnType": "System.Func", + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Field", + "Name": "_uv_try_write", + "Parameters": [], + "ReturnType": "System.Func", + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Field", + "Name": "_uv_write", + "Parameters": [], + "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_write_func", + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Field", + "Name": "_uv_write2", + "Parameters": [], + "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_write2_func", + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Field", + "Name": "_uv_shutdown", + "Parameters": [], + "ReturnType": "System.Func", + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Field", + "Name": "_uv_err_name", + "Parameters": [], + "ReturnType": "System.Func", + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Field", + "Name": "_uv_strerror", + "Parameters": [], + "ReturnType": "System.Func", + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Field", + "Name": "_uv_loop_size", + "Parameters": [], + "ReturnType": "System.Func", + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Field", + "Name": "_uv_handle_size", + "Parameters": [], + "ReturnType": "System.Func", + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Field", + "Name": "_uv_req_size", + "Parameters": [], + "ReturnType": "System.Func", + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Field", + "Name": "_uv_ip4_addr", + "Parameters": [], + "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_ip4_addr_func", + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Field", + "Name": "_uv_ip6_addr", + "Parameters": [], + "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_ip6_addr_func", + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Field", + "Name": "_uv_walk", + "Parameters": [], + "ReturnType": "System.Func", + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Field", + "Name": "_uv_tcp_getsockname", + "Parameters": [], + "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_tcp_getsockname_func", + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Field", + "Name": "_uv_tcp_getpeername", + "Parameters": [], + "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_tcp_getpeername_func", + "Visibility": "Protected", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.PlatformApis", + "Visibility": "Public", + "Kind": "Class", + "Abstract": true, + "Static": true, + "Sealed": true, + "ImplementedInterfaces": [], + "Members": [ + { + "Kind": "Method", + "Name": "get_IsWindows", + "Parameters": [], + "ReturnType": "System.Boolean", + "Static": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_IsDarwin", + "Parameters": [], + "ReturnType": "System.Boolean", + "Static": true, + "Visibility": "Public", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.SockAddr", + "Visibility": "Public", + "Kind": "Struct", + "Sealed": true, + "ImplementedInterfaces": [], + "Members": [ + { + "Kind": "Method", + "Name": "GetIPEndPoint", + "Parameters": [], + "ReturnType": "System.Net.IPEndPoint", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [ + { + "Name": "ignored", + "Type": "System.Int64" + } + ], + "Visibility": "Public", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvAsyncHandle", + "Visibility": "Public", + "Kind": "Class", + "BaseType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvHandle", + "ImplementedInterfaces": [], + "Members": [ + { + "Kind": "Method", + "Name": "Init", + "Parameters": [ + { + "Name": "loop", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvLoopHandle" + }, + { + "Name": "callback", + "Type": "System.Action" + }, + { + "Name": "queueCloseHandle", + "Type": "System.Action, System.IntPtr>" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "Send", + "Parameters": [], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "ReleaseHandle", + "Parameters": [], + "ReturnType": "System.Boolean", + "Virtual": true, + "Override": true, + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [ + { + "Name": "logger", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IKestrelTrace" + } + ], + "Visibility": "Public", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvConnectRequest", + "Visibility": "Public", + "Kind": "Class", + "BaseType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvRequest", + "ImplementedInterfaces": [], + "Members": [ + { + "Kind": "Method", + "Name": "Init", + "Parameters": [ + { + "Name": "loop", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvLoopHandle" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "Connect", + "Parameters": [ + { + "Name": "pipe", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvPipeHandle" + }, + { + "Name": "name", + "Type": "System.String" + }, + { + "Name": "callback", + "Type": "System.Action" + }, + { + "Name": "state", + "Type": "System.Object" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [ + { + "Name": "logger", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IKestrelTrace" + } + ], + "Visibility": "Public", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvException", + "Visibility": "Public", + "Kind": "Class", + "BaseType": "System.Exception", + "ImplementedInterfaces": [], + "Members": [ + { + "Kind": "Method", + "Name": "get_StatusCode", + "Parameters": [], + "ReturnType": "System.Int32", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [ + { + "Name": "message", + "Type": "System.String" + }, + { + "Name": "statusCode", + "Type": "System.Int32" + } + ], + "Visibility": "Public", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvHandle", + "Visibility": "Public", + "Kind": "Class", + "Abstract": true, + "BaseType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvMemory", + "ImplementedInterfaces": [], + "Members": [ + { + "Kind": "Method", + "Name": "CreateHandle", + "Parameters": [ + { + "Name": "uv", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv" + }, + { + "Name": "threadId", + "Type": "System.Int32" + }, + { + "Name": "size", + "Type": "System.Int32" + }, + { + "Name": "queueCloseHandle", + "Type": "System.Action, System.IntPtr>" + } + ], + "ReturnType": "System.Void", + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "ReleaseHandle", + "Parameters": [], + "ReturnType": "System.Boolean", + "Virtual": true, + "Override": true, + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "Reference", + "Parameters": [], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "Unreference", + "Parameters": [], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [ + { + "Name": "logger", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IKestrelTrace" + } + ], + "Visibility": "Protected", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvLoopHandle", + "Visibility": "Public", + "Kind": "Class", + "BaseType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvMemory", + "ImplementedInterfaces": [], + "Members": [ + { + "Kind": "Method", + "Name": "Init", + "Parameters": [ + { + "Name": "uv", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "Run", + "Parameters": [ + { + "Name": "mode", + "Type": "System.Int32", + "DefaultValue": "0" + } + ], + "ReturnType": "System.Int32", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "Stop", + "Parameters": [], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "ReleaseHandle", + "Parameters": [], + "ReturnType": "System.Boolean", + "Virtual": true, + "Override": true, + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [ + { + "Name": "logger", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IKestrelTrace" + } + ], + "Visibility": "Public", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvMemory", + "Visibility": "Public", + "Kind": "Class", + "Abstract": true, + "BaseType": "System.Runtime.InteropServices.SafeHandle", + "ImplementedInterfaces": [], + "Members": [ + { + "Kind": "Method", + "Name": "get_Libuv", + "Parameters": [], + "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_IsInvalid", + "Parameters": [], + "ReturnType": "System.Boolean", + "Virtual": true, + "Override": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_ThreadId", + "Parameters": [], + "ReturnType": "System.Int32", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "CreateMemory", + "Parameters": [ + { + "Name": "uv", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv" + }, + { + "Name": "threadId", + "Type": "System.Int32" + }, + { + "Name": "size", + "Type": "System.Int32" + } + ], + "ReturnType": "System.Void", + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "DestroyMemory", + "Parameters": [ + { + "Name": "memory", + "Type": "System.IntPtr" + } + ], + "ReturnType": "System.Void", + "Static": true, + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "DestroyMemory", + "Parameters": [ + { + "Name": "memory", + "Type": "System.IntPtr" + }, + { + "Name": "gcHandlePtr", + "Type": "System.IntPtr" + } + ], + "ReturnType": "System.Void", + "Static": true, + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "Validate", + "Parameters": [ + { + "Name": "closed", + "Type": "System.Boolean", + "DefaultValue": "False" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "FromIntPtr", + "Parameters": [ + { + "Name": "handle", + "Type": "System.IntPtr" + } + ], + "ReturnType": "T0", + "Static": true, + "Visibility": "Public", + "GenericParameter": [ + { + "ParameterName": "THandle", + "ParameterPosition": 0, + "BaseTypeOrInterfaces": [] + } + ] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [ + { + "Name": "logger", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IKestrelTrace" + } + ], + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Field", + "Name": "_uv", + "Parameters": [], + "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv", + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Field", + "Name": "_threadId", + "Parameters": [], + "ReturnType": "System.Int32", + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Field", + "Name": "_log", + "Parameters": [], + "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IKestrelTrace", + "ReadOnly": true, + "Visibility": "Protected", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvPipeHandle", + "Visibility": "Public", + "Kind": "Class", + "BaseType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle", + "ImplementedInterfaces": [], + "Members": [ + { + "Kind": "Method", + "Name": "Init", + "Parameters": [ + { + "Name": "loop", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvLoopHandle" + }, + { + "Name": "queueCloseHandle", + "Type": "System.Action, System.IntPtr>" + }, + { + "Name": "ipc", + "Type": "System.Boolean", + "DefaultValue": "False" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "Bind", + "Parameters": [ + { + "Name": "name", + "Type": "System.String" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "PendingCount", + "Parameters": [], + "ReturnType": "System.Int32", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [ + { + "Name": "logger", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IKestrelTrace" + } + ], + "Visibility": "Public", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvRequest", + "Visibility": "Public", + "Kind": "Class", + "BaseType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvMemory", + "ImplementedInterfaces": [], + "Members": [ + { + "Kind": "Method", + "Name": "ReleaseHandle", + "Parameters": [], + "ReturnType": "System.Boolean", + "Virtual": true, + "Override": true, + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "Pin", + "Parameters": [], + "ReturnType": "System.Void", + "Virtual": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "Unpin", + "Parameters": [], + "ReturnType": "System.Void", + "Virtual": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [ + { + "Name": "logger", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IKestrelTrace" + } + ], + "Visibility": "Protected", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvShutdownReq", + "Visibility": "Public", + "Kind": "Class", + "BaseType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvRequest", + "ImplementedInterfaces": [], + "Members": [ + { + "Kind": "Method", + "Name": "Init", + "Parameters": [ + { + "Name": "loop", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvLoopHandle" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "Shutdown", + "Parameters": [ + { + "Name": "handle", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle" + }, + { + "Name": "callback", + "Type": "System.Action" + }, + { + "Name": "state", + "Type": "System.Object" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [ + { + "Name": "logger", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IKestrelTrace" + } + ], + "Visibility": "Public", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle", + "Visibility": "Public", + "Kind": "Class", + "Abstract": true, + "BaseType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvHandle", + "ImplementedInterfaces": [], + "Members": [ + { + "Kind": "Method", + "Name": "get_Connection", + "Parameters": [], + "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.Connection", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_Connection", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.Connection" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "ReleaseHandle", + "Parameters": [], + "ReturnType": "System.Boolean", + "Virtual": true, + "Override": true, + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "Listen", + "Parameters": [ + { + "Name": "backlog", + "Type": "System.Int32" + }, + { + "Name": "callback", + "Type": "System.Action" + }, + { + "Name": "state", + "Type": "System.Object" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "Accept", + "Parameters": [ + { + "Name": "handle", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "ReadStart", + "Parameters": [ + { + "Name": "allocCallback", + "Type": "System.Func" + }, + { + "Name": "readCallback", + "Type": "System.Action" + }, + { + "Name": "state", + "Type": "System.Object" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "ReadStop", + "Parameters": [], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "TryWrite", + "Parameters": [ + { + "Name": "buf", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_buf_t" + } + ], + "ReturnType": "System.Int32", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [ + { + "Name": "logger", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IKestrelTrace" + } + ], + "Visibility": "Protected", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvTcpHandle", + "Visibility": "Public", + "Kind": "Class", + "BaseType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle", + "ImplementedInterfaces": [], + "Members": [ + { + "Kind": "Method", + "Name": "Init", + "Parameters": [ + { + "Name": "loop", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvLoopHandle" + }, + { + "Name": "queueCloseHandle", + "Type": "System.Action, System.IntPtr>" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "Bind", + "Parameters": [ + { + "Name": "address", + "Type": "Microsoft.AspNetCore.Server.Kestrel.ServerAddress" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "GetPeerIPEndPoint", + "Parameters": [], + "ReturnType": "System.Net.IPEndPoint", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "GetSockIPEndPoint", + "Parameters": [], + "ReturnType": "System.Net.IPEndPoint", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "Open", + "Parameters": [ + { + "Name": "hSocket", + "Type": "System.IntPtr" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "NoDelay", + "Parameters": [ + { + "Name": "enable", + "Type": "System.Boolean" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "CreateIPEndpoint", + "Parameters": [ + { + "Name": "address", + "Type": "Microsoft.AspNetCore.Server.Kestrel.ServerAddress" + } + ], + "ReturnType": "System.Net.IPEndPoint", + "Static": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [ + { + "Name": "logger", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IKestrelTrace" + } + ], + "Visibility": "Public", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvWriteReq", + "Visibility": "Public", + "Kind": "Class", + "BaseType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvRequest", + "ImplementedInterfaces": [], + "Members": [ + { + "Kind": "Method", + "Name": "Init", + "Parameters": [ + { + "Name": "loop", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvLoopHandle" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "Write", + "Parameters": [ + { + "Name": "handle", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle" + }, + { + "Name": "start", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolIterator" + }, + { + "Name": "end", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolIterator" + }, + { + "Name": "nBuffers", + "Type": "System.Int32" + }, + { + "Name": "callback", + "Type": "System.Action" + }, + { + "Name": "state", + "Type": "System.Object" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "Write2", + "Parameters": [ + { + "Name": "handle", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle" + }, + { + "Name": "bufs", + "Type": "System.ArraySegment>" + }, + { + "Name": "sendHandle", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle" + }, + { + "Name": "callback", + "Type": "System.Action" + }, + { + "Name": "state", + "Type": "System.Object" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [ + { + "Name": "logger", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IKestrelTrace" + } + ], + "Visibility": "Public", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IKestrelTrace", + "Visibility": "Public", + "Kind": "Interface", + "Abstract": true, + "ImplementedInterfaces": [ + "Microsoft.Extensions.Logging.ILogger" + ], + "Members": [ + { + "Kind": "Method", + "Name": "ConnectionStart", + "Parameters": [ + { + "Name": "connectionId", + "Type": "System.String" + } + ], + "ReturnType": "System.Void", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "ConnectionStop", + "Parameters": [ + { + "Name": "connectionId", + "Type": "System.String" + } + ], + "ReturnType": "System.Void", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "ConnectionRead", + "Parameters": [ + { + "Name": "connectionId", + "Type": "System.String" + }, + { + "Name": "count", + "Type": "System.Int32" + } + ], + "ReturnType": "System.Void", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "ConnectionPause", + "Parameters": [ + { + "Name": "connectionId", + "Type": "System.String" + } + ], + "ReturnType": "System.Void", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "ConnectionResume", + "Parameters": [ + { + "Name": "connectionId", + "Type": "System.String" + } + ], + "ReturnType": "System.Void", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "ConnectionReadFin", + "Parameters": [ + { + "Name": "connectionId", + "Type": "System.String" + } + ], + "ReturnType": "System.Void", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "ConnectionWriteFin", + "Parameters": [ + { + "Name": "connectionId", + "Type": "System.String" + } + ], + "ReturnType": "System.Void", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "ConnectionWroteFin", + "Parameters": [ + { + "Name": "connectionId", + "Type": "System.String" + }, + { + "Name": "status", + "Type": "System.Int32" + } + ], + "ReturnType": "System.Void", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "ConnectionKeepAlive", + "Parameters": [ + { + "Name": "connectionId", + "Type": "System.String" + } + ], + "ReturnType": "System.Void", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "ConnectionDisconnect", + "Parameters": [ + { + "Name": "connectionId", + "Type": "System.String" + } + ], + "ReturnType": "System.Void", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "ConnectionWrite", + "Parameters": [ + { + "Name": "connectionId", + "Type": "System.String" + }, + { + "Name": "count", + "Type": "System.Int32" + } + ], + "ReturnType": "System.Void", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "ConnectionWriteCallback", + "Parameters": [ + { + "Name": "connectionId", + "Type": "System.String" + }, + { + "Name": "status", + "Type": "System.Int32" + } + ], + "ReturnType": "System.Void", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "ConnectionError", + "Parameters": [ + { + "Name": "connectionId", + "Type": "System.String" + }, + { + "Name": "ex", + "Type": "System.Exception" + } + ], + "ReturnType": "System.Void", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "ConnectionDisconnectedWrite", + "Parameters": [ + { + "Name": "connectionId", + "Type": "System.String" + }, + { + "Name": "count", + "Type": "System.Int32" + }, + { + "Name": "ex", + "Type": "System.Exception" + } + ], + "ReturnType": "System.Void", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "ConnectionBadRequest", + "Parameters": [ + { + "Name": "connectionId", + "Type": "System.String" + }, + { + "Name": "ex", + "Type": "Microsoft.AspNetCore.Server.Kestrel.BadHttpRequestException" + } + ], + "ReturnType": "System.Void", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "NotAllConnectionsClosedGracefully", + "Parameters": [], + "ReturnType": "System.Void", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "ApplicationError", + "Parameters": [ + { + "Name": "connectionId", + "Type": "System.String" + }, + { + "Name": "ex", + "Type": "System.Exception" + } + ], + "ReturnType": "System.Void", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IThreadPool", + "Visibility": "Public", + "Kind": "Interface", + "Abstract": true, + "ImplementedInterfaces": [], + "Members": [ + { + "Kind": "Method", + "Name": "Complete", + "Parameters": [ + { + "Name": "tcs", + "Type": "System.Threading.Tasks.TaskCompletionSource" + } + ], + "ReturnType": "System.Void", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "Cancel", + "Parameters": [ + { + "Name": "tcs", + "Type": "System.Threading.Tasks.TaskCompletionSource" + } + ], + "ReturnType": "System.Void", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "Error", + "Parameters": [ + { + "Name": "tcs", + "Type": "System.Threading.Tasks.TaskCompletionSource" + }, + { + "Name": "ex", + "Type": "System.Exception" + } + ], + "ReturnType": "System.Void", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "Run", + "Parameters": [ + { + "Name": "action", + "Type": "System.Action" + } + ], + "ReturnType": "System.Void", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.LoggingThreadPool", + "Visibility": "Public", + "Kind": "Class", + "ImplementedInterfaces": [ + "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IThreadPool" + ], + "Members": [ + { + "Kind": "Method", + "Name": "Run", + "Parameters": [ + { + "Name": "action", + "Type": "System.Action" + } + ], + "ReturnType": "System.Void", + "Sealed": true, + "Virtual": true, + "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IThreadPool", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "Complete", + "Parameters": [ + { + "Name": "tcs", + "Type": "System.Threading.Tasks.TaskCompletionSource" + } + ], + "ReturnType": "System.Void", + "Sealed": true, + "Virtual": true, + "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IThreadPool", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "Cancel", + "Parameters": [ + { + "Name": "tcs", + "Type": "System.Threading.Tasks.TaskCompletionSource" + } + ], + "ReturnType": "System.Void", + "Sealed": true, + "Virtual": true, + "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IThreadPool", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "Error", + "Parameters": [ + { + "Name": "tcs", + "Type": "System.Threading.Tasks.TaskCompletionSource" + }, + { + "Name": "ex", + "Type": "System.Exception" + } + ], + "ReturnType": "System.Void", + "Sealed": true, + "Virtual": true, + "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IThreadPool", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [ + { + "Name": "log", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IKestrelTrace" + } + ], + "Visibility": "Public", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPool", + "Visibility": "Public", + "Kind": "Class", + "ImplementedInterfaces": [ + "System.IDisposable" + ], + "Members": [ + { + "Kind": "Method", + "Name": "Lease", + "Parameters": [], + "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolBlock", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "Return", + "Parameters": [ + { + "Name": "block", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolBlock" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "Dispose", + "Parameters": [ + { + "Name": "disposing", + "Type": "System.Boolean" + } + ], + "ReturnType": "System.Void", + "Virtual": true, + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "Dispose", + "Parameters": [], + "ReturnType": "System.Void", + "Sealed": true, + "Virtual": true, + "ImplementedInterface": "System.IDisposable", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [], + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Field", + "Name": "MaxPooledBlockLength", + "Parameters": [], + "ReturnType": "System.Int32", + "Static": true, + "Visibility": "Public", + "GenericParameter": [], + "Constant": true, + "Literal": "4032" + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolBlock", + "Visibility": "Public", + "Kind": "Class", + "ImplementedInterfaces": [], + "Members": [ + { + "Kind": "Method", + "Name": "get_Pool", + "Parameters": [], + "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPool", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_Slab", + "Parameters": [], + "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolSlab", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_Array", + "Parameters": [], + "ReturnType": "System.Byte[]", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "Finalize", + "Parameters": [], + "ReturnType": "System.Void", + "Virtual": true, + "Override": true, + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "Reset", + "Parameters": [], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "ToString", + "Parameters": [], + "ReturnType": "System.String", + "Virtual": true, + "Override": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "GetIterator", + "Parameters": [], + "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolIterator", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [ + { + "Name": "dataArrayPtr", + "Type": "System.IntPtr" + } + ], + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Field", + "Name": "DataArrayPtr", + "Parameters": [], + "ReturnType": "System.IntPtr", + "ReadOnly": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Field", + "Name": "Data", + "Parameters": [], + "ReturnType": "System.ArraySegment", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Field", + "Name": "Start", + "Parameters": [], + "ReturnType": "System.Int32", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Field", + "Name": "End", + "Parameters": [], + "ReturnType": "System.Int32", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Field", + "Name": "Next", + "Parameters": [], + "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolBlock", + "Visibility": "Public", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolIterator", + "Visibility": "Public", + "Kind": "Struct", + "Sealed": true, + "ImplementedInterfaces": [], + "Members": [ + { + "Kind": "Method", + "Name": "get_IsDefault", + "Parameters": [], + "ReturnType": "System.Boolean", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_IsEnd", + "Parameters": [], + "ReturnType": "System.Boolean", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_Block", + "Parameters": [], + "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolBlock", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_Index", + "Parameters": [], + "ReturnType": "System.Int32", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "Take", + "Parameters": [], + "ReturnType": "System.Int32", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "Skip", + "Parameters": [ + { + "Name": "bytesToSkip", + "Type": "System.Int32" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "Peek", + "Parameters": [], + "ReturnType": "System.Int32", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "PeekLong", + "Parameters": [], + "ReturnType": "System.Int64", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "Seek", + "Parameters": [ + { + "Name": "byte0Vector", + "Type": "System.Numerics.Vector`1[[System.Byte, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]", + "Direction": "Ref" + } + ], + "ReturnType": "System.Int32", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "Seek", + "Parameters": [ + { + "Name": "byte0Vector", + "Type": "System.Numerics.Vector`1[[System.Byte, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]", + "Direction": "Ref" + }, + { + "Name": "byte1Vector", + "Type": "System.Numerics.Vector`1[[System.Byte, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]", + "Direction": "Ref" + } + ], + "ReturnType": "System.Int32", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "Seek", + "Parameters": [ + { + "Name": "byte0Vector", + "Type": "System.Numerics.Vector`1[[System.Byte, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]", + "Direction": "Ref" + }, + { + "Name": "byte1Vector", + "Type": "System.Numerics.Vector`1[[System.Byte, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]", + "Direction": "Ref" + }, + { + "Name": "byte2Vector", + "Type": "System.Numerics.Vector`1[[System.Byte, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]", + "Direction": "Ref" + } + ], + "ReturnType": "System.Int32", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "Put", + "Parameters": [ + { + "Name": "data", + "Type": "System.Byte" + } + ], + "ReturnType": "System.Boolean", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "GetLength", + "Parameters": [ + { + "Name": "end", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolIterator" + } + ], + "ReturnType": "System.Int32", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "CopyTo", + "Parameters": [ + { + "Name": "array", + "Type": "System.Byte[]" + }, + { + "Name": "offset", + "Type": "System.Int32" + }, + { + "Name": "count", + "Type": "System.Int32" + }, + { + "Name": "actual", + "Type": "System.Int32", + "Direction": "Out" + } + ], + "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolIterator", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "CopyFrom", + "Parameters": [ + { + "Name": "data", + "Type": "System.Byte[]" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "CopyFrom", + "Parameters": [ + { + "Name": "buffer", + "Type": "System.ArraySegment" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "CopyFrom", + "Parameters": [ + { + "Name": "data", + "Type": "System.Byte[]" + }, + { + "Name": "offset", + "Type": "System.Int32" + }, + { + "Name": "count", + "Type": "System.Int32" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "CopyFromAscii", + "Parameters": [ + { + "Name": "data", + "Type": "System.String" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [ + { + "Name": "block", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolBlock" + } + ], + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [ + { + "Name": "block", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolBlock" + }, + { + "Name": "index", + "Type": "System.Int32" + } + ], + "Visibility": "Public", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolIteratorExtensions", + "Visibility": "Public", + "Kind": "Class", + "Abstract": true, + "Static": true, + "Sealed": true, + "ImplementedInterfaces": [], + "Members": [ + { + "Kind": "Method", + "Name": "GetAsciiString", + "Parameters": [ + { + "Name": "start", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolIterator" + }, + { + "Name": "end", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolIterator" + } + ], + "ReturnType": "System.String", + "Static": true, + "Extension": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "GetUtf8String", + "Parameters": [ + { + "Name": "start", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolIterator" + }, + { + "Name": "end", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolIterator" + } + ], + "ReturnType": "System.String", + "Static": true, + "Extension": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "GetArraySegment", + "Parameters": [ + { + "Name": "start", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolIterator" + }, + { + "Name": "end", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolIterator" + } + ], + "ReturnType": "System.ArraySegment", + "Static": true, + "Extension": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "GetKnownMethod", + "Parameters": [ + { + "Name": "begin", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolIterator" + }, + { + "Name": "knownMethod", + "Type": "System.String", + "Direction": "Out" + } + ], + "ReturnType": "System.Boolean", + "Static": true, + "Extension": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "GetKnownVersion", + "Parameters": [ + { + "Name": "begin", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolIterator" + }, + { + "Name": "knownVersion", + "Type": "System.String", + "Direction": "Out" + } + ], + "ReturnType": "System.Boolean", + "Static": true, + "Extension": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Field", + "Name": "HttpConnectMethod", + "Parameters": [], + "ReturnType": "System.String", + "Static": true, + "Visibility": "Public", + "GenericParameter": [], + "Constant": true, + "Literal": "\"CONNECT\"" + }, + { + "Kind": "Field", + "Name": "HttpDeleteMethod", + "Parameters": [], + "ReturnType": "System.String", + "Static": true, + "Visibility": "Public", + "GenericParameter": [], + "Constant": true, + "Literal": "\"DELETE\"" + }, + { + "Kind": "Field", + "Name": "HttpGetMethod", + "Parameters": [], + "ReturnType": "System.String", + "Static": true, + "Visibility": "Public", + "GenericParameter": [], + "Constant": true, + "Literal": "\"GET\"" + }, + { + "Kind": "Field", + "Name": "HttpHeadMethod", + "Parameters": [], + "ReturnType": "System.String", + "Static": true, + "Visibility": "Public", + "GenericParameter": [], + "Constant": true, + "Literal": "\"HEAD\"" + }, + { + "Kind": "Field", + "Name": "HttpPatchMethod", + "Parameters": [], + "ReturnType": "System.String", + "Static": true, + "Visibility": "Public", + "GenericParameter": [], + "Constant": true, + "Literal": "\"PATCH\"" + }, + { + "Kind": "Field", + "Name": "HttpPostMethod", + "Parameters": [], + "ReturnType": "System.String", + "Static": true, + "Visibility": "Public", + "GenericParameter": [], + "Constant": true, + "Literal": "\"POST\"" + }, + { + "Kind": "Field", + "Name": "HttpPutMethod", + "Parameters": [], + "ReturnType": "System.String", + "Static": true, + "Visibility": "Public", + "GenericParameter": [], + "Constant": true, + "Literal": "\"PUT\"" + }, + { + "Kind": "Field", + "Name": "HttpOptionsMethod", + "Parameters": [], + "ReturnType": "System.String", + "Static": true, + "Visibility": "Public", + "GenericParameter": [], + "Constant": true, + "Literal": "\"OPTIONS\"" + }, + { + "Kind": "Field", + "Name": "HttpTraceMethod", + "Parameters": [], + "ReturnType": "System.String", + "Static": true, + "Visibility": "Public", + "GenericParameter": [], + "Constant": true, + "Literal": "\"TRACE\"" + }, + { + "Kind": "Field", + "Name": "Http10Version", + "Parameters": [], + "ReturnType": "System.String", + "Static": true, + "Visibility": "Public", + "GenericParameter": [], + "Constant": true, + "Literal": "\"HTTP/1.0\"" + }, + { + "Kind": "Field", + "Name": "Http11Version", + "Parameters": [], + "ReturnType": "System.String", + "Static": true, + "Visibility": "Public", + "GenericParameter": [], + "Constant": true, + "Literal": "\"HTTP/1.1\"" + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolSlab", + "Visibility": "Public", + "Kind": "Class", + "ImplementedInterfaces": [ + "System.IDisposable" + ], + "Members": [ + { + "Kind": "Method", + "Name": "Create", + "Parameters": [ + { + "Name": "length", + "Type": "System.Int32" + } + ], + "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolSlab", + "Static": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "Dispose", + "Parameters": [ + { + "Name": "disposing", + "Type": "System.Boolean" + } + ], + "ReturnType": "System.Void", + "Virtual": true, + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "Finalize", + "Parameters": [], + "ReturnType": "System.Void", + "Virtual": true, + "Override": true, + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "Dispose", + "Parameters": [], + "ReturnType": "System.Void", + "Sealed": true, + "Virtual": true, + "ImplementedInterface": "System.IDisposable", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [], + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Field", + "Name": "Array", + "Parameters": [], + "ReturnType": "System.Byte[]", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Field", + "Name": "ArrayPtr", + "Parameters": [], + "ReturnType": "System.IntPtr", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Field", + "Name": "IsActive", + "Parameters": [], + "ReturnType": "System.Boolean", + "Visibility": "Public", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.TaskUtilities", + "Visibility": "Public", + "Kind": "Class", + "Abstract": true, + "Static": true, + "Sealed": true, + "ImplementedInterfaces": [], + "Members": [ + { + "Kind": "Method", + "Name": "GetCancelledTask", + "Parameters": [ + { + "Name": "cancellationToken", + "Type": "System.Threading.CancellationToken" + } + ], + "ReturnType": "System.Threading.Tasks.Task", + "Static": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "GetCancelledZeroTask", + "Parameters": [ + { + "Name": "cancellationToken", + "Type": "System.Threading.CancellationToken", + "DefaultValue": "default(System.Threading.CancellationToken)" + } + ], + "ReturnType": "System.Threading.Tasks.Task", + "Static": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Field", + "Name": "CompletedTask", + "Parameters": [], + "ReturnType": "System.Threading.Tasks.Task", + "Static": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Field", + "Name": "ZeroTask", + "Parameters": [], + "ReturnType": "System.Threading.Tasks.Task", + "Static": true, + "Visibility": "Public", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.BufferSizeControl", + "Visibility": "Public", + "Kind": "Class", + "ImplementedInterfaces": [ + "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.IBufferSizeControl" + ], + "Members": [ + { + "Kind": "Method", + "Name": "Add", + "Parameters": [ + { + "Name": "count", + "Type": "System.Int32" + } + ], + "ReturnType": "System.Void", + "Sealed": true, + "Virtual": true, + "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.IBufferSizeControl", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "Subtract", + "Parameters": [ + { + "Name": "count", + "Type": "System.Int32" + } + ], + "ReturnType": "System.Void", + "Sealed": true, + "Virtual": true, + "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.IBufferSizeControl", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [ + { + "Name": "maxSize", + "Type": "System.Int64" + }, + { + "Name": "connectionControl", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.IConnectionControl" + }, + { + "Name": "connectionThread", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.KestrelThread" + } + ], + "Visibility": "Public", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ChunkWriter", + "Visibility": "Public", + "Kind": "Class", + "Abstract": true, + "Static": true, + "Sealed": true, + "ImplementedInterfaces": [], + "Members": [ + { + "Kind": "Method", + "Name": "BeginChunkBytes", + "Parameters": [ + { + "Name": "dataCount", + "Type": "System.Int32" + } + ], + "ReturnType": "System.ArraySegment", + "Static": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "WriteBeginChunkBytes", + "Parameters": [ + { + "Name": "start", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolIterator", + "Direction": "Ref" + }, + { + "Name": "dataCount", + "Type": "System.Int32" + } + ], + "ReturnType": "System.Int32", + "Static": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "WriteEndChunkBytes", + "Parameters": [ + { + "Name": "start", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolIterator", + "Direction": "Ref" + } + ], + "ReturnType": "System.Void", + "Static": true, + "Visibility": "Public", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.Connection", + "Visibility": "Public", + "Kind": "Class", + "BaseType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ConnectionContext", + "ImplementedInterfaces": [ + "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.IConnectionControl" + ], + "Members": [ + { + "Kind": "Method", + "Name": "Start", + "Parameters": [], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "StopAsync", + "Parameters": [], + "ReturnType": "System.Threading.Tasks.Task", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "Abort", + "Parameters": [], + "ReturnType": "System.Void", + "Virtual": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "OnSocketClosed", + "Parameters": [], + "ReturnType": "System.Void", + "Virtual": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [ + { + "Name": "context", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ListenerContext" + }, + { + "Name": "socket", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle" + } + ], + "Visibility": "Public", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ConnectionContext", + "Visibility": "Public", + "Kind": "Class", + "BaseType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ListenerContext", + "ImplementedInterfaces": [], + "Members": [ + { + "Kind": "Method", + "Name": "get_SocketInput", + "Parameters": [], + "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.SocketInput", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_SocketInput", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.SocketInput" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_SocketOutput", + "Parameters": [], + "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ISocketOutput", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_SocketOutput", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ISocketOutput" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_ConnectionControl", + "Parameters": [], + "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.IConnectionControl", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_ConnectionControl", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.IConnectionControl" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_RemoteEndPoint", + "Parameters": [], + "ReturnType": "System.Net.IPEndPoint", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_RemoteEndPoint", + "Parameters": [ + { + "Name": "value", + "Type": "System.Net.IPEndPoint" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_LocalEndPoint", + "Parameters": [], + "ReturnType": "System.Net.IPEndPoint", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_LocalEndPoint", + "Parameters": [ + { + "Name": "value", + "Type": "System.Net.IPEndPoint" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_ConnectionId", + "Parameters": [], + "ReturnType": "System.String", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_ConnectionId", + "Parameters": [ + { + "Name": "value", + "Type": "System.String" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_PrepareRequest", + "Parameters": [], + "ReturnType": "System.Action", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_PrepareRequest", + "Parameters": [ + { + "Name": "value", + "Type": "System.Action" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [], + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [ + { + "Name": "context", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ListenerContext" + } + ], + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [ + { + "Name": "context", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ConnectionContext" + } + ], + "Visibility": "Public", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ConnectionManager", + "Visibility": "Public", + "Kind": "Class", + "ImplementedInterfaces": [], + "Members": [ + { + "Kind": "Method", + "Name": "WalkConnectionsAndClose", + "Parameters": [], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "WaitForConnectionCloseAsync", + "Parameters": [], + "ReturnType": "System.Threading.Tasks.Task", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [ + { + "Name": "thread", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.KestrelThread" + } + ], + "Visibility": "Public", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.DateHeaderValueManager", + "Visibility": "Public", + "Kind": "Class", + "ImplementedInterfaces": [ + "System.IDisposable" + ], + "Members": [ + { + "Kind": "Method", + "Name": "GetDateHeaderValues", + "Parameters": [], + "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.DateHeaderValueManager+DateHeaderValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "Dispose", + "Parameters": [], + "ReturnType": "System.Void", + "Sealed": true, + "Virtual": true, + "ImplementedInterface": "System.IDisposable", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [], + "Visibility": "Public", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.Frame", + "Visibility": "Public", + "Kind": "Class", + "Abstract": true, + "BaseType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ConnectionContext", + "ImplementedInterfaces": [ + "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.IFrameControl", + "Microsoft.AspNetCore.Http.Features.IFeatureCollection", + "Microsoft.AspNetCore.Http.Features.IHttpRequestFeature", + "Microsoft.AspNetCore.Http.Features.IHttpResponseFeature", + "Microsoft.AspNetCore.Http.Features.IHttpUpgradeFeature", + "Microsoft.AspNetCore.Http.Features.IHttpConnectionFeature", + "Microsoft.AspNetCore.Http.Features.IHttpRequestLifetimeFeature" + ], + "Members": [ + { + "Kind": "Method", + "Name": "get_ConnectionIdFeature", + "Parameters": [], + "ReturnType": "System.String", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_ConnectionIdFeature", + "Parameters": [ + { + "Name": "value", + "Type": "System.String" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_RemoteIpAddress", + "Parameters": [], + "ReturnType": "System.Net.IPAddress", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_RemoteIpAddress", + "Parameters": [ + { + "Name": "value", + "Type": "System.Net.IPAddress" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_RemotePort", + "Parameters": [], + "ReturnType": "System.Int32", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_RemotePort", + "Parameters": [ + { + "Name": "value", + "Type": "System.Int32" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_LocalIpAddress", + "Parameters": [], + "ReturnType": "System.Net.IPAddress", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_LocalIpAddress", + "Parameters": [ + { + "Name": "value", + "Type": "System.Net.IPAddress" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_LocalPort", + "Parameters": [], + "ReturnType": "System.Int32", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_LocalPort", + "Parameters": [ + { + "Name": "value", + "Type": "System.Int32" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_Scheme", + "Parameters": [], + "ReturnType": "System.String", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_Scheme", + "Parameters": [ + { + "Name": "value", + "Type": "System.String" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_Method", + "Parameters": [], + "ReturnType": "System.String", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_Method", + "Parameters": [ + { + "Name": "value", + "Type": "System.String" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_PathBase", + "Parameters": [], + "ReturnType": "System.String", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_PathBase", + "Parameters": [ + { + "Name": "value", + "Type": "System.String" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_Path", + "Parameters": [], + "ReturnType": "System.String", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_Path", + "Parameters": [ + { + "Name": "value", + "Type": "System.String" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_QueryString", + "Parameters": [], + "ReturnType": "System.String", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_QueryString", + "Parameters": [ + { + "Name": "value", + "Type": "System.String" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_RawTarget", + "Parameters": [], + "ReturnType": "System.String", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_RawTarget", + "Parameters": [ + { + "Name": "value", + "Type": "System.String" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HttpVersion", + "Parameters": [], + "ReturnType": "System.String", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HttpVersion", + "Parameters": [ + { + "Name": "value", + "Type": "System.String" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_RequestHeaders", + "Parameters": [], + "ReturnType": "Microsoft.AspNetCore.Http.IHeaderDictionary", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_RequestHeaders", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.AspNetCore.Http.IHeaderDictionary" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_RequestBody", + "Parameters": [], + "ReturnType": "System.IO.Stream", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_RequestBody", + "Parameters": [ + { + "Name": "value", + "Type": "System.IO.Stream" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_StatusCode", + "Parameters": [], + "ReturnType": "System.Int32", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_StatusCode", + "Parameters": [ + { + "Name": "value", + "Type": "System.Int32" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_ReasonPhrase", + "Parameters": [], + "ReturnType": "System.String", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_ReasonPhrase", + "Parameters": [ + { + "Name": "value", + "Type": "System.String" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_ResponseHeaders", + "Parameters": [], + "ReturnType": "Microsoft.AspNetCore.Http.IHeaderDictionary", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_ResponseHeaders", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.AspNetCore.Http.IHeaderDictionary" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_ResponseBody", + "Parameters": [], + "ReturnType": "System.IO.Stream", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_ResponseBody", + "Parameters": [ + { + "Name": "value", + "Type": "System.IO.Stream" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_DuplexStream", + "Parameters": [], + "ReturnType": "System.IO.Stream", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_DuplexStream", + "Parameters": [ + { + "Name": "value", + "Type": "System.IO.Stream" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_RequestAborted", + "Parameters": [], + "ReturnType": "System.Threading.CancellationToken", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_RequestAborted", + "Parameters": [ + { + "Name": "value", + "Type": "System.Threading.CancellationToken" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HasResponseStarted", + "Parameters": [], + "ReturnType": "System.Boolean", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_FrameRequestHeaders", + "Parameters": [], + "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.FrameRequestHeaders", + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_FrameResponseHeaders", + "Parameters": [], + "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.FrameResponseHeaders", + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "InitializeHeaders", + "Parameters": [], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "InitializeStreams", + "Parameters": [ + { + "Name": "messageBody", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.MessageBody" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "PauseStreams", + "Parameters": [], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "ResumeStreams", + "Parameters": [], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "StopStreams", + "Parameters": [], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "Reset", + "Parameters": [], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "Start", + "Parameters": [], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "Stop", + "Parameters": [], + "ReturnType": "System.Threading.Tasks.Task", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "Abort", + "Parameters": [], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "RequestProcessingAsync", + "Parameters": [], + "ReturnType": "System.Threading.Tasks.Task", + "Virtual": true, + "Abstract": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "OnStarting", + "Parameters": [ + { + "Name": "callback", + "Type": "System.Func" + }, + { + "Name": "state", + "Type": "System.Object" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "OnCompleted", + "Parameters": [ + { + "Name": "callback", + "Type": "System.Func" + }, + { + "Name": "state", + "Type": "System.Object" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "FireOnStarting", + "Parameters": [], + "ReturnType": "System.Threading.Tasks.Task", + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "FireOnCompleted", + "Parameters": [], + "ReturnType": "System.Threading.Tasks.Task", + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "Flush", + "Parameters": [], + "ReturnType": "System.Void", + "Sealed": true, + "Virtual": true, + "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.IFrameControl", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "FlushAsync", + "Parameters": [ + { + "Name": "cancellationToken", + "Type": "System.Threading.CancellationToken" + } + ], + "ReturnType": "System.Threading.Tasks.Task", + "Sealed": true, + "Virtual": true, + "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.IFrameControl", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "Write", + "Parameters": [ + { + "Name": "data", + "Type": "System.ArraySegment" + } + ], + "ReturnType": "System.Void", + "Sealed": true, + "Virtual": true, + "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.IFrameControl", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "WriteAsync", + "Parameters": [ + { + "Name": "data", + "Type": "System.ArraySegment" + }, + { + "Name": "cancellationToken", + "Type": "System.Threading.CancellationToken" + } + ], + "ReturnType": "System.Threading.Tasks.Task", + "Sealed": true, + "Virtual": true, + "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.IFrameControl", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "WriteAsyncAwaited", + "Parameters": [ + { + "Name": "data", + "Type": "System.ArraySegment" + }, + { + "Name": "cancellationToken", + "Type": "System.Threading.CancellationToken" + } + ], + "ReturnType": "System.Threading.Tasks.Task", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "ProduceContinue", + "Parameters": [], + "ReturnType": "System.Void", + "Sealed": true, + "Virtual": true, + "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.IFrameControl", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "ProduceStartAndFireOnStarting", + "Parameters": [], + "ReturnType": "System.Threading.Tasks.Task", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "TryProduceInvalidRequestResponse", + "Parameters": [], + "ReturnType": "System.Threading.Tasks.Task", + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "ProduceEnd", + "Parameters": [], + "ReturnType": "System.Threading.Tasks.Task", + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "TakeStartLine", + "Parameters": [ + { + "Name": "input", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.SocketInput" + } + ], + "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.Frame+RequestLineStatus", + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "TakeMessageHeaders", + "Parameters": [ + { + "Name": "input", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.SocketInput" + }, + { + "Name": "requestHeaders", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.FrameRequestHeaders" + } + ], + "ReturnType": "System.Boolean", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "StatusCanHaveBody", + "Parameters": [ + { + "Name": "statusCode", + "Type": "System.Int32" + } + ], + "ReturnType": "System.Boolean", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "RejectRequest", + "Parameters": [ + { + "Name": "message", + "Type": "System.String" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "SetBadRequestState", + "Parameters": [ + { + "Name": "ex", + "Type": "Microsoft.AspNetCore.Server.Kestrel.BadHttpRequestException" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "ReportApplicationError", + "Parameters": [ + { + "Name": "ex", + "Type": "System.Exception" + } + ], + "ReturnType": "System.Void", + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "ResetFeatureCollection", + "Parameters": [], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_FrameControl", + "Parameters": [], + "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.IFrameControl", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_FrameControl", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.IFrameControl" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [ + { + "Name": "context", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ConnectionContext" + } + ], + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Field", + "Name": "_requestRejected", + "Parameters": [], + "ReturnType": "System.Boolean", + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Field", + "Name": "_onStarting", + "Parameters": [], + "ReturnType": "System.Collections.Generic.List, System.Object>>", + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Field", + "Name": "_onCompleted", + "Parameters": [], + "ReturnType": "System.Collections.Generic.List, System.Object>>", + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Field", + "Name": "_requestProcessingStopping", + "Parameters": [], + "ReturnType": "System.Boolean", + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Field", + "Name": "_requestAborted", + "Parameters": [], + "ReturnType": "System.Int32", + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Field", + "Name": "_requestProcessingStatus", + "Parameters": [], + "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.Frame+RequestProcessingStatus", + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Field", + "Name": "_keepAlive", + "Parameters": [], + "ReturnType": "System.Boolean", + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Field", + "Name": "_applicationException", + "Parameters": [], + "ReturnType": "System.Exception", + "Visibility": "Protected", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.FrameHeaders", + "Visibility": "Public", + "Kind": "Class", + "Abstract": true, + "ImplementedInterfaces": [ + "Microsoft.AspNetCore.Http.IHeaderDictionary" + ], + "Members": [ + { + "Kind": "Method", + "Name": "get_Unknown", + "Parameters": [], + "ReturnType": "System.Collections.Generic.Dictionary", + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "ThrowReadOnlyException", + "Parameters": [], + "ReturnType": "System.Void", + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "ThrowArgumentException", + "Parameters": [], + "ReturnType": "System.Void", + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "ThrowKeyNotFoundException", + "Parameters": [], + "ReturnType": "System.Void", + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "ThrowDuplicateKeyException", + "Parameters": [], + "ReturnType": "System.Void", + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "SetReadOnly", + "Parameters": [], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "Reset", + "Parameters": [], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "AppendValue", + "Parameters": [ + { + "Name": "existing", + "Type": "Microsoft.Extensions.Primitives.StringValues" + }, + { + "Name": "append", + "Type": "System.String" + } + ], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Static": true, + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "BitCount", + "Parameters": [ + { + "Name": "value", + "Type": "System.Int64" + } + ], + "ReturnType": "System.Int32", + "Static": true, + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "GetCountFast", + "Parameters": [], + "ReturnType": "System.Int32", + "Virtual": true, + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "GetValueFast", + "Parameters": [ + { + "Name": "key", + "Type": "System.String" + } + ], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Virtual": true, + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "TryGetValueFast", + "Parameters": [ + { + "Name": "key", + "Type": "System.String" + }, + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues", + "Direction": "Out" + } + ], + "ReturnType": "System.Boolean", + "Virtual": true, + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "SetValueFast", + "Parameters": [ + { + "Name": "key", + "Type": "System.String" + }, + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Virtual": true, + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "AddValueFast", + "Parameters": [ + { + "Name": "key", + "Type": "System.String" + }, + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Virtual": true, + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "RemoveFast", + "Parameters": [ + { + "Name": "key", + "Type": "System.String" + } + ], + "ReturnType": "System.Boolean", + "Virtual": true, + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "ClearFast", + "Parameters": [], + "ReturnType": "System.Void", + "Virtual": true, + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "CopyToFast", + "Parameters": [ + { + "Name": "array", + "Type": "System.Collections.Generic.KeyValuePair[]" + }, + { + "Name": "arrayIndex", + "Type": "System.Int32" + } + ], + "ReturnType": "System.Void", + "Virtual": true, + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "GetEnumeratorFast", + "Parameters": [], + "ReturnType": "System.Collections.Generic.IEnumerator>", + "Virtual": true, + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "ValidateHeaderCharacters", + "Parameters": [ + { + "Name": "headerValues", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Static": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "ValidateHeaderCharacters", + "Parameters": [ + { + "Name": "headerCharacters", + "Type": "System.String" + } + ], + "ReturnType": "System.Void", + "Static": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [], + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Field", + "Name": "_isReadOnly", + "Parameters": [], + "ReturnType": "System.Boolean", + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Field", + "Name": "MaybeUnknown", + "Parameters": [], + "ReturnType": "System.Collections.Generic.Dictionary", + "Visibility": "Protected", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.FrameRequestHeaders", + "Visibility": "Public", + "Kind": "Class", + "BaseType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.FrameHeaders", + "ImplementedInterfaces": [], + "Members": [ + { + "Kind": "Method", + "Name": "get_HeaderCacheControl", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderCacheControl", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HeaderConnection", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderConnection", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HeaderDate", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderDate", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HeaderKeepAlive", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderKeepAlive", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HeaderPragma", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderPragma", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HeaderTrailer", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderTrailer", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HeaderTransferEncoding", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderTransferEncoding", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HeaderUpgrade", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderUpgrade", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HeaderVia", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderVia", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HeaderWarning", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderWarning", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HeaderAllow", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderAllow", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HeaderContentLength", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderContentLength", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HeaderContentType", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderContentType", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HeaderContentEncoding", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderContentEncoding", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HeaderContentLanguage", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderContentLanguage", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HeaderContentLocation", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderContentLocation", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HeaderContentMD5", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderContentMD5", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HeaderContentRange", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderContentRange", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HeaderExpires", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderExpires", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HeaderLastModified", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderLastModified", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HeaderAccept", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderAccept", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HeaderAcceptCharset", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderAcceptCharset", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HeaderAcceptEncoding", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderAcceptEncoding", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HeaderAcceptLanguage", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderAcceptLanguage", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HeaderAuthorization", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderAuthorization", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HeaderCookie", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderCookie", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HeaderExpect", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderExpect", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HeaderFrom", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderFrom", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HeaderHost", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderHost", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HeaderIfMatch", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderIfMatch", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HeaderIfModifiedSince", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderIfModifiedSince", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HeaderIfNoneMatch", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderIfNoneMatch", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HeaderIfRange", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderIfRange", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HeaderIfUnmodifiedSince", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderIfUnmodifiedSince", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HeaderMaxForwards", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderMaxForwards", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HeaderProxyAuthorization", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderProxyAuthorization", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HeaderReferer", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderReferer", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HeaderRange", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderRange", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HeaderTE", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderTE", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HeaderTranslate", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderTranslate", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HeaderUserAgent", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderUserAgent", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HeaderOrigin", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderOrigin", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HeaderAccessControlRequestMethod", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderAccessControlRequestMethod", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HeaderAccessControlRequestHeaders", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderAccessControlRequestHeaders", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "GetCountFast", + "Parameters": [], + "ReturnType": "System.Int32", + "Virtual": true, + "Override": true, + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "GetValueFast", + "Parameters": [ + { + "Name": "key", + "Type": "System.String" + } + ], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Virtual": true, + "Override": true, + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "TryGetValueFast", + "Parameters": [ + { + "Name": "key", + "Type": "System.String" + }, + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues", + "Direction": "Out" + } + ], + "ReturnType": "System.Boolean", + "Virtual": true, + "Override": true, + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "SetValueFast", + "Parameters": [ + { + "Name": "key", + "Type": "System.String" + }, + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Virtual": true, + "Override": true, + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "AddValueFast", + "Parameters": [ + { + "Name": "key", + "Type": "System.String" + }, + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Virtual": true, + "Override": true, + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "RemoveFast", + "Parameters": [ + { + "Name": "key", + "Type": "System.String" + } + ], + "ReturnType": "System.Boolean", + "Virtual": true, + "Override": true, + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "ClearFast", + "Parameters": [], + "ReturnType": "System.Void", + "Virtual": true, + "Override": true, + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "CopyToFast", + "Parameters": [ + { + "Name": "array", + "Type": "System.Collections.Generic.KeyValuePair[]" + }, + { + "Name": "arrayIndex", + "Type": "System.Int32" + } + ], + "ReturnType": "System.Void", + "Virtual": true, + "Override": true, + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "Append", + "Parameters": [ + { + "Name": "keyBytes", + "Type": "System.Byte[]" + }, + { + "Name": "keyOffset", + "Type": "System.Int32" + }, + { + "Name": "keyLength", + "Type": "System.Int32" + }, + { + "Name": "value", + "Type": "System.String" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "GetEnumerator", + "Parameters": [], + "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.FrameRequestHeaders+Enumerator", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "GetEnumeratorFast", + "Parameters": [], + "ReturnType": "System.Collections.Generic.IEnumerator>", + "Virtual": true, + "Override": true, + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [], + "Visibility": "Public", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.FrameResponseHeaders", + "Visibility": "Public", + "Kind": "Class", + "BaseType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.FrameHeaders", + "ImplementedInterfaces": [], + "Members": [ + { + "Kind": "Method", + "Name": "get_HeaderCacheControl", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderCacheControl", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HeaderConnection", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderConnection", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HeaderDate", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderDate", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HeaderKeepAlive", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderKeepAlive", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HeaderPragma", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderPragma", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HeaderTrailer", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderTrailer", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HeaderTransferEncoding", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderTransferEncoding", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HeaderUpgrade", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderUpgrade", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HeaderVia", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderVia", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HeaderWarning", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderWarning", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HeaderAllow", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderAllow", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HeaderContentLength", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderContentLength", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HeaderContentType", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderContentType", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HeaderContentEncoding", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderContentEncoding", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HeaderContentLanguage", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderContentLanguage", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HeaderContentLocation", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderContentLocation", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HeaderContentMD5", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderContentMD5", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HeaderContentRange", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderContentRange", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HeaderExpires", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderExpires", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HeaderLastModified", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderLastModified", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HeaderAcceptRanges", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderAcceptRanges", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HeaderAge", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderAge", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HeaderETag", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderETag", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HeaderLocation", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderLocation", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HeaderProxyAutheticate", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderProxyAutheticate", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HeaderRetryAfter", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderRetryAfter", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HeaderServer", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderServer", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HeaderSetCookie", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderSetCookie", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HeaderVary", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderVary", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HeaderWWWAuthenticate", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderWWWAuthenticate", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HeaderAccessControlAllowCredentials", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderAccessControlAllowCredentials", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HeaderAccessControlAllowHeaders", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderAccessControlAllowHeaders", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HeaderAccessControlAllowMethods", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderAccessControlAllowMethods", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HeaderAccessControlAllowOrigin", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderAccessControlAllowOrigin", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HeaderAccessControlExposeHeaders", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderAccessControlExposeHeaders", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HeaderAccessControlMaxAge", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderAccessControlMaxAge", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "SetRawConnection", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + }, + { + "Name": "raw", + "Type": "System.Byte[]" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "SetRawDate", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + }, + { + "Name": "raw", + "Type": "System.Byte[]" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "SetRawTransferEncoding", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + }, + { + "Name": "raw", + "Type": "System.Byte[]" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "SetRawContentLength", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + }, + { + "Name": "raw", + "Type": "System.Byte[]" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "SetRawServer", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + }, + { + "Name": "raw", + "Type": "System.Byte[]" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "GetCountFast", + "Parameters": [], + "ReturnType": "System.Int32", + "Virtual": true, + "Override": true, + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "GetValueFast", + "Parameters": [ + { + "Name": "key", + "Type": "System.String" + } + ], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Virtual": true, + "Override": true, + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "TryGetValueFast", + "Parameters": [ + { + "Name": "key", + "Type": "System.String" + }, + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues", + "Direction": "Out" + } + ], + "ReturnType": "System.Boolean", + "Virtual": true, + "Override": true, + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "SetValueFast", + "Parameters": [ + { + "Name": "key", + "Type": "System.String" + }, + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Virtual": true, + "Override": true, + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "AddValueFast", + "Parameters": [ + { + "Name": "key", + "Type": "System.String" + }, + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Virtual": true, + "Override": true, + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "RemoveFast", + "Parameters": [ + { + "Name": "key", + "Type": "System.String" + } + ], + "ReturnType": "System.Boolean", + "Virtual": true, + "Override": true, + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "ClearFast", + "Parameters": [], + "ReturnType": "System.Void", + "Virtual": true, + "Override": true, + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "CopyToFast", + "Parameters": [ + { + "Name": "array", + "Type": "System.Collections.Generic.KeyValuePair[]" + }, + { + "Name": "arrayIndex", + "Type": "System.Int32" + } + ], + "ReturnType": "System.Void", + "Virtual": true, + "Override": true, + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "CopyToFast", + "Parameters": [ + { + "Name": "output", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolIterator", + "Direction": "Ref" + } + ], + "ReturnType": "System.Void", + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HasConnection", + "Parameters": [], + "ReturnType": "System.Boolean", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HasTransferEncoding", + "Parameters": [], + "ReturnType": "System.Boolean", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HasContentLength", + "Parameters": [], + "ReturnType": "System.Boolean", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HasServer", + "Parameters": [], + "ReturnType": "System.Boolean", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HasDate", + "Parameters": [], + "ReturnType": "System.Boolean", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "GetEnumerator", + "Parameters": [], + "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.FrameResponseHeaders+Enumerator", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "GetEnumeratorFast", + "Parameters": [], + "ReturnType": "System.Collections.Generic.IEnumerator>", + "Virtual": true, + "Override": true, + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "CopyTo", + "Parameters": [ + { + "Name": "output", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolIterator", + "Direction": "Ref" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [], + "Visibility": "Public", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.Frame", + "Visibility": "Public", + "Kind": "Class", + "BaseType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.Frame", + "ImplementedInterfaces": [], + "Members": [ + { + "Kind": "Method", + "Name": "RequestProcessingAsync", + "Parameters": [], + "ReturnType": "System.Threading.Tasks.Task", + "Virtual": true, + "Override": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [ + { + "Name": "application", + "Type": "Microsoft.AspNetCore.Hosting.Server.IHttpApplication" + }, + { + "Name": "context", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ConnectionContext" + } + ], + "Visibility": "Public", + "GenericParameter": [] + } + ], + "GenericParameters": [ + { + "ParameterName": "TContext", + "ParameterPosition": 0, + "BaseTypeOrInterfaces": [] + } + ] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.IBufferSizeControl", + "Visibility": "Public", + "Kind": "Interface", + "Abstract": true, + "ImplementedInterfaces": [], + "Members": [ + { + "Kind": "Method", + "Name": "Add", + "Parameters": [ + { + "Name": "count", + "Type": "System.Int32" + } + ], + "ReturnType": "System.Void", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "Subtract", + "Parameters": [ + { + "Name": "count", + "Type": "System.Int32" + } + ], + "ReturnType": "System.Void", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.IConnectionControl", + "Visibility": "Public", + "Kind": "Interface", + "Abstract": true, + "ImplementedInterfaces": [], + "Members": [ + { + "Kind": "Method", + "Name": "Pause", + "Parameters": [], + "ReturnType": "System.Void", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "Resume", + "Parameters": [], + "ReturnType": "System.Void", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "End", + "Parameters": [ + { + "Name": "endType", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ProduceEndType" + } + ], + "ReturnType": "System.Void", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.IFrameControl", + "Visibility": "Public", + "Kind": "Interface", + "Abstract": true, + "ImplementedInterfaces": [], + "Members": [ + { + "Kind": "Method", + "Name": "ProduceContinue", + "Parameters": [], + "ReturnType": "System.Void", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "Write", + "Parameters": [ + { + "Name": "data", + "Type": "System.ArraySegment" + } + ], + "ReturnType": "System.Void", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "WriteAsync", + "Parameters": [ + { + "Name": "data", + "Type": "System.ArraySegment" + }, + { + "Name": "cancellationToken", + "Type": "System.Threading.CancellationToken" + } + ], + "ReturnType": "System.Threading.Tasks.Task", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "Flush", + "Parameters": [], + "ReturnType": "System.Void", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "FlushAsync", + "Parameters": [ + { + "Name": "cancellationToken", + "Type": "System.Threading.CancellationToken" + } + ], + "ReturnType": "System.Threading.Tasks.Task", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ISocketOutput", + "Visibility": "Public", + "Kind": "Interface", + "Abstract": true, + "ImplementedInterfaces": [], + "Members": [ + { + "Kind": "Method", + "Name": "Write", + "Parameters": [ + { + "Name": "buffer", + "Type": "System.ArraySegment" + }, + { + "Name": "chunk", + "Type": "System.Boolean", + "DefaultValue": "False" + } + ], + "ReturnType": "System.Void", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "WriteAsync", + "Parameters": [ + { + "Name": "buffer", + "Type": "System.ArraySegment" + }, + { + "Name": "chunk", + "Type": "System.Boolean", + "DefaultValue": "False" + }, + { + "Name": "cancellationToken", + "Type": "System.Threading.CancellationToken", + "DefaultValue": "default(System.Threading.CancellationToken)" + } + ], + "ReturnType": "System.Threading.Tasks.Task", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "ProducingStart", + "Parameters": [], + "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolIterator", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "ProducingComplete", + "Parameters": [ + { + "Name": "end", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolIterator" + } + ], + "ReturnType": "System.Void", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.Listener", + "Visibility": "Public", + "Kind": "Class", + "Abstract": true, + "BaseType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ListenerContext", + "ImplementedInterfaces": [ + "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.IAsyncDisposable" + ], + "Members": [ + { + "Kind": "Method", + "Name": "get_ListenSocket", + "Parameters": [], + "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle", + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "StartAsync", + "Parameters": [ + { + "Name": "address", + "Type": "Microsoft.AspNetCore.Server.Kestrel.ServerAddress" + }, + { + "Name": "thread", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.KestrelThread" + } + ], + "ReturnType": "System.Threading.Tasks.Task", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "CreateListenSocket", + "Parameters": [], + "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle", + "Virtual": true, + "Abstract": true, + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "ConnectionCallback", + "Parameters": [ + { + "Name": "stream", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle" + }, + { + "Name": "status", + "Type": "System.Int32" + }, + { + "Name": "error", + "Type": "System.Exception" + }, + { + "Name": "state", + "Type": "System.Object" + } + ], + "ReturnType": "System.Void", + "Static": true, + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "OnConnection", + "Parameters": [ + { + "Name": "listenSocket", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle" + }, + { + "Name": "status", + "Type": "System.Int32" + } + ], + "ReturnType": "System.Void", + "Virtual": true, + "Abstract": true, + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "DispatchConnection", + "Parameters": [ + { + "Name": "socket", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle" + } + ], + "ReturnType": "System.Void", + "Virtual": true, + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "DisposeAsync", + "Parameters": [], + "ReturnType": "System.Threading.Tasks.Task", + "Virtual": true, + "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.IAsyncDisposable", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [ + { + "Name": "serviceContext", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.ServiceContext" + } + ], + "Visibility": "Protected", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ListenerContext", + "Visibility": "Public", + "Kind": "Class", + "BaseType": "Microsoft.AspNetCore.Server.Kestrel.Internal.ServiceContext", + "ImplementedInterfaces": [], + "Members": [ + { + "Kind": "Method", + "Name": "get_ServerAddress", + "Parameters": [], + "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.ServerAddress", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_ServerAddress", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.AspNetCore.Server.Kestrel.ServerAddress" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_Thread", + "Parameters": [], + "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.KestrelThread", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_Thread", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.KestrelThread" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_Memory", + "Parameters": [], + "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPool", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_Memory", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPool" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_ConnectionManager", + "Parameters": [], + "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ConnectionManager", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_ConnectionManager", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ConnectionManager" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_WriteReqPool", + "Parameters": [], + "ReturnType": "System.Collections.Generic.Queue", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_WriteReqPool", + "Parameters": [ + { + "Name": "value", + "Type": "System.Collections.Generic.Queue" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [], + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [ + { + "Name": "serviceContext", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.ServiceContext" + } + ], + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [ + { + "Name": "listenerContext", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ListenerContext" + } + ], + "Visibility": "Public", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ListenerPrimary", + "Visibility": "Public", + "Kind": "Class", + "Abstract": true, + "BaseType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.Listener", + "ImplementedInterfaces": [], + "Members": [ + { + "Kind": "Method", + "Name": "StartAsync", + "Parameters": [ + { + "Name": "pipeName", + "Type": "System.String" + }, + { + "Name": "address", + "Type": "Microsoft.AspNetCore.Server.Kestrel.ServerAddress" + }, + { + "Name": "thread", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.KestrelThread" + } + ], + "ReturnType": "System.Threading.Tasks.Task", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "DispatchConnection", + "Parameters": [ + { + "Name": "socket", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle" + } + ], + "ReturnType": "System.Void", + "Virtual": true, + "Override": true, + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "DisposeAsync", + "Parameters": [], + "ReturnType": "System.Threading.Tasks.Task", + "Virtual": true, + "Override": true, + "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.IAsyncDisposable", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [ + { + "Name": "serviceContext", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.ServiceContext" + } + ], + "Visibility": "Protected", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ListenerSecondary", + "Visibility": "Public", + "Kind": "Class", + "Abstract": true, + "BaseType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ListenerContext", + "ImplementedInterfaces": [ + "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.IAsyncDisposable" + ], + "Members": [ + { + "Kind": "Method", + "Name": "StartAsync", + "Parameters": [ + { + "Name": "pipeName", + "Type": "System.String" + }, + { + "Name": "address", + "Type": "Microsoft.AspNetCore.Server.Kestrel.ServerAddress" + }, + { + "Name": "thread", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.KestrelThread" + } + ], + "ReturnType": "System.Threading.Tasks.Task", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "CreateAcceptSocket", + "Parameters": [], + "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle", + "Virtual": true, + "Abstract": true, + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "DisposeAsync", + "Parameters": [], + "ReturnType": "System.Threading.Tasks.Task", + "Sealed": true, + "Virtual": true, + "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.IAsyncDisposable", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [ + { + "Name": "serviceContext", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.ServiceContext" + } + ], + "Visibility": "Protected", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.MessageBody", + "Visibility": "Public", + "Kind": "Class", + "Abstract": true, + "ImplementedInterfaces": [], + "Members": [ + { + "Kind": "Method", + "Name": "get_RequestKeepAlive", + "Parameters": [], + "ReturnType": "System.Boolean", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_RequestKeepAlive", + "Parameters": [ + { + "Name": "value", + "Type": "System.Boolean" + } + ], + "ReturnType": "System.Void", + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "ReadAsync", + "Parameters": [ + { + "Name": "buffer", + "Type": "System.ArraySegment" + }, + { + "Name": "cancellationToken", + "Type": "System.Threading.CancellationToken", + "DefaultValue": "default(System.Threading.CancellationToken)" + } + ], + "ReturnType": "System.Threading.Tasks.ValueTask", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "Consume", + "Parameters": [ + { + "Name": "cancellationToken", + "Type": "System.Threading.CancellationToken", + "DefaultValue": "default(System.Threading.CancellationToken)" + } + ], + "ReturnType": "System.Threading.Tasks.Task", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "ReadAsyncImplementation", + "Parameters": [ + { + "Name": "buffer", + "Type": "System.ArraySegment" + }, + { + "Name": "cancellationToken", + "Type": "System.Threading.CancellationToken" + } + ], + "ReturnType": "System.Threading.Tasks.ValueTask", + "Virtual": true, + "Abstract": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "For", + "Parameters": [ + { + "Name": "httpVersion", + "Type": "System.String" + }, + { + "Name": "headers", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.FrameRequestHeaders" + }, + { + "Name": "context", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.Frame" + } + ], + "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.MessageBody", + "Static": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [ + { + "Name": "context", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.Frame" + } + ], + "Visibility": "Protected", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.PathNormalizer", + "Visibility": "Public", + "Kind": "Class", + "Abstract": true, + "Static": true, + "Sealed": true, + "ImplementedInterfaces": [], + "Members": [ + { + "Kind": "Method", + "Name": "RemoveDotSegments", + "Parameters": [ + { + "Name": "path", + "Type": "System.String" + } + ], + "ReturnType": "System.String", + "Static": true, + "Visibility": "Public", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.PipeListener", + "Visibility": "Public", + "Kind": "Class", + "BaseType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.Listener", + "ImplementedInterfaces": [], + "Members": [ + { + "Kind": "Method", + "Name": "CreateListenSocket", + "Parameters": [], + "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle", + "Virtual": true, + "Override": true, + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "OnConnection", + "Parameters": [ + { + "Name": "listenSocket", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle" + }, + { + "Name": "status", + "Type": "System.Int32" + } + ], + "ReturnType": "System.Void", + "Virtual": true, + "Override": true, + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [ + { + "Name": "serviceContext", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.ServiceContext" + } + ], + "Visibility": "Public", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.PipeListenerPrimary", + "Visibility": "Public", + "Kind": "Class", + "BaseType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ListenerPrimary", + "ImplementedInterfaces": [], + "Members": [ + { + "Kind": "Method", + "Name": "CreateListenSocket", + "Parameters": [], + "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle", + "Virtual": true, + "Override": true, + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "OnConnection", + "Parameters": [ + { + "Name": "listenSocket", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle" + }, + { + "Name": "status", + "Type": "System.Int32" + } + ], + "ReturnType": "System.Void", + "Virtual": true, + "Override": true, + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [ + { + "Name": "serviceContext", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.ServiceContext" + } + ], + "Visibility": "Public", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.PipeListenerSecondary", + "Visibility": "Public", + "Kind": "Class", + "BaseType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ListenerSecondary", + "ImplementedInterfaces": [], + "Members": [ + { + "Kind": "Method", + "Name": "CreateAcceptSocket", + "Parameters": [], + "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle", + "Virtual": true, + "Override": true, + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [ + { + "Name": "serviceContext", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.ServiceContext" + } + ], + "Visibility": "Public", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ProduceEndType", + "Visibility": "Public", + "Kind": "Enumeration", + "Sealed": true, + "ImplementedInterfaces": [], + "Members": [ + { + "Kind": "Field", + "Name": "SocketShutdown", + "Parameters": [], + "GenericParameter": [], + "Literal": "0" + }, + { + "Kind": "Field", + "Name": "SocketDisconnect", + "Parameters": [], + "GenericParameter": [], + "Literal": "1" + }, + { + "Kind": "Field", + "Name": "ConnectionKeepAlive", + "Parameters": [], + "GenericParameter": [], + "Literal": "2" + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ReasonPhrases", + "Visibility": "Public", + "Kind": "Class", + "Abstract": true, + "Static": true, + "Sealed": true, + "ImplementedInterfaces": [], + "Members": [ + { + "Kind": "Method", + "Name": "ToStatusBytes", + "Parameters": [ + { + "Name": "statusCode", + "Type": "System.Int32" + }, + { + "Name": "reasonPhrase", + "Type": "System.String", + "DefaultValue": "null" + } + ], + "ReturnType": "System.Byte[]", + "Static": true, + "Visibility": "Public", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.SocketInput", + "Visibility": "Public", + "Kind": "Class", + "ImplementedInterfaces": [ + "System.Runtime.CompilerServices.ICriticalNotifyCompletion", + "System.IDisposable" + ], + "Members": [ + { + "Kind": "Method", + "Name": "get_RemoteIntakeFin", + "Parameters": [], + "ReturnType": "System.Boolean", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_RemoteIntakeFin", + "Parameters": [ + { + "Name": "value", + "Type": "System.Boolean" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_IsCompleted", + "Parameters": [], + "ReturnType": "System.Boolean", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "IncomingStart", + "Parameters": [], + "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolBlock", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "IncomingData", + "Parameters": [ + { + "Name": "buffer", + "Type": "System.Byte[]" + }, + { + "Name": "offset", + "Type": "System.Int32" + }, + { + "Name": "count", + "Type": "System.Int32" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "IncomingComplete", + "Parameters": [ + { + "Name": "count", + "Type": "System.Int32" + }, + { + "Name": "error", + "Type": "System.Exception" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "IncomingDeferred", + "Parameters": [], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "IncomingFin", + "Parameters": [], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "ConsumingStart", + "Parameters": [], + "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolIterator", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "ConsumingComplete", + "Parameters": [ + { + "Name": "consumed", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolIterator" + }, + { + "Name": "examined", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolIterator" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "CompleteAwaiting", + "Parameters": [], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "AbortAwaiting", + "Parameters": [], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "GetAwaiter", + "Parameters": [], + "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.SocketInput", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "OnCompleted", + "Parameters": [ + { + "Name": "continuation", + "Type": "System.Action" + } + ], + "ReturnType": "System.Void", + "Sealed": true, + "Virtual": true, + "ImplementedInterface": "System.Runtime.CompilerServices.INotifyCompletion", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "UnsafeOnCompleted", + "Parameters": [ + { + "Name": "continuation", + "Type": "System.Action" + } + ], + "ReturnType": "System.Void", + "Sealed": true, + "Virtual": true, + "ImplementedInterface": "System.Runtime.CompilerServices.ICriticalNotifyCompletion", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "GetResult", + "Parameters": [], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "Dispose", + "Parameters": [], + "ReturnType": "System.Void", + "Sealed": true, + "Virtual": true, + "ImplementedInterface": "System.IDisposable", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [ + { + "Name": "memory", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPool" + }, + { + "Name": "threadPool", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IThreadPool" + }, + { + "Name": "bufferSizeControl", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.IBufferSizeControl", + "DefaultValue": "null" + } + ], + "Visibility": "Public", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.SocketInputExtensions", + "Visibility": "Public", + "Kind": "Class", + "Abstract": true, + "Static": true, + "Sealed": true, + "ImplementedInterfaces": [], + "Members": [ + { + "Kind": "Method", + "Name": "ReadAsync", + "Parameters": [ + { + "Name": "input", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.SocketInput" + }, + { + "Name": "buffer", + "Type": "System.Byte[]" + }, + { + "Name": "offset", + "Type": "System.Int32" + }, + { + "Name": "count", + "Type": "System.Int32" + } + ], + "ReturnType": "System.Threading.Tasks.ValueTask", + "Static": true, + "Extension": true, + "Visibility": "Public", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.SocketOutput", + "Visibility": "Public", + "Kind": "Class", + "ImplementedInterfaces": [ + "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ISocketOutput" + ], + "Members": [ + { + "Kind": "Method", + "Name": "WriteAsync", + "Parameters": [ + { + "Name": "buffer", + "Type": "System.ArraySegment" + }, + { + "Name": "cancellationToken", + "Type": "System.Threading.CancellationToken" + }, + { + "Name": "chunk", + "Type": "System.Boolean", + "DefaultValue": "False" + }, + { + "Name": "socketShutdownSend", + "Type": "System.Boolean", + "DefaultValue": "False" + }, + { + "Name": "socketDisconnect", + "Type": "System.Boolean", + "DefaultValue": "False" + }, + { + "Name": "isSync", + "Type": "System.Boolean", + "DefaultValue": "False" + } + ], + "ReturnType": "System.Threading.Tasks.Task", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "End", + "Parameters": [ + { + "Name": "endType", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ProduceEndType" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "ProducingStart", + "Parameters": [], + "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolIterator", + "Sealed": true, + "Virtual": true, + "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ISocketOutput", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "ProducingComplete", + "Parameters": [ + { + "Name": "end", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolIterator" + } + ], + "ReturnType": "System.Void", + "Sealed": true, + "Virtual": true, + "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ISocketOutput", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [ + { + "Name": "thread", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.KestrelThread" + }, + { + "Name": "socket", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle" + }, + { + "Name": "memory", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPool" + }, + { + "Name": "connection", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.Connection" + }, + { + "Name": "connectionId", + "Type": "System.String" + }, + { + "Name": "log", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IKestrelTrace" + }, + { + "Name": "threadPool", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IThreadPool" + }, + { + "Name": "writeReqPool", + "Type": "System.Collections.Generic.Queue" + } + ], + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Field", + "Name": "MaxPooledWriteReqs", + "Parameters": [], + "ReturnType": "System.Int32", + "Static": true, + "Visibility": "Public", + "GenericParameter": [], + "Constant": true, + "Literal": "1024" + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.TcpListener", + "Visibility": "Public", + "Kind": "Class", + "BaseType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.Listener", + "ImplementedInterfaces": [], + "Members": [ + { + "Kind": "Method", + "Name": "CreateListenSocket", + "Parameters": [], + "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle", + "Virtual": true, + "Override": true, + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "OnConnection", + "Parameters": [ + { + "Name": "listenSocket", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle" + }, + { + "Name": "status", + "Type": "System.Int32" + } + ], + "ReturnType": "System.Void", + "Virtual": true, + "Override": true, + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [ + { + "Name": "serviceContext", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.ServiceContext" + } + ], + "Visibility": "Public", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.TcpListenerPrimary", + "Visibility": "Public", + "Kind": "Class", + "BaseType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ListenerPrimary", + "ImplementedInterfaces": [], + "Members": [ + { + "Kind": "Method", + "Name": "CreateListenSocket", + "Parameters": [], + "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle", + "Virtual": true, + "Override": true, + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "OnConnection", + "Parameters": [ + { + "Name": "listenSocket", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle" + }, + { + "Name": "status", + "Type": "System.Int32" + } + ], + "ReturnType": "System.Void", + "Virtual": true, + "Override": true, + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [ + { + "Name": "serviceContext", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.ServiceContext" + } + ], + "Visibility": "Public", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.TcpListenerSecondary", + "Visibility": "Public", + "Kind": "Class", + "BaseType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ListenerSecondary", + "ImplementedInterfaces": [], + "Members": [ + { + "Kind": "Method", + "Name": "CreateAcceptSocket", + "Parameters": [], + "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle", + "Virtual": true, + "Override": true, + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [ + { + "Name": "serviceContext", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.ServiceContext" + } + ], + "Visibility": "Public", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.UrlPathDecoder", + "Visibility": "Public", + "Kind": "Class", + "ImplementedInterfaces": [], + "Members": [ + { + "Kind": "Method", + "Name": "Unescape", + "Parameters": [ + { + "Name": "start", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolIterator" + }, + { + "Name": "end", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolIterator" + } + ], + "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolIterator", + "Static": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [], + "Visibility": "Public", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Filter.ConnectionFilterContext", + "Visibility": "Public", + "Kind": "Class", + "ImplementedInterfaces": [], + "Members": [ + { + "Kind": "Method", + "Name": "get_Address", + "Parameters": [], + "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.ServerAddress", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_Address", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.AspNetCore.Server.Kestrel.ServerAddress" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_Connection", + "Parameters": [], + "ReturnType": "System.IO.Stream", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_Connection", + "Parameters": [ + { + "Name": "value", + "Type": "System.IO.Stream" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_PrepareRequest", + "Parameters": [], + "ReturnType": "System.Action", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_PrepareRequest", + "Parameters": [ + { + "Name": "value", + "Type": "System.Action" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [], + "Visibility": "Public", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Filter.IConnectionFilter", + "Visibility": "Public", + "Kind": "Interface", + "Abstract": true, + "ImplementedInterfaces": [], + "Members": [ + { + "Kind": "Method", + "Name": "OnConnectionAsync", + "Parameters": [ + { + "Name": "context", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Filter.ConnectionFilterContext" + } + ], + "ReturnType": "System.Threading.Tasks.Task", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Filter.LoggingConnectionFilter", + "Visibility": "Public", + "Kind": "Class", + "ImplementedInterfaces": [ + "Microsoft.AspNetCore.Server.Kestrel.Filter.IConnectionFilter" + ], + "Members": [ + { + "Kind": "Method", + "Name": "OnConnectionAsync", + "Parameters": [ + { + "Name": "context", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Filter.ConnectionFilterContext" + } + ], + "ReturnType": "System.Threading.Tasks.Task", + "Sealed": true, + "Virtual": true, + "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Filter.IConnectionFilter", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [ + { + "Name": "logger", + "Type": "Microsoft.Extensions.Logging.ILogger" + }, + { + "Name": "previous", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Filter.IConnectionFilter" + } + ], + "Visibility": "Public", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Filter.NoOpConnectionFilter", + "Visibility": "Public", + "Kind": "Class", + "ImplementedInterfaces": [ + "Microsoft.AspNetCore.Server.Kestrel.Filter.IConnectionFilter" + ], + "Members": [ + { + "Kind": "Method", + "Name": "OnConnectionAsync", + "Parameters": [ + { + "Name": "context", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Filter.ConnectionFilterContext" + } + ], + "ReturnType": "System.Threading.Tasks.Task", + "Sealed": true, + "Virtual": true, + "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Filter.IConnectionFilter", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [], + "Visibility": "Public", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Filter.Internal.FilteredStreamAdapter", + "Visibility": "Public", + "Kind": "Class", + "ImplementedInterfaces": [ + "System.IDisposable" + ], + "Members": [ + { + "Kind": "Method", + "Name": "get_SocketInput", + "Parameters": [], + "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.SocketInput", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_SocketOutput", + "Parameters": [], + "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ISocketOutput", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "ReadInputAsync", + "Parameters": [], + "ReturnType": "System.Threading.Tasks.Task", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "Abort", + "Parameters": [], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "Dispose", + "Parameters": [], + "ReturnType": "System.Void", + "Sealed": true, + "Virtual": true, + "ImplementedInterface": "System.IDisposable", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [ + { + "Name": "connectionId", + "Type": "System.String" + }, + { + "Name": "filteredStream", + "Type": "System.IO.Stream" + }, + { + "Name": "memory", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPool" + }, + { + "Name": "logger", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IKestrelTrace" + }, + { + "Name": "threadPool", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IThreadPool" + }, + { + "Name": "bufferSizeControl", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.IBufferSizeControl" + } + ], + "Visibility": "Public", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Filter.Internal.LibuvStream", + "Visibility": "Public", + "Kind": "Class", + "BaseType": "System.IO.Stream", + "ImplementedInterfaces": [], + "Members": [ + { + "Kind": "Method", + "Name": "get_CanRead", + "Parameters": [], + "ReturnType": "System.Boolean", + "Virtual": true, + "Override": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_CanSeek", + "Parameters": [], + "ReturnType": "System.Boolean", + "Virtual": true, + "Override": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_CanWrite", + "Parameters": [], + "ReturnType": "System.Boolean", + "Virtual": true, + "Override": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_Length", + "Parameters": [], + "ReturnType": "System.Int64", + "Virtual": true, + "Override": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_Position", + "Parameters": [], + "ReturnType": "System.Int64", + "Virtual": true, + "Override": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_Position", + "Parameters": [ + { + "Name": "value", + "Type": "System.Int64" + } + ], + "ReturnType": "System.Void", + "Virtual": true, + "Override": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "Seek", + "Parameters": [ + { + "Name": "offset", + "Type": "System.Int64" + }, + { + "Name": "origin", + "Type": "System.IO.SeekOrigin" + } + ], + "ReturnType": "System.Int64", + "Virtual": true, + "Override": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "SetLength", + "Parameters": [ + { + "Name": "value", + "Type": "System.Int64" + } + ], + "ReturnType": "System.Void", + "Virtual": true, + "Override": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "Read", + "Parameters": [ + { + "Name": "buffer", + "Type": "System.Byte[]" + }, + { + "Name": "offset", + "Type": "System.Int32" + }, + { + "Name": "count", + "Type": "System.Int32" + } + ], + "ReturnType": "System.Int32", + "Virtual": true, + "Override": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "ReadAsync", + "Parameters": [ + { + "Name": "buffer", + "Type": "System.Byte[]" + }, + { + "Name": "offset", + "Type": "System.Int32" + }, + { + "Name": "count", + "Type": "System.Int32" + }, + { + "Name": "cancellationToken", + "Type": "System.Threading.CancellationToken" + } + ], + "ReturnType": "System.Threading.Tasks.Task", + "Virtual": true, + "Override": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "Write", + "Parameters": [ + { + "Name": "buffer", + "Type": "System.Byte[]" + }, + { + "Name": "offset", + "Type": "System.Int32" + }, + { + "Name": "count", + "Type": "System.Int32" + } + ], + "ReturnType": "System.Void", + "Virtual": true, + "Override": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "WriteAsync", + "Parameters": [ + { + "Name": "buffer", + "Type": "System.Byte[]" + }, + { + "Name": "offset", + "Type": "System.Int32" + }, + { + "Name": "count", + "Type": "System.Int32" + }, + { + "Name": "token", + "Type": "System.Threading.CancellationToken" + } + ], + "ReturnType": "System.Threading.Tasks.Task", + "Virtual": true, + "Override": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "Flush", + "Parameters": [], + "ReturnType": "System.Void", + "Virtual": true, + "Override": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "FlushAsync", + "Parameters": [ + { + "Name": "cancellationToken", + "Type": "System.Threading.CancellationToken" + } + ], + "ReturnType": "System.Threading.Tasks.Task", + "Virtual": true, + "Override": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [ + { + "Name": "input", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.SocketInput" + }, + { + "Name": "output", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ISocketOutput" + } + ], + "Visibility": "Public", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Filter.Internal.StreamSocketOutput", + "Visibility": "Public", + "Kind": "Class", + "ImplementedInterfaces": [ + "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ISocketOutput" + ], + "Members": [ + { + "Kind": "Method", + "Name": "Write", + "Parameters": [ + { + "Name": "buffer", + "Type": "System.ArraySegment" + }, + { + "Name": "chunk", + "Type": "System.Boolean" + } + ], + "ReturnType": "System.Void", + "Sealed": true, + "Virtual": true, + "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ISocketOutput", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "WriteAsync", + "Parameters": [ + { + "Name": "buffer", + "Type": "System.ArraySegment" + }, + { + "Name": "chunk", + "Type": "System.Boolean" + }, + { + "Name": "cancellationToken", + "Type": "System.Threading.CancellationToken" + } + ], + "ReturnType": "System.Threading.Tasks.Task", + "Sealed": true, + "Virtual": true, + "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ISocketOutput", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "ProducingStart", + "Parameters": [], + "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolIterator", + "Sealed": true, + "Virtual": true, + "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ISocketOutput", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "ProducingComplete", + "Parameters": [ + { + "Name": "end", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolIterator" + } + ], + "ReturnType": "System.Void", + "Sealed": true, + "Virtual": true, + "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ISocketOutput", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [ + { + "Name": "connectionId", + "Type": "System.String" + }, + { + "Name": "outputStream", + "Type": "System.IO.Stream" + }, + { + "Name": "memory", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPool" + }, + { + "Name": "logger", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IKestrelTrace" + } + ], + "Visibility": "Public", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_fileno_func", + "Visibility": "Protected", + "Kind": "Class", + "Sealed": true, + "BaseType": "System.MulticastDelegate", + "ImplementedInterfaces": [], + "Members": [ + { + "Kind": "Method", + "Name": "Invoke", + "Parameters": [ + { + "Name": "handle", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvHandle" + }, + { + "Name": "socket", + "Type": "System.IntPtr", + "Direction": "Ref" + } + ], + "ReturnType": "System.Int32", + "Virtual": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "BeginInvoke", + "Parameters": [ + { + "Name": "handle", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvHandle" + }, + { + "Name": "socket", + "Type": "System.IntPtr", + "Direction": "Ref" + }, + { + "Name": "callback", + "Type": "System.AsyncCallback" + }, + { + "Name": "object", + "Type": "System.Object" + } + ], + "ReturnType": "System.IAsyncResult", + "Virtual": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "EndInvoke", + "Parameters": [ + { + "Name": "socket", + "Type": "System.IntPtr", + "Direction": "Ref" + }, + { + "Name": "result", + "Type": "System.IAsyncResult" + } + ], + "ReturnType": "System.Int32", + "Virtual": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [ + { + "Name": "object", + "Type": "System.Object" + }, + { + "Name": "method", + "Type": "System.IntPtr" + } + ], + "Visibility": "Public", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_close_cb", + "Visibility": "Public", + "Kind": "Class", + "Sealed": true, + "BaseType": "System.MulticastDelegate", + "ImplementedInterfaces": [], + "Members": [ + { + "Kind": "Method", + "Name": "Invoke", + "Parameters": [ + { + "Name": "handle", + "Type": "System.IntPtr" + } + ], + "ReturnType": "System.Void", + "Virtual": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "BeginInvoke", + "Parameters": [ + { + "Name": "handle", + "Type": "System.IntPtr" + }, + { + "Name": "callback", + "Type": "System.AsyncCallback" + }, + { + "Name": "object", + "Type": "System.Object" + } + ], + "ReturnType": "System.IAsyncResult", + "Virtual": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "EndInvoke", + "Parameters": [ + { + "Name": "result", + "Type": "System.IAsyncResult" + } + ], + "ReturnType": "System.Void", + "Virtual": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [ + { + "Name": "object", + "Type": "System.Object" + }, + { + "Name": "method", + "Type": "System.IntPtr" + } + ], + "Visibility": "Public", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_async_cb", + "Visibility": "Public", + "Kind": "Class", + "Sealed": true, + "BaseType": "System.MulticastDelegate", + "ImplementedInterfaces": [], + "Members": [ + { + "Kind": "Method", + "Name": "Invoke", + "Parameters": [ + { + "Name": "handle", + "Type": "System.IntPtr" + } + ], + "ReturnType": "System.Void", + "Virtual": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "BeginInvoke", + "Parameters": [ + { + "Name": "handle", + "Type": "System.IntPtr" + }, + { + "Name": "callback", + "Type": "System.AsyncCallback" + }, + { + "Name": "object", + "Type": "System.Object" + } + ], + "ReturnType": "System.IAsyncResult", + "Virtual": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "EndInvoke", + "Parameters": [ + { + "Name": "result", + "Type": "System.IAsyncResult" + } + ], + "ReturnType": "System.Void", + "Virtual": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [ + { + "Name": "object", + "Type": "System.Object" + }, + { + "Name": "method", + "Type": "System.IntPtr" + } + ], + "Visibility": "Public", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_tcp_bind_func", + "Visibility": "Protected", + "Kind": "Class", + "Sealed": true, + "BaseType": "System.MulticastDelegate", + "ImplementedInterfaces": [], + "Members": [ + { + "Kind": "Method", + "Name": "Invoke", + "Parameters": [ + { + "Name": "handle", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvTcpHandle" + }, + { + "Name": "addr", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.SockAddr", + "Direction": "Ref" + }, + { + "Name": "flags", + "Type": "System.Int32" + } + ], + "ReturnType": "System.Int32", + "Virtual": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "BeginInvoke", + "Parameters": [ + { + "Name": "handle", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvTcpHandle" + }, + { + "Name": "addr", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.SockAddr", + "Direction": "Ref" + }, + { + "Name": "flags", + "Type": "System.Int32" + }, + { + "Name": "callback", + "Type": "System.AsyncCallback" + }, + { + "Name": "object", + "Type": "System.Object" + } + ], + "ReturnType": "System.IAsyncResult", + "Virtual": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "EndInvoke", + "Parameters": [ + { + "Name": "addr", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.SockAddr", + "Direction": "Ref" + }, + { + "Name": "result", + "Type": "System.IAsyncResult" + } + ], + "ReturnType": "System.Int32", + "Virtual": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [ + { + "Name": "object", + "Type": "System.Object" + }, + { + "Name": "method", + "Type": "System.IntPtr" + } + ], + "Visibility": "Public", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_connection_cb", + "Visibility": "Public", + "Kind": "Class", + "Sealed": true, + "BaseType": "System.MulticastDelegate", + "ImplementedInterfaces": [], + "Members": [ + { + "Kind": "Method", + "Name": "Invoke", + "Parameters": [ + { + "Name": "server", + "Type": "System.IntPtr" + }, + { + "Name": "status", + "Type": "System.Int32" + } + ], + "ReturnType": "System.Void", + "Virtual": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "BeginInvoke", + "Parameters": [ + { + "Name": "server", + "Type": "System.IntPtr" + }, + { + "Name": "status", + "Type": "System.Int32" + }, + { + "Name": "callback", + "Type": "System.AsyncCallback" + }, + { + "Name": "object", + "Type": "System.Object" + } + ], + "ReturnType": "System.IAsyncResult", + "Virtual": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "EndInvoke", + "Parameters": [ + { + "Name": "result", + "Type": "System.IAsyncResult" + } + ], + "ReturnType": "System.Void", + "Virtual": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [ + { + "Name": "object", + "Type": "System.Object" + }, + { + "Name": "method", + "Type": "System.IntPtr" + } + ], + "Visibility": "Public", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_connect_cb", + "Visibility": "Public", + "Kind": "Class", + "Sealed": true, + "BaseType": "System.MulticastDelegate", + "ImplementedInterfaces": [], + "Members": [ + { + "Kind": "Method", + "Name": "Invoke", + "Parameters": [ + { + "Name": "req", + "Type": "System.IntPtr" + }, + { + "Name": "status", + "Type": "System.Int32" + } + ], + "ReturnType": "System.Void", + "Virtual": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "BeginInvoke", + "Parameters": [ + { + "Name": "req", + "Type": "System.IntPtr" + }, + { + "Name": "status", + "Type": "System.Int32" + }, + { + "Name": "callback", + "Type": "System.AsyncCallback" + }, + { + "Name": "object", + "Type": "System.Object" + } + ], + "ReturnType": "System.IAsyncResult", + "Virtual": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "EndInvoke", + "Parameters": [ + { + "Name": "result", + "Type": "System.IAsyncResult" + } + ], + "ReturnType": "System.Void", + "Virtual": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [ + { + "Name": "object", + "Type": "System.Object" + }, + { + "Name": "method", + "Type": "System.IntPtr" + } + ], + "Visibility": "Public", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_alloc_cb", + "Visibility": "Public", + "Kind": "Class", + "Sealed": true, + "BaseType": "System.MulticastDelegate", + "ImplementedInterfaces": [], + "Members": [ + { + "Kind": "Method", + "Name": "Invoke", + "Parameters": [ + { + "Name": "server", + "Type": "System.IntPtr" + }, + { + "Name": "suggested_size", + "Type": "System.Int32" + }, + { + "Name": "buf", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_buf_t", + "Direction": "Out" + } + ], + "ReturnType": "System.Void", + "Virtual": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "BeginInvoke", + "Parameters": [ + { + "Name": "server", + "Type": "System.IntPtr" + }, + { + "Name": "suggested_size", + "Type": "System.Int32" + }, + { + "Name": "buf", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_buf_t", + "Direction": "Out" + }, + { + "Name": "callback", + "Type": "System.AsyncCallback" + }, + { + "Name": "object", + "Type": "System.Object" + } + ], + "ReturnType": "System.IAsyncResult", + "Virtual": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "EndInvoke", + "Parameters": [ + { + "Name": "buf", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_buf_t", + "Direction": "Out" + }, + { + "Name": "result", + "Type": "System.IAsyncResult" + } + ], + "ReturnType": "System.Void", + "Virtual": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [ + { + "Name": "object", + "Type": "System.Object" + }, + { + "Name": "method", + "Type": "System.IntPtr" + } + ], + "Visibility": "Public", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_read_cb", + "Visibility": "Public", + "Kind": "Class", + "Sealed": true, + "BaseType": "System.MulticastDelegate", + "ImplementedInterfaces": [], + "Members": [ + { + "Kind": "Method", + "Name": "Invoke", + "Parameters": [ + { + "Name": "server", + "Type": "System.IntPtr" + }, + { + "Name": "nread", + "Type": "System.Int32" + }, + { + "Name": "buf", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_buf_t", + "Direction": "Ref" + } + ], + "ReturnType": "System.Void", + "Virtual": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "BeginInvoke", + "Parameters": [ + { + "Name": "server", + "Type": "System.IntPtr" + }, + { + "Name": "nread", + "Type": "System.Int32" + }, + { + "Name": "buf", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_buf_t", + "Direction": "Ref" + }, + { + "Name": "callback", + "Type": "System.AsyncCallback" + }, + { + "Name": "object", + "Type": "System.Object" + } + ], + "ReturnType": "System.IAsyncResult", + "Virtual": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "EndInvoke", + "Parameters": [ + { + "Name": "buf", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_buf_t", + "Direction": "Ref" + }, + { + "Name": "result", + "Type": "System.IAsyncResult" + } + ], + "ReturnType": "System.Void", + "Virtual": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [ + { + "Name": "object", + "Type": "System.Object" + }, + { + "Name": "method", + "Type": "System.IntPtr" + } + ], + "Visibility": "Public", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_write_cb", + "Visibility": "Public", + "Kind": "Class", + "Sealed": true, + "BaseType": "System.MulticastDelegate", + "ImplementedInterfaces": [], + "Members": [ + { + "Kind": "Method", + "Name": "Invoke", + "Parameters": [ + { + "Name": "req", + "Type": "System.IntPtr" + }, + { + "Name": "status", + "Type": "System.Int32" + } + ], + "ReturnType": "System.Void", + "Virtual": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "BeginInvoke", + "Parameters": [ + { + "Name": "req", + "Type": "System.IntPtr" + }, + { + "Name": "status", + "Type": "System.Int32" + }, + { + "Name": "callback", + "Type": "System.AsyncCallback" + }, + { + "Name": "object", + "Type": "System.Object" + } + ], + "ReturnType": "System.IAsyncResult", + "Virtual": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "EndInvoke", + "Parameters": [ + { + "Name": "result", + "Type": "System.IAsyncResult" + } + ], + "ReturnType": "System.Void", + "Virtual": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [ + { + "Name": "object", + "Type": "System.Object" + }, + { + "Name": "method", + "Type": "System.IntPtr" + } + ], + "Visibility": "Public", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_write_func", + "Visibility": "Protected", + "Kind": "Class", + "Sealed": true, + "BaseType": "System.MulticastDelegate", + "ImplementedInterfaces": [], + "Members": [ + { + "Kind": "Method", + "Name": "Invoke", + "Parameters": [ + { + "Name": "req", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvRequest" + }, + { + "Name": "handle", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle" + }, + { + "Name": "bufs", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_buf_t*" + }, + { + "Name": "nbufs", + "Type": "System.Int32" + }, + { + "Name": "cb", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_write_cb" + } + ], + "ReturnType": "System.Int32", + "Virtual": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "BeginInvoke", + "Parameters": [ + { + "Name": "req", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvRequest" + }, + { + "Name": "handle", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle" + }, + { + "Name": "bufs", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_buf_t*" + }, + { + "Name": "nbufs", + "Type": "System.Int32" + }, + { + "Name": "cb", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_write_cb" + }, + { + "Name": "callback", + "Type": "System.AsyncCallback" + }, + { + "Name": "object", + "Type": "System.Object" + } + ], + "ReturnType": "System.IAsyncResult", + "Virtual": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "EndInvoke", + "Parameters": [ + { + "Name": "result", + "Type": "System.IAsyncResult" + } + ], + "ReturnType": "System.Int32", + "Virtual": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [ + { + "Name": "object", + "Type": "System.Object" + }, + { + "Name": "method", + "Type": "System.IntPtr" + } + ], + "Visibility": "Public", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_write2_func", + "Visibility": "Protected", + "Kind": "Class", + "Sealed": true, + "BaseType": "System.MulticastDelegate", + "ImplementedInterfaces": [], + "Members": [ + { + "Kind": "Method", + "Name": "Invoke", + "Parameters": [ + { + "Name": "req", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvRequest" + }, + { + "Name": "handle", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle" + }, + { + "Name": "bufs", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_buf_t*" + }, + { + "Name": "nbufs", + "Type": "System.Int32" + }, + { + "Name": "sendHandle", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle" + }, + { + "Name": "cb", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_write_cb" + } + ], + "ReturnType": "System.Int32", + "Virtual": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "BeginInvoke", + "Parameters": [ + { + "Name": "req", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvRequest" + }, + { + "Name": "handle", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle" + }, + { + "Name": "bufs", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_buf_t*" + }, + { + "Name": "nbufs", + "Type": "System.Int32" + }, + { + "Name": "sendHandle", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle" + }, + { + "Name": "cb", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_write_cb" + }, + { + "Name": "callback", + "Type": "System.AsyncCallback" + }, + { + "Name": "object", + "Type": "System.Object" + } + ], + "ReturnType": "System.IAsyncResult", + "Virtual": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "EndInvoke", + "Parameters": [ + { + "Name": "result", + "Type": "System.IAsyncResult" + } + ], + "ReturnType": "System.Int32", + "Virtual": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [ + { + "Name": "object", + "Type": "System.Object" + }, + { + "Name": "method", + "Type": "System.IntPtr" + } + ], + "Visibility": "Public", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_shutdown_cb", + "Visibility": "Public", + "Kind": "Class", + "Sealed": true, + "BaseType": "System.MulticastDelegate", + "ImplementedInterfaces": [], + "Members": [ + { + "Kind": "Method", + "Name": "Invoke", + "Parameters": [ + { + "Name": "req", + "Type": "System.IntPtr" + }, + { + "Name": "status", + "Type": "System.Int32" + } + ], + "ReturnType": "System.Void", + "Virtual": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "BeginInvoke", + "Parameters": [ + { + "Name": "req", + "Type": "System.IntPtr" + }, + { + "Name": "status", + "Type": "System.Int32" + }, + { + "Name": "callback", + "Type": "System.AsyncCallback" + }, + { + "Name": "object", + "Type": "System.Object" + } + ], + "ReturnType": "System.IAsyncResult", + "Virtual": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "EndInvoke", + "Parameters": [ + { + "Name": "result", + "Type": "System.IAsyncResult" + } + ], + "ReturnType": "System.Void", + "Virtual": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [ + { + "Name": "object", + "Type": "System.Object" + }, + { + "Name": "method", + "Type": "System.IntPtr" + } + ], + "Visibility": "Public", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_ip4_addr_func", + "Visibility": "Protected", + "Kind": "Class", + "Sealed": true, + "BaseType": "System.MulticastDelegate", + "ImplementedInterfaces": [], + "Members": [ + { + "Kind": "Method", + "Name": "Invoke", + "Parameters": [ + { + "Name": "ip", + "Type": "System.String" + }, + { + "Name": "port", + "Type": "System.Int32" + }, + { + "Name": "addr", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.SockAddr", + "Direction": "Out" + } + ], + "ReturnType": "System.Int32", + "Virtual": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "BeginInvoke", + "Parameters": [ + { + "Name": "ip", + "Type": "System.String" + }, + { + "Name": "port", + "Type": "System.Int32" + }, + { + "Name": "addr", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.SockAddr", + "Direction": "Out" + }, + { + "Name": "callback", + "Type": "System.AsyncCallback" + }, + { + "Name": "object", + "Type": "System.Object" + } + ], + "ReturnType": "System.IAsyncResult", + "Virtual": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "EndInvoke", + "Parameters": [ + { + "Name": "addr", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.SockAddr", + "Direction": "Out" + }, + { + "Name": "result", + "Type": "System.IAsyncResult" + } + ], + "ReturnType": "System.Int32", + "Virtual": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [ + { + "Name": "object", + "Type": "System.Object" + }, + { + "Name": "method", + "Type": "System.IntPtr" + } + ], + "Visibility": "Public", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_ip6_addr_func", + "Visibility": "Protected", + "Kind": "Class", + "Sealed": true, + "BaseType": "System.MulticastDelegate", + "ImplementedInterfaces": [], + "Members": [ + { + "Kind": "Method", + "Name": "Invoke", + "Parameters": [ + { + "Name": "ip", + "Type": "System.String" + }, + { + "Name": "port", + "Type": "System.Int32" + }, + { + "Name": "addr", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.SockAddr", + "Direction": "Out" + } + ], + "ReturnType": "System.Int32", + "Virtual": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "BeginInvoke", + "Parameters": [ + { + "Name": "ip", + "Type": "System.String" + }, + { + "Name": "port", + "Type": "System.Int32" + }, + { + "Name": "addr", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.SockAddr", + "Direction": "Out" + }, + { + "Name": "callback", + "Type": "System.AsyncCallback" + }, + { + "Name": "object", + "Type": "System.Object" + } + ], + "ReturnType": "System.IAsyncResult", + "Virtual": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "EndInvoke", + "Parameters": [ + { + "Name": "addr", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.SockAddr", + "Direction": "Out" + }, + { + "Name": "result", + "Type": "System.IAsyncResult" + } + ], + "ReturnType": "System.Int32", + "Virtual": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [ + { + "Name": "object", + "Type": "System.Object" + }, + { + "Name": "method", + "Type": "System.IntPtr" + } + ], + "Visibility": "Public", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_walk_cb", + "Visibility": "Public", + "Kind": "Class", + "Sealed": true, + "BaseType": "System.MulticastDelegate", + "ImplementedInterfaces": [], + "Members": [ + { + "Kind": "Method", + "Name": "Invoke", + "Parameters": [ + { + "Name": "handle", + "Type": "System.IntPtr" + }, + { + "Name": "arg", + "Type": "System.IntPtr" + } + ], + "ReturnType": "System.Void", + "Virtual": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "BeginInvoke", + "Parameters": [ + { + "Name": "handle", + "Type": "System.IntPtr" + }, + { + "Name": "arg", + "Type": "System.IntPtr" + }, + { + "Name": "callback", + "Type": "System.AsyncCallback" + }, + { + "Name": "object", + "Type": "System.Object" + } + ], + "ReturnType": "System.IAsyncResult", + "Virtual": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "EndInvoke", + "Parameters": [ + { + "Name": "result", + "Type": "System.IAsyncResult" + } + ], + "ReturnType": "System.Void", + "Virtual": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [ + { + "Name": "object", + "Type": "System.Object" + }, + { + "Name": "method", + "Type": "System.IntPtr" + } + ], + "Visibility": "Public", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_tcp_getsockname_func", + "Visibility": "Public", + "Kind": "Class", + "Sealed": true, + "BaseType": "System.MulticastDelegate", + "ImplementedInterfaces": [], + "Members": [ + { + "Kind": "Method", + "Name": "Invoke", + "Parameters": [ + { + "Name": "handle", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvTcpHandle" + }, + { + "Name": "addr", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.SockAddr", + "Direction": "Out" + }, + { + "Name": "namelen", + "Type": "System.Int32", + "Direction": "Ref" + } + ], + "ReturnType": "System.Int32", + "Virtual": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "BeginInvoke", + "Parameters": [ + { + "Name": "handle", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvTcpHandle" + }, + { + "Name": "addr", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.SockAddr", + "Direction": "Out" + }, + { + "Name": "namelen", + "Type": "System.Int32", + "Direction": "Ref" + }, + { + "Name": "callback", + "Type": "System.AsyncCallback" + }, + { + "Name": "object", + "Type": "System.Object" + } + ], + "ReturnType": "System.IAsyncResult", + "Virtual": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "EndInvoke", + "Parameters": [ + { + "Name": "addr", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.SockAddr", + "Direction": "Out" + }, + { + "Name": "namelen", + "Type": "System.Int32", + "Direction": "Ref" + }, + { + "Name": "result", + "Type": "System.IAsyncResult" + } + ], + "ReturnType": "System.Int32", + "Virtual": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [ + { + "Name": "object", + "Type": "System.Object" + }, + { + "Name": "method", + "Type": "System.IntPtr" + } + ], + "Visibility": "Public", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_tcp_getpeername_func", + "Visibility": "Public", + "Kind": "Class", + "Sealed": true, + "BaseType": "System.MulticastDelegate", + "ImplementedInterfaces": [], + "Members": [ + { + "Kind": "Method", + "Name": "Invoke", + "Parameters": [ + { + "Name": "handle", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvTcpHandle" + }, + { + "Name": "addr", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.SockAddr", + "Direction": "Out" + }, + { + "Name": "namelen", + "Type": "System.Int32", + "Direction": "Ref" + } + ], + "ReturnType": "System.Int32", + "Virtual": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "BeginInvoke", + "Parameters": [ + { + "Name": "handle", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvTcpHandle" + }, + { + "Name": "addr", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.SockAddr", + "Direction": "Out" + }, + { + "Name": "namelen", + "Type": "System.Int32", + "Direction": "Ref" + }, + { + "Name": "callback", + "Type": "System.AsyncCallback" + }, + { + "Name": "object", + "Type": "System.Object" + } + ], + "ReturnType": "System.IAsyncResult", + "Virtual": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "EndInvoke", + "Parameters": [ + { + "Name": "addr", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.SockAddr", + "Direction": "Out" + }, + { + "Name": "namelen", + "Type": "System.Int32", + "Direction": "Ref" + }, + { + "Name": "result", + "Type": "System.IAsyncResult" + } + ], + "ReturnType": "System.Int32", + "Virtual": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [ + { + "Name": "object", + "Type": "System.Object" + }, + { + "Name": "method", + "Type": "System.IntPtr" + } + ], + "Visibility": "Public", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_buf_t", + "Visibility": "Public", + "Kind": "Struct", + "Sealed": true, + "ImplementedInterfaces": [], + "Members": [ + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [ + { + "Name": "memory", + "Type": "System.IntPtr" + }, + { + "Name": "len", + "Type": "System.Int32" + }, + { + "Name": "IsWindows", + "Type": "System.Boolean" + } + ], + "Visibility": "Public", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+HandleType", + "Visibility": "Public", + "Kind": "Enumeration", + "Sealed": true, + "ImplementedInterfaces": [], + "Members": [ + { + "Kind": "Field", + "Name": "Unknown", + "Parameters": [], + "GenericParameter": [], + "Literal": "0" + }, + { + "Kind": "Field", + "Name": "ASYNC", + "Parameters": [], + "GenericParameter": [], + "Literal": "1" + }, + { + "Kind": "Field", + "Name": "CHECK", + "Parameters": [], + "GenericParameter": [], + "Literal": "2" + }, + { + "Kind": "Field", + "Name": "FS_EVENT", + "Parameters": [], + "GenericParameter": [], + "Literal": "3" + }, + { + "Kind": "Field", + "Name": "FS_POLL", + "Parameters": [], + "GenericParameter": [], + "Literal": "4" + }, + { + "Kind": "Field", + "Name": "HANDLE", + "Parameters": [], + "GenericParameter": [], + "Literal": "5" + }, + { + "Kind": "Field", + "Name": "IDLE", + "Parameters": [], + "GenericParameter": [], + "Literal": "6" + }, + { + "Kind": "Field", + "Name": "NAMED_PIPE", + "Parameters": [], + "GenericParameter": [], + "Literal": "7" + }, + { + "Kind": "Field", + "Name": "POLL", + "Parameters": [], + "GenericParameter": [], + "Literal": "8" + }, + { + "Kind": "Field", + "Name": "PREPARE", + "Parameters": [], + "GenericParameter": [], + "Literal": "9" + }, + { + "Kind": "Field", + "Name": "PROCESS", + "Parameters": [], + "GenericParameter": [], + "Literal": "10" + }, + { + "Kind": "Field", + "Name": "STREAM", + "Parameters": [], + "GenericParameter": [], + "Literal": "11" + }, + { + "Kind": "Field", + "Name": "TCP", + "Parameters": [], + "GenericParameter": [], + "Literal": "12" + }, + { + "Kind": "Field", + "Name": "TIMER", + "Parameters": [], + "GenericParameter": [], + "Literal": "13" + }, + { + "Kind": "Field", + "Name": "TTY", + "Parameters": [], + "GenericParameter": [], + "Literal": "14" + }, + { + "Kind": "Field", + "Name": "UDP", + "Parameters": [], + "GenericParameter": [], + "Literal": "15" + }, + { + "Kind": "Field", + "Name": "SIGNAL", + "Parameters": [], + "GenericParameter": [], + "Literal": "16" + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+RequestType", + "Visibility": "Public", + "Kind": "Enumeration", + "Sealed": true, + "ImplementedInterfaces": [], + "Members": [ + { + "Kind": "Field", + "Name": "Unknown", + "Parameters": [], + "GenericParameter": [], + "Literal": "0" + }, + { + "Kind": "Field", + "Name": "REQ", + "Parameters": [], + "GenericParameter": [], + "Literal": "1" + }, + { + "Kind": "Field", + "Name": "CONNECT", + "Parameters": [], + "GenericParameter": [], + "Literal": "2" + }, + { + "Kind": "Field", + "Name": "WRITE", + "Parameters": [], + "GenericParameter": [], + "Literal": "3" + }, + { + "Kind": "Field", + "Name": "SHUTDOWN", + "Parameters": [], + "GenericParameter": [], + "Literal": "4" + }, + { + "Kind": "Field", + "Name": "UDP_SEND", + "Parameters": [], + "GenericParameter": [], + "Literal": "5" + }, + { + "Kind": "Field", + "Name": "FS", + "Parameters": [], + "GenericParameter": [], + "Literal": "6" + }, + { + "Kind": "Field", + "Name": "WORK", + "Parameters": [], + "GenericParameter": [], + "Literal": "7" + }, + { + "Kind": "Field", + "Name": "GETADDRINFO", + "Parameters": [], + "GenericParameter": [], + "Literal": "8" + }, + { + "Kind": "Field", + "Name": "GETNAMEINFO", + "Parameters": [], + "GenericParameter": [], + "Literal": "9" + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.DateHeaderValueManager+DateHeaderValues", + "Visibility": "Public", + "Kind": "Class", + "ImplementedInterfaces": [], + "Members": [ + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [], + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Field", + "Name": "Bytes", + "Parameters": [], + "ReturnType": "System.Byte[]", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Field", + "Name": "String", + "Parameters": [], + "ReturnType": "System.String", + "Visibility": "Public", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.Frame+RequestLineStatus", + "Visibility": "Protected", + "Kind": "Enumeration", + "Sealed": true, + "ImplementedInterfaces": [], + "Members": [ + { + "Kind": "Field", + "Name": "Empty", + "Parameters": [], + "GenericParameter": [], + "Literal": "0" + }, + { + "Kind": "Field", + "Name": "MethodIncomplete", + "Parameters": [], + "GenericParameter": [], + "Literal": "1" + }, + { + "Kind": "Field", + "Name": "TargetIncomplete", + "Parameters": [], + "GenericParameter": [], + "Literal": "2" + }, + { + "Kind": "Field", + "Name": "VersionIncomplete", + "Parameters": [], + "GenericParameter": [], + "Literal": "3" + }, + { + "Kind": "Field", + "Name": "Incomplete", + "Parameters": [], + "GenericParameter": [], + "Literal": "4" + }, + { + "Kind": "Field", + "Name": "Done", + "Parameters": [], + "GenericParameter": [], + "Literal": "5" + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.Frame+RequestProcessingStatus", + "Visibility": "Protected", + "Kind": "Enumeration", + "Sealed": true, + "ImplementedInterfaces": [], + "Members": [ + { + "Kind": "Field", + "Name": "RequestPending", + "Parameters": [], + "GenericParameter": [], + "Literal": "0" + }, + { + "Kind": "Field", + "Name": "RequestStarted", + "Parameters": [], + "GenericParameter": [], + "Literal": "1" + }, + { + "Kind": "Field", + "Name": "ResponseStarted", + "Parameters": [], + "GenericParameter": [], + "Literal": "2" + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.FrameRequestHeaders+Enumerator", + "Visibility": "Public", + "Kind": "Struct", + "Sealed": true, + "ImplementedInterfaces": [ + "System.Collections.Generic.IEnumerator>" + ], + "Members": [ + { + "Kind": "Method", + "Name": "MoveNext", + "Parameters": [], + "ReturnType": "System.Boolean", + "Sealed": true, + "Virtual": true, + "ImplementedInterface": "System.Collections.IEnumerator", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_Current", + "Parameters": [], + "ReturnType": "System.Collections.Generic.KeyValuePair", + "Sealed": true, + "Virtual": true, + "ImplementedInterface": "System.Collections.Generic.IEnumerator>", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "Dispose", + "Parameters": [], + "ReturnType": "System.Void", + "Sealed": true, + "Virtual": true, + "ImplementedInterface": "System.IDisposable", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "Reset", + "Parameters": [], + "ReturnType": "System.Void", + "Sealed": true, + "Virtual": true, + "ImplementedInterface": "System.Collections.IEnumerator", + "Visibility": "Public", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.FrameResponseHeaders+Enumerator", + "Visibility": "Public", + "Kind": "Struct", + "Sealed": true, + "ImplementedInterfaces": [ + "System.Collections.Generic.IEnumerator>" + ], + "Members": [ + { + "Kind": "Method", + "Name": "MoveNext", + "Parameters": [], + "ReturnType": "System.Boolean", + "Sealed": true, + "Virtual": true, + "ImplementedInterface": "System.Collections.IEnumerator", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_Current", + "Parameters": [], + "ReturnType": "System.Collections.Generic.KeyValuePair", + "Sealed": true, + "Virtual": true, + "ImplementedInterface": "System.Collections.Generic.IEnumerator>", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "Dispose", + "Parameters": [], + "ReturnType": "System.Void", + "Sealed": true, + "Virtual": true, + "ImplementedInterface": "System.IDisposable", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "Reset", + "Parameters": [], + "ReturnType": "System.Void", + "Sealed": true, + "Virtual": true, + "ImplementedInterface": "System.Collections.IEnumerator", + "Visibility": "Public", + "GenericParameter": [] + } + ], + "GenericParameters": [] + } + ] +} \ No newline at end of file diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/baseline.netcore.json b/src/Microsoft.AspNetCore.Server.Kestrel/baseline.netcore.json new file mode 100644 index 0000000000..e786e3a8e1 --- /dev/null +++ b/src/Microsoft.AspNetCore.Server.Kestrel/baseline.netcore.json @@ -0,0 +1,12700 @@ +{ + "AssemblyIdentity": "Microsoft.AspNetCore.Server.Kestrel, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60", + "Types": [ + { + "Name": "Microsoft.AspNetCore.Hosting.WebHostBuilderKestrelExtensions", + "Visibility": "Public", + "Kind": "Class", + "Abstract": true, + "Static": true, + "Sealed": true, + "ImplementedInterfaces": [], + "Members": [ + { + "Kind": "Method", + "Name": "UseKestrel", + "Parameters": [ + { + "Name": "hostBuilder", + "Type": "Microsoft.AspNetCore.Hosting.IWebHostBuilder" + } + ], + "ReturnType": "Microsoft.AspNetCore.Hosting.IWebHostBuilder", + "Static": true, + "Extension": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "UseKestrel", + "Parameters": [ + { + "Name": "hostBuilder", + "Type": "Microsoft.AspNetCore.Hosting.IWebHostBuilder" + }, + { + "Name": "options", + "Type": "System.Action" + } + ], + "ReturnType": "Microsoft.AspNetCore.Hosting.IWebHostBuilder", + "Static": true, + "Extension": true, + "Visibility": "Public", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Hosting.KestrelServerOptionsConnectionLoggingExtensions", + "Visibility": "Public", + "Kind": "Class", + "Abstract": true, + "Static": true, + "Sealed": true, + "ImplementedInterfaces": [], + "Members": [ + { + "Kind": "Method", + "Name": "UseConnectionLogging", + "Parameters": [ + { + "Name": "options", + "Type": "Microsoft.AspNetCore.Server.Kestrel.KestrelServerOptions" + } + ], + "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.KestrelServerOptions", + "Static": true, + "Extension": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "UseConnectionLogging", + "Parameters": [ + { + "Name": "options", + "Type": "Microsoft.AspNetCore.Server.Kestrel.KestrelServerOptions" + }, + { + "Name": "loggerName", + "Type": "System.String" + } + ], + "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.KestrelServerOptions", + "Static": true, + "Extension": true, + "Visibility": "Public", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.BadHttpRequestException", + "Visibility": "Public", + "Kind": "Class", + "Sealed": true, + "BaseType": "System.IO.IOException", + "ImplementedInterfaces": [], + "Members": [], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.KestrelServer", + "Visibility": "Public", + "Kind": "Class", + "ImplementedInterfaces": [ + "Microsoft.AspNetCore.Hosting.Server.IServer" + ], + "Members": [ + { + "Kind": "Method", + "Name": "get_Features", + "Parameters": [], + "ReturnType": "Microsoft.AspNetCore.Http.Features.IFeatureCollection", + "Sealed": true, + "Virtual": true, + "ImplementedInterface": "Microsoft.AspNetCore.Hosting.Server.IServer", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_Options", + "Parameters": [], + "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.KestrelServerOptions", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "Start", + "Parameters": [ + { + "Name": "application", + "Type": "Microsoft.AspNetCore.Hosting.Server.IHttpApplication" + } + ], + "ReturnType": "System.Void", + "Sealed": true, + "Virtual": true, + "ImplementedInterface": "Microsoft.AspNetCore.Hosting.Server.IServer", + "Visibility": "Public", + "GenericParameter": [ + { + "ParameterName": "TContext", + "ParameterPosition": 0, + "BaseTypeOrInterfaces": [] + } + ] + }, + { + "Kind": "Method", + "Name": "Dispose", + "Parameters": [], + "ReturnType": "System.Void", + "Sealed": true, + "Virtual": true, + "ImplementedInterface": "System.IDisposable", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [ + { + "Name": "options", + "Type": "Microsoft.Extensions.Options.IOptions" + }, + { + "Name": "applicationLifetime", + "Type": "Microsoft.AspNetCore.Hosting.IApplicationLifetime" + }, + { + "Name": "loggerFactory", + "Type": "Microsoft.Extensions.Logging.ILoggerFactory" + } + ], + "Visibility": "Public", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.KestrelServerOptions", + "Visibility": "Public", + "Kind": "Class", + "ImplementedInterfaces": [], + "Members": [ + { + "Kind": "Method", + "Name": "get_AddServerHeader", + "Parameters": [], + "ReturnType": "System.Boolean", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_AddServerHeader", + "Parameters": [ + { + "Name": "value", + "Type": "System.Boolean" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_ApplicationServices", + "Parameters": [], + "ReturnType": "System.IServiceProvider", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_ApplicationServices", + "Parameters": [ + { + "Name": "value", + "Type": "System.IServiceProvider" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_ConnectionFilter", + "Parameters": [], + "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Filter.IConnectionFilter", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_ConnectionFilter", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Filter.IConnectionFilter" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_MaxRequestBufferSize", + "Parameters": [], + "ReturnType": "System.Nullable", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_MaxRequestBufferSize", + "Parameters": [ + { + "Name": "value", + "Type": "System.Nullable" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_NoDelay", + "Parameters": [], + "ReturnType": "System.Boolean", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_NoDelay", + "Parameters": [ + { + "Name": "value", + "Type": "System.Boolean" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_ShutdownTimeout", + "Parameters": [], + "ReturnType": "System.TimeSpan", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_ShutdownTimeout", + "Parameters": [ + { + "Name": "value", + "Type": "System.TimeSpan" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_ThreadCount", + "Parameters": [], + "ReturnType": "System.Int32", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_ThreadCount", + "Parameters": [ + { + "Name": "value", + "Type": "System.Int32" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [], + "Visibility": "Public", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.ServerAddress", + "Visibility": "Public", + "Kind": "Class", + "ImplementedInterfaces": [], + "Members": [ + { + "Kind": "Method", + "Name": "get_Host", + "Parameters": [], + "ReturnType": "System.String", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_PathBase", + "Parameters": [], + "ReturnType": "System.String", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_Port", + "Parameters": [], + "ReturnType": "System.Int32", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_Scheme", + "Parameters": [], + "ReturnType": "System.String", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_IsUnixPipe", + "Parameters": [], + "ReturnType": "System.Boolean", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_UnixPipePath", + "Parameters": [], + "ReturnType": "System.String", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "ToString", + "Parameters": [], + "ReturnType": "System.String", + "Virtual": true, + "Override": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "GetHashCode", + "Parameters": [], + "ReturnType": "System.Int32", + "Virtual": true, + "Override": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "Equals", + "Parameters": [ + { + "Name": "obj", + "Type": "System.Object" + } + ], + "ReturnType": "System.Boolean", + "Virtual": true, + "Override": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "FromUrl", + "Parameters": [ + { + "Name": "url", + "Type": "System.String" + } + ], + "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.ServerAddress", + "Static": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [], + "Visibility": "Public", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.KestrelEngine", + "Visibility": "Public", + "Kind": "Class", + "BaseType": "Microsoft.AspNetCore.Server.Kestrel.Internal.ServiceContext", + "ImplementedInterfaces": [ + "System.IDisposable" + ], + "Members": [ + { + "Kind": "Method", + "Name": "get_Libuv", + "Parameters": [], + "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_Threads", + "Parameters": [], + "ReturnType": "System.Collections.Generic.List", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "Start", + "Parameters": [ + { + "Name": "count", + "Type": "System.Int32" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "Dispose", + "Parameters": [], + "ReturnType": "System.Void", + "Sealed": true, + "Virtual": true, + "ImplementedInterface": "System.IDisposable", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "CreateServer", + "Parameters": [ + { + "Name": "address", + "Type": "Microsoft.AspNetCore.Server.Kestrel.ServerAddress" + } + ], + "ReturnType": "System.IDisposable", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [ + { + "Name": "context", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.ServiceContext" + } + ], + "Visibility": "Public", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.KestrelServerOptionsSetup", + "Visibility": "Public", + "Kind": "Class", + "ImplementedInterfaces": [ + "Microsoft.Extensions.Options.IConfigureOptions" + ], + "Members": [ + { + "Kind": "Method", + "Name": "Configure", + "Parameters": [ + { + "Name": "options", + "Type": "Microsoft.AspNetCore.Server.Kestrel.KestrelServerOptions" + } + ], + "ReturnType": "System.Void", + "Sealed": true, + "Virtual": true, + "ImplementedInterface": "Microsoft.Extensions.Options.IConfigureOptions", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [ + { + "Name": "services", + "Type": "System.IServiceProvider" + } + ], + "Visibility": "Public", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.ServiceContext", + "Visibility": "Public", + "Kind": "Class", + "ImplementedInterfaces": [], + "Members": [ + { + "Kind": "Method", + "Name": "get_AppLifetime", + "Parameters": [], + "ReturnType": "Microsoft.AspNetCore.Hosting.IApplicationLifetime", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_AppLifetime", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.AspNetCore.Hosting.IApplicationLifetime" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_Log", + "Parameters": [], + "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IKestrelTrace", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_Log", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IKestrelTrace" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_ThreadPool", + "Parameters": [], + "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IThreadPool", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_ThreadPool", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IThreadPool" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_FrameFactory", + "Parameters": [], + "ReturnType": "System.Func", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_FrameFactory", + "Parameters": [ + { + "Name": "value", + "Type": "System.Func" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_DateHeaderValueManager", + "Parameters": [], + "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.DateHeaderValueManager", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_DateHeaderValueManager", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.DateHeaderValueManager" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_ServerOptions", + "Parameters": [], + "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.KestrelServerOptions", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_ServerOptions", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.AspNetCore.Server.Kestrel.KestrelServerOptions" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [], + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [ + { + "Name": "context", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.ServiceContext" + } + ], + "Visibility": "Public", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Disposable", + "Visibility": "Public", + "Kind": "Class", + "ImplementedInterfaces": [ + "System.IDisposable" + ], + "Members": [ + { + "Kind": "Method", + "Name": "Dispose", + "Parameters": [ + { + "Name": "disposing", + "Type": "System.Boolean" + } + ], + "ReturnType": "System.Void", + "Virtual": true, + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "Dispose", + "Parameters": [], + "ReturnType": "System.Void", + "Sealed": true, + "Virtual": true, + "ImplementedInterface": "System.IDisposable", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [ + { + "Name": "dispose", + "Type": "System.Action" + } + ], + "Visibility": "Public", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.KestrelThread", + "Visibility": "Public", + "Kind": "Class", + "ImplementedInterfaces": [], + "Members": [ + { + "Kind": "Method", + "Name": "get_Loop", + "Parameters": [], + "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvLoopHandle", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_FatalError", + "Parameters": [], + "ReturnType": "System.Runtime.ExceptionServices.ExceptionDispatchInfo", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_QueueCloseHandle", + "Parameters": [], + "ReturnType": "System.Action, System.IntPtr>", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "StartAsync", + "Parameters": [], + "ReturnType": "System.Threading.Tasks.Task", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "AllowStop", + "Parameters": [], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "Stop", + "Parameters": [ + { + "Name": "timeout", + "Type": "System.TimeSpan" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "Post", + "Parameters": [ + { + "Name": "callback", + "Type": "System.Action" + }, + { + "Name": "state", + "Type": "System.Object" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "PostAsync", + "Parameters": [ + { + "Name": "callback", + "Type": "System.Action" + }, + { + "Name": "state", + "Type": "System.Object" + } + ], + "ReturnType": "System.Threading.Tasks.Task", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "Walk", + "Parameters": [ + { + "Name": "callback", + "Type": "System.Action" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [ + { + "Name": "engine", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.KestrelEngine" + } + ], + "Visibility": "Public", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.KestrelTrace", + "Visibility": "Public", + "Kind": "Class", + "ImplementedInterfaces": [ + "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IKestrelTrace" + ], + "Members": [ + { + "Kind": "Method", + "Name": "ConnectionStart", + "Parameters": [ + { + "Name": "connectionId", + "Type": "System.String" + } + ], + "ReturnType": "System.Void", + "Virtual": true, + "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IKestrelTrace", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "ConnectionStop", + "Parameters": [ + { + "Name": "connectionId", + "Type": "System.String" + } + ], + "ReturnType": "System.Void", + "Virtual": true, + "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IKestrelTrace", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "ConnectionRead", + "Parameters": [ + { + "Name": "connectionId", + "Type": "System.String" + }, + { + "Name": "count", + "Type": "System.Int32" + } + ], + "ReturnType": "System.Void", + "Virtual": true, + "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IKestrelTrace", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "ConnectionPause", + "Parameters": [ + { + "Name": "connectionId", + "Type": "System.String" + } + ], + "ReturnType": "System.Void", + "Virtual": true, + "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IKestrelTrace", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "ConnectionResume", + "Parameters": [ + { + "Name": "connectionId", + "Type": "System.String" + } + ], + "ReturnType": "System.Void", + "Virtual": true, + "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IKestrelTrace", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "ConnectionReadFin", + "Parameters": [ + { + "Name": "connectionId", + "Type": "System.String" + } + ], + "ReturnType": "System.Void", + "Virtual": true, + "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IKestrelTrace", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "ConnectionWriteFin", + "Parameters": [ + { + "Name": "connectionId", + "Type": "System.String" + } + ], + "ReturnType": "System.Void", + "Virtual": true, + "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IKestrelTrace", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "ConnectionWroteFin", + "Parameters": [ + { + "Name": "connectionId", + "Type": "System.String" + }, + { + "Name": "status", + "Type": "System.Int32" + } + ], + "ReturnType": "System.Void", + "Virtual": true, + "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IKestrelTrace", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "ConnectionKeepAlive", + "Parameters": [ + { + "Name": "connectionId", + "Type": "System.String" + } + ], + "ReturnType": "System.Void", + "Virtual": true, + "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IKestrelTrace", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "ConnectionDisconnect", + "Parameters": [ + { + "Name": "connectionId", + "Type": "System.String" + } + ], + "ReturnType": "System.Void", + "Virtual": true, + "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IKestrelTrace", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "ConnectionWrite", + "Parameters": [ + { + "Name": "connectionId", + "Type": "System.String" + }, + { + "Name": "count", + "Type": "System.Int32" + } + ], + "ReturnType": "System.Void", + "Virtual": true, + "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IKestrelTrace", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "ConnectionWriteCallback", + "Parameters": [ + { + "Name": "connectionId", + "Type": "System.String" + }, + { + "Name": "status", + "Type": "System.Int32" + } + ], + "ReturnType": "System.Void", + "Virtual": true, + "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IKestrelTrace", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "ApplicationError", + "Parameters": [ + { + "Name": "connectionId", + "Type": "System.String" + }, + { + "Name": "ex", + "Type": "System.Exception" + } + ], + "ReturnType": "System.Void", + "Virtual": true, + "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IKestrelTrace", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "ConnectionError", + "Parameters": [ + { + "Name": "connectionId", + "Type": "System.String" + }, + { + "Name": "ex", + "Type": "System.Exception" + } + ], + "ReturnType": "System.Void", + "Virtual": true, + "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IKestrelTrace", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "ConnectionDisconnectedWrite", + "Parameters": [ + { + "Name": "connectionId", + "Type": "System.String" + }, + { + "Name": "count", + "Type": "System.Int32" + }, + { + "Name": "ex", + "Type": "System.Exception" + } + ], + "ReturnType": "System.Void", + "Virtual": true, + "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IKestrelTrace", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "NotAllConnectionsClosedGracefully", + "Parameters": [], + "ReturnType": "System.Void", + "Virtual": true, + "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IKestrelTrace", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "ConnectionBadRequest", + "Parameters": [ + { + "Name": "connectionId", + "Type": "System.String" + }, + { + "Name": "ex", + "Type": "Microsoft.AspNetCore.Server.Kestrel.BadHttpRequestException" + } + ], + "ReturnType": "System.Void", + "Sealed": true, + "Virtual": true, + "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IKestrelTrace", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "Log", + "Parameters": [ + { + "Name": "logLevel", + "Type": "Microsoft.Extensions.Logging.LogLevel" + }, + { + "Name": "eventId", + "Type": "Microsoft.Extensions.Logging.EventId" + }, + { + "Name": "state", + "Type": "T0" + }, + { + "Name": "exception", + "Type": "System.Exception" + }, + { + "Name": "formatter", + "Type": "System.Func" + } + ], + "ReturnType": "System.Void", + "Virtual": true, + "ImplementedInterface": "Microsoft.Extensions.Logging.ILogger", + "Visibility": "Public", + "GenericParameter": [ + { + "ParameterName": "TState", + "ParameterPosition": 0, + "BaseTypeOrInterfaces": [] + } + ] + }, + { + "Kind": "Method", + "Name": "IsEnabled", + "Parameters": [ + { + "Name": "logLevel", + "Type": "Microsoft.Extensions.Logging.LogLevel" + } + ], + "ReturnType": "System.Boolean", + "Virtual": true, + "ImplementedInterface": "Microsoft.Extensions.Logging.ILogger", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "BeginScope", + "Parameters": [ + { + "Name": "state", + "Type": "T0" + } + ], + "ReturnType": "System.IDisposable", + "Virtual": true, + "ImplementedInterface": "Microsoft.Extensions.Logging.ILogger", + "Visibility": "Public", + "GenericParameter": [ + { + "ParameterName": "TState", + "ParameterPosition": 0, + "BaseTypeOrInterfaces": [] + } + ] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [ + { + "Name": "logger", + "Type": "Microsoft.Extensions.Logging.ILogger" + } + ], + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Field", + "Name": "_logger", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Logging.ILogger", + "ReadOnly": true, + "Visibility": "Protected", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv", + "Visibility": "Public", + "Kind": "Class", + "ImplementedInterfaces": [], + "Members": [ + { + "Kind": "Method", + "Name": "Check", + "Parameters": [ + { + "Name": "statusCode", + "Type": "System.Int32" + } + ], + "ReturnType": "System.Int32", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "Check", + "Parameters": [ + { + "Name": "statusCode", + "Type": "System.Int32" + }, + { + "Name": "error", + "Type": "System.Exception", + "Direction": "Out" + } + ], + "ReturnType": "System.Int32", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "loop_init", + "Parameters": [ + { + "Name": "handle", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvLoopHandle" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "loop_close", + "Parameters": [ + { + "Name": "handle", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvLoopHandle" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "run", + "Parameters": [ + { + "Name": "handle", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvLoopHandle" + }, + { + "Name": "mode", + "Type": "System.Int32" + } + ], + "ReturnType": "System.Int32", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "stop", + "Parameters": [ + { + "Name": "handle", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvLoopHandle" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "ref", + "Parameters": [ + { + "Name": "handle", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvHandle" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "unref", + "Parameters": [ + { + "Name": "handle", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvHandle" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "uv_fileno", + "Parameters": [ + { + "Name": "handle", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvHandle" + }, + { + "Name": "socket", + "Type": "System.IntPtr", + "Direction": "Ref" + } + ], + "ReturnType": "System.Int32", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "close", + "Parameters": [ + { + "Name": "handle", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvHandle" + }, + { + "Name": "close_cb", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_close_cb" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "close", + "Parameters": [ + { + "Name": "handle", + "Type": "System.IntPtr" + }, + { + "Name": "close_cb", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_close_cb" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "async_init", + "Parameters": [ + { + "Name": "loop", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvLoopHandle" + }, + { + "Name": "handle", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvAsyncHandle" + }, + { + "Name": "cb", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_async_cb" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "async_send", + "Parameters": [ + { + "Name": "handle", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvAsyncHandle" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "unsafe_async_send", + "Parameters": [ + { + "Name": "handle", + "Type": "System.IntPtr" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "tcp_init", + "Parameters": [ + { + "Name": "loop", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvLoopHandle" + }, + { + "Name": "handle", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvTcpHandle" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "tcp_bind", + "Parameters": [ + { + "Name": "handle", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvTcpHandle" + }, + { + "Name": "addr", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.SockAddr", + "Direction": "Ref" + }, + { + "Name": "flags", + "Type": "System.Int32" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "tcp_open", + "Parameters": [ + { + "Name": "handle", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvTcpHandle" + }, + { + "Name": "hSocket", + "Type": "System.IntPtr" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "tcp_nodelay", + "Parameters": [ + { + "Name": "handle", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvTcpHandle" + }, + { + "Name": "enable", + "Type": "System.Boolean" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "pipe_init", + "Parameters": [ + { + "Name": "loop", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvLoopHandle" + }, + { + "Name": "handle", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvPipeHandle" + }, + { + "Name": "ipc", + "Type": "System.Boolean" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "pipe_bind", + "Parameters": [ + { + "Name": "handle", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvPipeHandle" + }, + { + "Name": "name", + "Type": "System.String" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "listen", + "Parameters": [ + { + "Name": "handle", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle" + }, + { + "Name": "backlog", + "Type": "System.Int32" + }, + { + "Name": "cb", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_connection_cb" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "accept", + "Parameters": [ + { + "Name": "server", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle" + }, + { + "Name": "client", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "pipe_connect", + "Parameters": [ + { + "Name": "req", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvConnectRequest" + }, + { + "Name": "handle", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvPipeHandle" + }, + { + "Name": "name", + "Type": "System.String" + }, + { + "Name": "cb", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_connect_cb" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "pipe_pending_count", + "Parameters": [ + { + "Name": "handle", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvPipeHandle" + } + ], + "ReturnType": "System.Int32", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "read_start", + "Parameters": [ + { + "Name": "handle", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle" + }, + { + "Name": "alloc_cb", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_alloc_cb" + }, + { + "Name": "read_cb", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_read_cb" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "read_stop", + "Parameters": [ + { + "Name": "handle", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "try_write", + "Parameters": [ + { + "Name": "handle", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle" + }, + { + "Name": "bufs", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_buf_t[]" + }, + { + "Name": "nbufs", + "Type": "System.Int32" + } + ], + "ReturnType": "System.Int32", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "write", + "Parameters": [ + { + "Name": "req", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvRequest" + }, + { + "Name": "handle", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle" + }, + { + "Name": "bufs", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_buf_t*" + }, + { + "Name": "nbufs", + "Type": "System.Int32" + }, + { + "Name": "cb", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_write_cb" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "write2", + "Parameters": [ + { + "Name": "req", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvRequest" + }, + { + "Name": "handle", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle" + }, + { + "Name": "bufs", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_buf_t*" + }, + { + "Name": "nbufs", + "Type": "System.Int32" + }, + { + "Name": "sendHandle", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle" + }, + { + "Name": "cb", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_write_cb" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "shutdown", + "Parameters": [ + { + "Name": "req", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvShutdownReq" + }, + { + "Name": "handle", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle" + }, + { + "Name": "cb", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_shutdown_cb" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "err_name", + "Parameters": [ + { + "Name": "err", + "Type": "System.Int32" + } + ], + "ReturnType": "System.String", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "strerror", + "Parameters": [ + { + "Name": "err", + "Type": "System.Int32" + } + ], + "ReturnType": "System.String", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "loop_size", + "Parameters": [], + "ReturnType": "System.Int32", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "handle_size", + "Parameters": [ + { + "Name": "handleType", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+HandleType" + } + ], + "ReturnType": "System.Int32", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "req_size", + "Parameters": [ + { + "Name": "reqType", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+RequestType" + } + ], + "ReturnType": "System.Int32", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "ip4_addr", + "Parameters": [ + { + "Name": "ip", + "Type": "System.String" + }, + { + "Name": "port", + "Type": "System.Int32" + }, + { + "Name": "addr", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.SockAddr", + "Direction": "Out" + }, + { + "Name": "error", + "Type": "System.Exception", + "Direction": "Out" + } + ], + "ReturnType": "System.Int32", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "ip6_addr", + "Parameters": [ + { + "Name": "ip", + "Type": "System.String" + }, + { + "Name": "port", + "Type": "System.Int32" + }, + { + "Name": "addr", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.SockAddr", + "Direction": "Out" + }, + { + "Name": "error", + "Type": "System.Exception", + "Direction": "Out" + } + ], + "ReturnType": "System.Int32", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "walk", + "Parameters": [ + { + "Name": "loop", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvLoopHandle" + }, + { + "Name": "walk_cb", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_walk_cb" + }, + { + "Name": "arg", + "Type": "System.IntPtr" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "tcp_getsockname", + "Parameters": [ + { + "Name": "handle", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvTcpHandle" + }, + { + "Name": "addr", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.SockAddr", + "Direction": "Out" + }, + { + "Name": "namelen", + "Type": "System.Int32", + "Direction": "Ref" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "tcp_getpeername", + "Parameters": [ + { + "Name": "handle", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvTcpHandle" + }, + { + "Name": "addr", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.SockAddr", + "Direction": "Out" + }, + { + "Name": "namelen", + "Type": "System.Int32", + "Direction": "Ref" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "buf_init", + "Parameters": [ + { + "Name": "memory", + "Type": "System.IntPtr" + }, + { + "Name": "len", + "Type": "System.Int32" + } + ], + "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_buf_t", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [], + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Field", + "Name": "IsWindows", + "Parameters": [], + "ReturnType": "System.Boolean", + "ReadOnly": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Field", + "Name": "_uv_loop_init", + "Parameters": [], + "ReturnType": "System.Func", + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Field", + "Name": "_uv_loop_close", + "Parameters": [], + "ReturnType": "System.Func", + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Field", + "Name": "_uv_run", + "Parameters": [], + "ReturnType": "System.Func", + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Field", + "Name": "_uv_stop", + "Parameters": [], + "ReturnType": "System.Action", + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Field", + "Name": "_uv_ref", + "Parameters": [], + "ReturnType": "System.Action", + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Field", + "Name": "_uv_unref", + "Parameters": [], + "ReturnType": "System.Action", + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Field", + "Name": "_uv_fileno", + "Parameters": [], + "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_fileno_func", + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Field", + "Name": "_uv_close", + "Parameters": [], + "ReturnType": "System.Action", + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Field", + "Name": "_uv_async_init", + "Parameters": [], + "ReturnType": "System.Func", + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Field", + "Name": "_uv_async_send", + "Parameters": [], + "ReturnType": "System.Func", + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Field", + "Name": "_uv_unsafe_async_send", + "Parameters": [], + "ReturnType": "System.Func", + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Field", + "Name": "_uv_tcp_init", + "Parameters": [], + "ReturnType": "System.Func", + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Field", + "Name": "_uv_tcp_bind", + "Parameters": [], + "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_tcp_bind_func", + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Field", + "Name": "_uv_tcp_open", + "Parameters": [], + "ReturnType": "System.Func", + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Field", + "Name": "_uv_tcp_nodelay", + "Parameters": [], + "ReturnType": "System.Func", + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Field", + "Name": "_uv_pipe_init", + "Parameters": [], + "ReturnType": "System.Func", + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Field", + "Name": "_uv_pipe_bind", + "Parameters": [], + "ReturnType": "System.Func", + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Field", + "Name": "_uv_listen", + "Parameters": [], + "ReturnType": "System.Func", + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Field", + "Name": "_uv_accept", + "Parameters": [], + "ReturnType": "System.Func", + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Field", + "Name": "_uv_pipe_connect", + "Parameters": [], + "ReturnType": "System.Action", + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Field", + "Name": "_uv_pipe_pending_count", + "Parameters": [], + "ReturnType": "System.Func", + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Field", + "Name": "_uv_read_start", + "Parameters": [], + "ReturnType": "System.Func", + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Field", + "Name": "_uv_read_stop", + "Parameters": [], + "ReturnType": "System.Func", + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Field", + "Name": "_uv_try_write", + "Parameters": [], + "ReturnType": "System.Func", + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Field", + "Name": "_uv_write", + "Parameters": [], + "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_write_func", + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Field", + "Name": "_uv_write2", + "Parameters": [], + "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_write2_func", + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Field", + "Name": "_uv_shutdown", + "Parameters": [], + "ReturnType": "System.Func", + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Field", + "Name": "_uv_err_name", + "Parameters": [], + "ReturnType": "System.Func", + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Field", + "Name": "_uv_strerror", + "Parameters": [], + "ReturnType": "System.Func", + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Field", + "Name": "_uv_loop_size", + "Parameters": [], + "ReturnType": "System.Func", + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Field", + "Name": "_uv_handle_size", + "Parameters": [], + "ReturnType": "System.Func", + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Field", + "Name": "_uv_req_size", + "Parameters": [], + "ReturnType": "System.Func", + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Field", + "Name": "_uv_ip4_addr", + "Parameters": [], + "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_ip4_addr_func", + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Field", + "Name": "_uv_ip6_addr", + "Parameters": [], + "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_ip6_addr_func", + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Field", + "Name": "_uv_walk", + "Parameters": [], + "ReturnType": "System.Func", + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Field", + "Name": "_uv_tcp_getsockname", + "Parameters": [], + "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_tcp_getsockname_func", + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Field", + "Name": "_uv_tcp_getpeername", + "Parameters": [], + "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_tcp_getpeername_func", + "Visibility": "Protected", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.PlatformApis", + "Visibility": "Public", + "Kind": "Class", + "Abstract": true, + "Static": true, + "Sealed": true, + "ImplementedInterfaces": [], + "Members": [ + { + "Kind": "Method", + "Name": "get_IsWindows", + "Parameters": [], + "ReturnType": "System.Boolean", + "Static": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_IsDarwin", + "Parameters": [], + "ReturnType": "System.Boolean", + "Static": true, + "Visibility": "Public", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.SockAddr", + "Visibility": "Public", + "Kind": "Struct", + "Sealed": true, + "ImplementedInterfaces": [], + "Members": [ + { + "Kind": "Method", + "Name": "GetIPEndPoint", + "Parameters": [], + "ReturnType": "System.Net.IPEndPoint", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [ + { + "Name": "ignored", + "Type": "System.Int64" + } + ], + "Visibility": "Public", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvAsyncHandle", + "Visibility": "Public", + "Kind": "Class", + "BaseType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvHandle", + "ImplementedInterfaces": [], + "Members": [ + { + "Kind": "Method", + "Name": "Init", + "Parameters": [ + { + "Name": "loop", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvLoopHandle" + }, + { + "Name": "callback", + "Type": "System.Action" + }, + { + "Name": "queueCloseHandle", + "Type": "System.Action, System.IntPtr>" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "Send", + "Parameters": [], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "ReleaseHandle", + "Parameters": [], + "ReturnType": "System.Boolean", + "Virtual": true, + "Override": true, + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [ + { + "Name": "logger", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IKestrelTrace" + } + ], + "Visibility": "Public", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvConnectRequest", + "Visibility": "Public", + "Kind": "Class", + "BaseType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvRequest", + "ImplementedInterfaces": [], + "Members": [ + { + "Kind": "Method", + "Name": "Init", + "Parameters": [ + { + "Name": "loop", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvLoopHandle" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "Connect", + "Parameters": [ + { + "Name": "pipe", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvPipeHandle" + }, + { + "Name": "name", + "Type": "System.String" + }, + { + "Name": "callback", + "Type": "System.Action" + }, + { + "Name": "state", + "Type": "System.Object" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [ + { + "Name": "logger", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IKestrelTrace" + } + ], + "Visibility": "Public", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvException", + "Visibility": "Public", + "Kind": "Class", + "BaseType": "System.Exception", + "ImplementedInterfaces": [], + "Members": [ + { + "Kind": "Method", + "Name": "get_StatusCode", + "Parameters": [], + "ReturnType": "System.Int32", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [ + { + "Name": "message", + "Type": "System.String" + }, + { + "Name": "statusCode", + "Type": "System.Int32" + } + ], + "Visibility": "Public", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvHandle", + "Visibility": "Public", + "Kind": "Class", + "Abstract": true, + "BaseType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvMemory", + "ImplementedInterfaces": [], + "Members": [ + { + "Kind": "Method", + "Name": "CreateHandle", + "Parameters": [ + { + "Name": "uv", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv" + }, + { + "Name": "threadId", + "Type": "System.Int32" + }, + { + "Name": "size", + "Type": "System.Int32" + }, + { + "Name": "queueCloseHandle", + "Type": "System.Action, System.IntPtr>" + } + ], + "ReturnType": "System.Void", + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "ReleaseHandle", + "Parameters": [], + "ReturnType": "System.Boolean", + "Virtual": true, + "Override": true, + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "Reference", + "Parameters": [], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "Unreference", + "Parameters": [], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [ + { + "Name": "logger", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IKestrelTrace" + } + ], + "Visibility": "Protected", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvLoopHandle", + "Visibility": "Public", + "Kind": "Class", + "BaseType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvMemory", + "ImplementedInterfaces": [], + "Members": [ + { + "Kind": "Method", + "Name": "Init", + "Parameters": [ + { + "Name": "uv", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "Run", + "Parameters": [ + { + "Name": "mode", + "Type": "System.Int32", + "DefaultValue": "0" + } + ], + "ReturnType": "System.Int32", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "Stop", + "Parameters": [], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "ReleaseHandle", + "Parameters": [], + "ReturnType": "System.Boolean", + "Virtual": true, + "Override": true, + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [ + { + "Name": "logger", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IKestrelTrace" + } + ], + "Visibility": "Public", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvMemory", + "Visibility": "Public", + "Kind": "Class", + "Abstract": true, + "BaseType": "System.Runtime.InteropServices.SafeHandle", + "ImplementedInterfaces": [], + "Members": [ + { + "Kind": "Method", + "Name": "get_Libuv", + "Parameters": [], + "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_IsInvalid", + "Parameters": [], + "ReturnType": "System.Boolean", + "Virtual": true, + "Override": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_ThreadId", + "Parameters": [], + "ReturnType": "System.Int32", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "CreateMemory", + "Parameters": [ + { + "Name": "uv", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv" + }, + { + "Name": "threadId", + "Type": "System.Int32" + }, + { + "Name": "size", + "Type": "System.Int32" + } + ], + "ReturnType": "System.Void", + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "DestroyMemory", + "Parameters": [ + { + "Name": "memory", + "Type": "System.IntPtr" + } + ], + "ReturnType": "System.Void", + "Static": true, + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "DestroyMemory", + "Parameters": [ + { + "Name": "memory", + "Type": "System.IntPtr" + }, + { + "Name": "gcHandlePtr", + "Type": "System.IntPtr" + } + ], + "ReturnType": "System.Void", + "Static": true, + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "Validate", + "Parameters": [ + { + "Name": "closed", + "Type": "System.Boolean", + "DefaultValue": "False" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "FromIntPtr", + "Parameters": [ + { + "Name": "handle", + "Type": "System.IntPtr" + } + ], + "ReturnType": "T0", + "Static": true, + "Visibility": "Public", + "GenericParameter": [ + { + "ParameterName": "THandle", + "ParameterPosition": 0, + "BaseTypeOrInterfaces": [] + } + ] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [ + { + "Name": "logger", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IKestrelTrace" + } + ], + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Field", + "Name": "_uv", + "Parameters": [], + "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv", + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Field", + "Name": "_threadId", + "Parameters": [], + "ReturnType": "System.Int32", + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Field", + "Name": "_log", + "Parameters": [], + "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IKestrelTrace", + "ReadOnly": true, + "Visibility": "Protected", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvPipeHandle", + "Visibility": "Public", + "Kind": "Class", + "BaseType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle", + "ImplementedInterfaces": [], + "Members": [ + { + "Kind": "Method", + "Name": "Init", + "Parameters": [ + { + "Name": "loop", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvLoopHandle" + }, + { + "Name": "queueCloseHandle", + "Type": "System.Action, System.IntPtr>" + }, + { + "Name": "ipc", + "Type": "System.Boolean", + "DefaultValue": "False" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "Bind", + "Parameters": [ + { + "Name": "name", + "Type": "System.String" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "PendingCount", + "Parameters": [], + "ReturnType": "System.Int32", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [ + { + "Name": "logger", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IKestrelTrace" + } + ], + "Visibility": "Public", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvRequest", + "Visibility": "Public", + "Kind": "Class", + "BaseType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvMemory", + "ImplementedInterfaces": [], + "Members": [ + { + "Kind": "Method", + "Name": "ReleaseHandle", + "Parameters": [], + "ReturnType": "System.Boolean", + "Virtual": true, + "Override": true, + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "Pin", + "Parameters": [], + "ReturnType": "System.Void", + "Virtual": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "Unpin", + "Parameters": [], + "ReturnType": "System.Void", + "Virtual": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [ + { + "Name": "logger", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IKestrelTrace" + } + ], + "Visibility": "Protected", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvShutdownReq", + "Visibility": "Public", + "Kind": "Class", + "BaseType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvRequest", + "ImplementedInterfaces": [], + "Members": [ + { + "Kind": "Method", + "Name": "Init", + "Parameters": [ + { + "Name": "loop", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvLoopHandle" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "Shutdown", + "Parameters": [ + { + "Name": "handle", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle" + }, + { + "Name": "callback", + "Type": "System.Action" + }, + { + "Name": "state", + "Type": "System.Object" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [ + { + "Name": "logger", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IKestrelTrace" + } + ], + "Visibility": "Public", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle", + "Visibility": "Public", + "Kind": "Class", + "Abstract": true, + "BaseType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvHandle", + "ImplementedInterfaces": [], + "Members": [ + { + "Kind": "Method", + "Name": "get_Connection", + "Parameters": [], + "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.Connection", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_Connection", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.Connection" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "ReleaseHandle", + "Parameters": [], + "ReturnType": "System.Boolean", + "Virtual": true, + "Override": true, + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "Listen", + "Parameters": [ + { + "Name": "backlog", + "Type": "System.Int32" + }, + { + "Name": "callback", + "Type": "System.Action" + }, + { + "Name": "state", + "Type": "System.Object" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "Accept", + "Parameters": [ + { + "Name": "handle", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "ReadStart", + "Parameters": [ + { + "Name": "allocCallback", + "Type": "System.Func" + }, + { + "Name": "readCallback", + "Type": "System.Action" + }, + { + "Name": "state", + "Type": "System.Object" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "ReadStop", + "Parameters": [], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "TryWrite", + "Parameters": [ + { + "Name": "buf", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_buf_t" + } + ], + "ReturnType": "System.Int32", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [ + { + "Name": "logger", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IKestrelTrace" + } + ], + "Visibility": "Protected", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvTcpHandle", + "Visibility": "Public", + "Kind": "Class", + "BaseType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle", + "ImplementedInterfaces": [], + "Members": [ + { + "Kind": "Method", + "Name": "Init", + "Parameters": [ + { + "Name": "loop", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvLoopHandle" + }, + { + "Name": "queueCloseHandle", + "Type": "System.Action, System.IntPtr>" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "Bind", + "Parameters": [ + { + "Name": "address", + "Type": "Microsoft.AspNetCore.Server.Kestrel.ServerAddress" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "GetPeerIPEndPoint", + "Parameters": [], + "ReturnType": "System.Net.IPEndPoint", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "GetSockIPEndPoint", + "Parameters": [], + "ReturnType": "System.Net.IPEndPoint", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "Open", + "Parameters": [ + { + "Name": "hSocket", + "Type": "System.IntPtr" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "NoDelay", + "Parameters": [ + { + "Name": "enable", + "Type": "System.Boolean" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "CreateIPEndpoint", + "Parameters": [ + { + "Name": "address", + "Type": "Microsoft.AspNetCore.Server.Kestrel.ServerAddress" + } + ], + "ReturnType": "System.Net.IPEndPoint", + "Static": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [ + { + "Name": "logger", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IKestrelTrace" + } + ], + "Visibility": "Public", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvWriteReq", + "Visibility": "Public", + "Kind": "Class", + "BaseType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvRequest", + "ImplementedInterfaces": [], + "Members": [ + { + "Kind": "Method", + "Name": "Init", + "Parameters": [ + { + "Name": "loop", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvLoopHandle" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "Write", + "Parameters": [ + { + "Name": "handle", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle" + }, + { + "Name": "start", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolIterator" + }, + { + "Name": "end", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolIterator" + }, + { + "Name": "nBuffers", + "Type": "System.Int32" + }, + { + "Name": "callback", + "Type": "System.Action" + }, + { + "Name": "state", + "Type": "System.Object" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "Write2", + "Parameters": [ + { + "Name": "handle", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle" + }, + { + "Name": "bufs", + "Type": "System.ArraySegment>" + }, + { + "Name": "sendHandle", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle" + }, + { + "Name": "callback", + "Type": "System.Action" + }, + { + "Name": "state", + "Type": "System.Object" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [ + { + "Name": "logger", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IKestrelTrace" + } + ], + "Visibility": "Public", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IKestrelTrace", + "Visibility": "Public", + "Kind": "Interface", + "Abstract": true, + "ImplementedInterfaces": [ + "Microsoft.Extensions.Logging.ILogger" + ], + "Members": [ + { + "Kind": "Method", + "Name": "ConnectionStart", + "Parameters": [ + { + "Name": "connectionId", + "Type": "System.String" + } + ], + "ReturnType": "System.Void", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "ConnectionStop", + "Parameters": [ + { + "Name": "connectionId", + "Type": "System.String" + } + ], + "ReturnType": "System.Void", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "ConnectionRead", + "Parameters": [ + { + "Name": "connectionId", + "Type": "System.String" + }, + { + "Name": "count", + "Type": "System.Int32" + } + ], + "ReturnType": "System.Void", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "ConnectionPause", + "Parameters": [ + { + "Name": "connectionId", + "Type": "System.String" + } + ], + "ReturnType": "System.Void", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "ConnectionResume", + "Parameters": [ + { + "Name": "connectionId", + "Type": "System.String" + } + ], + "ReturnType": "System.Void", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "ConnectionReadFin", + "Parameters": [ + { + "Name": "connectionId", + "Type": "System.String" + } + ], + "ReturnType": "System.Void", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "ConnectionWriteFin", + "Parameters": [ + { + "Name": "connectionId", + "Type": "System.String" + } + ], + "ReturnType": "System.Void", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "ConnectionWroteFin", + "Parameters": [ + { + "Name": "connectionId", + "Type": "System.String" + }, + { + "Name": "status", + "Type": "System.Int32" + } + ], + "ReturnType": "System.Void", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "ConnectionKeepAlive", + "Parameters": [ + { + "Name": "connectionId", + "Type": "System.String" + } + ], + "ReturnType": "System.Void", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "ConnectionDisconnect", + "Parameters": [ + { + "Name": "connectionId", + "Type": "System.String" + } + ], + "ReturnType": "System.Void", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "ConnectionWrite", + "Parameters": [ + { + "Name": "connectionId", + "Type": "System.String" + }, + { + "Name": "count", + "Type": "System.Int32" + } + ], + "ReturnType": "System.Void", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "ConnectionWriteCallback", + "Parameters": [ + { + "Name": "connectionId", + "Type": "System.String" + }, + { + "Name": "status", + "Type": "System.Int32" + } + ], + "ReturnType": "System.Void", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "ConnectionError", + "Parameters": [ + { + "Name": "connectionId", + "Type": "System.String" + }, + { + "Name": "ex", + "Type": "System.Exception" + } + ], + "ReturnType": "System.Void", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "ConnectionDisconnectedWrite", + "Parameters": [ + { + "Name": "connectionId", + "Type": "System.String" + }, + { + "Name": "count", + "Type": "System.Int32" + }, + { + "Name": "ex", + "Type": "System.Exception" + } + ], + "ReturnType": "System.Void", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "ConnectionBadRequest", + "Parameters": [ + { + "Name": "connectionId", + "Type": "System.String" + }, + { + "Name": "ex", + "Type": "Microsoft.AspNetCore.Server.Kestrel.BadHttpRequestException" + } + ], + "ReturnType": "System.Void", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "NotAllConnectionsClosedGracefully", + "Parameters": [], + "ReturnType": "System.Void", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "ApplicationError", + "Parameters": [ + { + "Name": "connectionId", + "Type": "System.String" + }, + { + "Name": "ex", + "Type": "System.Exception" + } + ], + "ReturnType": "System.Void", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IThreadPool", + "Visibility": "Public", + "Kind": "Interface", + "Abstract": true, + "ImplementedInterfaces": [], + "Members": [ + { + "Kind": "Method", + "Name": "Complete", + "Parameters": [ + { + "Name": "tcs", + "Type": "System.Threading.Tasks.TaskCompletionSource" + } + ], + "ReturnType": "System.Void", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "Cancel", + "Parameters": [ + { + "Name": "tcs", + "Type": "System.Threading.Tasks.TaskCompletionSource" + } + ], + "ReturnType": "System.Void", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "Error", + "Parameters": [ + { + "Name": "tcs", + "Type": "System.Threading.Tasks.TaskCompletionSource" + }, + { + "Name": "ex", + "Type": "System.Exception" + } + ], + "ReturnType": "System.Void", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "Run", + "Parameters": [ + { + "Name": "action", + "Type": "System.Action" + } + ], + "ReturnType": "System.Void", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.LoggingThreadPool", + "Visibility": "Public", + "Kind": "Class", + "ImplementedInterfaces": [ + "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IThreadPool" + ], + "Members": [ + { + "Kind": "Method", + "Name": "Run", + "Parameters": [ + { + "Name": "action", + "Type": "System.Action" + } + ], + "ReturnType": "System.Void", + "Sealed": true, + "Virtual": true, + "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IThreadPool", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "Complete", + "Parameters": [ + { + "Name": "tcs", + "Type": "System.Threading.Tasks.TaskCompletionSource" + } + ], + "ReturnType": "System.Void", + "Sealed": true, + "Virtual": true, + "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IThreadPool", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "Cancel", + "Parameters": [ + { + "Name": "tcs", + "Type": "System.Threading.Tasks.TaskCompletionSource" + } + ], + "ReturnType": "System.Void", + "Sealed": true, + "Virtual": true, + "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IThreadPool", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "Error", + "Parameters": [ + { + "Name": "tcs", + "Type": "System.Threading.Tasks.TaskCompletionSource" + }, + { + "Name": "ex", + "Type": "System.Exception" + } + ], + "ReturnType": "System.Void", + "Sealed": true, + "Virtual": true, + "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IThreadPool", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [ + { + "Name": "log", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IKestrelTrace" + } + ], + "Visibility": "Public", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPool", + "Visibility": "Public", + "Kind": "Class", + "ImplementedInterfaces": [ + "System.IDisposable" + ], + "Members": [ + { + "Kind": "Method", + "Name": "Lease", + "Parameters": [], + "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolBlock", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "Return", + "Parameters": [ + { + "Name": "block", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolBlock" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "Dispose", + "Parameters": [ + { + "Name": "disposing", + "Type": "System.Boolean" + } + ], + "ReturnType": "System.Void", + "Virtual": true, + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "Dispose", + "Parameters": [], + "ReturnType": "System.Void", + "Sealed": true, + "Virtual": true, + "ImplementedInterface": "System.IDisposable", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [], + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Field", + "Name": "MaxPooledBlockLength", + "Parameters": [], + "ReturnType": "System.Int32", + "Static": true, + "Visibility": "Public", + "GenericParameter": [], + "Constant": true, + "Literal": "4032" + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolBlock", + "Visibility": "Public", + "Kind": "Class", + "ImplementedInterfaces": [], + "Members": [ + { + "Kind": "Method", + "Name": "get_Pool", + "Parameters": [], + "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPool", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_Slab", + "Parameters": [], + "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolSlab", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_Array", + "Parameters": [], + "ReturnType": "System.Byte[]", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "Finalize", + "Parameters": [], + "ReturnType": "System.Void", + "Virtual": true, + "Override": true, + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "Reset", + "Parameters": [], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "ToString", + "Parameters": [], + "ReturnType": "System.String", + "Virtual": true, + "Override": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "GetIterator", + "Parameters": [], + "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolIterator", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [ + { + "Name": "dataArrayPtr", + "Type": "System.IntPtr" + } + ], + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Field", + "Name": "DataArrayPtr", + "Parameters": [], + "ReturnType": "System.IntPtr", + "ReadOnly": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Field", + "Name": "Data", + "Parameters": [], + "ReturnType": "System.ArraySegment", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Field", + "Name": "Start", + "Parameters": [], + "ReturnType": "System.Int32", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Field", + "Name": "End", + "Parameters": [], + "ReturnType": "System.Int32", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Field", + "Name": "Next", + "Parameters": [], + "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolBlock", + "Visibility": "Public", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolIterator", + "Visibility": "Public", + "Kind": "Struct", + "Sealed": true, + "ImplementedInterfaces": [], + "Members": [ + { + "Kind": "Method", + "Name": "get_IsDefault", + "Parameters": [], + "ReturnType": "System.Boolean", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_IsEnd", + "Parameters": [], + "ReturnType": "System.Boolean", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_Block", + "Parameters": [], + "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolBlock", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_Index", + "Parameters": [], + "ReturnType": "System.Int32", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "Take", + "Parameters": [], + "ReturnType": "System.Int32", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "Skip", + "Parameters": [ + { + "Name": "bytesToSkip", + "Type": "System.Int32" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "Peek", + "Parameters": [], + "ReturnType": "System.Int32", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "PeekLong", + "Parameters": [], + "ReturnType": "System.Int64", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "Seek", + "Parameters": [ + { + "Name": "byte0Vector", + "Type": "System.Numerics.Vector`1[[System.Byte, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]]", + "Direction": "Ref" + } + ], + "ReturnType": "System.Int32", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "Seek", + "Parameters": [ + { + "Name": "byte0Vector", + "Type": "System.Numerics.Vector`1[[System.Byte, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]]", + "Direction": "Ref" + }, + { + "Name": "byte1Vector", + "Type": "System.Numerics.Vector`1[[System.Byte, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]]", + "Direction": "Ref" + } + ], + "ReturnType": "System.Int32", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "Seek", + "Parameters": [ + { + "Name": "byte0Vector", + "Type": "System.Numerics.Vector`1[[System.Byte, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]]", + "Direction": "Ref" + }, + { + "Name": "byte1Vector", + "Type": "System.Numerics.Vector`1[[System.Byte, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]]", + "Direction": "Ref" + }, + { + "Name": "byte2Vector", + "Type": "System.Numerics.Vector`1[[System.Byte, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]]", + "Direction": "Ref" + } + ], + "ReturnType": "System.Int32", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "Put", + "Parameters": [ + { + "Name": "data", + "Type": "System.Byte" + } + ], + "ReturnType": "System.Boolean", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "GetLength", + "Parameters": [ + { + "Name": "end", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolIterator" + } + ], + "ReturnType": "System.Int32", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "CopyTo", + "Parameters": [ + { + "Name": "array", + "Type": "System.Byte[]" + }, + { + "Name": "offset", + "Type": "System.Int32" + }, + { + "Name": "count", + "Type": "System.Int32" + }, + { + "Name": "actual", + "Type": "System.Int32", + "Direction": "Out" + } + ], + "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolIterator", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "CopyFrom", + "Parameters": [ + { + "Name": "data", + "Type": "System.Byte[]" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "CopyFrom", + "Parameters": [ + { + "Name": "buffer", + "Type": "System.ArraySegment" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "CopyFrom", + "Parameters": [ + { + "Name": "data", + "Type": "System.Byte[]" + }, + { + "Name": "offset", + "Type": "System.Int32" + }, + { + "Name": "count", + "Type": "System.Int32" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "CopyFromAscii", + "Parameters": [ + { + "Name": "data", + "Type": "System.String" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [ + { + "Name": "block", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolBlock" + } + ], + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [ + { + "Name": "block", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolBlock" + }, + { + "Name": "index", + "Type": "System.Int32" + } + ], + "Visibility": "Public", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolIteratorExtensions", + "Visibility": "Public", + "Kind": "Class", + "Abstract": true, + "Static": true, + "Sealed": true, + "ImplementedInterfaces": [], + "Members": [ + { + "Kind": "Method", + "Name": "GetAsciiString", + "Parameters": [ + { + "Name": "start", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolIterator" + }, + { + "Name": "end", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolIterator" + } + ], + "ReturnType": "System.String", + "Static": true, + "Extension": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "GetUtf8String", + "Parameters": [ + { + "Name": "start", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolIterator" + }, + { + "Name": "end", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolIterator" + } + ], + "ReturnType": "System.String", + "Static": true, + "Extension": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "GetArraySegment", + "Parameters": [ + { + "Name": "start", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolIterator" + }, + { + "Name": "end", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolIterator" + } + ], + "ReturnType": "System.ArraySegment", + "Static": true, + "Extension": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "GetKnownMethod", + "Parameters": [ + { + "Name": "begin", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolIterator" + }, + { + "Name": "knownMethod", + "Type": "System.String", + "Direction": "Out" + } + ], + "ReturnType": "System.Boolean", + "Static": true, + "Extension": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "GetKnownVersion", + "Parameters": [ + { + "Name": "begin", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolIterator" + }, + { + "Name": "knownVersion", + "Type": "System.String", + "Direction": "Out" + } + ], + "ReturnType": "System.Boolean", + "Static": true, + "Extension": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Field", + "Name": "HttpConnectMethod", + "Parameters": [], + "ReturnType": "System.String", + "Static": true, + "Visibility": "Public", + "GenericParameter": [], + "Constant": true, + "Literal": "\"CONNECT\"" + }, + { + "Kind": "Field", + "Name": "HttpDeleteMethod", + "Parameters": [], + "ReturnType": "System.String", + "Static": true, + "Visibility": "Public", + "GenericParameter": [], + "Constant": true, + "Literal": "\"DELETE\"" + }, + { + "Kind": "Field", + "Name": "HttpGetMethod", + "Parameters": [], + "ReturnType": "System.String", + "Static": true, + "Visibility": "Public", + "GenericParameter": [], + "Constant": true, + "Literal": "\"GET\"" + }, + { + "Kind": "Field", + "Name": "HttpHeadMethod", + "Parameters": [], + "ReturnType": "System.String", + "Static": true, + "Visibility": "Public", + "GenericParameter": [], + "Constant": true, + "Literal": "\"HEAD\"" + }, + { + "Kind": "Field", + "Name": "HttpPatchMethod", + "Parameters": [], + "ReturnType": "System.String", + "Static": true, + "Visibility": "Public", + "GenericParameter": [], + "Constant": true, + "Literal": "\"PATCH\"" + }, + { + "Kind": "Field", + "Name": "HttpPostMethod", + "Parameters": [], + "ReturnType": "System.String", + "Static": true, + "Visibility": "Public", + "GenericParameter": [], + "Constant": true, + "Literal": "\"POST\"" + }, + { + "Kind": "Field", + "Name": "HttpPutMethod", + "Parameters": [], + "ReturnType": "System.String", + "Static": true, + "Visibility": "Public", + "GenericParameter": [], + "Constant": true, + "Literal": "\"PUT\"" + }, + { + "Kind": "Field", + "Name": "HttpOptionsMethod", + "Parameters": [], + "ReturnType": "System.String", + "Static": true, + "Visibility": "Public", + "GenericParameter": [], + "Constant": true, + "Literal": "\"OPTIONS\"" + }, + { + "Kind": "Field", + "Name": "HttpTraceMethod", + "Parameters": [], + "ReturnType": "System.String", + "Static": true, + "Visibility": "Public", + "GenericParameter": [], + "Constant": true, + "Literal": "\"TRACE\"" + }, + { + "Kind": "Field", + "Name": "Http10Version", + "Parameters": [], + "ReturnType": "System.String", + "Static": true, + "Visibility": "Public", + "GenericParameter": [], + "Constant": true, + "Literal": "\"HTTP/1.0\"" + }, + { + "Kind": "Field", + "Name": "Http11Version", + "Parameters": [], + "ReturnType": "System.String", + "Static": true, + "Visibility": "Public", + "GenericParameter": [], + "Constant": true, + "Literal": "\"HTTP/1.1\"" + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolSlab", + "Visibility": "Public", + "Kind": "Class", + "ImplementedInterfaces": [ + "System.IDisposable" + ], + "Members": [ + { + "Kind": "Method", + "Name": "Create", + "Parameters": [ + { + "Name": "length", + "Type": "System.Int32" + } + ], + "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolSlab", + "Static": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "Dispose", + "Parameters": [ + { + "Name": "disposing", + "Type": "System.Boolean" + } + ], + "ReturnType": "System.Void", + "Virtual": true, + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "Finalize", + "Parameters": [], + "ReturnType": "System.Void", + "Virtual": true, + "Override": true, + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "Dispose", + "Parameters": [], + "ReturnType": "System.Void", + "Sealed": true, + "Virtual": true, + "ImplementedInterface": "System.IDisposable", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [], + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Field", + "Name": "Array", + "Parameters": [], + "ReturnType": "System.Byte[]", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Field", + "Name": "ArrayPtr", + "Parameters": [], + "ReturnType": "System.IntPtr", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Field", + "Name": "IsActive", + "Parameters": [], + "ReturnType": "System.Boolean", + "Visibility": "Public", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.TaskUtilities", + "Visibility": "Public", + "Kind": "Class", + "Abstract": true, + "Static": true, + "Sealed": true, + "ImplementedInterfaces": [], + "Members": [ + { + "Kind": "Method", + "Name": "GetCancelledTask", + "Parameters": [ + { + "Name": "cancellationToken", + "Type": "System.Threading.CancellationToken" + } + ], + "ReturnType": "System.Threading.Tasks.Task", + "Static": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "GetCancelledZeroTask", + "Parameters": [ + { + "Name": "cancellationToken", + "Type": "System.Threading.CancellationToken", + "DefaultValue": "default(System.Threading.CancellationToken)" + } + ], + "ReturnType": "System.Threading.Tasks.Task", + "Static": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Field", + "Name": "CompletedTask", + "Parameters": [], + "ReturnType": "System.Threading.Tasks.Task", + "Static": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Field", + "Name": "ZeroTask", + "Parameters": [], + "ReturnType": "System.Threading.Tasks.Task", + "Static": true, + "Visibility": "Public", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.BufferSizeControl", + "Visibility": "Public", + "Kind": "Class", + "ImplementedInterfaces": [ + "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.IBufferSizeControl" + ], + "Members": [ + { + "Kind": "Method", + "Name": "Add", + "Parameters": [ + { + "Name": "count", + "Type": "System.Int32" + } + ], + "ReturnType": "System.Void", + "Sealed": true, + "Virtual": true, + "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.IBufferSizeControl", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "Subtract", + "Parameters": [ + { + "Name": "count", + "Type": "System.Int32" + } + ], + "ReturnType": "System.Void", + "Sealed": true, + "Virtual": true, + "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.IBufferSizeControl", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [ + { + "Name": "maxSize", + "Type": "System.Int64" + }, + { + "Name": "connectionControl", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.IConnectionControl" + }, + { + "Name": "connectionThread", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.KestrelThread" + } + ], + "Visibility": "Public", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ChunkWriter", + "Visibility": "Public", + "Kind": "Class", + "Abstract": true, + "Static": true, + "Sealed": true, + "ImplementedInterfaces": [], + "Members": [ + { + "Kind": "Method", + "Name": "BeginChunkBytes", + "Parameters": [ + { + "Name": "dataCount", + "Type": "System.Int32" + } + ], + "ReturnType": "System.ArraySegment", + "Static": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "WriteBeginChunkBytes", + "Parameters": [ + { + "Name": "start", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolIterator", + "Direction": "Ref" + }, + { + "Name": "dataCount", + "Type": "System.Int32" + } + ], + "ReturnType": "System.Int32", + "Static": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "WriteEndChunkBytes", + "Parameters": [ + { + "Name": "start", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolIterator", + "Direction": "Ref" + } + ], + "ReturnType": "System.Void", + "Static": true, + "Visibility": "Public", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.Connection", + "Visibility": "Public", + "Kind": "Class", + "BaseType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ConnectionContext", + "ImplementedInterfaces": [ + "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.IConnectionControl" + ], + "Members": [ + { + "Kind": "Method", + "Name": "Start", + "Parameters": [], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "StopAsync", + "Parameters": [], + "ReturnType": "System.Threading.Tasks.Task", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "Abort", + "Parameters": [], + "ReturnType": "System.Void", + "Virtual": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "OnSocketClosed", + "Parameters": [], + "ReturnType": "System.Void", + "Virtual": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [ + { + "Name": "context", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ListenerContext" + }, + { + "Name": "socket", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle" + } + ], + "Visibility": "Public", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ConnectionContext", + "Visibility": "Public", + "Kind": "Class", + "BaseType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ListenerContext", + "ImplementedInterfaces": [], + "Members": [ + { + "Kind": "Method", + "Name": "get_SocketInput", + "Parameters": [], + "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.SocketInput", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_SocketInput", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.SocketInput" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_SocketOutput", + "Parameters": [], + "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ISocketOutput", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_SocketOutput", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ISocketOutput" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_ConnectionControl", + "Parameters": [], + "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.IConnectionControl", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_ConnectionControl", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.IConnectionControl" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_RemoteEndPoint", + "Parameters": [], + "ReturnType": "System.Net.IPEndPoint", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_RemoteEndPoint", + "Parameters": [ + { + "Name": "value", + "Type": "System.Net.IPEndPoint" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_LocalEndPoint", + "Parameters": [], + "ReturnType": "System.Net.IPEndPoint", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_LocalEndPoint", + "Parameters": [ + { + "Name": "value", + "Type": "System.Net.IPEndPoint" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_ConnectionId", + "Parameters": [], + "ReturnType": "System.String", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_ConnectionId", + "Parameters": [ + { + "Name": "value", + "Type": "System.String" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_PrepareRequest", + "Parameters": [], + "ReturnType": "System.Action", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_PrepareRequest", + "Parameters": [ + { + "Name": "value", + "Type": "System.Action" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [], + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [ + { + "Name": "context", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ListenerContext" + } + ], + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [ + { + "Name": "context", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ConnectionContext" + } + ], + "Visibility": "Public", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ConnectionManager", + "Visibility": "Public", + "Kind": "Class", + "ImplementedInterfaces": [], + "Members": [ + { + "Kind": "Method", + "Name": "WalkConnectionsAndClose", + "Parameters": [], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "WaitForConnectionCloseAsync", + "Parameters": [], + "ReturnType": "System.Threading.Tasks.Task", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [ + { + "Name": "thread", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.KestrelThread" + } + ], + "Visibility": "Public", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.DateHeaderValueManager", + "Visibility": "Public", + "Kind": "Class", + "ImplementedInterfaces": [ + "System.IDisposable" + ], + "Members": [ + { + "Kind": "Method", + "Name": "GetDateHeaderValues", + "Parameters": [], + "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.DateHeaderValueManager+DateHeaderValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "Dispose", + "Parameters": [], + "ReturnType": "System.Void", + "Sealed": true, + "Virtual": true, + "ImplementedInterface": "System.IDisposable", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [], + "Visibility": "Public", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.Frame", + "Visibility": "Public", + "Kind": "Class", + "Abstract": true, + "BaseType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ConnectionContext", + "ImplementedInterfaces": [ + "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.IFrameControl", + "Microsoft.AspNetCore.Http.Features.IFeatureCollection", + "Microsoft.AspNetCore.Http.Features.IHttpRequestFeature", + "Microsoft.AspNetCore.Http.Features.IHttpResponseFeature", + "Microsoft.AspNetCore.Http.Features.IHttpUpgradeFeature", + "Microsoft.AspNetCore.Http.Features.IHttpConnectionFeature", + "Microsoft.AspNetCore.Http.Features.IHttpRequestLifetimeFeature" + ], + "Members": [ + { + "Kind": "Method", + "Name": "get_ConnectionIdFeature", + "Parameters": [], + "ReturnType": "System.String", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_ConnectionIdFeature", + "Parameters": [ + { + "Name": "value", + "Type": "System.String" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_RemoteIpAddress", + "Parameters": [], + "ReturnType": "System.Net.IPAddress", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_RemoteIpAddress", + "Parameters": [ + { + "Name": "value", + "Type": "System.Net.IPAddress" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_RemotePort", + "Parameters": [], + "ReturnType": "System.Int32", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_RemotePort", + "Parameters": [ + { + "Name": "value", + "Type": "System.Int32" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_LocalIpAddress", + "Parameters": [], + "ReturnType": "System.Net.IPAddress", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_LocalIpAddress", + "Parameters": [ + { + "Name": "value", + "Type": "System.Net.IPAddress" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_LocalPort", + "Parameters": [], + "ReturnType": "System.Int32", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_LocalPort", + "Parameters": [ + { + "Name": "value", + "Type": "System.Int32" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_Scheme", + "Parameters": [], + "ReturnType": "System.String", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_Scheme", + "Parameters": [ + { + "Name": "value", + "Type": "System.String" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_Method", + "Parameters": [], + "ReturnType": "System.String", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_Method", + "Parameters": [ + { + "Name": "value", + "Type": "System.String" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_PathBase", + "Parameters": [], + "ReturnType": "System.String", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_PathBase", + "Parameters": [ + { + "Name": "value", + "Type": "System.String" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_Path", + "Parameters": [], + "ReturnType": "System.String", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_Path", + "Parameters": [ + { + "Name": "value", + "Type": "System.String" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_QueryString", + "Parameters": [], + "ReturnType": "System.String", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_QueryString", + "Parameters": [ + { + "Name": "value", + "Type": "System.String" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_RawTarget", + "Parameters": [], + "ReturnType": "System.String", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_RawTarget", + "Parameters": [ + { + "Name": "value", + "Type": "System.String" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HttpVersion", + "Parameters": [], + "ReturnType": "System.String", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HttpVersion", + "Parameters": [ + { + "Name": "value", + "Type": "System.String" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_RequestHeaders", + "Parameters": [], + "ReturnType": "Microsoft.AspNetCore.Http.IHeaderDictionary", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_RequestHeaders", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.AspNetCore.Http.IHeaderDictionary" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_RequestBody", + "Parameters": [], + "ReturnType": "System.IO.Stream", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_RequestBody", + "Parameters": [ + { + "Name": "value", + "Type": "System.IO.Stream" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_StatusCode", + "Parameters": [], + "ReturnType": "System.Int32", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_StatusCode", + "Parameters": [ + { + "Name": "value", + "Type": "System.Int32" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_ReasonPhrase", + "Parameters": [], + "ReturnType": "System.String", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_ReasonPhrase", + "Parameters": [ + { + "Name": "value", + "Type": "System.String" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_ResponseHeaders", + "Parameters": [], + "ReturnType": "Microsoft.AspNetCore.Http.IHeaderDictionary", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_ResponseHeaders", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.AspNetCore.Http.IHeaderDictionary" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_ResponseBody", + "Parameters": [], + "ReturnType": "System.IO.Stream", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_ResponseBody", + "Parameters": [ + { + "Name": "value", + "Type": "System.IO.Stream" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_DuplexStream", + "Parameters": [], + "ReturnType": "System.IO.Stream", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_DuplexStream", + "Parameters": [ + { + "Name": "value", + "Type": "System.IO.Stream" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_RequestAborted", + "Parameters": [], + "ReturnType": "System.Threading.CancellationToken", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_RequestAborted", + "Parameters": [ + { + "Name": "value", + "Type": "System.Threading.CancellationToken" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HasResponseStarted", + "Parameters": [], + "ReturnType": "System.Boolean", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_FrameRequestHeaders", + "Parameters": [], + "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.FrameRequestHeaders", + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_FrameResponseHeaders", + "Parameters": [], + "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.FrameResponseHeaders", + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "InitializeHeaders", + "Parameters": [], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "InitializeStreams", + "Parameters": [ + { + "Name": "messageBody", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.MessageBody" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "PauseStreams", + "Parameters": [], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "ResumeStreams", + "Parameters": [], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "StopStreams", + "Parameters": [], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "Reset", + "Parameters": [], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "Start", + "Parameters": [], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "Stop", + "Parameters": [], + "ReturnType": "System.Threading.Tasks.Task", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "Abort", + "Parameters": [], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "RequestProcessingAsync", + "Parameters": [], + "ReturnType": "System.Threading.Tasks.Task", + "Virtual": true, + "Abstract": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "OnStarting", + "Parameters": [ + { + "Name": "callback", + "Type": "System.Func" + }, + { + "Name": "state", + "Type": "System.Object" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "OnCompleted", + "Parameters": [ + { + "Name": "callback", + "Type": "System.Func" + }, + { + "Name": "state", + "Type": "System.Object" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "FireOnStarting", + "Parameters": [], + "ReturnType": "System.Threading.Tasks.Task", + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "FireOnCompleted", + "Parameters": [], + "ReturnType": "System.Threading.Tasks.Task", + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "Flush", + "Parameters": [], + "ReturnType": "System.Void", + "Sealed": true, + "Virtual": true, + "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.IFrameControl", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "FlushAsync", + "Parameters": [ + { + "Name": "cancellationToken", + "Type": "System.Threading.CancellationToken" + } + ], + "ReturnType": "System.Threading.Tasks.Task", + "Sealed": true, + "Virtual": true, + "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.IFrameControl", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "Write", + "Parameters": [ + { + "Name": "data", + "Type": "System.ArraySegment" + } + ], + "ReturnType": "System.Void", + "Sealed": true, + "Virtual": true, + "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.IFrameControl", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "WriteAsync", + "Parameters": [ + { + "Name": "data", + "Type": "System.ArraySegment" + }, + { + "Name": "cancellationToken", + "Type": "System.Threading.CancellationToken" + } + ], + "ReturnType": "System.Threading.Tasks.Task", + "Sealed": true, + "Virtual": true, + "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.IFrameControl", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "WriteAsyncAwaited", + "Parameters": [ + { + "Name": "data", + "Type": "System.ArraySegment" + }, + { + "Name": "cancellationToken", + "Type": "System.Threading.CancellationToken" + } + ], + "ReturnType": "System.Threading.Tasks.Task", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "ProduceContinue", + "Parameters": [], + "ReturnType": "System.Void", + "Sealed": true, + "Virtual": true, + "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.IFrameControl", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "ProduceStartAndFireOnStarting", + "Parameters": [], + "ReturnType": "System.Threading.Tasks.Task", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "TryProduceInvalidRequestResponse", + "Parameters": [], + "ReturnType": "System.Threading.Tasks.Task", + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "ProduceEnd", + "Parameters": [], + "ReturnType": "System.Threading.Tasks.Task", + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "TakeStartLine", + "Parameters": [ + { + "Name": "input", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.SocketInput" + } + ], + "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.Frame+RequestLineStatus", + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "TakeMessageHeaders", + "Parameters": [ + { + "Name": "input", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.SocketInput" + }, + { + "Name": "requestHeaders", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.FrameRequestHeaders" + } + ], + "ReturnType": "System.Boolean", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "StatusCanHaveBody", + "Parameters": [ + { + "Name": "statusCode", + "Type": "System.Int32" + } + ], + "ReturnType": "System.Boolean", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "RejectRequest", + "Parameters": [ + { + "Name": "message", + "Type": "System.String" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "SetBadRequestState", + "Parameters": [ + { + "Name": "ex", + "Type": "Microsoft.AspNetCore.Server.Kestrel.BadHttpRequestException" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "ReportApplicationError", + "Parameters": [ + { + "Name": "ex", + "Type": "System.Exception" + } + ], + "ReturnType": "System.Void", + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "ResetFeatureCollection", + "Parameters": [], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_FrameControl", + "Parameters": [], + "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.IFrameControl", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_FrameControl", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.IFrameControl" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [ + { + "Name": "context", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ConnectionContext" + } + ], + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Field", + "Name": "_requestRejected", + "Parameters": [], + "ReturnType": "System.Boolean", + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Field", + "Name": "_onStarting", + "Parameters": [], + "ReturnType": "System.Collections.Generic.List, System.Object>>", + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Field", + "Name": "_onCompleted", + "Parameters": [], + "ReturnType": "System.Collections.Generic.List, System.Object>>", + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Field", + "Name": "_requestProcessingStopping", + "Parameters": [], + "ReturnType": "System.Boolean", + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Field", + "Name": "_requestAborted", + "Parameters": [], + "ReturnType": "System.Int32", + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Field", + "Name": "_requestProcessingStatus", + "Parameters": [], + "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.Frame+RequestProcessingStatus", + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Field", + "Name": "_keepAlive", + "Parameters": [], + "ReturnType": "System.Boolean", + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Field", + "Name": "_applicationException", + "Parameters": [], + "ReturnType": "System.Exception", + "Visibility": "Protected", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.FrameHeaders", + "Visibility": "Public", + "Kind": "Class", + "Abstract": true, + "ImplementedInterfaces": [ + "Microsoft.AspNetCore.Http.IHeaderDictionary" + ], + "Members": [ + { + "Kind": "Method", + "Name": "get_Unknown", + "Parameters": [], + "ReturnType": "System.Collections.Generic.Dictionary", + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "ThrowReadOnlyException", + "Parameters": [], + "ReturnType": "System.Void", + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "ThrowArgumentException", + "Parameters": [], + "ReturnType": "System.Void", + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "ThrowKeyNotFoundException", + "Parameters": [], + "ReturnType": "System.Void", + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "ThrowDuplicateKeyException", + "Parameters": [], + "ReturnType": "System.Void", + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "SetReadOnly", + "Parameters": [], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "Reset", + "Parameters": [], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "AppendValue", + "Parameters": [ + { + "Name": "existing", + "Type": "Microsoft.Extensions.Primitives.StringValues" + }, + { + "Name": "append", + "Type": "System.String" + } + ], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Static": true, + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "BitCount", + "Parameters": [ + { + "Name": "value", + "Type": "System.Int64" + } + ], + "ReturnType": "System.Int32", + "Static": true, + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "GetCountFast", + "Parameters": [], + "ReturnType": "System.Int32", + "Virtual": true, + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "GetValueFast", + "Parameters": [ + { + "Name": "key", + "Type": "System.String" + } + ], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Virtual": true, + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "TryGetValueFast", + "Parameters": [ + { + "Name": "key", + "Type": "System.String" + }, + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues", + "Direction": "Out" + } + ], + "ReturnType": "System.Boolean", + "Virtual": true, + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "SetValueFast", + "Parameters": [ + { + "Name": "key", + "Type": "System.String" + }, + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Virtual": true, + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "AddValueFast", + "Parameters": [ + { + "Name": "key", + "Type": "System.String" + }, + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Virtual": true, + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "RemoveFast", + "Parameters": [ + { + "Name": "key", + "Type": "System.String" + } + ], + "ReturnType": "System.Boolean", + "Virtual": true, + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "ClearFast", + "Parameters": [], + "ReturnType": "System.Void", + "Virtual": true, + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "CopyToFast", + "Parameters": [ + { + "Name": "array", + "Type": "System.Collections.Generic.KeyValuePair[]" + }, + { + "Name": "arrayIndex", + "Type": "System.Int32" + } + ], + "ReturnType": "System.Void", + "Virtual": true, + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "GetEnumeratorFast", + "Parameters": [], + "ReturnType": "System.Collections.Generic.IEnumerator>", + "Virtual": true, + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "ValidateHeaderCharacters", + "Parameters": [ + { + "Name": "headerValues", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Static": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "ValidateHeaderCharacters", + "Parameters": [ + { + "Name": "headerCharacters", + "Type": "System.String" + } + ], + "ReturnType": "System.Void", + "Static": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [], + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Field", + "Name": "_isReadOnly", + "Parameters": [], + "ReturnType": "System.Boolean", + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Field", + "Name": "MaybeUnknown", + "Parameters": [], + "ReturnType": "System.Collections.Generic.Dictionary", + "Visibility": "Protected", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.FrameRequestHeaders", + "Visibility": "Public", + "Kind": "Class", + "BaseType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.FrameHeaders", + "ImplementedInterfaces": [], + "Members": [ + { + "Kind": "Method", + "Name": "get_HeaderCacheControl", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderCacheControl", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HeaderConnection", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderConnection", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HeaderDate", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderDate", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HeaderKeepAlive", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderKeepAlive", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HeaderPragma", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderPragma", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HeaderTrailer", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderTrailer", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HeaderTransferEncoding", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderTransferEncoding", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HeaderUpgrade", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderUpgrade", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HeaderVia", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderVia", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HeaderWarning", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderWarning", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HeaderAllow", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderAllow", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HeaderContentLength", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderContentLength", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HeaderContentType", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderContentType", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HeaderContentEncoding", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderContentEncoding", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HeaderContentLanguage", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderContentLanguage", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HeaderContentLocation", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderContentLocation", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HeaderContentMD5", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderContentMD5", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HeaderContentRange", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderContentRange", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HeaderExpires", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderExpires", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HeaderLastModified", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderLastModified", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HeaderAccept", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderAccept", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HeaderAcceptCharset", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderAcceptCharset", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HeaderAcceptEncoding", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderAcceptEncoding", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HeaderAcceptLanguage", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderAcceptLanguage", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HeaderAuthorization", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderAuthorization", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HeaderCookie", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderCookie", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HeaderExpect", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderExpect", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HeaderFrom", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderFrom", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HeaderHost", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderHost", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HeaderIfMatch", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderIfMatch", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HeaderIfModifiedSince", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderIfModifiedSince", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HeaderIfNoneMatch", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderIfNoneMatch", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HeaderIfRange", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderIfRange", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HeaderIfUnmodifiedSince", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderIfUnmodifiedSince", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HeaderMaxForwards", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderMaxForwards", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HeaderProxyAuthorization", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderProxyAuthorization", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HeaderReferer", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderReferer", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HeaderRange", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderRange", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HeaderTE", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderTE", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HeaderTranslate", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderTranslate", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HeaderUserAgent", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderUserAgent", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HeaderOrigin", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderOrigin", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HeaderAccessControlRequestMethod", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderAccessControlRequestMethod", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HeaderAccessControlRequestHeaders", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderAccessControlRequestHeaders", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "GetCountFast", + "Parameters": [], + "ReturnType": "System.Int32", + "Virtual": true, + "Override": true, + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "GetValueFast", + "Parameters": [ + { + "Name": "key", + "Type": "System.String" + } + ], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Virtual": true, + "Override": true, + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "TryGetValueFast", + "Parameters": [ + { + "Name": "key", + "Type": "System.String" + }, + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues", + "Direction": "Out" + } + ], + "ReturnType": "System.Boolean", + "Virtual": true, + "Override": true, + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "SetValueFast", + "Parameters": [ + { + "Name": "key", + "Type": "System.String" + }, + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Virtual": true, + "Override": true, + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "AddValueFast", + "Parameters": [ + { + "Name": "key", + "Type": "System.String" + }, + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Virtual": true, + "Override": true, + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "RemoveFast", + "Parameters": [ + { + "Name": "key", + "Type": "System.String" + } + ], + "ReturnType": "System.Boolean", + "Virtual": true, + "Override": true, + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "ClearFast", + "Parameters": [], + "ReturnType": "System.Void", + "Virtual": true, + "Override": true, + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "CopyToFast", + "Parameters": [ + { + "Name": "array", + "Type": "System.Collections.Generic.KeyValuePair[]" + }, + { + "Name": "arrayIndex", + "Type": "System.Int32" + } + ], + "ReturnType": "System.Void", + "Virtual": true, + "Override": true, + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "Append", + "Parameters": [ + { + "Name": "keyBytes", + "Type": "System.Byte[]" + }, + { + "Name": "keyOffset", + "Type": "System.Int32" + }, + { + "Name": "keyLength", + "Type": "System.Int32" + }, + { + "Name": "value", + "Type": "System.String" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "GetEnumerator", + "Parameters": [], + "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.FrameRequestHeaders+Enumerator", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "GetEnumeratorFast", + "Parameters": [], + "ReturnType": "System.Collections.Generic.IEnumerator>", + "Virtual": true, + "Override": true, + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [], + "Visibility": "Public", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.FrameResponseHeaders", + "Visibility": "Public", + "Kind": "Class", + "BaseType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.FrameHeaders", + "ImplementedInterfaces": [], + "Members": [ + { + "Kind": "Method", + "Name": "get_HeaderCacheControl", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderCacheControl", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HeaderConnection", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderConnection", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HeaderDate", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderDate", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HeaderKeepAlive", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderKeepAlive", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HeaderPragma", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderPragma", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HeaderTrailer", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderTrailer", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HeaderTransferEncoding", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderTransferEncoding", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HeaderUpgrade", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderUpgrade", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HeaderVia", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderVia", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HeaderWarning", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderWarning", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HeaderAllow", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderAllow", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HeaderContentLength", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderContentLength", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HeaderContentType", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderContentType", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HeaderContentEncoding", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderContentEncoding", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HeaderContentLanguage", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderContentLanguage", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HeaderContentLocation", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderContentLocation", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HeaderContentMD5", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderContentMD5", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HeaderContentRange", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderContentRange", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HeaderExpires", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderExpires", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HeaderLastModified", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderLastModified", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HeaderAcceptRanges", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderAcceptRanges", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HeaderAge", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderAge", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HeaderETag", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderETag", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HeaderLocation", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderLocation", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HeaderProxyAutheticate", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderProxyAutheticate", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HeaderRetryAfter", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderRetryAfter", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HeaderServer", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderServer", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HeaderSetCookie", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderSetCookie", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HeaderVary", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderVary", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HeaderWWWAuthenticate", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderWWWAuthenticate", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HeaderAccessControlAllowCredentials", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderAccessControlAllowCredentials", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HeaderAccessControlAllowHeaders", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderAccessControlAllowHeaders", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HeaderAccessControlAllowMethods", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderAccessControlAllowMethods", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HeaderAccessControlAllowOrigin", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderAccessControlAllowOrigin", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HeaderAccessControlExposeHeaders", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderAccessControlExposeHeaders", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HeaderAccessControlMaxAge", + "Parameters": [], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_HeaderAccessControlMaxAge", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "SetRawConnection", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + }, + { + "Name": "raw", + "Type": "System.Byte[]" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "SetRawDate", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + }, + { + "Name": "raw", + "Type": "System.Byte[]" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "SetRawTransferEncoding", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + }, + { + "Name": "raw", + "Type": "System.Byte[]" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "SetRawContentLength", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + }, + { + "Name": "raw", + "Type": "System.Byte[]" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "SetRawServer", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + }, + { + "Name": "raw", + "Type": "System.Byte[]" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "GetCountFast", + "Parameters": [], + "ReturnType": "System.Int32", + "Virtual": true, + "Override": true, + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "GetValueFast", + "Parameters": [ + { + "Name": "key", + "Type": "System.String" + } + ], + "ReturnType": "Microsoft.Extensions.Primitives.StringValues", + "Virtual": true, + "Override": true, + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "TryGetValueFast", + "Parameters": [ + { + "Name": "key", + "Type": "System.String" + }, + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues", + "Direction": "Out" + } + ], + "ReturnType": "System.Boolean", + "Virtual": true, + "Override": true, + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "SetValueFast", + "Parameters": [ + { + "Name": "key", + "Type": "System.String" + }, + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Virtual": true, + "Override": true, + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "AddValueFast", + "Parameters": [ + { + "Name": "key", + "Type": "System.String" + }, + { + "Name": "value", + "Type": "Microsoft.Extensions.Primitives.StringValues" + } + ], + "ReturnType": "System.Void", + "Virtual": true, + "Override": true, + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "RemoveFast", + "Parameters": [ + { + "Name": "key", + "Type": "System.String" + } + ], + "ReturnType": "System.Boolean", + "Virtual": true, + "Override": true, + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "ClearFast", + "Parameters": [], + "ReturnType": "System.Void", + "Virtual": true, + "Override": true, + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "CopyToFast", + "Parameters": [ + { + "Name": "array", + "Type": "System.Collections.Generic.KeyValuePair[]" + }, + { + "Name": "arrayIndex", + "Type": "System.Int32" + } + ], + "ReturnType": "System.Void", + "Virtual": true, + "Override": true, + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "CopyToFast", + "Parameters": [ + { + "Name": "output", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolIterator", + "Direction": "Ref" + } + ], + "ReturnType": "System.Void", + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HasConnection", + "Parameters": [], + "ReturnType": "System.Boolean", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HasTransferEncoding", + "Parameters": [], + "ReturnType": "System.Boolean", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HasContentLength", + "Parameters": [], + "ReturnType": "System.Boolean", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HasServer", + "Parameters": [], + "ReturnType": "System.Boolean", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_HasDate", + "Parameters": [], + "ReturnType": "System.Boolean", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "GetEnumerator", + "Parameters": [], + "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.FrameResponseHeaders+Enumerator", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "GetEnumeratorFast", + "Parameters": [], + "ReturnType": "System.Collections.Generic.IEnumerator>", + "Virtual": true, + "Override": true, + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "CopyTo", + "Parameters": [ + { + "Name": "output", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolIterator", + "Direction": "Ref" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [], + "Visibility": "Public", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.Frame", + "Visibility": "Public", + "Kind": "Class", + "BaseType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.Frame", + "ImplementedInterfaces": [], + "Members": [ + { + "Kind": "Method", + "Name": "RequestProcessingAsync", + "Parameters": [], + "ReturnType": "System.Threading.Tasks.Task", + "Virtual": true, + "Override": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [ + { + "Name": "application", + "Type": "Microsoft.AspNetCore.Hosting.Server.IHttpApplication" + }, + { + "Name": "context", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ConnectionContext" + } + ], + "Visibility": "Public", + "GenericParameter": [] + } + ], + "GenericParameters": [ + { + "ParameterName": "TContext", + "ParameterPosition": 0, + "BaseTypeOrInterfaces": [] + } + ] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.IBufferSizeControl", + "Visibility": "Public", + "Kind": "Interface", + "Abstract": true, + "ImplementedInterfaces": [], + "Members": [ + { + "Kind": "Method", + "Name": "Add", + "Parameters": [ + { + "Name": "count", + "Type": "System.Int32" + } + ], + "ReturnType": "System.Void", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "Subtract", + "Parameters": [ + { + "Name": "count", + "Type": "System.Int32" + } + ], + "ReturnType": "System.Void", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.IConnectionControl", + "Visibility": "Public", + "Kind": "Interface", + "Abstract": true, + "ImplementedInterfaces": [], + "Members": [ + { + "Kind": "Method", + "Name": "Pause", + "Parameters": [], + "ReturnType": "System.Void", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "Resume", + "Parameters": [], + "ReturnType": "System.Void", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "End", + "Parameters": [ + { + "Name": "endType", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ProduceEndType" + } + ], + "ReturnType": "System.Void", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.IFrameControl", + "Visibility": "Public", + "Kind": "Interface", + "Abstract": true, + "ImplementedInterfaces": [], + "Members": [ + { + "Kind": "Method", + "Name": "ProduceContinue", + "Parameters": [], + "ReturnType": "System.Void", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "Write", + "Parameters": [ + { + "Name": "data", + "Type": "System.ArraySegment" + } + ], + "ReturnType": "System.Void", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "WriteAsync", + "Parameters": [ + { + "Name": "data", + "Type": "System.ArraySegment" + }, + { + "Name": "cancellationToken", + "Type": "System.Threading.CancellationToken" + } + ], + "ReturnType": "System.Threading.Tasks.Task", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "Flush", + "Parameters": [], + "ReturnType": "System.Void", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "FlushAsync", + "Parameters": [ + { + "Name": "cancellationToken", + "Type": "System.Threading.CancellationToken" + } + ], + "ReturnType": "System.Threading.Tasks.Task", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ISocketOutput", + "Visibility": "Public", + "Kind": "Interface", + "Abstract": true, + "ImplementedInterfaces": [], + "Members": [ + { + "Kind": "Method", + "Name": "Write", + "Parameters": [ + { + "Name": "buffer", + "Type": "System.ArraySegment" + }, + { + "Name": "chunk", + "Type": "System.Boolean", + "DefaultValue": "False" + } + ], + "ReturnType": "System.Void", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "WriteAsync", + "Parameters": [ + { + "Name": "buffer", + "Type": "System.ArraySegment" + }, + { + "Name": "chunk", + "Type": "System.Boolean", + "DefaultValue": "False" + }, + { + "Name": "cancellationToken", + "Type": "System.Threading.CancellationToken", + "DefaultValue": "default(System.Threading.CancellationToken)" + } + ], + "ReturnType": "System.Threading.Tasks.Task", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "ProducingStart", + "Parameters": [], + "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolIterator", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "ProducingComplete", + "Parameters": [ + { + "Name": "end", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolIterator" + } + ], + "ReturnType": "System.Void", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.Listener", + "Visibility": "Public", + "Kind": "Class", + "Abstract": true, + "BaseType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ListenerContext", + "ImplementedInterfaces": [ + "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.IAsyncDisposable" + ], + "Members": [ + { + "Kind": "Method", + "Name": "get_ListenSocket", + "Parameters": [], + "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle", + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "StartAsync", + "Parameters": [ + { + "Name": "address", + "Type": "Microsoft.AspNetCore.Server.Kestrel.ServerAddress" + }, + { + "Name": "thread", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.KestrelThread" + } + ], + "ReturnType": "System.Threading.Tasks.Task", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "CreateListenSocket", + "Parameters": [], + "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle", + "Virtual": true, + "Abstract": true, + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "ConnectionCallback", + "Parameters": [ + { + "Name": "stream", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle" + }, + { + "Name": "status", + "Type": "System.Int32" + }, + { + "Name": "error", + "Type": "System.Exception" + }, + { + "Name": "state", + "Type": "System.Object" + } + ], + "ReturnType": "System.Void", + "Static": true, + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "OnConnection", + "Parameters": [ + { + "Name": "listenSocket", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle" + }, + { + "Name": "status", + "Type": "System.Int32" + } + ], + "ReturnType": "System.Void", + "Virtual": true, + "Abstract": true, + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "DispatchConnection", + "Parameters": [ + { + "Name": "socket", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle" + } + ], + "ReturnType": "System.Void", + "Virtual": true, + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "DisposeAsync", + "Parameters": [], + "ReturnType": "System.Threading.Tasks.Task", + "Virtual": true, + "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.IAsyncDisposable", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [ + { + "Name": "serviceContext", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.ServiceContext" + } + ], + "Visibility": "Protected", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ListenerContext", + "Visibility": "Public", + "Kind": "Class", + "BaseType": "Microsoft.AspNetCore.Server.Kestrel.Internal.ServiceContext", + "ImplementedInterfaces": [], + "Members": [ + { + "Kind": "Method", + "Name": "get_ServerAddress", + "Parameters": [], + "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.ServerAddress", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_ServerAddress", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.AspNetCore.Server.Kestrel.ServerAddress" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_Thread", + "Parameters": [], + "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.KestrelThread", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_Thread", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.KestrelThread" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_Memory", + "Parameters": [], + "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPool", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_Memory", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPool" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_ConnectionManager", + "Parameters": [], + "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ConnectionManager", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_ConnectionManager", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ConnectionManager" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_WriteReqPool", + "Parameters": [], + "ReturnType": "System.Collections.Generic.Queue", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_WriteReqPool", + "Parameters": [ + { + "Name": "value", + "Type": "System.Collections.Generic.Queue" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [], + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [ + { + "Name": "serviceContext", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.ServiceContext" + } + ], + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [ + { + "Name": "listenerContext", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ListenerContext" + } + ], + "Visibility": "Public", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ListenerPrimary", + "Visibility": "Public", + "Kind": "Class", + "Abstract": true, + "BaseType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.Listener", + "ImplementedInterfaces": [], + "Members": [ + { + "Kind": "Method", + "Name": "StartAsync", + "Parameters": [ + { + "Name": "pipeName", + "Type": "System.String" + }, + { + "Name": "address", + "Type": "Microsoft.AspNetCore.Server.Kestrel.ServerAddress" + }, + { + "Name": "thread", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.KestrelThread" + } + ], + "ReturnType": "System.Threading.Tasks.Task", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "DispatchConnection", + "Parameters": [ + { + "Name": "socket", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle" + } + ], + "ReturnType": "System.Void", + "Virtual": true, + "Override": true, + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "DisposeAsync", + "Parameters": [], + "ReturnType": "System.Threading.Tasks.Task", + "Virtual": true, + "Override": true, + "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.IAsyncDisposable", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [ + { + "Name": "serviceContext", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.ServiceContext" + } + ], + "Visibility": "Protected", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ListenerSecondary", + "Visibility": "Public", + "Kind": "Class", + "Abstract": true, + "BaseType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ListenerContext", + "ImplementedInterfaces": [ + "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.IAsyncDisposable" + ], + "Members": [ + { + "Kind": "Method", + "Name": "StartAsync", + "Parameters": [ + { + "Name": "pipeName", + "Type": "System.String" + }, + { + "Name": "address", + "Type": "Microsoft.AspNetCore.Server.Kestrel.ServerAddress" + }, + { + "Name": "thread", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.KestrelThread" + } + ], + "ReturnType": "System.Threading.Tasks.Task", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "CreateAcceptSocket", + "Parameters": [], + "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle", + "Virtual": true, + "Abstract": true, + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "DisposeAsync", + "Parameters": [], + "ReturnType": "System.Threading.Tasks.Task", + "Sealed": true, + "Virtual": true, + "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.IAsyncDisposable", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [ + { + "Name": "serviceContext", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.ServiceContext" + } + ], + "Visibility": "Protected", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.MessageBody", + "Visibility": "Public", + "Kind": "Class", + "Abstract": true, + "ImplementedInterfaces": [], + "Members": [ + { + "Kind": "Method", + "Name": "get_RequestKeepAlive", + "Parameters": [], + "ReturnType": "System.Boolean", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_RequestKeepAlive", + "Parameters": [ + { + "Name": "value", + "Type": "System.Boolean" + } + ], + "ReturnType": "System.Void", + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "ReadAsync", + "Parameters": [ + { + "Name": "buffer", + "Type": "System.ArraySegment" + }, + { + "Name": "cancellationToken", + "Type": "System.Threading.CancellationToken", + "DefaultValue": "default(System.Threading.CancellationToken)" + } + ], + "ReturnType": "System.Threading.Tasks.ValueTask", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "Consume", + "Parameters": [ + { + "Name": "cancellationToken", + "Type": "System.Threading.CancellationToken", + "DefaultValue": "default(System.Threading.CancellationToken)" + } + ], + "ReturnType": "System.Threading.Tasks.Task", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "ReadAsyncImplementation", + "Parameters": [ + { + "Name": "buffer", + "Type": "System.ArraySegment" + }, + { + "Name": "cancellationToken", + "Type": "System.Threading.CancellationToken" + } + ], + "ReturnType": "System.Threading.Tasks.ValueTask", + "Virtual": true, + "Abstract": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "For", + "Parameters": [ + { + "Name": "httpVersion", + "Type": "System.String" + }, + { + "Name": "headers", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.FrameRequestHeaders" + }, + { + "Name": "context", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.Frame" + } + ], + "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.MessageBody", + "Static": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [ + { + "Name": "context", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.Frame" + } + ], + "Visibility": "Protected", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.PathNormalizer", + "Visibility": "Public", + "Kind": "Class", + "Abstract": true, + "Static": true, + "Sealed": true, + "ImplementedInterfaces": [], + "Members": [ + { + "Kind": "Method", + "Name": "RemoveDotSegments", + "Parameters": [ + { + "Name": "path", + "Type": "System.String" + } + ], + "ReturnType": "System.String", + "Static": true, + "Visibility": "Public", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.PipeListener", + "Visibility": "Public", + "Kind": "Class", + "BaseType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.Listener", + "ImplementedInterfaces": [], + "Members": [ + { + "Kind": "Method", + "Name": "CreateListenSocket", + "Parameters": [], + "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle", + "Virtual": true, + "Override": true, + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "OnConnection", + "Parameters": [ + { + "Name": "listenSocket", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle" + }, + { + "Name": "status", + "Type": "System.Int32" + } + ], + "ReturnType": "System.Void", + "Virtual": true, + "Override": true, + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [ + { + "Name": "serviceContext", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.ServiceContext" + } + ], + "Visibility": "Public", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.PipeListenerPrimary", + "Visibility": "Public", + "Kind": "Class", + "BaseType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ListenerPrimary", + "ImplementedInterfaces": [], + "Members": [ + { + "Kind": "Method", + "Name": "CreateListenSocket", + "Parameters": [], + "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle", + "Virtual": true, + "Override": true, + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "OnConnection", + "Parameters": [ + { + "Name": "listenSocket", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle" + }, + { + "Name": "status", + "Type": "System.Int32" + } + ], + "ReturnType": "System.Void", + "Virtual": true, + "Override": true, + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [ + { + "Name": "serviceContext", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.ServiceContext" + } + ], + "Visibility": "Public", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.PipeListenerSecondary", + "Visibility": "Public", + "Kind": "Class", + "BaseType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ListenerSecondary", + "ImplementedInterfaces": [], + "Members": [ + { + "Kind": "Method", + "Name": "CreateAcceptSocket", + "Parameters": [], + "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle", + "Virtual": true, + "Override": true, + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [ + { + "Name": "serviceContext", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.ServiceContext" + } + ], + "Visibility": "Public", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ProduceEndType", + "Visibility": "Public", + "Kind": "Enumeration", + "Sealed": true, + "ImplementedInterfaces": [], + "Members": [ + { + "Kind": "Field", + "Name": "SocketShutdown", + "Parameters": [], + "GenericParameter": [], + "Literal": "0" + }, + { + "Kind": "Field", + "Name": "SocketDisconnect", + "Parameters": [], + "GenericParameter": [], + "Literal": "1" + }, + { + "Kind": "Field", + "Name": "ConnectionKeepAlive", + "Parameters": [], + "GenericParameter": [], + "Literal": "2" + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ReasonPhrases", + "Visibility": "Public", + "Kind": "Class", + "Abstract": true, + "Static": true, + "Sealed": true, + "ImplementedInterfaces": [], + "Members": [ + { + "Kind": "Method", + "Name": "ToStatusBytes", + "Parameters": [ + { + "Name": "statusCode", + "Type": "System.Int32" + }, + { + "Name": "reasonPhrase", + "Type": "System.String", + "DefaultValue": "null" + } + ], + "ReturnType": "System.Byte[]", + "Static": true, + "Visibility": "Public", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.SocketInput", + "Visibility": "Public", + "Kind": "Class", + "ImplementedInterfaces": [ + "System.Runtime.CompilerServices.ICriticalNotifyCompletion", + "System.IDisposable" + ], + "Members": [ + { + "Kind": "Method", + "Name": "get_RemoteIntakeFin", + "Parameters": [], + "ReturnType": "System.Boolean", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_RemoteIntakeFin", + "Parameters": [ + { + "Name": "value", + "Type": "System.Boolean" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_IsCompleted", + "Parameters": [], + "ReturnType": "System.Boolean", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "IncomingStart", + "Parameters": [], + "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolBlock", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "IncomingData", + "Parameters": [ + { + "Name": "buffer", + "Type": "System.Byte[]" + }, + { + "Name": "offset", + "Type": "System.Int32" + }, + { + "Name": "count", + "Type": "System.Int32" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "IncomingComplete", + "Parameters": [ + { + "Name": "count", + "Type": "System.Int32" + }, + { + "Name": "error", + "Type": "System.Exception" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "IncomingDeferred", + "Parameters": [], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "IncomingFin", + "Parameters": [], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "ConsumingStart", + "Parameters": [], + "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolIterator", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "ConsumingComplete", + "Parameters": [ + { + "Name": "consumed", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolIterator" + }, + { + "Name": "examined", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolIterator" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "CompleteAwaiting", + "Parameters": [], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "AbortAwaiting", + "Parameters": [], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "GetAwaiter", + "Parameters": [], + "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.SocketInput", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "OnCompleted", + "Parameters": [ + { + "Name": "continuation", + "Type": "System.Action" + } + ], + "ReturnType": "System.Void", + "Sealed": true, + "Virtual": true, + "ImplementedInterface": "System.Runtime.CompilerServices.INotifyCompletion", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "UnsafeOnCompleted", + "Parameters": [ + { + "Name": "continuation", + "Type": "System.Action" + } + ], + "ReturnType": "System.Void", + "Sealed": true, + "Virtual": true, + "ImplementedInterface": "System.Runtime.CompilerServices.ICriticalNotifyCompletion", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "GetResult", + "Parameters": [], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "Dispose", + "Parameters": [], + "ReturnType": "System.Void", + "Sealed": true, + "Virtual": true, + "ImplementedInterface": "System.IDisposable", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [ + { + "Name": "memory", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPool" + }, + { + "Name": "threadPool", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IThreadPool" + }, + { + "Name": "bufferSizeControl", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.IBufferSizeControl", + "DefaultValue": "null" + } + ], + "Visibility": "Public", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.SocketInputExtensions", + "Visibility": "Public", + "Kind": "Class", + "Abstract": true, + "Static": true, + "Sealed": true, + "ImplementedInterfaces": [], + "Members": [ + { + "Kind": "Method", + "Name": "ReadAsync", + "Parameters": [ + { + "Name": "input", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.SocketInput" + }, + { + "Name": "buffer", + "Type": "System.Byte[]" + }, + { + "Name": "offset", + "Type": "System.Int32" + }, + { + "Name": "count", + "Type": "System.Int32" + } + ], + "ReturnType": "System.Threading.Tasks.ValueTask", + "Static": true, + "Extension": true, + "Visibility": "Public", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.SocketOutput", + "Visibility": "Public", + "Kind": "Class", + "ImplementedInterfaces": [ + "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ISocketOutput" + ], + "Members": [ + { + "Kind": "Method", + "Name": "WriteAsync", + "Parameters": [ + { + "Name": "buffer", + "Type": "System.ArraySegment" + }, + { + "Name": "cancellationToken", + "Type": "System.Threading.CancellationToken" + }, + { + "Name": "chunk", + "Type": "System.Boolean", + "DefaultValue": "False" + }, + { + "Name": "socketShutdownSend", + "Type": "System.Boolean", + "DefaultValue": "False" + }, + { + "Name": "socketDisconnect", + "Type": "System.Boolean", + "DefaultValue": "False" + }, + { + "Name": "isSync", + "Type": "System.Boolean", + "DefaultValue": "False" + } + ], + "ReturnType": "System.Threading.Tasks.Task", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "End", + "Parameters": [ + { + "Name": "endType", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ProduceEndType" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "ProducingStart", + "Parameters": [], + "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolIterator", + "Sealed": true, + "Virtual": true, + "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ISocketOutput", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "ProducingComplete", + "Parameters": [ + { + "Name": "end", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolIterator" + } + ], + "ReturnType": "System.Void", + "Sealed": true, + "Virtual": true, + "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ISocketOutput", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [ + { + "Name": "thread", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.KestrelThread" + }, + { + "Name": "socket", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle" + }, + { + "Name": "memory", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPool" + }, + { + "Name": "connection", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.Connection" + }, + { + "Name": "connectionId", + "Type": "System.String" + }, + { + "Name": "log", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IKestrelTrace" + }, + { + "Name": "threadPool", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IThreadPool" + }, + { + "Name": "writeReqPool", + "Type": "System.Collections.Generic.Queue" + } + ], + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Field", + "Name": "MaxPooledWriteReqs", + "Parameters": [], + "ReturnType": "System.Int32", + "Static": true, + "Visibility": "Public", + "GenericParameter": [], + "Constant": true, + "Literal": "1024" + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.TcpListener", + "Visibility": "Public", + "Kind": "Class", + "BaseType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.Listener", + "ImplementedInterfaces": [], + "Members": [ + { + "Kind": "Method", + "Name": "CreateListenSocket", + "Parameters": [], + "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle", + "Virtual": true, + "Override": true, + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "OnConnection", + "Parameters": [ + { + "Name": "listenSocket", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle" + }, + { + "Name": "status", + "Type": "System.Int32" + } + ], + "ReturnType": "System.Void", + "Virtual": true, + "Override": true, + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [ + { + "Name": "serviceContext", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.ServiceContext" + } + ], + "Visibility": "Public", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.TcpListenerPrimary", + "Visibility": "Public", + "Kind": "Class", + "BaseType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ListenerPrimary", + "ImplementedInterfaces": [], + "Members": [ + { + "Kind": "Method", + "Name": "CreateListenSocket", + "Parameters": [], + "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle", + "Virtual": true, + "Override": true, + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "OnConnection", + "Parameters": [ + { + "Name": "listenSocket", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle" + }, + { + "Name": "status", + "Type": "System.Int32" + } + ], + "ReturnType": "System.Void", + "Virtual": true, + "Override": true, + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [ + { + "Name": "serviceContext", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.ServiceContext" + } + ], + "Visibility": "Public", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.TcpListenerSecondary", + "Visibility": "Public", + "Kind": "Class", + "BaseType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ListenerSecondary", + "ImplementedInterfaces": [], + "Members": [ + { + "Kind": "Method", + "Name": "CreateAcceptSocket", + "Parameters": [], + "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle", + "Virtual": true, + "Override": true, + "Visibility": "Protected", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [ + { + "Name": "serviceContext", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.ServiceContext" + } + ], + "Visibility": "Public", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.UrlPathDecoder", + "Visibility": "Public", + "Kind": "Class", + "ImplementedInterfaces": [], + "Members": [ + { + "Kind": "Method", + "Name": "Unescape", + "Parameters": [ + { + "Name": "start", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolIterator" + }, + { + "Name": "end", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolIterator" + } + ], + "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolIterator", + "Static": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [], + "Visibility": "Public", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Filter.ConnectionFilterContext", + "Visibility": "Public", + "Kind": "Class", + "ImplementedInterfaces": [], + "Members": [ + { + "Kind": "Method", + "Name": "get_Address", + "Parameters": [], + "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.ServerAddress", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_Address", + "Parameters": [ + { + "Name": "value", + "Type": "Microsoft.AspNetCore.Server.Kestrel.ServerAddress" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_Connection", + "Parameters": [], + "ReturnType": "System.IO.Stream", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_Connection", + "Parameters": [ + { + "Name": "value", + "Type": "System.IO.Stream" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_PrepareRequest", + "Parameters": [], + "ReturnType": "System.Action", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_PrepareRequest", + "Parameters": [ + { + "Name": "value", + "Type": "System.Action" + } + ], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [], + "Visibility": "Public", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Filter.IConnectionFilter", + "Visibility": "Public", + "Kind": "Interface", + "Abstract": true, + "ImplementedInterfaces": [], + "Members": [ + { + "Kind": "Method", + "Name": "OnConnectionAsync", + "Parameters": [ + { + "Name": "context", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Filter.ConnectionFilterContext" + } + ], + "ReturnType": "System.Threading.Tasks.Task", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Filter.LoggingConnectionFilter", + "Visibility": "Public", + "Kind": "Class", + "ImplementedInterfaces": [ + "Microsoft.AspNetCore.Server.Kestrel.Filter.IConnectionFilter" + ], + "Members": [ + { + "Kind": "Method", + "Name": "OnConnectionAsync", + "Parameters": [ + { + "Name": "context", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Filter.ConnectionFilterContext" + } + ], + "ReturnType": "System.Threading.Tasks.Task", + "Sealed": true, + "Virtual": true, + "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Filter.IConnectionFilter", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [ + { + "Name": "logger", + "Type": "Microsoft.Extensions.Logging.ILogger" + }, + { + "Name": "previous", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Filter.IConnectionFilter" + } + ], + "Visibility": "Public", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Filter.NoOpConnectionFilter", + "Visibility": "Public", + "Kind": "Class", + "ImplementedInterfaces": [ + "Microsoft.AspNetCore.Server.Kestrel.Filter.IConnectionFilter" + ], + "Members": [ + { + "Kind": "Method", + "Name": "OnConnectionAsync", + "Parameters": [ + { + "Name": "context", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Filter.ConnectionFilterContext" + } + ], + "ReturnType": "System.Threading.Tasks.Task", + "Sealed": true, + "Virtual": true, + "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Filter.IConnectionFilter", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [], + "Visibility": "Public", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Filter.Internal.FilteredStreamAdapter", + "Visibility": "Public", + "Kind": "Class", + "ImplementedInterfaces": [ + "System.IDisposable" + ], + "Members": [ + { + "Kind": "Method", + "Name": "get_SocketInput", + "Parameters": [], + "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.SocketInput", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_SocketOutput", + "Parameters": [], + "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ISocketOutput", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "ReadInputAsync", + "Parameters": [], + "ReturnType": "System.Threading.Tasks.Task", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "Abort", + "Parameters": [], + "ReturnType": "System.Void", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "Dispose", + "Parameters": [], + "ReturnType": "System.Void", + "Sealed": true, + "Virtual": true, + "ImplementedInterface": "System.IDisposable", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [ + { + "Name": "connectionId", + "Type": "System.String" + }, + { + "Name": "filteredStream", + "Type": "System.IO.Stream" + }, + { + "Name": "memory", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPool" + }, + { + "Name": "logger", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IKestrelTrace" + }, + { + "Name": "threadPool", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IThreadPool" + }, + { + "Name": "bufferSizeControl", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.IBufferSizeControl" + } + ], + "Visibility": "Public", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Filter.Internal.LibuvStream", + "Visibility": "Public", + "Kind": "Class", + "BaseType": "System.IO.Stream", + "ImplementedInterfaces": [], + "Members": [ + { + "Kind": "Method", + "Name": "get_CanRead", + "Parameters": [], + "ReturnType": "System.Boolean", + "Virtual": true, + "Override": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_CanSeek", + "Parameters": [], + "ReturnType": "System.Boolean", + "Virtual": true, + "Override": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_CanWrite", + "Parameters": [], + "ReturnType": "System.Boolean", + "Virtual": true, + "Override": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_Length", + "Parameters": [], + "ReturnType": "System.Int64", + "Virtual": true, + "Override": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_Position", + "Parameters": [], + "ReturnType": "System.Int64", + "Virtual": true, + "Override": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "set_Position", + "Parameters": [ + { + "Name": "value", + "Type": "System.Int64" + } + ], + "ReturnType": "System.Void", + "Virtual": true, + "Override": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "Seek", + "Parameters": [ + { + "Name": "offset", + "Type": "System.Int64" + }, + { + "Name": "origin", + "Type": "System.IO.SeekOrigin" + } + ], + "ReturnType": "System.Int64", + "Virtual": true, + "Override": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "SetLength", + "Parameters": [ + { + "Name": "value", + "Type": "System.Int64" + } + ], + "ReturnType": "System.Void", + "Virtual": true, + "Override": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "Read", + "Parameters": [ + { + "Name": "buffer", + "Type": "System.Byte[]" + }, + { + "Name": "offset", + "Type": "System.Int32" + }, + { + "Name": "count", + "Type": "System.Int32" + } + ], + "ReturnType": "System.Int32", + "Virtual": true, + "Override": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "ReadAsync", + "Parameters": [ + { + "Name": "buffer", + "Type": "System.Byte[]" + }, + { + "Name": "offset", + "Type": "System.Int32" + }, + { + "Name": "count", + "Type": "System.Int32" + }, + { + "Name": "cancellationToken", + "Type": "System.Threading.CancellationToken" + } + ], + "ReturnType": "System.Threading.Tasks.Task", + "Virtual": true, + "Override": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "Write", + "Parameters": [ + { + "Name": "buffer", + "Type": "System.Byte[]" + }, + { + "Name": "offset", + "Type": "System.Int32" + }, + { + "Name": "count", + "Type": "System.Int32" + } + ], + "ReturnType": "System.Void", + "Virtual": true, + "Override": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "WriteAsync", + "Parameters": [ + { + "Name": "buffer", + "Type": "System.Byte[]" + }, + { + "Name": "offset", + "Type": "System.Int32" + }, + { + "Name": "count", + "Type": "System.Int32" + }, + { + "Name": "token", + "Type": "System.Threading.CancellationToken" + } + ], + "ReturnType": "System.Threading.Tasks.Task", + "Virtual": true, + "Override": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "Flush", + "Parameters": [], + "ReturnType": "System.Void", + "Virtual": true, + "Override": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "FlushAsync", + "Parameters": [ + { + "Name": "cancellationToken", + "Type": "System.Threading.CancellationToken" + } + ], + "ReturnType": "System.Threading.Tasks.Task", + "Virtual": true, + "Override": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [ + { + "Name": "input", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.SocketInput" + }, + { + "Name": "output", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ISocketOutput" + } + ], + "Visibility": "Public", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Filter.Internal.StreamSocketOutput", + "Visibility": "Public", + "Kind": "Class", + "ImplementedInterfaces": [ + "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ISocketOutput" + ], + "Members": [ + { + "Kind": "Method", + "Name": "Write", + "Parameters": [ + { + "Name": "buffer", + "Type": "System.ArraySegment" + }, + { + "Name": "chunk", + "Type": "System.Boolean" + } + ], + "ReturnType": "System.Void", + "Sealed": true, + "Virtual": true, + "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ISocketOutput", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "WriteAsync", + "Parameters": [ + { + "Name": "buffer", + "Type": "System.ArraySegment" + }, + { + "Name": "chunk", + "Type": "System.Boolean" + }, + { + "Name": "cancellationToken", + "Type": "System.Threading.CancellationToken" + } + ], + "ReturnType": "System.Threading.Tasks.Task", + "Sealed": true, + "Virtual": true, + "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ISocketOutput", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "ProducingStart", + "Parameters": [], + "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolIterator", + "Sealed": true, + "Virtual": true, + "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ISocketOutput", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "ProducingComplete", + "Parameters": [ + { + "Name": "end", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolIterator" + } + ], + "ReturnType": "System.Void", + "Sealed": true, + "Virtual": true, + "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ISocketOutput", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [ + { + "Name": "connectionId", + "Type": "System.String" + }, + { + "Name": "outputStream", + "Type": "System.IO.Stream" + }, + { + "Name": "memory", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPool" + }, + { + "Name": "logger", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IKestrelTrace" + } + ], + "Visibility": "Public", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_fileno_func", + "Visibility": "Protected", + "Kind": "Class", + "Sealed": true, + "BaseType": "System.MulticastDelegate", + "ImplementedInterfaces": [], + "Members": [ + { + "Kind": "Method", + "Name": "Invoke", + "Parameters": [ + { + "Name": "handle", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvHandle" + }, + { + "Name": "socket", + "Type": "System.IntPtr", + "Direction": "Ref" + } + ], + "ReturnType": "System.Int32", + "Virtual": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "BeginInvoke", + "Parameters": [ + { + "Name": "handle", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvHandle" + }, + { + "Name": "socket", + "Type": "System.IntPtr", + "Direction": "Ref" + }, + { + "Name": "callback", + "Type": "System.AsyncCallback" + }, + { + "Name": "object", + "Type": "System.Object" + } + ], + "ReturnType": "System.IAsyncResult", + "Virtual": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "EndInvoke", + "Parameters": [ + { + "Name": "socket", + "Type": "System.IntPtr", + "Direction": "Ref" + }, + { + "Name": "result", + "Type": "System.IAsyncResult" + } + ], + "ReturnType": "System.Int32", + "Virtual": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [ + { + "Name": "object", + "Type": "System.Object" + }, + { + "Name": "method", + "Type": "System.IntPtr" + } + ], + "Visibility": "Public", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_close_cb", + "Visibility": "Public", + "Kind": "Class", + "Sealed": true, + "BaseType": "System.MulticastDelegate", + "ImplementedInterfaces": [], + "Members": [ + { + "Kind": "Method", + "Name": "Invoke", + "Parameters": [ + { + "Name": "handle", + "Type": "System.IntPtr" + } + ], + "ReturnType": "System.Void", + "Virtual": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "BeginInvoke", + "Parameters": [ + { + "Name": "handle", + "Type": "System.IntPtr" + }, + { + "Name": "callback", + "Type": "System.AsyncCallback" + }, + { + "Name": "object", + "Type": "System.Object" + } + ], + "ReturnType": "System.IAsyncResult", + "Virtual": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "EndInvoke", + "Parameters": [ + { + "Name": "result", + "Type": "System.IAsyncResult" + } + ], + "ReturnType": "System.Void", + "Virtual": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [ + { + "Name": "object", + "Type": "System.Object" + }, + { + "Name": "method", + "Type": "System.IntPtr" + } + ], + "Visibility": "Public", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_async_cb", + "Visibility": "Public", + "Kind": "Class", + "Sealed": true, + "BaseType": "System.MulticastDelegate", + "ImplementedInterfaces": [], + "Members": [ + { + "Kind": "Method", + "Name": "Invoke", + "Parameters": [ + { + "Name": "handle", + "Type": "System.IntPtr" + } + ], + "ReturnType": "System.Void", + "Virtual": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "BeginInvoke", + "Parameters": [ + { + "Name": "handle", + "Type": "System.IntPtr" + }, + { + "Name": "callback", + "Type": "System.AsyncCallback" + }, + { + "Name": "object", + "Type": "System.Object" + } + ], + "ReturnType": "System.IAsyncResult", + "Virtual": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "EndInvoke", + "Parameters": [ + { + "Name": "result", + "Type": "System.IAsyncResult" + } + ], + "ReturnType": "System.Void", + "Virtual": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [ + { + "Name": "object", + "Type": "System.Object" + }, + { + "Name": "method", + "Type": "System.IntPtr" + } + ], + "Visibility": "Public", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_tcp_bind_func", + "Visibility": "Protected", + "Kind": "Class", + "Sealed": true, + "BaseType": "System.MulticastDelegate", + "ImplementedInterfaces": [], + "Members": [ + { + "Kind": "Method", + "Name": "Invoke", + "Parameters": [ + { + "Name": "handle", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvTcpHandle" + }, + { + "Name": "addr", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.SockAddr", + "Direction": "Ref" + }, + { + "Name": "flags", + "Type": "System.Int32" + } + ], + "ReturnType": "System.Int32", + "Virtual": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "BeginInvoke", + "Parameters": [ + { + "Name": "handle", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvTcpHandle" + }, + { + "Name": "addr", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.SockAddr", + "Direction": "Ref" + }, + { + "Name": "flags", + "Type": "System.Int32" + }, + { + "Name": "callback", + "Type": "System.AsyncCallback" + }, + { + "Name": "object", + "Type": "System.Object" + } + ], + "ReturnType": "System.IAsyncResult", + "Virtual": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "EndInvoke", + "Parameters": [ + { + "Name": "addr", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.SockAddr", + "Direction": "Ref" + }, + { + "Name": "result", + "Type": "System.IAsyncResult" + } + ], + "ReturnType": "System.Int32", + "Virtual": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [ + { + "Name": "object", + "Type": "System.Object" + }, + { + "Name": "method", + "Type": "System.IntPtr" + } + ], + "Visibility": "Public", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_connection_cb", + "Visibility": "Public", + "Kind": "Class", + "Sealed": true, + "BaseType": "System.MulticastDelegate", + "ImplementedInterfaces": [], + "Members": [ + { + "Kind": "Method", + "Name": "Invoke", + "Parameters": [ + { + "Name": "server", + "Type": "System.IntPtr" + }, + { + "Name": "status", + "Type": "System.Int32" + } + ], + "ReturnType": "System.Void", + "Virtual": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "BeginInvoke", + "Parameters": [ + { + "Name": "server", + "Type": "System.IntPtr" + }, + { + "Name": "status", + "Type": "System.Int32" + }, + { + "Name": "callback", + "Type": "System.AsyncCallback" + }, + { + "Name": "object", + "Type": "System.Object" + } + ], + "ReturnType": "System.IAsyncResult", + "Virtual": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "EndInvoke", + "Parameters": [ + { + "Name": "result", + "Type": "System.IAsyncResult" + } + ], + "ReturnType": "System.Void", + "Virtual": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [ + { + "Name": "object", + "Type": "System.Object" + }, + { + "Name": "method", + "Type": "System.IntPtr" + } + ], + "Visibility": "Public", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_connect_cb", + "Visibility": "Public", + "Kind": "Class", + "Sealed": true, + "BaseType": "System.MulticastDelegate", + "ImplementedInterfaces": [], + "Members": [ + { + "Kind": "Method", + "Name": "Invoke", + "Parameters": [ + { + "Name": "req", + "Type": "System.IntPtr" + }, + { + "Name": "status", + "Type": "System.Int32" + } + ], + "ReturnType": "System.Void", + "Virtual": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "BeginInvoke", + "Parameters": [ + { + "Name": "req", + "Type": "System.IntPtr" + }, + { + "Name": "status", + "Type": "System.Int32" + }, + { + "Name": "callback", + "Type": "System.AsyncCallback" + }, + { + "Name": "object", + "Type": "System.Object" + } + ], + "ReturnType": "System.IAsyncResult", + "Virtual": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "EndInvoke", + "Parameters": [ + { + "Name": "result", + "Type": "System.IAsyncResult" + } + ], + "ReturnType": "System.Void", + "Virtual": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [ + { + "Name": "object", + "Type": "System.Object" + }, + { + "Name": "method", + "Type": "System.IntPtr" + } + ], + "Visibility": "Public", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_alloc_cb", + "Visibility": "Public", + "Kind": "Class", + "Sealed": true, + "BaseType": "System.MulticastDelegate", + "ImplementedInterfaces": [], + "Members": [ + { + "Kind": "Method", + "Name": "Invoke", + "Parameters": [ + { + "Name": "server", + "Type": "System.IntPtr" + }, + { + "Name": "suggested_size", + "Type": "System.Int32" + }, + { + "Name": "buf", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_buf_t", + "Direction": "Out" + } + ], + "ReturnType": "System.Void", + "Virtual": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "BeginInvoke", + "Parameters": [ + { + "Name": "server", + "Type": "System.IntPtr" + }, + { + "Name": "suggested_size", + "Type": "System.Int32" + }, + { + "Name": "buf", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_buf_t", + "Direction": "Out" + }, + { + "Name": "callback", + "Type": "System.AsyncCallback" + }, + { + "Name": "object", + "Type": "System.Object" + } + ], + "ReturnType": "System.IAsyncResult", + "Virtual": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "EndInvoke", + "Parameters": [ + { + "Name": "buf", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_buf_t", + "Direction": "Out" + }, + { + "Name": "result", + "Type": "System.IAsyncResult" + } + ], + "ReturnType": "System.Void", + "Virtual": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [ + { + "Name": "object", + "Type": "System.Object" + }, + { + "Name": "method", + "Type": "System.IntPtr" + } + ], + "Visibility": "Public", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_read_cb", + "Visibility": "Public", + "Kind": "Class", + "Sealed": true, + "BaseType": "System.MulticastDelegate", + "ImplementedInterfaces": [], + "Members": [ + { + "Kind": "Method", + "Name": "Invoke", + "Parameters": [ + { + "Name": "server", + "Type": "System.IntPtr" + }, + { + "Name": "nread", + "Type": "System.Int32" + }, + { + "Name": "buf", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_buf_t", + "Direction": "Ref" + } + ], + "ReturnType": "System.Void", + "Virtual": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "BeginInvoke", + "Parameters": [ + { + "Name": "server", + "Type": "System.IntPtr" + }, + { + "Name": "nread", + "Type": "System.Int32" + }, + { + "Name": "buf", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_buf_t", + "Direction": "Ref" + }, + { + "Name": "callback", + "Type": "System.AsyncCallback" + }, + { + "Name": "object", + "Type": "System.Object" + } + ], + "ReturnType": "System.IAsyncResult", + "Virtual": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "EndInvoke", + "Parameters": [ + { + "Name": "buf", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_buf_t", + "Direction": "Ref" + }, + { + "Name": "result", + "Type": "System.IAsyncResult" + } + ], + "ReturnType": "System.Void", + "Virtual": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [ + { + "Name": "object", + "Type": "System.Object" + }, + { + "Name": "method", + "Type": "System.IntPtr" + } + ], + "Visibility": "Public", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_write_cb", + "Visibility": "Public", + "Kind": "Class", + "Sealed": true, + "BaseType": "System.MulticastDelegate", + "ImplementedInterfaces": [], + "Members": [ + { + "Kind": "Method", + "Name": "Invoke", + "Parameters": [ + { + "Name": "req", + "Type": "System.IntPtr" + }, + { + "Name": "status", + "Type": "System.Int32" + } + ], + "ReturnType": "System.Void", + "Virtual": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "BeginInvoke", + "Parameters": [ + { + "Name": "req", + "Type": "System.IntPtr" + }, + { + "Name": "status", + "Type": "System.Int32" + }, + { + "Name": "callback", + "Type": "System.AsyncCallback" + }, + { + "Name": "object", + "Type": "System.Object" + } + ], + "ReturnType": "System.IAsyncResult", + "Virtual": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "EndInvoke", + "Parameters": [ + { + "Name": "result", + "Type": "System.IAsyncResult" + } + ], + "ReturnType": "System.Void", + "Virtual": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [ + { + "Name": "object", + "Type": "System.Object" + }, + { + "Name": "method", + "Type": "System.IntPtr" + } + ], + "Visibility": "Public", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_write_func", + "Visibility": "Protected", + "Kind": "Class", + "Sealed": true, + "BaseType": "System.MulticastDelegate", + "ImplementedInterfaces": [], + "Members": [ + { + "Kind": "Method", + "Name": "Invoke", + "Parameters": [ + { + "Name": "req", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvRequest" + }, + { + "Name": "handle", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle" + }, + { + "Name": "bufs", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_buf_t*" + }, + { + "Name": "nbufs", + "Type": "System.Int32" + }, + { + "Name": "cb", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_write_cb" + } + ], + "ReturnType": "System.Int32", + "Virtual": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "BeginInvoke", + "Parameters": [ + { + "Name": "req", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvRequest" + }, + { + "Name": "handle", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle" + }, + { + "Name": "bufs", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_buf_t*" + }, + { + "Name": "nbufs", + "Type": "System.Int32" + }, + { + "Name": "cb", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_write_cb" + }, + { + "Name": "callback", + "Type": "System.AsyncCallback" + }, + { + "Name": "object", + "Type": "System.Object" + } + ], + "ReturnType": "System.IAsyncResult", + "Virtual": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "EndInvoke", + "Parameters": [ + { + "Name": "result", + "Type": "System.IAsyncResult" + } + ], + "ReturnType": "System.Int32", + "Virtual": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [ + { + "Name": "object", + "Type": "System.Object" + }, + { + "Name": "method", + "Type": "System.IntPtr" + } + ], + "Visibility": "Public", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_write2_func", + "Visibility": "Protected", + "Kind": "Class", + "Sealed": true, + "BaseType": "System.MulticastDelegate", + "ImplementedInterfaces": [], + "Members": [ + { + "Kind": "Method", + "Name": "Invoke", + "Parameters": [ + { + "Name": "req", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvRequest" + }, + { + "Name": "handle", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle" + }, + { + "Name": "bufs", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_buf_t*" + }, + { + "Name": "nbufs", + "Type": "System.Int32" + }, + { + "Name": "sendHandle", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle" + }, + { + "Name": "cb", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_write_cb" + } + ], + "ReturnType": "System.Int32", + "Virtual": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "BeginInvoke", + "Parameters": [ + { + "Name": "req", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvRequest" + }, + { + "Name": "handle", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle" + }, + { + "Name": "bufs", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_buf_t*" + }, + { + "Name": "nbufs", + "Type": "System.Int32" + }, + { + "Name": "sendHandle", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle" + }, + { + "Name": "cb", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_write_cb" + }, + { + "Name": "callback", + "Type": "System.AsyncCallback" + }, + { + "Name": "object", + "Type": "System.Object" + } + ], + "ReturnType": "System.IAsyncResult", + "Virtual": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "EndInvoke", + "Parameters": [ + { + "Name": "result", + "Type": "System.IAsyncResult" + } + ], + "ReturnType": "System.Int32", + "Virtual": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [ + { + "Name": "object", + "Type": "System.Object" + }, + { + "Name": "method", + "Type": "System.IntPtr" + } + ], + "Visibility": "Public", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_shutdown_cb", + "Visibility": "Public", + "Kind": "Class", + "Sealed": true, + "BaseType": "System.MulticastDelegate", + "ImplementedInterfaces": [], + "Members": [ + { + "Kind": "Method", + "Name": "Invoke", + "Parameters": [ + { + "Name": "req", + "Type": "System.IntPtr" + }, + { + "Name": "status", + "Type": "System.Int32" + } + ], + "ReturnType": "System.Void", + "Virtual": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "BeginInvoke", + "Parameters": [ + { + "Name": "req", + "Type": "System.IntPtr" + }, + { + "Name": "status", + "Type": "System.Int32" + }, + { + "Name": "callback", + "Type": "System.AsyncCallback" + }, + { + "Name": "object", + "Type": "System.Object" + } + ], + "ReturnType": "System.IAsyncResult", + "Virtual": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "EndInvoke", + "Parameters": [ + { + "Name": "result", + "Type": "System.IAsyncResult" + } + ], + "ReturnType": "System.Void", + "Virtual": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [ + { + "Name": "object", + "Type": "System.Object" + }, + { + "Name": "method", + "Type": "System.IntPtr" + } + ], + "Visibility": "Public", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_ip4_addr_func", + "Visibility": "Protected", + "Kind": "Class", + "Sealed": true, + "BaseType": "System.MulticastDelegate", + "ImplementedInterfaces": [], + "Members": [ + { + "Kind": "Method", + "Name": "Invoke", + "Parameters": [ + { + "Name": "ip", + "Type": "System.String" + }, + { + "Name": "port", + "Type": "System.Int32" + }, + { + "Name": "addr", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.SockAddr", + "Direction": "Out" + } + ], + "ReturnType": "System.Int32", + "Virtual": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "BeginInvoke", + "Parameters": [ + { + "Name": "ip", + "Type": "System.String" + }, + { + "Name": "port", + "Type": "System.Int32" + }, + { + "Name": "addr", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.SockAddr", + "Direction": "Out" + }, + { + "Name": "callback", + "Type": "System.AsyncCallback" + }, + { + "Name": "object", + "Type": "System.Object" + } + ], + "ReturnType": "System.IAsyncResult", + "Virtual": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "EndInvoke", + "Parameters": [ + { + "Name": "addr", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.SockAddr", + "Direction": "Out" + }, + { + "Name": "result", + "Type": "System.IAsyncResult" + } + ], + "ReturnType": "System.Int32", + "Virtual": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [ + { + "Name": "object", + "Type": "System.Object" + }, + { + "Name": "method", + "Type": "System.IntPtr" + } + ], + "Visibility": "Public", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_ip6_addr_func", + "Visibility": "Protected", + "Kind": "Class", + "Sealed": true, + "BaseType": "System.MulticastDelegate", + "ImplementedInterfaces": [], + "Members": [ + { + "Kind": "Method", + "Name": "Invoke", + "Parameters": [ + { + "Name": "ip", + "Type": "System.String" + }, + { + "Name": "port", + "Type": "System.Int32" + }, + { + "Name": "addr", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.SockAddr", + "Direction": "Out" + } + ], + "ReturnType": "System.Int32", + "Virtual": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "BeginInvoke", + "Parameters": [ + { + "Name": "ip", + "Type": "System.String" + }, + { + "Name": "port", + "Type": "System.Int32" + }, + { + "Name": "addr", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.SockAddr", + "Direction": "Out" + }, + { + "Name": "callback", + "Type": "System.AsyncCallback" + }, + { + "Name": "object", + "Type": "System.Object" + } + ], + "ReturnType": "System.IAsyncResult", + "Virtual": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "EndInvoke", + "Parameters": [ + { + "Name": "addr", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.SockAddr", + "Direction": "Out" + }, + { + "Name": "result", + "Type": "System.IAsyncResult" + } + ], + "ReturnType": "System.Int32", + "Virtual": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [ + { + "Name": "object", + "Type": "System.Object" + }, + { + "Name": "method", + "Type": "System.IntPtr" + } + ], + "Visibility": "Public", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_walk_cb", + "Visibility": "Public", + "Kind": "Class", + "Sealed": true, + "BaseType": "System.MulticastDelegate", + "ImplementedInterfaces": [], + "Members": [ + { + "Kind": "Method", + "Name": "Invoke", + "Parameters": [ + { + "Name": "handle", + "Type": "System.IntPtr" + }, + { + "Name": "arg", + "Type": "System.IntPtr" + } + ], + "ReturnType": "System.Void", + "Virtual": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "BeginInvoke", + "Parameters": [ + { + "Name": "handle", + "Type": "System.IntPtr" + }, + { + "Name": "arg", + "Type": "System.IntPtr" + }, + { + "Name": "callback", + "Type": "System.AsyncCallback" + }, + { + "Name": "object", + "Type": "System.Object" + } + ], + "ReturnType": "System.IAsyncResult", + "Virtual": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "EndInvoke", + "Parameters": [ + { + "Name": "result", + "Type": "System.IAsyncResult" + } + ], + "ReturnType": "System.Void", + "Virtual": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [ + { + "Name": "object", + "Type": "System.Object" + }, + { + "Name": "method", + "Type": "System.IntPtr" + } + ], + "Visibility": "Public", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_tcp_getsockname_func", + "Visibility": "Public", + "Kind": "Class", + "Sealed": true, + "BaseType": "System.MulticastDelegate", + "ImplementedInterfaces": [], + "Members": [ + { + "Kind": "Method", + "Name": "Invoke", + "Parameters": [ + { + "Name": "handle", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvTcpHandle" + }, + { + "Name": "addr", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.SockAddr", + "Direction": "Out" + }, + { + "Name": "namelen", + "Type": "System.Int32", + "Direction": "Ref" + } + ], + "ReturnType": "System.Int32", + "Virtual": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "BeginInvoke", + "Parameters": [ + { + "Name": "handle", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvTcpHandle" + }, + { + "Name": "addr", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.SockAddr", + "Direction": "Out" + }, + { + "Name": "namelen", + "Type": "System.Int32", + "Direction": "Ref" + }, + { + "Name": "callback", + "Type": "System.AsyncCallback" + }, + { + "Name": "object", + "Type": "System.Object" + } + ], + "ReturnType": "System.IAsyncResult", + "Virtual": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "EndInvoke", + "Parameters": [ + { + "Name": "addr", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.SockAddr", + "Direction": "Out" + }, + { + "Name": "namelen", + "Type": "System.Int32", + "Direction": "Ref" + }, + { + "Name": "result", + "Type": "System.IAsyncResult" + } + ], + "ReturnType": "System.Int32", + "Virtual": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [ + { + "Name": "object", + "Type": "System.Object" + }, + { + "Name": "method", + "Type": "System.IntPtr" + } + ], + "Visibility": "Public", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_tcp_getpeername_func", + "Visibility": "Public", + "Kind": "Class", + "Sealed": true, + "BaseType": "System.MulticastDelegate", + "ImplementedInterfaces": [], + "Members": [ + { + "Kind": "Method", + "Name": "Invoke", + "Parameters": [ + { + "Name": "handle", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvTcpHandle" + }, + { + "Name": "addr", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.SockAddr", + "Direction": "Out" + }, + { + "Name": "namelen", + "Type": "System.Int32", + "Direction": "Ref" + } + ], + "ReturnType": "System.Int32", + "Virtual": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "BeginInvoke", + "Parameters": [ + { + "Name": "handle", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvTcpHandle" + }, + { + "Name": "addr", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.SockAddr", + "Direction": "Out" + }, + { + "Name": "namelen", + "Type": "System.Int32", + "Direction": "Ref" + }, + { + "Name": "callback", + "Type": "System.AsyncCallback" + }, + { + "Name": "object", + "Type": "System.Object" + } + ], + "ReturnType": "System.IAsyncResult", + "Virtual": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "EndInvoke", + "Parameters": [ + { + "Name": "addr", + "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.SockAddr", + "Direction": "Out" + }, + { + "Name": "namelen", + "Type": "System.Int32", + "Direction": "Ref" + }, + { + "Name": "result", + "Type": "System.IAsyncResult" + } + ], + "ReturnType": "System.Int32", + "Virtual": true, + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [ + { + "Name": "object", + "Type": "System.Object" + }, + { + "Name": "method", + "Type": "System.IntPtr" + } + ], + "Visibility": "Public", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_buf_t", + "Visibility": "Public", + "Kind": "Struct", + "Sealed": true, + "ImplementedInterfaces": [], + "Members": [ + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [ + { + "Name": "memory", + "Type": "System.IntPtr" + }, + { + "Name": "len", + "Type": "System.Int32" + }, + { + "Name": "IsWindows", + "Type": "System.Boolean" + } + ], + "Visibility": "Public", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+HandleType", + "Visibility": "Public", + "Kind": "Enumeration", + "Sealed": true, + "ImplementedInterfaces": [], + "Members": [ + { + "Kind": "Field", + "Name": "Unknown", + "Parameters": [], + "GenericParameter": [], + "Literal": "0" + }, + { + "Kind": "Field", + "Name": "ASYNC", + "Parameters": [], + "GenericParameter": [], + "Literal": "1" + }, + { + "Kind": "Field", + "Name": "CHECK", + "Parameters": [], + "GenericParameter": [], + "Literal": "2" + }, + { + "Kind": "Field", + "Name": "FS_EVENT", + "Parameters": [], + "GenericParameter": [], + "Literal": "3" + }, + { + "Kind": "Field", + "Name": "FS_POLL", + "Parameters": [], + "GenericParameter": [], + "Literal": "4" + }, + { + "Kind": "Field", + "Name": "HANDLE", + "Parameters": [], + "GenericParameter": [], + "Literal": "5" + }, + { + "Kind": "Field", + "Name": "IDLE", + "Parameters": [], + "GenericParameter": [], + "Literal": "6" + }, + { + "Kind": "Field", + "Name": "NAMED_PIPE", + "Parameters": [], + "GenericParameter": [], + "Literal": "7" + }, + { + "Kind": "Field", + "Name": "POLL", + "Parameters": [], + "GenericParameter": [], + "Literal": "8" + }, + { + "Kind": "Field", + "Name": "PREPARE", + "Parameters": [], + "GenericParameter": [], + "Literal": "9" + }, + { + "Kind": "Field", + "Name": "PROCESS", + "Parameters": [], + "GenericParameter": [], + "Literal": "10" + }, + { + "Kind": "Field", + "Name": "STREAM", + "Parameters": [], + "GenericParameter": [], + "Literal": "11" + }, + { + "Kind": "Field", + "Name": "TCP", + "Parameters": [], + "GenericParameter": [], + "Literal": "12" + }, + { + "Kind": "Field", + "Name": "TIMER", + "Parameters": [], + "GenericParameter": [], + "Literal": "13" + }, + { + "Kind": "Field", + "Name": "TTY", + "Parameters": [], + "GenericParameter": [], + "Literal": "14" + }, + { + "Kind": "Field", + "Name": "UDP", + "Parameters": [], + "GenericParameter": [], + "Literal": "15" + }, + { + "Kind": "Field", + "Name": "SIGNAL", + "Parameters": [], + "GenericParameter": [], + "Literal": "16" + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+RequestType", + "Visibility": "Public", + "Kind": "Enumeration", + "Sealed": true, + "ImplementedInterfaces": [], + "Members": [ + { + "Kind": "Field", + "Name": "Unknown", + "Parameters": [], + "GenericParameter": [], + "Literal": "0" + }, + { + "Kind": "Field", + "Name": "REQ", + "Parameters": [], + "GenericParameter": [], + "Literal": "1" + }, + { + "Kind": "Field", + "Name": "CONNECT", + "Parameters": [], + "GenericParameter": [], + "Literal": "2" + }, + { + "Kind": "Field", + "Name": "WRITE", + "Parameters": [], + "GenericParameter": [], + "Literal": "3" + }, + { + "Kind": "Field", + "Name": "SHUTDOWN", + "Parameters": [], + "GenericParameter": [], + "Literal": "4" + }, + { + "Kind": "Field", + "Name": "UDP_SEND", + "Parameters": [], + "GenericParameter": [], + "Literal": "5" + }, + { + "Kind": "Field", + "Name": "FS", + "Parameters": [], + "GenericParameter": [], + "Literal": "6" + }, + { + "Kind": "Field", + "Name": "WORK", + "Parameters": [], + "GenericParameter": [], + "Literal": "7" + }, + { + "Kind": "Field", + "Name": "GETADDRINFO", + "Parameters": [], + "GenericParameter": [], + "Literal": "8" + }, + { + "Kind": "Field", + "Name": "GETNAMEINFO", + "Parameters": [], + "GenericParameter": [], + "Literal": "9" + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.DateHeaderValueManager+DateHeaderValues", + "Visibility": "Public", + "Kind": "Class", + "ImplementedInterfaces": [], + "Members": [ + { + "Kind": "Constructor", + "Name": ".ctor", + "Parameters": [], + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Field", + "Name": "Bytes", + "Parameters": [], + "ReturnType": "System.Byte[]", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Field", + "Name": "String", + "Parameters": [], + "ReturnType": "System.String", + "Visibility": "Public", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.Frame+RequestLineStatus", + "Visibility": "Protected", + "Kind": "Enumeration", + "Sealed": true, + "ImplementedInterfaces": [], + "Members": [ + { + "Kind": "Field", + "Name": "Empty", + "Parameters": [], + "GenericParameter": [], + "Literal": "0" + }, + { + "Kind": "Field", + "Name": "MethodIncomplete", + "Parameters": [], + "GenericParameter": [], + "Literal": "1" + }, + { + "Kind": "Field", + "Name": "TargetIncomplete", + "Parameters": [], + "GenericParameter": [], + "Literal": "2" + }, + { + "Kind": "Field", + "Name": "VersionIncomplete", + "Parameters": [], + "GenericParameter": [], + "Literal": "3" + }, + { + "Kind": "Field", + "Name": "Incomplete", + "Parameters": [], + "GenericParameter": [], + "Literal": "4" + }, + { + "Kind": "Field", + "Name": "Done", + "Parameters": [], + "GenericParameter": [], + "Literal": "5" + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.Frame+RequestProcessingStatus", + "Visibility": "Protected", + "Kind": "Enumeration", + "Sealed": true, + "ImplementedInterfaces": [], + "Members": [ + { + "Kind": "Field", + "Name": "RequestPending", + "Parameters": [], + "GenericParameter": [], + "Literal": "0" + }, + { + "Kind": "Field", + "Name": "RequestStarted", + "Parameters": [], + "GenericParameter": [], + "Literal": "1" + }, + { + "Kind": "Field", + "Name": "ResponseStarted", + "Parameters": [], + "GenericParameter": [], + "Literal": "2" + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.FrameRequestHeaders+Enumerator", + "Visibility": "Public", + "Kind": "Struct", + "Sealed": true, + "ImplementedInterfaces": [ + "System.Collections.Generic.IEnumerator>" + ], + "Members": [ + { + "Kind": "Method", + "Name": "MoveNext", + "Parameters": [], + "ReturnType": "System.Boolean", + "Sealed": true, + "Virtual": true, + "ImplementedInterface": "System.Collections.IEnumerator", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_Current", + "Parameters": [], + "ReturnType": "System.Collections.Generic.KeyValuePair", + "Sealed": true, + "Virtual": true, + "ImplementedInterface": "System.Collections.Generic.IEnumerator>", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "Dispose", + "Parameters": [], + "ReturnType": "System.Void", + "Sealed": true, + "Virtual": true, + "ImplementedInterface": "System.IDisposable", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "Reset", + "Parameters": [], + "ReturnType": "System.Void", + "Sealed": true, + "Virtual": true, + "ImplementedInterface": "System.Collections.IEnumerator", + "Visibility": "Public", + "GenericParameter": [] + } + ], + "GenericParameters": [] + }, + { + "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.FrameResponseHeaders+Enumerator", + "Visibility": "Public", + "Kind": "Struct", + "Sealed": true, + "ImplementedInterfaces": [ + "System.Collections.Generic.IEnumerator>" + ], + "Members": [ + { + "Kind": "Method", + "Name": "MoveNext", + "Parameters": [], + "ReturnType": "System.Boolean", + "Sealed": true, + "Virtual": true, + "ImplementedInterface": "System.Collections.IEnumerator", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "get_Current", + "Parameters": [], + "ReturnType": "System.Collections.Generic.KeyValuePair", + "Sealed": true, + "Virtual": true, + "ImplementedInterface": "System.Collections.Generic.IEnumerator>", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "Dispose", + "Parameters": [], + "ReturnType": "System.Void", + "Sealed": true, + "Virtual": true, + "ImplementedInterface": "System.IDisposable", + "Visibility": "Public", + "GenericParameter": [] + }, + { + "Kind": "Method", + "Name": "Reset", + "Parameters": [], + "ReturnType": "System.Void", + "Sealed": true, + "Virtual": true, + "ImplementedInterface": "System.Collections.IEnumerator", + "Visibility": "Public", + "GenericParameter": [] + } + ], + "GenericParameters": [] + } + ] +} \ No newline at end of file From 5b65117b64dd58518e22edbbac480b30403bf949 Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Fri, 4 Nov 2016 16:14:06 -0700 Subject: [PATCH 0942/1662] Add functional regression test for 'Connection: keep-alive, upgrade' request header. --- .../RequestTests.cs | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs index 0d803c45da..d1ce7b8951 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs @@ -14,6 +14,7 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; using Microsoft.AspNetCore.Testing.xunit; using Microsoft.Extensions.Logging.Testing; @@ -190,6 +191,47 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } } + [Fact] + public void CanUpgradeRequestWithConnectionKeepAliveUpgradeHeader() + { + var dataRead = false; + var builder = new WebHostBuilder() + .UseKestrel() + .UseUrls($"http://127.0.0.1:0") + .Configure(app => + { + app.Run(async context => + { + var stream = await context.Features.Get().UpgradeAsync(); + var data = new byte[3]; + var bytesRead = 0; + + while (bytesRead < 3) + { + bytesRead += await stream.ReadAsync(data, bytesRead, data.Length - bytesRead); + } + + dataRead = Encoding.ASCII.GetString(data, 0, 3) == "abc"; + }); + }); + + using (var host = builder.Build()) + { + host.Start(); + + using (var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)) + { + socket.Connect(new IPEndPoint(IPAddress.Loopback, host.GetPort())); + socket.Send(Encoding.ASCII.GetBytes("GET / HTTP/1.1\r\nConnection: keep-alive, upgrade\r\n\r\n")); + socket.Send(Encoding.ASCII.GetBytes("abc")); + + while (socket.Receive(new byte[1024]) > 0) ; + } + } + + Assert.True(dataRead); + } + [Fact] public async Task ConnectionResetAbortsRequest() { From a1c598733b4d834a8a36359f52e447e99da2f142 Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Thu, 3 Nov 2016 13:57:55 -0700 Subject: [PATCH 0943/1662] Reject POST and PUT requests with no Content-Length or Transfer-Encoding (#1130). --- .../BadHttpRequestException.cs | 6 ++++ .../Internal/Http/MessageBody.cs | 25 ++++++++++---- .../Internal/Http/RequestRejectionReason.cs | 4 ++- .../MaxRequestLineSizeTests.cs | 28 +++++++-------- .../BadHttpRequestTests.cs | 30 ++++++++++++++++ .../MessageBodyTests.cs | 34 ++++++++++++++++++- 6 files changed, 105 insertions(+), 22 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/BadHttpRequestException.cs b/src/Microsoft.AspNetCore.Server.Kestrel/BadHttpRequestException.cs index 2b4aa25f12..cb37af76c1 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/BadHttpRequestException.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/BadHttpRequestException.cs @@ -102,6 +102,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel case RequestRejectionReason.FinalTransferCodingNotChunked: ex = new BadHttpRequestException($"Final transfer coding is not \"chunked\": \"{value}\"", 400); break; + case RequestRejectionReason.LengthRequired: + ex = new BadHttpRequestException($"{value} request contains no Content-Length or Transfer-Encoding header", 411); + break; + case RequestRejectionReason.LengthRequiredHttp10: + ex = new BadHttpRequestException($"{value} request contains no Content-Length header", 400); + break; default: ex = new BadHttpRequestException("Bad request.", 400); break; diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/MessageBody.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/MessageBody.cs index c2843a2d00..5fb8fa2c3a 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/MessageBody.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/MessageBody.cs @@ -6,6 +6,7 @@ using System.IO; using System.Numerics; using System.Threading; using System.Threading.Tasks; +using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.Extensions.Internal; using Microsoft.Extensions.Primitives; @@ -266,17 +267,29 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http return new ForChunkedEncoding(keepAlive, headers, context); } - var unparsedContentLength = headers.HeaderContentLength.ToString(); - if (unparsedContentLength.Length > 0) + var unparsedContentLength = headers.HeaderContentLength; + if (unparsedContentLength.Count > 0) { - long contentLength; - if (!long.TryParse(unparsedContentLength, out contentLength) || contentLength < 0) + try + { + var contentLength = FrameHeaders.ParseContentLength(unparsedContentLength); + return new ForContentLength(keepAlive, contentLength, context); + } + catch (InvalidOperationException) { context.RejectRequest(RequestRejectionReason.InvalidContentLength, unparsedContentLength); } - else + } + + // Avoid slowing down most common case + if (!object.ReferenceEquals(context.Method, HttpMethods.Get)) + { + // If we got here, request contains no Content-Length or Transfer-Encoding header. + // Reject with 411 Length Required. + if (HttpMethods.IsPost(context.Method) || HttpMethods.IsPut(context.Method)) { - return new ForContentLength(keepAlive, contentLength, context); + var requestRejectionReason = httpVersion == HttpVersion.Http11 ? RequestRejectionReason.LengthRequired : RequestRejectionReason.LengthRequiredHttp10; + context.RejectRequest(requestRejectionReason, context.Method); } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/RequestRejectionReason.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/RequestRejectionReason.cs index 68693304e0..0c05a6b8ea 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/RequestRejectionReason.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/RequestRejectionReason.cs @@ -27,6 +27,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http MissingCRInHeaderLine, TooManyHeaders, RequestTimeout, - FinalTransferCodingNotChunked + FinalTransferCodingNotChunked, + LengthRequired, + LengthRequiredHttp10, } } diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/MaxRequestLineSizeTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/MaxRequestLineSizeTests.cs index 35b66ed5b5..1118f28d07 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/MaxRequestLineSizeTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/MaxRequestLineSizeTests.cs @@ -11,19 +11,19 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests public class MaxRequestLineSizeTests { [Theory] - [InlineData("GET / HTTP/1.1\r\n", 16)] - [InlineData("GET / HTTP/1.1\r\n", 17)] - [InlineData("GET / HTTP/1.1\r\n", 137)] - [InlineData("POST /abc/de HTTP/1.1\r\n", 23)] - [InlineData("POST /abc/de HTTP/1.1\r\n", 24)] - [InlineData("POST /abc/de HTTP/1.1\r\n", 287)] - [InlineData("PUT /abc/de?f=ghi HTTP/1.1\r\n", 28)] - [InlineData("PUT /abc/de?f=ghi HTTP/1.1\r\n", 29)] - [InlineData("PUT /abc/de?f=ghi HTTP/1.1\r\n", 589)] - [InlineData("DELETE /a%20b%20c/d%20e?f=ghi HTTP/1.1\r\n", 40)] - [InlineData("DELETE /a%20b%20c/d%20e?f=ghi HTTP/1.1\r\n", 41)] - [InlineData("DELETE /a%20b%20c/d%20e?f=ghi HTTP/1.1\r\n", 1027)] - public async Task ServerAcceptsRequestLineWithinLimit(string requestLine, int limit) + [InlineData("GET / HTTP/1.1\r\n\r\n", 16)] + [InlineData("GET / HTTP/1.1\r\n\r\n", 17)] + [InlineData("GET / HTTP/1.1\r\n\r\n", 137)] + [InlineData("POST /abc/de HTTP/1.1\r\nContent-Length: 0\r\n\r\n", 23)] + [InlineData("POST /abc/de HTTP/1.1\r\nContent-Length: 0\r\n\r\n", 24)] + [InlineData("POST /abc/de HTTP/1.1\r\nContent-Length: 0\r\n\r\n", 287)] + [InlineData("PUT /abc/de?f=ghi HTTP/1.1\r\nContent-Length: 0\r\n\r\n", 28)] + [InlineData("PUT /abc/de?f=ghi HTTP/1.1\r\nContent-Length: 0\r\n\r\n", 29)] + [InlineData("PUT /abc/de?f=ghi HTTP/1.1\r\nContent-Length: 0\r\n\r\n", 589)] + [InlineData("DELETE /a%20b%20c/d%20e?f=ghi HTTP/1.1\r\n\r\n", 40)] + [InlineData("DELETE /a%20b%20c/d%20e?f=ghi HTTP/1.1\r\n\r\n", 41)] + [InlineData("DELETE /a%20b%20c/d%20e?f=ghi HTTP/1.1\r\n\r\n", 1027)] + public async Task ServerAcceptsRequestLineWithinLimit(string request, int limit) { var maxRequestLineSize = limit; @@ -31,7 +31,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { using (var connection = new TestConnection(server.Port)) { - await connection.SendEnd($"{requestLine}\r\n"); + await connection.SendEnd(request); await connection.ReceiveEnd( "HTTP/1.1 200 OK", $"Date: {server.Context.DateHeaderValue}", diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/BadHttpRequestTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/BadHttpRequestTests.cs index a4e0f11169..7b8b6a0114 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/BadHttpRequestTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/BadHttpRequestTests.cs @@ -174,6 +174,36 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } } + [Theory] + [InlineData("POST")] + [InlineData("PUT")] + public async Task BadRequestIfMethodRequiresLengthButNoContentLengthOrTransferEncodingInRequest(string method) + { + using (var server = new TestServer(context => { return Task.FromResult(0); })) + { + using (var connection = server.CreateConnection()) + { + await connection.SendEnd($"{method} / HTTP/1.1\r\n\r\n"); + await ReceiveBadRequestResponse(connection, "411 Length Required", server.Context.DateHeaderValue); + } + } + } + + [Theory] + [InlineData("POST")] + [InlineData("PUT")] + public async Task BadRequestIfMethodRequiresLengthButNoContentLengthInHttp10Request(string method) + { + using (var server = new TestServer(context => { return Task.FromResult(0); })) + { + using (var connection = server.CreateConnection()) + { + await connection.SendEnd($"{method} / HTTP/1.0\r\n\r\n"); + await ReceiveBadRequestResponse(connection, "400 Bad Request", server.Context.DateHeaderValue); + } + } + } + private async Task ReceiveBadRequestResponse(TestConnection connection, string expectedResponseStatusCode, string expectedDateHeaderValue) { await connection.ReceiveForcedEnd( diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/MessageBodyTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/MessageBodyTests.cs index 4ada15b2c5..a5ed8d7c9f 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/MessageBodyTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/MessageBodyTests.cs @@ -196,13 +196,45 @@ namespace Microsoft.AspNetCore.Server.KestrelTests using (var input = new TestInput()) { var ex = Assert.Throws(() => - MessageBody.For(HttpVersion.Http10, new FrameRequestHeaders { HeaderTransferEncoding = "chunked, not-chunked" }, input.FrameContext)); + MessageBody.For(HttpVersion.Http11, new FrameRequestHeaders { HeaderTransferEncoding = "chunked, not-chunked" }, input.FrameContext)); Assert.Equal(400, ex.StatusCode); Assert.Equal("Final transfer coding is not \"chunked\": \"chunked, not-chunked\"", ex.Message); } } + [Theory] + [InlineData("POST")] + [InlineData("PUT")] + public void ForThrowsWhenMethodRequiresLengthButNoContentLengthOrTransferEncodingIsSet(string method) + { + using (var input = new TestInput()) + { + input.FrameContext.Method = method; + var ex = Assert.Throws(() => + MessageBody.For(HttpVersion.Http11, new FrameRequestHeaders(), input.FrameContext)); + + Assert.Equal(411, ex.StatusCode); + Assert.Equal($"{method} request contains no Content-Length or Transfer-Encoding header", ex.Message); + } + } + + [Theory] + [InlineData("POST")] + [InlineData("PUT")] + public void ForThrowsWhenMethodRequiresLengthButNoContentLengthSetHttp10(string method) + { + using (var input = new TestInput()) + { + input.FrameContext.Method = method; + var ex = Assert.Throws(() => + MessageBody.For(HttpVersion.Http10, new FrameRequestHeaders(), input.FrameContext)); + + Assert.Equal(400, ex.StatusCode); + Assert.Equal($"{method} request contains no Content-Length header", ex.Message); + } + } + public static IEnumerable StreamData => new[] { new object[] { new ThrowOnWriteSynchronousStream() }, From a83bbcfba7f7782669ca3dbfd9b34b458e4fd4a5 Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Fri, 4 Nov 2016 11:39:27 -0700 Subject: [PATCH 0944/1662] Prevent block leak when socket is closed before connection filter is applied. --- .../Internal/Http/Connection.cs | 20 ++++++++----- .../Internal/Http/Frame.cs | 4 +++ .../HttpsTests.cs | 30 +++++++++++++++++++ 3 files changed, 46 insertions(+), 8 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Connection.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Connection.cs index d48bc08944..f92f419bf8 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Connection.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Connection.cs @@ -154,15 +154,20 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http // Called on Libuv thread public virtual void OnSocketClosed() { - if (_filteredStreamAdapter != null) + _frame.FrameStartedTask.ContinueWith((task, state) => { - Task.WhenAll(_readInputTask, _frame.StopAsync()).ContinueWith((task, state) => + var connection = (Connection)state; + + if (_filteredStreamAdapter != null) { - var connection = (Connection)state; - connection._filterContext.Connection.Dispose(); - connection._filteredStreamAdapter.Dispose(); - }, this); - } + Task.WhenAll(_readInputTask, _frame.StopAsync()).ContinueWith((task2, state2) => + { + var connection2 = (Connection)state2; + connection2._filterContext.Connection.Dispose(); + connection2._filteredStreamAdapter.Dispose(); + }, connection); + } + }, this); SocketInput.Dispose(); _socketClosedTcs.TrySetResult(null); @@ -199,7 +204,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } _frame.PrepareRequest = _filterContext.PrepareRequest; - _frame.Start(); } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs index c4a0c50d85..eabcf12081 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs @@ -51,6 +51,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http protected Stack, object>> _onStarting; protected Stack, object>> _onCompleted; + private TaskCompletionSource _frameStartedTcs = new TaskCompletionSource(); private Task _requestProcessingTask; protected volatile bool _requestProcessingStopping; // volatile, see: https://msdn.microsoft.com/en-us/library/x13ttww7.aspx protected int _requestAborted; @@ -205,6 +206,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http public Stream DuplexStream { get; set; } + public Task FrameStartedTask => _frameStartedTcs.Task; + public CancellationToken RequestAborted { get @@ -366,6 +369,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http default(CancellationToken), TaskCreationOptions.DenyChildAttach, TaskScheduler.Default).Unwrap(); + _frameStartedTcs.SetResult(null); } /// diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/HttpsTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/HttpsTests.cs index 8f3a624406..f6badb31cf 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/HttpsTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/HttpsTests.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Net; using System.Net.Security; using System.Net.Sockets; using System.Security.Authentication; @@ -184,6 +185,35 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests await tcs.Task.TimeoutAfter(TimeSpan.FromSeconds(10)); } + // Regression test for https://github.com/aspnet/KestrelHttpServer/pull/1197 + [Fact] + public void ConnectionFilterDoesNotLeakBlock() + { + var loggerFactory = new HandshakeErrorLoggerFactory(); + + var hostBuilder = new WebHostBuilder() + .UseKestrel(options => + { + options.UseHttps(@"TestResources/testCert.pfx", "testPassword"); + }) + .UseUrls("https://127.0.0.1:0/") + .UseLoggerFactory(loggerFactory) + .Configure(app => { }); + + using (var host = hostBuilder.Build()) + { + host.Start(); + + using (var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)) + { + socket.Connect(new IPEndPoint(IPAddress.Loopback, host.GetPort())); + + // Close socket immediately + socket.LingerState = new LingerOption(true, 0); + } + } + } + private class HandshakeErrorLoggerFactory : ILoggerFactory { public HttpsConnectionFilterLogger FilterLogger { get; } = new HttpsConnectionFilterLogger(); From 0d559468f1e18d1e3dc6693fcbc5b27c704d2d02 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Fri, 4 Nov 2016 16:00:41 -0700 Subject: [PATCH 0945/1662] Make connection reset logs less scary - Particularly between requests, connection resets aren't that abnormal. --- .../Internal/Http/Connection.cs | 12 +- .../Internal/Http/Frame.cs | 2 +- .../Internal/Http/FrameOfT.cs | 26 ++- .../Internal/Http/SocketOutput.cs | 11 +- .../Internal/Infrastructure/Constants.cs | 20 ++- .../Internal/Infrastructure/IKestrelTrace.cs | 4 + .../Internal/Infrastructure/KestrelTrace.cs | 16 +- .../KestrelServer.cs | 5 + .../RequestTests.cs | 151 ++++++++++++++++-- 9 files changed, 225 insertions(+), 22 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Connection.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Connection.cs index f92f419bf8..3f61f8530c 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Connection.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Connection.cs @@ -262,7 +262,17 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { Exception uvError; handle.Libuv.Check(status, out uvError); - Log.ConnectionError(ConnectionId, uvError); + + // Log connection resets at a lower (Debug) level. + if (status == Constants.ECONNRESET) + { + Log.ConnectionReset(ConnectionId); + } + else + { + Log.ConnectionError(ConnectionId, uvError); + } + error = new IOException(uvError.Message, uvError); } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs index eabcf12081..725e284bc6 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs @@ -117,7 +117,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http private KestrelServerOptions ServerOptions { get; } private IPEndPoint LocalEndPoint => ConnectionContext.LocalEndPoint; private IPEndPoint RemoteEndPoint => ConnectionContext.RemoteEndPoint; - private string ConnectionId => ConnectionContext.ConnectionId; + protected string ConnectionId => ConnectionContext.ConnectionId; public string ConnectionIdFeature { get; set; } public IPAddress RemoteIpAddress { get; set; } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameOfT.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameOfT.cs index 2d0eecad6e..a59b010e32 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameOfT.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameOfT.cs @@ -2,10 +2,12 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.IO; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Hosting.Server; -using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; using Microsoft.Extensions.Logging; namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http @@ -29,21 +31,30 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http /// public override async Task RequestProcessingAsync() { + var requestLineStatus = RequestLineStatus.Empty; + try { while (!_requestProcessingStopping) { ConnectionControl.SetTimeout(_keepAliveMilliseconds, TimeoutAction.CloseConnection); - while (!_requestProcessingStopping && TakeStartLine(SocketInput) != RequestLineStatus.Done) + while (!_requestProcessingStopping) { + requestLineStatus = TakeStartLine(SocketInput); + + if (requestLineStatus == RequestLineStatus.Done) + { + break; + } + if (SocketInput.CheckFinOrThrow()) { // We need to attempt to consume start lines and headers even after // SocketInput.RemoteIntakeFin is set to true to ensure we don't close a // connection without giving the application a chance to respond to a request // sent immediately before the a FIN from the client. - var requestLineStatus = TakeStartLine(SocketInput); + requestLineStatus = TakeStartLine(SocketInput); if (requestLineStatus == RequestLineStatus.Empty) { @@ -188,6 +199,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http // SetBadRequestState logs the error. SetBadRequestState(ex); } + catch (IOException ex) when (ex.InnerException is UvException) + { + // Don't log ECONNRESET errors made between requests. Browsers like IE will reset connections regularly. + if (requestLineStatus != RequestLineStatus.Empty || + ((UvException)ex.InnerException).StatusCode != Constants.ECONNRESET) + { + Log.RequestProcessingError(ConnectionId, ex); + } + } catch (Exception ex) { Log.LogWarning(0, ex, "Connection processing ended abnormally"); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/SocketOutput.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/SocketOutput.cs index 86b274dd12..4a6cac5006 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/SocketOutput.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/SocketOutput.cs @@ -393,7 +393,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http else { CompleteAllWrites(); - _log.ConnectionError(_connectionId, error); + + // Log connection resets at a lower (Debug) level. + if (status == Constants.ECONNRESET) + { + _log.ConnectionReset(_connectionId); + } + else + { + _log.ConnectionError(_connectionId, error); + } } if (!_postingWrite && _nextWriteContext != null) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/Constants.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/Constants.cs index ddc9f767b9..77968bca17 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/Constants.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/Constants.cs @@ -10,6 +10,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure public const int ListenBacklog = 128; public const int EOF = -4095; + public static readonly int? ECONNRESET = GetECONNRESET(); public static readonly int? EADDRINUSE = GetEADDRINUSE(); /// @@ -19,11 +20,28 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure public const string ServerName = "Kestrel"; + private static int? GetECONNRESET() + { + if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + { + return -4077; + } + else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) + { + return -104; + } + else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) + { + return -54; + } + return null; + } + private static int? GetEADDRINUSE() { if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { - return -4091; + return -4091; } else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/IKestrelTrace.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/IKestrelTrace.cs index 2be2acbfc3..2645aa8e88 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/IKestrelTrace.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/IKestrelTrace.cs @@ -31,6 +31,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure void ConnectionError(string connectionId, Exception ex); + void ConnectionReset(string connectionId); + + void RequestProcessingError(string connectionId, Exception ex); + void ConnectionDisconnectedWrite(string connectionId, int count, Exception ex); void ConnectionHeadResponseBodyWrite(string connectionId, long count); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/KestrelTrace.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/KestrelTrace.cs index fcdc3f9208..181e6380a2 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/KestrelTrace.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/KestrelTrace.cs @@ -27,6 +27,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal private static readonly Action _connectionHeadResponseBodyWrite; private static readonly Action _notAllConnectionsClosedGracefully; private static readonly Action _connectionBadRequest; + private static readonly Action _connectionReset; + private static readonly Action _requestProcessingError; protected readonly ILogger _logger; @@ -45,11 +47,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal // ConnectionWrite: Reserved: 11 // ConnectionWriteCallback: Reserved: 12 _applicationError = LoggerMessage.Define(LogLevel.Error, 13, @"Connection id ""{ConnectionId}"": An unhandled exception was thrown by the application."); - _connectionError = LoggerMessage.Define(LogLevel.Information, 14, @"Connection id ""{ConnectionId}"" communication error"); + _connectionError = LoggerMessage.Define(LogLevel.Information, 14, @"Connection id ""{ConnectionId}"" communication error."); _connectionDisconnectedWrite = LoggerMessage.Define(LogLevel.Debug, 15, @"Connection id ""{ConnectionId}"" write of ""{count}"" bytes to disconnected client."); _notAllConnectionsClosedGracefully = LoggerMessage.Define(LogLevel.Debug, 16, "Some connections failed to close gracefully during server shutdown."); _connectionBadRequest = LoggerMessage.Define(LogLevel.Information, 17, @"Connection id ""{ConnectionId}"" bad request data: ""{message}"""); _connectionHeadResponseBodyWrite = LoggerMessage.Define(LogLevel.Debug, 18, @"Connection id ""{ConnectionId}"" write of ""{count}"" body bytes to non-body HEAD response."); + _connectionReset = LoggerMessage.Define(LogLevel.Debug, 19, @"Connection id ""{ConnectionId}"" reset."); + _requestProcessingError = LoggerMessage.Define(LogLevel.Information, 20, @"Connection id ""{ConnectionId}"" request processing ended abnormally."); } public KestrelTrace(ILogger logger) @@ -150,6 +154,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal _connectionBadRequest(_logger, connectionId, ex.Message, ex); } + public virtual void ConnectionReset(string connectionId) + { + _connectionReset(_logger, connectionId, null); + } + + public virtual void RequestProcessingError(string connectionId, Exception ex) + { + _requestProcessingError(_logger, connectionId, ex); + } + public virtual void Log(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func formatter) { _logger.Log(logLevel, eventId, state, exception, formatter); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServer.cs b/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServer.cs index d26fa002b0..e7e4e38d62 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServer.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServer.cs @@ -100,6 +100,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel "ThreadCount must be positive."); } + if (!Constants.ECONNRESET.HasValue) + { + _logger.LogWarning("Unable to determine ECONNRESET value on this platform."); + } + if (!Constants.EADDRINUSE.HasValue) { _logger.LogWarning("Unable to determine EADDRINUSE value on this platform."); diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs index d1ce7b8951..645f7c5205 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs @@ -17,6 +17,7 @@ using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; using Microsoft.AspNetCore.Testing.xunit; +using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Testing; using Newtonsoft.Json; using Newtonsoft.Json.Linq; @@ -233,12 +234,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } [Fact] - public async Task ConnectionResetAbortsRequest() + public async Task ConnectionResetPriorToRequestIsLoggedAsDebug() { var connectionStarted = new SemaphoreSlim(0); - var connectionErrorLogged = new SemaphoreSlim(0); + var connectionResetLogged = new SemaphoreSlim(0); var testSink = new ConnectionErrorTestSink( - () => connectionStarted.Release(), () => connectionErrorLogged.Release()); + () => connectionStarted.Release(), () => connectionResetLogged.Release(), () => { }); var builder = new WebHostBuilder() .UseLoggerFactory(new TestLoggerFactory(testSink, true)) .UseKestrel() @@ -257,16 +258,118 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests socket.Connect(new IPEndPoint(IPAddress.Loopback, host.GetPort())); // Wait until connection is established Assert.True(await connectionStarted.WaitAsync(_semaphoreWaitTimeout)); + // Force a reset socket.LingerState = new LingerOption(true, 0); } // Wait until connection error is logged - Assert.True(await connectionErrorLogged.WaitAsync(_semaphoreWaitTimeout)); + Assert.True(await connectionResetLogged.WaitAsync(_semaphoreWaitTimeout)); + + // Check the no log level higher than Debug was used for a reset before a request + Assert.Equal(LogLevel.Debug, testSink.MaxLogLevel); // Check for expected message - Assert.NotNull(testSink.ConnectionErrorMessage); - Assert.Contains("ECONNRESET", testSink.ConnectionErrorMessage); + Assert.NotNull(testSink.ConnectionResetMessage); + Assert.Contains("reset", testSink.ConnectionResetMessage); + } + } + + [Fact] + public async Task ConnectionResetBetweenRequestsIsLoggedAsDebug() + { + var connectionStarted = new SemaphoreSlim(0); + var connectionResetLogged = new SemaphoreSlim(0); + var testSink = new ConnectionErrorTestSink( + () => { }, () => connectionResetLogged.Release(), () => { }); + var builder = new WebHostBuilder() + .UseLoggerFactory(new TestLoggerFactory(testSink, true)) + .UseKestrel() + .UseUrls($"http://127.0.0.1:0") + .Configure(app => app.Run(context => + { + connectionStarted.Release(); + return Task.FromResult(0); + })); + + using (var host = builder.Build()) + { + host.Start(); + + using (var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)) + { + socket.Connect(new IPEndPoint(IPAddress.Loopback, host.GetPort())); + socket.Send(Encoding.ASCII.GetBytes("GET / HTTP/1.1\r\n\r\n")); + + // Wait until connection is established + Assert.True(await connectionStarted.WaitAsync(_semaphoreWaitTimeout)); + + // Force a reset + socket.LingerState = new LingerOption(true, 0); + } + + // Wait until connection error is logged + Assert.True(await connectionResetLogged.WaitAsync(_semaphoreWaitTimeout)); + + // Check the no log level higher than Debug was used for a reset between a requests + Assert.Equal(LogLevel.Debug, testSink.MaxLogLevel); + + // Check for expected message + Assert.NotNull(testSink.ConnectionResetMessage); + Assert.Contains("reset", testSink.ConnectionResetMessage); + } + } + + [Fact] + public async Task ConnectionResetMidRequestIsLoggedAsInformation() + { + var connectionStarted = new SemaphoreSlim(0); + var connectionResetLogged = new SemaphoreSlim(0); + var requestProcessingErrorLogged = new SemaphoreSlim(0); + var testSink = new ConnectionErrorTestSink( + () => connectionStarted.Release(), () => connectionResetLogged.Release(), () => requestProcessingErrorLogged.Release()); + var builder = new WebHostBuilder() + .UseLoggerFactory(new TestLoggerFactory(testSink, true)) + .UseKestrel() + .UseUrls($"http://127.0.0.1:0") + .Configure(app => app.Run(context => + { + return Task.FromResult(0); + })); + + using (var host = builder.Build()) + { + host.Start(); + + using (var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)) + { + socket.Connect(new IPEndPoint(IPAddress.Loopback, host.GetPort())); + socket.Send(Encoding.ASCII.GetBytes("GET")); + + // Wait until connection is established + Assert.True(await connectionStarted.WaitAsync(_semaphoreWaitTimeout)); + + // Ensure "GET" has been processed + // Sadly, there is no event/log for starting request line processing + await Task.Delay(1000); + + // Force a reset, give some time for the "GET" to be processed + socket.LingerState = new LingerOption(true, 0); + } + + // Wait until connection error and request processingError is logged + var waitAsyncResults = await Task.WhenAll(connectionResetLogged.WaitAsync(_semaphoreWaitTimeout), requestProcessingErrorLogged.WaitAsync(_semaphoreWaitTimeout)); + + Assert.All(waitAsyncResults, Assert.True); + + // Check the no log level lower than Information was used for a reset mid-request + Assert.Equal(LogLevel.Information, testSink.MaxLogLevel); + + // Check for expected message + Assert.NotNull(testSink.ConnectionResetMessage); + Assert.Contains("reset", testSink.ConnectionResetMessage); + Assert.NotNull(testSink.RequestProcessingErrorMessage); + Assert.Contains("abnormal", testSink.RequestProcessingErrorMessage); } } @@ -357,15 +460,24 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests private class ConnectionErrorTestSink : ITestSink { private readonly Action _connectionStarted; - private readonly Action _connectionErrorLogged; + private readonly Action _connectionResetLogged; + private readonly Action _requestProcessingErrorLogged; - public ConnectionErrorTestSink(Action connectionStarted, Action connectionErrorLogged) + public ConnectionErrorTestSink( + Action connectionStarted, + Action connectionResetLogged, + Action requestProcessingErrorLogged) { _connectionStarted = connectionStarted; - _connectionErrorLogged = connectionErrorLogged; + _connectionResetLogged = connectionResetLogged; + _requestProcessingErrorLogged = requestProcessingErrorLogged; } - public string ConnectionErrorMessage { get; set; } + public LogLevel MaxLogLevel { get; set; } + + public string ConnectionResetMessage { get; set; } + + public string RequestProcessingErrorMessage { get; set; } public Func BeginEnabled { get; set; } @@ -381,17 +493,28 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests public void Write(WriteContext context) { + if (context.LoggerName == "Microsoft.AspNetCore.Server.Kestrel" && context.LogLevel > MaxLogLevel) + { + MaxLogLevel = context.LogLevel; + } + const int connectionStartEventId = 1; - const int connectionErrorEventId = 14; + const int connectionResetEventId = 19; + const int requestProcessingErrorEventId = 20; if (context.EventId.Id == connectionStartEventId) { _connectionStarted(); } - else if (context.EventId.Id == connectionErrorEventId) + else if (context.EventId.Id == connectionResetEventId) { - ConnectionErrorMessage = context.Exception?.Message; - _connectionErrorLogged(); + ConnectionResetMessage = context.Formatter(context.State, context.Exception); + _connectionResetLogged(); + } + else if (context.EventId.Id == requestProcessingErrorEventId) + { + RequestProcessingErrorMessage = context.Formatter(context.State, context.Exception); + _requestProcessingErrorLogged(); } } } From 194059a198d843ede2b96b067b2b50c4e602c8d9 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Fri, 21 Oct 2016 16:22:13 -0700 Subject: [PATCH 0946/1662] Implement Begin/End Read/Write methods in LoggingStream - This allows the reads and writes from SslStream to be logged on desktop .NET --- .../Filter/Internal/LoggingStream.cs | 80 +++++++++++++++++++ .../LoggingConnectionFilterTests.cs | 47 +++++++++++ .../ChunkedRequestTests.cs | 1 + .../ChunkedResponseTests.cs | 1 + .../ConnectionFilterTests.cs | 19 ++--- .../EngineTests.cs | 1 + .../PassThroughConnectionFilter.cs | 2 +- 7 files changed, 137 insertions(+), 14 deletions(-) create mode 100644 test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/LoggingConnectionFilterTests.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Filter/Internal/LoggingStream.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Filter/Internal/LoggingStream.cs index e43d1c7f2d..14890c0e3a 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Filter/Internal/LoggingStream.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Filter/Internal/LoggingStream.cs @@ -1,6 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; using System.IO; using System.Text; using System.Threading; @@ -125,5 +126,84 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Filter.Internal _logger.LogDebug(builder.ToString()); } + +#if NET451 + // The below APM methods call the underlying Read/WriteAsync methods which will still be logged. + public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback callback, object state) + { + var task = ReadAsync(buffer, offset, count, default(CancellationToken), state); + if (callback != null) + { + task.ContinueWith(t => callback.Invoke(t)); + } + return task; + } + + public override int EndRead(IAsyncResult asyncResult) + { + return ((Task)asyncResult).GetAwaiter().GetResult(); + } + + private Task ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken, object state) + { + var tcs = new TaskCompletionSource(state); + var task = ReadAsync(buffer, offset, count, cancellationToken); + task.ContinueWith((task2, state2) => + { + var tcs2 = (TaskCompletionSource)state2; + if (task2.IsCanceled) + { + tcs2.SetCanceled(); + } + else if (task2.IsFaulted) + { + tcs2.SetException(task2.Exception); + } + else + { + tcs2.SetResult(task2.Result); + } + }, tcs, cancellationToken); + return tcs.Task; + } + + public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback callback, object state) + { + var task = WriteAsync(buffer, offset, count, default(CancellationToken), state); + if (callback != null) + { + task.ContinueWith(t => callback.Invoke(t)); + } + return task; + } + + public override void EndWrite(IAsyncResult asyncResult) + { + ((Task)asyncResult).GetAwaiter().GetResult(); + } + + private Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken, object state) + { + var tcs = new TaskCompletionSource(state); + var task = WriteAsync(buffer, offset, count, cancellationToken); + task.ContinueWith((task2, state2) => + { + var tcs2 = (TaskCompletionSource)state2; + if (task2.IsCanceled) + { + tcs2.SetCanceled(); + } + else if (task2.IsFaulted) + { + tcs2.SetException(task2.Exception); + } + else + { + tcs2.SetResult(null); + } + }, tcs, cancellationToken); + return tcs.Task; + } +#endif } } diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/LoggingConnectionFilterTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/LoggingConnectionFilterTests.cs new file mode 100644 index 0000000000..6dd7a8fb98 --- /dev/null +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/LoggingConnectionFilterTests.cs @@ -0,0 +1,47 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Testing; +using Xunit; + +namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests +{ + public class LoggingConnectionFilterTests + { + [Fact] + public async Task LoggingConnectionFilterCanBeAddedBeforeAndAfterHttpsFilter() + { + var host = new WebHostBuilder() + .UseUrls($"https://127.0.0.1:0") + .UseKestrel(options => + { + options.UseConnectionLogging(); + options.UseHttps(@"TestResources/testCert.pfx", "testPassword"); + }) + .Configure(app => + { + app.Run(context => + { + context.Response.ContentLength = 12; + return context.Response.WriteAsync("Hello World!"); + }); + }) + .Build(); + + using (host) + { + host.Start(); + + var response = await HttpClientSlim.GetStringAsync($"https://localhost:{host.GetPort()}/", validateCertificate: false) + .TimeoutAfter(TimeSpan.FromSeconds(10)); + + Assert.Equal("Hello World!", response); + } + } + } +} diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedRequestTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedRequestTests.cs index 30f4ecd9d6..403e7a0208 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedRequestTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedRequestTests.cs @@ -7,6 +7,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Server.KestrelTests.TestHelpers; using Microsoft.AspNetCore.Testing; using Microsoft.Extensions.Internal; using Xunit; diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedResponseTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedResponseTests.cs index b6e59342fb..469f17051c 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedResponseTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedResponseTests.cs @@ -6,6 +6,7 @@ using System.Text; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Server.KestrelTests.TestHelpers; using Microsoft.AspNetCore.Testing; using Xunit; diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionFilterTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionFilterTests.cs index 3d1423dc2b..ea76646561 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionFilterTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionFilterTests.cs @@ -88,19 +88,12 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { using (var connection = server.CreateConnection()) { - try - { - await connection.SendEnd( - "POST / HTTP/1.0", - "Content-Length: 12", - "", - "Hello World?"); - } - catch (IOException) - { - // Will throw because the exception in the connection filter will close the connection. - Assert.True(true); - } + // Will throw because the exception in the connection filter will close the connection. + await Assert.ThrowsAsync(async () => await connection.SendEnd( + "POST / HTTP/1.0", + "Content-Length: 12", + "", + "Hello World?")); } } } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs index ef73602834..650fcedbe1 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs @@ -14,6 +14,7 @@ using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Server.Kestrel; using Microsoft.AspNetCore.Server.Kestrel.Internal; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; +using Microsoft.AspNetCore.Server.KestrelTests.TestHelpers; using Microsoft.AspNetCore.Testing; using Microsoft.Extensions.Internal; using Xunit; diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/PassThroughConnectionFilter.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/PassThroughConnectionFilter.cs index bab4e24987..b4492bb8b6 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/PassThroughConnectionFilter.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/PassThroughConnectionFilter.cs @@ -7,7 +7,7 @@ using Microsoft.AspNetCore.Server.Kestrel.Filter.Internal; using Microsoft.AspNetCore.Testing; using Microsoft.Extensions.Internal; -namespace Microsoft.AspNetCore.Server.KestrelTests +namespace Microsoft.AspNetCore.Server.KestrelTests.TestHelpers { public class PassThroughConnectionFilter : IConnectionFilter From 7c15646303e3e925eb72be6539e2192487d76596 Mon Sep 17 00:00:00 2001 From: John Luo Date: Sat, 5 Nov 2016 23:43:39 -0700 Subject: [PATCH 0947/1662] Updates for 1.0.2 --- samples/SampleApp/project.json | 2 +- src/Microsoft.AspNetCore.Server.Kestrel/project.json | 2 +- .../project.json | 6 +++--- test/Microsoft.AspNetCore.Server.KestrelTests/project.json | 2 +- .../project.json | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/samples/SampleApp/project.json b/samples/SampleApp/project.json index 6822d6300b..e632502b5a 100644 --- a/samples/SampleApp/project.json +++ b/samples/SampleApp/project.json @@ -3,7 +3,7 @@ "dependencies": { "Microsoft.AspNetCore.Server.Kestrel": "1.0.2", "Microsoft.AspNetCore.Server.Kestrel.Https": "1.0.2", - "Microsoft.Extensions.Logging.Console": "1.0.0" + "Microsoft.Extensions.Logging.Console": "1.0.1" }, "buildOptions": { "emitEntryPoint": true diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/project.json b/src/Microsoft.AspNetCore.Server.Kestrel/project.json index 0c2bc1ebc9..42b2681d9f 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/project.json +++ b/src/Microsoft.AspNetCore.Server.Kestrel/project.json @@ -18,7 +18,7 @@ "System.Threading.Tasks.Extensions": "4.0.0", "Libuv": "1.9.0", "Microsoft.AspNetCore.Hosting": "1.0.1", - "Microsoft.Extensions.Logging.Abstractions": "1.0.0" + "Microsoft.Extensions.Logging.Abstractions": "1.0.1" }, "frameworks": { "net451": { diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json index 16bdbf98ea..00c06a068b 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json @@ -2,11 +2,11 @@ "version": "1.0.0-*", "dependencies": { "dotnet-test-xunit": "1.0.0-rc3-000000-01", - "Microsoft.AspNetCore.Http.Abstractions": "1.0.0", + "Microsoft.AspNetCore.Http.Abstractions": "1.0.1", "Microsoft.AspNetCore.Server.Kestrel": "1.0.2", "Microsoft.AspNetCore.Server.Kestrel.Https": "1.0.2", - "Microsoft.AspNetCore.Testing": "1.0.0-rtm-21431", - "Microsoft.Extensions.Logging.Console": "1.0.0", + "Microsoft.AspNetCore.Testing": "1.0.1", + "Microsoft.Extensions.Logging.Console": "1.0.1", "Newtonsoft.Json": "9.0.1", "xunit": "2.1.0" }, diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/project.json b/test/Microsoft.AspNetCore.Server.KestrelTests/project.json index 0509e08481..a7fa0c7321 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/project.json +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/project.json @@ -4,7 +4,7 @@ "dotnet-test-xunit": "1.0.0-rc3-000000-01", "Microsoft.AspNetCore.Server.Kestrel": "1.0.2", "Microsoft.AspNetCore.Server.Kestrel.Https": "1.0.2", - "Microsoft.AspNetCore.Testing": "1.0.0-rtm-21431", + "Microsoft.AspNetCore.Testing": "1.0.1", "xunit": "2.1.0" }, "frameworks": { diff --git a/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/project.json b/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/project.json index 0ef1ca51fe..766acfdddd 100644 --- a/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/project.json +++ b/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/project.json @@ -4,7 +4,7 @@ "emitEntryPoint": true }, "dependencies": { - "Microsoft.AspNetCore.Http.Features": "1.0.0", + "Microsoft.AspNetCore.Http.Features": "1.0.1", "Microsoft.AspNetCore.Hosting": "1.0.1" }, "frameworks": { From 8b97327950a9e4bb93d050aa636601d8e94aca14 Mon Sep 17 00:00:00 2001 From: Pranav K Date: Tue, 8 Nov 2016 09:18:35 -0800 Subject: [PATCH 0948/1662] Updating partner package versions --- NuGet.config | 3 ++- build.ps1 | 2 +- build.sh | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/NuGet.config b/NuGet.config index adbb3c1710..06aa92dbda 100644 --- a/NuGet.config +++ b/NuGet.config @@ -2,7 +2,8 @@ - + + \ No newline at end of file diff --git a/build.ps1 b/build.ps1 index 6d49c4dccd..6e48462f03 100644 --- a/build.ps1 +++ b/build.ps1 @@ -33,7 +33,7 @@ cd $PSScriptRoot $repoFolder = $PSScriptRoot $env:REPO_FOLDER = $repoFolder -$koreBuildZip="https://github.com/aspnet/KoreBuild/archive/1.0.0.zip" +$koreBuildZip="https://github.com/aspnet/KoreBuild/archive/rel/1.0.1.zip" if ($env:KOREBUILD_ZIP) { $koreBuildZip=$env:KOREBUILD_ZIP diff --git a/build.sh b/build.sh index a55d3ebc12..023d73a87e 100755 --- a/build.sh +++ b/build.sh @@ -2,7 +2,7 @@ repoFolder="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" cd $repoFolder -koreBuildZip="https://github.com/aspnet/KoreBuild/archive/1.0.0.zip" +koreBuildZip="https://github.com/aspnet/KoreBuild/archive/rel/1.0.1.zip" if [ ! -z $KOREBUILD_ZIP ]; then koreBuildZip=$KOREBUILD_ZIP fi From 610c6ddd837aa98120825467f198a2567bfbeba3 Mon Sep 17 00:00:00 2001 From: Pranav K Date: Tue, 8 Nov 2016 09:29:49 -0800 Subject: [PATCH 0949/1662] Updating partner package versions --- samples/LargeResponseApp/project.json | 2 +- samples/SampleApp/project.json | 2 +- .../project.json | 2 +- test/Microsoft.AspNetCore.Server.KestrelTests/project.json | 2 +- .../project.json | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/samples/LargeResponseApp/project.json b/samples/LargeResponseApp/project.json index c0999b69c9..47f43cb1fb 100644 --- a/samples/LargeResponseApp/project.json +++ b/samples/LargeResponseApp/project.json @@ -11,7 +11,7 @@ "netcoreapp1.0": { "dependencies": { "Microsoft.NETCore.App": { - "version": "1.0.0", + "version": "1.0.3-*", "type": "platform" } } diff --git a/samples/SampleApp/project.json b/samples/SampleApp/project.json index e632502b5a..467673e7dc 100644 --- a/samples/SampleApp/project.json +++ b/samples/SampleApp/project.json @@ -13,7 +13,7 @@ "netcoreapp1.0": { "dependencies": { "Microsoft.NETCore.App": { - "version": "1.0.0", + "version": "1.0.3-*", "type": "platform" }, "System.Console": "4.0.0" diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json index 00c06a068b..2176ca5d32 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json @@ -14,7 +14,7 @@ "netcoreapp1.0": { "dependencies": { "Microsoft.NETCore.App": { - "version": "1.0.0", + "version": "1.0.3-*", "type": "platform" }, "System.Net.Http": "4.1.0", diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/project.json b/test/Microsoft.AspNetCore.Server.KestrelTests/project.json index a7fa0c7321..bcbf9561e3 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/project.json +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/project.json @@ -11,7 +11,7 @@ "netcoreapp1.0": { "dependencies": { "Microsoft.NETCore.App": { - "version": "1.0.0", + "version": "1.0.3-*", "type": "platform" }, "System.Diagnostics.TraceSource": "4.0.0", diff --git a/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/project.json b/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/project.json index 766acfdddd..22390e4adc 100644 --- a/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/project.json +++ b/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/project.json @@ -11,7 +11,7 @@ "netcoreapp1.0": { "dependencies": { "Microsoft.NETCore.App": { - "version": "1.0.0", + "version": "1.0.3-*", "type": "platform" } } From 84cf6789051ab75a6bc7bf1f6d4b6156f18668c8 Mon Sep 17 00:00:00 2001 From: John Luo Date: Tue, 8 Nov 2016 18:04:07 -0800 Subject: [PATCH 0950/1662] Update System.Net.Http --- .../project.json | 2 +- test/Microsoft.AspNetCore.Server.KestrelTests/project.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json index 2176ca5d32..684f86df2f 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json @@ -17,7 +17,7 @@ "version": "1.0.3-*", "type": "platform" }, - "System.Net.Http": "4.1.0", + "System.Net.Http": "4.1.1-servicing-24703-01", "System.Net.Http.WinHttpHandler": "4.0.0", "System.Runtime.Serialization.Primitives": "4.1.1" }, diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/project.json b/test/Microsoft.AspNetCore.Server.KestrelTests/project.json index bcbf9561e3..d69bc34891 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/project.json +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/project.json @@ -17,7 +17,7 @@ "System.Diagnostics.TraceSource": "4.0.0", "System.Globalization.Extensions": "4.0.1", "System.IO": "4.1.0", - "System.Net.Http": "4.1.0", + "System.Net.Http": "4.1.1-servicing-24703-01", "System.Net.Http.WinHttpHandler": "4.0.0", "System.Net.Sockets": "4.1.0", "System.Runtime.Handles": "4.0.1", From 0fbbd9e165497fa5efab852ab6d64bb9efeaa91e Mon Sep 17 00:00:00 2001 From: Pranav K Date: Wed, 9 Nov 2016 11:31:33 -0800 Subject: [PATCH 0951/1662] Branching for 1.1.0 --- NuGet.config | 4 ++-- build.ps1 | 2 +- build.sh | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/NuGet.config b/NuGet.config index 826a1f9035..6197c93176 100644 --- a/NuGet.config +++ b/NuGet.config @@ -1,7 +1,7 @@ - + - + \ No newline at end of file diff --git a/build.ps1 b/build.ps1 index 8f2f99691a..24ca167cf6 100644 --- a/build.ps1 +++ b/build.ps1 @@ -33,7 +33,7 @@ cd $PSScriptRoot $repoFolder = $PSScriptRoot $env:REPO_FOLDER = $repoFolder -$koreBuildZip="https://github.com/aspnet/KoreBuild/archive/dev.zip" +$koreBuildZip="https://github.com/aspnet/KoreBuild/archive/rel/1.1.0.zip" if ($env:KOREBUILD_ZIP) { $koreBuildZip=$env:KOREBUILD_ZIP diff --git a/build.sh b/build.sh index f4208100eb..fea9ac64ad 100755 --- a/build.sh +++ b/build.sh @@ -2,7 +2,7 @@ repoFolder="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" cd $repoFolder -koreBuildZip="https://github.com/aspnet/KoreBuild/archive/dev.zip" +koreBuildZip="https://github.com/aspnet/KoreBuild/archive/rel/1.1.0.zip" if [ ! -z $KOREBUILD_ZIP ]; then koreBuildZip=$KOREBUILD_ZIP fi From c0e75dcbf86be380526c7028e8a3607b3f5ddf84 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Mon, 7 Nov 2016 15:55:46 -0800 Subject: [PATCH 0952/1662] Always flush headers on first response write (#1202). --- .../Internal/Http/Frame.cs | 18 ++++- .../ResponseTests.cs | 80 +++++++++++++++++-- .../ChunkedResponseTests.cs | 42 ++++++++++ 3 files changed, 134 insertions(+), 6 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs index 725e284bc6..307ce7bc49 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs @@ -520,6 +520,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http public void Write(ArraySegment data) { + // For the first write, ensure headers are flushed if Write(Chunked)isn't called. + var firstWrite = !HasResponseStarted; + VerifyAndUpdateWrite(data.Count); ProduceStartAndFireOnStarting().GetAwaiter().GetResult(); @@ -529,6 +532,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { if (data.Count == 0) { + if (firstWrite) + { + Flush(); + } return; } WriteChunked(data); @@ -541,6 +548,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http else { HandleNonBodyResponseWrite(); + + if (firstWrite) + { + Flush(); + } } } @@ -581,14 +593,18 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http await ProduceStartAndFireOnStarting(); + // WriteAsyncAwaited is only called for the first write to the body. + // Ensure headers are flushed if Write(Chunked)Async isn't called. if (_canHaveBody) { if (_autoChunk) { if (data.Count == 0) { + await FlushAsync(cancellationToken); return; } + await WriteChunkedAsync(data, cancellationToken); } else @@ -599,7 +615,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http else { HandleNonBodyResponseWrite(); - return; + await FlushAsync(cancellationToken); } } diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs index 5b4b5b73fe..dbf6f5bdd4 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs @@ -7,6 +7,7 @@ using System.Net; using System.Net.Http; using System.Net.Sockets; using System.Text; +using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; @@ -767,11 +768,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { using (var connection = server.CreateConnection()) { - await connection.SendEnd( + await connection.Send( "HEAD / HTTP/1.1", "", ""); - await connection.ReceiveEnd( + await connection.Receive( "HTTP/1.1 200 OK", $"Date: {server.Context.DateHeaderValue}", "Content-Length: 42", @@ -782,26 +783,95 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } [Fact] - public async Task HeadResponseCanContainContentLengthHeaderButBodyNotWritten() + public async Task HeadResponseBodyNotWrittenWithAsyncWrite() { + var flushed = new SemaphoreSlim(0, 1); + using (var server = new TestServer(async httpContext => { httpContext.Response.ContentLength = 12; await httpContext.Response.WriteAsync("hello, world"); + await flushed.WaitAsync(); + }, new TestServiceContext())) + { + using (var connection = server.CreateConnection()) + { + await connection.Send( + "HEAD / HTTP/1.1", + "", + ""); + await connection.Receive( + "HTTP/1.1 200 OK", + $"Date: {server.Context.DateHeaderValue}", + "Content-Length: 12", + "", + ""); + + flushed.Release(); + } + } + } + + [Fact] + public async Task HeadResponseBodyNotWrittenWithSyncWrite() + { + var flushed = new SemaphoreSlim(0, 1); + + using (var server = new TestServer(httpContext => + { + httpContext.Response.ContentLength = 12; + httpContext.Response.Body.Write(Encoding.ASCII.GetBytes("hello, world"), 0, 12); + flushed.Wait(); + return TaskCache.CompletedTask; + }, new TestServiceContext())) + { + using (var connection = server.CreateConnection()) + { + await connection.Send( + "HEAD / HTTP/1.1", + "", + ""); + await connection.Receive( + "HTTP/1.1 200 OK", + $"Date: {server.Context.DateHeaderValue}", + "Content-Length: 12", + "", + ""); + + flushed.Release(); + } + } + } + + [Fact] + public async Task ZeroLengthWritesFlushHeaders() + { + var flushed = new SemaphoreSlim(0, 1); + + using (var server = new TestServer(async httpContext => + { + httpContext.Response.ContentLength = 12; + await httpContext.Response.WriteAsync(""); + flushed.Wait(); + await httpContext.Response.WriteAsync("hello, world"); }, new TestServiceContext())) { using (var connection = server.CreateConnection()) { await connection.SendEnd( - "HEAD / HTTP/1.1", + "GET / HTTP/1.1", "", ""); - await connection.ReceiveEnd( + await connection.Receive( "HTTP/1.1 200 OK", $"Date: {server.Context.DateHeaderValue}", "Content-Length: 12", "", ""); + + flushed.Release(); + + await connection.ReceiveEnd("hello, world"); } } } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedResponseTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedResponseTests.cs index 469f17051c..7ce2297b00 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedResponseTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedResponseTests.cs @@ -192,6 +192,48 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } } + [Theory] + [MemberData(nameof(ConnectionFilterData))] + public async Task ZeroLengthWritesFlushHeaders(TestServiceContext testContext) + { + var flushed = new SemaphoreSlim(0, 1); + + using (var server = new TestServer(async httpContext => + { + var response = httpContext.Response; + await response.WriteAsync(""); + + await flushed.WaitAsync(); + + await response.WriteAsync("Hello World!"); + }, testContext)) + { + using (var connection = server.CreateConnection()) + { + await connection.SendEnd( + "GET / HTTP/1.1", + "", + ""); + + await connection.Receive( + "HTTP/1.1 200 OK", + $"Date: {testContext.DateHeaderValue}", + "Transfer-Encoding: chunked", + "", + ""); + + flushed.Release(); + + await connection.ReceiveEnd( + "c", + "Hello World!", + "0", + "", + ""); + } + } + } + [Theory] [MemberData(nameof(ConnectionFilterData))] public async Task EmptyResponseBodyHandledCorrectlyWithZeroLengthWrite(TestServiceContext testContext) From 3c7e7d1f6cfb3d3d19cc0e956f621673c68f899e Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Tue, 8 Nov 2016 23:38:58 -0800 Subject: [PATCH 0953/1662] Make ConnectionFilterTests more reliable --- .../ConnectionFilterTests.cs | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionFilterTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionFilterTests.cs index ea76646561..6ef4b9de24 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionFilterTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionFilterTests.cs @@ -89,11 +89,19 @@ namespace Microsoft.AspNetCore.Server.KestrelTests using (var connection = server.CreateConnection()) { // Will throw because the exception in the connection filter will close the connection. - await Assert.ThrowsAsync(async () => await connection.SendEnd( - "POST / HTTP/1.0", - "Content-Length: 12", - "", - "Hello World?")); + await Assert.ThrowsAsync(async () => + { + await connection.Send( + "POST / HTTP/1.0", + "Content-Length: 1000", + "\r\n"); + + for (var i = 0; i < 1000; i++) + { + await connection.Send("a"); + await Task.Delay(5); + } + }); } } } From 757952d4d374a832dcd823760aa3a751ec46812b Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Mon, 7 Nov 2016 15:55:46 -0800 Subject: [PATCH 0954/1662] Always flush headers on first response write (#1202). --- .../Internal/Http/Frame.cs | 18 ++++- .../ResponseTests.cs | 80 +++++++++++++++++-- .../ChunkedResponseTests.cs | 42 ++++++++++ 3 files changed, 134 insertions(+), 6 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs index 725e284bc6..307ce7bc49 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs @@ -520,6 +520,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http public void Write(ArraySegment data) { + // For the first write, ensure headers are flushed if Write(Chunked)isn't called. + var firstWrite = !HasResponseStarted; + VerifyAndUpdateWrite(data.Count); ProduceStartAndFireOnStarting().GetAwaiter().GetResult(); @@ -529,6 +532,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { if (data.Count == 0) { + if (firstWrite) + { + Flush(); + } return; } WriteChunked(data); @@ -541,6 +548,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http else { HandleNonBodyResponseWrite(); + + if (firstWrite) + { + Flush(); + } } } @@ -581,14 +593,18 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http await ProduceStartAndFireOnStarting(); + // WriteAsyncAwaited is only called for the first write to the body. + // Ensure headers are flushed if Write(Chunked)Async isn't called. if (_canHaveBody) { if (_autoChunk) { if (data.Count == 0) { + await FlushAsync(cancellationToken); return; } + await WriteChunkedAsync(data, cancellationToken); } else @@ -599,7 +615,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http else { HandleNonBodyResponseWrite(); - return; + await FlushAsync(cancellationToken); } } diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs index 5b4b5b73fe..dbf6f5bdd4 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs @@ -7,6 +7,7 @@ using System.Net; using System.Net.Http; using System.Net.Sockets; using System.Text; +using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; @@ -767,11 +768,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { using (var connection = server.CreateConnection()) { - await connection.SendEnd( + await connection.Send( "HEAD / HTTP/1.1", "", ""); - await connection.ReceiveEnd( + await connection.Receive( "HTTP/1.1 200 OK", $"Date: {server.Context.DateHeaderValue}", "Content-Length: 42", @@ -782,26 +783,95 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } [Fact] - public async Task HeadResponseCanContainContentLengthHeaderButBodyNotWritten() + public async Task HeadResponseBodyNotWrittenWithAsyncWrite() { + var flushed = new SemaphoreSlim(0, 1); + using (var server = new TestServer(async httpContext => { httpContext.Response.ContentLength = 12; await httpContext.Response.WriteAsync("hello, world"); + await flushed.WaitAsync(); + }, new TestServiceContext())) + { + using (var connection = server.CreateConnection()) + { + await connection.Send( + "HEAD / HTTP/1.1", + "", + ""); + await connection.Receive( + "HTTP/1.1 200 OK", + $"Date: {server.Context.DateHeaderValue}", + "Content-Length: 12", + "", + ""); + + flushed.Release(); + } + } + } + + [Fact] + public async Task HeadResponseBodyNotWrittenWithSyncWrite() + { + var flushed = new SemaphoreSlim(0, 1); + + using (var server = new TestServer(httpContext => + { + httpContext.Response.ContentLength = 12; + httpContext.Response.Body.Write(Encoding.ASCII.GetBytes("hello, world"), 0, 12); + flushed.Wait(); + return TaskCache.CompletedTask; + }, new TestServiceContext())) + { + using (var connection = server.CreateConnection()) + { + await connection.Send( + "HEAD / HTTP/1.1", + "", + ""); + await connection.Receive( + "HTTP/1.1 200 OK", + $"Date: {server.Context.DateHeaderValue}", + "Content-Length: 12", + "", + ""); + + flushed.Release(); + } + } + } + + [Fact] + public async Task ZeroLengthWritesFlushHeaders() + { + var flushed = new SemaphoreSlim(0, 1); + + using (var server = new TestServer(async httpContext => + { + httpContext.Response.ContentLength = 12; + await httpContext.Response.WriteAsync(""); + flushed.Wait(); + await httpContext.Response.WriteAsync("hello, world"); }, new TestServiceContext())) { using (var connection = server.CreateConnection()) { await connection.SendEnd( - "HEAD / HTTP/1.1", + "GET / HTTP/1.1", "", ""); - await connection.ReceiveEnd( + await connection.Receive( "HTTP/1.1 200 OK", $"Date: {server.Context.DateHeaderValue}", "Content-Length: 12", "", ""); + + flushed.Release(); + + await connection.ReceiveEnd("hello, world"); } } } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedResponseTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedResponseTests.cs index 469f17051c..7ce2297b00 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedResponseTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedResponseTests.cs @@ -192,6 +192,48 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } } + [Theory] + [MemberData(nameof(ConnectionFilterData))] + public async Task ZeroLengthWritesFlushHeaders(TestServiceContext testContext) + { + var flushed = new SemaphoreSlim(0, 1); + + using (var server = new TestServer(async httpContext => + { + var response = httpContext.Response; + await response.WriteAsync(""); + + await flushed.WaitAsync(); + + await response.WriteAsync("Hello World!"); + }, testContext)) + { + using (var connection = server.CreateConnection()) + { + await connection.SendEnd( + "GET / HTTP/1.1", + "", + ""); + + await connection.Receive( + "HTTP/1.1 200 OK", + $"Date: {testContext.DateHeaderValue}", + "Transfer-Encoding: chunked", + "", + ""); + + flushed.Release(); + + await connection.ReceiveEnd( + "c", + "Hello World!", + "0", + "", + ""); + } + } + } + [Theory] [MemberData(nameof(ConnectionFilterData))] public async Task EmptyResponseBodyHandledCorrectlyWithZeroLengthWrite(TestServiceContext testContext) From 5043f9b17a170dd176211a74bf826240590b7bac Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Tue, 8 Nov 2016 23:38:58 -0800 Subject: [PATCH 0955/1662] Make ConnectionFilterTests more reliable --- .../ConnectionFilterTests.cs | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionFilterTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionFilterTests.cs index ea76646561..6ef4b9de24 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionFilterTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionFilterTests.cs @@ -89,11 +89,19 @@ namespace Microsoft.AspNetCore.Server.KestrelTests using (var connection = server.CreateConnection()) { // Will throw because the exception in the connection filter will close the connection. - await Assert.ThrowsAsync(async () => await connection.SendEnd( - "POST / HTTP/1.0", - "Content-Length: 12", - "", - "Hello World?")); + await Assert.ThrowsAsync(async () => + { + await connection.Send( + "POST / HTTP/1.0", + "Content-Length: 1000", + "\r\n"); + + for (var i = 0; i < 1000; i++) + { + await connection.Send("a"); + await Task.Delay(5); + } + }); } } } From 9d081d17e5aaa36b214bbeb87a0077b893e5b4a0 Mon Sep 17 00:00:00 2001 From: Pranav K Date: Wed, 9 Nov 2016 14:18:16 -0800 Subject: [PATCH 0956/1662] Updating versions to 1.2.0-* --- samples/LargeResponseApp/project.json | 2 +- samples/SampleApp/project.json | 6 +++--- .../project.json | 8 +++++--- src/Microsoft.AspNetCore.Server.Kestrel/project.json | 8 ++++---- .../project.json | 10 +++++----- .../project.json | 6 +++--- .../project.json | 4 ++-- 7 files changed, 23 insertions(+), 21 deletions(-) diff --git a/samples/LargeResponseApp/project.json b/samples/LargeResponseApp/project.json index d2305ee97e..7ed65ab333 100644 --- a/samples/LargeResponseApp/project.json +++ b/samples/LargeResponseApp/project.json @@ -1,7 +1,7 @@ { "version": "1.1.0-*", "dependencies": { - "Microsoft.AspNetCore.Server.Kestrel": "1.1.0-*" + "Microsoft.AspNetCore.Server.Kestrel": "1.2.0-*" }, "buildOptions": { "emitEntryPoint": true diff --git a/samples/SampleApp/project.json b/samples/SampleApp/project.json index c3314ee4f9..82eacdcb88 100644 --- a/samples/SampleApp/project.json +++ b/samples/SampleApp/project.json @@ -1,9 +1,9 @@ { "version": "1.1.0-*", "dependencies": { - "Microsoft.AspNetCore.Server.Kestrel": "1.1.0-*", - "Microsoft.AspNetCore.Server.Kestrel.Https": "1.1.0-*", - "Microsoft.Extensions.Logging.Console": "1.1.0-*" + "Microsoft.AspNetCore.Server.Kestrel": "1.2.0-*", + "Microsoft.AspNetCore.Server.Kestrel.Https": "1.2.0-*", + "Microsoft.Extensions.Logging.Console": "1.2.0-*" }, "buildOptions": { "emitEntryPoint": true diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Https/project.json b/src/Microsoft.AspNetCore.Server.Kestrel.Https/project.json index 5c23958fbd..7b97256dcd 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Https/project.json +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Https/project.json @@ -1,5 +1,5 @@ { - "version": "1.1.0-*", + "version": "1.2.0-*", "description": "HTTPS support for the ASP.NET Core Kestrel cross-platform web server.", "buildOptions": { "keyFile": "../../tools/Key.snk", @@ -20,9 +20,11 @@ ] }, "dependencies": { - "Microsoft.AspNetCore.Server.Kestrel": "1.1.0-*", + "Microsoft.AspNetCore.Server.Kestrel": { + "target": "project" + }, "Microsoft.Extensions.TaskCache.Sources": { - "version": "1.1.0-*", + "version": "1.2.0-*", "type": "build" }, "NETStandard.Library": "1.6.1-*" diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/project.json b/src/Microsoft.AspNetCore.Server.Kestrel/project.json index 4db40355f9..fc3b894d2b 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/project.json +++ b/src/Microsoft.AspNetCore.Server.Kestrel/project.json @@ -1,5 +1,5 @@ { - "version": "1.1.0-*", + "version": "1.2.0-*", "description": "ASP.NET Core Kestrel cross-platform web server.", "packOptions": { "repository": { @@ -13,10 +13,10 @@ }, "dependencies": { "Libuv": "1.9.1", - "Microsoft.AspNetCore.Hosting": "1.1.0-*", - "Microsoft.Extensions.Logging.Abstractions": "1.1.0-*", + "Microsoft.AspNetCore.Hosting": "1.2.0-*", + "Microsoft.Extensions.Logging.Abstractions": "1.2.0-*", "Microsoft.Extensions.TaskCache.Sources": { - "version": "1.1.0-*", + "version": "1.2.0-*", "type": "build" }, "NETStandard.Library": "1.6.1-*", diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json index 9444a422fd..cb8f653a45 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json @@ -2,11 +2,11 @@ "version": "1.1.0-*", "dependencies": { "dotnet-test-xunit": "2.2.0-*", - "Microsoft.AspNetCore.Http.Abstractions": "1.1.0-*", - "Microsoft.AspNetCore.Server.Kestrel": "1.1.0-*", - "Microsoft.AspNetCore.Server.Kestrel.Https": "1.1.0-*", - "Microsoft.AspNetCore.Testing": "1.1.0-*", - "Microsoft.Extensions.Logging.Testing": "1.1.0-*", + "Microsoft.AspNetCore.Http.Abstractions": "1.2.0-*", + "Microsoft.AspNetCore.Server.Kestrel": "1.2.0-*", + "Microsoft.AspNetCore.Server.Kestrel.Https": "1.2.0-*", + "Microsoft.AspNetCore.Testing": "1.2.0-*", + "Microsoft.Extensions.Logging.Testing": "1.2.0-*", "Moq": "4.6.36-*", "Newtonsoft.Json": "9.0.1", "xunit": "2.2.0-*", diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/project.json b/test/Microsoft.AspNetCore.Server.KestrelTests/project.json index 54537f5e83..56a54d3f76 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/project.json +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/project.json @@ -2,9 +2,9 @@ "version": "1.1.0-*", "dependencies": { "dotnet-test-xunit": "2.2.0-*", - "Microsoft.AspNetCore.Server.Kestrel": "1.1.0-*", - "Microsoft.AspNetCore.Server.Kestrel.Https": "1.1.0-*", - "Microsoft.AspNetCore.Testing": "1.1.0-*", + "Microsoft.AspNetCore.Server.Kestrel": "1.2.0-*", + "Microsoft.AspNetCore.Server.Kestrel.Https": "1.2.0-*", + "Microsoft.AspNetCore.Testing": "1.2.0-*", "Moq": "4.6.36-*", "xunit": "2.2.0-*", "Microsoft.CodeCoverage": { diff --git a/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/project.json b/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/project.json index f22ca3b7d6..636be2bff9 100644 --- a/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/project.json +++ b/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/project.json @@ -4,8 +4,8 @@ "emitEntryPoint": true }, "dependencies": { - "Microsoft.AspNetCore.Hosting": "1.1.0-*", - "Microsoft.AspNetCore.Http.Features": "1.1.0-*" + "Microsoft.AspNetCore.Hosting": "1.2.0-*", + "Microsoft.AspNetCore.Http.Features": "1.2.0-*" }, "frameworks": { "netcoreapp1.1": { From e780ad95162f48cf263165fdfc4d0ca26a942c1e Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Tue, 8 Nov 2016 17:07:23 -0800 Subject: [PATCH 0957/1662] Ensure clients connecting to Kestrel's dispatch pipe are listeners --- .../Internal/Http/ListenerPrimary.cs | 61 ++++++++++++++++++- .../Internal/Http/ListenerSecondary.cs | 25 +++++++- .../Internal/Infrastructure/Constants.cs | 3 + .../Internal/Networking/UvWriteReq.cs | 38 +++++++++--- 4 files changed, 114 insertions(+), 13 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ListenerPrimary.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ListenerPrimary.cs index 9e40e6b549..d20ea8dd81 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ListenerPrimary.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ListenerPrimary.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; +using System.IO; using System.Runtime.InteropServices; using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; @@ -75,15 +76,19 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { dispatchPipe.Init(Thread.Loop, Thread.QueueCloseHandle, true); pipe.Accept(dispatchPipe); + + // Ensure client sends "Kestrel" before adding pipe to _dispatchPipes. + var readContext = new PipeReadContext(this); + dispatchPipe.ReadStart( + (handle, status2, state) => ((PipeReadContext)state).AllocCallback(handle, status2), + (handle, status2, state) => ((PipeReadContext)state).ReadCallback(handle, status2), + readContext); } catch (UvException ex) { dispatchPipe.Dispose(); Log.LogError(0, ex, "ListenerPrimary.OnListenPipe"); - return; } - - _dispatchPipes.Add(dispatchPipe); } protected override void DispatchConnection(UvStreamHandle socket) @@ -179,5 +184,55 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http }, this).ConfigureAwait(false); } } + + private class PipeReadContext + { + private readonly ListenerPrimary _listener; + private readonly IntPtr _bufPtr; + private GCHandle _bufHandle; + private int _bytesRead; + + public PipeReadContext(ListenerPrimary listener) + { + _listener = listener; + _bufHandle = GCHandle.Alloc(new byte[8], GCHandleType.Pinned); + _bufPtr = _bufHandle.AddrOfPinnedObject(); + } + + public Libuv.uv_buf_t AllocCallback(UvStreamHandle dispatchPipe, int suggestedSize) + { + return dispatchPipe.Libuv.buf_init(_bufPtr + _bytesRead, 8 - _bytesRead); + } + + public unsafe void ReadCallback(UvStreamHandle dispatchPipe, int status) + { + try + { + dispatchPipe.Libuv.ThrowIfErrored(status); + + _bytesRead += status; + + if (_bytesRead == 8) + { + if (*(ulong*)_bufPtr == Constants.PipeMessage) + { + _listener._dispatchPipes.Add((UvPipeHandle) dispatchPipe); + dispatchPipe.ReadStop(); + _bufHandle.Free(); + } + else + { + throw new IOException("Bad data sent over Kestrel pipe."); + } + } + } + catch (Exception ex) + { + dispatchPipe.Dispose(); + _bufHandle.Free(); + _listener.Log.LogError(0, ex, "ListenerPrimary.ReadCallback"); + } + } + } } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ListenerSecondary.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ListenerSecondary.cs index 3fd1db29be..9220aa4ddc 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ListenerSecondary.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ListenerSecondary.cs @@ -17,6 +17,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http /// public abstract class ListenerSecondary : ListenerContext, IAsyncDisposable { + private static ArraySegment> _pipeMessage = + new ArraySegment>(new[] { new ArraySegment(BitConverter.GetBytes(Constants.PipeMessage)) }); + private string _pipeName; private IntPtr _ptr; private Libuv.uv_buf_t _buf; @@ -89,6 +92,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http return; } + var writeReq = new UvWriteReq(Log); + try { DispatchPipe.ReadStart( @@ -96,10 +101,28 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http (handle, status2, state) => ((ListenerSecondary)state).ReadStartCallback(handle, status2), this); - tcs.SetResult(0); + writeReq.Init(Thread.Loop); + writeReq.Write( + DispatchPipe, + _pipeMessage, + (req, status2, ex, state) => + { + req.Dispose(); + + if (ex != null) + { + tcs.SetException(ex); + } + else + { + tcs.SetResult(0); + } + }, + tcs); } catch (Exception ex) { + writeReq.Dispose(); DispatchPipe.Dispose(); tcs.SetException(ex); } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/Constants.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/Constants.cs index 77968bca17..9c9fbf73a7 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/Constants.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/Constants.cs @@ -20,6 +20,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure public const string ServerName = "Kestrel"; + // "Kestrel\0" + public const ulong PipeMessage = 0x006C65727473654B; + private static int? GetECONNRESET() { if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/UvWriteReq.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/UvWriteReq.cs index 4a0aec28bc..93a06519a0 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/UvWriteReq.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/UvWriteReq.cs @@ -85,18 +85,30 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking _callback = null; _state = null; Unpin(this); - - var block = start.Block; - for (var index = 0; index < nBuffers; index++) - { - block = block.Next; - } - throw; } } - public unsafe void Write2( + public void Write( + UvStreamHandle handle, + ArraySegment> bufs, + Action callback, + object state) + { + WriteArraySegmentInternal(handle, bufs, sendHandle: null, callback: callback, state: state); + } + + public void Write2( + UvStreamHandle handle, + ArraySegment> bufs, + UvStreamHandle sendHandle, + Action callback, + object state) + { + WriteArraySegmentInternal(handle, bufs, sendHandle, callback, state); + } + + private unsafe void WriteArraySegmentInternal( UvStreamHandle handle, ArraySegment> bufs, UvStreamHandle sendHandle, @@ -133,7 +145,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking _callback = callback; _state = state; - _uv.write2(this, handle, pBuffers, nBuffers, sendHandle, _uv_write_cb); + + if (sendHandle == null) + { + _uv.write(this, handle, pBuffers, nBuffers, _uv_write_cb); + } + else + { + _uv.write2(this, handle, pBuffers, nBuffers, sendHandle, _uv_write_cb); + } } catch { From ec89197ecb7f86e13e40f34dbc6a1ad7f20acbae Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Tue, 8 Nov 2016 22:29:03 -0800 Subject: [PATCH 0958/1662] Add ListenerPrimaryTests --- .../ListenerPrimaryTests.cs | 229 ++++++++++++++++++ test/shared/TestKestrelTrace.cs | 9 +- 2 files changed, 236 insertions(+), 2 deletions(-) create mode 100644 test/Microsoft.AspNetCore.Server.KestrelTests/ListenerPrimaryTests.cs diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/ListenerPrimaryTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/ListenerPrimaryTests.cs new file mode 100644 index 0000000000..13be40ed2c --- /dev/null +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/ListenerPrimaryTests.cs @@ -0,0 +1,229 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Hosting.Server; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Http.Features; +using Microsoft.AspNetCore.Server.Kestrel; +using Microsoft.AspNetCore.Server.Kestrel.Internal; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; +using Microsoft.AspNetCore.Testing; +using Microsoft.Extensions.Logging; +using Xunit; + +namespace Microsoft.AspNetCore.Server.KestrelTests +{ + public class ListenerPrimaryTests + { + [Fact] + public async Task ConnectionsGetRoundRobinedToSecondaryListeners() + { + var libuv = new Libuv(); + + var serviceContextPrimary = new TestServiceContext + { + FrameFactory = context => + { + return new Frame(new TestApplication(c => + { + return c.Response.WriteAsync("Primary"); + }), context); + } + }; + + var serviceContextSecondary = new ServiceContext + { + Log = serviceContextPrimary.Log, + AppLifetime = serviceContextPrimary.AppLifetime, + DateHeaderValueManager = serviceContextPrimary.DateHeaderValueManager, + ServerOptions = serviceContextPrimary.ServerOptions, + ThreadPool = serviceContextPrimary.ThreadPool, + FrameFactory = context => + { + return new Frame(new TestApplication(c => + { + return c.Response.WriteAsync("Secondary"); ; + }), context); + } + }; + + using (var kestrelEngine = new KestrelEngine(libuv, serviceContextPrimary)) + { + var address = ServerAddress.FromUrl("http://127.0.0.1:0/"); + var pipeName = (libuv.IsWindows ? @"\\.\pipe\kestrel_" : "/tmp/kestrel_") + Guid.NewGuid().ToString("n"); + + // Start primary listener + var kestrelThreadPrimary = new KestrelThread(kestrelEngine); + await kestrelThreadPrimary.StartAsync(); + var listenerPrimary = new TcpListenerPrimary(serviceContextPrimary); + await listenerPrimary.StartAsync(pipeName, address, kestrelThreadPrimary); + + // Until a secondary listener is added, TCP connections get dispatched directly + Assert.Equal("Primary", await HttpClientSlim.GetStringAsync(address.ToString())); + Assert.Equal("Primary", await HttpClientSlim.GetStringAsync(address.ToString())); + + // Add secondary listener + var kestrelThreadSecondary = new KestrelThread(kestrelEngine); + await kestrelThreadSecondary.StartAsync(); + var listenerSecondary = new TcpListenerSecondary(serviceContextSecondary); + await listenerSecondary.StartAsync(pipeName, address, kestrelThreadSecondary); + + // Once a secondary listener is added, TCP connections start getting dispatched to it + Assert.Equal("Secondary", await HttpClientSlim.GetStringAsync(address.ToString())); + + // TCP connections will still get round-robined to the primary listener + Assert.Equal("Primary", await HttpClientSlim.GetStringAsync(address.ToString())); + Assert.Equal("Secondary", await HttpClientSlim.GetStringAsync(address.ToString())); + Assert.Equal("Primary", await HttpClientSlim.GetStringAsync(address.ToString())); + + await listenerSecondary.DisposeAsync(); + await kestrelThreadSecondary.StopAsync(TimeSpan.FromSeconds(1)); + + await listenerPrimary.DisposeAsync(); + await kestrelThreadPrimary.StopAsync(TimeSpan.FromSeconds(1)); + } + } + + // https://github.com/aspnet/KestrelHttpServer/issues/1182 + [Fact] + public async Task NonListenerPipeConnectionsAreLoggedAndIgnored() + { + var libuv = new Libuv(); + + var primaryTrace = new TestKestrelTrace(); + + var serviceContextPrimary = new TestServiceContext + { + Log = primaryTrace, + FrameFactory = context => + { + return new Frame(new TestApplication(c => + { + return c.Response.WriteAsync("Primary"); + }), context); + } + }; + + var serviceContextSecondary = new ServiceContext + { + Log = new TestKestrelTrace(), + AppLifetime = serviceContextPrimary.AppLifetime, + DateHeaderValueManager = serviceContextPrimary.DateHeaderValueManager, + ServerOptions = serviceContextPrimary.ServerOptions, + ThreadPool = serviceContextPrimary.ThreadPool, + FrameFactory = context => + { + return new Frame(new TestApplication(c => + { + return c.Response.WriteAsync("Secondary"); ; + }), context); + } + }; + + using (var kestrelEngine = new KestrelEngine(libuv, serviceContextPrimary)) + { + var address = ServerAddress.FromUrl("http://127.0.0.1:0/"); + var pipeName = (libuv.IsWindows ? @"\\.\pipe\kestrel_" : "/tmp/kestrel_") + Guid.NewGuid().ToString("n"); + + // Start primary listener + var kestrelThreadPrimary = new KestrelThread(kestrelEngine); + await kestrelThreadPrimary.StartAsync(); + var listenerPrimary = new TcpListenerPrimary(serviceContextPrimary); + await listenerPrimary.StartAsync(pipeName, address, kestrelThreadPrimary); + + // Add secondary listener + var kestrelThreadSecondary = new KestrelThread(kestrelEngine); + await kestrelThreadSecondary.StartAsync(); + var listenerSecondary = new TcpListenerSecondary(serviceContextSecondary); + await listenerSecondary.StartAsync(pipeName, address, kestrelThreadSecondary); + + // TCP Connections get round-robined + Assert.Equal("Secondary", await HttpClientSlim.GetStringAsync(address.ToString())); + Assert.Equal("Primary", await HttpClientSlim.GetStringAsync(address.ToString())); + + // Create a pipe connection and keep it open without sending any data + var connectTcs = new TaskCompletionSource(); + var connectionTrace = new TestKestrelTrace(); + var pipe = new UvPipeHandle(connectionTrace); + + kestrelThreadPrimary.Post(_ => + { + var connectReq = new UvConnectRequest(connectionTrace); + + pipe.Init(kestrelThreadPrimary.Loop, kestrelThreadPrimary.QueueCloseHandle); + connectReq.Init(kestrelThreadPrimary.Loop); + + connectReq.Connect( + pipe, + pipeName, + (req, status, ex, __) => + { + req.Dispose(); + + if (ex != null) + { + connectTcs.SetException(ex); + } + else + { + connectTcs.SetResult(null); + } + }, + null); + }, null); + + await connectTcs.Task; + + // TCP connections will still get round-robined between only the two listeners + Assert.Equal("Secondary", await HttpClientSlim.GetStringAsync(address.ToString())); + Assert.Equal("Primary", await HttpClientSlim.GetStringAsync(address.ToString())); + Assert.Equal("Secondary", await HttpClientSlim.GetStringAsync(address.ToString())); + + await kestrelThreadPrimary.PostAsync(_ => pipe.Dispose(), null); + + // Same for after the non-listener pipe connection is closed + Assert.Equal("Primary", await HttpClientSlim.GetStringAsync(address.ToString())); + Assert.Equal("Secondary", await HttpClientSlim.GetStringAsync(address.ToString())); + Assert.Equal("Primary", await HttpClientSlim.GetStringAsync(address.ToString())); + + await listenerSecondary.DisposeAsync(); + await kestrelThreadSecondary.StopAsync(TimeSpan.FromSeconds(1)); + + await listenerPrimary.DisposeAsync(); + await kestrelThreadPrimary.StopAsync(TimeSpan.FromSeconds(1)); + } + + Assert.Equal(1, primaryTrace.Logger.TotalErrorsLogged); + var errorMessage = primaryTrace.Logger.Messages.First(m => m.LogLevel == LogLevel.Error); + Assert.Contains("EOF", errorMessage.Exception.ToString()); + } + + private class TestApplication : IHttpApplication + { + private readonly Func _app; + + public TestApplication(Func app) + { + _app = app; + } + + public DefaultHttpContext CreateContext(IFeatureCollection contextFeatures) + { + return new DefaultHttpContext(contextFeatures); + } + + public Task ProcessRequestAsync(DefaultHttpContext context) + { + return _app(context); + } + + public void DisposeContext(DefaultHttpContext context, Exception exception) + { + } + } + } +} diff --git a/test/shared/TestKestrelTrace.cs b/test/shared/TestKestrelTrace.cs index 814005d4d1..f9879bda37 100644 --- a/test/shared/TestKestrelTrace.cs +++ b/test/shared/TestKestrelTrace.cs @@ -1,5 +1,7 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + using Microsoft.AspNetCore.Server.Kestrel.Internal; -using Microsoft.Extensions.Logging; namespace Microsoft.AspNetCore.Testing { @@ -9,10 +11,13 @@ namespace Microsoft.AspNetCore.Testing { } - public TestKestrelTrace(ILogger testLogger) : base(testLogger) + public TestKestrelTrace(TestApplicationErrorLogger testLogger) : base(testLogger) { + Logger = testLogger; } + public TestApplicationErrorLogger Logger { get; private set; } + public override void ConnectionRead(string connectionId, int count) { //_logger.LogDebug(1, @"Connection id ""{ConnectionId}"" recv {count} bytes.", connectionId, count); From f1d0fafaa48ec4e60719f21927d4634642862429 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Fri, 11 Nov 2016 14:51:37 -0800 Subject: [PATCH 0959/1662] Better filter clients connecting to Kestrel's dispatch pipes --- .../Internal/Http/ListenerPrimary.cs | 26 ++++-- .../Internal/Http/ListenerSecondary.cs | 8 +- .../Internal/Infrastructure/Constants.cs | 3 - .../Internal/KestrelEngine.cs | 5 +- .../ListenerPrimaryTests.cs | 86 +++++++++++++++++-- 5 files changed, 109 insertions(+), 19 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ListenerPrimary.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ListenerPrimary.cs index d20ea8dd81..4b192c505d 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ListenerPrimary.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ListenerPrimary.cs @@ -21,6 +21,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http private readonly List _dispatchPipes = new List(); private int _dispatchIndex; private string _pipeName; + private byte[] _pipeMessage; private IntPtr _fileCompletionInfoPtr; private bool _tryDetachFromIOCP = PlatformApis.IsWindows; @@ -36,10 +37,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http public async Task StartAsync( string pipeName, + byte[] pipeMessage, ServerAddress address, KestrelThread thread) { _pipeName = pipeName; + _pipeMessage = pipeMessage; if (_fileCompletionInfoPtr == IntPtr.Zero) { @@ -187,7 +190,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http private class PipeReadContext { + private const int _bufferLength = 16; + private readonly ListenerPrimary _listener; + private readonly byte[] _buf = new byte[_bufferLength]; private readonly IntPtr _bufPtr; private GCHandle _bufHandle; private int _bytesRead; @@ -195,16 +201,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http public PipeReadContext(ListenerPrimary listener) { _listener = listener; - _bufHandle = GCHandle.Alloc(new byte[8], GCHandleType.Pinned); + _bufHandle = GCHandle.Alloc(_buf, GCHandleType.Pinned); _bufPtr = _bufHandle.AddrOfPinnedObject(); } public Libuv.uv_buf_t AllocCallback(UvStreamHandle dispatchPipe, int suggestedSize) { - return dispatchPipe.Libuv.buf_init(_bufPtr + _bytesRead, 8 - _bytesRead); + return dispatchPipe.Libuv.buf_init(_bufPtr + _bytesRead, _bufferLength - _bytesRead); } - public unsafe void ReadCallback(UvStreamHandle dispatchPipe, int status) + public void ReadCallback(UvStreamHandle dispatchPipe, int status) { try { @@ -212,9 +218,19 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _bytesRead += status; - if (_bytesRead == 8) + if (_bytesRead == _bufferLength) { - if (*(ulong*)_bufPtr == Constants.PipeMessage) + var correctMessage = true; + + for (var i = 0; i < _bufferLength; i++) + { + if (_buf[i] != _listener._pipeMessage[i]) + { + correctMessage = false; + } + } + + if (correctMessage) { _listener._dispatchPipes.Add((UvPipeHandle) dispatchPipe); dispatchPipe.ReadStop(); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ListenerSecondary.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ListenerSecondary.cs index 9220aa4ddc..078f9c6e03 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ListenerSecondary.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ListenerSecondary.cs @@ -17,10 +17,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http /// public abstract class ListenerSecondary : ListenerContext, IAsyncDisposable { - private static ArraySegment> _pipeMessage = - new ArraySegment>(new[] { new ArraySegment(BitConverter.GetBytes(Constants.PipeMessage)) }); - private string _pipeName; + private byte[] _pipeMessage; private IntPtr _ptr; private Libuv.uv_buf_t _buf; private bool _closed; @@ -36,10 +34,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http public Task StartAsync( string pipeName, + byte[] pipeMessage, ServerAddress address, KestrelThread thread) { _pipeName = pipeName; + _pipeMessage = pipeMessage; _buf = thread.Loop.Libuv.buf_init(_ptr, 4); ServerAddress = address; @@ -104,7 +104,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http writeReq.Init(Thread.Loop); writeReq.Write( DispatchPipe, - _pipeMessage, + new ArraySegment>(new [] { new ArraySegment(_pipeMessage) }), (req, status2, ex, state) => { req.Dispose(); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/Constants.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/Constants.cs index 9c9fbf73a7..77968bca17 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/Constants.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/Constants.cs @@ -20,9 +20,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure public const string ServerName = "Kestrel"; - // "Kestrel\0" - public const ulong PipeMessage = 0x006C65727473654B; - private static int? GetECONNRESET() { if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/KestrelEngine.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/KestrelEngine.cs index 1f7c4c7a3c..3b3b46a4c9 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/KestrelEngine.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/KestrelEngine.cs @@ -70,6 +70,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal try { var pipeName = (Libuv.IsWindows ? @"\\.\pipe\kestrel_" : "/tmp/kestrel_") + Guid.NewGuid().ToString("n"); + var pipeMessage = Guid.NewGuid().ToByteArray(); var single = Threads.Count == 1; var first = true; @@ -91,7 +92,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal : new TcpListenerPrimary(ServiceContext); listeners.Add(listener); - listener.StartAsync(pipeName, address, thread).Wait(); + listener.StartAsync(pipeName, pipeMessage, address, thread).Wait(); } else { @@ -99,7 +100,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal ? (ListenerSecondary) new PipeListenerSecondary(ServiceContext) : new TcpListenerSecondary(ServiceContext); listeners.Add(listener); - listener.StartAsync(pipeName, address, thread).Wait(); + listener.StartAsync(pipeName, pipeMessage, address, thread).Wait(); } first = false; diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/ListenerPrimaryTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/ListenerPrimaryTests.cs index 13be40ed2c..94f57fc99d 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/ListenerPrimaryTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/ListenerPrimaryTests.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.IO; using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Hosting.Server; @@ -10,6 +11,7 @@ using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Server.Kestrel; using Microsoft.AspNetCore.Server.Kestrel.Internal; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; using Microsoft.AspNetCore.Testing; using Microsoft.Extensions.Logging; @@ -55,12 +57,13 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { var address = ServerAddress.FromUrl("http://127.0.0.1:0/"); var pipeName = (libuv.IsWindows ? @"\\.\pipe\kestrel_" : "/tmp/kestrel_") + Guid.NewGuid().ToString("n"); + var pipeMessage = Guid.NewGuid().ToByteArray(); // Start primary listener var kestrelThreadPrimary = new KestrelThread(kestrelEngine); await kestrelThreadPrimary.StartAsync(); var listenerPrimary = new TcpListenerPrimary(serviceContextPrimary); - await listenerPrimary.StartAsync(pipeName, address, kestrelThreadPrimary); + await listenerPrimary.StartAsync(pipeName, pipeMessage, address, kestrelThreadPrimary); // Until a secondary listener is added, TCP connections get dispatched directly Assert.Equal("Primary", await HttpClientSlim.GetStringAsync(address.ToString())); @@ -70,7 +73,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var kestrelThreadSecondary = new KestrelThread(kestrelEngine); await kestrelThreadSecondary.StartAsync(); var listenerSecondary = new TcpListenerSecondary(serviceContextSecondary); - await listenerSecondary.StartAsync(pipeName, address, kestrelThreadSecondary); + await listenerSecondary.StartAsync(pipeName, pipeMessage, address, kestrelThreadSecondary); // Once a secondary listener is added, TCP connections start getting dispatched to it Assert.Equal("Secondary", await HttpClientSlim.GetStringAsync(address.ToString())); @@ -128,18 +131,19 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { var address = ServerAddress.FromUrl("http://127.0.0.1:0/"); var pipeName = (libuv.IsWindows ? @"\\.\pipe\kestrel_" : "/tmp/kestrel_") + Guid.NewGuid().ToString("n"); + var pipeMessage = Guid.NewGuid().ToByteArray(); // Start primary listener var kestrelThreadPrimary = new KestrelThread(kestrelEngine); await kestrelThreadPrimary.StartAsync(); var listenerPrimary = new TcpListenerPrimary(serviceContextPrimary); - await listenerPrimary.StartAsync(pipeName, address, kestrelThreadPrimary); + await listenerPrimary.StartAsync(pipeName, pipeMessage, address, kestrelThreadPrimary); // Add secondary listener var kestrelThreadSecondary = new KestrelThread(kestrelEngine); await kestrelThreadSecondary.StartAsync(); var listenerSecondary = new TcpListenerSecondary(serviceContextSecondary); - await listenerSecondary.StartAsync(pipeName, address, kestrelThreadSecondary); + await listenerSecondary.StartAsync(pipeName, pipeMessage, address, kestrelThreadSecondary); // TCP Connections get round-robined Assert.Equal("Secondary", await HttpClientSlim.GetStringAsync(address.ToString())); @@ -199,7 +203,79 @@ namespace Microsoft.AspNetCore.Server.KestrelTests Assert.Equal(1, primaryTrace.Logger.TotalErrorsLogged); var errorMessage = primaryTrace.Logger.Messages.First(m => m.LogLevel == LogLevel.Error); - Assert.Contains("EOF", errorMessage.Exception.ToString()); + Assert.Equal(Constants.EOF, Assert.IsType(errorMessage.Exception).StatusCode); + } + + + [Fact] + public async Task PipeConnectionsWithWrongMessageAreLoggedAndIgnored() + { + var libuv = new Libuv(); + + var primaryTrace = new TestKestrelTrace(); + + var serviceContextPrimary = new TestServiceContext + { + Log = primaryTrace, + FrameFactory = context => + { + return new Frame(new TestApplication(c => + { + return c.Response.WriteAsync("Primary"); + }), context); + } + }; + + var serviceContextSecondary = new ServiceContext + { + Log = new TestKestrelTrace(), + AppLifetime = serviceContextPrimary.AppLifetime, + DateHeaderValueManager = serviceContextPrimary.DateHeaderValueManager, + ServerOptions = serviceContextPrimary.ServerOptions, + ThreadPool = serviceContextPrimary.ThreadPool, + FrameFactory = context => + { + return new Frame(new TestApplication(c => + { + return c.Response.WriteAsync("Secondary"); ; + }), context); + } + }; + + using (var kestrelEngine = new KestrelEngine(libuv, serviceContextPrimary)) + { + var address = ServerAddress.FromUrl("http://127.0.0.1:0/"); + var pipeName = (libuv.IsWindows ? @"\\.\pipe\kestrel_" : "/tmp/kestrel_") + Guid.NewGuid().ToString("n"); + var pipeMessage = Guid.NewGuid().ToByteArray(); + + // Start primary listener + var kestrelThreadPrimary = new KestrelThread(kestrelEngine); + await kestrelThreadPrimary.StartAsync(); + var listenerPrimary = new TcpListenerPrimary(serviceContextPrimary); + await listenerPrimary.StartAsync(pipeName, pipeMessage, address, kestrelThreadPrimary); + + // Add secondary listener with wrong pipe message + var kestrelThreadSecondary = new KestrelThread(kestrelEngine); + await kestrelThreadSecondary.StartAsync(); + var listenerSecondary = new TcpListenerSecondary(serviceContextSecondary); + await listenerSecondary.StartAsync(pipeName, Guid.NewGuid().ToByteArray(), address, kestrelThreadSecondary); + + // TCP Connections get round-robined + Assert.Equal("Primary", await HttpClientSlim.GetStringAsync(address.ToString())); + Assert.Equal("Primary", await HttpClientSlim.GetStringAsync(address.ToString())); + Assert.Equal("Primary", await HttpClientSlim.GetStringAsync(address.ToString())); + + await listenerSecondary.DisposeAsync(); + await kestrelThreadSecondary.StopAsync(TimeSpan.FromSeconds(1)); + + await listenerPrimary.DisposeAsync(); + await kestrelThreadPrimary.StopAsync(TimeSpan.FromSeconds(1)); + } + + Assert.Equal(1, primaryTrace.Logger.TotalErrorsLogged); + var errorMessage = primaryTrace.Logger.Messages.First(m => m.LogLevel == LogLevel.Error); + Assert.IsType(errorMessage.Exception); + Assert.Contains("Bad data", errorMessage.Exception.ToString()); } private class TestApplication : IHttpApplication From eee9520ffdfb01f4c8a9d061e1ff41184910fb0c Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Tue, 8 Nov 2016 17:07:23 -0800 Subject: [PATCH 0960/1662] Ensure clients connecting to Kestrel's dispatch pipe are listeners --- .../Internal/Http/ListenerPrimary.cs | 61 ++++++++++++++++++- .../Internal/Http/ListenerSecondary.cs | 25 +++++++- .../Internal/Infrastructure/Constants.cs | 3 + .../Internal/Networking/UvWriteReq.cs | 38 +++++++++--- 4 files changed, 114 insertions(+), 13 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ListenerPrimary.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ListenerPrimary.cs index a9b938d158..1bfc4c0ad0 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ListenerPrimary.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ListenerPrimary.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; +using System.IO; using System.Runtime.InteropServices; using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; @@ -75,15 +76,19 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http try { pipe.Accept(dispatchPipe); + + // Ensure client sends "Kestrel" before adding pipe to _dispatchPipes. + var readContext = new PipeReadContext(this); + dispatchPipe.ReadStart( + (handle, status2, state) => ((PipeReadContext)state).AllocCallback(handle, status2), + (handle, status2, state) => ((PipeReadContext)state).ReadCallback(handle, status2), + readContext); } catch (UvException ex) { dispatchPipe.Dispose(); Log.LogError(0, ex, "ListenerPrimary.OnListenPipe"); - return; } - - _dispatchPipes.Add(dispatchPipe); } protected override void DispatchConnection(UvStreamHandle socket) @@ -179,5 +184,55 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http }, this).ConfigureAwait(false); } } + + private class PipeReadContext + { + private readonly ListenerPrimary _listener; + private readonly IntPtr _bufPtr; + private GCHandle _bufHandle; + private int _bytesRead; + + public PipeReadContext(ListenerPrimary listener) + { + _listener = listener; + _bufHandle = GCHandle.Alloc(new byte[8], GCHandleType.Pinned); + _bufPtr = _bufHandle.AddrOfPinnedObject(); + } + + public Libuv.uv_buf_t AllocCallback(UvStreamHandle dispatchPipe, int suggestedSize) + { + return dispatchPipe.Libuv.buf_init(_bufPtr + _bytesRead, 8 - _bytesRead); + } + + public unsafe void ReadCallback(UvStreamHandle dispatchPipe, int status) + { + try + { + dispatchPipe.Libuv.Check(status); + + _bytesRead += status; + + if (_bytesRead == 8) + { + if (*(ulong*)_bufPtr == Constants.PipeMessage) + { + _listener._dispatchPipes.Add((UvPipeHandle) dispatchPipe); + dispatchPipe.ReadStop(); + _bufHandle.Free(); + } + else + { + throw new IOException("Bad data sent over Kestrel pipe."); + } + } + } + catch (Exception ex) + { + dispatchPipe.Dispose(); + _bufHandle.Free(); + _listener.Log.LogError(0, ex, "ListenerPrimary.ReadCallback"); + } + } + } } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ListenerSecondary.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ListenerSecondary.cs index e11729200f..bd4d384fb2 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ListenerSecondary.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ListenerSecondary.cs @@ -17,6 +17,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http /// public abstract class ListenerSecondary : ListenerContext, IAsyncDisposable { + private static ArraySegment> _pipeMessage = + new ArraySegment>(new[] { new ArraySegment(BitConverter.GetBytes(Constants.PipeMessage)) }); + private string _pipeName; private IntPtr _ptr; private Libuv.uv_buf_t _buf; @@ -89,6 +92,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http return; } + var writeReq = new UvWriteReq(Log); + try { DispatchPipe.ReadStart( @@ -96,10 +101,28 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http (handle, status2, state) => ((ListenerSecondary)state).ReadStartCallback(handle, status2), this); - tcs.SetResult(0); + writeReq.Init(Thread.Loop); + writeReq.Write( + DispatchPipe, + _pipeMessage, + (req, status2, ex, state) => + { + req.Dispose(); + + if (ex != null) + { + tcs.SetException(ex); + } + else + { + tcs.SetResult(0); + } + }, + tcs); } catch (Exception ex) { + writeReq.Dispose(); DispatchPipe.Dispose(); tcs.SetException(ex); } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/Constants.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/Constants.cs index 2d270d9955..47b04be220 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/Constants.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/Constants.cs @@ -26,6 +26,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure public const string ServerName = "Kestrel"; + // "Kestrel\0" + public const ulong PipeMessage = 0x006C65727473654B; + private static int? GetECONNRESET() { if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/UvWriteReq.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/UvWriteReq.cs index 4a0aec28bc..93a06519a0 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/UvWriteReq.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/UvWriteReq.cs @@ -85,18 +85,30 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking _callback = null; _state = null; Unpin(this); - - var block = start.Block; - for (var index = 0; index < nBuffers; index++) - { - block = block.Next; - } - throw; } } - public unsafe void Write2( + public void Write( + UvStreamHandle handle, + ArraySegment> bufs, + Action callback, + object state) + { + WriteArraySegmentInternal(handle, bufs, sendHandle: null, callback: callback, state: state); + } + + public void Write2( + UvStreamHandle handle, + ArraySegment> bufs, + UvStreamHandle sendHandle, + Action callback, + object state) + { + WriteArraySegmentInternal(handle, bufs, sendHandle, callback, state); + } + + private unsafe void WriteArraySegmentInternal( UvStreamHandle handle, ArraySegment> bufs, UvStreamHandle sendHandle, @@ -133,7 +145,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking _callback = callback; _state = state; - _uv.write2(this, handle, pBuffers, nBuffers, sendHandle, _uv_write_cb); + + if (sendHandle == null) + { + _uv.write(this, handle, pBuffers, nBuffers, _uv_write_cb); + } + else + { + _uv.write2(this, handle, pBuffers, nBuffers, sendHandle, _uv_write_cb); + } } catch { From ecc8a0088d79e087867b463e5897d8e11868b814 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Tue, 8 Nov 2016 22:29:03 -0800 Subject: [PATCH 0961/1662] Add ListenerPrimaryTests --- .../ListenerPrimaryTests.cs | 229 ++++++++++++++++++ .../TestHelpers/HttpClientSlim.cs | 129 ++++++++++ .../TestHelpers/TestApplicationErrorLogger.cs | 26 +- .../TestHelpers/TestKestrelTrace.cs | 9 +- 4 files changed, 380 insertions(+), 13 deletions(-) create mode 100644 test/Microsoft.AspNetCore.Server.KestrelTests/ListenerPrimaryTests.cs create mode 100644 test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/HttpClientSlim.cs diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/ListenerPrimaryTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/ListenerPrimaryTests.cs new file mode 100644 index 0000000000..471aa42b43 --- /dev/null +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/ListenerPrimaryTests.cs @@ -0,0 +1,229 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Hosting.Server; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Http.Features; +using Microsoft.AspNetCore.Server.Kestrel; +using Microsoft.AspNetCore.Server.Kestrel.Internal; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; +using Microsoft.AspNetCore.Testing; +using Microsoft.Extensions.Logging; +using Xunit; + +namespace Microsoft.AspNetCore.Server.KestrelTests +{ + public class ListenerPrimaryTests + { + [Fact] + public async Task ConnectionsGetRoundRobinedToSecondaryListeners() + { + var libuv = new Libuv(); + + var serviceContextPrimary = new TestServiceContext + { + FrameFactory = context => + { + return new Frame(new TestApplication(c => + { + return c.Response.WriteAsync("Primary"); + }), context); + } + }; + + var serviceContextSecondary = new ServiceContext + { + Log = serviceContextPrimary.Log, + AppLifetime = serviceContextPrimary.AppLifetime, + DateHeaderValueManager = serviceContextPrimary.DateHeaderValueManager, + ServerOptions = serviceContextPrimary.ServerOptions, + ThreadPool = serviceContextPrimary.ThreadPool, + FrameFactory = context => + { + return new Frame(new TestApplication(c => + { + return c.Response.WriteAsync("Secondary"); ; + }), context); + } + }; + + using (var kestrelEngine = new KestrelEngine(libuv, serviceContextPrimary)) + { + var address = ServerAddress.FromUrl("http://127.0.0.1:0/"); + var pipeName = (libuv.IsWindows ? @"\\.\pipe\kestrel_" : "/tmp/kestrel_") + Guid.NewGuid().ToString("n"); + + // Start primary listener + var kestrelThreadPrimary = new KestrelThread(kestrelEngine); + await kestrelThreadPrimary.StartAsync(); + var listenerPrimary = new TcpListenerPrimary(serviceContextPrimary); + await listenerPrimary.StartAsync(pipeName, address, kestrelThreadPrimary); + + // Until a secondary listener is added, TCP connections get dispatched directly + Assert.Equal("Primary", await HttpClientSlim.GetStringAsync(address.ToString())); + Assert.Equal("Primary", await HttpClientSlim.GetStringAsync(address.ToString())); + + // Add secondary listener + var kestrelThreadSecondary = new KestrelThread(kestrelEngine); + await kestrelThreadSecondary.StartAsync(); + var listenerSecondary = new TcpListenerSecondary(serviceContextSecondary); + await listenerSecondary.StartAsync(pipeName, address, kestrelThreadSecondary); + + // Once a secondary listener is added, TCP connections start getting dispatched to it + Assert.Equal("Secondary", await HttpClientSlim.GetStringAsync(address.ToString())); + + // TCP connections will still get round-robined to the primary listener + Assert.Equal("Primary", await HttpClientSlim.GetStringAsync(address.ToString())); + Assert.Equal("Secondary", await HttpClientSlim.GetStringAsync(address.ToString())); + Assert.Equal("Primary", await HttpClientSlim.GetStringAsync(address.ToString())); + + await listenerSecondary.DisposeAsync(); + kestrelThreadSecondary.Stop(TimeSpan.FromSeconds(1)); + + await listenerPrimary.DisposeAsync(); + kestrelThreadPrimary.Stop(TimeSpan.FromSeconds(1)); + } + } + + // https://github.com/aspnet/KestrelHttpServer/issues/1182 + [Fact] + public async Task NonListenerPipeConnectionsAreLoggedAndIgnored() + { + var libuv = new Libuv(); + + var primaryTrace = new TestKestrelTrace(); + + var serviceContextPrimary = new TestServiceContext + { + Log = primaryTrace, + FrameFactory = context => + { + return new Frame(new TestApplication(c => + { + return c.Response.WriteAsync("Primary"); + }), context); + } + }; + + var serviceContextSecondary = new ServiceContext + { + Log = new TestKestrelTrace(), + AppLifetime = serviceContextPrimary.AppLifetime, + DateHeaderValueManager = serviceContextPrimary.DateHeaderValueManager, + ServerOptions = serviceContextPrimary.ServerOptions, + ThreadPool = serviceContextPrimary.ThreadPool, + FrameFactory = context => + { + return new Frame(new TestApplication(c => + { + return c.Response.WriteAsync("Secondary"); ; + }), context); + } + }; + + using (var kestrelEngine = new KestrelEngine(libuv, serviceContextPrimary)) + { + var address = ServerAddress.FromUrl("http://127.0.0.1:0/"); + var pipeName = (libuv.IsWindows ? @"\\.\pipe\kestrel_" : "/tmp/kestrel_") + Guid.NewGuid().ToString("n"); + + // Start primary listener + var kestrelThreadPrimary = new KestrelThread(kestrelEngine); + await kestrelThreadPrimary.StartAsync(); + var listenerPrimary = new TcpListenerPrimary(serviceContextPrimary); + await listenerPrimary.StartAsync(pipeName, address, kestrelThreadPrimary); + + // Add secondary listener + var kestrelThreadSecondary = new KestrelThread(kestrelEngine); + await kestrelThreadSecondary.StartAsync(); + var listenerSecondary = new TcpListenerSecondary(serviceContextSecondary); + await listenerSecondary.StartAsync(pipeName, address, kestrelThreadSecondary); + + // TCP Connections get round-robined + Assert.Equal("Secondary", await HttpClientSlim.GetStringAsync(address.ToString())); + Assert.Equal("Primary", await HttpClientSlim.GetStringAsync(address.ToString())); + + // Create a pipe connection and keep it open without sending any data + var connectTcs = new TaskCompletionSource(); + var connectionTrace = new TestKestrelTrace(); + var pipe = new UvPipeHandle(connectionTrace); + + kestrelThreadPrimary.Post(_ => + { + var connectReq = new UvConnectRequest(connectionTrace); + + pipe.Init(kestrelThreadPrimary.Loop, kestrelThreadPrimary.QueueCloseHandle); + connectReq.Init(kestrelThreadPrimary.Loop); + + connectReq.Connect( + pipe, + pipeName, + (req, status, ex, __) => + { + req.Dispose(); + + if (ex != null) + { + connectTcs.SetException(ex); + } + else + { + connectTcs.SetResult(null); + } + }, + null); + }, null); + + await connectTcs.Task; + + // TCP connections will still get round-robined between only the two listeners + Assert.Equal("Secondary", await HttpClientSlim.GetStringAsync(address.ToString())); + Assert.Equal("Primary", await HttpClientSlim.GetStringAsync(address.ToString())); + Assert.Equal("Secondary", await HttpClientSlim.GetStringAsync(address.ToString())); + + await kestrelThreadPrimary.PostAsync(_ => pipe.Dispose(), null); + + // Same for after the non-listener pipe connection is closed + Assert.Equal("Primary", await HttpClientSlim.GetStringAsync(address.ToString())); + Assert.Equal("Secondary", await HttpClientSlim.GetStringAsync(address.ToString())); + Assert.Equal("Primary", await HttpClientSlim.GetStringAsync(address.ToString())); + + await listenerSecondary.DisposeAsync(); + kestrelThreadSecondary.Stop(TimeSpan.FromSeconds(1)); + + await listenerPrimary.DisposeAsync(); + kestrelThreadPrimary.Stop(TimeSpan.FromSeconds(1)); + } + + Assert.Equal(1, primaryTrace.Logger.TotalErrorsLogged); + var errorMessage = primaryTrace.Logger.Messages.First(m => m.LogLevel == LogLevel.Error); + Assert.Contains("EOF", errorMessage.Exception.ToString()); + } + + private class TestApplication : IHttpApplication + { + private readonly Func _app; + + public TestApplication(Func app) + { + _app = app; + } + + public DefaultHttpContext CreateContext(IFeatureCollection contextFeatures) + { + return new DefaultHttpContext(contextFeatures); + } + + public Task ProcessRequestAsync(DefaultHttpContext context) + { + return _app(context); + } + + public void DisposeContext(DefaultHttpContext context, Exception exception) + { + } + } + } +} diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/HttpClientSlim.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/HttpClientSlim.cs new file mode 100644 index 0000000000..02cf1880fe --- /dev/null +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/HttpClientSlim.cs @@ -0,0 +1,129 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.IO; +using System.Net; +using System.Net.Http; +using System.Net.Security; +using System.Net.Sockets; +using System.Security.Authentication; +using System.Text; +using System.Threading.Tasks; + +namespace Microsoft.AspNetCore.Testing +{ + // Lightweight version of HttpClient implemented using Socket and SslStream + public static class HttpClientSlim + { + public static Task GetStringAsync(string requestUri, bool validateCertificate = true) + => GetStringAsync(new Uri(requestUri), validateCertificate); + + public static async Task GetStringAsync(Uri requestUri, bool validateCertificate = true) + { + using (var stream = await GetStream(requestUri, validateCertificate)) + { + using (var writer = new StreamWriter(stream, Encoding.ASCII, bufferSize: 1024, leaveOpen: true)) + { + await writer.WriteAsync($"GET {requestUri.PathAndQuery} HTTP/1.0\r\n"); + await writer.WriteAsync($"Host: {requestUri.Authority}\r\n"); + await writer.WriteAsync("\r\n"); + } + + return await ReadResponse(stream); + } + } + + public static Task PostAsync(string requestUri, HttpContent content, bool validateCertificate = true) + => PostAsync(new Uri(requestUri), content, validateCertificate); + + public static async Task PostAsync(Uri requestUri, HttpContent content, bool validateCertificate = true) + { + using (var stream = await GetStream(requestUri, validateCertificate)) + { + using (var writer = new StreamWriter(stream, Encoding.ASCII, bufferSize: 1024, leaveOpen: true)) + { + await writer.WriteAsync($"POST {requestUri.PathAndQuery} HTTP/1.0\r\n"); + await writer.WriteAsync($"Host: {requestUri.Authority}\r\n"); + await writer.WriteAsync($"Content-Type: {content.Headers.ContentType}\r\n"); + await writer.WriteAsync($"Content-Length: {content.Headers.ContentLength}\r\n"); + await writer.WriteAsync("\r\n"); + } + + await content.CopyToAsync(stream); + + return await ReadResponse(stream); + } + } + + private static async Task ReadResponse(Stream stream) + { + using (var reader = new StreamReader(stream, Encoding.ASCII, detectEncodingFromByteOrderMarks: true, + bufferSize: 1024, leaveOpen: true)) + { + var response = await reader.ReadToEndAsync(); + + var status = GetStatus(response); + new HttpResponseMessage(status).EnsureSuccessStatusCode(); + + var body = response.Substring(response.IndexOf("\r\n\r\n") + 4); + return body; + } + + } + + private static HttpStatusCode GetStatus(string response) + { + var statusStart = response.IndexOf(' ') + 1; + var statusEnd = response.IndexOf(' ', statusStart) - 1; + var statusLength = statusEnd - statusStart + 1; + return (HttpStatusCode)int.Parse(response.Substring(statusStart, statusLength)); + } + + private static async Task GetStream(Uri requestUri, bool validateCertificate) + { + var socket = await GetSocket(requestUri); + Stream stream = new NetworkStream(socket, ownsSocket: true); + + if (requestUri.Scheme.Equals("https", StringComparison.OrdinalIgnoreCase)) + { + var sslStream = new SslStream(stream, leaveInnerStreamOpen: false, userCertificateValidationCallback: + validateCertificate ? null : (RemoteCertificateValidationCallback)((a, b, c, d) => true)); + await sslStream.AuthenticateAsClientAsync(requestUri.Host, clientCertificates: null, + enabledSslProtocols: SslProtocols.Tls11 | SslProtocols.Tls12, + checkCertificateRevocation: validateCertificate); + return sslStream; + } + else + { + return stream; + } + } + + public static async Task GetSocket(Uri requestUri) + { + var tcs = new TaskCompletionSource(); + + var socketArgs = new SocketAsyncEventArgs(); + socketArgs.RemoteEndPoint = new DnsEndPoint(requestUri.DnsSafeHost, requestUri.Port); + socketArgs.Completed += (s, e) => tcs.TrySetResult(e.ConnectSocket); + + // Must use static ConnectAsync(), since instance Connect() does not support DNS names on OSX/Linux. + if (Socket.ConnectAsync(SocketType.Stream, ProtocolType.Tcp, socketArgs)) + { + await tcs.Task; + } + + var socket = socketArgs.ConnectSocket; + + if (socket == null) + { + throw new SocketException((int)socketArgs.SocketError); + } + else + { + return socket; + } + } + } +} diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/TestApplicationErrorLogger.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/TestApplicationErrorLogger.cs index 2534de82da..4d97615b2c 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/TestApplicationErrorLogger.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/TestApplicationErrorLogger.cs @@ -2,7 +2,8 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using Microsoft.AspNetCore.Server.Kestrel; +using System.Collections.Generic; +using System.Linq; using Microsoft.AspNetCore.Server.Kestrel.Internal; using Microsoft.Extensions.Logging; @@ -13,9 +14,13 @@ namespace Microsoft.AspNetCore.Server.KestrelTests // Application errors are logged using 13 as the eventId. private const int ApplicationErrorEventId = 13; - public int TotalErrorsLogged { get; set; } + public List Messages { get; } = new List(); - public int ApplicationErrorsLogged { get; set; } + public int TotalErrorsLogged => Messages.Count(message => message.LogLevel == LogLevel.Error); + + public int CriticalErrorsLogged => Messages.Count(message => message.LogLevel == LogLevel.Critical); + + public int ApplicationErrorsLogged => Messages.Count(message => message.EventId.Id == ApplicationErrorEventId); public IDisposable BeginScope(TState state) { @@ -33,15 +38,14 @@ namespace Microsoft.AspNetCore.Server.KestrelTests Console.WriteLine($"Log {logLevel}[{eventId}]: {formatter(state, exception)} {exception?.Message}"); #endif - if (eventId.Id == ApplicationErrorEventId) - { - ApplicationErrorsLogged++; - } + Messages.Add(new LogMessage { LogLevel = logLevel, EventId = eventId, Exception = exception }); + } - if (logLevel == LogLevel.Error) - { - TotalErrorsLogged++; - } + public class LogMessage + { + public LogLevel LogLevel { get; set; } + public EventId EventId { get; set; } + public Exception Exception { get; set; } } } } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/TestKestrelTrace.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/TestKestrelTrace.cs index 741ec54a0b..c3f0860064 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/TestKestrelTrace.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/TestKestrelTrace.cs @@ -1,5 +1,7 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + using Microsoft.AspNetCore.Server.Kestrel.Internal; -using Microsoft.Extensions.Logging; namespace Microsoft.AspNetCore.Server.KestrelTests { @@ -9,10 +11,13 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { } - public TestKestrelTrace(ILogger testLogger) : base(testLogger) + public TestKestrelTrace(TestApplicationErrorLogger testLogger) : base(testLogger) { + Logger = testLogger; } + public TestApplicationErrorLogger Logger { get; private set; } + public override void ConnectionRead(string connectionId, int count) { //_logger.LogDebug(1, @"Connection id ""{ConnectionId}"" recv {count} bytes.", connectionId, count); From 847e4e2697319567533a9fe9f31a5c5895bed826 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Fri, 11 Nov 2016 14:51:37 -0800 Subject: [PATCH 0962/1662] Better filter clients connecting to Kestrel's dispatch pipes --- .../Internal/Http/ListenerPrimary.cs | 26 ++++-- .../Internal/Http/ListenerSecondary.cs | 8 +- .../Internal/Infrastructure/Constants.cs | 3 - .../Internal/KestrelEngine.cs | 5 +- .../ListenerPrimaryTests.cs | 85 +++++++++++++++++-- 5 files changed, 108 insertions(+), 19 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ListenerPrimary.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ListenerPrimary.cs index 1bfc4c0ad0..6520a4ad08 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ListenerPrimary.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ListenerPrimary.cs @@ -21,6 +21,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http private readonly List _dispatchPipes = new List(); private int _dispatchIndex; private string _pipeName; + private byte[] _pipeMessage; private IntPtr _fileCompletionInfoPtr; private bool _tryDetachFromIOCP = PlatformApis.IsWindows; @@ -36,10 +37,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http public async Task StartAsync( string pipeName, + byte[] pipeMessage, ServerAddress address, KestrelThread thread) { _pipeName = pipeName; + _pipeMessage = pipeMessage; if (_fileCompletionInfoPtr == IntPtr.Zero) { @@ -187,7 +190,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http private class PipeReadContext { + private const int _bufferLength = 16; + private readonly ListenerPrimary _listener; + private readonly byte[] _buf = new byte[_bufferLength]; private readonly IntPtr _bufPtr; private GCHandle _bufHandle; private int _bytesRead; @@ -195,16 +201,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http public PipeReadContext(ListenerPrimary listener) { _listener = listener; - _bufHandle = GCHandle.Alloc(new byte[8], GCHandleType.Pinned); + _bufHandle = GCHandle.Alloc(_buf, GCHandleType.Pinned); _bufPtr = _bufHandle.AddrOfPinnedObject(); } public Libuv.uv_buf_t AllocCallback(UvStreamHandle dispatchPipe, int suggestedSize) { - return dispatchPipe.Libuv.buf_init(_bufPtr + _bytesRead, 8 - _bytesRead); + return dispatchPipe.Libuv.buf_init(_bufPtr + _bytesRead, _bufferLength - _bytesRead); } - public unsafe void ReadCallback(UvStreamHandle dispatchPipe, int status) + public void ReadCallback(UvStreamHandle dispatchPipe, int status) { try { @@ -212,9 +218,19 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _bytesRead += status; - if (_bytesRead == 8) + if (_bytesRead == _bufferLength) { - if (*(ulong*)_bufPtr == Constants.PipeMessage) + var correctMessage = true; + + for (var i = 0; i < _bufferLength; i++) + { + if (_buf[i] != _listener._pipeMessage[i]) + { + correctMessage = false; + } + } + + if (correctMessage) { _listener._dispatchPipes.Add((UvPipeHandle) dispatchPipe); dispatchPipe.ReadStop(); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ListenerSecondary.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ListenerSecondary.cs index bd4d384fb2..497e1061bb 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ListenerSecondary.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ListenerSecondary.cs @@ -17,10 +17,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http /// public abstract class ListenerSecondary : ListenerContext, IAsyncDisposable { - private static ArraySegment> _pipeMessage = - new ArraySegment>(new[] { new ArraySegment(BitConverter.GetBytes(Constants.PipeMessage)) }); - private string _pipeName; + private byte[] _pipeMessage; private IntPtr _ptr; private Libuv.uv_buf_t _buf; private bool _closed; @@ -34,10 +32,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http public Task StartAsync( string pipeName, + byte[] pipeMessage, ServerAddress address, KestrelThread thread) { _pipeName = pipeName; + _pipeMessage = pipeMessage; _buf = thread.Loop.Libuv.buf_init(_ptr, 4); ServerAddress = address; @@ -104,7 +104,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http writeReq.Init(Thread.Loop); writeReq.Write( DispatchPipe, - _pipeMessage, + new ArraySegment>(new [] { new ArraySegment(_pipeMessage) }), (req, status2, ex, state) => { req.Dispose(); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/Constants.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/Constants.cs index 47b04be220..2d270d9955 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/Constants.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/Constants.cs @@ -26,9 +26,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure public const string ServerName = "Kestrel"; - // "Kestrel\0" - public const ulong PipeMessage = 0x006C65727473654B; - private static int? GetECONNRESET() { if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/KestrelEngine.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/KestrelEngine.cs index a3faaad6a4..976b8c3718 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/KestrelEngine.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/KestrelEngine.cs @@ -57,6 +57,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal try { var pipeName = (Libuv.IsWindows ? @"\\.\pipe\kestrel_" : "/tmp/kestrel_") + Guid.NewGuid().ToString("n"); + var pipeMessage = Guid.NewGuid().ToByteArray(); var single = Threads.Count == 1; var first = true; @@ -78,7 +79,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal : new TcpListenerPrimary(this); listeners.Add(listener); - listener.StartAsync(pipeName, address, thread).Wait(); + listener.StartAsync(pipeName, pipeMessage, address, thread).Wait(); } else { @@ -86,7 +87,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal ? (ListenerSecondary) new PipeListenerSecondary(this) : new TcpListenerSecondary(this); listeners.Add(listener); - listener.StartAsync(pipeName, address, thread).Wait(); + listener.StartAsync(pipeName, pipeMessage, address, thread).Wait(); } first = false; diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/ListenerPrimaryTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/ListenerPrimaryTests.cs index 471aa42b43..51d113e335 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/ListenerPrimaryTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/ListenerPrimaryTests.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.IO; using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Hosting.Server; @@ -10,6 +11,7 @@ using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Server.Kestrel; using Microsoft.AspNetCore.Server.Kestrel.Internal; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; using Microsoft.AspNetCore.Testing; using Microsoft.Extensions.Logging; @@ -55,12 +57,13 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { var address = ServerAddress.FromUrl("http://127.0.0.1:0/"); var pipeName = (libuv.IsWindows ? @"\\.\pipe\kestrel_" : "/tmp/kestrel_") + Guid.NewGuid().ToString("n"); + var pipeMessage = Guid.NewGuid().ToByteArray(); // Start primary listener var kestrelThreadPrimary = new KestrelThread(kestrelEngine); await kestrelThreadPrimary.StartAsync(); var listenerPrimary = new TcpListenerPrimary(serviceContextPrimary); - await listenerPrimary.StartAsync(pipeName, address, kestrelThreadPrimary); + await listenerPrimary.StartAsync(pipeName, pipeMessage, address, kestrelThreadPrimary); // Until a secondary listener is added, TCP connections get dispatched directly Assert.Equal("Primary", await HttpClientSlim.GetStringAsync(address.ToString())); @@ -70,7 +73,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var kestrelThreadSecondary = new KestrelThread(kestrelEngine); await kestrelThreadSecondary.StartAsync(); var listenerSecondary = new TcpListenerSecondary(serviceContextSecondary); - await listenerSecondary.StartAsync(pipeName, address, kestrelThreadSecondary); + await listenerSecondary.StartAsync(pipeName, pipeMessage, address, kestrelThreadSecondary); // Once a secondary listener is added, TCP connections start getting dispatched to it Assert.Equal("Secondary", await HttpClientSlim.GetStringAsync(address.ToString())); @@ -128,18 +131,19 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { var address = ServerAddress.FromUrl("http://127.0.0.1:0/"); var pipeName = (libuv.IsWindows ? @"\\.\pipe\kestrel_" : "/tmp/kestrel_") + Guid.NewGuid().ToString("n"); + var pipeMessage = Guid.NewGuid().ToByteArray(); // Start primary listener var kestrelThreadPrimary = new KestrelThread(kestrelEngine); await kestrelThreadPrimary.StartAsync(); var listenerPrimary = new TcpListenerPrimary(serviceContextPrimary); - await listenerPrimary.StartAsync(pipeName, address, kestrelThreadPrimary); + await listenerPrimary.StartAsync(pipeName, pipeMessage, address, kestrelThreadPrimary); // Add secondary listener var kestrelThreadSecondary = new KestrelThread(kestrelEngine); await kestrelThreadSecondary.StartAsync(); var listenerSecondary = new TcpListenerSecondary(serviceContextSecondary); - await listenerSecondary.StartAsync(pipeName, address, kestrelThreadSecondary); + await listenerSecondary.StartAsync(pipeName, pipeMessage, address, kestrelThreadSecondary); // TCP Connections get round-robined Assert.Equal("Secondary", await HttpClientSlim.GetStringAsync(address.ToString())); @@ -199,7 +203,78 @@ namespace Microsoft.AspNetCore.Server.KestrelTests Assert.Equal(1, primaryTrace.Logger.TotalErrorsLogged); var errorMessage = primaryTrace.Logger.Messages.First(m => m.LogLevel == LogLevel.Error); - Assert.Contains("EOF", errorMessage.Exception.ToString()); + Assert.Equal(Constants.EOF, Assert.IsType(errorMessage.Exception).StatusCode); + } + + [Fact] + public async Task PipeConnectionsWithWrongMessageAreLoggedAndIgnored() + { + var libuv = new Libuv(); + + var primaryTrace = new TestKestrelTrace(); + + var serviceContextPrimary = new TestServiceContext + { + Log = primaryTrace, + FrameFactory = context => + { + return new Frame(new TestApplication(c => + { + return c.Response.WriteAsync("Primary"); + }), context); + } + }; + + var serviceContextSecondary = new ServiceContext + { + Log = new TestKestrelTrace(), + AppLifetime = serviceContextPrimary.AppLifetime, + DateHeaderValueManager = serviceContextPrimary.DateHeaderValueManager, + ServerOptions = serviceContextPrimary.ServerOptions, + ThreadPool = serviceContextPrimary.ThreadPool, + FrameFactory = context => + { + return new Frame(new TestApplication(c => + { + return c.Response.WriteAsync("Secondary"); ; + }), context); + } + }; + + using (var kestrelEngine = new KestrelEngine(libuv, serviceContextPrimary)) + { + var address = ServerAddress.FromUrl("http://127.0.0.1:0/"); + var pipeName = (libuv.IsWindows ? @"\\.\pipe\kestrel_" : "/tmp/kestrel_") + Guid.NewGuid().ToString("n"); + var pipeMessage = Guid.NewGuid().ToByteArray(); + + // Start primary listener + var kestrelThreadPrimary = new KestrelThread(kestrelEngine); + await kestrelThreadPrimary.StartAsync(); + var listenerPrimary = new TcpListenerPrimary(serviceContextPrimary); + await listenerPrimary.StartAsync(pipeName, pipeMessage, address, kestrelThreadPrimary); + + // Add secondary listener with wrong pipe message + var kestrelThreadSecondary = new KestrelThread(kestrelEngine); + await kestrelThreadSecondary.StartAsync(); + var listenerSecondary = new TcpListenerSecondary(serviceContextSecondary); + await listenerSecondary.StartAsync(pipeName, Guid.NewGuid().ToByteArray(), address, kestrelThreadSecondary); + + // TCP Connections get round-robined + Assert.Equal("Primary", await HttpClientSlim.GetStringAsync(address.ToString())); + Assert.Equal("Primary", await HttpClientSlim.GetStringAsync(address.ToString())); + Assert.Equal("Primary", await HttpClientSlim.GetStringAsync(address.ToString())); + + await listenerSecondary.DisposeAsync(); + kestrelThreadSecondary.Stop(TimeSpan.FromSeconds(1)); + + await listenerPrimary.DisposeAsync(); + kestrelThreadPrimary.Stop(TimeSpan.FromSeconds(1)); + } + + Assert.Equal(1, primaryTrace.Logger.TotalErrorsLogged); + var errorMessage = primaryTrace.Logger.Messages.First(m => m.LogLevel == LogLevel.Error); + Assert.IsType(errorMessage.Exception); + Assert.Contains("Bad data", errorMessage.Exception.ToString()); } private class TestApplication : IHttpApplication From d8c0f4e2bc6f5b00184dd14e8fbc1d8e10e0c3a3 Mon Sep 17 00:00:00 2001 From: Pranav K Date: Tue, 15 Nov 2016 13:31:45 -0800 Subject: [PATCH 0963/1662] Pin System.Net.Http to final build --- .../project.json | 2 +- test/Microsoft.AspNetCore.Server.KestrelTests/project.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json index 684f86df2f..db594f6152 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json @@ -17,7 +17,7 @@ "version": "1.0.3-*", "type": "platform" }, - "System.Net.Http": "4.1.1-servicing-24703-01", + "System.Net.Http": "4.1.1", "System.Net.Http.WinHttpHandler": "4.0.0", "System.Runtime.Serialization.Primitives": "4.1.1" }, diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/project.json b/test/Microsoft.AspNetCore.Server.KestrelTests/project.json index d69bc34891..a916a2da57 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/project.json +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/project.json @@ -17,7 +17,7 @@ "System.Diagnostics.TraceSource": "4.0.0", "System.Globalization.Extensions": "4.0.1", "System.IO": "4.1.0", - "System.Net.Http": "4.1.1-servicing-24703-01", + "System.Net.Http": "4.1.1", "System.Net.Http.WinHttpHandler": "4.0.0", "System.Net.Sockets": "4.1.0", "System.Runtime.Handles": "4.0.1", From 48d957ae854678db25cb381bfc6c6832b0ec3b5f Mon Sep 17 00:00:00 2001 From: Pranav K Date: Thu, 17 Nov 2016 10:57:41 -0800 Subject: [PATCH 0964/1662] Updating to Microsoft.NETCore.App 1.0.3 --- samples/LargeResponseApp/project.json | 2 +- samples/SampleApp/project.json | 2 +- .../project.json | 2 +- test/Microsoft.AspNetCore.Server.KestrelTests/project.json | 2 +- .../project.json | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/samples/LargeResponseApp/project.json b/samples/LargeResponseApp/project.json index 47f43cb1fb..7482ebee80 100644 --- a/samples/LargeResponseApp/project.json +++ b/samples/LargeResponseApp/project.json @@ -11,7 +11,7 @@ "netcoreapp1.0": { "dependencies": { "Microsoft.NETCore.App": { - "version": "1.0.3-*", + "version": "1.0.3", "type": "platform" } } diff --git a/samples/SampleApp/project.json b/samples/SampleApp/project.json index 467673e7dc..0d323ffb28 100644 --- a/samples/SampleApp/project.json +++ b/samples/SampleApp/project.json @@ -13,7 +13,7 @@ "netcoreapp1.0": { "dependencies": { "Microsoft.NETCore.App": { - "version": "1.0.3-*", + "version": "1.0.3", "type": "platform" }, "System.Console": "4.0.0" diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json index db594f6152..522b45177a 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json @@ -14,7 +14,7 @@ "netcoreapp1.0": { "dependencies": { "Microsoft.NETCore.App": { - "version": "1.0.3-*", + "version": "1.0.3", "type": "platform" }, "System.Net.Http": "4.1.1", diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/project.json b/test/Microsoft.AspNetCore.Server.KestrelTests/project.json index a916a2da57..be73eba5d2 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/project.json +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/project.json @@ -11,7 +11,7 @@ "netcoreapp1.0": { "dependencies": { "Microsoft.NETCore.App": { - "version": "1.0.3-*", + "version": "1.0.3", "type": "platform" }, "System.Diagnostics.TraceSource": "4.0.0", diff --git a/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/project.json b/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/project.json index 22390e4adc..e28200677a 100644 --- a/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/project.json +++ b/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/project.json @@ -11,7 +11,7 @@ "netcoreapp1.0": { "dependencies": { "Microsoft.NETCore.App": { - "version": "1.0.3-*", + "version": "1.0.3", "type": "platform" } } From 7bd027cb6b8e13a4533651636f23076a8575755e Mon Sep 17 00:00:00 2001 From: Nate McMaster Date: Fri, 18 Nov 2016 10:56:54 -0800 Subject: [PATCH 0965/1662] Clean tmp folder after unzipping KoreBuild --- build.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.sh b/build.sh index f4208100eb..4fd7ede788 100755 --- a/build.sh +++ b/build.sh @@ -38,7 +38,7 @@ if test ! -d $buildFolder; then chmod +x $buildFile # Cleanup - if test ! -d $tempFolder; then + if test -d $tempFolder; then rm -rf $tempFolder fi fi From 4f7977d440fff5ea4ae60983fb2d20d008252c54 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Mon, 3 Oct 2016 07:58:24 +0100 Subject: [PATCH 0966/1662] Use PowerOfTwoToHighByte for FindFirstEqualByte --- .../Infrastructure/MemoryPoolIterator.cs | 81 +++++++------------ .../MemoryPoolIteratorTests.cs | 24 +----- 2 files changed, 31 insertions(+), 74 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolIterator.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolIterator.cs index 5f7e908c36..0ab1bf01ad 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolIterator.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolIterator.cs @@ -4,12 +4,14 @@ using System; using System.Diagnostics; using System.Numerics; +using System.Runtime.CompilerServices; using System.Threading; namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure { public struct MemoryPoolIterator { + private static readonly ulong _powerOfTwoToHighByte = PowerOfTwoToHighByte(); private static readonly int _vectorSpan = Vector.Count; private MemoryPoolBlock _block; @@ -307,7 +309,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure _block = block; - var firstEqualByteIndex = FindFirstEqualByte(ref byte0Equals); + var firstEqualByteIndex = LocateFirstFoundByte(ref byte0Equals); var vectorBytesScanned = firstEqualByteIndex + 1; if (bytesScanned + vectorBytesScanned > limit) @@ -413,7 +415,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure _block = block; - var firstEqualByteIndex = FindFirstEqualByte(ref byte0Equals); + var firstEqualByteIndex = LocateFirstFoundByte(ref byte0Equals); if (_block == limit.Block && index + firstEqualByteIndex > limit.Index) { @@ -512,11 +514,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure if (!byte0Equals.Equals(Vector.Zero)) { - byte0Index = FindFirstEqualByte(ref byte0Equals); + byte0Index = LocateFirstFoundByte(ref byte0Equals); } if (!byte1Equals.Equals(Vector.Zero)) { - byte1Index = FindFirstEqualByte(ref byte1Equals); + byte1Index = LocateFirstFoundByte(ref byte1Equals); } if (byte0Index == int.MaxValue && byte1Index == int.MaxValue) @@ -656,15 +658,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure if (!byte0Equals.Equals(Vector.Zero)) { - byte0Index = FindFirstEqualByte(ref byte0Equals); + byte0Index = LocateFirstFoundByte(ref byte0Equals); } if (!byte1Equals.Equals(Vector.Zero)) { - byte1Index = FindFirstEqualByte(ref byte1Equals); + byte1Index = LocateFirstFoundByte(ref byte1Equals); } if (!byte2Equals.Equals(Vector.Zero)) { - byte2Index = FindFirstEqualByte(ref byte2Equals); + byte2Index = LocateFirstFoundByte(ref byte2Equals); } if (byte0Index == int.MaxValue && byte1Index == int.MaxValue && byte2Index == int.MaxValue) @@ -761,60 +763,30 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure } /// - /// Find first byte + /// Locate the first of the found bytes /// /// /// The first index of the result vector - /// byteEquals = 0 - internal static int FindFirstEqualByte(ref Vector byteEquals) + // Force inlining (64 IL bytes, 91 bytes asm) Issue: https://github.com/dotnet/coreclr/issues/7386 + [MethodImpl(MethodImplOptions.AggressiveInlining)] + internal static int LocateFirstFoundByte(ref Vector byteEquals) { - if (!BitConverter.IsLittleEndian) return FindFirstEqualByteSlow(ref byteEquals); - - // Quasi-tree search var vector64 = Vector.AsVectorInt64(byteEquals); - for (var i = 0; i < Vector.Count; i++) + var i = 0; + long longValue = 0; + for (; i < Vector.Count; i++) { - var longValue = vector64[i]; + longValue = vector64[i]; if (longValue == 0) continue; - - return (i << 3) + - ((longValue & 0x00000000ffffffff) > 0 - ? (longValue & 0x000000000000ffff) > 0 - ? (longValue & 0x00000000000000ff) > 0 ? 0 : 1 - : (longValue & 0x0000000000ff0000) > 0 ? 2 : 3 - : (longValue & 0x0000ffff00000000) > 0 - ? (longValue & 0x000000ff00000000) > 0 ? 4 : 5 - : (longValue & 0x00ff000000000000) > 0 ? 6 : 7); + break; } - throw new InvalidOperationException(); - } - // Internal for testing - internal static int FindFirstEqualByteSlow(ref Vector byteEquals) - { - // Quasi-tree search - var vector64 = Vector.AsVectorInt64(byteEquals); - for (var i = 0; i < Vector.Count; i++) - { - var longValue = vector64[i]; - if (longValue == 0) continue; - - var shift = i << 1; - var offset = shift << 2; - var vector32 = Vector.AsVectorInt32(byteEquals); - if (vector32[shift] != 0) - { - if (byteEquals[offset] != 0) return offset; - if (byteEquals[offset + 1] != 0) return offset + 1; - if (byteEquals[offset + 2] != 0) return offset + 2; - return offset + 3; - } - if (byteEquals[offset + 4] != 0) return offset + 4; - if (byteEquals[offset + 5] != 0) return offset + 5; - if (byteEquals[offset + 6] != 0) return offset + 6; - return offset + 7; - } - throw new InvalidOperationException(); + // Flag least significant power of two bit + var powerOfTwoFlag = (ulong)(longValue & -longValue); + // Shift all powers of two into the high byte and extract + var foundByteIndex = (int)((powerOfTwoFlag * _powerOfTwoToHighByte) >> 61); + // Single LEA instruction with jitted const (using function result) + return i * 8 + foundByteIndex; } /// @@ -1059,5 +1031,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure _block = block; _index = blockIndex; } + + private static ulong PowerOfTwoToHighByte() + { + return BitConverter.IsLittleEndian ? 0x20406080A0C0E0ul : 0xE0C0A080604020ul; + } } } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolIteratorTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolIteratorTests.cs index 454f66291f..8ac556ed55 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolIteratorTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolIteratorTests.cs @@ -32,7 +32,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests for (int i = 0; i < Vector.Count; i++) { Vector vector = new Vector(bytes); - Assert.Equal(i, MemoryPoolIterator.FindFirstEqualByte(ref vector)); + Assert.Equal(i, MemoryPoolIterator.LocateFirstFoundByte(ref vector)); bytes[i] = 0; } @@ -40,27 +40,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { bytes[i] = 1; Vector vector = new Vector(bytes); - Assert.Equal(i, MemoryPoolIterator.FindFirstEqualByte(ref vector)); - bytes[i] = 0; - } - } - - [Fact] - public void TestFindFirstEqualByteSlow() - { - var bytes = Enumerable.Repeat(0xff, Vector.Count).ToArray(); - for (int i = 0; i < Vector.Count; i++) - { - Vector vector = new Vector(bytes); - Assert.Equal(i, MemoryPoolIterator.FindFirstEqualByteSlow(ref vector)); - bytes[i] = 0; - } - - for (int i = 0; i < Vector.Count; i++) - { - bytes[i] = 1; - Vector vector = new Vector(bytes); - Assert.Equal(i, MemoryPoolIterator.FindFirstEqualByteSlow(ref vector)); + Assert.Equal(i, MemoryPoolIterator.LocateFirstFoundByte(ref vector)); bytes[i] = 0; } } From 9eb01d1c576320aae04ad46c3b3831774dd2fe91 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Wed, 5 Oct 2016 16:23:58 +0100 Subject: [PATCH 0967/1662] Reduce Vector register pressure by not overlapping --- .../Internal/Infrastructure/MemoryPoolIterator.cs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolIterator.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolIterator.cs index 0ab1bf01ad..34f8b44608 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolIterator.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolIterator.cs @@ -509,13 +509,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure if (following >= _vectorSpan) { var data = new Vector(array, index); - var byte0Equals = Vector.Equals(data, byte0Vector); - var byte1Equals = Vector.Equals(data, byte1Vector); + var byte0Equals = Vector.Equals(data, byte0Vector); if (!byte0Equals.Equals(Vector.Zero)) { byte0Index = LocateFirstFoundByte(ref byte0Equals); } + + var byte1Equals = Vector.Equals(data, byte1Vector); if (!byte1Equals.Equals(Vector.Zero)) { byte1Index = LocateFirstFoundByte(ref byte1Equals); @@ -652,18 +653,20 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure if (following >= _vectorSpan) { var data = new Vector(array, index); - var byte0Equals = Vector.Equals(data, byte0Vector); - var byte1Equals = Vector.Equals(data, byte1Vector); - var byte2Equals = Vector.Equals(data, byte2Vector); + var byte0Equals = Vector.Equals(data, byte0Vector); if (!byte0Equals.Equals(Vector.Zero)) { byte0Index = LocateFirstFoundByte(ref byte0Equals); } + + var byte1Equals = Vector.Equals(data, byte1Vector); if (!byte1Equals.Equals(Vector.Zero)) { byte1Index = LocateFirstFoundByte(ref byte1Equals); } + + var byte2Equals = Vector.Equals(data, byte2Vector); if (!byte2Equals.Equals(Vector.Zero)) { byte2Index = LocateFirstFoundByte(ref byte2Equals); From 972d978d1111054f5caedc1f091059309ecf51cd Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Sat, 15 Oct 2016 18:53:57 +0100 Subject: [PATCH 0968/1662] Swap for vector loop unroll detection --- .../Internal/Infrastructure/MemoryPoolIterator.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolIterator.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolIterator.cs index 34f8b44608..daf2d20f5c 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolIterator.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolIterator.cs @@ -775,8 +775,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure internal static int LocateFirstFoundByte(ref Vector byteEquals) { var vector64 = Vector.AsVectorInt64(byteEquals); - var i = 0; long longValue = 0; + var i = 0; for (; i < Vector.Count; i++) { longValue = vector64[i]; From 97d4406614799746c8608d2633a3a54ea9bcb8d9 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Sat, 15 Oct 2016 20:05:50 +0100 Subject: [PATCH 0969/1662] Use Vector.ctor workaround --- .../Internal/Http/Frame.cs | 64 +++++++++---------- .../Internal/Http/MessageBody.cs | 8 +-- .../Infrastructure/MemoryPoolIterator.cs | 49 ++++++++------ .../MemoryPoolBlockTests.cs | 32 ++++------ .../MemoryPoolIteratorTests.cs | 55 ++++++---------- 5 files changed, 97 insertions(+), 111 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs index 307ce7bc49..399976939c 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs @@ -7,7 +7,6 @@ using System.Diagnostics; using System.IO; using System.Linq; using System.Net; -using System.Numerics; using System.Text; using System.Threading; using System.Threading.Tasks; @@ -24,6 +23,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { public abstract partial class Frame : IFrameControl { + // byte consts don't have a data type annotation so we pre-cast them + private const byte ByteCR = (byte)'\r'; + private const byte ByteLF = (byte)'\n'; + private const byte ByteColon = (byte)':'; + private const byte ByteSpace = (byte)' '; + private const byte ByteTab = (byte)'\t'; + private const byte ByteQuestionMark = (byte)'?'; + private const byte BytePercentage = (byte)'%'; + private static readonly ArraySegment _endChunkedResponseBytes = CreateAsciiByteArraySegment("0\r\n\r\n"); private static readonly ArraySegment _continueBytes = CreateAsciiByteArraySegment("HTTP/1.1 100 Continue\r\n\r\n"); @@ -35,14 +43,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http private static readonly byte[] _bytesEndHeaders = Encoding.ASCII.GetBytes("\r\n\r\n"); private static readonly byte[] _bytesServer = Encoding.ASCII.GetBytes("\r\nServer: Kestrel"); - private static Vector _vectorCRs = new Vector((byte)'\r'); - private static Vector _vectorLFs = new Vector((byte)'\n'); - private static Vector _vectorColons = new Vector((byte)':'); - private static Vector _vectorSpaces = new Vector((byte)' '); - private static Vector _vectorTabs = new Vector((byte)'\t'); - private static Vector _vectorQuestionMarks = new Vector((byte)'?'); - private static Vector _vectorPercentages = new Vector((byte)'%'); - private readonly object _onStartingSync = new Object(); private readonly object _onCompletedSync = new Object(); @@ -952,7 +952,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _requestProcessingStatus = RequestProcessingStatus.RequestStarted; int bytesScanned; - if (end.Seek(ref _vectorLFs, out bytesScanned, ServerOptions.Limits.MaxRequestLineSize) == -1) + if (end.Seek(ByteLF, out bytesScanned, ServerOptions.Limits.MaxRequestLineSize) == -1) { if (bytesScanned >= ServerOptions.Limits.MaxRequestLineSize) { @@ -969,7 +969,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var begin = scan; if (!begin.GetKnownMethod(out method)) { - if (scan.Seek(ref _vectorSpaces, ref end) == -1) + if (scan.Seek(ByteSpace, ref end) == -1) { RejectRequest(RequestRejectionReason.InvalidRequestLine, Log.IsEnabled(LogLevel.Information) ? start.GetAsciiStringEscaped(end, MaxInvalidRequestLineChars) : string.Empty); @@ -1002,16 +1002,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http scan.Take(); begin = scan; var needDecode = false; - var chFound = scan.Seek(ref _vectorSpaces, ref _vectorQuestionMarks, ref _vectorPercentages, ref end); + var chFound = scan.Seek(ByteSpace, ByteQuestionMark, BytePercentage, ref end); if (chFound == -1) { RejectRequest(RequestRejectionReason.InvalidRequestLine, Log.IsEnabled(LogLevel.Information) ? start.GetAsciiStringEscaped(end, MaxInvalidRequestLineChars) : string.Empty); } - else if (chFound == '%') + else if (chFound == BytePercentage) { needDecode = true; - chFound = scan.Seek(ref _vectorSpaces, ref _vectorQuestionMarks, ref end); + chFound = scan.Seek(ByteSpace, ByteQuestionMark, ref end); if (chFound == -1) { RejectRequest(RequestRejectionReason.InvalidRequestLine, @@ -1023,10 +1023,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var pathEnd = scan; var queryString = ""; - if (chFound == '?') + if (chFound == ByteQuestionMark) { begin = scan; - if (scan.Seek(ref _vectorSpaces, ref end) == -1) + if (scan.Seek(ByteSpace, ref end) == -1) { RejectRequest(RequestRejectionReason.InvalidRequestLine, Log.IsEnabled(LogLevel.Information) ? start.GetAsciiStringEscaped(end, MaxInvalidRequestLineChars) : string.Empty); @@ -1036,7 +1036,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var queryEnd = scan; - if (pathBegin.Peek() == ' ') + if (pathBegin.Peek() == ByteSpace) { RejectRequest(RequestRejectionReason.InvalidRequestLine, Log.IsEnabled(LogLevel.Information) ? start.GetAsciiStringEscaped(end, MaxInvalidRequestLineChars) : string.Empty); @@ -1044,7 +1044,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http scan.Take(); begin = scan; - if (scan.Seek(ref _vectorCRs, ref end) == -1) + if (scan.Seek(ByteCR, ref end) == -1) { RejectRequest(RequestRejectionReason.InvalidRequestLine, Log.IsEnabled(LogLevel.Information) ? start.GetAsciiStringEscaped(end, MaxInvalidRequestLineChars) : string.Empty); @@ -1067,7 +1067,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } scan.Take(); // consume CR - if (scan.Take() != '\n') + if (scan.Take() != ByteLF) { RejectRequest(RequestRejectionReason.InvalidRequestLine, Log.IsEnabled(LogLevel.Information) ? start.GetAsciiStringEscaped(end, MaxInvalidRequestLineChars) : string.Empty); @@ -1208,7 +1208,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { return false; } - else if (ch == '\r') + else if (ch == ByteCR) { // Check for final CRLF. end.Take(); @@ -1218,7 +1218,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { return false; } - else if (ch == '\n') + else if (ch == ByteLF) { ConnectionControl.CancelTimeout(); consumed = end; @@ -1228,7 +1228,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http // Headers don't end in CRLF line. RejectRequest(RequestRejectionReason.HeadersCorruptedInvalidHeaderSequence); } - else if (ch == ' ' || ch == '\t') + else if (ch == ByteSpace || ch == ByteTab) { RejectRequest(RequestRejectionReason.HeaderLineMustNotStartWithWhitespace); } @@ -1241,7 +1241,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } int bytesScanned; - if (end.Seek(ref _vectorLFs, out bytesScanned, _remainingRequestHeadersBytesAllowed) == -1) + if (end.Seek(ByteLF, out bytesScanned, _remainingRequestHeadersBytesAllowed) == -1) { if (bytesScanned >= _remainingRequestHeadersBytesAllowed) { @@ -1254,7 +1254,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } var beginName = scan; - if (scan.Seek(ref _vectorColons, ref end) == -1) + if (scan.Seek(ByteColon, ref end) == -1) { RejectRequest(RequestRejectionReason.NoColonCharacterFoundInHeaderLine); } @@ -1263,7 +1263,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http scan.Take(); var validateName = beginName; - if (validateName.Seek(ref _vectorSpaces, ref _vectorTabs, ref endName) != -1) + if (validateName.Seek(ByteSpace, ByteTab, ref endName) != -1) { RejectRequest(RequestRejectionReason.WhitespaceIsNotAllowedInHeaderName); } @@ -1271,14 +1271,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var beginValue = scan; ch = scan.Take(); - while (ch == ' ' || ch == '\t') + while (ch == ByteSpace || ch == ByteTab) { beginValue = scan; ch = scan.Take(); } scan = beginValue; - if (scan.Seek(ref _vectorCRs, ref end) == -1) + if (scan.Seek(ByteCR, ref end) == -1) { RejectRequest(RequestRejectionReason.MissingCRInHeaderLine); } @@ -1287,7 +1287,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http ch = scan.Take(); // expecting '\n' end = scan; - if (ch != '\n') + if (ch != ByteLF) { RejectRequest(RequestRejectionReason.HeaderValueMustNotContainCR); } @@ -1297,7 +1297,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { return false; } - else if (next == ' ' || next == '\t') + else if (next == ByteSpace || next == ByteTab) { // From https://tools.ietf.org/html/rfc7230#section-3.2.4: // @@ -1330,15 +1330,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var endValue = scan; do { - ws.Seek(ref _vectorSpaces, ref _vectorTabs, ref _vectorCRs); + ws.Seek(ByteSpace, ByteTab, ByteCR); endValue = ws; ch = ws.Take(); - while (ch == ' ' || ch == '\t') + while (ch == ByteSpace || ch == ByteTab) { ch = ws.Take(); } - } while (ch != '\r'); + } while (ch != ByteCR); var name = beginName.GetArraySegment(endName); var value = beginValue.GetAsciiString(endValue); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/MessageBody.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/MessageBody.cs index 5fb8fa2c3a..77e9b9adcd 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/MessageBody.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/MessageBody.cs @@ -3,7 +3,6 @@ using System; using System.IO; -using System.Numerics; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; @@ -390,9 +389,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http /// private class ForChunkedEncoding : MessageBody { - // This causes an InvalidProgramException if made static - // https://github.com/dotnet/corefx/issues/8825 - private Vector _vectorCRs = new Vector((byte)'\r'); + // byte consts don't have a data type annotation so we pre-cast it + private const byte ByteCR = (byte)'\r'; private readonly SocketInput _input; private readonly FrameRequestHeaders _requestHeaders; @@ -613,7 +611,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http // Just drain the data do { - if (scan.Seek(ref _vectorCRs) == -1) + if (scan.Seek(ByteCR) == -1) { // End marker not found yet consumed = scan; diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolIterator.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolIterator.cs index daf2d20f5c..3bff457c17 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolIterator.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolIterator.cs @@ -236,14 +236,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure } } - public int Seek(ref Vector byte0Vector) + public int Seek(byte byte0) { int bytesScanned; - return Seek(ref byte0Vector, out bytesScanned); + return Seek(byte0, out bytesScanned); } public unsafe int Seek( - ref Vector byte0Vector, + byte byte0, out int bytesScanned, int limit = int.MaxValue) { @@ -259,7 +259,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure var wasLastBlock = block.Next == null; var following = block.End - index; byte[] array; - var byte0 = byte0Vector[0]; + var byte0Vector = GetVector(byte0); while (true) { @@ -352,7 +352,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure } public unsafe int Seek( - ref Vector byte0Vector, + byte byte0, ref MemoryPoolIterator limit) { if (IsDefault) @@ -365,7 +365,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure var wasLastBlock = block.Next == null; var following = block.End - index; byte[] array; - var byte0 = byte0Vector[0]; + var byte0Vector = GetVector(byte0); while (true) { @@ -453,15 +453,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure } } - public int Seek(ref Vector byte0Vector, ref Vector byte1Vector) + public int Seek(byte byte0, byte byte1) { var limit = new MemoryPoolIterator(); - return Seek(ref byte0Vector, ref byte1Vector, ref limit); + return Seek(byte0, byte1, ref limit); } public unsafe int Seek( - ref Vector byte0Vector, - ref Vector byte1Vector, + byte byte0, + byte byte1, ref MemoryPoolIterator limit) { if (IsDefault) @@ -476,8 +476,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure byte[] array; int byte0Index = int.MaxValue; int byte1Index = int.MaxValue; - var byte0 = byte0Vector[0]; - var byte1 = byte1Vector[0]; + var byte0Vector = GetVector(byte0); + var byte1Vector = GetVector(byte1); while (true) { @@ -595,16 +595,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure } } - public int Seek(ref Vector byte0Vector, ref Vector byte1Vector, ref Vector byte2Vector) + public int Seek(byte byte0, byte byte1, byte byte2) { var limit = new MemoryPoolIterator(); - return Seek(ref byte0Vector, ref byte1Vector, ref byte2Vector, ref limit); + return Seek(byte0, byte1, byte2, ref limit); } public unsafe int Seek( - ref Vector byte0Vector, - ref Vector byte1Vector, - ref Vector byte2Vector, + byte byte0, + byte byte1, + byte byte2, ref MemoryPoolIterator limit) { if (IsDefault) @@ -620,9 +620,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure int byte0Index = int.MaxValue; int byte1Index = int.MaxValue; int byte2Index = int.MaxValue; - var byte0 = byte0Vector[0]; - var byte1 = byte1Vector[0]; - var byte2 = byte2Vector[0]; + var byte0Vector = GetVector(byte0); + var byte1Vector = GetVector(byte1); + var byte2Vector = GetVector(byte2); while (true) { @@ -1035,6 +1035,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure _index = blockIndex; } + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static Vector GetVector(byte vectorByte) + { + // Vector .ctor doesn't become an intrinsic due to detection issue + // However this does cause it to become an intrinsic (with additional multiply and reg->reg copy) + // https://github.com/dotnet/coreclr/issues/7459#issuecomment-253965670 + return Vector.AsVectorByte(new Vector(vectorByte * 0x0101010101010101ul)); + } + private static ulong PowerOfTwoToHighByte() { return BitConverter.IsLittleEndian ? 0x20406080A0C0E0ul : 0xE0C0A080604020ul; diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolBlockTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolBlockTests.cs index a9c5652e4e..4cde6c079a 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolBlockTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolBlockTests.cs @@ -19,35 +19,31 @@ namespace Microsoft.AspNetCore.Server.KestrelTests block.Array[block.End++] = ch; } - var vectorMaxValues = new Vector(byte.MaxValue); - var iterator = block.GetIterator(); foreach (var ch in Enumerable.Range(0, 256).Select(x => (byte)x)) { - var vectorCh = new Vector(ch); - var hit = iterator; - hit.Seek(ref vectorCh); + hit.Seek(ch); Assert.Equal(ch, iterator.GetLength(hit)); hit = iterator; - hit.Seek(ref vectorCh, ref vectorMaxValues); + hit.Seek(ch, byte.MaxValue); Assert.Equal(ch, iterator.GetLength(hit)); hit = iterator; - hit.Seek(ref vectorMaxValues, ref vectorCh); + hit.Seek(byte.MaxValue, ch); Assert.Equal(ch, iterator.GetLength(hit)); hit = iterator; - hit.Seek(ref vectorCh, ref vectorMaxValues, ref vectorMaxValues); + hit.Seek(ch, byte.MaxValue, byte.MaxValue); Assert.Equal(ch, iterator.GetLength(hit)); hit = iterator; - hit.Seek(ref vectorMaxValues, ref vectorCh, ref vectorMaxValues); + hit.Seek(byte.MaxValue, ch, byte.MaxValue); Assert.Equal(ch, iterator.GetLength(hit)); hit = iterator; - hit.Seek(ref vectorCh, ref vectorMaxValues, ref vectorMaxValues); + hit.Seek(ch, byte.MaxValue, byte.MaxValue); Assert.Equal(ch, iterator.GetLength(hit)); } @@ -77,35 +73,31 @@ namespace Microsoft.AspNetCore.Server.KestrelTests block3.Array[block3.End++] = ch; } - var vectorMaxValues = new Vector(byte.MaxValue); - var iterator = block1.GetIterator(); foreach (var ch in Enumerable.Range(0, 256).Select(x => (byte)x)) { - var vectorCh = new Vector(ch); - var hit = iterator; - hit.Seek(ref vectorCh); + hit.Seek(ch); Assert.Equal(ch, iterator.GetLength(hit)); hit = iterator; - hit.Seek(ref vectorCh, ref vectorMaxValues); + hit.Seek(ch, byte.MaxValue); Assert.Equal(ch, iterator.GetLength(hit)); hit = iterator; - hit.Seek(ref vectorMaxValues, ref vectorCh); + hit.Seek(byte.MaxValue, ch); Assert.Equal(ch, iterator.GetLength(hit)); hit = iterator; - hit.Seek(ref vectorCh, ref vectorMaxValues, ref vectorMaxValues); + hit.Seek(ch, byte.MaxValue, byte.MaxValue); Assert.Equal(ch, iterator.GetLength(hit)); hit = iterator; - hit.Seek(ref vectorMaxValues, ref vectorCh, ref vectorMaxValues); + hit.Seek(byte.MaxValue, ch, byte.MaxValue); Assert.Equal(ch, iterator.GetLength(hit)); hit = iterator; - hit.Seek(ref vectorMaxValues, ref vectorMaxValues, ref vectorCh); + hit.Seek(byte.MaxValue, byte.MaxValue, ch); Assert.Equal(ch, iterator.GetLength(hit)); } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolIteratorTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolIteratorTests.cs index 8ac556ed55..c0ff83603b 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolIteratorTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolIteratorTests.cs @@ -78,21 +78,15 @@ namespace Microsoft.AspNetCore.Server.KestrelTests int found = -1; if (searchFor.Length == 1) { - var search0 = new Vector((byte) searchFor[0]); - found = begin.Seek(ref search0); + found = begin.Seek((byte)searchFor[0]); } else if (searchFor.Length == 2) { - var search0 = new Vector((byte) searchFor[0]); - var search1 = new Vector((byte) searchFor[1]); - found = begin.Seek(ref search0, ref search1); + found = begin.Seek((byte)searchFor[0], (byte)searchFor[1]); } else if (searchFor.Length == 3) { - var search0 = new Vector((byte) searchFor[0]); - var search1 = new Vector((byte) searchFor[1]); - var search2 = new Vector((byte) searchFor[2]); - found = begin.Seek(ref search0, ref search1, ref search2); + found = begin.Seek((byte)searchFor[0], (byte)searchFor[1], (byte)searchFor[2]); } else { @@ -739,7 +733,6 @@ namespace Microsoft.AspNetCore.Server.KestrelTests try { // Arrange - var seekVector = new Vector((byte)seek); block = _pool.Lease(); var chars = input.ToString().ToCharArray().Select(c => (byte)c).ToArray(); @@ -749,7 +742,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests // Act int bytesScanned; - var returnValue = scan.Seek(ref seekVector, out bytesScanned, limit); + var returnValue = scan.Seek((byte)seek, out bytesScanned, limit); // Assert Assert.Equal(expectedBytesScanned, bytesScanned); @@ -779,8 +772,6 @@ namespace Microsoft.AspNetCore.Server.KestrelTests try { // Arrange - var seekVector = new Vector((byte)seek); - var input1 = input.Substring(0, input.Length / 2); block1 = _pool.Lease(); var chars1 = input1.ToCharArray().Select(c => (byte)c).ToArray(); @@ -801,7 +792,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests // Act int bytesScanned; - var returnValue = scan.Seek(ref seekVector, out bytesScanned, limit); + var returnValue = scan.Seek((byte)seek, out bytesScanned, limit); // Assert Assert.Equal(expectedBytesScanned, bytesScanned); @@ -835,9 +826,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests try { // Arrange - var seekVector = new Vector((byte)seek); - var limitAtVector = new Vector((byte)limitAt); - var afterSeekVector = new Vector((byte)'B'); + var afterSeek = (byte)'B'; block = _pool.Lease(); var chars = input.ToCharArray().Select(c => (byte)c).ToArray(); @@ -852,13 +841,13 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var end = scan1; // Act - var endReturnValue = end.Seek(ref limitAtVector); - var returnValue1 = scan1.Seek(ref seekVector, ref end); - var returnValue2_1 = scan2_1.Seek(ref seekVector, ref afterSeekVector, ref end); - var returnValue2_2 = scan2_2.Seek(ref afterSeekVector, ref seekVector, ref end); - var returnValue3_1 = scan3_1.Seek(ref seekVector, ref afterSeekVector, ref afterSeekVector, ref end); - var returnValue3_2 = scan3_2.Seek(ref afterSeekVector, ref seekVector, ref afterSeekVector, ref end); - var returnValue3_3 = scan3_3.Seek(ref afterSeekVector, ref afterSeekVector, ref seekVector, ref end); + var endReturnValue = end.Seek((byte)limitAt); + var returnValue1 = scan1.Seek((byte)seek, ref end); + var returnValue2_1 = scan2_1.Seek((byte)seek, afterSeek, ref end); + var returnValue2_2 = scan2_2.Seek(afterSeek, (byte)seek, ref end); + var returnValue3_1 = scan3_1.Seek((byte)seek, afterSeek, afterSeek, ref end); + var returnValue3_2 = scan3_2.Seek(afterSeek, (byte)seek, afterSeek, ref end); + var returnValue3_3 = scan3_3.Seek(afterSeek, afterSeek, (byte)seek, ref end); // Assert Assert.Equal(input.Contains(limitAt) ? limitAt : -1, endReturnValue); @@ -902,9 +891,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests try { // Arrange - var seekVector = new Vector((byte)seek); - var limitAtVector = new Vector((byte)limitAt); - var afterSeekVector = new Vector((byte)'B'); + var afterSeek = (byte)'B'; var input1 = input.Substring(0, input.Length / 2); block1 = _pool.Lease(); @@ -931,13 +918,13 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var end = scan1; // Act - var endReturnValue = end.Seek(ref limitAtVector); - var returnValue1 = scan1.Seek(ref seekVector, ref end); - var returnValue2_1 = scan2_1.Seek(ref seekVector, ref afterSeekVector, ref end); - var returnValue2_2 = scan2_2.Seek(ref afterSeekVector, ref seekVector, ref end); - var returnValue3_1 = scan3_1.Seek(ref seekVector, ref afterSeekVector, ref afterSeekVector, ref end); - var returnValue3_2 = scan3_2.Seek(ref afterSeekVector, ref seekVector, ref afterSeekVector, ref end); - var returnValue3_3 = scan3_3.Seek(ref afterSeekVector, ref afterSeekVector, ref seekVector, ref end); + var endReturnValue = end.Seek((byte)limitAt); + var returnValue1 = scan1.Seek((byte)seek, ref end); + var returnValue2_1 = scan2_1.Seek((byte)seek, afterSeek, ref end); + var returnValue2_2 = scan2_2.Seek(afterSeek, (byte)seek, ref end); + var returnValue3_1 = scan3_1.Seek((byte)seek, afterSeek, afterSeek, ref end); + var returnValue3_2 = scan3_2.Seek(afterSeek, (byte)seek, afterSeek, ref end); + var returnValue3_3 = scan3_3.Seek(afterSeek, afterSeek, (byte)seek, ref end); // Assert Assert.Equal(input.Contains(limitAt) ? limitAt : -1, endReturnValue); From 00a63537cf25f225546a0ef3264717ebd224be45 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Sun, 16 Oct 2016 21:58:49 +0100 Subject: [PATCH 0970/1662] And=> xor, powerOfTwoToHighByte to const --- .../Infrastructure/MemoryPoolIterator.cs | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolIterator.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolIterator.cs index 3bff457c17..83fcc300f0 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolIterator.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolIterator.cs @@ -11,7 +11,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure { public struct MemoryPoolIterator { - private static readonly ulong _powerOfTwoToHighByte = PowerOfTwoToHighByte(); + private const ulong _xorPowerOfTwoToHighByte = (0x07ul | + 0x06ul << 8 | + 0x05ul << 16 | + 0x04ul << 24 | + 0x03ul << 32 | + 0x02ul << 40 | + 0x01ul << 48 ) + 1; + private static readonly int _vectorSpan = Vector.Count; private MemoryPoolBlock _block; @@ -785,9 +792,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure } // Flag least significant power of two bit - var powerOfTwoFlag = (ulong)(longValue & -longValue); + var powerOfTwoFlag = (ulong)(longValue ^ (longValue - 1)); // Shift all powers of two into the high byte and extract - var foundByteIndex = (int)((powerOfTwoFlag * _powerOfTwoToHighByte) >> 61); + var foundByteIndex = (int)((powerOfTwoFlag * _xorPowerOfTwoToHighByte) >> 57); // Single LEA instruction with jitted const (using function result) return i * 8 + foundByteIndex; } @@ -1044,9 +1051,5 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure return Vector.AsVectorByte(new Vector(vectorByte * 0x0101010101010101ul)); } - private static ulong PowerOfTwoToHighByte() - { - return BitConverter.IsLittleEndian ? 0x20406080A0C0E0ul : 0xE0C0A080604020ul; - } } } From 28a21fa7a953e79ea150a9e44daea640cb442314 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Sun, 16 Oct 2016 22:12:56 +0100 Subject: [PATCH 0971/1662] Move vectors closer to use --- .../Infrastructure/MemoryPoolIterator.cs | 27 +++++++------------ 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolIterator.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolIterator.cs index 83fcc300f0..f8327cebec 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolIterator.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolIterator.cs @@ -371,8 +371,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure var index = _index; var wasLastBlock = block.Next == null; var following = block.End - index; - byte[] array; - var byte0Vector = GetVector(byte0); while (true) { @@ -392,7 +390,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure wasLastBlock = block.Next == null; following = block.End - index; } - array = block.Array; + var array = block.Array; while (following > 0) { // Need unit tests to test Vector path @@ -403,7 +401,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure #endif if (following >= _vectorSpan) { - var byte0Equals = Vector.Equals(new Vector(array, index), byte0Vector); + var byte0Equals = Vector.Equals(new Vector(array, index), GetVector(byte0)); if (byte0Equals.Equals(Vector.Zero)) { @@ -480,11 +478,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure var index = _index; var wasLastBlock = block.Next == null; var following = block.End - index; - byte[] array; int byte0Index = int.MaxValue; int byte1Index = int.MaxValue; - var byte0Vector = GetVector(byte0); - var byte1Vector = GetVector(byte1); while (true) { @@ -503,7 +498,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure wasLastBlock = block.Next == null; following = block.End - index; } - array = block.Array; + var array = block.Array; while (following > 0) { @@ -517,13 +512,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure { var data = new Vector(array, index); - var byte0Equals = Vector.Equals(data, byte0Vector); + var byte0Equals = Vector.Equals(data, GetVector(byte0)); if (!byte0Equals.Equals(Vector.Zero)) { byte0Index = LocateFirstFoundByte(ref byte0Equals); } - var byte1Equals = Vector.Equals(data, byte1Vector); + var byte1Equals = Vector.Equals(data, GetVector(byte1)); if (!byte1Equals.Equals(Vector.Zero)) { byte1Index = LocateFirstFoundByte(ref byte1Equals); @@ -623,13 +618,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure var index = _index; var wasLastBlock = block.Next == null; var following = block.End - index; - byte[] array; int byte0Index = int.MaxValue; int byte1Index = int.MaxValue; int byte2Index = int.MaxValue; - var byte0Vector = GetVector(byte0); - var byte1Vector = GetVector(byte1); - var byte2Vector = GetVector(byte2); while (true) { @@ -648,7 +639,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure wasLastBlock = block.Next == null; following = block.End - index; } - array = block.Array; + var array = block.Array; while (following > 0) { // Need unit tests to test Vector path @@ -661,19 +652,19 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure { var data = new Vector(array, index); - var byte0Equals = Vector.Equals(data, byte0Vector); + var byte0Equals = Vector.Equals(data, GetVector(byte0)); if (!byte0Equals.Equals(Vector.Zero)) { byte0Index = LocateFirstFoundByte(ref byte0Equals); } - var byte1Equals = Vector.Equals(data, byte1Vector); + var byte1Equals = Vector.Equals(data, GetVector(byte1)); if (!byte1Equals.Equals(Vector.Zero)) { byte1Index = LocateFirstFoundByte(ref byte1Equals); } - var byte2Equals = Vector.Equals(data, byte2Vector); + var byte2Equals = Vector.Equals(data, GetVector(byte2)); if (!byte2Equals.Equals(Vector.Zero)) { byte2Index = LocateFirstFoundByte(ref byte2Equals); From 8bcbfb9971b208e966b9b8f10010ad287acd4f60 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Wed, 9 Nov 2016 11:40:31 -0800 Subject: [PATCH 0972/1662] Only LocateFirstFoundByte once --- .../Infrastructure/MemoryPoolIterator.cs | 111 +++++------------- .../MemoryPoolIteratorTests.cs | 4 +- 2 files changed, 33 insertions(+), 82 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolIterator.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolIterator.cs index f8327cebec..67856d530b 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolIterator.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolIterator.cs @@ -316,7 +316,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure _block = block; - var firstEqualByteIndex = LocateFirstFoundByte(ref byte0Equals); + var firstEqualByteIndex = LocateFirstFoundByte(byte0Equals); var vectorBytesScanned = firstEqualByteIndex + 1; if (bytesScanned + vectorBytesScanned > limit) @@ -420,7 +420,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure _block = block; - var firstEqualByteIndex = LocateFirstFoundByte(ref byte0Equals); + var firstEqualByteIndex = LocateFirstFoundByte(byte0Equals); if (_block == limit.Block && index + firstEqualByteIndex > limit.Index) { @@ -478,8 +478,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure var index = _index; var wasLastBlock = block.Next == null; var following = block.End - index; - int byte0Index = int.MaxValue; - int byte1Index = int.MaxValue; + int byteIndex = int.MaxValue; while (true) { @@ -512,19 +511,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure { var data = new Vector(array, index); - var byte0Equals = Vector.Equals(data, GetVector(byte0)); - if (!byte0Equals.Equals(Vector.Zero)) + var byteEquals = Vector.Equals(data, GetVector(byte0)); + byteEquals = Vector.ConditionalSelect(byteEquals, byteEquals, Vector.Equals(data, GetVector(byte1))); + + if (!byteEquals.Equals(Vector.Zero)) { - byte0Index = LocateFirstFoundByte(ref byte0Equals); + byteIndex = LocateFirstFoundByte(byteEquals); } - var byte1Equals = Vector.Equals(data, GetVector(byte1)); - if (!byte1Equals.Equals(Vector.Zero)) - { - byte1Index = LocateFirstFoundByte(ref byte1Equals); - } - - if (byte0Index == int.MaxValue && byte1Index == int.MaxValue) + if (byteIndex == int.MaxValue) { following -= _vectorSpan; index += _vectorSpan; @@ -542,21 +537,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure _block = block; - if (byte0Index < byte1Index) - { - _index = index + byte0Index; - - if (block == limit.Block && _index > limit.Index) - { - // Ensure iterator is left at limit position - _index = limit.Index; - return -1; - } - - return byte0; - } - - _index = index + byte1Index; + _index = index + byteIndex; if (block == limit.Block && _index > limit.Index) { @@ -565,7 +546,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure return -1; } - return byte1; + _index = index + byteIndex; + + if (block == limit.Block && _index > limit.Index) + { + // Ensure iterator is left at limit position + _index = limit.Index; + return -1; + } + + return block.Array[index + byteIndex]; } // Need unit tests to test Vector path #if !DEBUG @@ -618,9 +608,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure var index = _index; var wasLastBlock = block.Next == null; var following = block.End - index; - int byte0Index = int.MaxValue; - int byte1Index = int.MaxValue; - int byte2Index = int.MaxValue; + int byteIndex = int.MaxValue; while (true) { @@ -652,25 +640,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure { var data = new Vector(array, index); - var byte0Equals = Vector.Equals(data, GetVector(byte0)); - if (!byte0Equals.Equals(Vector.Zero)) + var byteEquals = Vector.Equals(data, GetVector(byte0)); + byteEquals = Vector.ConditionalSelect(byteEquals, byteEquals, Vector.Equals(data, GetVector(byte1))); + byteEquals = Vector.ConditionalSelect(byteEquals, byteEquals, Vector.Equals(data, GetVector(byte2))); + + if (!byteEquals.Equals(Vector.Zero)) { - byte0Index = LocateFirstFoundByte(ref byte0Equals); + byteIndex = LocateFirstFoundByte(byteEquals); } - var byte1Equals = Vector.Equals(data, GetVector(byte1)); - if (!byte1Equals.Equals(Vector.Zero)) - { - byte1Index = LocateFirstFoundByte(ref byte1Equals); - } - - var byte2Equals = Vector.Equals(data, GetVector(byte2)); - if (!byte2Equals.Equals(Vector.Zero)) - { - byte2Index = LocateFirstFoundByte(ref byte2Equals); - } - - if (byte0Index == int.MaxValue && byte1Index == int.MaxValue && byte2Index == int.MaxValue) + if (byteIndex == int.MaxValue) { following -= _vectorSpan; index += _vectorSpan; @@ -688,35 +667,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure _block = block; - int toReturn, toMove; - if (byte0Index < byte1Index) - { - if (byte0Index < byte2Index) - { - toReturn = byte0; - toMove = byte0Index; - } - else - { - toReturn = byte2; - toMove = byte2Index; - } - } - else - { - if (byte1Index < byte2Index) - { - toReturn = byte1; - toMove = byte1Index; - } - else - { - toReturn = byte2; - toMove = byte2Index; - } - } - - _index = index + toMove; + _index = index + byteIndex; if (block == limit.Block && _index > limit.Index) { @@ -725,7 +676,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure return -1; } - return toReturn; + return block.Array[index + byteIndex]; } // Need unit tests to test Vector path #if !DEBUG @@ -770,7 +721,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure /// The first index of the result vector // Force inlining (64 IL bytes, 91 bytes asm) Issue: https://github.com/dotnet/coreclr/issues/7386 [MethodImpl(MethodImplOptions.AggressiveInlining)] - internal static int LocateFirstFoundByte(ref Vector byteEquals) + internal static int LocateFirstFoundByte(Vector byteEquals) { var vector64 = Vector.AsVectorInt64(byteEquals); long longValue = 0; diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolIteratorTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolIteratorTests.cs index c0ff83603b..156832ca0f 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolIteratorTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolIteratorTests.cs @@ -32,7 +32,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests for (int i = 0; i < Vector.Count; i++) { Vector vector = new Vector(bytes); - Assert.Equal(i, MemoryPoolIterator.LocateFirstFoundByte(ref vector)); + Assert.Equal(i, MemoryPoolIterator.LocateFirstFoundByte(vector)); bytes[i] = 0; } @@ -40,7 +40,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { bytes[i] = 1; Vector vector = new Vector(bytes); - Assert.Equal(i, MemoryPoolIterator.LocateFirstFoundByte(ref vector)); + Assert.Equal(i, MemoryPoolIterator.LocateFirstFoundByte(vector)); bytes[i] = 0; } } From 53f361160e55ba3a7c2fea3fed7ea11a792d5184 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Wed, 9 Nov 2016 09:57:59 -0800 Subject: [PATCH 0973/1662] MemoryPoolIterator fast paths --- .../Infrastructure/MemoryPoolIterator.cs | 72 +++++++++++++++---- 1 file changed, 57 insertions(+), 15 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolIterator.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolIterator.cs index 67856d530b..f41a6542f0 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolIterator.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolIterator.cs @@ -39,6 +39,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure public bool IsEnd { + [MethodImpl(MethodImplOptions.AggressiveInlining)] get { if (_block == null) @@ -51,24 +52,30 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure } else { - var block = _block.Next; - while (block != null) - { - if (block.Start < block.End) - { - return false; // subsequent block has data - IsEnd is false - } - block = block.Next; - } - return true; + return IsEndMultiBlock(); } } } + private bool IsEndMultiBlock() + { + var block = _block.Next; + while (block != null) + { + if (block.Start < block.End) + { + return false; // subsequent block has data - IsEnd is false + } + block = block.Next; + } + return true; + } + public MemoryPoolBlock Block => _block; public int Index => _index; + [MethodImpl(MethodImplOptions.AggressiveInlining)] public int Take() { var block = _block; @@ -78,7 +85,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure } var index = _index; - var wasLastBlock = block.Next == null; if (index < block.End) { @@ -86,6 +92,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure return block.Array[index]; } + return TakeMultiBlock(block, index); + } + + private int TakeMultiBlock(MemoryPoolBlock block, int index) + { + var wasLastBlock = block.Next == null; do { if (wasLastBlock) @@ -109,6 +121,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure } while (true); } + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Skip(int bytesToSkip) { if (_block == null) @@ -116,7 +129,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure return; } - var wasLastBlock = _block.Next == null; var following = _block.End - _index; if (following >= bytesToSkip) @@ -125,6 +137,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure return; } + SkipMultiBlock(bytesToSkip, following); + } + + private void SkipMultiBlock(int bytesToSkip, int following) + { + var wasLastBlock = _block.Next == null; var block = _block; var index = _index; while (true) @@ -152,6 +170,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure } } + [MethodImpl(MethodImplOptions.AggressiveInlining)] public int Peek() { var block = _block; @@ -160,7 +179,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure return -1; } - var wasLastBlock = _block.Next == null; var index = _index; if (index < block.End) @@ -168,6 +186,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure return block.Array[index]; } + return PeekMultiBlock(block, index); + } + + private static int PeekMultiBlock(MemoryPoolBlock block, int index) + { + var wasLastBlock = block.Next == null; do { if (wasLastBlock) @@ -190,6 +214,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure } // NOTE: Little-endian only! + [MethodImpl(MethodImplOptions.AggressiveInlining)] public unsafe bool TryPeekLong(out ulong longValue) { longValue = 0; @@ -199,7 +224,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure return false; } - var wasLastBlock = _block.Next == null; var blockBytes = _block.End - _index; if (blockBytes >= sizeof(ulong)) @@ -207,7 +231,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure longValue = *(ulong*)(_block.DataFixedPtr + _index); return true; } - else if (wasLastBlock) + + return TryPeekLongMultiBlock(ref longValue, blockBytes); + } + + private unsafe bool TryPeekLongMultiBlock(ref ulong longValue, int blockBytes) + { + var wasLastBlock = _block.Next == null; + if (wasLastBlock) { return false; } @@ -778,6 +809,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure } } + [MethodImpl(MethodImplOptions.AggressiveInlining)] public int GetLength(MemoryPoolIterator end) { if (IsDefault || end.IsDefault) @@ -785,6 +817,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure return -1; } + if (_block == end._block) + { + return end._index - _index; + } + + return GetLengthMultiBlock(end); + } + + public int GetLengthMultiBlock(MemoryPoolIterator end) + { var block = _block; var index = _index; var length = 0; From 90c7be1fc0c6566a37f487dc165193d3aa2cb961 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Tue, 15 Nov 2016 00:42:04 +0000 Subject: [PATCH 0974/1662] Add Request Parsing benchmark --- .gitignore | 2 + KestrelHttpServer.sln | 9 + global.json | 2 +- ...spNetCore.Server.Kestrel.Performance.xproj | 22 ++ .../Program.cs | 48 +++++ .../Readme.md | 11 + .../RequestParsing.cs | 200 ++++++++++++++++++ .../columns/RpsColumn.cs | 31 +++ .../configs/CoreConfig.cs | 31 +++ .../configs/DefaultConfig.cs | 42 ++++ .../helpers/MockApplicationErrorLogger.cs | 51 +++++ .../helpers/MockConnectionControl.cs | 34 +++ .../helpers/MockKestrelTrace.cs | 36 ++++ .../helpers/SocketInputExtensions.cs | 37 ++++ .../project.json | 29 +++ 15 files changed, 584 insertions(+), 1 deletion(-) create mode 100644 perf/Microsoft.AspNetCore.Server.Kestrel.Performance/Microsoft.AspNetCore.Server.Kestrel.Performance.xproj create mode 100644 perf/Microsoft.AspNetCore.Server.Kestrel.Performance/Program.cs create mode 100644 perf/Microsoft.AspNetCore.Server.Kestrel.Performance/Readme.md create mode 100644 perf/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsing.cs create mode 100644 perf/Microsoft.AspNetCore.Server.Kestrel.Performance/columns/RpsColumn.cs create mode 100644 perf/Microsoft.AspNetCore.Server.Kestrel.Performance/configs/CoreConfig.cs create mode 100644 perf/Microsoft.AspNetCore.Server.Kestrel.Performance/configs/DefaultConfig.cs create mode 100644 perf/Microsoft.AspNetCore.Server.Kestrel.Performance/helpers/MockApplicationErrorLogger.cs create mode 100644 perf/Microsoft.AspNetCore.Server.Kestrel.Performance/helpers/MockConnectionControl.cs create mode 100644 perf/Microsoft.AspNetCore.Server.Kestrel.Performance/helpers/MockKestrelTrace.cs create mode 100644 perf/Microsoft.AspNetCore.Server.Kestrel.Performance/helpers/SocketInputExtensions.cs create mode 100644 perf/Microsoft.AspNetCore.Server.Kestrel.Performance/project.json diff --git a/.gitignore b/.gitignore index 6acc284439..af0898e29a 100644 --- a/.gitignore +++ b/.gitignore @@ -30,3 +30,5 @@ runtimes/ .build/ .testPublish/ launchSettings.json +BenchmarkDotNet.Artifacts/ +BDN.Generated/ diff --git a/KestrelHttpServer.sln b/KestrelHttpServer.sln index 1a5cda8a81..e6dca6eac9 100644 --- a/KestrelHttpServer.sln +++ b/KestrelHttpServer.sln @@ -45,6 +45,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "shared", "shared", "{0EF2AC test\shared\TestServiceContext.cs = test\shared\TestServiceContext.cs EndProjectSection EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "perf", "perf", "{21B17FBB-5A58-42A8-8473-43160509A9FF}" +EndProject +Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNetCore.Server.Kestrel.Performance", "perf\Microsoft.AspNetCore.Server.Kestrel.Performance\Microsoft.AspNetCore.Server.Kestrel.Performance.xproj", "{70567566-524C-4B67-9B59-E5C206D6C2EB}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -79,6 +83,10 @@ Global {9559A5F1-080C-4909-B6CF-7E4B3DC55748}.Debug|Any CPU.Build.0 = Debug|Any CPU {9559A5F1-080C-4909-B6CF-7E4B3DC55748}.Release|Any CPU.ActiveCfg = Release|Any CPU {9559A5F1-080C-4909-B6CF-7E4B3DC55748}.Release|Any CPU.Build.0 = Release|Any CPU + {70567566-524C-4B67-9B59-E5C206D6C2EB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {70567566-524C-4B67-9B59-E5C206D6C2EB}.Debug|Any CPU.Build.0 = Debug|Any CPU + {70567566-524C-4B67-9B59-E5C206D6C2EB}.Release|Any CPU.ActiveCfg = Release|Any CPU + {70567566-524C-4B67-9B59-E5C206D6C2EB}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -92,5 +100,6 @@ Global {5F64B3C3-0C2E-431A-B820-A81BBFC863DA} = {2D5D5227-4DBD-499A-96B1-76A36B03B750} {9559A5F1-080C-4909-B6CF-7E4B3DC55748} = {D3273454-EA07-41D2-BF0B-FCC3675C2483} {0EF2ACDF-012F-4472-A13A-4272419E2903} = {D3273454-EA07-41D2-BF0B-FCC3675C2483} + {70567566-524C-4B67-9B59-E5C206D6C2EB} = {21B17FBB-5A58-42A8-8473-43160509A9FF} EndGlobalSection EndGlobal diff --git a/global.json b/global.json index 983ba0401e..c0415c19af 100644 --- a/global.json +++ b/global.json @@ -1,3 +1,3 @@ { - "projects": ["src"] + "projects": ["src", "perf"] } diff --git a/perf/Microsoft.AspNetCore.Server.Kestrel.Performance/Microsoft.AspNetCore.Server.Kestrel.Performance.xproj b/perf/Microsoft.AspNetCore.Server.Kestrel.Performance/Microsoft.AspNetCore.Server.Kestrel.Performance.xproj new file mode 100644 index 0000000000..3bbc5601e0 --- /dev/null +++ b/perf/Microsoft.AspNetCore.Server.Kestrel.Performance/Microsoft.AspNetCore.Server.Kestrel.Performance.xproj @@ -0,0 +1,22 @@ + + + + 14.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + + + + 70567566-524c-4b67-9b59-e5c206d6c2eb + Microsoft.AspNetCore.Server.Kestrel.Performance + .\obj + .\bin\ + v4.6.2 + + + 2.0 + + + + + + \ No newline at end of file diff --git a/perf/Microsoft.AspNetCore.Server.Kestrel.Performance/Program.cs b/perf/Microsoft.AspNetCore.Server.Kestrel.Performance/Program.cs new file mode 100644 index 0000000000..db29b584db --- /dev/null +++ b/perf/Microsoft.AspNetCore.Server.Kestrel.Performance/Program.cs @@ -0,0 +1,48 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using BenchmarkDotNet.Running; + +namespace Microsoft.AspNetCore.Server.Kestrel.Performance +{ + public class Program + { + public static void Main(string[] args) + { + var options = (uint[])Enum.GetValues(typeof(BenchmarkType)); + BenchmarkType type; + if (args.Length != 1 || !Enum.TryParse(args[0], out type)) + { + Console.WriteLine($"Please add benchmark to run as parameter:"); + for (var i = 0; i < options.Length; i++) + { + Console.WriteLine($" {((BenchmarkType)options[i]).ToString()}"); + } + + return; + } + + RunSelectedBenchmarks(type); + } + + private static void RunSelectedBenchmarks(BenchmarkType type) + { + if (type.HasFlag(BenchmarkType.RequestParsing)) + { + BenchmarkRunner.Run(); + } + } + } + + [Flags] + public enum BenchmarkType : uint + { + RequestParsing = 1, + // add new ones in powers of two - e.g. 2,4,8,16... + + All = uint.MaxValue + } + + +} diff --git a/perf/Microsoft.AspNetCore.Server.Kestrel.Performance/Readme.md b/perf/Microsoft.AspNetCore.Server.Kestrel.Performance/Readme.md new file mode 100644 index 0000000000..4088c38007 --- /dev/null +++ b/perf/Microsoft.AspNetCore.Server.Kestrel.Performance/Readme.md @@ -0,0 +1,11 @@ +Compile the solution in Release mode (so Kestrel is available in release) + +To run a specific benchmark add it as parameter +``` +dotnet run -c Release RequestParsing +``` +To run all use `All` as parameter +``` +dotnet run -c Release All +``` +Using no parameter will list all available benchmarks \ No newline at end of file diff --git a/perf/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsing.cs b/perf/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsing.cs new file mode 100644 index 0000000000..b1bdbe16f9 --- /dev/null +++ b/perf/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsing.cs @@ -0,0 +1,200 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Linq; +using System.Text; +using BenchmarkDotNet.Attributes; +using Microsoft.AspNetCore.Server.Kestrel.Internal; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; +using RequestLineStatus = Microsoft.AspNetCore.Server.Kestrel.Internal.Http.Frame.RequestLineStatus; + +namespace Microsoft.AspNetCore.Server.Kestrel.Performance +{ + [Config(typeof(CoreConfig))] + public class RequestParsing + { + private const int InnerLoopCount = 512; + private const int Pipelining = 16; + + private const string plaintextRequest = "GET /plaintext HTTP/1.1\r\nHost: www.example.com\r\n\r\n"; + + private const string liveaspnetRequest = "GET https://live.asp.net/ HTTP/1.1\r\n" + + "Host: live.asp.net\r\n" + + "Connection: keep-alive\r\n" + + "Upgrade-Insecure-Requests: 1\r\n" + + "User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.99 Safari/537.36\r\n" + + "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8\r\n" + + "DNT: 1\r\n" + + "Accept-Encoding: gzip, deflate, sdch, br\r\n" + + "Accept-Language: en-US,en;q=0.8\r\n" + + "Cookie: __unam=7a67379-1s65dc575c4-6d778abe-1; omniID=9519gfde_3347_4762_8762_df51458c8ec2\r\n\r\n"; + + private const string unicodeRequest = + "GET http://stackoverflow.com/questions/40148683/why-is-%e0%a5%a7%e0%a5%a8%e0%a5%a9-numeric HTTP/1.1\r\n" + + "Accept: text/html, application/xhtml+xml, image/jxr, */*\r\n" + + "Accept-Language: en-US,en-GB;q=0.7,en;q=0.3\r\n" + + "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36 Edge/15.14965\r\n" + + "Accept-Encoding: gzip, deflate\r\n" + + "Host: stackoverflow.com\r\n" + + "Connection: Keep-Alive\r\n" + + "Cache-Control: max-age=0\r\n" + + "Upgrade-Insecure-Requests: 1\r\n" + + "DNT: 1\r\n" + + "Referer: http://stackoverflow.com/?tab=month\r\n" + + "Pragma: no-cache\r\n" + + "Cookie: prov=20629ccd-8b0f-e8ef-2935-cd26609fc0bc; __qca=P0-1591065732-1479167353442; _ga=GA1.2.1298898376.1479167354; _gat=1; sgt=id=9519gfde_3347_4762_8762_df51458c8ec2; acct=t=why-is-%e0%a5%a7%e0%a5%a8%e0%a5%a9-numeric&s=why-is-%e0%a5%a7%e0%a5%a8%e0%a5%a9-numeric\r\n\r\n"; + + private static readonly byte[] _plaintextPipelinedRequests = Encoding.ASCII.GetBytes(string.Concat(Enumerable.Repeat(plaintextRequest, Pipelining))); + private static readonly byte[] _plaintextRequest = Encoding.ASCII.GetBytes(plaintextRequest); + + private static readonly byte[] _liveaspnentPipelinedRequests = Encoding.ASCII.GetBytes(string.Concat(Enumerable.Repeat(liveaspnetRequest, Pipelining))); + private static readonly byte[] _liveaspnentRequest = Encoding.ASCII.GetBytes(liveaspnetRequest); + + private static readonly byte[] _unicodePipelinedRequests = Encoding.ASCII.GetBytes(string.Concat(Enumerable.Repeat(unicodeRequest, Pipelining))); + private static readonly byte[] _unicodeRequest = Encoding.ASCII.GetBytes(unicodeRequest); + + private KestrelTrace Trace; + private LoggingThreadPool ThreadPool; + private MemoryPool MemoryPool; + private SocketInput SocketInput; + private Frame Frame; + + [Benchmark(Baseline = true, OperationsPerInvoke = InnerLoopCount)] + public void ParsePlaintext() + { + for (var i = 0; i < InnerLoopCount; i++) + { + InsertData(_plaintextRequest); + + ParseData(); + } + } + + [Benchmark(OperationsPerInvoke = InnerLoopCount * Pipelining)] + public void ParsePipelinedPlaintext() + { + for (var i = 0; i < InnerLoopCount; i++) + { + InsertData(_plaintextPipelinedRequests); + + ParseData(); + } + } + + [Benchmark(OperationsPerInvoke = InnerLoopCount)] + public void ParseLiveAspNet() + { + for (var i = 0; i < InnerLoopCount; i++) + { + InsertData(_liveaspnentRequest); + + ParseData(); + } + } + + [Benchmark(OperationsPerInvoke = InnerLoopCount * Pipelining)] + public void ParsePipelinedLiveAspNet() + { + for (var i = 0; i < InnerLoopCount; i++) + { + InsertData(_liveaspnentPipelinedRequests); + + ParseData(); + } + } + + [Benchmark(OperationsPerInvoke = InnerLoopCount)] + public void ParseUnicode() + { + for (var i = 0; i < InnerLoopCount; i++) + { + InsertData(_unicodeRequest); + + ParseData(); + } + } + + [Benchmark(OperationsPerInvoke = InnerLoopCount * Pipelining)] + public void ParseUnicodePipelined() + { + for (var i = 0; i < InnerLoopCount; i++) + { + InsertData(_unicodePipelinedRequests); + + ParseData(); + } + } + + private void InsertData(byte[] dataBytes) + { + SocketInput.IncomingData(dataBytes, 0, dataBytes.Length); + } + + private void ParseData() + { + while (SocketInput.GetAwaiter().IsCompleted) + { + Frame.Reset(); + + if (Frame.TakeStartLine(SocketInput) != RequestLineStatus.Done) + { + ThrowInvalidStartLine(); + } + + Frame.InitializeHeaders(); + + if (!Frame.TakeMessageHeaders(SocketInput, (FrameRequestHeaders) Frame.RequestHeaders)) + { + ThrowInvalidMessageHeaders(); + } + } + } + + private void ThrowInvalidStartLine() + { + throw new InvalidOperationException("Invalid StartLine"); + } + + private void ThrowInvalidMessageHeaders() + { + throw new InvalidOperationException("Invalid MessageHeaders"); + } + + [Setup] + public void Setup() + { + Trace = new KestrelTrace(new MockKestrelTrace()); + ThreadPool = new LoggingThreadPool(Trace); + MemoryPool = new MemoryPool(); + SocketInput = new SocketInput(MemoryPool, ThreadPool); + + var serviceContext = new ServiceContext + { + DateHeaderValueManager = new DateHeaderValueManager(), + ServerOptions = new KestrelServerOptions(), + Log = Trace + }; + var listenerContext = new ListenerContext(serviceContext) + { + ServerAddress = ServerAddress.FromUrl("http://localhost:5000") + }; + var connectionContext = new ConnectionContext(listenerContext) + { + ConnectionControl = new MockConnectionControl(), + SocketInput = SocketInput + }; + + Frame = new Frame(application: null, context: connectionContext); + } + + [Cleanup] + public void Cleanup() + { + SocketInput.IncomingFin(); + SocketInput.Dispose(); + MemoryPool.Dispose(); + } + } +} diff --git a/perf/Microsoft.AspNetCore.Server.Kestrel.Performance/columns/RpsColumn.cs b/perf/Microsoft.AspNetCore.Server.Kestrel.Performance/columns/RpsColumn.cs new file mode 100644 index 0000000000..12e9969ed2 --- /dev/null +++ b/perf/Microsoft.AspNetCore.Server.Kestrel.Performance/columns/RpsColumn.cs @@ -0,0 +1,31 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Linq; +using BenchmarkDotNet.Columns; +using BenchmarkDotNet.Reports; +using BenchmarkDotNet.Running; + +namespace Microsoft.AspNetCore.Server.Kestrel.Performance +{ + public class RpsColumn : IColumn + { + private static int NanosPerSecond = 1000 * 1000 * 1000; + + public string GetValue(Summary summary, Benchmark benchmark) + { + var totalNanos = summary.Reports.First(r => r.Benchmark == benchmark).ResultStatistics.Mean; + // Make sure we don't divide by zero!! + return Math.Abs(totalNanos) > 0.0 ? (NanosPerSecond / totalNanos).ToString("N2") : "N/A"; + } + + public bool IsDefault(Summary summary, Benchmark benchmark) => false; + public bool IsAvailable(Summary summary) => true; + public string Id => "RPS-Column"; + public string ColumnName => "RPS"; + public bool AlwaysShow => true; + public ColumnCategory Category => ColumnCategory.Custom; + public int PriorityInCategory => 1; + } +} diff --git a/perf/Microsoft.AspNetCore.Server.Kestrel.Performance/configs/CoreConfig.cs b/perf/Microsoft.AspNetCore.Server.Kestrel.Performance/configs/CoreConfig.cs new file mode 100644 index 0000000000..eff6663fec --- /dev/null +++ b/perf/Microsoft.AspNetCore.Server.Kestrel.Performance/configs/CoreConfig.cs @@ -0,0 +1,31 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using BenchmarkDotNet.Configs; +using BenchmarkDotNet.Engines; +using BenchmarkDotNet.Environments; +using BenchmarkDotNet.Jobs; +using BenchmarkDotNet.Validators; + +namespace Microsoft.AspNetCore.Server.Kestrel.Performance +{ + public class CoreConfig : ManualConfig + { + public CoreConfig() + { + Add(JitOptimizationsValidator.FailOnError); + Add(new RpsColumn()); + + Add(Job.Default. + With(Platform.X64). + With(Jit.RyuJit). + With(BenchmarkDotNet.Environments.Runtime.Core). + WithRemoveOutliers(true). + With(new GcMode() { Server = true }). + With(RunStrategy.Throughput). + WithLaunchCount(3). + WithWarmupCount(5). + WithTargetCount(10)); + } + } +} diff --git a/perf/Microsoft.AspNetCore.Server.Kestrel.Performance/configs/DefaultConfig.cs b/perf/Microsoft.AspNetCore.Server.Kestrel.Performance/configs/DefaultConfig.cs new file mode 100644 index 0000000000..01f30373c4 --- /dev/null +++ b/perf/Microsoft.AspNetCore.Server.Kestrel.Performance/configs/DefaultConfig.cs @@ -0,0 +1,42 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using BenchmarkDotNet.Configs; +using BenchmarkDotNet.Engines; +using BenchmarkDotNet.Environments; +using BenchmarkDotNet.Jobs; +using BenchmarkDotNet.Validators; + +namespace Microsoft.AspNetCore.Server.Kestrel.Performance +{ + public class DefaultConfig : ManualConfig + { + public DefaultConfig() + { + Add(JitOptimizationsValidator.FailOnError); + Add(new RpsColumn()); + + Add(Job.Default. + With(Platform.X64). + With(Jit.RyuJit). + With(BenchmarkDotNet.Environments.Runtime.Clr). + WithRemoveOutliers(true). + With(new GcMode() { Server = true }). + With(RunStrategy.Throughput). + WithLaunchCount(3). + WithWarmupCount(5). + WithTargetCount(10)); + + Add(Job.Default. + With(Platform.X64). + With(Jit.RyuJit). + With(BenchmarkDotNet.Environments.Runtime.Core). + WithRemoveOutliers(true). + With(new GcMode() { Server = true }). + With(RunStrategy.Throughput). + WithLaunchCount(3). + WithWarmupCount(5). + WithTargetCount(10)); + } + } +} diff --git a/perf/Microsoft.AspNetCore.Server.Kestrel.Performance/helpers/MockApplicationErrorLogger.cs b/perf/Microsoft.AspNetCore.Server.Kestrel.Performance/helpers/MockApplicationErrorLogger.cs new file mode 100644 index 0000000000..c126eba79c --- /dev/null +++ b/perf/Microsoft.AspNetCore.Server.Kestrel.Performance/helpers/MockApplicationErrorLogger.cs @@ -0,0 +1,51 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Collections.Generic; +using System.Linq; +using Microsoft.AspNetCore.Server.Kestrel.Internal; +using Microsoft.Extensions.Logging; + +namespace Microsoft.AspNetCore.Server.Kestrel.Performance +{ + public class MockApplicationErrorLogger : ILogger + { + // Application errors are logged using 13 as the eventId. + private const int ApplicationErrorEventId = 13; + + public List Messages { get; } = new List(); + + public int TotalErrorsLogged => Messages.Count(message => message.LogLevel == LogLevel.Error); + + public int CriticalErrorsLogged => Messages.Count(message => message.LogLevel == LogLevel.Critical); + + public int ApplicationErrorsLogged => Messages.Count(message => message.EventId.Id == ApplicationErrorEventId); + + public IDisposable BeginScope(TState state) + { + return new Disposable(() => { }); + } + + public bool IsEnabled(LogLevel logLevel) + { + return true; + } + + public void Log(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func formatter) + { +#if false + Console.WriteLine($"Log {logLevel}[{eventId}]: {formatter(state, exception)} {exception?.Message}"); +#endif + + Messages.Add(new LogMessage { LogLevel = logLevel, EventId = eventId, Exception = exception }); + } + + public class LogMessage + { + public LogLevel LogLevel { get; set; } + public EventId EventId { get; set; } + public Exception Exception { get; set; } + } + } +} diff --git a/perf/Microsoft.AspNetCore.Server.Kestrel.Performance/helpers/MockConnectionControl.cs b/perf/Microsoft.AspNetCore.Server.Kestrel.Performance/helpers/MockConnectionControl.cs new file mode 100644 index 0000000000..b3587d81db --- /dev/null +++ b/perf/Microsoft.AspNetCore.Server.Kestrel.Performance/helpers/MockConnectionControl.cs @@ -0,0 +1,34 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; + +namespace Microsoft.AspNetCore.Server.Kestrel.Performance +{ + public class MockConnectionControl : IConnectionControl + { + public void CancelTimeout() + { + } + + public void End(ProduceEndType endType) + { + } + + public void Pause() + { + } + + public void ResetTimeout(long milliseconds, TimeoutAction timeoutAction) + { + } + + public void Resume() + { + } + + public void SetTimeout(long milliseconds, TimeoutAction timeoutAction) + { + } + } +} diff --git a/perf/Microsoft.AspNetCore.Server.Kestrel.Performance/helpers/MockKestrelTrace.cs b/perf/Microsoft.AspNetCore.Server.Kestrel.Performance/helpers/MockKestrelTrace.cs new file mode 100644 index 0000000000..9e035010d3 --- /dev/null +++ b/perf/Microsoft.AspNetCore.Server.Kestrel.Performance/helpers/MockKestrelTrace.cs @@ -0,0 +1,36 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using Microsoft.AspNetCore.Server.Kestrel.Internal; + +namespace Microsoft.AspNetCore.Server.Kestrel.Performance +{ + public class MockKestrelTrace : KestrelTrace + { + public MockKestrelTrace() : this(new MockApplicationErrorLogger()) + { + } + + public MockKestrelTrace(MockApplicationErrorLogger testLogger) : base(testLogger) + { + Logger = testLogger; + } + + public MockApplicationErrorLogger Logger { get; private set; } + + public override void ConnectionRead(string connectionId, int count) + { + //_logger.LogDebug(1, @"Connection id ""{ConnectionId}"" recv {count} bytes.", connectionId, count); + } + + public override void ConnectionWrite(string connectionId, int count) + { + //_logger.LogDebug(1, @"Connection id ""{ConnectionId}"" send {count} bytes.", connectionId, count); + } + + public override void ConnectionWriteCallback(string connectionId, int status) + { + //_logger.LogDebug(1, @"Connection id ""{ConnectionId}"" send finished with status {status}.", connectionId, status); + } + } +} \ No newline at end of file diff --git a/perf/Microsoft.AspNetCore.Server.Kestrel.Performance/helpers/SocketInputExtensions.cs b/perf/Microsoft.AspNetCore.Server.Kestrel.Performance/helpers/SocketInputExtensions.cs new file mode 100644 index 0000000000..af26c2994c --- /dev/null +++ b/perf/Microsoft.AspNetCore.Server.Kestrel.Performance/helpers/SocketInputExtensions.cs @@ -0,0 +1,37 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; + +namespace Microsoft.AspNetCore.Server.Kestrel.Performance +{ + public static class SocketInputExtensions + { + public static void IncomingData(this SocketInput input, byte[] buffer, int offset, int count) + { + var bufferIndex = offset; + var remaining = count; + + while (remaining > 0) + { + var block = input.IncomingStart(); + + var bytesLeftInBlock = block.Data.Offset + block.Data.Count - block.End; + var bytesToCopy = remaining < bytesLeftInBlock ? remaining : bytesLeftInBlock; + + Buffer.BlockCopy(buffer, bufferIndex, block.Array, block.End, bytesToCopy); + + bufferIndex += bytesToCopy; + remaining -= bytesToCopy; + + input.IncomingComplete(bytesToCopy, null); + } + } + + public static void IncomingFin(this SocketInput input) + { + input.IncomingComplete(0, null); + } + } +} diff --git a/perf/Microsoft.AspNetCore.Server.Kestrel.Performance/project.json b/perf/Microsoft.AspNetCore.Server.Kestrel.Performance/project.json new file mode 100644 index 0000000000..38bb58ec76 --- /dev/null +++ b/perf/Microsoft.AspNetCore.Server.Kestrel.Performance/project.json @@ -0,0 +1,29 @@ +{ + "version": "1.0.0-*", + "buildOptions": { + "emitEntryPoint": true + }, + + "dependencies": { + "BenchmarkDotNet": "0.10.0", + "Microsoft.AspNetCore.Server.Kestrel": "1.2.0-*" + }, + + "frameworks": { + "net46": {}, + "netcoreapp1.0": { + "dependencies": { + "Microsoft.NETCore.App": { + "version": "1.0.1-*", + "type": "platform" + } + } + } + }, + + "runtimeOptions": { + "configProperties": { + "System.GC.Server": true + } + } +} \ No newline at end of file From 12e2f3057756069f0ff4431fb530a5c259767efe Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Tue, 15 Nov 2016 12:01:13 +0000 Subject: [PATCH 0975/1662] MemoryPoolIterator byref structs --- .../Internal/Http/Frame.cs | 14 +- .../Infrastructure/MemoryPoolIterator.cs | 161 ++++++++++++++++++ .../MemoryPoolIteratorExtensions.cs | 155 +---------------- .../AsciiDecoding.cs | 8 +- .../UrlPathDecoder.cs | 8 +- 5 files changed, 179 insertions(+), 167 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs index 399976939c..59891a7355 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs @@ -975,7 +975,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http Log.IsEnabled(LogLevel.Information) ? start.GetAsciiStringEscaped(end, MaxInvalidRequestLineChars) : string.Empty); } - method = begin.GetAsciiString(scan); + method = begin.GetAsciiString(ref scan); if (method == null) { @@ -1031,7 +1031,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http RejectRequest(RequestRejectionReason.InvalidRequestLine, Log.IsEnabled(LogLevel.Information) ? start.GetAsciiStringEscaped(end, MaxInvalidRequestLineChars) : string.Empty); } - queryString = begin.GetAsciiString(scan); + queryString = begin.GetAsciiString(ref scan); } var queryEnd = scan; @@ -1081,16 +1081,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if (needDecode) { // Read raw target before mutating memory. - rawTarget = pathBegin.GetAsciiString(queryEnd); + rawTarget = pathBegin.GetAsciiString(ref queryEnd); // URI was encoded, unescape and then parse as utf8 pathEnd = UrlPathDecoder.Unescape(pathBegin, pathEnd); - requestUrlPath = pathBegin.GetUtf8String(pathEnd); + requestUrlPath = pathBegin.GetUtf8String(ref pathEnd); } else { // URI wasn't encoded, parse as ASCII - requestUrlPath = pathBegin.GetAsciiString(pathEnd); + requestUrlPath = pathBegin.GetAsciiString(ref pathEnd); if (queryString.Length == 0) { @@ -1100,7 +1100,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } else { - rawTarget = pathBegin.GetAsciiString(queryEnd); + rawTarget = pathBegin.GetAsciiString(ref queryEnd); } } @@ -1341,7 +1341,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } while (ch != ByteCR); var name = beginName.GetArraySegment(endName); - var value = beginValue.GetAsciiString(endValue); + var value = beginValue.GetAsciiString(ref endValue); consumed = scan; requestHeaders.Append(name.Array, name.Offset, name.Count, value); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolIterator.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolIterator.cs index f41a6542f0..78f782d39e 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolIterator.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolIterator.cs @@ -5,7 +5,9 @@ using System; using System.Diagnostics; using System.Numerics; using System.Runtime.CompilerServices; +using System.Text; using System.Threading; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure { @@ -19,6 +21,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure 0x02ul << 40 | 0x01ul << 48 ) + 1; + private static readonly Encoding _utf8 = Encoding.UTF8; private static readonly int _vectorSpan = Vector.Count; private MemoryPoolBlock _block; @@ -1026,6 +1029,164 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure _index = blockIndex; } + public unsafe string GetAsciiString(ref MemoryPoolIterator end) + { + if (IsDefault || end.IsDefault) + { + return null; + } + + var length = GetLength(end); + + if (length == 0) + { + return null; + } + + var inputOffset = Index; + var block = Block; + + var asciiString = new string('\0', length); + + fixed (char* outputStart = asciiString) + { + var output = outputStart; + var remaining = length; + + var endBlock = end.Block; + var endIndex = end.Index; + + var outputOffset = 0; + while (true) + { + int following = (block != endBlock ? block.End : endIndex) - inputOffset; + + if (following > 0) + { + if (!AsciiUtilities.TryGetAsciiString(block.DataFixedPtr + inputOffset, output + outputOffset, following)) + { + throw BadHttpRequestException.GetException(RequestRejectionReason.NonAsciiOrNullCharactersInInputString); + } + + outputOffset += following; + remaining -= following; + } + + if (remaining == 0) + { + break; + } + + block = block.Next; + inputOffset = block.Start; + } + } + + return asciiString; + } + + public string GetUtf8String(ref MemoryPoolIterator end) + { + if (IsDefault || end.IsDefault) + { + return default(string); + } + if (end.Block == Block) + { + return _utf8.GetString(Block.Array, Index, end.Index - Index); + } + + var decoder = _utf8.GetDecoder(); + + var length = GetLength(end); + var charLength = length; + // Worse case is 1 byte = 1 char + var chars = new char[charLength]; + var charIndex = 0; + + var block = Block; + var index = Index; + var remaining = length; + while (true) + { + int bytesUsed; + int charsUsed; + bool completed; + var following = block.End - index; + if (remaining <= following) + { + decoder.Convert( + block.Array, + index, + remaining, + chars, + charIndex, + charLength - charIndex, + true, + out bytesUsed, + out charsUsed, + out completed); + return new string(chars, 0, charIndex + charsUsed); + } + else if (block.Next == null) + { + decoder.Convert( + block.Array, + index, + following, + chars, + charIndex, + charLength - charIndex, + true, + out bytesUsed, + out charsUsed, + out completed); + return new string(chars, 0, charIndex + charsUsed); + } + else + { + decoder.Convert( + block.Array, + index, + following, + chars, + charIndex, + charLength - charIndex, + false, + out bytesUsed, + out charsUsed, + out completed); + charIndex += charsUsed; + remaining -= following; + block = block.Next; + index = block.Start; + } + } + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public ArraySegment GetArraySegment(MemoryPoolIterator end) + { + if (IsDefault || end.IsDefault) + { + return default(ArraySegment); + } + if (end.Block == Block) + { + return new ArraySegment(Block.Array, Index, end.Index - Index); + } + + return GetArraySegmentMultiBlock(ref end); + } + + private ArraySegment GetArraySegmentMultiBlock(ref MemoryPoolIterator end) + { + var length = GetLength(end); + var array = new byte[length]; + CopyTo(array, 0, length, out length); + return new ArraySegment(array, 0, length); + } + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Vector GetVector(byte vectorByte) { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolIteratorExtensions.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolIteratorExtensions.cs index d59f689662..0b7e988af3 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolIteratorExtensions.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolIteratorExtensions.cs @@ -3,6 +3,7 @@ using System; using System.Diagnostics; +using System.Runtime.CompilerServices; using System.Text; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; @@ -71,62 +72,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure } } - public unsafe static string GetAsciiString(this MemoryPoolIterator start, MemoryPoolIterator end) - { - if (start.IsDefault || end.IsDefault) - { - return null; - } - - var length = start.GetLength(end); - - if (length == 0) - { - return null; - } - - var inputOffset = start.Index; - var block = start.Block; - - var asciiString = new string('\0', length); - - fixed (char* outputStart = asciiString) - { - var output = outputStart; - var remaining = length; - - var endBlock = end.Block; - var endIndex = end.Index; - - var outputOffset = 0; - while (true) - { - int following = (block != endBlock ? block.End : endIndex) - inputOffset; - - if (following > 0) - { - if (!AsciiUtilities.TryGetAsciiString(block.DataFixedPtr + inputOffset, output + outputOffset, following)) - { - throw BadHttpRequestException.GetException(RequestRejectionReason.NonAsciiOrNullCharactersInInputString); - } - - outputOffset += following; - remaining -= following; - } - - if (remaining == 0) - { - break; - } - - block = block.Next; - inputOffset = block.Start; - } - } - - return asciiString; - } - public static string GetAsciiStringEscaped(this MemoryPoolIterator start, MemoryPoolIterator end, int maxChars) { var sb = new StringBuilder(); @@ -147,102 +92,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure return sb.ToString(); } - public static string GetUtf8String(this MemoryPoolIterator start, MemoryPoolIterator end) - { - if (start.IsDefault || end.IsDefault) - { - return default(string); - } - if (end.Block == start.Block) - { - return _utf8.GetString(start.Block.Array, start.Index, end.Index - start.Index); - } - - var decoder = _utf8.GetDecoder(); - - var length = start.GetLength(end); - var charLength = length; - // Worse case is 1 byte = 1 char - var chars = new char[charLength]; - var charIndex = 0; - - var block = start.Block; - var index = start.Index; - var remaining = length; - while (true) - { - int bytesUsed; - int charsUsed; - bool completed; - var following = block.End - index; - if (remaining <= following) - { - decoder.Convert( - block.Array, - index, - remaining, - chars, - charIndex, - charLength - charIndex, - true, - out bytesUsed, - out charsUsed, - out completed); - return new string(chars, 0, charIndex + charsUsed); - } - else if (block.Next == null) - { - decoder.Convert( - block.Array, - index, - following, - chars, - charIndex, - charLength - charIndex, - true, - out bytesUsed, - out charsUsed, - out completed); - return new string(chars, 0, charIndex + charsUsed); - } - else - { - decoder.Convert( - block.Array, - index, - following, - chars, - charIndex, - charLength - charIndex, - false, - out bytesUsed, - out charsUsed, - out completed); - charIndex += charsUsed; - remaining -= following; - block = block.Next; - index = block.Start; - } - } - } - - public static ArraySegment GetArraySegment(this MemoryPoolIterator start, MemoryPoolIterator end) - { - if (start.IsDefault || end.IsDefault) - { - return default(ArraySegment); - } - if (end.Block == start.Block) - { - return new ArraySegment(start.Block.Array, start.Index, end.Index - start.Index); - } - - var length = start.GetLength(end); - var array = new byte[length]; - start.CopyTo(array, 0, length, out length); - return new ArraySegment(array, 0, length); - } - public static ArraySegment PeekArraySegment(this MemoryPoolIterator iter) { if (iter.IsDefault || iter.IsEnd) @@ -283,6 +132,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure /// The iterator from which to start the known string lookup. /// A reference to a pre-allocated known string, if the input matches any. /// true if the input matches a known string, false otherwise. + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool GetKnownMethod(this MemoryPoolIterator begin, out string knownMethod) { knownMethod = null; @@ -323,6 +173,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure /// The iterator from which to start the known string lookup. /// A reference to a pre-allocated known string, if the input matches any. /// true if the input matches a known string, false otherwise. + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool GetKnownVersion(this MemoryPoolIterator begin, out string knownVersion) { knownVersion = null; diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/AsciiDecoding.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/AsciiDecoding.cs index 87990788c6..220ae3d80b 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/AsciiDecoding.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/AsciiDecoding.cs @@ -22,7 +22,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var begin = mem.GetIterator(); var end = GetIterator(begin, byteRange.Length); - var s = begin.GetAsciiString(end); + var s = begin.GetAsciiString(ref end); Assert.Equal(s.Length, byteRange.Length); @@ -58,7 +58,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var begin = mem.GetIterator(); var end = GetIterator(begin, byteRange.Length); - Assert.Throws(() => begin.GetAsciiString(end)); + Assert.Throws(() => begin.GetAsciiString(ref end)); pool.Return(mem); } @@ -94,7 +94,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var begin = mem0.GetIterator(); var end = GetIterator(begin, expectedByteRange.Length); - var s = begin.GetAsciiString(end); + var s = begin.GetAsciiString(ref end); Assert.Equal(s.Length, expectedByteRange.Length); @@ -135,7 +135,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var begin = mem0.GetIterator(); var end = GetIterator(begin, expectedByteRange.Length); - var s = begin.GetAsciiString(end); + var s = begin.GetAsciiString(ref end); Assert.Equal(expectedByteRange.Length, s.Length); diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/UrlPathDecoder.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/UrlPathDecoder.cs index c33c8e5168..0acfc27fe8 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/UrlPathDecoder.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/UrlPathDecoder.cs @@ -167,7 +167,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var end = GetIterator(begin, rawLength); var end2 = UrlPathDecoder.Unescape(begin, end); - var result = begin.GetUtf8String(end2); + var result = begin.GetUtf8String(ref end2); Assert.Equal(expectLength, result.Length); Assert.Equal(expect, result); @@ -201,7 +201,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var end = GetIterator(begin, raw.Length); var result = UrlPathDecoder.Unescape(begin, end); - Assert.Equal(expect, begin.GetUtf8String(result)); + Assert.Equal(expect, begin.GetUtf8String(ref result)); } private void PositiveAssert(MemoryPoolBlock mem, string raw) @@ -210,7 +210,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var end = GetIterator(begin, raw.Length); var result = UrlPathDecoder.Unescape(begin, end); - Assert.NotEqual(raw.Length, begin.GetUtf8String(result).Length); + Assert.NotEqual(raw.Length, begin.GetUtf8String(ref result).Length); } private void NegativeAssert(MemoryPoolBlock mem, string raw) @@ -219,7 +219,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var end = GetIterator(begin, raw.Length); var resultEnd = UrlPathDecoder.Unescape(begin, end); - var result = begin.GetUtf8String(resultEnd); + var result = begin.GetUtf8String(ref resultEnd); Assert.Equal(raw, result); } } From 4cdcca212ed700bf3643f36dccde302f90c84f05 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Wed, 16 Nov 2016 04:56:45 +0000 Subject: [PATCH 0976/1662] Don't inline slow paths --- .../Infrastructure/MemoryPoolIterator.cs | 70 ++++++++++++++----- 1 file changed, 51 insertions(+), 19 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolIterator.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolIterator.cs index 78f782d39e..f562c9ae02 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolIterator.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolIterator.cs @@ -60,6 +60,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure } } + [MethodImpl(MethodImplOptions.NoInlining)] private bool IsEndMultiBlock() { var block = _block.Next; @@ -95,14 +96,17 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure return block.Array[index]; } - return TakeMultiBlock(block, index); + return TakeMultiBlock(); } - private int TakeMultiBlock(MemoryPoolBlock block, int index) + [MethodImpl(MethodImplOptions.NoInlining)] + private int TakeMultiBlock() { + var block = _block; var wasLastBlock = block.Next == null; do { + int index; if (wasLastBlock) { return -1; @@ -143,13 +147,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure SkipMultiBlock(bytesToSkip, following); } + [MethodImpl(MethodImplOptions.NoInlining)] private void SkipMultiBlock(int bytesToSkip, int following) { var wasLastBlock = _block.Next == null; var block = _block; - var index = _index; while (true) { + int index; if (wasLastBlock) { throw new InvalidOperationException("Attempted to skip more bytes than available."); @@ -189,14 +194,17 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure return block.Array[index]; } - return PeekMultiBlock(block, index); + return PeekMultiBlock(); } - private static int PeekMultiBlock(MemoryPoolBlock block, int index) + [MethodImpl(MethodImplOptions.NoInlining)] + private int PeekMultiBlock() { + var block = _block; var wasLastBlock = block.Next == null; do { + int index; if (wasLastBlock) { return -1; @@ -238,6 +246,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure return TryPeekLongMultiBlock(ref longValue, blockBytes); } + [MethodImpl(MethodImplOptions.NoInlining)] private unsafe bool TryPeekLongMultiBlock(ref ulong longValue, int blockBytes) { var wasLastBlock = _block.Next == null; @@ -780,6 +789,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure /// /// The byte to be saved. /// true if the operation successes. false if can't find available space. + [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Put(byte data) { if (_block == null) @@ -789,18 +799,26 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure var block = _block; var index = _index; - while (true) - { - var wasLastBlock = block.Next == null; - if (index < block.End) - { - _block = block; - _index = index + 1; - block.Array[index] = data; - return true; - } - else if (wasLastBlock) + if (index < block.End) + { + _index = index + 1; + block.Array[index] = data; + return true; + } + + return PutMultiBlock(data); + } + + [MethodImpl(MethodImplOptions.NoInlining)] + private bool PutMultiBlock(byte data) + { + var block = _block; + var wasLastBlock = block.Next == null; + do + { + int index; + if (wasLastBlock) { return false; } @@ -809,7 +827,19 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure block = block.Next; index = block.Start; } - } + + wasLastBlock = block.Next == null; + + if (index < block.End) + { + _block = block; + _index = index + 1; + block.Array[index] = data; + break; + } + } while (true); + + return true; } [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -825,10 +855,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure return end._index - _index; } - return GetLengthMultiBlock(end); + return GetLengthMultiBlock(ref end); } - public int GetLengthMultiBlock(MemoryPoolIterator end) + [MethodImpl(MethodImplOptions.NoInlining)] + public int GetLengthMultiBlock(ref MemoryPoolIterator end) { var block = _block; var index = _index; @@ -1179,6 +1210,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure return GetArraySegmentMultiBlock(ref end); } + [MethodImpl(MethodImplOptions.NoInlining)] private ArraySegment GetArraySegmentMultiBlock(ref MemoryPoolIterator end) { var length = GetLength(end); From 7ab44423920eb57f48ef1aff09d8dd7f8b8e1270 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Fri, 18 Nov 2016 23:30:12 +0000 Subject: [PATCH 0977/1662] Feedback + Cleanup --- .../Program.cs | 2 -- .../configs/CoreConfig.cs | 4 ---- .../configs/DefaultConfig.cs | 4 ---- .../helpers/MockKestrelTrace.cs | 3 --- .../Internal/Infrastructure/Constants.cs | 3 +++ .../Internal/Infrastructure/MemoryPoolIterator.cs | 5 ++--- .../Internal/Infrastructure/MemoryPoolIteratorExtensions.cs | 3 --- 7 files changed, 5 insertions(+), 19 deletions(-) diff --git a/perf/Microsoft.AspNetCore.Server.Kestrel.Performance/Program.cs b/perf/Microsoft.AspNetCore.Server.Kestrel.Performance/Program.cs index db29b584db..688771f622 100644 --- a/perf/Microsoft.AspNetCore.Server.Kestrel.Performance/Program.cs +++ b/perf/Microsoft.AspNetCore.Server.Kestrel.Performance/Program.cs @@ -43,6 +43,4 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance All = uint.MaxValue } - - } diff --git a/perf/Microsoft.AspNetCore.Server.Kestrel.Performance/configs/CoreConfig.cs b/perf/Microsoft.AspNetCore.Server.Kestrel.Performance/configs/CoreConfig.cs index eff6663fec..72056a28b4 100644 --- a/perf/Microsoft.AspNetCore.Server.Kestrel.Performance/configs/CoreConfig.cs +++ b/perf/Microsoft.AspNetCore.Server.Kestrel.Performance/configs/CoreConfig.cs @@ -3,7 +3,6 @@ using BenchmarkDotNet.Configs; using BenchmarkDotNet.Engines; -using BenchmarkDotNet.Environments; using BenchmarkDotNet.Jobs; using BenchmarkDotNet.Validators; @@ -17,10 +16,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance Add(new RpsColumn()); Add(Job.Default. - With(Platform.X64). - With(Jit.RyuJit). With(BenchmarkDotNet.Environments.Runtime.Core). - WithRemoveOutliers(true). With(new GcMode() { Server = true }). With(RunStrategy.Throughput). WithLaunchCount(3). diff --git a/perf/Microsoft.AspNetCore.Server.Kestrel.Performance/configs/DefaultConfig.cs b/perf/Microsoft.AspNetCore.Server.Kestrel.Performance/configs/DefaultConfig.cs index 01f30373c4..6b2670302c 100644 --- a/perf/Microsoft.AspNetCore.Server.Kestrel.Performance/configs/DefaultConfig.cs +++ b/perf/Microsoft.AspNetCore.Server.Kestrel.Performance/configs/DefaultConfig.cs @@ -20,7 +20,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance With(Platform.X64). With(Jit.RyuJit). With(BenchmarkDotNet.Environments.Runtime.Clr). - WithRemoveOutliers(true). With(new GcMode() { Server = true }). With(RunStrategy.Throughput). WithLaunchCount(3). @@ -28,10 +27,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance WithTargetCount(10)); Add(Job.Default. - With(Platform.X64). - With(Jit.RyuJit). With(BenchmarkDotNet.Environments.Runtime.Core). - WithRemoveOutliers(true). With(new GcMode() { Server = true }). With(RunStrategy.Throughput). WithLaunchCount(3). diff --git a/perf/Microsoft.AspNetCore.Server.Kestrel.Performance/helpers/MockKestrelTrace.cs b/perf/Microsoft.AspNetCore.Server.Kestrel.Performance/helpers/MockKestrelTrace.cs index 9e035010d3..5d5bf38201 100644 --- a/perf/Microsoft.AspNetCore.Server.Kestrel.Performance/helpers/MockKestrelTrace.cs +++ b/perf/Microsoft.AspNetCore.Server.Kestrel.Performance/helpers/MockKestrelTrace.cs @@ -20,17 +20,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance public override void ConnectionRead(string connectionId, int count) { - //_logger.LogDebug(1, @"Connection id ""{ConnectionId}"" recv {count} bytes.", connectionId, count); } public override void ConnectionWrite(string connectionId, int count) { - //_logger.LogDebug(1, @"Connection id ""{ConnectionId}"" send {count} bytes.", connectionId, count); } public override void ConnectionWriteCallback(string connectionId, int status) { - //_logger.LogDebug(1, @"Connection id ""{ConnectionId}"" send finished with status {status}.", connectionId, status); } } } \ No newline at end of file diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/Constants.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/Constants.cs index 77968bca17..32267912e0 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/Constants.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/Constants.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Runtime.InteropServices; +using System.Text; namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure { @@ -13,6 +14,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure public static readonly int? ECONNRESET = GetECONNRESET(); public static readonly int? EADDRINUSE = GetEADDRINUSE(); + public static readonly Encoding UTF8 = Encoding.UTF8; + /// /// Prefix of host name used to specify Unix sockets in the configuration. /// diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolIterator.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolIterator.cs index f562c9ae02..9f18b75465 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolIterator.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolIterator.cs @@ -21,7 +21,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure 0x02ul << 40 | 0x01ul << 48 ) + 1; - private static readonly Encoding _utf8 = Encoding.UTF8; private static readonly int _vectorSpan = Vector.Count; private MemoryPoolBlock _block; @@ -1124,10 +1123,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure } if (end.Block == Block) { - return _utf8.GetString(Block.Array, Index, end.Index - Index); + return Constants.UTF8.GetString(Block.Array, Index, end.Index - Index); } - var decoder = _utf8.GetDecoder(); + var decoder = Constants.UTF8.GetDecoder(); var length = GetLength(end); var charLength = length; diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolIteratorExtensions.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolIteratorExtensions.cs index 0b7e988af3..1839d3309f 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolIteratorExtensions.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolIteratorExtensions.cs @@ -6,14 +6,11 @@ using System.Diagnostics; using System.Runtime.CompilerServices; using System.Text; using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure { public static class MemoryPoolIteratorExtensions { - private static readonly Encoding _utf8 = Encoding.UTF8; - public const string Http10Version = "HTTP/1.0"; public const string Http11Version = "HTTP/1.1"; From 5041d6c2918ff6d9e4b4bc3aab8a6e0796c32fa8 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Sat, 19 Nov 2016 04:32:42 +0000 Subject: [PATCH 0978/1662] wasLastBlock adjustments --- .../Internal/Infrastructure/Constants.cs | 2 - .../Infrastructure/MemoryPoolIterator.cs | 197 +++++++++--------- 2 files changed, 103 insertions(+), 96 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/Constants.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/Constants.cs index 32267912e0..3acb659218 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/Constants.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/Constants.cs @@ -14,8 +14,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure public static readonly int? ECONNRESET = GetECONNRESET(); public static readonly int? EADDRINUSE = GetEADDRINUSE(); - public static readonly Encoding UTF8 = Encoding.UTF8; - /// /// Prefix of host name used to specify Unix sockets in the configuration. /// diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolIterator.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolIterator.cs index 9f18b75465..7c7e0865e8 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolIterator.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolIterator.cs @@ -44,14 +44,19 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure [MethodImpl(MethodImplOptions.AggressiveInlining)] get { - if (_block == null) + var block = _block; + if (block == null) { return true; } - else if (_index < _block.End) + else if (_index < block.End) { return false; } + else if (block.Next == null) + { + return true; + } else { return IsEndMultiBlock(); @@ -63,14 +68,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure private bool IsEndMultiBlock() { var block = _block.Next; - while (block != null) + do { if (block.Start < block.End) { return false; // subsequent block has data - IsEnd is false } block = block.Next; - } + } while (block != null); + return true; } @@ -88,6 +94,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure } var index = _index; + // Always set wasLastBlock before checking .End to avoid race which may cause data loss + var wasLastBlock = block.Next == null; if (index < block.End) { @@ -95,28 +103,20 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure return block.Array[index]; } - return TakeMultiBlock(); + return wasLastBlock ? -1 : TakeMultiBlock(); } [MethodImpl(MethodImplOptions.NoInlining)] private int TakeMultiBlock() { var block = _block; - var wasLastBlock = block.Next == null; do { - int index; - if (wasLastBlock) - { - return -1; - } - else - { - block = block.Next; - index = block.Start; - } + block = block.Next; + var index = block.Start; - wasLastBlock = block.Next == null; + // Always set wasLastBlock before checking .End to avoid race which may cause data loss + var wasLastBlock = block.Next == null; if (index < block.End) { @@ -124,18 +124,26 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure _index = index + 1; return block.Array[index]; } + + if (wasLastBlock) + { + return -1; + } } while (true); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Skip(int bytesToSkip) { - if (_block == null) + var block = _block; + if (block == null) { return; } - var following = _block.End - _index; + // Always set wasLastBlock before checking .End to avoid race which may cause data loss + var wasLastBlock = block.Next == null; + var following = block.End - _index; if (following >= bytesToSkip) { @@ -143,29 +151,26 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure return; } + if (wasLastBlock) + { + ThrowInvalidOperationException_SkipMoreThanAvailable(); + } + SkipMultiBlock(bytesToSkip, following); } [MethodImpl(MethodImplOptions.NoInlining)] private void SkipMultiBlock(int bytesToSkip, int following) { - var wasLastBlock = _block.Next == null; var block = _block; - while (true) + do { - int index; - if (wasLastBlock) - { - throw new InvalidOperationException("Attempted to skip more bytes than available."); - } - else - { - bytesToSkip -= following; - block = block.Next; - index = block.Start; - } + bytesToSkip -= following; + block = block.Next; + var index = block.Start; - wasLastBlock = block.Next == null; + // Always set wasLastBlock before checking .End to avoid race which may cause data loss + var wasLastBlock = block.Next == null; following = block.End - index; if (following >= bytesToSkip) @@ -174,7 +179,17 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure _index = index + bytesToSkip; return; } - } + + if (wasLastBlock) + { + ThrowInvalidOperationException_SkipMoreThanAvailable(); + } + } while (true); + } + + private static void ThrowInvalidOperationException_SkipMoreThanAvailable() + { + throw new InvalidOperationException("Attempted to skip more bytes than available."); } [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -188,38 +203,36 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure var index = _index; + // Always set wasLastBlock before checking .End to avoid race which may cause data loss + var wasLastBlock = block.Next == null; if (index < block.End) { return block.Array[index]; } - return PeekMultiBlock(); + return wasLastBlock ? -1 : PeekMultiBlock(); } [MethodImpl(MethodImplOptions.NoInlining)] private int PeekMultiBlock() { var block = _block; - var wasLastBlock = block.Next == null; do { - int index; - if (wasLastBlock) - { - return -1; - } - else - { - block = block.Next; - index = block.Start; - } + block = block.Next; + var index = block.Start; - wasLastBlock = block.Next == null; + // Always set wasLastBlock before checking .End to avoid race which may cause data loss + var wasLastBlock = block.Next == null; if (index < block.End) { return block.Array[index]; } + if (wasLastBlock) + { + return -1; + } } while (true); } @@ -229,60 +242,57 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure { longValue = 0; - if (_block == null) + var block = _block; + if (block == null) { return false; } - var blockBytes = _block.End - _index; + // Always set wasLastBlock before checking .End to avoid race which may cause data loss + var wasLastBlock = block.Next == null; + var blockBytes = block.End - _index; if (blockBytes >= sizeof(ulong)) { - longValue = *(ulong*)(_block.DataFixedPtr + _index); + longValue = *(ulong*)(block.DataFixedPtr + _index); return true; } - return TryPeekLongMultiBlock(ref longValue, blockBytes); + // wasLastBlock ? false : TryPeekLongMultiBlock(ref longValue, blockBytes); + return !wasLastBlock && TryPeekLongMultiBlock(ref longValue, blockBytes); } [MethodImpl(MethodImplOptions.NoInlining)] private unsafe bool TryPeekLongMultiBlock(ref ulong longValue, int blockBytes) { - var wasLastBlock = _block.Next == null; - if (wasLastBlock) + // Each block will be filled with at least 2048 bytes before the Next pointer is set, so a long + // will cross at most one block boundary assuming there are at least 8 bytes following the iterator. + var nextBytes = sizeof(ulong) - blockBytes; + + var block = _block; + if (block.Next.End - block.Next.Start < nextBytes) { return false; } + + var nextLong = *(ulong*)(block.Next.DataFixedPtr + block.Next.Start); + + if (blockBytes == 0) + { + // This case can not fall through to the else block since that would cause a 64-bit right shift + // on blockLong which is equivalent to no shift at all instead of shifting in all zeros. + // https://msdn.microsoft.com/en-us/library/xt18et0d.aspx + longValue = nextLong; + } else { - // Each block will be filled with at least 2048 bytes before the Next pointer is set, so a long - // will cross at most one block boundary assuming there are at least 8 bytes following the iterator. - var nextBytes = sizeof(ulong) - blockBytes; + var blockLong = *(ulong*)(block.DataFixedPtr + block.End - sizeof(ulong)); - if (_block.Next.End - _block.Next.Start < nextBytes) - { - return false; - } - - var nextLong = *(ulong*)(_block.Next.DataFixedPtr + _block.Next.Start); - - if (blockBytes == 0) - { - // This case can not fall through to the else block since that would cause a 64-bit right shift - // on blockLong which is equivalent to no shift at all instead of shifting in all zeros. - // https://msdn.microsoft.com/en-us/library/xt18et0d.aspx - longValue = nextLong; - } - else - { - var blockLong = *(ulong*)(_block.DataFixedPtr + _block.End - sizeof(ulong)); - - // Ensure that the right shift has a ulong operand so a logical shift is performed. - longValue = (blockLong >> nextBytes * 8) | (nextLong << blockBytes * 8); - } - - return true; + // Ensure that the right shift has a ulong operand so a logical shift is performed. + longValue = (blockLong >> nextBytes * 8) | (nextLong << blockBytes * 8); } + + return true; } public int Seek(byte byte0) @@ -799,6 +809,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure var block = _block; var index = _index; + // Always set wasLastBlock before checking .End to avoid race which may cause data loss + var wasLastBlock = block.Next == null; if (index < block.End) { _index = index + 1; @@ -806,28 +818,21 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure return true; } - return PutMultiBlock(data); + // wasLastBlock ? false : PutMultiBlock(data); + return !wasLastBlock && PutMultiBlock(data); } [MethodImpl(MethodImplOptions.NoInlining)] private bool PutMultiBlock(byte data) { var block = _block; - var wasLastBlock = block.Next == null; do { - int index; - if (wasLastBlock) - { - return false; - } - else - { - block = block.Next; - index = block.Start; - } + block = block.Next; + var index = block.Start; - wasLastBlock = block.Next == null; + // Always set wasLastBlock before checking .End to avoid race which may cause data loss + var wasLastBlock = block.Next == null; if (index < block.End) { @@ -836,6 +841,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure block.Array[index] = data; break; } + if (wasLastBlock) + { + return false; + } } while (true); return true; @@ -1123,10 +1132,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure } if (end.Block == Block) { - return Constants.UTF8.GetString(Block.Array, Index, end.Index - Index); + return Encoding.UTF8.GetString(Block.Array, Index, end.Index - Index); } - var decoder = Constants.UTF8.GetDecoder(); + var decoder = Encoding.UTF8.GetDecoder(); var length = GetLength(end); var charLength = length; From 8ce47fb8b64ace860e0d0167eba89dd45f0dcad5 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Sat, 19 Nov 2016 04:33:08 +0000 Subject: [PATCH 0979/1662] Move perf, share code --- KestrelHttpServer.sln | 9 ++-- global.json | 2 +- .../configs/DefaultConfig.cs | 38 -------------- .../helpers/MockApplicationErrorLogger.cs | 51 ------------------- .../helpers/MockConnectionControl.cs | 34 ------------- .../helpers/MockKestrelTrace.cs | 33 ------------ .../helpers/SocketInputExtensions.cs | 37 -------------- .../project.json | 29 ----------- .../Properties/AssemblyInfo.cs | 1 + ...spNetCore.Server.Kestrel.Performance.xproj | 0 .../Program.cs | 4 ++ .../Readme.md | 4 +- .../RequestParsing.cs | 21 ++------ .../columns/RpsColumn.cs | 0 .../configs/CoreConfig.cs | 1 + .../global.json | 3 ++ .../project.json | 42 +++++++++++++++ .../TestHelpers => shared}/MockConnection.cs | 5 +- .../SocketInputExtensions.cs | 0 19 files changed, 68 insertions(+), 246 deletions(-) delete mode 100644 perf/Microsoft.AspNetCore.Server.Kestrel.Performance/configs/DefaultConfig.cs delete mode 100644 perf/Microsoft.AspNetCore.Server.Kestrel.Performance/helpers/MockApplicationErrorLogger.cs delete mode 100644 perf/Microsoft.AspNetCore.Server.Kestrel.Performance/helpers/MockConnectionControl.cs delete mode 100644 perf/Microsoft.AspNetCore.Server.Kestrel.Performance/helpers/MockKestrelTrace.cs delete mode 100644 perf/Microsoft.AspNetCore.Server.Kestrel.Performance/helpers/SocketInputExtensions.cs delete mode 100644 perf/Microsoft.AspNetCore.Server.Kestrel.Performance/project.json rename {perf => test}/Microsoft.AspNetCore.Server.Kestrel.Performance/Microsoft.AspNetCore.Server.Kestrel.Performance.xproj (100%) rename {perf => test}/Microsoft.AspNetCore.Server.Kestrel.Performance/Program.cs (90%) rename {perf => test}/Microsoft.AspNetCore.Server.Kestrel.Performance/Readme.md (60%) rename {perf => test}/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsing.cs (90%) rename {perf => test}/Microsoft.AspNetCore.Server.Kestrel.Performance/columns/RpsColumn.cs (100%) rename {perf => test}/Microsoft.AspNetCore.Server.Kestrel.Performance/configs/CoreConfig.cs (95%) create mode 100644 test/Microsoft.AspNetCore.Server.Kestrel.Performance/global.json create mode 100644 test/Microsoft.AspNetCore.Server.Kestrel.Performance/project.json rename test/{Microsoft.AspNetCore.Server.KestrelTests/TestHelpers => shared}/MockConnection.cs (90%) rename test/{Microsoft.AspNetCore.Server.KestrelTests/TestHelpers => shared}/SocketInputExtensions.cs (100%) diff --git a/KestrelHttpServer.sln b/KestrelHttpServer.sln index e6dca6eac9..d78ceec5ad 100644 --- a/KestrelHttpServer.sln +++ b/KestrelHttpServer.sln @@ -37,7 +37,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "shared", "shared", "{0EF2AC test\shared\DummyApplication.cs = test\shared\DummyApplication.cs test\shared\HttpClientSlim.cs = test\shared\HttpClientSlim.cs test\shared\LifetimeNotImplemented.cs = test\shared\LifetimeNotImplemented.cs + test\shared\MockConnection.cs = test\shared\MockConnection.cs + test\shared\MockFrameControl.cs = test\shared\MockFrameControl.cs test\shared\MockSystemClock.cs = test\shared\MockSystemClock.cs + test\shared\SocketInputExtensions.cs = test\shared\SocketInputExtensions.cs test\shared\TestApplicationErrorLogger.cs = test\shared\TestApplicationErrorLogger.cs test\shared\TestConnection.cs = test\shared\TestConnection.cs test\shared\TestKestrelTrace.cs = test\shared\TestKestrelTrace.cs @@ -45,9 +48,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "shared", "shared", "{0EF2AC test\shared\TestServiceContext.cs = test\shared\TestServiceContext.cs EndProjectSection EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "perf", "perf", "{21B17FBB-5A58-42A8-8473-43160509A9FF}" -EndProject -Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNetCore.Server.Kestrel.Performance", "perf\Microsoft.AspNetCore.Server.Kestrel.Performance\Microsoft.AspNetCore.Server.Kestrel.Performance.xproj", "{70567566-524C-4B67-9B59-E5C206D6C2EB}" +Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNetCore.Server.Kestrel.Performance", "test\Microsoft.AspNetCore.Server.Kestrel.Performance\Microsoft.AspNetCore.Server.Kestrel.Performance.xproj", "{70567566-524C-4B67-9B59-E5C206D6C2EB}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -100,6 +101,6 @@ Global {5F64B3C3-0C2E-431A-B820-A81BBFC863DA} = {2D5D5227-4DBD-499A-96B1-76A36B03B750} {9559A5F1-080C-4909-B6CF-7E4B3DC55748} = {D3273454-EA07-41D2-BF0B-FCC3675C2483} {0EF2ACDF-012F-4472-A13A-4272419E2903} = {D3273454-EA07-41D2-BF0B-FCC3675C2483} - {70567566-524C-4B67-9B59-E5C206D6C2EB} = {21B17FBB-5A58-42A8-8473-43160509A9FF} + {70567566-524C-4B67-9B59-E5C206D6C2EB} = {D3273454-EA07-41D2-BF0B-FCC3675C2483} EndGlobalSection EndGlobal diff --git a/global.json b/global.json index c0415c19af..d9b4ed63ae 100644 --- a/global.json +++ b/global.json @@ -1,3 +1,3 @@ { - "projects": ["src", "perf"] + "projects": [ "src" ] } diff --git a/perf/Microsoft.AspNetCore.Server.Kestrel.Performance/configs/DefaultConfig.cs b/perf/Microsoft.AspNetCore.Server.Kestrel.Performance/configs/DefaultConfig.cs deleted file mode 100644 index 6b2670302c..0000000000 --- a/perf/Microsoft.AspNetCore.Server.Kestrel.Performance/configs/DefaultConfig.cs +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using BenchmarkDotNet.Configs; -using BenchmarkDotNet.Engines; -using BenchmarkDotNet.Environments; -using BenchmarkDotNet.Jobs; -using BenchmarkDotNet.Validators; - -namespace Microsoft.AspNetCore.Server.Kestrel.Performance -{ - public class DefaultConfig : ManualConfig - { - public DefaultConfig() - { - Add(JitOptimizationsValidator.FailOnError); - Add(new RpsColumn()); - - Add(Job.Default. - With(Platform.X64). - With(Jit.RyuJit). - With(BenchmarkDotNet.Environments.Runtime.Clr). - With(new GcMode() { Server = true }). - With(RunStrategy.Throughput). - WithLaunchCount(3). - WithWarmupCount(5). - WithTargetCount(10)); - - Add(Job.Default. - With(BenchmarkDotNet.Environments.Runtime.Core). - With(new GcMode() { Server = true }). - With(RunStrategy.Throughput). - WithLaunchCount(3). - WithWarmupCount(5). - WithTargetCount(10)); - } - } -} diff --git a/perf/Microsoft.AspNetCore.Server.Kestrel.Performance/helpers/MockApplicationErrorLogger.cs b/perf/Microsoft.AspNetCore.Server.Kestrel.Performance/helpers/MockApplicationErrorLogger.cs deleted file mode 100644 index c126eba79c..0000000000 --- a/perf/Microsoft.AspNetCore.Server.Kestrel.Performance/helpers/MockApplicationErrorLogger.cs +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using System.Collections.Generic; -using System.Linq; -using Microsoft.AspNetCore.Server.Kestrel.Internal; -using Microsoft.Extensions.Logging; - -namespace Microsoft.AspNetCore.Server.Kestrel.Performance -{ - public class MockApplicationErrorLogger : ILogger - { - // Application errors are logged using 13 as the eventId. - private const int ApplicationErrorEventId = 13; - - public List Messages { get; } = new List(); - - public int TotalErrorsLogged => Messages.Count(message => message.LogLevel == LogLevel.Error); - - public int CriticalErrorsLogged => Messages.Count(message => message.LogLevel == LogLevel.Critical); - - public int ApplicationErrorsLogged => Messages.Count(message => message.EventId.Id == ApplicationErrorEventId); - - public IDisposable BeginScope(TState state) - { - return new Disposable(() => { }); - } - - public bool IsEnabled(LogLevel logLevel) - { - return true; - } - - public void Log(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func formatter) - { -#if false - Console.WriteLine($"Log {logLevel}[{eventId}]: {formatter(state, exception)} {exception?.Message}"); -#endif - - Messages.Add(new LogMessage { LogLevel = logLevel, EventId = eventId, Exception = exception }); - } - - public class LogMessage - { - public LogLevel LogLevel { get; set; } - public EventId EventId { get; set; } - public Exception Exception { get; set; } - } - } -} diff --git a/perf/Microsoft.AspNetCore.Server.Kestrel.Performance/helpers/MockConnectionControl.cs b/perf/Microsoft.AspNetCore.Server.Kestrel.Performance/helpers/MockConnectionControl.cs deleted file mode 100644 index b3587d81db..0000000000 --- a/perf/Microsoft.AspNetCore.Server.Kestrel.Performance/helpers/MockConnectionControl.cs +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; - -namespace Microsoft.AspNetCore.Server.Kestrel.Performance -{ - public class MockConnectionControl : IConnectionControl - { - public void CancelTimeout() - { - } - - public void End(ProduceEndType endType) - { - } - - public void Pause() - { - } - - public void ResetTimeout(long milliseconds, TimeoutAction timeoutAction) - { - } - - public void Resume() - { - } - - public void SetTimeout(long milliseconds, TimeoutAction timeoutAction) - { - } - } -} diff --git a/perf/Microsoft.AspNetCore.Server.Kestrel.Performance/helpers/MockKestrelTrace.cs b/perf/Microsoft.AspNetCore.Server.Kestrel.Performance/helpers/MockKestrelTrace.cs deleted file mode 100644 index 5d5bf38201..0000000000 --- a/perf/Microsoft.AspNetCore.Server.Kestrel.Performance/helpers/MockKestrelTrace.cs +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using Microsoft.AspNetCore.Server.Kestrel.Internal; - -namespace Microsoft.AspNetCore.Server.Kestrel.Performance -{ - public class MockKestrelTrace : KestrelTrace - { - public MockKestrelTrace() : this(new MockApplicationErrorLogger()) - { - } - - public MockKestrelTrace(MockApplicationErrorLogger testLogger) : base(testLogger) - { - Logger = testLogger; - } - - public MockApplicationErrorLogger Logger { get; private set; } - - public override void ConnectionRead(string connectionId, int count) - { - } - - public override void ConnectionWrite(string connectionId, int count) - { - } - - public override void ConnectionWriteCallback(string connectionId, int status) - { - } - } -} \ No newline at end of file diff --git a/perf/Microsoft.AspNetCore.Server.Kestrel.Performance/helpers/SocketInputExtensions.cs b/perf/Microsoft.AspNetCore.Server.Kestrel.Performance/helpers/SocketInputExtensions.cs deleted file mode 100644 index af26c2994c..0000000000 --- a/perf/Microsoft.AspNetCore.Server.Kestrel.Performance/helpers/SocketInputExtensions.cs +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; - -namespace Microsoft.AspNetCore.Server.Kestrel.Performance -{ - public static class SocketInputExtensions - { - public static void IncomingData(this SocketInput input, byte[] buffer, int offset, int count) - { - var bufferIndex = offset; - var remaining = count; - - while (remaining > 0) - { - var block = input.IncomingStart(); - - var bytesLeftInBlock = block.Data.Offset + block.Data.Count - block.End; - var bytesToCopy = remaining < bytesLeftInBlock ? remaining : bytesLeftInBlock; - - Buffer.BlockCopy(buffer, bufferIndex, block.Array, block.End, bytesToCopy); - - bufferIndex += bytesToCopy; - remaining -= bytesToCopy; - - input.IncomingComplete(bytesToCopy, null); - } - } - - public static void IncomingFin(this SocketInput input) - { - input.IncomingComplete(0, null); - } - } -} diff --git a/perf/Microsoft.AspNetCore.Server.Kestrel.Performance/project.json b/perf/Microsoft.AspNetCore.Server.Kestrel.Performance/project.json deleted file mode 100644 index 38bb58ec76..0000000000 --- a/perf/Microsoft.AspNetCore.Server.Kestrel.Performance/project.json +++ /dev/null @@ -1,29 +0,0 @@ -{ - "version": "1.0.0-*", - "buildOptions": { - "emitEntryPoint": true - }, - - "dependencies": { - "BenchmarkDotNet": "0.10.0", - "Microsoft.AspNetCore.Server.Kestrel": "1.2.0-*" - }, - - "frameworks": { - "net46": {}, - "netcoreapp1.0": { - "dependencies": { - "Microsoft.NETCore.App": { - "version": "1.0.1-*", - "type": "platform" - } - } - } - }, - - "runtimeOptions": { - "configProperties": { - "System.GC.Server": true - } - } -} \ No newline at end of file diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Properties/AssemblyInfo.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Properties/AssemblyInfo.cs index 8989a4b649..86b8eff609 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Properties/AssemblyInfo.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Properties/AssemblyInfo.cs @@ -7,6 +7,7 @@ using System.Runtime.CompilerServices; [assembly: InternalsVisibleTo("Microsoft.AspNetCore.Server.Kestrel.FunctionalTests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")] [assembly: InternalsVisibleTo("Microsoft.AspNetCore.Server.KestrelTests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")] +[assembly: InternalsVisibleTo("Microsoft.AspNetCore.Server.Kestrel.Performance, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")] [assembly: AssemblyMetadata("Serviceable", "True")] [assembly: NeutralResourcesLanguage("en-us")] [assembly: AssemblyCompany("Microsoft Corporation.")] diff --git a/perf/Microsoft.AspNetCore.Server.Kestrel.Performance/Microsoft.AspNetCore.Server.Kestrel.Performance.xproj b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Microsoft.AspNetCore.Server.Kestrel.Performance.xproj similarity index 100% rename from perf/Microsoft.AspNetCore.Server.Kestrel.Performance/Microsoft.AspNetCore.Server.Kestrel.Performance.xproj rename to test/Microsoft.AspNetCore.Server.Kestrel.Performance/Microsoft.AspNetCore.Server.Kestrel.Performance.xproj diff --git a/perf/Microsoft.AspNetCore.Server.Kestrel.Performance/Program.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Program.cs similarity index 90% rename from perf/Microsoft.AspNetCore.Server.Kestrel.Performance/Program.cs rename to test/Microsoft.AspNetCore.Server.Kestrel.Performance/Program.cs index 688771f622..b627755d76 100644 --- a/perf/Microsoft.AspNetCore.Server.Kestrel.Performance/Program.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Program.cs @@ -2,7 +2,11 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using BenchmarkDotNet.Environments; +using BenchmarkDotNet.Jobs; +using BenchmarkDotNet.Properties; using BenchmarkDotNet.Running; +using BenchmarkDotNet.Toolchains; namespace Microsoft.AspNetCore.Server.Kestrel.Performance { diff --git a/perf/Microsoft.AspNetCore.Server.Kestrel.Performance/Readme.md b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Readme.md similarity index 60% rename from perf/Microsoft.AspNetCore.Server.Kestrel.Performance/Readme.md rename to test/Microsoft.AspNetCore.Server.Kestrel.Performance/Readme.md index 4088c38007..b98f36ff5c 100644 --- a/perf/Microsoft.AspNetCore.Server.Kestrel.Performance/Readme.md +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Readme.md @@ -2,10 +2,10 @@ To run a specific benchmark add it as parameter ``` -dotnet run -c Release RequestParsing +dotnet run RequestParsing ``` To run all use `All` as parameter ``` -dotnet run -c Release All +dotnet run All ``` Using no parameter will list all available benchmarks \ No newline at end of file diff --git a/perf/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsing.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsing.cs similarity index 90% rename from perf/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsing.cs rename to test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsing.cs index b1bdbe16f9..7388c547a2 100644 --- a/perf/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsing.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsing.cs @@ -8,6 +8,8 @@ using BenchmarkDotNet.Attributes; using Microsoft.AspNetCore.Server.Kestrel.Internal; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; +using Microsoft.AspNetCore.Server.KestrelTests.TestHelpers; +using Microsoft.AspNetCore.Testing; using RequestLineStatus = Microsoft.AspNetCore.Server.Kestrel.Internal.Http.Frame.RequestLineStatus; namespace Microsoft.AspNetCore.Server.Kestrel.Performance @@ -165,26 +167,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance [Setup] public void Setup() { - Trace = new KestrelTrace(new MockKestrelTrace()); + Trace = new KestrelTrace(new TestKestrelTrace()); ThreadPool = new LoggingThreadPool(Trace); MemoryPool = new MemoryPool(); SocketInput = new SocketInput(MemoryPool, ThreadPool); - var serviceContext = new ServiceContext - { - DateHeaderValueManager = new DateHeaderValueManager(), - ServerOptions = new KestrelServerOptions(), - Log = Trace - }; - var listenerContext = new ListenerContext(serviceContext) - { - ServerAddress = ServerAddress.FromUrl("http://localhost:5000") - }; - var connectionContext = new ConnectionContext(listenerContext) - { - ConnectionControl = new MockConnectionControl(), - SocketInput = SocketInput - }; + var connectionContext = new MockConnection(new KestrelServerOptions()); + connectionContext.SocketInput = SocketInput; Frame = new Frame(application: null, context: connectionContext); } diff --git a/perf/Microsoft.AspNetCore.Server.Kestrel.Performance/columns/RpsColumn.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/columns/RpsColumn.cs similarity index 100% rename from perf/Microsoft.AspNetCore.Server.Kestrel.Performance/columns/RpsColumn.cs rename to test/Microsoft.AspNetCore.Server.Kestrel.Performance/columns/RpsColumn.cs diff --git a/perf/Microsoft.AspNetCore.Server.Kestrel.Performance/configs/CoreConfig.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/configs/CoreConfig.cs similarity index 95% rename from perf/Microsoft.AspNetCore.Server.Kestrel.Performance/configs/CoreConfig.cs rename to test/Microsoft.AspNetCore.Server.Kestrel.Performance/configs/CoreConfig.cs index 72056a28b4..efdf192205 100644 --- a/perf/Microsoft.AspNetCore.Server.Kestrel.Performance/configs/CoreConfig.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/configs/CoreConfig.cs @@ -17,6 +17,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance Add(Job.Default. With(BenchmarkDotNet.Environments.Runtime.Core). + WithRemoveOutliers(false). With(new GcMode() { Server = true }). With(RunStrategy.Throughput). WithLaunchCount(3). diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/global.json b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/global.json new file mode 100644 index 0000000000..33f0f54e92 --- /dev/null +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/global.json @@ -0,0 +1,3 @@ +{ + "projects": [ "..\\" ] +} diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/project.json b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/project.json new file mode 100644 index 0000000000..a74be5fefb --- /dev/null +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/project.json @@ -0,0 +1,42 @@ +{ + "version": "1.0.0-*", + "dependencies": { + "BenchmarkDotNet": "0.10.0", + "Microsoft.AspNetCore.Server.Kestrel": "1.2.0-*" + }, + "frameworks": { + "netcoreapp1.0": { + "dependencies": { + "Microsoft.NETCore.App": { + "version": "1.0.1-*", + "type": "platform" + } + } + } + }, + "buildOptions": { + "emitEntryPoint": true, + "compile": { + "include": [ + "../shared/SocketInputExtensions.cs", + "../shared/TestKestrelTrace.cs", + "../shared/TestApplicationErrorLogger.cs", + "../shared/MockConnection.cs" + ] + }, + "keyFile": "../../tools/Key.snk", + "copyToOutput": { + "include": "TestResources/testCert.pfx" + } + }, + "runtimeOptions": { + "configProperties": { + "System.GC.Server": true + } + }, + "publishOptions": { + "include": [ + "TestResources/testCert.pfx" + ] + } +} \ No newline at end of file diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockConnection.cs b/test/shared/MockConnection.cs similarity index 90% rename from test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockConnection.cs rename to test/shared/MockConnection.cs index ee781a3935..a782f51ffd 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockConnection.cs +++ b/test/shared/MockConnection.cs @@ -18,7 +18,10 @@ namespace Microsoft.AspNetCore.Server.KestrelTests.TestHelpers { ConnectionControl = this; RequestAbortedSource = new CancellationTokenSource(); - ListenerContext = new ListenerContext(new ServiceContext { ServerOptions = options }); + ListenerContext = new ListenerContext(new ServiceContext {ServerOptions = options}) + { + ServerAddress = ServerAddress.FromUrl("http://localhost:5000") + }; } public override void Abort(Exception error = null) diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/SocketInputExtensions.cs b/test/shared/SocketInputExtensions.cs similarity index 100% rename from test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/SocketInputExtensions.cs rename to test/shared/SocketInputExtensions.cs From 2011a27bde7f2363b231f607c33355a84a3e9ab2 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Sat, 19 Nov 2016 05:10:16 +0000 Subject: [PATCH 0980/1662] Use ternary op rather than lazy and --- .../Internal/Infrastructure/MemoryPoolIterator.cs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolIterator.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolIterator.cs index 7c7e0865e8..97b71e3a2d 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolIterator.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolIterator.cs @@ -258,8 +258,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure return true; } - // wasLastBlock ? false : TryPeekLongMultiBlock(ref longValue, blockBytes); - return !wasLastBlock && TryPeekLongMultiBlock(ref longValue, blockBytes); + return wasLastBlock ? false : TryPeekLongMultiBlock(ref longValue, blockBytes); } [MethodImpl(MethodImplOptions.NoInlining)] @@ -818,8 +817,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure return true; } - // wasLastBlock ? false : PutMultiBlock(data); - return !wasLastBlock && PutMultiBlock(data); + return wasLastBlock ? false : PutMultiBlock(data); } [MethodImpl(MethodImplOptions.NoInlining)] From ef5ad3deeaaec690cf0ee315e11d75b35f220ec7 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Sat, 19 Nov 2016 12:37:11 +0000 Subject: [PATCH 0981/1662] defaullt(MemoryPoolIterator) test coverage --- .../Infrastructure/MemoryPoolIterator.cs | 81 ++++++++++--------- .../MemoryPoolIteratorTests.cs | 28 +++++++ 2 files changed, 70 insertions(+), 39 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolIterator.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolIterator.cs index 97b71e3a2d..4cceb50bf7 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolIterator.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolIterator.cs @@ -136,9 +136,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure public void Skip(int bytesToSkip) { var block = _block; - if (block == null) + if (block == null && bytesToSkip > 0) { - return; + ThrowInvalidOperationException_SkipMoreThanAvailable(); } // Always set wasLastBlock before checking .End to avoid race which may cause data loss @@ -307,12 +307,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure { bytesScanned = 0; - if (IsDefault || limit <= 0) + var block = _block; + if (block == null || limit <= 0) { return -1; } - var block = _block; var index = _index; var wasLastBlock = block.Next == null; var following = block.End - index; @@ -413,12 +413,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure byte byte0, ref MemoryPoolIterator limit) { - if (IsDefault) + var block = _block; + if (block == null) { return -1; } - var block = _block; var index = _index; var wasLastBlock = block.Next == null; var following = block.End - index; @@ -520,12 +520,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure byte byte1, ref MemoryPoolIterator limit) { - if (IsDefault) + var block = _block; + if (block == null) { return -1; } - var block = _block; var index = _index; var wasLastBlock = block.Next == null; var following = block.End - index; @@ -650,12 +650,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure byte byte2, ref MemoryPoolIterator limit) { - if (IsDefault) + var block = _block; + if (block == null) { return -1; } - var block = _block; var index = _index; var wasLastBlock = block.Next == null; var following = block.End - index; @@ -800,12 +800,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Put(byte data) { - if (_block == null) + var block = _block; + if (block == null) { return false; } - var block = _block; var index = _index; // Always set wasLastBlock before checking .End to avoid race which may cause data loss @@ -851,12 +851,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure [MethodImpl(MethodImplOptions.AggressiveInlining)] public int GetLength(MemoryPoolIterator end) { - if (IsDefault || end.IsDefault) + var block = _block; + if (block == null || end.IsDefault) { return -1; } - if (_block == end._block) + if (block == end._block) { return end._index - _index; } @@ -894,13 +895,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure public MemoryPoolIterator CopyTo(byte[] array, int offset, int count, out int actual) { - if (IsDefault) + var block = _block; + if (block == null) { actual = 0; return this; } - var block = _block; var index = _index; var remaining = count; while (true) @@ -955,17 +956,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure public void CopyFrom(byte[] data, int offset, int count) { - if (IsDefault) + var block = _block; + if (block == null) { return; } - Debug.Assert(_block != null); - Debug.Assert(_block.Next == null); - Debug.Assert(_block.End == _index); + Debug.Assert(block.Next == null); + Debug.Assert(block.End == _index); - var pool = _block.Pool; - var block = _block; + var pool = block.Pool; var blockIndex = _index; var bufferIndex = offset; @@ -1002,17 +1002,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure public unsafe void CopyFromAscii(string data) { - if (IsDefault) + var block = _block; + if (block == null) { return; } - Debug.Assert(_block != null); - Debug.Assert(_block.Next == null); - Debug.Assert(_block.End == _index); + Debug.Assert(block.Next == null); + Debug.Assert(block.End == _index); - var pool = _block.Pool; - var block = _block; + var pool = block.Pool; var blockIndex = _index; var length = data.Length; @@ -1068,7 +1067,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure public unsafe string GetAsciiString(ref MemoryPoolIterator end) { - if (IsDefault || end.IsDefault) + var block = _block; + if (block == null || end.IsDefault) { return null; } @@ -1080,8 +1080,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure return null; } - var inputOffset = Index; - var block = Block; + var inputOffset = _index; var asciiString = new string('\0', length); @@ -1124,13 +1123,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure public string GetUtf8String(ref MemoryPoolIterator end) { - if (IsDefault || end.IsDefault) + var block = _block; + if (block == null || end.IsDefault) { return default(string); } - if (end.Block == Block) + + var index = _index; + if (end.Block == block) { - return Encoding.UTF8.GetString(Block.Array, Index, end.Index - Index); + return Encoding.UTF8.GetString(block.Array, index, end.Index - index); } var decoder = Encoding.UTF8.GetDecoder(); @@ -1141,8 +1143,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure var chars = new char[charLength]; var charIndex = 0; - var block = Block; - var index = Index; var remaining = length; while (true) { @@ -1204,13 +1204,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure [MethodImpl(MethodImplOptions.AggressiveInlining)] public ArraySegment GetArraySegment(MemoryPoolIterator end) { - if (IsDefault || end.IsDefault) + var block = _block; + if (block == null || end.IsDefault) { return default(ArraySegment); } - if (end.Block == Block) + + var index = _index; + if (end.Block == block) { - return new ArraySegment(Block.Array, Index, end.Index - Index); + return new ArraySegment(block.Array, index, end.Index - index); } return GetArraySegmentMultiBlock(ref end); diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolIteratorTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolIteratorTests.cs index 156832ca0f..f3ec36afe2 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolIteratorTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolIteratorTests.cs @@ -966,6 +966,34 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } } + [Fact] + public void EmptyIteratorBehaviourIsValid() + { + const byte byteCr = (byte) '\n'; + ulong longValue; + var end = default(MemoryPoolIterator); + + Assert.False(default(MemoryPoolIterator).TryPeekLong(out longValue)); + Assert.False(default(MemoryPoolIterator).Put(byteCr)); + Assert.Null(default(MemoryPoolIterator).GetAsciiString(ref end)); + Assert.Null(default(MemoryPoolIterator).GetUtf8String(ref end)); + // Assert.Equal doesn't work for default(ArraySegments) + Assert.True(default(MemoryPoolIterator).GetArraySegment(end).Equals(default(ArraySegment))); + Assert.True(default(MemoryPoolIterator).IsDefault); + Assert.True(default(MemoryPoolIterator).IsEnd); + Assert.Equal(default(MemoryPoolIterator).Take(), -1); + Assert.Equal(default(MemoryPoolIterator).Peek(), -1); + Assert.Equal(default(MemoryPoolIterator).Seek(byteCr), -1); + Assert.Equal(default(MemoryPoolIterator).Seek(byteCr, ref end), -1); + Assert.Equal(default(MemoryPoolIterator).Seek(byteCr, byteCr), -1); + Assert.Equal(default(MemoryPoolIterator).Seek(byteCr, byteCr, byteCr), -1); + + default(MemoryPoolIterator).CopyFrom(default(ArraySegment)); + default(MemoryPoolIterator).CopyFromAscii(""); + Assert.Equal(default(MemoryPoolIterator).GetLength(end), -1); + Assert.ThrowsAny(() => default(MemoryPoolIterator).Skip(1)); + } + [Theory] [InlineData("a", "a", 1)] [InlineData("ab", "a...", 1)] From dc90dd164967848abe7991f99181318429afdabf Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Sat, 19 Nov 2016 13:21:37 +0000 Subject: [PATCH 0982/1662] Add GetArraySegment test --- .../MemoryPoolIteratorTests.cs | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolIteratorTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolIteratorTests.cs index f3ec36afe2..07a8bfa666 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolIteratorTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolIteratorTests.cs @@ -994,6 +994,65 @@ namespace Microsoft.AspNetCore.Server.KestrelTests Assert.ThrowsAny(() => default(MemoryPoolIterator).Skip(1)); } + [Fact] + public void TestGetArraySegment() + { + MemoryPoolBlock block0 = null; + MemoryPoolBlock block1 = null; + + var byteRange = Enumerable.Range(1, 127).Select(x => (byte)x).ToArray(); + try + { + // Arrange + block0 = _pool.Lease(); + block1 = _pool.Lease(); + + block0.GetIterator().CopyFrom(byteRange); + block1.GetIterator().CopyFrom(byteRange); + + block0.Next = block1; + + var begin = block0.GetIterator(); + var end0 = begin; + var end1 = begin; + + end0.Skip(byteRange.Length); + end1.Skip(byteRange.Length * 2); + + // Act + var as0 = begin.GetArraySegment(end0); + var as1 = begin.GetArraySegment(end1); + + // Assert + Assert.Equal(as0.Count, byteRange.Length); + Assert.Equal(as1.Count, byteRange.Length * 2); + + for (var i = 1; i < byteRange.Length; i++) + { + var asb0 = as0.Array[i + as0.Offset]; + var asb1 = as1.Array[i + as1.Offset]; + var b = byteRange[i]; + + Assert.Equal(asb0, b); + Assert.Equal(asb1, b); + } + + for (var i = 1 + byteRange.Length; i < byteRange.Length * 2; i++) + { + var asb1 = as1.Array[i + as1.Offset]; + var b = byteRange[i - byteRange.Length]; + + Assert.Equal(asb1, b); + } + + } + finally + { + if (block0 != null) _pool.Return(block0); + if (block1 != null) _pool.Return(block1); + } + } + [Theory] [InlineData("a", "a", 1)] [InlineData("ab", "a...", 1)] From ba0b7cc55322759094a3170bcb2ee47f35d6fe4e Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Sat, 19 Nov 2016 13:55:11 +0000 Subject: [PATCH 0983/1662] Add 100% coverage Take tests --- .../MemoryPoolIteratorTests.cs | 123 ++++++++++++++++++ 1 file changed, 123 insertions(+) diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolIteratorTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolIteratorTests.cs index 07a8bfa666..1416f652df 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolIteratorTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolIteratorTests.cs @@ -1053,6 +1053,129 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } } + [Fact] + public void TestTake() + { + MemoryPoolBlock block0 = null; + MemoryPoolBlock block1 = null; + MemoryPoolBlock block2 = null; + MemoryPoolBlock emptyBlock0 = null; + MemoryPoolBlock emptyBlock1 = null; + + var byteRange = Enumerable.Range(1, 127).Select(x => (byte)x).ToArray(); + try + { + // Arrange + block0 = _pool.Lease(); + block1 = _pool.Lease(); + block2 = _pool.Lease(); + emptyBlock0 = _pool.Lease(); + emptyBlock1 = _pool.Lease(); + + block0.GetIterator().CopyFrom(byteRange); + block1.GetIterator().CopyFrom(byteRange); + block2.GetIterator().CopyFrom(byteRange); + + var begin = block0.GetIterator(); + + // Single block + for (var i = 0; i < byteRange.Length; i++) + { + var t = begin.Take(); + var b = byteRange[i]; + + Assert.Equal(t, b); + } + + Assert.Equal(begin.Take(), -1); + + // Dual block + block0.Next = block1; + begin = block0.GetIterator(); + + for (var block = 0; block < 2; block++) + { + for (var i = 0; i < byteRange.Length; i++) + { + var t = begin.Take(); + var b = byteRange[i]; + + Assert.Equal(t, b); + } + } + + Assert.Equal(begin.Take(), -1); + + // Multi block + block1.Next = emptyBlock0; + emptyBlock0.Next = emptyBlock1; + emptyBlock1.Next = block2; + begin = block0.GetIterator(); + + for (var block = 0; block < 3; block++) + { + for (var i = 0; i < byteRange.Length; i++) + { + var t = begin.Take(); + var b = byteRange[i]; + + Assert.Equal(t, b); + } + } + + Assert.Equal(begin.Take(), -1); + } + finally + { + if (block0 != null) _pool.Return(block0); + if (block1 != null) _pool.Return(block1); + if (block2 != null) _pool.Return(block2); + if (emptyBlock0 != null) _pool.Return(emptyBlock0); + if (emptyBlock1 != null) _pool.Return(emptyBlock1); + } + } + + [Fact] + public void TestTakeEmptyBlocks() + { + MemoryPoolBlock emptyBlock0 = null; + MemoryPoolBlock emptyBlock1 = null; + MemoryPoolBlock emptyBlock2 = null; + try + { + // Arrange + emptyBlock0 = _pool.Lease(); + emptyBlock1 = _pool.Lease(); + emptyBlock2 = _pool.Lease(); + + var beginEmpty = emptyBlock0.GetIterator(); + + // Assert + + // No blocks + Assert.Equal(default(MemoryPoolIterator).Take(), -1); + + // Single empty block + Assert.Equal(beginEmpty.Take(), -1); + + // Dual empty block + emptyBlock0.Next = emptyBlock1; + beginEmpty = emptyBlock0.GetIterator(); + Assert.Equal(beginEmpty.Take(), -1); + + // Multi empty block + emptyBlock1.Next = emptyBlock2; + beginEmpty = emptyBlock0.GetIterator(); + Assert.Equal(beginEmpty.Take(), -1); + } + finally + { + if (emptyBlock0 != null) _pool.Return(emptyBlock0); + if (emptyBlock1 != null) _pool.Return(emptyBlock1); + if (emptyBlock2 != null) _pool.Return(emptyBlock2); + } + } + [Theory] [InlineData("a", "a", 1)] [InlineData("ab", "a...", 1)] From 9ec4d88fbe7da35305d4609de66ed17d3f618e4c Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Sat, 19 Nov 2016 14:15:37 +0000 Subject: [PATCH 0984/1662] Improve Skip coverage --- .../MemoryPoolIteratorTests.cs | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolIteratorTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolIteratorTests.cs index 1416f652df..0cb46de20d 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolIteratorTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolIteratorTests.cs @@ -518,20 +518,25 @@ namespace Microsoft.AspNetCore.Server.KestrelTests public void SkipThrowsWhenSkippingMoreBytesThanAvailableInMultipleBlocks() { // Arrange - var block = _pool.Lease(); - block.End += 3; + var firstBlock = _pool.Lease(); + firstBlock.End += 3; - var nextBlock = _pool.Lease(); - nextBlock.End += 2; - block.Next = nextBlock; + var middleBlock = _pool.Lease(); + middleBlock.End += 1; + firstBlock.Next = middleBlock; - var scan = block.GetIterator(); + var finalBlock = _pool.Lease(); + finalBlock.End += 2; + middleBlock.Next = finalBlock; + + var scan = firstBlock.GetIterator(); // Act/Assert Assert.ThrowsAny(() => scan.Skip(8)); - _pool.Return(block); - _pool.Return(nextBlock); + _pool.Return(firstBlock); + _pool.Return(middleBlock); + _pool.Return(finalBlock); } [Theory] From 2eba4017c1aa2f969e5a081f928c9c6a9df95327 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Mon, 21 Nov 2016 22:18:17 +0000 Subject: [PATCH 0985/1662] MemoryPoolIterator feedback --- global.json | 2 +- .../Internal/Http/Frame.cs | 2 +- .../Infrastructure/MemoryPoolIterator.cs | 33 ++++++++++++++----- .../RequestParsing.cs | 1 - .../MemoryPoolIteratorTests.cs | 6 ++-- .../MessageBodyTests.cs | 2 +- test/shared/MockConnection.cs | 2 +- test/shared/SocketInputExtensions.cs | 2 +- 8 files changed, 33 insertions(+), 17 deletions(-) diff --git a/global.json b/global.json index d9b4ed63ae..983ba0401e 100644 --- a/global.json +++ b/global.json @@ -1,3 +1,3 @@ { - "projects": [ "src" ] + "projects": ["src"] } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs index 59891a7355..2b7f56e882 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs @@ -23,7 +23,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { public abstract partial class Frame : IFrameControl { - // byte consts don't have a data type annotation so we pre-cast them + // byte types don't have a data type annotation so we pre-cast them; to avoid in-place casts private const byte ByteCR = (byte)'\r'; private const byte ByteLF = (byte)'\n'; private const byte ByteColon = (byte)':'; diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolIterator.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolIterator.cs index 4cceb50bf7..b1b45eb6e8 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolIterator.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolIterator.cs @@ -774,10 +774,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure [MethodImpl(MethodImplOptions.AggressiveInlining)] internal static int LocateFirstFoundByte(Vector byteEquals) { - var vector64 = Vector.AsVectorInt64(byteEquals); - long longValue = 0; + var vector64 = Vector.AsVectorUInt64(byteEquals); + ulong longValue = 0; var i = 0; - for (; i < Vector.Count; i++) + // Pattern unrolled by jit https://github.com/dotnet/coreclr/pull/8001 + for (; i < Vector.Count; i++) { longValue = vector64[i]; if (longValue == 0) continue; @@ -785,7 +786,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure } // Flag least significant power of two bit - var powerOfTwoFlag = (ulong)(longValue ^ (longValue - 1)); + var powerOfTwoFlag = (longValue ^ (longValue - 1)); // Shift all powers of two into the high byte and extract var foundByteIndex = (int)((powerOfTwoFlag * _xorPowerOfTwoToHighByte) >> 57); // Single LEA instruction with jitted const (using function result) @@ -803,7 +804,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure var block = _block; if (block == null) { - return false; + ThrowInvalidOperationException_PutPassedEndOfBlock(); } var index = _index; @@ -817,7 +818,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure return true; } - return wasLastBlock ? false : PutMultiBlock(data); + if (wasLastBlock) + { + ThrowInvalidOperationException_PutPassedEndOfBlock(); + } + + return PutMultiBlock(data); } [MethodImpl(MethodImplOptions.NoInlining)] @@ -841,6 +847,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure } if (wasLastBlock) { + ThrowInvalidOperationException_PutPassedEndOfBlock(); return false; } } while (true); @@ -848,13 +855,18 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure return true; } + private static void ThrowInvalidOperationException_PutPassedEndOfBlock() + { + throw new InvalidOperationException("Attempted to put passed end of block."); + } + [MethodImpl(MethodImplOptions.AggressiveInlining)] public int GetLength(MemoryPoolIterator end) { var block = _block; if (block == null || end.IsDefault) { - return -1; + ThrowInvalidOperationException_GetLengthNullBlock(); } if (block == end._block) @@ -865,6 +877,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure return GetLengthMultiBlock(ref end); } + private static void ThrowInvalidOperationException_GetLengthNullBlock() + { + throw new InvalidOperationException("Attempted GetLength of non existent block."); + } + [MethodImpl(MethodImplOptions.NoInlining)] public int GetLengthMultiBlock(ref MemoryPoolIterator end) { @@ -1234,7 +1251,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure // Vector .ctor doesn't become an intrinsic due to detection issue // However this does cause it to become an intrinsic (with additional multiply and reg->reg copy) // https://github.com/dotnet/coreclr/issues/7459#issuecomment-253965670 - return Vector.AsVectorByte(new Vector(vectorByte * 0x0101010101010101ul)); + return Vector.AsVectorByte(new Vector(vectorByte * 0x01010101u)); } } diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsing.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsing.cs index 7388c547a2..5ae06776f5 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsing.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsing.cs @@ -8,7 +8,6 @@ using BenchmarkDotNet.Attributes; using Microsoft.AspNetCore.Server.Kestrel.Internal; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; -using Microsoft.AspNetCore.Server.KestrelTests.TestHelpers; using Microsoft.AspNetCore.Testing; using RequestLineStatus = Microsoft.AspNetCore.Server.Kestrel.Internal.Http.Frame.RequestLineStatus; diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolIteratorTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolIteratorTests.cs index 0cb46de20d..1db21257a3 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolIteratorTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolIteratorTests.cs @@ -154,7 +154,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } // Can't put anything by the end - Assert.False(head.Put(0xFF)); + Assert.ThrowsAny(() => head.Put(0xFF)); for (var i = 0; i < 4; ++i) { @@ -979,7 +979,6 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var end = default(MemoryPoolIterator); Assert.False(default(MemoryPoolIterator).TryPeekLong(out longValue)); - Assert.False(default(MemoryPoolIterator).Put(byteCr)); Assert.Null(default(MemoryPoolIterator).GetAsciiString(ref end)); Assert.Null(default(MemoryPoolIterator).GetUtf8String(ref end)); // Assert.Equal doesn't work for default(ArraySegments) @@ -995,7 +994,8 @@ namespace Microsoft.AspNetCore.Server.KestrelTests default(MemoryPoolIterator).CopyFrom(default(ArraySegment)); default(MemoryPoolIterator).CopyFromAscii(""); - Assert.Equal(default(MemoryPoolIterator).GetLength(end), -1); + Assert.ThrowsAny(() => default(MemoryPoolIterator).Put(byteCr)); + Assert.ThrowsAny(() => default(MemoryPoolIterator).GetLength(end)); Assert.ThrowsAny(() => default(MemoryPoolIterator).Skip(1)); } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/MessageBodyTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/MessageBodyTests.cs index a5ed8d7c9f..414bb208e3 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/MessageBodyTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/MessageBodyTests.cs @@ -10,11 +10,11 @@ using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; -using Microsoft.AspNetCore.Server.KestrelTests.TestHelpers; using Microsoft.Extensions.Internal; using Moq; using Xunit; using Xunit.Sdk; +using Microsoft.AspNetCore.Testing; namespace Microsoft.AspNetCore.Server.KestrelTests { diff --git a/test/shared/MockConnection.cs b/test/shared/MockConnection.cs index a782f51ffd..e1025c624c 100644 --- a/test/shared/MockConnection.cs +++ b/test/shared/MockConnection.cs @@ -8,7 +8,7 @@ using Microsoft.AspNetCore.Server.Kestrel; using Microsoft.AspNetCore.Server.Kestrel.Internal; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; -namespace Microsoft.AspNetCore.Server.KestrelTests.TestHelpers +namespace Microsoft.AspNetCore.Testing { public class MockConnection : Connection, IDisposable { diff --git a/test/shared/SocketInputExtensions.cs b/test/shared/SocketInputExtensions.cs index 998e0552c5..d6dbbb7e88 100644 --- a/test/shared/SocketInputExtensions.cs +++ b/test/shared/SocketInputExtensions.cs @@ -4,7 +4,7 @@ using System; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; -namespace Microsoft.AspNetCore.Server.KestrelTests.TestHelpers +namespace Microsoft.AspNetCore.Testing { public static class SocketInputExtensions { From b2d45c3dd03475f6483adcf323ab6d6d55172269 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Mon, 21 Nov 2016 12:09:47 -0800 Subject: [PATCH 0986/1662] Make TestApplicationErrorLogger thread-safe --- test/shared/TestApplicationErrorLogger.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/shared/TestApplicationErrorLogger.cs b/test/shared/TestApplicationErrorLogger.cs index 5036f1cec9..80c12a23bd 100644 --- a/test/shared/TestApplicationErrorLogger.cs +++ b/test/shared/TestApplicationErrorLogger.cs @@ -2,7 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.Collections.Generic; +using System.Collections.Concurrent; using System.Linq; using Microsoft.AspNetCore.Server.Kestrel.Internal; using Microsoft.Extensions.Logging; @@ -14,7 +14,7 @@ namespace Microsoft.AspNetCore.Testing // Application errors are logged using 13 as the eventId. private const int ApplicationErrorEventId = 13; - public List Messages { get; } = new List(); + public ConcurrentBag Messages { get; } = new ConcurrentBag(); public int TotalErrorsLogged => Messages.Count(message => message.LogLevel == LogLevel.Error); From a0f5585d3ff89f12333c6f8c2fe86a70a02ad49d Mon Sep 17 00:00:00 2001 From: Kristian Hellang Date: Tue, 22 Nov 2016 13:00:42 +0100 Subject: [PATCH 0987/1662] Fixed typo; Proxy-Authenticate #1223 --- .../Internal/Http/FrameHeaders.Generated.cs | 178 ++++++++++-------- .../KnownHeaders.cs | 2 +- 2 files changed, 100 insertions(+), 80 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameHeaders.Generated.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameHeaders.Generated.cs index c7502e61af..e8b118824d 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameHeaders.Generated.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameHeaders.Generated.cs @@ -5950,7 +5950,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { private static byte[] _headerBytes = new byte[] { - 13,10,67,97,99,104,101,45,67,111,110,116,114,111,108,58,32,13,10,67,111,110,110,101,99,116,105,111,110,58,32,13,10,68,97,116,101,58,32,13,10,75,101,101,112,45,65,108,105,118,101,58,32,13,10,80,114,97,103,109,97,58,32,13,10,84,114,97,105,108,101,114,58,32,13,10,84,114,97,110,115,102,101,114,45,69,110,99,111,100,105,110,103,58,32,13,10,85,112,103,114,97,100,101,58,32,13,10,86,105,97,58,32,13,10,87,97,114,110,105,110,103,58,32,13,10,65,108,108,111,119,58,32,13,10,67,111,110,116,101,110,116,45,76,101,110,103,116,104,58,32,13,10,67,111,110,116,101,110,116,45,84,121,112,101,58,32,13,10,67,111,110,116,101,110,116,45,69,110,99,111,100,105,110,103,58,32,13,10,67,111,110,116,101,110,116,45,76,97,110,103,117,97,103,101,58,32,13,10,67,111,110,116,101,110,116,45,76,111,99,97,116,105,111,110,58,32,13,10,67,111,110,116,101,110,116,45,77,68,53,58,32,13,10,67,111,110,116,101,110,116,45,82,97,110,103,101,58,32,13,10,69,120,112,105,114,101,115,58,32,13,10,76,97,115,116,45,77,111,100,105,102,105,101,100,58,32,13,10,65,99,99,101,112,116,45,82,97,110,103,101,115,58,32,13,10,65,103,101,58,32,13,10,69,84,97,103,58,32,13,10,76,111,99,97,116,105,111,110,58,32,13,10,80,114,111,120,121,45,65,117,116,104,101,116,105,99,97,116,101,58,32,13,10,82,101,116,114,121,45,65,102,116,101,114,58,32,13,10,83,101,114,118,101,114,58,32,13,10,83,101,116,45,67,111,111,107,105,101,58,32,13,10,86,97,114,121,58,32,13,10,87,87,87,45,65,117,116,104,101,110,116,105,99,97,116,101,58,32,13,10,65,99,99,101,115,115,45,67,111,110,116,114,111,108,45,65,108,108,111,119,45,67,114,101,100,101,110,116,105,97,108,115,58,32,13,10,65,99,99,101,115,115,45,67,111,110,116,114,111,108,45,65,108,108,111,119,45,72,101,97,100,101,114,115,58,32,13,10,65,99,99,101,115,115,45,67,111,110,116,114,111,108,45,65,108,108,111,119,45,77,101,116,104,111,100,115,58,32,13,10,65,99,99,101,115,115,45,67,111,110,116,114,111,108,45,65,108,108,111,119,45,79,114,105,103,105,110,58,32,13,10,65,99,99,101,115,115,45,67,111,110,116,114,111,108,45,69,120,112,111,115,101,45,72,101,97,100,101,114,115,58,32,13,10,65,99,99,101,115,115,45,67,111,110,116,114,111,108,45,77,97,120,45,65,103,101,58,32, + 13,10,67,97,99,104,101,45,67,111,110,116,114,111,108,58,32,13,10,67,111,110,110,101,99,116,105,111,110,58,32,13,10,68,97,116,101,58,32,13,10,75,101,101,112,45,65,108,105,118,101,58,32,13,10,80,114,97,103,109,97,58,32,13,10,84,114,97,105,108,101,114,58,32,13,10,84,114,97,110,115,102,101,114,45,69,110,99,111,100,105,110,103,58,32,13,10,85,112,103,114,97,100,101,58,32,13,10,86,105,97,58,32,13,10,87,97,114,110,105,110,103,58,32,13,10,65,108,108,111,119,58,32,13,10,67,111,110,116,101,110,116,45,76,101,110,103,116,104,58,32,13,10,67,111,110,116,101,110,116,45,84,121,112,101,58,32,13,10,67,111,110,116,101,110,116,45,69,110,99,111,100,105,110,103,58,32,13,10,67,111,110,116,101,110,116,45,76,97,110,103,117,97,103,101,58,32,13,10,67,111,110,116,101,110,116,45,76,111,99,97,116,105,111,110,58,32,13,10,67,111,110,116,101,110,116,45,77,68,53,58,32,13,10,67,111,110,116,101,110,116,45,82,97,110,103,101,58,32,13,10,69,120,112,105,114,101,115,58,32,13,10,76,97,115,116,45,77,111,100,105,102,105,101,100,58,32,13,10,65,99,99,101,112,116,45,82,97,110,103,101,115,58,32,13,10,65,103,101,58,32,13,10,69,84,97,103,58,32,13,10,76,111,99,97,116,105,111,110,58,32,13,10,80,114,111,120,121,45,65,117,116,104,101,110,116,105,99,97,116,101,58,32,13,10,82,101,116,114,121,45,65,102,116,101,114,58,32,13,10,83,101,114,118,101,114,58,32,13,10,83,101,116,45,67,111,111,107,105,101,58,32,13,10,86,97,114,121,58,32,13,10,87,87,87,45,65,117,116,104,101,110,116,105,99,97,116,101,58,32,13,10,65,99,99,101,115,115,45,67,111,110,116,114,111,108,45,65,108,108,111,119,45,67,114,101,100,101,110,116,105,97,108,115,58,32,13,10,65,99,99,101,115,115,45,67,111,110,116,114,111,108,45,65,108,108,111,119,45,72,101,97,100,101,114,115,58,32,13,10,65,99,99,101,115,115,45,67,111,110,116,114,111,108,45,65,108,108,111,119,45,77,101,116,104,111,100,115,58,32,13,10,65,99,99,101,115,115,45,67,111,110,116,114,111,108,45,65,108,108,111,119,45,79,114,105,103,105,110,58,32,13,10,65,99,99,101,115,115,45,67,111,110,116,114,111,108,45,69,120,112,111,115,101,45,72,101,97,100,101,114,115,58,32,13,10,65,99,99,101,115,115,45,67,111,110,116,114,111,108,45,77,97,120,45,65,103,101,58,32, }; private long _bits = 0; @@ -6345,20 +6345,20 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _headers._Location = value; } } - public StringValues HeaderProxyAutheticate + public StringValues HeaderProxyAuthenticate { get { if (((_bits & 16777216L) != 0)) { - return _headers._ProxyAutheticate; + return _headers._ProxyAuthenticate; } return StringValues.Empty; } set { _bits |= 16777216L; - _headers._ProxyAutheticate = value; + _headers._ProxyAuthenticate = value; } } public StringValues HeaderRetryAfter @@ -6803,18 +6803,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http ThrowKeyNotFoundException(); } } - - if ("Proxy-Autheticate".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 16777216L) != 0)) - { - return _headers._ProxyAutheticate; - } - else - { - ThrowKeyNotFoundException(); - } - } } break; @@ -6990,6 +6978,22 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } break; + case 18: + { + if ("Proxy-Authenticate".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 16777216L) != 0)) + { + return _headers._ProxyAuthenticate; + } + else + { + ThrowKeyNotFoundException(); + } + } + } + break; + case 32: { if ("Access-Control-Allow-Credentials".Equals(key, StringComparison.OrdinalIgnoreCase)) @@ -7351,20 +7355,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http return false; } } - - if ("Proxy-Autheticate".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 16777216L) != 0)) - { - value = _headers._ProxyAutheticate; - return true; - } - else - { - value = StringValues.Empty; - return false; - } - } } break; @@ -7564,6 +7554,24 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } break; + case 18: + { + if ("Proxy-Authenticate".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 16777216L) != 0)) + { + value = _headers._ProxyAuthenticate; + return true; + } + else + { + value = StringValues.Empty; + return false; + } + } + } + break; + case 32: { if ("Access-Control-Allow-Credentials".Equals(key, StringComparison.OrdinalIgnoreCase)) @@ -7820,13 +7828,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _headers._rawTransferEncoding = null; return; } - - if ("Proxy-Autheticate".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - _bits |= 16777216L; - _headers._ProxyAutheticate = value; - return; - } } break; @@ -7944,6 +7945,17 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } break; + case 18: + { + if ("Proxy-Authenticate".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + _bits |= 16777216L; + _headers._ProxyAuthenticate = value; + return; + } + } + break; + case 32: { if ("Access-Control-Allow-Credentials".Equals(key, StringComparison.OrdinalIgnoreCase)) @@ -8226,17 +8238,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _headers._rawTransferEncoding = null; return; } - - if ("Proxy-Autheticate".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 16777216L) != 0)) - { - ThrowDuplicateKeyException(); - } - _bits |= 16777216L; - _headers._ProxyAutheticate = value; - return; - } } break; @@ -8402,6 +8403,21 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } break; + case 18: + { + if ("Proxy-Authenticate".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 16777216L) != 0)) + { + ThrowDuplicateKeyException(); + } + _bits |= 16777216L; + _headers._ProxyAuthenticate = value; + return; + } + } + break; + case 32: { if ("Access-Control-Allow-Credentials".Equals(key, StringComparison.OrdinalIgnoreCase)) @@ -8758,20 +8774,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http return false; } } - - if ("Proxy-Autheticate".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 16777216L) != 0)) - { - _bits &= ~16777216L; - _headers._ProxyAutheticate = StringValues.Empty; - return true; - } - else - { - return false; - } - } } break; @@ -8973,6 +8975,24 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } break; + case 18: + { + if ("Proxy-Authenticate".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (((_bits & 16777216L) != 0)) + { + _bits &= ~16777216L; + _headers._ProxyAuthenticate = StringValues.Empty; + return true; + } + else + { + return false; + } + } + } + break; + case 32: { if ("Access-Control-Allow-Credentials".Equals(key, StringComparison.OrdinalIgnoreCase)) @@ -9342,7 +9362,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if (((_bits & 16777216L) != 0)) { - _headers._ProxyAutheticate = default(StringValues); + _headers._ProxyAuthenticate = default(StringValues); _bits &= ~16777216L; if(_bits == 0) { @@ -9730,7 +9750,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http ThrowArgumentException(); } - array[arrayIndex] = new KeyValuePair("Proxy-Autheticate", _headers._ProxyAutheticate); + array[arrayIndex] = new KeyValuePair("Proxy-Authenticate", _headers._ProxyAuthenticate); ++arrayIndex; } @@ -9960,7 +9980,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { if (value != null) { - output.CopyFrom(_headerBytes, 367, 10); + output.CopyFrom(_headerBytes, 368, 10); output.CopyFromAscii(value); } } @@ -10339,11 +10359,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if (((_bits & 16777216L) != 0)) { - foreach (var value in _headers._ProxyAutheticate) + foreach (var value in _headers._ProxyAuthenticate) { if (value != null) { - output.CopyFrom(_headerBytes, 331, 21); + output.CopyFrom(_headerBytes, 331, 22); output.CopyFromAscii(value); } } @@ -10361,7 +10381,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { if (value != null) { - output.CopyFrom(_headerBytes, 352, 15); + output.CopyFrom(_headerBytes, 353, 15); output.CopyFromAscii(value); } } @@ -10379,7 +10399,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { if (value != null) { - output.CopyFrom(_headerBytes, 377, 14); + output.CopyFrom(_headerBytes, 378, 14); output.CopyFromAscii(value); } } @@ -10397,7 +10417,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { if (value != null) { - output.CopyFrom(_headerBytes, 391, 8); + output.CopyFrom(_headerBytes, 392, 8); output.CopyFromAscii(value); } } @@ -10415,7 +10435,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { if (value != null) { - output.CopyFrom(_headerBytes, 399, 20); + output.CopyFrom(_headerBytes, 400, 20); output.CopyFromAscii(value); } } @@ -10433,7 +10453,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { if (value != null) { - output.CopyFrom(_headerBytes, 419, 36); + output.CopyFrom(_headerBytes, 420, 36); output.CopyFromAscii(value); } } @@ -10451,7 +10471,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { if (value != null) { - output.CopyFrom(_headerBytes, 455, 32); + output.CopyFrom(_headerBytes, 456, 32); output.CopyFromAscii(value); } } @@ -10469,7 +10489,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { if (value != null) { - output.CopyFrom(_headerBytes, 487, 32); + output.CopyFrom(_headerBytes, 488, 32); output.CopyFromAscii(value); } } @@ -10487,7 +10507,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { if (value != null) { - output.CopyFrom(_headerBytes, 519, 31); + output.CopyFrom(_headerBytes, 520, 31); output.CopyFromAscii(value); } } @@ -10505,7 +10525,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { if (value != null) { - output.CopyFrom(_headerBytes, 550, 33); + output.CopyFrom(_headerBytes, 551, 33); output.CopyFromAscii(value); } } @@ -10523,7 +10543,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { if (value != null) { - output.CopyFrom(_headerBytes, 583, 26); + output.CopyFrom(_headerBytes, 584, 26); output.CopyFromAscii(value); } } @@ -10565,7 +10585,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http public StringValues _Age; public StringValues _ETag; public StringValues _Location; - public StringValues _ProxyAutheticate; + public StringValues _ProxyAuthenticate; public StringValues _RetryAfter; public StringValues _Server; public StringValues _SetCookie; @@ -10899,7 +10919,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http state24: if (((_bits & 16777216L) != 0)) { - _current = new KeyValuePair("Proxy-Autheticate", _collection._headers._ProxyAutheticate); + _current = new KeyValuePair("Proxy-Authenticate", _collection._headers._ProxyAuthenticate); _state = 25; return true; } diff --git a/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/KnownHeaders.cs b/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/KnownHeaders.cs index fef4219b12..d50bdebf46 100644 --- a/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/KnownHeaders.cs +++ b/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/KnownHeaders.cs @@ -222,7 +222,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.GeneratedCode "Age", "ETag", "Location", - "Proxy-Autheticate", + "Proxy-Authenticate", "Retry-After", "Server", "Set-Cookie", From 2bf5a966cdf214a365b5c97f8d844924074097a8 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Tue, 15 Nov 2016 20:15:02 +0000 Subject: [PATCH 0988/1662] Fast path and inline HttpVersion.set --- .../Internal/Http/Frame.cs | 28 +++++++++++++++++-- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs index 2b7f56e882..5f336b71f6 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs @@ -7,6 +7,7 @@ using System.Diagnostics; using System.IO; using System.Linq; using System.Net; +using System.Runtime.CompilerServices; using System.Text; using System.Threading; using System.Threading.Tasks; @@ -145,23 +146,44 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http return string.Empty; } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] set { - if (value == "HTTP/1.1") + // GetKnownVersion returns versions which ReferenceEquals interned string + // As most common path, check for this only in fast-path and inline + if (ReferenceEquals(value, "HTTP/1.1")) { _httpVersion = Http.HttpVersion.Http11; } - else if (value == "HTTP/1.0") + else if (ReferenceEquals(value, "HTTP/1.0")) { _httpVersion = Http.HttpVersion.Http10; } else { - _httpVersion = Http.HttpVersion.Unset; + HttpVersionSetSlow(value); } } } + [MethodImpl(MethodImplOptions.NoInlining)] + private void HttpVersionSetSlow(string value) + { + if (value == "HTTP/1.1") + { + _httpVersion = Http.HttpVersion.Http11; + } + else if (value == "HTTP/1.0") + { + _httpVersion = Http.HttpVersion.Http10; + } + else + { + _httpVersion = Http.HttpVersion.Unset; + } + } + public IHeaderDictionary RequestHeaders { get; set; } public Stream RequestBody { get; set; } From e55c62444bdd34274173b011720c03f23c4db2f5 Mon Sep 17 00:00:00 2001 From: Pavel Krymets Date: Tue, 22 Nov 2016 16:36:36 -0800 Subject: [PATCH 0989/1662] Refactor FrameTests and rename SocketInput SocketOutput properties (#1229) --- .../Internal/Http/Connection.cs | 24 +- .../Internal/Http/ConnectionContext.cs | 4 +- .../Internal/Http/Frame.cs | 32 +- .../Internal/Http/FrameOfT.cs | 16 +- .../Internal/Http/MessageBody.cs | 10 +- .../RequestParsing.cs | 2 +- .../ConnectionTests.cs | 2 +- .../FrameTests.cs | 1350 ++++------------- .../MessageBodyTests.cs | 2 +- .../TestInput.cs | 8 +- 10 files changed, 330 insertions(+), 1120 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Connection.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Connection.cs index 3f61f8530c..eb9fae5648 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Connection.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Connection.cs @@ -56,8 +56,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _bufferSizeControl = new BufferSizeControl(ServerOptions.Limits.MaxRequestBufferSize.Value, this, Thread); } - SocketInput = new SocketInput(Thread.Memory, ThreadPool, _bufferSizeControl); - SocketOutput = new SocketOutput(Thread, _socket, this, ConnectionId, Log, ThreadPool); + Input = new SocketInput(Thread.Memory, ThreadPool, _bufferSizeControl); + Output = new SocketOutput(Thread, _socket, this, ConnectionId, Log, ThreadPool); var tcpHandle = _socket as UvTcpHandle; if (tcpHandle != null) @@ -95,7 +95,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } else { - _libuvStream = new LibuvStream(SocketInput, SocketOutput); + _libuvStream = new LibuvStream(Input, Output); _filterContext = new ConnectionFilterContext { @@ -136,7 +136,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http public Task StopAsync() { _frame.StopAsync(); - _frame.SocketInput.CompleteAwaiting(); + _frame.Input.CompleteAwaiting(); return _socketClosedTcs.Task; } @@ -169,7 +169,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } }, this); - SocketInput.Dispose(); + Input.Dispose(); _socketClosedTcs.TrySetResult(null); } @@ -197,8 +197,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { _filteredStreamAdapter = new FilteredStreamAdapter(ConnectionId, _filterContext.Connection, Thread.Memory, Log, ThreadPool, _bufferSizeControl); - _frame.SocketInput = _filteredStreamAdapter.SocketInput; - _frame.SocketOutput = _filteredStreamAdapter.SocketOutput; + _frame.Input = _filteredStreamAdapter.SocketInput; + _frame.Output = _filteredStreamAdapter.SocketOutput; _readInputTask = _filteredStreamAdapter.ReadInputAsync(); } @@ -214,7 +214,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http private Libuv.uv_buf_t OnAlloc(UvStreamHandle handle, int suggestedSize) { - var result = SocketInput.IncomingStart(); + var result = Input.IncomingStart(); return handle.Libuv.buf_init( result.DataArrayPtr + result.End, @@ -234,7 +234,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http // there is no data to be read right now. // See the note at http://docs.libuv.org/en/v1.x/stream.html#c.uv_read_cb. // We need to clean up whatever was allocated by OnAlloc. - SocketInput.IncomingDeferred(); + Input.IncomingDeferred(); return; } @@ -276,7 +276,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http error = new IOException(uvError.Message, uvError); } - SocketInput.IncomingComplete(readCount, error); + Input.IncomingComplete(readCount, error); if (errorDone) { @@ -302,7 +302,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http // ReadStart() can throw a UvException in some cases (e.g. socket is no longer connected). // This should be treated the same as OnRead() seeing a "normalDone" condition. Log.ConnectionReadFin(ConnectionId); - SocketInput.IncomingComplete(0, null); + Input.IncomingComplete(0, null); } } @@ -316,7 +316,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http case ProduceEndType.SocketShutdown: case ProduceEndType.SocketDisconnect: Log.ConnectionDisconnect(ConnectionId); - ((SocketOutput)SocketOutput).End(endType); + ((SocketOutput)Output).End(endType); break; } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ConnectionContext.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ConnectionContext.cs index 7ee603e4c5..72344c73b1 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ConnectionContext.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ConnectionContext.cs @@ -20,9 +20,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http public ListenerContext ListenerContext { get; set; } - public SocketInput SocketInput { get; set; } + public SocketInput Input { get; set; } - public ISocketOutput SocketOutput { get; set; } + public ISocketOutput Output { get; set; } public IConnectionControl ConnectionControl { get; set; } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs index 5f336b71f6..0b37975bc3 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs @@ -82,8 +82,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http public Frame(ConnectionContext context) { ConnectionContext = context; - SocketInput = context.SocketInput; - SocketOutput = context.SocketOutput; + Input = context.Input; + Output = context.Output; ServerOptions = context.ListenerContext.ServiceContext.ServerOptions; @@ -95,8 +95,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } public ConnectionContext ConnectionContext { get; } - public SocketInput SocketInput { get; set; } - public ISocketOutput SocketOutput { get; set; } + public SocketInput Input { get; set; } + public ISocketOutput Output { get; set; } public Action PrepareRequest { get @@ -531,13 +531,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http public void Flush() { ProduceStartAndFireOnStarting().GetAwaiter().GetResult(); - SocketOutput.Flush(); + Output.Flush(); } public async Task FlushAsync(CancellationToken cancellationToken) { await ProduceStartAndFireOnStarting(); - await SocketOutput.FlushAsync(cancellationToken); + await Output.FlushAsync(cancellationToken); } public void Write(ArraySegment data) @@ -564,7 +564,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } else { - SocketOutput.Write(data); + Output.Write(data); } } else @@ -599,7 +599,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } else { - return SocketOutput.WriteAsync(data, cancellationToken: cancellationToken); + return Output.WriteAsync(data, cancellationToken: cancellationToken); } } else @@ -631,7 +631,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } else { - await SocketOutput.WriteAsync(data, cancellationToken: cancellationToken); + await Output.WriteAsync(data, cancellationToken: cancellationToken); } } else @@ -675,17 +675,17 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http private void WriteChunked(ArraySegment data) { - SocketOutput.Write(data, chunk: true); + Output.Write(data, chunk: true); } private Task WriteChunkedAsync(ArraySegment data, CancellationToken cancellationToken) { - return SocketOutput.WriteAsync(data, chunk: true, cancellationToken: cancellationToken); + return Output.WriteAsync(data, chunk: true, cancellationToken: cancellationToken); } private Task WriteChunkedResponseSuffix() { - return SocketOutput.WriteAsync(_endChunkedResponseBytes); + return Output.WriteAsync(_endChunkedResponseBytes); } private static ArraySegment CreateAsciiByteArraySegment(string text) @@ -706,7 +706,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http RequestHeaders.TryGetValue("Expect", out expect) && (expect.FirstOrDefault() ?? "").Equals("100-continue", StringComparison.OrdinalIgnoreCase)) { - SocketOutput.Write(_continueBytes); + Output.Write(_continueBytes); } } @@ -809,7 +809,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http ProduceStart(appCompleted: true); // Force flush - await SocketOutput.FlushAsync(); + await Output.FlushAsync(); await WriteSuffix(); } @@ -856,7 +856,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var hasTransferEncoding = responseHeaders.HasTransferEncoding; var transferCoding = FrameHeaders.GetFinalTransferCoding(responseHeaders.HeaderTransferEncoding); - var end = SocketOutput.ProducingStart(); + var end = Output.ProducingStart(); if (_keepAlive && hasConnection) { @@ -944,7 +944,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http responseHeaders.CopyTo(ref end); end.CopyFrom(_bytesEndHeaders, 0, _bytesEndHeaders.Length); - SocketOutput.ProducingComplete(end); + Output.ProducingComplete(end); } public RequestLineStatus TakeStartLine(SocketInput input) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameOfT.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameOfT.cs index a59b010e32..f6d9128fa4 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameOfT.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameOfT.cs @@ -41,20 +41,20 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http while (!_requestProcessingStopping) { - requestLineStatus = TakeStartLine(SocketInput); + requestLineStatus = TakeStartLine(Input); if (requestLineStatus == RequestLineStatus.Done) { break; } - if (SocketInput.CheckFinOrThrow()) + if (Input.CheckFinOrThrow()) { // We need to attempt to consume start lines and headers even after // SocketInput.RemoteIntakeFin is set to true to ensure we don't close a // connection without giving the application a chance to respond to a request // sent immediately before the a FIN from the client. - requestLineStatus = TakeStartLine(SocketInput); + requestLineStatus = TakeStartLine(Input); if (requestLineStatus == RequestLineStatus.Empty) { @@ -69,20 +69,20 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http break; } - await SocketInput; + await Input; } InitializeHeaders(); - while (!_requestProcessingStopping && !TakeMessageHeaders(SocketInput, FrameRequestHeaders)) + while (!_requestProcessingStopping && !TakeMessageHeaders(Input, FrameRequestHeaders)) { - if (SocketInput.CheckFinOrThrow()) + if (Input.CheckFinOrThrow()) { // We need to attempt to consume start lines and headers even after // SocketInput.RemoteIntakeFin is set to true to ensure we don't close a // connection without giving the application a chance to respond to a request // sent immediately before the a FIN from the client. - if (!TakeMessageHeaders(SocketInput, FrameRequestHeaders)) + if (!TakeMessageHeaders(Input, FrameRequestHeaders)) { RejectRequest(RequestRejectionReason.MalformedRequestInvalidHeaders); } @@ -90,7 +90,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http break; } - await SocketInput; + await Input; } if (!_requestProcessingStopping) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/MessageBody.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/MessageBody.cs index 77e9b9adcd..50cb468741 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/MessageBody.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/MessageBody.cs @@ -213,9 +213,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http private void ConsumedBytes(int count) { - var scan = _context.SocketInput.ConsumingStart(); + var scan = _context.Input.ConsumingStart(); scan.Skip(count); - _context.SocketInput.ConsumingComplete(scan, scan); + _context.Input.ConsumingComplete(scan, scan); OnConsumedBytes(count); } @@ -305,7 +305,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http protected override ValueTask> PeekAsync(CancellationToken cancellationToken) { - return _context.SocketInput.PeekAsync(); + return _context.Input.PeekAsync(); } } @@ -330,7 +330,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http return new ValueTask>(); } - var task = _context.SocketInput.PeekAsync(); + var task = _context.Input.PeekAsync(); if (task.IsCompleted) { @@ -402,7 +402,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http : base(context) { RequestKeepAlive = keepAlive; - _input = _context.SocketInput; + _input = _context.Input; _requestHeaders = headers; } diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsing.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsing.cs index 5ae06776f5..facb7bcef5 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsing.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsing.cs @@ -172,7 +172,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance SocketInput = new SocketInput(MemoryPool, ThreadPool); var connectionContext = new MockConnection(new KestrelServerOptions()); - connectionContext.SocketInput = SocketInput; + connectionContext.Input = SocketInput; Frame = new Frame(application: null, context: connectionContext); } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionTests.cs index a987904831..779cc60372 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionTests.cs @@ -48,7 +48,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests Libuv.uv_buf_t ignored; mockLibuv.AllocCallback(socket.InternalGetHandle(), 2048, out ignored); mockLibuv.ReadCallback(socket.InternalGetHandle(), 0, ref ignored); - Assert.False(connection.SocketInput.CheckFinOrThrow()); + Assert.False(connection.Input.CheckFinOrThrow()); }, null); connection.ConnectionControl.End(ProduceEndType.SocketDisconnect); diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs index be5c3e9348..efed448cfe 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs @@ -6,8 +6,6 @@ using System.IO; using System.Text; using System.Threading; using System.Threading.Tasks; -using Microsoft.AspNetCore.Hosting.Server; -using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Server.Kestrel; using Microsoft.AspNetCore.Server.Kestrel.Internal; @@ -21,47 +19,66 @@ using Xunit; namespace Microsoft.AspNetCore.Server.KestrelTests { - public class FrameTests + public class FrameTests : IDisposable { - [Fact] - public void CanReadHeaderValueWithoutLeadingWhitespace() + private readonly SocketInput _socketInput; + private readonly MemoryPool _pool; + private readonly Frame _frame; + private readonly ServiceContext _serviceContext; + private readonly ConnectionContext _connectionContext; + + public FrameTests() { var trace = new KestrelTrace(new TestKestrelTrace()); var ltp = new LoggingThreadPool(trace); - using (var pool = new MemoryPool()) - using (var socketInput = new SocketInput(pool, ltp)) + _pool = new MemoryPool(); + _socketInput = new SocketInput(_pool, ltp); + + _serviceContext = new ServiceContext { - var serviceContext = new ServiceContext - { - DateHeaderValueManager = new DateHeaderValueManager(), - ServerOptions = new KestrelServerOptions() - }; - var listenerContext = new ListenerContext(serviceContext) - { - ServerAddress = ServerAddress.FromUrl("http://localhost:5000") - }; - var connectionContext = new ConnectionContext(listenerContext) - { - ConnectionControl = Mock.Of() - }; + DateHeaderValueManager = new DateHeaderValueManager(), + ServerOptions = new KestrelServerOptions(), + Log = trace + }; + var listenerContext = new ListenerContext(_serviceContext) + { + ServerAddress = ServerAddress.FromUrl("http://localhost:5000") + }; + _connectionContext = new ConnectionContext(listenerContext) + { + Input = _socketInput, + Output = new MockSocketOuptut(), + ConnectionControl = Mock.Of() + }; - var frame = new Frame(application: null, context: connectionContext); - frame.Reset(); - frame.InitializeHeaders(); + _frame = new Frame(application: null, context: _connectionContext); + _frame.Reset(); + _frame.InitializeHeaders(); + } - var headerArray = Encoding.ASCII.GetBytes("Header:value\r\n\r\n"); - socketInput.IncomingData(headerArray, 0, headerArray.Length); + public void Dispose() + { + _pool.Dispose(); + _socketInput.Dispose(); + } - var success = frame.TakeMessageHeaders(socketInput, (FrameRequestHeaders)frame.RequestHeaders); + [Fact] + public void CanReadHeaderValueWithoutLeadingWhitespace() + { + _frame.InitializeHeaders(); - Assert.True(success); - Assert.Equal(1, frame.RequestHeaders.Count); - Assert.Equal("value", frame.RequestHeaders["Header"]); + var headerArray = Encoding.ASCII.GetBytes("Header:value\r\n\r\n"); + _socketInput.IncomingData(headerArray, 0, headerArray.Length); - // Assert TakeMessageHeaders consumed all the input - var scan = socketInput.ConsumingStart(); - Assert.True(scan.IsEnd); - } + var success = _frame.TakeMessageHeaders(_socketInput, (FrameRequestHeaders)_frame.RequestHeaders); + + Assert.True(success); + Assert.Equal(1, _frame.RequestHeaders.Count); + Assert.Equal("value", _frame.RequestHeaders["Header"]); + + // Assert TakeMessageHeaders consumed all the input + var scan = _socketInput.ConsumingStart(); + Assert.True(scan.IsEnd); } [Theory] @@ -77,42 +94,18 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [InlineData("Header: \t \t value\r\n\r\n")] public void LeadingWhitespaceIsNotIncludedInHeaderValue(string rawHeaders) { - var trace = new KestrelTrace(new TestKestrelTrace()); - var ltp = new LoggingThreadPool(trace); - using (var pool = new MemoryPool()) - using (var socketInput = new SocketInput(pool, ltp)) - { - var serviceContext = new ServiceContext - { - DateHeaderValueManager = new DateHeaderValueManager(), - ServerOptions = new KestrelServerOptions() - }; - var listenerContext = new ListenerContext(serviceContext) - { - ServerAddress = ServerAddress.FromUrl("http://localhost:5000") - }; - var connectionContext = new ConnectionContext(listenerContext) - { - ConnectionControl = Mock.Of() - }; + var headerArray = Encoding.ASCII.GetBytes(rawHeaders); + _socketInput.IncomingData(headerArray, 0, headerArray.Length); - var frame = new Frame(application: null, context: connectionContext); - frame.Reset(); - frame.InitializeHeaders(); + var success = _frame.TakeMessageHeaders(_socketInput, (FrameRequestHeaders)_frame.RequestHeaders); - var headerArray = Encoding.ASCII.GetBytes(rawHeaders); - socketInput.IncomingData(headerArray, 0, headerArray.Length); + Assert.True(success); + Assert.Equal(1, _frame.RequestHeaders.Count); + Assert.Equal("value", _frame.RequestHeaders["Header"]); - var success = frame.TakeMessageHeaders(socketInput, (FrameRequestHeaders)frame.RequestHeaders); - - Assert.True(success); - Assert.Equal(1, frame.RequestHeaders.Count); - Assert.Equal("value", frame.RequestHeaders["Header"]); - - // Assert TakeMessageHeaders consumed all the input - var scan = socketInput.ConsumingStart(); - Assert.True(scan.IsEnd); - } + // Assert TakeMessageHeaders consumed all the input + var scan = _socketInput.ConsumingStart(); + Assert.True(scan.IsEnd); } [Theory] @@ -127,42 +120,18 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [InlineData("Header: value \t \t \r\n\r\n")] public void TrailingWhitespaceIsNotIncludedInHeaderValue(string rawHeaders) { - var trace = new KestrelTrace(new TestKestrelTrace()); - var ltp = new LoggingThreadPool(trace); - using (var pool = new MemoryPool()) - using (var socketInput = new SocketInput(pool, ltp)) - { - var serviceContext = new ServiceContext - { - DateHeaderValueManager = new DateHeaderValueManager(), - ServerOptions = new KestrelServerOptions() - }; - var listenerContext = new ListenerContext(serviceContext) - { - ServerAddress = ServerAddress.FromUrl("http://localhost:5000") - }; - var connectionContext = new ConnectionContext(listenerContext) - { - ConnectionControl = Mock.Of() - }; + var headerArray = Encoding.ASCII.GetBytes(rawHeaders); + _socketInput.IncomingData(headerArray, 0, headerArray.Length); - var frame = new Frame(application: null, context: connectionContext); - frame.Reset(); - frame.InitializeHeaders(); + var success = _frame.TakeMessageHeaders(_socketInput, (FrameRequestHeaders)_frame.RequestHeaders); - var headerArray = Encoding.ASCII.GetBytes(rawHeaders); - socketInput.IncomingData(headerArray, 0, headerArray.Length); + Assert.True(success); + Assert.Equal(1, _frame.RequestHeaders.Count); + Assert.Equal("value", _frame.RequestHeaders["Header"]); - var success = frame.TakeMessageHeaders(socketInput, (FrameRequestHeaders)frame.RequestHeaders); - - Assert.True(success); - Assert.Equal(1, frame.RequestHeaders.Count); - Assert.Equal("value", frame.RequestHeaders["Header"]); - - // Assert TakeMessageHeaders consumed all the input - var scan = socketInput.ConsumingStart(); - Assert.True(scan.IsEnd); - } + // Assert TakeMessageHeaders consumed all the input + var scan = _socketInput.ConsumingStart(); + Assert.True(scan.IsEnd); } [Theory] @@ -176,43 +145,18 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [InlineData("Header: one \ttwo\t three\r\n\r\n", "one \ttwo\t three")] public void WhitespaceWithinHeaderValueIsPreserved(string rawHeaders, string expectedValue) { - var trace = new KestrelTrace(new TestKestrelTrace()); - var ltp = new LoggingThreadPool(trace); - using (var pool = new MemoryPool()) - using (var socketInput = new SocketInput(pool, ltp)) - { - var serviceContext = new ServiceContext - { - DateHeaderValueManager = new DateHeaderValueManager(), - ServerOptions = new KestrelServerOptions(), - Log = trace - }; - var listenerContext = new ListenerContext(serviceContext) - { - ServerAddress = ServerAddress.FromUrl("http://localhost:5000") - }; - var connectionContext = new ConnectionContext(listenerContext) - { - ConnectionControl = Mock.Of() - }; + var headerArray = Encoding.ASCII.GetBytes(rawHeaders); + _socketInput.IncomingData(headerArray, 0, headerArray.Length); - var frame = new Frame(application: null, context: connectionContext); - frame.Reset(); - frame.InitializeHeaders(); + var success = _frame.TakeMessageHeaders(_socketInput, (FrameRequestHeaders)_frame.RequestHeaders); - var headerArray = Encoding.ASCII.GetBytes(rawHeaders); - socketInput.IncomingData(headerArray, 0, headerArray.Length); + Assert.True(success); + Assert.Equal(1, _frame.RequestHeaders.Count); + Assert.Equal(expectedValue, _frame.RequestHeaders["Header"]); - var success = frame.TakeMessageHeaders(socketInput, (FrameRequestHeaders)frame.RequestHeaders); - - Assert.True(success); - Assert.Equal(1, frame.RequestHeaders.Count); - Assert.Equal(expectedValue, frame.RequestHeaders["Header"]); - - // Assert TakeMessageHeaders consumed all the input - var scan = socketInput.ConsumingStart(); - Assert.True(scan.IsEnd); - } + // Assert TakeMessageHeaders consumed all the input + var scan = _socketInput.ConsumingStart(); + Assert.True(scan.IsEnd); } [Theory] @@ -226,71 +170,27 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [InlineData("Header: line1\r\n \t \t line2\r\n\r\n")] public void TakeMessageHeadersThrowsOnHeaderValueWithLineFolding(string rawHeaders) { - var trace = new KestrelTrace(new TestKestrelTrace()); - var ltp = new LoggingThreadPool(trace); - using (var pool = new MemoryPool()) - using (var socketInput = new SocketInput(pool, ltp)) - { - var serviceContext = new ServiceContext - { - DateHeaderValueManager = new DateHeaderValueManager(), - ServerOptions = new KestrelServerOptions(), - Log = trace - }; - var listenerContext = new ListenerContext(serviceContext) - { - ServerAddress = ServerAddress.FromUrl("http://localhost:5000") - }; - var connectionContext = new ConnectionContext(listenerContext); + var headerArray = Encoding.ASCII.GetBytes(rawHeaders); + _socketInput.IncomingData(headerArray, 0, headerArray.Length); - var frame = new Frame(application: null, context: connectionContext); - frame.Reset(); - frame.InitializeHeaders(); - - var headerArray = Encoding.ASCII.GetBytes(rawHeaders); - socketInput.IncomingData(headerArray, 0, headerArray.Length); - - var exception = Assert.Throws(() => frame.TakeMessageHeaders(socketInput, (FrameRequestHeaders)frame.RequestHeaders)); - Assert.Equal("Header value line folding not supported.", exception.Message); - Assert.Equal(400, exception.StatusCode); - } + var exception = Assert.Throws(() => _frame.TakeMessageHeaders(_socketInput, (FrameRequestHeaders)_frame.RequestHeaders)); + Assert.Equal("Header value line folding not supported.", exception.Message); + Assert.Equal(400, exception.StatusCode); } [Fact] public void TakeMessageHeadersThrowsOnHeaderValueWithLineFolding_CharacterNotAvailableOnFirstAttempt() { - var trace = new KestrelTrace(new TestKestrelTrace()); - var ltp = new LoggingThreadPool(trace); - using (var pool = new MemoryPool()) - using (var socketInput = new SocketInput(pool, ltp)) - { - var serviceContext = new ServiceContext - { - DateHeaderValueManager = new DateHeaderValueManager(), - ServerOptions = new KestrelServerOptions(), - Log = trace - }; - var listenerContext = new ListenerContext(serviceContext) - { - ServerAddress = ServerAddress.FromUrl("http://localhost:5000") - }; - var connectionContext = new ConnectionContext(listenerContext); + var headerArray = Encoding.ASCII.GetBytes("Header-1: value1\r\n"); + _socketInput.IncomingData(headerArray, 0, headerArray.Length); - var frame = new Frame(application: null, context: connectionContext); - frame.Reset(); - frame.InitializeHeaders(); + Assert.False(_frame.TakeMessageHeaders(_socketInput, (FrameRequestHeaders)_frame.RequestHeaders)); - var headerArray = Encoding.ASCII.GetBytes("Header-1: value1\r\n"); - socketInput.IncomingData(headerArray, 0, headerArray.Length); + _socketInput.IncomingData(Encoding.ASCII.GetBytes(" "), 0, 1); - Assert.False(frame.TakeMessageHeaders(socketInput, (FrameRequestHeaders)frame.RequestHeaders)); - - socketInput.IncomingData(Encoding.ASCII.GetBytes(" "), 0, 1); - - var exception = Assert.Throws(() => frame.TakeMessageHeaders(socketInput, (FrameRequestHeaders)frame.RequestHeaders)); - Assert.Equal("Header value line folding not supported.", exception.Message); - Assert.Equal(400, exception.StatusCode); - } + var exception = Assert.Throws(() => _frame.TakeMessageHeaders(_socketInput, (FrameRequestHeaders)_frame.RequestHeaders)); + Assert.Equal("Header value line folding not supported.", exception.Message); + Assert.Equal(400, exception.StatusCode); } [Theory] @@ -301,34 +201,13 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [InlineData("Header-1: value1\r\nHeader-2: v\ralue2\r\n")] public void TakeMessageHeadersThrowsOnHeaderValueContainingCR(string rawHeaders) { - var trace = new KestrelTrace(new TestKestrelTrace()); - var ltp = new LoggingThreadPool(trace); - using (var pool = new MemoryPool()) - using (var socketInput = new SocketInput(pool, ltp)) - { - var serviceContext = new ServiceContext - { - DateHeaderValueManager = new DateHeaderValueManager(), - ServerOptions = new KestrelServerOptions(), - Log = trace - }; - var listenerContext = new ListenerContext(serviceContext) - { - ServerAddress = ServerAddress.FromUrl("http://localhost:5000") - }; - var connectionContext = new ConnectionContext(listenerContext); - var frame = new Frame(application: null, context: connectionContext); - frame.Reset(); - frame.InitializeHeaders(); + var headerArray = Encoding.ASCII.GetBytes(rawHeaders); + _socketInput.IncomingData(headerArray, 0, headerArray.Length); - var headerArray = Encoding.ASCII.GetBytes(rawHeaders); - socketInput.IncomingData(headerArray, 0, headerArray.Length); - - var exception = Assert.Throws(() => frame.TakeMessageHeaders(socketInput, (FrameRequestHeaders)frame.RequestHeaders)); - Assert.Equal("Header value must not contain CR characters.", exception.Message); - Assert.Equal(400, exception.StatusCode); - } + var exception = Assert.Throws(() => _frame.TakeMessageHeaders(_socketInput, (FrameRequestHeaders)_frame.RequestHeaders)); + Assert.Equal("Header value must not contain CR characters.", exception.Message); + Assert.Equal(400, exception.StatusCode); } [Theory] @@ -337,34 +216,12 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [InlineData("Header-1: value1\r\nHeader-2 value2\r\n\r\n")] public void TakeMessageHeadersThrowsOnHeaderLineMissingColon(string rawHeaders) { - var trace = new KestrelTrace(new TestKestrelTrace()); - var ltp = new LoggingThreadPool(trace); - using (var pool = new MemoryPool()) - using (var socketInput = new SocketInput(pool, ltp)) - { - var serviceContext = new ServiceContext - { - DateHeaderValueManager = new DateHeaderValueManager(), - ServerOptions = new KestrelServerOptions(), - Log = trace - }; - var listenerContext = new ListenerContext(serviceContext) - { - ServerAddress = ServerAddress.FromUrl("http://localhost:5000") - }; - var connectionContext = new ConnectionContext(listenerContext); + var headerArray = Encoding.ASCII.GetBytes(rawHeaders); + _socketInput.IncomingData(headerArray, 0, headerArray.Length); - var frame = new Frame(application: null, context: connectionContext); - frame.Reset(); - frame.InitializeHeaders(); - - var headerArray = Encoding.ASCII.GetBytes(rawHeaders); - socketInput.IncomingData(headerArray, 0, headerArray.Length); - - var exception = Assert.Throws(() => frame.TakeMessageHeaders(socketInput, (FrameRequestHeaders)frame.RequestHeaders)); - Assert.Equal("No ':' character found in header line.", exception.Message); - Assert.Equal(400, exception.StatusCode); - } + var exception = Assert.Throws(() => _frame.TakeMessageHeaders(_socketInput, (FrameRequestHeaders)_frame.RequestHeaders)); + Assert.Equal("No ':' character found in header line.", exception.Message); + Assert.Equal(400, exception.StatusCode); } [Theory] @@ -374,34 +231,12 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [InlineData("\tHeader-1: value1\r\nHeader-2: value2\r\n\r\n")] public void TakeMessageHeadersThrowsOnHeaderLineStartingWithWhitespace(string rawHeaders) { - var trace = new KestrelTrace(new TestKestrelTrace()); - var ltp = new LoggingThreadPool(trace); - using (var pool = new MemoryPool()) - using (var socketInput = new SocketInput(pool, ltp)) - { - var serviceContext = new ServiceContext - { - DateHeaderValueManager = new DateHeaderValueManager(), - ServerOptions = new KestrelServerOptions(), - Log = trace - }; - var listenerContext = new ListenerContext(serviceContext) - { - ServerAddress = ServerAddress.FromUrl("http://localhost:5000") - }; - var connectionContext = new ConnectionContext(listenerContext); + var headerArray = Encoding.ASCII.GetBytes(rawHeaders); + _socketInput.IncomingData(headerArray, 0, headerArray.Length); - var frame = new Frame(application: null, context: connectionContext); - frame.Reset(); - frame.InitializeHeaders(); - - var headerArray = Encoding.ASCII.GetBytes(rawHeaders); - socketInput.IncomingData(headerArray, 0, headerArray.Length); - - var exception = Assert.Throws(() => frame.TakeMessageHeaders(socketInput, (FrameRequestHeaders)frame.RequestHeaders)); - Assert.Equal("Header line must not start with whitespace.", exception.Message); - Assert.Equal(400, exception.StatusCode); - } + var exception = Assert.Throws(() => _frame.TakeMessageHeaders(_socketInput, (FrameRequestHeaders)_frame.RequestHeaders)); + Assert.Equal("Header line must not start with whitespace.", exception.Message); + Assert.Equal(400, exception.StatusCode); } [Theory] @@ -415,34 +250,12 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [InlineData("Header-1: value1\r\nHeader-2\t: value2\r\n\r\n")] public void TakeMessageHeadersThrowsOnWhitespaceInHeaderName(string rawHeaders) { - var trace = new KestrelTrace(new TestKestrelTrace()); - var ltp = new LoggingThreadPool(trace); - using (var pool = new MemoryPool()) - using (var socketInput = new SocketInput(pool, ltp)) - { - var serviceContext = new ServiceContext - { - DateHeaderValueManager = new DateHeaderValueManager(), - ServerOptions = new KestrelServerOptions(), - Log = trace - }; - var listenerContext = new ListenerContext(serviceContext) - { - ServerAddress = ServerAddress.FromUrl("http://localhost:5000") - }; - var connectionContext = new ConnectionContext(listenerContext); + var headerArray = Encoding.ASCII.GetBytes(rawHeaders); + _socketInput.IncomingData(headerArray, 0, headerArray.Length); - var frame = new Frame(application: null, context: connectionContext); - frame.Reset(); - frame.InitializeHeaders(); - - var headerArray = Encoding.ASCII.GetBytes(rawHeaders); - socketInput.IncomingData(headerArray, 0, headerArray.Length); - - var exception = Assert.Throws(() => frame.TakeMessageHeaders(socketInput, (FrameRequestHeaders)frame.RequestHeaders)); - Assert.Equal("Whitespace is not allowed in header name.", exception.Message); - Assert.Equal(400, exception.StatusCode); - } + var exception = Assert.Throws(() => _frame.TakeMessageHeaders(_socketInput, (FrameRequestHeaders)_frame.RequestHeaders)); + Assert.Equal("Whitespace is not allowed in header name.", exception.Message); + Assert.Equal(400, exception.StatusCode); } [Theory] @@ -451,110 +264,41 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [InlineData("Header-1: value1\r\nHeader-2: value2\r\n\r \n")] public void TakeMessageHeadersThrowsOnHeadersNotEndingInCRLFLine(string rawHeaders) { - var trace = new KestrelTrace(new TestKestrelTrace()); - var ltp = new LoggingThreadPool(trace); - using (var pool = new MemoryPool()) - using (var socketInput = new SocketInput(pool, ltp)) - { - var serviceContext = new ServiceContext - { - DateHeaderValueManager = new DateHeaderValueManager(), - ServerOptions = new KestrelServerOptions(), - Log = trace - }; - var listenerContext = new ListenerContext(serviceContext) - { - ServerAddress = ServerAddress.FromUrl("http://localhost:5000") - }; - var connectionContext = new ConnectionContext(listenerContext); + var headerArray = Encoding.ASCII.GetBytes(rawHeaders); + _socketInput.IncomingData(headerArray, 0, headerArray.Length); - var frame = new Frame(application: null, context: connectionContext); - frame.Reset(); - frame.InitializeHeaders(); - - var headerArray = Encoding.ASCII.GetBytes(rawHeaders); - socketInput.IncomingData(headerArray, 0, headerArray.Length); - - var exception = Assert.Throws(() => frame.TakeMessageHeaders(socketInput, (FrameRequestHeaders)frame.RequestHeaders)); - Assert.Equal("Headers corrupted, invalid header sequence.", exception.Message); - Assert.Equal(400, exception.StatusCode); - } + var exception = Assert.Throws(() => _frame.TakeMessageHeaders(_socketInput, (FrameRequestHeaders)_frame.RequestHeaders)); + Assert.Equal("Headers corrupted, invalid header sequence.", exception.Message); + Assert.Equal(400, exception.StatusCode); } [Fact] public void TakeMessageHeadersThrowsWhenHeadersExceedTotalSizeLimit() { - var trace = new KestrelTrace(new TestKestrelTrace()); - var ltp = new LoggingThreadPool(trace); - using (var pool = new MemoryPool()) - using (var socketInput = new SocketInput(pool, ltp)) - { - const string headerLine = "Header: value\r\n"; + const string headerLine = "Header: value\r\n"; + _serviceContext.ServerOptions.Limits.MaxRequestHeadersTotalSize = headerLine.Length - 1; + _frame.Reset(); - var options = new KestrelServerOptions(); - options.Limits.MaxRequestHeadersTotalSize = headerLine.Length - 1; + var headerArray = Encoding.ASCII.GetBytes($"{headerLine}\r\n"); + _socketInput.IncomingData(headerArray, 0, headerArray.Length); - var serviceContext = new ServiceContext - { - DateHeaderValueManager = new DateHeaderValueManager(), - ServerOptions = options, - Log = trace - }; - var listenerContext = new ListenerContext(serviceContext) - { - ServerAddress = ServerAddress.FromUrl("http://localhost:5000") - }; - var connectionContext = new ConnectionContext(listenerContext); - - var frame = new Frame(application: null, context: connectionContext); - frame.Reset(); - frame.InitializeHeaders(); - - var headerArray = Encoding.ASCII.GetBytes($"{headerLine}\r\n"); - socketInput.IncomingData(headerArray, 0, headerArray.Length); - - var exception = Assert.Throws(() => frame.TakeMessageHeaders(socketInput, (FrameRequestHeaders)frame.RequestHeaders)); - Assert.Equal("Request headers too long.", exception.Message); - Assert.Equal(431, exception.StatusCode); - } + var exception = Assert.Throws(() => _frame.TakeMessageHeaders(_socketInput, (FrameRequestHeaders)_frame.RequestHeaders)); + Assert.Equal("Request headers too long.", exception.Message); + Assert.Equal(431, exception.StatusCode); } [Fact] public void TakeMessageHeadersThrowsWhenHeadersExceedCountLimit() { - var trace = new KestrelTrace(new TestKestrelTrace()); - var ltp = new LoggingThreadPool(trace); - using (var pool = new MemoryPool()) - using (var socketInput = new SocketInput(pool, ltp)) - { - const string headerLines = "Header-1: value1\r\nHeader-2: value2\r\n"; + const string headerLines = "Header-1: value1\r\nHeader-2: value2\r\n"; + _serviceContext.ServerOptions.Limits.MaxRequestHeaderCount = 1; - var options = new KestrelServerOptions(); - options.Limits.MaxRequestHeaderCount = 1; + var headerArray = Encoding.ASCII.GetBytes($"{headerLines}\r\n"); + _socketInput.IncomingData(headerArray, 0, headerArray.Length); - var serviceContext = new ServiceContext - { - DateHeaderValueManager = new DateHeaderValueManager(), - ServerOptions = options, - Log = trace - }; - var listenerContext = new ListenerContext(serviceContext) - { - ServerAddress = ServerAddress.FromUrl("http://localhost:5000") - }; - var connectionContext = new ConnectionContext(listenerContext); - - var frame = new Frame(application: null, context: connectionContext); - frame.Reset(); - frame.InitializeHeaders(); - - var headerArray = Encoding.ASCII.GetBytes($"{headerLines}\r\n"); - socketInput.IncomingData(headerArray, 0, headerArray.Length); - - var exception = Assert.Throws(() => frame.TakeMessageHeaders(socketInput, (FrameRequestHeaders)frame.RequestHeaders)); - Assert.Equal("Request contains too many headers.", exception.Message); - Assert.Equal(431, exception.StatusCode); - } + var exception = Assert.Throws(() => _frame.TakeMessageHeaders(_socketInput, (FrameRequestHeaders)_frame.RequestHeaders)); + Assert.Equal("Request contains too many headers.", exception.Message); + Assert.Equal(431, exception.StatusCode); } [Theory] @@ -566,341 +310,154 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [InlineData("Connection: close\r\nCookie:\r\n\r\n", 2)] public void EmptyHeaderValuesCanBeParsed(string rawHeaders, int numHeaders) { - var trace = new KestrelTrace(new TestKestrelTrace()); - var ltp = new LoggingThreadPool(trace); - using (var pool = new MemoryPool()) - using (var socketInput = new SocketInput(pool, ltp)) - { - var serviceContext = new ServiceContext - { - DateHeaderValueManager = new DateHeaderValueManager(), - ServerOptions = new KestrelServerOptions() - }; - var listenerContext = new ListenerContext(serviceContext) - { - ServerAddress = ServerAddress.FromUrl("http://localhost:5000") - }; - var connectionContext = new ConnectionContext(listenerContext) - { - ConnectionControl = Mock.Of() - }; + var headerArray = Encoding.ASCII.GetBytes(rawHeaders); + _socketInput.IncomingData(headerArray, 0, headerArray.Length); - var frame = new Frame(application: null, context: connectionContext); - frame.Reset(); - frame.InitializeHeaders(); + var success = _frame.TakeMessageHeaders(_socketInput, (FrameRequestHeaders)_frame.RequestHeaders); - var headerArray = Encoding.ASCII.GetBytes(rawHeaders); - socketInput.IncomingData(headerArray, 0, headerArray.Length); + Assert.True(success); + Assert.Equal(numHeaders, _frame.RequestHeaders.Count); - var success = frame.TakeMessageHeaders(socketInput, (FrameRequestHeaders)frame.RequestHeaders); - - Assert.True(success); - Assert.Equal(numHeaders, frame.RequestHeaders.Count); - - // Assert TakeMessageHeaders consumed all the input - var scan = socketInput.ConsumingStart(); - Assert.True(scan.IsEnd); - } + // Assert TakeMessageHeaders consumed all the input + var scan = _socketInput.ConsumingStart(); + Assert.True(scan.IsEnd); } [Fact] public void ResetResetsScheme() { - // Arrange - var serviceContext = new ServiceContext - { - DateHeaderValueManager = new DateHeaderValueManager(), - ServerOptions = new KestrelServerOptions() - }; - var listenerContext = new ListenerContext(serviceContext) - { - ServerAddress = ServerAddress.FromUrl("http://localhost:5000") - }; - var connectionContext = new ConnectionContext(listenerContext); - - var frame = new Frame(application: null, context: connectionContext); - frame.Scheme = "https"; + _frame.Scheme = "https"; // Act - frame.Reset(); + _frame.Reset(); // Assert - Assert.Equal("http", ((IFeatureCollection)frame).Get().Scheme); + Assert.Equal("http", ((IFeatureCollection)_frame).Get().Scheme); } [Fact] public void ResetResetsHeaderLimits() { - var trace = new KestrelTrace(new TestKestrelTrace()); - var ltp = new LoggingThreadPool(trace); - using (var pool = new MemoryPool()) - using (var socketInput = new SocketInput(pool, ltp)) - { - const string headerLine1 = "Header-1: value1\r\n"; - const string headerLine2 = "Header-2: value2\r\n"; + const string headerLine1 = "Header-1: value1\r\n"; + const string headerLine2 = "Header-2: value2\r\n"; - var options = new KestrelServerOptions(); - options.Limits.MaxRequestHeadersTotalSize = headerLine1.Length; - options.Limits.MaxRequestHeaderCount = 1; + var options = new KestrelServerOptions(); + options.Limits.MaxRequestHeadersTotalSize = headerLine1.Length; + options.Limits.MaxRequestHeaderCount = 1; + _serviceContext.ServerOptions = options; - var serviceContext = new ServiceContext - { - DateHeaderValueManager = new DateHeaderValueManager(), - ServerOptions = options - }; - var listenerContext = new ListenerContext(serviceContext) - { - ServerAddress = ServerAddress.FromUrl("http://localhost:5000") - }; - var connectionContext = new ConnectionContext(listenerContext) - { - ConnectionControl = Mock.Of() - }; + var headerArray1 = Encoding.ASCII.GetBytes($"{headerLine1}\r\n"); + _socketInput.IncomingData(headerArray1, 0, headerArray1.Length); - var frame = new Frame(application: null, context: connectionContext); - frame.Reset(); - frame.InitializeHeaders(); + Assert.True(_frame.TakeMessageHeaders(_socketInput, (FrameRequestHeaders)_frame.RequestHeaders)); + Assert.Equal(1, _frame.RequestHeaders.Count); + Assert.Equal("value1", _frame.RequestHeaders["Header-1"]); - var headerArray1 = Encoding.ASCII.GetBytes($"{headerLine1}\r\n"); - socketInput.IncomingData(headerArray1, 0, headerArray1.Length); + _frame.Reset(); - Assert.True(frame.TakeMessageHeaders(socketInput, (FrameRequestHeaders)frame.RequestHeaders)); - Assert.Equal(1, frame.RequestHeaders.Count); - Assert.Equal("value1", frame.RequestHeaders["Header-1"]); + var headerArray2 = Encoding.ASCII.GetBytes($"{headerLine2}\r\n"); + _socketInput.IncomingData(headerArray2, 0, headerArray1.Length); - frame.Reset(); - - var headerArray2 = Encoding.ASCII.GetBytes($"{headerLine2}\r\n"); - socketInput.IncomingData(headerArray2, 0, headerArray1.Length); - - Assert.True(frame.TakeMessageHeaders(socketInput, (FrameRequestHeaders)frame.RequestHeaders)); - Assert.Equal(1, frame.RequestHeaders.Count); - Assert.Equal("value2", frame.RequestHeaders["Header-2"]); - } + Assert.True(_frame.TakeMessageHeaders(_socketInput, (FrameRequestHeaders)_frame.RequestHeaders)); + Assert.Equal(1, _frame.RequestHeaders.Count); + Assert.Equal("value2", _frame.RequestHeaders["Header-2"]); } [Fact] public void ThrowsWhenStatusCodeIsSetAfterResponseStarted() { - // Arrange - var serviceContext = new ServiceContext - { - DateHeaderValueManager = new DateHeaderValueManager(), - ServerOptions = new KestrelServerOptions() - }; - var listenerContext = new ListenerContext(serviceContext) - { - ServerAddress = ServerAddress.FromUrl("http://localhost:5000") - }; - var connectionContext = new ConnectionContext(listenerContext) - { - SocketOutput = new MockSocketOuptut() - }; - - var frame = new Frame(application: null, context: connectionContext); - frame.InitializeHeaders(); - // Act - frame.Write(new ArraySegment(new byte[1])); + _frame.Write(new ArraySegment(new byte[1])); // Assert - Assert.True(frame.HasResponseStarted); - Assert.Throws(() => ((IHttpResponseFeature)frame).StatusCode = 404); + Assert.True(_frame.HasResponseStarted); + Assert.Throws(() => ((IHttpResponseFeature)_frame).StatusCode = 404); } [Fact] public void ThrowsWhenReasonPhraseIsSetAfterResponseStarted() { - // Arrange - var serviceContext = new ServiceContext - { - DateHeaderValueManager = new DateHeaderValueManager(), - ServerOptions = new KestrelServerOptions() - }; - var listenerContext = new ListenerContext(serviceContext) - { - ServerAddress = ServerAddress.FromUrl("http://localhost:5000") - }; - var connectionContext = new ConnectionContext(listenerContext) - { - SocketOutput = new MockSocketOuptut() - }; - - var frame = new Frame(application: null, context: connectionContext); - frame.InitializeHeaders(); - // Act - frame.Write(new ArraySegment(new byte[1])); + _frame.Write(new ArraySegment(new byte[1])); // Assert - Assert.True(frame.HasResponseStarted); - Assert.Throws(() => ((IHttpResponseFeature)frame).ReasonPhrase = "Reason phrase"); + Assert.True(_frame.HasResponseStarted); + Assert.Throws(() => ((IHttpResponseFeature)_frame).ReasonPhrase = "Reason phrase"); } [Fact] public void ThrowsWhenOnStartingIsSetAfterResponseStarted() { - // Arrange - var serviceContext = new ServiceContext - { - DateHeaderValueManager = new DateHeaderValueManager(), - ServerOptions = new KestrelServerOptions() - }; - var listenerContext = new ListenerContext(serviceContext) - { - ServerAddress = ServerAddress.FromUrl("http://localhost:5000") - }; - var connectionContext = new ConnectionContext(listenerContext) - { - SocketOutput = new MockSocketOuptut() - }; - - var frame = new Frame(application: null, context: connectionContext); - frame.InitializeHeaders(); - frame.Write(new ArraySegment(new byte[1])); + _frame.Write(new ArraySegment(new byte[1])); // Act/Assert - Assert.True(frame.HasResponseStarted); - Assert.Throws(() => ((IHttpResponseFeature)frame).OnStarting(_ => TaskCache.CompletedTask, null)); + Assert.True(_frame.HasResponseStarted); + Assert.Throws(() => ((IHttpResponseFeature)_frame).OnStarting(_ => TaskCache.CompletedTask, null)); } [Fact] public void InitializeHeadersResetsRequestHeaders() { // Arrange - var serviceContext = new ServiceContext - { - DateHeaderValueManager = new DateHeaderValueManager(), - ServerOptions = new KestrelServerOptions() - }; - var listenerContext = new ListenerContext(serviceContext) - { - ServerAddress = ServerAddress.FromUrl("http://localhost:5000") - }; - var connectionContext = new ConnectionContext(listenerContext) - { - SocketOutput = new MockSocketOuptut() - }; - - var frame = new Frame(application: null, context: connectionContext); - frame.InitializeHeaders(); - - var originalRequestHeaders = frame.RequestHeaders; - frame.RequestHeaders = new FrameRequestHeaders(); + var originalRequestHeaders = _frame.RequestHeaders; + _frame.RequestHeaders = new FrameRequestHeaders(); // Act - frame.InitializeHeaders(); + _frame.InitializeHeaders(); // Assert - Assert.Same(originalRequestHeaders, frame.RequestHeaders); + Assert.Same(originalRequestHeaders, _frame.RequestHeaders); } [Fact] public void InitializeHeadersResetsResponseHeaders() { // Arrange - var serviceContext = new ServiceContext - { - DateHeaderValueManager = new DateHeaderValueManager(), - ServerOptions = new KestrelServerOptions() - }; - var listenerContext = new ListenerContext(serviceContext) - { - ServerAddress = ServerAddress.FromUrl("http://localhost:5000") - }; - var connectionContext = new ConnectionContext(listenerContext) - { - SocketOutput = new MockSocketOuptut() - }; - - var frame = new Frame(application: null, context: connectionContext); - frame.InitializeHeaders(); - - var originalResponseHeaders = frame.ResponseHeaders; - frame.ResponseHeaders = new FrameResponseHeaders(); + var originalResponseHeaders = _frame.ResponseHeaders; + _frame.ResponseHeaders = new FrameResponseHeaders(); // Act - frame.InitializeHeaders(); + _frame.InitializeHeaders(); // Assert - Assert.Same(originalResponseHeaders, frame.ResponseHeaders); + Assert.Same(originalResponseHeaders, _frame.ResponseHeaders); } [Fact] public void InitializeStreamsResetsStreams() { // Arrange - var serviceContext = new ServiceContext - { - DateHeaderValueManager = new DateHeaderValueManager(), - ServerOptions = new KestrelServerOptions() - }; - var listenerContext = new ListenerContext(serviceContext) - { - ServerAddress = ServerAddress.FromUrl("http://localhost:5000") - }; - var connectionContext = new ConnectionContext(listenerContext) - { - SocketOutput = new MockSocketOuptut() - }; + var messageBody = MessageBody.For(HttpVersion.Http11, (FrameRequestHeaders)_frame.RequestHeaders, _frame); + _frame.InitializeStreams(messageBody); - var frame = new Frame(application: null, context: connectionContext); - frame.InitializeHeaders(); - - var messageBody = MessageBody.For(HttpVersion.Http11, (FrameRequestHeaders)frame.RequestHeaders, frame); - frame.InitializeStreams(messageBody); - - var originalRequestBody = frame.RequestBody; - var originalResponseBody = frame.ResponseBody; - var originalDuplexStream = frame.DuplexStream; - frame.RequestBody = new MemoryStream(); - frame.ResponseBody = new MemoryStream(); - frame.DuplexStream = new MemoryStream(); + var originalRequestBody = _frame.RequestBody; + var originalResponseBody = _frame.ResponseBody; + var originalDuplexStream = _frame.DuplexStream; + _frame.RequestBody = new MemoryStream(); + _frame.ResponseBody = new MemoryStream(); + _frame.DuplexStream = new MemoryStream(); // Act - frame.InitializeStreams(messageBody); + _frame.InitializeStreams(messageBody); // Assert - Assert.Same(originalRequestBody, frame.RequestBody); - Assert.Same(originalResponseBody, frame.ResponseBody); - Assert.Same(originalDuplexStream, frame.DuplexStream); + Assert.Same(originalRequestBody, _frame.RequestBody); + Assert.Same(originalResponseBody, _frame.ResponseBody); + Assert.Same(originalDuplexStream, _frame.DuplexStream); } [Fact] public void TakeStartLineCallsConsumingCompleteWithFurthestExamined() { - var trace = new KestrelTrace(new TestKestrelTrace()); - var ltp = new LoggingThreadPool(trace); - using (var pool = new MemoryPool()) - using (var socketInput = new SocketInput(pool, ltp)) - { - var serviceContext = new ServiceContext - { - DateHeaderValueManager = new DateHeaderValueManager(), - ServerOptions = new KestrelServerOptions(), - Log = trace - }; - var listenerContext = new ListenerContext(serviceContext) - { - ServerAddress = ServerAddress.FromUrl("http://localhost:5000"), - }; - var connectionContext = new ConnectionContext(listenerContext) - { - ConnectionControl = new Mock().Object - }; - var frame = new Frame(application: null, context: connectionContext); - frame.Reset(); + var requestLineBytes = Encoding.ASCII.GetBytes("GET / "); + _socketInput.IncomingData(requestLineBytes, 0, requestLineBytes.Length); + _frame.TakeStartLine(_socketInput); + Assert.False(_socketInput.IsCompleted); - var requestLineBytes = Encoding.ASCII.GetBytes("GET / "); - socketInput.IncomingData(requestLineBytes, 0, requestLineBytes.Length); - frame.TakeStartLine(socketInput); - Assert.False(socketInput.IsCompleted); - - requestLineBytes = Encoding.ASCII.GetBytes("HTTP/1.1\r\n"); - socketInput.IncomingData(requestLineBytes, 0, requestLineBytes.Length); - frame.TakeStartLine(socketInput); - Assert.False(socketInput.IsCompleted); - } + requestLineBytes = Encoding.ASCII.GetBytes("HTTP/1.1\r\n"); + _socketInput.IncomingData(requestLineBytes, 0, requestLineBytes.Length); + _frame.TakeStartLine(_socketInput); + Assert.False(_socketInput.IsCompleted); } [Theory] @@ -922,140 +479,48 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [InlineData("GET / HTTP/1.1\r", Frame.RequestLineStatus.Incomplete)] public void TakeStartLineReturnsWhenGivenIncompleteRequestLines(string requestLine, Frame.RequestLineStatus expectedReturnValue) { - var trace = new KestrelTrace(new TestKestrelTrace()); - var ltp = new LoggingThreadPool(trace); - using (var pool = new MemoryPool()) - using (var socketInput = new SocketInput(pool, ltp)) - { - var serviceContext = new ServiceContext - { - DateHeaderValueManager = new DateHeaderValueManager(), - ServerOptions = new KestrelServerOptions(), - Log = trace - }; - var listenerContext = new ListenerContext(serviceContext) - { - ServerAddress = ServerAddress.FromUrl("http://localhost:5000"), - }; - var connectionContext = new ConnectionContext(listenerContext) - { - ConnectionControl = new Mock().Object - }; - var frame = new Frame(application: null, context: connectionContext); - frame.Reset(); + var requestLineBytes = Encoding.ASCII.GetBytes(requestLine); + _socketInput.IncomingData(requestLineBytes, 0, requestLineBytes.Length); - var requestLineBytes = Encoding.ASCII.GetBytes(requestLine); - socketInput.IncomingData(requestLineBytes, 0, requestLineBytes.Length); - - var returnValue = frame.TakeStartLine(socketInput); - Assert.Equal(expectedReturnValue, returnValue); - } + var returnValue = _frame.TakeStartLine(_socketInput); + Assert.Equal(expectedReturnValue, returnValue); } [Fact] public void TakeStartLineStartsRequestHeadersTimeoutOnFirstByteAvailable() { - var trace = new KestrelTrace(new TestKestrelTrace()); - var ltp = new LoggingThreadPool(trace); - using (var pool = new MemoryPool()) - using (var socketInput = new SocketInput(pool, ltp)) - { - var serviceContext = new ServiceContext - { - DateHeaderValueManager = new DateHeaderValueManager(), - ServerOptions = new KestrelServerOptions(), - Log = trace - }; - var listenerContext = new ListenerContext(serviceContext) - { - ServerAddress = ServerAddress.FromUrl("http://localhost:5000"), - }; - var connectionControl = new Mock(); - var connectionContext = new ConnectionContext(listenerContext) - { - ConnectionControl = connectionControl.Object - }; - var frame = new Frame(application: null, context: connectionContext); - frame.Reset(); + var connectionControl = new Mock(); + _connectionContext.ConnectionControl = connectionControl.Object; - var requestLineBytes = Encoding.ASCII.GetBytes("G"); - socketInput.IncomingData(requestLineBytes, 0, requestLineBytes.Length); + var requestLineBytes = Encoding.ASCII.GetBytes("G"); + _socketInput.IncomingData(requestLineBytes, 0, requestLineBytes.Length); - frame.TakeStartLine(socketInput); - var expectedRequestHeadersTimeout = (long)serviceContext.ServerOptions.Limits.RequestHeadersTimeout.TotalMilliseconds; - connectionControl.Verify(cc => cc.ResetTimeout(expectedRequestHeadersTimeout, TimeoutAction.SendTimeoutResponse)); - } + _frame.TakeStartLine(_socketInput); + var expectedRequestHeadersTimeout = (long)_serviceContext.ServerOptions.Limits.RequestHeadersTimeout.TotalMilliseconds; + connectionControl.Verify(cc => cc.ResetTimeout(expectedRequestHeadersTimeout, TimeoutAction.SendTimeoutResponse)); } [Fact] public void TakeStartLineDoesNotStartRequestHeadersTimeoutIfNoDataAvailable() { - var trace = new KestrelTrace(new TestKestrelTrace()); - var ltp = new LoggingThreadPool(trace); - using (var pool = new MemoryPool()) - using (var socketInput = new SocketInput(pool, ltp)) - { - var serviceContext = new ServiceContext - { - DateHeaderValueManager = new DateHeaderValueManager(), - ServerOptions = new KestrelServerOptions(), - Log = trace - }; - var listenerContext = new ListenerContext(serviceContext) - { - ServerAddress = ServerAddress.FromUrl("http://localhost:5000") - }; - var connectionControl = new Mock(); - var connectionContext = new ConnectionContext(listenerContext) - { - ConnectionControl = connectionControl.Object - }; - var frame = new Frame(application: null, context: connectionContext); - frame.Reset(); + var connectionControl = new Mock(); + _connectionContext.ConnectionControl = connectionControl.Object; - frame.TakeStartLine(socketInput); - connectionControl.Verify(cc => cc.ResetTimeout(It.IsAny(), It.IsAny()), Times.Never); - } + _frame.TakeStartLine(_socketInput); + connectionControl.Verify(cc => cc.ResetTimeout(It.IsAny(), It.IsAny()), Times.Never); } [Fact] public void TakeStartLineThrowsWhenTooLong() { - var trace = new KestrelTrace(new TestKestrelTrace()); - var ltp = new LoggingThreadPool(trace); - using (var pool = new MemoryPool()) - using (var socketInput = new SocketInput(pool, ltp)) - { - var serviceContext = new ServiceContext - { - DateHeaderValueManager = new DateHeaderValueManager(), - ServerOptions = new KestrelServerOptions() - { - Limits = - { - MaxRequestLineSize = "GET / HTTP/1.1\r\n".Length - } - }, - Log = trace - }; - var listenerContext = new ListenerContext(serviceContext) - { - ServerAddress = ServerAddress.FromUrl("http://localhost:5000") - }; - var connectionContext = new ConnectionContext(listenerContext) - { - ConnectionControl = Mock.Of() - }; - var frame = new Frame(application: null, context: connectionContext); - frame.Reset(); + _serviceContext.ServerOptions.Limits.MaxRequestLineSize = "GET / HTTP/1.1\r\n".Length; - var requestLineBytes = Encoding.ASCII.GetBytes("GET /a HTTP/1.1\r\n"); - socketInput.IncomingData(requestLineBytes, 0, requestLineBytes.Length); + var requestLineBytes = Encoding.ASCII.GetBytes("GET /a HTTP/1.1\r\n"); + _socketInput.IncomingData(requestLineBytes, 0, requestLineBytes.Length); - var exception = Assert.Throws(() => frame.TakeStartLine(socketInput)); - Assert.Equal("Request line too long.", exception.Message); - Assert.Equal(414, exception.StatusCode); - } + var exception = Assert.Throws(() => _frame.TakeStartLine(_socketInput)); + Assert.Equal("Request line too long.", exception.Message); + Assert.Equal(414, exception.StatusCode); } [Theory] @@ -1072,146 +537,53 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [InlineData("GET / HTTP/1.1\ra\n", "Invalid request line: GET / HTTP/1.1<0x0D>a<0x0A>")] public void TakeStartLineThrowsWhenInvalid(string requestLine, string expectedExceptionMessage) { - var trace = new KestrelTrace(new TestKestrelTrace()); - var ltp = new LoggingThreadPool(trace); - using (var pool = new MemoryPool()) - using (var socketInput = new SocketInput(pool, ltp)) - { - var serviceContext = new ServiceContext - { - DateHeaderValueManager = new DateHeaderValueManager(), - ServerOptions = new KestrelServerOptions(), - Log = trace - }; - var listenerContext = new ListenerContext(serviceContext) - { - ServerAddress = ServerAddress.FromUrl("http://localhost:5000") - }; - var connectionContext = new ConnectionContext(listenerContext) - { - ConnectionControl = Mock.Of() - }; - var frame = new Frame(application: null, context: connectionContext); - frame.Reset(); + var requestLineBytes = Encoding.ASCII.GetBytes(requestLine); + _socketInput.IncomingData(requestLineBytes, 0, requestLineBytes.Length); - var requestLineBytes = Encoding.ASCII.GetBytes(requestLine); - socketInput.IncomingData(requestLineBytes, 0, requestLineBytes.Length); - - var exception = Assert.Throws(() => frame.TakeStartLine(socketInput)); - Assert.Equal(expectedExceptionMessage, exception.Message); - Assert.Equal(400, exception.StatusCode); - } + var exception = Assert.Throws(() => _frame.TakeStartLine(_socketInput)); + Assert.Equal(expectedExceptionMessage, exception.Message); + Assert.Equal(400, exception.StatusCode); } [Fact] public void TakeStartLineThrowsOnUnsupportedHttpVersion() { - var trace = new KestrelTrace(new TestKestrelTrace()); - var ltp = new LoggingThreadPool(trace); - using (var pool = new MemoryPool()) - using (var socketInput = new SocketInput(pool, ltp)) - { - var serviceContext = new ServiceContext - { - DateHeaderValueManager = new DateHeaderValueManager(), - ServerOptions = new KestrelServerOptions(), - Log = trace - }; - var listenerContext = new ListenerContext(serviceContext) - { - ServerAddress = ServerAddress.FromUrl("http://localhost:5000") - }; - var connectionContext = new ConnectionContext(listenerContext) - { - ConnectionControl = Mock.Of(), - }; - var frame = new Frame(application: null, context: connectionContext); - frame.Reset(); + var requestLineBytes = Encoding.ASCII.GetBytes("GET / HTTP/1.2\r\n"); + _socketInput.IncomingData(requestLineBytes, 0, requestLineBytes.Length); - var requestLineBytes = Encoding.ASCII.GetBytes("GET / HTTP/1.2\r\n"); - socketInput.IncomingData(requestLineBytes, 0, requestLineBytes.Length); - - var exception = Assert.Throws(() => frame.TakeStartLine(socketInput)); - Assert.Equal("Unrecognized HTTP version: HTTP/1.2", exception.Message); - Assert.Equal(505, exception.StatusCode); - } + var exception = Assert.Throws(() => _frame.TakeStartLine(_socketInput)); + Assert.Equal("Unrecognized HTTP version: HTTP/1.2", exception.Message); + Assert.Equal(505, exception.StatusCode); } [Fact] - public void TakeStartLineThrowsOnUnsupportedHttpVersionLongerThanEigthCharacters() + public void TakeStartLineThrowsOnUnsupportedHttpVersionLongerThanEightCharacters() { - var trace = new KestrelTrace(new TestKestrelTrace()); - var ltp = new LoggingThreadPool(trace); - using (var pool = new MemoryPool()) - using (var socketInput = new SocketInput(pool, ltp)) - { - var serviceContext = new ServiceContext - { - DateHeaderValueManager = new DateHeaderValueManager(), - ServerOptions = new KestrelServerOptions(), - Log = trace - }; - var listenerContext = new ListenerContext(serviceContext) - { - ServerAddress = ServerAddress.FromUrl("http://localhost:5000") - }; - var connectionContext = new ConnectionContext(listenerContext) - { - ConnectionControl = Mock.Of(), - }; - var frame = new Frame(application: null, context: connectionContext); - frame.Reset(); + var requestLineBytes = Encoding.ASCII.GetBytes("GET / HTTP/1.1ab\r\n"); + _socketInput.IncomingData(requestLineBytes, 0, requestLineBytes.Length); - var requestLineBytes = Encoding.ASCII.GetBytes("GET / HTTP/1.1ab\r\n"); - socketInput.IncomingData(requestLineBytes, 0, requestLineBytes.Length); - - var exception = Assert.Throws(() => frame.TakeStartLine(socketInput)); - Assert.Equal("Unrecognized HTTP version: HTTP/1.1a...", exception.Message); - Assert.Equal(505, exception.StatusCode); - } + var exception = Assert.Throws(() => _frame.TakeStartLine(_socketInput)); + Assert.Equal("Unrecognized HTTP version: HTTP/1.1a...", exception.Message); + Assert.Equal(505, exception.StatusCode); } [Fact] public void TakeMessageHeadersCallsConsumingCompleteWithFurthestExamined() { - var trace = new KestrelTrace(new TestKestrelTrace()); - var ltp = new LoggingThreadPool(trace); - using (var pool = new MemoryPool()) - using (var socketInput = new SocketInput(pool, ltp)) - { - var serviceContext = new ServiceContext - { - DateHeaderValueManager = new DateHeaderValueManager(), - ServerOptions = new KestrelServerOptions(), - Log = trace - }; - var listenerContext = new ListenerContext(serviceContext) - { - ServerAddress = ServerAddress.FromUrl("http://localhost:5000") - }; - var connectionContext = new ConnectionContext(listenerContext) - { - ConnectionControl = Mock.Of() - }; - var frame = new Frame(application: null, context: connectionContext); - frame.Reset(); - frame.InitializeHeaders(); + var headersBytes = Encoding.ASCII.GetBytes("Header: "); + _socketInput.IncomingData(headersBytes, 0, headersBytes.Length); + _frame.TakeMessageHeaders(_socketInput, (FrameRequestHeaders)_frame.RequestHeaders); + Assert.False(_socketInput.IsCompleted); - var headersBytes = Encoding.ASCII.GetBytes("Header: "); - socketInput.IncomingData(headersBytes, 0, headersBytes.Length); - frame.TakeMessageHeaders(socketInput, (FrameRequestHeaders)frame.RequestHeaders); - Assert.False(socketInput.IsCompleted); + headersBytes = Encoding.ASCII.GetBytes("value\r\n"); + _socketInput.IncomingData(headersBytes, 0, headersBytes.Length); + _frame.TakeMessageHeaders(_socketInput, (FrameRequestHeaders)_frame.RequestHeaders); + Assert.False(_socketInput.IsCompleted); - headersBytes = Encoding.ASCII.GetBytes("value\r\n"); - socketInput.IncomingData(headersBytes, 0, headersBytes.Length); - frame.TakeMessageHeaders(socketInput, (FrameRequestHeaders)frame.RequestHeaders); - Assert.False(socketInput.IsCompleted); - - headersBytes = Encoding.ASCII.GetBytes("\r\n"); - socketInput.IncomingData(headersBytes, 0, headersBytes.Length); - frame.TakeMessageHeaders(socketInput, (FrameRequestHeaders)frame.RequestHeaders); - Assert.False(socketInput.IsCompleted); - } + headersBytes = Encoding.ASCII.GetBytes("\r\n"); + _socketInput.IncomingData(headersBytes, 0, headersBytes.Length); + _frame.TakeMessageHeaders(_socketInput, (FrameRequestHeaders)_frame.RequestHeaders); + Assert.False(_socketInput.IsCompleted); } [Theory] @@ -1234,275 +606,113 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [InlineData("Header: value\r\n\r")] public void TakeMessageHeadersReturnsWhenGivenIncompleteHeaders(string headers) { - var trace = new KestrelTrace(new TestKestrelTrace()); - var ltp = new LoggingThreadPool(trace); - using (var pool = new MemoryPool()) - using (var socketInput = new SocketInput(pool, ltp)) - { - var serviceContext = new ServiceContext - { - DateHeaderValueManager = new DateHeaderValueManager(), - ServerOptions = new KestrelServerOptions(), - Log = trace - }; - var listenerContext = new ListenerContext(serviceContext) - { - ServerAddress = ServerAddress.FromUrl("http://localhost:5000"), - }; - var connectionContext = new ConnectionContext(listenerContext); - var frame = new Frame(application: null, context: connectionContext); - frame.Reset(); - frame.InitializeHeaders(); + var headerBytes = Encoding.ASCII.GetBytes(headers); + _socketInput.IncomingData(headerBytes, 0, headerBytes.Length); - var headerBytes = Encoding.ASCII.GetBytes(headers); - socketInput.IncomingData(headerBytes, 0, headerBytes.Length); - - Assert.Equal(false, frame.TakeMessageHeaders(socketInput, (FrameRequestHeaders)frame.RequestHeaders)); - } + Assert.Equal(false, _frame.TakeMessageHeaders(_socketInput, (FrameRequestHeaders)_frame.RequestHeaders)); } [Fact] public void RequestProcessingAsyncEnablesKeepAliveTimeout() { - var trace = new KestrelTrace(new TestKestrelTrace()); - var ltp = new LoggingThreadPool(trace); - using (var pool = new MemoryPool()) - using (var socketInput = new SocketInput(pool, ltp)) - { - var serviceContext = new ServiceContext - { - DateHeaderValueManager = new DateHeaderValueManager(), - ServerOptions = new KestrelServerOptions(), - Log = trace - }; - var listenerContext = new ListenerContext(serviceContext) - { - ServerAddress = ServerAddress.FromUrl("http://localhost:5000") - }; - var connectionControl = new Mock(); - var connectionContext = new ConnectionContext(listenerContext) - { - ConnectionControl = connectionControl.Object - }; - var frame = new Frame(application: null, context: connectionContext); - frame.Reset(); + var connectionControl = new Mock(); + _connectionContext.ConnectionControl = connectionControl.Object; - var requestProcessingTask = frame.RequestProcessingAsync(); + var requestProcessingTask = _frame.RequestProcessingAsync(); - var expectedKeepAliveTimeout = (long)serviceContext.ServerOptions.Limits.KeepAliveTimeout.TotalMilliseconds; - connectionControl.Verify(cc => cc.SetTimeout(expectedKeepAliveTimeout, TimeoutAction.CloseConnection)); + var expectedKeepAliveTimeout = (long)_serviceContext.ServerOptions.Limits.KeepAliveTimeout.TotalMilliseconds; + connectionControl.Verify(cc => cc.SetTimeout(expectedKeepAliveTimeout, TimeoutAction.CloseConnection)); - frame.StopAsync(); - socketInput.IncomingFin(); + _frame.StopAsync(); + _socketInput.IncomingFin(); - requestProcessingTask.Wait(); - } + requestProcessingTask.Wait(); } [Fact] public void WriteThrowsForNonBodyResponse() { // Arrange - var serviceContext = new ServiceContext - { - DateHeaderValueManager = new DateHeaderValueManager(), - ServerOptions = new KestrelServerOptions(), - Log = new TestKestrelTrace() - }; - var listenerContext = new ListenerContext(serviceContext) - { - ServerAddress = ServerAddress.FromUrl("http://localhost:5000") - }; - var connectionContext = new ConnectionContext(listenerContext) - { - SocketOutput = new MockSocketOuptut(), - }; - var frame = new Frame(application: null, context: connectionContext); - frame.InitializeHeaders(); - frame.HttpVersion = "HTTP/1.1"; - ((IHttpResponseFeature)frame).StatusCode = 304; + ((IHttpResponseFeature)_frame).StatusCode = 304; // Act/Assert - Assert.Throws(() => frame.Write(new ArraySegment(new byte[1]))); + Assert.Throws(() => _frame.Write(new ArraySegment(new byte[1]))); } [Fact] public async Task WriteAsyncThrowsForNonBodyResponse() { // Arrange - var serviceContext = new ServiceContext - { - DateHeaderValueManager = new DateHeaderValueManager(), - ServerOptions = new KestrelServerOptions(), - Log = new TestKestrelTrace() - }; - var listenerContext = new ListenerContext(serviceContext) - { - ServerAddress = ServerAddress.FromUrl("http://localhost:5000") - }; - var connectionContext = new ConnectionContext(listenerContext) - { - SocketOutput = new MockSocketOuptut(), - }; - var frame = new Frame(application: null, context: connectionContext); - frame.InitializeHeaders(); - frame.HttpVersion = "HTTP/1.1"; - ((IHttpResponseFeature)frame).StatusCode = 304; + _frame.HttpVersion = "HTTP/1.1"; + ((IHttpResponseFeature)_frame).StatusCode = 304; // Act/Assert - await Assert.ThrowsAsync(() => frame.WriteAsync(new ArraySegment(new byte[1]), default(CancellationToken))); + await Assert.ThrowsAsync(() => _frame.WriteAsync(new ArraySegment(new byte[1]), default(CancellationToken))); } [Fact] public void WriteDoesNotThrowForHeadResponse() { // Arrange - var serviceContext = new ServiceContext - { - DateHeaderValueManager = new DateHeaderValueManager(), - ServerOptions = new KestrelServerOptions(), - Log = new TestKestrelTrace() - }; - var listenerContext = new ListenerContext(serviceContext) - { - ServerAddress = ServerAddress.FromUrl("http://localhost:5000") - }; - var connectionContext = new ConnectionContext(listenerContext) - { - SocketOutput = new MockSocketOuptut(), - }; - var frame = new Frame(application: null, context: connectionContext); - frame.InitializeHeaders(); - frame.HttpVersion = "HTTP/1.1"; - ((IHttpRequestFeature)frame).Method = "HEAD"; + _frame.HttpVersion = "HTTP/1.1"; + ((IHttpRequestFeature)_frame).Method = "HEAD"; // Act/Assert - frame.Write(new ArraySegment(new byte[1])); + _frame.Write(new ArraySegment(new byte[1])); } [Fact] public async Task WriteAsyncDoesNotThrowForHeadResponse() { // Arrange - var serviceContext = new ServiceContext - { - DateHeaderValueManager = new DateHeaderValueManager(), - ServerOptions = new KestrelServerOptions(), - Log = new TestKestrelTrace() - }; - var listenerContext = new ListenerContext(serviceContext) - { - ServerAddress = ServerAddress.FromUrl("http://localhost:5000") - }; - var connectionContext = new ConnectionContext(listenerContext) - { - SocketOutput = new MockSocketOuptut(), - }; - var frame = new Frame(application: null, context: connectionContext); - frame.InitializeHeaders(); - frame.HttpVersion = "HTTP/1.1"; - ((IHttpRequestFeature)frame).Method = "HEAD"; + _frame.HttpVersion = "HTTP/1.1"; + ((IHttpRequestFeature)_frame).Method = "HEAD"; // Act/Assert - await frame.WriteAsync(new ArraySegment(new byte[1]), default(CancellationToken)); + await _frame.WriteAsync(new ArraySegment(new byte[1]), default(CancellationToken)); } [Fact] public void ManuallySettingTransferEncodingThrowsForHeadResponse() { // Arrange - var serviceContext = new ServiceContext - { - DateHeaderValueManager = new DateHeaderValueManager(), - ServerOptions = new KestrelServerOptions(), - Log = new TestKestrelTrace() - }; - var listenerContext = new ListenerContext(serviceContext) - { - ServerAddress = ServerAddress.FromUrl("http://localhost:5000") - }; - var connectionContext = new ConnectionContext(listenerContext) - { - SocketOutput = new MockSocketOuptut(), - }; - var frame = new Frame(application: null, context: connectionContext); - frame.InitializeHeaders(); - frame.HttpVersion = "HTTP/1.1"; - ((IHttpRequestFeature)frame).Method = "HEAD"; + _frame.HttpVersion = "HTTP/1.1"; + ((IHttpRequestFeature)_frame).Method = "HEAD"; // Act - frame.ResponseHeaders.Add("Transfer-Encoding", "chunked"); + _frame.ResponseHeaders.Add("Transfer-Encoding", "chunked"); // Assert - Assert.Throws(() => frame.Flush()); + Assert.Throws(() => _frame.Flush()); } [Fact] public void ManuallySettingTransferEncodingThrowsForNoBodyResponse() { // Arrange - var serviceContext = new ServiceContext - { - DateHeaderValueManager = new DateHeaderValueManager(), - ServerOptions = new KestrelServerOptions(), - Log = new TestKestrelTrace() - }; - var listenerContext = new ListenerContext(serviceContext) - { - ServerAddress = ServerAddress.FromUrl("http://localhost:5000") - }; - var connectionContext = new ConnectionContext(listenerContext) - { - SocketOutput = new MockSocketOuptut(), - }; - var frame = new Frame(application: null, context: connectionContext); - frame.InitializeHeaders(); - frame.HttpVersion = "HTTP/1.1"; - ((IHttpResponseFeature)frame).StatusCode = 304; + _frame.HttpVersion = "HTTP/1.1"; + ((IHttpResponseFeature)_frame).StatusCode = 304; // Act - frame.ResponseHeaders.Add("Transfer-Encoding", "chunked"); + _frame.ResponseHeaders.Add("Transfer-Encoding", "chunked"); // Assert - Assert.Throws(() => frame.Flush()); + Assert.Throws(() => _frame.Flush()); } [Fact] public async Task RequestProcessingTaskIsUnwrapped() { - var trace = new KestrelTrace(new TestKestrelTrace()); - var ltp = new LoggingThreadPool(trace); - using (var pool = new MemoryPool()) - using (var socketInput = new SocketInput(pool, ltp)) - { - var serviceContext = new ServiceContext - { - DateHeaderValueManager = new DateHeaderValueManager(), - ServerOptions = new KestrelServerOptions(), - Log = trace - }; - var listenerContext = new ListenerContext(serviceContext) - { - ServerAddress = ServerAddress.FromUrl("http://localhost:5000") - }; - var connectionContext = new ConnectionContext(listenerContext) - { - ConnectionControl = Mock.Of(), - SocketInput = socketInput - }; + _frame.Start(); - var frame = new Frame(application: null, context: connectionContext); - frame.Start(); + var data = Encoding.ASCII.GetBytes("GET / HTTP/1.1\r\n\r\n"); + _socketInput.IncomingData(data, 0, data.Length); - var data = Encoding.ASCII.GetBytes("GET / HTTP/1.1\r\n\r\n"); - socketInput.IncomingData(data, 0, data.Length); + var requestProcessingTask = _frame.StopAsync(); + Assert.IsNotType(typeof(Task), requestProcessingTask); - var requestProcessingTask = frame.StopAsync(); - Assert.IsNotType(typeof(Task), requestProcessingTask); - - await requestProcessingTask.TimeoutAfter(TimeSpan.FromSeconds(10)); - socketInput.IncomingFin(); - } + await requestProcessingTask.TimeoutAfter(TimeSpan.FromSeconds(10)); + _socketInput.IncomingFin(); } } } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/MessageBodyTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/MessageBodyTests.cs index 414bb208e3..e0f8dac560 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/MessageBodyTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/MessageBodyTests.cs @@ -279,7 +279,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests // The block returned by IncomingStart always has at least 2048 available bytes, // so no need to bounds check in this test. - var socketInput = input.FrameContext.SocketInput; + var socketInput = input.FrameContext.Input; var bytes = Encoding.ASCII.GetBytes(data[0]); var block = socketInput.IncomingStart(); Buffer.BlockCopy(bytes, 0, block.Array, block.End, bytes.Length); diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestInput.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/TestInput.cs index 872e4512f4..96d63ca04f 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/TestInput.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/TestInput.cs @@ -41,7 +41,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests FrameContext.ConnectionContext.ListenerContext.ServiceContext.Log = trace; _memoryPool = new MemoryPool(); - FrameContext.SocketInput = new SocketInput(_memoryPool, ltp); + FrameContext.Input = new SocketInput(_memoryPool, ltp); } public Frame FrameContext { get; set; } @@ -49,10 +49,10 @@ namespace Microsoft.AspNetCore.Server.KestrelTests public void Add(string text, bool fin = false) { var data = System.Text.Encoding.ASCII.GetBytes(text); - FrameContext.SocketInput.IncomingData(data, 0, data.Length); + FrameContext.Input.IncomingData(data, 0, data.Length); if (fin) { - FrameContext.SocketInput.IncomingFin(); + FrameContext.Input.IncomingFin(); } } @@ -116,7 +116,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests public void Dispose() { - FrameContext.SocketInput.Dispose(); + FrameContext.Input.Dispose(); _memoryPool.Dispose(); } } From e316898c9fe115c8bba0bc80d3bc0843d9b44b99 Mon Sep 17 00:00:00 2001 From: Kristian Hellang Date: Tue, 22 Nov 2016 13:08:34 +0100 Subject: [PATCH 0990/1662] Added missing copyright header --- .../Internal/Http/Frame.Generated.cs | 2 ++ .../Internal/Http/FrameHeaders.Generated.cs | 2 ++ .../FrameFeatureCollection.cs | 4 +++- .../KnownHeaders.cs | 4 +++- 4 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.Generated.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.Generated.cs index adef63eee8..160d110c54 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.Generated.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.Generated.cs @@ -1,3 +1,5 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; using System.Collections.Generic; diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameHeaders.Generated.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameHeaders.Generated.cs index e8b118824d..08bdcc099b 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameHeaders.Generated.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameHeaders.Generated.cs @@ -1,3 +1,5 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; using System.Collections.Generic; diff --git a/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/FrameFeatureCollection.cs b/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/FrameFeatureCollection.cs index 950f06b730..9f46ddfd11 100644 --- a/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/FrameFeatureCollection.cs +++ b/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/FrameFeatureCollection.cs @@ -62,7 +62,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.GeneratedCode typeof(IHttpConnectionFeature) }; - return $@" + return $@"// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + using System; using System.Collections.Generic; diff --git a/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/KnownHeaders.cs b/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/KnownHeaders.cs index d50bdebf46..1003a17e99 100644 --- a/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/KnownHeaders.cs +++ b/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/KnownHeaders.cs @@ -262,7 +262,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.GeneratedCode offset += header.BytesCount; } } - return $@" + return $@"// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + using System; using System.Collections.Generic; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; From fd7232616ad95e10cd0657ad5ae030fdd43213a9 Mon Sep 17 00:00:00 2001 From: "N. Taylor Mullen" Date: Wed, 23 Nov 2016 15:59:21 -0800 Subject: [PATCH 0991/1662] Pin global.json SDK to 1.0.0-preview2-1-003177. --- global.json | 9 +++++++-- .../global.json | 11 ++++++++--- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/global.json b/global.json index 983ba0401e..f45e8cc925 100644 --- a/global.json +++ b/global.json @@ -1,3 +1,8 @@ { - "projects": ["src"] -} + "projects": [ + "src" + ], + "sdk": { + "version": "1.0.0-preview2-1-003177" + } +} \ No newline at end of file diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/global.json b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/global.json index 33f0f54e92..0ddae8e73f 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/global.json +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/global.json @@ -1,3 +1,8 @@ -{ - "projects": [ "..\\" ] -} +{ + "projects": [ + "..\\" + ], + "sdk": { + "version": "1.0.0-preview2-1-003177" + } +} \ No newline at end of file From 02b84d7ae11151dd6f761107a29b39f4aad673d7 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Tue, 22 Nov 2016 16:24:42 -0800 Subject: [PATCH 0992/1662] Make ListenerPrimaryTests more reliable - The Task from ListenerSecondary.StartAsync() may complete before the PrimaryListener adds the pipe connection to its dispatch pipe list. --- .../ListenerPrimaryTests.cs | 48 +++++++++++++++++-- 1 file changed, 43 insertions(+), 5 deletions(-) diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/ListenerPrimaryTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/ListenerPrimaryTests.cs index 94f57fc99d..b6afadda5b 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/ListenerPrimaryTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/ListenerPrimaryTests.cs @@ -48,7 +48,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { return new Frame(new TestApplication(c => { - return c.Response.WriteAsync("Secondary"); ; + return c.Response.WriteAsync("Secondary"); }), context); } }; @@ -76,7 +76,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests await listenerSecondary.StartAsync(pipeName, pipeMessage, address, kestrelThreadSecondary); // Once a secondary listener is added, TCP connections start getting dispatched to it - Assert.Equal("Secondary", await HttpClientSlim.GetStringAsync(address.ToString())); + await AssertResponseEventually(address.ToString(), "Secondary", allowed: new[] { "Primary" }); // TCP connections will still get round-robined to the primary listener Assert.Equal("Primary", await HttpClientSlim.GetStringAsync(address.ToString())); @@ -146,7 +146,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests await listenerSecondary.StartAsync(pipeName, pipeMessage, address, kestrelThreadSecondary); // TCP Connections get round-robined - Assert.Equal("Secondary", await HttpClientSlim.GetStringAsync(address.ToString())); + await AssertResponseEventually(address.ToString(), "Secondary", allowed: new[] { "Primary" }); Assert.Equal("Primary", await HttpClientSlim.GetStringAsync(address.ToString())); // Create a pipe connection and keep it open without sending any data @@ -189,6 +189,12 @@ namespace Microsoft.AspNetCore.Server.KestrelTests await kestrelThreadPrimary.PostAsync(_ => pipe.Dispose(), null); + // Wait up to 10 seconds for error to be logged + for (var i = 0; i < 10 && primaryTrace.Logger.TotalErrorsLogged == 0; i++) + { + await Task.Delay(100); + } + // Same for after the non-listener pipe connection is closed Assert.Equal("Primary", await HttpClientSlim.GetStringAsync(address.ToString())); Assert.Equal("Secondary", await HttpClientSlim.GetStringAsync(address.ToString())); @@ -237,7 +243,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { return new Frame(new TestApplication(c => { - return c.Response.WriteAsync("Secondary"); ; + return c.Response.WriteAsync("Secondary"); }), context); } }; @@ -260,7 +266,13 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var listenerSecondary = new TcpListenerSecondary(serviceContextSecondary); await listenerSecondary.StartAsync(pipeName, Guid.NewGuid().ToByteArray(), address, kestrelThreadSecondary); - // TCP Connections get round-robined + // Wait up to 10 seconds for error to be logged + for (var i = 0; i < 10 && primaryTrace.Logger.TotalErrorsLogged == 0; i++) + { + await Task.Delay(100); + } + + // TCP Connections don't get round-robined Assert.Equal("Primary", await HttpClientSlim.GetStringAsync(address.ToString())); Assert.Equal("Primary", await HttpClientSlim.GetStringAsync(address.ToString())); Assert.Equal("Primary", await HttpClientSlim.GetStringAsync(address.ToString())); @@ -278,6 +290,32 @@ namespace Microsoft.AspNetCore.Server.KestrelTests Assert.Contains("Bad data", errorMessage.Exception.ToString()); } + private static async Task AssertResponseEventually( + string address, + string expected, + string[] allowed = null, + int maxRetries = 100, + int retryDelay = 100) + { + for (var i = 0; i < maxRetries; i++) + { + var response = await HttpClientSlim.GetStringAsync(address); + if (response == expected) + { + return; + } + + if (allowed != null) + { + Assert.Contains(response, allowed); + } + + await Task.Delay(retryDelay); + } + + Assert.True(false, $"'{address}' failed to respond with '{expected}' in {maxRetries} retries."); + } + private class TestApplication : IHttpApplication { private readonly Func _app; From 53e5c3d56c1257260dd01aa37987860eca621649 Mon Sep 17 00:00:00 2001 From: Chris R Date: Mon, 28 Nov 2016 15:24:30 -0800 Subject: [PATCH 0993/1662] #1001 don't log stack traces for localhost bind failures. --- .../KestrelServer.cs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServer.cs b/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServer.cs index e7e4e38d62..57fbc17017 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServer.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServer.cs @@ -150,14 +150,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel } catch (AggregateException ex) when (ex.InnerException is UvException) { - if ((ex.InnerException as UvException).StatusCode == Constants.EADDRINUSE) + var uvEx = (UvException)ex.InnerException; + if (uvEx.StatusCode == Constants.EADDRINUSE) { throw new IOException($"Failed to bind to address {parsedAddress.ToString()} on the IPv4 loopback interface: port already in use.", ex); } else { - _logger.LogWarning(0, ex, $"Unable to bind to {parsedAddress.ToString()} on the IPv4 loopback interface."); - exceptions.Add(ex.InnerException); + _logger.LogWarning(0, $"Unable to bind to {parsedAddress.ToString()} on the IPv4 loopback interface: ({uvEx.Message})"); + exceptions.Add(uvEx); } } @@ -169,14 +170,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel } catch (AggregateException ex) when (ex.InnerException is UvException) { - if ((ex.InnerException as UvException).StatusCode == Constants.EADDRINUSE) + var uvEx = (UvException)ex.InnerException; + if (uvEx.StatusCode == Constants.EADDRINUSE) { throw new IOException($"Failed to bind to address {parsedAddress.ToString()} on the IPv6 loopback interface: port already in use.", ex); } else { - _logger.LogWarning(0, ex, $"Unable to bind to {parsedAddress.ToString()} on the IPv6 loopback interface."); - exceptions.Add(ex.InnerException); + _logger.LogWarning(0, $"Unable to bind to {parsedAddress.ToString()} on the IPv6 loopback interface: ({uvEx.Message})"); + exceptions.Add(uvEx); } } From dbaa01830b117397c3e9cb170712df7b2c499c42 Mon Sep 17 00:00:00 2001 From: Yves57 Date: Tue, 29 Nov 2016 22:33:18 +0100 Subject: [PATCH 0994/1662] Replace 'foreach' by 'for' in StringValues (faster) --- .../Internal/Http/FrameHeaders.Generated.cs | 216 +++++++++++++++--- .../Internal/Http/FrameHeaders.cs | 14 +- .../KnownHeaders.cs | 6 +- 3 files changed, 195 insertions(+), 41 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameHeaders.Generated.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameHeaders.Generated.cs index 08bdcc099b..eaa963843a 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameHeaders.Generated.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameHeaders.Generated.cs @@ -9891,14 +9891,18 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http output.CopyFrom(_headers._rawConnection, 0, _headers._rawConnection.Length); } else - foreach (var value in _headers._Connection) + { + var valueCount = _headers._Connection.Count; + for (var i = 0; i < valueCount; i++) { + var value = _headers._Connection[i]; if (value != null) { output.CopyFrom(_headerBytes, 17, 14); output.CopyFromAscii(value); } } + } tempBits &= ~2L; if(tempBits == 0) @@ -9914,14 +9918,18 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http output.CopyFrom(_headers._rawDate, 0, _headers._rawDate.Length); } else - foreach (var value in _headers._Date) + { + var valueCount = _headers._Date.Count; + for (var i = 0; i < valueCount; i++) { + var value = _headers._Date[i]; if (value != null) { output.CopyFrom(_headerBytes, 31, 8); output.CopyFromAscii(value); } } + } tempBits &= ~4L; if(tempBits == 0) @@ -9937,14 +9945,18 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http output.CopyFrom(_headers._rawContentLength, 0, _headers._rawContentLength.Length); } else - foreach (var value in _headers._ContentLength) + { + var valueCount = _headers._ContentLength.Count; + for (var i = 0; i < valueCount; i++) { + var value = _headers._ContentLength[i]; if (value != null) { output.CopyFrom(_headerBytes, 133, 18); output.CopyFromAscii(value); } } + } tempBits &= ~2048L; if(tempBits == 0) @@ -9955,14 +9967,18 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if (((_bits & 4096L) != 0)) { - foreach (var value in _headers._ContentType) + { + var valueCount = _headers._ContentType.Count; + for (var i = 0; i < valueCount; i++) { + var value = _headers._ContentType[i]; if (value != null) { output.CopyFrom(_headerBytes, 151, 16); output.CopyFromAscii(value); } } + } tempBits &= ~4096L; if(tempBits == 0) @@ -9978,14 +9994,18 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http output.CopyFrom(_headers._rawServer, 0, _headers._rawServer.Length); } else - foreach (var value in _headers._Server) + { + var valueCount = _headers._Server.Count; + for (var i = 0; i < valueCount; i++) { + var value = _headers._Server[i]; if (value != null) { output.CopyFrom(_headerBytes, 368, 10); output.CopyFromAscii(value); } } + } tempBits &= ~67108864L; if(tempBits == 0) @@ -9996,14 +10016,18 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if (((_bits & 1L) != 0)) { - foreach (var value in _headers._CacheControl) + { + var valueCount = _headers._CacheControl.Count; + for (var i = 0; i < valueCount; i++) { + var value = _headers._CacheControl[i]; if (value != null) { output.CopyFrom(_headerBytes, 0, 17); output.CopyFromAscii(value); } } + } tempBits &= ~1L; if(tempBits == 0) @@ -10014,14 +10038,18 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if (((_bits & 8L) != 0)) { - foreach (var value in _headers._KeepAlive) + { + var valueCount = _headers._KeepAlive.Count; + for (var i = 0; i < valueCount; i++) { + var value = _headers._KeepAlive[i]; if (value != null) { output.CopyFrom(_headerBytes, 39, 14); output.CopyFromAscii(value); } } + } tempBits &= ~8L; if(tempBits == 0) @@ -10032,14 +10060,18 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if (((_bits & 16L) != 0)) { - foreach (var value in _headers._Pragma) + { + var valueCount = _headers._Pragma.Count; + for (var i = 0; i < valueCount; i++) { + var value = _headers._Pragma[i]; if (value != null) { output.CopyFrom(_headerBytes, 53, 10); output.CopyFromAscii(value); } } + } tempBits &= ~16L; if(tempBits == 0) @@ -10050,14 +10082,18 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if (((_bits & 32L) != 0)) { - foreach (var value in _headers._Trailer) + { + var valueCount = _headers._Trailer.Count; + for (var i = 0; i < valueCount; i++) { + var value = _headers._Trailer[i]; if (value != null) { output.CopyFrom(_headerBytes, 63, 11); output.CopyFromAscii(value); } } + } tempBits &= ~32L; if(tempBits == 0) @@ -10073,14 +10109,18 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http output.CopyFrom(_headers._rawTransferEncoding, 0, _headers._rawTransferEncoding.Length); } else - foreach (var value in _headers._TransferEncoding) + { + var valueCount = _headers._TransferEncoding.Count; + for (var i = 0; i < valueCount; i++) { + var value = _headers._TransferEncoding[i]; if (value != null) { output.CopyFrom(_headerBytes, 74, 21); output.CopyFromAscii(value); } } + } tempBits &= ~64L; if(tempBits == 0) @@ -10091,14 +10131,18 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if (((_bits & 128L) != 0)) { - foreach (var value in _headers._Upgrade) + { + var valueCount = _headers._Upgrade.Count; + for (var i = 0; i < valueCount; i++) { + var value = _headers._Upgrade[i]; if (value != null) { output.CopyFrom(_headerBytes, 95, 11); output.CopyFromAscii(value); } } + } tempBits &= ~128L; if(tempBits == 0) @@ -10109,14 +10153,18 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if (((_bits & 256L) != 0)) { - foreach (var value in _headers._Via) + { + var valueCount = _headers._Via.Count; + for (var i = 0; i < valueCount; i++) { + var value = _headers._Via[i]; if (value != null) { output.CopyFrom(_headerBytes, 106, 7); output.CopyFromAscii(value); } } + } tempBits &= ~256L; if(tempBits == 0) @@ -10127,14 +10175,18 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if (((_bits & 512L) != 0)) { - foreach (var value in _headers._Warning) + { + var valueCount = _headers._Warning.Count; + for (var i = 0; i < valueCount; i++) { + var value = _headers._Warning[i]; if (value != null) { output.CopyFrom(_headerBytes, 113, 11); output.CopyFromAscii(value); } } + } tempBits &= ~512L; if(tempBits == 0) @@ -10145,14 +10197,18 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if (((_bits & 1024L) != 0)) { - foreach (var value in _headers._Allow) + { + var valueCount = _headers._Allow.Count; + for (var i = 0; i < valueCount; i++) { + var value = _headers._Allow[i]; if (value != null) { output.CopyFrom(_headerBytes, 124, 9); output.CopyFromAscii(value); } } + } tempBits &= ~1024L; if(tempBits == 0) @@ -10163,14 +10219,18 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if (((_bits & 8192L) != 0)) { - foreach (var value in _headers._ContentEncoding) + { + var valueCount = _headers._ContentEncoding.Count; + for (var i = 0; i < valueCount; i++) { + var value = _headers._ContentEncoding[i]; if (value != null) { output.CopyFrom(_headerBytes, 167, 20); output.CopyFromAscii(value); } } + } tempBits &= ~8192L; if(tempBits == 0) @@ -10181,14 +10241,18 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if (((_bits & 16384L) != 0)) { - foreach (var value in _headers._ContentLanguage) + { + var valueCount = _headers._ContentLanguage.Count; + for (var i = 0; i < valueCount; i++) { + var value = _headers._ContentLanguage[i]; if (value != null) { output.CopyFrom(_headerBytes, 187, 20); output.CopyFromAscii(value); } } + } tempBits &= ~16384L; if(tempBits == 0) @@ -10199,14 +10263,18 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if (((_bits & 32768L) != 0)) { - foreach (var value in _headers._ContentLocation) + { + var valueCount = _headers._ContentLocation.Count; + for (var i = 0; i < valueCount; i++) { + var value = _headers._ContentLocation[i]; if (value != null) { output.CopyFrom(_headerBytes, 207, 20); output.CopyFromAscii(value); } } + } tempBits &= ~32768L; if(tempBits == 0) @@ -10217,14 +10285,18 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if (((_bits & 65536L) != 0)) { - foreach (var value in _headers._ContentMD5) + { + var valueCount = _headers._ContentMD5.Count; + for (var i = 0; i < valueCount; i++) { + var value = _headers._ContentMD5[i]; if (value != null) { output.CopyFrom(_headerBytes, 227, 15); output.CopyFromAscii(value); } } + } tempBits &= ~65536L; if(tempBits == 0) @@ -10235,14 +10307,18 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if (((_bits & 131072L) != 0)) { - foreach (var value in _headers._ContentRange) + { + var valueCount = _headers._ContentRange.Count; + for (var i = 0; i < valueCount; i++) { + var value = _headers._ContentRange[i]; if (value != null) { output.CopyFrom(_headerBytes, 242, 17); output.CopyFromAscii(value); } } + } tempBits &= ~131072L; if(tempBits == 0) @@ -10253,14 +10329,18 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if (((_bits & 262144L) != 0)) { - foreach (var value in _headers._Expires) + { + var valueCount = _headers._Expires.Count; + for (var i = 0; i < valueCount; i++) { + var value = _headers._Expires[i]; if (value != null) { output.CopyFrom(_headerBytes, 259, 11); output.CopyFromAscii(value); } } + } tempBits &= ~262144L; if(tempBits == 0) @@ -10271,14 +10351,18 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if (((_bits & 524288L) != 0)) { - foreach (var value in _headers._LastModified) + { + var valueCount = _headers._LastModified.Count; + for (var i = 0; i < valueCount; i++) { + var value = _headers._LastModified[i]; if (value != null) { output.CopyFrom(_headerBytes, 270, 17); output.CopyFromAscii(value); } } + } tempBits &= ~524288L; if(tempBits == 0) @@ -10289,14 +10373,18 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if (((_bits & 1048576L) != 0)) { - foreach (var value in _headers._AcceptRanges) + { + var valueCount = _headers._AcceptRanges.Count; + for (var i = 0; i < valueCount; i++) { + var value = _headers._AcceptRanges[i]; if (value != null) { output.CopyFrom(_headerBytes, 287, 17); output.CopyFromAscii(value); } } + } tempBits &= ~1048576L; if(tempBits == 0) @@ -10307,14 +10395,18 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if (((_bits & 2097152L) != 0)) { - foreach (var value in _headers._Age) + { + var valueCount = _headers._Age.Count; + for (var i = 0; i < valueCount; i++) { + var value = _headers._Age[i]; if (value != null) { output.CopyFrom(_headerBytes, 304, 7); output.CopyFromAscii(value); } } + } tempBits &= ~2097152L; if(tempBits == 0) @@ -10325,14 +10417,18 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if (((_bits & 4194304L) != 0)) { - foreach (var value in _headers._ETag) + { + var valueCount = _headers._ETag.Count; + for (var i = 0; i < valueCount; i++) { + var value = _headers._ETag[i]; if (value != null) { output.CopyFrom(_headerBytes, 311, 8); output.CopyFromAscii(value); } } + } tempBits &= ~4194304L; if(tempBits == 0) @@ -10343,14 +10439,18 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if (((_bits & 8388608L) != 0)) { - foreach (var value in _headers._Location) + { + var valueCount = _headers._Location.Count; + for (var i = 0; i < valueCount; i++) { + var value = _headers._Location[i]; if (value != null) { output.CopyFrom(_headerBytes, 319, 12); output.CopyFromAscii(value); } } + } tempBits &= ~8388608L; if(tempBits == 0) @@ -10361,14 +10461,18 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if (((_bits & 16777216L) != 0)) { - foreach (var value in _headers._ProxyAuthenticate) + { + var valueCount = _headers._ProxyAuthenticate.Count; + for (var i = 0; i < valueCount; i++) { + var value = _headers._ProxyAuthenticate[i]; if (value != null) { output.CopyFrom(_headerBytes, 331, 22); output.CopyFromAscii(value); } } + } tempBits &= ~16777216L; if(tempBits == 0) @@ -10379,14 +10483,18 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if (((_bits & 33554432L) != 0)) { - foreach (var value in _headers._RetryAfter) + { + var valueCount = _headers._RetryAfter.Count; + for (var i = 0; i < valueCount; i++) { + var value = _headers._RetryAfter[i]; if (value != null) { output.CopyFrom(_headerBytes, 353, 15); output.CopyFromAscii(value); } } + } tempBits &= ~33554432L; if(tempBits == 0) @@ -10397,14 +10505,18 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if (((_bits & 134217728L) != 0)) { - foreach (var value in _headers._SetCookie) + { + var valueCount = _headers._SetCookie.Count; + for (var i = 0; i < valueCount; i++) { + var value = _headers._SetCookie[i]; if (value != null) { output.CopyFrom(_headerBytes, 378, 14); output.CopyFromAscii(value); } } + } tempBits &= ~134217728L; if(tempBits == 0) @@ -10415,14 +10527,18 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if (((_bits & 268435456L) != 0)) { - foreach (var value in _headers._Vary) + { + var valueCount = _headers._Vary.Count; + for (var i = 0; i < valueCount; i++) { + var value = _headers._Vary[i]; if (value != null) { output.CopyFrom(_headerBytes, 392, 8); output.CopyFromAscii(value); } } + } tempBits &= ~268435456L; if(tempBits == 0) @@ -10433,14 +10549,18 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if (((_bits & 536870912L) != 0)) { - foreach (var value in _headers._WWWAuthenticate) + { + var valueCount = _headers._WWWAuthenticate.Count; + for (var i = 0; i < valueCount; i++) { + var value = _headers._WWWAuthenticate[i]; if (value != null) { output.CopyFrom(_headerBytes, 400, 20); output.CopyFromAscii(value); } } + } tempBits &= ~536870912L; if(tempBits == 0) @@ -10451,14 +10571,18 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if (((_bits & 1073741824L) != 0)) { - foreach (var value in _headers._AccessControlAllowCredentials) + { + var valueCount = _headers._AccessControlAllowCredentials.Count; + for (var i = 0; i < valueCount; i++) { + var value = _headers._AccessControlAllowCredentials[i]; if (value != null) { output.CopyFrom(_headerBytes, 420, 36); output.CopyFromAscii(value); } } + } tempBits &= ~1073741824L; if(tempBits == 0) @@ -10469,14 +10593,18 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if (((_bits & 2147483648L) != 0)) { - foreach (var value in _headers._AccessControlAllowHeaders) + { + var valueCount = _headers._AccessControlAllowHeaders.Count; + for (var i = 0; i < valueCount; i++) { + var value = _headers._AccessControlAllowHeaders[i]; if (value != null) { output.CopyFrom(_headerBytes, 456, 32); output.CopyFromAscii(value); } } + } tempBits &= ~2147483648L; if(tempBits == 0) @@ -10487,14 +10615,18 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if (((_bits & 4294967296L) != 0)) { - foreach (var value in _headers._AccessControlAllowMethods) + { + var valueCount = _headers._AccessControlAllowMethods.Count; + for (var i = 0; i < valueCount; i++) { + var value = _headers._AccessControlAllowMethods[i]; if (value != null) { output.CopyFrom(_headerBytes, 488, 32); output.CopyFromAscii(value); } } + } tempBits &= ~4294967296L; if(tempBits == 0) @@ -10505,14 +10637,18 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if (((_bits & 8589934592L) != 0)) { - foreach (var value in _headers._AccessControlAllowOrigin) + { + var valueCount = _headers._AccessControlAllowOrigin.Count; + for (var i = 0; i < valueCount; i++) { + var value = _headers._AccessControlAllowOrigin[i]; if (value != null) { output.CopyFrom(_headerBytes, 520, 31); output.CopyFromAscii(value); } } + } tempBits &= ~8589934592L; if(tempBits == 0) @@ -10523,14 +10659,18 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if (((_bits & 17179869184L) != 0)) { - foreach (var value in _headers._AccessControlExposeHeaders) + { + var valueCount = _headers._AccessControlExposeHeaders.Count; + for (var i = 0; i < valueCount; i++) { + var value = _headers._AccessControlExposeHeaders[i]; if (value != null) { output.CopyFrom(_headerBytes, 551, 33); output.CopyFromAscii(value); } } + } tempBits &= ~17179869184L; if(tempBits == 0) @@ -10541,14 +10681,18 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if (((_bits & 34359738368L) != 0)) { - foreach (var value in _headers._AccessControlMaxAge) + { + var valueCount = _headers._AccessControlMaxAge.Count; + for (var i = 0; i < valueCount; i++) { + var value = _headers._AccessControlMaxAge[i]; if (value != null) { output.CopyFrom(_headerBytes, 584, 26); output.CopyFromAscii(value); } } + } tempBits &= ~34359738368L; if(tempBits == 0) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameHeaders.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameHeaders.cs index e4d42e1eaa..03f15c58dc 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameHeaders.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameHeaders.cs @@ -212,9 +212,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http public static void ValidateHeaderCharacters(StringValues headerValues) { - foreach (var value in headerValues) + var count = headerValues.Count; + for (var i = 0; i < count; i++) + { - ValidateHeaderCharacters(value); + ValidateHeaderCharacters(headerValues[i]); } } @@ -268,8 +270,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { var connectionOptions = ConnectionOptions.None; - foreach (var value in connection) + var connectionCount = connection.Count; + for (var i = 0; i < connectionCount; i++) { + var value = connection[i]; fixed (char* ptr = value) { var ch = ptr; @@ -368,8 +372,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { var transferEncodingOptions = TransferCoding.None; - foreach (var value in transferEncoding) + var transferEncodingCount = transferEncoding.Count; + for (var i = 0; i < transferEncodingCount; i++) { + var value = transferEncoding[i]; fixed (char* ptr = value) { var ch = ptr; diff --git a/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/KnownHeaders.cs b/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/KnownHeaders.cs index 1003a17e99..bd0c24aa0a 100644 --- a/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/KnownHeaders.cs +++ b/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/KnownHeaders.cs @@ -494,14 +494,18 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http output.CopyFrom(_headers._raw{header.Identifier}, 0, _headers._raw{header.Identifier}.Length); }} else ")} - foreach (var value in _headers._{header.Identifier}) + {{ + var valueCount = _headers._{header.Identifier}.Count; + for (var i = 0; i < valueCount; i++) {{ + var value = _headers._{header.Identifier}[i]; if (value != null) {{ output.CopyFrom(_headerBytes, {header.BytesOffset}, {header.BytesCount}); output.CopyFromAscii(value); }} }} + }} tempBits &= ~{1L << header.Index}L; if(tempBits == 0) From e53a87be9ccbc93e50453ac4a6476f6683015360 Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Tue, 29 Nov 2016 13:21:29 -0800 Subject: [PATCH 0995/1662] Add MaxRequestBodySize limit (#478). --- .../BadHttpRequestException.cs | 3 + .../Internal/Http/Frame.cs | 2 +- .../Internal/Http/MessageBody.cs | 16 +- .../Internal/Http/RequestRejectionReason.cs | 1 + .../KestrelServerLimits.cs | 26 +++ .../KeepAliveTimeoutTests.cs | 5 +- .../MaxRequestBodySizeTests.cs | 168 ++++++++++++++++++ .../MaxRequestBufferSizeTests.cs | 1 + .../RequestTests.cs | 5 +- .../KestrelServerLimitsTests.cs | 28 +++ 10 files changed, 250 insertions(+), 5 deletions(-) create mode 100644 test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/MaxRequestBodySizeTests.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/BadHttpRequestException.cs b/src/Microsoft.AspNetCore.Server.Kestrel/BadHttpRequestException.cs index cb37af76c1..8e70e90c66 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/BadHttpRequestException.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/BadHttpRequestException.cs @@ -78,6 +78,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel case RequestRejectionReason.RequestTimeout: ex = new BadHttpRequestException("Request timed out.", 408); break; + case RequestRejectionReason.PayloadTooLarge: + ex = new BadHttpRequestException("Payload too large.", 413); + break; default: ex = new BadHttpRequestException("Bad request.", 400); break; diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs index 0b37975bc3..9966b60c9e 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs @@ -115,7 +115,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http private DateHeaderValueManager DateHeaderValueManager => ConnectionContext.ListenerContext.ServiceContext.DateHeaderValueManager; private ServerAddress ServerAddress => ConnectionContext.ListenerContext.ServerAddress; // Hold direct reference to ServerOptions since this is used very often in the request processing path - private KestrelServerOptions ServerOptions { get; } + public KestrelServerOptions ServerOptions { get; } private IPEndPoint LocalEndPoint => ConnectionContext.LocalEndPoint; private IPEndPoint RemoteEndPoint => ConnectionContext.RemoteEndPoint; protected string ConnectionId => ConnectionContext.ConnectionId; diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/MessageBody.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/MessageBody.cs index 50cb468741..f4a260dcc6 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/MessageBody.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/MessageBody.cs @@ -8,7 +8,6 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.Extensions.Internal; -using Microsoft.Extensions.Primitives; namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { @@ -272,6 +271,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http try { var contentLength = FrameHeaders.ParseContentLength(unparsedContentLength); + + if (contentLength > context.ServerOptions.Limits.MaxRequestBodySize) + { + context.RejectRequest(RequestRejectionReason.PayloadTooLarge); + } + return new ForContentLength(keepAlive, contentLength, context); } catch (InvalidOperationException) @@ -281,7 +286,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } // Avoid slowing down most common case - if (!object.ReferenceEquals(context.Method, HttpMethods.Get)) + if (!ReferenceEquals(context.Method, HttpMethods.Get)) { // If we got here, request contains no Content-Length or Transfer-Encoding header. // Reject with 411 Length Required. @@ -394,6 +399,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http private readonly SocketInput _input; private readonly FrameRequestHeaders _requestHeaders; + private long _inputBytesRead; private int _inputLength; private Mode _mode = Mode.Prefix; @@ -414,6 +420,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http protected override void OnConsumedBytes(int count) { _inputLength -= count; + _inputBytesRead += count; + + if (_inputBytesRead > _context.ServerOptions.Limits.MaxRequestBodySize) + { + _context.RejectRequest(RequestRejectionReason.PayloadTooLarge); + } } private async Task> PeekStateMachineAsync() diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/RequestRejectionReason.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/RequestRejectionReason.cs index 0c05a6b8ea..f774e5d6a3 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/RequestRejectionReason.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/RequestRejectionReason.cs @@ -30,5 +30,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http FinalTransferCodingNotChunked, LengthRequired, LengthRequiredHttp10, + PayloadTooLarge } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServerLimits.cs b/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServerLimits.cs index ac8a047542..b85e3875d8 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServerLimits.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServerLimits.cs @@ -23,6 +23,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel // Matches the default LimitRequestFields in Apache httpd. private int _maxRequestHeaderCount = 100; + // Matches default HttpRuntimeSection.MaxRequestLength. + // https://msdn.microsoft.com/en-us/library/system.web.configuration.httpruntimesection.maxrequestlength%28v=vs.100%29.aspx + private long _maxRequestBodySize = 4 * 1024 * 1024; + // Matches the default http.sys connectionTimeout. private TimeSpan _keepAliveTimeout = TimeSpan.FromMinutes(2); @@ -144,6 +148,28 @@ namespace Microsoft.AspNetCore.Server.Kestrel } } + /// + /// Gets or sets the maximum request body size, in bytes. + /// + /// + /// Defaults to 4MB. + /// + public long MaxRequestBodySize + { + get + { + return _maxRequestBodySize; + } + set + { + if (value <= 0) + { + throw new ArgumentOutOfRangeException(nameof(value), "Value must a positive integer."); + } + _maxRequestBodySize = value; + } + } + /// /// Gets or sets the keep-alive timeout. /// diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/KeepAliveTimeoutTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/KeepAliveTimeoutTests.cs index ee4a72cc57..77adb2b983 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/KeepAliveTimeoutTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/KeepAliveTimeoutTests.cs @@ -178,7 +178,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests AddServerHeader = false, Limits = { - KeepAliveTimeout = KeepAliveTimeout + KeepAliveTimeout = KeepAliveTimeout, + // Prevent request rejection if ConnectionNotTimedOutWhileRequestBeingSent + // sends more bytes than the default body size limit. + MaxRequestBodySize = long.MaxValue } } }); diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/MaxRequestBodySizeTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/MaxRequestBodySizeTests.cs new file mode 100644 index 0000000000..c54c9b2ad5 --- /dev/null +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/MaxRequestBodySizeTests.cs @@ -0,0 +1,168 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Text; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Http.Features; +using Microsoft.AspNetCore.Testing; +using Xunit; + +namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests +{ + public class MaxRequestBodySizeTests + { + private const int MaxRequestBodySize = 128; + + [Theory] + [InlineData(MaxRequestBodySize - 1, 0)] + [InlineData(MaxRequestBodySize, 0)] + [InlineData(MaxRequestBodySize - 1, 1)] + [InlineData(MaxRequestBodySize, 1)] + [InlineData(MaxRequestBodySize - 1, 2)] + [InlineData(MaxRequestBodySize, 2)] + public async Task ServerAcceptsRequestBodyWithinLimit(int requestBodySize, int chunks) + { + using (var server = CreateServer(MaxRequestBodySize, async httpContext => await httpContext.Response.WriteAsync("hello, world"))) + { + using (var connection = new TestConnection(server.Port)) + { + await connection.SendAll(BuildRequest(connection, requestBodySize, chunks)); + + await connection.Receive( + "HTTP/1.1 200 OK", + $"Date: {server.Context.DateHeaderValue}", + "Transfer-Encoding: chunked", + "", + "c", + "hello, world", + "0", + "", + ""); + } + } + } + + [Theory] + [InlineData(MaxRequestBodySize + 1, 0)] + [InlineData(MaxRequestBodySize + 1, 1)] + [InlineData(MaxRequestBodySize + 1, 2)] + public async Task ServerRejectsRequestBodyExceedingLimit(int requestBodySize, int chunks) + { + using (var server = CreateServer(MaxRequestBodySize, async httpContext => + { + var received = 0; + while (received < requestBodySize) + { + received += await httpContext.Request.Body.ReadAsync(new byte[1024], 0, 1024); + } + + // Should never get here + await httpContext.Response.WriteAsync("hello, world"); + })) + { + using (var connection = new TestConnection(server.Port)) + { + await connection.SendAll(BuildRequest(connection, requestBodySize, chunks)); + + await connection.ReceiveForcedEnd( + "HTTP/1.1 413 Payload Too Large", + "Connection: close", + $"Date: {server.Context.DateHeaderValue}", + "Content-Length: 0", + "", + ""); + } + } + } + + [Fact] + public async Task MaxRequestBodySizeNotEnforcedOnUpgradedConnection() + { + var sendBytes = MaxRequestBodySize + 1; + + using (var server = CreateServer(MaxRequestBodySize, async httpContext => + { + var stream = await httpContext.Features.Get().UpgradeAsync(); + + var received = 0; + while (received < sendBytes) + { + received += await stream.ReadAsync(new byte[1024], 0, 1024); + } + + var response = Encoding.ASCII.GetBytes($"{received}"); + await stream.WriteAsync(response, 0, response.Length); + })) + { + using (var connection = new TestConnection(server.Port)) + { + await connection.Send( + "GET / HTTP/1.1", + "Connection: upgrade", + "", + new string('a', sendBytes)); + + await connection.Receive( + "HTTP/1.1 101 Switching Protocols", + "Connection: Upgrade", + $"Date: {server.Context.DateHeaderValue}", + "", + $"{sendBytes}"); + } + } + } + + private string BuildRequest(TestConnection connection, int requestBodySize, int chunks) + { + var request = new StringBuilder(); + + request.Append("POST / HTTP/1.1\r\n"); + + if (chunks == 0) + { + request.Append($"Content-Length: {requestBodySize}\r\n\r\n"); + request.Append(new string('a', requestBodySize)); + } + else + { + request.Append("Transfer-Encoding: chunked\r\n\r\n"); + + var bytesSent = 0; + while (bytesSent < requestBodySize) + { + var chunkSize = Math.Min(requestBodySize / chunks, requestBodySize - bytesSent); + + request.Append($"{chunkSize:X}\r\n"); + request.Append(new string('a', chunkSize)); + request.Append("\r\n"); + + bytesSent += chunkSize; + } + + // Make sure we sent the right amount of data + Assert.Equal(requestBodySize, bytesSent); + + request.Append("0\r\n\r\n"); + } + + return request.ToString(); + } + + private TestServer CreateServer(int maxRequestBodySize, RequestDelegate app) + { + return new TestServer(app, new TestServiceContext + { + ServerOptions = new KestrelServerOptions + { + AddServerHeader = false, + Limits = + { + MaxRequestBodySize = maxRequestBodySize + } + } + }); + } + } +} diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/MaxRequestBufferSizeTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/MaxRequestBufferSizeTests.cs index d78f60a7cd..4a19b8cd10 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/MaxRequestBufferSizeTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/MaxRequestBufferSizeTests.cs @@ -169,6 +169,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests .UseKestrel(options => { options.Limits.MaxRequestBufferSize = maxRequestBufferSize; + options.Limits.MaxRequestBodySize = _dataLength; options.UseHttps(@"TestResources/testCert.pfx", "testPassword"); if (maxRequestBufferSize.HasValue && diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs index 645f7c5205..9434429926 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs @@ -43,7 +43,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests Assert.True(bufferLength % 256 == 0, $"{nameof(bufferLength)} must be evenly divisible by 256"); var builder = new WebHostBuilder() - .UseKestrel() + .UseKestrel(options => + { + options.Limits.MaxRequestBodySize = contentLength; + }) .UseUrls("http://127.0.0.1:0/") .Configure(app => { diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerLimitsTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerLimitsTests.cs index 0b9363b58f..ae17670ba3 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerLimitsTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerLimitsTests.cs @@ -149,6 +149,34 @@ namespace Microsoft.AspNetCore.Server.KestrelTests Assert.Equal(value, o.MaxRequestHeaderCount); } + [Fact] + public void MaxRequestBodySizeDefault() + { + Assert.Equal(4 * 1024 * 1024, (new KestrelServerLimits()).MaxRequestBodySize); + } + + [Theory] + [InlineData(long.MinValue)] + [InlineData(-1)] + [InlineData(0)] + public void MaxRequestBodySizeInvalid(long value) + { + Assert.Throws(() => + { + (new KestrelServerLimits()).MaxRequestBodySize = value; + }); + } + + [Theory] + [InlineData(1)] + [InlineData(long.MaxValue)] + public void MaxRequestBodySizeValid(long value) + { + var o = new KestrelServerLimits(); + o.MaxRequestBodySize = value; + Assert.Equal(value, o.MaxRequestBodySize); + } + [Fact] public void KeepAliveTimeoutDefault() { From ad2a00dbbd82867dc4351ae70d2577599335b041 Mon Sep 17 00:00:00 2001 From: "N. Taylor Mullen" Date: Thu, 8 Dec 2016 10:03:35 -0800 Subject: [PATCH 0996/1662] Update .travis.yml osx image to xcode7.3. --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index d7636fa329..a0be886892 100644 --- a/.travis.yml +++ b/.travis.yml @@ -19,7 +19,7 @@ mono: os: - linux - osx -osx_image: xcode7.1 +osx_image: xcode7.3 branches: only: - master From 4da06e8acd799b3e5a92fce00dc686eb2c55e831 Mon Sep 17 00:00:00 2001 From: John Luo Date: Thu, 8 Dec 2016 17:22:21 -0800 Subject: [PATCH 0997/1662] Move Int64 parsing logic to HttpAbstractions --- .../Internal/Http/FrameHeaders.cs | 28 +++---------------- 1 file changed, 4 insertions(+), 24 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameHeaders.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameHeaders.cs index e4d42e1eaa..5bca7067d8 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameHeaders.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameHeaders.cs @@ -7,6 +7,7 @@ using System.Collections.Generic; using System.Linq; using Microsoft.AspNetCore.Http; using Microsoft.Extensions.Primitives; +using Microsoft.Net.Http.Headers; namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { @@ -234,31 +235,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http public static unsafe long ParseContentLength(StringValues value) { - var input = value.ToString(); - var parsed = 0L; - - fixed (char* ptr = input) + long parsed; + if (!HeaderUtilities.TryParseInt64(new StringSegment(value.ToString()), out parsed)) { - var ch = (ushort*)ptr; - var end = ch + input.Length; - - if (ch == end) - { - ThrowInvalidContentLengthException(value); - } - - ushort digit = 0; - while (ch < end && (digit = (ushort)(*ch - 0x30)) <= 9) - { - parsed *= 10; - parsed += digit; - ch++; - } - - if (ch != end) - { - ThrowInvalidContentLengthException(value); - } + ThrowInvalidContentLengthException(value); } return parsed; From 859816bb53f52dc6aa04810d36154965a392cf58 Mon Sep 17 00:00:00 2001 From: John Luo Date: Fri, 9 Dec 2016 11:39:25 -0800 Subject: [PATCH 0998/1662] Update ParseContentLength to remove unnecessary casting and unsafe --- .../Internal/Http/FrameHeaders.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameHeaders.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameHeaders.cs index 5bca7067d8..b00c3bbfba 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameHeaders.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameHeaders.cs @@ -233,10 +233,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } } - public static unsafe long ParseContentLength(StringValues value) + public static long ParseContentLength(StringValues value) { long parsed; - if (!HeaderUtilities.TryParseInt64(new StringSegment(value.ToString()), out parsed)) + if (!HeaderUtilities.TryParseInt64(value.ToString(), out parsed)) { ThrowInvalidContentLengthException(value); } From defcbdb907daf5433c167a2dc74f90653120eb5c Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Thu, 8 Dec 2016 11:06:47 -0800 Subject: [PATCH 0999/1662] Revert "Add MaxRequestBodySize limit (#478)." This reverts commit e53a87be9ccbc93e50453ac4a6476f6683015360. --- .../BadHttpRequestException.cs | 3 - .../Internal/Http/Frame.cs | 2 +- .../Internal/Http/MessageBody.cs | 16 +- .../Internal/Http/RequestRejectionReason.cs | 1 - .../KestrelServerLimits.cs | 26 --- .../KeepAliveTimeoutTests.cs | 5 +- .../MaxRequestBodySizeTests.cs | 168 ------------------ .../MaxRequestBufferSizeTests.cs | 1 - .../RequestTests.cs | 5 +- .../KestrelServerLimitsTests.cs | 28 --- 10 files changed, 5 insertions(+), 250 deletions(-) delete mode 100644 test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/MaxRequestBodySizeTests.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/BadHttpRequestException.cs b/src/Microsoft.AspNetCore.Server.Kestrel/BadHttpRequestException.cs index 8e70e90c66..cb37af76c1 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/BadHttpRequestException.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/BadHttpRequestException.cs @@ -78,9 +78,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel case RequestRejectionReason.RequestTimeout: ex = new BadHttpRequestException("Request timed out.", 408); break; - case RequestRejectionReason.PayloadTooLarge: - ex = new BadHttpRequestException("Payload too large.", 413); - break; default: ex = new BadHttpRequestException("Bad request.", 400); break; diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs index 9966b60c9e..0b37975bc3 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs @@ -115,7 +115,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http private DateHeaderValueManager DateHeaderValueManager => ConnectionContext.ListenerContext.ServiceContext.DateHeaderValueManager; private ServerAddress ServerAddress => ConnectionContext.ListenerContext.ServerAddress; // Hold direct reference to ServerOptions since this is used very often in the request processing path - public KestrelServerOptions ServerOptions { get; } + private KestrelServerOptions ServerOptions { get; } private IPEndPoint LocalEndPoint => ConnectionContext.LocalEndPoint; private IPEndPoint RemoteEndPoint => ConnectionContext.RemoteEndPoint; protected string ConnectionId => ConnectionContext.ConnectionId; diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/MessageBody.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/MessageBody.cs index f4a260dcc6..50cb468741 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/MessageBody.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/MessageBody.cs @@ -8,6 +8,7 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.Extensions.Internal; +using Microsoft.Extensions.Primitives; namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { @@ -271,12 +272,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http try { var contentLength = FrameHeaders.ParseContentLength(unparsedContentLength); - - if (contentLength > context.ServerOptions.Limits.MaxRequestBodySize) - { - context.RejectRequest(RequestRejectionReason.PayloadTooLarge); - } - return new ForContentLength(keepAlive, contentLength, context); } catch (InvalidOperationException) @@ -286,7 +281,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } // Avoid slowing down most common case - if (!ReferenceEquals(context.Method, HttpMethods.Get)) + if (!object.ReferenceEquals(context.Method, HttpMethods.Get)) { // If we got here, request contains no Content-Length or Transfer-Encoding header. // Reject with 411 Length Required. @@ -399,7 +394,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http private readonly SocketInput _input; private readonly FrameRequestHeaders _requestHeaders; - private long _inputBytesRead; private int _inputLength; private Mode _mode = Mode.Prefix; @@ -420,12 +414,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http protected override void OnConsumedBytes(int count) { _inputLength -= count; - _inputBytesRead += count; - - if (_inputBytesRead > _context.ServerOptions.Limits.MaxRequestBodySize) - { - _context.RejectRequest(RequestRejectionReason.PayloadTooLarge); - } } private async Task> PeekStateMachineAsync() diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/RequestRejectionReason.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/RequestRejectionReason.cs index f774e5d6a3..0c05a6b8ea 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/RequestRejectionReason.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/RequestRejectionReason.cs @@ -30,6 +30,5 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http FinalTransferCodingNotChunked, LengthRequired, LengthRequiredHttp10, - PayloadTooLarge } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServerLimits.cs b/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServerLimits.cs index b85e3875d8..ac8a047542 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServerLimits.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServerLimits.cs @@ -23,10 +23,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel // Matches the default LimitRequestFields in Apache httpd. private int _maxRequestHeaderCount = 100; - // Matches default HttpRuntimeSection.MaxRequestLength. - // https://msdn.microsoft.com/en-us/library/system.web.configuration.httpruntimesection.maxrequestlength%28v=vs.100%29.aspx - private long _maxRequestBodySize = 4 * 1024 * 1024; - // Matches the default http.sys connectionTimeout. private TimeSpan _keepAliveTimeout = TimeSpan.FromMinutes(2); @@ -148,28 +144,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel } } - /// - /// Gets or sets the maximum request body size, in bytes. - /// - /// - /// Defaults to 4MB. - /// - public long MaxRequestBodySize - { - get - { - return _maxRequestBodySize; - } - set - { - if (value <= 0) - { - throw new ArgumentOutOfRangeException(nameof(value), "Value must a positive integer."); - } - _maxRequestBodySize = value; - } - } - /// /// Gets or sets the keep-alive timeout. /// diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/KeepAliveTimeoutTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/KeepAliveTimeoutTests.cs index 77adb2b983..ee4a72cc57 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/KeepAliveTimeoutTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/KeepAliveTimeoutTests.cs @@ -178,10 +178,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests AddServerHeader = false, Limits = { - KeepAliveTimeout = KeepAliveTimeout, - // Prevent request rejection if ConnectionNotTimedOutWhileRequestBeingSent - // sends more bytes than the default body size limit. - MaxRequestBodySize = long.MaxValue + KeepAliveTimeout = KeepAliveTimeout } } }); diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/MaxRequestBodySizeTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/MaxRequestBodySizeTests.cs deleted file mode 100644 index c54c9b2ad5..0000000000 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/MaxRequestBodySizeTests.cs +++ /dev/null @@ -1,168 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using System.Text; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Http.Features; -using Microsoft.AspNetCore.Testing; -using Xunit; - -namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests -{ - public class MaxRequestBodySizeTests - { - private const int MaxRequestBodySize = 128; - - [Theory] - [InlineData(MaxRequestBodySize - 1, 0)] - [InlineData(MaxRequestBodySize, 0)] - [InlineData(MaxRequestBodySize - 1, 1)] - [InlineData(MaxRequestBodySize, 1)] - [InlineData(MaxRequestBodySize - 1, 2)] - [InlineData(MaxRequestBodySize, 2)] - public async Task ServerAcceptsRequestBodyWithinLimit(int requestBodySize, int chunks) - { - using (var server = CreateServer(MaxRequestBodySize, async httpContext => await httpContext.Response.WriteAsync("hello, world"))) - { - using (var connection = new TestConnection(server.Port)) - { - await connection.SendAll(BuildRequest(connection, requestBodySize, chunks)); - - await connection.Receive( - "HTTP/1.1 200 OK", - $"Date: {server.Context.DateHeaderValue}", - "Transfer-Encoding: chunked", - "", - "c", - "hello, world", - "0", - "", - ""); - } - } - } - - [Theory] - [InlineData(MaxRequestBodySize + 1, 0)] - [InlineData(MaxRequestBodySize + 1, 1)] - [InlineData(MaxRequestBodySize + 1, 2)] - public async Task ServerRejectsRequestBodyExceedingLimit(int requestBodySize, int chunks) - { - using (var server = CreateServer(MaxRequestBodySize, async httpContext => - { - var received = 0; - while (received < requestBodySize) - { - received += await httpContext.Request.Body.ReadAsync(new byte[1024], 0, 1024); - } - - // Should never get here - await httpContext.Response.WriteAsync("hello, world"); - })) - { - using (var connection = new TestConnection(server.Port)) - { - await connection.SendAll(BuildRequest(connection, requestBodySize, chunks)); - - await connection.ReceiveForcedEnd( - "HTTP/1.1 413 Payload Too Large", - "Connection: close", - $"Date: {server.Context.DateHeaderValue}", - "Content-Length: 0", - "", - ""); - } - } - } - - [Fact] - public async Task MaxRequestBodySizeNotEnforcedOnUpgradedConnection() - { - var sendBytes = MaxRequestBodySize + 1; - - using (var server = CreateServer(MaxRequestBodySize, async httpContext => - { - var stream = await httpContext.Features.Get().UpgradeAsync(); - - var received = 0; - while (received < sendBytes) - { - received += await stream.ReadAsync(new byte[1024], 0, 1024); - } - - var response = Encoding.ASCII.GetBytes($"{received}"); - await stream.WriteAsync(response, 0, response.Length); - })) - { - using (var connection = new TestConnection(server.Port)) - { - await connection.Send( - "GET / HTTP/1.1", - "Connection: upgrade", - "", - new string('a', sendBytes)); - - await connection.Receive( - "HTTP/1.1 101 Switching Protocols", - "Connection: Upgrade", - $"Date: {server.Context.DateHeaderValue}", - "", - $"{sendBytes}"); - } - } - } - - private string BuildRequest(TestConnection connection, int requestBodySize, int chunks) - { - var request = new StringBuilder(); - - request.Append("POST / HTTP/1.1\r\n"); - - if (chunks == 0) - { - request.Append($"Content-Length: {requestBodySize}\r\n\r\n"); - request.Append(new string('a', requestBodySize)); - } - else - { - request.Append("Transfer-Encoding: chunked\r\n\r\n"); - - var bytesSent = 0; - while (bytesSent < requestBodySize) - { - var chunkSize = Math.Min(requestBodySize / chunks, requestBodySize - bytesSent); - - request.Append($"{chunkSize:X}\r\n"); - request.Append(new string('a', chunkSize)); - request.Append("\r\n"); - - bytesSent += chunkSize; - } - - // Make sure we sent the right amount of data - Assert.Equal(requestBodySize, bytesSent); - - request.Append("0\r\n\r\n"); - } - - return request.ToString(); - } - - private TestServer CreateServer(int maxRequestBodySize, RequestDelegate app) - { - return new TestServer(app, new TestServiceContext - { - ServerOptions = new KestrelServerOptions - { - AddServerHeader = false, - Limits = - { - MaxRequestBodySize = maxRequestBodySize - } - } - }); - } - } -} diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/MaxRequestBufferSizeTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/MaxRequestBufferSizeTests.cs index 4a19b8cd10..d78f60a7cd 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/MaxRequestBufferSizeTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/MaxRequestBufferSizeTests.cs @@ -169,7 +169,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests .UseKestrel(options => { options.Limits.MaxRequestBufferSize = maxRequestBufferSize; - options.Limits.MaxRequestBodySize = _dataLength; options.UseHttps(@"TestResources/testCert.pfx", "testPassword"); if (maxRequestBufferSize.HasValue && diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs index 9434429926..645f7c5205 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs @@ -43,10 +43,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests Assert.True(bufferLength % 256 == 0, $"{nameof(bufferLength)} must be evenly divisible by 256"); var builder = new WebHostBuilder() - .UseKestrel(options => - { - options.Limits.MaxRequestBodySize = contentLength; - }) + .UseKestrel() .UseUrls("http://127.0.0.1:0/") .Configure(app => { diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerLimitsTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerLimitsTests.cs index ae17670ba3..0b9363b58f 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerLimitsTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerLimitsTests.cs @@ -149,34 +149,6 @@ namespace Microsoft.AspNetCore.Server.KestrelTests Assert.Equal(value, o.MaxRequestHeaderCount); } - [Fact] - public void MaxRequestBodySizeDefault() - { - Assert.Equal(4 * 1024 * 1024, (new KestrelServerLimits()).MaxRequestBodySize); - } - - [Theory] - [InlineData(long.MinValue)] - [InlineData(-1)] - [InlineData(0)] - public void MaxRequestBodySizeInvalid(long value) - { - Assert.Throws(() => - { - (new KestrelServerLimits()).MaxRequestBodySize = value; - }); - } - - [Theory] - [InlineData(1)] - [InlineData(long.MaxValue)] - public void MaxRequestBodySizeValid(long value) - { - var o = new KestrelServerLimits(); - o.MaxRequestBodySize = value; - Assert.Equal(value, o.MaxRequestBodySize); - } - [Fact] public void KeepAliveTimeoutDefault() { From f467c42f544f13ee42c91b99ad30e3b047d47916 Mon Sep 17 00:00:00 2001 From: Ajay Bhargav Baaskaran Date: Mon, 12 Dec 2016 00:42:17 -0800 Subject: [PATCH 1000/1662] Removed packages list in NuGetPackageVerifier.json --- NuGetPackageVerifier.json | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/NuGetPackageVerifier.json b/NuGetPackageVerifier.json index 54c54dd56f..b153ab1515 100644 --- a/NuGetPackageVerifier.json +++ b/NuGetPackageVerifier.json @@ -1,14 +1,5 @@ { - "adx": { // Packages written by the ADX team and that ship on NuGet.org - "rules": [ - "AdxVerificationCompositeRule" - ], - "packages": { - "Microsoft.AspNetCore.Server.Kestrel": { }, - "Microsoft.AspNetCore.Server.Kestrel.Https": { } - } - }, - "Default": { // Rules to run for packages not listed in any other set. + "Default": { "rules": [ "DefaultCompositeRule" ] From 51ecbd7949d42976793c148b50f89798e725be98 Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Wed, 7 Dec 2016 17:34:01 -0800 Subject: [PATCH 1001/1662] Add benchmarks for Frame writes. --- KestrelHttpServer.sln | 2 + .../Program.cs | 9 +- .../Readme.md | 4 +- .../Writing.cs | 117 ++++++++++++++++++ .../project.json | 19 +-- .../FrameTests.cs | 3 +- .../MockSocketOutput.cs} | 4 +- test/shared/TestFrame.cs | 22 ++++ 8 files changed, 162 insertions(+), 18 deletions(-) create mode 100644 test/Microsoft.AspNetCore.Server.Kestrel.Performance/Writing.cs rename test/{Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockSocketOuptut.cs => shared/MockSocketOutput.cs} (90%) create mode 100644 test/shared/TestFrame.cs diff --git a/KestrelHttpServer.sln b/KestrelHttpServer.sln index d78ceec5ad..4280909874 100644 --- a/KestrelHttpServer.sln +++ b/KestrelHttpServer.sln @@ -39,10 +39,12 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "shared", "shared", "{0EF2AC test\shared\LifetimeNotImplemented.cs = test\shared\LifetimeNotImplemented.cs test\shared\MockConnection.cs = test\shared\MockConnection.cs test\shared\MockFrameControl.cs = test\shared\MockFrameControl.cs + test\shared\MockSocketOutput.cs = test\shared\MockSocketOutput.cs test\shared\MockSystemClock.cs = test\shared\MockSystemClock.cs test\shared\SocketInputExtensions.cs = test\shared\SocketInputExtensions.cs test\shared\TestApplicationErrorLogger.cs = test\shared\TestApplicationErrorLogger.cs test\shared\TestConnection.cs = test\shared\TestConnection.cs + test\shared\TestFrame.cs = test\shared\TestFrame.cs test\shared\TestKestrelTrace.cs = test\shared\TestKestrelTrace.cs test\shared\TestServer.cs = test\shared\TestServer.cs test\shared\TestServiceContext.cs = test\shared\TestServiceContext.cs diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Program.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Program.cs index b627755d76..3e2d92774b 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Program.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Program.cs @@ -2,11 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using BenchmarkDotNet.Environments; -using BenchmarkDotNet.Jobs; -using BenchmarkDotNet.Properties; using BenchmarkDotNet.Running; -using BenchmarkDotNet.Toolchains; namespace Microsoft.AspNetCore.Server.Kestrel.Performance { @@ -36,6 +32,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance { BenchmarkRunner.Run(); } + if (type.HasFlag(BenchmarkType.Writing)) + { + BenchmarkRunner.Run(); + } } } @@ -43,6 +43,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance public enum BenchmarkType : uint { RequestParsing = 1, + Writing = 2, // add new ones in powers of two - e.g. 2,4,8,16... All = uint.MaxValue diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Readme.md b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Readme.md index b98f36ff5c..4088c38007 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Readme.md +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Readme.md @@ -2,10 +2,10 @@ To run a specific benchmark add it as parameter ``` -dotnet run RequestParsing +dotnet run -c Release RequestParsing ``` To run all use `All` as parameter ``` -dotnet run All +dotnet run -c Release All ``` Using no parameter will list all available benchmarks \ No newline at end of file diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Writing.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Writing.cs new file mode 100644 index 0000000000..07d8c9a3bc --- /dev/null +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Writing.cs @@ -0,0 +1,117 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Threading; +using System.Threading.Tasks; +using BenchmarkDotNet.Attributes; +using Microsoft.AspNetCore.Server.Kestrel.Internal; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; +using Microsoft.AspNetCore.Testing; +using Moq; + +namespace Microsoft.AspNetCore.Server.Kestrel.Performance +{ + public class Writing + { + private readonly TestFrame _frame; + private readonly TestFrame _frameChunked; + private readonly byte[] _writeData; + + public Writing() + { + _frame = MakeFrame(); + _frameChunked = MakeFrame(); + _writeData = new byte[1]; + } + + [Setup] + public void Setup() + { + _frame.Reset(); + _frame.RequestHeaders.Add("Content-Length", "1073741824"); + + _frameChunked.Reset(); + _frameChunked.RequestHeaders.Add("Transfer-Encoding", "chunked"); + } + + [Benchmark] + public void Write() + { + _frame.Write(new ArraySegment(_writeData)); + } + + [Benchmark] + public void WriteChunked() + { + _frameChunked.Write(new ArraySegment(_writeData)); + } + + [Benchmark] + public async Task WriteAsync() + { + await _frame.WriteAsync(new ArraySegment(_writeData), default(CancellationToken)); + } + + [Benchmark] + public async Task WriteAsyncChunked() + { + await _frameChunked.WriteAsync(new ArraySegment(_writeData), default(CancellationToken)); + } + + [Benchmark] + public async Task WriteAsyncAwaited() + { + await _frame.WriteAsyncAwaited(new ArraySegment(_writeData), default(CancellationToken)); + } + + [Benchmark] + public async Task WriteAsyncAwaitedChunked() + { + await _frameChunked.WriteAsyncAwaited(new ArraySegment(_writeData), default(CancellationToken)); + } + + [Benchmark] + public async Task ProduceEnd() + { + await _frame.ProduceEndAsync(); + } + + [Benchmark] + public async Task ProduceEndChunked() + { + await _frameChunked.ProduceEndAsync(); + } + + private TestFrame MakeFrame() + { + var ltp = new LoggingThreadPool(Mock.Of()); + var pool = new MemoryPool(); + var socketInput = new SocketInput(pool, ltp); + + var serviceContext = new ServiceContext + { + DateHeaderValueManager = new DateHeaderValueManager(), + ServerOptions = new KestrelServerOptions(), + Log = Mock.Of() + }; + var listenerContext = new ListenerContext(serviceContext) + { + ServerAddress = ServerAddress.FromUrl("http://localhost:5000") + }; + var connectionContext = new ConnectionContext(listenerContext) + { + Input = socketInput, + Output = new MockSocketOutput(), + ConnectionControl = Mock.Of() + }; + + var frame = new TestFrame(application: null, context: connectionContext); + frame.Reset(); + frame.InitializeHeaders(); + + return frame; + } + } +} diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/project.json b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/project.json index a74be5fefb..4871d8a63c 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/project.json +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/project.json @@ -1,14 +1,15 @@ { "version": "1.0.0-*", "dependencies": { - "BenchmarkDotNet": "0.10.0", - "Microsoft.AspNetCore.Server.Kestrel": "1.2.0-*" + "BenchmarkDotNet": "0.10.1", + "Microsoft.AspNetCore.Server.Kestrel": "1.2.0-*", + "Moq": "4.6.36-*" }, "frameworks": { - "netcoreapp1.0": { + "netcoreapp1.1": { "dependencies": { "Microsoft.NETCore.App": { - "version": "1.0.1-*", + "version": "1.1.0-*", "type": "platform" } } @@ -18,16 +19,18 @@ "emitEntryPoint": true, "compile": { "include": [ - "../shared/SocketInputExtensions.cs", - "../shared/TestKestrelTrace.cs", "../shared/TestApplicationErrorLogger.cs", - "../shared/MockConnection.cs" + "../shared/TestFrame.cs", + "../shared/TestKestrelTrace.cs", + "../shared/MockConnection.cs", + "../shared/MockSocketOutput.cs", + "../shared/SocketInputExtensions.cs" ] }, "keyFile": "../../tools/Key.snk", "copyToOutput": { "include": "TestResources/testCert.pfx" - } + }, }, "runtimeOptions": { "configProperties": { diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs index efed448cfe..b9444c0f79 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs @@ -11,7 +11,6 @@ using Microsoft.AspNetCore.Server.Kestrel; using Microsoft.AspNetCore.Server.Kestrel.Internal; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; -using Microsoft.AspNetCore.Server.KestrelTests.TestHelpers; using Microsoft.AspNetCore.Testing; using Microsoft.Extensions.Internal; using Moq; @@ -47,7 +46,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests _connectionContext = new ConnectionContext(listenerContext) { Input = _socketInput, - Output = new MockSocketOuptut(), + Output = new MockSocketOutput(), ConnectionControl = Mock.Of() }; diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockSocketOuptut.cs b/test/shared/MockSocketOutput.cs similarity index 90% rename from test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockSocketOuptut.cs rename to test/shared/MockSocketOutput.cs index b5f65900b4..19c115d94e 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockSocketOuptut.cs +++ b/test/shared/MockSocketOutput.cs @@ -8,9 +8,9 @@ using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.Extensions.Internal; -namespace Microsoft.AspNetCore.Server.KestrelTests.TestHelpers +namespace Microsoft.AspNetCore.Testing { - public class MockSocketOuptut : ISocketOutput + public class MockSocketOutput : ISocketOutput { public void ProducingComplete(MemoryPoolIterator end) { diff --git a/test/shared/TestFrame.cs b/test/shared/TestFrame.cs new file mode 100644 index 0000000000..4ccba9bd4a --- /dev/null +++ b/test/shared/TestFrame.cs @@ -0,0 +1,22 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System.Threading.Tasks; +using Microsoft.AspNetCore.Hosting.Server; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; + +namespace Microsoft.AspNetCore.Testing +{ + public class TestFrame : Frame + { + public TestFrame(IHttpApplication application, ConnectionContext context) + : base(application, context) + { + } + + public Task ProduceEndAsync() + { + return ProduceEnd(); + } + } +} \ No newline at end of file From cedbe76f5263f4fbb34dac1327cc048c10ca0d8e Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Fri, 4 Nov 2016 11:10:36 -0700 Subject: [PATCH 1002/1662] Abort request on client FIN (#1139). --- KestrelHttpServer.sln | 1 + .../Internal/Http/Connection.cs | 9 +- .../Internal/Http/Frame.cs | 24 ++ .../MaxRequestBufferSizeTests.cs | 1 - .../MaxRequestLineSizeTests.cs | 8 +- .../RequestHeaderLimitsTests.cs | 8 +- .../RequestTests.cs | 33 +++ .../ResponseTests.cs | 89 +++---- .../BadHttpRequestTests.cs | 16 +- .../ChunkedRequestTests.cs | 17 +- .../ChunkedResponseTests.cs | 22 +- .../ConnectionFilterTests.cs | 55 +++-- .../DefaultHeaderTests.cs | 2 +- .../EngineTests.cs | 228 +++++++----------- .../FrameTests.cs | 86 ++++++- .../RequestTargetProcessingTests.cs | 6 +- test/shared/DummyApplication.cs | 11 +- test/shared/TestApp.cs | 49 ++++ test/shared/TestConnection.cs | 40 ++- test/shared/TestServer.cs | 7 +- 20 files changed, 423 insertions(+), 289 deletions(-) create mode 100644 test/shared/TestApp.cs diff --git a/KestrelHttpServer.sln b/KestrelHttpServer.sln index 4280909874..fd5f9367d1 100644 --- a/KestrelHttpServer.sln +++ b/KestrelHttpServer.sln @@ -42,6 +42,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "shared", "shared", "{0EF2AC test\shared\MockSocketOutput.cs = test\shared\MockSocketOutput.cs test\shared\MockSystemClock.cs = test\shared\MockSystemClock.cs test\shared\SocketInputExtensions.cs = test\shared\SocketInputExtensions.cs + test\shared\TestApp.cs = test\shared\TestApp.cs test\shared\TestApplicationErrorLogger.cs = test\shared\TestApplicationErrorLogger.cs test\shared\TestConnection.cs = test\shared\TestConnection.cs test\shared\TestFrame.cs = test\shared\TestFrame.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Connection.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Connection.cs index eb9fae5648..1b7eaa8e97 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Connection.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Connection.cs @@ -10,6 +10,7 @@ using Microsoft.AspNetCore.Server.Kestrel.Filter; using Microsoft.AspNetCore.Server.Kestrel.Filter.Internal; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; +using Microsoft.Extensions.Internal; using Microsoft.Extensions.Logging; namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http @@ -200,7 +201,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _frame.Input = _filteredStreamAdapter.SocketInput; _frame.Output = _filteredStreamAdapter.SocketOutput; - _readInputTask = _filteredStreamAdapter.ReadInputAsync(); + // Don't attempt to read input if connection has already closed. + // This can happen if a client opens a connection and immediately closes it. + _readInputTask = _socketClosedTcs.Task.Status == TaskStatus.WaitingForActivation ? + _filteredStreamAdapter.ReadInputAsync() : + TaskCache.CompletedTask; } _frame.PrepareRequest = _filterContext.PrepareRequest; @@ -278,7 +283,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http Input.IncomingComplete(readCount, error); - if (errorDone) + if (!normalRead) { Abort(error); } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs index 0b37975bc3..2cb16d13bb 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs @@ -564,6 +564,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } else { + CheckLastWrite(); Output.Write(data); } } @@ -599,6 +600,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } else { + CheckLastWrite(); return Output.WriteAsync(data, cancellationToken: cancellationToken); } } @@ -631,6 +633,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } else { + CheckLastWrite(); await Output.WriteAsync(data, cancellationToken: cancellationToken); } } @@ -658,6 +661,24 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _responseBytesWritten += count; } + private void CheckLastWrite() + { + var responseHeaders = FrameResponseHeaders; + + // Prevent firing request aborted token if this is the last write, to avoid + // aborting the request if the app is still running when the client receives + // the final bytes of the response and gracefully closes the connection. + // + // Called after VerifyAndUpdateWrite(), so _responseBytesWritten has already been updated. + if (responseHeaders != null && + !responseHeaders.HasTransferEncoding && + responseHeaders.HasContentLength && + _responseBytesWritten == responseHeaders.HeaderContentLengthValue.Value) + { + _abortedCts = null; + } + } + protected void VerifyResponseContentLength() { var responseHeaders = FrameResponseHeaders; @@ -838,6 +859,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http private async Task WriteAutoChunkSuffixAwaited() { + // For the same reason we call CheckLastWrite() in Content-Length responses. + _abortedCts = null; + await WriteChunkedResponseSuffix(); if (_keepAlive) diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/MaxRequestBufferSizeTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/MaxRequestBufferSizeTests.cs index d78f60a7cd..4ffab99136 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/MaxRequestBufferSizeTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/MaxRequestBufferSizeTests.cs @@ -103,7 +103,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } Assert.Equal(data.Length, bytesWritten); - socket.Shutdown(SocketShutdown.Send); clientFinishedSendingRequestBody.Set(); }; diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/MaxRequestLineSizeTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/MaxRequestLineSizeTests.cs index 1118f28d07..1f6e95e767 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/MaxRequestLineSizeTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/MaxRequestLineSizeTests.cs @@ -25,13 +25,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [InlineData("DELETE /a%20b%20c/d%20e?f=ghi HTTP/1.1\r\n\r\n", 1027)] public async Task ServerAcceptsRequestLineWithinLimit(string request, int limit) { - var maxRequestLineSize = limit; - using (var server = CreateServer(limit)) { using (var connection = new TestConnection(server.Port)) { - await connection.SendEnd(request); + await connection.Send(request); await connection.ReceiveEnd( "HTTP/1.1 200 OK", $"Date: {server.Context.DateHeaderValue}", @@ -57,8 +55,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { using (var connection = new TestConnection(server.Port)) { - await connection.SendAllTryEnd($"{requestLine}\r\n"); - await connection.Receive( + await connection.SendAll(requestLine); + await connection.ReceiveForcedEnd( "HTTP/1.1 414 URI Too Long", "Connection: close", $"Date: {server.Context.DateHeaderValue}", diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestHeaderLimitsTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestHeaderLimitsTests.cs index 712407f76c..7ce1faf4bc 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestHeaderLimitsTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestHeaderLimitsTests.cs @@ -28,7 +28,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { using (var connection = new TestConnection(server.Port)) { - await connection.SendEnd($"GET / HTTP/1.1\r\n{headers}\r\n"); + await connection.Send($"GET / HTTP/1.1\r\n{headers}\r\n"); await connection.ReceiveEnd( "HTTP/1.1 200 OK", $"Date: {server.Context.DateHeaderValue}", @@ -60,7 +60,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { using (var connection = new TestConnection(server.Port)) { - await connection.SendEnd($"GET / HTTP/1.1\r\n{headers}\r\n"); + await connection.Send($"GET / HTTP/1.1\r\n{headers}\r\n"); await connection.ReceiveEnd( "HTTP/1.1 200 OK", $"Date: {server.Context.DateHeaderValue}", @@ -86,7 +86,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { using (var connection = new TestConnection(server.Port)) { - await connection.SendAllTryEnd($"GET / HTTP/1.1\r\n{headers}\r\n"); + await connection.SendAll($"GET / HTTP/1.1\r\n{headers}\r\n"); await connection.ReceiveForcedEnd( "HTTP/1.1 431 Request Header Fields Too Large", "Connection: close", @@ -110,7 +110,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { using (var connection = new TestConnection(server.Port)) { - await connection.SendAllTryEnd($"GET / HTTP/1.1\r\n{headers}\r\n"); + await connection.SendAll($"GET / HTTP/1.1\r\n{headers}\r\n"); await connection.ReceiveForcedEnd( "HTTP/1.1 431 Request Header Fields Too Large", "Connection: close", diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs index 645f7c5205..bc1362023b 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs @@ -16,6 +16,7 @@ using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; +using Microsoft.AspNetCore.Testing; using Microsoft.AspNetCore.Testing.xunit; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Testing; @@ -420,6 +421,38 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } } + [Fact] + public async Task RequestAbortedTokenFiredOnClientFIN() + { + var appStarted = new SemaphoreSlim(0); + var requestAborted = new SemaphoreSlim(0); + var builder = new WebHostBuilder() + .UseKestrel() + .UseUrls($"http://127.0.0.1:0") + .Configure(app => app.Run(async context => + { + appStarted.Release(); + + var token = context.RequestAborted; + token.Register(() => requestAborted.Release(2)); + await requestAborted.WaitAsync().TimeoutAfter(TimeSpan.FromSeconds(10)); + })); + + using (var host = builder.Build()) + { + host.Start(); + + using (var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)) + { + socket.Connect(new IPEndPoint(IPAddress.Loopback, host.GetPort())); + socket.Send(Encoding.ASCII.GetBytes("GET / HTTP/1.1\r\n\r\n")); + await appStarted.WaitAsync(); + socket.Shutdown(SocketShutdown.Send); + await requestAborted.WaitAsync().TimeoutAfter(TimeSpan.FromSeconds(10)); + } + } + } + private async Task TestRemoteIPAddress(string registerAddress, string requestAddress, string expectAddress) { var builder = new WebHostBuilder() diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs index dbf6f5bdd4..49bdc6e99c 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs @@ -5,7 +5,6 @@ using System; using System.Linq; using System.Net; using System.Net.Http; -using System.Net.Sockets; using System.Text; using System.Threading; using System.Threading.Tasks; @@ -288,26 +287,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests disposedTcs.TrySetResult(c.Response.StatusCode); }); - var hostBuilder = new WebHostBuilder() - .UseKestrel() - .UseUrls("http://127.0.0.1:0") - .ConfigureServices(services => services.AddSingleton(mockHttpContextFactory.Object)) - .Configure(app => - { - app.Run(handler); - }); - - using (var host = hostBuilder.Build()) + using (var server = new TestServer(handler, new TestServiceContext(), "http://127.0.0.1:0", mockHttpContextFactory.Object)) { - host.Start(); - if (!sendMalformedRequest) { using (var client = new HttpClient()) { try { - var response = await client.GetAsync($"http://localhost:{host.GetPort()}/"); + var response = await client.GetAsync($"http://127.0.0.1:{server.Port}/"); Assert.Equal(expectedClientStatusCode, response.StatusCode); } catch @@ -321,14 +309,20 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } else { - using (var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)) + using (var connection = new TestConnection(server.Port)) { - socket.Connect(new IPEndPoint(IPAddress.Loopback, host.GetPort())); - socket.Send(Encoding.ASCII.GetBytes( - "POST / HTTP/1.1\r\n" + - "Transfer-Encoding: chunked\r\n" + - "\r\n" + - "wrong")); + await connection.Send( + "POST / HTTP/1.1", + "Transfer-Encoding: chunked", + "", + "gg"); + await connection.ReceiveForcedEnd( + "HTTP/1.1 400 Bad Request", + "Connection: close", + $"Date: {server.Context.DateHeaderValue}", + "Content-Length: 0", + "", + ""); } } @@ -453,13 +447,19 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [Fact] public async Task ResponseBodyNotWrittenOnHeadResponseAndLoggedOnlyOnce() { - var mockKestrelTrace = new Mock(); + const string response = "hello, world"; - using (var server = new TestServer(async httpContext => - { - await httpContext.Response.WriteAsync("hello, world"); - await httpContext.Response.Body.FlushAsync(); - }, new TestServiceContext { Log = mockKestrelTrace.Object })) + var logTcs = new TaskCompletionSource(); + var mockKestrelTrace = new Mock(); + mockKestrelTrace + .Setup(trace => trace.ConnectionHeadResponseBodyWrite(It.IsAny(), response.Length)) + .Callback((connectionId, count) => logTcs.SetResult(null)); + + using (var server = new TestServer(async httpContext => + { + await httpContext.Response.WriteAsync(response); + await httpContext.Response.Body.FlushAsync(); + }, new TestServiceContext { Log = mockKestrelTrace.Object })) { using (var connection = server.CreateConnection()) { @@ -472,11 +472,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests $"Date: {server.Context.DateHeaderValue}", "", ""); + + // Wait for message to be logged before disposing the socket. + // Disposing the socket will abort the connection and Frame._requestAborted + // might be 1 by the time ProduceEnd() gets called and the message is logged. + await logTcs.Task.TimeoutAfter(TimeSpan.FromSeconds(10)); } } mockKestrelTrace.Verify(kestrelTrace => - kestrelTrace.ConnectionHeadResponseBodyWrite(It.IsAny(), "hello, world".Length), Times.Once); + kestrelTrace.ConnectionHeadResponseBodyWrite(It.IsAny(), response.Length), Times.Once); } [Fact] @@ -533,7 +538,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests "GET / HTTP/1.1", "", ""); - await connection.ReceiveEnd( + await connection.ReceiveForcedEnd( $"HTTP/1.1 200 OK", $"Date: {server.Context.DateHeaderValue}", "Content-Length: 11", @@ -566,7 +571,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests "GET / HTTP/1.1", "", ""); - await connection.ReceiveEnd( + await connection.ReceiveForcedEnd( $"HTTP/1.1 500 Internal Server Error", "Connection: close", $"Date: {server.Context.DateHeaderValue}", @@ -633,7 +638,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests "GET / HTTP/1.1", "", ""); - await connection.ReceiveEnd( + await connection.ReceiveForcedEnd( $"HTTP/1.1 500 Internal Server Error", "Connection: close", $"Date: {server.Context.DateHeaderValue}", @@ -858,7 +863,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { using (var connection = server.CreateConnection()) { - await connection.SendEnd( + await connection.Send( "GET / HTTP/1.1", "", ""); @@ -880,7 +885,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests public async Task AppCanWriteOwnBadRequestResponse() { var expectedResponse = string.Empty; - var responseWrittenTcs = new TaskCompletionSource(); + var responseWritten = new SemaphoreSlim(0); using (var server = new TestServer(async httpContext => { @@ -894,18 +899,18 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests httpContext.Response.StatusCode = 400; httpContext.Response.ContentLength = ex.Message.Length; await httpContext.Response.WriteAsync(ex.Message); - responseWrittenTcs.SetResult(null); + responseWritten.Release(); } }, new TestServiceContext())) { using (var connection = server.CreateConnection()) { - await connection.SendEnd( + await connection.Send( "POST / HTTP/1.1", "Transfer-Encoding: chunked", "", - "bad"); - await responseWrittenTcs.Task; + "wrong"); + await responseWritten.WaitAsync(); await connection.ReceiveEnd( "HTTP/1.1 400 Bad Request", $"Date: {server.Context.DateHeaderValue}", @@ -935,7 +940,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests "GET / HTTP/1.1", "", ""); - await connection.ReceiveEnd( + await connection.ReceiveForcedEnd( "HTTP/1.1 200 OK", "Connection: close", $"Date: {server.Context.DateHeaderValue}", @@ -951,7 +956,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests "Connection: keep-alive", "", ""); - await connection.ReceiveEnd( + await connection.ReceiveForcedEnd( "HTTP/1.1 200 OK", "Connection: close", $"Date: {server.Context.DateHeaderValue}", @@ -982,7 +987,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests "GET / HTTP/1.1", "", ""); - await connection.ReceiveEnd( + await connection.ReceiveForcedEnd( "HTTP/1.1 200 OK", "Connection: keep-alive", $"Date: {server.Context.DateHeaderValue}", @@ -998,7 +1003,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests "Connection: keep-alive", "", ""); - await connection.ReceiveEnd( + await connection.ReceiveForcedEnd( "HTTP/1.1 200 OK", "Connection: keep-alive", $"Date: {server.Context.DateHeaderValue}", @@ -1036,7 +1041,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests "hello, world"); // Make sure connection was kept open - await connection.SendEnd( + await connection.Send( "GET / HTTP/1.1", "", ""); diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/BadHttpRequestTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/BadHttpRequestTests.cs index 7b8b6a0114..b211578da5 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/BadHttpRequestTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/BadHttpRequestTests.cs @@ -58,7 +58,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { using (var connection = server.CreateConnection()) { - await connection.SendAllTryEnd(request); + await connection.SendAll(request); await ReceiveBadRequestResponse(connection, "400 Bad Request", server.Context.DateHeaderValue); } } @@ -88,15 +88,13 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { using (var connection = server.CreateConnection()) { - await connection.SendAllTryEnd(request); + await connection.SendAll(request); await ReceiveBadRequestResponse(connection, "505 HTTP Version Not Supported", server.Context.DateHeaderValue); } } } [Theory] - // Missing final CRLF - [InlineData("Header-1: value1\r\nHeader-2: value2\r\n")] // Leading whitespace [InlineData(" Header-1: value1\r\nHeader-2: value2\r\n\r\n")] [InlineData("\tHeader-1: value1\r\nHeader-2: value2\r\n\r\n")] @@ -124,7 +122,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { using (var connection = server.CreateConnection()) { - await connection.SendAllTryEnd($"GET / HTTP/1.1\r\n{rawHeaders}"); + await connection.SendAll($"GET / HTTP/1.1\r\n{rawHeaders}"); await ReceiveBadRequestResponse(connection, "400 Bad Request", server.Context.DateHeaderValue); } } @@ -137,7 +135,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { using (var connection = server.CreateConnection()) { - await connection.SendAllTryEnd( + await connection.SendAll( "GET / HTTP/1.1", "H\u00eb\u00e4d\u00ebr: value", "", @@ -168,7 +166,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { using (var connection = server.CreateConnection()) { - await connection.SendAllTryEnd($"GET {path} HTTP/1.1\r\n"); + await connection.SendAll($"GET {path} HTTP/1.1\r\n"); await ReceiveBadRequestResponse(connection, "400 Bad Request", server.Context.DateHeaderValue); } } @@ -183,7 +181,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { using (var connection = server.CreateConnection()) { - await connection.SendEnd($"{method} / HTTP/1.1\r\n\r\n"); + await connection.Send($"{method} / HTTP/1.1\r\n\r\n"); await ReceiveBadRequestResponse(connection, "411 Length Required", server.Context.DateHeaderValue); } } @@ -198,7 +196,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { using (var connection = server.CreateConnection()) { - await connection.SendEnd($"{method} / HTTP/1.0\r\n\r\n"); + await connection.Send($"{method} / HTTP/1.0\r\n\r\n"); await ReceiveBadRequestResponse(connection, "400 Bad Request", server.Context.DateHeaderValue); } } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedRequestTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedRequestTests.cs index 403e7a0208..6fe3bc1d6d 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedRequestTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedRequestTests.cs @@ -68,13 +68,14 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { using (var connection = server.CreateConnection()) { - await connection.SendEnd( + await connection.Send( "POST / HTTP/1.0", "Transfer-Encoding: chunked", "", "5", "Hello", "6", " World", "0", + "", ""); await connection.ReceiveEnd( "HTTP/1.1 200 OK", @@ -94,7 +95,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { using (var connection = server.CreateConnection()) { - await connection.SendEnd( + await connection.Send( "POST / HTTP/1.0", "Transfer-Encoding: chunked", "Connection: keep-alive", @@ -143,7 +144,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { using (var connection = server.CreateConnection()) { - await connection.SendEnd( + await connection.Send( "POST / HTTP/1.1", "Content-Length: 5", "", @@ -254,8 +255,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests using (var connection = server.CreateConnection()) { - await connection.SendEnd(fullRequest); - + await connection.Send(fullRequest); await connection.ReceiveEnd(expectedFullResponse); } } @@ -282,7 +282,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { using (var connection = server.CreateConnection()) { - await connection.SendAllTryEnd( + await connection.SendAll( "POST / HTTP/1.1", $"{transferEncodingHeaderLine}", $"{headerLine}", @@ -322,7 +322,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { using (var connection = server.CreateConnection()) { - await connection.SendAllTryEnd( + await connection.SendAll( "POST / HTTP/1.1", $"{transferEncodingHeaderLine}", $"{headerLine}", @@ -423,8 +423,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests using (var connection = server.CreateConnection()) { - await connection.SendEnd(fullRequest); - + await connection.Send(fullRequest); await connection.ReceiveEnd(expectedFullResponse); } } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedResponseTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedResponseTests.cs index 7ce2297b00..9bbe7c88a7 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedResponseTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedResponseTests.cs @@ -43,7 +43,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { using (var connection = server.CreateConnection()) { - await connection.SendEnd( + await connection.Send( "GET / HTTP/1.1", "", ""); @@ -75,7 +75,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { using (var connection = server.CreateConnection()) { - await connection.SendEnd( + await connection.Send( "GET / HTTP/1.0", "Connection: keep-alive", "", @@ -102,7 +102,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { using (var connection = server.CreateConnection()) { - await connection.SendEnd( + await connection.Send( "GET / HTTP/1.1", "Connection: close", "", @@ -137,7 +137,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { using (var connection = server.CreateConnection()) { - await connection.SendEnd( + await connection.Send( "GET / HTTP/1.1", "", ""); @@ -172,7 +172,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { using (var connection = server.CreateConnection()) { - await connection.SendEnd( + await connection.Send( "GET / HTTP/1.1", "", ""); @@ -210,7 +210,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { using (var connection = server.CreateConnection()) { - await connection.SendEnd( + await connection.Send( "GET / HTTP/1.1", "", ""); @@ -246,7 +246,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { using (var connection = server.CreateConnection()) { - await connection.SendEnd( + await connection.Send( "GET / HTTP/1.1", "", ""); @@ -264,7 +264,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [Theory] [MemberData(nameof(ConnectionFilterData))] - public async Task ConnectionClosedIfExeptionThrownAfterWrite(TestServiceContext testContext) + public async Task ConnectionClosedIfExceptionThrownAfterWrite(TestServiceContext testContext) { using (var server = new TestServer(async httpContext => { @@ -295,7 +295,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [Theory] [MemberData(nameof(ConnectionFilterData))] - public async Task ConnectionClosedIfExeptionThrownAfterZeroLengthWrite(TestServiceContext testContext) + public async Task ConnectionClosedIfExceptionThrownAfterZeroLengthWrite(TestServiceContext testContext) { using (var server = new TestServer(async httpContext => { @@ -342,7 +342,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { using (var connection = server.CreateConnection()) { - await connection.SendEnd( + await connection.Send( "GET / HTTP/1.1", "", ""); @@ -383,7 +383,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { using (var connection = server.CreateConnection()) { - await connection.SendEnd( + await connection.Send( "GET / HTTP/1.1", "", ""); diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionFilterTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionFilterTests.cs index 6ef4b9de24..a27e8a40bd 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionFilterTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionFilterTests.cs @@ -3,32 +3,17 @@ using System; using System.IO; +using System.Threading; using System.Threading.Tasks; -using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Server.Kestrel.Filter; using Microsoft.AspNetCore.Testing; +using Microsoft.Extensions.Internal; using Xunit; namespace Microsoft.AspNetCore.Server.KestrelTests { public class ConnectionFilterTests { - private async Task App(HttpContext httpContext) - { - var request = httpContext.Request; - var response = httpContext.Response; - while (true) - { - var buffer = new byte[8192]; - var count = await request.Body.ReadAsync(buffer, 0, buffer.Length); - if (count == 0) - { - break; - } - await response.Body.WriteAsync(buffer, 0, count); - } - } - [Fact] public async Task CanReadAndWriteWithRewritingConnectionFilter() { @@ -37,12 +22,12 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var sendString = "POST / HTTP/1.0\r\nContent-Length: 12\r\n\r\nHello World?"; - using (var server = new TestServer(App, serviceContext)) + using (var server = new TestServer(TestApp.EchoApp, serviceContext)) { using (var connection = server.CreateConnection()) { // "?" changes to "!" - await connection.SendEnd(sendString); + await connection.Send(sendString); await connection.ReceiveEnd( "HTTP/1.1 200 OK", "Connection: close", @@ -60,11 +45,11 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { var serviceContext = new TestServiceContext(new AsyncConnectionFilter()); - using (var server = new TestServer(App, serviceContext)) + using (var server = new TestServer(TestApp.EchoApp, serviceContext)) { using (var connection = server.CreateConnection()) { - await connection.SendEnd( + await connection.Send( "POST / HTTP/1.0", "Content-Length: 12", "", @@ -84,7 +69,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { var serviceContext = new TestServiceContext(new ThrowingConnectionFilter()); - using (var server = new TestServer(App, serviceContext)) + using (var server = new TestServer(TestApp.EchoApp, serviceContext)) { using (var connection = server.CreateConnection()) { @@ -108,15 +93,13 @@ namespace Microsoft.AspNetCore.Server.KestrelTests private class RewritingConnectionFilter : IConnectionFilter { - private static Task _empty = Task.FromResult(null); - private RewritingStream _rewritingStream; public Task OnConnectionAsync(ConnectionFilterContext context) { _rewritingStream = new RewritingStream(context.Connection); context.Connection = _rewritingStream; - return _empty; + return TaskCache.CompletedTask; } public int BytesRead => _rewritingStream.BytesRead; @@ -189,6 +172,15 @@ namespace Microsoft.AspNetCore.Server.KestrelTests return actual; } + public override async Task ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) + { + var actual = await _innerStream.ReadAsync(buffer, offset, count); + + BytesRead += actual; + + return actual; + } + public override long Seek(long offset, SeekOrigin origin) { return _innerStream.Seek(offset, origin); @@ -211,6 +203,19 @@ namespace Microsoft.AspNetCore.Server.KestrelTests _innerStream.Write(buffer, offset, count); } + + public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) + { + for (int i = 0; i < buffer.Length; i++) + { + if (buffer[i] == '?') + { + buffer[i] = (byte)'!'; + } + } + + return _innerStream.WriteAsync(buffer, offset, count, cancellationToken); + } } } } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/DefaultHeaderTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/DefaultHeaderTests.cs index 3070332da9..b8a843f738 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/DefaultHeaderTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/DefaultHeaderTests.cs @@ -22,7 +22,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { using (var connection = server.CreateConnection()) { - await connection.SendEnd( + await connection.Send( "GET / HTTP/1.1", "", "GET / HTTP/1.0", diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs index 650fcedbe1..d5997be036 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs @@ -42,39 +42,6 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } } - private async Task App(HttpContext httpContext) - { - var request = httpContext.Request; - var response = httpContext.Response; - while (true) - { - var buffer = new byte[8192]; - var count = await request.Body.ReadAsync(buffer, 0, buffer.Length); - if (count == 0) - { - break; - } - await response.Body.WriteAsync(buffer, 0, count); - } - } - - private async Task AppChunked(HttpContext httpContext) - { - var request = httpContext.Request; - var response = httpContext.Response; - var data = new MemoryStream(); - await request.Body.CopyToAsync(data); - var bytes = data.ToArray(); - - response.Headers["Content-Length"] = bytes.Length.ToString(); - await response.Body.WriteAsync(bytes, 0, bytes.Length); - } - - private Task EmptyApp(HttpContext httpContext) - { - return Task.FromResult(null); - } - [Theory] [MemberData(nameof(ConnectionFilterData))] public void EngineCanStartAndStop(TestServiceContext testContext) @@ -88,7 +55,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [MemberData(nameof(ConnectionFilterData))] public void ListenerCanCreateAndDispose(TestServiceContext testContext) { - testContext.App = App; + testContext.App = TestApp.EchoApp; var engine = new KestrelEngine(testContext); engine.Start(1); var address = ServerAddress.FromUrl("http://127.0.0.1:0/"); @@ -101,22 +68,22 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [MemberData(nameof(ConnectionFilterData))] public void ConnectionCanReadAndWrite(TestServiceContext testContext) { - testContext.App = App; + testContext.App = TestApp.EchoApp; var engine = new KestrelEngine(testContext); engine.Start(1); var address = ServerAddress.FromUrl("http://127.0.0.1:0/"); var started = engine.CreateServer(address); var socket = TestConnection.CreateConnectedLoopbackSocket(address.Port); - socket.Send(Encoding.ASCII.GetBytes("POST / HTTP/1.0\r\nContent-Length: 11\r\n\r\nHello World")); - socket.Shutdown(SocketShutdown.Send); - var buffer = new byte[8192]; - while (true) + var data = "Hello World"; + socket.Send(Encoding.ASCII.GetBytes($"POST / HTTP/1.0\r\nContent-Length: 11\r\n\r\n{data}")); + var buffer = new byte[data.Length]; + var read = 0; + while (read < data.Length) { - var length = socket.Receive(buffer); - if (length == 0) { break; } - var text = Encoding.ASCII.GetString(buffer, 0, length); + read += socket.Receive(buffer, read, buffer.Length - read, SocketFlags.None); } + socket.Dispose(); started.Dispose(); engine.Dispose(); } @@ -125,11 +92,11 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [MemberData(nameof(ConnectionFilterData))] public async Task Http10RequestReceivesHttp11Response(TestServiceContext testContext) { - using (var server = new TestServer(App, testContext)) + using (var server = new TestServer(TestApp.EchoApp, testContext)) { using (var connection = server.CreateConnection()) { - await connection.SendEnd( + await connection.Send( "POST / HTTP/1.0", "Content-Length: 11", "", @@ -148,11 +115,11 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [MemberData(nameof(ConnectionFilterData))] public async Task Http11(TestServiceContext testContext) { - using (var server = new TestServer(AppChunked, testContext)) + using (var server = new TestServer(TestApp.EchoAppChunked, testContext)) { using (var connection = server.CreateConnection()) { - await connection.SendEnd( + await connection.Send( "GET / HTTP/1.1", "", "GET / HTTP/1.1", @@ -243,7 +210,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests Enumerable.Repeat(response, loopCount) .Concat(new[] { lastResponse }); - await connection.SendEnd(requestData.ToArray()); + await connection.Send(requestData.ToArray()); await connection.ReceiveEnd(responseData.ToArray()); } @@ -258,11 +225,11 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [MemberData(nameof(ConnectionFilterData))] public async Task Http10ContentLength(TestServiceContext testContext) { - using (var server = new TestServer(App, testContext)) + using (var server = new TestServer(TestApp.EchoApp, testContext)) { using (var connection = server.CreateConnection()) { - await connection.SendEnd( + await connection.Send( "POST / HTTP/1.0", "Content-Length: 11", "", @@ -281,11 +248,11 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [MemberData(nameof(ConnectionFilterData))] public async Task Http10KeepAlive(TestServiceContext testContext) { - using (var server = new TestServer(AppChunked, testContext)) + using (var server = new TestServer(TestApp.EchoAppChunked, testContext)) { using (var connection = server.CreateConnection()) { - await connection.SendEnd( + await connection.Send( "GET / HTTP/1.0", "Connection: keep-alive", "", @@ -314,11 +281,11 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [MemberData(nameof(ConnectionFilterData))] public async Task Http10KeepAliveNotUsedIfResponseContentLengthNotSet(TestServiceContext testContext) { - using (var server = new TestServer(App, testContext)) + using (var server = new TestServer(TestApp.EchoApp, testContext)) { using (var connection = server.CreateConnection()) { - await connection.SendEnd( + await connection.Send( "GET / HTTP/1.0", "Connection: keep-alive", "", @@ -347,11 +314,11 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [MemberData(nameof(ConnectionFilterData))] public async Task Http10KeepAliveContentLength(TestServiceContext testContext) { - using (var server = new TestServer(AppChunked, testContext)) + using (var server = new TestServer(TestApp.EchoAppChunked, testContext)) { using (var connection = server.CreateConnection()) { - await connection.SendEnd( + await connection.Send( "POST / HTTP/1.0", "Content-Length: 11", "Connection: keep-alive", @@ -382,7 +349,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [MemberData(nameof(ConnectionFilterData))] public async Task Expect100ContinueForBody(TestServiceContext testContext) { - using (var server = new TestServer(AppChunked, testContext)) + using (var server = new TestServer(TestApp.EchoAppChunked, testContext)) { using (var connection = server.CreateConnection()) { @@ -392,8 +359,11 @@ namespace Microsoft.AspNetCore.Server.KestrelTests "Connection: close", "Content-Length: 11", "\r\n"); - await connection.Receive("HTTP/1.1 100 Continue", "\r\n"); - await connection.SendEnd("Hello World"); + await connection.Receive( + "HTTP/1.1 100 Continue", + "", + ""); + await connection.Send("Hello World"); await connection.Receive( "HTTP/1.1 200 OK", "Connection: close", @@ -409,7 +379,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [MemberData(nameof(ConnectionFilterData))] public async Task DisconnectingClient(TestServiceContext testContext) { - using (var server = new TestServer(App, testContext)) + using (var server = new TestServer(TestApp.EchoApp, testContext)) { var socket = TestConnection.CreateConnectedLoopbackSocket(server.Port); await Task.Delay(200); @@ -418,15 +388,17 @@ namespace Microsoft.AspNetCore.Server.KestrelTests await Task.Delay(200); using (var connection = server.CreateConnection()) { - await connection.SendEnd( + await connection.Send( "GET / HTTP/1.0", - "\r\n"); + "", + ""); await connection.ReceiveEnd( "HTTP/1.1 200 OK", "Connection: close", $"Date: {testContext.DateHeaderValue}", "Content-Length: 0", - "\r\n"); + "", + ""); } } } @@ -435,11 +407,11 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [MemberData(nameof(ConnectionFilterData))] public async Task ZeroContentLengthSetAutomaticallyAfterNoWrites(TestServiceContext testContext) { - using (var server = new TestServer(EmptyApp, testContext)) + using (var server = new TestServer(TestApp.EmptyApp, testContext)) { using (var connection = server.CreateConnection()) { - await connection.SendEnd( + await connection.Send( "GET / HTTP/1.1", "", "GET / HTTP/1.0", @@ -472,7 +444,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { using (var connection = server.CreateConnection()) { - await connection.SendEnd( + await connection.Send( "GET / HTTP/1.1", "Connection: close", "", @@ -488,7 +460,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests using (var connection = server.CreateConnection()) { - await connection.SendEnd( + await connection.Send( "GET / HTTP/1.0", "", ""); @@ -507,11 +479,11 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [MemberData(nameof(ConnectionFilterData))] public async Task ZeroContentLengthNotSetAutomaticallyForHeadRequests(TestServiceContext testContext) { - using (var server = new TestServer(EmptyApp, testContext)) + using (var server = new TestServer(TestApp.EmptyApp, testContext)) { using (var connection = server.CreateConnection()) { - await connection.SendEnd( + await connection.Send( "HEAD / HTTP/1.1", "", ""); @@ -542,7 +514,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { using (var connection = server.CreateConnection()) { - await connection.SendEnd( + await connection.Send( "POST / HTTP/1.1", "Content-Length: 3", "", @@ -639,7 +611,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests "GET / HTTP/1.1", "", ""); - await connection.ReceiveEnd( + await connection.ReceiveForcedEnd( "HTTP/1.1 101 Switching Protocols", "Connection: Upgrade", $"Date: {testContext.DateHeaderValue}", @@ -654,7 +626,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests "Connection: keep-alive", "", ""); - await connection.ReceiveEnd( + await connection.ReceiveForcedEnd( "HTTP/1.1 101 Switching Protocols", "Connection: Upgrade", $"Date: {testContext.DateHeaderValue}", @@ -679,7 +651,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests response.OnStarting(_ => { onStartingCalled = true; - return Task.FromResult(null); + return TaskCache.CompletedTask; }, null); // Anything added to the ResponseHeaders dictionary is ignored @@ -689,25 +661,20 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { using (var connection = server.CreateConnection()) { - await connection.SendEnd( + await connection.Send( "GET / HTTP/1.1", "", "GET / HTTP/1.1", "Connection: close", "", ""); - await connection.Receive( + await connection.ReceiveForcedEnd( "HTTP/1.1 500 Internal Server Error", - ""); - await connection.Receive( $"Date: {testContext.DateHeaderValue}", "Content-Length: 0", "", "HTTP/1.1 500 Internal Server Error", - ""); - await connection.Receive("Connection: close", - ""); - await connection.ReceiveEnd( + "Connection: close", $"Date: {testContext.DateHeaderValue}", "Content-Length: 0", "", @@ -802,48 +769,19 @@ namespace Microsoft.AspNetCore.Server.KestrelTests Assert.True(onStartingCalled); Assert.Equal(1, testLogger.ApplicationErrorsLogged); } - - [Theory] - [MemberData(nameof(ConnectionFilterData))] - public async Task ConnectionClosesWhenFinReceived(TestServiceContext testContext) - { - using (var server = new TestServer(AppChunked, testContext)) - { - using (var connection = server.CreateConnection()) - { - await connection.SendEnd( - "GET / HTTP/1.1", - "", - "Post / HTTP/1.1", - "Content-Length: 7", - "", - "Goodbye"); - await connection.ReceiveEnd( - "HTTP/1.1 200 OK", - $"Date: {testContext.DateHeaderValue}", - "Content-Length: 0", - "", - "HTTP/1.1 200 OK", - $"Date: {testContext.DateHeaderValue}", - "Content-Length: 7", - "", - "Goodbye"); - } - } - } - - [Theory] + [MemberData(nameof(ConnectionFilterData))] public async Task ConnectionClosesWhenFinReceivedBeforeRequestCompletes(TestServiceContext testContext) { - using (var server = new TestServer(AppChunked, testContext)) + using (var server = new TestServer(TestApp.EchoAppChunked, testContext)) { using (var connection = server.CreateConnection()) { - await connection.SendEnd( + await connection.Send( "GET / HTTP/1.1", "", "POST / HTTP/1.1"); + connection.Shutdown(SocketShutdown.Send); await connection.ReceiveForcedEnd( "HTTP/1.1 200 OK", $"Date: {testContext.DateHeaderValue}", @@ -859,11 +797,12 @@ namespace Microsoft.AspNetCore.Server.KestrelTests using (var connection = server.CreateConnection()) { - await connection.SendEnd( + await connection.Send( "GET / HTTP/1.1", "", "POST / HTTP/1.1", "Content-Length: 7"); + connection.Shutdown(SocketShutdown.Send); await connection.ReceiveForcedEnd( "HTTP/1.1 200 OK", $"Date: {testContext.DateHeaderValue}", @@ -918,24 +857,18 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { using (var connection = server.CreateConnection()) { - await connection.SendEnd( + await connection.Send( "GET / HTTP/1.1", "", "GET / HTTP/1.1", - "Connection: close", "", ""); - await connection.Receive( + await connection.ReceiveEnd( "HTTP/1.1 500 Internal Server Error", - ""); - await connection.Receive( $"Date: {testContext.DateHeaderValue}", "Content-Length: 0", "", "HTTP/1.1 500 Internal Server Error", - "Connection: close", - ""); - await connection.ReceiveEnd( $"Date: {testContext.DateHeaderValue}", "Content-Length: 0", "", @@ -1072,7 +1005,6 @@ namespace Microsoft.AspNetCore.Server.KestrelTests Assert.Equal(2, abortedRequestId); } - [Theory] [MemberData(nameof(ConnectionFilterData))] public async Task FailedWritesResultInAbortedRequest(TestServiceContext testContext) { @@ -1215,7 +1147,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { using (var connection = server.CreateConnection()) { - await connection.SendEnd( + await connection.Send( "GET / HTTP/1.1", "", "GET / HTTP/1.1", @@ -1262,7 +1194,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { using (var connection = server.CreateConnection()) { - await connection.SendEnd( + await connection.Send( "GET / HTTP/1.1", "", "GET / HTTP/1.1", @@ -1290,13 +1222,13 @@ namespace Microsoft.AspNetCore.Server.KestrelTests using (var server = new TestServer(async httpContext => { var path = httpContext.Request.Path.Value; - httpContext.Response.Headers["Content-Length"] = new[] {path.Length.ToString() }; + httpContext.Response.Headers["Content-Length"] = new[] { path.Length.ToString() }; await httpContext.Response.WriteAsync(path); })) { using (var connection = server.CreateConnection()) { - await connection.SendEnd( + await connection.Send( $"GET {inputPath} HTTP/1.1", "", ""); @@ -1330,14 +1262,14 @@ namespace Microsoft.AspNetCore.Server.KestrelTests callOrder.Push(2); return TaskCache.CompletedTask; }, null); - + context.Response.ContentLength = response.Length; await context.Response.WriteAsync(response); }, testContext)) { using (var connection = server.CreateConnection()) { - await connection.SendEnd( + await connection.Send( "GET / HTTP/1.1", "", ""); @@ -1348,10 +1280,12 @@ namespace Microsoft.AspNetCore.Server.KestrelTests "", "hello, world"); - Assert.Equal(1, callOrder.Pop()); - Assert.Equal(2, callOrder.Pop()); + } } + + Assert.Equal(1, callOrder.Pop()); + Assert.Equal(2, callOrder.Pop()); } [Theory] @@ -1381,7 +1315,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { using (var connection = server.CreateConnection()) { - await connection.SendEnd( + await connection.Send( "GET / HTTP/1.1", "", ""); @@ -1391,47 +1325,47 @@ namespace Microsoft.AspNetCore.Server.KestrelTests $"Content-Length: {response.Length}", "", "hello, world"); - - Assert.Equal(1, callOrder.Pop()); - Assert.Equal(2, callOrder.Pop()); } } + + Assert.Equal(1, callOrder.Pop()); + Assert.Equal(2, callOrder.Pop()); } [Theory] [MemberData(nameof(ConnectionFilterData))] public async Task UpgradeRequestIsNotKeptAliveOrChunked(TestServiceContext testContext) { + const string message = "Hello World"; + using (var server = new TestServer(async context => { var upgradeFeature = context.Features.Get(); var duplexStream = await upgradeFeature.UpgradeAsync(); - while (true) + var buffer = new byte[message.Length]; + var read = 0; + while (read < message.Length) { - var buffer = new byte[8192]; - var count = await duplexStream.ReadAsync(buffer, 0, buffer.Length); - if (count == 0) - { - break; - } - await duplexStream.WriteAsync(buffer, 0, count); + read += await duplexStream.ReadAsync(buffer, read, buffer.Length - read).TimeoutAfter(TimeSpan.FromSeconds(10)); } + + await duplexStream.WriteAsync(buffer, 0, read); }, testContext)) { using (var connection = server.CreateConnection()) { - await connection.SendEnd( + await connection.Send( "GET / HTTP/1.1", "Connection: Upgrade", "", - "Hello World"); - await connection.ReceiveEnd( + message); + await connection.ReceiveForcedEnd( "HTTP/1.1 101 Switching Protocols", "Connection: Upgrade", $"Date: {testContext.DateHeaderValue}", "", - "Hello World"); + message); } } } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs index b9444c0f79..318061b832 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs @@ -6,6 +6,7 @@ using System.IO; using System.Text; using System.Threading; using System.Threading.Tasks; +using Microsoft.AspNetCore.Hosting.Server; using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Server.Kestrel; using Microsoft.AspNetCore.Server.Kestrel.Internal; @@ -22,10 +23,23 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { private readonly SocketInput _socketInput; private readonly MemoryPool _pool; - private readonly Frame _frame; + private readonly TestFrame _frame; private readonly ServiceContext _serviceContext; private readonly ConnectionContext _connectionContext; + private class TestFrame : Frame + { + public TestFrame(IHttpApplication application, ConnectionContext context) + : base(application, context) + { + } + + public Task ProduceEndAsync() + { + return ProduceEnd(); + } + } + public FrameTests() { var trace = new KestrelTrace(new TestKestrelTrace()); @@ -50,7 +64,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests ConnectionControl = Mock.Of() }; - _frame = new Frame(application: null, context: _connectionContext); + _frame = new TestFrame(application: null, context: _connectionContext); _frame.Reset(); _frame.InitializeHeaders(); } @@ -713,5 +727,73 @@ namespace Microsoft.AspNetCore.Server.KestrelTests await requestProcessingTask.TimeoutAfter(TimeSpan.FromSeconds(10)); _socketInput.IncomingFin(); } + + [Fact] + public void RequestAbortedTokenIsResetBeforeLastWriteWithContentLength() + { + _frame.ResponseHeaders["Content-Length"] = "12"; + + // Need to compare WaitHandle ref since CancellationToken is struct + var original = _frame.RequestAborted.WaitHandle; + + foreach (var ch in "hello, worl") + { + _frame.Write(new ArraySegment(new[] { (byte)ch })); + Assert.Same(original, _frame.RequestAborted.WaitHandle); + } + + _frame.Write(new ArraySegment(new[] { (byte)'d' })); + Assert.NotSame(original, _frame.RequestAborted.WaitHandle); + } + + [Fact] + public async Task RequestAbortedTokenIsResetBeforeLastWriteAsyncWithContentLength() + { + _frame.ResponseHeaders["Content-Length"] = "12"; + + // Need to compare WaitHandle ref since CancellationToken is struct + var original = _frame.RequestAborted.WaitHandle; + + foreach (var ch in "hello, worl") + { + await _frame.WriteAsync(new ArraySegment(new[] { (byte)ch }), default(CancellationToken)); + Assert.Same(original, _frame.RequestAborted.WaitHandle); + } + + await _frame.WriteAsync(new ArraySegment(new[] { (byte)'d' }), default(CancellationToken)); + Assert.NotSame(original, _frame.RequestAborted.WaitHandle); + } + + [Fact] + public async Task RequestAbortedTokenIsResetBeforeLastWriteAsyncAwaitedWithContentLength() + { + _frame.ResponseHeaders["Content-Length"] = "12"; + + // Need to compare WaitHandle ref since CancellationToken is struct + var original = _frame.RequestAborted.WaitHandle; + + foreach (var ch in "hello, worl") + { + await _frame.WriteAsyncAwaited(new ArraySegment(new[] { (byte)ch }), default(CancellationToken)); + Assert.Same(original, _frame.RequestAborted.WaitHandle); + } + + await _frame.WriteAsyncAwaited(new ArraySegment(new[] { (byte)'d' }), default(CancellationToken)); + Assert.NotSame(original, _frame.RequestAborted.WaitHandle); + } + + [Fact] + public async Task RequestAbortedTokenIsResetBeforeLastWriteWithChunkedEncoding() + { + // Need to compare WaitHandle ref since CancellationToken is struct + var original = _frame.RequestAborted.WaitHandle; + + _frame.HttpVersion = "HTTP/1.1"; + await _frame.WriteAsync(new ArraySegment(Encoding.ASCII.GetBytes("hello, world")), default(CancellationToken)); + Assert.Same(original, _frame.RequestAborted.WaitHandle); + + await _frame.ProduceEndAsync(); + Assert.NotSame(original, _frame.RequestAborted.WaitHandle); + } } } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/RequestTargetProcessingTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/RequestTargetProcessingTests.cs index e01610a93d..a793cf0269 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/RequestTargetProcessingTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/RequestTargetProcessingTests.cs @@ -27,7 +27,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { using (var connection = server.CreateConnection()) { - await connection.SendEnd( + await connection.Send( "GET /%41%CC%8A/A/../B/%41%CC%8A HTTP/1.1", "", ""); @@ -71,7 +71,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { using (var connection = server.CreateConnection()) { - await connection.SendEnd( + await connection.Send( $"GET {requestTarget} HTTP/1.1", "", ""); @@ -115,7 +115,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { using (var connection = server.CreateConnection()) { - await connection.SendEnd( + await connection.Send( $"GET {requestTarget} HTTP/1.1", "", ""); diff --git a/test/shared/DummyApplication.cs b/test/shared/DummyApplication.cs index a4b3eb4b1a..e944bf3562 100644 --- a/test/shared/DummyApplication.cs +++ b/test/shared/DummyApplication.cs @@ -12,20 +12,27 @@ namespace Microsoft.AspNetCore.Testing public class DummyApplication : IHttpApplication { private readonly RequestDelegate _requestDelegate; + private readonly IHttpContextFactory _httpContextFactory; public DummyApplication(RequestDelegate requestDelegate) + : this(requestDelegate, null) + { + } + + public DummyApplication(RequestDelegate requestDelegate, IHttpContextFactory httpContextFactory) { _requestDelegate = requestDelegate; + _httpContextFactory = httpContextFactory; } public HttpContext CreateContext(IFeatureCollection contextFeatures) { - return new DefaultHttpContext(contextFeatures); + return _httpContextFactory?.Create(contextFeatures) ?? new DefaultHttpContext(contextFeatures); } public void DisposeContext(HttpContext context, Exception exception) { - + _httpContextFactory?.Dispose(context); } public async Task ProcessRequestAsync(HttpContext context) diff --git a/test/shared/TestApp.cs b/test/shared/TestApp.cs new file mode 100644 index 0000000000..54a4f33a90 --- /dev/null +++ b/test/shared/TestApp.cs @@ -0,0 +1,49 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System.IO; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Http; +using Microsoft.Extensions.Internal; + +namespace Microsoft.AspNetCore.Testing +{ + public static class TestApp + { + public static async Task EchoApp(HttpContext httpContext) + { + var request = httpContext.Request; + var response = httpContext.Response; + var buffer = new byte[httpContext.Request.ContentLength ?? 0]; + var bytesRead = 0; + + while (bytesRead < buffer.Length) + { + var count = await request.Body.ReadAsync(buffer, bytesRead, buffer.Length - bytesRead); + bytesRead += count; + } + + if (buffer.Length > 0) + { + await response.Body.WriteAsync(buffer, 0, buffer.Length); + } + } + + public static async Task EchoAppChunked(HttpContext httpContext) + { + var request = httpContext.Request; + var response = httpContext.Response; + var data = new MemoryStream(); + await request.Body.CopyToAsync(data); + var bytes = data.ToArray(); + + response.Headers["Content-Length"] = bytes.Length.ToString(); + await response.Body.WriteAsync(bytes, 0, bytes.Length); + } + + public static Task EmptyApp(HttpContext httpContext) + { + return TaskCache.CompletedTask; + } + } +} \ No newline at end of file diff --git a/test/shared/TestConnection.cs b/test/shared/TestConnection.cs index 56e6c53ce2..13b9d67fa8 100644 --- a/test/shared/TestConnection.cs +++ b/test/shared/TestConnection.cs @@ -50,22 +50,6 @@ namespace Microsoft.AspNetCore.Testing _stream.Flush(); } - public async Task SendAllTryEnd(params string[] lines) - { - await SendAll(lines); - - try - { - _socket.Shutdown(SocketShutdown.Send); - } - catch (IOException) - { - // The server may forcefully close the connection (usually due to a bad request), - // so an IOException: "An existing connection was forcibly closed by the remote host" - // isn't guaranteed but not unexpected. - } - } - public async Task Send(params string[] lines) { var text = string.Join("\r\n", lines); @@ -82,12 +66,6 @@ namespace Microsoft.AspNetCore.Testing _stream.Flush(); } - public async Task SendEnd(params string[] lines) - { - await Send(lines); - _socket.Shutdown(SocketShutdown.Send); - } - public async Task Receive(params string[] lines) { var expected = string.Join("\r\n", lines); @@ -95,6 +73,7 @@ namespace Microsoft.AspNetCore.Testing var offset = 0; while (offset < expected.Length) { + var data = new byte[expected.Length]; var task = _reader.ReadAsync(actual, offset, actual.Length - offset); if (!Debugger.IsAttached) { @@ -108,12 +87,13 @@ namespace Microsoft.AspNetCore.Testing offset += count; } - Assert.Equal(expected, new String(actual, 0, offset)); + Assert.Equal(expected, new string(actual, 0, offset)); } public async Task ReceiveEnd(params string[] lines) { await Receive(lines); + _socket.Shutdown(SocketShutdown.Send); var ch = new char[128]; var count = await _reader.ReadAsync(ch, 0, 128).TimeoutAfter(TimeSpan.FromMinutes(1)); var text = new string(ch, 0, count); @@ -139,11 +119,16 @@ namespace Microsoft.AspNetCore.Testing } } + public void Shutdown(SocketShutdown how) + { + _socket.Shutdown(how); + } + public Task WaitForConnectionClose() { var tcs = new TaskCompletionSource(); var eventArgs = new SocketAsyncEventArgs(); - eventArgs.SetBuffer(new byte[1], 0, 1); + eventArgs.SetBuffer(new byte[128], 0, 128); eventArgs.Completed += ReceiveAsyncCompleted; eventArgs.UserToken = tcs; @@ -157,11 +142,16 @@ namespace Microsoft.AspNetCore.Testing private void ReceiveAsyncCompleted(object sender, SocketAsyncEventArgs e) { + var tcs = (TaskCompletionSource)e.UserToken; if (e.BytesTransferred == 0) { - var tcs = (TaskCompletionSource)e.UserToken; tcs.SetResult(null); } + else + { + tcs.SetException(new IOException( + $"Expected connection close, received data instead: \"{_reader.CurrentEncoding.GetString(e.Buffer, 0, e.BytesTransferred)}\"")); + } } public static Socket CreateConnectedLoopbackSocket(int port) diff --git a/test/shared/TestServer.cs b/test/shared/TestServer.cs index 738b0b10df..f52cc190d3 100644 --- a/test/shared/TestServer.cs +++ b/test/shared/TestServer.cs @@ -29,12 +29,17 @@ namespace Microsoft.AspNetCore.Testing } public TestServer(RequestDelegate app, TestServiceContext context, string serverAddress) + : this(app, context, serverAddress, null) + { + } + + public TestServer(RequestDelegate app, TestServiceContext context, string serverAddress, IHttpContextFactory httpContextFactory) { Context = context; context.FrameFactory = connectionContext => { - return new Frame(new DummyApplication(app), connectionContext); + return new Frame(new DummyApplication(app, httpContextFactory), connectionContext); }; try From 4485bfec3900d97e36967b7cca1fe045ba491621 Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Tue, 13 Dec 2016 12:55:15 -0800 Subject: [PATCH 1003/1662] Fix test races caused by cedbe76. --- .../ResponseTests.cs | 22 ++++++++++++++----- .../EngineTests.cs | 10 ++++++++- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs index 49bdc6e99c..21bd934ff8 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs @@ -590,14 +590,22 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [Fact] public async Task WhenAppWritesLessThanContentLengthErrorLogged() { - var testLogger = new TestApplicationErrorLogger(); - var serviceContext = new TestServiceContext { Log = new TestKestrelTrace(testLogger) }; + string errorMessage = null; + var logTcs = new TaskCompletionSource(); + var mockTrace = new Mock(); + mockTrace + .Setup(trace => trace.ApplicationError(It.IsAny(), It.IsAny())) + .Callback((connectionId, ex) => + { + errorMessage = ex.Message; + logTcs.SetResult(null); + }); using (var server = new TestServer(async httpContext => { httpContext.Response.ContentLength = 13; await httpContext.Response.WriteAsync("hello, world"); - }, serviceContext)) + }, new TestServiceContext { Log = mockTrace.Object })) { using (var connection = server.CreateConnection()) { @@ -611,13 +619,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests "Content-Length: 13", "", "hello, world"); + + // Wait for error message to be logged. + await logTcs.Task.TimeoutAfter(TimeSpan.FromSeconds(10)); } } - var errorMessage = Assert.Single(testLogger.Messages, message => message.LogLevel == LogLevel.Error); Assert.Equal( $"Response Content-Length mismatch: too few bytes written (12 of 13).", - errorMessage.Exception.Message); + errorMessage); } [Fact] @@ -909,7 +919,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests "POST / HTTP/1.1", "Transfer-Encoding: chunked", "", - "wrong"); + "gg"); await responseWritten.WaitAsync(); await connection.ReceiveEnd( "HTTP/1.1 400 Bad Request", diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs index d5997be036..f6ea43495e 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs @@ -1249,12 +1249,14 @@ namespace Microsoft.AspNetCore.Server.KestrelTests const string response = "hello, world"; var callOrder = new Stack(); + var onStartingTcs = new TaskCompletionSource(); using (var server = new TestServer(async context => { context.Response.OnStarting(_ => { callOrder.Push(1); + onStartingTcs.SetResult(null); return TaskCache.CompletedTask; }, null); context.Response.OnStarting(_ => @@ -1280,7 +1282,8 @@ namespace Microsoft.AspNetCore.Server.KestrelTests "", "hello, world"); - + // Wait for all callbacks to be called. + await onStartingTcs.Task.TimeoutAfter(TimeSpan.FromSeconds(10)); } } @@ -1295,12 +1298,14 @@ namespace Microsoft.AspNetCore.Server.KestrelTests const string response = "hello, world"; var callOrder = new Stack(); + var onCompletedTcs = new TaskCompletionSource(); using (var server = new TestServer(async context => { context.Response.OnCompleted(_ => { callOrder.Push(1); + onCompletedTcs.SetResult(null); return TaskCache.CompletedTask; }, null); context.Response.OnCompleted(_ => @@ -1325,6 +1330,9 @@ namespace Microsoft.AspNetCore.Server.KestrelTests $"Content-Length: {response.Length}", "", "hello, world"); + + // Wait for all callbacks to be called. + await onCompletedTcs.Task.TimeoutAfter(TimeSpan.FromSeconds(10)); } } From 7bdd98ea6954e64f74ed9a9fa3145f7ea008d79c Mon Sep 17 00:00:00 2001 From: Mike Harder Date: Thu, 15 Dec 2016 16:33:22 -0800 Subject: [PATCH 1004/1662] Enable Server GC for Samples --- samples/LargeResponseApp/project.json | 7 ++++++- samples/SampleApp/project.json | 7 ++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/samples/LargeResponseApp/project.json b/samples/LargeResponseApp/project.json index 7ed65ab333..eaf79cd206 100644 --- a/samples/LargeResponseApp/project.json +++ b/samples/LargeResponseApp/project.json @@ -21,5 +21,10 @@ "include": [ "hosting.json" ] - } + }, + "runtimeOptions": { + "configProperties": { + "System.GC.Server": true + } + } } \ No newline at end of file diff --git a/samples/SampleApp/project.json b/samples/SampleApp/project.json index 82eacdcb88..b9f5a5cb90 100644 --- a/samples/SampleApp/project.json +++ b/samples/SampleApp/project.json @@ -24,5 +24,10 @@ "hosting.json", "testCert.pfx" ] - } + }, + "runtimeOptions": { + "configProperties": { + "System.GC.Server": true + } + } } \ No newline at end of file From 8b44e8e38289b0e0a48b3b08b5645835627176ed Mon Sep 17 00:00:00 2001 From: Pavel Krymets Date: Fri, 16 Dec 2016 14:42:30 -0800 Subject: [PATCH 1005/1662] Prevent closure allocations in OnHeartbeat (#1261) --- .../Internal/Infrastructure/KestrelThread.cs | 26 ++++++++++--------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/KestrelThread.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/KestrelThread.cs index ec8394be20..60536fe5d9 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/KestrelThread.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/KestrelThread.cs @@ -23,6 +23,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal private static readonly Action _postCallbackAdapter = (callback, state) => ((Action)callback).Invoke(state); private static readonly Action _postAsyncCallbackAdapter = (callback, state) => ((Action)callback).Invoke(state); + private static readonly Libuv.uv_walk_cb _heartbeatWalkCallback = (ptr, arg) => + { + var handle = UvMemory.FromIntPtr(ptr); + (handle as UvStreamHandle)?.Connection?.Tick((long)arg); + }; // maximum times the work queues swapped and are processed in a single pass // as completing a task may immediately have write data to put on the network @@ -245,14 +250,17 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal } public void Walk(Action callback) + { + Walk((ptr, arg) => callback(ptr), IntPtr.Zero); + } + + private void Walk(Libuv.uv_walk_cb callback, IntPtr arg) { _engine.Libuv.walk( _loop, - (ptr, arg) => - { - callback(ptr); - }, - IntPtr.Zero); + callback, + arg + ); } private void PostCloseHandle(Action callback, IntPtr handle) @@ -336,13 +344,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal private void OnHeartbeat(UvTimerHandle timer) { - var now = Loop.Now(); - - Walk(ptr => - { - var handle = UvMemory.FromIntPtr(ptr); - (handle as UvStreamHandle)?.Connection?.Tick(now); - }); + Walk(_heartbeatWalkCallback, (IntPtr)Loop.Now()); } private bool DoPostWork() From b41c4078bdbbf2b2413fe13922a64552ed1177b6 Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Wed, 14 Dec 2016 16:53:19 -0800 Subject: [PATCH 1006/1662] Abort connections not closed during shutdown (#1112). --- .../Internal/Http/Connection.cs | 6 ++-- .../Internal/Http/ConnectionManager.cs | 29 +++++++++++++++---- .../Internal/Http/SocketOutput.cs | 8 ++--- .../Internal/Infrastructure/IKestrelTrace.cs | 2 ++ .../Internal/Infrastructure/KestrelThread.cs | 7 ++++- .../Internal/Infrastructure/KestrelTrace.cs | 7 +++++ test/shared/MockConnection.cs | 4 ++- 7 files changed, 50 insertions(+), 13 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Connection.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Connection.cs index 1b7eaa8e97..2b2366ee4e 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Connection.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Connection.cs @@ -142,7 +142,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http return _socketClosedTcs.Task; } - public virtual void Abort(Exception error = null) + public virtual Task AbortAsync(Exception error = null) { // Frame.Abort calls user code while this method is always // called from a libuv thread. @@ -150,6 +150,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { _frame.Abort(error); }); + + return _socketClosedTcs.Task; } // Called on Libuv thread @@ -285,7 +287,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if (!normalRead) { - Abort(error); + AbortAsync(error); } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ConnectionManager.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ConnectionManager.cs index 561f45ee06..884324f0e8 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ConnectionManager.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ConnectionManager.cs @@ -3,7 +3,6 @@ using System; using System.Collections.Generic; -using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; @@ -22,17 +21,37 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } public async Task WalkConnectionsAndCloseAsync(TimeSpan timeout) + { + return await WalkConnectionsAsync((connectionManager, tcs) => connectionManager.WalkConnectionsAndCloseCore(tcs), timeout).ConfigureAwait(false); + } + + public async Task WalkConnectionsAndAbortAsync(TimeSpan timeout) + { + return await WalkConnectionsAsync((connectionManager, tcs) => connectionManager.WalkConnectionsAndAbortCore(tcs), timeout).ConfigureAwait(false); + } + + private async Task WalkConnectionsAsync(Action> action, TimeSpan timeout) { var tcs = new TaskCompletionSource(); - _thread.Post(state => ((ConnectionManager)state).WalkConnectionsAndCloseCore(tcs), this); + _thread.Post(state => action((ConnectionManager)state, tcs), this); return await Task.WhenAny(tcs.Task, Task.Delay(timeout)).ConfigureAwait(false) == tcs.Task; } private void WalkConnectionsAndCloseCore(TaskCompletionSource tcs) { - var connectionStopTasks = new List(); + WalkConnectionsCore(connection => connection.StopAsync(), tcs); + } + + private void WalkConnectionsAndAbortCore(TaskCompletionSource tcs) + { + WalkConnectionsCore(connection => connection.AbortAsync(), tcs); + } + + private void WalkConnectionsCore(Func action, TaskCompletionSource tcs) + { + var tasks = new List(); _thread.Walk(ptr => { @@ -41,13 +60,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if (connection != null) { - connectionStopTasks.Add(connection.StopAsync()); + tasks.Add(action(connection)); } }); _threadPool.Run(() => { - Task.WaitAll(connectionStopTasks.ToArray()); + Task.WaitAll(tasks.ToArray()); tcs.SetResult(null); }); } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/SocketOutput.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/SocketOutput.cs index 4a6cac5006..d7ac287ec6 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/SocketOutput.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/SocketOutput.cs @@ -158,7 +158,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { if (cancellationToken.IsCancellationRequested) { - _connection.Abort(); + _connection.AbortAsync(); _cancelled = true; return TaskUtilities.GetCancelledTask(cancellationToken); } @@ -304,7 +304,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { // Abort the connection for any failed write // Queued on threadpool so get it in as first op. - _connection.Abort(); + _connection.AbortAsync(); _cancelled = true; CompleteAllWrites(); @@ -374,7 +374,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { // Abort the connection for any failed write // Queued on threadpool so get it in as first op. - _connection.Abort(); + _connection.AbortAsync(); _cancelled = true; _lastWriteError = error; } @@ -532,7 +532,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { if (cancellationToken.IsCancellationRequested) { - _connection.Abort(); + _connection.AbortAsync(); _cancelled = true; return TaskUtilities.GetCancelledTask(cancellationToken); } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/IKestrelTrace.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/IKestrelTrace.cs index 2645aa8e88..ff622fa69b 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/IKestrelTrace.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/IKestrelTrace.cs @@ -43,6 +43,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure void NotAllConnectionsClosedGracefully(); + void NotAllConnectionsAborted(); + void ApplicationError(string connectionId, Exception ex); } } \ No newline at end of file diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/KestrelThread.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/KestrelThread.cs index 60536fe5d9..87e48f5205 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/KestrelThread.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/KestrelThread.cs @@ -165,6 +165,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal if (!await ConnectionManager.WalkConnectionsAndCloseAsync(_shutdownTimeout).ConfigureAwait(false)) { _log.NotAllConnectionsClosedGracefully(); + + if (!await ConnectionManager.WalkConnectionsAndAbortAsync(TimeSpan.FromSeconds(1)).ConfigureAwait(false)) + { + _log.NotAllConnectionsAborted(); + } } var result = await WaitAsync(PostAsync(state => @@ -281,7 +286,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal { lock (_startSync) { - var tcs = (TaskCompletionSource) parameter; + var tcs = (TaskCompletionSource)parameter; try { _loop.Init(_engine.Libuv); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/KestrelTrace.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/KestrelTrace.cs index 181e6380a2..9dcd15eedc 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/KestrelTrace.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/KestrelTrace.cs @@ -26,6 +26,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal private static readonly Action _connectionDisconnectedWrite; private static readonly Action _connectionHeadResponseBodyWrite; private static readonly Action _notAllConnectionsClosedGracefully; + private static readonly Action _notAllConnectionsAborted; private static readonly Action _connectionBadRequest; private static readonly Action _connectionReset; private static readonly Action _requestProcessingError; @@ -54,6 +55,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal _connectionHeadResponseBodyWrite = LoggerMessage.Define(LogLevel.Debug, 18, @"Connection id ""{ConnectionId}"" write of ""{count}"" body bytes to non-body HEAD response."); _connectionReset = LoggerMessage.Define(LogLevel.Debug, 19, @"Connection id ""{ConnectionId}"" reset."); _requestProcessingError = LoggerMessage.Define(LogLevel.Information, 20, @"Connection id ""{ConnectionId}"" request processing ended abnormally."); + _notAllConnectionsAborted = LoggerMessage.Define(LogLevel.Debug, 21, "Some connections failed to abort during server shutdown."); } public KestrelTrace(ILogger logger) @@ -149,6 +151,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal _notAllConnectionsClosedGracefully(_logger, null); } + public virtual void NotAllConnectionsAborted() + { + _notAllConnectionsAborted(_logger, null); + } + public void ConnectionBadRequest(string connectionId, BadHttpRequestException ex) { _connectionBadRequest(_logger, connectionId, ex.Message, ex); diff --git a/test/shared/MockConnection.cs b/test/shared/MockConnection.cs index e1025c624c..eff3da34fb 100644 --- a/test/shared/MockConnection.cs +++ b/test/shared/MockConnection.cs @@ -7,6 +7,7 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel; using Microsoft.AspNetCore.Server.Kestrel.Internal; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; +using Microsoft.Extensions.Internal; namespace Microsoft.AspNetCore.Testing { @@ -24,9 +25,10 @@ namespace Microsoft.AspNetCore.Testing }; } - public override void Abort(Exception error = null) + public override Task AbortAsync(Exception error = null) { RequestAbortedSource?.Cancel(); + return TaskCache.CompletedTask; } public override void OnSocketClosed() From 461caa85f4ccd3d2045413172ddd62f803ae3112 Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Wed, 21 Dec 2016 13:22:20 -0800 Subject: [PATCH 1007/1662] Test RequestHeadersTimeout in KestrelServerLimitsTests.RequestHeadersTimeoutValid (#1268). --- .../KestrelServerLimitsTests.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerLimitsTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerLimitsTests.cs index 0b9363b58f..2b95674e5b 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerLimitsTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerLimitsTests.cs @@ -94,7 +94,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } [Fact] - public void MaxRequestHeaderTotalSizeDefault() + public void MaxRequestHeadersTotalSizeDefault() { Assert.Equal(32 * 1024, (new KestrelServerLimits()).MaxRequestHeadersTotalSize); } @@ -103,7 +103,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [InlineData(int.MinValue)] [InlineData(-1)] [InlineData(0)] - public void MaxRequestHeaderTotalSizeInvalid(int value) + public void MaxRequestHeadersTotalSizeInvalid(int value) { Assert.Throws(() => { @@ -114,7 +114,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [Theory] [InlineData(1)] [InlineData(int.MaxValue)] - public void MaxRequestHeaderTotalSizeValid(int value) + public void MaxRequestHeadersTotalSizeValid(int value) { var o = new KestrelServerLimits(); o.MaxRequestHeadersTotalSize = value; @@ -184,8 +184,8 @@ namespace Microsoft.AspNetCore.Server.KestrelTests public void RequestHeadersTimeoutValid(double seconds) { var o = new KestrelServerLimits(); - o.KeepAliveTimeout = TimeSpan.FromSeconds(seconds); - Assert.Equal(seconds, o.KeepAliveTimeout.TotalSeconds); + o.RequestHeadersTimeout = TimeSpan.FromSeconds(seconds); + Assert.Equal(seconds, o.RequestHeadersTimeout.TotalSeconds); } } } From 5b8f7c2b2be5744edac8ce3c5a2dea86ed65b8ee Mon Sep 17 00:00:00 2001 From: Pranav K Date: Mon, 5 Dec 2016 09:02:57 -0800 Subject: [PATCH 1008/1662] Updating to 4.4 CoreFx packages --- global.json | 2 +- samples/LargeResponseApp/project.json | 2 +- samples/SampleApp/project.json | 2 +- .../project.json | 4 ++-- .../project.json | 14 +++++++------- .../project.json | 8 ++++---- .../global.json | 2 +- .../project.json | 4 ++-- .../project.json | 6 +++--- .../project.json | 2 +- 10 files changed, 23 insertions(+), 23 deletions(-) diff --git a/global.json b/global.json index f45e8cc925..0ad1995dd2 100644 --- a/global.json +++ b/global.json @@ -3,6 +3,6 @@ "src" ], "sdk": { - "version": "1.0.0-preview2-1-003177" + "version": "1.0.0-preview2-1-003180" } } \ No newline at end of file diff --git a/samples/LargeResponseApp/project.json b/samples/LargeResponseApp/project.json index eaf79cd206..a97b7a05bd 100644 --- a/samples/LargeResponseApp/project.json +++ b/samples/LargeResponseApp/project.json @@ -11,7 +11,7 @@ "netcoreapp1.1": { "dependencies": { "Microsoft.NETCore.App": { - "version": "1.1.0-*", + "version": "1.2.0-*", "type": "platform" } } diff --git a/samples/SampleApp/project.json b/samples/SampleApp/project.json index b9f5a5cb90..fe98b83848 100644 --- a/samples/SampleApp/project.json +++ b/samples/SampleApp/project.json @@ -13,7 +13,7 @@ "netcoreapp1.1": { "dependencies": { "Microsoft.NETCore.App": { - "version": "1.1.0-*", + "version": "1.2.0-*", "type": "platform" } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Https/project.json b/src/Microsoft.AspNetCore.Server.Kestrel.Https/project.json index 7b97256dcd..22529c3013 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Https/project.json +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Https/project.json @@ -27,13 +27,13 @@ "version": "1.2.0-*", "type": "build" }, - "NETStandard.Library": "1.6.1-*" + "NETStandard.Library": "1.6.2-*" }, "frameworks": { "net451": {}, "netstandard1.3": { "dependencies": { - "System.Net.Security": "4.3.0-*" + "System.Net.Security": "4.4.0-*" } } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/project.json b/src/Microsoft.AspNetCore.Server.Kestrel/project.json index fc3b894d2b..2e7d82d6bb 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/project.json +++ b/src/Microsoft.AspNetCore.Server.Kestrel/project.json @@ -12,17 +12,17 @@ ] }, "dependencies": { - "Libuv": "1.9.1", + "Libuv": "1.10.0-*", "Microsoft.AspNetCore.Hosting": "1.2.0-*", "Microsoft.Extensions.Logging.Abstractions": "1.2.0-*", "Microsoft.Extensions.TaskCache.Sources": { "version": "1.2.0-*", "type": "build" }, - "NETStandard.Library": "1.6.1-*", - "System.Buffers": "4.3.0-*", - "System.Numerics.Vectors": "4.3.0-*", - "System.Threading.Tasks.Extensions": "4.3.0-*" + "NETStandard.Library": "1.6.2-*", + "System.Buffers": "4.4.0-*", + "System.Numerics.Vectors": "4.4.0-*", + "System.Threading.Tasks.Extensions": "4.4.0-*" }, "frameworks": { "net451": { @@ -37,8 +37,8 @@ }, "netstandard1.3": { "dependencies": { - "System.Threading.Thread": "4.3.0-*", - "System.Threading.ThreadPool": "4.3.0-*" + "System.Threading.Thread": "4.4.0-*", + "System.Threading.ThreadPool": "4.4.0-*" } } }, diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json index cb8f653a45..139d7680af 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json @@ -19,12 +19,12 @@ "netcoreapp1.1": { "dependencies": { "Microsoft.NETCore.App": { - "version": "1.1.0-*", + "version": "1.2.0-*", "type": "platform" }, - "System.Net.Http.WinHttpHandler": "4.3.0-*", - "System.Net.NetworkInformation": "4.3.0-*", - "System.Runtime.Serialization.Primitives": "4.3.0-*" + "System.Net.Http.WinHttpHandler": "4.4.0-*", + "System.Net.NetworkInformation": "4.4.0-*", + "System.Runtime.Serialization.Primitives": "4.4.0-*" }, "imports": "dnxcore50" }, diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/global.json b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/global.json index 0ddae8e73f..19a079f795 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/global.json +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/global.json @@ -3,6 +3,6 @@ "..\\" ], "sdk": { - "version": "1.0.0-preview2-1-003177" + "version": "1.0.0-preview2-1-003180" } } \ No newline at end of file diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/project.json b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/project.json index 4871d8a63c..93c887405f 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/project.json +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/project.json @@ -1,4 +1,4 @@ -{ +{ "version": "1.0.0-*", "dependencies": { "BenchmarkDotNet": "0.10.1", @@ -9,7 +9,7 @@ "netcoreapp1.1": { "dependencies": { "Microsoft.NETCore.App": { - "version": "1.1.0-*", + "version": "1.2.0-*", "type": "platform" } } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/project.json b/test/Microsoft.AspNetCore.Server.KestrelTests/project.json index 56a54d3f76..4c53f1867d 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/project.json +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/project.json @@ -16,11 +16,11 @@ "netcoreapp1.1": { "dependencies": { "Microsoft.NETCore.App": { - "version": "1.1.0-*", + "version": "1.2.0-*", "type": "platform" }, - "System.Diagnostics.TraceSource": "4.3.0-*", - "System.Net.Http.WinHttpHandler": "4.3.0-*" + "System.Diagnostics.TraceSource": "4.4.0-*", + "System.Net.Http.WinHttpHandler": "4.4.0-*" }, "imports": "dnxcore50" }, diff --git a/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/project.json b/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/project.json index 636be2bff9..a6eab2c3ba 100644 --- a/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/project.json +++ b/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/project.json @@ -11,7 +11,7 @@ "netcoreapp1.1": { "dependencies": { "Microsoft.NETCore.App": { - "version": "1.1.0-*", + "version": "1.2.0-*", "type": "platform" } } From 4c0413c8043b084362d473365765269ec0fd302b Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Thu, 22 Dec 2016 13:40:40 +0000 Subject: [PATCH 1009/1662] Implement Stream Flush+FlushAsync fully Streams should pass through the flush and not assume the underlying Stream's Flush behaviour --- .../Filter/Internal/LibuvStream.cs | 5 ++--- .../Filter/Internal/LoggingStream.cs | 5 +++++ .../Filter/Internal/StreamSocketOutput.cs | 4 ++-- .../ConnectionFilterTests.cs | 7 ++++++- 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Filter/Internal/LibuvStream.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Filter/Internal/LibuvStream.cs index b8bc766f94..da3bb43f7e 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Filter/Internal/LibuvStream.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Filter/Internal/LibuvStream.cs @@ -117,13 +117,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Filter.Internal public override void Flush() { - // No-op since writes are immediate. + _output.Flush(); } public override Task FlushAsync(CancellationToken cancellationToken) { - // No-op since writes are immediate. - return TaskCache.CompletedTask; + return _output.FlushAsync(cancellationToken); } private ValueTask ReadAsync(ArraySegment buffer) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Filter/Internal/LoggingStream.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Filter/Internal/LoggingStream.cs index 14890c0e3a..cb052fe2a0 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Filter/Internal/LoggingStream.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Filter/Internal/LoggingStream.cs @@ -71,6 +71,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Filter.Internal _inner.Flush(); } + public override Task FlushAsync(CancellationToken cancellationToken) + { + return _inner.FlushAsync(cancellationToken); + } + public override int Read(byte[] buffer, int offset, int count) { int read = _inner.Read(buffer, offset, count); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Filter/Internal/StreamSocketOutput.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Filter/Internal/StreamSocketOutput.cs index bce699f693..8d3bf6df70 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Filter/Internal/StreamSocketOutput.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Filter/Internal/StreamSocketOutput.cs @@ -114,14 +114,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Filter.Internal end.Block.Pool.Return(end.Block); } - // Flush no-ops. We rely on connection filter streams to auto-flush. public void Flush() { + _outputStream.Flush(); } public Task FlushAsync(CancellationToken cancellationToken) { - return TaskCache.CompletedTask; + return _outputStream.FlushAsync(cancellationToken); } } } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionFilterTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionFilterTests.cs index a27e8a40bd..a121d77180 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionFilterTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionFilterTests.cs @@ -160,7 +160,12 @@ namespace Microsoft.AspNetCore.Server.KestrelTests public override void Flush() { - // No-op + _innerStream.Flush(); + } + + public override Task FlushAsync(CancellationToken cancellationToken) + { + return _innerStream.FlushAsync(cancellationToken); } public override int Read(byte[] buffer, int offset, int count) From 973b705cdbec70368b4c07428ef2cc6b80627595 Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Thu, 22 Dec 2016 18:37:14 -0800 Subject: [PATCH 1010/1662] Disable tests that hang on SslStream.WriteAsync after update to CoreFx 4.4. --- .../AddressRegistrationTests.cs | 17 ++++++++++------- .../HttpClientSlimTests.cs | 4 ++-- .../HttpsTests.cs | 4 ++-- .../LoggingConnectionFilterTests.cs | 2 +- .../MaxRequestBufferSizeTests.cs | 2 +- .../HttpsConnectionFilterTests.cs | 14 +++++++------- 6 files changed, 23 insertions(+), 20 deletions(-) diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs index be37bf0674..4cf30fc687 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs @@ -14,7 +14,6 @@ using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting.Server.Features; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http.Extensions; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; using Microsoft.AspNetCore.Testing; using Microsoft.AspNetCore.Testing.xunit; using Xunit; @@ -23,7 +22,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { public class AddressRegistrationTests { - [Theory, MemberData(nameof(AddressRegistrationDataIPv4))] + [Theory(Skip = "SslStream hanging on write after update to CoreFx 4.4 (https://github.com/dotnet/corefx/issues/14698)"), MemberData(nameof(AddressRegistrationDataIPv4))] public async Task RegisterAddresses_IPv4_Success(string addressInput, Func testUrls) { await RegisterAddresses_Success(addressInput, testUrls); @@ -36,14 +35,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests await RegisterAddresses_Success(addressInput, testUrls); } - [ConditionalTheory, MemberData(nameof(AddressRegistrationDataIPv4Port443))] + // SslStream hanging on write after update to CoreFx 4.4 (https://github.com/dotnet/corefx/issues/14698) + //[ConditionalTheory, MemberData(nameof(AddressRegistrationDataIPv4Port443))] [PortSupportedCondition(443)] public async Task RegisterAddresses_IPv4Port443_Success(string addressInput, Func testUrls) { await RegisterAddresses_Success(addressInput, testUrls); } - [ConditionalTheory, MemberData(nameof(AddressRegistrationDataIPv6))] + // SslStream hanging on write after update to CoreFx 4.4 (https://github.com/dotnet/corefx/issues/14698) + //[ConditionalTheory, MemberData(nameof(AddressRegistrationDataIPv6))] [IPv6SupportedCondition] public async Task RegisterAddresses_IPv6_Success(string addressInput, Func testUrls) { @@ -58,7 +59,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests await RegisterAddresses_Success(addressInput, testUrls); } - [ConditionalTheory, MemberData(nameof(AddressRegistrationDataIPv6Port443))] + // SslStream hanging on write after update to CoreFx 4.4 (https://github.com/dotnet/corefx/issues/14698) + //[ConditionalTheory, MemberData(nameof(AddressRegistrationDataIPv6Port443))] [IPv6SupportedCondition] [PortSupportedCondition(443)] public async Task RegisterAddresses_IPv6Port443_Success(string addressInput, Func testUrls) @@ -66,7 +68,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests await RegisterAddresses_Success(addressInput, testUrls); } - [ConditionalTheory, MemberData(nameof(AddressRegistrationDataIPv6ScopeId))] + // SslStream hanging on write after update to CoreFx 4.4 (https://github.com/dotnet/corefx/issues/14698) + //[ConditionalTheory, MemberData(nameof(AddressRegistrationDataIPv6ScopeId))] [IPv6SupportedCondition] public async Task RegisterAddresses_IPv6ScopeId_Success(string addressInput, Func testUrls) { @@ -89,7 +92,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests foreach (var testUrl in testUrls(host.ServerFeatures.Get())) { - var response = await HttpClientSlim.GetStringAsync(testUrl, validateCertificate: false); + var response = await HttpClientSlim.GetStringAsync(testUrl, validateCertificate: false).TimeoutAfter(TimeSpan.FromSeconds(2)); // Compare the response with Uri.ToString(), rather than testUrl directly. // Required to handle IPv6 addresses with zone index, like "fe80::3%1" diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/HttpClientSlimTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/HttpClientSlimTests.cs index 913f160902..0f2caf96b9 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/HttpClientSlimTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/HttpClientSlimTests.cs @@ -26,7 +26,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } } - [Fact] + [Fact(Skip = "SslStream hanging on write after update to CoreFx 4.4 (https://github.com/dotnet/corefx/issues/14698)")] public async Task GetStringAsyncHttps() { using (var host = StartHost(protocol: "https")) @@ -53,7 +53,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } } - [Fact] + [Fact(Skip = "SslStream hanging on write after update to CoreFx 4.4 (https://github.com/dotnet/corefx/issues/14698)")] public async Task PostAsyncHttps() { using (var host = StartHost(protocol: "https", diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/HttpsTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/HttpsTests.cs index f6badb31cf..cffbd96ddd 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/HttpsTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/HttpsTests.cs @@ -87,7 +87,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } // Regression test for https://github.com/aspnet/KestrelHttpServer/issues/1103#issuecomment-246971172 - [Fact] + [Fact(Skip = "SslStream hanging on write after update to CoreFx 4.4 (https://github.com/dotnet/corefx/issues/14698)")] public async Task DoesNotThrowObjectDisposedExceptionOnConnectionAbort() { var x509Certificate2 = new X509Certificate2(@"TestResources/testCert.pfx", "testPassword"); @@ -137,7 +137,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests Assert.False(loggerFactory.ErrorLogger.ObjectDisposedExceptionLogged); } - [Fact] + [Fact(Skip = "SslStream hanging on write after update to CoreFx 4.4 (https://github.com/dotnet/corefx/issues/14698)")] public async Task DoesNotThrowObjectDisposedExceptionFromWriteAsyncAfterConnectionIsAborted() { var tcs = new TaskCompletionSource(); diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/LoggingConnectionFilterTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/LoggingConnectionFilterTests.cs index 6dd7a8fb98..e1f091cb3e 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/LoggingConnectionFilterTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/LoggingConnectionFilterTests.cs @@ -13,7 +13,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { public class LoggingConnectionFilterTests { - [Fact] + [Fact(Skip = "SslStream hanging on write after update to CoreFx 4.4 (https://github.com/dotnet/corefx/issues/14698)")] public async Task LoggingConnectionFilterCanBeAddedBeforeAndAfterHttpsFilter() { var host = new WebHostBuilder() diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/MaxRequestBufferSizeTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/MaxRequestBufferSizeTests.cs index 4ffab99136..00bece92ff 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/MaxRequestBufferSizeTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/MaxRequestBufferSizeTests.cs @@ -65,7 +65,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } } - [Theory] + [Theory(Skip = "SslStream hanging on write after update to CoreFx 4.4 (https://github.com/dotnet/corefx/issues/14698)")] [MemberData("LargeUploadData")] public async Task LargeUpload(long? maxRequestBufferSize, bool ssl, bool expectPause) { diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/HttpsConnectionFilterTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/HttpsConnectionFilterTests.cs index 1b5354acb2..148260cf21 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/HttpsConnectionFilterTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/HttpsConnectionFilterTests.cs @@ -31,7 +31,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests // https://github.com/aspnet/KestrelHttpServer/issues/240 // This test currently fails on mono because of an issue with SslStream. - [Fact] + [Fact(Skip = "SslStream hanging on write after update to CoreFx 4.4 (https://github.com/dotnet/corefx/issues/14698)")] public async Task CanReadAndWriteWithHttpsConnectionFilter() { var serviceContext = new TestServiceContext(new HttpsConnectionFilter( @@ -51,7 +51,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } } - [Fact] + [Fact(Skip = "SslStream hanging on write after update to CoreFx 4.4 (https://github.com/dotnet/corefx/issues/14698)")] public async Task RequireCertificateFailsWhenNoCertificate() { var serviceContext = new TestServiceContext(new HttpsConnectionFilter( @@ -70,7 +70,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } } - [Fact] + [Fact(Skip = "SslStream hanging on write after update to CoreFx 4.4 (https://github.com/dotnet/corefx/issues/14698)")] public async Task AllowCertificateContinuesWhenNoCertificate() { var serviceContext = new TestServiceContext(new HttpsConnectionFilter( @@ -129,7 +129,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } - [Fact] + [Fact(Skip = "SslStream hanging on write after update to CoreFx 4.4 (https://github.com/dotnet/corefx/issues/14698)")] public async Task CertificatePassedToHttpContext() { var serviceContext = new TestServiceContext(new HttpsConnectionFilter( @@ -164,7 +164,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } } - [Fact] + [Fact(Skip = "SslStream hanging on write after update to CoreFx 4.4 (https://github.com/dotnet/corefx/issues/14698)")] public async Task HttpsSchemePassedToRequestFeature() { var serviceContext = new TestServiceContext( @@ -183,7 +183,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } } - [Fact] + [Fact(Skip = "SslStream hanging on write after update to CoreFx 4.4 (https://github.com/dotnet/corefx/issues/14698)")] public async Task DoesNotSupportTls10() { var serviceContext = new TestServiceContext(new HttpsConnectionFilter( @@ -295,7 +295,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } } - [Fact] + [Fact(Skip = "SslStream hanging on write after update to CoreFx 4.4 (https://github.com/dotnet/corefx/issues/14698)")] public async Task CertificatePassedToHttpContextIsNotDisposed() { var serviceContext = new TestServiceContext(new HttpsConnectionFilter( From 81a8ba034791b21f6aca676db3b3787137cb3a1f Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Fri, 23 Dec 2016 17:38:54 -0800 Subject: [PATCH 1011/1662] Skip tests commentd out in 973b705. --- .../AddressRegistrationTests.cs | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs index 4cf30fc687..e2513ece90 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs @@ -35,16 +35,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests await RegisterAddresses_Success(addressInput, testUrls); } - // SslStream hanging on write after update to CoreFx 4.4 (https://github.com/dotnet/corefx/issues/14698) - //[ConditionalTheory, MemberData(nameof(AddressRegistrationDataIPv4Port443))] + [ConditionalTheory(Skip = "SslStream hanging on write after update to CoreFx 4.4 (https://github.com/dotnet/corefx/issues/14698)"), MemberData(nameof(AddressRegistrationDataIPv4Port443))] [PortSupportedCondition(443)] public async Task RegisterAddresses_IPv4Port443_Success(string addressInput, Func testUrls) { await RegisterAddresses_Success(addressInput, testUrls); } - // SslStream hanging on write after update to CoreFx 4.4 (https://github.com/dotnet/corefx/issues/14698) - //[ConditionalTheory, MemberData(nameof(AddressRegistrationDataIPv6))] + [ConditionalTheory(Skip = "SslStream hanging on write after update to CoreFx 4.4 (https://github.com/dotnet/corefx/issues/14698)"), MemberData(nameof(AddressRegistrationDataIPv6))] [IPv6SupportedCondition] public async Task RegisterAddresses_IPv6_Success(string addressInput, Func testUrls) { @@ -59,8 +57,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests await RegisterAddresses_Success(addressInput, testUrls); } - // SslStream hanging on write after update to CoreFx 4.4 (https://github.com/dotnet/corefx/issues/14698) - //[ConditionalTheory, MemberData(nameof(AddressRegistrationDataIPv6Port443))] + [ConditionalTheory(Skip = "SslStream hanging on write after update to CoreFx 4.4 (https://github.com/dotnet/corefx/issues/14698)"), MemberData(nameof(AddressRegistrationDataIPv6Port443))] [IPv6SupportedCondition] [PortSupportedCondition(443)] public async Task RegisterAddresses_IPv6Port443_Success(string addressInput, Func testUrls) @@ -68,8 +65,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests await RegisterAddresses_Success(addressInput, testUrls); } - // SslStream hanging on write after update to CoreFx 4.4 (https://github.com/dotnet/corefx/issues/14698) - //[ConditionalTheory, MemberData(nameof(AddressRegistrationDataIPv6ScopeId))] + [ConditionalTheory(Skip = "SslStream hanging on write after update to CoreFx 4.4 (https://github.com/dotnet/corefx/issues/14698)"), MemberData(nameof(AddressRegistrationDataIPv6ScopeId))] [IPv6SupportedCondition] public async Task RegisterAddresses_IPv6ScopeId_Success(string addressInput, Func testUrls) { @@ -92,7 +88,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests foreach (var testUrl in testUrls(host.ServerFeatures.Get())) { - var response = await HttpClientSlim.GetStringAsync(testUrl, validateCertificate: false).TimeoutAfter(TimeSpan.FromSeconds(2)); + var response = await HttpClientSlim.GetStringAsync(testUrl, validateCertificate: false); // Compare the response with Uri.ToString(), rather than testUrl directly. // Required to handle IPv6 addresses with zone index, like "fe80::3%1" From c72605f43a51b4290864df1da6903e25ec1e0c61 Mon Sep 17 00:00:00 2001 From: Pranav K Date: Thu, 22 Dec 2016 17:02:35 -0800 Subject: [PATCH 1012/1662] Fix NuGet downgrade warning Works around warning where a P2P reference is explicitly listed in the project. For e.g. warn : SampleApp (>= 1.1.0) -> Microsoft.AspNetCore.Server.Kestrel.Https (>= 1.2.0) -> Microsoft.AspNetCore.Server.Kestrel warn : SampleApp (>= 1.1.0) -> Microsoft.AspNetCore.Server.Kestrel (>= 1.2.0) --- samples/SampleApp/project.json | 1 - .../project.json | 1 - test/Microsoft.AspNetCore.Server.KestrelTests/project.json | 1 - 3 files changed, 3 deletions(-) diff --git a/samples/SampleApp/project.json b/samples/SampleApp/project.json index fe98b83848..557ab3faa6 100644 --- a/samples/SampleApp/project.json +++ b/samples/SampleApp/project.json @@ -1,7 +1,6 @@ { "version": "1.1.0-*", "dependencies": { - "Microsoft.AspNetCore.Server.Kestrel": "1.2.0-*", "Microsoft.AspNetCore.Server.Kestrel.Https": "1.2.0-*", "Microsoft.Extensions.Logging.Console": "1.2.0-*" }, diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json index 139d7680af..f690fe4a65 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json @@ -3,7 +3,6 @@ "dependencies": { "dotnet-test-xunit": "2.2.0-*", "Microsoft.AspNetCore.Http.Abstractions": "1.2.0-*", - "Microsoft.AspNetCore.Server.Kestrel": "1.2.0-*", "Microsoft.AspNetCore.Server.Kestrel.Https": "1.2.0-*", "Microsoft.AspNetCore.Testing": "1.2.0-*", "Microsoft.Extensions.Logging.Testing": "1.2.0-*", diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/project.json b/test/Microsoft.AspNetCore.Server.KestrelTests/project.json index 4c53f1867d..1d358e6fe8 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/project.json +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/project.json @@ -2,7 +2,6 @@ "version": "1.1.0-*", "dependencies": { "dotnet-test-xunit": "2.2.0-*", - "Microsoft.AspNetCore.Server.Kestrel": "1.2.0-*", "Microsoft.AspNetCore.Server.Kestrel.Https": "1.2.0-*", "Microsoft.AspNetCore.Testing": "1.2.0-*", "Moq": "4.6.36-*", From 2351c1b558fc6f4312af262aa866fd2c5164761f Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Wed, 4 Jan 2017 10:21:21 -0800 Subject: [PATCH 1013/1662] Create a direct way to configure Kestrel endpoints - Replace endpoint configuration via .UseUrls() or --server.urls with Listen* methods on KestrelSerrverOptions. - Replace IConnectionFilter with IConnectionAdapter which no longer exposes ServerAddress via a context. - Simplify libuv Listener classes - Support systemd socket activation - Add docker-based test for systemd socket activation to be run on Travis --- .travis.yml | 3 + samples/LargeResponseApp/Startup.cs | 7 +- samples/SampleApp/Startup.cs | 40 ++- .../HttpsConnectionAdapter.cs | 160 ++++++++++ ...ns.cs => HttpsConnectionAdapterOptions.cs} | 4 +- .../HttpsConnectionFilter.cs | 156 ---------- .../KestrelServerOptionsHttpsExtensions.cs | 92 ------ .../ListenOptionsHttpsExtensions.cs | 94 ++++++ .../exceptions.net45.json | 14 + .../exceptions.netcore.json | 14 + .../Adapter/ConnectionAdapterContext.cs | 19 ++ .../Adapter/IAdaptedConnection.cs | 15 + .../Adapter/IConnectionAdapter.cs | 13 + .../Internal/AdaptedPipeline.cs} | 6 +- .../Internal/LoggingStream.cs | 2 +- .../Internal/RawStream.cs} | 6 +- .../Internal/StreamSocketOutput.cs | 2 +- ...istenOptionsConnectionLoggingExtensions.cs | 38 +++ .../Adapter/LoggingConnectionAdapter.cs | 47 +++ .../Filter/ConnectionFilterContext.cs | 16 - .../Filter/IConnectionFilter.cs | 12 - ...erverOptionsConnectionLoggingExtensions.cs | 39 --- .../Filter/LoggingConnectionFilter.cs | 38 --- .../Filter/NoOpConnectionFilter.cs | 16 - .../Internal/Http/Connection.cs | 113 ++++--- .../Internal/Http/ConnectionContext.cs | 2 - .../Internal/Http/Frame.cs | 31 +- .../Internal/Http/Listener.cs | 83 +++++- .../Internal/Http/ListenerContext.cs | 27 +- .../Internal/Http/ListenerPrimary.cs | 8 +- .../Internal/Http/ListenerSecondary.cs | 13 +- .../Internal/Http/PipeListener.cs | 61 ---- .../Internal/Http/PipeListenerPrimary.cs | 62 ---- .../Internal/Http/PipeListenerSecondary.cs | 27 -- .../Internal/Http/TcpListener.cs | 68 ----- .../Internal/Http/TcpListenerPrimary.cs | 68 ----- .../Internal/Http/TcpListenerSecondary.cs | 28 -- .../Internal/Infrastructure/Constants.cs | 10 + .../Internal/KestrelEngine.cs | 55 ++-- .../Internal/Networking/SockAddr.cs | 5 +- .../Internal/Networking/UvTcpHandle.cs | 43 +-- .../KestrelServer.cs | 210 +++++++++---- .../KestrelServerOptions.cs | 141 +++++++-- .../ListenOptions.cs | 108 +++++++ .../ListenType.cs | 15 + .../ServerAddress.cs | 2 +- .../KesterlServerOptionsSystemdExtensions.cs | 45 +++ .../exceptions.net45.json | 46 +++ .../exceptions.netcore.json | 46 +++ .../project.json | 1 + .../AddressRegistrationTests.cs | 214 ++++++++----- .../HttpClientSlimTests.cs | 14 +- .../HttpsTests.cs | 35 ++- .../IWebHostPortExtensions.cs | 26 +- ...ts.cs => LoggingConnectionAdapterTests.cs} | 17 +- .../MaxRequestBufferSizeTests.cs | 18 +- .../ResponseTests.cs | 2 +- .../SystemdActivation/Dockerfile | 28 ++ .../activate-kestrel.service | 8 + .../SystemdActivation/activate-kestrel.socket | 7 + .../SystemdActivation/docker.sh | 21 ++ .../Writing.cs | 3 +- .../ChunkedRequestTests.cs | 92 +++--- .../ChunkedResponseTests.cs | 107 ++++--- ...lterTests.cs => ConnectionAdapterTests.cs} | 88 ++++-- .../ConnectionTests.cs | 3 +- .../CreateIPEndpointTests.cs | 4 +- .../EngineTests.cs | 281 +++++++++++------- .../FrameResponseHeadersTests.cs | 3 +- .../FrameTests.cs | 5 +- ...ests.cs => HttpsConnectionAdapterTests.cs} | 242 ++++++++------- .../KestrelServerOptionsTests.cs | 17 +- .../ListenerPrimaryTests.cs | 69 +++-- .../MultipleLoopTests.cs | 5 +- .../NetworkingTests.cs | 16 +- .../RequestTargetProcessingTests.cs | 9 +- .../StreamSocketOutputTests.cs | 2 +- .../PassThroughConnectionAdapter.cs | 35 +++ .../PassThroughConnectionFilter.cs | 21 -- .../TestInput.cs | 4 +- test/shared/MockConnection.cs | 3 +- test/shared/TestServer.cs | 22 +- test/shared/TestServiceContext.cs | 8 +- 83 files changed, 2088 insertions(+), 1512 deletions(-) create mode 100644 src/Microsoft.AspNetCore.Server.Kestrel.Https/HttpsConnectionAdapter.cs rename src/Microsoft.AspNetCore.Server.Kestrel.Https/{HttpsConnectionFilterOptions.cs => HttpsConnectionAdapterOptions.cs} (90%) delete mode 100644 src/Microsoft.AspNetCore.Server.Kestrel.Https/HttpsConnectionFilter.cs delete mode 100644 src/Microsoft.AspNetCore.Server.Kestrel.Https/KestrelServerOptionsHttpsExtensions.cs create mode 100644 src/Microsoft.AspNetCore.Server.Kestrel.Https/ListenOptionsHttpsExtensions.cs create mode 100644 src/Microsoft.AspNetCore.Server.Kestrel.Https/exceptions.net45.json create mode 100644 src/Microsoft.AspNetCore.Server.Kestrel.Https/exceptions.netcore.json create mode 100644 src/Microsoft.AspNetCore.Server.Kestrel/Adapter/ConnectionAdapterContext.cs create mode 100644 src/Microsoft.AspNetCore.Server.Kestrel/Adapter/IAdaptedConnection.cs create mode 100644 src/Microsoft.AspNetCore.Server.Kestrel/Adapter/IConnectionAdapter.cs rename src/Microsoft.AspNetCore.Server.Kestrel/{Filter/Internal/FilteredStreamAdapter.cs => Adapter/Internal/AdaptedPipeline.cs} (91%) rename src/Microsoft.AspNetCore.Server.Kestrel/{Filter => Adapter}/Internal/LoggingStream.cs (98%) rename src/Microsoft.AspNetCore.Server.Kestrel/{Filter/Internal/LibuvStream.cs => Adapter/Internal/RawStream.cs} (97%) rename src/Microsoft.AspNetCore.Server.Kestrel/{Filter => Adapter}/Internal/StreamSocketOutput.cs (98%) create mode 100644 src/Microsoft.AspNetCore.Server.Kestrel/Adapter/ListenOptionsConnectionLoggingExtensions.cs create mode 100644 src/Microsoft.AspNetCore.Server.Kestrel/Adapter/LoggingConnectionAdapter.cs delete mode 100644 src/Microsoft.AspNetCore.Server.Kestrel/Filter/ConnectionFilterContext.cs delete mode 100644 src/Microsoft.AspNetCore.Server.Kestrel/Filter/IConnectionFilter.cs delete mode 100644 src/Microsoft.AspNetCore.Server.Kestrel/Filter/KestrelServerOptionsConnectionLoggingExtensions.cs delete mode 100644 src/Microsoft.AspNetCore.Server.Kestrel/Filter/LoggingConnectionFilter.cs delete mode 100644 src/Microsoft.AspNetCore.Server.Kestrel/Filter/NoOpConnectionFilter.cs delete mode 100644 src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/PipeListener.cs delete mode 100644 src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/PipeListenerPrimary.cs delete mode 100644 src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/PipeListenerSecondary.cs delete mode 100644 src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/TcpListener.cs delete mode 100644 src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/TcpListenerPrimary.cs delete mode 100644 src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/TcpListenerSecondary.cs create mode 100644 src/Microsoft.AspNetCore.Server.Kestrel/ListenOptions.cs create mode 100644 src/Microsoft.AspNetCore.Server.Kestrel/ListenType.cs create mode 100644 src/Microsoft.AspNetCore.Server.Kestrel/Systemd/KesterlServerOptionsSystemdExtensions.cs create mode 100644 src/Microsoft.AspNetCore.Server.Kestrel/exceptions.net45.json create mode 100644 src/Microsoft.AspNetCore.Server.Kestrel/exceptions.netcore.json rename test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/{LoggingConnectionFilterTests.cs => LoggingConnectionAdapterTests.cs} (76%) create mode 100644 test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/SystemdActivation/Dockerfile create mode 100644 test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/SystemdActivation/activate-kestrel.service create mode 100644 test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/SystemdActivation/activate-kestrel.socket create mode 100755 test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/SystemdActivation/docker.sh rename test/Microsoft.AspNetCore.Server.KestrelTests/{ConnectionFilterTests.cs => ConnectionAdapterTests.cs} (69%) rename test/Microsoft.AspNetCore.Server.KestrelTests/{HttpsConnectionFilterTests.cs => HttpsConnectionAdapterTests.cs} (65%) create mode 100644 test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/PassThroughConnectionAdapter.cs delete mode 100644 test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/PassThroughConnectionFilter.cs diff --git a/.travis.yml b/.travis.yml index a0be886892..03c4d59416 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,8 @@ language: csharp sudo: required dist: trusty +services: + - docker addons: apt: packages: @@ -30,3 +32,4 @@ before_install: - if test "$TRAVIS_OS_NAME" == "osx"; then brew update; brew install openssl; ln -s /usr/local/opt/openssl/lib/libcrypto.1.0.0.dylib /usr/local/lib/; ln -s /usr/local/opt/openssl/lib/libssl.1.0.0.dylib /usr/local/lib/; fi script: - ./build.sh --quiet verify + - if test "$TRAVIS_OS_NAME" != "osx"; then bash test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/SystemdActivation/docker.sh; fi diff --git a/samples/LargeResponseApp/Startup.cs b/samples/LargeResponseApp/Startup.cs index bc02662832..47ecd8a08b 100644 --- a/samples/LargeResponseApp/Startup.cs +++ b/samples/LargeResponseApp/Startup.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.IO; +using System.Net; using System.Text; using System.Threading.Tasks; using Microsoft.AspNetCore.Builder; @@ -40,8 +41,10 @@ namespace LargeResponseApp public static void Main(string[] args) { var host = new WebHostBuilder() - .UseKestrel() - .UseUrls("http://localhost:5001/") + .UseKestrel(options => + { + options.Listen(IPAddress.Loopback, 5001); + }) .UseContentRoot(Directory.GetCurrentDirectory()) .UseStartup() .Build(); diff --git a/samples/SampleApp/Startup.cs b/samples/SampleApp/Startup.cs index 84bb918a99..1ba9d55393 100644 --- a/samples/SampleApp/Startup.cs +++ b/samples/SampleApp/Startup.cs @@ -3,6 +3,7 @@ using System; using System.IO; +using System.Net; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; @@ -33,24 +34,33 @@ namespace SampleApp public static void Main(string[] args) { - var host = new WebHostBuilder() - .UseKestrel(options => + var hostBuilder = new WebHostBuilder().UseKestrel(options => + { + options.Listen(IPAddress.Loopback, 5000, listenOptions => { - // options.ThreadCount = 4; - options.NoDelay = true; - options.UseHttps("testCert.pfx", "testPassword"); - options.UseConnectionLogging(); - }) - .UseUrls("http://localhost:5000", "https://localhost:5001") - .UseContentRoot(Directory.GetCurrentDirectory()) - .UseStartup() - .Build(); + // Uncomment the following to enable Nagle's algorithm for this endpoint. + //listenOptions.NoDelay = false; - // The following section should be used to demo sockets - //var addresses = application.GetAddresses(); - //addresses.Clear(); - //addresses.Add("http://unix:/tmp/kestrel-test.sock"); + listenOptions.UseConnectionLogging(); + }); + options.Listen(IPAddress.Loopback, 5001, listenOptions => + { + listenOptions.UseHttps("testCert.pfx", "testPassword"); + listenOptions.UseConnectionLogging(); + }); + options.UseSystemd(); + + // The following section should be used to demo sockets + //options.ListenUnixSocket("/tmp/kestrel-test.sock"); + + // Uncomment the following line to change the default number of libuv threads for all endpoints. + //options.ThreadCount = 4; + }) + .UseContentRoot(Directory.GetCurrentDirectory()) + .UseStartup(); + + var host = hostBuilder.Build(); host.Run(); } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Https/HttpsConnectionAdapter.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Https/HttpsConnectionAdapter.cs new file mode 100644 index 0000000000..d56d440512 --- /dev/null +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Https/HttpsConnectionAdapter.cs @@ -0,0 +1,160 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.IO; +using System.Net.Security; +using System.Security.Cryptography.X509Certificates; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Http.Features; +using Microsoft.AspNetCore.Server.Kestrel.Adapter; +using Microsoft.AspNetCore.Server.Kestrel.Https.Internal; +using Microsoft.Extensions.Logging; + +namespace Microsoft.AspNetCore.Server.Kestrel.Https +{ + public class HttpsConnectionAdapter : IConnectionAdapter + { + private static readonly ClosedAdaptedConnection _closedAdaptedConnection = new ClosedAdaptedConnection(); + + private readonly HttpsConnectionAdapterOptions _options; + private readonly ILogger _logger; + + public HttpsConnectionAdapter(HttpsConnectionAdapterOptions options) + : this(options, loggerFactory: null) + { + } + + public HttpsConnectionAdapter(HttpsConnectionAdapterOptions options, ILoggerFactory loggerFactory) + { + if (options == null) + { + throw new ArgumentNullException(nameof(options)); + } + if (options.ServerCertificate == null) + { + throw new ArgumentException("The server certificate parameter is required."); + } + + _options = options; + _logger = loggerFactory?.CreateLogger(nameof(HttpsConnectionAdapter)); + } + + public async Task OnConnectionAsync(ConnectionAdapterContext context) + { + SslStream sslStream; + bool certificateRequired; + + if (_options.ClientCertificateMode == ClientCertificateMode.NoCertificate) + { + sslStream = new SslStream(context.ConnectionStream); + certificateRequired = false; + } + else + { + sslStream = new SslStream(context.ConnectionStream, leaveInnerStreamOpen: false, + userCertificateValidationCallback: (sender, certificate, chain, sslPolicyErrors) => + { + if (certificate == null) + { + return _options.ClientCertificateMode != ClientCertificateMode.RequireCertificate; + } + + if (_options.ClientCertificateValidation == null) + { + if (sslPolicyErrors != SslPolicyErrors.None) + { + return false; + } + } + + var certificate2 = ConvertToX509Certificate2(certificate); + if (certificate2 == null) + { + return false; + } + + if (_options.ClientCertificateValidation != null) + { + if (!_options.ClientCertificateValidation(certificate2, chain, sslPolicyErrors)) + { + return false; + } + } + + return true; + }); + + certificateRequired = true; + } + + try + { + await sslStream.AuthenticateAsServerAsync(_options.ServerCertificate, certificateRequired, + _options.SslProtocols, _options.CheckCertificateRevocation); + } + catch (IOException ex) + { + _logger?.LogInformation(1, ex, "Failed to authenticate HTTPS connection."); + sslStream.Dispose(); + return _closedAdaptedConnection; + } + + return new HttpsAdaptedConnection(sslStream); + } + + private static X509Certificate2 ConvertToX509Certificate2(X509Certificate certificate) + { + if (certificate == null) + { + return null; + } + + X509Certificate2 certificate2 = certificate as X509Certificate2; + if (certificate2 != null) + { + return certificate2; + } + +#if NETSTANDARD1_3 + // conversion X509Certificate to X509Certificate2 not supported + // https://github.com/dotnet/corefx/issues/4510 + return null; +#else + return new X509Certificate2(certificate); +#endif + } + + private class HttpsAdaptedConnection : IAdaptedConnection + { + private readonly SslStream _sslStream; + + public HttpsAdaptedConnection(SslStream sslStream) + { + _sslStream = sslStream; + } + + public Stream ConnectionStream => _sslStream; + + public void PrepareRequest(IFeatureCollection requestFeatures) + { + var clientCertificate = ConvertToX509Certificate2(_sslStream.RemoteCertificate); + if (clientCertificate != null) + { + requestFeatures.Set(new TlsConnectionFeature { ClientCertificate = clientCertificate }); + } + + requestFeatures.Get().Scheme = "https"; + } + } + + private class ClosedAdaptedConnection : IAdaptedConnection + { + public Stream ConnectionStream { get; } = new ClosedStream(); + + public void PrepareRequest(IFeatureCollection requestFeatures) + { + } + } + } +} diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Https/HttpsConnectionFilterOptions.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Https/HttpsConnectionAdapterOptions.cs similarity index 90% rename from src/Microsoft.AspNetCore.Server.Kestrel.Https/HttpsConnectionFilterOptions.cs rename to src/Microsoft.AspNetCore.Server.Kestrel.Https/HttpsConnectionAdapterOptions.cs index 93eab7158d..728c842c65 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Https/HttpsConnectionFilterOptions.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Https/HttpsConnectionAdapterOptions.cs @@ -8,9 +8,9 @@ using System.Security.Cryptography.X509Certificates; namespace Microsoft.AspNetCore.Server.Kestrel.Https { - public class HttpsConnectionFilterOptions + public class HttpsConnectionAdapterOptions { - public HttpsConnectionFilterOptions() + public HttpsConnectionAdapterOptions() { ClientCertificateMode = ClientCertificateMode.NoCertificate; SslProtocols = SslProtocols.Tls12 | SslProtocols.Tls11; diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Https/HttpsConnectionFilter.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Https/HttpsConnectionFilter.cs deleted file mode 100644 index 30a34cfb91..0000000000 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Https/HttpsConnectionFilter.cs +++ /dev/null @@ -1,156 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using System.IO; -using System.Net.Security; -using System.Security.Cryptography.X509Certificates; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Http.Features; -using Microsoft.AspNetCore.Server.Kestrel.Filter; -using Microsoft.AspNetCore.Server.Kestrel.Https.Internal; -using Microsoft.Extensions.Logging; - -namespace Microsoft.AspNetCore.Server.Kestrel.Https -{ - public class HttpsConnectionFilter : IConnectionFilter - { - private static readonly ClosedStream _closedStream = new ClosedStream(); - - private readonly HttpsConnectionFilterOptions _options; - private readonly IConnectionFilter _previous; - private readonly ILogger _logger; - - public HttpsConnectionFilter(HttpsConnectionFilterOptions options, IConnectionFilter previous) - : this(options, previous, loggerFactory: null) - { - } - - public HttpsConnectionFilter(HttpsConnectionFilterOptions options, IConnectionFilter previous, ILoggerFactory loggerFactory) - { - if (options == null) - { - throw new ArgumentNullException(nameof(options)); - } - if (previous == null) - { - throw new ArgumentNullException(nameof(previous)); - } - if (options.ServerCertificate == null) - { - throw new ArgumentException("The server certificate parameter is required."); - } - - _options = options; - _previous = previous; - _logger = loggerFactory?.CreateLogger(nameof(HttpsConnectionFilter)); - } - - public async Task OnConnectionAsync(ConnectionFilterContext context) - { - await _previous.OnConnectionAsync(context); - - if (string.Equals(context.Address.Scheme, "https", StringComparison.OrdinalIgnoreCase)) - { - SslStream sslStream; - bool certificateRequired; - - if (_options.ClientCertificateMode == ClientCertificateMode.NoCertificate) - { - sslStream = new SslStream(context.Connection); - certificateRequired = false; - } - else - { - sslStream = new SslStream(context.Connection, leaveInnerStreamOpen: false, - userCertificateValidationCallback: (sender, certificate, chain, sslPolicyErrors) => - { - if (certificate == null) - { - return _options.ClientCertificateMode != ClientCertificateMode.RequireCertificate; - } - - if (_options.ClientCertificateValidation == null) - { - if (sslPolicyErrors != SslPolicyErrors.None) - { - return false; - } - } - - var certificate2 = ConvertToX509Certificate2(certificate); - if (certificate2 == null) - { - return false; - } - - if (_options.ClientCertificateValidation != null) - { - if (!_options.ClientCertificateValidation(certificate2, chain, sslPolicyErrors)) - { - return false; - } - } - - return true; - }); - - certificateRequired = true; - } - - try - { - await sslStream.AuthenticateAsServerAsync(_options.ServerCertificate, certificateRequired, - _options.SslProtocols, _options.CheckCertificateRevocation); - } - catch (IOException ex) - { - _logger?.LogInformation(1, ex, "Failed to authenticate HTTPS connection."); - - sslStream.Dispose(); - context.Connection = _closedStream; - - return; - } - - var previousPrepareRequest = context.PrepareRequest; - context.PrepareRequest = features => - { - previousPrepareRequest?.Invoke(features); - - var clientCertificate = ConvertToX509Certificate2(sslStream.RemoteCertificate); - if (clientCertificate != null) - { - features.Set(new TlsConnectionFeature { ClientCertificate = clientCertificate }); - } - - features.Get().Scheme = "https"; - }; - - context.Connection = sslStream; - } - } - - private X509Certificate2 ConvertToX509Certificate2(X509Certificate certificate) - { - if (certificate == null) - { - return null; - } - - X509Certificate2 certificate2 = certificate as X509Certificate2; - if (certificate2 != null) - { - return certificate2; - } - -#if NETSTANDARD1_3 - // conversion X509Certificate to X509Certificate2 not supported - // https://github.com/dotnet/corefx/issues/4510 - return null; -#else - return new X509Certificate2(certificate); -#endif - } - } -} diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Https/KestrelServerOptionsHttpsExtensions.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Https/KestrelServerOptionsHttpsExtensions.cs deleted file mode 100644 index d4036985f5..0000000000 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Https/KestrelServerOptionsHttpsExtensions.cs +++ /dev/null @@ -1,92 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System.IO; -using System.Security.Cryptography.X509Certificates; -using Microsoft.AspNetCore.Server.Kestrel; -using Microsoft.AspNetCore.Server.Kestrel.Filter; -using Microsoft.AspNetCore.Server.Kestrel.Https; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Logging; - -namespace Microsoft.AspNetCore.Hosting -{ - public static class KestrelServerOptionsHttpsExtensions - { - /// - /// Configure Kestrel to use HTTPS. - /// - /// - /// The Microsoft.AspNetCore.Server.KestrelServerOptions to configure. - /// - /// - /// The name of a certificate file, relative to the directory that contains the application content files. - /// - /// - /// The Microsoft.AspNetCore.Server.KestrelServerOptions. - /// - public static KestrelServerOptions UseHttps(this KestrelServerOptions options, string fileName) - { - var env = options.ApplicationServices.GetRequiredService(); - return options.UseHttps(new X509Certificate2(Path.Combine(env.ContentRootPath, fileName))); - } - - /// - /// Configure Kestrel to use HTTPS. - /// - /// - /// The Microsoft.AspNetCore.Server.KestrelServerOptions to configure. - /// - /// - /// The name of a certificate file, relative to the directory that contains the application content files. - /// - /// - /// The password required to access the X.509 certificate data. - /// - /// - /// The Microsoft.AspNetCore.Server.KestrelServerOptions. - /// - public static KestrelServerOptions UseHttps(this KestrelServerOptions options, string fileName, string password) - { - var env = options.ApplicationServices.GetRequiredService(); - return options.UseHttps(new X509Certificate2(Path.Combine(env.ContentRootPath, fileName), password)); - } - - /// - /// Configure Kestrel to use HTTPS. - /// - /// - /// The Microsoft.AspNetCore.Server.KestrelServerOptions to configure. - /// - /// - /// The X.509 certificate. - /// - /// - /// The Microsoft.AspNetCore.Server.KestrelServerOptions. - /// - public static KestrelServerOptions UseHttps(this KestrelServerOptions options, X509Certificate2 serverCertificate) - { - return options.UseHttps(new HttpsConnectionFilterOptions { ServerCertificate = serverCertificate }); - } - - /// - /// Configure Kestrel to use HTTPS. - /// - /// - /// The Microsoft.AspNetCore.Server.KestrelServerOptions to configure. - /// - /// - /// Options to configure HTTPS. - /// - /// - /// The Microsoft.AspNetCore.Server.KestrelServerOptions. - /// - public static KestrelServerOptions UseHttps(this KestrelServerOptions options, HttpsConnectionFilterOptions httpsOptions) - { - var prevFilter = options.ConnectionFilter ?? new NoOpConnectionFilter(); - var loggerFactory = options.ApplicationServices.GetRequiredService(); - options.ConnectionFilter = new HttpsConnectionFilter(httpsOptions, prevFilter, loggerFactory); - return options; - } - } -} diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Https/ListenOptionsHttpsExtensions.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Https/ListenOptionsHttpsExtensions.cs new file mode 100644 index 0000000000..148da6deb1 --- /dev/null +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Https/ListenOptionsHttpsExtensions.cs @@ -0,0 +1,94 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.IO; +using System.Security.Cryptography.X509Certificates; +using Microsoft.AspNetCore.Server.Kestrel; +using Microsoft.AspNetCore.Server.Kestrel.Https; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; + +namespace Microsoft.AspNetCore.Hosting +{ + /// + /// Extension methods fro that configure Kestrel to use HTTPS for a given endpoint. + /// + public static class ListenOptionsHttpsExtensions + { + /// + /// Configure Kestrel to use HTTPS. + /// + /// + /// The to configure. + /// + /// + /// The name of a certificate file, relative to the directory that contains the application content files. + /// + /// + /// The . + /// + public static ListenOptions UseHttps(this ListenOptions listenOptions, string fileName) + { + var env = listenOptions.KestrelServerOptions.ApplicationServices.GetRequiredService(); + return listenOptions.UseHttps(new X509Certificate2(Path.Combine(env.ContentRootPath, fileName))); + } + + /// + /// Configure Kestrel to use HTTPS. + /// + /// + /// The to configure. + /// + /// + /// The name of a certificate file, relative to the directory that contains the application content files. + /// + /// + /// The password required to access the X.509 certificate data. + /// + /// + /// The . + /// + public static ListenOptions UseHttps(this ListenOptions listenOptions, string fileName, string password) + { + var env = listenOptions.KestrelServerOptions.ApplicationServices.GetRequiredService(); + return listenOptions.UseHttps(new X509Certificate2(Path.Combine(env.ContentRootPath, fileName), password)); + } + + /// + /// Configure Kestrel to use HTTPS. + /// + /// + /// The to configure. + /// + /// + /// The X.509 certificate. + /// + /// + /// The . + /// + public static ListenOptions UseHttps(this ListenOptions listenOptions, X509Certificate2 serverCertificate) + { + return listenOptions.UseHttps(new HttpsConnectionAdapterOptions { ServerCertificate = serverCertificate }); + } + + /// + /// Configure Kestrel to use HTTPS. + /// + /// + /// The to configure. + /// + /// + /// Options to configure HTTPS. + /// + /// + /// The . + /// + public static ListenOptions UseHttps(this ListenOptions listenOptions, HttpsConnectionAdapterOptions httpsOptions) + { + var loggerFactory = listenOptions.KestrelServerOptions.ApplicationServices.GetRequiredService(); + listenOptions.ConnectionAdapters.Add(new HttpsConnectionAdapter(httpsOptions, loggerFactory)); + return listenOptions; + } + } +} diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Https/exceptions.net45.json b/src/Microsoft.AspNetCore.Server.Kestrel.Https/exceptions.net45.json new file mode 100644 index 0000000000..c063085fff --- /dev/null +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Https/exceptions.net45.json @@ -0,0 +1,14 @@ +[ + { + "OldTypeId": "public static class Microsoft.AspNetCore.Hosting.KestrelServerOptionsHttpsExtensions", + "Kind": "Removal" + }, + { + "OldTypeId": "public class Microsoft.AspNetCore.Server.Kestrel.Https.HttpsConnectionFilter : Microsoft.AspNetCore.Server.Kestrel.Filter.IConnectionFilter", + "Kind": "Removal" + }, + { + "OldTypeId": "public class Microsoft.AspNetCore.Server.Kestrel.Https.HttpsConnectionFilterOptions", + "Kind": "Removal" + } +] \ No newline at end of file diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Https/exceptions.netcore.json b/src/Microsoft.AspNetCore.Server.Kestrel.Https/exceptions.netcore.json new file mode 100644 index 0000000000..c063085fff --- /dev/null +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Https/exceptions.netcore.json @@ -0,0 +1,14 @@ +[ + { + "OldTypeId": "public static class Microsoft.AspNetCore.Hosting.KestrelServerOptionsHttpsExtensions", + "Kind": "Removal" + }, + { + "OldTypeId": "public class Microsoft.AspNetCore.Server.Kestrel.Https.HttpsConnectionFilter : Microsoft.AspNetCore.Server.Kestrel.Filter.IConnectionFilter", + "Kind": "Removal" + }, + { + "OldTypeId": "public class Microsoft.AspNetCore.Server.Kestrel.Https.HttpsConnectionFilterOptions", + "Kind": "Removal" + } +] \ No newline at end of file diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Adapter/ConnectionAdapterContext.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Adapter/ConnectionAdapterContext.cs new file mode 100644 index 0000000000..15a87c9075 --- /dev/null +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Adapter/ConnectionAdapterContext.cs @@ -0,0 +1,19 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System.IO; + +namespace Microsoft.AspNetCore.Server.Kestrel.Adapter +{ + // Even though this only includes the non-adapted ConnectionStream currently, this is a context in case + // we want to add more connection metadata later. + public class ConnectionAdapterContext + { + internal ConnectionAdapterContext(Stream connectionStream) + { + ConnectionStream = connectionStream; + } + + public Stream ConnectionStream { get; } + } +} diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Adapter/IAdaptedConnection.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Adapter/IAdaptedConnection.cs new file mode 100644 index 0000000000..aa8c2e820e --- /dev/null +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Adapter/IAdaptedConnection.cs @@ -0,0 +1,15 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System.IO; +using Microsoft.AspNetCore.Http.Features; + +namespace Microsoft.AspNetCore.Server.Kestrel.Adapter +{ + public interface IAdaptedConnection + { + Stream ConnectionStream { get; } + + void PrepareRequest(IFeatureCollection requestFeatures); + } +} diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Adapter/IConnectionAdapter.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Adapter/IConnectionAdapter.cs new file mode 100644 index 0000000000..cbdb12b3b3 --- /dev/null +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Adapter/IConnectionAdapter.cs @@ -0,0 +1,13 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System.IO; +using System.Threading.Tasks; + +namespace Microsoft.AspNetCore.Server.Kestrel.Adapter +{ + public interface IConnectionAdapter + { + Task OnConnectionAsync(ConnectionAdapterContext context); + } +} diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Filter/Internal/FilteredStreamAdapter.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Adapter/Internal/AdaptedPipeline.cs similarity index 91% rename from src/Microsoft.AspNetCore.Server.Kestrel/Filter/Internal/FilteredStreamAdapter.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Adapter/Internal/AdaptedPipeline.cs index 4f4a0f9405..28c8fd66e1 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Filter/Internal/FilteredStreamAdapter.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Adapter/Internal/AdaptedPipeline.cs @@ -7,13 +7,13 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; -namespace Microsoft.AspNetCore.Server.Kestrel.Filter.Internal +namespace Microsoft.AspNetCore.Server.Kestrel.Adapter.Internal { - public class FilteredStreamAdapter : IDisposable + public class AdaptedPipeline : IDisposable { private readonly Stream _filteredStream; - public FilteredStreamAdapter( + public AdaptedPipeline( string connectionId, Stream filteredStream, MemoryPool memory, diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Filter/Internal/LoggingStream.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Adapter/Internal/LoggingStream.cs similarity index 98% rename from src/Microsoft.AspNetCore.Server.Kestrel/Filter/Internal/LoggingStream.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Adapter/Internal/LoggingStream.cs index 14890c0e3a..184839163c 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Filter/Internal/LoggingStream.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Adapter/Internal/LoggingStream.cs @@ -8,7 +8,7 @@ using System.Threading; using System.Threading.Tasks; using Microsoft.Extensions.Logging; -namespace Microsoft.AspNetCore.Server.Kestrel.Filter.Internal +namespace Microsoft.AspNetCore.Server.Kestrel.Adapter.Internal { internal class LoggingStream : Stream { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Filter/Internal/LibuvStream.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Adapter/Internal/RawStream.cs similarity index 97% rename from src/Microsoft.AspNetCore.Server.Kestrel/Filter/Internal/LibuvStream.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Adapter/Internal/RawStream.cs index b8bc766f94..2c7fb8accf 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Filter/Internal/LibuvStream.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Adapter/Internal/RawStream.cs @@ -8,16 +8,16 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; using Microsoft.Extensions.Internal; -namespace Microsoft.AspNetCore.Server.Kestrel.Filter.Internal +namespace Microsoft.AspNetCore.Server.Kestrel.Adapter.Internal { - public class LibuvStream : Stream + public class RawStream : Stream { private readonly SocketInput _input; private readonly ISocketOutput _output; private Task _cachedTask = TaskCache.DefaultCompletedTask; - public LibuvStream(SocketInput input, ISocketOutput output) + public RawStream(SocketInput input, ISocketOutput output) { _input = input; _output = output; diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Filter/Internal/StreamSocketOutput.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Adapter/Internal/StreamSocketOutput.cs similarity index 98% rename from src/Microsoft.AspNetCore.Server.Kestrel/Filter/Internal/StreamSocketOutput.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Adapter/Internal/StreamSocketOutput.cs index bce699f693..e2cce039aa 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Filter/Internal/StreamSocketOutput.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Adapter/Internal/StreamSocketOutput.cs @@ -10,7 +10,7 @@ using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.Extensions.Internal; -namespace Microsoft.AspNetCore.Server.Kestrel.Filter.Internal +namespace Microsoft.AspNetCore.Server.Kestrel.Adapter.Internal { public class StreamSocketOutput : ISocketOutput { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Adapter/ListenOptionsConnectionLoggingExtensions.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Adapter/ListenOptionsConnectionLoggingExtensions.cs new file mode 100644 index 0000000000..9d5affe345 --- /dev/null +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Adapter/ListenOptionsConnectionLoggingExtensions.cs @@ -0,0 +1,38 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using Microsoft.AspNetCore.Server.Kestrel; +using Microsoft.AspNetCore.Server.Kestrel.Adapter; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; + +namespace Microsoft.AspNetCore.Hosting +{ + public static class ListenOptionsConnectionLoggingExtensions + { + /// + /// Emits verbose logs for bytes read from and written to the connection. + /// + /// + /// The . + /// + public static ListenOptions UseConnectionLogging(this ListenOptions listenOptions) + { + return listenOptions.UseConnectionLogging(nameof(LoggingConnectionAdapter)); + } + + /// + /// Emits verbose logs for bytes read from and written to the connection. + /// + /// + /// The . + /// + public static ListenOptions UseConnectionLogging(this ListenOptions listenOptions, string loggerName) + { + var loggerFactory = listenOptions.KestrelServerOptions.ApplicationServices.GetRequiredService(); + var logger = loggerFactory.CreateLogger(loggerName ?? nameof(LoggingConnectionAdapter)); + listenOptions.ConnectionAdapters.Add(new LoggingConnectionAdapter(logger)); + return listenOptions; + } + } +} diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Adapter/LoggingConnectionAdapter.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Adapter/LoggingConnectionAdapter.cs new file mode 100644 index 0000000000..6c25f4ba2f --- /dev/null +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Adapter/LoggingConnectionAdapter.cs @@ -0,0 +1,47 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.IO; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Http.Features; +using Microsoft.AspNetCore.Server.Kestrel.Adapter.Internal; +using Microsoft.Extensions.Logging; + +namespace Microsoft.AspNetCore.Server.Kestrel.Adapter +{ + public class LoggingConnectionAdapter : IConnectionAdapter + { + private readonly ILogger _logger; + + public LoggingConnectionAdapter(ILogger logger) + { + if (logger == null) + { + throw new ArgumentNullException(nameof(logger)); + } + + _logger = logger; + } + + public Task OnConnectionAsync(ConnectionAdapterContext context) + { + return Task.FromResult( + new LoggingAdaptedConnection(context.ConnectionStream, _logger)); + } + + private class LoggingAdaptedConnection : IAdaptedConnection + { + public LoggingAdaptedConnection(Stream rawStream, ILogger logger) + { + ConnectionStream = new LoggingStream(rawStream, logger); + } + + public Stream ConnectionStream { get; } + + public void PrepareRequest(IFeatureCollection requestFeatures) + { + } + } + } +} diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Filter/ConnectionFilterContext.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Filter/ConnectionFilterContext.cs deleted file mode 100644 index 386753342f..0000000000 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Filter/ConnectionFilterContext.cs +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using System.IO; -using Microsoft.AspNetCore.Http.Features; - -namespace Microsoft.AspNetCore.Server.Kestrel.Filter -{ - public class ConnectionFilterContext - { - public ServerAddress Address { get; set; } - public Stream Connection { get; set; } - public Action PrepareRequest { get; set; } - } -} diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Filter/IConnectionFilter.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Filter/IConnectionFilter.cs deleted file mode 100644 index 0447f8b07a..0000000000 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Filter/IConnectionFilter.cs +++ /dev/null @@ -1,12 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System.Threading.Tasks; - -namespace Microsoft.AspNetCore.Server.Kestrel.Filter -{ - public interface IConnectionFilter - { - Task OnConnectionAsync(ConnectionFilterContext context); - } -} diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Filter/KestrelServerOptionsConnectionLoggingExtensions.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Filter/KestrelServerOptionsConnectionLoggingExtensions.cs deleted file mode 100644 index a46d0646eb..0000000000 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Filter/KestrelServerOptionsConnectionLoggingExtensions.cs +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using Microsoft.AspNetCore.Server.Kestrel; -using Microsoft.AspNetCore.Server.Kestrel.Filter; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Logging; - -namespace Microsoft.AspNetCore.Hosting -{ - public static class KestrelServerOptionsConnectionLoggingExtensions - { - /// - /// Emits verbose logs for bytes read from and written to the connection. - /// - /// - /// The Microsoft.AspNetCore.Server.KestrelServerOptions. - /// - public static KestrelServerOptions UseConnectionLogging(this KestrelServerOptions options) - { - return options.UseConnectionLogging(nameof(LoggingConnectionFilter)); - } - - /// - /// Emits verbose logs for bytes read from and written to the connection. - /// - /// - /// The Microsoft.AspNetCore.Server.KestrelServerOptions. - /// - public static KestrelServerOptions UseConnectionLogging(this KestrelServerOptions options, string loggerName) - { - var prevFilter = options.ConnectionFilter ?? new NoOpConnectionFilter(); - var loggerFactory = options.ApplicationServices.GetRequiredService(); - var logger = loggerFactory.CreateLogger(loggerName ?? nameof(LoggingConnectionFilter)); - options.ConnectionFilter = new LoggingConnectionFilter(logger, prevFilter); - return options; - } - } -} diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Filter/LoggingConnectionFilter.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Filter/LoggingConnectionFilter.cs deleted file mode 100644 index fd77be1295..0000000000 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Filter/LoggingConnectionFilter.cs +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Server.Kestrel.Filter.Internal; -using Microsoft.Extensions.Logging; - -namespace Microsoft.AspNetCore.Server.Kestrel.Filter -{ - public class LoggingConnectionFilter : IConnectionFilter - { - private readonly ILogger _logger; - private readonly IConnectionFilter _previous; - - public LoggingConnectionFilter(ILogger logger, IConnectionFilter previous) - { - if (logger == null) - { - throw new ArgumentNullException(nameof(logger)); - } - if (previous == null) - { - throw new ArgumentNullException(nameof(previous)); - } - - _logger = logger; - _previous = previous; - } - - public async Task OnConnectionAsync(ConnectionFilterContext context) - { - await _previous.OnConnectionAsync(context); - - context.Connection = new LoggingStream(context.Connection, _logger); - } - } -} diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Filter/NoOpConnectionFilter.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Filter/NoOpConnectionFilter.cs deleted file mode 100644 index a41bd9313e..0000000000 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Filter/NoOpConnectionFilter.cs +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System.Threading.Tasks; -using Microsoft.Extensions.Internal; - -namespace Microsoft.AspNetCore.Server.Kestrel.Filter -{ - public class NoOpConnectionFilter : IConnectionFilter - { - public Task OnConnectionAsync(ConnectionFilterContext context) - { - return TaskCache.CompletedTask; - } - } -} diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Connection.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Connection.cs index 2b2366ee4e..9d1c537814 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Connection.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Connection.cs @@ -2,12 +2,13 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Threading; using System.Threading.Tasks; -using Microsoft.AspNetCore.Server.Kestrel.Filter; -using Microsoft.AspNetCore.Server.Kestrel.Filter.Internal; +using Microsoft.AspNetCore.Server.Kestrel.Adapter; +using Microsoft.AspNetCore.Server.Kestrel.Adapter.Internal; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; using Microsoft.Extensions.Internal; @@ -22,6 +23,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http private static readonly Action _readCallback = (handle, status, state) => ReadCallback(handle, status, state); + private static readonly Func _allocCallback = (handle, suggestedsize, state) => AllocCallback(handle, suggestedsize, state); @@ -32,9 +34,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http private readonly UvStreamHandle _socket; private readonly Frame _frame; - private ConnectionFilterContext _filterContext; - private LibuvStream _libuvStream; - private FilteredStreamAdapter _filteredStreamAdapter; + private readonly List _connectionAdapters; + private AdaptedPipeline _adaptedPipeline; + private Stream _filteredStream; private Task _readInputTask; private TaskCompletionSource _socketClosedTcs = new TaskCompletionSource(); @@ -47,6 +49,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http public Connection(ListenerContext context, UvStreamHandle socket) : base(context) { _socket = socket; + _connectionAdapters = context.ListenOptions.ConnectionAdapters; socket.Connection = this; ConnectionControl = this; @@ -80,57 +83,24 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http private Func FrameFactory => ListenerContext.ServiceContext.FrameFactory; private IKestrelTrace Log => ListenerContext.ServiceContext.Log; private IThreadPool ThreadPool => ListenerContext.ServiceContext.ThreadPool; - private ServerAddress ServerAddress => ListenerContext.ServerAddress; private KestrelThread Thread => ListenerContext.Thread; public void Start() { Log.ConnectionStart(ConnectionId); - // Start socket prior to applying the ConnectionFilter + // Start socket prior to applying the ConnectionAdapter _socket.ReadStart(_allocCallback, _readCallback, this); - if (ServerOptions.ConnectionFilter == null) + if (_connectionAdapters.Count == 0) { _frame.Start(); } else { - _libuvStream = new LibuvStream(Input, Output); - - _filterContext = new ConnectionFilterContext - { - Connection = _libuvStream, - Address = ServerAddress - }; - - try - { - ServerOptions.ConnectionFilter.OnConnectionAsync(_filterContext).ContinueWith((task, state) => - { - var connection = (Connection)state; - - if (task.IsFaulted) - { - connection.Log.LogError(0, task.Exception, "ConnectionFilter.OnConnection"); - connection.ConnectionControl.End(ProduceEndType.SocketDisconnect); - } - else if (task.IsCanceled) - { - connection.Log.LogError("ConnectionFilter.OnConnection Canceled"); - connection.ConnectionControl.End(ProduceEndType.SocketDisconnect); - } - else - { - connection.ApplyConnectionFilter(); - } - }, this); - } - catch (Exception ex) - { - Log.LogError(0, ex, "ConnectionFilter.OnConnection"); - ConnectionControl.End(ProduceEndType.SocketDisconnect); - } + // ApplyConnectionAdaptersAsync should never throw. If it succeeds, it will call _frame.Start(). + // Otherwise, it will close the connection. + var ignore = ApplyConnectionAdaptersAsync(); } } @@ -161,13 +131,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { var connection = (Connection)state; - if (_filteredStreamAdapter != null) + if (connection._adaptedPipeline != null) { - Task.WhenAll(_readInputTask, _frame.StopAsync()).ContinueWith((task2, state2) => + Task.WhenAll(connection._readInputTask, connection._frame.StopAsync()).ContinueWith((task2, state2) => { var connection2 = (Connection)state2; - connection2._filterContext.Connection.Dispose(); - connection2._filteredStreamAdapter.Dispose(); + connection2._filteredStream.Dispose(); + connection2._adaptedPipeline.Dispose(); }, connection); } }, this); @@ -187,31 +157,52 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { _frame.SetBadRequestState(RequestRejectionReason.RequestTimeout); } - + StopAsync(); } Interlocked.Exchange(ref _lastTimestamp, timestamp); } - private void ApplyConnectionFilter() + private async Task ApplyConnectionAdaptersAsync() { - if (_filterContext.Connection != _libuvStream) + try { - _filteredStreamAdapter = new FilteredStreamAdapter(ConnectionId, _filterContext.Connection, Thread.Memory, Log, ThreadPool, _bufferSizeControl); + var rawStream = new RawStream(Input, Output); + var adapterContext = new ConnectionAdapterContext(rawStream); + var adaptedConnections = new IAdaptedConnection[_connectionAdapters.Count]; - _frame.Input = _filteredStreamAdapter.SocketInput; - _frame.Output = _filteredStreamAdapter.SocketOutput; + for (var i = 0; i < _connectionAdapters.Count; i++) + { + var adaptedConnection = await _connectionAdapters[i].OnConnectionAsync(adapterContext); + adaptedConnections[i] = adaptedConnection; + adapterContext = new ConnectionAdapterContext(adaptedConnection.ConnectionStream); + } - // Don't attempt to read input if connection has already closed. - // This can happen if a client opens a connection and immediately closes it. - _readInputTask = _socketClosedTcs.Task.Status == TaskStatus.WaitingForActivation ? - _filteredStreamAdapter.ReadInputAsync() : - TaskCache.CompletedTask; + if (adapterContext.ConnectionStream != rawStream) + { + _filteredStream = adapterContext.ConnectionStream; + _adaptedPipeline = new AdaptedPipeline(ConnectionId, adapterContext.ConnectionStream, + Thread.Memory, Log, ThreadPool, _bufferSizeControl); + + _frame.Input = _adaptedPipeline.SocketInput; + _frame.Output = _adaptedPipeline.SocketOutput; + + // Don't attempt to read input if connection has already closed. + // This can happen if a client opens a connection and immediately closes it. + _readInputTask = _socketClosedTcs.Task.Status == TaskStatus.WaitingForActivation + ? _adaptedPipeline.ReadInputAsync() + : TaskCache.CompletedTask; + } + + _frame.AdaptedConnections = adaptedConnections; + _frame.Start(); + } + catch (Exception ex) + { + Log.LogError(0, ex, $"Uncaught exception from the {nameof(IConnectionAdapter.OnConnectionAsync)} method of an {nameof(IConnectionAdapter)}."); + ConnectionControl.End(ProduceEndType.SocketDisconnect); } - - _frame.PrepareRequest = _filterContext.PrepareRequest; - _frame.Start(); } private static Libuv.uv_buf_t AllocCallback(UvStreamHandle handle, int suggestedSize, object state) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ConnectionContext.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ConnectionContext.cs index 72344c73b1..decc5dbf8c 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ConnectionContext.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ConnectionContext.cs @@ -31,7 +31,5 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http public IPEndPoint LocalEndPoint { get; set; } public string ConnectionId { get; set; } - - public Action PrepareRequest { get; set; } } } \ No newline at end of file diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs index 2cb16d13bb..dfc49447b9 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs @@ -13,6 +13,7 @@ using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http.Features; +using Microsoft.AspNetCore.Server.Kestrel.Adapter; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.Extensions.Internal; using Microsoft.Extensions.Logging; @@ -87,7 +88,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http ServerOptions = context.ListenerContext.ServiceContext.ServerOptions; - _pathBase = ServerAddress.PathBase; + _pathBase = context.ListenerContext.ListenOptions.PathBase; FrameControl = this; _keepAliveMilliseconds = (long)ServerOptions.Limits.KeepAliveTimeout.TotalMilliseconds; @@ -97,23 +98,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http public ConnectionContext ConnectionContext { get; } public SocketInput Input { get; set; } public ISocketOutput Output { get; set; } - public Action PrepareRequest - { - get - { - return ConnectionContext.PrepareRequest; - } - set - { - ConnectionContext.PrepareRequest = value; - } - } + public IEnumerable AdaptedConnections { get; set; } protected IConnectionControl ConnectionControl => ConnectionContext.ConnectionControl; protected IKestrelTrace Log => ConnectionContext.ListenerContext.ServiceContext.Log; private DateHeaderValueManager DateHeaderValueManager => ConnectionContext.ListenerContext.ServiceContext.DateHeaderValueManager; - private ServerAddress ServerAddress => ConnectionContext.ListenerContext.ServerAddress; // Hold direct reference to ServerOptions since this is used very often in the request processing path private KestrelServerOptions ServerOptions { get; } private IPEndPoint LocalEndPoint => ConnectionContext.LocalEndPoint; @@ -367,7 +357,20 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http LocalPort = LocalEndPoint?.Port ?? 0; ConnectionIdFeature = ConnectionId; - PrepareRequest?.Invoke(this); + if (AdaptedConnections != null) + { + try + { + foreach (var adaptedConnection in AdaptedConnections) + { + adaptedConnection.PrepareRequest(this); + } + } + catch (Exception ex) + { + Log.LogError(0, ex, $"Uncaught exception from the {nameof(IAdaptedConnection.PrepareRequest)} method of an {nameof(IAdaptedConnection)}."); + } + } _manuallySetRequestAbortToken = null; _abortedCts = null; diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Listener.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Listener.cs index f66485a5ed..3bb269f6c8 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Listener.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Listener.cs @@ -12,11 +12,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http /// /// Base class for listeners in Kestrel. Listens for incoming connections /// - public abstract class Listener : ListenerContext, IAsyncDisposable + public class Listener : ListenerContext, IAsyncDisposable { private bool _closed; - protected Listener(ServiceContext serviceContext) + public Listener(ServiceContext serviceContext) : base(serviceContext) { } @@ -26,20 +26,20 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http public IKestrelTrace Log => ServiceContext.Log; public Task StartAsync( - ServerAddress address, + ListenOptions listenOptions, KestrelThread thread) { - ServerAddress = address; + ListenOptions = listenOptions; Thread = thread; var tcs = new TaskCompletionSource(this); Thread.Post(state => { - var tcs2 = (TaskCompletionSource)state; + var tcs2 = (TaskCompletionSource) state; try { - var listener = ((Listener)tcs2.Task.AsyncState); + var listener = ((Listener) tcs2.Task.AsyncState); listener.ListenSocket = listener.CreateListenSocket(); ListenSocket.Listen(Constants.ListenBacklog, ConnectionCallback, this); tcs2.SetResult(0); @@ -56,11 +56,61 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http /// /// Creates the socket used to listen for incoming connections /// - protected abstract UvStreamHandle CreateListenSocket(); + private UvStreamHandle CreateListenSocket() + { + switch (ListenOptions.Type) + { + case ListenType.IPEndPoint: + case ListenType.FileHandle: + var socket = new UvTcpHandle(Log); + + try + { + socket.Init(Thread.Loop, Thread.QueueCloseHandle); + socket.NoDelay(ListenOptions.NoDelay); + + if (ListenOptions.Type == ListenType.IPEndPoint) + { + socket.Bind(ListenOptions.IPEndPoint); + + // If requested port was "0", replace with assigned dynamic port. + ListenOptions.IPEndPoint = socket.GetSockIPEndPoint(); + } + else + { + socket.Open((IntPtr)ListenOptions.FileHandle); + } + } + catch + { + socket.Dispose(); + throw; + } + + return socket; + case ListenType.SocketPath: + var pipe = new UvPipeHandle(Log); + + try + { + pipe.Init(Thread.Loop, Thread.QueueCloseHandle, false); + pipe.Bind(ListenOptions.SocketPath); + } + catch + { + pipe.Dispose(); + throw; + } + + return pipe; + default: + throw new NotSupportedException(); + } + } private static void ConnectionCallback(UvStreamHandle stream, int status, Exception error, object state) { - var listener = (Listener)state; + var listener = (Listener) state; if (error != null) { @@ -77,7 +127,22 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http /// /// Socket being used to listen on /// Connection status - protected abstract void OnConnection(UvStreamHandle listenSocket, int status); + private void OnConnection(UvStreamHandle listenSocket, int status) + { + UvStreamHandle acceptSocket = null; + + try + { + acceptSocket = CreateAcceptSocket(); + listenSocket.Accept(acceptSocket); + DispatchConnection(acceptSocket); + } + catch (UvException ex) + { + Log.LogError(0, ex, "Listener.OnConnection"); + acceptSocket?.Dispose(); + } + } protected virtual void DispatchConnection(UvStreamHandle socket) { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ListenerContext.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ListenerContext.cs index 8ecee653f0..083f1a2148 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ListenerContext.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ListenerContext.cs @@ -1,6 +1,9 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; + namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { public class ListenerContext @@ -12,10 +15,30 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http public ServiceContext ServiceContext { get; set; } - public ServerAddress ServerAddress { get; set; } + public ListenOptions ListenOptions { get; set; } public KestrelThread Thread { get; set; } - public KestrelServerOptions ServerOptions => ServiceContext.ServerOptions; + /// + /// Creates a socket which can be used to accept an incoming connection. + /// + protected UvStreamHandle CreateAcceptSocket() + { + switch (ListenOptions.Type) + { + case ListenType.IPEndPoint: + case ListenType.FileHandle: + var tcpHandle = new UvTcpHandle(ServiceContext.Log); + tcpHandle.Init(Thread.Loop, Thread.QueueCloseHandle); + tcpHandle.NoDelay(ListenOptions.NoDelay); + return tcpHandle; + case ListenType.SocketPath: + var pipeHandle = new UvPipeHandle(ServiceContext.Log); + pipeHandle.Init(Thread.Loop, Thread.QueueCloseHandle); + return pipeHandle; + default: + throw new InvalidOperationException(); + } + } } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ListenerPrimary.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ListenerPrimary.cs index 4b192c505d..ebf6267630 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ListenerPrimary.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ListenerPrimary.cs @@ -16,7 +16,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http /// A primary listener waits for incoming connections on a specified socket. Incoming /// connections may be passed to a secondary listener to handle. /// - public abstract class ListenerPrimary : Listener + public class ListenerPrimary : Listener { private readonly List _dispatchPipes = new List(); private int _dispatchIndex; @@ -29,7 +29,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http // but it has no other functional significance private readonly ArraySegment> _dummyMessage = new ArraySegment>(new[] { new ArraySegment(new byte[] { 1, 2, 3, 4 }) }); - protected ListenerPrimary(ServiceContext serviceContext) : base(serviceContext) + public ListenerPrimary(ServiceContext serviceContext) : base(serviceContext) { } @@ -38,7 +38,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http public async Task StartAsync( string pipeName, byte[] pipeMessage, - ServerAddress address, + ListenOptions listenOptions, KestrelThread thread) { _pipeName = pipeName; @@ -51,7 +51,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http Marshal.StructureToPtr(fileCompletionInfo, _fileCompletionInfoPtr, false); } - await StartAsync(address, thread).ConfigureAwait(false); + await StartAsync(listenOptions, thread).ConfigureAwait(false); await Thread.PostAsync(state => ((ListenerPrimary)state).PostCallback(), this).ConfigureAwait(false); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ListenerSecondary.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ListenerSecondary.cs index 078f9c6e03..9ce1478b24 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ListenerSecondary.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ListenerSecondary.cs @@ -15,7 +15,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http /// A secondary listener is delegated requests from a primary listener via a named pipe or /// UNIX domain socket. /// - public abstract class ListenerSecondary : ListenerContext, IAsyncDisposable + public class ListenerSecondary : ListenerContext, IAsyncDisposable { private string _pipeName; private byte[] _pipeMessage; @@ -23,7 +23,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http private Libuv.uv_buf_t _buf; private bool _closed; - protected ListenerSecondary(ServiceContext serviceContext) : base(serviceContext) + public ListenerSecondary(ServiceContext serviceContext) : base(serviceContext) { _ptr = Marshal.AllocHGlobal(4); } @@ -35,14 +35,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http public Task StartAsync( string pipeName, byte[] pipeMessage, - ServerAddress address, + ListenOptions listenOptions, KestrelThread thread) { _pipeName = pipeName; _pipeMessage = pipeMessage; _buf = thread.Loop.Libuv.buf_init(_ptr, 4); - ServerAddress = address; + ListenOptions = listenOptions; Thread = thread; DispatchPipe = new UvPipeHandle(Log); @@ -173,11 +173,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } } - /// - /// Creates a socket which can be used to accept an incoming connection - /// - protected abstract UvStreamHandle CreateAcceptSocket(); - private void FreeBuffer() { var ptr = Interlocked.Exchange(ref _ptr, IntPtr.Zero); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/PipeListener.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/PipeListener.cs deleted file mode 100644 index 8ef9e38683..0000000000 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/PipeListener.cs +++ /dev/null @@ -1,61 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; -using Microsoft.Extensions.Logging; - -namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http -{ - /// - /// Implementation of that uses UNIX domain sockets as its transport. - /// - public class PipeListener : Listener - { - public PipeListener(ServiceContext serviceContext) : base(serviceContext) - { - } - - /// - /// Creates the socket used to listen for incoming connections - /// - protected override UvStreamHandle CreateListenSocket() - { - var socket = new UvPipeHandle(Log); - - try - { - socket.Init(Thread.Loop, Thread.QueueCloseHandle, false); - socket.Bind(ServerAddress.UnixPipePath); - } - catch - { - socket.Dispose(); - throw; - } - - return socket; - } - - /// - /// Handles an incoming connection - /// - /// Socket being used to listen on - /// Connection status - protected override void OnConnection(UvStreamHandle listenSocket, int status) - { - var acceptSocket = new UvPipeHandle(Log); - - try - { - acceptSocket.Init(Thread.Loop, Thread.QueueCloseHandle, false); - listenSocket.Accept(acceptSocket); - DispatchConnection(acceptSocket); - } - catch (UvException ex) - { - Log.LogError(0, ex, "PipeListener.OnConnection"); - acceptSocket.Dispose(); - } - } - } -} diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/PipeListenerPrimary.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/PipeListenerPrimary.cs deleted file mode 100644 index ebc59cfadb..0000000000 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/PipeListenerPrimary.cs +++ /dev/null @@ -1,62 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; -using Microsoft.Extensions.Logging; - -namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http -{ - /// - /// An implementation of using UNIX sockets. - /// - public class PipeListenerPrimary : ListenerPrimary - { - public PipeListenerPrimary(ServiceContext serviceContext) : base(serviceContext) - { - } - - /// - /// Creates the socket used to listen for incoming connections - /// - protected override UvStreamHandle CreateListenSocket() - { - var socket = new UvPipeHandle(Log); - - try - { - socket.Init(Thread.Loop, Thread.QueueCloseHandle, false); - socket.Bind(ServerAddress.UnixPipePath); - } - catch - { - socket.Dispose(); - throw; - } - - return socket; - } - - /// - /// Handles an incoming connection - /// - /// Socket being used to listen on - /// Connection status - protected override void OnConnection(UvStreamHandle listenSocket, int status) - { - var acceptSocket = new UvPipeHandle(Log); - - try - { - acceptSocket.Init(Thread.Loop, Thread.QueueCloseHandle, false); - listenSocket.Accept(acceptSocket); - DispatchConnection(acceptSocket); - } - catch (UvException ex) - { - Log.LogError(0, ex, "ListenerPrimary.OnConnection"); - acceptSocket.Dispose(); - } - } - } -} diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/PipeListenerSecondary.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/PipeListenerSecondary.cs deleted file mode 100644 index be9879f13b..0000000000 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/PipeListenerSecondary.cs +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; - -namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http -{ - /// - /// An implementation of using UNIX sockets. - /// - public class PipeListenerSecondary : ListenerSecondary - { - public PipeListenerSecondary(ServiceContext serviceContext) : base(serviceContext) - { - } - - /// - /// Creates a socket which can be used to accept an incoming connection - /// - protected override UvStreamHandle CreateAcceptSocket() - { - var acceptSocket = new UvPipeHandle(Log); - acceptSocket.Init(Thread.Loop, Thread.QueueCloseHandle, false); - return acceptSocket; - } - } -} diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/TcpListener.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/TcpListener.cs deleted file mode 100644 index fd69130fb8..0000000000 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/TcpListener.cs +++ /dev/null @@ -1,68 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; -using Microsoft.Extensions.Logging; - -namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http -{ - /// - /// Implementation of that uses TCP sockets as its transport. - /// - public class TcpListener : Listener - { - public TcpListener(ServiceContext serviceContext) : base(serviceContext) - { - } - - /// - /// Creates the socket used to listen for incoming connections - /// - protected override UvStreamHandle CreateListenSocket() - { - var socket = new UvTcpHandle(Log); - - try - { - socket.Init(Thread.Loop, Thread.QueueCloseHandle); - socket.NoDelay(ServerOptions.NoDelay); - socket.Bind(ServerAddress); - - // If requested port was "0", replace with assigned dynamic port. - ServerAddress.Port = socket.GetSockIPEndPoint().Port; - } - catch - { - socket.Dispose(); - throw; - } - - return socket; - } - - /// - /// Handle an incoming connection - /// - /// Socket being used to listen on - /// Connection status - protected override void OnConnection(UvStreamHandle listenSocket, int status) - { - var acceptSocket = new UvTcpHandle(Log); - - try - { - acceptSocket.Init(Thread.Loop, Thread.QueueCloseHandle); - acceptSocket.NoDelay(ServerOptions.NoDelay); - listenSocket.Accept(acceptSocket); - DispatchConnection(acceptSocket); - } - catch (UvException ex) - { - Log.LogError(0, ex, "TcpListener.OnConnection"); - acceptSocket.Dispose(); - } - } - } -} diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/TcpListenerPrimary.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/TcpListenerPrimary.cs deleted file mode 100644 index 09b856438a..0000000000 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/TcpListenerPrimary.cs +++ /dev/null @@ -1,68 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; -using Microsoft.Extensions.Logging; - -namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http -{ - /// - /// An implementation of using TCP sockets. - /// - public class TcpListenerPrimary : ListenerPrimary - { - public TcpListenerPrimary(ServiceContext serviceContext) : base(serviceContext) - { - } - - /// - /// Creates the socket used to listen for incoming connections - /// - protected override UvStreamHandle CreateListenSocket() - { - var socket = new UvTcpHandle(Log); - - try - { - socket.Init(Thread.Loop, Thread.QueueCloseHandle); - socket.NoDelay(ServerOptions.NoDelay); - socket.Bind(ServerAddress); - - // If requested port was "0", replace with assigned dynamic port. - ServerAddress.Port = socket.GetSockIPEndPoint().Port; - } - catch - { - socket.Dispose(); - throw; - } - - return socket; - } - - /// - /// Handles an incoming connection - /// - /// Socket being used to listen on - /// Connection status - protected override void OnConnection(UvStreamHandle listenSocket, int status) - { - var acceptSocket = new UvTcpHandle(Log); - - try - { - acceptSocket.Init(Thread.Loop, Thread.QueueCloseHandle); - acceptSocket.NoDelay(ServerOptions.NoDelay); - listenSocket.Accept(acceptSocket); - DispatchConnection(acceptSocket); - } - catch (UvException ex) - { - Log.LogError(0, ex, "TcpListenerPrimary.OnConnection"); - acceptSocket.Dispose(); - } - } - } -} diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/TcpListenerSecondary.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/TcpListenerSecondary.cs deleted file mode 100644 index 0a34eb7202..0000000000 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/TcpListenerSecondary.cs +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; - -namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http -{ - /// - /// An implementation of using TCP sockets. - /// - public class TcpListenerSecondary : ListenerSecondary - { - public TcpListenerSecondary(ServiceContext serviceContext) : base(serviceContext) - { - } - - /// - /// Creates a socket which can be used to accept an incoming connection - /// - protected override UvStreamHandle CreateAcceptSocket() - { - var acceptSocket = new UvTcpHandle(Log); - acceptSocket.Init(Thread.Loop, Thread.QueueCloseHandle); - acceptSocket.NoDelay(ServerOptions.NoDelay); - return acceptSocket; - } - } -} diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/Constants.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/Constants.cs index 3acb659218..46d0bdac5a 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/Constants.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/Constants.cs @@ -19,6 +19,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure /// public const string UnixPipeHostPrefix = "unix:/"; + /// + /// Prefix of host name used to specify pipe file descriptor in the configuration. + /// + public const string PipeDescriptorPrefix = "pipefd:"; + + /// + /// Prefix of host name used to specify socket descriptor in the configuration. + /// + public const string SocketDescriptorPrefix = "sockfd:"; + public const string ServerName = "Kestrel"; private static int? GetECONNRESET() diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/KestrelEngine.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/KestrelEngine.cs index 3b3b46a4c9..b7a7b5a63e 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/KestrelEngine.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/KestrelEngine.cs @@ -61,49 +61,33 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal #endif } - public IDisposable CreateServer(ServerAddress address) + public IDisposable CreateServer(ListenOptions listenOptions) { var listeners = new List(); - var usingPipes = address.IsUnixPipe; - try { - var pipeName = (Libuv.IsWindows ? @"\\.\pipe\kestrel_" : "/tmp/kestrel_") + Guid.NewGuid().ToString("n"); - var pipeMessage = Guid.NewGuid().ToByteArray(); - - var single = Threads.Count == 1; - var first = true; - - foreach (var thread in Threads) + if (Threads.Count == 1) { - if (single) - { - var listener = usingPipes ? - (Listener) new PipeListener(ServiceContext) : - new TcpListener(ServiceContext); - listeners.Add(listener); - listener.StartAsync(address, thread).Wait(); - } - else if (first) - { - var listener = usingPipes - ? (ListenerPrimary) new PipeListenerPrimary(ServiceContext) - : new TcpListenerPrimary(ServiceContext); + var listener = new Listener(ServiceContext); + listeners.Add(listener); + listener.StartAsync(listenOptions, Threads[0]).Wait(); + } + else + { + var pipeName = (Libuv.IsWindows ? @"\\.\pipe\kestrel_" : "/tmp/kestrel_") + Guid.NewGuid().ToString("n"); + var pipeMessage = Guid.NewGuid().ToByteArray(); - listeners.Add(listener); - listener.StartAsync(pipeName, pipeMessage, address, thread).Wait(); - } - else - { - var listener = usingPipes - ? (ListenerSecondary) new PipeListenerSecondary(ServiceContext) - : new TcpListenerSecondary(ServiceContext); - listeners.Add(listener); - listener.StartAsync(pipeName, pipeMessage, address, thread).Wait(); - } + var listenerPrimary = new ListenerPrimary(ServiceContext); + listeners.Add(listenerPrimary); + listenerPrimary.StartAsync(pipeName, pipeMessage, listenOptions, Threads[0]).Wait(); - first = false; + foreach (var thread in Threads.Skip(1)) + { + var listenerSecondary = new ListenerSecondary(ServiceContext); + listeners.Add(listenerSecondary); + listenerSecondary.StartAsync(pipeName, pipeMessage, listenOptions, thread).Wait(); + } } return new Disposable(() => @@ -114,7 +98,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal catch { DisposeListeners(listeners); - throw; } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/SockAddr.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/SockAddr.cs index ae4196153f..71e7c59b32 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/SockAddr.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/SockAddr.cs @@ -32,7 +32,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking // 0000 0000 0b99 0017 => The third and fourth bytes 990B is the actual port // 9103 e000 9848 0120 => IPv6 address is represented in the 128bit field1 and field2. // 54a3 3e9d 2411 efb9 Read these two 64-bit long from right to left byte by byte. - // 0000 0000 0000 0000 + // 0000 0000 0000 0010 => Scope ID 0x10 (eg [::1%16]) the first 4 bytes of field3 in host byte order. // // Example 2: 10.135.34.141:39178 when adopt dual-stack sockets, IPv4 is mapped to IPv6 // @@ -58,6 +58,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking // Reference: // - Windows: https://msdn.microsoft.com/en-us/library/windows/desktop/ms740506(v=vs.85).aspx // - Linux: https://github.com/torvalds/linux/blob/6a13feb9c82803e2b815eca72fa7a9f5561d7861/include/linux/socket.h + // - Linux (sin6_scope_id): https://github.com/torvalds/linux/blob/5924bbecd0267d87c24110cbe2041b5075173a25/net/sunrpc/addr.c#L82 // - Apple: http://www.opensource.apple.com/source/xnu/xnu-1456.1.26/bsd/sys/socket.h // Quick calculate the port by mask the field and locate the byte 3 and byte 4 @@ -92,7 +93,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking *((long*)(b + 8)) = _field2; } - return new IPEndPoint(new IPAddress(bytes), port); + return new IPEndPoint(new IPAddress(bytes, scopeid: _field3 & 0xFFFFFFFF), port); } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/UvTcpHandle.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/UvTcpHandle.cs index 3684f4f412..402f2f37cd 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/UvTcpHandle.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/UvTcpHandle.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Diagnostics; using System.Net; using System.Runtime.InteropServices; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; @@ -24,20 +25,23 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking _uv.tcp_init(loop, this); } - public void Bind(ServerAddress address) + public void Open(IntPtr fileDescriptor) { - var endpoint = CreateIPEndpoint(address); + _uv.tcp_open(this, fileDescriptor); + } + public void Bind(IPEndPoint endPoint) + { SockAddr addr; - var addressText = endpoint.Address.ToString(); + var addressText = endPoint.Address.ToString(); Exception error1; - _uv.ip4_addr(addressText, endpoint.Port, out addr, out error1); + _uv.ip4_addr(addressText, endPoint.Port, out addr, out error1); if (error1 != null) { Exception error2; - _uv.ip6_addr(addressText, endpoint.Port, out addr, out error2); + _uv.ip6_addr(addressText, endPoint.Port, out addr, out error2); if (error2 != null) { throw error1; @@ -65,38 +69,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking return socketAddress.GetIPEndPoint(); } - public void Open(IntPtr hSocket) - { - _uv.tcp_open(this, hSocket); - } - public void NoDelay(bool enable) { _uv.tcp_nodelay(this, enable); } - - /// - /// Returns an for the given host an port. - /// If the host parameter isn't "localhost" or an IP address, use IPAddress.Any. - /// - public static IPEndPoint CreateIPEndpoint(ServerAddress address) - { - // TODO: IPv6 support - IPAddress ip; - - if (!IPAddress.TryParse(address.Host, out ip)) - { - if (string.Equals(address.Host, "localhost", StringComparison.OrdinalIgnoreCase)) - { - ip = IPAddress.Loopback; - } - else - { - ip = IPAddress.IPv6Any; - } - } - - return new IPEndPoint(ip, address.Port); - } } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServer.cs b/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServer.cs index 57fbc17017..a8a9c5af66 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServer.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServer.cs @@ -5,6 +5,7 @@ using System; using System.Collections.Generic; using System.IO; using System.Linq; +using System.Net; using System.Reflection; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting.Server; @@ -113,84 +114,82 @@ namespace Microsoft.AspNetCore.Server.Kestrel engine.Start(threadCount); var atLeastOneListener = false; - foreach (var address in _serverAddresses.Addresses.ToArray()) + var listenOptions = Options.ListenOptions; + + if (listenOptions.Any()) { - var parsedAddress = ServerAddress.FromUrl(address); - atLeastOneListener = true; - - if (!parsedAddress.Host.Equals("localhost", StringComparison.OrdinalIgnoreCase)) + var addresses = _serverAddresses.Addresses; + if (addresses.SingleOrDefault() != "http://localhost:5000") { - try - { - _disposables.Push(engine.CreateServer(parsedAddress)); - } - catch (AggregateException ex) - { - if ((ex.InnerException as UvException)?.StatusCode == Constants.EADDRINUSE) - { - throw new IOException($"Failed to bind to address {parsedAddress}: address already in use.", ex); - } + var joined = string.Join(", ", addresses); + throw new NotSupportedException($"Specifying address(es) '{joined}' is incompatible with also configuring endpoint(s) in UseKestrel."); + } - throw; + _serverAddresses.Addresses.Clear(); + } + else + { + // If no endpoints are configured directly using KestrelServerOptions, use those configured via the IServerAddressesFeature. + var copiedAddresses = _serverAddresses.Addresses.ToArray(); + _serverAddresses.Addresses.Clear(); + + foreach (var address in copiedAddresses) + { + var parsedAddress = ServerAddress.FromUrl(address); + + if (parsedAddress.IsUnixPipe) + { + listenOptions.Add(new ListenOptions(parsedAddress.UnixPipePath) + { + Scheme = parsedAddress.Scheme, + PathBase = parsedAddress.PathBase + }); + } + else + { + if (string.Equals(parsedAddress.Host, "localhost", StringComparison.OrdinalIgnoreCase)) + { + // "localhost" for both IPv4 and IPv6 can't be represented as an IPEndPoint. + StartLocalhost(engine, parsedAddress); + + // If StartLocalhost doesn't throw, there is at least one listener. + // The port cannot change for "localhost". + _serverAddresses.Addresses.Add(parsedAddress.ToString()); + atLeastOneListener = true; + } + else + { + // These endPoints will be added later to _serverAddresses.Addresses + listenOptions.Add(new ListenOptions(CreateIPEndPoint(parsedAddress)) + { + Scheme = parsedAddress.Scheme, + PathBase = parsedAddress.PathBase + }); + } } } - else + } + + foreach (var endPoint in listenOptions) + { + atLeastOneListener = true; + + try { - if (parsedAddress.Port == 0) + _disposables.Push(engine.CreateServer(endPoint)); + } + catch (AggregateException ex) + { + if ((ex.InnerException as UvException)?.StatusCode == Constants.EADDRINUSE) { - throw new InvalidOperationException("Dynamic port binding is not supported when binding to localhost. You must either bind to 127.0.0.1:0 or [::1]:0, or both."); + throw new IOException($"Failed to bind to address {endPoint}: address already in use.", ex); } - var ipv4Address = parsedAddress.WithHost("127.0.0.1"); - var exceptions = new List(); - - try - { - _disposables.Push(engine.CreateServer(ipv4Address)); - } - catch (AggregateException ex) when (ex.InnerException is UvException) - { - var uvEx = (UvException)ex.InnerException; - if (uvEx.StatusCode == Constants.EADDRINUSE) - { - throw new IOException($"Failed to bind to address {parsedAddress.ToString()} on the IPv4 loopback interface: port already in use.", ex); - } - else - { - _logger.LogWarning(0, $"Unable to bind to {parsedAddress.ToString()} on the IPv4 loopback interface: ({uvEx.Message})"); - exceptions.Add(uvEx); - } - } - - var ipv6Address = parsedAddress.WithHost("[::1]"); - - try - { - _disposables.Push(engine.CreateServer(ipv6Address)); - } - catch (AggregateException ex) when (ex.InnerException is UvException) - { - var uvEx = (UvException)ex.InnerException; - if (uvEx.StatusCode == Constants.EADDRINUSE) - { - throw new IOException($"Failed to bind to address {parsedAddress.ToString()} on the IPv6 loopback interface: port already in use.", ex); - } - else - { - _logger.LogWarning(0, $"Unable to bind to {parsedAddress.ToString()} on the IPv6 loopback interface: ({uvEx.Message})"); - exceptions.Add(uvEx); - } - } - - if (exceptions.Count == 2) - { - throw new IOException($"Failed to bind to address {parsedAddress.ToString()}.", new AggregateException(exceptions)); - } + throw; } // If requested port was "0", replace with assigned dynamic port. - _serverAddresses.Addresses.Remove(address); - _serverAddresses.Addresses.Add(parsedAddress.ToString()); + _serverAddresses.Addresses.Add(endPoint.ToString()); } if (!atLeastOneListener) @@ -227,5 +226,84 @@ namespace Microsoft.AspNetCore.Server.Kestrel $"Maximum request buffer size ({Options.Limits.MaxRequestBufferSize.Value}) must be greater than or equal to maximum request line size ({Options.Limits.MaxRequestLineSize})."); } } + + private void StartLocalhost(KestrelEngine engine, ServerAddress parsedAddress) + { + if (parsedAddress.Port == 0) + { + throw new InvalidOperationException("Dynamic port binding is not supported when binding to localhost. You must either bind to 127.0.0.1:0 or [::1]:0, or both."); + } + + var exceptions = new List(); + + try + { + var ipv4ListenOptions = new ListenOptions(new IPEndPoint(IPAddress.Loopback, parsedAddress.Port)) + { + Scheme = parsedAddress.Scheme, + PathBase = parsedAddress.PathBase + }; + + _disposables.Push(engine.CreateServer(ipv4ListenOptions)); + } + catch (AggregateException ex) when (ex.InnerException is UvException) + { + var uvEx = (UvException)ex.InnerException; + if (uvEx.StatusCode == Constants.EADDRINUSE) + { + throw new IOException($"Failed to bind to address {parsedAddress} on the IPv4 loopback interface: port already in use.", ex); + } + else + { + _logger.LogWarning(0, $"Unable to bind to {parsedAddress} on the IPv4 loopback interface: ({uvEx.Message})"); + exceptions.Add(uvEx); + } + } + + try + { + var ipv6ListenOptions = new ListenOptions(new IPEndPoint(IPAddress.IPv6Loopback, parsedAddress.Port)) + { + Scheme = parsedAddress.Scheme, + PathBase = parsedAddress.PathBase + }; + + _disposables.Push(engine.CreateServer(ipv6ListenOptions)); + } + catch (AggregateException ex) when (ex.InnerException is UvException) + { + var uvEx = (UvException)ex.InnerException; + if (uvEx.StatusCode == Constants.EADDRINUSE) + { + throw new IOException($"Failed to bind to address {parsedAddress} on the IPv6 loopback interface: port already in use.", ex); + } + else + { + _logger.LogWarning(0, $"Unable to bind to {parsedAddress} on the IPv6 loopback interface: ({uvEx.Message})"); + exceptions.Add(uvEx); + } + } + + if (exceptions.Count == 2) + { + throw new IOException($"Failed to bind to address {parsedAddress}.", new AggregateException(exceptions)); + } + } + + /// + /// Returns an for the given host an port. + /// If the host parameter isn't "localhost" or an IP address, use IPAddress.Any. + /// + internal static IPEndPoint CreateIPEndPoint(ServerAddress address) + { + IPAddress ip; + + if (!IPAddress.TryParse(address.Host, out ip)) + { + ip = IPAddress.IPv6Any; + } + + return new IPEndPoint(ip, address.Port); + } } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServerOptions.cs b/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServerOptions.cs index 7fe386e34c..c458d1e5f7 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServerOptions.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServerOptions.cs @@ -1,5 +1,9 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + using System; -using Microsoft.AspNetCore.Server.Kestrel.Filter; +using System.Collections.Generic; +using System.Net; namespace Microsoft.AspNetCore.Server.Kestrel { @@ -8,6 +12,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel /// public class KestrelServerOptions { + /// + /// Configures the endpoints that Kestrel should listen to. + /// + /// + /// If this list is empty, the server.urls setting (e.g. UseUrls) is used. + /// + internal List ListenOptions { get; } = new List(); + /// /// Gets or sets whether the Server header should be included in each response. /// @@ -17,22 +29,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel public bool AddServerHeader { get; set; } = true; /// - /// Enables the UseKestrel options callback to resolve and use services registered by the application during startup. + /// Enables the Listen options callback to resolve and use services registered by the application during startup. /// Typically initialized by . /// public IServiceProvider ApplicationServices { get; set; } - /// - /// Gets or sets an that allows each connection - /// to be intercepted and transformed. - /// Configured by the UseHttps() and - /// extension methods. - /// - /// - /// Defaults to null. - /// - public IConnectionFilter ConnectionFilter { get; set; } - /// /// /// This property is obsolete and will be removed in a future version. @@ -64,14 +65,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel /// public KestrelServerLimits Limits { get; } = new KestrelServerLimits(); - /// - /// Set to false to enable Nagle's algorithm for all connections. - /// - /// - /// Defaults to true. - /// - public bool NoDelay { get; set; } = true; - /// /// The amount of time after the server begins shutting down before connections will be forcefully closed. /// Kestrel will wait for the duration of the timeout for any ongoing request processing to complete before @@ -115,5 +108,111 @@ namespace Microsoft.AspNetCore.Server.Kestrel return threadCount; } } + + /// + /// Bind to given IP address and port. + /// + public void Listen(IPAddress address, int port) + { + Listen(address, port, _ => { }); + } + + /// + /// Bind to given IP address and port. + /// The callback configures endpoint-specific settings. + /// + public void Listen(IPAddress address, int port, Action configure) + { + if (address == null) + { + throw new ArgumentNullException(nameof(address)); + } + + Listen(new IPEndPoint(address, port), configure); + } + + /// + /// Bind to given IP endpoint. + /// + public void Listen(IPEndPoint endPoint) + { + Listen(endPoint, _ => { }); + } + + /// + /// Bind to given IP address and port. + /// The callback configures endpoint-specific settings. + /// + public void Listen(IPEndPoint endPoint, Action configure) + { + if (endPoint == null) + { + throw new ArgumentNullException(nameof(endPoint)); + } + if (configure == null) + { + throw new ArgumentNullException(nameof(configure)); + } + + var listenOptions = new ListenOptions(endPoint) { KestrelServerOptions = this }; + configure(listenOptions); + ListenOptions.Add(listenOptions); + } + + /// + /// Bind to given Unix domain socket path. + /// + public void ListenUnixSocket(string socketPath) + { + ListenUnixSocket(socketPath, _ => { }); + } + + /// + /// Bind to given Unix domain socket path. + /// Specify callback to configure endpoint-specific settings. + /// + public void ListenUnixSocket(string socketPath, Action configure) + { + if (socketPath == null) + { + throw new ArgumentNullException(nameof(socketPath)); + } + if (socketPath.Length == 0 || socketPath[0] != '/') + { + throw new ArgumentException("Unix socket path must be absolute.", nameof(socketPath)); + } + if (configure == null) + { + throw new ArgumentNullException(nameof(configure)); + } + + var listenOptions = new ListenOptions(socketPath) { KestrelServerOptions = this }; + configure(listenOptions); + ListenOptions.Add(listenOptions); + } + + /// + /// Open a socket file descriptor. + /// + public void ListenHandle(ulong handle) + { + ListenHandle(handle, _ => { }); + } + + /// + /// Open a socket file descriptor. + /// The callback configures endpoint-specific settings. + /// + public void ListenHandle(ulong handle, Action configure) + { + if (configure == null) + { + throw new ArgumentNullException(nameof(configure)); + } + + var listenOptions = new ListenOptions(handle) { KestrelServerOptions = this }; + configure(listenOptions); + ListenOptions.Add(listenOptions); + } } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/ListenOptions.cs b/src/Microsoft.AspNetCore.Server.Kestrel/ListenOptions.cs new file mode 100644 index 0000000000..f1a458776e --- /dev/null +++ b/src/Microsoft.AspNetCore.Server.Kestrel/ListenOptions.cs @@ -0,0 +1,108 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Collections.Generic; +using System.Net; +using Microsoft.AspNetCore.Server.Kestrel.Adapter; + +namespace Microsoft.AspNetCore.Server.Kestrel +{ + /// + /// Describes either an , Unix domain socket path, or a file descriptor for an already open + /// socket that Kestrel should bind to or open. + /// + public class ListenOptions + { + internal ListenOptions(IPEndPoint endPoint) + { + Type = ListenType.IPEndPoint; + IPEndPoint = endPoint; + } + + internal ListenOptions(string socketPath) + { + Type = ListenType.SocketPath; + SocketPath = socketPath; + } + + internal ListenOptions(ulong fileHandle) + { + Type = ListenType.FileHandle; + FileHandle = fileHandle; + } + + /// + /// The type of interface being described: either an , Unix domain socket path, or a file descriptor. + /// + public ListenType Type { get; } + + // IPEndPoint is mutable so port 0 can be updated to the bound port. + /// + /// The to bind to. + /// Only set if the is . + /// + public IPEndPoint IPEndPoint { get; internal set; } + + /// + /// The absolute path to a Unix domain socket to bind to. + /// Only set if the is . + /// + public string SocketPath { get; } + + /// + /// A file descriptor for the socket to open. + /// Only set if the is . + /// + public ulong FileHandle { get; } + + /// + /// Enables an to resolve and use services registered by the application during startup. + /// Only set if accessed from the callback of a Listen* method. + /// + public KestrelServerOptions KestrelServerOptions { get; internal set; } + + /// + /// Set to false to enable Nagle's algorithm for all connections. + /// + /// + /// Defaults to true. + /// + public bool NoDelay { get; set; } = true; + + /// + /// Gets the that allows each connection + /// to be intercepted and transformed. + /// Configured by the UseHttps() and + /// extension methods. + /// + /// + /// Defaults to empty. + /// + public List ConnectionAdapters { get; } = new List(); + + // PathBase and Scheme are hopefully only a temporary measure for back compat with IServerAddressesFeature. + // This allows a ListenOptions to describe all the information encoded in IWebHostBuilder.UseUrls. + internal string PathBase { get; set; } + internal string Scheme { get; set; } = "http"; + + public override string ToString() + { + // Use http scheme for all addresses. If https should be used for this endPoint, + // it can still be configured for this endPoint specifically. + switch (Type) + { + case ListenType.IPEndPoint: + return $"{Scheme}://{IPEndPoint}{PathBase}"; + case ListenType.SocketPath: + // ":" is used by ServerAddress to separate the socket path from PathBase. + return $"{Scheme}://unix:{SocketPath}:{PathBase}"; + case ListenType.FileHandle: + // This was never supported via --server.urls, so no need to include Scheme or PathBase. + return "http://"; + default: + throw new InvalidOperationException(); + } + } + } +} diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/ListenType.cs b/src/Microsoft.AspNetCore.Server.Kestrel/ListenType.cs new file mode 100644 index 0000000000..7ead1d91e0 --- /dev/null +++ b/src/Microsoft.AspNetCore.Server.Kestrel/ListenType.cs @@ -0,0 +1,15 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +namespace Microsoft.AspNetCore.Server.Kestrel +{ + /// + /// Enumerates the types. + /// + public enum ListenType + { + IPEndPoint, + SocketPath, + FileHandle + } +} diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/ServerAddress.cs b/src/Microsoft.AspNetCore.Server.Kestrel/ServerAddress.cs index 4771fe54f7..cfa0bff4e8 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/ServerAddress.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/ServerAddress.cs @@ -169,4 +169,4 @@ namespace Microsoft.AspNetCore.Server.Kestrel }; } } -} \ No newline at end of file +} diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Systemd/KesterlServerOptionsSystemdExtensions.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Systemd/KesterlServerOptionsSystemdExtensions.cs new file mode 100644 index 0000000000..ca24796a65 --- /dev/null +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Systemd/KesterlServerOptionsSystemdExtensions.cs @@ -0,0 +1,45 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Diagnostics; +using System.Globalization; +using Microsoft.AspNetCore.Server.Kestrel; + +namespace Microsoft.AspNetCore.Hosting +{ + public static class KesterlServerOptionsSystemdExtensions + { + // SD_LISTEN_FDS_START https://www.freedesktop.org/software/systemd/man/sd_listen_fds.html + private const ulong SdListenFdsStart = 3; + private const string ListenPidEnvVar = "LISTEN_PID"; + + /// + /// Open file descriptor (SD_LISTEN_FDS_START) initialized by systemd socket-based activation logic if available. + /// + /// + /// The . + /// + public static KestrelServerOptions UseSystemd(this KestrelServerOptions options) + { + return options.UseSystemd(_ => { }); + } + + /// + /// Open file descriptor (SD_LISTEN_FDS_START) initialized by systemd socket-based activation logic if available. + /// Specify callback to configure endpoint-specific settings. + /// + /// + /// The . + /// + public static KestrelServerOptions UseSystemd(this KestrelServerOptions options, Action configure) + { + if (string.Equals(Process.GetCurrentProcess().Id.ToString(CultureInfo.InvariantCulture), Environment.GetEnvironmentVariable(ListenPidEnvVar), StringComparison.Ordinal)) + { + options.ListenHandle(SdListenFdsStart, configure); + } + + return options; + } + } +} diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/exceptions.net45.json b/src/Microsoft.AspNetCore.Server.Kestrel/exceptions.net45.json new file mode 100644 index 0000000000..95752b8370 --- /dev/null +++ b/src/Microsoft.AspNetCore.Server.Kestrel/exceptions.net45.json @@ -0,0 +1,46 @@ +[ + { + "OldTypeId": "public static class Microsoft.AspNetCore.Hosting.KestrelServerOptionsConnectionLoggingExtensions", + "Kind": "Removal" + }, + { + "OldTypeId": "public class Microsoft.AspNetCore.Server.Kestrel.Filter.ConnectionFilterContext", + "Kind": "Removal" + }, + { + "OldTypeId": "public interface Microsoft.AspNetCore.Server.Kestrel.Filter.IConnectionFilter", + "Kind": "Removal" + }, + { + "OldTypeId": "public class Microsoft.AspNetCore.Server.Kestrel.Filter.LoggingConnectionFilter : Microsoft.AspNetCore.Server.Kestrel.Filter.IConnectionFilter", + "Kind": "Removal" + }, + { + "OldTypeId": "public class Microsoft.AspNetCore.Server.Kestrel.Filter.NoOpConnectionFilter : Microsoft.AspNetCore.Server.Kestrel.Filter.IConnectionFilter", + "Kind": "Removal" + }, + { + "OldTypeId": "public class Microsoft.AspNetCore.Server.Kestrel.KestrelServerOptions", + "OldMemberId": "public Microsoft.AspNetCore.Server.Kestrel.Filter.IConnectionFilter get_ConnectionFilter()", + "Kind": "Removal" + }, + { + "OldTypeId": "public class Microsoft.AspNetCore.Server.Kestrel.KestrelServerOptions", + "OldMemberId": "public System.Void set_ConnectionFilter(Microsoft.AspNetCore.Server.Kestrel.Filter.IConnectionFilter value)", + "Kind": "Removal" + }, + { + "OldTypeId": "public class Microsoft.AspNetCore.Server.Kestrel.KestrelServerOptions", + "OldMemberId": "public System.Boolean get_NoDelay()", + "NewTypeId": "public class Microsoft.AspNetCore.Server.Kestrel.ListenOptions", + "NewMemberId": "public System.Boolean get_NoDelay()", + "Kind": "Modification" + }, + { + "OldTypeId": "public class Microsoft.AspNetCore.Server.Kestrel.KestrelServerOptions", + "OldMemberId": "public System.Void set_NoDelay(System.Boolean value)", + "NewTypeId": "public class Microsoft.AspNetCore.Server.Kestrel.ListenOptions", + "NewMemberId": "public System.Void set_NoDelay(System.Boolean value)", + "Kind": "Modification" + } +] \ No newline at end of file diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/exceptions.netcore.json b/src/Microsoft.AspNetCore.Server.Kestrel/exceptions.netcore.json new file mode 100644 index 0000000000..95752b8370 --- /dev/null +++ b/src/Microsoft.AspNetCore.Server.Kestrel/exceptions.netcore.json @@ -0,0 +1,46 @@ +[ + { + "OldTypeId": "public static class Microsoft.AspNetCore.Hosting.KestrelServerOptionsConnectionLoggingExtensions", + "Kind": "Removal" + }, + { + "OldTypeId": "public class Microsoft.AspNetCore.Server.Kestrel.Filter.ConnectionFilterContext", + "Kind": "Removal" + }, + { + "OldTypeId": "public interface Microsoft.AspNetCore.Server.Kestrel.Filter.IConnectionFilter", + "Kind": "Removal" + }, + { + "OldTypeId": "public class Microsoft.AspNetCore.Server.Kestrel.Filter.LoggingConnectionFilter : Microsoft.AspNetCore.Server.Kestrel.Filter.IConnectionFilter", + "Kind": "Removal" + }, + { + "OldTypeId": "public class Microsoft.AspNetCore.Server.Kestrel.Filter.NoOpConnectionFilter : Microsoft.AspNetCore.Server.Kestrel.Filter.IConnectionFilter", + "Kind": "Removal" + }, + { + "OldTypeId": "public class Microsoft.AspNetCore.Server.Kestrel.KestrelServerOptions", + "OldMemberId": "public Microsoft.AspNetCore.Server.Kestrel.Filter.IConnectionFilter get_ConnectionFilter()", + "Kind": "Removal" + }, + { + "OldTypeId": "public class Microsoft.AspNetCore.Server.Kestrel.KestrelServerOptions", + "OldMemberId": "public System.Void set_ConnectionFilter(Microsoft.AspNetCore.Server.Kestrel.Filter.IConnectionFilter value)", + "Kind": "Removal" + }, + { + "OldTypeId": "public class Microsoft.AspNetCore.Server.Kestrel.KestrelServerOptions", + "OldMemberId": "public System.Boolean get_NoDelay()", + "NewTypeId": "public class Microsoft.AspNetCore.Server.Kestrel.ListenOptions", + "NewMemberId": "public System.Boolean get_NoDelay()", + "Kind": "Modification" + }, + { + "OldTypeId": "public class Microsoft.AspNetCore.Server.Kestrel.KestrelServerOptions", + "OldMemberId": "public System.Void set_NoDelay(System.Boolean value)", + "NewTypeId": "public class Microsoft.AspNetCore.Server.Kestrel.ListenOptions", + "NewMemberId": "public System.Void set_NoDelay(System.Boolean value)", + "Kind": "Modification" + } +] \ No newline at end of file diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/project.json b/src/Microsoft.AspNetCore.Server.Kestrel/project.json index 2e7d82d6bb..fc40afeee6 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/project.json +++ b/src/Microsoft.AspNetCore.Server.Kestrel/project.json @@ -37,6 +37,7 @@ }, "netstandard1.3": { "dependencies": { + "System.Diagnostics.Process": "4.4.0-*", "System.Threading.Thread": "4.4.0-*", "System.Threading.ThreadPool": "4.4.0-*" } diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs index e2513ece90..2b57c4d575 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs @@ -16,13 +16,14 @@ using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http.Extensions; using Microsoft.AspNetCore.Testing; using Microsoft.AspNetCore.Testing.xunit; +using Microsoft.Extensions.Options; using Xunit; namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { public class AddressRegistrationTests { - [Theory(Skip = "SslStream hanging on write after update to CoreFx 4.4 (https://github.com/dotnet/corefx/issues/14698)"), MemberData(nameof(AddressRegistrationDataIPv4))] + [Theory, MemberData(nameof(AddressRegistrationDataIPv4))] public async Task RegisterAddresses_IPv4_Success(string addressInput, Func testUrls) { await RegisterAddresses_Success(addressInput, testUrls); @@ -35,14 +36,22 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests await RegisterAddresses_Success(addressInput, testUrls); } - [ConditionalTheory(Skip = "SslStream hanging on write after update to CoreFx 4.4 (https://github.com/dotnet/corefx/issues/14698)"), MemberData(nameof(AddressRegistrationDataIPv4Port443))] - [PortSupportedCondition(443)] - public async Task RegisterAddresses_IPv4Port443_Success(string addressInput, Func testUrls) + [Theory(Skip = "SslStream hanging on write after update to CoreFx 4.4 (https://github.com/dotnet/corefx/issues/14698)"), MemberData(nameof(IPEndPointRegistrationDataRandomPort))] + [IPv6SupportedCondition] + public async Task RegisterIPEndPoint_RandomPort_Success(IPEndPoint endPoint, Func testUrl) { - await RegisterAddresses_Success(addressInput, testUrls); + await RegisterIPEndPoint_Success(endPoint, testUrl); } - [ConditionalTheory(Skip = "SslStream hanging on write after update to CoreFx 4.4 (https://github.com/dotnet/corefx/issues/14698)"), MemberData(nameof(AddressRegistrationDataIPv6))] + [ConditionalTheory(Skip = "SslStream hanging on write after update to CoreFx 4.4 (https://github.com/dotnet/corefx/issues/14698)"), MemberData(nameof(IPEndPointRegistrationDataPort443))] + [IPv6SupportedCondition] + [PortSupportedCondition(443)] + public async Task RegisterIPEndPoint_Port443_Success(IPEndPoint endpoint, Func testUrl) + { + await RegisterIPEndPoint_Success(endpoint, testUrl); + } + + [ConditionalTheory, MemberData(nameof(AddressRegistrationDataIPv6))] [IPv6SupportedCondition] public async Task RegisterAddresses_IPv6_Success(string addressInput, Func testUrls) { @@ -57,15 +66,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests await RegisterAddresses_Success(addressInput, testUrls); } - [ConditionalTheory(Skip = "SslStream hanging on write after update to CoreFx 4.4 (https://github.com/dotnet/corefx/issues/14698)"), MemberData(nameof(AddressRegistrationDataIPv6Port443))] - [IPv6SupportedCondition] - [PortSupportedCondition(443)] - public async Task RegisterAddresses_IPv6Port443_Success(string addressInput, Func testUrls) - { - await RegisterAddresses_Success(addressInput, testUrls); - } - - [ConditionalTheory(Skip = "SslStream hanging on write after update to CoreFx 4.4 (https://github.com/dotnet/corefx/issues/14698)"), MemberData(nameof(AddressRegistrationDataIPv6ScopeId))] + [ConditionalTheory, MemberData(nameof(AddressRegistrationDataIPv6ScopeId))] [IPv6SupportedCondition] public async Task RegisterAddresses_IPv6ScopeId_Success(string addressInput, Func testUrls) { @@ -75,10 +76,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests private async Task RegisterAddresses_Success(string addressInput, Func testUrls) { var hostBuilder = new WebHostBuilder() - .UseKestrel(options => - { - options.UseHttps(@"TestResources/testCert.pfx", "testPassword"); - }) + .UseKestrel() .UseUrls(addressInput) .Configure(ConfigureEchoAddress); @@ -97,6 +95,37 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } } + private async Task RegisterIPEndPoint_Success(IPEndPoint endPoint, Func testUrl) + { + var hostBuilder = new WebHostBuilder() + .UseKestrel(options => + { + options.Listen(endPoint, listenOptions => + { + if (testUrl(listenOptions.IPEndPoint).StartsWith("https")) + { + listenOptions.UseHttps("TestResources/testCert.pfx", "testPassword"); + } + }); + }) + .Configure(ConfigureEchoAddress); + + using (var host = hostBuilder.Build()) + { + host.Start(); + + var options = ((IOptions)host.Services.GetService(typeof(IOptions))).Value; + Assert.Single(options.ListenOptions); + var listenOptions = options.ListenOptions[0]; + + var response = await HttpClientSlim.GetStringAsync(testUrl(listenOptions.IPEndPoint), validateCertificate: false); + + // Compare the response with Uri.ToString(), rather than testUrl directly. + // Required to handle IPv6 addresses with zone index, like "fe80::3%1" + Assert.Equal(new Uri(testUrl(listenOptions.IPEndPoint)).ToString(), response); + } + } + [Fact] public void ThrowsWhenBindingToIPv4AddressInUse() { @@ -200,37 +229,73 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests dataset.Add(string.Empty, _ => new[] { "http://127.0.0.1:5000/" }); // Static ports - var port1 = GetNextPort(); - var port2 = GetNextPort(); + var port = GetNextPort(); // Loopback - dataset.Add($"http://127.0.0.1:{port1};https://127.0.0.1:{port2}", - _ => new[] { $"http://127.0.0.1:{port1}/", $"https://127.0.0.1:{port2}/" }); + dataset.Add($"http://127.0.0.1:{port}", _ => new[] { $"http://127.0.0.1:{port}/" }); // Localhost - dataset.Add($"http://localhost:{port1};https://localhost:{port2}", - _ => new[] { $"http://localhost:{port1}/", $"http://127.0.0.1:{port1}/", - $"https://localhost:{port2}/", $"https://127.0.0.1:{port2}/" }); + dataset.Add($"http://localhost:{port}", _ => new[] { $"http://localhost:{port}/", $"http://127.0.0.1:{port}/" }); // Any - dataset.Add($"http://*:{port1}/;https://*:{port2}/", - _ => new[] { $"http://127.0.0.1:{port1}/", $"https://127.0.0.1:{port2}/" }); - dataset.Add($"http://+:{port1}/;https://+:{port2}/", - _ => new[] { $"http://127.0.0.1:{port1}/", $"https://127.0.0.1:{port2}/" }); + dataset.Add($"http://*:{port}/", _ => new[] { $"http://127.0.0.1:{port}/" }); + dataset.Add($"http://+:{port}/", _ => new[] { $"http://127.0.0.1:{port}/" }); // Path after port - dataset.Add($"http://127.0.0.1:{port1}/base/path;https://127.0.0.1:{port2}/base/path", - _ => new[] { $"http://127.0.0.1:{port1}/base/path", $"https://127.0.0.1:{port2}/base/path" }); + dataset.Add($"http://127.0.0.1:{port}/base/path", _ => new[] { $"http://127.0.0.1:{port}/base/path" }); // Dynamic port and non-loopback addresses - dataset.Add("http://127.0.0.1:0/;https://127.0.0.1:0/", GetTestUrls); - dataset.Add($"http://{Dns.GetHostName()}:0/;https://{Dns.GetHostName()}:0/", GetTestUrls); + dataset.Add("http://127.0.0.1:0/", GetTestUrls); + dataset.Add($"http://{Dns.GetHostName()}:0/", GetTestUrls); var ipv4Addresses = GetIPAddresses() .Where(ip => ip.AddressFamily == AddressFamily.InterNetwork); foreach (var ip in ipv4Addresses) { - dataset.Add($"http://{ip}:0/;https://{ip}:0/", GetTestUrls); + dataset.Add($"http://{ip}:0/", GetTestUrls); + } + + return dataset; + } + } + + public static TheoryData> IPEndPointRegistrationDataRandomPort + { + get + { + var dataset = new TheoryData>(); + + // Static port + var port = GetNextPort(); + + // Loopback + dataset.Add(new IPEndPoint(IPAddress.Loopback, port), _ => $"http://127.0.0.1:{port}/"); + dataset.Add(new IPEndPoint(IPAddress.Loopback, port), _ => $"https://127.0.0.1:{port}/"); + + // IPv6 loopback + dataset.Add(new IPEndPoint(IPAddress.IPv6Loopback, port), _ => FixTestUrl($"http://[::1]:{port}/")); + dataset.Add(new IPEndPoint(IPAddress.IPv6Loopback, port), _ => FixTestUrl($"https://[::1]:{port}/")); + + // Any + dataset.Add(new IPEndPoint(IPAddress.Any, port), _ => $"http://127.0.0.1:{port}/"); + dataset.Add(new IPEndPoint(IPAddress.Any, port), _ => $"https://127.0.0.1:{port}/"); + + // IPv6 Any + dataset.Add(new IPEndPoint(IPAddress.IPv6Any, port), _ => $"http://127.0.0.1:{port}/"); + dataset.Add(new IPEndPoint(IPAddress.IPv6Any, port), _ => FixTestUrl($"http://[::1]:{port}/")); + dataset.Add(new IPEndPoint(IPAddress.IPv6Any, port), _ => $"https://127.0.0.1:{port}/"); + dataset.Add(new IPEndPoint(IPAddress.IPv6Any, port), _ => FixTestUrl($"https://[::1]:{port}/")); + + // Dynamic port + dataset.Add(new IPEndPoint(IPAddress.Loopback, 0), endPoint => $"http://127.0.0.1:{endPoint.Port}/"); + dataset.Add(new IPEndPoint(IPAddress.Loopback, 0), endPoint => $"https://127.0.0.1:{endPoint.Port}/"); + + var ipv4Addresses = GetIPAddresses() + .Where(ip => ip.AddressFamily == AddressFamily.InterNetwork); + foreach (var ip in ipv4Addresses) + { + dataset.Add(new IPEndPoint(ip, 0), endPoint => FixTestUrl($"http://{endPoint}/")); + dataset.Add(new IPEndPoint(ip, 0), endPoint => FixTestUrl($"https://{endPoint}/")); } return dataset; @@ -252,16 +317,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } } - public static TheoryData> AddressRegistrationDataIPv4Port443 + public static TheoryData> IPEndPointRegistrationDataPort443 { get { - var dataset = new TheoryData>(); + var dataset = new TheoryData>(); - // Default port for HTTPS (443) - dataset.Add("https://127.0.0.1", _ => new[] { "https://127.0.0.1/" }); - dataset.Add("https://localhost", _ => new[] { "https://127.0.0.1/" }); - dataset.Add("https://*", _ => new[] { "https://127.0.0.1/" }); + dataset.Add(new IPEndPoint(IPAddress.Loopback, 443), _ => "https://127.0.0.1/"); + dataset.Add(new IPEndPoint(IPAddress.IPv6Loopback, 443), _ => FixTestUrl("https://[::1]/")); + dataset.Add(new IPEndPoint(IPAddress.Any, 443), _ => "https://127.0.0.1/"); + dataset.Add(new IPEndPoint(IPAddress.IPv6Any, 443), _ => FixTestUrl("https://[::1]/")); return dataset; } @@ -278,34 +343,29 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests dataset.Add(string.Empty, _ => new[] { "http://127.0.0.1:5000/", "http://[::1]:5000/" }); // Static ports - var port1 = GetNextPort(); - var port2 = GetNextPort(); + var port = GetNextPort(); // Loopback - dataset.Add($"http://[::1]:{port1}/;https://[::1]:{port2}/", - _ => new[] { $"http://[::1]:{port1}/", $"https://[::1]:{port2}/" }); + dataset.Add($"http://[::1]:{port}/", + _ => new[] { $"http://[::1]:{port}/" }); // Localhost - dataset.Add($"http://localhost:{port1};https://localhost:{port2}", - _ => new[] { $"http://localhost:{port1}/", $"http://127.0.0.1:{port1}/", $"http://[::1]:{port1}/", - $"https://localhost:{port2}/", $"https://127.0.0.1:{port2}/", $"https://[::1]:{port2}/" }); + dataset.Add($"http://localhost:{port}", + _ => new[] { $"http://localhost:{port}/", $"http://127.0.0.1:{port}/", $"http://[::1]:{port}/" }); // Any - dataset.Add($"http://*:{port1}/;https://*:{port2}/", - _ => new[] { $"http://127.0.0.1:{port1}/", $"http://[::1]:{port1}/", - $"https://127.0.0.1:{port2}/", $"https://[::1]:{port2}/" }); - dataset.Add($"http://+:{port1}/;https://+:{port2}/", - _ => new[] { $"http://127.0.0.1:{port1}/", $"http://[::1]:{port1}/", - $"https://127.0.0.1:{port2}/", $"https://[::1]:{port2}/" }); + dataset.Add($"http://*:{port}/", + _ => new[] { $"http://127.0.0.1:{port}/", $"http://[::1]:{port}/" }); + dataset.Add($"http://+:{port}/", + _ => new[] { $"http://127.0.0.1:{port}/", $"http://[::1]:{port}/" }); // Explicit IPv4 and IPv6 on same port - dataset.Add($"http://127.0.0.1:{port1}/;http://[::1]:{port1}/;https://127.0.0.1:{port2}/;https://[::1]:{port2}/", - _ => new[] { $"http://127.0.0.1:{port1}/", $"http://[::1]:{port1}/", - $"https://127.0.0.1:{port2}/", $"https://[::1]:{port2}/" }); + dataset.Add($"http://127.0.0.1:{port}/;http://[::1]:{port}/", + _ => new[] { $"http://127.0.0.1:{port}/", $"http://[::1]:{port}/" }); // Path after port - dataset.Add($"http://[::1]:{port1}/base/path;https://[::1]:{port2}/base/path", - _ => new[] { $"http://[::1]:{port1}/base/path", $"https://[::1]:{port2}/base/path" }); + dataset.Add($"http://[::1]:{port}/base/path", + _ => new[] { $"http://[::1]:{port}/base/path" }); // Dynamic port and non-loopback addresses var ipv6Addresses = GetIPAddresses() @@ -313,7 +373,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests .Where(ip => ip.ScopeId == 0); foreach (var ip in ipv6Addresses) { - dataset.Add($"http://[{ip}]:0/;https://[{ip}]:0/", GetTestUrls); + dataset.Add($"http://[{ip}]:0/", GetTestUrls); } return dataset; @@ -335,21 +395,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } } - public static TheoryData> AddressRegistrationDataIPv6Port443 - { - get - { - var dataset = new TheoryData>(); - - // Default port for HTTPS (443) - dataset.Add("https://[::1]", _ => new[] { "https://[::1]/" }); - dataset.Add("https://localhost", _ => new[] { "https://127.0.0.1/", "https://[::1]/" }); - dataset.Add("https://*", _ => new[] { "https://[::1]/" }); - - return dataset; - } - } - public static TheoryData> AddressRegistrationDataIPv6ScopeId { get @@ -362,7 +407,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests .Where(ip => ip.ScopeId != 0); foreach (var ip in ipv6Addresses) { - dataset.Add($"http://[{ip}]:0/;https://[{ip}]:0/", GetTestUrls); + dataset.Add($"http://[{ip}]:0/", GetTestUrls); } return dataset; @@ -380,11 +425,24 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests private static string[] GetTestUrls(IServerAddressesFeature addressesFeature) { return addressesFeature.Addresses - .Select(a => a.Replace("://+", "://localhost")) - .Select(a => a.EndsWith("/") ? a : a + "/") + .Select(FixTestUrl) .ToArray(); } + private static string FixTestUrl(string url) + { + var fixedUrl = url.Replace("://+", "://localhost") + .Replace("0.0.0.0", Dns.GetHostName()) + .Replace("[::]", Dns.GetHostName()); + + if (!fixedUrl.EndsWith("/")) + { + fixedUrl = fixedUrl + "/"; + } + + return fixedUrl; + } + private void ConfigureEchoAddress(IApplicationBuilder app) { app.Run(context => diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/HttpClientSlimTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/HttpClientSlimTests.cs index 0f2caf96b9..ab8f3a5c02 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/HttpClientSlimTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/HttpClientSlimTests.cs @@ -4,6 +4,7 @@ using System; using System.IO; using System.Linq; +using System.Net; using System.Net.Http; using System.Text; using System.Threading.Tasks; @@ -31,7 +32,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { using (var host = StartHost(protocol: "https")) { - Assert.Equal("test", await HttpClientSlim.GetStringAsync(host.GetUri(), validateCertificate: false)); + Assert.Equal("test", await HttpClientSlim.GetStringAsync(host.GetUri(isHttps: true), validateCertificate: false)); } } @@ -59,7 +60,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests using (var host = StartHost(protocol: "https", handler: (context) => context.Request.Body.CopyToAsync(context.Response.Body))) { - Assert.Equal("test post", await HttpClientSlim.PostAsync(host.GetUri(), + Assert.Equal("test post", await HttpClientSlim.PostAsync(host.GetUri(isHttps: true), new StringContent("test post"), validateCertificate: false)); } } @@ -77,10 +78,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests private IWebHost StartHost(string protocol = "http", int statusCode = 200, Func handler = null) { var host = new WebHostBuilder() - .UseUrls($"{protocol}://127.0.0.1:0") .UseKestrel(options => { - options.UseHttps(@"TestResources/testCert.pfx", "testPassword"); + options.Listen(new IPEndPoint(IPAddress.Loopback, 0), listenOptions => + { + if (protocol == "https") + { + listenOptions.UseHttps("TestResources/testCert.pfx", "testPassword"); + } + }); }) .Configure((app) => { diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/HttpsTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/HttpsTests.cs index cffbd96ddd..85ed2e6fd6 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/HttpsTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/HttpsTests.cs @@ -30,9 +30,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests var hostBuilder = new WebHostBuilder() .UseKestrel(options => { - options.UseHttps(@"TestResources/testCert.pfx", "testPassword"); + options.Listen(new IPEndPoint(IPAddress.Loopback, 0), listenOptions => + { + listenOptions.UseHttps("TestResources/testCert.pfx", "testPassword"); + }); }) - .UseUrls("https://127.0.0.1:0/") .UseLoggerFactory(loggerFactory) .Configure(app => { }); @@ -61,9 +63,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests var hostBuilder = new WebHostBuilder() .UseKestrel(options => { - options.UseHttps(@"TestResources/testCert.pfx", "testPassword"); + options.Listen(new IPEndPoint(IPAddress.Loopback, 0), listenOptions => + { + listenOptions.UseHttps("TestResources/testCert.pfx", "testPassword"); + }); }) - .UseUrls("https://127.0.0.1:0/") .UseLoggerFactory(loggerFactory) .Configure(app => { }); @@ -90,12 +94,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [Fact(Skip = "SslStream hanging on write after update to CoreFx 4.4 (https://github.com/dotnet/corefx/issues/14698)")] public async Task DoesNotThrowObjectDisposedExceptionOnConnectionAbort() { - var x509Certificate2 = new X509Certificate2(@"TestResources/testCert.pfx", "testPassword"); + var x509Certificate2 = new X509Certificate2("TestResources/testCert.pfx", "testPassword"); var loggerFactory = new HandshakeErrorLoggerFactory(); var hostBuilder = new WebHostBuilder() .UseKestrel(options => { - options.UseHttps(@"TestResources/testCert.pfx", "testPassword"); + options.Listen(new IPEndPoint(IPAddress.Loopback, 0), listenOptions => + { + listenOptions.UseHttps("TestResources/testCert.pfx", "testPassword"); + }); }) .UseUrls("https://127.0.0.1:0/") .UseLoggerFactory(loggerFactory) @@ -141,14 +148,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests public async Task DoesNotThrowObjectDisposedExceptionFromWriteAsyncAfterConnectionIsAborted() { var tcs = new TaskCompletionSource(); - var x509Certificate2 = new X509Certificate2(@"TestResources/testCert.pfx", "testPassword"); + var x509Certificate2 = new X509Certificate2("TestResources/testCert.pfx", "testPassword"); var loggerFactory = new HandshakeErrorLoggerFactory(); var hostBuilder = new WebHostBuilder() .UseKestrel(options => { - options.UseHttps(@"TestResources/testCert.pfx", "testPassword"); + options.Listen(new IPEndPoint(IPAddress.Loopback, 0), listenOptions => + { + listenOptions.UseHttps("TestResources/testCert.pfx", "testPassword"); + }); }) - .UseUrls("https://127.0.0.1:0/") .UseLoggerFactory(loggerFactory) .Configure(app => app.Run(async httpContext => { @@ -194,9 +203,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests var hostBuilder = new WebHostBuilder() .UseKestrel(options => { - options.UseHttps(@"TestResources/testCert.pfx", "testPassword"); + options.Listen(new IPEndPoint(IPAddress.Loopback, 0), listenOptions => + { + listenOptions.UseHttps("TestResources/testCert.pfx", "testPassword"); + }); }) - .UseUrls("https://127.0.0.1:0/") .UseLoggerFactory(loggerFactory) .Configure(app => { }); @@ -221,7 +232,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests public ILogger CreateLogger(string categoryName) { - if (categoryName == nameof(HttpsConnectionFilter)) + if (categoryName == nameof(HttpsConnectionAdapter)) { return FilterLogger; } diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/IWebHostPortExtensions.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/IWebHostPortExtensions.cs index f2702be8f7..11e8f4fa0f 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/IWebHostPortExtensions.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/IWebHostPortExtensions.cs @@ -10,9 +10,9 @@ namespace Microsoft.AspNetCore.Hosting { public static class IWebHostPortExtensions { - public static string GetHost(this IWebHost host) + public static string GetHost(this IWebHost host, bool isHttps = false) { - return host.GetUri().Host; + return host.GetUri(isHttps).Host; } public static int GetPort(this IWebHost host) @@ -37,13 +37,29 @@ namespace Microsoft.AspNetCore.Hosting public static IEnumerable GetUris(this IWebHost host) { return host.ServerFeatures.Get().Addresses - .Select(a => a.Replace("://+", "://localhost")) .Select(a => new Uri(a)); } - public static Uri GetUri(this IWebHost host) + public static Uri GetUri(this IWebHost host, bool isHttps = false) { - return host.GetUris().First(); + var uri = host.GetUris().First(); + + if (isHttps && uri.Scheme == "http") + { + var uriBuilder = new UriBuilder(uri) + { + Scheme = "https", + }; + + if (uri.Port == 80) + { + uriBuilder.Port = 443; + } + + return uriBuilder.Uri; + } + + return uri; } } } diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/LoggingConnectionFilterTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/LoggingConnectionAdapterTests.cs similarity index 76% rename from test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/LoggingConnectionFilterTests.cs rename to test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/LoggingConnectionAdapterTests.cs index e1f091cb3e..6637baea9c 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/LoggingConnectionFilterTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/LoggingConnectionAdapterTests.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Net; using System.Threading.Tasks; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; @@ -11,18 +12,20 @@ using Xunit; namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { - public class LoggingConnectionFilterTests + public class LoggingConnectionAdapterTests { [Fact(Skip = "SslStream hanging on write after update to CoreFx 4.4 (https://github.com/dotnet/corefx/issues/14698)")] public async Task LoggingConnectionFilterCanBeAddedBeforeAndAfterHttpsFilter() { var host = new WebHostBuilder() - .UseUrls($"https://127.0.0.1:0") - .UseKestrel(options => - { - options.UseConnectionLogging(); - options.UseHttps(@"TestResources/testCert.pfx", "testPassword"); - }) + .UseKestrel(options => + { + options.Listen(new IPEndPoint(IPAddress.Loopback, 0), listenOptions => + { + listenOptions.UseConnectionLogging(); + listenOptions.UseHttps("TestResources/testCert.pfx", "testPassword"); + }); + }) .Configure(app => { app.Run(context => diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/MaxRequestBufferSizeTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/MaxRequestBufferSizeTests.cs index 00bece92ff..0fea1d1ee4 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/MaxRequestBufferSizeTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/MaxRequestBufferSizeTests.cs @@ -82,11 +82,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests var clientFinishedSendingRequestBody = new ManualResetEvent(false); var lastBytesWritten = DateTime.MaxValue; - using (var host = StartWebHost(maxRequestBufferSize, data, startReadingRequestBody, clientFinishedSendingRequestBody)) + using (var host = StartWebHost(maxRequestBufferSize, data, ssl, startReadingRequestBody, clientFinishedSendingRequestBody)) { - var port = host.GetPort(ssl ? "https" : "http"); + var port = host.GetPort(); using (var socket = CreateSocket(port)) - using (var stream = await CreateStreamAsync(socket, ssl, host.GetHost())) + using (var stream = await CreateStreamAsync(socket, ssl, host.GetHost(ssl))) { await WritePostRequestHeaders(stream, data.Length); @@ -161,14 +161,21 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } } - private static IWebHost StartWebHost(long? maxRequestBufferSize, byte[] expectedBody, ManualResetEvent startReadingRequestBody, + private static IWebHost StartWebHost(long? maxRequestBufferSize, byte[] expectedBody, bool useSsl, ManualResetEvent startReadingRequestBody, ManualResetEvent clientFinishedSendingRequestBody) { var host = new WebHostBuilder() .UseKestrel(options => { + options.Listen(new IPEndPoint(IPAddress.Loopback, 0), listenOptions => + { + if (useSsl) + { + listenOptions.UseHttps("TestResources/testCert.pfx", "testPassword"); + } + }); + options.Limits.MaxRequestBufferSize = maxRequestBufferSize; - options.UseHttps(@"TestResources/testCert.pfx", "testPassword"); if (maxRequestBufferSize.HasValue && maxRequestBufferSize.Value < options.Limits.MaxRequestLineSize) @@ -176,7 +183,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests options.Limits.MaxRequestLineSize = (int)maxRequestBufferSize; } }) - .UseUrls("http://127.0.0.1:0/", "https://127.0.0.1:0/") .UseContentRoot(Directory.GetCurrentDirectory()) .Configure(app => app.Run(async context => { diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs index 21bd934ff8..468b6ef9b4 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs @@ -287,7 +287,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests disposedTcs.TrySetResult(c.Response.StatusCode); }); - using (var server = new TestServer(handler, new TestServiceContext(), "http://127.0.0.1:0", mockHttpContextFactory.Object)) + using (var server = new TestServer(handler, new TestServiceContext(), mockHttpContextFactory.Object)) { if (!sendMalformedRequest) { diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/SystemdActivation/Dockerfile b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/SystemdActivation/Dockerfile new file mode 100644 index 0000000000..464f6a4ec0 --- /dev/null +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/SystemdActivation/Dockerfile @@ -0,0 +1,28 @@ +FROM microsoft/dotnet:1.1-runtime-deps + +# The "container" environment variable is read by systemd. +ENV container=docker + +# This is required by systemd and won't work without "dotnet run --privileged". +VOLUME ["/sys/fs/cgroup"] + +# Create activate-kestrel.service to launch the "publish" app on new requests to 8080. +EXPOSE 8080 +ADD .dotnet/ /usr/share/dotnet/ +ADD publish/ /publish/ +ADD activate-kestrel.socket /etc/systemd/system/activate-kestrel.socket +ADD activate-kestrel.service /etc/systemd/system/activate-kestrel.service + +# Install and configure systemd which requires dbus for graceful shutdown. +RUN ["apt-get", "-o", "Acquire::Check-Valid-Until=false", "update"] +RUN ["apt-get", "install", "-y", "dbus"] +RUN ["systemctl", "mask", "getty.target", "console-getty.service"] +RUN ["cp", "/lib/systemd/system/dbus.service", "/etc/systemd/system/"] +RUN ["sed", "-i", "s/OOMScoreAdjust=-900//", "/etc/systemd/system/dbus.service"] + +# Automatically start activate-kestrel.service on boot. +RUN ["ln", "-s", "/usr/share/dotnet/dotnet", "/usr/bin/dotnet"] +RUN ["ln", "-s", "/usr/lib/systemd/system/activate-kestrel.service", "/etc/systemd/system/multi-user.target.wants/activate-kestrel.service"] + +# Launch systemd. +CMD ["/sbin/init"] diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/SystemdActivation/activate-kestrel.service b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/SystemdActivation/activate-kestrel.service new file mode 100644 index 0000000000..392bf823cd --- /dev/null +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/SystemdActivation/activate-kestrel.service @@ -0,0 +1,8 @@ +[Unit] +Requires=activate-kestrel.socket + +[Service] +ExecStart=/usr/bin/dotnet SampleApp.dll +WorkingDirectory=/publish +NonBlocking=true + diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/SystemdActivation/activate-kestrel.socket b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/SystemdActivation/activate-kestrel.socket new file mode 100644 index 0000000000..1407c09f88 --- /dev/null +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/SystemdActivation/activate-kestrel.socket @@ -0,0 +1,7 @@ +[Unit] +Description=Kestrel Activation + +[Socket] +ListenStream=8080 +NoDelay=true + diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/SystemdActivation/docker.sh b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/SystemdActivation/docker.sh new file mode 100755 index 0000000000..b450ff3e54 --- /dev/null +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/SystemdActivation/docker.sh @@ -0,0 +1,21 @@ +#!/usr/bin/env bash + +set -e + +# Ensure that dotnet is added to the PATH. +# build.sh should always be run before this script to create the .build/ directory and restore packages. +scriptDir=$(dirname "${BASH_SOURCE[0]}") +repoDir=$(cd $scriptDir/../../.. && pwd) +source ./.build/KoreBuild.sh -r $repoDir --quiet + +dotnet publish -f netcoreapp1.1 ./samples/SampleApp/ +cp -R ./samples/SampleApp/bin/Debug/netcoreapp1.1/publish/ $scriptDir +cp -R ~/.dotnet/ $scriptDir + +image=$(docker build -qf $scriptDir/Dockerfile $scriptDir) +container=$(docker run -Ptd --privileged $image) + +# Try to connect to SampleApp once a second up to 10 times. +for i in {1..10}; do curl $(docker port $container 8080/tcp) && exit 0 || sleep 1; done + +exit -1 diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Writing.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Writing.cs index 07d8c9a3bc..39ac17d1c8 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Writing.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Writing.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Net; using System.Threading; using System.Threading.Tasks; using BenchmarkDotNet.Attributes; @@ -98,7 +99,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance }; var listenerContext = new ListenerContext(serviceContext) { - ServerAddress = ServerAddress.FromUrl("http://localhost:5000") + ListenOptions = new ListenOptions(new IPEndPoint(IPAddress.Loopback, 5000)) }; var connectionContext = new ConnectionContext(listenerContext) { diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedRequestTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedRequestTests.cs index 6fe3bc1d6d..29ea2ba050 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedRequestTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedRequestTests.cs @@ -4,9 +4,11 @@ using System.Collections.Generic; using System.IO; using System.Linq; +using System.Net; using System.Text; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Server.Kestrel; using Microsoft.AspNetCore.Server.KestrelTests.TestHelpers; using Microsoft.AspNetCore.Testing; using Microsoft.Extensions.Internal; @@ -16,21 +18,14 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { public class ChunkedRequestTests { - public static TheoryData ConnectionFilterData + public static TheoryData ConnectionAdapterData => new TheoryData { - get + new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0)), + new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0)) { - return new TheoryData - { - { - new TestServiceContext() - }, - { - new TestServiceContext(new PassThroughConnectionFilter()) - } - }; + ConnectionAdapters = { new PassThroughConnectionAdapter() } } - } + }; private async Task App(HttpContext httpContext) { @@ -61,10 +56,12 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } [Theory] - [MemberData(nameof(ConnectionFilterData))] - public async Task Http10TransferEncoding(TestServiceContext testContext) + [MemberData(nameof(ConnectionAdapterData))] + public async Task Http10TransferEncoding(ListenOptions listenOptions) { - using (var server = new TestServer(App, testContext)) + var testContext = new TestServiceContext(); + + using (var server = new TestServer(App, testContext, listenOptions)) { using (var connection = server.CreateConnection()) { @@ -88,10 +85,12 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } [Theory] - [MemberData(nameof(ConnectionFilterData))] - public async Task Http10KeepAliveTransferEncoding(TestServiceContext testContext) + [MemberData(nameof(ConnectionAdapterData))] + public async Task Http10KeepAliveTransferEncoding(ListenOptions listenOptions) { - using (var server = new TestServer(AppChunked, testContext)) + var testContext = new TestServiceContext(); + + using (var server = new TestServer(AppChunked, testContext, listenOptions)) { using (var connection = server.CreateConnection()) { @@ -127,9 +126,11 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } [Theory] - [MemberData(nameof(ConnectionFilterData))] - public async Task RequestBodyIsConsumedAutomaticallyIfAppDoesntConsumeItFully(TestServiceContext testContext) + [MemberData(nameof(ConnectionAdapterData))] + public async Task RequestBodyIsConsumedAutomaticallyIfAppDoesntConsumeItFully(ListenOptions listenOptions) { + var testContext = new TestServiceContext(); + using (var server = new TestServer(async httpContext => { var response = httpContext.Response; @@ -140,7 +141,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests response.Headers["Content-Length"] = new[] { "11" }; await response.Body.WriteAsync(Encoding.ASCII.GetBytes("Hello World"), 0, 11); - }, testContext)) + }, testContext, listenOptions)) { using (var connection = server.CreateConnection()) { @@ -177,9 +178,10 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } [Theory] - [MemberData(nameof(ConnectionFilterData))] - public async Task TrailingHeadersAreParsed(TestServiceContext testContext) + [MemberData(nameof(ConnectionAdapterData))] + public async Task TrailingHeadersAreParsed(ListenOptions listenOptions) { + var testContext = new TestServiceContext(); var requestCount = 10; var requestsReceived = 0; @@ -211,7 +213,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests response.Headers["Content-Length"] = new[] { "11" }; await response.Body.WriteAsync(Encoding.ASCII.GetBytes("Hello World"), 0, 11); - }, testContext)) + }, testContext, listenOptions)) { var response = string.Join("\r\n", new string[] { "HTTP/1.1 200 OK", @@ -262,13 +264,14 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } [Theory] - [MemberData(nameof(ConnectionFilterData))] - public async Task TrailingHeadersCountTowardsHeadersTotalSizeLimit(TestServiceContext testContext) + [MemberData(nameof(ConnectionAdapterData))] + public async Task TrailingHeadersCountTowardsHeadersTotalSizeLimit(ListenOptions listenOptions) { const string transferEncodingHeaderLine = "Transfer-Encoding: chunked"; const string headerLine = "Header: value"; const string trailingHeaderLine = "Trailing-Header: trailing-value"; + var testContext = new TestServiceContext(); testContext.ServerOptions.Limits.MaxRequestHeadersTotalSize = transferEncodingHeaderLine.Length + 2 + headerLine.Length + 2 + @@ -278,7 +281,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { var buffer = new byte[128]; while (await context.Request.Body.ReadAsync(buffer, 0, buffer.Length) != 0) ; // read to end - }, testContext)) + }, testContext, listenOptions)) { using (var connection = server.CreateConnection()) { @@ -305,20 +308,21 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } [Theory] - [MemberData(nameof(ConnectionFilterData))] - public async Task TrailingHeadersCountTowardsHeaderCountLimit(TestServiceContext testContext) + [MemberData(nameof(ConnectionAdapterData))] + public async Task TrailingHeadersCountTowardsHeaderCountLimit(ListenOptions listenOptions) { const string transferEncodingHeaderLine = "Transfer-Encoding: chunked"; const string headerLine = "Header: value"; const string trailingHeaderLine = "Trailing-Header: trailing-value"; + var testContext = new TestServiceContext(); testContext.ServerOptions.Limits.MaxRequestHeaderCount = 2; using (var server = new TestServer(async context => { var buffer = new byte[128]; while (await context.Request.Body.ReadAsync(buffer, 0, buffer.Length) != 0) ; // read to end - }, testContext)) + }, testContext, listenOptions)) { using (var connection = server.CreateConnection()) { @@ -345,9 +349,10 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } [Theory] - [MemberData(nameof(ConnectionFilterData))] - public async Task ExtensionsAreIgnored(TestServiceContext testContext) + [MemberData(nameof(ConnectionAdapterData))] + public async Task ExtensionsAreIgnored(ListenOptions listenOptions) { + var testContext = new TestServiceContext(); var requestCount = 10; var requestsReceived = 0; @@ -379,7 +384,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests response.Headers["Content-Length"] = new[] { "11" }; await response.Body.WriteAsync(Encoding.ASCII.GetBytes("Hello World"), 0, 11); - }, testContext)) + }, testContext, listenOptions)) { var response = string.Join("\r\n", new string[] { "HTTP/1.1 200 OK", @@ -430,9 +435,10 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } [Theory] - [MemberData(nameof(ConnectionFilterData))] - public async Task InvalidLengthResultsIn400(TestServiceContext testContext) + [MemberData(nameof(ConnectionAdapterData))] + public async Task InvalidLengthResultsIn400(ListenOptions listenOptions) { + var testContext = new TestServiceContext(); using (var server = new TestServer(async httpContext => { var response = httpContext.Response; @@ -448,7 +454,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests response.Headers["Content-Length"] = new[] { "11" }; await response.Body.WriteAsync(Encoding.ASCII.GetBytes("Hello World"), 0, 11); - }, testContext)) + }, testContext, listenOptions)) { using (var connection = server.CreateConnection()) { @@ -472,9 +478,10 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } [Theory] - [MemberData(nameof(ConnectionFilterData))] - public async Task InvalidSizedDataResultsIn400(TestServiceContext testContext) + [MemberData(nameof(ConnectionAdapterData))] + public async Task InvalidSizedDataResultsIn400(ListenOptions listenOptions) { + var testContext = new TestServiceContext(); using (var server = new TestServer(async httpContext => { var response = httpContext.Response; @@ -490,7 +497,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests response.Headers["Content-Length"] = new[] { "11" }; await response.Body.WriteAsync(Encoding.ASCII.GetBytes("Hello World"), 0, 11); - }, testContext)) + }, testContext, listenOptions)) { using (var connection = server.CreateConnection()) { @@ -516,13 +523,14 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [Theory] - [MemberData(nameof(ConnectionFilterData))] - public async Task ChunkedNotFinalTransferCodingResultsIn400(TestServiceContext testContext) + [MemberData(nameof(ConnectionAdapterData))] + public async Task ChunkedNotFinalTransferCodingResultsIn400(ListenOptions listenOptions) { + var testContext = new TestServiceContext(); using (var server = new TestServer(httpContext => { return TaskCache.CompletedTask; - }, testContext)) + }, testContext, listenOptions)) { using (var connection = server.CreateConnection()) { diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedResponseTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedResponseTests.cs index 9bbe7c88a7..ad35e4339a 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedResponseTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedResponseTests.cs @@ -2,10 +2,12 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Net; using System.Text; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Server.Kestrel; using Microsoft.AspNetCore.Server.KestrelTests.TestHelpers; using Microsoft.AspNetCore.Testing; using Xunit; @@ -14,32 +16,27 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { public class ChunkedResponseTests { - public static TheoryData ConnectionFilterData + public static TheoryData ConnectionAdapterData => new TheoryData { - get + new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0)), + new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0)) { - return new TheoryData - { - { - new TestServiceContext() - }, - { - new TestServiceContext(new PassThroughConnectionFilter()) - } - }; + ConnectionAdapters = { new PassThroughConnectionAdapter() } } - } + }; [Theory] - [MemberData(nameof(ConnectionFilterData))] - public async Task ResponsesAreChunkedAutomatically(TestServiceContext testContext) + [MemberData(nameof(ConnectionAdapterData))] + public async Task ResponsesAreChunkedAutomatically(ListenOptions listenOptions) { + var testContext = new TestServiceContext(); + using (var server = new TestServer(async httpContext => { var response = httpContext.Response; await response.Body.WriteAsync(Encoding.ASCII.GetBytes("Hello "), 0, 6); await response.Body.WriteAsync(Encoding.ASCII.GetBytes("World!"), 0, 6); - }, testContext)) + }, testContext, listenOptions)) { using (var connection = server.CreateConnection()) { @@ -64,14 +61,16 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } [Theory] - [MemberData(nameof(ConnectionFilterData))] - public async Task ResponsesAreNotChunkedAutomaticallyForHttp10Requests(TestServiceContext testContext) + [MemberData(nameof(ConnectionAdapterData))] + public async Task ResponsesAreNotChunkedAutomaticallyForHttp10Requests(ListenOptions listenOptions) { + var testContext = new TestServiceContext(); + using (var server = new TestServer(async httpContext => { await httpContext.Response.WriteAsync("Hello "); await httpContext.Response.WriteAsync("World!"); - }, testContext)) + }, testContext, listenOptions)) { using (var connection = server.CreateConnection()) { @@ -91,14 +90,16 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } [Theory] - [MemberData(nameof(ConnectionFilterData))] - public async Task ResponsesAreChunkedAutomaticallyForHttp11NonKeepAliveRequests(TestServiceContext testContext) + [MemberData(nameof(ConnectionAdapterData))] + public async Task ResponsesAreChunkedAutomaticallyForHttp11NonKeepAliveRequests(ListenOptions listenOptions) { + var testContext = new TestServiceContext(); + using (var server = new TestServer(async httpContext => { await httpContext.Response.WriteAsync("Hello "); await httpContext.Response.WriteAsync("World!"); - }, testContext)) + }, testContext, listenOptions)) { using (var connection = server.CreateConnection()) { @@ -125,15 +126,17 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } [Theory] - [MemberData(nameof(ConnectionFilterData))] - public async Task SettingConnectionCloseHeaderInAppDoesNotDisableChunking(TestServiceContext testContext) + [MemberData(nameof(ConnectionAdapterData))] + public async Task SettingConnectionCloseHeaderInAppDoesNotDisableChunking(ListenOptions listenOptions) { + var testContext = new TestServiceContext(); + using (var server = new TestServer(async httpContext => { httpContext.Response.Headers["Connection"] = "close"; await httpContext.Response.WriteAsync("Hello "); await httpContext.Response.WriteAsync("World!"); - }, testContext)) + }, testContext, listenOptions)) { using (var connection = server.CreateConnection()) { @@ -159,16 +162,18 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } [Theory] - [MemberData(nameof(ConnectionFilterData))] - public async Task ZeroLengthWritesAreIgnored(TestServiceContext testContext) + [MemberData(nameof(ConnectionAdapterData))] + public async Task ZeroLengthWritesAreIgnored(ListenOptions listenOptions) { + var testContext = new TestServiceContext(); + using (var server = new TestServer(async httpContext => { var response = httpContext.Response; await response.Body.WriteAsync(Encoding.ASCII.GetBytes("Hello "), 0, 6); await response.Body.WriteAsync(new byte[0], 0, 0); await response.Body.WriteAsync(Encoding.ASCII.GetBytes("World!"), 0, 6); - }, testContext)) + }, testContext, listenOptions)) { using (var connection = server.CreateConnection()) { @@ -193,9 +198,11 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } [Theory] - [MemberData(nameof(ConnectionFilterData))] - public async Task ZeroLengthWritesFlushHeaders(TestServiceContext testContext) + [MemberData(nameof(ConnectionAdapterData))] + public async Task ZeroLengthWritesFlushHeaders(ListenOptions listenOptions) { + var testContext = new TestServiceContext(); + var flushed = new SemaphoreSlim(0, 1); using (var server = new TestServer(async httpContext => @@ -206,7 +213,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests await flushed.WaitAsync(); await response.WriteAsync("Hello World!"); - }, testContext)) + }, testContext, listenOptions)) { using (var connection = server.CreateConnection()) { @@ -235,14 +242,16 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } [Theory] - [MemberData(nameof(ConnectionFilterData))] - public async Task EmptyResponseBodyHandledCorrectlyWithZeroLengthWrite(TestServiceContext testContext) + [MemberData(nameof(ConnectionAdapterData))] + public async Task EmptyResponseBodyHandledCorrectlyWithZeroLengthWrite(ListenOptions listenOptions) { + var testContext = new TestServiceContext(); + using (var server = new TestServer(async httpContext => { var response = httpContext.Response; await response.Body.WriteAsync(new byte[0], 0, 0); - }, testContext)) + }, testContext, listenOptions)) { using (var connection = server.CreateConnection()) { @@ -263,15 +272,17 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } [Theory] - [MemberData(nameof(ConnectionFilterData))] - public async Task ConnectionClosedIfExceptionThrownAfterWrite(TestServiceContext testContext) + [MemberData(nameof(ConnectionAdapterData))] + public async Task ConnectionClosedIfExceptionThrownAfterWrite(ListenOptions listenOptions) { + var testContext = new TestServiceContext(); + using (var server = new TestServer(async httpContext => { var response = httpContext.Response; await response.Body.WriteAsync(Encoding.ASCII.GetBytes("Hello World!"), 0, 12); throw new Exception(); - }, testContext)) + }, testContext, listenOptions)) { using (var connection = server.CreateConnection()) { @@ -294,15 +305,17 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } [Theory] - [MemberData(nameof(ConnectionFilterData))] - public async Task ConnectionClosedIfExceptionThrownAfterZeroLengthWrite(TestServiceContext testContext) + [MemberData(nameof(ConnectionAdapterData))] + public async Task ConnectionClosedIfExceptionThrownAfterZeroLengthWrite(ListenOptions listenOptions) { + var testContext = new TestServiceContext(); + using (var server = new TestServer(async httpContext => { var response = httpContext.Response; await response.Body.WriteAsync(new byte[0], 0, 0); throw new Exception(); - }, testContext)) + }, testContext, listenOptions)) { using (var connection = server.CreateConnection()) { @@ -324,9 +337,11 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } [Theory] - [MemberData(nameof(ConnectionFilterData))] - public async Task WritesAreFlushedPriorToResponseCompletion(TestServiceContext testContext) + [MemberData(nameof(ConnectionAdapterData))] + public async Task WritesAreFlushedPriorToResponseCompletion(ListenOptions listenOptions) { + var testContext = new TestServiceContext(); + var flushWh = new ManualResetEventSlim(); using (var server = new TestServer(async httpContext => @@ -338,7 +353,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests flushWh.Wait(); await response.Body.WriteAsync(Encoding.ASCII.GetBytes("World!"), 0, 6); - }, testContext)) + }, testContext, listenOptions)) { using (var connection = server.CreateConnection()) { @@ -368,9 +383,11 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } [Theory] - [MemberData(nameof(ConnectionFilterData))] - public async Task ChunksCanBeWrittenManually(TestServiceContext testContext) + [MemberData(nameof(ConnectionAdapterData))] + public async Task ChunksCanBeWrittenManually(ListenOptions listenOptions) { + var testContext = new TestServiceContext(); + using (var server = new TestServer(async httpContext => { var response = httpContext.Response; @@ -379,7 +396,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests await response.Body.WriteAsync(Encoding.ASCII.GetBytes("6\r\nHello \r\n"), 0, 11); await response.Body.WriteAsync(Encoding.ASCII.GetBytes("6\r\nWorld!\r\n"), 0, 11); await response.Body.WriteAsync(Encoding.ASCII.GetBytes("0\r\n\r\n"), 0, 5); - }, testContext)) + }, testContext, listenOptions)) { using (var connection = server.CreateConnection()) { diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionFilterTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionAdapterTests.cs similarity index 69% rename from test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionFilterTests.cs rename to test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionAdapterTests.cs index a27e8a40bd..81fb5629c2 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionFilterTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionAdapterTests.cs @@ -3,26 +3,34 @@ using System; using System.IO; +using System.Net; using System.Threading; using System.Threading.Tasks; -using Microsoft.AspNetCore.Server.Kestrel.Filter; +using Microsoft.AspNetCore.Http.Features; +using Microsoft.AspNetCore.Server.Kestrel; +using Microsoft.AspNetCore.Server.Kestrel.Adapter; +using Microsoft.AspNetCore.Server.KestrelTests.TestHelpers; using Microsoft.AspNetCore.Testing; -using Microsoft.Extensions.Internal; using Xunit; namespace Microsoft.AspNetCore.Server.KestrelTests { - public class ConnectionFilterTests + public class ConnectionAdapterTests { [Fact] - public async Task CanReadAndWriteWithRewritingConnectionFilter() + public async Task CanReadAndWriteWithRewritingConnectionAdapter() { - var filter = new RewritingConnectionFilter(); - var serviceContext = new TestServiceContext(filter); + var adapter = new RewritingConnectionAdapter(); + var listenOptions = new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0)) + { + ConnectionAdapters = { adapter } + }; + + var serviceContext = new TestServiceContext(); var sendString = "POST / HTTP/1.0\r\nContent-Length: 12\r\n\r\nHello World?"; - using (var server = new TestServer(TestApp.EchoApp, serviceContext)) + using (var server = new TestServer(TestApp.EchoApp, serviceContext, listenOptions)) { using (var connection = server.CreateConnection()) { @@ -37,15 +45,20 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } } - Assert.Equal(sendString.Length, filter.BytesRead); + Assert.Equal(sendString.Length, adapter.BytesRead); } [Fact] - public async Task CanReadAndWriteWithAsyncConnectionFilter() + public async Task CanReadAndWriteWithAsyncConnectionAdapter() { - var serviceContext = new TestServiceContext(new AsyncConnectionFilter()); + var listenOptions = new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0)) + { + ConnectionAdapters = { new AsyncConnectionAdapter() } + }; - using (var server = new TestServer(TestApp.EchoApp, serviceContext)) + var serviceContext = new TestServiceContext(); + + using (var server = new TestServer(TestApp.EchoApp, serviceContext, listenOptions)) { using (var connection = server.CreateConnection()) { @@ -65,15 +78,20 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } [Fact] - public async Task ThrowingSynchronousConnectionFilterDoesNotCrashServer() + public async Task ThrowingSynchronousConnectionAdapterDoesNotCrashServer() { - var serviceContext = new TestServiceContext(new ThrowingConnectionFilter()); + var listenOptions = new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0)) + { + ConnectionAdapters = { new ThrowingConnectionAdapter() } + }; - using (var server = new TestServer(TestApp.EchoApp, serviceContext)) + var serviceContext = new TestServiceContext(); + + using (var server = new TestServer(TestApp.EchoApp, serviceContext, listenOptions)) { using (var connection = server.CreateConnection()) { - // Will throw because the exception in the connection filter will close the connection. + // Will throw because the exception in the connection adapter will close the connection. await Assert.ThrowsAsync(async () => { await connection.Send( @@ -91,42 +109,50 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } } - private class RewritingConnectionFilter : IConnectionFilter + private class RewritingConnectionAdapter : IConnectionAdapter { private RewritingStream _rewritingStream; - public Task OnConnectionAsync(ConnectionFilterContext context) + public Task OnConnectionAsync(ConnectionAdapterContext context) { - _rewritingStream = new RewritingStream(context.Connection); - context.Connection = _rewritingStream; - return TaskCache.CompletedTask; + _rewritingStream = new RewritingStream(context.ConnectionStream); + return Task.FromResult(new AdaptedConnection(_rewritingStream)); } public int BytesRead => _rewritingStream.BytesRead; - } + } - private class AsyncConnectionFilter : IConnectionFilter + private class AsyncConnectionAdapter : IConnectionAdapter { - public async Task OnConnectionAsync(ConnectionFilterContext context) + public async Task OnConnectionAsync(ConnectionAdapterContext context) { - var oldConnection = context.Connection; - - // Set Connection to null to ensure it isn't used until the returned task completes. - context.Connection = null; await Task.Delay(100); - - context.Connection = new RewritingStream(oldConnection); + return new AdaptedConnection(new RewritingStream(context.ConnectionStream)); } } - private class ThrowingConnectionFilter : IConnectionFilter + private class ThrowingConnectionAdapter : IConnectionAdapter { - public Task OnConnectionAsync(ConnectionFilterContext context) + public Task OnConnectionAsync(ConnectionAdapterContext context) { throw new Exception(); } } + private class AdaptedConnection : IAdaptedConnection + { + public AdaptedConnection(Stream adaptedStream) + { + ConnectionStream = adaptedStream; + } + + public Stream ConnectionStream { get; } + + public void PrepareRequest(IFeatureCollection requestFeatures) + { + } + } + private class RewritingStream : Stream { private readonly Stream _innerStream; diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionTests.cs index 779cc60372..518bb721e5 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionTests.cs @@ -1,6 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System.Net; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; @@ -34,7 +35,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests }; var context = new ListenerContext(serviceContext) { - ServerAddress = ServerAddress.FromUrl("http://127.0.0.1:0"), + ListenOptions = new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0)), Thread = engine.Threads[0] }; diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/CreateIPEndpointTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/CreateIPEndpointTests.cs index 7a8742e864..a7bb17c55f 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/CreateIPEndpointTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/CreateIPEndpointTests.cs @@ -3,7 +3,6 @@ using System.Net; using Microsoft.AspNetCore.Server.Kestrel; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; using Xunit; namespace Microsoft.AspNetCore.Server.KestrelTests @@ -11,14 +10,13 @@ namespace Microsoft.AspNetCore.Server.KestrelTests public class CreateIPEndpointTests { [Theory] - [InlineData("localhost", "127.0.0.1")] // https://github.com/aspnet/KestrelHttpServer/issues/231 [InlineData("10.10.10.10", "10.10.10.10")] [InlineData("[::1]", "::1")] [InlineData("randomhost", "::")] // "::" is IPAddress.IPv6Any [InlineData("*", "::")] // "::" is IPAddress.IPv6Any public void CorrectIPEndpointsAreCreated(string host, string expectedAddress) { - var endpoint = UvTcpHandle.CreateIPEndpoint(ServerAddress.FromUrl($"http://{host}:5000/")); + var endpoint = KestrelServer.CreateIPEndPoint(ServerAddress.FromUrl($"http://{host}:5000/")); Assert.NotNull(endpoint); Assert.Equal(IPAddress.Parse(expectedAddress), endpoint.Address); Assert.Equal(5000, endpoint.Port); diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs index f6ea43495e..dff37141cb 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs @@ -5,6 +5,7 @@ using System; using System.Collections.Generic; using System.IO; using System.Linq; +using System.Net; using System.Net.Sockets; using System.Text; using System.Threading; @@ -14,6 +15,7 @@ using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Server.Kestrel; using Microsoft.AspNetCore.Server.Kestrel.Internal; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; using Microsoft.AspNetCore.Server.KestrelTests.TestHelpers; using Microsoft.AspNetCore.Testing; using Microsoft.Extensions.Internal; @@ -26,55 +28,47 @@ namespace Microsoft.AspNetCore.Server.KestrelTests /// public class EngineTests { - public static TheoryData ConnectionFilterData + public static TheoryData ConnectionAdapterData => new TheoryData { - get + new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0)), + new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0)) { - return new TheoryData - { - { - new TestServiceContext() - }, - { - new TestServiceContext(new PassThroughConnectionFilter()) - } - }; + ConnectionAdapters = { new PassThroughConnectionAdapter() } } - } + }; - [Theory] - [MemberData(nameof(ConnectionFilterData))] - public void EngineCanStartAndStop(TestServiceContext testContext) + [Fact] + public void EngineCanStartAndStop() { - var engine = new KestrelEngine(testContext); + var engine = new KestrelEngine(new TestServiceContext()); engine.Start(1); engine.Dispose(); } [Theory] - [MemberData(nameof(ConnectionFilterData))] - public void ListenerCanCreateAndDispose(TestServiceContext testContext) + [MemberData(nameof(ConnectionAdapterData))] + public void ListenerCanCreateAndDispose(ListenOptions listenOptions) { + var testContext = new TestServiceContext(); testContext.App = TestApp.EchoApp; var engine = new KestrelEngine(testContext); engine.Start(1); - var address = ServerAddress.FromUrl("http://127.0.0.1:0/"); - var started = engine.CreateServer(address); + var started = engine.CreateServer(listenOptions); started.Dispose(); engine.Dispose(); } [Theory] - [MemberData(nameof(ConnectionFilterData))] - public void ConnectionCanReadAndWrite(TestServiceContext testContext) + [MemberData(nameof(ConnectionAdapterData))] + public void ConnectionCanReadAndWrite(ListenOptions listenOptions) { + var testContext = new TestServiceContext(); testContext.App = TestApp.EchoApp; var engine = new KestrelEngine(testContext); engine.Start(1); - var address = ServerAddress.FromUrl("http://127.0.0.1:0/"); - var started = engine.CreateServer(address); + var started = engine.CreateServer(listenOptions); - var socket = TestConnection.CreateConnectedLoopbackSocket(address.Port); + var socket = TestConnection.CreateConnectedLoopbackSocket(listenOptions.IPEndPoint.Port); var data = "Hello World"; socket.Send(Encoding.ASCII.GetBytes($"POST / HTTP/1.0\r\nContent-Length: 11\r\n\r\n{data}")); var buffer = new byte[data.Length]; @@ -89,10 +83,12 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } [Theory] - [MemberData(nameof(ConnectionFilterData))] - public async Task Http10RequestReceivesHttp11Response(TestServiceContext testContext) + [MemberData(nameof(ConnectionAdapterData))] + public async Task Http10RequestReceivesHttp11Response(ListenOptions listenOptions) { - using (var server = new TestServer(TestApp.EchoApp, testContext)) + var testContext = new TestServiceContext(); + + using (var server = new TestServer(TestApp.EchoApp, testContext, listenOptions)) { using (var connection = server.CreateConnection()) { @@ -112,10 +108,12 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } [Theory] - [MemberData(nameof(ConnectionFilterData))] - public async Task Http11(TestServiceContext testContext) + [MemberData(nameof(ConnectionAdapterData))] + public async Task Http11(ListenOptions listenOptions) { - using (var server = new TestServer(TestApp.EchoAppChunked, testContext)) + var testContext = new TestServiceContext(); + + using (var server = new TestServer(TestApp.EchoAppChunked, testContext, listenOptions)) { using (var connection = server.CreateConnection()) { @@ -143,9 +141,10 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } [Theory] - [MemberData(nameof(ConnectionFilterData))] - public async Task HeadersAndStreamsAreReused(TestServiceContext testContext) + [MemberData(nameof(ConnectionAdapterData))] + public async Task HeadersAndStreamsAreReused(ListenOptions listenOptions) { + var testContext = new TestServiceContext(); var streamCount = 0; var requestHeadersCount = 0; var responseHeadersCount = 0; @@ -222,10 +221,12 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } [Theory] - [MemberData(nameof(ConnectionFilterData))] - public async Task Http10ContentLength(TestServiceContext testContext) + [MemberData(nameof(ConnectionAdapterData))] + public async Task Http10ContentLength(ListenOptions listenOptions) { - using (var server = new TestServer(TestApp.EchoApp, testContext)) + var testContext = new TestServiceContext(); + + using (var server = new TestServer(TestApp.EchoApp, testContext, listenOptions)) { using (var connection = server.CreateConnection()) { @@ -245,10 +246,12 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } [Theory] - [MemberData(nameof(ConnectionFilterData))] - public async Task Http10KeepAlive(TestServiceContext testContext) + [MemberData(nameof(ConnectionAdapterData))] + public async Task Http10KeepAlive(ListenOptions listenOptions) { - using (var server = new TestServer(TestApp.EchoAppChunked, testContext)) + var testContext = new TestServiceContext(); + + using (var server = new TestServer(TestApp.EchoAppChunked, testContext, listenOptions)) { using (var connection = server.CreateConnection()) { @@ -278,10 +281,12 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } [Theory] - [MemberData(nameof(ConnectionFilterData))] - public async Task Http10KeepAliveNotUsedIfResponseContentLengthNotSet(TestServiceContext testContext) + [MemberData(nameof(ConnectionAdapterData))] + public async Task Http10KeepAliveNotUsedIfResponseContentLengthNotSet(ListenOptions listenOptions) { - using (var server = new TestServer(TestApp.EchoApp, testContext)) + var testContext = new TestServiceContext(); + + using (var server = new TestServer(TestApp.EchoApp, testContext, listenOptions)) { using (var connection = server.CreateConnection()) { @@ -311,10 +316,12 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } [Theory] - [MemberData(nameof(ConnectionFilterData))] - public async Task Http10KeepAliveContentLength(TestServiceContext testContext) + [MemberData(nameof(ConnectionAdapterData))] + public async Task Http10KeepAliveContentLength(ListenOptions listenOptions) { - using (var server = new TestServer(TestApp.EchoAppChunked, testContext)) + var testContext = new TestServiceContext(); + + using (var server = new TestServer(TestApp.EchoAppChunked, testContext, listenOptions)) { using (var connection = server.CreateConnection()) { @@ -346,10 +353,12 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } [Theory] - [MemberData(nameof(ConnectionFilterData))] - public async Task Expect100ContinueForBody(TestServiceContext testContext) + [MemberData(nameof(ConnectionAdapterData))] + public async Task Expect100ContinueForBody(ListenOptions listenOptions) { - using (var server = new TestServer(TestApp.EchoAppChunked, testContext)) + var testContext = new TestServiceContext(); + + using (var server = new TestServer(TestApp.EchoAppChunked, testContext, listenOptions)) { using (var connection = server.CreateConnection()) { @@ -376,10 +385,12 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } [Theory] - [MemberData(nameof(ConnectionFilterData))] - public async Task DisconnectingClient(TestServiceContext testContext) + [MemberData(nameof(ConnectionAdapterData))] + public async Task DisconnectingClient(ListenOptions listenOptions) { - using (var server = new TestServer(TestApp.EchoApp, testContext)) + var testContext = new TestServiceContext(); + + using (var server = new TestServer(TestApp.EchoApp, testContext, listenOptions)) { var socket = TestConnection.CreateConnectedLoopbackSocket(server.Port); await Task.Delay(200); @@ -404,10 +415,12 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } [Theory] - [MemberData(nameof(ConnectionFilterData))] - public async Task ZeroContentLengthSetAutomaticallyAfterNoWrites(TestServiceContext testContext) + [MemberData(nameof(ConnectionAdapterData))] + public async Task ZeroContentLengthSetAutomaticallyAfterNoWrites(ListenOptions listenOptions) { - using (var server = new TestServer(TestApp.EmptyApp, testContext)) + var testContext = new TestServiceContext(); + + using (var server = new TestServer(TestApp.EmptyApp, testContext, listenOptions)) { using (var connection = server.CreateConnection()) { @@ -434,13 +447,15 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } [Theory] - [MemberData(nameof(ConnectionFilterData))] - public async Task ZeroContentLengthSetAutomaticallyForNonKeepAliveRequests(TestServiceContext testContext) + [MemberData(nameof(ConnectionAdapterData))] + public async Task ZeroContentLengthSetAutomaticallyForNonKeepAliveRequests(ListenOptions listenOptions) { + var testContext = new TestServiceContext(); + using (var server = new TestServer(async httpContext => { Assert.Equal(0, await httpContext.Request.Body.ReadAsync(new byte[1], 0, 1).TimeoutAfter(TimeSpan.FromSeconds(10))); - }, testContext)) + }, testContext, listenOptions)) { using (var connection = server.CreateConnection()) { @@ -476,10 +491,12 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } [Theory] - [MemberData(nameof(ConnectionFilterData))] - public async Task ZeroContentLengthNotSetAutomaticallyForHeadRequests(TestServiceContext testContext) + [MemberData(nameof(ConnectionAdapterData))] + public async Task ZeroContentLengthNotSetAutomaticallyForHeadRequests(ListenOptions listenOptions) { - using (var server = new TestServer(TestApp.EmptyApp, testContext)) + var testContext = new TestServiceContext(); + + using (var server = new TestServer(TestApp.EmptyApp, testContext, listenOptions)) { using (var connection = server.CreateConnection()) { @@ -497,9 +514,11 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } [Theory] - [MemberData(nameof(ConnectionFilterData))] - public async Task ZeroContentLengthNotSetAutomaticallyForCertainStatusCodes(TestServiceContext testContext) + [MemberData(nameof(ConnectionAdapterData))] + public async Task ZeroContentLengthNotSetAutomaticallyForCertainStatusCodes(ListenOptions listenOptions) { + var testContext = new TestServiceContext(); + using (var server = new TestServer(async httpContext => { var request = httpContext.Request; @@ -510,7 +529,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var statusString = await reader.ReadLineAsync(); response.StatusCode = int.Parse(statusString); } - }, testContext)) + }, testContext, listenOptions)) { using (var connection = server.CreateConnection()) { @@ -548,14 +567,16 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } [Theory] - [MemberData(nameof(ConnectionFilterData))] - public async Task ZeroContentLengthAssumedOnNonKeepAliveRequestsWithoutContentLengthOrTransferEncodingHeader(TestServiceContext testContext) + [MemberData(nameof(ConnectionAdapterData))] + public async Task ZeroContentLengthAssumedOnNonKeepAliveRequestsWithoutContentLengthOrTransferEncodingHeader(ListenOptions listenOptions) { + var testContext = new TestServiceContext(); + using (var server = new TestServer(async httpContext => { // This will hang if 0 content length is not assumed by the server Assert.Equal(0, await httpContext.Request.Body.ReadAsync(new byte[1], 0, 1).TimeoutAfter(TimeSpan.FromSeconds(10))); - }, testContext)) + }, testContext, listenOptions)) { using (var connection = server.CreateConnection()) { @@ -594,16 +615,18 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } [Theory] - [MemberData(nameof(ConnectionFilterData))] - public async Task ConnectionClosedAfter101Response(TestServiceContext testContext) + [MemberData(nameof(ConnectionAdapterData))] + public async Task ConnectionClosedAfter101Response(ListenOptions listenOptions) { + var testContext = new TestServiceContext(); + using (var server = new TestServer(async httpContext => { var request = httpContext.Request; var stream = await httpContext.Features.Get().UpgradeAsync(); var response = Encoding.ASCII.GetBytes("hello, world"); await stream.WriteAsync(response, 0, response.Length); - }, testContext)) + }, testContext, listenOptions)) { using (var connection = server.CreateConnection()) { @@ -637,9 +660,11 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } [Theory] - [MemberData(nameof(ConnectionFilterData))] - public async Task ThrowingResultsIn500Response(TestServiceContext testContext) + [MemberData(nameof(ConnectionAdapterData))] + public async Task ThrowingResultsIn500Response(ListenOptions listenOptions) { + var testContext = new TestServiceContext(); + bool onStartingCalled = false; var testLogger = new TestApplicationErrorLogger(); @@ -657,7 +682,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests // Anything added to the ResponseHeaders dictionary is ignored response.Headers["Content-Length"] = "11"; throw new Exception(); - }, testContext)) + }, testContext, listenOptions)) { using (var connection = server.CreateConnection()) { @@ -687,9 +712,11 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } [Theory] - [MemberData(nameof(ConnectionFilterData))] - public async Task ThrowingAfterWritingKillsConnection(TestServiceContext testContext) + [MemberData(nameof(ConnectionAdapterData))] + public async Task ThrowingAfterWritingKillsConnection(ListenOptions listenOptions) { + var testContext = new TestServiceContext(); + bool onStartingCalled = false; var testLogger = new TestApplicationErrorLogger(); @@ -707,7 +734,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests response.Headers["Content-Length"] = new[] { "11" }; await response.Body.WriteAsync(Encoding.ASCII.GetBytes("Hello World"), 0, 11); throw new Exception(); - }, testContext)) + }, testContext, listenOptions)) { using (var connection = server.CreateConnection()) { @@ -729,9 +756,11 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } [Theory] - [MemberData(nameof(ConnectionFilterData))] - public async Task ThrowingAfterPartialWriteKillsConnection(TestServiceContext testContext) + [MemberData(nameof(ConnectionAdapterData))] + public async Task ThrowingAfterPartialWriteKillsConnection(ListenOptions listenOptions) { + var testContext = new TestServiceContext(); + bool onStartingCalled = false; var testLogger = new TestApplicationErrorLogger(); @@ -749,7 +778,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests response.Headers["Content-Length"] = new[] { "11" }; await response.Body.WriteAsync(Encoding.ASCII.GetBytes("Hello"), 0, 5); throw new Exception(); - }, testContext)) + }, testContext, listenOptions)) { using (var connection = server.CreateConnection()) { @@ -770,10 +799,12 @@ namespace Microsoft.AspNetCore.Server.KestrelTests Assert.Equal(1, testLogger.ApplicationErrorsLogged); } - [MemberData(nameof(ConnectionFilterData))] - public async Task ConnectionClosesWhenFinReceivedBeforeRequestCompletes(TestServiceContext testContext) + [MemberData(nameof(ConnectionAdapterData))] + public async Task ConnectionClosesWhenFinReceivedBeforeRequestCompletes(ListenOptions listenOptions) { - using (var server = new TestServer(TestApp.EchoAppChunked, testContext)) + var testContext = new TestServiceContext(); + + using (var server = new TestServer(TestApp.EchoAppChunked, testContext, listenOptions)) { using (var connection = server.CreateConnection()) { @@ -819,9 +850,11 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } [Theory] - [MemberData(nameof(ConnectionFilterData))] - public async Task ThrowingInOnStartingResultsInFailedWritesAnd500Response(TestServiceContext testContext) + [MemberData(nameof(ConnectionAdapterData))] + public async Task ThrowingInOnStartingResultsInFailedWritesAnd500Response(ListenOptions listenOptions) { + var testContext = new TestServiceContext(); + var onStartingCallCount1 = 0; var onStartingCallCount2 = 0; var failedWriteCount = 0; @@ -853,7 +886,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests Assert.Same(onStartingException, writeException.InnerException); failedWriteCount++; - }, testContext)) + }, testContext, listenOptions)) { using (var connection = server.CreateConnection()) { @@ -884,9 +917,11 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } [Theory] - [MemberData(nameof(ConnectionFilterData))] - public async Task ThrowingInOnCompletedIsLoggedAndClosesConnection(TestServiceContext testContext) + [MemberData(nameof(ConnectionAdapterData))] + public async Task ThrowingInOnCompletedIsLoggedAndClosesConnection(ListenOptions listenOptions) { + var testContext = new TestServiceContext(); + var onCompletedCalled1 = false; var onCompletedCalled2 = false; @@ -910,7 +945,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests response.Headers["Content-Length"] = new[] { "11" }; await response.Body.WriteAsync(Encoding.ASCII.GetBytes("Hello World"), 0, 11); - }, testContext)) + }, testContext, listenOptions)) { using (var connection = server.CreateConnection()) { @@ -934,9 +969,11 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } [Theory] - [MemberData(nameof(ConnectionFilterData))] - public async Task RequestsCanBeAbortedMidRead(TestServiceContext testContext) + [MemberData(nameof(ConnectionAdapterData))] + public async Task RequestsCanBeAbortedMidRead(ListenOptions listenOptions) { + var testContext = new TestServiceContext(); + var readTcs = new TaskCompletionSource(); var registrationTcs = new TaskCompletionSource(); var requestId = 0; @@ -975,7 +1012,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests readTcs.SetException(new Exception("This shouldn't be reached.")); } - }, testContext)) + }, testContext, listenOptions)) { using (var connection = server.CreateConnection()) { @@ -1005,9 +1042,11 @@ namespace Microsoft.AspNetCore.Server.KestrelTests Assert.Equal(2, abortedRequestId); } - [MemberData(nameof(ConnectionFilterData))] - public async Task FailedWritesResultInAbortedRequest(TestServiceContext testContext) + [MemberData(nameof(ConnectionAdapterData))] + public async Task FailedWritesResultInAbortedRequest(ListenOptions listenOptions) { + var testContext = new TestServiceContext(); + // This should match _maxBytesPreCompleted in SocketOutput var maxBytesPreCompleted = 65536; // Ensure string is long enough to disable write-behind buffering @@ -1044,7 +1083,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } writeTcs.SetException(new Exception("This shouldn't be reached.")); - }, testContext)) + }, testContext, listenOptions)) { using (var connection = server.CreateConnection()) { @@ -1066,9 +1105,11 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } [Theory] - [MemberData(nameof(ConnectionFilterData))] - public async Task NoErrorsLoggedWhenServerEndsConnectionBeforeClient(TestServiceContext testContext) + [MemberData(nameof(ConnectionAdapterData))] + public async Task NoErrorsLoggedWhenServerEndsConnectionBeforeClient(ListenOptions listenOptions) { + var testContext = new TestServiceContext(); + var testLogger = new TestApplicationErrorLogger(); testContext.Log = new KestrelTrace(testLogger); @@ -1077,7 +1118,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var response = httpContext.Response; response.Headers["Content-Length"] = new[] { "11" }; await response.Body.WriteAsync(Encoding.ASCII.GetBytes("Hello World"), 0, 11); - }, testContext)) + }, testContext, listenOptions)) { using (var connection = server.CreateConnection()) { @@ -1099,14 +1140,16 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } [Theory] - [MemberData(nameof(ConnectionFilterData))] - public async Task NoResponseSentWhenConnectionIsClosedByServerBeforeClientFinishesSendingRequest(TestServiceContext testContext) + [MemberData(nameof(ConnectionAdapterData))] + public async Task NoResponseSentWhenConnectionIsClosedByServerBeforeClientFinishesSendingRequest(ListenOptions listenOptions) { + var testContext = new TestServiceContext(); + using (var server = new TestServer(httpContext => { httpContext.Abort(); return TaskCache.CompletedTask; - }, testContext)) + }, testContext, listenOptions)) { using (var connection = server.CreateConnection()) { @@ -1121,9 +1164,11 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } [Theory] - [MemberData(nameof(ConnectionFilterData))] - public async Task RequestHeadersAreResetOnEachRequest(TestServiceContext testContext) + [MemberData(nameof(ConnectionAdapterData))] + public async Task RequestHeadersAreResetOnEachRequest(ListenOptions listenOptions) { + var testContext = new TestServiceContext(); + IHeaderDictionary originalRequestHeaders = null; var firstRequest = true; @@ -1143,7 +1188,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } return TaskCache.CompletedTask; - }, testContext)) + }, testContext, listenOptions)) { using (var connection = server.CreateConnection()) { @@ -1168,9 +1213,11 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } [Theory] - [MemberData(nameof(ConnectionFilterData))] - public async Task ResponseHeadersAreResetOnEachRequest(TestServiceContext testContext) + [MemberData(nameof(ConnectionAdapterData))] + public async Task ResponseHeadersAreResetOnEachRequest(ListenOptions listenOptions) { + var testContext = new TestServiceContext(); + IHeaderDictionary originalResponseHeaders = null; var firstRequest = true; @@ -1190,7 +1237,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } return TaskCache.CompletedTask; - }, testContext)) + }, testContext, listenOptions)) { using (var connection = server.CreateConnection()) { @@ -1243,11 +1290,13 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } [Theory] - [MemberData(nameof(ConnectionFilterData))] - public async Task OnStartingCallbacksAreCalledInLastInFirstOutOrder(TestServiceContext testContext) + [MemberData(nameof(ConnectionAdapterData))] + public async Task OnStartingCallbacksAreCalledInLastInFirstOutOrder(ListenOptions listenOptions) { const string response = "hello, world"; + var testContext = new TestServiceContext(); + var callOrder = new Stack(); var onStartingTcs = new TaskCompletionSource(); @@ -1267,7 +1316,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests context.Response.ContentLength = response.Length; await context.Response.WriteAsync(response); - }, testContext)) + }, testContext, listenOptions)) { using (var connection = server.CreateConnection()) { @@ -1292,11 +1341,13 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } [Theory] - [MemberData(nameof(ConnectionFilterData))] - public async Task OnCompletedCallbacksAreCalledInLastInFirstOutOrder(TestServiceContext testContext) + [MemberData(nameof(ConnectionAdapterData))] + public async Task OnCompletedCallbacksAreCalledInLastInFirstOutOrder(ListenOptions listenOptions) { const string response = "hello, world"; + var testContext = new TestServiceContext(); + var callOrder = new Stack(); var onCompletedTcs = new TaskCompletionSource(); @@ -1316,7 +1367,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests context.Response.ContentLength = response.Length; await context.Response.WriteAsync(response); - }, testContext)) + }, testContext, listenOptions)) { using (var connection = server.CreateConnection()) { @@ -1341,11 +1392,13 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } [Theory] - [MemberData(nameof(ConnectionFilterData))] - public async Task UpgradeRequestIsNotKeptAliveOrChunked(TestServiceContext testContext) + [MemberData(nameof(ConnectionAdapterData))] + public async Task UpgradeRequestIsNotKeptAliveOrChunked(ListenOptions listenOptions) { const string message = "Hello World"; + var testContext = new TestServiceContext(); + using (var server = new TestServer(async context => { var upgradeFeature = context.Features.Get(); @@ -1359,7 +1412,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } await duplexStream.WriteAsync(buffer, 0, read); - }, testContext)) + }, testContext, listenOptions)) { using (var connection = server.CreateConnection()) { diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameResponseHeadersTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameResponseHeadersTests.cs index bc76f2c09f..55ec8ee48b 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameResponseHeadersTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameResponseHeadersTests.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using System.Globalization; +using System.Net; using System.Text; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Server.Kestrel; @@ -28,7 +29,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests }; var listenerContext = new ListenerContext(serviceContext) { - ServerAddress = ServerAddress.FromUrl("http://localhost:5000") + ListenOptions = new ListenOptions(new IPEndPoint(IPAddress.Loopback, 5000)) }; var connectionContext = new ConnectionContext(listenerContext); diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs index 318061b832..5bf5fabb26 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs @@ -3,6 +3,7 @@ using System; using System.IO; +using System.Net; using System.Text; using System.Threading; using System.Threading.Tasks; @@ -55,7 +56,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests }; var listenerContext = new ListenerContext(_serviceContext) { - ServerAddress = ServerAddress.FromUrl("http://localhost:5000") + ListenOptions = new ListenOptions(new IPEndPoint(IPAddress.Loopback, 5000)) }; _connectionContext = new ConnectionContext(listenerContext) { @@ -440,7 +441,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests public void InitializeStreamsResetsStreams() { // Arrange - var messageBody = MessageBody.For(HttpVersion.Http11, (FrameRequestHeaders)_frame.RequestHeaders, _frame); + var messageBody = MessageBody.For(Kestrel.Internal.Http.HttpVersion.Http11, (FrameRequestHeaders)_frame.RequestHeaders, _frame); _frame.InitializeStreams(messageBody); var originalRequestBody = _frame.RequestBody; diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/HttpsConnectionFilterTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/HttpsConnectionAdapterTests.cs similarity index 65% rename from test/Microsoft.AspNetCore.Server.KestrelTests/HttpsConnectionFilterTests.cs rename to test/Microsoft.AspNetCore.Server.KestrelTests/HttpsConnectionAdapterTests.cs index 148260cf21..d37027adc6 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/HttpsConnectionFilterTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/HttpsConnectionAdapterTests.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using System.IO; +using System.Net; using System.Net.Http; using System.Net.Security; using System.Net.Sockets; @@ -13,33 +14,33 @@ using System.Text; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http.Features; -using Microsoft.AspNetCore.Server.Kestrel.Filter; +using Microsoft.AspNetCore.Server.Kestrel; using Microsoft.AspNetCore.Server.Kestrel.Https; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.AspNetCore.Testing; using Microsoft.Extensions.Internal; -using Microsoft.Extensions.Logging; -using Moq; using Xunit; namespace Microsoft.AspNetCore.Server.KestrelTests { - public class HttpsConnectionFilterTests + public class HttpsConnectionAdapterTests { - private static string _serverAddress = "https://127.0.0.1:0/"; - private static X509Certificate2 _x509Certificate2 = new X509Certificate2(@"TestResources/testCert.pfx", "testPassword"); + private static X509Certificate2 _x509Certificate2 = new X509Certificate2("TestResources/testCert.pfx", "testPassword"); // https://github.com/aspnet/KestrelHttpServer/issues/240 // This test currently fails on mono because of an issue with SslStream. [Fact(Skip = "SslStream hanging on write after update to CoreFx 4.4 (https://github.com/dotnet/corefx/issues/14698)")] - public async Task CanReadAndWriteWithHttpsConnectionFilter() + public async Task CanReadAndWriteWithHttpsConnectionAdapter() { - var serviceContext = new TestServiceContext(new HttpsConnectionFilter( - new HttpsConnectionFilterOptions { ServerCertificate = _x509Certificate2 }, - new NoOpConnectionFilter()) - ); + var serviceContext = new TestServiceContext(); + var listenOptions = new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0)) + { + ConnectionAdapters = + { + new HttpsConnectionAdapter(new HttpsConnectionAdapterOptions { ServerCertificate = _x509Certificate2 }) + } + }; - using (var server = new TestServer(App, serviceContext, _serverAddress)) + using (var server = new TestServer(App, serviceContext, listenOptions)) { var result = await HttpClientSlim.PostAsync($"https://localhost:{server.Port}/", new FormUrlEncodedContent(new[] { @@ -54,16 +55,21 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [Fact(Skip = "SslStream hanging on write after update to CoreFx 4.4 (https://github.com/dotnet/corefx/issues/14698)")] public async Task RequireCertificateFailsWhenNoCertificate() { - var serviceContext = new TestServiceContext(new HttpsConnectionFilter( - new HttpsConnectionFilterOptions + var serviceContext = new TestServiceContext(); + var listenOptions = new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0)) + { + ConnectionAdapters = + { + new HttpsConnectionAdapter(new HttpsConnectionAdapterOptions { ServerCertificate = _x509Certificate2, ClientCertificateMode = ClientCertificateMode.RequireCertificate - }, - new NoOpConnectionFilter()) - ); + }) + } + }; - using (var server = new TestServer(App, serviceContext, _serverAddress)) + + using (var server = new TestServer(App, serviceContext, listenOptions)) { await Assert.ThrowsAnyAsync( () => HttpClientSlim.GetStringAsync($"https://localhost:{server.Port}/")); @@ -73,21 +79,25 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [Fact(Skip = "SslStream hanging on write after update to CoreFx 4.4 (https://github.com/dotnet/corefx/issues/14698)")] public async Task AllowCertificateContinuesWhenNoCertificate() { - var serviceContext = new TestServiceContext(new HttpsConnectionFilter( - new HttpsConnectionFilterOptions + var serviceContext = new TestServiceContext(); + var listenOptions = new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0)) + { + ConnectionAdapters = { - ServerCertificate = _x509Certificate2, - ClientCertificateMode = ClientCertificateMode.AllowCertificate - }, - new NoOpConnectionFilter()) - ); + new HttpsConnectionAdapter(new HttpsConnectionAdapterOptions + { + ServerCertificate = _x509Certificate2, + ClientCertificateMode = ClientCertificateMode.AllowCertificate + }) + } + }; using (var server = new TestServer(context => { Assert.Equal(context.Features.Get(), null); return context.Response.WriteAsync("hello world"); }, - serviceContext, _serverAddress)) + serviceContext, listenOptions)) { var result = await HttpClientSlim.GetStringAsync($"https://localhost:{server.Port}/", validateCertificate: false); Assert.Equal("hello world", result); @@ -97,24 +107,24 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [Fact] public void ThrowsWhenNoServerCertificateIsProvided() { - Assert.Throws(() => new HttpsConnectionFilter( - new HttpsConnectionFilterOptions(), - new NoOpConnectionFilter()) + Assert.Throws(() => new HttpsConnectionAdapter( + new HttpsConnectionAdapterOptions()) ); } [Fact] public async Task UsesProvidedServerCertificate() { - var serviceContext = new TestServiceContext(new HttpsConnectionFilter( - new HttpsConnectionFilterOptions + var serviceContext = new TestServiceContext(); + var listenOptions = new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0)) + { + ConnectionAdapters = { - ServerCertificate = _x509Certificate2 - }, - new NoOpConnectionFilter()) - ); + new HttpsConnectionAdapter(new HttpsConnectionAdapterOptions { ServerCertificate = _x509Certificate2 }) + } + }; - using (var server = new TestServer(context => TaskCache.CompletedTask, serviceContext, _serverAddress)) + using (var server = new TestServer(context => TaskCache.CompletedTask, serviceContext, listenOptions)) { using (var client = new TcpClient()) { @@ -132,15 +142,19 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [Fact(Skip = "SslStream hanging on write after update to CoreFx 4.4 (https://github.com/dotnet/corefx/issues/14698)")] public async Task CertificatePassedToHttpContext() { - var serviceContext = new TestServiceContext(new HttpsConnectionFilter( - new HttpsConnectionFilterOptions + var serviceContext = new TestServiceContext(); + var listenOptions = new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0)) + { + ConnectionAdapters = { - ServerCertificate = _x509Certificate2, - ClientCertificateMode = ClientCertificateMode.RequireCertificate, - ClientCertificateValidation = (certificate, chain, sslPolicyErrors) => true - }, - new NoOpConnectionFilter()) - ); + new HttpsConnectionAdapter(new HttpsConnectionAdapterOptions + { + ServerCertificate = _x509Certificate2, + ClientCertificateMode = ClientCertificateMode.RequireCertificate, + ClientCertificateValidation = (certificate, chain, sslPolicyErrors) => true + }) + } + }; using (var server = new TestServer(context => { @@ -150,7 +164,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests Assert.NotNull(context.Connection.ClientCertificate); return context.Response.WriteAsync("hello world"); }, - serviceContext, _serverAddress)) + serviceContext, listenOptions)) { using (var client = new TcpClient()) { @@ -167,16 +181,16 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [Fact(Skip = "SslStream hanging on write after update to CoreFx 4.4 (https://github.com/dotnet/corefx/issues/14698)")] public async Task HttpsSchemePassedToRequestFeature() { - var serviceContext = new TestServiceContext( - new HttpsConnectionFilter( - new HttpsConnectionFilterOptions - { - ServerCertificate = _x509Certificate2 - }, - new NoOpConnectionFilter()) - ); + var listenOptions = new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0)) + { + ConnectionAdapters = + { + new HttpsConnectionAdapter(new HttpsConnectionAdapterOptions { ServerCertificate = _x509Certificate2 }) + } + }; + var serviceContext = new TestServiceContext(); - using (var server = new TestServer(context => context.Response.WriteAsync(context.Request.Scheme), serviceContext, _serverAddress)) + using (var server = new TestServer(context => context.Response.WriteAsync(context.Request.Scheme), serviceContext, listenOptions)) { var result = await HttpClientSlim.GetStringAsync($"https://localhost:{server.Port}/", validateCertificate: false); Assert.Equal("https", result); @@ -186,17 +200,21 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [Fact(Skip = "SslStream hanging on write after update to CoreFx 4.4 (https://github.com/dotnet/corefx/issues/14698)")] public async Task DoesNotSupportTls10() { - var serviceContext = new TestServiceContext(new HttpsConnectionFilter( - new HttpsConnectionFilterOptions + var serviceContext = new TestServiceContext(); + var listenOptions = new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0)) + { + ConnectionAdapters = { - ServerCertificate = _x509Certificate2, - ClientCertificateMode = ClientCertificateMode.RequireCertificate, - ClientCertificateValidation = (certificate, chain, sslPolicyErrors) => true - }, - new NoOpConnectionFilter()) - ); + new HttpsConnectionAdapter(new HttpsConnectionAdapterOptions + { + ServerCertificate = _x509Certificate2, + ClientCertificateMode = ClientCertificateMode.RequireCertificate, + ClientCertificateValidation = (certificate, chain, sslPolicyErrors) => true + }) + } + }; - using (var server = new TestServer(context => context.Response.WriteAsync("hello world"), serviceContext, _serverAddress)) + using (var server = new TestServer(context => context.Response.WriteAsync("hello world"), serviceContext, listenOptions)) { // SslStream is used to ensure the certificate is actually passed to the server // HttpClient might not send the certificate because it is invalid or it doesn't match any @@ -216,23 +234,27 @@ namespace Microsoft.AspNetCore.Server.KestrelTests public async Task ClientCertificateValidationGetsCalledWithNotNullParameters(ClientCertificateMode mode) { var clientCertificateValidationCalled = false; - var serviceContext = new TestServiceContext(new HttpsConnectionFilter( - new HttpsConnectionFilterOptions + var serviceContext = new TestServiceContext(); + var listenOptions = new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0)) + { + ConnectionAdapters = { - ServerCertificate = _x509Certificate2, - ClientCertificateMode = mode, - ClientCertificateValidation = (certificate, chain, sslPolicyErrors) => + new HttpsConnectionAdapter(new HttpsConnectionAdapterOptions { - clientCertificateValidationCalled = true; - Assert.NotNull(certificate); - Assert.NotNull(chain); - return true; - } - }, - new NoOpConnectionFilter()) - ); + ServerCertificate = _x509Certificate2, + ClientCertificateMode = mode, + ClientCertificateValidation = (certificate, chain, sslPolicyErrors) => + { + clientCertificateValidationCalled = true; + Assert.NotNull(certificate); + Assert.NotNull(chain); + return true; + } + }) + } + }; - using (var server = new TestServer(context => TaskCache.CompletedTask, serviceContext, _serverAddress)) + using (var server = new TestServer(context => TaskCache.CompletedTask, serviceContext, listenOptions)) { using (var client = new TcpClient()) { @@ -249,17 +271,21 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [InlineData(ClientCertificateMode.RequireCertificate)] public async Task ValidationFailureRejectsConnection(ClientCertificateMode mode) { - var serviceContext = new TestServiceContext(new HttpsConnectionFilter( - new HttpsConnectionFilterOptions + var serviceContext = new TestServiceContext(); + var listenOptions = new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0)) + { + ConnectionAdapters = { - ServerCertificate = _x509Certificate2, - ClientCertificateMode = mode, - ClientCertificateValidation = (certificate, chain, sslPolicyErrors) => false - }, - new NoOpConnectionFilter()) - ); + new HttpsConnectionAdapter(new HttpsConnectionAdapterOptions + { + ServerCertificate = _x509Certificate2, + ClientCertificateMode = mode, + ClientCertificateValidation = (certificate, chain, sslPolicyErrors) => false + }) + } + }; - using (var server = new TestServer(context => TaskCache.CompletedTask, serviceContext, _serverAddress)) + using (var server = new TestServer(context => TaskCache.CompletedTask, serviceContext, listenOptions)) { using (var client = new TcpClient()) { @@ -275,16 +301,20 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [InlineData(ClientCertificateMode.RequireCertificate)] public async Task RejectsConnectionOnSslPolicyErrorsWhenNoValidation(ClientCertificateMode mode) { - var serviceContext = new TestServiceContext(new HttpsConnectionFilter( - new HttpsConnectionFilterOptions + var serviceContext = new TestServiceContext(); + var listenOptions = new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0)) + { + ConnectionAdapters = { - ServerCertificate = _x509Certificate2, - ClientCertificateMode = mode, - }, - new NoOpConnectionFilter()) - ); + new HttpsConnectionAdapter(new HttpsConnectionAdapterOptions + { + ServerCertificate = _x509Certificate2, + ClientCertificateMode = mode + }) + } + }; - using (var server = new TestServer(context => TaskCache.CompletedTask, serviceContext, _serverAddress)) + using (var server = new TestServer(context => TaskCache.CompletedTask, serviceContext, listenOptions)) { using (var client = new TcpClient()) { @@ -298,15 +328,19 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [Fact(Skip = "SslStream hanging on write after update to CoreFx 4.4 (https://github.com/dotnet/corefx/issues/14698)")] public async Task CertificatePassedToHttpContextIsNotDisposed() { - var serviceContext = new TestServiceContext(new HttpsConnectionFilter( - new HttpsConnectionFilterOptions + var serviceContext = new TestServiceContext(); + var listenOptions = new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0)) + { + ConnectionAdapters = { - ServerCertificate = _x509Certificate2, - ClientCertificateMode = ClientCertificateMode.RequireCertificate, - ClientCertificateValidation = (certificate, chain, sslPolicyErrors) => true - }, - new NoOpConnectionFilter()) - ); + new HttpsConnectionAdapter(new HttpsConnectionAdapterOptions + { + ServerCertificate = _x509Certificate2, + ClientCertificateMode = ClientCertificateMode.RequireCertificate, + ClientCertificateValidation = (certificate, chain, sslPolicyErrors) => true + }) + } + }; RequestDelegate app = context => { @@ -318,7 +352,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests return context.Response.WriteAsync("hello world"); }; - using (var server = new TestServer(app, serviceContext, _serverAddress)) + using (var server = new TestServer(app, serviceContext, listenOptions)) { // SslStream is used to ensure the certificate is actually passed to the server // HttpClient might not send the certificate because it is invalid or it doesn't match any diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerOptionsTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerOptionsTests.cs index 540922a009..8b7fa7d599 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerOptionsTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerOptionsTests.cs @@ -3,13 +3,14 @@ using System; using System.Linq; +using System.Net; using System.Reflection; using Microsoft.AspNetCore.Server.Kestrel; using Xunit; namespace Microsoft.AspNetCore.Server.KestrelTests { - public class KestrelServerInformationTests + public class KestrelServerOptionsTests { #pragma warning disable CS0618 [Fact] @@ -39,6 +40,20 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } #pragma warning restore CS0612 + [Fact] + public void NoDelayDefaultsToTrue() + { + var o1 = new KestrelServerOptions(); + o1.Listen(IPAddress.Loopback, 0); + o1.Listen(IPAddress.Loopback, 0, d => + { + d.NoDelay = false; + }); + + Assert.True(o1.ListenOptions[0].NoDelay); + Assert.False(o1.ListenOptions[1].NoDelay); + } + [Fact] public void SetThreadCountUsingProcessorCount() { diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/ListenerPrimaryTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/ListenerPrimaryTests.cs index b6afadda5b..43e7b78e24 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/ListenerPrimaryTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/ListenerPrimaryTests.cs @@ -4,6 +4,7 @@ using System; using System.IO; using System.Linq; +using System.Net; using System.Threading.Tasks; using Microsoft.AspNetCore.Hosting.Server; using Microsoft.AspNetCore.Http; @@ -55,33 +56,35 @@ namespace Microsoft.AspNetCore.Server.KestrelTests using (var kestrelEngine = new KestrelEngine(libuv, serviceContextPrimary)) { - var address = ServerAddress.FromUrl("http://127.0.0.1:0/"); + var listenOptions = new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0)); + var pipeName = (libuv.IsWindows ? @"\\.\pipe\kestrel_" : "/tmp/kestrel_") + Guid.NewGuid().ToString("n"); var pipeMessage = Guid.NewGuid().ToByteArray(); // Start primary listener var kestrelThreadPrimary = new KestrelThread(kestrelEngine); await kestrelThreadPrimary.StartAsync(); - var listenerPrimary = new TcpListenerPrimary(serviceContextPrimary); - await listenerPrimary.StartAsync(pipeName, pipeMessage, address, kestrelThreadPrimary); + var listenerPrimary = new ListenerPrimary(serviceContextPrimary); + await listenerPrimary.StartAsync(pipeName, pipeMessage, listenOptions, kestrelThreadPrimary); + var address = listenOptions.ToString(); // Until a secondary listener is added, TCP connections get dispatched directly - Assert.Equal("Primary", await HttpClientSlim.GetStringAsync(address.ToString())); - Assert.Equal("Primary", await HttpClientSlim.GetStringAsync(address.ToString())); + Assert.Equal("Primary", await HttpClientSlim.GetStringAsync(address)); + Assert.Equal("Primary", await HttpClientSlim.GetStringAsync(address)); // Add secondary listener var kestrelThreadSecondary = new KestrelThread(kestrelEngine); await kestrelThreadSecondary.StartAsync(); - var listenerSecondary = new TcpListenerSecondary(serviceContextSecondary); - await listenerSecondary.StartAsync(pipeName, pipeMessage, address, kestrelThreadSecondary); + var listenerSecondary = new ListenerSecondary(serviceContextSecondary); + await listenerSecondary.StartAsync(pipeName, pipeMessage, listenOptions, kestrelThreadSecondary); // Once a secondary listener is added, TCP connections start getting dispatched to it - await AssertResponseEventually(address.ToString(), "Secondary", allowed: new[] { "Primary" }); + await AssertResponseEventually(address, "Secondary", allowed: new[] { "Primary" }); // TCP connections will still get round-robined to the primary listener - Assert.Equal("Primary", await HttpClientSlim.GetStringAsync(address.ToString())); - Assert.Equal("Secondary", await HttpClientSlim.GetStringAsync(address.ToString())); - Assert.Equal("Primary", await HttpClientSlim.GetStringAsync(address.ToString())); + Assert.Equal("Primary", await HttpClientSlim.GetStringAsync(address)); + Assert.Equal("Secondary", await HttpClientSlim.GetStringAsync(address)); + Assert.Equal("Primary", await HttpClientSlim.GetStringAsync(address)); await listenerSecondary.DisposeAsync(); await kestrelThreadSecondary.StopAsync(TimeSpan.FromSeconds(1)); @@ -129,25 +132,26 @@ namespace Microsoft.AspNetCore.Server.KestrelTests using (var kestrelEngine = new KestrelEngine(libuv, serviceContextPrimary)) { - var address = ServerAddress.FromUrl("http://127.0.0.1:0/"); + var listenOptions = new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0)); var pipeName = (libuv.IsWindows ? @"\\.\pipe\kestrel_" : "/tmp/kestrel_") + Guid.NewGuid().ToString("n"); var pipeMessage = Guid.NewGuid().ToByteArray(); // Start primary listener var kestrelThreadPrimary = new KestrelThread(kestrelEngine); await kestrelThreadPrimary.StartAsync(); - var listenerPrimary = new TcpListenerPrimary(serviceContextPrimary); - await listenerPrimary.StartAsync(pipeName, pipeMessage, address, kestrelThreadPrimary); + var listenerPrimary = new ListenerPrimary(serviceContextPrimary); + await listenerPrimary.StartAsync(pipeName, pipeMessage, listenOptions, kestrelThreadPrimary); + var address = listenOptions.ToString(); // Add secondary listener var kestrelThreadSecondary = new KestrelThread(kestrelEngine); await kestrelThreadSecondary.StartAsync(); - var listenerSecondary = new TcpListenerSecondary(serviceContextSecondary); - await listenerSecondary.StartAsync(pipeName, pipeMessage, address, kestrelThreadSecondary); + var listenerSecondary = new ListenerSecondary(serviceContextSecondary); + await listenerSecondary.StartAsync(pipeName, pipeMessage, listenOptions, kestrelThreadSecondary); // TCP Connections get round-robined - await AssertResponseEventually(address.ToString(), "Secondary", allowed: new[] { "Primary" }); - Assert.Equal("Primary", await HttpClientSlim.GetStringAsync(address.ToString())); + await AssertResponseEventually(address, "Secondary", allowed: new[] { "Primary" }); + Assert.Equal("Primary", await HttpClientSlim.GetStringAsync(address)); // Create a pipe connection and keep it open without sending any data var connectTcs = new TaskCompletionSource(); @@ -183,9 +187,9 @@ namespace Microsoft.AspNetCore.Server.KestrelTests await connectTcs.Task; // TCP connections will still get round-robined between only the two listeners - Assert.Equal("Secondary", await HttpClientSlim.GetStringAsync(address.ToString())); - Assert.Equal("Primary", await HttpClientSlim.GetStringAsync(address.ToString())); - Assert.Equal("Secondary", await HttpClientSlim.GetStringAsync(address.ToString())); + Assert.Equal("Secondary", await HttpClientSlim.GetStringAsync(address)); + Assert.Equal("Primary", await HttpClientSlim.GetStringAsync(address)); + Assert.Equal("Secondary", await HttpClientSlim.GetStringAsync(address)); await kestrelThreadPrimary.PostAsync(_ => pipe.Dispose(), null); @@ -196,9 +200,9 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } // Same for after the non-listener pipe connection is closed - Assert.Equal("Primary", await HttpClientSlim.GetStringAsync(address.ToString())); - Assert.Equal("Secondary", await HttpClientSlim.GetStringAsync(address.ToString())); - Assert.Equal("Primary", await HttpClientSlim.GetStringAsync(address.ToString())); + Assert.Equal("Primary", await HttpClientSlim.GetStringAsync(address)); + Assert.Equal("Secondary", await HttpClientSlim.GetStringAsync(address)); + Assert.Equal("Primary", await HttpClientSlim.GetStringAsync(address)); await listenerSecondary.DisposeAsync(); await kestrelThreadSecondary.StopAsync(TimeSpan.FromSeconds(1)); @@ -250,21 +254,22 @@ namespace Microsoft.AspNetCore.Server.KestrelTests using (var kestrelEngine = new KestrelEngine(libuv, serviceContextPrimary)) { - var address = ServerAddress.FromUrl("http://127.0.0.1:0/"); + var listenOptions = new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0)); var pipeName = (libuv.IsWindows ? @"\\.\pipe\kestrel_" : "/tmp/kestrel_") + Guid.NewGuid().ToString("n"); var pipeMessage = Guid.NewGuid().ToByteArray(); // Start primary listener var kestrelThreadPrimary = new KestrelThread(kestrelEngine); await kestrelThreadPrimary.StartAsync(); - var listenerPrimary = new TcpListenerPrimary(serviceContextPrimary); - await listenerPrimary.StartAsync(pipeName, pipeMessage, address, kestrelThreadPrimary); + var listenerPrimary = new ListenerPrimary(serviceContextPrimary); + await listenerPrimary.StartAsync(pipeName, pipeMessage, listenOptions, kestrelThreadPrimary); + var address = listenOptions.ToString(); // Add secondary listener with wrong pipe message var kestrelThreadSecondary = new KestrelThread(kestrelEngine); await kestrelThreadSecondary.StartAsync(); - var listenerSecondary = new TcpListenerSecondary(serviceContextSecondary); - await listenerSecondary.StartAsync(pipeName, Guid.NewGuid().ToByteArray(), address, kestrelThreadSecondary); + var listenerSecondary = new ListenerSecondary(serviceContextSecondary); + await listenerSecondary.StartAsync(pipeName, Guid.NewGuid().ToByteArray(), listenOptions, kestrelThreadSecondary); // Wait up to 10 seconds for error to be logged for (var i = 0; i < 10 && primaryTrace.Logger.TotalErrorsLogged == 0; i++) @@ -273,9 +278,9 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } // TCP Connections don't get round-robined - Assert.Equal("Primary", await HttpClientSlim.GetStringAsync(address.ToString())); - Assert.Equal("Primary", await HttpClientSlim.GetStringAsync(address.ToString())); - Assert.Equal("Primary", await HttpClientSlim.GetStringAsync(address.ToString())); + Assert.Equal("Primary", await HttpClientSlim.GetStringAsync(address)); + Assert.Equal("Primary", await HttpClientSlim.GetStringAsync(address)); + Assert.Equal("Primary", await HttpClientSlim.GetStringAsync(address)); await listenerSecondary.DisposeAsync(); await kestrelThreadSecondary.StopAsync(TimeSpan.FromSeconds(1)); diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/MultipleLoopTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/MultipleLoopTests.cs index d5926a14ec..687cf6577e 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/MultipleLoopTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/MultipleLoopTests.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Net; using System.Net.Sockets; using System.Runtime.InteropServices; using System.Threading; @@ -163,8 +164,8 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var serverListenTcp = new UvTcpHandle(_logger); serverListenTcp.Init(loop, (a, b) => { }); - var address = ServerAddress.FromUrl($"http://127.0.0.1:0/"); - serverListenTcp.Bind(address); + var endPoint = new IPEndPoint(IPAddress.Loopback, 0); + serverListenTcp.Bind(endPoint); var port = serverListenTcp.GetSockIPEndPoint().Port; serverListenTcp.Listen(128, (handle, status, error, state) => { diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/NetworkingTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/NetworkingTests.cs index ccd320a220..ebc3ebeb22 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/NetworkingTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/NetworkingTests.cs @@ -63,8 +63,8 @@ namespace Microsoft.AspNetCore.Server.KestrelTests loop.Init(_uv); var tcp = new UvTcpHandle(_logger); tcp.Init(loop, (a, b) => { }); - var address = ServerAddress.FromUrl("http://127.0.0.1:0/"); - tcp.Bind(address); + var endPoint = new IPEndPoint(IPAddress.Loopback, 0); + tcp.Bind(endPoint); tcp.Dispose(); loop.Run(); loop.Dispose(); @@ -78,8 +78,8 @@ namespace Microsoft.AspNetCore.Server.KestrelTests loop.Init(_uv); var tcp = new UvTcpHandle(_logger); tcp.Init(loop, (a, b) => { }); - var address = ServerAddress.FromUrl($"http://127.0.0.1:0/"); - tcp.Bind(address); + var endPoint = new IPEndPoint(IPAddress.Loopback, 0); + tcp.Bind(endPoint); var port = tcp.GetSockIPEndPoint().Port; tcp.Listen(10, (stream, status, error, state) => { @@ -107,8 +107,8 @@ namespace Microsoft.AspNetCore.Server.KestrelTests loop.Init(_uv); var tcp = new UvTcpHandle(_logger); tcp.Init(loop, (a, b) => { }); - var address = ServerAddress.FromUrl($"http://127.0.0.1:0/"); - tcp.Bind(address); + var endPoint = new IPEndPoint(IPAddress.Loopback, 0); + tcp.Bind(endPoint); var port = tcp.GetSockIPEndPoint().Port; tcp.Listen(10, (_, status, error, state) => { @@ -157,8 +157,8 @@ namespace Microsoft.AspNetCore.Server.KestrelTests loop.Init(_uv); var tcp = new UvTcpHandle(_logger); tcp.Init(loop, (a, b) => { }); - var address = ServerAddress.FromUrl($"http://127.0.0.1:0/"); - tcp.Bind(address); + var endPoint = new IPEndPoint(IPAddress.Loopback, 0); + tcp.Bind(endPoint); var port = tcp.GetSockIPEndPoint().Port; tcp.Listen(10, (_, status, error, state) => { diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/RequestTargetProcessingTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/RequestTargetProcessingTests.cs index a793cf0269..7a1d479f29 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/RequestTargetProcessingTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/RequestTargetProcessingTests.cs @@ -1,9 +1,11 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System.Net; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http.Features; +using Microsoft.AspNetCore.Server.Kestrel; using Microsoft.AspNetCore.Testing; using Xunit; @@ -16,6 +18,11 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { var testContext = new TestServiceContext(); + var listenOptions = new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0)) + { + PathBase = "/\u0041\u030A" + }; + using (var server = new TestServer(async context => { Assert.Equal("/\u0041\u030A", context.Request.PathBase.Value); @@ -23,7 +30,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests context.Response.Headers["Content-Length"] = new[] { "11" }; await context.Response.WriteAsync("Hello World"); - }, testContext, "http://127.0.0.1:0/\u0041\u030A")) + }, testContext, listenOptions)) { using (var connection = server.CreateConnection()) { diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/StreamSocketOutputTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/StreamSocketOutputTests.cs index ab8f83e46e..669efdf99e 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/StreamSocketOutputTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/StreamSocketOutputTests.cs @@ -3,7 +3,7 @@ using System; using System.IO; -using Microsoft.AspNetCore.Server.Kestrel.Filter.Internal; +using Microsoft.AspNetCore.Server.Kestrel.Adapter.Internal; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; using Microsoft.AspNetCore.Testing; using Xunit; diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/PassThroughConnectionAdapter.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/PassThroughConnectionAdapter.cs new file mode 100644 index 0000000000..2494e4bc5d --- /dev/null +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/PassThroughConnectionAdapter.cs @@ -0,0 +1,35 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System.IO; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Http.Features; +using Microsoft.AspNetCore.Server.Kestrel.Adapter; +using Microsoft.AspNetCore.Server.Kestrel.Adapter.Internal; +using Microsoft.AspNetCore.Testing; + +namespace Microsoft.AspNetCore.Server.KestrelTests.TestHelpers +{ + public class PassThroughConnectionAdapter : IConnectionAdapter + { + public Task OnConnectionAsync(ConnectionAdapterContext context) + { + var adapted = new AdaptedConnection(new LoggingStream(context.ConnectionStream, new TestApplicationErrorLogger())); + return Task.FromResult(adapted); + } + + private class AdaptedConnection : IAdaptedConnection + { + public AdaptedConnection(Stream stream) + { + ConnectionStream = stream; + } + + public Stream ConnectionStream { get; } + + public void PrepareRequest(IFeatureCollection requestFeatures) + { + } + } + } +} diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/PassThroughConnectionFilter.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/PassThroughConnectionFilter.cs deleted file mode 100644 index b4492bb8b6..0000000000 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/PassThroughConnectionFilter.cs +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System.Threading.Tasks; -using Microsoft.AspNetCore.Server.Kestrel.Filter; -using Microsoft.AspNetCore.Server.Kestrel.Filter.Internal; -using Microsoft.AspNetCore.Testing; -using Microsoft.Extensions.Internal; - -namespace Microsoft.AspNetCore.Server.KestrelTests.TestHelpers -{ - - public class PassThroughConnectionFilter : IConnectionFilter - { - public Task OnConnectionAsync(ConnectionFilterContext context) - { - context.Connection = new LoggingStream(context.Connection, new TestApplicationErrorLogger()); - return TaskCache.CompletedTask; - } - } -} diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestInput.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/TestInput.cs index 96d63ca04f..5a798e804b 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/TestInput.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/TestInput.cs @@ -2,13 +2,13 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Net; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel; using Microsoft.AspNetCore.Server.Kestrel.Internal; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; -using Microsoft.AspNetCore.Server.KestrelTests.TestHelpers; using Microsoft.AspNetCore.Testing; using Microsoft.Extensions.Internal; @@ -29,7 +29,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests }; var listenerContext = new ListenerContext(serviceContext) { - ServerAddress = ServerAddress.FromUrl("http://localhost:5000") + ListenOptions = new ListenOptions(new IPEndPoint(IPAddress.Loopback, 5000)) }; var connectionContext = new ConnectionContext(listenerContext) { diff --git a/test/shared/MockConnection.cs b/test/shared/MockConnection.cs index eff3da34fb..c68870cde6 100644 --- a/test/shared/MockConnection.cs +++ b/test/shared/MockConnection.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Net; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel; @@ -21,7 +22,7 @@ namespace Microsoft.AspNetCore.Testing RequestAbortedSource = new CancellationTokenSource(); ListenerContext = new ListenerContext(new ServiceContext {ServerOptions = options}) { - ServerAddress = ServerAddress.FromUrl("http://localhost:5000") + ListenOptions = new ListenOptions(new IPEndPoint(IPAddress.Loopback, 5000)) }; } diff --git a/test/shared/TestServer.cs b/test/shared/TestServer.cs index f52cc190d3..480e456bd2 100644 --- a/test/shared/TestServer.cs +++ b/test/shared/TestServer.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Net; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Server.Kestrel; using Microsoft.AspNetCore.Server.Kestrel.Internal; @@ -16,7 +17,7 @@ namespace Microsoft.AspNetCore.Testing { private KestrelEngine _engine; private IDisposable _server; - private ServerAddress _address; + private ListenOptions _listenOptions; public TestServer(RequestDelegate app) : this(app, new TestServiceContext()) @@ -24,18 +25,24 @@ namespace Microsoft.AspNetCore.Testing } public TestServer(RequestDelegate app, TestServiceContext context) - : this(app, context, "http://127.0.0.1:0/") + : this(app, context, httpContextFactory: null) { } - public TestServer(RequestDelegate app, TestServiceContext context, string serverAddress) - : this(app, context, serverAddress, null) + public TestServer(RequestDelegate app, TestServiceContext context, IHttpContextFactory httpContextFactory) + : this(app, context, new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0)), httpContextFactory) { } - public TestServer(RequestDelegate app, TestServiceContext context, string serverAddress, IHttpContextFactory httpContextFactory) + public TestServer(RequestDelegate app, TestServiceContext context, ListenOptions listenOptions) + : this(app, context, listenOptions, null) + { + } + + public TestServer(RequestDelegate app, TestServiceContext context, ListenOptions listenOptions, IHttpContextFactory httpContextFactory) { Context = context; + _listenOptions = listenOptions; context.FrameFactory = connectionContext => { @@ -46,8 +53,7 @@ namespace Microsoft.AspNetCore.Testing { _engine = new KestrelEngine(context); _engine.Start(1); - _address = ServerAddress.FromUrl(serverAddress); - _server = _engine.CreateServer(_address); + _server = _engine.CreateServer(_listenOptions); } catch { @@ -57,7 +63,7 @@ namespace Microsoft.AspNetCore.Testing } } - public int Port => _address.Port; + public int Port => _listenOptions.IPEndPoint.Port; public TestServiceContext Context { get; } diff --git a/test/shared/TestServiceContext.cs b/test/shared/TestServiceContext.cs index 9da3e8811b..7214c5e109 100644 --- a/test/shared/TestServiceContext.cs +++ b/test/shared/TestServiceContext.cs @@ -4,7 +4,7 @@ using System; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Server.Kestrel; -using Microsoft.AspNetCore.Server.Kestrel.Filter; +using Microsoft.AspNetCore.Server.Kestrel.Adapter; using Microsoft.AspNetCore.Server.Kestrel.Internal; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; @@ -26,12 +26,6 @@ namespace Microsoft.AspNetCore.Testing ServerOptions.ShutdownTimeout = TimeSpan.FromSeconds(5); } - public TestServiceContext(IConnectionFilter filter) - : this() - { - ServerOptions.ConnectionFilter = filter; - } - public string DateHeaderValue { get; } public RequestDelegate App From 6d7ddc45ef0468d37a23707344a41d5f6ce63863 Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Wed, 4 Jan 2017 17:17:52 -0800 Subject: [PATCH 1014/1662] Fix deadlock in SocketOutput (#1278). --- .../Internal/Http/SocketOutput.cs | 2 +- .../CancellationTokenExtensions.cs | 76 +++++++++++++++++++ .../Infrastructure/DisposableAction.cs | 40 ++++++++++ .../SocketOutputTests.cs | 4 +- 4 files changed, 119 insertions(+), 3 deletions(-) create mode 100644 src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/CancellationTokenExtensions.cs create mode 100644 src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/DisposableAction.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/SocketOutput.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/SocketOutput.cs index d7ac287ec6..c06bd4b236 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/SocketOutput.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/SocketOutput.cs @@ -169,7 +169,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _tasksPending.Enqueue(new WaitingTask() { CancellationToken = cancellationToken, - CancellationRegistration = cancellationToken.Register(_connectionCancellation, this), + CancellationRegistration = cancellationToken.SafeRegister(_connectionCancellation, this), BytesToWrite = buffer.Count, CompletionSource = tcs }); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/CancellationTokenExtensions.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/CancellationTokenExtensions.cs new file mode 100644 index 0000000000..1d4275a314 --- /dev/null +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/CancellationTokenExtensions.cs @@ -0,0 +1,76 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Threading; + +namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure +{ + internal static class CancellationTokenExtensions + { + public static IDisposable SafeRegister(this CancellationToken cancellationToken, Action callback, object state) + { + var callbackWrapper = new CancellationCallbackWrapper(callback, state); + var registration = cancellationToken.Register(s => InvokeCallback(s), callbackWrapper); + var disposeCancellationState = new DisposeCancellationState(callbackWrapper, registration); + + return new DisposableAction(s => Dispose(s), disposeCancellationState); + } + + private static void InvokeCallback(object state) + { + ((CancellationCallbackWrapper)state).TryInvoke(); + } + + private static void Dispose(object state) + { + ((DisposeCancellationState)state).TryDispose(); + } + + private class DisposeCancellationState + { + private readonly CancellationCallbackWrapper _callbackWrapper; + private readonly CancellationTokenRegistration _registration; + + public DisposeCancellationState(CancellationCallbackWrapper callbackWrapper, CancellationTokenRegistration registration) + { + _callbackWrapper = callbackWrapper; + _registration = registration; + } + + public void TryDispose() + { + if (_callbackWrapper.TrySetInvoked()) + { + _registration.Dispose(); + } + } + } + + private class CancellationCallbackWrapper + { + private readonly Action _callback; + private readonly object _state; + private int _callbackInvoked; + + public CancellationCallbackWrapper(Action callback, object state) + { + _callback = callback; + _state = state; + } + + public bool TrySetInvoked() + { + return Interlocked.Exchange(ref _callbackInvoked, 1) == 0; + } + + public void TryInvoke() + { + if (TrySetInvoked()) + { + _callback(_state); + } + } + } + } +} diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/DisposableAction.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/DisposableAction.cs new file mode 100644 index 0000000000..4336437ae9 --- /dev/null +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/DisposableAction.cs @@ -0,0 +1,40 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Threading; + +namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure +{ + internal class DisposableAction : IDisposable + { + public static readonly DisposableAction Empty = new DisposableAction(() => { }); + + private Action _action; + private readonly object _state; + + public DisposableAction(Action action) + : this(state => ((Action)state).Invoke(), state: action) + { + } + + public DisposableAction(Action action, object state) + { + _action = action; + _state = state; + } + + protected virtual void Dispose(bool disposing) + { + if (disposing) + { + Interlocked.Exchange(ref _action, (state) => { }).Invoke(_state); + } + } + + public void Dispose() + { + Dispose(true); + } + } +} diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/SocketOutputTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/SocketOutputTests.cs index bcd15a643c..f28b1ba8c5 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/SocketOutputTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/SocketOutputTests.cs @@ -753,7 +753,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests Action triggerNextCompleted; Assert.True(completeQueue.TryDequeue(out triggerNextCompleted)); triggerNextCompleted(0); - await mockLibuv.OnPostTask; + await mockLibuv.OnPostTask; Assert.True(writeCalled); // Cleanup @@ -862,4 +862,4 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } } } -} +} \ No newline at end of file From 57b368566d74b3cb7da60f412609938d2c96fdf6 Mon Sep 17 00:00:00 2001 From: John Luo Date: Thu, 5 Jan 2017 15:02:23 -0800 Subject: [PATCH 1015/1662] Use StatusCode instead of three digit numbers for status codes --- .../BadHttpRequestException.cs | 55 ++-- .../Internal/Http/Frame.FeatureCollection.cs | 2 +- .../Internal/Http/Frame.cs | 18 +- .../Internal/Http/ReasonPhrases.cs | 266 ++++++++++-------- .../HttpClientSlimTests.cs | 6 +- .../MaxRequestBufferSizeTests.cs | 8 +- .../ResponseTests.cs | 8 +- .../FrameRequestHeadersTests.cs | 3 +- .../FrameTests.cs | 35 +-- .../MessageBodyTests.cs | 11 +- 10 files changed, 230 insertions(+), 182 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/BadHttpRequestException.cs b/src/Microsoft.AspNetCore.Server.Kestrel/BadHttpRequestException.cs index cb37af76c1..128040c1df 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/BadHttpRequestException.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/BadHttpRequestException.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.IO; +using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; namespace Microsoft.AspNetCore.Server.Kestrel @@ -22,64 +23,64 @@ namespace Microsoft.AspNetCore.Server.Kestrel switch (reason) { case RequestRejectionReason.HeadersCorruptedInvalidHeaderSequence: - ex = new BadHttpRequestException("Headers corrupted, invalid header sequence.", 400); + ex = new BadHttpRequestException("Headers corrupted, invalid header sequence.", StatusCodes.Status400BadRequest); break; case RequestRejectionReason.HeaderLineMustNotStartWithWhitespace: - ex = new BadHttpRequestException("Header line must not start with whitespace.", 400); + ex = new BadHttpRequestException("Header line must not start with whitespace.", StatusCodes.Status400BadRequest); break; case RequestRejectionReason.NoColonCharacterFoundInHeaderLine: - ex = new BadHttpRequestException("No ':' character found in header line.", 400); + ex = new BadHttpRequestException("No ':' character found in header line.", StatusCodes.Status400BadRequest); break; case RequestRejectionReason.WhitespaceIsNotAllowedInHeaderName: - ex = new BadHttpRequestException("Whitespace is not allowed in header name.", 400); + ex = new BadHttpRequestException("Whitespace is not allowed in header name.", StatusCodes.Status400BadRequest); break; case RequestRejectionReason.HeaderValueMustNotContainCR: - ex = new BadHttpRequestException("Header value must not contain CR characters.", 400); + ex = new BadHttpRequestException("Header value must not contain CR characters.", StatusCodes.Status400BadRequest); break; case RequestRejectionReason.HeaderValueLineFoldingNotSupported: - ex = new BadHttpRequestException("Header value line folding not supported.", 400); + ex = new BadHttpRequestException("Header value line folding not supported.", StatusCodes.Status400BadRequest); break; case RequestRejectionReason.MalformedRequestInvalidHeaders: - ex = new BadHttpRequestException("Malformed request: invalid headers.", 400); + ex = new BadHttpRequestException("Malformed request: invalid headers.", StatusCodes.Status400BadRequest); break; case RequestRejectionReason.UnexpectedEndOfRequestContent: - ex = new BadHttpRequestException("Unexpected end of request content.", 400); + ex = new BadHttpRequestException("Unexpected end of request content.", StatusCodes.Status400BadRequest); break; case RequestRejectionReason.BadChunkSuffix: - ex = new BadHttpRequestException("Bad chunk suffix.", 400); + ex = new BadHttpRequestException("Bad chunk suffix.", StatusCodes.Status400BadRequest); break; case RequestRejectionReason.BadChunkSizeData: - ex = new BadHttpRequestException("Bad chunk size data.", 400); + ex = new BadHttpRequestException("Bad chunk size data.", StatusCodes.Status400BadRequest); break; case RequestRejectionReason.ChunkedRequestIncomplete: - ex = new BadHttpRequestException("Chunked request incomplete.", 400); + ex = new BadHttpRequestException("Chunked request incomplete.", StatusCodes.Status400BadRequest); break; case RequestRejectionReason.PathContainsNullCharacters: - ex = new BadHttpRequestException("The path contains null characters.", 400); + ex = new BadHttpRequestException("The path contains null characters.", StatusCodes.Status400BadRequest); break; case RequestRejectionReason.InvalidCharactersInHeaderName: - ex = new BadHttpRequestException("Invalid characters in header name.", 400); + ex = new BadHttpRequestException("Invalid characters in header name.", StatusCodes.Status400BadRequest); break; case RequestRejectionReason.NonAsciiOrNullCharactersInInputString: - ex = new BadHttpRequestException("The input string contains non-ASCII or null characters.", 400); + ex = new BadHttpRequestException("The input string contains non-ASCII or null characters.", StatusCodes.Status400BadRequest); break; case RequestRejectionReason.RequestLineTooLong: - ex = new BadHttpRequestException("Request line too long.", 414); + ex = new BadHttpRequestException("Request line too long.", StatusCodes.Status414UriTooLong); break; case RequestRejectionReason.HeadersExceedMaxTotalSize: - ex = new BadHttpRequestException("Request headers too long.", 431); + ex = new BadHttpRequestException("Request headers too long.", StatusCodes.Status431RequestHeaderFieldsTooLarge); break; case RequestRejectionReason.MissingCRInHeaderLine: - ex = new BadHttpRequestException("No CR character found in header line.", 400); + ex = new BadHttpRequestException("No CR character found in header line.", StatusCodes.Status400BadRequest); break; case RequestRejectionReason.TooManyHeaders: - ex = new BadHttpRequestException("Request contains too many headers.", 431); + ex = new BadHttpRequestException("Request contains too many headers.", StatusCodes.Status431RequestHeaderFieldsTooLarge); break; case RequestRejectionReason.RequestTimeout: - ex = new BadHttpRequestException("Request timed out.", 408); + ex = new BadHttpRequestException("Request timed out.", StatusCodes.Status408RequestTimeout); break; default: - ex = new BadHttpRequestException("Bad request.", 400); + ex = new BadHttpRequestException("Bad request.", StatusCodes.Status400BadRequest); break; } return ex; @@ -91,25 +92,25 @@ namespace Microsoft.AspNetCore.Server.Kestrel switch (reason) { case RequestRejectionReason.InvalidRequestLine: - ex = new BadHttpRequestException($"Invalid request line: {value}", 400); + ex = new BadHttpRequestException($"Invalid request line: {value}", StatusCodes.Status400BadRequest); break; case RequestRejectionReason.InvalidContentLength: - ex = new BadHttpRequestException($"Invalid content length: {value}", 400); + ex = new BadHttpRequestException($"Invalid content length: {value}", StatusCodes.Status400BadRequest); break; case RequestRejectionReason.UnrecognizedHTTPVersion: - ex = new BadHttpRequestException($"Unrecognized HTTP version: {value}", 505); + ex = new BadHttpRequestException($"Unrecognized HTTP version: {value}", StatusCodes.Status505HttpVersionNotsupported); break; case RequestRejectionReason.FinalTransferCodingNotChunked: - ex = new BadHttpRequestException($"Final transfer coding is not \"chunked\": \"{value}\"", 400); + ex = new BadHttpRequestException($"Final transfer coding is not \"chunked\": \"{value}\"", StatusCodes.Status400BadRequest); break; case RequestRejectionReason.LengthRequired: - ex = new BadHttpRequestException($"{value} request contains no Content-Length or Transfer-Encoding header", 411); + ex = new BadHttpRequestException($"{value} request contains no Content-Length or Transfer-Encoding header", StatusCodes.Status411LengthRequired); break; case RequestRejectionReason.LengthRequiredHttp10: - ex = new BadHttpRequestException($"{value} request contains no Content-Length header", 400); + ex = new BadHttpRequestException($"{value} request contains no Content-Length header", StatusCodes.Status400BadRequest); break; default: - ex = new BadHttpRequestException("Bad request.", 400); + ex = new BadHttpRequestException("Bad request.", StatusCodes.Status400BadRequest); break; } return ex; diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.FeatureCollection.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.FeatureCollection.cs index 9480147f95..66be41e7e0 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.FeatureCollection.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.FeatureCollection.cs @@ -323,7 +323,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http async Task IHttpUpgradeFeature.UpgradeAsync() { - StatusCode = 101; + StatusCode = StatusCodes.Status101SwitchingProtocols; ReasonPhrase = "Switching Protocols"; ResponseHeaders["Connection"] = "Upgrade"; if (!ResponseHeaders.ContainsKey("Upgrade")) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs index dfc49447b9..fc4ba2b202 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs @@ -141,7 +141,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http set { // GetKnownVersion returns versions which ReferenceEquals interned string - // As most common path, check for this only in fast-path and inline + // As most common path, check for this only in fast-path and inline if (ReferenceEquals(value, "HTTP/1.1")) { _httpVersion = Http.HttpVersion.Http11; @@ -347,7 +347,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http Path = null; QueryString = null; _httpVersion = Http.HttpVersion.Unset; - StatusCode = 200; + StatusCode = StatusCodes.Status200OK; ReasonPhrase = null; RemoteIpAddress = RemoteEndPoint?.Address; @@ -816,7 +816,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http else { // 500 Internal Server Error - SetErrorResponseHeaders(statusCode: 500); + SetErrorResponseHeaders(statusCode: StatusCodes.Status500InternalServerError); } } @@ -909,7 +909,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { if (!hasTransferEncoding && !responseHeaders.HasContentLength) { - if (appCompleted && StatusCode != 101) + if (appCompleted && StatusCode != StatusCodes.Status101SwitchingProtocols) { // Since the app has completed and we are only now generating // the headers we can safely set the Content-Length to 0. @@ -924,7 +924,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http // // A server MUST NOT send a response containing Transfer-Encoding unless the corresponding // request indicates HTTP/1.1 (or later). - if (_httpVersion == Http.HttpVersion.Http11 && StatusCode != 101) + if (_httpVersion == Http.HttpVersion.Http11 && StatusCode != StatusCodes.Status101SwitchingProtocols) { _autoChunk = true; responseHeaders.SetRawTransferEncoding("chunked", _bytesTransferEncodingChunked); @@ -1410,9 +1410,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http public bool StatusCanHaveBody(int statusCode) { // List of status codes taken from Microsoft.Net.Http.Server.Response - return statusCode != 204 && - statusCode != 205 && - statusCode != 304; + return statusCode != StatusCodes.Status204NoContent && + statusCode != StatusCodes.Status205ResetContent && + statusCode != StatusCodes.Status304NotModified; } private void ThrowResponseAlreadyStartedException(string value) @@ -1434,7 +1434,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http ReportApplicationError(ex); // 500 Internal Server Error - SetErrorResponseHeaders(statusCode: 500); + SetErrorResponseHeaders(statusCode: StatusCodes.Status500InternalServerError); } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ReasonPhrases.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ReasonPhrases.cs index c7d52fc91c..d3e916606e 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ReasonPhrases.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ReasonPhrases.cs @@ -1,68 +1,89 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System.Diagnostics; using System.Globalization; using System.Text; +using Microsoft.AspNetCore.Http; namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { public static class ReasonPhrases { - private static readonly byte[] _bytesStatus100 = Encoding.ASCII.GetBytes("100 Continue"); - private static readonly byte[] _bytesStatus101 = Encoding.ASCII.GetBytes("101 Switching Protocols"); - private static readonly byte[] _bytesStatus102 = Encoding.ASCII.GetBytes("102 Processing"); - private static readonly byte[] _bytesStatus200 = Encoding.ASCII.GetBytes("200 OK"); - private static readonly byte[] _bytesStatus201 = Encoding.ASCII.GetBytes("201 Created"); - private static readonly byte[] _bytesStatus202 = Encoding.ASCII.GetBytes("202 Accepted"); - private static readonly byte[] _bytesStatus203 = Encoding.ASCII.GetBytes("203 Non-Authoritative Information"); - private static readonly byte[] _bytesStatus204 = Encoding.ASCII.GetBytes("204 No Content"); - private static readonly byte[] _bytesStatus205 = Encoding.ASCII.GetBytes("205 Reset Content"); - private static readonly byte[] _bytesStatus206 = Encoding.ASCII.GetBytes("206 Partial Content"); - private static readonly byte[] _bytesStatus207 = Encoding.ASCII.GetBytes("207 Multi-Status"); - private static readonly byte[] _bytesStatus226 = Encoding.ASCII.GetBytes("226 IM Used"); - private static readonly byte[] _bytesStatus300 = Encoding.ASCII.GetBytes("300 Multiple Choices"); - private static readonly byte[] _bytesStatus301 = Encoding.ASCII.GetBytes("301 Moved Permanently"); - private static readonly byte[] _bytesStatus302 = Encoding.ASCII.GetBytes("302 Found"); - private static readonly byte[] _bytesStatus303 = Encoding.ASCII.GetBytes("303 See Other"); - private static readonly byte[] _bytesStatus304 = Encoding.ASCII.GetBytes("304 Not Modified"); - private static readonly byte[] _bytesStatus305 = Encoding.ASCII.GetBytes("305 Use Proxy"); - private static readonly byte[] _bytesStatus306 = Encoding.ASCII.GetBytes("306 Reserved"); - private static readonly byte[] _bytesStatus307 = Encoding.ASCII.GetBytes("307 Temporary Redirect"); - private static readonly byte[] _bytesStatus308 = Encoding.ASCII.GetBytes("308 Permanent Redirect"); - private static readonly byte[] _bytesStatus400 = Encoding.ASCII.GetBytes("400 Bad Request"); - private static readonly byte[] _bytesStatus401 = Encoding.ASCII.GetBytes("401 Unauthorized"); - private static readonly byte[] _bytesStatus402 = Encoding.ASCII.GetBytes("402 Payment Required"); - private static readonly byte[] _bytesStatus403 = Encoding.ASCII.GetBytes("403 Forbidden"); - private static readonly byte[] _bytesStatus404 = Encoding.ASCII.GetBytes("404 Not Found"); - private static readonly byte[] _bytesStatus405 = Encoding.ASCII.GetBytes("405 Method Not Allowed"); - private static readonly byte[] _bytesStatus406 = Encoding.ASCII.GetBytes("406 Not Acceptable"); - private static readonly byte[] _bytesStatus407 = Encoding.ASCII.GetBytes("407 Proxy Authentication Required"); - private static readonly byte[] _bytesStatus408 = Encoding.ASCII.GetBytes("408 Request Timeout"); - private static readonly byte[] _bytesStatus409 = Encoding.ASCII.GetBytes("409 Conflict"); - private static readonly byte[] _bytesStatus410 = Encoding.ASCII.GetBytes("410 Gone"); - private static readonly byte[] _bytesStatus411 = Encoding.ASCII.GetBytes("411 Length Required"); - private static readonly byte[] _bytesStatus412 = Encoding.ASCII.GetBytes("412 Precondition Failed"); - private static readonly byte[] _bytesStatus413 = Encoding.ASCII.GetBytes("413 Payload Too Large"); - private static readonly byte[] _bytesStatus414 = Encoding.ASCII.GetBytes("414 URI Too Long"); - private static readonly byte[] _bytesStatus415 = Encoding.ASCII.GetBytes("415 Unsupported Media Type"); - private static readonly byte[] _bytesStatus416 = Encoding.ASCII.GetBytes("416 Range Not Satisfiable"); - private static readonly byte[] _bytesStatus417 = Encoding.ASCII.GetBytes("417 Expectation Failed"); - private static readonly byte[] _bytesStatus418 = Encoding.ASCII.GetBytes("418 I'm a Teapot"); - private static readonly byte[] _bytesStatus422 = Encoding.ASCII.GetBytes("422 Unprocessable Entity"); - private static readonly byte[] _bytesStatus423 = Encoding.ASCII.GetBytes("423 Locked"); - private static readonly byte[] _bytesStatus424 = Encoding.ASCII.GetBytes("424 Failed Dependency"); - private static readonly byte[] _bytesStatus426 = Encoding.ASCII.GetBytes("426 Upgrade Required"); - private static readonly byte[] _bytesStatus431 = Encoding.ASCII.GetBytes("431 Request Header Fields Too Large"); - private static readonly byte[] _bytesStatus451 = Encoding.ASCII.GetBytes("451 Unavailable For Legal Reasons"); - private static readonly byte[] _bytesStatus500 = Encoding.ASCII.GetBytes("500 Internal Server Error"); - private static readonly byte[] _bytesStatus501 = Encoding.ASCII.GetBytes("501 Not Implemented"); - private static readonly byte[] _bytesStatus502 = Encoding.ASCII.GetBytes("502 Bad Gateway"); - private static readonly byte[] _bytesStatus503 = Encoding.ASCII.GetBytes("503 Service Unavailable"); - private static readonly byte[] _bytesStatus504 = Encoding.ASCII.GetBytes("504 Gateway Timeout"); - private static readonly byte[] _bytesStatus505 = Encoding.ASCII.GetBytes("505 HTTP Version Not Supported"); - private static readonly byte[] _bytesStatus506 = Encoding.ASCII.GetBytes("506 Variant Also Negotiates"); - private static readonly byte[] _bytesStatus507 = Encoding.ASCII.GetBytes("507 Insufficient Storage"); - private static readonly byte[] _bytesStatus510 = Encoding.ASCII.GetBytes("510 Not Extended"); + private static readonly byte[] _bytesStatus100 = CreateStatusBytes(StatusCodes.Status100Continue); + private static readonly byte[] _bytesStatus101 = CreateStatusBytes(StatusCodes.Status101SwitchingProtocols); + private static readonly byte[] _bytesStatus102 = CreateStatusBytes(StatusCodes.Status102Processing); + + private static readonly byte[] _bytesStatus200 = CreateStatusBytes(StatusCodes.Status200OK); + private static readonly byte[] _bytesStatus201 = CreateStatusBytes(StatusCodes.Status201Created); + private static readonly byte[] _bytesStatus202 = CreateStatusBytes(StatusCodes.Status202Accepted); + private static readonly byte[] _bytesStatus203 = CreateStatusBytes(StatusCodes.Status203NonAuthoritative); + private static readonly byte[] _bytesStatus204 = CreateStatusBytes(StatusCodes.Status204NoContent); + private static readonly byte[] _bytesStatus205 = CreateStatusBytes(StatusCodes.Status205ResetContent); + private static readonly byte[] _bytesStatus206 = CreateStatusBytes(StatusCodes.Status206PartialContent); + private static readonly byte[] _bytesStatus207 = CreateStatusBytes(StatusCodes.Status207MultiStatus); + private static readonly byte[] _bytesStatus208 = CreateStatusBytes(StatusCodes.Status208AlreadyReported); + private static readonly byte[] _bytesStatus226 = CreateStatusBytes(StatusCodes.Status226IMUsed); + + private static readonly byte[] _bytesStatus300 = CreateStatusBytes(StatusCodes.Status300MultipleChoices); + private static readonly byte[] _bytesStatus301 = CreateStatusBytes(StatusCodes.Status301MovedPermanently); + private static readonly byte[] _bytesStatus302 = CreateStatusBytes(StatusCodes.Status302Found); + private static readonly byte[] _bytesStatus303 = CreateStatusBytes(StatusCodes.Status303SeeOther); + private static readonly byte[] _bytesStatus304 = CreateStatusBytes(StatusCodes.Status304NotModified); + private static readonly byte[] _bytesStatus305 = CreateStatusBytes(StatusCodes.Status305UseProxy); + private static readonly byte[] _bytesStatus306 = CreateStatusBytes(StatusCodes.Status306SwitchProxy); + private static readonly byte[] _bytesStatus307 = CreateStatusBytes(StatusCodes.Status307TemporaryRedirect); + private static readonly byte[] _bytesStatus308 = CreateStatusBytes(StatusCodes.Status308PermanentRedirect); + + private static readonly byte[] _bytesStatus400 = CreateStatusBytes(StatusCodes.Status400BadRequest); + private static readonly byte[] _bytesStatus401 = CreateStatusBytes(StatusCodes.Status401Unauthorized); + private static readonly byte[] _bytesStatus402 = CreateStatusBytes(StatusCodes.Status402PaymentRequired); + private static readonly byte[] _bytesStatus403 = CreateStatusBytes(StatusCodes.Status403Forbidden); + private static readonly byte[] _bytesStatus404 = CreateStatusBytes(StatusCodes.Status404NotFound); + private static readonly byte[] _bytesStatus405 = CreateStatusBytes(StatusCodes.Status405MethodNotAllowed); + private static readonly byte[] _bytesStatus406 = CreateStatusBytes(StatusCodes.Status406NotAcceptable); + private static readonly byte[] _bytesStatus407 = CreateStatusBytes(StatusCodes.Status407ProxyAuthenticationRequired); + private static readonly byte[] _bytesStatus408 = CreateStatusBytes(StatusCodes.Status408RequestTimeout); + private static readonly byte[] _bytesStatus409 = CreateStatusBytes(StatusCodes.Status409Conflict); + private static readonly byte[] _bytesStatus410 = CreateStatusBytes(StatusCodes.Status410Gone); + private static readonly byte[] _bytesStatus411 = CreateStatusBytes(StatusCodes.Status411LengthRequired); + private static readonly byte[] _bytesStatus412 = CreateStatusBytes(StatusCodes.Status412PreconditionFailed); + private static readonly byte[] _bytesStatus413 = CreateStatusBytes(StatusCodes.Status413PayloadTooLarge); + private static readonly byte[] _bytesStatus414 = CreateStatusBytes(StatusCodes.Status414UriTooLong); + private static readonly byte[] _bytesStatus415 = CreateStatusBytes(StatusCodes.Status415UnsupportedMediaType); + private static readonly byte[] _bytesStatus416 = CreateStatusBytes(StatusCodes.Status416RangeNotSatisfiable); + private static readonly byte[] _bytesStatus417 = CreateStatusBytes(StatusCodes.Status417ExpectationFailed); + private static readonly byte[] _bytesStatus418 = CreateStatusBytes(StatusCodes.Status418ImATeapot); + private static readonly byte[] _bytesStatus419 = CreateStatusBytes(StatusCodes.Status419AuthenticationTimeout); + private static readonly byte[] _bytesStatus421 = CreateStatusBytes(StatusCodes.Status421MisdirectedRequest); + private static readonly byte[] _bytesStatus422 = CreateStatusBytes(StatusCodes.Status422UnprocessableEntity); + private static readonly byte[] _bytesStatus423 = CreateStatusBytes(StatusCodes.Status423Locked); + private static readonly byte[] _bytesStatus424 = CreateStatusBytes(StatusCodes.Status424FailedDependency); + private static readonly byte[] _bytesStatus426 = CreateStatusBytes(StatusCodes.Status426UpgradeRequired); + private static readonly byte[] _bytesStatus428 = CreateStatusBytes(StatusCodes.Status428PreconditionRequired); + private static readonly byte[] _bytesStatus429 = CreateStatusBytes(StatusCodes.Status429TooManyRequests); + private static readonly byte[] _bytesStatus431 = CreateStatusBytes(StatusCodes.Status431RequestHeaderFieldsTooLarge); + private static readonly byte[] _bytesStatus451 = CreateStatusBytes(StatusCodes.Status451UnavailableForLegalReasons); + + private static readonly byte[] _bytesStatus500 = CreateStatusBytes(StatusCodes.Status500InternalServerError); + private static readonly byte[] _bytesStatus501 = CreateStatusBytes(StatusCodes.Status501NotImplemented); + private static readonly byte[] _bytesStatus502 = CreateStatusBytes(StatusCodes.Status502BadGateway); + private static readonly byte[] _bytesStatus503 = CreateStatusBytes(StatusCodes.Status503ServiceUnavailable); + private static readonly byte[] _bytesStatus504 = CreateStatusBytes(StatusCodes.Status504GatewayTimeout); + private static readonly byte[] _bytesStatus505 = CreateStatusBytes(StatusCodes.Status505HttpVersionNotsupported); + private static readonly byte[] _bytesStatus506 = CreateStatusBytes(StatusCodes.Status506VariantAlsoNegotiates); + private static readonly byte[] _bytesStatus507 = CreateStatusBytes(StatusCodes.Status507InsufficientStorage); + private static readonly byte[] _bytesStatus508 = CreateStatusBytes(StatusCodes.Status508LoopDetected); + private static readonly byte[] _bytesStatus510 = CreateStatusBytes(StatusCodes.Status510NotExtended); + private static readonly byte[] _bytesStatus511 = CreateStatusBytes(StatusCodes.Status511NetworkAuthenticationRequired); + + private static byte[] CreateStatusBytes(int statusCode) + { + var reasonPhrase = WebUtilities.ReasonPhrases.GetReasonPhrase(statusCode); + Debug.Assert(!string.IsNullOrEmpty(reasonPhrase)); + + return Encoding.ASCII.GetBytes(statusCode.ToString(CultureInfo.InvariantCulture) + " " + reasonPhrase); + } public static byte[] ToStatusBytes(int statusCode, string reasonPhrase = null) { @@ -70,118 +91,141 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { switch (statusCode) { - case 100: + case StatusCodes.Status100Continue: return _bytesStatus100; - case 101: + case StatusCodes.Status101SwitchingProtocols: return _bytesStatus101; - case 102: + case StatusCodes.Status102Processing: return _bytesStatus102; - case 200: + + case StatusCodes.Status200OK: return _bytesStatus200; - case 201: + case StatusCodes.Status201Created: return _bytesStatus201; - case 202: + case StatusCodes.Status202Accepted: return _bytesStatus202; - case 203: + case StatusCodes.Status203NonAuthoritative: return _bytesStatus203; - case 204: + case StatusCodes.Status204NoContent: return _bytesStatus204; - case 205: + case StatusCodes.Status205ResetContent: return _bytesStatus205; - case 206: + case StatusCodes.Status206PartialContent: return _bytesStatus206; - case 207: + case StatusCodes.Status207MultiStatus: return _bytesStatus207; - case 226: + case StatusCodes.Status208AlreadyReported: + return _bytesStatus208; + case StatusCodes.Status226IMUsed: return _bytesStatus226; - case 300: + + case StatusCodes.Status300MultipleChoices: return _bytesStatus300; - case 301: + case StatusCodes.Status301MovedPermanently: return _bytesStatus301; - case 302: + case StatusCodes.Status302Found: return _bytesStatus302; - case 303: + case StatusCodes.Status303SeeOther: return _bytesStatus303; - case 304: + case StatusCodes.Status304NotModified: return _bytesStatus304; - case 305: + case StatusCodes.Status305UseProxy: return _bytesStatus305; - case 306: + case StatusCodes.Status306SwitchProxy: return _bytesStatus306; - case 307: + case StatusCodes.Status307TemporaryRedirect: return _bytesStatus307; - case 308: + case StatusCodes.Status308PermanentRedirect: return _bytesStatus308; - case 400: + + case StatusCodes.Status400BadRequest: return _bytesStatus400; - case 401: + case StatusCodes.Status401Unauthorized: return _bytesStatus401; - case 402: + case StatusCodes.Status402PaymentRequired: return _bytesStatus402; - case 403: + case StatusCodes.Status403Forbidden: return _bytesStatus403; - case 404: + case StatusCodes.Status404NotFound: return _bytesStatus404; - case 405: + case StatusCodes.Status405MethodNotAllowed: return _bytesStatus405; - case 406: + case StatusCodes.Status406NotAcceptable: return _bytesStatus406; - case 407: + case StatusCodes.Status407ProxyAuthenticationRequired: return _bytesStatus407; - case 408: + case StatusCodes.Status408RequestTimeout: return _bytesStatus408; - case 409: + case StatusCodes.Status409Conflict: return _bytesStatus409; - case 410: + case StatusCodes.Status410Gone: return _bytesStatus410; - case 411: + case StatusCodes.Status411LengthRequired: return _bytesStatus411; - case 412: + case StatusCodes.Status412PreconditionFailed: return _bytesStatus412; - case 413: + case StatusCodes.Status413PayloadTooLarge: return _bytesStatus413; - case 414: + case StatusCodes.Status414UriTooLong: return _bytesStatus414; - case 415: + case StatusCodes.Status415UnsupportedMediaType: return _bytesStatus415; - case 416: + case StatusCodes.Status416RangeNotSatisfiable: return _bytesStatus416; - case 417: + case StatusCodes.Status417ExpectationFailed: return _bytesStatus417; - case 418: + case StatusCodes.Status418ImATeapot: return _bytesStatus418; - case 422: + case StatusCodes.Status419AuthenticationTimeout: + return _bytesStatus419; + case StatusCodes.Status421MisdirectedRequest: + return _bytesStatus421; + case StatusCodes.Status422UnprocessableEntity: return _bytesStatus422; - case 423: + case StatusCodes.Status423Locked: return _bytesStatus423; - case 424: + case StatusCodes.Status424FailedDependency: return _bytesStatus424; - case 426: + case StatusCodes.Status426UpgradeRequired: return _bytesStatus426; - case 431: + case StatusCodes.Status428PreconditionRequired: + return _bytesStatus428; + case StatusCodes.Status429TooManyRequests: + return _bytesStatus429; + case StatusCodes.Status431RequestHeaderFieldsTooLarge: return _bytesStatus431; - case 451: + case StatusCodes.Status451UnavailableForLegalReasons: return _bytesStatus451; - case 500: + + case StatusCodes.Status500InternalServerError: return _bytesStatus500; - case 501: + case StatusCodes.Status501NotImplemented: return _bytesStatus501; - case 502: + case StatusCodes.Status502BadGateway: return _bytesStatus502; - case 503: + case StatusCodes.Status503ServiceUnavailable: return _bytesStatus503; - case 504: + case StatusCodes.Status504GatewayTimeout: return _bytesStatus504; - case 505: + case StatusCodes.Status505HttpVersionNotsupported: return _bytesStatus505; - case 506: + case StatusCodes.Status506VariantAlsoNegotiates: return _bytesStatus506; - case 507: + case StatusCodes.Status507InsufficientStorage: return _bytesStatus507; - case 510: + case StatusCodes.Status508LoopDetected: + return _bytesStatus508; + case StatusCodes.Status510NotExtended: return _bytesStatus510; + case StatusCodes.Status511NetworkAuthenticationRequired: + return _bytesStatus511; + default: - return Encoding.ASCII.GetBytes(statusCode.ToString(CultureInfo.InvariantCulture) + " Unknown"); + var predefinedReasonPhrase = WebUtilities.ReasonPhrases.GetReasonPhrase(statusCode); + return string.IsNullOrEmpty(predefinedReasonPhrase) + ? Encoding.ASCII.GetBytes(statusCode.ToString(CultureInfo.InvariantCulture)) + : Encoding.ASCII.GetBytes(statusCode.ToString(CultureInfo.InvariantCulture) + " " + predefinedReasonPhrase); + } } return Encoding.ASCII.GetBytes(statusCode.ToString(CultureInfo.InvariantCulture) + " " + reasonPhrase); diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/HttpClientSlimTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/HttpClientSlimTests.cs index ab8f3a5c02..76cd68c918 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/HttpClientSlimTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/HttpClientSlimTests.cs @@ -39,7 +39,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [Fact] public async Task GetStringAsyncThrowsForErrorResponse() { - using (var host = StartHost(statusCode: 500)) + using (var host = StartHost(statusCode: StatusCodes.Status500InternalServerError)) { await Assert.ThrowsAnyAsync(() => HttpClientSlim.GetStringAsync(host.GetUri())); } @@ -68,14 +68,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [Fact] public async Task PostAsyncThrowsForErrorResponse() { - using (var host = StartHost(statusCode: 500)) + using (var host = StartHost(statusCode: StatusCodes.Status500InternalServerError)) { await Assert.ThrowsAnyAsync( () => HttpClientSlim.PostAsync(host.GetUri(), new StringContent(""))); } } - private IWebHost StartHost(string protocol = "http", int statusCode = 200, Func handler = null) + private IWebHost StartHost(string protocol = "http", int statusCode = StatusCodes.Status200OK, Func handler = null) { var host = new WebHostBuilder() .UseKestrel(options => diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/MaxRequestBufferSizeTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/MaxRequestBufferSizeTests.cs index 0fea1d1ee4..3449b08b51 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/MaxRequestBufferSizeTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/MaxRequestBufferSizeTests.cs @@ -118,13 +118,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests // The maximum is harder to determine, since there can be OS-level buffers in both the client // and server, which allow the client to send more than maxRequestBufferSize before getting // paused. We assume the combined buffers are smaller than the difference between - // data.Length and maxRequestBufferSize. + // data.Length and maxRequestBufferSize. var maximumExpectedBytesWritten = data.Length - 1; // Block until the send task has gone a while without writing bytes AND // the bytes written exceeds the minimum expected. This indicates the server buffer // is full. - // + // // If the send task is paused before the expected number of bytes have been // written, keep waiting since the pause may have been caused by something else // like a slow machine. @@ -200,7 +200,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests // Verify client didn't send extra bytes if (context.Request.Body.ReadByte() != -1) { - context.Response.StatusCode = 500; + context.Response.StatusCode = StatusCodes.Status500InternalServerError; await context.Response.WriteAsync("Client sent more bytes than expectedBody.Length"); return; } @@ -210,7 +210,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { if (buffer[i] != expectedBody[i]) { - context.Response.StatusCode = 500; + context.Response.StatusCode = StatusCodes.Status500InternalServerError; await context.Response.WriteAsync($"Bytes received do not match expectedBody at position {i}"); return; } diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs index 468b6ef9b4..31ffb191ec 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs @@ -395,9 +395,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } [Theory] - [InlineData(204)] - [InlineData(205)] - [InlineData(304)] + [InlineData(StatusCodes.Status204NoContent)] + [InlineData(StatusCodes.Status205ResetContent)] + [InlineData(StatusCodes.Status304NotModified)] public async Task TransferEncodingChunkedNotSetOnNonBodyResponse(int statusCode) { using (var server = new TestServer(httpContext => @@ -906,7 +906,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests catch (BadHttpRequestException ex) { expectedResponse = ex.Message; - httpContext.Response.StatusCode = 400; + httpContext.Response.StatusCode = StatusCodes.Status400BadRequest; httpContext.Response.ContentLength = ex.Message.Length; await httpContext.Response.WriteAsync(ex.Message); responseWritten.Release(); diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameRequestHeadersTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameRequestHeadersTests.cs index 44e421191d..b19ca07124 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameRequestHeadersTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameRequestHeadersTests.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using System.Text; +using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Server.Kestrel; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; using Microsoft.Extensions.Primitives; @@ -248,7 +249,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var encoding = Encoding.GetEncoding("iso-8859-1"); var exception = Assert.Throws( () => headers.Append(encoding.GetBytes(key), 0, encoding.GetByteCount(key), key)); - Assert.Equal(400, exception.StatusCode); + Assert.Equal(StatusCodes.Status400BadRequest, exception.StatusCode); } } } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs index 5bf5fabb26..abbed6dfaa 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs @@ -8,6 +8,7 @@ using System.Text; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Hosting.Server; +using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Server.Kestrel; using Microsoft.AspNetCore.Server.Kestrel.Internal; @@ -189,7 +190,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var exception = Assert.Throws(() => _frame.TakeMessageHeaders(_socketInput, (FrameRequestHeaders)_frame.RequestHeaders)); Assert.Equal("Header value line folding not supported.", exception.Message); - Assert.Equal(400, exception.StatusCode); + Assert.Equal(StatusCodes.Status400BadRequest, exception.StatusCode); } [Fact] @@ -204,7 +205,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var exception = Assert.Throws(() => _frame.TakeMessageHeaders(_socketInput, (FrameRequestHeaders)_frame.RequestHeaders)); Assert.Equal("Header value line folding not supported.", exception.Message); - Assert.Equal(400, exception.StatusCode); + Assert.Equal(StatusCodes.Status400BadRequest, exception.StatusCode); } [Theory] @@ -221,7 +222,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var exception = Assert.Throws(() => _frame.TakeMessageHeaders(_socketInput, (FrameRequestHeaders)_frame.RequestHeaders)); Assert.Equal("Header value must not contain CR characters.", exception.Message); - Assert.Equal(400, exception.StatusCode); + Assert.Equal(StatusCodes.Status400BadRequest, exception.StatusCode); } [Theory] @@ -235,7 +236,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var exception = Assert.Throws(() => _frame.TakeMessageHeaders(_socketInput, (FrameRequestHeaders)_frame.RequestHeaders)); Assert.Equal("No ':' character found in header line.", exception.Message); - Assert.Equal(400, exception.StatusCode); + Assert.Equal(StatusCodes.Status400BadRequest, exception.StatusCode); } [Theory] @@ -250,7 +251,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var exception = Assert.Throws(() => _frame.TakeMessageHeaders(_socketInput, (FrameRequestHeaders)_frame.RequestHeaders)); Assert.Equal("Header line must not start with whitespace.", exception.Message); - Assert.Equal(400, exception.StatusCode); + Assert.Equal(StatusCodes.Status400BadRequest, exception.StatusCode); } [Theory] @@ -269,7 +270,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var exception = Assert.Throws(() => _frame.TakeMessageHeaders(_socketInput, (FrameRequestHeaders)_frame.RequestHeaders)); Assert.Equal("Whitespace is not allowed in header name.", exception.Message); - Assert.Equal(400, exception.StatusCode); + Assert.Equal(StatusCodes.Status400BadRequest, exception.StatusCode); } [Theory] @@ -283,7 +284,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var exception = Assert.Throws(() => _frame.TakeMessageHeaders(_socketInput, (FrameRequestHeaders)_frame.RequestHeaders)); Assert.Equal("Headers corrupted, invalid header sequence.", exception.Message); - Assert.Equal(400, exception.StatusCode); + Assert.Equal(StatusCodes.Status400BadRequest, exception.StatusCode); } [Fact] @@ -298,7 +299,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var exception = Assert.Throws(() => _frame.TakeMessageHeaders(_socketInput, (FrameRequestHeaders)_frame.RequestHeaders)); Assert.Equal("Request headers too long.", exception.Message); - Assert.Equal(431, exception.StatusCode); + Assert.Equal(StatusCodes.Status431RequestHeaderFieldsTooLarge, exception.StatusCode); } [Fact] @@ -312,7 +313,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var exception = Assert.Throws(() => _frame.TakeMessageHeaders(_socketInput, (FrameRequestHeaders)_frame.RequestHeaders)); Assert.Equal("Request contains too many headers.", exception.Message); - Assert.Equal(431, exception.StatusCode); + Assert.Equal(StatusCodes.Status431RequestHeaderFieldsTooLarge, exception.StatusCode); } [Theory] @@ -385,7 +386,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests // Assert Assert.True(_frame.HasResponseStarted); - Assert.Throws(() => ((IHttpResponseFeature)_frame).StatusCode = 404); + Assert.Throws(() => ((IHttpResponseFeature)_frame).StatusCode = StatusCodes.Status404NotFound); } [Fact] @@ -534,7 +535,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var exception = Assert.Throws(() => _frame.TakeStartLine(_socketInput)); Assert.Equal("Request line too long.", exception.Message); - Assert.Equal(414, exception.StatusCode); + Assert.Equal(StatusCodes.Status414UriTooLong, exception.StatusCode); } [Theory] @@ -556,7 +557,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var exception = Assert.Throws(() => _frame.TakeStartLine(_socketInput)); Assert.Equal(expectedExceptionMessage, exception.Message); - Assert.Equal(400, exception.StatusCode); + Assert.Equal(StatusCodes.Status400BadRequest, exception.StatusCode); } [Fact] @@ -567,7 +568,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var exception = Assert.Throws(() => _frame.TakeStartLine(_socketInput)); Assert.Equal("Unrecognized HTTP version: HTTP/1.2", exception.Message); - Assert.Equal(505, exception.StatusCode); + Assert.Equal(StatusCodes.Status505HttpVersionNotsupported, exception.StatusCode); } [Fact] @@ -578,7 +579,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var exception = Assert.Throws(() => _frame.TakeStartLine(_socketInput)); Assert.Equal("Unrecognized HTTP version: HTTP/1.1a...", exception.Message); - Assert.Equal(505, exception.StatusCode); + Assert.Equal(StatusCodes.Status505HttpVersionNotsupported, exception.StatusCode); } [Fact] @@ -647,7 +648,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests public void WriteThrowsForNonBodyResponse() { // Arrange - ((IHttpResponseFeature)_frame).StatusCode = 304; + ((IHttpResponseFeature)_frame).StatusCode = StatusCodes.Status304NotModified; // Act/Assert Assert.Throws(() => _frame.Write(new ArraySegment(new byte[1]))); @@ -658,7 +659,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { // Arrange _frame.HttpVersion = "HTTP/1.1"; - ((IHttpResponseFeature)_frame).StatusCode = 304; + ((IHttpResponseFeature)_frame).StatusCode = StatusCodes.Status304NotModified; // Act/Assert await Assert.ThrowsAsync(() => _frame.WriteAsync(new ArraySegment(new byte[1]), default(CancellationToken))); @@ -705,7 +706,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { // Arrange _frame.HttpVersion = "HTTP/1.1"; - ((IHttpResponseFeature)_frame).StatusCode = 304; + ((IHttpResponseFeature)_frame).StatusCode = StatusCodes.Status304NotModified; // Act _frame.ResponseHeaders.Add("Transfer-Encoding", "chunked"); diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/MessageBodyTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/MessageBodyTests.cs index e0f8dac560..3e11350d40 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/MessageBodyTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/MessageBodyTests.cs @@ -8,13 +8,14 @@ using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; +using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Server.Kestrel; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; +using Microsoft.AspNetCore.Testing; using Microsoft.Extensions.Internal; using Moq; using Xunit; using Xunit.Sdk; -using Microsoft.AspNetCore.Testing; namespace Microsoft.AspNetCore.Server.KestrelTests { @@ -198,7 +199,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var ex = Assert.Throws(() => MessageBody.For(HttpVersion.Http11, new FrameRequestHeaders { HeaderTransferEncoding = "chunked, not-chunked" }, input.FrameContext)); - Assert.Equal(400, ex.StatusCode); + Assert.Equal(StatusCodes.Status400BadRequest, ex.StatusCode); Assert.Equal("Final transfer coding is not \"chunked\": \"chunked, not-chunked\"", ex.Message); } } @@ -214,7 +215,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var ex = Assert.Throws(() => MessageBody.For(HttpVersion.Http11, new FrameRequestHeaders(), input.FrameContext)); - Assert.Equal(411, ex.StatusCode); + Assert.Equal(StatusCodes.Status411LengthRequired, ex.StatusCode); Assert.Equal($"{method} request contains no Content-Length or Transfer-Encoding header", ex.Message); } } @@ -230,7 +231,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var ex = Assert.Throws(() => MessageBody.For(HttpVersion.Http10, new FrameRequestHeaders(), input.FrameContext)); - Assert.Equal(400, ex.StatusCode); + Assert.Equal(StatusCodes.Status400BadRequest, ex.StatusCode); Assert.Equal($"{method} request contains no Content-Length header", ex.Message); } } @@ -249,7 +250,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests new object[] { new FrameRequestHeaders { HeaderTransferEncoding = "chunked" }, new[] { "6\r\nHello \r\n", "6\r\nWorld!\r\n0\r\n\r\n" } }, }; - public static IEnumerable CombinedData => + public static IEnumerable CombinedData => from stream in StreamData from request in RequestData select new[] { stream[0], request[0], request[1] }; From cf77813c82a2c03e5006071dffd55b15457aef73 Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Tue, 3 Jan 2017 14:23:49 -0800 Subject: [PATCH 1016/1662] Re-enable HTTPS tests (#1273). --- samples/SampleApp/project.json | 2 +- .../AddressRegistrationTests.cs | 4 ++-- .../HttpClientSlimTests.cs | 4 ++-- .../HttpsTests.cs | 5 ++--- .../LoggingConnectionAdapterTests.cs | 2 +- .../MaxRequestBufferSizeTests.cs | 2 +- .../HttpsConnectionAdapterTests.cs | 14 +++++++------- 7 files changed, 16 insertions(+), 17 deletions(-) diff --git a/samples/SampleApp/project.json b/samples/SampleApp/project.json index 557ab3faa6..c7f940c21b 100644 --- a/samples/SampleApp/project.json +++ b/samples/SampleApp/project.json @@ -28,5 +28,5 @@ "configProperties": { "System.GC.Server": true } - } + } } \ No newline at end of file diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs index 2b57c4d575..58044e3692 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs @@ -36,14 +36,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests await RegisterAddresses_Success(addressInput, testUrls); } - [Theory(Skip = "SslStream hanging on write after update to CoreFx 4.4 (https://github.com/dotnet/corefx/issues/14698)"), MemberData(nameof(IPEndPointRegistrationDataRandomPort))] + [ConditionalTheory, MemberData(nameof(IPEndPointRegistrationDataRandomPort))] [IPv6SupportedCondition] public async Task RegisterIPEndPoint_RandomPort_Success(IPEndPoint endPoint, Func testUrl) { await RegisterIPEndPoint_Success(endPoint, testUrl); } - [ConditionalTheory(Skip = "SslStream hanging on write after update to CoreFx 4.4 (https://github.com/dotnet/corefx/issues/14698)"), MemberData(nameof(IPEndPointRegistrationDataPort443))] + [ConditionalTheory, MemberData(nameof(IPEndPointRegistrationDataPort443))] [IPv6SupportedCondition] [PortSupportedCondition(443)] public async Task RegisterIPEndPoint_Port443_Success(IPEndPoint endpoint, Func testUrl) diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/HttpClientSlimTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/HttpClientSlimTests.cs index 76cd68c918..28c1b95773 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/HttpClientSlimTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/HttpClientSlimTests.cs @@ -27,7 +27,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } } - [Fact(Skip = "SslStream hanging on write after update to CoreFx 4.4 (https://github.com/dotnet/corefx/issues/14698)")] + [Fact] public async Task GetStringAsyncHttps() { using (var host = StartHost(protocol: "https")) @@ -54,7 +54,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } } - [Fact(Skip = "SslStream hanging on write after update to CoreFx 4.4 (https://github.com/dotnet/corefx/issues/14698)")] + [Fact] public async Task PostAsyncHttps() { using (var host = StartHost(protocol: "https", diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/HttpsTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/HttpsTests.cs index 85ed2e6fd6..c5c594f574 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/HttpsTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/HttpsTests.cs @@ -91,7 +91,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } // Regression test for https://github.com/aspnet/KestrelHttpServer/issues/1103#issuecomment-246971172 - [Fact(Skip = "SslStream hanging on write after update to CoreFx 4.4 (https://github.com/dotnet/corefx/issues/14698)")] + [Fact] public async Task DoesNotThrowObjectDisposedExceptionOnConnectionAbort() { var x509Certificate2 = new X509Certificate2("TestResources/testCert.pfx", "testPassword"); @@ -104,7 +104,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests listenOptions.UseHttps("TestResources/testCert.pfx", "testPassword"); }); }) - .UseUrls("https://127.0.0.1:0/") .UseLoggerFactory(loggerFactory) .Configure(app => app.Run(async httpContext => { @@ -144,7 +143,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests Assert.False(loggerFactory.ErrorLogger.ObjectDisposedExceptionLogged); } - [Fact(Skip = "SslStream hanging on write after update to CoreFx 4.4 (https://github.com/dotnet/corefx/issues/14698)")] + [Fact] public async Task DoesNotThrowObjectDisposedExceptionFromWriteAsyncAfterConnectionIsAborted() { var tcs = new TaskCompletionSource(); diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/LoggingConnectionAdapterTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/LoggingConnectionAdapterTests.cs index 6637baea9c..adff41264c 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/LoggingConnectionAdapterTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/LoggingConnectionAdapterTests.cs @@ -14,7 +14,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { public class LoggingConnectionAdapterTests { - [Fact(Skip = "SslStream hanging on write after update to CoreFx 4.4 (https://github.com/dotnet/corefx/issues/14698)")] + [Fact] public async Task LoggingConnectionFilterCanBeAddedBeforeAndAfterHttpsFilter() { var host = new WebHostBuilder() diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/MaxRequestBufferSizeTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/MaxRequestBufferSizeTests.cs index 3449b08b51..a7116d6b07 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/MaxRequestBufferSizeTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/MaxRequestBufferSizeTests.cs @@ -65,7 +65,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } } - [Theory(Skip = "SslStream hanging on write after update to CoreFx 4.4 (https://github.com/dotnet/corefx/issues/14698)")] + [Theory] [MemberData("LargeUploadData")] public async Task LargeUpload(long? maxRequestBufferSize, bool ssl, bool expectPause) { diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/HttpsConnectionAdapterTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/HttpsConnectionAdapterTests.cs index d37027adc6..0fb3642b0e 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/HttpsConnectionAdapterTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/HttpsConnectionAdapterTests.cs @@ -28,7 +28,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests // https://github.com/aspnet/KestrelHttpServer/issues/240 // This test currently fails on mono because of an issue with SslStream. - [Fact(Skip = "SslStream hanging on write after update to CoreFx 4.4 (https://github.com/dotnet/corefx/issues/14698)")] + [Fact] public async Task CanReadAndWriteWithHttpsConnectionAdapter() { var serviceContext = new TestServiceContext(); @@ -52,7 +52,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } } - [Fact(Skip = "SslStream hanging on write after update to CoreFx 4.4 (https://github.com/dotnet/corefx/issues/14698)")] + [Fact] public async Task RequireCertificateFailsWhenNoCertificate() { var serviceContext = new TestServiceContext(); @@ -76,7 +76,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } } - [Fact(Skip = "SslStream hanging on write after update to CoreFx 4.4 (https://github.com/dotnet/corefx/issues/14698)")] + [Fact] public async Task AllowCertificateContinuesWhenNoCertificate() { var serviceContext = new TestServiceContext(); @@ -139,7 +139,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } - [Fact(Skip = "SslStream hanging on write after update to CoreFx 4.4 (https://github.com/dotnet/corefx/issues/14698)")] + [Fact] public async Task CertificatePassedToHttpContext() { var serviceContext = new TestServiceContext(); @@ -178,7 +178,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } } - [Fact(Skip = "SslStream hanging on write after update to CoreFx 4.4 (https://github.com/dotnet/corefx/issues/14698)")] + [Fact] public async Task HttpsSchemePassedToRequestFeature() { var listenOptions = new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0)) @@ -197,7 +197,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } } - [Fact(Skip = "SslStream hanging on write after update to CoreFx 4.4 (https://github.com/dotnet/corefx/issues/14698)")] + [Fact] public async Task DoesNotSupportTls10() { var serviceContext = new TestServiceContext(); @@ -325,7 +325,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } } - [Fact(Skip = "SslStream hanging on write after update to CoreFx 4.4 (https://github.com/dotnet/corefx/issues/14698)")] + [Fact] public async Task CertificatePassedToHttpContextIsNotDisposed() { var serviceContext = new TestServiceContext(); From e26f91a39246bcd0ea458b4144681b942b2275ff Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Tue, 10 Jan 2017 14:12:07 -0800 Subject: [PATCH 1017/1662] Call OnStarting before verifying response length (#1289). --- .../Internal/Http/Frame.cs | 29 ++- .../ResponseTests.cs | 211 +++++++++++++++++- .../EngineTests.cs | 8 +- 3 files changed, 226 insertions(+), 22 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs index fc4ba2b202..d829c68c18 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs @@ -533,23 +533,29 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http public void Flush() { - ProduceStartAndFireOnStarting().GetAwaiter().GetResult(); + InitializeResponse(0).GetAwaiter().GetResult(); Output.Flush(); } public async Task FlushAsync(CancellationToken cancellationToken) { - await ProduceStartAndFireOnStarting(); + await InitializeResponse(0); await Output.FlushAsync(cancellationToken); } public void Write(ArraySegment data) { - // For the first write, ensure headers are flushed if Write(Chunked)isn't called. + // For the first write, ensure headers are flushed if Write(Chunked) isn't called. var firstWrite = !HasResponseStarted; - VerifyAndUpdateWrite(data.Count); - ProduceStartAndFireOnStarting().GetAwaiter().GetResult(); + if (firstWrite) + { + InitializeResponse(data.Count).GetAwaiter().GetResult(); + } + else + { + VerifyAndUpdateWrite(data.Count); + } if (_canHaveBody) { @@ -616,9 +622,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http public async Task WriteAsyncAwaited(ArraySegment data, CancellationToken cancellationToken) { - VerifyAndUpdateWrite(data.Count); - - await ProduceStartAndFireOnStarting(); + await InitializeResponseAwaited(data.Count); // WriteAsyncAwaited is only called for the first write to the body. // Ensure headers are flushed if Write(Chunked)Async isn't called. @@ -734,7 +738,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } } - public Task ProduceStartAndFireOnStarting() + public Task InitializeResponse(int firstWriteByteCount) { if (HasResponseStarted) { @@ -743,7 +747,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if (_onStarting != null) { - return ProduceStartAndFireOnStartingAwaited(); + return InitializeResponseAwaited(firstWriteByteCount); } if (_applicationException != null) @@ -751,11 +755,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http ThrowResponseAbortedException(); } + VerifyAndUpdateWrite(firstWriteByteCount); ProduceStart(appCompleted: false); + return TaskCache.CompletedTask; } - private async Task ProduceStartAndFireOnStartingAwaited() + private async Task InitializeResponseAwaited(int firstWriteByteCount) { await FireOnStarting(); @@ -764,6 +770,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http ThrowResponseAbortedException(); } + VerifyAndUpdateWrite(firstWriteByteCount); ProduceStart(appCompleted: false); } diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs index 31ffb191ec..c84b3a4663 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs @@ -485,7 +485,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } [Fact] - public async Task WhenAppWritesMoreThanContentLengthWriteThrowsAndConnectionCloses() + public async Task ThrowsAndClosesConnectionWhenAppWritesMoreThanContentLengthWrite() { var testLogger = new TestApplicationErrorLogger(); var serviceContext = new TestServiceContext { Log = new TestKestrelTrace(testLogger) }; @@ -520,7 +520,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } [Fact] - public async Task WhenAppWritesMoreThanContentLengthWriteAsyncThrowsAndConnectionCloses() + public async Task ThrowsAndClosesConnectionWhenAppWritesMoreThanContentLengthWriteAsync() { var testLogger = new TestApplicationErrorLogger(); var serviceContext = new TestServiceContext { Log = new TestKestrelTrace(testLogger) }; @@ -554,15 +554,52 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } [Fact] - public async Task WhenAppWritesMoreThanContentLengthAndResponseNotStarted500ResponseSentAndConnectionCloses() + public async Task InternalServerErrorAndConnectionClosedOnWriteWithMoreThanContentLengthAndResponseNotStarted() { var testLogger = new TestApplicationErrorLogger(); var serviceContext = new TestServiceContext { Log = new TestKestrelTrace(testLogger) }; - using (var server = new TestServer(async httpContext => + using (var server = new TestServer(httpContext => { + var response = Encoding.ASCII.GetBytes("hello, world"); httpContext.Response.ContentLength = 5; - await httpContext.Response.WriteAsync("hello, world"); + httpContext.Response.Body.Write(response, 0, response.Length); + return TaskCache.CompletedTask; + }, serviceContext)) + { + using (var connection = server.CreateConnection()) + { + await connection.Send( + "GET / HTTP/1.1", + "", + ""); + await connection.ReceiveForcedEnd( + $"HTTP/1.1 500 Internal Server Error", + "Connection: close", + $"Date: {server.Context.DateHeaderValue}", + "Content-Length: 0", + "", + ""); + } + } + + var logMessage = Assert.Single(testLogger.Messages, message => message.LogLevel == LogLevel.Error); + Assert.Equal( + $"Response Content-Length mismatch: too many bytes written (12 of 5).", + logMessage.Exception.Message); + } + + [Fact] + public async Task InternalServerErrorAndConnectionClosedOnWriteAsyncWithMoreThanContentLengthAndResponseNotStarted() + { + var testLogger = new TestApplicationErrorLogger(); + var serviceContext = new TestServiceContext { Log = new TestKestrelTrace(testLogger) }; + + using (var server = new TestServer(httpContext => + { + var response = Encoding.ASCII.GetBytes("hello, world"); + httpContext.Response.ContentLength = 5; + return httpContext.Response.Body.WriteAsync(response, 0, response.Length); }, serviceContext)) { using (var connection = server.CreateConnection()) @@ -1065,6 +1102,170 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } } + [Fact] + public async Task FirstWriteVerifiedAfterOnStarting() + { + using (var server = new TestServer(httpContext => + { + httpContext.Response.OnStarting(() => + { + // Change response to chunked + httpContext.Response.ContentLength = null; + return TaskCache.CompletedTask; + }); + + var response = Encoding.ASCII.GetBytes("hello, world"); + httpContext.Response.ContentLength = response.Length - 1; + + // If OnStarting is not run before verifying writes, an error response will be sent. + httpContext.Response.Body.Write(response, 0, response.Length); + return TaskCache.CompletedTask; + }, new TestServiceContext())) + { + using (var connection = server.CreateConnection()) + { + await connection.Send( + "GET / HTTP/1.1", + "", + ""); + await connection.Receive( + "HTTP/1.1 200 OK", + $"Date: {server.Context.DateHeaderValue}", + $"Transfer-Encoding: chunked", + "", + "c", + "hello, world", + "0", + "", + ""); + } + } + } + + [Fact] + public async Task SubsequentWriteVerifiedAfterOnStarting() + { + using (var server = new TestServer(httpContext => + { + httpContext.Response.OnStarting(() => + { + // Change response to chunked + httpContext.Response.ContentLength = null; + return TaskCache.CompletedTask; + }); + + var response = Encoding.ASCII.GetBytes("hello, world"); + httpContext.Response.ContentLength = response.Length - 1; + + // If OnStarting is not run before verifying writes, an error response will be sent. + httpContext.Response.Body.Write(response, 0, response.Length / 2); + httpContext.Response.Body.Write(response, response.Length / 2, response.Length - response.Length / 2); + return TaskCache.CompletedTask; + }, new TestServiceContext())) + { + using (var connection = server.CreateConnection()) + { + await connection.Send( + "GET / HTTP/1.1", + "", + ""); + await connection.Receive( + "HTTP/1.1 200 OK", + $"Date: {server.Context.DateHeaderValue}", + $"Transfer-Encoding: chunked", + "", + "6", + "hello,", + "6", + " world", + "0", + "", + ""); + } + } + } + + [Fact] + public async Task FirstWriteAsyncVerifiedAfterOnStarting() + { + using (var server = new TestServer(httpContext => + { + httpContext.Response.OnStarting(() => + { + // Change response to chunked + httpContext.Response.ContentLength = null; + return TaskCache.CompletedTask; + }); + + var response = Encoding.ASCII.GetBytes("hello, world"); + httpContext.Response.ContentLength = response.Length - 1; + + // If OnStarting is not run before verifying writes, an error response will be sent. + return httpContext.Response.Body.WriteAsync(response, 0, response.Length); + }, new TestServiceContext())) + { + using (var connection = server.CreateConnection()) + { + await connection.Send( + "GET / HTTP/1.1", + "", + ""); + await connection.Receive( + "HTTP/1.1 200 OK", + $"Date: {server.Context.DateHeaderValue}", + $"Transfer-Encoding: chunked", + "", + "c", + "hello, world", + "0", + "", + ""); + } + } + } + + [Fact] + public async Task SubsequentWriteAsyncVerifiedAfterOnStarting() + { + using (var server = new TestServer(async httpContext => + { + httpContext.Response.OnStarting(() => + { + // Change response to chunked + httpContext.Response.ContentLength = null; + return TaskCache.CompletedTask; + }); + + var response = Encoding.ASCII.GetBytes("hello, world"); + httpContext.Response.ContentLength = response.Length - 1; + + // If OnStarting is not run before verifying writes, an error response will be sent. + await httpContext.Response.Body.WriteAsync(response, 0, response.Length / 2); + await httpContext.Response.Body.WriteAsync(response, response.Length / 2, response.Length - response.Length / 2); + }, new TestServiceContext())) + { + using (var connection = server.CreateConnection()) + { + await connection.Send( + "GET / HTTP/1.1", + "", + ""); + await connection.Receive( + "HTTP/1.1 200 OK", + $"Date: {server.Context.DateHeaderValue}", + $"Transfer-Encoding: chunked", + "", + "6", + "hello,", + "6", + " world", + "0", + "", + ""); + } + } + } + public static TheoryData NullHeaderData { get diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs index dff37141cb..f4965d908f 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs @@ -878,11 +878,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests throw onStartingException; }, null); - response.Headers["Content-Length"] = new[] { "11" }; - - var writeException = await Assert.ThrowsAsync(async () => - await response.Body.WriteAsync(Encoding.ASCII.GetBytes("Hello World"), 0, 11)); - + var writeException = await Assert.ThrowsAsync(async () => await response.Body.FlushAsync()); Assert.Same(onStartingException, writeException.InnerException); failedWriteCount++; @@ -896,7 +892,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests "GET / HTTP/1.1", "", ""); - await connection.ReceiveEnd( + await connection.Receive( "HTTP/1.1 500 Internal Server Error", $"Date: {testContext.DateHeaderValue}", "Content-Length: 0", From 89a63d190edd69f6ae63123c6aeb2ad27cb92ef7 Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Thu, 12 Jan 2017 12:38:15 -0800 Subject: [PATCH 1018/1662] Don't close connection when Content-Length set but no bytes written. --- .../Internal/Http/Frame.cs | 8 ++++++- .../ResponseTests.cs | 20 +++++++++------- .../EngineTests.cs | 24 ++++++++----------- 3 files changed, 29 insertions(+), 23 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs index d829c68c18..66868595f2 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs @@ -695,7 +695,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http responseHeaders.HeaderContentLengthValue.HasValue && _responseBytesWritten < responseHeaders.HeaderContentLengthValue.Value) { - _keepAlive = false; + // We need to close the connection if any bytes were written since the client + // cannot be certain of how many bytes it will receive. + if (_responseBytesWritten > 0) + { + _keepAlive = false; + } + ReportApplicationError(new InvalidOperationException( $"Response Content-Length mismatch: too few bytes written ({_responseBytesWritten} of {responseHeaders.HeaderContentLengthValue.Value}).")); } diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs index c84b3a4663..edf5d39703 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs @@ -668,7 +668,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } [Fact] - public async Task WhenAppSetsContentLengthButDoesNotWriteBody500ResponseSentAndConnectionCloses() + public async Task WhenAppSetsContentLengthButDoesNotWriteBody500ResponseSentAndConnectionDoesNotClose() { var testLogger = new TestApplicationErrorLogger(); var serviceContext = new TestServiceContext { Log = new TestKestrelTrace(testLogger) }; @@ -682,12 +682,17 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests using (var connection = server.CreateConnection()) { await connection.Send( + "GET / HTTP/1.1", + "", "GET / HTTP/1.1", "", ""); - await connection.ReceiveForcedEnd( - $"HTTP/1.1 500 Internal Server Error", - "Connection: close", + await connection.Receive( + "HTTP/1.1 500 Internal Server Error", + $"Date: {server.Context.DateHeaderValue}", + "Content-Length: 0", + "", + "HTTP/1.1 500 Internal Server Error", $"Date: {server.Context.DateHeaderValue}", "Content-Length: 0", "", @@ -695,10 +700,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } } - var errorMessage = Assert.Single(testLogger.Messages, message => message.LogLevel == LogLevel.Error); - Assert.Equal( - $"Response Content-Length mismatch: too few bytes written (0 of 5).", - errorMessage.Exception.Message); + var error = testLogger.Messages.Where(message => message.LogLevel == LogLevel.Error); + Assert.Equal(2, error.Count()); + Assert.All(error, message => message.Equals("Response Content-Length mismatch: too few bytes written (0 of 5).")); } [Theory] diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs index f4965d908f..f138f063ba 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs @@ -853,12 +853,10 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [MemberData(nameof(ConnectionAdapterData))] public async Task ThrowingInOnStartingResultsInFailedWritesAnd500Response(ListenOptions listenOptions) { + var callback1Called = false; + var callback2CallCount = 0; + var testContext = new TestServiceContext(); - - var onStartingCallCount1 = 0; - var onStartingCallCount2 = 0; - var failedWriteCount = 0; - var testLogger = new TestApplicationErrorLogger(); testContext.Log = new KestrelTrace(testLogger); @@ -869,19 +867,17 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var response = httpContext.Response; response.OnStarting(_ => { - onStartingCallCount1++; + callback1Called = true; throw onStartingException; }, null); response.OnStarting(_ => { - onStartingCallCount2++; + callback2CallCount++; throw onStartingException; }, null); var writeException = await Assert.ThrowsAsync(async () => await response.Body.FlushAsync()); Assert.Same(onStartingException, writeException.InnerException); - - failedWriteCount++; }, testContext, listenOptions)) { using (var connection = server.CreateConnection()) @@ -892,7 +888,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests "GET / HTTP/1.1", "", ""); - await connection.Receive( + await connection.ReceiveEnd( "HTTP/1.1 500 Internal Server Error", $"Date: {testContext.DateHeaderValue}", "Content-Length: 0", @@ -905,10 +901,10 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } } - // The first registered OnStarting callback should not be called, - // since they are called LIFO and the other one failed. - Assert.Equal(0, onStartingCallCount1); - Assert.Equal(2, onStartingCallCount2); + // The first registered OnStarting callback should have been called, + // since they are called LIFO order and the other one failed. + Assert.False(callback1Called); + Assert.Equal(2, callback2CallCount); Assert.Equal(2, testLogger.ApplicationErrorsLogged); } From c4762cdfd5190de091d2a8b4624181a677af448e Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Tue, 17 Jan 2017 12:32:53 -0800 Subject: [PATCH 1019/1662] Better handle OnHeartbeat in 32-bit environments - Prevent potential overflow when casting a long to an IntPtr --- .../Internal/Infrastructure/KestrelThread.cs | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/KestrelThread.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/KestrelThread.cs index 87e48f5205..117efc08fc 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/KestrelThread.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/KestrelThread.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using System.Runtime.ExceptionServices; +using System.Runtime.InteropServices; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Hosting; @@ -25,8 +26,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal private static readonly Action _postAsyncCallbackAdapter = (callback, state) => ((Action)callback).Invoke(state); private static readonly Libuv.uv_walk_cb _heartbeatWalkCallback = (ptr, arg) => { - var handle = UvMemory.FromIntPtr(ptr); - (handle as UvStreamHandle)?.Connection?.Tick((long)arg); + var streamHandle = UvMemory.FromIntPtr(ptr) as UvStreamHandle; + var thisHandle = GCHandle.FromIntPtr(arg); + var kestrelThread = (KestrelThread)thisHandle.Target; + streamHandle?.Connection?.Tick(kestrelThread.Now); }; // maximum times the work queues swapped and are processed in a single pass @@ -53,6 +56,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal private readonly IKestrelTrace _log; private readonly IThreadPool _threadPool; private readonly TimeSpan _shutdownTimeout; + private IntPtr _thisPtr; public KestrelThread(KestrelEngine engine) { @@ -99,6 +103,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal private Action, IntPtr> QueueCloseAsyncHandle { get; } + // The cached result of Loop.Now() which is a timestamp in milliseconds + private long Now { get; set; } + public Task StartAsync() { var tcs = new TaskCompletionSource(); @@ -303,8 +310,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal } } + // This is used to access a 64-bit timestamp (this.Now) using a potentially 32-bit IntPtr. + var thisHandle = GCHandle.Alloc(this, GCHandleType.Weak); + try { + _thisPtr = GCHandle.ToIntPtr(thisHandle); + _loop.Run(); if (_stopImmediate) { @@ -331,6 +343,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal } finally { + thisHandle.Free(); _threadTcs.SetResult(null); } } @@ -349,7 +362,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal private void OnHeartbeat(UvTimerHandle timer) { - Walk(_heartbeatWalkCallback, (IntPtr)Loop.Now()); + Now = Loop.Now(); + Walk(_heartbeatWalkCallback, _thisPtr); } private bool DoPostWork() From 20e02e8fd6487a54f35f8731a67c3bc88816bc31 Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Fri, 13 Jan 2017 15:33:21 -0800 Subject: [PATCH 1020/1662] Don't overwhelm server with data in KeepAliveTimeoutTests.ConnectionNotTimedOutWhileRequestBeingSent(). --- .../KeepAliveTimeoutTests.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/KeepAliveTimeoutTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/KeepAliveTimeoutTests.cs index ee4a72cc57..0648c1bf57 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/KeepAliveTimeoutTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/KeepAliveTimeoutTests.cs @@ -100,6 +100,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests "1", "a", ""); + await Task.Delay(ShortDelay); } await connection.Send( From f32058c5c34aecfc894d202a9b809bf75ea05d06 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Tue, 17 Jan 2017 16:30:02 -0800 Subject: [PATCH 1021/1662] Warn instead of throw when ignoring IServerAddressesFeature - Throwing could be too much when IServerAddressesFeature URLs come from VS - Listen on 127.0.0.1:5000 by default https://github.com/aspnet/Hosting/issues/917 --- KestrelHttpServer.sln | 1 + samples/SampleApp/Startup.cs | 43 ++++++++-------- .../Internal/Infrastructure/Constants.cs | 9 +++- .../KestrelServer.cs | 28 ++++------ .../AddressRegistrationTests.cs | 31 +++++++++++ .../KestrelServerTests.cs | 51 +++++++------------ test/shared/KestrelTestLoggerFactory.cs | 33 ++++++++++++ test/shared/TestApplicationErrorLogger.cs | 9 +++- 8 files changed, 132 insertions(+), 73 deletions(-) create mode 100644 test/shared/KestrelTestLoggerFactory.cs diff --git a/KestrelHttpServer.sln b/KestrelHttpServer.sln index fd5f9367d1..5773d78aa9 100644 --- a/KestrelHttpServer.sln +++ b/KestrelHttpServer.sln @@ -36,6 +36,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "shared", "shared", "{0EF2AC ProjectSection(SolutionItems) = preProject test\shared\DummyApplication.cs = test\shared\DummyApplication.cs test\shared\HttpClientSlim.cs = test\shared\HttpClientSlim.cs + test\shared\KestrelTestLoggerFactory.cs = test\shared\KestrelTestLoggerFactory.cs test\shared\LifetimeNotImplemented.cs = test\shared\LifetimeNotImplemented.cs test\shared\MockConnection.cs = test\shared\MockConnection.cs test\shared\MockFrameControl.cs = test\shared\MockFrameControl.cs diff --git a/samples/SampleApp/Startup.cs b/samples/SampleApp/Startup.cs index 1ba9d55393..c2256120bc 100644 --- a/samples/SampleApp/Startup.cs +++ b/samples/SampleApp/Startup.cs @@ -34,33 +34,34 @@ namespace SampleApp public static void Main(string[] args) { - var hostBuilder = new WebHostBuilder().UseKestrel(options => - { - options.Listen(IPAddress.Loopback, 5000, listenOptions => + var host = new WebHostBuilder() + .UseKestrel(options => { - // Uncomment the following to enable Nagle's algorithm for this endpoint. - //listenOptions.NoDelay = false; + options.Listen(IPAddress.Loopback, 5000, listenOptions => + { + // Uncomment the following to enable Nagle's algorithm for this endpoint. + //listenOptions.NoDelay = false; - listenOptions.UseConnectionLogging(); - }); - options.Listen(IPAddress.Loopback, 5001, listenOptions => - { - listenOptions.UseHttps("testCert.pfx", "testPassword"); - listenOptions.UseConnectionLogging(); - }); + listenOptions.UseConnectionLogging(); + }); + options.Listen(IPAddress.Loopback, 5001, listenOptions => + { + listenOptions.UseHttps("testCert.pfx", "testPassword"); + listenOptions.UseConnectionLogging(); + }); - options.UseSystemd(); + options.UseSystemd(); - // The following section should be used to demo sockets - //options.ListenUnixSocket("/tmp/kestrel-test.sock"); + // The following section should be used to demo sockets + //options.ListenUnixSocket("/tmp/kestrel-test.sock"); - // Uncomment the following line to change the default number of libuv threads for all endpoints. - //options.ThreadCount = 4; - }) - .UseContentRoot(Directory.GetCurrentDirectory()) - .UseStartup(); + // Uncomment the following line to change the default number of libuv threads for all endpoints. + //options.ThreadCount = 4; + }) + .UseContentRoot(Directory.GetCurrentDirectory()) + .UseStartup() + .Build(); - var host = hostBuilder.Build(); host.Run(); } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/Constants.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/Constants.cs index 46d0bdac5a..e0f592154b 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/Constants.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/Constants.cs @@ -1,12 +1,12 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System.Net; using System.Runtime.InteropServices; -using System.Text; namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure { - internal class Constants + internal static class Constants { public const int ListenBacklog = 128; @@ -14,6 +14,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure public static readonly int? ECONNRESET = GetECONNRESET(); public static readonly int? EADDRINUSE = GetEADDRINUSE(); + /// + /// The IPEndPoint Kestrel will bind to if nothing else is specified. + /// + public static readonly IPEndPoint DefaultIPEndPoint = new IPEndPoint(IPAddress.Loopback, 5000); + /// /// Prefix of host name used to specify Unix sockets in the configuration. /// diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServer.cs b/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServer.cs index a8a9c5af66..24803a963a 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServer.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServer.cs @@ -112,22 +112,24 @@ namespace Microsoft.AspNetCore.Server.Kestrel } engine.Start(threadCount); - var atLeastOneListener = false; var listenOptions = Options.ListenOptions; + var hasListenOptions = listenOptions.Any(); + var hasServerAddresses = _serverAddresses.Addresses.Any(); - if (listenOptions.Any()) + if (hasListenOptions && hasServerAddresses) { - var addresses = _serverAddresses.Addresses; - if (addresses.SingleOrDefault() != "http://localhost:5000") - { - var joined = string.Join(", ", addresses); - throw new NotSupportedException($"Specifying address(es) '{joined}' is incompatible with also configuring endpoint(s) in UseKestrel."); - } + var joined = string.Join(", ", _serverAddresses.Addresses); + _logger.LogWarning($"Overriding address(es) '{joined}'. Binding to endpoints defined in {nameof(WebHostBuilderKestrelExtensions.UseKestrel)}() instead."); _serverAddresses.Addresses.Clear(); } - else + else if (!hasListenOptions && !hasServerAddresses) + { + _logger.LogDebug($"No listening endpoints were configured. Binding to {Constants.DefaultIPEndPoint} by default."); + listenOptions.Add(new ListenOptions(Constants.DefaultIPEndPoint)); + } + else if (!hasListenOptions) { // If no endpoints are configured directly using KestrelServerOptions, use those configured via the IServerAddressesFeature. var copiedAddresses = _serverAddresses.Addresses.ToArray(); @@ -155,7 +157,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel // If StartLocalhost doesn't throw, there is at least one listener. // The port cannot change for "localhost". _serverAddresses.Addresses.Add(parsedAddress.ToString()); - atLeastOneListener = true; } else { @@ -172,8 +173,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel foreach (var endPoint in listenOptions) { - atLeastOneListener = true; - try { _disposables.Push(engine.CreateServer(endPoint)); @@ -191,11 +190,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel // If requested port was "0", replace with assigned dynamic port. _serverAddresses.Addresses.Add(endPoint.ToString()); } - - if (!atLeastOneListener) - { - throw new InvalidOperationException("No recognized listening addresses were configured."); - } } catch (Exception ex) { diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs index 58044e3692..0357f6ab4f 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs @@ -16,6 +16,8 @@ using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http.Extensions; using Microsoft.AspNetCore.Testing; using Microsoft.AspNetCore.Testing.xunit; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using Xunit; @@ -126,6 +128,35 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } } + [ConditionalFact(Skip = "Waiting on https://github.com/aspnet/Hosting/issues/917")] + [PortSupportedCondition(5000)] + public async Task DefaultsToPort5000() + { + var testLogger = new TestApplicationErrorLogger(); + + var hostBuilder = new WebHostBuilder() + .UseKestrel() + .ConfigureServices(services => + { + services.AddSingleton(new KestrelTestLoggerFactory(testLogger)); + }) + .Configure(ConfigureEchoAddress); + + using (var host = hostBuilder.Build()) + { + host.Start(); + + var debugLog = testLogger.Messages.Single(log => log.LogLevel == LogLevel.Debug); + Assert.True(debugLog.Message.Contains("default")); + + foreach (var testUrl in new[] { "http://127.0.0.1:5000", "http://localhost:5000" }) + { + var response = await HttpClientSlim.GetStringAsync(testUrl); + Assert.Equal(new Uri(testUrl).ToString(), response); + } + } + } + [Fact] public void ThrowsWhenBindingToIPv4AddressInUse() { diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerTests.cs index 773d5180e9..bb82eac55f 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerTests.cs @@ -2,6 +2,8 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Linq; +using System.Net; using Microsoft.AspNetCore.Hosting.Server; using Microsoft.AspNetCore.Hosting.Server.Features; using Microsoft.AspNetCore.Server.Kestrel; @@ -43,16 +45,26 @@ namespace Microsoft.AspNetCore.Server.KestrelTests Assert.Equal(1, testLogger.CriticalErrorsLogged); } - [Fact] - public void StartWithEmptyAddressesThrows() + [Theory] + [InlineData("http://localhost:5000")] + [InlineData("The value of the string shouldn't matter.")] + [InlineData(null)] + public void StartWarnsWhenIgnoringIServerAddressesFeature(string ignoredAddress) { var testLogger = new TestApplicationErrorLogger(); - var server = CreateServer(new KestrelServerOptions(), testLogger); + var kestrelOptions = new KestrelServerOptions(); - var exception = Assert.Throws(() => StartDummyApplication(server)); + // Directly configuring an endpoint using Listen causes the IServerAddressesFeature to be ignored. + kestrelOptions.Listen(IPAddress.Loopback, 0); - Assert.Equal("No recognized listening addresses were configured.", exception.Message); - Assert.Equal(1, testLogger.CriticalErrorsLogged); + using (var server = CreateServer(kestrelOptions, testLogger)) + { + server.Features.Get().Addresses.Add(ignoredAddress); + StartDummyApplication(server); + + var warning = testLogger.Messages.Single(log => log.LogLevel == LogLevel.Warning); + Assert.True(warning.Message.Contains("Overriding")); + } } [Theory] @@ -87,37 +99,12 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { var lifetime = new LifetimeNotImplemented(); - return new KestrelServer(Options.Create(options), lifetime, new TestLoggerFactory(testLogger)); + return new KestrelServer(Options.Create(options), lifetime, new KestrelTestLoggerFactory(testLogger)); } private static void StartDummyApplication(IServer server) { server.Start(new DummyApplication(context => TaskCache.CompletedTask)); } - - private class TestLoggerFactory : ILoggerFactory - { - private readonly ILogger _testLogger; - - public TestLoggerFactory(ILogger testLogger) - { - _testLogger = testLogger; - } - - public ILogger CreateLogger(string categoryName) - { - return _testLogger; - } - - public void AddProvider(ILoggerProvider provider) - { - throw new NotImplementedException(); - } - - public void Dispose() - { - throw new NotImplementedException(); - } - } } } diff --git a/test/shared/KestrelTestLoggerFactory.cs b/test/shared/KestrelTestLoggerFactory.cs new file mode 100644 index 0000000000..e8dbbd3408 --- /dev/null +++ b/test/shared/KestrelTestLoggerFactory.cs @@ -0,0 +1,33 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using Microsoft.Extensions.Logging; + +namespace Microsoft.AspNetCore.Testing +{ + public class KestrelTestLoggerFactory : ILoggerFactory + { + private readonly ILogger _testLogger; + + public KestrelTestLoggerFactory(ILogger testLogger) + { + _testLogger = testLogger; + } + + public ILogger CreateLogger(string categoryName) + { + return _testLogger; + } + + public void AddProvider(ILoggerProvider provider) + { + throw new NotImplementedException(); + } + + public void Dispose() + { + throw new NotImplementedException(); + } + } +} \ No newline at end of file diff --git a/test/shared/TestApplicationErrorLogger.cs b/test/shared/TestApplicationErrorLogger.cs index 80c12a23bd..057e8435fb 100644 --- a/test/shared/TestApplicationErrorLogger.cs +++ b/test/shared/TestApplicationErrorLogger.cs @@ -38,7 +38,13 @@ namespace Microsoft.AspNetCore.Testing Console.WriteLine($"Log {logLevel}[{eventId}]: {formatter(state, exception)} {exception?.Message}"); #endif - Messages.Add(new LogMessage { LogLevel = logLevel, EventId = eventId, Exception = exception }); + Messages.Add(new LogMessage + { + LogLevel = logLevel, + EventId = eventId, + Exception = exception, + Message = formatter(state, exception) + }); } public class LogMessage @@ -46,6 +52,7 @@ namespace Microsoft.AspNetCore.Testing public LogLevel LogLevel { get; set; } public EventId EventId { get; set; } public Exception Exception { get; set; } + public string Message { get; set; } } } } From 10fe5e6fa25e95ab9acd2b3bd733e78be4315a37 Mon Sep 17 00:00:00 2001 From: Pavel Krymets Date: Tue, 10 Jan 2017 12:47:53 -0800 Subject: [PATCH 1022/1662] Fix performance tests --- .../configs/Core12Toolchain.cs | 64 +++++++++++++++++++ .../configs/CoreConfig.cs | 4 +- 2 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 test/Microsoft.AspNetCore.Server.Kestrel.Performance/configs/Core12Toolchain.cs diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/configs/Core12Toolchain.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/configs/Core12Toolchain.cs new file mode 100644 index 0000000000..d9cfdc6aca --- /dev/null +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/configs/Core12Toolchain.cs @@ -0,0 +1,64 @@ +using System; +using System.Reflection; +using BenchmarkDotNet.Characteristics; +using BenchmarkDotNet.Environments; +using BenchmarkDotNet.Loggers; +using BenchmarkDotNet.Running; +using BenchmarkDotNet.Toolchains; +using BenchmarkDotNet.Toolchains.DotNetCli; + +namespace Microsoft.AspNetCore.Server.Kestrel.Performance +{ + public class Core12Toolchain : Toolchain + { + private const string TargetFrameworkMoniker = "netcoreapp1.1"; + + public static readonly IToolchain Instance = new Core12Toolchain(); + + public Core12Toolchain() + : base("Core12", + (IGenerator) Activator.CreateInstance(typeof(Toolchain).GetTypeInfo().Assembly.GetType("BenchmarkDotNet.Toolchains.DotNetCli.DotNetCliGenerator"), + TargetFrameworkMoniker, + GetExtraDependencies(), + (Func) (_ => "x64"), // dotnet cli supports only x64 compilation now + GetImports(), + GetRuntime()), + new DotNetCliBuilder(TargetFrameworkMoniker), + (IExecutor) Activator.CreateInstance(typeof(Toolchain).GetTypeInfo().Assembly.GetType("BenchmarkDotNet.Toolchains.Executor"))) + { + } + + public override bool IsSupported(Benchmark benchmark, ILogger logger, IResolver resolver) + { + if (!base.IsSupported(benchmark, logger, resolver)) + { + return false; + } + + return true; + } + + private static string GetExtraDependencies() + { + // do not set the type to platform in order to produce exe + // https://github.com/dotnet/core/issues/77#issuecomment-219692312 + return "\"dependencies\": { \"Microsoft.NETCore.App\": { \"version\": \"1.2-*\" } },"; + } + + private static string GetImports() + { + return "[ \"dnxcore50\", \"portable-net45+win8\", \"dotnet5.6\", \"netcore50\" ]"; + } + + private static string GetRuntime() + { + var currentRuntime = Microsoft.DotNet.InternalAbstractions.RuntimeEnvironment.GetRuntimeIdentifier(); ; + if (!string.IsNullOrEmpty(currentRuntime)) + { + return $"\"runtimes\": {{ \"{currentRuntime}\": {{ }} }},"; + } + + return string.Empty; + } + } +} diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/configs/CoreConfig.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/configs/CoreConfig.cs index efdf192205..97fbd2d78e 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/configs/CoreConfig.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/configs/CoreConfig.cs @@ -22,7 +22,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance With(RunStrategy.Throughput). WithLaunchCount(3). WithWarmupCount(5). - WithTargetCount(10)); + WithTargetCount(10). + With(new Core12Toolchain()) + ); } } } From cac6ade7c95d744f37313f8567787de7de162781 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Mon, 23 Jan 2017 13:51:57 +0000 Subject: [PATCH 1023/1662] Implement Stream Flush+FlushAsync fully Streams should pass through the flush and not assume the underlying Stream's Flush behaviour --- .../Adapter/Internal/LoggingStream.cs | 5 +++++ .../Adapter/Internal/RawStream.cs | 6 +++--- .../Adapter/Internal/StreamSocketOutput.cs | 5 ++--- .../ConnectionAdapterTests.cs | 7 ++++++- 4 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Adapter/Internal/LoggingStream.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Adapter/Internal/LoggingStream.cs index 184839163c..5421093a63 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Adapter/Internal/LoggingStream.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Adapter/Internal/LoggingStream.cs @@ -71,6 +71,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Adapter.Internal _inner.Flush(); } + public override Task FlushAsync(CancellationToken cancellationToken) + { + return _inner.FlushAsync(cancellationToken); + } + public override int Read(byte[] buffer, int offset, int count) { int read = _inner.Read(buffer, offset, count); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Adapter/Internal/RawStream.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Adapter/Internal/RawStream.cs index 2c7fb8accf..0824eeb594 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Adapter/Internal/RawStream.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Adapter/Internal/RawStream.cs @@ -117,15 +117,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Adapter.Internal public override void Flush() { - // No-op since writes are immediate. + _output.Flush(); } public override Task FlushAsync(CancellationToken cancellationToken) { - // No-op since writes are immediate. - return TaskCache.CompletedTask; + return _output.FlushAsync(cancellationToken); } + private ValueTask ReadAsync(ArraySegment buffer) { return _input.ReadAsync(buffer.Array, buffer.Offset, buffer.Count); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Adapter/Internal/StreamSocketOutput.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Adapter/Internal/StreamSocketOutput.cs index e2cce039aa..a5fd6c24a0 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Adapter/Internal/StreamSocketOutput.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Adapter/Internal/StreamSocketOutput.cs @@ -8,7 +8,6 @@ using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; -using Microsoft.Extensions.Internal; namespace Microsoft.AspNetCore.Server.Kestrel.Adapter.Internal { @@ -114,14 +113,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Adapter.Internal end.Block.Pool.Return(end.Block); } - // Flush no-ops. We rely on connection filter streams to auto-flush. public void Flush() { + _outputStream.Flush(); } public Task FlushAsync(CancellationToken cancellationToken) { - return TaskCache.CompletedTask; + return _outputStream.FlushAsync(cancellationToken); } } } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionAdapterTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionAdapterTests.cs index 81fb5629c2..c842e0e83e 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionAdapterTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionAdapterTests.cs @@ -186,7 +186,12 @@ namespace Microsoft.AspNetCore.Server.KestrelTests public override void Flush() { - // No-op + _innerStream.Flush(); + } + + public override Task FlushAsync(CancellationToken cancellationToken) + { + return _innerStream.FlushAsync(cancellationToken); } public override int Read(byte[] buffer, int offset, int count) From ecca980c914f7427859a3ff968727ff1617dd5a0 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Tue, 24 Jan 2017 22:55:48 +0000 Subject: [PATCH 1024/1662] Implement IHeaderDictionary.ContentLength --- .../BadHttpRequestException.cs | 3 + .../Internal/Http/Frame.cs | 23 +- .../Internal/Http/FrameHeaders.Generated.cs | 7697 ++++++----------- .../Internal/Http/FrameHeaders.cs | 58 +- .../Internal/Http/FrameRequestHeaders.cs | 47 + .../Internal/Http/FrameResponseHeaders.cs | 33 +- .../Internal/Http/MessageBody.cs | 43 +- .../Internal/Http/RequestRejectionReason.cs | 1 + .../Infrastructure/MemoryPoolIterator.cs | 100 +- .../ResponseHeaders.cs | 209 + .../columns/RpsColumn.cs | 2 +- .../BadHttpRequestTests.cs | 15 + .../DefaultHeaderTests.cs | 4 +- .../FrameHeadersTests.cs | 63 + .../FrameRequestHeadersTests.cs | 95 +- .../FrameResponseHeadersTests.cs | 32 +- .../MemoryPoolIteratorTests.cs | 80 + .../KnownHeaders.cs | 373 +- 18 files changed, 3683 insertions(+), 5195 deletions(-) create mode 100644 test/Microsoft.AspNetCore.Server.Kestrel.Performance/ResponseHeaders.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/BadHttpRequestException.cs b/src/Microsoft.AspNetCore.Server.Kestrel/BadHttpRequestException.cs index 128040c1df..f7109710c6 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/BadHttpRequestException.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/BadHttpRequestException.cs @@ -43,6 +43,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel case RequestRejectionReason.MalformedRequestInvalidHeaders: ex = new BadHttpRequestException("Malformed request: invalid headers.", StatusCodes.Status400BadRequest); break; + case RequestRejectionReason.MultipleContentLengths: + ex = new BadHttpRequestException("Multiple Content-Length headers.", StatusCodes.Status400BadRequest); + break; case RequestRejectionReason.UnexpectedEndOfRequestContent: ex = new BadHttpRequestException("Unexpected end of request content.", StatusCodes.Status400BadRequest); break; diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs index 66868595f2..e72549c71e 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs @@ -41,7 +41,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http private static readonly byte[] _bytesConnectionKeepAlive = Encoding.ASCII.GetBytes("\r\nConnection: keep-alive"); private static readonly byte[] _bytesTransferEncodingChunked = Encoding.ASCII.GetBytes("\r\nTransfer-Encoding: chunked"); private static readonly byte[] _bytesHttpVersion11 = Encoding.ASCII.GetBytes("HTTP/1.1 "); - private static readonly byte[] _bytesContentLengthZero = Encoding.ASCII.GetBytes("\r\nContent-Length: 0"); private static readonly byte[] _bytesEndHeaders = Encoding.ASCII.GetBytes("\r\n\r\n"); private static readonly byte[] _bytesServer = Encoding.ASCII.GetBytes("\r\nServer: Kestrel"); @@ -657,12 +656,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if (responseHeaders != null && !responseHeaders.HasTransferEncoding && - responseHeaders.HasContentLength && - _responseBytesWritten + count > responseHeaders.HeaderContentLengthValue.Value) + responseHeaders.ContentLength.HasValue && + _responseBytesWritten + count > responseHeaders.ContentLength.Value) { _keepAlive = false; throw new InvalidOperationException( - $"Response Content-Length mismatch: too many bytes written ({_responseBytesWritten + count} of {responseHeaders.HeaderContentLengthValue.Value})."); + $"Response Content-Length mismatch: too many bytes written ({_responseBytesWritten + count} of {responseHeaders.ContentLength.Value})."); } _responseBytesWritten += count; @@ -679,8 +678,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http // Called after VerifyAndUpdateWrite(), so _responseBytesWritten has already been updated. if (responseHeaders != null && !responseHeaders.HasTransferEncoding && - responseHeaders.HasContentLength && - _responseBytesWritten == responseHeaders.HeaderContentLengthValue.Value) + responseHeaders.ContentLength.HasValue && + _responseBytesWritten == responseHeaders.ContentLength.Value) { _abortedCts = null; } @@ -692,8 +691,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if (!HttpMethods.IsHead(Method) && !responseHeaders.HasTransferEncoding && - responseHeaders.HeaderContentLengthValue.HasValue && - _responseBytesWritten < responseHeaders.HeaderContentLengthValue.Value) + responseHeaders.ContentLength.HasValue && + _responseBytesWritten < responseHeaders.ContentLength.Value) { // We need to close the connection if any bytes were written since the client // cannot be certain of how many bytes it will receive. @@ -703,7 +702,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } ReportApplicationError(new InvalidOperationException( - $"Response Content-Length mismatch: too few bytes written ({_responseBytesWritten} of {responseHeaders.HeaderContentLengthValue.Value}).")); + $"Response Content-Length mismatch: too few bytes written ({_responseBytesWritten} of {responseHeaders.ContentLength.Value}).")); } } @@ -920,13 +919,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http // automatically for HEAD requests or 204, 205, 304 responses. if (_canHaveBody) { - if (!hasTransferEncoding && !responseHeaders.HasContentLength) + if (!hasTransferEncoding && !responseHeaders.ContentLength.HasValue) { if (appCompleted && StatusCode != StatusCodes.Status101SwitchingProtocols) { // Since the app has completed and we are only now generating // the headers we can safely set the Content-Length to 0. - responseHeaders.SetRawContentLength("0", _bytesContentLengthZero); + responseHeaders.ContentLength = 0; } else { @@ -1468,7 +1467,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var dateHeaderValues = DateHeaderValueManager.GetDateHeaderValues(); responseHeaders.SetRawDate(dateHeaderValues.String, dateHeaderValues.Bytes); - responseHeaders.SetRawContentLength("0", _bytesContentLengthZero); + responseHeaders.ContentLength = 0; if (ServerOptions.AddServerHeader) { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameHeaders.Generated.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameHeaders.Generated.cs index eaa963843a..7cfb64ff31 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameHeaders.Generated.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameHeaders.Generated.cs @@ -5,6 +5,7 @@ using System; using System.Collections.Generic; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.Extensions.Primitives; +using Microsoft.Net.Http.Headers; namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { @@ -19,11 +20,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { get { - if (((_bits & 1L) != 0)) + StringValues value; + if ((_bits & 1L) != 0) { - return _headers._CacheControl; + value = _headers._CacheControl; } - return StringValues.Empty; + return value; } set { @@ -35,11 +37,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { get { - if (((_bits & 2L) != 0)) + StringValues value; + if ((_bits & 2L) != 0) { - return _headers._Connection; + value = _headers._Connection; } - return StringValues.Empty; + return value; } set { @@ -51,11 +54,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { get { - if (((_bits & 4L) != 0)) + StringValues value; + if ((_bits & 4L) != 0) { - return _headers._Date; + value = _headers._Date; } - return StringValues.Empty; + return value; } set { @@ -67,11 +71,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { get { - if (((_bits & 8L) != 0)) + StringValues value; + if ((_bits & 8L) != 0) { - return _headers._KeepAlive; + value = _headers._KeepAlive; } - return StringValues.Empty; + return value; } set { @@ -83,11 +88,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { get { - if (((_bits & 16L) != 0)) + StringValues value; + if ((_bits & 16L) != 0) { - return _headers._Pragma; + value = _headers._Pragma; } - return StringValues.Empty; + return value; } set { @@ -99,11 +105,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { get { - if (((_bits & 32L) != 0)) + StringValues value; + if ((_bits & 32L) != 0) { - return _headers._Trailer; + value = _headers._Trailer; } - return StringValues.Empty; + return value; } set { @@ -115,11 +122,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { get { - if (((_bits & 64L) != 0)) + StringValues value; + if ((_bits & 64L) != 0) { - return _headers._TransferEncoding; + value = _headers._TransferEncoding; } - return StringValues.Empty; + return value; } set { @@ -131,11 +139,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { get { - if (((_bits & 128L) != 0)) + StringValues value; + if ((_bits & 128L) != 0) { - return _headers._Upgrade; + value = _headers._Upgrade; } - return StringValues.Empty; + return value; } set { @@ -147,11 +156,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { get { - if (((_bits & 256L) != 0)) + StringValues value; + if ((_bits & 256L) != 0) { - return _headers._Via; + value = _headers._Via; } - return StringValues.Empty; + return value; } set { @@ -163,11 +173,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { get { - if (((_bits & 512L) != 0)) + StringValues value; + if ((_bits & 512L) != 0) { - return _headers._Warning; + value = _headers._Warning; } - return StringValues.Empty; + return value; } set { @@ -179,11 +190,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { get { - if (((_bits & 1024L) != 0)) + StringValues value; + if ((_bits & 1024L) != 0) { - return _headers._Allow; + value = _headers._Allow; } - return StringValues.Empty; + return value; } set { @@ -191,35 +203,20 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _headers._Allow = value; } } - public StringValues HeaderContentLength - { - get - { - if (((_bits & 2048L) != 0)) - { - return _headers._ContentLength; - } - return StringValues.Empty; - } - set - { - _bits |= 2048L; - _headers._ContentLength = value; - } - } public StringValues HeaderContentType { get { - if (((_bits & 4096L) != 0)) + StringValues value; + if ((_bits & 2048L) != 0) { - return _headers._ContentType; + value = _headers._ContentType; } - return StringValues.Empty; + return value; } set { - _bits |= 4096L; + _bits |= 2048L; _headers._ContentType = value; } } @@ -227,15 +224,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { get { - if (((_bits & 8192L) != 0)) + StringValues value; + if ((_bits & 4096L) != 0) { - return _headers._ContentEncoding; + value = _headers._ContentEncoding; } - return StringValues.Empty; + return value; } set { - _bits |= 8192L; + _bits |= 4096L; _headers._ContentEncoding = value; } } @@ -243,15 +241,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { get { - if (((_bits & 16384L) != 0)) + StringValues value; + if ((_bits & 8192L) != 0) { - return _headers._ContentLanguage; + value = _headers._ContentLanguage; } - return StringValues.Empty; + return value; } set { - _bits |= 16384L; + _bits |= 8192L; _headers._ContentLanguage = value; } } @@ -259,15 +258,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { get { - if (((_bits & 32768L) != 0)) + StringValues value; + if ((_bits & 16384L) != 0) { - return _headers._ContentLocation; + value = _headers._ContentLocation; } - return StringValues.Empty; + return value; } set { - _bits |= 32768L; + _bits |= 16384L; _headers._ContentLocation = value; } } @@ -275,15 +275,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { get { - if (((_bits & 65536L) != 0)) + StringValues value; + if ((_bits & 32768L) != 0) { - return _headers._ContentMD5; + value = _headers._ContentMD5; } - return StringValues.Empty; + return value; } set { - _bits |= 65536L; + _bits |= 32768L; _headers._ContentMD5 = value; } } @@ -291,15 +292,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { get { - if (((_bits & 131072L) != 0)) + StringValues value; + if ((_bits & 65536L) != 0) { - return _headers._ContentRange; + value = _headers._ContentRange; } - return StringValues.Empty; + return value; } set { - _bits |= 131072L; + _bits |= 65536L; _headers._ContentRange = value; } } @@ -307,15 +309,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { get { - if (((_bits & 262144L) != 0)) + StringValues value; + if ((_bits & 131072L) != 0) { - return _headers._Expires; + value = _headers._Expires; } - return StringValues.Empty; + return value; } set { - _bits |= 262144L; + _bits |= 131072L; _headers._Expires = value; } } @@ -323,15 +326,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { get { - if (((_bits & 524288L) != 0)) + StringValues value; + if ((_bits & 262144L) != 0) { - return _headers._LastModified; + value = _headers._LastModified; } - return StringValues.Empty; + return value; } set { - _bits |= 524288L; + _bits |= 262144L; _headers._LastModified = value; } } @@ -339,15 +343,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { get { - if (((_bits & 1048576L) != 0)) + StringValues value; + if ((_bits & 524288L) != 0) { - return _headers._Accept; + value = _headers._Accept; } - return StringValues.Empty; + return value; } set { - _bits |= 1048576L; + _bits |= 524288L; _headers._Accept = value; } } @@ -355,15 +360,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { get { - if (((_bits & 2097152L) != 0)) + StringValues value; + if ((_bits & 1048576L) != 0) { - return _headers._AcceptCharset; + value = _headers._AcceptCharset; } - return StringValues.Empty; + return value; } set { - _bits |= 2097152L; + _bits |= 1048576L; _headers._AcceptCharset = value; } } @@ -371,15 +377,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { get { - if (((_bits & 4194304L) != 0)) + StringValues value; + if ((_bits & 2097152L) != 0) { - return _headers._AcceptEncoding; + value = _headers._AcceptEncoding; } - return StringValues.Empty; + return value; } set { - _bits |= 4194304L; + _bits |= 2097152L; _headers._AcceptEncoding = value; } } @@ -387,15 +394,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { get { - if (((_bits & 8388608L) != 0)) + StringValues value; + if ((_bits & 4194304L) != 0) { - return _headers._AcceptLanguage; + value = _headers._AcceptLanguage; } - return StringValues.Empty; + return value; } set { - _bits |= 8388608L; + _bits |= 4194304L; _headers._AcceptLanguage = value; } } @@ -403,15 +411,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { get { - if (((_bits & 16777216L) != 0)) + StringValues value; + if ((_bits & 8388608L) != 0) { - return _headers._Authorization; + value = _headers._Authorization; } - return StringValues.Empty; + return value; } set { - _bits |= 16777216L; + _bits |= 8388608L; _headers._Authorization = value; } } @@ -419,15 +428,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { get { - if (((_bits & 33554432L) != 0)) + StringValues value; + if ((_bits & 16777216L) != 0) { - return _headers._Cookie; + value = _headers._Cookie; } - return StringValues.Empty; + return value; } set { - _bits |= 33554432L; + _bits |= 16777216L; _headers._Cookie = value; } } @@ -435,15 +445,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { get { - if (((_bits & 67108864L) != 0)) + StringValues value; + if ((_bits & 33554432L) != 0) { - return _headers._Expect; + value = _headers._Expect; } - return StringValues.Empty; + return value; } set { - _bits |= 67108864L; + _bits |= 33554432L; _headers._Expect = value; } } @@ -451,15 +462,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { get { - if (((_bits & 134217728L) != 0)) + StringValues value; + if ((_bits & 67108864L) != 0) { - return _headers._From; + value = _headers._From; } - return StringValues.Empty; + return value; } set { - _bits |= 134217728L; + _bits |= 67108864L; _headers._From = value; } } @@ -467,15 +479,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { get { - if (((_bits & 268435456L) != 0)) + StringValues value; + if ((_bits & 134217728L) != 0) { - return _headers._Host; + value = _headers._Host; } - return StringValues.Empty; + return value; } set { - _bits |= 268435456L; + _bits |= 134217728L; _headers._Host = value; } } @@ -483,15 +496,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { get { - if (((_bits & 536870912L) != 0)) + StringValues value; + if ((_bits & 268435456L) != 0) { - return _headers._IfMatch; + value = _headers._IfMatch; } - return StringValues.Empty; + return value; } set { - _bits |= 536870912L; + _bits |= 268435456L; _headers._IfMatch = value; } } @@ -499,15 +513,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { get { - if (((_bits & 1073741824L) != 0)) + StringValues value; + if ((_bits & 536870912L) != 0) { - return _headers._IfModifiedSince; + value = _headers._IfModifiedSince; } - return StringValues.Empty; + return value; } set { - _bits |= 1073741824L; + _bits |= 536870912L; _headers._IfModifiedSince = value; } } @@ -515,15 +530,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { get { - if (((_bits & 2147483648L) != 0)) + StringValues value; + if ((_bits & 1073741824L) != 0) { - return _headers._IfNoneMatch; + value = _headers._IfNoneMatch; } - return StringValues.Empty; + return value; } set { - _bits |= 2147483648L; + _bits |= 1073741824L; _headers._IfNoneMatch = value; } } @@ -531,15 +547,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { get { - if (((_bits & 4294967296L) != 0)) + StringValues value; + if ((_bits & 2147483648L) != 0) { - return _headers._IfRange; + value = _headers._IfRange; } - return StringValues.Empty; + return value; } set { - _bits |= 4294967296L; + _bits |= 2147483648L; _headers._IfRange = value; } } @@ -547,15 +564,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { get { - if (((_bits & 8589934592L) != 0)) + StringValues value; + if ((_bits & 4294967296L) != 0) { - return _headers._IfUnmodifiedSince; + value = _headers._IfUnmodifiedSince; } - return StringValues.Empty; + return value; } set { - _bits |= 8589934592L; + _bits |= 4294967296L; _headers._IfUnmodifiedSince = value; } } @@ -563,15 +581,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { get { - if (((_bits & 17179869184L) != 0)) + StringValues value; + if ((_bits & 8589934592L) != 0) { - return _headers._MaxForwards; + value = _headers._MaxForwards; } - return StringValues.Empty; + return value; } set { - _bits |= 17179869184L; + _bits |= 8589934592L; _headers._MaxForwards = value; } } @@ -579,15 +598,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { get { - if (((_bits & 34359738368L) != 0)) + StringValues value; + if ((_bits & 17179869184L) != 0) { - return _headers._ProxyAuthorization; + value = _headers._ProxyAuthorization; } - return StringValues.Empty; + return value; } set { - _bits |= 34359738368L; + _bits |= 17179869184L; _headers._ProxyAuthorization = value; } } @@ -595,15 +615,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { get { - if (((_bits & 68719476736L) != 0)) + StringValues value; + if ((_bits & 34359738368L) != 0) { - return _headers._Referer; + value = _headers._Referer; } - return StringValues.Empty; + return value; } set { - _bits |= 68719476736L; + _bits |= 34359738368L; _headers._Referer = value; } } @@ -611,15 +632,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { get { - if (((_bits & 137438953472L) != 0)) + StringValues value; + if ((_bits & 68719476736L) != 0) { - return _headers._Range; + value = _headers._Range; } - return StringValues.Empty; + return value; } set { - _bits |= 137438953472L; + _bits |= 68719476736L; _headers._Range = value; } } @@ -627,15 +649,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { get { - if (((_bits & 274877906944L) != 0)) + StringValues value; + if ((_bits & 137438953472L) != 0) { - return _headers._TE; + value = _headers._TE; } - return StringValues.Empty; + return value; } set { - _bits |= 274877906944L; + _bits |= 137438953472L; _headers._TE = value; } } @@ -643,15 +666,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { get { - if (((_bits & 549755813888L) != 0)) + StringValues value; + if ((_bits & 274877906944L) != 0) { - return _headers._Translate; + value = _headers._Translate; } - return StringValues.Empty; + return value; } set { - _bits |= 549755813888L; + _bits |= 274877906944L; _headers._Translate = value; } } @@ -659,15 +683,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { get { - if (((_bits & 1099511627776L) != 0)) + StringValues value; + if ((_bits & 549755813888L) != 0) { - return _headers._UserAgent; + value = _headers._UserAgent; } - return StringValues.Empty; + return value; } set { - _bits |= 1099511627776L; + _bits |= 549755813888L; _headers._UserAgent = value; } } @@ -675,15 +700,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { get { - if (((_bits & 2199023255552L) != 0)) + StringValues value; + if ((_bits & 1099511627776L) != 0) { - return _headers._Origin; + value = _headers._Origin; } - return StringValues.Empty; + return value; } set { - _bits |= 2199023255552L; + _bits |= 1099511627776L; _headers._Origin = value; } } @@ -691,15 +717,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { get { - if (((_bits & 4398046511104L) != 0)) + StringValues value; + if ((_bits & 2199023255552L) != 0) { - return _headers._AccessControlRequestMethod; + value = _headers._AccessControlRequestMethod; } - return StringValues.Empty; + return value; } set { - _bits |= 4398046511104L; + _bits |= 2199023255552L; _headers._AccessControlRequestMethod = value; } } @@ -707,637 +734,41 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { get { - if (((_bits & 8796093022208L) != 0)) + StringValues value; + if ((_bits & 4398046511104L) != 0) { - return _headers._AccessControlRequestHeaders; + value = _headers._AccessControlRequestHeaders; } - return StringValues.Empty; + return value; } set { - _bits |= 8796093022208L; + _bits |= 4398046511104L; _headers._AccessControlRequestHeaders = value; } } - + public StringValues HeaderContentLength + { + get + { + StringValues value; + if (_contentLength.HasValue) + { + value = new StringValues(HeaderUtilities.FormatInt64(_contentLength.Value)); + } + return value; + } + set + { + _contentLength = ParseContentLength(value); + } + } + protected override int GetCountFast() { - return BitCount(_bits) + (MaybeUnknown?.Count ?? 0); + return (_contentLength.HasValue ? 1 : 0 ) + BitCount(_bits) + (MaybeUnknown?.Count ?? 0); } - protected override StringValues GetValueFast(string key) - { - switch (key.Length) - { - case 13: - { - if ("Cache-Control".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 1L) != 0)) - { - return _headers._CacheControl; - } - else - { - ThrowKeyNotFoundException(); - } - } - - if ("Content-Range".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 131072L) != 0)) - { - return _headers._ContentRange; - } - else - { - ThrowKeyNotFoundException(); - } - } - - if ("Last-Modified".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 524288L) != 0)) - { - return _headers._LastModified; - } - else - { - ThrowKeyNotFoundException(); - } - } - - if ("Authorization".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 16777216L) != 0)) - { - return _headers._Authorization; - } - else - { - ThrowKeyNotFoundException(); - } - } - - if ("If-None-Match".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 2147483648L) != 0)) - { - return _headers._IfNoneMatch; - } - else - { - ThrowKeyNotFoundException(); - } - } - } - break; - case 10: - { - if ("Connection".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 2L) != 0)) - { - return _headers._Connection; - } - else - { - ThrowKeyNotFoundException(); - } - } - - if ("Keep-Alive".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 8L) != 0)) - { - return _headers._KeepAlive; - } - else - { - ThrowKeyNotFoundException(); - } - } - - if ("User-Agent".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 1099511627776L) != 0)) - { - return _headers._UserAgent; - } - else - { - ThrowKeyNotFoundException(); - } - } - } - break; - - case 4: - { - if ("Date".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 4L) != 0)) - { - return _headers._Date; - } - else - { - ThrowKeyNotFoundException(); - } - } - - if ("From".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 134217728L) != 0)) - { - return _headers._From; - } - else - { - ThrowKeyNotFoundException(); - } - } - - if ("Host".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 268435456L) != 0)) - { - return _headers._Host; - } - else - { - ThrowKeyNotFoundException(); - } - } - } - break; - - case 6: - { - if ("Pragma".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 16L) != 0)) - { - return _headers._Pragma; - } - else - { - ThrowKeyNotFoundException(); - } - } - - if ("Accept".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 1048576L) != 0)) - { - return _headers._Accept; - } - else - { - ThrowKeyNotFoundException(); - } - } - - if ("Cookie".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 33554432L) != 0)) - { - return _headers._Cookie; - } - else - { - ThrowKeyNotFoundException(); - } - } - - if ("Expect".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 67108864L) != 0)) - { - return _headers._Expect; - } - else - { - ThrowKeyNotFoundException(); - } - } - - if ("Origin".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 2199023255552L) != 0)) - { - return _headers._Origin; - } - else - { - ThrowKeyNotFoundException(); - } - } - } - break; - - case 7: - { - if ("Trailer".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 32L) != 0)) - { - return _headers._Trailer; - } - else - { - ThrowKeyNotFoundException(); - } - } - - if ("Upgrade".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 128L) != 0)) - { - return _headers._Upgrade; - } - else - { - ThrowKeyNotFoundException(); - } - } - - if ("Warning".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 512L) != 0)) - { - return _headers._Warning; - } - else - { - ThrowKeyNotFoundException(); - } - } - - if ("Expires".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 262144L) != 0)) - { - return _headers._Expires; - } - else - { - ThrowKeyNotFoundException(); - } - } - - if ("Referer".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 68719476736L) != 0)) - { - return _headers._Referer; - } - else - { - ThrowKeyNotFoundException(); - } - } - } - break; - - case 17: - { - if ("Transfer-Encoding".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 64L) != 0)) - { - return _headers._TransferEncoding; - } - else - { - ThrowKeyNotFoundException(); - } - } - - if ("If-Modified-Since".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 1073741824L) != 0)) - { - return _headers._IfModifiedSince; - } - else - { - ThrowKeyNotFoundException(); - } - } - } - break; - - case 3: - { - if ("Via".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 256L) != 0)) - { - return _headers._Via; - } - else - { - ThrowKeyNotFoundException(); - } - } - } - break; - - case 5: - { - if ("Allow".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 1024L) != 0)) - { - return _headers._Allow; - } - else - { - ThrowKeyNotFoundException(); - } - } - - if ("Range".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 137438953472L) != 0)) - { - return _headers._Range; - } - else - { - ThrowKeyNotFoundException(); - } - } - } - break; - - case 14: - { - if ("Content-Length".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 2048L) != 0)) - { - return _headers._ContentLength; - } - else - { - ThrowKeyNotFoundException(); - } - } - - if ("Accept-Charset".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 2097152L) != 0)) - { - return _headers._AcceptCharset; - } - else - { - ThrowKeyNotFoundException(); - } - } - } - break; - - case 12: - { - if ("Content-Type".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 4096L) != 0)) - { - return _headers._ContentType; - } - else - { - ThrowKeyNotFoundException(); - } - } - - if ("Max-Forwards".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 17179869184L) != 0)) - { - return _headers._MaxForwards; - } - else - { - ThrowKeyNotFoundException(); - } - } - } - break; - - case 16: - { - if ("Content-Encoding".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 8192L) != 0)) - { - return _headers._ContentEncoding; - } - else - { - ThrowKeyNotFoundException(); - } - } - - if ("Content-Language".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 16384L) != 0)) - { - return _headers._ContentLanguage; - } - else - { - ThrowKeyNotFoundException(); - } - } - - if ("Content-Location".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 32768L) != 0)) - { - return _headers._ContentLocation; - } - else - { - ThrowKeyNotFoundException(); - } - } - } - break; - - case 11: - { - if ("Content-MD5".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 65536L) != 0)) - { - return _headers._ContentMD5; - } - else - { - ThrowKeyNotFoundException(); - } - } - } - break; - - case 15: - { - if ("Accept-Encoding".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 4194304L) != 0)) - { - return _headers._AcceptEncoding; - } - else - { - ThrowKeyNotFoundException(); - } - } - - if ("Accept-Language".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 8388608L) != 0)) - { - return _headers._AcceptLanguage; - } - else - { - ThrowKeyNotFoundException(); - } - } - } - break; - - case 8: - { - if ("If-Match".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 536870912L) != 0)) - { - return _headers._IfMatch; - } - else - { - ThrowKeyNotFoundException(); - } - } - - if ("If-Range".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 4294967296L) != 0)) - { - return _headers._IfRange; - } - else - { - ThrowKeyNotFoundException(); - } - } - } - break; - - case 19: - { - if ("If-Unmodified-Since".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 8589934592L) != 0)) - { - return _headers._IfUnmodifiedSince; - } - else - { - ThrowKeyNotFoundException(); - } - } - - if ("Proxy-Authorization".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 34359738368L) != 0)) - { - return _headers._ProxyAuthorization; - } - else - { - ThrowKeyNotFoundException(); - } - } - } - break; - - case 2: - { - if ("TE".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 274877906944L) != 0)) - { - return _headers._TE; - } - else - { - ThrowKeyNotFoundException(); - } - } - } - break; - - case 9: - { - if ("Translate".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 549755813888L) != 0)) - { - return _headers._Translate; - } - else - { - ThrowKeyNotFoundException(); - } - } - } - break; - - case 29: - { - if ("Access-Control-Request-Method".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 4398046511104L) != 0)) - { - return _headers._AccessControlRequestMethod; - } - else - { - ThrowKeyNotFoundException(); - } - } - } - break; - - case 30: - { - if ("Access-Control-Request-Headers".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 8796093022208L) != 0)) - { - return _headers._AccessControlRequestHeaders; - } - else - { - ThrowKeyNotFoundException(); - } - } - } - break; -} - if (MaybeUnknown == null) - { - ThrowKeyNotFoundException(); - } - return MaybeUnknown[key]; - } protected override bool TryGetValueFast(string key, out StringValues value) { switch (key.Length) @@ -1346,700 +777,481 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { if ("Cache-Control".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 1L) != 0)) + if ((_bits & 1L) != 0) { value = _headers._CacheControl; return true; } - else - { - value = StringValues.Empty; - return false; - } + return false; } - if ("Content-Range".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 131072L) != 0)) + if ((_bits & 65536L) != 0) { value = _headers._ContentRange; return true; } - else - { - value = StringValues.Empty; - return false; - } + return false; } - if ("Last-Modified".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 524288L) != 0)) + if ((_bits & 262144L) != 0) { value = _headers._LastModified; return true; } - else - { - value = StringValues.Empty; - return false; - } + return false; } - if ("Authorization".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 16777216L) != 0)) + if ((_bits & 8388608L) != 0) { value = _headers._Authorization; return true; } - else - { - value = StringValues.Empty; - return false; - } + return false; } - if ("If-None-Match".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 2147483648L) != 0)) + if ((_bits & 1073741824L) != 0) { value = _headers._IfNoneMatch; return true; } - else - { - value = StringValues.Empty; - return false; - } + return false; } } break; - case 10: { if ("Connection".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 2L) != 0)) + if ((_bits & 2L) != 0) { value = _headers._Connection; return true; } - else - { - value = StringValues.Empty; - return false; - } + return false; } - if ("Keep-Alive".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 8L) != 0)) + if ((_bits & 8L) != 0) { value = _headers._KeepAlive; return true; } - else - { - value = StringValues.Empty; - return false; - } + return false; } - if ("User-Agent".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 1099511627776L) != 0)) + if ((_bits & 549755813888L) != 0) { value = _headers._UserAgent; return true; } - else - { - value = StringValues.Empty; - return false; - } + return false; } } break; - case 4: { if ("Date".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 4L) != 0)) + if ((_bits & 4L) != 0) { value = _headers._Date; return true; } - else - { - value = StringValues.Empty; - return false; - } + return false; } - if ("From".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 134217728L) != 0)) + if ((_bits & 67108864L) != 0) { value = _headers._From; return true; } - else - { - value = StringValues.Empty; - return false; - } + return false; } - if ("Host".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 268435456L) != 0)) + if ((_bits & 134217728L) != 0) { value = _headers._Host; return true; } - else - { - value = StringValues.Empty; - return false; - } + return false; } } break; - case 6: { if ("Pragma".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 16L) != 0)) + if ((_bits & 16L) != 0) { value = _headers._Pragma; return true; } - else - { - value = StringValues.Empty; - return false; - } + return false; } - if ("Accept".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 1048576L) != 0)) + if ((_bits & 524288L) != 0) { value = _headers._Accept; return true; } - else - { - value = StringValues.Empty; - return false; - } + return false; } - if ("Cookie".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 33554432L) != 0)) + if ((_bits & 16777216L) != 0) { value = _headers._Cookie; return true; } - else - { - value = StringValues.Empty; - return false; - } + return false; } - if ("Expect".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 67108864L) != 0)) + if ((_bits & 33554432L) != 0) { value = _headers._Expect; return true; } - else - { - value = StringValues.Empty; - return false; - } + return false; } - if ("Origin".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 2199023255552L) != 0)) + if ((_bits & 1099511627776L) != 0) { value = _headers._Origin; return true; } - else - { - value = StringValues.Empty; - return false; - } + return false; } } break; - case 7: { if ("Trailer".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 32L) != 0)) + if ((_bits & 32L) != 0) { value = _headers._Trailer; return true; } - else - { - value = StringValues.Empty; - return false; - } + return false; } - if ("Upgrade".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 128L) != 0)) + if ((_bits & 128L) != 0) { value = _headers._Upgrade; return true; } - else - { - value = StringValues.Empty; - return false; - } + return false; } - if ("Warning".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 512L) != 0)) + if ((_bits & 512L) != 0) { value = _headers._Warning; return true; } - else - { - value = StringValues.Empty; - return false; - } + return false; } - if ("Expires".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 262144L) != 0)) + if ((_bits & 131072L) != 0) { value = _headers._Expires; return true; } - else - { - value = StringValues.Empty; - return false; - } + return false; } - if ("Referer".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 68719476736L) != 0)) + if ((_bits & 34359738368L) != 0) { value = _headers._Referer; return true; } - else - { - value = StringValues.Empty; - return false; - } + return false; } } break; - case 17: { if ("Transfer-Encoding".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 64L) != 0)) + if ((_bits & 64L) != 0) { value = _headers._TransferEncoding; return true; } - else - { - value = StringValues.Empty; - return false; - } + return false; } - if ("If-Modified-Since".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 1073741824L) != 0)) + if ((_bits & 536870912L) != 0) { value = _headers._IfModifiedSince; return true; } - else - { - value = StringValues.Empty; - return false; - } + return false; } } break; - case 3: { if ("Via".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 256L) != 0)) + if ((_bits & 256L) != 0) { value = _headers._Via; return true; } - else - { - value = StringValues.Empty; - return false; - } + return false; } } break; - case 5: { if ("Allow".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 1024L) != 0)) + if ((_bits & 1024L) != 0) { value = _headers._Allow; return true; } - else - { - value = StringValues.Empty; - return false; - } + return false; } - if ("Range".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 137438953472L) != 0)) + if ((_bits & 68719476736L) != 0) { value = _headers._Range; return true; } - else - { - value = StringValues.Empty; - return false; - } + return false; } } break; - - case 14: - { - if ("Content-Length".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 2048L) != 0)) - { - value = _headers._ContentLength; - return true; - } - else - { - value = StringValues.Empty; - return false; - } - } - - if ("Accept-Charset".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 2097152L) != 0)) - { - value = _headers._AcceptCharset; - return true; - } - else - { - value = StringValues.Empty; - return false; - } - } - } - break; - case 12: { if ("Content-Type".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 4096L) != 0)) + if ((_bits & 2048L) != 0) { value = _headers._ContentType; return true; } - else - { - value = StringValues.Empty; - return false; - } + return false; } - if ("Max-Forwards".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 17179869184L) != 0)) + if ((_bits & 8589934592L) != 0) { value = _headers._MaxForwards; return true; } - else - { - value = StringValues.Empty; - return false; - } + return false; } } break; - case 16: { if ("Content-Encoding".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 8192L) != 0)) + if ((_bits & 4096L) != 0) { value = _headers._ContentEncoding; return true; } - else - { - value = StringValues.Empty; - return false; - } + return false; } - if ("Content-Language".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 16384L) != 0)) + if ((_bits & 8192L) != 0) { value = _headers._ContentLanguage; return true; } - else - { - value = StringValues.Empty; - return false; - } + return false; } - if ("Content-Location".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 32768L) != 0)) + if ((_bits & 16384L) != 0) { value = _headers._ContentLocation; return true; } - else - { - value = StringValues.Empty; - return false; - } + return false; } } break; - case 11: { if ("Content-MD5".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 65536L) != 0)) + if ((_bits & 32768L) != 0) { value = _headers._ContentMD5; return true; } - else - { - value = StringValues.Empty; - return false; - } + return false; + } + } + break; + case 14: + { + if ("Accept-Charset".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if ((_bits & 1048576L) != 0) + { + value = _headers._AcceptCharset; + return true; + } + return false; + } + if ("Content-Length".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (_contentLength.HasValue) + { + value = HeaderUtilities.FormatInt64(_contentLength.Value); + return true; + } + return false; } } break; - case 15: { if ("Accept-Encoding".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 4194304L) != 0)) + if ((_bits & 2097152L) != 0) { value = _headers._AcceptEncoding; return true; } - else - { - value = StringValues.Empty; - return false; - } + return false; } - if ("Accept-Language".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 8388608L) != 0)) + if ((_bits & 4194304L) != 0) { value = _headers._AcceptLanguage; return true; } - else - { - value = StringValues.Empty; - return false; - } + return false; } } break; - case 8: { if ("If-Match".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 536870912L) != 0)) + if ((_bits & 268435456L) != 0) { value = _headers._IfMatch; return true; } - else - { - value = StringValues.Empty; - return false; - } + return false; } - if ("If-Range".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 4294967296L) != 0)) + if ((_bits & 2147483648L) != 0) { value = _headers._IfRange; return true; } - else - { - value = StringValues.Empty; - return false; - } + return false; } } break; - case 19: { if ("If-Unmodified-Since".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 8589934592L) != 0)) + if ((_bits & 4294967296L) != 0) { value = _headers._IfUnmodifiedSince; return true; } - else - { - value = StringValues.Empty; - return false; - } + return false; } - if ("Proxy-Authorization".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 34359738368L) != 0)) + if ((_bits & 17179869184L) != 0) { value = _headers._ProxyAuthorization; return true; } - else - { - value = StringValues.Empty; - return false; - } + return false; } } break; - case 2: { if ("TE".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 274877906944L) != 0)) + if ((_bits & 137438953472L) != 0) { value = _headers._TE; return true; } - else - { - value = StringValues.Empty; - return false; - } + return false; } } break; - case 9: { if ("Translate".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 549755813888L) != 0)) + if ((_bits & 274877906944L) != 0) { value = _headers._Translate; return true; } - else - { - value = StringValues.Empty; - return false; - } + return false; } } break; - case 29: { if ("Access-Control-Request-Method".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 4398046511104L) != 0)) + if ((_bits & 2199023255552L) != 0) { value = _headers._AccessControlRequestMethod; return true; } - else - { - value = StringValues.Empty; - return false; - } + return false; } } break; - case 30: { if ("Access-Control-Request-Headers".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 8796093022208L) != 0)) + if ((_bits & 4398046511104L) != 0) { value = _headers._AccessControlRequestHeaders; return true; } - else - { - value = StringValues.Empty; - return false; - } + return false; } } break; -} - value = StringValues.Empty; + } + return MaybeUnknown?.TryGetValue(key, out value) ?? false; } + protected override void SetValueFast(string key, StringValues value) { - switch (key.Length) { case 13: @@ -2050,37 +1262,32 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _headers._CacheControl = value; return; } - if ("Content-Range".Equals(key, StringComparison.OrdinalIgnoreCase)) { - _bits |= 131072L; + _bits |= 65536L; _headers._ContentRange = value; return; } - if ("Last-Modified".Equals(key, StringComparison.OrdinalIgnoreCase)) { - _bits |= 524288L; + _bits |= 262144L; _headers._LastModified = value; return; } - if ("Authorization".Equals(key, StringComparison.OrdinalIgnoreCase)) { - _bits |= 16777216L; + _bits |= 8388608L; _headers._Authorization = value; return; } - if ("If-None-Match".Equals(key, StringComparison.OrdinalIgnoreCase)) { - _bits |= 2147483648L; + _bits |= 1073741824L; _headers._IfNoneMatch = value; return; } } break; - case 10: { if ("Connection".Equals(key, StringComparison.OrdinalIgnoreCase)) @@ -2089,23 +1296,20 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _headers._Connection = value; return; } - if ("Keep-Alive".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 8L; _headers._KeepAlive = value; return; } - if ("User-Agent".Equals(key, StringComparison.OrdinalIgnoreCase)) { - _bits |= 1099511627776L; + _bits |= 549755813888L; _headers._UserAgent = value; return; } } break; - case 4: { if ("Date".Equals(key, StringComparison.OrdinalIgnoreCase)) @@ -2114,23 +1318,20 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _headers._Date = value; return; } - if ("From".Equals(key, StringComparison.OrdinalIgnoreCase)) { - _bits |= 134217728L; + _bits |= 67108864L; _headers._From = value; return; } - if ("Host".Equals(key, StringComparison.OrdinalIgnoreCase)) { - _bits |= 268435456L; + _bits |= 134217728L; _headers._Host = value; return; } } break; - case 6: { if ("Pragma".Equals(key, StringComparison.OrdinalIgnoreCase)) @@ -2139,37 +1340,32 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _headers._Pragma = value; return; } - if ("Accept".Equals(key, StringComparison.OrdinalIgnoreCase)) { - _bits |= 1048576L; + _bits |= 524288L; _headers._Accept = value; return; } - if ("Cookie".Equals(key, StringComparison.OrdinalIgnoreCase)) { - _bits |= 33554432L; + _bits |= 16777216L; _headers._Cookie = value; return; } - if ("Expect".Equals(key, StringComparison.OrdinalIgnoreCase)) { - _bits |= 67108864L; + _bits |= 33554432L; _headers._Expect = value; return; } - if ("Origin".Equals(key, StringComparison.OrdinalIgnoreCase)) { - _bits |= 2199023255552L; + _bits |= 1099511627776L; _headers._Origin = value; return; } } break; - case 7: { if ("Trailer".Equals(key, StringComparison.OrdinalIgnoreCase)) @@ -2178,37 +1374,32 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _headers._Trailer = value; return; } - if ("Upgrade".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 128L; _headers._Upgrade = value; return; } - if ("Warning".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 512L; _headers._Warning = value; return; } - if ("Expires".Equals(key, StringComparison.OrdinalIgnoreCase)) { - _bits |= 262144L; + _bits |= 131072L; _headers._Expires = value; return; } - if ("Referer".Equals(key, StringComparison.OrdinalIgnoreCase)) { - _bits |= 68719476736L; + _bits |= 34359738368L; _headers._Referer = value; return; } } break; - case 17: { if ("Transfer-Encoding".Equals(key, StringComparison.OrdinalIgnoreCase)) @@ -2217,16 +1408,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _headers._TransferEncoding = value; return; } - if ("If-Modified-Since".Equals(key, StringComparison.OrdinalIgnoreCase)) { - _bits |= 1073741824L; + _bits |= 536870912L; _headers._IfModifiedSince = value; return; } } break; - case 3: { if ("Via".Equals(key, StringComparison.OrdinalIgnoreCase)) @@ -2237,7 +1426,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } } break; - case 5: { if ("Allow".Equals(key, StringComparison.OrdinalIgnoreCase)) @@ -2246,757 +1434,696 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _headers._Allow = value; return; } - if ("Range".Equals(key, StringComparison.OrdinalIgnoreCase)) { - _bits |= 137438953472L; - _headers._Range = value; - return; - } - } - break; - - case 14: - { - if ("Content-Length".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - _bits |= 2048L; - _headers._ContentLength = value; - return; - } - - if ("Accept-Charset".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - _bits |= 2097152L; - _headers._AcceptCharset = value; - return; - } - } - break; - - case 12: - { - if ("Content-Type".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - _bits |= 4096L; - _headers._ContentType = value; - return; - } - - if ("Max-Forwards".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - _bits |= 17179869184L; - _headers._MaxForwards = value; - return; - } - } - break; - - case 16: - { - if ("Content-Encoding".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - _bits |= 8192L; - _headers._ContentEncoding = value; - return; - } - - if ("Content-Language".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - _bits |= 16384L; - _headers._ContentLanguage = value; - return; - } - - if ("Content-Location".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - _bits |= 32768L; - _headers._ContentLocation = value; - return; - } - } - break; - - case 11: - { - if ("Content-MD5".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - _bits |= 65536L; - _headers._ContentMD5 = value; - return; - } - } - break; - - case 15: - { - if ("Accept-Encoding".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - _bits |= 4194304L; - _headers._AcceptEncoding = value; - return; - } - - if ("Accept-Language".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - _bits |= 8388608L; - _headers._AcceptLanguage = value; - return; - } - } - break; - - case 8: - { - if ("If-Match".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - _bits |= 536870912L; - _headers._IfMatch = value; - return; - } - - if ("If-Range".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - _bits |= 4294967296L; - _headers._IfRange = value; - return; - } - } - break; - - case 19: - { - if ("If-Unmodified-Since".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - _bits |= 8589934592L; - _headers._IfUnmodifiedSince = value; - return; - } - - if ("Proxy-Authorization".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - _bits |= 34359738368L; - _headers._ProxyAuthorization = value; - return; - } - } - break; - - case 2: - { - if ("TE".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - _bits |= 274877906944L; - _headers._TE = value; - return; - } - } - break; - - case 9: - { - if ("Translate".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - _bits |= 549755813888L; - _headers._Translate = value; - return; - } - } - break; - - case 29: - { - if ("Access-Control-Request-Method".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - _bits |= 4398046511104L; - _headers._AccessControlRequestMethod = value; - return; - } - } - break; - - case 30: - { - if ("Access-Control-Request-Headers".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - _bits |= 8796093022208L; - _headers._AccessControlRequestHeaders = value; - return; - } - } - break; -} - - Unknown[key] = value; - } - protected override void AddValueFast(string key, StringValues value) - { - - switch (key.Length) - { - case 13: - { - if ("Cache-Control".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 1L) != 0)) - { - ThrowDuplicateKeyException(); - } - _bits |= 1L; - _headers._CacheControl = value; - return; - } - - if ("Content-Range".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 131072L) != 0)) - { - ThrowDuplicateKeyException(); - } - _bits |= 131072L; - _headers._ContentRange = value; - return; - } - - if ("Last-Modified".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 524288L) != 0)) - { - ThrowDuplicateKeyException(); - } - _bits |= 524288L; - _headers._LastModified = value; - return; - } - - if ("Authorization".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 16777216L) != 0)) - { - ThrowDuplicateKeyException(); - } - _bits |= 16777216L; - _headers._Authorization = value; - return; - } - - if ("If-None-Match".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 2147483648L) != 0)) - { - ThrowDuplicateKeyException(); - } - _bits |= 2147483648L; - _headers._IfNoneMatch = value; - return; - } - } - break; - - case 10: - { - if ("Connection".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 2L) != 0)) - { - ThrowDuplicateKeyException(); - } - _bits |= 2L; - _headers._Connection = value; - return; - } - - if ("Keep-Alive".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 8L) != 0)) - { - ThrowDuplicateKeyException(); - } - _bits |= 8L; - _headers._KeepAlive = value; - return; - } - - if ("User-Agent".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 1099511627776L) != 0)) - { - ThrowDuplicateKeyException(); - } - _bits |= 1099511627776L; - _headers._UserAgent = value; - return; - } - } - break; - - case 4: - { - if ("Date".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 4L) != 0)) - { - ThrowDuplicateKeyException(); - } - _bits |= 4L; - _headers._Date = value; - return; - } - - if ("From".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 134217728L) != 0)) - { - ThrowDuplicateKeyException(); - } - _bits |= 134217728L; - _headers._From = value; - return; - } - - if ("Host".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 268435456L) != 0)) - { - ThrowDuplicateKeyException(); - } - _bits |= 268435456L; - _headers._Host = value; - return; - } - } - break; - - case 6: - { - if ("Pragma".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 16L) != 0)) - { - ThrowDuplicateKeyException(); - } - _bits |= 16L; - _headers._Pragma = value; - return; - } - - if ("Accept".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 1048576L) != 0)) - { - ThrowDuplicateKeyException(); - } - _bits |= 1048576L; - _headers._Accept = value; - return; - } - - if ("Cookie".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 33554432L) != 0)) - { - ThrowDuplicateKeyException(); - } - _bits |= 33554432L; - _headers._Cookie = value; - return; - } - - if ("Expect".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 67108864L) != 0)) - { - ThrowDuplicateKeyException(); - } - _bits |= 67108864L; - _headers._Expect = value; - return; - } - - if ("Origin".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 2199023255552L) != 0)) - { - ThrowDuplicateKeyException(); - } - _bits |= 2199023255552L; - _headers._Origin = value; - return; - } - } - break; - - case 7: - { - if ("Trailer".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 32L) != 0)) - { - ThrowDuplicateKeyException(); - } - _bits |= 32L; - _headers._Trailer = value; - return; - } - - if ("Upgrade".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 128L) != 0)) - { - ThrowDuplicateKeyException(); - } - _bits |= 128L; - _headers._Upgrade = value; - return; - } - - if ("Warning".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 512L) != 0)) - { - ThrowDuplicateKeyException(); - } - _bits |= 512L; - _headers._Warning = value; - return; - } - - if ("Expires".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 262144L) != 0)) - { - ThrowDuplicateKeyException(); - } - _bits |= 262144L; - _headers._Expires = value; - return; - } - - if ("Referer".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 68719476736L) != 0)) - { - ThrowDuplicateKeyException(); - } _bits |= 68719476736L; - _headers._Referer = value; - return; - } - } - break; - - case 17: - { - if ("Transfer-Encoding".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 64L) != 0)) - { - ThrowDuplicateKeyException(); - } - _bits |= 64L; - _headers._TransferEncoding = value; - return; - } - - if ("If-Modified-Since".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 1073741824L) != 0)) - { - ThrowDuplicateKeyException(); - } - _bits |= 1073741824L; - _headers._IfModifiedSince = value; - return; - } - } - break; - - case 3: - { - if ("Via".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 256L) != 0)) - { - ThrowDuplicateKeyException(); - } - _bits |= 256L; - _headers._Via = value; - return; - } - } - break; - - case 5: - { - if ("Allow".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 1024L) != 0)) - { - ThrowDuplicateKeyException(); - } - _bits |= 1024L; - _headers._Allow = value; - return; - } - - if ("Range".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 137438953472L) != 0)) - { - ThrowDuplicateKeyException(); - } - _bits |= 137438953472L; _headers._Range = value; return; } } break; - - case 14: - { - if ("Content-Length".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 2048L) != 0)) - { - ThrowDuplicateKeyException(); - } - _bits |= 2048L; - _headers._ContentLength = value; - return; - } - - if ("Accept-Charset".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 2097152L) != 0)) - { - ThrowDuplicateKeyException(); - } - _bits |= 2097152L; - _headers._AcceptCharset = value; - return; - } - } - break; - case 12: { if ("Content-Type".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 4096L) != 0)) - { - ThrowDuplicateKeyException(); - } - _bits |= 4096L; + _bits |= 2048L; _headers._ContentType = value; return; } - if ("Max-Forwards".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 17179869184L) != 0)) - { - ThrowDuplicateKeyException(); - } - _bits |= 17179869184L; + _bits |= 8589934592L; _headers._MaxForwards = value; return; } } break; - case 16: { if ("Content-Encoding".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 8192L) != 0)) - { - ThrowDuplicateKeyException(); - } - _bits |= 8192L; + _bits |= 4096L; _headers._ContentEncoding = value; return; } - if ("Content-Language".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 16384L) != 0)) - { - ThrowDuplicateKeyException(); - } - _bits |= 16384L; + _bits |= 8192L; _headers._ContentLanguage = value; return; } - if ("Content-Location".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 32768L) != 0)) - { - ThrowDuplicateKeyException(); - } - _bits |= 32768L; + _bits |= 16384L; _headers._ContentLocation = value; return; } } break; - case 11: { if ("Content-MD5".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 65536L) != 0)) - { - ThrowDuplicateKeyException(); - } - _bits |= 65536L; + _bits |= 32768L; _headers._ContentMD5 = value; return; } } break; - + case 14: + { + if ("Accept-Charset".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + _bits |= 1048576L; + _headers._AcceptCharset = value; + return; + } + if ("Content-Length".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + _contentLength = ParseContentLength(value.ToString()); + return; + } + } + break; case 15: { if ("Accept-Encoding".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 4194304L) != 0)) - { - ThrowDuplicateKeyException(); - } - _bits |= 4194304L; + _bits |= 2097152L; _headers._AcceptEncoding = value; return; } - if ("Accept-Language".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 8388608L) != 0)) - { - ThrowDuplicateKeyException(); - } - _bits |= 8388608L; + _bits |= 4194304L; _headers._AcceptLanguage = value; return; } } break; - case 8: { if ("If-Match".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 536870912L) != 0)) - { - ThrowDuplicateKeyException(); - } - _bits |= 536870912L; + _bits |= 268435456L; _headers._IfMatch = value; return; } - if ("If-Range".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 4294967296L) != 0)) - { - ThrowDuplicateKeyException(); - } - _bits |= 4294967296L; + _bits |= 2147483648L; _headers._IfRange = value; return; } } break; - case 19: { if ("If-Unmodified-Since".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 8589934592L) != 0)) - { - ThrowDuplicateKeyException(); - } - _bits |= 8589934592L; + _bits |= 4294967296L; _headers._IfUnmodifiedSince = value; return; } - if ("Proxy-Authorization".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 34359738368L) != 0)) - { - ThrowDuplicateKeyException(); - } - _bits |= 34359738368L; + _bits |= 17179869184L; _headers._ProxyAuthorization = value; return; } } break; - case 2: { if ("TE".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 274877906944L) != 0)) - { - ThrowDuplicateKeyException(); - } - _bits |= 274877906944L; + _bits |= 137438953472L; _headers._TE = value; return; } } break; - case 9: { if ("Translate".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 549755813888L) != 0)) - { - ThrowDuplicateKeyException(); - } - _bits |= 549755813888L; + _bits |= 274877906944L; _headers._Translate = value; return; } } break; - case 29: { if ("Access-Control-Request-Method".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 4398046511104L) != 0)) - { - ThrowDuplicateKeyException(); - } - _bits |= 4398046511104L; + _bits |= 2199023255552L; _headers._AccessControlRequestMethod = value; return; } } break; - case 30: { if ("Access-Control-Request-Headers".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 8796093022208L) != 0)) - { - ThrowDuplicateKeyException(); - } - _bits |= 8796093022208L; + _bits |= 4398046511104L; _headers._AccessControlRequestHeaders = value; return; } } break; } - - Unknown.Add(key, value); + + SetValueUnknown(key, value); } + + protected override bool AddValueFast(string key, StringValues value) + { + switch (key.Length) + { + case 13: + { + if ("Cache-Control".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if ((_bits & 1L) == 0) + { + _bits |= 1L; + _headers._CacheControl = value; + return true; + } + return false; + } + if ("Content-Range".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if ((_bits & 65536L) == 0) + { + _bits |= 65536L; + _headers._ContentRange = value; + return true; + } + return false; + } + if ("Last-Modified".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if ((_bits & 262144L) == 0) + { + _bits |= 262144L; + _headers._LastModified = value; + return true; + } + return false; + } + if ("Authorization".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if ((_bits & 8388608L) == 0) + { + _bits |= 8388608L; + _headers._Authorization = value; + return true; + } + return false; + } + if ("If-None-Match".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if ((_bits & 1073741824L) == 0) + { + _bits |= 1073741824L; + _headers._IfNoneMatch = value; + return true; + } + return false; + } + } + break; + case 10: + { + if ("Connection".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if ((_bits & 2L) == 0) + { + _bits |= 2L; + _headers._Connection = value; + return true; + } + return false; + } + if ("Keep-Alive".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if ((_bits & 8L) == 0) + { + _bits |= 8L; + _headers._KeepAlive = value; + return true; + } + return false; + } + if ("User-Agent".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if ((_bits & 549755813888L) == 0) + { + _bits |= 549755813888L; + _headers._UserAgent = value; + return true; + } + return false; + } + } + break; + case 4: + { + if ("Date".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if ((_bits & 4L) == 0) + { + _bits |= 4L; + _headers._Date = value; + return true; + } + return false; + } + if ("From".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if ((_bits & 67108864L) == 0) + { + _bits |= 67108864L; + _headers._From = value; + return true; + } + return false; + } + if ("Host".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if ((_bits & 134217728L) == 0) + { + _bits |= 134217728L; + _headers._Host = value; + return true; + } + return false; + } + } + break; + case 6: + { + if ("Pragma".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if ((_bits & 16L) == 0) + { + _bits |= 16L; + _headers._Pragma = value; + return true; + } + return false; + } + if ("Accept".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if ((_bits & 524288L) == 0) + { + _bits |= 524288L; + _headers._Accept = value; + return true; + } + return false; + } + if ("Cookie".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if ((_bits & 16777216L) == 0) + { + _bits |= 16777216L; + _headers._Cookie = value; + return true; + } + return false; + } + if ("Expect".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if ((_bits & 33554432L) == 0) + { + _bits |= 33554432L; + _headers._Expect = value; + return true; + } + return false; + } + if ("Origin".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if ((_bits & 1099511627776L) == 0) + { + _bits |= 1099511627776L; + _headers._Origin = value; + return true; + } + return false; + } + } + break; + case 7: + { + if ("Trailer".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if ((_bits & 32L) == 0) + { + _bits |= 32L; + _headers._Trailer = value; + return true; + } + return false; + } + if ("Upgrade".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if ((_bits & 128L) == 0) + { + _bits |= 128L; + _headers._Upgrade = value; + return true; + } + return false; + } + if ("Warning".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if ((_bits & 512L) == 0) + { + _bits |= 512L; + _headers._Warning = value; + return true; + } + return false; + } + if ("Expires".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if ((_bits & 131072L) == 0) + { + _bits |= 131072L; + _headers._Expires = value; + return true; + } + return false; + } + if ("Referer".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if ((_bits & 34359738368L) == 0) + { + _bits |= 34359738368L; + _headers._Referer = value; + return true; + } + return false; + } + } + break; + case 17: + { + if ("Transfer-Encoding".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if ((_bits & 64L) == 0) + { + _bits |= 64L; + _headers._TransferEncoding = value; + return true; + } + return false; + } + if ("If-Modified-Since".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if ((_bits & 536870912L) == 0) + { + _bits |= 536870912L; + _headers._IfModifiedSince = value; + return true; + } + return false; + } + } + break; + case 3: + { + if ("Via".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if ((_bits & 256L) == 0) + { + _bits |= 256L; + _headers._Via = value; + return true; + } + return false; + } + } + break; + case 5: + { + if ("Allow".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if ((_bits & 1024L) == 0) + { + _bits |= 1024L; + _headers._Allow = value; + return true; + } + return false; + } + if ("Range".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if ((_bits & 68719476736L) == 0) + { + _bits |= 68719476736L; + _headers._Range = value; + return true; + } + return false; + } + } + break; + case 12: + { + if ("Content-Type".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if ((_bits & 2048L) == 0) + { + _bits |= 2048L; + _headers._ContentType = value; + return true; + } + return false; + } + if ("Max-Forwards".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if ((_bits & 8589934592L) == 0) + { + _bits |= 8589934592L; + _headers._MaxForwards = value; + return true; + } + return false; + } + } + break; + case 16: + { + if ("Content-Encoding".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if ((_bits & 4096L) == 0) + { + _bits |= 4096L; + _headers._ContentEncoding = value; + return true; + } + return false; + } + if ("Content-Language".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if ((_bits & 8192L) == 0) + { + _bits |= 8192L; + _headers._ContentLanguage = value; + return true; + } + return false; + } + if ("Content-Location".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if ((_bits & 16384L) == 0) + { + _bits |= 16384L; + _headers._ContentLocation = value; + return true; + } + return false; + } + } + break; + case 11: + { + if ("Content-MD5".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if ((_bits & 32768L) == 0) + { + _bits |= 32768L; + _headers._ContentMD5 = value; + return true; + } + return false; + } + } + break; + case 14: + { + if ("Accept-Charset".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if ((_bits & 1048576L) == 0) + { + _bits |= 1048576L; + _headers._AcceptCharset = value; + return true; + } + return false; + } + if ("Content-Length".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (!_contentLength.HasValue) + { + _contentLength = ParseContentLength(value); + return true; + } + return false; + } + } + break; + case 15: + { + if ("Accept-Encoding".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if ((_bits & 2097152L) == 0) + { + _bits |= 2097152L; + _headers._AcceptEncoding = value; + return true; + } + return false; + } + if ("Accept-Language".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if ((_bits & 4194304L) == 0) + { + _bits |= 4194304L; + _headers._AcceptLanguage = value; + return true; + } + return false; + } + } + break; + case 8: + { + if ("If-Match".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if ((_bits & 268435456L) == 0) + { + _bits |= 268435456L; + _headers._IfMatch = value; + return true; + } + return false; + } + if ("If-Range".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if ((_bits & 2147483648L) == 0) + { + _bits |= 2147483648L; + _headers._IfRange = value; + return true; + } + return false; + } + } + break; + case 19: + { + if ("If-Unmodified-Since".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if ((_bits & 4294967296L) == 0) + { + _bits |= 4294967296L; + _headers._IfUnmodifiedSince = value; + return true; + } + return false; + } + if ("Proxy-Authorization".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if ((_bits & 17179869184L) == 0) + { + _bits |= 17179869184L; + _headers._ProxyAuthorization = value; + return true; + } + return false; + } + } + break; + case 2: + { + if ("TE".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if ((_bits & 137438953472L) == 0) + { + _bits |= 137438953472L; + _headers._TE = value; + return true; + } + return false; + } + } + break; + case 9: + { + if ("Translate".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if ((_bits & 274877906944L) == 0) + { + _bits |= 274877906944L; + _headers._Translate = value; + return true; + } + return false; + } + } + break; + case 29: + { + if ("Access-Control-Request-Method".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if ((_bits & 2199023255552L) == 0) + { + _bits |= 2199023255552L; + _headers._AccessControlRequestMethod = value; + return true; + } + return false; + } + } + break; + case 30: + { + if ("Access-Control-Request-Headers".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if ((_bits & 4398046511104L) == 0) + { + _bits |= 4398046511104L; + _headers._AccessControlRequestHeaders = value; + return true; + } + return false; + } + } + break; + } + + Unknown.Add(key, value); + // Return true, above will throw and exit for false + return true; + } + protected override bool RemoveFast(string key) { switch (key.Length) @@ -3005,1641 +2132,1372 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { if ("Cache-Control".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 1L) != 0)) + if ((_bits & 1L) != 0) { _bits &= ~1L; - _headers._CacheControl = StringValues.Empty; + _headers._CacheControl = default(StringValues); return true; } - else - { - return false; - } + return false; } - if ("Content-Range".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 131072L) != 0)) + if ((_bits & 65536L) != 0) { - _bits &= ~131072L; - _headers._ContentRange = StringValues.Empty; + _bits &= ~65536L; + _headers._ContentRange = default(StringValues); return true; } - else - { - return false; - } + return false; } - if ("Last-Modified".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 524288L) != 0)) + if ((_bits & 262144L) != 0) { - _bits &= ~524288L; - _headers._LastModified = StringValues.Empty; + _bits &= ~262144L; + _headers._LastModified = default(StringValues); return true; } - else - { - return false; - } + return false; } - if ("Authorization".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 16777216L) != 0)) + if ((_bits & 8388608L) != 0) { - _bits &= ~16777216L; - _headers._Authorization = StringValues.Empty; + _bits &= ~8388608L; + _headers._Authorization = default(StringValues); return true; } - else - { - return false; - } + return false; } - if ("If-None-Match".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 2147483648L) != 0)) + if ((_bits & 1073741824L) != 0) { - _bits &= ~2147483648L; - _headers._IfNoneMatch = StringValues.Empty; + _bits &= ~1073741824L; + _headers._IfNoneMatch = default(StringValues); return true; } - else - { - return false; - } + return false; } } break; - case 10: { if ("Connection".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 2L) != 0)) + if ((_bits & 2L) != 0) { _bits &= ~2L; - _headers._Connection = StringValues.Empty; + _headers._Connection = default(StringValues); return true; } - else - { - return false; - } + return false; } - if ("Keep-Alive".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 8L) != 0)) + if ((_bits & 8L) != 0) { _bits &= ~8L; - _headers._KeepAlive = StringValues.Empty; + _headers._KeepAlive = default(StringValues); return true; } - else - { - return false; - } + return false; } - if ("User-Agent".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 1099511627776L) != 0)) + if ((_bits & 549755813888L) != 0) { - _bits &= ~1099511627776L; - _headers._UserAgent = StringValues.Empty; + _bits &= ~549755813888L; + _headers._UserAgent = default(StringValues); return true; } - else - { - return false; - } + return false; } } break; - case 4: { if ("Date".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 4L) != 0)) + if ((_bits & 4L) != 0) { _bits &= ~4L; - _headers._Date = StringValues.Empty; + _headers._Date = default(StringValues); return true; } - else - { - return false; - } + return false; } - if ("From".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 134217728L) != 0)) + if ((_bits & 67108864L) != 0) { - _bits &= ~134217728L; - _headers._From = StringValues.Empty; + _bits &= ~67108864L; + _headers._From = default(StringValues); return true; } - else - { - return false; - } + return false; } - if ("Host".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 268435456L) != 0)) + if ((_bits & 134217728L) != 0) { - _bits &= ~268435456L; - _headers._Host = StringValues.Empty; + _bits &= ~134217728L; + _headers._Host = default(StringValues); return true; } - else - { - return false; - } + return false; } } break; - case 6: { if ("Pragma".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 16L) != 0)) + if ((_bits & 16L) != 0) { _bits &= ~16L; - _headers._Pragma = StringValues.Empty; + _headers._Pragma = default(StringValues); return true; } - else - { - return false; - } + return false; } - if ("Accept".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 1048576L) != 0)) + if ((_bits & 524288L) != 0) { - _bits &= ~1048576L; - _headers._Accept = StringValues.Empty; + _bits &= ~524288L; + _headers._Accept = default(StringValues); return true; } - else - { - return false; - } + return false; } - if ("Cookie".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 33554432L) != 0)) + if ((_bits & 16777216L) != 0) { - _bits &= ~33554432L; - _headers._Cookie = StringValues.Empty; + _bits &= ~16777216L; + _headers._Cookie = default(StringValues); return true; } - else - { - return false; - } + return false; } - if ("Expect".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 67108864L) != 0)) + if ((_bits & 33554432L) != 0) { - _bits &= ~67108864L; - _headers._Expect = StringValues.Empty; + _bits &= ~33554432L; + _headers._Expect = default(StringValues); return true; } - else - { - return false; - } + return false; } - if ("Origin".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 2199023255552L) != 0)) + if ((_bits & 1099511627776L) != 0) { - _bits &= ~2199023255552L; - _headers._Origin = StringValues.Empty; + _bits &= ~1099511627776L; + _headers._Origin = default(StringValues); return true; } - else - { - return false; - } + return false; } } break; - case 7: { if ("Trailer".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 32L) != 0)) + if ((_bits & 32L) != 0) { _bits &= ~32L; - _headers._Trailer = StringValues.Empty; + _headers._Trailer = default(StringValues); return true; } - else - { - return false; - } + return false; } - if ("Upgrade".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 128L) != 0)) + if ((_bits & 128L) != 0) { _bits &= ~128L; - _headers._Upgrade = StringValues.Empty; + _headers._Upgrade = default(StringValues); return true; } - else - { - return false; - } + return false; } - if ("Warning".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 512L) != 0)) + if ((_bits & 512L) != 0) { _bits &= ~512L; - _headers._Warning = StringValues.Empty; + _headers._Warning = default(StringValues); return true; } - else - { - return false; - } + return false; } - if ("Expires".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 262144L) != 0)) + if ((_bits & 131072L) != 0) { - _bits &= ~262144L; - _headers._Expires = StringValues.Empty; + _bits &= ~131072L; + _headers._Expires = default(StringValues); return true; } - else - { - return false; - } + return false; } - if ("Referer".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 68719476736L) != 0)) + if ((_bits & 34359738368L) != 0) { - _bits &= ~68719476736L; - _headers._Referer = StringValues.Empty; + _bits &= ~34359738368L; + _headers._Referer = default(StringValues); return true; } - else - { - return false; - } + return false; } } break; - case 17: { if ("Transfer-Encoding".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 64L) != 0)) + if ((_bits & 64L) != 0) { _bits &= ~64L; - _headers._TransferEncoding = StringValues.Empty; + _headers._TransferEncoding = default(StringValues); return true; } - else - { - return false; - } + return false; } - if ("If-Modified-Since".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 1073741824L) != 0)) + if ((_bits & 536870912L) != 0) { - _bits &= ~1073741824L; - _headers._IfModifiedSince = StringValues.Empty; + _bits &= ~536870912L; + _headers._IfModifiedSince = default(StringValues); return true; } - else - { - return false; - } + return false; } } break; - case 3: { if ("Via".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 256L) != 0)) + if ((_bits & 256L) != 0) { _bits &= ~256L; - _headers._Via = StringValues.Empty; + _headers._Via = default(StringValues); return true; } - else - { - return false; - } + return false; } } break; - case 5: { if ("Allow".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 1024L) != 0)) + if ((_bits & 1024L) != 0) { _bits &= ~1024L; - _headers._Allow = StringValues.Empty; + _headers._Allow = default(StringValues); return true; } - else - { - return false; - } + return false; } - if ("Range".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 137438953472L) != 0)) + if ((_bits & 68719476736L) != 0) { - _bits &= ~137438953472L; - _headers._Range = StringValues.Empty; + _bits &= ~68719476736L; + _headers._Range = default(StringValues); return true; } - else - { - return false; - } + return false; } } break; - - case 14: - { - if ("Content-Length".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 2048L) != 0)) - { - _bits &= ~2048L; - _headers._ContentLength = StringValues.Empty; - return true; - } - else - { - return false; - } - } - - if ("Accept-Charset".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 2097152L) != 0)) - { - _bits &= ~2097152L; - _headers._AcceptCharset = StringValues.Empty; - return true; - } - else - { - return false; - } - } - } - break; - case 12: { if ("Content-Type".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 4096L) != 0)) + if ((_bits & 2048L) != 0) { - _bits &= ~4096L; - _headers._ContentType = StringValues.Empty; + _bits &= ~2048L; + _headers._ContentType = default(StringValues); return true; } - else - { - return false; - } + return false; } - if ("Max-Forwards".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 17179869184L) != 0)) + if ((_bits & 8589934592L) != 0) { - _bits &= ~17179869184L; - _headers._MaxForwards = StringValues.Empty; + _bits &= ~8589934592L; + _headers._MaxForwards = default(StringValues); return true; } - else - { - return false; - } + return false; } } break; - case 16: { if ("Content-Encoding".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 8192L) != 0)) + if ((_bits & 4096L) != 0) { - _bits &= ~8192L; - _headers._ContentEncoding = StringValues.Empty; + _bits &= ~4096L; + _headers._ContentEncoding = default(StringValues); return true; } - else - { - return false; - } + return false; } - if ("Content-Language".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 16384L) != 0)) + if ((_bits & 8192L) != 0) { - _bits &= ~16384L; - _headers._ContentLanguage = StringValues.Empty; + _bits &= ~8192L; + _headers._ContentLanguage = default(StringValues); return true; } - else - { - return false; - } + return false; } - if ("Content-Location".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 32768L) != 0)) + if ((_bits & 16384L) != 0) { - _bits &= ~32768L; - _headers._ContentLocation = StringValues.Empty; + _bits &= ~16384L; + _headers._ContentLocation = default(StringValues); return true; } - else - { - return false; - } + return false; } } break; - case 11: { if ("Content-MD5".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 65536L) != 0)) + if ((_bits & 32768L) != 0) { - _bits &= ~65536L; - _headers._ContentMD5 = StringValues.Empty; + _bits &= ~32768L; + _headers._ContentMD5 = default(StringValues); return true; } - else - { - return false; - } + return false; + } + } + break; + case 14: + { + if ("Accept-Charset".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if ((_bits & 1048576L) != 0) + { + _bits &= ~1048576L; + _headers._AcceptCharset = default(StringValues); + return true; + } + return false; + } + if ("Content-Length".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (_contentLength.HasValue) + { + _contentLength = null; + return true; + } + return false; } } break; - case 15: { if ("Accept-Encoding".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 4194304L) != 0)) + if ((_bits & 2097152L) != 0) { - _bits &= ~4194304L; - _headers._AcceptEncoding = StringValues.Empty; + _bits &= ~2097152L; + _headers._AcceptEncoding = default(StringValues); return true; } - else - { - return false; - } + return false; } - if ("Accept-Language".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 8388608L) != 0)) + if ((_bits & 4194304L) != 0) { - _bits &= ~8388608L; - _headers._AcceptLanguage = StringValues.Empty; + _bits &= ~4194304L; + _headers._AcceptLanguage = default(StringValues); return true; } - else - { - return false; - } + return false; } } break; - case 8: { if ("If-Match".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 536870912L) != 0)) + if ((_bits & 268435456L) != 0) { - _bits &= ~536870912L; - _headers._IfMatch = StringValues.Empty; + _bits &= ~268435456L; + _headers._IfMatch = default(StringValues); return true; } - else - { - return false; - } + return false; } - if ("If-Range".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 4294967296L) != 0)) + if ((_bits & 2147483648L) != 0) { - _bits &= ~4294967296L; - _headers._IfRange = StringValues.Empty; + _bits &= ~2147483648L; + _headers._IfRange = default(StringValues); return true; } - else - { - return false; - } + return false; } } break; - case 19: { if ("If-Unmodified-Since".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 8589934592L) != 0)) + if ((_bits & 4294967296L) != 0) { - _bits &= ~8589934592L; - _headers._IfUnmodifiedSince = StringValues.Empty; + _bits &= ~4294967296L; + _headers._IfUnmodifiedSince = default(StringValues); return true; } - else - { - return false; - } + return false; } - if ("Proxy-Authorization".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 34359738368L) != 0)) + if ((_bits & 17179869184L) != 0) { - _bits &= ~34359738368L; - _headers._ProxyAuthorization = StringValues.Empty; + _bits &= ~17179869184L; + _headers._ProxyAuthorization = default(StringValues); return true; } - else - { - return false; - } + return false; } } break; - case 2: { if ("TE".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 274877906944L) != 0)) + if ((_bits & 137438953472L) != 0) { - _bits &= ~274877906944L; - _headers._TE = StringValues.Empty; + _bits &= ~137438953472L; + _headers._TE = default(StringValues); return true; } - else - { - return false; - } + return false; } } break; - case 9: { if ("Translate".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 549755813888L) != 0)) + if ((_bits & 274877906944L) != 0) { - _bits &= ~549755813888L; - _headers._Translate = StringValues.Empty; + _bits &= ~274877906944L; + _headers._Translate = default(StringValues); return true; } - else - { - return false; - } + return false; } } break; - case 29: { if ("Access-Control-Request-Method".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 4398046511104L) != 0)) + if ((_bits & 2199023255552L) != 0) { - _bits &= ~4398046511104L; - _headers._AccessControlRequestMethod = StringValues.Empty; + _bits &= ~2199023255552L; + _headers._AccessControlRequestMethod = default(StringValues); return true; } - else - { - return false; - } + return false; } } break; - case 30: { if ("Access-Control-Request-Headers".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 8796093022208L) != 0)) + if ((_bits & 4398046511104L) != 0) { - _bits &= ~8796093022208L; - _headers._AccessControlRequestHeaders = StringValues.Empty; + _bits &= ~4398046511104L; + _headers._AccessControlRequestHeaders = default(StringValues); return true; } - else - { - return false; - } + return false; } } break; } + return MaybeUnknown?.Remove(key) ?? false; } + protected override void ClearFast() - { + { MaybeUnknown?.Clear(); - - if(FrameHeaders.BitCount(_bits) > 12) + _contentLength = null; + var tempBits = _bits; + _bits = 0; + if(FrameHeaders.BitCount(tempBits) > 12) { _headers = default(HeaderReferences); - _bits = 0; return; } - if (((_bits & 1048576L) != 0)) + if ((tempBits & 524288L) != 0) { _headers._Accept = default(StringValues); - _bits &= ~1048576L; - if(_bits == 0) + if((tempBits & ~524288L) == 0) { return; } + tempBits &= ~524288L; } - if (((_bits & 268435456L) != 0)) + if ((tempBits & 134217728L) != 0) { _headers._Host = default(StringValues); - _bits &= ~268435456L; - if(_bits == 0) + if((tempBits & ~134217728L) == 0) { return; } + tempBits &= ~134217728L; } - if (((_bits & 1099511627776L) != 0)) + if ((tempBits & 549755813888L) != 0) { _headers._UserAgent = default(StringValues); - _bits &= ~1099511627776L; - if(_bits == 0) + if((tempBits & ~549755813888L) == 0) { return; } + tempBits &= ~549755813888L; } - if (((_bits & 1L) != 0)) + if ((tempBits & 1L) != 0) { _headers._CacheControl = default(StringValues); - _bits &= ~1L; - if(_bits == 0) + if((tempBits & ~1L) == 0) { return; } + tempBits &= ~1L; } - if (((_bits & 2L) != 0)) + if ((tempBits & 2L) != 0) { _headers._Connection = default(StringValues); - _bits &= ~2L; - if(_bits == 0) + if((tempBits & ~2L) == 0) { return; } + tempBits &= ~2L; } - if (((_bits & 4L) != 0)) + if ((tempBits & 4L) != 0) { _headers._Date = default(StringValues); - _bits &= ~4L; - if(_bits == 0) + if((tempBits & ~4L) == 0) { return; } + tempBits &= ~4L; } - if (((_bits & 8L) != 0)) + if ((tempBits & 8L) != 0) { _headers._KeepAlive = default(StringValues); - _bits &= ~8L; - if(_bits == 0) + if((tempBits & ~8L) == 0) { return; } + tempBits &= ~8L; } - if (((_bits & 16L) != 0)) + if ((tempBits & 16L) != 0) { _headers._Pragma = default(StringValues); - _bits &= ~16L; - if(_bits == 0) + if((tempBits & ~16L) == 0) { return; } + tempBits &= ~16L; } - if (((_bits & 32L) != 0)) + if ((tempBits & 32L) != 0) { _headers._Trailer = default(StringValues); - _bits &= ~32L; - if(_bits == 0) + if((tempBits & ~32L) == 0) { return; } + tempBits &= ~32L; } - if (((_bits & 64L) != 0)) + if ((tempBits & 64L) != 0) { _headers._TransferEncoding = default(StringValues); - _bits &= ~64L; - if(_bits == 0) + if((tempBits & ~64L) == 0) { return; } + tempBits &= ~64L; } - if (((_bits & 128L) != 0)) + if ((tempBits & 128L) != 0) { _headers._Upgrade = default(StringValues); - _bits &= ~128L; - if(_bits == 0) + if((tempBits & ~128L) == 0) { return; } + tempBits &= ~128L; } - if (((_bits & 256L) != 0)) + if ((tempBits & 256L) != 0) { _headers._Via = default(StringValues); - _bits &= ~256L; - if(_bits == 0) + if((tempBits & ~256L) == 0) { return; } + tempBits &= ~256L; } - if (((_bits & 512L) != 0)) + if ((tempBits & 512L) != 0) { _headers._Warning = default(StringValues); - _bits &= ~512L; - if(_bits == 0) + if((tempBits & ~512L) == 0) { return; } + tempBits &= ~512L; } - if (((_bits & 1024L) != 0)) + if ((tempBits & 1024L) != 0) { _headers._Allow = default(StringValues); - _bits &= ~1024L; - if(_bits == 0) + if((tempBits & ~1024L) == 0) { return; } + tempBits &= ~1024L; } - if (((_bits & 2048L) != 0)) - { - _headers._ContentLength = default(StringValues); - _bits &= ~2048L; - if(_bits == 0) - { - return; - } - } - - if (((_bits & 4096L) != 0)) + if ((tempBits & 2048L) != 0) { _headers._ContentType = default(StringValues); - _bits &= ~4096L; - if(_bits == 0) + if((tempBits & ~2048L) == 0) { return; } + tempBits &= ~2048L; } - if (((_bits & 8192L) != 0)) + if ((tempBits & 4096L) != 0) { _headers._ContentEncoding = default(StringValues); - _bits &= ~8192L; - if(_bits == 0) + if((tempBits & ~4096L) == 0) { return; } + tempBits &= ~4096L; } - if (((_bits & 16384L) != 0)) + if ((tempBits & 8192L) != 0) { _headers._ContentLanguage = default(StringValues); - _bits &= ~16384L; - if(_bits == 0) + if((tempBits & ~8192L) == 0) { return; } + tempBits &= ~8192L; } - if (((_bits & 32768L) != 0)) + if ((tempBits & 16384L) != 0) { _headers._ContentLocation = default(StringValues); - _bits &= ~32768L; - if(_bits == 0) + if((tempBits & ~16384L) == 0) { return; } + tempBits &= ~16384L; } - if (((_bits & 65536L) != 0)) + if ((tempBits & 32768L) != 0) { _headers._ContentMD5 = default(StringValues); - _bits &= ~65536L; - if(_bits == 0) + if((tempBits & ~32768L) == 0) { return; } + tempBits &= ~32768L; } - if (((_bits & 131072L) != 0)) + if ((tempBits & 65536L) != 0) { _headers._ContentRange = default(StringValues); - _bits &= ~131072L; - if(_bits == 0) + if((tempBits & ~65536L) == 0) { return; } + tempBits &= ~65536L; } - if (((_bits & 262144L) != 0)) + if ((tempBits & 131072L) != 0) { _headers._Expires = default(StringValues); - _bits &= ~262144L; - if(_bits == 0) + if((tempBits & ~131072L) == 0) { return; } + tempBits &= ~131072L; } - if (((_bits & 524288L) != 0)) + if ((tempBits & 262144L) != 0) { _headers._LastModified = default(StringValues); - _bits &= ~524288L; - if(_bits == 0) + if((tempBits & ~262144L) == 0) { return; } + tempBits &= ~262144L; } - if (((_bits & 2097152L) != 0)) + if ((tempBits & 1048576L) != 0) { _headers._AcceptCharset = default(StringValues); - _bits &= ~2097152L; - if(_bits == 0) + if((tempBits & ~1048576L) == 0) { return; } + tempBits &= ~1048576L; } - if (((_bits & 4194304L) != 0)) + if ((tempBits & 2097152L) != 0) { _headers._AcceptEncoding = default(StringValues); - _bits &= ~4194304L; - if(_bits == 0) + if((tempBits & ~2097152L) == 0) { return; } + tempBits &= ~2097152L; } - if (((_bits & 8388608L) != 0)) + if ((tempBits & 4194304L) != 0) { _headers._AcceptLanguage = default(StringValues); - _bits &= ~8388608L; - if(_bits == 0) + if((tempBits & ~4194304L) == 0) { return; } + tempBits &= ~4194304L; } - if (((_bits & 16777216L) != 0)) + if ((tempBits & 8388608L) != 0) { _headers._Authorization = default(StringValues); - _bits &= ~16777216L; - if(_bits == 0) + if((tempBits & ~8388608L) == 0) { return; } + tempBits &= ~8388608L; } - if (((_bits & 33554432L) != 0)) + if ((tempBits & 16777216L) != 0) { _headers._Cookie = default(StringValues); - _bits &= ~33554432L; - if(_bits == 0) + if((tempBits & ~16777216L) == 0) { return; } + tempBits &= ~16777216L; } - if (((_bits & 67108864L) != 0)) + if ((tempBits & 33554432L) != 0) { _headers._Expect = default(StringValues); - _bits &= ~67108864L; - if(_bits == 0) + if((tempBits & ~33554432L) == 0) { return; } + tempBits &= ~33554432L; } - if (((_bits & 134217728L) != 0)) + if ((tempBits & 67108864L) != 0) { _headers._From = default(StringValues); - _bits &= ~134217728L; - if(_bits == 0) + if((tempBits & ~67108864L) == 0) { return; } + tempBits &= ~67108864L; } - if (((_bits & 536870912L) != 0)) + if ((tempBits & 268435456L) != 0) { _headers._IfMatch = default(StringValues); - _bits &= ~536870912L; - if(_bits == 0) + if((tempBits & ~268435456L) == 0) { return; } + tempBits &= ~268435456L; } - if (((_bits & 1073741824L) != 0)) + if ((tempBits & 536870912L) != 0) { _headers._IfModifiedSince = default(StringValues); - _bits &= ~1073741824L; - if(_bits == 0) + if((tempBits & ~536870912L) == 0) { return; } + tempBits &= ~536870912L; } - if (((_bits & 2147483648L) != 0)) + if ((tempBits & 1073741824L) != 0) { _headers._IfNoneMatch = default(StringValues); - _bits &= ~2147483648L; - if(_bits == 0) + if((tempBits & ~1073741824L) == 0) { return; } + tempBits &= ~1073741824L; } - if (((_bits & 4294967296L) != 0)) + if ((tempBits & 2147483648L) != 0) { _headers._IfRange = default(StringValues); - _bits &= ~4294967296L; - if(_bits == 0) + if((tempBits & ~2147483648L) == 0) { return; } + tempBits &= ~2147483648L; } - if (((_bits & 8589934592L) != 0)) + if ((tempBits & 4294967296L) != 0) { _headers._IfUnmodifiedSince = default(StringValues); - _bits &= ~8589934592L; - if(_bits == 0) + if((tempBits & ~4294967296L) == 0) { return; } + tempBits &= ~4294967296L; } - if (((_bits & 17179869184L) != 0)) + if ((tempBits & 8589934592L) != 0) { _headers._MaxForwards = default(StringValues); - _bits &= ~17179869184L; - if(_bits == 0) + if((tempBits & ~8589934592L) == 0) { return; } + tempBits &= ~8589934592L; } - if (((_bits & 34359738368L) != 0)) + if ((tempBits & 17179869184L) != 0) { _headers._ProxyAuthorization = default(StringValues); - _bits &= ~34359738368L; - if(_bits == 0) + if((tempBits & ~17179869184L) == 0) { return; } + tempBits &= ~17179869184L; } - if (((_bits & 68719476736L) != 0)) + if ((tempBits & 34359738368L) != 0) { _headers._Referer = default(StringValues); - _bits &= ~68719476736L; - if(_bits == 0) + if((tempBits & ~34359738368L) == 0) { return; } + tempBits &= ~34359738368L; } - if (((_bits & 137438953472L) != 0)) + if ((tempBits & 68719476736L) != 0) { _headers._Range = default(StringValues); - _bits &= ~137438953472L; - if(_bits == 0) + if((tempBits & ~68719476736L) == 0) { return; } + tempBits &= ~68719476736L; } - if (((_bits & 274877906944L) != 0)) + if ((tempBits & 137438953472L) != 0) { _headers._TE = default(StringValues); - _bits &= ~274877906944L; - if(_bits == 0) + if((tempBits & ~137438953472L) == 0) { return; } + tempBits &= ~137438953472L; } - if (((_bits & 549755813888L) != 0)) + if ((tempBits & 274877906944L) != 0) { _headers._Translate = default(StringValues); - _bits &= ~549755813888L; - if(_bits == 0) + if((tempBits & ~274877906944L) == 0) { return; } + tempBits &= ~274877906944L; } - if (((_bits & 2199023255552L) != 0)) + if ((tempBits & 1099511627776L) != 0) { _headers._Origin = default(StringValues); - _bits &= ~2199023255552L; - if(_bits == 0) + if((tempBits & ~1099511627776L) == 0) { return; } + tempBits &= ~1099511627776L; } - if (((_bits & 4398046511104L) != 0)) + if ((tempBits & 2199023255552L) != 0) { _headers._AccessControlRequestMethod = default(StringValues); - _bits &= ~4398046511104L; - if(_bits == 0) + if((tempBits & ~2199023255552L) == 0) { return; } + tempBits &= ~2199023255552L; } - if (((_bits & 8796093022208L) != 0)) + if ((tempBits & 4398046511104L) != 0) { _headers._AccessControlRequestHeaders = default(StringValues); - _bits &= ~8796093022208L; - if(_bits == 0) + if((tempBits & ~4398046511104L) == 0) { return; } + tempBits &= ~4398046511104L; } } - protected override void CopyToFast(KeyValuePair[] array, int arrayIndex) + protected override bool CopyToFast(KeyValuePair[] array, int arrayIndex) { if (arrayIndex < 0) { - ThrowArgumentException(); + return false; } - if (((_bits & 1L) != 0)) + if ((_bits & 1L) != 0) { if (arrayIndex == array.Length) { - ThrowArgumentException(); + return false; } - array[arrayIndex] = new KeyValuePair("Cache-Control", _headers._CacheControl); ++arrayIndex; } - - if (((_bits & 2L) != 0)) + if ((_bits & 2L) != 0) { if (arrayIndex == array.Length) { - ThrowArgumentException(); + return false; } - array[arrayIndex] = new KeyValuePair("Connection", _headers._Connection); ++arrayIndex; } - - if (((_bits & 4L) != 0)) + if ((_bits & 4L) != 0) { if (arrayIndex == array.Length) { - ThrowArgumentException(); + return false; } - array[arrayIndex] = new KeyValuePair("Date", _headers._Date); ++arrayIndex; } - - if (((_bits & 8L) != 0)) + if ((_bits & 8L) != 0) { if (arrayIndex == array.Length) { - ThrowArgumentException(); + return false; } - array[arrayIndex] = new KeyValuePair("Keep-Alive", _headers._KeepAlive); ++arrayIndex; } - - if (((_bits & 16L) != 0)) + if ((_bits & 16L) != 0) { if (arrayIndex == array.Length) { - ThrowArgumentException(); + return false; } - array[arrayIndex] = new KeyValuePair("Pragma", _headers._Pragma); ++arrayIndex; } - - if (((_bits & 32L) != 0)) + if ((_bits & 32L) != 0) { if (arrayIndex == array.Length) { - ThrowArgumentException(); + return false; } - array[arrayIndex] = new KeyValuePair("Trailer", _headers._Trailer); ++arrayIndex; } - - if (((_bits & 64L) != 0)) + if ((_bits & 64L) != 0) { if (arrayIndex == array.Length) { - ThrowArgumentException(); + return false; } - array[arrayIndex] = new KeyValuePair("Transfer-Encoding", _headers._TransferEncoding); ++arrayIndex; } - - if (((_bits & 128L) != 0)) + if ((_bits & 128L) != 0) { if (arrayIndex == array.Length) { - ThrowArgumentException(); + return false; } - array[arrayIndex] = new KeyValuePair("Upgrade", _headers._Upgrade); ++arrayIndex; } - - if (((_bits & 256L) != 0)) + if ((_bits & 256L) != 0) { if (arrayIndex == array.Length) { - ThrowArgumentException(); + return false; } - array[arrayIndex] = new KeyValuePair("Via", _headers._Via); ++arrayIndex; } - - if (((_bits & 512L) != 0)) + if ((_bits & 512L) != 0) { if (arrayIndex == array.Length) { - ThrowArgumentException(); + return false; } - array[arrayIndex] = new KeyValuePair("Warning", _headers._Warning); ++arrayIndex; } - - if (((_bits & 1024L) != 0)) + if ((_bits & 1024L) != 0) { if (arrayIndex == array.Length) { - ThrowArgumentException(); + return false; } - array[arrayIndex] = new KeyValuePair("Allow", _headers._Allow); ++arrayIndex; } - - if (((_bits & 2048L) != 0)) + if ((_bits & 2048L) != 0) { if (arrayIndex == array.Length) { - ThrowArgumentException(); + return false; } - - array[arrayIndex] = new KeyValuePair("Content-Length", _headers._ContentLength); - ++arrayIndex; - } - - if (((_bits & 4096L) != 0)) - { - if (arrayIndex == array.Length) - { - ThrowArgumentException(); - } - array[arrayIndex] = new KeyValuePair("Content-Type", _headers._ContentType); ++arrayIndex; } - - if (((_bits & 8192L) != 0)) + if ((_bits & 4096L) != 0) { if (arrayIndex == array.Length) { - ThrowArgumentException(); + return false; } - array[arrayIndex] = new KeyValuePair("Content-Encoding", _headers._ContentEncoding); ++arrayIndex; } - - if (((_bits & 16384L) != 0)) + if ((_bits & 8192L) != 0) { if (arrayIndex == array.Length) { - ThrowArgumentException(); + return false; } - array[arrayIndex] = new KeyValuePair("Content-Language", _headers._ContentLanguage); ++arrayIndex; } - - if (((_bits & 32768L) != 0)) + if ((_bits & 16384L) != 0) { if (arrayIndex == array.Length) { - ThrowArgumentException(); + return false; } - array[arrayIndex] = new KeyValuePair("Content-Location", _headers._ContentLocation); ++arrayIndex; } - - if (((_bits & 65536L) != 0)) + if ((_bits & 32768L) != 0) { if (arrayIndex == array.Length) { - ThrowArgumentException(); + return false; } - array[arrayIndex] = new KeyValuePair("Content-MD5", _headers._ContentMD5); ++arrayIndex; } - - if (((_bits & 131072L) != 0)) + if ((_bits & 65536L) != 0) { if (arrayIndex == array.Length) { - ThrowArgumentException(); + return false; } - array[arrayIndex] = new KeyValuePair("Content-Range", _headers._ContentRange); ++arrayIndex; } - - if (((_bits & 262144L) != 0)) + if ((_bits & 131072L) != 0) { if (arrayIndex == array.Length) { - ThrowArgumentException(); + return false; } - array[arrayIndex] = new KeyValuePair("Expires", _headers._Expires); ++arrayIndex; } - - if (((_bits & 524288L) != 0)) + if ((_bits & 262144L) != 0) { if (arrayIndex == array.Length) { - ThrowArgumentException(); + return false; } - array[arrayIndex] = new KeyValuePair("Last-Modified", _headers._LastModified); ++arrayIndex; } - - if (((_bits & 1048576L) != 0)) + if ((_bits & 524288L) != 0) { if (arrayIndex == array.Length) { - ThrowArgumentException(); + return false; } - array[arrayIndex] = new KeyValuePair("Accept", _headers._Accept); ++arrayIndex; } - - if (((_bits & 2097152L) != 0)) + if ((_bits & 1048576L) != 0) { if (arrayIndex == array.Length) { - ThrowArgumentException(); + return false; } - array[arrayIndex] = new KeyValuePair("Accept-Charset", _headers._AcceptCharset); ++arrayIndex; } - - if (((_bits & 4194304L) != 0)) + if ((_bits & 2097152L) != 0) { if (arrayIndex == array.Length) { - ThrowArgumentException(); + return false; } - array[arrayIndex] = new KeyValuePair("Accept-Encoding", _headers._AcceptEncoding); ++arrayIndex; } - - if (((_bits & 8388608L) != 0)) + if ((_bits & 4194304L) != 0) { if (arrayIndex == array.Length) { - ThrowArgumentException(); + return false; } - array[arrayIndex] = new KeyValuePair("Accept-Language", _headers._AcceptLanguage); ++arrayIndex; } - - if (((_bits & 16777216L) != 0)) + if ((_bits & 8388608L) != 0) { if (arrayIndex == array.Length) { - ThrowArgumentException(); + return false; } - array[arrayIndex] = new KeyValuePair("Authorization", _headers._Authorization); ++arrayIndex; } - - if (((_bits & 33554432L) != 0)) + if ((_bits & 16777216L) != 0) { if (arrayIndex == array.Length) { - ThrowArgumentException(); + return false; } - array[arrayIndex] = new KeyValuePair("Cookie", _headers._Cookie); ++arrayIndex; } - - if (((_bits & 67108864L) != 0)) + if ((_bits & 33554432L) != 0) { if (arrayIndex == array.Length) { - ThrowArgumentException(); + return false; } - array[arrayIndex] = new KeyValuePair("Expect", _headers._Expect); ++arrayIndex; } - - if (((_bits & 134217728L) != 0)) + if ((_bits & 67108864L) != 0) { if (arrayIndex == array.Length) { - ThrowArgumentException(); + return false; } - array[arrayIndex] = new KeyValuePair("From", _headers._From); ++arrayIndex; } - - if (((_bits & 268435456L) != 0)) + if ((_bits & 134217728L) != 0) { if (arrayIndex == array.Length) { - ThrowArgumentException(); + return false; } - array[arrayIndex] = new KeyValuePair("Host", _headers._Host); ++arrayIndex; } - - if (((_bits & 536870912L) != 0)) + if ((_bits & 268435456L) != 0) { if (arrayIndex == array.Length) { - ThrowArgumentException(); + return false; } - array[arrayIndex] = new KeyValuePair("If-Match", _headers._IfMatch); ++arrayIndex; } - - if (((_bits & 1073741824L) != 0)) + if ((_bits & 536870912L) != 0) { if (arrayIndex == array.Length) { - ThrowArgumentException(); + return false; } - array[arrayIndex] = new KeyValuePair("If-Modified-Since", _headers._IfModifiedSince); ++arrayIndex; } - - if (((_bits & 2147483648L) != 0)) + if ((_bits & 1073741824L) != 0) { if (arrayIndex == array.Length) { - ThrowArgumentException(); + return false; } - array[arrayIndex] = new KeyValuePair("If-None-Match", _headers._IfNoneMatch); ++arrayIndex; } - - if (((_bits & 4294967296L) != 0)) + if ((_bits & 2147483648L) != 0) { if (arrayIndex == array.Length) { - ThrowArgumentException(); + return false; } - array[arrayIndex] = new KeyValuePair("If-Range", _headers._IfRange); ++arrayIndex; } - - if (((_bits & 8589934592L) != 0)) + if ((_bits & 4294967296L) != 0) { if (arrayIndex == array.Length) { - ThrowArgumentException(); + return false; } - array[arrayIndex] = new KeyValuePair("If-Unmodified-Since", _headers._IfUnmodifiedSince); ++arrayIndex; } - - if (((_bits & 17179869184L) != 0)) + if ((_bits & 8589934592L) != 0) { if (arrayIndex == array.Length) { - ThrowArgumentException(); + return false; } - array[arrayIndex] = new KeyValuePair("Max-Forwards", _headers._MaxForwards); ++arrayIndex; } - - if (((_bits & 34359738368L) != 0)) + if ((_bits & 17179869184L) != 0) { if (arrayIndex == array.Length) { - ThrowArgumentException(); + return false; } - array[arrayIndex] = new KeyValuePair("Proxy-Authorization", _headers._ProxyAuthorization); ++arrayIndex; } - - if (((_bits & 68719476736L) != 0)) + if ((_bits & 34359738368L) != 0) { if (arrayIndex == array.Length) { - ThrowArgumentException(); + return false; } - array[arrayIndex] = new KeyValuePair("Referer", _headers._Referer); ++arrayIndex; } - - if (((_bits & 137438953472L) != 0)) + if ((_bits & 68719476736L) != 0) { if (arrayIndex == array.Length) { - ThrowArgumentException(); + return false; } - array[arrayIndex] = new KeyValuePair("Range", _headers._Range); ++arrayIndex; } - - if (((_bits & 274877906944L) != 0)) + if ((_bits & 137438953472L) != 0) { if (arrayIndex == array.Length) { - ThrowArgumentException(); + return false; } - array[arrayIndex] = new KeyValuePair("TE", _headers._TE); ++arrayIndex; } - - if (((_bits & 549755813888L) != 0)) + if ((_bits & 274877906944L) != 0) { if (arrayIndex == array.Length) { - ThrowArgumentException(); + return false; } - array[arrayIndex] = new KeyValuePair("Translate", _headers._Translate); ++arrayIndex; } - - if (((_bits & 1099511627776L) != 0)) + if ((_bits & 549755813888L) != 0) { if (arrayIndex == array.Length) { - ThrowArgumentException(); + return false; } - array[arrayIndex] = new KeyValuePair("User-Agent", _headers._UserAgent); ++arrayIndex; } - - if (((_bits & 2199023255552L) != 0)) + if ((_bits & 1099511627776L) != 0) { if (arrayIndex == array.Length) { - ThrowArgumentException(); + return false; } - array[arrayIndex] = new KeyValuePair("Origin", _headers._Origin); ++arrayIndex; } - - if (((_bits & 4398046511104L) != 0)) + if ((_bits & 2199023255552L) != 0) { if (arrayIndex == array.Length) { - ThrowArgumentException(); + return false; } - array[arrayIndex] = new KeyValuePair("Access-Control-Request-Method", _headers._AccessControlRequestMethod); ++arrayIndex; } - - if (((_bits & 8796093022208L) != 0)) + if ((_bits & 4398046511104L) != 0) { if (arrayIndex == array.Length) { - ThrowArgumentException(); + return false; } - array[arrayIndex] = new KeyValuePair("Access-Control-Request-Headers", _headers._AccessControlRequestHeaders); ++arrayIndex; } - + if (_contentLength.HasValue) + { + if (arrayIndex == array.Length) + { + return false; + } + array[arrayIndex] = new KeyValuePair("Content-Length", HeaderUtilities.FormatInt64(_contentLength.Value)); + ++arrayIndex; + } ((ICollection>)MaybeUnknown)?.CopyTo(array, arrayIndex); + + return true; } @@ -4651,20 +3509,21 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var pUL = (ulong*)pUB; var pUI = (uint*)pUB; var pUS = (ushort*)pUB; + var stringValue = new StringValues(value); switch (keyLength) { case 6: { if ((((pUI[0] & 3755991007u) == 1162036033u) && ((pUS[2] & 57311u) == 21584u))) { - if (((_bits & 1048576L) != 0)) + if ((_bits & 524288L) != 0) { _headers._Accept = AppendValue(_headers._Accept, value); } else { - _bits |= 1048576L; - _headers._Accept = new StringValues(value); + _bits |= 524288L; + _headers._Accept = stringValue; } return; } @@ -4675,14 +3534,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { if ((((pUI[0] & 3755991007u) == 1414745928u))) { - if (((_bits & 268435456L) != 0)) + if ((_bits & 134217728L) != 0) { _headers._Host = AppendValue(_headers._Host, value); } else { - _bits |= 268435456L; - _headers._Host = new StringValues(value); + _bits |= 134217728L; + _headers._Host = stringValue; } return; } @@ -4693,14 +3552,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { if ((((pUL[0] & 16131858680330051551uL) == 4992030374873092949uL) && ((pUS[4] & 57311u) == 21582u))) { - if (((_bits & 1099511627776L) != 0)) + if ((_bits & 549755813888L) != 0) { _headers._UserAgent = AppendValue(_headers._UserAgent, value); } else { - _bits |= 1099511627776L; - _headers._UserAgent = new StringValues(value); + _bits |= 549755813888L; + _headers._UserAgent = stringValue; } return; } @@ -4708,91 +3567,87 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http break; } - + AppendNonPrimaryHeaders(ptr, keyOffset, keyLength, value); } - - AppendNonPrimaryHeaders(keyBytes, keyOffset, keyLength, value); } - private unsafe void AppendNonPrimaryHeaders(byte[] keyBytes, int keyOffset, int keyLength, string value) + private unsafe void AppendNonPrimaryHeaders(byte* pKeyBytes, int keyOffset, int keyLength, string value) { - string key; - fixed (byte* ptr = &keyBytes[keyOffset]) - { - var pUB = ptr; + var pUB = pKeyBytes; var pUL = (ulong*)pUB; var pUI = (uint*)pUB; var pUS = (ushort*)pUB; + var stringValue = new StringValues(value); switch (keyLength) { case 13: { if ((((pUL[0] & 16131893727263186911uL) == 5711458528024281411uL) && ((pUI[2] & 3755991007u) == 1330795598u) && ((pUB[12] & 223u) == 76u))) { - if (((_bits & 1L) != 0)) + if ((_bits & 1L) != 0) { _headers._CacheControl = AppendValue(_headers._CacheControl, value); } else { _bits |= 1L; - _headers._CacheControl = new StringValues(value); + _headers._CacheControl = stringValue; } return; } if ((((pUL[0] & 18437701552104792031uL) == 3266321689424580419uL) && ((pUI[2] & 3755991007u) == 1196310866u) && ((pUB[12] & 223u) == 69u))) { - if (((_bits & 131072L) != 0)) + if ((_bits & 65536L) != 0) { _headers._ContentRange = AppendValue(_headers._ContentRange, value); } else { - _bits |= 131072L; - _headers._ContentRange = new StringValues(value); + _bits |= 65536L; + _headers._ContentRange = stringValue; } return; } if ((((pUL[0] & 16131858680330051551uL) == 4922237774822850892uL) && ((pUI[2] & 3755991007u) == 1162430025u) && ((pUB[12] & 223u) == 68u))) { - if (((_bits & 524288L) != 0)) + if ((_bits & 262144L) != 0) { _headers._LastModified = AppendValue(_headers._LastModified, value); } else { - _bits |= 524288L; - _headers._LastModified = new StringValues(value); + _bits |= 262144L; + _headers._LastModified = stringValue; } return; } if ((((pUL[0] & 16131858542891098079uL) == 6505821637182772545uL) && ((pUI[2] & 3755991007u) == 1330205761u) && ((pUB[12] & 223u) == 78u))) { - if (((_bits & 16777216L) != 0)) + if ((_bits & 8388608L) != 0) { _headers._Authorization = AppendValue(_headers._Authorization, value); } else { - _bits |= 16777216L; - _headers._Authorization = new StringValues(value); + _bits |= 8388608L; + _headers._Authorization = stringValue; } return; } if ((((pUL[0] & 18437701552106889183uL) == 3262099607620765257uL) && ((pUI[2] & 3755991007u) == 1129595213u) && ((pUB[12] & 223u) == 72u))) { - if (((_bits & 2147483648L) != 0)) + if ((_bits & 1073741824L) != 0) { _headers._IfNoneMatch = AppendValue(_headers._IfNoneMatch, value); } else { - _bits |= 2147483648L; - _headers._IfNoneMatch = new StringValues(value); + _bits |= 1073741824L; + _headers._IfNoneMatch = stringValue; } return; } @@ -4803,28 +3658,28 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { if ((((pUL[0] & 16131858542891098079uL) == 5283922227757993795uL) && ((pUS[4] & 57311u) == 20047u))) { - if (((_bits & 2L) != 0)) + if ((_bits & 2L) != 0) { _headers._Connection = AppendValue(_headers._Connection, value); } else { _bits |= 2L; - _headers._Connection = new StringValues(value); + _headers._Connection = stringValue; } return; } if ((((pUL[0] & 16131858680330051551uL) == 5281668125874799947uL) && ((pUS[4] & 57311u) == 17750u))) { - if (((_bits & 8L) != 0)) + if ((_bits & 8L) != 0) { _headers._KeepAlive = AppendValue(_headers._KeepAlive, value); } else { _bits |= 8L; - _headers._KeepAlive = new StringValues(value); + _headers._KeepAlive = stringValue; } return; } @@ -4835,28 +3690,28 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { if ((((pUI[0] & 3755991007u) == 1163149636u))) { - if (((_bits & 4L) != 0)) + if ((_bits & 4L) != 0) { _headers._Date = AppendValue(_headers._Date, value); } else { _bits |= 4L; - _headers._Date = new StringValues(value); + _headers._Date = stringValue; } return; } if ((((pUI[0] & 3755991007u) == 1297044038u))) { - if (((_bits & 134217728L) != 0)) + if ((_bits & 67108864L) != 0) { _headers._From = AppendValue(_headers._From, value); } else { - _bits |= 134217728L; - _headers._From = new StringValues(value); + _bits |= 67108864L; + _headers._From = stringValue; } return; } @@ -4867,56 +3722,56 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { if ((((pUI[0] & 3755991007u) == 1195463248u) && ((pUS[2] & 57311u) == 16717u))) { - if (((_bits & 16L) != 0)) + if ((_bits & 16L) != 0) { _headers._Pragma = AppendValue(_headers._Pragma, value); } else { _bits |= 16L; - _headers._Pragma = new StringValues(value); + _headers._Pragma = stringValue; } return; } if ((((pUI[0] & 3755991007u) == 1263488835u) && ((pUS[2] & 57311u) == 17737u))) { - if (((_bits & 33554432L) != 0)) + if ((_bits & 16777216L) != 0) { _headers._Cookie = AppendValue(_headers._Cookie, value); } else { - _bits |= 33554432L; - _headers._Cookie = new StringValues(value); + _bits |= 16777216L; + _headers._Cookie = stringValue; } return; } if ((((pUI[0] & 3755991007u) == 1162893381u) && ((pUS[2] & 57311u) == 21571u))) { - if (((_bits & 67108864L) != 0)) + if ((_bits & 33554432L) != 0) { _headers._Expect = AppendValue(_headers._Expect, value); } else { - _bits |= 67108864L; - _headers._Expect = new StringValues(value); + _bits |= 33554432L; + _headers._Expect = stringValue; } return; } if ((((pUI[0] & 3755991007u) == 1195987535u) && ((pUS[2] & 57311u) == 20041u))) { - if (((_bits & 2199023255552L) != 0)) + if ((_bits & 1099511627776L) != 0) { _headers._Origin = AppendValue(_headers._Origin, value); } else { - _bits |= 2199023255552L; - _headers._Origin = new StringValues(value); + _bits |= 1099511627776L; + _headers._Origin = stringValue; } return; } @@ -4927,70 +3782,70 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { if ((((pUI[0] & 3755991007u) == 1229017684u) && ((pUS[2] & 57311u) == 17740u) && ((pUB[6] & 223u) == 82u))) { - if (((_bits & 32L) != 0)) + if ((_bits & 32L) != 0) { _headers._Trailer = AppendValue(_headers._Trailer, value); } else { _bits |= 32L; - _headers._Trailer = new StringValues(value); + _headers._Trailer = stringValue; } return; } if ((((pUI[0] & 3755991007u) == 1380405333u) && ((pUS[2] & 57311u) == 17473u) && ((pUB[6] & 223u) == 69u))) { - if (((_bits & 128L) != 0)) + if ((_bits & 128L) != 0) { _headers._Upgrade = AppendValue(_headers._Upgrade, value); } else { _bits |= 128L; - _headers._Upgrade = new StringValues(value); + _headers._Upgrade = stringValue; } return; } if ((((pUI[0] & 3755991007u) == 1314013527u) && ((pUS[2] & 57311u) == 20041u) && ((pUB[6] & 223u) == 71u))) { - if (((_bits & 512L) != 0)) + if ((_bits & 512L) != 0) { _headers._Warning = AppendValue(_headers._Warning, value); } else { _bits |= 512L; - _headers._Warning = new StringValues(value); + _headers._Warning = stringValue; } return; } if ((((pUI[0] & 3755991007u) == 1230002245u) && ((pUS[2] & 57311u) == 17746u) && ((pUB[6] & 223u) == 83u))) { - if (((_bits & 262144L) != 0)) + if ((_bits & 131072L) != 0) { _headers._Expires = AppendValue(_headers._Expires, value); } else { - _bits |= 262144L; - _headers._Expires = new StringValues(value); + _bits |= 131072L; + _headers._Expires = stringValue; } return; } if ((((pUI[0] & 3755991007u) == 1162233170u) && ((pUS[2] & 57311u) == 17746u) && ((pUB[6] & 223u) == 82u))) { - if (((_bits & 68719476736L) != 0)) + if ((_bits & 34359738368L) != 0) { _headers._Referer = AppendValue(_headers._Referer, value); } else { - _bits |= 68719476736L; - _headers._Referer = new StringValues(value); + _bits |= 34359738368L; + _headers._Referer = stringValue; } return; } @@ -5001,28 +3856,28 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { if ((((pUL[0] & 16131858542891098079uL) == 5928221808112259668uL) && ((pUL[1] & 16131858542891098111uL) == 5641115115480565037uL) && ((pUB[16] & 223u) == 71u))) { - if (((_bits & 64L) != 0)) + if ((_bits & 64L) != 0) { _headers._TransferEncoding = AppendValue(_headers._TransferEncoding, value); } else { _bits |= 64L; - _headers._TransferEncoding = new StringValues(value); + _headers._TransferEncoding = stringValue; } return; } if ((((pUL[0] & 16131858542893195231uL) == 5064654363342751305uL) && ((pUL[1] & 16131858543427968991uL) == 4849894470315165001uL) && ((pUB[16] & 223u) == 69u))) { - if (((_bits & 1073741824L) != 0)) + if ((_bits & 536870912L) != 0) { _headers._IfModifiedSince = AppendValue(_headers._IfModifiedSince, value); } else { - _bits |= 1073741824L; - _headers._IfModifiedSince = new StringValues(value); + _bits |= 536870912L; + _headers._IfModifiedSince = stringValue; } return; } @@ -5033,14 +3888,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { if ((((pUS[0] & 57311u) == 18774u) && ((pUB[2] & 223u) == 65u))) { - if (((_bits & 256L) != 0)) + if ((_bits & 256L) != 0) { _headers._Via = AppendValue(_headers._Via, value); } else { _bits |= 256L; - _headers._Via = new StringValues(value); + _headers._Via = stringValue; } return; } @@ -5051,60 +3906,28 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { if ((((pUI[0] & 3755991007u) == 1330400321u) && ((pUB[4] & 223u) == 87u))) { - if (((_bits & 1024L) != 0)) + if ((_bits & 1024L) != 0) { _headers._Allow = AppendValue(_headers._Allow, value); } else { _bits |= 1024L; - _headers._Allow = new StringValues(value); + _headers._Allow = stringValue; } return; } if ((((pUI[0] & 3755991007u) == 1196310866u) && ((pUB[4] & 223u) == 69u))) { - if (((_bits & 137438953472L) != 0)) + if ((_bits & 68719476736L) != 0) { _headers._Range = AppendValue(_headers._Range, value); } else { - _bits |= 137438953472L; - _headers._Range = new StringValues(value); - } - return; - } - } - break; - - case 14: - { - if ((((pUL[0] & 18437701552104792031uL) == 3266321689424580419uL) && ((pUI[2] & 3755991007u) == 1196311884u) && ((pUS[6] & 57311u) == 18516u))) - { - if (((_bits & 2048L) != 0)) - { - _headers._ContentLength = AppendValue(_headers._ContentLength, value); - } - else - { - _bits |= 2048L; - _headers._ContentLength = new StringValues(value); - } - return; - } - - if ((((pUL[0] & 16140865742145839071uL) == 4840617878229304129uL) && ((pUI[2] & 3755991007u) == 1397899592u) && ((pUS[6] & 57311u) == 21573u))) - { - if (((_bits & 2097152L) != 0)) - { - _headers._AcceptCharset = AppendValue(_headers._AcceptCharset, value); - } - else - { - _bits |= 2097152L; - _headers._AcceptCharset = new StringValues(value); + _bits |= 68719476736L; + _headers._Range = stringValue; } return; } @@ -5115,28 +3938,28 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { if ((((pUL[0] & 18437701552104792031uL) == 3266321689424580419uL) && ((pUI[2] & 3755991007u) == 1162893652u))) { - if (((_bits & 4096L) != 0)) + if ((_bits & 2048L) != 0) { _headers._ContentType = AppendValue(_headers._ContentType, value); } else { - _bits |= 4096L; - _headers._ContentType = new StringValues(value); + _bits |= 2048L; + _headers._ContentType = stringValue; } return; } if ((((pUL[0] & 16131858543427968991uL) == 6292178792217067853uL) && ((pUI[2] & 3755991007u) == 1396986433u))) { - if (((_bits & 17179869184L) != 0)) + if ((_bits & 8589934592L) != 0) { _headers._MaxForwards = AppendValue(_headers._MaxForwards, value); } else { - _bits |= 17179869184L; - _headers._MaxForwards = new StringValues(value); + _bits |= 8589934592L; + _headers._MaxForwards = stringValue; } return; } @@ -5147,42 +3970,42 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { if ((((pUL[0] & 18437701552104792031uL) == 3266321689424580419uL) && ((pUL[1] & 16131858542891098079uL) == 5138124782612729413uL))) { - if (((_bits & 8192L) != 0)) + if ((_bits & 4096L) != 0) { _headers._ContentEncoding = AppendValue(_headers._ContentEncoding, value); } else { - _bits |= 8192L; - _headers._ContentEncoding = new StringValues(value); + _bits |= 4096L; + _headers._ContentEncoding = stringValue; } return; } if ((((pUL[0] & 18437701552104792031uL) == 3266321689424580419uL) && ((pUL[1] & 16131858542891098079uL) == 4992030546487820620uL))) { - if (((_bits & 16384L) != 0)) + if ((_bits & 8192L) != 0) { _headers._ContentLanguage = AppendValue(_headers._ContentLanguage, value); } else { - _bits |= 16384L; - _headers._ContentLanguage = new StringValues(value); + _bits |= 8192L; + _headers._ContentLanguage = stringValue; } return; } if ((((pUL[0] & 18437701552104792031uL) == 3266321689424580419uL) && ((pUL[1] & 16131858542891098079uL) == 5642809484339531596uL))) { - if (((_bits & 32768L) != 0)) + if ((_bits & 16384L) != 0) { _headers._ContentLocation = AppendValue(_headers._ContentLocation, value); } else { - _bits |= 32768L; - _headers._ContentLocation = new StringValues(value); + _bits |= 16384L; + _headers._ContentLocation = stringValue; } return; } @@ -5193,14 +4016,45 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { if ((((pUL[0] & 18437701552104792031uL) == 3266321689424580419uL) && ((pUS[4] & 57311u) == 17485u) && ((pUB[10] & 255u) == 53u))) { - if (((_bits & 65536L) != 0)) + if ((_bits & 32768L) != 0) { _headers._ContentMD5 = AppendValue(_headers._ContentMD5, value); } else { - _bits |= 65536L; - _headers._ContentMD5 = new StringValues(value); + _bits |= 32768L; + _headers._ContentMD5 = stringValue; + } + return; + } + } + break; + + case 14: + { + if ((((pUL[0] & 16140865742145839071uL) == 4840617878229304129uL) && ((pUI[2] & 3755991007u) == 1397899592u) && ((pUS[6] & 57311u) == 21573u))) + { + if ((_bits & 1048576L) != 0) + { + _headers._AcceptCharset = AppendValue(_headers._AcceptCharset, value); + } + else + { + _bits |= 1048576L; + _headers._AcceptCharset = stringValue; + } + return; + } + + if ((((pUL[0] & 18437701552104792031uL) == 3266321689424580419uL) && ((pUI[2] & 3755991007u) == 1196311884u) && ((pUS[6] & 57311u) == 18516u))) + { + if (_contentLength.HasValue) + { + ThrowMultipleContentLengthsException(); + } + else + { + _contentLength = ParseContentLength(value); } return; } @@ -5211,28 +4065,28 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { if ((((pUL[0] & 16140865742145839071uL) == 4984733066305160001uL) && ((pUI[2] & 3755991007u) == 1146045262u) && ((pUS[6] & 57311u) == 20041u) && ((pUB[14] & 223u) == 71u))) { - if (((_bits & 4194304L) != 0)) + if ((_bits & 2097152L) != 0) { _headers._AcceptEncoding = AppendValue(_headers._AcceptEncoding, value); } else { - _bits |= 4194304L; - _headers._AcceptEncoding = new StringValues(value); + _bits |= 2097152L; + _headers._AcceptEncoding = stringValue; } return; } if ((((pUL[0] & 16140865742145839071uL) == 5489136224570655553uL) && ((pUI[2] & 3755991007u) == 1430736449u) && ((pUS[6] & 57311u) == 18241u) && ((pUB[14] & 223u) == 69u))) { - if (((_bits & 8388608L) != 0)) + if ((_bits & 4194304L) != 0) { _headers._AcceptLanguage = AppendValue(_headers._AcceptLanguage, value); } else { - _bits |= 8388608L; - _headers._AcceptLanguage = new StringValues(value); + _bits |= 4194304L; + _headers._AcceptLanguage = stringValue; } return; } @@ -5243,28 +4097,28 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { if ((((pUL[0] & 16131858542893195231uL) == 5207098233614845513uL))) { - if (((_bits & 536870912L) != 0)) + if ((_bits & 268435456L) != 0) { _headers._IfMatch = AppendValue(_headers._IfMatch, value); } else { - _bits |= 536870912L; - _headers._IfMatch = new StringValues(value); + _bits |= 268435456L; + _headers._IfMatch = stringValue; } return; } if ((((pUL[0] & 16131858542893195231uL) == 4992044754422023753uL))) { - if (((_bits & 4294967296L) != 0)) + if ((_bits & 2147483648L) != 0) { _headers._IfRange = AppendValue(_headers._IfRange, value); } else { - _bits |= 4294967296L; - _headers._IfRange = new StringValues(value); + _bits |= 2147483648L; + _headers._IfRange = stringValue; } return; } @@ -5275,28 +4129,28 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { if ((((pUL[0] & 16131858542893195231uL) == 4922237916571059785uL) && ((pUL[1] & 16131893727263186911uL) == 5283616559079179849uL) && ((pUS[8] & 57311u) == 17230u) && ((pUB[18] & 223u) == 69u))) { - if (((_bits & 8589934592L) != 0)) + if ((_bits & 4294967296L) != 0) { _headers._IfUnmodifiedSince = AppendValue(_headers._IfUnmodifiedSince, value); } else { - _bits |= 8589934592L; - _headers._IfUnmodifiedSince = new StringValues(value); + _bits |= 4294967296L; + _headers._IfUnmodifiedSince = stringValue; } return; } if ((((pUL[0] & 16131893727263186911uL) == 6143241228466999888uL) && ((pUL[1] & 16131858542891098079uL) == 6071233043632179284uL) && ((pUS[8] & 57311u) == 20297u) && ((pUB[18] & 223u) == 78u))) { - if (((_bits & 34359738368L) != 0)) + if ((_bits & 17179869184L) != 0) { _headers._ProxyAuthorization = AppendValue(_headers._ProxyAuthorization, value); } else { - _bits |= 34359738368L; - _headers._ProxyAuthorization = new StringValues(value); + _bits |= 17179869184L; + _headers._ProxyAuthorization = stringValue; } return; } @@ -5307,14 +4161,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { if ((((pUS[0] & 57311u) == 17748u))) { - if (((_bits & 274877906944L) != 0)) + if ((_bits & 137438953472L) != 0) { _headers._TE = AppendValue(_headers._TE, value); } else { - _bits |= 274877906944L; - _headers._TE = new StringValues(value); + _bits |= 137438953472L; + _headers._TE = stringValue; } return; } @@ -5325,14 +4179,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { if ((((pUL[0] & 16131858542891098079uL) == 6071217693351039572uL) && ((pUB[8] & 223u) == 69u))) { - if (((_bits & 549755813888L) != 0)) + if ((_bits & 274877906944L) != 0) { _headers._Translate = AppendValue(_headers._Translate, value); } else { - _bits |= 549755813888L; - _headers._Translate = new StringValues(value); + _bits |= 274877906944L; + _headers._Translate = stringValue; } return; } @@ -5343,14 +4197,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { if ((((pUL[0] & 16140865742145839071uL) == 4840616791602578241uL) && ((pUL[1] & 16140865742145839071uL) == 5921472988629454415uL) && ((pUL[2] & 16140865742145839071uL) == 5561193831494668613uL) && ((pUI[6] & 3755991007u) == 1330140229u) && ((pUB[28] & 223u) == 68u))) { - if (((_bits & 4398046511104L) != 0)) + if ((_bits & 2199023255552L) != 0) { _headers._AccessControlRequestMethod = AppendValue(_headers._AccessControlRequestMethod, value); } else { - _bits |= 4398046511104L; - _headers._AccessControlRequestMethod = new StringValues(value); + _bits |= 2199023255552L; + _headers._AccessControlRequestMethod = stringValue; } return; } @@ -5361,14 +4215,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { if ((((pUL[0] & 16140865742145839071uL) == 4840616791602578241uL) && ((pUL[1] & 16140865742145839071uL) == 5921472988629454415uL) && ((pUL[2] & 16140865742145839071uL) == 5200905861305028933uL) && ((pUI[6] & 3755991007u) == 1162101061u) && ((pUS[14] & 57311u) == 21330u))) { - if (((_bits & 8796093022208L) != 0)) + if ((_bits & 4398046511104L) != 0) { _headers._AccessControlRequestHeaders = AppendValue(_headers._AccessControlRequestHeaders, value); } else { - _bits |= 8796093022208L; - _headers._AccessControlRequestHeaders = new StringValues(value); + _bits |= 4398046511104L; + _headers._AccessControlRequestHeaders = stringValue; } return; } @@ -5376,22 +4230,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http break; } - - key = new string('\0', keyLength); - fixed(char *keyBuffer = key) - { - if (!AsciiUtilities.TryGetAsciiString(ptr, keyBuffer, keyLength)) - { - throw BadHttpRequestException.GetException(RequestRejectionReason.InvalidCharactersInHeaderName); - } - } - - } - - StringValues existing; - Unknown.TryGetValue(key, out existing); - Unknown[key] = AppendValue(existing, value); + AppendUnknownHeaders(pKeyBytes, keyLength, value); } + private struct HeaderReferences { public StringValues _CacheControl; @@ -5405,7 +4246,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http public StringValues _Via; public StringValues _Warning; public StringValues _Allow; - public StringValues _ContentLength; public StringValues _ContentType; public StringValues _ContentEncoding; public StringValues _ContentLanguage; @@ -5448,144 +4288,143 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http switch (_state) { - case 0: - goto state0; + case 0: + goto state0; - case 1: - goto state1; + case 1: + goto state1; - case 2: - goto state2; + case 2: + goto state2; - case 3: - goto state3; + case 3: + goto state3; - case 4: - goto state4; + case 4: + goto state4; - case 5: - goto state5; + case 5: + goto state5; - case 6: - goto state6; + case 6: + goto state6; - case 7: - goto state7; + case 7: + goto state7; - case 8: - goto state8; + case 8: + goto state8; - case 9: - goto state9; + case 9: + goto state9; - case 10: - goto state10; + case 10: + goto state10; - case 11: - goto state11; + case 11: + goto state11; - case 12: - goto state12; + case 12: + goto state12; - case 13: - goto state13; + case 13: + goto state13; - case 14: - goto state14; + case 14: + goto state14; - case 15: - goto state15; + case 15: + goto state15; - case 16: - goto state16; + case 16: + goto state16; - case 17: - goto state17; + case 17: + goto state17; - case 18: - goto state18; + case 18: + goto state18; - case 19: - goto state19; + case 19: + goto state19; - case 20: - goto state20; + case 20: + goto state20; - case 21: - goto state21; + case 21: + goto state21; - case 22: - goto state22; + case 22: + goto state22; - case 23: - goto state23; + case 23: + goto state23; - case 24: - goto state24; + case 24: + goto state24; - case 25: - goto state25; + case 25: + goto state25; - case 26: - goto state26; + case 26: + goto state26; - case 27: - goto state27; + case 27: + goto state27; - case 28: - goto state28; + case 28: + goto state28; - case 29: - goto state29; + case 29: + goto state29; - case 30: - goto state30; + case 30: + goto state30; - case 31: - goto state31; + case 31: + goto state31; - case 32: - goto state32; + case 32: + goto state32; - case 33: - goto state33; + case 33: + goto state33; - case 34: - goto state34; + case 34: + goto state34; - case 35: - goto state35; + case 35: + goto state35; - case 36: - goto state36; + case 36: + goto state36; - case 37: - goto state37; + case 37: + goto state37; - case 38: - goto state38; + case 38: + goto state38; - case 39: - goto state39; + case 39: + goto state39; - case 40: - goto state40; + case 40: + goto state40; - case 41: - goto state41; + case 41: + goto state41; - case 42: - goto state42; - - case 43: - goto state43; + case 42: + goto state42; + case 44: + goto state44; default: goto state_default; } state0: - if (((_bits & 1L) != 0)) + if ((_bits & 1L) != 0) { _current = new KeyValuePair("Cache-Control", _collection._headers._CacheControl); _state = 1; @@ -5593,7 +4432,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } state1: - if (((_bits & 2L) != 0)) + if ((_bits & 2L) != 0) { _current = new KeyValuePair("Connection", _collection._headers._Connection); _state = 2; @@ -5601,7 +4440,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } state2: - if (((_bits & 4L) != 0)) + if ((_bits & 4L) != 0) { _current = new KeyValuePair("Date", _collection._headers._Date); _state = 3; @@ -5609,7 +4448,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } state3: - if (((_bits & 8L) != 0)) + if ((_bits & 8L) != 0) { _current = new KeyValuePair("Keep-Alive", _collection._headers._KeepAlive); _state = 4; @@ -5617,7 +4456,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } state4: - if (((_bits & 16L) != 0)) + if ((_bits & 16L) != 0) { _current = new KeyValuePair("Pragma", _collection._headers._Pragma); _state = 5; @@ -5625,7 +4464,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } state5: - if (((_bits & 32L) != 0)) + if ((_bits & 32L) != 0) { _current = new KeyValuePair("Trailer", _collection._headers._Trailer); _state = 6; @@ -5633,7 +4472,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } state6: - if (((_bits & 64L) != 0)) + if ((_bits & 64L) != 0) { _current = new KeyValuePair("Transfer-Encoding", _collection._headers._TransferEncoding); _state = 7; @@ -5641,7 +4480,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } state7: - if (((_bits & 128L) != 0)) + if ((_bits & 128L) != 0) { _current = new KeyValuePair("Upgrade", _collection._headers._Upgrade); _state = 8; @@ -5649,7 +4488,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } state8: - if (((_bits & 256L) != 0)) + if ((_bits & 256L) != 0) { _current = new KeyValuePair("Via", _collection._headers._Via); _state = 9; @@ -5657,7 +4496,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } state9: - if (((_bits & 512L) != 0)) + if ((_bits & 512L) != 0) { _current = new KeyValuePair("Warning", _collection._headers._Warning); _state = 10; @@ -5665,7 +4504,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } state10: - if (((_bits & 1024L) != 0)) + if ((_bits & 1024L) != 0) { _current = new KeyValuePair("Allow", _collection._headers._Allow); _state = 11; @@ -5673,269 +4512,268 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } state11: - if (((_bits & 2048L) != 0)) + if ((_bits & 2048L) != 0) { - _current = new KeyValuePair("Content-Length", _collection._headers._ContentLength); + _current = new KeyValuePair("Content-Type", _collection._headers._ContentType); _state = 12; return true; } state12: - if (((_bits & 4096L) != 0)) + if ((_bits & 4096L) != 0) { - _current = new KeyValuePair("Content-Type", _collection._headers._ContentType); + _current = new KeyValuePair("Content-Encoding", _collection._headers._ContentEncoding); _state = 13; return true; } state13: - if (((_bits & 8192L) != 0)) + if ((_bits & 8192L) != 0) { - _current = new KeyValuePair("Content-Encoding", _collection._headers._ContentEncoding); + _current = new KeyValuePair("Content-Language", _collection._headers._ContentLanguage); _state = 14; return true; } state14: - if (((_bits & 16384L) != 0)) + if ((_bits & 16384L) != 0) { - _current = new KeyValuePair("Content-Language", _collection._headers._ContentLanguage); + _current = new KeyValuePair("Content-Location", _collection._headers._ContentLocation); _state = 15; return true; } state15: - if (((_bits & 32768L) != 0)) + if ((_bits & 32768L) != 0) { - _current = new KeyValuePair("Content-Location", _collection._headers._ContentLocation); + _current = new KeyValuePair("Content-MD5", _collection._headers._ContentMD5); _state = 16; return true; } state16: - if (((_bits & 65536L) != 0)) + if ((_bits & 65536L) != 0) { - _current = new KeyValuePair("Content-MD5", _collection._headers._ContentMD5); + _current = new KeyValuePair("Content-Range", _collection._headers._ContentRange); _state = 17; return true; } state17: - if (((_bits & 131072L) != 0)) + if ((_bits & 131072L) != 0) { - _current = new KeyValuePair("Content-Range", _collection._headers._ContentRange); + _current = new KeyValuePair("Expires", _collection._headers._Expires); _state = 18; return true; } state18: - if (((_bits & 262144L) != 0)) + if ((_bits & 262144L) != 0) { - _current = new KeyValuePair("Expires", _collection._headers._Expires); + _current = new KeyValuePair("Last-Modified", _collection._headers._LastModified); _state = 19; return true; } state19: - if (((_bits & 524288L) != 0)) + if ((_bits & 524288L) != 0) { - _current = new KeyValuePair("Last-Modified", _collection._headers._LastModified); + _current = new KeyValuePair("Accept", _collection._headers._Accept); _state = 20; return true; } state20: - if (((_bits & 1048576L) != 0)) + if ((_bits & 1048576L) != 0) { - _current = new KeyValuePair("Accept", _collection._headers._Accept); + _current = new KeyValuePair("Accept-Charset", _collection._headers._AcceptCharset); _state = 21; return true; } state21: - if (((_bits & 2097152L) != 0)) + if ((_bits & 2097152L) != 0) { - _current = new KeyValuePair("Accept-Charset", _collection._headers._AcceptCharset); + _current = new KeyValuePair("Accept-Encoding", _collection._headers._AcceptEncoding); _state = 22; return true; } state22: - if (((_bits & 4194304L) != 0)) + if ((_bits & 4194304L) != 0) { - _current = new KeyValuePair("Accept-Encoding", _collection._headers._AcceptEncoding); + _current = new KeyValuePair("Accept-Language", _collection._headers._AcceptLanguage); _state = 23; return true; } state23: - if (((_bits & 8388608L) != 0)) + if ((_bits & 8388608L) != 0) { - _current = new KeyValuePair("Accept-Language", _collection._headers._AcceptLanguage); + _current = new KeyValuePair("Authorization", _collection._headers._Authorization); _state = 24; return true; } state24: - if (((_bits & 16777216L) != 0)) + if ((_bits & 16777216L) != 0) { - _current = new KeyValuePair("Authorization", _collection._headers._Authorization); + _current = new KeyValuePair("Cookie", _collection._headers._Cookie); _state = 25; return true; } state25: - if (((_bits & 33554432L) != 0)) + if ((_bits & 33554432L) != 0) { - _current = new KeyValuePair("Cookie", _collection._headers._Cookie); + _current = new KeyValuePair("Expect", _collection._headers._Expect); _state = 26; return true; } state26: - if (((_bits & 67108864L) != 0)) + if ((_bits & 67108864L) != 0) { - _current = new KeyValuePair("Expect", _collection._headers._Expect); + _current = new KeyValuePair("From", _collection._headers._From); _state = 27; return true; } state27: - if (((_bits & 134217728L) != 0)) + if ((_bits & 134217728L) != 0) { - _current = new KeyValuePair("From", _collection._headers._From); + _current = new KeyValuePair("Host", _collection._headers._Host); _state = 28; return true; } state28: - if (((_bits & 268435456L) != 0)) + if ((_bits & 268435456L) != 0) { - _current = new KeyValuePair("Host", _collection._headers._Host); + _current = new KeyValuePair("If-Match", _collection._headers._IfMatch); _state = 29; return true; } state29: - if (((_bits & 536870912L) != 0)) + if ((_bits & 536870912L) != 0) { - _current = new KeyValuePair("If-Match", _collection._headers._IfMatch); + _current = new KeyValuePair("If-Modified-Since", _collection._headers._IfModifiedSince); _state = 30; return true; } state30: - if (((_bits & 1073741824L) != 0)) + if ((_bits & 1073741824L) != 0) { - _current = new KeyValuePair("If-Modified-Since", _collection._headers._IfModifiedSince); + _current = new KeyValuePair("If-None-Match", _collection._headers._IfNoneMatch); _state = 31; return true; } state31: - if (((_bits & 2147483648L) != 0)) + if ((_bits & 2147483648L) != 0) { - _current = new KeyValuePair("If-None-Match", _collection._headers._IfNoneMatch); + _current = new KeyValuePair("If-Range", _collection._headers._IfRange); _state = 32; return true; } state32: - if (((_bits & 4294967296L) != 0)) + if ((_bits & 4294967296L) != 0) { - _current = new KeyValuePair("If-Range", _collection._headers._IfRange); + _current = new KeyValuePair("If-Unmodified-Since", _collection._headers._IfUnmodifiedSince); _state = 33; return true; } state33: - if (((_bits & 8589934592L) != 0)) + if ((_bits & 8589934592L) != 0) { - _current = new KeyValuePair("If-Unmodified-Since", _collection._headers._IfUnmodifiedSince); + _current = new KeyValuePair("Max-Forwards", _collection._headers._MaxForwards); _state = 34; return true; } state34: - if (((_bits & 17179869184L) != 0)) + if ((_bits & 17179869184L) != 0) { - _current = new KeyValuePair("Max-Forwards", _collection._headers._MaxForwards); + _current = new KeyValuePair("Proxy-Authorization", _collection._headers._ProxyAuthorization); _state = 35; return true; } state35: - if (((_bits & 34359738368L) != 0)) + if ((_bits & 34359738368L) != 0) { - _current = new KeyValuePair("Proxy-Authorization", _collection._headers._ProxyAuthorization); + _current = new KeyValuePair("Referer", _collection._headers._Referer); _state = 36; return true; } state36: - if (((_bits & 68719476736L) != 0)) + if ((_bits & 68719476736L) != 0) { - _current = new KeyValuePair("Referer", _collection._headers._Referer); + _current = new KeyValuePair("Range", _collection._headers._Range); _state = 37; return true; } state37: - if (((_bits & 137438953472L) != 0)) + if ((_bits & 137438953472L) != 0) { - _current = new KeyValuePair("Range", _collection._headers._Range); + _current = new KeyValuePair("TE", _collection._headers._TE); _state = 38; return true; } state38: - if (((_bits & 274877906944L) != 0)) + if ((_bits & 274877906944L) != 0) { - _current = new KeyValuePair("TE", _collection._headers._TE); + _current = new KeyValuePair("Translate", _collection._headers._Translate); _state = 39; return true; } state39: - if (((_bits & 549755813888L) != 0)) + if ((_bits & 549755813888L) != 0) { - _current = new KeyValuePair("Translate", _collection._headers._Translate); + _current = new KeyValuePair("User-Agent", _collection._headers._UserAgent); _state = 40; return true; } state40: - if (((_bits & 1099511627776L) != 0)) + if ((_bits & 1099511627776L) != 0) { - _current = new KeyValuePair("User-Agent", _collection._headers._UserAgent); + _current = new KeyValuePair("Origin", _collection._headers._Origin); _state = 41; return true; } state41: - if (((_bits & 2199023255552L) != 0)) + if ((_bits & 2199023255552L) != 0) { - _current = new KeyValuePair("Origin", _collection._headers._Origin); + _current = new KeyValuePair("Access-Control-Request-Method", _collection._headers._AccessControlRequestMethod); _state = 42; return true; } state42: - if (((_bits & 4398046511104L) != 0)) + if ((_bits & 4398046511104L) != 0) { - _current = new KeyValuePair("Access-Control-Request-Method", _collection._headers._AccessControlRequestMethod); + _current = new KeyValuePair("Access-Control-Request-Headers", _collection._headers._AccessControlRequestHeaders); _state = 43; return true; } - state43: - if (((_bits & 8796093022208L) != 0)) + state44: + if (_collection._contentLength.HasValue) { - _current = new KeyValuePair("Access-Control-Request-Headers", _collection._headers._AccessControlRequestHeaders); - _state = 44; + _current = new KeyValuePair("Content-Length", HeaderUtilities.FormatInt64(_collection._contentLength.Value)); + _state = 45; return true; } - state_default: if (!_hasUnknown || !_unknownEnumerator.MoveNext()) { @@ -5952,7 +4790,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { private static byte[] _headerBytes = new byte[] { - 13,10,67,97,99,104,101,45,67,111,110,116,114,111,108,58,32,13,10,67,111,110,110,101,99,116,105,111,110,58,32,13,10,68,97,116,101,58,32,13,10,75,101,101,112,45,65,108,105,118,101,58,32,13,10,80,114,97,103,109,97,58,32,13,10,84,114,97,105,108,101,114,58,32,13,10,84,114,97,110,115,102,101,114,45,69,110,99,111,100,105,110,103,58,32,13,10,85,112,103,114,97,100,101,58,32,13,10,86,105,97,58,32,13,10,87,97,114,110,105,110,103,58,32,13,10,65,108,108,111,119,58,32,13,10,67,111,110,116,101,110,116,45,76,101,110,103,116,104,58,32,13,10,67,111,110,116,101,110,116,45,84,121,112,101,58,32,13,10,67,111,110,116,101,110,116,45,69,110,99,111,100,105,110,103,58,32,13,10,67,111,110,116,101,110,116,45,76,97,110,103,117,97,103,101,58,32,13,10,67,111,110,116,101,110,116,45,76,111,99,97,116,105,111,110,58,32,13,10,67,111,110,116,101,110,116,45,77,68,53,58,32,13,10,67,111,110,116,101,110,116,45,82,97,110,103,101,58,32,13,10,69,120,112,105,114,101,115,58,32,13,10,76,97,115,116,45,77,111,100,105,102,105,101,100,58,32,13,10,65,99,99,101,112,116,45,82,97,110,103,101,115,58,32,13,10,65,103,101,58,32,13,10,69,84,97,103,58,32,13,10,76,111,99,97,116,105,111,110,58,32,13,10,80,114,111,120,121,45,65,117,116,104,101,110,116,105,99,97,116,101,58,32,13,10,82,101,116,114,121,45,65,102,116,101,114,58,32,13,10,83,101,114,118,101,114,58,32,13,10,83,101,116,45,67,111,111,107,105,101,58,32,13,10,86,97,114,121,58,32,13,10,87,87,87,45,65,117,116,104,101,110,116,105,99,97,116,101,58,32,13,10,65,99,99,101,115,115,45,67,111,110,116,114,111,108,45,65,108,108,111,119,45,67,114,101,100,101,110,116,105,97,108,115,58,32,13,10,65,99,99,101,115,115,45,67,111,110,116,114,111,108,45,65,108,108,111,119,45,72,101,97,100,101,114,115,58,32,13,10,65,99,99,101,115,115,45,67,111,110,116,114,111,108,45,65,108,108,111,119,45,77,101,116,104,111,100,115,58,32,13,10,65,99,99,101,115,115,45,67,111,110,116,114,111,108,45,65,108,108,111,119,45,79,114,105,103,105,110,58,32,13,10,65,99,99,101,115,115,45,67,111,110,116,114,111,108,45,69,120,112,111,115,101,45,72,101,97,100,101,114,115,58,32,13,10,65,99,99,101,115,115,45,67,111,110,116,114,111,108,45,77,97,120,45,65,103,101,58,32, + 13,10,67,97,99,104,101,45,67,111,110,116,114,111,108,58,32,13,10,67,111,110,110,101,99,116,105,111,110,58,32,13,10,68,97,116,101,58,32,13,10,75,101,101,112,45,65,108,105,118,101,58,32,13,10,80,114,97,103,109,97,58,32,13,10,84,114,97,105,108,101,114,58,32,13,10,84,114,97,110,115,102,101,114,45,69,110,99,111,100,105,110,103,58,32,13,10,85,112,103,114,97,100,101,58,32,13,10,86,105,97,58,32,13,10,87,97,114,110,105,110,103,58,32,13,10,65,108,108,111,119,58,32,13,10,67,111,110,116,101,110,116,45,84,121,112,101,58,32,13,10,67,111,110,116,101,110,116,45,69,110,99,111,100,105,110,103,58,32,13,10,67,111,110,116,101,110,116,45,76,97,110,103,117,97,103,101,58,32,13,10,67,111,110,116,101,110,116,45,76,111,99,97,116,105,111,110,58,32,13,10,67,111,110,116,101,110,116,45,77,68,53,58,32,13,10,67,111,110,116,101,110,116,45,82,97,110,103,101,58,32,13,10,69,120,112,105,114,101,115,58,32,13,10,76,97,115,116,45,77,111,100,105,102,105,101,100,58,32,13,10,65,99,99,101,112,116,45,82,97,110,103,101,115,58,32,13,10,65,103,101,58,32,13,10,69,84,97,103,58,32,13,10,76,111,99,97,116,105,111,110,58,32,13,10,80,114,111,120,121,45,65,117,116,104,101,110,116,105,99,97,116,101,58,32,13,10,82,101,116,114,121,45,65,102,116,101,114,58,32,13,10,83,101,114,118,101,114,58,32,13,10,83,101,116,45,67,111,111,107,105,101,58,32,13,10,86,97,114,121,58,32,13,10,87,87,87,45,65,117,116,104,101,110,116,105,99,97,116,101,58,32,13,10,65,99,99,101,115,115,45,67,111,110,116,114,111,108,45,65,108,108,111,119,45,67,114,101,100,101,110,116,105,97,108,115,58,32,13,10,65,99,99,101,115,115,45,67,111,110,116,114,111,108,45,65,108,108,111,119,45,72,101,97,100,101,114,115,58,32,13,10,65,99,99,101,115,115,45,67,111,110,116,114,111,108,45,65,108,108,111,119,45,77,101,116,104,111,100,115,58,32,13,10,65,99,99,101,115,115,45,67,111,110,116,114,111,108,45,65,108,108,111,119,45,79,114,105,103,105,110,58,32,13,10,65,99,99,101,115,115,45,67,111,110,116,114,111,108,45,69,120,112,111,115,101,45,72,101,97,100,101,114,115,58,32,13,10,65,99,99,101,115,115,45,67,111,110,116,114,111,108,45,77,97,120,45,65,103,101,58,32,13,10,67,111,110,116,101,110,116,45,76,101,110,103,116,104,58,32, }; private long _bits = 0; @@ -5962,11 +4800,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { get { - if (((_bits & 1L) != 0)) + StringValues value; + if ((_bits & 1L) != 0) { - return _headers._CacheControl; + value = _headers._CacheControl; } - return StringValues.Empty; + return value; } set { @@ -5978,11 +4817,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { get { - if (((_bits & 2L) != 0)) + StringValues value; + if ((_bits & 2L) != 0) { - return _headers._Connection; + value = _headers._Connection; } - return StringValues.Empty; + return value; } set { @@ -5995,11 +4835,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { get { - if (((_bits & 4L) != 0)) + StringValues value; + if ((_bits & 4L) != 0) { - return _headers._Date; + value = _headers._Date; } - return StringValues.Empty; + return value; } set { @@ -6012,11 +4853,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { get { - if (((_bits & 8L) != 0)) + StringValues value; + if ((_bits & 8L) != 0) { - return _headers._KeepAlive; + value = _headers._KeepAlive; } - return StringValues.Empty; + return value; } set { @@ -6028,11 +4870,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { get { - if (((_bits & 16L) != 0)) + StringValues value; + if ((_bits & 16L) != 0) { - return _headers._Pragma; + value = _headers._Pragma; } - return StringValues.Empty; + return value; } set { @@ -6044,11 +4887,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { get { - if (((_bits & 32L) != 0)) + StringValues value; + if ((_bits & 32L) != 0) { - return _headers._Trailer; + value = _headers._Trailer; } - return StringValues.Empty; + return value; } set { @@ -6060,11 +4904,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { get { - if (((_bits & 64L) != 0)) + StringValues value; + if ((_bits & 64L) != 0) { - return _headers._TransferEncoding; + value = _headers._TransferEncoding; } - return StringValues.Empty; + return value; } set { @@ -6077,11 +4922,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { get { - if (((_bits & 128L) != 0)) + StringValues value; + if ((_bits & 128L) != 0) { - return _headers._Upgrade; + value = _headers._Upgrade; } - return StringValues.Empty; + return value; } set { @@ -6093,11 +4939,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { get { - if (((_bits & 256L) != 0)) + StringValues value; + if ((_bits & 256L) != 0) { - return _headers._Via; + value = _headers._Via; } - return StringValues.Empty; + return value; } set { @@ -6109,11 +4956,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { get { - if (((_bits & 512L) != 0)) + StringValues value; + if ((_bits & 512L) != 0) { - return _headers._Warning; + value = _headers._Warning; } - return StringValues.Empty; + return value; } set { @@ -6125,11 +4973,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { get { - if (((_bits & 1024L) != 0)) + StringValues value; + if ((_bits & 1024L) != 0) { - return _headers._Allow; + value = _headers._Allow; } - return StringValues.Empty; + return value; } set { @@ -6137,37 +4986,20 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _headers._Allow = value; } } - public StringValues HeaderContentLength - { - get - { - if (((_bits & 2048L) != 0)) - { - return _headers._ContentLength; - } - return StringValues.Empty; - } - set - { - _contentLength = ParseContentLength(value); - _bits |= 2048L; - _headers._ContentLength = value; - _headers._rawContentLength = null; - } - } public StringValues HeaderContentType { get { - if (((_bits & 4096L) != 0)) + StringValues value; + if ((_bits & 2048L) != 0) { - return _headers._ContentType; + value = _headers._ContentType; } - return StringValues.Empty; + return value; } set { - _bits |= 4096L; + _bits |= 2048L; _headers._ContentType = value; } } @@ -6175,15 +5007,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { get { - if (((_bits & 8192L) != 0)) + StringValues value; + if ((_bits & 4096L) != 0) { - return _headers._ContentEncoding; + value = _headers._ContentEncoding; } - return StringValues.Empty; + return value; } set { - _bits |= 8192L; + _bits |= 4096L; _headers._ContentEncoding = value; } } @@ -6191,15 +5024,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { get { - if (((_bits & 16384L) != 0)) + StringValues value; + if ((_bits & 8192L) != 0) { - return _headers._ContentLanguage; + value = _headers._ContentLanguage; } - return StringValues.Empty; + return value; } set { - _bits |= 16384L; + _bits |= 8192L; _headers._ContentLanguage = value; } } @@ -6207,15 +5041,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { get { - if (((_bits & 32768L) != 0)) + StringValues value; + if ((_bits & 16384L) != 0) { - return _headers._ContentLocation; + value = _headers._ContentLocation; } - return StringValues.Empty; + return value; } set { - _bits |= 32768L; + _bits |= 16384L; _headers._ContentLocation = value; } } @@ -6223,15 +5058,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { get { - if (((_bits & 65536L) != 0)) + StringValues value; + if ((_bits & 32768L) != 0) { - return _headers._ContentMD5; + value = _headers._ContentMD5; } - return StringValues.Empty; + return value; } set { - _bits |= 65536L; + _bits |= 32768L; _headers._ContentMD5 = value; } } @@ -6239,15 +5075,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { get { - if (((_bits & 131072L) != 0)) + StringValues value; + if ((_bits & 65536L) != 0) { - return _headers._ContentRange; + value = _headers._ContentRange; } - return StringValues.Empty; + return value; } set { - _bits |= 131072L; + _bits |= 65536L; _headers._ContentRange = value; } } @@ -6255,15 +5092,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { get { - if (((_bits & 262144L) != 0)) + StringValues value; + if ((_bits & 131072L) != 0) { - return _headers._Expires; + value = _headers._Expires; } - return StringValues.Empty; + return value; } set { - _bits |= 262144L; + _bits |= 131072L; _headers._Expires = value; } } @@ -6271,15 +5109,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { get { - if (((_bits & 524288L) != 0)) + StringValues value; + if ((_bits & 262144L) != 0) { - return _headers._LastModified; + value = _headers._LastModified; } - return StringValues.Empty; + return value; } set { - _bits |= 524288L; + _bits |= 262144L; _headers._LastModified = value; } } @@ -6287,15 +5126,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { get { - if (((_bits & 1048576L) != 0)) + StringValues value; + if ((_bits & 524288L) != 0) { - return _headers._AcceptRanges; + value = _headers._AcceptRanges; } - return StringValues.Empty; + return value; } set { - _bits |= 1048576L; + _bits |= 524288L; _headers._AcceptRanges = value; } } @@ -6303,15 +5143,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { get { - if (((_bits & 2097152L) != 0)) + StringValues value; + if ((_bits & 1048576L) != 0) { - return _headers._Age; + value = _headers._Age; } - return StringValues.Empty; + return value; } set { - _bits |= 2097152L; + _bits |= 1048576L; _headers._Age = value; } } @@ -6319,15 +5160,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { get { - if (((_bits & 4194304L) != 0)) + StringValues value; + if ((_bits & 2097152L) != 0) { - return _headers._ETag; + value = _headers._ETag; } - return StringValues.Empty; + return value; } set { - _bits |= 4194304L; + _bits |= 2097152L; _headers._ETag = value; } } @@ -6335,15 +5177,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { get { - if (((_bits & 8388608L) != 0)) + StringValues value; + if ((_bits & 4194304L) != 0) { - return _headers._Location; + value = _headers._Location; } - return StringValues.Empty; + return value; } set { - _bits |= 8388608L; + _bits |= 4194304L; _headers._Location = value; } } @@ -6351,15 +5194,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { get { - if (((_bits & 16777216L) != 0)) + StringValues value; + if ((_bits & 8388608L) != 0) { - return _headers._ProxyAuthenticate; + value = _headers._ProxyAuthenticate; } - return StringValues.Empty; + return value; } set { - _bits |= 16777216L; + _bits |= 8388608L; _headers._ProxyAuthenticate = value; } } @@ -6367,15 +5211,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { get { - if (((_bits & 33554432L) != 0)) + StringValues value; + if ((_bits & 16777216L) != 0) { - return _headers._RetryAfter; + value = _headers._RetryAfter; } - return StringValues.Empty; + return value; } set { - _bits |= 33554432L; + _bits |= 16777216L; _headers._RetryAfter = value; } } @@ -6383,15 +5228,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { get { - if (((_bits & 67108864L) != 0)) + StringValues value; + if ((_bits & 33554432L) != 0) { - return _headers._Server; + value = _headers._Server; } - return StringValues.Empty; + return value; } set { - _bits |= 67108864L; + _bits |= 33554432L; _headers._Server = value; _headers._rawServer = null; } @@ -6400,15 +5246,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { get { - if (((_bits & 134217728L) != 0)) + StringValues value; + if ((_bits & 67108864L) != 0) { - return _headers._SetCookie; + value = _headers._SetCookie; } - return StringValues.Empty; + return value; } set { - _bits |= 134217728L; + _bits |= 67108864L; _headers._SetCookie = value; } } @@ -6416,15 +5263,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { get { - if (((_bits & 268435456L) != 0)) + StringValues value; + if ((_bits & 134217728L) != 0) { - return _headers._Vary; + value = _headers._Vary; } - return StringValues.Empty; + return value; } set { - _bits |= 268435456L; + _bits |= 134217728L; _headers._Vary = value; } } @@ -6432,15 +5280,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { get { - if (((_bits & 536870912L) != 0)) + StringValues value; + if ((_bits & 268435456L) != 0) { - return _headers._WWWAuthenticate; + value = _headers._WWWAuthenticate; } - return StringValues.Empty; + return value; } set { - _bits |= 536870912L; + _bits |= 268435456L; _headers._WWWAuthenticate = value; } } @@ -6448,15 +5297,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { get { - if (((_bits & 1073741824L) != 0)) + StringValues value; + if ((_bits & 536870912L) != 0) { - return _headers._AccessControlAllowCredentials; + value = _headers._AccessControlAllowCredentials; } - return StringValues.Empty; + return value; } set { - _bits |= 1073741824L; + _bits |= 536870912L; _headers._AccessControlAllowCredentials = value; } } @@ -6464,15 +5314,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { get { - if (((_bits & 2147483648L) != 0)) + StringValues value; + if ((_bits & 1073741824L) != 0) { - return _headers._AccessControlAllowHeaders; + value = _headers._AccessControlAllowHeaders; } - return StringValues.Empty; + return value; } set { - _bits |= 2147483648L; + _bits |= 1073741824L; _headers._AccessControlAllowHeaders = value; } } @@ -6480,15 +5331,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { get { - if (((_bits & 4294967296L) != 0)) + StringValues value; + if ((_bits & 2147483648L) != 0) { - return _headers._AccessControlAllowMethods; + value = _headers._AccessControlAllowMethods; } - return StringValues.Empty; + return value; } set { - _bits |= 4294967296L; + _bits |= 2147483648L; _headers._AccessControlAllowMethods = value; } } @@ -6496,15 +5348,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { get { - if (((_bits & 8589934592L) != 0)) + StringValues value; + if ((_bits & 4294967296L) != 0) { - return _headers._AccessControlAllowOrigin; + value = _headers._AccessControlAllowOrigin; } - return StringValues.Empty; + return value; } set { - _bits |= 8589934592L; + _bits |= 4294967296L; _headers._AccessControlAllowOrigin = value; } } @@ -6512,15 +5365,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { get { - if (((_bits & 17179869184L) != 0)) + StringValues value; + if ((_bits & 8589934592L) != 0) { - return _headers._AccessControlExposeHeaders; + value = _headers._AccessControlExposeHeaders; } - return StringValues.Empty; + return value; } set { - _bits |= 17179869184L; + _bits |= 8589934592L; _headers._AccessControlExposeHeaders = value; } } @@ -6528,19 +5382,36 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { get { - if (((_bits & 34359738368L) != 0)) + StringValues value; + if ((_bits & 17179869184L) != 0) { - return _headers._AccessControlMaxAge; + value = _headers._AccessControlMaxAge; } - return StringValues.Empty; + return value; } set { - _bits |= 34359738368L; + _bits |= 17179869184L; _headers._AccessControlMaxAge = value; } } - + public StringValues HeaderContentLength + { + get + { + StringValues value; + if (_contentLength.HasValue) + { + value = new StringValues(HeaderUtilities.FormatInt64(_contentLength.Value)); + } + return value; + } + set + { + _contentLength = ParseContentLength(value); + } + } + public void SetRawConnection(StringValues value, byte[] raw) { _bits |= 2L; @@ -6559,541 +5430,17 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _headers._TransferEncoding = value; _headers._rawTransferEncoding = raw; } - public void SetRawContentLength(StringValues value, byte[] raw) - { - _contentLength = ParseContentLength(value); - _bits |= 2048L; - _headers._ContentLength = value; - _headers._rawContentLength = raw; - } public void SetRawServer(StringValues value, byte[] raw) { - _bits |= 67108864L; + _bits |= 33554432L; _headers._Server = value; _headers._rawServer = raw; } protected override int GetCountFast() { - return BitCount(_bits) + (MaybeUnknown?.Count ?? 0); + return (_contentLength.HasValue ? 1 : 0 ) + BitCount(_bits) + (MaybeUnknown?.Count ?? 0); } - protected override StringValues GetValueFast(string key) - { - switch (key.Length) - { - case 13: - { - if ("Cache-Control".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 1L) != 0)) - { - return _headers._CacheControl; - } - else - { - ThrowKeyNotFoundException(); - } - } - - if ("Content-Range".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 131072L) != 0)) - { - return _headers._ContentRange; - } - else - { - ThrowKeyNotFoundException(); - } - } - - if ("Last-Modified".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 524288L) != 0)) - { - return _headers._LastModified; - } - else - { - ThrowKeyNotFoundException(); - } - } - - if ("Accept-Ranges".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 1048576L) != 0)) - { - return _headers._AcceptRanges; - } - else - { - ThrowKeyNotFoundException(); - } - } - } - break; - case 10: - { - if ("Connection".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 2L) != 0)) - { - return _headers._Connection; - } - else - { - ThrowKeyNotFoundException(); - } - } - - if ("Keep-Alive".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 8L) != 0)) - { - return _headers._KeepAlive; - } - else - { - ThrowKeyNotFoundException(); - } - } - - if ("Set-Cookie".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 134217728L) != 0)) - { - return _headers._SetCookie; - } - else - { - ThrowKeyNotFoundException(); - } - } - } - break; - - case 4: - { - if ("Date".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 4L) != 0)) - { - return _headers._Date; - } - else - { - ThrowKeyNotFoundException(); - } - } - - if ("ETag".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 4194304L) != 0)) - { - return _headers._ETag; - } - else - { - ThrowKeyNotFoundException(); - } - } - - if ("Vary".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 268435456L) != 0)) - { - return _headers._Vary; - } - else - { - ThrowKeyNotFoundException(); - } - } - } - break; - - case 6: - { - if ("Pragma".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 16L) != 0)) - { - return _headers._Pragma; - } - else - { - ThrowKeyNotFoundException(); - } - } - - if ("Server".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 67108864L) != 0)) - { - return _headers._Server; - } - else - { - ThrowKeyNotFoundException(); - } - } - } - break; - - case 7: - { - if ("Trailer".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 32L) != 0)) - { - return _headers._Trailer; - } - else - { - ThrowKeyNotFoundException(); - } - } - - if ("Upgrade".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 128L) != 0)) - { - return _headers._Upgrade; - } - else - { - ThrowKeyNotFoundException(); - } - } - - if ("Warning".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 512L) != 0)) - { - return _headers._Warning; - } - else - { - ThrowKeyNotFoundException(); - } - } - - if ("Expires".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 262144L) != 0)) - { - return _headers._Expires; - } - else - { - ThrowKeyNotFoundException(); - } - } - } - break; - - case 17: - { - if ("Transfer-Encoding".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 64L) != 0)) - { - return _headers._TransferEncoding; - } - else - { - ThrowKeyNotFoundException(); - } - } - } - break; - - case 3: - { - if ("Via".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 256L) != 0)) - { - return _headers._Via; - } - else - { - ThrowKeyNotFoundException(); - } - } - - if ("Age".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 2097152L) != 0)) - { - return _headers._Age; - } - else - { - ThrowKeyNotFoundException(); - } - } - } - break; - - case 5: - { - if ("Allow".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 1024L) != 0)) - { - return _headers._Allow; - } - else - { - ThrowKeyNotFoundException(); - } - } - } - break; - - case 14: - { - if ("Content-Length".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 2048L) != 0)) - { - return _headers._ContentLength; - } - else - { - ThrowKeyNotFoundException(); - } - } - } - break; - - case 12: - { - if ("Content-Type".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 4096L) != 0)) - { - return _headers._ContentType; - } - else - { - ThrowKeyNotFoundException(); - } - } - } - break; - - case 16: - { - if ("Content-Encoding".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 8192L) != 0)) - { - return _headers._ContentEncoding; - } - else - { - ThrowKeyNotFoundException(); - } - } - - if ("Content-Language".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 16384L) != 0)) - { - return _headers._ContentLanguage; - } - else - { - ThrowKeyNotFoundException(); - } - } - - if ("Content-Location".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 32768L) != 0)) - { - return _headers._ContentLocation; - } - else - { - ThrowKeyNotFoundException(); - } - } - - if ("WWW-Authenticate".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 536870912L) != 0)) - { - return _headers._WWWAuthenticate; - } - else - { - ThrowKeyNotFoundException(); - } - } - } - break; - - case 11: - { - if ("Content-MD5".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 65536L) != 0)) - { - return _headers._ContentMD5; - } - else - { - ThrowKeyNotFoundException(); - } - } - - if ("Retry-After".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 33554432L) != 0)) - { - return _headers._RetryAfter; - } - else - { - ThrowKeyNotFoundException(); - } - } - } - break; - - case 8: - { - if ("Location".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 8388608L) != 0)) - { - return _headers._Location; - } - else - { - ThrowKeyNotFoundException(); - } - } - } - break; - - case 18: - { - if ("Proxy-Authenticate".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 16777216L) != 0)) - { - return _headers._ProxyAuthenticate; - } - else - { - ThrowKeyNotFoundException(); - } - } - } - break; - - case 32: - { - if ("Access-Control-Allow-Credentials".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 1073741824L) != 0)) - { - return _headers._AccessControlAllowCredentials; - } - else - { - ThrowKeyNotFoundException(); - } - } - } - break; - - case 28: - { - if ("Access-Control-Allow-Headers".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 2147483648L) != 0)) - { - return _headers._AccessControlAllowHeaders; - } - else - { - ThrowKeyNotFoundException(); - } - } - - if ("Access-Control-Allow-Methods".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 4294967296L) != 0)) - { - return _headers._AccessControlAllowMethods; - } - else - { - ThrowKeyNotFoundException(); - } - } - } - break; - - case 27: - { - if ("Access-Control-Allow-Origin".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 8589934592L) != 0)) - { - return _headers._AccessControlAllowOrigin; - } - else - { - ThrowKeyNotFoundException(); - } - } - } - break; - - case 29: - { - if ("Access-Control-Expose-Headers".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 17179869184L) != 0)) - { - return _headers._AccessControlExposeHeaders; - } - else - { - ThrowKeyNotFoundException(); - } - } - } - break; - - case 22: - { - if ("Access-Control-Max-Age".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 34359738368L) != 0)) - { - return _headers._AccessControlMaxAge; - } - else - { - ThrowKeyNotFoundException(); - } - } - } - break; -} - if (MaybeUnknown == null) - { - ThrowKeyNotFoundException(); - } - return MaybeUnknown[key]; - } protected override bool TryGetValueFast(string key, out StringValues value) { switch (key.Length) @@ -7102,585 +5449,407 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { if ("Cache-Control".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 1L) != 0)) + if ((_bits & 1L) != 0) { value = _headers._CacheControl; return true; } - else - { - value = StringValues.Empty; - return false; - } + return false; } - if ("Content-Range".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 131072L) != 0)) + if ((_bits & 65536L) != 0) { value = _headers._ContentRange; return true; } - else - { - value = StringValues.Empty; - return false; - } + return false; } - if ("Last-Modified".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 524288L) != 0)) + if ((_bits & 262144L) != 0) { value = _headers._LastModified; return true; } - else - { - value = StringValues.Empty; - return false; - } + return false; } - if ("Accept-Ranges".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 1048576L) != 0)) + if ((_bits & 524288L) != 0) { value = _headers._AcceptRanges; return true; } - else - { - value = StringValues.Empty; - return false; - } + return false; } } break; - case 10: { if ("Connection".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 2L) != 0)) + if ((_bits & 2L) != 0) { value = _headers._Connection; return true; } - else - { - value = StringValues.Empty; - return false; - } + return false; } - if ("Keep-Alive".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 8L) != 0)) + if ((_bits & 8L) != 0) { value = _headers._KeepAlive; return true; } - else - { - value = StringValues.Empty; - return false; - } + return false; } - if ("Set-Cookie".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 134217728L) != 0)) + if ((_bits & 67108864L) != 0) { value = _headers._SetCookie; return true; } - else - { - value = StringValues.Empty; - return false; - } + return false; } } break; - case 4: { if ("Date".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 4L) != 0)) + if ((_bits & 4L) != 0) { value = _headers._Date; return true; } - else - { - value = StringValues.Empty; - return false; - } + return false; } - if ("ETag".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 4194304L) != 0)) + if ((_bits & 2097152L) != 0) { value = _headers._ETag; return true; } - else - { - value = StringValues.Empty; - return false; - } + return false; } - if ("Vary".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 268435456L) != 0)) + if ((_bits & 134217728L) != 0) { value = _headers._Vary; return true; } - else - { - value = StringValues.Empty; - return false; - } + return false; } } break; - case 6: { if ("Pragma".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 16L) != 0)) + if ((_bits & 16L) != 0) { value = _headers._Pragma; return true; } - else - { - value = StringValues.Empty; - return false; - } + return false; } - if ("Server".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 67108864L) != 0)) + if ((_bits & 33554432L) != 0) { value = _headers._Server; return true; } - else - { - value = StringValues.Empty; - return false; - } + return false; } } break; - case 7: { if ("Trailer".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 32L) != 0)) + if ((_bits & 32L) != 0) { value = _headers._Trailer; return true; } - else - { - value = StringValues.Empty; - return false; - } + return false; } - if ("Upgrade".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 128L) != 0)) + if ((_bits & 128L) != 0) { value = _headers._Upgrade; return true; } - else - { - value = StringValues.Empty; - return false; - } + return false; } - if ("Warning".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 512L) != 0)) + if ((_bits & 512L) != 0) { value = _headers._Warning; return true; } - else - { - value = StringValues.Empty; - return false; - } + return false; } - if ("Expires".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 262144L) != 0)) + if ((_bits & 131072L) != 0) { value = _headers._Expires; return true; } - else - { - value = StringValues.Empty; - return false; - } + return false; } } break; - case 17: { if ("Transfer-Encoding".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 64L) != 0)) + if ((_bits & 64L) != 0) { value = _headers._TransferEncoding; return true; } - else - { - value = StringValues.Empty; - return false; - } + return false; } } break; - case 3: { if ("Via".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 256L) != 0)) + if ((_bits & 256L) != 0) { value = _headers._Via; return true; } - else - { - value = StringValues.Empty; - return false; - } + return false; } - if ("Age".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 2097152L) != 0)) + if ((_bits & 1048576L) != 0) { value = _headers._Age; return true; } - else - { - value = StringValues.Empty; - return false; - } + return false; } } break; - case 5: { if ("Allow".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 1024L) != 0)) + if ((_bits & 1024L) != 0) { value = _headers._Allow; return true; } - else - { - value = StringValues.Empty; - return false; - } + return false; } } break; - - case 14: - { - if ("Content-Length".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 2048L) != 0)) - { - value = _headers._ContentLength; - return true; - } - else - { - value = StringValues.Empty; - return false; - } - } - } - break; - case 12: { if ("Content-Type".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 4096L) != 0)) + if ((_bits & 2048L) != 0) { value = _headers._ContentType; return true; } - else - { - value = StringValues.Empty; - return false; - } + return false; } } break; - case 16: { if ("Content-Encoding".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 8192L) != 0)) + if ((_bits & 4096L) != 0) { value = _headers._ContentEncoding; return true; } - else - { - value = StringValues.Empty; - return false; - } + return false; } - if ("Content-Language".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 16384L) != 0)) + if ((_bits & 8192L) != 0) { value = _headers._ContentLanguage; return true; } - else - { - value = StringValues.Empty; - return false; - } + return false; } - if ("Content-Location".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 32768L) != 0)) + if ((_bits & 16384L) != 0) { value = _headers._ContentLocation; return true; } - else - { - value = StringValues.Empty; - return false; - } + return false; } - if ("WWW-Authenticate".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 536870912L) != 0)) + if ((_bits & 268435456L) != 0) { value = _headers._WWWAuthenticate; return true; } - else - { - value = StringValues.Empty; - return false; - } + return false; } } break; - case 11: { if ("Content-MD5".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 65536L) != 0)) + if ((_bits & 32768L) != 0) { value = _headers._ContentMD5; return true; } - else - { - value = StringValues.Empty; - return false; - } + return false; } - if ("Retry-After".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 33554432L) != 0)) + if ((_bits & 16777216L) != 0) { value = _headers._RetryAfter; return true; } - else - { - value = StringValues.Empty; - return false; - } + return false; } } break; - case 8: { if ("Location".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 8388608L) != 0)) + if ((_bits & 4194304L) != 0) { value = _headers._Location; return true; } - else - { - value = StringValues.Empty; - return false; - } + return false; } } break; - case 18: { if ("Proxy-Authenticate".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 16777216L) != 0)) + if ((_bits & 8388608L) != 0) { value = _headers._ProxyAuthenticate; return true; } - else - { - value = StringValues.Empty; - return false; - } + return false; } } break; - case 32: { if ("Access-Control-Allow-Credentials".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 1073741824L) != 0)) + if ((_bits & 536870912L) != 0) { value = _headers._AccessControlAllowCredentials; return true; } - else - { - value = StringValues.Empty; - return false; - } + return false; } } break; - case 28: { if ("Access-Control-Allow-Headers".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 2147483648L) != 0)) + if ((_bits & 1073741824L) != 0) { value = _headers._AccessControlAllowHeaders; return true; } - else - { - value = StringValues.Empty; - return false; - } + return false; } - if ("Access-Control-Allow-Methods".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 4294967296L) != 0)) + if ((_bits & 2147483648L) != 0) { value = _headers._AccessControlAllowMethods; return true; } - else - { - value = StringValues.Empty; - return false; - } + return false; } } break; - case 27: { if ("Access-Control-Allow-Origin".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 8589934592L) != 0)) + if ((_bits & 4294967296L) != 0) { value = _headers._AccessControlAllowOrigin; return true; } - else - { - value = StringValues.Empty; - return false; - } + return false; } } break; - case 29: { if ("Access-Control-Expose-Headers".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 17179869184L) != 0)) + if ((_bits & 8589934592L) != 0) { value = _headers._AccessControlExposeHeaders; return true; } - else - { - value = StringValues.Empty; - return false; - } + return false; } } break; - case 22: { if ("Access-Control-Max-Age".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 34359738368L) != 0)) + if ((_bits & 17179869184L) != 0) { value = _headers._AccessControlMaxAge; return true; } - else - { - value = StringValues.Empty; - return false; - } + return false; } } break; -} - value = StringValues.Empty; + case 14: + { + if ("Content-Length".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (_contentLength.HasValue) + { + value = HeaderUtilities.FormatInt64(_contentLength.Value); + return true; + } + return false; + } + } + break; + } + return MaybeUnknown?.TryGetValue(key, out value) ?? false; } + protected override void SetValueFast(string key, StringValues value) { ValidateHeaderCharacters(value); @@ -7694,30 +5863,26 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _headers._CacheControl = value; return; } - if ("Content-Range".Equals(key, StringComparison.OrdinalIgnoreCase)) { - _bits |= 131072L; + _bits |= 65536L; _headers._ContentRange = value; return; } - if ("Last-Modified".Equals(key, StringComparison.OrdinalIgnoreCase)) { - _bits |= 524288L; + _bits |= 262144L; _headers._LastModified = value; return; } - if ("Accept-Ranges".Equals(key, StringComparison.OrdinalIgnoreCase)) { - _bits |= 1048576L; + _bits |= 524288L; _headers._AcceptRanges = value; return; } } break; - case 10: { if ("Connection".Equals(key, StringComparison.OrdinalIgnoreCase)) @@ -7727,23 +5892,20 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _headers._rawConnection = null; return; } - if ("Keep-Alive".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 8L; _headers._KeepAlive = value; return; } - if ("Set-Cookie".Equals(key, StringComparison.OrdinalIgnoreCase)) { - _bits |= 134217728L; + _bits |= 67108864L; _headers._SetCookie = value; return; } } break; - case 4: { if ("Date".Equals(key, StringComparison.OrdinalIgnoreCase)) @@ -7753,23 +5915,20 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _headers._rawDate = null; return; } - if ("ETag".Equals(key, StringComparison.OrdinalIgnoreCase)) { - _bits |= 4194304L; + _bits |= 2097152L; _headers._ETag = value; return; } - if ("Vary".Equals(key, StringComparison.OrdinalIgnoreCase)) { - _bits |= 268435456L; + _bits |= 134217728L; _headers._Vary = value; return; } } break; - case 6: { if ("Pragma".Equals(key, StringComparison.OrdinalIgnoreCase)) @@ -7778,17 +5937,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _headers._Pragma = value; return; } - if ("Server".Equals(key, StringComparison.OrdinalIgnoreCase)) { - _bits |= 67108864L; + _bits |= 33554432L; _headers._Server = value; _headers._rawServer = null; return; } } break; - case 7: { if ("Trailer".Equals(key, StringComparison.OrdinalIgnoreCase)) @@ -7797,30 +5954,26 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _headers._Trailer = value; return; } - if ("Upgrade".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 128L; _headers._Upgrade = value; return; } - if ("Warning".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 512L; _headers._Warning = value; return; } - if ("Expires".Equals(key, StringComparison.OrdinalIgnoreCase)) { - _bits |= 262144L; + _bits |= 131072L; _headers._Expires = value; return; } } break; - case 17: { if ("Transfer-Encoding".Equals(key, StringComparison.OrdinalIgnoreCase)) @@ -7832,7 +5985,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } } break; - case 3: { if ("Via".Equals(key, StringComparison.OrdinalIgnoreCase)) @@ -7841,16 +5993,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _headers._Via = value; return; } - if ("Age".Equals(key, StringComparison.OrdinalIgnoreCase)) { - _bits |= 2097152L; + _bits |= 1048576L; _headers._Age = value; return; } } break; - case 5: { if ("Allow".Equals(key, StringComparison.OrdinalIgnoreCase)) @@ -7861,169 +6011,151 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } } break; - - case 14: - { - if ("Content-Length".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - _contentLength = ParseContentLength(value); - _bits |= 2048L; - _headers._ContentLength = value; - _headers._rawContentLength = null; - return; - } - } - break; - case 12: { if ("Content-Type".Equals(key, StringComparison.OrdinalIgnoreCase)) { - _bits |= 4096L; + _bits |= 2048L; _headers._ContentType = value; return; } } break; - case 16: { if ("Content-Encoding".Equals(key, StringComparison.OrdinalIgnoreCase)) { - _bits |= 8192L; + _bits |= 4096L; _headers._ContentEncoding = value; return; } - if ("Content-Language".Equals(key, StringComparison.OrdinalIgnoreCase)) { - _bits |= 16384L; + _bits |= 8192L; _headers._ContentLanguage = value; return; } - if ("Content-Location".Equals(key, StringComparison.OrdinalIgnoreCase)) { - _bits |= 32768L; + _bits |= 16384L; _headers._ContentLocation = value; return; } - if ("WWW-Authenticate".Equals(key, StringComparison.OrdinalIgnoreCase)) { - _bits |= 536870912L; + _bits |= 268435456L; _headers._WWWAuthenticate = value; return; } } break; - case 11: { if ("Content-MD5".Equals(key, StringComparison.OrdinalIgnoreCase)) { - _bits |= 65536L; + _bits |= 32768L; _headers._ContentMD5 = value; return; } - if ("Retry-After".Equals(key, StringComparison.OrdinalIgnoreCase)) { - _bits |= 33554432L; + _bits |= 16777216L; _headers._RetryAfter = value; return; } } break; - case 8: { if ("Location".Equals(key, StringComparison.OrdinalIgnoreCase)) { - _bits |= 8388608L; + _bits |= 4194304L; _headers._Location = value; return; } } break; - case 18: { if ("Proxy-Authenticate".Equals(key, StringComparison.OrdinalIgnoreCase)) { - _bits |= 16777216L; + _bits |= 8388608L; _headers._ProxyAuthenticate = value; return; } } break; - case 32: { if ("Access-Control-Allow-Credentials".Equals(key, StringComparison.OrdinalIgnoreCase)) { - _bits |= 1073741824L; + _bits |= 536870912L; _headers._AccessControlAllowCredentials = value; return; } } break; - case 28: { if ("Access-Control-Allow-Headers".Equals(key, StringComparison.OrdinalIgnoreCase)) { - _bits |= 2147483648L; + _bits |= 1073741824L; _headers._AccessControlAllowHeaders = value; return; } - if ("Access-Control-Allow-Methods".Equals(key, StringComparison.OrdinalIgnoreCase)) { - _bits |= 4294967296L; + _bits |= 2147483648L; _headers._AccessControlAllowMethods = value; return; } } break; - case 27: { if ("Access-Control-Allow-Origin".Equals(key, StringComparison.OrdinalIgnoreCase)) { - _bits |= 8589934592L; + _bits |= 4294967296L; _headers._AccessControlAllowOrigin = value; return; } } break; - case 29: { if ("Access-Control-Expose-Headers".Equals(key, StringComparison.OrdinalIgnoreCase)) { - _bits |= 17179869184L; + _bits |= 8589934592L; _headers._AccessControlExposeHeaders = value; return; } } break; - case 22: { if ("Access-Control-Max-Age".Equals(key, StringComparison.OrdinalIgnoreCase)) { - _bits |= 34359738368L; + _bits |= 17179869184L; _headers._AccessControlMaxAge = value; return; } } break; -} - ValidateHeaderCharacters(key); - Unknown[key] = value; + case 14: + { + if ("Content-Length".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + _contentLength = ParseContentLength(value.ToString()); + return; + } + } + break; + } + + SetValueUnknown(key, value); } - protected override void AddValueFast(string key, StringValues value) + + protected override bool AddValueFast(string key, StringValues value) { ValidateHeaderCharacters(value); switch (key.Length) @@ -8032,483 +6164,449 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { if ("Cache-Control".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 1L) != 0)) + if ((_bits & 1L) == 0) { - ThrowDuplicateKeyException(); + _bits |= 1L; + _headers._CacheControl = value; + return true; } - _bits |= 1L; - _headers._CacheControl = value; - return; + return false; } - if ("Content-Range".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 131072L) != 0)) + if ((_bits & 65536L) == 0) { - ThrowDuplicateKeyException(); + _bits |= 65536L; + _headers._ContentRange = value; + return true; } - _bits |= 131072L; - _headers._ContentRange = value; - return; + return false; } - if ("Last-Modified".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 524288L) != 0)) + if ((_bits & 262144L) == 0) { - ThrowDuplicateKeyException(); + _bits |= 262144L; + _headers._LastModified = value; + return true; } - _bits |= 524288L; - _headers._LastModified = value; - return; + return false; } - if ("Accept-Ranges".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 1048576L) != 0)) + if ((_bits & 524288L) == 0) { - ThrowDuplicateKeyException(); + _bits |= 524288L; + _headers._AcceptRanges = value; + return true; } - _bits |= 1048576L; - _headers._AcceptRanges = value; - return; + return false; } } break; - case 10: { if ("Connection".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 2L) != 0)) + if ((_bits & 2L) == 0) { - ThrowDuplicateKeyException(); + _bits |= 2L; + _headers._Connection = value; + _headers._rawConnection = null; + return true; } - _bits |= 2L; - _headers._Connection = value; - _headers._rawConnection = null; - return; + return false; } - if ("Keep-Alive".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 8L) != 0)) + if ((_bits & 8L) == 0) { - ThrowDuplicateKeyException(); + _bits |= 8L; + _headers._KeepAlive = value; + return true; } - _bits |= 8L; - _headers._KeepAlive = value; - return; + return false; } - if ("Set-Cookie".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 134217728L) != 0)) + if ((_bits & 67108864L) == 0) { - ThrowDuplicateKeyException(); + _bits |= 67108864L; + _headers._SetCookie = value; + return true; } - _bits |= 134217728L; - _headers._SetCookie = value; - return; + return false; } } break; - case 4: { if ("Date".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 4L) != 0)) + if ((_bits & 4L) == 0) { - ThrowDuplicateKeyException(); + _bits |= 4L; + _headers._Date = value; + _headers._rawDate = null; + return true; } - _bits |= 4L; - _headers._Date = value; - _headers._rawDate = null; - return; + return false; } - if ("ETag".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 4194304L) != 0)) + if ((_bits & 2097152L) == 0) { - ThrowDuplicateKeyException(); + _bits |= 2097152L; + _headers._ETag = value; + return true; } - _bits |= 4194304L; - _headers._ETag = value; - return; + return false; } - if ("Vary".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 268435456L) != 0)) + if ((_bits & 134217728L) == 0) { - ThrowDuplicateKeyException(); + _bits |= 134217728L; + _headers._Vary = value; + return true; } - _bits |= 268435456L; - _headers._Vary = value; - return; + return false; } } break; - case 6: { if ("Pragma".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 16L) != 0)) + if ((_bits & 16L) == 0) { - ThrowDuplicateKeyException(); + _bits |= 16L; + _headers._Pragma = value; + return true; } - _bits |= 16L; - _headers._Pragma = value; - return; + return false; } - if ("Server".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 67108864L) != 0)) + if ((_bits & 33554432L) == 0) { - ThrowDuplicateKeyException(); + _bits |= 33554432L; + _headers._Server = value; + _headers._rawServer = null; + return true; } - _bits |= 67108864L; - _headers._Server = value; - _headers._rawServer = null; - return; + return false; } } break; - case 7: { if ("Trailer".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 32L) != 0)) + if ((_bits & 32L) == 0) { - ThrowDuplicateKeyException(); + _bits |= 32L; + _headers._Trailer = value; + return true; } - _bits |= 32L; - _headers._Trailer = value; - return; + return false; } - if ("Upgrade".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 128L) != 0)) + if ((_bits & 128L) == 0) { - ThrowDuplicateKeyException(); + _bits |= 128L; + _headers._Upgrade = value; + return true; } - _bits |= 128L; - _headers._Upgrade = value; - return; + return false; } - if ("Warning".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 512L) != 0)) + if ((_bits & 512L) == 0) { - ThrowDuplicateKeyException(); + _bits |= 512L; + _headers._Warning = value; + return true; } - _bits |= 512L; - _headers._Warning = value; - return; + return false; } - if ("Expires".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 262144L) != 0)) + if ((_bits & 131072L) == 0) { - ThrowDuplicateKeyException(); + _bits |= 131072L; + _headers._Expires = value; + return true; } - _bits |= 262144L; - _headers._Expires = value; - return; + return false; } } break; - case 17: { if ("Transfer-Encoding".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 64L) != 0)) + if ((_bits & 64L) == 0) { - ThrowDuplicateKeyException(); + _bits |= 64L; + _headers._TransferEncoding = value; + _headers._rawTransferEncoding = null; + return true; } - _bits |= 64L; - _headers._TransferEncoding = value; - _headers._rawTransferEncoding = null; - return; + return false; } } break; - case 3: { if ("Via".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 256L) != 0)) + if ((_bits & 256L) == 0) { - ThrowDuplicateKeyException(); + _bits |= 256L; + _headers._Via = value; + return true; } - _bits |= 256L; - _headers._Via = value; - return; + return false; } - if ("Age".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 2097152L) != 0)) + if ((_bits & 1048576L) == 0) { - ThrowDuplicateKeyException(); + _bits |= 1048576L; + _headers._Age = value; + return true; } - _bits |= 2097152L; - _headers._Age = value; - return; + return false; } } break; - case 5: { if ("Allow".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 1024L) != 0)) + if ((_bits & 1024L) == 0) { - ThrowDuplicateKeyException(); + _bits |= 1024L; + _headers._Allow = value; + return true; } - _bits |= 1024L; - _headers._Allow = value; - return; + return false; } } break; - - case 14: - { - if ("Content-Length".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 2048L) != 0)) - { - ThrowDuplicateKeyException(); - } - _contentLength = ParseContentLength(value); - _bits |= 2048L; - _headers._ContentLength = value; - _headers._rawContentLength = null; - return; - } - } - break; - case 12: { if ("Content-Type".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 4096L) != 0)) + if ((_bits & 2048L) == 0) { - ThrowDuplicateKeyException(); + _bits |= 2048L; + _headers._ContentType = value; + return true; } - _bits |= 4096L; - _headers._ContentType = value; - return; + return false; } } break; - case 16: { if ("Content-Encoding".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 8192L) != 0)) + if ((_bits & 4096L) == 0) { - ThrowDuplicateKeyException(); + _bits |= 4096L; + _headers._ContentEncoding = value; + return true; } - _bits |= 8192L; - _headers._ContentEncoding = value; - return; + return false; } - if ("Content-Language".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 16384L) != 0)) + if ((_bits & 8192L) == 0) { - ThrowDuplicateKeyException(); + _bits |= 8192L; + _headers._ContentLanguage = value; + return true; } - _bits |= 16384L; - _headers._ContentLanguage = value; - return; + return false; } - if ("Content-Location".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 32768L) != 0)) + if ((_bits & 16384L) == 0) { - ThrowDuplicateKeyException(); + _bits |= 16384L; + _headers._ContentLocation = value; + return true; } - _bits |= 32768L; - _headers._ContentLocation = value; - return; + return false; } - if ("WWW-Authenticate".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 536870912L) != 0)) + if ((_bits & 268435456L) == 0) { - ThrowDuplicateKeyException(); + _bits |= 268435456L; + _headers._WWWAuthenticate = value; + return true; } - _bits |= 536870912L; - _headers._WWWAuthenticate = value; - return; + return false; } } break; - case 11: { if ("Content-MD5".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 65536L) != 0)) + if ((_bits & 32768L) == 0) { - ThrowDuplicateKeyException(); + _bits |= 32768L; + _headers._ContentMD5 = value; + return true; } - _bits |= 65536L; - _headers._ContentMD5 = value; - return; + return false; } - if ("Retry-After".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 33554432L) != 0)) + if ((_bits & 16777216L) == 0) { - ThrowDuplicateKeyException(); + _bits |= 16777216L; + _headers._RetryAfter = value; + return true; } - _bits |= 33554432L; - _headers._RetryAfter = value; - return; + return false; } } break; - case 8: { if ("Location".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 8388608L) != 0)) + if ((_bits & 4194304L) == 0) { - ThrowDuplicateKeyException(); + _bits |= 4194304L; + _headers._Location = value; + return true; } - _bits |= 8388608L; - _headers._Location = value; - return; + return false; } } break; - case 18: { if ("Proxy-Authenticate".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 16777216L) != 0)) + if ((_bits & 8388608L) == 0) { - ThrowDuplicateKeyException(); + _bits |= 8388608L; + _headers._ProxyAuthenticate = value; + return true; } - _bits |= 16777216L; - _headers._ProxyAuthenticate = value; - return; + return false; } } break; - case 32: { if ("Access-Control-Allow-Credentials".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 1073741824L) != 0)) + if ((_bits & 536870912L) == 0) { - ThrowDuplicateKeyException(); + _bits |= 536870912L; + _headers._AccessControlAllowCredentials = value; + return true; } - _bits |= 1073741824L; - _headers._AccessControlAllowCredentials = value; - return; + return false; } } break; - case 28: { if ("Access-Control-Allow-Headers".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 2147483648L) != 0)) + if ((_bits & 1073741824L) == 0) { - ThrowDuplicateKeyException(); + _bits |= 1073741824L; + _headers._AccessControlAllowHeaders = value; + return true; } - _bits |= 2147483648L; - _headers._AccessControlAllowHeaders = value; - return; + return false; } - if ("Access-Control-Allow-Methods".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 4294967296L) != 0)) + if ((_bits & 2147483648L) == 0) { - ThrowDuplicateKeyException(); + _bits |= 2147483648L; + _headers._AccessControlAllowMethods = value; + return true; } - _bits |= 4294967296L; - _headers._AccessControlAllowMethods = value; - return; + return false; } } break; - case 27: { if ("Access-Control-Allow-Origin".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 8589934592L) != 0)) + if ((_bits & 4294967296L) == 0) { - ThrowDuplicateKeyException(); + _bits |= 4294967296L; + _headers._AccessControlAllowOrigin = value; + return true; } - _bits |= 8589934592L; - _headers._AccessControlAllowOrigin = value; - return; + return false; } } break; - case 29: { if ("Access-Control-Expose-Headers".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 17179869184L) != 0)) + if ((_bits & 8589934592L) == 0) { - ThrowDuplicateKeyException(); + _bits |= 8589934592L; + _headers._AccessControlExposeHeaders = value; + return true; } - _bits |= 17179869184L; - _headers._AccessControlExposeHeaders = value; - return; + return false; } } break; - case 22: { if ("Access-Control-Max-Age".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 34359738368L) != 0)) + if ((_bits & 17179869184L) == 0) { - ThrowDuplicateKeyException(); + _bits |= 17179869184L; + _headers._AccessControlMaxAge = value; + return true; } - _bits |= 34359738368L; - _headers._AccessControlMaxAge = value; - return; + return false; + } + } + break; + case 14: + { + if ("Content-Length".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (!_contentLength.HasValue) + { + _contentLength = ParseContentLength(value); + return true; + } + return false; } } break; } + ValidateHeaderCharacters(key); Unknown.Add(key, value); + // Return true, above will throw and exit for false + return true; } + protected override bool RemoveFast(string key) { switch (key.Length) @@ -8517,1374 +6615,1151 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { if ("Cache-Control".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 1L) != 0)) + if ((_bits & 1L) != 0) { _bits &= ~1L; - _headers._CacheControl = StringValues.Empty; + _headers._CacheControl = default(StringValues); return true; } - else - { - return false; - } + return false; } - if ("Content-Range".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 131072L) != 0)) + if ((_bits & 65536L) != 0) { - _bits &= ~131072L; - _headers._ContentRange = StringValues.Empty; + _bits &= ~65536L; + _headers._ContentRange = default(StringValues); return true; } - else - { - return false; - } + return false; } - if ("Last-Modified".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 524288L) != 0)) + if ((_bits & 262144L) != 0) { - _bits &= ~524288L; - _headers._LastModified = StringValues.Empty; + _bits &= ~262144L; + _headers._LastModified = default(StringValues); return true; } - else - { - return false; - } + return false; } - if ("Accept-Ranges".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 1048576L) != 0)) + if ((_bits & 524288L) != 0) { - _bits &= ~1048576L; - _headers._AcceptRanges = StringValues.Empty; + _bits &= ~524288L; + _headers._AcceptRanges = default(StringValues); return true; } - else - { - return false; - } + return false; } } break; - case 10: { if ("Connection".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 2L) != 0)) + if ((_bits & 2L) != 0) { _bits &= ~2L; - _headers._Connection = StringValues.Empty; + _headers._Connection = default(StringValues); _headers._rawConnection = null; return true; } - else - { - return false; - } + return false; } - if ("Keep-Alive".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 8L) != 0)) + if ((_bits & 8L) != 0) { _bits &= ~8L; - _headers._KeepAlive = StringValues.Empty; + _headers._KeepAlive = default(StringValues); return true; } - else - { - return false; - } + return false; } - if ("Set-Cookie".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 134217728L) != 0)) + if ((_bits & 67108864L) != 0) { - _bits &= ~134217728L; - _headers._SetCookie = StringValues.Empty; + _bits &= ~67108864L; + _headers._SetCookie = default(StringValues); return true; } - else - { - return false; - } + return false; } } break; - case 4: { if ("Date".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 4L) != 0)) + if ((_bits & 4L) != 0) { _bits &= ~4L; - _headers._Date = StringValues.Empty; + _headers._Date = default(StringValues); _headers._rawDate = null; return true; } - else - { - return false; - } + return false; } - if ("ETag".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 4194304L) != 0)) + if ((_bits & 2097152L) != 0) { - _bits &= ~4194304L; - _headers._ETag = StringValues.Empty; + _bits &= ~2097152L; + _headers._ETag = default(StringValues); return true; } - else - { - return false; - } + return false; } - if ("Vary".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 268435456L) != 0)) + if ((_bits & 134217728L) != 0) { - _bits &= ~268435456L; - _headers._Vary = StringValues.Empty; + _bits &= ~134217728L; + _headers._Vary = default(StringValues); return true; } - else - { - return false; - } + return false; } } break; - case 6: { if ("Pragma".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 16L) != 0)) + if ((_bits & 16L) != 0) { _bits &= ~16L; - _headers._Pragma = StringValues.Empty; + _headers._Pragma = default(StringValues); return true; } - else - { - return false; - } + return false; } - if ("Server".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 67108864L) != 0)) + if ((_bits & 33554432L) != 0) { - _bits &= ~67108864L; - _headers._Server = StringValues.Empty; + _bits &= ~33554432L; + _headers._Server = default(StringValues); _headers._rawServer = null; return true; } - else - { - return false; - } + return false; } } break; - case 7: { if ("Trailer".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 32L) != 0)) + if ((_bits & 32L) != 0) { _bits &= ~32L; - _headers._Trailer = StringValues.Empty; + _headers._Trailer = default(StringValues); return true; } - else - { - return false; - } + return false; } - if ("Upgrade".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 128L) != 0)) + if ((_bits & 128L) != 0) { _bits &= ~128L; - _headers._Upgrade = StringValues.Empty; + _headers._Upgrade = default(StringValues); return true; } - else - { - return false; - } + return false; } - if ("Warning".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 512L) != 0)) + if ((_bits & 512L) != 0) { _bits &= ~512L; - _headers._Warning = StringValues.Empty; + _headers._Warning = default(StringValues); return true; } - else - { - return false; - } + return false; } - if ("Expires".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 262144L) != 0)) + if ((_bits & 131072L) != 0) { - _bits &= ~262144L; - _headers._Expires = StringValues.Empty; + _bits &= ~131072L; + _headers._Expires = default(StringValues); return true; } - else - { - return false; - } + return false; } } break; - case 17: { if ("Transfer-Encoding".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 64L) != 0)) + if ((_bits & 64L) != 0) { _bits &= ~64L; - _headers._TransferEncoding = StringValues.Empty; + _headers._TransferEncoding = default(StringValues); _headers._rawTransferEncoding = null; return true; } - else - { - return false; - } + return false; } } break; - case 3: { if ("Via".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 256L) != 0)) + if ((_bits & 256L) != 0) { _bits &= ~256L; - _headers._Via = StringValues.Empty; + _headers._Via = default(StringValues); return true; } - else - { - return false; - } + return false; } - if ("Age".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 2097152L) != 0)) + if ((_bits & 1048576L) != 0) { - _bits &= ~2097152L; - _headers._Age = StringValues.Empty; + _bits &= ~1048576L; + _headers._Age = default(StringValues); return true; } - else - { - return false; - } + return false; } } break; - case 5: { if ("Allow".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 1024L) != 0)) + if ((_bits & 1024L) != 0) { _bits &= ~1024L; - _headers._Allow = StringValues.Empty; + _headers._Allow = default(StringValues); return true; } - else - { - return false; - } + return false; } } break; - - case 14: - { - if ("Content-Length".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 2048L) != 0)) - { - _contentLength = null; - _bits &= ~2048L; - _headers._ContentLength = StringValues.Empty; - _headers._rawContentLength = null; - return true; - } - else - { - return false; - } - } - } - break; - case 12: { if ("Content-Type".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 4096L) != 0)) + if ((_bits & 2048L) != 0) { - _bits &= ~4096L; - _headers._ContentType = StringValues.Empty; + _bits &= ~2048L; + _headers._ContentType = default(StringValues); return true; } - else - { - return false; - } + return false; } } break; - case 16: { if ("Content-Encoding".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 8192L) != 0)) + if ((_bits & 4096L) != 0) { - _bits &= ~8192L; - _headers._ContentEncoding = StringValues.Empty; + _bits &= ~4096L; + _headers._ContentEncoding = default(StringValues); return true; } - else - { - return false; - } + return false; } - if ("Content-Language".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 16384L) != 0)) + if ((_bits & 8192L) != 0) { - _bits &= ~16384L; - _headers._ContentLanguage = StringValues.Empty; + _bits &= ~8192L; + _headers._ContentLanguage = default(StringValues); return true; } - else - { - return false; - } + return false; } - if ("Content-Location".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 32768L) != 0)) + if ((_bits & 16384L) != 0) { - _bits &= ~32768L; - _headers._ContentLocation = StringValues.Empty; + _bits &= ~16384L; + _headers._ContentLocation = default(StringValues); return true; } - else - { - return false; - } + return false; } - if ("WWW-Authenticate".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 536870912L) != 0)) + if ((_bits & 268435456L) != 0) { - _bits &= ~536870912L; - _headers._WWWAuthenticate = StringValues.Empty; + _bits &= ~268435456L; + _headers._WWWAuthenticate = default(StringValues); return true; } - else - { - return false; - } + return false; } } break; - case 11: { if ("Content-MD5".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 65536L) != 0)) + if ((_bits & 32768L) != 0) { - _bits &= ~65536L; - _headers._ContentMD5 = StringValues.Empty; + _bits &= ~32768L; + _headers._ContentMD5 = default(StringValues); return true; } - else - { - return false; - } + return false; } - if ("Retry-After".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 33554432L) != 0)) + if ((_bits & 16777216L) != 0) { - _bits &= ~33554432L; - _headers._RetryAfter = StringValues.Empty; + _bits &= ~16777216L; + _headers._RetryAfter = default(StringValues); return true; } - else - { - return false; - } + return false; } } break; - case 8: { if ("Location".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 8388608L) != 0)) + if ((_bits & 4194304L) != 0) { - _bits &= ~8388608L; - _headers._Location = StringValues.Empty; + _bits &= ~4194304L; + _headers._Location = default(StringValues); return true; } - else - { - return false; - } + return false; } } break; - case 18: { if ("Proxy-Authenticate".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 16777216L) != 0)) + if ((_bits & 8388608L) != 0) { - _bits &= ~16777216L; - _headers._ProxyAuthenticate = StringValues.Empty; + _bits &= ~8388608L; + _headers._ProxyAuthenticate = default(StringValues); return true; } - else - { - return false; - } + return false; } } break; - case 32: { if ("Access-Control-Allow-Credentials".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 1073741824L) != 0)) + if ((_bits & 536870912L) != 0) { - _bits &= ~1073741824L; - _headers._AccessControlAllowCredentials = StringValues.Empty; + _bits &= ~536870912L; + _headers._AccessControlAllowCredentials = default(StringValues); return true; } - else - { - return false; - } + return false; } } break; - case 28: { if ("Access-Control-Allow-Headers".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 2147483648L) != 0)) + if ((_bits & 1073741824L) != 0) { - _bits &= ~2147483648L; - _headers._AccessControlAllowHeaders = StringValues.Empty; + _bits &= ~1073741824L; + _headers._AccessControlAllowHeaders = default(StringValues); return true; } - else - { - return false; - } + return false; } - if ("Access-Control-Allow-Methods".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 4294967296L) != 0)) + if ((_bits & 2147483648L) != 0) { - _bits &= ~4294967296L; - _headers._AccessControlAllowMethods = StringValues.Empty; + _bits &= ~2147483648L; + _headers._AccessControlAllowMethods = default(StringValues); return true; } - else - { - return false; - } + return false; } } break; - case 27: { if ("Access-Control-Allow-Origin".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 8589934592L) != 0)) + if ((_bits & 4294967296L) != 0) { - _bits &= ~8589934592L; - _headers._AccessControlAllowOrigin = StringValues.Empty; + _bits &= ~4294967296L; + _headers._AccessControlAllowOrigin = default(StringValues); return true; } - else - { - return false; - } + return false; } } break; - case 29: { if ("Access-Control-Expose-Headers".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 17179869184L) != 0)) + if ((_bits & 8589934592L) != 0) { - _bits &= ~17179869184L; - _headers._AccessControlExposeHeaders = StringValues.Empty; + _bits &= ~8589934592L; + _headers._AccessControlExposeHeaders = default(StringValues); return true; } - else - { - return false; - } + return false; } } break; - case 22: { if ("Access-Control-Max-Age".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 34359738368L) != 0)) + if ((_bits & 17179869184L) != 0) { - _bits &= ~34359738368L; - _headers._AccessControlMaxAge = StringValues.Empty; + _bits &= ~17179869184L; + _headers._AccessControlMaxAge = default(StringValues); return true; } - else + return false; + } + } + break; + case 14: + { + if ("Content-Length".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (_contentLength.HasValue) { - return false; + _contentLength = null; + return true; } + return false; } } break; } + return MaybeUnknown?.Remove(key) ?? false; } + protected override void ClearFast() - { + { MaybeUnknown?.Clear(); _contentLength = null; - if(FrameHeaders.BitCount(_bits) > 12) + var tempBits = _bits; + _bits = 0; + if(FrameHeaders.BitCount(tempBits) > 12) { _headers = default(HeaderReferences); - _bits = 0; return; } - if (((_bits & 2L) != 0)) + if ((tempBits & 2L) != 0) { _headers._Connection = default(StringValues); - _bits &= ~2L; - if(_bits == 0) + if((tempBits & ~2L) == 0) { return; } + tempBits &= ~2L; } - if (((_bits & 4L) != 0)) + if ((tempBits & 4L) != 0) { _headers._Date = default(StringValues); - _bits &= ~4L; - if(_bits == 0) + if((tempBits & ~4L) == 0) { return; } + tempBits &= ~4L; } - if (((_bits & 2048L) != 0)) - { - _headers._ContentLength = default(StringValues); - _bits &= ~2048L; - if(_bits == 0) - { - return; - } - } - - if (((_bits & 4096L) != 0)) + if ((tempBits & 2048L) != 0) { _headers._ContentType = default(StringValues); - _bits &= ~4096L; - if(_bits == 0) + if((tempBits & ~2048L) == 0) { return; } + tempBits &= ~2048L; } - if (((_bits & 67108864L) != 0)) + if ((tempBits & 33554432L) != 0) { _headers._Server = default(StringValues); - _bits &= ~67108864L; - if(_bits == 0) + if((tempBits & ~33554432L) == 0) { return; } + tempBits &= ~33554432L; } - if (((_bits & 1L) != 0)) + if ((tempBits & 1L) != 0) { _headers._CacheControl = default(StringValues); - _bits &= ~1L; - if(_bits == 0) + if((tempBits & ~1L) == 0) { return; } + tempBits &= ~1L; } - if (((_bits & 8L) != 0)) + if ((tempBits & 8L) != 0) { _headers._KeepAlive = default(StringValues); - _bits &= ~8L; - if(_bits == 0) + if((tempBits & ~8L) == 0) { return; } + tempBits &= ~8L; } - if (((_bits & 16L) != 0)) + if ((tempBits & 16L) != 0) { _headers._Pragma = default(StringValues); - _bits &= ~16L; - if(_bits == 0) + if((tempBits & ~16L) == 0) { return; } + tempBits &= ~16L; } - if (((_bits & 32L) != 0)) + if ((tempBits & 32L) != 0) { _headers._Trailer = default(StringValues); - _bits &= ~32L; - if(_bits == 0) + if((tempBits & ~32L) == 0) { return; } + tempBits &= ~32L; } - if (((_bits & 64L) != 0)) + if ((tempBits & 64L) != 0) { _headers._TransferEncoding = default(StringValues); - _bits &= ~64L; - if(_bits == 0) + if((tempBits & ~64L) == 0) { return; } + tempBits &= ~64L; } - if (((_bits & 128L) != 0)) + if ((tempBits & 128L) != 0) { _headers._Upgrade = default(StringValues); - _bits &= ~128L; - if(_bits == 0) + if((tempBits & ~128L) == 0) { return; } + tempBits &= ~128L; } - if (((_bits & 256L) != 0)) + if ((tempBits & 256L) != 0) { _headers._Via = default(StringValues); - _bits &= ~256L; - if(_bits == 0) + if((tempBits & ~256L) == 0) { return; } + tempBits &= ~256L; } - if (((_bits & 512L) != 0)) + if ((tempBits & 512L) != 0) { _headers._Warning = default(StringValues); - _bits &= ~512L; - if(_bits == 0) + if((tempBits & ~512L) == 0) { return; } + tempBits &= ~512L; } - if (((_bits & 1024L) != 0)) + if ((tempBits & 1024L) != 0) { _headers._Allow = default(StringValues); - _bits &= ~1024L; - if(_bits == 0) + if((tempBits & ~1024L) == 0) { return; } + tempBits &= ~1024L; } - if (((_bits & 8192L) != 0)) + if ((tempBits & 4096L) != 0) { _headers._ContentEncoding = default(StringValues); - _bits &= ~8192L; - if(_bits == 0) + if((tempBits & ~4096L) == 0) { return; } + tempBits &= ~4096L; } - if (((_bits & 16384L) != 0)) + if ((tempBits & 8192L) != 0) { _headers._ContentLanguage = default(StringValues); - _bits &= ~16384L; - if(_bits == 0) + if((tempBits & ~8192L) == 0) { return; } + tempBits &= ~8192L; } - if (((_bits & 32768L) != 0)) + if ((tempBits & 16384L) != 0) { _headers._ContentLocation = default(StringValues); - _bits &= ~32768L; - if(_bits == 0) + if((tempBits & ~16384L) == 0) { return; } + tempBits &= ~16384L; } - if (((_bits & 65536L) != 0)) + if ((tempBits & 32768L) != 0) { _headers._ContentMD5 = default(StringValues); - _bits &= ~65536L; - if(_bits == 0) + if((tempBits & ~32768L) == 0) { return; } + tempBits &= ~32768L; } - if (((_bits & 131072L) != 0)) + if ((tempBits & 65536L) != 0) { _headers._ContentRange = default(StringValues); - _bits &= ~131072L; - if(_bits == 0) + if((tempBits & ~65536L) == 0) { return; } + tempBits &= ~65536L; } - if (((_bits & 262144L) != 0)) + if ((tempBits & 131072L) != 0) { _headers._Expires = default(StringValues); - _bits &= ~262144L; - if(_bits == 0) + if((tempBits & ~131072L) == 0) { return; } + tempBits &= ~131072L; } - if (((_bits & 524288L) != 0)) + if ((tempBits & 262144L) != 0) { _headers._LastModified = default(StringValues); - _bits &= ~524288L; - if(_bits == 0) + if((tempBits & ~262144L) == 0) { return; } + tempBits &= ~262144L; } - if (((_bits & 1048576L) != 0)) + if ((tempBits & 524288L) != 0) { _headers._AcceptRanges = default(StringValues); - _bits &= ~1048576L; - if(_bits == 0) + if((tempBits & ~524288L) == 0) { return; } + tempBits &= ~524288L; } - if (((_bits & 2097152L) != 0)) + if ((tempBits & 1048576L) != 0) { _headers._Age = default(StringValues); - _bits &= ~2097152L; - if(_bits == 0) + if((tempBits & ~1048576L) == 0) { return; } + tempBits &= ~1048576L; } - if (((_bits & 4194304L) != 0)) + if ((tempBits & 2097152L) != 0) { _headers._ETag = default(StringValues); - _bits &= ~4194304L; - if(_bits == 0) + if((tempBits & ~2097152L) == 0) { return; } + tempBits &= ~2097152L; } - if (((_bits & 8388608L) != 0)) + if ((tempBits & 4194304L) != 0) { _headers._Location = default(StringValues); - _bits &= ~8388608L; - if(_bits == 0) + if((tempBits & ~4194304L) == 0) { return; } + tempBits &= ~4194304L; } - if (((_bits & 16777216L) != 0)) + if ((tempBits & 8388608L) != 0) { _headers._ProxyAuthenticate = default(StringValues); - _bits &= ~16777216L; - if(_bits == 0) + if((tempBits & ~8388608L) == 0) { return; } + tempBits &= ~8388608L; } - if (((_bits & 33554432L) != 0)) + if ((tempBits & 16777216L) != 0) { _headers._RetryAfter = default(StringValues); - _bits &= ~33554432L; - if(_bits == 0) + if((tempBits & ~16777216L) == 0) { return; } + tempBits &= ~16777216L; } - if (((_bits & 134217728L) != 0)) + if ((tempBits & 67108864L) != 0) { _headers._SetCookie = default(StringValues); - _bits &= ~134217728L; - if(_bits == 0) + if((tempBits & ~67108864L) == 0) { return; } + tempBits &= ~67108864L; } - if (((_bits & 268435456L) != 0)) + if ((tempBits & 134217728L) != 0) { _headers._Vary = default(StringValues); - _bits &= ~268435456L; - if(_bits == 0) + if((tempBits & ~134217728L) == 0) { return; } + tempBits &= ~134217728L; } - if (((_bits & 536870912L) != 0)) + if ((tempBits & 268435456L) != 0) { _headers._WWWAuthenticate = default(StringValues); - _bits &= ~536870912L; - if(_bits == 0) + if((tempBits & ~268435456L) == 0) { return; } + tempBits &= ~268435456L; } - if (((_bits & 1073741824L) != 0)) + if ((tempBits & 536870912L) != 0) { _headers._AccessControlAllowCredentials = default(StringValues); - _bits &= ~1073741824L; - if(_bits == 0) + if((tempBits & ~536870912L) == 0) { return; } + tempBits &= ~536870912L; } - if (((_bits & 2147483648L) != 0)) + if ((tempBits & 1073741824L) != 0) { _headers._AccessControlAllowHeaders = default(StringValues); - _bits &= ~2147483648L; - if(_bits == 0) + if((tempBits & ~1073741824L) == 0) { return; } + tempBits &= ~1073741824L; } - if (((_bits & 4294967296L) != 0)) + if ((tempBits & 2147483648L) != 0) { _headers._AccessControlAllowMethods = default(StringValues); - _bits &= ~4294967296L; - if(_bits == 0) + if((tempBits & ~2147483648L) == 0) { return; } + tempBits &= ~2147483648L; } - if (((_bits & 8589934592L) != 0)) + if ((tempBits & 4294967296L) != 0) { _headers._AccessControlAllowOrigin = default(StringValues); - _bits &= ~8589934592L; - if(_bits == 0) + if((tempBits & ~4294967296L) == 0) { return; } + tempBits &= ~4294967296L; } - if (((_bits & 17179869184L) != 0)) + if ((tempBits & 8589934592L) != 0) { _headers._AccessControlExposeHeaders = default(StringValues); - _bits &= ~17179869184L; - if(_bits == 0) + if((tempBits & ~8589934592L) == 0) { return; } + tempBits &= ~8589934592L; } - if (((_bits & 34359738368L) != 0)) + if ((tempBits & 17179869184L) != 0) { _headers._AccessControlMaxAge = default(StringValues); - _bits &= ~34359738368L; - if(_bits == 0) + if((tempBits & ~17179869184L) == 0) { return; } + tempBits &= ~17179869184L; } } - protected override void CopyToFast(KeyValuePair[] array, int arrayIndex) + protected override bool CopyToFast(KeyValuePair[] array, int arrayIndex) { if (arrayIndex < 0) { - ThrowArgumentException(); + return false; } - if (((_bits & 1L) != 0)) + if ((_bits & 1L) != 0) { if (arrayIndex == array.Length) { - ThrowArgumentException(); + return false; } - array[arrayIndex] = new KeyValuePair("Cache-Control", _headers._CacheControl); ++arrayIndex; } - - if (((_bits & 2L) != 0)) + if ((_bits & 2L) != 0) { if (arrayIndex == array.Length) { - ThrowArgumentException(); + return false; } - array[arrayIndex] = new KeyValuePair("Connection", _headers._Connection); ++arrayIndex; } - - if (((_bits & 4L) != 0)) + if ((_bits & 4L) != 0) { if (arrayIndex == array.Length) { - ThrowArgumentException(); + return false; } - array[arrayIndex] = new KeyValuePair("Date", _headers._Date); ++arrayIndex; } - - if (((_bits & 8L) != 0)) + if ((_bits & 8L) != 0) { if (arrayIndex == array.Length) { - ThrowArgumentException(); + return false; } - array[arrayIndex] = new KeyValuePair("Keep-Alive", _headers._KeepAlive); ++arrayIndex; } - - if (((_bits & 16L) != 0)) + if ((_bits & 16L) != 0) { if (arrayIndex == array.Length) { - ThrowArgumentException(); + return false; } - array[arrayIndex] = new KeyValuePair("Pragma", _headers._Pragma); ++arrayIndex; } - - if (((_bits & 32L) != 0)) + if ((_bits & 32L) != 0) { if (arrayIndex == array.Length) { - ThrowArgumentException(); + return false; } - array[arrayIndex] = new KeyValuePair("Trailer", _headers._Trailer); ++arrayIndex; } - - if (((_bits & 64L) != 0)) + if ((_bits & 64L) != 0) { if (arrayIndex == array.Length) { - ThrowArgumentException(); + return false; } - array[arrayIndex] = new KeyValuePair("Transfer-Encoding", _headers._TransferEncoding); ++arrayIndex; } - - if (((_bits & 128L) != 0)) + if ((_bits & 128L) != 0) { if (arrayIndex == array.Length) { - ThrowArgumentException(); + return false; } - array[arrayIndex] = new KeyValuePair("Upgrade", _headers._Upgrade); ++arrayIndex; } - - if (((_bits & 256L) != 0)) + if ((_bits & 256L) != 0) { if (arrayIndex == array.Length) { - ThrowArgumentException(); + return false; } - array[arrayIndex] = new KeyValuePair("Via", _headers._Via); ++arrayIndex; } - - if (((_bits & 512L) != 0)) + if ((_bits & 512L) != 0) { if (arrayIndex == array.Length) { - ThrowArgumentException(); + return false; } - array[arrayIndex] = new KeyValuePair("Warning", _headers._Warning); ++arrayIndex; } - - if (((_bits & 1024L) != 0)) + if ((_bits & 1024L) != 0) { if (arrayIndex == array.Length) { - ThrowArgumentException(); + return false; } - array[arrayIndex] = new KeyValuePair("Allow", _headers._Allow); ++arrayIndex; } - - if (((_bits & 2048L) != 0)) + if ((_bits & 2048L) != 0) { if (arrayIndex == array.Length) { - ThrowArgumentException(); + return false; } - - array[arrayIndex] = new KeyValuePair("Content-Length", _headers._ContentLength); - ++arrayIndex; - } - - if (((_bits & 4096L) != 0)) - { - if (arrayIndex == array.Length) - { - ThrowArgumentException(); - } - array[arrayIndex] = new KeyValuePair("Content-Type", _headers._ContentType); ++arrayIndex; } - - if (((_bits & 8192L) != 0)) + if ((_bits & 4096L) != 0) { if (arrayIndex == array.Length) { - ThrowArgumentException(); + return false; } - array[arrayIndex] = new KeyValuePair("Content-Encoding", _headers._ContentEncoding); ++arrayIndex; } - - if (((_bits & 16384L) != 0)) + if ((_bits & 8192L) != 0) { if (arrayIndex == array.Length) { - ThrowArgumentException(); + return false; } - array[arrayIndex] = new KeyValuePair("Content-Language", _headers._ContentLanguage); ++arrayIndex; } - - if (((_bits & 32768L) != 0)) + if ((_bits & 16384L) != 0) { if (arrayIndex == array.Length) { - ThrowArgumentException(); + return false; } - array[arrayIndex] = new KeyValuePair("Content-Location", _headers._ContentLocation); ++arrayIndex; } - - if (((_bits & 65536L) != 0)) + if ((_bits & 32768L) != 0) { if (arrayIndex == array.Length) { - ThrowArgumentException(); + return false; } - array[arrayIndex] = new KeyValuePair("Content-MD5", _headers._ContentMD5); ++arrayIndex; } - - if (((_bits & 131072L) != 0)) + if ((_bits & 65536L) != 0) { if (arrayIndex == array.Length) { - ThrowArgumentException(); + return false; } - array[arrayIndex] = new KeyValuePair("Content-Range", _headers._ContentRange); ++arrayIndex; } - - if (((_bits & 262144L) != 0)) + if ((_bits & 131072L) != 0) { if (arrayIndex == array.Length) { - ThrowArgumentException(); + return false; } - array[arrayIndex] = new KeyValuePair("Expires", _headers._Expires); ++arrayIndex; } - - if (((_bits & 524288L) != 0)) + if ((_bits & 262144L) != 0) { if (arrayIndex == array.Length) { - ThrowArgumentException(); + return false; } - array[arrayIndex] = new KeyValuePair("Last-Modified", _headers._LastModified); ++arrayIndex; } - - if (((_bits & 1048576L) != 0)) + if ((_bits & 524288L) != 0) { if (arrayIndex == array.Length) { - ThrowArgumentException(); + return false; } - array[arrayIndex] = new KeyValuePair("Accept-Ranges", _headers._AcceptRanges); ++arrayIndex; } - - if (((_bits & 2097152L) != 0)) + if ((_bits & 1048576L) != 0) { if (arrayIndex == array.Length) { - ThrowArgumentException(); + return false; } - array[arrayIndex] = new KeyValuePair("Age", _headers._Age); ++arrayIndex; } - - if (((_bits & 4194304L) != 0)) + if ((_bits & 2097152L) != 0) { if (arrayIndex == array.Length) { - ThrowArgumentException(); + return false; } - array[arrayIndex] = new KeyValuePair("ETag", _headers._ETag); ++arrayIndex; } - - if (((_bits & 8388608L) != 0)) + if ((_bits & 4194304L) != 0) { if (arrayIndex == array.Length) { - ThrowArgumentException(); + return false; } - array[arrayIndex] = new KeyValuePair("Location", _headers._Location); ++arrayIndex; } - - if (((_bits & 16777216L) != 0)) + if ((_bits & 8388608L) != 0) { if (arrayIndex == array.Length) { - ThrowArgumentException(); + return false; } - array[arrayIndex] = new KeyValuePair("Proxy-Authenticate", _headers._ProxyAuthenticate); ++arrayIndex; } - - if (((_bits & 33554432L) != 0)) + if ((_bits & 16777216L) != 0) { if (arrayIndex == array.Length) { - ThrowArgumentException(); + return false; } - array[arrayIndex] = new KeyValuePair("Retry-After", _headers._RetryAfter); ++arrayIndex; } - - if (((_bits & 67108864L) != 0)) + if ((_bits & 33554432L) != 0) { if (arrayIndex == array.Length) { - ThrowArgumentException(); + return false; } - array[arrayIndex] = new KeyValuePair("Server", _headers._Server); ++arrayIndex; } - - if (((_bits & 134217728L) != 0)) + if ((_bits & 67108864L) != 0) { if (arrayIndex == array.Length) { - ThrowArgumentException(); + return false; } - array[arrayIndex] = new KeyValuePair("Set-Cookie", _headers._SetCookie); ++arrayIndex; } - - if (((_bits & 268435456L) != 0)) + if ((_bits & 134217728L) != 0) { if (arrayIndex == array.Length) { - ThrowArgumentException(); + return false; } - array[arrayIndex] = new KeyValuePair("Vary", _headers._Vary); ++arrayIndex; } - - if (((_bits & 536870912L) != 0)) + if ((_bits & 268435456L) != 0) { if (arrayIndex == array.Length) { - ThrowArgumentException(); + return false; } - array[arrayIndex] = new KeyValuePair("WWW-Authenticate", _headers._WWWAuthenticate); ++arrayIndex; } - - if (((_bits & 1073741824L) != 0)) + if ((_bits & 536870912L) != 0) { if (arrayIndex == array.Length) { - ThrowArgumentException(); + return false; } - array[arrayIndex] = new KeyValuePair("Access-Control-Allow-Credentials", _headers._AccessControlAllowCredentials); ++arrayIndex; } - - if (((_bits & 2147483648L) != 0)) + if ((_bits & 1073741824L) != 0) { if (arrayIndex == array.Length) { - ThrowArgumentException(); + return false; } - array[arrayIndex] = new KeyValuePair("Access-Control-Allow-Headers", _headers._AccessControlAllowHeaders); ++arrayIndex; } - - if (((_bits & 4294967296L) != 0)) + if ((_bits & 2147483648L) != 0) { if (arrayIndex == array.Length) { - ThrowArgumentException(); + return false; } - array[arrayIndex] = new KeyValuePair("Access-Control-Allow-Methods", _headers._AccessControlAllowMethods); ++arrayIndex; } - - if (((_bits & 8589934592L) != 0)) + if ((_bits & 4294967296L) != 0) { if (arrayIndex == array.Length) { - ThrowArgumentException(); + return false; } - array[arrayIndex] = new KeyValuePair("Access-Control-Allow-Origin", _headers._AccessControlAllowOrigin); ++arrayIndex; } - - if (((_bits & 17179869184L) != 0)) + if ((_bits & 8589934592L) != 0) { if (arrayIndex == array.Length) { - ThrowArgumentException(); + return false; } - array[arrayIndex] = new KeyValuePair("Access-Control-Expose-Headers", _headers._AccessControlExposeHeaders); ++arrayIndex; } - - if (((_bits & 34359738368L) != 0)) + if ((_bits & 17179869184L) != 0) { if (arrayIndex == array.Length) { - ThrowArgumentException(); + return false; } - array[arrayIndex] = new KeyValuePair("Access-Control-Max-Age", _headers._AccessControlMaxAge); ++arrayIndex; } - + if (_contentLength.HasValue) + { + if (arrayIndex == array.Length) + { + return false; + } + array[arrayIndex] = new KeyValuePair("Content-Length", HeaderUtilities.FormatInt64(_contentLength.Value)); + ++arrayIndex; + } ((ICollection>)MaybeUnknown)?.CopyTo(array, arrayIndex); + + return true; } protected void CopyToFast(ref MemoryPoolIterator output) { - var tempBits = _bits; + var tempBits = _bits | (_contentLength.HasValue ? -9223372036854775808L : 0); - if (((_bits & 2L) != 0)) + if ((tempBits & 2L) != 0) { if (_headers._rawConnection != null) { @@ -9904,14 +7779,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } } - tempBits &= ~2L; - if(tempBits == 0) + if((tempBits & ~2L) == 0) { return; } + tempBits &= ~2L; } - - if (((_bits & 4L) != 0)) + if ((tempBits & 4L) != 0) { if (_headers._rawDate != null) { @@ -9931,41 +7805,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } } + if((tempBits & ~4L) == 0) + { + return; + } tempBits &= ~4L; - if(tempBits == 0) - { - return; - } } - - if (((_bits & 2048L) != 0)) - { - if (_headers._rawContentLength != null) - { - output.CopyFrom(_headers._rawContentLength, 0, _headers._rawContentLength.Length); - } - else - { - var valueCount = _headers._ContentLength.Count; - for (var i = 0; i < valueCount; i++) - { - var value = _headers._ContentLength[i]; - if (value != null) - { - output.CopyFrom(_headerBytes, 133, 18); - output.CopyFromAscii(value); - } - } - } - - tempBits &= ~2048L; - if(tempBits == 0) - { - return; - } - } - - if (((_bits & 4096L) != 0)) + if ((tempBits & 2048L) != 0) { { var valueCount = _headers._ContentType.Count; @@ -9974,20 +7820,19 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var value = _headers._ContentType[i]; if (value != null) { - output.CopyFrom(_headerBytes, 151, 16); + output.CopyFrom(_headerBytes, 133, 16); output.CopyFromAscii(value); } } } - tempBits &= ~4096L; - if(tempBits == 0) + if((tempBits & ~2048L) == 0) { return; } + tempBits &= ~2048L; } - - if (((_bits & 67108864L) != 0)) + if ((tempBits & 33554432L) != 0) { if (_headers._rawServer != null) { @@ -10001,20 +7846,30 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var value = _headers._Server[i]; if (value != null) { - output.CopyFrom(_headerBytes, 368, 10); + output.CopyFrom(_headerBytes, 350, 10); output.CopyFromAscii(value); } } } - tempBits &= ~67108864L; - if(tempBits == 0) + if((tempBits & ~33554432L) == 0) { return; } + tempBits &= ~33554432L; } - - if (((_bits & 1L) != 0)) + if ((tempBits & -9223372036854775808L) != 0) + { + output.CopyFrom(_headerBytes, 592, 18); + output.CopyFromNumeric((ulong)ContentLength.Value); + + if((tempBits & ~-9223372036854775808L) == 0) + { + return; + } + tempBits &= ~-9223372036854775808L; + } + if ((tempBits & 1L) != 0) { { var valueCount = _headers._CacheControl.Count; @@ -10029,14 +7884,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } } - tempBits &= ~1L; - if(tempBits == 0) + if((tempBits & ~1L) == 0) { return; } + tempBits &= ~1L; } - - if (((_bits & 8L) != 0)) + if ((tempBits & 8L) != 0) { { var valueCount = _headers._KeepAlive.Count; @@ -10051,14 +7905,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } } - tempBits &= ~8L; - if(tempBits == 0) + if((tempBits & ~8L) == 0) { return; } + tempBits &= ~8L; } - - if (((_bits & 16L) != 0)) + if ((tempBits & 16L) != 0) { { var valueCount = _headers._Pragma.Count; @@ -10073,14 +7926,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } } - tempBits &= ~16L; - if(tempBits == 0) + if((tempBits & ~16L) == 0) { return; } + tempBits &= ~16L; } - - if (((_bits & 32L) != 0)) + if ((tempBits & 32L) != 0) { { var valueCount = _headers._Trailer.Count; @@ -10095,14 +7947,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } } - tempBits &= ~32L; - if(tempBits == 0) + if((tempBits & ~32L) == 0) { return; } + tempBits &= ~32L; } - - if (((_bits & 64L) != 0)) + if ((tempBits & 64L) != 0) { if (_headers._rawTransferEncoding != null) { @@ -10122,14 +7973,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } } - tempBits &= ~64L; - if(tempBits == 0) + if((tempBits & ~64L) == 0) { return; } + tempBits &= ~64L; } - - if (((_bits & 128L) != 0)) + if ((tempBits & 128L) != 0) { { var valueCount = _headers._Upgrade.Count; @@ -10144,14 +7994,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } } - tempBits &= ~128L; - if(tempBits == 0) + if((tempBits & ~128L) == 0) { return; } + tempBits &= ~128L; } - - if (((_bits & 256L) != 0)) + if ((tempBits & 256L) != 0) { { var valueCount = _headers._Via.Count; @@ -10166,14 +8015,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } } - tempBits &= ~256L; - if(tempBits == 0) + if((tempBits & ~256L) == 0) { return; } + tempBits &= ~256L; } - - if (((_bits & 512L) != 0)) + if ((tempBits & 512L) != 0) { { var valueCount = _headers._Warning.Count; @@ -10188,14 +8036,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } } - tempBits &= ~512L; - if(tempBits == 0) + if((tempBits & ~512L) == 0) { return; } + tempBits &= ~512L; } - - if (((_bits & 1024L) != 0)) + if ((tempBits & 1024L) != 0) { { var valueCount = _headers._Allow.Count; @@ -10210,14 +8057,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } } - tempBits &= ~1024L; - if(tempBits == 0) + if((tempBits & ~1024L) == 0) { return; } + tempBits &= ~1024L; } - - if (((_bits & 8192L) != 0)) + if ((tempBits & 4096L) != 0) { { var valueCount = _headers._ContentEncoding.Count; @@ -10226,20 +8072,19 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var value = _headers._ContentEncoding[i]; if (value != null) { - output.CopyFrom(_headerBytes, 167, 20); + output.CopyFrom(_headerBytes, 149, 20); output.CopyFromAscii(value); } } } - tempBits &= ~8192L; - if(tempBits == 0) + if((tempBits & ~4096L) == 0) { return; } + tempBits &= ~4096L; } - - if (((_bits & 16384L) != 0)) + if ((tempBits & 8192L) != 0) { { var valueCount = _headers._ContentLanguage.Count; @@ -10248,20 +8093,19 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var value = _headers._ContentLanguage[i]; if (value != null) { - output.CopyFrom(_headerBytes, 187, 20); + output.CopyFrom(_headerBytes, 169, 20); output.CopyFromAscii(value); } } } - tempBits &= ~16384L; - if(tempBits == 0) + if((tempBits & ~8192L) == 0) { return; } + tempBits &= ~8192L; } - - if (((_bits & 32768L) != 0)) + if ((tempBits & 16384L) != 0) { { var valueCount = _headers._ContentLocation.Count; @@ -10270,20 +8114,19 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var value = _headers._ContentLocation[i]; if (value != null) { - output.CopyFrom(_headerBytes, 207, 20); + output.CopyFrom(_headerBytes, 189, 20); output.CopyFromAscii(value); } } } - tempBits &= ~32768L; - if(tempBits == 0) + if((tempBits & ~16384L) == 0) { return; } + tempBits &= ~16384L; } - - if (((_bits & 65536L) != 0)) + if ((tempBits & 32768L) != 0) { { var valueCount = _headers._ContentMD5.Count; @@ -10292,20 +8135,19 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var value = _headers._ContentMD5[i]; if (value != null) { - output.CopyFrom(_headerBytes, 227, 15); + output.CopyFrom(_headerBytes, 209, 15); output.CopyFromAscii(value); } } } - tempBits &= ~65536L; - if(tempBits == 0) + if((tempBits & ~32768L) == 0) { return; } + tempBits &= ~32768L; } - - if (((_bits & 131072L) != 0)) + if ((tempBits & 65536L) != 0) { { var valueCount = _headers._ContentRange.Count; @@ -10314,20 +8156,19 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var value = _headers._ContentRange[i]; if (value != null) { - output.CopyFrom(_headerBytes, 242, 17); + output.CopyFrom(_headerBytes, 224, 17); output.CopyFromAscii(value); } } } - tempBits &= ~131072L; - if(tempBits == 0) + if((tempBits & ~65536L) == 0) { return; } + tempBits &= ~65536L; } - - if (((_bits & 262144L) != 0)) + if ((tempBits & 131072L) != 0) { { var valueCount = _headers._Expires.Count; @@ -10336,20 +8177,19 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var value = _headers._Expires[i]; if (value != null) { - output.CopyFrom(_headerBytes, 259, 11); + output.CopyFrom(_headerBytes, 241, 11); output.CopyFromAscii(value); } } } - tempBits &= ~262144L; - if(tempBits == 0) + if((tempBits & ~131072L) == 0) { return; } + tempBits &= ~131072L; } - - if (((_bits & 524288L) != 0)) + if ((tempBits & 262144L) != 0) { { var valueCount = _headers._LastModified.Count; @@ -10358,20 +8198,19 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var value = _headers._LastModified[i]; if (value != null) { - output.CopyFrom(_headerBytes, 270, 17); + output.CopyFrom(_headerBytes, 252, 17); output.CopyFromAscii(value); } } } - tempBits &= ~524288L; - if(tempBits == 0) + if((tempBits & ~262144L) == 0) { return; } + tempBits &= ~262144L; } - - if (((_bits & 1048576L) != 0)) + if ((tempBits & 524288L) != 0) { { var valueCount = _headers._AcceptRanges.Count; @@ -10380,20 +8219,19 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var value = _headers._AcceptRanges[i]; if (value != null) { - output.CopyFrom(_headerBytes, 287, 17); + output.CopyFrom(_headerBytes, 269, 17); output.CopyFromAscii(value); } } } - tempBits &= ~1048576L; - if(tempBits == 0) + if((tempBits & ~524288L) == 0) { return; } + tempBits &= ~524288L; } - - if (((_bits & 2097152L) != 0)) + if ((tempBits & 1048576L) != 0) { { var valueCount = _headers._Age.Count; @@ -10402,20 +8240,19 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var value = _headers._Age[i]; if (value != null) { - output.CopyFrom(_headerBytes, 304, 7); + output.CopyFrom(_headerBytes, 286, 7); output.CopyFromAscii(value); } } } - tempBits &= ~2097152L; - if(tempBits == 0) + if((tempBits & ~1048576L) == 0) { return; } + tempBits &= ~1048576L; } - - if (((_bits & 4194304L) != 0)) + if ((tempBits & 2097152L) != 0) { { var valueCount = _headers._ETag.Count; @@ -10424,20 +8261,19 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var value = _headers._ETag[i]; if (value != null) { - output.CopyFrom(_headerBytes, 311, 8); + output.CopyFrom(_headerBytes, 293, 8); output.CopyFromAscii(value); } } } - tempBits &= ~4194304L; - if(tempBits == 0) + if((tempBits & ~2097152L) == 0) { return; } + tempBits &= ~2097152L; } - - if (((_bits & 8388608L) != 0)) + if ((tempBits & 4194304L) != 0) { { var valueCount = _headers._Location.Count; @@ -10446,20 +8282,19 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var value = _headers._Location[i]; if (value != null) { - output.CopyFrom(_headerBytes, 319, 12); + output.CopyFrom(_headerBytes, 301, 12); output.CopyFromAscii(value); } } } - tempBits &= ~8388608L; - if(tempBits == 0) + if((tempBits & ~4194304L) == 0) { return; } + tempBits &= ~4194304L; } - - if (((_bits & 16777216L) != 0)) + if ((tempBits & 8388608L) != 0) { { var valueCount = _headers._ProxyAuthenticate.Count; @@ -10468,20 +8303,19 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var value = _headers._ProxyAuthenticate[i]; if (value != null) { - output.CopyFrom(_headerBytes, 331, 22); + output.CopyFrom(_headerBytes, 313, 22); output.CopyFromAscii(value); } } } - tempBits &= ~16777216L; - if(tempBits == 0) + if((tempBits & ~8388608L) == 0) { return; } + tempBits &= ~8388608L; } - - if (((_bits & 33554432L) != 0)) + if ((tempBits & 16777216L) != 0) { { var valueCount = _headers._RetryAfter.Count; @@ -10490,20 +8324,19 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var value = _headers._RetryAfter[i]; if (value != null) { - output.CopyFrom(_headerBytes, 353, 15); + output.CopyFrom(_headerBytes, 335, 15); output.CopyFromAscii(value); } } } - tempBits &= ~33554432L; - if(tempBits == 0) + if((tempBits & ~16777216L) == 0) { return; } + tempBits &= ~16777216L; } - - if (((_bits & 134217728L) != 0)) + if ((tempBits & 67108864L) != 0) { { var valueCount = _headers._SetCookie.Count; @@ -10512,20 +8345,19 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var value = _headers._SetCookie[i]; if (value != null) { - output.CopyFrom(_headerBytes, 378, 14); + output.CopyFrom(_headerBytes, 360, 14); output.CopyFromAscii(value); } } } - tempBits &= ~134217728L; - if(tempBits == 0) + if((tempBits & ~67108864L) == 0) { return; } + tempBits &= ~67108864L; } - - if (((_bits & 268435456L) != 0)) + if ((tempBits & 134217728L) != 0) { { var valueCount = _headers._Vary.Count; @@ -10534,20 +8366,19 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var value = _headers._Vary[i]; if (value != null) { - output.CopyFrom(_headerBytes, 392, 8); + output.CopyFrom(_headerBytes, 374, 8); output.CopyFromAscii(value); } } } - tempBits &= ~268435456L; - if(tempBits == 0) + if((tempBits & ~134217728L) == 0) { return; } + tempBits &= ~134217728L; } - - if (((_bits & 536870912L) != 0)) + if ((tempBits & 268435456L) != 0) { { var valueCount = _headers._WWWAuthenticate.Count; @@ -10556,20 +8387,19 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var value = _headers._WWWAuthenticate[i]; if (value != null) { - output.CopyFrom(_headerBytes, 400, 20); + output.CopyFrom(_headerBytes, 382, 20); output.CopyFromAscii(value); } } } - tempBits &= ~536870912L; - if(tempBits == 0) + if((tempBits & ~268435456L) == 0) { return; } + tempBits &= ~268435456L; } - - if (((_bits & 1073741824L) != 0)) + if ((tempBits & 536870912L) != 0) { { var valueCount = _headers._AccessControlAllowCredentials.Count; @@ -10578,20 +8408,19 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var value = _headers._AccessControlAllowCredentials[i]; if (value != null) { - output.CopyFrom(_headerBytes, 420, 36); + output.CopyFrom(_headerBytes, 402, 36); output.CopyFromAscii(value); } } } - tempBits &= ~1073741824L; - if(tempBits == 0) + if((tempBits & ~536870912L) == 0) { return; } + tempBits &= ~536870912L; } - - if (((_bits & 2147483648L) != 0)) + if ((tempBits & 1073741824L) != 0) { { var valueCount = _headers._AccessControlAllowHeaders.Count; @@ -10600,20 +8429,19 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var value = _headers._AccessControlAllowHeaders[i]; if (value != null) { - output.CopyFrom(_headerBytes, 456, 32); + output.CopyFrom(_headerBytes, 438, 32); output.CopyFromAscii(value); } } } - tempBits &= ~2147483648L; - if(tempBits == 0) + if((tempBits & ~1073741824L) == 0) { return; } + tempBits &= ~1073741824L; } - - if (((_bits & 4294967296L) != 0)) + if ((tempBits & 2147483648L) != 0) { { var valueCount = _headers._AccessControlAllowMethods.Count; @@ -10622,20 +8450,19 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var value = _headers._AccessControlAllowMethods[i]; if (value != null) { - output.CopyFrom(_headerBytes, 488, 32); + output.CopyFrom(_headerBytes, 470, 32); output.CopyFromAscii(value); } } } - tempBits &= ~4294967296L; - if(tempBits == 0) + if((tempBits & ~2147483648L) == 0) { return; } + tempBits &= ~2147483648L; } - - if (((_bits & 8589934592L) != 0)) + if ((tempBits & 4294967296L) != 0) { { var valueCount = _headers._AccessControlAllowOrigin.Count; @@ -10644,20 +8471,19 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var value = _headers._AccessControlAllowOrigin[i]; if (value != null) { - output.CopyFrom(_headerBytes, 520, 31); + output.CopyFrom(_headerBytes, 502, 31); output.CopyFromAscii(value); } } } - tempBits &= ~8589934592L; - if(tempBits == 0) + if((tempBits & ~4294967296L) == 0) { return; } + tempBits &= ~4294967296L; } - - if (((_bits & 17179869184L) != 0)) + if ((tempBits & 8589934592L) != 0) { { var valueCount = _headers._AccessControlExposeHeaders.Count; @@ -10666,20 +8492,19 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var value = _headers._AccessControlExposeHeaders[i]; if (value != null) { - output.CopyFrom(_headerBytes, 551, 33); + output.CopyFrom(_headerBytes, 533, 33); output.CopyFromAscii(value); } } } - tempBits &= ~17179869184L; - if(tempBits == 0) + if((tempBits & ~8589934592L) == 0) { return; } + tempBits &= ~8589934592L; } - - if (((_bits & 34359738368L) != 0)) + if ((tempBits & 17179869184L) != 0) { { var valueCount = _headers._AccessControlMaxAge.Count; @@ -10688,23 +8513,21 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var value = _headers._AccessControlMaxAge[i]; if (value != null) { - output.CopyFrom(_headerBytes, 584, 26); + output.CopyFrom(_headerBytes, 566, 26); output.CopyFromAscii(value); } } } - tempBits &= ~34359738368L; - if(tempBits == 0) + if((tempBits & ~17179869184L) == 0) { return; } + tempBits &= ~17179869184L; } - } - - + private struct HeaderReferences { public StringValues _CacheControl; @@ -10718,7 +8541,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http public StringValues _Via; public StringValues _Warning; public StringValues _Allow; - public StringValues _ContentLength; public StringValues _ContentType; public StringValues _ContentEncoding; public StringValues _ContentLanguage; @@ -10747,7 +8569,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http public byte[] _rawConnection; public byte[] _rawDate; public byte[] _rawTransferEncoding; - public byte[] _rawContentLength; public byte[] _rawServer; } @@ -10758,120 +8579,119 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http switch (_state) { - case 0: - goto state0; + case 0: + goto state0; - case 1: - goto state1; + case 1: + goto state1; - case 2: - goto state2; + case 2: + goto state2; - case 3: - goto state3; + case 3: + goto state3; - case 4: - goto state4; + case 4: + goto state4; - case 5: - goto state5; + case 5: + goto state5; - case 6: - goto state6; + case 6: + goto state6; - case 7: - goto state7; + case 7: + goto state7; - case 8: - goto state8; + case 8: + goto state8; - case 9: - goto state9; + case 9: + goto state9; - case 10: - goto state10; + case 10: + goto state10; - case 11: - goto state11; + case 11: + goto state11; - case 12: - goto state12; + case 12: + goto state12; - case 13: - goto state13; + case 13: + goto state13; - case 14: - goto state14; + case 14: + goto state14; - case 15: - goto state15; + case 15: + goto state15; - case 16: - goto state16; + case 16: + goto state16; - case 17: - goto state17; + case 17: + goto state17; - case 18: - goto state18; + case 18: + goto state18; - case 19: - goto state19; + case 19: + goto state19; - case 20: - goto state20; + case 20: + goto state20; - case 21: - goto state21; + case 21: + goto state21; - case 22: - goto state22; + case 22: + goto state22; - case 23: - goto state23; + case 23: + goto state23; - case 24: - goto state24; + case 24: + goto state24; - case 25: - goto state25; + case 25: + goto state25; - case 26: - goto state26; + case 26: + goto state26; - case 27: - goto state27; + case 27: + goto state27; - case 28: - goto state28; + case 28: + goto state28; - case 29: - goto state29; + case 29: + goto state29; - case 30: - goto state30; + case 30: + goto state30; - case 31: - goto state31; + case 31: + goto state31; - case 32: - goto state32; + case 32: + goto state32; - case 33: - goto state33; + case 33: + goto state33; - case 34: - goto state34; - - case 35: - goto state35; + case 34: + goto state34; + case 36: + goto state36; default: goto state_default; } state0: - if (((_bits & 1L) != 0)) + if ((_bits & 1L) != 0) { _current = new KeyValuePair("Cache-Control", _collection._headers._CacheControl); _state = 1; @@ -10879,7 +8699,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } state1: - if (((_bits & 2L) != 0)) + if ((_bits & 2L) != 0) { _current = new KeyValuePair("Connection", _collection._headers._Connection); _state = 2; @@ -10887,7 +8707,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } state2: - if (((_bits & 4L) != 0)) + if ((_bits & 4L) != 0) { _current = new KeyValuePair("Date", _collection._headers._Date); _state = 3; @@ -10895,7 +8715,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } state3: - if (((_bits & 8L) != 0)) + if ((_bits & 8L) != 0) { _current = new KeyValuePair("Keep-Alive", _collection._headers._KeepAlive); _state = 4; @@ -10903,7 +8723,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } state4: - if (((_bits & 16L) != 0)) + if ((_bits & 16L) != 0) { _current = new KeyValuePair("Pragma", _collection._headers._Pragma); _state = 5; @@ -10911,7 +8731,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } state5: - if (((_bits & 32L) != 0)) + if ((_bits & 32L) != 0) { _current = new KeyValuePair("Trailer", _collection._headers._Trailer); _state = 6; @@ -10919,7 +8739,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } state6: - if (((_bits & 64L) != 0)) + if ((_bits & 64L) != 0) { _current = new KeyValuePair("Transfer-Encoding", _collection._headers._TransferEncoding); _state = 7; @@ -10927,7 +8747,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } state7: - if (((_bits & 128L) != 0)) + if ((_bits & 128L) != 0) { _current = new KeyValuePair("Upgrade", _collection._headers._Upgrade); _state = 8; @@ -10935,7 +8755,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } state8: - if (((_bits & 256L) != 0)) + if ((_bits & 256L) != 0) { _current = new KeyValuePair("Via", _collection._headers._Via); _state = 9; @@ -10943,7 +8763,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } state9: - if (((_bits & 512L) != 0)) + if ((_bits & 512L) != 0) { _current = new KeyValuePair("Warning", _collection._headers._Warning); _state = 10; @@ -10951,7 +8771,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } state10: - if (((_bits & 1024L) != 0)) + if ((_bits & 1024L) != 0) { _current = new KeyValuePair("Allow", _collection._headers._Allow); _state = 11; @@ -10959,205 +8779,204 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } state11: - if (((_bits & 2048L) != 0)) + if ((_bits & 2048L) != 0) { - _current = new KeyValuePair("Content-Length", _collection._headers._ContentLength); + _current = new KeyValuePair("Content-Type", _collection._headers._ContentType); _state = 12; return true; } state12: - if (((_bits & 4096L) != 0)) + if ((_bits & 4096L) != 0) { - _current = new KeyValuePair("Content-Type", _collection._headers._ContentType); + _current = new KeyValuePair("Content-Encoding", _collection._headers._ContentEncoding); _state = 13; return true; } state13: - if (((_bits & 8192L) != 0)) + if ((_bits & 8192L) != 0) { - _current = new KeyValuePair("Content-Encoding", _collection._headers._ContentEncoding); + _current = new KeyValuePair("Content-Language", _collection._headers._ContentLanguage); _state = 14; return true; } state14: - if (((_bits & 16384L) != 0)) + if ((_bits & 16384L) != 0) { - _current = new KeyValuePair("Content-Language", _collection._headers._ContentLanguage); + _current = new KeyValuePair("Content-Location", _collection._headers._ContentLocation); _state = 15; return true; } state15: - if (((_bits & 32768L) != 0)) + if ((_bits & 32768L) != 0) { - _current = new KeyValuePair("Content-Location", _collection._headers._ContentLocation); + _current = new KeyValuePair("Content-MD5", _collection._headers._ContentMD5); _state = 16; return true; } state16: - if (((_bits & 65536L) != 0)) + if ((_bits & 65536L) != 0) { - _current = new KeyValuePair("Content-MD5", _collection._headers._ContentMD5); + _current = new KeyValuePair("Content-Range", _collection._headers._ContentRange); _state = 17; return true; } state17: - if (((_bits & 131072L) != 0)) + if ((_bits & 131072L) != 0) { - _current = new KeyValuePair("Content-Range", _collection._headers._ContentRange); + _current = new KeyValuePair("Expires", _collection._headers._Expires); _state = 18; return true; } state18: - if (((_bits & 262144L) != 0)) + if ((_bits & 262144L) != 0) { - _current = new KeyValuePair("Expires", _collection._headers._Expires); + _current = new KeyValuePair("Last-Modified", _collection._headers._LastModified); _state = 19; return true; } state19: - if (((_bits & 524288L) != 0)) + if ((_bits & 524288L) != 0) { - _current = new KeyValuePair("Last-Modified", _collection._headers._LastModified); + _current = new KeyValuePair("Accept-Ranges", _collection._headers._AcceptRanges); _state = 20; return true; } state20: - if (((_bits & 1048576L) != 0)) + if ((_bits & 1048576L) != 0) { - _current = new KeyValuePair("Accept-Ranges", _collection._headers._AcceptRanges); + _current = new KeyValuePair("Age", _collection._headers._Age); _state = 21; return true; } state21: - if (((_bits & 2097152L) != 0)) + if ((_bits & 2097152L) != 0) { - _current = new KeyValuePair("Age", _collection._headers._Age); + _current = new KeyValuePair("ETag", _collection._headers._ETag); _state = 22; return true; } state22: - if (((_bits & 4194304L) != 0)) + if ((_bits & 4194304L) != 0) { - _current = new KeyValuePair("ETag", _collection._headers._ETag); + _current = new KeyValuePair("Location", _collection._headers._Location); _state = 23; return true; } state23: - if (((_bits & 8388608L) != 0)) + if ((_bits & 8388608L) != 0) { - _current = new KeyValuePair("Location", _collection._headers._Location); + _current = new KeyValuePair("Proxy-Authenticate", _collection._headers._ProxyAuthenticate); _state = 24; return true; } state24: - if (((_bits & 16777216L) != 0)) + if ((_bits & 16777216L) != 0) { - _current = new KeyValuePair("Proxy-Authenticate", _collection._headers._ProxyAuthenticate); + _current = new KeyValuePair("Retry-After", _collection._headers._RetryAfter); _state = 25; return true; } state25: - if (((_bits & 33554432L) != 0)) + if ((_bits & 33554432L) != 0) { - _current = new KeyValuePair("Retry-After", _collection._headers._RetryAfter); + _current = new KeyValuePair("Server", _collection._headers._Server); _state = 26; return true; } state26: - if (((_bits & 67108864L) != 0)) + if ((_bits & 67108864L) != 0) { - _current = new KeyValuePair("Server", _collection._headers._Server); + _current = new KeyValuePair("Set-Cookie", _collection._headers._SetCookie); _state = 27; return true; } state27: - if (((_bits & 134217728L) != 0)) + if ((_bits & 134217728L) != 0) { - _current = new KeyValuePair("Set-Cookie", _collection._headers._SetCookie); + _current = new KeyValuePair("Vary", _collection._headers._Vary); _state = 28; return true; } state28: - if (((_bits & 268435456L) != 0)) + if ((_bits & 268435456L) != 0) { - _current = new KeyValuePair("Vary", _collection._headers._Vary); + _current = new KeyValuePair("WWW-Authenticate", _collection._headers._WWWAuthenticate); _state = 29; return true; } state29: - if (((_bits & 536870912L) != 0)) + if ((_bits & 536870912L) != 0) { - _current = new KeyValuePair("WWW-Authenticate", _collection._headers._WWWAuthenticate); + _current = new KeyValuePair("Access-Control-Allow-Credentials", _collection._headers._AccessControlAllowCredentials); _state = 30; return true; } state30: - if (((_bits & 1073741824L) != 0)) + if ((_bits & 1073741824L) != 0) { - _current = new KeyValuePair("Access-Control-Allow-Credentials", _collection._headers._AccessControlAllowCredentials); + _current = new KeyValuePair("Access-Control-Allow-Headers", _collection._headers._AccessControlAllowHeaders); _state = 31; return true; } state31: - if (((_bits & 2147483648L) != 0)) + if ((_bits & 2147483648L) != 0) { - _current = new KeyValuePair("Access-Control-Allow-Headers", _collection._headers._AccessControlAllowHeaders); + _current = new KeyValuePair("Access-Control-Allow-Methods", _collection._headers._AccessControlAllowMethods); _state = 32; return true; } state32: - if (((_bits & 4294967296L) != 0)) + if ((_bits & 4294967296L) != 0) { - _current = new KeyValuePair("Access-Control-Allow-Methods", _collection._headers._AccessControlAllowMethods); + _current = new KeyValuePair("Access-Control-Allow-Origin", _collection._headers._AccessControlAllowOrigin); _state = 33; return true; } state33: - if (((_bits & 8589934592L) != 0)) + if ((_bits & 8589934592L) != 0) { - _current = new KeyValuePair("Access-Control-Allow-Origin", _collection._headers._AccessControlAllowOrigin); + _current = new KeyValuePair("Access-Control-Expose-Headers", _collection._headers._AccessControlExposeHeaders); _state = 34; return true; } state34: - if (((_bits & 17179869184L) != 0)) + if ((_bits & 17179869184L) != 0) { - _current = new KeyValuePair("Access-Control-Expose-Headers", _collection._headers._AccessControlExposeHeaders); + _current = new KeyValuePair("Access-Control-Max-Age", _collection._headers._AccessControlMaxAge); _state = 35; return true; } - state35: - if (((_bits & 34359738368L) != 0)) + state36: + if (_collection._contentLength.HasValue) { - _current = new KeyValuePair("Access-Control-Max-Age", _collection._headers._AccessControlMaxAge); - _state = 36; + _current = new KeyValuePair("Content-Length", HeaderUtilities.FormatInt64(_collection._contentLength.Value)); + _state = 37; return true; } - state_default: if (!_hasUnknown || !_unknownEnumerator.MoveNext()) { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameHeaders.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameHeaders.cs index 4cb77a2783..312fc0dfd7 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameHeaders.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameHeaders.cs @@ -5,19 +5,32 @@ using System; using System.Collections; using System.Collections.Generic; using System.Linq; +using System.Runtime.CompilerServices; using Microsoft.AspNetCore.Http; using Microsoft.Extensions.Primitives; -using Microsoft.Net.Http.Headers; namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { public abstract class FrameHeaders : IHeaderDictionary { + protected long? _contentLength; protected bool _isReadOnly; protected Dictionary MaybeUnknown; - protected Dictionary Unknown => MaybeUnknown ?? (MaybeUnknown = new Dictionary(StringComparer.OrdinalIgnoreCase)); + public long? ContentLength + { + get { return _contentLength; } + set + { + if (value.HasValue && value.Value < 0) + { + ThrowInvalidContentLengthException(value.Value); + } + _contentLength = value; + } + } + StringValues IHeaderDictionary.this[string key] { get @@ -41,7 +54,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http get { // Unlike the IHeaderDictionary version, this getter will throw a KeyNotFoundException. - return GetValueFast(key); + StringValues value; + if (!TryGetValueFast(key, out value)) + { + ThrowKeyNotFoundException(); + } + return value; } set { @@ -88,6 +106,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http ClearFast(); } + [MethodImpl(MethodImplOptions.NoInlining)] protected static StringValues AppendValue(StringValues existing, string append) { return StringValues.Concat(existing, append); @@ -112,16 +131,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http protected virtual int GetCountFast() { throw new NotImplementedException(); } - protected virtual StringValues GetValueFast(string key) - { throw new NotImplementedException(); } - protected virtual bool TryGetValueFast(string key, out StringValues value) { throw new NotImplementedException(); } protected virtual void SetValueFast(string key, StringValues value) { throw new NotImplementedException(); } - protected virtual void AddValueFast(string key, StringValues value) + protected virtual bool AddValueFast(string key, StringValues value) { throw new NotImplementedException(); } protected virtual bool RemoveFast(string key) @@ -130,7 +146,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http protected virtual void ClearFast() { throw new NotImplementedException(); } - protected virtual void CopyToFast(KeyValuePair[] array, int arrayIndex) + protected virtual bool CopyToFast(KeyValuePair[] array, int arrayIndex) { throw new NotImplementedException(); } protected virtual IEnumerator> GetEnumeratorFast() @@ -147,7 +163,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { ThrowHeadersReadOnlyException(); } - AddValueFast(key, value); + + if (!AddValueFast(key, value)) + { + ThrowDuplicateKeyException(); + } } void ICollection>.Clear() @@ -175,7 +195,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http void ICollection>.CopyTo(KeyValuePair[] array, int arrayIndex) { - CopyToFast(array, arrayIndex); + if (!CopyToFast(array, arrayIndex)) + { + ThrowArgumentException(); + } } IEnumerator IEnumerable.GetEnumerator() @@ -235,17 +258,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } } - public static long ParseContentLength(StringValues value) - { - long parsed; - if (!HeaderUtilities.TryParseInt64(value.ToString(), out parsed)) - { - ThrowInvalidContentLengthException(value); - } - - return parsed; - } - public static unsafe ConnectionOptions ParseConnection(StringValues connection) { var connectionOptions = ConnectionOptions.None; @@ -412,9 +424,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http return transferEncodingOptions; } - private static void ThrowInvalidContentLengthException(string value) + private static void ThrowInvalidContentLengthException(long value) { - throw new InvalidOperationException($"Invalid Content-Length: \"{value}\". Value must be a positive integral number."); + throw new ArgumentOutOfRangeException($"Invalid Content-Length: \"{value}\". Value must be a positive integral number."); } private static void ThrowInvalidHeaderCharacter(char ch) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameRequestHeaders.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameRequestHeaders.cs index 7d24bf3d8e..4dd46d5cf1 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameRequestHeaders.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameRequestHeaders.cs @@ -3,12 +3,59 @@ using System.Collections; using System.Collections.Generic; +using System.Runtime.CompilerServices; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.Extensions.Primitives; +using Microsoft.Net.Http.Headers; namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { public partial class FrameRequestHeaders : FrameHeaders { + private static long ParseContentLength(string value) + { + long parsed; + if (!HeaderUtilities.TryParseInt64(value, out parsed)) + { + ThrowInvalidContentLengthException(value); + } + + return parsed; + } + + [MethodImpl(MethodImplOptions.NoInlining)] + private void SetValueUnknown(string key, StringValues value) + { + Unknown[key] = value; + } + + [MethodImpl(MethodImplOptions.NoInlining)] + private unsafe void AppendUnknownHeaders(byte* pKeyBytes, int keyLength, string value) + { + string key = new string('\0', keyLength); + fixed (char* keyBuffer = key) + { + if (!AsciiUtilities.TryGetAsciiString(pKeyBytes, keyBuffer, keyLength)) + { + throw BadHttpRequestException.GetException(RequestRejectionReason.InvalidCharactersInHeaderName); + } + } + + StringValues existing; + Unknown.TryGetValue(key, out existing); + Unknown[key] = AppendValue(existing, value); + } + + private static void ThrowInvalidContentLengthException(string value) + { + throw BadHttpRequestException.GetException(RequestRejectionReason.InvalidContentLength, value); + } + + private static void ThrowMultipleContentLengthsException() + { + throw BadHttpRequestException.GetException(RequestRejectionReason.MultipleContentLengths); + } + public Enumerator GetEnumerator() { return new Enumerator(this); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameResponseHeaders.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameResponseHeaders.cs index ccb5e0d463..4666041dd9 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameResponseHeaders.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameResponseHeaders.cs @@ -1,10 +1,13 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; using System.Collections; using System.Collections.Generic; +using System.Runtime.CompilerServices; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.Extensions.Primitives; +using Microsoft.Net.Http.Headers; namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { @@ -13,20 +16,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http private static readonly byte[] _CrLf = new[] { (byte)'\r', (byte)'\n' }; private static readonly byte[] _colonSpace = new[] { (byte)':', (byte)' ' }; - private long? _contentLength; - public bool HasConnection => HeaderConnection.Count != 0; public bool HasTransferEncoding => HeaderTransferEncoding.Count != 0; - public bool HasContentLength => HeaderContentLength.Count != 0; - public bool HasServer => HeaderServer.Count != 0; public bool HasDate => HeaderDate.Count != 0; - public long? HeaderContentLengthValue => _contentLength; - public Enumerator GetEnumerator() { return new Enumerator(this); @@ -58,6 +55,29 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } } + private static long ParseContentLength(string value) + { + long parsed; + if (!HeaderUtilities.TryParseInt64(value, out parsed)) + { + ThrowInvalidContentLengthException(value); + } + + return parsed; + } + + [MethodImpl(MethodImplOptions.NoInlining)] + private void SetValueUnknown(string key, StringValues value) + { + ValidateHeaderCharacters(key); + Unknown[key] = value; + } + + private static void ThrowInvalidContentLengthException(string value) + { + throw new InvalidOperationException($"Invalid Content-Length: \"{value}\". Value must be a positive integral number."); + } + public partial struct Enumerator : IEnumerator> { private readonly FrameResponseHeaders _collection; @@ -92,5 +112,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _state = 0; } } + } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/MessageBody.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/MessageBody.cs index 50cb468741..99b10d1b47 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/MessageBody.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/MessageBody.cs @@ -8,12 +8,14 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.Extensions.Internal; -using Microsoft.Extensions.Primitives; namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { public abstract class MessageBody { + private static readonly MessageBody _zeroContentLengthClose = new ForZeroContentLength(keepAlive: false); + private static readonly MessageBody _zeroContentLengthKeepAlive = new ForZeroContentLength(keepAlive: true); + private readonly Frame _context; private bool _send100Continue = true; @@ -266,18 +268,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http return new ForChunkedEncoding(keepAlive, headers, context); } - var unparsedContentLength = headers.HeaderContentLength; - if (unparsedContentLength.Count > 0) + if (headers.ContentLength.HasValue) { - try + var contentLength = headers.ContentLength.Value; + if (contentLength == 0) { - var contentLength = FrameHeaders.ParseContentLength(unparsedContentLength); - return new ForContentLength(keepAlive, contentLength, context); - } - catch (InvalidOperationException) - { - context.RejectRequest(RequestRejectionReason.InvalidContentLength, unparsedContentLength); + return keepAlive ? _zeroContentLengthKeepAlive : _zeroContentLengthClose; } + + return new ForContentLength(keepAlive, contentLength, context); } // Avoid slowing down most common case @@ -292,7 +291,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } } - return new ForContentLength(keepAlive, 0, context); + return keepAlive ? _zeroContentLengthKeepAlive : _zeroContentLengthClose; } private class ForRemainingData : MessageBody @@ -309,6 +308,28 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } } + private class ForZeroContentLength : MessageBody + { + public ForZeroContentLength(bool keepAlive) + : base(null) + { + RequestKeepAlive = keepAlive; + } + + protected override ValueTask> PeekAsync(CancellationToken cancellationToken) + { + return new ValueTask>(); + } + + protected override void OnConsumedBytes(int count) + { + if (count > 0) + { + throw new InvalidDataException("Consuming non-existent data"); + } + } + } + private class ForContentLength : MessageBody { private readonly long _contentLength; diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/RequestRejectionReason.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/RequestRejectionReason.cs index 0c05a6b8ea..caa6475d9a 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/RequestRejectionReason.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/RequestRejectionReason.cs @@ -15,6 +15,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http InvalidRequestLine, MalformedRequestInvalidHeaders, InvalidContentLength, + MultipleContentLengths, UnexpectedEndOfRequestContent, BadChunkSuffix, BadChunkSizeData, diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolIterator.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolIterator.cs index b1b45eb6e8..07491b7377 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolIterator.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolIterator.cs @@ -13,6 +13,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure { public struct MemoryPoolIterator { + private const int _maxULongByteLength = 20; private const ulong _xorPowerOfTwoToHighByte = (0x07ul | 0x06ul << 8 | 0x05ul << 16 | @@ -23,6 +24,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure private static readonly int _vectorSpan = Vector.Count; + [ThreadStatic] + private static byte[] _numericBytesScratch; + private MemoryPoolBlock _block; private int _index; @@ -1082,6 +1086,101 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure _index = blockIndex; } + private static byte[] NumericBytesScratch => _numericBytesScratch ?? CreateNumericBytesScratch(); + + [MethodImpl(MethodImplOptions.NoInlining)] + private static byte[] CreateNumericBytesScratch() + { + var bytes = new byte[_maxULongByteLength]; + _numericBytesScratch = bytes; + return bytes; + } + + public unsafe void CopyFromNumeric(ulong value) + { + const byte AsciiDigitStart = (byte)'0'; + + var block = _block; + if (block == null) + { + return; + } + + var blockIndex = _index; + var bytesLeftInBlock = block.Data.Offset + block.Data.Count - blockIndex; + var start = block.DataFixedPtr + blockIndex; + + if (value < 10) + { + if (bytesLeftInBlock < 1) + { + CopyFromNumericOverflow(value); + return; + } + _index = blockIndex + 1; + block.End = blockIndex + 1; + + *(start) = (byte)(((uint)value) + AsciiDigitStart); + } + else if (value < 100) + { + if (bytesLeftInBlock < 2) + { + CopyFromNumericOverflow(value); + return; + } + _index = blockIndex + 2; + block.End = blockIndex + 2; + + var val = (uint)value; + var tens = (byte)((val * 205u) >> 11); // div10, valid to 1028 + + *(start) = (byte)(tens + AsciiDigitStart); + *(start + 1) = (byte)(val - (tens * 10) + AsciiDigitStart); + } + else if (value < 1000) + { + if (bytesLeftInBlock < 3) + { + CopyFromNumericOverflow(value); + return; + } + _index = blockIndex + 3; + block.End = blockIndex + 3; + + var val = (uint)value; + var digit0 = (byte)((val * 41u) >> 12); // div100, valid to 1098 + var digits01 = (byte)((val * 205u) >> 11); // div10, valid to 1028 + + *(start) = (byte)(digit0 + AsciiDigitStart); + *(start + 1) = (byte)(digits01 - (digit0 * 10) + AsciiDigitStart); + *(start + 2) = (byte)(val - (digits01 * 10) + AsciiDigitStart); + } + else + { + CopyFromNumericOverflow(value); + } + } + + [MethodImpl(MethodImplOptions.NoInlining)] + private unsafe void CopyFromNumericOverflow(ulong value) + { + const byte AsciiDigitStart = (byte)'0'; + + var position = _maxULongByteLength; + var byteBuffer = NumericBytesScratch; + do + { + // Consider using Math.DivRem() if available + var quotient = value / 10; + byteBuffer[--position] = (byte)(AsciiDigitStart + (value - quotient * 10)); // 0x30 = '0' + value = quotient; + } + while (value != 0); + + CopyFrom(byteBuffer, position, _maxULongByteLength - position); + } + public unsafe string GetAsciiString(ref MemoryPoolIterator end) { var block = _block; @@ -1253,6 +1352,5 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure // https://github.com/dotnet/coreclr/issues/7459#issuecomment-253965670 return Vector.AsVectorByte(new Vector(vectorByte * 0x01010101u)); } - } } diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/ResponseHeaders.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/ResponseHeaders.cs new file mode 100644 index 0000000000..a8dcf79468 --- /dev/null +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/ResponseHeaders.cs @@ -0,0 +1,209 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using BenchmarkDotNet.Attributes; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; +using Microsoft.AspNetCore.Testing; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Http.Internal; +using System.Runtime.CompilerServices; +using System.Text; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; + +namespace Microsoft.AspNetCore.Server.Kestrel.Performance +{ + [Config(typeof(CoreConfig))] + public class ResponseHeaders + { + private const int InnerLoopCount = 512; + + private static readonly byte[] _bytesServer = Encoding.ASCII.GetBytes("\r\nServer: Kestrel"); + private static readonly DateHeaderValueManager _dateHeaderValueManager = new DateHeaderValueManager(); + private static readonly MemoryPool _memoryPool = new MemoryPool(); + private FrameResponseHeaders _responseHeadersDirect; + private HttpResponse _response; + + [Params("ContentLengthNumeric", "ContentLengthString", "Plaintext", "Common", "Unknown")] + public string Type { get; set; } + + [Benchmark(OperationsPerInvoke = InnerLoopCount)] + public void SetHeaders() + { + switch (Type) + { + case "ContentLengthNumeric": + ContentLengthNumeric(InnerLoopCount); + break; + case "ContentLengthString": + ContentLengthString(InnerLoopCount); + break; + case "Plaintext": + Plaintext(InnerLoopCount); + break; + case "Common": + Common(InnerLoopCount); + break; + case "Unknown": + Unknown(InnerLoopCount); + break; + } + } + + [Benchmark(OperationsPerInvoke = InnerLoopCount)] + public void OutputHeaders() + { + for (var i = 0; i < InnerLoopCount; i++) + { + var block = _memoryPool.Lease(); + var iter = new MemoryPoolIterator(block); + _responseHeadersDirect.CopyTo(ref iter); + + ReturnBlocks(block); + } + } + + [MethodImpl(MethodImplOptions.NoInlining)] + private void ContentLengthNumeric(int count) + { + for (var i = 0; i < count; i++) + { + _responseHeadersDirect.Reset(); + + _response.ContentLength = 0; + } + } + + [MethodImpl(MethodImplOptions.NoInlining)] + private void ContentLengthString(int count) + { + for (var i = 0; i < count; i++) + { + _responseHeadersDirect.Reset(); + + _response.Headers["Content-Length"] = "0"; + } + } + + [MethodImpl(MethodImplOptions.NoInlining)] + private void Plaintext(int count) + { + for (var i = 0; i < count; i++) + { + _responseHeadersDirect.Reset(); + + _response.StatusCode = 200; + _response.ContentType = "text/plain"; + _response.ContentLength = 13; + + var dateHeaderValues = _dateHeaderValueManager.GetDateHeaderValues(); + _responseHeadersDirect.SetRawDate(dateHeaderValues.String, dateHeaderValues.Bytes); + _responseHeadersDirect.SetRawServer("Kestrel", _bytesServer); + } + } + + [MethodImpl(MethodImplOptions.NoInlining)] + private void Common(int count) + { + for (var i = 0; i < count; i++) + { + _responseHeadersDirect.Reset(); + + _response.StatusCode = 200; + _response.ContentType = "text/css"; + _response.ContentLength = 421; + + var headers = _response.Headers; + + headers["Connection"] = "Close"; + headers["Cache-Control"] = "public, max-age=30672000"; + headers["Vary"] = "Accept-Encoding"; + headers["Content-Encoding"] = "gzip"; + headers["Expires"] = "Fri, 12 Jan 2018 22:01:55 GMT"; + headers["Last-Modified"] = "Wed, 22 Jun 2016 20:08:29 GMT"; + headers["Set-Cookie"] = "prov=20629ccd-8b0f-e8ef-2935-cd26609fc0bc; __qca=P0-1591065732-1479167353442; _ga=GA1.2.1298898376.1479167354; _gat=1; sgt=id=9519gfde_3347_4762_8762_df51458c8ec2; acct=t=why-is-%e0%a5%a7%e0%a5%a8%e0%a5%a9-numeric&s=why-is-%e0%a5%a7%e0%a5%a8%e0%a5%a9-numeric"; + headers["ETag"] = "\"54ef7954-1078\""; + headers["Transfer-Encoding"] = "chunked"; + headers["Content-Language"] = "en-gb"; + headers["Upgrade"] = "websocket"; + headers["Via"] = "1.1 varnish"; + headers["Access-Control-Allow-Origin"] = "*"; + headers["Access-Control-Allow-credentials"] = "true"; + headers["Access-Control-Expose-Headers"] = "Client-Protocol, Content-Length, Content-Type, X-Bandwidth-Est, X-Bandwidth-Est2, X-Bandwidth-Est-Comp, X-Bandwidth-Avg, X-Walltime-Ms, X-Sequence-Num"; + + var dateHeaderValues = _dateHeaderValueManager.GetDateHeaderValues(); + _responseHeadersDirect.SetRawDate(dateHeaderValues.String, dateHeaderValues.Bytes); + _responseHeadersDirect.SetRawServer("Kestrel", _bytesServer); + } + } + + [MethodImpl(MethodImplOptions.NoInlining)] + private void Unknown(int count) + { + for (var i = 0; i < count; i++) + { + _responseHeadersDirect.Reset(); + + _response.StatusCode = 200; + _response.ContentType = "text/plain"; + _response.ContentLength = 13; + + var headers = _response.Headers; + + headers["Link"] = "; rel=\"canonical\""; + headers["X-Ua-Compatible"] = "IE=Edge"; + headers["X-Powered-By"] = "ASP.NET"; + headers["X-Content-Type-Options"] = "nosniff"; + headers["X-Xss-Protection"] = "1; mode=block"; + headers["X-Frame-Options"] = "SAMEORIGIN"; + headers["Strict-Transport-Security"] = "max-age=31536000; includeSubDomains; preload"; + headers["Content-Security-Policy"] = "default-src 'none'; script-src 'self' cdnjs.cloudflare.com code.jquery.com scotthelme.disqus.com a.disquscdn.com www.google-analytics.com go.disqus.com platform.twitter.com cdn.syndication.twimg.com; style-src 'self' a.disquscdn.com fonts.googleapis.com cdnjs.cloudflare.com platform.twitter.com; img-src 'self' data: www.gravatar.com www.google-analytics.com links.services.disqus.com referrer.disqus.com a.disquscdn.com cdn.syndication.twimg.com syndication.twitter.com pbs.twimg.com platform.twitter.com abs.twimg.com; child-src fusiontables.googleusercontent.com fusiontables.google.com www.google.com disqus.com www.youtube.com syndication.twitter.com platform.twitter.com; frame-src fusiontables.googleusercontent.com fusiontables.google.com www.google.com disqus.com www.youtube.com syndication.twitter.com platform.twitter.com; connect-src 'self' links.services.disqus.com; font-src 'self' cdnjs.cloudflare.com fonts.gstatic.com fonts.googleapis.com; form-action 'self'; upgrade-insecure-requests;"; + + var dateHeaderValues = _dateHeaderValueManager.GetDateHeaderValues(); + _responseHeadersDirect.SetRawDate(dateHeaderValues.String, dateHeaderValues.Bytes); + _responseHeadersDirect.SetRawServer("Kestrel", _bytesServer); + } + } + + [Setup] + public void Setup() + { + var connectionContext = new MockConnection(new KestrelServerOptions()); + var frame = new Frame(application: null, context: connectionContext); + frame.Reset(); + frame.InitializeHeaders(); + _responseHeadersDirect = (FrameResponseHeaders)frame.ResponseHeaders; + var context = new DefaultHttpContext(frame); + _response = new DefaultHttpResponse(context); + + switch (Type) + { + case "ContentLengthNumeric": + ContentLengthNumeric(1); + break; + case "ContentLengthString": + ContentLengthString(1); + break; + case "Plaintext": + Plaintext(1); + break; + case "Common": + Common(1); + break; + case "Unknown": + Unknown(1); + break; + } + } + + private static void ReturnBlocks(MemoryPoolBlock block) + { + while (block != null) + { + var returningBlock = block; + block = returningBlock.Next; + + returningBlock.Pool.Return(returningBlock); + } + } + } +} diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/columns/RpsColumn.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/columns/RpsColumn.cs index 12e9969ed2..9727e7110d 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/columns/RpsColumn.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/columns/RpsColumn.cs @@ -15,7 +15,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance public string GetValue(Summary summary, Benchmark benchmark) { - var totalNanos = summary.Reports.First(r => r.Benchmark == benchmark).ResultStatistics.Mean; + var totalNanos = summary.Reports.First(r => r.Benchmark == benchmark)?.ResultStatistics?.Mean ?? 0; // Make sure we don't divide by zero!! return Math.Abs(totalNanos) > 0.0 ? (NanosPerSecond / totalNanos).ToString("N2") : "N/A"; } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/BadHttpRequestTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/BadHttpRequestTests.cs index b211578da5..ab681e5467 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/BadHttpRequestTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/BadHttpRequestTests.cs @@ -202,6 +202,21 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } } + [Theory] + [InlineData("NaN")] + [InlineData("-1")] + public async Task BadRequestIfContentLengthInvalid(string contentLength) + { + using (var server = new TestServer(context => { return Task.FromResult(0); })) + { + using (var connection = server.CreateConnection()) + { + await connection.Send($"GET / HTTP/1.1\r\nContent-Length: {contentLength}\r\n\r\n"); + await ReceiveBadRequestResponse(connection, "400 Bad Request", server.Context.DateHeaderValue); + } + } + } + private async Task ReceiveBadRequestResponse(TestConnection connection, string expectedResponseStatusCode, string expectedDateHeaderValue) { await connection.ReceiveForcedEnd( diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/DefaultHeaderTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/DefaultHeaderTests.cs index b8a843f738..2493387b9b 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/DefaultHeaderTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/DefaultHeaderTests.cs @@ -32,14 +32,14 @@ namespace Microsoft.AspNetCore.Server.KestrelTests await connection.ReceiveEnd( "HTTP/1.1 200 OK", $"Date: {testContext.DateHeaderValue}", - "Content-Length: 0", "Server: Kestrel", + "Content-Length: 0", "", "HTTP/1.1 200 OK", "Connection: close", $"Date: {testContext.DateHeaderValue}", - "Content-Length: 0", "Server: Kestrel", + "Content-Length: 0", "", ""); } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameHeadersTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameHeadersTests.cs index 6e41b778e2..83856879ad 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameHeadersTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameHeadersTests.cs @@ -1,8 +1,11 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; +using System.Collections.Generic; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; using Microsoft.Extensions.Primitives; +using Microsoft.Net.Http.Headers; using Xunit; namespace Microsoft.AspNetCore.Server.KestrelTests @@ -223,5 +226,65 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var transferEncodingOptions = FrameHeaders.GetFinalTransferCoding(transferEncoding); Assert.Equal(expectedTransferEncodingOptions, transferEncodingOptions); } + + [Fact] + public void ValidContentLengthsAccepted() + { + ValidContentLengthsAccepted(new FrameRequestHeaders()); + ValidContentLengthsAccepted(new FrameResponseHeaders()); + } + + private static void ValidContentLengthsAccepted(FrameHeaders frameHeaders) + { + IDictionary headers = frameHeaders; + + StringValues value; + + Assert.False(headers.TryGetValue("Content-Length", out value)); + Assert.Equal(null, frameHeaders.ContentLength); + Assert.False(frameHeaders.ContentLength.HasValue); + + frameHeaders.ContentLength = 1; + Assert.True(headers.TryGetValue("Content-Length", out value)); + Assert.Equal("1", value[0]); + Assert.Equal(1, frameHeaders.ContentLength); + Assert.True(frameHeaders.ContentLength.HasValue); + + frameHeaders.ContentLength = long.MaxValue; + Assert.True(headers.TryGetValue("Content-Length", out value)); + Assert.Equal(HeaderUtilities.FormatInt64(long.MaxValue), value[0]); + Assert.Equal(long.MaxValue, frameHeaders.ContentLength); + Assert.True(frameHeaders.ContentLength.HasValue); + + frameHeaders.ContentLength = null; + Assert.False(headers.TryGetValue("Content-Length", out value)); + Assert.Equal(null, frameHeaders.ContentLength); + Assert.False(frameHeaders.ContentLength.HasValue); + } + + [Fact] + public void InvalidContentLengthsRejected() + { + InvalidContentLengthsRejected(new FrameRequestHeaders()); + InvalidContentLengthsRejected(new FrameResponseHeaders()); + } + + private static void InvalidContentLengthsRejected(FrameHeaders frameHeaders) + { + IDictionary headers = frameHeaders; + + StringValues value; + + Assert.False(headers.TryGetValue("Content-Length", out value)); + Assert.Equal(null, frameHeaders.ContentLength); + Assert.False(frameHeaders.ContentLength.HasValue); + + Assert.Throws(() => frameHeaders.ContentLength = -1); + Assert.Throws(() => frameHeaders.ContentLength = long.MinValue); + + Assert.False(headers.TryGetValue("Content-Length", out value)); + Assert.Equal(null, frameHeaders.ContentLength); + Assert.False(frameHeaders.ContentLength.HasValue); + } } } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameRequestHeadersTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameRequestHeadersTests.cs index b19ca07124..91212d627b 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameRequestHeadersTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameRequestHeadersTests.cs @@ -41,10 +41,14 @@ namespace Microsoft.AspNetCore.Server.KestrelTests IDictionary headers = new FrameRequestHeaders(); headers["host"] = new[] { "value" }; + headers["content-length"] = new[] { "0" }; Assert.NotNull(headers["host"]); + Assert.NotNull(headers["content-length"]); Assert.Equal(1, headers["host"].Count); + Assert.Equal(1, headers["content-length"].Count); Assert.Equal("value", headers["host"][0]); + Assert.Equal("0", headers["content-length"][0]); } [Fact] @@ -54,8 +58,9 @@ namespace Microsoft.AspNetCore.Server.KestrelTests headers["host"] = new[] { "value" }; headers["custom"] = new[] { "value" }; + headers["Content-Length"] = new[] { "0" }; - Assert.Equal(2, headers.Count); + Assert.Equal(3, headers.Count); } [Fact] @@ -66,14 +71,22 @@ namespace Microsoft.AspNetCore.Server.KestrelTests StringValues value; Assert.False(headers.TryGetValue("host", out value)); Assert.False(headers.TryGetValue("custom", out value)); + Assert.False(headers.TryGetValue("Content-Length", out value)); headers["host"] = new[] { "value" }; Assert.True(headers.TryGetValue("host", out value)); Assert.False(headers.TryGetValue("custom", out value)); + Assert.False(headers.TryGetValue("Content-Length", out value)); headers["custom"] = new[] { "value" }; Assert.True(headers.TryGetValue("host", out value)); Assert.True(headers.TryGetValue("custom", out value)); + Assert.False(headers.TryGetValue("Content-Length", out value)); + + headers["Content-Length"] = new[] { "0" }; + Assert.True(headers.TryGetValue("host", out value)); + Assert.True(headers.TryGetValue("custom", out value)); + Assert.True(headers.TryGetValue("Content-Length", out value)); } [Fact] @@ -83,6 +96,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests Assert.Throws(() => headers["custom"]); Assert.Throws(() => headers["host"]); + Assert.Throws(() => headers["Content-Length"]); } [Fact] @@ -90,14 +104,17 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { IDictionary headers = new FrameRequestHeaders(); var v1 = new[] { "localhost" }; - var v2 = new[] { "value" }; + var v2 = new[] { "0" }; + var v3 = new[] { "value" }; headers["host"] = v1; - headers["custom"] = v2; + headers["Content-Length"] = v2; + headers["custom"] = v3; Assert.Equal( new[] { new KeyValuePair("Host", v1), - new KeyValuePair("custom", v2), + new KeyValuePair("Content-Length", v2), + new KeyValuePair("custom", v3), }, headers); } @@ -107,16 +124,18 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { IDictionary headers = new FrameRequestHeaders(); StringValues v1 = new[] { "localhost" }; - StringValues v2 = new[] { "value" }; + StringValues v2 = new[] { "0" }; + StringValues v3 = new[] { "value" }; headers["host"] = v1; - headers["custom"] = v2; + headers["Content-Length"] = v2; + headers["custom"] = v3; Assert.Equal( - new[] { "Host", "custom" }, + new[] { "Host", "Content-Length", "custom" }, headers.Keys); Assert.Equal( - new[] { v1, v2 }, + new[] { v1, v2, v3 }, headers.Values); } @@ -126,29 +145,50 @@ namespace Microsoft.AspNetCore.Server.KestrelTests IDictionary headers = new FrameRequestHeaders(); var kv1 = new KeyValuePair("host", new[] { "localhost" }); var kv2 = new KeyValuePair("custom", new[] { "value" }); + var kv3 = new KeyValuePair("Content-Length", new[] { "0" }); var kv1b = new KeyValuePair("host", new[] { "not-localhost" }); var kv2b = new KeyValuePair("custom", new[] { "not-value" }); + var kv3b = new KeyValuePair("Content-Length", new[] { "1" }); Assert.False(headers.ContainsKey("host")); Assert.False(headers.ContainsKey("custom")); + Assert.False(headers.ContainsKey("Content-Length")); Assert.False(headers.Contains(kv1)); Assert.False(headers.Contains(kv2)); + Assert.False(headers.Contains(kv3)); headers["host"] = kv1.Value; Assert.True(headers.ContainsKey("host")); Assert.False(headers.ContainsKey("custom")); + Assert.False(headers.ContainsKey("Content-Length")); Assert.True(headers.Contains(kv1)); Assert.False(headers.Contains(kv2)); + Assert.False(headers.Contains(kv3)); Assert.False(headers.Contains(kv1b)); Assert.False(headers.Contains(kv2b)); + Assert.False(headers.Contains(kv3b)); headers["custom"] = kv2.Value; Assert.True(headers.ContainsKey("host")); Assert.True(headers.ContainsKey("custom")); + Assert.False(headers.ContainsKey("Content-Length")); Assert.True(headers.Contains(kv1)); Assert.True(headers.Contains(kv2)); + Assert.False(headers.Contains(kv3)); Assert.False(headers.Contains(kv1b)); Assert.False(headers.Contains(kv2b)); + Assert.False(headers.Contains(kv3b)); + + headers["Content-Length"] = kv3.Value; + Assert.True(headers.ContainsKey("host")); + Assert.True(headers.ContainsKey("custom")); + Assert.True(headers.ContainsKey("Content-Length")); + Assert.True(headers.Contains(kv1)); + Assert.True(headers.Contains(kv2)); + Assert.True(headers.Contains(kv3)); + Assert.False(headers.Contains(kv1b)); + Assert.False(headers.Contains(kv2b)); + Assert.False(headers.Contains(kv3b)); } [Fact] @@ -159,16 +199,21 @@ namespace Microsoft.AspNetCore.Server.KestrelTests StringValues value; Assert.False(headers.TryGetValue("host", out value)); Assert.False(headers.TryGetValue("custom", out value)); + Assert.False(headers.TryGetValue("Content-Length", out value)); headers.Add("host", new[] { "localhost" }); headers.Add("custom", new[] { "value" }); + headers.Add("Content-Length", new[] { "0" }); Assert.True(headers.TryGetValue("host", out value)); Assert.True(headers.TryGetValue("custom", out value)); + Assert.True(headers.TryGetValue("Content-Length", out value)); Assert.Throws(() => headers.Add("host", new[] { "localhost" })); Assert.Throws(() => headers.Add("custom", new[] { "value" })); + Assert.Throws(() => headers.Add("Content-Length", new[] { "0" })); Assert.True(headers.TryGetValue("host", out value)); Assert.True(headers.TryGetValue("custom", out value)); + Assert.True(headers.TryGetValue("Content-Length", out value)); } [Fact] @@ -177,17 +222,20 @@ namespace Microsoft.AspNetCore.Server.KestrelTests IDictionary headers = new FrameRequestHeaders(); headers.Add("host", new[] { "localhost" }); headers.Add("custom", new[] { "value" }); + headers.Add("Content-Length", new[] { "0" }); StringValues value; - Assert.Equal(2, headers.Count); + Assert.Equal(3, headers.Count); Assert.True(headers.TryGetValue("host", out value)); Assert.True(headers.TryGetValue("custom", out value)); + Assert.True(headers.TryGetValue("Content-Length", out value)); headers.Clear(); Assert.Equal(0, headers.Count); Assert.False(headers.TryGetValue("host", out value)); Assert.False(headers.TryGetValue("custom", out value)); + Assert.False(headers.TryGetValue("Content-Length", out value)); } [Fact] @@ -196,25 +244,36 @@ namespace Microsoft.AspNetCore.Server.KestrelTests IDictionary headers = new FrameRequestHeaders(); headers.Add("host", new[] { "localhost" }); headers.Add("custom", new[] { "value" }); + headers.Add("Content-Length", new[] { "0" }); StringValues value; - Assert.Equal(2, headers.Count); + Assert.Equal(3, headers.Count); Assert.True(headers.TryGetValue("host", out value)); Assert.True(headers.TryGetValue("custom", out value)); + Assert.True(headers.TryGetValue("Content-Length", out value)); Assert.True(headers.Remove("host")); Assert.False(headers.Remove("host")); - Assert.Equal(1, headers.Count); + Assert.Equal(2, headers.Count); Assert.False(headers.TryGetValue("host", out value)); Assert.True(headers.TryGetValue("custom", out value)); Assert.True(headers.Remove("custom")); Assert.False(headers.Remove("custom")); + Assert.Equal(1, headers.Count); + Assert.False(headers.TryGetValue("host", out value)); + Assert.False(headers.TryGetValue("custom", out value)); + Assert.True(headers.TryGetValue("Content-Length", out value)); + + Assert.True(headers.Remove("Content-Length")); + Assert.False(headers.Remove("Content-Length")); + Assert.Equal(0, headers.Count); Assert.False(headers.TryGetValue("host", out value)); Assert.False(headers.TryGetValue("custom", out value)); + Assert.False(headers.TryGetValue("Content-Length", out value)); } [Fact] @@ -222,9 +281,10 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { IDictionary headers = new FrameRequestHeaders(); headers.Add("host", new[] { "localhost" }); + headers.Add("Content-Length", new[] { "0" }); headers.Add("custom", new[] { "value" }); - var entries = new KeyValuePair[4]; + var entries = new KeyValuePair[5]; headers.CopyTo(entries, 1); Assert.Null(entries[0].Key); @@ -233,11 +293,14 @@ namespace Microsoft.AspNetCore.Server.KestrelTests Assert.Equal("Host", entries[1].Key); Assert.Equal(new[] { "localhost" }, entries[1].Value); - Assert.Equal("custom", entries[2].Key); - Assert.Equal(new[] { "value" }, entries[2].Value); + Assert.Equal("Content-Length", entries[2].Key); + Assert.Equal(new[] { "0" }, entries[2].Value); - Assert.Null(entries[3].Key); - Assert.Equal(new StringValues(), entries[0].Value); + Assert.Equal("custom", entries[3].Key); + Assert.Equal(new[] { "value" }, entries[3].Value); + + Assert.Null(entries[4].Key); + Assert.Equal(new StringValues(), entries[4].Value); } [Fact] diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameResponseHeadersTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameResponseHeadersTests.cs index 55ec8ee48b..b3dee3d0c7 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameResponseHeadersTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameResponseHeadersTests.cs @@ -10,8 +10,10 @@ using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Server.Kestrel; using Microsoft.AspNetCore.Server.Kestrel.Internal; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.Extensions.Primitives; using Xunit; +using Microsoft.Net.Http.Headers; namespace Microsoft.AspNetCore.Server.KestrelTests { @@ -173,16 +175,6 @@ namespace Microsoft.AspNetCore.Server.KestrelTests Assert.Equal($"Invalid Content-Length: \"{contentLength}\". Value must be a positive integral number.", exception.Message); } - [Theory] - [MemberData(nameof(BadContentLengths))] - public void ThrowsWhenSettingRawContentLengthToNonNumericValue(string contentLength) - { - var headers = new FrameResponseHeaders(); - - var exception = Assert.Throws(() => headers.SetRawContentLength(contentLength, Encoding.ASCII.GetBytes(contentLength))); - Assert.Equal($"Invalid Content-Length: \"{contentLength}\". Value must be a positive integral number.", exception.Message); - } - [Theory] [MemberData(nameof(BadContentLengths))] public void ThrowsWhenAssigningHeaderContentLengthToNonNumericValue(string contentLength) @@ -201,7 +193,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var dictionary = (IDictionary)headers; dictionary.Add("Content-Length", contentLength); - Assert.Equal(ParseLong(contentLength), headers.HeaderContentLengthValue); + Assert.Equal(ParseLong(contentLength), headers.ContentLength); } [Theory] @@ -212,17 +204,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var dictionary = (IDictionary)headers; dictionary["Content-Length"] = contentLength; - Assert.Equal(ParseLong(contentLength), headers.HeaderContentLengthValue); - } - - [Theory] - [MemberData(nameof(GoodContentLengths))] - public void ContentLengthValueCanBeReadAsLongAfterSettingRawHeader(string contentLength) - { - var headers = new FrameResponseHeaders(); - headers.SetRawContentLength(contentLength, Encoding.ASCII.GetBytes(contentLength)); - - Assert.Equal(ParseLong(contentLength), headers.HeaderContentLengthValue); + Assert.Equal(ParseLong(contentLength), headers.ContentLength); } [Theory] @@ -232,7 +214,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var headers = new FrameResponseHeaders(); headers.HeaderContentLength = contentLength; - Assert.Equal(ParseLong(contentLength), headers.HeaderContentLengthValue); + Assert.Equal(ParseLong(contentLength), headers.ContentLength); } [Fact] @@ -244,7 +226,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests dictionary.Remove("Content-Length"); - Assert.Equal(null, headers.HeaderContentLengthValue); + Assert.Equal(null, headers.ContentLength); } [Fact] @@ -256,7 +238,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests dictionary.Clear(); - Assert.Equal(null, headers.HeaderContentLengthValue); + Assert.Equal(null, headers.ContentLength); } private static long ParseLong(string value) diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolIteratorTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolIteratorTests.cs index 1db21257a3..1239cfa999 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolIteratorTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolIteratorTests.cs @@ -1214,6 +1214,86 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } } + [Fact] + public void CorrectContentLengthsOutput() + { + using (var pool = new MemoryPool()) + { + var block = pool.Lease(); + try + { + for (var i = 0u; i <= 9u; i++) + { + block.Reset(); + var iter = new MemoryPoolIterator(block); + iter.CopyFromNumeric(i); + + Assert.Equal(block.Array[block.Start], (byte)(i + '0')); + Assert.Equal(block.End, block.Start + 1); + Assert.Equal(iter.Index, block.End); + } + for (var i = 10u; i <= 99u; i++) + { + block.Reset(); + var iter = new MemoryPoolIterator(block); + iter.CopyFromNumeric(i); + + Assert.Equal(block.Array[block.Start], (byte)((i / 10) + '0')); + Assert.Equal(block.Array[block.Start + 1], (byte)((i % 10) + '0')); + + Assert.Equal(block.End, block.Start + 2); + Assert.Equal(iter.Index, block.End); + } + for (var i = 100u; i <= 999u; i++) + { + block.Reset(); + var iter = new MemoryPoolIterator(block); + iter.CopyFromNumeric(i); + + Assert.Equal(block.Array[block.Start], (byte)((i / 100) + '0')); + Assert.Equal(block.Array[block.Start + 1], (byte)(((i % 100) / 10) + '0')); + Assert.Equal(block.Array[block.Start + 2], (byte)((i % 10) + '0')); + + Assert.Equal(block.End, block.Start + 3); + Assert.Equal(iter.Index, block.End); + } + for (var i = 1000u; i <= 9999u; i++) + { + block.Reset(); + var iter = new MemoryPoolIterator(block); + iter.CopyFromNumeric(i); + + Assert.Equal(block.Array[block.Start], (byte)((i / 1000) + '0')); + Assert.Equal(block.Array[block.Start + 1], (byte)(((i % 1000) / 100) + '0')); + Assert.Equal(block.Array[block.Start + 2], (byte)(((i % 100) / 10) + '0')); + Assert.Equal(block.Array[block.Start + 3], (byte)((i % 10) + '0')); + + Assert.Equal(block.End, block.Start + 4); + Assert.Equal(iter.Index, block.End); + } + { + block.Reset(); + var iter = new MemoryPoolIterator(block); + iter.CopyFromNumeric(ulong.MaxValue); + + var outputBytes = Encoding.ASCII.GetBytes(ulong.MaxValue.ToString("0")); + + for (var i = 0; i < outputBytes.Length; i++) + { + Assert.Equal(block.Array[block.Start + i], outputBytes[i]); + } + + Assert.Equal(block.End, block.Start + outputBytes.Length); + Assert.Equal(iter.Index, block.End); + } + } + finally + { + pool.Return(block); + } + } + } + private delegate bool GetKnownString(MemoryPoolIterator iter, out string result); private void TestKnownStringsInterning(string input, string expected, GetKnownString action) diff --git a/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/KnownHeaders.cs b/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/KnownHeaders.cs index bd0c24aa0a..96cc6a350a 100644 --- a/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/KnownHeaders.cs +++ b/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/KnownHeaders.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using System.Linq; using System.Text; @@ -19,47 +20,41 @@ namespace Microsoft.AspNetCore.Server.Kestrel.GeneratedCode return condition ? formatter() : ""; } - static string AppendSwitch(IEnumerable> values, string className, bool handleUnknown = false) => - $@"fixed (byte* ptr = &keyBytes[keyOffset]) - {{ - var pUB = ptr; - var pUL = (ulong*)pUB; + static string AppendSwitch(IEnumerable> values, string className) => + $@"var pUL = (ulong*)pUB; var pUI = (uint*)pUB; var pUS = (ushort*)pUB; + var stringValue = new StringValues(value); switch (keyLength) {{{Each(values, byLength => $@" case {byLength.Key}: {{{Each(byLength, header => $@" if ({header.EqualIgnoreCaseBytes()}) - {{ + {{{(header.Identifier == "ContentLength" ? $@" + if (_contentLength.HasValue) + {{ + ThrowMultipleContentLengthsException(); + }} + else + {{ + _contentLength = ParseContentLength(value); + }} + return;" : $@" if ({header.TestBit()}) {{ _headers._{header.Identifier} = AppendValue(_headers._{header.Identifier}, value); }} else - {{{If(className == "FrameResponseHeaders" && header.Identifier == "ContentLength", () => @" - _contentLength = ParseContentLength(value);")} + {{ {header.SetBit()}; - _headers._{header.Identifier} = new StringValues(value);{(header.EnhancedSetter == false ? "" : $@" + _headers._{header.Identifier} = stringValue;{(header.EnhancedSetter == false ? "" : $@" _headers._raw{header.Identifier} = null;")} }} - return; + return;")} }} ")}}} break; - ")}}} - - {(handleUnknown ? $@" - key = new string('\0', keyLength); - fixed(char *keyBuffer = key) - {{ - if (!AsciiUtilities.TryGetAsciiString(ptr, keyBuffer, keyLength)) - {{ - throw BadHttpRequestException.GetException(RequestRejectionReason.InvalidCharactersInHeaderName); - }} - }} - ": "")} - }}"; + ")}}}"; class KnownHeader { @@ -72,7 +67,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.GeneratedCode public int BytesCount { get; set; } public bool EnhancedSetter { get; set; } public bool PrimaryHeader { get; set; } - public string TestBit() => $"((_bits & {1L << Index}L) != 0)"; + public string TestBit() => $"(_bits & {1L << Index}L) != 0"; + public string TestTempBit() => $"(tempBits & {1L << Index}L) != 0"; + public string TestNotTempBit() => $"(tempBits & ~{1L << Index}L) == 0"; + public string TestNotBit() => $"(_bits & {1L << Index}L) == 0"; public string SetBit() => $"_bits |= {1L << Index}L"; public string ClearBit() => $"_bits &= ~{1L << Index}L"; @@ -135,7 +133,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.GeneratedCode { "Connection", "Date", - "Content-Length", "Content-Type", "Server", }; @@ -152,7 +149,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.GeneratedCode "Via", "Warning", "Allow", - "Content-Length", "Content-Type", "Content-Encoding", "Content-Language", @@ -192,19 +188,30 @@ namespace Microsoft.AspNetCore.Server.Kestrel.GeneratedCode "TE", "Translate", "User-Agent", - }).Concat(corsRequestHeaders).Select((header, index) => new KnownHeader + }) + .Concat(corsRequestHeaders) + .Select((header, index) => new KnownHeader { Name = header, Index = index, PrimaryHeader = requestPrimaryHeaders.Contains(header) - }).ToArray(); + }) + .Concat(new[] { new KnownHeader + { + Name = "Content-Length", + Index = -1, + PrimaryHeader = requestPrimaryHeaders.Contains("Content-Length") + }}) + .ToArray(); + Debug.Assert(requestHeaders.Length <= 64); + Debug.Assert(requestHeaders.Max(x => x.Index) <= 62); + var enhancedHeaders = new[] { "Connection", "Server", "Date", - "Transfer-Encoding", - "Content-Length", + "Transfer-Encoding" }; // http://www.w3.org/TR/cors/#syntax var corsResponseHeaders = new[] @@ -228,13 +235,27 @@ namespace Microsoft.AspNetCore.Server.Kestrel.GeneratedCode "Set-Cookie", "Vary", "WWW-Authenticate", - }).Concat(corsResponseHeaders).Select((header, index) => new KnownHeader + }) + .Concat(corsResponseHeaders) + .Select((header, index) => new KnownHeader { Name = header, Index = index, EnhancedSetter = enhancedHeaders.Contains(header), PrimaryHeader = responsePrimaryHeaders.Contains(header) - }).ToArray(); + }) + .Concat(new[] { new KnownHeader + { + Name = "Content-Length", + Index = -1, + EnhancedSetter = enhancedHeaders.Contains("Content-Length"), + PrimaryHeader = responsePrimaryHeaders.Contains("Content-Length") + }}) + .ToArray(); + // 63 for reponseHeaders as it steals one bit for Content-Length in CopyTo(ref MemoryPoolIterator output) + Debug.Assert(responseHeaders.Length <= 63); + Debug.Assert(responseHeaders.Max(x => x.Index) <= 62); + var loops = new[] { new @@ -269,6 +290,7 @@ using System; using System.Collections.Generic; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.Extensions.Primitives; +using Microsoft.Net.Http.Headers; namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http {{ @@ -286,61 +308,48 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http private HeaderReferences _headers; {Each(loop.Headers, header => $@" public StringValues Header{header.Identifier} - {{ + {{{(header.Identifier == "ContentLength" ? $@" get {{ - if ({header.TestBit()}) + StringValues value; + if (_contentLength.HasValue) {{ - return _headers._{header.Identifier}; + value = new StringValues(HeaderUtilities.FormatInt64(_contentLength.Value)); }} - return StringValues.Empty; + return value; }} set - {{{If(loop.ClassName == "FrameResponseHeaders" && header.Identifier == "ContentLength", () => @" - _contentLength = ParseContentLength(value);")} + {{ + _contentLength = ParseContentLength(value); + }}" : $@" + get + {{ + StringValues value; + if ({header.TestBit()}) + {{ + value = _headers._{header.Identifier}; + }} + return value; + }} + set + {{ {header.SetBit()}; _headers._{header.Identifier} = value; {(header.EnhancedSetter == false ? "" : $@" _headers._raw{header.Identifier} = null;")} - }} + }}")} }}")} - {Each(loop.Headers.Where(header => header.EnhancedSetter), header => $@" +{Each(loop.Headers.Where(header => header.EnhancedSetter), header => $@" public void SetRaw{header.Identifier}(StringValues value, byte[] raw) - {{{If(loop.ClassName == "FrameResponseHeaders" && header.Identifier == "ContentLength", () => @" - _contentLength = ParseContentLength(value);")} + {{ {header.SetBit()}; _headers._{header.Identifier} = value; _headers._raw{header.Identifier} = raw; }}")} protected override int GetCountFast() {{ - return BitCount(_bits) + (MaybeUnknown?.Count ?? 0); - }} - protected override StringValues GetValueFast(string key) - {{ - switch (key.Length) - {{{Each(loop.HeadersByLength, byLength => $@" - case {byLength.Key}: - {{{Each(byLength, header => $@" - if (""{header.Name}"".Equals(key, StringComparison.OrdinalIgnoreCase)) - {{ - if ({header.TestBit()}) - {{ - return _headers._{header.Identifier}; - }} - else - {{ - ThrowKeyNotFoundException(); - }} - }} - ")}}} - break; -")}}} - if (MaybeUnknown == null) - {{ - ThrowKeyNotFoundException(); - }} - return MaybeUnknown[key]; + return (_contentLength.HasValue ? 1 : 0 ) + BitCount(_bits) + (MaybeUnknown?.Count ?? 0); }} + protected override bool TryGetValueFast(string key, out StringValues value) {{ switch (key.Length) @@ -348,71 +357,83 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http case {byLength.Key}: {{{Each(byLength, header => $@" if (""{header.Name}"".Equals(key, StringComparison.OrdinalIgnoreCase)) - {{ + {{{(header.Identifier == "ContentLength" ? @" + if (_contentLength.HasValue) + { + value = HeaderUtilities.FormatInt64(_contentLength.Value); + return true; + } + return false;" : $@" if ({header.TestBit()}) {{ value = _headers._{header.Identifier}; return true; }} - else - {{ - value = StringValues.Empty; - return false; - }} - }} - ")}}} - break; -")}}} - value = StringValues.Empty; + return false;")} + }}")} + }} + break;")} + }} + return MaybeUnknown?.TryGetValue(key, out value) ?? false; }} + protected override void SetValueFast(string key, StringValues value) - {{ - {(loop.ClassName == "FrameResponseHeaders" ? "ValidateHeaderCharacters(value);" : "")} + {{{(loop.ClassName == "FrameResponseHeaders" ? @" + ValidateHeaderCharacters(value);" : "")} switch (key.Length) {{{Each(loop.HeadersByLength, byLength => $@" case {byLength.Key}: {{{Each(byLength, header => $@" if (""{header.Name}"".Equals(key, StringComparison.OrdinalIgnoreCase)) - {{{If(loop.ClassName == "FrameResponseHeaders" && header.Identifier == "ContentLength", () => @" - _contentLength = ParseContentLength(value);")} + {{{(header.Identifier == "ContentLength" ? $@" + _contentLength = ParseContentLength(value.ToString());" : $@" {header.SetBit()}; _headers._{header.Identifier} = value;{(header.EnhancedSetter == false ? "" : $@" - _headers._raw{header.Identifier} = null;")} + _headers._raw{header.Identifier} = null;")}")} return; - }} - ")}}} - break; -")}}} - {(loop.ClassName == "FrameResponseHeaders" ? "ValidateHeaderCharacters(key);" : "")} - Unknown[key] = value; + }}")} + }} + break;")} + }} + + SetValueUnknown(key, value); }} - protected override void AddValueFast(string key, StringValues value) - {{ - {(loop.ClassName == "FrameResponseHeaders" ? "ValidateHeaderCharacters(value);" : "")} + + protected override bool AddValueFast(string key, StringValues value) + {{{(loop.ClassName == "FrameResponseHeaders" ? @" + ValidateHeaderCharacters(value);" : "")} switch (key.Length) {{{Each(loop.HeadersByLength, byLength => $@" case {byLength.Key}: {{{Each(byLength, header => $@" if (""{header.Name}"".Equals(key, StringComparison.OrdinalIgnoreCase)) - {{ - if ({header.TestBit()}) + {{{(header.Identifier == "ContentLength" ? $@" + if (!_contentLength.HasValue) {{ - ThrowDuplicateKeyException(); - }}{ - If(loop.ClassName == "FrameResponseHeaders" && header.Identifier == "ContentLength", () => @" - _contentLength = ParseContentLength(value);")} - {header.SetBit()}; - _headers._{header.Identifier} = value;{(header.EnhancedSetter == false ? "" : $@" - _headers._raw{header.Identifier} = null;")} - return; - }} - ")}}} - break; - ")}}} - {(loop.ClassName == "FrameResponseHeaders" ? "ValidateHeaderCharacters(key);" : "")} + _contentLength = ParseContentLength(value); + return true; + }} + return false;" : $@" + if ({header.TestNotBit()}) + {{ + {header.SetBit()}; + _headers._{header.Identifier} = value;{(header.EnhancedSetter == false ? "" : $@" + _headers._raw{header.Identifier} = null;")} + return true; + }} + return false;")} + }}")} + }} + break;")} + }} +{(loop.ClassName == "FrameResponseHeaders" ? @" + ValidateHeaderCharacters(key);" : "")} Unknown.Add(key, value); + // Return true, above will throw and exit for false + return true; }} + protected override bool RemoveFast(string key) {{ switch (key.Length) @@ -420,74 +441,88 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http case {byLength.Key}: {{{Each(byLength, header => $@" if (""{header.Name}"".Equals(key, StringComparison.OrdinalIgnoreCase)) - {{ + {{{(header.Identifier == "ContentLength" ? @" + if (_contentLength.HasValue) + { + _contentLength = null; + return true; + } + return false;" : $@" if ({header.TestBit()}) - {{{If(loop.ClassName == "FrameResponseHeaders" && header.Identifier == "ContentLength", () => @" - _contentLength = null;")} + {{ {header.ClearBit()}; - _headers._{header.Identifier} = StringValues.Empty;{(header.EnhancedSetter == false ? "" : $@" + _headers._{header.Identifier} = default(StringValues);{(header.EnhancedSetter == false ? "" : $@" _headers._raw{header.Identifier} = null;")} return true; }} - else - {{ - return false; - }} - }} - ")}}} - break; - ")}}} + return false;")} + }}")} + }} + break;")} + }} + return MaybeUnknown?.Remove(key) ?? false; }} + protected override void ClearFast() - {{ + {{ MaybeUnknown?.Clear(); - {(loop.ClassName == "FrameResponseHeaders" ? "_contentLength = null;" : "")} - if(FrameHeaders.BitCount(_bits) > 12) + _contentLength = null; + var tempBits = _bits; + _bits = 0; + if(FrameHeaders.BitCount(tempBits) > 12) {{ _headers = default(HeaderReferences); - _bits = 0; return; }} - {Each(loop.Headers.OrderBy(h => !h.PrimaryHeader), header => $@" - if ({header.TestBit()}) + {Each(loop.Headers.Where(header => header.Identifier != "ContentLength").OrderBy(h => !h.PrimaryHeader), header => $@" + if ({header.TestTempBit()}) {{ _headers._{header.Identifier} = default(StringValues); - {header.ClearBit()}; - if(_bits == 0) + if({header.TestNotTempBit()}) {{ return; }} + tempBits &= ~{1L << header.Index}L; }} ")} }} - protected override void CopyToFast(KeyValuePair[] array, int arrayIndex) + protected override bool CopyToFast(KeyValuePair[] array, int arrayIndex) {{ if (arrayIndex < 0) {{ - ThrowArgumentException(); + return false; }} - {Each(loop.Headers, header => $@" + {Each(loop.Headers.Where(header => header.Identifier != "ContentLength"), header => $@" if ({header.TestBit()}) {{ if (arrayIndex == array.Length) {{ - ThrowArgumentException(); + return false; }} - array[arrayIndex] = new KeyValuePair(""{header.Name}"", _headers._{header.Identifier}); ++arrayIndex; + }}")} + if (_contentLength.HasValue) + {{ + if (arrayIndex == array.Length) + {{ + return false; + }} + array[arrayIndex] = new KeyValuePair(""Content-Length"", HeaderUtilities.FormatInt64(_contentLength.Value)); + ++arrayIndex; }} - ")} ((ICollection>)MaybeUnknown)?.CopyTo(array, arrayIndex); + + return true; }} {(loop.ClassName == "FrameResponseHeaders" ? $@" protected void CopyToFast(ref MemoryPoolIterator output) {{ - var tempBits = _bits; - {Each(loop.Headers.OrderBy(h => !h.PrimaryHeader), header => $@" - if ({header.TestBit()}) + var tempBits = _bits | (_contentLength.HasValue ? {1L << 63}L : 0); + {Each(loop.Headers.Where(header => header.Identifier != "ContentLength").OrderBy(h => !h.PrimaryHeader), header => $@" + if ({header.TestTempBit()}) {{ {(header.EnhancedSetter == false ? "" : $@" if (_headers._raw{header.Identifier} != null) {{ @@ -507,35 +542,46 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http }} }} - tempBits &= ~{1L << header.Index}L; - if(tempBits == 0) + if({header.TestNotTempBit()}) {{ return; }} - }} - ")} - }} - - " : "")} + tempBits &= ~{1L << header.Index}L; + }}{(header.Identifier == "Server" ? $@" + if ((tempBits & {1L << 63}L) != 0) + {{ + output.CopyFrom(_headerBytes, {loop.Headers.First(x => x.Identifier == "ContentLength").BytesOffset}, {loop.Headers.First(x => x.Identifier == "ContentLength").BytesCount}); + output.CopyFromNumeric((ulong)ContentLength.Value); + + if((tempBits & ~{1L << 63}L) == 0) + {{ + return; + }} + tempBits &= ~{1L << 63}L; + }}" : "")}")} + }}" : "")} {(loop.ClassName == "FrameRequestHeaders" ? $@" public unsafe void Append(byte[] keyBytes, int keyOffset, int keyLength, string value) {{ - {AppendSwitch(loop.Headers.Where(h => h.PrimaryHeader).GroupBy(x => x.Name.Length), loop.ClassName)} - - AppendNonPrimaryHeaders(keyBytes, keyOffset, keyLength, value); + fixed (byte* ptr = &keyBytes[keyOffset]) + {{ + var pUB = ptr; + {AppendSwitch(loop.Headers.Where(h => h.PrimaryHeader).GroupBy(x => x.Name.Length), loop.ClassName)} + + AppendNonPrimaryHeaders(ptr, keyOffset, keyLength, value); + }} }} - private unsafe void AppendNonPrimaryHeaders(byte[] keyBytes, int keyOffset, int keyLength, string value) + private unsafe void AppendNonPrimaryHeaders(byte* pKeyBytes, int keyOffset, int keyLength, string value) {{ - string key; - {AppendSwitch(loop.Headers.Where(h => !h.PrimaryHeader).GroupBy(x => x.Name.Length), loop.ClassName, true)} + var pUB = pKeyBytes; + {AppendSwitch(loop.Headers.Where(h => !h.PrimaryHeader).GroupBy(x => x.Name.Length), loop.ClassName)} - StringValues existing; - Unknown.TryGetValue(key, out existing); - Unknown[key] = AppendValue(existing, value); + AppendUnknownHeaders(pKeyBytes, keyLength, value); }}" : "")} + private struct HeaderReferences - {{{Each(loop.Headers, header => @" + {{{Each(loop.Headers.Where(header => header.Identifier != "ContentLength"), header => @" public StringValues _" + header.Identifier + ";")} {Each(loop.Headers.Where(header => header.EnhancedSetter), header => @" public byte[] _raw" + header.Identifier + ";")} @@ -547,14 +593,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http {{ switch (_state) {{ - {Each(loop.Headers, header => $@" - case {header.Index}: - goto state{header.Index}; + {Each(loop.Headers.Where(header => header.Identifier != "ContentLength"), header => $@" + case {header.Index}: + goto state{header.Index}; ")} + case {loop.Headers.Count()}: + goto state{loop.Headers.Count()}; default: goto state_default; }} - {Each(loop.Headers, header => $@" + {Each(loop.Headers.Where(header => header.Identifier != "ContentLength"), header => $@" state{header.Index}: if ({header.TestBit()}) {{ @@ -563,6 +611,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http return true; }} ")} + state{loop.Headers.Count()}: + if (_collection._contentLength.HasValue) + {{ + _current = new KeyValuePair(""Content-Length"", HeaderUtilities.FormatInt64(_collection._contentLength.Value)); + _state = {loop.Headers.Count() + 1}; + return true; + }} state_default: if (!_hasUnknown || !_unknownEnumerator.MoveNext()) {{ From 4ac842b050c249ff3e15f7516160d8c248cef455 Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Tue, 24 Jan 2017 14:57:51 -0800 Subject: [PATCH 1025/1662] Update to version 1.0.3. --- samples/LargeResponseApp/project.json | 2 +- samples/SampleApp/project.json | 4 ++-- src/Microsoft.AspNetCore.Server.Kestrel.Https/project.json | 4 ++-- src/Microsoft.AspNetCore.Server.Kestrel/project.json | 2 +- .../project.json | 4 ++-- test/Microsoft.AspNetCore.Server.KestrelTests/project.json | 4 ++-- 6 files changed, 10 insertions(+), 10 deletions(-) diff --git a/samples/LargeResponseApp/project.json b/samples/LargeResponseApp/project.json index 7482ebee80..901c01d703 100644 --- a/samples/LargeResponseApp/project.json +++ b/samples/LargeResponseApp/project.json @@ -1,7 +1,7 @@ { "version": "1.0.0-*", "dependencies": { - "Microsoft.AspNetCore.Server.Kestrel": "1.0.2" + "Microsoft.AspNetCore.Server.Kestrel": "1.0.3" }, "buildOptions": { "emitEntryPoint": true diff --git a/samples/SampleApp/project.json b/samples/SampleApp/project.json index 0d323ffb28..eb27dc59bd 100644 --- a/samples/SampleApp/project.json +++ b/samples/SampleApp/project.json @@ -1,8 +1,8 @@ { "version": "1.0.0-*", "dependencies": { - "Microsoft.AspNetCore.Server.Kestrel": "1.0.2", - "Microsoft.AspNetCore.Server.Kestrel.Https": "1.0.2", + "Microsoft.AspNetCore.Server.Kestrel": "1.0.3", + "Microsoft.AspNetCore.Server.Kestrel.Https": "1.0.3", "Microsoft.Extensions.Logging.Console": "1.0.1" }, "buildOptions": { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Https/project.json b/src/Microsoft.AspNetCore.Server.Kestrel.Https/project.json index dcb023542c..3ccb6c39af 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Https/project.json +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Https/project.json @@ -1,5 +1,5 @@ { - "version": "1.0.2", + "version": "1.0.3", "description": "HTTPS support for the ASP.NET Core Kestrel cross-platform web server.", "buildOptions": { "keyFile": "../../tools/Key.snk", @@ -19,7 +19,7 @@ ] }, "dependencies": { - "Microsoft.AspNetCore.Server.Kestrel": "1.0.2" + "Microsoft.AspNetCore.Server.Kestrel": "1.0.3" }, "frameworks": { "net451": {}, diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/project.json b/src/Microsoft.AspNetCore.Server.Kestrel/project.json index 42b2681d9f..5a227b47e5 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/project.json +++ b/src/Microsoft.AspNetCore.Server.Kestrel/project.json @@ -1,5 +1,5 @@ { - "version": "1.0.2", + "version": "1.0.3", "description": "ASP.NET Core Kestrel cross-platform web server.", "packOptions": { "repository": { diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json index 522b45177a..47f90621ad 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json @@ -3,8 +3,8 @@ "dependencies": { "dotnet-test-xunit": "1.0.0-rc3-000000-01", "Microsoft.AspNetCore.Http.Abstractions": "1.0.1", - "Microsoft.AspNetCore.Server.Kestrel": "1.0.2", - "Microsoft.AspNetCore.Server.Kestrel.Https": "1.0.2", + "Microsoft.AspNetCore.Server.Kestrel": "1.0.3", + "Microsoft.AspNetCore.Server.Kestrel.Https": "1.0.3", "Microsoft.AspNetCore.Testing": "1.0.1", "Microsoft.Extensions.Logging.Console": "1.0.1", "Newtonsoft.Json": "9.0.1", diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/project.json b/test/Microsoft.AspNetCore.Server.KestrelTests/project.json index be73eba5d2..9f23e30f5a 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/project.json +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/project.json @@ -2,8 +2,8 @@ "version": "1.0.0-*", "dependencies": { "dotnet-test-xunit": "1.0.0-rc3-000000-01", - "Microsoft.AspNetCore.Server.Kestrel": "1.0.2", - "Microsoft.AspNetCore.Server.Kestrel.Https": "1.0.2", + "Microsoft.AspNetCore.Server.Kestrel": "1.0.3", + "Microsoft.AspNetCore.Server.Kestrel.Https": "1.0.3", "Microsoft.AspNetCore.Testing": "1.0.1", "xunit": "2.1.0" }, From b9de869a2d504f8a5fd2b7698bbafbfbbdca391d Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Tue, 24 Jan 2017 17:10:53 -0800 Subject: [PATCH 1026/1662] Add SDK version to global.json. --- global.json | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/global.json b/global.json index 983ba0401e..fa49c8b23f 100644 --- a/global.json +++ b/global.json @@ -1,3 +1,6 @@ { - "projects": ["src"] + "projects": ["src"], + "sdk": { + "version": "1.0.0-preview2-003131" + } } From fe089a8826737649ced05701682afd4613add444 Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Wed, 25 Jan 2017 10:12:03 -0800 Subject: [PATCH 1027/1662] Update SDK version to 1.0.0-preview2-003154. --- global.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/global.json b/global.json index fa49c8b23f..fa4ae5e2d6 100644 --- a/global.json +++ b/global.json @@ -1,6 +1,6 @@ { "projects": ["src"], "sdk": { - "version": "1.0.0-preview2-003131" + "version": "1.0.0-preview2-003154" } } From c8da6e062877072b1d8a42fc69e52160e100e282 Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Wed, 25 Jan 2017 10:13:52 -0800 Subject: [PATCH 1028/1662] Fix deadlock in SocketOutput (#1304). --- .../Internal/Http/SocketOutput.cs | 2 +- .../CancellationTokenExtensions.cs | 76 +++++++++++++++++++ .../Infrastructure/DisposableAction.cs | 40 ++++++++++ 3 files changed, 117 insertions(+), 1 deletion(-) create mode 100644 src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/CancellationTokenExtensions.cs create mode 100644 src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/DisposableAction.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/SocketOutput.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/SocketOutput.cs index fc43cd67fa..e0787aebfd 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/SocketOutput.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/SocketOutput.cs @@ -174,7 +174,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _tasksPending.Enqueue(new WaitingTask() { CancellationToken = cancellationToken, - CancellationRegistration = cancellationToken.Register(_connectionCancellation, this), + CancellationRegistration = cancellationToken.SafeRegister(_connectionCancellation, this), BytesToWrite = buffer.Count, CompletionSource = tcs }); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/CancellationTokenExtensions.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/CancellationTokenExtensions.cs new file mode 100644 index 0000000000..2f9b6c1afb --- /dev/null +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/CancellationTokenExtensions.cs @@ -0,0 +1,76 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Threading; + +namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure +{ + internal static class CancellationTokenExtensions + { + public static IDisposable SafeRegister(this CancellationToken cancellationToken, Action callback, object state) + { + var callbackWrapper = new CancellationCallbackWrapper(callback, state); + var registration = cancellationToken.Register(s => InvokeCallback(s), callbackWrapper); + var disposeCancellationState = new DisposeCancellationState(callbackWrapper, registration); + + return new DisposableAction(s => Dispose(s), disposeCancellationState); + } + + private static void InvokeCallback(object state) + { + ((CancellationCallbackWrapper)state).TryInvoke(); + } + + private static void Dispose(object state) + { + ((DisposeCancellationState)state).TryDispose(); + } + + private class DisposeCancellationState + { + private readonly CancellationCallbackWrapper _callbackWrapper; + private readonly CancellationTokenRegistration _registration; + + public DisposeCancellationState(CancellationCallbackWrapper callbackWrapper, CancellationTokenRegistration registration) + { + _callbackWrapper = callbackWrapper; + _registration = registration; + } + + public void TryDispose() + { + if (_callbackWrapper.TrySetInvoked()) + { + _registration.Dispose(); + } + } + } + + private class CancellationCallbackWrapper + { + private readonly Action _callback; + private readonly object _state; + private int _callbackInvoked; + + public CancellationCallbackWrapper(Action callback, object state) + { + _callback = callback; + _state = state; + } + + public bool TrySetInvoked() + { + return Interlocked.Exchange(ref _callbackInvoked, 1) == 0; + } + + public void TryInvoke() + { + if (TrySetInvoked()) + { + _callback(_state); + } + } + } + } +} \ No newline at end of file diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/DisposableAction.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/DisposableAction.cs new file mode 100644 index 0000000000..466e66b4a6 --- /dev/null +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/DisposableAction.cs @@ -0,0 +1,40 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Threading; + +namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure +{ + internal class DisposableAction : IDisposable + { + public static readonly DisposableAction Empty = new DisposableAction(() => { }); + + private Action _action; + private readonly object _state; + + public DisposableAction(Action action) + : this(state => ((Action)state).Invoke(), state: action) + { + } + + public DisposableAction(Action action, object state) + { + _action = action; + _state = state; + } + + protected virtual void Dispose(bool disposing) + { + if (disposing) + { + Interlocked.Exchange(ref _action, (state) => { }).Invoke(_state); + } + } + + public void Dispose() + { + Dispose(true); + } + } +} \ No newline at end of file From ba3976aeebb6d687f71cbcb0cbbb3d397e706c98 Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Wed, 25 Jan 2017 10:30:16 -0800 Subject: [PATCH 1029/1662] Update to version 1.1.1. --- global.json | 5 ++++- samples/LargeResponseApp/project.json | 4 ++-- samples/SampleApp/project.json | 6 +++--- src/Microsoft.AspNetCore.Server.Kestrel.Https/project.json | 4 ++-- src/Microsoft.AspNetCore.Server.Kestrel/project.json | 2 +- .../project.json | 6 +++--- test/Microsoft.AspNetCore.Server.KestrelTests/project.json | 6 +++--- .../project.json | 2 +- 8 files changed, 19 insertions(+), 16 deletions(-) diff --git a/global.json b/global.json index 983ba0401e..8ae3012369 100644 --- a/global.json +++ b/global.json @@ -1,3 +1,6 @@ { - "projects": ["src"] + "projects": ["src"], + "sdk": { + "version": "1.0.0-preview2-1-003177" + } } diff --git a/samples/LargeResponseApp/project.json b/samples/LargeResponseApp/project.json index d2305ee97e..b5cf8ce7a8 100644 --- a/samples/LargeResponseApp/project.json +++ b/samples/LargeResponseApp/project.json @@ -1,7 +1,7 @@ { - "version": "1.1.0-*", + "version": "1.1.1-*", "dependencies": { - "Microsoft.AspNetCore.Server.Kestrel": "1.1.0-*" + "Microsoft.AspNetCore.Server.Kestrel": "1.1.1-*" }, "buildOptions": { "emitEntryPoint": true diff --git a/samples/SampleApp/project.json b/samples/SampleApp/project.json index c3314ee4f9..78c58406b1 100644 --- a/samples/SampleApp/project.json +++ b/samples/SampleApp/project.json @@ -1,8 +1,8 @@ { - "version": "1.1.0-*", + "version": "1.1.1-*", "dependencies": { - "Microsoft.AspNetCore.Server.Kestrel": "1.1.0-*", - "Microsoft.AspNetCore.Server.Kestrel.Https": "1.1.0-*", + "Microsoft.AspNetCore.Server.Kestrel": "1.1.1-*", + "Microsoft.AspNetCore.Server.Kestrel.Https": "1.1.1-*", "Microsoft.Extensions.Logging.Console": "1.1.0-*" }, "buildOptions": { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Https/project.json b/src/Microsoft.AspNetCore.Server.Kestrel.Https/project.json index 5c23958fbd..5ec93e16f4 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Https/project.json +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Https/project.json @@ -1,5 +1,5 @@ { - "version": "1.1.0-*", + "version": "1.1.1-*", "description": "HTTPS support for the ASP.NET Core Kestrel cross-platform web server.", "buildOptions": { "keyFile": "../../tools/Key.snk", @@ -20,7 +20,7 @@ ] }, "dependencies": { - "Microsoft.AspNetCore.Server.Kestrel": "1.1.0-*", + "Microsoft.AspNetCore.Server.Kestrel": "1.1.1-*", "Microsoft.Extensions.TaskCache.Sources": { "version": "1.1.0-*", "type": "build" diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/project.json b/src/Microsoft.AspNetCore.Server.Kestrel/project.json index 4db40355f9..5a23dd7840 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/project.json +++ b/src/Microsoft.AspNetCore.Server.Kestrel/project.json @@ -1,5 +1,5 @@ { - "version": "1.1.0-*", + "version": "1.1.1-*", "description": "ASP.NET Core Kestrel cross-platform web server.", "packOptions": { "repository": { diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json index 9444a422fd..5e3d3d1b27 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json @@ -1,10 +1,10 @@ { - "version": "1.1.0-*", + "version": "1.1.1-*", "dependencies": { "dotnet-test-xunit": "2.2.0-*", "Microsoft.AspNetCore.Http.Abstractions": "1.1.0-*", - "Microsoft.AspNetCore.Server.Kestrel": "1.1.0-*", - "Microsoft.AspNetCore.Server.Kestrel.Https": "1.1.0-*", + "Microsoft.AspNetCore.Server.Kestrel": "1.1.1-*", + "Microsoft.AspNetCore.Server.Kestrel.Https": "1.1.1-*", "Microsoft.AspNetCore.Testing": "1.1.0-*", "Microsoft.Extensions.Logging.Testing": "1.1.0-*", "Moq": "4.6.36-*", diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/project.json b/test/Microsoft.AspNetCore.Server.KestrelTests/project.json index 54537f5e83..91575c605d 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/project.json +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/project.json @@ -1,9 +1,9 @@ { - "version": "1.1.0-*", + "version": "1.1.1-*", "dependencies": { "dotnet-test-xunit": "2.2.0-*", - "Microsoft.AspNetCore.Server.Kestrel": "1.1.0-*", - "Microsoft.AspNetCore.Server.Kestrel.Https": "1.1.0-*", + "Microsoft.AspNetCore.Server.Kestrel": "1.1.1-*", + "Microsoft.AspNetCore.Server.Kestrel.Https": "1.1.1-*", "Microsoft.AspNetCore.Testing": "1.1.0-*", "Moq": "4.6.36-*", "xunit": "2.2.0-*", diff --git a/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/project.json b/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/project.json index f22ca3b7d6..3b3e4a330a 100644 --- a/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/project.json +++ b/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/project.json @@ -1,5 +1,5 @@ { - "version": "1.1.0-*", + "version": "1.1.1-*", "buildOptions": { "emitEntryPoint": true }, From aacb7d7453ccfdd76af598079f685131dea94282 Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Wed, 25 Jan 2017 11:00:31 -0800 Subject: [PATCH 1030/1662] Fix flaky tests. --- .../EngineTests.cs | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs index 1c9eefb324..5a6dc3ddb4 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs @@ -832,12 +832,14 @@ namespace Microsoft.AspNetCore.Server.KestrelTests "", ""); - Assert.Equal(2, onStartingCallCount1); - // The second OnStarting callback should not be called since the first failed. - Assert.Equal(0, onStartingCallCount2); - Assert.Equal(2, testLogger.ApplicationErrorsLogged); + } } + + Assert.Equal(2, onStartingCallCount1); + // The second OnStarting callback should not be called since the first failed. + Assert.Equal(0, onStartingCallCount2); + Assert.Equal(2, testLogger.ApplicationErrorsLogged); } [Theory] @@ -882,12 +884,12 @@ namespace Microsoft.AspNetCore.Server.KestrelTests "", "Hello World"); } - - // All OnCompleted callbacks should be called even if they throw. - Assert.Equal(2, testLogger.ApplicationErrorsLogged); - Assert.True(onCompletedCalled1); - Assert.True(onCompletedCalled2); } + + // All OnCompleted callbacks should be called even if they throw. + Assert.Equal(2, testLogger.ApplicationErrorsLogged); + Assert.True(onCompletedCalled1); + Assert.True(onCompletedCalled2); } [Theory] From 9051bbf322a226c0ff9bcf2bfa7009d715b28fd4 Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Wed, 25 Jan 2017 14:11:21 -0800 Subject: [PATCH 1031/1662] Fix deadlock in SocketOutput (#1304). --- .../Internal/Http/SocketOutput.cs | 2 +- .../CancellationTokenExtensions.cs | 76 +++++++++++++++++++ .../Infrastructure/DisposableAction.cs | 40 ++++++++++ 3 files changed, 117 insertions(+), 1 deletion(-) create mode 100644 src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/CancellationTokenExtensions.cs create mode 100644 src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/DisposableAction.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/SocketOutput.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/SocketOutput.cs index 4a6cac5006..14c7393f29 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/SocketOutput.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/SocketOutput.cs @@ -169,7 +169,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _tasksPending.Enqueue(new WaitingTask() { CancellationToken = cancellationToken, - CancellationRegistration = cancellationToken.Register(_connectionCancellation, this), + CancellationRegistration = cancellationToken.SafeRegister(_connectionCancellation, this), BytesToWrite = buffer.Count, CompletionSource = tcs }); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/CancellationTokenExtensions.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/CancellationTokenExtensions.cs new file mode 100644 index 0000000000..2f9b6c1afb --- /dev/null +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/CancellationTokenExtensions.cs @@ -0,0 +1,76 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Threading; + +namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure +{ + internal static class CancellationTokenExtensions + { + public static IDisposable SafeRegister(this CancellationToken cancellationToken, Action callback, object state) + { + var callbackWrapper = new CancellationCallbackWrapper(callback, state); + var registration = cancellationToken.Register(s => InvokeCallback(s), callbackWrapper); + var disposeCancellationState = new DisposeCancellationState(callbackWrapper, registration); + + return new DisposableAction(s => Dispose(s), disposeCancellationState); + } + + private static void InvokeCallback(object state) + { + ((CancellationCallbackWrapper)state).TryInvoke(); + } + + private static void Dispose(object state) + { + ((DisposeCancellationState)state).TryDispose(); + } + + private class DisposeCancellationState + { + private readonly CancellationCallbackWrapper _callbackWrapper; + private readonly CancellationTokenRegistration _registration; + + public DisposeCancellationState(CancellationCallbackWrapper callbackWrapper, CancellationTokenRegistration registration) + { + _callbackWrapper = callbackWrapper; + _registration = registration; + } + + public void TryDispose() + { + if (_callbackWrapper.TrySetInvoked()) + { + _registration.Dispose(); + } + } + } + + private class CancellationCallbackWrapper + { + private readonly Action _callback; + private readonly object _state; + private int _callbackInvoked; + + public CancellationCallbackWrapper(Action callback, object state) + { + _callback = callback; + _state = state; + } + + public bool TrySetInvoked() + { + return Interlocked.Exchange(ref _callbackInvoked, 1) == 0; + } + + public void TryInvoke() + { + if (TrySetInvoked()) + { + _callback(_state); + } + } + } + } +} \ No newline at end of file diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/DisposableAction.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/DisposableAction.cs new file mode 100644 index 0000000000..466e66b4a6 --- /dev/null +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/DisposableAction.cs @@ -0,0 +1,40 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Threading; + +namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure +{ + internal class DisposableAction : IDisposable + { + public static readonly DisposableAction Empty = new DisposableAction(() => { }); + + private Action _action; + private readonly object _state; + + public DisposableAction(Action action) + : this(state => ((Action)state).Invoke(), state: action) + { + } + + public DisposableAction(Action action, object state) + { + _action = action; + _state = state; + } + + protected virtual void Dispose(bool disposing) + { + if (disposing) + { + Interlocked.Exchange(ref _action, (state) => { }).Invoke(_state); + } + } + + public void Dispose() + { + Dispose(true); + } + } +} \ No newline at end of file From e2a2e9a620e926fe6b04341a1fe7b80dd7362c21 Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Wed, 25 Jan 2017 15:43:22 -0800 Subject: [PATCH 1032/1662] Fix memory leak caused by closure allocations in KestrelThread (#1264). --- .../Internal/Infrastructure/KestrelThread.cs | 42 +++++++++++++------ 1 file changed, 29 insertions(+), 13 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/KestrelThread.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/KestrelThread.cs index ec8394be20..fd7323c731 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/KestrelThread.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/KestrelThread.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using System.Runtime.ExceptionServices; +using System.Runtime.InteropServices; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Hosting; @@ -23,6 +24,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal private static readonly Action _postCallbackAdapter = (callback, state) => ((Action)callback).Invoke(state); private static readonly Action _postAsyncCallbackAdapter = (callback, state) => ((Action)callback).Invoke(state); + private static readonly Libuv.uv_walk_cb _heartbeatWalkCallback = (ptr, arg) => + { + var streamHandle = UvMemory.FromIntPtr(ptr) as UvStreamHandle; + var thisHandle = GCHandle.FromIntPtr(arg); + var kestrelThread = (KestrelThread)thisHandle.Target; + streamHandle?.Connection?.Tick(kestrelThread.Now); + }; // maximum times the work queues swapped and are processed in a single pass // as completing a task may immediately have write data to put on the network @@ -48,6 +56,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal private readonly IKestrelTrace _log; private readonly IThreadPool _threadPool; private readonly TimeSpan _shutdownTimeout; + private IntPtr _thisPtr; public KestrelThread(KestrelEngine engine) { @@ -94,6 +103,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal private Action, IntPtr> QueueCloseAsyncHandle { get; } + // The cached result of Loop.Now() which is a timestamp in milliseconds + private long Now { get; set; } + public Task StartAsync() { var tcs = new TaskCompletionSource(); @@ -245,14 +257,17 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal } public void Walk(Action callback) + { + Walk((ptr, arg) => callback(ptr), IntPtr.Zero); + } + + private void Walk(Libuv.uv_walk_cb callback, IntPtr arg) { _engine.Libuv.walk( _loop, - (ptr, arg) => - { - callback(ptr); - }, - IntPtr.Zero); + callback, + arg + ); } private void PostCloseHandle(Action callback, IntPtr handle) @@ -273,7 +288,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal { lock (_startSync) { - var tcs = (TaskCompletionSource) parameter; + var tcs = (TaskCompletionSource)parameter; try { _loop.Init(_engine.Libuv); @@ -290,8 +305,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal } } + // This is used to access a 64-bit timestamp (this.Now) using a potentially 32-bit IntPtr. + var thisHandle = GCHandle.Alloc(this, GCHandleType.Weak); + try { + _thisPtr = GCHandle.ToIntPtr(thisHandle); + _loop.Run(); if (_stopImmediate) { @@ -318,6 +338,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal } finally { + thisHandle.Free(); _threadTcs.SetResult(null); } } @@ -336,13 +357,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal private void OnHeartbeat(UvTimerHandle timer) { - var now = Loop.Now(); - - Walk(ptr => - { - var handle = UvMemory.FromIntPtr(ptr); - (handle as UvStreamHandle)?.Connection?.Tick(now); - }); + Now = Loop.Now(); + Walk(_heartbeatWalkCallback, _thisPtr); } private bool DoPostWork() From c11aedd272034dc5d13752c46f1cb0ef6cf4b99e Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Wed, 25 Jan 2017 15:07:48 -0800 Subject: [PATCH 1033/1662] Call OnStarting before verifying response length (#1303). - Also don't close connection when Content-Length set but no bytes written. --- .../Internal/Http/Frame.cs | 37 ++- .../ResponseTests.cs | 233 ++++++++++++++++-- .../EngineTests.cs | 23 +- 3 files changed, 252 insertions(+), 41 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs index 307ce7bc49..fb5e82df2a 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs @@ -508,23 +508,29 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http public void Flush() { - ProduceStartAndFireOnStarting().GetAwaiter().GetResult(); + InitializeResponse(0).GetAwaiter().GetResult(); SocketOutput.Flush(); } public async Task FlushAsync(CancellationToken cancellationToken) { - await ProduceStartAndFireOnStarting(); + await InitializeResponse(0); await SocketOutput.FlushAsync(cancellationToken); } public void Write(ArraySegment data) { - // For the first write, ensure headers are flushed if Write(Chunked)isn't called. + // For the first write, ensure headers are flushed if Write(Chunked) isn't called. var firstWrite = !HasResponseStarted; - VerifyAndUpdateWrite(data.Count); - ProduceStartAndFireOnStarting().GetAwaiter().GetResult(); + if (firstWrite) + { + InitializeResponse(data.Count).GetAwaiter().GetResult(); + } + else + { + VerifyAndUpdateWrite(data.Count); + } if (_canHaveBody) { @@ -589,9 +595,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http public async Task WriteAsyncAwaited(ArraySegment data, CancellationToken cancellationToken) { - VerifyAndUpdateWrite(data.Count); - - await ProduceStartAndFireOnStarting(); + await InitializeResponseAwaited(data.Count); // WriteAsyncAwaited is only called for the first write to the body. // Ensure headers are flushed if Write(Chunked)Async isn't called. @@ -645,7 +649,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http responseHeaders.HeaderContentLengthValue.HasValue && _responseBytesWritten < responseHeaders.HeaderContentLengthValue.Value) { - _keepAlive = false; + // We need to close the connection if any bytes were written since the client + // cannot be certain of how many bytes it will receive. + if (_responseBytesWritten > 0) + { + _keepAlive = false; + } + ReportApplicationError(new InvalidOperationException( $"Response Content-Length mismatch: too few bytes written ({_responseBytesWritten} of {responseHeaders.HeaderContentLengthValue.Value}).")); } @@ -688,7 +698,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } } - public Task ProduceStartAndFireOnStarting() + public Task InitializeResponse(int firstWriteByteCount) { if (HasResponseStarted) { @@ -697,7 +707,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if (_onStarting != null) { - return ProduceStartAndFireOnStartingAwaited(); + return InitializeResponseAwaited(firstWriteByteCount); } if (_applicationException != null) @@ -705,11 +715,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http ThrowResponseAbortedException(); } + VerifyAndUpdateWrite(firstWriteByteCount); ProduceStart(appCompleted: false); + return TaskCache.CompletedTask; } - private async Task ProduceStartAndFireOnStartingAwaited() + private async Task InitializeResponseAwaited(int firstWriteByteCount) { await FireOnStarting(); @@ -718,6 +730,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http ThrowResponseAbortedException(); } + VerifyAndUpdateWrite(firstWriteByteCount); ProduceStart(appCompleted: false); } diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs index dbf6f5bdd4..af166d1ecf 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs @@ -480,7 +480,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } [Fact] - public async Task WhenAppWritesMoreThanContentLengthWriteThrowsAndConnectionCloses() + public async Task ThrowsAndClosesConnectionWhenAppWritesMoreThanContentLengthWrite() { var testLogger = new TestApplicationErrorLogger(); var serviceContext = new TestServiceContext { Log = new TestKestrelTrace(testLogger) }; @@ -515,7 +515,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } [Fact] - public async Task WhenAppWritesMoreThanContentLengthWriteAsyncThrowsAndConnectionCloses() + public async Task ThrowsAndClosesConnectionWhenAppWritesMoreThanContentLengthWriteAsync() { var testLogger = new TestApplicationErrorLogger(); var serviceContext = new TestServiceContext { Log = new TestKestrelTrace(testLogger) }; @@ -549,15 +549,17 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } [Fact] - public async Task WhenAppWritesMoreThanContentLengthAndResponseNotStarted500ResponseSentAndConnectionCloses() + public async Task InternalServerErrorAndConnectionClosedOnWriteWithMoreThanContentLengthAndResponseNotStarted() { var testLogger = new TestApplicationErrorLogger(); var serviceContext = new TestServiceContext { Log = new TestKestrelTrace(testLogger) }; - using (var server = new TestServer(async httpContext => + using (var server = new TestServer(httpContext => { + var response = Encoding.ASCII.GetBytes("hello, world"); httpContext.Response.ContentLength = 5; - await httpContext.Response.WriteAsync("hello, world"); + httpContext.Response.Body.Write(response, 0, response.Length); + return TaskCache.CompletedTask; }, serviceContext)) { using (var connection = server.CreateConnection()) @@ -566,7 +568,42 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests "GET / HTTP/1.1", "", ""); - await connection.ReceiveEnd( + await connection.ReceiveForcedEnd( + $"HTTP/1.1 500 Internal Server Error", + "Connection: close", + $"Date: {server.Context.DateHeaderValue}", + "Content-Length: 0", + "", + ""); + } + } + + var logMessage = Assert.Single(testLogger.Messages, message => message.LogLevel == LogLevel.Error); + Assert.Equal( + $"Response Content-Length mismatch: too many bytes written (12 of 5).", + logMessage.Exception.Message); + } + + [Fact] + public async Task InternalServerErrorAndConnectionClosedOnWriteAsyncWithMoreThanContentLengthAndResponseNotStarted() + { + var testLogger = new TestApplicationErrorLogger(); + var serviceContext = new TestServiceContext { Log = new TestKestrelTrace(testLogger) }; + + using (var server = new TestServer(httpContext => + { + var response = Encoding.ASCII.GetBytes("hello, world"); + httpContext.Response.ContentLength = 5; + return httpContext.Response.Body.WriteAsync(response, 0, response.Length); + }, serviceContext)) + { + using (var connection = server.CreateConnection()) + { + await connection.Send( + "GET / HTTP/1.1", + "", + ""); + await connection.ReceiveForcedEnd( $"HTTP/1.1 500 Internal Server Error", "Connection: close", $"Date: {server.Context.DateHeaderValue}", @@ -616,7 +653,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } [Fact] - public async Task WhenAppSetsContentLengthButDoesNotWriteBody500ResponseSentAndConnectionCloses() + public async Task WhenAppSetsContentLengthButDoesNotWriteBody500ResponseSentAndConnectionDoesNotClose() { var testLogger = new TestApplicationErrorLogger(); var serviceContext = new TestServiceContext { Log = new TestKestrelTrace(testLogger) }; @@ -630,12 +667,17 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests using (var connection = server.CreateConnection()) { await connection.Send( + "GET / HTTP/1.1", + "", "GET / HTTP/1.1", "", ""); - await connection.ReceiveEnd( - $"HTTP/1.1 500 Internal Server Error", - "Connection: close", + await connection.Receive( + "HTTP/1.1 500 Internal Server Error", + $"Date: {server.Context.DateHeaderValue}", + "Content-Length: 0", + "", + "HTTP/1.1 500 Internal Server Error", $"Date: {server.Context.DateHeaderValue}", "Content-Length: 0", "", @@ -643,10 +685,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } } - var errorMessage = Assert.Single(testLogger.Messages, message => message.LogLevel == LogLevel.Error); - Assert.Equal( - $"Response Content-Length mismatch: too few bytes written (0 of 5).", - errorMessage.Exception.Message); + var error = testLogger.Messages.Where(message => message.LogLevel == LogLevel.Error); + Assert.Equal(2, error.Count()); + Assert.All(error, message => message.Equals("Response Content-Length mismatch: too few bytes written (0 of 5).")); } [Theory] @@ -1050,6 +1091,170 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } } + [Fact] + public async Task FirstWriteVerifiedAfterOnStarting() + { + using (var server = new TestServer(httpContext => + { + httpContext.Response.OnStarting(() => + { + // Change response to chunked + httpContext.Response.ContentLength = null; + return TaskCache.CompletedTask; + }); + + var response = Encoding.ASCII.GetBytes("hello, world"); + httpContext.Response.ContentLength = response.Length - 1; + + // If OnStarting is not run before verifying writes, an error response will be sent. + httpContext.Response.Body.Write(response, 0, response.Length); + return TaskCache.CompletedTask; + }, new TestServiceContext())) + { + using (var connection = server.CreateConnection()) + { + await connection.Send( + "GET / HTTP/1.1", + "", + ""); + await connection.Receive( + "HTTP/1.1 200 OK", + $"Date: {server.Context.DateHeaderValue}", + $"Transfer-Encoding: chunked", + "", + "c", + "hello, world", + "0", + "", + ""); + } + } + } + + [Fact] + public async Task SubsequentWriteVerifiedAfterOnStarting() + { + using (var server = new TestServer(httpContext => + { + httpContext.Response.OnStarting(() => + { + // Change response to chunked + httpContext.Response.ContentLength = null; + return TaskCache.CompletedTask; + }); + + var response = Encoding.ASCII.GetBytes("hello, world"); + httpContext.Response.ContentLength = response.Length - 1; + + // If OnStarting is not run before verifying writes, an error response will be sent. + httpContext.Response.Body.Write(response, 0, response.Length / 2); + httpContext.Response.Body.Write(response, response.Length / 2, response.Length - response.Length / 2); + return TaskCache.CompletedTask; + }, new TestServiceContext())) + { + using (var connection = server.CreateConnection()) + { + await connection.Send( + "GET / HTTP/1.1", + "", + ""); + await connection.Receive( + "HTTP/1.1 200 OK", + $"Date: {server.Context.DateHeaderValue}", + $"Transfer-Encoding: chunked", + "", + "6", + "hello,", + "6", + " world", + "0", + "", + ""); + } + } + } + + [Fact] + public async Task FirstWriteAsyncVerifiedAfterOnStarting() + { + using (var server = new TestServer(httpContext => + { + httpContext.Response.OnStarting(() => + { + // Change response to chunked + httpContext.Response.ContentLength = null; + return TaskCache.CompletedTask; + }); + + var response = Encoding.ASCII.GetBytes("hello, world"); + httpContext.Response.ContentLength = response.Length - 1; + + // If OnStarting is not run before verifying writes, an error response will be sent. + return httpContext.Response.Body.WriteAsync(response, 0, response.Length); + }, new TestServiceContext())) + { + using (var connection = server.CreateConnection()) + { + await connection.Send( + "GET / HTTP/1.1", + "", + ""); + await connection.Receive( + "HTTP/1.1 200 OK", + $"Date: {server.Context.DateHeaderValue}", + $"Transfer-Encoding: chunked", + "", + "c", + "hello, world", + "0", + "", + ""); + } + } + } + + [Fact] + public async Task SubsequentWriteAsyncVerifiedAfterOnStarting() + { + using (var server = new TestServer(async httpContext => + { + httpContext.Response.OnStarting(() => + { + // Change response to chunked + httpContext.Response.ContentLength = null; + return TaskCache.CompletedTask; + }); + + var response = Encoding.ASCII.GetBytes("hello, world"); + httpContext.Response.ContentLength = response.Length - 1; + + // If OnStarting is not run before verifying writes, an error response will be sent. + await httpContext.Response.Body.WriteAsync(response, 0, response.Length / 2); + await httpContext.Response.Body.WriteAsync(response, response.Length / 2, response.Length - response.Length / 2); + }, new TestServiceContext())) + { + using (var connection = server.CreateConnection()) + { + await connection.Send( + "GET / HTTP/1.1", + "", + ""); + await connection.Receive( + "HTTP/1.1 200 OK", + $"Date: {server.Context.DateHeaderValue}", + $"Transfer-Encoding: chunked", + "", + "6", + "hello,", + "6", + " world", + "0", + "", + ""); + } + } + } + public static TheoryData NullHeaderData { get diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs index 650fcedbe1..35144e1f26 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs @@ -883,9 +883,8 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [MemberData(nameof(ConnectionFilterData))] public async Task ThrowingInOnStartingResultsInFailedWritesAnd500Response(TestServiceContext testContext) { - var onStartingCallCount1 = 0; - var onStartingCallCount2 = 0; - var failedWriteCount = 0; + var callback1Called = false; + var callback2CallCount = 0; var testLogger = new TestApplicationErrorLogger(); testContext.Log = new KestrelTrace(testLogger); @@ -897,23 +896,17 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var response = httpContext.Response; response.OnStarting(_ => { - onStartingCallCount1++; + callback1Called = true; throw onStartingException; }, null); response.OnStarting(_ => { - onStartingCallCount2++; + callback2CallCount++; throw onStartingException; }, null); - response.Headers["Content-Length"] = new[] { "11" }; - - var writeException = await Assert.ThrowsAsync(async () => - await response.Body.WriteAsync(Encoding.ASCII.GetBytes("Hello World"), 0, 11)); - + var writeException = await Assert.ThrowsAsync(async () => await response.Body.FlushAsync()); Assert.Same(onStartingException, writeException.InnerException); - - failedWriteCount++; }, testContext)) { using (var connection = server.CreateConnection()) @@ -943,10 +936,10 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } } - // The first registered OnStarting callback should not be called, + // The first registered OnStarting callback should not have been called, // since they are called LIFO and the other one failed. - Assert.Equal(0, onStartingCallCount1); - Assert.Equal(2, onStartingCallCount2); + Assert.False(callback1Called); + Assert.Equal(2, callback2CallCount); Assert.Equal(2, testLogger.ApplicationErrorsLogged); } From 1a2c4388991c0583909f9c9d6e2f6aea48efa915 Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Wed, 18 Jan 2017 15:17:00 -0800 Subject: [PATCH 1034/1662] Upgrade to RC.3 --- KestrelHttpServer.sln | 122 ++++++++++++++---- NuGet.config | 2 + appveyor.yml | 3 +- build.ps1 | 14 +- build.sh | 20 +-- {tools => build}/Key.snk | Bin build/common.props | 24 ++++ global.json | 8 -- makefile.shade | 45 +------ .../LargeResponseApp/LargeResponseApp.csproj | 16 +++ .../LargeResponseApp/LargeResponseApp.xproj | 18 --- samples/LargeResponseApp/project.json | 30 ----- .../runtimeconfig.template.json | 5 + samples/SampleApp/SampleApp.csproj | 24 ++++ samples/SampleApp/SampleApp.xproj | 17 --- samples/SampleApp/project.json | 32 ----- samples/SampleApp/runtimeconfig.template.json | 5 + ...oft.AspNetCore.Server.Kestrel.Https.csproj | 22 ++++ ...soft.AspNetCore.Server.Kestrel.Https.xproj | 17 --- .../Properties/AssemblyInfo.cs | 11 -- .../project.json | 40 ------ ...Microsoft.AspNetCore.Server.Kestrel.csproj | 29 +++++ .../Microsoft.AspNetCore.Server.Kestrel.xproj | 17 --- .../Properties/AssemblyInfo.cs | 5 - .../project.json | 55 -------- .../AddressRegistrationTests.cs | 2 +- .../HttpClientSlimTests.cs | 5 +- .../HttpsTests.cs | 14 +- .../LoggingConnectionAdapterTests.cs | 2 +- .../MaxRequestBufferSizeTests.cs | 8 +- ...Core.Server.Kestrel.FunctionalTests.csproj | 48 +++++++ ...tCore.Server.Kestrel.FunctionalTests.xproj | 20 --- .../Properties/AssemblyInfo.cs | 8 ++ .../project.json | 55 -------- .../.notest | 0 ...pNetCore.Server.Kestrel.Performance.csproj | 25 ++++ ...spNetCore.Server.Kestrel.Performance.xproj | 22 ---- .../Writing.cs | 1 + .../configs/Core12Toolchain.cs | 64 --------- .../configs/CoreConfig.cs | 19 ++- .../configs/MsBuildExecutor.cs | 69 ++++++++++ .../configs/MsBuildGenerator.cs | 61 +++++++++ .../configs/MsBuildToolchain.cs | 28 ++++ .../global.json | 8 -- .../project.json | 45 ------- .../runtimeconfig.template.json | 5 + .../BadHttpRequestTests.cs | 2 +- .../HttpsConnectionAdapterTests.cs | 2 +- ...soft.AspNetCore.Server.KestrelTests.csproj | 32 +++++ ...osoft.AspNetCore.Server.KestrelTests.xproj | 20 --- .../TestResources/testCert.pfx | Bin 2483 -> 0 bytes .../project.json | 51 -------- test/shared/TestResources.cs | 20 +++ .../TestResources/testCert.pfx | Bin ...etCore.Server.Kestrel.GeneratedCode.csproj | 15 +++ ...NetCore.Server.Kestrel.GeneratedCode.xproj | 17 --- .../project.json | 27 ---- version.props | 7 + 58 files changed, 591 insertions(+), 692 deletions(-) rename {tools => build}/Key.snk (100%) create mode 100644 build/common.props delete mode 100644 global.json create mode 100644 samples/LargeResponseApp/LargeResponseApp.csproj delete mode 100644 samples/LargeResponseApp/LargeResponseApp.xproj delete mode 100644 samples/LargeResponseApp/project.json create mode 100644 samples/LargeResponseApp/runtimeconfig.template.json create mode 100644 samples/SampleApp/SampleApp.csproj delete mode 100644 samples/SampleApp/SampleApp.xproj delete mode 100644 samples/SampleApp/project.json create mode 100644 samples/SampleApp/runtimeconfig.template.json create mode 100644 src/Microsoft.AspNetCore.Server.Kestrel.Https/Microsoft.AspNetCore.Server.Kestrel.Https.csproj delete mode 100644 src/Microsoft.AspNetCore.Server.Kestrel.Https/Microsoft.AspNetCore.Server.Kestrel.Https.xproj delete mode 100644 src/Microsoft.AspNetCore.Server.Kestrel.Https/Properties/AssemblyInfo.cs delete mode 100644 src/Microsoft.AspNetCore.Server.Kestrel.Https/project.json create mode 100644 src/Microsoft.AspNetCore.Server.Kestrel/Microsoft.AspNetCore.Server.Kestrel.csproj delete mode 100644 src/Microsoft.AspNetCore.Server.Kestrel/Microsoft.AspNetCore.Server.Kestrel.xproj delete mode 100644 src/Microsoft.AspNetCore.Server.Kestrel/project.json create mode 100644 test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests.csproj delete mode 100644 test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests.xproj create mode 100644 test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/Properties/AssemblyInfo.cs delete mode 100644 test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json create mode 100644 test/Microsoft.AspNetCore.Server.Kestrel.Performance/.notest create mode 100644 test/Microsoft.AspNetCore.Server.Kestrel.Performance/Microsoft.AspNetCore.Server.Kestrel.Performance.csproj delete mode 100644 test/Microsoft.AspNetCore.Server.Kestrel.Performance/Microsoft.AspNetCore.Server.Kestrel.Performance.xproj delete mode 100644 test/Microsoft.AspNetCore.Server.Kestrel.Performance/configs/Core12Toolchain.cs create mode 100644 test/Microsoft.AspNetCore.Server.Kestrel.Performance/configs/MsBuildExecutor.cs create mode 100644 test/Microsoft.AspNetCore.Server.Kestrel.Performance/configs/MsBuildGenerator.cs create mode 100644 test/Microsoft.AspNetCore.Server.Kestrel.Performance/configs/MsBuildToolchain.cs delete mode 100644 test/Microsoft.AspNetCore.Server.Kestrel.Performance/global.json delete mode 100644 test/Microsoft.AspNetCore.Server.Kestrel.Performance/project.json create mode 100644 test/Microsoft.AspNetCore.Server.Kestrel.Performance/runtimeconfig.template.json create mode 100644 test/Microsoft.AspNetCore.Server.KestrelTests/Microsoft.AspNetCore.Server.KestrelTests.csproj delete mode 100644 test/Microsoft.AspNetCore.Server.KestrelTests/Microsoft.AspNetCore.Server.KestrelTests.xproj delete mode 100644 test/Microsoft.AspNetCore.Server.KestrelTests/TestResources/testCert.pfx delete mode 100644 test/Microsoft.AspNetCore.Server.KestrelTests/project.json create mode 100644 test/shared/TestResources.cs rename test/{Microsoft.AspNetCore.Server.Kestrel.FunctionalTests => shared}/TestResources/testCert.pfx (100%) create mode 100644 tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode.csproj delete mode 100644 tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode.xproj delete mode 100644 tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/project.json create mode 100644 version.props diff --git a/KestrelHttpServer.sln b/KestrelHttpServer.sln index 5773d78aa9..cceaccce52 100644 --- a/KestrelHttpServer.sln +++ b/KestrelHttpServer.sln @@ -1,37 +1,22 @@ Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 14 -VisualStudioVersion = 14.0.25420.1 +# Visual Studio 15 +VisualStudioVersion = 15.0.26117.0 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNetCore.Server.Kestrel", "src\Microsoft.AspNetCore.Server.Kestrel\Microsoft.AspNetCore.Server.Kestrel.xproj", "{F510611A-3BEE-4B88-A613-5F4A74ED82A1}" -EndProject -Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNetCore.Server.KestrelTests", "test\Microsoft.AspNetCore.Server.KestrelTests\Microsoft.AspNetCore.Server.KestrelTests.xproj", "{37F3BFB2-6454-49E5-9D7F-581BF755CCFE}" -EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{7972A5D6-3385-4127-9277-428506DD44FF}" ProjectSection(SolutionItems) = preProject build.cmd = build.cmd - global.json = global.json makefile.shade = makefile.shade NuGet.Config = NuGet.Config EndProjectSection EndProject -Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "SampleApp", "samples\SampleApp\SampleApp.xproj", "{2C3CB3DC-EEBF-4F52-9E1C-4F2F972E76C3}" -EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{2D5D5227-4DBD-499A-96B1-76A36B03B750}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{D3273454-EA07-41D2-BF0B-FCC3675C2483}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "samples", "samples", "{8A3D00B8-1CCF-4BE6-A060-11104CE2D9CE}" EndProject -Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "LargeResponseApp", "samples\LargeResponseApp\LargeResponseApp.xproj", "{B35D4D31-E74C-4646-8A11-7A7A40F0021E}" -EndProject -Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNetCore.Server.Kestrel.GeneratedCode", "tools\Microsoft.AspNetCore.Server.Kestrel.GeneratedCode\Microsoft.AspNetCore.Server.Kestrel.GeneratedCode.xproj", "{BD2D4D29-1BD9-40D0-BB31-337D5416B63C}" -EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tools", "tools", "{327F7880-D9AF-46BD-B45C-3B7E34A01DFD}" EndProject -Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNetCore.Server.Kestrel.Https", "src\Microsoft.AspNetCore.Server.Kestrel.Https\Microsoft.AspNetCore.Server.Kestrel.Https.xproj", "{5F64B3C3-0C2E-431A-B820-A81BBFC863DA}" -EndProject -Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNetCore.Server.Kestrel.FunctionalTests", "test\Microsoft.AspNetCore.Server.Kestrel.FunctionalTests\Microsoft.AspNetCore.Server.Kestrel.FunctionalTests.xproj", "{9559A5F1-080C-4909-B6CF-7E4B3DC55748}" -EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "shared", "shared", "{0EF2ACDF-012F-4472-A13A-4272419E2903}" ProjectSection(SolutionItems) = preProject test\shared\DummyApplication.cs = test\shared\DummyApplication.cs @@ -48,55 +33,144 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "shared", "shared", "{0EF2AC test\shared\TestConnection.cs = test\shared\TestConnection.cs test\shared\TestFrame.cs = test\shared\TestFrame.cs test\shared\TestKestrelTrace.cs = test\shared\TestKestrelTrace.cs + test\shared\TestResources.cs = test\shared\TestResources.cs test\shared\TestServer.cs = test\shared\TestServer.cs test\shared\TestServiceContext.cs = test\shared\TestServiceContext.cs EndProjectSection EndProject -Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNetCore.Server.Kestrel.Performance", "test\Microsoft.AspNetCore.Server.Kestrel.Performance\Microsoft.AspNetCore.Server.Kestrel.Performance.xproj", "{70567566-524C-4B67-9B59-E5C206D6C2EB}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Server.Kestrel", "src\Microsoft.AspNetCore.Server.Kestrel\Microsoft.AspNetCore.Server.Kestrel.csproj", "{F510611A-3BEE-4B88-A613-5F4A74ED82A1}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Server.KestrelTests", "test\Microsoft.AspNetCore.Server.KestrelTests\Microsoft.AspNetCore.Server.KestrelTests.csproj", "{37F3BFB2-6454-49E5-9D7F-581BF755CCFE}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SampleApp", "samples\SampleApp\SampleApp.csproj", "{2C3CB3DC-EEBF-4F52-9E1C-4F2F972E76C3}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LargeResponseApp", "samples\LargeResponseApp\LargeResponseApp.csproj", "{B35D4D31-E74C-4646-8A11-7A7A40F0021E}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Server.Kestrel.GeneratedCode", "tools\Microsoft.AspNetCore.Server.Kestrel.GeneratedCode\Microsoft.AspNetCore.Server.Kestrel.GeneratedCode.csproj", "{BD2D4D29-1BD9-40D0-BB31-337D5416B63C}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Server.Kestrel.Https", "src\Microsoft.AspNetCore.Server.Kestrel.Https\Microsoft.AspNetCore.Server.Kestrel.Https.csproj", "{5F64B3C3-0C2E-431A-B820-A81BBFC863DA}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Server.Kestrel.FunctionalTests", "test\Microsoft.AspNetCore.Server.Kestrel.FunctionalTests\Microsoft.AspNetCore.Server.Kestrel.FunctionalTests.csproj", "{9559A5F1-080C-4909-B6CF-7E4B3DC55748}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Server.Kestrel.Performance", "test\Microsoft.AspNetCore.Server.Kestrel.Performance\Microsoft.AspNetCore.Server.Kestrel.Performance.csproj", "{EBFE9719-A44B-4978-A71F-D5C254E7F35A}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "TestResources", "TestResources", "{2822C132-BFFB-4D53-AC5B-E7E47DD81A6E}" + ProjectSection(SolutionItems) = preProject + test\shared\TestResources\testCert.pfx = test\shared\TestResources\testCert.pfx + EndProjectSection EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 Release|Any CPU = Release|Any CPU + Release|x64 = Release|x64 + Release|x86 = Release|x86 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution {F510611A-3BEE-4B88-A613-5F4A74ED82A1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {F510611A-3BEE-4B88-A613-5F4A74ED82A1}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F510611A-3BEE-4B88-A613-5F4A74ED82A1}.Debug|x64.ActiveCfg = Debug|x64 + {F510611A-3BEE-4B88-A613-5F4A74ED82A1}.Debug|x64.Build.0 = Debug|x64 + {F510611A-3BEE-4B88-A613-5F4A74ED82A1}.Debug|x86.ActiveCfg = Debug|x86 + {F510611A-3BEE-4B88-A613-5F4A74ED82A1}.Debug|x86.Build.0 = Debug|x86 {F510611A-3BEE-4B88-A613-5F4A74ED82A1}.Release|Any CPU.ActiveCfg = Release|Any CPU {F510611A-3BEE-4B88-A613-5F4A74ED82A1}.Release|Any CPU.Build.0 = Release|Any CPU + {F510611A-3BEE-4B88-A613-5F4A74ED82A1}.Release|x64.ActiveCfg = Release|x64 + {F510611A-3BEE-4B88-A613-5F4A74ED82A1}.Release|x64.Build.0 = Release|x64 + {F510611A-3BEE-4B88-A613-5F4A74ED82A1}.Release|x86.ActiveCfg = Release|x86 + {F510611A-3BEE-4B88-A613-5F4A74ED82A1}.Release|x86.Build.0 = Release|x86 {37F3BFB2-6454-49E5-9D7F-581BF755CCFE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {37F3BFB2-6454-49E5-9D7F-581BF755CCFE}.Debug|Any CPU.Build.0 = Debug|Any CPU + {37F3BFB2-6454-49E5-9D7F-581BF755CCFE}.Debug|x64.ActiveCfg = Debug|x64 + {37F3BFB2-6454-49E5-9D7F-581BF755CCFE}.Debug|x64.Build.0 = Debug|x64 + {37F3BFB2-6454-49E5-9D7F-581BF755CCFE}.Debug|x86.ActiveCfg = Debug|x86 + {37F3BFB2-6454-49E5-9D7F-581BF755CCFE}.Debug|x86.Build.0 = Debug|x86 {37F3BFB2-6454-49E5-9D7F-581BF755CCFE}.Release|Any CPU.ActiveCfg = Release|Any CPU {37F3BFB2-6454-49E5-9D7F-581BF755CCFE}.Release|Any CPU.Build.0 = Release|Any CPU + {37F3BFB2-6454-49E5-9D7F-581BF755CCFE}.Release|x64.ActiveCfg = Release|x64 + {37F3BFB2-6454-49E5-9D7F-581BF755CCFE}.Release|x64.Build.0 = Release|x64 + {37F3BFB2-6454-49E5-9D7F-581BF755CCFE}.Release|x86.ActiveCfg = Release|x86 + {37F3BFB2-6454-49E5-9D7F-581BF755CCFE}.Release|x86.Build.0 = Release|x86 {2C3CB3DC-EEBF-4F52-9E1C-4F2F972E76C3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {2C3CB3DC-EEBF-4F52-9E1C-4F2F972E76C3}.Debug|Any CPU.Build.0 = Debug|Any CPU + {2C3CB3DC-EEBF-4F52-9E1C-4F2F972E76C3}.Debug|x64.ActiveCfg = Debug|x64 + {2C3CB3DC-EEBF-4F52-9E1C-4F2F972E76C3}.Debug|x64.Build.0 = Debug|x64 + {2C3CB3DC-EEBF-4F52-9E1C-4F2F972E76C3}.Debug|x86.ActiveCfg = Debug|x86 + {2C3CB3DC-EEBF-4F52-9E1C-4F2F972E76C3}.Debug|x86.Build.0 = Debug|x86 {2C3CB3DC-EEBF-4F52-9E1C-4F2F972E76C3}.Release|Any CPU.ActiveCfg = Release|Any CPU {2C3CB3DC-EEBF-4F52-9E1C-4F2F972E76C3}.Release|Any CPU.Build.0 = Release|Any CPU + {2C3CB3DC-EEBF-4F52-9E1C-4F2F972E76C3}.Release|x64.ActiveCfg = Release|x64 + {2C3CB3DC-EEBF-4F52-9E1C-4F2F972E76C3}.Release|x64.Build.0 = Release|x64 + {2C3CB3DC-EEBF-4F52-9E1C-4F2F972E76C3}.Release|x86.ActiveCfg = Release|x86 + {2C3CB3DC-EEBF-4F52-9E1C-4F2F972E76C3}.Release|x86.Build.0 = Release|x86 {B35D4D31-E74C-4646-8A11-7A7A40F0021E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {B35D4D31-E74C-4646-8A11-7A7A40F0021E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B35D4D31-E74C-4646-8A11-7A7A40F0021E}.Debug|x64.ActiveCfg = Debug|x64 + {B35D4D31-E74C-4646-8A11-7A7A40F0021E}.Debug|x64.Build.0 = Debug|x64 + {B35D4D31-E74C-4646-8A11-7A7A40F0021E}.Debug|x86.ActiveCfg = Debug|x86 + {B35D4D31-E74C-4646-8A11-7A7A40F0021E}.Debug|x86.Build.0 = Debug|x86 {B35D4D31-E74C-4646-8A11-7A7A40F0021E}.Release|Any CPU.ActiveCfg = Release|Any CPU {B35D4D31-E74C-4646-8A11-7A7A40F0021E}.Release|Any CPU.Build.0 = Release|Any CPU + {B35D4D31-E74C-4646-8A11-7A7A40F0021E}.Release|x64.ActiveCfg = Release|x64 + {B35D4D31-E74C-4646-8A11-7A7A40F0021E}.Release|x64.Build.0 = Release|x64 + {B35D4D31-E74C-4646-8A11-7A7A40F0021E}.Release|x86.ActiveCfg = Release|x86 + {B35D4D31-E74C-4646-8A11-7A7A40F0021E}.Release|x86.Build.0 = Release|x86 {BD2D4D29-1BD9-40D0-BB31-337D5416B63C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {BD2D4D29-1BD9-40D0-BB31-337D5416B63C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {BD2D4D29-1BD9-40D0-BB31-337D5416B63C}.Debug|x64.ActiveCfg = Debug|x64 + {BD2D4D29-1BD9-40D0-BB31-337D5416B63C}.Debug|x64.Build.0 = Debug|x64 + {BD2D4D29-1BD9-40D0-BB31-337D5416B63C}.Debug|x86.ActiveCfg = Debug|x86 + {BD2D4D29-1BD9-40D0-BB31-337D5416B63C}.Debug|x86.Build.0 = Debug|x86 {BD2D4D29-1BD9-40D0-BB31-337D5416B63C}.Release|Any CPU.ActiveCfg = Release|Any CPU {BD2D4D29-1BD9-40D0-BB31-337D5416B63C}.Release|Any CPU.Build.0 = Release|Any CPU + {BD2D4D29-1BD9-40D0-BB31-337D5416B63C}.Release|x64.ActiveCfg = Release|x64 + {BD2D4D29-1BD9-40D0-BB31-337D5416B63C}.Release|x64.Build.0 = Release|x64 + {BD2D4D29-1BD9-40D0-BB31-337D5416B63C}.Release|x86.ActiveCfg = Release|x86 + {BD2D4D29-1BD9-40D0-BB31-337D5416B63C}.Release|x86.Build.0 = Release|x86 {5F64B3C3-0C2E-431A-B820-A81BBFC863DA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {5F64B3C3-0C2E-431A-B820-A81BBFC863DA}.Debug|Any CPU.Build.0 = Debug|Any CPU + {5F64B3C3-0C2E-431A-B820-A81BBFC863DA}.Debug|x64.ActiveCfg = Debug|x64 + {5F64B3C3-0C2E-431A-B820-A81BBFC863DA}.Debug|x64.Build.0 = Debug|x64 + {5F64B3C3-0C2E-431A-B820-A81BBFC863DA}.Debug|x86.ActiveCfg = Debug|x86 + {5F64B3C3-0C2E-431A-B820-A81BBFC863DA}.Debug|x86.Build.0 = Debug|x86 {5F64B3C3-0C2E-431A-B820-A81BBFC863DA}.Release|Any CPU.ActiveCfg = Release|Any CPU {5F64B3C3-0C2E-431A-B820-A81BBFC863DA}.Release|Any CPU.Build.0 = Release|Any CPU + {5F64B3C3-0C2E-431A-B820-A81BBFC863DA}.Release|x64.ActiveCfg = Release|x64 + {5F64B3C3-0C2E-431A-B820-A81BBFC863DA}.Release|x64.Build.0 = Release|x64 + {5F64B3C3-0C2E-431A-B820-A81BBFC863DA}.Release|x86.ActiveCfg = Release|x86 + {5F64B3C3-0C2E-431A-B820-A81BBFC863DA}.Release|x86.Build.0 = Release|x86 {9559A5F1-080C-4909-B6CF-7E4B3DC55748}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {9559A5F1-080C-4909-B6CF-7E4B3DC55748}.Debug|Any CPU.Build.0 = Debug|Any CPU + {9559A5F1-080C-4909-B6CF-7E4B3DC55748}.Debug|x64.ActiveCfg = Debug|x64 + {9559A5F1-080C-4909-B6CF-7E4B3DC55748}.Debug|x64.Build.0 = Debug|x64 + {9559A5F1-080C-4909-B6CF-7E4B3DC55748}.Debug|x86.ActiveCfg = Debug|x86 + {9559A5F1-080C-4909-B6CF-7E4B3DC55748}.Debug|x86.Build.0 = Debug|x86 {9559A5F1-080C-4909-B6CF-7E4B3DC55748}.Release|Any CPU.ActiveCfg = Release|Any CPU {9559A5F1-080C-4909-B6CF-7E4B3DC55748}.Release|Any CPU.Build.0 = Release|Any CPU - {70567566-524C-4B67-9B59-E5C206D6C2EB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {70567566-524C-4B67-9B59-E5C206D6C2EB}.Debug|Any CPU.Build.0 = Debug|Any CPU - {70567566-524C-4B67-9B59-E5C206D6C2EB}.Release|Any CPU.ActiveCfg = Release|Any CPU - {70567566-524C-4B67-9B59-E5C206D6C2EB}.Release|Any CPU.Build.0 = Release|Any CPU + {9559A5F1-080C-4909-B6CF-7E4B3DC55748}.Release|x64.ActiveCfg = Release|x64 + {9559A5F1-080C-4909-B6CF-7E4B3DC55748}.Release|x64.Build.0 = Release|x64 + {9559A5F1-080C-4909-B6CF-7E4B3DC55748}.Release|x86.ActiveCfg = Release|x86 + {9559A5F1-080C-4909-B6CF-7E4B3DC55748}.Release|x86.Build.0 = Release|x86 + {EBFE9719-A44B-4978-A71F-D5C254E7F35A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {EBFE9719-A44B-4978-A71F-D5C254E7F35A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {EBFE9719-A44B-4978-A71F-D5C254E7F35A}.Debug|x64.ActiveCfg = Debug|x64 + {EBFE9719-A44B-4978-A71F-D5C254E7F35A}.Debug|x64.Build.0 = Debug|x64 + {EBFE9719-A44B-4978-A71F-D5C254E7F35A}.Debug|x86.ActiveCfg = Debug|x86 + {EBFE9719-A44B-4978-A71F-D5C254E7F35A}.Debug|x86.Build.0 = Debug|x86 + {EBFE9719-A44B-4978-A71F-D5C254E7F35A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {EBFE9719-A44B-4978-A71F-D5C254E7F35A}.Release|Any CPU.Build.0 = Release|Any CPU + {EBFE9719-A44B-4978-A71F-D5C254E7F35A}.Release|x64.ActiveCfg = Release|x64 + {EBFE9719-A44B-4978-A71F-D5C254E7F35A}.Release|x64.Build.0 = Release|x64 + {EBFE9719-A44B-4978-A71F-D5C254E7F35A}.Release|x86.ActiveCfg = Release|x86 + {EBFE9719-A44B-4978-A71F-D5C254E7F35A}.Release|x86.Build.0 = Release|x86 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection GlobalSection(NestedProjects) = preSolution + {0EF2ACDF-012F-4472-A13A-4272419E2903} = {D3273454-EA07-41D2-BF0B-FCC3675C2483} {F510611A-3BEE-4B88-A613-5F4A74ED82A1} = {2D5D5227-4DBD-499A-96B1-76A36B03B750} {37F3BFB2-6454-49E5-9D7F-581BF755CCFE} = {D3273454-EA07-41D2-BF0B-FCC3675C2483} {2C3CB3DC-EEBF-4F52-9E1C-4F2F972E76C3} = {8A3D00B8-1CCF-4BE6-A060-11104CE2D9CE} @@ -104,7 +178,7 @@ Global {BD2D4D29-1BD9-40D0-BB31-337D5416B63C} = {327F7880-D9AF-46BD-B45C-3B7E34A01DFD} {5F64B3C3-0C2E-431A-B820-A81BBFC863DA} = {2D5D5227-4DBD-499A-96B1-76A36B03B750} {9559A5F1-080C-4909-B6CF-7E4B3DC55748} = {D3273454-EA07-41D2-BF0B-FCC3675C2483} - {0EF2ACDF-012F-4472-A13A-4272419E2903} = {D3273454-EA07-41D2-BF0B-FCC3675C2483} - {70567566-524C-4B67-9B59-E5C206D6C2EB} = {D3273454-EA07-41D2-BF0B-FCC3675C2483} + {EBFE9719-A44B-4978-A71F-D5C254E7F35A} = {D3273454-EA07-41D2-BF0B-FCC3675C2483} + {2822C132-BFFB-4D53-AC5B-E7E47DD81A6E} = {0EF2ACDF-012F-4472-A13A-4272419E2903} EndGlobalSection EndGlobal diff --git a/NuGet.config b/NuGet.config index 826a1f9035..7e1d6d073e 100644 --- a/NuGet.config +++ b/NuGet.config @@ -2,6 +2,8 @@ + + \ No newline at end of file diff --git a/appveyor.yml b/appveyor.yml index be95b88d6f..7617e58a1e 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -10,4 +10,5 @@ build_script: - build.cmd --quiet verify clone_depth: 1 test: off -deploy: off \ No newline at end of file +deploy: off +os: Visual Studio 2017 RC \ No newline at end of file diff --git a/build.ps1 b/build.ps1 index 8f2f99691a..f780c43a82 100644 --- a/build.ps1 +++ b/build.ps1 @@ -1,6 +1,6 @@ $ErrorActionPreference = "Stop" -function DownloadWithRetry([string] $url, [string] $downloadLocation, [int] $retries) +function DownloadWithRetry([string] $url, [string] $downloadLocation, [int] $retries) { while($true) { @@ -19,7 +19,7 @@ function DownloadWithRetry([string] $url, [string] $downloadLocation, [int] $ret Start-Sleep -Seconds 10 } - else + else { $exception = $_.Exception throw $exception @@ -33,7 +33,7 @@ cd $PSScriptRoot $repoFolder = $PSScriptRoot $env:REPO_FOLDER = $repoFolder -$koreBuildZip="https://github.com/aspnet/KoreBuild/archive/dev.zip" +$koreBuildZip="https://github.com/aspnet/KoreBuild/archive/feature/msbuild.zip" if ($env:KOREBUILD_ZIP) { $koreBuildZip=$env:KOREBUILD_ZIP @@ -43,18 +43,18 @@ $buildFolder = ".build" $buildFile="$buildFolder\KoreBuild.ps1" if (!(Test-Path $buildFolder)) { - Write-Host "Downloading KoreBuild from $koreBuildZip" - + Write-Host "Downloading KoreBuild from $koreBuildZip" + $tempFolder=$env:TEMP + "\KoreBuild-" + [guid]::NewGuid() New-Item -Path "$tempFolder" -Type directory | Out-Null $localZipFile="$tempFolder\korebuild.zip" - + DownloadWithRetry -url $koreBuildZip -downloadLocation $localZipFile -retries 6 Add-Type -AssemblyName System.IO.Compression.FileSystem [System.IO.Compression.ZipFile]::ExtractToDirectory($localZipFile, $tempFolder) - + New-Item -Path "$buildFolder" -Type directory | Out-Null copy-item "$tempFolder\**\build\*" $buildFolder -Recurse diff --git a/build.sh b/build.sh index 4fd7ede788..ff79789196 100755 --- a/build.sh +++ b/build.sh @@ -2,7 +2,7 @@ repoFolder="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" cd $repoFolder -koreBuildZip="https://github.com/aspnet/KoreBuild/archive/dev.zip" +koreBuildZip="https://github.com/aspnet/KoreBuild/archive/feature/msbuild.zip" if [ ! -z $KOREBUILD_ZIP ]; then koreBuildZip=$KOREBUILD_ZIP fi @@ -12,12 +12,12 @@ buildFile="$buildFolder/KoreBuild.sh" if test ! -d $buildFolder; then echo "Downloading KoreBuild from $koreBuildZip" - - tempFolder="/tmp/KoreBuild-$(uuidgen)" + + tempFolder="/tmp/KoreBuild-$(uuidgen)" mkdir $tempFolder - + localZipFile="$tempFolder/korebuild.zip" - + retries=6 until (wget -O $localZipFile $koreBuildZip 2>/dev/null || curl -o $localZipFile --location $koreBuildZip 2>/dev/null) do @@ -29,17 +29,17 @@ if test ! -d $buildFolder; then echo "Waiting 10 seconds before retrying. Retries left: $retries" sleep 10s done - + unzip -q -d $tempFolder $localZipFile - + mkdir $buildFolder cp -r $tempFolder/**/build/** $buildFolder - + chmod +x $buildFile - + # Cleanup if test -d $tempFolder; then - rm -rf $tempFolder + rm -rf $tempFolder fi fi diff --git a/tools/Key.snk b/build/Key.snk similarity index 100% rename from tools/Key.snk rename to build/Key.snk diff --git a/build/common.props b/build/common.props new file mode 100644 index 0000000000..9574eadb58 --- /dev/null +++ b/build/common.props @@ -0,0 +1,24 @@ + + + + + Microsoft ASP.NET Core + https://github.com/aspnet/KestrelHttpServer + git + $(MSBuildThisFileDirectory)Key.snk + true + true + 1.2.0-* + 1.6.2-* + $(VersionSuffix)-$(BuildNumber) + + + + + + + + + + + \ No newline at end of file diff --git a/global.json b/global.json deleted file mode 100644 index 0ad1995dd2..0000000000 --- a/global.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "projects": [ - "src" - ], - "sdk": { - "version": "1.0.0-preview2-1-003180" - } -} \ No newline at end of file diff --git a/makefile.shade b/makefile.shade index afc4c24b2a..58a82b5a00 100644 --- a/makefile.shade +++ b/makefile.shade @@ -1,6 +1,3 @@ -use namespace="System.Diagnostics" -use namespace="System.IO" - var VERSION='0.1' var FULL_VERSION='0.1' var AUTHORS='Microsoft' @@ -10,44 +7,4 @@ k-standard-goals custom-goals #initialize - @{ - if (Directory.Exists("src")) - { - Exec("dotnet", - commandline: "run -p ../../tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode Internal/Http/FrameHeaders.Generated.cs Internal/Http/Frame.Generated.cs", - workingdir: Path.Combine(Directory.GetCurrentDirectory(), "src/Microsoft.AspNetCore.Server.Kestrel")); - } - - if (IsOSX()) - { - var noParallelTestProjects = Environment.GetEnvironmentVariable("NO_PARALLEL_TEST_PROJECTS") ?? string.Empty; - noParallelTestProjects += ",Microsoft.AspNetCore.Server.Kestrel.FunctionalTests"; - Environment.SetEnvironmentVariable("NO_PARALLEL_TEST_PROJECTS", noParallelTestProjects); - } - } - -functions @{ - bool IsOSX() - { - if (!IsLinux) - { - return false; - } - - var processStartInfo = new ProcessStartInfo - { - FileName = "uname", - RedirectStandardOutput = true, - UseShellExecute = false - }; - var output = string.Empty; - - using (var process = Process.Start(processStartInfo)) - { - output = process.StandardOutput.ReadToEnd(); - process.WaitForExit(); - } - - return output.StartsWith("Darwin"); - } -} \ No newline at end of file + dotnet command='run -f netcoreapp1.1 -p tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode.csproj src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameHeaders.Generated.cs src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.Generated.cs' \ No newline at end of file diff --git a/samples/LargeResponseApp/LargeResponseApp.csproj b/samples/LargeResponseApp/LargeResponseApp.csproj new file mode 100644 index 0000000000..0149ac0ba2 --- /dev/null +++ b/samples/LargeResponseApp/LargeResponseApp.csproj @@ -0,0 +1,16 @@ + + + + + + net451;netcoreapp1.1 + Exe + + win7-x64 + + + + + + + \ No newline at end of file diff --git a/samples/LargeResponseApp/LargeResponseApp.xproj b/samples/LargeResponseApp/LargeResponseApp.xproj deleted file mode 100644 index 3f742acc02..0000000000 --- a/samples/LargeResponseApp/LargeResponseApp.xproj +++ /dev/null @@ -1,18 +0,0 @@ - - - - 14.0 - $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) - - - - b35d4d31-e74c-4646-8a11-7a7a40f0021e - .\obj - .\bin\ - - - 2.0 - 42216 - - - \ No newline at end of file diff --git a/samples/LargeResponseApp/project.json b/samples/LargeResponseApp/project.json deleted file mode 100644 index a97b7a05bd..0000000000 --- a/samples/LargeResponseApp/project.json +++ /dev/null @@ -1,30 +0,0 @@ -{ - "version": "1.1.0-*", - "dependencies": { - "Microsoft.AspNetCore.Server.Kestrel": "1.2.0-*" - }, - "buildOptions": { - "emitEntryPoint": true - }, - "frameworks": { - "net451": {}, - "netcoreapp1.1": { - "dependencies": { - "Microsoft.NETCore.App": { - "version": "1.2.0-*", - "type": "platform" - } - } - } - }, - "publishOptions": { - "include": [ - "hosting.json" - ] - }, - "runtimeOptions": { - "configProperties": { - "System.GC.Server": true - } - } -} \ No newline at end of file diff --git a/samples/LargeResponseApp/runtimeconfig.template.json b/samples/LargeResponseApp/runtimeconfig.template.json new file mode 100644 index 0000000000..7305508a37 --- /dev/null +++ b/samples/LargeResponseApp/runtimeconfig.template.json @@ -0,0 +1,5 @@ +{ + "configProperties": { + "System.GC.Server": true + } +} \ No newline at end of file diff --git a/samples/SampleApp/SampleApp.csproj b/samples/SampleApp/SampleApp.csproj new file mode 100644 index 0000000000..e3feb7221a --- /dev/null +++ b/samples/SampleApp/SampleApp.csproj @@ -0,0 +1,24 @@ + + + + + + net451;netcoreapp1.1 + Exe + + win7-x64 + + + + + + + + + + + + + + + diff --git a/samples/SampleApp/SampleApp.xproj b/samples/SampleApp/SampleApp.xproj deleted file mode 100644 index 7728a1cab2..0000000000 --- a/samples/SampleApp/SampleApp.xproj +++ /dev/null @@ -1,17 +0,0 @@ - - - - 14.0 - $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) - - - - 2c3cb3dc-eebf-4f52-9e1c-4f2f972e76c3 - .\obj - .\bin\ - - - 2.0 - - - \ No newline at end of file diff --git a/samples/SampleApp/project.json b/samples/SampleApp/project.json deleted file mode 100644 index c7f940c21b..0000000000 --- a/samples/SampleApp/project.json +++ /dev/null @@ -1,32 +0,0 @@ -{ - "version": "1.1.0-*", - "dependencies": { - "Microsoft.AspNetCore.Server.Kestrel.Https": "1.2.0-*", - "Microsoft.Extensions.Logging.Console": "1.2.0-*" - }, - "buildOptions": { - "emitEntryPoint": true - }, - "frameworks": { - "net451": {}, - "netcoreapp1.1": { - "dependencies": { - "Microsoft.NETCore.App": { - "version": "1.2.0-*", - "type": "platform" - } - } - } - }, - "publishOptions": { - "include": [ - "hosting.json", - "testCert.pfx" - ] - }, - "runtimeOptions": { - "configProperties": { - "System.GC.Server": true - } - } -} \ No newline at end of file diff --git a/samples/SampleApp/runtimeconfig.template.json b/samples/SampleApp/runtimeconfig.template.json new file mode 100644 index 0000000000..7305508a37 --- /dev/null +++ b/samples/SampleApp/runtimeconfig.template.json @@ -0,0 +1,5 @@ +{ + "configProperties": { + "System.GC.Server": true + } +} \ No newline at end of file diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Https/Microsoft.AspNetCore.Server.Kestrel.Https.csproj b/src/Microsoft.AspNetCore.Server.Kestrel.Https/Microsoft.AspNetCore.Server.Kestrel.Https.csproj new file mode 100644 index 0000000000..95e5a0110d --- /dev/null +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Https/Microsoft.AspNetCore.Server.Kestrel.Https.csproj @@ -0,0 +1,22 @@ + + + + + + HTTPS support for the ASP.NET Core Kestrel cross-platform web server. + net451;netstandard1.3 + true + aspnetcore;kestrel + CS1591;$(NoWarn) + + + + + + + + + + + + diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Https/Microsoft.AspNetCore.Server.Kestrel.Https.xproj b/src/Microsoft.AspNetCore.Server.Kestrel.Https/Microsoft.AspNetCore.Server.Kestrel.Https.xproj deleted file mode 100644 index fb3eb70783..0000000000 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Https/Microsoft.AspNetCore.Server.Kestrel.Https.xproj +++ /dev/null @@ -1,17 +0,0 @@ - - - - 14.0 - $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) - - - - 5f64b3c3-0c2e-431a-b820-a81bbfc863da - .\obj - .\bin\ - - - 2.0 - - - \ No newline at end of file diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Https/Properties/AssemblyInfo.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Https/Properties/AssemblyInfo.cs deleted file mode 100644 index 76feceeff0..0000000000 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Https/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,11 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System.Reflection; -using System.Resources; - -[assembly: AssemblyMetadata("Serviceable", "True")] -[assembly: NeutralResourcesLanguage("en-us")] -[assembly: AssemblyCompany("Microsoft Corporation.")] -[assembly: AssemblyCopyright("© Microsoft Corporation. All rights reserved.")] -[assembly: AssemblyProduct("Microsoft ASP.NET Core")] diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Https/project.json b/src/Microsoft.AspNetCore.Server.Kestrel.Https/project.json deleted file mode 100644 index 22529c3013..0000000000 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Https/project.json +++ /dev/null @@ -1,40 +0,0 @@ -{ - "version": "1.2.0-*", - "description": "HTTPS support for the ASP.NET Core Kestrel cross-platform web server.", - "buildOptions": { - "keyFile": "../../tools/Key.snk", - "nowarn": [ - "CS1591" - ], - "warningsAsErrors": true, - "xmlDoc": true - }, - "packOptions": { - "repository": { - "type": "git", - "url": "git://github.com/aspnet/kestrelhttpserver" - }, - "tags": [ - "aspnetcore", - "kestrel" - ] - }, - "dependencies": { - "Microsoft.AspNetCore.Server.Kestrel": { - "target": "project" - }, - "Microsoft.Extensions.TaskCache.Sources": { - "version": "1.2.0-*", - "type": "build" - }, - "NETStandard.Library": "1.6.2-*" - }, - "frameworks": { - "net451": {}, - "netstandard1.3": { - "dependencies": { - "System.Net.Security": "4.4.0-*" - } - } - } -} \ No newline at end of file diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Microsoft.AspNetCore.Server.Kestrel.csproj b/src/Microsoft.AspNetCore.Server.Kestrel/Microsoft.AspNetCore.Server.Kestrel.csproj new file mode 100644 index 0000000000..bca637d906 --- /dev/null +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Microsoft.AspNetCore.Server.Kestrel.csproj @@ -0,0 +1,29 @@ + + + + + + ASP.NET Core Kestrel cross-platform web server. + net451;netstandard1.3 + true + aspnetcore;kestrel + true + CS1591;$(NoWarn) + + + + + + + + + + + + + + + + + + diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Microsoft.AspNetCore.Server.Kestrel.xproj b/src/Microsoft.AspNetCore.Server.Kestrel/Microsoft.AspNetCore.Server.Kestrel.xproj deleted file mode 100644 index 1e2963de0d..0000000000 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Microsoft.AspNetCore.Server.Kestrel.xproj +++ /dev/null @@ -1,17 +0,0 @@ - - - - 14.0 - $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) - - - - f510611a-3bee-4b88-a613-5f4a74ed82a1 - .\obj - .\bin\ - - - 2.0 - - - \ No newline at end of file diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Properties/AssemblyInfo.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Properties/AssemblyInfo.cs index 86b8eff609..a171d27c0f 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Properties/AssemblyInfo.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Properties/AssemblyInfo.cs @@ -8,8 +8,3 @@ using System.Runtime.CompilerServices; [assembly: InternalsVisibleTo("Microsoft.AspNetCore.Server.Kestrel.FunctionalTests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")] [assembly: InternalsVisibleTo("Microsoft.AspNetCore.Server.KestrelTests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")] [assembly: InternalsVisibleTo("Microsoft.AspNetCore.Server.Kestrel.Performance, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")] -[assembly: AssemblyMetadata("Serviceable", "True")] -[assembly: NeutralResourcesLanguage("en-us")] -[assembly: AssemblyCompany("Microsoft Corporation.")] -[assembly: AssemblyCopyright("© Microsoft Corporation. All rights reserved.")] -[assembly: AssemblyProduct("Microsoft ASP.NET Core")] diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/project.json b/src/Microsoft.AspNetCore.Server.Kestrel/project.json deleted file mode 100644 index fc40afeee6..0000000000 --- a/src/Microsoft.AspNetCore.Server.Kestrel/project.json +++ /dev/null @@ -1,55 +0,0 @@ -{ - "version": "1.2.0-*", - "description": "ASP.NET Core Kestrel cross-platform web server.", - "packOptions": { - "repository": { - "type": "git", - "url": "git://github.com/aspnet/kestrelhttpserver" - }, - "tags": [ - "aspnetcore", - "kestrel" - ] - }, - "dependencies": { - "Libuv": "1.10.0-*", - "Microsoft.AspNetCore.Hosting": "1.2.0-*", - "Microsoft.Extensions.Logging.Abstractions": "1.2.0-*", - "Microsoft.Extensions.TaskCache.Sources": { - "version": "1.2.0-*", - "type": "build" - }, - "NETStandard.Library": "1.6.2-*", - "System.Buffers": "4.4.0-*", - "System.Numerics.Vectors": "4.4.0-*", - "System.Threading.Tasks.Extensions": "4.4.0-*" - }, - "frameworks": { - "net451": { - "frameworkAssemblies": { - "System.Runtime": { - "type": "build" - }, - "System.Threading.Tasks": { - "type": "build" - } - } - }, - "netstandard1.3": { - "dependencies": { - "System.Diagnostics.Process": "4.4.0-*", - "System.Threading.Thread": "4.4.0-*", - "System.Threading.ThreadPool": "4.4.0-*" - } - } - }, - "buildOptions": { - "allowUnsafe": true, - "warningsAsErrors": true, - "keyFile": "../../tools/Key.snk", - "nowarn": [ - "CS1591" - ], - "xmlDoc": true - } -} \ No newline at end of file diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs index 0357f6ab4f..2abb129b52 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs @@ -106,7 +106,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { if (testUrl(listenOptions.IPEndPoint).StartsWith("https")) { - listenOptions.UseHttps("TestResources/testCert.pfx", "testPassword"); + listenOptions.UseHttps(TestResources.TestCertificatePath, "testPassword"); } }); }) diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/HttpClientSlimTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/HttpClientSlimTests.cs index 28c1b95773..7410d7d656 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/HttpClientSlimTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/HttpClientSlimTests.cs @@ -2,11 +2,8 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.IO; -using System.Linq; using System.Net; using System.Net.Http; -using System.Text; using System.Threading.Tasks; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; @@ -84,7 +81,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { if (protocol == "https") { - listenOptions.UseHttps("TestResources/testCert.pfx", "testPassword"); + listenOptions.UseHttps(TestResources.TestCertificatePath, "testPassword"); } }); }) diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/HttpsTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/HttpsTests.cs index c5c594f574..113ddc1830 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/HttpsTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/HttpsTests.cs @@ -32,7 +32,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { options.Listen(new IPEndPoint(IPAddress.Loopback, 0), listenOptions => { - listenOptions.UseHttps("TestResources/testCert.pfx", "testPassword"); + listenOptions.UseHttps(TestResources.TestCertificatePath, "testPassword"); }); }) .UseLoggerFactory(loggerFactory) @@ -65,7 +65,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { options.Listen(new IPEndPoint(IPAddress.Loopback, 0), listenOptions => { - listenOptions.UseHttps("TestResources/testCert.pfx", "testPassword"); + listenOptions.UseHttps(TestResources.TestCertificatePath, "testPassword"); }); }) .UseLoggerFactory(loggerFactory) @@ -94,14 +94,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [Fact] public async Task DoesNotThrowObjectDisposedExceptionOnConnectionAbort() { - var x509Certificate2 = new X509Certificate2("TestResources/testCert.pfx", "testPassword"); + var x509Certificate2 = new X509Certificate2(TestResources.TestCertificatePath, "testPassword"); var loggerFactory = new HandshakeErrorLoggerFactory(); var hostBuilder = new WebHostBuilder() .UseKestrel(options => { options.Listen(new IPEndPoint(IPAddress.Loopback, 0), listenOptions => { - listenOptions.UseHttps("TestResources/testCert.pfx", "testPassword"); + listenOptions.UseHttps(TestResources.TestCertificatePath, "testPassword"); }); }) .UseLoggerFactory(loggerFactory) @@ -147,14 +147,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests public async Task DoesNotThrowObjectDisposedExceptionFromWriteAsyncAfterConnectionIsAborted() { var tcs = new TaskCompletionSource(); - var x509Certificate2 = new X509Certificate2("TestResources/testCert.pfx", "testPassword"); + var x509Certificate2 = new X509Certificate2(TestResources.TestCertificatePath, "testPassword"); var loggerFactory = new HandshakeErrorLoggerFactory(); var hostBuilder = new WebHostBuilder() .UseKestrel(options => { options.Listen(new IPEndPoint(IPAddress.Loopback, 0), listenOptions => { - listenOptions.UseHttps("TestResources/testCert.pfx", "testPassword"); + listenOptions.UseHttps(TestResources.TestCertificatePath, "testPassword"); }); }) .UseLoggerFactory(loggerFactory) @@ -204,7 +204,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { options.Listen(new IPEndPoint(IPAddress.Loopback, 0), listenOptions => { - listenOptions.UseHttps("TestResources/testCert.pfx", "testPassword"); + listenOptions.UseHttps(TestResources.TestCertificatePath, "testPassword"); }); }) .UseLoggerFactory(loggerFactory) diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/LoggingConnectionAdapterTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/LoggingConnectionAdapterTests.cs index adff41264c..2b579ce3f0 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/LoggingConnectionAdapterTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/LoggingConnectionAdapterTests.cs @@ -23,7 +23,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests options.Listen(new IPEndPoint(IPAddress.Loopback, 0), listenOptions => { listenOptions.UseConnectionLogging(); - listenOptions.UseHttps("TestResources/testCert.pfx", "testPassword"); + listenOptions.UseHttps(TestResources.TestCertificatePath, "testPassword"); }); }) .Configure(app => diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/MaxRequestBufferSizeTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/MaxRequestBufferSizeTests.cs index a7116d6b07..2acd8f7f8d 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/MaxRequestBufferSizeTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/MaxRequestBufferSizeTests.cs @@ -1,4 +1,7 @@ -using System; +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; using System.Collections.Generic; using System.IO; using System.Linq; @@ -12,6 +15,7 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Testing; using Xunit; namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests @@ -171,7 +175,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { if (useSsl) { - listenOptions.UseHttps("TestResources/testCert.pfx", "testPassword"); + listenOptions.UseHttps(TestResources.TestCertificatePath, "testPassword"); } }); diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests.csproj b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests.csproj new file mode 100644 index 0000000000..c56280900c --- /dev/null +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests.csproj @@ -0,0 +1,48 @@ + + + + + + netcoreapp1.1 + $(TargetFrameworks);net451 + + win7-x64 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + $(DefineConstants);DARWIN + + + + \ No newline at end of file diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests.xproj b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests.xproj deleted file mode 100644 index 4c5139d367..0000000000 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests.xproj +++ /dev/null @@ -1,20 +0,0 @@ - - - - 14.0 - $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) - - - - 9559a5f1-080c-4909-b6cf-7e4b3dc55748 - .\obj - .\bin\ - - - 2.0 - - - - - - \ No newline at end of file diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/Properties/AssemblyInfo.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/Properties/AssemblyInfo.cs new file mode 100644 index 0000000000..e067e94cf3 --- /dev/null +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/Properties/AssemblyInfo.cs @@ -0,0 +1,8 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using Xunit; + +#if DARWIN +[assembly: CollectionBehavior(DisableTestParallelization = true)] +#endif diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json deleted file mode 100644 index f690fe4a65..0000000000 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json +++ /dev/null @@ -1,55 +0,0 @@ -{ - "version": "1.1.0-*", - "dependencies": { - "dotnet-test-xunit": "2.2.0-*", - "Microsoft.AspNetCore.Http.Abstractions": "1.2.0-*", - "Microsoft.AspNetCore.Server.Kestrel.Https": "1.2.0-*", - "Microsoft.AspNetCore.Testing": "1.2.0-*", - "Microsoft.Extensions.Logging.Testing": "1.2.0-*", - "Moq": "4.6.36-*", - "Newtonsoft.Json": "9.0.1", - "xunit": "2.2.0-*", - "Microsoft.CodeCoverage": { - "type": "build", - "version": "1.0.1" - } - }, - "frameworks": { - "netcoreapp1.1": { - "dependencies": { - "Microsoft.NETCore.App": { - "version": "1.2.0-*", - "type": "platform" - }, - "System.Net.Http.WinHttpHandler": "4.4.0-*", - "System.Net.NetworkInformation": "4.4.0-*", - "System.Runtime.Serialization.Primitives": "4.4.0-*" - }, - "imports": "dnxcore50" - }, - "net451": { - "frameworkAssemblies": { - "System.Net.Http": "4.0.0.0" - }, - "imports": "dnx451" - } - }, - "buildOptions": { - "allowUnsafe": true, - "compile": { - "include": [ - "../shared/**/*.cs" - ] - }, - "keyFile": "../../tools/Key.snk", - "copyToOutput": { - "include": "TestResources/testCert.pfx" - } - }, - "testRunner": "xunit", - "publishOptions": { - "include": [ - "TestResources/testCert.pfx" - ] - } -} \ No newline at end of file diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/.notest b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/.notest new file mode 100644 index 0000000000..e69de29bb2 diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Microsoft.AspNetCore.Server.Kestrel.Performance.csproj b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Microsoft.AspNetCore.Server.Kestrel.Performance.csproj new file mode 100644 index 0000000000..6f479fdb7a --- /dev/null +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Microsoft.AspNetCore.Server.Kestrel.Performance.csproj @@ -0,0 +1,25 @@ + + + + + + netcoreapp1.1 + Exe + + + + + + + + + + + + + + + + + + diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Microsoft.AspNetCore.Server.Kestrel.Performance.xproj b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Microsoft.AspNetCore.Server.Kestrel.Performance.xproj deleted file mode 100644 index 3bbc5601e0..0000000000 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Microsoft.AspNetCore.Server.Kestrel.Performance.xproj +++ /dev/null @@ -1,22 +0,0 @@ - - - - 14.0 - $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) - - - - 70567566-524c-4b67-9b59-e5c206d6c2eb - Microsoft.AspNetCore.Server.Kestrel.Performance - .\obj - .\bin\ - v4.6.2 - - - 2.0 - - - - - - \ No newline at end of file diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Writing.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Writing.cs index 39ac17d1c8..fdbc73d6c6 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Writing.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Writing.cs @@ -14,6 +14,7 @@ using Moq; namespace Microsoft.AspNetCore.Server.Kestrel.Performance { + [Config(typeof(CoreConfig))] public class Writing { private readonly TestFrame _frame; diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/configs/Core12Toolchain.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/configs/Core12Toolchain.cs deleted file mode 100644 index d9cfdc6aca..0000000000 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/configs/Core12Toolchain.cs +++ /dev/null @@ -1,64 +0,0 @@ -using System; -using System.Reflection; -using BenchmarkDotNet.Characteristics; -using BenchmarkDotNet.Environments; -using BenchmarkDotNet.Loggers; -using BenchmarkDotNet.Running; -using BenchmarkDotNet.Toolchains; -using BenchmarkDotNet.Toolchains.DotNetCli; - -namespace Microsoft.AspNetCore.Server.Kestrel.Performance -{ - public class Core12Toolchain : Toolchain - { - private const string TargetFrameworkMoniker = "netcoreapp1.1"; - - public static readonly IToolchain Instance = new Core12Toolchain(); - - public Core12Toolchain() - : base("Core12", - (IGenerator) Activator.CreateInstance(typeof(Toolchain).GetTypeInfo().Assembly.GetType("BenchmarkDotNet.Toolchains.DotNetCli.DotNetCliGenerator"), - TargetFrameworkMoniker, - GetExtraDependencies(), - (Func) (_ => "x64"), // dotnet cli supports only x64 compilation now - GetImports(), - GetRuntime()), - new DotNetCliBuilder(TargetFrameworkMoniker), - (IExecutor) Activator.CreateInstance(typeof(Toolchain).GetTypeInfo().Assembly.GetType("BenchmarkDotNet.Toolchains.Executor"))) - { - } - - public override bool IsSupported(Benchmark benchmark, ILogger logger, IResolver resolver) - { - if (!base.IsSupported(benchmark, logger, resolver)) - { - return false; - } - - return true; - } - - private static string GetExtraDependencies() - { - // do not set the type to platform in order to produce exe - // https://github.com/dotnet/core/issues/77#issuecomment-219692312 - return "\"dependencies\": { \"Microsoft.NETCore.App\": { \"version\": \"1.2-*\" } },"; - } - - private static string GetImports() - { - return "[ \"dnxcore50\", \"portable-net45+win8\", \"dotnet5.6\", \"netcore50\" ]"; - } - - private static string GetRuntime() - { - var currentRuntime = Microsoft.DotNet.InternalAbstractions.RuntimeEnvironment.GetRuntimeIdentifier(); ; - if (!string.IsNullOrEmpty(currentRuntime)) - { - return $"\"runtimes\": {{ \"{currentRuntime}\": {{ }} }},"; - } - - return string.Empty; - } - } -} diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/configs/CoreConfig.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/configs/CoreConfig.cs index 97fbd2d78e..391da34c72 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/configs/CoreConfig.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/configs/CoreConfig.cs @@ -15,16 +15,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance Add(JitOptimizationsValidator.FailOnError); Add(new RpsColumn()); - Add(Job.Default. - With(BenchmarkDotNet.Environments.Runtime.Core). - WithRemoveOutliers(false). - With(new GcMode() { Server = true }). - With(RunStrategy.Throughput). - WithLaunchCount(3). - WithWarmupCount(5). - WithTargetCount(10). - With(new Core12Toolchain()) - ); + Add(Job.Default + .With(BenchmarkDotNet.Environments.Runtime.Core) + .WithRemoveOutliers(false) + .With(new GcMode() { Server = true }) + .With(RunStrategy.Throughput) + .WithLaunchCount(3) + .WithWarmupCount(5) + .WithTargetCount(10) + .With(new MsBuildToolchain())); } } } diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/configs/MsBuildExecutor.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/configs/MsBuildExecutor.cs new file mode 100644 index 0000000000..c36449b6b8 --- /dev/null +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/configs/MsBuildExecutor.cs @@ -0,0 +1,69 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.IO; +using System.Reflection; +using BenchmarkDotNet.Characteristics; +using BenchmarkDotNet.Diagnosers; +using BenchmarkDotNet.Extensions; +using BenchmarkDotNet.Jobs; +using BenchmarkDotNet.Loggers; +using BenchmarkDotNet.Running; +using BenchmarkDotNet.Toolchains; +using BenchmarkDotNet.Toolchains.DotNetCli; +using BenchmarkDotNet.Toolchains.Results; + +namespace Microsoft.AspNetCore.Server.Kestrel.Performance +{ + public class MsBuildExecutor : IExecutor + { + public ExecuteResult Execute(BuildResult buildResult, Benchmark benchmark, ILogger logger, IResolver resolver, IDiagnoser diagnoser = null) + { + var workingDirectory = buildResult.ArtifactsPaths.BuildArtifactsDirectoryPath; + + using (var process = new Process { StartInfo = BuildDotNetProcessStartInfo(workingDirectory) }) + { + var loggerDiagnoserType = typeof(Toolchain).GetTypeInfo().Assembly.GetType("BenchmarkDotNet.Loggers.SynchronousProcessOutputLoggerWithDiagnoser"); + var loggerDiagnoser = Activator.CreateInstance( + loggerDiagnoserType, + new object[] { logger, process, diagnoser, benchmark }); + + process.Start(); + + var processInputMethodInfo = loggerDiagnoser.GetType().GetMethod("ProcessInput", BindingFlags.Instance | BindingFlags.NonPublic); + processInputMethodInfo.Invoke(loggerDiagnoser, null); + + process.WaitForExit(); + + if (process.ExitCode != 0) + { + return new ExecuteResult(true, process.ExitCode, new string[0], new string[0]); + } + + var linesWithResults = (IReadOnlyList)loggerDiagnoserType + .GetProperty("LinesWithResults", BindingFlags.Instance | BindingFlags.NonPublic) + .GetValue(loggerDiagnoser, null); + var linesWithExtraOutput = (IReadOnlyList)loggerDiagnoserType + .GetProperty("LinesWithExtraOutput", BindingFlags.Instance | BindingFlags.NonPublic) + .GetValue(loggerDiagnoser, null); + + return new ExecuteResult(true, process.ExitCode, linesWithResults, linesWithExtraOutput); + } + } + + private ProcessStartInfo BuildDotNetProcessStartInfo(string workingDirectory) + => new ProcessStartInfo + { + FileName = "dotnet", + WorkingDirectory = workingDirectory, + Arguments = "binaries/Benchmark.Generated.dll", + UseShellExecute = false, + CreateNoWindow = true, + RedirectStandardOutput = true, + RedirectStandardError = true + }; + } +} \ No newline at end of file diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/configs/MsBuildGenerator.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/configs/MsBuildGenerator.cs new file mode 100644 index 0000000000..a1bac17136 --- /dev/null +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/configs/MsBuildGenerator.cs @@ -0,0 +1,61 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.IO; +using BenchmarkDotNet.Characteristics; +using BenchmarkDotNet.Environments; +using BenchmarkDotNet.Helpers; +using BenchmarkDotNet.Jobs; +using BenchmarkDotNet.Running; +using BenchmarkDotNet.Toolchains; +using BenchmarkDotNet.Toolchains.DotNetCli; +using System.Reflection; + +namespace Microsoft.AspNetCore.Server.Kestrel.Performance +{ + public class MsBuildGenerator : DotNetCliGenerator + { + public MsBuildGenerator() + : base("netcoreapp1.1", null, (Func) (_ => "x64"), null, null) + { + } + + protected override string GetProjectFilePath(string binariesDirectoryPath) + => Path.Combine(binariesDirectoryPath, "Benchmark.Generated.csproj"); + + protected override void GenerateProject(Benchmark benchmark, ArtifactsPaths artifactsPaths, IResolver resolver) + { + var projectTemplate = @" + + + + + netcoreapp1.1 + true + Exe + + + + + + + + + + +"; + + var projectContent = SetCodeFileName(projectTemplate, Path.GetFileName(artifactsPaths.ProgramCodePath)); + File.WriteAllText(artifactsPaths.ProjectFilePath, projectContent); + + var runtimeConfigContent = @" +{ + ""configProperties"": { + ""System.GC.Server"": true + } +}"; + File.WriteAllText(Path.Combine(artifactsPaths.BuildArtifactsDirectoryPath, "runtimeConfig.template.json"), runtimeConfigContent); + } + } +} \ No newline at end of file diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/configs/MsBuildToolchain.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/configs/MsBuildToolchain.cs new file mode 100644 index 0000000000..a0bbda47db --- /dev/null +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/configs/MsBuildToolchain.cs @@ -0,0 +1,28 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using BenchmarkDotNet.Characteristics; +using BenchmarkDotNet.Environments; +using BenchmarkDotNet.Jobs; +using BenchmarkDotNet.Loggers; +using BenchmarkDotNet.Running; +using BenchmarkDotNet.Toolchains; +using BenchmarkDotNet.Toolchains.Core; +using BenchmarkDotNet.Toolchains.DotNetCli; + +namespace Microsoft.AspNetCore.Server.Kestrel.Performance +{ + public class MsBuildToolchain : Toolchain + { + private const string TargetFrameworkMoniker = "netcoreapp1.1"; + + public MsBuildToolchain() + : base("MsBuildCore", + new MsBuildGenerator(), + new DotNetCliBuilder(TargetFrameworkMoniker), + new MsBuildExecutor()) + { + } + } +} \ No newline at end of file diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/global.json b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/global.json deleted file mode 100644 index 19a079f795..0000000000 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/global.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "projects": [ - "..\\" - ], - "sdk": { - "version": "1.0.0-preview2-1-003180" - } -} \ No newline at end of file diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/project.json b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/project.json deleted file mode 100644 index 93c887405f..0000000000 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/project.json +++ /dev/null @@ -1,45 +0,0 @@ -{ - "version": "1.0.0-*", - "dependencies": { - "BenchmarkDotNet": "0.10.1", - "Microsoft.AspNetCore.Server.Kestrel": "1.2.0-*", - "Moq": "4.6.36-*" - }, - "frameworks": { - "netcoreapp1.1": { - "dependencies": { - "Microsoft.NETCore.App": { - "version": "1.2.0-*", - "type": "platform" - } - } - } - }, - "buildOptions": { - "emitEntryPoint": true, - "compile": { - "include": [ - "../shared/TestApplicationErrorLogger.cs", - "../shared/TestFrame.cs", - "../shared/TestKestrelTrace.cs", - "../shared/MockConnection.cs", - "../shared/MockSocketOutput.cs", - "../shared/SocketInputExtensions.cs" - ] - }, - "keyFile": "../../tools/Key.snk", - "copyToOutput": { - "include": "TestResources/testCert.pfx" - }, - }, - "runtimeOptions": { - "configProperties": { - "System.GC.Server": true - } - }, - "publishOptions": { - "include": [ - "TestResources/testCert.pfx" - ] - } -} \ No newline at end of file diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/runtimeconfig.template.json b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/runtimeconfig.template.json new file mode 100644 index 0000000000..7305508a37 --- /dev/null +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/runtimeconfig.template.json @@ -0,0 +1,5 @@ +{ + "configProperties": { + "System.GC.Server": true + } +} \ No newline at end of file diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/BadHttpRequestTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/BadHttpRequestTests.cs index ab681e5467..cf3ebc03de 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/BadHttpRequestTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/BadHttpRequestTests.cs @@ -211,7 +211,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { using (var connection = server.CreateConnection()) { - await connection.Send($"GET / HTTP/1.1\r\nContent-Length: {contentLength}\r\n\r\n"); + await connection.SendAll($"GET / HTTP/1.1\r\nContent-Length: {contentLength}\r\n\r\n"); await ReceiveBadRequestResponse(connection, "400 Bad Request", server.Context.DateHeaderValue); } } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/HttpsConnectionAdapterTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/HttpsConnectionAdapterTests.cs index 0fb3642b0e..5df67aa16f 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/HttpsConnectionAdapterTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/HttpsConnectionAdapterTests.cs @@ -24,7 +24,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { public class HttpsConnectionAdapterTests { - private static X509Certificate2 _x509Certificate2 = new X509Certificate2("TestResources/testCert.pfx", "testPassword"); + private static X509Certificate2 _x509Certificate2 = new X509Certificate2(TestResources.TestCertificatePath, "testPassword"); // https://github.com/aspnet/KestrelHttpServer/issues/240 // This test currently fails on mono because of an issue with SslStream. diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/Microsoft.AspNetCore.Server.KestrelTests.csproj b/test/Microsoft.AspNetCore.Server.KestrelTests/Microsoft.AspNetCore.Server.KestrelTests.csproj new file mode 100644 index 0000000000..cb7cf885dc --- /dev/null +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/Microsoft.AspNetCore.Server.KestrelTests.csproj @@ -0,0 +1,32 @@ + + + + + + netcoreapp1.1 + $(TargetFrameworks);net451 + true + + win7-x64 + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/Microsoft.AspNetCore.Server.KestrelTests.xproj b/test/Microsoft.AspNetCore.Server.KestrelTests/Microsoft.AspNetCore.Server.KestrelTests.xproj deleted file mode 100644 index 148f89093b..0000000000 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/Microsoft.AspNetCore.Server.KestrelTests.xproj +++ /dev/null @@ -1,20 +0,0 @@ - - - - 14.0 - $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) - - - - 37f3bfb2-6454-49e5-9d7f-581bf755ccfe - .\obj - .\bin\ - - - 2.0 - - - - - - \ No newline at end of file diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestResources/testCert.pfx b/test/Microsoft.AspNetCore.Server.KestrelTests/TestResources/testCert.pfx deleted file mode 100644 index 7118908c2d730670c16e9f8b2c532a262c951989..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2483 zcmaKuc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dH?_b diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/project.json b/test/Microsoft.AspNetCore.Server.KestrelTests/project.json deleted file mode 100644 index 1d358e6fe8..0000000000 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/project.json +++ /dev/null @@ -1,51 +0,0 @@ -{ - "version": "1.1.0-*", - "dependencies": { - "dotnet-test-xunit": "2.2.0-*", - "Microsoft.AspNetCore.Server.Kestrel.Https": "1.2.0-*", - "Microsoft.AspNetCore.Testing": "1.2.0-*", - "Moq": "4.6.36-*", - "xunit": "2.2.0-*", - "Microsoft.CodeCoverage": { - "type": "build", - "version": "1.0.1" - } - }, - "frameworks": { - "netcoreapp1.1": { - "dependencies": { - "Microsoft.NETCore.App": { - "version": "1.2.0-*", - "type": "platform" - }, - "System.Diagnostics.TraceSource": "4.4.0-*", - "System.Net.Http.WinHttpHandler": "4.4.0-*" - }, - "imports": "dnxcore50" - }, - "net451": { - "frameworkAssemblies": { - "System.Net.Http": "4.0.0.0" - }, - "imports": "dnx451" - } - }, - "buildOptions": { - "allowUnsafe": true, - "compile": { - "include": [ - "../shared/**/*.cs" - ] - }, - "keyFile": "../../tools/Key.snk", - "copyToOutput": { - "include": "TestResources/testCert.pfx" - } - }, - "testRunner": "xunit", - "publishOptions": { - "include": [ - "TestResources/testCert.pfx" - ] - } -} \ No newline at end of file diff --git a/test/shared/TestResources.cs b/test/shared/TestResources.cs new file mode 100644 index 0000000000..261b64b43d --- /dev/null +++ b/test/shared/TestResources.cs @@ -0,0 +1,20 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.IO; + +namespace Microsoft.AspNetCore.Testing +{ + public static class TestResources + { + private static readonly string _testCertificatePath = +#if NET451 + Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "testCert.pfx"); +#else + Path.Combine(AppContext.BaseDirectory, "testCert.pfx"); +#endif + + public static string TestCertificatePath => _testCertificatePath; + } +} \ No newline at end of file diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/TestResources/testCert.pfx b/test/shared/TestResources/testCert.pfx similarity index 100% rename from test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/TestResources/testCert.pfx rename to test/shared/TestResources/testCert.pfx diff --git a/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode.csproj b/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode.csproj new file mode 100644 index 0000000000..13963dcd68 --- /dev/null +++ b/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode.csproj @@ -0,0 +1,15 @@ + + + + + + netcoreapp1.1 + Exe + + + + + + + + diff --git a/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode.xproj b/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode.xproj deleted file mode 100644 index eb41dbdbb4..0000000000 --- a/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode.xproj +++ /dev/null @@ -1,17 +0,0 @@ - - - - 14.0 - $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) - - - - bd2d4d29-1bd9-40d0-bb31-337d5416b63c - .\obj - .\bin\ - - - 2.0 - - - \ No newline at end of file diff --git a/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/project.json b/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/project.json deleted file mode 100644 index a6eab2c3ba..0000000000 --- a/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/project.json +++ /dev/null @@ -1,27 +0,0 @@ -{ - "version": "1.1.0-*", - "buildOptions": { - "emitEntryPoint": true - }, - "dependencies": { - "Microsoft.AspNetCore.Hosting": "1.2.0-*", - "Microsoft.AspNetCore.Http.Features": "1.2.0-*" - }, - "frameworks": { - "netcoreapp1.1": { - "dependencies": { - "Microsoft.NETCore.App": { - "version": "1.2.0-*", - "type": "platform" - } - } - }, - "net451": { - "frameworkAssemblies": { - "System.Runtime": "", - "System.Text.Encoding": "", - "System.Threading.Tasks": "" - } - } - } -} \ No newline at end of file diff --git a/version.props b/version.props new file mode 100644 index 0000000000..e77c8d9c38 --- /dev/null +++ b/version.props @@ -0,0 +1,7 @@ + + + + 1.2.0 + preview1 + + \ No newline at end of file From 8cbe54a1825fee0b7b8a646c6fc9e66f1e7943bd Mon Sep 17 00:00:00 2001 From: Nate McMaster Date: Wed, 1 Feb 2017 12:12:43 -0800 Subject: [PATCH 1035/1662] Remove usage of conditional multi-targeting This causes Visual Studio to crash. See dotnet/roslyn-project-system#1431 --- .../Microsoft.AspNetCore.Server.Kestrel.FunctionalTests.csproj | 3 +-- .../Microsoft.AspNetCore.Server.KestrelTests.csproj | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests.csproj b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests.csproj index c56280900c..a12cabcbec 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests.csproj +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests.csproj @@ -3,8 +3,7 @@ - netcoreapp1.1 - $(TargetFrameworks);net451 + netcoreapp1.1;net451 win7-x64 diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/Microsoft.AspNetCore.Server.KestrelTests.csproj b/test/Microsoft.AspNetCore.Server.KestrelTests/Microsoft.AspNetCore.Server.KestrelTests.csproj index cb7cf885dc..500a01e2a1 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/Microsoft.AspNetCore.Server.KestrelTests.csproj +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/Microsoft.AspNetCore.Server.KestrelTests.csproj @@ -3,8 +3,7 @@ - netcoreapp1.1 - $(TargetFrameworks);net451 + netcoreapp1.1;net451 true win7-x64 From 5124adf450969acc46ab7705463072ffccabd3f7 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Thu, 2 Feb 2017 17:07:14 -0800 Subject: [PATCH 1036/1662] Better report Kestrel crashing errors --- .../Internal/Infrastructure/KestrelThread.cs | 7 +++---- .../Internal/KestrelEngine.cs | 17 ++++++++++++++++- .../KestrelServerTests.cs | 6 +++--- test/shared/TestApplicationErrorLogger.cs | 14 ++++++++++++-- 4 files changed, 34 insertions(+), 10 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/KestrelThread.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/KestrelThread.cs index 117efc08fc..383f804cfa 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/KestrelThread.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/KestrelThread.cs @@ -142,17 +142,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal Post(t => t.OnStopImmediate()); if (!await WaitAsync(_threadTcs.Task, stepTimeout).ConfigureAwait(false)) { - _log.LogError(0, null, "KestrelThread.StopAsync failed to terminate libuv thread."); + _log.LogCritical("KestrelThread.StopAsync failed to terminate libuv thread."); } } } catch (ObjectDisposedException) { - // REVIEW: Should we log something here? // Until we rework this logic, ODEs are bound to happen sometimes. if (!await WaitAsync(_threadTcs.Task, stepTimeout).ConfigureAwait(false)) { - _log.LogError(0, null, "KestrelThread.StopAsync failed to terminate libuv thread."); + _log.LogCritical("KestrelThread.StopAsync failed to terminate libuv thread."); } } } @@ -343,8 +342,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal } finally { - thisHandle.Free(); _threadTcs.SetResult(null); + thisHandle.Free(); } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/KestrelEngine.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/KestrelEngine.cs index b7a7b5a63e..6f21130f6f 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/KestrelEngine.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/KestrelEngine.cs @@ -51,7 +51,22 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal public void Dispose() { - Task.WaitAll(Threads.Select(thread => thread.StopAsync(TimeSpan.FromSeconds(2.5))).ToArray()); + try + { + Task.WaitAll(Threads.Select(thread => thread.StopAsync(TimeSpan.FromSeconds(2.5))).ToArray()); + } + catch (AggregateException aggEx) + { + // An uncaught exception was likely thrown from the libuv event loop. + // The original error that crashed one loop may have caused secondary errors in others. + // Make sure that the stack trace of the original error is logged. + foreach (var ex in aggEx.InnerExceptions) + { + Log.LogCritical("Failed to gracefully close Kestrel.", ex); + } + + throw; + } Threads.Clear(); #if DEBUG diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerTests.cs index bb82eac55f..5225e5a16d 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerTests.cs @@ -23,7 +23,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [InlineData(-1337)] public void StartWithNonPositiveThreadCountThrows(int threadCount) { - var testLogger = new TestApplicationErrorLogger(); + var testLogger = new TestApplicationErrorLogger { ThrowOnCriticalErrors = false }; var server = CreateServer(new KestrelServerOptions() { ThreadCount = threadCount }, testLogger); var exception = Assert.Throws(() => StartDummyApplication(server)); @@ -35,7 +35,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [Fact] public void StartWithInvalidAddressThrows() { - var testLogger = new TestApplicationErrorLogger(); + var testLogger = new TestApplicationErrorLogger { ThrowOnCriticalErrors = false }; var server = CreateServer(new KestrelServerOptions(), testLogger); server.Features.Get().Addresses.Add("http:/asdf"); @@ -72,7 +72,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [InlineData(int.MaxValue - 1, int.MaxValue)] public void StartWithMaxRequestBufferSizeLessThanMaxRequestLineSizeThrows(long maxRequestBufferSize, int maxRequestLineSize) { - var testLogger = new TestApplicationErrorLogger(); + var testLogger = new TestApplicationErrorLogger { ThrowOnCriticalErrors = false }; var options = new KestrelServerOptions(); options.Limits.MaxRequestBufferSize = maxRequestBufferSize; options.Limits.MaxRequestLineSize = maxRequestLineSize; diff --git a/test/shared/TestApplicationErrorLogger.cs b/test/shared/TestApplicationErrorLogger.cs index 057e8435fb..76ee249a36 100644 --- a/test/shared/TestApplicationErrorLogger.cs +++ b/test/shared/TestApplicationErrorLogger.cs @@ -14,6 +14,8 @@ namespace Microsoft.AspNetCore.Testing // Application errors are logged using 13 as the eventId. private const int ApplicationErrorEventId = 13; + public bool ThrowOnCriticalErrors { get; set; } = true; + public ConcurrentBag Messages { get; } = new ConcurrentBag(); public int TotalErrorsLogged => Messages.Count(message => message.LogLevel == LogLevel.Error); @@ -34,9 +36,17 @@ namespace Microsoft.AspNetCore.Testing public void Log(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func formatter) { -#if false - Console.WriteLine($"Log {logLevel}[{eventId}]: {formatter(state, exception)} {exception?.Message}"); +#if true + if (logLevel == LogLevel.Critical && ThrowOnCriticalErrors) #endif + { + Console.WriteLine($"Log {logLevel}[{eventId}]: {formatter(state, exception)} {exception?.Message}"); + + if (logLevel == LogLevel.Critical && ThrowOnCriticalErrors) + { + throw new Exception("Unexpected critical error.", exception); + } + } Messages.Add(new LogMessage { From e9e0cf7325c9814090d69d7e12eab8a14ca26519 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Thu, 2 Feb 2017 20:29:33 -0800 Subject: [PATCH 1037/1662] Prevent ODE when ReadStart/Stop() is queued after disposal --- .../Internal/Http/BufferSizeControl.cs | 12 ++---- .../Internal/Http/Connection.cs | 42 +++++++++++++++---- 2 files changed, 36 insertions(+), 18 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/BufferSizeControl.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/BufferSizeControl.cs index 7fbec15ec2..364a1a2cf8 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/BufferSizeControl.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/BufferSizeControl.cs @@ -6,18 +6,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { private readonly long _maxSize; private readonly IConnectionControl _connectionControl; - private readonly KestrelThread _connectionThread; private readonly object _lock = new object(); private long _size; private bool _connectionPaused; - public BufferSizeControl(long maxSize, IConnectionControl connectionControl, KestrelThread connectionThread) + public BufferSizeControl(long maxSize, IConnectionControl connectionControl) { _maxSize = maxSize; _connectionControl = connectionControl; - _connectionThread = connectionThread; } private long Size @@ -50,9 +48,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if (!_connectionPaused && Size >= _maxSize) { _connectionPaused = true; - _connectionThread.Post( - (connectionControl) => ((IConnectionControl)connectionControl).Pause(), - _connectionControl); + _connectionControl.Pause(); } } } @@ -73,9 +69,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if (_connectionPaused && Size < _maxSize) { _connectionPaused = false; - _connectionThread.Post( - (connectionControl) => ((IConnectionControl)connectionControl).Resume(), - _connectionControl); + _connectionControl.Resume(); } } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Connection.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Connection.cs index 9d1c537814..12b978687b 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Connection.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Connection.cs @@ -57,7 +57,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if (ServerOptions.Limits.MaxRequestBufferSize.HasValue) { - _bufferSizeControl = new BufferSizeControl(ServerOptions.Limits.MaxRequestBufferSize.Value, this, Thread); + _bufferSizeControl = new BufferSizeControl(ServerOptions.Limits.MaxRequestBufferSize.Value, this); } Input = new SocketInput(Thread.Memory, ThreadPool, _bufferSizeControl); @@ -285,22 +285,46 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http void IConnectionControl.Pause() { Log.ConnectionPause(ConnectionId); - _socket.ReadStop(); + + // Even though this method is called on the event loop already, + // post anyway so the ReadStop() call doesn't get reordered + // relative to the ReadStart() call made in Resume(). + Thread.Post(state => ((Connection)state).OnPausePosted(), this); } void IConnectionControl.Resume() { Log.ConnectionResume(ConnectionId); - try + + // This is called from the consuming thread. + Thread.Post(state => ((Connection)state).OnResumePosted(), this); + } + + private void OnPausePosted() + { + // It's possible that uv_close was called between the call to Thread.Post() and now. + if (!_socket.IsClosed) { - _socket.ReadStart(_allocCallback, _readCallback, this); + _socket.ReadStop(); } - catch (UvException) + } + + private void OnResumePosted() + { + // It's possible that uv_close was called even before the call to Resume(). + if (!_socket.IsClosed) { - // ReadStart() can throw a UvException in some cases (e.g. socket is no longer connected). - // This should be treated the same as OnRead() seeing a "normalDone" condition. - Log.ConnectionReadFin(ConnectionId); - Input.IncomingComplete(0, null); + try + { + _socket.ReadStart(_allocCallback, _readCallback, this); + } + catch (UvException) + { + // ReadStart() can throw a UvException in some cases (e.g. socket is no longer connected). + // This should be treated the same as OnRead() seeing a "normalDone" condition. + Log.ConnectionReadFin(ConnectionId); + Input.IncomingComplete(0, null); + } } } From 21be33023cc662a5f82233f6bc5f33a1a2130eba Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Wed, 8 Feb 2017 16:39:14 -0800 Subject: [PATCH 1038/1662] Implement APM methods in streams (#1335). --- .../Filter/Internal/LibuvStream.cs | 78 +++++++++++++++++++ .../Filter/Internal/StreamSocketOutput.cs | 49 ++++-------- .../Internal/Http/FrameRequestStream.cs | 8 +- .../Internal/Http/FrameResponseStream.cs | 40 ++++++++++ 4 files changed, 133 insertions(+), 42 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Filter/Internal/LibuvStream.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Filter/Internal/LibuvStream.cs index 3ae1ddbd69..0127d156a0 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Filter/Internal/LibuvStream.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Filter/Internal/LibuvStream.cs @@ -132,5 +132,83 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Filter.Internal { return _input.ReadAsync(buffer.Array, buffer.Offset, buffer.Count); } + +#if NET451 + public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback callback, object state) + { + var task = ReadAsync(buffer, offset, count, default(CancellationToken), state); + if (callback != null) + { + task.ContinueWith(t => callback.Invoke(t)); + } + return task; + } + + public override int EndRead(IAsyncResult asyncResult) + { + return ((Task)asyncResult).GetAwaiter().GetResult(); + } + + private Task ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken, object state) + { + var tcs = new TaskCompletionSource(state); + var task = ReadAsync(buffer, offset, count, cancellationToken); + task.ContinueWith((task2, state2) => + { + var tcs2 = (TaskCompletionSource)state2; + if (task2.IsCanceled) + { + tcs2.SetCanceled(); + } + else if (task2.IsFaulted) + { + tcs2.SetException(task2.Exception); + } + else + { + tcs2.SetResult(task2.Result); + } + }, tcs, cancellationToken); + return tcs.Task; + } + + public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback callback, object state) + { + var task = WriteAsync(buffer, offset, count, default(CancellationToken), state); + if (callback != null) + { + task.ContinueWith(t => callback.Invoke(t)); + } + return task; + } + + public override void EndWrite(IAsyncResult asyncResult) + { + ((Task)asyncResult).GetAwaiter().GetResult(); + } + + private Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken, object state) + { + var tcs = new TaskCompletionSource(state); + var task = WriteAsync(buffer, offset, count, cancellationToken); + task.ContinueWith((task2, state2) => + { + var tcs2 = (TaskCompletionSource)state2; + if (task2.IsCanceled) + { + tcs2.SetCanceled(); + } + else if (task2.IsFaulted) + { + tcs2.SetException(task2.Exception); + } + else + { + tcs2.SetResult(null); + } + }, tcs, cancellationToken); + return tcs.Task; + } +#endif } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Filter/Internal/StreamSocketOutput.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Filter/Internal/StreamSocketOutput.cs index bfd7d5201b..052ab4f068 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Filter/Internal/StreamSocketOutput.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Filter/Internal/StreamSocketOutput.cs @@ -24,8 +24,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Filter.Internal private bool _canWrite = true; - private object _writeLock = new object(); - public StreamSocketOutput(string connectionId, Stream outputStream, MemoryPool memory, IKestrelTrace logger) { _connectionId = connectionId; @@ -36,54 +34,33 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Filter.Internal public void Write(ArraySegment buffer, bool chunk) { - lock (_writeLock) + if (buffer.Count == 0 ) { - if (buffer.Count == 0 ) - { - return; - } + return; + } - try - { - if (!_canWrite) - { - return; - } + if (chunk && buffer.Array != null) + { + var beginChunkBytes = ChunkWriter.BeginChunkBytes(buffer.Count); + _outputStream.Write(beginChunkBytes.Array, beginChunkBytes.Offset, beginChunkBytes.Count); + } - if (chunk && buffer.Array != null) - { - var beginChunkBytes = ChunkWriter.BeginChunkBytes(buffer.Count); - _outputStream.Write(beginChunkBytes.Array, beginChunkBytes.Offset, beginChunkBytes.Count); - } + _outputStream.Write(buffer.Array ?? _nullBuffer, buffer.Offset, buffer.Count); - _outputStream.Write(buffer.Array ?? _nullBuffer, buffer.Offset, buffer.Count); - - if (chunk && buffer.Array != null) - { - _outputStream.Write(_endChunkBytes, 0, _endChunkBytes.Length); - } - } - catch (Exception ex) - { - _canWrite = false; - _logger.ConnectionError(_connectionId, ex); - } + if (chunk && buffer.Array != null) + { + _outputStream.Write(_endChunkBytes, 0, _endChunkBytes.Length); } } public Task WriteAsync(ArraySegment buffer, bool chunk, CancellationToken cancellationToken) { -#if NET451 - Write(buffer, chunk); - return TaskUtilities.CompletedTask; -#else if (chunk && buffer.Array != null) { return WriteAsyncChunked(buffer, cancellationToken); } return _outputStream.WriteAsync(buffer.Array ?? _nullBuffer, buffer.Offset, buffer.Count, cancellationToken); -#endif } private async Task WriteAsyncChunked(ArraySegment buffer, CancellationToken cancellationToken) @@ -124,7 +101,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Filter.Internal block = block.Next; returnBlock.Pool.Return(returnBlock); } - + if (_canWrite) { try diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameRequestStream.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameRequestStream.cs index f2f7b379be..0874fd9441 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameRequestStream.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameRequestStream.cs @@ -75,8 +75,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http #if NET451 public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback callback, object state) { - ValidateState(default(CancellationToken)); - var task = ReadAsync(buffer, offset, count, default(CancellationToken), state); if (callback != null) { @@ -92,11 +90,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http private Task ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken, object state) { - ValidateState(cancellationToken); - var tcs = new TaskCompletionSource(state); - var task = _body.ReadAsync(new ArraySegment(buffer, offset, count), cancellationToken); - task.AsTask().ContinueWith((task2, state2) => + var task = ReadAsync(buffer, offset, count, cancellationToken); + task.ContinueWith((task2, state2) => { var tcs2 = (TaskCompletionSource)state2; if (task2.IsCanceled) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameResponseStream.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameResponseStream.cs index 61013ac16c..5a3c9159d5 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameResponseStream.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameResponseStream.cs @@ -85,6 +85,46 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _frameControl.Write(new ArraySegment(buffer, offset, count)); } +#if NET451 + public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback callback, object state) + { + var task = WriteAsync(buffer, offset, count, default(CancellationToken), state); + if (callback != null) + { + task.ContinueWith(t => callback.Invoke(t)); + } + return task; + } + + public override void EndWrite(IAsyncResult asyncResult) + { + ((Task)asyncResult).GetAwaiter().GetResult(); + } + + private Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken, object state) + { + var tcs = new TaskCompletionSource(state); + var task = WriteAsync(buffer, offset, count, cancellationToken); + task.ContinueWith((task2, state2) => + { + var tcs2 = (TaskCompletionSource)state2; + if (task2.IsCanceled) + { + tcs2.SetCanceled(); + } + else if (task2.IsFaulted) + { + tcs2.SetException(task2.Exception); + } + else + { + tcs2.SetResult(null); + } + }, tcs, cancellationToken); + return tcs.Task; + } +#endif + public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) { var task = ValidateState(cancellationToken); From be9f83b30820230eb853dd33c687fa7d0ad05e8e Mon Sep 17 00:00:00 2001 From: Doug Bunting Date: Tue, 14 Feb 2017 09:21:44 -0800 Subject: [PATCH 1039/1662] Bump test projects up to .NET 4.5.2 - aspnet/Testing#248 - xUnit no longer supports .NET 4.5.1 - build tests for desktop .NET only on Windows --- ...crosoft.AspNetCore.Server.Kestrel.FunctionalTests.csproj | 5 +++-- .../FrameRequestStreamTests.cs | 2 +- .../FrameResponseStreamTests.cs | 2 +- .../Microsoft.AspNetCore.Server.KestrelTests.csproj | 5 +++-- .../NetworkingTests.cs | 6 +++--- test/shared/TestResources.cs | 2 +- 6 files changed, 12 insertions(+), 10 deletions(-) diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests.csproj b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests.csproj index a12cabcbec..eb262112bc 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests.csproj +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests.csproj @@ -3,7 +3,8 @@ - netcoreapp1.1;net451 + netcoreapp1.1;net452 + netcoreapp1.1 win7-x64 @@ -26,7 +27,7 @@ - + diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameRequestStreamTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameRequestStreamTests.cs index 5d1c96e0f8..ac5bc1b354 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameRequestStreamTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameRequestStreamTests.cs @@ -83,7 +83,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests await Assert.ThrowsAsync(() => stream.WriteAsync(new byte[1], 0, 1)); } -#if NET451 +#if NET452 [Fact] public void BeginWriteThrows() { diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameResponseStreamTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameResponseStreamTests.cs index 64590151bc..9c791b059d 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameResponseStreamTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameResponseStreamTests.cs @@ -54,7 +54,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests await Assert.ThrowsAsync(() => stream.ReadAsync(new byte[1], 0, 1)); } -#if NET451 +#if NET452 [Fact] public void BeginReadThrows() { diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/Microsoft.AspNetCore.Server.KestrelTests.csproj b/test/Microsoft.AspNetCore.Server.KestrelTests/Microsoft.AspNetCore.Server.KestrelTests.csproj index 500a01e2a1..4ee43ea35b 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/Microsoft.AspNetCore.Server.KestrelTests.csproj +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/Microsoft.AspNetCore.Server.KestrelTests.csproj @@ -3,7 +3,8 @@ - netcoreapp1.1;net451 + netcoreapp1.1;net452 + netcoreapp1.1 true win7-x64 @@ -24,7 +25,7 @@ - + diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/NetworkingTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/NetworkingTests.cs index ebc3ebeb22..afa087f430 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/NetworkingTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/NetworkingTests.cs @@ -131,7 +131,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var t = Task.Run(async () => { var socket = TestConnection.CreateConnectedLoopbackSocket(port); -#if NET451 +#if NET452 await Task.Factory.FromAsync( socket.BeginSend, socket.EndSend, @@ -205,7 +205,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var t = Task.Run(async () => { var socket = TestConnection.CreateConnectedLoopbackSocket(port); -#if NET451 +#if NET452 await Task.Factory.FromAsync( socket.BeginSend, socket.EndSend, @@ -221,7 +221,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var buffer = new ArraySegment(new byte[2048]); while (true) { -#if NET451 +#if NET452 var count = await Task.Factory.FromAsync( socket.BeginReceive, socket.EndReceive, diff --git a/test/shared/TestResources.cs b/test/shared/TestResources.cs index 261b64b43d..64a3161914 100644 --- a/test/shared/TestResources.cs +++ b/test/shared/TestResources.cs @@ -9,7 +9,7 @@ namespace Microsoft.AspNetCore.Testing public static class TestResources { private static readonly string _testCertificatePath = -#if NET451 +#if NET452 Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "testCert.pfx"); #else Path.Combine(AppContext.BaseDirectory, "testCert.pfx"); From 708630fd23f323062ac60fc972c286e60c03c041 Mon Sep 17 00:00:00 2001 From: Nate McMaster Date: Tue, 14 Feb 2017 16:03:53 -0800 Subject: [PATCH 1040/1662] Downgrade to stable packages --- build/common.props | 5 ++--- build/dependencies.props | 7 +++++++ makefile.shade | 10 ---------- samples/LargeResponseApp/LargeResponseApp.csproj | 4 ++-- samples/SampleApp/SampleApp.csproj | 2 +- ...icrosoft.AspNetCore.Server.Kestrel.Https.csproj | 4 ++-- .../Microsoft.AspNetCore.Server.Kestrel.csproj | 14 +++++++------- ...spNetCore.Server.Kestrel.FunctionalTests.csproj | 6 +++--- ...ft.AspNetCore.Server.Kestrel.Performance.csproj | 2 +- ...Microsoft.AspNetCore.Server.KestrelTests.csproj | 4 ++-- ....AspNetCore.Server.Kestrel.GeneratedCode.csproj | 2 +- 11 files changed, 28 insertions(+), 32 deletions(-) create mode 100644 build/dependencies.props delete mode 100644 makefile.shade diff --git a/build/common.props b/build/common.props index 9574eadb58..f6342cb9d3 100644 --- a/build/common.props +++ b/build/common.props @@ -1,4 +1,5 @@ + @@ -8,8 +9,6 @@ $(MSBuildThisFileDirectory)Key.snk true true - 1.2.0-* - 1.6.2-* $(VersionSuffix)-$(BuildNumber) @@ -21,4 +20,4 @@ - \ No newline at end of file + diff --git a/build/dependencies.props b/build/dependencies.props new file mode 100644 index 0000000000..9aa824128d --- /dev/null +++ b/build/dependencies.props @@ -0,0 +1,7 @@ + + + 1.6.1 + 4.3.0 + 1.9.1 + + diff --git a/makefile.shade b/makefile.shade deleted file mode 100644 index 58a82b5a00..0000000000 --- a/makefile.shade +++ /dev/null @@ -1,10 +0,0 @@ -var VERSION='0.1' -var FULL_VERSION='0.1' -var AUTHORS='Microsoft' - -use-standard-lifecycle -k-standard-goals -custom-goals - -#initialize - dotnet command='run -f netcoreapp1.1 -p tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode.csproj src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameHeaders.Generated.cs src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.Generated.cs' \ No newline at end of file diff --git a/samples/LargeResponseApp/LargeResponseApp.csproj b/samples/LargeResponseApp/LargeResponseApp.csproj index 0149ac0ba2..45de356f95 100644 --- a/samples/LargeResponseApp/LargeResponseApp.csproj +++ b/samples/LargeResponseApp/LargeResponseApp.csproj @@ -1,4 +1,4 @@ - + @@ -13,4 +13,4 @@ - \ No newline at end of file + diff --git a/samples/SampleApp/SampleApp.csproj b/samples/SampleApp/SampleApp.csproj index e3feb7221a..19792a43e2 100644 --- a/samples/SampleApp/SampleApp.csproj +++ b/samples/SampleApp/SampleApp.csproj @@ -1,4 +1,4 @@ - + diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Https/Microsoft.AspNetCore.Server.Kestrel.Https.csproj b/src/Microsoft.AspNetCore.Server.Kestrel.Https/Microsoft.AspNetCore.Server.Kestrel.Https.csproj index 95e5a0110d..7765f0e77a 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Https/Microsoft.AspNetCore.Server.Kestrel.Https.csproj +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Https/Microsoft.AspNetCore.Server.Kestrel.Https.csproj @@ -1,4 +1,4 @@ - + @@ -16,7 +16,7 @@ - + diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Microsoft.AspNetCore.Server.Kestrel.csproj b/src/Microsoft.AspNetCore.Server.Kestrel/Microsoft.AspNetCore.Server.Kestrel.csproj index bca637d906..02214cbaf6 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Microsoft.AspNetCore.Server.Kestrel.csproj +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Microsoft.AspNetCore.Server.Kestrel.csproj @@ -1,4 +1,4 @@ - + @@ -12,18 +12,18 @@ - + - - + + - - - + + + diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests.csproj b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests.csproj index eb262112bc..fa3f75fdba 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests.csproj +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests.csproj @@ -1,4 +1,4 @@ - + @@ -32,7 +32,7 @@ - + @@ -45,4 +45,4 @@ - \ No newline at end of file + diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Microsoft.AspNetCore.Server.Kestrel.Performance.csproj b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Microsoft.AspNetCore.Server.Kestrel.Performance.csproj index 6f479fdb7a..f234b8fb10 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Microsoft.AspNetCore.Server.Kestrel.Performance.csproj +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Microsoft.AspNetCore.Server.Kestrel.Performance.csproj @@ -1,4 +1,4 @@ - + diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/Microsoft.AspNetCore.Server.KestrelTests.csproj b/test/Microsoft.AspNetCore.Server.KestrelTests/Microsoft.AspNetCore.Server.KestrelTests.csproj index 4ee43ea35b..7af504a271 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/Microsoft.AspNetCore.Server.KestrelTests.csproj +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/Microsoft.AspNetCore.Server.KestrelTests.csproj @@ -1,4 +1,4 @@ - + @@ -29,4 +29,4 @@ - \ No newline at end of file + diff --git a/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode.csproj b/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode.csproj index 13963dcd68..dafd54104a 100644 --- a/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode.csproj +++ b/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode.csproj @@ -1,4 +1,4 @@ - + From 932b6ed53a622a3a1b6616c550cf3e29fb0223eb Mon Sep 17 00:00:00 2001 From: Nate McMaster Date: Thu, 16 Feb 2017 09:32:03 -0800 Subject: [PATCH 1041/1662] Cleanup MSBuild conversion Remove runtimeconfig.template.json Remove ToolsVersion attribute Use repo.targets instead of makefile.shade Rename code gen app to shorter name Use GetOSPlatform task Upgrade tests to .NET Framework 4.5.2 Cleanup solution configurations. Set the class libraries to AnyCPU even when on the x86 or x64 solution config. --- .gitignore | 1 + KestrelHttpServer.sln | 72 +++++++++---------- NuGet.config | 2 +- appveyor.yml | 2 +- build/repo.props | 5 ++ build/repo.targets | 5 ++ .../LargeResponseApp/LargeResponseApp.csproj | 1 + .../runtimeconfig.template.json | 5 -- samples/SampleApp/SampleApp.csproj | 2 + samples/SampleApp/runtimeconfig.template.json | 5 -- ...oft.AspNetCore.Server.Kestrel.Https.csproj | 3 + ...Core.Server.Kestrel.FunctionalTests.csproj | 28 ++++---- .../Properties/AssemblyInfo.cs | 2 +- .../.notest | 0 ...pNetCore.Server.Kestrel.Performance.csproj | 5 ++ .../runtimeconfig.template.json | 5 -- ...soft.AspNetCore.Server.KestrelTests.csproj | 11 +-- .../UvStreamHandleTests.cs | 5 +- .../CodeGenerator.csproj} | 6 ++ .../FrameFeatureCollection.cs | 5 +- .../KnownHeaders.cs | 17 +++-- .../Program.cs | 5 +- version.props | 2 +- 23 files changed, 113 insertions(+), 81 deletions(-) create mode 100644 build/repo.props create mode 100644 build/repo.targets delete mode 100644 samples/LargeResponseApp/runtimeconfig.template.json delete mode 100644 samples/SampleApp/runtimeconfig.template.json delete mode 100644 test/Microsoft.AspNetCore.Server.Kestrel.Performance/.notest delete mode 100644 test/Microsoft.AspNetCore.Server.Kestrel.Performance/runtimeconfig.template.json rename tools/{Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode.csproj => CodeGenerator/CodeGenerator.csproj} (58%) rename tools/{Microsoft.AspNetCore.Server.Kestrel.GeneratedCode => CodeGenerator}/FrameFeatureCollection.cs (95%) rename tools/{Microsoft.AspNetCore.Server.Kestrel.GeneratedCode => CodeGenerator}/KnownHeaders.cs (98%) rename tools/{Microsoft.AspNetCore.Server.Kestrel.GeneratedCode => CodeGenerator}/Program.cs (86%) diff --git a/.gitignore b/.gitignore index af0898e29a..317cee961f 100644 --- a/.gitignore +++ b/.gitignore @@ -8,6 +8,7 @@ packages/ artifacts/ PublishProfiles/ .vs/ +.vscode/ *.user *.suo *.cache diff --git a/KestrelHttpServer.sln b/KestrelHttpServer.sln index cceaccce52..d935b2d9b4 100644 --- a/KestrelHttpServer.sln +++ b/KestrelHttpServer.sln @@ -1,6 +1,6 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 15 -VisualStudioVersion = 15.0.26117.0 +VisualStudioVersion = 15.0.26213.1 MinimumVisualStudioVersion = 10.0.40219.1 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{7972A5D6-3385-4127-9277-428506DD44FF}" ProjectSection(SolutionItems) = preProject @@ -46,7 +46,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SampleApp", "samples\Sample EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LargeResponseApp", "samples\LargeResponseApp\LargeResponseApp.csproj", "{B35D4D31-E74C-4646-8A11-7A7A40F0021E}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Server.Kestrel.GeneratedCode", "tools\Microsoft.AspNetCore.Server.Kestrel.GeneratedCode\Microsoft.AspNetCore.Server.Kestrel.GeneratedCode.csproj", "{BD2D4D29-1BD9-40D0-BB31-337D5416B63C}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CodeGenerator", "tools\CodeGenerator\CodeGenerator.csproj", "{BD2D4D29-1BD9-40D0-BB31-337D5416B63C}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Server.Kestrel.Https", "src\Microsoft.AspNetCore.Server.Kestrel.Https\Microsoft.AspNetCore.Server.Kestrel.Https.csproj", "{5F64B3C3-0C2E-431A-B820-A81BBFC863DA}" EndProject @@ -71,16 +71,16 @@ Global GlobalSection(ProjectConfigurationPlatforms) = postSolution {F510611A-3BEE-4B88-A613-5F4A74ED82A1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {F510611A-3BEE-4B88-A613-5F4A74ED82A1}.Debug|Any CPU.Build.0 = Debug|Any CPU - {F510611A-3BEE-4B88-A613-5F4A74ED82A1}.Debug|x64.ActiveCfg = Debug|x64 - {F510611A-3BEE-4B88-A613-5F4A74ED82A1}.Debug|x64.Build.0 = Debug|x64 - {F510611A-3BEE-4B88-A613-5F4A74ED82A1}.Debug|x86.ActiveCfg = Debug|x86 - {F510611A-3BEE-4B88-A613-5F4A74ED82A1}.Debug|x86.Build.0 = Debug|x86 + {F510611A-3BEE-4B88-A613-5F4A74ED82A1}.Debug|x64.ActiveCfg = Debug|Any CPU + {F510611A-3BEE-4B88-A613-5F4A74ED82A1}.Debug|x64.Build.0 = Debug|Any CPU + {F510611A-3BEE-4B88-A613-5F4A74ED82A1}.Debug|x86.ActiveCfg = Debug|Any CPU + {F510611A-3BEE-4B88-A613-5F4A74ED82A1}.Debug|x86.Build.0 = Debug|Any CPU {F510611A-3BEE-4B88-A613-5F4A74ED82A1}.Release|Any CPU.ActiveCfg = Release|Any CPU {F510611A-3BEE-4B88-A613-5F4A74ED82A1}.Release|Any CPU.Build.0 = Release|Any CPU - {F510611A-3BEE-4B88-A613-5F4A74ED82A1}.Release|x64.ActiveCfg = Release|x64 - {F510611A-3BEE-4B88-A613-5F4A74ED82A1}.Release|x64.Build.0 = Release|x64 - {F510611A-3BEE-4B88-A613-5F4A74ED82A1}.Release|x86.ActiveCfg = Release|x86 - {F510611A-3BEE-4B88-A613-5F4A74ED82A1}.Release|x86.Build.0 = Release|x86 + {F510611A-3BEE-4B88-A613-5F4A74ED82A1}.Release|x64.ActiveCfg = Release|Any CPU + {F510611A-3BEE-4B88-A613-5F4A74ED82A1}.Release|x64.Build.0 = Release|Any CPU + {F510611A-3BEE-4B88-A613-5F4A74ED82A1}.Release|x86.ActiveCfg = Release|Any CPU + {F510611A-3BEE-4B88-A613-5F4A74ED82A1}.Release|x86.Build.0 = Release|Any CPU {37F3BFB2-6454-49E5-9D7F-581BF755CCFE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {37F3BFB2-6454-49E5-9D7F-581BF755CCFE}.Debug|Any CPU.Build.0 = Debug|Any CPU {37F3BFB2-6454-49E5-9D7F-581BF755CCFE}.Debug|x64.ActiveCfg = Debug|x64 @@ -91,8 +91,8 @@ Global {37F3BFB2-6454-49E5-9D7F-581BF755CCFE}.Release|Any CPU.Build.0 = Release|Any CPU {37F3BFB2-6454-49E5-9D7F-581BF755CCFE}.Release|x64.ActiveCfg = Release|x64 {37F3BFB2-6454-49E5-9D7F-581BF755CCFE}.Release|x64.Build.0 = Release|x64 - {37F3BFB2-6454-49E5-9D7F-581BF755CCFE}.Release|x86.ActiveCfg = Release|x86 - {37F3BFB2-6454-49E5-9D7F-581BF755CCFE}.Release|x86.Build.0 = Release|x86 + {37F3BFB2-6454-49E5-9D7F-581BF755CCFE}.Release|x86.ActiveCfg = Release|Any CPU + {37F3BFB2-6454-49E5-9D7F-581BF755CCFE}.Release|x86.Build.0 = Release|Any CPU {2C3CB3DC-EEBF-4F52-9E1C-4F2F972E76C3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {2C3CB3DC-EEBF-4F52-9E1C-4F2F972E76C3}.Debug|Any CPU.Build.0 = Debug|Any CPU {2C3CB3DC-EEBF-4F52-9E1C-4F2F972E76C3}.Debug|x64.ActiveCfg = Debug|x64 @@ -103,8 +103,8 @@ Global {2C3CB3DC-EEBF-4F52-9E1C-4F2F972E76C3}.Release|Any CPU.Build.0 = Release|Any CPU {2C3CB3DC-EEBF-4F52-9E1C-4F2F972E76C3}.Release|x64.ActiveCfg = Release|x64 {2C3CB3DC-EEBF-4F52-9E1C-4F2F972E76C3}.Release|x64.Build.0 = Release|x64 - {2C3CB3DC-EEBF-4F52-9E1C-4F2F972E76C3}.Release|x86.ActiveCfg = Release|x86 - {2C3CB3DC-EEBF-4F52-9E1C-4F2F972E76C3}.Release|x86.Build.0 = Release|x86 + {2C3CB3DC-EEBF-4F52-9E1C-4F2F972E76C3}.Release|x86.ActiveCfg = Release|Any CPU + {2C3CB3DC-EEBF-4F52-9E1C-4F2F972E76C3}.Release|x86.Build.0 = Release|Any CPU {B35D4D31-E74C-4646-8A11-7A7A40F0021E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {B35D4D31-E74C-4646-8A11-7A7A40F0021E}.Debug|Any CPU.Build.0 = Debug|Any CPU {B35D4D31-E74C-4646-8A11-7A7A40F0021E}.Debug|x64.ActiveCfg = Debug|x64 @@ -115,32 +115,32 @@ Global {B35D4D31-E74C-4646-8A11-7A7A40F0021E}.Release|Any CPU.Build.0 = Release|Any CPU {B35D4D31-E74C-4646-8A11-7A7A40F0021E}.Release|x64.ActiveCfg = Release|x64 {B35D4D31-E74C-4646-8A11-7A7A40F0021E}.Release|x64.Build.0 = Release|x64 - {B35D4D31-E74C-4646-8A11-7A7A40F0021E}.Release|x86.ActiveCfg = Release|x86 - {B35D4D31-E74C-4646-8A11-7A7A40F0021E}.Release|x86.Build.0 = Release|x86 + {B35D4D31-E74C-4646-8A11-7A7A40F0021E}.Release|x86.ActiveCfg = Release|Any CPU + {B35D4D31-E74C-4646-8A11-7A7A40F0021E}.Release|x86.Build.0 = Release|Any CPU {BD2D4D29-1BD9-40D0-BB31-337D5416B63C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {BD2D4D29-1BD9-40D0-BB31-337D5416B63C}.Debug|Any CPU.Build.0 = Debug|Any CPU - {BD2D4D29-1BD9-40D0-BB31-337D5416B63C}.Debug|x64.ActiveCfg = Debug|x64 - {BD2D4D29-1BD9-40D0-BB31-337D5416B63C}.Debug|x64.Build.0 = Debug|x64 - {BD2D4D29-1BD9-40D0-BB31-337D5416B63C}.Debug|x86.ActiveCfg = Debug|x86 - {BD2D4D29-1BD9-40D0-BB31-337D5416B63C}.Debug|x86.Build.0 = Debug|x86 + {BD2D4D29-1BD9-40D0-BB31-337D5416B63C}.Debug|x64.ActiveCfg = Debug|Any CPU + {BD2D4D29-1BD9-40D0-BB31-337D5416B63C}.Debug|x64.Build.0 = Debug|Any CPU + {BD2D4D29-1BD9-40D0-BB31-337D5416B63C}.Debug|x86.ActiveCfg = Debug|Any CPU + {BD2D4D29-1BD9-40D0-BB31-337D5416B63C}.Debug|x86.Build.0 = Debug|Any CPU {BD2D4D29-1BD9-40D0-BB31-337D5416B63C}.Release|Any CPU.ActiveCfg = Release|Any CPU {BD2D4D29-1BD9-40D0-BB31-337D5416B63C}.Release|Any CPU.Build.0 = Release|Any CPU - {BD2D4D29-1BD9-40D0-BB31-337D5416B63C}.Release|x64.ActiveCfg = Release|x64 - {BD2D4D29-1BD9-40D0-BB31-337D5416B63C}.Release|x64.Build.0 = Release|x64 - {BD2D4D29-1BD9-40D0-BB31-337D5416B63C}.Release|x86.ActiveCfg = Release|x86 - {BD2D4D29-1BD9-40D0-BB31-337D5416B63C}.Release|x86.Build.0 = Release|x86 + {BD2D4D29-1BD9-40D0-BB31-337D5416B63C}.Release|x64.ActiveCfg = Release|Any CPU + {BD2D4D29-1BD9-40D0-BB31-337D5416B63C}.Release|x64.Build.0 = Release|Any CPU + {BD2D4D29-1BD9-40D0-BB31-337D5416B63C}.Release|x86.ActiveCfg = Release|Any CPU + {BD2D4D29-1BD9-40D0-BB31-337D5416B63C}.Release|x86.Build.0 = Release|Any CPU {5F64B3C3-0C2E-431A-B820-A81BBFC863DA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {5F64B3C3-0C2E-431A-B820-A81BBFC863DA}.Debug|Any CPU.Build.0 = Debug|Any CPU - {5F64B3C3-0C2E-431A-B820-A81BBFC863DA}.Debug|x64.ActiveCfg = Debug|x64 - {5F64B3C3-0C2E-431A-B820-A81BBFC863DA}.Debug|x64.Build.0 = Debug|x64 - {5F64B3C3-0C2E-431A-B820-A81BBFC863DA}.Debug|x86.ActiveCfg = Debug|x86 - {5F64B3C3-0C2E-431A-B820-A81BBFC863DA}.Debug|x86.Build.0 = Debug|x86 + {5F64B3C3-0C2E-431A-B820-A81BBFC863DA}.Debug|x64.ActiveCfg = Debug|Any CPU + {5F64B3C3-0C2E-431A-B820-A81BBFC863DA}.Debug|x64.Build.0 = Debug|Any CPU + {5F64B3C3-0C2E-431A-B820-A81BBFC863DA}.Debug|x86.ActiveCfg = Debug|Any CPU + {5F64B3C3-0C2E-431A-B820-A81BBFC863DA}.Debug|x86.Build.0 = Debug|Any CPU {5F64B3C3-0C2E-431A-B820-A81BBFC863DA}.Release|Any CPU.ActiveCfg = Release|Any CPU {5F64B3C3-0C2E-431A-B820-A81BBFC863DA}.Release|Any CPU.Build.0 = Release|Any CPU - {5F64B3C3-0C2E-431A-B820-A81BBFC863DA}.Release|x64.ActiveCfg = Release|x64 - {5F64B3C3-0C2E-431A-B820-A81BBFC863DA}.Release|x64.Build.0 = Release|x64 - {5F64B3C3-0C2E-431A-B820-A81BBFC863DA}.Release|x86.ActiveCfg = Release|x86 - {5F64B3C3-0C2E-431A-B820-A81BBFC863DA}.Release|x86.Build.0 = Release|x86 + {5F64B3C3-0C2E-431A-B820-A81BBFC863DA}.Release|x64.ActiveCfg = Release|Any CPU + {5F64B3C3-0C2E-431A-B820-A81BBFC863DA}.Release|x64.Build.0 = Release|Any CPU + {5F64B3C3-0C2E-431A-B820-A81BBFC863DA}.Release|x86.ActiveCfg = Release|Any CPU + {5F64B3C3-0C2E-431A-B820-A81BBFC863DA}.Release|x86.Build.0 = Release|Any CPU {9559A5F1-080C-4909-B6CF-7E4B3DC55748}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {9559A5F1-080C-4909-B6CF-7E4B3DC55748}.Debug|Any CPU.Build.0 = Debug|Any CPU {9559A5F1-080C-4909-B6CF-7E4B3DC55748}.Debug|x64.ActiveCfg = Debug|x64 @@ -151,8 +151,8 @@ Global {9559A5F1-080C-4909-B6CF-7E4B3DC55748}.Release|Any CPU.Build.0 = Release|Any CPU {9559A5F1-080C-4909-B6CF-7E4B3DC55748}.Release|x64.ActiveCfg = Release|x64 {9559A5F1-080C-4909-B6CF-7E4B3DC55748}.Release|x64.Build.0 = Release|x64 - {9559A5F1-080C-4909-B6CF-7E4B3DC55748}.Release|x86.ActiveCfg = Release|x86 - {9559A5F1-080C-4909-B6CF-7E4B3DC55748}.Release|x86.Build.0 = Release|x86 + {9559A5F1-080C-4909-B6CF-7E4B3DC55748}.Release|x86.ActiveCfg = Release|Any CPU + {9559A5F1-080C-4909-B6CF-7E4B3DC55748}.Release|x86.Build.0 = Release|Any CPU {EBFE9719-A44B-4978-A71F-D5C254E7F35A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {EBFE9719-A44B-4978-A71F-D5C254E7F35A}.Debug|Any CPU.Build.0 = Debug|Any CPU {EBFE9719-A44B-4978-A71F-D5C254E7F35A}.Debug|x64.ActiveCfg = Debug|x64 @@ -163,8 +163,8 @@ Global {EBFE9719-A44B-4978-A71F-D5C254E7F35A}.Release|Any CPU.Build.0 = Release|Any CPU {EBFE9719-A44B-4978-A71F-D5C254E7F35A}.Release|x64.ActiveCfg = Release|x64 {EBFE9719-A44B-4978-A71F-D5C254E7F35A}.Release|x64.Build.0 = Release|x64 - {EBFE9719-A44B-4978-A71F-D5C254E7F35A}.Release|x86.ActiveCfg = Release|x86 - {EBFE9719-A44B-4978-A71F-D5C254E7F35A}.Release|x86.Build.0 = Release|x86 + {EBFE9719-A44B-4978-A71F-D5C254E7F35A}.Release|x86.ActiveCfg = Release|Any CPU + {EBFE9719-A44B-4978-A71F-D5C254E7F35A}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/NuGet.config b/NuGet.config index 7e1d6d073e..69bab2da9a 100644 --- a/NuGet.config +++ b/NuGet.config @@ -6,4 +6,4 @@ - \ No newline at end of file + diff --git a/appveyor.yml b/appveyor.yml index 7617e58a1e..13c0650228 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -11,4 +11,4 @@ build_script: clone_depth: 1 test: off deploy: off -os: Visual Studio 2017 RC \ No newline at end of file +os: Visual Studio 2017 RC diff --git a/build/repo.props b/build/repo.props new file mode 100644 index 0000000000..a5d5b0f21d --- /dev/null +++ b/build/repo.props @@ -0,0 +1,5 @@ + + + + + diff --git a/build/repo.targets b/build/repo.targets new file mode 100644 index 0000000000..d05edf3572 --- /dev/null +++ b/build/repo.targets @@ -0,0 +1,5 @@ + + + + + diff --git a/samples/LargeResponseApp/LargeResponseApp.csproj b/samples/LargeResponseApp/LargeResponseApp.csproj index 45de356f95..3af02d73c5 100644 --- a/samples/LargeResponseApp/LargeResponseApp.csproj +++ b/samples/LargeResponseApp/LargeResponseApp.csproj @@ -7,6 +7,7 @@ Exe win7-x64 + false diff --git a/samples/LargeResponseApp/runtimeconfig.template.json b/samples/LargeResponseApp/runtimeconfig.template.json deleted file mode 100644 index 7305508a37..0000000000 --- a/samples/LargeResponseApp/runtimeconfig.template.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "configProperties": { - "System.GC.Server": true - } -} \ No newline at end of file diff --git a/samples/SampleApp/SampleApp.csproj b/samples/SampleApp/SampleApp.csproj index 19792a43e2..7d7dab864e 100644 --- a/samples/SampleApp/SampleApp.csproj +++ b/samples/SampleApp/SampleApp.csproj @@ -7,6 +7,8 @@ Exe win7-x64 + false + 1.2.0-* diff --git a/samples/SampleApp/runtimeconfig.template.json b/samples/SampleApp/runtimeconfig.template.json deleted file mode 100644 index 7305508a37..0000000000 --- a/samples/SampleApp/runtimeconfig.template.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "configProperties": { - "System.GC.Server": true - } -} \ No newline at end of file diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Https/Microsoft.AspNetCore.Server.Kestrel.Https.csproj b/src/Microsoft.AspNetCore.Server.Kestrel.Https/Microsoft.AspNetCore.Server.Kestrel.Https.csproj index 7765f0e77a..a314782a45 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Https/Microsoft.AspNetCore.Server.Kestrel.Https.csproj +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Https/Microsoft.AspNetCore.Server.Kestrel.Https.csproj @@ -12,6 +12,9 @@ + + + diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests.csproj b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests.csproj index fa3f75fdba..ac06d2b346 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests.csproj +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests.csproj @@ -6,7 +6,7 @@ netcoreapp1.1;net452 netcoreapp1.1 - win7-x64 + win7-x64 @@ -16,15 +16,18 @@ - - - + + + + + - + + @@ -35,14 +38,15 @@ - - - - + + + + + - - $(DefineConstants);DARWIN + + $(DefineConstants);$(OSPlatform.ToUpperInvariant()) - + \ No newline at end of file diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/Properties/AssemblyInfo.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/Properties/AssemblyInfo.cs index e067e94cf3..24fe027b5e 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/Properties/AssemblyInfo.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/Properties/AssemblyInfo.cs @@ -1,8 +1,8 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +#if MACOS using Xunit; -#if DARWIN [assembly: CollectionBehavior(DisableTestParallelization = true)] #endif diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/.notest b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/.notest deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Microsoft.AspNetCore.Server.Kestrel.Performance.csproj b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Microsoft.AspNetCore.Server.Kestrel.Performance.csproj index f234b8fb10..bae45dfafb 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Microsoft.AspNetCore.Server.Kestrel.Performance.csproj +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Microsoft.AspNetCore.Server.Kestrel.Performance.csproj @@ -5,6 +5,8 @@ netcoreapp1.1 Exe + true + false @@ -18,6 +20,9 @@ + + + diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/runtimeconfig.template.json b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/runtimeconfig.template.json deleted file mode 100644 index 7305508a37..0000000000 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/runtimeconfig.template.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "configProperties": { - "System.GC.Server": true - } -} \ No newline at end of file diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/Microsoft.AspNetCore.Server.KestrelTests.csproj b/test/Microsoft.AspNetCore.Server.KestrelTests/Microsoft.AspNetCore.Server.KestrelTests.csproj index 7af504a271..322597f3a2 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/Microsoft.AspNetCore.Server.KestrelTests.csproj +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/Microsoft.AspNetCore.Server.KestrelTests.csproj @@ -17,16 +17,19 @@ + + + + + + - - - - + \ No newline at end of file diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/UvStreamHandleTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/UvStreamHandleTests.cs index 51dbce5b5d..355447f545 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/UvStreamHandleTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/UvStreamHandleTests.cs @@ -1,4 +1,7 @@ -using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; using Microsoft.AspNetCore.Server.KestrelTests.TestHelpers; using Moq; diff --git a/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode.csproj b/tools/CodeGenerator/CodeGenerator.csproj similarity index 58% rename from tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode.csproj rename to tools/CodeGenerator/CodeGenerator.csproj index dafd54104a..c99ff50075 100644 --- a/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode.csproj +++ b/tools/CodeGenerator/CodeGenerator.csproj @@ -5,6 +5,7 @@ netcoreapp1.1 Exe + false @@ -12,4 +13,9 @@ + + $(MSBuildThisFileDirectory)..\..\src\Microsoft.AspNetCore.Server.Kestrel\Internal\Http + FrameHeaders.Generated.cs Frame.Generated.cs + + diff --git a/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/FrameFeatureCollection.cs b/tools/CodeGenerator/FrameFeatureCollection.cs similarity index 95% rename from tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/FrameFeatureCollection.cs rename to tools/CodeGenerator/FrameFeatureCollection.cs index 9f46ddfd11..22e6a9316b 100644 --- a/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/FrameFeatureCollection.cs +++ b/tools/CodeGenerator/FrameFeatureCollection.cs @@ -1,10 +1,13 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + using System; using System.Collections.Generic; using System.Linq; using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Http.Features.Authentication; -namespace Microsoft.AspNetCore.Server.Kestrel.GeneratedCode +namespace CodeGenerator { // This project can output the Class library as a NuGet Package. // To enable this option, right-click on the project and select the Properties menu item. In the Build tab select "Produce outputs on build". diff --git a/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/KnownHeaders.cs b/tools/CodeGenerator/KnownHeaders.cs similarity index 98% rename from tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/KnownHeaders.cs rename to tools/CodeGenerator/KnownHeaders.cs index 96cc6a350a..0e2fdf858f 100644 --- a/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/KnownHeaders.cs +++ b/tools/CodeGenerator/KnownHeaders.cs @@ -1,10 +1,13 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Text; -namespace Microsoft.AspNetCore.Server.Kestrel.GeneratedCode +namespace CodeGenerator { // This project can output the Class library as a NuGet Package. // To enable this option, right-click on the project and select the Properties menu item. In the Build tab select "Produce outputs on build". @@ -20,7 +23,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.GeneratedCode return condition ? formatter() : ""; } - static string AppendSwitch(IEnumerable> values, string className) => + static string AppendSwitch(IEnumerable> values, string className) => $@"var pUL = (ulong*)pUB; var pUI = (uint*)pUB; var pUS = (ushort*)pUB; @@ -73,7 +76,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.GeneratedCode public string TestNotBit() => $"(_bits & {1L << Index}L) == 0"; public string SetBit() => $"_bits |= {1L << Index}L"; public string ClearBit() => $"_bits &= ~{1L << Index}L"; - + public string EqualIgnoreCaseBytes() { var result = ""; @@ -530,10 +533,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http }} else ")} {{ - var valueCount = _headers._{header.Identifier}.Count; - for (var i = 0; i < valueCount; i++) + var valueCount = _headers._{header.Identifier}.Count; + for (var i = 0; i < valueCount; i++) {{ - var value = _headers._{header.Identifier}[i]; + var value = _headers._{header.Identifier}[i]; if (value != null) {{ output.CopyFrom(_headerBytes, {header.BytesOffset}, {header.BytesCount}); @@ -571,7 +574,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http AppendNonPrimaryHeaders(ptr, keyOffset, keyLength, value); }} }} - + private unsafe void AppendNonPrimaryHeaders(byte* pKeyBytes, int keyOffset, int keyLength, string value) {{ var pUB = pKeyBytes; diff --git a/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/Program.cs b/tools/CodeGenerator/Program.cs similarity index 86% rename from tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/Program.cs rename to tools/CodeGenerator/Program.cs index f0a0814b16..102839b6b7 100644 --- a/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/Program.cs +++ b/tools/CodeGenerator/Program.cs @@ -1,7 +1,10 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + using System; using System.IO; -namespace Microsoft.AspNetCore.Server.Kestrel.GeneratedCode +namespace CodeGenerator { public class Program { diff --git a/version.props b/version.props index e77c8d9c38..29f91e170d 100644 --- a/version.props +++ b/version.props @@ -4,4 +4,4 @@ 1.2.0 preview1 - \ No newline at end of file + From 68cc4fdb2417371cbe367cda9ab657ddbd1b9239 Mon Sep 17 00:00:00 2001 From: Nate McMaster Date: Thu, 16 Feb 2017 18:35:03 -0800 Subject: [PATCH 1042/1662] Remove RuntimeFrameworkVersion from sample --- samples/SampleApp/SampleApp.csproj | 1 - 1 file changed, 1 deletion(-) diff --git a/samples/SampleApp/SampleApp.csproj b/samples/SampleApp/SampleApp.csproj index 7d7dab864e..9d5b086b5c 100644 --- a/samples/SampleApp/SampleApp.csproj +++ b/samples/SampleApp/SampleApp.csproj @@ -8,7 +8,6 @@ win7-x64 false - 1.2.0-* From bfe1f06938eeb68f62898963c69a6e7d4a87a20a Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Tue, 14 Feb 2017 10:53:06 -0800 Subject: [PATCH 1043/1662] Fix AddressRegistrationTests.RegisterAddresses_IPv6ScopeId_Success (#1363). --- .../AddressRegistrationTests.cs | 1 + .../IPv6ScopeIdPresentConditionAttribute.cs | 35 +++++++++++++++++++ .../IPv6SupportedConditionAttribute.cs | 16 ++------- 3 files changed, 38 insertions(+), 14 deletions(-) create mode 100644 test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/IPv6ScopeIdPresentConditionAttribute.cs diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs index 2abb129b52..ecdd2e97ba 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs @@ -70,6 +70,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [ConditionalTheory, MemberData(nameof(AddressRegistrationDataIPv6ScopeId))] [IPv6SupportedCondition] + [IPv6ScopeIdPresentCondition] public async Task RegisterAddresses_IPv6ScopeId_Success(string addressInput, Func testUrls) { await RegisterAddresses_Success(addressInput, testUrls); diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/IPv6ScopeIdPresentConditionAttribute.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/IPv6ScopeIdPresentConditionAttribute.cs new file mode 100644 index 0000000000..f1705b9c7b --- /dev/null +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/IPv6ScopeIdPresentConditionAttribute.cs @@ -0,0 +1,35 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Linq; +using System.Net.NetworkInformation; +using System.Net.Sockets; +using Microsoft.AspNetCore.Testing.xunit; + +namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests +{ + public class IPv6ScopeIdPresentConditionAttribute : Attribute, ITestCondition + { + private static readonly Lazy _ipv6ScopeIdPresent = new Lazy(IPv6ScopeIdAddressPresent); + + public bool IsMet => _ipv6ScopeIdPresent.Value; + + public string SkipReason => "No IPv6 addresses with scope IDs were found on the host."; + + private static bool IPv6ScopeIdAddressPresent() + { + try + { + return NetworkInterface.GetAllNetworkInterfaces() + .Where(iface => iface.OperationalStatus == OperationalStatus.Up) + .SelectMany(iface => iface.GetIPProperties().UnicastAddresses) + .Any(addrInfo => addrInfo.Address.AddressFamily == AddressFamily.InterNetworkV6 && addrInfo.Address.ScopeId != 0); + } + catch (SocketException) + { + return false; + } + } + } +} \ No newline at end of file diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/IPv6SupportedConditionAttribute.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/IPv6SupportedConditionAttribute.cs index ca2f2bc6b9..815a271825 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/IPv6SupportedConditionAttribute.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/IPv6SupportedConditionAttribute.cs @@ -13,21 +13,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { private static readonly Lazy _ipv6Supported = new Lazy(CanBindToIPv6Address); - public bool IsMet - { - get - { - return _ipv6Supported.Value; - } - } + public bool IsMet => _ipv6Supported.Value; - public string SkipReason - { - get - { - return "IPv6 not supported on the host."; - } - } + public string SkipReason => "IPv6 not supported on the host."; private static bool CanBindToIPv6Address() { From 824ef2c9375538a0980c435e661ed04d0fea8916 Mon Sep 17 00:00:00 2001 From: Pavel Krymets Date: Fri, 17 Feb 2017 15:38:13 -0800 Subject: [PATCH 1044/1662] Input Pipeline migration (#1277) --- NuGet.config | 2 + ToProjectReferences.ps1 | 45 ++ .../Adapter/Internal/AdaptedPipeline.cs | 39 +- .../Adapter/Internal/RawStream.cs | 52 +- .../Internal/Http/BufferSizeControl.cs | 77 --- .../Internal/Http/Connection.cs | 105 ++- .../Internal/Http/ConnectionContext.cs | 3 +- .../Internal/Http/ConnectionManager.cs | 2 +- .../Internal/Http/Frame.cs | 641 +++++++++--------- .../Internal/Http/FrameOfT.cs | 89 ++- .../Internal/Http/Listener.cs | 2 +- .../Internal/Http/ListenerContext.cs | 17 + .../Internal/Http/ListenerSecondary.cs | 2 +- .../Internal/Http/MessageBody.cs | 387 ++++++----- .../Internal/Http/PipelineExtensions.cs | 108 +++ .../Internal/Http/RequestRejectionReason.cs | 2 +- .../Internal/Http/SocketInput.cs | 351 ---------- .../Internal/Http/SocketInputExtensions.cs | 90 --- .../Internal/Http/SocketOutput.cs | 2 +- .../Infrastructure/AwaitableThreadPool.cs | 39 ++ .../Internal/Infrastructure/KestrelThread.cs | 35 +- .../MemoryPoolIteratorExtensions.cs | 30 +- ...Microsoft.AspNetCore.Server.Kestrel.csproj | 4 + .../MaxRequestBufferSizeTests.cs | 2 +- ...Core.Server.Kestrel.FunctionalTests.csproj | 2 +- .../PathBaseTests.cs | 3 +- .../RequestTests.cs | 5 +- .../ResponseTests.cs | 8 +- .../ThreadCountTests.cs | 2 +- ...pNetCore.Server.Kestrel.Performance.csproj | 1 - .../PipeThroughput.cs | 68 ++ .../Program.cs | 5 + .../RequestParsing.cs | 82 +-- .../Writing.cs | 5 +- .../ConnectionTests.cs | 10 +- .../FrameTests.cs | 369 +++++----- .../ListenerPrimaryTests.cs | 4 +- .../MemoryPoolIteratorTests.cs | 206 +++--- .../MessageBodyTests.cs | 20 +- ...soft.AspNetCore.Server.KestrelTests.csproj | 2 +- .../SocketInputTests.cs | 243 ------- .../TestInput.cs | 15 +- test/shared/SocketInputExtensions.cs | 37 - 43 files changed, 1421 insertions(+), 1792 deletions(-) create mode 100644 ToProjectReferences.ps1 delete mode 100644 src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/BufferSizeControl.cs create mode 100644 src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/PipelineExtensions.cs delete mode 100644 src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/SocketInput.cs delete mode 100644 src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/SocketInputExtensions.cs create mode 100644 src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/AwaitableThreadPool.cs create mode 100644 test/Microsoft.AspNetCore.Server.Kestrel.Performance/PipeThroughput.cs delete mode 100644 test/Microsoft.AspNetCore.Server.KestrelTests/SocketInputTests.cs delete mode 100644 test/shared/SocketInputExtensions.cs diff --git a/NuGet.config b/NuGet.config index 69bab2da9a..ce00c056c6 100644 --- a/NuGet.config +++ b/NuGet.config @@ -4,6 +4,8 @@ + + diff --git a/ToProjectReferences.ps1 b/ToProjectReferences.ps1 new file mode 100644 index 0000000000..4273aff929 --- /dev/null +++ b/ToProjectReferences.ps1 @@ -0,0 +1,45 @@ +param($references) +$ErrorActionPreference = "Stop"; + +function ToProjectName($file) +{ + return $file.Directory.Name; +} + +$projectreferences = ls (Join-Path $references *.csproj) -rec; + +$localprojects = ls -rec *.csproj; + +foreach ($project in $localprojects) +{ + Write-Host "Processing $project"; + + [Reflection.Assembly]::LoadWithPartialName("System.Xml.Linq") | Out-Null; + + $changed = $false + $xDoc = [System.Xml.Linq.XDocument]::Load($project, [System.Xml.Linq.LoadOptions]::PreserveWhitespace); + $endpoints = $xDoc.Descendants("PackageReference") | %{ + $packageName = $_.Attribute("Include").Value; + $replacementProject = $projectreferences | ? { + return (ToProjectName($_)) -eq $packageName + }; + + if ($replacementProject) + { + $changed = $true + Write-Host " Replacing $packageName with $($project.FullName)"; + $_.Name = "ProjectReference"; + $_.Attribute("Include").Value = $replacementProject.FullName; + } + }; + if ($changed) + { + $settings = New-Object System.Xml.XmlWriterSettings + $settings.OmitXmlDeclaration = $true; + $writer = [System.Xml.XmlWriter]::Create($project, $settings) + + $xDoc.Save($writer); + $writer.Dispose(); + } + +} \ No newline at end of file diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Adapter/Internal/AdaptedPipeline.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Adapter/Internal/AdaptedPipeline.cs index 28c8fd66e1..f3ca1812ae 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Adapter/Internal/AdaptedPipeline.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Adapter/Internal/AdaptedPipeline.cs @@ -3,37 +3,40 @@ using System; using System.IO; +using System.IO.Pipelines; using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; +using MemoryPool = Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPool; namespace Microsoft.AspNetCore.Server.Kestrel.Adapter.Internal { public class AdaptedPipeline : IDisposable { + private const int MinAllocBufferSize = 2048; + private readonly Stream _filteredStream; public AdaptedPipeline( string connectionId, Stream filteredStream, + IPipe pipe, MemoryPool memory, - IKestrelTrace logger, - IThreadPool threadPool, - IBufferSizeControl bufferSizeControl) + IKestrelTrace logger) { - SocketInput = new SocketInput(memory, threadPool, bufferSizeControl); - SocketOutput = new StreamSocketOutput(connectionId, filteredStream, memory, logger); + Input = pipe; + Output = new StreamSocketOutput(connectionId, filteredStream, memory, logger); _filteredStream = filteredStream; } - public SocketInput SocketInput { get; } + public IPipe Input { get; } - public ISocketOutput SocketOutput { get; } + public ISocketOutput Output { get; } public void Dispose() { - SocketInput.Dispose(); + Input.Writer.Complete(); } public async Task ReadInputAsync() @@ -42,21 +45,29 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Adapter.Internal do { - var block = SocketInput.IncomingStart(); + var block = Input.Writer.Alloc(MinAllocBufferSize); try { - var count = block.Data.Offset + block.Data.Count - block.End; - bytesRead = await _filteredStream.ReadAsync(block.Array, block.End, count); + var array = block.Memory.GetArray(); + try + { + bytesRead = await _filteredStream.ReadAsync(array.Array, array.Offset, array.Count); + block.Advance(bytesRead); + } + finally + { + await block.FlushAsync(); + } } catch (Exception ex) { - SocketInput.IncomingComplete(0, ex); + Input.Writer.Complete(ex); throw; } - - SocketInput.IncomingComplete(bytesRead, error: null); } while (bytesRead != 0); + + Input.Writer.Complete(); } } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Adapter/Internal/RawStream.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Adapter/Internal/RawStream.cs index 0824eeb594..3ec258b19d 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Adapter/Internal/RawStream.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Adapter/Internal/RawStream.cs @@ -3,6 +3,7 @@ using System; using System.IO; +using System.IO.Pipelines; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; @@ -12,12 +13,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Adapter.Internal { public class RawStream : Stream { - private readonly SocketInput _input; + private readonly IPipeReader _input; private readonly ISocketOutput _output; - private Task _cachedTask = TaskCache.DefaultCompletedTask; - - public RawStream(SocketInput input, ISocketOutput output) + public RawStream(IPipeReader input, ISocketOutput output) { _input = input; _output = output; @@ -68,23 +67,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Adapter.Internal public override Task ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) { - var task = ReadAsync(new ArraySegment(buffer, offset, count)); - - if (task.IsCompletedSuccessfully) - { - if (_cachedTask.Result != task.Result) - { - // Needs .AsTask to match Stream's Async method return types - _cachedTask = task.AsTask(); - } - } - else - { - // Needs .AsTask to match Stream's Async method return types - _cachedTask = task.AsTask(); - } - - return _cachedTask; + return ReadAsync(new ArraySegment(buffer, offset, count)); } public override void Write(byte[] buffer, int offset, int count) @@ -125,10 +108,31 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Adapter.Internal return _output.FlushAsync(cancellationToken); } - - private ValueTask ReadAsync(ArraySegment buffer) + private async Task ReadAsync(ArraySegment buffer) { - return _input.ReadAsync(buffer.Array, buffer.Offset, buffer.Count); + while (true) + { + var result = await _input.ReadAsync(); + var readableBuffer = result.Buffer; + try + { + if (!readableBuffer.IsEmpty) + { + var count = Math.Min(readableBuffer.Length, buffer.Count); + readableBuffer = readableBuffer.Slice(0, count); + readableBuffer.CopyTo(buffer); + return count; + } + else if (result.IsCompleted || result.IsCancelled) + { + return 0; + } + } + finally + { + _input.Advance(readableBuffer.End, readableBuffer.End); + } + } } #if NET451 diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/BufferSizeControl.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/BufferSizeControl.cs deleted file mode 100644 index 364a1a2cf8..0000000000 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/BufferSizeControl.cs +++ /dev/null @@ -1,77 +0,0 @@ -using System.Diagnostics; - -namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http -{ - public class BufferSizeControl : IBufferSizeControl - { - private readonly long _maxSize; - private readonly IConnectionControl _connectionControl; - - private readonly object _lock = new object(); - - private long _size; - private bool _connectionPaused; - - public BufferSizeControl(long maxSize, IConnectionControl connectionControl) - { - _maxSize = maxSize; - _connectionControl = connectionControl; - } - - private long Size - { - get - { - return _size; - } - set - { - // Caller should ensure that bytes are never consumed before the producer has called Add() - Debug.Assert(value >= 0); - _size = value; - } - } - - public void Add(int count) - { - Debug.Assert(count >= 0); - - if (count == 0) - { - // No-op and avoid taking lock to reduce contention - return; - } - - lock (_lock) - { - Size += count; - if (!_connectionPaused && Size >= _maxSize) - { - _connectionPaused = true; - _connectionControl.Pause(); - } - } - } - - public void Subtract(int count) - { - Debug.Assert(count >= 0); - - if (count == 0) - { - // No-op and avoid taking lock to reduce contention - return; - } - - lock (_lock) - { - Size -= count; - if (_connectionPaused && Size < _maxSize) - { - _connectionPaused = false; - _connectionControl.Resume(); - } - } - } - } -} diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Connection.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Connection.cs index 12b978687b..f2211cdc6c 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Connection.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Connection.cs @@ -5,6 +5,7 @@ using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; +using System.IO.Pipelines; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Adapter; @@ -18,6 +19,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { public class Connection : ConnectionContext, IConnectionControl { + private const int MinAllocBufferSize = 2048; + // Base32 encoding - in ascii sort order for easy text based sorting private static readonly string _encode32Chars = "0123456789ABCDEFGHIJKLMNOPQRSTUV"; @@ -40,11 +43,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http private Task _readInputTask; private TaskCompletionSource _socketClosedTcs = new TaskCompletionSource(); - private BufferSizeControl _bufferSizeControl; private long _lastTimestamp; private long _timeoutTimestamp = long.MaxValue; private TimeoutAction _timeoutAction; + private WritableBuffer? _currentWritableBuffer; public Connection(ListenerContext context, UvStreamHandle socket) : base(context) { @@ -55,12 +58,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http ConnectionId = GenerateConnectionId(Interlocked.Increment(ref _lastConnectionId)); - if (ServerOptions.Limits.MaxRequestBufferSize.HasValue) - { - _bufferSizeControl = new BufferSizeControl(ServerOptions.Limits.MaxRequestBufferSize.Value, this); - } - - Input = new SocketInput(Thread.Memory, ThreadPool, _bufferSizeControl); + Input = Thread.PipelineFactory.Create(ListenerContext.LibuvPipeOptions); Output = new SocketOutput(Thread, _socket, this, ConnectionId, Log, ThreadPool); var tcpHandle = _socket as UvTcpHandle; @@ -92,6 +90,21 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http // Start socket prior to applying the ConnectionAdapter _socket.ReadStart(_allocCallback, _readCallback, this); + // Dispatch to a thread pool so if the first read completes synchronously + // we won't be on IO thread + try + { + ThreadPool.UnsafeRun(state => ((Connection)state).StartFrame(), this); + } + catch (Exception e) + { + Log.LogError(0, e, "Connection.StartFrame"); + throw; + } + } + + private void StartFrame() + { if (_connectionAdapters.Count == 0) { _frame.Start(); @@ -107,7 +120,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http public Task StopAsync() { _frame.StopAsync(); - _frame.Input.CompleteAwaiting(); + _frame.Input.Reader.CancelPendingRead(); return _socketClosedTcs.Task; } @@ -138,11 +151,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var connection2 = (Connection)state2; connection2._filteredStream.Dispose(); connection2._adaptedPipeline.Dispose(); + Input.Reader.Complete(); }, connection); } }, this); - Input.Dispose(); + Input.Writer.Complete(new TaskCanceledException("The request was aborted")); _socketClosedTcs.TrySetResult(null); } @@ -168,7 +182,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { try { - var rawStream = new RawStream(Input, Output); + var rawStream = new RawStream(Input.Reader, Output); var adapterContext = new ConnectionAdapterContext(rawStream); var adaptedConnections = new IAdaptedConnection[_connectionAdapters.Count]; @@ -182,11 +196,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if (adapterContext.ConnectionStream != rawStream) { _filteredStream = adapterContext.ConnectionStream; - _adaptedPipeline = new AdaptedPipeline(ConnectionId, adapterContext.ConnectionStream, - Thread.Memory, Log, ThreadPool, _bufferSizeControl); + _adaptedPipeline = new AdaptedPipeline( + ConnectionId, + adapterContext.ConnectionStream, + Thread.PipelineFactory.Create(ListenerContext.AdaptedPipeOptions), + Thread.Memory, + Log); - _frame.Input = _adaptedPipeline.SocketInput; - _frame.Output = _adaptedPipeline.SocketOutput; + _frame.Input = _adaptedPipeline.Input; + _frame.Output = _adaptedPipeline.Output; // Don't attempt to read input if connection has already closed. // This can happen if a client opens a connection and immediately closes it. @@ -201,6 +219,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http catch (Exception ex) { Log.LogError(0, ex, $"Uncaught exception from the {nameof(IConnectionAdapter.OnConnectionAsync)} method of an {nameof(IConnectionAdapter)}."); + Input.Reader.Complete(); ConnectionControl.End(ProduceEndType.SocketDisconnect); } } @@ -210,13 +229,18 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http return ((Connection)state).OnAlloc(handle, suggestedSize); } - private Libuv.uv_buf_t OnAlloc(UvStreamHandle handle, int suggestedSize) + private unsafe Libuv.uv_buf_t OnAlloc(UvStreamHandle handle, int suggestedSize) { - var result = Input.IncomingStart(); + Debug.Assert(_currentWritableBuffer == null); + var currentWritableBuffer = Input.Writer.Alloc(MinAllocBufferSize); + _currentWritableBuffer = currentWritableBuffer; + void* dataPtr; + var tryGetPointer = currentWritableBuffer.Memory.TryGetPointer(out dataPtr); + Debug.Assert(tryGetPointer); return handle.Libuv.buf_init( - result.DataArrayPtr + result.End, - result.Data.Offset + result.Data.Count - result.End); + (IntPtr)dataPtr, + currentWritableBuffer.Memory.Length); } private static void ReadCallback(UvStreamHandle handle, int status, object state) @@ -224,19 +248,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http ((Connection)state).OnRead(handle, status); } - private void OnRead(UvStreamHandle handle, int status) + private async void OnRead(UvStreamHandle handle, int status) { - if (status == 0) - { - // A zero status does not indicate an error or connection end. It indicates - // there is no data to be read right now. - // See the note at http://docs.libuv.org/en/v1.x/stream.html#c.uv_read_cb. - // We need to clean up whatever was allocated by OnAlloc. - Input.IncomingDeferred(); - return; - } - - var normalRead = status > 0; + var normalRead = status >= 0; var normalDone = status == Constants.EOF; var errorDone = !(normalDone || normalRead); var readCount = normalRead ? status : 0; @@ -256,6 +270,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } IOException error = null; + WritableBufferAwaitable? flushTask = null; if (errorDone) { Exception uvError; @@ -272,13 +287,31 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } error = new IOException(uvError.Message, uvError); + _currentWritableBuffer?.Commit(); + } + else + { + Debug.Assert(_currentWritableBuffer != null); + + var currentWritableBuffer = _currentWritableBuffer.Value; + currentWritableBuffer.Advance(readCount); + flushTask = currentWritableBuffer.FlushAsync(); } - Input.IncomingComplete(readCount, error); + _currentWritableBuffer = null; + if (flushTask?.IsCompleted == false) + { + OnPausePosted(); + if (await flushTask.Value) + { + OnResumePosted(); + } + } if (!normalRead) { - AbortAsync(error); + Input.Writer.Complete(error); + var ignore = AbortAsync(error); } } @@ -289,7 +322,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http // Even though this method is called on the event loop already, // post anyway so the ReadStop() call doesn't get reordered // relative to the ReadStart() call made in Resume(). - Thread.Post(state => ((Connection)state).OnPausePosted(), this); + Thread.Post(state => state.OnPausePosted(), this); } void IConnectionControl.Resume() @@ -297,7 +330,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http Log.ConnectionResume(ConnectionId); // This is called from the consuming thread. - Thread.Post(state => ((Connection)state).OnResumePosted(), this); + Thread.Post(state => state.OnResumePosted(), this); } private void OnPausePosted() @@ -316,14 +349,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { try { - _socket.ReadStart(_allocCallback, _readCallback, this); + _socket.ReadStart(_allocCallback, _readCallback, this); } catch (UvException) { // ReadStart() can throw a UvException in some cases (e.g. socket is no longer connected). // This should be treated the same as OnRead() seeing a "normalDone" condition. Log.ConnectionReadFin(ConnectionId); - Input.IncomingComplete(0, null); + Input.Writer.Complete(); } } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ConnectionContext.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ConnectionContext.cs index decc5dbf8c..267f34ddaa 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ConnectionContext.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ConnectionContext.cs @@ -3,6 +3,7 @@ using System; using System.Net; +using System.IO.Pipelines; using Microsoft.AspNetCore.Http.Features; namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http @@ -20,7 +21,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http public ListenerContext ListenerContext { get; set; } - public SocketInput Input { get; set; } + public IPipe Input { get; set; } public ISocketOutput Output { get; set; } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ConnectionManager.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ConnectionManager.cs index 884324f0e8..dbea0eefed 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ConnectionManager.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ConnectionManager.cs @@ -34,7 +34,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { var tcs = new TaskCompletionSource(); - _thread.Post(state => action((ConnectionManager)state, tcs), this); + _thread.Post(state => action(state, tcs), this); return await Task.WhenAny(tcs.Task, Task.Delay(timeout)).ConfigureAwait(false) == tcs.Task; } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs index e72549c71e..7a3d04e8d8 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs @@ -5,10 +5,14 @@ using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; +using System.IO.Pipelines; +using System.IO.Pipelines.Text.Primitives; using System.Linq; using System.Net; using System.Runtime.CompilerServices; using System.Text; +using System.Text.Encodings.Web.Utf8; +using System.Text.Utf8; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; @@ -95,7 +99,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } public ConnectionContext ConnectionContext { get; } - public SocketInput Input { get; set; } + public IPipe Input { get; set; } public ISocketOutput Output { get; set; } public IEnumerable AdaptedConnections { get; set; } @@ -386,13 +390,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http public void Start() { Reset(); - _requestProcessingTask = - Task.Factory.StartNew( - (o) => ((Frame)o).RequestProcessingAsync(), - this, - default(CancellationToken), - TaskCreationOptions.DenyChildAttach, - TaskScheduler.Default).Unwrap(); + _requestProcessingTask = RequestProcessingAsync(); _frameStartedTcs.SetResult(null); } @@ -986,216 +984,204 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http Output.ProducingComplete(end); } - public RequestLineStatus TakeStartLine(SocketInput input) + public bool TakeStartLine(ReadableBuffer buffer, out ReadCursor consumed, out ReadCursor examined) { - const int MaxInvalidRequestLineChars = 32; + var start = buffer.Start; + var end = buffer.Start; - var scan = input.ConsumingStart(); - var start = scan; - var consumed = scan; - var end = scan; + examined = buffer.End; + consumed = buffer.Start; - try + if (_requestProcessingStatus == RequestProcessingStatus.RequestPending) { - // We may hit this when the client has stopped sending data but - // the connection hasn't closed yet, and therefore Frame.Stop() - // hasn't been called yet. - if (scan.Peek() == -1) + ConnectionControl.ResetTimeout(_requestHeadersTimeoutMilliseconds, TimeoutAction.SendTimeoutResponse); + } + + _requestProcessingStatus = RequestProcessingStatus.RequestStarted; + + var limitedBuffer = buffer; + if (buffer.Length >= ServerOptions.Limits.MaxRequestLineSize) + { + limitedBuffer = buffer.Slice(0, ServerOptions.Limits.MaxRequestLineSize); + } + if (ReadCursorOperations.Seek(limitedBuffer.Start, limitedBuffer.End, out end, ByteLF) == -1) + { + if (limitedBuffer.Length == ServerOptions.Limits.MaxRequestLineSize) { - return RequestLineStatus.Empty; - } - - if (_requestProcessingStatus == RequestProcessingStatus.RequestPending) - { - ConnectionControl.ResetTimeout(_requestHeadersTimeoutMilliseconds, TimeoutAction.SendTimeoutResponse); - } - - _requestProcessingStatus = RequestProcessingStatus.RequestStarted; - - int bytesScanned; - if (end.Seek(ByteLF, out bytesScanned, ServerOptions.Limits.MaxRequestLineSize) == -1) - { - if (bytesScanned >= ServerOptions.Limits.MaxRequestLineSize) - { - RejectRequest(RequestRejectionReason.RequestLineTooLong); - } - else - { - return RequestLineStatus.Incomplete; - } - } - end.Take(); - - string method; - var begin = scan; - if (!begin.GetKnownMethod(out method)) - { - if (scan.Seek(ByteSpace, ref end) == -1) - { - RejectRequest(RequestRejectionReason.InvalidRequestLine, - Log.IsEnabled(LogLevel.Information) ? start.GetAsciiStringEscaped(end, MaxInvalidRequestLineChars) : string.Empty); - } - - method = begin.GetAsciiString(ref scan); - - if (method == null) - { - RejectRequest(RequestRejectionReason.InvalidRequestLine, - Log.IsEnabled(LogLevel.Information) ? start.GetAsciiStringEscaped(end, MaxInvalidRequestLineChars) : string.Empty); - } - - // Note: We're not in the fast path any more (GetKnownMethod should have handled any HTTP Method we're aware of) - // So we can be a tiny bit slower and more careful here. - for (int i = 0; i < method.Length; i++) - { - if (!IsValidTokenChar(method[i])) - { - RejectRequest(RequestRejectionReason.InvalidRequestLine, - Log.IsEnabled(LogLevel.Information) ? start.GetAsciiStringEscaped(end, MaxInvalidRequestLineChars) : string.Empty); - } - } + RejectRequest(RequestRejectionReason.RequestLineTooLong); } else { - scan.Skip(method.Length); + return false; + } + } + + end = buffer.Move(end, 1); + ReadCursor methodEnd; + string method; + if (!buffer.GetKnownMethod(out method)) + { + if (ReadCursorOperations.Seek(buffer.Start, end, out methodEnd, ByteSpace) == -1) + { + RejectRequestLine(start, end); } - scan.Take(); - begin = scan; - var needDecode = false; - var chFound = scan.Seek(ByteSpace, ByteQuestionMark, BytePercentage, ref end); + method = buffer.Slice(buffer.Start, methodEnd).GetAsciiString(); + + if (method == null) + { + RejectRequestLine(start, end); + } + + // Note: We're not in the fast path any more (GetKnownMethod should have handled any HTTP Method we're aware of) + // So we can be a tiny bit slower and more careful here. + for (int i = 0; i < method.Length; i++) + { + if (!IsValidTokenChar(method[i])) + { + RejectRequestLine(start, end); + } + } + } + else + { + methodEnd = buffer.Slice(method.Length).Start; + } + + var needDecode = false; + ReadCursor pathEnd; + + var pathBegin = buffer.Move(methodEnd, 1); + + var chFound = ReadCursorOperations.Seek(pathBegin, end, out pathEnd, ByteSpace, ByteQuestionMark, BytePercentage); + if (chFound == -1) + { + RejectRequestLine(start, end); + } + else if (chFound == BytePercentage) + { + needDecode = true; + chFound = ReadCursorOperations.Seek(pathBegin, end, out pathEnd, ByteSpace, ByteQuestionMark); if (chFound == -1) { - RejectRequest(RequestRejectionReason.InvalidRequestLine, - Log.IsEnabled(LogLevel.Information) ? start.GetAsciiStringEscaped(end, MaxInvalidRequestLineChars) : string.Empty); - } - else if (chFound == BytePercentage) - { - needDecode = true; - chFound = scan.Seek(ByteSpace, ByteQuestionMark, ref end); - if (chFound == -1) - { - RejectRequest(RequestRejectionReason.InvalidRequestLine, - Log.IsEnabled(LogLevel.Information) ? start.GetAsciiStringEscaped(end, MaxInvalidRequestLineChars) : string.Empty); - } + RejectRequestLine(start, end); } + }; - var pathBegin = begin; - var pathEnd = scan; - - var queryString = ""; - if (chFound == ByteQuestionMark) - { - begin = scan; - if (scan.Seek(ByteSpace, ref end) == -1) - { - RejectRequest(RequestRejectionReason.InvalidRequestLine, - Log.IsEnabled(LogLevel.Information) ? start.GetAsciiStringEscaped(end, MaxInvalidRequestLineChars) : string.Empty); - } - queryString = begin.GetAsciiString(ref scan); - } - - var queryEnd = scan; - - if (pathBegin.Peek() == ByteSpace) - { - RejectRequest(RequestRejectionReason.InvalidRequestLine, - Log.IsEnabled(LogLevel.Information) ? start.GetAsciiStringEscaped(end, MaxInvalidRequestLineChars) : string.Empty); - } - - scan.Take(); - begin = scan; - if (scan.Seek(ByteCR, ref end) == -1) - { - RejectRequest(RequestRejectionReason.InvalidRequestLine, - Log.IsEnabled(LogLevel.Information) ? start.GetAsciiStringEscaped(end, MaxInvalidRequestLineChars) : string.Empty); - } - - string httpVersion; - if (!begin.GetKnownVersion(out httpVersion)) - { - httpVersion = begin.GetAsciiStringEscaped(scan, 9); - - if (httpVersion == string.Empty) - { - RejectRequest(RequestRejectionReason.InvalidRequestLine, - Log.IsEnabled(LogLevel.Information) ? start.GetAsciiStringEscaped(end, MaxInvalidRequestLineChars) : string.Empty); - } - else - { - RejectRequest(RequestRejectionReason.UnrecognizedHTTPVersion, httpVersion); - } - } - - scan.Take(); // consume CR - if (scan.Take() != ByteLF) - { - RejectRequest(RequestRejectionReason.InvalidRequestLine, - Log.IsEnabled(LogLevel.Information) ? start.GetAsciiStringEscaped(end, MaxInvalidRequestLineChars) : string.Empty); - } - - // URIs are always encoded/escaped to ASCII https://tools.ietf.org/html/rfc3986#page-11 - // Multibyte Internationalized Resource Identifiers (IRIs) are first converted to utf8; - // then encoded/escaped to ASCII https://www.ietf.org/rfc/rfc3987.txt "Mapping of IRIs to URIs" - string requestUrlPath; - string rawTarget; - if (needDecode) - { - // Read raw target before mutating memory. - rawTarget = pathBegin.GetAsciiString(ref queryEnd); - - // URI was encoded, unescape and then parse as utf8 - pathEnd = UrlPathDecoder.Unescape(pathBegin, pathEnd); - requestUrlPath = pathBegin.GetUtf8String(ref pathEnd); - } - else - { - // URI wasn't encoded, parse as ASCII - requestUrlPath = pathBegin.GetAsciiString(ref pathEnd); - - if (queryString.Length == 0) - { - // No need to allocate an extra string if the path didn't need - // decoding and there's no query string following it. - rawTarget = requestUrlPath; - } - else - { - rawTarget = pathBegin.GetAsciiString(ref queryEnd); - } - } - - var normalizedTarget = PathNormalizer.RemoveDotSegments(requestUrlPath); - - consumed = scan; - Method = method; - QueryString = queryString; - RawTarget = rawTarget; - HttpVersion = httpVersion; - - bool caseMatches; - if (RequestUrlStartsWithPathBase(normalizedTarget, out caseMatches)) - { - PathBase = caseMatches ? _pathBase : normalizedTarget.Substring(0, _pathBase.Length); - Path = normalizedTarget.Substring(_pathBase.Length); - } - else if (rawTarget[0] == '/') // check rawTarget since normalizedTarget can be "" or "/" after dot segment removal - { - Path = normalizedTarget; - } - else - { - Path = string.Empty; - PathBase = string.Empty; - QueryString = string.Empty; - } - - return RequestLineStatus.Done; - } - finally + var queryString = ""; + ReadCursor queryEnd = pathEnd; + if (chFound == ByteQuestionMark) { - input.ConsumingComplete(consumed, end); + if (ReadCursorOperations.Seek(pathEnd, end, out queryEnd, ByteSpace) == -1) + { + RejectRequestLine(start, end); + } + queryString = buffer.Slice(pathEnd, queryEnd).GetAsciiString(); } + + // No path + if (pathBegin == pathEnd) + { + RejectRequestLine(start, end); + } + + ReadCursor versionEnd; + if (ReadCursorOperations.Seek(queryEnd, end, out versionEnd, ByteCR) == -1) + { + RejectRequestLine(start, end); + } + + string httpVersion; + var versionBuffer = buffer.Slice(queryEnd, end).Slice(1); + if (!versionBuffer.GetKnownVersion(out httpVersion)) + { + httpVersion = versionBuffer.Start.GetAsciiStringEscaped(versionEnd, 9); + + if (httpVersion == string.Empty) + { + RejectRequestLine(start, end); + } + else + { + RejectRequest(RequestRejectionReason.UnrecognizedHTTPVersion, httpVersion); + } + } + + var lineEnd = buffer.Slice(versionEnd, 2).ToSpan(); + if (lineEnd[1] != ByteLF) + { + RejectRequestLine(start, end); + } + + var pathBuffer = buffer.Slice(pathBegin, pathEnd); + var targetBuffer = buffer.Slice(pathBegin, queryEnd); + + // URIs are always encoded/escaped to ASCII https://tools.ietf.org/html/rfc3986#page-11 + // Multibyte Internationalized Resource Identifiers (IRIs) are first converted to utf8; + // then encoded/escaped to ASCII https://www.ietf.org/rfc/rfc3987.txt "Mapping of IRIs to URIs" + string requestUrlPath; + string rawTarget; + if (needDecode) + { + // Read raw target before mutating memory. + rawTarget = targetBuffer.GetAsciiString() ?? string.Empty; + + // URI was encoded, unescape and then parse as utf8 + var pathSpan = pathBuffer.ToSpan(); + int pathLength = UrlEncoder.Decode(pathSpan, pathSpan); + requestUrlPath = new Utf8String(pathSpan.Slice(0, pathLength)).ToString(); + } + else + { + // URI wasn't encoded, parse as ASCII + requestUrlPath = pathBuffer.GetAsciiString() ?? string.Empty; + + if (queryString.Length == 0) + { + // No need to allocate an extra string if the path didn't need + // decoding and there's no query string following it. + rawTarget = requestUrlPath; + } + else + { + rawTarget = targetBuffer.GetAsciiString() ?? string.Empty; + } + } + + var normalizedTarget = PathNormalizer.RemoveDotSegments(requestUrlPath); + + consumed = end; + examined = end; + Method = method; + QueryString = queryString; + RawTarget = rawTarget; + HttpVersion = httpVersion; + + bool caseMatches; + if (RequestUrlStartsWithPathBase(normalizedTarget, out caseMatches)) + { + PathBase = caseMatches ? _pathBase : normalizedTarget.Substring(0, _pathBase.Length); + Path = normalizedTarget.Substring(_pathBase.Length); + } + else if (rawTarget[0] == '/') // check rawTarget since normalizedTarget can be "" or "/" after dot segment removal + { + Path = normalizedTarget; + } + else + { + Path = string.Empty; + PathBase = string.Empty; + QueryString = string.Empty; + } + + return true; + } + + private void RejectRequestLine(ReadCursor start, ReadCursor end) + { + const int MaxRequestLineError = 32; + RejectRequest(RequestRejectionReason.InvalidRequestLine, + Log.IsEnabled(LogLevel.Information) ? start.GetAsciiStringEscaped(end, MaxRequestLineError) : string.Empty); } private static bool IsValidTokenChar(char c) @@ -1255,34 +1241,35 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http return true; } - public bool TakeMessageHeaders(SocketInput input, FrameRequestHeaders requestHeaders) + public bool TakeMessageHeaders(ReadableBuffer buffer, FrameRequestHeaders requestHeaders, out ReadCursor consumed, out ReadCursor examined) { - var scan = input.ConsumingStart(); - var consumed = scan; - var end = scan; - try + consumed = buffer.Start; + examined = buffer.End; + + while (true) { - while (!end.IsEnd) + var headersEnd = buffer.Slice(0, Math.Min(buffer.Length, 2)); + var headersEndSpan = headersEnd.ToSpan(); + + if (headersEndSpan.Length == 0) { - var ch = end.Peek(); - if (ch == -1) - { - return false; - } - else if (ch == ByteCR) + return false; + } + else + { + var ch = headersEndSpan[0]; + if (ch == ByteCR) { // Check for final CRLF. - end.Take(); - ch = end.Take(); - - if (ch == -1) + if (headersEndSpan.Length < 2) { return false; } - else if (ch == ByteLF) + else if (headersEndSpan[1] == ByteLF) { + consumed = headersEnd.End; + examined = consumed; ConnectionControl.CancelTimeout(); - consumed = end; return true; } @@ -1293,129 +1280,113 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { RejectRequest(RequestRejectionReason.HeaderLineMustNotStartWithWhitespace); } + } - // If we've parsed the max allowed numbers of headers and we're starting a new - // one, we've gone over the limit. - if (_requestHeadersParsed == ServerOptions.Limits.MaxRequestHeaderCount) + // If we've parsed the max allowed numbers of headers and we're starting a new + // one, we've gone over the limit. + if (_requestHeadersParsed == ServerOptions.Limits.MaxRequestHeaderCount) + { + RejectRequest(RequestRejectionReason.TooManyHeaders); + } + + ReadCursor lineEnd; + var limitedBuffer = buffer; + if (buffer.Length >= _remainingRequestHeadersBytesAllowed) + { + limitedBuffer = buffer.Slice(0, _remainingRequestHeadersBytesAllowed); + } + if (ReadCursorOperations.Seek(limitedBuffer.Start, limitedBuffer.End, out lineEnd, ByteLF) == -1) + { + if (limitedBuffer.Length == _remainingRequestHeadersBytesAllowed) { - RejectRequest(RequestRejectionReason.TooManyHeaders); + RejectRequest(RequestRejectionReason.HeadersExceedMaxTotalSize); } - - int bytesScanned; - if (end.Seek(ByteLF, out bytesScanned, _remainingRequestHeadersBytesAllowed) == -1) - { - if (bytesScanned >= _remainingRequestHeadersBytesAllowed) - { - RejectRequest(RequestRejectionReason.HeadersExceedMaxTotalSize); - } - else - { - return false; - } - } - - var beginName = scan; - if (scan.Seek(ByteColon, ref end) == -1) - { - RejectRequest(RequestRejectionReason.NoColonCharacterFoundInHeaderLine); - } - var endName = scan; - - scan.Take(); - - var validateName = beginName; - if (validateName.Seek(ByteSpace, ByteTab, ref endName) != -1) - { - RejectRequest(RequestRejectionReason.WhitespaceIsNotAllowedInHeaderName); - } - - var beginValue = scan; - ch = scan.Take(); - - while (ch == ByteSpace || ch == ByteTab) - { - beginValue = scan; - ch = scan.Take(); - } - - scan = beginValue; - if (scan.Seek(ByteCR, ref end) == -1) - { - RejectRequest(RequestRejectionReason.MissingCRInHeaderLine); - } - - scan.Take(); // we know this is '\r' - ch = scan.Take(); // expecting '\n' - end = scan; - - if (ch != ByteLF) - { - RejectRequest(RequestRejectionReason.HeaderValueMustNotContainCR); - } - - var next = scan.Peek(); - if (next == -1) + else { return false; } - else if (next == ByteSpace || next == ByteTab) - { - // From https://tools.ietf.org/html/rfc7230#section-3.2.4: - // - // Historically, HTTP header field values could be extended over - // multiple lines by preceding each extra line with at least one space - // or horizontal tab (obs-fold). This specification deprecates such - // line folding except within the message/http media type - // (Section 8.3.1). A sender MUST NOT generate a message that includes - // line folding (i.e., that has any field-value that contains a match to - // the obs-fold rule) unless the message is intended for packaging - // within the message/http media type. - // - // A server that receives an obs-fold in a request message that is not - // within a message/http container MUST either reject the message by - // sending a 400 (Bad Request), preferably with a representation - // explaining that obsolete line folding is unacceptable, or replace - // each received obs-fold with one or more SP octets prior to - // interpreting the field value or forwarding the message downstream. - RejectRequest(RequestRejectionReason.HeaderValueLineFoldingNotSupported); - } - - // Trim trailing whitespace from header value by repeatedly advancing to next - // whitespace or CR. - // - // - If CR is found, this is the end of the header value. - // - If whitespace is found, this is the _tentative_ end of the header value. - // If non-whitespace is found after it and it's not CR, seek again to the next - // whitespace or CR for a new (possibly tentative) end of value. - var ws = beginValue; - var endValue = scan; - do - { - ws.Seek(ByteSpace, ByteTab, ByteCR); - endValue = ws; - - ch = ws.Take(); - while (ch == ByteSpace || ch == ByteTab) - { - ch = ws.Take(); - } - } while (ch != ByteCR); - - var name = beginName.GetArraySegment(endName); - var value = beginValue.GetAsciiString(ref endValue); - - consumed = scan; - requestHeaders.Append(name.Array, name.Offset, name.Count, value); - - _remainingRequestHeadersBytesAllowed -= bytesScanned; - _requestHeadersParsed++; } - return false; - } - finally - { - input.ConsumingComplete(consumed, end); + var beginName = buffer.Start; + ReadCursor endName; + if (ReadCursorOperations.Seek(buffer.Start, lineEnd, out endName, ByteColon) == -1) + { + RejectRequest(RequestRejectionReason.NoColonCharacterFoundInHeaderLine); + } + + ReadCursor whitespace; + if (ReadCursorOperations.Seek(beginName, endName, out whitespace, ByteTab, ByteSpace) != -1) + { + RejectRequest(RequestRejectionReason.WhitespaceIsNotAllowedInHeaderName); + } + + ReadCursor endValue; + if (ReadCursorOperations.Seek(beginName, lineEnd, out endValue, ByteCR) == -1) + { + RejectRequest(RequestRejectionReason.MissingCRInHeaderLine); + } + + var lineSufix = buffer.Slice(endValue); + if (lineSufix.Length < 3) + { + return false; + } + lineSufix = lineSufix.Slice(0, 3); // \r\n\r + var lineSufixSpan = lineSufix.ToSpan(); + // This check and MissingCRInHeaderLine is a bit backwards, we should do it at once instead of having another seek + if (lineSufixSpan[1] != ByteLF) + { + RejectRequest(RequestRejectionReason.HeaderValueMustNotContainCR); + } + + var next = lineSufixSpan[2]; + if (next == ByteSpace || next == ByteTab) + { + // From https://tools.ietf.org/html/rfc7230#section-3.2.4: + // + // Historically, HTTP header field values could be extended over + // multiple lines by preceding each extra line with at least one space + // or horizontal tab (obs-fold). This specification deprecates such + // line folding except within the message/http media type + // (Section 8.3.1). A sender MUST NOT generate a message that includes + // line folding (i.e., that has any field-value that contains a match to + // the obs-fold rule) unless the message is intended for packaging + // within the message/http media type. + // + // A server that receives an obs-fold in a request message that is not + // within a message/http container MUST either reject the message by + // sending a 400 (Bad Request), preferably with a representation + // explaining that obsolete line folding is unacceptable, or replace + // each received obs-fold with one or more SP octets prior to + // interpreting the field value or forwarding the message downstream. + RejectRequest(RequestRejectionReason.HeaderValueLineFoldingNotSupported); + } + + // Trim trailing whitespace from header value by repeatedly advancing to next + // whitespace or CR. + // + // - If CR is found, this is the end of the header value. + // - If whitespace is found, this is the _tentative_ end of the header value. + // If non-whitespace is found after it and it's not CR, seek again to the next + // whitespace or CR for a new (possibly tentative) end of value. + + var nameBuffer = buffer.Slice(beginName, endName); + + // TODO: TrimStart and TrimEnd are pretty slow + var valueBuffer = buffer.Slice(endName, endValue).Slice(1).TrimStart().TrimEnd(); + + var name = nameBuffer.ToArraySegment(); + var value = valueBuffer.GetAsciiString(); + + lineEnd = limitedBuffer.Move(lineEnd, 1); + + // TODO: bad + _remainingRequestHeadersBytesAllowed -= buffer.Slice(0, lineEnd).Length; + _requestHeadersParsed++; + + requestHeaders.Append(name.Array, name.Offset, name.Count, value); + buffer = buffer.Slice(lineEnd); + consumed = buffer.Start; } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameOfT.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameOfT.cs index f6d9128fa4..40fc9e2059 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameOfT.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameOfT.cs @@ -3,6 +3,7 @@ using System; using System.IO; +using System.IO.Pipelines; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Hosting.Server; @@ -31,66 +32,95 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http /// public override async Task RequestProcessingAsync() { - var requestLineStatus = RequestLineStatus.Empty; + var requestLineStatus = default(RequestLineStatus); try { while (!_requestProcessingStopping) { + // If writer completes with an error Input.ReadAsyncDispatched would throw and + // this would not be reset to empty. But it's required by ECONNRESET check lower in the method. + requestLineStatus = RequestLineStatus.Empty; + ConnectionControl.SetTimeout(_keepAliveMilliseconds, TimeoutAction.CloseConnection); while (!_requestProcessingStopping) { - requestLineStatus = TakeStartLine(Input); + var result = await Input.Reader.ReadAsync(); + var examined = result.Buffer.End; + var consumed = result.Buffer.End; + + try + { + if (!result.Buffer.IsEmpty) + { + requestLineStatus = TakeStartLine(result.Buffer, out consumed, out examined) + ? RequestLineStatus.Done : RequestLineStatus.Incomplete; + } + else + { + requestLineStatus = RequestLineStatus.Empty; + } + } + catch (InvalidOperationException) + { + throw BadHttpRequestException.GetException(RequestRejectionReason.InvalidRequestLine); + } + finally + { + Input.Reader.Advance(consumed, examined); + } if (requestLineStatus == RequestLineStatus.Done) { break; } - if (Input.CheckFinOrThrow()) + if (result.IsCompleted) { - // We need to attempt to consume start lines and headers even after - // SocketInput.RemoteIntakeFin is set to true to ensure we don't close a - // connection without giving the application a chance to respond to a request - // sent immediately before the a FIN from the client. - requestLineStatus = TakeStartLine(Input); - if (requestLineStatus == RequestLineStatus.Empty) { return; } - if (requestLineStatus != RequestLineStatus.Done) - { - RejectRequest(RequestRejectionReason.InvalidRequestLine, requestLineStatus.ToString()); - } - - break; + RejectRequest(RequestRejectionReason.InvalidRequestLine, requestLineStatus.ToString()); } - - await Input; } InitializeHeaders(); - while (!_requestProcessingStopping && !TakeMessageHeaders(Input, FrameRequestHeaders)) + while (!_requestProcessingStopping) { - if (Input.CheckFinOrThrow()) - { - // We need to attempt to consume start lines and headers even after - // SocketInput.RemoteIntakeFin is set to true to ensure we don't close a - // connection without giving the application a chance to respond to a request - // sent immediately before the a FIN from the client. - if (!TakeMessageHeaders(Input, FrameRequestHeaders)) - { - RejectRequest(RequestRejectionReason.MalformedRequestInvalidHeaders); - } + var result = await Input.Reader.ReadAsync(); + var examined = result.Buffer.End; + var consumed = result.Buffer.End; + + bool headersDone; + + try + { + headersDone = TakeMessageHeaders(result.Buffer, FrameRequestHeaders, out consumed, + out examined); + } + catch (InvalidOperationException) + { + throw BadHttpRequestException.GetException(RequestRejectionReason.MalformedRequestInvalidHeaders); + } + finally + { + Input.Reader.Advance(consumed, examined); + } + + if (headersDone) + { break; } - await Input; + if (result.IsCompleted) + { + RejectRequest(RequestRejectionReason.MalformedRequestInvalidHeaders); + } } if (!_requestProcessingStopping) @@ -216,6 +246,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { try { + Input.Reader.Complete(); // If _requestAborted is set, the connection has already been closed. if (Volatile.Read(ref _requestAborted) == 0) { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Listener.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Listener.cs index 3bb269f6c8..a8624d1764 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Listener.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Listener.cs @@ -36,7 +36,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http Thread.Post(state => { - var tcs2 = (TaskCompletionSource) state; + var tcs2 = state; try { var listener = ((Listener) tcs2.Task.AsyncState); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ListenerContext.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ListenerContext.cs index 083f1a2148..e5a7ae80e4 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ListenerContext.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ListenerContext.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.IO.Pipelines; using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http @@ -40,5 +41,21 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http throw new InvalidOperationException(); } } + + public PipeOptions LibuvPipeOptions => new PipeOptions + { + ReaderScheduler = TaskRunScheduler.Default, + WriterScheduler = Thread, + MaximumSizeHigh = ServiceContext.ServerOptions.Limits.MaxRequestBufferSize ?? 0, + MaximumSizeLow = ServiceContext.ServerOptions.Limits.MaxRequestBufferSize ?? 0 + }; + + public PipeOptions AdaptedPipeOptions => new PipeOptions + { + ReaderScheduler = InlineScheduler.Default, + WriterScheduler = InlineScheduler.Default, + MaximumSizeHigh = ServiceContext.ServerOptions.Limits.MaxRequestBufferSize ?? 0, + MaximumSizeLow = ServiceContext.ServerOptions.Limits.MaxRequestBufferSize ?? 0 + }; } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ListenerSecondary.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ListenerSecondary.cs index 9ce1478b24..41de1df45c 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ListenerSecondary.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ListenerSecondary.cs @@ -47,7 +47,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http DispatchPipe = new UvPipeHandle(Log); var tcs = new TaskCompletionSource(this); - Thread.Post(state => StartCallback((TaskCompletionSource)state), tcs); + Thread.Post(StartCallback, tcs); return tcs.Task; } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/MessageBody.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/MessageBody.cs index 99b10d1b47..ce0edff4b9 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/MessageBody.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/MessageBody.cs @@ -3,10 +3,10 @@ using System; using System.IO; +using System.IO.Pipelines; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.Extensions.Internal; namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http @@ -215,9 +215,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http private void ConsumedBytes(int count) { - var scan = _context.Input.ConsumingStart(); - scan.Skip(count); - _context.Input.ConsumingComplete(scan, scan); + var scan = _context.Input.Reader.ReadAsync().GetResult().Buffer; + var consumed = scan.Move(scan.Start, count); + _context.Input.Reader.Advance(consumed, consumed); OnConsumedBytes(count); } @@ -304,7 +304,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http protected override ValueTask> PeekAsync(CancellationToken cancellationToken) { - return _context.Input.PeekAsync(); + return _context.Input.Reader.PeekAsync(); } } @@ -351,7 +351,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http return new ValueTask>(); } - var task = _context.Input.PeekAsync(); + var task = _context.Input.Reader.PeekAsync(); if (task.IsCompleted) { @@ -413,7 +413,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http // byte consts don't have a data type annotation so we pre-cast it private const byte ByteCR = (byte)'\r'; - private readonly SocketInput _input; + private readonly IPipeReader _input; private readonly FrameRequestHeaders _requestHeaders; private int _inputLength; @@ -423,7 +423,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http : base(context) { RequestKeepAlive = keepAlive; - _input = _context.Input; + _input = _context.Input.Reader; _requestHeaders = headers; } @@ -443,45 +443,71 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { while (_mode == Mode.Prefix) { - var fin = _input.CheckFinOrThrow(); + var result = await _input.ReadAsync(); + var buffer = result.Buffer; + var consumed = default(ReadCursor); + var examined = default(ReadCursor); - ParseChunkedPrefix(); + try + { + ParseChunkedPrefix(buffer, out consumed, out examined); + } + finally + { + _input.Advance(consumed, examined); + } if (_mode != Mode.Prefix) { break; } - else if (fin) + else if (result.IsCompleted) { _context.RejectRequest(RequestRejectionReason.ChunkedRequestIncomplete); } - await _input; } while (_mode == Mode.Extension) { - var fin = _input.CheckFinOrThrow(); + var result = await _input.ReadAsync(); + var buffer = result.Buffer; + var consumed = default(ReadCursor); + var examined = default(ReadCursor); - ParseExtension(); + try + { + ParseExtension(buffer, out consumed, out examined); + } + finally + { + _input.Advance(consumed, examined); + } if (_mode != Mode.Extension) { break; } - else if (fin) + else if (result.IsCompleted) { _context.RejectRequest(RequestRejectionReason.ChunkedRequestIncomplete); } - await _input; } while (_mode == Mode.Data) { - var fin = _input.CheckFinOrThrow(); - - var segment = PeekChunkedData(); + var result = await _input.ReadAsync(); + var buffer = result.Buffer; + ArraySegment segment; + try + { + segment = PeekChunkedData(buffer); + } + finally + { + _input.Advance(buffer.Start, buffer.Start); + } if (segment.Count != 0) { @@ -491,195 +517,214 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { break; } - else if (fin) + else if (result.IsCompleted) { _context.RejectRequest(RequestRejectionReason.ChunkedRequestIncomplete); } - - await _input; } while (_mode == Mode.Suffix) { - var fin = _input.CheckFinOrThrow(); + var result = await _input.ReadAsync(); + var buffer = result.Buffer; + var consumed = default(ReadCursor); + var examined = default(ReadCursor); - ParseChunkedSuffix(); + try + { + ParseChunkedSuffix(buffer, out consumed, out examined); + } + finally + { + _input.Advance(consumed, examined); + } if (_mode != Mode.Suffix) { break; } - else if (fin) + else if (result.IsCompleted) { _context.RejectRequest(RequestRejectionReason.ChunkedRequestIncomplete); } - - await _input; } } // Chunks finished, parse trailers while (_mode == Mode.Trailer) { - var fin = _input.CheckFinOrThrow(); + var result = await _input.ReadAsync(); + var buffer = result.Buffer; + var consumed = default(ReadCursor); + var examined = default(ReadCursor); - ParseChunkedTrailer(); + try + { + ParseChunkedTrailer(buffer, out consumed, out examined); + } + finally + { + _input.Advance(consumed, examined); + } if (_mode != Mode.Trailer) { break; } - else if (fin) + else if (result.IsCompleted) { _context.RejectRequest(RequestRejectionReason.ChunkedRequestIncomplete); } - await _input; } if (_mode == Mode.TrailerHeaders) { - while (!_context.TakeMessageHeaders(_input, _requestHeaders)) + while (true) { - if (_input.CheckFinOrThrow()) + var result = await _input.ReadAsync(); + var buffer = result.Buffer; + + if (buffer.IsEmpty && result.IsCompleted) { - if (_context.TakeMessageHeaders(_input, _requestHeaders)) + _context.RejectRequest(RequestRejectionReason.ChunkedRequestIncomplete); + } + + var consumed = default(ReadCursor); + var examined = default(ReadCursor); + + try + { + if (_context.TakeMessageHeaders(buffer, _requestHeaders, out consumed, out examined)) { break; } - else - { - _context.RejectRequest(RequestRejectionReason.ChunkedRequestIncomplete); - } } - - await _input; + finally + { + _input.Advance(consumed, examined); + } } - _mode = Mode.Complete; } return default(ArraySegment); } - private void ParseChunkedPrefix() + private void ParseChunkedPrefix(ReadableBuffer buffer, out ReadCursor consumed, out ReadCursor examined) { - var scan = _input.ConsumingStart(); - var consumed = scan; - try + consumed = buffer.Start; + examined = buffer.Start; + var reader = new ReadableBufferReader(buffer); + var ch1 = reader.Take(); + var ch2 = reader.Take(); + + if (ch1 == -1 || ch2 == -1) { - var ch1 = scan.Take(); - var ch2 = scan.Take(); - if (ch1 == -1 || ch2 == -1) + examined = reader.Cursor; + return; + } + + var chunkSize = CalculateChunkSize(ch1, 0); + ch1 = ch2; + + do + { + if (ch1 == ';') { + consumed = reader.Cursor; + examined = reader.Cursor; + + _inputLength = chunkSize; + _mode = Mode.Extension; return; } - var chunkSize = CalculateChunkSize(ch1, 0); + ch2 = reader.Take(); + if (ch2 == -1) + { + examined = reader.Cursor; + return; + } + + if (ch1 == '\r' && ch2 == '\n') + { + consumed = reader.Cursor; + examined = reader.Cursor; + + _inputLength = chunkSize; + + if (chunkSize > 0) + { + _mode = Mode.Data; + } + else + { + _mode = Mode.Trailer; + } + + return; + } + + chunkSize = CalculateChunkSize(ch1, chunkSize); ch1 = ch2; - - do - { - if (ch1 == ';') - { - consumed = scan; - - _inputLength = chunkSize; - _mode = Mode.Extension; - return; - } - - ch2 = scan.Take(); - if (ch2 == -1) - { - return; - } - - if (ch1 == '\r' && ch2 == '\n') - { - consumed = scan; - _inputLength = chunkSize; - - if (chunkSize > 0) - { - _mode = Mode.Data; - } - else - { - _mode = Mode.Trailer; - } - - return; - } - - chunkSize = CalculateChunkSize(ch1, chunkSize); - ch1 = ch2; - } while (ch1 != -1); - } - finally - { - _input.ConsumingComplete(consumed, scan); - } + } while (ch1 != -1); } - private void ParseExtension() + private void ParseExtension(ReadableBuffer buffer, out ReadCursor consumed, out ReadCursor examined) { - var scan = _input.ConsumingStart(); - var consumed = scan; - try + // Chunk-extensions not currently parsed + // Just drain the data + consumed = buffer.Start; + examined = buffer.Start; + do { - // Chunk-extensions not currently parsed - // Just drain the data - do + ReadCursor extensionCursor; + if (ReadCursorOperations.Seek(buffer.Start, buffer.End, out extensionCursor, ByteCR) == -1) { - if (scan.Seek(ByteCR) == -1) - { - // End marker not found yet - consumed = scan; - return; - }; + // End marker not found yet + examined = buffer.End; + return; + }; - var ch1 = scan.Take(); - var ch2 = scan.Take(); + var sufixBuffer = buffer.Slice(extensionCursor); + if (sufixBuffer.Length < 2) + { + examined = buffer.End; + return; + } - if (ch2 == '\n') + sufixBuffer = sufixBuffer.Slice(0, 2); + var sufixSpan = sufixBuffer.ToSpan(); + + + if (sufixSpan[1] == '\n') + { + consumed = sufixBuffer.End; + examined = sufixBuffer.End; + if (_inputLength > 0) { - consumed = scan; - if (_inputLength > 0) - { - _mode = Mode.Data; - } - else - { - _mode = Mode.Trailer; - } + _mode = Mode.Data; } - else if (ch2 == -1) + else { - return; + _mode = Mode.Trailer; } - } while (_mode == Mode.Extension); - } - finally - { - _input.ConsumingComplete(consumed, scan); - } + } + } while (_mode == Mode.Extension); } - private ArraySegment PeekChunkedData() + private ArraySegment PeekChunkedData(ReadableBuffer buffer) { if (_inputLength == 0) { _mode = Mode.Suffix; return default(ArraySegment); } + var segment = buffer.First.GetArray(); - var scan = _input.ConsumingStart(); - var segment = scan.PeekArraySegment(); int actual = Math.Min(segment.Count, _inputLength); // Nothing is consumed yet. ConsumedBytes(int) will move the iterator. - _input.ConsumingComplete(scan, scan); - if (actual == segment.Count) { return segment; @@ -690,60 +735,54 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } } - private void ParseChunkedSuffix() + private void ParseChunkedSuffix(ReadableBuffer buffer, out ReadCursor consumed, out ReadCursor examined) { - var scan = _input.ConsumingStart(); - var consumed = scan; - try + consumed = buffer.Start; + examined = buffer.Start; + + if (buffer.Length < 2) { - var ch1 = scan.Take(); - var ch2 = scan.Take(); - if (ch1 == -1 || ch2 == -1) - { - return; - } - else if (ch1 == '\r' && ch2 == '\n') - { - consumed = scan; - _mode = Mode.Prefix; - } - else - { - _context.RejectRequest(RequestRejectionReason.BadChunkSuffix); - } + examined = buffer.End; + return; } - finally + + var sufixBuffer = buffer.Slice(0, 2); + var sufixSpan = sufixBuffer.ToSpan(); + if (sufixSpan[0] == '\r' && sufixSpan[1] == '\n') { - _input.ConsumingComplete(consumed, scan); + consumed = sufixBuffer.End; + examined = sufixBuffer.End; + _mode = Mode.Prefix; + } + else + { + _context.RejectRequest(RequestRejectionReason.BadChunkSuffix); } } - private void ParseChunkedTrailer() + private void ParseChunkedTrailer(ReadableBuffer buffer, out ReadCursor consumed, out ReadCursor examined) { - var scan = _input.ConsumingStart(); - var consumed = scan; - try - { - var ch1 = scan.Take(); - var ch2 = scan.Take(); + consumed = buffer.Start; + examined = buffer.Start; - if (ch1 == -1 || ch2 == -1) - { - return; - } - else if (ch1 == '\r' && ch2 == '\n') - { - consumed = scan; - _mode = Mode.Complete; - } - else - { - _mode = Mode.TrailerHeaders; - } - } - finally + if (buffer.Length < 2) { - _input.ConsumingComplete(consumed, scan); + examined = buffer.End; + return; + } + + var trailerBuffer = buffer.Slice(0, 2); + var trailerSpan = trailerBuffer.ToSpan(); + + if (trailerSpan[0] == '\r' && trailerSpan[1] == '\n') + { + consumed = trailerBuffer.End; + examined = trailerBuffer.End; + _mode = Mode.Complete; + } + else + { + _mode = Mode.TrailerHeaders; } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/PipelineExtensions.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/PipelineExtensions.cs new file mode 100644 index 0000000000..4698eb51ab --- /dev/null +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/PipelineExtensions.cs @@ -0,0 +1,108 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.IO.Pipelines; +using System.Threading; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; + +namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http +{ + public static class PipelineExtensions + { + public static ValueTask> PeekAsync(this IPipeReader pipelineReader) + { + var input = pipelineReader.ReadAsync(); + while (input.IsCompleted) + { + var result = input.GetResult(); + try + { + if (!result.Buffer.IsEmpty) + { + var segment = result.Buffer.First; + var data = segment.GetArray(); + + return new ValueTask>(data); + } + else if (result.IsCompleted || result.IsCancelled) + { + return default(ValueTask>); + } + } + finally + { + pipelineReader.Advance(result.Buffer.Start, result.Buffer.Start); + } + input = pipelineReader.ReadAsync(); + } + + return new ValueTask>(pipelineReader.PeekAsyncAwaited(input)); + } + + private static async Task> PeekAsyncAwaited(this IPipeReader pipelineReader, ReadableBufferAwaitable readingTask) + { + while (true) + { + var result = await readingTask; + + await AwaitableThreadPool.Yield(); + + try + { + if (!result.Buffer.IsEmpty) + { + var segment = result.Buffer.First; + return segment.GetArray(); + } + else if (result.IsCompleted || result.IsCancelled) + { + return default(ArraySegment); + } + } + finally + { + pipelineReader.Advance(result.Buffer.Start, result.Buffer.Start); + } + + readingTask = pipelineReader.ReadAsync(); + } + } + + private static async Task ReadAsyncDispatchedAwaited(ReadableBufferAwaitable awaitable) + { + var result = await awaitable; + await AwaitableThreadPool.Yield(); + return result; + } + + public static Span ToSpan(this ReadableBuffer buffer) + { + if (buffer.IsSingleSpan) + { + return buffer.First.Span; + } + return buffer.ToArray(); + } + + public static ArraySegment ToArraySegment(this ReadableBuffer buffer) + { + if (buffer.IsSingleSpan) + { + return buffer.First.GetArray(); + } + return new ArraySegment(buffer.ToArray()); + } + + public static ArraySegment GetArray(this Memory memory) + { + ArraySegment result; + if (!memory.TryGetArray(out result)) + { + throw new InvalidOperationException("Memory backed by array was expected"); + } + return result; + } + } +} \ No newline at end of file diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/RequestRejectionReason.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/RequestRejectionReason.cs index caa6475d9a..042a25d99c 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/RequestRejectionReason.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/RequestRejectionReason.cs @@ -30,6 +30,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http RequestTimeout, FinalTransferCodingNotChunked, LengthRequired, - LengthRequiredHttp10, + LengthRequiredHttp10 } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/SocketInput.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/SocketInput.cs deleted file mode 100644 index a89fff7bff..0000000000 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/SocketInput.cs +++ /dev/null @@ -1,351 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using System.Diagnostics; -using System.Runtime.CompilerServices; -using System.Threading; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; - -namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http -{ - public class SocketInput : ICriticalNotifyCompletion, IDisposable - { - private static readonly Action _awaitableIsCompleted = () => { }; - private static readonly Action _awaitableIsNotCompleted = () => { }; - - private readonly MemoryPool _memory; - private readonly IThreadPool _threadPool; - private readonly IBufferSizeControl _bufferSizeControl; - private readonly ManualResetEventSlim _manualResetEvent = new ManualResetEventSlim(false, 0); - - private Action _awaitableState; - - private MemoryPoolBlock _head; - private MemoryPoolBlock _tail; - private MemoryPoolBlock _pinned; - - private object _sync = new object(); - - private bool _consuming; - private bool _disposed; - - private TaskCompletionSource _tcs = new TaskCompletionSource(); - - public SocketInput(MemoryPool memory, IThreadPool threadPool, IBufferSizeControl bufferSizeControl = null) - { - _memory = memory; - _threadPool = threadPool; - _bufferSizeControl = bufferSizeControl; - _awaitableState = _awaitableIsNotCompleted; - } - - public bool IsCompleted => ReferenceEquals(_awaitableState, _awaitableIsCompleted); - - private bool ReadingInput => _tcs.Task.Status == TaskStatus.WaitingForActivation; - - public bool CheckFinOrThrow() - { - CheckConnectionError(); - return _tcs.Task.Status == TaskStatus.RanToCompletion; - } - - public MemoryPoolBlock IncomingStart() - { - lock (_sync) - { - const int minimumSize = 2048; - - if (_tail != null && minimumSize <= _tail.Data.Offset + _tail.Data.Count - _tail.End) - { - _pinned = _tail; - } - else - { - _pinned = _memory.Lease(); - } - - return _pinned; - } - } - - public void IncomingComplete(int count, Exception error) - { - Action awaitableState; - - lock (_sync) - { - // Must call Add() before bytes are available to consumer, to ensure that Length is >= 0 - _bufferSizeControl?.Add(count); - - if (_pinned != null) - { - _pinned.End += count; - - if (_head == null) - { - _head = _tail = _pinned; - } - else if (_tail == _pinned) - { - // NO-OP: this was a read into unoccupied tail-space - } - else - { - Volatile.Write(ref _tail.Next, _pinned); - _tail = _pinned; - } - - _pinned = null; - } - - if (error != null) - { - SetConnectionError(error); - } - else if (count == 0) - { - FinReceived(); - } - - awaitableState = Interlocked.Exchange(ref _awaitableState, _awaitableIsCompleted); - } - - Complete(awaitableState); - } - - public void IncomingDeferred() - { - Debug.Assert(_pinned != null); - - lock (_sync) - { - if (_pinned != null) - { - if (_pinned != _tail) - { - _memory.Return(_pinned); - } - - _pinned = null; - } - } - } - - private void Complete(Action awaitableState) - { - _manualResetEvent.Set(); - - if (!ReferenceEquals(awaitableState, _awaitableIsCompleted) && - !ReferenceEquals(awaitableState, _awaitableIsNotCompleted)) - { - _threadPool.Run(awaitableState); - } - } - - public MemoryPoolIterator ConsumingStart() - { - MemoryPoolBlock head; - bool isAlreadyConsuming; - - lock (_sync) - { - isAlreadyConsuming = _consuming; - head = _head; - _consuming = true; - } - - if (isAlreadyConsuming) - { - throw new InvalidOperationException("Already consuming input."); - } - - return new MemoryPoolIterator(head); - } - - public void ConsumingComplete( - MemoryPoolIterator consumed, - MemoryPoolIterator examined) - { - bool isConsuming; - MemoryPoolBlock returnStart = null; - MemoryPoolBlock returnEnd = null; - - lock (_sync) - { - if (!_disposed) - { - if (!consumed.IsDefault) - { - // Compute lengthConsumed before modifying _head or consumed - var lengthConsumed = 0; - if (_bufferSizeControl != null) - { - lengthConsumed = new MemoryPoolIterator(_head).GetLength(consumed); - } - - returnStart = _head; - - var consumedAll = !consumed.IsDefault && consumed.IsEnd; - if (consumedAll && _pinned != _tail) - { - // Everything has been consumed and no data is being written to the - // _tail block, so return all blocks between _head and _tail inclusive. - _head = null; - _tail = null; - } - else - { - returnEnd = consumed.Block; - _head = consumed.Block; - _head.Start = consumed.Index; - } - - // Must call Subtract() after _head has been advanced, to avoid producer starting too early and growing - // buffer beyond max length. - _bufferSizeControl?.Subtract(lengthConsumed); - } - - // If _head is null, everything has been consumed and examined. - var examinedAll = (!examined.IsDefault && examined.IsEnd) || _head == null; - if (examinedAll && ReadingInput) - { - _manualResetEvent.Reset(); - - Interlocked.CompareExchange( - ref _awaitableState, - _awaitableIsNotCompleted, - _awaitableIsCompleted); - } - } - else - { - // Dispose won't have returned the blocks if we were consuming, so return them now - returnStart = _head; - _head = null; - _tail = null; - } - - isConsuming = _consuming; - _consuming = false; - } - - ReturnBlocks(returnStart, returnEnd); - - if (!isConsuming) - { - throw new InvalidOperationException("No ongoing consuming operation to complete."); - } - } - - public void CompleteAwaiting() - { - Complete(Interlocked.Exchange(ref _awaitableState, _awaitableIsCompleted)); - } - - public void AbortAwaiting() - { - SetConnectionError(new TaskCanceledException("The request was aborted")); - - CompleteAwaiting(); - } - - public SocketInput GetAwaiter() - { - return this; - } - - public void OnCompleted(Action continuation) - { - var awaitableState = Interlocked.CompareExchange( - ref _awaitableState, - continuation, - _awaitableIsNotCompleted); - - if (ReferenceEquals(awaitableState, _awaitableIsCompleted)) - { - _threadPool.Run(continuation); - } - else if (!ReferenceEquals(awaitableState, _awaitableIsNotCompleted)) - { - SetConnectionError(new InvalidOperationException("Concurrent reads are not supported.")); - - Interlocked.Exchange( - ref _awaitableState, - _awaitableIsCompleted); - - _manualResetEvent.Set(); - - _threadPool.Run(continuation); - _threadPool.Run(awaitableState); - } - } - - public void UnsafeOnCompleted(Action continuation) - { - OnCompleted(continuation); - } - - public void GetResult() - { - if (!IsCompleted) - { - _manualResetEvent.Wait(); - } - - CheckConnectionError(); - } - - public void Dispose() - { - AbortAwaiting(); - - MemoryPoolBlock block = null; - - lock (_sync) - { - if (!_consuming) - { - block = _head; - _head = null; - _tail = null; - } - - _disposed = true; - } - - ReturnBlocks(block, null); - } - - private static void ReturnBlocks(MemoryPoolBlock block, MemoryPoolBlock end) - { - while (block != end) - { - var returnBlock = block; - block = block.Next; - - returnBlock.Pool.Return(returnBlock); - } - } - - private void SetConnectionError(Exception error) - { - _tcs.TrySetException(error); - } - - private void FinReceived() - { - _tcs.TrySetResult(null); - } - - private void CheckConnectionError() - { - var error = _tcs.Task.Exception?.InnerException; - if (error != null) - { - throw error; - } - } - } -} diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/SocketInputExtensions.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/SocketInputExtensions.cs deleted file mode 100644 index 8dd26803ab..0000000000 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/SocketInputExtensions.cs +++ /dev/null @@ -1,90 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; - -namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http -{ - public static class SocketInputExtensions - { - public static ValueTask ReadAsync(this SocketInput input, byte[] buffer, int offset, int count) - { - while (input.IsCompleted) - { - var fin = input.CheckFinOrThrow(); - - var begin = input.ConsumingStart(); - int actual; - var end = begin.CopyTo(buffer, offset, count, out actual); - input.ConsumingComplete(end, end); - - if (actual != 0 || fin) - { - return new ValueTask(actual); - } - } - - return new ValueTask(input.ReadAsyncAwaited(buffer, offset, count)); - } - - private static async Task ReadAsyncAwaited(this SocketInput input, byte[] buffer, int offset, int count) - { - while (true) - { - await input; - - var fin = input.CheckFinOrThrow(); - - var begin = input.ConsumingStart(); - int actual; - var end = begin.CopyTo(buffer, offset, count, out actual); - input.ConsumingComplete(end, end); - - if (actual != 0 || fin) - { - return actual; - } - } - } - - public static ValueTask> PeekAsync(this SocketInput input) - { - while (input.IsCompleted) - { - var fin = input.CheckFinOrThrow(); - - var begin = input.ConsumingStart(); - var segment = begin.PeekArraySegment(); - input.ConsumingComplete(begin, begin); - - if (segment.Count != 0 || fin) - { - return new ValueTask>(segment); - } - } - - return new ValueTask>(input.PeekAsyncAwaited()); - } - - private static async Task> PeekAsyncAwaited(this SocketInput input) - { - while (true) - { - await input; - - var fin = input.CheckFinOrThrow(); - - var begin = input.ConsumingStart(); - var segment = begin.PeekArraySegment(); - input.ConsumingComplete(begin, begin); - - if (segment.Count != 0 || fin) - { - return segment; - } - } - } - } -} diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/SocketOutput.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/SocketOutput.cs index c06bd4b236..52a3d5b1c5 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/SocketOutput.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/SocketOutput.cs @@ -327,7 +327,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http private void ScheduleWrite() { - _thread.Post(state => ((SocketOutput)state).WriteAllPending(), this); + _thread.Post(state => state.WriteAllPending(), this); } // This is called on the libuv event loop diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/AwaitableThreadPool.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/AwaitableThreadPool.cs new file mode 100644 index 0000000000..70930c73ae --- /dev/null +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/AwaitableThreadPool.cs @@ -0,0 +1,39 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Runtime.CompilerServices; +using System.Threading.Tasks; + +namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure +{ + internal static class AwaitableThreadPool + { + internal static Awaitable Yield() + { + return new Awaitable(); + } + + internal struct Awaitable : ICriticalNotifyCompletion + { + public void GetResult() + { + + } + + public Awaitable GetAwaiter() => this; + + public bool IsCompleted => false; + + public void OnCompleted(Action continuation) + { + Task.Run(continuation); + } + + public void UnsafeOnCompleted(Action continuation) + { + OnCompleted(continuation); + } + } + } +} \ No newline at end of file diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/KestrelThread.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/KestrelThread.cs index 383f804cfa..ea40ccf322 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/KestrelThread.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/KestrelThread.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; +using System.IO.Pipelines; using System.Runtime.ExceptionServices; using System.Runtime.InteropServices; using System.Threading; @@ -12,18 +13,17 @@ using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; using Microsoft.Extensions.Logging; +using MemoryPool = Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPool; namespace Microsoft.AspNetCore.Server.Kestrel.Internal { /// /// Summary description for KestrelThread /// - public class KestrelThread + public class KestrelThread: IScheduler { public const long HeartbeatMilliseconds = 1000; - private static readonly Action _postCallbackAdapter = (callback, state) => ((Action)callback).Invoke(state); - private static readonly Action _postAsyncCallbackAdapter = (callback, state) => ((Action)callback).Invoke(state); private static readonly Libuv.uv_walk_cb _heartbeatWalkCallback = (ptr, arg) => { var streamHandle = UvMemory.FromIntPtr(ptr) as UvStreamHandle; @@ -78,10 +78,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal QueueCloseHandle = PostCloseHandle; QueueCloseAsyncHandle = EnqueueCloseHandle; Memory = new MemoryPool(); + PipelineFactory = new PipeFactory(); WriteReqPool = new WriteReqPool(this, _log); ConnectionManager = new ConnectionManager(this, _threadPool); } - // For testing internal KestrelThread(KestrelEngine engine, int maxLoops) : this(engine) @@ -93,6 +93,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal public MemoryPool Memory { get; } + public PipeFactory PipelineFactory { get; } + public ConnectionManager ConnectionManager { get; } public WriteReqPool WriteReqPool { get; } @@ -180,7 +182,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal var result = await WaitAsync(PostAsync(state => { - var listener = (KestrelThread)state; + var listener = state; listener.WriteReqPool.Dispose(); }, this), _shutdownTimeout).ConfigureAwait(false); @@ -193,6 +195,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal finally { Memory.Dispose(); + PipelineFactory.Dispose(); } } @@ -224,13 +227,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal _loop.Stop(); } - public void Post(Action callback, object state) + public void Post(Action callback, T state) { lock (_workSync) { _workAdding.Enqueue(new Work { - CallbackAdapter = _postCallbackAdapter, + CallbackAdapter = CallbackAdapter.PostCallbackAdapter, Callback = callback, State = state }); @@ -240,17 +243,17 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal private void Post(Action callback) { - Post(thread => callback((KestrelThread)thread), this); + Post(callback, this); } - public Task PostAsync(Action callback, object state) + public Task PostAsync(Action callback, T state) { var tcs = new TaskCompletionSource(); lock (_workSync) { _workAdding.Enqueue(new Work { - CallbackAdapter = _postAsyncCallbackAdapter, + CallbackAdapter = CallbackAdapter.PostAsyncCallbackAdapter, Callback = callback, State = state, Completion = tcs @@ -439,6 +442,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal return await Task.WhenAny(task, Task.Delay(timeout)).ConfigureAwait(false) == task; } + public void Schedule(Action action) + { + Post(state => state(), action); + } + private struct Work { public Action CallbackAdapter; @@ -452,5 +460,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal public Action Callback; public IntPtr Handle; } + + private class CallbackAdapter + { + public static readonly Action PostCallbackAdapter = (callback, state) => ((Action)callback).Invoke((T)state); + public static readonly Action PostAsyncCallbackAdapter = (callback, state) => ((Action)callback).Invoke((T)state); + } + } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolIteratorExtensions.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolIteratorExtensions.cs index 1839d3309f..94cf66ef7b 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolIteratorExtensions.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolIteratorExtensions.cs @@ -3,6 +3,7 @@ using System; using System.Diagnostics; +using System.IO.Pipelines; using System.Runtime.CompilerServices; using System.Text; using Microsoft.AspNetCore.Http; @@ -69,19 +70,19 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure } } - public static string GetAsciiStringEscaped(this MemoryPoolIterator start, MemoryPoolIterator end, int maxChars) + public static string GetAsciiStringEscaped(this ReadCursor start, ReadCursor end, int maxChars) { var sb = new StringBuilder(); - var scan = start; + var reader = new ReadableBufferReader(start, end); - while (maxChars > 0 && (scan.Block != end.Block || scan.Index != end.Index)) + while (maxChars > 0 && !reader.End) { - var ch = scan.Take(); - sb.Append(ch < 0x20 || ch >= 0x7F ? $"<0x{ch.ToString("X2")}>" : ((char)ch).ToString()); + var ch = reader.Take(); + sb.Append(ch < 0x20 || ch >= 0x7F ? $"<0x{ch:X2}>" : ((char)ch).ToString()); maxChars--; } - if (scan.Block != end.Block || scan.Index != end.Index) + if (!reader.End) { sb.Append("..."); } @@ -130,16 +131,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure /// A reference to a pre-allocated known string, if the input matches any. /// true if the input matches a known string, false otherwise. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static bool GetKnownMethod(this MemoryPoolIterator begin, out string knownMethod) + public static bool GetKnownMethod(this ReadableBuffer begin, out string knownMethod) { knownMethod = null; - - ulong value; - if (!begin.TryPeekLong(out value)) + if (begin.Length < sizeof(ulong)) { return false; } + ulong value = begin.ReadLittleEndian(); if ((value & _mask4Chars) == _httpGetMethodLong) { knownMethod = HttpMethods.Get; @@ -171,16 +171,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure /// A reference to a pre-allocated known string, if the input matches any. /// true if the input matches a known string, false otherwise. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static bool GetKnownVersion(this MemoryPoolIterator begin, out string knownVersion) + public static bool GetKnownVersion(this ReadableBuffer begin, out string knownVersion) { knownVersion = null; - ulong value; - if (!begin.TryPeekLong(out value)) + if (begin.Length < sizeof(ulong)) { return false; } + var value = begin.ReadLittleEndian(); if (value == _http11VersionLong) { knownVersion = Http11Version; @@ -192,9 +192,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure if (knownVersion != null) { - begin.Skip(knownVersion.Length); - - if (begin.Peek() != '\r') + if (begin.Slice(sizeof(ulong)).Peek() != '\r') { knownVersion = null; } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Microsoft.AspNetCore.Server.Kestrel.csproj b/src/Microsoft.AspNetCore.Server.Kestrel/Microsoft.AspNetCore.Server.Kestrel.csproj index 02214cbaf6..c62c37e231 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Microsoft.AspNetCore.Server.Kestrel.csproj +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Microsoft.AspNetCore.Server.Kestrel.csproj @@ -18,6 +18,10 @@ + + + + diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/MaxRequestBufferSizeTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/MaxRequestBufferSizeTests.cs index 2acd8f7f8d..cfbb6cc2ce 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/MaxRequestBufferSizeTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/MaxRequestBufferSizeTests.cs @@ -70,7 +70,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } [Theory] - [MemberData("LargeUploadData")] + [MemberData(nameof(LargeUploadData))] public async Task LargeUpload(long? maxRequestBufferSize, bool ssl, bool expectPause) { // Parameters diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests.csproj b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests.csproj index ac06d2b346..af33bd65b7 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests.csproj +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests.csproj @@ -3,7 +3,7 @@ - netcoreapp1.1;net452 + netcoreapp1.1 netcoreapp1.1 win7-x64 diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/PathBaseTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/PathBaseTests.cs index 0e6045f101..8c0edb6e22 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/PathBaseTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/PathBaseTests.cs @@ -1,6 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; using System.Net.Http; using System.Threading.Tasks; using Microsoft.AspNetCore.Builder; @@ -87,7 +88,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests using (var client = new HttpClient()) { - var response = await client.GetAsync($"http://localhost:{host.GetPort()}{requestPath}"); + var response = await client.GetAsync($"http://127.0.0.1:{host.GetPort()}{requestPath}"); response.EnsureSuccessStatusCode(); var responseText = await response.Content.ReadAsStringAsync(); diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs index bc1362023b..77ae582bfa 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs @@ -60,7 +60,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { for (var i = 0; i < received; i++) { - Assert.Equal((byte)((total + i) % 256), receivedBytes[i]); + // Do not use Assert.Equal here, it is to slow for this hot path + Assert.True((byte)((total + i) % 256) == receivedBytes[i], "Data received is incorrect"); } } @@ -143,7 +144,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests client.DefaultRequestHeaders.Connection.Clear(); client.DefaultRequestHeaders.Connection.Add("close"); - var response = await client.GetAsync($"http://localhost:{host.GetPort()}/"); + var response = await client.GetAsync($"http://127.0.0.1:{host.GetPort()}/"); response.EnsureSuccessStatusCode(); } } diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs index edf5d39703..e027de1e57 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs @@ -57,7 +57,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests using (var client = new HttpClient()) { - var response = await client.GetAsync($"http://localhost:{host.GetPort()}/"); + var response = await client.GetAsync($"http://127.0.0.1:{host.GetPort()}/"); response.EnsureSuccessStatusCode(); var responseBody = await response.Content.ReadAsStreamAsync(); @@ -100,7 +100,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests using (var client = new HttpClient()) { - var response = await client.GetAsync($"http://localhost:{host.GetPort()}/"); + var response = await client.GetAsync($"http://127.0.0.1:{host.GetPort()}/"); response.EnsureSuccessStatusCode(); var headers = response.Headers; @@ -145,7 +145,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests using (var client = new HttpClient()) { - var response = await client.GetAsync($"http://localhost:{host.GetPort()}/"); + var response = await client.GetAsync($"http://127.0.0.1:{host.GetPort()}/"); Assert.Equal(HttpStatusCode.InternalServerError, response.StatusCode); Assert.False(onStartingCalled); @@ -178,7 +178,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests using (var client = new HttpClient()) { - var response = await client.GetAsync($"http://localhost:{host.GetPort()}/"); + var response = await client.GetAsync($"http://127.0.0.1:{host.GetPort()}/"); // Despite the error, the response had already started Assert.Equal(HttpStatusCode.OK, response.StatusCode); diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ThreadCountTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ThreadCountTests.cs index e4a723a9d1..cfd2e133af 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ThreadCountTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ThreadCountTests.cs @@ -43,7 +43,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests var requestTasks = new List>(); for (int i = 0; i < 20; i++) { - var requestTask = client.GetStringAsync($"http://localhost:{host.GetPort()}/"); + var requestTask = client.GetStringAsync($"http://127.0.0.1:{host.GetPort()}/"); requestTasks.Add(requestTask); } diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Microsoft.AspNetCore.Server.Kestrel.Performance.csproj b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Microsoft.AspNetCore.Server.Kestrel.Performance.csproj index bae45dfafb..4e4fabb7a6 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Microsoft.AspNetCore.Server.Kestrel.Performance.csproj +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Microsoft.AspNetCore.Server.Kestrel.Performance.csproj @@ -15,7 +15,6 @@ - diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/PipeThroughput.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/PipeThroughput.cs new file mode 100644 index 0000000000..dc99101261 --- /dev/null +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/PipeThroughput.cs @@ -0,0 +1,68 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.IO.Pipelines; +using System.Text; +using System.Threading.Tasks; +using BenchmarkDotNet.Attributes; + +namespace Microsoft.AspNetCore.Server.Kestrel.Performance +{ + [Config(typeof(CoreConfig))] + public class PipeThroughput + { + private const int _writeLenght = 57; + private const int InnerLoopCount = 512; + + private IPipe _pipe; + private PipeFactory _pipelineFactory; + + [Setup] + public void Setup() + { + _pipelineFactory = new PipeFactory(); + _pipe = _pipelineFactory.Create(); + } + + [Benchmark(OperationsPerInvoke = InnerLoopCount)] + public void ParseLiveAspNetTwoTasks() + { + var writing = Task.Run(async () => + { + for (int i = 0; i < InnerLoopCount; i++) + { + var writableBuffer = _pipe.Writer.Alloc(_writeLenght); + writableBuffer.Advance(_writeLenght); + await writableBuffer.FlushAsync(); + } + }); + + var reading = Task.Run(async () => + { + int remaining = InnerLoopCount * _writeLenght; + while (remaining != 0) + { + var result = await _pipe.Reader.ReadAsync(); + remaining -= result.Buffer.Length; + _pipe.Reader.Advance(result.Buffer.End, result.Buffer.End); + } + }); + + Task.WaitAll(writing, reading); + } + + [Benchmark(OperationsPerInvoke = InnerLoopCount)] + public void ParseLiveAspNetInline() + { + for (int i = 0; i < InnerLoopCount; i++) + { + var writableBuffer = _pipe.Writer.Alloc(_writeLenght); + writableBuffer.Advance(_writeLenght); + writableBuffer.FlushAsync().GetAwaiter().GetResult(); + var result = _pipe.Reader.ReadAsync().GetAwaiter().GetResult(); + _pipe.Reader.Advance(result.Buffer.End, result.Buffer.End); + } + } + } +} diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Program.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Program.cs index 3e2d92774b..d687d6bea2 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Program.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Program.cs @@ -36,6 +36,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance { BenchmarkRunner.Run(); } + if (type.HasFlag(BenchmarkType.Throughput)) + { + BenchmarkRunner.Run(); + } } } @@ -44,6 +48,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance { RequestParsing = 1, Writing = 2, + Throughput = 4, // add new ones in powers of two - e.g. 2,4,8,16... All = uint.MaxValue diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsing.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsing.cs index facb7bcef5..e42f109178 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsing.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsing.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.IO.Pipelines; using System.Linq; using System.Text; using BenchmarkDotNet.Attributes; @@ -9,6 +10,7 @@ using Microsoft.AspNetCore.Server.Kestrel.Internal; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.AspNetCore.Testing; +using MemoryPool = Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPool; using RequestLineStatus = Microsoft.AspNetCore.Server.Kestrel.Internal.Http.Frame.RequestLineStatus; namespace Microsoft.AspNetCore.Server.Kestrel.Performance @@ -21,14 +23,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance private const string plaintextRequest = "GET /plaintext HTTP/1.1\r\nHost: www.example.com\r\n\r\n"; - private const string liveaspnetRequest = "GET https://live.asp.net/ HTTP/1.1\r\n" + - "Host: live.asp.net\r\n" + - "Connection: keep-alive\r\n" + - "Upgrade-Insecure-Requests: 1\r\n" + - "User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.99 Safari/537.36\r\n" + - "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8\r\n" + - "DNT: 1\r\n" + - "Accept-Encoding: gzip, deflate, sdch, br\r\n" + + private const string liveaspnetRequest = "GET https://live.asp.net/ HTTP/1.1\r\n" + + "Host: live.asp.net\r\n" + + "Connection: keep-alive\r\n" + + "Upgrade-Insecure-Requests: 1\r\n" + + "User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.99 Safari/537.36\r\n" + + "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8\r\n" + + "DNT: 1\r\n" + + "Accept-Encoding: gzip, deflate, sdch, br\r\n" + "Accept-Language: en-US,en;q=0.8\r\n" + "Cookie: __unam=7a67379-1s65dc575c4-6d778abe-1; omniID=9519gfde_3347_4762_8762_df51458c8ec2\r\n\r\n"; @@ -48,7 +50,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance "Cookie: prov=20629ccd-8b0f-e8ef-2935-cd26609fc0bc; __qca=P0-1591065732-1479167353442; _ga=GA1.2.1298898376.1479167354; _gat=1; sgt=id=9519gfde_3347_4762_8762_df51458c8ec2; acct=t=why-is-%e0%a5%a7%e0%a5%a8%e0%a5%a9-numeric&s=why-is-%e0%a5%a7%e0%a5%a8%e0%a5%a9-numeric\r\n\r\n"; private static readonly byte[] _plaintextPipelinedRequests = Encoding.ASCII.GetBytes(string.Concat(Enumerable.Repeat(plaintextRequest, Pipelining))); - private static readonly byte[] _plaintextRequest = Encoding.ASCII.GetBytes(plaintextRequest); + private static readonly byte[] _plaintextRequest = Encoding.ASCII.GetBytes(plaintextRequest); private static readonly byte[] _liveaspnentPipelinedRequests = Encoding.ASCII.GetBytes(string.Concat(Enumerable.Repeat(liveaspnetRequest, Pipelining))); private static readonly byte[] _liveaspnentRequest = Encoding.ASCII.GetBytes(liveaspnetRequest); @@ -56,19 +58,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance private static readonly byte[] _unicodePipelinedRequests = Encoding.ASCII.GetBytes(string.Concat(Enumerable.Repeat(unicodeRequest, Pipelining))); private static readonly byte[] _unicodeRequest = Encoding.ASCII.GetBytes(unicodeRequest); - private KestrelTrace Trace; - private LoggingThreadPool ThreadPool; - private MemoryPool MemoryPool; - private SocketInput SocketInput; - private Frame Frame; - [Benchmark(Baseline = true, OperationsPerInvoke = InnerLoopCount)] public void ParsePlaintext() { for (var i = 0; i < InnerLoopCount; i++) { InsertData(_plaintextRequest); - ParseData(); } } @@ -79,7 +74,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance for (var i = 0; i < InnerLoopCount; i++) { InsertData(_plaintextPipelinedRequests); - ParseData(); } } @@ -90,7 +84,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance for (var i = 0; i < InnerLoopCount; i++) { InsertData(_liveaspnentRequest); - ParseData(); } } @@ -101,7 +94,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance for (var i = 0; i < InnerLoopCount; i++) { InsertData(_liveaspnentPipelinedRequests); - ParseData(); } } @@ -112,7 +104,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance for (var i = 0; i < InnerLoopCount; i++) { InsertData(_unicodeRequest); - ParseData(); } } @@ -123,34 +114,52 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance for (var i = 0; i < InnerLoopCount; i++) { InsertData(_unicodePipelinedRequests); - ParseData(); } } - private void InsertData(byte[] dataBytes) + private void InsertData(byte[] bytes) { - SocketInput.IncomingData(dataBytes, 0, dataBytes.Length); + // There should not be any backpressure and task completes immediately + Pipe.Writer.WriteAsync(bytes).GetAwaiter().GetResult(); } private void ParseData() { - while (SocketInput.GetAwaiter().IsCompleted) + do { + var awaitable = Pipe.Reader.ReadAsync(); + if (!awaitable.IsCompleted) + { + // No more data + return; + } + + var result = awaitable.GetAwaiter().GetResult(); + var readableBuffer = result.Buffer; + Frame.Reset(); - if (Frame.TakeStartLine(SocketInput) != RequestLineStatus.Done) + ReadCursor consumed; + ReadCursor examined; + if (!Frame.TakeStartLine(readableBuffer, out consumed, out examined)) { ThrowInvalidStartLine(); } + Pipe.Reader.Advance(consumed, examined); + + result = Pipe.Reader.ReadAsync().GetAwaiter().GetResult(); + readableBuffer = result.Buffer; Frame.InitializeHeaders(); - if (!Frame.TakeMessageHeaders(SocketInput, (FrameRequestHeaders) Frame.RequestHeaders)) + if (!Frame.TakeMessageHeaders(readableBuffer, (FrameRequestHeaders)Frame.RequestHeaders, out consumed, out examined)) { ThrowInvalidMessageHeaders(); } + Pipe.Reader.Advance(consumed, examined); } + while(true); } private void ThrowInvalidStartLine() @@ -166,23 +175,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance [Setup] public void Setup() { - Trace = new KestrelTrace(new TestKestrelTrace()); - ThreadPool = new LoggingThreadPool(Trace); - MemoryPool = new MemoryPool(); - SocketInput = new SocketInput(MemoryPool, ThreadPool); - var connectionContext = new MockConnection(new KestrelServerOptions()); - connectionContext.Input = SocketInput; - Frame = new Frame(application: null, context: connectionContext); + PipelineFactory = new PipeFactory(); + Pipe = PipelineFactory.Create(); } - [Cleanup] - public void Cleanup() - { - SocketInput.IncomingFin(); - SocketInput.Dispose(); - MemoryPool.Dispose(); - } + public IPipe Pipe { get; set; } + + public Frame Frame { get; set; } + + public PipeFactory PipelineFactory { get; set; } } } diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Writing.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Writing.cs index fdbc73d6c6..04c8e414f9 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Writing.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Writing.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.IO.Pipelines; using System.Net; using System.Threading; using System.Threading.Tasks; @@ -88,9 +89,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance private TestFrame MakeFrame() { - var ltp = new LoggingThreadPool(Mock.Of()); - var pool = new MemoryPool(); - var socketInput = new SocketInput(pool, ltp); + var socketInput = new PipeFactory().Create(); var serviceContext = new ServiceContext { diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionTests.cs index 518bb721e5..cbffa6aaff 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionTests.cs @@ -49,11 +49,15 @@ namespace Microsoft.AspNetCore.Server.KestrelTests Libuv.uv_buf_t ignored; mockLibuv.AllocCallback(socket.InternalGetHandle(), 2048, out ignored); mockLibuv.ReadCallback(socket.InternalGetHandle(), 0, ref ignored); - Assert.False(connection.Input.CheckFinOrThrow()); - }, null); + + var readAwaitable = connection.Input.Reader.ReadAsync(); + + var result = readAwaitable.GetResult(); + Assert.False(result.IsCompleted); + }, (object)null); connection.ConnectionControl.End(ProduceEndType.SocketDisconnect); } } } -} +} \ No newline at end of file diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs index abbed6dfaa..bf6fc9c78b 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs @@ -3,6 +3,7 @@ using System; using System.IO; +using System.IO.Pipelines; using System.Net; using System.Text; using System.Threading; @@ -13,7 +14,6 @@ using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Server.Kestrel; using Microsoft.AspNetCore.Server.Kestrel.Internal; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.AspNetCore.Testing; using Microsoft.Extensions.Internal; using Moq; @@ -23,11 +23,14 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { public class FrameTests : IDisposable { - private readonly SocketInput _socketInput; - private readonly MemoryPool _pool; + private readonly IPipe _socketInput; private readonly TestFrame _frame; private readonly ServiceContext _serviceContext; private readonly ConnectionContext _connectionContext; + private PipeFactory _pipelineFactory; + + ReadCursor consumed; + ReadCursor examined; private class TestFrame : Frame { @@ -45,9 +48,8 @@ namespace Microsoft.AspNetCore.Server.KestrelTests public FrameTests() { var trace = new KestrelTrace(new TestKestrelTrace()); - var ltp = new LoggingThreadPool(trace); - _pool = new MemoryPool(); - _socketInput = new SocketInput(_pool, ltp); + _pipelineFactory = new PipeFactory(); + _socketInput = _pipelineFactory.Create(); _serviceContext = new ServiceContext { @@ -73,27 +75,26 @@ namespace Microsoft.AspNetCore.Server.KestrelTests public void Dispose() { - _pool.Dispose(); - _socketInput.Dispose(); + _socketInput.Reader.Complete(); + _socketInput.Writer.Complete(); + _pipelineFactory.Dispose(); } [Fact] - public void CanReadHeaderValueWithoutLeadingWhitespace() + public async Task CanReadHeaderValueWithoutLeadingWhitespace() { _frame.InitializeHeaders(); - var headerArray = Encoding.ASCII.GetBytes("Header:value\r\n\r\n"); - _socketInput.IncomingData(headerArray, 0, headerArray.Length); + await _socketInput.Writer.WriteAsync(Encoding.ASCII.GetBytes("Header:value\r\n\r\n")); - var success = _frame.TakeMessageHeaders(_socketInput, (FrameRequestHeaders)_frame.RequestHeaders); + var readableBuffer = (await _socketInput.Reader.ReadAsync()).Buffer; + var success = _frame.TakeMessageHeaders(readableBuffer, (FrameRequestHeaders) _frame.RequestHeaders, out consumed, out examined); + _socketInput.Reader.Advance(consumed, examined); Assert.True(success); Assert.Equal(1, _frame.RequestHeaders.Count); Assert.Equal("value", _frame.RequestHeaders["Header"]); - - // Assert TakeMessageHeaders consumed all the input - var scan = _socketInput.ConsumingStart(); - Assert.True(scan.IsEnd); + Assert.Equal(readableBuffer.End, consumed); } [Theory] @@ -107,20 +108,18 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [InlineData("Header: \t\tvalue\r\n\r\n")] [InlineData("Header: \t\t value\r\n\r\n")] [InlineData("Header: \t \t value\r\n\r\n")] - public void LeadingWhitespaceIsNotIncludedInHeaderValue(string rawHeaders) + public async Task LeadingWhitespaceIsNotIncludedInHeaderValue(string rawHeaders) { - var headerArray = Encoding.ASCII.GetBytes(rawHeaders); - _socketInput.IncomingData(headerArray, 0, headerArray.Length); + await _socketInput.Writer.WriteAsync(Encoding.ASCII.GetBytes(rawHeaders)); - var success = _frame.TakeMessageHeaders(_socketInput, (FrameRequestHeaders)_frame.RequestHeaders); + var readableBuffer = (await _socketInput.Reader.ReadAsync()).Buffer; + var success = _frame.TakeMessageHeaders(readableBuffer, (FrameRequestHeaders)_frame.RequestHeaders, out consumed, out examined); + _socketInput.Reader.Advance(consumed, examined); Assert.True(success); Assert.Equal(1, _frame.RequestHeaders.Count); Assert.Equal("value", _frame.RequestHeaders["Header"]); - - // Assert TakeMessageHeaders consumed all the input - var scan = _socketInput.ConsumingStart(); - Assert.True(scan.IsEnd); + Assert.Equal(readableBuffer.End, consumed); } [Theory] @@ -133,20 +132,18 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [InlineData("Header: value \t\t\r\n\r\n")] [InlineData("Header: value \t\t \r\n\r\n")] [InlineData("Header: value \t \t \r\n\r\n")] - public void TrailingWhitespaceIsNotIncludedInHeaderValue(string rawHeaders) + public async Task TrailingWhitespaceIsNotIncludedInHeaderValue(string rawHeaders) { - var headerArray = Encoding.ASCII.GetBytes(rawHeaders); - _socketInput.IncomingData(headerArray, 0, headerArray.Length); + await _socketInput.Writer.WriteAsync(Encoding.ASCII.GetBytes(rawHeaders)); - var success = _frame.TakeMessageHeaders(_socketInput, (FrameRequestHeaders)_frame.RequestHeaders); + var readableBuffer = (await _socketInput.Reader.ReadAsync()).Buffer; + var success = _frame.TakeMessageHeaders(readableBuffer, (FrameRequestHeaders)_frame.RequestHeaders, out consumed, out examined); + _socketInput.Reader.Advance(consumed, examined); Assert.True(success); Assert.Equal(1, _frame.RequestHeaders.Count); Assert.Equal("value", _frame.RequestHeaders["Header"]); - - // Assert TakeMessageHeaders consumed all the input - var scan = _socketInput.ConsumingStart(); - Assert.True(scan.IsEnd); + Assert.Equal(readableBuffer.End, consumed); } [Theory] @@ -158,20 +155,18 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [InlineData("Header: one \ttwo \tthree\r\n\r\n", "one \ttwo \tthree")] [InlineData("Header: one\t two\t three\r\n\r\n", "one\t two\t three")] [InlineData("Header: one \ttwo\t three\r\n\r\n", "one \ttwo\t three")] - public void WhitespaceWithinHeaderValueIsPreserved(string rawHeaders, string expectedValue) + public async Task WhitespaceWithinHeaderValueIsPreserved(string rawHeaders, string expectedValue) { - var headerArray = Encoding.ASCII.GetBytes(rawHeaders); - _socketInput.IncomingData(headerArray, 0, headerArray.Length); + await _socketInput.Writer.WriteAsync(Encoding.ASCII.GetBytes(rawHeaders)); - var success = _frame.TakeMessageHeaders(_socketInput, (FrameRequestHeaders)_frame.RequestHeaders); + var readableBuffer = (await _socketInput.Reader.ReadAsync()).Buffer; + var success = _frame.TakeMessageHeaders(readableBuffer, (FrameRequestHeaders)_frame.RequestHeaders, out consumed, out examined); + _socketInput.Reader.Advance(consumed, examined); Assert.True(success); Assert.Equal(1, _frame.RequestHeaders.Count); Assert.Equal(expectedValue, _frame.RequestHeaders["Header"]); - - // Assert TakeMessageHeaders consumed all the input - var scan = _socketInput.ConsumingStart(); - Assert.True(scan.IsEnd); + Assert.Equal(readableBuffer.End, consumed); } [Theory] @@ -183,27 +178,32 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [InlineData("Header: line1\r\n\t\tline2\r\n\r\n")] [InlineData("Header: line1\r\n \t\t line2\r\n\r\n")] [InlineData("Header: line1\r\n \t \t line2\r\n\r\n")] - public void TakeMessageHeadersThrowsOnHeaderValueWithLineFolding(string rawHeaders) + public async Task TakeMessageHeadersThrowsOnHeaderValueWithLineFolding(string rawHeaders) { - var headerArray = Encoding.ASCII.GetBytes(rawHeaders); - _socketInput.IncomingData(headerArray, 0, headerArray.Length); + await _socketInput.Writer.WriteAsync(Encoding.ASCII.GetBytes(rawHeaders)); + var readableBuffer = (await _socketInput.Reader.ReadAsync()).Buffer; + _socketInput.Reader.Advance(consumed, examined); - var exception = Assert.Throws(() => _frame.TakeMessageHeaders(_socketInput, (FrameRequestHeaders)_frame.RequestHeaders)); + var exception = Assert.Throws(() => _frame.TakeMessageHeaders(readableBuffer, (FrameRequestHeaders)_frame.RequestHeaders, out consumed, out examined)); Assert.Equal("Header value line folding not supported.", exception.Message); Assert.Equal(StatusCodes.Status400BadRequest, exception.StatusCode); } [Fact] - public void TakeMessageHeadersThrowsOnHeaderValueWithLineFolding_CharacterNotAvailableOnFirstAttempt() + public async Task TakeMessageHeadersThrowsOnHeaderValueWithLineFolding_CharacterNotAvailableOnFirstAttempt() { - var headerArray = Encoding.ASCII.GetBytes("Header-1: value1\r\n"); - _socketInput.IncomingData(headerArray, 0, headerArray.Length); + await _socketInput.Writer.WriteAsync(Encoding.ASCII.GetBytes("Header-1: value1\r\n")); - Assert.False(_frame.TakeMessageHeaders(_socketInput, (FrameRequestHeaders)_frame.RequestHeaders)); + var readableBuffer = (await _socketInput.Reader.ReadAsync()).Buffer; + Assert.False(_frame.TakeMessageHeaders(readableBuffer, (FrameRequestHeaders)_frame.RequestHeaders, out consumed, out examined)); + _socketInput.Reader.Advance(consumed, examined); - _socketInput.IncomingData(Encoding.ASCII.GetBytes(" "), 0, 1); + await _socketInput.Writer.WriteAsync(Encoding.ASCII.GetBytes(" ")); + + readableBuffer = (await _socketInput.Reader.ReadAsync()).Buffer; + var exception = Assert.Throws(() => _frame.TakeMessageHeaders(readableBuffer, (FrameRequestHeaders)_frame.RequestHeaders, out consumed, out examined)); + _socketInput.Reader.Advance(consumed, examined); - var exception = Assert.Throws(() => _frame.TakeMessageHeaders(_socketInput, (FrameRequestHeaders)_frame.RequestHeaders)); Assert.Equal("Header value line folding not supported.", exception.Message); Assert.Equal(StatusCodes.Status400BadRequest, exception.StatusCode); } @@ -214,13 +214,14 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [InlineData("Header-1: value1\rHeader-2: value2\r\n\r\n")] [InlineData("Header-1: value1\r\nHeader-2: value2\r\r\n")] [InlineData("Header-1: value1\r\nHeader-2: v\ralue2\r\n")] - public void TakeMessageHeadersThrowsOnHeaderValueContainingCR(string rawHeaders) + public async Task TakeMessageHeadersThrowsOnHeaderValueContainingCR(string rawHeaders) { + await _socketInput.Writer.WriteAsync(Encoding.ASCII.GetBytes(rawHeaders)); + var readableBuffer = (await _socketInput.Reader.ReadAsync()).Buffer; - var headerArray = Encoding.ASCII.GetBytes(rawHeaders); - _socketInput.IncomingData(headerArray, 0, headerArray.Length); + var exception = Assert.Throws(() => _frame.TakeMessageHeaders(readableBuffer, (FrameRequestHeaders)_frame.RequestHeaders, out consumed, out examined)); + _socketInput.Reader.Advance(consumed, examined); - var exception = Assert.Throws(() => _frame.TakeMessageHeaders(_socketInput, (FrameRequestHeaders)_frame.RequestHeaders)); Assert.Equal("Header value must not contain CR characters.", exception.Message); Assert.Equal(StatusCodes.Status400BadRequest, exception.StatusCode); } @@ -229,12 +230,14 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [InlineData("Header-1 value1\r\n\r\n")] [InlineData("Header-1 value1\r\nHeader-2: value2\r\n\r\n")] [InlineData("Header-1: value1\r\nHeader-2 value2\r\n\r\n")] - public void TakeMessageHeadersThrowsOnHeaderLineMissingColon(string rawHeaders) + public async Task TakeMessageHeadersThrowsOnHeaderLineMissingColon(string rawHeaders) { - var headerArray = Encoding.ASCII.GetBytes(rawHeaders); - _socketInput.IncomingData(headerArray, 0, headerArray.Length); + await _socketInput.Writer.WriteAsync(Encoding.ASCII.GetBytes(rawHeaders)); + var readableBuffer = (await _socketInput.Reader.ReadAsync()).Buffer; + + var exception = Assert.Throws(() => _frame.TakeMessageHeaders(readableBuffer, (FrameRequestHeaders)_frame.RequestHeaders, out consumed, out examined)); + _socketInput.Reader.Advance(consumed, examined); - var exception = Assert.Throws(() => _frame.TakeMessageHeaders(_socketInput, (FrameRequestHeaders)_frame.RequestHeaders)); Assert.Equal("No ':' character found in header line.", exception.Message); Assert.Equal(StatusCodes.Status400BadRequest, exception.StatusCode); } @@ -244,12 +247,14 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [InlineData("\tHeader: value\r\n\r\n")] [InlineData(" Header-1: value1\r\nHeader-2: value2\r\n\r\n")] [InlineData("\tHeader-1: value1\r\nHeader-2: value2\r\n\r\n")] - public void TakeMessageHeadersThrowsOnHeaderLineStartingWithWhitespace(string rawHeaders) + public async Task TakeMessageHeadersThrowsOnHeaderLineStartingWithWhitespace(string rawHeaders) { - var headerArray = Encoding.ASCII.GetBytes(rawHeaders); - _socketInput.IncomingData(headerArray, 0, headerArray.Length); + await _socketInput.Writer.WriteAsync(Encoding.ASCII.GetBytes(rawHeaders)); + var readableBuffer = (await _socketInput.Reader.ReadAsync()).Buffer; + + var exception = Assert.Throws(() => _frame.TakeMessageHeaders(readableBuffer, (FrameRequestHeaders)_frame.RequestHeaders, out consumed, out examined)); + _socketInput.Reader.Advance(consumed, examined); - var exception = Assert.Throws(() => _frame.TakeMessageHeaders(_socketInput, (FrameRequestHeaders)_frame.RequestHeaders)); Assert.Equal("Header line must not start with whitespace.", exception.Message); Assert.Equal(StatusCodes.Status400BadRequest, exception.StatusCode); } @@ -263,12 +268,14 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [InlineData("Header-1: value1\r\nHeader 2: value2\r\n\r\n")] [InlineData("Header-1: value1\r\nHeader-2 : value2\r\n\r\n")] [InlineData("Header-1: value1\r\nHeader-2\t: value2\r\n\r\n")] - public void TakeMessageHeadersThrowsOnWhitespaceInHeaderName(string rawHeaders) + public async Task TakeMessageHeadersThrowsOnWhitespaceInHeaderName(string rawHeaders) { - var headerArray = Encoding.ASCII.GetBytes(rawHeaders); - _socketInput.IncomingData(headerArray, 0, headerArray.Length); + await _socketInput.Writer.WriteAsync(Encoding.ASCII.GetBytes(rawHeaders)); + var readableBuffer = (await _socketInput.Reader.ReadAsync()).Buffer; + + var exception = Assert.Throws(() => _frame.TakeMessageHeaders(readableBuffer, (FrameRequestHeaders)_frame.RequestHeaders, out consumed, out examined)); + _socketInput.Reader.Advance(consumed, examined); - var exception = Assert.Throws(() => _frame.TakeMessageHeaders(_socketInput, (FrameRequestHeaders)_frame.RequestHeaders)); Assert.Equal("Whitespace is not allowed in header name.", exception.Message); Assert.Equal(StatusCodes.Status400BadRequest, exception.StatusCode); } @@ -277,41 +284,47 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [InlineData("Header-1: value1\r\nHeader-2: value2\r\n\r\r")] [InlineData("Header-1: value1\r\nHeader-2: value2\r\n\r ")] [InlineData("Header-1: value1\r\nHeader-2: value2\r\n\r \n")] - public void TakeMessageHeadersThrowsOnHeadersNotEndingInCRLFLine(string rawHeaders) + public async Task TakeMessageHeadersThrowsOnHeadersNotEndingInCRLFLine(string rawHeaders) { - var headerArray = Encoding.ASCII.GetBytes(rawHeaders); - _socketInput.IncomingData(headerArray, 0, headerArray.Length); + await _socketInput.Writer.WriteAsync(Encoding.ASCII.GetBytes(rawHeaders)); + var readableBuffer = (await _socketInput.Reader.ReadAsync()).Buffer; + + var exception = Assert.Throws(() => _frame.TakeMessageHeaders(readableBuffer, (FrameRequestHeaders)_frame.RequestHeaders, out consumed, out examined)); + _socketInput.Reader.Advance(consumed, examined); - var exception = Assert.Throws(() => _frame.TakeMessageHeaders(_socketInput, (FrameRequestHeaders)_frame.RequestHeaders)); Assert.Equal("Headers corrupted, invalid header sequence.", exception.Message); Assert.Equal(StatusCodes.Status400BadRequest, exception.StatusCode); } [Fact] - public void TakeMessageHeadersThrowsWhenHeadersExceedTotalSizeLimit() + public async Task TakeMessageHeadersThrowsWhenHeadersExceedTotalSizeLimit() { const string headerLine = "Header: value\r\n"; _serviceContext.ServerOptions.Limits.MaxRequestHeadersTotalSize = headerLine.Length - 1; _frame.Reset(); - var headerArray = Encoding.ASCII.GetBytes($"{headerLine}\r\n"); - _socketInput.IncomingData(headerArray, 0, headerArray.Length); + await _socketInput.Writer.WriteAsync(Encoding.ASCII.GetBytes($"{headerLine}\r\n")); + var readableBuffer = (await _socketInput.Reader.ReadAsync()).Buffer; + + var exception = Assert.Throws(() => _frame.TakeMessageHeaders(readableBuffer, (FrameRequestHeaders)_frame.RequestHeaders, out consumed, out examined)); + _socketInput.Reader.Advance(consumed, examined); - var exception = Assert.Throws(() => _frame.TakeMessageHeaders(_socketInput, (FrameRequestHeaders)_frame.RequestHeaders)); Assert.Equal("Request headers too long.", exception.Message); Assert.Equal(StatusCodes.Status431RequestHeaderFieldsTooLarge, exception.StatusCode); } [Fact] - public void TakeMessageHeadersThrowsWhenHeadersExceedCountLimit() + public async Task TakeMessageHeadersThrowsWhenHeadersExceedCountLimit() { const string headerLines = "Header-1: value1\r\nHeader-2: value2\r\n"; _serviceContext.ServerOptions.Limits.MaxRequestHeaderCount = 1; - var headerArray = Encoding.ASCII.GetBytes($"{headerLines}\r\n"); - _socketInput.IncomingData(headerArray, 0, headerArray.Length); + await _socketInput.Writer.WriteAsync(Encoding.ASCII.GetBytes($"{headerLines}\r\n")); + var readableBuffer = (await _socketInput.Reader.ReadAsync()).Buffer; + + var exception = Assert.Throws(() => _frame.TakeMessageHeaders(readableBuffer, (FrameRequestHeaders)_frame.RequestHeaders, out consumed, out examined)); + _socketInput.Reader.Advance(consumed, examined); - var exception = Assert.Throws(() => _frame.TakeMessageHeaders(_socketInput, (FrameRequestHeaders)_frame.RequestHeaders)); Assert.Equal("Request contains too many headers.", exception.Message); Assert.Equal(StatusCodes.Status431RequestHeaderFieldsTooLarge, exception.StatusCode); } @@ -323,19 +336,17 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [InlineData("Cookie:\r\nConnection: close\r\n\r\n", 2)] [InlineData("Connection: close\r\nCookie: \r\n\r\n", 2)] [InlineData("Connection: close\r\nCookie:\r\n\r\n", 2)] - public void EmptyHeaderValuesCanBeParsed(string rawHeaders, int numHeaders) + public async Task EmptyHeaderValuesCanBeParsed(string rawHeaders, int numHeaders) { - var headerArray = Encoding.ASCII.GetBytes(rawHeaders); - _socketInput.IncomingData(headerArray, 0, headerArray.Length); + await _socketInput.Writer.WriteAsync(Encoding.ASCII.GetBytes(rawHeaders)); + var readableBuffer = (await _socketInput.Reader.ReadAsync()).Buffer; - var success = _frame.TakeMessageHeaders(_socketInput, (FrameRequestHeaders)_frame.RequestHeaders); + var success = _frame.TakeMessageHeaders(readableBuffer, (FrameRequestHeaders)_frame.RequestHeaders, out consumed, out examined); + _socketInput.Reader.Advance(consumed, examined); Assert.True(success); Assert.Equal(numHeaders, _frame.RequestHeaders.Count); - - // Assert TakeMessageHeaders consumed all the input - var scan = _socketInput.ConsumingStart(); - Assert.True(scan.IsEnd); + Assert.Equal(readableBuffer.End, consumed); } [Fact] @@ -351,7 +362,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } [Fact] - public void ResetResetsHeaderLimits() + public async Task ResetResetsHeaderLimits() { const string headerLine1 = "Header-1: value1\r\n"; const string headerLine2 = "Header-2: value2\r\n"; @@ -361,19 +372,25 @@ namespace Microsoft.AspNetCore.Server.KestrelTests options.Limits.MaxRequestHeaderCount = 1; _serviceContext.ServerOptions = options; - var headerArray1 = Encoding.ASCII.GetBytes($"{headerLine1}\r\n"); - _socketInput.IncomingData(headerArray1, 0, headerArray1.Length); + await _socketInput.Writer.WriteAsync(Encoding.ASCII.GetBytes($"{headerLine1}\r\n")); + var readableBuffer = (await _socketInput.Reader.ReadAsync()).Buffer; - Assert.True(_frame.TakeMessageHeaders(_socketInput, (FrameRequestHeaders)_frame.RequestHeaders)); + var takeMessageHeaders = _frame.TakeMessageHeaders(readableBuffer, (FrameRequestHeaders)_frame.RequestHeaders, out consumed, out examined); + _socketInput.Reader.Advance(consumed, examined); + + Assert.True(takeMessageHeaders); Assert.Equal(1, _frame.RequestHeaders.Count); Assert.Equal("value1", _frame.RequestHeaders["Header-1"]); _frame.Reset(); - var headerArray2 = Encoding.ASCII.GetBytes($"{headerLine2}\r\n"); - _socketInput.IncomingData(headerArray2, 0, headerArray1.Length); + await _socketInput.Writer.WriteAsync(Encoding.ASCII.GetBytes($"{headerLine2}\r\n")); + readableBuffer = (await _socketInput.Reader.ReadAsync()).Buffer; - Assert.True(_frame.TakeMessageHeaders(_socketInput, (FrameRequestHeaders)_frame.RequestHeaders)); + takeMessageHeaders = _frame.TakeMessageHeaders(readableBuffer, (FrameRequestHeaders)_frame.RequestHeaders, out consumed, out examined); + _socketInput.Reader.Advance(consumed, examined); + + Assert.True(takeMessageHeaders); Assert.Equal(1, _frame.RequestHeaders.Count); Assert.Equal("value2", _frame.RequestHeaders["Header-2"]); } @@ -462,78 +479,84 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } [Fact] - public void TakeStartLineCallsConsumingCompleteWithFurthestExamined() + public async Task TakeStartLineCallsConsumingCompleteWithFurthestExamined() { var requestLineBytes = Encoding.ASCII.GetBytes("GET / "); - _socketInput.IncomingData(requestLineBytes, 0, requestLineBytes.Length); - _frame.TakeStartLine(_socketInput); - Assert.False(_socketInput.IsCompleted); + await _socketInput.Writer.WriteAsync(requestLineBytes); + var readableBuffer = (await _socketInput.Reader.ReadAsync()).Buffer; + + _frame.TakeStartLine(readableBuffer, out consumed, out examined); + _socketInput.Reader.Advance(consumed, examined); + + Assert.Equal(readableBuffer.Start, consumed); + Assert.Equal(readableBuffer.End, examined); requestLineBytes = Encoding.ASCII.GetBytes("HTTP/1.1\r\n"); - _socketInput.IncomingData(requestLineBytes, 0, requestLineBytes.Length); - _frame.TakeStartLine(_socketInput); - Assert.False(_socketInput.IsCompleted); + await _socketInput.Writer.WriteAsync(requestLineBytes); + readableBuffer = (await _socketInput.Reader.ReadAsync()).Buffer; + + _frame.TakeStartLine(readableBuffer, out consumed, out examined); + _socketInput.Reader.Advance(consumed, examined); + + Assert.Equal(readableBuffer.End, consumed); + Assert.Equal(readableBuffer.End, examined); } [Theory] - [InlineData("", Frame.RequestLineStatus.Empty)] - [InlineData("G", Frame.RequestLineStatus.Incomplete)] - [InlineData("GE", Frame.RequestLineStatus.Incomplete)] - [InlineData("GET", Frame.RequestLineStatus.Incomplete)] - [InlineData("GET ", Frame.RequestLineStatus.Incomplete)] - [InlineData("GET /", Frame.RequestLineStatus.Incomplete)] - [InlineData("GET / ", Frame.RequestLineStatus.Incomplete)] - [InlineData("GET / H", Frame.RequestLineStatus.Incomplete)] - [InlineData("GET / HT", Frame.RequestLineStatus.Incomplete)] - [InlineData("GET / HTT", Frame.RequestLineStatus.Incomplete)] - [InlineData("GET / HTTP", Frame.RequestLineStatus.Incomplete)] - [InlineData("GET / HTTP/", Frame.RequestLineStatus.Incomplete)] - [InlineData("GET / HTTP/1", Frame.RequestLineStatus.Incomplete)] - [InlineData("GET / HTTP/1.", Frame.RequestLineStatus.Incomplete)] - [InlineData("GET / HTTP/1.1", Frame.RequestLineStatus.Incomplete)] - [InlineData("GET / HTTP/1.1\r", Frame.RequestLineStatus.Incomplete)] - public void TakeStartLineReturnsWhenGivenIncompleteRequestLines(string requestLine, Frame.RequestLineStatus expectedReturnValue) + [InlineData("G")] + [InlineData("GE")] + [InlineData("GET")] + [InlineData("GET ")] + [InlineData("GET /")] + [InlineData("GET / ")] + [InlineData("GET / H")] + [InlineData("GET / HT")] + [InlineData("GET / HTT")] + [InlineData("GET / HTTP")] + [InlineData("GET / HTTP/")] + [InlineData("GET / HTTP/1")] + [InlineData("GET / HTTP/1.")] + [InlineData("GET / HTTP/1.1")] + [InlineData("GET / HTTP/1.1\r")] + public async Task TakeStartLineReturnsWhenGivenIncompleteRequestLines(string requestLine) { var requestLineBytes = Encoding.ASCII.GetBytes(requestLine); - _socketInput.IncomingData(requestLineBytes, 0, requestLineBytes.Length); + await _socketInput.Writer.WriteAsync(requestLineBytes); - var returnValue = _frame.TakeStartLine(_socketInput); - Assert.Equal(expectedReturnValue, returnValue); + var readableBuffer = (await _socketInput.Reader.ReadAsync()).Buffer; + var returnValue = _frame.TakeStartLine(readableBuffer, out consumed, out examined); + _socketInput.Reader.Advance(consumed, examined); + + Assert.False(returnValue); } [Fact] - public void TakeStartLineStartsRequestHeadersTimeoutOnFirstByteAvailable() + public async Task TakeStartLineStartsRequestHeadersTimeoutOnFirstByteAvailable() { var connectionControl = new Mock(); _connectionContext.ConnectionControl = connectionControl.Object; - var requestLineBytes = Encoding.ASCII.GetBytes("G"); - _socketInput.IncomingData(requestLineBytes, 0, requestLineBytes.Length); + await _socketInput.Writer.WriteAsync(Encoding.ASCII.GetBytes("G")); + + _frame.TakeStartLine((await _socketInput.Reader.ReadAsync()).Buffer, out consumed, out examined); + _socketInput.Reader.Advance(consumed, examined); - _frame.TakeStartLine(_socketInput); var expectedRequestHeadersTimeout = (long)_serviceContext.ServerOptions.Limits.RequestHeadersTimeout.TotalMilliseconds; connectionControl.Verify(cc => cc.ResetTimeout(expectedRequestHeadersTimeout, TimeoutAction.SendTimeoutResponse)); } [Fact] - public void TakeStartLineDoesNotStartRequestHeadersTimeoutIfNoDataAvailable() - { - var connectionControl = new Mock(); - _connectionContext.ConnectionControl = connectionControl.Object; - - _frame.TakeStartLine(_socketInput); - connectionControl.Verify(cc => cc.ResetTimeout(It.IsAny(), It.IsAny()), Times.Never); - } - - [Fact] - public void TakeStartLineThrowsWhenTooLong() + public async Task TakeStartLineThrowsWhenTooLong() { _serviceContext.ServerOptions.Limits.MaxRequestLineSize = "GET / HTTP/1.1\r\n".Length; var requestLineBytes = Encoding.ASCII.GetBytes("GET /a HTTP/1.1\r\n"); - _socketInput.IncomingData(requestLineBytes, 0, requestLineBytes.Length); + await _socketInput.Writer.WriteAsync(requestLineBytes); + + var readableBuffer = (await _socketInput.Reader.ReadAsync()).Buffer; + var exception = Assert.Throws(() => _frame.TakeStartLine(readableBuffer, out consumed, out examined)); + _socketInput.Reader.Advance(consumed, examined); - var exception = Assert.Throws(() => _frame.TakeStartLine(_socketInput)); Assert.Equal("Request line too long.", exception.Message); Assert.Equal(StatusCodes.Status414UriTooLong, exception.StatusCode); } @@ -550,55 +573,60 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [InlineData("GET / HTTP/1.1\n", "Invalid request line: GET / HTTP/1.1<0x0A>")] [InlineData("GET / \r\n", "Invalid request line: GET / <0x0D><0x0A>")] [InlineData("GET / HTTP/1.1\ra\n", "Invalid request line: GET / HTTP/1.1<0x0D>a<0x0A>")] - public void TakeStartLineThrowsWhenInvalid(string requestLine, string expectedExceptionMessage) + public async Task TakeStartLineThrowsWhenInvalid(string requestLine, string expectedExceptionMessage) { - var requestLineBytes = Encoding.ASCII.GetBytes(requestLine); - _socketInput.IncomingData(requestLineBytes, 0, requestLineBytes.Length); + await _socketInput.Writer.WriteAsync(Encoding.ASCII.GetBytes(requestLine)); + + var readableBuffer = (await _socketInput.Reader.ReadAsync()).Buffer; + + var exception = Assert.Throws(() => _frame.TakeStartLine(readableBuffer, out consumed, out examined)); + _socketInput.Reader.Advance(consumed, examined); - var exception = Assert.Throws(() => _frame.TakeStartLine(_socketInput)); Assert.Equal(expectedExceptionMessage, exception.Message); Assert.Equal(StatusCodes.Status400BadRequest, exception.StatusCode); } [Fact] - public void TakeStartLineThrowsOnUnsupportedHttpVersion() + public async Task TakeStartLineThrowsOnUnsupportedHttpVersion() { - var requestLineBytes = Encoding.ASCII.GetBytes("GET / HTTP/1.2\r\n"); - _socketInput.IncomingData(requestLineBytes, 0, requestLineBytes.Length); + await _socketInput.Writer.WriteAsync(Encoding.ASCII.GetBytes("GET / HTTP/1.2\r\n")); + + var readableBuffer = (await _socketInput.Reader.ReadAsync()).Buffer; + + var exception = Assert.Throws(() => _frame.TakeStartLine(readableBuffer, out consumed, out examined)); + _socketInput.Reader.Advance(consumed, examined); - var exception = Assert.Throws(() => _frame.TakeStartLine(_socketInput)); Assert.Equal("Unrecognized HTTP version: HTTP/1.2", exception.Message); Assert.Equal(StatusCodes.Status505HttpVersionNotsupported, exception.StatusCode); } [Fact] - public void TakeStartLineThrowsOnUnsupportedHttpVersionLongerThanEightCharacters() + public async Task TakeStartLineThrowsOnUnsupportedHttpVersionLongerThanEightCharacters() { var requestLineBytes = Encoding.ASCII.GetBytes("GET / HTTP/1.1ab\r\n"); - _socketInput.IncomingData(requestLineBytes, 0, requestLineBytes.Length); + await _socketInput.Writer.WriteAsync(requestLineBytes); + + var readableBuffer = (await _socketInput.Reader.ReadAsync()).Buffer; + + var exception = Assert.Throws(() => _frame.TakeStartLine(readableBuffer, out consumed, out examined)); + _socketInput.Reader.Advance(consumed, examined); - var exception = Assert.Throws(() => _frame.TakeStartLine(_socketInput)); Assert.Equal("Unrecognized HTTP version: HTTP/1.1a...", exception.Message); Assert.Equal(StatusCodes.Status505HttpVersionNotsupported, exception.StatusCode); } [Fact] - public void TakeMessageHeadersCallsConsumingCompleteWithFurthestExamined() + public async Task TakeMessageHeadersCallsConsumingCompleteWithFurthestExamined() { - var headersBytes = Encoding.ASCII.GetBytes("Header: "); - _socketInput.IncomingData(headersBytes, 0, headersBytes.Length); - _frame.TakeMessageHeaders(_socketInput, (FrameRequestHeaders)_frame.RequestHeaders); - Assert.False(_socketInput.IsCompleted); + foreach (var rawHeader in new [] { "Header: " , "value\r\n" , "\r\n"}) + { + await _socketInput.Writer.WriteAsync(Encoding.ASCII.GetBytes(rawHeader)); - headersBytes = Encoding.ASCII.GetBytes("value\r\n"); - _socketInput.IncomingData(headersBytes, 0, headersBytes.Length); - _frame.TakeMessageHeaders(_socketInput, (FrameRequestHeaders)_frame.RequestHeaders); - Assert.False(_socketInput.IsCompleted); - - headersBytes = Encoding.ASCII.GetBytes("\r\n"); - _socketInput.IncomingData(headersBytes, 0, headersBytes.Length); - _frame.TakeMessageHeaders(_socketInput, (FrameRequestHeaders)_frame.RequestHeaders); - Assert.False(_socketInput.IsCompleted); + var readableBuffer = (await _socketInput.Reader.ReadAsync()).Buffer; + _frame.TakeMessageHeaders(readableBuffer, (FrameRequestHeaders)_frame.RequestHeaders, out consumed, out examined); + _socketInput.Reader.Advance(consumed, examined); + Assert.Equal(readableBuffer.End, examined); + } } [Theory] @@ -619,12 +647,17 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [InlineData("Header: value\r")] [InlineData("Header: value\r\n")] [InlineData("Header: value\r\n\r")] - public void TakeMessageHeadersReturnsWhenGivenIncompleteHeaders(string headers) + public async Task TakeMessageHeadersReturnsWhenGivenIncompleteHeaders(string headers) { var headerBytes = Encoding.ASCII.GetBytes(headers); - _socketInput.IncomingData(headerBytes, 0, headerBytes.Length); + await _socketInput.Writer.WriteAsync(headerBytes); - Assert.Equal(false, _frame.TakeMessageHeaders(_socketInput, (FrameRequestHeaders)_frame.RequestHeaders)); + ReadCursor consumed; + ReadCursor examined; + var readableBuffer = (await _socketInput.Reader.ReadAsync()).Buffer; + + Assert.Equal(false, _frame.TakeMessageHeaders(readableBuffer, (FrameRequestHeaders)_frame.RequestHeaders, out consumed, out examined)); + _socketInput.Reader.Advance(consumed, examined); } [Fact] @@ -639,7 +672,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests connectionControl.Verify(cc => cc.SetTimeout(expectedKeepAliveTimeout, TimeoutAction.CloseConnection)); _frame.StopAsync(); - _socketInput.IncomingFin(); + _socketInput.Writer.Complete(); requestProcessingTask.Wait(); } @@ -721,13 +754,13 @@ namespace Microsoft.AspNetCore.Server.KestrelTests _frame.Start(); var data = Encoding.ASCII.GetBytes("GET / HTTP/1.1\r\n\r\n"); - _socketInput.IncomingData(data, 0, data.Length); + await _socketInput.Writer.WriteAsync(data); var requestProcessingTask = _frame.StopAsync(); Assert.IsNotType(typeof(Task), requestProcessingTask); await requestProcessingTask.TimeoutAfter(TimeSpan.FromSeconds(10)); - _socketInput.IncomingFin(); + _socketInput.Writer.Complete(); } [Fact] diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/ListenerPrimaryTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/ListenerPrimaryTests.cs index 43e7b78e24..137eaee98a 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/ListenerPrimaryTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/ListenerPrimaryTests.cs @@ -182,7 +182,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } }, null); - }, null); + }, (object)null); await connectTcs.Task; @@ -191,7 +191,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests Assert.Equal("Primary", await HttpClientSlim.GetStringAsync(address)); Assert.Equal("Secondary", await HttpClientSlim.GetStringAsync(address)); - await kestrelThreadPrimary.PostAsync(_ => pipe.Dispose(), null); + await kestrelThreadPrimary.PostAsync(_ => pipe.Dispose(), (object)null); // Wait up to 10 seconds for error to be logged for (var i = 0; i < 10 && primaryTrace.Logger.TotalErrorsLogged == 0; i++) diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolIteratorTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolIteratorTests.cs index 1239cfa999..78b7e1fc36 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolIteratorTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolIteratorTests.cs @@ -3,11 +3,14 @@ using System; using System.Collections.Generic; +using System.IO.Pipelines; using System.Linq; using System.Numerics; using System.Text; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Xunit; +using MemoryPool = Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPool; +using MemoryPoolBlock = Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolBlock; namespace Microsoft.AspNetCore.Server.KestrelTests { @@ -68,7 +71,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests public void MemorySeek(string raw, string search, char expectResult, int expectIndex) { var block = _pool.Lease(); - var chars = raw.ToCharArray().Select(c => (byte) c).ToArray(); + var chars = raw.ToCharArray().Select(c => (byte)c).ToArray(); Buffer.BlockCopy(chars, 0, block.Array, block.Start, chars.Length); block.End += chars.Length; @@ -150,7 +153,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests head = blocks[0].GetIterator(); for (var i = 0; i < 64; ++i) { - Assert.True(head.Put((byte) i), $"Fail to put data at {i}."); + Assert.True(head.Put((byte)i), $"Fail to put data at {i}."); } // Can't put anything by the end @@ -167,7 +170,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { // Arrange var block = _pool.Lease(); - var bytes = new byte[] {0, 1, 2, 3, 4, 5, 6, 7}; + var bytes = new byte[] { 0, 1, 2, 3, 4, 5, 6, 7 }; Buffer.BlockCopy(bytes, 0, block.Array, block.Start, bytes.Length); block.End += bytes.Length; var scan = block.GetIterator(); @@ -177,7 +180,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var result = scan.PeekArraySegment(); // Assert - Assert.Equal(new byte[] {0, 1, 2, 3, 4, 5, 6, 7}, result); + Assert.Equal(new byte[] { 0, 1, 2, 3, 4, 5, 6, 7 }, result); Assert.Equal(originalIndex, scan.Index); _pool.Return(block); @@ -195,7 +198,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { // Arrange var block = _pool.Lease(); - var bytes = new byte[] {0, 1, 2, 3, 4, 5, 6, 7}; + var bytes = new byte[] { 0, 1, 2, 3, 4, 5, 6, 7 }; Buffer.BlockCopy(bytes, 0, block.Array, block.Start, bytes.Length); block.End += bytes.Length; block.Start = block.End; @@ -559,50 +562,63 @@ namespace Microsoft.AspNetCore.Server.KestrelTests public void GetsKnownMethod(string input, bool expectedResult, string expectedKnownString) { // Arrange - var block = _pool.Lease(); - var chars = input.ToCharArray().Select(c => (byte)c).ToArray(); - Buffer.BlockCopy(chars, 0, block.Array, block.Start, chars.Length); - block.End += chars.Length; - var begin = block.GetIterator(); - string knownString; + var block = ReadableBuffer.Create(Encoding.ASCII.GetBytes(input)); // Act - var result = begin.GetKnownMethod(out knownString); - + string knownString; + var result = block.GetKnownMethod(out knownString); // Assert Assert.Equal(expectedResult, result); Assert.Equal(expectedKnownString, knownString); + } + + [Theory] + [InlineData("CONNECT / HTTP/1.1", true, "CONNECT")] + [InlineData("DELETE / HTTP/1.1", true, "DELETE")] + [InlineData("GET / HTTP/1.1", true, "GET")] + [InlineData("HEAD / HTTP/1.1", true, "HEAD")] + [InlineData("PATCH / HTTP/1.1", true, "PATCH")] + [InlineData("POST / HTTP/1.1", true, "POST")] + [InlineData("PUT / HTTP/1.1", true, "PUT")] + [InlineData("OPTIONS / HTTP/1.1", true, "OPTIONS")] + [InlineData("TRACE / HTTP/1.1", true, "TRACE")] + [InlineData("GET/ HTTP/1.1", false, null)] + [InlineData("get / HTTP/1.1", false, null)] + [InlineData("GOT / HTTP/1.1", false, null)] + [InlineData("ABC / HTTP/1.1", false, null)] + [InlineData("PO / HTTP/1.1", false, null)] + [InlineData("PO ST / HTTP/1.1", false, null)] + [InlineData("short ", false, null)] + public void GetsKnownMethodOnBoundary(string input, bool expectedResult, string expectedKnownString) + { // Test at boundary var maxSplit = Math.Min(input.Length, 8); - var nextBlock = _pool.Lease(); for (var split = 0; split <= maxSplit; split++) { - // Arrange - block.Reset(); - nextBlock.Reset(); + using (var pipelineFactory = new PipeFactory()) + { + // Arrange + var pipe = pipelineFactory.Create(); + var buffer = pipe.Writer.Alloc(); + var block1Input = input.Substring(0, split); + var block2Input = input.Substring(split); + buffer.Append(ReadableBuffer.Create(Encoding.ASCII.GetBytes(block1Input))); + buffer.Append(ReadableBuffer.Create(Encoding.ASCII.GetBytes(block2Input))); + buffer.FlushAsync().GetAwaiter().GetResult(); - Buffer.BlockCopy(chars, 0, block.Array, block.Start, split); - Buffer.BlockCopy(chars, split, nextBlock.Array, nextBlock.Start, chars.Length - split); + var readResult = pipe.Reader.ReadAsync().GetAwaiter().GetResult(); - block.End += split; - nextBlock.End += chars.Length - split; - block.Next = nextBlock; + // Act + string boundaryKnownString; + var boundaryResult = readResult.Buffer.GetKnownMethod(out boundaryKnownString); - var boundaryBegin = block.GetIterator(); - string boundaryKnownString; - - // Act - var boundaryResult = boundaryBegin.GetKnownMethod(out boundaryKnownString); - - // Assert - Assert.Equal(expectedResult, boundaryResult); - Assert.Equal(expectedKnownString, boundaryKnownString); + // Assert + Assert.Equal(expectedResult, boundaryResult); + Assert.Equal(expectedKnownString, boundaryKnownString); + } } - - _pool.Return(block); - _pool.Return(nextBlock); } [Theory] @@ -615,49 +631,52 @@ namespace Microsoft.AspNetCore.Server.KestrelTests public void GetsKnownVersion(string input, bool expectedResult, string expectedKnownString) { // Arrange - var block = _pool.Lease(); - var chars = input.ToCharArray().Select(c => (byte)c).ToArray(); - Buffer.BlockCopy(chars, 0, block.Array, block.Start, chars.Length); - block.End += chars.Length; - var begin = block.GetIterator(); - string knownString; + var block = ReadableBuffer.Create(Encoding.ASCII.GetBytes(input)); // Act - var result = begin.GetKnownVersion(out knownString); + string knownString; + var result = block.GetKnownVersion(out knownString); // Assert Assert.Equal(expectedResult, result); Assert.Equal(expectedKnownString, knownString); + } + [Theory] + [InlineData("HTTP/1.0\r", true, MemoryPoolIteratorExtensions.Http10Version)] + [InlineData("HTTP/1.1\r", true, MemoryPoolIteratorExtensions.Http11Version)] + [InlineData("HTTP/3.0\r", false, null)] + [InlineData("http/1.0\r", false, null)] + [InlineData("http/1.1\r", false, null)] + [InlineData("short ", false, null)] + public void GetsKnownVersionOnBoundary(string input, bool expectedResult, string expectedKnownString) + { // Test at boundary var maxSplit = Math.Min(input.Length, 9); - var nextBlock = _pool.Lease(); for (var split = 0; split <= maxSplit; split++) { - // Arrange - block.Reset(); - nextBlock.Reset(); + using (var pipelineFactory = new PipeFactory()) + { + // Arrange + var pipe = pipelineFactory.Create(); + var buffer = pipe.Writer.Alloc(); + var block1Input = input.Substring(0, split); + var block2Input = input.Substring(split); + buffer.Append(ReadableBuffer.Create(Encoding.ASCII.GetBytes(block1Input))); + buffer.Append(ReadableBuffer.Create(Encoding.ASCII.GetBytes(block2Input))); + buffer.FlushAsync().GetAwaiter().GetResult(); - Buffer.BlockCopy(chars, 0, block.Array, block.Start, split); - Buffer.BlockCopy(chars, split, nextBlock.Array, nextBlock.Start, chars.Length - split); + var readResult = pipe.Reader.ReadAsync().GetAwaiter().GetResult(); - block.End += split; - nextBlock.End += chars.Length - split; - block.Next = nextBlock; + // Act + string boundaryKnownString; + var boundaryResult = readResult.Buffer.GetKnownVersion(out boundaryKnownString); - var boundaryBegin = block.GetIterator(); - string boundaryKnownString; - - // Act - var boundaryResult = boundaryBegin.GetKnownVersion(out boundaryKnownString); - - // Assert - Assert.Equal(expectedResult, boundaryResult); - Assert.Equal(expectedKnownString, boundaryKnownString); + // Assert + Assert.Equal(expectedResult, boundaryResult); + Assert.Equal(expectedKnownString, boundaryKnownString); + } } - - _pool.Return(block); - _pool.Return(nextBlock); } [Theory] @@ -681,37 +700,24 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [InlineData("HTTP/1.1\r", "")] public void KnownVersionCanBeReadAtAnyBlockBoundary(string block1Input, string block2Input) { - MemoryPoolBlock block1 = null; - MemoryPoolBlock block2 = null; - - try + using (var pipelineFactory = new PipeFactory()) { // Arrange - var chars1 = block1Input.ToCharArray().Select(c => (byte)c).ToArray(); - var chars2 = block2Input.ToCharArray().Select(c => (byte)c).ToArray(); - block1 = _pool.Lease(); - block2 = _pool.Lease(); - Buffer.BlockCopy(chars1, 0, block1.Array, block1.Start, chars1.Length); - Buffer.BlockCopy(chars2, 0, block2.Array, block2.Start, chars2.Length); - block1.End += chars1.Length; - block2.End += chars2.Length; - block1.Next = block2; - var iterator = block1.GetIterator(); + var pipe = pipelineFactory.Create(); + var buffer = pipe.Writer.Alloc(); + buffer.Append(ReadableBuffer.Create(Encoding.ASCII.GetBytes(block1Input))); + buffer.Append(ReadableBuffer.Create(Encoding.ASCII.GetBytes(block2Input))); + buffer.FlushAsync().GetAwaiter().GetResult(); + var readResult = pipe.Reader.ReadAsync().GetAwaiter().GetResult(); // Act string knownVersion; - var result = iterator.GetKnownVersion(out knownVersion); + var result = readResult.Buffer.GetKnownVersion(out knownVersion); // Assert Assert.True(result); Assert.Equal("HTTP/1.1", knownVersion); } - finally - { - // Cleanup - if (block1 != null) _pool.Return(block1); - if (block2 != null) _pool.Return(block2); - } } [Theory] @@ -740,7 +746,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests // Arrange block = _pool.Lease(); - var chars = input.ToString().ToCharArray().Select(c => (byte)c).ToArray(); + var chars = input.ToString().ToCharArray().Select(c => (byte) c).ToArray(); Buffer.BlockCopy(chars, 0, block.Array, block.Start, chars.Length); block.End += chars.Length; var scan = block.GetIterator(); @@ -974,7 +980,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [Fact] public void EmptyIteratorBehaviourIsValid() { - const byte byteCr = (byte) '\n'; + const byte byteCr = (byte)'\n'; ulong longValue; var end = default(MemoryPoolIterator); @@ -1194,16 +1200,10 @@ namespace Microsoft.AspNetCore.Server.KestrelTests try { // Arrange - block = _pool.Lease(); - var chars = input.ToCharArray().Select(c => (byte)c).ToArray(); - Buffer.BlockCopy(chars, 0, block.Array, block.Start, chars.Length); - block.End += chars.Length; - var start = block.GetIterator(); - var end = start; - end.Skip(input.Length); + var buffer = ReadableBuffer.Create(Encoding.ASCII.GetBytes(input)); // Act - var result = start.GetAsciiStringEscaped(end, maxChars); + var result = buffer.Start.GetAsciiStringEscaped(buffer.End, maxChars); // Assert Assert.Equal(expected, result); @@ -1294,28 +1294,14 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } } - private delegate bool GetKnownString(MemoryPoolIterator iter, out string result); + private delegate bool GetKnownString(ReadableBuffer iter, out string result); private void TestKnownStringsInterning(string input, string expected, GetKnownString action) { - // Arrange - var chars = input.ToCharArray().Select(c => (byte)c).ToArray(); - var block1 = _pool.Lease(); - var block2 = _pool.Lease(); - Buffer.BlockCopy(chars, 0, block1.Array, block1.Start, chars.Length); - Buffer.BlockCopy(chars, 0, block2.Array, block2.Start, chars.Length); - block1.End += chars.Length; - block2.End += chars.Length; - var begin1 = block1.GetIterator(); - var begin2 = block2.GetIterator(); - // Act string knownString1, knownString2; - var result1 = action(begin1, out knownString1); - var result2 = action(begin2, out knownString2); - - _pool.Return(block1); - _pool.Return(block2); + var result1 = action(ReadableBuffer.Create(Encoding.ASCII.GetBytes(input)), out knownString1); + var result2 = action(ReadableBuffer.Create(Encoding.ASCII.GetBytes(input)), out knownString2); // Assert Assert.True(result1); diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/MessageBodyTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/MessageBodyTests.cs index 3e11350d40..0cce86969b 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/MessageBodyTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/MessageBodyTests.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using System.IO; +using System.IO.Pipelines; using System.Linq; using System.Text; using System.Threading; @@ -282,24 +283,29 @@ namespace Microsoft.AspNetCore.Server.KestrelTests // so no need to bounds check in this test. var socketInput = input.FrameContext.Input; var bytes = Encoding.ASCII.GetBytes(data[0]); - var block = socketInput.IncomingStart(); - Buffer.BlockCopy(bytes, 0, block.Array, block.End, bytes.Length); - socketInput.IncomingComplete(bytes.Length, null); + var buffer = socketInput.Writer.Alloc(2048); + ArraySegment block; + Assert.True(buffer.Memory.TryGetArray(out block)); + Buffer.BlockCopy(bytes, 0, block.Array, block.Offset, bytes.Length); + buffer.Advance(bytes.Length); + await buffer.FlushAsync(); // Verify the block passed to WriteAsync is the same one incoming data was written into. Assert.Same(block.Array, await writeTcs.Task); writeTcs = new TaskCompletionSource(); bytes = Encoding.ASCII.GetBytes(data[1]); - block = socketInput.IncomingStart(); - Buffer.BlockCopy(bytes, 0, block.Array, block.End, bytes.Length); - socketInput.IncomingComplete(bytes.Length, null); + buffer = socketInput.Writer.Alloc(2048); + Assert.True(buffer.Memory.TryGetArray(out block)); + Buffer.BlockCopy(bytes, 0, block.Array, block.Offset, bytes.Length); + buffer.Advance(bytes.Length); + await buffer.FlushAsync(); Assert.Same(block.Array, await writeTcs.Task); if (headers.HeaderConnection == "close") { - socketInput.IncomingFin(); + socketInput.Writer.Complete(); } await copyToAsyncTask; diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/Microsoft.AspNetCore.Server.KestrelTests.csproj b/test/Microsoft.AspNetCore.Server.KestrelTests/Microsoft.AspNetCore.Server.KestrelTests.csproj index 322597f3a2..a2ceb96dee 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/Microsoft.AspNetCore.Server.KestrelTests.csproj +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/Microsoft.AspNetCore.Server.KestrelTests.csproj @@ -3,7 +3,7 @@ - netcoreapp1.1;net452 + netcoreapp1.1 netcoreapp1.1 true diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/SocketInputTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/SocketInputTests.cs deleted file mode 100644 index a751bbe342..0000000000 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/SocketInputTests.cs +++ /dev/null @@ -1,243 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Server.Kestrel.Internal; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; -using Microsoft.AspNetCore.Server.KestrelTests.TestHelpers; -using Microsoft.AspNetCore.Testing; -using Moq; -using Xunit; - -namespace Microsoft.AspNetCore.Server.KestrelTests -{ - public class SocketInputTests - { - public static readonly TheoryData> MockBufferSizeControlData = - new TheoryData>() { new Mock(), null }; - - [Theory] - [MemberData(nameof(MockBufferSizeControlData))] - public void IncomingDataCallsBufferSizeControlAdd(Mock mockBufferSizeControl) - { - using (var memory = new MemoryPool()) - using (var socketInput = new SocketInput(memory, null, mockBufferSizeControl?.Object)) - { - socketInput.IncomingData(new byte[5], 0, 5); - mockBufferSizeControl?.Verify(b => b.Add(5)); - } - } - - [Theory] - [MemberData(nameof(MockBufferSizeControlData))] - public void IncomingCompleteCallsBufferSizeControlAdd(Mock mockBufferSizeControl) - { - using (var memory = new MemoryPool()) - using (var socketInput = new SocketInput(memory, null, mockBufferSizeControl?.Object)) - { - socketInput.IncomingComplete(5, null); - mockBufferSizeControl?.Verify(b => b.Add(5)); - } - } - - [Theory] - [MemberData(nameof(MockBufferSizeControlData))] - public void ConsumingCompleteCallsBufferSizeControlSubtract(Mock mockBufferSizeControl) - { - using (var kestrelEngine = new KestrelEngine(new MockLibuv(), new TestServiceContext())) - { - kestrelEngine.Start(1); - - using (var memory = new MemoryPool()) - using (var socketInput = new SocketInput(memory, null, mockBufferSizeControl?.Object)) - { - socketInput.IncomingData(new byte[20], 0, 20); - - var iterator = socketInput.ConsumingStart(); - iterator.Skip(5); - socketInput.ConsumingComplete(iterator, iterator); - mockBufferSizeControl?.Verify(b => b.Subtract(5)); - } - } - } - - [Fact] - public async Task ConcurrentReadsFailGracefully() - { - // Arrange - var trace = new KestrelTrace(new TestKestrelTrace()); - var ltp = new LoggingThreadPool(trace); - using (var memory2 = new MemoryPool()) - using (var socketInput = new SocketInput(memory2, ltp)) - { - var task0Threw = false; - var task1Threw = false; - var task2Threw = false; - - var task0 = AwaitAsTaskAsync(socketInput); - - Assert.False(task0.IsFaulted); - - var task = task0.ContinueWith( - (t) => - { - TestConcurrentFaultedTask(t); - task0Threw = true; - }, - TaskContinuationOptions.OnlyOnFaulted); - - Assert.False(task0.IsFaulted); - - // Awaiting/continuing two tasks faults both - - var task1 = AwaitAsTaskAsync(socketInput); - - await task1.ContinueWith( - (t) => - { - TestConcurrentFaultedTask(t); - task1Threw = true; - }, - TaskContinuationOptions.OnlyOnFaulted); - - await task; - - Assert.True(task0.IsFaulted); - Assert.True(task1.IsFaulted); - - Assert.True(task0Threw); - Assert.True(task1Threw); - - // socket stays faulted - - var task2 = AwaitAsTaskAsync(socketInput); - - await task2.ContinueWith( - (t) => - { - TestConcurrentFaultedTask(t); - task2Threw = true; - }, - TaskContinuationOptions.OnlyOnFaulted); - - Assert.True(task2.IsFaulted); - Assert.True(task2Threw); - } - } - - [Fact] - public void ConsumingOutOfOrderFailsGracefully() - { - var defultIter = new MemoryPoolIterator(); - - // Calling ConsumingComplete without a preceding calling to ConsumingStart fails - using (var socketInput = new SocketInput(null, null)) - { - Assert.Throws(() => socketInput.ConsumingComplete(defultIter, defultIter)); - } - - // Calling ConsumingComplete twice in a row fails - using (var socketInput = new SocketInput(null, null)) - { - socketInput.ConsumingStart(); - socketInput.ConsumingComplete(defultIter, defultIter); - Assert.Throws(() => socketInput.ConsumingComplete(defultIter, defultIter)); - } - - // Calling ConsumingStart twice in a row fails - using (var socketInput = new SocketInput(null, null)) - { - socketInput.ConsumingStart(); - Assert.Throws(() => socketInput.ConsumingStart()); - } - } - - [Fact] - public async Task PeekAsyncRereturnsTheSameData() - { - using (var memory = new MemoryPool()) - using (var socketInput = new SocketInput(memory, new SynchronousThreadPool())) - { - socketInput.IncomingData(new byte[5], 0, 5); - - Assert.True(socketInput.IsCompleted); - Assert.Equal(5, (await socketInput.PeekAsync()).Count); - - // The same 5 bytes will be returned again since it hasn't been consumed. - Assert.True(socketInput.IsCompleted); - Assert.Equal(5, (await socketInput.PeekAsync()).Count); - - var scan = socketInput.ConsumingStart(); - scan.Skip(3); - socketInput.ConsumingComplete(scan, scan); - - // The remaining 2 unconsumed bytes will be returned. - Assert.True(socketInput.IsCompleted); - Assert.Equal(2, (await socketInput.PeekAsync()).Count); - - scan = socketInput.ConsumingStart(); - scan.Skip(2); - socketInput.ConsumingComplete(scan, scan); - - // Everything has been consume so socketInput is no longer in the completed state - Assert.False(socketInput.IsCompleted); - } - } - - [Fact] - public async Task CompleteAwaitingDoesNotCauseZeroLengthRead() - { - using (var memory = new MemoryPool()) - using (var socketInput = new SocketInput(memory, new SynchronousThreadPool())) - { - var readBuffer = new byte[20]; - - socketInput.IncomingData(new byte[5], 0, 5); - Assert.Equal(5, await socketInput.ReadAsync(readBuffer, 0, 20)); - - var readTask = socketInput.ReadAsync(readBuffer, 0, 20); - socketInput.CompleteAwaiting(); - Assert.False(readTask.IsCompleted); - - socketInput.IncomingData(new byte[5], 0, 5); - Assert.Equal(5, await readTask); - } - } - - [Fact] - public async Task CompleteAwaitingDoesNotCauseZeroLengthPeek() - { - using (var memory = new MemoryPool()) - using (var socketInput = new SocketInput(memory, new SynchronousThreadPool())) - { - socketInput.IncomingData(new byte[5], 0, 5); - Assert.Equal(5, (await socketInput.PeekAsync()).Count); - - var scan = socketInput.ConsumingStart(); - scan.Skip(5); - socketInput.ConsumingComplete(scan, scan); - - var peekTask = socketInput.PeekAsync(); - socketInput.CompleteAwaiting(); - Assert.False(peekTask.IsCompleted); - - socketInput.IncomingData(new byte[5], 0, 5); - Assert.Equal(5, (await socketInput.PeekAsync()).Count); - } - } - - private static void TestConcurrentFaultedTask(Task t) - { - Assert.True(t.IsFaulted); - Assert.IsType(typeof(System.InvalidOperationException), t.Exception.InnerException); - Assert.Equal(t.Exception.InnerException.Message, "Concurrent reads are not supported."); - } - - private async Task AwaitAsTaskAsync(SocketInput socketInput) - { - await socketInput; - } - } -} diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestInput.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/TestInput.cs index 5a798e804b..ff0d2d94c4 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/TestInput.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/TestInput.cs @@ -2,6 +2,8 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.IO.Pipelines; +using System.Text; using System.Net; using System.Threading; using System.Threading.Tasks; @@ -11,12 +13,14 @@ using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.AspNetCore.Testing; using Microsoft.Extensions.Internal; +using MemoryPool = Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPool; namespace Microsoft.AspNetCore.Server.KestrelTests { class TestInput : IConnectionControl, IFrameControl, IDisposable { private MemoryPool _memoryPool; + private PipeFactory _pipelineFactory; public TestInput() { @@ -41,18 +45,19 @@ namespace Microsoft.AspNetCore.Server.KestrelTests FrameContext.ConnectionContext.ListenerContext.ServiceContext.Log = trace; _memoryPool = new MemoryPool(); - FrameContext.Input = new SocketInput(_memoryPool, ltp); + _pipelineFactory = new PipeFactory(); + FrameContext.Input = _pipelineFactory.Create();; } public Frame FrameContext { get; set; } public void Add(string text, bool fin = false) { - var data = System.Text.Encoding.ASCII.GetBytes(text); - FrameContext.Input.IncomingData(data, 0, data.Length); + var data = Encoding.ASCII.GetBytes(text); + FrameContext.Input.Writer.WriteAsync(data).Wait(); if (fin) { - FrameContext.Input.IncomingFin(); + FrameContext.Input.Writer.Complete(); } } @@ -116,7 +121,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests public void Dispose() { - FrameContext.Input.Dispose(); + _pipelineFactory.Dispose(); _memoryPool.Dispose(); } } diff --git a/test/shared/SocketInputExtensions.cs b/test/shared/SocketInputExtensions.cs deleted file mode 100644 index d6dbbb7e88..0000000000 --- a/test/shared/SocketInputExtensions.cs +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; - -namespace Microsoft.AspNetCore.Testing -{ - public static class SocketInputExtensions - { - public static void IncomingData(this SocketInput input, byte[] buffer, int offset, int count) - { - var bufferIndex = offset; - var remaining = count; - - while (remaining > 0) - { - var block = input.IncomingStart(); - - var bytesLeftInBlock = block.Data.Offset + block.Data.Count - block.End; - var bytesToCopy = remaining < bytesLeftInBlock ? remaining : bytesLeftInBlock; - - Buffer.BlockCopy(buffer, bufferIndex, block.Array, block.End, bytesToCopy); - - bufferIndex += bytesToCopy; - remaining -= bytesToCopy; - - input.IncomingComplete(bytesToCopy, null); - } - } - - public static void IncomingFin(this SocketInput input) - { - input.IncomingComplete(0, null); - } - } -} From ef60779d3165cd4af51465e3f4992f62b45bf746 Mon Sep 17 00:00:00 2001 From: The Gitter Badger Date: Sat, 18 Feb 2017 16:16:02 -0600 Subject: [PATCH 1045/1662] Add Gitter badge (#1371) --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index a693db070f..e26fd19c0e 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,8 @@ KestrelHttpServer ================= +[![Join the chat at https://gitter.im/aspnet/KestrelHttpServer](https://badges.gitter.im/aspnet/KestrelHttpServer.svg)](https://gitter.im/aspnet/KestrelHttpServer?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) + AppVeyor: [![AppVeyor](https://ci.appveyor.com/api/projects/status/nr0s92ykm57q0bjv/branch/dev?svg=true)](https://ci.appveyor.com/project/aspnetci/KestrelHttpServer/branch/dev) Travis: [![Travis](https://travis-ci.org/aspnet/KestrelHttpServer.svg?branch=dev)](https://travis-ci.org/aspnet/KestrelHttpServer) From d3a691573226d7651e82def25d1b39e364c1b288 Mon Sep 17 00:00:00 2001 From: Pranav K Date: Mon, 20 Feb 2017 10:24:41 -0800 Subject: [PATCH 1046/1662] Remove dotnet-core and dotnet-corefxlab feeds Let VS do it's thing with test projects --- NuGet.config | 2 -- ...Microsoft.AspNetCore.Server.Kestrel.FunctionalTests.csproj | 4 ++++ .../Microsoft.AspNetCore.Server.KestrelTests.csproj | 4 ++++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/NuGet.config b/NuGet.config index ce00c056c6..69bab2da9a 100644 --- a/NuGet.config +++ b/NuGet.config @@ -4,8 +4,6 @@ - - diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests.csproj b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests.csproj index af33bd65b7..41df7b3e09 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests.csproj +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests.csproj @@ -38,6 +38,10 @@ + + + + diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/Microsoft.AspNetCore.Server.KestrelTests.csproj b/test/Microsoft.AspNetCore.Server.KestrelTests/Microsoft.AspNetCore.Server.KestrelTests.csproj index a2ceb96dee..f0a9a37c51 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/Microsoft.AspNetCore.Server.KestrelTests.csproj +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/Microsoft.AspNetCore.Server.KestrelTests.csproj @@ -32,4 +32,8 @@ + + + + \ No newline at end of file From 4fd71e3a6b00699d7be3298fb45a7262048c733e Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Tue, 21 Feb 2017 11:08:40 -0800 Subject: [PATCH 1047/1662] Fix 'No data found for...' errors in CI test runs. --- .../AddressRegistrationTests.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs index ecdd2e97ba..00bd4a0826 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs @@ -442,6 +442,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests dataset.Add($"http://[{ip}]:0/", GetTestUrls); } + // There may be no addresses with scope IDs and we need at least one data item in the + // collection, otherwise xUnit fails the test run because a theory has no data. + dataset.Add("http://[::1]:0", GetTestUrls); + return dataset; } } From 0dca3a266fb7f6daa3698b75e27c04ccee5a58c0 Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Tue, 21 Feb 2017 10:05:29 -0800 Subject: [PATCH 1048/1662] Remove custom BenchmarkDotNet toolchain. --- .gitignore | 1 + .../configs/CoreConfig.cs | 3 +- .../configs/MsBuildExecutor.cs | 69 ------------------- .../configs/MsBuildGenerator.cs | 61 ---------------- .../configs/MsBuildToolchain.cs | 28 -------- 5 files changed, 2 insertions(+), 160 deletions(-) delete mode 100644 test/Microsoft.AspNetCore.Server.Kestrel.Performance/configs/MsBuildExecutor.cs delete mode 100644 test/Microsoft.AspNetCore.Server.Kestrel.Performance/configs/MsBuildGenerator.cs delete mode 100644 test/Microsoft.AspNetCore.Server.Kestrel.Performance/configs/MsBuildToolchain.cs diff --git a/.gitignore b/.gitignore index 317cee961f..d685f8ca52 100644 --- a/.gitignore +++ b/.gitignore @@ -33,3 +33,4 @@ runtimes/ launchSettings.json BenchmarkDotNet.Artifacts/ BDN.Generated/ +binaries/ diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/configs/CoreConfig.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/configs/CoreConfig.cs index 391da34c72..1621a1ddc2 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/configs/CoreConfig.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/configs/CoreConfig.cs @@ -22,8 +22,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance .With(RunStrategy.Throughput) .WithLaunchCount(3) .WithWarmupCount(5) - .WithTargetCount(10) - .With(new MsBuildToolchain())); + .WithTargetCount(10)); } } } diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/configs/MsBuildExecutor.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/configs/MsBuildExecutor.cs deleted file mode 100644 index c36449b6b8..0000000000 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/configs/MsBuildExecutor.cs +++ /dev/null @@ -1,69 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.IO; -using System.Reflection; -using BenchmarkDotNet.Characteristics; -using BenchmarkDotNet.Diagnosers; -using BenchmarkDotNet.Extensions; -using BenchmarkDotNet.Jobs; -using BenchmarkDotNet.Loggers; -using BenchmarkDotNet.Running; -using BenchmarkDotNet.Toolchains; -using BenchmarkDotNet.Toolchains.DotNetCli; -using BenchmarkDotNet.Toolchains.Results; - -namespace Microsoft.AspNetCore.Server.Kestrel.Performance -{ - public class MsBuildExecutor : IExecutor - { - public ExecuteResult Execute(BuildResult buildResult, Benchmark benchmark, ILogger logger, IResolver resolver, IDiagnoser diagnoser = null) - { - var workingDirectory = buildResult.ArtifactsPaths.BuildArtifactsDirectoryPath; - - using (var process = new Process { StartInfo = BuildDotNetProcessStartInfo(workingDirectory) }) - { - var loggerDiagnoserType = typeof(Toolchain).GetTypeInfo().Assembly.GetType("BenchmarkDotNet.Loggers.SynchronousProcessOutputLoggerWithDiagnoser"); - var loggerDiagnoser = Activator.CreateInstance( - loggerDiagnoserType, - new object[] { logger, process, diagnoser, benchmark }); - - process.Start(); - - var processInputMethodInfo = loggerDiagnoser.GetType().GetMethod("ProcessInput", BindingFlags.Instance | BindingFlags.NonPublic); - processInputMethodInfo.Invoke(loggerDiagnoser, null); - - process.WaitForExit(); - - if (process.ExitCode != 0) - { - return new ExecuteResult(true, process.ExitCode, new string[0], new string[0]); - } - - var linesWithResults = (IReadOnlyList)loggerDiagnoserType - .GetProperty("LinesWithResults", BindingFlags.Instance | BindingFlags.NonPublic) - .GetValue(loggerDiagnoser, null); - var linesWithExtraOutput = (IReadOnlyList)loggerDiagnoserType - .GetProperty("LinesWithExtraOutput", BindingFlags.Instance | BindingFlags.NonPublic) - .GetValue(loggerDiagnoser, null); - - return new ExecuteResult(true, process.ExitCode, linesWithResults, linesWithExtraOutput); - } - } - - private ProcessStartInfo BuildDotNetProcessStartInfo(string workingDirectory) - => new ProcessStartInfo - { - FileName = "dotnet", - WorkingDirectory = workingDirectory, - Arguments = "binaries/Benchmark.Generated.dll", - UseShellExecute = false, - CreateNoWindow = true, - RedirectStandardOutput = true, - RedirectStandardError = true - }; - } -} \ No newline at end of file diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/configs/MsBuildGenerator.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/configs/MsBuildGenerator.cs deleted file mode 100644 index a1bac17136..0000000000 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/configs/MsBuildGenerator.cs +++ /dev/null @@ -1,61 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using System.IO; -using BenchmarkDotNet.Characteristics; -using BenchmarkDotNet.Environments; -using BenchmarkDotNet.Helpers; -using BenchmarkDotNet.Jobs; -using BenchmarkDotNet.Running; -using BenchmarkDotNet.Toolchains; -using BenchmarkDotNet.Toolchains.DotNetCli; -using System.Reflection; - -namespace Microsoft.AspNetCore.Server.Kestrel.Performance -{ - public class MsBuildGenerator : DotNetCliGenerator - { - public MsBuildGenerator() - : base("netcoreapp1.1", null, (Func) (_ => "x64"), null, null) - { - } - - protected override string GetProjectFilePath(string binariesDirectoryPath) - => Path.Combine(binariesDirectoryPath, "Benchmark.Generated.csproj"); - - protected override void GenerateProject(Benchmark benchmark, ArtifactsPaths artifactsPaths, IResolver resolver) - { - var projectTemplate = @" - - - - - netcoreapp1.1 - true - Exe - - - - - - - - - - -"; - - var projectContent = SetCodeFileName(projectTemplate, Path.GetFileName(artifactsPaths.ProgramCodePath)); - File.WriteAllText(artifactsPaths.ProjectFilePath, projectContent); - - var runtimeConfigContent = @" -{ - ""configProperties"": { - ""System.GC.Server"": true - } -}"; - File.WriteAllText(Path.Combine(artifactsPaths.BuildArtifactsDirectoryPath, "runtimeConfig.template.json"), runtimeConfigContent); - } - } -} \ No newline at end of file diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/configs/MsBuildToolchain.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/configs/MsBuildToolchain.cs deleted file mode 100644 index a0bbda47db..0000000000 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/configs/MsBuildToolchain.cs +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using BenchmarkDotNet.Characteristics; -using BenchmarkDotNet.Environments; -using BenchmarkDotNet.Jobs; -using BenchmarkDotNet.Loggers; -using BenchmarkDotNet.Running; -using BenchmarkDotNet.Toolchains; -using BenchmarkDotNet.Toolchains.Core; -using BenchmarkDotNet.Toolchains.DotNetCli; - -namespace Microsoft.AspNetCore.Server.Kestrel.Performance -{ - public class MsBuildToolchain : Toolchain - { - private const string TargetFrameworkMoniker = "netcoreapp1.1"; - - public MsBuildToolchain() - : base("MsBuildCore", - new MsBuildGenerator(), - new DotNetCliBuilder(TargetFrameworkMoniker), - new MsBuildExecutor()) - { - } - } -} \ No newline at end of file From 80b9673693f8fba2946d51aa4b6edce3906d95b5 Mon Sep 17 00:00:00 2001 From: Pavel Krymets Date: Tue, 21 Feb 2017 16:04:32 -0800 Subject: [PATCH 1049/1662] Temporary add delay to connection test to make it pass (#1384) --- .../ConnectionTests.cs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionTests.cs index cbffa6aaff..2310329ff2 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionTests.cs @@ -50,12 +50,18 @@ namespace Microsoft.AspNetCore.Server.KestrelTests mockLibuv.AllocCallback(socket.InternalGetHandle(), 2048, out ignored); mockLibuv.ReadCallback(socket.InternalGetHandle(), 0, ref ignored); - var readAwaitable = connection.Input.Reader.ReadAsync(); - - var result = readAwaitable.GetResult(); - Assert.False(result.IsCompleted); }, (object)null); + // Wait until ProcessRequestAsync runs + // TODO: Remove when we get non dispatching support + await Task.Delay(1000); + + await context.Thread.PostAsync(_ => + { + var readAwaitable = connection.Input.Reader.ReadAsync(); + + Assert.False(readAwaitable.IsCompleted); + }, (object)null); connection.ConnectionControl.End(ProduceEndType.SocketDisconnect); } } From ba549502e178214cefdb5b58a9db965d576de857 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Tue, 21 Feb 2017 21:09:23 -0800 Subject: [PATCH 1050/1662] Use the IThreadPool as the ReaderScheduler (#1372) - This is what socket input did, also using ThreadPool.QueueUserWorkItem is better than Task.Run for this scenario and avoids a bunch of overhead. --- .../Internal/Http/ListenerContext.cs | 2 +- .../Internal/Infrastructure/IThreadPool.cs | 3 ++- .../Internal/Infrastructure/LoggingThreadPool.cs | 5 +++++ .../TestHelpers/SynchronousThreadPool.cs | 5 +++++ 4 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ListenerContext.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ListenerContext.cs index e5a7ae80e4..f947a17aaa 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ListenerContext.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ListenerContext.cs @@ -44,7 +44,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http public PipeOptions LibuvPipeOptions => new PipeOptions { - ReaderScheduler = TaskRunScheduler.Default, + ReaderScheduler = ServiceContext.ThreadPool, WriterScheduler = Thread, MaximumSizeHigh = ServiceContext.ServerOptions.Limits.MaxRequestBufferSize ?? 0, MaximumSizeLow = ServiceContext.ServerOptions.Limits.MaxRequestBufferSize ?? 0 diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/IThreadPool.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/IThreadPool.cs index af5b6df175..48db68ff10 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/IThreadPool.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/IThreadPool.cs @@ -2,12 +2,13 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.IO.Pipelines; using System.Threading; using System.Threading.Tasks; namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure { - public interface IThreadPool + public interface IThreadPool : IScheduler { void Complete(TaskCompletionSource tcs); void Cancel(TaskCompletionSource tcs); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/LoggingThreadPool.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/LoggingThreadPool.cs index 1cc2f52491..d0cff5e9ac 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/LoggingThreadPool.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/LoggingThreadPool.cs @@ -112,5 +112,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure } }, tcs); } + + public void Schedule(Action action) + { + Run(action); + } } } \ No newline at end of file diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/SynchronousThreadPool.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/SynchronousThreadPool.cs index 15994044d2..b4d35e6ee5 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/SynchronousThreadPool.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/SynchronousThreadPool.cs @@ -34,5 +34,10 @@ namespace Microsoft.AspNetCore.Server.KestrelTests.TestHelpers { action(state); } + + public void Schedule(Action action) + { + action(); + } } } From 7d3bcd2bf868dbd65741da1569ce974993a8e720 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Tue, 7 Feb 2017 03:44:00 -0800 Subject: [PATCH 1051/1662] Avoid unobserved exceptions - Don't throw from AdaptedPipeline.ReadInputAsync - Watch for unobserved exceptions in SampleApp --- samples/SampleApp/Startup.cs | 6 ++++++ .../Adapter/Internal/AdaptedPipeline.cs | 4 +++- .../Internal/Http/Connection.cs | 5 +---- .../Internal/Http/Frame.cs | 6 ++---- 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/samples/SampleApp/Startup.cs b/samples/SampleApp/Startup.cs index c2256120bc..61992fd4d2 100644 --- a/samples/SampleApp/Startup.cs +++ b/samples/SampleApp/Startup.cs @@ -4,6 +4,7 @@ using System; using System.IO; using System.Net; +using System.Threading.Tasks; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; @@ -34,6 +35,11 @@ namespace SampleApp public static void Main(string[] args) { + TaskScheduler.UnobservedTaskException += (sender, e) => + { + Console.WriteLine("Unobserved exception: {0}", e.Exception); + }; + var host = new WebHostBuilder() .UseKestrel(options => { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Adapter/Internal/AdaptedPipeline.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Adapter/Internal/AdaptedPipeline.cs index f3ca1812ae..498357c52d 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Adapter/Internal/AdaptedPipeline.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Adapter/Internal/AdaptedPipeline.cs @@ -63,7 +63,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Adapter.Internal catch (Exception ex) { Input.Writer.Complete(ex); - throw; + + // Don't rethrow the exception. It should be handled by the Pipeline consumer. + return; } } while (bytesRead != 0); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Connection.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Connection.cs index f2211cdc6c..1de0607695 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Connection.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Connection.cs @@ -119,10 +119,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http public Task StopAsync() { - _frame.StopAsync(); - _frame.Input.Reader.CancelPendingRead(); - - return _socketClosedTcs.Task; + return Task.WhenAll(_frame.StopAsync(), _socketClosedTcs.Task); } public virtual Task AbortAsync(Exception error = null) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs index 7a3d04e8d8..525dc56135 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs @@ -402,10 +402,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http /// public Task StopAsync() { - if (!_requestProcessingStopping) - { - _requestProcessingStopping = true; - } + _requestProcessingStopping = true; + Input.Reader.CancelPendingRead(); return _requestProcessingTask ?? TaskCache.CompletedTask; } From 990e2a8dc40ee8f394f930ee456520ffa9c0b7c6 Mon Sep 17 00:00:00 2001 From: Pavel Krymets Date: Thu, 23 Feb 2017 08:04:43 -0800 Subject: [PATCH 1052/1662] Use pass through connection adapter instead of ssl for max buffer size tests (#1391) --- .../MaxRequestBufferSizeTests.cs | 29 ++++--------------- .../PassThroughConnectionAdapter.cs | 2 +- 2 files changed, 7 insertions(+), 24 deletions(-) rename test/{Microsoft.AspNetCore.Server.KestrelTests/TestHelpers => shared}/PassThroughConnectionAdapter.cs (94%) diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/MaxRequestBufferSizeTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/MaxRequestBufferSizeTests.cs index cfbb6cc2ce..3c09271a4f 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/MaxRequestBufferSizeTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/MaxRequestBufferSizeTests.cs @@ -71,7 +71,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [Theory] [MemberData(nameof(LargeUploadData))] - public async Task LargeUpload(long? maxRequestBufferSize, bool ssl, bool expectPause) + public async Task LargeUpload(long? maxRequestBufferSize, bool connectionAdapter, bool expectPause) { // Parameters var data = new byte[_dataLength]; @@ -86,11 +86,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests var clientFinishedSendingRequestBody = new ManualResetEvent(false); var lastBytesWritten = DateTime.MaxValue; - using (var host = StartWebHost(maxRequestBufferSize, data, ssl, startReadingRequestBody, clientFinishedSendingRequestBody)) + using (var host = StartWebHost(maxRequestBufferSize, data, connectionAdapter, startReadingRequestBody, clientFinishedSendingRequestBody)) { var port = host.GetPort(); using (var socket = CreateSocket(port)) - using (var stream = await CreateStreamAsync(socket, ssl, host.GetHost(ssl))) + using (var stream = new NetworkStream(socket)) { await WritePostRequestHeaders(stream, data.Length); @@ -165,7 +165,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } } - private static IWebHost StartWebHost(long? maxRequestBufferSize, byte[] expectedBody, bool useSsl, ManualResetEvent startReadingRequestBody, + private static IWebHost StartWebHost(long? maxRequestBufferSize, byte[] expectedBody, bool useConnectionAdapter, ManualResetEvent startReadingRequestBody, ManualResetEvent clientFinishedSendingRequestBody) { var host = new WebHostBuilder() @@ -173,9 +173,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { options.Listen(new IPEndPoint(IPAddress.Loopback, 0), listenOptions => { - if (useSsl) + if (useConnectionAdapter) { - listenOptions.UseHttps(TestResources.TestCertificatePath, "testPassword"); + listenOptions.ConnectionAdapters.Add(new PassThroughConnectionAdapter()); } }); @@ -251,22 +251,5 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests await writer.WriteAsync("\r\n"); } } - - private static async Task CreateStreamAsync(Socket socket, bool ssl, string targetHost) - { - var networkStream = new NetworkStream(socket); - if (ssl) - { - var sslStream = new SslStream(networkStream, leaveInnerStreamOpen: false, - userCertificateValidationCallback: (a, b, c, d) => true); - await sslStream.AuthenticateAsClientAsync(targetHost, clientCertificates: null, - enabledSslProtocols: SslProtocols.Tls11 | SslProtocols.Tls12, checkCertificateRevocation: false); - return sslStream; - } - else - { - return networkStream; - } - } } } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/PassThroughConnectionAdapter.cs b/test/shared/PassThroughConnectionAdapter.cs similarity index 94% rename from test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/PassThroughConnectionAdapter.cs rename to test/shared/PassThroughConnectionAdapter.cs index 2494e4bc5d..faa688a194 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/PassThroughConnectionAdapter.cs +++ b/test/shared/PassThroughConnectionAdapter.cs @@ -8,7 +8,7 @@ using Microsoft.AspNetCore.Server.Kestrel.Adapter; using Microsoft.AspNetCore.Server.Kestrel.Adapter.Internal; using Microsoft.AspNetCore.Testing; -namespace Microsoft.AspNetCore.Server.KestrelTests.TestHelpers +namespace Microsoft.AspNetCore.Testing { public class PassThroughConnectionAdapter : IConnectionAdapter { From 39b536b402cec895cfe01497650a243cd85f0c28 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Wed, 22 Feb 2017 19:22:22 -0800 Subject: [PATCH 1053/1662] Don't treat canceled reads as end of input --- .../Adapter/Internal/RawStream.cs | 2 +- .../Internal/Http/PipelineExtensions.cs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Adapter/Internal/RawStream.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Adapter/Internal/RawStream.cs index 3ec258b19d..5cc97ee3e8 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Adapter/Internal/RawStream.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Adapter/Internal/RawStream.cs @@ -123,7 +123,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Adapter.Internal readableBuffer.CopyTo(buffer); return count; } - else if (result.IsCompleted || result.IsCancelled) + else if (result.IsCompleted) { return 0; } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/PipelineExtensions.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/PipelineExtensions.cs index 4698eb51ab..c7a92e7639 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/PipelineExtensions.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/PipelineExtensions.cs @@ -26,7 +26,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http return new ValueTask>(data); } - else if (result.IsCompleted || result.IsCancelled) + else if (result.IsCompleted) { return default(ValueTask>); } @@ -56,7 +56,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var segment = result.Buffer.First; return segment.GetArray(); } - else if (result.IsCompleted || result.IsCancelled) + else if (result.IsCompleted) { return default(ArraySegment); } From 8140b8cdfe7638ecd40f8e88605d1dc0cc6df511 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Thu, 23 Feb 2017 23:02:29 -0800 Subject: [PATCH 1054/1662] Use Spans to parse the start line and headers (#1394) * Use Spans to parse the start line and headers - Use `Span` to parse the start line and headers --- KestrelHttpServer.sln | 2 +- samples/SampleApp/SampleApp.csproj | 2 +- .../Internal/Http/Frame.cs | 319 ++++++++++++------ .../Internal/Http/FrameHeaders.Generated.cs | 225 ++++++------ .../Internal/Http/FrameRequestHeaders.cs | 9 + .../MemoryPoolIteratorExtensions.cs | 71 ++++ ...Microsoft.AspNetCore.Server.Kestrel.csproj | 2 +- .../FrameRequestHeadersTests.cs | 2 +- .../FrameTests.cs | 2 +- tools/CodeGenerator/KnownHeaders.cs | 13 +- 10 files changed, 417 insertions(+), 230 deletions(-) diff --git a/KestrelHttpServer.sln b/KestrelHttpServer.sln index d935b2d9b4..24da20c0e0 100644 --- a/KestrelHttpServer.sln +++ b/KestrelHttpServer.sln @@ -1,6 +1,6 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 15 -VisualStudioVersion = 15.0.26213.1 +VisualStudioVersion = 15.0.26206.0 MinimumVisualStudioVersion = 10.0.40219.1 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{7972A5D6-3385-4127-9277-428506DD44FF}" ProjectSection(SolutionItems) = preProject diff --git a/samples/SampleApp/SampleApp.csproj b/samples/SampleApp/SampleApp.csproj index 9d5b086b5c..5fcf04fb03 100644 --- a/samples/SampleApp/SampleApp.csproj +++ b/samples/SampleApp/SampleApp.csproj @@ -3,7 +3,7 @@ - net451;netcoreapp1.1 + netcoreapp1.1;net451 Exe win7-x64 diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs index 525dc56135..232e567a27 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs @@ -997,11 +997,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _requestProcessingStatus = RequestProcessingStatus.RequestStarted; - var limitedBuffer = buffer; + ReadableBuffer limitedBuffer; if (buffer.Length >= ServerOptions.Limits.MaxRequestLineSize) { limitedBuffer = buffer.Slice(0, ServerOptions.Limits.MaxRequestLineSize); } + else + { + limitedBuffer = buffer; + } + if (ReadCursorOperations.Seek(limitedBuffer.Start, limitedBuffer.End, out end, ByteLF) == -1) { if (limitedBuffer.Length == ServerOptions.Limits.MaxRequestLineSize) @@ -1014,17 +1019,46 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } } - end = buffer.Move(end, 1); - ReadCursor methodEnd; - string method; - if (!buffer.GetKnownMethod(out method)) + const int stackAllocLimit = 512; + + // Move 1 byte past the \r + end = limitedBuffer.Move(end, 1); + var startLineBuffer = limitedBuffer.Slice(0, end); + + Span span; + + if (startLineBuffer.IsSingleSpan) { - if (ReadCursorOperations.Seek(buffer.Start, end, out methodEnd, ByteSpace) == -1) + // No copies, directly use the one and only span + span = startLineBuffer.ToSpan(); + } + else if (startLineBuffer.Length < stackAllocLimit) + { + unsafe + { + // Multiple buffers and < stackAllocLimit, copy into a stack buffer + byte* stackBuffer = stackalloc byte[startLineBuffer.Length]; + span = new Span(stackBuffer, startLineBuffer.Length); + startLineBuffer.CopyTo(span); + } + } + else + { + // We're not a single span here but we can use pooled arrays to avoid allocations in the rare case + span = new Span(new byte[startLineBuffer.Length]); + startLineBuffer.CopyTo(span); + } + + var methodEnd = 0; + if (!span.GetKnownMethod(out string method)) + { + methodEnd = span.IndexOf(ByteSpace); + if (methodEnd == -1) { RejectRequestLine(start, end); } - method = buffer.Slice(buffer.Start, methodEnd).GetAsciiString(); + method = span.Slice(0, methodEnd).GetAsciiString(); if (method == null) { @@ -1043,57 +1077,67 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } else { - methodEnd = buffer.Slice(method.Length).Start; + methodEnd += method.Length; } var needDecode = false; - ReadCursor pathEnd; + var pathBegin = methodEnd + 1; + var pathToEndSpan = span.Slice(pathBegin, span.Length - pathBegin); + pathBegin = 0; - var pathBegin = buffer.Move(methodEnd, 1); + // TODO: IndexOfAny + var spaceIndex = pathToEndSpan.IndexOf(ByteSpace); + var questionMarkIndex = pathToEndSpan.IndexOf(ByteQuestionMark); + var percentageIndex = pathToEndSpan.IndexOf(BytePercentage); - var chFound = ReadCursorOperations.Seek(pathBegin, end, out pathEnd, ByteSpace, ByteQuestionMark, BytePercentage); - if (chFound == -1) + var pathEnd = MinNonZero(spaceIndex, questionMarkIndex, percentageIndex); + + if (spaceIndex == -1 && questionMarkIndex == -1 && percentageIndex == -1) { RejectRequestLine(start, end); } - else if (chFound == BytePercentage) + else if (percentageIndex != -1) { needDecode = true; - chFound = ReadCursorOperations.Seek(pathBegin, end, out pathEnd, ByteSpace, ByteQuestionMark); - if (chFound == -1) - { - RejectRequestLine(start, end); - } - }; - var queryString = ""; - ReadCursor queryEnd = pathEnd; - if (chFound == ByteQuestionMark) - { - if (ReadCursorOperations.Seek(pathEnd, end, out queryEnd, ByteSpace) == -1) + pathEnd = MinNonZero(spaceIndex, questionMarkIndex); + if (questionMarkIndex == -1 && spaceIndex == -1) { RejectRequestLine(start, end); } - queryString = buffer.Slice(pathEnd, queryEnd).GetAsciiString(); } - // No path + var queryString = ""; + var queryEnd = pathEnd; + if (questionMarkIndex != -1) + { + queryEnd = spaceIndex; + if (spaceIndex == -1) + { + RejectRequestLine(start, end); + } + + queryString = pathToEndSpan.Slice(pathEnd, queryEnd - pathEnd).GetAsciiString(); + } + if (pathBegin == pathEnd) { RejectRequestLine(start, end); } - ReadCursor versionEnd; - if (ReadCursorOperations.Seek(queryEnd, end, out versionEnd, ByteCR) == -1) + var versionBegin = queryEnd + 1; + var versionToEndSpan = pathToEndSpan.Slice(versionBegin, pathToEndSpan.Length - versionBegin); + versionBegin = 0; + var versionEnd = versionToEndSpan.IndexOf(ByteCR); + + if (versionEnd == -1) { RejectRequestLine(start, end); } - string httpVersion; - var versionBuffer = buffer.Slice(queryEnd, end).Slice(1); - if (!versionBuffer.GetKnownVersion(out httpVersion)) + if (!versionToEndSpan.GetKnownVersion(out string httpVersion)) { - httpVersion = versionBuffer.Start.GetAsciiStringEscaped(versionEnd, 9); + httpVersion = versionToEndSpan.Slice(0, versionEnd).GetAsciiStringEscaped(); if (httpVersion == string.Empty) { @@ -1105,14 +1149,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } } - var lineEnd = buffer.Slice(versionEnd, 2).ToSpan(); - if (lineEnd[1] != ByteLF) + if (versionToEndSpan[versionEnd + 1] != ByteLF) { RejectRequestLine(start, end); } - var pathBuffer = buffer.Slice(pathBegin, pathEnd); - var targetBuffer = buffer.Slice(pathBegin, queryEnd); + var pathBuffer = pathToEndSpan.Slice(pathBegin, pathEnd); + var targetBuffer = pathToEndSpan.Slice(pathBegin, queryEnd); // URIs are always encoded/escaped to ASCII https://tools.ietf.org/html/rfc3986#page-11 // Multibyte Internationalized Resource Identifiers (IRIs) are first converted to utf8; @@ -1125,7 +1168,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http rawTarget = targetBuffer.GetAsciiString() ?? string.Empty; // URI was encoded, unescape and then parse as utf8 - var pathSpan = pathBuffer.ToSpan(); + var pathSpan = pathBuffer; int pathLength = UrlEncoder.Decode(pathSpan, pathSpan); requestUrlPath = new Utf8String(pathSpan.Slice(0, pathLength)).ToString(); } @@ -1175,6 +1218,21 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http return true; } + private int MinNonZero(int v1, int v2) + { + v1 = v1 == -1 ? int.MaxValue : v1; + v2 = v2 == -1 ? int.MaxValue : v2; + return Math.Min(v1, v2); + } + + private int MinNonZero(int v1, int v2, int v3) + { + v1 = v1 == -1 ? int.MaxValue : v1; + v2 = v2 == -1 ? int.MaxValue : v2; + v3 = v3 == -1 ? int.MaxValue : v3; + return Math.Min(Math.Min(v1, v2), v3); + } + private void RejectRequestLine(ReadCursor start, ReadCursor end) { const int MaxRequestLineError = 32; @@ -1244,40 +1302,41 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http consumed = buffer.Start; examined = buffer.End; + var bufferLength = buffer.Length; + var reader = new ReadableBufferReader(buffer); + while (true) { - var headersEnd = buffer.Slice(0, Math.Min(buffer.Length, 2)); - var headersEndSpan = headersEnd.ToSpan(); + var start = reader; + int ch1 = reader.Take(); + var ch2 = reader.Take(); - if (headersEndSpan.Length == 0) + if (ch1 == -1) { return false; } - else - { - var ch = headersEndSpan[0]; - if (ch == ByteCR) - { - // Check for final CRLF. - if (headersEndSpan.Length < 2) - { - return false; - } - else if (headersEndSpan[1] == ByteLF) - { - consumed = headersEnd.End; - examined = consumed; - ConnectionControl.CancelTimeout(); - return true; - } - // Headers don't end in CRLF line. - RejectRequest(RequestRejectionReason.HeadersCorruptedInvalidHeaderSequence); - } - else if (ch == ByteSpace || ch == ByteTab) + if (ch1 == ByteCR) + { + // Check for final CRLF. + if (ch2 == -1) { - RejectRequest(RequestRejectionReason.HeaderLineMustNotStartWithWhitespace); + return false; } + else if (ch2 == ByteLF) + { + consumed = reader.Cursor; + examined = consumed; + ConnectionControl.CancelTimeout(); + return true; + } + + // Headers don't end in CRLF line. + RejectRequest(RequestRejectionReason.HeadersCorruptedInvalidHeaderSequence); + } + else if (ch1 == ByteSpace || ch1 == ByteTab) + { + RejectRequest(RequestRejectionReason.HeaderLineMustNotStartWithWhitespace); } // If we've parsed the max allowed numbers of headers and we're starting a new @@ -1287,15 +1346,30 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http RejectRequest(RequestRejectionReason.TooManyHeaders); } - ReadCursor lineEnd; - var limitedBuffer = buffer; - if (buffer.Length >= _remainingRequestHeadersBytesAllowed) + // Reset the reader since we're not at the end of headers + reader = start; + + // Now parse a single header + ReadableBuffer limitedBuffer; + var overLength = false; + + if (bufferLength >= _remainingRequestHeadersBytesAllowed) { - limitedBuffer = buffer.Slice(0, _remainingRequestHeadersBytesAllowed); + limitedBuffer = buffer.Slice(consumed, _remainingRequestHeadersBytesAllowed); + + // If we sliced it means the current buffer bigger than what we're + // allowed to look at + overLength = true; } - if (ReadCursorOperations.Seek(limitedBuffer.Start, limitedBuffer.End, out lineEnd, ByteLF) == -1) + else { - if (limitedBuffer.Length == _remainingRequestHeadersBytesAllowed) + limitedBuffer = buffer; + } + + if (ReadCursorOperations.Seek(consumed, limitedBuffer.End, out var lineEnd, ByteLF) == -1) + { + // We didn't find a \n in the current buffer and we had to slice it so it's an issue + if (overLength) { RejectRequest(RequestRejectionReason.HeadersExceedMaxTotalSize); } @@ -1305,39 +1379,94 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } } - var beginName = buffer.Start; - ReadCursor endName; - if (ReadCursorOperations.Seek(buffer.Start, lineEnd, out endName, ByteColon) == -1) + const int stackAllocLimit = 512; + + if (lineEnd != limitedBuffer.End) + { + lineEnd = limitedBuffer.Move(lineEnd, 1); + } + + var headerBuffer = limitedBuffer.Slice(consumed, lineEnd); + + Span span; + if (headerBuffer.IsSingleSpan) + { + // No copies, directly use the one and only span + span = headerBuffer.ToSpan(); + } + else if (headerBuffer.Length < stackAllocLimit) + { + unsafe + { + // Multiple buffers and < stackAllocLimit, copy into a stack buffer + byte* stackBuffer = stackalloc byte[headerBuffer.Length]; + span = new Span(stackBuffer, headerBuffer.Length); + headerBuffer.CopyTo(span); + } + } + else + { + // We're not a single span here but we can use pooled arrays to avoid allocations in the rare case + span = new Span(new byte[headerBuffer.Length]); + headerBuffer.CopyTo(span); + } + + int endNameIndex = span.IndexOf(ByteColon); + if (endNameIndex == -1) { RejectRequest(RequestRejectionReason.NoColonCharacterFoundInHeaderLine); } - ReadCursor whitespace; - if (ReadCursorOperations.Seek(beginName, endName, out whitespace, ByteTab, ByteSpace) != -1) + var nameBuffer = span.Slice(0, endNameIndex); + if (nameBuffer.IndexOf(ByteSpace) != -1 || nameBuffer.IndexOf(ByteTab) != -1) { RejectRequest(RequestRejectionReason.WhitespaceIsNotAllowedInHeaderName); } - ReadCursor endValue; - if (ReadCursorOperations.Seek(beginName, lineEnd, out endValue, ByteCR) == -1) + int endValueIndex = span.IndexOf(ByteCR); + if (endValueIndex == -1) { RejectRequest(RequestRejectionReason.MissingCRInHeaderLine); } - var lineSufix = buffer.Slice(endValue); - if (lineSufix.Length < 3) + var lineSuffix = span.Slice(endValueIndex); + if (lineSuffix.Length < 2) { return false; } - lineSufix = lineSufix.Slice(0, 3); // \r\n\r - var lineSufixSpan = lineSufix.ToSpan(); + // This check and MissingCRInHeaderLine is a bit backwards, we should do it at once instead of having another seek - if (lineSufixSpan[1] != ByteLF) + if (lineSuffix[1] != ByteLF) { RejectRequest(RequestRejectionReason.HeaderValueMustNotContainCR); } - var next = lineSufixSpan[2]; + // Trim trailing whitespace from header value by repeatedly advancing to next + // whitespace or CR. + // + // - If CR is found, this is the end of the header value. + // - If whitespace is found, this is the _tentative_ end of the header value. + // If non-whitespace is found after it and it's not CR, seek again to the next + // whitespace or CR for a new (possibly tentative) end of value. + + var valueBuffer = span.Slice(endNameIndex + 1, endValueIndex - (endNameIndex + 1)); + + // TODO: Trim else where + var value = valueBuffer.GetAsciiString()?.Trim() ?? string.Empty; + + var headerLineLength = span.Length; + + // -1 so that we can re-check the extra \r + reader.Skip(headerLineLength); + + var next = reader.Peek(); + + // We cant check for line continuations to reject everything we've done so far + if (next == -1) + { + return false; + } + if (next == ByteSpace || next == ByteTab) { // From https://tools.ietf.org/html/rfc7230#section-3.2.4: @@ -1360,31 +1489,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http RejectRequest(RequestRejectionReason.HeaderValueLineFoldingNotSupported); } - // Trim trailing whitespace from header value by repeatedly advancing to next - // whitespace or CR. - // - // - If CR is found, this is the end of the header value. - // - If whitespace is found, this is the _tentative_ end of the header value. - // If non-whitespace is found after it and it's not CR, seek again to the next - // whitespace or CR for a new (possibly tentative) end of value. + // Update the frame state only after we know there's no header line continuation + _remainingRequestHeadersBytesAllowed -= headerLineLength; + bufferLength -= headerLineLength; - var nameBuffer = buffer.Slice(beginName, endName); - - // TODO: TrimStart and TrimEnd are pretty slow - var valueBuffer = buffer.Slice(endName, endValue).Slice(1).TrimStart().TrimEnd(); - - var name = nameBuffer.ToArraySegment(); - var value = valueBuffer.GetAsciiString(); - - lineEnd = limitedBuffer.Move(lineEnd, 1); - - // TODO: bad - _remainingRequestHeadersBytesAllowed -= buffer.Slice(0, lineEnd).Length; _requestHeadersParsed++; - requestHeaders.Append(name.Array, name.Offset, name.Count, value); - buffer = buffer.Slice(lineEnd); - consumed = buffer.Start; + requestHeaders.Append(nameBuffer, value); + + consumed = reader.Cursor; } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameHeaders.Generated.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameHeaders.Generated.cs index 7cfb64ff31..051b6b5737 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameHeaders.Generated.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameHeaders.Generated.cs @@ -3501,12 +3501,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } - public unsafe void Append(byte[] keyBytes, int keyOffset, int keyLength, string value) + public unsafe void Append(byte* pKeyBytes, int keyLength, string value) { - fixed (byte* ptr = &keyBytes[keyOffset]) - { - var pUB = ptr; - var pUL = (ulong*)pUB; + var pUB = pKeyBytes; + var pUL = (ulong*)pUB; var pUI = (uint*)pUB; var pUS = (ushort*)pUB; var stringValue = new StringValues(value); @@ -3567,11 +3565,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http break; } - AppendNonPrimaryHeaders(ptr, keyOffset, keyLength, value); - } + AppendNonPrimaryHeaders(pKeyBytes, keyLength, value); } - - private unsafe void AppendNonPrimaryHeaders(byte* pKeyBytes, int keyOffset, int keyLength, string value) + + private unsafe void AppendNonPrimaryHeaders(byte* pKeyBytes, int keyLength, string value) { var pUB = pKeyBytes; var pUL = (ulong*)pUB; @@ -7767,10 +7764,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } else { - var valueCount = _headers._Connection.Count; - for (var i = 0; i < valueCount; i++) + var valueCount = _headers._Connection.Count; + for (var i = 0; i < valueCount; i++) { - var value = _headers._Connection[i]; + var value = _headers._Connection[i]; if (value != null) { output.CopyFrom(_headerBytes, 17, 14); @@ -7793,10 +7790,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } else { - var valueCount = _headers._Date.Count; - for (var i = 0; i < valueCount; i++) + var valueCount = _headers._Date.Count; + for (var i = 0; i < valueCount; i++) { - var value = _headers._Date[i]; + var value = _headers._Date[i]; if (value != null) { output.CopyFrom(_headerBytes, 31, 8); @@ -7814,10 +7811,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if ((tempBits & 2048L) != 0) { { - var valueCount = _headers._ContentType.Count; - for (var i = 0; i < valueCount; i++) + var valueCount = _headers._ContentType.Count; + for (var i = 0; i < valueCount; i++) { - var value = _headers._ContentType[i]; + var value = _headers._ContentType[i]; if (value != null) { output.CopyFrom(_headerBytes, 133, 16); @@ -7840,10 +7837,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } else { - var valueCount = _headers._Server.Count; - for (var i = 0; i < valueCount; i++) + var valueCount = _headers._Server.Count; + for (var i = 0; i < valueCount; i++) { - var value = _headers._Server[i]; + var value = _headers._Server[i]; if (value != null) { output.CopyFrom(_headerBytes, 350, 10); @@ -7872,10 +7869,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if ((tempBits & 1L) != 0) { { - var valueCount = _headers._CacheControl.Count; - for (var i = 0; i < valueCount; i++) + var valueCount = _headers._CacheControl.Count; + for (var i = 0; i < valueCount; i++) { - var value = _headers._CacheControl[i]; + var value = _headers._CacheControl[i]; if (value != null) { output.CopyFrom(_headerBytes, 0, 17); @@ -7893,10 +7890,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if ((tempBits & 8L) != 0) { { - var valueCount = _headers._KeepAlive.Count; - for (var i = 0; i < valueCount; i++) + var valueCount = _headers._KeepAlive.Count; + for (var i = 0; i < valueCount; i++) { - var value = _headers._KeepAlive[i]; + var value = _headers._KeepAlive[i]; if (value != null) { output.CopyFrom(_headerBytes, 39, 14); @@ -7914,10 +7911,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if ((tempBits & 16L) != 0) { { - var valueCount = _headers._Pragma.Count; - for (var i = 0; i < valueCount; i++) + var valueCount = _headers._Pragma.Count; + for (var i = 0; i < valueCount; i++) { - var value = _headers._Pragma[i]; + var value = _headers._Pragma[i]; if (value != null) { output.CopyFrom(_headerBytes, 53, 10); @@ -7935,10 +7932,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if ((tempBits & 32L) != 0) { { - var valueCount = _headers._Trailer.Count; - for (var i = 0; i < valueCount; i++) + var valueCount = _headers._Trailer.Count; + for (var i = 0; i < valueCount; i++) { - var value = _headers._Trailer[i]; + var value = _headers._Trailer[i]; if (value != null) { output.CopyFrom(_headerBytes, 63, 11); @@ -7961,10 +7958,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } else { - var valueCount = _headers._TransferEncoding.Count; - for (var i = 0; i < valueCount; i++) + var valueCount = _headers._TransferEncoding.Count; + for (var i = 0; i < valueCount; i++) { - var value = _headers._TransferEncoding[i]; + var value = _headers._TransferEncoding[i]; if (value != null) { output.CopyFrom(_headerBytes, 74, 21); @@ -7982,10 +7979,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if ((tempBits & 128L) != 0) { { - var valueCount = _headers._Upgrade.Count; - for (var i = 0; i < valueCount; i++) + var valueCount = _headers._Upgrade.Count; + for (var i = 0; i < valueCount; i++) { - var value = _headers._Upgrade[i]; + var value = _headers._Upgrade[i]; if (value != null) { output.CopyFrom(_headerBytes, 95, 11); @@ -8003,10 +8000,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if ((tempBits & 256L) != 0) { { - var valueCount = _headers._Via.Count; - for (var i = 0; i < valueCount; i++) + var valueCount = _headers._Via.Count; + for (var i = 0; i < valueCount; i++) { - var value = _headers._Via[i]; + var value = _headers._Via[i]; if (value != null) { output.CopyFrom(_headerBytes, 106, 7); @@ -8024,10 +8021,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if ((tempBits & 512L) != 0) { { - var valueCount = _headers._Warning.Count; - for (var i = 0; i < valueCount; i++) + var valueCount = _headers._Warning.Count; + for (var i = 0; i < valueCount; i++) { - var value = _headers._Warning[i]; + var value = _headers._Warning[i]; if (value != null) { output.CopyFrom(_headerBytes, 113, 11); @@ -8045,10 +8042,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if ((tempBits & 1024L) != 0) { { - var valueCount = _headers._Allow.Count; - for (var i = 0; i < valueCount; i++) + var valueCount = _headers._Allow.Count; + for (var i = 0; i < valueCount; i++) { - var value = _headers._Allow[i]; + var value = _headers._Allow[i]; if (value != null) { output.CopyFrom(_headerBytes, 124, 9); @@ -8066,10 +8063,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if ((tempBits & 4096L) != 0) { { - var valueCount = _headers._ContentEncoding.Count; - for (var i = 0; i < valueCount; i++) + var valueCount = _headers._ContentEncoding.Count; + for (var i = 0; i < valueCount; i++) { - var value = _headers._ContentEncoding[i]; + var value = _headers._ContentEncoding[i]; if (value != null) { output.CopyFrom(_headerBytes, 149, 20); @@ -8087,10 +8084,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if ((tempBits & 8192L) != 0) { { - var valueCount = _headers._ContentLanguage.Count; - for (var i = 0; i < valueCount; i++) + var valueCount = _headers._ContentLanguage.Count; + for (var i = 0; i < valueCount; i++) { - var value = _headers._ContentLanguage[i]; + var value = _headers._ContentLanguage[i]; if (value != null) { output.CopyFrom(_headerBytes, 169, 20); @@ -8108,10 +8105,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if ((tempBits & 16384L) != 0) { { - var valueCount = _headers._ContentLocation.Count; - for (var i = 0; i < valueCount; i++) + var valueCount = _headers._ContentLocation.Count; + for (var i = 0; i < valueCount; i++) { - var value = _headers._ContentLocation[i]; + var value = _headers._ContentLocation[i]; if (value != null) { output.CopyFrom(_headerBytes, 189, 20); @@ -8129,10 +8126,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if ((tempBits & 32768L) != 0) { { - var valueCount = _headers._ContentMD5.Count; - for (var i = 0; i < valueCount; i++) + var valueCount = _headers._ContentMD5.Count; + for (var i = 0; i < valueCount; i++) { - var value = _headers._ContentMD5[i]; + var value = _headers._ContentMD5[i]; if (value != null) { output.CopyFrom(_headerBytes, 209, 15); @@ -8150,10 +8147,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if ((tempBits & 65536L) != 0) { { - var valueCount = _headers._ContentRange.Count; - for (var i = 0; i < valueCount; i++) + var valueCount = _headers._ContentRange.Count; + for (var i = 0; i < valueCount; i++) { - var value = _headers._ContentRange[i]; + var value = _headers._ContentRange[i]; if (value != null) { output.CopyFrom(_headerBytes, 224, 17); @@ -8171,10 +8168,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if ((tempBits & 131072L) != 0) { { - var valueCount = _headers._Expires.Count; - for (var i = 0; i < valueCount; i++) + var valueCount = _headers._Expires.Count; + for (var i = 0; i < valueCount; i++) { - var value = _headers._Expires[i]; + var value = _headers._Expires[i]; if (value != null) { output.CopyFrom(_headerBytes, 241, 11); @@ -8192,10 +8189,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if ((tempBits & 262144L) != 0) { { - var valueCount = _headers._LastModified.Count; - for (var i = 0; i < valueCount; i++) + var valueCount = _headers._LastModified.Count; + for (var i = 0; i < valueCount; i++) { - var value = _headers._LastModified[i]; + var value = _headers._LastModified[i]; if (value != null) { output.CopyFrom(_headerBytes, 252, 17); @@ -8213,10 +8210,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if ((tempBits & 524288L) != 0) { { - var valueCount = _headers._AcceptRanges.Count; - for (var i = 0; i < valueCount; i++) + var valueCount = _headers._AcceptRanges.Count; + for (var i = 0; i < valueCount; i++) { - var value = _headers._AcceptRanges[i]; + var value = _headers._AcceptRanges[i]; if (value != null) { output.CopyFrom(_headerBytes, 269, 17); @@ -8234,10 +8231,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if ((tempBits & 1048576L) != 0) { { - var valueCount = _headers._Age.Count; - for (var i = 0; i < valueCount; i++) + var valueCount = _headers._Age.Count; + for (var i = 0; i < valueCount; i++) { - var value = _headers._Age[i]; + var value = _headers._Age[i]; if (value != null) { output.CopyFrom(_headerBytes, 286, 7); @@ -8255,10 +8252,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if ((tempBits & 2097152L) != 0) { { - var valueCount = _headers._ETag.Count; - for (var i = 0; i < valueCount; i++) + var valueCount = _headers._ETag.Count; + for (var i = 0; i < valueCount; i++) { - var value = _headers._ETag[i]; + var value = _headers._ETag[i]; if (value != null) { output.CopyFrom(_headerBytes, 293, 8); @@ -8276,10 +8273,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if ((tempBits & 4194304L) != 0) { { - var valueCount = _headers._Location.Count; - for (var i = 0; i < valueCount; i++) + var valueCount = _headers._Location.Count; + for (var i = 0; i < valueCount; i++) { - var value = _headers._Location[i]; + var value = _headers._Location[i]; if (value != null) { output.CopyFrom(_headerBytes, 301, 12); @@ -8297,10 +8294,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if ((tempBits & 8388608L) != 0) { { - var valueCount = _headers._ProxyAuthenticate.Count; - for (var i = 0; i < valueCount; i++) + var valueCount = _headers._ProxyAuthenticate.Count; + for (var i = 0; i < valueCount; i++) { - var value = _headers._ProxyAuthenticate[i]; + var value = _headers._ProxyAuthenticate[i]; if (value != null) { output.CopyFrom(_headerBytes, 313, 22); @@ -8318,10 +8315,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if ((tempBits & 16777216L) != 0) { { - var valueCount = _headers._RetryAfter.Count; - for (var i = 0; i < valueCount; i++) + var valueCount = _headers._RetryAfter.Count; + for (var i = 0; i < valueCount; i++) { - var value = _headers._RetryAfter[i]; + var value = _headers._RetryAfter[i]; if (value != null) { output.CopyFrom(_headerBytes, 335, 15); @@ -8339,10 +8336,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if ((tempBits & 67108864L) != 0) { { - var valueCount = _headers._SetCookie.Count; - for (var i = 0; i < valueCount; i++) + var valueCount = _headers._SetCookie.Count; + for (var i = 0; i < valueCount; i++) { - var value = _headers._SetCookie[i]; + var value = _headers._SetCookie[i]; if (value != null) { output.CopyFrom(_headerBytes, 360, 14); @@ -8360,10 +8357,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if ((tempBits & 134217728L) != 0) { { - var valueCount = _headers._Vary.Count; - for (var i = 0; i < valueCount; i++) + var valueCount = _headers._Vary.Count; + for (var i = 0; i < valueCount; i++) { - var value = _headers._Vary[i]; + var value = _headers._Vary[i]; if (value != null) { output.CopyFrom(_headerBytes, 374, 8); @@ -8381,10 +8378,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if ((tempBits & 268435456L) != 0) { { - var valueCount = _headers._WWWAuthenticate.Count; - for (var i = 0; i < valueCount; i++) + var valueCount = _headers._WWWAuthenticate.Count; + for (var i = 0; i < valueCount; i++) { - var value = _headers._WWWAuthenticate[i]; + var value = _headers._WWWAuthenticate[i]; if (value != null) { output.CopyFrom(_headerBytes, 382, 20); @@ -8402,10 +8399,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if ((tempBits & 536870912L) != 0) { { - var valueCount = _headers._AccessControlAllowCredentials.Count; - for (var i = 0; i < valueCount; i++) + var valueCount = _headers._AccessControlAllowCredentials.Count; + for (var i = 0; i < valueCount; i++) { - var value = _headers._AccessControlAllowCredentials[i]; + var value = _headers._AccessControlAllowCredentials[i]; if (value != null) { output.CopyFrom(_headerBytes, 402, 36); @@ -8423,10 +8420,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if ((tempBits & 1073741824L) != 0) { { - var valueCount = _headers._AccessControlAllowHeaders.Count; - for (var i = 0; i < valueCount; i++) + var valueCount = _headers._AccessControlAllowHeaders.Count; + for (var i = 0; i < valueCount; i++) { - var value = _headers._AccessControlAllowHeaders[i]; + var value = _headers._AccessControlAllowHeaders[i]; if (value != null) { output.CopyFrom(_headerBytes, 438, 32); @@ -8444,10 +8441,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if ((tempBits & 2147483648L) != 0) { { - var valueCount = _headers._AccessControlAllowMethods.Count; - for (var i = 0; i < valueCount; i++) + var valueCount = _headers._AccessControlAllowMethods.Count; + for (var i = 0; i < valueCount; i++) { - var value = _headers._AccessControlAllowMethods[i]; + var value = _headers._AccessControlAllowMethods[i]; if (value != null) { output.CopyFrom(_headerBytes, 470, 32); @@ -8465,10 +8462,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if ((tempBits & 4294967296L) != 0) { { - var valueCount = _headers._AccessControlAllowOrigin.Count; - for (var i = 0; i < valueCount; i++) + var valueCount = _headers._AccessControlAllowOrigin.Count; + for (var i = 0; i < valueCount; i++) { - var value = _headers._AccessControlAllowOrigin[i]; + var value = _headers._AccessControlAllowOrigin[i]; if (value != null) { output.CopyFrom(_headerBytes, 502, 31); @@ -8486,10 +8483,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if ((tempBits & 8589934592L) != 0) { { - var valueCount = _headers._AccessControlExposeHeaders.Count; - for (var i = 0; i < valueCount; i++) + var valueCount = _headers._AccessControlExposeHeaders.Count; + for (var i = 0; i < valueCount; i++) { - var value = _headers._AccessControlExposeHeaders[i]; + var value = _headers._AccessControlExposeHeaders[i]; if (value != null) { output.CopyFrom(_headerBytes, 533, 33); @@ -8507,10 +8504,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if ((tempBits & 17179869184L) != 0) { { - var valueCount = _headers._AccessControlMaxAge.Count; - for (var i = 0; i < valueCount; i++) + var valueCount = _headers._AccessControlMaxAge.Count; + for (var i = 0; i < valueCount; i++) { - var value = _headers._AccessControlMaxAge[i]; + var value = _headers._AccessControlMaxAge[i]; if (value != null) { output.CopyFrom(_headerBytes, 566, 26); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameRequestHeaders.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameRequestHeaders.cs index 4dd46d5cf1..ca6496d320 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameRequestHeaders.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameRequestHeaders.cs @@ -1,6 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; using System.Collections; using System.Collections.Generic; using System.Runtime.CompilerServices; @@ -29,6 +30,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http Unknown[key] = value; } + public unsafe void Append(Span name, string value) + { + fixed (byte* namePtr = &name.DangerousGetPinnableReference()) + { + Append(namePtr, name.Length, value); + } + } + [MethodImpl(MethodImplOptions.NoInlining)] private unsafe void AppendUnknownHeaders(byte* pKeyBytes, int keyLength, string value) { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolIteratorExtensions.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolIteratorExtensions.cs index 94cf66ef7b..95c3c5a59f 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolIteratorExtensions.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolIteratorExtensions.cs @@ -90,6 +90,19 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure return sb.ToString(); } + public static string GetAsciiStringEscaped(this Span span) + { + var sb = new StringBuilder(); + + for (var i = 0; i < span.Length; ++i) + { + var ch = span[i]; + sb.Append(ch < 0x20 || ch >= 0x7F ? $"<0x{ch:X2}>" : ((char)ch).ToString()); + } + + return sb.ToString(); + } + public static ArraySegment PeekArraySegment(this MemoryPoolIterator iter) { if (iter.IsDefault || iter.IsEnd) @@ -157,6 +170,33 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure return false; } + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static bool GetKnownMethod(this Span span, out string knownMethod) + { + knownMethod = null; + if (span.Length < sizeof(ulong)) + { + return false; + } + + ulong value = span.Read(); + if ((value & _mask4Chars) == _httpGetMethodLong) + { + knownMethod = HttpMethods.Get; + return true; + } + foreach (var x in _knownMethods) + { + if ((value & x.Item1) == x.Item2) + { + knownMethod = x.Item3; + return true; + } + } + + return false; + } + /// /// Checks 9 bytes from correspond to a known HTTP version. /// @@ -200,5 +240,36 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure return knownVersion != null; } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static bool GetKnownVersion(this Span span, out string knownVersion) + { + knownVersion = null; + + if (span.Length < sizeof(ulong)) + { + return false; + } + + var value = span.Read(); + if (value == _http11VersionLong) + { + knownVersion = Http11Version; + } + else if (value == _http10VersionLong) + { + knownVersion = Http10Version; + } + + if (knownVersion != null) + { + if (span[sizeof(ulong)] != (byte)'\r') + { + knownVersion = null; + } + } + + return knownVersion != null; + } } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Microsoft.AspNetCore.Server.Kestrel.csproj b/src/Microsoft.AspNetCore.Server.Kestrel/Microsoft.AspNetCore.Server.Kestrel.csproj index c62c37e231..5dd7b984c9 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Microsoft.AspNetCore.Server.Kestrel.csproj +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Microsoft.AspNetCore.Server.Kestrel.csproj @@ -30,4 +30,4 @@ - + \ No newline at end of file diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameRequestHeadersTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameRequestHeadersTests.cs index 91212d627b..dbf6d857a5 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameRequestHeadersTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameRequestHeadersTests.cs @@ -311,7 +311,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var encoding = Encoding.GetEncoding("iso-8859-1"); var exception = Assert.Throws( - () => headers.Append(encoding.GetBytes(key), 0, encoding.GetByteCount(key), key)); + () => headers.Append(encoding.GetBytes(key), key)); Assert.Equal(StatusCodes.Status400BadRequest, exception.StatusCode); } } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs index bf6fc9c78b..3edb7fad3d 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs @@ -611,7 +611,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var exception = Assert.Throws(() => _frame.TakeStartLine(readableBuffer, out consumed, out examined)); _socketInput.Reader.Advance(consumed, examined); - Assert.Equal("Unrecognized HTTP version: HTTP/1.1a...", exception.Message); + Assert.Equal("Unrecognized HTTP version: HTTP/1.1ab", exception.Message); Assert.Equal(StatusCodes.Status505HttpVersionNotsupported, exception.StatusCode); } diff --git a/tools/CodeGenerator/KnownHeaders.cs b/tools/CodeGenerator/KnownHeaders.cs index 0e2fdf858f..a211013404 100644 --- a/tools/CodeGenerator/KnownHeaders.cs +++ b/tools/CodeGenerator/KnownHeaders.cs @@ -564,18 +564,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http }}" : "")}")} }}" : "")} {(loop.ClassName == "FrameRequestHeaders" ? $@" - public unsafe void Append(byte[] keyBytes, int keyOffset, int keyLength, string value) + public unsafe void Append(byte* pKeyBytes, int keyLength, string value) {{ - fixed (byte* ptr = &keyBytes[keyOffset]) - {{ - var pUB = ptr; - {AppendSwitch(loop.Headers.Where(h => h.PrimaryHeader).GroupBy(x => x.Name.Length), loop.ClassName)} + var pUB = pKeyBytes; + {AppendSwitch(loop.Headers.Where(h => h.PrimaryHeader).GroupBy(x => x.Name.Length), loop.ClassName)} - AppendNonPrimaryHeaders(ptr, keyOffset, keyLength, value); - }} + AppendNonPrimaryHeaders(pKeyBytes, keyLength, value); }} - private unsafe void AppendNonPrimaryHeaders(byte* pKeyBytes, int keyOffset, int keyLength, string value) + private unsafe void AppendNonPrimaryHeaders(byte* pKeyBytes, int keyLength, string value) {{ var pUB = pKeyBytes; {AppendSwitch(loop.Headers.Where(h => !h.PrimaryHeader).GroupBy(x => x.Name.Length), loop.ClassName)} From 0860981adacdb5510f7266b93d7b7781b6102e2b Mon Sep 17 00:00:00 2001 From: David Fowler Date: Fri, 24 Feb 2017 09:31:43 -0800 Subject: [PATCH 1055/1662] Skipping failing tests to unblock CI --- .../RequestTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs index 77ae582bfa..7abd78a213 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs @@ -36,7 +36,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests // Never change to a lower value, otherwise regression testing for // https://github.com/aspnet/KestrelHttpServer/issues/520#issuecomment-188591242 // will be lost. - [InlineData((long)int.MaxValue + 1, false)] + [InlineData((long)int.MaxValue + 1, false, Skip = "Failing on the CI")] public void LargeUpload(long contentLength, bool checkBytes) { const int bufferLength = 1024 * 1024; From 4544f881a2f42faba07a46166863771d2fcc8276 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Fri, 24 Feb 2017 09:48:44 -0800 Subject: [PATCH 1056/1662] Revert "Skipping failing tests to unblock CI" This reverts commit 0860981adacdb5510f7266b93d7b7781b6102e2b. --- .../RequestTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs index 7abd78a213..77ae582bfa 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs @@ -36,7 +36,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests // Never change to a lower value, otherwise regression testing for // https://github.com/aspnet/KestrelHttpServer/issues/520#issuecomment-188591242 // will be lost. - [InlineData((long)int.MaxValue + 1, false, Skip = "Failing on the CI")] + [InlineData((long)int.MaxValue + 1, false)] public void LargeUpload(long contentLength, bool checkBytes) { const int bufferLength = 1024 * 1024; From 19c3107debdf6ba65d9eb00996bf83a517b897b0 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Fri, 24 Feb 2017 10:03:32 -0800 Subject: [PATCH 1057/1662] Revert "Use Spans to parse the start line and headers (#1394)" This reverts commit 8140b8cdfe7638ecd40f8e88605d1dc0cc6df511. --- KestrelHttpServer.sln | 2 +- samples/SampleApp/SampleApp.csproj | 2 +- .../Internal/Http/Frame.cs | 309 ++++++------------ .../Internal/Http/FrameHeaders.Generated.cs | 225 ++++++------- .../Internal/Http/FrameRequestHeaders.cs | 9 - .../MemoryPoolIteratorExtensions.cs | 71 ---- ...Microsoft.AspNetCore.Server.Kestrel.csproj | 2 +- .../FrameRequestHeadersTests.cs | 2 +- .../FrameTests.cs | 2 +- tools/CodeGenerator/KnownHeaders.cs | 13 +- 10 files changed, 225 insertions(+), 412 deletions(-) diff --git a/KestrelHttpServer.sln b/KestrelHttpServer.sln index 24da20c0e0..d935b2d9b4 100644 --- a/KestrelHttpServer.sln +++ b/KestrelHttpServer.sln @@ -1,6 +1,6 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 15 -VisualStudioVersion = 15.0.26206.0 +VisualStudioVersion = 15.0.26213.1 MinimumVisualStudioVersion = 10.0.40219.1 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{7972A5D6-3385-4127-9277-428506DD44FF}" ProjectSection(SolutionItems) = preProject diff --git a/samples/SampleApp/SampleApp.csproj b/samples/SampleApp/SampleApp.csproj index 5fcf04fb03..9d5b086b5c 100644 --- a/samples/SampleApp/SampleApp.csproj +++ b/samples/SampleApp/SampleApp.csproj @@ -3,7 +3,7 @@ - netcoreapp1.1;net451 + net451;netcoreapp1.1 Exe win7-x64 diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs index 232e567a27..525dc56135 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs @@ -997,16 +997,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _requestProcessingStatus = RequestProcessingStatus.RequestStarted; - ReadableBuffer limitedBuffer; + var limitedBuffer = buffer; if (buffer.Length >= ServerOptions.Limits.MaxRequestLineSize) { limitedBuffer = buffer.Slice(0, ServerOptions.Limits.MaxRequestLineSize); } - else - { - limitedBuffer = buffer; - } - if (ReadCursorOperations.Seek(limitedBuffer.Start, limitedBuffer.End, out end, ByteLF) == -1) { if (limitedBuffer.Length == ServerOptions.Limits.MaxRequestLineSize) @@ -1019,46 +1014,17 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } } - const int stackAllocLimit = 512; - - // Move 1 byte past the \r - end = limitedBuffer.Move(end, 1); - var startLineBuffer = limitedBuffer.Slice(0, end); - - Span span; - - if (startLineBuffer.IsSingleSpan) + end = buffer.Move(end, 1); + ReadCursor methodEnd; + string method; + if (!buffer.GetKnownMethod(out method)) { - // No copies, directly use the one and only span - span = startLineBuffer.ToSpan(); - } - else if (startLineBuffer.Length < stackAllocLimit) - { - unsafe - { - // Multiple buffers and < stackAllocLimit, copy into a stack buffer - byte* stackBuffer = stackalloc byte[startLineBuffer.Length]; - span = new Span(stackBuffer, startLineBuffer.Length); - startLineBuffer.CopyTo(span); - } - } - else - { - // We're not a single span here but we can use pooled arrays to avoid allocations in the rare case - span = new Span(new byte[startLineBuffer.Length]); - startLineBuffer.CopyTo(span); - } - - var methodEnd = 0; - if (!span.GetKnownMethod(out string method)) - { - methodEnd = span.IndexOf(ByteSpace); - if (methodEnd == -1) + if (ReadCursorOperations.Seek(buffer.Start, end, out methodEnd, ByteSpace) == -1) { RejectRequestLine(start, end); } - method = span.Slice(0, methodEnd).GetAsciiString(); + method = buffer.Slice(buffer.Start, methodEnd).GetAsciiString(); if (method == null) { @@ -1077,67 +1043,57 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } else { - methodEnd += method.Length; + methodEnd = buffer.Slice(method.Length).Start; } var needDecode = false; - var pathBegin = methodEnd + 1; - var pathToEndSpan = span.Slice(pathBegin, span.Length - pathBegin); - pathBegin = 0; + ReadCursor pathEnd; - // TODO: IndexOfAny - var spaceIndex = pathToEndSpan.IndexOf(ByteSpace); - var questionMarkIndex = pathToEndSpan.IndexOf(ByteQuestionMark); - var percentageIndex = pathToEndSpan.IndexOf(BytePercentage); + var pathBegin = buffer.Move(methodEnd, 1); - var pathEnd = MinNonZero(spaceIndex, questionMarkIndex, percentageIndex); - - if (spaceIndex == -1 && questionMarkIndex == -1 && percentageIndex == -1) + var chFound = ReadCursorOperations.Seek(pathBegin, end, out pathEnd, ByteSpace, ByteQuestionMark, BytePercentage); + if (chFound == -1) { RejectRequestLine(start, end); } - else if (percentageIndex != -1) + else if (chFound == BytePercentage) { needDecode = true; - - pathEnd = MinNonZero(spaceIndex, questionMarkIndex); - if (questionMarkIndex == -1 && spaceIndex == -1) + chFound = ReadCursorOperations.Seek(pathBegin, end, out pathEnd, ByteSpace, ByteQuestionMark); + if (chFound == -1) { RejectRequestLine(start, end); } - } + }; var queryString = ""; - var queryEnd = pathEnd; - if (questionMarkIndex != -1) + ReadCursor queryEnd = pathEnd; + if (chFound == ByteQuestionMark) { - queryEnd = spaceIndex; - if (spaceIndex == -1) + if (ReadCursorOperations.Seek(pathEnd, end, out queryEnd, ByteSpace) == -1) { RejectRequestLine(start, end); } - - queryString = pathToEndSpan.Slice(pathEnd, queryEnd - pathEnd).GetAsciiString(); + queryString = buffer.Slice(pathEnd, queryEnd).GetAsciiString(); } + // No path if (pathBegin == pathEnd) { RejectRequestLine(start, end); } - var versionBegin = queryEnd + 1; - var versionToEndSpan = pathToEndSpan.Slice(versionBegin, pathToEndSpan.Length - versionBegin); - versionBegin = 0; - var versionEnd = versionToEndSpan.IndexOf(ByteCR); - - if (versionEnd == -1) + ReadCursor versionEnd; + if (ReadCursorOperations.Seek(queryEnd, end, out versionEnd, ByteCR) == -1) { RejectRequestLine(start, end); } - if (!versionToEndSpan.GetKnownVersion(out string httpVersion)) + string httpVersion; + var versionBuffer = buffer.Slice(queryEnd, end).Slice(1); + if (!versionBuffer.GetKnownVersion(out httpVersion)) { - httpVersion = versionToEndSpan.Slice(0, versionEnd).GetAsciiStringEscaped(); + httpVersion = versionBuffer.Start.GetAsciiStringEscaped(versionEnd, 9); if (httpVersion == string.Empty) { @@ -1149,13 +1105,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } } - if (versionToEndSpan[versionEnd + 1] != ByteLF) + var lineEnd = buffer.Slice(versionEnd, 2).ToSpan(); + if (lineEnd[1] != ByteLF) { RejectRequestLine(start, end); } - var pathBuffer = pathToEndSpan.Slice(pathBegin, pathEnd); - var targetBuffer = pathToEndSpan.Slice(pathBegin, queryEnd); + var pathBuffer = buffer.Slice(pathBegin, pathEnd); + var targetBuffer = buffer.Slice(pathBegin, queryEnd); // URIs are always encoded/escaped to ASCII https://tools.ietf.org/html/rfc3986#page-11 // Multibyte Internationalized Resource Identifiers (IRIs) are first converted to utf8; @@ -1168,7 +1125,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http rawTarget = targetBuffer.GetAsciiString() ?? string.Empty; // URI was encoded, unescape and then parse as utf8 - var pathSpan = pathBuffer; + var pathSpan = pathBuffer.ToSpan(); int pathLength = UrlEncoder.Decode(pathSpan, pathSpan); requestUrlPath = new Utf8String(pathSpan.Slice(0, pathLength)).ToString(); } @@ -1218,21 +1175,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http return true; } - private int MinNonZero(int v1, int v2) - { - v1 = v1 == -1 ? int.MaxValue : v1; - v2 = v2 == -1 ? int.MaxValue : v2; - return Math.Min(v1, v2); - } - - private int MinNonZero(int v1, int v2, int v3) - { - v1 = v1 == -1 ? int.MaxValue : v1; - v2 = v2 == -1 ? int.MaxValue : v2; - v3 = v3 == -1 ? int.MaxValue : v3; - return Math.Min(Math.Min(v1, v2), v3); - } - private void RejectRequestLine(ReadCursor start, ReadCursor end) { const int MaxRequestLineError = 32; @@ -1302,41 +1244,40 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http consumed = buffer.Start; examined = buffer.End; - var bufferLength = buffer.Length; - var reader = new ReadableBufferReader(buffer); - while (true) { - var start = reader; - int ch1 = reader.Take(); - var ch2 = reader.Take(); + var headersEnd = buffer.Slice(0, Math.Min(buffer.Length, 2)); + var headersEndSpan = headersEnd.ToSpan(); - if (ch1 == -1) + if (headersEndSpan.Length == 0) { return false; } - - if (ch1 == ByteCR) + else { - // Check for final CRLF. - if (ch2 == -1) + var ch = headersEndSpan[0]; + if (ch == ByteCR) { - return false; - } - else if (ch2 == ByteLF) - { - consumed = reader.Cursor; - examined = consumed; - ConnectionControl.CancelTimeout(); - return true; - } + // Check for final CRLF. + if (headersEndSpan.Length < 2) + { + return false; + } + else if (headersEndSpan[1] == ByteLF) + { + consumed = headersEnd.End; + examined = consumed; + ConnectionControl.CancelTimeout(); + return true; + } - // Headers don't end in CRLF line. - RejectRequest(RequestRejectionReason.HeadersCorruptedInvalidHeaderSequence); - } - else if (ch1 == ByteSpace || ch1 == ByteTab) - { - RejectRequest(RequestRejectionReason.HeaderLineMustNotStartWithWhitespace); + // Headers don't end in CRLF line. + RejectRequest(RequestRejectionReason.HeadersCorruptedInvalidHeaderSequence); + } + else if (ch == ByteSpace || ch == ByteTab) + { + RejectRequest(RequestRejectionReason.HeaderLineMustNotStartWithWhitespace); + } } // If we've parsed the max allowed numbers of headers and we're starting a new @@ -1346,30 +1287,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http RejectRequest(RequestRejectionReason.TooManyHeaders); } - // Reset the reader since we're not at the end of headers - reader = start; - - // Now parse a single header - ReadableBuffer limitedBuffer; - var overLength = false; - - if (bufferLength >= _remainingRequestHeadersBytesAllowed) + ReadCursor lineEnd; + var limitedBuffer = buffer; + if (buffer.Length >= _remainingRequestHeadersBytesAllowed) { - limitedBuffer = buffer.Slice(consumed, _remainingRequestHeadersBytesAllowed); - - // If we sliced it means the current buffer bigger than what we're - // allowed to look at - overLength = true; + limitedBuffer = buffer.Slice(0, _remainingRequestHeadersBytesAllowed); } - else + if (ReadCursorOperations.Seek(limitedBuffer.Start, limitedBuffer.End, out lineEnd, ByteLF) == -1) { - limitedBuffer = buffer; - } - - if (ReadCursorOperations.Seek(consumed, limitedBuffer.End, out var lineEnd, ByteLF) == -1) - { - // We didn't find a \n in the current buffer and we had to slice it so it's an issue - if (overLength) + if (limitedBuffer.Length == _remainingRequestHeadersBytesAllowed) { RejectRequest(RequestRejectionReason.HeadersExceedMaxTotalSize); } @@ -1379,94 +1305,39 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } } - const int stackAllocLimit = 512; - - if (lineEnd != limitedBuffer.End) - { - lineEnd = limitedBuffer.Move(lineEnd, 1); - } - - var headerBuffer = limitedBuffer.Slice(consumed, lineEnd); - - Span span; - if (headerBuffer.IsSingleSpan) - { - // No copies, directly use the one and only span - span = headerBuffer.ToSpan(); - } - else if (headerBuffer.Length < stackAllocLimit) - { - unsafe - { - // Multiple buffers and < stackAllocLimit, copy into a stack buffer - byte* stackBuffer = stackalloc byte[headerBuffer.Length]; - span = new Span(stackBuffer, headerBuffer.Length); - headerBuffer.CopyTo(span); - } - } - else - { - // We're not a single span here but we can use pooled arrays to avoid allocations in the rare case - span = new Span(new byte[headerBuffer.Length]); - headerBuffer.CopyTo(span); - } - - int endNameIndex = span.IndexOf(ByteColon); - if (endNameIndex == -1) + var beginName = buffer.Start; + ReadCursor endName; + if (ReadCursorOperations.Seek(buffer.Start, lineEnd, out endName, ByteColon) == -1) { RejectRequest(RequestRejectionReason.NoColonCharacterFoundInHeaderLine); } - var nameBuffer = span.Slice(0, endNameIndex); - if (nameBuffer.IndexOf(ByteSpace) != -1 || nameBuffer.IndexOf(ByteTab) != -1) + ReadCursor whitespace; + if (ReadCursorOperations.Seek(beginName, endName, out whitespace, ByteTab, ByteSpace) != -1) { RejectRequest(RequestRejectionReason.WhitespaceIsNotAllowedInHeaderName); } - int endValueIndex = span.IndexOf(ByteCR); - if (endValueIndex == -1) + ReadCursor endValue; + if (ReadCursorOperations.Seek(beginName, lineEnd, out endValue, ByteCR) == -1) { RejectRequest(RequestRejectionReason.MissingCRInHeaderLine); } - var lineSuffix = span.Slice(endValueIndex); - if (lineSuffix.Length < 2) + var lineSufix = buffer.Slice(endValue); + if (lineSufix.Length < 3) { return false; } - + lineSufix = lineSufix.Slice(0, 3); // \r\n\r + var lineSufixSpan = lineSufix.ToSpan(); // This check and MissingCRInHeaderLine is a bit backwards, we should do it at once instead of having another seek - if (lineSuffix[1] != ByteLF) + if (lineSufixSpan[1] != ByteLF) { RejectRequest(RequestRejectionReason.HeaderValueMustNotContainCR); } - // Trim trailing whitespace from header value by repeatedly advancing to next - // whitespace or CR. - // - // - If CR is found, this is the end of the header value. - // - If whitespace is found, this is the _tentative_ end of the header value. - // If non-whitespace is found after it and it's not CR, seek again to the next - // whitespace or CR for a new (possibly tentative) end of value. - - var valueBuffer = span.Slice(endNameIndex + 1, endValueIndex - (endNameIndex + 1)); - - // TODO: Trim else where - var value = valueBuffer.GetAsciiString()?.Trim() ?? string.Empty; - - var headerLineLength = span.Length; - - // -1 so that we can re-check the extra \r - reader.Skip(headerLineLength); - - var next = reader.Peek(); - - // We cant check for line continuations to reject everything we've done so far - if (next == -1) - { - return false; - } - + var next = lineSufixSpan[2]; if (next == ByteSpace || next == ByteTab) { // From https://tools.ietf.org/html/rfc7230#section-3.2.4: @@ -1489,15 +1360,31 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http RejectRequest(RequestRejectionReason.HeaderValueLineFoldingNotSupported); } - // Update the frame state only after we know there's no header line continuation - _remainingRequestHeadersBytesAllowed -= headerLineLength; - bufferLength -= headerLineLength; + // Trim trailing whitespace from header value by repeatedly advancing to next + // whitespace or CR. + // + // - If CR is found, this is the end of the header value. + // - If whitespace is found, this is the _tentative_ end of the header value. + // If non-whitespace is found after it and it's not CR, seek again to the next + // whitespace or CR for a new (possibly tentative) end of value. + var nameBuffer = buffer.Slice(beginName, endName); + + // TODO: TrimStart and TrimEnd are pretty slow + var valueBuffer = buffer.Slice(endName, endValue).Slice(1).TrimStart().TrimEnd(); + + var name = nameBuffer.ToArraySegment(); + var value = valueBuffer.GetAsciiString(); + + lineEnd = limitedBuffer.Move(lineEnd, 1); + + // TODO: bad + _remainingRequestHeadersBytesAllowed -= buffer.Slice(0, lineEnd).Length; _requestHeadersParsed++; - requestHeaders.Append(nameBuffer, value); - - consumed = reader.Cursor; + requestHeaders.Append(name.Array, name.Offset, name.Count, value); + buffer = buffer.Slice(lineEnd); + consumed = buffer.Start; } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameHeaders.Generated.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameHeaders.Generated.cs index 051b6b5737..7cfb64ff31 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameHeaders.Generated.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameHeaders.Generated.cs @@ -3501,10 +3501,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } - public unsafe void Append(byte* pKeyBytes, int keyLength, string value) + public unsafe void Append(byte[] keyBytes, int keyOffset, int keyLength, string value) { - var pUB = pKeyBytes; - var pUL = (ulong*)pUB; + fixed (byte* ptr = &keyBytes[keyOffset]) + { + var pUB = ptr; + var pUL = (ulong*)pUB; var pUI = (uint*)pUB; var pUS = (ushort*)pUB; var stringValue = new StringValues(value); @@ -3565,10 +3567,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http break; } - AppendNonPrimaryHeaders(pKeyBytes, keyLength, value); + AppendNonPrimaryHeaders(ptr, keyOffset, keyLength, value); + } } - - private unsafe void AppendNonPrimaryHeaders(byte* pKeyBytes, int keyLength, string value) + + private unsafe void AppendNonPrimaryHeaders(byte* pKeyBytes, int keyOffset, int keyLength, string value) { var pUB = pKeyBytes; var pUL = (ulong*)pUB; @@ -7764,10 +7767,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } else { - var valueCount = _headers._Connection.Count; - for (var i = 0; i < valueCount; i++) + var valueCount = _headers._Connection.Count; + for (var i = 0; i < valueCount; i++) { - var value = _headers._Connection[i]; + var value = _headers._Connection[i]; if (value != null) { output.CopyFrom(_headerBytes, 17, 14); @@ -7790,10 +7793,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } else { - var valueCount = _headers._Date.Count; - for (var i = 0; i < valueCount; i++) + var valueCount = _headers._Date.Count; + for (var i = 0; i < valueCount; i++) { - var value = _headers._Date[i]; + var value = _headers._Date[i]; if (value != null) { output.CopyFrom(_headerBytes, 31, 8); @@ -7811,10 +7814,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if ((tempBits & 2048L) != 0) { { - var valueCount = _headers._ContentType.Count; - for (var i = 0; i < valueCount; i++) + var valueCount = _headers._ContentType.Count; + for (var i = 0; i < valueCount; i++) { - var value = _headers._ContentType[i]; + var value = _headers._ContentType[i]; if (value != null) { output.CopyFrom(_headerBytes, 133, 16); @@ -7837,10 +7840,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } else { - var valueCount = _headers._Server.Count; - for (var i = 0; i < valueCount; i++) + var valueCount = _headers._Server.Count; + for (var i = 0; i < valueCount; i++) { - var value = _headers._Server[i]; + var value = _headers._Server[i]; if (value != null) { output.CopyFrom(_headerBytes, 350, 10); @@ -7869,10 +7872,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if ((tempBits & 1L) != 0) { { - var valueCount = _headers._CacheControl.Count; - for (var i = 0; i < valueCount; i++) + var valueCount = _headers._CacheControl.Count; + for (var i = 0; i < valueCount; i++) { - var value = _headers._CacheControl[i]; + var value = _headers._CacheControl[i]; if (value != null) { output.CopyFrom(_headerBytes, 0, 17); @@ -7890,10 +7893,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if ((tempBits & 8L) != 0) { { - var valueCount = _headers._KeepAlive.Count; - for (var i = 0; i < valueCount; i++) + var valueCount = _headers._KeepAlive.Count; + for (var i = 0; i < valueCount; i++) { - var value = _headers._KeepAlive[i]; + var value = _headers._KeepAlive[i]; if (value != null) { output.CopyFrom(_headerBytes, 39, 14); @@ -7911,10 +7914,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if ((tempBits & 16L) != 0) { { - var valueCount = _headers._Pragma.Count; - for (var i = 0; i < valueCount; i++) + var valueCount = _headers._Pragma.Count; + for (var i = 0; i < valueCount; i++) { - var value = _headers._Pragma[i]; + var value = _headers._Pragma[i]; if (value != null) { output.CopyFrom(_headerBytes, 53, 10); @@ -7932,10 +7935,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if ((tempBits & 32L) != 0) { { - var valueCount = _headers._Trailer.Count; - for (var i = 0; i < valueCount; i++) + var valueCount = _headers._Trailer.Count; + for (var i = 0; i < valueCount; i++) { - var value = _headers._Trailer[i]; + var value = _headers._Trailer[i]; if (value != null) { output.CopyFrom(_headerBytes, 63, 11); @@ -7958,10 +7961,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } else { - var valueCount = _headers._TransferEncoding.Count; - for (var i = 0; i < valueCount; i++) + var valueCount = _headers._TransferEncoding.Count; + for (var i = 0; i < valueCount; i++) { - var value = _headers._TransferEncoding[i]; + var value = _headers._TransferEncoding[i]; if (value != null) { output.CopyFrom(_headerBytes, 74, 21); @@ -7979,10 +7982,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if ((tempBits & 128L) != 0) { { - var valueCount = _headers._Upgrade.Count; - for (var i = 0; i < valueCount; i++) + var valueCount = _headers._Upgrade.Count; + for (var i = 0; i < valueCount; i++) { - var value = _headers._Upgrade[i]; + var value = _headers._Upgrade[i]; if (value != null) { output.CopyFrom(_headerBytes, 95, 11); @@ -8000,10 +8003,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if ((tempBits & 256L) != 0) { { - var valueCount = _headers._Via.Count; - for (var i = 0; i < valueCount; i++) + var valueCount = _headers._Via.Count; + for (var i = 0; i < valueCount; i++) { - var value = _headers._Via[i]; + var value = _headers._Via[i]; if (value != null) { output.CopyFrom(_headerBytes, 106, 7); @@ -8021,10 +8024,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if ((tempBits & 512L) != 0) { { - var valueCount = _headers._Warning.Count; - for (var i = 0; i < valueCount; i++) + var valueCount = _headers._Warning.Count; + for (var i = 0; i < valueCount; i++) { - var value = _headers._Warning[i]; + var value = _headers._Warning[i]; if (value != null) { output.CopyFrom(_headerBytes, 113, 11); @@ -8042,10 +8045,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if ((tempBits & 1024L) != 0) { { - var valueCount = _headers._Allow.Count; - for (var i = 0; i < valueCount; i++) + var valueCount = _headers._Allow.Count; + for (var i = 0; i < valueCount; i++) { - var value = _headers._Allow[i]; + var value = _headers._Allow[i]; if (value != null) { output.CopyFrom(_headerBytes, 124, 9); @@ -8063,10 +8066,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if ((tempBits & 4096L) != 0) { { - var valueCount = _headers._ContentEncoding.Count; - for (var i = 0; i < valueCount; i++) + var valueCount = _headers._ContentEncoding.Count; + for (var i = 0; i < valueCount; i++) { - var value = _headers._ContentEncoding[i]; + var value = _headers._ContentEncoding[i]; if (value != null) { output.CopyFrom(_headerBytes, 149, 20); @@ -8084,10 +8087,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if ((tempBits & 8192L) != 0) { { - var valueCount = _headers._ContentLanguage.Count; - for (var i = 0; i < valueCount; i++) + var valueCount = _headers._ContentLanguage.Count; + for (var i = 0; i < valueCount; i++) { - var value = _headers._ContentLanguage[i]; + var value = _headers._ContentLanguage[i]; if (value != null) { output.CopyFrom(_headerBytes, 169, 20); @@ -8105,10 +8108,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if ((tempBits & 16384L) != 0) { { - var valueCount = _headers._ContentLocation.Count; - for (var i = 0; i < valueCount; i++) + var valueCount = _headers._ContentLocation.Count; + for (var i = 0; i < valueCount; i++) { - var value = _headers._ContentLocation[i]; + var value = _headers._ContentLocation[i]; if (value != null) { output.CopyFrom(_headerBytes, 189, 20); @@ -8126,10 +8129,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if ((tempBits & 32768L) != 0) { { - var valueCount = _headers._ContentMD5.Count; - for (var i = 0; i < valueCount; i++) + var valueCount = _headers._ContentMD5.Count; + for (var i = 0; i < valueCount; i++) { - var value = _headers._ContentMD5[i]; + var value = _headers._ContentMD5[i]; if (value != null) { output.CopyFrom(_headerBytes, 209, 15); @@ -8147,10 +8150,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if ((tempBits & 65536L) != 0) { { - var valueCount = _headers._ContentRange.Count; - for (var i = 0; i < valueCount; i++) + var valueCount = _headers._ContentRange.Count; + for (var i = 0; i < valueCount; i++) { - var value = _headers._ContentRange[i]; + var value = _headers._ContentRange[i]; if (value != null) { output.CopyFrom(_headerBytes, 224, 17); @@ -8168,10 +8171,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if ((tempBits & 131072L) != 0) { { - var valueCount = _headers._Expires.Count; - for (var i = 0; i < valueCount; i++) + var valueCount = _headers._Expires.Count; + for (var i = 0; i < valueCount; i++) { - var value = _headers._Expires[i]; + var value = _headers._Expires[i]; if (value != null) { output.CopyFrom(_headerBytes, 241, 11); @@ -8189,10 +8192,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if ((tempBits & 262144L) != 0) { { - var valueCount = _headers._LastModified.Count; - for (var i = 0; i < valueCount; i++) + var valueCount = _headers._LastModified.Count; + for (var i = 0; i < valueCount; i++) { - var value = _headers._LastModified[i]; + var value = _headers._LastModified[i]; if (value != null) { output.CopyFrom(_headerBytes, 252, 17); @@ -8210,10 +8213,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if ((tempBits & 524288L) != 0) { { - var valueCount = _headers._AcceptRanges.Count; - for (var i = 0; i < valueCount; i++) + var valueCount = _headers._AcceptRanges.Count; + for (var i = 0; i < valueCount; i++) { - var value = _headers._AcceptRanges[i]; + var value = _headers._AcceptRanges[i]; if (value != null) { output.CopyFrom(_headerBytes, 269, 17); @@ -8231,10 +8234,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if ((tempBits & 1048576L) != 0) { { - var valueCount = _headers._Age.Count; - for (var i = 0; i < valueCount; i++) + var valueCount = _headers._Age.Count; + for (var i = 0; i < valueCount; i++) { - var value = _headers._Age[i]; + var value = _headers._Age[i]; if (value != null) { output.CopyFrom(_headerBytes, 286, 7); @@ -8252,10 +8255,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if ((tempBits & 2097152L) != 0) { { - var valueCount = _headers._ETag.Count; - for (var i = 0; i < valueCount; i++) + var valueCount = _headers._ETag.Count; + for (var i = 0; i < valueCount; i++) { - var value = _headers._ETag[i]; + var value = _headers._ETag[i]; if (value != null) { output.CopyFrom(_headerBytes, 293, 8); @@ -8273,10 +8276,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if ((tempBits & 4194304L) != 0) { { - var valueCount = _headers._Location.Count; - for (var i = 0; i < valueCount; i++) + var valueCount = _headers._Location.Count; + for (var i = 0; i < valueCount; i++) { - var value = _headers._Location[i]; + var value = _headers._Location[i]; if (value != null) { output.CopyFrom(_headerBytes, 301, 12); @@ -8294,10 +8297,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if ((tempBits & 8388608L) != 0) { { - var valueCount = _headers._ProxyAuthenticate.Count; - for (var i = 0; i < valueCount; i++) + var valueCount = _headers._ProxyAuthenticate.Count; + for (var i = 0; i < valueCount; i++) { - var value = _headers._ProxyAuthenticate[i]; + var value = _headers._ProxyAuthenticate[i]; if (value != null) { output.CopyFrom(_headerBytes, 313, 22); @@ -8315,10 +8318,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if ((tempBits & 16777216L) != 0) { { - var valueCount = _headers._RetryAfter.Count; - for (var i = 0; i < valueCount; i++) + var valueCount = _headers._RetryAfter.Count; + for (var i = 0; i < valueCount; i++) { - var value = _headers._RetryAfter[i]; + var value = _headers._RetryAfter[i]; if (value != null) { output.CopyFrom(_headerBytes, 335, 15); @@ -8336,10 +8339,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if ((tempBits & 67108864L) != 0) { { - var valueCount = _headers._SetCookie.Count; - for (var i = 0; i < valueCount; i++) + var valueCount = _headers._SetCookie.Count; + for (var i = 0; i < valueCount; i++) { - var value = _headers._SetCookie[i]; + var value = _headers._SetCookie[i]; if (value != null) { output.CopyFrom(_headerBytes, 360, 14); @@ -8357,10 +8360,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if ((tempBits & 134217728L) != 0) { { - var valueCount = _headers._Vary.Count; - for (var i = 0; i < valueCount; i++) + var valueCount = _headers._Vary.Count; + for (var i = 0; i < valueCount; i++) { - var value = _headers._Vary[i]; + var value = _headers._Vary[i]; if (value != null) { output.CopyFrom(_headerBytes, 374, 8); @@ -8378,10 +8381,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if ((tempBits & 268435456L) != 0) { { - var valueCount = _headers._WWWAuthenticate.Count; - for (var i = 0; i < valueCount; i++) + var valueCount = _headers._WWWAuthenticate.Count; + for (var i = 0; i < valueCount; i++) { - var value = _headers._WWWAuthenticate[i]; + var value = _headers._WWWAuthenticate[i]; if (value != null) { output.CopyFrom(_headerBytes, 382, 20); @@ -8399,10 +8402,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if ((tempBits & 536870912L) != 0) { { - var valueCount = _headers._AccessControlAllowCredentials.Count; - for (var i = 0; i < valueCount; i++) + var valueCount = _headers._AccessControlAllowCredentials.Count; + for (var i = 0; i < valueCount; i++) { - var value = _headers._AccessControlAllowCredentials[i]; + var value = _headers._AccessControlAllowCredentials[i]; if (value != null) { output.CopyFrom(_headerBytes, 402, 36); @@ -8420,10 +8423,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if ((tempBits & 1073741824L) != 0) { { - var valueCount = _headers._AccessControlAllowHeaders.Count; - for (var i = 0; i < valueCount; i++) + var valueCount = _headers._AccessControlAllowHeaders.Count; + for (var i = 0; i < valueCount; i++) { - var value = _headers._AccessControlAllowHeaders[i]; + var value = _headers._AccessControlAllowHeaders[i]; if (value != null) { output.CopyFrom(_headerBytes, 438, 32); @@ -8441,10 +8444,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if ((tempBits & 2147483648L) != 0) { { - var valueCount = _headers._AccessControlAllowMethods.Count; - for (var i = 0; i < valueCount; i++) + var valueCount = _headers._AccessControlAllowMethods.Count; + for (var i = 0; i < valueCount; i++) { - var value = _headers._AccessControlAllowMethods[i]; + var value = _headers._AccessControlAllowMethods[i]; if (value != null) { output.CopyFrom(_headerBytes, 470, 32); @@ -8462,10 +8465,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if ((tempBits & 4294967296L) != 0) { { - var valueCount = _headers._AccessControlAllowOrigin.Count; - for (var i = 0; i < valueCount; i++) + var valueCount = _headers._AccessControlAllowOrigin.Count; + for (var i = 0; i < valueCount; i++) { - var value = _headers._AccessControlAllowOrigin[i]; + var value = _headers._AccessControlAllowOrigin[i]; if (value != null) { output.CopyFrom(_headerBytes, 502, 31); @@ -8483,10 +8486,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if ((tempBits & 8589934592L) != 0) { { - var valueCount = _headers._AccessControlExposeHeaders.Count; - for (var i = 0; i < valueCount; i++) + var valueCount = _headers._AccessControlExposeHeaders.Count; + for (var i = 0; i < valueCount; i++) { - var value = _headers._AccessControlExposeHeaders[i]; + var value = _headers._AccessControlExposeHeaders[i]; if (value != null) { output.CopyFrom(_headerBytes, 533, 33); @@ -8504,10 +8507,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if ((tempBits & 17179869184L) != 0) { { - var valueCount = _headers._AccessControlMaxAge.Count; - for (var i = 0; i < valueCount; i++) + var valueCount = _headers._AccessControlMaxAge.Count; + for (var i = 0; i < valueCount; i++) { - var value = _headers._AccessControlMaxAge[i]; + var value = _headers._AccessControlMaxAge[i]; if (value != null) { output.CopyFrom(_headerBytes, 566, 26); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameRequestHeaders.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameRequestHeaders.cs index ca6496d320..4dd46d5cf1 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameRequestHeaders.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameRequestHeaders.cs @@ -1,7 +1,6 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System; using System.Collections; using System.Collections.Generic; using System.Runtime.CompilerServices; @@ -30,14 +29,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http Unknown[key] = value; } - public unsafe void Append(Span name, string value) - { - fixed (byte* namePtr = &name.DangerousGetPinnableReference()) - { - Append(namePtr, name.Length, value); - } - } - [MethodImpl(MethodImplOptions.NoInlining)] private unsafe void AppendUnknownHeaders(byte* pKeyBytes, int keyLength, string value) { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolIteratorExtensions.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolIteratorExtensions.cs index 95c3c5a59f..94cf66ef7b 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolIteratorExtensions.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolIteratorExtensions.cs @@ -90,19 +90,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure return sb.ToString(); } - public static string GetAsciiStringEscaped(this Span span) - { - var sb = new StringBuilder(); - - for (var i = 0; i < span.Length; ++i) - { - var ch = span[i]; - sb.Append(ch < 0x20 || ch >= 0x7F ? $"<0x{ch:X2}>" : ((char)ch).ToString()); - } - - return sb.ToString(); - } - public static ArraySegment PeekArraySegment(this MemoryPoolIterator iter) { if (iter.IsDefault || iter.IsEnd) @@ -170,33 +157,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure return false; } - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static bool GetKnownMethod(this Span span, out string knownMethod) - { - knownMethod = null; - if (span.Length < sizeof(ulong)) - { - return false; - } - - ulong value = span.Read(); - if ((value & _mask4Chars) == _httpGetMethodLong) - { - knownMethod = HttpMethods.Get; - return true; - } - foreach (var x in _knownMethods) - { - if ((value & x.Item1) == x.Item2) - { - knownMethod = x.Item3; - return true; - } - } - - return false; - } - /// /// Checks 9 bytes from correspond to a known HTTP version. /// @@ -240,36 +200,5 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure return knownVersion != null; } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static bool GetKnownVersion(this Span span, out string knownVersion) - { - knownVersion = null; - - if (span.Length < sizeof(ulong)) - { - return false; - } - - var value = span.Read(); - if (value == _http11VersionLong) - { - knownVersion = Http11Version; - } - else if (value == _http10VersionLong) - { - knownVersion = Http10Version; - } - - if (knownVersion != null) - { - if (span[sizeof(ulong)] != (byte)'\r') - { - knownVersion = null; - } - } - - return knownVersion != null; - } } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Microsoft.AspNetCore.Server.Kestrel.csproj b/src/Microsoft.AspNetCore.Server.Kestrel/Microsoft.AspNetCore.Server.Kestrel.csproj index 5dd7b984c9..c62c37e231 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Microsoft.AspNetCore.Server.Kestrel.csproj +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Microsoft.AspNetCore.Server.Kestrel.csproj @@ -30,4 +30,4 @@ - \ No newline at end of file + diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameRequestHeadersTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameRequestHeadersTests.cs index dbf6d857a5..91212d627b 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameRequestHeadersTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameRequestHeadersTests.cs @@ -311,7 +311,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var encoding = Encoding.GetEncoding("iso-8859-1"); var exception = Assert.Throws( - () => headers.Append(encoding.GetBytes(key), key)); + () => headers.Append(encoding.GetBytes(key), 0, encoding.GetByteCount(key), key)); Assert.Equal(StatusCodes.Status400BadRequest, exception.StatusCode); } } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs index 3edb7fad3d..bf6fc9c78b 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs @@ -611,7 +611,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var exception = Assert.Throws(() => _frame.TakeStartLine(readableBuffer, out consumed, out examined)); _socketInput.Reader.Advance(consumed, examined); - Assert.Equal("Unrecognized HTTP version: HTTP/1.1ab", exception.Message); + Assert.Equal("Unrecognized HTTP version: HTTP/1.1a...", exception.Message); Assert.Equal(StatusCodes.Status505HttpVersionNotsupported, exception.StatusCode); } diff --git a/tools/CodeGenerator/KnownHeaders.cs b/tools/CodeGenerator/KnownHeaders.cs index a211013404..0e2fdf858f 100644 --- a/tools/CodeGenerator/KnownHeaders.cs +++ b/tools/CodeGenerator/KnownHeaders.cs @@ -564,15 +564,18 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http }}" : "")}")} }}" : "")} {(loop.ClassName == "FrameRequestHeaders" ? $@" - public unsafe void Append(byte* pKeyBytes, int keyLength, string value) + public unsafe void Append(byte[] keyBytes, int keyOffset, int keyLength, string value) {{ - var pUB = pKeyBytes; - {AppendSwitch(loop.Headers.Where(h => h.PrimaryHeader).GroupBy(x => x.Name.Length), loop.ClassName)} + fixed (byte* ptr = &keyBytes[keyOffset]) + {{ + var pUB = ptr; + {AppendSwitch(loop.Headers.Where(h => h.PrimaryHeader).GroupBy(x => x.Name.Length), loop.ClassName)} - AppendNonPrimaryHeaders(pKeyBytes, keyLength, value); + AppendNonPrimaryHeaders(ptr, keyOffset, keyLength, value); + }} }} - private unsafe void AppendNonPrimaryHeaders(byte* pKeyBytes, int keyLength, string value) + private unsafe void AppendNonPrimaryHeaders(byte* pKeyBytes, int keyOffset, int keyLength, string value) {{ var pUB = pKeyBytes; {AppendSwitch(loop.Headers.Where(h => !h.PrimaryHeader).GroupBy(x => x.Name.Length), loop.ClassName)} From 5692f51bf72c82d480a13f9f4282a3e84739e954 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Fri, 24 Feb 2017 10:22:05 -0800 Subject: [PATCH 1058/1662] Revert "Revert "Use Spans to parse the start line and headers (#1394)"" This reverts commit 19c3107debdf6ba65d9eb00996bf83a517b897b0. --- KestrelHttpServer.sln | 2 +- samples/SampleApp/SampleApp.csproj | 2 +- .../Internal/Http/Frame.cs | 319 ++++++++++++------ .../Internal/Http/FrameHeaders.Generated.cs | 225 ++++++------ .../Internal/Http/FrameRequestHeaders.cs | 9 + .../MemoryPoolIteratorExtensions.cs | 71 ++++ ...Microsoft.AspNetCore.Server.Kestrel.csproj | 2 +- .../FrameRequestHeadersTests.cs | 2 +- .../FrameTests.cs | 2 +- tools/CodeGenerator/KnownHeaders.cs | 13 +- 10 files changed, 417 insertions(+), 230 deletions(-) diff --git a/KestrelHttpServer.sln b/KestrelHttpServer.sln index d935b2d9b4..24da20c0e0 100644 --- a/KestrelHttpServer.sln +++ b/KestrelHttpServer.sln @@ -1,6 +1,6 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 15 -VisualStudioVersion = 15.0.26213.1 +VisualStudioVersion = 15.0.26206.0 MinimumVisualStudioVersion = 10.0.40219.1 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{7972A5D6-3385-4127-9277-428506DD44FF}" ProjectSection(SolutionItems) = preProject diff --git a/samples/SampleApp/SampleApp.csproj b/samples/SampleApp/SampleApp.csproj index 9d5b086b5c..5fcf04fb03 100644 --- a/samples/SampleApp/SampleApp.csproj +++ b/samples/SampleApp/SampleApp.csproj @@ -3,7 +3,7 @@ - net451;netcoreapp1.1 + netcoreapp1.1;net451 Exe win7-x64 diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs index 525dc56135..232e567a27 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs @@ -997,11 +997,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _requestProcessingStatus = RequestProcessingStatus.RequestStarted; - var limitedBuffer = buffer; + ReadableBuffer limitedBuffer; if (buffer.Length >= ServerOptions.Limits.MaxRequestLineSize) { limitedBuffer = buffer.Slice(0, ServerOptions.Limits.MaxRequestLineSize); } + else + { + limitedBuffer = buffer; + } + if (ReadCursorOperations.Seek(limitedBuffer.Start, limitedBuffer.End, out end, ByteLF) == -1) { if (limitedBuffer.Length == ServerOptions.Limits.MaxRequestLineSize) @@ -1014,17 +1019,46 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } } - end = buffer.Move(end, 1); - ReadCursor methodEnd; - string method; - if (!buffer.GetKnownMethod(out method)) + const int stackAllocLimit = 512; + + // Move 1 byte past the \r + end = limitedBuffer.Move(end, 1); + var startLineBuffer = limitedBuffer.Slice(0, end); + + Span span; + + if (startLineBuffer.IsSingleSpan) { - if (ReadCursorOperations.Seek(buffer.Start, end, out methodEnd, ByteSpace) == -1) + // No copies, directly use the one and only span + span = startLineBuffer.ToSpan(); + } + else if (startLineBuffer.Length < stackAllocLimit) + { + unsafe + { + // Multiple buffers and < stackAllocLimit, copy into a stack buffer + byte* stackBuffer = stackalloc byte[startLineBuffer.Length]; + span = new Span(stackBuffer, startLineBuffer.Length); + startLineBuffer.CopyTo(span); + } + } + else + { + // We're not a single span here but we can use pooled arrays to avoid allocations in the rare case + span = new Span(new byte[startLineBuffer.Length]); + startLineBuffer.CopyTo(span); + } + + var methodEnd = 0; + if (!span.GetKnownMethod(out string method)) + { + methodEnd = span.IndexOf(ByteSpace); + if (methodEnd == -1) { RejectRequestLine(start, end); } - method = buffer.Slice(buffer.Start, methodEnd).GetAsciiString(); + method = span.Slice(0, methodEnd).GetAsciiString(); if (method == null) { @@ -1043,57 +1077,67 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } else { - methodEnd = buffer.Slice(method.Length).Start; + methodEnd += method.Length; } var needDecode = false; - ReadCursor pathEnd; + var pathBegin = methodEnd + 1; + var pathToEndSpan = span.Slice(pathBegin, span.Length - pathBegin); + pathBegin = 0; - var pathBegin = buffer.Move(methodEnd, 1); + // TODO: IndexOfAny + var spaceIndex = pathToEndSpan.IndexOf(ByteSpace); + var questionMarkIndex = pathToEndSpan.IndexOf(ByteQuestionMark); + var percentageIndex = pathToEndSpan.IndexOf(BytePercentage); - var chFound = ReadCursorOperations.Seek(pathBegin, end, out pathEnd, ByteSpace, ByteQuestionMark, BytePercentage); - if (chFound == -1) + var pathEnd = MinNonZero(spaceIndex, questionMarkIndex, percentageIndex); + + if (spaceIndex == -1 && questionMarkIndex == -1 && percentageIndex == -1) { RejectRequestLine(start, end); } - else if (chFound == BytePercentage) + else if (percentageIndex != -1) { needDecode = true; - chFound = ReadCursorOperations.Seek(pathBegin, end, out pathEnd, ByteSpace, ByteQuestionMark); - if (chFound == -1) - { - RejectRequestLine(start, end); - } - }; - var queryString = ""; - ReadCursor queryEnd = pathEnd; - if (chFound == ByteQuestionMark) - { - if (ReadCursorOperations.Seek(pathEnd, end, out queryEnd, ByteSpace) == -1) + pathEnd = MinNonZero(spaceIndex, questionMarkIndex); + if (questionMarkIndex == -1 && spaceIndex == -1) { RejectRequestLine(start, end); } - queryString = buffer.Slice(pathEnd, queryEnd).GetAsciiString(); } - // No path + var queryString = ""; + var queryEnd = pathEnd; + if (questionMarkIndex != -1) + { + queryEnd = spaceIndex; + if (spaceIndex == -1) + { + RejectRequestLine(start, end); + } + + queryString = pathToEndSpan.Slice(pathEnd, queryEnd - pathEnd).GetAsciiString(); + } + if (pathBegin == pathEnd) { RejectRequestLine(start, end); } - ReadCursor versionEnd; - if (ReadCursorOperations.Seek(queryEnd, end, out versionEnd, ByteCR) == -1) + var versionBegin = queryEnd + 1; + var versionToEndSpan = pathToEndSpan.Slice(versionBegin, pathToEndSpan.Length - versionBegin); + versionBegin = 0; + var versionEnd = versionToEndSpan.IndexOf(ByteCR); + + if (versionEnd == -1) { RejectRequestLine(start, end); } - string httpVersion; - var versionBuffer = buffer.Slice(queryEnd, end).Slice(1); - if (!versionBuffer.GetKnownVersion(out httpVersion)) + if (!versionToEndSpan.GetKnownVersion(out string httpVersion)) { - httpVersion = versionBuffer.Start.GetAsciiStringEscaped(versionEnd, 9); + httpVersion = versionToEndSpan.Slice(0, versionEnd).GetAsciiStringEscaped(); if (httpVersion == string.Empty) { @@ -1105,14 +1149,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } } - var lineEnd = buffer.Slice(versionEnd, 2).ToSpan(); - if (lineEnd[1] != ByteLF) + if (versionToEndSpan[versionEnd + 1] != ByteLF) { RejectRequestLine(start, end); } - var pathBuffer = buffer.Slice(pathBegin, pathEnd); - var targetBuffer = buffer.Slice(pathBegin, queryEnd); + var pathBuffer = pathToEndSpan.Slice(pathBegin, pathEnd); + var targetBuffer = pathToEndSpan.Slice(pathBegin, queryEnd); // URIs are always encoded/escaped to ASCII https://tools.ietf.org/html/rfc3986#page-11 // Multibyte Internationalized Resource Identifiers (IRIs) are first converted to utf8; @@ -1125,7 +1168,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http rawTarget = targetBuffer.GetAsciiString() ?? string.Empty; // URI was encoded, unescape and then parse as utf8 - var pathSpan = pathBuffer.ToSpan(); + var pathSpan = pathBuffer; int pathLength = UrlEncoder.Decode(pathSpan, pathSpan); requestUrlPath = new Utf8String(pathSpan.Slice(0, pathLength)).ToString(); } @@ -1175,6 +1218,21 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http return true; } + private int MinNonZero(int v1, int v2) + { + v1 = v1 == -1 ? int.MaxValue : v1; + v2 = v2 == -1 ? int.MaxValue : v2; + return Math.Min(v1, v2); + } + + private int MinNonZero(int v1, int v2, int v3) + { + v1 = v1 == -1 ? int.MaxValue : v1; + v2 = v2 == -1 ? int.MaxValue : v2; + v3 = v3 == -1 ? int.MaxValue : v3; + return Math.Min(Math.Min(v1, v2), v3); + } + private void RejectRequestLine(ReadCursor start, ReadCursor end) { const int MaxRequestLineError = 32; @@ -1244,40 +1302,41 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http consumed = buffer.Start; examined = buffer.End; + var bufferLength = buffer.Length; + var reader = new ReadableBufferReader(buffer); + while (true) { - var headersEnd = buffer.Slice(0, Math.Min(buffer.Length, 2)); - var headersEndSpan = headersEnd.ToSpan(); + var start = reader; + int ch1 = reader.Take(); + var ch2 = reader.Take(); - if (headersEndSpan.Length == 0) + if (ch1 == -1) { return false; } - else - { - var ch = headersEndSpan[0]; - if (ch == ByteCR) - { - // Check for final CRLF. - if (headersEndSpan.Length < 2) - { - return false; - } - else if (headersEndSpan[1] == ByteLF) - { - consumed = headersEnd.End; - examined = consumed; - ConnectionControl.CancelTimeout(); - return true; - } - // Headers don't end in CRLF line. - RejectRequest(RequestRejectionReason.HeadersCorruptedInvalidHeaderSequence); - } - else if (ch == ByteSpace || ch == ByteTab) + if (ch1 == ByteCR) + { + // Check for final CRLF. + if (ch2 == -1) { - RejectRequest(RequestRejectionReason.HeaderLineMustNotStartWithWhitespace); + return false; } + else if (ch2 == ByteLF) + { + consumed = reader.Cursor; + examined = consumed; + ConnectionControl.CancelTimeout(); + return true; + } + + // Headers don't end in CRLF line. + RejectRequest(RequestRejectionReason.HeadersCorruptedInvalidHeaderSequence); + } + else if (ch1 == ByteSpace || ch1 == ByteTab) + { + RejectRequest(RequestRejectionReason.HeaderLineMustNotStartWithWhitespace); } // If we've parsed the max allowed numbers of headers and we're starting a new @@ -1287,15 +1346,30 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http RejectRequest(RequestRejectionReason.TooManyHeaders); } - ReadCursor lineEnd; - var limitedBuffer = buffer; - if (buffer.Length >= _remainingRequestHeadersBytesAllowed) + // Reset the reader since we're not at the end of headers + reader = start; + + // Now parse a single header + ReadableBuffer limitedBuffer; + var overLength = false; + + if (bufferLength >= _remainingRequestHeadersBytesAllowed) { - limitedBuffer = buffer.Slice(0, _remainingRequestHeadersBytesAllowed); + limitedBuffer = buffer.Slice(consumed, _remainingRequestHeadersBytesAllowed); + + // If we sliced it means the current buffer bigger than what we're + // allowed to look at + overLength = true; } - if (ReadCursorOperations.Seek(limitedBuffer.Start, limitedBuffer.End, out lineEnd, ByteLF) == -1) + else { - if (limitedBuffer.Length == _remainingRequestHeadersBytesAllowed) + limitedBuffer = buffer; + } + + if (ReadCursorOperations.Seek(consumed, limitedBuffer.End, out var lineEnd, ByteLF) == -1) + { + // We didn't find a \n in the current buffer and we had to slice it so it's an issue + if (overLength) { RejectRequest(RequestRejectionReason.HeadersExceedMaxTotalSize); } @@ -1305,39 +1379,94 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } } - var beginName = buffer.Start; - ReadCursor endName; - if (ReadCursorOperations.Seek(buffer.Start, lineEnd, out endName, ByteColon) == -1) + const int stackAllocLimit = 512; + + if (lineEnd != limitedBuffer.End) + { + lineEnd = limitedBuffer.Move(lineEnd, 1); + } + + var headerBuffer = limitedBuffer.Slice(consumed, lineEnd); + + Span span; + if (headerBuffer.IsSingleSpan) + { + // No copies, directly use the one and only span + span = headerBuffer.ToSpan(); + } + else if (headerBuffer.Length < stackAllocLimit) + { + unsafe + { + // Multiple buffers and < stackAllocLimit, copy into a stack buffer + byte* stackBuffer = stackalloc byte[headerBuffer.Length]; + span = new Span(stackBuffer, headerBuffer.Length); + headerBuffer.CopyTo(span); + } + } + else + { + // We're not a single span here but we can use pooled arrays to avoid allocations in the rare case + span = new Span(new byte[headerBuffer.Length]); + headerBuffer.CopyTo(span); + } + + int endNameIndex = span.IndexOf(ByteColon); + if (endNameIndex == -1) { RejectRequest(RequestRejectionReason.NoColonCharacterFoundInHeaderLine); } - ReadCursor whitespace; - if (ReadCursorOperations.Seek(beginName, endName, out whitespace, ByteTab, ByteSpace) != -1) + var nameBuffer = span.Slice(0, endNameIndex); + if (nameBuffer.IndexOf(ByteSpace) != -1 || nameBuffer.IndexOf(ByteTab) != -1) { RejectRequest(RequestRejectionReason.WhitespaceIsNotAllowedInHeaderName); } - ReadCursor endValue; - if (ReadCursorOperations.Seek(beginName, lineEnd, out endValue, ByteCR) == -1) + int endValueIndex = span.IndexOf(ByteCR); + if (endValueIndex == -1) { RejectRequest(RequestRejectionReason.MissingCRInHeaderLine); } - var lineSufix = buffer.Slice(endValue); - if (lineSufix.Length < 3) + var lineSuffix = span.Slice(endValueIndex); + if (lineSuffix.Length < 2) { return false; } - lineSufix = lineSufix.Slice(0, 3); // \r\n\r - var lineSufixSpan = lineSufix.ToSpan(); + // This check and MissingCRInHeaderLine is a bit backwards, we should do it at once instead of having another seek - if (lineSufixSpan[1] != ByteLF) + if (lineSuffix[1] != ByteLF) { RejectRequest(RequestRejectionReason.HeaderValueMustNotContainCR); } - var next = lineSufixSpan[2]; + // Trim trailing whitespace from header value by repeatedly advancing to next + // whitespace or CR. + // + // - If CR is found, this is the end of the header value. + // - If whitespace is found, this is the _tentative_ end of the header value. + // If non-whitespace is found after it and it's not CR, seek again to the next + // whitespace or CR for a new (possibly tentative) end of value. + + var valueBuffer = span.Slice(endNameIndex + 1, endValueIndex - (endNameIndex + 1)); + + // TODO: Trim else where + var value = valueBuffer.GetAsciiString()?.Trim() ?? string.Empty; + + var headerLineLength = span.Length; + + // -1 so that we can re-check the extra \r + reader.Skip(headerLineLength); + + var next = reader.Peek(); + + // We cant check for line continuations to reject everything we've done so far + if (next == -1) + { + return false; + } + if (next == ByteSpace || next == ByteTab) { // From https://tools.ietf.org/html/rfc7230#section-3.2.4: @@ -1360,31 +1489,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http RejectRequest(RequestRejectionReason.HeaderValueLineFoldingNotSupported); } - // Trim trailing whitespace from header value by repeatedly advancing to next - // whitespace or CR. - // - // - If CR is found, this is the end of the header value. - // - If whitespace is found, this is the _tentative_ end of the header value. - // If non-whitespace is found after it and it's not CR, seek again to the next - // whitespace or CR for a new (possibly tentative) end of value. + // Update the frame state only after we know there's no header line continuation + _remainingRequestHeadersBytesAllowed -= headerLineLength; + bufferLength -= headerLineLength; - var nameBuffer = buffer.Slice(beginName, endName); - - // TODO: TrimStart and TrimEnd are pretty slow - var valueBuffer = buffer.Slice(endName, endValue).Slice(1).TrimStart().TrimEnd(); - - var name = nameBuffer.ToArraySegment(); - var value = valueBuffer.GetAsciiString(); - - lineEnd = limitedBuffer.Move(lineEnd, 1); - - // TODO: bad - _remainingRequestHeadersBytesAllowed -= buffer.Slice(0, lineEnd).Length; _requestHeadersParsed++; - requestHeaders.Append(name.Array, name.Offset, name.Count, value); - buffer = buffer.Slice(lineEnd); - consumed = buffer.Start; + requestHeaders.Append(nameBuffer, value); + + consumed = reader.Cursor; } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameHeaders.Generated.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameHeaders.Generated.cs index 7cfb64ff31..051b6b5737 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameHeaders.Generated.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameHeaders.Generated.cs @@ -3501,12 +3501,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } - public unsafe void Append(byte[] keyBytes, int keyOffset, int keyLength, string value) + public unsafe void Append(byte* pKeyBytes, int keyLength, string value) { - fixed (byte* ptr = &keyBytes[keyOffset]) - { - var pUB = ptr; - var pUL = (ulong*)pUB; + var pUB = pKeyBytes; + var pUL = (ulong*)pUB; var pUI = (uint*)pUB; var pUS = (ushort*)pUB; var stringValue = new StringValues(value); @@ -3567,11 +3565,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http break; } - AppendNonPrimaryHeaders(ptr, keyOffset, keyLength, value); - } + AppendNonPrimaryHeaders(pKeyBytes, keyLength, value); } - - private unsafe void AppendNonPrimaryHeaders(byte* pKeyBytes, int keyOffset, int keyLength, string value) + + private unsafe void AppendNonPrimaryHeaders(byte* pKeyBytes, int keyLength, string value) { var pUB = pKeyBytes; var pUL = (ulong*)pUB; @@ -7767,10 +7764,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } else { - var valueCount = _headers._Connection.Count; - for (var i = 0; i < valueCount; i++) + var valueCount = _headers._Connection.Count; + for (var i = 0; i < valueCount; i++) { - var value = _headers._Connection[i]; + var value = _headers._Connection[i]; if (value != null) { output.CopyFrom(_headerBytes, 17, 14); @@ -7793,10 +7790,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } else { - var valueCount = _headers._Date.Count; - for (var i = 0; i < valueCount; i++) + var valueCount = _headers._Date.Count; + for (var i = 0; i < valueCount; i++) { - var value = _headers._Date[i]; + var value = _headers._Date[i]; if (value != null) { output.CopyFrom(_headerBytes, 31, 8); @@ -7814,10 +7811,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if ((tempBits & 2048L) != 0) { { - var valueCount = _headers._ContentType.Count; - for (var i = 0; i < valueCount; i++) + var valueCount = _headers._ContentType.Count; + for (var i = 0; i < valueCount; i++) { - var value = _headers._ContentType[i]; + var value = _headers._ContentType[i]; if (value != null) { output.CopyFrom(_headerBytes, 133, 16); @@ -7840,10 +7837,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } else { - var valueCount = _headers._Server.Count; - for (var i = 0; i < valueCount; i++) + var valueCount = _headers._Server.Count; + for (var i = 0; i < valueCount; i++) { - var value = _headers._Server[i]; + var value = _headers._Server[i]; if (value != null) { output.CopyFrom(_headerBytes, 350, 10); @@ -7872,10 +7869,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if ((tempBits & 1L) != 0) { { - var valueCount = _headers._CacheControl.Count; - for (var i = 0; i < valueCount; i++) + var valueCount = _headers._CacheControl.Count; + for (var i = 0; i < valueCount; i++) { - var value = _headers._CacheControl[i]; + var value = _headers._CacheControl[i]; if (value != null) { output.CopyFrom(_headerBytes, 0, 17); @@ -7893,10 +7890,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if ((tempBits & 8L) != 0) { { - var valueCount = _headers._KeepAlive.Count; - for (var i = 0; i < valueCount; i++) + var valueCount = _headers._KeepAlive.Count; + for (var i = 0; i < valueCount; i++) { - var value = _headers._KeepAlive[i]; + var value = _headers._KeepAlive[i]; if (value != null) { output.CopyFrom(_headerBytes, 39, 14); @@ -7914,10 +7911,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if ((tempBits & 16L) != 0) { { - var valueCount = _headers._Pragma.Count; - for (var i = 0; i < valueCount; i++) + var valueCount = _headers._Pragma.Count; + for (var i = 0; i < valueCount; i++) { - var value = _headers._Pragma[i]; + var value = _headers._Pragma[i]; if (value != null) { output.CopyFrom(_headerBytes, 53, 10); @@ -7935,10 +7932,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if ((tempBits & 32L) != 0) { { - var valueCount = _headers._Trailer.Count; - for (var i = 0; i < valueCount; i++) + var valueCount = _headers._Trailer.Count; + for (var i = 0; i < valueCount; i++) { - var value = _headers._Trailer[i]; + var value = _headers._Trailer[i]; if (value != null) { output.CopyFrom(_headerBytes, 63, 11); @@ -7961,10 +7958,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } else { - var valueCount = _headers._TransferEncoding.Count; - for (var i = 0; i < valueCount; i++) + var valueCount = _headers._TransferEncoding.Count; + for (var i = 0; i < valueCount; i++) { - var value = _headers._TransferEncoding[i]; + var value = _headers._TransferEncoding[i]; if (value != null) { output.CopyFrom(_headerBytes, 74, 21); @@ -7982,10 +7979,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if ((tempBits & 128L) != 0) { { - var valueCount = _headers._Upgrade.Count; - for (var i = 0; i < valueCount; i++) + var valueCount = _headers._Upgrade.Count; + for (var i = 0; i < valueCount; i++) { - var value = _headers._Upgrade[i]; + var value = _headers._Upgrade[i]; if (value != null) { output.CopyFrom(_headerBytes, 95, 11); @@ -8003,10 +8000,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if ((tempBits & 256L) != 0) { { - var valueCount = _headers._Via.Count; - for (var i = 0; i < valueCount; i++) + var valueCount = _headers._Via.Count; + for (var i = 0; i < valueCount; i++) { - var value = _headers._Via[i]; + var value = _headers._Via[i]; if (value != null) { output.CopyFrom(_headerBytes, 106, 7); @@ -8024,10 +8021,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if ((tempBits & 512L) != 0) { { - var valueCount = _headers._Warning.Count; - for (var i = 0; i < valueCount; i++) + var valueCount = _headers._Warning.Count; + for (var i = 0; i < valueCount; i++) { - var value = _headers._Warning[i]; + var value = _headers._Warning[i]; if (value != null) { output.CopyFrom(_headerBytes, 113, 11); @@ -8045,10 +8042,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if ((tempBits & 1024L) != 0) { { - var valueCount = _headers._Allow.Count; - for (var i = 0; i < valueCount; i++) + var valueCount = _headers._Allow.Count; + for (var i = 0; i < valueCount; i++) { - var value = _headers._Allow[i]; + var value = _headers._Allow[i]; if (value != null) { output.CopyFrom(_headerBytes, 124, 9); @@ -8066,10 +8063,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if ((tempBits & 4096L) != 0) { { - var valueCount = _headers._ContentEncoding.Count; - for (var i = 0; i < valueCount; i++) + var valueCount = _headers._ContentEncoding.Count; + for (var i = 0; i < valueCount; i++) { - var value = _headers._ContentEncoding[i]; + var value = _headers._ContentEncoding[i]; if (value != null) { output.CopyFrom(_headerBytes, 149, 20); @@ -8087,10 +8084,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if ((tempBits & 8192L) != 0) { { - var valueCount = _headers._ContentLanguage.Count; - for (var i = 0; i < valueCount; i++) + var valueCount = _headers._ContentLanguage.Count; + for (var i = 0; i < valueCount; i++) { - var value = _headers._ContentLanguage[i]; + var value = _headers._ContentLanguage[i]; if (value != null) { output.CopyFrom(_headerBytes, 169, 20); @@ -8108,10 +8105,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if ((tempBits & 16384L) != 0) { { - var valueCount = _headers._ContentLocation.Count; - for (var i = 0; i < valueCount; i++) + var valueCount = _headers._ContentLocation.Count; + for (var i = 0; i < valueCount; i++) { - var value = _headers._ContentLocation[i]; + var value = _headers._ContentLocation[i]; if (value != null) { output.CopyFrom(_headerBytes, 189, 20); @@ -8129,10 +8126,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if ((tempBits & 32768L) != 0) { { - var valueCount = _headers._ContentMD5.Count; - for (var i = 0; i < valueCount; i++) + var valueCount = _headers._ContentMD5.Count; + for (var i = 0; i < valueCount; i++) { - var value = _headers._ContentMD5[i]; + var value = _headers._ContentMD5[i]; if (value != null) { output.CopyFrom(_headerBytes, 209, 15); @@ -8150,10 +8147,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if ((tempBits & 65536L) != 0) { { - var valueCount = _headers._ContentRange.Count; - for (var i = 0; i < valueCount; i++) + var valueCount = _headers._ContentRange.Count; + for (var i = 0; i < valueCount; i++) { - var value = _headers._ContentRange[i]; + var value = _headers._ContentRange[i]; if (value != null) { output.CopyFrom(_headerBytes, 224, 17); @@ -8171,10 +8168,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if ((tempBits & 131072L) != 0) { { - var valueCount = _headers._Expires.Count; - for (var i = 0; i < valueCount; i++) + var valueCount = _headers._Expires.Count; + for (var i = 0; i < valueCount; i++) { - var value = _headers._Expires[i]; + var value = _headers._Expires[i]; if (value != null) { output.CopyFrom(_headerBytes, 241, 11); @@ -8192,10 +8189,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if ((tempBits & 262144L) != 0) { { - var valueCount = _headers._LastModified.Count; - for (var i = 0; i < valueCount; i++) + var valueCount = _headers._LastModified.Count; + for (var i = 0; i < valueCount; i++) { - var value = _headers._LastModified[i]; + var value = _headers._LastModified[i]; if (value != null) { output.CopyFrom(_headerBytes, 252, 17); @@ -8213,10 +8210,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if ((tempBits & 524288L) != 0) { { - var valueCount = _headers._AcceptRanges.Count; - for (var i = 0; i < valueCount; i++) + var valueCount = _headers._AcceptRanges.Count; + for (var i = 0; i < valueCount; i++) { - var value = _headers._AcceptRanges[i]; + var value = _headers._AcceptRanges[i]; if (value != null) { output.CopyFrom(_headerBytes, 269, 17); @@ -8234,10 +8231,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if ((tempBits & 1048576L) != 0) { { - var valueCount = _headers._Age.Count; - for (var i = 0; i < valueCount; i++) + var valueCount = _headers._Age.Count; + for (var i = 0; i < valueCount; i++) { - var value = _headers._Age[i]; + var value = _headers._Age[i]; if (value != null) { output.CopyFrom(_headerBytes, 286, 7); @@ -8255,10 +8252,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if ((tempBits & 2097152L) != 0) { { - var valueCount = _headers._ETag.Count; - for (var i = 0; i < valueCount; i++) + var valueCount = _headers._ETag.Count; + for (var i = 0; i < valueCount; i++) { - var value = _headers._ETag[i]; + var value = _headers._ETag[i]; if (value != null) { output.CopyFrom(_headerBytes, 293, 8); @@ -8276,10 +8273,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if ((tempBits & 4194304L) != 0) { { - var valueCount = _headers._Location.Count; - for (var i = 0; i < valueCount; i++) + var valueCount = _headers._Location.Count; + for (var i = 0; i < valueCount; i++) { - var value = _headers._Location[i]; + var value = _headers._Location[i]; if (value != null) { output.CopyFrom(_headerBytes, 301, 12); @@ -8297,10 +8294,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if ((tempBits & 8388608L) != 0) { { - var valueCount = _headers._ProxyAuthenticate.Count; - for (var i = 0; i < valueCount; i++) + var valueCount = _headers._ProxyAuthenticate.Count; + for (var i = 0; i < valueCount; i++) { - var value = _headers._ProxyAuthenticate[i]; + var value = _headers._ProxyAuthenticate[i]; if (value != null) { output.CopyFrom(_headerBytes, 313, 22); @@ -8318,10 +8315,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if ((tempBits & 16777216L) != 0) { { - var valueCount = _headers._RetryAfter.Count; - for (var i = 0; i < valueCount; i++) + var valueCount = _headers._RetryAfter.Count; + for (var i = 0; i < valueCount; i++) { - var value = _headers._RetryAfter[i]; + var value = _headers._RetryAfter[i]; if (value != null) { output.CopyFrom(_headerBytes, 335, 15); @@ -8339,10 +8336,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if ((tempBits & 67108864L) != 0) { { - var valueCount = _headers._SetCookie.Count; - for (var i = 0; i < valueCount; i++) + var valueCount = _headers._SetCookie.Count; + for (var i = 0; i < valueCount; i++) { - var value = _headers._SetCookie[i]; + var value = _headers._SetCookie[i]; if (value != null) { output.CopyFrom(_headerBytes, 360, 14); @@ -8360,10 +8357,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if ((tempBits & 134217728L) != 0) { { - var valueCount = _headers._Vary.Count; - for (var i = 0; i < valueCount; i++) + var valueCount = _headers._Vary.Count; + for (var i = 0; i < valueCount; i++) { - var value = _headers._Vary[i]; + var value = _headers._Vary[i]; if (value != null) { output.CopyFrom(_headerBytes, 374, 8); @@ -8381,10 +8378,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if ((tempBits & 268435456L) != 0) { { - var valueCount = _headers._WWWAuthenticate.Count; - for (var i = 0; i < valueCount; i++) + var valueCount = _headers._WWWAuthenticate.Count; + for (var i = 0; i < valueCount; i++) { - var value = _headers._WWWAuthenticate[i]; + var value = _headers._WWWAuthenticate[i]; if (value != null) { output.CopyFrom(_headerBytes, 382, 20); @@ -8402,10 +8399,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if ((tempBits & 536870912L) != 0) { { - var valueCount = _headers._AccessControlAllowCredentials.Count; - for (var i = 0; i < valueCount; i++) + var valueCount = _headers._AccessControlAllowCredentials.Count; + for (var i = 0; i < valueCount; i++) { - var value = _headers._AccessControlAllowCredentials[i]; + var value = _headers._AccessControlAllowCredentials[i]; if (value != null) { output.CopyFrom(_headerBytes, 402, 36); @@ -8423,10 +8420,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if ((tempBits & 1073741824L) != 0) { { - var valueCount = _headers._AccessControlAllowHeaders.Count; - for (var i = 0; i < valueCount; i++) + var valueCount = _headers._AccessControlAllowHeaders.Count; + for (var i = 0; i < valueCount; i++) { - var value = _headers._AccessControlAllowHeaders[i]; + var value = _headers._AccessControlAllowHeaders[i]; if (value != null) { output.CopyFrom(_headerBytes, 438, 32); @@ -8444,10 +8441,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if ((tempBits & 2147483648L) != 0) { { - var valueCount = _headers._AccessControlAllowMethods.Count; - for (var i = 0; i < valueCount; i++) + var valueCount = _headers._AccessControlAllowMethods.Count; + for (var i = 0; i < valueCount; i++) { - var value = _headers._AccessControlAllowMethods[i]; + var value = _headers._AccessControlAllowMethods[i]; if (value != null) { output.CopyFrom(_headerBytes, 470, 32); @@ -8465,10 +8462,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if ((tempBits & 4294967296L) != 0) { { - var valueCount = _headers._AccessControlAllowOrigin.Count; - for (var i = 0; i < valueCount; i++) + var valueCount = _headers._AccessControlAllowOrigin.Count; + for (var i = 0; i < valueCount; i++) { - var value = _headers._AccessControlAllowOrigin[i]; + var value = _headers._AccessControlAllowOrigin[i]; if (value != null) { output.CopyFrom(_headerBytes, 502, 31); @@ -8486,10 +8483,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if ((tempBits & 8589934592L) != 0) { { - var valueCount = _headers._AccessControlExposeHeaders.Count; - for (var i = 0; i < valueCount; i++) + var valueCount = _headers._AccessControlExposeHeaders.Count; + for (var i = 0; i < valueCount; i++) { - var value = _headers._AccessControlExposeHeaders[i]; + var value = _headers._AccessControlExposeHeaders[i]; if (value != null) { output.CopyFrom(_headerBytes, 533, 33); @@ -8507,10 +8504,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if ((tempBits & 17179869184L) != 0) { { - var valueCount = _headers._AccessControlMaxAge.Count; - for (var i = 0; i < valueCount; i++) + var valueCount = _headers._AccessControlMaxAge.Count; + for (var i = 0; i < valueCount; i++) { - var value = _headers._AccessControlMaxAge[i]; + var value = _headers._AccessControlMaxAge[i]; if (value != null) { output.CopyFrom(_headerBytes, 566, 26); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameRequestHeaders.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameRequestHeaders.cs index 4dd46d5cf1..ca6496d320 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameRequestHeaders.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameRequestHeaders.cs @@ -1,6 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; using System.Collections; using System.Collections.Generic; using System.Runtime.CompilerServices; @@ -29,6 +30,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http Unknown[key] = value; } + public unsafe void Append(Span name, string value) + { + fixed (byte* namePtr = &name.DangerousGetPinnableReference()) + { + Append(namePtr, name.Length, value); + } + } + [MethodImpl(MethodImplOptions.NoInlining)] private unsafe void AppendUnknownHeaders(byte* pKeyBytes, int keyLength, string value) { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolIteratorExtensions.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolIteratorExtensions.cs index 94cf66ef7b..95c3c5a59f 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolIteratorExtensions.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolIteratorExtensions.cs @@ -90,6 +90,19 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure return sb.ToString(); } + public static string GetAsciiStringEscaped(this Span span) + { + var sb = new StringBuilder(); + + for (var i = 0; i < span.Length; ++i) + { + var ch = span[i]; + sb.Append(ch < 0x20 || ch >= 0x7F ? $"<0x{ch:X2}>" : ((char)ch).ToString()); + } + + return sb.ToString(); + } + public static ArraySegment PeekArraySegment(this MemoryPoolIterator iter) { if (iter.IsDefault || iter.IsEnd) @@ -157,6 +170,33 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure return false; } + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static bool GetKnownMethod(this Span span, out string knownMethod) + { + knownMethod = null; + if (span.Length < sizeof(ulong)) + { + return false; + } + + ulong value = span.Read(); + if ((value & _mask4Chars) == _httpGetMethodLong) + { + knownMethod = HttpMethods.Get; + return true; + } + foreach (var x in _knownMethods) + { + if ((value & x.Item1) == x.Item2) + { + knownMethod = x.Item3; + return true; + } + } + + return false; + } + /// /// Checks 9 bytes from correspond to a known HTTP version. /// @@ -200,5 +240,36 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure return knownVersion != null; } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static bool GetKnownVersion(this Span span, out string knownVersion) + { + knownVersion = null; + + if (span.Length < sizeof(ulong)) + { + return false; + } + + var value = span.Read(); + if (value == _http11VersionLong) + { + knownVersion = Http11Version; + } + else if (value == _http10VersionLong) + { + knownVersion = Http10Version; + } + + if (knownVersion != null) + { + if (span[sizeof(ulong)] != (byte)'\r') + { + knownVersion = null; + } + } + + return knownVersion != null; + } } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Microsoft.AspNetCore.Server.Kestrel.csproj b/src/Microsoft.AspNetCore.Server.Kestrel/Microsoft.AspNetCore.Server.Kestrel.csproj index c62c37e231..5dd7b984c9 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Microsoft.AspNetCore.Server.Kestrel.csproj +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Microsoft.AspNetCore.Server.Kestrel.csproj @@ -30,4 +30,4 @@ - + \ No newline at end of file diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameRequestHeadersTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameRequestHeadersTests.cs index 91212d627b..dbf6d857a5 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameRequestHeadersTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameRequestHeadersTests.cs @@ -311,7 +311,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var encoding = Encoding.GetEncoding("iso-8859-1"); var exception = Assert.Throws( - () => headers.Append(encoding.GetBytes(key), 0, encoding.GetByteCount(key), key)); + () => headers.Append(encoding.GetBytes(key), key)); Assert.Equal(StatusCodes.Status400BadRequest, exception.StatusCode); } } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs index bf6fc9c78b..3edb7fad3d 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs @@ -611,7 +611,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var exception = Assert.Throws(() => _frame.TakeStartLine(readableBuffer, out consumed, out examined)); _socketInput.Reader.Advance(consumed, examined); - Assert.Equal("Unrecognized HTTP version: HTTP/1.1a...", exception.Message); + Assert.Equal("Unrecognized HTTP version: HTTP/1.1ab", exception.Message); Assert.Equal(StatusCodes.Status505HttpVersionNotsupported, exception.StatusCode); } diff --git a/tools/CodeGenerator/KnownHeaders.cs b/tools/CodeGenerator/KnownHeaders.cs index 0e2fdf858f..a211013404 100644 --- a/tools/CodeGenerator/KnownHeaders.cs +++ b/tools/CodeGenerator/KnownHeaders.cs @@ -564,18 +564,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http }}" : "")}")} }}" : "")} {(loop.ClassName == "FrameRequestHeaders" ? $@" - public unsafe void Append(byte[] keyBytes, int keyOffset, int keyLength, string value) + public unsafe void Append(byte* pKeyBytes, int keyLength, string value) {{ - fixed (byte* ptr = &keyBytes[keyOffset]) - {{ - var pUB = ptr; - {AppendSwitch(loop.Headers.Where(h => h.PrimaryHeader).GroupBy(x => x.Name.Length), loop.ClassName)} + var pUB = pKeyBytes; + {AppendSwitch(loop.Headers.Where(h => h.PrimaryHeader).GroupBy(x => x.Name.Length), loop.ClassName)} - AppendNonPrimaryHeaders(ptr, keyOffset, keyLength, value); - }} + AppendNonPrimaryHeaders(pKeyBytes, keyLength, value); }} - private unsafe void AppendNonPrimaryHeaders(byte* pKeyBytes, int keyOffset, int keyLength, string value) + private unsafe void AppendNonPrimaryHeaders(byte* pKeyBytes, int keyLength, string value) {{ var pUB = pKeyBytes; {AppendSwitch(loop.Headers.Where(h => !h.PrimaryHeader).GroupBy(x => x.Name.Length), loop.ClassName)} From c6705d8693847c695552523c1bd66284735979e3 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Mon, 27 Feb 2017 11:55:30 -0800 Subject: [PATCH 1059/1662] Convert TakeStartLine and TakeMessageHeaders to be state machines (#1401) - Less passes over the buffer - Single pass to find all start line delimiters instead of calling IndexOf multiple times. - Made TakeStartLine and TakeMessageHeaders a state machine - Only check length against remaining bytes once - Change variable names to match TakeStartLine - Use ReadableBuffer.First.Span instead of ToSpan() - Added test for missing path with a querystring --- .../Internal/Http/Frame.cs | 526 +++++++++++------- .../FrameTests.cs | 1 + 2 files changed, 327 insertions(+), 200 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs index 232e567a27..046c29c0e6 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs @@ -982,10 +982,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http Output.ProducingComplete(end); } - public bool TakeStartLine(ReadableBuffer buffer, out ReadCursor consumed, out ReadCursor examined) + public unsafe bool TakeStartLine(ReadableBuffer buffer, out ReadCursor consumed, out ReadCursor examined) { var start = buffer.Start; var end = buffer.Start; + var bufferEnd = buffer.End; examined = buffer.End; consumed = buffer.Start; @@ -997,19 +998,17 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _requestProcessingStatus = RequestProcessingStatus.RequestStarted; - ReadableBuffer limitedBuffer; + var overLength = false; if (buffer.Length >= ServerOptions.Limits.MaxRequestLineSize) { - limitedBuffer = buffer.Slice(0, ServerOptions.Limits.MaxRequestLineSize); - } - else - { - limitedBuffer = buffer; + bufferEnd = buffer.Move(start, ServerOptions.Limits.MaxRequestLineSize); + + overLength = true; } - if (ReadCursorOperations.Seek(limitedBuffer.Start, limitedBuffer.End, out end, ByteLF) == -1) + if (ReadCursorOperations.Seek(start, bufferEnd, out end, ByteLF) == -1) { - if (limitedBuffer.Length == ServerOptions.Limits.MaxRequestLineSize) + if (overLength) { RejectRequest(RequestRejectionReason.RequestLineTooLong); } @@ -1021,26 +1020,23 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http const int stackAllocLimit = 512; - // Move 1 byte past the \r - end = limitedBuffer.Move(end, 1); - var startLineBuffer = limitedBuffer.Slice(0, end); + // Move 1 byte past the \n + end = buffer.Move(end, 1); + var startLineBuffer = buffer.Slice(start, end); Span span; if (startLineBuffer.IsSingleSpan) { // No copies, directly use the one and only span - span = startLineBuffer.ToSpan(); + span = startLineBuffer.First.Span; } else if (startLineBuffer.Length < stackAllocLimit) { - unsafe - { - // Multiple buffers and < stackAllocLimit, copy into a stack buffer - byte* stackBuffer = stackalloc byte[startLineBuffer.Length]; - span = new Span(stackBuffer, startLineBuffer.Length); - startLineBuffer.CopyTo(span); - } + // Multiple buffers and < stackAllocLimit, copy into a stack buffer + byte* stackBuffer = stackalloc byte[startLineBuffer.Length]; + span = new Span(stackBuffer, startLineBuffer.Length); + startLineBuffer.CopyTo(span); } else { @@ -1049,113 +1045,163 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http startLineBuffer.CopyTo(span); } - var methodEnd = 0; - if (!span.GetKnownMethod(out string method)) + var needDecode = false; + var pathStart = -1; + var queryStart = -1; + var queryEnd = -1; + var pathEnd = -1; + var versionStart = -1; + var queryString = ""; + var httpVersion = ""; + var method = ""; + var state = StartLineState.KnownMethod; + + fixed (byte* data = &span.DangerousGetPinnableReference()) { - methodEnd = span.IndexOf(ByteSpace); - if (methodEnd == -1) + var length = span.Length; + for (var i = 0; i < length; i++) { - RejectRequestLine(start, end); - } + var ch = data[i]; - method = span.Slice(0, methodEnd).GetAsciiString(); - - if (method == null) - { - RejectRequestLine(start, end); - } - - // Note: We're not in the fast path any more (GetKnownMethod should have handled any HTTP Method we're aware of) - // So we can be a tiny bit slower and more careful here. - for (int i = 0; i < method.Length; i++) - { - if (!IsValidTokenChar(method[i])) + switch (state) { - RejectRequestLine(start, end); + case StartLineState.KnownMethod: + if (span.GetKnownMethod(out method)) + { + // Update the index, current char, state and jump directly + // to the next state + i += method.Length + 1; + ch = data[i]; + state = StartLineState.Path; + + goto case StartLineState.Path; + } + + state = StartLineState.UnknownMethod; + goto case StartLineState.UnknownMethod; + + case StartLineState.UnknownMethod: + if (ch == ByteSpace) + { + method = span.Slice(0, i).GetAsciiString(); + + if (method == null) + { + RejectRequestLine(start, end); + } + + state = StartLineState.Path; + } + else if (!IsValidTokenChar((char)ch)) + { + RejectRequestLine(start, end); + } + + break; + case StartLineState.Path: + if (ch == ByteSpace) + { + pathEnd = i; + + if (pathStart == -1) + { + // Empty path is illegal + RejectRequestLine(start, end); + } + + // No query string found + queryStart = queryEnd = i; + + state = StartLineState.KnownVersion; + } + else if (ch == ByteQuestionMark) + { + pathEnd = i; + + if (pathStart == -1) + { + // Empty path is illegal + RejectRequestLine(start, end); + } + + queryStart = i; + state = StartLineState.QueryString; + } + else if (ch == BytePercentage) + { + needDecode = true; + } + + if (pathStart == -1) + { + pathStart = i; + } + break; + case StartLineState.QueryString: + if (ch == ByteSpace) + { + queryEnd = i; + state = StartLineState.KnownVersion; + + queryString = span.Slice(queryStart, queryEnd - queryStart).GetAsciiString() ?? string.Empty; + } + break; + case StartLineState.KnownVersion: + // REVIEW: We don't *need* to slice here but it makes the API + // nicer, slicing should be free :) + if (span.Slice(i).GetKnownVersion(out httpVersion)) + { + // Update the index, current char, state and jump directly + // to the next state + i += httpVersion.Length + 1; + ch = data[i]; + state = StartLineState.NewLine; + + goto case StartLineState.NewLine; + } + + versionStart = i; + state = StartLineState.UnknownVersion; + goto case StartLineState.UnknownVersion; + + case StartLineState.UnknownVersion: + if (ch == ByteCR) + { + var versionSpan = span.Slice(versionStart, i - versionStart); + + if (versionSpan.Length == 0) + { + RejectRequestLine(start, end); + } + else + { + RejectRequest(RequestRejectionReason.UnrecognizedHTTPVersion, versionSpan.GetAsciiStringEscaped()); + } + } + break; + case StartLineState.NewLine: + if (ch != ByteLF) + { + RejectRequestLine(start, end); + } + + state = StartLineState.Complete; + break; + case StartLineState.Complete: + break; + default: + break; } } } - else - { - methodEnd += method.Length; - } - var needDecode = false; - var pathBegin = methodEnd + 1; - var pathToEndSpan = span.Slice(pathBegin, span.Length - pathBegin); - pathBegin = 0; - - // TODO: IndexOfAny - var spaceIndex = pathToEndSpan.IndexOf(ByteSpace); - var questionMarkIndex = pathToEndSpan.IndexOf(ByteQuestionMark); - var percentageIndex = pathToEndSpan.IndexOf(BytePercentage); - - var pathEnd = MinNonZero(spaceIndex, questionMarkIndex, percentageIndex); - - if (spaceIndex == -1 && questionMarkIndex == -1 && percentageIndex == -1) - { - RejectRequestLine(start, end); - } - else if (percentageIndex != -1) - { - needDecode = true; - - pathEnd = MinNonZero(spaceIndex, questionMarkIndex); - if (questionMarkIndex == -1 && spaceIndex == -1) - { - RejectRequestLine(start, end); - } - } - - var queryString = ""; - var queryEnd = pathEnd; - if (questionMarkIndex != -1) - { - queryEnd = spaceIndex; - if (spaceIndex == -1) - { - RejectRequestLine(start, end); - } - - queryString = pathToEndSpan.Slice(pathEnd, queryEnd - pathEnd).GetAsciiString(); - } - - if (pathBegin == pathEnd) + if (state != StartLineState.Complete) { RejectRequestLine(start, end); } - var versionBegin = queryEnd + 1; - var versionToEndSpan = pathToEndSpan.Slice(versionBegin, pathToEndSpan.Length - versionBegin); - versionBegin = 0; - var versionEnd = versionToEndSpan.IndexOf(ByteCR); - - if (versionEnd == -1) - { - RejectRequestLine(start, end); - } - - if (!versionToEndSpan.GetKnownVersion(out string httpVersion)) - { - httpVersion = versionToEndSpan.Slice(0, versionEnd).GetAsciiStringEscaped(); - - if (httpVersion == string.Empty) - { - RejectRequestLine(start, end); - } - else - { - RejectRequest(RequestRejectionReason.UnrecognizedHTTPVersion, httpVersion); - } - } - - if (versionToEndSpan[versionEnd + 1] != ByteLF) - { - RejectRequestLine(start, end); - } - - var pathBuffer = pathToEndSpan.Slice(pathBegin, pathEnd); - var targetBuffer = pathToEndSpan.Slice(pathBegin, queryEnd); + var pathBuffer = span.Slice(pathStart, pathEnd - pathStart); + var targetBuffer = span.Slice(pathStart, queryEnd - pathStart); // URIs are always encoded/escaped to ASCII https://tools.ietf.org/html/rfc3986#page-11 // Multibyte Internationalized Resource Identifiers (IRIs) are first converted to utf8; @@ -1198,8 +1244,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http RawTarget = rawTarget; HttpVersion = httpVersion; - bool caseMatches; - if (RequestUrlStartsWithPathBase(normalizedTarget, out caseMatches)) + if (RequestUrlStartsWithPathBase(normalizedTarget, out bool caseMatches)) { PathBase = caseMatches ? _pathBase : normalizedTarget.Substring(0, _pathBase.Length); Path = normalizedTarget.Substring(_pathBase.Length); @@ -1215,24 +1260,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http QueryString = string.Empty; } + return true; } - private int MinNonZero(int v1, int v2) - { - v1 = v1 == -1 ? int.MaxValue : v1; - v2 = v2 == -1 ? int.MaxValue : v2; - return Math.Min(v1, v2); - } - - private int MinNonZero(int v1, int v2, int v3) - { - v1 = v1 == -1 ? int.MaxValue : v1; - v2 = v2 == -1 ? int.MaxValue : v2; - v3 = v3 == -1 ? int.MaxValue : v3; - return Math.Min(Math.Min(v1, v2), v3); - } - private void RejectRequestLine(ReadCursor start, ReadCursor end) { const int MaxRequestLineError = 32; @@ -1297,13 +1328,24 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http return true; } - public bool TakeMessageHeaders(ReadableBuffer buffer, FrameRequestHeaders requestHeaders, out ReadCursor consumed, out ReadCursor examined) + public unsafe bool TakeMessageHeaders(ReadableBuffer buffer, FrameRequestHeaders requestHeaders, out ReadCursor consumed, out ReadCursor examined) { consumed = buffer.Start; examined = buffer.End; - var bufferLength = buffer.Length; + var bufferEnd = buffer.End; var reader = new ReadableBufferReader(buffer); + + // Make sure the buffer is limited + var overLength = false; + if (buffer.Length >= _remainingRequestHeadersBytesAllowed) + { + bufferEnd = buffer.Move(consumed, _remainingRequestHeadersBytesAllowed); + + // If we sliced it means the current buffer bigger than what we're + // allowed to look at + overLength = true; + } while (true) { @@ -1349,24 +1391,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http // Reset the reader since we're not at the end of headers reader = start; - // Now parse a single header - ReadableBuffer limitedBuffer; - var overLength = false; - - if (bufferLength >= _remainingRequestHeadersBytesAllowed) - { - limitedBuffer = buffer.Slice(consumed, _remainingRequestHeadersBytesAllowed); - - // If we sliced it means the current buffer bigger than what we're - // allowed to look at - overLength = true; - } - else - { - limitedBuffer = buffer; - } - - if (ReadCursorOperations.Seek(consumed, limitedBuffer.End, out var lineEnd, ByteLF) == -1) + if (ReadCursorOperations.Seek(consumed, bufferEnd, out var lineEnd, ByteLF) == -1) { // We didn't find a \n in the current buffer and we had to slice it so it's an issue if (overLength) @@ -1381,28 +1406,25 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http const int stackAllocLimit = 512; - if (lineEnd != limitedBuffer.End) + if (lineEnd != bufferEnd) { - lineEnd = limitedBuffer.Move(lineEnd, 1); + lineEnd = buffer.Move(lineEnd, 1); } - var headerBuffer = limitedBuffer.Slice(consumed, lineEnd); + var headerBuffer = buffer.Slice(consumed, lineEnd); Span span; if (headerBuffer.IsSingleSpan) { // No copies, directly use the one and only span - span = headerBuffer.ToSpan(); + span = headerBuffer.First.Span; } else if (headerBuffer.Length < stackAllocLimit) { - unsafe - { - // Multiple buffers and < stackAllocLimit, copy into a stack buffer - byte* stackBuffer = stackalloc byte[headerBuffer.Length]; - span = new Span(stackBuffer, headerBuffer.Length); - headerBuffer.CopyTo(span); - } + // Multiple buffers and < stackAllocLimit, copy into a stack buffer + byte* stackBuffer = stackalloc byte[headerBuffer.Length]; + span = new Span(stackBuffer, headerBuffer.Length); + headerBuffer.CopyTo(span); } else { @@ -1411,59 +1433,139 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http headerBuffer.CopyTo(span); } - int endNameIndex = span.IndexOf(ByteColon); - if (endNameIndex == -1) + var state = HeaderState.Name; + var nameStart = 0; + var nameEnd = -1; + var valueStart = -1; + var valueEnd = -1; + var nameHasWhitespace = false; + var previouslyWhitespace = false; + var headerLineLength = span.Length; + + fixed (byte* data = &span.DangerousGetPinnableReference()) + { + for (var i = 0; i < headerLineLength; i++) + { + var ch = data[i]; + + switch (state) + { + case HeaderState.Name: + if (ch == ByteColon) + { + if (nameHasWhitespace) + { + RejectRequest(RequestRejectionReason.WhitespaceIsNotAllowedInHeaderName); + } + + state = HeaderState.Whitespace; + nameEnd = i; + } + + if (ch == ByteSpace || ch == ByteTab) + { + nameHasWhitespace = true; + } + break; + case HeaderState.Whitespace: + { + var whitespace = ch == ByteTab || ch == ByteSpace || ch == ByteCR; + + if (!whitespace) + { + // Mark the first non whitespace char as the start of the + // header value and change the state to expect to the header value + valueStart = i; + state = HeaderState.ExpectValue; + } + // If we see a CR then jump to the next state directly + else if (ch == ByteCR) + { + state = HeaderState.ExpectValue; + goto case HeaderState.ExpectValue; + } + } + break; + case HeaderState.ExpectValue: + { + var whitespace = ch == ByteTab || ch == ByteSpace; + + if (whitespace) + { + if (!previouslyWhitespace) + { + // If we see a whitespace char then maybe it's end of the + // header value + valueEnd = i; + } + } + else if (ch == ByteCR) + { + // If we see a CR and we haven't ever seen whitespace then + // this is the end of the header value + if (valueEnd == -1) + { + valueEnd = i; + } + + // We never saw a non whitespace character before the CR + if (valueStart == -1) + { + valueStart = valueEnd; + } + + state = HeaderState.ExpectNewLine; + } + else + { + // If we find a non whitespace char that isn't CR then reset the end index + valueEnd = -1; + } + + previouslyWhitespace = whitespace; + } + break; + case HeaderState.ExpectNewLine: + if (ch != ByteLF) + { + RejectRequest(RequestRejectionReason.HeaderValueMustNotContainCR); + } + + state = HeaderState.Complete; + break; + default: + break; + } + } + } + + if (state == HeaderState.Name) { RejectRequest(RequestRejectionReason.NoColonCharacterFoundInHeaderLine); } - var nameBuffer = span.Slice(0, endNameIndex); - if (nameBuffer.IndexOf(ByteSpace) != -1 || nameBuffer.IndexOf(ByteTab) != -1) - { - RejectRequest(RequestRejectionReason.WhitespaceIsNotAllowedInHeaderName); - } - - int endValueIndex = span.IndexOf(ByteCR); - if (endValueIndex == -1) + if (state == HeaderState.ExpectValue || state == HeaderState.Whitespace) { RejectRequest(RequestRejectionReason.MissingCRInHeaderLine); } - var lineSuffix = span.Slice(endValueIndex); - if (lineSuffix.Length < 2) + if (state != HeaderState.Complete) { return false; } - // This check and MissingCRInHeaderLine is a bit backwards, we should do it at once instead of having another seek - if (lineSuffix[1] != ByteLF) - { - RejectRequest(RequestRejectionReason.HeaderValueMustNotContainCR); - } - - // Trim trailing whitespace from header value by repeatedly advancing to next - // whitespace or CR. - // - // - If CR is found, this is the end of the header value. - // - If whitespace is found, this is the _tentative_ end of the header value. - // If non-whitespace is found after it and it's not CR, seek again to the next - // whitespace or CR for a new (possibly tentative) end of value. - - var valueBuffer = span.Slice(endNameIndex + 1, endValueIndex - (endNameIndex + 1)); - - // TODO: Trim else where - var value = valueBuffer.GetAsciiString()?.Trim() ?? string.Empty; - - var headerLineLength = span.Length; - - // -1 so that we can re-check the extra \r + // Skip the reader forward past the header line reader.Skip(headerLineLength); + // Before accepting the header line, we need to see at least one character + // > so we can make sure there's no space or tab var next = reader.Peek(); - // We cant check for line continuations to reject everything we've done so far + // TODO: We don't need to reject the line here, we can use the state machine + // to store the fact that we're reading a header value if (next == -1) { + // If we can't see the next char then reject the entire line return false; } @@ -1489,10 +1591,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http RejectRequest(RequestRejectionReason.HeaderValueLineFoldingNotSupported); } + var nameBuffer = span.Slice(nameStart, nameEnd - nameStart); + var valueBuffer = span.Slice(valueStart, valueEnd - valueStart); + + var value = valueBuffer.GetAsciiString() ?? string.Empty; + // Update the frame state only after we know there's no header line continuation _remainingRequestHeadersBytesAllowed -= headerLineLength; - bufferLength -= headerLineLength; - _requestHeadersParsed++; requestHeaders.Append(nameBuffer, value); @@ -1638,5 +1743,26 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http RequestStarted, ResponseStarted } + + private enum StartLineState + { + KnownMethod, + UnknownMethod, + Path, + QueryString, + KnownVersion, + UnknownVersion, + NewLine, + Complete + } + + private enum HeaderState + { + Name, + Whitespace, + ExpectValue, + ExpectNewLine, + Complete + } } } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs index 3edb7fad3d..d8f7dc701c 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs @@ -572,6 +572,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [InlineData("GET HTTP/1.1\r\n", "Invalid request line: GET HTTP/1.1<0x0D><0x0A>")] [InlineData("GET / HTTP/1.1\n", "Invalid request line: GET / HTTP/1.1<0x0A>")] [InlineData("GET / \r\n", "Invalid request line: GET / <0x0D><0x0A>")] + [InlineData("GET ? HTTP/1.1\r\n", "Invalid request line: GET ? HTTP/1.1<0x0D><0x0A>")] [InlineData("GET / HTTP/1.1\ra\n", "Invalid request line: GET / HTTP/1.1<0x0D>a<0x0A>")] public async Task TakeStartLineThrowsWhenInvalid(string requestLine, string expectedExceptionMessage) { From a95743c5f659d5c8fb597f810f7743e39f8b01f2 Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Mon, 6 Feb 2017 16:34:28 -0800 Subject: [PATCH 1060/1662] Add functional test to verify generated code is up to date (#1369). --- .../GeneratedCodeTests.cs | 44 +++++++++++++++ ...Core.Server.Kestrel.FunctionalTests.csproj | 1 + tools/CodeGenerator/Program.cs | 56 ++++++++++--------- 3 files changed, 74 insertions(+), 27 deletions(-) create mode 100644 test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/GeneratedCodeTests.cs diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/GeneratedCodeTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/GeneratedCodeTests.cs new file mode 100644 index 0000000000..3fa3d89026 --- /dev/null +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/GeneratedCodeTests.cs @@ -0,0 +1,44 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +#if NETCOREAPP1_1 + +using System.IO; +using Xunit; + +namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests +{ + public class GeneratedCodeTests + { + [Fact] + public void GeneratedCodeIsUpToDate() + { + const string frameHeadersGeneratedPath = "../../../../../src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameHeaders.Generated.cs"; + const string frameGeneratedPath = "../../../../../src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.Generated.cs"; + + var testFrameHeadersGeneratedPath = Path.GetTempFileName(); + var testFrameGeneratedPath = Path.GetTempFileName(); + + try + { + var currentFrameHeadersGenerated = File.ReadAllText(frameHeadersGeneratedPath); + var currentFrameGenerated = File.ReadAllText(frameGeneratedPath); + + CodeGenerator.Program.Run(testFrameHeadersGeneratedPath, testFrameGeneratedPath); + + var testFrameHeadersGenerated = File.ReadAllText(testFrameHeadersGeneratedPath); + var testFrameGenerated = File.ReadAllText(testFrameGeneratedPath); + + Assert.Equal(currentFrameHeadersGenerated, testFrameHeadersGenerated, ignoreLineEndingDifferences: true); + Assert.Equal(currentFrameGenerated, testFrameGenerated, ignoreLineEndingDifferences: true); + } + finally + { + File.Delete(testFrameHeadersGeneratedPath); + File.Delete(testFrameGeneratedPath); + } + } + } +} + +#endif \ No newline at end of file diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests.csproj b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests.csproj index 41df7b3e09..fe6cbe0da0 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests.csproj +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests.csproj @@ -35,6 +35,7 @@ + diff --git a/tools/CodeGenerator/Program.cs b/tools/CodeGenerator/Program.cs index 102839b6b7..a057b078c6 100644 --- a/tools/CodeGenerator/Program.cs +++ b/tools/CodeGenerator/Program.cs @@ -10,36 +10,38 @@ namespace CodeGenerator { public static int Main(string[] args) { - var text0 = KnownHeaders.GeneratedFile(); - var text1 = FrameFeatureCollection.GeneratedFile(); + if (args.Length < 1) + { + Console.Error.WriteLine("Missing path to FrameHeaders.Generated.cs"); + return 1; + } + else if (args.Length < 2) + { + Console.Error.WriteLine("Missing path to Frame.Generated.cs"); + return 1; + } - if (args.Length == 1) - { - var existing = File.Exists(args[0]) ? File.ReadAllText(args[0]) : ""; - if (!string.Equals(text0, existing)) - { - File.WriteAllText(args[0], text0); - } - } - else if (args.Length == 2) - { - var existing0 = File.Exists(args[0]) ? File.ReadAllText(args[0]) : ""; - if (!string.Equals(text0, existing0)) - { - File.WriteAllText(args[0], text0); - } + Run(args[0], args[1]); - var existing1 = File.Exists(args[1]) ? File.ReadAllText(args[1]) : ""; - if (!string.Equals(text1, existing1)) - { - File.WriteAllText(args[1], text1); - } - } - else - { - Console.WriteLine(text0); - } return 0; } + + public static void Run(string knownHeadersPath, string frameFeaturesCollectionPath) + { + var knownHeadersContent = KnownHeaders.GeneratedFile(); + var frameFeatureCollectionContent = FrameFeatureCollection.GeneratedFile(); + + var existingKnownHeaders = File.Exists(knownHeadersPath) ? File.ReadAllText(knownHeadersPath) : ""; + if (!string.Equals(knownHeadersContent, existingKnownHeaders)) + { + File.WriteAllText(knownHeadersPath, knownHeadersContent); + } + + var existingFrameFeatureCollection = File.Exists(frameFeaturesCollectionPath) ? File.ReadAllText(frameFeaturesCollectionPath) : ""; + if (!string.Equals(frameFeatureCollectionContent, existingFrameFeatureCollection)) + { + File.WriteAllText(frameFeaturesCollectionPath, frameFeatureCollectionContent); + } + } } } From fde0f6b2fcad1dd5fa953a65caf749c604c7cfe5 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Tue, 28 Feb 2017 10:14:58 -0800 Subject: [PATCH 1061/1662] Add an option to Kestrel to disable threadpool dispatching --- samples/SampleApp/Startup.cs | 3 + .../Internal/Http/FrameOfT.cs | 3 +- .../Infrastructure/InlineLoggingThreadPool.cs | 78 +++++++++++++++++++ .../Internal/Infrastructure/KestrelThread.cs | 2 +- .../Internal/InternalKestrelServerOptions.cs | 12 +++ .../KestrelServer.cs | 17 +++- .../ConnectionTests.cs | 34 ++++---- .../SocketOutputTests.cs | 24 +++--- .../TestHelpers/SynchronousThreadPool.cs | 43 ---------- test/shared/TestServiceContext.cs | 8 +- 10 files changed, 143 insertions(+), 81 deletions(-) create mode 100644 src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/InlineLoggingThreadPool.cs create mode 100644 src/Microsoft.AspNetCore.Server.Kestrel/Internal/InternalKestrelServerOptions.cs delete mode 100644 test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/SynchronousThreadPool.cs diff --git a/samples/SampleApp/Startup.cs b/samples/SampleApp/Startup.cs index 61992fd4d2..f8d32ebe1c 100644 --- a/samples/SampleApp/Startup.cs +++ b/samples/SampleApp/Startup.cs @@ -8,6 +8,7 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Server.Kestrel.Internal; using Microsoft.Extensions.Logging; namespace SampleApp @@ -68,6 +69,8 @@ namespace SampleApp .UseStartup() .Build(); + host.ServerFeatures.Get().ThreadPoolDispatching = false; + host.Run(); } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameOfT.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameOfT.cs index 40fc9e2059..23626c47ac 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameOfT.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameOfT.cs @@ -17,8 +17,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { private readonly IHttpApplication _application; - public Frame(IHttpApplication application, - ConnectionContext context) + public Frame(IHttpApplication application, ConnectionContext context) : base(context) { _application = application; diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/InlineLoggingThreadPool.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/InlineLoggingThreadPool.cs new file mode 100644 index 0000000000..8945ec0827 --- /dev/null +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/InlineLoggingThreadPool.cs @@ -0,0 +1,78 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Threading; +using System.Threading.Tasks; +using Microsoft.Extensions.Logging; + +namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure +{ + public class InlineLoggingThreadPool : IThreadPool + { + private readonly IKestrelTrace _log; + + public InlineLoggingThreadPool(IKestrelTrace log) + { + _log = log; + } + + public void Run(Action action) + { + try + { + action(); + } + catch (Exception e) + { + _log.LogError(0, e, "InlineLoggingThreadPool.Run"); + } + } + + public void Complete(TaskCompletionSource tcs) + { + try + { + tcs.TrySetResult(null); + } + catch (Exception e) + { + _log.LogError(0, e, "InlineLoggingThreadPool.Complete"); + } + } + + public void Cancel(TaskCompletionSource tcs) + { + try + { + tcs.TrySetCanceled(); + } + catch (Exception e) + { + _log.LogError(0, e, "InlineLoggingThreadPool.Cancel"); + } + } + + public void Error(TaskCompletionSource tcs, Exception ex) + { + try + { + tcs.TrySetException(ex); + } + catch (Exception e) + { + _log.LogError(0, e, "InlineLoggingThreadPool.Error"); + } + } + + public void UnsafeRun(WaitCallback action, object state) + { + action(state); + } + + public void Schedule(Action action) + { + Run(action); + } + } +} diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/KestrelThread.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/KestrelThread.cs index ea40ccf322..03d6abcbc2 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/KestrelThread.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/KestrelThread.cs @@ -20,7 +20,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal /// /// Summary description for KestrelThread /// - public class KestrelThread: IScheduler + public class KestrelThread : IScheduler { public const long HeartbeatMilliseconds = 1000; diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/InternalKestrelServerOptions.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/InternalKestrelServerOptions.cs new file mode 100644 index 0000000000..e8d98268cd --- /dev/null +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/InternalKestrelServerOptions.cs @@ -0,0 +1,12 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +namespace Microsoft.AspNetCore.Server.Kestrel.Internal +{ + public class InternalKestrelServerOptions + { + // This will likely be replace with transport-specific configuration. + // https://github.com/aspnet/KestrelHttpServer/issues/828 + public bool ThreadPoolDispatching { get; set; } = true; + } +} diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServer.cs b/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServer.cs index 24803a963a..01e9f74402 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServer.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServer.cs @@ -45,17 +45,21 @@ namespace Microsoft.AspNetCore.Server.Kestrel } Options = options.Value ?? new KestrelServerOptions(); + InternalOptions = new InternalKestrelServerOptions(); _applicationLifetime = applicationLifetime; _logger = loggerFactory.CreateLogger(typeof(KestrelServer).GetTypeInfo().Namespace); Features = new FeatureCollection(); _serverAddresses = new ServerAddressesFeature(); Features.Set(_serverAddresses); + Features.Set(InternalOptions); } public IFeatureCollection Features { get; } public KestrelServerOptions Options { get; } + private InternalKestrelServerOptions InternalOptions { get; } + public void Start(IHttpApplication application) { try @@ -76,6 +80,17 @@ namespace Microsoft.AspNetCore.Server.Kestrel var dateHeaderValueManager = new DateHeaderValueManager(); var trace = new KestrelTrace(_logger); + + IThreadPool threadPool; + if (InternalOptions.ThreadPoolDispatching) + { + threadPool = new LoggingThreadPool(trace); + } + else + { + threadPool = new InlineLoggingThreadPool(trace); + } + var engine = new KestrelEngine(new ServiceContext { FrameFactory = context => @@ -84,7 +99,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel }, AppLifetime = _applicationLifetime, Log = trace, - ThreadPool = new LoggingThreadPool(trace), + ThreadPool = threadPool, DateHeaderValueManager = dateHeaderValueManager, ServerOptions = Options }); diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionTests.cs index 2310329ff2..bd0b197235 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionTests.cs @@ -8,6 +8,7 @@ using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Server.Kestrel; using Microsoft.AspNetCore.Server.Kestrel.Internal; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; using Microsoft.AspNetCore.Server.KestrelTests.TestHelpers; using Microsoft.AspNetCore.Testing; @@ -22,42 +23,37 @@ namespace Microsoft.AspNetCore.Server.KestrelTests public async Task DoesNotEndConnectionOnZeroRead() { var mockLibuv = new MockLibuv(); + var serviceContext = new TestServiceContext + { + FrameFactory = connectionContext => new Frame( + new DummyApplication(httpContext => TaskCache.CompletedTask), connectionContext) + }; - using (var engine = new KestrelEngine(mockLibuv, new TestServiceContext())) + // Ensure ProcessRequestAsync runs inline with the ReadCallback + serviceContext.ThreadPool = new InlineLoggingThreadPool(serviceContext.Log); + + using (var engine = new KestrelEngine(mockLibuv, serviceContext)) { engine.Start(count: 1); - var trace = new TestKestrelTrace(); - var serviceContext = new TestServiceContext - { - FrameFactory = connectionContext => new Frame( - new DummyApplication(httpContext => TaskCache.CompletedTask), connectionContext), - }; - var context = new ListenerContext(serviceContext) + var listenerContext = new ListenerContext(serviceContext) { ListenOptions = new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0)), Thread = engine.Threads[0] }; Connection connection = null; - await context.Thread.PostAsync(_ => + await listenerContext.Thread.PostAsync(_ => { - var socket = new MockSocket(mockLibuv, Thread.CurrentThread.ManagedThreadId, trace); - connection = new Connection(context, socket); + var socket = new MockSocket(mockLibuv, Thread.CurrentThread.ManagedThreadId, serviceContext.Log); + connection = new Connection(listenerContext, socket); connection.Start(); Libuv.uv_buf_t ignored; mockLibuv.AllocCallback(socket.InternalGetHandle(), 2048, out ignored); + // This runs the ProcessRequestAsync inline mockLibuv.ReadCallback(socket.InternalGetHandle(), 0, ref ignored); - - }, (object)null); - // Wait until ProcessRequestAsync runs - // TODO: Remove when we get non dispatching support - await Task.Delay(1000); - - await context.Thread.PostAsync(_ => - { var readAwaitable = connection.Input.Reader.ReadAsync(); Assert.False(readAwaitable.IsCompleted); diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/SocketOutputTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/SocketOutputTests.cs index f28b1ba8c5..3bc33f1e55 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/SocketOutputTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/SocketOutputTests.cs @@ -69,7 +69,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var socket = new MockSocket(mockLibuv, kestrelThread.Loop.ThreadId, new TestKestrelTrace()); var trace = new KestrelTrace(new TestKestrelTrace()); - var ltp = new SynchronousThreadPool(); + var ltp = new InlineLoggingThreadPool(trace); var socketOutput = new SocketOutput(kestrelThread, socket, new MockConnection(options), "0", trace, ltp); // At least one run of this test should have a MaxResponseBufferSize < 1 MB. @@ -112,7 +112,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var socket = new MockSocket(mockLibuv, kestrelThread.Loop.ThreadId, new TestKestrelTrace()); var trace = new KestrelTrace(new TestKestrelTrace()); - var ltp = new SynchronousThreadPool(); + var ltp = new InlineLoggingThreadPool(trace); var options = new KestrelServerOptions { Limits = { MaxResponseBufferSize = null } }; var socketOutput = new SocketOutput(kestrelThread, socket, new MockConnection(options), "0", trace, ltp); @@ -163,7 +163,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var socket = new MockSocket(mockLibuv, kestrelThread.Loop.ThreadId, new TestKestrelTrace()); var trace = new KestrelTrace(new TestKestrelTrace()); - var ltp = new SynchronousThreadPool(); + var ltp = new InlineLoggingThreadPool(trace); var options = new KestrelServerOptions { Limits = { MaxResponseBufferSize = 0 } }; var socketOutput = new SocketOutput(kestrelThread, socket, new MockConnection(options), "0", trace, ltp); @@ -226,7 +226,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var socket = new MockSocket(mockLibuv, kestrelThread.Loop.ThreadId, new TestKestrelTrace()); var trace = new KestrelTrace(new TestKestrelTrace()); - var ltp = new SynchronousThreadPool(); + var ltp = new InlineLoggingThreadPool(trace); var mockConnection = new MockConnection(options); var socketOutput = new SocketOutput(kestrelThread, socket, mockConnection, "0", trace, ltp); @@ -298,7 +298,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var socket = new MockSocket(mockLibuv, kestrelThread.Loop.ThreadId, new TestKestrelTrace()); var trace = new KestrelTrace(new TestKestrelTrace()); - var ltp = new SynchronousThreadPool(); + var ltp = new InlineLoggingThreadPool(trace); var mockConnection = new MockConnection(options); var socketOutput = new SocketOutput(kestrelThread, socket, mockConnection, "0", trace, ltp); @@ -381,7 +381,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var socket = new MockSocket(mockLibuv, kestrelThread.Loop.ThreadId, new TestKestrelTrace()); var trace = new KestrelTrace(new TestKestrelTrace()); - var ltp = new SynchronousThreadPool(); + var ltp = new InlineLoggingThreadPool(trace); using (var mockConnection = new MockConnection(options)) { @@ -498,7 +498,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var socket = new MockSocket(mockLibuv, kestrelThread.Loop.ThreadId, new TestKestrelTrace()); var trace = new KestrelTrace(new TestKestrelTrace()); - var ltp = new SynchronousThreadPool(); + var ltp = new InlineLoggingThreadPool(trace); using (var mockConnection = new MockConnection(options)) { @@ -591,7 +591,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var socket = new MockSocket(mockLibuv, kestrelThread.Loop.ThreadId, new TestKestrelTrace()); var trace = new KestrelTrace(new TestKestrelTrace()); - var ltp = new SynchronousThreadPool(); + var ltp = new InlineLoggingThreadPool(trace); var mockConnection = new MockConnection(options); var socketOutput = new SocketOutput(kestrelThread, socket, mockConnection, "0", trace, ltp); @@ -671,7 +671,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var socket = new MockSocket(mockLibuv, kestrelThread.Loop.ThreadId, new TestKestrelTrace()); var trace = new KestrelTrace(new TestKestrelTrace()); - var ltp = new SynchronousThreadPool(); + var ltp = new InlineLoggingThreadPool(trace); var socketOutput = new SocketOutput(kestrelThread, socket, new MockConnection(options), "0", trace, ltp); // block 1 @@ -724,7 +724,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var socket = new MockSocket(mockLibuv, kestrelThread.Loop.ThreadId, new TestKestrelTrace()); var trace = new KestrelTrace(new TestKestrelTrace()); - var ltp = new SynchronousThreadPool(); + var ltp = new InlineLoggingThreadPool(trace); var mockConnection = new MockConnection(options); var socketOutput = new SocketOutput(kestrelThread, socket, mockConnection, "0", trace, ltp); @@ -796,7 +796,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var socket = new MockSocket(mockLibuv, kestrelThread.Loop.ThreadId, new TestKestrelTrace()); var trace = new KestrelTrace(new TestKestrelTrace()); - var ltp = new SynchronousThreadPool(); + var ltp = new InlineLoggingThreadPool(trace); var socketOutput = new SocketOutput(kestrelThread, socket, new MockConnection(new KestrelServerOptions()), "0", trace, ltp); mockLibuv.KestrelThreadBlocker.Reset(); @@ -842,7 +842,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var socket = new MockSocket(mockLibuv, kestrelThread.Loop.ThreadId, new TestKestrelTrace()); var trace = new KestrelTrace(new TestKestrelTrace()); - var ltp = new SynchronousThreadPool(); + var ltp = new InlineLoggingThreadPool(trace); var connection = new MockConnection(new KestrelServerOptions()); var socketOutput = new SocketOutput(kestrelThread, socket, connection, "0", trace, ltp); diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/SynchronousThreadPool.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/SynchronousThreadPool.cs deleted file mode 100644 index b4d35e6ee5..0000000000 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/SynchronousThreadPool.cs +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using System.Threading; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; - -namespace Microsoft.AspNetCore.Server.KestrelTests.TestHelpers -{ - public class SynchronousThreadPool : IThreadPool - { - public void Complete(TaskCompletionSource tcs) - { - tcs.TrySetResult(null); - } - - public void Cancel(TaskCompletionSource tcs) - { - tcs.TrySetCanceled(); - } - - public void Error(TaskCompletionSource tcs, Exception ex) - { - tcs.TrySetException(ex); - } - - public void Run(Action action) - { - action(); - } - - public void UnsafeRun(WaitCallback action, object state) - { - action(state); - } - - public void Schedule(Action action) - { - action(); - } - } -} diff --git a/test/shared/TestServiceContext.cs b/test/shared/TestServiceContext.cs index 7214c5e109..e7dc2c962f 100644 --- a/test/shared/TestServiceContext.cs +++ b/test/shared/TestServiceContext.cs @@ -4,7 +4,6 @@ using System; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Server.Kestrel; -using Microsoft.AspNetCore.Server.Kestrel.Adapter; using Microsoft.AspNetCore.Server.Kestrel.Internal; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; @@ -22,8 +21,11 @@ namespace Microsoft.AspNetCore.Testing ThreadPool = new LoggingThreadPool(Log); DateHeaderValueManager = new DateHeaderValueManager(systemClock: new MockSystemClock()); DateHeaderValue = DateHeaderValueManager.GetDateHeaderValues().String; - ServerOptions = new KestrelServerOptions { AddServerHeader = false }; - ServerOptions.ShutdownTimeout = TimeSpan.FromSeconds(5); + ServerOptions = new KestrelServerOptions + { + AddServerHeader = false, + ShutdownTimeout = TimeSpan.FromSeconds(5) + }; } public string DateHeaderValue { get; } From f5ac8c4ebd512a8887f72afb29757598844b9404 Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Tue, 28 Feb 2017 13:50:16 -0800 Subject: [PATCH 1062/1662] Don't require framework when running CodeGenerator. --- tools/CodeGenerator/CodeGenerator.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/CodeGenerator/CodeGenerator.csproj b/tools/CodeGenerator/CodeGenerator.csproj index c99ff50075..d581f31921 100644 --- a/tools/CodeGenerator/CodeGenerator.csproj +++ b/tools/CodeGenerator/CodeGenerator.csproj @@ -3,7 +3,7 @@ - netcoreapp1.1 + netcoreapp1.1 Exe false From 568aaff9c4eb661c83d8215d5f0e44b04956fd5e Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Tue, 28 Feb 2017 09:35:10 -0800 Subject: [PATCH 1063/1662] Improve HTTP parsing tests (#1393). - Add several more test cases - Share data between functional and unit tests --- KestrelHttpServer.sln | 63 ++-- .../Internal/Http/Frame.cs | 8 +- .../BadHttpRequestTests.cs | 136 ++++++++ .../BadHttpRequestTests.cs | 231 -------------- .../FrameTests.cs | 290 ++++++----------- test/shared/HttpParsingData.cs | 301 ++++++++++++++++++ 6 files changed, 579 insertions(+), 450 deletions(-) create mode 100644 test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/BadHttpRequestTests.cs delete mode 100644 test/Microsoft.AspNetCore.Server.KestrelTests/BadHttpRequestTests.cs create mode 100644 test/shared/HttpParsingData.cs diff --git a/KestrelHttpServer.sln b/KestrelHttpServer.sln index 24da20c0e0..10d207a841 100644 --- a/KestrelHttpServer.sln +++ b/KestrelHttpServer.sln @@ -1,6 +1,6 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 15 -VisualStudioVersion = 15.0.26206.0 +VisualStudioVersion = 15.0.26223.1 MinimumVisualStudioVersion = 10.0.40219.1 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{7972A5D6-3385-4127-9277-428506DD44FF}" ProjectSection(SolutionItems) = preProject @@ -21,6 +21,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "shared", "shared", "{0EF2AC ProjectSection(SolutionItems) = preProject test\shared\DummyApplication.cs = test\shared\DummyApplication.cs test\shared\HttpClientSlim.cs = test\shared\HttpClientSlim.cs + test\shared\HttpParsingData.cs = test\shared\HttpParsingData.cs test\shared\KestrelTestLoggerFactory.cs = test\shared\KestrelTestLoggerFactory.cs test\shared\LifetimeNotImplemented.cs = test\shared\LifetimeNotImplemented.cs test\shared\MockConnection.cs = test\shared\MockConnection.cs @@ -83,38 +84,38 @@ Global {F510611A-3BEE-4B88-A613-5F4A74ED82A1}.Release|x86.Build.0 = Release|Any CPU {37F3BFB2-6454-49E5-9D7F-581BF755CCFE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {37F3BFB2-6454-49E5-9D7F-581BF755CCFE}.Debug|Any CPU.Build.0 = Debug|Any CPU - {37F3BFB2-6454-49E5-9D7F-581BF755CCFE}.Debug|x64.ActiveCfg = Debug|x64 - {37F3BFB2-6454-49E5-9D7F-581BF755CCFE}.Debug|x64.Build.0 = Debug|x64 - {37F3BFB2-6454-49E5-9D7F-581BF755CCFE}.Debug|x86.ActiveCfg = Debug|x86 - {37F3BFB2-6454-49E5-9D7F-581BF755CCFE}.Debug|x86.Build.0 = Debug|x86 + {37F3BFB2-6454-49E5-9D7F-581BF755CCFE}.Debug|x64.ActiveCfg = Debug|Any CPU + {37F3BFB2-6454-49E5-9D7F-581BF755CCFE}.Debug|x64.Build.0 = Debug|Any CPU + {37F3BFB2-6454-49E5-9D7F-581BF755CCFE}.Debug|x86.ActiveCfg = Debug|Any CPU + {37F3BFB2-6454-49E5-9D7F-581BF755CCFE}.Debug|x86.Build.0 = Debug|Any CPU {37F3BFB2-6454-49E5-9D7F-581BF755CCFE}.Release|Any CPU.ActiveCfg = Release|Any CPU {37F3BFB2-6454-49E5-9D7F-581BF755CCFE}.Release|Any CPU.Build.0 = Release|Any CPU - {37F3BFB2-6454-49E5-9D7F-581BF755CCFE}.Release|x64.ActiveCfg = Release|x64 - {37F3BFB2-6454-49E5-9D7F-581BF755CCFE}.Release|x64.Build.0 = Release|x64 + {37F3BFB2-6454-49E5-9D7F-581BF755CCFE}.Release|x64.ActiveCfg = Release|Any CPU + {37F3BFB2-6454-49E5-9D7F-581BF755CCFE}.Release|x64.Build.0 = Release|Any CPU {37F3BFB2-6454-49E5-9D7F-581BF755CCFE}.Release|x86.ActiveCfg = Release|Any CPU {37F3BFB2-6454-49E5-9D7F-581BF755CCFE}.Release|x86.Build.0 = Release|Any CPU {2C3CB3DC-EEBF-4F52-9E1C-4F2F972E76C3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {2C3CB3DC-EEBF-4F52-9E1C-4F2F972E76C3}.Debug|Any CPU.Build.0 = Debug|Any CPU - {2C3CB3DC-EEBF-4F52-9E1C-4F2F972E76C3}.Debug|x64.ActiveCfg = Debug|x64 - {2C3CB3DC-EEBF-4F52-9E1C-4F2F972E76C3}.Debug|x64.Build.0 = Debug|x64 - {2C3CB3DC-EEBF-4F52-9E1C-4F2F972E76C3}.Debug|x86.ActiveCfg = Debug|x86 - {2C3CB3DC-EEBF-4F52-9E1C-4F2F972E76C3}.Debug|x86.Build.0 = Debug|x86 + {2C3CB3DC-EEBF-4F52-9E1C-4F2F972E76C3}.Debug|x64.ActiveCfg = Debug|Any CPU + {2C3CB3DC-EEBF-4F52-9E1C-4F2F972E76C3}.Debug|x64.Build.0 = Debug|Any CPU + {2C3CB3DC-EEBF-4F52-9E1C-4F2F972E76C3}.Debug|x86.ActiveCfg = Debug|Any CPU + {2C3CB3DC-EEBF-4F52-9E1C-4F2F972E76C3}.Debug|x86.Build.0 = Debug|Any CPU {2C3CB3DC-EEBF-4F52-9E1C-4F2F972E76C3}.Release|Any CPU.ActiveCfg = Release|Any CPU {2C3CB3DC-EEBF-4F52-9E1C-4F2F972E76C3}.Release|Any CPU.Build.0 = Release|Any CPU - {2C3CB3DC-EEBF-4F52-9E1C-4F2F972E76C3}.Release|x64.ActiveCfg = Release|x64 - {2C3CB3DC-EEBF-4F52-9E1C-4F2F972E76C3}.Release|x64.Build.0 = Release|x64 + {2C3CB3DC-EEBF-4F52-9E1C-4F2F972E76C3}.Release|x64.ActiveCfg = Release|Any CPU + {2C3CB3DC-EEBF-4F52-9E1C-4F2F972E76C3}.Release|x64.Build.0 = Release|Any CPU {2C3CB3DC-EEBF-4F52-9E1C-4F2F972E76C3}.Release|x86.ActiveCfg = Release|Any CPU {2C3CB3DC-EEBF-4F52-9E1C-4F2F972E76C3}.Release|x86.Build.0 = Release|Any CPU {B35D4D31-E74C-4646-8A11-7A7A40F0021E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {B35D4D31-E74C-4646-8A11-7A7A40F0021E}.Debug|Any CPU.Build.0 = Debug|Any CPU - {B35D4D31-E74C-4646-8A11-7A7A40F0021E}.Debug|x64.ActiveCfg = Debug|x64 - {B35D4D31-E74C-4646-8A11-7A7A40F0021E}.Debug|x64.Build.0 = Debug|x64 - {B35D4D31-E74C-4646-8A11-7A7A40F0021E}.Debug|x86.ActiveCfg = Debug|x86 - {B35D4D31-E74C-4646-8A11-7A7A40F0021E}.Debug|x86.Build.0 = Debug|x86 + {B35D4D31-E74C-4646-8A11-7A7A40F0021E}.Debug|x64.ActiveCfg = Debug|Any CPU + {B35D4D31-E74C-4646-8A11-7A7A40F0021E}.Debug|x64.Build.0 = Debug|Any CPU + {B35D4D31-E74C-4646-8A11-7A7A40F0021E}.Debug|x86.ActiveCfg = Debug|Any CPU + {B35D4D31-E74C-4646-8A11-7A7A40F0021E}.Debug|x86.Build.0 = Debug|Any CPU {B35D4D31-E74C-4646-8A11-7A7A40F0021E}.Release|Any CPU.ActiveCfg = Release|Any CPU {B35D4D31-E74C-4646-8A11-7A7A40F0021E}.Release|Any CPU.Build.0 = Release|Any CPU - {B35D4D31-E74C-4646-8A11-7A7A40F0021E}.Release|x64.ActiveCfg = Release|x64 - {B35D4D31-E74C-4646-8A11-7A7A40F0021E}.Release|x64.Build.0 = Release|x64 + {B35D4D31-E74C-4646-8A11-7A7A40F0021E}.Release|x64.ActiveCfg = Release|Any CPU + {B35D4D31-E74C-4646-8A11-7A7A40F0021E}.Release|x64.Build.0 = Release|Any CPU {B35D4D31-E74C-4646-8A11-7A7A40F0021E}.Release|x86.ActiveCfg = Release|Any CPU {B35D4D31-E74C-4646-8A11-7A7A40F0021E}.Release|x86.Build.0 = Release|Any CPU {BD2D4D29-1BD9-40D0-BB31-337D5416B63C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU @@ -143,26 +144,26 @@ Global {5F64B3C3-0C2E-431A-B820-A81BBFC863DA}.Release|x86.Build.0 = Release|Any CPU {9559A5F1-080C-4909-B6CF-7E4B3DC55748}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {9559A5F1-080C-4909-B6CF-7E4B3DC55748}.Debug|Any CPU.Build.0 = Debug|Any CPU - {9559A5F1-080C-4909-B6CF-7E4B3DC55748}.Debug|x64.ActiveCfg = Debug|x64 - {9559A5F1-080C-4909-B6CF-7E4B3DC55748}.Debug|x64.Build.0 = Debug|x64 - {9559A5F1-080C-4909-B6CF-7E4B3DC55748}.Debug|x86.ActiveCfg = Debug|x86 - {9559A5F1-080C-4909-B6CF-7E4B3DC55748}.Debug|x86.Build.0 = Debug|x86 + {9559A5F1-080C-4909-B6CF-7E4B3DC55748}.Debug|x64.ActiveCfg = Debug|Any CPU + {9559A5F1-080C-4909-B6CF-7E4B3DC55748}.Debug|x64.Build.0 = Debug|Any CPU + {9559A5F1-080C-4909-B6CF-7E4B3DC55748}.Debug|x86.ActiveCfg = Debug|Any CPU + {9559A5F1-080C-4909-B6CF-7E4B3DC55748}.Debug|x86.Build.0 = Debug|Any CPU {9559A5F1-080C-4909-B6CF-7E4B3DC55748}.Release|Any CPU.ActiveCfg = Release|Any CPU {9559A5F1-080C-4909-B6CF-7E4B3DC55748}.Release|Any CPU.Build.0 = Release|Any CPU - {9559A5F1-080C-4909-B6CF-7E4B3DC55748}.Release|x64.ActiveCfg = Release|x64 - {9559A5F1-080C-4909-B6CF-7E4B3DC55748}.Release|x64.Build.0 = Release|x64 + {9559A5F1-080C-4909-B6CF-7E4B3DC55748}.Release|x64.ActiveCfg = Release|Any CPU + {9559A5F1-080C-4909-B6CF-7E4B3DC55748}.Release|x64.Build.0 = Release|Any CPU {9559A5F1-080C-4909-B6CF-7E4B3DC55748}.Release|x86.ActiveCfg = Release|Any CPU {9559A5F1-080C-4909-B6CF-7E4B3DC55748}.Release|x86.Build.0 = Release|Any CPU {EBFE9719-A44B-4978-A71F-D5C254E7F35A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {EBFE9719-A44B-4978-A71F-D5C254E7F35A}.Debug|Any CPU.Build.0 = Debug|Any CPU - {EBFE9719-A44B-4978-A71F-D5C254E7F35A}.Debug|x64.ActiveCfg = Debug|x64 - {EBFE9719-A44B-4978-A71F-D5C254E7F35A}.Debug|x64.Build.0 = Debug|x64 - {EBFE9719-A44B-4978-A71F-D5C254E7F35A}.Debug|x86.ActiveCfg = Debug|x86 - {EBFE9719-A44B-4978-A71F-D5C254E7F35A}.Debug|x86.Build.0 = Debug|x86 + {EBFE9719-A44B-4978-A71F-D5C254E7F35A}.Debug|x64.ActiveCfg = Debug|Any CPU + {EBFE9719-A44B-4978-A71F-D5C254E7F35A}.Debug|x64.Build.0 = Debug|Any CPU + {EBFE9719-A44B-4978-A71F-D5C254E7F35A}.Debug|x86.ActiveCfg = Debug|Any CPU + {EBFE9719-A44B-4978-A71F-D5C254E7F35A}.Debug|x86.Build.0 = Debug|Any CPU {EBFE9719-A44B-4978-A71F-D5C254E7F35A}.Release|Any CPU.ActiveCfg = Release|Any CPU {EBFE9719-A44B-4978-A71F-D5C254E7F35A}.Release|Any CPU.Build.0 = Release|Any CPU - {EBFE9719-A44B-4978-A71F-D5C254E7F35A}.Release|x64.ActiveCfg = Release|x64 - {EBFE9719-A44B-4978-A71F-D5C254E7F35A}.Release|x64.Build.0 = Release|x64 + {EBFE9719-A44B-4978-A71F-D5C254E7F35A}.Release|x64.ActiveCfg = Release|Any CPU + {EBFE9719-A44B-4978-A71F-D5C254E7F35A}.Release|x64.Build.0 = Release|Any CPU {EBFE9719-A44B-4978-A71F-D5C254E7F35A}.Release|x86.ActiveCfg = Release|Any CPU {EBFE9719-A44B-4978-A71F-D5C254E7F35A}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs index 046c29c0e6..f3d6787b55 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs @@ -1129,6 +1129,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } else if (ch == BytePercentage) { + if (pathStart == -1) + { + // Empty path is illegal + RejectRequestLine(start, end); + } + needDecode = true; } @@ -1268,7 +1274,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { const int MaxRequestLineError = 32; RejectRequest(RequestRejectionReason.InvalidRequestLine, - Log.IsEnabled(LogLevel.Information) ? start.GetAsciiStringEscaped(end, MaxRequestLineError) : string.Empty); + Log.IsEnabled(LogLevel.Information) ? start.GetAsciiStringEscaped(end, MaxRequestLineError) : string.Empty); } private static bool IsValidTokenChar(char c) diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/BadHttpRequestTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/BadHttpRequestTests.cs new file mode 100644 index 0000000000..0394b7fcd3 --- /dev/null +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/BadHttpRequestTests.cs @@ -0,0 +1,136 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Testing; +using Microsoft.Extensions.Internal; +using Xunit; + +namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests +{ + public class BadHttpRequestTests + { + [Theory] + [MemberData(nameof(InvalidRequestLineData))] + public async Task TestInvalidRequestLines(string request) + { + using (var server = new TestServer(context => TaskCache.CompletedTask)) + { + using (var connection = server.CreateConnection()) + { + await connection.SendAll(request); + await ReceiveBadRequestResponse(connection, "400 Bad Request", server.Context.DateHeaderValue); + } + } + } + + [Theory] + [MemberData(nameof(UnrecognizedHttpVersionData))] + public async Task TestInvalidRequestLinesWithUnrecognizedVersion(string httpVersion) + { + using (var server = new TestServer(context => TaskCache.CompletedTask)) + { + using (var connection = server.CreateConnection()) + { + await connection.SendAll($"GET / {httpVersion}\r\n"); + await ReceiveBadRequestResponse(connection, "505 HTTP Version Not Supported", server.Context.DateHeaderValue); + } + } + } + + [Theory] + [MemberData(nameof(InvalidRequestHeaderData))] + public async Task TestInvalidHeaders(string rawHeaders) + { + using (var server = new TestServer(context => TaskCache.CompletedTask)) + { + using (var connection = server.CreateConnection()) + { + await connection.SendAll($"GET / HTTP/1.1\r\n{rawHeaders}"); + await ReceiveBadRequestResponse(connection, "400 Bad Request", server.Context.DateHeaderValue); + } + } + } + + [Fact] + public async Task BadRequestWhenHeaderNameContainsNonASCIICharacters() + { + using (var server = new TestServer(context => { return Task.FromResult(0); })) + { + using (var connection = server.CreateConnection()) + { + await connection.SendAll( + "GET / HTTP/1.1", + "H\u00eb\u00e4d\u00ebr: value", + "", + ""); + await ReceiveBadRequestResponse(connection, "400 Bad Request", server.Context.DateHeaderValue); + } + } + } + + [Theory] + [InlineData("POST")] + [InlineData("PUT")] + public async Task BadRequestIfMethodRequiresLengthButNoContentLengthOrTransferEncodingInRequest(string method) + { + using (var server = new TestServer(context => { return Task.FromResult(0); })) + { + using (var connection = server.CreateConnection()) + { + await connection.Send($"{method} / HTTP/1.1\r\n\r\n"); + await ReceiveBadRequestResponse(connection, "411 Length Required", server.Context.DateHeaderValue); + } + } + } + + [Theory] + [InlineData("POST")] + [InlineData("PUT")] + public async Task BadRequestIfMethodRequiresLengthButNoContentLengthInHttp10Request(string method) + { + using (var server = new TestServer(context => { return Task.FromResult(0); })) + { + using (var connection = server.CreateConnection()) + { + await connection.Send($"{method} / HTTP/1.0\r\n\r\n"); + await ReceiveBadRequestResponse(connection, "400 Bad Request", server.Context.DateHeaderValue); + } + } + } + + [Theory] + [InlineData("NaN")] + [InlineData("-1")] + public async Task BadRequestIfContentLengthInvalid(string contentLength) + { + using (var server = new TestServer(context => { return Task.FromResult(0); })) + { + using (var connection = server.CreateConnection()) + { + await connection.SendAll($"GET / HTTP/1.1\r\nContent-Length: {contentLength}\r\n\r\n"); + await ReceiveBadRequestResponse(connection, "400 Bad Request", server.Context.DateHeaderValue); + } + } + } + + private async Task ReceiveBadRequestResponse(TestConnection connection, string expectedResponseStatusCode, string expectedDateHeaderValue) + { + await connection.ReceiveForcedEnd( + $"HTTP/1.1 {expectedResponseStatusCode}", + "Connection: close", + $"Date: {expectedDateHeaderValue}", + "Content-Length: 0", + "", + ""); + } + + public static IEnumerable InvalidRequestLineData => HttpParsingData.InvalidRequestLineData.Select(data => new[] { data[0] }); + + public static TheoryData UnrecognizedHttpVersionData => HttpParsingData.UnrecognizedHttpVersionData; + + public static IEnumerable InvalidRequestHeaderData => HttpParsingData.InvalidRequestHeaderData.Select(data => new[] { data[0] }); + } +} diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/BadHttpRequestTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/BadHttpRequestTests.cs deleted file mode 100644 index cf3ebc03de..0000000000 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/BadHttpRequestTests.cs +++ /dev/null @@ -1,231 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System.Threading.Tasks; -using Microsoft.AspNetCore.Testing; -using Microsoft.Extensions.Internal; -using Xunit; - -namespace Microsoft.AspNetCore.Server.KestrelTests -{ - public class BadHttpRequestTests - { - // All test cases for this theory must end in '\n', otherwise the server will spin forever - [Theory] - // Incomplete request lines - [InlineData("G\r\n")] - [InlineData("GE\r\n")] - [InlineData("GET\r\n")] - [InlineData("GET \r\n")] - [InlineData("GET /\r\n")] - [InlineData("GET / \r\n")] - // Missing method - [InlineData(" \r\n")] - // Missing second space - [InlineData("/ \r\n")] // This fails trying to read the '/' because that's invalid for an HTTP method - [InlineData("GET /\r\n")] - // Missing target - [InlineData("GET \r\n")] - // Missing version - [InlineData("GET / \r\n")] - // Missing CR - [InlineData("GET / \n")] - // Missing LF after CR - [InlineData("GET / HTTP/1.0\rA\n")] - // Bad HTTP Methods (invalid according to RFC) - [InlineData("( / HTTP/1.0\r\n")] - [InlineData(") / HTTP/1.0\r\n")] - [InlineData("< / HTTP/1.0\r\n")] - [InlineData("> / HTTP/1.0\r\n")] - [InlineData("@ / HTTP/1.0\r\n")] - [InlineData(", / HTTP/1.0\r\n")] - [InlineData("; / HTTP/1.0\r\n")] - [InlineData(": / HTTP/1.0\r\n")] - [InlineData("\\ / HTTP/1.0\r\n")] - [InlineData("\" / HTTP/1.0\r\n")] - [InlineData("/ / HTTP/1.0\r\n")] - [InlineData("[ / HTTP/1.0\r\n")] - [InlineData("] / HTTP/1.0\r\n")] - [InlineData("? / HTTP/1.0\r\n")] - [InlineData("= / HTTP/1.0\r\n")] - [InlineData("{ / HTTP/1.0\r\n")] - [InlineData("} / HTTP/1.0\r\n")] - [InlineData("get@ / HTTP/1.0\r\n")] - [InlineData("post= / HTTP/1.0\r\n")] - public async Task TestInvalidRequestLines(string request) - { - using (var server = new TestServer(context => TaskCache.CompletedTask)) - { - using (var connection = server.CreateConnection()) - { - await connection.SendAll(request); - await ReceiveBadRequestResponse(connection, "400 Bad Request", server.Context.DateHeaderValue); - } - } - } - - [Theory] - [InlineData("GET / H\r\n")] - [InlineData("GET / HT\r\n")] - [InlineData("GET / HTT\r\n")] - [InlineData("GET / HTTP\r\n")] - [InlineData("GET / HTTP/\r\n")] - [InlineData("GET / HTTP/1\r\n")] - [InlineData("GET / HTTP/1.\r\n")] - [InlineData("GET / http/1.0\r\n")] - [InlineData("GET / http/1.1\r\n")] - [InlineData("GET / HTTP/1.1 \r\n")] - [InlineData("GET / HTTP/1.1a\r\n")] - [InlineData("GET / HTTP/1.2\r\n")] - [InlineData("GET / HTTP/3.0\r\n")] - [InlineData("GET / H\r\n")] - [InlineData("GET / HTTP/1.\r\n")] - [InlineData("GET / hello\r\n")] - [InlineData("GET / 8charact\r\n")] - public async Task TestInvalidRequestLinesWithUnsupportedVersion(string request) - { - using (var server = new TestServer(context => TaskCache.CompletedTask)) - { - using (var connection = server.CreateConnection()) - { - await connection.SendAll(request); - await ReceiveBadRequestResponse(connection, "505 HTTP Version Not Supported", server.Context.DateHeaderValue); - } - } - } - - [Theory] - // Leading whitespace - [InlineData(" Header-1: value1\r\nHeader-2: value2\r\n\r\n")] - [InlineData("\tHeader-1: value1\r\nHeader-2: value2\r\n\r\n")] - [InlineData("Header-1: value1\r\n Header-2: value2\r\n\r\n")] - [InlineData("Header-1: value1\r\n\tHeader-2: value2\r\n\r\n")] - // Missing LF - [InlineData("Header-1: value1\rHeader-2: value2\r\n\r\n")] - [InlineData("Header-1: value1\r\nHeader-2: value2\r\r\n")] - // Line folding - [InlineData("Header-1: multi\r\n line\r\nHeader-2: value2\r\n\r\n")] - [InlineData("Header-1: value1\r\nHeader-2: multi\r\n line\r\n\r\n")] - // Missing ':' - [InlineData("Header-1 value1\r\nHeader-2: value2\r\n\r\n")] - [InlineData("Header-1: value1\r\nHeader-2 value2\r\n\r\n")] - // Whitespace in header name - [InlineData("Header 1: value1\r\nHeader-2: value2\r\n\r\n")] - [InlineData("Header-1: value1\r\nHeader 2: value2\r\n\r\n")] - [InlineData("Header-1 : value1\r\nHeader-2: value2\r\n\r\n")] - [InlineData("Header-1\t: value1\r\nHeader-2: value2\r\n\r\n")] - [InlineData("Header-1: value1\r\nHeader-2 : value2\r\n\r\n")] - [InlineData("Header-1: value1\r\nHeader-2\t: value2\r\n\r\n")] - public async Task TestInvalidHeaders(string rawHeaders) - { - using (var server = new TestServer(context => TaskCache.CompletedTask)) - { - using (var connection = server.CreateConnection()) - { - await connection.SendAll($"GET / HTTP/1.1\r\n{rawHeaders}"); - await ReceiveBadRequestResponse(connection, "400 Bad Request", server.Context.DateHeaderValue); - } - } - } - - [Fact] - public async Task BadRequestWhenNameHeaderNamesContainsNonASCIICharacters() - { - using (var server = new TestServer(context => { return Task.FromResult(0); })) - { - using (var connection = server.CreateConnection()) - { - await connection.SendAll( - "GET / HTTP/1.1", - "H\u00eb\u00e4d\u00ebr: value", - "", - ""); - await ReceiveBadRequestResponse(connection, "400 Bad Request", server.Context.DateHeaderValue); - } - } - } - - [Theory] - [InlineData("\0")] - [InlineData("%00")] - [InlineData("/\0")] - [InlineData("/%00")] - [InlineData("/\0\0")] - [InlineData("/%00%00")] - [InlineData("/%C8\0")] - [InlineData("/%E8%00%84")] - [InlineData("/%E8%85%00")] - [InlineData("/%F3%00%82%86")] - [InlineData("/%F3%85%00%82")] - [InlineData("/%F3%85%82%00")] - [InlineData("/%E8%85%00")] - [InlineData("/%E8%01%00")] - public async Task BadRequestIfPathContainsNullCharacters(string path) - { - using (var server = new TestServer(context => { return Task.FromResult(0); })) - { - using (var connection = server.CreateConnection()) - { - await connection.SendAll($"GET {path} HTTP/1.1\r\n"); - await ReceiveBadRequestResponse(connection, "400 Bad Request", server.Context.DateHeaderValue); - } - } - } - - [Theory] - [InlineData("POST")] - [InlineData("PUT")] - public async Task BadRequestIfMethodRequiresLengthButNoContentLengthOrTransferEncodingInRequest(string method) - { - using (var server = new TestServer(context => { return Task.FromResult(0); })) - { - using (var connection = server.CreateConnection()) - { - await connection.Send($"{method} / HTTP/1.1\r\n\r\n"); - await ReceiveBadRequestResponse(connection, "411 Length Required", server.Context.DateHeaderValue); - } - } - } - - [Theory] - [InlineData("POST")] - [InlineData("PUT")] - public async Task BadRequestIfMethodRequiresLengthButNoContentLengthInHttp10Request(string method) - { - using (var server = new TestServer(context => { return Task.FromResult(0); })) - { - using (var connection = server.CreateConnection()) - { - await connection.Send($"{method} / HTTP/1.0\r\n\r\n"); - await ReceiveBadRequestResponse(connection, "400 Bad Request", server.Context.DateHeaderValue); - } - } - } - - [Theory] - [InlineData("NaN")] - [InlineData("-1")] - public async Task BadRequestIfContentLengthInvalid(string contentLength) - { - using (var server = new TestServer(context => { return Task.FromResult(0); })) - { - using (var connection = server.CreateConnection()) - { - await connection.SendAll($"GET / HTTP/1.1\r\nContent-Length: {contentLength}\r\n\r\n"); - await ReceiveBadRequestResponse(connection, "400 Bad Request", server.Context.DateHeaderValue); - } - } - } - - private async Task ReceiveBadRequestResponse(TestConnection connection, string expectedResponseStatusCode, string expectedDateHeaderValue) - { - await connection.ReceiveForcedEnd( - $"HTTP/1.1 {expectedResponseStatusCode}", - "Connection: close", - $"Date: {expectedDateHeaderValue}", - "Content-Length: 0", - "", - ""); - } - } -} diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs index d8f7dc701c..9e5fe001ef 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Collections.Generic; using System.IO; using System.IO.Pipelines; using System.Net; @@ -27,10 +28,9 @@ namespace Microsoft.AspNetCore.Server.KestrelTests private readonly TestFrame _frame; private readonly ServiceContext _serviceContext; private readonly ConnectionContext _connectionContext; - private PipeFactory _pipelineFactory; - - ReadCursor consumed; - ReadCursor examined; + private readonly PipeFactory _pipelineFactory; + private ReadCursor _consumed; + private ReadCursor _examined; private class TestFrame : Frame { @@ -88,13 +88,13 @@ namespace Microsoft.AspNetCore.Server.KestrelTests await _socketInput.Writer.WriteAsync(Encoding.ASCII.GetBytes("Header:value\r\n\r\n")); var readableBuffer = (await _socketInput.Reader.ReadAsync()).Buffer; - var success = _frame.TakeMessageHeaders(readableBuffer, (FrameRequestHeaders) _frame.RequestHeaders, out consumed, out examined); - _socketInput.Reader.Advance(consumed, examined); + var success = _frame.TakeMessageHeaders(readableBuffer, (FrameRequestHeaders)_frame.RequestHeaders, out _consumed, out _examined); + _socketInput.Reader.Advance(_consumed, _examined); Assert.True(success); Assert.Equal(1, _frame.RequestHeaders.Count); Assert.Equal("value", _frame.RequestHeaders["Header"]); - Assert.Equal(readableBuffer.End, consumed); + Assert.Equal(readableBuffer.End, _consumed); } [Theory] @@ -113,13 +113,13 @@ namespace Microsoft.AspNetCore.Server.KestrelTests await _socketInput.Writer.WriteAsync(Encoding.ASCII.GetBytes(rawHeaders)); var readableBuffer = (await _socketInput.Reader.ReadAsync()).Buffer; - var success = _frame.TakeMessageHeaders(readableBuffer, (FrameRequestHeaders)_frame.RequestHeaders, out consumed, out examined); - _socketInput.Reader.Advance(consumed, examined); + var success = _frame.TakeMessageHeaders(readableBuffer, (FrameRequestHeaders)_frame.RequestHeaders, out _consumed, out _examined); + _socketInput.Reader.Advance(_consumed, _examined); Assert.True(success); Assert.Equal(1, _frame.RequestHeaders.Count); Assert.Equal("value", _frame.RequestHeaders["Header"]); - Assert.Equal(readableBuffer.End, consumed); + Assert.Equal(readableBuffer.End, _consumed); } [Theory] @@ -137,13 +137,13 @@ namespace Microsoft.AspNetCore.Server.KestrelTests await _socketInput.Writer.WriteAsync(Encoding.ASCII.GetBytes(rawHeaders)); var readableBuffer = (await _socketInput.Reader.ReadAsync()).Buffer; - var success = _frame.TakeMessageHeaders(readableBuffer, (FrameRequestHeaders)_frame.RequestHeaders, out consumed, out examined); - _socketInput.Reader.Advance(consumed, examined); + var success = _frame.TakeMessageHeaders(readableBuffer, (FrameRequestHeaders)_frame.RequestHeaders, out _consumed, out _examined); + _socketInput.Reader.Advance(_consumed, _examined); Assert.True(success); Assert.Equal(1, _frame.RequestHeaders.Count); Assert.Equal("value", _frame.RequestHeaders["Header"]); - Assert.Equal(readableBuffer.End, consumed); + Assert.Equal(readableBuffer.End, _consumed); } [Theory] @@ -160,32 +160,26 @@ namespace Microsoft.AspNetCore.Server.KestrelTests await _socketInput.Writer.WriteAsync(Encoding.ASCII.GetBytes(rawHeaders)); var readableBuffer = (await _socketInput.Reader.ReadAsync()).Buffer; - var success = _frame.TakeMessageHeaders(readableBuffer, (FrameRequestHeaders)_frame.RequestHeaders, out consumed, out examined); - _socketInput.Reader.Advance(consumed, examined); + var success = _frame.TakeMessageHeaders(readableBuffer, (FrameRequestHeaders)_frame.RequestHeaders, out _consumed, out _examined); + _socketInput.Reader.Advance(_consumed, _examined); Assert.True(success); Assert.Equal(1, _frame.RequestHeaders.Count); Assert.Equal(expectedValue, _frame.RequestHeaders["Header"]); - Assert.Equal(readableBuffer.End, consumed); + Assert.Equal(readableBuffer.End, _consumed); } [Theory] - [InlineData("Header: line1\r\n line2\r\n\r\n")] - [InlineData("Header: line1\r\n\tline2\r\n\r\n")] - [InlineData("Header: line1\r\n line2\r\n\r\n")] - [InlineData("Header: line1\r\n \tline2\r\n\r\n")] - [InlineData("Header: line1\r\n\t line2\r\n\r\n")] - [InlineData("Header: line1\r\n\t\tline2\r\n\r\n")] - [InlineData("Header: line1\r\n \t\t line2\r\n\r\n")] - [InlineData("Header: line1\r\n \t \t line2\r\n\r\n")] - public async Task TakeMessageHeadersThrowsOnHeaderValueWithLineFolding(string rawHeaders) + [MemberData(nameof(InvalidRequestHeaderData))] + public async Task TakeMessageHeadersThrowsOnInvalidRequestHeaders(string rawHeaders, string expectedExceptionMessage) { await _socketInput.Writer.WriteAsync(Encoding.ASCII.GetBytes(rawHeaders)); var readableBuffer = (await _socketInput.Reader.ReadAsync()).Buffer; - _socketInput.Reader.Advance(consumed, examined); - var exception = Assert.Throws(() => _frame.TakeMessageHeaders(readableBuffer, (FrameRequestHeaders)_frame.RequestHeaders, out consumed, out examined)); - Assert.Equal("Header value line folding not supported.", exception.Message); + var exception = Assert.Throws(() => _frame.TakeMessageHeaders(readableBuffer, (FrameRequestHeaders)_frame.RequestHeaders, out _consumed, out _examined)); + _socketInput.Reader.Advance(_consumed, _examined); + + Assert.Equal(expectedExceptionMessage, exception.Message); Assert.Equal(StatusCodes.Status400BadRequest, exception.StatusCode); } @@ -195,107 +189,19 @@ namespace Microsoft.AspNetCore.Server.KestrelTests await _socketInput.Writer.WriteAsync(Encoding.ASCII.GetBytes("Header-1: value1\r\n")); var readableBuffer = (await _socketInput.Reader.ReadAsync()).Buffer; - Assert.False(_frame.TakeMessageHeaders(readableBuffer, (FrameRequestHeaders)_frame.RequestHeaders, out consumed, out examined)); - _socketInput.Reader.Advance(consumed, examined); + Assert.False(_frame.TakeMessageHeaders(readableBuffer, (FrameRequestHeaders)_frame.RequestHeaders, out _consumed, out _examined)); + _socketInput.Reader.Advance(_consumed, _examined); await _socketInput.Writer.WriteAsync(Encoding.ASCII.GetBytes(" ")); readableBuffer = (await _socketInput.Reader.ReadAsync()).Buffer; - var exception = Assert.Throws(() => _frame.TakeMessageHeaders(readableBuffer, (FrameRequestHeaders)_frame.RequestHeaders, out consumed, out examined)); - _socketInput.Reader.Advance(consumed, examined); + var exception = Assert.Throws(() => _frame.TakeMessageHeaders(readableBuffer, (FrameRequestHeaders)_frame.RequestHeaders, out _consumed, out _examined)); + _socketInput.Reader.Advance(_consumed, _examined); Assert.Equal("Header value line folding not supported.", exception.Message); Assert.Equal(StatusCodes.Status400BadRequest, exception.StatusCode); } - [Theory] - [InlineData("Header-1: value1\r\r\n")] - [InlineData("Header-1: val\rue1\r\n")] - [InlineData("Header-1: value1\rHeader-2: value2\r\n\r\n")] - [InlineData("Header-1: value1\r\nHeader-2: value2\r\r\n")] - [InlineData("Header-1: value1\r\nHeader-2: v\ralue2\r\n")] - public async Task TakeMessageHeadersThrowsOnHeaderValueContainingCR(string rawHeaders) - { - await _socketInput.Writer.WriteAsync(Encoding.ASCII.GetBytes(rawHeaders)); - var readableBuffer = (await _socketInput.Reader.ReadAsync()).Buffer; - - var exception = Assert.Throws(() => _frame.TakeMessageHeaders(readableBuffer, (FrameRequestHeaders)_frame.RequestHeaders, out consumed, out examined)); - _socketInput.Reader.Advance(consumed, examined); - - Assert.Equal("Header value must not contain CR characters.", exception.Message); - Assert.Equal(StatusCodes.Status400BadRequest, exception.StatusCode); - } - - [Theory] - [InlineData("Header-1 value1\r\n\r\n")] - [InlineData("Header-1 value1\r\nHeader-2: value2\r\n\r\n")] - [InlineData("Header-1: value1\r\nHeader-2 value2\r\n\r\n")] - public async Task TakeMessageHeadersThrowsOnHeaderLineMissingColon(string rawHeaders) - { - await _socketInput.Writer.WriteAsync(Encoding.ASCII.GetBytes(rawHeaders)); - var readableBuffer = (await _socketInput.Reader.ReadAsync()).Buffer; - - var exception = Assert.Throws(() => _frame.TakeMessageHeaders(readableBuffer, (FrameRequestHeaders)_frame.RequestHeaders, out consumed, out examined)); - _socketInput.Reader.Advance(consumed, examined); - - Assert.Equal("No ':' character found in header line.", exception.Message); - Assert.Equal(StatusCodes.Status400BadRequest, exception.StatusCode); - } - - [Theory] - [InlineData(" Header: value\r\n\r\n")] - [InlineData("\tHeader: value\r\n\r\n")] - [InlineData(" Header-1: value1\r\nHeader-2: value2\r\n\r\n")] - [InlineData("\tHeader-1: value1\r\nHeader-2: value2\r\n\r\n")] - public async Task TakeMessageHeadersThrowsOnHeaderLineStartingWithWhitespace(string rawHeaders) - { - await _socketInput.Writer.WriteAsync(Encoding.ASCII.GetBytes(rawHeaders)); - var readableBuffer = (await _socketInput.Reader.ReadAsync()).Buffer; - - var exception = Assert.Throws(() => _frame.TakeMessageHeaders(readableBuffer, (FrameRequestHeaders)_frame.RequestHeaders, out consumed, out examined)); - _socketInput.Reader.Advance(consumed, examined); - - Assert.Equal("Header line must not start with whitespace.", exception.Message); - Assert.Equal(StatusCodes.Status400BadRequest, exception.StatusCode); - } - - [Theory] - [InlineData("Header : value\r\n\r\n")] - [InlineData("Header\t: value\r\n\r\n")] - [InlineData("Header 1: value1\r\nHeader-2: value2\r\n\r\n")] - [InlineData("Header 1 : value1\r\nHeader-2: value2\r\n\r\n")] - [InlineData("Header 1\t: value1\r\nHeader-2: value2\r\n\r\n")] - [InlineData("Header-1: value1\r\nHeader 2: value2\r\n\r\n")] - [InlineData("Header-1: value1\r\nHeader-2 : value2\r\n\r\n")] - [InlineData("Header-1: value1\r\nHeader-2\t: value2\r\n\r\n")] - public async Task TakeMessageHeadersThrowsOnWhitespaceInHeaderName(string rawHeaders) - { - await _socketInput.Writer.WriteAsync(Encoding.ASCII.GetBytes(rawHeaders)); - var readableBuffer = (await _socketInput.Reader.ReadAsync()).Buffer; - - var exception = Assert.Throws(() => _frame.TakeMessageHeaders(readableBuffer, (FrameRequestHeaders)_frame.RequestHeaders, out consumed, out examined)); - _socketInput.Reader.Advance(consumed, examined); - - Assert.Equal("Whitespace is not allowed in header name.", exception.Message); - Assert.Equal(StatusCodes.Status400BadRequest, exception.StatusCode); - } - - [Theory] - [InlineData("Header-1: value1\r\nHeader-2: value2\r\n\r\r")] - [InlineData("Header-1: value1\r\nHeader-2: value2\r\n\r ")] - [InlineData("Header-1: value1\r\nHeader-2: value2\r\n\r \n")] - public async Task TakeMessageHeadersThrowsOnHeadersNotEndingInCRLFLine(string rawHeaders) - { - await _socketInput.Writer.WriteAsync(Encoding.ASCII.GetBytes(rawHeaders)); - var readableBuffer = (await _socketInput.Reader.ReadAsync()).Buffer; - - var exception = Assert.Throws(() => _frame.TakeMessageHeaders(readableBuffer, (FrameRequestHeaders)_frame.RequestHeaders, out consumed, out examined)); - _socketInput.Reader.Advance(consumed, examined); - - Assert.Equal("Headers corrupted, invalid header sequence.", exception.Message); - Assert.Equal(StatusCodes.Status400BadRequest, exception.StatusCode); - } - [Fact] public async Task TakeMessageHeadersThrowsWhenHeadersExceedTotalSizeLimit() { @@ -306,8 +212,8 @@ namespace Microsoft.AspNetCore.Server.KestrelTests await _socketInput.Writer.WriteAsync(Encoding.ASCII.GetBytes($"{headerLine}\r\n")); var readableBuffer = (await _socketInput.Reader.ReadAsync()).Buffer; - var exception = Assert.Throws(() => _frame.TakeMessageHeaders(readableBuffer, (FrameRequestHeaders)_frame.RequestHeaders, out consumed, out examined)); - _socketInput.Reader.Advance(consumed, examined); + var exception = Assert.Throws(() => _frame.TakeMessageHeaders(readableBuffer, (FrameRequestHeaders)_frame.RequestHeaders, out _consumed, out _examined)); + _socketInput.Reader.Advance(_consumed, _examined); Assert.Equal("Request headers too long.", exception.Message); Assert.Equal(StatusCodes.Status431RequestHeaderFieldsTooLarge, exception.StatusCode); @@ -322,8 +228,8 @@ namespace Microsoft.AspNetCore.Server.KestrelTests await _socketInput.Writer.WriteAsync(Encoding.ASCII.GetBytes($"{headerLines}\r\n")); var readableBuffer = (await _socketInput.Reader.ReadAsync()).Buffer; - var exception = Assert.Throws(() => _frame.TakeMessageHeaders(readableBuffer, (FrameRequestHeaders)_frame.RequestHeaders, out consumed, out examined)); - _socketInput.Reader.Advance(consumed, examined); + var exception = Assert.Throws(() => _frame.TakeMessageHeaders(readableBuffer, (FrameRequestHeaders)_frame.RequestHeaders, out _consumed, out _examined)); + _socketInput.Reader.Advance(_consumed, _examined); Assert.Equal("Request contains too many headers.", exception.Message); Assert.Equal(StatusCodes.Status431RequestHeaderFieldsTooLarge, exception.StatusCode); @@ -341,12 +247,12 @@ namespace Microsoft.AspNetCore.Server.KestrelTests await _socketInput.Writer.WriteAsync(Encoding.ASCII.GetBytes(rawHeaders)); var readableBuffer = (await _socketInput.Reader.ReadAsync()).Buffer; - var success = _frame.TakeMessageHeaders(readableBuffer, (FrameRequestHeaders)_frame.RequestHeaders, out consumed, out examined); - _socketInput.Reader.Advance(consumed, examined); + var success = _frame.TakeMessageHeaders(readableBuffer, (FrameRequestHeaders)_frame.RequestHeaders, out _consumed, out _examined); + _socketInput.Reader.Advance(_consumed, _examined); Assert.True(success); Assert.Equal(numHeaders, _frame.RequestHeaders.Count); - Assert.Equal(readableBuffer.End, consumed); + Assert.Equal(readableBuffer.End, _consumed); } [Fact] @@ -375,8 +281,8 @@ namespace Microsoft.AspNetCore.Server.KestrelTests await _socketInput.Writer.WriteAsync(Encoding.ASCII.GetBytes($"{headerLine1}\r\n")); var readableBuffer = (await _socketInput.Reader.ReadAsync()).Buffer; - var takeMessageHeaders = _frame.TakeMessageHeaders(readableBuffer, (FrameRequestHeaders)_frame.RequestHeaders, out consumed, out examined); - _socketInput.Reader.Advance(consumed, examined); + var takeMessageHeaders = _frame.TakeMessageHeaders(readableBuffer, (FrameRequestHeaders)_frame.RequestHeaders, out _consumed, out _examined); + _socketInput.Reader.Advance(_consumed, _examined); Assert.True(takeMessageHeaders); Assert.Equal(1, _frame.RequestHeaders.Count); @@ -387,8 +293,8 @@ namespace Microsoft.AspNetCore.Server.KestrelTests await _socketInput.Writer.WriteAsync(Encoding.ASCII.GetBytes($"{headerLine2}\r\n")); readableBuffer = (await _socketInput.Reader.ReadAsync()).Buffer; - takeMessageHeaders = _frame.TakeMessageHeaders(readableBuffer, (FrameRequestHeaders)_frame.RequestHeaders, out consumed, out examined); - _socketInput.Reader.Advance(consumed, examined); + takeMessageHeaders = _frame.TakeMessageHeaders(readableBuffer, (FrameRequestHeaders)_frame.RequestHeaders, out _consumed, out _examined); + _socketInput.Reader.Advance(_consumed, _examined); Assert.True(takeMessageHeaders); Assert.Equal(1, _frame.RequestHeaders.Count); @@ -478,6 +384,29 @@ namespace Microsoft.AspNetCore.Server.KestrelTests Assert.Same(originalDuplexStream, _frame.DuplexStream); } + [Theory] + [MemberData(nameof(ValidRequestLineData))] + public async Task TakeStartLineSetsFrameProperties( + string requestLine, + string expectedMethod, + string expectedPath, + string expectedQueryString, + string expectedHttpVersion) + { + var requestLineBytes = Encoding.ASCII.GetBytes(requestLine); + await _socketInput.Writer.WriteAsync(requestLineBytes); + var readableBuffer = (await _socketInput.Reader.ReadAsync()).Buffer; + + var returnValue = _frame.TakeStartLine(readableBuffer, out _consumed, out _examined); + _socketInput.Reader.Advance(_consumed, _examined); + + Assert.True(returnValue); + Assert.Equal(expectedMethod, _frame.Method); + Assert.Equal(expectedPath, _frame.Path); + Assert.Equal(expectedQueryString, _frame.QueryString); + Assert.Equal(expectedHttpVersion, _frame.HttpVersion); + } + [Fact] public async Task TakeStartLineCallsConsumingCompleteWithFurthestExamined() { @@ -485,21 +414,21 @@ namespace Microsoft.AspNetCore.Server.KestrelTests await _socketInput.Writer.WriteAsync(requestLineBytes); var readableBuffer = (await _socketInput.Reader.ReadAsync()).Buffer; - _frame.TakeStartLine(readableBuffer, out consumed, out examined); - _socketInput.Reader.Advance(consumed, examined); + _frame.TakeStartLine(readableBuffer, out _consumed, out _examined); + _socketInput.Reader.Advance(_consumed, _examined); - Assert.Equal(readableBuffer.Start, consumed); - Assert.Equal(readableBuffer.End, examined); + Assert.Equal(readableBuffer.Start, _consumed); + Assert.Equal(readableBuffer.End, _examined); requestLineBytes = Encoding.ASCII.GetBytes("HTTP/1.1\r\n"); await _socketInput.Writer.WriteAsync(requestLineBytes); readableBuffer = (await _socketInput.Reader.ReadAsync()).Buffer; - _frame.TakeStartLine(readableBuffer, out consumed, out examined); - _socketInput.Reader.Advance(consumed, examined); + _frame.TakeStartLine(readableBuffer, out _consumed, out _examined); + _socketInput.Reader.Advance(_consumed, _examined); - Assert.Equal(readableBuffer.End, consumed); - Assert.Equal(readableBuffer.End, examined); + Assert.Equal(readableBuffer.End, _consumed); + Assert.Equal(readableBuffer.End, _examined); } [Theory] @@ -524,8 +453,8 @@ namespace Microsoft.AspNetCore.Server.KestrelTests await _socketInput.Writer.WriteAsync(requestLineBytes); var readableBuffer = (await _socketInput.Reader.ReadAsync()).Buffer; - var returnValue = _frame.TakeStartLine(readableBuffer, out consumed, out examined); - _socketInput.Reader.Advance(consumed, examined); + var returnValue = _frame.TakeStartLine(readableBuffer, out _consumed, out _examined); + _socketInput.Reader.Advance(_consumed, _examined); Assert.False(returnValue); } @@ -538,8 +467,8 @@ namespace Microsoft.AspNetCore.Server.KestrelTests await _socketInput.Writer.WriteAsync(Encoding.ASCII.GetBytes("G")); - _frame.TakeStartLine((await _socketInput.Reader.ReadAsync()).Buffer, out consumed, out examined); - _socketInput.Reader.Advance(consumed, examined); + _frame.TakeStartLine((await _socketInput.Reader.ReadAsync()).Buffer, out _consumed, out _examined); + _socketInput.Reader.Advance(_consumed, _examined); var expectedRequestHeadersTimeout = (long)_serviceContext.ServerOptions.Limits.RequestHeadersTimeout.TotalMilliseconds; connectionControl.Verify(cc => cc.ResetTimeout(expectedRequestHeadersTimeout, TimeoutAction.SendTimeoutResponse)); @@ -554,79 +483,58 @@ namespace Microsoft.AspNetCore.Server.KestrelTests await _socketInput.Writer.WriteAsync(requestLineBytes); var readableBuffer = (await _socketInput.Reader.ReadAsync()).Buffer; - var exception = Assert.Throws(() => _frame.TakeStartLine(readableBuffer, out consumed, out examined)); - _socketInput.Reader.Advance(consumed, examined); + var exception = Assert.Throws(() =>_frame.TakeStartLine(readableBuffer, out _consumed, out _examined)); + _socketInput.Reader.Advance(_consumed, _examined); Assert.Equal("Request line too long.", exception.Message); Assert.Equal(StatusCodes.Status414UriTooLong, exception.StatusCode); } [Theory] - [InlineData("GET/HTTP/1.1\r\n", "Invalid request line: GET/HTTP/1.1<0x0D><0x0A>")] - [InlineData(" / HTTP/1.1\r\n", "Invalid request line: / HTTP/1.1<0x0D><0x0A>")] - [InlineData("GET? / HTTP/1.1\r\n", "Invalid request line: GET? / HTTP/1.1<0x0D><0x0A>")] - [InlineData("GET /HTTP/1.1\r\n", "Invalid request line: GET /HTTP/1.1<0x0D><0x0A>")] - [InlineData("GET /a?b=cHTTP/1.1\r\n", "Invalid request line: GET /a?b=cHTTP/1.1<0x0D><0x0A>")] - [InlineData("GET /a%20bHTTP/1.1\r\n", "Invalid request line: GET /a%20bHTTP/1.1<0x0D><0x0A>")] - [InlineData("GET /a%20b?c=dHTTP/1.1\r\n", "Invalid request line: GET /a%20b?c=dHTTP/1.1<0x0D><0x0A>")] - [InlineData("GET HTTP/1.1\r\n", "Invalid request line: GET HTTP/1.1<0x0D><0x0A>")] - [InlineData("GET / HTTP/1.1\n", "Invalid request line: GET / HTTP/1.1<0x0A>")] - [InlineData("GET / \r\n", "Invalid request line: GET / <0x0D><0x0A>")] - [InlineData("GET ? HTTP/1.1\r\n", "Invalid request line: GET ? HTTP/1.1<0x0D><0x0A>")] - [InlineData("GET / HTTP/1.1\ra\n", "Invalid request line: GET / HTTP/1.1<0x0D>a<0x0A>")] - public async Task TakeStartLineThrowsWhenInvalid(string requestLine, string expectedExceptionMessage) + [MemberData(nameof(InvalidRequestLineData))] + public async Task TakeStartLineThrowsOnInvalidRequestLine(string requestLine, Type expectedExceptionType, string expectedExceptionMessage) { await _socketInput.Writer.WriteAsync(Encoding.ASCII.GetBytes(requestLine)); - var readableBuffer = (await _socketInput.Reader.ReadAsync()).Buffer; - var exception = Assert.Throws(() => _frame.TakeStartLine(readableBuffer, out consumed, out examined)); - _socketInput.Reader.Advance(consumed, examined); + var exception = Assert.Throws(expectedExceptionType, () => + _frame.TakeStartLine(readableBuffer, out _consumed, out _examined)); + _socketInput.Reader.Advance(_consumed, _examined); Assert.Equal(expectedExceptionMessage, exception.Message); - Assert.Equal(StatusCodes.Status400BadRequest, exception.StatusCode); + + if (expectedExceptionType == typeof(BadHttpRequestException)) + { + Assert.Equal(StatusCodes.Status400BadRequest, (exception as BadHttpRequestException).StatusCode); + } } - [Fact] - public async Task TakeStartLineThrowsOnUnsupportedHttpVersion() + [Theory] + [MemberData(nameof(UnrecognizedHttpVersionData))] + public async Task TakeStartLineThrowsOnUnrecognizedHttpVersion(string httpVersion) { - await _socketInput.Writer.WriteAsync(Encoding.ASCII.GetBytes("GET / HTTP/1.2\r\n")); + await _socketInput.Writer.WriteAsync(Encoding.ASCII.GetBytes($"GET / {httpVersion}\r\n")); var readableBuffer = (await _socketInput.Reader.ReadAsync()).Buffer; - var exception = Assert.Throws(() => _frame.TakeStartLine(readableBuffer, out consumed, out examined)); - _socketInput.Reader.Advance(consumed, examined); + var exception = Assert.Throws(() => _frame.TakeStartLine(readableBuffer, out _consumed, out _examined)); + _socketInput.Reader.Advance(_consumed, _examined); - Assert.Equal("Unrecognized HTTP version: HTTP/1.2", exception.Message); - Assert.Equal(StatusCodes.Status505HttpVersionNotsupported, exception.StatusCode); - } - - [Fact] - public async Task TakeStartLineThrowsOnUnsupportedHttpVersionLongerThanEightCharacters() - { - var requestLineBytes = Encoding.ASCII.GetBytes("GET / HTTP/1.1ab\r\n"); - await _socketInput.Writer.WriteAsync(requestLineBytes); - - var readableBuffer = (await _socketInput.Reader.ReadAsync()).Buffer; - - var exception = Assert.Throws(() => _frame.TakeStartLine(readableBuffer, out consumed, out examined)); - _socketInput.Reader.Advance(consumed, examined); - - Assert.Equal("Unrecognized HTTP version: HTTP/1.1ab", exception.Message); + Assert.Equal($"Unrecognized HTTP version: {httpVersion}", exception.Message); Assert.Equal(StatusCodes.Status505HttpVersionNotsupported, exception.StatusCode); } [Fact] public async Task TakeMessageHeadersCallsConsumingCompleteWithFurthestExamined() { - foreach (var rawHeader in new [] { "Header: " , "value\r\n" , "\r\n"}) + foreach (var rawHeader in new[] { "Header: ", "value\r\n", "\r\n" }) { await _socketInput.Writer.WriteAsync(Encoding.ASCII.GetBytes(rawHeader)); var readableBuffer = (await _socketInput.Reader.ReadAsync()).Buffer; - _frame.TakeMessageHeaders(readableBuffer, (FrameRequestHeaders)_frame.RequestHeaders, out consumed, out examined); - _socketInput.Reader.Advance(consumed, examined); - Assert.Equal(readableBuffer.End, examined); + _frame.TakeMessageHeaders(readableBuffer, (FrameRequestHeaders)_frame.RequestHeaders, out _consumed, out _examined); + _socketInput.Reader.Advance(_consumed, _examined); + Assert.Equal(readableBuffer.End, _examined); } } @@ -831,5 +739,13 @@ namespace Microsoft.AspNetCore.Server.KestrelTests await _frame.ProduceEndAsync(); Assert.NotSame(original, _frame.RequestAborted.WaitHandle); } + + public static IEnumerable ValidRequestLineData => HttpParsingData.ValidRequestLineData; + + public static IEnumerable InvalidRequestLineData => HttpParsingData.InvalidRequestLineData; + + public static TheoryData UnrecognizedHttpVersionData => HttpParsingData.UnrecognizedHttpVersionData; + + public static IEnumerable InvalidRequestHeaderData => HttpParsingData.InvalidRequestHeaderData; } } diff --git a/test/shared/HttpParsingData.cs b/test/shared/HttpParsingData.cs new file mode 100644 index 0000000000..b38afb96c5 --- /dev/null +++ b/test/shared/HttpParsingData.cs @@ -0,0 +1,301 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Collections.Generic; +using System.Linq; +using Microsoft.AspNetCore.Server.Kestrel; +using Xunit; + +namespace Microsoft.AspNetCore.Testing +{ + public class HttpParsingData + { + public static IEnumerable ValidRequestLineData + { + get + { + var methods = new[] + { + "GET", + "CUSTOM", + }; + var targets = new[] + { + Tuple.Create("/", "/"), + Tuple.Create("/abc", "/abc"), + Tuple.Create("/abc/de/f", "/abc/de/f"), + Tuple.Create("/%20", "/ "), + Tuple.Create("/a%20", "/a "), + Tuple.Create("/%20a", "/ a"), + Tuple.Create("/a/b%20c", "/a/b c"), + Tuple.Create("/%C3%A5", "/\u00E5"), + Tuple.Create("/a%C3%A5a", "/a\u00E5a"), + Tuple.Create("/%C3%A5/bc", "/\u00E5/bc"), + Tuple.Create("/%25", "/%"), + Tuple.Create("/%2F", "/%2F"), + }; + var queryStrings = new[] + { + "", + "?", + "?arg1=val1", + "?arg1=a%20b", + "?%A", + "?%20=space", + "?%C3%A5=val", + "?path=/home", + "?path=/%C3%A5/", + "?question=what?", + "?%00", + "?arg=%00" + }; + var httpVersions = new[] + { + "HTTP/1.0", + "HTTP/1.1" + }; + + return from method in methods + from target in targets + from queryString in queryStrings + from httpVersion in httpVersions + select new[] + { + $"{method} {target.Item1}{queryString} {httpVersion}\r\n", + method, + $"{target.Item2}", + queryString, + httpVersion + }; + } + } + + // All these test cases must end in '\n', otherwise the server will spin forever + public static IEnumerable InvalidRequestLineData + { + get + { + var invalidRequestLines = new[] + { + "G\r\n", + "GE\r\n", + "GET\r\n", + "GET \r\n", + "GET /\r\n", + "GET / \r\n", + "GET/HTTP/1.1\r\n", + "GET /HTTP/1.1\r\n", + " \r\n", + " \r\n", + "/ HTTP/1.1\r\n", + " / HTTP/1.1\r\n", + "/ \r\n", + "GET \r\n", + "GET HTTP/1.0\r\n", + "GET HTTP/1.1\r\n", + "GET / \n", + "GET / HTTP/1.0\n", + "GET / HTTP/1.1\n", + "GET / HTTP/1.0\rA\n", + "GET / HTTP/1.1\ra\n", + "GET? / HTTP/1.1\r\n", + "GET ? HTTP/1.1\r\n", + "GET /a?b=cHTTP/1.1\r\n", + "GET /a%20bHTTP/1.1\r\n", + "GET /a%20b?c=dHTTP/1.1\r\n", + "GET %2F HTTP/1.1\r\n", + "GET %00 HTTP/1.1\r\n", + "CUSTOM \r\n", + "CUSTOM /\r\n", + "CUSTOM / \r\n", + "CUSTOM /HTTP/1.1\r\n", + "CUSTOM \r\n", + "CUSTOM HTTP/1.0\r\n", + "CUSTOM HTTP/1.1\r\n", + "CUSTOM / \n", + "CUSTOM / HTTP/1.0\n", + "CUSTOM / HTTP/1.1\n", + "CUSTOM / HTTP/1.0\rA\n", + "CUSTOM / HTTP/1.1\ra\n", + "CUSTOM ? HTTP/1.1\r\n", + "CUSTOM /a?b=cHTTP/1.1\r\n", + "CUSTOM /a%20bHTTP/1.1\r\n", + "CUSTOM /a%20b?c=dHTTP/1.1\r\n", + "CUSTOM %2F HTTP/1.1\r\n", + "CUSTOM %00 HTTP/1.1\r\n", + // Bad HTTP Methods (invalid according to RFC) + "( / HTTP/1.0\r\n", + ") / HTTP/1.0\r\n", + "< / HTTP/1.0\r\n", + "> / HTTP/1.0\r\n", + "@ / HTTP/1.0\r\n", + ", / HTTP/1.0\r\n", + "; / HTTP/1.0\r\n", + ": / HTTP/1.0\r\n", + "\\ / HTTP/1.0\r\n", + "\" / HTTP/1.0\r\n", + "/ / HTTP/1.0\r\n", + "[ / HTTP/1.0\r\n", + "] / HTTP/1.0\r\n", + "? / HTTP/1.0\r\n", + "= / HTTP/1.0\r\n", + "{ / HTTP/1.0\r\n", + "} / HTTP/1.0\r\n", + "get@ / HTTP/1.0\r\n", + "post= / HTTP/1.0\r\n", + }; + + var encodedNullCharInTargetRequestLines = new[] + { + "GET /%00 HTTP/1.1\r\n", + "GET /%00%00 HTTP/1.1\r\n", + "GET /%E8%00%84 HTTP/1.1\r\n", + "GET /%E8%85%00 HTTP/1.1\r\n", + "GET /%F3%00%82%86 HTTP/1.1\r\n", + "GET /%F3%85%00%82 HTTP/1.1\r\n", + "GET /%F3%85%82%00 HTTP/1.1\r\n", + "GET /%E8%85%00 HTTP/1.1\r\n", + "GET /%E8%01%00 HTTP/1.1\r\n", + }; + + var nullCharInTargetRequestLines = new[] + { + "GET \0 HTTP/1.1\r\n", + "GET /\0 HTTP/1.1\r\n", + "GET /\0\0 HTTP/1.1\r\n", + "GET /%C8\0 HTTP/1.1\r\n", + }; + + return invalidRequestLines.Select(requestLine => new object[] + { + requestLine, + typeof(BadHttpRequestException), + $"Invalid request line: {requestLine.Replace("\r", "<0x0D>").Replace("\n", "<0x0A>")}" + }) + .Concat(encodedNullCharInTargetRequestLines.Select(requestLine => new object[] + { + requestLine, + typeof(InvalidOperationException), + $"The path contains null characters." + })) + .Concat(nullCharInTargetRequestLines.Select(requestLine => new object[] + { + requestLine, + typeof(InvalidOperationException), + new InvalidOperationException().Message + })); + } + } + + public static TheoryData UnrecognizedHttpVersionData + { + get + { + return new TheoryData + { + "H", + "HT", + "HTT", + "HTTP", + "HTTP/", + "HTTP/1", + "HTTP/1.", + "http/1.0", + "http/1.1", + "HTTP/1.1 ", + "HTTP/1.0a", + "HTTP/1.0ab", + "HTTP/1.1a", + "HTTP/1.1ab", + "HTTP/1.2", + "HTTP/3.0", + "hello", + "8charact", + }; + } + } + + public static IEnumerable InvalidRequestHeaderData + { + get + { + // Line folding + var headersWithLineFolding = new[] + { + "Header: line1\r\n line2\r\n\r\n", + "Header: line1\r\n\tline2\r\n\r\n", + "Header: line1\r\n line2\r\n\r\n", + "Header: line1\r\n \tline2\r\n\r\n", + "Header: line1\r\n\t line2\r\n\r\n", + "Header: line1\r\n\t\tline2\r\n\r\n", + "Header: line1\r\n \t\t line2\r\n\r\n", + "Header: line1\r\n \t \t line2\r\n\r\n", + "Header-1: multi\r\n line\r\nHeader-2: value2\r\n\r\n", + "Header-1: value1\r\nHeader-2: multi\r\n line\r\n\r\n", + "Header-1: value1\r\n Header-2: value2\r\n\r\n", + "Header-1: value1\r\n\tHeader-2: value2\r\n\r\n", + }; + + // CR in value + var headersWithCRInValue = new[] + { + "Header-1: value1\r\r\n", + "Header-1: val\rue1\r\n", + "Header-1: value1\rHeader-2: value2\r\n\r\n", + "Header-1: value1\r\nHeader-2: value2\r\r\n", + "Header-1: value1\r\nHeader-2: v\ralue2\r\n", + }; + + // Missing colon + var headersWithMissingColon = new[] + { + "Header-1 value1\r\n\r\n", + "Header-1 value1\r\nHeader-2: value2\r\n\r\n", + "Header-1: value1\r\nHeader-2 value2\r\n\r\n", + }; + + // Starting with whitespace + var headersStartingWithWhitespace = new[] + { + " Header: value\r\n\r\n", + "\tHeader: value\r\n\r\n", + " Header-1: value1\r\nHeader-2: value2\r\n\r\n", + "\tHeader-1: value1\r\nHeader-2: value2\r\n\r\n", + }; + + // Whitespace in header name + var headersWithWithspaceInName = new[] + { + "Header : value\r\n\r\n", + "Header\t: value\r\n\r\n", + "Header 1: value1\r\nHeader-2: value2\r\n\r\n", + "Header 1 : value1\r\nHeader-2: value2\r\n\r\n", + "Header 1\t: value1\r\nHeader-2: value2\r\n\r\n", + "Header-1: value1\r\nHeader 2: value2\r\n\r\n", + "Header-1: value1\r\nHeader-2 : value2\r\n\r\n", + "Header-1: value1\r\nHeader-2\t: value2\r\n\r\n", + }; + + // Headers not ending in CRLF line + var headersNotEndingInCrLfLine = new[] + { + "Header-1: value1\r\nHeader-2: value2\r\n\r\r", + "Header-1: value1\r\nHeader-2: value2\r\n\r ", + "Header-1: value1\r\nHeader-2: value2\r\n\r \n", + }; + + return new[] + { + Tuple.Create(headersWithLineFolding,"Header value line folding not supported."), + Tuple.Create(headersWithCRInValue,"Header value must not contain CR characters."), + Tuple.Create(headersWithMissingColon,"No ':' character found in header line."), + Tuple.Create(headersStartingWithWhitespace, "Header line must not start with whitespace."), + Tuple.Create(headersWithWithspaceInName,"Whitespace is not allowed in header name."), + Tuple.Create(headersNotEndingInCrLfLine, "Headers corrupted, invalid header sequence.") + } + .SelectMany(t => t.Item1.Select(headers => new[] { headers, t.Item2 })); + } + } + } +} From 6ad9f3e8b0cdb3526b15f317ac8e2c608642ef5d Mon Sep 17 00:00:00 2001 From: John Luo Date: Tue, 28 Feb 2017 13:55:16 -0800 Subject: [PATCH 1064/1662] Reacting to HeaderUtitilities renames --- .../Internal/Http/FrameHeaders.Generated.cs | 16 ++++++++-------- .../Internal/Http/FrameRequestHeaders.cs | 2 +- .../Internal/Http/FrameResponseHeaders.cs | 2 +- .../FrameHeadersTests.cs | 2 +- tools/CodeGenerator/KnownHeaders.cs | 8 ++++---- 5 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameHeaders.Generated.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameHeaders.Generated.cs index 051b6b5737..df02ae9a33 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameHeaders.Generated.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameHeaders.Generated.cs @@ -754,7 +754,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http StringValues value; if (_contentLength.HasValue) { - value = new StringValues(HeaderUtilities.FormatInt64(_contentLength.Value)); + value = new StringValues(HeaderUtilities.FormatNonNegativeInt64(_contentLength.Value)); } return value; } @@ -1120,7 +1120,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { if (_contentLength.HasValue) { - value = HeaderUtilities.FormatInt64(_contentLength.Value); + value = HeaderUtilities.FormatNonNegativeInt64(_contentLength.Value); return true; } return false; @@ -3492,7 +3492,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { return false; } - array[arrayIndex] = new KeyValuePair("Content-Length", HeaderUtilities.FormatInt64(_contentLength.Value)); + array[arrayIndex] = new KeyValuePair("Content-Length", HeaderUtilities.FormatNonNegativeInt64(_contentLength.Value)); ++arrayIndex; } ((ICollection>)MaybeUnknown)?.CopyTo(array, arrayIndex); @@ -4767,7 +4767,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http state44: if (_collection._contentLength.HasValue) { - _current = new KeyValuePair("Content-Length", HeaderUtilities.FormatInt64(_collection._contentLength.Value)); + _current = new KeyValuePair("Content-Length", HeaderUtilities.FormatNonNegativeInt64(_collection._contentLength.Value)); _state = 45; return true; } @@ -5399,7 +5399,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http StringValues value; if (_contentLength.HasValue) { - value = new StringValues(HeaderUtilities.FormatInt64(_contentLength.Value)); + value = new StringValues(HeaderUtilities.FormatNonNegativeInt64(_contentLength.Value)); } return value; } @@ -5835,7 +5835,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { if (_contentLength.HasValue) { - value = HeaderUtilities.FormatInt64(_contentLength.Value); + value = HeaderUtilities.FormatNonNegativeInt64(_contentLength.Value); return true; } return false; @@ -7744,7 +7744,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { return false; } - array[arrayIndex] = new KeyValuePair("Content-Length", HeaderUtilities.FormatInt64(_contentLength.Value)); + array[arrayIndex] = new KeyValuePair("Content-Length", HeaderUtilities.FormatNonNegativeInt64(_contentLength.Value)); ++arrayIndex; } ((ICollection>)MaybeUnknown)?.CopyTo(array, arrayIndex); @@ -8970,7 +8970,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http state36: if (_collection._contentLength.HasValue) { - _current = new KeyValuePair("Content-Length", HeaderUtilities.FormatInt64(_collection._contentLength.Value)); + _current = new KeyValuePair("Content-Length", HeaderUtilities.FormatNonNegativeInt64(_collection._contentLength.Value)); _state = 37; return true; } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameRequestHeaders.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameRequestHeaders.cs index ca6496d320..b7432853b7 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameRequestHeaders.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameRequestHeaders.cs @@ -16,7 +16,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http private static long ParseContentLength(string value) { long parsed; - if (!HeaderUtilities.TryParseInt64(value, out parsed)) + if (!HeaderUtilities.TryParseNonNegativeInt64(value, out parsed)) { ThrowInvalidContentLengthException(value); } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameResponseHeaders.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameResponseHeaders.cs index 4666041dd9..836d73774a 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameResponseHeaders.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameResponseHeaders.cs @@ -58,7 +58,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http private static long ParseContentLength(string value) { long parsed; - if (!HeaderUtilities.TryParseInt64(value, out parsed)) + if (!HeaderUtilities.TryParseNonNegativeInt64(value, out parsed)) { ThrowInvalidContentLengthException(value); } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameHeadersTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameHeadersTests.cs index 83856879ad..24ec00d821 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameHeadersTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameHeadersTests.cs @@ -252,7 +252,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests frameHeaders.ContentLength = long.MaxValue; Assert.True(headers.TryGetValue("Content-Length", out value)); - Assert.Equal(HeaderUtilities.FormatInt64(long.MaxValue), value[0]); + Assert.Equal(HeaderUtilities.FormatNonNegativeInt64(long.MaxValue), value[0]); Assert.Equal(long.MaxValue, frameHeaders.ContentLength); Assert.True(frameHeaders.ContentLength.HasValue); diff --git a/tools/CodeGenerator/KnownHeaders.cs b/tools/CodeGenerator/KnownHeaders.cs index a211013404..ae8756af2d 100644 --- a/tools/CodeGenerator/KnownHeaders.cs +++ b/tools/CodeGenerator/KnownHeaders.cs @@ -317,7 +317,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http StringValues value; if (_contentLength.HasValue) {{ - value = new StringValues(HeaderUtilities.FormatInt64(_contentLength.Value)); + value = new StringValues(HeaderUtilities.FormatNonNegativeInt64(_contentLength.Value)); }} return value; }} @@ -363,7 +363,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http {{{(header.Identifier == "ContentLength" ? @" if (_contentLength.HasValue) { - value = HeaderUtilities.FormatInt64(_contentLength.Value); + value = HeaderUtilities.FormatNonNegativeInt64(_contentLength.Value); return true; } return false;" : $@" @@ -513,7 +513,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http {{ return false; }} - array[arrayIndex] = new KeyValuePair(""Content-Length"", HeaderUtilities.FormatInt64(_contentLength.Value)); + array[arrayIndex] = new KeyValuePair(""Content-Length"", HeaderUtilities.FormatNonNegativeInt64(_contentLength.Value)); ++arrayIndex; }} ((ICollection>)MaybeUnknown)?.CopyTo(array, arrayIndex); @@ -614,7 +614,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http state{loop.Headers.Count()}: if (_collection._contentLength.HasValue) {{ - _current = new KeyValuePair(""Content-Length"", HeaderUtilities.FormatInt64(_collection._contentLength.Value)); + _current = new KeyValuePair(""Content-Length"", HeaderUtilities.FormatNonNegativeInt64(_collection._contentLength.Value)); _state = {loop.Headers.Count() + 1}; return true; }} From 64b6563249209b58083f1b0e010c696f94a96fae Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Tue, 28 Feb 2017 15:27:57 -0800 Subject: [PATCH 1065/1662] Run Travis and AppVeyor builds on feature/dev-si --- .travis.yml | 1 + appveyor.yml | 1 + 2 files changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index 03c4d59416..33d8f34d20 100644 --- a/.travis.yml +++ b/.travis.yml @@ -27,6 +27,7 @@ branches: - master - release - dev + - feature/dev-si - /^(.*\/)?ci-.*$/ before_install: - if test "$TRAVIS_OS_NAME" == "osx"; then brew update; brew install openssl; ln -s /usr/local/opt/openssl/lib/libcrypto.1.0.0.dylib /usr/local/lib/; ln -s /usr/local/opt/openssl/lib/libssl.1.0.0.dylib /usr/local/lib/; fi diff --git a/appveyor.yml b/appveyor.yml index 13c0650228..61e1ba06b7 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -5,6 +5,7 @@ branches: - master - release - dev + - feature/dev-si - /^(.*\/)?ci-.*$/ build_script: - build.cmd --quiet verify From c56de066d359eaf1d6123abea5610d6ba6cfb2bf Mon Sep 17 00:00:00 2001 From: Krzysztof Cwalina Date: Tue, 28 Feb 2017 17:02:52 -0800 Subject: [PATCH 1066/1662] Optimized parsing GET verb and version (#1399) * Optimized parsing GET verb * optimized http version parsing * Added microbenchmarks for GetKnownMethod and GetKnownVersion --- .../MemoryPoolIteratorExtensions.cs | 89 +++++++++++-------- .../KnownStrings.cs | 79 ++++++++++++++++ .../Program.cs | 5 ++ 3 files changed, 135 insertions(+), 38 deletions(-) create mode 100644 test/Microsoft.AspNetCore.Server.Kestrel.Performance/KnownStrings.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolIteratorExtensions.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolIteratorExtensions.cs index 95c3c5a59f..950ae4bc40 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolIteratorExtensions.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolIteratorExtensions.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -19,6 +19,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure private readonly static ulong _httpConnectMethodLong = GetAsciiStringAsLong("CONNECT "); private readonly static ulong _httpDeleteMethodLong = GetAsciiStringAsLong("DELETE \0"); private readonly static ulong _httpGetMethodLong = GetAsciiStringAsLong("GET \0\0\0\0"); + private const uint _httpGetMethodInt = 542393671; // retun of GetAsciiStringAsInt("GET "); const results in better codegen private readonly static ulong _httpHeadMethodLong = GetAsciiStringAsLong("HEAD \0\0\0"); private readonly static ulong _httpPatchMethodLong = GetAsciiStringAsLong("PATCH \0\0"); private readonly static ulong _httpPostMethodLong = GetAsciiStringAsLong("POST \0\0\0"); @@ -26,8 +27,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure private readonly static ulong _httpOptionsMethodLong = GetAsciiStringAsLong("OPTIONS "); private readonly static ulong _httpTraceMethodLong = GetAsciiStringAsLong("TRACE \0\0"); - private readonly static ulong _http10VersionLong = GetAsciiStringAsLong("HTTP/1.0"); - private readonly static ulong _http11VersionLong = GetAsciiStringAsLong("HTTP/1.1"); + private const ulong _http10VersionLong = 3471766442030158920; // GetAsciiStringAsLong("HTTP/1.0"); const results in better codegen + private const ulong _http11VersionLong = 3543824036068086856; // GetAsciiStringAsLong("HTTP/1.1"); const results in better codegen private readonly static ulong _mask8Chars = GetMaskAsLong(new byte[] { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }); private readonly static ulong _mask7Chars = GetMaskAsLong(new byte[] { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00 }); @@ -60,6 +61,19 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure return *(ulong*)ptr; } } + + private unsafe static uint GetAsciiStringAsInt(string str) + { + Debug.Assert(str.Length == 4, "String must be exactly 4 (ASCII) characters long."); + + var bytes = Encoding.ASCII.GetBytes(str); + + fixed (byte* ptr = &bytes[0]) + { + return *(uint*)ptr; + } + } + private unsafe static ulong GetMaskAsLong(byte[] bytes) { Debug.Assert(bytes.Length == 8, "Mask must be exactly 8 bytes long."); @@ -173,27 +187,28 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool GetKnownMethod(this Span span, out string knownMethod) { - knownMethod = null; - if (span.Length < sizeof(ulong)) + if (span.TryRead(out var possiblyGet)) { - return false; - } - - ulong value = span.Read(); - if ((value & _mask4Chars) == _httpGetMethodLong) - { - knownMethod = HttpMethods.Get; - return true; - } - foreach (var x in _knownMethods) - { - if ((value & x.Item1) == x.Item2) + if (possiblyGet == _httpGetMethodInt) { - knownMethod = x.Item3; + knownMethod = HttpMethods.Get; return true; } } + if (span.TryRead(out var value)) + { + foreach (var x in _knownMethods) + { + if ((value & x.Item1) == x.Item2) + { + knownMethod = x.Item3; + return true; + } + } + } + + knownMethod = null; return false; } @@ -244,32 +259,30 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool GetKnownVersion(this Span span, out string knownVersion) { - knownVersion = null; - - if (span.Length < sizeof(ulong)) + if (span.TryRead(out var version)) { - return false; - } - - var value = span.Read(); - if (value == _http11VersionLong) - { - knownVersion = Http11Version; - } - else if (value == _http10VersionLong) - { - knownVersion = Http10Version; - } - - if (knownVersion != null) - { - if (span[sizeof(ulong)] != (byte)'\r') + if (version == _http11VersionLong) + { + knownVersion = Http11Version; + } + else if (version == _http10VersionLong) + { + knownVersion = Http10Version; + } + else { knownVersion = null; + return false; + } + + if (span[sizeof(ulong)] == (byte)'\r') + { + return true; } } - return knownVersion != null; + knownVersion = null; + return false; } } } diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/KnownStrings.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/KnownStrings.cs new file mode 100644 index 0000000000..74ef1153ff --- /dev/null +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/KnownStrings.cs @@ -0,0 +1,79 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Text; +using BenchmarkDotNet.Attributes; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; + +namespace Microsoft.AspNetCore.Server.Kestrel.Performance +{ + public class KnownStrings + { + static byte[] _method = Encoding.UTF8.GetBytes("GET "); + static byte[] _version = Encoding.UTF8.GetBytes("HTTP/1.1\r\n"); + const int loops = 1000; + + [Benchmark(OperationsPerInvoke = loops * 10)] + public int GetKnownMethod_GET() + { + int len = 0; + string method; + Span data = _method; + for (int i = 0; i < loops; i++) { + data.GetKnownMethod(out method); + len += method.Length; + data.GetKnownMethod(out method); + len += method.Length; + data.GetKnownMethod(out method); + len += method.Length; + data.GetKnownMethod(out method); + len += method.Length; + data.GetKnownMethod(out method); + len += method.Length; + data.GetKnownMethod(out method); + len += method.Length; + data.GetKnownMethod(out method); + len += method.Length; + data.GetKnownMethod(out method); + len += method.Length; + data.GetKnownMethod(out method); + len += method.Length; + data.GetKnownMethod(out method); + len += method.Length; + } + return len; + } + + [Benchmark(OperationsPerInvoke = loops * 10)] + public int GetKnownVersion_HTTP1_1() + { + int len = 0; + string version; + Span data = _version; + for (int i = 0; i < loops; i++) { + data.GetKnownVersion(out version); + len += version.Length; + data.GetKnownVersion(out version); + len += version.Length; + data.GetKnownVersion(out version); + len += version.Length; + data.GetKnownVersion(out version); + len += version.Length; + data.GetKnownVersion(out version); + len += version.Length; + data.GetKnownVersion(out version); + len += version.Length; + data.GetKnownVersion(out version); + len += version.Length; + data.GetKnownVersion(out version); + len += version.Length; + data.GetKnownVersion(out version); + len += version.Length; + data.GetKnownVersion(out version); + len += version.Length; + } + return len; + } + } +} diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Program.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Program.cs index d687d6bea2..e6bea9e92c 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Program.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Program.cs @@ -40,6 +40,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance { BenchmarkRunner.Run(); } + if (type.HasFlag(BenchmarkType.KnownStrings)) + { + BenchmarkRunner.Run(); + } } } @@ -49,6 +53,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance RequestParsing = 1, Writing = 2, Throughput = 4, + KnownStrings = 8, // add new ones in powers of two - e.g. 2,4,8,16... All = uint.MaxValue From d3694f085a2df0c51286fdc4369bca8012d308fc Mon Sep 17 00:00:00 2001 From: Pavel Krymets Date: Wed, 1 Mar 2017 11:55:36 -0800 Subject: [PATCH 1067/1662] Add IHttpParser interface (#1414) --- KestrelHttpServer.sln | 2 +- .../Internal/Http/Frame.cs | 691 +++--------------- .../Internal/Http/HttpMethod.cs | 20 + .../Internal/Http/HttpVersion.cs | 2 +- .../Internal/Http/IHttpHeadersHandler.cs | 12 + .../Internal/Http/IHttpParser.cs | 14 + .../Internal/Http/IHttpRequestLineHandler.cs | 12 + .../Internal/Http/KestrelHttpParser.cs | 549 ++++++++++++++ ...IteratorExtensions.cs => HttpUtilities.cs} | 208 ++---- .../Internal/ServiceContext.cs | 2 + .../KestrelServer.cs | 1 + .../KnownStrings.cs | 85 +-- .../RequestParsing.cs | 5 + .../FrameTests.cs | 1 + .../HttpUtilitiesTest.cs | 122 ++++ .../ListenerPrimaryTests.cs | 3 + .../MemoryPoolIteratorTests.cs | 354 ++------- .../TestInput.cs | 5 +- test/shared/TestServiceContext.cs | 1 + 19 files changed, 1018 insertions(+), 1071 deletions(-) create mode 100644 src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/HttpMethod.cs create mode 100644 src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/IHttpHeadersHandler.cs create mode 100644 src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/IHttpParser.cs create mode 100644 src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/IHttpRequestLineHandler.cs create mode 100644 src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/KestrelHttpParser.cs rename src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/{MemoryPoolIteratorExtensions.cs => HttpUtilities.cs} (59%) create mode 100644 test/Microsoft.AspNetCore.Server.KestrelTests/HttpUtilitiesTest.cs diff --git a/KestrelHttpServer.sln b/KestrelHttpServer.sln index 10d207a841..60a967cf1a 100644 --- a/KestrelHttpServer.sln +++ b/KestrelHttpServer.sln @@ -1,6 +1,6 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 15 -VisualStudioVersion = 15.0.26223.1 +VisualStudioVersion = 15.0.26222.1 MinimumVisualStudioVersion = 10.0.40219.1 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{7972A5D6-3385-4127-9277-428506DD44FF}" ProjectSection(SolutionItems) = preProject diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs index f3d6787b55..26e9dddee6 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs @@ -16,7 +16,6 @@ using System.Text.Utf8; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Server.Kestrel.Adapter; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.Extensions.Internal; @@ -27,15 +26,8 @@ using Microsoft.Extensions.Primitives; namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { - public abstract partial class Frame : IFrameControl + public abstract partial class Frame : IFrameControl, IHttpRequestLineHandler, IHttpHeadersHandler { - // byte types don't have a data type annotation so we pre-cast them; to avoid in-place casts - private const byte ByteCR = (byte)'\r'; - private const byte ByteLF = (byte)'\n'; - private const byte ByteColon = (byte)':'; - private const byte ByteSpace = (byte)' '; - private const byte ByteTab = (byte)'\t'; - private const byte ByteQuestionMark = (byte)'?'; private const byte BytePercentage = (byte)'%'; private static readonly ArraySegment _endChunkedResponseBytes = CreateAsciiByteArraySegment("0\r\n\r\n"); @@ -83,6 +75,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http protected long _responseBytesWritten; + private readonly IHttpParser _parser; + public Frame(ConnectionContext context) { ConnectionContext = context; @@ -92,6 +86,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http ServerOptions = context.ListenerContext.ServiceContext.ServerOptions; _pathBase = context.ListenerContext.ListenOptions.PathBase; + _parser = context.ListenerContext.ServiceContext.HttpParser; FrameControl = this; _keepAliveMilliseconds = (long)ServerOptions.Limits.KeepAliveTimeout.TotalMilliseconds; @@ -173,7 +168,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } else { - _httpVersion = Http.HttpVersion.Unset; + _httpVersion = Http.HttpVersion.Unknown; } } @@ -199,6 +194,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } private string _reasonPhrase; + public string ReasonPhrase { get @@ -349,7 +345,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http PathBase = null; Path = null; QueryString = null; - _httpVersion = Http.HttpVersion.Unset; + _httpVersion = Http.HttpVersion.Unknown; StatusCode = StatusCodes.Status200OK; ReasonPhrase = null; @@ -378,7 +374,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _manuallySetRequestAbortToken = null; _abortedCts = null; - _remainingRequestHeadersBytesAllowed = ServerOptions.Limits.MaxRequestHeadersTotalSize; + // Allow to bytes for \r\n after headers + _remainingRequestHeadersBytesAllowed = ServerOptions.Limits.MaxRequestHeadersTotalSize + 2; _requestHeadersParsed = 0; _responseBytesWritten = 0; @@ -982,15 +979,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http Output.ProducingComplete(end); } - public unsafe bool TakeStartLine(ReadableBuffer buffer, out ReadCursor consumed, out ReadCursor examined) + public bool TakeStartLine(ReadableBuffer buffer, out ReadCursor consumed, out ReadCursor examined) { - var start = buffer.Start; - var end = buffer.Start; - var bufferEnd = buffer.End; - - examined = buffer.End; - consumed = buffer.Start; - if (_requestProcessingStatus == RequestProcessingStatus.RequestPending) { ConnectionControl.ResetTimeout(_requestHeadersTimeoutMilliseconds, TimeoutAction.SendTimeoutResponse); @@ -1001,305 +991,17 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var overLength = false; if (buffer.Length >= ServerOptions.Limits.MaxRequestLineSize) { - bufferEnd = buffer.Move(start, ServerOptions.Limits.MaxRequestLineSize); - + buffer = buffer.Slice(buffer.Start, ServerOptions.Limits.MaxRequestLineSize); overLength = true; } - if (ReadCursorOperations.Seek(start, bufferEnd, out end, ByteLF) == -1) + var result = _parser.ParseRequestLine(this, buffer, out consumed, out examined); + if (!result && overLength) { - if (overLength) - { - RejectRequest(RequestRejectionReason.RequestLineTooLong); - } - else - { - return false; - } + RejectRequest(RequestRejectionReason.RequestLineTooLong); } - const int stackAllocLimit = 512; - - // Move 1 byte past the \n - end = buffer.Move(end, 1); - var startLineBuffer = buffer.Slice(start, end); - - Span span; - - if (startLineBuffer.IsSingleSpan) - { - // No copies, directly use the one and only span - span = startLineBuffer.First.Span; - } - else if (startLineBuffer.Length < stackAllocLimit) - { - // Multiple buffers and < stackAllocLimit, copy into a stack buffer - byte* stackBuffer = stackalloc byte[startLineBuffer.Length]; - span = new Span(stackBuffer, startLineBuffer.Length); - startLineBuffer.CopyTo(span); - } - else - { - // We're not a single span here but we can use pooled arrays to avoid allocations in the rare case - span = new Span(new byte[startLineBuffer.Length]); - startLineBuffer.CopyTo(span); - } - - var needDecode = false; - var pathStart = -1; - var queryStart = -1; - var queryEnd = -1; - var pathEnd = -1; - var versionStart = -1; - var queryString = ""; - var httpVersion = ""; - var method = ""; - var state = StartLineState.KnownMethod; - - fixed (byte* data = &span.DangerousGetPinnableReference()) - { - var length = span.Length; - for (var i = 0; i < length; i++) - { - var ch = data[i]; - - switch (state) - { - case StartLineState.KnownMethod: - if (span.GetKnownMethod(out method)) - { - // Update the index, current char, state and jump directly - // to the next state - i += method.Length + 1; - ch = data[i]; - state = StartLineState.Path; - - goto case StartLineState.Path; - } - - state = StartLineState.UnknownMethod; - goto case StartLineState.UnknownMethod; - - case StartLineState.UnknownMethod: - if (ch == ByteSpace) - { - method = span.Slice(0, i).GetAsciiString(); - - if (method == null) - { - RejectRequestLine(start, end); - } - - state = StartLineState.Path; - } - else if (!IsValidTokenChar((char)ch)) - { - RejectRequestLine(start, end); - } - - break; - case StartLineState.Path: - if (ch == ByteSpace) - { - pathEnd = i; - - if (pathStart == -1) - { - // Empty path is illegal - RejectRequestLine(start, end); - } - - // No query string found - queryStart = queryEnd = i; - - state = StartLineState.KnownVersion; - } - else if (ch == ByteQuestionMark) - { - pathEnd = i; - - if (pathStart == -1) - { - // Empty path is illegal - RejectRequestLine(start, end); - } - - queryStart = i; - state = StartLineState.QueryString; - } - else if (ch == BytePercentage) - { - if (pathStart == -1) - { - // Empty path is illegal - RejectRequestLine(start, end); - } - - needDecode = true; - } - - if (pathStart == -1) - { - pathStart = i; - } - break; - case StartLineState.QueryString: - if (ch == ByteSpace) - { - queryEnd = i; - state = StartLineState.KnownVersion; - - queryString = span.Slice(queryStart, queryEnd - queryStart).GetAsciiString() ?? string.Empty; - } - break; - case StartLineState.KnownVersion: - // REVIEW: We don't *need* to slice here but it makes the API - // nicer, slicing should be free :) - if (span.Slice(i).GetKnownVersion(out httpVersion)) - { - // Update the index, current char, state and jump directly - // to the next state - i += httpVersion.Length + 1; - ch = data[i]; - state = StartLineState.NewLine; - - goto case StartLineState.NewLine; - } - - versionStart = i; - state = StartLineState.UnknownVersion; - goto case StartLineState.UnknownVersion; - - case StartLineState.UnknownVersion: - if (ch == ByteCR) - { - var versionSpan = span.Slice(versionStart, i - versionStart); - - if (versionSpan.Length == 0) - { - RejectRequestLine(start, end); - } - else - { - RejectRequest(RequestRejectionReason.UnrecognizedHTTPVersion, versionSpan.GetAsciiStringEscaped()); - } - } - break; - case StartLineState.NewLine: - if (ch != ByteLF) - { - RejectRequestLine(start, end); - } - - state = StartLineState.Complete; - break; - case StartLineState.Complete: - break; - default: - break; - } - } - } - - if (state != StartLineState.Complete) - { - RejectRequestLine(start, end); - } - - var pathBuffer = span.Slice(pathStart, pathEnd - pathStart); - var targetBuffer = span.Slice(pathStart, queryEnd - pathStart); - - // URIs are always encoded/escaped to ASCII https://tools.ietf.org/html/rfc3986#page-11 - // Multibyte Internationalized Resource Identifiers (IRIs) are first converted to utf8; - // then encoded/escaped to ASCII https://www.ietf.org/rfc/rfc3987.txt "Mapping of IRIs to URIs" - string requestUrlPath; - string rawTarget; - if (needDecode) - { - // Read raw target before mutating memory. - rawTarget = targetBuffer.GetAsciiString() ?? string.Empty; - - // URI was encoded, unescape and then parse as utf8 - var pathSpan = pathBuffer; - int pathLength = UrlEncoder.Decode(pathSpan, pathSpan); - requestUrlPath = new Utf8String(pathSpan.Slice(0, pathLength)).ToString(); - } - else - { - // URI wasn't encoded, parse as ASCII - requestUrlPath = pathBuffer.GetAsciiString() ?? string.Empty; - - if (queryString.Length == 0) - { - // No need to allocate an extra string if the path didn't need - // decoding and there's no query string following it. - rawTarget = requestUrlPath; - } - else - { - rawTarget = targetBuffer.GetAsciiString() ?? string.Empty; - } - } - - var normalizedTarget = PathNormalizer.RemoveDotSegments(requestUrlPath); - - consumed = end; - examined = end; - Method = method; - QueryString = queryString; - RawTarget = rawTarget; - HttpVersion = httpVersion; - - if (RequestUrlStartsWithPathBase(normalizedTarget, out bool caseMatches)) - { - PathBase = caseMatches ? _pathBase : normalizedTarget.Substring(0, _pathBase.Length); - Path = normalizedTarget.Substring(_pathBase.Length); - } - else if (rawTarget[0] == '/') // check rawTarget since normalizedTarget can be "" or "/" after dot segment removal - { - Path = normalizedTarget; - } - else - { - Path = string.Empty; - PathBase = string.Empty; - QueryString = string.Empty; - } - - - return true; - } - - private void RejectRequestLine(ReadCursor start, ReadCursor end) - { - const int MaxRequestLineError = 32; - RejectRequest(RequestRejectionReason.InvalidRequestLine, - Log.IsEnabled(LogLevel.Information) ? start.GetAsciiStringEscaped(end, MaxRequestLineError) : string.Empty); - } - - private static bool IsValidTokenChar(char c) - { - // Determines if a character is valid as a 'token' as defined in the - // HTTP spec: https://tools.ietf.org/html/rfc7230#section-3.2.6 - return - (c >= '0' && c <= '9') || - (c >= 'A' && c <= 'Z') || - (c >= 'a' && c <= 'z') || - c == '!' || - c == '#' || - c == '$' || - c == '%' || - c == '&' || - c == '\'' || - c == '*' || - c == '+' || - c == '-' || - c == '.' || - c == '^' || - c == '_' || - c == '`' || - c == '|' || - c == '~'; + return result; } private bool RequestUrlStartsWithPathBase(string requestUrl, out bool caseMatches) @@ -1334,282 +1036,31 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http return true; } - public unsafe bool TakeMessageHeaders(ReadableBuffer buffer, FrameRequestHeaders requestHeaders, out ReadCursor consumed, out ReadCursor examined) + public bool TakeMessageHeaders(ReadableBuffer buffer, FrameRequestHeaders requestHeaders, out ReadCursor consumed, out ReadCursor examined) { - consumed = buffer.Start; - examined = buffer.End; - - var bufferEnd = buffer.End; - var reader = new ReadableBufferReader(buffer); - // Make sure the buffer is limited - var overLength = false; + bool overLength = false; if (buffer.Length >= _remainingRequestHeadersBytesAllowed) { - bufferEnd = buffer.Move(consumed, _remainingRequestHeadersBytesAllowed); + buffer = buffer.Slice(buffer.Start, _remainingRequestHeadersBytesAllowed); // If we sliced it means the current buffer bigger than what we're // allowed to look at overLength = true; } - while (true) + var result = _parser.ParseHeaders(this, buffer, out consumed, out examined, out var consumedBytes); + _remainingRequestHeadersBytesAllowed -= consumedBytes; + + if (!result && overLength) { - var start = reader; - int ch1 = reader.Take(); - var ch2 = reader.Take(); - - if (ch1 == -1) - { - return false; - } - - if (ch1 == ByteCR) - { - // Check for final CRLF. - if (ch2 == -1) - { - return false; - } - else if (ch2 == ByteLF) - { - consumed = reader.Cursor; - examined = consumed; - ConnectionControl.CancelTimeout(); - return true; - } - - // Headers don't end in CRLF line. - RejectRequest(RequestRejectionReason.HeadersCorruptedInvalidHeaderSequence); - } - else if (ch1 == ByteSpace || ch1 == ByteTab) - { - RejectRequest(RequestRejectionReason.HeaderLineMustNotStartWithWhitespace); - } - - // If we've parsed the max allowed numbers of headers and we're starting a new - // one, we've gone over the limit. - if (_requestHeadersParsed == ServerOptions.Limits.MaxRequestHeaderCount) - { - RejectRequest(RequestRejectionReason.TooManyHeaders); - } - - // Reset the reader since we're not at the end of headers - reader = start; - - if (ReadCursorOperations.Seek(consumed, bufferEnd, out var lineEnd, ByteLF) == -1) - { - // We didn't find a \n in the current buffer and we had to slice it so it's an issue - if (overLength) - { - RejectRequest(RequestRejectionReason.HeadersExceedMaxTotalSize); - } - else - { - return false; - } - } - - const int stackAllocLimit = 512; - - if (lineEnd != bufferEnd) - { - lineEnd = buffer.Move(lineEnd, 1); - } - - var headerBuffer = buffer.Slice(consumed, lineEnd); - - Span span; - if (headerBuffer.IsSingleSpan) - { - // No copies, directly use the one and only span - span = headerBuffer.First.Span; - } - else if (headerBuffer.Length < stackAllocLimit) - { - // Multiple buffers and < stackAllocLimit, copy into a stack buffer - byte* stackBuffer = stackalloc byte[headerBuffer.Length]; - span = new Span(stackBuffer, headerBuffer.Length); - headerBuffer.CopyTo(span); - } - else - { - // We're not a single span here but we can use pooled arrays to avoid allocations in the rare case - span = new Span(new byte[headerBuffer.Length]); - headerBuffer.CopyTo(span); - } - - var state = HeaderState.Name; - var nameStart = 0; - var nameEnd = -1; - var valueStart = -1; - var valueEnd = -1; - var nameHasWhitespace = false; - var previouslyWhitespace = false; - var headerLineLength = span.Length; - - fixed (byte* data = &span.DangerousGetPinnableReference()) - { - for (var i = 0; i < headerLineLength; i++) - { - var ch = data[i]; - - switch (state) - { - case HeaderState.Name: - if (ch == ByteColon) - { - if (nameHasWhitespace) - { - RejectRequest(RequestRejectionReason.WhitespaceIsNotAllowedInHeaderName); - } - - state = HeaderState.Whitespace; - nameEnd = i; - } - - if (ch == ByteSpace || ch == ByteTab) - { - nameHasWhitespace = true; - } - break; - case HeaderState.Whitespace: - { - var whitespace = ch == ByteTab || ch == ByteSpace || ch == ByteCR; - - if (!whitespace) - { - // Mark the first non whitespace char as the start of the - // header value and change the state to expect to the header value - valueStart = i; - state = HeaderState.ExpectValue; - } - // If we see a CR then jump to the next state directly - else if (ch == ByteCR) - { - state = HeaderState.ExpectValue; - goto case HeaderState.ExpectValue; - } - } - break; - case HeaderState.ExpectValue: - { - var whitespace = ch == ByteTab || ch == ByteSpace; - - if (whitespace) - { - if (!previouslyWhitespace) - { - // If we see a whitespace char then maybe it's end of the - // header value - valueEnd = i; - } - } - else if (ch == ByteCR) - { - // If we see a CR and we haven't ever seen whitespace then - // this is the end of the header value - if (valueEnd == -1) - { - valueEnd = i; - } - - // We never saw a non whitespace character before the CR - if (valueStart == -1) - { - valueStart = valueEnd; - } - - state = HeaderState.ExpectNewLine; - } - else - { - // If we find a non whitespace char that isn't CR then reset the end index - valueEnd = -1; - } - - previouslyWhitespace = whitespace; - } - break; - case HeaderState.ExpectNewLine: - if (ch != ByteLF) - { - RejectRequest(RequestRejectionReason.HeaderValueMustNotContainCR); - } - - state = HeaderState.Complete; - break; - default: - break; - } - } - } - - if (state == HeaderState.Name) - { - RejectRequest(RequestRejectionReason.NoColonCharacterFoundInHeaderLine); - } - - if (state == HeaderState.ExpectValue || state == HeaderState.Whitespace) - { - RejectRequest(RequestRejectionReason.MissingCRInHeaderLine); - } - - if (state != HeaderState.Complete) - { - return false; - } - - // Skip the reader forward past the header line - reader.Skip(headerLineLength); - - // Before accepting the header line, we need to see at least one character - // > so we can make sure there's no space or tab - var next = reader.Peek(); - - // TODO: We don't need to reject the line here, we can use the state machine - // to store the fact that we're reading a header value - if (next == -1) - { - // If we can't see the next char then reject the entire line - return false; - } - - if (next == ByteSpace || next == ByteTab) - { - // From https://tools.ietf.org/html/rfc7230#section-3.2.4: - // - // Historically, HTTP header field values could be extended over - // multiple lines by preceding each extra line with at least one space - // or horizontal tab (obs-fold). This specification deprecates such - // line folding except within the message/http media type - // (Section 8.3.1). A sender MUST NOT generate a message that includes - // line folding (i.e., that has any field-value that contains a match to - // the obs-fold rule) unless the message is intended for packaging - // within the message/http media type. - // - // A server that receives an obs-fold in a request message that is not - // within a message/http container MUST either reject the message by - // sending a 400 (Bad Request), preferably with a representation - // explaining that obsolete line folding is unacceptable, or replace - // each received obs-fold with one or more SP octets prior to - // interpreting the field value or forwarding the message downstream. - RejectRequest(RequestRejectionReason.HeaderValueLineFoldingNotSupported); - } - - var nameBuffer = span.Slice(nameStart, nameEnd - nameStart); - var valueBuffer = span.Slice(valueStart, valueEnd - valueStart); - - var value = valueBuffer.GetAsciiString() ?? string.Empty; - - // Update the frame state only after we know there's no header line continuation - _remainingRequestHeadersBytesAllowed -= headerLineLength; - _requestHeadersParsed++; - - requestHeaders.Append(nameBuffer, value); - - consumed = reader.Cursor; + RejectRequest(RequestRejectionReason.HeadersExceedMaxTotalSize); } + if (result) + { + ConnectionControl.CancelTimeout(); + } + return result; } public bool StatusCanHaveBody(int statusCode) @@ -1750,25 +1201,81 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http ResponseStarted } - private enum StartLineState + public void OnStartLine(HttpMethod method, HttpVersion version, Span target, Span path, Span query, Span customMethod) { - KnownMethod, - UnknownMethod, - Path, - QueryString, - KnownVersion, - UnknownVersion, - NewLine, - Complete + // URIs are always encoded/escaped to ASCII https://tools.ietf.org/html/rfc3986#page-11 + // Multibyte Internationalized Resource Identifiers (IRIs) are first converted to utf8; + // then encoded/escaped to ASCII https://www.ietf.org/rfc/rfc3987.txt "Mapping of IRIs to URIs" + string requestUrlPath; + string rawTarget; + var needDecode = path.IndexOf(BytePercentage) >= 0; + if (needDecode) + { + // Read raw target before mutating memory. + rawTarget = target.GetAsciiString() ?? string.Empty; + + // URI was encoded, unescape and then parse as utf8 + int pathLength = UrlEncoder.Decode(path, path); + requestUrlPath = new Utf8String(path.Slice(0, pathLength)).ToString(); + } + else + { + // URI wasn't encoded, parse as ASCII + requestUrlPath = path.GetAsciiString() ?? string.Empty; + + if (query.Length == 0) + { + // No need to allocate an extra string if the path didn't need + // decoding and there's no query string following it. + rawTarget = requestUrlPath; + } + else + { + rawTarget = target.GetAsciiString() ?? string.Empty; + } + } + + var normalizedTarget = PathNormalizer.RemoveDotSegments(requestUrlPath); + if (method != HttpMethod.Custom) + { + Method = HttpUtilities.MethodToString(method) ?? String.Empty; + } + else + { + Method = customMethod.GetAsciiString() ?? string.Empty; + } + + QueryString = query.GetAsciiString() ?? string.Empty; + RawTarget = rawTarget; + HttpVersion = HttpUtilities.VersionToString(version); + + if (RequestUrlStartsWithPathBase(normalizedTarget, out bool caseMatches)) + { + PathBase = caseMatches ? _pathBase : normalizedTarget.Substring(0, _pathBase.Length); + Path = normalizedTarget.Substring(_pathBase.Length); + } + else if (rawTarget[0] == '/') // check rawTarget since normalizedTarget can be "" or "/" after dot segment removal + { + Path = normalizedTarget; + } + else + { + Path = string.Empty; + PathBase = string.Empty; + QueryString = string.Empty; + } } - private enum HeaderState + public void OnHeader(Span name, Span value) { - Name, - Whitespace, - ExpectValue, - ExpectNewLine, - Complete + _requestHeadersParsed++; + if (_requestHeadersParsed > ServerOptions.Limits.MaxRequestHeaderCount) + { + RejectRequest(RequestRejectionReason.TooManyHeaders); + } + var valueString = value.GetAsciiString() ?? string.Empty; + + FrameRequestHeaders.Append(name, valueString); } } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/HttpMethod.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/HttpMethod.cs new file mode 100644 index 0000000000..88b4ed73c2 --- /dev/null +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/HttpMethod.cs @@ -0,0 +1,20 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http +{ + public enum HttpMethod: byte + { + Get, + Put, + Delete, + Post, + Head, + Trace, + Patch, + Connect, + Options, + + Custom, + } +} \ No newline at end of file diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/HttpVersion.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/HttpVersion.cs index 67712ec54d..f3a015af88 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/HttpVersion.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/HttpVersion.cs @@ -5,7 +5,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { public enum HttpVersion { - Unset = -1, + Unknown = -1, Http10 = 0, Http11 = 1 } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/IHttpHeadersHandler.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/IHttpHeadersHandler.cs new file mode 100644 index 0000000000..57468508d1 --- /dev/null +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/IHttpHeadersHandler.cs @@ -0,0 +1,12 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; + +namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http +{ + public interface IHttpHeadersHandler + { + void OnHeader(Span name, Span value); + } +} \ No newline at end of file diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/IHttpParser.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/IHttpParser.cs new file mode 100644 index 0000000000..e1d68293cd --- /dev/null +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/IHttpParser.cs @@ -0,0 +1,14 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System.IO.Pipelines; + +namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http +{ + public interface IHttpParser + { + bool ParseRequestLine(T handler, ReadableBuffer buffer, out ReadCursor consumed, out ReadCursor examined) where T : IHttpRequestLineHandler; + + bool ParseHeaders(T handler, ReadableBuffer buffer, out ReadCursor consumed, out ReadCursor examined, out int consumedBytes) where T : IHttpHeadersHandler; + } +} \ No newline at end of file diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/IHttpRequestLineHandler.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/IHttpRequestLineHandler.cs new file mode 100644 index 0000000000..ddb6473882 --- /dev/null +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/IHttpRequestLineHandler.cs @@ -0,0 +1,12 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; + +namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http +{ + public interface IHttpRequestLineHandler + { + void OnStartLine(HttpMethod method, HttpVersion version, Span target, Span path, Span query, Span customMethod); + } +} \ No newline at end of file diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/KestrelHttpParser.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/KestrelHttpParser.cs new file mode 100644 index 0000000000..8f334a5a20 --- /dev/null +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/KestrelHttpParser.cs @@ -0,0 +1,549 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.IO.Pipelines; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; +using Microsoft.Extensions.Logging; + +namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http +{ + public class KestrelHttpParser : IHttpParser + { + public KestrelHttpParser(IKestrelTrace log) + { + Log = log; + } + + private IKestrelTrace Log { get; } + + // byte types don't have a data type annotation so we pre-cast them; to avoid in-place casts + private const byte ByteCR = (byte)'\r'; + private const byte ByteLF = (byte)'\n'; + private const byte ByteColon = (byte)':'; + private const byte ByteSpace = (byte)' '; + private const byte ByteTab = (byte)'\t'; + private const byte ByteQuestionMark = (byte)'?'; + private const byte BytePercentage = (byte)'%'; + + public unsafe bool ParseRequestLine(T handler, ReadableBuffer buffer, out ReadCursor consumed, out ReadCursor examined) where T : IHttpRequestLineHandler + { + consumed = buffer.Start; + examined = buffer.End; + + var start = buffer.Start; + ReadCursor end; + if (ReadCursorOperations.Seek(start, buffer.End, out end, ByteLF) == -1) + { + return false; + } + + const int stackAllocLimit = 512; + + // Move 1 byte past the \n + end = buffer.Move(end, 1); + var startLineBuffer = buffer.Slice(start, end); + + Span span; + + if (startLineBuffer.IsSingleSpan) + { + // No copies, directly use the one and only span + span = startLineBuffer.First.Span; + } + else if (startLineBuffer.Length < stackAllocLimit) + { + // Multiple buffers and < stackAllocLimit, copy into a stack buffer + byte* stackBuffer = stackalloc byte[startLineBuffer.Length]; + span = new Span(stackBuffer, startLineBuffer.Length); + startLineBuffer.CopyTo(span); + } + else + { + // We're not a single span here but we can use pooled arrays to avoid allocations in the rare case + span = new Span(new byte[startLineBuffer.Length]); + startLineBuffer.CopyTo(span); + } + + var pathStart = -1; + var queryStart = -1; + var queryEnd = -1; + var pathEnd = -1; + var versionStart = -1; + + HttpVersion httpVersion = HttpVersion.Unknown; + HttpMethod method = HttpMethod.Custom; + Span customMethod; + var state = StartLineState.KnownMethod; + + int i; + fixed (byte* data = &span.DangerousGetPinnableReference()) + { + var length = span.Length; + for (i = 0; i < length; i++) + { + var ch = data[i]; + + switch (state) + { + case StartLineState.KnownMethod: + if (span.GetKnownMethod(out method, out var methodLength)) + { + // Update the index, current char, state and jump directly + // to the next state + i += methodLength + 1; + ch = data[i]; + state = StartLineState.Path; + + goto case StartLineState.Path; + } + + state = StartLineState.UnknownMethod; + goto case StartLineState.UnknownMethod; + + case StartLineState.UnknownMethod: + if (ch == ByteSpace) + { + customMethod = span.Slice(0, i); + + if (customMethod.Length == 0) + { + RejectRequestLine(span); + } + + state = StartLineState.Path; + } + else if (!IsValidTokenChar((char)ch)) + { + RejectRequestLine(span); + } + + break; + case StartLineState.Path: + if (ch == ByteSpace) + { + pathEnd = i; + + if (pathStart == -1) + { + // Empty path is illegal + RejectRequestLine(span); + } + + // No query string found + queryStart = queryEnd = i; + + state = StartLineState.KnownVersion; + } + else if (ch == ByteQuestionMark) + { + pathEnd = i; + + if (pathStart == -1) + { + // Empty path is illegal + RejectRequestLine(span); + } + + queryStart = i; + state = StartLineState.QueryString; + } + else if (ch == BytePercentage) + { + if (pathStart == -1) + { + RejectRequestLine(span); + } + } + + if (pathStart == -1) + { + pathStart = i; + } + break; + + case StartLineState.QueryString: + if (ch == ByteSpace) + { + queryEnd = i; + state = StartLineState.KnownVersion; + + } + break; + case StartLineState.KnownVersion: + // REVIEW: We don't *need* to slice here but it makes the API + // nicer, slicing should be free :) + if (span.Slice(i).GetKnownVersion(out httpVersion, out var versionLenght)) + { + // Update the index, current char, state and jump directly + // to the next state + i += versionLenght + 1; + ch = data[i]; + state = StartLineState.NewLine; + + goto case StartLineState.NewLine; + } + + versionStart = i; + state = StartLineState.UnknownVersion; + goto case StartLineState.UnknownVersion; + + case StartLineState.UnknownVersion: + if (ch == ByteCR) + { + var versionSpan = span.Slice(versionStart, i - versionStart); + + if (versionSpan.Length == 0) + { + RejectRequestLine(span); + } + else + { + RejectRequest(RequestRejectionReason.UnrecognizedHTTPVersion, versionSpan.GetAsciiStringEscaped(32)); + } + } + break; + case StartLineState.NewLine: + if (ch != ByteLF) + { + RejectRequestLine(span); + } + + state = StartLineState.Complete; + break; + case StartLineState.Complete: + break; + } + } + } + + if (state != StartLineState.Complete) + { + RejectRequestLine(span); + } + + var pathBuffer = span.Slice(pathStart, pathEnd - pathStart); + var targetBuffer = span.Slice(pathStart, queryEnd - pathStart); + var query = span.Slice(queryStart, queryEnd - queryStart); + + handler.OnStartLine(method, httpVersion, targetBuffer, pathBuffer, query, customMethod); + consumed = buffer.Move(start, i); + examined = consumed; + return true; + } + + public unsafe bool ParseHeaders(T handler, ReadableBuffer buffer, out ReadCursor consumed, out ReadCursor examined, out int consumedBytes) where T : IHttpHeadersHandler + { + consumed = buffer.Start; + examined = buffer.End; + consumedBytes = 0; + + var bufferEnd = buffer.End; + + var reader = new ReadableBufferReader(buffer); + while (true) + { + var start = reader; + int ch1 = reader.Take(); + var ch2 = reader.Take(); + + if (ch1 == -1) + { + return false; + } + + if (ch1 == ByteCR) + { + // Check for final CRLF. + if (ch2 == -1) + { + return false; + } + else if (ch2 == ByteLF) + { + consumed = reader.Cursor; + examined = consumed; + return true; + } + + // Headers don't end in CRLF line. + RejectRequest(RequestRejectionReason.HeadersCorruptedInvalidHeaderSequence); + } + else if (ch1 == ByteSpace || ch1 == ByteTab) + { + RejectRequest(RequestRejectionReason.HeaderLineMustNotStartWithWhitespace); + } + + // Reset the reader since we're not at the end of headers + reader = start; + + if (ReadCursorOperations.Seek(consumed, bufferEnd, out var lineEnd, ByteLF) == -1) + { + return false; + } + + const int stackAllocLimit = 512; + + if (lineEnd != bufferEnd) + { + lineEnd = buffer.Move(lineEnd, 1); + } + + var headerBuffer = buffer.Slice(consumed, lineEnd); + + Span span; + if (headerBuffer.IsSingleSpan) + { + // No copies, directly use the one and only span + span = headerBuffer.First.Span; + } + else if (headerBuffer.Length < stackAllocLimit) + { + // Multiple buffers and < stackAllocLimit, copy into a stack buffer + byte* stackBuffer = stackalloc byte[headerBuffer.Length]; + span = new Span(stackBuffer, headerBuffer.Length); + headerBuffer.CopyTo(span); + } + else + { + // We're not a single span here but we can use pooled arrays to avoid allocations in the rare case + span = new Span(new byte[headerBuffer.Length]); + headerBuffer.CopyTo(span); + } + + var state = HeaderState.Name; + var nameStart = 0; + var nameEnd = -1; + var valueStart = -1; + var valueEnd = -1; + var nameHasWhitespace = false; + var previouslyWhitespace = false; + var headerLineLength = span.Length; + + fixed (byte* data = &span.DangerousGetPinnableReference()) + { + for (var i = 0; i < headerLineLength; i++) + { + var ch = data[i]; + + switch (state) + { + case HeaderState.Name: + if (ch == ByteColon) + { + if (nameHasWhitespace) + { + RejectRequest(RequestRejectionReason.WhitespaceIsNotAllowedInHeaderName); + } + + state = HeaderState.Whitespace; + nameEnd = i; + } + + if (ch == ByteSpace || ch == ByteTab) + { + nameHasWhitespace = true; + } + break; + case HeaderState.Whitespace: + { + var whitespace = ch == ByteTab || ch == ByteSpace || ch == ByteCR; + + if (!whitespace) + { + // Mark the first non whitespace char as the start of the + // header value and change the state to expect to the header value + valueStart = i; + state = HeaderState.ExpectValue; + } + // If we see a CR then jump to the next state directly + else if (ch == ByteCR) + { + state = HeaderState.ExpectValue; + goto case HeaderState.ExpectValue; + } + } + break; + case HeaderState.ExpectValue: + { + var whitespace = ch == ByteTab || ch == ByteSpace; + + if (whitespace) + { + if (!previouslyWhitespace) + { + // If we see a whitespace char then maybe it's end of the + // header value + valueEnd = i; + } + } + else if (ch == ByteCR) + { + // If we see a CR and we haven't ever seen whitespace then + // this is the end of the header value + if (valueEnd == -1) + { + valueEnd = i; + } + + // We never saw a non whitespace character before the CR + if (valueStart == -1) + { + valueStart = valueEnd; + } + + state = HeaderState.ExpectNewLine; + } + else + { + // If we find a non whitespace char that isn't CR then reset the end index + valueEnd = -1; + } + + previouslyWhitespace = whitespace; + } + break; + case HeaderState.ExpectNewLine: + if (ch != ByteLF) + { + RejectRequest(RequestRejectionReason.HeaderValueMustNotContainCR); + } + + state = HeaderState.Complete; + break; + default: + break; + } + } + } + + if (state == HeaderState.Name) + { + RejectRequest(RequestRejectionReason.NoColonCharacterFoundInHeaderLine); + } + + if (state == HeaderState.ExpectValue || state == HeaderState.Whitespace) + { + RejectRequest(RequestRejectionReason.MissingCRInHeaderLine); + } + + if (state != HeaderState.Complete) + { + return false; + } + + // Skip the reader forward past the header line + reader.Skip(headerLineLength); + + // Before accepting the header line, we need to see at least one character + // > so we can make sure there's no space or tab + var next = reader.Peek(); + + // TODO: We don't need to reject the line here, we can use the state machine + // to store the fact that we're reading a header value + if (next == -1) + { + // If we can't see the next char then reject the entire line + return false; + } + + if (next == ByteSpace || next == ByteTab) + { + // From https://tools.ietf.org/html/rfc7230#section-3.2.4: + // + // Historically, HTTP header field values could be extended over + // multiple lines by preceding each extra line with at least one space + // or horizontal tab (obs-fold). This specification deprecates such + // line folding except within the message/http media type + // (Section 8.3.1). A sender MUST NOT generate a message that includes + // line folding (i.e., that has any field-value that contains a match to + // the obs-fold rule) unless the message is intended for packaging + // within the message/http media type. + // + // A server that receives an obs-fold in a request message that is not + // within a message/http container MUST either reject the message by + // sending a 400 (Bad Request), preferably with a representation + // explaining that obsolete line folding is unacceptable, or replace + // each received obs-fold with one or more SP octets prior to + // interpreting the field value or forwarding the message downstream. + RejectRequest(RequestRejectionReason.HeaderValueLineFoldingNotSupported); + } + + var nameBuffer = span.Slice(nameStart, nameEnd - nameStart); + var valueBuffer = span.Slice(valueStart, valueEnd - valueStart); + consumedBytes += headerLineLength; + + handler.OnHeader(nameBuffer, valueBuffer); + consumed = reader.Cursor; + } + } + + private static bool IsValidTokenChar(char c) + { + // Determines if a character is valid as a 'token' as defined in the + // HTTP spec: https://tools.ietf.org/html/rfc7230#section-3.2.6 + return + (c >= '0' && c <= '9') || + (c >= 'A' && c <= 'Z') || + (c >= 'a' && c <= 'z') || + c == '!' || + c == '#' || + c == '$' || + c == '%' || + c == '&' || + c == '\'' || + c == '*' || + c == '+' || + c == '-' || + c == '.' || + c == '^' || + c == '_' || + c == '`' || + c == '|' || + c == '~'; + } + + public void RejectRequest(RequestRejectionReason reason) + { + RejectRequest(BadHttpRequestException.GetException(reason)); + } + + public void RejectRequest(RequestRejectionReason reason, string value) + { + RejectRequest(BadHttpRequestException.GetException(reason, value)); + } + + private void RejectRequest(BadHttpRequestException ex) + { + throw ex; + } + + private void RejectRequestLine(Span span) + { + const int MaxRequestLineError = 32; + RejectRequest(RequestRejectionReason.InvalidRequestLine, + Log.IsEnabled(LogLevel.Information) ? span.GetAsciiStringEscaped(MaxRequestLineError) : string.Empty); + } + + private enum HeaderState + { + Name, + Whitespace, + ExpectValue, + ExpectNewLine, + Complete + } + + private enum StartLineState + { + KnownMethod, + UnknownMethod, + Path, + QueryString, + KnownVersion, + UnknownVersion, + NewLine, + Complete + } + } +} \ No newline at end of file diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolIteratorExtensions.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/HttpUtilities.cs similarity index 59% rename from src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolIteratorExtensions.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/HttpUtilities.cs index 950ae4bc40..719e27eff4 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolIteratorExtensions.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/HttpUtilities.cs @@ -1,16 +1,16 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; using System.Diagnostics; -using System.IO.Pipelines; using System.Runtime.CompilerServices; using System.Text; using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure { - public static class MemoryPoolIteratorExtensions + public static class HttpUtilities { public const string Http10Version = "HTTP/1.0"; public const string Http11Version = "HTTP/1.1"; @@ -18,7 +18,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure // readonly primitive statics can be Jit'd to consts https://github.com/dotnet/coreclr/issues/1079 private readonly static ulong _httpConnectMethodLong = GetAsciiStringAsLong("CONNECT "); private readonly static ulong _httpDeleteMethodLong = GetAsciiStringAsLong("DELETE \0"); - private readonly static ulong _httpGetMethodLong = GetAsciiStringAsLong("GET \0\0\0\0"); private const uint _httpGetMethodInt = 542393671; // retun of GetAsciiStringAsInt("GET "); const results in better codegen private readonly static ulong _httpHeadMethodLong = GetAsciiStringAsLong("HEAD \0\0\0"); private readonly static ulong _httpPatchMethodLong = GetAsciiStringAsLong("PATCH \0\0"); @@ -36,18 +35,29 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure private readonly static ulong _mask5Chars = GetMaskAsLong(new byte[] { 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00 }); private readonly static ulong _mask4Chars = GetMaskAsLong(new byte[] { 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00 }); - private readonly static Tuple[] _knownMethods = new Tuple[8]; + private readonly static Tuple[] _knownMethods = new Tuple[8]; - static MemoryPoolIteratorExtensions() + private readonly static string[] _methodNames = new string[9]; + + static HttpUtilities() { - _knownMethods[0] = Tuple.Create(_mask4Chars, _httpPutMethodLong, HttpMethods.Put); - _knownMethods[1] = Tuple.Create(_mask5Chars, _httpPostMethodLong, HttpMethods.Post); - _knownMethods[2] = Tuple.Create(_mask5Chars, _httpHeadMethodLong, HttpMethods.Head); - _knownMethods[3] = Tuple.Create(_mask6Chars, _httpTraceMethodLong, HttpMethods.Trace); - _knownMethods[4] = Tuple.Create(_mask6Chars, _httpPatchMethodLong, HttpMethods.Patch); - _knownMethods[5] = Tuple.Create(_mask7Chars, _httpDeleteMethodLong, HttpMethods.Delete); - _knownMethods[6] = Tuple.Create(_mask8Chars, _httpConnectMethodLong, HttpMethods.Connect); - _knownMethods[7] = Tuple.Create(_mask8Chars, _httpOptionsMethodLong, HttpMethods.Options); + _knownMethods[0] = Tuple.Create(_mask4Chars, _httpPutMethodLong, HttpMethod.Put, 3); + _knownMethods[1] = Tuple.Create(_mask5Chars, _httpPostMethodLong, HttpMethod.Post, 4); + _knownMethods[2] = Tuple.Create(_mask5Chars, _httpHeadMethodLong, HttpMethod.Head, 4); + _knownMethods[3] = Tuple.Create(_mask6Chars, _httpTraceMethodLong, HttpMethod.Trace, 5); + _knownMethods[4] = Tuple.Create(_mask6Chars, _httpPatchMethodLong, HttpMethod.Patch, 5); + _knownMethods[5] = Tuple.Create(_mask7Chars, _httpDeleteMethodLong, HttpMethod.Delete, 6); + _knownMethods[6] = Tuple.Create(_mask8Chars, _httpConnectMethodLong, HttpMethod.Connect, 7); + _knownMethods[7] = Tuple.Create(_mask8Chars, _httpOptionsMethodLong, HttpMethod.Options, 7); + _methodNames[(byte)HttpMethod.Get] = HttpMethods.Get; + _methodNames[(byte)HttpMethod.Put] = HttpMethods.Put; + _methodNames[(byte)HttpMethod.Delete] = HttpMethods.Delete; + _methodNames[(byte)HttpMethod.Post] = HttpMethods.Post; + _methodNames[(byte)HttpMethod.Head] = HttpMethods.Head; + _methodNames[(byte)HttpMethod.Trace] = HttpMethods.Trace; + _methodNames[(byte)HttpMethod.Patch] = HttpMethods.Patch; + _methodNames[(byte)HttpMethod.Connect] = HttpMethods.Connect; + _methodNames[(byte)HttpMethod.Options] = HttpMethods.Options; } private unsafe static ulong GetAsciiStringAsLong(string str) @@ -84,67 +94,26 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure } } - public static string GetAsciiStringEscaped(this ReadCursor start, ReadCursor end, int maxChars) - { - var sb = new StringBuilder(); - var reader = new ReadableBufferReader(start, end); - - while (maxChars > 0 && !reader.End) - { - var ch = reader.Take(); - sb.Append(ch < 0x20 || ch >= 0x7F ? $"<0x{ch:X2}>" : ((char)ch).ToString()); - maxChars--; - } - - if (!reader.End) - { - sb.Append("..."); - } - - return sb.ToString(); - } - - public static string GetAsciiStringEscaped(this Span span) + public static string GetAsciiStringEscaped(this Span span, int maxChars) { var sb = new StringBuilder(); - for (var i = 0; i < span.Length; ++i) + int i; + for (i = 0; i < Math.Min(span.Length, maxChars); ++i) { var ch = span[i]; sb.Append(ch < 0x20 || ch >= 0x7F ? $"<0x{ch:X2}>" : ((char)ch).ToString()); } + if (span.Length > maxChars) + { + sb.Append("..."); + } return sb.ToString(); } - public static ArraySegment PeekArraySegment(this MemoryPoolIterator iter) - { - if (iter.IsDefault || iter.IsEnd) - { - return default(ArraySegment); - } - - if (iter.Index < iter.Block.End) - { - return new ArraySegment(iter.Block.Array, iter.Index, iter.Block.End - iter.Index); - } - - var block = iter.Block.Next; - while (block != null) - { - if (block.Start < block.End) - { - return new ArraySegment(block.Array, block.Start, block.End - block.Start); - } - block = block.Next; - } - - // The following should be unreachable due to the IsEnd check above. - throw new InvalidOperationException("This should be unreachable!"); - } - /// - /// Checks that up to 8 bytes from correspond to a known HTTP method. + /// Checks that up to 8 bytes from correspond to a known HTTP method. /// /// /// A "known HTTP method" can be an HTTP method name defined in the HTTP/1.1 RFC. @@ -154,44 +123,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure /// and will be compared with the required space. A mask is used if the Known method is less than 8 bytes. /// To optimize performance the GET method will be checked first. /// - /// The iterator from which to start the known string lookup. - /// A reference to a pre-allocated known string, if the input matches any. /// true if the input matches a known string, false otherwise. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static bool GetKnownMethod(this ReadableBuffer begin, out string knownMethod) - { - knownMethod = null; - if (begin.Length < sizeof(ulong)) - { - return false; - } - - ulong value = begin.ReadLittleEndian(); - if ((value & _mask4Chars) == _httpGetMethodLong) - { - knownMethod = HttpMethods.Get; - return true; - } - foreach (var x in _knownMethods) - { - if ((value & x.Item1) == x.Item2) - { - knownMethod = x.Item3; - return true; - } - } - - return false; - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static bool GetKnownMethod(this Span span, out string knownMethod) + public static bool GetKnownMethod(this Span span, out HttpMethod method, out int length) { if (span.TryRead(out var possiblyGet)) { if (possiblyGet == _httpGetMethodInt) { - knownMethod = HttpMethods.Get; + length = 3; + method = HttpMethod.Get; return true; } } @@ -202,18 +143,20 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure { if ((value & x.Item1) == x.Item2) { - knownMethod = x.Item3; + method = x.Item3; + length = x.Item4; return true; } } } - - knownMethod = null; + + method = HttpMethod.Custom; + length = 0; return false; } /// - /// Checks 9 bytes from correspond to a known HTTP version. + /// Checks 9 bytes from correspond to a known HTTP version. /// /// /// A "known HTTP version" Is is either HTTP/1.0 or HTTP/1.1. @@ -222,56 +165,26 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure /// The Known versions will be checked with the required '\r'. /// To optimize performance the HTTP/1.1 will be checked first. /// - /// The iterator from which to start the known string lookup. - /// A reference to a pre-allocated known string, if the input matches any. /// true if the input matches a known string, false otherwise. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static bool GetKnownVersion(this ReadableBuffer begin, out string knownVersion) - { - knownVersion = null; - - if (begin.Length < sizeof(ulong)) - { - return false; - } - - var value = begin.ReadLittleEndian(); - if (value == _http11VersionLong) - { - knownVersion = Http11Version; - } - else if (value == _http10VersionLong) - { - knownVersion = Http10Version; - } - - if (knownVersion != null) - { - if (begin.Slice(sizeof(ulong)).Peek() != '\r') - { - knownVersion = null; - } - } - - return knownVersion != null; - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static bool GetKnownVersion(this Span span, out string knownVersion) + public static bool GetKnownVersion(this Span span, out HttpVersion knownVersion, out byte length) { if (span.TryRead(out var version)) { if (version == _http11VersionLong) { - knownVersion = Http11Version; + length = sizeof(ulong); + knownVersion = HttpVersion.Http11; } else if (version == _http10VersionLong) { - knownVersion = Http10Version; + length = sizeof(ulong); + knownVersion = HttpVersion.Http10; } else { - knownVersion = null; + length = 0; + knownVersion = HttpVersion.Unknown; return false; } @@ -281,8 +194,31 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure } } - knownVersion = null; + knownVersion = HttpVersion.Unknown; + length = 0; return false; } + + public static string VersionToString(HttpVersion httpVersion) + { + switch (httpVersion) + { + case HttpVersion.Http10: + return Http10Version; + case HttpVersion.Http11: + return Http11Version; + default: + return null; + } + } + public static string MethodToString(HttpMethod method) + { + int methodIndex = (int)method; + if (methodIndex >= 0 && methodIndex <= 8) + { + return _methodNames[methodIndex]; + } + return null; + } } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/ServiceContext.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/ServiceContext.cs index 10ee1378f7..531ff25fe7 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/ServiceContext.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/ServiceContext.cs @@ -16,6 +16,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal public IThreadPool ThreadPool { get; set; } + public IHttpParser HttpParser { get; set; } + public Func FrameFactory { get; set; } public DateHeaderValueManager DateHeaderValueManager { get; set; } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServer.cs b/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServer.cs index 01e9f74402..194d03b0dd 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServer.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServer.cs @@ -99,6 +99,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel }, AppLifetime = _applicationLifetime, Log = trace, + HttpParser = new KestrelHttpParser(trace), ThreadPool = threadPool, DateHeaderValueManager = dateHeaderValueManager, ServerOptions = Options diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/KnownStrings.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/KnownStrings.cs index 74ef1153ff..f5fd841f90 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/KnownStrings.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/KnownStrings.cs @@ -4,6 +4,7 @@ using System; using System.Text; using BenchmarkDotNet.Attributes; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; namespace Microsoft.AspNetCore.Server.Kestrel.Performance @@ -18,29 +19,29 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance public int GetKnownMethod_GET() { int len = 0; - string method; + HttpMethod method; Span data = _method; for (int i = 0; i < loops; i++) { - data.GetKnownMethod(out method); - len += method.Length; - data.GetKnownMethod(out method); - len += method.Length; - data.GetKnownMethod(out method); - len += method.Length; - data.GetKnownMethod(out method); - len += method.Length; - data.GetKnownMethod(out method); - len += method.Length; - data.GetKnownMethod(out method); - len += method.Length; - data.GetKnownMethod(out method); - len += method.Length; - data.GetKnownMethod(out method); - len += method.Length; - data.GetKnownMethod(out method); - len += method.Length; - data.GetKnownMethod(out method); - len += method.Length; + data.GetKnownMethod(out method, out var length); + len += length; + data.GetKnownMethod(out method, out length); + len += length; + data.GetKnownMethod(out method, out length); + len += length; + data.GetKnownMethod(out method, out length); + len += length; + data.GetKnownMethod(out method, out length); + len += length; + data.GetKnownMethod(out method, out length); + len += length; + data.GetKnownMethod(out method, out length); + len += length; + data.GetKnownMethod(out method, out length); + len += length; + data.GetKnownMethod(out method, out length); + len += length; + data.GetKnownMethod(out method, out length); + len += length; } return len; } @@ -49,29 +50,29 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance public int GetKnownVersion_HTTP1_1() { int len = 0; - string version; + HttpVersion version; Span data = _version; for (int i = 0; i < loops; i++) { - data.GetKnownVersion(out version); - len += version.Length; - data.GetKnownVersion(out version); - len += version.Length; - data.GetKnownVersion(out version); - len += version.Length; - data.GetKnownVersion(out version); - len += version.Length; - data.GetKnownVersion(out version); - len += version.Length; - data.GetKnownVersion(out version); - len += version.Length; - data.GetKnownVersion(out version); - len += version.Length; - data.GetKnownVersion(out version); - len += version.Length; - data.GetKnownVersion(out version); - len += version.Length; - data.GetKnownVersion(out version); - len += version.Length; + data.GetKnownVersion(out version, out var length); + len += length; + data.GetKnownVersion(out version, out length); + len += length; + data.GetKnownVersion(out version, out length); + len += length; + data.GetKnownVersion(out version, out length); + len += length; + data.GetKnownVersion(out version, out length); + len += length; + data.GetKnownVersion(out version, out length); + len += length; + data.GetKnownVersion(out version, out length); + len += length; + data.GetKnownVersion(out version, out length); + len += length; + data.GetKnownVersion(out version, out length); + len += length; + data.GetKnownVersion(out version, out length); + len += length; } return len; } diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsing.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsing.cs index e42f109178..0b42b9761e 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsing.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsing.cs @@ -58,6 +58,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance private static readonly byte[] _unicodePipelinedRequests = Encoding.ASCII.GetBytes(string.Concat(Enumerable.Repeat(unicodeRequest, Pipelining))); private static readonly byte[] _unicodeRequest = Encoding.ASCII.GetBytes(unicodeRequest); + [Params(typeof(KestrelHttpParser))] + public Type ParserType { get; set; } + [Benchmark(Baseline = true, OperationsPerInvoke = InnerLoopCount)] public void ParsePlaintext() { @@ -176,6 +179,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance public void Setup() { var connectionContext = new MockConnection(new KestrelServerOptions()); + connectionContext.ListenerContext.ServiceContext.HttpParser = (IHttpParser) Activator.CreateInstance(ParserType, connectionContext.ListenerContext.ServiceContext.Log); + Frame = new Frame(application: null, context: connectionContext); PipelineFactory = new PipeFactory(); Pipe = PipelineFactory.Create(); diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs index 9e5fe001ef..853cb2cefd 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs @@ -55,6 +55,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { DateHeaderValueManager = new DateHeaderValueManager(), ServerOptions = new KestrelServerOptions(), + HttpParser = new KestrelHttpParser(trace), Log = trace }; var listenerContext = new ListenerContext(_serviceContext) diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/HttpUtilitiesTest.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/HttpUtilitiesTest.cs new file mode 100644 index 0000000000..6dd176e553 --- /dev/null +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/HttpUtilitiesTest.cs @@ -0,0 +1,122 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Text; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; +using Xunit; + +namespace Microsoft.AspNetCore.Server.KestrelTests +{ + public class HttpUtilitiesTest + { + [Theory] + [InlineData("CONNECT / HTTP/1.1", true, "CONNECT", HttpMethod.Connect)] + [InlineData("DELETE / HTTP/1.1", true, "DELETE", HttpMethod.Delete)] + [InlineData("GET / HTTP/1.1", true, "GET", HttpMethod.Get)] + [InlineData("HEAD / HTTP/1.1", true, "HEAD", HttpMethod.Head)] + [InlineData("PATCH / HTTP/1.1", true, "PATCH", HttpMethod.Patch)] + [InlineData("POST / HTTP/1.1", true, "POST", HttpMethod.Post)] + [InlineData("PUT / HTTP/1.1", true, "PUT", HttpMethod.Put)] + [InlineData("OPTIONS / HTTP/1.1", true, "OPTIONS", HttpMethod.Options)] + [InlineData("TRACE / HTTP/1.1", true, "TRACE", HttpMethod.Trace)] + [InlineData("GET/ HTTP/1.1", false, null, HttpMethod.Custom)] + [InlineData("get / HTTP/1.1", false, null, HttpMethod.Custom)] + [InlineData("GOT / HTTP/1.1", false, null, HttpMethod.Custom)] + [InlineData("ABC / HTTP/1.1", false, null, HttpMethod.Custom)] + [InlineData("PO / HTTP/1.1", false, null, HttpMethod.Custom)] + [InlineData("PO ST / HTTP/1.1", false, null, HttpMethod.Custom)] + [InlineData("short ", false, null, HttpMethod.Custom)] + public void GetsKnownMethod(string input, bool expectedResult, string expectedKnownString, HttpMethod expectedMethod) + { + // Arrange + var block = new Span(Encoding.ASCII.GetBytes(input)); + + // Act + HttpMethod knownMethod; + var result = block.GetKnownMethod(out knownMethod, out var length); + + string toString = null; + if (knownMethod != HttpMethod.Custom) + { + toString = HttpUtilities.MethodToString(knownMethod); + } + + + // Assert + Assert.Equal(expectedResult, result); + Assert.Equal(expectedMethod, knownMethod); + Assert.Equal(toString, expectedKnownString); + Assert.Equal(length, expectedKnownString?.Length ?? 0); + } + + [Theory] + [InlineData("HTTP/1.0\r", true, HttpUtilities.Http10Version, HttpVersion.Http10)] + [InlineData("HTTP/1.1\r", true, HttpUtilities.Http11Version, HttpVersion.Http11)] + [InlineData("HTTP/3.0\r", false, null, HttpVersion.Unknown)] + [InlineData("http/1.0\r", false, null, HttpVersion.Unknown)] + [InlineData("http/1.1\r", false, null, HttpVersion.Unknown)] + [InlineData("short ", false, null, HttpVersion.Unknown)] + public void GetsKnownVersion(string input, bool expectedResult, string expectedKnownString, HttpVersion version) + { + // Arrange + var block = new Span(Encoding.ASCII.GetBytes(input)); + + // Act + HttpVersion knownVersion; + var result = block.GetKnownVersion(out knownVersion, out var length); + string toString = null; + if (knownVersion != HttpVersion.Unknown) + { + toString = HttpUtilities.VersionToString(knownVersion); + } + // Assert + Assert.Equal(expectedResult, result); + Assert.Equal(expectedKnownString, toString); + Assert.Equal(expectedKnownString?.Length ?? 0, length); + } + + [Theory] + [InlineData("HTTP/1.0\r", "HTTP/1.0")] + [InlineData("HTTP/1.1\r", "HTTP/1.1")] + public void KnownVersionsAreInterned(string input, string expected) + { + TestKnownStringsInterning(input, expected, span => + { + HttpUtilities.GetKnownVersion(span, out var version, out var lenght); + return HttpUtilities.VersionToString(version); + }); + } + + [Theory] + [InlineData("CONNECT / HTTP/1.1", "CONNECT")] + [InlineData("DELETE / HTTP/1.1", "DELETE")] + [InlineData("GET / HTTP/1.1", "GET")] + [InlineData("HEAD / HTTP/1.1", "HEAD")] + [InlineData("PATCH / HTTP/1.1", "PATCH")] + [InlineData("POST / HTTP/1.1", "POST")] + [InlineData("PUT / HTTP/1.1", "PUT")] + [InlineData("OPTIONS / HTTP/1.1", "OPTIONS")] + [InlineData("TRACE / HTTP/1.1", "TRACE")] + public void KnownMethodsAreInterned(string input, string expected) + { + TestKnownStringsInterning(input, expected, span => + { + HttpUtilities.GetKnownMethod(span, out var method, out var length); + return HttpUtilities.MethodToString(method); + }); + } + + private void TestKnownStringsInterning(string input, string expected, Func, string> action) + { + // Act + var knownString1 = action(new Span(Encoding.ASCII.GetBytes(input))); + var knownString2 = action(new Span(Encoding.ASCII.GetBytes(input))); + + // Assert + Assert.Equal(knownString1, expected); + Assert.Same(knownString1, knownString2); + } + } +} \ No newline at end of file diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/ListenerPrimaryTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/ListenerPrimaryTests.cs index 137eaee98a..797520a1c7 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/ListenerPrimaryTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/ListenerPrimaryTests.cs @@ -45,6 +45,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests DateHeaderValueManager = serviceContextPrimary.DateHeaderValueManager, ServerOptions = serviceContextPrimary.ServerOptions, ThreadPool = serviceContextPrimary.ThreadPool, + HttpParser = new KestrelHttpParser(serviceContextPrimary.Log), FrameFactory = context => { return new Frame(new TestApplication(c => @@ -121,6 +122,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests DateHeaderValueManager = serviceContextPrimary.DateHeaderValueManager, ServerOptions = serviceContextPrimary.ServerOptions, ThreadPool = serviceContextPrimary.ThreadPool, + HttpParser = new KestrelHttpParser(serviceContextPrimary.Log), FrameFactory = context => { return new Frame(new TestApplication(c => @@ -243,6 +245,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests DateHeaderValueManager = serviceContextPrimary.DateHeaderValueManager, ServerOptions = serviceContextPrimary.ServerOptions, ThreadPool = serviceContextPrimary.ThreadPool, + HttpParser = new KestrelHttpParser(serviceContextPrimary.Log), FrameFactory = context => { return new Frame(new TestApplication(c => diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolIteratorTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolIteratorTests.cs index 78b7e1fc36..83cf36c4c8 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolIteratorTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolIteratorTests.cs @@ -7,6 +7,8 @@ using System.IO.Pipelines; using System.Linq; using System.Numerics; using System.Text; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Xunit; using MemoryPool = Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPool; @@ -166,109 +168,77 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } [Fact] - public void PeekArraySegment() + public async Task PeekArraySegment() { - // Arrange - var block = _pool.Lease(); - var bytes = new byte[] { 0, 1, 2, 3, 4, 5, 6, 7 }; - Buffer.BlockCopy(bytes, 0, block.Array, block.Start, bytes.Length); - block.End += bytes.Length; - var scan = block.GetIterator(); - var originalIndex = scan.Index; + using (var pipeFactory = new PipeFactory()) + { + // Arrange + var pipe = pipeFactory.Create(); + var buffer = pipe.Writer.Alloc(); + buffer.Append(ReadableBuffer.Create(new byte[] { 0, 1, 2, 3, 4, 5, 6, 7 })); + await buffer.FlushAsync(); + + // Act + var result = await pipe.Reader.PeekAsync(); - // Act - var result = scan.PeekArraySegment(); + // Assert + Assert.Equal(new byte[] {0, 1, 2, 3, 4, 5, 6, 7}, result); - // Assert - Assert.Equal(new byte[] { 0, 1, 2, 3, 4, 5, 6, 7 }, result); - Assert.Equal(originalIndex, scan.Index); - - _pool.Return(block); + pipe.Writer.Complete(); + pipe.Reader.Complete(); + } } [Fact] - public void PeekArraySegmentOnDefaultIteratorReturnsDefaultArraySegment() + public async Task PeekArraySegmentAtEndOfDataReturnsDefaultArraySegment() { - // Assert.Equals doesn't work since xunit tries to access the underlying array. - Assert.True(default(ArraySegment).Equals(default(MemoryPoolIterator).PeekArraySegment())); + using (var pipeFactory = new PipeFactory()) + { + // Arrange + var pipe = pipeFactory.Create(); + pipe.Writer.Complete(); + + // Act + var result = await pipe.Reader.PeekAsync(); + + // Assert + // Assert.Equals doesn't work since xunit tries to access the underlying array. + Assert.True(default(ArraySegment).Equals(result)); + + pipe.Reader.Complete(); + } } [Fact] - public void PeekArraySegmentAtEndOfDataReturnsDefaultArraySegment() + public async Task PeekArraySegmentAtBlockBoundary() { - // Arrange - var block = _pool.Lease(); - var bytes = new byte[] { 0, 1, 2, 3, 4, 5, 6, 7 }; - Buffer.BlockCopy(bytes, 0, block.Array, block.Start, bytes.Length); - block.End += bytes.Length; - block.Start = block.End; + using (var pipeFactory = new PipeFactory()) + { + var pipe = pipeFactory.Create(); + var buffer = pipe.Writer.Alloc(); + buffer.Append(ReadableBuffer.Create(new byte[] { 0, 1, 2, 3, 4, 5, 6, 7 })); + buffer.Append(ReadableBuffer.Create(new byte[] { 8, 9, 10, 11, 12, 13, 14, 15 })); + await buffer.FlushAsync(); - var scan = block.GetIterator(); + // Act + var result = await pipe.Reader.PeekAsync(); - // Act - var result = scan.PeekArraySegment(); + // Assert + Assert.Equal(new byte[] { 0, 1, 2, 3, 4, 5, 6, 7 }, result); - // Assert - // Assert.Equals doesn't work since xunit tries to access the underlying array. - Assert.True(default(ArraySegment).Equals(result)); + // Act + // Advance past the data in the first block + var readResult = pipe.Reader.ReadAsync().GetAwaiter().GetResult(); + pipe.Reader.Advance(readResult.Buffer.Move(readResult.Buffer.Start, 8)); + result = await pipe.Reader.PeekAsync(); - _pool.Return(block); - } + // Assert + Assert.Equal(new byte[] { 8, 9, 10, 11, 12, 13, 14, 15 }, result); - [Fact] - public void PeekArraySegmentAtBlockBoundary() - { - // Arrange - var firstBlock = _pool.Lease(); - var lastBlock = _pool.Lease(); + pipe.Writer.Complete(); + pipe.Reader.Complete(); + } - var firstBytes = new byte[] { 0, 1, 2, 3, 4, 5, 6, 7 }; - var lastBytes = new byte[] { 8, 9, 10, 11, 12, 13, 14, 15 }; - - Buffer.BlockCopy(firstBytes, 0, firstBlock.Array, firstBlock.Start, firstBytes.Length); - firstBlock.End += lastBytes.Length; - - firstBlock.Next = lastBlock; - Buffer.BlockCopy(lastBytes, 0, lastBlock.Array, lastBlock.Start, lastBytes.Length); - lastBlock.End += lastBytes.Length; - - var scan = firstBlock.GetIterator(); - var originalIndex = scan.Index; - var originalBlock = scan.Block; - - // Act - var result = scan.PeekArraySegment(); - - // Assert - Assert.Equal(new byte[] { 0, 1, 2, 3, 4, 5, 6, 7 }, result); - Assert.Equal(originalBlock, scan.Block); - Assert.Equal(originalIndex, scan.Index); - - // Act - // Advance past the data in the first block - scan.Skip(8); - result = scan.PeekArraySegment(); - - // Assert - Assert.Equal(new byte[] { 8, 9, 10, 11, 12, 13, 14, 15 }, result); - Assert.Equal(originalBlock, scan.Block); - Assert.Equal(originalIndex + 8, scan.Index); - - // Act - // Add anther empty block between the first and last block - var middleBlock = _pool.Lease(); - firstBlock.Next = middleBlock; - middleBlock.Next = lastBlock; - result = scan.PeekArraySegment(); - - // Assert - Assert.Equal(new byte[] { 8, 9, 10, 11, 12, 13, 14, 15 }, result); - Assert.Equal(originalBlock, scan.Block); - Assert.Equal(originalIndex + 8, scan.Index); - - _pool.Return(firstBlock); - _pool.Return(middleBlock); - _pool.Return(lastBlock); } [Fact] @@ -542,198 +512,6 @@ namespace Microsoft.AspNetCore.Server.KestrelTests _pool.Return(finalBlock); } - [Theory] - [InlineData("CONNECT / HTTP/1.1", true, "CONNECT")] - [InlineData("DELETE / HTTP/1.1", true, "DELETE")] - [InlineData("GET / HTTP/1.1", true, "GET")] - [InlineData("HEAD / HTTP/1.1", true, "HEAD")] - [InlineData("PATCH / HTTP/1.1", true, "PATCH")] - [InlineData("POST / HTTP/1.1", true, "POST")] - [InlineData("PUT / HTTP/1.1", true, "PUT")] - [InlineData("OPTIONS / HTTP/1.1", true, "OPTIONS")] - [InlineData("TRACE / HTTP/1.1", true, "TRACE")] - [InlineData("GET/ HTTP/1.1", false, null)] - [InlineData("get / HTTP/1.1", false, null)] - [InlineData("GOT / HTTP/1.1", false, null)] - [InlineData("ABC / HTTP/1.1", false, null)] - [InlineData("PO / HTTP/1.1", false, null)] - [InlineData("PO ST / HTTP/1.1", false, null)] - [InlineData("short ", false, null)] - public void GetsKnownMethod(string input, bool expectedResult, string expectedKnownString) - { - // Arrange - var block = ReadableBuffer.Create(Encoding.ASCII.GetBytes(input)); - - // Act - string knownString; - var result = block.GetKnownMethod(out knownString); - // Assert - Assert.Equal(expectedResult, result); - Assert.Equal(expectedKnownString, knownString); - } - - - [Theory] - [InlineData("CONNECT / HTTP/1.1", true, "CONNECT")] - [InlineData("DELETE / HTTP/1.1", true, "DELETE")] - [InlineData("GET / HTTP/1.1", true, "GET")] - [InlineData("HEAD / HTTP/1.1", true, "HEAD")] - [InlineData("PATCH / HTTP/1.1", true, "PATCH")] - [InlineData("POST / HTTP/1.1", true, "POST")] - [InlineData("PUT / HTTP/1.1", true, "PUT")] - [InlineData("OPTIONS / HTTP/1.1", true, "OPTIONS")] - [InlineData("TRACE / HTTP/1.1", true, "TRACE")] - [InlineData("GET/ HTTP/1.1", false, null)] - [InlineData("get / HTTP/1.1", false, null)] - [InlineData("GOT / HTTP/1.1", false, null)] - [InlineData("ABC / HTTP/1.1", false, null)] - [InlineData("PO / HTTP/1.1", false, null)] - [InlineData("PO ST / HTTP/1.1", false, null)] - [InlineData("short ", false, null)] - public void GetsKnownMethodOnBoundary(string input, bool expectedResult, string expectedKnownString) - { - // Test at boundary - var maxSplit = Math.Min(input.Length, 8); - - for (var split = 0; split <= maxSplit; split++) - { - using (var pipelineFactory = new PipeFactory()) - { - // Arrange - var pipe = pipelineFactory.Create(); - var buffer = pipe.Writer.Alloc(); - var block1Input = input.Substring(0, split); - var block2Input = input.Substring(split); - buffer.Append(ReadableBuffer.Create(Encoding.ASCII.GetBytes(block1Input))); - buffer.Append(ReadableBuffer.Create(Encoding.ASCII.GetBytes(block2Input))); - buffer.FlushAsync().GetAwaiter().GetResult(); - - var readResult = pipe.Reader.ReadAsync().GetAwaiter().GetResult(); - - // Act - string boundaryKnownString; - var boundaryResult = readResult.Buffer.GetKnownMethod(out boundaryKnownString); - - // Assert - Assert.Equal(expectedResult, boundaryResult); - Assert.Equal(expectedKnownString, boundaryKnownString); - } - } - } - - [Theory] - [InlineData("HTTP/1.0\r", true, MemoryPoolIteratorExtensions.Http10Version)] - [InlineData("HTTP/1.1\r", true, MemoryPoolIteratorExtensions.Http11Version)] - [InlineData("HTTP/3.0\r", false, null)] - [InlineData("http/1.0\r", false, null)] - [InlineData("http/1.1\r", false, null)] - [InlineData("short ", false, null)] - public void GetsKnownVersion(string input, bool expectedResult, string expectedKnownString) - { - // Arrange - var block = ReadableBuffer.Create(Encoding.ASCII.GetBytes(input)); - - // Act - string knownString; - var result = block.GetKnownVersion(out knownString); - // Assert - Assert.Equal(expectedResult, result); - Assert.Equal(expectedKnownString, knownString); - } - - [Theory] - [InlineData("HTTP/1.0\r", true, MemoryPoolIteratorExtensions.Http10Version)] - [InlineData("HTTP/1.1\r", true, MemoryPoolIteratorExtensions.Http11Version)] - [InlineData("HTTP/3.0\r", false, null)] - [InlineData("http/1.0\r", false, null)] - [InlineData("http/1.1\r", false, null)] - [InlineData("short ", false, null)] - public void GetsKnownVersionOnBoundary(string input, bool expectedResult, string expectedKnownString) - { - // Test at boundary - var maxSplit = Math.Min(input.Length, 9); - - for (var split = 0; split <= maxSplit; split++) - { - using (var pipelineFactory = new PipeFactory()) - { - // Arrange - var pipe = pipelineFactory.Create(); - var buffer = pipe.Writer.Alloc(); - var block1Input = input.Substring(0, split); - var block2Input = input.Substring(split); - buffer.Append(ReadableBuffer.Create(Encoding.ASCII.GetBytes(block1Input))); - buffer.Append(ReadableBuffer.Create(Encoding.ASCII.GetBytes(block2Input))); - buffer.FlushAsync().GetAwaiter().GetResult(); - - var readResult = pipe.Reader.ReadAsync().GetAwaiter().GetResult(); - - // Act - string boundaryKnownString; - var boundaryResult = readResult.Buffer.GetKnownVersion(out boundaryKnownString); - - // Assert - Assert.Equal(expectedResult, boundaryResult); - Assert.Equal(expectedKnownString, boundaryKnownString); - } - } - } - - [Theory] - [InlineData("HTTP/1.0\r", "HTTP/1.0")] - [InlineData("HTTP/1.1\r", "HTTP/1.1")] - public void KnownVersionsAreInterned(string input, string expected) - { - TestKnownStringsInterning(input, expected, MemoryPoolIteratorExtensions.GetKnownVersion); - } - - [Theory] - [InlineData("", "HTTP/1.1\r")] - [InlineData("H", "TTP/1.1\r")] - [InlineData("HT", "TP/1.1\r")] - [InlineData("HTT", "P/1.1\r")] - [InlineData("HTTP", "/1.1\r")] - [InlineData("HTTP/", "1.1\r")] - [InlineData("HTTP/1", ".1\r")] - [InlineData("HTTP/1.", "1\r")] - [InlineData("HTTP/1.1", "\r")] - [InlineData("HTTP/1.1\r", "")] - public void KnownVersionCanBeReadAtAnyBlockBoundary(string block1Input, string block2Input) - { - using (var pipelineFactory = new PipeFactory()) - { - // Arrange - var pipe = pipelineFactory.Create(); - var buffer = pipe.Writer.Alloc(); - buffer.Append(ReadableBuffer.Create(Encoding.ASCII.GetBytes(block1Input))); - buffer.Append(ReadableBuffer.Create(Encoding.ASCII.GetBytes(block2Input))); - buffer.FlushAsync().GetAwaiter().GetResult(); - - var readResult = pipe.Reader.ReadAsync().GetAwaiter().GetResult(); - // Act - string knownVersion; - var result = readResult.Buffer.GetKnownVersion(out knownVersion); - - // Assert - Assert.True(result); - Assert.Equal("HTTP/1.1", knownVersion); - } - } - - [Theory] - [InlineData("CONNECT / HTTP/1.1", "CONNECT")] - [InlineData("DELETE / HTTP/1.1", "DELETE")] - [InlineData("GET / HTTP/1.1", "GET")] - [InlineData("HEAD / HTTP/1.1", "HEAD")] - [InlineData("PATCH / HTTP/1.1", "PATCH")] - [InlineData("POST / HTTP/1.1", "POST")] - [InlineData("PUT / HTTP/1.1", "PUT")] - [InlineData("OPTIONS / HTTP/1.1", "OPTIONS")] - [InlineData("TRACE / HTTP/1.1", "TRACE")] - public void KnownMethodsAreInterned(string input, string expected) - { - TestKnownStringsInterning(input, expected, MemoryPoolIteratorExtensions.GetKnownMethod); - } [Theory] [MemberData(nameof(SeekByteLimitData))] @@ -1200,10 +978,10 @@ namespace Microsoft.AspNetCore.Server.KestrelTests try { // Arrange - var buffer = ReadableBuffer.Create(Encoding.ASCII.GetBytes(input)); + var buffer = new Span(Encoding.ASCII.GetBytes(input)); // Act - var result = buffer.Start.GetAsciiStringEscaped(buffer.End, maxChars); + var result = buffer.GetAsciiStringEscaped(maxChars); // Assert Assert.Equal(expected, result); @@ -1294,22 +1072,6 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } } - private delegate bool GetKnownString(ReadableBuffer iter, out string result); - - private void TestKnownStringsInterning(string input, string expected, GetKnownString action) - { - // Act - string knownString1, knownString2; - var result1 = action(ReadableBuffer.Create(Encoding.ASCII.GetBytes(input)), out knownString1); - var result2 = action(ReadableBuffer.Create(Encoding.ASCII.GetBytes(input)), out knownString2); - - // Assert - Assert.True(result1); - Assert.True(result2); - Assert.Equal(knownString1, expected); - Assert.Same(knownString1, knownString2); - } - public static IEnumerable SeekByteLimitData { get diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestInput.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/TestInput.cs index ff0d2d94c4..fae8ad499f 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/TestInput.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/TestInput.cs @@ -10,7 +10,6 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel; using Microsoft.AspNetCore.Server.Kestrel.Internal; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.AspNetCore.Testing; using Microsoft.Extensions.Internal; using MemoryPool = Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPool; @@ -25,11 +24,11 @@ namespace Microsoft.AspNetCore.Server.KestrelTests public TestInput() { var trace = new KestrelTrace(new TestKestrelTrace()); - var ltp = new LoggingThreadPool(trace); var serviceContext = new ServiceContext { DateHeaderValueManager = new DateHeaderValueManager(), - ServerOptions = new KestrelServerOptions() + ServerOptions = new KestrelServerOptions(), + HttpParser = new KestrelHttpParser(trace), }; var listenerContext = new ListenerContext(serviceContext) { diff --git a/test/shared/TestServiceContext.cs b/test/shared/TestServiceContext.cs index e7dc2c962f..356e1e3beb 100644 --- a/test/shared/TestServiceContext.cs +++ b/test/shared/TestServiceContext.cs @@ -21,6 +21,7 @@ namespace Microsoft.AspNetCore.Testing ThreadPool = new LoggingThreadPool(Log); DateHeaderValueManager = new DateHeaderValueManager(systemClock: new MockSystemClock()); DateHeaderValue = DateHeaderValueManager.GetDateHeaderValues().String; + HttpParser = new KestrelHttpParser(Log); ServerOptions = new KestrelServerOptions { AddServerHeader = false, From cb6059c143e595dd47b47892aa002adfcf3b9018 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Wed, 1 Mar 2017 13:12:03 -0800 Subject: [PATCH 1068/1662] Make the IHttpParser per frame and add a reset (#1415) * Make the IHttpParser per frame and add a reset - Made the IHttpParser a per frame object so state can be stored across method calls and parses. - Added HttpParserFactory to ServiceContext --- .../Internal/Http/Frame.cs | 5 +++- .../Internal/Http/IHttpParser.cs | 2 ++ .../Internal/Http/KestrelHttpParser.cs | 5 ++++ .../Internal/ServiceContext.cs | 2 +- .../KestrelServer.cs | 2 +- .../RequestParsing.cs | 4 +-- .../FrameResponseHeadersTests.cs | 30 ++++++++++++++++--- .../FrameTests.cs | 4 +-- .../ListenerPrimaryTests.cs | 6 ++-- .../TestInput.cs | 4 +-- test/shared/TestServiceContext.cs | 2 +- 11 files changed, 49 insertions(+), 17 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs index 26e9dddee6..c87c72c468 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs @@ -86,7 +86,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http ServerOptions = context.ListenerContext.ServiceContext.ServerOptions; _pathBase = context.ListenerContext.ListenOptions.PathBase; - _parser = context.ListenerContext.ServiceContext.HttpParser; + _parser = context.ListenerContext.ServiceContext.HttpParserFactory(this); FrameControl = this; _keepAliveMilliseconds = (long)ServerOptions.Limits.KeepAliveTimeout.TotalMilliseconds; @@ -379,6 +379,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _requestHeadersParsed = 0; _responseBytesWritten = 0; + + // When testing parser can be null + _parser.Reset(); } /// diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/IHttpParser.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/IHttpParser.cs index e1d68293cd..ee888bea1f 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/IHttpParser.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/IHttpParser.cs @@ -10,5 +10,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http bool ParseRequestLine(T handler, ReadableBuffer buffer, out ReadCursor consumed, out ReadCursor examined) where T : IHttpRequestLineHandler; bool ParseHeaders(T handler, ReadableBuffer buffer, out ReadCursor consumed, out ReadCursor examined, out int consumedBytes) where T : IHttpHeadersHandler; + + void Reset(); } } \ No newline at end of file diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/KestrelHttpParser.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/KestrelHttpParser.cs index 8f334a5a20..662fd8aabe 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/KestrelHttpParser.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/KestrelHttpParser.cs @@ -525,6 +525,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http Log.IsEnabled(LogLevel.Information) ? span.GetAsciiStringEscaped(MaxRequestLineError) : string.Empty); } + public void Reset() + { + + } + private enum HeaderState { Name, diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/ServiceContext.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/ServiceContext.cs index 531ff25fe7..6233378f40 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/ServiceContext.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/ServiceContext.cs @@ -16,7 +16,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal public IThreadPool ThreadPool { get; set; } - public IHttpParser HttpParser { get; set; } + public Func HttpParserFactory { get; set; } public Func FrameFactory { get; set; } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServer.cs b/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServer.cs index 194d03b0dd..1d05a0dd2b 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServer.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServer.cs @@ -99,7 +99,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel }, AppLifetime = _applicationLifetime, Log = trace, - HttpParser = new KestrelHttpParser(trace), + HttpParserFactory = frame => new KestrelHttpParser(frame.ConnectionContext.ListenerContext.ServiceContext.Log), ThreadPool = threadPool, DateHeaderValueManager = dateHeaderValueManager, ServerOptions = Options diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsing.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsing.cs index 0b42b9761e..9d91d8e681 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsing.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsing.cs @@ -162,7 +162,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance } Pipe.Reader.Advance(consumed, examined); } - while(true); + while (true); } private void ThrowInvalidStartLine() @@ -179,7 +179,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance public void Setup() { var connectionContext = new MockConnection(new KestrelServerOptions()); - connectionContext.ListenerContext.ServiceContext.HttpParser = (IHttpParser) Activator.CreateInstance(ParserType, connectionContext.ListenerContext.ServiceContext.Log); + connectionContext.ListenerContext.ServiceContext.HttpParserFactory = frame => (IHttpParser)Activator.CreateInstance(ParserType, frame.ConnectionContext.ListenerContext.ServiceContext.Log); Frame = new Frame(application: null, context: connectionContext); PipelineFactory = new PipeFactory(); diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameResponseHeadersTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameResponseHeadersTests.cs index b3dee3d0c7..7b908fd642 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameResponseHeadersTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameResponseHeadersTests.cs @@ -4,16 +4,14 @@ using System; using System.Collections.Generic; using System.Globalization; +using System.IO.Pipelines; using System.Net; -using System.Text; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Server.Kestrel; using Microsoft.AspNetCore.Server.Kestrel.Internal; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.Extensions.Primitives; using Xunit; -using Microsoft.Net.Http.Headers; namespace Microsoft.AspNetCore.Server.KestrelTests { @@ -27,7 +25,8 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var serviceContext = new ServiceContext { DateHeaderValueManager = new DateHeaderValueManager(), - ServerOptions = serverOptions + ServerOptions = serverOptions, + HttpParserFactory = f => new NoopHttpParser(), }; var listenerContext = new ListenerContext(serviceContext) { @@ -268,5 +267,28 @@ namespace Microsoft.AspNetCore.Server.KestrelTests "42,000", "42.000", }; + + private class NoopHttpParser : IHttpParser + { + public bool ParseHeaders(T handler, ReadableBuffer buffer, out ReadCursor consumed, out ReadCursor examined, out int consumedBytes) where T : IHttpHeadersHandler + { + consumed = buffer.Start; + examined = buffer.End; + consumedBytes = 0; + return false; + } + + public bool ParseRequestLine(T handler, ReadableBuffer buffer, out ReadCursor consumed, out ReadCursor examined) where T : IHttpRequestLineHandler + { + consumed = buffer.Start; + examined = buffer.End; + return false; + } + + public void Reset() + { + + } + } } } \ No newline at end of file diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs index 853cb2cefd..f4b4339479 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs @@ -55,7 +55,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { DateHeaderValueManager = new DateHeaderValueManager(), ServerOptions = new KestrelServerOptions(), - HttpParser = new KestrelHttpParser(trace), + HttpParserFactory = frame => new KestrelHttpParser(trace), Log = trace }; var listenerContext = new ListenerContext(_serviceContext) @@ -484,7 +484,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests await _socketInput.Writer.WriteAsync(requestLineBytes); var readableBuffer = (await _socketInput.Reader.ReadAsync()).Buffer; - var exception = Assert.Throws(() =>_frame.TakeStartLine(readableBuffer, out _consumed, out _examined)); + var exception = Assert.Throws(() => _frame.TakeStartLine(readableBuffer, out _consumed, out _examined)); _socketInput.Reader.Advance(_consumed, _examined); Assert.Equal("Request line too long.", exception.Message); diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/ListenerPrimaryTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/ListenerPrimaryTests.cs index 797520a1c7..486b9ffda5 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/ListenerPrimaryTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/ListenerPrimaryTests.cs @@ -45,7 +45,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests DateHeaderValueManager = serviceContextPrimary.DateHeaderValueManager, ServerOptions = serviceContextPrimary.ServerOptions, ThreadPool = serviceContextPrimary.ThreadPool, - HttpParser = new KestrelHttpParser(serviceContextPrimary.Log), + HttpParserFactory = frame => new KestrelHttpParser(serviceContextPrimary.Log), FrameFactory = context => { return new Frame(new TestApplication(c => @@ -122,7 +122,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests DateHeaderValueManager = serviceContextPrimary.DateHeaderValueManager, ServerOptions = serviceContextPrimary.ServerOptions, ThreadPool = serviceContextPrimary.ThreadPool, - HttpParser = new KestrelHttpParser(serviceContextPrimary.Log), + HttpParserFactory = frame => new KestrelHttpParser(serviceContextPrimary.Log), FrameFactory = context => { return new Frame(new TestApplication(c => @@ -245,7 +245,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests DateHeaderValueManager = serviceContextPrimary.DateHeaderValueManager, ServerOptions = serviceContextPrimary.ServerOptions, ThreadPool = serviceContextPrimary.ThreadPool, - HttpParser = new KestrelHttpParser(serviceContextPrimary.Log), + HttpParserFactory = frame => new KestrelHttpParser(serviceContextPrimary.Log), FrameFactory = context => { return new Frame(new TestApplication(c => diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestInput.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/TestInput.cs index fae8ad499f..19f1f81890 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/TestInput.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/TestInput.cs @@ -28,7 +28,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { DateHeaderValueManager = new DateHeaderValueManager(), ServerOptions = new KestrelServerOptions(), - HttpParser = new KestrelHttpParser(trace), + HttpParserFactory = frame => new KestrelHttpParser(trace), }; var listenerContext = new ListenerContext(serviceContext) { @@ -45,7 +45,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests _memoryPool = new MemoryPool(); _pipelineFactory = new PipeFactory(); - FrameContext.Input = _pipelineFactory.Create();; + FrameContext.Input = _pipelineFactory.Create(); ; } public Frame FrameContext { get; set; } diff --git a/test/shared/TestServiceContext.cs b/test/shared/TestServiceContext.cs index 356e1e3beb..ad78537efb 100644 --- a/test/shared/TestServiceContext.cs +++ b/test/shared/TestServiceContext.cs @@ -21,7 +21,7 @@ namespace Microsoft.AspNetCore.Testing ThreadPool = new LoggingThreadPool(Log); DateHeaderValueManager = new DateHeaderValueManager(systemClock: new MockSystemClock()); DateHeaderValue = DateHeaderValueManager.GetDateHeaderValues().String; - HttpParser = new KestrelHttpParser(Log); + HttpParserFactory = frame => new KestrelHttpParser(Log); ServerOptions = new KestrelServerOptions { AddServerHeader = false, From b89415d9b2ea9bda711621bf9ac5a54f27dcb783 Mon Sep 17 00:00:00 2001 From: arespr Date: Thu, 2 Mar 2017 03:10:00 +0100 Subject: [PATCH 1069/1662] knownmethods optimizations --- .../Internal/Infrastructure/HttpUtilities.cs | 61 +++++++++---- .../KnownStrings.cs | 91 ++++++++++++++++++- 2 files changed, 132 insertions(+), 20 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/HttpUtilities.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/HttpUtilities.cs index 719e27eff4..0ec137186e 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/HttpUtilities.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/HttpUtilities.cs @@ -35,20 +35,21 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure private readonly static ulong _mask5Chars = GetMaskAsLong(new byte[] { 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00 }); private readonly static ulong _mask4Chars = GetMaskAsLong(new byte[] { 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00 }); - private readonly static Tuple[] _knownMethods = new Tuple[8]; + private readonly static Tuple[] _knownMethods = new Tuple[17]; private readonly static string[] _methodNames = new string[9]; static HttpUtilities() { - _knownMethods[0] = Tuple.Create(_mask4Chars, _httpPutMethodLong, HttpMethod.Put, 3); - _knownMethods[1] = Tuple.Create(_mask5Chars, _httpPostMethodLong, HttpMethod.Post, 4); - _knownMethods[2] = Tuple.Create(_mask5Chars, _httpHeadMethodLong, HttpMethod.Head, 4); - _knownMethods[3] = Tuple.Create(_mask6Chars, _httpTraceMethodLong, HttpMethod.Trace, 5); - _knownMethods[4] = Tuple.Create(_mask6Chars, _httpPatchMethodLong, HttpMethod.Patch, 5); - _knownMethods[5] = Tuple.Create(_mask7Chars, _httpDeleteMethodLong, HttpMethod.Delete, 6); - _knownMethods[6] = Tuple.Create(_mask8Chars, _httpConnectMethodLong, HttpMethod.Connect, 7); - _knownMethods[7] = Tuple.Create(_mask8Chars, _httpOptionsMethodLong, HttpMethod.Options, 7); + SetKnownMethod(_mask4Chars, _httpPutMethodLong, HttpMethod.Put, 3); + SetKnownMethod(_mask5Chars, _httpPostMethodLong, HttpMethod.Post, 4); + SetKnownMethod(_mask5Chars, _httpHeadMethodLong, HttpMethod.Head, 4); + SetKnownMethod(_mask6Chars, _httpTraceMethodLong, HttpMethod.Trace, 5); + SetKnownMethod(_mask6Chars, _httpPatchMethodLong, HttpMethod.Patch, 5); + SetKnownMethod(_mask7Chars, _httpDeleteMethodLong, HttpMethod.Delete, 6); + SetKnownMethod(_mask8Chars, _httpConnectMethodLong, HttpMethod.Connect, 7); + SetKnownMethod(_mask8Chars, _httpOptionsMethodLong, HttpMethod.Options, 7); + FillEmptyKnownMethods(); _methodNames[(byte)HttpMethod.Get] = HttpMethods.Get; _methodNames[(byte)HttpMethod.Put] = HttpMethods.Put; _methodNames[(byte)HttpMethod.Delete] = HttpMethods.Delete; @@ -60,6 +61,33 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure _methodNames[(byte)HttpMethod.Options] = HttpMethods.Options; } + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static int GetKnownMethodIndex(ulong value) + { + var tmp = (int)value & 0x100604; + + return ((tmp >> 2) | (tmp >> 8) | (tmp >> 17)) & 0x0F; + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static void SetKnownMethod(ulong mask, ulong knownMethodUlong, HttpMethod knownMethod, int length) + { + _knownMethods[GetKnownMethodIndex(knownMethodUlong)] = new Tuple(mask, knownMethodUlong, knownMethod, length, true); + } + + private static void FillEmptyKnownMethods() + { + var knownMethods = _knownMethods; + var length = knownMethods.Length; + for (int i = 0; i < length; i++) + { + if (knownMethods[i] == null) + { + knownMethods[i] = new Tuple(_mask8Chars, 0ul, HttpMethod.Custom, 0, false); + } + } + } + private unsafe static ulong GetAsciiStringAsLong(string str) { Debug.Assert(str.Length == 8, "String must be exactly 8 (ASCII) characters long."); @@ -139,14 +167,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure if (span.TryRead(out var value)) { - foreach (var x in _knownMethods) + var key = GetKnownMethodIndex(value); + + var x = _knownMethods[key]; + + if (x != null && (value & x.Item1) == x.Item2) { - if ((value & x.Item1) == x.Item2) - { - method = x.Item3; - length = x.Item4; - return true; - } + method = x.Item3; + length = x.Item4; + return x.Item5; } } diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/KnownStrings.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/KnownStrings.cs index f5fd841f90..95bb6a87ef 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/KnownStrings.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/KnownStrings.cs @@ -11,17 +11,98 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance { public class KnownStrings { - static byte[] _method = Encoding.UTF8.GetBytes("GET "); + static byte[] _methodGet = Encoding.UTF8.GetBytes("GET "); + static byte[] _methodConnect = Encoding.UTF8.GetBytes("CONNECT "); + static byte[] _methodDelete = Encoding.UTF8.GetBytes("DELETE "); + static byte[] _methodHead = Encoding.UTF8.GetBytes("HEAD "); + static byte[] _methodPatch = Encoding.UTF8.GetBytes("PATCH "); + static byte[] _methodPost = Encoding.UTF8.GetBytes("POST "); + static byte[] _methodPut = Encoding.UTF8.GetBytes("PUT "); + static byte[] _methodOptions = Encoding.UTF8.GetBytes("OPTIONS "); + static byte[] _methodTrace = Encoding.UTF8.GetBytes("TRACE "); + + + static byte[] _version = Encoding.UTF8.GetBytes("HTTP/1.1\r\n"); const int loops = 1000; [Benchmark(OperationsPerInvoke = loops * 10)] public int GetKnownMethod_GET() + { + Span data = _methodGet; + + return GetKnownMethod(data); + } + + [Benchmark(OperationsPerInvoke = loops * 10)] + public int GetKnownMethod_CONNECT() + { + Span data = _methodConnect; + + return GetKnownMethod(data); + } + + [Benchmark(OperationsPerInvoke = loops * 10)] + public int GetKnownMethod_DELETE() + { + Span data = _methodDelete; + + return GetKnownMethod(data); + } + [Benchmark(OperationsPerInvoke = loops * 10)] + public int GetKnownMethod_HEAD() + { + Span data = _methodHead; + + return GetKnownMethod(data); + } + + [Benchmark(OperationsPerInvoke = loops * 10)] + public int GetKnownMethod_PATCH() + { + Span data = _methodPatch; + + return GetKnownMethod(data); + } + [Benchmark(OperationsPerInvoke = loops * 10)] + public int GetKnownMethod_POST() + { + Span data = _methodPost; + + return GetKnownMethod(data); + } + [Benchmark(OperationsPerInvoke = loops * 10)] + public int GetKnownMethod_PUT() + { + Span data = _methodPut; + + return GetKnownMethod(data); + } + + [Benchmark(OperationsPerInvoke = loops * 10)] + public int GetKnownMethod_OPTIONS() + { + Span data = _methodOptions; + + return GetKnownMethod(data); + } + + [Benchmark(OperationsPerInvoke = loops * 10)] + public int GetKnownMethod_TRACE() + { + Span data = _methodTrace; + + return GetKnownMethod(data); + } + + + private int GetKnownMethod(Span data) { int len = 0; HttpMethod method; - Span data = _method; - for (int i = 0; i < loops; i++) { + + for (int i = 0; i < loops; i++) + { data.GetKnownMethod(out method, out var length); len += length; data.GetKnownMethod(out method, out length); @@ -46,13 +127,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance return len; } + [Benchmark(OperationsPerInvoke = loops * 10)] public int GetKnownVersion_HTTP1_1() { int len = 0; HttpVersion version; Span data = _version; - for (int i = 0; i < loops; i++) { + for (int i = 0; i < loops; i++) + { data.GetKnownVersion(out version, out var length); len += length; data.GetKnownVersion(out version, out length); From d3924b0149eeda4defa94ed2dc8af738a65810e1 Mon Sep 17 00:00:00 2001 From: Nate McMaster Date: Wed, 1 Mar 2017 18:14:13 -0800 Subject: [PATCH 1070/1662] Change korebuild branch and fix argument forwarding in bootstrapper --- build.ps1 | 4 ++-- build.sh | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/build.ps1 b/build.ps1 index f780c43a82..5bf0e2c113 100644 --- a/build.ps1 +++ b/build.ps1 @@ -33,7 +33,7 @@ cd $PSScriptRoot $repoFolder = $PSScriptRoot $env:REPO_FOLDER = $repoFolder -$koreBuildZip="https://github.com/aspnet/KoreBuild/archive/feature/msbuild.zip" +$koreBuildZip="https://github.com/aspnet/KoreBuild/archive/dev.zip" if ($env:KOREBUILD_ZIP) { $koreBuildZip=$env:KOREBUILD_ZIP @@ -64,4 +64,4 @@ if (!(Test-Path $buildFolder)) { } } -&"$buildFile" $args \ No newline at end of file +&"$buildFile" @args diff --git a/build.sh b/build.sh index ff79789196..b0bcadb579 100755 --- a/build.sh +++ b/build.sh @@ -2,7 +2,7 @@ repoFolder="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" cd $repoFolder -koreBuildZip="https://github.com/aspnet/KoreBuild/archive/feature/msbuild.zip" +koreBuildZip="https://github.com/aspnet/KoreBuild/archive/dev.zip" if [ ! -z $KOREBUILD_ZIP ]; then koreBuildZip=$KOREBUILD_ZIP fi @@ -43,4 +43,4 @@ if test ! -d $buildFolder; then fi fi -$buildFile -r $repoFolder "$@" \ No newline at end of file +$buildFile -r $repoFolder "$@" From f2a00da8110b1679c19640a4ed7043b07c19f8ea Mon Sep 17 00:00:00 2001 From: Pavel Krymets Date: Wed, 1 Mar 2017 18:18:34 -0800 Subject: [PATCH 1071/1662] Loop over bytes inside states of parser state machine (#1417) --- .../Internal/Http/KestrelHttpParser.cs | 225 ++++++++++-------- 1 file changed, 123 insertions(+), 102 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/KestrelHttpParser.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/KestrelHttpParser.cs index 662fd8aabe..2d1e51a013 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/KestrelHttpParser.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/KestrelHttpParser.cs @@ -72,36 +72,32 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var versionStart = -1; HttpVersion httpVersion = HttpVersion.Unknown; - HttpMethod method = HttpMethod.Custom; + HttpMethod method; Span customMethod; - var state = StartLineState.KnownMethod; + int i = 0; + var length = span.Length; + var done = false; - int i; fixed (byte* data = &span.DangerousGetPinnableReference()) { - var length = span.Length; - for (i = 0; i < length; i++) + switch (StartLineState.KnownMethod) { - var ch = data[i]; + case StartLineState.KnownMethod: + if (span.GetKnownMethod(out method, out var methodLength)) + { + // Update the index, current char, state and jump directly + // to the next state + i += methodLength + 1; - switch (state) - { - case StartLineState.KnownMethod: - if (span.GetKnownMethod(out method, out var methodLength)) - { - // Update the index, current char, state and jump directly - // to the next state - i += methodLength + 1; - ch = data[i]; - state = StartLineState.Path; + goto case StartLineState.Path; + } + goto case StartLineState.UnknownMethod; - goto case StartLineState.Path; - } + case StartLineState.UnknownMethod: + for (; i < length; i++) + { + var ch = data[i]; - state = StartLineState.UnknownMethod; - goto case StartLineState.UnknownMethod; - - case StartLineState.UnknownMethod: if (ch == ByteSpace) { customMethod = span.Slice(0, i); @@ -110,16 +106,23 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { RejectRequestLine(span); } + // Consume space + i++; - state = StartLineState.Path; + goto case StartLineState.Path; } - else if (!IsValidTokenChar((char)ch)) + + if (!IsValidTokenChar((char)ch)) { RejectRequestLine(span); } + } - break; - case StartLineState.Path: + break; + case StartLineState.Path: + for (; i < length; i++) + { + var ch = data[i]; if (ch == ByteSpace) { pathEnd = i; @@ -133,7 +136,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http // No query string found queryStart = queryEnd = i; - state = StartLineState.KnownVersion; + // Consume space + i++; + + goto case StartLineState.KnownVersion; } else if (ch == ByteQuestionMark) { @@ -146,7 +152,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } queryStart = i; - state = StartLineState.QueryString; + goto case StartLineState.QueryString; } else if (ch == BytePercentage) { @@ -160,35 +166,42 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { pathStart = i; } - break; - - case StartLineState.QueryString: + } + break; + case StartLineState.QueryString: + for (; i < length; i++) + { + var ch = data[i]; if (ch == ByteSpace) { queryEnd = i; - state = StartLineState.KnownVersion; + // Consume space + i++; + + goto case StartLineState.KnownVersion; } - break; - case StartLineState.KnownVersion: - // REVIEW: We don't *need* to slice here but it makes the API - // nicer, slicing should be free :) - if (span.Slice(i).GetKnownVersion(out httpVersion, out var versionLenght)) - { - // Update the index, current char, state and jump directly - // to the next state - i += versionLenght + 1; - ch = data[i]; - state = StartLineState.NewLine; + } + break; + case StartLineState.KnownVersion: + // REVIEW: We don't *need* to slice here but it makes the API + // nicer, slicing should be free :) + if (span.Slice(i).GetKnownVersion(out httpVersion, out var versionLenght)) + { + // Update the index, current char, state and jump directly + // to the next state + i += versionLenght + 1; + goto case StartLineState.NewLine; + } - goto case StartLineState.NewLine; - } + versionStart = i; - versionStart = i; - state = StartLineState.UnknownVersion; - goto case StartLineState.UnknownVersion; + goto case StartLineState.UnknownVersion; - case StartLineState.UnknownVersion: + case StartLineState.UnknownVersion: + for (; i < length; i++) + { + var ch = data[i]; if (ch == ByteCR) { var versionSpan = span.Slice(versionStart, i - versionStart); @@ -199,25 +212,27 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } else { - RejectRequest(RequestRejectionReason.UnrecognizedHTTPVersion, versionSpan.GetAsciiStringEscaped(32)); + RejectRequest(RequestRejectionReason.UnrecognizedHTTPVersion, + versionSpan.GetAsciiStringEscaped(32)); } } - break; - case StartLineState.NewLine: - if (ch != ByteLF) - { - RejectRequestLine(span); - } + } + break; + case StartLineState.NewLine: + if (data[i] != ByteLF) + { + RejectRequestLine(span); + } + i++; - state = StartLineState.Complete; - break; - case StartLineState.Complete: - break; - } + goto case StartLineState.Complete; + case StartLineState.Complete: + done = true; + break; } } - if (state != StartLineState.Complete) + if (!done) { RejectRequestLine(span); } @@ -311,7 +326,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http headerBuffer.CopyTo(span); } - var state = HeaderState.Name; var nameStart = 0; var nameEnd = -1; var valueStart = -1; @@ -320,33 +334,43 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var previouslyWhitespace = false; var headerLineLength = span.Length; + int i = 0; + var length = span.Length; + bool done = false; fixed (byte* data = &span.DangerousGetPinnableReference()) { - for (var i = 0; i < headerLineLength; i++) + switch (HeaderState.Name) { - var ch = data[i]; - - switch (state) - { - case HeaderState.Name: + case HeaderState.Name: + for (; i < length; i++) + { + var ch = data[i]; if (ch == ByteColon) { if (nameHasWhitespace) { RejectRequest(RequestRejectionReason.WhitespaceIsNotAllowedInHeaderName); } - - state = HeaderState.Whitespace; nameEnd = i; + + // Consume space + i++; + + goto case HeaderState.Whitespace; } if (ch == ByteSpace || ch == ByteTab) { nameHasWhitespace = true; } - break; - case HeaderState.Whitespace: + } + RejectRequest(RequestRejectionReason.NoColonCharacterFoundInHeaderLine); + + break; + case HeaderState.Whitespace: + for (; i < length; i++) { + var ch = data[i]; var whitespace = ch == ByteTab || ch == ByteSpace || ch == ByteCR; if (!whitespace) @@ -354,18 +378,23 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http // Mark the first non whitespace char as the start of the // header value and change the state to expect to the header value valueStart = i; - state = HeaderState.ExpectValue; + + goto case HeaderState.ExpectValue; } // If we see a CR then jump to the next state directly else if (ch == ByteCR) { - state = HeaderState.ExpectValue; goto case HeaderState.ExpectValue; } } - break; - case HeaderState.ExpectValue: + + RejectRequest(RequestRejectionReason.MissingCRInHeaderLine); + + break; + case HeaderState.ExpectValue: + for (; i < length; i++) { + var ch = data[i]; var whitespace = ch == ByteTab || ch == ByteSpace; if (whitespace) @@ -392,7 +421,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http valueStart = valueEnd; } - state = HeaderState.ExpectNewLine; + // Consume space + i++; + + goto case HeaderState.ExpectNewLine; } else { @@ -402,32 +434,21 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http previouslyWhitespace = whitespace; } - break; - case HeaderState.ExpectNewLine: - if (ch != ByteLF) - { - RejectRequest(RequestRejectionReason.HeaderValueMustNotContainCR); - } - - state = HeaderState.Complete; - break; - default: - break; - } + RejectRequest(RequestRejectionReason.MissingCRInHeaderLine); + break; + case HeaderState.ExpectNewLine: + if (data[i] != ByteLF) + { + RejectRequest(RequestRejectionReason.HeaderValueMustNotContainCR); + } + goto case HeaderState.Complete; + case HeaderState.Complete: + done = true; + break; } } - if (state == HeaderState.Name) - { - RejectRequest(RequestRejectionReason.NoColonCharacterFoundInHeaderLine); - } - - if (state == HeaderState.ExpectValue || state == HeaderState.Whitespace) - { - RejectRequest(RequestRejectionReason.MissingCRInHeaderLine); - } - - if (state != HeaderState.Complete) + if (!done) { return false; } @@ -527,7 +548,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http public void Reset() { - + } private enum HeaderState From ca31627a5e4c01378bdf0cfb495316803666c7e4 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Wed, 1 Mar 2017 22:33:37 -0800 Subject: [PATCH 1072/1662] Parser clean up (#1419) - Remove stackalloc - Remove extra Move in ParseRequestLine --- .../Internal/Http/KestrelHttpParser.cs | 25 +++---------------- 1 file changed, 3 insertions(+), 22 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/KestrelHttpParser.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/KestrelHttpParser.cs index 2d1e51a013..18477d28dd 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/KestrelHttpParser.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/KestrelHttpParser.cs @@ -32,32 +32,21 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http examined = buffer.End; var start = buffer.Start; - ReadCursor end; - if (ReadCursorOperations.Seek(start, buffer.End, out end, ByteLF) == -1) + if (ReadCursorOperations.Seek(start, buffer.End, out var end, ByteLF) == -1) { return false; } - const int stackAllocLimit = 512; - // Move 1 byte past the \n end = buffer.Move(end, 1); var startLineBuffer = buffer.Slice(start, end); Span span; - if (startLineBuffer.IsSingleSpan) { // No copies, directly use the one and only span span = startLineBuffer.First.Span; } - else if (startLineBuffer.Length < stackAllocLimit) - { - // Multiple buffers and < stackAllocLimit, copy into a stack buffer - byte* stackBuffer = stackalloc byte[startLineBuffer.Length]; - span = new Span(stackBuffer, startLineBuffer.Length); - startLineBuffer.CopyTo(span); - } else { // We're not a single span here but we can use pooled arrays to avoid allocations in the rare case @@ -242,7 +231,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var query = span.Slice(queryStart, queryEnd - queryStart); handler.OnStartLine(method, httpVersion, targetBuffer, pathBuffer, query, customMethod); - consumed = buffer.Move(start, i); + + consumed = end; examined = consumed; return true; } @@ -297,8 +287,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http return false; } - const int stackAllocLimit = 512; - if (lineEnd != bufferEnd) { lineEnd = buffer.Move(lineEnd, 1); @@ -312,13 +300,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http // No copies, directly use the one and only span span = headerBuffer.First.Span; } - else if (headerBuffer.Length < stackAllocLimit) - { - // Multiple buffers and < stackAllocLimit, copy into a stack buffer - byte* stackBuffer = stackalloc byte[headerBuffer.Length]; - span = new Span(stackBuffer, headerBuffer.Length); - headerBuffer.CopyTo(span); - } else { // We're not a single span here but we can use pooled arrays to avoid allocations in the rare case From 40ee51846cb59d04c194642c3770e18cf5f07e87 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Thu, 2 Mar 2017 14:56:05 +0000 Subject: [PATCH 1073/1662] Add allocations column (#1422) --- .../configs/CoreConfig.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/configs/CoreConfig.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/configs/CoreConfig.cs index 1621a1ddc2..01f4c02318 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/configs/CoreConfig.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/configs/CoreConfig.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using BenchmarkDotNet.Configs; +using BenchmarkDotNet.Diagnosers; using BenchmarkDotNet.Engines; using BenchmarkDotNet.Jobs; using BenchmarkDotNet.Validators; @@ -13,6 +14,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance public CoreConfig() { Add(JitOptimizationsValidator.FailOnError); + Add(MemoryDiagnoser.Default); Add(new RpsColumn()); Add(Job.Default From aaea173cbaa72b1c373349f6058fd6083e7e0ad7 Mon Sep 17 00:00:00 2001 From: Nate McMaster Date: Wed, 1 Mar 2017 18:25:45 -0800 Subject: [PATCH 1074/1662] Update AppVeyor and Travis settings --- .travis.yml | 2 +- appveyor.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 33d8f34d20..4d388988b4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -32,5 +32,5 @@ branches: before_install: - if test "$TRAVIS_OS_NAME" == "osx"; then brew update; brew install openssl; ln -s /usr/local/opt/openssl/lib/libcrypto.1.0.0.dylib /usr/local/lib/; ln -s /usr/local/opt/openssl/lib/libssl.1.0.0.dylib /usr/local/lib/; fi script: - - ./build.sh --quiet verify + - ./build.sh - if test "$TRAVIS_OS_NAME" != "osx"; then bash test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/SystemdActivation/docker.sh; fi diff --git a/appveyor.yml b/appveyor.yml index 61e1ba06b7..d622af030a 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -8,7 +8,7 @@ branches: - feature/dev-si - /^(.*\/)?ci-.*$/ build_script: - - build.cmd --quiet verify + - ps: .\build.ps1 clone_depth: 1 test: off deploy: off From 96fead6282057bb7f4475aa02dd7f48bc56a64ab Mon Sep 17 00:00:00 2001 From: arespr Date: Thu, 2 Mar 2017 20:58:18 +0100 Subject: [PATCH 1075/1662] better GetKnownMethodIndex, unit tests, benchmark repair --- .../Internal/Infrastructure/HttpUtilities.cs | 13 ++- .../KnownStrings.cs | 18 ++-- .../KnownStringsTests.cs | 92 +++++++++++++++++++ 3 files changed, 109 insertions(+), 14 deletions(-) create mode 100644 test/Microsoft.AspNetCore.Server.KestrelTests/KnownStringsTests.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/HttpUtilities.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/HttpUtilities.cs index 0ec137186e..8474b2b0f6 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/HttpUtilities.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/HttpUtilities.cs @@ -49,7 +49,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure SetKnownMethod(_mask7Chars, _httpDeleteMethodLong, HttpMethod.Delete, 6); SetKnownMethod(_mask8Chars, _httpConnectMethodLong, HttpMethod.Connect, 7); SetKnownMethod(_mask8Chars, _httpOptionsMethodLong, HttpMethod.Options, 7); - FillEmptyKnownMethods(); + FillKnownMethodsGaps(); _methodNames[(byte)HttpMethod.Get] = HttpMethods.Get; _methodNames[(byte)HttpMethod.Put] = HttpMethods.Put; _methodNames[(byte)HttpMethod.Delete] = HttpMethods.Delete; @@ -64,9 +64,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure [MethodImpl(MethodImplOptions.AggressiveInlining)] private static int GetKnownMethodIndex(ulong value) { - var tmp = (int)value & 0x100604; + const int MagicNumer = 0x0600000C; + var tmp = (int)value & MagicNumer; - return ((tmp >> 2) | (tmp >> 8) | (tmp >> 17)) & 0x0F; + return ((tmp >> 2) | (tmp >> 23)) & 0x0F; } [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -75,15 +76,17 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure _knownMethods[GetKnownMethodIndex(knownMethodUlong)] = new Tuple(mask, knownMethodUlong, knownMethod, length, true); } - private static void FillEmptyKnownMethods() + + private static void FillKnownMethodsGaps() { var knownMethods = _knownMethods; var length = knownMethods.Length; + var invalidHttpMethod = new Tuple(_mask8Chars, 0ul, HttpMethod.Custom, 0, false); for (int i = 0; i < length; i++) { if (knownMethods[i] == null) { - knownMethods[i] = new Tuple(_mask8Chars, 0ul, HttpMethod.Custom, 0, false); + knownMethods[i] = invalidHttpMethod; } } } diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/KnownStrings.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/KnownStrings.cs index 95bb6a87ef..99b20dc8c5 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/KnownStrings.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/KnownStrings.cs @@ -11,15 +11,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance { public class KnownStrings { - static byte[] _methodGet = Encoding.UTF8.GetBytes("GET "); - static byte[] _methodConnect = Encoding.UTF8.GetBytes("CONNECT "); - static byte[] _methodDelete = Encoding.UTF8.GetBytes("DELETE "); - static byte[] _methodHead = Encoding.UTF8.GetBytes("HEAD "); - static byte[] _methodPatch = Encoding.UTF8.GetBytes("PATCH "); - static byte[] _methodPost = Encoding.UTF8.GetBytes("POST "); - static byte[] _methodPut = Encoding.UTF8.GetBytes("PUT "); - static byte[] _methodOptions = Encoding.UTF8.GetBytes("OPTIONS "); - static byte[] _methodTrace = Encoding.UTF8.GetBytes("TRACE "); + static byte[] _methodConnect = Encoding.ASCII.GetBytes("CONNECT "); + static byte[] _methodDelete = Encoding.ASCII.GetBytes("DELETE \0"); + static byte[] _methodGet = Encoding.ASCII.GetBytes("GET "); + static byte[] _methodHead = Encoding.ASCII.GetBytes("HEAD \0\0\0"); + static byte[] _methodPatch = Encoding.ASCII.GetBytes("PATCH \0\0"); + static byte[] _methodPost = Encoding.ASCII.GetBytes("POST \0\0\0"); + static byte[] _methodPut = Encoding.ASCII.GetBytes("PUT \0\0\0\0"); + static byte[] _methodOptions = Encoding.ASCII.GetBytes("OPTIONS "); + static byte[] _methodTrace = Encoding.ASCII.GetBytes("TRACE \0\0"); diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/KnownStringsTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/KnownStringsTests.cs new file mode 100644 index 0000000000..14dba4859c --- /dev/null +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/KnownStringsTests.cs @@ -0,0 +1,92 @@ +using System; +using System.Collections.Generic; +using System.Runtime.CompilerServices; +using System.Text; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; +using Xunit; + +namespace Microsoft.AspNetCore.Server.KestrelTests +{ + public class KnownStringsTests + { + static byte[] _methodConnect = Encoding.ASCII.GetBytes("CONNECT "); + static byte[] _methodDelete = Encoding.ASCII.GetBytes("DELETE \0"); + static byte[] _methodGet = Encoding.ASCII.GetBytes("GET "); + static byte[] _methodHead = Encoding.ASCII.GetBytes("HEAD \0\0\0"); + static byte[] _methodPatch = Encoding.ASCII.GetBytes("PATCH \0\0"); + static byte[] _methodPost = Encoding.ASCII.GetBytes("POST \0\0\0"); + static byte[] _methodPut = Encoding.ASCII.GetBytes("PUT \0\0\0\0"); + static byte[] _methodOptions = Encoding.ASCII.GetBytes("OPTIONS "); + static byte[] _methodTrace = Encoding.ASCII.GetBytes("TRACE \0\0"); + + + const int MagicNumer = 0x0600000C; + static byte[] _invalidMethod1 = BitConverter.GetBytes((ulong)MagicNumer); + static byte[] _invalidMethod2 = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; + static byte[] _invalidMethod3 = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; + static byte[] _invalidMethod4 = Encoding.ASCII.GetBytes("CONNECT "); + static byte[] _invalidMethod5 = Encoding.ASCII.GetBytes("DELETE \0"); + static byte[] _invalidMethod6 = Encoding.ASCII.GetBytes("GET "); + static byte[] _invalidMethod7 = Encoding.ASCII.GetBytes("HEAD \0\0\0"); + static byte[] _invalidMethod8 = Encoding.ASCII.GetBytes("PATCH \0\0"); + static byte[] _invalidMethod9 = Encoding.ASCII.GetBytes("POST \0\0\0"); + static byte[] _invalidMethod10 = Encoding.ASCII.GetBytes("PUT \0\0\0\0"); + static byte[] _invalidMethod11 = Encoding.ASCII.GetBytes("OPTIONS "); + static byte[] _invalidMethod12 = Encoding.ASCII.GetBytes("TRACE \0\0"); + + + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static object[] CreateTestDataEntry(byte[] methodData, HttpMethod expectedMethod, int expectedLength, bool expectedResult) + { + return new object[] { methodData, expectedMethod, expectedLength, expectedResult }; + } + + private static readonly List _testData + = new List + { + CreateTestDataEntry(_methodGet, HttpMethod.Get, 3,true), + CreateTestDataEntry(_methodPut, HttpMethod.Put, 3,true), + CreateTestDataEntry(_methodPost, HttpMethod.Post, 4,true), + CreateTestDataEntry(_methodHead, HttpMethod.Head, 4,true), + CreateTestDataEntry(_methodTrace, HttpMethod.Trace, 5,true), + CreateTestDataEntry(_methodPatch, HttpMethod.Patch, 5,true), + CreateTestDataEntry(_methodDelete, HttpMethod.Delete, 6,true), + CreateTestDataEntry(_methodConnect, HttpMethod.Connect, 7,true), + CreateTestDataEntry(_methodOptions, HttpMethod.Options, 7,true), + CreateTestDataEntry(_invalidMethod1, HttpMethod.Custom, 0,false), + CreateTestDataEntry(_invalidMethod2, HttpMethod.Custom, 0,false), + CreateTestDataEntry(_invalidMethod3, HttpMethod.Custom, 0,false), + CreateTestDataEntry(_invalidMethod4, HttpMethod.Custom, 0,false), + CreateTestDataEntry(_invalidMethod5, HttpMethod.Custom, 0,false), + CreateTestDataEntry(_invalidMethod6, HttpMethod.Custom, 0,false), + CreateTestDataEntry(_invalidMethod7, HttpMethod.Custom, 0,false), + CreateTestDataEntry(_invalidMethod8, HttpMethod.Custom, 0,false), + CreateTestDataEntry(_invalidMethod9, HttpMethod.Custom, 0,false), + CreateTestDataEntry(_invalidMethod10, HttpMethod.Custom, 0,false), + CreateTestDataEntry(_invalidMethod11, HttpMethod.Custom, 0,false), + CreateTestDataEntry(_invalidMethod12, HttpMethod.Custom, 0,false), + }; + + public static IEnumerable TestData => _testData; + + + [Theory] + [MemberData(nameof(TestData), MemberType = typeof(KnownStringsTests))] + public void GetsKnownMethod(byte[] methodData, HttpMethod expectedMethod, int expectedLength, bool expectedResult) + { + var data = new Span(methodData); + + HttpMethod method; + int length; + + bool result = data.GetKnownMethod(out method, out length); + + Assert.Equal(expectedResult, result); + Assert.Equal(expectedMethod, method); + Assert.Equal(expectedLength, length); + + } + } +} From 8929b405277e42060e85ec52d6839add4ad6197b Mon Sep 17 00:00:00 2001 From: David Fowler Date: Thu, 2 Mar 2017 12:17:39 -0800 Subject: [PATCH 1076/1662] Single span optimizations (#1421) - Added a fast path for single span in the start line parsing - Added a fast path for single span header parsing - Changed the out header loop to be pointer based (instead of slicing) --- .../Internal/Http/KestrelHttpParser.cs | 424 ++++++++++++------ .../RequestParsing.cs | 4 +- 2 files changed, 284 insertions(+), 144 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/KestrelHttpParser.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/KestrelHttpParser.cs index 18477d28dd..a92c330b05 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/KestrelHttpParser.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/KestrelHttpParser.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Buffers; using System.IO.Pipelines; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.Extensions.Logging; @@ -31,27 +32,46 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http consumed = buffer.Start; examined = buffer.End; - var start = buffer.Start; - if (ReadCursorOperations.Seek(start, buffer.End, out var end, ByteLF) == -1) - { - return false; - } - - // Move 1 byte past the \n - end = buffer.Move(end, 1); - var startLineBuffer = buffer.Slice(start, end); - + ReadCursor end; Span span; - if (startLineBuffer.IsSingleSpan) + + // If the buffer is a single span then use it to find the LF + if (buffer.IsSingleSpan) { - // No copies, directly use the one and only span - span = startLineBuffer.First.Span; + var startLineSpan = buffer.First.Span; + var lineIndex = startLineSpan.IndexOfVectorized(ByteLF); + + if (lineIndex == -1) + { + return false; + } + + end = buffer.Move(consumed, lineIndex + 1); + span = startLineSpan.Slice(0, lineIndex + 1); } else { - // We're not a single span here but we can use pooled arrays to avoid allocations in the rare case - span = new Span(new byte[startLineBuffer.Length]); - startLineBuffer.CopyTo(span); + var start = buffer.Start; + if (ReadCursorOperations.Seek(start, buffer.End, out end, ByteLF) == -1) + { + return false; + } + + // Move 1 byte past the \n + end = buffer.Move(end, 1); + var startLineBuffer = buffer.Slice(start, end); + + if (startLineBuffer.IsSingleSpan) + { + // No copies, directly use the one and only span + span = startLineBuffer.First.Span; + } + else + { + // We're not a single span here but we can use pooled arrays to avoid allocations in the rare case + span = new Span(new byte[startLineBuffer.Length]); + startLineBuffer.CopyTo(span); + } } var pathStart = -1; @@ -243,6 +263,19 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http examined = buffer.End; consumedBytes = 0; + if (buffer.IsSingleSpan) + { + var result = TakeMessageHeadersSingleSpan(handler, buffer.First.Span, out consumedBytes); + consumed = buffer.Move(consumed, consumedBytes); + + if (result) + { + examined = consumed; + } + + return result; + } + var bufferEnd = buffer.End; var reader = new ReadableBufferReader(buffer); @@ -307,135 +340,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http headerBuffer.CopyTo(span); } - var nameStart = 0; - var nameEnd = -1; - var valueStart = -1; - var valueEnd = -1; - var nameHasWhitespace = false; - var previouslyWhitespace = false; - var headerLineLength = span.Length; - - int i = 0; - var length = span.Length; - bool done = false; - fixed (byte* data = &span.DangerousGetPinnableReference()) - { - switch (HeaderState.Name) - { - case HeaderState.Name: - for (; i < length; i++) - { - var ch = data[i]; - if (ch == ByteColon) - { - if (nameHasWhitespace) - { - RejectRequest(RequestRejectionReason.WhitespaceIsNotAllowedInHeaderName); - } - nameEnd = i; - - // Consume space - i++; - - goto case HeaderState.Whitespace; - } - - if (ch == ByteSpace || ch == ByteTab) - { - nameHasWhitespace = true; - } - } - RejectRequest(RequestRejectionReason.NoColonCharacterFoundInHeaderLine); - - break; - case HeaderState.Whitespace: - for (; i < length; i++) - { - var ch = data[i]; - var whitespace = ch == ByteTab || ch == ByteSpace || ch == ByteCR; - - if (!whitespace) - { - // Mark the first non whitespace char as the start of the - // header value and change the state to expect to the header value - valueStart = i; - - goto case HeaderState.ExpectValue; - } - // If we see a CR then jump to the next state directly - else if (ch == ByteCR) - { - goto case HeaderState.ExpectValue; - } - } - - RejectRequest(RequestRejectionReason.MissingCRInHeaderLine); - - break; - case HeaderState.ExpectValue: - for (; i < length; i++) - { - var ch = data[i]; - var whitespace = ch == ByteTab || ch == ByteSpace; - - if (whitespace) - { - if (!previouslyWhitespace) - { - // If we see a whitespace char then maybe it's end of the - // header value - valueEnd = i; - } - } - else if (ch == ByteCR) - { - // If we see a CR and we haven't ever seen whitespace then - // this is the end of the header value - if (valueEnd == -1) - { - valueEnd = i; - } - - // We never saw a non whitespace character before the CR - if (valueStart == -1) - { - valueStart = valueEnd; - } - - // Consume space - i++; - - goto case HeaderState.ExpectNewLine; - } - else - { - // If we find a non whitespace char that isn't CR then reset the end index - valueEnd = -1; - } - - previouslyWhitespace = whitespace; - } - RejectRequest(RequestRejectionReason.MissingCRInHeaderLine); - break; - case HeaderState.ExpectNewLine: - if (data[i] != ByteLF) - { - RejectRequest(RequestRejectionReason.HeaderValueMustNotContainCR); - } - goto case HeaderState.Complete; - case HeaderState.Complete: - done = true; - break; - } - } - - if (!done) + if (!TakeSingleHeader(span, out var nameStart, out var nameEnd, out var valueStart, out var valueEnd)) { return false; } // Skip the reader forward past the header line - reader.Skip(headerLineLength); + reader.Skip(span.Length); // Before accepting the header line, we need to see at least one character // > so we can make sure there's no space or tab @@ -473,13 +384,244 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var nameBuffer = span.Slice(nameStart, nameEnd - nameStart); var valueBuffer = span.Slice(valueStart, valueEnd - valueStart); - consumedBytes += headerLineLength; + consumedBytes += span.Length; handler.OnHeader(nameBuffer, valueBuffer); + consumed = reader.Cursor; } } + private unsafe bool TakeMessageHeadersSingleSpan(T handler, Span headersSpan, out int consumedBytes) where T : IHttpHeadersHandler + { + consumedBytes = 0; + + var remaining = headersSpan.Length; + var index = 0; + fixed (byte* data = &headersSpan.DangerousGetPinnableReference()) + { + while (true) + { + if (remaining < 2) + { + return false; + } + + var ch1 = data[index]; + var ch2 = data[index + 1]; + + if (ch1 == ByteCR) + { + // Check for final CRLF. + if (ch2 == ByteLF) + { + consumedBytes += 2; + return true; + } + + // Headers don't end in CRLF line. + RejectRequest(RequestRejectionReason.HeadersCorruptedInvalidHeaderSequence); + } + else if (ch1 == ByteSpace || ch1 == ByteTab) + { + RejectRequest(RequestRejectionReason.HeaderLineMustNotStartWithWhitespace); + } + + var endOfLineIndex = IndexOf(data, index, headersSpan.Length, ByteLF); + + if (endOfLineIndex == -1) + { + return false; + } + + var span = new Span(data + index, (endOfLineIndex - index + 1)); + index += span.Length; + + if (!TakeSingleHeader(span, out var nameStart, out var nameEnd, out var valueStart, out var valueEnd)) + { + return false; + } + + if ((endOfLineIndex + 1) >= headersSpan.Length) + { + return false; + } + + // Before accepting the header line, we need to see at least one character + // > so we can make sure there's no space or tab + var next = data[index]; + + if (next == ByteSpace || next == ByteTab) + { + // From https://tools.ietf.org/html/rfc7230#section-3.2.4: + // + // Historically, HTTP header field values could be extended over + // multiple lines by preceding each extra line with at least one space + // or horizontal tab (obs-fold). This specification deprecates such + // line folding except within the message/http media type + // (Section 8.3.1). A sender MUST NOT generate a message that includes + // line folding (i.e., that has any field-value that contains a match to + // the obs-fold rule) unless the message is intended for packaging + // within the message/http media type. + // + // A server that receives an obs-fold in a request message that is not + // within a message/http container MUST either reject the message by + // sending a 400 (Bad Request), preferably with a representation + // explaining that obsolete line folding is unacceptable, or replace + // each received obs-fold with one or more SP octets prior to + // interpreting the field value or forwarding the message downstream. + RejectRequest(RequestRejectionReason.HeaderValueLineFoldingNotSupported); + } + + var nameBuffer = span.Slice(nameStart, nameEnd - nameStart); + var valueBuffer = span.Slice(valueStart, valueEnd - valueStart); + + handler.OnHeader(nameBuffer, valueBuffer); + + consumedBytes += span.Length; + remaining -= span.Length; + } + } + } + + private unsafe int IndexOf(byte* data, int index, int length, byte value) + { + for (int i = index; i < length; i++) + { + if (data[i] == value) + { + return i; + } + } + return -1; + } + + private unsafe bool TakeSingleHeader(Span span, out int nameStart, out int nameEnd, out int valueStart, out int valueEnd) + { + nameStart = 0; + nameEnd = -1; + valueStart = -1; + valueEnd = -1; + var headerLineLength = span.Length; + var nameHasWhitespace = false; + var previouslyWhitespace = false; + + int i = 0; + var done = false; + fixed (byte* data = &span.DangerousGetPinnableReference()) + { + switch (HeaderState.Name) + { + case HeaderState.Name: + for (; i < headerLineLength; i++) + { + var ch = data[i]; + if (ch == ByteColon) + { + if (nameHasWhitespace) + { + RejectRequest(RequestRejectionReason.WhitespaceIsNotAllowedInHeaderName); + } + nameEnd = i; + + // Consume space + i++; + + goto case HeaderState.Whitespace; + } + + if (ch == ByteSpace || ch == ByteTab) + { + nameHasWhitespace = true; + } + } + RejectRequest(RequestRejectionReason.NoColonCharacterFoundInHeaderLine); + + break; + case HeaderState.Whitespace: + for (; i < headerLineLength; i++) + { + var ch = data[i]; + var whitespace = ch == ByteTab || ch == ByteSpace || ch == ByteCR; + + if (!whitespace) + { + // Mark the first non whitespace char as the start of the + // header value and change the state to expect to the header value + valueStart = i; + + goto case HeaderState.ExpectValue; + } + // If we see a CR then jump to the next state directly + else if (ch == ByteCR) + { + goto case HeaderState.ExpectValue; + } + } + + RejectRequest(RequestRejectionReason.MissingCRInHeaderLine); + + break; + case HeaderState.ExpectValue: + for (; i < headerLineLength; i++) + { + var ch = data[i]; + var whitespace = ch == ByteTab || ch == ByteSpace; + + if (whitespace) + { + if (!previouslyWhitespace) + { + // If we see a whitespace char then maybe it's end of the + // header value + valueEnd = i; + } + } + else if (ch == ByteCR) + { + // If we see a CR and we haven't ever seen whitespace then + // this is the end of the header value + if (valueEnd == -1) + { + valueEnd = i; + } + + // We never saw a non whitespace character before the CR + if (valueStart == -1) + { + valueStart = valueEnd; + } + + // Consume space + i++; + + goto case HeaderState.ExpectNewLine; + } + else + { + // If we find a non whitespace char that isn't CR then reset the end index + valueEnd = -1; + } + + previouslyWhitespace = whitespace; + } + RejectRequest(RequestRejectionReason.MissingCRInHeaderLine); + break; + case HeaderState.ExpectNewLine: + if (data[i] != ByteLF) + { + RejectRequest(RequestRejectionReason.HeaderValueMustNotContainCR); + } + goto case HeaderState.Complete; + case HeaderState.Complete: + done = true; + break; + } + } + + return done; + } + private static bool IsValidTokenChar(char c) { // Determines if a character is valid as a 'token' as defined in the diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsing.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsing.cs index 9d91d8e681..41c7010c48 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsing.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsing.cs @@ -143,9 +143,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance Frame.Reset(); - ReadCursor consumed; - ReadCursor examined; - if (!Frame.TakeStartLine(readableBuffer, out consumed, out examined)) + if (!Frame.TakeStartLine(readableBuffer, out var consumed, out var examined)) { ThrowInvalidStartLine(); } From bb74a6ce34733b333dee063d8a9fc3688f59d1c8 Mon Sep 17 00:00:00 2001 From: arespr Date: Thu, 2 Mar 2017 22:04:43 +0100 Subject: [PATCH 1077/1662] address PR feetback, fix unit tests for invalid known methods --- .../Internal/Infrastructure/HttpUtilities.cs | 1 - .../KnownStringsTests.cs | 26 ++++++++++--------- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/HttpUtilities.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/HttpUtilities.cs index 8474b2b0f6..954c19fe6b 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/HttpUtilities.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/HttpUtilities.cs @@ -76,7 +76,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure _knownMethods[GetKnownMethodIndex(knownMethodUlong)] = new Tuple(mask, knownMethodUlong, knownMethod, length, true); } - private static void FillKnownMethodsGaps() { var knownMethods = _knownMethods; diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/KnownStringsTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/KnownStringsTests.cs index 14dba4859c..f359dfae05 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/KnownStringsTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/KnownStringsTests.cs @@ -1,4 +1,7 @@ -using System; +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; using System.Collections.Generic; using System.Runtime.CompilerServices; using System.Text; @@ -25,15 +28,15 @@ namespace Microsoft.AspNetCore.Server.KestrelTests static byte[] _invalidMethod1 = BitConverter.GetBytes((ulong)MagicNumer); static byte[] _invalidMethod2 = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; static byte[] _invalidMethod3 = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; - static byte[] _invalidMethod4 = Encoding.ASCII.GetBytes("CONNECT "); - static byte[] _invalidMethod5 = Encoding.ASCII.GetBytes("DELETE \0"); - static byte[] _invalidMethod6 = Encoding.ASCII.GetBytes("GET "); - static byte[] _invalidMethod7 = Encoding.ASCII.GetBytes("HEAD \0\0\0"); - static byte[] _invalidMethod8 = Encoding.ASCII.GetBytes("PATCH \0\0"); - static byte[] _invalidMethod9 = Encoding.ASCII.GetBytes("POST \0\0\0"); - static byte[] _invalidMethod10 = Encoding.ASCII.GetBytes("PUT \0\0\0\0"); - static byte[] _invalidMethod11 = Encoding.ASCII.GetBytes("OPTIONS "); - static byte[] _invalidMethod12 = Encoding.ASCII.GetBytes("TRACE \0\0"); + static byte[] _invalidMethod4 = Encoding.ASCII.GetBytes("CONNECT_"); + static byte[] _invalidMethod5 = Encoding.ASCII.GetBytes("DELETE_\0"); + static byte[] _invalidMethod6 = Encoding.ASCII.GetBytes("GET_"); + static byte[] _invalidMethod7 = Encoding.ASCII.GetBytes("HEAD_\0\0\0"); + static byte[] _invalidMethod8 = Encoding.ASCII.GetBytes("PATCH_\0\0"); + static byte[] _invalidMethod9 = Encoding.ASCII.GetBytes("POST_\0\0\0"); + static byte[] _invalidMethod10 = Encoding.ASCII.GetBytes("PUT_\0\0\0\0"); + static byte[] _invalidMethod11 = Encoding.ASCII.GetBytes("OPTIONS_"); + static byte[] _invalidMethod12 = Encoding.ASCII.GetBytes("TRACE_\0\0"); @@ -81,12 +84,11 @@ namespace Microsoft.AspNetCore.Server.KestrelTests HttpMethod method; int length; - bool result = data.GetKnownMethod(out method, out length); + var result = data.GetKnownMethod(out method, out length); Assert.Equal(expectedResult, result); Assert.Equal(expectedMethod, method); Assert.Equal(expectedLength, length); - } } } From 346d8eaa0343cfbf6c6b64b504a46f8cf2f7de7e Mon Sep 17 00:00:00 2001 From: arespr Date: Thu, 2 Mar 2017 22:14:36 +0100 Subject: [PATCH 1078/1662] address PR feedback --- .../KnownStrings.cs | 4 -- .../KnownStringsTests.cs | 53 +++++++++---------- 2 files changed, 24 insertions(+), 33 deletions(-) diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/KnownStrings.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/KnownStrings.cs index 99b20dc8c5..240611a404 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/KnownStrings.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/KnownStrings.cs @@ -21,8 +21,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance static byte[] _methodOptions = Encoding.ASCII.GetBytes("OPTIONS "); static byte[] _methodTrace = Encoding.ASCII.GetBytes("TRACE \0\0"); - - static byte[] _version = Encoding.UTF8.GetBytes("HTTP/1.1\r\n"); const int loops = 1000; @@ -95,7 +93,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance return GetKnownMethod(data); } - private int GetKnownMethod(Span data) { int len = 0; @@ -127,7 +124,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance return len; } - [Benchmark(OperationsPerInvoke = loops * 10)] public int GetKnownVersion_HTTP1_1() { diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/KnownStringsTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/KnownStringsTests.cs index f359dfae05..7c6176766e 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/KnownStringsTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/KnownStringsTests.cs @@ -23,7 +23,6 @@ namespace Microsoft.AspNetCore.Server.KestrelTests static byte[] _methodOptions = Encoding.ASCII.GetBytes("OPTIONS "); static byte[] _methodTrace = Encoding.ASCII.GetBytes("TRACE \0\0"); - const int MagicNumer = 0x0600000C; static byte[] _invalidMethod1 = BitConverter.GetBytes((ulong)MagicNumer); static byte[] _invalidMethod2 = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; @@ -38,43 +37,39 @@ namespace Microsoft.AspNetCore.Server.KestrelTests static byte[] _invalidMethod11 = Encoding.ASCII.GetBytes("OPTIONS_"); static byte[] _invalidMethod12 = Encoding.ASCII.GetBytes("TRACE_\0\0"); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] private static object[] CreateTestDataEntry(byte[] methodData, HttpMethod expectedMethod, int expectedLength, bool expectedResult) { return new object[] { methodData, expectedMethod, expectedLength, expectedResult }; } - private static readonly List _testData - = new List - { - CreateTestDataEntry(_methodGet, HttpMethod.Get, 3,true), - CreateTestDataEntry(_methodPut, HttpMethod.Put, 3,true), - CreateTestDataEntry(_methodPost, HttpMethod.Post, 4,true), - CreateTestDataEntry(_methodHead, HttpMethod.Head, 4,true), - CreateTestDataEntry(_methodTrace, HttpMethod.Trace, 5,true), - CreateTestDataEntry(_methodPatch, HttpMethod.Patch, 5,true), - CreateTestDataEntry(_methodDelete, HttpMethod.Delete, 6,true), - CreateTestDataEntry(_methodConnect, HttpMethod.Connect, 7,true), - CreateTestDataEntry(_methodOptions, HttpMethod.Options, 7,true), - CreateTestDataEntry(_invalidMethod1, HttpMethod.Custom, 0,false), - CreateTestDataEntry(_invalidMethod2, HttpMethod.Custom, 0,false), - CreateTestDataEntry(_invalidMethod3, HttpMethod.Custom, 0,false), - CreateTestDataEntry(_invalidMethod4, HttpMethod.Custom, 0,false), - CreateTestDataEntry(_invalidMethod5, HttpMethod.Custom, 0,false), - CreateTestDataEntry(_invalidMethod6, HttpMethod.Custom, 0,false), - CreateTestDataEntry(_invalidMethod7, HttpMethod.Custom, 0,false), - CreateTestDataEntry(_invalidMethod8, HttpMethod.Custom, 0,false), - CreateTestDataEntry(_invalidMethod9, HttpMethod.Custom, 0,false), - CreateTestDataEntry(_invalidMethod10, HttpMethod.Custom, 0,false), - CreateTestDataEntry(_invalidMethod11, HttpMethod.Custom, 0,false), - CreateTestDataEntry(_invalidMethod12, HttpMethod.Custom, 0,false), - }; + private static readonly object[][] _testData = new object[][] + { + CreateTestDataEntry(_methodGet, HttpMethod.Get, 3, true), + CreateTestDataEntry(_methodPut, HttpMethod.Put, 3, true), + CreateTestDataEntry(_methodPost, HttpMethod.Post, 4, true), + CreateTestDataEntry(_methodHead, HttpMethod.Head, 4, true), + CreateTestDataEntry(_methodTrace, HttpMethod.Trace, 5, true), + CreateTestDataEntry(_methodPatch, HttpMethod.Patch, 5, true), + CreateTestDataEntry(_methodDelete, HttpMethod.Delete, 6, true), + CreateTestDataEntry(_methodConnect, HttpMethod.Connect, 7, true), + CreateTestDataEntry(_methodOptions, HttpMethod.Options, 7, true), + CreateTestDataEntry(_invalidMethod1, HttpMethod.Custom, 0, false), + CreateTestDataEntry(_invalidMethod2, HttpMethod.Custom, 0, false), + CreateTestDataEntry(_invalidMethod3, HttpMethod.Custom, 0, false), + CreateTestDataEntry(_invalidMethod4, HttpMethod.Custom, 0, false), + CreateTestDataEntry(_invalidMethod5, HttpMethod.Custom, 0, false), + CreateTestDataEntry(_invalidMethod6, HttpMethod.Custom, 0, false), + CreateTestDataEntry(_invalidMethod7, HttpMethod.Custom, 0, false), + CreateTestDataEntry(_invalidMethod8, HttpMethod.Custom, 0, false), + CreateTestDataEntry(_invalidMethod9, HttpMethod.Custom, 0, false), + CreateTestDataEntry(_invalidMethod10, HttpMethod.Custom, 0, false), + CreateTestDataEntry(_invalidMethod11, HttpMethod.Custom, 0, false), + CreateTestDataEntry(_invalidMethod12, HttpMethod.Custom, 0, false), + }; public static IEnumerable TestData => _testData; - [Theory] [MemberData(nameof(TestData), MemberType = typeof(KnownStringsTests))] public void GetsKnownMethod(byte[] methodData, HttpMethod expectedMethod, int expectedLength, bool expectedResult) From ac5fd3f29f2ebf500a21e9a727a42f89fe55bf8c Mon Sep 17 00:00:00 2001 From: arespr Date: Thu, 2 Mar 2017 22:45:36 +0100 Subject: [PATCH 1079/1662] PR feetback --- .../Internal/Infrastructure/HttpUtilities.cs | 4 ++-- .../KnownStringsTests.cs | 5 +---- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/HttpUtilities.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/HttpUtilities.cs index 954c19fe6b..ca765963ba 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/HttpUtilities.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/HttpUtilities.cs @@ -64,8 +64,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure [MethodImpl(MethodImplOptions.AggressiveInlining)] private static int GetKnownMethodIndex(ulong value) { - const int MagicNumer = 0x0600000C; - var tmp = (int)value & MagicNumer; + const int magicNumer = 0x0600000C; + var tmp = (int)value & magicNumer; return ((tmp >> 2) | (tmp >> 23)) & 0x0F; } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/KnownStringsTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/KnownStringsTests.cs index 7c6176766e..1926eaa377 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/KnownStringsTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/KnownStringsTests.cs @@ -76,10 +76,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { var data = new Span(methodData); - HttpMethod method; - int length; - - var result = data.GetKnownMethod(out method, out length); + var result = data.GetKnownMethod(out var method, out var length); Assert.Equal(expectedResult, result); Assert.Equal(expectedMethod, method); From 1e0f2b3951c89359da051ee969283d7dd6bba46c Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Thu, 2 Mar 2017 17:26:41 -0800 Subject: [PATCH 1080/1662] Fix systemd activation tests (#1429) --- .../SystemdActivation/docker.sh | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/SystemdActivation/docker.sh b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/SystemdActivation/docker.sh index b450ff3e54..7075a37d8c 100755 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/SystemdActivation/docker.sh +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/SystemdActivation/docker.sh @@ -2,13 +2,8 @@ set -e -# Ensure that dotnet is added to the PATH. -# build.sh should always be run before this script to create the .build/ directory and restore packages. scriptDir=$(dirname "${BASH_SOURCE[0]}") -repoDir=$(cd $scriptDir/../../.. && pwd) -source ./.build/KoreBuild.sh -r $repoDir --quiet - -dotnet publish -f netcoreapp1.1 ./samples/SampleApp/ +~/.dotnet/dotnet publish -f netcoreapp1.1 ./samples/SampleApp/ cp -R ./samples/SampleApp/bin/Debug/netcoreapp1.1/publish/ $scriptDir cp -R ~/.dotnet/ $scriptDir From 4d7c6ff69fcf147d83e5b44501f3edb0e29695bc Mon Sep 17 00:00:00 2001 From: David Fowler Date: Thu, 2 Mar 2017 21:40:20 -0800 Subject: [PATCH 1081/1662] use rtm appveyor --- NuGet.config | 1 - .../Microsoft.AspNetCore.Server.Kestrel.Performance.csproj | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/NuGet.config b/NuGet.config index 69bab2da9a..93f1ac47df 100644 --- a/NuGet.config +++ b/NuGet.config @@ -3,7 +3,6 @@ - diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Microsoft.AspNetCore.Server.Kestrel.Performance.csproj b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Microsoft.AspNetCore.Server.Kestrel.Performance.csproj index 4e4fabb7a6..746c59cd10 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Microsoft.AspNetCore.Server.Kestrel.Performance.csproj +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Microsoft.AspNetCore.Server.Kestrel.Performance.csproj @@ -22,7 +22,7 @@ - + From 4533383612fccc324337528f50ce324d7fc10d27 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Thu, 2 Mar 2017 23:09:13 -0800 Subject: [PATCH 1082/1662] React to hosting change - Kestrel binds to ipv4 by default Fixes #1432 --- .../AddressRegistrationTests.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs index 00bd4a0826..9e011adda4 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs @@ -371,8 +371,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests var dataset = new TheoryData>(); // Default host and port - dataset.Add(null, _ => new[] { "http://127.0.0.1:5000/", "http://[::1]:5000/" }); - dataset.Add(string.Empty, _ => new[] { "http://127.0.0.1:5000/", "http://[::1]:5000/" }); + dataset.Add(null, _ => new[] { "http://127.0.0.1:5000/", /*"http://[::1]:5000/"*/ }); + dataset.Add(string.Empty, _ => new[] { "http://127.0.0.1:5000/", /*"http://[::1]:5000/"*/ }); // Static ports var port = GetNextPort(); From 1d685e195ef57c209bffd45cc4dbc88f30fd5deb Mon Sep 17 00:00:00 2001 From: David Fowler Date: Fri, 3 Mar 2017 10:04:44 -0800 Subject: [PATCH 1083/1662] Parser cleanup and remove line continuation header error (#1431) - Cleaned up some parsing logic (removed locals etc) - Removing line continuation errors cleaned up code duplication a little bit --- .../Internal/Http/KestrelHttpParser.cs | 141 ++++-------------- .../Internal/Http/PipelineExtensions.cs | 2 + .../FrameTests.cs | 2 +- test/shared/HttpParsingData.cs | 2 +- 4 files changed, 31 insertions(+), 116 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/KestrelHttpParser.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/KestrelHttpParser.cs index a92c330b05..7ce4097985 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/KestrelHttpParser.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/KestrelHttpParser.cs @@ -61,17 +61,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http end = buffer.Move(end, 1); var startLineBuffer = buffer.Slice(start, end); - if (startLineBuffer.IsSingleSpan) - { - // No copies, directly use the one and only span - span = startLineBuffer.First.Span; - } - else - { - // We're not a single span here but we can use pooled arrays to avoid allocations in the rare case - span = new Span(new byte[startLineBuffer.Length]); - startLineBuffer.CopyTo(span); - } + span = startLineBuffer.ToSpan(); } var pathStart = -1; @@ -80,10 +70,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var pathEnd = -1; var versionStart = -1; - HttpVersion httpVersion = HttpVersion.Unknown; + var httpVersion = HttpVersion.Unknown; HttpMethod method; Span customMethod; - int i = 0; + var i = 0; var length = span.Length; var done = false; @@ -320,25 +310,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http return false; } - if (lineEnd != bufferEnd) - { - lineEnd = buffer.Move(lineEnd, 1); - } + // Make sure LF is included in lineEnd + lineEnd = buffer.Move(lineEnd, 1); var headerBuffer = buffer.Slice(consumed, lineEnd); - - Span span; - if (headerBuffer.IsSingleSpan) - { - // No copies, directly use the one and only span - span = headerBuffer.First.Span; - } - else - { - // We're not a single span here but we can use pooled arrays to avoid allocations in the rare case - span = new Span(new byte[headerBuffer.Length]); - headerBuffer.CopyTo(span); - } + var span = headerBuffer.ToSpan(); if (!TakeSingleHeader(span, out var nameStart, out var nameEnd, out var valueStart, out var valueEnd)) { @@ -347,73 +323,41 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http // Skip the reader forward past the header line reader.Skip(span.Length); - - // Before accepting the header line, we need to see at least one character - // > so we can make sure there's no space or tab - var next = reader.Peek(); - - // TODO: We don't need to reject the line here, we can use the state machine - // to store the fact that we're reading a header value - if (next == -1) - { - // If we can't see the next char then reject the entire line - return false; - } - - if (next == ByteSpace || next == ByteTab) - { - // From https://tools.ietf.org/html/rfc7230#section-3.2.4: - // - // Historically, HTTP header field values could be extended over - // multiple lines by preceding each extra line with at least one space - // or horizontal tab (obs-fold). This specification deprecates such - // line folding except within the message/http media type - // (Section 8.3.1). A sender MUST NOT generate a message that includes - // line folding (i.e., that has any field-value that contains a match to - // the obs-fold rule) unless the message is intended for packaging - // within the message/http media type. - // - // A server that receives an obs-fold in a request message that is not - // within a message/http container MUST either reject the message by - // sending a 400 (Bad Request), preferably with a representation - // explaining that obsolete line folding is unacceptable, or replace - // each received obs-fold with one or more SP octets prior to - // interpreting the field value or forwarding the message downstream. - RejectRequest(RequestRejectionReason.HeaderValueLineFoldingNotSupported); - } + consumed = reader.Cursor; + consumedBytes += span.Length; var nameBuffer = span.Slice(nameStart, nameEnd - nameStart); var valueBuffer = span.Slice(valueStart, valueEnd - valueStart); - consumedBytes += span.Length; handler.OnHeader(nameBuffer, valueBuffer); - - consumed = reader.Cursor; } } private unsafe bool TakeMessageHeadersSingleSpan(T handler, Span headersSpan, out int consumedBytes) where T : IHttpHeadersHandler { consumedBytes = 0; + var length = headersSpan.Length; - var remaining = headersSpan.Length; - var index = 0; fixed (byte* data = &headersSpan.DangerousGetPinnableReference()) { - while (true) + while (consumedBytes < length) { - if (remaining < 2) - { - return false; - } + var ch1 = data[consumedBytes]; + var ch2 = -1; - var ch1 = data[index]; - var ch2 = data[index + 1]; + if (consumedBytes + 1 < length) + { + ch2 = data[consumedBytes + 1]; + } if (ch1 == ByteCR) { // Check for final CRLF. - if (ch2 == ByteLF) + if (ch2 == -1) + { + return false; + } + else if (ch2 == ByteLF) { consumedBytes += 2; return true; @@ -427,61 +371,30 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http RejectRequest(RequestRejectionReason.HeaderLineMustNotStartWithWhitespace); } - var endOfLineIndex = IndexOf(data, index, headersSpan.Length, ByteLF); + var lineEnd = IndexOf(data, consumedBytes, headersSpan.Length, ByteLF); - if (endOfLineIndex == -1) + if (lineEnd == -1) { return false; } - var span = new Span(data + index, (endOfLineIndex - index + 1)); - index += span.Length; + var span = new Span(data + consumedBytes, (lineEnd - consumedBytes + 1)); if (!TakeSingleHeader(span, out var nameStart, out var nameEnd, out var valueStart, out var valueEnd)) { return false; } - if ((endOfLineIndex + 1) >= headersSpan.Length) - { - return false; - } - - // Before accepting the header line, we need to see at least one character - // > so we can make sure there's no space or tab - var next = data[index]; - - if (next == ByteSpace || next == ByteTab) - { - // From https://tools.ietf.org/html/rfc7230#section-3.2.4: - // - // Historically, HTTP header field values could be extended over - // multiple lines by preceding each extra line with at least one space - // or horizontal tab (obs-fold). This specification deprecates such - // line folding except within the message/http media type - // (Section 8.3.1). A sender MUST NOT generate a message that includes - // line folding (i.e., that has any field-value that contains a match to - // the obs-fold rule) unless the message is intended for packaging - // within the message/http media type. - // - // A server that receives an obs-fold in a request message that is not - // within a message/http container MUST either reject the message by - // sending a 400 (Bad Request), preferably with a representation - // explaining that obsolete line folding is unacceptable, or replace - // each received obs-fold with one or more SP octets prior to - // interpreting the field value or forwarding the message downstream. - RejectRequest(RequestRejectionReason.HeaderValueLineFoldingNotSupported); - } + consumedBytes += span.Length; var nameBuffer = span.Slice(nameStart, nameEnd - nameStart); var valueBuffer = span.Slice(valueStart, valueEnd - valueStart); handler.OnHeader(nameBuffer, valueBuffer); - - consumedBytes += span.Length; - remaining -= span.Length; } } + + return false; } private unsafe int IndexOf(byte* data, int index, int length, byte value) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/PipelineExtensions.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/PipelineExtensions.cs index c7a92e7639..a37670cfa6 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/PipelineExtensions.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/PipelineExtensions.cs @@ -3,6 +3,7 @@ using System; using System.IO.Pipelines; +using System.Runtime.CompilerServices; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; @@ -77,6 +78,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http return result; } + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Span ToSpan(this ReadableBuffer buffer) { if (buffer.IsSingleSpan) diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs index f4b4339479..0f3185e6c8 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs @@ -199,7 +199,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var exception = Assert.Throws(() => _frame.TakeMessageHeaders(readableBuffer, (FrameRequestHeaders)_frame.RequestHeaders, out _consumed, out _examined)); _socketInput.Reader.Advance(_consumed, _examined); - Assert.Equal("Header value line folding not supported.", exception.Message); + Assert.Equal("Header line must not start with whitespace.", exception.Message); Assert.Equal(StatusCodes.Status400BadRequest, exception.StatusCode); } diff --git a/test/shared/HttpParsingData.cs b/test/shared/HttpParsingData.cs index b38afb96c5..a5a83c58c6 100644 --- a/test/shared/HttpParsingData.cs +++ b/test/shared/HttpParsingData.cs @@ -287,7 +287,7 @@ namespace Microsoft.AspNetCore.Testing return new[] { - Tuple.Create(headersWithLineFolding,"Header value line folding not supported."), + Tuple.Create(headersWithLineFolding,"Header line must not start with whitespace."), Tuple.Create(headersWithCRInValue,"Header value must not contain CR characters."), Tuple.Create(headersWithMissingColon,"No ':' character found in header line."), Tuple.Create(headersStartingWithWhitespace, "Header line must not start with whitespace."), From 7cc5c537a42634c13e45705799098da06bc79a6c Mon Sep 17 00:00:00 2001 From: Krzysztof Cwalina Date: Thu, 2 Mar 2017 08:41:44 -0800 Subject: [PATCH 1084/1662] Added a new benchmark --- .../RequestParsing.cs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsing.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsing.cs index 9d91d8e681..7dffa9c1f4 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsing.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsing.cs @@ -23,6 +23,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance private const string plaintextRequest = "GET /plaintext HTTP/1.1\r\nHost: www.example.com\r\n\r\n"; + private const string plaintextTechEmpower = "GET /plaintext HTTP/1.1\r\n" + + "Host: localhost\r\n" + + "Accept: text/plain,text/html;q=0.9,application/xhtml+xml;q=0.9,application/xml;q=0.8,*/*;q=0.7\r\n" + + "Connection: keep-alive\r\n\r\n"; + private const string liveaspnetRequest = "GET https://live.asp.net/ HTTP/1.1\r\n" + "Host: live.asp.net\r\n" + "Connection: keep-alive\r\n" + @@ -51,7 +56,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance private static readonly byte[] _plaintextPipelinedRequests = Encoding.ASCII.GetBytes(string.Concat(Enumerable.Repeat(plaintextRequest, Pipelining))); private static readonly byte[] _plaintextRequest = Encoding.ASCII.GetBytes(plaintextRequest); - + private static readonly byte[] _plaintextTechEmpower = Encoding.ASCII.GetBytes(plaintextTechEmpower); + private static readonly byte[] _liveaspnentPipelinedRequests = Encoding.ASCII.GetBytes(string.Concat(Enumerable.Repeat(liveaspnetRequest, Pipelining))); private static readonly byte[] _liveaspnentRequest = Encoding.ASCII.GetBytes(liveaspnetRequest); @@ -71,6 +77,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance } } + [Benchmark(OperationsPerInvoke = InnerLoopCount)] + public void ParsePlaintextTechEmpower() + { + for (var i = 0; i < InnerLoopCount; i++) { + InsertData(_plaintextTechEmpower); + ParseData(); + } + } + [Benchmark(OperationsPerInvoke = InnerLoopCount * Pipelining)] public void ParsePipelinedPlaintext() { From ac60f13312b0776cbffe333e72ce521211845b89 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Fri, 3 Mar 2017 14:43:32 -0800 Subject: [PATCH 1085/1662] Modify RequestProcessingAsync to call single parse method (#1427) * Modify RequestProcessingAsync to call single parse method * Fix bad request logging --- .../BadHttpRequestException.cs | 3 + .../Internal/Http/Frame.cs | 77 ++++++++++-------- .../Internal/Http/FrameOfT.cs | 79 +++++-------------- .../Internal/Http/KestrelHttpParser.cs | 21 ++--- .../Internal/Http/MessageBody.cs | 2 +- .../Internal/Http/RequestProcessingStatus.cs | 14 ++++ .../RequestParsing.cs | 6 +- .../FrameTests.cs | 32 ++++---- 8 files changed, 111 insertions(+), 123 deletions(-) create mode 100644 src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/RequestProcessingStatus.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/BadHttpRequestException.cs b/src/Microsoft.AspNetCore.Server.Kestrel/BadHttpRequestException.cs index f7109710c6..a19fd6db35 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/BadHttpRequestException.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/BadHttpRequestException.cs @@ -40,6 +40,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel case RequestRejectionReason.HeaderValueLineFoldingNotSupported: ex = new BadHttpRequestException("Header value line folding not supported.", StatusCodes.Status400BadRequest); break; + case RequestRejectionReason.InvalidRequestLine: + ex = new BadHttpRequestException("Invalid request line.", StatusCodes.Status400BadRequest); + break; case RequestRejectionReason.MalformedRequestInvalidHeaders: ex = new BadHttpRequestException("Malformed request: invalid headers.", StatusCodes.Status400BadRequest); break; diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs index c87c72c468..e059ce638f 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs @@ -55,7 +55,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http private CancellationTokenSource _abortedCts; private CancellationToken? _manuallySetRequestAbortToken; - private RequestProcessingStatus _requestProcessingStatus; + protected RequestProcessingStatus _requestProcessingStatus; protected bool _keepAlive; protected bool _upgrade; private bool _canHaveBody; @@ -982,15 +982,46 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http Output.ProducingComplete(end); } + public void ParseRequest(ReadableBuffer buffer, out ReadCursor consumed, out ReadCursor examined) + { + consumed = buffer.Start; + examined = buffer.End; + + switch (_requestProcessingStatus) + { + case RequestProcessingStatus.RequestPending: + if (buffer.IsEmpty) + { + break; + } + + ConnectionControl.ResetTimeout(_requestHeadersTimeoutMilliseconds, TimeoutAction.SendTimeoutResponse); + + _requestProcessingStatus = RequestProcessingStatus.ParsingRequestLine; + goto case RequestProcessingStatus.ParsingRequestLine; + case RequestProcessingStatus.ParsingRequestLine: + if (TakeStartLine(buffer, out consumed, out examined)) + { + buffer = buffer.Slice(consumed, buffer.End); + + _requestProcessingStatus = RequestProcessingStatus.ParsingHeaders; + goto case RequestProcessingStatus.ParsingHeaders; + } + else + { + break; + } + case RequestProcessingStatus.ParsingHeaders: + if (TakeMessageHeaders(buffer, out consumed, out examined)) + { + _requestProcessingStatus = RequestProcessingStatus.AppStarted; + } + break; + } + } + public bool TakeStartLine(ReadableBuffer buffer, out ReadCursor consumed, out ReadCursor examined) { - if (_requestProcessingStatus == RequestProcessingStatus.RequestPending) - { - ConnectionControl.ResetTimeout(_requestHeadersTimeoutMilliseconds, TimeoutAction.SendTimeoutResponse); - } - - _requestProcessingStatus = RequestProcessingStatus.RequestStarted; - var overLength = false; if (buffer.Length >= ServerOptions.Limits.MaxRequestLineSize) { @@ -1039,7 +1070,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http return true; } - public bool TakeMessageHeaders(ReadableBuffer buffer, FrameRequestHeaders requestHeaders, out ReadCursor consumed, out ReadCursor examined) + public bool TakeMessageHeaders(ReadableBuffer buffer, out ReadCursor consumed, out ReadCursor examined) { // Make sure the buffer is limited bool overLength = false; @@ -1085,7 +1116,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if (!appCompleted) { // Back out of header creation surface exeception in user code - _requestProcessingStatus = RequestProcessingStatus.RequestStarted; + _requestProcessingStatus = RequestProcessingStatus.AppStarted; throw ex; } else @@ -1141,18 +1172,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http public void RejectRequest(RequestRejectionReason reason) { - RejectRequest(BadHttpRequestException.GetException(reason)); + throw BadHttpRequestException.GetException(reason); } public void RejectRequest(RequestRejectionReason reason, string value) { - RejectRequest(BadHttpRequestException.GetException(reason, value)); - } - - private void RejectRequest(BadHttpRequestException ex) - { - Log.ConnectionBadRequest(ConnectionId, ex); - throw ex; + throw BadHttpRequestException.GetException(reason, value); } public void SetBadRequestState(RequestRejectionReason reason) @@ -1162,6 +1187,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http public void SetBadRequestState(BadHttpRequestException ex) { + Log.ConnectionBadRequest(ConnectionId, ex); + if (!HasResponseStarted) { SetErrorResponseHeaders(ex.StatusCode); @@ -1190,20 +1217,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http Log.ApplicationError(ConnectionId, ex); } - public enum RequestLineStatus - { - Empty, - Incomplete, - Done - } - - private enum RequestProcessingStatus - { - RequestPending, - RequestStarted, - ResponseStarted - } - public void OnStartLine(HttpMethod method, HttpVersion version, Span target, Span path, Span query, Span customMethod) { // URIs are always encoded/escaped to ASCII https://tools.ietf.org/html/rfc3986#page-11 diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameOfT.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameOfT.cs index 23626c47ac..bf9d21e7ab 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameOfT.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameOfT.cs @@ -3,7 +3,6 @@ using System; using System.IO; -using System.IO.Pipelines; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Hosting.Server; @@ -31,16 +30,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http /// public override async Task RequestProcessingAsync() { - var requestLineStatus = default(RequestLineStatus); - try { while (!_requestProcessingStopping) { - // If writer completes with an error Input.ReadAsyncDispatched would throw and - // this would not be reset to empty. But it's required by ECONNRESET check lower in the method. - requestLineStatus = RequestLineStatus.Empty; - ConnectionControl.SetTimeout(_keepAliveMilliseconds, TimeoutAction.CloseConnection); while (!_requestProcessingStopping) @@ -49,76 +42,44 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var examined = result.Buffer.End; var consumed = result.Buffer.End; + InitializeHeaders(); + try { - if (!result.Buffer.IsEmpty) - { - requestLineStatus = TakeStartLine(result.Buffer, out consumed, out examined) - ? RequestLineStatus.Done : RequestLineStatus.Incomplete; - } - else - { - requestLineStatus = RequestLineStatus.Empty; - } + ParseRequest(result.Buffer, out consumed, out examined); } catch (InvalidOperationException) { - throw BadHttpRequestException.GetException(RequestRejectionReason.InvalidRequestLine); + switch (_requestProcessingStatus) + { + case RequestProcessingStatus.ParsingRequestLine: + throw BadHttpRequestException.GetException(RequestRejectionReason.InvalidRequestLine); + case RequestProcessingStatus.ParsingHeaders: + throw BadHttpRequestException.GetException(RequestRejectionReason.MalformedRequestInvalidHeaders); + } + throw; } finally { Input.Reader.Advance(consumed, examined); } - if (requestLineStatus == RequestLineStatus.Done) + if (_requestProcessingStatus == RequestProcessingStatus.AppStarted) { break; } if (result.IsCompleted) { - if (requestLineStatus == RequestLineStatus.Empty) + switch (_requestProcessingStatus) { - return; + case RequestProcessingStatus.RequestPending: + return; + case RequestProcessingStatus.ParsingRequestLine: + throw BadHttpRequestException.GetException(RequestRejectionReason.InvalidRequestLine); + case RequestProcessingStatus.ParsingHeaders: + throw BadHttpRequestException.GetException(RequestRejectionReason.MalformedRequestInvalidHeaders); } - - RejectRequest(RequestRejectionReason.InvalidRequestLine, requestLineStatus.ToString()); - } - } - - InitializeHeaders(); - - while (!_requestProcessingStopping) - { - - var result = await Input.Reader.ReadAsync(); - var examined = result.Buffer.End; - var consumed = result.Buffer.End; - - bool headersDone; - - try - { - headersDone = TakeMessageHeaders(result.Buffer, FrameRequestHeaders, out consumed, - out examined); - } - catch (InvalidOperationException) - { - throw BadHttpRequestException.GetException(RequestRejectionReason.MalformedRequestInvalidHeaders); - } - finally - { - Input.Reader.Advance(consumed, examined); - } - - if (headersDone) - { - break; - } - - if (result.IsCompleted) - { - RejectRequest(RequestRejectionReason.MalformedRequestInvalidHeaders); } } @@ -231,7 +192,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http catch (IOException ex) when (ex.InnerException is UvException) { // Don't log ECONNRESET errors made between requests. Browsers like IE will reset connections regularly. - if (requestLineStatus != RequestLineStatus.Empty || + if (_requestProcessingStatus != RequestProcessingStatus.RequestPending || ((UvException)ex.InnerException).StatusCode != Constants.ECONNRESET) { Log.RequestProcessingError(ConnectionId, ex); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/KestrelHttpParser.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/KestrelHttpParser.cs index 7ce4097985..2e9947c9d8 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/KestrelHttpParser.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/KestrelHttpParser.cs @@ -289,7 +289,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } else if (ch2 == ByteLF) { - consumed = reader.Cursor; + // REVIEW: Removed usage of ReadableBufferReader.Cursor, because it's broken when the buffer is + // sliced and doesn't start at the start of a segment. We should probably fix this. + //consumed = reader.Cursor; + consumed = buffer.Move(consumed, 2); examined = consumed; return true; } @@ -323,7 +326,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http // Skip the reader forward past the header line reader.Skip(span.Length); - consumed = reader.Cursor; + // REVIEW: Removed usage of ReadableBufferReader.Cursor, because it's broken when the buffer is + // sliced and doesn't start at the start of a segment. We should probably fix this. + //consumed = reader.Cursor; + consumed = buffer.Move(consumed, span.Length); consumedBytes += span.Length; var nameBuffer = span.Slice(nameStart, nameEnd - nameStart); @@ -562,17 +568,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http public void RejectRequest(RequestRejectionReason reason) { - RejectRequest(BadHttpRequestException.GetException(reason)); + throw BadHttpRequestException.GetException(reason); } public void RejectRequest(RequestRejectionReason reason, string value) { - RejectRequest(BadHttpRequestException.GetException(reason, value)); - } - - private void RejectRequest(BadHttpRequestException ex) - { - throw ex; + throw BadHttpRequestException.GetException(reason, value); } private void RejectRequestLine(Span span) @@ -608,4 +609,4 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http Complete } } -} \ No newline at end of file +} diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/MessageBody.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/MessageBody.cs index ce0edff4b9..8a817b82bb 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/MessageBody.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/MessageBody.cs @@ -595,7 +595,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http try { - if (_context.TakeMessageHeaders(buffer, _requestHeaders, out consumed, out examined)) + if (_context.TakeMessageHeaders(buffer, out consumed, out examined)) { break; } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/RequestProcessingStatus.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/RequestProcessingStatus.cs new file mode 100644 index 0000000000..e8ebb73784 --- /dev/null +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/RequestProcessingStatus.cs @@ -0,0 +1,14 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http +{ + public enum RequestProcessingStatus + { + RequestPending, + ParsingRequestLine, + ParsingHeaders, + AppStarted, + ResponseStarted + } +} \ No newline at end of file diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsing.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsing.cs index 41c7010c48..7080d93e3a 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsing.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsing.cs @@ -6,12 +6,8 @@ using System.IO.Pipelines; using System.Linq; using System.Text; using BenchmarkDotNet.Attributes; -using Microsoft.AspNetCore.Server.Kestrel.Internal; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.AspNetCore.Testing; -using MemoryPool = Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPool; -using RequestLineStatus = Microsoft.AspNetCore.Server.Kestrel.Internal.Http.Frame.RequestLineStatus; namespace Microsoft.AspNetCore.Server.Kestrel.Performance { @@ -154,7 +150,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance Frame.InitializeHeaders(); - if (!Frame.TakeMessageHeaders(readableBuffer, (FrameRequestHeaders)Frame.RequestHeaders, out consumed, out examined)) + if (!Frame.TakeMessageHeaders(readableBuffer, out consumed, out examined)) { ThrowInvalidMessageHeaders(); } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs index 0f3185e6c8..0d4c59b374 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs @@ -89,7 +89,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests await _socketInput.Writer.WriteAsync(Encoding.ASCII.GetBytes("Header:value\r\n\r\n")); var readableBuffer = (await _socketInput.Reader.ReadAsync()).Buffer; - var success = _frame.TakeMessageHeaders(readableBuffer, (FrameRequestHeaders)_frame.RequestHeaders, out _consumed, out _examined); + var success = _frame.TakeMessageHeaders(readableBuffer, out _consumed, out _examined); _socketInput.Reader.Advance(_consumed, _examined); Assert.True(success); @@ -114,7 +114,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests await _socketInput.Writer.WriteAsync(Encoding.ASCII.GetBytes(rawHeaders)); var readableBuffer = (await _socketInput.Reader.ReadAsync()).Buffer; - var success = _frame.TakeMessageHeaders(readableBuffer, (FrameRequestHeaders)_frame.RequestHeaders, out _consumed, out _examined); + var success = _frame.TakeMessageHeaders(readableBuffer, out _consumed, out _examined); _socketInput.Reader.Advance(_consumed, _examined); Assert.True(success); @@ -138,7 +138,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests await _socketInput.Writer.WriteAsync(Encoding.ASCII.GetBytes(rawHeaders)); var readableBuffer = (await _socketInput.Reader.ReadAsync()).Buffer; - var success = _frame.TakeMessageHeaders(readableBuffer, (FrameRequestHeaders)_frame.RequestHeaders, out _consumed, out _examined); + var success = _frame.TakeMessageHeaders(readableBuffer, out _consumed, out _examined); _socketInput.Reader.Advance(_consumed, _examined); Assert.True(success); @@ -161,7 +161,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests await _socketInput.Writer.WriteAsync(Encoding.ASCII.GetBytes(rawHeaders)); var readableBuffer = (await _socketInput.Reader.ReadAsync()).Buffer; - var success = _frame.TakeMessageHeaders(readableBuffer, (FrameRequestHeaders)_frame.RequestHeaders, out _consumed, out _examined); + var success = _frame.TakeMessageHeaders(readableBuffer, out _consumed, out _examined); _socketInput.Reader.Advance(_consumed, _examined); Assert.True(success); @@ -177,7 +177,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests await _socketInput.Writer.WriteAsync(Encoding.ASCII.GetBytes(rawHeaders)); var readableBuffer = (await _socketInput.Reader.ReadAsync()).Buffer; - var exception = Assert.Throws(() => _frame.TakeMessageHeaders(readableBuffer, (FrameRequestHeaders)_frame.RequestHeaders, out _consumed, out _examined)); + var exception = Assert.Throws(() => _frame.TakeMessageHeaders(readableBuffer, out _consumed, out _examined)); _socketInput.Reader.Advance(_consumed, _examined); Assert.Equal(expectedExceptionMessage, exception.Message); @@ -190,13 +190,13 @@ namespace Microsoft.AspNetCore.Server.KestrelTests await _socketInput.Writer.WriteAsync(Encoding.ASCII.GetBytes("Header-1: value1\r\n")); var readableBuffer = (await _socketInput.Reader.ReadAsync()).Buffer; - Assert.False(_frame.TakeMessageHeaders(readableBuffer, (FrameRequestHeaders)_frame.RequestHeaders, out _consumed, out _examined)); + Assert.False(_frame.TakeMessageHeaders(readableBuffer, out _consumed, out _examined)); _socketInput.Reader.Advance(_consumed, _examined); await _socketInput.Writer.WriteAsync(Encoding.ASCII.GetBytes(" ")); readableBuffer = (await _socketInput.Reader.ReadAsync()).Buffer; - var exception = Assert.Throws(() => _frame.TakeMessageHeaders(readableBuffer, (FrameRequestHeaders)_frame.RequestHeaders, out _consumed, out _examined)); + var exception = Assert.Throws(() => _frame.TakeMessageHeaders(readableBuffer, out _consumed, out _examined)); _socketInput.Reader.Advance(_consumed, _examined); Assert.Equal("Header line must not start with whitespace.", exception.Message); @@ -213,7 +213,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests await _socketInput.Writer.WriteAsync(Encoding.ASCII.GetBytes($"{headerLine}\r\n")); var readableBuffer = (await _socketInput.Reader.ReadAsync()).Buffer; - var exception = Assert.Throws(() => _frame.TakeMessageHeaders(readableBuffer, (FrameRequestHeaders)_frame.RequestHeaders, out _consumed, out _examined)); + var exception = Assert.Throws(() => _frame.TakeMessageHeaders(readableBuffer, out _consumed, out _examined)); _socketInput.Reader.Advance(_consumed, _examined); Assert.Equal("Request headers too long.", exception.Message); @@ -229,7 +229,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests await _socketInput.Writer.WriteAsync(Encoding.ASCII.GetBytes($"{headerLines}\r\n")); var readableBuffer = (await _socketInput.Reader.ReadAsync()).Buffer; - var exception = Assert.Throws(() => _frame.TakeMessageHeaders(readableBuffer, (FrameRequestHeaders)_frame.RequestHeaders, out _consumed, out _examined)); + var exception = Assert.Throws(() => _frame.TakeMessageHeaders(readableBuffer, out _consumed, out _examined)); _socketInput.Reader.Advance(_consumed, _examined); Assert.Equal("Request contains too many headers.", exception.Message); @@ -248,7 +248,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests await _socketInput.Writer.WriteAsync(Encoding.ASCII.GetBytes(rawHeaders)); var readableBuffer = (await _socketInput.Reader.ReadAsync()).Buffer; - var success = _frame.TakeMessageHeaders(readableBuffer, (FrameRequestHeaders)_frame.RequestHeaders, out _consumed, out _examined); + var success = _frame.TakeMessageHeaders(readableBuffer, out _consumed, out _examined); _socketInput.Reader.Advance(_consumed, _examined); Assert.True(success); @@ -282,7 +282,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests await _socketInput.Writer.WriteAsync(Encoding.ASCII.GetBytes($"{headerLine1}\r\n")); var readableBuffer = (await _socketInput.Reader.ReadAsync()).Buffer; - var takeMessageHeaders = _frame.TakeMessageHeaders(readableBuffer, (FrameRequestHeaders)_frame.RequestHeaders, out _consumed, out _examined); + var takeMessageHeaders = _frame.TakeMessageHeaders(readableBuffer, out _consumed, out _examined); _socketInput.Reader.Advance(_consumed, _examined); Assert.True(takeMessageHeaders); @@ -294,7 +294,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests await _socketInput.Writer.WriteAsync(Encoding.ASCII.GetBytes($"{headerLine2}\r\n")); readableBuffer = (await _socketInput.Reader.ReadAsync()).Buffer; - takeMessageHeaders = _frame.TakeMessageHeaders(readableBuffer, (FrameRequestHeaders)_frame.RequestHeaders, out _consumed, out _examined); + takeMessageHeaders = _frame.TakeMessageHeaders(readableBuffer, out _consumed, out _examined); _socketInput.Reader.Advance(_consumed, _examined); Assert.True(takeMessageHeaders); @@ -461,14 +461,14 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } [Fact] - public async Task TakeStartLineStartsRequestHeadersTimeoutOnFirstByteAvailable() + public async Task ParseRequestStartsRequestHeadersTimeoutOnFirstByteAvailable() { var connectionControl = new Mock(); _connectionContext.ConnectionControl = connectionControl.Object; await _socketInput.Writer.WriteAsync(Encoding.ASCII.GetBytes("G")); - _frame.TakeStartLine((await _socketInput.Reader.ReadAsync()).Buffer, out _consumed, out _examined); + _frame.ParseRequest((await _socketInput.Reader.ReadAsync()).Buffer, out _consumed, out _examined); _socketInput.Reader.Advance(_consumed, _examined); var expectedRequestHeadersTimeout = (long)_serviceContext.ServerOptions.Limits.RequestHeadersTimeout.TotalMilliseconds; @@ -533,7 +533,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests await _socketInput.Writer.WriteAsync(Encoding.ASCII.GetBytes(rawHeader)); var readableBuffer = (await _socketInput.Reader.ReadAsync()).Buffer; - _frame.TakeMessageHeaders(readableBuffer, (FrameRequestHeaders)_frame.RequestHeaders, out _consumed, out _examined); + _frame.TakeMessageHeaders(readableBuffer, out _consumed, out _examined); _socketInput.Reader.Advance(_consumed, _examined); Assert.Equal(readableBuffer.End, _examined); } @@ -566,7 +566,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests ReadCursor examined; var readableBuffer = (await _socketInput.Reader.ReadAsync()).Buffer; - Assert.Equal(false, _frame.TakeMessageHeaders(readableBuffer, (FrameRequestHeaders)_frame.RequestHeaders, out consumed, out examined)); + Assert.Equal(false, _frame.TakeMessageHeaders(readableBuffer, out consumed, out examined)); _socketInput.Reader.Advance(consumed, examined); } From 83edc38e722c924aafad146b5b366035b781757b Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Fri, 3 Mar 2017 15:55:07 -0800 Subject: [PATCH 1086/1662] Use TechEmpower request as baseline for request parsing benchmarks. --- .../RequestParsing.cs | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsing.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsing.cs index fb11720970..350a2a0000 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsing.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsing.cs @@ -17,8 +17,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance private const int InnerLoopCount = 512; private const int Pipelining = 16; - private const string plaintextRequest = "GET /plaintext HTTP/1.1\r\nHost: www.example.com\r\n\r\n"; - private const string plaintextTechEmpower = "GET /plaintext HTTP/1.1\r\n" + "Host: localhost\r\n" + "Accept: text/plain,text/html;q=0.9,application/xhtml+xml;q=0.9,application/xml;q=0.8,*/*;q=0.7\r\n" + @@ -50,8 +48,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance "Pragma: no-cache\r\n" + "Cookie: prov=20629ccd-8b0f-e8ef-2935-cd26609fc0bc; __qca=P0-1591065732-1479167353442; _ga=GA1.2.1298898376.1479167354; _gat=1; sgt=id=9519gfde_3347_4762_8762_df51458c8ec2; acct=t=why-is-%e0%a5%a7%e0%a5%a8%e0%a5%a9-numeric&s=why-is-%e0%a5%a7%e0%a5%a8%e0%a5%a9-numeric\r\n\r\n"; - private static readonly byte[] _plaintextPipelinedRequests = Encoding.ASCII.GetBytes(string.Concat(Enumerable.Repeat(plaintextRequest, Pipelining))); - private static readonly byte[] _plaintextRequest = Encoding.ASCII.GetBytes(plaintextRequest); + private static readonly byte[] _plaintextTechEmpowerPipelinedRequests = Encoding.ASCII.GetBytes(string.Concat(Enumerable.Repeat(plaintextTechEmpower, Pipelining))); private static readonly byte[] _plaintextTechEmpower = Encoding.ASCII.GetBytes(plaintextTechEmpower); private static readonly byte[] _liveaspnentPipelinedRequests = Encoding.ASCII.GetBytes(string.Concat(Enumerable.Repeat(liveaspnetRequest, Pipelining))); @@ -64,16 +61,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance public Type ParserType { get; set; } [Benchmark(Baseline = true, OperationsPerInvoke = InnerLoopCount)] - public void ParsePlaintext() - { - for (var i = 0; i < InnerLoopCount; i++) - { - InsertData(_plaintextRequest); - ParseData(); - } - } - - [Benchmark(OperationsPerInvoke = InnerLoopCount)] public void ParsePlaintextTechEmpower() { for (var i = 0; i < InnerLoopCount; i++) { @@ -83,11 +70,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance } [Benchmark(OperationsPerInvoke = InnerLoopCount * Pipelining)] - public void ParsePipelinedPlaintext() + public void ParsePipelinedPlaintextTechEmpower() { for (var i = 0; i < InnerLoopCount; i++) { - InsertData(_plaintextPipelinedRequests); + InsertData(_plaintextTechEmpowerPipelinedRequests); ParseData(); } } From 20f75605ca776cfb66309c319c491ca2170c5292 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Fri, 3 Mar 2017 22:35:41 -0800 Subject: [PATCH 1087/1662] Workaround rogue System.IO.Pipelines on nuget.org --- build/dependencies.props | 3 +++ .../Microsoft.AspNetCore.Server.Kestrel.csproj | 7 +++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/build/dependencies.props b/build/dependencies.props index 9aa824128d..da2ebb0d94 100644 --- a/build/dependencies.props +++ b/build/dependencies.props @@ -3,5 +3,8 @@ 1.6.1 4.3.0 1.9.1 + + 0.1.0-e170301-1 + 0.1.0-e170228-1 diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Microsoft.AspNetCore.Server.Kestrel.csproj b/src/Microsoft.AspNetCore.Server.Kestrel/Microsoft.AspNetCore.Server.Kestrel.csproj index 5dd7b984c9..35ccda46b3 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Microsoft.AspNetCore.Server.Kestrel.csproj +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Microsoft.AspNetCore.Server.Kestrel.csproj @@ -18,10 +18,9 @@ - - - - + + + From da763b487383f8c56c3ee6e4febace161bfc0a0c Mon Sep 17 00:00:00 2001 From: David Fowler Date: Sat, 4 Mar 2017 11:26:32 -0800 Subject: [PATCH 1088/1662] Use ascii decoding routine that disallows null chars (#1445) * Use ascii decoding routine that disallows null chars - GetAsciiString() in newer corefxlab builds allows 0 (which is a valid ascii char). To avoid future regressions, GetAsciiStringNonNullCharacters() was added and used in place of GetAsciiString() when interpreting the request line and headers - Make GetAsciiStringNonNullCharacters return empty instead of null --- .../Internal/Http/Frame.cs | 14 ++++++------ .../Internal/Infrastructure/HttpUtilities.cs | 22 +++++++++++++++++++ 2 files changed, 29 insertions(+), 7 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs index e059ce638f..463ce0a237 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs @@ -1228,7 +1228,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if (needDecode) { // Read raw target before mutating memory. - rawTarget = target.GetAsciiString() ?? string.Empty; + rawTarget = target.GetAsciiStringNonNullCharacters(); // URI was encoded, unescape and then parse as utf8 int pathLength = UrlEncoder.Decode(path, path); @@ -1237,7 +1237,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http else { // URI wasn't encoded, parse as ASCII - requestUrlPath = path.GetAsciiString() ?? string.Empty; + requestUrlPath = path.GetAsciiStringNonNullCharacters(); if (query.Length == 0) { @@ -1247,21 +1247,21 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } else { - rawTarget = target.GetAsciiString() ?? string.Empty; + rawTarget = target.GetAsciiStringNonNullCharacters(); } } var normalizedTarget = PathNormalizer.RemoveDotSegments(requestUrlPath); if (method != HttpMethod.Custom) { - Method = HttpUtilities.MethodToString(method) ?? String.Empty; + Method = HttpUtilities.MethodToString(method) ?? string.Empty; } else { - Method = customMethod.GetAsciiString() ?? string.Empty; + Method = customMethod.GetAsciiStringNonNullCharacters(); } - QueryString = query.GetAsciiString() ?? string.Empty; + QueryString = query.GetAsciiStringNonNullCharacters(); RawTarget = rawTarget; HttpVersion = HttpUtilities.VersionToString(version); @@ -1289,7 +1289,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { RejectRequest(RequestRejectionReason.TooManyHeaders); } - var valueString = value.GetAsciiString() ?? string.Empty; + var valueString = value.GetAsciiStringNonNullCharacters(); FrameRequestHeaders.Append(name, valueString); } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/HttpUtilities.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/HttpUtilities.cs index 719e27eff4..e38ad9fd6e 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/HttpUtilities.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/HttpUtilities.cs @@ -94,6 +94,28 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure } } + public unsafe static string GetAsciiStringNonNullCharacters(this Span span) + { + if (span.IsEmpty) + { + return string.Empty; + } + + var asciiString = new string('\0', span.Length); + + fixed (char* output = asciiString) + fixed (byte* buffer = &span.DangerousGetPinnableReference()) + { + // This version if AsciiUtilities returns null if there are any null (0 byte) characters + // in the string + if (!AsciiUtilities.TryGetAsciiString(buffer, output, span.Length)) + { + throw new InvalidOperationException(); + } + } + return asciiString; + } + public static string GetAsciiStringEscaped(this Span span, int maxChars) { var sb = new StringBuilder(); From acf97b610277019e33ece6ce99dfd652d0540bd3 Mon Sep 17 00:00:00 2001 From: Pranav K Date: Sun, 5 Mar 2017 08:54:51 -0800 Subject: [PATCH 1089/1662] Unpin CoreFxLab package versions --- build/dependencies.props | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/build/dependencies.props b/build/dependencies.props index da2ebb0d94..3c441802d9 100644 --- a/build/dependencies.props +++ b/build/dependencies.props @@ -3,8 +3,7 @@ 1.6.1 4.3.0 1.9.1 - - 0.1.0-e170301-1 - 0.1.0-e170228-1 + 0.1.0-* + 0.1.0-* From 0ce111d9f13bc873b609dd0f0e2494a4b4730936 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Mon, 6 Mar 2017 03:31:45 -0800 Subject: [PATCH 1090/1662] Fix write size in benchmark (#1449) --- .../RequestParsing.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsing.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsing.cs index 350a2a0000..444e4022b6 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsing.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsing.cs @@ -121,8 +121,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance private void InsertData(byte[] bytes) { + var buffer = Pipe.Writer.Alloc(2048); + buffer.Write(bytes); // There should not be any backpressure and task completes immediately - Pipe.Writer.WriteAsync(bytes).GetAwaiter().GetResult(); + buffer.FlushAsync().GetAwaiter().GetResult(); } private void ParseData() From 537b06f025561578ed78de248e0654a745f69df5 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Mon, 6 Mar 2017 09:06:28 -0800 Subject: [PATCH 1091/1662] Interleave multispan and single span code path (#1442) - Attempt at making the reader better for multispan parsing - Try tighter inner loop - Fix boundary case and clean code up - Update the cursor once instead of after every header - Fix errors with not updating consumed state on incomplete header payload - Filled a test hole, removed a condition that should never happen - Avoid struct copies every iteration when parsing headers --- .../Internal/Http/KestrelHttpParser.cs | 277 +++++++++--------- .../FrameTests.cs | 16 + 2 files changed, 148 insertions(+), 145 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/KestrelHttpParser.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/KestrelHttpParser.cs index 2e9947c9d8..998aa6f46a 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/KestrelHttpParser.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/KestrelHttpParser.cs @@ -253,163 +253,150 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http examined = buffer.End; consumedBytes = 0; - if (buffer.IsSingleSpan) - { - var result = TakeMessageHeadersSingleSpan(handler, buffer.First.Span, out consumedBytes); - consumed = buffer.Move(consumed, consumedBytes); - - if (result) - { - examined = consumed; - } - - return result; - } - var bufferEnd = buffer.End; var reader = new ReadableBufferReader(buffer); - while (true) + var start = default(ReadableBufferReader); + var done = false; + + try { - var start = reader; - int ch1 = reader.Take(); - var ch2 = reader.Take(); - - if (ch1 == -1) + while (!reader.End) { - return false; - } + var span = reader.Span; + var remaining = span.Length; - if (ch1 == ByteCR) - { - // Check for final CRLF. - if (ch2 == -1) + fixed (byte* pBuffer = &span.DangerousGetPinnableReference()) { - return false; + while (remaining > 0) + { + var index = reader.Index; + int ch1; + int ch2; + + // Fast path, we're still looking at the same span + if (remaining >= 2) + { + ch1 = pBuffer[index]; + ch2 = pBuffer[index + 1]; + } + else + { + // Store the reader before we look ahead 2 bytes (probably straddling + // spans) + start = reader; + + // Possibly split across spans + ch1 = reader.Take(); + ch2 = reader.Take(); + } + + if (ch1 == ByteCR) + { + // Check for final CRLF. + if (ch2 == -1) + { + // Reset the reader so we don't consume anything + reader = start; + return false; + } + else if (ch2 == ByteLF) + { + // If we got 2 bytes from the span directly so skip ahead 2 so that + // the reader's state matches what we expect + if (index == reader.Index) + { + reader.Skip(2); + } + + done = true; + return true; + } + + // Headers don't end in CRLF line. + RejectRequest(RequestRejectionReason.HeadersCorruptedInvalidHeaderSequence); + } + else if (ch1 == ByteSpace || ch1 == ByteTab) + { + RejectRequest(RequestRejectionReason.HeaderLineMustNotStartWithWhitespace); + } + + // We moved the reader so look ahead 2 bytes so reset both the reader + // and the index + if (index != reader.Index) + { + reader = start; + index = reader.Index; + } + + Span headerSpan; + + var endIndex = IndexOf(pBuffer, index, remaining, ByteLF); + + if (endIndex != -1) + { + headerSpan = new Span(pBuffer + index, (endIndex - index + 1)); + } + else + { + var current = reader.Cursor; + + // Split buffers + if (ReadCursorOperations.Seek(current, bufferEnd, out var lineEnd, ByteLF) == -1) + { + // Not there + return false; + } + + // Make sure LF is included in lineEnd + lineEnd = buffer.Move(lineEnd, 1); + headerSpan = buffer.Slice(current, lineEnd).ToSpan(); + + // We're going to the next span after this since we know we crossed spans here + // so mark the remaining as equal to the headerSpan so that we end up at 0 + // on the next iteration + remaining = headerSpan.Length; + } + + if (!TakeSingleHeader(headerSpan, out var nameStart, out var nameEnd, out var valueStart, out var valueEnd)) + { + return false; + } + + // Skip the reader forward past the header line + reader.Skip(headerSpan.Length); + + remaining -= headerSpan.Length; + + var nameBuffer = headerSpan.Slice(nameStart, nameEnd - nameStart); + var valueBuffer = headerSpan.Slice(valueStart, valueEnd - valueStart); + + handler.OnHeader(nameBuffer, valueBuffer); + } } - else if (ch2 == ByteLF) - { - // REVIEW: Removed usage of ReadableBufferReader.Cursor, because it's broken when the buffer is - // sliced and doesn't start at the start of a segment. We should probably fix this. - //consumed = reader.Cursor; - consumed = buffer.Move(consumed, 2); - examined = consumed; - return true; - } - - // Headers don't end in CRLF line. - RejectRequest(RequestRejectionReason.HeadersCorruptedInvalidHeaderSequence); } - else if (ch1 == ByteSpace || ch1 == ByteTab) + + return false; + } + finally + { + consumed = reader.Cursor; + consumedBytes = reader.ConsumedBytes; + + if (done) { - RejectRequest(RequestRejectionReason.HeaderLineMustNotStartWithWhitespace); + examined = consumed; } - - // Reset the reader since we're not at the end of headers - reader = start; - - if (ReadCursorOperations.Seek(consumed, bufferEnd, out var lineEnd, ByteLF) == -1) - { - return false; - } - - // Make sure LF is included in lineEnd - lineEnd = buffer.Move(lineEnd, 1); - - var headerBuffer = buffer.Slice(consumed, lineEnd); - var span = headerBuffer.ToSpan(); - - if (!TakeSingleHeader(span, out var nameStart, out var nameEnd, out var valueStart, out var valueEnd)) - { - return false; - } - - // Skip the reader forward past the header line - reader.Skip(span.Length); - // REVIEW: Removed usage of ReadableBufferReader.Cursor, because it's broken when the buffer is - // sliced and doesn't start at the start of a segment. We should probably fix this. - //consumed = reader.Cursor; - consumed = buffer.Move(consumed, span.Length); - consumedBytes += span.Length; - - var nameBuffer = span.Slice(nameStart, nameEnd - nameStart); - var valueBuffer = span.Slice(valueStart, valueEnd - valueStart); - - handler.OnHeader(nameBuffer, valueBuffer); } } - private unsafe bool TakeMessageHeadersSingleSpan(T handler, Span headersSpan, out int consumedBytes) where T : IHttpHeadersHandler + private unsafe int IndexOf(byte* pBuffer, int index, int length, byte value) { - consumedBytes = 0; - var length = headersSpan.Length; - - fixed (byte* data = &headersSpan.DangerousGetPinnableReference()) + for (int i = 0; i < length; i++, index++) { - while (consumedBytes < length) + if (pBuffer[index] == value) { - var ch1 = data[consumedBytes]; - var ch2 = -1; - - if (consumedBytes + 1 < length) - { - ch2 = data[consumedBytes + 1]; - } - - if (ch1 == ByteCR) - { - // Check for final CRLF. - if (ch2 == -1) - { - return false; - } - else if (ch2 == ByteLF) - { - consumedBytes += 2; - return true; - } - - // Headers don't end in CRLF line. - RejectRequest(RequestRejectionReason.HeadersCorruptedInvalidHeaderSequence); - } - else if (ch1 == ByteSpace || ch1 == ByteTab) - { - RejectRequest(RequestRejectionReason.HeaderLineMustNotStartWithWhitespace); - } - - var lineEnd = IndexOf(data, consumedBytes, headersSpan.Length, ByteLF); - - if (lineEnd == -1) - { - return false; - } - - var span = new Span(data + consumedBytes, (lineEnd - consumedBytes + 1)); - - if (!TakeSingleHeader(span, out var nameStart, out var nameEnd, out var valueStart, out var valueEnd)) - { - return false; - } - - consumedBytes += span.Length; - - var nameBuffer = span.Slice(nameStart, nameEnd - nameStart); - var valueBuffer = span.Slice(valueStart, valueEnd - valueStart); - - handler.OnHeader(nameBuffer, valueBuffer); - } - } - - return false; - } - - private unsafe int IndexOf(byte* data, int index, int length, byte value) - { - for (int i = index; i < length; i++) - { - if (data[i] == value) - { - return i; + return index; } } return -1; @@ -427,14 +414,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http int i = 0; var done = false; - fixed (byte* data = &span.DangerousGetPinnableReference()) + fixed (byte* pHeader = &span.DangerousGetPinnableReference()) { switch (HeaderState.Name) { case HeaderState.Name: for (; i < headerLineLength; i++) { - var ch = data[i]; + var ch = pHeader[i]; if (ch == ByteColon) { if (nameHasWhitespace) @@ -460,7 +447,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http case HeaderState.Whitespace: for (; i < headerLineLength; i++) { - var ch = data[i]; + var ch = pHeader[i]; var whitespace = ch == ByteTab || ch == ByteSpace || ch == ByteCR; if (!whitespace) @@ -484,7 +471,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http case HeaderState.ExpectValue: for (; i < headerLineLength; i++) { - var ch = data[i]; + var ch = pHeader[i]; var whitespace = ch == ByteTab || ch == ByteSpace; if (whitespace) @@ -527,7 +514,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http RejectRequest(RequestRejectionReason.MissingCRInHeaderLine); break; case HeaderState.ExpectNewLine: - if (data[i] != ByteLF) + if (pHeader[i] != ByteLF) { RejectRequest(RequestRejectionReason.HeaderValueMustNotContainCR); } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs index 0d4c59b374..f48a614579 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs @@ -203,6 +203,22 @@ namespace Microsoft.AspNetCore.Server.KestrelTests Assert.Equal(StatusCodes.Status400BadRequest, exception.StatusCode); } + [Fact] + public async Task TakeMessageHeadersConsumesBytesCorrectlyAtEnd() + { + await _socketInput.Writer.WriteAsync(Encoding.ASCII.GetBytes("Header-1: value1\r\n\r")); + + var readableBuffer = (await _socketInput.Reader.ReadAsync()).Buffer; + Assert.False(_frame.TakeMessageHeaders(readableBuffer, out _consumed, out _examined)); + _socketInput.Reader.Advance(_consumed, _examined); + + await _socketInput.Writer.WriteAsync(Encoding.ASCII.GetBytes("\n")); + + readableBuffer = (await _socketInput.Reader.ReadAsync()).Buffer; + Assert.True(_frame.TakeMessageHeaders(readableBuffer, out _consumed, out _examined)); + _socketInput.Reader.Advance(_consumed, _examined); + } + [Fact] public async Task TakeMessageHeadersThrowsWhenHeadersExceedTotalSizeLimit() { From 0404bcc58c6de8740b16e393de325bf982eefaa4 Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Wed, 1 Mar 2017 17:29:13 -0800 Subject: [PATCH 1092/1662] Add more microbenchmarks. --- .../FrameParsingOverhead.cs | 135 +++++++++++++++++ .../KestrelHttpParser.cs | 77 ++++++++++ .../Program.cs | 12 +- .../RequestParsing.cs | 142 ++++++------------ .../RequestParsingData.cs | 62 ++++++++ 5 files changed, 334 insertions(+), 94 deletions(-) create mode 100644 test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameParsingOverhead.cs create mode 100644 test/Microsoft.AspNetCore.Server.Kestrel.Performance/KestrelHttpParser.cs create mode 100644 test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsingData.cs diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameParsingOverhead.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameParsingOverhead.cs new file mode 100644 index 0000000000..acb39238bc --- /dev/null +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameParsingOverhead.cs @@ -0,0 +1,135 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.IO.Pipelines; +using System.Text; +using BenchmarkDotNet.Attributes; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; +using Microsoft.AspNetCore.Testing; + +namespace Microsoft.AspNetCore.Server.Kestrel.Performance +{ + [Config(typeof(CoreConfig))] + public class FrameParsingOverhead + { + private const int InnerLoopCount = 512; + + public ReadableBuffer _buffer; + public Frame _frame; + + [Setup] + public void Setup() + { + var connectionContext = new MockConnection(new KestrelServerOptions()); + connectionContext.ListenerContext.ServiceContext.HttpParserFactory = frame => NullParser.Instance; + + _frame = new Frame(application: null, context: connectionContext); + } + + [Benchmark(Baseline = true, OperationsPerInvoke = InnerLoopCount)] + public void FrameOverheadTotal() + { + for (var i = 0; i < InnerLoopCount; i++) + { + ParseRequest(); + } + } + + [Benchmark(OperationsPerInvoke = InnerLoopCount)] + public void FrameOverheadRequestLine() + { + for (var i = 0; i < InnerLoopCount; i++) + { + ParseRequestLine(); + } + } + + [Benchmark(OperationsPerInvoke = InnerLoopCount)] + public void FrameOverheadRequestHeaders() + { + for (var i = 0; i < InnerLoopCount; i++) + { + ParseRequestHeaders(); + } + } + + private void ParseRequest() + { + _frame.Reset(); + + if (!_frame.TakeStartLine(_buffer, out var consumed, out var examined)) + { + RequestParsing.ThrowInvalidRequestLine(); + } + + _frame.InitializeHeaders(); + + if (!_frame.TakeMessageHeaders(_buffer, out consumed, out examined)) + { + RequestParsing.ThrowInvalidRequestHeaders(); + } + } + + private void ParseRequestLine() + { + _frame.Reset(); + + if (!_frame.TakeStartLine(_buffer, out var consumed, out var examined)) + { + RequestParsing.ThrowInvalidRequestLine(); + } + } + + private void ParseRequestHeaders() + { + _frame.Reset(); + _frame.InitializeHeaders(); + + if (!_frame.TakeMessageHeaders(_buffer, out var consumed, out var examined)) + { + RequestParsing.ThrowInvalidRequestHeaders(); + } + } + + private class NullParser : IHttpParser + { + private readonly byte[] _target = Encoding.ASCII.GetBytes("/plaintext"); + private readonly byte[] _hostHeaderName = Encoding.ASCII.GetBytes("Host"); + private readonly byte[] _hostHeaderValue = Encoding.ASCII.GetBytes("www.example.com"); + private readonly byte[] _acceptHeaderName = Encoding.ASCII.GetBytes("Accept"); + private readonly byte[] _acceptHeaderValue = Encoding.ASCII.GetBytes("text/plain,text/html;q=0.9,application/xhtml+xml;q=0.9,application/xml;q=0.8,*/*;q=0.7\r\n\r\n"); + private readonly byte[] _connectionHeaderName = Encoding.ASCII.GetBytes("Connection"); + private readonly byte[] _connectionHeaderValue = Encoding.ASCII.GetBytes("keep-alive"); + + public static readonly NullParser Instance = new NullParser(); + + public bool ParseHeaders(T handler, ReadableBuffer buffer, out ReadCursor consumed, out ReadCursor examined, out int consumedBytes) where T : IHttpHeadersHandler + { + handler.OnHeader(new Span(_hostHeaderName), new Span(_hostHeaderValue)); + handler.OnHeader(new Span(_acceptHeaderName), new Span(_acceptHeaderValue)); + handler.OnHeader(new Span(_connectionHeaderName), new Span(_connectionHeaderValue)); + + consumedBytes = 0; + consumed = buffer.Start; + examined = buffer.End; + + return true; + } + + public bool ParseRequestLine(T handler, ReadableBuffer buffer, out ReadCursor consumed, out ReadCursor examined) where T : IHttpRequestLineHandler + { + handler.OnStartLine(HttpMethod.Get, HttpVersion.Http11, new Span(_target), new Span(_target), Span.Empty, Span.Empty); + + consumed = buffer.Start; + examined = buffer.End; + + return true; + } + + public void Reset() + { + } + } + } +} diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/KestrelHttpParser.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/KestrelHttpParser.cs new file mode 100644 index 0000000000..f77346ee8b --- /dev/null +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/KestrelHttpParser.cs @@ -0,0 +1,77 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.IO.Pipelines; +using BenchmarkDotNet.Attributes; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; + +namespace Microsoft.AspNetCore.Server.Kestrel.Performance +{ + [Config(typeof(CoreConfig))] + + public class KestrelHttpParser : IHttpRequestLineHandler, IHttpHeadersHandler + { + private readonly Internal.Http.KestrelHttpParser _parser = new Internal.Http.KestrelHttpParser(log: null); + + private ReadableBuffer _buffer; + + [Benchmark(Baseline = true, OperationsPerInvoke = RequestParsingData.InnerLoopCount)] + public void PlaintextTechEmpower() + { + for (var i = 0; i < RequestParsingData.InnerLoopCount; i++) + { + InsertData(RequestParsingData.PlaintextTechEmpowerRequest); + ParseData(); + } + } + + [Benchmark(OperationsPerInvoke = RequestParsingData.InnerLoopCount)] + public void LiveAspNet() + { + for (var i = 0; i < RequestParsingData.InnerLoopCount; i++) + { + InsertData(RequestParsingData.LiveaspnetRequest); + ParseData(); + } + } + + [Benchmark(OperationsPerInvoke = RequestParsingData.InnerLoopCount)] + public void Unicode() + { + for (var i = 0; i < RequestParsingData.InnerLoopCount; i++) + { + InsertData(RequestParsingData.UnicodeRequest); + ParseData(); + } + } + + private void InsertData(byte[] data) + { + _buffer = ReadableBuffer.Create(data); + } + + private void ParseData() + { + if (!_parser.ParseRequestLine(this, _buffer, out var consumed, out var examined)) + { + RequestParsing.ThrowInvalidRequestHeaders(); + } + + _buffer = _buffer.Slice(consumed, _buffer.End); + + if (!_parser.ParseHeaders(this, _buffer, out consumed, out examined, out var consumedBytes)) + { + RequestParsing.ThrowInvalidRequestHeaders(); + } + } + + public void OnStartLine(HttpMethod method, HttpVersion version, Span target, Span path, Span query, Span customMethod) + { + } + + public void OnHeader(Span name, Span value) + { + } + } +} diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Program.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Program.cs index e6bea9e92c..95ca5909db 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Program.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Program.cs @@ -40,10 +40,18 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance { BenchmarkRunner.Run(); } - if (type.HasFlag(BenchmarkType.KnownStrings)) + if (type.HasFlag(BenchmarkType.KnownStrings)) { BenchmarkRunner.Run(); } + if (type.HasFlag(BenchmarkType.KestrelHttpParser)) + { + BenchmarkRunner.Run(); + } + if (type.HasFlag(BenchmarkType.FrameParsingOverhead)) + { + BenchmarkRunner.Run(); + } } } @@ -54,6 +62,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance Writing = 2, Throughput = 4, KnownStrings = 8, + KestrelHttpParser = 16, + FrameParsingOverhead = 32, // add new ones in powers of two - e.g. 2,4,8,16... All = uint.MaxValue diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsing.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsing.cs index 444e4022b6..90bd7a16c5 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsing.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsing.cs @@ -3,8 +3,6 @@ using System; using System.IO.Pipelines; -using System.Linq; -using System.Text; using BenchmarkDotNet.Attributes; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; using Microsoft.AspNetCore.Testing; @@ -14,107 +12,82 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance [Config(typeof(CoreConfig))] public class RequestParsing { - private const int InnerLoopCount = 512; - private const int Pipelining = 16; - - private const string plaintextTechEmpower = "GET /plaintext HTTP/1.1\r\n" + - "Host: localhost\r\n" + - "Accept: text/plain,text/html;q=0.9,application/xhtml+xml;q=0.9,application/xml;q=0.8,*/*;q=0.7\r\n" + - "Connection: keep-alive\r\n\r\n"; - - private const string liveaspnetRequest = "GET https://live.asp.net/ HTTP/1.1\r\n" + - "Host: live.asp.net\r\n" + - "Connection: keep-alive\r\n" + - "Upgrade-Insecure-Requests: 1\r\n" + - "User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.99 Safari/537.36\r\n" + - "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8\r\n" + - "DNT: 1\r\n" + - "Accept-Encoding: gzip, deflate, sdch, br\r\n" + - "Accept-Language: en-US,en;q=0.8\r\n" + - "Cookie: __unam=7a67379-1s65dc575c4-6d778abe-1; omniID=9519gfde_3347_4762_8762_df51458c8ec2\r\n\r\n"; - - private const string unicodeRequest = - "GET http://stackoverflow.com/questions/40148683/why-is-%e0%a5%a7%e0%a5%a8%e0%a5%a9-numeric HTTP/1.1\r\n" + - "Accept: text/html, application/xhtml+xml, image/jxr, */*\r\n" + - "Accept-Language: en-US,en-GB;q=0.7,en;q=0.3\r\n" + - "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36 Edge/15.14965\r\n" + - "Accept-Encoding: gzip, deflate\r\n" + - "Host: stackoverflow.com\r\n" + - "Connection: Keep-Alive\r\n" + - "Cache-Control: max-age=0\r\n" + - "Upgrade-Insecure-Requests: 1\r\n" + - "DNT: 1\r\n" + - "Referer: http://stackoverflow.com/?tab=month\r\n" + - "Pragma: no-cache\r\n" + - "Cookie: prov=20629ccd-8b0f-e8ef-2935-cd26609fc0bc; __qca=P0-1591065732-1479167353442; _ga=GA1.2.1298898376.1479167354; _gat=1; sgt=id=9519gfde_3347_4762_8762_df51458c8ec2; acct=t=why-is-%e0%a5%a7%e0%a5%a8%e0%a5%a9-numeric&s=why-is-%e0%a5%a7%e0%a5%a8%e0%a5%a9-numeric\r\n\r\n"; - - private static readonly byte[] _plaintextTechEmpowerPipelinedRequests = Encoding.ASCII.GetBytes(string.Concat(Enumerable.Repeat(plaintextTechEmpower, Pipelining))); - private static readonly byte[] _plaintextTechEmpower = Encoding.ASCII.GetBytes(plaintextTechEmpower); - - private static readonly byte[] _liveaspnentPipelinedRequests = Encoding.ASCII.GetBytes(string.Concat(Enumerable.Repeat(liveaspnetRequest, Pipelining))); - private static readonly byte[] _liveaspnentRequest = Encoding.ASCII.GetBytes(liveaspnetRequest); - - private static readonly byte[] _unicodePipelinedRequests = Encoding.ASCII.GetBytes(string.Concat(Enumerable.Repeat(unicodeRequest, Pipelining))); - private static readonly byte[] _unicodeRequest = Encoding.ASCII.GetBytes(unicodeRequest); - - [Params(typeof(KestrelHttpParser))] + [Params(typeof(Internal.Http.KestrelHttpParser))] public Type ParserType { get; set; } - [Benchmark(Baseline = true, OperationsPerInvoke = InnerLoopCount)] - public void ParsePlaintextTechEmpower() + public IPipe Pipe { get; set; } + + public Frame Frame { get; set; } + + public PipeFactory PipelineFactory { get; set; } + + [Setup] + public void Setup() { - for (var i = 0; i < InnerLoopCount; i++) { - InsertData(_plaintextTechEmpower); + var connectionContext = new MockConnection(new KestrelServerOptions()); + connectionContext.ListenerContext.ServiceContext.HttpParserFactory = frame => (IHttpParser)Activator.CreateInstance(ParserType, frame.ConnectionContext.ListenerContext.ServiceContext.Log); + + Frame = new Frame(application: null, context: connectionContext); + PipelineFactory = new PipeFactory(); + Pipe = PipelineFactory.Create(); + } + + [Benchmark(Baseline = true, OperationsPerInvoke = RequestParsingData.InnerLoopCount)] + public void PlaintextTechEmpower() + { + for (var i = 0; i < RequestParsingData.InnerLoopCount; i++) + { + InsertData(RequestParsingData.PlaintextTechEmpowerRequest); ParseData(); } } - [Benchmark(OperationsPerInvoke = InnerLoopCount * Pipelining)] - public void ParsePipelinedPlaintextTechEmpower() + [Benchmark(OperationsPerInvoke = RequestParsingData.InnerLoopCount * RequestParsingData.Pipelining)] + public void PipelinedPlaintextTechEmpower() { - for (var i = 0; i < InnerLoopCount; i++) + for (var i = 0; i < RequestParsingData.InnerLoopCount; i++) { - InsertData(_plaintextTechEmpowerPipelinedRequests); + InsertData(RequestParsingData.PlaintextTechEmpowerPipelinedRequests); ParseData(); } } - [Benchmark(OperationsPerInvoke = InnerLoopCount)] - public void ParseLiveAspNet() + [Benchmark(OperationsPerInvoke = RequestParsingData.InnerLoopCount)] + public void LiveAspNet() { - for (var i = 0; i < InnerLoopCount; i++) + for (var i = 0; i < RequestParsingData.InnerLoopCount; i++) { - InsertData(_liveaspnentRequest); + InsertData(RequestParsingData.LiveaspnetRequest); ParseData(); } } - [Benchmark(OperationsPerInvoke = InnerLoopCount * Pipelining)] - public void ParsePipelinedLiveAspNet() + [Benchmark(OperationsPerInvoke = RequestParsingData.InnerLoopCount * RequestParsingData.Pipelining)] + public void PipelinedLiveAspNet() { - for (var i = 0; i < InnerLoopCount; i++) + for (var i = 0; i < RequestParsingData.InnerLoopCount; i++) { - InsertData(_liveaspnentPipelinedRequests); + InsertData(RequestParsingData.LiveaspnetPipelinedRequests); ParseData(); } } - [Benchmark(OperationsPerInvoke = InnerLoopCount)] - public void ParseUnicode() + [Benchmark(OperationsPerInvoke = RequestParsingData.InnerLoopCount)] + public void Unicode() { - for (var i = 0; i < InnerLoopCount; i++) + for (var i = 0; i < RequestParsingData.InnerLoopCount; i++) { - InsertData(_unicodeRequest); + InsertData(RequestParsingData.UnicodeRequest); ParseData(); } } - [Benchmark(OperationsPerInvoke = InnerLoopCount * Pipelining)] - public void ParseUnicodePipelined() + [Benchmark(OperationsPerInvoke = RequestParsingData.InnerLoopCount * RequestParsingData.Pipelining)] + public void UnicodePipelined() { - for (var i = 0; i < InnerLoopCount; i++) + for (var i = 0; i < RequestParsingData.InnerLoopCount; i++) { - InsertData(_unicodePipelinedRequests); + InsertData(RequestParsingData.UnicodePipelinedRequests); ParseData(); } } @@ -145,7 +118,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance if (!Frame.TakeStartLine(readableBuffer, out var consumed, out var examined)) { - ThrowInvalidStartLine(); + ThrowInvalidRequestLine(); } Pipe.Reader.Advance(consumed, examined); @@ -156,38 +129,21 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance if (!Frame.TakeMessageHeaders(readableBuffer, out consumed, out examined)) { - ThrowInvalidMessageHeaders(); + ThrowInvalidRequestHeaders(); } Pipe.Reader.Advance(consumed, examined); } while (true); } - private void ThrowInvalidStartLine() + public static void ThrowInvalidRequestLine() { - throw new InvalidOperationException("Invalid StartLine"); + throw new InvalidOperationException("Invalid request line"); } - private void ThrowInvalidMessageHeaders() + public static void ThrowInvalidRequestHeaders() { - throw new InvalidOperationException("Invalid MessageHeaders"); + throw new InvalidOperationException("Invalid request headers"); } - - [Setup] - public void Setup() - { - var connectionContext = new MockConnection(new KestrelServerOptions()); - connectionContext.ListenerContext.ServiceContext.HttpParserFactory = frame => (IHttpParser)Activator.CreateInstance(ParserType, frame.ConnectionContext.ListenerContext.ServiceContext.Log); - - Frame = new Frame(application: null, context: connectionContext); - PipelineFactory = new PipeFactory(); - Pipe = PipelineFactory.Create(); - } - - public IPipe Pipe { get; set; } - - public Frame Frame { get; set; } - - public PipeFactory PipelineFactory { get; set; } } } diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsingData.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsingData.cs new file mode 100644 index 0000000000..bddc1a7a97 --- /dev/null +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsingData.cs @@ -0,0 +1,62 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System.Linq; +using System.Text; +using BenchmarkDotNet.Attributes; + +namespace Microsoft.AspNetCore.Server.Kestrel.Performance +{ + [Config(typeof(CoreConfig))] + public class RequestParsingData + { + public const int InnerLoopCount = 512; + + public const int Pipelining = 16; + + private const string _plaintextTechEmpowerRequest = + "GET /plaintext HTTP/1.1\r\n" + + "Host: localhost\r\n" + + "Accept: text/plain,text/html;q=0.9,application/xhtml+xml;q=0.9,application/xml;q=0.8,*/*;q=0.7\r\n" + + "Connection: keep-alive\r\n" + + "\r\n"; + + private const string _liveaspnetRequest = + "GET https://live.asp.net/ HTTP/1.1\r\n" + + "Host: live.asp.net\r\n" + + "Connection: keep-alive\r\n" + + "Upgrade-Insecure-Requests: 1\r\n" + + "User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.99 Safari/537.36\r\n" + + "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8\r\n" + + "DNT: 1\r\n" + + "Accept-Encoding: gzip, deflate, sdch, br\r\n" + + "Accept-Language: en-US,en;q=0.8\r\n" + + "Cookie: __unam=7a67379-1s65dc575c4-6d778abe-1; omniID=9519gfde_3347_4762_8762_df51458c8ec2\r\n" + + "\r\n"; + + private const string _unicodeRequest = + "GET http://stackoverflow.com/questions/40148683/why-is-%e0%a5%a7%e0%a5%a8%e0%a5%a9-numeric HTTP/1.1\r\n" + + "Accept: text/html, application/xhtml+xml, image/jxr, */*\r\n" + + "Accept-Language: en-US,en-GB;q=0.7,en;q=0.3\r\n" + + "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36 Edge/15.14965\r\n" + + "Accept-Encoding: gzip, deflate\r\n" + + "Host: stackoverflow.com\r\n" + + "Connection: Keep-Alive\r\n" + + "Cache-Control: max-age=0\r\n" + + "Upgrade-Insecure-Requests: 1\r\n" + + "DNT: 1\r\n" + + "Referer: http://stackoverflow.com/?tab=month\r\n" + + "Pragma: no-cache\r\n" + + "Cookie: prov=20629ccd-8b0f-e8ef-2935-cd26609fc0bc; __qca=P0-1591065732-1479167353442; _ga=GA1.2.1298898376.1479167354; _gat=1; sgt=id=9519gfde_3347_4762_8762_df51458c8ec2; acct=t=why-is-%e0%a5%a7%e0%a5%a8%e0%a5%a9-numeric&s=why-is-%e0%a5%a7%e0%a5%a8%e0%a5%a9-numeric\r\n" + + "\r\n"; + + public static readonly byte[] PlaintextTechEmpowerPipelinedRequests = Encoding.ASCII.GetBytes(string.Concat(Enumerable.Repeat(_plaintextTechEmpowerRequest, Pipelining))); + public static readonly byte[] PlaintextTechEmpowerRequest = Encoding.ASCII.GetBytes(_plaintextTechEmpowerRequest); + + public static readonly byte[] LiveaspnetPipelinedRequests = Encoding.ASCII.GetBytes(string.Concat(Enumerable.Repeat(_liveaspnetRequest, Pipelining))); + public static readonly byte[] LiveaspnetRequest = Encoding.ASCII.GetBytes(_liveaspnetRequest); + + public static readonly byte[] UnicodePipelinedRequests = Encoding.ASCII.GetBytes(string.Concat(Enumerable.Repeat(_unicodeRequest, Pipelining))); + public static readonly byte[] UnicodeRequest = Encoding.ASCII.GetBytes(_unicodeRequest); + } +} From 7d94abd606a787ff9ecb421bdf7c3e486f9e291f Mon Sep 17 00:00:00 2001 From: John Luo Date: Thu, 2 Mar 2017 23:34:52 -0800 Subject: [PATCH 1093/1662] Enable default server address test --- .../AddressRegistrationTests.cs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs index 9e011adda4..fd7b950e24 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs @@ -14,6 +14,7 @@ using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting.Server.Features; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http.Extensions; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.AspNetCore.Testing; using Microsoft.AspNetCore.Testing.xunit; using Microsoft.Extensions.DependencyInjection; @@ -129,7 +130,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } } - [ConditionalFact(Skip = "Waiting on https://github.com/aspnet/Hosting/issues/917")] + [ConditionalFact] [PortSupportedCondition(5000)] public async Task DefaultsToPort5000() { @@ -147,13 +148,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { host.Start(); - var debugLog = testLogger.Messages.Single(log => log.LogLevel == LogLevel.Debug); - Assert.True(debugLog.Message.Contains("default")); + Assert.Equal(5000, host.GetPort()); + Assert.Single(testLogger.Messages, log => log.LogLevel == LogLevel.Debug && + string.Equals($"No listening endpoints were configured. Binding to {Constants.DefaultIPEndPoint} by default.", + log.Message, StringComparison.Ordinal)); - foreach (var testUrl in new[] { "http://127.0.0.1:5000", "http://localhost:5000" }) + foreach (var testUrl in new[] { "http://127.0.0.1:5000", /* "http://[::1]:5000" */}) { - var response = await HttpClientSlim.GetStringAsync(testUrl); - Assert.Equal(new Uri(testUrl).ToString(), response); + Assert.Equal(new Uri(testUrl).ToString(), await HttpClientSlim.GetStringAsync(testUrl)); } } } From 11c7eb5665b294395db4227dd6f163e7e0fcbed5 Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Thu, 2 Mar 2017 16:34:22 -0800 Subject: [PATCH 1094/1662] Verify all request rejections are logged (#1295). --- .../BadHttpRequestTests.cs | 145 +++++----- .../FrameRequestHeadersTests.cs | 4 +- .../FrameTests.cs | 21 +- test/shared/HttpParsingData.cs | 249 ++++++++---------- 4 files changed, 210 insertions(+), 209 deletions(-) diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/BadHttpRequestTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/BadHttpRequestTests.cs index 0394b7fcd3..80f127c9d1 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/BadHttpRequestTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/BadHttpRequestTests.cs @@ -1,11 +1,15 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.AspNetCore.Testing; using Microsoft.Extensions.Internal; +using Microsoft.Extensions.Logging; +using Moq; using Xunit; namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests @@ -14,106 +18,102 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { [Theory] [MemberData(nameof(InvalidRequestLineData))] - public async Task TestInvalidRequestLines(string request) + public Task TestInvalidRequestLines(string request, string expectedExceptionMessage) { - using (var server = new TestServer(context => TaskCache.CompletedTask)) - { - using (var connection = server.CreateConnection()) - { - await connection.SendAll(request); - await ReceiveBadRequestResponse(connection, "400 Bad Request", server.Context.DateHeaderValue); - } - } + return TestBadRequest( + request, + "400 Bad Request", + expectedExceptionMessage); } [Theory] [MemberData(nameof(UnrecognizedHttpVersionData))] - public async Task TestInvalidRequestLinesWithUnrecognizedVersion(string httpVersion) + public Task TestInvalidRequestLinesWithUnrecognizedVersion(string httpVersion) { - using (var server = new TestServer(context => TaskCache.CompletedTask)) - { - using (var connection = server.CreateConnection()) - { - await connection.SendAll($"GET / {httpVersion}\r\n"); - await ReceiveBadRequestResponse(connection, "505 HTTP Version Not Supported", server.Context.DateHeaderValue); - } - } + return TestBadRequest( + $"GET / {httpVersion}\r\n", + "505 HTTP Version Not Supported", + $"Unrecognized HTTP version: {httpVersion}"); } [Theory] [MemberData(nameof(InvalidRequestHeaderData))] - public async Task TestInvalidHeaders(string rawHeaders) + public Task TestInvalidHeaders(string rawHeaders, string expectedExceptionMessage) { - using (var server = new TestServer(context => TaskCache.CompletedTask)) - { - using (var connection = server.CreateConnection()) - { - await connection.SendAll($"GET / HTTP/1.1\r\n{rawHeaders}"); - await ReceiveBadRequestResponse(connection, "400 Bad Request", server.Context.DateHeaderValue); - } - } + return TestBadRequest( + $"GET / HTTP/1.1\r\n{rawHeaders}", + "400 Bad Request", + expectedExceptionMessage); } - [Fact] - public async Task BadRequestWhenHeaderNameContainsNonASCIICharacters() + [Theory] + [InlineData("Hea\0der: value", "Invalid characters in header name.")] + [InlineData("Header: va\0lue", "Malformed request: invalid headers.")] + [InlineData("Head\x80r: value", "Invalid characters in header name.")] + [InlineData("Header: valu\x80", "Malformed request: invalid headers.")] + public Task BadRequestWhenHeaderNameContainsNonASCIIOrNullCharacters(string header, string expectedExceptionMessage) { - using (var server = new TestServer(context => { return Task.FromResult(0); })) - { - using (var connection = server.CreateConnection()) - { - await connection.SendAll( - "GET / HTTP/1.1", - "H\u00eb\u00e4d\u00ebr: value", - "", - ""); - await ReceiveBadRequestResponse(connection, "400 Bad Request", server.Context.DateHeaderValue); - } - } + return TestBadRequest( + $"GET / HTTP/1.1\r\n{header}\r\n\r\n", + "400 Bad Request", + expectedExceptionMessage); } [Theory] [InlineData("POST")] [InlineData("PUT")] - public async Task BadRequestIfMethodRequiresLengthButNoContentLengthOrTransferEncodingInRequest(string method) + public Task BadRequestIfMethodRequiresLengthButNoContentLengthOrTransferEncodingInRequest(string method) { - using (var server = new TestServer(context => { return Task.FromResult(0); })) - { - using (var connection = server.CreateConnection()) - { - await connection.Send($"{method} / HTTP/1.1\r\n\r\n"); - await ReceiveBadRequestResponse(connection, "411 Length Required", server.Context.DateHeaderValue); - } - } + return TestBadRequest( + $"{method} / HTTP/1.1\r\n\r\n", + "411 Length Required", + $"{method} request contains no Content-Length or Transfer-Encoding header"); } [Theory] [InlineData("POST")] [InlineData("PUT")] - public async Task BadRequestIfMethodRequiresLengthButNoContentLengthInHttp10Request(string method) + public Task BadRequestIfMethodRequiresLengthButNoContentLengthInHttp10Request(string method) { - using (var server = new TestServer(context => { return Task.FromResult(0); })) - { - using (var connection = server.CreateConnection()) - { - await connection.Send($"{method} / HTTP/1.0\r\n\r\n"); - await ReceiveBadRequestResponse(connection, "400 Bad Request", server.Context.DateHeaderValue); - } - } + return TestBadRequest( + $"{method} / HTTP/1.0\r\n\r\n", + "400 Bad Request", + $"{method} request contains no Content-Length header"); } [Theory] [InlineData("NaN")] [InlineData("-1")] - public async Task BadRequestIfContentLengthInvalid(string contentLength) + public Task BadRequestIfContentLengthInvalid(string contentLength) { - using (var server = new TestServer(context => { return Task.FromResult(0); })) + return TestBadRequest( + $"POST / HTTP/1.1\r\nContent-Length: {contentLength}\r\n\r\n", + "400 Bad Request", + $"Invalid content length: {contentLength}"); + } + + private async Task TestBadRequest(string request, string expectedResponseStatusCode, string expectedExceptionMessage) + { + BadHttpRequestException loggedException = null; + var mockKestrelTrace = new Mock(); + mockKestrelTrace + .Setup(trace => trace.IsEnabled(LogLevel.Information)) + .Returns(true); + mockKestrelTrace + .Setup(trace => trace.ConnectionBadRequest(It.IsAny(), It.IsAny())) + .Callback((connectionId, exception) => loggedException = exception); + + using (var server = new TestServer(context => TaskCache.CompletedTask, new TestServiceContext { Log = mockKestrelTrace.Object })) { using (var connection = server.CreateConnection()) { - await connection.SendAll($"GET / HTTP/1.1\r\nContent-Length: {contentLength}\r\n\r\n"); - await ReceiveBadRequestResponse(connection, "400 Bad Request", server.Context.DateHeaderValue); + await connection.SendAll(request); + await ReceiveBadRequestResponse(connection, expectedResponseStatusCode, server.Context.DateHeaderValue); } } + + mockKestrelTrace.Verify(trace => trace.ConnectionBadRequest(It.IsAny(), It.IsAny())); + Assert.Equal(expectedExceptionMessage, loggedException.Message); } private async Task ReceiveBadRequestResponse(TestConnection connection, string expectedResponseStatusCode, string expectedDateHeaderValue) @@ -127,10 +127,25 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests ""); } - public static IEnumerable InvalidRequestLineData => HttpParsingData.InvalidRequestLineData.Select(data => new[] { data[0] }); + public static IEnumerable InvalidRequestLineData => HttpParsingData.InvalidRequestLineData + .Select(requestLine => new object[] + { + requestLine, + $"Invalid request line: {requestLine.Replace("\r", "<0x0D>").Replace("\n", "<0x0A>")}", + }) + .Concat(HttpParsingData.EncodedNullCharInTargetRequestLines.Select(requestLine => new object[] + { + requestLine, + "Invalid request line." + })) + .Concat(HttpParsingData.NullCharInTargetRequestLines.Select(requestLine => new object[] + { + requestLine, + "Invalid request line." + })); public static TheoryData UnrecognizedHttpVersionData => HttpParsingData.UnrecognizedHttpVersionData; - public static IEnumerable InvalidRequestHeaderData => HttpParsingData.InvalidRequestHeaderData.Select(data => new[] { data[0] }); + public static IEnumerable InvalidRequestHeaderData => HttpParsingData.InvalidRequestHeaderData; } } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameRequestHeadersTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameRequestHeadersTests.cs index dbf6d857a5..006ac65cd1 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameRequestHeadersTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameRequestHeadersTests.cs @@ -304,14 +304,14 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } [Fact] - public void AppendThrowsWhenHeaderValueContainsNonASCIICharacters() + public void AppendThrowsWhenHeaderNameContainsNonASCIICharacters() { var headers = new FrameRequestHeaders(); const string key = "\u00141d\017c"; var encoding = Encoding.GetEncoding("iso-8859-1"); var exception = Assert.Throws( - () => headers.Append(encoding.GetBytes(key), key)); + () => headers.Append(encoding.GetBytes(key), "value")); Assert.Equal(StatusCodes.Status400BadRequest, exception.StatusCode); } } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs index f48a614579..ebfd64fea4 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs @@ -5,6 +5,7 @@ using System; using System.Collections.Generic; using System.IO; using System.IO.Pipelines; +using System.Linq; using System.Net; using System.Text; using System.Threading; @@ -759,7 +760,25 @@ namespace Microsoft.AspNetCore.Server.KestrelTests public static IEnumerable ValidRequestLineData => HttpParsingData.ValidRequestLineData; - public static IEnumerable InvalidRequestLineData => HttpParsingData.InvalidRequestLineData; + public static IEnumerable InvalidRequestLineData => HttpParsingData.InvalidRequestLineData + .Select(requestLine => new object[] + { + requestLine, + typeof(BadHttpRequestException), + $"Invalid request line: {requestLine.Replace("\r", "<0x0D>").Replace("\n", "<0x0A>")}", + }) + .Concat(HttpParsingData.EncodedNullCharInTargetRequestLines.Select(requestLine => new object[] + { + requestLine, + typeof(InvalidOperationException), + "The path contains null characters." + })) + .Concat(HttpParsingData.NullCharInTargetRequestLines.Select(requestLine => new object[] + { + requestLine, + typeof(InvalidOperationException), + new InvalidOperationException().Message + })); public static TheoryData UnrecognizedHttpVersionData => HttpParsingData.UnrecognizedHttpVersionData; diff --git a/test/shared/HttpParsingData.cs b/test/shared/HttpParsingData.cs index a5a83c58c6..50a5633c9c 100644 --- a/test/shared/HttpParsingData.cs +++ b/test/shared/HttpParsingData.cs @@ -4,7 +4,6 @@ using System; using System.Collections.Generic; using System.Linq; -using Microsoft.AspNetCore.Server.Kestrel; using Xunit; namespace Microsoft.AspNetCore.Testing @@ -71,150 +70,118 @@ namespace Microsoft.AspNetCore.Testing } } - // All these test cases must end in '\n', otherwise the server will spin forever - public static IEnumerable InvalidRequestLineData + public static IEnumerable InvalidRequestLineData => new[] { - get - { - var invalidRequestLines = new[] - { - "G\r\n", - "GE\r\n", - "GET\r\n", - "GET \r\n", - "GET /\r\n", - "GET / \r\n", - "GET/HTTP/1.1\r\n", - "GET /HTTP/1.1\r\n", - " \r\n", - " \r\n", - "/ HTTP/1.1\r\n", - " / HTTP/1.1\r\n", - "/ \r\n", - "GET \r\n", - "GET HTTP/1.0\r\n", - "GET HTTP/1.1\r\n", - "GET / \n", - "GET / HTTP/1.0\n", - "GET / HTTP/1.1\n", - "GET / HTTP/1.0\rA\n", - "GET / HTTP/1.1\ra\n", - "GET? / HTTP/1.1\r\n", - "GET ? HTTP/1.1\r\n", - "GET /a?b=cHTTP/1.1\r\n", - "GET /a%20bHTTP/1.1\r\n", - "GET /a%20b?c=dHTTP/1.1\r\n", - "GET %2F HTTP/1.1\r\n", - "GET %00 HTTP/1.1\r\n", - "CUSTOM \r\n", - "CUSTOM /\r\n", - "CUSTOM / \r\n", - "CUSTOM /HTTP/1.1\r\n", - "CUSTOM \r\n", - "CUSTOM HTTP/1.0\r\n", - "CUSTOM HTTP/1.1\r\n", - "CUSTOM / \n", - "CUSTOM / HTTP/1.0\n", - "CUSTOM / HTTP/1.1\n", - "CUSTOM / HTTP/1.0\rA\n", - "CUSTOM / HTTP/1.1\ra\n", - "CUSTOM ? HTTP/1.1\r\n", - "CUSTOM /a?b=cHTTP/1.1\r\n", - "CUSTOM /a%20bHTTP/1.1\r\n", - "CUSTOM /a%20b?c=dHTTP/1.1\r\n", - "CUSTOM %2F HTTP/1.1\r\n", - "CUSTOM %00 HTTP/1.1\r\n", - // Bad HTTP Methods (invalid according to RFC) - "( / HTTP/1.0\r\n", - ") / HTTP/1.0\r\n", - "< / HTTP/1.0\r\n", - "> / HTTP/1.0\r\n", - "@ / HTTP/1.0\r\n", - ", / HTTP/1.0\r\n", - "; / HTTP/1.0\r\n", - ": / HTTP/1.0\r\n", - "\\ / HTTP/1.0\r\n", - "\" / HTTP/1.0\r\n", - "/ / HTTP/1.0\r\n", - "[ / HTTP/1.0\r\n", - "] / HTTP/1.0\r\n", - "? / HTTP/1.0\r\n", - "= / HTTP/1.0\r\n", - "{ / HTTP/1.0\r\n", - "} / HTTP/1.0\r\n", - "get@ / HTTP/1.0\r\n", - "post= / HTTP/1.0\r\n", - }; + "G\r\n", + "GE\r\n", + "GET\r\n", + "GET \r\n", + "GET /\r\n", + "GET / \r\n", + "GET/HTTP/1.1\r\n", + "GET /HTTP/1.1\r\n", + " \r\n", + " \r\n", + "/ HTTP/1.1\r\n", + " / HTTP/1.1\r\n", + "/ \r\n", + "GET \r\n", + "GET HTTP/1.0\r\n", + "GET HTTP/1.1\r\n", + "GET / \n", + "GET / HTTP/1.0\n", + "GET / HTTP/1.1\n", + "GET / HTTP/1.0\rA\n", + "GET / HTTP/1.1\ra\n", + "GET? / HTTP/1.1\r\n", + "GET ? HTTP/1.1\r\n", + "GET /a?b=cHTTP/1.1\r\n", + "GET /a%20bHTTP/1.1\r\n", + "GET /a%20b?c=dHTTP/1.1\r\n", + "GET %2F HTTP/1.1\r\n", + "GET %00 HTTP/1.1\r\n", + "CUSTOM \r\n", + "CUSTOM /\r\n", + "CUSTOM / \r\n", + "CUSTOM /HTTP/1.1\r\n", + "CUSTOM \r\n", + "CUSTOM HTTP/1.0\r\n", + "CUSTOM HTTP/1.1\r\n", + "CUSTOM / \n", + "CUSTOM / HTTP/1.0\n", + "CUSTOM / HTTP/1.1\n", + "CUSTOM / HTTP/1.0\rA\n", + "CUSTOM / HTTP/1.1\ra\n", + "CUSTOM ? HTTP/1.1\r\n", + "CUSTOM /a?b=cHTTP/1.1\r\n", + "CUSTOM /a%20bHTTP/1.1\r\n", + "CUSTOM /a%20b?c=dHTTP/1.1\r\n", + "CUSTOM %2F HTTP/1.1\r\n", + "CUSTOM %00 HTTP/1.1\r\n", + // Bad HTTP Methods (invalid according to RFC) + "( / HTTP/1.0\r\n", + ") / HTTP/1.0\r\n", + "< / HTTP/1.0\r\n", + "> / HTTP/1.0\r\n", + "@ / HTTP/1.0\r\n", + ", / HTTP/1.0\r\n", + "; / HTTP/1.0\r\n", + ": / HTTP/1.0\r\n", + "\\ / HTTP/1.0\r\n", + "\" / HTTP/1.0\r\n", + "/ / HTTP/1.0\r\n", + "[ / HTTP/1.0\r\n", + "] / HTTP/1.0\r\n", + "? / HTTP/1.0\r\n", + "= / HTTP/1.0\r\n", + "{ / HTTP/1.0\r\n", + "} / HTTP/1.0\r\n", + "get@ / HTTP/1.0\r\n", + "post= / HTTP/1.0\r\n", + }; - var encodedNullCharInTargetRequestLines = new[] - { - "GET /%00 HTTP/1.1\r\n", - "GET /%00%00 HTTP/1.1\r\n", - "GET /%E8%00%84 HTTP/1.1\r\n", - "GET /%E8%85%00 HTTP/1.1\r\n", - "GET /%F3%00%82%86 HTTP/1.1\r\n", - "GET /%F3%85%00%82 HTTP/1.1\r\n", - "GET /%F3%85%82%00 HTTP/1.1\r\n", - "GET /%E8%85%00 HTTP/1.1\r\n", - "GET /%E8%01%00 HTTP/1.1\r\n", - }; - - var nullCharInTargetRequestLines = new[] - { - "GET \0 HTTP/1.1\r\n", - "GET /\0 HTTP/1.1\r\n", - "GET /\0\0 HTTP/1.1\r\n", - "GET /%C8\0 HTTP/1.1\r\n", - }; - - return invalidRequestLines.Select(requestLine => new object[] - { - requestLine, - typeof(BadHttpRequestException), - $"Invalid request line: {requestLine.Replace("\r", "<0x0D>").Replace("\n", "<0x0A>")}" - }) - .Concat(encodedNullCharInTargetRequestLines.Select(requestLine => new object[] - { - requestLine, - typeof(InvalidOperationException), - $"The path contains null characters." - })) - .Concat(nullCharInTargetRequestLines.Select(requestLine => new object[] - { - requestLine, - typeof(InvalidOperationException), - new InvalidOperationException().Message - })); - } - } - - public static TheoryData UnrecognizedHttpVersionData + public static IEnumerable EncodedNullCharInTargetRequestLines => new[] { - get + "GET /%00 HTTP/1.1\r\n", + "GET /%00%00 HTTP/1.1\r\n", + "GET /%E8%00%84 HTTP/1.1\r\n", + "GET /%E8%85%00 HTTP/1.1\r\n", + "GET /%F3%00%82%86 HTTP/1.1\r\n", + "GET /%F3%85%00%82 HTTP/1.1\r\n", + "GET /%F3%85%82%00 HTTP/1.1\r\n", + "GET /%E8%85%00 HTTP/1.1\r\n", + "GET /%E8%01%00 HTTP/1.1\r\n", + }; + + public static IEnumerable NullCharInTargetRequestLines => new[] { - return new TheoryData - { - "H", - "HT", - "HTT", - "HTTP", - "HTTP/", - "HTTP/1", - "HTTP/1.", - "http/1.0", - "http/1.1", - "HTTP/1.1 ", - "HTTP/1.0a", - "HTTP/1.0ab", - "HTTP/1.1a", - "HTTP/1.1ab", - "HTTP/1.2", - "HTTP/3.0", - "hello", - "8charact", - }; - } - } + "GET \0 HTTP/1.1\r\n", + "GET /\0 HTTP/1.1\r\n", + "GET /\0\0 HTTP/1.1\r\n", + "GET /%C8\0 HTTP/1.1\r\n", + }; + + public static TheoryData UnrecognizedHttpVersionData => new TheoryData + { + "H", + "HT", + "HTT", + "HTTP", + "HTTP/", + "HTTP/1", + "HTTP/1.", + "http/1.0", + "http/1.1", + "HTTP/1.1 ", + "HTTP/1.0a", + "HTTP/1.0ab", + "HTTP/1.1a", + "HTTP/1.1ab", + "HTTP/1.2", + "HTTP/3.0", + "hello", + "8charact", + }; public static IEnumerable InvalidRequestHeaderData { From 06134bc6e0795f0908c6dcdccec5915c3185dce3 Mon Sep 17 00:00:00 2001 From: John Luo Date: Sat, 4 Mar 2017 22:03:27 -0800 Subject: [PATCH 1095/1662] Add IPv6 loopback address by default #1434 --- .../Internal/Infrastructure/Constants.cs | 2 +- .../KestrelServer.cs | 12 +++++-- .../AddressRegistrationTests.cs | 31 +++++++++++++------ 3 files changed, 33 insertions(+), 12 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/Constants.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/Constants.cs index e0f592154b..2c201fea7c 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/Constants.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/Constants.cs @@ -17,7 +17,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure /// /// The IPEndPoint Kestrel will bind to if nothing else is specified. /// - public static readonly IPEndPoint DefaultIPEndPoint = new IPEndPoint(IPAddress.Loopback, 5000); + public static readonly string DefaultServerAddress = "http://localhost:5000"; /// /// Prefix of host name used to specify Unix sockets in the configuration. diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServer.cs b/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServer.cs index 1d05a0dd2b..a36da353f4 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServer.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServer.cs @@ -142,8 +142,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel } else if (!hasListenOptions && !hasServerAddresses) { - _logger.LogDebug($"No listening endpoints were configured. Binding to {Constants.DefaultIPEndPoint} by default."); - listenOptions.Add(new ListenOptions(Constants.DefaultIPEndPoint)); + _logger.LogDebug($"No listening endpoints were configured. Binding to {Constants.DefaultServerAddress} by default."); + + // "localhost" for both IPv4 and IPv6 can't be represented as an IPEndPoint. + StartLocalhost(engine, ServerAddress.FromUrl(Constants.DefaultServerAddress)); + + // If StartLocalhost doesn't throw, there is at least one listener. + // The port cannot change for "localhost". + _serverAddresses.Addresses.Add(Constants.DefaultServerAddress); + + return; } else if (!hasListenOptions) { diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs index fd7b950e24..572b45aa68 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs @@ -132,16 +132,29 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [ConditionalFact] [PortSupportedCondition(5000)] - public async Task DefaultsToPort5000() + public Task DefaultsServerAddress_BindsToIPv4() + { + return RegisterDefaultServerAddresses_Success(new[] { "http://127.0.0.1:5000" }); + } + + [ConditionalFact] + [IPv6SupportedCondition] + [PortSupportedCondition(5000)] + public Task DefaultsServerAddress_BindsToIPv6() + { + return RegisterDefaultServerAddresses_Success(new[] { "http://127.0.0.1:5000", "http://[::1]:5000" }); + } + + private async Task RegisterDefaultServerAddresses_Success(IEnumerable addresses) { var testLogger = new TestApplicationErrorLogger(); var hostBuilder = new WebHostBuilder() .UseKestrel() .ConfigureServices(services => - { - services.AddSingleton(new KestrelTestLoggerFactory(testLogger)); - }) + { + services.AddSingleton(new KestrelTestLoggerFactory(testLogger)); + }) .Configure(ConfigureEchoAddress); using (var host = hostBuilder.Build()) @@ -150,12 +163,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests Assert.Equal(5000, host.GetPort()); Assert.Single(testLogger.Messages, log => log.LogLevel == LogLevel.Debug && - string.Equals($"No listening endpoints were configured. Binding to {Constants.DefaultIPEndPoint} by default.", + string.Equals($"No listening endpoints were configured. Binding to {Constants.DefaultServerAddress} by default.", log.Message, StringComparison.Ordinal)); - foreach (var testUrl in new[] { "http://127.0.0.1:5000", /* "http://[::1]:5000" */}) + foreach (var address in addresses) { - Assert.Equal(new Uri(testUrl).ToString(), await HttpClientSlim.GetStringAsync(testUrl)); + Assert.Equal(new Uri(address).ToString(), await HttpClientSlim.GetStringAsync(address)); } } } @@ -373,8 +386,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests var dataset = new TheoryData>(); // Default host and port - dataset.Add(null, _ => new[] { "http://127.0.0.1:5000/", /*"http://[::1]:5000/"*/ }); - dataset.Add(string.Empty, _ => new[] { "http://127.0.0.1:5000/", /*"http://[::1]:5000/"*/ }); + dataset.Add(null, _ => new[] { "http://127.0.0.1:5000/", "http://[::1]:5000/" }); + dataset.Add(string.Empty, _ => new[] { "http://127.0.0.1:5000/", "http://[::1]:5000/" }); // Static ports var port = GetNextPort(); From 02a434290824a1d9ef4496f6bb6a742d156be465 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Tue, 7 Mar 2017 08:58:55 -0800 Subject: [PATCH 1096/1662] Made changes to TakeSingleHeader (#1453) * Made changes to TakeSingleHeader - Remove state machine and just parse in place - Inline OnHeader into TakeSingleHeader - Use IndexOfVectorized instead of custom indexof - Normalize header whitespace error - Combine IndexOf and IndexOfAny into a single IndexOfNameEnd call --- .../BadHttpRequestException.cs | 3 - .../Internal/Http/KestrelHttpParser.cs | 273 ++++++++---------- .../Internal/Http/RequestRejectionReason.cs | 1 - .../FrameTests.cs | 2 +- test/shared/HttpParsingData.cs | 4 +- 5 files changed, 131 insertions(+), 152 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/BadHttpRequestException.cs b/src/Microsoft.AspNetCore.Server.Kestrel/BadHttpRequestException.cs index a19fd6db35..54533f05e1 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/BadHttpRequestException.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/BadHttpRequestException.cs @@ -25,9 +25,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel case RequestRejectionReason.HeadersCorruptedInvalidHeaderSequence: ex = new BadHttpRequestException("Headers corrupted, invalid header sequence.", StatusCodes.Status400BadRequest); break; - case RequestRejectionReason.HeaderLineMustNotStartWithWhitespace: - ex = new BadHttpRequestException("Header line must not start with whitespace.", StatusCodes.Status400BadRequest); - break; case RequestRejectionReason.NoColonCharacterFoundInHeaderLine: ex = new BadHttpRequestException("No ':' character found in header line.", StatusCodes.Status400BadRequest); break; diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/KestrelHttpParser.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/KestrelHttpParser.cs index 998aa6f46a..f85af592fb 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/KestrelHttpParser.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/KestrelHttpParser.cs @@ -4,6 +4,7 @@ using System; using System.Buffers; using System.IO.Pipelines; +using System.Runtime.CompilerServices; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.Extensions.Logging; @@ -316,9 +317,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http // Headers don't end in CRLF line. RejectRequest(RequestRejectionReason.HeadersCorruptedInvalidHeaderSequence); } - else if (ch1 == ByteSpace || ch1 == ByteTab) + else if(ch1 == ByteSpace || ch1 == ByteTab) { - RejectRequest(RequestRejectionReason.HeaderLineMustNotStartWithWhitespace); + RejectRequest(RequestRejectionReason.WhitespaceIsNotAllowedInHeaderName); } // We moved the reader so look ahead 2 bytes so reset both the reader @@ -329,13 +330,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http index = reader.Index; } - Span headerSpan; - - var endIndex = IndexOf(pBuffer, index, remaining, ByteLF); + var endIndex = new Span(pBuffer + index, remaining).IndexOfVectorized(ByteLF); + var length = 0; if (endIndex != -1) { - headerSpan = new Span(pBuffer + index, (endIndex - index + 1)); + length = endIndex + 1; + var pHeader = pBuffer + index; + + TakeSingleHeader(pHeader, length, handler); } else { @@ -350,28 +353,23 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http // Make sure LF is included in lineEnd lineEnd = buffer.Move(lineEnd, 1); - headerSpan = buffer.Slice(current, lineEnd).ToSpan(); + var headerSpan = buffer.Slice(current, lineEnd).ToSpan(); + length = headerSpan.Length; + + fixed (byte* pHeader = &headerSpan.DangerousGetPinnableReference()) + { + TakeSingleHeader(pHeader, length, handler); + } // We're going to the next span after this since we know we crossed spans here // so mark the remaining as equal to the headerSpan so that we end up at 0 // on the next iteration - remaining = headerSpan.Length; - } - - if (!TakeSingleHeader(headerSpan, out var nameStart, out var nameEnd, out var valueStart, out var valueEnd)) - { - return false; + remaining = length; } // Skip the reader forward past the header line - reader.Skip(headerSpan.Length); - - remaining -= headerSpan.Length; - - var nameBuffer = headerSpan.Slice(nameStart, nameEnd - nameStart); - var valueBuffer = headerSpan.Slice(valueStart, valueEnd - valueStart); - - handler.OnHeader(nameBuffer, valueBuffer); + reader.Skip(length); + remaining -= length; } } } @@ -390,142 +388,127 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } } - private unsafe int IndexOf(byte* pBuffer, int index, int length, byte value) + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private unsafe int IndexOfNameEnd(byte* pBuffer, int index, int length) { - for (int i = 0; i < length; i++, index++) + var pCurrent = pBuffer + index; + var pEnd = pBuffer + index + length; + var result = -1; + var sawWhitespace = false; + + while (pCurrent < pEnd) { - if (pBuffer[index] == value) + var ch = *pCurrent; + if (ch == ByteColon) { - return index; + if (sawWhitespace) + { + RejectRequest(RequestRejectionReason.WhitespaceIsNotAllowedInHeaderName); + } + + result = index; + break; } + + if (ch == ByteTab || ch == ByteSpace) + { + sawWhitespace = true; + } + + index++; + pCurrent++; } - return -1; + return result; } - private unsafe bool TakeSingleHeader(Span span, out int nameStart, out int nameEnd, out int valueStart, out int valueEnd) + private unsafe void TakeSingleHeader(byte* pHeader, int headerLineLength, T handler) where T : IHttpHeadersHandler { - nameStart = 0; - nameEnd = -1; - valueStart = -1; - valueEnd = -1; - var headerLineLength = span.Length; - var nameHasWhitespace = false; - var previouslyWhitespace = false; + var nameEnd = -1; + var valueStart = -1; + var valueEnd = -1; + var index = 0; + var pCurrent = pHeader + index; + var pEnd = pHeader + headerLineLength; - int i = 0; - var done = false; - fixed (byte* pHeader = &span.DangerousGetPinnableReference()) + nameEnd = IndexOfNameEnd(pHeader, index, headerLineLength); + + if (nameEnd == -1) { - switch (HeaderState.Name) - { - case HeaderState.Name: - for (; i < headerLineLength; i++) - { - var ch = pHeader[i]; - if (ch == ByteColon) - { - if (nameHasWhitespace) - { - RejectRequest(RequestRejectionReason.WhitespaceIsNotAllowedInHeaderName); - } - nameEnd = i; - - // Consume space - i++; - - goto case HeaderState.Whitespace; - } - - if (ch == ByteSpace || ch == ByteTab) - { - nameHasWhitespace = true; - } - } - RejectRequest(RequestRejectionReason.NoColonCharacterFoundInHeaderLine); - - break; - case HeaderState.Whitespace: - for (; i < headerLineLength; i++) - { - var ch = pHeader[i]; - var whitespace = ch == ByteTab || ch == ByteSpace || ch == ByteCR; - - if (!whitespace) - { - // Mark the first non whitespace char as the start of the - // header value and change the state to expect to the header value - valueStart = i; - - goto case HeaderState.ExpectValue; - } - // If we see a CR then jump to the next state directly - else if (ch == ByteCR) - { - goto case HeaderState.ExpectValue; - } - } - - RejectRequest(RequestRejectionReason.MissingCRInHeaderLine); - - break; - case HeaderState.ExpectValue: - for (; i < headerLineLength; i++) - { - var ch = pHeader[i]; - var whitespace = ch == ByteTab || ch == ByteSpace; - - if (whitespace) - { - if (!previouslyWhitespace) - { - // If we see a whitespace char then maybe it's end of the - // header value - valueEnd = i; - } - } - else if (ch == ByteCR) - { - // If we see a CR and we haven't ever seen whitespace then - // this is the end of the header value - if (valueEnd == -1) - { - valueEnd = i; - } - - // We never saw a non whitespace character before the CR - if (valueStart == -1) - { - valueStart = valueEnd; - } - - // Consume space - i++; - - goto case HeaderState.ExpectNewLine; - } - else - { - // If we find a non whitespace char that isn't CR then reset the end index - valueEnd = -1; - } - - previouslyWhitespace = whitespace; - } - RejectRequest(RequestRejectionReason.MissingCRInHeaderLine); - break; - case HeaderState.ExpectNewLine: - if (pHeader[i] != ByteLF) - { - RejectRequest(RequestRejectionReason.HeaderValueMustNotContainCR); - } - goto case HeaderState.Complete; - case HeaderState.Complete: - done = true; - break; - } + RejectRequest(RequestRejectionReason.NoColonCharacterFoundInHeaderLine); } - return done; + // Skip colon + index += nameEnd + 1; + pCurrent += index; + valueStart = index; + var pValueStart = pCurrent; + + while (pCurrent < pEnd) + { + var ch = *pCurrent; + if (ch != ByteTab && ch != ByteSpace && ch != ByteCR) + { + valueStart = index; + pValueStart = pCurrent; + break; + } + else if (ch == ByteCR) + { + break; + } + pCurrent++; + index++; + } + + var endIndex = headerLineLength - 1; + pEnd--; + + if (*pEnd != ByteLF) + { + RejectRequest(RequestRejectionReason.HeaderValueMustNotContainCR); + } + + endIndex--; + pEnd--; + + if (*pEnd != ByteCR) + { + RejectRequest(RequestRejectionReason.MissingCRInHeaderLine); + } + + endIndex--; + pEnd--; + + while (pEnd >= pValueStart) + { + var ch = *pEnd; + if (ch != ByteTab && ch != ByteSpace && ch != ByteCR && valueEnd == -1) + { + valueEnd = endIndex; + } + else if (ch == ByteCR) + { + RejectRequest(RequestRejectionReason.HeaderValueMustNotContainCR); + } + + pEnd--; + endIndex--; + } + + if (valueEnd == -1) + { + valueEnd = valueStart; + } + else + { + valueEnd++; + } + + + var nameBuffer = new Span(pHeader, nameEnd); + var valueBuffer = new Span(pHeader + valueStart, valueEnd - valueStart); + + handler.OnHeader(nameBuffer, valueBuffer); } private static bool IsValidTokenChar(char c) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/RequestRejectionReason.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/RequestRejectionReason.cs index 042a25d99c..b0aa5a1372 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/RequestRejectionReason.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/RequestRejectionReason.cs @@ -7,7 +7,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { UnrecognizedHTTPVersion, HeadersCorruptedInvalidHeaderSequence, - HeaderLineMustNotStartWithWhitespace, NoColonCharacterFoundInHeaderLine, WhitespaceIsNotAllowedInHeaderName, HeaderValueMustNotContainCR, diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs index ebfd64fea4..46d54d1b40 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs @@ -200,7 +200,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var exception = Assert.Throws(() => _frame.TakeMessageHeaders(readableBuffer, out _consumed, out _examined)); _socketInput.Reader.Advance(_consumed, _examined); - Assert.Equal("Header line must not start with whitespace.", exception.Message); + Assert.Equal("Whitespace is not allowed in header name.", exception.Message); Assert.Equal(StatusCodes.Status400BadRequest, exception.StatusCode); } diff --git a/test/shared/HttpParsingData.cs b/test/shared/HttpParsingData.cs index 50a5633c9c..56688b67f0 100644 --- a/test/shared/HttpParsingData.cs +++ b/test/shared/HttpParsingData.cs @@ -254,10 +254,10 @@ namespace Microsoft.AspNetCore.Testing return new[] { - Tuple.Create(headersWithLineFolding,"Header line must not start with whitespace."), + Tuple.Create(headersWithLineFolding,"Whitespace is not allowed in header name."), Tuple.Create(headersWithCRInValue,"Header value must not contain CR characters."), Tuple.Create(headersWithMissingColon,"No ':' character found in header line."), - Tuple.Create(headersStartingWithWhitespace, "Header line must not start with whitespace."), + Tuple.Create(headersStartingWithWhitespace, "Whitespace is not allowed in header name."), Tuple.Create(headersWithWithspaceInName,"Whitespace is not allowed in header name."), Tuple.Create(headersNotEndingInCrLfLine, "Headers corrupted, invalid header sequence.") } From 1294c006183af28bd3f34ccc01ea1354d3e830d9 Mon Sep 17 00:00:00 2001 From: Pavel Krymets Date: Tue, 7 Mar 2017 11:52:45 -0800 Subject: [PATCH 1097/1662] Cleanup unused code (#1458) --- .../Internal/Http/UrlPathDecoder.cs | 312 ------ .../Infrastructure/MemoryPoolIterator.cs | 895 +----------------- .../AsciiDecoding.cs | 144 +-- .../MemoryPoolBlockTests.cs | 182 +--- .../MemoryPoolExtensions.cs | 7 +- .../MemoryPoolIteratorTests.cs | 803 +--------------- .../UrlPathDecoder.cs | 226 ----- 7 files changed, 34 insertions(+), 2535 deletions(-) delete mode 100644 src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/UrlPathDecoder.cs delete mode 100644 test/Microsoft.AspNetCore.Server.KestrelTests/UrlPathDecoder.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/UrlPathDecoder.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/UrlPathDecoder.cs deleted file mode 100644 index 67004cf24f..0000000000 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/UrlPathDecoder.cs +++ /dev/null @@ -1,312 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; - -namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http -{ - public class UrlPathDecoder - { - /// - /// Unescapes the string between given memory iterators in place. - /// - /// The iterator points to the beginning of the sequence. - /// The iterator points to the byte behind the end of the sequence. - /// The iterator points to the byte behind the end of the processed sequence. - public static MemoryPoolIterator Unescape(MemoryPoolIterator start, MemoryPoolIterator end) - { - // the slot to read the input - var reader = start; - - // the slot to write the unescaped byte - var writer = reader; - - while (true) - { - if (CompareIterators(ref reader, ref end)) - { - return writer; - } - - if (reader.Peek() == '%') - { - var decodeReader = reader; - - // If decoding process succeeds, the writer iterator will be moved - // to the next write-ready location. On the other hand if the scanned - // percent-encodings cannot be interpreted as sequence of UTF-8 octets, - // these bytes should be copied to output as is. - // The decodeReader iterator is always moved to the first byte not yet - // be scanned after the process. A failed decoding means the chars - // between the reader and decodeReader can be copied to output untouched. - if (!DecodeCore(ref decodeReader, ref writer, end)) - { - Copy(reader, decodeReader, ref writer); - } - - reader = decodeReader; - } - else - { - writer.Put((byte)reader.Take()); - } - } - } - - /// - /// Unescape the percent-encodings - /// - /// The iterator point to the first % char - /// The place to write to - /// The end of the sequence - private static bool DecodeCore(ref MemoryPoolIterator reader, ref MemoryPoolIterator writer, MemoryPoolIterator end) - { - // preserves the original head. if the percent-encodings cannot be interpreted as sequence of UTF-8 octets, - // bytes from this till the last scanned one will be copied to the memory pointed by writer. - var byte1 = UnescapePercentEncoding(ref reader, end); - - if (byte1 == 0) - { - throw BadHttpRequestException.GetException(RequestRejectionReason.PathContainsNullCharacters); - } - - if (byte1 == -1) - { - return false; - } - - if (byte1 <= 0x7F) - { - // first byte < U+007f, it is a single byte ASCII - writer.Put((byte)byte1); - return true; - } - - int byte2 = 0, byte3 = 0, byte4 = 0; - - // anticipate more bytes - var currentDecodeBits = 0; - var byteCount = 1; - var expectValueMin = 0; - if ((byte1 & 0xE0) == 0xC0) - { - // 110x xxxx, expect one more byte - currentDecodeBits = byte1 & 0x1F; - byteCount = 2; - expectValueMin = 0x80; - } - else if ((byte1 & 0xF0) == 0xE0) - { - // 1110 xxxx, expect two more bytes - currentDecodeBits = byte1 & 0x0F; - byteCount = 3; - expectValueMin = 0x800; - } - else if ((byte1 & 0xF8) == 0xF0) - { - // 1111 0xxx, expect three more bytes - currentDecodeBits = byte1 & 0x07; - byteCount = 4; - expectValueMin = 0x10000; - } - else - { - // invalid first byte - return false; - } - - var remainingBytes = byteCount - 1; - while (remainingBytes > 0) - { - // read following three chars - if (CompareIterators(ref reader, ref end)) - { - return false; - } - - var nextItr = reader; - var nextByte = UnescapePercentEncoding(ref nextItr, end); - if (nextByte == -1) - { - return false; - } - - if ((nextByte & 0xC0) != 0x80) - { - // the follow up byte is not in form of 10xx xxxx - return false; - } - - currentDecodeBits = (currentDecodeBits << 6) | (nextByte & 0x3F); - remainingBytes--; - - if (remainingBytes == 1 && currentDecodeBits >= 0x360 && currentDecodeBits <= 0x37F) - { - // this is going to end up in the range of 0xD800-0xDFFF UTF-16 surrogates that - // are not allowed in UTF-8; - return false; - } - - if (remainingBytes == 2 && currentDecodeBits >= 0x110) - { - // this is going to be out of the upper Unicode bound 0x10FFFF. - return false; - } - - reader = nextItr; - if (byteCount - remainingBytes == 2) - { - byte2 = nextByte; - } - else if (byteCount - remainingBytes == 3) - { - byte3 = nextByte; - } - else if (byteCount - remainingBytes == 4) - { - byte4 = nextByte; - } - } - - if (currentDecodeBits < expectValueMin) - { - // overlong encoding (e.g. using 2 bytes to encode something that only needed 1). - return false; - } - - // all bytes are verified, write to the output - if (byteCount > 0) - { - writer.Put((byte)byte1); - } - if (byteCount > 1) - { - writer.Put((byte)byte2); - } - if (byteCount > 2) - { - writer.Put((byte)byte3); - } - if (byteCount > 3) - { - writer.Put((byte)byte4); - } - - return true; - } - - private static void Copy(MemoryPoolIterator head, MemoryPoolIterator tail, ref MemoryPoolIterator writer) - { - while (!CompareIterators(ref head, ref tail)) - { - writer.Put((byte)head.Take()); - } - } - - /// - /// Read the percent-encoding and try unescape it. - /// - /// The operation first peek at the character the - /// iterator points at. If it is % the is then - /// moved on to scan the following to characters. If the two following - /// characters are hexadecimal literals they will be unescaped and the - /// value will be returned. - /// - /// If the first character is not % the iterator - /// will be removed beyond the location of % and -1 will be returned. - /// - /// If the following two characters can't be successfully unescaped the - /// iterator will be move behind the % and -1 - /// will be returned. - /// - /// The value to read - /// The end of the sequence - /// The unescaped byte if success. Otherwise return -1. - private static int UnescapePercentEncoding(ref MemoryPoolIterator scan, MemoryPoolIterator end) - { - if (scan.Take() != '%') - { - return -1; - } - - var probe = scan; - - int value1 = ReadHex(ref probe, end); - if (value1 == -1) - { - return -1; - } - - int value2 = ReadHex(ref probe, end); - if (value2 == -1) - { - return -1; - } - - if (SkipUnescape(value1, value2)) - { - return -1; - } - - scan = probe; - return (value1 << 4) + value2; - } - - /// - /// Read the next char and convert it into hexadecimal value. - /// - /// The iterator will be moved to the next - /// byte no matter no matter whether the operation successes. - /// - /// The value to read - /// The end of the sequence - /// The hexadecimal value if successes, otherwise -1. - private static int ReadHex(ref MemoryPoolIterator scan, MemoryPoolIterator end) - { - if (CompareIterators(ref scan, ref end)) - { - return -1; - } - - var value = scan.Take(); - var isHead = (((value >= '0') && (value <= '9')) || - ((value >= 'A') && (value <= 'F')) || - ((value >= 'a') && (value <= 'f'))); - - if (!isHead) - { - return -1; - } - - if (value <= '9') - { - return value - '0'; - } - else if (value <= 'F') - { - return (value - 'A') + 10; - } - else // a - f - { - return (value - 'a') + 10; - } - } - - private static bool SkipUnescape(int value1, int value2) - { - // skip %2F - if (value1 == 2 && value2 == 15) - { - return true; - } - - return false; - } - - private static bool CompareIterators(ref MemoryPoolIterator lhs, ref MemoryPoolIterator rhs) - { - // uses ref parameter to save cost of copying - return (lhs.Block == rhs.Block) && (lhs.Index == rhs.Index); - } - } -} diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolIterator.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolIterator.cs index 07491b7377..0f4d3cebe5 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolIterator.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolIterator.cs @@ -14,15 +14,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure public struct MemoryPoolIterator { private const int _maxULongByteLength = 20; - private const ulong _xorPowerOfTwoToHighByte = (0x07ul | - 0x06ul << 8 | - 0x05ul << 16 | - 0x04ul << 24 | - 0x03ul << 32 | - 0x02ul << 40 | - 0x01ul << 48 ) + 1; - - private static readonly int _vectorSpan = Vector.Count; [ThreadStatic] private static byte[] _numericBytesScratch; @@ -135,668 +126,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure } } while (true); } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void Skip(int bytesToSkip) - { - var block = _block; - if (block == null && bytesToSkip > 0) - { - ThrowInvalidOperationException_SkipMoreThanAvailable(); - } - - // Always set wasLastBlock before checking .End to avoid race which may cause data loss - var wasLastBlock = block.Next == null; - var following = block.End - _index; - - if (following >= bytesToSkip) - { - _index += bytesToSkip; - return; - } - - if (wasLastBlock) - { - ThrowInvalidOperationException_SkipMoreThanAvailable(); - } - - SkipMultiBlock(bytesToSkip, following); - } - - [MethodImpl(MethodImplOptions.NoInlining)] - private void SkipMultiBlock(int bytesToSkip, int following) - { - var block = _block; - do - { - bytesToSkip -= following; - block = block.Next; - var index = block.Start; - - // Always set wasLastBlock before checking .End to avoid race which may cause data loss - var wasLastBlock = block.Next == null; - following = block.End - index; - - if (following >= bytesToSkip) - { - _block = block; - _index = index + bytesToSkip; - return; - } - - if (wasLastBlock) - { - ThrowInvalidOperationException_SkipMoreThanAvailable(); - } - } while (true); - } - - private static void ThrowInvalidOperationException_SkipMoreThanAvailable() - { - throw new InvalidOperationException("Attempted to skip more bytes than available."); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public int Peek() - { - var block = _block; - if (block == null) - { - return -1; - } - - var index = _index; - - // Always set wasLastBlock before checking .End to avoid race which may cause data loss - var wasLastBlock = block.Next == null; - if (index < block.End) - { - return block.Array[index]; - } - - return wasLastBlock ? -1 : PeekMultiBlock(); - } - - [MethodImpl(MethodImplOptions.NoInlining)] - private int PeekMultiBlock() - { - var block = _block; - do - { - block = block.Next; - var index = block.Start; - - // Always set wasLastBlock before checking .End to avoid race which may cause data loss - var wasLastBlock = block.Next == null; - - if (index < block.End) - { - return block.Array[index]; - } - if (wasLastBlock) - { - return -1; - } - } while (true); - } - - // NOTE: Little-endian only! - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public unsafe bool TryPeekLong(out ulong longValue) - { - longValue = 0; - - var block = _block; - if (block == null) - { - return false; - } - - // Always set wasLastBlock before checking .End to avoid race which may cause data loss - var wasLastBlock = block.Next == null; - var blockBytes = block.End - _index; - - if (blockBytes >= sizeof(ulong)) - { - longValue = *(ulong*)(block.DataFixedPtr + _index); - return true; - } - - return wasLastBlock ? false : TryPeekLongMultiBlock(ref longValue, blockBytes); - } - - [MethodImpl(MethodImplOptions.NoInlining)] - private unsafe bool TryPeekLongMultiBlock(ref ulong longValue, int blockBytes) - { - // Each block will be filled with at least 2048 bytes before the Next pointer is set, so a long - // will cross at most one block boundary assuming there are at least 8 bytes following the iterator. - var nextBytes = sizeof(ulong) - blockBytes; - - var block = _block; - if (block.Next.End - block.Next.Start < nextBytes) - { - return false; - } - - var nextLong = *(ulong*)(block.Next.DataFixedPtr + block.Next.Start); - - if (blockBytes == 0) - { - // This case can not fall through to the else block since that would cause a 64-bit right shift - // on blockLong which is equivalent to no shift at all instead of shifting in all zeros. - // https://msdn.microsoft.com/en-us/library/xt18et0d.aspx - longValue = nextLong; - } - else - { - var blockLong = *(ulong*)(block.DataFixedPtr + block.End - sizeof(ulong)); - - // Ensure that the right shift has a ulong operand so a logical shift is performed. - longValue = (blockLong >> nextBytes * 8) | (nextLong << blockBytes * 8); - } - - return true; - } - - public int Seek(byte byte0) - { - int bytesScanned; - return Seek(byte0, out bytesScanned); - } - - public unsafe int Seek( - byte byte0, - out int bytesScanned, - int limit = int.MaxValue) - { - bytesScanned = 0; - - var block = _block; - if (block == null || limit <= 0) - { - return -1; - } - - var index = _index; - var wasLastBlock = block.Next == null; - var following = block.End - index; - byte[] array; - var byte0Vector = GetVector(byte0); - - while (true) - { - while (following == 0) - { - if (bytesScanned >= limit || wasLastBlock) - { - _block = block; - _index = index; - return -1; - } - - block = block.Next; - index = block.Start; - wasLastBlock = block.Next == null; - following = block.End - index; - } - array = block.Array; - while (following > 0) - { - // Need unit tests to test Vector path -#if !DEBUG - // Check will be Jitted away https://github.com/dotnet/coreclr/issues/1079 - if (Vector.IsHardwareAccelerated) - { -#endif - if (following >= _vectorSpan) - { - var byte0Equals = Vector.Equals(new Vector(array, index), byte0Vector); - - if (byte0Equals.Equals(Vector.Zero)) - { - if (bytesScanned + _vectorSpan >= limit) - { - _block = block; - // Ensure iterator is left at limit position - _index = index + (limit - bytesScanned); - bytesScanned = limit; - return -1; - } - - bytesScanned += _vectorSpan; - following -= _vectorSpan; - index += _vectorSpan; - continue; - } - - _block = block; - - var firstEqualByteIndex = LocateFirstFoundByte(byte0Equals); - var vectorBytesScanned = firstEqualByteIndex + 1; - - if (bytesScanned + vectorBytesScanned > limit) - { - // Ensure iterator is left at limit position - _index = index + (limit - bytesScanned); - bytesScanned = limit; - return -1; - } - - _index = index + firstEqualByteIndex; - bytesScanned += vectorBytesScanned; - - return byte0; - } - // Need unit tests to test Vector path -#if !DEBUG - } -#endif - - var pCurrent = (block.DataFixedPtr + index); - var pEnd = pCurrent + Math.Min(following, limit - bytesScanned); - do - { - bytesScanned++; - if (*pCurrent == byte0) - { - _block = block; - _index = index; - return byte0; - } - pCurrent++; - index++; - } while (pCurrent < pEnd); - - following = 0; - break; - } - } - } - - public unsafe int Seek( - byte byte0, - ref MemoryPoolIterator limit) - { - var block = _block; - if (block == null) - { - return -1; - } - - var index = _index; - var wasLastBlock = block.Next == null; - var following = block.End - index; - - while (true) - { - while (following == 0) - { - if ((block == limit.Block && index > limit.Index) || - wasLastBlock) - { - _block = block; - // Ensure iterator is left at limit position - _index = limit.Index; - return -1; - } - - block = block.Next; - index = block.Start; - wasLastBlock = block.Next == null; - following = block.End - index; - } - var array = block.Array; - while (following > 0) - { -// Need unit tests to test Vector path -#if !DEBUG - // Check will be Jitted away https://github.com/dotnet/coreclr/issues/1079 - if (Vector.IsHardwareAccelerated) - { -#endif - if (following >= _vectorSpan) - { - var byte0Equals = Vector.Equals(new Vector(array, index), GetVector(byte0)); - - if (byte0Equals.Equals(Vector.Zero)) - { - if (block == limit.Block && index + _vectorSpan > limit.Index) - { - _block = block; - // Ensure iterator is left at limit position - _index = limit.Index; - return -1; - } - - following -= _vectorSpan; - index += _vectorSpan; - continue; - } - - _block = block; - - var firstEqualByteIndex = LocateFirstFoundByte(byte0Equals); - - if (_block == limit.Block && index + firstEqualByteIndex > limit.Index) - { - // Ensure iterator is left at limit position - _index = limit.Index; - return -1; - } - - _index = index + firstEqualByteIndex; - - return byte0; - } -// Need unit tests to test Vector path -#if !DEBUG - } -#endif - - var pCurrent = (block.DataFixedPtr + index); - var pEnd = block == limit.Block ? block.DataFixedPtr + limit.Index + 1 : pCurrent + following; - do - { - if (*pCurrent == byte0) - { - _block = block; - _index = index; - return byte0; - } - pCurrent++; - index++; - } while (pCurrent < pEnd); - - following = 0; - break; - } - } - } - - public int Seek(byte byte0, byte byte1) - { - var limit = new MemoryPoolIterator(); - return Seek(byte0, byte1, ref limit); - } - - public unsafe int Seek( - byte byte0, - byte byte1, - ref MemoryPoolIterator limit) - { - var block = _block; - if (block == null) - { - return -1; - } - - var index = _index; - var wasLastBlock = block.Next == null; - var following = block.End - index; - int byteIndex = int.MaxValue; - - while (true) - { - while (following == 0) - { - if ((block == limit.Block && index > limit.Index) || - wasLastBlock) - { - _block = block; - // Ensure iterator is left at limit position - _index = limit.Index; - return -1; - } - block = block.Next; - index = block.Start; - wasLastBlock = block.Next == null; - following = block.End - index; - } - var array = block.Array; - while (following > 0) - { - -// Need unit tests to test Vector path -#if !DEBUG - // Check will be Jitted away https://github.com/dotnet/coreclr/issues/1079 - if (Vector.IsHardwareAccelerated) - { -#endif - if (following >= _vectorSpan) - { - var data = new Vector(array, index); - - var byteEquals = Vector.Equals(data, GetVector(byte0)); - byteEquals = Vector.ConditionalSelect(byteEquals, byteEquals, Vector.Equals(data, GetVector(byte1))); - - if (!byteEquals.Equals(Vector.Zero)) - { - byteIndex = LocateFirstFoundByte(byteEquals); - } - - if (byteIndex == int.MaxValue) - { - following -= _vectorSpan; - index += _vectorSpan; - - if (block == limit.Block && index > limit.Index) - { - _block = block; - // Ensure iterator is left at limit position - _index = limit.Index; - return -1; - } - - continue; - } - - _block = block; - - _index = index + byteIndex; - - if (block == limit.Block && _index > limit.Index) - { - // Ensure iterator is left at limit position - _index = limit.Index; - return -1; - } - - _index = index + byteIndex; - - if (block == limit.Block && _index > limit.Index) - { - // Ensure iterator is left at limit position - _index = limit.Index; - return -1; - } - - return block.Array[index + byteIndex]; - } -// Need unit tests to test Vector path -#if !DEBUG - } -#endif - var pCurrent = (block.DataFixedPtr + index); - var pEnd = block == limit.Block ? block.DataFixedPtr + limit.Index + 1 : pCurrent + following; - do - { - if (*pCurrent == byte0) - { - _block = block; - _index = index; - return byte0; - } - if (*pCurrent == byte1) - { - _block = block; - _index = index; - return byte1; - } - pCurrent++; - index++; - } while (pCurrent != pEnd); - - following = 0; - break; - } - } - } - - public int Seek(byte byte0, byte byte1, byte byte2) - { - var limit = new MemoryPoolIterator(); - return Seek(byte0, byte1, byte2, ref limit); - } - - public unsafe int Seek( - byte byte0, - byte byte1, - byte byte2, - ref MemoryPoolIterator limit) - { - var block = _block; - if (block == null) - { - return -1; - } - - var index = _index; - var wasLastBlock = block.Next == null; - var following = block.End - index; - int byteIndex = int.MaxValue; - - while (true) - { - while (following == 0) - { - if ((block == limit.Block && index > limit.Index) || - wasLastBlock) - { - _block = block; - // Ensure iterator is left at limit position - _index = limit.Index; - return -1; - } - block = block.Next; - index = block.Start; - wasLastBlock = block.Next == null; - following = block.End - index; - } - var array = block.Array; - while (following > 0) - { -// Need unit tests to test Vector path -#if !DEBUG - // Check will be Jitted away https://github.com/dotnet/coreclr/issues/1079 - if (Vector.IsHardwareAccelerated) - { -#endif - if (following >= _vectorSpan) - { - var data = new Vector(array, index); - - var byteEquals = Vector.Equals(data, GetVector(byte0)); - byteEquals = Vector.ConditionalSelect(byteEquals, byteEquals, Vector.Equals(data, GetVector(byte1))); - byteEquals = Vector.ConditionalSelect(byteEquals, byteEquals, Vector.Equals(data, GetVector(byte2))); - - if (!byteEquals.Equals(Vector.Zero)) - { - byteIndex = LocateFirstFoundByte(byteEquals); - } - - if (byteIndex == int.MaxValue) - { - following -= _vectorSpan; - index += _vectorSpan; - - if (block == limit.Block && index > limit.Index) - { - _block = block; - // Ensure iterator is left at limit position - _index = limit.Index; - return -1; - } - - continue; - } - - _block = block; - - _index = index + byteIndex; - - if (block == limit.Block && _index > limit.Index) - { - // Ensure iterator is left at limit position - _index = limit.Index; - return -1; - } - - return block.Array[index + byteIndex]; - } -// Need unit tests to test Vector path -#if !DEBUG - } -#endif - var pCurrent = (block.DataFixedPtr + index); - var pEnd = block == limit.Block ? block.DataFixedPtr + limit.Index + 1 : pCurrent + following; - do - { - if (*pCurrent == byte0) - { - _block = block; - _index = index; - return byte0; - } - if (*pCurrent == byte1) - { - _block = block; - _index = index; - return byte1; - } - if (*pCurrent == byte2) - { - _block = block; - _index = index; - return byte2; - } - pCurrent++; - index++; - } while (pCurrent != pEnd); - - following = 0; - break; - } - } - } - - /// - /// Locate the first of the found bytes - /// - /// - /// The first index of the result vector - // Force inlining (64 IL bytes, 91 bytes asm) Issue: https://github.com/dotnet/coreclr/issues/7386 - [MethodImpl(MethodImplOptions.AggressiveInlining)] - internal static int LocateFirstFoundByte(Vector byteEquals) - { - var vector64 = Vector.AsVectorUInt64(byteEquals); - ulong longValue = 0; - var i = 0; - // Pattern unrolled by jit https://github.com/dotnet/coreclr/pull/8001 - for (; i < Vector.Count; i++) - { - longValue = vector64[i]; - if (longValue == 0) continue; - break; - } - - // Flag least significant power of two bit - var powerOfTwoFlag = (longValue ^ (longValue - 1)); - // Shift all powers of two into the high byte and extract - var foundByteIndex = (int)((powerOfTwoFlag * _xorPowerOfTwoToHighByte) >> 57); - // Single LEA instruction with jitted const (using function result) - return i * 8 + foundByteIndex; - } - + /// /// Save the data at the current location then move to the next available space. /// @@ -914,57 +244,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure } } - public MemoryPoolIterator CopyTo(byte[] array, int offset, int count, out int actual) - { - var block = _block; - if (block == null) - { - actual = 0; - return this; - } - - var index = _index; - var remaining = count; - while (true) - { - // Determine if we might attempt to copy data from block.Next before - // calculating "following" so we don't risk skipping data that could - // be added after block.End when we decide to copy from block.Next. - // block.End will always be advanced before block.Next is set. - var wasLastBlock = block.Next == null; - var following = block.End - index; - if (remaining <= following) - { - actual = count; - if (array != null) - { - Buffer.BlockCopy(block.Array, index, array, offset, remaining); - } - return new MemoryPoolIterator(block, index + remaining); - } - else if (wasLastBlock) - { - actual = count - remaining + following; - if (array != null) - { - Buffer.BlockCopy(block.Array, index, array, offset, following); - } - return new MemoryPoolIterator(block, index + following); - } - else - { - if (array != null) - { - Buffer.BlockCopy(block.Array, index, array, offset, following); - } - offset += following; - remaining -= following; - block = block.Next; - index = block.Start; - } - } - } - public void CopyFrom(byte[] data) { CopyFrom(data, 0, data.Length); @@ -1180,177 +459,5 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure CopyFrom(byteBuffer, position, _maxULongByteLength - position); } - - public unsafe string GetAsciiString(ref MemoryPoolIterator end) - { - var block = _block; - if (block == null || end.IsDefault) - { - return null; - } - - var length = GetLength(end); - - if (length == 0) - { - return null; - } - - var inputOffset = _index; - - var asciiString = new string('\0', length); - - fixed (char* outputStart = asciiString) - { - var output = outputStart; - var remaining = length; - - var endBlock = end.Block; - var endIndex = end.Index; - - var outputOffset = 0; - while (true) - { - int following = (block != endBlock ? block.End : endIndex) - inputOffset; - - if (following > 0) - { - if (!AsciiUtilities.TryGetAsciiString(block.DataFixedPtr + inputOffset, output + outputOffset, following)) - { - throw BadHttpRequestException.GetException(RequestRejectionReason.NonAsciiOrNullCharactersInInputString); - } - - outputOffset += following; - remaining -= following; - } - - if (remaining == 0) - { - break; - } - - block = block.Next; - inputOffset = block.Start; - } - } - - return asciiString; - } - - public string GetUtf8String(ref MemoryPoolIterator end) - { - var block = _block; - if (block == null || end.IsDefault) - { - return default(string); - } - - var index = _index; - if (end.Block == block) - { - return Encoding.UTF8.GetString(block.Array, index, end.Index - index); - } - - var decoder = Encoding.UTF8.GetDecoder(); - - var length = GetLength(end); - var charLength = length; - // Worse case is 1 byte = 1 char - var chars = new char[charLength]; - var charIndex = 0; - - var remaining = length; - while (true) - { - int bytesUsed; - int charsUsed; - bool completed; - var following = block.End - index; - if (remaining <= following) - { - decoder.Convert( - block.Array, - index, - remaining, - chars, - charIndex, - charLength - charIndex, - true, - out bytesUsed, - out charsUsed, - out completed); - return new string(chars, 0, charIndex + charsUsed); - } - else if (block.Next == null) - { - decoder.Convert( - block.Array, - index, - following, - chars, - charIndex, - charLength - charIndex, - true, - out bytesUsed, - out charsUsed, - out completed); - return new string(chars, 0, charIndex + charsUsed); - } - else - { - decoder.Convert( - block.Array, - index, - following, - chars, - charIndex, - charLength - charIndex, - false, - out bytesUsed, - out charsUsed, - out completed); - charIndex += charsUsed; - remaining -= following; - block = block.Next; - index = block.Start; - } - } - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ArraySegment GetArraySegment(MemoryPoolIterator end) - { - var block = _block; - if (block == null || end.IsDefault) - { - return default(ArraySegment); - } - - var index = _index; - if (end.Block == block) - { - return new ArraySegment(block.Array, index, end.Index - index); - } - - return GetArraySegmentMultiBlock(ref end); - } - - [MethodImpl(MethodImplOptions.NoInlining)] - private ArraySegment GetArraySegmentMultiBlock(ref MemoryPoolIterator end) - { - var length = GetLength(end); - var array = new byte[length]; - CopyTo(array, 0, length, out length); - return new ArraySegment(array, 0, length); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Vector GetVector(byte vectorByte) - { - // Vector .ctor doesn't become an intrinsic due to detection issue - // However this does cause it to become an intrinsic (with additional multiply and reg->reg copy) - // https://github.com/dotnet/coreclr/issues/7459#issuecomment-253965670 - return Vector.AsVectorByte(new Vector(vectorByte * 0x01010101u)); - } } } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/AsciiDecoding.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/AsciiDecoding.cs index 220ae3d80b..5252a96e9a 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/AsciiDecoding.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/AsciiDecoding.cs @@ -1,6 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; using System.Linq; using Microsoft.AspNetCore.Server.Kestrel; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; @@ -14,27 +15,16 @@ namespace Microsoft.AspNetCore.Server.KestrelTests private void FullAsciiRangeSupported() { var byteRange = Enumerable.Range(1, 127).Select(x => (byte)x).ToArray(); - using (var pool = new MemoryPool()) + var s = new Span(byteRange).GetAsciiStringNonNullCharacters(); + + Assert.Equal(s.Length, byteRange.Length); + + for (var i = 1; i < byteRange.Length; i++) { - var mem = pool.Lease(); - mem.GetIterator().CopyFrom(byteRange); + var sb = (byte)s[i]; + var b = byteRange[i]; - var begin = mem.GetIterator(); - var end = GetIterator(begin, byteRange.Length); - - var s = begin.GetAsciiString(ref end); - - Assert.Equal(s.Length, byteRange.Length); - - for (var i = 1; i < byteRange.Length; i++) - { - var sb = (byte)s[i]; - var b = byteRange[i]; - - Assert.Equal(sb, b); - } - - pool.Return(mem); + Assert.Equal(sb, b); } } @@ -49,123 +39,29 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { var byteRange = Enumerable.Range(1, length).Select(x => (byte)x).ToArray(); byteRange[position] = b; - - using (var pool = new MemoryPool()) - { - var mem = pool.Lease(); - mem.GetIterator().CopyFrom(byteRange); - - var begin = mem.GetIterator(); - var end = GetIterator(begin, byteRange.Length); - - Assert.Throws(() => begin.GetAsciiString(ref end)); - - pool.Return(mem); - } + + Assert.Throws(() => new Span(byteRange).GetAsciiStringNonNullCharacters()); } } } - [Fact] - private void MultiBlockProducesCorrectResults() - { - var byteRange = Enumerable.Range(0, 512 + 64).Select(x => (byte)((x & 0x7f) | 0x01)).ToArray(); - var expectedByteRange = byteRange - .Concat(byteRange) - .Concat(byteRange) - .Concat(byteRange) - .ToArray(); - - using (var pool = new MemoryPool()) - { - var mem0 = pool.Lease(); - var mem1 = pool.Lease(); - var mem2 = pool.Lease(); - var mem3 = pool.Lease(); - mem0.GetIterator().CopyFrom(byteRange); - mem1.GetIterator().CopyFrom(byteRange); - mem2.GetIterator().CopyFrom(byteRange); - mem3.GetIterator().CopyFrom(byteRange); - - mem0.Next = mem1; - mem1.Next = mem2; - mem2.Next = mem3; - - var begin = mem0.GetIterator(); - var end = GetIterator(begin, expectedByteRange.Length); - - var s = begin.GetAsciiString(ref end); - - Assert.Equal(s.Length, expectedByteRange.Length); - - for (var i = 0; i < expectedByteRange.Length; i++) - { - var sb = (byte)((s[i] & 0x7f) | 0x01); - var b = expectedByteRange[i]; - - Assert.Equal(sb, b); - } - - pool.Return(mem0); - pool.Return(mem1); - pool.Return(mem2); - pool.Return(mem3); - } - } - [Fact] private void LargeAllocationProducesCorrectResults() { var byteRange = Enumerable.Range(0, 16384 + 64).Select(x => (byte)((x & 0x7f) | 0x01)).ToArray(); var expectedByteRange = byteRange.Concat(byteRange).ToArray(); - using (var pool = new MemoryPool()) + + var s = new Span(expectedByteRange).GetAsciiStringNonNullCharacters(); + + Assert.Equal(expectedByteRange.Length, s.Length); + + for (var i = 0; i < expectedByteRange.Length; i++) { - var mem0 = pool.Lease(); - var mem1 = pool.Lease(); - mem0.GetIterator().CopyFrom(byteRange); - mem1.GetIterator().CopyFrom(byteRange); + var sb = (byte)((s[i] & 0x7f) | 0x01); + var b = expectedByteRange[i]; - var lastBlock = mem0; - while (lastBlock.Next != null) - { - lastBlock = lastBlock.Next; - } - lastBlock.Next = mem1; - - var begin = mem0.GetIterator(); - var end = GetIterator(begin, expectedByteRange.Length); - - var s = begin.GetAsciiString(ref end); - - Assert.Equal(expectedByteRange.Length, s.Length); - - for (var i = 0; i < expectedByteRange.Length; i++) - { - var sb = (byte)((s[i] & 0x7f) | 0x01); - var b = expectedByteRange[i]; - - Assert.Equal(sb, b); - } - - var block = mem0; - while (block != null) - { - var returnBlock = block; - block = block.Next; - pool.Return(returnBlock); - } + Assert.Equal(sb, b); } } - - private MemoryPoolIterator GetIterator(MemoryPoolIterator begin, int displacement) - { - var result = begin; - for (int i = 0; i < displacement; ++i) - { - result.Take(); - } - - return result; - } } } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolBlockTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolBlockTests.cs index 4cde6c079a..2213f81f07 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolBlockTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolBlockTests.cs @@ -8,105 +8,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { public class MemoryPoolBlockTests { - [Fact] - public void SeekWorks() - { - using (var pool = new MemoryPool()) - { - var block = pool.Lease(); - foreach (var ch in Enumerable.Range(0, 256).Select(x => (byte)x)) - { - block.Array[block.End++] = ch; - } - - var iterator = block.GetIterator(); - foreach (var ch in Enumerable.Range(0, 256).Select(x => (byte)x)) - { - var hit = iterator; - hit.Seek(ch); - Assert.Equal(ch, iterator.GetLength(hit)); - - hit = iterator; - hit.Seek(ch, byte.MaxValue); - Assert.Equal(ch, iterator.GetLength(hit)); - - hit = iterator; - hit.Seek(byte.MaxValue, ch); - Assert.Equal(ch, iterator.GetLength(hit)); - - hit = iterator; - hit.Seek(ch, byte.MaxValue, byte.MaxValue); - Assert.Equal(ch, iterator.GetLength(hit)); - - hit = iterator; - hit.Seek(byte.MaxValue, ch, byte.MaxValue); - Assert.Equal(ch, iterator.GetLength(hit)); - - hit = iterator; - hit.Seek(ch, byte.MaxValue, byte.MaxValue); - Assert.Equal(ch, iterator.GetLength(hit)); - } - - pool.Return(block); - } - } - - [Fact] - public void SeekWorksAcrossBlocks() - { - using (var pool = new MemoryPool()) - { - var block1 = pool.Lease(); - var block2 = block1.Next = pool.Lease(); - var block3 = block2.Next = pool.Lease(); - - foreach (var ch in Enumerable.Range(0, 34).Select(x => (byte)x)) - { - block1.Array[block1.End++] = ch; - } - foreach (var ch in Enumerable.Range(34, 25).Select(x => (byte)x)) - { - block2.Array[block2.End++] = ch; - } - foreach (var ch in Enumerable.Range(59, 197).Select(x => (byte)x)) - { - block3.Array[block3.End++] = ch; - } - - var iterator = block1.GetIterator(); - foreach (var ch in Enumerable.Range(0, 256).Select(x => (byte)x)) - { - var hit = iterator; - hit.Seek(ch); - Assert.Equal(ch, iterator.GetLength(hit)); - - hit = iterator; - hit.Seek(ch, byte.MaxValue); - Assert.Equal(ch, iterator.GetLength(hit)); - - hit = iterator; - hit.Seek(byte.MaxValue, ch); - Assert.Equal(ch, iterator.GetLength(hit)); - - hit = iterator; - hit.Seek(ch, byte.MaxValue, byte.MaxValue); - Assert.Equal(ch, iterator.GetLength(hit)); - - hit = iterator; - hit.Seek(byte.MaxValue, ch, byte.MaxValue); - Assert.Equal(ch, iterator.GetLength(hit)); - - hit = iterator; - hit.Seek(byte.MaxValue, byte.MaxValue, ch); - Assert.Equal(ch, iterator.GetLength(hit)); - } - - pool.Return(block1); - pool.Return(block2); - pool.Return(block3); - } - } - + [Fact] public void GetLengthBetweenIteratorsWorks() { @@ -192,87 +94,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests pool.Return(block2); } } - - [Fact] - public void CopyToCorrectlyTraversesBlocks() - { - using (var pool = new MemoryPool()) - { - var block1 = pool.Lease(); - var block2 = block1.Next = pool.Lease(); - - for (int i = 0; i < 128; i++) - { - block1.Array[block1.End++] = (byte)i; - } - for (int i = 128; i < 256; i++) - { - block2.Array[block2.End++] = (byte)i; - } - - var beginIterator = block1.GetIterator(); - - var array = new byte[256]; - int actual; - var endIterator = beginIterator.CopyTo(array, 0, 256, out actual); - - Assert.Equal(256, actual); - - for (int i = 0; i < 256; i++) - { - Assert.Equal(i, array[i]); - } - - endIterator.CopyTo(array, 0, 256, out actual); - Assert.Equal(0, actual); - - pool.Return(block1); - pool.Return(block2); - } - } - - [Fact] - public void CopyFromCorrectlyTraversesBlocks() - { - using (var pool = new MemoryPool()) - { - var block1 = pool.Lease(); - var start = block1.GetIterator(); - var end = start; - var bufferSize = block1.Data.Count * 3; - var buffer = new byte[bufferSize]; - - for (int i = 0; i < bufferSize; i++) - { - buffer[i] = (byte)(i % 73); - } - - Assert.Null(block1.Next); - - end.CopyFrom(new ArraySegment(buffer)); - - Assert.NotNull(block1.Next); - - for (int i = 0; i < bufferSize; i++) - { - Assert.Equal(i % 73, start.Take()); - } - - Assert.Equal(-1, start.Take()); - Assert.Equal(start.Block, end.Block); - Assert.Equal(start.Index, end.Index); - - var block = block1; - while (block != null) - { - var returnBlock = block; - block = block.Next; - - pool.Return(returnBlock); - } - } - } - + [Fact] public void IsEndCorrectlyTraversesBlocks() { diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolExtensions.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolExtensions.cs index 6348258ce9..1d62dd2793 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolExtensions.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolExtensions.cs @@ -6,8 +6,11 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { public static MemoryPoolIterator Add(this MemoryPoolIterator iterator, int count) { - int actual; - return iterator.CopyTo(new byte[count], 0, count, out actual); + for (int i = 0; i < count; i++) + { + iterator.Take(); + } + return iterator; } } } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolIteratorTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolIteratorTests.cs index 83cf36c4c8..4643b5236b 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolIteratorTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolIteratorTests.cs @@ -30,80 +30,6 @@ namespace Microsoft.AspNetCore.Server.KestrelTests _pool.Dispose(); } - [Fact] - public void TestFindFirstEqualByte() - { - var bytes = Enumerable.Repeat(0xff, Vector.Count).ToArray(); - for (int i = 0; i < Vector.Count; i++) - { - Vector vector = new Vector(bytes); - Assert.Equal(i, MemoryPoolIterator.LocateFirstFoundByte(vector)); - bytes[i] = 0; - } - - for (int i = 0; i < Vector.Count; i++) - { - bytes[i] = 1; - Vector vector = new Vector(bytes); - Assert.Equal(i, MemoryPoolIterator.LocateFirstFoundByte(vector)); - bytes[i] = 0; - } - } - - [Theory] - [InlineData("a", "a", 'a', 0)] - [InlineData("ab", "a", 'a', 0)] - [InlineData("aab", "a", 'a', 0)] - [InlineData("acab", "a", 'a', 0)] - [InlineData("acab", "c", 'c', 1)] - [InlineData("abcdefghijklmnopqrstuvwxyz", "lo", 'l', 11)] - [InlineData("abcdefghijklmnopqrstuvwxyz", "ol", 'l', 11)] - [InlineData("abcdefghijklmnopqrstuvwxyz", "ll", 'l', 11)] - [InlineData("abcdefghijklmnopqrstuvwxyz", "lmr", 'l', 11)] - [InlineData("abcdefghijklmnopqrstuvwxyz", "rml", 'l', 11)] - [InlineData("abcdefghijklmnopqrstuvwxyz", "mlr", 'l', 11)] - [InlineData("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz", "lmr", 'l', 11)] - [InlineData("aaaaaaaaaaalmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz", "lmr", 'l', 11)] - [InlineData("aaaaaaaaaaacmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz", "lmr", 'm', 12)] - [InlineData("aaaaaaaaaaarmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz", "lmr", 'r', 11)] - [InlineData("/localhost:5000/PATH/%2FPATH2/ HTTP/1.1", " %?", '%', 21)] - [InlineData("/localhost:5000/PATH/%2FPATH2/?key=value HTTP/1.1", " %?", '%', 21)] - [InlineData("/localhost:5000/PATH/PATH2/?key=value HTTP/1.1", " %?", '?', 27)] - [InlineData("/localhost:5000/PATH/PATH2/ HTTP/1.1", " %?", ' ', 27)] - public void MemorySeek(string raw, string search, char expectResult, int expectIndex) - { - var block = _pool.Lease(); - var chars = raw.ToCharArray().Select(c => (byte)c).ToArray(); - Buffer.BlockCopy(chars, 0, block.Array, block.Start, chars.Length); - block.End += chars.Length; - - var begin = block.GetIterator(); - var searchFor = search.ToCharArray(); - - int found = -1; - if (searchFor.Length == 1) - { - found = begin.Seek((byte)searchFor[0]); - } - else if (searchFor.Length == 2) - { - found = begin.Seek((byte)searchFor[0], (byte)searchFor[1]); - } - else if (searchFor.Length == 3) - { - found = begin.Seek((byte)searchFor[0], (byte)searchFor[1], (byte)searchFor[2]); - } - else - { - Assert.False(true, "Invalid test sample."); - } - - Assert.Equal(expectResult, found); - Assert.Equal(expectIndex, begin.Index - block.Start); - - _pool.Return(block); - } - [Fact] public void Put() { @@ -241,728 +167,20 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } - [Fact] - public void PeekLong() - { - // Arrange - var block = _pool.Lease(); - var bytes = BitConverter.GetBytes(0x0102030405060708UL); - Buffer.BlockCopy(bytes, 0, block.Array, block.Start, bytes.Length); - block.End += bytes.Length; - var scan = block.GetIterator(); - var originalIndex = scan.Index; - - // Assert - ulong result; - Assert.True(scan.TryPeekLong(out result)); - Assert.Equal(0x0102030405060708UL, result); - Assert.Equal(originalIndex, scan.Index); - - _pool.Return(block); - } - - [Theory] - [InlineData(0)] - [InlineData(1)] - [InlineData(2)] - [InlineData(3)] - [InlineData(4)] - [InlineData(5)] - [InlineData(6)] - [InlineData(7)] - public void PeekLongNotEnoughBytes(int totalBytes) - { - // Arrange - var block = _pool.Lease(); - var bytes = BitConverter.GetBytes(0x0102030405060708UL); - var bytesLength = totalBytes; - Buffer.BlockCopy(bytes, 0, block.Array, block.Start, bytesLength); - block.End += bytesLength; - var scan = block.GetIterator(); - var originalIndex = scan.Index; - - // Assert - ulong result; - Assert.False(scan.TryPeekLong(out result)); - Assert.Equal(originalIndex, scan.Index); - _pool.Return(block); - } - - [Theory] - [InlineData(0)] - [InlineData(1)] - [InlineData(2)] - [InlineData(3)] - [InlineData(4)] - [InlineData(5)] - [InlineData(6)] - [InlineData(7)] - public void PeekLongNotEnoughBytesAtBlockBoundary(int firstBlockBytes) - { - // Arrange - var expectedResult = 0x0102030405060708UL; - var nextBlockBytes = 7 - firstBlockBytes; - - var block = _pool.Lease(); - block.End += firstBlockBytes; - - var nextBlock = _pool.Lease(); - nextBlock.End += nextBlockBytes; - - block.Next = nextBlock; - - var bytes = BitConverter.GetBytes(expectedResult); - Buffer.BlockCopy(bytes, 0, block.Array, block.Start, firstBlockBytes); - Buffer.BlockCopy(bytes, firstBlockBytes, nextBlock.Array, nextBlock.Start, nextBlockBytes); - - var scan = block.GetIterator(); - var originalIndex = scan.Index; - - // Assert - ulong result; - Assert.False(scan.TryPeekLong(out result)); - Assert.Equal(originalIndex, scan.Index); - - _pool.Return(block); - _pool.Return(nextBlock); - } - - [Theory] - [InlineData(0)] - [InlineData(1)] - [InlineData(2)] - [InlineData(3)] - [InlineData(4)] - [InlineData(5)] - [InlineData(6)] - [InlineData(7)] - [InlineData(8)] - public void PeekLongAtBlockBoundary(int firstBlockBytes) - { - // Arrange - var expectedResult = 0x0102030405060708UL; - var nonZeroData = 0xFF00FFFF0000FFFFUL; - var nextBlockBytes = 8 - firstBlockBytes; - - var block = _pool.Lease(); - block.Start += 8; - block.End = block.Start + firstBlockBytes; - - var nextBlock = _pool.Lease(); - nextBlock.Start += 8; - nextBlock.End = nextBlock.Start + nextBlockBytes; - - block.Next = nextBlock; - - var bytes = BitConverter.GetBytes(expectedResult); - Buffer.BlockCopy(bytes, 0, block.Array, block.Start, firstBlockBytes); - Buffer.BlockCopy(bytes, firstBlockBytes, nextBlock.Array, nextBlock.Start, nextBlockBytes); - - // Fill in surrounding bytes with non-zero data - var nonZeroBytes = BitConverter.GetBytes(nonZeroData); - Buffer.BlockCopy(nonZeroBytes, 0, block.Array, block.Start - 8, 8); - Buffer.BlockCopy(nonZeroBytes, 0, block.Array, block.End, 8); - Buffer.BlockCopy(nonZeroBytes, 0, nextBlock.Array, nextBlock.Start - 8, 8); - Buffer.BlockCopy(nonZeroBytes, 0, nextBlock.Array, nextBlock.End, 8); - - var scan = block.GetIterator(); - var originalIndex = scan.Index; - - // Assert - ulong result; - Assert.True(scan.TryPeekLong(out result)); - Assert.Equal(expectedResult, result); - Assert.Equal(originalIndex, scan.Index); - - _pool.Return(block); - _pool.Return(nextBlock); - } - - [Theory] - [InlineData(0)] - [InlineData(1)] - [InlineData(2)] - [InlineData(3)] - [InlineData(4)] - [InlineData(5)] - [InlineData(6)] - [InlineData(7)] - [InlineData(8)] - public void PeekLongAtBlockBoundarayWithMostSignificatBitsSet(int firstBlockBytes) - { - // Arrange - var expectedResult = 0xFF02030405060708UL; - var nonZeroData = 0xFF00FFFF0000FFFFUL; - var nextBlockBytes = 8 - firstBlockBytes; - - var block = _pool.Lease(); - block.Start += 8; - block.End = block.Start + firstBlockBytes; - - var nextBlock = _pool.Lease(); - nextBlock.Start += 8; - nextBlock.End = nextBlock.Start + nextBlockBytes; - - block.Next = nextBlock; - - var expectedBytes = BitConverter.GetBytes(expectedResult); - Buffer.BlockCopy(expectedBytes, 0, block.Array, block.Start, firstBlockBytes); - Buffer.BlockCopy(expectedBytes, firstBlockBytes, nextBlock.Array, nextBlock.Start, nextBlockBytes); - - // Fill in surrounding bytes with non-zero data - var nonZeroBytes = BitConverter.GetBytes(nonZeroData); - Buffer.BlockCopy(nonZeroBytes, 0, block.Array, block.Start - 8, 8); - Buffer.BlockCopy(nonZeroBytes, 0, block.Array, block.End, 8); - Buffer.BlockCopy(nonZeroBytes, 0, nextBlock.Array, nextBlock.Start - 8, 8); - Buffer.BlockCopy(nonZeroBytes, 0, nextBlock.Array, nextBlock.End, 8); - - var scan = block.GetIterator(); - var originalIndex = scan.Index; - - // Assert - ulong result; - Assert.True(scan.TryPeekLong(out result)); - Assert.Equal(expectedResult, result); - Assert.Equal(originalIndex, scan.Index); - - _pool.Return(block); - _pool.Return(nextBlock); - } - - [Theory] - [InlineData(0)] - [InlineData(1)] - [InlineData(2)] - [InlineData(3)] - [InlineData(4)] - [InlineData(5)] - [InlineData(6)] - [InlineData(7)] - [InlineData(8)] - [InlineData(9)] - public void SkipAtBlockBoundary(int blockBytes) - { - // Arrange - var nextBlockBytes = 10 - blockBytes; - - var block = _pool.Lease(); - block.End += blockBytes; - - var nextBlock = _pool.Lease(); - nextBlock.End += nextBlockBytes; - - block.Next = nextBlock; - - var bytes = new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; - Buffer.BlockCopy(bytes, 0, block.Array, block.Start, blockBytes); - Buffer.BlockCopy(bytes, blockBytes, nextBlock.Array, nextBlock.Start, nextBlockBytes); - - var scan = block.GetIterator(); - var originalIndex = scan.Index; - - // Act - scan.Skip(8); - var result = scan.Take(); - - // Assert - Assert.Equal(0x08, result); - Assert.NotEqual(originalIndex, scan.Index); - - _pool.Return(block); - _pool.Return(nextBlock); - } - - [Fact] - public void SkipThrowsWhenSkippingMoreBytesThanAvailableInSingleBlock() - { - // Arrange - var block = _pool.Lease(); - block.End += 5; - - var scan = block.GetIterator(); - - // Act/Assert - Assert.ThrowsAny(() => scan.Skip(8)); - - _pool.Return(block); - } - - [Fact] - public void SkipThrowsWhenSkippingMoreBytesThanAvailableInMultipleBlocks() - { - // Arrange - var firstBlock = _pool.Lease(); - firstBlock.End += 3; - - var middleBlock = _pool.Lease(); - middleBlock.End += 1; - firstBlock.Next = middleBlock; - - var finalBlock = _pool.Lease(); - finalBlock.End += 2; - middleBlock.Next = finalBlock; - - var scan = firstBlock.GetIterator(); - - // Act/Assert - Assert.ThrowsAny(() => scan.Skip(8)); - - _pool.Return(firstBlock); - _pool.Return(middleBlock); - _pool.Return(finalBlock); - } - - - [Theory] - [MemberData(nameof(SeekByteLimitData))] - public void TestSeekByteLimitWithinSameBlock(string input, char seek, int limit, int expectedBytesScanned, int expectedReturnValue) - { - MemoryPoolBlock block = null; - - try - { - // Arrange - - block = _pool.Lease(); - var chars = input.ToString().ToCharArray().Select(c => (byte) c).ToArray(); - Buffer.BlockCopy(chars, 0, block.Array, block.Start, chars.Length); - block.End += chars.Length; - var scan = block.GetIterator(); - - // Act - int bytesScanned; - var returnValue = scan.Seek((byte)seek, out bytesScanned, limit); - - // Assert - Assert.Equal(expectedBytesScanned, bytesScanned); - Assert.Equal(expectedReturnValue, returnValue); - - Assert.Same(block, scan.Block); - var expectedEndIndex = expectedReturnValue != -1 ? - block.Start + input.IndexOf(seek) : - block.Start + expectedBytesScanned; - Assert.Equal(expectedEndIndex, scan.Index); - } - finally - { - // Cleanup - if (block != null) _pool.Return(block); - } - } - - [Theory] - [MemberData(nameof(SeekByteLimitData))] - public void TestSeekByteLimitAcrossBlocks(string input, char seek, int limit, int expectedBytesScanned, int expectedReturnValue) - { - MemoryPoolBlock block1 = null; - MemoryPoolBlock block2 = null; - MemoryPoolBlock emptyBlock = null; - - try - { - // Arrange - var input1 = input.Substring(0, input.Length / 2); - block1 = _pool.Lease(); - var chars1 = input1.ToCharArray().Select(c => (byte)c).ToArray(); - Buffer.BlockCopy(chars1, 0, block1.Array, block1.Start, chars1.Length); - block1.End += chars1.Length; - - emptyBlock = _pool.Lease(); - block1.Next = emptyBlock; - - var input2 = input.Substring(input.Length / 2); - block2 = _pool.Lease(); - var chars2 = input2.ToCharArray().Select(c => (byte)c).ToArray(); - Buffer.BlockCopy(chars2, 0, block2.Array, block2.Start, chars2.Length); - block2.End += chars2.Length; - emptyBlock.Next = block2; - - var scan = block1.GetIterator(); - - // Act - int bytesScanned; - var returnValue = scan.Seek((byte)seek, out bytesScanned, limit); - - // Assert - Assert.Equal(expectedBytesScanned, bytesScanned); - Assert.Equal(expectedReturnValue, returnValue); - - var seekCharIndex = input.IndexOf(seek); - var expectedEndBlock = limit <= input.Length / 2 ? - block1 : - (seekCharIndex != -1 && seekCharIndex < input.Length / 2 ? block1 : block2); - Assert.Same(expectedEndBlock, scan.Block); - var expectedEndIndex = expectedReturnValue != -1 ? - expectedEndBlock.Start + (expectedEndBlock == block1 ? input1.IndexOf(seek) : input2.IndexOf(seek)) : - expectedEndBlock.Start + (expectedEndBlock == block1 ? expectedBytesScanned : expectedBytesScanned - (input.Length / 2)); - Assert.Equal(expectedEndIndex, scan.Index); - } - finally - { - // Cleanup - if (block1 != null) _pool.Return(block1); - if (emptyBlock != null) _pool.Return(emptyBlock); - if (block2 != null) _pool.Return(block2); - } - } - - [Theory] - [MemberData(nameof(SeekIteratorLimitData))] - public void TestSeekIteratorLimitWithinSameBlock(string input, char seek, char limitAt, int expectedReturnValue) - { - MemoryPoolBlock block = null; - - try - { - // Arrange - var afterSeek = (byte)'B'; - - block = _pool.Lease(); - var chars = input.ToCharArray().Select(c => (byte)c).ToArray(); - Buffer.BlockCopy(chars, 0, block.Array, block.Start, chars.Length); - block.End += chars.Length; - var scan1 = block.GetIterator(); - var scan2_1 = scan1; - var scan2_2 = scan1; - var scan3_1 = scan1; - var scan3_2 = scan1; - var scan3_3 = scan1; - var end = scan1; - - // Act - var endReturnValue = end.Seek((byte)limitAt); - var returnValue1 = scan1.Seek((byte)seek, ref end); - var returnValue2_1 = scan2_1.Seek((byte)seek, afterSeek, ref end); - var returnValue2_2 = scan2_2.Seek(afterSeek, (byte)seek, ref end); - var returnValue3_1 = scan3_1.Seek((byte)seek, afterSeek, afterSeek, ref end); - var returnValue3_2 = scan3_2.Seek(afterSeek, (byte)seek, afterSeek, ref end); - var returnValue3_3 = scan3_3.Seek(afterSeek, afterSeek, (byte)seek, ref end); - - // Assert - Assert.Equal(input.Contains(limitAt) ? limitAt : -1, endReturnValue); - Assert.Equal(expectedReturnValue, returnValue1); - Assert.Equal(expectedReturnValue, returnValue2_1); - Assert.Equal(expectedReturnValue, returnValue2_2); - Assert.Equal(expectedReturnValue, returnValue3_1); - Assert.Equal(expectedReturnValue, returnValue3_2); - Assert.Equal(expectedReturnValue, returnValue3_3); - - Assert.Same(block, scan1.Block); - Assert.Same(block, scan2_1.Block); - Assert.Same(block, scan2_2.Block); - Assert.Same(block, scan3_1.Block); - Assert.Same(block, scan3_2.Block); - Assert.Same(block, scan3_3.Block); - - var expectedEndIndex = expectedReturnValue != -1 ? block.Start + input.IndexOf(seek) : end.Index; - Assert.Equal(expectedEndIndex, scan1.Index); - Assert.Equal(expectedEndIndex, scan2_1.Index); - Assert.Equal(expectedEndIndex, scan2_2.Index); - Assert.Equal(expectedEndIndex, scan3_1.Index); - Assert.Equal(expectedEndIndex, scan3_2.Index); - Assert.Equal(expectedEndIndex, scan3_3.Index); - } - finally - { - // Cleanup - if (block != null) _pool.Return(block); - } - } - - [Theory] - [MemberData(nameof(SeekIteratorLimitData))] - public void TestSeekIteratorLimitAcrossBlocks(string input, char seek, char limitAt, int expectedReturnValue) - { - MemoryPoolBlock block1 = null; - MemoryPoolBlock block2 = null; - MemoryPoolBlock emptyBlock = null; - - try - { - // Arrange - var afterSeek = (byte)'B'; - - var input1 = input.Substring(0, input.Length / 2); - block1 = _pool.Lease(); - var chars1 = input1.ToCharArray().Select(c => (byte)c).ToArray(); - Buffer.BlockCopy(chars1, 0, block1.Array, block1.Start, chars1.Length); - block1.End += chars1.Length; - - emptyBlock = _pool.Lease(); - block1.Next = emptyBlock; - - var input2 = input.Substring(input.Length / 2); - block2 = _pool.Lease(); - var chars2 = input2.ToCharArray().Select(c => (byte)c).ToArray(); - Buffer.BlockCopy(chars2, 0, block2.Array, block2.Start, chars2.Length); - block2.End += chars2.Length; - emptyBlock.Next = block2; - - var scan1 = block1.GetIterator(); - var scan2_1 = scan1; - var scan2_2 = scan1; - var scan3_1 = scan1; - var scan3_2 = scan1; - var scan3_3 = scan1; - var end = scan1; - - // Act - var endReturnValue = end.Seek((byte)limitAt); - var returnValue1 = scan1.Seek((byte)seek, ref end); - var returnValue2_1 = scan2_1.Seek((byte)seek, afterSeek, ref end); - var returnValue2_2 = scan2_2.Seek(afterSeek, (byte)seek, ref end); - var returnValue3_1 = scan3_1.Seek((byte)seek, afterSeek, afterSeek, ref end); - var returnValue3_2 = scan3_2.Seek(afterSeek, (byte)seek, afterSeek, ref end); - var returnValue3_3 = scan3_3.Seek(afterSeek, afterSeek, (byte)seek, ref end); - - // Assert - Assert.Equal(input.Contains(limitAt) ? limitAt : -1, endReturnValue); - Assert.Equal(expectedReturnValue, returnValue1); - Assert.Equal(expectedReturnValue, returnValue2_1); - Assert.Equal(expectedReturnValue, returnValue2_2); - Assert.Equal(expectedReturnValue, returnValue3_1); - Assert.Equal(expectedReturnValue, returnValue3_2); - Assert.Equal(expectedReturnValue, returnValue3_3); - - var seekCharIndex = input.IndexOf(seek); - var limitAtIndex = input.IndexOf(limitAt); - var expectedEndBlock = seekCharIndex != -1 && seekCharIndex < input.Length / 2 ? - block1 : - (limitAtIndex != -1 && limitAtIndex < input.Length / 2 ? block1 : block2); - Assert.Same(expectedEndBlock, scan1.Block); - Assert.Same(expectedEndBlock, scan2_1.Block); - Assert.Same(expectedEndBlock, scan2_2.Block); - Assert.Same(expectedEndBlock, scan3_1.Block); - Assert.Same(expectedEndBlock, scan3_2.Block); - Assert.Same(expectedEndBlock, scan3_3.Block); - - var expectedEndIndex = expectedReturnValue != -1 ? - expectedEndBlock.Start + (expectedEndBlock == block1 ? input1.IndexOf(seek) : input2.IndexOf(seek)) : - end.Index; - Assert.Equal(expectedEndIndex, scan1.Index); - Assert.Equal(expectedEndIndex, scan2_1.Index); - Assert.Equal(expectedEndIndex, scan2_2.Index); - Assert.Equal(expectedEndIndex, scan3_1.Index); - Assert.Equal(expectedEndIndex, scan3_2.Index); - Assert.Equal(expectedEndIndex, scan3_3.Index); - } - finally - { - // Cleanup - if (block1 != null) _pool.Return(block1); - if (emptyBlock != null) _pool.Return(emptyBlock); - if (block2 != null) _pool.Return(block2); - } - } [Fact] public void EmptyIteratorBehaviourIsValid() { const byte byteCr = (byte)'\n'; - ulong longValue; var end = default(MemoryPoolIterator); - - Assert.False(default(MemoryPoolIterator).TryPeekLong(out longValue)); - Assert.Null(default(MemoryPoolIterator).GetAsciiString(ref end)); - Assert.Null(default(MemoryPoolIterator).GetUtf8String(ref end)); - // Assert.Equal doesn't work for default(ArraySegments) - Assert.True(default(MemoryPoolIterator).GetArraySegment(end).Equals(default(ArraySegment))); + Assert.True(default(MemoryPoolIterator).IsDefault); Assert.True(default(MemoryPoolIterator).IsEnd); - Assert.Equal(default(MemoryPoolIterator).Take(), -1); - Assert.Equal(default(MemoryPoolIterator).Peek(), -1); - Assert.Equal(default(MemoryPoolIterator).Seek(byteCr), -1); - Assert.Equal(default(MemoryPoolIterator).Seek(byteCr, ref end), -1); - Assert.Equal(default(MemoryPoolIterator).Seek(byteCr, byteCr), -1); - Assert.Equal(default(MemoryPoolIterator).Seek(byteCr, byteCr, byteCr), -1); default(MemoryPoolIterator).CopyFrom(default(ArraySegment)); default(MemoryPoolIterator).CopyFromAscii(""); Assert.ThrowsAny(() => default(MemoryPoolIterator).Put(byteCr)); Assert.ThrowsAny(() => default(MemoryPoolIterator).GetLength(end)); - Assert.ThrowsAny(() => default(MemoryPoolIterator).Skip(1)); - } - - [Fact] - public void TestGetArraySegment() - { - MemoryPoolBlock block0 = null; - MemoryPoolBlock block1 = null; - - var byteRange = Enumerable.Range(1, 127).Select(x => (byte)x).ToArray(); - try - { - // Arrange - block0 = _pool.Lease(); - block1 = _pool.Lease(); - - block0.GetIterator().CopyFrom(byteRange); - block1.GetIterator().CopyFrom(byteRange); - - block0.Next = block1; - - var begin = block0.GetIterator(); - var end0 = begin; - var end1 = begin; - - end0.Skip(byteRange.Length); - end1.Skip(byteRange.Length * 2); - - // Act - var as0 = begin.GetArraySegment(end0); - var as1 = begin.GetArraySegment(end1); - - // Assert - Assert.Equal(as0.Count, byteRange.Length); - Assert.Equal(as1.Count, byteRange.Length * 2); - - for (var i = 1; i < byteRange.Length; i++) - { - var asb0 = as0.Array[i + as0.Offset]; - var asb1 = as1.Array[i + as1.Offset]; - var b = byteRange[i]; - - Assert.Equal(asb0, b); - Assert.Equal(asb1, b); - } - - for (var i = 1 + byteRange.Length; i < byteRange.Length * 2; i++) - { - var asb1 = as1.Array[i + as1.Offset]; - var b = byteRange[i - byteRange.Length]; - - Assert.Equal(asb1, b); - } - - } - finally - { - if (block0 != null) _pool.Return(block0); - if (block1 != null) _pool.Return(block1); - } - } - - [Fact] - public void TestTake() - { - MemoryPoolBlock block0 = null; - MemoryPoolBlock block1 = null; - MemoryPoolBlock block2 = null; - MemoryPoolBlock emptyBlock0 = null; - MemoryPoolBlock emptyBlock1 = null; - - var byteRange = Enumerable.Range(1, 127).Select(x => (byte)x).ToArray(); - try - { - // Arrange - block0 = _pool.Lease(); - block1 = _pool.Lease(); - block2 = _pool.Lease(); - emptyBlock0 = _pool.Lease(); - emptyBlock1 = _pool.Lease(); - - block0.GetIterator().CopyFrom(byteRange); - block1.GetIterator().CopyFrom(byteRange); - block2.GetIterator().CopyFrom(byteRange); - - var begin = block0.GetIterator(); - - // Single block - for (var i = 0; i < byteRange.Length; i++) - { - var t = begin.Take(); - var b = byteRange[i]; - - Assert.Equal(t, b); - } - - Assert.Equal(begin.Take(), -1); - - // Dual block - block0.Next = block1; - begin = block0.GetIterator(); - - for (var block = 0; block < 2; block++) - { - for (var i = 0; i < byteRange.Length; i++) - { - var t = begin.Take(); - var b = byteRange[i]; - - Assert.Equal(t, b); - } - } - - Assert.Equal(begin.Take(), -1); - - // Multi block - block1.Next = emptyBlock0; - emptyBlock0.Next = emptyBlock1; - emptyBlock1.Next = block2; - begin = block0.GetIterator(); - - for (var block = 0; block < 3; block++) - { - for (var i = 0; i < byteRange.Length; i++) - { - var t = begin.Take(); - var b = byteRange[i]; - - Assert.Equal(t, b); - } - } - - Assert.Equal(begin.Take(), -1); - } - finally - { - if (block0 != null) _pool.Return(block0); - if (block1 != null) _pool.Return(block1); - if (block2 != null) _pool.Return(block2); - if (emptyBlock0 != null) _pool.Return(emptyBlock0); - if (emptyBlock1 != null) _pool.Return(emptyBlock1); - } - } - - [Fact] - public void TestTakeEmptyBlocks() - { - MemoryPoolBlock emptyBlock0 = null; - MemoryPoolBlock emptyBlock1 = null; - MemoryPoolBlock emptyBlock2 = null; - try - { - // Arrange - emptyBlock0 = _pool.Lease(); - emptyBlock1 = _pool.Lease(); - emptyBlock2 = _pool.Lease(); - - var beginEmpty = emptyBlock0.GetIterator(); - - // Assert - - // No blocks - Assert.Equal(default(MemoryPoolIterator).Take(), -1); - - // Single empty block - Assert.Equal(beginEmpty.Take(), -1); - - // Dual empty block - emptyBlock0.Next = emptyBlock1; - beginEmpty = emptyBlock0.GetIterator(); - Assert.Equal(beginEmpty.Take(), -1); - - // Multi empty block - emptyBlock1.Next = emptyBlock2; - beginEmpty = emptyBlock0.GetIterator(); - Assert.Equal(beginEmpty.Take(), -1); - } - finally - { - if (emptyBlock0 != null) _pool.Return(emptyBlock0); - if (emptyBlock1 != null) _pool.Return(emptyBlock1); - if (emptyBlock2 != null) _pool.Return(emptyBlock2); - } } [Theory] @@ -973,23 +191,14 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [InlineData("abcde", "abcde", 6)] public void TestGetAsciiStringEscaped(string input, string expected, int maxChars) { - MemoryPoolBlock block = null; - - try - { // Arrange - var buffer = new Span(Encoding.ASCII.GetBytes(input)); + var buffer = new Span(Encoding.ASCII.GetBytes(input)); - // Act - var result = buffer.GetAsciiStringEscaped(maxChars); + // Act + var result = buffer.GetAsciiStringEscaped(maxChars); - // Assert - Assert.Equal(expected, result); - } - finally - { - if (block != null) _pool.Return(block); - } + // Assert + Assert.Equal(expected, result); } [Fact] diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/UrlPathDecoder.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/UrlPathDecoder.cs deleted file mode 100644 index 0acfc27fe8..0000000000 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/UrlPathDecoder.cs +++ /dev/null @@ -1,226 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using System.Linq; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; -using Xunit; - -namespace Microsoft.AspNetCore.Server.KestrelTests -{ - public class UrlPathDecoderTests - { - [Fact] - public void Empty() - { - using (var pool = new MemoryPool()) - { - var mem = pool.Lease(); - - PositiveAssert(mem, string.Empty, string.Empty); - - pool.Return(mem); - } - } - - [Fact] - public void WhiteSpace() - { - using (var pool = new MemoryPool()) - { - var mem = pool.Lease(); - - PositiveAssert(mem, " ", " "); - - pool.Return(mem); - } - } - - [Theory] - [InlineData("/foo/bar", "/foo/bar")] - [InlineData("/foo/BAR", "/foo/BAR")] - [InlineData("/foo/", "/foo/")] - [InlineData("/", "/")] - public void NormalCases(string raw, string expect) - { - using (var pool = new MemoryPool()) - { - var mem = pool.Lease(); - - PositiveAssert(mem, raw, expect); - - pool.Return(mem); - } - } - - [Theory] - [InlineData("%2F", "%2F")] - [InlineData("/foo%2Fbar", "/foo%2Fbar")] - [InlineData("/foo%2F%20bar", "/foo%2F bar")] - public void SkipForwardSlash(string raw, string expect) - { - using (var pool = new MemoryPool()) - { - var mem = pool.Lease(); - - PositiveAssert(mem, raw, expect); - - pool.Return(mem); - } - } - - [Theory] - [InlineData("%D0%A4", "Ф")] - [InlineData("%d0%a4", "Ф")] - [InlineData("%E0%A4%AD", "भ")] - [InlineData("%e0%A4%Ad", "भ")] - [InlineData("%F0%A4%AD%A2", "𤭢")] - [InlineData("%F0%a4%Ad%a2", "𤭢")] - [InlineData("%48%65%6C%6C%6F%20%57%6F%72%6C%64", "Hello World")] - [InlineData("%48%65%6C%6C%6F%2D%C2%B5%40%C3%9F%C3%B6%C3%A4%C3%BC%C3%A0%C3%A1", "Hello-µ@ßöäüàá")] - // Test the borderline cases of overlong UTF8. - [InlineData("%C2%80", "\u0080")] - [InlineData("%E0%A0%80", "\u0800")] - [InlineData("%F0%90%80%80", "\U00010000")] - [InlineData("%63", "c")] - [InlineData("%32", "2")] - [InlineData("%20", " ")] - public void ValidUTF8(string raw, string expect) - { - using (var pool = new MemoryPool()) - { - var mem = pool.Lease(); - - PositiveAssert(mem, raw, expect); - - pool.Return(mem); - } - } - - [Theory] - [InlineData("%C3%84ra%20Benetton", "Ära Benetton")] - [InlineData("%E6%88%91%E8%87%AA%E6%A8%AA%E5%88%80%E5%90%91%E5%A4%A9%E7%AC%91%E5%8E%BB%E7%95%99%E8%82%9D%E8%83%86%E4%B8%A4%E6%98%86%E4%BB%91", "我自横刀向天笑去留肝胆两昆仑")] - public void Internationalized(string raw, string expect) - { - using (var pool = new MemoryPool()) - { - var mem = pool.Lease(); - - PositiveAssert(mem, raw, expect); - - pool.Return(mem); - } - } - - [Theory] - // Overlong ASCII - [InlineData("%C0%A4", "%C0%A4")] - [InlineData("%C1%BF", "%C1%BF")] - [InlineData("%E0%80%AF", "%E0%80%AF")] - [InlineData("%E0%9F%BF", "%E0%9F%BF")] - [InlineData("%F0%80%80%AF", "%F0%80%80%AF")] - [InlineData("%F0%8F%8F%BF", "%F0%8F%8F%BF")] - // Incomplete - [InlineData("%", "%")] - [InlineData("%%", "%%")] - [InlineData("%A", "%A")] - [InlineData("%Y", "%Y")] - // Mixed - [InlineData("%%32", "%2")] - [InlineData("%%20", "% ")] - [InlineData("%C0%A4%32", "%C0%A42")] - [InlineData("%32%C0%A4%32", "2%C0%A42")] - [InlineData("%C0%32%A4", "%C02%A4")] - public void InvalidUTF8(string raw, string expect) - { - using (var pool = new MemoryPool()) - { - var mem = pool.Lease(); - - PositiveAssert(mem, raw, expect); - - pool.Return(mem); - } - } - - [Theory] - [InlineData("/foo%2Fbar", 10, "/foo%2Fbar", 10)] - [InlineData("/foo%2Fbar", 9, "/foo%2Fba", 9)] - [InlineData("/foo%2Fbar", 8, "/foo%2Fb", 8)] - [InlineData("%D0%A4", 6, "Ф", 1)] - [InlineData("%D0%A4", 5, "%D0%A", 5)] - [InlineData("%D0%A4", 4, "%D0%", 4)] - [InlineData("%D0%A4", 3, "%D0", 3)] - [InlineData("%D0%A4", 2, "%D", 2)] - [InlineData("%D0%A4", 1, "%", 1)] - [InlineData("%D0%A4", 0, "", 0)] - [InlineData("%C2%B5%40%C3%9F%C3%B6%C3%A4%C3%BC%C3%A0%C3%A1", 45, "µ@ßöäüàá", 8)] - [InlineData("%C2%B5%40%C3%9F%C3%B6%C3%A4%C3%BC%C3%A0%C3%A1", 44, "µ@ßöäüà%C3%A", 12)] - public void DecodeWithBoundary(string raw, int rawLength, string expect, int expectLength) - { - using (var pool = new MemoryPool()) - { - var mem = pool.Lease(); - - var begin = BuildSample(mem, raw); - var end = GetIterator(begin, rawLength); - - var end2 = UrlPathDecoder.Unescape(begin, end); - var result = begin.GetUtf8String(ref end2); - - Assert.Equal(expectLength, result.Length); - Assert.Equal(expect, result); - - pool.Return(mem); - } - } - - private MemoryPoolIterator BuildSample(MemoryPoolBlock mem, string data) - { - var store = data.Select(c => (byte)c).ToArray(); - mem.GetIterator().CopyFrom(new ArraySegment(store)); - - return mem.GetIterator(); - } - - private MemoryPoolIterator GetIterator(MemoryPoolIterator begin, int displacement) - { - var result = begin; - for (int i = 0; i < displacement; ++i) - { - result.Take(); - } - - return result; - } - - private void PositiveAssert(MemoryPoolBlock mem, string raw, string expect) - { - var begin = BuildSample(mem, raw); - var end = GetIterator(begin, raw.Length); - - var result = UrlPathDecoder.Unescape(begin, end); - Assert.Equal(expect, begin.GetUtf8String(ref result)); - } - - private void PositiveAssert(MemoryPoolBlock mem, string raw) - { - var begin = BuildSample(mem, raw); - var end = GetIterator(begin, raw.Length); - - var result = UrlPathDecoder.Unescape(begin, end); - Assert.NotEqual(raw.Length, begin.GetUtf8String(ref result).Length); - } - - private void NegativeAssert(MemoryPoolBlock mem, string raw) - { - var begin = BuildSample(mem, raw); - var end = GetIterator(begin, raw.Length); - - var resultEnd = UrlPathDecoder.Unescape(begin, end); - var result = begin.GetUtf8String(ref resultEnd); - Assert.Equal(raw, result); - } - } -} From e2f8c226efbb8008a342e1b3a12badeb77b7a86d Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Tue, 7 Mar 2017 21:30:57 +0000 Subject: [PATCH 1098/1662] Simplify TakeSingleHeader and Vectorize (#1457) * Sanitize unsafe code * Vectorize * Extract Contains and add more tests --- .../Internal/Http/KestrelHttpParser.cs | 175 ++++++++++-------- test/shared/HttpParsingData.cs | 19 ++ 2 files changed, 113 insertions(+), 81 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/KestrelHttpParser.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/KestrelHttpParser.cs index f85af592fb..d8da5a89bc 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/KestrelHttpParser.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/KestrelHttpParser.cs @@ -4,6 +4,7 @@ using System; using System.Buffers; using System.IO.Pipelines; +using System.Numerics; using System.Runtime.CompilerServices; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.Extensions.Logging; @@ -389,128 +390,126 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } [MethodImpl(MethodImplOptions.AggressiveInlining)] - private unsafe int IndexOfNameEnd(byte* pBuffer, int index, int length) + private static unsafe int FindEndOfName(byte* headerLine, int length) { - var pCurrent = pBuffer + index; - var pEnd = pBuffer + index + length; - var result = -1; + var index = 0; var sawWhitespace = false; - - while (pCurrent < pEnd) + for (; index < length; index++) { - var ch = *pCurrent; + var ch = headerLine[index]; if (ch == ByteColon) { - if (sawWhitespace) - { - RejectRequest(RequestRejectionReason.WhitespaceIsNotAllowedInHeaderName); - } - - result = index; break; } - - if (ch == ByteTab || ch == ByteSpace) + if (ch == ByteTab || ch == ByteSpace || ch == ByteCR) { sawWhitespace = true; } - - index++; - pCurrent++; } - return result; - } - private unsafe void TakeSingleHeader(byte* pHeader, int headerLineLength, T handler) where T : IHttpHeadersHandler - { - var nameEnd = -1; - var valueStart = -1; - var valueEnd = -1; - var index = 0; - var pCurrent = pHeader + index; - var pEnd = pHeader + headerLineLength; - - nameEnd = IndexOfNameEnd(pHeader, index, headerLineLength); - - if (nameEnd == -1) + if (index == length) { RejectRequest(RequestRejectionReason.NoColonCharacterFoundInHeaderLine); } - - // Skip colon - index += nameEnd + 1; - pCurrent += index; - valueStart = index; - var pValueStart = pCurrent; - - while (pCurrent < pEnd) + if (sawWhitespace) { - var ch = *pCurrent; - if (ch != ByteTab && ch != ByteSpace && ch != ByteCR) - { - valueStart = index; - pValueStart = pCurrent; - break; - } - else if (ch == ByteCR) - { - break; - } - pCurrent++; - index++; + RejectRequest(RequestRejectionReason.WhitespaceIsNotAllowedInHeaderName); } + return index; + } - var endIndex = headerLineLength - 1; - pEnd--; + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private unsafe void TakeSingleHeader(byte* headerLine, int length, T handler) where T : IHttpHeadersHandler + { + // Skip CR, LF from end position + var valueEnd = length - 3; + var nameEnd = FindEndOfName(headerLine, length); - if (*pEnd != ByteLF) + if (headerLine[valueEnd + 2] != ByteLF) { RejectRequest(RequestRejectionReason.HeaderValueMustNotContainCR); } - - endIndex--; - pEnd--; - - if (*pEnd != ByteCR) + if (headerLine[valueEnd + 1] != ByteCR) { RejectRequest(RequestRejectionReason.MissingCRInHeaderLine); } - endIndex--; - pEnd--; - - while (pEnd >= pValueStart) + // Skip colon from value start + var valueStart = nameEnd + 1; + // Ignore start whitespace + for(; valueStart < valueEnd; valueStart++) { - var ch = *pEnd; - if (ch != ByteTab && ch != ByteSpace && ch != ByteCR && valueEnd == -1) + var ch = headerLine[valueStart]; + if (ch != ByteTab && ch != ByteSpace && ch != ByteCR) { - valueEnd = endIndex; + break; } else if (ch == ByteCR) { RejectRequest(RequestRejectionReason.HeaderValueMustNotContainCR); } - - pEnd--; - endIndex--; } - if (valueEnd == -1) + + // Check for CR in value + var i = valueStart + 1; + if (Contains(headerLine + i, valueEnd - i, ByteCR)) { - valueEnd = valueStart; + RejectRequest(RequestRejectionReason.HeaderValueMustNotContainCR); } - else + + // Ignore end whitespace + for (; valueEnd > valueStart; valueEnd--) { - valueEnd++; + var ch = headerLine[valueEnd]; + if (ch != ByteTab && ch != ByteSpace) + { + break; + } } - - var nameBuffer = new Span(pHeader, nameEnd); - var valueBuffer = new Span(pHeader + valueStart, valueEnd - valueStart); + var nameBuffer = new Span(headerLine, nameEnd); + var valueBuffer = new Span(headerLine + valueStart, valueEnd - valueStart + 1); handler.OnHeader(nameBuffer, valueBuffer); } + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static unsafe bool Contains(byte* searchSpace, int length, byte value) + { + var i = 0; + if (Vector.IsHardwareAccelerated) + { + // Check Vector lengths + if (length - Vector.Count >= i) + { + var vValue = GetVector(value); + do + { + if (!Vector.Zero.Equals(Vector.Equals(vValue, Unsafe.Read>(searchSpace + i)))) + { + goto found; + } + + i += Vector.Count; + } while (length - Vector.Count >= i); + } + } + + // Check remaining for CR + for (; i <= length; i++) + { + var ch = searchSpace[i]; + if (ch == value) + { + goto found; + } + } + return false; + found: + return true; + } + private static bool IsValidTokenChar(char c) { // Determines if a character is valid as a 'token' as defined in the @@ -536,20 +535,25 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http c == '~'; } - public void RejectRequest(RequestRejectionReason reason) + public static void RejectRequest(RequestRejectionReason reason) { throw BadHttpRequestException.GetException(reason); } - public void RejectRequest(RequestRejectionReason reason, string value) + public static void RejectRequest(RequestRejectionReason reason, string value) { throw BadHttpRequestException.GetException(reason, value); } private void RejectRequestLine(Span span) + { + throw GetRejectRequestLineException(span); + } + + private BadHttpRequestException GetRejectRequestLineException(Span span) { const int MaxRequestLineError = 32; - RejectRequest(RequestRejectionReason.InvalidRequestLine, + return BadHttpRequestException.GetException(RequestRejectionReason.InvalidRequestLine, Log.IsEnabled(LogLevel.Information) ? span.GetAsciiStringEscaped(MaxRequestLineError) : string.Empty); } @@ -558,6 +562,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static Vector GetVector(byte vectorByte) + { + // Vector .ctor doesn't become an intrinsic due to detection issue + // However this does cause it to become an intrinsic (with additional multiply and reg->reg copy) + // https://github.com/dotnet/coreclr/issues/7459#issuecomment-253965670 + return Vector.AsVectorByte(new Vector(vectorByte * 0x01010101u)); + } + private enum HeaderState { Name, diff --git a/test/shared/HttpParsingData.cs b/test/shared/HttpParsingData.cs index 56688b67f0..72a579feb0 100644 --- a/test/shared/HttpParsingData.cs +++ b/test/shared/HttpParsingData.cs @@ -212,6 +212,14 @@ namespace Microsoft.AspNetCore.Testing "Header-1: value1\rHeader-2: value2\r\n\r\n", "Header-1: value1\r\nHeader-2: value2\r\r\n", "Header-1: value1\r\nHeader-2: v\ralue2\r\n", + "Header-1: Value__\rVector16________Vector32\r\n", + "Header-1: Value___Vector16\r________Vector32\r\n", + "Header-1: Value___Vector16_______\rVector32\r\n", + "Header-1: Value___Vector16________Vector32\r\r\n", + "Header-1: Value___Vector16________Vector32_\r\r\n", + "Header-1: Value___Vector16________Vector32Value___Vector16_______\rVector32\r\n", + "Header-1: Value___Vector16________Vector32Value___Vector16________Vector32\r\r\n", + "Header-1: Value___Vector16________Vector32Value___Vector16________Vector32_\r\r\n", }; // Missing colon @@ -236,9 +244,20 @@ namespace Microsoft.AspNetCore.Testing { "Header : value\r\n\r\n", "Header\t: value\r\n\r\n", + "Header\r: value\r\n\r\n", + "Header_\rVector16: value\r\n\r\n", + "Header__Vector16\r: value\r\n\r\n", + "Header__Vector16_\r: value\r\n\r\n", + "Header_\rVector16________Vector32: value\r\n\r\n", + "Header__Vector16________Vector32\r: value\r\n\r\n", + "Header__Vector16________Vector32_\r: value\r\n\r\n", + "Header__Vector16________Vector32Header_\rVector16________Vector32: value\r\n\r\n", + "Header__Vector16________Vector32Header__Vector16________Vector32\r: value\r\n\r\n", + "Header__Vector16________Vector32Header__Vector16________Vector32_\r: value\r\n\r\n", "Header 1: value1\r\nHeader-2: value2\r\n\r\n", "Header 1 : value1\r\nHeader-2: value2\r\n\r\n", "Header 1\t: value1\r\nHeader-2: value2\r\n\r\n", + "Header 1\r: value1\r\nHeader-2: value2\r\n\r\n", "Header-1: value1\r\nHeader 2: value2\r\n\r\n", "Header-1: value1\r\nHeader-2 : value2\r\n\r\n", "Header-1: value1\r\nHeader-2\t: value2\r\n\r\n", From 5743d740b454874a3d056d2f480297be51abcb71 Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Mon, 6 Mar 2017 17:15:59 -0800 Subject: [PATCH 1099/1662] Convert HTTP parsing FrameTests to IHttpParser tests (#1416). - Also fix an issue in KestrelHttpParser where "Header: \r\n" is parsed with a value of " " instead of "". --- .../Internal/Http/KestrelHttpParser.cs | 2 +- .../BadHttpRequestTests.cs | 42 +- .../FrameTests.cs | 398 ++++-------------- .../HttpParserTests.cs | 383 +++++++++++++++++ test/shared/HttpParsingData.cs | 61 ++- 5 files changed, 531 insertions(+), 355 deletions(-) create mode 100644 test/Microsoft.AspNetCore.Server.KestrelTests/HttpParserTests.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/KestrelHttpParser.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/KestrelHttpParser.cs index d8da5a89bc..a5ce732aec 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/KestrelHttpParser.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/KestrelHttpParser.cs @@ -459,7 +459,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } // Ignore end whitespace - for (; valueEnd > valueStart; valueEnd--) + for (; valueEnd >= valueStart; valueEnd--) { var ch = headerLine[valueEnd]; if (ch != ByteTab && ch != ByteSpace) diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/BadHttpRequestTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/BadHttpRequestTests.cs index 80f127c9d1..565b06c2f1 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/BadHttpRequestTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/BadHttpRequestTests.cs @@ -1,9 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System; using System.Collections.Generic; -using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.AspNetCore.Testing; @@ -127,25 +125,33 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests ""); } - public static IEnumerable InvalidRequestLineData => HttpParsingData.InvalidRequestLineData - .Select(requestLine => new object[] + public static TheoryData InvalidRequestLineData + { + get { - requestLine, - $"Invalid request line: {requestLine.Replace("\r", "<0x0D>").Replace("\n", "<0x0A>")}", - }) - .Concat(HttpParsingData.EncodedNullCharInTargetRequestLines.Select(requestLine => new object[] - { - requestLine, - "Invalid request line." - })) - .Concat(HttpParsingData.NullCharInTargetRequestLines.Select(requestLine => new object[] - { - requestLine, - "Invalid request line." - })); + var data = new TheoryData(); + + foreach (var requestLine in HttpParsingData.RequestLineInvalidData) + { + data.Add(requestLine, $"Invalid request line: {requestLine.Replace("\r", "<0x0D>").Replace("\n", "<0x0A>")}"); + } + + foreach (var requestLine in HttpParsingData.RequestLineWithEncodedNullCharInTargetData) + { + data.Add(requestLine, "Invalid request line."); + } + + foreach (var requestLine in HttpParsingData.RequestLineWithNullCharInTargetData) + { + data.Add(requestLine, "Invalid request line."); + } + + return data; + } + } public static TheoryData UnrecognizedHttpVersionData => HttpParsingData.UnrecognizedHttpVersionData; - public static IEnumerable InvalidRequestHeaderData => HttpParsingData.InvalidRequestHeaderData; + public static IEnumerable InvalidRequestHeaderData => HttpParsingData.RequestHeaderInvalidData; } } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs index 46d54d1b40..8aeb066862 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs @@ -5,7 +5,6 @@ using System; using System.Collections.Generic; using System.IO; using System.IO.Pipelines; -using System.Linq; using System.Net; using System.Text; using System.Threading; @@ -25,7 +24,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { public class FrameTests : IDisposable { - private readonly IPipe _socketInput; + private readonly IPipe _input; private readonly TestFrame _frame; private readonly ServiceContext _serviceContext; private readonly ConnectionContext _connectionContext; @@ -50,7 +49,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { var trace = new KestrelTrace(new TestKestrelTrace()); _pipelineFactory = new PipeFactory(); - _socketInput = _pipelineFactory.Create(); + _input = _pipelineFactory.Create(); _serviceContext = new ServiceContext { @@ -65,7 +64,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests }; _connectionContext = new ConnectionContext(listenerContext) { - Input = _socketInput, + Input = _input, Output = new MockSocketOutput(), ConnectionControl = Mock.Of() }; @@ -77,149 +76,30 @@ namespace Microsoft.AspNetCore.Server.KestrelTests public void Dispose() { - _socketInput.Reader.Complete(); - _socketInput.Writer.Complete(); + _input.Reader.Complete(); + _input.Writer.Complete(); _pipelineFactory.Dispose(); } - [Fact] - public async Task CanReadHeaderValueWithoutLeadingWhitespace() - { - _frame.InitializeHeaders(); - - await _socketInput.Writer.WriteAsync(Encoding.ASCII.GetBytes("Header:value\r\n\r\n")); - - var readableBuffer = (await _socketInput.Reader.ReadAsync()).Buffer; - var success = _frame.TakeMessageHeaders(readableBuffer, out _consumed, out _examined); - _socketInput.Reader.Advance(_consumed, _examined); - - Assert.True(success); - Assert.Equal(1, _frame.RequestHeaders.Count); - Assert.Equal("value", _frame.RequestHeaders["Header"]); - Assert.Equal(readableBuffer.End, _consumed); - } - - [Theory] - [InlineData("Header: value\r\n\r\n")] - [InlineData("Header: value\r\n\r\n")] - [InlineData("Header:\tvalue\r\n\r\n")] - [InlineData("Header: \tvalue\r\n\r\n")] - [InlineData("Header:\t value\r\n\r\n")] - [InlineData("Header:\t\tvalue\r\n\r\n")] - [InlineData("Header:\t\t value\r\n\r\n")] - [InlineData("Header: \t\tvalue\r\n\r\n")] - [InlineData("Header: \t\t value\r\n\r\n")] - [InlineData("Header: \t \t value\r\n\r\n")] - public async Task LeadingWhitespaceIsNotIncludedInHeaderValue(string rawHeaders) - { - await _socketInput.Writer.WriteAsync(Encoding.ASCII.GetBytes(rawHeaders)); - - var readableBuffer = (await _socketInput.Reader.ReadAsync()).Buffer; - var success = _frame.TakeMessageHeaders(readableBuffer, out _consumed, out _examined); - _socketInput.Reader.Advance(_consumed, _examined); - - Assert.True(success); - Assert.Equal(1, _frame.RequestHeaders.Count); - Assert.Equal("value", _frame.RequestHeaders["Header"]); - Assert.Equal(readableBuffer.End, _consumed); - } - - [Theory] - [InlineData("Header: value \r\n\r\n")] - [InlineData("Header: value\t\r\n\r\n")] - [InlineData("Header: value \t\r\n\r\n")] - [InlineData("Header: value\t \r\n\r\n")] - [InlineData("Header: value\t\t\r\n\r\n")] - [InlineData("Header: value\t\t \r\n\r\n")] - [InlineData("Header: value \t\t\r\n\r\n")] - [InlineData("Header: value \t\t \r\n\r\n")] - [InlineData("Header: value \t \t \r\n\r\n")] - public async Task TrailingWhitespaceIsNotIncludedInHeaderValue(string rawHeaders) - { - await _socketInput.Writer.WriteAsync(Encoding.ASCII.GetBytes(rawHeaders)); - - var readableBuffer = (await _socketInput.Reader.ReadAsync()).Buffer; - var success = _frame.TakeMessageHeaders(readableBuffer, out _consumed, out _examined); - _socketInput.Reader.Advance(_consumed, _examined); - - Assert.True(success); - Assert.Equal(1, _frame.RequestHeaders.Count); - Assert.Equal("value", _frame.RequestHeaders["Header"]); - Assert.Equal(readableBuffer.End, _consumed); - } - - [Theory] - [InlineData("Header: one two three\r\n\r\n", "one two three")] - [InlineData("Header: one two three\r\n\r\n", "one two three")] - [InlineData("Header: one\ttwo\tthree\r\n\r\n", "one\ttwo\tthree")] - [InlineData("Header: one two\tthree\r\n\r\n", "one two\tthree")] - [InlineData("Header: one\ttwo three\r\n\r\n", "one\ttwo three")] - [InlineData("Header: one \ttwo \tthree\r\n\r\n", "one \ttwo \tthree")] - [InlineData("Header: one\t two\t three\r\n\r\n", "one\t two\t three")] - [InlineData("Header: one \ttwo\t three\r\n\r\n", "one \ttwo\t three")] - public async Task WhitespaceWithinHeaderValueIsPreserved(string rawHeaders, string expectedValue) - { - await _socketInput.Writer.WriteAsync(Encoding.ASCII.GetBytes(rawHeaders)); - - var readableBuffer = (await _socketInput.Reader.ReadAsync()).Buffer; - var success = _frame.TakeMessageHeaders(readableBuffer, out _consumed, out _examined); - _socketInput.Reader.Advance(_consumed, _examined); - - Assert.True(success); - Assert.Equal(1, _frame.RequestHeaders.Count); - Assert.Equal(expectedValue, _frame.RequestHeaders["Header"]); - Assert.Equal(readableBuffer.End, _consumed); - } - - [Theory] - [MemberData(nameof(InvalidRequestHeaderData))] - public async Task TakeMessageHeadersThrowsOnInvalidRequestHeaders(string rawHeaders, string expectedExceptionMessage) - { - await _socketInput.Writer.WriteAsync(Encoding.ASCII.GetBytes(rawHeaders)); - var readableBuffer = (await _socketInput.Reader.ReadAsync()).Buffer; - - var exception = Assert.Throws(() => _frame.TakeMessageHeaders(readableBuffer, out _consumed, out _examined)); - _socketInput.Reader.Advance(_consumed, _examined); - - Assert.Equal(expectedExceptionMessage, exception.Message); - Assert.Equal(StatusCodes.Status400BadRequest, exception.StatusCode); - } - [Fact] public async Task TakeMessageHeadersThrowsOnHeaderValueWithLineFolding_CharacterNotAvailableOnFirstAttempt() { - await _socketInput.Writer.WriteAsync(Encoding.ASCII.GetBytes("Header-1: value1\r\n")); + await _input.Writer.WriteAsync(Encoding.ASCII.GetBytes("Header-1: value1\r\n")); - var readableBuffer = (await _socketInput.Reader.ReadAsync()).Buffer; + var readableBuffer = (await _input.Reader.ReadAsync()).Buffer; Assert.False(_frame.TakeMessageHeaders(readableBuffer, out _consumed, out _examined)); - _socketInput.Reader.Advance(_consumed, _examined); + _input.Reader.Advance(_consumed, _examined); - await _socketInput.Writer.WriteAsync(Encoding.ASCII.GetBytes(" ")); + await _input.Writer.WriteAsync(Encoding.ASCII.GetBytes(" ")); - readableBuffer = (await _socketInput.Reader.ReadAsync()).Buffer; + readableBuffer = (await _input.Reader.ReadAsync()).Buffer; var exception = Assert.Throws(() => _frame.TakeMessageHeaders(readableBuffer, out _consumed, out _examined)); - _socketInput.Reader.Advance(_consumed, _examined); + _input.Reader.Advance(_consumed, _examined); Assert.Equal("Whitespace is not allowed in header name.", exception.Message); Assert.Equal(StatusCodes.Status400BadRequest, exception.StatusCode); } - [Fact] - public async Task TakeMessageHeadersConsumesBytesCorrectlyAtEnd() - { - await _socketInput.Writer.WriteAsync(Encoding.ASCII.GetBytes("Header-1: value1\r\n\r")); - - var readableBuffer = (await _socketInput.Reader.ReadAsync()).Buffer; - Assert.False(_frame.TakeMessageHeaders(readableBuffer, out _consumed, out _examined)); - _socketInput.Reader.Advance(_consumed, _examined); - - await _socketInput.Writer.WriteAsync(Encoding.ASCII.GetBytes("\n")); - - readableBuffer = (await _socketInput.Reader.ReadAsync()).Buffer; - Assert.True(_frame.TakeMessageHeaders(readableBuffer, out _consumed, out _examined)); - _socketInput.Reader.Advance(_consumed, _examined); - } - [Fact] public async Task TakeMessageHeadersThrowsWhenHeadersExceedTotalSizeLimit() { @@ -227,11 +107,11 @@ namespace Microsoft.AspNetCore.Server.KestrelTests _serviceContext.ServerOptions.Limits.MaxRequestHeadersTotalSize = headerLine.Length - 1; _frame.Reset(); - await _socketInput.Writer.WriteAsync(Encoding.ASCII.GetBytes($"{headerLine}\r\n")); - var readableBuffer = (await _socketInput.Reader.ReadAsync()).Buffer; + await _input.Writer.WriteAsync(Encoding.ASCII.GetBytes($"{headerLine}\r\n")); + var readableBuffer = (await _input.Reader.ReadAsync()).Buffer; var exception = Assert.Throws(() => _frame.TakeMessageHeaders(readableBuffer, out _consumed, out _examined)); - _socketInput.Reader.Advance(_consumed, _examined); + _input.Reader.Advance(_consumed, _examined); Assert.Equal("Request headers too long.", exception.Message); Assert.Equal(StatusCodes.Status431RequestHeaderFieldsTooLarge, exception.StatusCode); @@ -243,36 +123,16 @@ namespace Microsoft.AspNetCore.Server.KestrelTests const string headerLines = "Header-1: value1\r\nHeader-2: value2\r\n"; _serviceContext.ServerOptions.Limits.MaxRequestHeaderCount = 1; - await _socketInput.Writer.WriteAsync(Encoding.ASCII.GetBytes($"{headerLines}\r\n")); - var readableBuffer = (await _socketInput.Reader.ReadAsync()).Buffer; + await _input.Writer.WriteAsync(Encoding.ASCII.GetBytes($"{headerLines}\r\n")); + var readableBuffer = (await _input.Reader.ReadAsync()).Buffer; var exception = Assert.Throws(() => _frame.TakeMessageHeaders(readableBuffer, out _consumed, out _examined)); - _socketInput.Reader.Advance(_consumed, _examined); + _input.Reader.Advance(_consumed, _examined); Assert.Equal("Request contains too many headers.", exception.Message); Assert.Equal(StatusCodes.Status431RequestHeaderFieldsTooLarge, exception.StatusCode); } - [Theory] - [InlineData("Cookie: \r\n\r\n", 1)] - [InlineData("Cookie:\r\n\r\n", 1)] - [InlineData("Cookie: \r\nConnection: close\r\n\r\n", 2)] - [InlineData("Cookie:\r\nConnection: close\r\n\r\n", 2)] - [InlineData("Connection: close\r\nCookie: \r\n\r\n", 2)] - [InlineData("Connection: close\r\nCookie:\r\n\r\n", 2)] - public async Task EmptyHeaderValuesCanBeParsed(string rawHeaders, int numHeaders) - { - await _socketInput.Writer.WriteAsync(Encoding.ASCII.GetBytes(rawHeaders)); - var readableBuffer = (await _socketInput.Reader.ReadAsync()).Buffer; - - var success = _frame.TakeMessageHeaders(readableBuffer, out _consumed, out _examined); - _socketInput.Reader.Advance(_consumed, _examined); - - Assert.True(success); - Assert.Equal(numHeaders, _frame.RequestHeaders.Count); - Assert.Equal(readableBuffer.End, _consumed); - } - [Fact] public void ResetResetsScheme() { @@ -296,11 +156,11 @@ namespace Microsoft.AspNetCore.Server.KestrelTests options.Limits.MaxRequestHeaderCount = 1; _serviceContext.ServerOptions = options; - await _socketInput.Writer.WriteAsync(Encoding.ASCII.GetBytes($"{headerLine1}\r\n")); - var readableBuffer = (await _socketInput.Reader.ReadAsync()).Buffer; + await _input.Writer.WriteAsync(Encoding.ASCII.GetBytes($"{headerLine1}\r\n")); + var readableBuffer = (await _input.Reader.ReadAsync()).Buffer; var takeMessageHeaders = _frame.TakeMessageHeaders(readableBuffer, out _consumed, out _examined); - _socketInput.Reader.Advance(_consumed, _examined); + _input.Reader.Advance(_consumed, _examined); Assert.True(takeMessageHeaders); Assert.Equal(1, _frame.RequestHeaders.Count); @@ -308,11 +168,11 @@ namespace Microsoft.AspNetCore.Server.KestrelTests _frame.Reset(); - await _socketInput.Writer.WriteAsync(Encoding.ASCII.GetBytes($"{headerLine2}\r\n")); - readableBuffer = (await _socketInput.Reader.ReadAsync()).Buffer; + await _input.Writer.WriteAsync(Encoding.ASCII.GetBytes($"{headerLine2}\r\n")); + readableBuffer = (await _input.Reader.ReadAsync()).Buffer; takeMessageHeaders = _frame.TakeMessageHeaders(readableBuffer, out _consumed, out _examined); - _socketInput.Reader.Advance(_consumed, _examined); + _input.Reader.Advance(_consumed, _examined); Assert.True(takeMessageHeaders); Assert.Equal(1, _frame.RequestHeaders.Count); @@ -407,86 +267,37 @@ namespace Microsoft.AspNetCore.Server.KestrelTests public async Task TakeStartLineSetsFrameProperties( string requestLine, string expectedMethod, - string expectedPath, + string expectedRawTarget, + string expectedRawPath, + string expectedDecodedPath, string expectedQueryString, string expectedHttpVersion) { var requestLineBytes = Encoding.ASCII.GetBytes(requestLine); - await _socketInput.Writer.WriteAsync(requestLineBytes); - var readableBuffer = (await _socketInput.Reader.ReadAsync()).Buffer; + await _input.Writer.WriteAsync(requestLineBytes); + var readableBuffer = (await _input.Reader.ReadAsync()).Buffer; var returnValue = _frame.TakeStartLine(readableBuffer, out _consumed, out _examined); - _socketInput.Reader.Advance(_consumed, _examined); + _input.Reader.Advance(_consumed, _examined); Assert.True(returnValue); Assert.Equal(expectedMethod, _frame.Method); - Assert.Equal(expectedPath, _frame.Path); + Assert.Equal(expectedRawTarget, _frame.RawTarget); + Assert.Equal(expectedDecodedPath, _frame.Path); Assert.Equal(expectedQueryString, _frame.QueryString); Assert.Equal(expectedHttpVersion, _frame.HttpVersion); } - [Fact] - public async Task TakeStartLineCallsConsumingCompleteWithFurthestExamined() - { - var requestLineBytes = Encoding.ASCII.GetBytes("GET / "); - await _socketInput.Writer.WriteAsync(requestLineBytes); - var readableBuffer = (await _socketInput.Reader.ReadAsync()).Buffer; - - _frame.TakeStartLine(readableBuffer, out _consumed, out _examined); - _socketInput.Reader.Advance(_consumed, _examined); - - Assert.Equal(readableBuffer.Start, _consumed); - Assert.Equal(readableBuffer.End, _examined); - - requestLineBytes = Encoding.ASCII.GetBytes("HTTP/1.1\r\n"); - await _socketInput.Writer.WriteAsync(requestLineBytes); - readableBuffer = (await _socketInput.Reader.ReadAsync()).Buffer; - - _frame.TakeStartLine(readableBuffer, out _consumed, out _examined); - _socketInput.Reader.Advance(_consumed, _examined); - - Assert.Equal(readableBuffer.End, _consumed); - Assert.Equal(readableBuffer.End, _examined); - } - - [Theory] - [InlineData("G")] - [InlineData("GE")] - [InlineData("GET")] - [InlineData("GET ")] - [InlineData("GET /")] - [InlineData("GET / ")] - [InlineData("GET / H")] - [InlineData("GET / HT")] - [InlineData("GET / HTT")] - [InlineData("GET / HTTP")] - [InlineData("GET / HTTP/")] - [InlineData("GET / HTTP/1")] - [InlineData("GET / HTTP/1.")] - [InlineData("GET / HTTP/1.1")] - [InlineData("GET / HTTP/1.1\r")] - public async Task TakeStartLineReturnsWhenGivenIncompleteRequestLines(string requestLine) - { - var requestLineBytes = Encoding.ASCII.GetBytes(requestLine); - await _socketInput.Writer.WriteAsync(requestLineBytes); - - var readableBuffer = (await _socketInput.Reader.ReadAsync()).Buffer; - var returnValue = _frame.TakeStartLine(readableBuffer, out _consumed, out _examined); - _socketInput.Reader.Advance(_consumed, _examined); - - Assert.False(returnValue); - } - [Fact] public async Task ParseRequestStartsRequestHeadersTimeoutOnFirstByteAvailable() { var connectionControl = new Mock(); _connectionContext.ConnectionControl = connectionControl.Object; - await _socketInput.Writer.WriteAsync(Encoding.ASCII.GetBytes("G")); + await _input.Writer.WriteAsync(Encoding.ASCII.GetBytes("G")); - _frame.ParseRequest((await _socketInput.Reader.ReadAsync()).Buffer, out _consumed, out _examined); - _socketInput.Reader.Advance(_consumed, _examined); + _frame.ParseRequest((await _input.Reader.ReadAsync()).Buffer, out _consumed, out _examined); + _input.Reader.Advance(_consumed, _examined); var expectedRequestHeadersTimeout = (long)_serviceContext.ServerOptions.Limits.RequestHeadersTimeout.TotalMilliseconds; connectionControl.Verify(cc => cc.ResetTimeout(expectedRequestHeadersTimeout, TimeoutAction.SendTimeoutResponse)); @@ -498,93 +309,42 @@ namespace Microsoft.AspNetCore.Server.KestrelTests _serviceContext.ServerOptions.Limits.MaxRequestLineSize = "GET / HTTP/1.1\r\n".Length; var requestLineBytes = Encoding.ASCII.GetBytes("GET /a HTTP/1.1\r\n"); - await _socketInput.Writer.WriteAsync(requestLineBytes); + await _input.Writer.WriteAsync(requestLineBytes); - var readableBuffer = (await _socketInput.Reader.ReadAsync()).Buffer; + var readableBuffer = (await _input.Reader.ReadAsync()).Buffer; var exception = Assert.Throws(() => _frame.TakeStartLine(readableBuffer, out _consumed, out _examined)); - _socketInput.Reader.Advance(_consumed, _examined); + _input.Reader.Advance(_consumed, _examined); Assert.Equal("Request line too long.", exception.Message); Assert.Equal(StatusCodes.Status414UriTooLong, exception.StatusCode); } [Theory] - [MemberData(nameof(InvalidRequestLineData))] - public async Task TakeStartLineThrowsOnInvalidRequestLine(string requestLine, Type expectedExceptionType, string expectedExceptionMessage) + [MemberData(nameof(RequestLineWithEncodedNullCharInTargetData))] + public async Task TakeStartLineThrowsOnEncodedNullCharInTarget(string requestLine) { - await _socketInput.Writer.WriteAsync(Encoding.ASCII.GetBytes(requestLine)); - var readableBuffer = (await _socketInput.Reader.ReadAsync()).Buffer; + await _input.Writer.WriteAsync(Encoding.ASCII.GetBytes(requestLine)); + var readableBuffer = (await _input.Reader.ReadAsync()).Buffer; - var exception = Assert.Throws(expectedExceptionType, () => + var exception = Assert.Throws(() => _frame.TakeStartLine(readableBuffer, out _consumed, out _examined)); - _socketInput.Reader.Advance(_consumed, _examined); + _input.Reader.Advance(_consumed, _examined); - Assert.Equal(expectedExceptionMessage, exception.Message); - - if (expectedExceptionType == typeof(BadHttpRequestException)) - { - Assert.Equal(StatusCodes.Status400BadRequest, (exception as BadHttpRequestException).StatusCode); - } + Assert.Equal("The path contains null characters.", exception.Message); } [Theory] - [MemberData(nameof(UnrecognizedHttpVersionData))] - public async Task TakeStartLineThrowsOnUnrecognizedHttpVersion(string httpVersion) + [MemberData(nameof(RequestLineWithNullCharInTargetData))] + public async Task TakeStartLineThrowsOnNullCharInTarget(string requestLine) { - await _socketInput.Writer.WriteAsync(Encoding.ASCII.GetBytes($"GET / {httpVersion}\r\n")); + await _input.Writer.WriteAsync(Encoding.ASCII.GetBytes(requestLine)); + var readableBuffer = (await _input.Reader.ReadAsync()).Buffer; - var readableBuffer = (await _socketInput.Reader.ReadAsync()).Buffer; + var exception = Assert.Throws(() => + _frame.TakeStartLine(readableBuffer, out _consumed, out _examined)); + _input.Reader.Advance(_consumed, _examined); - var exception = Assert.Throws(() => _frame.TakeStartLine(readableBuffer, out _consumed, out _examined)); - _socketInput.Reader.Advance(_consumed, _examined); - - Assert.Equal($"Unrecognized HTTP version: {httpVersion}", exception.Message); - Assert.Equal(StatusCodes.Status505HttpVersionNotsupported, exception.StatusCode); - } - - [Fact] - public async Task TakeMessageHeadersCallsConsumingCompleteWithFurthestExamined() - { - foreach (var rawHeader in new[] { "Header: ", "value\r\n", "\r\n" }) - { - await _socketInput.Writer.WriteAsync(Encoding.ASCII.GetBytes(rawHeader)); - - var readableBuffer = (await _socketInput.Reader.ReadAsync()).Buffer; - _frame.TakeMessageHeaders(readableBuffer, out _consumed, out _examined); - _socketInput.Reader.Advance(_consumed, _examined); - Assert.Equal(readableBuffer.End, _examined); - } - } - - [Theory] - [InlineData("\r")] - [InlineData("H")] - [InlineData("He")] - [InlineData("Hea")] - [InlineData("Head")] - [InlineData("Heade")] - [InlineData("Header")] - [InlineData("Header:")] - [InlineData("Header: ")] - [InlineData("Header: v")] - [InlineData("Header: va")] - [InlineData("Header: val")] - [InlineData("Header: valu")] - [InlineData("Header: value")] - [InlineData("Header: value\r")] - [InlineData("Header: value\r\n")] - [InlineData("Header: value\r\n\r")] - public async Task TakeMessageHeadersReturnsWhenGivenIncompleteHeaders(string headers) - { - var headerBytes = Encoding.ASCII.GetBytes(headers); - await _socketInput.Writer.WriteAsync(headerBytes); - - ReadCursor consumed; - ReadCursor examined; - var readableBuffer = (await _socketInput.Reader.ReadAsync()).Buffer; - - Assert.Equal(false, _frame.TakeMessageHeaders(readableBuffer, out consumed, out examined)); - _socketInput.Reader.Advance(consumed, examined); + Assert.Equal(new InvalidOperationException().Message, exception.Message); } [Fact] @@ -599,7 +359,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests connectionControl.Verify(cc => cc.SetTimeout(expectedKeepAliveTimeout, TimeoutAction.CloseConnection)); _frame.StopAsync(); - _socketInput.Writer.Complete(); + _input.Writer.Complete(); requestProcessingTask.Wait(); } @@ -681,13 +441,13 @@ namespace Microsoft.AspNetCore.Server.KestrelTests _frame.Start(); var data = Encoding.ASCII.GetBytes("GET / HTTP/1.1\r\n\r\n"); - await _socketInput.Writer.WriteAsync(data); + await _input.Writer.WriteAsync(data); var requestProcessingTask = _frame.StopAsync(); Assert.IsNotType(typeof(Task), requestProcessingTask); await requestProcessingTask.TimeoutAfter(TimeSpan.FromSeconds(10)); - _socketInput.Writer.Complete(); + _input.Writer.Complete(); } [Fact] @@ -758,30 +518,36 @@ namespace Microsoft.AspNetCore.Server.KestrelTests Assert.NotSame(original, _frame.RequestAborted.WaitHandle); } - public static IEnumerable ValidRequestLineData => HttpParsingData.ValidRequestLineData; + public static IEnumerable ValidRequestLineData => HttpParsingData.RequestLineValidData; - public static IEnumerable InvalidRequestLineData => HttpParsingData.InvalidRequestLineData - .Select(requestLine => new object[] + public static TheoryData RequestLineWithEncodedNullCharInTargetData + { + get { - requestLine, - typeof(BadHttpRequestException), - $"Invalid request line: {requestLine.Replace("\r", "<0x0D>").Replace("\n", "<0x0A>")}", - }) - .Concat(HttpParsingData.EncodedNullCharInTargetRequestLines.Select(requestLine => new object[] - { - requestLine, - typeof(InvalidOperationException), - "The path contains null characters." - })) - .Concat(HttpParsingData.NullCharInTargetRequestLines.Select(requestLine => new object[] - { - requestLine, - typeof(InvalidOperationException), - new InvalidOperationException().Message - })); + var data = new TheoryData(); - public static TheoryData UnrecognizedHttpVersionData => HttpParsingData.UnrecognizedHttpVersionData; + foreach (var requestLine in HttpParsingData.RequestLineWithEncodedNullCharInTargetData) + { + data.Add(requestLine); + } - public static IEnumerable InvalidRequestHeaderData => HttpParsingData.InvalidRequestHeaderData; + return data; + } + } + + public static TheoryData RequestLineWithNullCharInTargetData + { + get + { + var data = new TheoryData(); + + foreach (var requestLine in HttpParsingData.RequestLineWithNullCharInTargetData) + { + data.Add(requestLine); + } + + return data; + } + } } } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/HttpParserTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/HttpParserTests.cs new file mode 100644 index 0000000000..7d16b5f06c --- /dev/null +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/HttpParserTests.cs @@ -0,0 +1,383 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Collections.Generic; +using System.IO.Pipelines; +using System.Linq; +using System.Text; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Server.Kestrel; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; +using Microsoft.AspNetCore.Testing; +using Microsoft.Extensions.Logging; +using Moq; +using Xunit; + +namespace Microsoft.AspNetCore.Server.KestrelTests +{ + public class HttpParserTests + { + // Returns true when all headers parsed + // Return false otherwise + + [Theory] + [MemberData(nameof(RequestLineValidData))] + public void ParsesRequestLine( + string requestLine, + string expectedMethod, + string expectedRawTarget, + string expectedRawPath, + string expectedDecodedPath, + string expectedQueryString, + string expectedVersion) + { + var parser = CreateParser(Mock.Of()); + var buffer = ReadableBuffer.Create(Encoding.ASCII.GetBytes(requestLine)); + + string parsedMethod = null; + string parsedVersion = null; + string parsedRawTarget = null; + string parsedRawPath = null; + string parsedQuery = null; + var requestLineHandler = new Mock(); + requestLineHandler + .Setup(handler => handler.OnStartLine( + It.IsAny(), + It.IsAny(), + It.IsAny>(), + It.IsAny>(), + It.IsAny>(), + It.IsAny>())) + .Callback, Span, Span, Span>((method, version, target, path, query, customMethod) => + { + parsedMethod = method != HttpMethod.Custom ? HttpUtilities.MethodToString(method) : customMethod.GetAsciiStringNonNullCharacters(); + parsedVersion = HttpUtilities.VersionToString(version); + parsedRawTarget = target.GetAsciiStringNonNullCharacters(); + parsedRawPath = path.GetAsciiStringNonNullCharacters(); + parsedQuery = query.GetAsciiStringNonNullCharacters(); + }); + + Assert.True(parser.ParseRequestLine(requestLineHandler.Object, buffer, out var consumed, out var examined)); + + Assert.Equal(parsedMethod, expectedMethod); + Assert.Equal(parsedVersion, expectedVersion); + Assert.Equal(parsedRawTarget, expectedRawTarget); + Assert.Equal(parsedRawPath, expectedRawPath); + Assert.Equal(parsedVersion, expectedVersion); + Assert.Equal(buffer.End, consumed); + Assert.Equal(buffer.End, examined); + } + + [Theory] + [MemberData(nameof(RequestLineIncompleteData))] + public void ParseRequestLineReturnsFalseWhenGivenIncompleteRequestLines(string requestLine) + { + var parser = CreateParser(Mock.Of()); + var buffer = ReadableBuffer.Create(Encoding.ASCII.GetBytes(requestLine)); + + Assert.False(parser.ParseRequestLine(Mock.Of(), buffer, out var consumed, out var examined)); + } + + [Theory] + [MemberData(nameof(RequestLineIncompleteData))] + public void ParseRequestLineDoesNotConsumeIncompleteRequestLine(string requestLine) + { + var parser = CreateParser(Mock.Of()); + var buffer = ReadableBuffer.Create(Encoding.ASCII.GetBytes(requestLine)); + + Assert.False(parser.ParseRequestLine(Mock.Of(), buffer, out var consumed, out var examined)); + + Assert.Equal(buffer.Start, consumed); + Assert.Equal(buffer.End, examined); + } + + [Theory] + [MemberData(nameof(RequestLineInvalidData))] + public void ParseRequestLineThrowsOnInvalidRequestLine(string requestLine) + { + var mockTrace = new Mock(); + mockTrace + .Setup(trace => trace.IsEnabled(LogLevel.Information)) + .Returns(true); + + var parser = CreateParser(mockTrace.Object); + var buffer = ReadableBuffer.Create(Encoding.ASCII.GetBytes(requestLine)); + + var exception = Assert.Throws(() => + parser.ParseRequestLine(Mock.Of(), buffer, out var consumed, out var examined)); + + Assert.Equal($"Invalid request line: {requestLine.Replace("\r", "<0x0D>").Replace("\n", "<0x0A>")}", exception.Message); + Assert.Equal(StatusCodes.Status400BadRequest, (exception as BadHttpRequestException).StatusCode); + } + + [Theory] + [MemberData(nameof(UnrecognizedHttpVersionData))] + public void ParseRequestLineThrowsOnUnrecognizedHttpVersion(string httpVersion) + { + var requestLine = $"GET / {httpVersion}\r\n"; + + var mockTrace = new Mock(); + mockTrace + .Setup(trace => trace.IsEnabled(LogLevel.Information)) + .Returns(true); + + var parser = CreateParser(mockTrace.Object); + var buffer = ReadableBuffer.Create(Encoding.ASCII.GetBytes(requestLine)); + + var exception = Assert.Throws(() => + parser.ParseRequestLine(Mock.Of(), buffer, out var consumed, out var examined)); + + Assert.Equal($"Unrecognized HTTP version: {httpVersion}", exception.Message); + Assert.Equal(StatusCodes.Status505HttpVersionNotsupported, (exception as BadHttpRequestException).StatusCode); + } + + [Theory] + [InlineData("\r")] + [InlineData("H")] + [InlineData("He")] + [InlineData("Hea")] + [InlineData("Head")] + [InlineData("Heade")] + [InlineData("Header")] + [InlineData("Header:")] + [InlineData("Header: ")] + [InlineData("Header: v")] + [InlineData("Header: va")] + [InlineData("Header: val")] + [InlineData("Header: valu")] + [InlineData("Header: value")] + [InlineData("Header: value\r")] + [InlineData("Header: value\r\n")] + [InlineData("Header: value\r\n\r")] + [InlineData("Header-1: value1\r\nH")] + [InlineData("Header-1: value1\r\nHe")] + [InlineData("Header-1: value1\r\nHea")] + [InlineData("Header-1: value1\r\nHead")] + [InlineData("Header-1: value1\r\nHeade")] + [InlineData("Header-1: value1\r\nHeader")] + [InlineData("Header-1: value1\r\nHeader-")] + [InlineData("Header-1: value1\r\nHeader-2")] + [InlineData("Header-1: value1\r\nHeader-2:")] + [InlineData("Header-1: value1\r\nHeader-2: ")] + [InlineData("Header-1: value1\r\nHeader-2: v")] + [InlineData("Header-1: value1\r\nHeader-2: va")] + [InlineData("Header-1: value1\r\nHeader-2: val")] + [InlineData("Header-1: value1\r\nHeader-2: valu")] + [InlineData("Header-1: value1\r\nHeader-2: value")] + [InlineData("Header-1: value1\r\nHeader-2: value2")] + [InlineData("Header-1: value1\r\nHeader-2: value2\r")] + [InlineData("Header-1: value1\r\nHeader-2: value2\r\n")] + [InlineData("Header-1: value1\r\nHeader-2: value2\r\n\r")] + public void ParseHeadersReturnsFalseWhenGivenIncompleteHeaders(string rawHeaders) + { + var parser = CreateParser(Mock.Of()); + + var buffer = ReadableBuffer.Create(Encoding.ASCII.GetBytes(rawHeaders)); + Assert.False(parser.ParseHeaders(Mock.Of(), buffer, out var consumed, out var examined, out var consumedBytes)); + } + + [Theory] + [InlineData("\r")] + [InlineData("H")] + [InlineData("He")] + [InlineData("Hea")] + [InlineData("Head")] + [InlineData("Heade")] + [InlineData("Header")] + [InlineData("Header:")] + [InlineData("Header: ")] + [InlineData("Header: v")] + [InlineData("Header: va")] + [InlineData("Header: val")] + [InlineData("Header: valu")] + [InlineData("Header: value")] + [InlineData("Header: value\r")] + public void ParseHeadersDoesNotConsumeIncompleteHeader(string rawHeaders) + { + var parser = CreateParser(Mock.Of()); + + var buffer = ReadableBuffer.Create(Encoding.ASCII.GetBytes(rawHeaders)); + parser.ParseHeaders(Mock.Of(), buffer, out var consumed, out var examined, out var consumedBytes); + + Assert.Equal(buffer.Start, consumed); + Assert.Equal(buffer.End, examined); + Assert.Equal(0, consumedBytes); + } + + [Fact] + public void ParseHeadersCanReadHeaderValueWithoutLeadingWhitespace() + { + VerifyHeader("Header", "value", "value"); + } + + [Theory] + [InlineData("Cookie: \r\n\r\n", "Cookie", "", null, null)] + [InlineData("Cookie:\r\n\r\n", "Cookie", "", null, null)] + [InlineData("Cookie: \r\nConnection: close\r\n\r\n", "Cookie", "", "Connection", "close")] + [InlineData("Cookie:\r\nConnection: close\r\n\r\n", "Cookie", "", "Connection", "close")] + [InlineData("Connection: close\r\nCookie: \r\n\r\n", "Connection", "close", "Cookie", "")] + [InlineData("Connection: close\r\nCookie:\r\n\r\n", "Connection", "close", "Cookie", "")] + public void ParseHeadersCanParseEmptyHeaderValues( + string rawHeaders, + string expectedHeaderName1, + string expectedHeaderValue1, + string expectedHeaderName2, + string expectedHeaderValue2) + { + var expectedHeaderNames = expectedHeaderName2 == null + ? new[] { expectedHeaderName1 } + : new[] { expectedHeaderName1, expectedHeaderName2 }; + var expectedHeaderValues = expectedHeaderValue2 == null + ? new[] { expectedHeaderValue1 } + : new[] { expectedHeaderValue1, expectedHeaderValue2 }; + + VerifyRawHeaders(rawHeaders, expectedHeaderNames, expectedHeaderValues); + } + + [Theory] + [InlineData(" value")] + [InlineData(" value")] + [InlineData("\tvalue")] + [InlineData(" \tvalue")] + [InlineData("\t value")] + [InlineData("\t\tvalue")] + [InlineData("\t\t value")] + [InlineData(" \t\tvalue")] + [InlineData(" \t\t value")] + [InlineData(" \t \t value")] + public void ParseHeadersDoesNotIncludeLeadingWhitespaceInHeaderValue(string rawHeaderValue) + { + VerifyHeader("Header", rawHeaderValue, "value"); + } + + [Theory] + [InlineData("value ")] + [InlineData("value\t")] + [InlineData("value \t")] + [InlineData("value\t ")] + [InlineData("value\t\t")] + [InlineData("value\t\t ")] + [InlineData("value \t\t")] + [InlineData("value \t\t ")] + [InlineData("value \t \t ")] + public void ParseHeadersDoesNotIncludeTrailingWhitespaceInHeaderValue(string rawHeaderValue) + { + VerifyHeader("Header", rawHeaderValue, "value"); + } + + [Theory] + [InlineData("one two three")] + [InlineData("one two three")] + [InlineData("one\ttwo\tthree")] + [InlineData("one two\tthree")] + [InlineData("one\ttwo three")] + [InlineData("one \ttwo \tthree")] + [InlineData("one\t two\t three")] + [InlineData("one \ttwo\t three")] + public void ParseHeadersPreservesWhitespaceWithinHeaderValue(string headerValue) + { + VerifyHeader("Header", headerValue, headerValue); + } + + [Fact] + public void ParseHeadersConsumesBytesCorrectlyAtEnd() + { + var parser = CreateParser(Mock.Of()); + + const string headerLine = "Header: value\r\n\r"; + var buffer1 = ReadableBuffer.Create(Encoding.ASCII.GetBytes(headerLine)); + Assert.False(parser.ParseHeaders(Mock.Of(), buffer1, out var consumed, out var examined, out var consumedBytes)); + + Assert.Equal(buffer1.Move(buffer1.Start, headerLine.Length - 1), consumed); + Assert.Equal(buffer1.End, examined); + Assert.Equal(headerLine.Length - 1, consumedBytes); + + var buffer2 = ReadableBuffer.Create(Encoding.ASCII.GetBytes("\r\n")); + Assert.True(parser.ParseHeaders(Mock.Of(), buffer2, out consumed, out examined, out consumedBytes)); + + Assert.Equal(buffer2.End, consumed); + Assert.Equal(buffer2.End, examined); + Assert.Equal(2, consumedBytes); + } + + [Theory] + [MemberData(nameof(RequestHeaderInvalidData))] + public void ParseHeadersThrowsOnInvalidRequestHeaders(string rawHeaders, string expectedExceptionMessage) + { + var parser = CreateParser(Mock.Of()); + var buffer = ReadableBuffer.Create(Encoding.ASCII.GetBytes(rawHeaders)); + + var exception = Assert.Throws(() => + parser.ParseHeaders(Mock.Of(), buffer, out var consumed, out var examined, out var consumedBytes)); + + Assert.Equal(expectedExceptionMessage, exception.Message); + Assert.Equal(StatusCodes.Status400BadRequest, exception.StatusCode); + } + + private void VerifyHeader( + string headerName, + string rawHeaderValue, + string expectedHeaderValue) + { + var parser = CreateParser(Mock.Of()); + var buffer = ReadableBuffer.Create(Encoding.ASCII.GetBytes($"{headerName}:{rawHeaderValue}\r\n")); + + string parsedHeaderName = "unexpected"; + string parsedHeaderValue = "unexpected"; + var headersHandler = new Mock(); + headersHandler + .Setup(handler => handler.OnHeader(It.IsAny>(), It.IsAny>())) + .Callback, Span>((name, value) => + { + parsedHeaderName = name.GetAsciiStringNonNullCharacters(); + parsedHeaderValue = value.GetAsciiStringNonNullCharacters(); + }); + + parser.ParseHeaders(headersHandler.Object, buffer, out var consumed, out var examined, out var consumedBytes); + + Assert.Equal(headerName, parsedHeaderName); + Assert.Equal(expectedHeaderValue, parsedHeaderValue); + Assert.Equal(buffer.End, consumed); + Assert.Equal(buffer.End, examined); + } + + private void VerifyRawHeaders(string rawHeaders, IEnumerable expectedHeaderNames, IEnumerable expectedHeaderValues) + { + Assert.True(expectedHeaderNames.Count() == expectedHeaderValues.Count(), $"{nameof(expectedHeaderNames)} and {nameof(expectedHeaderValues)} sizes must match"); + + var parser = CreateParser(Mock.Of()); + var buffer = ReadableBuffer.Create(Encoding.ASCII.GetBytes(rawHeaders)); + + var parsedHeaders = new List>(); + var headersHandler = new Mock(); + headersHandler + .Setup(handler => handler.OnHeader(It.IsAny>(), It.IsAny>())) + .Callback, Span>((name, value) => + { + parsedHeaders.Add(Tuple.Create(name.GetAsciiStringNonNullCharacters(), value.GetAsciiStringNonNullCharacters())); + }); + + parser.ParseHeaders(headersHandler.Object, buffer, out var consumed, out var examined, out var consumedBytes); + + Assert.Equal(expectedHeaderNames.Count(), parsedHeaders.Count); + Assert.Equal(expectedHeaderNames, parsedHeaders.Select(t => t.Item1)); + Assert.Equal(expectedHeaderValues, parsedHeaders.Select(t => t.Item2)); + Assert.Equal(buffer.End, consumed); + Assert.Equal(buffer.End, examined); + } + + private IHttpParser CreateParser(IKestrelTrace log) => new KestrelHttpParser(log); + + public static IEnumerable RequestLineValidData => HttpParsingData.RequestLineValidData; + + public static IEnumerable RequestLineIncompleteData => HttpParsingData.RequestLineIncompleteData.Select(requestLine => new[] { requestLine }); + + public static IEnumerable RequestLineInvalidData => HttpParsingData.RequestLineInvalidData.Select(requestLine => new[] { requestLine }); + + public static TheoryData UnrecognizedHttpVersionData => HttpParsingData.UnrecognizedHttpVersionData; + + public static IEnumerable RequestHeaderInvalidData => HttpParsingData.RequestHeaderInvalidData; + } +} diff --git a/test/shared/HttpParsingData.cs b/test/shared/HttpParsingData.cs index 72a579feb0..7d84ba37b3 100644 --- a/test/shared/HttpParsingData.cs +++ b/test/shared/HttpParsingData.cs @@ -10,7 +10,7 @@ namespace Microsoft.AspNetCore.Testing { public class HttpParsingData { - public static IEnumerable ValidRequestLineData + public static IEnumerable RequestLineValidData { get { @@ -19,7 +19,7 @@ namespace Microsoft.AspNetCore.Testing "GET", "CUSTOM", }; - var targets = new[] + var paths = new[] { Tuple.Create("/", "/"), Tuple.Create("/abc", "/abc"), @@ -56,21 +56,42 @@ namespace Microsoft.AspNetCore.Testing }; return from method in methods - from target in targets + from path in paths from queryString in queryStrings from httpVersion in httpVersions select new[] { - $"{method} {target.Item1}{queryString} {httpVersion}\r\n", + $"{method} {path.Item1}{queryString} {httpVersion}\r\n", method, - $"{target.Item2}", + $"{path.Item1}{queryString}", + $"{path.Item1}", + $"{path.Item2}", queryString, httpVersion }; } } - public static IEnumerable InvalidRequestLineData => new[] + public static IEnumerable RequestLineIncompleteData => new[] + { + "G", + "GE", + "GET", + "GET ", + "GET /", + "GET / ", + "GET / H", + "GET / HT", + "GET / HTT", + "GET / HTTP", + "GET / HTTP/", + "GET / HTTP/1", + "GET / HTTP/1.", + "GET / HTTP/1.1", + "GET / HTTP/1.1\r", + }; + + public static IEnumerable RequestLineInvalidData => new[] { "G\r\n", "GE\r\n", @@ -140,7 +161,7 @@ namespace Microsoft.AspNetCore.Testing "post= / HTTP/1.0\r\n", }; - public static IEnumerable EncodedNullCharInTargetRequestLines => new[] + public static IEnumerable RequestLineWithEncodedNullCharInTargetData => new[] { "GET /%00 HTTP/1.1\r\n", "GET /%00%00 HTTP/1.1\r\n", @@ -149,17 +170,16 @@ namespace Microsoft.AspNetCore.Testing "GET /%F3%00%82%86 HTTP/1.1\r\n", "GET /%F3%85%00%82 HTTP/1.1\r\n", "GET /%F3%85%82%00 HTTP/1.1\r\n", - "GET /%E8%85%00 HTTP/1.1\r\n", "GET /%E8%01%00 HTTP/1.1\r\n", }; - public static IEnumerable NullCharInTargetRequestLines => new[] - { - "GET \0 HTTP/1.1\r\n", - "GET /\0 HTTP/1.1\r\n", - "GET /\0\0 HTTP/1.1\r\n", - "GET /%C8\0 HTTP/1.1\r\n", - }; + public static IEnumerable RequestLineWithNullCharInTargetData => new[] + { + "GET \0 HTTP/1.1\r\n", + "GET /\0 HTTP/1.1\r\n", + "GET /\0\0 HTTP/1.1\r\n", + "GET /%C8\0 HTTP/1.1\r\n", + }; public static TheoryData UnrecognizedHttpVersionData => new TheoryData { @@ -183,7 +203,7 @@ namespace Microsoft.AspNetCore.Testing "8charact", }; - public static IEnumerable InvalidRequestHeaderData + public static IEnumerable RequestHeaderInvalidData { get { @@ -228,6 +248,7 @@ namespace Microsoft.AspNetCore.Testing "Header-1 value1\r\n\r\n", "Header-1 value1\r\nHeader-2: value2\r\n\r\n", "Header-1: value1\r\nHeader-2 value2\r\n\r\n", + "\n" }; // Starting with whitespace @@ -273,11 +294,11 @@ namespace Microsoft.AspNetCore.Testing return new[] { - Tuple.Create(headersWithLineFolding,"Whitespace is not allowed in header name."), - Tuple.Create(headersWithCRInValue,"Header value must not contain CR characters."), - Tuple.Create(headersWithMissingColon,"No ':' character found in header line."), + Tuple.Create(headersWithLineFolding, "Whitespace is not allowed in header name."), + Tuple.Create(headersWithCRInValue, "Header value must not contain CR characters."), + Tuple.Create(headersWithMissingColon, "No ':' character found in header line."), Tuple.Create(headersStartingWithWhitespace, "Whitespace is not allowed in header name."), - Tuple.Create(headersWithWithspaceInName,"Whitespace is not allowed in header name."), + Tuple.Create(headersWithWithspaceInName, "Whitespace is not allowed in header name."), Tuple.Create(headersNotEndingInCrLfLine, "Headers corrupted, invalid header sequence.") } .SelectMany(t => t.Item1.Select(headers => new[] { headers, t.Item2 })); From 13519b6079043f6b800b70011175912abed57e19 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Tue, 7 Mar 2017 17:39:56 -0800 Subject: [PATCH 1100/1662] Fix CopyTo implementation in benchmark. (#1462) * wip * ooops --- ...pNetCore.Server.Kestrel.Performance.csproj | 3 +- .../RequestParsing.cs | 2 +- .../WritableBufferExtensions.cs | 63 +++++++++++++++++++ 3 files changed, 66 insertions(+), 2 deletions(-) create mode 100644 test/Microsoft.AspNetCore.Server.Kestrel.Performance/WritableBufferExtensions.cs diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Microsoft.AspNetCore.Server.Kestrel.Performance.csproj b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Microsoft.AspNetCore.Server.Kestrel.Performance.csproj index 746c59cd10..e010d7fce2 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Microsoft.AspNetCore.Server.Kestrel.Performance.csproj +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Microsoft.AspNetCore.Server.Kestrel.Performance.csproj @@ -1,4 +1,4 @@ - + @@ -6,6 +6,7 @@ netcoreapp1.1 Exe true + true false diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsing.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsing.cs index 90bd7a16c5..8fc4bc0eea 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsing.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsing.cs @@ -95,7 +95,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance private void InsertData(byte[] bytes) { var buffer = Pipe.Writer.Alloc(2048); - buffer.Write(bytes); + buffer.WriteFast(bytes); // There should not be any backpressure and task completes immediately buffer.FlushAsync().GetAwaiter().GetResult(); } diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/WritableBufferExtensions.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/WritableBufferExtensions.cs new file mode 100644 index 0000000000..04a538e4be --- /dev/null +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/WritableBufferExtensions.cs @@ -0,0 +1,63 @@ +using System; +using System.Collections.Generic; +using System.IO.Pipelines; +using System.Text; + +namespace Microsoft.AspNetCore.Server.Kestrel.Performance +{ + internal static class WritableBufferExtensions + { + public static void WriteFast(this WritableBuffer buffer, ReadOnlySpan source) + { + if (buffer.Memory.IsEmpty) + { + buffer.Ensure(); + } + + // Fast path, try copying to the available memory directly + if (source.Length <= buffer.Memory.Length) + { + source.CopyToFast(buffer.Memory.Span); + buffer.Advance(source.Length); + return; + } + + var remaining = source.Length; + var offset = 0; + + while (remaining > 0) + { + var writable = Math.Min(remaining, buffer.Memory.Length); + + buffer.Ensure(writable); + + if (writable == 0) + { + continue; + } + + source.Slice(offset, writable).CopyToFast(buffer.Memory.Span); + + remaining -= writable; + offset += writable; + + buffer.Advance(writable); + } + } + + private unsafe static void CopyToFast(this ReadOnlySpan source, Span destination) + { + if (destination.Length < source.Length) + { + throw new InvalidOperationException(); + } + + // Assume it fits + fixed (byte* pSource = &source.DangerousGetPinnableReference()) + fixed (byte* pDest = &destination.DangerousGetPinnableReference()) + { + Buffer.MemoryCopy(pSource, pDest, destination.Length, source.Length); + } + } + } +} From 1f0bb14546a41ec9b03294df3874206099b52f0b Mon Sep 17 00:00:00 2001 From: David Fowler Date: Wed, 8 Mar 2017 08:43:11 -0800 Subject: [PATCH 1101/1662] Clean up left over code from port to pipelines (#1465) - Remove unused methods in PipelineExtensions - Remove AwaitableThreadPool since we dispatch reads --- .../Internal/Http/PipelineExtensions.cs | 20 ---------- .../Infrastructure/AwaitableThreadPool.cs | 39 ------------------- 2 files changed, 59 deletions(-) delete mode 100644 src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/AwaitableThreadPool.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/PipelineExtensions.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/PipelineExtensions.cs index a37670cfa6..1a014aff56 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/PipelineExtensions.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/PipelineExtensions.cs @@ -4,9 +4,7 @@ using System; using System.IO.Pipelines; using System.Runtime.CompilerServices; -using System.Threading; using System.Threading.Tasks; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { @@ -48,8 +46,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { var result = await readingTask; - await AwaitableThreadPool.Yield(); - try { if (!result.Buffer.IsEmpty) @@ -71,13 +67,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } } - private static async Task ReadAsyncDispatchedAwaited(ReadableBufferAwaitable awaitable) - { - var result = await awaitable; - await AwaitableThreadPool.Yield(); - return result; - } - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Span ToSpan(this ReadableBuffer buffer) { @@ -88,15 +77,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http return buffer.ToArray(); } - public static ArraySegment ToArraySegment(this ReadableBuffer buffer) - { - if (buffer.IsSingleSpan) - { - return buffer.First.GetArray(); - } - return new ArraySegment(buffer.ToArray()); - } - public static ArraySegment GetArray(this Memory memory) { ArraySegment result; diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/AwaitableThreadPool.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/AwaitableThreadPool.cs deleted file mode 100644 index 70930c73ae..0000000000 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/AwaitableThreadPool.cs +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using System.Runtime.CompilerServices; -using System.Threading.Tasks; - -namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure -{ - internal static class AwaitableThreadPool - { - internal static Awaitable Yield() - { - return new Awaitable(); - } - - internal struct Awaitable : ICriticalNotifyCompletion - { - public void GetResult() - { - - } - - public Awaitable GetAwaiter() => this; - - public bool IsCompleted => false; - - public void OnCompleted(Action continuation) - { - Task.Run(continuation); - } - - public void UnsafeOnCompleted(Action continuation) - { - OnCompleted(continuation); - } - } - } -} \ No newline at end of file From e25eb418bbb0f803fdee775cb721fadcdff1990e Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Tue, 7 Mar 2017 16:23:35 -0800 Subject: [PATCH 1102/1662] Change non-printable char representation in log messages from <0xXX> to \xXX. --- .../Internal/Infrastructure/HttpUtilities.cs | 2 +- .../BadHttpRequestTests.cs | 2 +- .../Microsoft.AspNetCore.Server.KestrelTests/HttpParserTests.cs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/HttpUtilities.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/HttpUtilities.cs index e38ad9fd6e..f93ceafc00 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/HttpUtilities.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/HttpUtilities.cs @@ -124,7 +124,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure for (i = 0; i < Math.Min(span.Length, maxChars); ++i) { var ch = span[i]; - sb.Append(ch < 0x20 || ch >= 0x7F ? $"<0x{ch:X2}>" : ((char)ch).ToString()); + sb.Append(ch < 0x20 || ch >= 0x7F ? $"\\x{ch:X2}" : ((char)ch).ToString()); } if (span.Length > maxChars) diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/BadHttpRequestTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/BadHttpRequestTests.cs index 565b06c2f1..65402a019b 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/BadHttpRequestTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/BadHttpRequestTests.cs @@ -133,7 +133,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests foreach (var requestLine in HttpParsingData.RequestLineInvalidData) { - data.Add(requestLine, $"Invalid request line: {requestLine.Replace("\r", "<0x0D>").Replace("\n", "<0x0A>")}"); + data.Add(requestLine, $"Invalid request line: {requestLine.Replace("\r", "\\x0D").Replace("\n", "\\x0A")}"); } foreach (var requestLine in HttpParsingData.RequestLineWithEncodedNullCharInTargetData) diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/HttpParserTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/HttpParserTests.cs index 7d16b5f06c..b63ecc5d83 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/HttpParserTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/HttpParserTests.cs @@ -108,7 +108,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var exception = Assert.Throws(() => parser.ParseRequestLine(Mock.Of(), buffer, out var consumed, out var examined)); - Assert.Equal($"Invalid request line: {requestLine.Replace("\r", "<0x0D>").Replace("\n", "<0x0A>")}", exception.Message); + Assert.Equal($"Invalid request line: {requestLine.Replace("\r", "\\x0D").Replace("\n", "\\x0A")}", exception.Message); Assert.Equal(StatusCodes.Status400BadRequest, (exception as BadHttpRequestException).StatusCode); } From 0bca84a268d07cd7c0b460a9c9b8f4e0914a1b81 Mon Sep 17 00:00:00 2001 From: arespr Date: Wed, 8 Mar 2017 19:17:12 +0100 Subject: [PATCH 1103/1662] Add HttpUtilities to CodeGenerator --- .../Infrastructure/HttpUtilities.Generated.cs | 62 ++++ .../Internal/Infrastructure/HttpUtilities.cs | 72 +--- ...Microsoft.AspNetCore.Server.Kestrel.csproj | 4 + tools/CodeGenerator/CodeGenerator.csproj | 14 +- .../CombinationsWithoutRepetition.cs | 103 ++++++ .../HttpUtilities/HttpUtilities.cs | 320 ++++++++++++++++++ .../HttpUtilitiesGeneratorHelpers.cs | 217 ++++++++++++ tools/CodeGenerator/Program.cs | 16 +- 8 files changed, 745 insertions(+), 63 deletions(-) create mode 100644 src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/HttpUtilities.Generated.cs create mode 100644 tools/CodeGenerator/HttpUtilities/CombinationsWithoutRepetition.cs create mode 100644 tools/CodeGenerator/HttpUtilities/HttpUtilities.cs create mode 100644 tools/CodeGenerator/HttpUtilities/HttpUtilitiesGeneratorHelpers.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/HttpUtilities.Generated.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/HttpUtilities.Generated.cs new file mode 100644 index 0000000000..c6cec88193 --- /dev/null +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/HttpUtilities.Generated.cs @@ -0,0 +1,62 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Runtime.CompilerServices; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; +namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure +{ + public static partial class HttpUtilities + { + // readonly primitive statics can be Jit'd to consts https://github.com/dotnet/coreclr/issues/1079 + private readonly static ulong _httpConnectMethodLong = GetAsciiStringAsLong("CONNECT "); + private readonly static ulong _httpDeleteMethodLong = GetAsciiStringAsLong("DELETE \0"); + private readonly static ulong _httpHeadMethodLong = GetAsciiStringAsLong("HEAD \0\0\0"); + private readonly static ulong _httpPatchMethodLong = GetAsciiStringAsLong("PATCH \0\0"); + private readonly static ulong _httpPostMethodLong = GetAsciiStringAsLong("POST \0\0\0"); + private readonly static ulong _httpPutMethodLong = GetAsciiStringAsLong("PUT \0\0\0\0"); + private readonly static ulong _httpOptionsMethodLong = GetAsciiStringAsLong("OPTIONS "); + private readonly static ulong _httpTraceMethodLong = GetAsciiStringAsLong("TRACE \0\0"); + + private readonly static ulong _mask8Chars = GetMaskAsLong(new byte[] { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }); + private readonly static ulong _mask7Chars = GetMaskAsLong(new byte[] { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00 }); + private readonly static ulong _mask6Chars = GetMaskAsLong(new byte[] { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00 }); + private readonly static ulong _mask5Chars = GetMaskAsLong(new byte[] { 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00 }); + private readonly static ulong _mask4Chars = GetMaskAsLong(new byte[] { 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00 }); + + private readonly static Tuple[] _knownMethods = new Tuple[17]; + + private readonly static string[] _methodNames = new string[9]; + + static HttpUtilities() + { + SetKnownMethod(_mask4Chars, _httpPutMethodLong, HttpMethod.Put, 3); + SetKnownMethod(_mask5Chars, _httpHeadMethodLong, HttpMethod.Head, 4); + SetKnownMethod(_mask5Chars, _httpPostMethodLong, HttpMethod.Post, 4); + SetKnownMethod(_mask6Chars, _httpPatchMethodLong, HttpMethod.Patch, 5); + SetKnownMethod(_mask6Chars, _httpTraceMethodLong, HttpMethod.Trace, 5); + SetKnownMethod(_mask7Chars, _httpDeleteMethodLong, HttpMethod.Delete, 6); + SetKnownMethod(_mask8Chars, _httpConnectMethodLong, HttpMethod.Connect, 7); + SetKnownMethod(_mask8Chars, _httpOptionsMethodLong, HttpMethod.Options, 7); + FillKnownMethodsGaps(); + _methodNames[(byte)HttpMethod.Connect] = HttpMethods.Connect; + _methodNames[(byte)HttpMethod.Delete] = HttpMethods.Delete; + _methodNames[(byte)HttpMethod.Get] = HttpMethods.Get; + _methodNames[(byte)HttpMethod.Head] = HttpMethods.Head; + _methodNames[(byte)HttpMethod.Options] = HttpMethods.Options; + _methodNames[(byte)HttpMethod.Patch] = HttpMethods.Patch; + _methodNames[(byte)HttpMethod.Post] = HttpMethods.Post; + _methodNames[(byte)HttpMethod.Put] = HttpMethods.Put; + _methodNames[(byte)HttpMethod.Trace] = HttpMethods.Trace; + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static int GetKnownMethodIndex(ulong value) + { + const int magicNumer = 0x600000C; + var tmp = (int)value & magicNumer; + return ((tmp >> 2) | (tmp >> 23)) & 0xF; + } + } +} \ No newline at end of file diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/HttpUtilities.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/HttpUtilities.cs index da9719a841..9d33889fe8 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/HttpUtilities.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/HttpUtilities.cs @@ -5,70 +5,20 @@ using System; using System.Diagnostics; using System.Runtime.CompilerServices; using System.Text; -using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure { - public static class HttpUtilities + public static partial class HttpUtilities { public const string Http10Version = "HTTP/1.0"; public const string Http11Version = "HTTP/1.1"; - - // readonly primitive statics can be Jit'd to consts https://github.com/dotnet/coreclr/issues/1079 - private readonly static ulong _httpConnectMethodLong = GetAsciiStringAsLong("CONNECT "); - private readonly static ulong _httpDeleteMethodLong = GetAsciiStringAsLong("DELETE \0"); private const uint _httpGetMethodInt = 542393671; // retun of GetAsciiStringAsInt("GET "); const results in better codegen - private readonly static ulong _httpHeadMethodLong = GetAsciiStringAsLong("HEAD \0\0\0"); - private readonly static ulong _httpPatchMethodLong = GetAsciiStringAsLong("PATCH \0\0"); - private readonly static ulong _httpPostMethodLong = GetAsciiStringAsLong("POST \0\0\0"); - private readonly static ulong _httpPutMethodLong = GetAsciiStringAsLong("PUT \0\0\0\0"); - private readonly static ulong _httpOptionsMethodLong = GetAsciiStringAsLong("OPTIONS "); - private readonly static ulong _httpTraceMethodLong = GetAsciiStringAsLong("TRACE \0\0"); + private const ulong _http10VersionLong = 3471766442030158920; // GetAsciiStringAsLong("HTTP/1.0"); const results in better codegen private const ulong _http11VersionLong = 3543824036068086856; // GetAsciiStringAsLong("HTTP/1.1"); const results in better codegen - private readonly static ulong _mask8Chars = GetMaskAsLong(new byte[] { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }); - private readonly static ulong _mask7Chars = GetMaskAsLong(new byte[] { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00 }); - private readonly static ulong _mask6Chars = GetMaskAsLong(new byte[] { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00 }); - private readonly static ulong _mask5Chars = GetMaskAsLong(new byte[] { 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00 }); - private readonly static ulong _mask4Chars = GetMaskAsLong(new byte[] { 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00 }); - - private readonly static Tuple[] _knownMethods = new Tuple[17]; - - private readonly static string[] _methodNames = new string[9]; - - static HttpUtilities() - { - SetKnownMethod(_mask4Chars, _httpPutMethodLong, HttpMethod.Put, 3); - SetKnownMethod(_mask5Chars, _httpPostMethodLong, HttpMethod.Post, 4); - SetKnownMethod(_mask5Chars, _httpHeadMethodLong, HttpMethod.Head, 4); - SetKnownMethod(_mask6Chars, _httpTraceMethodLong, HttpMethod.Trace, 5); - SetKnownMethod(_mask6Chars, _httpPatchMethodLong, HttpMethod.Patch, 5); - SetKnownMethod(_mask7Chars, _httpDeleteMethodLong, HttpMethod.Delete, 6); - SetKnownMethod(_mask8Chars, _httpConnectMethodLong, HttpMethod.Connect, 7); - SetKnownMethod(_mask8Chars, _httpOptionsMethodLong, HttpMethod.Options, 7); - FillKnownMethodsGaps(); - _methodNames[(byte)HttpMethod.Get] = HttpMethods.Get; - _methodNames[(byte)HttpMethod.Put] = HttpMethods.Put; - _methodNames[(byte)HttpMethod.Delete] = HttpMethods.Delete; - _methodNames[(byte)HttpMethod.Post] = HttpMethods.Post; - _methodNames[(byte)HttpMethod.Head] = HttpMethods.Head; - _methodNames[(byte)HttpMethod.Trace] = HttpMethods.Trace; - _methodNames[(byte)HttpMethod.Patch] = HttpMethods.Patch; - _methodNames[(byte)HttpMethod.Connect] = HttpMethods.Connect; - _methodNames[(byte)HttpMethod.Options] = HttpMethods.Options; - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - private static int GetKnownMethodIndex(ulong value) - { - const int magicNumer = 0x0600000C; - var tmp = (int)value & magicNumer; - - return ((tmp >> 2) | (tmp >> 23)) & 0x0F; - } [MethodImpl(MethodImplOptions.AggressiveInlining)] private static void SetKnownMethod(ulong mask, ulong knownMethodUlong, HttpMethod knownMethod, int length) @@ -76,6 +26,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure _knownMethods[GetKnownMethodIndex(knownMethodUlong)] = new Tuple(mask, knownMethodUlong, knownMethod, length, true); } + private unsafe static ulong GetMaskAsLong(byte[] bytes) + { + Debug.Assert(bytes.Length == 8, "Mask must be exactly 8 bytes long."); + + fixed (byte* ptr = bytes) + { + return *(ulong*)ptr; + } + } + private static void FillKnownMethodsGaps() { var knownMethods = _knownMethods; @@ -114,15 +74,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure } } - private unsafe static ulong GetMaskAsLong(byte[] bytes) - { - Debug.Assert(bytes.Length == 8, "Mask must be exactly 8 bytes long."); - fixed (byte* ptr = bytes) - { - return *(ulong*)ptr; - } - } public unsafe static string GetAsciiStringNonNullCharacters(this Span span) { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Microsoft.AspNetCore.Server.Kestrel.csproj b/src/Microsoft.AspNetCore.Server.Kestrel/Microsoft.AspNetCore.Server.Kestrel.csproj index 35ccda46b3..93bebcbe0f 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Microsoft.AspNetCore.Server.Kestrel.csproj +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Microsoft.AspNetCore.Server.Kestrel.csproj @@ -11,6 +11,10 @@ CS1591;$(NoWarn) + + + + diff --git a/tools/CodeGenerator/CodeGenerator.csproj b/tools/CodeGenerator/CodeGenerator.csproj index d581f31921..b4d8bf1d86 100644 --- a/tools/CodeGenerator/CodeGenerator.csproj +++ b/tools/CodeGenerator/CodeGenerator.csproj @@ -1,4 +1,4 @@ - + @@ -13,9 +13,21 @@ + + + + $(MSBuildThisFileDirectory)..\..\src\Microsoft.AspNetCore.Server.Kestrel\Internal\Http FrameHeaders.Generated.cs Frame.Generated.cs + + True + + + + True + + diff --git a/tools/CodeGenerator/HttpUtilities/CombinationsWithoutRepetition.cs b/tools/CodeGenerator/HttpUtilities/CombinationsWithoutRepetition.cs new file mode 100644 index 0000000000..b7de0f4c4e --- /dev/null +++ b/tools/CodeGenerator/HttpUtilities/CombinationsWithoutRepetition.cs @@ -0,0 +1,103 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Collections; +using System.Collections.Generic; + +namespace CodeGenerator.HttpUtilities +{ + // C code for Algorithm L (Lexicographic combinations) in Section 7.2.1.3 of The Art of Computer Programming, Volume 4A: Combinatorial Algorithms, Part 1 : + internal class CombinationsWithoutRepetition : IEnumerator + { + private int[] _pointers; + private T[] _nElements; + private readonly int _p; + public T[] Current { get; private set; } + object IEnumerator.Current => Current; + + public CombinationsWithoutRepetition(T[] nElements, int p) + { + if (nElements.Length < p) throw new ArgumentOutOfRangeException(nameof(p)); + + _nElements = nElements; + _p = p; + Current = new T[p]; + ResetCurrent(); + } + + private bool _firstElement; + + public bool MoveNext() + { + if (_firstElement) + { + _firstElement = false; + return true; + } + + var p = _p; + var pointers = _pointers; + var current = Current; + var nElements = _nElements; + var index = 1; + + while (pointers[index] + 1 == pointers[index + 1]) + { + var j1 = index - 1; + + pointers[index] = j1; + current[j1] = nElements[j1]; + ++index; + } + + if (index > p) + { + return false; + } + + current[index - 1] = nElements[++pointers[index]]; + + return true; + } + + private void ResetCurrent() + { + var p = _p; + if (_pointers == null) + _pointers = new int[p + 3]; + + var pointers = _pointers; + var current = Current; + var nElements = _nElements; + + pointers[0] = 0; + for (int j = 1; j <= _p; j++) + { + pointers[j] = j - 1; + } + pointers[_p + 1] = nElements.Length; + pointers[_p + 2] = 0; + + for (int j = _p; j > 0; j--) + { + current[j - 1] = nElements[pointers[j]]; + } + _firstElement = true; + } + + public void Reset() + { + Array.Clear(Current, 0, Current.Length); + Current = null; + ResetCurrent(); + } + + public void Dispose() + { + _nElements = null; + Current = null; + _pointers = null; + } + } +} diff --git a/tools/CodeGenerator/HttpUtilities/HttpUtilities.cs b/tools/CodeGenerator/HttpUtilities/HttpUtilities.cs new file mode 100644 index 0000000000..2c674fc71b --- /dev/null +++ b/tools/CodeGenerator/HttpUtilities/HttpUtilities.cs @@ -0,0 +1,320 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Text; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; + +namespace CodeGenerator.HttpUtilities +{ + public class HttpUtilities + { + public static string GeneratedFile() + { + var httpMethods = new [] + { + new Tuple("CONNECT ", HttpMethod.Connect), + new Tuple("DELETE ", HttpMethod.Delete), + new Tuple("HEAD ", HttpMethod.Head), + new Tuple("PATCH ", HttpMethod.Patch), + new Tuple("POST ", HttpMethod.Post), + new Tuple("PUT ", HttpMethod.Put), + new Tuple("OPTIONS ", HttpMethod.Options), + new Tuple("TRACE ", HttpMethod.Trace), + new Tuple("GET ", HttpMethod.Get) + }; + + return GenerateFile(httpMethods); + } + + private static string GenerateFile(Tuple[] httpMethods) + { + var maskLength = (byte)Math.Ceiling(Math.Log(httpMethods.Length, 2)); + + var methodsInfo = httpMethods.Select(GetMethodStringAndUlongAndMaskLength).ToList(); + + var methodsInfoWithoutGet = methodsInfo.Where(m => m.HttpMethod != HttpMethod.Get.ToString()).ToList(); + + var methodsAsciiStringAsLong = methodsInfo.Select(m => m.AsciiStringAsLong).ToArray(); + + var mask = HttpUtilitiesGeneratorHelpers.SearchKeyByLookThroughMaskCombinations(methodsAsciiStringAsLong, 0, sizeof(ulong) * 8, maskLength); + + if (mask.HasValue == false) + { + throw new InvalidOperationException(string.Format("Generated {0} not found.", nameof(mask))); + } + + var functionGetKnownMethodIndex = GetFunctionBodyGetKnownMethodIndex(mask.Value); + + var methodsSection = GetMethodsSection(methodsInfoWithoutGet); + + var masksSection = GetMasksSection(methodsInfoWithoutGet); + + var setKnownMethodSection = GetSetKnownMethodSection(methodsInfoWithoutGet); + var methodNamesSection = GetMethodNamesSection(methodsInfo); + + int knownMethodsArrayLength = (int)(Math.Pow(2, maskLength) + 1); + int methodNamesArrayLength = httpMethods.Length; + + return string.Format(@"// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Runtime.CompilerServices; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; +namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure +{{ + public static partial class HttpUtilities + {{ + // readonly primitive statics can be Jit'd to consts https://github.com/dotnet/coreclr/issues/1079 +{0} + +{1} + + private readonly static Tuple[] _knownMethods = new Tuple[{2}]; + + private readonly static string[] _methodNames = new string[{3}]; + + static HttpUtilities() + {{ +{4} + FillKnownMethodsGaps(); +{5} + }} + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static int GetKnownMethodIndex(ulong value) + {{ +{6} + }} + }} +}}", methodsSection, masksSection, knownMethodsArrayLength, methodNamesArrayLength, setKnownMethodSection, methodNamesSection, functionGetKnownMethodIndex); + } + + private static string GetMethodsSection(List methodsInfo) + { + var result = new StringBuilder(); + + for (var index = 0; index < methodsInfo.Count; index++) + { + var methodInfo = methodsInfo[index]; + + var httpMethodFieldName = GetHttpMethodFieldName(methodInfo); + result.AppendFormat("\t\tprivate readonly static ulong {0} = GetAsciiStringAsLong(\"{1}\");", httpMethodFieldName, methodInfo.MethodAsciiString.Replace("\0", "\\0")); + + if (index < methodsInfo.Count - 1) + { + result.AppendLine(); + } + } + + return result.ToString(); + } + + private static string GetMasksSection(List methodsInfo) + { + var distinctLengths = methodsInfo.Select(m => m.MaskLength).Distinct().ToList(); + + distinctLengths.Sort((t1, t2) => -t1.CompareTo(t2)); + + var result = new StringBuilder(); + + for (var index = 0; index < distinctLengths.Count; index++) + { + var maskBytesLength = distinctLengths[index]; + var maskArray = GetMaskArray(maskBytesLength); + + var hexMaskString = HttpUtilitiesGeneratorHelpers.GeHexString(maskArray, "0x", ", "); + var maskFieldName = GetMaskFieldName(maskBytesLength); + + result.AppendFormat("\t\tprivate readonly static ulong {0} = GetMaskAsLong(new byte[] {{ {1} }});", maskFieldName, hexMaskString); + + if (index < distinctLengths.Count - 1) + { + result.AppendLine(); + } + } + + return result.ToString(); + } + + private static string GetSetKnownMethodSection(List methodsInfo) + { + methodsInfo = methodsInfo.ToList(); + + methodsInfo.Sort((t1, t2) => t1.MaskLength.CompareTo(t2.MaskLength)); + + var result = new StringBuilder(); + + for (var index = 0; index < methodsInfo.Count; index++) + { + var methodInfo = methodsInfo[index]; + var maskFieldName = GetMaskFieldName(methodInfo.MaskLength); + var httpMethodFieldName = GetHttpMethodFieldName(methodInfo); + + result.AppendFormat("\t\t\tSetKnownMethod({0}, {1}, {2}.{3}, {4});", maskFieldName, httpMethodFieldName, typeof(HttpMethod).Name, methodInfo.HttpMethod, methodInfo.MaskLength - 1); + + if (index < methodsInfo.Count - 1) + { + result.AppendLine(); + } + } + + return result.ToString(); + } + + private static string GetMethodNamesSection(List methodsInfo) + { + methodsInfo = methodsInfo.ToList(); + + methodsInfo.Sort((t1, t2) => t1.HttpMethod.CompareTo(t2.HttpMethod)); + + var result = new StringBuilder(); + + for (var index = 0; index < methodsInfo.Count; index++) + { + var methodInfo = methodsInfo[index]; + + result.AppendFormat("\t\t\t_methodNames[(byte){0}.{1}] = {2}.{3};", typeof(HttpMethod).Name, methodInfo.HttpMethod, typeof(HttpMethods).Name, methodInfo.HttpMethod); + + if (index < methodsInfo.Count - 1) + { + result.AppendLine(); + } + } + + return result.ToString(); + } + + private static string GetFunctionBodyGetKnownMethodIndex(ulong mask) + { + var shifts = HttpUtilitiesGeneratorHelpers.GetShifts(mask); + + var maskHexString = HttpUtilitiesGeneratorHelpers.MaskToHexString(mask); + + string bodyString; + + if (shifts.Length > 0) + { + var bitsCount = HttpUtilitiesGeneratorHelpers.CountBits(mask); + + var tmpReturn = string.Empty; + foreach (var item in shifts) + { + if (tmpReturn.Length > 0) + { + tmpReturn += " | "; + } + + tmpReturn += string.Format("(tmp >> {1})", HttpUtilitiesGeneratorHelpers.MaskToHexString(item.Mask), item.Shift); + } + + var mask2 = (ulong)(Math.Pow(2, bitsCount) - 1); + + string returnString = string.Format("return ({0}) & {1};", tmpReturn, HttpUtilitiesGeneratorHelpers.MaskToHexString(mask2)); + + bodyString = string.Format("const int magicNumer = {0};\r\n\t\t\tvar tmp = (int)value & magicNumer;\r\n\t\t\t{1}", HttpUtilitiesGeneratorHelpers.MaskToHexString(mask), returnString); + + } + else + { + bodyString = string.Format("return (int)(value & {0});", maskHexString); + } + + return bodyString; + } + + private static string GetHttpMethodFieldName(MethodInfo methodsInfo) + { + return string.Format("_http{0}MethodLong", methodsInfo.HttpMethod.ToString()); + } + + private static string GetMaskFieldName(int nBytes) + { + return string.Format("_mask{0}Chars", nBytes); + } + + private static string GetMethodString(string method) + { + if (method == null) + { + throw new ArgumentNullException(nameof(method)); + } + + const int length = sizeof(ulong); + + if (method.Length > length) + { + throw new ArgumentException(string.Format("MethodAsciiString {0} length is greather than {1}", method, length)); + } + string result = method; + + if (result.Length == length) + { + return result; + } + + if (result.Length < length) + { + var count = length - result.Length; + + for (int i = 0; i < count; i++) + { + result += "\0"; + } + } + + return result; + } + + private class MethodInfo + { + public string MethodAsciiString; + public ulong AsciiStringAsLong; + public string HttpMethod; + public int MaskLength; + } + + private static MethodInfo GetMethodStringAndUlongAndMaskLength(Tuple method) + { + var methodString = GetMethodString(method.Item1); + + var asciiAsLong = GetAsciiStringAsLong(methodString); + + return new MethodInfo + { + MethodAsciiString = methodString, + AsciiStringAsLong = asciiAsLong, + HttpMethod = method.Item2.ToString(), + MaskLength = method.Item1.Length + }; + } + + private static byte[] GetMaskArray(int n, int length = sizeof(ulong)) + { + var maskArray = new byte[length]; + for (int i = 0; i < n; i++) + { + maskArray[i] = 0xff; + } + return maskArray; + } + + private unsafe static ulong GetAsciiStringAsLong(string str) + { + Debug.Assert(str.Length == sizeof(ulong), string.Format("String must be exactly {0} (ASCII) characters long.", sizeof(ulong))); + + var bytes = Encoding.ASCII.GetBytes(str); + + fixed (byte* ptr = &bytes[0]) + { + return *(ulong*)ptr; + } + } + } +} \ No newline at end of file diff --git a/tools/CodeGenerator/HttpUtilities/HttpUtilitiesGeneratorHelpers.cs b/tools/CodeGenerator/HttpUtilities/HttpUtilitiesGeneratorHelpers.cs new file mode 100644 index 0000000000..0cadd80aa0 --- /dev/null +++ b/tools/CodeGenerator/HttpUtilities/HttpUtilitiesGeneratorHelpers.cs @@ -0,0 +1,217 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Collections.Generic; +using System.Runtime.CompilerServices; +using System.Text; + +namespace CodeGenerator.HttpUtilities +{ + internal class HttpUtilitiesGeneratorHelpers + { + public class ShiftInfo + { + public TMask Mask; + public byte Shift; + } + + public static ShiftInfo[] GetShifts(ulong mask) + { + var shifts = new List>(); + + const ulong one = 0x01; + + ulong currentMask = 0; + + int currentBitsCount = 0; + int lastShift = 0; + for (int i = 0; i < sizeof(ulong) * 8; i++) + { + var currentBitMask = one << i; + bool isCurrentBit0 = (currentBitMask & mask) == 0; + + if (isCurrentBit0 == false) + { + currentMask |= currentBitMask; + currentBitsCount++; + } + else if (currentBitsCount > 0) + { + var currentShift = (byte)(i - currentBitsCount - lastShift); + shifts.Add(new ShiftInfo + { + Mask = currentMask, + Shift = currentShift + }); + lastShift = currentShift; + currentMask = 0; + currentBitsCount = 0; + } + } + + return shifts.ToArray(); + } + + public static ulong? SearchKeyByLookThroughMaskCombinations(ulong[] values, byte bitsIndexStart, byte bitsLength, byte bitsCount) + { + if (bitsIndexStart + bitsLength > sizeof(ulong) * 8) + { + throw new ArgumentOutOfRangeException(nameof(bitsIndexStart)); + } + + if (bitsLength < bitsCount || bitsCount == 0) + { + throw new ArgumentOutOfRangeException(nameof(bitsCount)); + } + + var bits = new byte[bitsLength]; + + for (byte i = bitsIndexStart; i < bitsIndexStart + bitsLength; i++) + { + bits[i - bitsIndexStart] = i; + } + + var combinations = new CombinationsWithoutRepetition(bits, bitsCount); + + ulong? maskFound = null; + int bit1ChunksFoundMask = 0; + + int arrayLength = values.Length; + + var mashHash = new HashSet(); + + while (combinations.MoveNext()) + { + var bitsCombination = combinations.Current; + + ulong currentMask = 0; + + for (int i = 0; i < bitsCombination.Length; i++) + { + var index = bitsCombination[i]; + + const ulong oneBit = 0x01; + + currentMask |= oneBit << index; + } + + mashHash.Clear(); + bool invalidMask = false; + for (int j = 0; j < arrayLength; j++) + { + var tmp = values[j] & currentMask; + + bool alreadyExists = mashHash.Add(tmp) == false; + if (alreadyExists) + { + invalidMask = true; + break; + } + } + + if (invalidMask == false) + { + var bit1Chunks = CountBit1Chunks(currentMask); + + if (maskFound.HasValue) + { + if (bit1ChunksFoundMask > bit1Chunks) + { + maskFound = currentMask; + bit1ChunksFoundMask = bit1Chunks; + if (bit1ChunksFoundMask == 0) + { + return maskFound; + } + } + } + else + { + maskFound = currentMask; + bit1ChunksFoundMask = bit1Chunks; + + if (bit1ChunksFoundMask == 0) + { + return maskFound; + } + } + } + } + + return maskFound; + } + + public static int CountBit1Chunks(ulong mask) + { + int currentBitsCount = 0; + + int chunks = 0; + + for (int i = 0; i < sizeof(ulong) * 8; i++) + { + const ulong oneBit = 0x01; + + var currentBitMask = oneBit << i; + bool isCurrentBit0 = (currentBitMask & mask) == 0; + + if (isCurrentBit0 == false) + { + currentBitsCount++; + } + else if (currentBitsCount > 0) + { + chunks++; + currentBitsCount = 0; + } + } + + return chunks; + } + + public static string GeHexString(byte[] array, string prefix, string separator) + { + var result = new StringBuilder(); + int i = 0; + for (; i < array.Length - 1; i++) + { + result.AppendFormat("{0}{1:x2}", prefix, array[i]); + result.Append(separator); + } + + if (array.Length > 0) + { + result.AppendFormat("{0}{1:x2}", prefix, array[i]); + } + + return result.ToString(); + } + + public static string MaskToString(ulong mask) + { + var maskSizeInBIts = Math.Log(mask, 2); + var hexMaskSize = Math.Ceiling(maskSizeInBIts / 4.0); + return string.Format("0x{0:X" + hexMaskSize + "}", mask); + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int CountBits(ulong v) + { + const ulong Mask01010101 = 0x5555555555555555UL; + const ulong Mask00110011 = 0x3333333333333333UL; + const ulong Mask00001111 = 0x0F0F0F0F0F0F0F0FUL; + const ulong Mask00000001 = 0x0101010101010101UL; + v = v - ((v >> 1) & Mask01010101); + v = (v & Mask00110011) + ((v >> 2) & Mask00110011); + return (int)(unchecked(((v + (v >> 4)) & Mask00001111) * Mask00000001) >> 56); + } + + public static string MaskToHexString(ulong mask) + { + var maskSizeInBIts = Math.Log(mask, 2); + var hexMaskSize = (byte)Math.Ceiling(maskSizeInBIts / 4); + + return string.Format("0x{0:X" + (hexMaskSize == 0 ? 1 : hexMaskSize) + "}", mask); + } + } +} diff --git a/tools/CodeGenerator/Program.cs b/tools/CodeGenerator/Program.cs index a057b078c6..24be8360b9 100644 --- a/tools/CodeGenerator/Program.cs +++ b/tools/CodeGenerator/Program.cs @@ -20,16 +20,22 @@ namespace CodeGenerator Console.Error.WriteLine("Missing path to Frame.Generated.cs"); return 1; } + else if (args.Length < 3) + { + Console.Error.WriteLine("Missing path to HttpUtilities.Generated.cs"); + return 1; + } - Run(args[0], args[1]); + Run(args[0], args[1], args[2]); return 0; } - public static void Run(string knownHeadersPath, string frameFeaturesCollectionPath) + public static void Run(string knownHeadersPath, string frameFeaturesCollectionPath, string httpUtilitiesPath) { var knownHeadersContent = KnownHeaders.GeneratedFile(); var frameFeatureCollectionContent = FrameFeatureCollection.GeneratedFile(); + var httpUtilitiesContent = HttpUtilities.HttpUtilities.GeneratedFile(); var existingKnownHeaders = File.Exists(knownHeadersPath) ? File.ReadAllText(knownHeadersPath) : ""; if (!string.Equals(knownHeadersContent, existingKnownHeaders)) @@ -42,6 +48,12 @@ namespace CodeGenerator { File.WriteAllText(frameFeaturesCollectionPath, frameFeatureCollectionContent); } + + var existingHttpUtilities = File.Exists(httpUtilitiesPath) ? File.ReadAllText(httpUtilitiesPath) : ""; + if (!string.Equals(httpUtilitiesContent, existingHttpUtilities)) + { + File.WriteAllText(httpUtilitiesPath, httpUtilitiesContent); + } } } } From dbcf34388eccef4d8a102f334841a7d801d82013 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Wed, 8 Mar 2017 12:38:55 -0800 Subject: [PATCH 1104/1662] Remove dependency on Utf8String (#1466) - Also remove System.IO.Pipelines.Text.Primitives --- .../Internal/Http/Frame.cs | 17 +++++++++++++++-- .../Microsoft.AspNetCore.Server.Kestrel.csproj | 1 - 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs index 463ce0a237..bc6757b30e 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs @@ -6,7 +6,6 @@ using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.IO.Pipelines; -using System.IO.Pipelines.Text.Primitives; using System.Linq; using System.Net; using System.Runtime.CompilerServices; @@ -1232,7 +1231,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http // URI was encoded, unescape and then parse as utf8 int pathLength = UrlEncoder.Decode(path, path); - requestUrlPath = new Utf8String(path.Slice(0, pathLength)).ToString(); + requestUrlPath = GetUtf8String(path.Slice(0, pathLength)); } else { @@ -1282,6 +1281,20 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } } + private unsafe static string GetUtf8String(Span path) + { + // .NET 451 doesn't have pointer overloads for Encoding.GetString so we + // copy to an array +#if NET451 + return Encoding.UTF8.GetString(path.ToArray()); +#else + fixed (byte* pointer = &path.DangerousGetPinnableReference()) + { + return Encoding.UTF8.GetString(pointer, path.Length); + } +#endif + } + public void OnHeader(Span name, Span value) { _requestHeadersParsed++; diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Microsoft.AspNetCore.Server.Kestrel.csproj b/src/Microsoft.AspNetCore.Server.Kestrel/Microsoft.AspNetCore.Server.Kestrel.csproj index 35ccda46b3..beacc7f230 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Microsoft.AspNetCore.Server.Kestrel.csproj +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Microsoft.AspNetCore.Server.Kestrel.csproj @@ -19,7 +19,6 @@ - From e9250323e0e739afd4627b548bf8d2f872182886 Mon Sep 17 00:00:00 2001 From: arespr Date: Wed, 8 Mar 2017 22:20:43 +0100 Subject: [PATCH 1105/1662] update GeneratedCodeTests --- .../Infrastructure/HttpUtilities.Generated.cs | 23 ++++++++++++++----- .../GeneratedCodeTests.cs | 11 ++++++--- .../HttpUtilities/HttpUtilities.cs | 17 +++++++------- 3 files changed, 34 insertions(+), 17 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/HttpUtilities.Generated.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/HttpUtilities.Generated.cs index c6cec88193..73cc726ad8 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/HttpUtilities.Generated.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/HttpUtilities.Generated.cs @@ -5,6 +5,7 @@ using System; using System.Runtime.CompilerServices; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; + namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure { public static partial class HttpUtilities @@ -19,13 +20,23 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure private readonly static ulong _httpOptionsMethodLong = GetAsciiStringAsLong("OPTIONS "); private readonly static ulong _httpTraceMethodLong = GetAsciiStringAsLong("TRACE \0\0"); - private readonly static ulong _mask8Chars = GetMaskAsLong(new byte[] { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }); - private readonly static ulong _mask7Chars = GetMaskAsLong(new byte[] { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00 }); - private readonly static ulong _mask6Chars = GetMaskAsLong(new byte[] { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00 }); - private readonly static ulong _mask5Chars = GetMaskAsLong(new byte[] { 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00 }); - private readonly static ulong _mask4Chars = GetMaskAsLong(new byte[] { 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00 }); + private readonly static ulong _mask8Chars = GetMaskAsLong(new byte[] + {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}); - private readonly static Tuple[] _knownMethods = new Tuple[17]; + private readonly static ulong _mask7Chars = GetMaskAsLong(new byte[] + {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00}); + + private readonly static ulong _mask6Chars = GetMaskAsLong(new byte[] + {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00}); + + private readonly static ulong _mask5Chars = GetMaskAsLong(new byte[] + {0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00}); + + private readonly static ulong _mask4Chars = GetMaskAsLong(new byte[] + {0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00}); + + private readonly static Tuple[] _knownMethods = + new Tuple[17]; private readonly static string[] _methodNames = new string[9]; diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/GeneratedCodeTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/GeneratedCodeTests.cs index 3fa3d89026..b3575f6f5e 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/GeneratedCodeTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/GeneratedCodeTests.cs @@ -15,27 +15,32 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { const string frameHeadersGeneratedPath = "../../../../../src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameHeaders.Generated.cs"; const string frameGeneratedPath = "../../../../../src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.Generated.cs"; - + const string httpUtilitiesGeneratedPath = "../../../../../src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/HttpUtilities.Generated.cs"; var testFrameHeadersGeneratedPath = Path.GetTempFileName(); var testFrameGeneratedPath = Path.GetTempFileName(); - + var testHttpUtilitiesGeneratedPath = Path.GetTempFileName(); try { var currentFrameHeadersGenerated = File.ReadAllText(frameHeadersGeneratedPath); var currentFrameGenerated = File.ReadAllText(frameGeneratedPath); + var currentHttpUtilitiesGenerated = File.ReadAllText(httpUtilitiesGeneratedPath); - CodeGenerator.Program.Run(testFrameHeadersGeneratedPath, testFrameGeneratedPath); + CodeGenerator.Program.Run(testFrameHeadersGeneratedPath, testFrameGeneratedPath, testHttpUtilitiesGeneratedPath); var testFrameHeadersGenerated = File.ReadAllText(testFrameHeadersGeneratedPath); var testFrameGenerated = File.ReadAllText(testFrameGeneratedPath); + var testHttpUtilitiesGenerated = File.ReadAllText(testHttpUtilitiesGeneratedPath); Assert.Equal(currentFrameHeadersGenerated, testFrameHeadersGenerated, ignoreLineEndingDifferences: true); Assert.Equal(currentFrameGenerated, testFrameGenerated, ignoreLineEndingDifferences: true); + Assert.Equal(currentHttpUtilitiesGenerated, testHttpUtilitiesGenerated, ignoreLineEndingDifferences: true); + } finally { File.Delete(testFrameHeadersGeneratedPath); File.Delete(testFrameGeneratedPath); + File.Delete(testHttpUtilitiesGeneratedPath); } } } diff --git a/tools/CodeGenerator/HttpUtilities/HttpUtilities.cs b/tools/CodeGenerator/HttpUtilities/HttpUtilities.cs index 2c674fc71b..ddc0c62753 100644 --- a/tools/CodeGenerator/HttpUtilities/HttpUtilities.cs +++ b/tools/CodeGenerator/HttpUtilities/HttpUtilities.cs @@ -67,6 +67,7 @@ using System; using System.Runtime.CompilerServices; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; + namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure {{ public static partial class HttpUtilities @@ -75,8 +76,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure {0} {1} - - private readonly static Tuple[] _knownMethods = new Tuple[{2}]; + private readonly static Tuple[] _knownMethods = + new Tuple[{2}]; private readonly static string[] _methodNames = new string[{3}]; @@ -105,7 +106,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure var methodInfo = methodsInfo[index]; var httpMethodFieldName = GetHttpMethodFieldName(methodInfo); - result.AppendFormat("\t\tprivate readonly static ulong {0} = GetAsciiStringAsLong(\"{1}\");", httpMethodFieldName, methodInfo.MethodAsciiString.Replace("\0", "\\0")); + result.AppendFormat(" private readonly static ulong {0} = GetAsciiStringAsLong(\"{1}\");", httpMethodFieldName, methodInfo.MethodAsciiString.Replace("\0", "\\0")); if (index < methodsInfo.Count - 1) { @@ -132,8 +133,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure var hexMaskString = HttpUtilitiesGeneratorHelpers.GeHexString(maskArray, "0x", ", "); var maskFieldName = GetMaskFieldName(maskBytesLength); - result.AppendFormat("\t\tprivate readonly static ulong {0} = GetMaskAsLong(new byte[] {{ {1} }});", maskFieldName, hexMaskString); - + result.AppendFormat(" private readonly static ulong {0} = GetMaskAsLong(new byte[]\r\n {{{1}}});", maskFieldName, hexMaskString); + result.AppendLine(); if (index < distinctLengths.Count - 1) { result.AppendLine(); @@ -157,7 +158,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure var maskFieldName = GetMaskFieldName(methodInfo.MaskLength); var httpMethodFieldName = GetHttpMethodFieldName(methodInfo); - result.AppendFormat("\t\t\tSetKnownMethod({0}, {1}, {2}.{3}, {4});", maskFieldName, httpMethodFieldName, typeof(HttpMethod).Name, methodInfo.HttpMethod, methodInfo.MaskLength - 1); + result.AppendFormat(" SetKnownMethod({0}, {1}, {2}.{3}, {4});", maskFieldName, httpMethodFieldName, typeof(HttpMethod).Name, methodInfo.HttpMethod, methodInfo.MaskLength - 1); if (index < methodsInfo.Count - 1) { @@ -180,7 +181,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure { var methodInfo = methodsInfo[index]; - result.AppendFormat("\t\t\t_methodNames[(byte){0}.{1}] = {2}.{3};", typeof(HttpMethod).Name, methodInfo.HttpMethod, typeof(HttpMethods).Name, methodInfo.HttpMethod); + result.AppendFormat(" _methodNames[(byte){0}.{1}] = {2}.{3};", typeof(HttpMethod).Name, methodInfo.HttpMethod, typeof(HttpMethods).Name, methodInfo.HttpMethod); if (index < methodsInfo.Count - 1) { @@ -218,7 +219,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure string returnString = string.Format("return ({0}) & {1};", tmpReturn, HttpUtilitiesGeneratorHelpers.MaskToHexString(mask2)); - bodyString = string.Format("const int magicNumer = {0};\r\n\t\t\tvar tmp = (int)value & magicNumer;\r\n\t\t\t{1}", HttpUtilitiesGeneratorHelpers.MaskToHexString(mask), returnString); + bodyString = string.Format(" const int magicNumer = {0};\r\n var tmp = (int)value & magicNumer;\r\n {1}", HttpUtilitiesGeneratorHelpers.MaskToHexString(mask), returnString); } else From bb973decb8c10716a17d1d236729a32c5a22afb7 Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Tue, 7 Mar 2017 17:25:15 -0800 Subject: [PATCH 1106/1662] Unify header rejection messages. - Log bad headers with escaped non-vchar characters --- .../BadHttpRequestException.cs | 30 +--- .../Internal/Http/KestrelHttpParser.cs | 44 +++-- .../Internal/Http/RequestRejectionReason.cs | 10 +- .../BadHttpRequestTests.cs | 2 +- .../FrameTests.cs | 19 --- .../HttpParserTests.cs | 9 +- test/shared/HttpParsingData.cs | 161 ++++++++---------- 7 files changed, 109 insertions(+), 166 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/BadHttpRequestException.cs b/src/Microsoft.AspNetCore.Server.Kestrel/BadHttpRequestException.cs index 54533f05e1..09aaf94a45 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/BadHttpRequestException.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/BadHttpRequestException.cs @@ -22,20 +22,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel BadHttpRequestException ex; switch (reason) { - case RequestRejectionReason.HeadersCorruptedInvalidHeaderSequence: - ex = new BadHttpRequestException("Headers corrupted, invalid header sequence.", StatusCodes.Status400BadRequest); - break; - case RequestRejectionReason.NoColonCharacterFoundInHeaderLine: - ex = new BadHttpRequestException("No ':' character found in header line.", StatusCodes.Status400BadRequest); - break; - case RequestRejectionReason.WhitespaceIsNotAllowedInHeaderName: - ex = new BadHttpRequestException("Whitespace is not allowed in header name.", StatusCodes.Status400BadRequest); - break; - case RequestRejectionReason.HeaderValueMustNotContainCR: - ex = new BadHttpRequestException("Header value must not contain CR characters.", StatusCodes.Status400BadRequest); - break; - case RequestRejectionReason.HeaderValueLineFoldingNotSupported: - ex = new BadHttpRequestException("Header value line folding not supported.", StatusCodes.Status400BadRequest); + case RequestRejectionReason.InvalidRequestHeadersNoCRLF: + ex = new BadHttpRequestException("Invalid request headers: missing final CRLF in header fields.", StatusCodes.Status400BadRequest); break; case RequestRejectionReason.InvalidRequestLine: ex = new BadHttpRequestException("Invalid request line.", StatusCodes.Status400BadRequest); @@ -58,24 +46,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel case RequestRejectionReason.ChunkedRequestIncomplete: ex = new BadHttpRequestException("Chunked request incomplete.", StatusCodes.Status400BadRequest); break; - case RequestRejectionReason.PathContainsNullCharacters: - ex = new BadHttpRequestException("The path contains null characters.", StatusCodes.Status400BadRequest); - break; case RequestRejectionReason.InvalidCharactersInHeaderName: ex = new BadHttpRequestException("Invalid characters in header name.", StatusCodes.Status400BadRequest); break; - case RequestRejectionReason.NonAsciiOrNullCharactersInInputString: - ex = new BadHttpRequestException("The input string contains non-ASCII or null characters.", StatusCodes.Status400BadRequest); - break; case RequestRejectionReason.RequestLineTooLong: ex = new BadHttpRequestException("Request line too long.", StatusCodes.Status414UriTooLong); break; case RequestRejectionReason.HeadersExceedMaxTotalSize: ex = new BadHttpRequestException("Request headers too long.", StatusCodes.Status431RequestHeaderFieldsTooLarge); break; - case RequestRejectionReason.MissingCRInHeaderLine: - ex = new BadHttpRequestException("No CR character found in header line.", StatusCodes.Status400BadRequest); - break; case RequestRejectionReason.TooManyHeaders: ex = new BadHttpRequestException("Request contains too many headers.", StatusCodes.Status431RequestHeaderFieldsTooLarge); break; @@ -95,7 +74,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel switch (reason) { case RequestRejectionReason.InvalidRequestLine: - ex = new BadHttpRequestException($"Invalid request line: {value}", StatusCodes.Status400BadRequest); + ex = new BadHttpRequestException($"Invalid request line: '{value}'", StatusCodes.Status400BadRequest); + break; + case RequestRejectionReason.InvalidRequestHeader: + ex = new BadHttpRequestException($"Invalid request header: '{value}'", StatusCodes.Status400BadRequest); break; case RequestRejectionReason.InvalidContentLength: ex = new BadHttpRequestException($"Invalid content length: {value}", StatusCodes.Status400BadRequest); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/KestrelHttpParser.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/KestrelHttpParser.cs index a5ce732aec..79ecd4b9f0 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/KestrelHttpParser.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/KestrelHttpParser.cs @@ -316,11 +316,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } // Headers don't end in CRLF line. - RejectRequest(RequestRejectionReason.HeadersCorruptedInvalidHeaderSequence); - } - else if(ch1 == ByteSpace || ch1 == ByteTab) - { - RejectRequest(RequestRejectionReason.WhitespaceIsNotAllowedInHeaderName); + RejectRequest(RequestRejectionReason.InvalidRequestHeadersNoCRLF); } // We moved the reader so look ahead 2 bytes so reset both the reader @@ -390,7 +386,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } [MethodImpl(MethodImplOptions.AggressiveInlining)] - private static unsafe int FindEndOfName(byte* headerLine, int length) + private unsafe int FindEndOfName(byte* headerLine, int length) { var index = 0; var sawWhitespace = false; @@ -407,14 +403,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } } - if (index == length) + if (index == length || sawWhitespace) { - RejectRequest(RequestRejectionReason.NoColonCharacterFoundInHeaderLine); - } - if (sawWhitespace) - { - RejectRequest(RequestRejectionReason.WhitespaceIsNotAllowedInHeaderName); + RejectRequestHeader(headerLine, length); } + return index; } @@ -427,11 +420,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if (headerLine[valueEnd + 2] != ByteLF) { - RejectRequest(RequestRejectionReason.HeaderValueMustNotContainCR); + RejectRequestHeader(headerLine, length); } if (headerLine[valueEnd + 1] != ByteCR) { - RejectRequest(RequestRejectionReason.MissingCRInHeaderLine); + RejectRequestHeader(headerLine, length); } // Skip colon from value start @@ -446,16 +439,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } else if (ch == ByteCR) { - RejectRequest(RequestRejectionReason.HeaderValueMustNotContainCR); + RejectRequestHeader(headerLine, length); } } - // Check for CR in value var i = valueStart + 1; if (Contains(headerLine + i, valueEnd - i, ByteCR)) { - RejectRequest(RequestRejectionReason.HeaderValueMustNotContainCR); + RejectRequestHeader(headerLine, length); } // Ignore end whitespace @@ -557,9 +549,25 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http Log.IsEnabled(LogLevel.Information) ? span.GetAsciiStringEscaped(MaxRequestLineError) : string.Empty); } + private unsafe void RejectRequestHeader(byte* headerLine, int length) + { + RejectRequestHeader(new Span(headerLine, length)); + } + + private void RejectRequestHeader(Span span) + { + throw GetRejectRequestHeaderException(span); + } + + private BadHttpRequestException GetRejectRequestHeaderException(Span span) + { + const int MaxRequestHeaderError = 128; + return BadHttpRequestException.GetException(RequestRejectionReason.InvalidRequestHeader, + Log.IsEnabled(LogLevel.Information) ? span.GetAsciiStringEscaped(MaxRequestHeaderError) : string.Empty); + } + public void Reset() { - } [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/RequestRejectionReason.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/RequestRejectionReason.cs index b0aa5a1372..92faea1965 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/RequestRejectionReason.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/RequestRejectionReason.cs @@ -6,12 +6,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http public enum RequestRejectionReason { UnrecognizedHTTPVersion, - HeadersCorruptedInvalidHeaderSequence, - NoColonCharacterFoundInHeaderLine, - WhitespaceIsNotAllowedInHeaderName, - HeaderValueMustNotContainCR, - HeaderValueLineFoldingNotSupported, InvalidRequestLine, + InvalidRequestHeader, + InvalidRequestHeadersNoCRLF, MalformedRequestInvalidHeaders, InvalidContentLength, MultipleContentLengths, @@ -19,12 +16,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http BadChunkSuffix, BadChunkSizeData, ChunkedRequestIncomplete, - PathContainsNullCharacters, InvalidCharactersInHeaderName, - NonAsciiOrNullCharactersInInputString, RequestLineTooLong, HeadersExceedMaxTotalSize, - MissingCRInHeaderLine, TooManyHeaders, RequestTimeout, FinalTransferCodingNotChunked, diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/BadHttpRequestTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/BadHttpRequestTests.cs index 65402a019b..380a51188e 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/BadHttpRequestTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/BadHttpRequestTests.cs @@ -133,7 +133,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests foreach (var requestLine in HttpParsingData.RequestLineInvalidData) { - data.Add(requestLine, $"Invalid request line: {requestLine.Replace("\r", "\\x0D").Replace("\n", "\\x0A")}"); + data.Add(requestLine, $"Invalid request line: '{requestLine.Replace("\r", "\\x0D").Replace("\n", "\\x0A")}'"); } foreach (var requestLine in HttpParsingData.RequestLineWithEncodedNullCharInTargetData) diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs index 8aeb066862..bbac629985 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs @@ -81,25 +81,6 @@ namespace Microsoft.AspNetCore.Server.KestrelTests _pipelineFactory.Dispose(); } - [Fact] - public async Task TakeMessageHeadersThrowsOnHeaderValueWithLineFolding_CharacterNotAvailableOnFirstAttempt() - { - await _input.Writer.WriteAsync(Encoding.ASCII.GetBytes("Header-1: value1\r\n")); - - var readableBuffer = (await _input.Reader.ReadAsync()).Buffer; - Assert.False(_frame.TakeMessageHeaders(readableBuffer, out _consumed, out _examined)); - _input.Reader.Advance(_consumed, _examined); - - await _input.Writer.WriteAsync(Encoding.ASCII.GetBytes(" ")); - - readableBuffer = (await _input.Reader.ReadAsync()).Buffer; - var exception = Assert.Throws(() => _frame.TakeMessageHeaders(readableBuffer, out _consumed, out _examined)); - _input.Reader.Advance(_consumed, _examined); - - Assert.Equal("Whitespace is not allowed in header name.", exception.Message); - Assert.Equal(StatusCodes.Status400BadRequest, exception.StatusCode); - } - [Fact] public async Task TakeMessageHeadersThrowsWhenHeadersExceedTotalSizeLimit() { diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/HttpParserTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/HttpParserTests.cs index b63ecc5d83..6ad29a68cb 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/HttpParserTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/HttpParserTests.cs @@ -108,7 +108,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var exception = Assert.Throws(() => parser.ParseRequestLine(Mock.Of(), buffer, out var consumed, out var examined)); - Assert.Equal($"Invalid request line: {requestLine.Replace("\r", "\\x0D").Replace("\n", "\\x0A")}", exception.Message); + Assert.Equal($"Invalid request line: '{requestLine.Replace("\r", "\\x0D").Replace("\n", "\\x0A")}'", exception.Message); Assert.Equal(StatusCodes.Status400BadRequest, (exception as BadHttpRequestException).StatusCode); } @@ -306,7 +306,12 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [MemberData(nameof(RequestHeaderInvalidData))] public void ParseHeadersThrowsOnInvalidRequestHeaders(string rawHeaders, string expectedExceptionMessage) { - var parser = CreateParser(Mock.Of()); + var mockTrace = new Mock(); + mockTrace + .Setup(trace => trace.IsEnabled(LogLevel.Information)) + .Returns(true); + + var parser = CreateParser(mockTrace.Object); var buffer = ReadableBuffer.Create(Encoding.ASCII.GetBytes(rawHeaders)); var exception = Assert.Throws(() => diff --git a/test/shared/HttpParsingData.cs b/test/shared/HttpParsingData.cs index 7d84ba37b3..e999fb3170 100644 --- a/test/shared/HttpParsingData.cs +++ b/test/shared/HttpParsingData.cs @@ -203,106 +203,79 @@ namespace Microsoft.AspNetCore.Testing "8charact", }; - public static IEnumerable RequestHeaderInvalidData + public static IEnumerable RequestHeaderInvalidData => new[] { - get - { - // Line folding - var headersWithLineFolding = new[] - { - "Header: line1\r\n line2\r\n\r\n", - "Header: line1\r\n\tline2\r\n\r\n", - "Header: line1\r\n line2\r\n\r\n", - "Header: line1\r\n \tline2\r\n\r\n", - "Header: line1\r\n\t line2\r\n\r\n", - "Header: line1\r\n\t\tline2\r\n\r\n", - "Header: line1\r\n \t\t line2\r\n\r\n", - "Header: line1\r\n \t \t line2\r\n\r\n", - "Header-1: multi\r\n line\r\nHeader-2: value2\r\n\r\n", - "Header-1: value1\r\nHeader-2: multi\r\n line\r\n\r\n", - "Header-1: value1\r\n Header-2: value2\r\n\r\n", - "Header-1: value1\r\n\tHeader-2: value2\r\n\r\n", - }; + // Missing CR + new[] { "Header: value\n\r\n", @"Invalid request header: 'Header: value\x0A'" }, + new[] { "Header-1: value1\nHeader-2: value2\r\n\r\n", @"Invalid request header: 'Header-1: value1\x0A'" }, + new[] { "Header-1: value1\r\nHeader-2: value2\n\r\n", @"Invalid request header: 'Header-2: value2\x0A'" }, - // CR in value - var headersWithCRInValue = new[] - { - "Header-1: value1\r\r\n", - "Header-1: val\rue1\r\n", - "Header-1: value1\rHeader-2: value2\r\n\r\n", - "Header-1: value1\r\nHeader-2: value2\r\r\n", - "Header-1: value1\r\nHeader-2: v\ralue2\r\n", - "Header-1: Value__\rVector16________Vector32\r\n", - "Header-1: Value___Vector16\r________Vector32\r\n", - "Header-1: Value___Vector16_______\rVector32\r\n", - "Header-1: Value___Vector16________Vector32\r\r\n", - "Header-1: Value___Vector16________Vector32_\r\r\n", - "Header-1: Value___Vector16________Vector32Value___Vector16_______\rVector32\r\n", - "Header-1: Value___Vector16________Vector32Value___Vector16________Vector32\r\r\n", - "Header-1: Value___Vector16________Vector32Value___Vector16________Vector32_\r\r\n", - }; + // Line folding + new[] { "Header: line1\r\n line2\r\n\r\n", @"Invalid request header: ' line2\x0D\x0A'" }, + new[] { "Header: line1\r\n\tline2\r\n\r\n", @"Invalid request header: '\x09line2\x0D\x0A'" }, + new[] { "Header: line1\r\n line2\r\n\r\n", @"Invalid request header: ' line2\x0D\x0A'" }, + new[] { "Header: line1\r\n \tline2\r\n\r\n", @"Invalid request header: ' \x09line2\x0D\x0A'" }, + new[] { "Header: line1\r\n\t line2\r\n\r\n", @"Invalid request header: '\x09 line2\x0D\x0A'" }, + new[] { "Header: line1\r\n\t\tline2\r\n\r\n", @"Invalid request header: '\x09\x09line2\x0D\x0A'" }, + new[] { "Header: line1\r\n \t\t line2\r\n\r\n", @"Invalid request header: ' \x09\x09 line2\x0D\x0A'" }, + new[] { "Header: line1\r\n \t \t line2\r\n\r\n", @"Invalid request header: ' \x09 \x09 line2\x0D\x0A'" }, + new[] { "Header-1: multi\r\n line\r\nHeader-2: value2\r\n\r\n", @"Invalid request header: ' line\x0D\x0A'" }, + new[] { "Header-1: value1\r\nHeader-2: multi\r\n line\r\n\r\n", @"Invalid request header: ' line\x0D\x0A'" }, + new[] { "Header-1: value1\r\n Header-2: value2\r\n\r\n", @"Invalid request header: ' Header-2: value2\x0D\x0A'" }, + new[] { "Header-1: value1\r\n\tHeader-2: value2\r\n\r\n", @"Invalid request header: '\x09Header-2: value2\x0D\x0A'" }, - // Missing colon - var headersWithMissingColon = new[] - { - "Header-1 value1\r\n\r\n", - "Header-1 value1\r\nHeader-2: value2\r\n\r\n", - "Header-1: value1\r\nHeader-2 value2\r\n\r\n", - "\n" - }; + // CR in value + new[] { "Header-1: value1\r\r\n", @"Invalid request header: 'Header-1: value1\x0D\x0D\x0A'" }, + new[] { "Header-1: val\rue1\r\n", @"Invalid request header: 'Header-1: val\x0Due1\x0D\x0A'" }, + new[] { "Header-1: value1\rHeader-2: value2\r\n\r\n", @"Invalid request header: 'Header-1: value1\x0DHeader-2: value2\x0D\x0A'" }, + new[] { "Header-1: value1\r\nHeader-2: value2\r\r\n", @"Invalid request header: 'Header-2: value2\x0D\x0D\x0A'" }, + new[] { "Header-1: value1\r\nHeader-2: v\ralue2\r\n", @"Invalid request header: 'Header-2: v\x0Dalue2\x0D\x0A'" }, + new[] { "Header-1: Value__\rVector16________Vector32\r\n", @"Invalid request header: 'Header-1: Value__\x0DVector16________Vector32\x0D\x0A'" }, + new[] { "Header-1: Value___Vector16\r________Vector32\r\n", @"Invalid request header: 'Header-1: Value___Vector16\x0D________Vector32\x0D\x0A'" }, + new[] { "Header-1: Value___Vector16_______\rVector32\r\n", @"Invalid request header: 'Header-1: Value___Vector16_______\x0DVector32\x0D\x0A'" }, + new[] { "Header-1: Value___Vector16________Vector32\r\r\n", @"Invalid request header: 'Header-1: Value___Vector16________Vector32\x0D\x0D\x0A'" }, + new[] { "Header-1: Value___Vector16________Vector32_\r\r\n", @"Invalid request header: 'Header-1: Value___Vector16________Vector32_\x0D\x0D\x0A'" }, + new[] { "Header-1: Value___Vector16________Vector32Value___Vector16_______\rVector32\r\n", @"Invalid request header: 'Header-1: Value___Vector16________Vector32Value___Vector16_______\x0DVector32\x0D\x0A'" }, + new[] { "Header-1: Value___Vector16________Vector32Value___Vector16________Vector32\r\r\n", @"Invalid request header: 'Header-1: Value___Vector16________Vector32Value___Vector16________Vector32\x0D\x0D\x0A'" }, + new[] { "Header-1: Value___Vector16________Vector32Value___Vector16________Vector32_\r\r\n", @"Invalid request header: 'Header-1: Value___Vector16________Vector32Value___Vector16________Vector32_\x0D\x0D\x0A'" }, - // Starting with whitespace - var headersStartingWithWhitespace = new[] - { - " Header: value\r\n\r\n", - "\tHeader: value\r\n\r\n", - " Header-1: value1\r\nHeader-2: value2\r\n\r\n", - "\tHeader-1: value1\r\nHeader-2: value2\r\n\r\n", - }; + // Missing colon + new[] { "Header-1 value1\r\n\r\n", @"Invalid request header: 'Header-1 value1\x0D\x0A'" }, + new[] { "Header-1 value1\r\nHeader-2: value2\r\n\r\n", @"Invalid request header: 'Header-1 value1\x0D\x0A'" }, + new[] { "Header-1: value1\r\nHeader-2 value2\r\n\r\n", @"Invalid request header: 'Header-2 value2\x0D\x0A'" }, + new[] { "\n", @"Invalid request header: '\x0A'" }, - // Whitespace in header name - var headersWithWithspaceInName = new[] - { - "Header : value\r\n\r\n", - "Header\t: value\r\n\r\n", - "Header\r: value\r\n\r\n", - "Header_\rVector16: value\r\n\r\n", - "Header__Vector16\r: value\r\n\r\n", - "Header__Vector16_\r: value\r\n\r\n", - "Header_\rVector16________Vector32: value\r\n\r\n", - "Header__Vector16________Vector32\r: value\r\n\r\n", - "Header__Vector16________Vector32_\r: value\r\n\r\n", - "Header__Vector16________Vector32Header_\rVector16________Vector32: value\r\n\r\n", - "Header__Vector16________Vector32Header__Vector16________Vector32\r: value\r\n\r\n", - "Header__Vector16________Vector32Header__Vector16________Vector32_\r: value\r\n\r\n", - "Header 1: value1\r\nHeader-2: value2\r\n\r\n", - "Header 1 : value1\r\nHeader-2: value2\r\n\r\n", - "Header 1\t: value1\r\nHeader-2: value2\r\n\r\n", - "Header 1\r: value1\r\nHeader-2: value2\r\n\r\n", - "Header-1: value1\r\nHeader 2: value2\r\n\r\n", - "Header-1: value1\r\nHeader-2 : value2\r\n\r\n", - "Header-1: value1\r\nHeader-2\t: value2\r\n\r\n", - }; + // Starting with whitespace + new[] { " Header: value\r\n\r\n", @"Invalid request header: ' Header: value\x0D\x0A'" }, + new[] { "\tHeader: value\r\n\r\n", @"Invalid request header: '\x09Header: value\x0D\x0A'" }, + new[] { " Header-1: value1\r\nHeader-2: value2\r\n\r\n", @"Invalid request header: ' Header-1: value1\x0D\x0A'" }, + new[] { "\tHeader-1: value1\r\nHeader-2: value2\r\n\r\n", @"Invalid request header: '\x09Header-1: value1\x0D\x0A'" }, - // Headers not ending in CRLF line - var headersNotEndingInCrLfLine = new[] - { - "Header-1: value1\r\nHeader-2: value2\r\n\r\r", - "Header-1: value1\r\nHeader-2: value2\r\n\r ", - "Header-1: value1\r\nHeader-2: value2\r\n\r \n", - }; + // Whitespace in header name + new[] { "Header : value\r\n\r\n", @"Invalid request header: 'Header : value\x0D\x0A'" }, + new[] { "Header\t: value\r\n\r\n", @"Invalid request header: 'Header\x09: value\x0D\x0A'" }, + new[] { "Header\r: value\r\n\r\n", @"Invalid request header: 'Header\x0D: value\x0D\x0A'" }, + new[] { "Header_\rVector16: value\r\n\r\n", @"Invalid request header: 'Header_\x0DVector16: value\x0D\x0A'" }, + new[] { "Header__Vector16\r: value\r\n\r\n", @"Invalid request header: 'Header__Vector16\x0D: value\x0D\x0A'" }, + new[] { "Header__Vector16_\r: value\r\n\r\n", @"Invalid request header: 'Header__Vector16_\x0D: value\x0D\x0A'" }, + new[] { "Header_\rVector16________Vector32: value\r\n\r\n", @"Invalid request header: 'Header_\x0DVector16________Vector32: value\x0D\x0A'" }, + new[] { "Header__Vector16________Vector32\r: value\r\n\r\n", @"Invalid request header: 'Header__Vector16________Vector32\x0D: value\x0D\x0A'" }, + new[] { "Header__Vector16________Vector32_\r: value\r\n\r\n", @"Invalid request header: 'Header__Vector16________Vector32_\x0D: value\x0D\x0A'" }, + new[] { "Header__Vector16________Vector32Header_\rVector16________Vector32: value\r\n\r\n", @"Invalid request header: 'Header__Vector16________Vector32Header_\x0DVector16________Vector32: value\x0D\x0A'" }, + new[] { "Header__Vector16________Vector32Header__Vector16________Vector32\r: value\r\n\r\n", @"Invalid request header: 'Header__Vector16________Vector32Header__Vector16________Vector32\x0D: value\x0D\x0A'" }, + new[] { "Header__Vector16________Vector32Header__Vector16________Vector32_\r: value\r\n\r\n", @"Invalid request header: 'Header__Vector16________Vector32Header__Vector16________Vector32_\x0D: value\x0D\x0A'" }, + new[] { "Header 1: value1\r\nHeader-2: value2\r\n\r\n", @"Invalid request header: 'Header 1: value1\x0D\x0A'" }, + new[] { "Header 1 : value1\r\nHeader-2: value2\r\n\r\n", @"Invalid request header: 'Header 1 : value1\x0D\x0A'" }, + new[] { "Header 1\t: value1\r\nHeader-2: value2\r\n\r\n", @"Invalid request header: 'Header 1\x09: value1\x0D\x0A'" }, + new[] { "Header 1\r: value1\r\nHeader-2: value2\r\n\r\n", @"Invalid request header: 'Header 1\x0D: value1\x0D\x0A'" }, + new[] { "Header-1: value1\r\nHeader 2: value2\r\n\r\n", @"Invalid request header: 'Header 2: value2\x0D\x0A'" }, + new[] { "Header-1: value1\r\nHeader-2 : value2\r\n\r\n", @"Invalid request header: 'Header-2 : value2\x0D\x0A'" }, + new[] { "Header-1: value1\r\nHeader-2\t: value2\r\n\r\n", @"Invalid request header: 'Header-2\x09: value2\x0D\x0A'" }, - return new[] - { - Tuple.Create(headersWithLineFolding, "Whitespace is not allowed in header name."), - Tuple.Create(headersWithCRInValue, "Header value must not contain CR characters."), - Tuple.Create(headersWithMissingColon, "No ':' character found in header line."), - Tuple.Create(headersStartingWithWhitespace, "Whitespace is not allowed in header name."), - Tuple.Create(headersWithWithspaceInName, "Whitespace is not allowed in header name."), - Tuple.Create(headersNotEndingInCrLfLine, "Headers corrupted, invalid header sequence.") - } - .SelectMany(t => t.Item1.Select(headers => new[] { headers, t.Item2 })); - } - } + // Headers not ending in CRLF line + new[] { "Header-1: value1\r\nHeader-2: value2\r\n\r\r", @"Invalid request headers: missing final CRLF in header fields." }, + new[] { "Header-1: value1\r\nHeader-2: value2\r\n\r ", @"Invalid request headers: missing final CRLF in header fields." }, + new[] { "Header-1: value1\r\nHeader-2: value2\r\n\r \n", @"Invalid request headers: missing final CRLF in header fields." }, + }; } } From 3a1f3d14f9c340606a3dbd5dc9ff97ce68a7d774 Mon Sep 17 00:00:00 2001 From: Nate McMaster Date: Wed, 8 Mar 2017 17:21:21 -0800 Subject: [PATCH 1107/1662] Add absolute-uri benchmark and change plaintext, live aspnet, and unicode benchmarks to use origin-form --- .../RequestParsing.cs | 10 ++++++++++ .../RequestParsingData.cs | 14 ++++++++++++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsing.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsing.cs index 8fc4bc0eea..16f1efdb8d 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsing.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsing.cs @@ -42,6 +42,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance } } + [Benchmark(Baseline = true, OperationsPerInvoke = RequestParsingData.InnerLoopCount)] + public void PlaintextAbsoluteUri() + { + for (var i = 0; i < RequestParsingData.InnerLoopCount; i++) + { + InsertData(RequestParsingData.PlaintextAbsoluteUriRequest); + ParseData(); + } + } + [Benchmark(OperationsPerInvoke = RequestParsingData.InnerLoopCount * RequestParsingData.Pipelining)] public void PipelinedPlaintextTechEmpower() { diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsingData.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsingData.cs index bddc1a7a97..45b585a2d0 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsingData.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsingData.cs @@ -21,8 +21,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance "Connection: keep-alive\r\n" + "\r\n"; + // edge-casey - client's don't normally send this + private const string _plaintextAbsoluteUriRequest = + "GET http://localhost/plaintext HTTP/1.1\r\n" + + "Host: localhost\r\n" + + "Accept: text/plain,text/html;q=0.9,application/xhtml+xml;q=0.9,application/xml;q=0.8,*/*;q=0.7\r\n" + + "Connection: keep-alive\r\n" + + "\r\n"; + private const string _liveaspnetRequest = - "GET https://live.asp.net/ HTTP/1.1\r\n" + + "GET / HTTP/1.1\r\n" + "Host: live.asp.net\r\n" + "Connection: keep-alive\r\n" + "Upgrade-Insecure-Requests: 1\r\n" + @@ -35,7 +43,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance "\r\n"; private const string _unicodeRequest = - "GET http://stackoverflow.com/questions/40148683/why-is-%e0%a5%a7%e0%a5%a8%e0%a5%a9-numeric HTTP/1.1\r\n" + + "GET /questions/40148683/why-is-%e0%a5%a7%e0%a5%a8%e0%a5%a9-numeric HTTP/1.1\r\n" + "Accept: text/html, application/xhtml+xml, image/jxr, */*\r\n" + "Accept-Language: en-US,en-GB;q=0.7,en;q=0.3\r\n" + "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36 Edge/15.14965\r\n" + @@ -53,6 +61,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance public static readonly byte[] PlaintextTechEmpowerPipelinedRequests = Encoding.ASCII.GetBytes(string.Concat(Enumerable.Repeat(_plaintextTechEmpowerRequest, Pipelining))); public static readonly byte[] PlaintextTechEmpowerRequest = Encoding.ASCII.GetBytes(_plaintextTechEmpowerRequest); + public static readonly byte[] PlaintextAbsoluteUriRequest = Encoding.ASCII.GetBytes(_plaintextAbsoluteUriRequest); + public static readonly byte[] LiveaspnetPipelinedRequests = Encoding.ASCII.GetBytes(string.Concat(Enumerable.Repeat(_liveaspnetRequest, Pipelining))); public static readonly byte[] LiveaspnetRequest = Encoding.ASCII.GetBytes(_liveaspnetRequest); From 63e3c9428a71158825b6f282856f915e958244e0 Mon Sep 17 00:00:00 2001 From: Nate McMaster Date: Wed, 8 Mar 2017 17:28:13 -0800 Subject: [PATCH 1108/1662] You can't have two benchmarks as the baseline. --- .../RequestParsing.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsing.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsing.cs index 16f1efdb8d..ccaf08ba57 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsing.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsing.cs @@ -42,7 +42,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance } } - [Benchmark(Baseline = true, OperationsPerInvoke = RequestParsingData.InnerLoopCount)] + [Benchmark(OperationsPerInvoke = RequestParsingData.InnerLoopCount)] public void PlaintextAbsoluteUri() { for (var i = 0; i < RequestParsingData.InnerLoopCount; i++) From 49d058a9970cbdb437bc4fad3e8a0e91dcc74dab Mon Sep 17 00:00:00 2001 From: David Fowler Date: Wed, 8 Mar 2017 18:47:52 -0800 Subject: [PATCH 1109/1662] No mono (#1472) --- .travis.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 4d388988b4..fb5fa0217a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,8 +16,7 @@ env: global: - DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true - DOTNET_CLI_TELEMETRY_OPTOUT: 1 -mono: - - 4.0.5 +mono: none os: - linux - osx From 941d3969427c31fa275f5760bfa7783e8384716b Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Thu, 9 Mar 2017 03:27:56 +0000 Subject: [PATCH 1110/1662] Speed up ParseRequestLine (#1463) --- .../Internal/Http/Frame.cs | 5 +- .../Internal/Http/IHttpRequestLineHandler.cs | 2 +- .../Internal/Http/KestrelHttpParser.cs | 395 ++++++++---------- .../Internal/Infrastructure/HttpUtilities.cs | 106 +++-- .../FrameParsingOverhead.cs | 2 +- .../KestrelHttpParser.cs | 2 +- .../HttpParserTests.cs | 6 +- 7 files changed, 256 insertions(+), 262 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs index bc6757b30e..c8a5e20033 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs @@ -1216,15 +1216,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http Log.ApplicationError(ConnectionId, ex); } - public void OnStartLine(HttpMethod method, HttpVersion version, Span target, Span path, Span query, Span customMethod) + public void OnStartLine(HttpMethod method, HttpVersion version, Span target, Span path, Span query, Span customMethod, bool pathEncoded) { // URIs are always encoded/escaped to ASCII https://tools.ietf.org/html/rfc3986#page-11 // Multibyte Internationalized Resource Identifiers (IRIs) are first converted to utf8; // then encoded/escaped to ASCII https://www.ietf.org/rfc/rfc3987.txt "Mapping of IRIs to URIs" string requestUrlPath; string rawTarget; - var needDecode = path.IndexOf(BytePercentage) >= 0; - if (needDecode) + if (pathEncoded) { // Read raw target before mutating memory. rawTarget = target.GetAsciiStringNonNullCharacters(); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/IHttpRequestLineHandler.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/IHttpRequestLineHandler.cs index ddb6473882..83481002b3 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/IHttpRequestLineHandler.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/IHttpRequestLineHandler.cs @@ -7,6 +7,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { public interface IHttpRequestLineHandler { - void OnStartLine(HttpMethod method, HttpVersion version, Span target, Span path, Span query, Span customMethod); + void OnStartLine(HttpMethod method, HttpVersion version, Span target, Span path, Span query, Span customMethod, bool pathEncoded); } } \ No newline at end of file diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/KestrelHttpParser.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/KestrelHttpParser.cs index 79ecd4b9f0..02363a2325 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/KestrelHttpParser.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/KestrelHttpParser.cs @@ -34,219 +34,130 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http consumed = buffer.Start; examined = buffer.End; - ReadCursor end; - Span span; - - // If the buffer is a single span then use it to find the LF - if (buffer.IsSingleSpan) + // Prepare the first span + var span = buffer.First.Span; + var lineIndex = span.IndexOfVectorized(ByteLF); + if (lineIndex >= 0) { - var startLineSpan = buffer.First.Span; - var lineIndex = startLineSpan.IndexOfVectorized(ByteLF); - - if (lineIndex == -1) - { - return false; - } - - end = buffer.Move(consumed, lineIndex + 1); - span = startLineSpan.Slice(0, lineIndex + 1); + consumed = buffer.Move(consumed, lineIndex + 1); + span = span.Slice(0, lineIndex + 1); } - else + else if (buffer.IsSingleSpan || !TryGetNewLineSpan(ref buffer, ref span, out consumed)) { - var start = buffer.Start; - if (ReadCursorOperations.Seek(start, buffer.End, out end, ByteLF) == -1) - { - return false; - } - - // Move 1 byte past the \n - end = buffer.Move(end, 1); - var startLineBuffer = buffer.Slice(start, end); - - span = startLineBuffer.ToSpan(); + // No request line end + return false; } - var pathStart = -1; - var queryStart = -1; - var queryEnd = -1; - var pathEnd = -1; - var versionStart = -1; - - var httpVersion = HttpVersion.Unknown; - HttpMethod method; - Span customMethod; - var i = 0; - var length = span.Length; - var done = false; - + // Fix and parse the span fixed (byte* data = &span.DangerousGetPinnableReference()) { - switch (StartLineState.KnownMethod) + ParseRequestLine(handler, data, span.Length); + } + + examined = consumed; + return true; + } + + private unsafe void ParseRequestLine(T handler, byte* data, int length) where T : IHttpRequestLineHandler + { + int offset; + Span customMethod; + // Get Method and set the offset + var method = HttpUtilities.GetKnownMethod(data, length, out offset); + if (method == HttpMethod.Custom) + { + customMethod = GetUnknownMethod(data, length, out offset); + } + + // Skip space + offset++; + + byte ch = 0; + // Target = Path and Query + var pathEncoded = false; + var pathStart = -1; + for (; offset < length; offset++) + { + ch = data[offset]; + if (ch == ByteSpace) { - case StartLineState.KnownMethod: - if (span.GetKnownMethod(out method, out var methodLength)) - { - // Update the index, current char, state and jump directly - // to the next state - i += methodLength + 1; + if (pathStart == -1) + { + // Empty path is illegal + RejectRequestLine(data, length); + } - goto case StartLineState.Path; - } - goto case StartLineState.UnknownMethod; + break; + } + else if (ch == ByteQuestionMark) + { + if (pathStart == -1) + { + // Empty path is illegal + RejectRequestLine(data, length); + } - case StartLineState.UnknownMethod: - for (; i < length; i++) - { - var ch = data[i]; + break; + } + else if (ch == BytePercentage) + { + if (pathStart == -1) + { + // Path starting with % is illegal + RejectRequestLine(data, length); + } - if (ch == ByteSpace) - { - customMethod = span.Slice(0, i); - - if (customMethod.Length == 0) - { - RejectRequestLine(span); - } - // Consume space - i++; - - goto case StartLineState.Path; - } - - if (!IsValidTokenChar((char)ch)) - { - RejectRequestLine(span); - } - } - - break; - case StartLineState.Path: - for (; i < length; i++) - { - var ch = data[i]; - if (ch == ByteSpace) - { - pathEnd = i; - - if (pathStart == -1) - { - // Empty path is illegal - RejectRequestLine(span); - } - - // No query string found - queryStart = queryEnd = i; - - // Consume space - i++; - - goto case StartLineState.KnownVersion; - } - else if (ch == ByteQuestionMark) - { - pathEnd = i; - - if (pathStart == -1) - { - // Empty path is illegal - RejectRequestLine(span); - } - - queryStart = i; - goto case StartLineState.QueryString; - } - else if (ch == BytePercentage) - { - if (pathStart == -1) - { - RejectRequestLine(span); - } - } - - if (pathStart == -1) - { - pathStart = i; - } - } - break; - case StartLineState.QueryString: - for (; i < length; i++) - { - var ch = data[i]; - if (ch == ByteSpace) - { - queryEnd = i; - - // Consume space - i++; - - goto case StartLineState.KnownVersion; - } - } - break; - case StartLineState.KnownVersion: - // REVIEW: We don't *need* to slice here but it makes the API - // nicer, slicing should be free :) - if (span.Slice(i).GetKnownVersion(out httpVersion, out var versionLenght)) - { - // Update the index, current char, state and jump directly - // to the next state - i += versionLenght + 1; - goto case StartLineState.NewLine; - } - - versionStart = i; - - goto case StartLineState.UnknownVersion; - - case StartLineState.UnknownVersion: - for (; i < length; i++) - { - var ch = data[i]; - if (ch == ByteCR) - { - var versionSpan = span.Slice(versionStart, i - versionStart); - - if (versionSpan.Length == 0) - { - RejectRequestLine(span); - } - else - { - RejectRequest(RequestRejectionReason.UnrecognizedHTTPVersion, - versionSpan.GetAsciiStringEscaped(32)); - } - } - } - break; - case StartLineState.NewLine: - if (data[i] != ByteLF) - { - RejectRequestLine(span); - } - i++; - - goto case StartLineState.Complete; - case StartLineState.Complete: - done = true; - break; + pathEncoded = true; + } + else if (pathStart == -1) + { + pathStart = offset; } } - if (!done) + if (pathStart == -1) { - RejectRequestLine(span); + // End of path not found + RejectRequestLine(data, length); } - var pathBuffer = span.Slice(pathStart, pathEnd - pathStart); - var targetBuffer = span.Slice(pathStart, queryEnd - pathStart); - var query = span.Slice(queryStart, queryEnd - queryStart); + var pathBuffer = new Span(data + pathStart, offset - pathStart); - handler.OnStartLine(method, httpVersion, targetBuffer, pathBuffer, query, customMethod); + var queryStart = offset; + // Query string + if (ch == ByteQuestionMark) + { + // We have a query string + for (; offset < length; offset++) + { + ch = data[offset]; + if (ch == ByteSpace) + { + break; + } + } + } - consumed = end; - examined = consumed; - return true; + var targetBuffer = new Span(data + pathStart, offset - pathStart); + var query = new Span(data + queryStart, offset - queryStart); + + // Consume space + offset++; + + // Version + var httpVersion = HttpUtilities.GetKnownVersion(data + offset, length - offset); + if (httpVersion == HttpVersion.Unknown) + { + RejectUnknownVersion(data, length, offset); + } + + // After version 8 bytes and cr 1 byte, expect lf + if (data[offset + 8 + 1] != ByteLF) + { + RejectRequestLine(data, length); + } + + handler.OnStartLine(method, httpVersion, targetBuffer, pathBuffer, query, customMethod, pathEncoded); } public unsafe bool ParseHeaders(T handler, ReadableBuffer buffer, out ReadCursor consumed, out ReadCursor examined, out int consumedBytes) where T : IHttpHeadersHandler @@ -502,6 +413,48 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http return true; } + + [MethodImpl(MethodImplOptions.NoInlining)] + private static bool TryGetNewLineSpan(ref ReadableBuffer buffer, ref Span span, out ReadCursor end) + { + var start = buffer.Start; + if (ReadCursorOperations.Seek(start, buffer.End, out end, ByteLF) != -1) + { + // Move 1 byte past the \n + end = buffer.Move(end, 1); + span = buffer.Slice(start, end).ToSpan(); + return true; + } + return false; + } + + [MethodImpl(MethodImplOptions.NoInlining)] + private unsafe Span GetUnknownMethod(byte* data, int length, out int methodLength) + { + methodLength = 0; + for (var i = 0; i < length; i++) + { + var ch = data[i]; + + if (ch == ByteSpace) + { + if (i == 0) + { + RejectRequestLine(data, length); + } + + methodLength = i; + break; + } + else if (!IsValidTokenChar((char)ch)) + { + RejectRequestLine(data, length); + } + } + + return new Span(data, methodLength); + } + private static bool IsValidTokenChar(char c) { // Determines if a character is valid as a 'token' as defined in the @@ -532,9 +485,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http throw BadHttpRequestException.GetException(reason); } - public static void RejectRequest(RequestRejectionReason reason, string value) + private unsafe void RejectUnknownVersion(byte* data, int length, int versionStart) { - throw BadHttpRequestException.GetException(reason, value); + throw GetRejectUnknownVersion(data, length, versionStart); + } + + private unsafe void RejectRequestLine(byte* data, int length) + { + throw GetRejectRequestLineException(new Span(data, length)); } private void RejectRequestLine(Span span) @@ -549,6 +507,30 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http Log.IsEnabled(LogLevel.Information) ? span.GetAsciiStringEscaped(MaxRequestLineError) : string.Empty); } + private unsafe BadHttpRequestException GetRejectUnknownVersion(byte* data, int length, int versionStart) + { + var span = new Span(data, length); + length -= versionStart; + for (var i = 0; i < length; i++) + { + var ch = span[i + versionStart]; + if (ch == ByteCR) + { + if (i == 0) + { + return GetRejectRequestLineException(span); + } + else + { + return BadHttpRequestException.GetException(RequestRejectionReason.UnrecognizedHTTPVersion, + span.Slice(versionStart, i).GetAsciiStringEscaped(32)); + } + } + } + + return GetRejectRequestLineException(span); + } + private unsafe void RejectRequestHeader(byte* headerLine, int length) { RejectRequestHeader(new Span(headerLine, length)); @@ -578,26 +560,5 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http // https://github.com/dotnet/coreclr/issues/7459#issuecomment-253965670 return Vector.AsVectorByte(new Vector(vectorByte * 0x01010101u)); } - - private enum HeaderState - { - Name, - Whitespace, - ExpectValue, - ExpectNewLine, - Complete - } - - private enum StartLineState - { - KnownMethod, - UnknownMethod, - Path, - QueryString, - KnownVersion, - UnknownVersion, - NewLine, - Complete - } } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/HttpUtilities.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/HttpUtilities.cs index f93ceafc00..182d424eb9 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/HttpUtilities.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/HttpUtilities.cs @@ -147,34 +147,46 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure /// /// true if the input matches a known string, false otherwise. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static bool GetKnownMethod(this Span span, out HttpMethod method, out int length) + public static unsafe bool GetKnownMethod(this Span span, out HttpMethod method, out int length) { - if (span.TryRead(out var possiblyGet)) + fixed (byte* data = &span.DangerousGetPinnableReference()) { - if (possiblyGet == _httpGetMethodInt) - { - length = 3; - method = HttpMethod.Get; - return true; - } + method = GetKnownMethod(data, span.Length, out length); + return method != HttpMethod.Custom; } + } - if (span.TryRead(out var value)) + [MethodImpl(MethodImplOptions.AggressiveInlining)] + internal unsafe static HttpMethod GetKnownMethod(byte* data, int length, out int methodLength) + { + methodLength = 0; + if (length < sizeof(uint)) { + return HttpMethod.Custom; + } + else if (*(uint*)data == _httpGetMethodInt) + { + methodLength = 3; + return HttpMethod.Get; + } + else if (length < sizeof(ulong)) + { + return HttpMethod.Custom; + } + else + { + var value = *(ulong*)data; foreach (var x in _knownMethods) { if ((value & x.Item1) == x.Item2) { - method = x.Item3; - length = x.Item4; - return true; + methodLength = x.Item4; + return x.Item3; } } } - method = HttpMethod.Custom; - length = 0; - return false; + return HttpMethod.Custom; } /// @@ -189,36 +201,56 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure /// /// true if the input matches a known string, false otherwise. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static bool GetKnownVersion(this Span span, out HttpVersion knownVersion, out byte length) + public static unsafe bool GetKnownVersion(this Span span, out HttpVersion knownVersion, out byte length) { - if (span.TryRead(out var version)) + fixed (byte* data = &span.DangerousGetPinnableReference()) { - if (version == _http11VersionLong) + knownVersion = GetKnownVersion(data, span.Length); + if (knownVersion != HttpVersion.Unknown) { length = sizeof(ulong); - knownVersion = HttpVersion.Http11; - } - else if (version == _http10VersionLong) - { - length = sizeof(ulong); - knownVersion = HttpVersion.Http10; - } - else - { - length = 0; - knownVersion = HttpVersion.Unknown; - return false; - } - - if (span[sizeof(ulong)] == (byte)'\r') - { return true; } + + length = 0; + return false; + } + } + + /// + /// Checks 9 bytes from correspond to a known HTTP version. + /// + /// + /// A "known HTTP version" Is is either HTTP/1.0 or HTTP/1.1. + /// Since those fit in 8 bytes, they can be optimally looked up by reading those bytes as a long. Once + /// in that format, it can be checked against the known versions. + /// The Known versions will be checked with the required '\r'. + /// To optimize performance the HTTP/1.1 will be checked first. + /// + /// true if the input matches a known string, false otherwise. + [MethodImpl(MethodImplOptions.AggressiveInlining)] + internal unsafe static HttpVersion GetKnownVersion(byte* location, int length) + { + HttpVersion knownVersion; + var version = *(ulong*)location; + if (length < sizeof(ulong) + 1 || location[sizeof(ulong)] != (byte)'\r') + { + knownVersion = HttpVersion.Unknown; + } + else if (version == _http11VersionLong) + { + knownVersion = HttpVersion.Http11; + } + else if (version == _http10VersionLong) + { + knownVersion = HttpVersion.Http10; + } + else + { + knownVersion = HttpVersion.Unknown; } - knownVersion = HttpVersion.Unknown; - length = 0; - return false; + return knownVersion; } public static string VersionToString(HttpVersion httpVersion) diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameParsingOverhead.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameParsingOverhead.cs index acb39238bc..3c077d6bf5 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameParsingOverhead.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameParsingOverhead.cs @@ -119,7 +119,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance public bool ParseRequestLine(T handler, ReadableBuffer buffer, out ReadCursor consumed, out ReadCursor examined) where T : IHttpRequestLineHandler { - handler.OnStartLine(HttpMethod.Get, HttpVersion.Http11, new Span(_target), new Span(_target), Span.Empty, Span.Empty); + handler.OnStartLine(HttpMethod.Get, HttpVersion.Http11, new Span(_target), new Span(_target), Span.Empty, Span.Empty, false); consumed = buffer.Start; examined = buffer.End; diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/KestrelHttpParser.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/KestrelHttpParser.cs index f77346ee8b..a4da66cbe6 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/KestrelHttpParser.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/KestrelHttpParser.cs @@ -66,7 +66,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance } } - public void OnStartLine(HttpMethod method, HttpVersion version, Span target, Span path, Span query, Span customMethod) + public void OnStartLine(HttpMethod method, HttpVersion version, Span target, Span path, Span query, Span customMethod, bool pathEncoded) { } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/HttpParserTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/HttpParserTests.cs index 6ad29a68cb..4605f5d8a0 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/HttpParserTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/HttpParserTests.cs @@ -49,14 +49,16 @@ namespace Microsoft.AspNetCore.Server.KestrelTests It.IsAny>(), It.IsAny>(), It.IsAny>(), - It.IsAny>())) - .Callback, Span, Span, Span>((method, version, target, path, query, customMethod) => + It.IsAny>(), + It.IsAny())) + .Callback, Span, Span, Span, bool>((method, version, target, path, query, customMethod, pathEncoded) => { parsedMethod = method != HttpMethod.Custom ? HttpUtilities.MethodToString(method) : customMethod.GetAsciiStringNonNullCharacters(); parsedVersion = HttpUtilities.VersionToString(version); parsedRawTarget = target.GetAsciiStringNonNullCharacters(); parsedRawPath = path.GetAsciiStringNonNullCharacters(); parsedQuery = query.GetAsciiStringNonNullCharacters(); + pathEncoded = false; }); Assert.True(parser.ParseRequestLine(requestLineHandler.Object, buffer, out var consumed, out var examined)); From 49b328d4c20a7a2f39748390022415671e33a6ca Mon Sep 17 00:00:00 2001 From: Nate McMaster Date: Thu, 9 Mar 2017 16:54:12 -0800 Subject: [PATCH 1111/1662] Handle absolute, asterisk, and authority-form request targets Improves compliance with RFC 7230 on the expected handling of requests that have URI or asterisk in the request target. This means rejecting asterisk requests that are not OPTIONS and rejecting authority-form requests taht are not CONNECT. This also means the server will handle the path and query on targets with absolute URIs as request-targets. --- .../BadHttpRequestException.cs | 19 ++ .../Internal/Http/Frame.cs | 189 +++++++++++++++--- .../Internal/Http/HttpScheme.cs | 12 ++ .../Internal/Http/IHttpRequestLineHandler.cs | 2 +- .../Internal/Http/KestrelHttpParser.cs | 8 +- .../Internal/Http/RequestRejectionReason.cs | 4 +- .../Internal/Infrastructure/HttpUtilities.cs | 47 +++++ .../Internal/Infrastructure/UriUtilities.cs | 35 ++++ .../BadHttpRequestTests.cs | 40 +++- .../RequestTests.cs | 66 ++++++ .../FrameParsingOverhead.cs | 10 +- .../KestrelHttpParser.cs | 2 +- .../FrameTests.cs | 51 +++++ .../HttpParserTests.cs | 3 +- .../HttpUtilitiesTest.cs | 14 +- .../RequestTargetProcessingTests.cs | 20 +- test/shared/HttpParsingData.cs | 89 ++++++++- 17 files changed, 557 insertions(+), 54 deletions(-) create mode 100644 src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/HttpScheme.cs create mode 100644 src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/UriUtilities.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/BadHttpRequestException.cs b/src/Microsoft.AspNetCore.Server.Kestrel/BadHttpRequestException.cs index 09aaf94a45..e735506074 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/BadHttpRequestException.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/BadHttpRequestException.cs @@ -4,19 +4,32 @@ using System.IO; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; +using Microsoft.Extensions.Primitives; namespace Microsoft.AspNetCore.Server.Kestrel { public sealed class BadHttpRequestException : IOException { private BadHttpRequestException(string message, int statusCode) + : this(message, statusCode, null) + { } + + private BadHttpRequestException(string message, int statusCode, HttpMethod? requiredMethod) : base(message) { StatusCode = statusCode; + + if (requiredMethod.HasValue) + { + AllowedHeader = HttpUtilities.MethodToString(requiredMethod.Value); + } } internal int StatusCode { get; } + internal StringValues AllowedHeader { get; } + internal static BadHttpRequestException GetException(RequestRejectionReason reason) { BadHttpRequestException ex; @@ -61,6 +74,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel case RequestRejectionReason.RequestTimeout: ex = new BadHttpRequestException("Request timed out.", StatusCodes.Status408RequestTimeout); break; + case RequestRejectionReason.OptionsMethodRequired: + ex = new BadHttpRequestException("Method not allowed.", StatusCodes.Status405MethodNotAllowed, HttpMethod.Options); + break; + case RequestRejectionReason.ConnectMethodRequired: + ex = new BadHttpRequestException("Method not allowed.", StatusCodes.Status405MethodNotAllowed, HttpMethod.Connect); + break; default: ex = new BadHttpRequestException("Bad request.", StatusCodes.Status400BadRequest); break; diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs index c8a5e20033..921646530c 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs @@ -11,7 +11,6 @@ using System.Net; using System.Runtime.CompilerServices; using System.Text; using System.Text.Encodings.Web.Utf8; -using System.Text.Utf8; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; @@ -27,6 +26,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { public abstract partial class Frame : IFrameControl, IHttpRequestLineHandler, IHttpHeadersHandler { + private const byte ByteAsterisk = (byte)'*'; + private const byte ByteForwardSlash = (byte)'/'; private const byte BytePercentage = (byte)'%'; private static readonly ArraySegment _endChunkedResponseBytes = CreateAsciiByteArraySegment("0\r\n\r\n"); @@ -39,6 +40,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http private static readonly byte[] _bytesEndHeaders = Encoding.ASCII.GetBytes("\r\n\r\n"); private static readonly byte[] _bytesServer = Encoding.ASCII.GetBytes("\r\nServer: Kestrel"); + private const string EmptyPath = "/"; + private const string Asterisk = "*"; + private readonly object _onStartingSync = new Object(); private readonly object _onCompletedSync = new Object(); @@ -818,7 +822,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http // that should take precedence. if (_requestRejectedException != null) { - SetErrorResponseHeaders(statusCode: _requestRejectedException.StatusCode); + SetErrorResponseException(_requestRejectedException); } else { @@ -1077,7 +1081,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { buffer = buffer.Slice(buffer.Start, _remainingRequestHeadersBytesAllowed); - // If we sliced it means the current buffer bigger than what we're + // If we sliced it means the current buffer bigger than what we're // allowed to look at overLength = true; } @@ -1127,6 +1131,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } } + private void SetErrorResponseException(BadHttpRequestException ex) + { + SetErrorResponseHeaders(ex.StatusCode); + + if (!StringValues.IsNullOrEmpty(ex.AllowedHeader)) + { + FrameResponseHeaders.HeaderAllow = ex.AllowedHeader; + } + } + private void SetErrorResponseHeaders(int statusCode) { Debug.Assert(!HasResponseStarted, $"{nameof(SetErrorResponseHeaders)} called after response had already started."); @@ -1179,6 +1193,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http throw BadHttpRequestException.GetException(reason, value); } + private void RejectRequestLine(Span requestLine) + { + Debug.Assert(Log.IsEnabled(LogLevel.Information) == true, "Use RejectRequest instead to improve inlining when log is disabled"); + + const int MaxRequestLineError = 32; + var line = requestLine.GetAsciiStringEscaped(MaxRequestLineError); + throw BadHttpRequestException.GetException(RequestRejectionReason.InvalidRequestLine, line); + } + public void SetBadRequestState(RequestRejectionReason reason) { SetBadRequestState(BadHttpRequestException.GetException(reason)); @@ -1190,7 +1213,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if (!HasResponseStarted) { - SetErrorResponseHeaders(ex.StatusCode); + SetErrorResponseException(ex); } _keepAlive = false; @@ -1216,8 +1239,51 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http Log.ApplicationError(ConnectionId, ex); } - public void OnStartLine(HttpMethod method, HttpVersion version, Span target, Span path, Span query, Span customMethod, bool pathEncoded) + public void OnStartLine(HttpMethod method, HttpVersion version, Span target, Span path, Span query, Span customMethod, Span line, bool pathEncoded) { + Debug.Assert(target.Length != 0, "Request target must be non-zero length"); + + var ch = target[0]; + if (ch == ByteForwardSlash) + { + // origin-form. + // The most common form of request-target. + // https://tools.ietf.org/html/rfc7230#section-5.3.1 + OnOriginFormTarget(method, version, target, path, query, customMethod, pathEncoded); + } + else if (ch == ByteAsterisk && target.Length == 1) + { + OnAsteriskFormTarget(method); + } + else if (target.GetKnownHttpScheme(out var scheme)) + { + OnAbsoluteFormTarget(target, query, line); + } + else + { + // Assume anything else is considered authority form. + // FYI: this should be an edge case. This should only happen when + // a client mistakenly things this server is a proxy server. + + OnAuthorityFormTarget(method, target, line); + } + + Method = method != HttpMethod.Custom + ? HttpUtilities.MethodToString(method) ?? string.Empty + : customMethod.GetAsciiStringNonNullCharacters(); + HttpVersion = HttpUtilities.VersionToString(version); + + Debug.Assert(RawTarget != null, "RawTarget was not set"); + Debug.Assert(Method != null, "Method was not set"); + Debug.Assert(Path != null, "Path was not set"); + Debug.Assert(QueryString != "QueryString was not set"); + Debug.Assert(HttpVersion != "HttpVersion was not set"); + } + + private void OnOriginFormTarget(HttpMethod method, HttpVersion version, Span target, Span path, Span query, Span customMethod, bool pathEncoded) + { + Debug.Assert(target[0] == ByteForwardSlash, "Should only be called when path starts with /"); + // URIs are always encoded/escaped to ASCII https://tools.ietf.org/html/rfc3986#page-11 // Multibyte Internationalized Resource Identifiers (IRIs) are first converted to utf8; // then encoded/escaped to ASCII https://www.ietf.org/rfc/rfc3987.txt "Mapping of IRIs to URIs" @@ -1249,34 +1315,111 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } } - var normalizedTarget = PathNormalizer.RemoveDotSegments(requestUrlPath); - if (method != HttpMethod.Custom) - { - Method = HttpUtilities.MethodToString(method) ?? string.Empty; - } - else - { - Method = customMethod.GetAsciiStringNonNullCharacters(); - } - QueryString = query.GetAsciiStringNonNullCharacters(); RawTarget = rawTarget; - HttpVersion = HttpUtilities.VersionToString(version); + SetNormalizedPath(requestUrlPath); + } + private void OnAuthorityFormTarget(HttpMethod method, Span target, Span line) + { + // TODO Validate that target is a correct host[:port] string. + // Reject as 400 if not. This is just a quick scan for invalid characters + // but doesn't check that the target fully matches the URI spec. + for (var i = 0; i < target.Length; i++) + { + var ch = target[i]; + if (!UriUtilities.IsValidAuthorityCharacter(ch)) + { + if (Log.IsEnabled(LogLevel.Information)) + { + RejectRequestLine(line); + } + + throw BadHttpRequestException.GetException(RequestRejectionReason.InvalidRequestLine); + } + } + + // The authority-form of request-target is only used for CONNECT + // requests (https://tools.ietf.org/html/rfc7231#section-4.3.6). + if (method != HttpMethod.Connect) + { + RejectRequest(RequestRejectionReason.ConnectMethodRequired); + } + + // When making a CONNECT request to establish a tunnel through one or + // more proxies, a client MUST send only the target URI's authority + // component(excluding any userinfo and its "@" delimiter) as the + // request - target.For example, + // + // CONNECT www.example.com:80 HTTP/1.1 + // + // Allowed characters in the 'host + port' section of authority. + // See https://tools.ietf.org/html/rfc3986#section-3.2 + + RawTarget = target.GetAsciiStringNonNullCharacters(); + Path = string.Empty; + PathBase = string.Empty; + QueryString = string.Empty; + } + + private void OnAsteriskFormTarget(HttpMethod method) + { + // The asterisk-form of request-target is only used for a server-wide + // OPTIONS request (https://tools.ietf.org/html/rfc7231#section-4.3.7). + if (method != HttpMethod.Options) + { + RejectRequest(RequestRejectionReason.OptionsMethodRequired); + } + + RawTarget = Asterisk; + Path = string.Empty; + PathBase = string.Empty; + QueryString = string.Empty; + } + + private void OnAbsoluteFormTarget(Span target, Span query, Span line) + { + // absolute-form + // https://tools.ietf.org/html/rfc7230#section-5.3.2 + + // This code should be the edge-case. + + // From the spec: + // a server MUST accept the absolute-form in requests, even though + // HTTP/1.1 clients will only send them in requests to proxies. + + RawTarget = target.GetAsciiStringNonNullCharacters(); + + // Validation of absolute URIs is slow, but clients + // should not be sending this form anyways, so perf optimization + // not high priority + + if (!Uri.TryCreate(RawTarget, UriKind.Absolute, out var uri)) + { + if (Log.IsEnabled(LogLevel.Information)) + { + RejectRequestLine(line); + } + + throw BadHttpRequestException.GetException(RequestRejectionReason.InvalidRequestLine); + } + + SetNormalizedPath(uri.LocalPath); + // don't use uri.Query because we need the unescaped version + QueryString = query.GetAsciiStringNonNullCharacters(); + } + + private void SetNormalizedPath(string requestPath) + { + var normalizedTarget = PathNormalizer.RemoveDotSegments(requestPath); if (RequestUrlStartsWithPathBase(normalizedTarget, out bool caseMatches)) { PathBase = caseMatches ? _pathBase : normalizedTarget.Substring(0, _pathBase.Length); Path = normalizedTarget.Substring(_pathBase.Length); } - else if (rawTarget[0] == '/') // check rawTarget since normalizedTarget can be "" or "/" after dot segment removal - { - Path = normalizedTarget; - } else { - Path = string.Empty; - PathBase = string.Empty; - QueryString = string.Empty; + Path = normalizedTarget; } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/HttpScheme.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/HttpScheme.cs new file mode 100644 index 0000000000..23f0bed5b9 --- /dev/null +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/HttpScheme.cs @@ -0,0 +1,12 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http +{ + public enum HttpScheme + { + Unknown = -1, + Http = 0, + Https = 1 + } +} diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/IHttpRequestLineHandler.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/IHttpRequestLineHandler.cs index 83481002b3..ed53d928f3 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/IHttpRequestLineHandler.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/IHttpRequestLineHandler.cs @@ -7,6 +7,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { public interface IHttpRequestLineHandler { - void OnStartLine(HttpMethod method, HttpVersion version, Span target, Span path, Span query, Span customMethod, bool pathEncoded); + void OnStartLine(HttpMethod method, HttpVersion version, Span target, Span path, Span query, Span customMethod, Span line, bool pathEncoded); } } \ No newline at end of file diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/KestrelHttpParser.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/KestrelHttpParser.cs index 02363a2325..2e118c9809 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/KestrelHttpParser.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/KestrelHttpParser.cs @@ -157,7 +157,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http RejectRequestLine(data, length); } - handler.OnStartLine(method, httpVersion, targetBuffer, pathBuffer, query, customMethod, pathEncoded); + var line = new Span(data, length); + + handler.OnStartLine(method, httpVersion, targetBuffer, pathBuffer, query, customMethod, line, pathEncoded); } public unsafe bool ParseHeaders(T handler, ReadableBuffer buffer, out ReadCursor consumed, out ReadCursor examined, out int consumedBytes) where T : IHttpHeadersHandler @@ -341,7 +343,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http // Skip colon from value start var valueStart = nameEnd + 1; // Ignore start whitespace - for(; valueStart < valueEnd; valueStart++) + for (; valueStart < valueEnd; valueStart++) { var ch = headerLine[valueStart]; if (ch != ByteTab && ch != ByteSpace && ch != ByteCR) @@ -409,7 +411,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } } return false; - found: + found: return true; } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/RequestRejectionReason.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/RequestRejectionReason.cs index 92faea1965..ce68141b93 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/RequestRejectionReason.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/RequestRejectionReason.cs @@ -23,6 +23,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http RequestTimeout, FinalTransferCodingNotChunked, LengthRequired, - LengthRequiredHttp10 + LengthRequiredHttp10, + OptionsMethodRequired, + ConnectMethodRequired, } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/HttpUtilities.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/HttpUtilities.cs index 182d424eb9..3def317d96 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/HttpUtilities.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/HttpUtilities.cs @@ -15,7 +15,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure public const string Http10Version = "HTTP/1.0"; public const string Http11Version = "HTTP/1.1"; + public const string HttpUriScheme = "http://"; + public const string HttpsUriScheme = "https://"; + // readonly primitive statics can be Jit'd to consts https://github.com/dotnet/coreclr/issues/1079 + + private readonly static ulong _httpSchemeLong = GetAsciiStringAsLong(HttpUriScheme + "\0"); + private readonly static ulong _httpsSchemeLong = GetAsciiStringAsLong(HttpsUriScheme); private readonly static ulong _httpConnectMethodLong = GetAsciiStringAsLong("CONNECT "); private readonly static ulong _httpDeleteMethodLong = GetAsciiStringAsLong("DELETE \0"); private const uint _httpGetMethodInt = 542393671; // retun of GetAsciiStringAsInt("GET "); const results in better codegen @@ -253,6 +259,34 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure return knownVersion; } + /// + /// Checks 8 bytes from that correspond to 'http://' or 'https://' + /// + /// The span + /// A reference to the known scheme, if the input matches any + /// True when memory starts with known http or https schema + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static bool GetKnownHttpScheme(this Span span, out HttpScheme knownScheme) + { + if (span.TryRead(out var value)) + { + if ((value & _mask7Chars) == _httpSchemeLong) + { + knownScheme = HttpScheme.Http; + return true; + } + + if (value == _httpsSchemeLong) + { + knownScheme = HttpScheme.Https; + return true; + } + } + + knownScheme = HttpScheme.Unknown; + return false; + } + public static string VersionToString(HttpVersion httpVersion) { switch (httpVersion) @@ -274,5 +308,18 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure } return null; } + + public static string SchemeToString(HttpScheme scheme) + { + switch (scheme) + { + case HttpScheme.Http: + return HttpUriScheme; + case HttpScheme.Https: + return HttpsUriScheme; + default: + return null; + } + } } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/UriUtilities.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/UriUtilities.cs new file mode 100644 index 0000000000..defcb9eb4f --- /dev/null +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/UriUtilities.cs @@ -0,0 +1,35 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure +{ + public class UriUtilities + { + /// + /// Returns true if character is valid in the 'authority' section of a URI. + /// + /// + /// The character + /// + public static bool IsValidAuthorityCharacter(byte ch) + { + // Examples: + // microsoft.com + // hostname:8080 + // [::]:8080 + // [fe80::] + // 127.0.0.1 + // user@host.com + // user:password@host.com + return + (ch >= '0' && ch <= '9') || + (ch >= 'A' && ch <= 'Z') || + (ch >= 'a' && ch <= 'z') || + ch == ':' || + ch == '.' || + ch == '[' || + ch == ']' || + ch == '@'; + } + } +} diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/BadHttpRequestTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/BadHttpRequestTests.cs index 380a51188e..3d3711cad6 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/BadHttpRequestTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/BadHttpRequestTests.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Collections.Generic; +using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.AspNetCore.Testing; @@ -90,7 +91,19 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests $"Invalid content length: {contentLength}"); } - private async Task TestBadRequest(string request, string expectedResponseStatusCode, string expectedExceptionMessage) + [Theory] + [InlineData("GET *", "OPTIONS")] + [InlineData("GET www.host.com", "CONNECT")] + public Task RejectsIncorrectMethods(string request, string allowedMethod) + { + return TestBadRequest( + $"{request} HTTP/1.1\r\n", + "405 Method Not Allowed", + "Method not allowed.", + $"Allow: {allowedMethod}"); + } + + private async Task TestBadRequest(string request, string expectedResponseStatusCode, string expectedExceptionMessage, string expectedAllowHeader = null) { BadHttpRequestException loggedException = null; var mockKestrelTrace = new Mock(); @@ -106,7 +119,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests using (var connection = server.CreateConnection()) { await connection.SendAll(request); - await ReceiveBadRequestResponse(connection, expectedResponseStatusCode, server.Context.DateHeaderValue); + await ReceiveBadRequestResponse(connection, expectedResponseStatusCode, server.Context.DateHeaderValue, expectedAllowHeader); } } @@ -114,15 +127,20 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests Assert.Equal(expectedExceptionMessage, loggedException.Message); } - private async Task ReceiveBadRequestResponse(TestConnection connection, string expectedResponseStatusCode, string expectedDateHeaderValue) + private async Task ReceiveBadRequestResponse(TestConnection connection, string expectedResponseStatusCode, string expectedDateHeaderValue, string expectedAllowHeader = null) { - await connection.ReceiveForcedEnd( + var lines = new[] + { $"HTTP/1.1 {expectedResponseStatusCode}", "Connection: close", $"Date: {expectedDateHeaderValue}", "Content-Length: 0", + expectedAllowHeader, "", - ""); + "" + }; + + await connection.ReceiveForcedEnd(lines.Where(f => f != null).ToArray()); } public static TheoryData InvalidRequestLineData @@ -131,9 +149,17 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { var data = new TheoryData(); + string Escape(string line) + { + return line + .Replace("\r", @"\x0D") + .Replace("\n", @"\x0A") + .Replace("\0", @"\x00"); + } + foreach (var requestLine in HttpParsingData.RequestLineInvalidData) { - data.Add(requestLine, $"Invalid request line: '{requestLine.Replace("\r", "\\x0D").Replace("\n", "\\x0A")}'"); + data.Add(requestLine, $"Invalid request line: '{Escape(requestLine)}'"); } foreach (var requestLine in HttpParsingData.RequestLineWithEncodedNullCharInTargetData) @@ -143,7 +169,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests foreach (var requestLine in HttpParsingData.RequestLineWithNullCharInTargetData) { - data.Add(requestLine, "Invalid request line."); + data.Add(requestLine, $"Invalid request line."); } return data; diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs index 77ae582bfa..4e5afb14df 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs @@ -454,6 +454,72 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } } + [Theory] + [InlineData("http://localhost/abs/path", "/abs/path", null)] + [InlineData("https://localhost/abs/path", "/abs/path", null)] // handles mismatch scheme + [InlineData("https://localhost:22/abs/path", "/abs/path", null)] // handles mismatched ports + [InlineData("https://differenthost/abs/path", "/abs/path", null)] // handles mismatched hostname + [InlineData("http://localhost/", "/", null)] + [InlineData("http://root@contoso.com/path", "/path", null)] + [InlineData("http://root:password@contoso.com/path", "/path", null)] + [InlineData("https://localhost/", "/", null)] + [InlineData("http://localhost", "/", null)] + [InlineData("http://127.0.0.1/", "/", null)] + [InlineData("http://[::1]/", "/", null)] + [InlineData("http://[::1]:8080/", "/", null)] + [InlineData("http://localhost?q=123&w=xyz", "/", "123")] + [InlineData("http://localhost/?q=123&w=xyz", "/", "123")] + [InlineData("http://localhost/path?q=123&w=xyz", "/path", "123")] + [InlineData("http://localhost/path%20with%20space?q=abc%20123", "/path with space", "abc 123")] + public async Task CanHandleRequestsWithUrlInAbsoluteForm(string requestUrl, string expectedPath, string queryValue) + { + var pathTcs = new TaskCompletionSource(); + var rawTargetTcs = new TaskCompletionSource(); + var hostTcs = new TaskCompletionSource(); + var queryTcs = new TaskCompletionSource(); + + using (var server = new TestServer(async context => + { + pathTcs.TrySetResult(context.Request.Path); + hostTcs.TrySetResult(context.Request.Host); + queryTcs.TrySetResult(context.Request.Query); + rawTargetTcs.TrySetResult(context.Features.Get().RawTarget); + await context.Response.WriteAsync("Done"); + })) + { + using (var connection = server.CreateConnection()) + { + await connection.Send( + $"GET {requestUrl} HTTP/1.1", + "Content-Length: 0", + "Host: localhost", + "", + ""); + + await connection.Receive($"HTTP/1.1 200 OK", + $"Date: {server.Context.DateHeaderValue}", + "Transfer-Encoding: chunked", + "", + "4", + "Done") + .TimeoutAfter(TimeSpan.FromSeconds(10)); + + await Task.WhenAll(pathTcs.Task, rawTargetTcs.Task, hostTcs.Task, queryTcs.Task).TimeoutAfter(TimeSpan.FromSeconds(30)); + Assert.Equal(new PathString(expectedPath), pathTcs.Task.Result); + Assert.Equal(requestUrl, rawTargetTcs.Task.Result); + Assert.Equal("localhost", hostTcs.Task.Result.ToString()); + if (queryValue == null) + { + Assert.False(queryTcs.Task.Result.ContainsKey("q")); + } + else + { + Assert.Equal(queryValue, queryTcs.Task.Result["q"]); + } + } + } + } + private async Task TestRemoteIPAddress(string registerAddress, string requestAddress, string expectAddress) { var builder = new WebHostBuilder() diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameParsingOverhead.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameParsingOverhead.cs index 3c077d6bf5..3c4276b619 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameParsingOverhead.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameParsingOverhead.cs @@ -94,6 +94,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance private class NullParser : IHttpParser { + private readonly byte[] _startLine = Encoding.ASCII.GetBytes("GET /plaintext HTTP/1.1\r\n"); private readonly byte[] _target = Encoding.ASCII.GetBytes("/plaintext"); private readonly byte[] _hostHeaderName = Encoding.ASCII.GetBytes("Host"); private readonly byte[] _hostHeaderValue = Encoding.ASCII.GetBytes("www.example.com"); @@ -119,7 +120,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance public bool ParseRequestLine(T handler, ReadableBuffer buffer, out ReadCursor consumed, out ReadCursor examined) where T : IHttpRequestLineHandler { - handler.OnStartLine(HttpMethod.Get, HttpVersion.Http11, new Span(_target), new Span(_target), Span.Empty, Span.Empty, false); + handler.OnStartLine(HttpMethod.Get, + HttpVersion.Http11, + new Span(_target), + new Span(_target), + Span.Empty, + Span.Empty, + new Span(_startLine), + false); consumed = buffer.Start; examined = buffer.End; diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/KestrelHttpParser.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/KestrelHttpParser.cs index a4da66cbe6..e49b613a45 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/KestrelHttpParser.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/KestrelHttpParser.cs @@ -66,7 +66,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance } } - public void OnStartLine(HttpMethod method, HttpVersion version, Span target, Span path, Span query, Span customMethod, bool pathEncoded) + public void OnStartLine(HttpMethod method, HttpVersion version, Span target, Span path, Span query, Span customMethod, Span line, bool pathEncoded) { } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs index bbac629985..ed28c1d86b 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs @@ -15,6 +15,7 @@ using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Server.Kestrel; using Microsoft.AspNetCore.Server.Kestrel.Internal; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.AspNetCore.Testing; using Microsoft.Extensions.Internal; using Moq; @@ -328,6 +329,37 @@ namespace Microsoft.AspNetCore.Server.KestrelTests Assert.Equal(new InvalidOperationException().Message, exception.Message); } + [Theory] + [MemberData(nameof(RequestLineWithInvalidRequestTargetData))] + public async Task TakeStartLineThrowsWhenRequestTargetIsInvalid(string requestLine) + { + await _input.Writer.WriteAsync(Encoding.ASCII.GetBytes(requestLine)); + var readableBuffer = (await _input.Reader.ReadAsync()).Buffer; + + var exception = Assert.Throws(() => + _frame.TakeStartLine(readableBuffer, out _consumed, out _examined)); + _input.Reader.Advance(_consumed, _examined); + + Assert.Equal($"Invalid request line: '{Escape(requestLine)}'", exception.Message); + } + + + [Theory] + [MemberData(nameof(MethodNotAllowedTargetData))] + public async Task TakeStartLineThrowsWhenMethodNotAllowed(string requestLine, HttpMethod allowedMethod) + { + await _input.Writer.WriteAsync(Encoding.ASCII.GetBytes(requestLine)); + var readableBuffer = (await _input.Reader.ReadAsync()).Buffer; + + var exception = Assert.Throws(() => + _frame.TakeStartLine(readableBuffer, out _consumed, out _examined)); + _input.Reader.Advance(_consumed, _examined); + + Assert.Equal(405, exception.StatusCode); + Assert.Equal("Method not allowed.", exception.Message); + Assert.Equal(HttpUtilities.MethodToString(allowedMethod), exception.AllowedHeader); + } + [Fact] public void RequestProcessingAsyncEnablesKeepAliveTimeout() { @@ -516,6 +548,25 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } } + private string Escape(string requestLine) + { + var ellipsis = requestLine.Length > 32 + ? "..." + : string.Empty; + return requestLine + .Substring(0, Math.Min(32, requestLine.Length)) + .Replace("\r", @"\x0D") + .Replace("\n", @"\x0A") + .Replace("\0", @"\x00") + + ellipsis; + } + + public static TheoryData RequestLineWithInvalidRequestTargetData + => HttpParsingData.RequestLineWithInvalidRequestTarget; + + public static TheoryData MethodNotAllowedTargetData + => HttpParsingData.MethodNotAllowedRequestLine; + public static TheoryData RequestLineWithNullCharInTargetData { get diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/HttpParserTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/HttpParserTests.cs index 4605f5d8a0..bd27800679 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/HttpParserTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/HttpParserTests.cs @@ -50,8 +50,9 @@ namespace Microsoft.AspNetCore.Server.KestrelTests It.IsAny>(), It.IsAny>(), It.IsAny>(), + It.IsAny>(), It.IsAny())) - .Callback, Span, Span, Span, bool>((method, version, target, path, query, customMethod, pathEncoded) => + .Callback, Span, Span, Span, Span, bool>((method, version, target, path, query, customMethod, line, pathEncoded) => { parsedMethod = method != HttpMethod.Custom ? HttpUtilities.MethodToString(method) : customMethod.GetAsciiStringNonNullCharacters(); parsedVersion = HttpUtilities.VersionToString(version); diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/HttpUtilitiesTest.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/HttpUtilitiesTest.cs index 6dd176e553..18b7a111c9 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/HttpUtilitiesTest.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/HttpUtilitiesTest.cs @@ -84,11 +84,23 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { TestKnownStringsInterning(input, expected, span => { - HttpUtilities.GetKnownVersion(span, out var version, out var lenght); + HttpUtilities.GetKnownVersion(span, out var version, out var _); return HttpUtilities.VersionToString(version); }); } + [Theory] + [InlineData("https://host/", "https://")] + [InlineData("http://host/", "http://")] + public void KnownSchemesAreInterned(string input, string expected) + { + TestKnownStringsInterning(input, expected, span => + { + HttpUtilities.GetKnownHttpScheme(span, out var scheme); + return HttpUtilities.SchemeToString(scheme); + }); + } + [Theory] [InlineData("CONNECT / HTTP/1.1", "CONNECT")] [InlineData("DELETE / HTTP/1.1", "DELETE")] diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/RequestTargetProcessingTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/RequestTargetProcessingTests.cs index 7a1d479f29..2da9a8144c 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/RequestTargetProcessingTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/RequestTargetProcessingTests.cs @@ -6,6 +6,8 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Server.Kestrel; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.AspNetCore.Testing; using Xunit; @@ -93,19 +95,9 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } [Theory] - [InlineData("*")] - [InlineData("*/?arg=value")] - [InlineData("*?arg=value")] - [InlineData("DoesNotStartWith/")] - [InlineData("DoesNotStartWith/?arg=value")] - [InlineData("DoesNotStartWithSlash?arg=value")] - [InlineData("./")] - [InlineData("../")] - [InlineData("../.")] - [InlineData(".././")] - [InlineData("../..")] - [InlineData("../../")] - public async Task NonPathRequestTargetSetInRawTarget(string requestTarget) + [InlineData(HttpMethod.Options, "*")] + [InlineData(HttpMethod.Connect, "host")] + public async Task NonPathRequestTargetSetInRawTarget(HttpMethod method, string requestTarget) { var testContext = new TestServiceContext(); @@ -123,7 +115,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests using (var connection = server.CreateConnection()) { await connection.Send( - $"GET {requestTarget} HTTP/1.1", + $"{HttpUtilities.MethodToString(method)} {requestTarget} HTTP/1.1", "", ""); await connection.ReceiveEnd( diff --git a/test/shared/HttpParsingData.cs b/test/shared/HttpParsingData.cs index e999fb3170..9e5df5e426 100644 --- a/test/shared/HttpParsingData.cs +++ b/test/shared/HttpParsingData.cs @@ -1,6 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; using System; using System.Collections.Generic; using System.Linq; @@ -33,6 +34,26 @@ namespace Microsoft.AspNetCore.Testing Tuple.Create("/%C3%A5/bc", "/\u00E5/bc"), Tuple.Create("/%25", "/%"), Tuple.Create("/%2F", "/%2F"), + Tuple.Create("http://host/abs/path", "/abs/path"), + Tuple.Create("http://host/abs/path/", "/abs/path/"), + Tuple.Create("http://host/a%20b%20c/", "/a b c/"), + Tuple.Create("https://host/abs/path", "/abs/path"), + Tuple.Create("https://host/abs/path/", "/abs/path/"), + Tuple.Create("https://host:22/abs/path", "/abs/path"), + Tuple.Create("https://user@host:9080/abs/path", "/abs/path"), + Tuple.Create("http://host/", "/"), + Tuple.Create("http://host", "/"), + Tuple.Create("https://host/", "/"), + Tuple.Create("https://host", "/"), + Tuple.Create("http://user@host/", "/"), + Tuple.Create("http://127.0.0.1/", "/"), + Tuple.Create("http://user@127.0.0.1/", "/"), + Tuple.Create("http://user@127.0.0.1:8080/", "/"), + Tuple.Create("http://127.0.0.1:8080/", "/"), + Tuple.Create("http://[::1]", "/"), + Tuple.Create("http://[::1]/path", "/path"), + Tuple.Create("http://[::1]:8080/", "/"), + Tuple.Create("http://user@[::1]:8080/", "/"), }; var queryStrings = new[] { @@ -173,9 +194,73 @@ namespace Microsoft.AspNetCore.Testing "GET /%E8%01%00 HTTP/1.1\r\n", }; + public static TheoryData RequestLineWithInvalidRequestTarget => new TheoryData + { + // Invalid absolute-form requests + "GET http:// HTTP/1.1\r\n", + "GET http:/ HTTP/1.1\r\n", + "GET https:/ HTTP/1.1\r\n", + "GET http:/// HTTP/1.1\r\n", + "GET https:// HTTP/1.1\r\n", + "GET http://// HTTP/1.1\r\n", + "GET http://:80 HTTP/1.1\r\n", + "GET http://:80/abc HTTP/1.1\r\n", + "GET http://user@ HTTP/1.1\r\n", + "GET http://user@/abc HTTP/1.1\r\n", + "GET http://abc%20xyz/abc HTTP/1.1\r\n", + "GET http://%20/abc?query=%0A HTTP/1.1\r\n", + // Valid absolute-form but with unsupported schemes + "GET otherscheme://host/ HTTP/1.1\r\n", + "GET ws://host/ HTTP/1.1\r\n", + "GET wss://host/ HTTP/1.1\r\n", + // Must only have one asterisk + "OPTIONS ** HTTP/1.1\r\n", + // Relative form + "GET ../../ HTTP/1.1\r\n", + "GET ..\\. HTTP/1.1\r\n", + }; + + public static TheoryData MethodNotAllowedRequestLine + { + get + { + var methods = new[] + { + "GET", + "PUT", + "DELETE", + "POST", + "HEAD", + "TRACE", + "PATCH", + "CONNECT", + //"OPTIONS", + "CUSTOM", + }; + + var theoryData = new TheoryData(); + foreach (var line in methods + .Select(m => Tuple.Create($"{m} * HTTP/1.1\r\n", HttpMethod.Options)) + .Concat(new[] + { + // CONNECT required for authority-form targets + Tuple.Create("GET http:80 HTTP/1.1\r\n", HttpMethod.Connect), + Tuple.Create("GET http: HTTP/1.1\r\n", HttpMethod.Connect), + Tuple.Create("GET https: HTTP/1.1\r\n", HttpMethod.Connect), + Tuple.Create("GET . HTTP/1.1\r\n", HttpMethod.Connect), + })) + { + theoryData.Add(line.Item1, line.Item2); + } + + return theoryData; + } + } + public static IEnumerable RequestLineWithNullCharInTargetData => new[] { - "GET \0 HTTP/1.1\r\n", + // TODO re-enable after we get both #1469 and #1470 merged + // "GET \0 HTTP/1.1\r\n", "GET /\0 HTTP/1.1\r\n", "GET /\0\0 HTTP/1.1\r\n", "GET /%C8\0 HTTP/1.1\r\n", @@ -183,6 +268,8 @@ namespace Microsoft.AspNetCore.Testing public static TheoryData UnrecognizedHttpVersionData => new TheoryData { + " ", + "/", "H", "HT", "HTT", From 3c8ee39f1de441daf24c63943dc335af92bdf215 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Fri, 10 Mar 2017 20:04:28 +0000 Subject: [PATCH 1112/1662] Fxi writing perf test (#1478) --- test/Microsoft.AspNetCore.Server.Kestrel.Performance/Writing.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Writing.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Writing.cs index 04c8e414f9..9e641715e6 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Writing.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Writing.cs @@ -107,6 +107,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance Output = new MockSocketOutput(), ConnectionControl = Mock.Of() }; + connectionContext.ListenerContext.ServiceContext.HttpParserFactory = f => new Internal.Http.KestrelHttpParser(log: null); var frame = new TestFrame(application: null, context: connectionContext); frame.Reset(); From f479720d5a9eb7759e235cf94134dcdb93e87784 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Sat, 11 Mar 2017 18:19:13 -0800 Subject: [PATCH 1113/1662] Remove our custom bootstrapper and use the BenchmarkSwitcher (#1480) --- .../Program.cs | 58 +------------------ 1 file changed, 2 insertions(+), 56 deletions(-) diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Program.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Program.cs index 95ca5909db..8a8d9c6d68 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Program.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Program.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Reflection; using BenchmarkDotNet.Running; namespace Microsoft.AspNetCore.Server.Kestrel.Performance @@ -10,62 +11,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance { public static void Main(string[] args) { - var options = (uint[])Enum.GetValues(typeof(BenchmarkType)); - BenchmarkType type; - if (args.Length != 1 || !Enum.TryParse(args[0], out type)) - { - Console.WriteLine($"Please add benchmark to run as parameter:"); - for (var i = 0; i < options.Length; i++) - { - Console.WriteLine($" {((BenchmarkType)options[i]).ToString()}"); - } - - return; - } - - RunSelectedBenchmarks(type); + BenchmarkSwitcher.FromAssembly(typeof(Program).GetTypeInfo().Assembly).Run(args); } - - private static void RunSelectedBenchmarks(BenchmarkType type) - { - if (type.HasFlag(BenchmarkType.RequestParsing)) - { - BenchmarkRunner.Run(); - } - if (type.HasFlag(BenchmarkType.Writing)) - { - BenchmarkRunner.Run(); - } - if (type.HasFlag(BenchmarkType.Throughput)) - { - BenchmarkRunner.Run(); - } - if (type.HasFlag(BenchmarkType.KnownStrings)) - { - BenchmarkRunner.Run(); - } - if (type.HasFlag(BenchmarkType.KestrelHttpParser)) - { - BenchmarkRunner.Run(); - } - if (type.HasFlag(BenchmarkType.FrameParsingOverhead)) - { - BenchmarkRunner.Run(); - } - } - } - - [Flags] - public enum BenchmarkType : uint - { - RequestParsing = 1, - Writing = 2, - Throughput = 4, - KnownStrings = 8, - KestrelHttpParser = 16, - FrameParsingOverhead = 32, - // add new ones in powers of two - e.g. 2,4,8,16... - - All = uint.MaxValue } } From a26f96237b668f050e93041ab6617600abc85cfc Mon Sep 17 00:00:00 2001 From: Justin Van Patten Date: Sat, 11 Mar 2017 22:31:42 -0800 Subject: [PATCH 1114/1662] Specify StringComparison when calling string.StartsWith (#1484) StartsWith does a culture-sensitive comparison by default. An ordinal comparison makes more sense here. --- src/Microsoft.AspNetCore.Server.Kestrel/ServerAddress.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/ServerAddress.cs b/src/Microsoft.AspNetCore.Server.Kestrel/ServerAddress.cs index cfa0bff4e8..5030e81993 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/ServerAddress.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/ServerAddress.cs @@ -19,7 +19,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel { get { - return Host.StartsWith(Constants.UnixPipeHostPrefix); + return Host.StartsWith(Constants.UnixPipeHostPrefix, StringComparison.Ordinal); } } From b612da4e6cb78ca85cd6d12627037705b467e146 Mon Sep 17 00:00:00 2001 From: Justin Van Patten Date: Sun, 12 Mar 2017 12:20:41 -0700 Subject: [PATCH 1115/1662] Avoid an unnecessary closure allocation in ListenerSecondary (#1485) The tcs is being passed as the state, so use it from the state instead of closing over it. --- .../Internal/Http/ListenerSecondary.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ListenerSecondary.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ListenerSecondary.cs index 41de1df45c..331e1bc4f3 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ListenerSecondary.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ListenerSecondary.cs @@ -109,13 +109,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { req.Dispose(); + var innerTcs = (TaskCompletionSource)state; if (ex != null) { - tcs.SetException(ex); + innerTcs.SetException(ex); } else { - tcs.SetResult(0); + innerTcs.SetResult(0); } }, tcs); From 49f09d5a255262c70a13d3c3fde1e04180e563a0 Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Tue, 7 Mar 2017 21:37:53 -0800 Subject: [PATCH 1116/1662] Log rejected request targets. --- KestrelHttpServer.sln | 3 +- .../BadHttpRequestException.cs | 19 +- .../Internal/Http/Frame.cs | 103 +++---- .../Internal/Http/FrameOfT.cs | 7 +- .../Internal/Http/IHttpRequestLineHandler.cs | 2 +- .../Internal/Http/KestrelHttpParser.cs | 100 +++---- .../Internal/Http/RequestRejectionReason.cs | 1 + .../Internal/Infrastructure/Constants.cs | 2 + .../Internal/Infrastructure/HttpUtilities.cs | 4 +- .../BadHttpRequestTests.cs | 20 +- .../FrameParsingOverhead.cs | 1 - .../KestrelHttpParser.cs | 2 +- .../FrameTests.cs | 149 +++++++--- .../HttpParserTests.cs | 71 ++++- test/shared/HttpParsingData.cs | 277 ++++++++++-------- test/shared/StringExtensions.cs | 22 ++ 16 files changed, 468 insertions(+), 315 deletions(-) create mode 100644 test/shared/StringExtensions.cs diff --git a/KestrelHttpServer.sln b/KestrelHttpServer.sln index 60a967cf1a..48cd152ee9 100644 --- a/KestrelHttpServer.sln +++ b/KestrelHttpServer.sln @@ -1,6 +1,6 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 15 -VisualStudioVersion = 15.0.26222.1 +VisualStudioVersion = 15.0.26228.0 MinimumVisualStudioVersion = 10.0.40219.1 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{7972A5D6-3385-4127-9277-428506DD44FF}" ProjectSection(SolutionItems) = preProject @@ -29,6 +29,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "shared", "shared", "{0EF2AC test\shared\MockSocketOutput.cs = test\shared\MockSocketOutput.cs test\shared\MockSystemClock.cs = test\shared\MockSystemClock.cs test\shared\SocketInputExtensions.cs = test\shared\SocketInputExtensions.cs + test\shared\StringExtensions.cs = test\shared\StringExtensions.cs test\shared\TestApp.cs = test\shared\TestApp.cs test\shared\TestApplicationErrorLogger.cs = test\shared\TestApplicationErrorLogger.cs test\shared\TestConnection.cs = test\shared\TestConnection.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/BadHttpRequestException.cs b/src/Microsoft.AspNetCore.Server.Kestrel/BadHttpRequestException.cs index e735506074..3c80a8a53a 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/BadHttpRequestException.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/BadHttpRequestException.cs @@ -87,31 +87,34 @@ namespace Microsoft.AspNetCore.Server.Kestrel return ex; } - internal static BadHttpRequestException GetException(RequestRejectionReason reason, string value) + internal static BadHttpRequestException GetException(RequestRejectionReason reason, string detail) { BadHttpRequestException ex; switch (reason) { case RequestRejectionReason.InvalidRequestLine: - ex = new BadHttpRequestException($"Invalid request line: '{value}'", StatusCodes.Status400BadRequest); + ex = new BadHttpRequestException($"Invalid request line: '{detail}'", StatusCodes.Status400BadRequest); + break; + case RequestRejectionReason.InvalidRequestTarget: + ex = new BadHttpRequestException($"Invalid request target: '{detail}'", StatusCodes.Status400BadRequest); break; case RequestRejectionReason.InvalidRequestHeader: - ex = new BadHttpRequestException($"Invalid request header: '{value}'", StatusCodes.Status400BadRequest); + ex = new BadHttpRequestException($"Invalid request header: '{detail}'", StatusCodes.Status400BadRequest); break; case RequestRejectionReason.InvalidContentLength: - ex = new BadHttpRequestException($"Invalid content length: {value}", StatusCodes.Status400BadRequest); + ex = new BadHttpRequestException($"Invalid content length: {detail}", StatusCodes.Status400BadRequest); break; case RequestRejectionReason.UnrecognizedHTTPVersion: - ex = new BadHttpRequestException($"Unrecognized HTTP version: {value}", StatusCodes.Status505HttpVersionNotsupported); + ex = new BadHttpRequestException($"Unrecognized HTTP version: '{detail}'", StatusCodes.Status505HttpVersionNotsupported); break; case RequestRejectionReason.FinalTransferCodingNotChunked: - ex = new BadHttpRequestException($"Final transfer coding is not \"chunked\": \"{value}\"", StatusCodes.Status400BadRequest); + ex = new BadHttpRequestException($"Final transfer coding is not \"chunked\": \"{detail}\"", StatusCodes.Status400BadRequest); break; case RequestRejectionReason.LengthRequired: - ex = new BadHttpRequestException($"{value} request contains no Content-Length or Transfer-Encoding header", StatusCodes.Status411LengthRequired); + ex = new BadHttpRequestException($"{detail} request contains no Content-Length or Transfer-Encoding header", StatusCodes.Status411LengthRequired); break; case RequestRejectionReason.LengthRequiredHttp10: - ex = new BadHttpRequestException($"{value} request contains no Content-Length header", StatusCodes.Status400BadRequest); + ex = new BadHttpRequestException($"{detail} request contains no Content-Length header", StatusCodes.Status400BadRequest); break; default: ex = new BadHttpRequestException("Bad request.", StatusCodes.Status400BadRequest); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs index 921646530c..1f0c0e2fac 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs @@ -1184,23 +1184,20 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } public void RejectRequest(RequestRejectionReason reason) - { - throw BadHttpRequestException.GetException(reason); - } + => throw BadHttpRequestException.GetException(reason); - public void RejectRequest(RequestRejectionReason reason, string value) - { - throw BadHttpRequestException.GetException(reason, value); - } + public void RejectRequest(RequestRejectionReason reason, string detail) + => throw BadHttpRequestException.GetException(reason, detail); - private void RejectRequestLine(Span requestLine) - { - Debug.Assert(Log.IsEnabled(LogLevel.Information) == true, "Use RejectRequest instead to improve inlining when log is disabled"); + private void RejectRequestTarget(Span target) + => throw GetInvalidRequestTargetException(target); - const int MaxRequestLineError = 32; - var line = requestLine.GetAsciiStringEscaped(MaxRequestLineError); - throw BadHttpRequestException.GetException(RequestRejectionReason.InvalidRequestLine, line); - } + private BadHttpRequestException GetInvalidRequestTargetException(Span target) + => BadHttpRequestException.GetException( + RequestRejectionReason.InvalidRequestTarget, + Log.IsEnabled(LogLevel.Information) + ? target.GetAsciiStringEscaped(Constants.MaxExceptionDetailSize) + : string.Empty); public void SetBadRequestState(RequestRejectionReason reason) { @@ -1239,7 +1236,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http Log.ApplicationError(ConnectionId, ex); } - public void OnStartLine(HttpMethod method, HttpVersion version, Span target, Span path, Span query, Span customMethod, Span line, bool pathEncoded) + public void OnStartLine(HttpMethod method, HttpVersion version, Span target, Span path, Span query, Span customMethod, bool pathEncoded) { Debug.Assert(target.Length != 0, "Request target must be non-zero length"); @@ -1257,15 +1254,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } else if (target.GetKnownHttpScheme(out var scheme)) { - OnAbsoluteFormTarget(target, query, line); + OnAbsoluteFormTarget(target, query); } else { // Assume anything else is considered authority form. // FYI: this should be an edge case. This should only happen when - // a client mistakenly things this server is a proxy server. - - OnAuthorityFormTarget(method, target, line); + // a client mistakenly thinks this server is a proxy server. + OnAuthorityFormTarget(method, target); } Method = method != HttpMethod.Custom @@ -1287,40 +1283,48 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http // URIs are always encoded/escaped to ASCII https://tools.ietf.org/html/rfc3986#page-11 // Multibyte Internationalized Resource Identifiers (IRIs) are first converted to utf8; // then encoded/escaped to ASCII https://www.ietf.org/rfc/rfc3987.txt "Mapping of IRIs to URIs" - string requestUrlPath; - string rawTarget; - if (pathEncoded) - { - // Read raw target before mutating memory. - rawTarget = target.GetAsciiStringNonNullCharacters(); + string requestUrlPath = null; + string rawTarget = null; - // URI was encoded, unescape and then parse as utf8 - int pathLength = UrlEncoder.Decode(path, path); - requestUrlPath = GetUtf8String(path.Slice(0, pathLength)); - } - else + try { - // URI wasn't encoded, parse as ASCII - requestUrlPath = path.GetAsciiStringNonNullCharacters(); - - if (query.Length == 0) + if (pathEncoded) { - // No need to allocate an extra string if the path didn't need - // decoding and there's no query string following it. - rawTarget = requestUrlPath; + // Read raw target before mutating memory. + rawTarget = target.GetAsciiStringNonNullCharacters(); + + // URI was encoded, unescape and then parse as utf8 + int pathLength = UrlEncoder.Decode(path, path); + requestUrlPath = GetUtf8String(path.Slice(0, pathLength)); } else { - rawTarget = target.GetAsciiStringNonNullCharacters(); + // URI wasn't encoded, parse as ASCII + requestUrlPath = path.GetAsciiStringNonNullCharacters(); + + if (query.Length == 0) + { + // No need to allocate an extra string if the path didn't need + // decoding and there's no query string following it. + rawTarget = requestUrlPath; + } + else + { + rawTarget = target.GetAsciiStringNonNullCharacters(); + } } } + catch (InvalidOperationException) + { + RejectRequestTarget(target); + } QueryString = query.GetAsciiStringNonNullCharacters(); RawTarget = rawTarget; SetNormalizedPath(requestUrlPath); } - private void OnAuthorityFormTarget(HttpMethod method, Span target, Span line) + private void OnAuthorityFormTarget(HttpMethod method, Span target) { // TODO Validate that target is a correct host[:port] string. // Reject as 400 if not. This is just a quick scan for invalid characters @@ -1330,12 +1334,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var ch = target[i]; if (!UriUtilities.IsValidAuthorityCharacter(ch)) { - if (Log.IsEnabled(LogLevel.Information)) - { - RejectRequestLine(line); - } - - throw BadHttpRequestException.GetException(RequestRejectionReason.InvalidRequestLine); + RejectRequestTarget(target); } } @@ -1348,14 +1347,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http // When making a CONNECT request to establish a tunnel through one or // more proxies, a client MUST send only the target URI's authority - // component(excluding any userinfo and its "@" delimiter) as the - // request - target.For example, + // component (excluding any userinfo and its "@" delimiter) as the + // request-target.For example, // // CONNECT www.example.com:80 HTTP/1.1 // // Allowed characters in the 'host + port' section of authority. // See https://tools.ietf.org/html/rfc3986#section-3.2 - RawTarget = target.GetAsciiStringNonNullCharacters(); Path = string.Empty; PathBase = string.Empty; @@ -1377,7 +1375,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http QueryString = string.Empty; } - private void OnAbsoluteFormTarget(Span target, Span query, Span line) + private void OnAbsoluteFormTarget(Span target, Span query) { // absolute-form // https://tools.ietf.org/html/rfc7230#section-5.3.2 @@ -1396,12 +1394,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if (!Uri.TryCreate(RawTarget, UriKind.Absolute, out var uri)) { - if (Log.IsEnabled(LogLevel.Information)) - { - RejectRequestLine(line); - } - - throw BadHttpRequestException.GetException(RequestRejectionReason.InvalidRequestLine); + RejectRequestTarget(target); } SetNormalizedPath(uri.LocalPath); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameOfT.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameOfT.cs index bf9d21e7ab..0065f6b8cf 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameOfT.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameOfT.cs @@ -50,12 +50,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } catch (InvalidOperationException) { - switch (_requestProcessingStatus) + if (_requestProcessingStatus == RequestProcessingStatus.ParsingHeaders) { - case RequestProcessingStatus.ParsingRequestLine: - throw BadHttpRequestException.GetException(RequestRejectionReason.InvalidRequestLine); - case RequestProcessingStatus.ParsingHeaders: - throw BadHttpRequestException.GetException(RequestRejectionReason.MalformedRequestInvalidHeaders); + throw BadHttpRequestException.GetException(RequestRejectionReason.MalformedRequestInvalidHeaders); } throw; } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/IHttpRequestLineHandler.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/IHttpRequestLineHandler.cs index ed53d928f3..83481002b3 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/IHttpRequestLineHandler.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/IHttpRequestLineHandler.cs @@ -7,6 +7,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { public interface IHttpRequestLineHandler { - void OnStartLine(HttpMethod method, HttpVersion version, Span target, Span path, Span query, Span customMethod, Span line, bool pathEncoded); + void OnStartLine(HttpMethod method, HttpVersion version, Span target, Span path, Span query, Span customMethod, bool pathEncoded); } } \ No newline at end of file diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/KestrelHttpParser.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/KestrelHttpParser.cs index 2e118c9809..17c0ebbf30 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/KestrelHttpParser.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/KestrelHttpParser.cs @@ -117,14 +117,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if (pathStart == -1) { - // End of path not found + // Start of path not found RejectRequestLine(data, length); } var pathBuffer = new Span(data + pathStart, offset - pathStart); - var queryStart = offset; // Query string + var queryStart = offset; if (ch == ByteQuestionMark) { // We have a query string @@ -138,6 +138,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } } + // End of query string not found + if (offset == length) + { + RejectRequestLine(data, length); + } + var targetBuffer = new Span(data + pathStart, offset - pathStart); var query = new Span(data + queryStart, offset - queryStart); @@ -148,10 +154,19 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var httpVersion = HttpUtilities.GetKnownVersion(data + offset, length - offset); if (httpVersion == HttpVersion.Unknown) { - RejectUnknownVersion(data, length, offset); + if (data[offset] == ByteCR || data[length - 2] != ByteCR) + { + // If missing delimiter or CR before LF, reject and log entire line + RejectRequestLine(data, length); + } + else + { + // else inform HTTP version is unsupported. + RejectUnknownVersion(data + offset, length - offset - 2); + } } - // After version 8 bytes and cr 1 byte, expect lf + // After version's 8 bytes and CR, expect LF if (data[offset + 8 + 1] != ByteLF) { RejectRequestLine(data, length); @@ -159,7 +174,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var line = new Span(data, length); - handler.OnStartLine(method, httpVersion, targetBuffer, pathBuffer, query, customMethod, line, pathEncoded); + handler.OnStartLine(method, httpVersion, targetBuffer, pathBuffer, query, customMethod, pathEncoded); } public unsafe bool ParseHeaders(T handler, ReadableBuffer buffer, out ReadCursor consumed, out ReadCursor examined, out int consumedBytes) where T : IHttpHeadersHandler @@ -482,73 +497,24 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http c == '~'; } - public static void RejectRequest(RequestRejectionReason reason) - { - throw BadHttpRequestException.GetException(reason); - } + private void RejectRequest(RequestRejectionReason reason) + => throw BadHttpRequestException.GetException(reason); - private unsafe void RejectUnknownVersion(byte* data, int length, int versionStart) - { - throw GetRejectUnknownVersion(data, length, versionStart); - } - - private unsafe void RejectRequestLine(byte* data, int length) - { - throw GetRejectRequestLineException(new Span(data, length)); - } - - private void RejectRequestLine(Span span) - { - throw GetRejectRequestLineException(span); - } - - private BadHttpRequestException GetRejectRequestLineException(Span span) - { - const int MaxRequestLineError = 32; - return BadHttpRequestException.GetException(RequestRejectionReason.InvalidRequestLine, - Log.IsEnabled(LogLevel.Information) ? span.GetAsciiStringEscaped(MaxRequestLineError) : string.Empty); - } - - private unsafe BadHttpRequestException GetRejectUnknownVersion(byte* data, int length, int versionStart) - { - var span = new Span(data, length); - length -= versionStart; - for (var i = 0; i < length; i++) - { - var ch = span[i + versionStart]; - if (ch == ByteCR) - { - if (i == 0) - { - return GetRejectRequestLineException(span); - } - else - { - return BadHttpRequestException.GetException(RequestRejectionReason.UnrecognizedHTTPVersion, - span.Slice(versionStart, i).GetAsciiStringEscaped(32)); - } - } - } - - return GetRejectRequestLineException(span); - } + private unsafe void RejectRequestLine(byte* requestLine, int length) + => throw GetInvalidRequestException(RequestRejectionReason.InvalidRequestLine, requestLine, length); private unsafe void RejectRequestHeader(byte* headerLine, int length) - { - RejectRequestHeader(new Span(headerLine, length)); - } + => throw GetInvalidRequestException(RequestRejectionReason.InvalidRequestHeader, headerLine, length); - private void RejectRequestHeader(Span span) - { - throw GetRejectRequestHeaderException(span); - } + private unsafe void RejectUnknownVersion(byte* version, int length) + => throw GetInvalidRequestException(RequestRejectionReason.UnrecognizedHTTPVersion, version, length); - private BadHttpRequestException GetRejectRequestHeaderException(Span span) - { - const int MaxRequestHeaderError = 128; - return BadHttpRequestException.GetException(RequestRejectionReason.InvalidRequestHeader, - Log.IsEnabled(LogLevel.Information) ? span.GetAsciiStringEscaped(MaxRequestHeaderError) : string.Empty); - } + private unsafe BadHttpRequestException GetInvalidRequestException(RequestRejectionReason reason, byte* detail, int length) + => BadHttpRequestException.GetException( + reason, + Log.IsEnabled(LogLevel.Information) + ? new Span(detail, length).GetAsciiStringEscaped(Constants.MaxExceptionDetailSize) + : string.Empty); public void Reset() { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/RequestRejectionReason.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/RequestRejectionReason.cs index ce68141b93..33aec0fc67 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/RequestRejectionReason.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/RequestRejectionReason.cs @@ -16,6 +16,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http BadChunkSuffix, BadChunkSizeData, ChunkedRequestIncomplete, + InvalidRequestTarget, InvalidCharactersInHeaderName, RequestLineTooLong, HeadersExceedMaxTotalSize, diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/Constants.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/Constants.cs index 2c201fea7c..0b7a9eaaa2 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/Constants.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/Constants.cs @@ -10,6 +10,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure { public const int ListenBacklog = 128; + public const int MaxExceptionDetailSize = 128; + public const int EOF = -4095; public static readonly int? ECONNRESET = GetECONNRESET(); public static readonly int? EADDRINUSE = GetEADDRINUSE(); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/HttpUtilities.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/HttpUtilities.cs index 3def317d96..32481ef1b1 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/HttpUtilities.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/HttpUtilities.cs @@ -126,8 +126,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure { var sb = new StringBuilder(); - int i; - for (i = 0; i < Math.Min(span.Length, maxChars); ++i) + for (var i = 0; i < Math.Min(span.Length, maxChars); i++) { var ch = span[i]; sb.Append(ch < 0x20 || ch >= 0x7F ? $"\\x{ch:X2}" : ((char)ch).ToString()); @@ -137,6 +136,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure { sb.Append("..."); } + return sb.ToString(); } diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/BadHttpRequestTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/BadHttpRequestTests.cs index 3d3711cad6..d2f09dd2b9 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/BadHttpRequestTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/BadHttpRequestTests.cs @@ -32,7 +32,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests return TestBadRequest( $"GET / {httpVersion}\r\n", "505 HTTP Version Not Supported", - $"Unrecognized HTTP version: {httpVersion}"); + $"Unrecognized HTTP version: '{httpVersion}'"); } [Theory] @@ -149,27 +149,19 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { var data = new TheoryData(); - string Escape(string line) - { - return line - .Replace("\r", @"\x0D") - .Replace("\n", @"\x0A") - .Replace("\0", @"\x00"); - } - foreach (var requestLine in HttpParsingData.RequestLineInvalidData) { - data.Add(requestLine, $"Invalid request line: '{Escape(requestLine)}'"); + data.Add(requestLine, $"Invalid request line: '{requestLine.EscapeNonPrintable()}'"); } - foreach (var requestLine in HttpParsingData.RequestLineWithEncodedNullCharInTargetData) + foreach (var target in HttpParsingData.TargetWithEncodedNullCharData) { - data.Add(requestLine, "Invalid request line."); + data.Add($"GET {target} HTTP/1.1\r\n", $"Invalid request target: '{target.EscapeNonPrintable()}'"); } - foreach (var requestLine in HttpParsingData.RequestLineWithNullCharInTargetData) + foreach (var target in HttpParsingData.TargetWithNullCharData) { - data.Add(requestLine, $"Invalid request line."); + data.Add($"GET {target} HTTP/1.1\r\n", $"Invalid request target: '{target.EscapeNonPrintable()}'"); } return data; diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameParsingOverhead.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameParsingOverhead.cs index 3c4276b619..aa3bdf84eb 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameParsingOverhead.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameParsingOverhead.cs @@ -126,7 +126,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance new Span(_target), Span.Empty, Span.Empty, - new Span(_startLine), false); consumed = buffer.Start; diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/KestrelHttpParser.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/KestrelHttpParser.cs index e49b613a45..a4da66cbe6 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/KestrelHttpParser.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/KestrelHttpParser.cs @@ -66,7 +66,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance } } - public void OnStartLine(HttpMethod method, HttpVersion version, Span target, Span path, Span query, Span customMethod, Span line, bool pathEncoded) + public void OnStartLine(HttpMethod method, HttpVersion version, Span target, Span path, Span query, Span customMethod, bool pathEncoded) { } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs index ed28c1d86b..7c8fd7bc62 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs @@ -18,6 +18,7 @@ using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.AspNetCore.Testing; using Microsoft.Extensions.Internal; +using Microsoft.Extensions.Logging; using Moq; using Xunit; @@ -302,37 +303,39 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } [Theory] - [MemberData(nameof(RequestLineWithEncodedNullCharInTargetData))] - public async Task TakeStartLineThrowsOnEncodedNullCharInTarget(string requestLine) + [MemberData(nameof(TargetWithEncodedNullCharData))] + public async Task TakeStartLineThrowsOnEncodedNullCharInTarget(string target) { - await _input.Writer.WriteAsync(Encoding.ASCII.GetBytes(requestLine)); + await _input.Writer.WriteAsync(Encoding.ASCII.GetBytes($"GET {target} HTTP/1.1\r\n")); var readableBuffer = (await _input.Reader.ReadAsync()).Buffer; - var exception = Assert.Throws(() => + var exception = Assert.Throws(() => _frame.TakeStartLine(readableBuffer, out _consumed, out _examined)); _input.Reader.Advance(_consumed, _examined); - Assert.Equal("The path contains null characters.", exception.Message); + Assert.Equal($"Invalid request target: '{target}'", exception.Message); } [Theory] - [MemberData(nameof(RequestLineWithNullCharInTargetData))] - public async Task TakeStartLineThrowsOnNullCharInTarget(string requestLine) + [MemberData(nameof(TargetWithNullCharData))] + public async Task TakeStartLineThrowsOnNullCharInTarget(string target) { - await _input.Writer.WriteAsync(Encoding.ASCII.GetBytes(requestLine)); + await _input.Writer.WriteAsync(Encoding.ASCII.GetBytes($"GET {target} HTTP/1.1\r\n")); var readableBuffer = (await _input.Reader.ReadAsync()).Buffer; - var exception = Assert.Throws(() => + var exception = Assert.Throws(() => _frame.TakeStartLine(readableBuffer, out _consumed, out _examined)); _input.Reader.Advance(_consumed, _examined); - Assert.Equal(new InvalidOperationException().Message, exception.Message); + Assert.Equal($"Invalid request target: '{target.EscapeNonPrintable()}'", exception.Message); } [Theory] - [MemberData(nameof(RequestLineWithInvalidRequestTargetData))] - public async Task TakeStartLineThrowsWhenRequestTargetIsInvalid(string requestLine) + [MemberData(nameof(MethodWithNullCharData))] + public async Task TakeStartLineThrowsOnNullCharInMethod(string method) { + var requestLine = $"{method} / HTTP/1.1\r\n"; + await _input.Writer.WriteAsync(Encoding.ASCII.GetBytes(requestLine)); var readableBuffer = (await _input.Reader.ReadAsync()).Buffer; @@ -340,9 +343,40 @@ namespace Microsoft.AspNetCore.Server.KestrelTests _frame.TakeStartLine(readableBuffer, out _consumed, out _examined)); _input.Reader.Advance(_consumed, _examined); - Assert.Equal($"Invalid request line: '{Escape(requestLine)}'", exception.Message); + Assert.Equal($"Invalid request line: '{requestLine.EscapeNonPrintable()}'", exception.Message); } + [Theory] + [MemberData(nameof(QueryStringWithNullCharData))] + public async Task TakeStartLineThrowsOnNullCharInQueryString(string queryString) + { + var target = $"/{queryString}"; + + await _input.Writer.WriteAsync(Encoding.ASCII.GetBytes($"GET {target} HTTP/1.1\r\n")); + var readableBuffer = (await _input.Reader.ReadAsync()).Buffer; + + var exception = Assert.Throws(() => + _frame.TakeStartLine(readableBuffer, out _consumed, out _examined)); + _input.Reader.Advance(_consumed, _examined); + + Assert.Equal($"Invalid request target: '{target.EscapeNonPrintable()}'", exception.Message); + } + + [Theory] + [MemberData(nameof(TargetInvalidData))] + public async Task TakeStartLineThrowsWhenRequestTargetIsInvalid(string method, string target) + { + var requestLine = $"{method} {target} HTTP/1.1\r\n"; + + await _input.Writer.WriteAsync(Encoding.ASCII.GetBytes(requestLine)); + var readableBuffer = (await _input.Reader.ReadAsync()).Buffer; + + var exception = Assert.Throws(() => + _frame.TakeStartLine(readableBuffer, out _consumed, out _examined)); + _input.Reader.Advance(_consumed, _examined); + + Assert.Equal($"Invalid request target: '{target.EscapeNonPrintable()}'", exception.Message); + } [Theory] [MemberData(nameof(MethodNotAllowedTargetData))] @@ -531,51 +565,98 @@ namespace Microsoft.AspNetCore.Server.KestrelTests Assert.NotSame(original, _frame.RequestAborted.WaitHandle); } + [Fact] + public async Task ExceptionDetailNotIncludedWhenLogLevelInformationNotEnabled() + { + var previousLog = _serviceContext.Log; + + try + { + var mockTrace = new Mock(); + mockTrace + .Setup(trace => trace.IsEnabled(LogLevel.Information)) + .Returns(false); + + _serviceContext.Log = mockTrace.Object; + + await _input.Writer.WriteAsync(Encoding.ASCII.GetBytes($"GET /%00 HTTP/1.1\r\n")); + var readableBuffer = (await _input.Reader.ReadAsync()).Buffer; + + var exception = Assert.Throws(() => + _frame.TakeStartLine(readableBuffer, out _consumed, out _examined)); + _input.Reader.Advance(_consumed, _examined); + + Assert.Equal("Invalid request target: ''", exception.Message); + Assert.Equal(StatusCodes.Status400BadRequest, exception.StatusCode); + } + finally + { + _serviceContext.Log = previousLog; + } + } + public static IEnumerable ValidRequestLineData => HttpParsingData.RequestLineValidData; - public static TheoryData RequestLineWithEncodedNullCharInTargetData + public static TheoryData TargetWithEncodedNullCharData { get { var data = new TheoryData(); - foreach (var requestLine in HttpParsingData.RequestLineWithEncodedNullCharInTargetData) + foreach (var target in HttpParsingData.TargetWithEncodedNullCharData) { - data.Add(requestLine); + data.Add(target); } return data; } } - private string Escape(string requestLine) - { - var ellipsis = requestLine.Length > 32 - ? "..." - : string.Empty; - return requestLine - .Substring(0, Math.Min(32, requestLine.Length)) - .Replace("\r", @"\x0D") - .Replace("\n", @"\x0A") - .Replace("\0", @"\x00") - + ellipsis; - } - - public static TheoryData RequestLineWithInvalidRequestTargetData - => HttpParsingData.RequestLineWithInvalidRequestTarget; + public static TheoryData TargetInvalidData + => HttpParsingData.TargetInvalidData; public static TheoryData MethodNotAllowedTargetData => HttpParsingData.MethodNotAllowedRequestLine; - public static TheoryData RequestLineWithNullCharInTargetData + public static TheoryData TargetWithNullCharData { get { var data = new TheoryData(); - foreach (var requestLine in HttpParsingData.RequestLineWithNullCharInTargetData) + foreach (var target in HttpParsingData.TargetWithNullCharData) { - data.Add(requestLine); + data.Add(target); + } + + return data; + } + } + + public static TheoryData MethodWithNullCharData + { + get + { + var data = new TheoryData(); + + foreach (var target in HttpParsingData.MethodWithNullCharData) + { + data.Add(target); + } + + return data; + } + } + + public static TheoryData QueryStringWithNullCharData + { + get + { + var data = new TheoryData(); + + foreach (var target in HttpParsingData.QueryStringWithNullCharData) + { + data.Add(target); } return data; diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/HttpParserTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/HttpParserTests.cs index bd27800679..41b5af4a55 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/HttpParserTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/HttpParserTests.cs @@ -19,9 +19,6 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { public class HttpParserTests { - // Returns true when all headers parsed - // Return false otherwise - [Theory] [MemberData(nameof(RequestLineValidData))] public void ParsesRequestLine( @@ -50,9 +47,8 @@ namespace Microsoft.AspNetCore.Server.KestrelTests It.IsAny>(), It.IsAny>(), It.IsAny>(), - It.IsAny>(), It.IsAny())) - .Callback, Span, Span, Span, Span, bool>((method, version, target, path, query, customMethod, line, pathEncoded) => + .Callback, Span, Span, Span, bool>((method, version, target, path, query, customMethod, pathEncoded) => { parsedMethod = method != HttpMethod.Custom ? HttpUtilities.MethodToString(method) : customMethod.GetAsciiStringNonNullCharacters(); parsedVersion = HttpUtilities.VersionToString(version); @@ -111,7 +107,28 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var exception = Assert.Throws(() => parser.ParseRequestLine(Mock.Of(), buffer, out var consumed, out var examined)); - Assert.Equal($"Invalid request line: '{requestLine.Replace("\r", "\\x0D").Replace("\n", "\\x0A")}'", exception.Message); + Assert.Equal($"Invalid request line: '{requestLine.EscapeNonPrintable()}'", exception.Message); + Assert.Equal(StatusCodes.Status400BadRequest, (exception as BadHttpRequestException).StatusCode); + } + + [Theory] + [MemberData(nameof(MethodWithNonTokenCharData))] + public void ParseRequestLineThrowsOnNonTokenCharsInCustomMethod(string method) + { + var requestLine = $"{method} / HTTP/1.1\r\n"; + + var mockTrace = new Mock(); + mockTrace + .Setup(trace => trace.IsEnabled(LogLevel.Information)) + .Returns(true); + + var parser = CreateParser(mockTrace.Object); + var buffer = ReadableBuffer.Create(Encoding.ASCII.GetBytes(requestLine)); + + var exception = Assert.Throws(() => + parser.ParseRequestLine(Mock.Of(), buffer, out var consumed, out var examined)); + + Assert.Equal($"Invalid request line: '{method.EscapeNonPrintable()} / HTTP/1.1\\x0D\\x0A'", exception.Message); Assert.Equal(StatusCodes.Status400BadRequest, (exception as BadHttpRequestException).StatusCode); } @@ -132,7 +149,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var exception = Assert.Throws(() => parser.ParseRequestLine(Mock.Of(), buffer, out var consumed, out var examined)); - Assert.Equal($"Unrecognized HTTP version: {httpVersion}", exception.Message); + Assert.Equal($"Unrecognized HTTP version: '{httpVersion}'", exception.Message); Assert.Equal(StatusCodes.Status505HttpVersionNotsupported, (exception as BadHttpRequestException).StatusCode); } @@ -324,6 +341,44 @@ namespace Microsoft.AspNetCore.Server.KestrelTests Assert.Equal(StatusCodes.Status400BadRequest, exception.StatusCode); } + [Fact] + public void ExceptionDetailNotIncludedWhenLogLevelInformationNotEnabled() + { + var mockTrace = new Mock(); + mockTrace + .Setup(trace => trace.IsEnabled(LogLevel.Information)) + .Returns(false); + + var parser = CreateParser(mockTrace.Object); + + // Invalid request line + var buffer = ReadableBuffer.Create(Encoding.ASCII.GetBytes("GET % HTTP/1.1\r\n")); + + var exception = Assert.Throws(() => + parser.ParseRequestLine(Mock.Of(), buffer, out var consumed, out var examined)); + + Assert.Equal("Invalid request line: ''", exception.Message); + Assert.Equal(StatusCodes.Status400BadRequest, (exception as BadHttpRequestException).StatusCode); + + // Unrecognized HTTP version + buffer = ReadableBuffer.Create(Encoding.ASCII.GetBytes("GET / HTTP/1.2\r\n")); + + exception = Assert.Throws(() => + parser.ParseRequestLine(Mock.Of(), buffer, out var consumed, out var examined)); + + Assert.Equal("Unrecognized HTTP version: ''", exception.Message); + Assert.Equal(StatusCodes.Status505HttpVersionNotsupported, (exception as BadHttpRequestException).StatusCode); + + // Invalid request header + buffer = ReadableBuffer.Create(Encoding.ASCII.GetBytes("Header: value\n\r\n")); + + exception = Assert.Throws(() => + parser.ParseHeaders(Mock.Of(), buffer, out var consumed, out var examined, out var consumedBytes)); + + Assert.Equal("Invalid request header: ''", exception.Message); + Assert.Equal(StatusCodes.Status400BadRequest, exception.StatusCode); + } + private void VerifyHeader( string headerName, string rawHeaderValue, @@ -384,6 +439,8 @@ namespace Microsoft.AspNetCore.Server.KestrelTests public static IEnumerable RequestLineInvalidData => HttpParsingData.RequestLineInvalidData.Select(requestLine => new[] { requestLine }); + public static IEnumerable MethodWithNonTokenCharData => HttpParsingData.MethodWithNonTokenCharData.Select(method => new[] { method }); + public static TheoryData UnrecognizedHttpVersionData => HttpParsingData.UnrecognizedHttpVersionData; public static IEnumerable RequestHeaderInvalidData => HttpParsingData.RequestHeaderInvalidData; diff --git a/test/shared/HttpParsingData.cs b/test/shared/HttpParsingData.cs index 9e5df5e426..f3bd39fcbe 100644 --- a/test/shared/HttpParsingData.cs +++ b/test/shared/HttpParsingData.cs @@ -112,113 +112,144 @@ namespace Microsoft.AspNetCore.Testing "GET / HTTP/1.1\r", }; - public static IEnumerable RequestLineInvalidData => new[] + public static IEnumerable RequestLineInvalidData + { + get + { + return new[] + { + "G\r\n", + "GE\r\n", + "GET\r\n", + "GET \r\n", + "GET /\r\n", + "GET / \r\n", + "GET/HTTP/1.1\r\n", + "GET /HTTP/1.1\r\n", + " \r\n", + " \r\n", + "/ HTTP/1.1\r\n", + " / HTTP/1.1\r\n", + "/ \r\n", + "GET \r\n", + "GET HTTP/1.0\r\n", + "GET HTTP/1.1\r\n", + "GET / \n", + "GET / HTTP/1.0\n", + "GET / HTTP/1.1\n", + "GET / HTTP/1.0\rA\n", + "GET / HTTP/1.1\ra\n", + "GET? / HTTP/1.1\r\n", + "GET ? HTTP/1.1\r\n", + "GET /a?b=cHTTP/1.1\r\n", + "GET /a%20bHTTP/1.1\r\n", + "GET /a%20b?c=dHTTP/1.1\r\n", + "GET %2F HTTP/1.1\r\n", + "GET %00 HTTP/1.1\r\n", + "CUSTOM \r\n", + "CUSTOM /\r\n", + "CUSTOM / \r\n", + "CUSTOM /HTTP/1.1\r\n", + "CUSTOM \r\n", + "CUSTOM HTTP/1.0\r\n", + "CUSTOM HTTP/1.1\r\n", + "CUSTOM / \n", + "CUSTOM / HTTP/1.0\n", + "CUSTOM / HTTP/1.1\n", + "CUSTOM / HTTP/1.0\rA\n", + "CUSTOM / HTTP/1.1\ra\n", + "CUSTOM ? HTTP/1.1\r\n", + "CUSTOM /a?b=cHTTP/1.1\r\n", + "CUSTOM /a%20bHTTP/1.1\r\n", + "CUSTOM /a%20b?c=dHTTP/1.1\r\n", + "CUSTOM %2F HTTP/1.1\r\n", + "CUSTOM %00 HTTP/1.1\r\n", + }.Concat(MethodWithNonTokenCharData.Select(method => $"{method} / HTTP/1.0\r\n")); + } + } + + // Bad HTTP Methods (invalid according to RFC) + public static IEnumerable MethodWithNonTokenCharData + { + get + { + return new[] + { + "(", + ")", + "<", + ">", + "@", + ",", + ";", + ":", + "\\", + "\"", + "/", + "[", + "]", + "?", + "=", + "{", + "}", + "get@", + "post=", + }.Concat(MethodWithNullCharData); + } + } + + public static IEnumerable MethodWithNullCharData => new[] { - "G\r\n", - "GE\r\n", - "GET\r\n", - "GET \r\n", - "GET /\r\n", - "GET / \r\n", - "GET/HTTP/1.1\r\n", - "GET /HTTP/1.1\r\n", - " \r\n", - " \r\n", - "/ HTTP/1.1\r\n", - " / HTTP/1.1\r\n", - "/ \r\n", - "GET \r\n", - "GET HTTP/1.0\r\n", - "GET HTTP/1.1\r\n", - "GET / \n", - "GET / HTTP/1.0\n", - "GET / HTTP/1.1\n", - "GET / HTTP/1.0\rA\n", - "GET / HTTP/1.1\ra\n", - "GET? / HTTP/1.1\r\n", - "GET ? HTTP/1.1\r\n", - "GET /a?b=cHTTP/1.1\r\n", - "GET /a%20bHTTP/1.1\r\n", - "GET /a%20b?c=dHTTP/1.1\r\n", - "GET %2F HTTP/1.1\r\n", - "GET %00 HTTP/1.1\r\n", - "CUSTOM \r\n", - "CUSTOM /\r\n", - "CUSTOM / \r\n", - "CUSTOM /HTTP/1.1\r\n", - "CUSTOM \r\n", - "CUSTOM HTTP/1.0\r\n", - "CUSTOM HTTP/1.1\r\n", - "CUSTOM / \n", - "CUSTOM / HTTP/1.0\n", - "CUSTOM / HTTP/1.1\n", - "CUSTOM / HTTP/1.0\rA\n", - "CUSTOM / HTTP/1.1\ra\n", - "CUSTOM ? HTTP/1.1\r\n", - "CUSTOM /a?b=cHTTP/1.1\r\n", - "CUSTOM /a%20bHTTP/1.1\r\n", - "CUSTOM /a%20b?c=dHTTP/1.1\r\n", - "CUSTOM %2F HTTP/1.1\r\n", - "CUSTOM %00 HTTP/1.1\r\n", // Bad HTTP Methods (invalid according to RFC) - "( / HTTP/1.0\r\n", - ") / HTTP/1.0\r\n", - "< / HTTP/1.0\r\n", - "> / HTTP/1.0\r\n", - "@ / HTTP/1.0\r\n", - ", / HTTP/1.0\r\n", - "; / HTTP/1.0\r\n", - ": / HTTP/1.0\r\n", - "\\ / HTTP/1.0\r\n", - "\" / HTTP/1.0\r\n", - "/ / HTTP/1.0\r\n", - "[ / HTTP/1.0\r\n", - "] / HTTP/1.0\r\n", - "? / HTTP/1.0\r\n", - "= / HTTP/1.0\r\n", - "{ / HTTP/1.0\r\n", - "} / HTTP/1.0\r\n", - "get@ / HTTP/1.0\r\n", - "post= / HTTP/1.0\r\n", + "\0", + "\0GET", + "G\0T", + "GET\0", }; - public static IEnumerable RequestLineWithEncodedNullCharInTargetData => new[] + public static IEnumerable TargetWithEncodedNullCharData => new[] { - "GET /%00 HTTP/1.1\r\n", - "GET /%00%00 HTTP/1.1\r\n", - "GET /%E8%00%84 HTTP/1.1\r\n", - "GET /%E8%85%00 HTTP/1.1\r\n", - "GET /%F3%00%82%86 HTTP/1.1\r\n", - "GET /%F3%85%00%82 HTTP/1.1\r\n", - "GET /%F3%85%82%00 HTTP/1.1\r\n", - "GET /%E8%01%00 HTTP/1.1\r\n", + "/%00", + "/%00%00", + "/%E8%00%84", + "/%E8%85%00", + "/%F3%00%82%86", + "/%F3%85%00%82", + "/%F3%85%82%00", }; - public static TheoryData RequestLineWithInvalidRequestTarget => new TheoryData + public static TheoryData TargetInvalidData { - // Invalid absolute-form requests - "GET http:// HTTP/1.1\r\n", - "GET http:/ HTTP/1.1\r\n", - "GET https:/ HTTP/1.1\r\n", - "GET http:/// HTTP/1.1\r\n", - "GET https:// HTTP/1.1\r\n", - "GET http://// HTTP/1.1\r\n", - "GET http://:80 HTTP/1.1\r\n", - "GET http://:80/abc HTTP/1.1\r\n", - "GET http://user@ HTTP/1.1\r\n", - "GET http://user@/abc HTTP/1.1\r\n", - "GET http://abc%20xyz/abc HTTP/1.1\r\n", - "GET http://%20/abc?query=%0A HTTP/1.1\r\n", - // Valid absolute-form but with unsupported schemes - "GET otherscheme://host/ HTTP/1.1\r\n", - "GET ws://host/ HTTP/1.1\r\n", - "GET wss://host/ HTTP/1.1\r\n", - // Must only have one asterisk - "OPTIONS ** HTTP/1.1\r\n", - // Relative form - "GET ../../ HTTP/1.1\r\n", - "GET ..\\. HTTP/1.1\r\n", - }; + get + { + var data = new TheoryData(); + + // Invalid absolute-form + data.Add("GET", "http://"); + data.Add("GET", "http:/"); + data.Add("GET", "https:/"); + data.Add("GET", "http:///"); + data.Add("GET", "https://"); + data.Add("GET", "http:////"); + data.Add("GET", "http://:80"); + data.Add("GET", "http://:80/abc"); + data.Add("GET", "http://user@"); + data.Add("GET", "http://user@/abc"); + data.Add("GET", "http://abc%20xyz/abc"); + data.Add("GET", "http://%20/abc?query=%0A"); + // Valid absolute-form but with unsupported schemes + data.Add("GET", "otherscheme://host/"); + data.Add("GET", "ws://host/"); + data.Add("GET", "wss://host/"); + // Must only have one asterisk + data.Add("OPTIONS", "**"); + // Relative form + data.Add("GET", "../../"); + data.Add("GET", "..\\."); + + return data; + } + } public static TheoryData MethodNotAllowedRequestLine { @@ -234,36 +265,44 @@ namespace Microsoft.AspNetCore.Testing "TRACE", "PATCH", "CONNECT", - //"OPTIONS", + "OPTIONS", "CUSTOM", }; - var theoryData = new TheoryData(); - foreach (var line in methods - .Select(m => Tuple.Create($"{m} * HTTP/1.1\r\n", HttpMethod.Options)) - .Concat(new[] - { - // CONNECT required for authority-form targets - Tuple.Create("GET http:80 HTTP/1.1\r\n", HttpMethod.Connect), - Tuple.Create("GET http: HTTP/1.1\r\n", HttpMethod.Connect), - Tuple.Create("GET https: HTTP/1.1\r\n", HttpMethod.Connect), - Tuple.Create("GET . HTTP/1.1\r\n", HttpMethod.Connect), - })) + var data = new TheoryData(); + + foreach (var method in methods.Except(new[] { "OPTIONS" })) { - theoryData.Add(line.Item1, line.Item2); + data.Add($"{method} * HTTP/1.1\r\n", HttpMethod.Options); } - return theoryData; + foreach (var method in methods.Except(new[] { "CONNECT" })) + { + data.Add($"{method} www.example.com:80 HTTP/1.1\r\n", HttpMethod.Connect); + } + + return data; } } - public static IEnumerable RequestLineWithNullCharInTargetData => new[] + public static IEnumerable TargetWithNullCharData { - // TODO re-enable after we get both #1469 and #1470 merged - // "GET \0 HTTP/1.1\r\n", - "GET /\0 HTTP/1.1\r\n", - "GET /\0\0 HTTP/1.1\r\n", - "GET /%C8\0 HTTP/1.1\r\n", + get + { + return new[] + { + "\0", + "/\0", + "/\0\0", + "/%C8\0", + }.Concat(QueryStringWithNullCharData); + } + } + + public static IEnumerable QueryStringWithNullCharData => new[] + { + "/?\0=a", + "/?a=\0", }; public static TheoryData UnrecognizedHttpVersionData => new TheoryData diff --git a/test/shared/StringExtensions.cs b/test/shared/StringExtensions.cs new file mode 100644 index 0000000000..5d1756b55b --- /dev/null +++ b/test/shared/StringExtensions.cs @@ -0,0 +1,22 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; + +namespace Microsoft.AspNetCore.Testing +{ + public static class StringExtensions + { + public static string EscapeNonPrintable(this string s) + { + var ellipsis = s.Length > 128 + ? "..." + : string.Empty; + return s.Substring(0, Math.Min(128, s.Length)) + .Replace("\r", @"\x0D") + .Replace("\n", @"\x0A") + .Replace("\0", @"\x00") + + ellipsis; + } + } +} \ No newline at end of file From 5644310811cd133abf22680807df0f97378b78e1 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Sun, 12 Mar 2017 22:52:24 -0700 Subject: [PATCH 1117/1662] Clean up benchmarks (#1487) - Benchmarks are suffixed with *Benchmarks - Removed Custom RpsColumn.cs and used Ops/Second column - Removed params from RequestParsingBenchmark --- .../ErrorUtilities.cs | 17 ++++++++++ ...ad.cs => FrameParsingOverheadBenchmark.cs} | 10 +++--- .../{Writing.cs => FrameWritingBenchmark.cs} | 4 +-- ...arser.cs => KestrelHttpParserBenchmark.cs} | 8 ++--- ...ownStrings.cs => KnownStringsBenchmark.cs} | 2 +- ...roughput.cs => PipeThroughputBenchmark.cs} | 2 +- ...tParsing.cs => RequestParsingBenchmark.cs} | 21 +++---------- .../RequestParsingData.cs | 2 -- ...Headers.cs => ResponseHeadersBenchmark.cs} | 2 +- .../columns/RpsColumn.cs | 31 ------------------- .../configs/CoreConfig.cs | 3 +- 11 files changed, 37 insertions(+), 65 deletions(-) create mode 100644 test/Microsoft.AspNetCore.Server.Kestrel.Performance/ErrorUtilities.cs rename test/Microsoft.AspNetCore.Server.Kestrel.Performance/{FrameParsingOverhead.cs => FrameParsingOverheadBenchmark.cs} (94%) rename test/Microsoft.AspNetCore.Server.Kestrel.Performance/{Writing.cs => FrameWritingBenchmark.cs} (97%) rename test/Microsoft.AspNetCore.Server.Kestrel.Performance/{KestrelHttpParser.cs => KestrelHttpParserBenchmark.cs} (87%) rename test/Microsoft.AspNetCore.Server.Kestrel.Performance/{KnownStrings.cs => KnownStringsBenchmark.cs} (98%) rename test/Microsoft.AspNetCore.Server.Kestrel.Performance/{PipeThroughput.cs => PipeThroughputBenchmark.cs} (98%) rename test/Microsoft.AspNetCore.Server.Kestrel.Performance/{RequestParsing.cs => RequestParsingBenchmark.cs} (87%) rename test/Microsoft.AspNetCore.Server.Kestrel.Performance/{ResponseHeaders.cs => ResponseHeadersBenchmark.cs} (99%) delete mode 100644 test/Microsoft.AspNetCore.Server.Kestrel.Performance/columns/RpsColumn.cs diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/ErrorUtilities.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/ErrorUtilities.cs new file mode 100644 index 0000000000..32ae14d571 --- /dev/null +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/ErrorUtilities.cs @@ -0,0 +1,17 @@ +using System; + +namespace Microsoft.AspNetCore.Server.Kestrel.Performance +{ + public static class ErrorUtilities + { + public static void ThrowInvalidRequestLine() + { + throw new InvalidOperationException("Invalid request line"); + } + + public static void ThrowInvalidRequestHeaders() + { + throw new InvalidOperationException("Invalid request headers"); + } + } +} diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameParsingOverhead.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameParsingOverheadBenchmark.cs similarity index 94% rename from test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameParsingOverhead.cs rename to test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameParsingOverheadBenchmark.cs index aa3bdf84eb..40bf9a6cd0 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameParsingOverhead.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameParsingOverheadBenchmark.cs @@ -11,7 +11,7 @@ using Microsoft.AspNetCore.Testing; namespace Microsoft.AspNetCore.Server.Kestrel.Performance { [Config(typeof(CoreConfig))] - public class FrameParsingOverhead + public class FrameParsingOverheadBenchmark { private const int InnerLoopCount = 512; @@ -60,14 +60,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance if (!_frame.TakeStartLine(_buffer, out var consumed, out var examined)) { - RequestParsing.ThrowInvalidRequestLine(); + ErrorUtilities.ThrowInvalidRequestLine(); } _frame.InitializeHeaders(); if (!_frame.TakeMessageHeaders(_buffer, out consumed, out examined)) { - RequestParsing.ThrowInvalidRequestHeaders(); + ErrorUtilities.ThrowInvalidRequestHeaders(); } } @@ -77,7 +77,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance if (!_frame.TakeStartLine(_buffer, out var consumed, out var examined)) { - RequestParsing.ThrowInvalidRequestLine(); + ErrorUtilities.ThrowInvalidRequestLine(); } } @@ -88,7 +88,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance if (!_frame.TakeMessageHeaders(_buffer, out var consumed, out var examined)) { - RequestParsing.ThrowInvalidRequestHeaders(); + ErrorUtilities.ThrowInvalidRequestHeaders(); } } diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Writing.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameWritingBenchmark.cs similarity index 97% rename from test/Microsoft.AspNetCore.Server.Kestrel.Performance/Writing.cs rename to test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameWritingBenchmark.cs index 9e641715e6..d632e337cd 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Writing.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameWritingBenchmark.cs @@ -16,13 +16,13 @@ using Moq; namespace Microsoft.AspNetCore.Server.Kestrel.Performance { [Config(typeof(CoreConfig))] - public class Writing + public class FrameWritingBenchmark { private readonly TestFrame _frame; private readonly TestFrame _frameChunked; private readonly byte[] _writeData; - public Writing() + public FrameWritingBenchmark() { _frame = MakeFrame(); _frameChunked = MakeFrame(); diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/KestrelHttpParser.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/KestrelHttpParserBenchmark.cs similarity index 87% rename from test/Microsoft.AspNetCore.Server.Kestrel.Performance/KestrelHttpParser.cs rename to test/Microsoft.AspNetCore.Server.Kestrel.Performance/KestrelHttpParserBenchmark.cs index a4da66cbe6..0a06b448d0 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/KestrelHttpParser.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/KestrelHttpParserBenchmark.cs @@ -10,9 +10,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance { [Config(typeof(CoreConfig))] - public class KestrelHttpParser : IHttpRequestLineHandler, IHttpHeadersHandler + public class KestrelHttpParserBenchmark : IHttpRequestLineHandler, IHttpHeadersHandler { - private readonly Internal.Http.KestrelHttpParser _parser = new Internal.Http.KestrelHttpParser(log: null); + private readonly KestrelHttpParser _parser = new KestrelHttpParser(log: null); private ReadableBuffer _buffer; @@ -55,14 +55,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance { if (!_parser.ParseRequestLine(this, _buffer, out var consumed, out var examined)) { - RequestParsing.ThrowInvalidRequestHeaders(); + ErrorUtilities.ThrowInvalidRequestHeaders(); } _buffer = _buffer.Slice(consumed, _buffer.End); if (!_parser.ParseHeaders(this, _buffer, out consumed, out examined, out var consumedBytes)) { - RequestParsing.ThrowInvalidRequestHeaders(); + ErrorUtilities.ThrowInvalidRequestHeaders(); } } diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/KnownStrings.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/KnownStringsBenchmark.cs similarity index 98% rename from test/Microsoft.AspNetCore.Server.Kestrel.Performance/KnownStrings.cs rename to test/Microsoft.AspNetCore.Server.Kestrel.Performance/KnownStringsBenchmark.cs index f5fd841f90..2bdc526f9e 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/KnownStrings.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/KnownStringsBenchmark.cs @@ -9,7 +9,7 @@ using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; namespace Microsoft.AspNetCore.Server.Kestrel.Performance { - public class KnownStrings + public class KnownStringsBenchmark { static byte[] _method = Encoding.UTF8.GetBytes("GET "); static byte[] _version = Encoding.UTF8.GetBytes("HTTP/1.1\r\n"); diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/PipeThroughput.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/PipeThroughputBenchmark.cs similarity index 98% rename from test/Microsoft.AspNetCore.Server.Kestrel.Performance/PipeThroughput.cs rename to test/Microsoft.AspNetCore.Server.Kestrel.Performance/PipeThroughputBenchmark.cs index dc99101261..abdd7ab8b7 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/PipeThroughput.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/PipeThroughputBenchmark.cs @@ -10,7 +10,7 @@ using BenchmarkDotNet.Attributes; namespace Microsoft.AspNetCore.Server.Kestrel.Performance { [Config(typeof(CoreConfig))] - public class PipeThroughput + public class PipeThroughputBenchmark { private const int _writeLenght = 57; private const int InnerLoopCount = 512; diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsing.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsingBenchmark.cs similarity index 87% rename from test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsing.cs rename to test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsingBenchmark.cs index ccaf08ba57..0b2e0ee914 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsing.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsingBenchmark.cs @@ -10,11 +10,8 @@ using Microsoft.AspNetCore.Testing; namespace Microsoft.AspNetCore.Server.Kestrel.Performance { [Config(typeof(CoreConfig))] - public class RequestParsing + public class RequestParsingBenchmark { - [Params(typeof(Internal.Http.KestrelHttpParser))] - public Type ParserType { get; set; } - public IPipe Pipe { get; set; } public Frame Frame { get; set; } @@ -25,7 +22,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance public void Setup() { var connectionContext = new MockConnection(new KestrelServerOptions()); - connectionContext.ListenerContext.ServiceContext.HttpParserFactory = frame => (IHttpParser)Activator.CreateInstance(ParserType, frame.ConnectionContext.ListenerContext.ServiceContext.Log); + connectionContext.ListenerContext.ServiceContext.HttpParserFactory = frame => new KestrelHttpParser(frame.ConnectionContext.ListenerContext.ServiceContext.Log); Frame = new Frame(application: null, context: connectionContext); PipelineFactory = new PipeFactory(); @@ -128,7 +125,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance if (!Frame.TakeStartLine(readableBuffer, out var consumed, out var examined)) { - ThrowInvalidRequestLine(); + ErrorUtilities.ThrowInvalidRequestLine(); } Pipe.Reader.Advance(consumed, examined); @@ -139,21 +136,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance if (!Frame.TakeMessageHeaders(readableBuffer, out consumed, out examined)) { - ThrowInvalidRequestHeaders(); + ErrorUtilities.ThrowInvalidRequestHeaders(); } Pipe.Reader.Advance(consumed, examined); } while (true); } - - public static void ThrowInvalidRequestLine() - { - throw new InvalidOperationException("Invalid request line"); - } - - public static void ThrowInvalidRequestHeaders() - { - throw new InvalidOperationException("Invalid request headers"); - } } } diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsingData.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsingData.cs index 45b585a2d0..5c496960bb 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsingData.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsingData.cs @@ -3,11 +3,9 @@ using System.Linq; using System.Text; -using BenchmarkDotNet.Attributes; namespace Microsoft.AspNetCore.Server.Kestrel.Performance { - [Config(typeof(CoreConfig))] public class RequestParsingData { public const int InnerLoopCount = 512; diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/ResponseHeaders.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/ResponseHeadersBenchmark.cs similarity index 99% rename from test/Microsoft.AspNetCore.Server.Kestrel.Performance/ResponseHeaders.cs rename to test/Microsoft.AspNetCore.Server.Kestrel.Performance/ResponseHeadersBenchmark.cs index a8dcf79468..b576735168 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/ResponseHeaders.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/ResponseHeadersBenchmark.cs @@ -13,7 +13,7 @@ using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; namespace Microsoft.AspNetCore.Server.Kestrel.Performance { [Config(typeof(CoreConfig))] - public class ResponseHeaders + public class ResponseHeadersBenchmark { private const int InnerLoopCount = 512; diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/columns/RpsColumn.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/columns/RpsColumn.cs deleted file mode 100644 index 9727e7110d..0000000000 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/columns/RpsColumn.cs +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using System.Linq; -using BenchmarkDotNet.Columns; -using BenchmarkDotNet.Reports; -using BenchmarkDotNet.Running; - -namespace Microsoft.AspNetCore.Server.Kestrel.Performance -{ - public class RpsColumn : IColumn - { - private static int NanosPerSecond = 1000 * 1000 * 1000; - - public string GetValue(Summary summary, Benchmark benchmark) - { - var totalNanos = summary.Reports.First(r => r.Benchmark == benchmark)?.ResultStatistics?.Mean ?? 0; - // Make sure we don't divide by zero!! - return Math.Abs(totalNanos) > 0.0 ? (NanosPerSecond / totalNanos).ToString("N2") : "N/A"; - } - - public bool IsDefault(Summary summary, Benchmark benchmark) => false; - public bool IsAvailable(Summary summary) => true; - public string Id => "RPS-Column"; - public string ColumnName => "RPS"; - public bool AlwaysShow => true; - public ColumnCategory Category => ColumnCategory.Custom; - public int PriorityInCategory => 1; - } -} diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/configs/CoreConfig.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/configs/CoreConfig.cs index 01f4c02318..49897ae207 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/configs/CoreConfig.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/configs/CoreConfig.cs @@ -1,6 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using BenchmarkDotNet.Columns; using BenchmarkDotNet.Configs; using BenchmarkDotNet.Diagnosers; using BenchmarkDotNet.Engines; @@ -15,7 +16,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance { Add(JitOptimizationsValidator.FailOnError); Add(MemoryDiagnoser.Default); - Add(new RpsColumn()); + Add(StatisticColumn.OperationsPerSecond); Add(Job.Default .With(BenchmarkDotNet.Environments.Runtime.Core) From b94912bcb12fbc9c27067fb9098a0abe744351d8 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Mon, 13 Mar 2017 22:32:28 +0000 Subject: [PATCH 1118/1662] InitializeHeaders only at start of parsing/Fix remaining (#1488) * Don't reinitialize header collection each loop * Correct remaining tracking value * Add tests --- .../Internal/Http/FrameOfT.cs | 4 +- .../Internal/Http/KestrelHttpParser.cs | 2 +- .../RequestHeaderLimitsTests.cs | 154 +++++++++++++++++- test/shared/TestServer.cs | 6 +- 4 files changed, 160 insertions(+), 6 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameOfT.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameOfT.cs index 0065f6b8cf..7af359cfc4 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameOfT.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameOfT.cs @@ -36,14 +36,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { ConnectionControl.SetTimeout(_keepAliveMilliseconds, TimeoutAction.CloseConnection); + InitializeHeaders(); + while (!_requestProcessingStopping) { var result = await Input.Reader.ReadAsync(); var examined = result.Buffer.End; var consumed = result.Buffer.End; - InitializeHeaders(); - try { ParseRequest(result.Buffer, out consumed, out examined); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/KestrelHttpParser.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/KestrelHttpParser.cs index 17c0ebbf30..71a49c2f45 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/KestrelHttpParser.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/KestrelHttpParser.cs @@ -194,7 +194,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http while (!reader.End) { var span = reader.Span; - var remaining = span.Length; + var remaining = span.Length - reader.Index; fixed (byte* pBuffer = &span.DangerousGetPinnableReference()) { diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestHeaderLimitsTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestHeaderLimitsTests.cs index 7ce1faf4bc..f7c1d8bc1a 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestHeaderLimitsTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestHeaderLimitsTests.cs @@ -1,11 +1,16 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Testing; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; using Xunit; +using Microsoft.Extensions.Primitives; +using System.Collections; +using System.Collections.Generic; namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { @@ -75,6 +80,108 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } } + [Theory] + [InlineData(1, 1)] + [InlineData(5, 5)] + [InlineData(100, 100)] + [InlineData(600, 100)] + [InlineData(700, 1)] + [InlineData(1, 700)] + public async Task ServerAcceptsHeadersAcrossSends(int header0Count, int header1Count) + { + var headers0 = MakeHeaders(header0Count); + var headers1 = MakeHeaders(header1Count, header0Count); + + using (var server = CreateServer(maxRequestHeaderCount: header0Count + header1Count)) + { + using (var connection = new TestConnection(server.Port)) + { + await connection.SendAll("GET / HTTP/1.1\r\n"); + // Wait for parsing to start + await WaitForCondition(TimeSpan.FromSeconds(1), () => server.Frame?.RequestHeaders != null); + + Assert.Equal(0, server.Frame.RequestHeaders.Count); + + await connection.SendAll(headers0); + // Wait for headers to be parsed + await WaitForCondition(TimeSpan.FromSeconds(1), () => server.Frame.RequestHeaders.Count >= header0Count); + + Assert.Equal(header0Count, server.Frame.RequestHeaders.Count); + + await connection.SendAll(headers1); + // Wait for headers to be parsed + await WaitForCondition(TimeSpan.FromSeconds(1), () => server.Frame.RequestHeaders.Count >= header0Count + header1Count); + + Assert.Equal(header0Count + header1Count, server.Frame.RequestHeaders.Count); + + await connection.SendAll("\r\n"); + await connection.ReceiveEnd( + "HTTP/1.1 200 OK", + $"Date: {server.Context.DateHeaderValue}", + "Transfer-Encoding: chunked", + "", + "c", + "hello, world", + "0", + "", + ""); + } + } + } + + [Theory] + [InlineData(1, 1)] + [InlineData(5, 5)] + public async Task ServerKeepsSameHeaderCollectionAcrossSends(int header0Count, int header1Count) + { + var headers0 = MakeHeaders(header0Count); + var headers1 = MakeHeaders(header0Count, header1Count); + + using (var server = CreateServer(maxRequestHeaderCount: header0Count + header1Count)) + { + using (var connection = new TestConnection(server.Port)) + { + await connection.SendAll("GET / HTTP/1.1\r\n"); + // Wait for parsing to start + await WaitForCondition(TimeSpan.FromSeconds(1), () => server.Frame?.RequestHeaders != null); + + Assert.Equal(0, server.Frame.RequestHeaders.Count); + + var newRequestHeaders = new RequestHeadersWrapper(server.Frame.RequestHeaders); + server.Frame.RequestHeaders = newRequestHeaders; + + Assert.Same(newRequestHeaders, server.Frame.RequestHeaders); + + await connection.SendAll(headers0); + // Wait for headers to be parsed + await WaitForCondition(TimeSpan.FromSeconds(1), () => server.Frame.RequestHeaders.Count >= header0Count); + + Assert.Same(newRequestHeaders, server.Frame.RequestHeaders); + Assert.Equal(header0Count, server.Frame.RequestHeaders.Count); + + await connection.SendAll(headers1); + // Wait for headers to be parsed + await WaitForCondition(TimeSpan.FromSeconds(1), () => server.Frame.RequestHeaders.Count >= header0Count + header1Count); + + Assert.Equal(header0Count + header1Count, server.Frame.RequestHeaders.Count); + + Assert.Same(newRequestHeaders, server.Frame.RequestHeaders); + + await connection.SendAll("\r\n"); + await connection.ReceiveEnd( + "HTTP/1.1 200 OK", + $"Date: {server.Context.DateHeaderValue}", + "Transfer-Encoding: chunked", + "", + "c", + "hello, world", + "0", + "", + ""); + } + } + } + [Theory] [InlineData(1)] [InlineData(5)] @@ -122,11 +229,26 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } } - private static string MakeHeaders(int count) + private static async Task WaitForCondition(TimeSpan timeout, Func condition) + { + const int MaxWaitLoop = 150; + + var delay = (int)Math.Ceiling(timeout.TotalMilliseconds / MaxWaitLoop); + + var waitLoop = 0; + while (waitLoop < MaxWaitLoop && !condition()) + { + // Wait for parsing condition to trigger + await Task.Delay(delay); + waitLoop++; + } + } + + private static string MakeHeaders(int count, int startAt = 0) { return string.Join("", Enumerable .Range(0, count) - .Select(i => $"Header-{i}: value{i}\r\n")); + .Select(i => $"Header-{startAt + i}: value{startAt + i}\r\n")); } private TestServer CreateServer(int? maxRequestHeaderCount = null, int? maxRequestHeadersTotalSize = null) @@ -148,5 +270,33 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests ServerOptions = options }); } + + private class RequestHeadersWrapper : IHeaderDictionary + { + IHeaderDictionary _innerHeaders; + + public RequestHeadersWrapper(IHeaderDictionary headers) + { + _innerHeaders = headers; + } + + public StringValues this[string key] { get => _innerHeaders[key]; set => _innerHeaders[key] = value; } + public long? ContentLength { get => _innerHeaders.ContentLength; set => _innerHeaders.ContentLength = value; } + public ICollection Keys => _innerHeaders.Keys; + public ICollection Values => _innerHeaders.Values; + public int Count => _innerHeaders.Count; + public bool IsReadOnly => _innerHeaders.IsReadOnly; + public void Add(string key, StringValues value) => _innerHeaders.Add(key, value); + public void Add(KeyValuePair item) => _innerHeaders.Add(item); + public void Clear() => _innerHeaders.Clear(); + public bool Contains(KeyValuePair item) => _innerHeaders.Contains(item); + public bool ContainsKey(string key) => _innerHeaders.ContainsKey(key); + public void CopyTo(KeyValuePair[] array, int arrayIndex) => _innerHeaders.CopyTo(array, arrayIndex); + public IEnumerator> GetEnumerator() => _innerHeaders.GetEnumerator(); + public bool Remove(string key) => _innerHeaders.Remove(key); + public bool Remove(KeyValuePair item) => _innerHeaders.Remove(item); + public bool TryGetValue(string key, out StringValues value) => _innerHeaders.TryGetValue(key, out value); + IEnumerator IEnumerable.GetEnumerator() => _innerHeaders.GetEnumerator(); + } } } \ No newline at end of file diff --git a/test/shared/TestServer.cs b/test/shared/TestServer.cs index 480e456bd2..95d5d81699 100644 --- a/test/shared/TestServer.cs +++ b/test/shared/TestServer.cs @@ -18,6 +18,7 @@ namespace Microsoft.AspNetCore.Testing private KestrelEngine _engine; private IDisposable _server; private ListenOptions _listenOptions; + private Frame _frame; public TestServer(RequestDelegate app) : this(app, new TestServiceContext()) @@ -46,7 +47,8 @@ namespace Microsoft.AspNetCore.Testing context.FrameFactory = connectionContext => { - return new Frame(new DummyApplication(app, httpContextFactory), connectionContext); + _frame = new Frame(new DummyApplication(app, httpContextFactory), connectionContext); + return _frame; }; try @@ -65,6 +67,8 @@ namespace Microsoft.AspNetCore.Testing public int Port => _listenOptions.IPEndPoint.Port; + public Frame Frame => _frame; + public TestServiceContext Context { get; } public TestConnection CreateConnection() From 5073d4fdaf29cf3827be9ae8d62969757aa5d8dc Mon Sep 17 00:00:00 2001 From: Nate McMaster Date: Tue, 14 Mar 2017 11:02:49 -0700 Subject: [PATCH 1119/1662] Re-add .NET Framework to tests and other cleanup (#1494) --- build/dependencies.props | 11 ++++++-- .../LargeResponseApp/LargeResponseApp.csproj | 3 -- samples/SampleApp/SampleApp.csproj | 5 +--- ...oft.AspNetCore.Server.Kestrel.Https.csproj | 2 +- ...Microsoft.AspNetCore.Server.Kestrel.csproj | 8 +++--- ...Core.Server.Kestrel.FunctionalTests.csproj | 28 ++++++++----------- ...pNetCore.Server.Kestrel.Performance.csproj | 2 +- .../FrameRequestStreamTests.cs | 2 +- .../FrameResponseStreamTests.cs | 2 +- ...soft.AspNetCore.Server.KestrelTests.csproj | 23 ++++++--------- .../NetworkingTests.cs | 6 ++-- .../xunit.runner.json | 4 +++ test/shared/TestResources.cs | 4 +-- tools/CodeGenerator/CodeGenerator.csproj | 4 +-- 14 files changed, 48 insertions(+), 56 deletions(-) create mode 100644 test/Microsoft.AspNetCore.Server.KestrelTests/xunit.runner.json diff --git a/build/dependencies.props b/build/dependencies.props index 3c441802d9..cc4fbc7fdc 100644 --- a/build/dependencies.props +++ b/build/dependencies.props @@ -1,9 +1,14 @@ - 1.6.1 + 1.2.0-* + 0.1.0-* + 0.1.0-* 4.3.0 1.9.1 - 0.1.0-* - 0.1.0-* + 9.0.1 + 4.7.1 + 1.6.1 + 15.0.0 + 2.2.0 diff --git a/samples/LargeResponseApp/LargeResponseApp.csproj b/samples/LargeResponseApp/LargeResponseApp.csproj index 3af02d73c5..9feeea1d07 100644 --- a/samples/LargeResponseApp/LargeResponseApp.csproj +++ b/samples/LargeResponseApp/LargeResponseApp.csproj @@ -4,9 +4,6 @@ net451;netcoreapp1.1 - Exe - - win7-x64 false diff --git a/samples/SampleApp/SampleApp.csproj b/samples/SampleApp/SampleApp.csproj index 5fcf04fb03..fa311e28dc 100644 --- a/samples/SampleApp/SampleApp.csproj +++ b/samples/SampleApp/SampleApp.csproj @@ -4,9 +4,6 @@ netcoreapp1.1;net451 - Exe - - win7-x64 false @@ -19,7 +16,7 @@ - + diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Https/Microsoft.AspNetCore.Server.Kestrel.Https.csproj b/src/Microsoft.AspNetCore.Server.Kestrel.Https/Microsoft.AspNetCore.Server.Kestrel.Https.csproj index a314782a45..5187bdb18d 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Https/Microsoft.AspNetCore.Server.Kestrel.Https.csproj +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Https/Microsoft.AspNetCore.Server.Kestrel.Https.csproj @@ -15,7 +15,7 @@ - + diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Microsoft.AspNetCore.Server.Kestrel.csproj b/src/Microsoft.AspNetCore.Server.Kestrel/Microsoft.AspNetCore.Server.Kestrel.csproj index beacc7f230..73ba4a6cd3 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Microsoft.AspNetCore.Server.Kestrel.csproj +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Microsoft.AspNetCore.Server.Kestrel.csproj @@ -13,9 +13,9 @@ - - - + + + @@ -28,4 +28,4 @@ - \ No newline at end of file + diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests.csproj b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests.csproj index fe6cbe0da0..9615b4a06d 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests.csproj +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests.csproj @@ -3,10 +3,9 @@ - netcoreapp1.1 + netcoreapp1.1;net46 netcoreapp1.1 - - win7-x64 + x64 @@ -19,19 +18,14 @@ - - - - - - - - - - - - - + + + + + + + + @@ -54,4 +48,4 @@ - \ No newline at end of file + diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Microsoft.AspNetCore.Server.Kestrel.Performance.csproj b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Microsoft.AspNetCore.Server.Kestrel.Performance.csproj index e010d7fce2..88b306a3d0 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Microsoft.AspNetCore.Server.Kestrel.Performance.csproj +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Microsoft.AspNetCore.Server.Kestrel.Performance.csproj @@ -24,7 +24,7 @@ - + diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameRequestStreamTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameRequestStreamTests.cs index ac5bc1b354..32f3e37d73 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameRequestStreamTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameRequestStreamTests.cs @@ -83,7 +83,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests await Assert.ThrowsAsync(() => stream.WriteAsync(new byte[1], 0, 1)); } -#if NET452 +#if NET46 [Fact] public void BeginWriteThrows() { diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameResponseStreamTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameResponseStreamTests.cs index 9c791b059d..b1f155ad52 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameResponseStreamTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameResponseStreamTests.cs @@ -54,7 +54,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests await Assert.ThrowsAsync(() => stream.ReadAsync(new byte[1], 0, 1)); } -#if NET452 +#if NET46 [Fact] public void BeginReadThrows() { diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/Microsoft.AspNetCore.Server.KestrelTests.csproj b/test/Microsoft.AspNetCore.Server.KestrelTests/Microsoft.AspNetCore.Server.KestrelTests.csproj index f0a9a37c51..382492d093 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/Microsoft.AspNetCore.Server.KestrelTests.csproj +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/Microsoft.AspNetCore.Server.KestrelTests.csproj @@ -3,14 +3,14 @@ - netcoreapp1.1 + netcoreapp1.1;net46 netcoreapp1.1 + x64 true - - win7-x64 + @@ -20,20 +20,15 @@ - - - - - - - - - - + + + + + - \ No newline at end of file + diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/NetworkingTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/NetworkingTests.cs index afa087f430..90e8fd6cdf 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/NetworkingTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/NetworkingTests.cs @@ -131,7 +131,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var t = Task.Run(async () => { var socket = TestConnection.CreateConnectedLoopbackSocket(port); -#if NET452 +#if NET46 await Task.Factory.FromAsync( socket.BeginSend, socket.EndSend, @@ -205,7 +205,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var t = Task.Run(async () => { var socket = TestConnection.CreateConnectedLoopbackSocket(port); -#if NET452 +#if NET46 await Task.Factory.FromAsync( socket.BeginSend, socket.EndSend, @@ -221,7 +221,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var buffer = new ArraySegment(new byte[2048]); while (true) { -#if NET452 +#if NET46 var count = await Task.Factory.FromAsync( socket.BeginReceive, socket.EndReceive, diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/xunit.runner.json b/test/Microsoft.AspNetCore.Server.KestrelTests/xunit.runner.json new file mode 100644 index 0000000000..bbd346e81c --- /dev/null +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/xunit.runner.json @@ -0,0 +1,4 @@ +{ + "$schema": "http://json.schemastore.org/xunit.runner.schema", + "appDomain": "denied" +} diff --git a/test/shared/TestResources.cs b/test/shared/TestResources.cs index 64a3161914..ff0b12b050 100644 --- a/test/shared/TestResources.cs +++ b/test/shared/TestResources.cs @@ -9,8 +9,8 @@ namespace Microsoft.AspNetCore.Testing public static class TestResources { private static readonly string _testCertificatePath = -#if NET452 - Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "testCert.pfx"); +#if NET46 + Path.Combine(Directory.GetCurrentDirectory(), "testCert.pfx"); #else Path.Combine(AppContext.BaseDirectory, "testCert.pfx"); #endif diff --git a/tools/CodeGenerator/CodeGenerator.csproj b/tools/CodeGenerator/CodeGenerator.csproj index d581f31921..ac31790238 100644 --- a/tools/CodeGenerator/CodeGenerator.csproj +++ b/tools/CodeGenerator/CodeGenerator.csproj @@ -9,8 +9,8 @@ - - + + From 64f84811bd6b10d63fdb859debea01c0ab529079 Mon Sep 17 00:00:00 2001 From: Nate McMaster Date: Tue, 14 Mar 2017 11:45:04 -0700 Subject: [PATCH 1120/1662] Fix incorrect debug asserts --- .../Internal/Http/Frame.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs index 1f0c0e2fac..a121986958 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs @@ -1272,8 +1272,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http Debug.Assert(RawTarget != null, "RawTarget was not set"); Debug.Assert(Method != null, "Method was not set"); Debug.Assert(Path != null, "Path was not set"); - Debug.Assert(QueryString != "QueryString was not set"); - Debug.Assert(HttpVersion != "HttpVersion was not set"); + Debug.Assert(QueryString != null, "QueryString was not set"); + Debug.Assert(HttpVersion != null, "HttpVersion was not set"); } private void OnOriginFormTarget(HttpMethod method, HttpVersion version, Span target, Span path, Span query, Span customMethod, bool pathEncoded) From 199329bed01dd8b6a0d027e5af6f1ad58f2dfc50 Mon Sep 17 00:00:00 2001 From: Nate McMaster Date: Tue, 14 Mar 2017 12:39:39 -0700 Subject: [PATCH 1121/1662] Update appveyor to VS 2017 --- .travis.yml | 1 - appveyor.yml | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index fb5fa0217a..a4f56d9d3a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -20,7 +20,6 @@ mono: none os: - linux - osx -osx_image: xcode7.3 branches: only: - master diff --git a/appveyor.yml b/appveyor.yml index d622af030a..30450f6367 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -12,4 +12,4 @@ build_script: clone_depth: 1 test: off deploy: off -os: Visual Studio 2017 RC +os: Visual Studio 2017 From d4c0d4b81ea916af6146663575a0c88412be64a2 Mon Sep 17 00:00:00 2001 From: Nate McMaster Date: Mon, 13 Mar 2017 14:58:07 -0700 Subject: [PATCH 1122/1662] Adds an EventSource named 'Microsoft-AspNetCore-Server-Kestrel' with the following event and properties: ConnectionStart: - connectionId - scheme - localEndPoint - remoteEndPoint ConnectionStop: - connectionId --- .../Internal/Http/Connection.cs | 3 + .../Internal/Http/SocketOutput.cs | 2 +- .../Infrastructure/KestrelEventSource.cs | 73 +++++++++++++++++ .../EventSourceTests.cs | 81 +++++++++++++++++++ .../KestrelEventSourceTests.cs | 30 +++++++ test/shared/TestConnection.cs | 27 +++++-- test/shared/TestServer.cs | 6 +- 7 files changed, 213 insertions(+), 9 deletions(-) create mode 100644 src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/KestrelEventSource.cs create mode 100644 test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/EventSourceTests.cs create mode 100644 test/Microsoft.AspNetCore.Server.KestrelTests/KestrelEventSourceTests.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Connection.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Connection.cs index 1de0607695..777d0b88dc 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Connection.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Connection.cs @@ -86,6 +86,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http public void Start() { Log.ConnectionStart(ConnectionId); + KestrelEventSource.Log.ConnectionStart(this); // Start socket prior to applying the ConnectionAdapter _socket.ReadStart(_allocCallback, _readCallback, this); @@ -137,6 +138,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http // Called on Libuv thread public virtual void OnSocketClosed() { + KestrelEventSource.Log.ConnectionStop(this); + _frame.FrameStartedTask.ContinueWith((task, state) => { var connection = (Connection)state; diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/SocketOutput.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/SocketOutput.cs index 52a3d5b1c5..148a7b7582 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/SocketOutput.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/SocketOutput.cs @@ -199,7 +199,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http ScheduleWrite(); } - // Return TaskCompletionSource's Task if set, otherwise completed Task + // Return TaskCompletionSource's Task if set, otherwise completed Task return tcs?.Task ?? TaskCache.CompletedTask; } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/KestrelEventSource.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/KestrelEventSource.cs new file mode 100644 index 0000000000..552b65ff33 --- /dev/null +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/KestrelEventSource.cs @@ -0,0 +1,73 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System.Diagnostics.Tracing; +using System.Runtime.CompilerServices; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; + +namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure +{ + [EventSource(Name = "Microsoft-AspNetCore-Server-Kestrel")] + public sealed class KestrelEventSource : EventSource + { + public static readonly KestrelEventSource Log = new KestrelEventSource(); + + private KestrelEventSource() + { + } + + // NOTE + // - The 'Start' and 'Stop' suffixes on the following event names have special meaning in EventSource. They + // enable creating 'activities'. + // For more information, take a look at the following blog post: + // https://blogs.msdn.microsoft.com/vancem/2015/09/14/exploring-eventsource-activity-correlation-and-causation-features/ + // - A stop event's event id must be next one after its start event. + // - Avoid renaming methods or parameters marked with EventAttribute. EventSource uses these to form the event object. + + [NonEvent] + public void ConnectionStart(Connection connection) + { + // avoid allocating strings unless this event source is enabled + if (IsEnabled()) + { + ConnectionStart( + connection.ConnectionId, + connection.ListenerContext.ListenOptions.Scheme, + connection.LocalEndPoint.ToString(), + connection.RemoteEndPoint.ToString()); + } + } + + [MethodImpl(MethodImplOptions.NoInlining)] + [Event(1, Level = EventLevel.Verbose)] + private void ConnectionStart(string connectionId, + string scheme, + string localEndPoint, + string remoteEndPoint) + { + WriteEvent( + 1, + connectionId, + scheme, + localEndPoint, + remoteEndPoint + ); + } + + [NonEvent] + public void ConnectionStop(Connection connection) + { + if (IsEnabled()) + { + ConnectionStop(connection.ConnectionId); + } + } + + [MethodImpl(MethodImplOptions.NoInlining)] + [Event(2, Level = EventLevel.Verbose)] + private void ConnectionStop(string connectionId) + { + WriteEvent(2, connectionId); + } + } +} diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/EventSourceTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/EventSourceTests.cs new file mode 100644 index 0000000000..e61447c87c --- /dev/null +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/EventSourceTests.cs @@ -0,0 +1,81 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Collections.Generic; +using System.Diagnostics.Tracing; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Http.Features; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; +using Microsoft.AspNetCore.Testing; +using Xunit; + +namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests +{ + public class EventSourceTests : IDisposable + { + private readonly TestEventListener _listener = new TestEventListener(); + + public EventSourceTests() + { + _listener.EnableEvents(KestrelEventSource.Log, EventLevel.Verbose); + } + + [Fact] + public async Task EmitsConnectionStartAndStop() + { + string connectionId = null; + int port; + using (var server = new TestServer(context => + { + connectionId = context.Features.Get().ConnectionId; + return Task.CompletedTask; + })) + { + port = server.Port; + using (var connection = server.CreateConnection()) + { + await connection.SendAll("GET / HTTP/1.1", + "", + "") + .TimeoutAfter(TimeSpan.FromSeconds(10)); + await connection.Receive("HTTP/1.1 200"); + } + } + + // capture list here as other tests executing in parallel may log events + Assert.NotNull(connectionId); + var events = _listener.EventData.Where(e => e != null && GetProperty(e, "connectionId") == connectionId).ToList(); + + var start = Assert.Single(events, e => e.EventName == "ConnectionStart"); + Assert.All(new[] { "connectionId", "scheme", "remoteEndPoint", "localEndPoint" }, p => Assert.Contains(p, start.PayloadNames)); + Assert.Equal("http", GetProperty(start, "scheme")); + Assert.Equal($"127.0.0.1:{port}", GetProperty(start, "localEndPoint")); + + var stop = Assert.Single(events, e => e.EventName == "ConnectionStop"); + Assert.All(new[] { "connectionId" }, p => Assert.Contains(p, start.PayloadNames)); + Assert.Same(KestrelEventSource.Log, start.EventSource); + } + + private string GetProperty(EventWrittenEventArgs data, string propName) + => data.Payload[data.PayloadNames.IndexOf(propName)] as string; + + private class TestEventListener : EventListener + { + private List _events = new List(); + + public IEnumerable EventData => _events; + + protected override void OnEventWritten(EventWrittenEventArgs eventData) + { + _events.Add(eventData); + } + } + + public void Dispose() + { + _listener.Dispose(); + } + } +} diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelEventSourceTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelEventSourceTests.cs new file mode 100644 index 0000000000..4661097172 --- /dev/null +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelEventSourceTests.cs @@ -0,0 +1,30 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Diagnostics.Tracing; +using System.Reflection; +using Microsoft.AspNetCore.Server.Kestrel; +using Xunit; + +namespace Microsoft.AspNetCore.Server.KestrelTests +{ + public class KestrelEventSourceTests + { + [Fact] + public void ExistsWithCorrectId() + { + var esType = typeof(KestrelServer).GetTypeInfo().Assembly.GetType( + "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.KestrelEventSource", + throwOnError: true, + ignoreCase: false + ); + + Assert.NotNull(esType); + + Assert.Equal("Microsoft-AspNetCore-Server-Kestrel", EventSource.GetName(esType)); + Assert.Equal(Guid.Parse("bdeb4676-a36e-5442-db99-4764e2326c7d"), EventSource.GetGuid(esType)); + Assert.NotEmpty(EventSource.GenerateManifest(esType, "assemblyPathToIncludeInManifest")); + } + } +} \ No newline at end of file diff --git a/test/shared/TestConnection.cs b/test/shared/TestConnection.cs index 13b9d67fa8..849962d378 100644 --- a/test/shared/TestConnection.cs +++ b/test/shared/TestConnection.cs @@ -23,13 +23,18 @@ namespace Microsoft.AspNetCore.Testing private StreamReader _reader; public TestConnection(int port) + : this(port, AddressFamily.InterNetwork) { - Create(port); } - public void Create(int port) + public TestConnection(int port, AddressFamily addressFamily) { - _socket = CreateConnectedLoopbackSocket(port); + Create(port, addressFamily); + } + + public void Create(int port, AddressFamily addressFamily) + { + _socket = CreateConnectedLoopbackSocket(port, addressFamily); _stream = new NetworkStream(_socket, false); _reader = new StreamReader(_stream, Encoding.ASCII); @@ -154,10 +159,20 @@ namespace Microsoft.AspNetCore.Testing } } - public static Socket CreateConnectedLoopbackSocket(int port) + public static Socket CreateConnectedLoopbackSocket(int port) => CreateConnectedLoopbackSocket(port, AddressFamily.InterNetwork); + + public static Socket CreateConnectedLoopbackSocket(int port, AddressFamily addressFamily) { - var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); - socket.Connect(new IPEndPoint(IPAddress.Loopback, port)); + if (addressFamily != AddressFamily.InterNetwork && addressFamily != AddressFamily.InterNetworkV6) + { + throw new ArgumentException($"TestConnection does not support address family of type {addressFamily}", nameof(addressFamily)); + } + + var socket = new Socket(addressFamily, SocketType.Stream, ProtocolType.Tcp); + var address = addressFamily == AddressFamily.InterNetworkV6 + ? IPAddress.IPv6Loopback + : IPAddress.Loopback; + socket.Connect(new IPEndPoint(address, port)); return socket; } } diff --git a/test/shared/TestServer.cs b/test/shared/TestServer.cs index 95d5d81699..ec0a8fbd12 100644 --- a/test/shared/TestServer.cs +++ b/test/shared/TestServer.cs @@ -3,6 +3,7 @@ using System; using System.Net; +using System.Net.Sockets; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Server.Kestrel; using Microsoft.AspNetCore.Server.Kestrel.Internal; @@ -66,6 +67,7 @@ namespace Microsoft.AspNetCore.Testing } public int Port => _listenOptions.IPEndPoint.Port; + public AddressFamily AddressFamily => _listenOptions.IPEndPoint.AddressFamily; public Frame Frame => _frame; @@ -73,7 +75,7 @@ namespace Microsoft.AspNetCore.Testing public TestConnection CreateConnection() { - return new TestConnection(Port); + return new TestConnection(Port, AddressFamily); } public void Dispose() @@ -82,4 +84,4 @@ namespace Microsoft.AspNetCore.Testing _engine.Dispose(); } } -} \ No newline at end of file +} From 632780dd16729298933f96796e6a969f3470d810 Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Sun, 12 Mar 2017 20:24:22 -0700 Subject: [PATCH 1123/1662] Remove splitting of path and path base (#1050). --- .../Internal/Http/Frame.cs | 55 +-------- .../KestrelServer.cs | 10 +- .../ListenOptions.cs | 11 +- .../ServerAddress.cs | 26 +---- .../PathBaseTests.cs | 104 ------------------ .../RequestTests.cs | 62 +++++++++++ .../RequestTargetProcessingTests.cs | 11 +- .../ServerAddressTests.cs | 30 +---- 8 files changed, 85 insertions(+), 224 deletions(-) delete mode 100644 test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/PathBaseTests.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs index a121986958..50fbf5a748 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs @@ -68,8 +68,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http protected HttpVersion _httpVersion; - private readonly string _pathBase; - private int _remainingRequestHeadersBytesAllowed; private int _requestHeadersParsed; @@ -88,7 +86,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http ServerOptions = context.ListenerContext.ServiceContext.ServerOptions; - _pathBase = context.ListenerContext.ListenOptions.PathBase; _parser = context.ListenerContext.ServiceContext.HttpParserFactory(this); FrameControl = this; @@ -1041,38 +1038,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http return result; } - private bool RequestUrlStartsWithPathBase(string requestUrl, out bool caseMatches) - { - caseMatches = true; - - if (string.IsNullOrEmpty(_pathBase)) - { - return false; - } - - if (requestUrl.Length < _pathBase.Length || (requestUrl.Length > _pathBase.Length && requestUrl[_pathBase.Length] != '/')) - { - return false; - } - - for (var i = 0; i < _pathBase.Length; i++) - { - if (requestUrl[i] != _pathBase[i]) - { - if (char.ToLowerInvariant(requestUrl[i]) == char.ToLowerInvariant(_pathBase[i])) - { - caseMatches = false; - } - else - { - return false; - } - } - } - - return true; - } - public bool TakeMessageHeaders(ReadableBuffer buffer, out ReadCursor consumed, out ReadCursor examined) { // Make sure the buffer is limited @@ -1321,7 +1286,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http QueryString = query.GetAsciiStringNonNullCharacters(); RawTarget = rawTarget; - SetNormalizedPath(requestUrlPath); + Path = PathNormalizer.RemoveDotSegments(requestUrlPath); } private void OnAuthorityFormTarget(HttpMethod method, Span target) @@ -1356,7 +1321,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http // See https://tools.ietf.org/html/rfc3986#section-3.2 RawTarget = target.GetAsciiStringNonNullCharacters(); Path = string.Empty; - PathBase = string.Empty; QueryString = string.Empty; } @@ -1371,7 +1335,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http RawTarget = Asterisk; Path = string.Empty; - PathBase = string.Empty; QueryString = string.Empty; } @@ -1397,25 +1360,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http RejectRequestTarget(target); } - SetNormalizedPath(uri.LocalPath); + Path = PathNormalizer.RemoveDotSegments(uri.LocalPath); // don't use uri.Query because we need the unescaped version QueryString = query.GetAsciiStringNonNullCharacters(); } - private void SetNormalizedPath(string requestPath) - { - var normalizedTarget = PathNormalizer.RemoveDotSegments(requestPath); - if (RequestUrlStartsWithPathBase(normalizedTarget, out bool caseMatches)) - { - PathBase = caseMatches ? _pathBase : normalizedTarget.Substring(0, _pathBase.Length); - Path = normalizedTarget.Substring(_pathBase.Length); - } - else - { - Path = normalizedTarget; - } - } - private unsafe static string GetUtf8String(Span path) { // .NET 451 doesn't have pointer overloads for Encoding.GetString so we diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServer.cs b/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServer.cs index a36da353f4..654544594b 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServer.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServer.cs @@ -7,6 +7,7 @@ using System.IO; using System.Linq; using System.Net; using System.Reflection; +using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting.Server; using Microsoft.AspNetCore.Hosting.Server.Features; @@ -163,12 +164,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel { var parsedAddress = ServerAddress.FromUrl(address); + if (!string.IsNullOrEmpty(parsedAddress.PathBase)) + { + _logger.LogWarning($"Path base in address {address} is not supported and will be ignored. To specify a path base, use {nameof(IApplicationBuilder)}.UsePathBase()."); + } + if (parsedAddress.IsUnixPipe) { listenOptions.Add(new ListenOptions(parsedAddress.UnixPipePath) { Scheme = parsedAddress.Scheme, - PathBase = parsedAddress.PathBase }); } else @@ -188,7 +193,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel listenOptions.Add(new ListenOptions(CreateIPEndPoint(parsedAddress)) { Scheme = parsedAddress.Scheme, - PathBase = parsedAddress.PathBase }); } } @@ -259,7 +263,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel var ipv4ListenOptions = new ListenOptions(new IPEndPoint(IPAddress.Loopback, parsedAddress.Port)) { Scheme = parsedAddress.Scheme, - PathBase = parsedAddress.PathBase }; _disposables.Push(engine.CreateServer(ipv4ListenOptions)); @@ -283,7 +286,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel var ipv6ListenOptions = new ListenOptions(new IPEndPoint(IPAddress.IPv6Loopback, parsedAddress.Port)) { Scheme = parsedAddress.Scheme, - PathBase = parsedAddress.PathBase }; _disposables.Push(engine.CreateServer(ipv6ListenOptions)); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/ListenOptions.cs b/src/Microsoft.AspNetCore.Server.Kestrel/ListenOptions.cs index f1a458776e..45ebe7917b 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/ListenOptions.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/ListenOptions.cs @@ -81,9 +81,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel /// public List ConnectionAdapters { get; } = new List(); - // PathBase and Scheme are hopefully only a temporary measure for back compat with IServerAddressesFeature. - // This allows a ListenOptions to describe all the information encoded in IWebHostBuilder.UseUrls. - internal string PathBase { get; set; } + // Scheme is hopefully only a temporary measure for back compat with IServerAddressesFeature. internal string Scheme { get; set; } = "http"; public override string ToString() @@ -93,12 +91,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel switch (Type) { case ListenType.IPEndPoint: - return $"{Scheme}://{IPEndPoint}{PathBase}"; + return $"{Scheme}://{IPEndPoint}"; case ListenType.SocketPath: - // ":" is used by ServerAddress to separate the socket path from PathBase. - return $"{Scheme}://unix:{SocketPath}:{PathBase}"; + return $"{Scheme}://unix:{SocketPath}"; case ListenType.FileHandle: - // This was never supported via --server.urls, so no need to include Scheme or PathBase. + // This was never supported via --server.urls, so no need to include Scheme. return "http://"; default: throw new InvalidOperationException(); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/ServerAddress.cs b/src/Microsoft.AspNetCore.Server.Kestrel/ServerAddress.cs index 5030e81993..7836c0658e 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/ServerAddress.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/ServerAddress.cs @@ -37,18 +37,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel { if (IsUnixPipe) { - if (string.IsNullOrEmpty(PathBase)) - { - return Scheme.ToLowerInvariant() + "://" + Host.ToLowerInvariant(); - } - else - { - return Scheme.ToLowerInvariant() + "://" + Host.ToLowerInvariant() + ":" + PathBase.ToLowerInvariant(); - } + return Scheme.ToLowerInvariant() + "://" + Host.ToLowerInvariant(); } else { - return Scheme.ToLowerInvariant() + "://" + Host.ToLowerInvariant() + ":" + Port.ToString(CultureInfo.InvariantCulture) + PathBase.ToLowerInvariant(); + return Scheme.ToLowerInvariant() + "://" + Host.ToLowerInvariant() + ":" + Port.ToString(CultureInfo.InvariantCulture); } } @@ -66,8 +59,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel } return string.Equals(Scheme, other.Scheme, StringComparison.OrdinalIgnoreCase) && string.Equals(Host, other.Host, StringComparison.OrdinalIgnoreCase) - && Port == other.Port - && string.Equals(PathBase, other.PathBase, StringComparison.OrdinalIgnoreCase); + && Port == other.Port; } public static ServerAddress FromUrl(string url) @@ -145,7 +137,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel throw new FormatException($"Invalid URL: {url}"); } - // Path should not end with a / since it will be used as PathBase later if (url[url.Length - 1] == '/') { serverAddress.PathBase = url.Substring(pathDelimiterEnd, url.Length - pathDelimiterEnd - 1); @@ -157,16 +148,5 @@ namespace Microsoft.AspNetCore.Server.Kestrel return serverAddress; } - - internal ServerAddress WithHost(string host) - { - return new ServerAddress - { - Scheme = Scheme, - Host = host, - Port = Port, - PathBase = PathBase - }; - } } } diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/PathBaseTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/PathBaseTests.cs deleted file mode 100644 index 8c0edb6e22..0000000000 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/PathBaseTests.cs +++ /dev/null @@ -1,104 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using System.Net.Http; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Builder; -using Microsoft.AspNetCore.Hosting; -using Microsoft.AspNetCore.Http; -using Newtonsoft.Json; -using Newtonsoft.Json.Linq; -using Xunit; - -namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests -{ - public class PathBaseTests - { - [Theory] - [InlineData("/base", "/base", "/base", "")] - [InlineData("/base", "/base/", "/base", "/")] - [InlineData("/base", "/base/something", "/base", "/something")] - [InlineData("/base", "/base/something/", "/base", "/something/")] - [InlineData("/base/more", "/base/more", "/base/more", "")] - [InlineData("/base/more", "/base/more/something", "/base/more", "/something")] - [InlineData("/base/more", "/base/more/something/", "/base/more", "/something/")] - public Task RequestPathBaseIsServerPathBase(string registerPathBase, string requestPath, string expectedPathBase, string expectedPath) - { - return TestPathBase(registerPathBase, requestPath, expectedPathBase, expectedPath); - } - - [Theory] - [InlineData("", "/", "", "/")] - [InlineData("", "/something", "", "/something")] - [InlineData("/", "/", "", "/")] - [InlineData("/base", "/", "", "/")] - [InlineData("/base", "/something", "", "/something")] - [InlineData("/base", "/baseandsomething", "", "/baseandsomething")] - [InlineData("/base", "/ba", "", "/ba")] - [InlineData("/base", "/ba/se", "", "/ba/se")] - public Task DefaultPathBaseIsEmpty(string registerPathBase, string requestPath, string expectedPathBase, string expectedPath) - { - return TestPathBase(registerPathBase, requestPath, expectedPathBase, expectedPath); - } - - [Theory] - [InlineData("", "/", "", "/")] - [InlineData("/", "/", "", "/")] - [InlineData("/base", "/base/", "/base", "/")] - [InlineData("/base/", "/base", "/base", "")] - [InlineData("/base/", "/base/", "/base", "/")] - public Task PathBaseNeverEndsWithSlash(string registerPathBase, string requestPath, string expectedPathBase, string expectedPath) - { - return TestPathBase(registerPathBase, requestPath, expectedPathBase, expectedPath); - } - - [Fact] - public Task PathBaseAndPathPreserveRequestCasing() - { - return TestPathBase("/base", "/Base/Something", "/Base", "/Something"); - } - - [Fact] - public Task PathBaseCanHaveUTF8Characters() - { - return TestPathBase("/b♫se", "/b♫se/something", "/b♫se", "/something"); - } - - private async Task TestPathBase(string registerPathBase, string requestPath, string expectedPathBase, string expectedPath) - { - var builder = new WebHostBuilder() - .UseKestrel() - .UseUrls($"http://127.0.0.1:0{registerPathBase}") - .Configure(app => - { - app.Run(async context => - { - await context.Response.WriteAsync(JsonConvert.SerializeObject(new - { - PathBase = context.Request.PathBase.Value, - Path = context.Request.Path.Value - })); - }); - }); - - using (var host = builder.Build()) - { - host.Start(); - - using (var client = new HttpClient()) - { - var response = await client.GetAsync($"http://127.0.0.1:{host.GetPort()}{requestPath}"); - response.EnsureSuccessStatusCode(); - - var responseText = await response.Content.ReadAsStringAsync(); - Assert.NotEmpty(responseText); - - var pathFacts = JsonConvert.DeserializeObject(responseText); - Assert.Equal(expectedPathBase, pathFacts["PathBase"].Value()); - Assert.Equal(expectedPath, pathFacts["Path"].Value()); - } - } - } - } -} diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs index 4e5afb14df..9a4ae90d6e 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs @@ -8,6 +8,7 @@ using System.IO; using System.Net; using System.Net.Http; using System.Net.Sockets; +using System.Reflection; using System.Text; using System.Threading; using System.Threading.Tasks; @@ -18,8 +19,11 @@ using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; using Microsoft.AspNetCore.Testing; using Microsoft.AspNetCore.Testing.xunit; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Internal; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Testing; +using Moq; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using Xunit; @@ -520,6 +524,64 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } } + [Theory] + [InlineData("/base", "/base")] + [InlineData("/base", "/base/")] + [InlineData("/base", "/base/something")] + [InlineData("/base", "/base/something/")] + [InlineData("/base/something", "/base/something")] + [InlineData("/base/something", "/base/something/")] + [InlineData("/base/something", "/base/something/more")] + [InlineData("/base/something", "/base/something/more/")] + public async Task DoesNotSplitPathBase(string registerPathBase, string requestPath) + { + var testLogger = new TestApplicationErrorLogger(); + + string contextPathBase = null; + string contextPath = null; + + var builder = new WebHostBuilder() + .UseKestrel() + .UseUrls($"http://127.0.0.1:0{registerPathBase}") + .ConfigureServices(services => + { + services.AddSingleton(new KestrelTestLoggerFactory(testLogger)); + }) + .Configure(app => + { + app.Run(context => + { + contextPathBase = context.Request.PathBase; + contextPath = context.Request.Path; + + return TaskCache.CompletedTask; + }); + }); + + using (var host = builder.Build()) + { + host.Start(); + + using (var connection = new TestConnection(host.GetPort())) + { + await connection.Send($"GET {requestPath} HTTP/1.1\r\n\r\n"); + await connection.Receive("HTTP/1.1 200 OK"); + } + + Assert.Single(testLogger.Messages, log => + log.LogLevel == LogLevel.Warning && + string.Equals( + $"Path base in address http://127.0.0.1:0{registerPathBase} is not supported and will be ignored. To specify a path base, use {nameof(IApplicationBuilder)}.UsePathBase().", + log.Message, + StringComparison.Ordinal)); + } + + Assert.Equal("", contextPathBase); + Assert.Equal(requestPath, contextPath); + + + } + private async Task TestRemoteIPAddress(string registerAddress, string requestAddress, string expectAddress) { var builder = new WebHostBuilder() diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/RequestTargetProcessingTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/RequestTargetProcessingTests.cs index 2da9a8144c..d60253405b 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/RequestTargetProcessingTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/RequestTargetProcessingTests.cs @@ -19,18 +19,13 @@ namespace Microsoft.AspNetCore.Server.KestrelTests public async Task RequestPathIsNotNormalized() { var testContext = new TestServiceContext(); - - var listenOptions = new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0)) - { - PathBase = "/\u0041\u030A" - }; + var listenOptions = new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0)); using (var server = new TestServer(async context => { - Assert.Equal("/\u0041\u030A", context.Request.PathBase.Value); - Assert.Equal("/B/\u0041\u030A", context.Request.Path.Value); + Assert.Equal("/\u0041\u030A/B/\u0041\u030A", context.Request.Path.Value); - context.Response.Headers["Content-Length"] = new[] { "11" }; + context.Response.Headers.ContentLength = 11; await context.Response.WriteAsync("Hello World"); }, testContext, listenOptions)) { diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/ServerAddressTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/ServerAddressTests.cs index c8920d384b..340ea1db27 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/ServerAddressTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/ServerAddressTests.cs @@ -2,7 +2,6 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.Text; using Microsoft.AspNetCore.Server.Kestrel; using Xunit; @@ -41,21 +40,21 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [InlineData("http://www.example.com", "http", "www.example.com", 80, "", "http://www.example.com:80")] [InlineData("https://www.example.com", "https", "www.example.com", 443, "", "https://www.example.com:443")] [InlineData("http://www.example.com/", "http", "www.example.com", 80, "", "http://www.example.com:80")] - [InlineData("http://www.example.com/foo?bar=baz", "http", "www.example.com", 80, "/foo?bar=baz", "http://www.example.com:80/foo?bar=baz")] + [InlineData("http://www.example.com/foo?bar=baz", "http", "www.example.com", 80, "/foo?bar=baz", "http://www.example.com:80")] [InlineData("http://www.example.com:5000", "http", "www.example.com", 5000, "", null)] [InlineData("https://www.example.com:5000", "https", "www.example.com", 5000, "", null)] [InlineData("http://www.example.com:5000/", "http", "www.example.com", 5000, "", "http://www.example.com:5000")] [InlineData("http://www.example.com:NOTAPORT", "http", "www.example.com:NOTAPORT", 80, "", "http://www.example.com:notaport:80")] [InlineData("https://www.example.com:NOTAPORT", "https", "www.example.com:NOTAPORT", 443, "", "https://www.example.com:notaport:443")] [InlineData("http://www.example.com:NOTAPORT/", "http", "www.example.com:NOTAPORT", 80, "", "http://www.example.com:notaport:80")] - [InlineData("http://foo:/tmp/kestrel-test.sock:5000/doesn't/matter", "http", "foo:", 80, "/tmp/kestrel-test.sock:5000/doesn't/matter", "http://foo::80/tmp/kestrel-test.sock:5000/doesn't/matter")] - [InlineData("http://unix:foo/tmp/kestrel-test.sock", "http", "unix:foo", 80, "/tmp/kestrel-test.sock", "http://unix:foo:80/tmp/kestrel-test.sock")] - [InlineData("http://unix:5000/tmp/kestrel-test.sock", "http", "unix", 5000, "/tmp/kestrel-test.sock", null)] + [InlineData("http://foo:/tmp/kestrel-test.sock:5000/doesn't/matter", "http", "foo:", 80, "/tmp/kestrel-test.sock:5000/doesn't/matter", "http://foo::80")] + [InlineData("http://unix:foo/tmp/kestrel-test.sock", "http", "unix:foo", 80, "/tmp/kestrel-test.sock", "http://unix:foo:80")] + [InlineData("http://unix:5000/tmp/kestrel-test.sock", "http", "unix", 5000, "/tmp/kestrel-test.sock", "http://unix:5000")] [InlineData("http://unix:/tmp/kestrel-test.sock", "http", "unix:/tmp/kestrel-test.sock", 0, "", null)] [InlineData("https://unix:/tmp/kestrel-test.sock", "https", "unix:/tmp/kestrel-test.sock", 0, "", null)] [InlineData("http://unix:/tmp/kestrel-test.sock:", "http", "unix:/tmp/kestrel-test.sock", 0, "", "http://unix:/tmp/kestrel-test.sock")] [InlineData("http://unix:/tmp/kestrel-test.sock:/", "http", "unix:/tmp/kestrel-test.sock", 0, "", "http://unix:/tmp/kestrel-test.sock")] - [InlineData("http://unix:/tmp/kestrel-test.sock:5000/doesn't/matter", "http", "unix:/tmp/kestrel-test.sock", 0, "5000/doesn't/matter", null)] + [InlineData("http://unix:/tmp/kestrel-test.sock:5000/doesn't/matter", "http", "unix:/tmp/kestrel-test.sock", 0, "5000/doesn't/matter", "http://unix:/tmp/kestrel-test.sock")] public void UrlsAreParsedCorrectly(string url, string scheme, string host, int port, string pathBase, string toString) { var serverAddress = ServerAddress.FromUrl(url); @@ -67,24 +66,5 @@ namespace Microsoft.AspNetCore.Server.KestrelTests Assert.Equal(toString ?? url, serverAddress.ToString()); } - - [Fact] - public void PathBaseIsNotNormalized() - { - var serverAddres = ServerAddress.FromUrl("http://localhost:8080/p\u0041\u030Athbase"); - - Assert.False(serverAddres.PathBase.IsNormalized(NormalizationForm.FormC)); - Assert.Equal("/p\u0041\u030Athbase", serverAddres.PathBase); - } - - [Fact] - public void WithHostReturnsNewInstanceWithDifferentHost() - { - var serverAddress = ServerAddress.FromUrl("http://localhost:8080"); - var newAddress = serverAddress.WithHost("otherhost"); - Assert.NotSame(serverAddress, newAddress); - Assert.Equal("otherhost", newAddress.Host); - Assert.Equal("localhost", serverAddress.Host); - } } } From 9a4a810aa83e3c4a439d59c2e3b8a66081157be3 Mon Sep 17 00:00:00 2001 From: Nate McMaster Date: Wed, 15 Mar 2017 10:26:09 -0700 Subject: [PATCH 1124/1662] Fix race conditions in test event listener --- .../EventSourceTests.cs | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/EventSourceTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/EventSourceTests.cs index e61447c87c..40610fe4c3 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/EventSourceTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/EventSourceTests.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Collections.Concurrent; using System.Collections.Generic; using System.Diagnostics.Tracing; using System.Linq; @@ -54,8 +55,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests Assert.Equal($"127.0.0.1:{port}", GetProperty(start, "localEndPoint")); var stop = Assert.Single(events, e => e.EventName == "ConnectionStop"); - Assert.All(new[] { "connectionId" }, p => Assert.Contains(p, start.PayloadNames)); - Assert.Same(KestrelEventSource.Log, start.EventSource); + Assert.All(new[] { "connectionId" }, p => Assert.Contains(p, stop.PayloadNames)); + Assert.Same(KestrelEventSource.Log, stop.EventSource); } private string GetProperty(EventWrittenEventArgs data, string propName) @@ -63,13 +64,23 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests private class TestEventListener : EventListener { - private List _events = new List(); + private volatile bool _disposed; + private ConcurrentBag _events = new ConcurrentBag(); public IEnumerable EventData => _events; protected override void OnEventWritten(EventWrittenEventArgs eventData) { - _events.Add(eventData); + if (!_disposed) + { + _events.Add(eventData); + } + } + + public override void Dispose() + { + _disposed = true; + base.Dispose(); } } From 2ef380457861702cb3d2e1140f702d80b9c1c092 Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Fri, 17 Mar 2017 14:42:13 -0700 Subject: [PATCH 1125/1662] Span-based RemoveDotSegments (#1448) --- .../Internal/Http/Frame.cs | 39 ++- .../Internal/Http/PathNormalizer.cs | 257 ++++++++++++------ .../DotSegmentRemovalBenchmark.cs | 60 ++++ .../FrameTests.cs | 27 +- .../PathNormalizerTests.cs | 62 +++-- test/shared/HttpParsingData.cs | 22 ++ 6 files changed, 341 insertions(+), 126 deletions(-) create mode 100644 test/Microsoft.AspNetCore.Server.Kestrel.Performance/DotSegmentRemovalBenchmark.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs index 50fbf5a748..d4f306d10d 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs @@ -1253,29 +1253,42 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http try { + // Read raw target before mutating memory. + rawTarget = target.GetAsciiStringNonNullCharacters(); + if (pathEncoded) { - // Read raw target before mutating memory. - rawTarget = target.GetAsciiStringNonNullCharacters(); + // URI was encoded, unescape and then parse as UTF-8 + var pathLength = UrlEncoder.Decode(path, path); + + // Removing dot segments must be done after unescaping. From RFC 3986: + // + // URI producing applications should percent-encode data octets that + // correspond to characters in the reserved set unless these characters + // are specifically allowed by the URI scheme to represent data in that + // component. If a reserved character is found in a URI component and + // no delimiting role is known for that character, then it must be + // interpreted as representing the data octet corresponding to that + // character's encoding in US-ASCII. + // + // https://tools.ietf.org/html/rfc3986#section-2.2 + pathLength = PathNormalizer.RemoveDotSegments(path.Slice(0, pathLength)); - // URI was encoded, unescape and then parse as utf8 - int pathLength = UrlEncoder.Decode(path, path); requestUrlPath = GetUtf8String(path.Slice(0, pathLength)); } else { - // URI wasn't encoded, parse as ASCII - requestUrlPath = path.GetAsciiStringNonNullCharacters(); + var pathLength = PathNormalizer.RemoveDotSegments(path); - if (query.Length == 0) + if (path.Length == pathLength && query.Length == 0) { - // No need to allocate an extra string if the path didn't need - // decoding and there's no query string following it. - rawTarget = requestUrlPath; + // If no decoding was required, no dot segments were removed and + // there is no query, the request path is the same as the raw target + requestUrlPath = rawTarget; } else { - rawTarget = target.GetAsciiStringNonNullCharacters(); + requestUrlPath = path.Slice(0, pathLength).GetAsciiStringNonNullCharacters(); } } } @@ -1286,7 +1299,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http QueryString = query.GetAsciiStringNonNullCharacters(); RawTarget = rawTarget; - Path = PathNormalizer.RemoveDotSegments(requestUrlPath); + Path = requestUrlPath; } private void OnAuthorityFormTarget(HttpMethod method, Span target) @@ -1360,7 +1373,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http RejectRequestTarget(target); } - Path = PathNormalizer.RemoveDotSegments(uri.LocalPath); + Path = uri.LocalPath; // don't use uri.Query because we need the unescaped version QueryString = query.GetAsciiStringNonNullCharacters(); } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/PathNormalizer.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/PathNormalizer.cs index 191eeb885e..99f49f287c 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/PathNormalizer.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/PathNormalizer.cs @@ -1,117 +1,204 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System.Buffers; +using System; +using System.Diagnostics; namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { public static class PathNormalizer { - public static string RemoveDotSegments(string path) + private const byte ByteSlash = (byte)'/'; + private const byte ByteDot = (byte)'.'; + + // In-place implementation of the algorithm from https://tools.ietf.org/html/rfc3986#section-5.2.4 + public static unsafe int RemoveDotSegments(Span input) { - if (ContainsDotSegments(path)) + fixed (byte* start = &input.DangerousGetPinnableReference()) { - var normalizedChars = ArrayPool.Shared.Rent(path.Length); - var normalizedIndex = normalizedChars.Length; - var pathIndex = path.Length - 1; - var skipSegments = 0; - - while (pathIndex >= 0) - { - if (pathIndex >= 2 && path[pathIndex] == '.' && path[pathIndex - 1] == '.' && path[pathIndex - 2] == '/') - { - if (normalizedIndex == normalizedChars.Length || normalizedChars[normalizedIndex] != '/') - { - normalizedChars[--normalizedIndex] = '/'; - } - - skipSegments++; - pathIndex -= 3; - } - else if (pathIndex >= 1 && path[pathIndex] == '.' && path[pathIndex - 1] == '/') - { - pathIndex -= 2; - } - else - { - while (pathIndex >= 0) - { - var lastChar = path[pathIndex]; - - if (skipSegments == 0) - { - normalizedChars[--normalizedIndex] = lastChar; - } - - pathIndex--; - - if (lastChar == '/') - { - break; - } - } - - if (skipSegments > 0) - { - skipSegments--; - } - } - } - - path = new string(normalizedChars, normalizedIndex, normalizedChars.Length - normalizedIndex); - ArrayPool.Shared.Return(normalizedChars); + var end = start + input.Length; + return RemoveDotSegments(start, end); } - - return path; } - private unsafe static bool ContainsDotSegments(string path) + public static unsafe int RemoveDotSegments(byte* start, byte* end) { - fixed (char* ptr = path) + if (!ContainsDotSegments(start, end)) { - char* end = ptr + path.Length; + return (int)(end - start); + } - for (char* p = ptr; p < end; p++) + var src = start; + var dst = start; + + while (src < end) + { + var ch1 = *src; + Debug.Assert(ch1 == '/', "Path segment must always start with a '/'"); + + byte ch2, ch3, ch4; + + switch (end - src) { - if (*p == '/') - { - p++; - } + case 1: + break; + case 2: + ch2 = *(src + 1); - if (p == end) - { - return false; - } - - if (*p == '.') - { - p++; - - if (p == end) + if (ch2 == ByteDot) { - return true; + // B. if the input buffer begins with a prefix of "/./" or "/.", + // where "." is a complete path segment, then replace that + // prefix with "/" in the input buffer; otherwise, + src += 1; + *src = ByteSlash; + continue; } - if (*p == '.') - { - p++; + break; + case 3: + ch2 = *(src + 1); + ch3 = *(src + 2); - if (p == end) + if (ch2 == ByteDot && ch3 == ByteDot) + { + // C. if the input buffer begins with a prefix of "/../" or "/..", + // where ".." is a complete path segment, then replace that + // prefix with "/" in the input buffer and remove the last + // segment and its preceding "/" (if any) from the output + // buffer; otherwise, + src += 2; + *src = ByteSlash; + + if (dst > start) { - return true; + do + { + dst--; + } while (dst > start && *dst != ByteSlash); } - if (*p == '/') - { - return true; - } + continue; } - else if (*p == '/') + else if (ch2 == ByteDot && ch3 == ByteSlash) { - return true; + // B. if the input buffer begins with a prefix of "/./" or "/.", + // where "." is a complete path segment, then replace that + // prefix with "/" in the input buffer; otherwise, + src += 2; + continue; } - } + + break; + default: + ch2 = *(src + 1); + ch3 = *(src + 2); + ch4 = *(src + 3); + + if (ch2 == ByteDot && ch3 == ByteDot && ch4 == ByteSlash) + { + // C. if the input buffer begins with a prefix of "/../" or "/..", + // where ".." is a complete path segment, then replace that + // prefix with "/" in the input buffer and remove the last + // segment and its preceding "/" (if any) from the output + // buffer; otherwise, + src += 3; + + if (dst > start) + { + do + { + dst--; + } while (dst > start && *dst != ByteSlash); + } + + continue; + } + else if (ch2 == ByteDot && ch3 == ByteSlash) + { + // B. if the input buffer begins with a prefix of "/./" or "/.", + // where "." is a complete path segment, then replace that + // prefix with "/" in the input buffer; otherwise, + src += 2; + continue; + } + + break; } + + // E. move the first path segment in the input buffer to the end of + // the output buffer, including the initial "/" character (if + // any) and any subsequent characters up to, but not including, + // the next "/" character or the end of the input buffer. + do + { + *dst++ = ch1; + ch1 = *++src; + } while (src < end && ch1 != ByteSlash); + } + + if (dst == start) + { + *dst++ = ByteSlash; + } + + return (int)(dst - start); + } + + public static unsafe bool ContainsDotSegments(byte* start, byte* end) + { + var src = start; + var dst = start; + + while (src < end) + { + var ch1 = *src; + Debug.Assert(ch1 == '/', "Path segment must always start with a '/'"); + + byte ch2, ch3, ch4; + + switch (end - src) + { + case 1: + break; + case 2: + ch2 = *(src + 1); + + if (ch2 == ByteDot) + { + return true; + } + + break; + case 3: + ch2 = *(src + 1); + ch3 = *(src + 2); + + if ((ch2 == ByteDot && ch3 == ByteDot) || + (ch2 == ByteDot && ch3 == ByteSlash)) + { + return true; + } + + break; + default: + ch2 = *(src + 1); + ch3 = *(src + 2); + ch4 = *(src + 3); + + if ((ch2 == ByteDot && ch3 == ByteDot && ch4 == ByteSlash) || + (ch2 == ByteDot && ch3 == ByteSlash)) + { + return true; + } + + break; + } + + do + { + ch1 = *++src; + } while (src < end && ch1 != ByteSlash); } return false; diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/DotSegmentRemovalBenchmark.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/DotSegmentRemovalBenchmark.cs new file mode 100644 index 0000000000..64482a568c --- /dev/null +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/DotSegmentRemovalBenchmark.cs @@ -0,0 +1,60 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Text; +using BenchmarkDotNet.Attributes; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; + +namespace Microsoft.AspNetCore.Server.Kestrel.Performance +{ + [Config(typeof(CoreConfig))] + public class DotSegmentRemovalBenchmark + { + // Immutable + private const string _noDotSegments = "/long/request/target/for/benchmarking/what/else/can/we/put/here"; + private const string _singleDotSegments = "/long/./request/./target/./for/./benchmarking/./what/./else/./can/./we/./put/./here"; + private const string _doubleDotSegments = "/long/../request/../target/../for/../benchmarking/../what/../else/../can/../we/../put/../here"; + + private readonly byte[] _noDotSegmentsAscii = Encoding.ASCII.GetBytes(_noDotSegments); + private readonly byte[] _singleDotSegmentsAscii = Encoding.ASCII.GetBytes(_singleDotSegments); + private readonly byte[] _doubleDotSegmentsAscii = Encoding.ASCII.GetBytes(_doubleDotSegments); + + private readonly byte[] _noDotSegmentsBytes = new byte[_noDotSegments.Length]; + private readonly byte[] _singleDotSegmentsBytes = new byte[_singleDotSegments.Length]; + private readonly byte[] _doubleDotSegmentsBytes = new byte[_doubleDotSegments.Length]; + + [Benchmark(Baseline = true)] + public unsafe int NoDotSegments() + { + _noDotSegmentsAscii.CopyTo(_noDotSegmentsBytes); + + fixed (byte* start = _noDotSegmentsBytes) + { + return PathNormalizer.RemoveDotSegments(start, start + _noDotSegments.Length); + } + } + + [Benchmark] + public unsafe int SingleDotSegments() + { + _singleDotSegmentsAscii.CopyTo(_singleDotSegmentsBytes); + + fixed (byte* start = _singleDotSegmentsBytes) + { + return PathNormalizer.RemoveDotSegments(start, start + _singleDotSegments.Length); + } + } + + [Benchmark] + public unsafe int DoubleDotSegments() + { + _doubleDotSegmentsAscii.CopyTo(_doubleDotSegmentsBytes); + + fixed (byte* start = _doubleDotSegmentsBytes) + { + return PathNormalizer.RemoveDotSegments(start, start + _doubleDotSegments.Length); + } + } + } +} diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs index 7c8fd7bc62..a87cd5e8a8 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs @@ -246,7 +246,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } [Theory] - [MemberData(nameof(ValidRequestLineData))] + [MemberData(nameof(RequestLineValidData))] public async Task TakeStartLineSetsFrameProperties( string requestLine, string expectedMethod, @@ -271,6 +271,27 @@ namespace Microsoft.AspNetCore.Server.KestrelTests Assert.Equal(expectedHttpVersion, _frame.HttpVersion); } + [Theory] + [MemberData(nameof(RequestLineDotSegmentData))] + public async Task TakeStartLineRemovesDotSegmentsFromTarget( + string requestLine, + string expectedRawTarget, + string expectedDecodedPath, + string expectedQueryString) + { + var requestLineBytes = Encoding.ASCII.GetBytes(requestLine); + await _input.Writer.WriteAsync(requestLineBytes); + var readableBuffer = (await _input.Reader.ReadAsync()).Buffer; + + var returnValue = _frame.TakeStartLine(readableBuffer, out _consumed, out _examined); + _input.Reader.Advance(_consumed, _examined); + + Assert.True(returnValue); + Assert.Equal(expectedRawTarget, _frame.RawTarget); + Assert.Equal(expectedDecodedPath, _frame.Path); + Assert.Equal(expectedQueryString, _frame.QueryString); + } + [Fact] public async Task ParseRequestStartsRequestHeadersTimeoutOnFirstByteAvailable() { @@ -595,7 +616,9 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } } - public static IEnumerable ValidRequestLineData => HttpParsingData.RequestLineValidData; + public static IEnumerable RequestLineValidData => HttpParsingData.RequestLineValidData; + + public static IEnumerable RequestLineDotSegmentData => HttpParsingData.RequestLineDotSegmentData; public static TheoryData TargetWithEncodedNullCharData { diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/PathNormalizerTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/PathNormalizerTests.cs index 92c0b3f688..d9b4cb6441 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/PathNormalizerTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/PathNormalizerTests.cs @@ -15,41 +15,51 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [InlineData("/a/", "/a/")] [InlineData("/a/b", "/a/b")] [InlineData("/a/b/", "/a/b/")] - [InlineData("/a", "/./a")] - [InlineData("/a", "/././a")] - [InlineData("/a", "/../a")] - [InlineData("/a", "/../../a")] - [InlineData("/a/b", "/a/./b")] - [InlineData("/b", "/a/../b")] - [InlineData("/a/", "/a/./")] - [InlineData("/a", "/a/.")] - [InlineData("/", "/a/../b/../")] - [InlineData("/", "/a/../b/..")] - [InlineData("/b", "/a/../../b")] - [InlineData("/b/", "/a/../../b/")] - [InlineData("/b", "/a/.././../b")] - [InlineData("/b/", "/a/.././../b/")] - [InlineData("/a/d", "/a/b/c/./../../d")] - [InlineData("/a/d", "/./a/b/c/./../../d")] - [InlineData("/a/d", "/../a/b/c/./../../d")] - [InlineData("/a/d", "/./../a/b/c/./../../d")] - [InlineData("/a/d", "/.././a/b/c/./../../d")] + [InlineData("/./a", "/a")] + [InlineData("/././a", "/a")] + [InlineData("/../a", "/a")] + [InlineData("/../../a", "/a")] + [InlineData("/a/./b", "/a/b")] + [InlineData("/a/../b", "/b")] + [InlineData("/a/./", "/a/")] + [InlineData("/a/.", "/a/")] + [InlineData("/a/../", "/")] + [InlineData("/a/..", "/")] + [InlineData("/a/../b/../", "/")] + [InlineData("/a/../b/..", "/")] + [InlineData("/a/../../b", "/b")] + [InlineData("/a/../../b/", "/b/")] + [InlineData("/a/.././../b", "/b")] + [InlineData("/a/.././../b/", "/b/")] + [InlineData("/a/b/c/./../../d", "/a/d")] + [InlineData("/./a/b/c/./../../d", "/a/d")] + [InlineData("/../a/b/c/./../../d", "/a/d")] + [InlineData("/./../a/b/c/./../../d", "/a/d")] + [InlineData("/.././a/b/c/./../../d", "/a/d")] [InlineData("/.a", "/.a")] [InlineData("/..a", "/..a")] [InlineData("/...", "/...")] [InlineData("/a/.../b", "/a/.../b")] - [InlineData("/b", "/a/../.../../b")] + [InlineData("/a/../.../../b", "/b")] [InlineData("/a/.b", "/a/.b")] [InlineData("/a/..b", "/a/..b")] [InlineData("/a/b.", "/a/b.")] [InlineData("/a/b..", "/a/b..")] - [InlineData("a/b", "a/b")] - [InlineData("a/c", "a/b/../c")] - [InlineData("*", "*")] - public void RemovesDotSegments(string expected, string input) + [InlineData("/longlong/../short", "/short")] + [InlineData("/short/../longlong", "/longlong")] + [InlineData("/longlong/../short/..", "/")] + [InlineData("/short/../longlong/..", "/")] + [InlineData("/longlong/../short/../", "/")] + [InlineData("/short/../longlong/../", "/")] + [InlineData("/", "/")] + [InlineData("/no/segments", "/no/segments")] + [InlineData("/no/segments/", "/no/segments/")] + public void RemovesDotSegments(string input, string expected) { - var result = PathNormalizer.RemoveDotSegments(input); - Assert.Equal(expected, result); + var data = Encoding.ASCII.GetBytes(input); + var length = PathNormalizer.RemoveDotSegments(new Span(data)); + Assert.True(length >= 1); + Assert.Equal(expected, Encoding.ASCII.GetString(data, 0, length)); } } } diff --git a/test/shared/HttpParsingData.cs b/test/shared/HttpParsingData.cs index f3bd39fcbe..1af1a2da1e 100644 --- a/test/shared/HttpParsingData.cs +++ b/test/shared/HttpParsingData.cs @@ -93,6 +93,28 @@ namespace Microsoft.AspNetCore.Testing } } + public static IEnumerable RequestLineDotSegmentData => new[] + { + new[] { "GET /a/../b HTTP/1.1\r\n", "/a/../b", "/b", "" }, + new[] { "GET /%61/../%62 HTTP/1.1\r\n", "/%61/../%62", "/b", "" }, + new[] { "GET /a/%2E%2E/b HTTP/1.1\r\n", "/a/%2E%2E/b", "/b", "" }, + new[] { "GET /%61/%2E%2E/%62 HTTP/1.1\r\n", "/%61/%2E%2E/%62", "/b", "" }, + new[] { "GET /a?p=/a/../b HTTP/1.1\r\n", "/a?p=/a/../b", "/a", "?p=/a/../b" }, + new[] { "GET /a?p=/a/%2E%2E/b HTTP/1.1\r\n", "/a?p=/a/%2E%2E/b", "/a", "?p=/a/%2E%2E/b" }, + new[] { "GET http://example.com/a/../b HTTP/1.1\r\n", "http://example.com/a/../b", "/b", "" }, + new[] { "GET http://example.com/%61/../%62 HTTP/1.1\r\n", "http://example.com/%61/../%62", "/b", "" }, + new[] { "GET http://example.com/a/%2E%2E/b HTTP/1.1\r\n", "http://example.com/a/%2E%2E/b", "/b", "" }, + new[] { "GET http://example.com/%61/%2E%2E/%62 HTTP/1.1\r\n", "http://example.com/%61/%2E%2E/%62", "/b", "" }, + new[] { "GET http://example.com/a?p=/a/../b HTTP/1.1\r\n", "http://example.com/a?p=/a/../b", "/a", "?p=/a/../b" }, + new[] { "GET http://example.com/a?p=/a/%2E%2E/b HTTP/1.1\r\n", "http://example.com/a?p=/a/%2E%2E/b", "/a", "?p=/a/%2E%2E/b" }, + new[] { "GET http://example.com?p=/a/../b HTTP/1.1\r\n", "http://example.com?p=/a/../b", "/", "?p=/a/../b" }, + new[] { "GET http://example.com?p=/a/%2E%2E/b HTTP/1.1\r\n", "http://example.com?p=/a/%2E%2E/b", "/", "?p=/a/%2E%2E/b" }, + + // Asterisk-form and authority-form should be unaffected and cause no issues + new[] { "OPTIONS * HTTP/1.1\r\n", "*", "", "" }, + new[] { "CONNECT www.example.com HTTP/1.1\r\n", "www.example.com", "", "" }, + }; + public static IEnumerable RequestLineIncompleteData => new[] { "G", From 07cbf7faa95034639ff42df2f2057974dcf8a055 Mon Sep 17 00:00:00 2001 From: Pavel Krymets Date: Fri, 10 Mar 2017 13:48:07 -0800 Subject: [PATCH 1126/1662] Use pipelines for SocketOutput - Changed socket output to be based on pipelines - Changed connection filter glue to be based on pipelines - Codegen that used `MemoryPoolIterator` for output now uses `WritableBuffer` - Made `UvWriteReq` async/await friendly with `LibuvAwaitable` - Deleted MemoryPool and friends --- KestrelHttpServer.sln | 2 +- build/dependencies.props | 4 +- .../Adapter/Internal/AdaptedPipeline.cs | 38 +- .../Adapter/Internal/StreamSocketOutput.cs | 166 ++-- .../Internal/Http/ChunkWriter.cs | 9 +- .../Internal/Http/Connection.cs | 11 +- .../Internal/Http/Frame.cs | 10 +- .../Internal/Http/FrameHeaders.Generated.cs | 155 ++-- .../Internal/Http/FrameResponseHeaders.cs | 11 +- .../Internal/Http/ISocketOutput.cs | 18 +- .../Internal/Http/ListenerContext.cs | 23 +- .../Internal/Http/ListenerSecondary.cs | 30 +- .../Internal/Http/PipelineExtensions.cs | 17 + .../Internal/Http/SocketOutput.cs | 810 ++++-------------- .../Internal/Infrastructure/KestrelThread.cs | 1 - .../Internal/Infrastructure/LibuvAwaitable.cs | 77 ++ .../Internal/Infrastructure/MemoryPool.cs | 214 ----- .../Infrastructure/MemoryPoolBlock.cs | 139 --- .../Infrastructure/MemoryPoolIterator.cs | 463 ---------- .../Internal/Infrastructure/MemoryPoolSlab.cs | 96 --- .../Internal/Networking/UvWriteReq.cs | 58 +- .../ResponseTests.cs | 17 +- .../ResponseHeadersBenchmark.cs | 37 +- .../ChunkedRequestTests.cs | 1 - .../MemoryPoolBlockTests.cs | 133 --- .../MemoryPoolExtensions.cs | 16 - .../MemoryPoolIteratorTests.cs | 406 --------- .../MultipleLoopTests.cs | 32 +- .../NetworkingTests.cs | 25 +- .../SocketOutputTests.cs | 526 ++++-------- .../StreamSocketOutputTests.cs | 13 +- .../TestInput.cs | 1 - test/shared/MockSocketOutput.cs | 16 +- test/shared/TestConnection.cs | 8 +- tools/CodeGenerator/KnownHeaders.cs | 13 +- 35 files changed, 753 insertions(+), 2843 deletions(-) create mode 100644 src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/LibuvAwaitable.cs delete mode 100644 src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPool.cs delete mode 100644 src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolBlock.cs delete mode 100644 src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolIterator.cs delete mode 100644 src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolSlab.cs delete mode 100644 test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolBlockTests.cs delete mode 100644 test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolExtensions.cs delete mode 100644 test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolIteratorTests.cs diff --git a/KestrelHttpServer.sln b/KestrelHttpServer.sln index 48cd152ee9..1df13131ef 100644 --- a/KestrelHttpServer.sln +++ b/KestrelHttpServer.sln @@ -1,6 +1,6 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 15 -VisualStudioVersion = 15.0.26228.0 +VisualStudioVersion = 15.0.26228.4 MinimumVisualStudioVersion = 10.0.40219.1 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{7972A5D6-3385-4127-9277-428506DD44FF}" ProjectSection(SolutionItems) = preProject diff --git a/build/dependencies.props b/build/dependencies.props index cc4fbc7fdc..74d0c3c23b 100644 --- a/build/dependencies.props +++ b/build/dependencies.props @@ -1,8 +1,8 @@ 1.2.0-* - 0.1.0-* - 0.1.0-* + 0.1.0-e170313-1 + 0.1.0-e170313-1 4.3.0 1.9.1 9.0.1 diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Adapter/Internal/AdaptedPipeline.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Adapter/Internal/AdaptedPipeline.cs index 498357c52d..cfd2c7d1f1 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Adapter/Internal/AdaptedPipeline.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Adapter/Internal/AdaptedPipeline.cs @@ -6,8 +6,6 @@ using System.IO; using System.IO.Pipelines; using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; -using MemoryPool = Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPool; namespace Microsoft.AspNetCore.Server.Kestrel.Adapter.Internal { @@ -16,30 +14,50 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Adapter.Internal private const int MinAllocBufferSize = 2048; private readonly Stream _filteredStream; + private readonly StreamSocketOutput _output; public AdaptedPipeline( - string connectionId, Stream filteredStream, - IPipe pipe, - MemoryPool memory, - IKestrelTrace logger) + IPipe inputPipe, + IPipe outputPipe) { - Input = pipe; - Output = new StreamSocketOutput(connectionId, filteredStream, memory, logger); + Input = inputPipe; + _output = new StreamSocketOutput(filteredStream, outputPipe); _filteredStream = filteredStream; } public IPipe Input { get; } - public ISocketOutput Output { get; } + public ISocketOutput Output => _output; public void Dispose() { Input.Writer.Complete(); } - public async Task ReadInputAsync() + public async Task StartAsync() + { + var inputTask = ReadInputAsync(); + var outputTask = _output.WriteOutputAsync(); + + var result = await Task.WhenAny(inputTask, outputTask); + + if (result == inputTask) + { + // Close output + _output.Dispose(); + } + else + { + // Close input + Input.Writer.Complete(); + } + + await Task.WhenAll(inputTask, outputTask); + } + + private async Task ReadInputAsync() { int bytesRead; diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Adapter/Internal/StreamSocketOutput.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Adapter/Internal/StreamSocketOutput.cs index a5fd6c24a0..0e17b99ae1 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Adapter/Internal/StreamSocketOutput.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Adapter/Internal/StreamSocketOutput.cs @@ -3,124 +3,130 @@ using System; using System.IO; -using System.Text; +using System.IO.Pipelines; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; namespace Microsoft.AspNetCore.Server.Kestrel.Adapter.Internal { public class StreamSocketOutput : ISocketOutput { - private static readonly byte[] _endChunkBytes = Encoding.ASCII.GetBytes("\r\n"); - private static readonly byte[] _nullBuffer = new byte[0]; + private static readonly ArraySegment _nullBuffer = new ArraySegment(new byte[0]); - private readonly string _connectionId; private readonly Stream _outputStream; - private readonly MemoryPool _memory; - private readonly IKestrelTrace _logger; - private MemoryPoolBlock _producingBlock; + private readonly IPipe _pipe; + private object _sync = new object(); + private bool _completed; - private bool _canWrite = true; - - public StreamSocketOutput(string connectionId, Stream outputStream, MemoryPool memory, IKestrelTrace logger) + public StreamSocketOutput(Stream outputStream, IPipe pipe) { - _connectionId = connectionId; _outputStream = outputStream; - _memory = memory; - _logger = logger; + _pipe = pipe; } public void Write(ArraySegment buffer, bool chunk) { - if (chunk && buffer.Array != null) - { - var beginChunkBytes = ChunkWriter.BeginChunkBytes(buffer.Count); - _outputStream.Write(beginChunkBytes.Array, beginChunkBytes.Offset, beginChunkBytes.Count); - } - - _outputStream.Write(buffer.Array ?? _nullBuffer, buffer.Offset, buffer.Count); - - if (chunk && buffer.Array != null) - { - _outputStream.Write(_endChunkBytes, 0, _endChunkBytes.Length); - } + WriteAsync(buffer, chunk, default(CancellationToken)).GetAwaiter().GetResult(); } - public Task WriteAsync(ArraySegment buffer, bool chunk, CancellationToken cancellationToken) + public async Task WriteAsync(ArraySegment buffer, bool chunk, CancellationToken cancellationToken) { - if (chunk && buffer.Array != null) + var flushAwaiter = default(WritableBufferAwaitable); + + lock (_sync) { - return WriteAsyncChunked(buffer, cancellationToken); - } - - return _outputStream.WriteAsync(buffer.Array ?? _nullBuffer, buffer.Offset, buffer.Count, cancellationToken); - } - - private async Task WriteAsyncChunked(ArraySegment buffer, CancellationToken cancellationToken) - { - var beginChunkBytes = ChunkWriter.BeginChunkBytes(buffer.Count); - - await _outputStream.WriteAsync(beginChunkBytes.Array, beginChunkBytes.Offset, beginChunkBytes.Count, cancellationToken); - await _outputStream.WriteAsync(buffer.Array, buffer.Offset, buffer.Count, cancellationToken); - await _outputStream.WriteAsync(_endChunkBytes, 0, _endChunkBytes.Length, cancellationToken); - } - - public MemoryPoolIterator ProducingStart() - { - _producingBlock = _memory.Lease(); - return new MemoryPoolIterator(_producingBlock); - } - - public void ProducingComplete(MemoryPoolIterator end) - { - var block = _producingBlock; - while (block != end.Block) - { - // If we don't handle an exception from _outputStream.Write() here, we'll leak memory blocks. - if (_canWrite) + if (_completed) { - try + return; + } + + var writableBuffer = _pipe.Writer.Alloc(); + + if (buffer.Count > 0) + { + if (chunk) { - _outputStream.Write(block.Data.Array, block.Data.Offset, block.Data.Count); + ChunkWriter.WriteBeginChunkBytes(ref writableBuffer, buffer.Count); + writableBuffer.Write(buffer); + ChunkWriter.WriteEndChunkBytes(ref writableBuffer); } - catch (Exception ex) + else { - _canWrite = false; - _logger.ConnectionError(_connectionId, ex); + writableBuffer.Write(buffer); } } - var returnBlock = block; - block = block.Next; - returnBlock.Pool.Return(returnBlock); - } - - if (_canWrite) - { - try - { - _outputStream.Write(end.Block.Array, end.Block.Data.Offset, end.Index - end.Block.Data.Offset); - } - catch (Exception ex) - { - _canWrite = false; - _logger.ConnectionError(_connectionId, ex); - } + flushAwaiter = writableBuffer.FlushAsync(); } - end.Block.Pool.Return(end.Block); + await flushAwaiter; + } + + public void Dispose() + { + lock (_sync) + { + _completed = true; + } + + _pipe.Writer.Complete(); } public void Flush() { - _outputStream.Flush(); + FlushAsync(CancellationToken.None).GetAwaiter().GetResult(); } public Task FlushAsync(CancellationToken cancellationToken) { - return _outputStream.FlushAsync(cancellationToken); + return WriteAsync(default(ArraySegment), chunk: false, cancellationToken: cancellationToken); + } + + public WritableBuffer Alloc() + { + return _pipe.Writer.Alloc(); + } + + public async Task WriteOutputAsync() + { + try + { + while (true) + { + var readResult = await _pipe.Reader.ReadAsync(); + var buffer = readResult.Buffer; + + try + { + if (buffer.IsEmpty && readResult.IsCompleted) + { + break; + } + + if (buffer.IsEmpty) + { + await _outputStream.FlushAsync(); + } + + foreach (var memory in buffer) + { + var array = memory.GetArray(); + await _outputStream.WriteAsync(array.Array, array.Offset, array.Count); + } + } + finally + { + _pipe.Reader.Advance(readResult.Buffer.End); + } + + // REVIEW: Should we flush here? + } + } + finally + { + _pipe.Reader.Complete(); + } } } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ChunkWriter.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ChunkWriter.cs index 51f9d9f58e..9846d42a04 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ChunkWriter.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ChunkWriter.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.IO.Pipelines; using System.Text; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; @@ -47,16 +48,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http return new ArraySegment(bytes, offset, 10 - offset); } - public static int WriteBeginChunkBytes(ref MemoryPoolIterator start, int dataCount) + public static int WriteBeginChunkBytes(ref WritableBuffer start, int dataCount) { var chunkSegment = BeginChunkBytes(dataCount); - start.CopyFrom(chunkSegment); + start.Write(chunkSegment); return chunkSegment.Count; } - public static void WriteEndChunkBytes(ref MemoryPoolIterator start) + public static void WriteEndChunkBytes(ref WritableBuffer start) { - start.CopyFrom(_endChunkBytes); + start.Write(_endChunkBytes); } } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Connection.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Connection.cs index 777d0b88dc..3708cf52a1 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Connection.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Connection.cs @@ -58,8 +58,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http ConnectionId = GenerateConnectionId(Interlocked.Increment(ref _lastConnectionId)); - Input = Thread.PipelineFactory.Create(ListenerContext.LibuvPipeOptions); - Output = new SocketOutput(Thread, _socket, this, ConnectionId, Log, ThreadPool); + Input = Thread.PipelineFactory.Create(ListenerContext.LibuvInputPipeOptions); + var outputPipe = Thread.PipelineFactory.Create(ListenerContext.LibuvOutputPipeOptions); + Output = new SocketOutput(outputPipe, Thread, _socket, this, ConnectionId, Log); var tcpHandle = _socket as UvTcpHandle; if (tcpHandle != null) @@ -197,11 +198,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { _filteredStream = adapterContext.ConnectionStream; _adaptedPipeline = new AdaptedPipeline( - ConnectionId, adapterContext.ConnectionStream, Thread.PipelineFactory.Create(ListenerContext.AdaptedPipeOptions), - Thread.Memory, - Log); + Thread.PipelineFactory.Create(ListenerContext.AdaptedPipeOptions)); _frame.Input = _adaptedPipeline.Input; _frame.Output = _adaptedPipeline.Output; @@ -209,7 +208,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http // Don't attempt to read input if connection has already closed. // This can happen if a client opens a connection and immediately closes it. _readInputTask = _socketClosedTcs.Task.Status == TaskStatus.WaitingForActivation - ? _adaptedPipeline.ReadInputAsync() + ? _adaptedPipeline.StartAsync() : TaskCache.CompletedTask; } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs index d4f306d10d..f5d1b49b84 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs @@ -891,7 +891,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var hasTransferEncoding = responseHeaders.HasTransferEncoding; var transferCoding = FrameHeaders.GetFinalTransferCoding(responseHeaders.HeaderTransferEncoding); - var end = Output.ProducingStart(); + var end = Output.Alloc(); if (_keepAlive && hasConnection) { @@ -974,12 +974,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http responseHeaders.SetRawDate(dateHeaderValues.String, dateHeaderValues.Bytes); } - end.CopyFrom(_bytesHttpVersion11); - end.CopyFrom(statusBytes); + end.Write(_bytesHttpVersion11); + end.Write(statusBytes); responseHeaders.CopyTo(ref end); - end.CopyFrom(_bytesEndHeaders, 0, _bytesEndHeaders.Length); + end.Write(_bytesEndHeaders); - Output.ProducingComplete(end); + end.Commit(); } public void ParseRequest(ReadableBuffer buffer, out ReadCursor consumed, out ReadCursor examined) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameHeaders.Generated.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameHeaders.Generated.cs index df02ae9a33..da9147f69f 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameHeaders.Generated.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameHeaders.Generated.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; +using System.IO.Pipelines; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.Extensions.Primitives; using Microsoft.Net.Http.Headers; @@ -7752,7 +7753,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http return true; } - protected void CopyToFast(ref MemoryPoolIterator output) + protected void CopyToFast(ref WritableBuffer output) { var tempBits = _bits | (_contentLength.HasValue ? -9223372036854775808L : 0); @@ -7760,7 +7761,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { if (_headers._rawConnection != null) { - output.CopyFrom(_headers._rawConnection, 0, _headers._rawConnection.Length); + output.Write(_headers._rawConnection); } else { @@ -7770,8 +7771,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var value = _headers._Connection[i]; if (value != null) { - output.CopyFrom(_headerBytes, 17, 14); - output.CopyFromAscii(value); + output.Write(new Span(_headerBytes, 17, 14)); + output.WriteAscii(value); } } } @@ -7786,7 +7787,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { if (_headers._rawDate != null) { - output.CopyFrom(_headers._rawDate, 0, _headers._rawDate.Length); + output.Write(_headers._rawDate); } else { @@ -7796,8 +7797,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var value = _headers._Date[i]; if (value != null) { - output.CopyFrom(_headerBytes, 31, 8); - output.CopyFromAscii(value); + output.Write(new Span(_headerBytes, 31, 8)); + output.WriteAscii(value); } } } @@ -7817,8 +7818,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var value = _headers._ContentType[i]; if (value != null) { - output.CopyFrom(_headerBytes, 133, 16); - output.CopyFromAscii(value); + output.Write(new Span(_headerBytes, 133, 16)); + output.WriteAscii(value); } } } @@ -7833,7 +7834,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { if (_headers._rawServer != null) { - output.CopyFrom(_headers._rawServer, 0, _headers._rawServer.Length); + output.Write(_headers._rawServer); } else { @@ -7843,8 +7844,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var value = _headers._Server[i]; if (value != null) { - output.CopyFrom(_headerBytes, 350, 10); - output.CopyFromAscii(value); + output.Write(new Span(_headerBytes, 350, 10)); + output.WriteAscii(value); } } } @@ -7857,8 +7858,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } if ((tempBits & -9223372036854775808L) != 0) { - output.CopyFrom(_headerBytes, 592, 18); - output.CopyFromNumeric((ulong)ContentLength.Value); + output.Write(new Span(_headerBytes, 592, 18)); + output.WriteNumeric((ulong)ContentLength.Value); if((tempBits & ~-9223372036854775808L) == 0) { @@ -7875,8 +7876,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var value = _headers._CacheControl[i]; if (value != null) { - output.CopyFrom(_headerBytes, 0, 17); - output.CopyFromAscii(value); + output.Write(new Span(_headerBytes, 0, 17)); + output.WriteAscii(value); } } } @@ -7896,8 +7897,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var value = _headers._KeepAlive[i]; if (value != null) { - output.CopyFrom(_headerBytes, 39, 14); - output.CopyFromAscii(value); + output.Write(new Span(_headerBytes, 39, 14)); + output.WriteAscii(value); } } } @@ -7917,8 +7918,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var value = _headers._Pragma[i]; if (value != null) { - output.CopyFrom(_headerBytes, 53, 10); - output.CopyFromAscii(value); + output.Write(new Span(_headerBytes, 53, 10)); + output.WriteAscii(value); } } } @@ -7938,8 +7939,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var value = _headers._Trailer[i]; if (value != null) { - output.CopyFrom(_headerBytes, 63, 11); - output.CopyFromAscii(value); + output.Write(new Span(_headerBytes, 63, 11)); + output.WriteAscii(value); } } } @@ -7954,7 +7955,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { if (_headers._rawTransferEncoding != null) { - output.CopyFrom(_headers._rawTransferEncoding, 0, _headers._rawTransferEncoding.Length); + output.Write(_headers._rawTransferEncoding); } else { @@ -7964,8 +7965,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var value = _headers._TransferEncoding[i]; if (value != null) { - output.CopyFrom(_headerBytes, 74, 21); - output.CopyFromAscii(value); + output.Write(new Span(_headerBytes, 74, 21)); + output.WriteAscii(value); } } } @@ -7985,8 +7986,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var value = _headers._Upgrade[i]; if (value != null) { - output.CopyFrom(_headerBytes, 95, 11); - output.CopyFromAscii(value); + output.Write(new Span(_headerBytes, 95, 11)); + output.WriteAscii(value); } } } @@ -8006,8 +8007,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var value = _headers._Via[i]; if (value != null) { - output.CopyFrom(_headerBytes, 106, 7); - output.CopyFromAscii(value); + output.Write(new Span(_headerBytes, 106, 7)); + output.WriteAscii(value); } } } @@ -8027,8 +8028,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var value = _headers._Warning[i]; if (value != null) { - output.CopyFrom(_headerBytes, 113, 11); - output.CopyFromAscii(value); + output.Write(new Span(_headerBytes, 113, 11)); + output.WriteAscii(value); } } } @@ -8048,8 +8049,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var value = _headers._Allow[i]; if (value != null) { - output.CopyFrom(_headerBytes, 124, 9); - output.CopyFromAscii(value); + output.Write(new Span(_headerBytes, 124, 9)); + output.WriteAscii(value); } } } @@ -8069,8 +8070,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var value = _headers._ContentEncoding[i]; if (value != null) { - output.CopyFrom(_headerBytes, 149, 20); - output.CopyFromAscii(value); + output.Write(new Span(_headerBytes, 149, 20)); + output.WriteAscii(value); } } } @@ -8090,8 +8091,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var value = _headers._ContentLanguage[i]; if (value != null) { - output.CopyFrom(_headerBytes, 169, 20); - output.CopyFromAscii(value); + output.Write(new Span(_headerBytes, 169, 20)); + output.WriteAscii(value); } } } @@ -8111,8 +8112,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var value = _headers._ContentLocation[i]; if (value != null) { - output.CopyFrom(_headerBytes, 189, 20); - output.CopyFromAscii(value); + output.Write(new Span(_headerBytes, 189, 20)); + output.WriteAscii(value); } } } @@ -8132,8 +8133,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var value = _headers._ContentMD5[i]; if (value != null) { - output.CopyFrom(_headerBytes, 209, 15); - output.CopyFromAscii(value); + output.Write(new Span(_headerBytes, 209, 15)); + output.WriteAscii(value); } } } @@ -8153,8 +8154,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var value = _headers._ContentRange[i]; if (value != null) { - output.CopyFrom(_headerBytes, 224, 17); - output.CopyFromAscii(value); + output.Write(new Span(_headerBytes, 224, 17)); + output.WriteAscii(value); } } } @@ -8174,8 +8175,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var value = _headers._Expires[i]; if (value != null) { - output.CopyFrom(_headerBytes, 241, 11); - output.CopyFromAscii(value); + output.Write(new Span(_headerBytes, 241, 11)); + output.WriteAscii(value); } } } @@ -8195,8 +8196,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var value = _headers._LastModified[i]; if (value != null) { - output.CopyFrom(_headerBytes, 252, 17); - output.CopyFromAscii(value); + output.Write(new Span(_headerBytes, 252, 17)); + output.WriteAscii(value); } } } @@ -8216,8 +8217,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var value = _headers._AcceptRanges[i]; if (value != null) { - output.CopyFrom(_headerBytes, 269, 17); - output.CopyFromAscii(value); + output.Write(new Span(_headerBytes, 269, 17)); + output.WriteAscii(value); } } } @@ -8237,8 +8238,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var value = _headers._Age[i]; if (value != null) { - output.CopyFrom(_headerBytes, 286, 7); - output.CopyFromAscii(value); + output.Write(new Span(_headerBytes, 286, 7)); + output.WriteAscii(value); } } } @@ -8258,8 +8259,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var value = _headers._ETag[i]; if (value != null) { - output.CopyFrom(_headerBytes, 293, 8); - output.CopyFromAscii(value); + output.Write(new Span(_headerBytes, 293, 8)); + output.WriteAscii(value); } } } @@ -8279,8 +8280,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var value = _headers._Location[i]; if (value != null) { - output.CopyFrom(_headerBytes, 301, 12); - output.CopyFromAscii(value); + output.Write(new Span(_headerBytes, 301, 12)); + output.WriteAscii(value); } } } @@ -8300,8 +8301,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var value = _headers._ProxyAuthenticate[i]; if (value != null) { - output.CopyFrom(_headerBytes, 313, 22); - output.CopyFromAscii(value); + output.Write(new Span(_headerBytes, 313, 22)); + output.WriteAscii(value); } } } @@ -8321,8 +8322,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var value = _headers._RetryAfter[i]; if (value != null) { - output.CopyFrom(_headerBytes, 335, 15); - output.CopyFromAscii(value); + output.Write(new Span(_headerBytes, 335, 15)); + output.WriteAscii(value); } } } @@ -8342,8 +8343,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var value = _headers._SetCookie[i]; if (value != null) { - output.CopyFrom(_headerBytes, 360, 14); - output.CopyFromAscii(value); + output.Write(new Span(_headerBytes, 360, 14)); + output.WriteAscii(value); } } } @@ -8363,8 +8364,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var value = _headers._Vary[i]; if (value != null) { - output.CopyFrom(_headerBytes, 374, 8); - output.CopyFromAscii(value); + output.Write(new Span(_headerBytes, 374, 8)); + output.WriteAscii(value); } } } @@ -8384,8 +8385,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var value = _headers._WWWAuthenticate[i]; if (value != null) { - output.CopyFrom(_headerBytes, 382, 20); - output.CopyFromAscii(value); + output.Write(new Span(_headerBytes, 382, 20)); + output.WriteAscii(value); } } } @@ -8405,8 +8406,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var value = _headers._AccessControlAllowCredentials[i]; if (value != null) { - output.CopyFrom(_headerBytes, 402, 36); - output.CopyFromAscii(value); + output.Write(new Span(_headerBytes, 402, 36)); + output.WriteAscii(value); } } } @@ -8426,8 +8427,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var value = _headers._AccessControlAllowHeaders[i]; if (value != null) { - output.CopyFrom(_headerBytes, 438, 32); - output.CopyFromAscii(value); + output.Write(new Span(_headerBytes, 438, 32)); + output.WriteAscii(value); } } } @@ -8447,8 +8448,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var value = _headers._AccessControlAllowMethods[i]; if (value != null) { - output.CopyFrom(_headerBytes, 470, 32); - output.CopyFromAscii(value); + output.Write(new Span(_headerBytes, 470, 32)); + output.WriteAscii(value); } } } @@ -8468,8 +8469,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var value = _headers._AccessControlAllowOrigin[i]; if (value != null) { - output.CopyFrom(_headerBytes, 502, 31); - output.CopyFromAscii(value); + output.Write(new Span(_headerBytes, 502, 31)); + output.WriteAscii(value); } } } @@ -8489,8 +8490,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var value = _headers._AccessControlExposeHeaders[i]; if (value != null) { - output.CopyFrom(_headerBytes, 533, 33); - output.CopyFromAscii(value); + output.Write(new Span(_headerBytes, 533, 33)); + output.WriteAscii(value); } } } @@ -8510,8 +8511,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var value = _headers._AccessControlMaxAge[i]; if (value != null) { - output.CopyFrom(_headerBytes, 566, 26); - output.CopyFromAscii(value); + output.Write(new Span(_headerBytes, 566, 26)); + output.WriteAscii(value); } } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameResponseHeaders.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameResponseHeaders.cs index 836d73774a..2a3f1979c9 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameResponseHeaders.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameResponseHeaders.cs @@ -4,6 +4,7 @@ using System; using System.Collections; using System.Collections.Generic; +using System.IO.Pipelines; using System.Runtime.CompilerServices; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.Extensions.Primitives; @@ -34,7 +35,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http return GetEnumerator(); } - public void CopyTo(ref MemoryPoolIterator output) + public void CopyTo(ref WritableBuffer output) { CopyToFast(ref output); if (MaybeUnknown != null) @@ -45,10 +46,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { if (value != null) { - output.CopyFrom(_CrLf, 0, 2); - output.CopyFromAscii(kv.Key); - output.CopyFrom(_colonSpace, 0, 2); - output.CopyFromAscii(value); + output.Write(_CrLf); + output.WriteAscii(kv.Key); + output.Write(_colonSpace); + output.Write(value); } } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ISocketOutput.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ISocketOutput.cs index e5c4e4102e..fbefd3fa44 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ISocketOutput.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ISocketOutput.cs @@ -4,6 +4,7 @@ using System; using System.Threading; using System.Threading.Tasks; +using System.IO.Pipelines; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http @@ -17,21 +18,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http Task WriteAsync(ArraySegment buffer, bool chunk = false, CancellationToken cancellationToken = default(CancellationToken)); void Flush(); Task FlushAsync(CancellationToken cancellationToken = default(CancellationToken)); - - /// - /// Returns an iterator pointing to the tail of the response buffer. Response data can be appended - /// manually or by using . - /// Be careful to ensure all appended blocks are backed by a . - /// - MemoryPoolIterator ProducingStart(); - - /// - /// Commits the response data appended to the iterator returned from . - /// All the data up to will be included in the response. - /// A write operation isn't guaranteed to be scheduled unless - /// or is called afterwards. - /// - /// Points to the end of the committed data. - void ProducingComplete(MemoryPoolIterator end); + WritableBuffer Alloc(); } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ListenerContext.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ListenerContext.cs index f947a17aaa..721a31bb60 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ListenerContext.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ListenerContext.cs @@ -42,7 +42,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } } - public PipeOptions LibuvPipeOptions => new PipeOptions + public PipeOptions LibuvInputPipeOptions => new PipeOptions { ReaderScheduler = ServiceContext.ThreadPool, WriterScheduler = Thread, @@ -50,6 +50,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http MaximumSizeLow = ServiceContext.ServerOptions.Limits.MaxRequestBufferSize ?? 0 }; + public PipeOptions LibuvOutputPipeOptions => new PipeOptions + { + ReaderScheduler = Thread, + WriterScheduler = ServiceContext.ThreadPool, + MaximumSizeHigh = GetOutputResponseBufferSize(), + MaximumSizeLow = GetOutputResponseBufferSize() + }; + public PipeOptions AdaptedPipeOptions => new PipeOptions { ReaderScheduler = InlineScheduler.Default, @@ -57,5 +65,18 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http MaximumSizeHigh = ServiceContext.ServerOptions.Limits.MaxRequestBufferSize ?? 0, MaximumSizeLow = ServiceContext.ServerOptions.Limits.MaxRequestBufferSize ?? 0 }; + + private long GetOutputResponseBufferSize() + { + var bufferSize = ServiceContext.ServerOptions.Limits.MaxRequestBufferSize; + if (bufferSize == 0) + { + // 0 = no buffering so we need to configure the pipe so the the writer waits on the reader directly + return 1; + } + + // null means that we have no back pressure + return bufferSize ?? 0; + } } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ListenerSecondary.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ListenerSecondary.cs index 331e1bc4f3..c2486055f4 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ListenerSecondary.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ListenerSecondary.cs @@ -83,7 +83,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http listener.ConnectedCallback(connect, status, error, tcs); } - private void ConnectedCallback(UvConnectRequest connect, int status, Exception error, TaskCompletionSource tcs) + private async void ConnectedCallback(UvConnectRequest connect, int status, Exception error, TaskCompletionSource tcs) { connect.Dispose(); if (error != null) @@ -102,24 +102,18 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http this); writeReq.Init(Thread.Loop); - writeReq.Write( + var result = await writeReq.WriteAsync( DispatchPipe, - new ArraySegment>(new [] { new ArraySegment(_pipeMessage) }), - (req, status2, ex, state) => - { - req.Dispose(); - - var innerTcs = (TaskCompletionSource)state; - if (ex != null) - { - innerTcs.SetException(ex); - } - else - { - innerTcs.SetResult(0); - } - }, - tcs); + new ArraySegment>(new [] { new ArraySegment(_pipeMessage) })); + + if (result.Error != null) + { + tcs.SetException(result.Error); + } + else + { + tcs.SetResult(0); + } } catch (Exception ex) { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/PipelineExtensions.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/PipelineExtensions.cs index 1a014aff56..a53b5d445b 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/PipelineExtensions.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/PipelineExtensions.cs @@ -2,8 +2,11 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Diagnostics; using System.IO.Pipelines; using System.Runtime.CompilerServices; +using System.Text; +using System.Threading; using System.Threading.Tasks; namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http @@ -86,5 +89,19 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } return result; } + + public static void WriteAscii(this WritableBuffer buffer, string data) + { + buffer.Write(Encoding.ASCII.GetBytes(data)); + } + public static void Write(this WritableBuffer buffer, string data) + { + buffer.Write(Encoding.UTF8.GetBytes(data)); + } + + public static void WriteNumeric(this WritableBuffer buffer, ulong number) + { + buffer.Write(number.ToString()); + } } } \ No newline at end of file diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/SocketOutput.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/SocketOutput.cs index 148a7b7582..1438f1c274 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/SocketOutput.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/SocketOutput.cs @@ -2,94 +2,69 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.Collections.Generic; -using System.Diagnostics; +using System.IO.Pipelines; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; using Microsoft.Extensions.Internal; -using Microsoft.Extensions.Logging; namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { public class SocketOutput : ISocketOutput { - private const int _maxPendingWrites = 3; - // There should be never be more WriteContexts than the max ongoing writes + 1 for the next write to be scheduled. - private const int _maxPooledWriteContexts = _maxPendingWrites + 1; - // Well behaved WriteAsync users should await returned task, so there is no need to allocate more per connection by default - private const int _initialTaskQueues = 1; - private static readonly ArraySegment _emptyData = new ArraySegment(new byte[0]); - private static readonly WaitCallback _returnBlocks = (state) => ReturnBlocks((MemoryPoolBlock)state); - private static readonly Action _connectionCancellation = (state) => ((SocketOutput)state).CancellationTriggered(); private readonly KestrelThread _thread; private readonly UvStreamHandle _socket; private readonly Connection _connection; - private readonly long? _maxBytesPreCompleted; private readonly string _connectionId; private readonly IKestrelTrace _log; - private readonly IThreadPool _threadPool; - - // This locks all access to _tail, _head, _lastStart and _closed. - private readonly object _returnLock = new object(); - - private bool _closed; - private MemoryPoolBlock _head; - private MemoryPoolBlock _tail; - private MemoryPoolIterator _lastStart; // This locks access to to all of the below fields private readonly object _contextLock = new object(); - // The number of write operations that have been scheduled so far - // but have not completed. - private int _ongoingWrites = 0; - // Whether or not a write operation is pending to start on the uv thread. - // If this is true, there is no reason to schedule another write even if - // there aren't yet three ongoing write operations. - private bool _postingWrite = false; - private bool _cancelled = false; - private long _numBytesPreCompleted = 0; + private bool _completed = false; private Exception _lastWriteError; - private WriteContext _nextWriteContext; - private readonly Queue _tasksPending; - private readonly Queue _writeContextPool; private readonly WriteReqPool _writeReqPool; + private readonly IPipe _pipe; + private Task _writingTask; + + // https://github.com/dotnet/corefxlab/issues/1334 + // Pipelines don't support multiple awaiters on flush + // this is temporary until it does + private TaskCompletionSource _flushTcs; + private readonly object _flushLock = new object(); + private readonly Action _onFlushCallback; public SocketOutput( + IPipe pipe, KestrelThread thread, UvStreamHandle socket, Connection connection, string connectionId, - IKestrelTrace log, - IThreadPool threadPool) + IKestrelTrace log) { + _pipe = pipe; + // We need to have empty pipe at this moment so callback + // get's scheduled + _writingTask = StartWrites(); _thread = thread; _socket = socket; _connection = connection; _connectionId = connectionId; _log = log; - _threadPool = threadPool; - _tasksPending = new Queue(_initialTaskQueues); - _writeContextPool = new Queue(_maxPooledWriteContexts); _writeReqPool = thread.WriteReqPool; - _maxBytesPreCompleted = connection.ServerOptions.Limits.MaxResponseBufferSize; + _onFlushCallback = OnFlush; } - public Task WriteAsync( + public async Task WriteAsync( ArraySegment buffer, CancellationToken cancellationToken, - bool chunk = false, - bool socketShutdownSend = false, - bool socketDisconnect = false, - bool isSync = false) + bool chunk = false) { - TaskCompletionSource tcs = null; - var scheduleWrite = false; + var writableBuffer = default(WritableBuffer); lock (_contextLock) { @@ -97,110 +72,35 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { _log.ConnectionDisconnectedWrite(_connectionId, buffer.Count, _lastWriteError); - return TaskCache.CompletedTask; + return; } + if (_completed) + { + return; + } + + writableBuffer = _pipe.Writer.Alloc(); + if (buffer.Count > 0) { - var tail = ProducingStart(); - if (tail.IsDefault) + if (chunk) { - return TaskCache.CompletedTask; + ChunkWriter.WriteBeginChunkBytes(ref writableBuffer, buffer.Count); } + writableBuffer.Write(buffer); + if (chunk) { - _numBytesPreCompleted += ChunkWriter.WriteBeginChunkBytes(ref tail, buffer.Count); - } - - tail.CopyFrom(buffer); - - if (chunk) - { - ChunkWriter.WriteEndChunkBytes(ref tail); - _numBytesPreCompleted += 2; - } - - // We do our own accounting below - ProducingCompleteNoPreComplete(tail); - } - - if (_nextWriteContext == null) - { - if (_writeContextPool.Count > 0) - { - _nextWriteContext = _writeContextPool.Dequeue(); - } - else - { - _nextWriteContext = new WriteContext(this); + ChunkWriter.WriteEndChunkBytes(ref writableBuffer); } } - if (socketShutdownSend) - { - _nextWriteContext.SocketShutdownSend = true; - } - if (socketDisconnect) - { - _nextWriteContext.SocketDisconnect = true; - } - - if (!_maxBytesPreCompleted.HasValue || _numBytesPreCompleted + buffer.Count <= _maxBytesPreCompleted.Value) - { - // Complete the write task immediately if all previous write tasks have been completed, - // the buffers haven't grown too large, and the last write to the socket succeeded. - _numBytesPreCompleted += buffer.Count; - } - else - { - if (cancellationToken.CanBeCanceled) - { - if (cancellationToken.IsCancellationRequested) - { - _connection.AbortAsync(); - _cancelled = true; - return TaskUtilities.GetCancelledTask(cancellationToken); - } - else - { - // immediate write, which is not eligable for instant completion above - tcs = new TaskCompletionSource(); - _tasksPending.Enqueue(new WaitingTask() - { - CancellationToken = cancellationToken, - CancellationRegistration = cancellationToken.SafeRegister(_connectionCancellation, this), - BytesToWrite = buffer.Count, - CompletionSource = tcs - }); - } - } - else - { - tcs = new TaskCompletionSource(); - _tasksPending.Enqueue(new WaitingTask() { - IsSync = isSync, - BytesToWrite = buffer.Count, - CompletionSource = tcs - }); - } - } - - if (!_postingWrite && _ongoingWrites < _maxPendingWrites) - { - _postingWrite = true; - _ongoingWrites++; - scheduleWrite = true; - } + writableBuffer.Commit(); } - if (scheduleWrite) - { - ScheduleWrite(); - } - - // Return TaskCompletionSource's Task if set, otherwise completed Task - return tcs?.Task ?? TaskCache.CompletedTask; + await FlushAsync(writableBuffer); } public void End(ProduceEndType endType) @@ -208,324 +108,61 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http switch (endType) { case ProduceEndType.SocketShutdown: - WriteAsync(default(ArraySegment), - default(CancellationToken), - socketShutdownSend: true, - socketDisconnect: true, - isSync: true); + // Graceful shutdown + _pipe.Reader.CancelPendingRead(); break; case ProduceEndType.SocketDisconnect: - WriteAsync(default(ArraySegment), - default(CancellationToken), - socketShutdownSend: false, - socketDisconnect: true, - isSync: true); + // Not graceful break; } - } - - public MemoryPoolIterator ProducingStart() - { - lock (_returnLock) - { - Debug.Assert(_lastStart.IsDefault); - - if (_closed) - { - return default(MemoryPoolIterator); - } - - if (_tail == null) - { - _head = _thread.Memory.Lease(); - _tail = _head; - } - - _lastStart = new MemoryPoolIterator(_tail, _tail.End); - - return _lastStart; - } - } - - public void ProducingComplete(MemoryPoolIterator end) - { - if (_lastStart.IsDefault) - { - return; - } - - int bytesProduced, buffersIncluded; - BytesBetween(_lastStart, end, out bytesProduced, out buffersIncluded); lock (_contextLock) { - _numBytesPreCompleted += bytesProduced; + _completed = true; } - ProducingCompleteNoPreComplete(end); + // We're done writing + _pipe.Writer.Complete(); } - private void ProducingCompleteNoPreComplete(MemoryPoolIterator end) + private Task FlushAsync(WritableBuffer writableBuffer) { - MemoryPoolBlock blockToReturn = null; - - lock (_returnLock) + var awaitable = writableBuffer.FlushAsync(); + if (awaitable.IsCompleted) { - // Both ProducingComplete and WriteAsync should not call this method - // if _lastStart was not set. - Debug.Assert(!_lastStart.IsDefault); - - // If the socket has been closed, return the produced blocks - // instead of advancing the now non-existent tail. - if (_tail != null) - { - _tail = end.Block; - _tail.End = end.Index; - } - else - { - blockToReturn = _lastStart.Block; - } - - _lastStart = default(MemoryPoolIterator); - } - - if (blockToReturn != null) - { - _threadPool.UnsafeRun(_returnBlocks, blockToReturn); + // The flush task can't fail today + return TaskCache.CompletedTask; } + return FlushAsyncAwaited(awaitable); } - private void CancellationTriggered() + private Task FlushAsyncAwaited(WritableBufferAwaitable awaitable) { - lock (_contextLock) + // https://github.com/dotnet/corefxlab/issues/1334 + // Since the flush awaitable doesn't currently support multiple awaiters + // we need to use a task to track the callbacks. + // All awaiters get the same task + lock (_flushLock) { - if (!_cancelled) + if (_flushTcs == null || _flushTcs.Task.IsCompleted) { - // Abort the connection for any failed write - // Queued on threadpool so get it in as first op. - _connection.AbortAsync(); - _cancelled = true; + _flushTcs = new TaskCompletionSource(); - CompleteAllWrites(); - - _log.ConnectionError(_connectionId, new TaskCanceledException("Write operation canceled. Aborting connection.")); + awaitable.OnCompleted(_onFlushCallback); } } + + return _flushTcs.Task; } - private static void ReturnBlocks(MemoryPoolBlock block) + private void OnFlush() { - while (block != null) - { - var returningBlock = block; - block = returningBlock.Next; - - returningBlock.Pool.Return(returningBlock); - } - } - - private void ScheduleWrite() - { - _thread.Post(state => state.WriteAllPending(), this); - } - - // This is called on the libuv event loop - private void WriteAllPending() - { - WriteContext writingContext = null; - - if (Monitor.TryEnter(_contextLock)) - { - _postingWrite = false; - - if (_nextWriteContext != null) - { - writingContext = _nextWriteContext; - _nextWriteContext = null; - } - else - { - _ongoingWrites--; - } - - Monitor.Exit(_contextLock); - } - else - { - ScheduleWrite(); - } - - if (writingContext != null) - { - writingContext.DoWriteIfNeeded(); - } - } - - // This may called on the libuv event loop - private void OnWriteCompleted(WriteContext writeContext) - { - // Called inside _contextLock - var bytesWritten = writeContext.ByteCount; - var status = writeContext.WriteStatus; - var error = writeContext.WriteError; - - if (error != null) - { - // Abort the connection for any failed write - // Queued on threadpool so get it in as first op. - _connection.AbortAsync(); - _cancelled = true; - _lastWriteError = error; - } - - PoolWriteContext(writeContext); - - // _numBytesPreCompleted can temporarily go negative in the event there are - // completed writes that we haven't triggered callbacks for yet. - _numBytesPreCompleted -= bytesWritten; - - if (error == null) - { - CompleteFinishedWrites(status); - _log.ConnectionWriteCallback(_connectionId, status); - } - else - { - CompleteAllWrites(); - - // Log connection resets at a lower (Debug) level. - if (status == Constants.ECONNRESET) - { - _log.ConnectionReset(_connectionId); - } - else - { - _log.ConnectionError(_connectionId, error); - } - } - - if (!_postingWrite && _nextWriteContext != null) - { - _postingWrite = true; - ScheduleWrite(); - } - else - { - _ongoingWrites--; - } - } - - private void CompleteNextWrite(ref long bytesLeftToBuffer) - { - // Called inside _contextLock - var waitingTask = _tasksPending.Dequeue(); - var bytesToWrite = waitingTask.BytesToWrite; - - _numBytesPreCompleted += bytesToWrite; - bytesLeftToBuffer -= bytesToWrite; - - // Dispose registration if there is one - waitingTask.CancellationRegistration?.Dispose(); - - if (waitingTask.CancellationToken.IsCancellationRequested) - { - if (waitingTask.IsSync) - { - waitingTask.CompletionSource.TrySetCanceled(); - } - else - { - _threadPool.Cancel(waitingTask.CompletionSource); - } - } - else - { - if (waitingTask.IsSync) - { - waitingTask.CompletionSource.TrySetResult(null); - } - else - { - _threadPool.Complete(waitingTask.CompletionSource); - } - } - } - - private void CompleteFinishedWrites(int status) - { - if (!_maxBytesPreCompleted.HasValue) - { - Debug.Assert(_tasksPending.Count == 0); - return; - } - - // Called inside _contextLock - // bytesLeftToBuffer can be greater than _maxBytesPreCompleted - // This allows large writes to complete once they've actually finished. - var bytesLeftToBuffer = _maxBytesPreCompleted.Value - _numBytesPreCompleted; - while (_tasksPending.Count > 0 && - (_tasksPending.Peek().BytesToWrite) <= bytesLeftToBuffer) - { - CompleteNextWrite(ref bytesLeftToBuffer); - } - } - - private void CompleteAllWrites() - { - if (!_maxBytesPreCompleted.HasValue) - { - Debug.Assert(_tasksPending.Count == 0); - return; - } - - // Called inside _contextLock - var bytesLeftToBuffer = _maxBytesPreCompleted.Value - _numBytesPreCompleted; - while (_tasksPending.Count > 0) - { - CompleteNextWrite(ref bytesLeftToBuffer); - } - } - - // This is called on the libuv event loop - private void ReturnAllBlocks() - { - lock (_returnLock) - { - var block = _head; - while (block != _tail) - { - var returnBlock = block; - block = block.Next; - - returnBlock.Pool.Return(returnBlock); - } - - // Only return the _tail if we aren't between ProducingStart/Complete calls - if (_lastStart.IsDefault) - { - _tail?.Pool.Return(_tail); - } - - _head = null; - _tail = null; - _closed = true; - } - } - - private void PoolWriteContext(WriteContext writeContext) - { - // Called inside _contextLock - if (_writeContextPool.Count < _maxPooledWriteContexts) - { - writeContext.Reset(); - _writeContextPool.Enqueue(writeContext); - } + _flushTcs.TrySetResult(null); } void ISocketOutput.Write(ArraySegment buffer, bool chunk) { - WriteAsync(buffer, default(CancellationToken), chunk, isSync: true).GetAwaiter().GetResult(); + WriteAsync(buffer, default(CancellationToken), chunk).GetAwaiter().GetResult(); } Task ISocketOutput.WriteAsync(ArraySegment buffer, bool chunk, CancellationToken cancellationToken) @@ -546,7 +183,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http void ISocketOutput.Flush() { - WriteAsync(_emptyData, default(CancellationToken), isSync: true).GetAwaiter().GetResult(); + WriteAsync(_emptyData, default(CancellationToken)).GetAwaiter().GetResult(); } Task ISocketOutput.FlushAsync(CancellationToken cancellationToken) @@ -554,261 +191,114 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http return WriteAsync(_emptyData, cancellationToken); } - private static void BytesBetween(MemoryPoolIterator start, MemoryPoolIterator end, out int bytes, out int buffers) + public WritableBuffer Alloc() { - if (start.Block == end.Block) + lock (_contextLock) { - bytes = end.Index - start.Index; - buffers = 1; - return; + if (_completed) + { + // This is broken + return default(WritableBuffer); + } + + return _pipe.Writer.Alloc(); } - - bytes = start.Block.Data.Offset + start.Block.Data.Count - start.Index; - buffers = 1; - - for (var block = start.Block.Next; block != end.Block; block = block.Next) - { - bytes += block.Data.Count; - buffers++; - } - - bytes += end.Index - end.Block.Data.Offset; - buffers++; } - private class WriteContext + public async Task StartWrites() { - private static readonly WaitCallback _returnWrittenBlocks = (state) => ReturnWrittenBlocks((MemoryPoolBlock)state); - private static readonly WaitCallback _completeWrite = (state) => ((WriteContext)state).CompleteOnThreadPool(); - - private SocketOutput Self; - private UvWriteReq _writeReq; - private MemoryPoolIterator _lockedStart; - private MemoryPoolIterator _lockedEnd; - private int _bufferCount; - - public int ByteCount; - public bool SocketShutdownSend; - public bool SocketDisconnect; - - public int WriteStatus; - public Exception WriteError; - - public WriteContext(SocketOutput self) + while (true) { - Self = self; - } + var result = await _pipe.Reader.ReadAsync(); + var buffer = result.Buffer; - /// - /// First step: initiate async write if needed, otherwise go to next step - /// - public void DoWriteIfNeeded() - { - LockWrite(); - - if (ByteCount == 0 || Self._socket.IsClosed) + try { - DoShutdownIfNeeded(); - return; - } - - // Update _head immediate after write is "locked", so the block returning logic - // works correctly when run inline in the write callback. - Self._head = _lockedEnd.Block; - Self._head.Start = _lockedEnd.Index; - - _writeReq = Self._writeReqPool.Allocate(); - - _writeReq.Write(Self._socket, _lockedStart, _lockedEnd, _bufferCount, (req, status, error, state) => - { - var writeContext = (WriteContext)state; - writeContext.PoolWriteReq(writeContext._writeReq); - writeContext._writeReq = null; - writeContext.ScheduleReturnWrittenBlocks(); - writeContext.WriteStatus = status; - writeContext.WriteError = error; - writeContext.DoShutdownIfNeeded(); - }, this); - } - - /// - /// Second step: initiate async shutdown if needed, otherwise go to next step - /// - public void DoShutdownIfNeeded() - { - if (SocketShutdownSend == false || Self._socket.IsClosed) - { - DoDisconnectIfNeeded(); - return; - } - - Self._log.ConnectionWriteFin(Self._connectionId); - - var shutdownReq = new UvShutdownReq(Self._log); - shutdownReq.Init(Self._thread.Loop); - shutdownReq.Shutdown(Self._socket, (req, status, state) => - { - req.Dispose(); - - var writeContext = (WriteContext)state; - writeContext.Self._log.ConnectionWroteFin(writeContext.Self._connectionId, status); - writeContext.DoDisconnectIfNeeded(); - }, this); - } - - /// - /// Third step: disconnect socket if needed, otherwise this work item is complete - /// - private void DoDisconnectIfNeeded() - { - if (SocketDisconnect == false || Self._socket.IsClosed) - { - CompleteWithContextLock(); - return; - } - - // Ensure all blocks are returned before calling OnSocketClosed - // to ensure the MemoryPool doesn't get disposed too soon. - Self.ReturnAllBlocks(); - Self._socket.Dispose(); - Self._connection.OnSocketClosed(); - Self._log.ConnectionStop(Self._connectionId); - CompleteWithContextLock(); - } - - private void CompleteWithContextLock() - { - if (Monitor.TryEnter(Self._contextLock)) - { - try + if (!buffer.IsEmpty) { - Self.OnWriteCompleted(this); + var writeReq = _writeReqPool.Allocate(); + var writeResult = await writeReq.WriteAsync(_socket, buffer); + _writeReqPool.Return(writeReq); + + // REVIEW: Locking here, do we need to take the context lock? + OnWriteCompleted(writeResult.Status, writeResult.Error); } - finally + + if (result.IsCancelled) { - Monitor.Exit(Self._contextLock); + // Send a FIN + await ShutdownAsync(); } + + if (buffer.IsEmpty && result.IsCompleted) + { + break; + } + } + finally + { + _pipe.Reader.Advance(result.Buffer.End); + } + } + + // We're done reading + _pipe.Reader.Complete(); + + _socket.Dispose(); + _connection.OnSocketClosed(); + _log.ConnectionStop(_connectionId); + } + + private void OnWriteCompleted(int writeStatus, Exception writeError) + { + // Called inside _contextLock + var status = writeStatus; + var error = writeError; + + if (error != null) + { + // Abort the connection for any failed write + // Queued on threadpool so get it in as first op. + _connection.AbortAsync(); + _cancelled = true; + _lastWriteError = error; + } + + if (error == null) + { + _log.ConnectionWriteCallback(_connectionId, status); + } + else + { + // Log connection resets at a lower (Debug) level. + if (status == Constants.ECONNRESET) + { + _log.ConnectionReset(_connectionId); } else { - Self._threadPool.UnsafeRun(_completeWrite, this); + _log.ConnectionError(_connectionId, error); } } - - private void CompleteOnThreadPool() - { - lock (Self._contextLock) - { - try - { - Self.OnWriteCompleted(this); - } - catch (Exception ex) - { - Self._log.LogError(0, ex, "SocketOutput.OnWriteCompleted"); - } - } - } - - private void PoolWriteReq(UvWriteReq writeReq) - { - Self._writeReqPool.Return(writeReq); - } - - private void ScheduleReturnWrittenBlocks() - { - var returnAll = false; - - lock (Self._returnLock) - { - // If everything has been fully written, return _tail/_lockedEnd. - if (_lockedEnd.Block == Self._tail && - _lockedEnd.Index == Self._tail.End && - Self._lastStart.IsDefault) - { - Debug.Assert(Self._head == Self._tail); - Debug.Assert(Self._tail.Start == Self._tail.End); - - Self._head = null; - Self._tail = null; - returnAll = true; - } - } - - if (!returnAll) - { - var block = _lockedStart.Block; - var end = _lockedEnd.Block; - if (block == end) - { - return; - } - - while (block.Next != end) - { - block = block.Next; - } - - // Set the Next pointer in the block before _lockedEnd.Block to null. - // This prevents _lockedEnd.Block from being returned if it isn't fully - // written, or it's still being written to. - block.Next = null; - } - - Self._threadPool.UnsafeRun(_returnWrittenBlocks, _lockedStart.Block); - } - - private static void ReturnWrittenBlocks(MemoryPoolBlock block) - { - while (block != null) - { - var returnBlock = block; - block = block.Next; - - returnBlock.Pool.Return(returnBlock); - } - } - - private void LockWrite() - { - var head = Self._head; - var tail = Self._tail; - - if (head == null || tail == null) - { - // ReturnAllBlocks has already bee called. Nothing to do here. - // Write will no-op since _byteCount will remain 0. - return; - } - - _lockedStart = new MemoryPoolIterator(head, head.Start); - _lockedEnd = new MemoryPoolIterator(tail, tail.End); - - BytesBetween(_lockedStart, _lockedEnd, out ByteCount, out _bufferCount); - } - - public void Reset() - { - _lockedStart = default(MemoryPoolIterator); - _lockedEnd = default(MemoryPoolIterator); - _bufferCount = 0; - ByteCount = 0; - - SocketShutdownSend = false; - SocketDisconnect = false; - - WriteStatus = 0; - WriteError = null; - } } - private struct WaitingTask + private Task ShutdownAsync() { - public bool IsSync; - public int BytesToWrite; - public CancellationToken CancellationToken; - public IDisposable CancellationRegistration; - public TaskCompletionSource CompletionSource; + var tcs = new TaskCompletionSource(); + _log.ConnectionWriteFin(_connectionId); + + var shutdownReq = new UvShutdownReq(_log); + shutdownReq.Init(_thread.Loop); + shutdownReq.Shutdown(_socket, (req, status, state) => + { + req.Dispose(); + _log.ConnectionWroteFin(_connectionId, status); + + tcs.TrySetResult(null); + }, + this); + + return tcs.Task; } } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/KestrelThread.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/KestrelThread.cs index 03d6abcbc2..1c42ccd055 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/KestrelThread.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/KestrelThread.cs @@ -13,7 +13,6 @@ using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; using Microsoft.Extensions.Logging; -using MemoryPool = Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPool; namespace Microsoft.AspNetCore.Server.Kestrel.Internal { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/LibuvAwaitable.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/LibuvAwaitable.cs new file mode 100644 index 0000000000..1bfd222e6c --- /dev/null +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/LibuvAwaitable.cs @@ -0,0 +1,77 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using System; +using System.Net; +using System.Threading.Tasks; +using System.Runtime.CompilerServices; +using System.Threading; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; + +namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure +{ + public class LibuvAwaitable : ICriticalNotifyCompletion where TRequest : UvRequest + { + private readonly static Action CALLBACK_RAN = () => { }; + + private Action _callback; + + private Exception _exception; + + private int _status; + + public static Action Callback = (req, status, error, state) => + { + var awaitable = (LibuvAwaitable)state; + + awaitable._exception = error; + awaitable._status = status; + + var continuation = Interlocked.Exchange(ref awaitable._callback, CALLBACK_RAN); + + continuation?.Invoke(); + }; + + public LibuvAwaitable GetAwaiter() => this; + public bool IsCompleted => _callback == CALLBACK_RAN; + + public UvWriteResult GetResult() + { + var exception = _exception; + var status = _status; + + // Reset the awaitable state + _exception = null; + _status = 0; + _callback = null; + + return new UvWriteResult(status, exception); + } + + public void OnCompleted(Action continuation) + { + if (_callback == CALLBACK_RAN || + Interlocked.CompareExchange(ref _callback, continuation, null) == CALLBACK_RAN) + { + Task.Run(continuation); + } + } + + public void UnsafeOnCompleted(Action continuation) + { + OnCompleted(continuation); + } + } + + public struct UvWriteResult + { + public int Status; + public Exception Error; + + public UvWriteResult(int status, Exception error) + { + Status = status; + Error = error; + } + } +} \ No newline at end of file diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPool.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPool.cs deleted file mode 100644 index 260cfc1f1e..0000000000 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPool.cs +++ /dev/null @@ -1,214 +0,0 @@ -using System; -using System.Collections.Concurrent; -using System.Diagnostics; -using System.Runtime.CompilerServices; - -namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure -{ - /// - /// Used to allocate and distribute re-usable blocks of memory. - /// - public class MemoryPool : IDisposable - { - /// - /// The gap between blocks' starting address. 4096 is chosen because most operating systems are 4k pages in size and alignment. - /// - private const int _blockStride = 4096; - - /// - /// The last 64 bytes of a block are unused to prevent CPU from pre-fetching the next 64 byte into it's memory cache. - /// See https://github.com/aspnet/KestrelHttpServer/issues/117 and https://www.youtube.com/watch?v=L7zSU9HI-6I - /// - private const int _blockUnused = 64; - - /// - /// Allocating 32 contiguous blocks per slab makes the slab size 128k. This is larger than the 85k size which will place the memory - /// in the large object heap. This means the GC will not try to relocate this array, so the fact it remains pinned does not negatively - /// affect memory management's compactification. - /// - private const int _blockCount = 32; - - /// - /// 4096 - 64 gives you a blockLength of 4032 usable bytes per block. - /// - private const int _blockLength = _blockStride - _blockUnused; - - /// - /// Max allocation block size for pooled blocks, - /// larger values can be leased but they will be disposed after use rather than returned to the pool. - /// - public const int MaxPooledBlockLength = _blockLength; - - /// - /// 4096 * 32 gives you a slabLength of 128k contiguous bytes allocated per slab - /// - private const int _slabLength = _blockStride * _blockCount; - - /// - /// Thread-safe collection of blocks which are currently in the pool. A slab will pre-allocate all of the block tracking objects - /// and add them to this collection. When memory is requested it is taken from here first, and when it is returned it is re-added. - /// - private readonly ConcurrentQueue _blocks = new ConcurrentQueue(); - - /// - /// Thread-safe collection of slabs which have been allocated by this pool. As long as a slab is in this collection and slab.IsActive, - /// the blocks will be added to _blocks when returned. - /// - private readonly ConcurrentStack _slabs = new ConcurrentStack(); - - /// - /// This is part of implementing the IDisposable pattern. - /// - private bool _disposedValue = false; // To detect redundant calls - - /// - /// Called to take a block from the pool. - /// - /// The block that is reserved for the called. It must be passed to Return when it is no longer being used. -#if DEBUG - public MemoryPoolBlock Lease( - [CallerMemberName] string memberName = "", - [CallerFilePath] string sourceFilePath = "", - [CallerLineNumber] int sourceLineNumber = 0) - { - Debug.Assert(!_disposedValue, "Block being leased from disposed pool!"); -#else - public MemoryPoolBlock Lease() - { -#endif - MemoryPoolBlock block; - if (_blocks.TryDequeue(out block)) - { - // block successfully taken from the stack - return it -#if DEBUG - block.Leaser = memberName + ", " + sourceFilePath + ", " + sourceLineNumber; - block.IsLeased = true; -#endif - return block; - } - // no blocks available - grow the pool - block = AllocateSlab(); -#if DEBUG - block.Leaser = memberName + ", " + sourceFilePath + ", " + sourceLineNumber; - block.IsLeased = true; -#endif - return block; - } - - /// - /// Internal method called when a block is requested and the pool is empty. It allocates one additional slab, creates all of the - /// block tracking objects, and adds them all to the pool. - /// - private MemoryPoolBlock AllocateSlab() - { - var slab = MemoryPoolSlab.Create(_slabLength); - _slabs.Push(slab); - - var basePtr = slab.ArrayPtr; - var firstOffset = (int)((_blockStride - 1) - ((ulong)(basePtr + _blockStride - 1) % _blockStride)); - - var poolAllocationLength = _slabLength - _blockStride; - - var offset = firstOffset; - for (; - offset + _blockLength < poolAllocationLength; - offset += _blockStride) - { - var block = MemoryPoolBlock.Create( - new ArraySegment(slab.Array, offset, _blockLength), - basePtr, - this, - slab); -#if DEBUG - block.IsLeased = true; -#endif - Return(block); - } - - // return last block rather than adding to pool - var newBlock = MemoryPoolBlock.Create( - new ArraySegment(slab.Array, offset, _blockLength), - basePtr, - this, - slab); - - return newBlock; - } - - /// - /// Called to return a block to the pool. Once Return has been called the memory no longer belongs to the caller, and - /// Very Bad Things will happen if the memory is read of modified subsequently. If a caller fails to call Return and the - /// block tracking object is garbage collected, the block tracking object's finalizer will automatically re-create and return - /// a new tracking object into the pool. This will only happen if there is a bug in the server, however it is necessary to avoid - /// leaving "dead zones" in the slab due to lost block tracking objects. - /// - /// The block to return. It must have been acquired by calling Lease on the same memory pool instance. - public void Return(MemoryPoolBlock block) - { -#if DEBUG - Debug.Assert(block.Pool == this, "Returned block was not leased from this pool"); - Debug.Assert(block.IsLeased, $"Block being returned to pool twice: {block.Leaser}{Environment.NewLine}"); - block.IsLeased = false; -#endif - - if (block.Slab != null && block.Slab.IsActive) - { - block.Reset(); - _blocks.Enqueue(block); - } - else - { - GC.SuppressFinalize(block); - } - } - - protected virtual void Dispose(bool disposing) - { - if (!_disposedValue) - { - _disposedValue = true; -#if DEBUG - GC.Collect(); - GC.WaitForPendingFinalizers(); - GC.Collect(); -#endif - if (disposing) - { - MemoryPoolSlab slab; - while (_slabs.TryPop(out slab)) - { - // dispose managed state (managed objects). - slab.Dispose(); - } - } - - // Discard blocks in pool - MemoryPoolBlock block; - while (_blocks.TryDequeue(out block)) - { - GC.SuppressFinalize(block); - } - - // N/A: free unmanaged resources (unmanaged objects) and override a finalizer below. - - // N/A: set large fields to null. - - } - } - - // N/A: override a finalizer only if Dispose(bool disposing) above has code to free unmanaged resources. - // ~MemoryPool2() { - // // Do not change this code. Put cleanup code in Dispose(bool disposing) above. - // Dispose(false); - // } - - // This code added to correctly implement the disposable pattern. - public void Dispose() - { - // Do not change this code. Put cleanup code in Dispose(bool disposing) above. - Dispose(true); - // N/A: uncomment the following line if the finalizer is overridden above. - // GC.SuppressFinalize(this); - } - } -} diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolBlock.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolBlock.cs deleted file mode 100644 index 5f22dd4a1f..0000000000 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolBlock.cs +++ /dev/null @@ -1,139 +0,0 @@ -using System; -using System.Diagnostics; -using System.Text; - -namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure -{ - /// - /// Block tracking object used by the byte buffer memory pool. A slab is a large allocation which is divided into smaller blocks. The - /// individual blocks are then treated as independent array segments. - /// - public class MemoryPoolBlock - { - /// - /// Native address of the first byte of this block's Data memory. It is null for one-time-use memory, or copied from - /// the Slab's ArrayPtr for a slab-block segment. The byte it points to corresponds to Data.Array[0], and in practice you will always - /// use the DataArrayPtr + Start or DataArrayPtr + End, which point to the start of "active" bytes, or point to just after the "active" bytes. - /// - public readonly IntPtr DataArrayPtr; - - internal unsafe readonly byte* DataFixedPtr; - - /// - /// The array segment describing the range of memory this block is tracking. The caller which has leased this block may only read and - /// modify the memory in this range. - /// - public ArraySegment Data; - - /// - /// This object cannot be instantiated outside of the static Create method - /// - unsafe protected MemoryPoolBlock(IntPtr dataArrayPtr) - { - DataArrayPtr = dataArrayPtr; - DataFixedPtr = (byte*)dataArrayPtr.ToPointer(); - } - - /// - /// Back-reference to the memory pool which this block was allocated from. It may only be returned to this pool. - /// - public MemoryPool Pool { get; private set; } - - /// - /// Back-reference to the slab from which this block was taken, or null if it is one-time-use memory. - /// - public MemoryPoolSlab Slab { get; private set; } - - /// - /// Convenience accessor - /// - public byte[] Array => Data.Array; - - /// - /// The Start represents the offset into Array where the range of "active" bytes begins. At the point when the block is leased - /// the Start is guaranteed to be equal to Array.Offset. The value of Start may be assigned anywhere between Data.Offset and - /// Data.Offset + Data.Count, and must be equal to or less than End. - /// - public int Start; - - /// - /// The End represents the offset into Array where the range of "active" bytes ends. At the point when the block is leased - /// the End is guaranteed to be equal to Array.Offset. The value of Start may be assigned anywhere between Data.Offset and - /// Data.Offset + Data.Count, and must be equal to or less than End. - /// - public volatile int End; - - /// - /// Reference to the next block of data when the overall "active" bytes spans multiple blocks. At the point when the block is - /// leased Next is guaranteed to be null. Start, End, and Next are used together in order to create a linked-list of discontiguous - /// working memory. The "active" memory is grown when bytes are copied in, End is increased, and Next is assigned. The "active" - /// memory is shrunk when bytes are consumed, Start is increased, and blocks are returned to the pool. - /// - public MemoryPoolBlock Next; - -#if DEBUG - public bool IsLeased { get; set; } - public string Leaser { get; set; } -#endif - - ~MemoryPoolBlock() - { -#if DEBUG - Debug.Assert(Slab == null || !Slab.IsActive, $"{Environment.NewLine}{Environment.NewLine}*** Block being garbage collected instead of returned to pool: {Leaser} ***{Environment.NewLine}"); -#endif - if (Slab != null && Slab.IsActive) - { - Pool.Return(new MemoryPoolBlock(DataArrayPtr) - { - Data = Data, - Pool = Pool, - Slab = Slab, - }); - } - } - - internal static MemoryPoolBlock Create( - ArraySegment data, - IntPtr dataPtr, - MemoryPool pool, - MemoryPoolSlab slab) - { - return new MemoryPoolBlock(dataPtr) - { - Data = data, - Pool = pool, - Slab = slab, - Start = data.Offset, - End = data.Offset, - }; - } - - /// - /// called when the block is returned to the pool. mutable values are re-assigned to their guaranteed initialized state. - /// - public void Reset() - { - Next = null; - Start = Data.Offset; - End = Data.Offset; - } - - /// - /// ToString overridden for debugger convenience. This displays the "active" byte information in this block as ASCII characters. - /// - /// - public override string ToString() - { - return Encoding.ASCII.GetString(Array, Start, End - Start); - } - - /// - /// acquires a cursor pointing into this block at the Start of "active" byte information - /// - /// - public MemoryPoolIterator GetIterator() - { - return new MemoryPoolIterator(this); - } - } -} diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolIterator.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolIterator.cs deleted file mode 100644 index 0f4d3cebe5..0000000000 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolIterator.cs +++ /dev/null @@ -1,463 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using System.Diagnostics; -using System.Numerics; -using System.Runtime.CompilerServices; -using System.Text; -using System.Threading; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; - -namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure -{ - public struct MemoryPoolIterator - { - private const int _maxULongByteLength = 20; - - [ThreadStatic] - private static byte[] _numericBytesScratch; - - private MemoryPoolBlock _block; - private int _index; - - public MemoryPoolIterator(MemoryPoolBlock block) - { - _block = block; - _index = _block?.Start ?? 0; - } - public MemoryPoolIterator(MemoryPoolBlock block, int index) - { - _block = block; - _index = index; - } - - public bool IsDefault => _block == null; - - public bool IsEnd - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - get - { - var block = _block; - if (block == null) - { - return true; - } - else if (_index < block.End) - { - return false; - } - else if (block.Next == null) - { - return true; - } - else - { - return IsEndMultiBlock(); - } - } - } - - [MethodImpl(MethodImplOptions.NoInlining)] - private bool IsEndMultiBlock() - { - var block = _block.Next; - do - { - if (block.Start < block.End) - { - return false; // subsequent block has data - IsEnd is false - } - block = block.Next; - } while (block != null); - - return true; - } - - public MemoryPoolBlock Block => _block; - - public int Index => _index; - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public int Take() - { - var block = _block; - if (block == null) - { - return -1; - } - - var index = _index; - // Always set wasLastBlock before checking .End to avoid race which may cause data loss - var wasLastBlock = block.Next == null; - - if (index < block.End) - { - _index = index + 1; - return block.Array[index]; - } - - return wasLastBlock ? -1 : TakeMultiBlock(); - } - - [MethodImpl(MethodImplOptions.NoInlining)] - private int TakeMultiBlock() - { - var block = _block; - do - { - block = block.Next; - var index = block.Start; - - // Always set wasLastBlock before checking .End to avoid race which may cause data loss - var wasLastBlock = block.Next == null; - - if (index < block.End) - { - _block = block; - _index = index + 1; - return block.Array[index]; - } - - if (wasLastBlock) - { - return -1; - } - } while (true); - } - - /// - /// Save the data at the current location then move to the next available space. - /// - /// The byte to be saved. - /// true if the operation successes. false if can't find available space. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Put(byte data) - { - var block = _block; - if (block == null) - { - ThrowInvalidOperationException_PutPassedEndOfBlock(); - } - - var index = _index; - - // Always set wasLastBlock before checking .End to avoid race which may cause data loss - var wasLastBlock = block.Next == null; - if (index < block.End) - { - _index = index + 1; - block.Array[index] = data; - return true; - } - - if (wasLastBlock) - { - ThrowInvalidOperationException_PutPassedEndOfBlock(); - } - - return PutMultiBlock(data); - } - - [MethodImpl(MethodImplOptions.NoInlining)] - private bool PutMultiBlock(byte data) - { - var block = _block; - do - { - block = block.Next; - var index = block.Start; - - // Always set wasLastBlock before checking .End to avoid race which may cause data loss - var wasLastBlock = block.Next == null; - - if (index < block.End) - { - _block = block; - _index = index + 1; - block.Array[index] = data; - break; - } - if (wasLastBlock) - { - ThrowInvalidOperationException_PutPassedEndOfBlock(); - return false; - } - } while (true); - - return true; - } - - private static void ThrowInvalidOperationException_PutPassedEndOfBlock() - { - throw new InvalidOperationException("Attempted to put passed end of block."); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public int GetLength(MemoryPoolIterator end) - { - var block = _block; - if (block == null || end.IsDefault) - { - ThrowInvalidOperationException_GetLengthNullBlock(); - } - - if (block == end._block) - { - return end._index - _index; - } - - return GetLengthMultiBlock(ref end); - } - - private static void ThrowInvalidOperationException_GetLengthNullBlock() - { - throw new InvalidOperationException("Attempted GetLength of non existent block."); - } - - [MethodImpl(MethodImplOptions.NoInlining)] - public int GetLengthMultiBlock(ref MemoryPoolIterator end) - { - var block = _block; - var index = _index; - var length = 0; - checked - { - while (true) - { - if (block == end._block) - { - return length + end._index - index; - } - else if (block.Next == null) - { - throw new InvalidOperationException("end did not follow iterator"); - } - else - { - length += block.End - index; - block = block.Next; - index = block.Start; - } - } - } - } - - public void CopyFrom(byte[] data) - { - CopyFrom(data, 0, data.Length); - } - - public void CopyFrom(ArraySegment buffer) - { - CopyFrom(buffer.Array, buffer.Offset, buffer.Count); - } - - public void CopyFrom(byte[] data, int offset, int count) - { - var block = _block; - if (block == null) - { - return; - } - - Debug.Assert(block.Next == null); - Debug.Assert(block.End == _index); - - var pool = block.Pool; - var blockIndex = _index; - - var bufferIndex = offset; - var remaining = count; - var bytesLeftInBlock = block.Data.Offset + block.Data.Count - blockIndex; - - while (remaining > 0) - { - if (bytesLeftInBlock == 0) - { - var nextBlock = pool.Lease(); - block.End = blockIndex; - Volatile.Write(ref block.Next, nextBlock); - block = nextBlock; - - blockIndex = block.Data.Offset; - bytesLeftInBlock = block.Data.Count; - } - - var bytesToCopy = remaining < bytesLeftInBlock ? remaining : bytesLeftInBlock; - - Buffer.BlockCopy(data, bufferIndex, block.Array, blockIndex, bytesToCopy); - - blockIndex += bytesToCopy; - bufferIndex += bytesToCopy; - remaining -= bytesToCopy; - bytesLeftInBlock -= bytesToCopy; - } - - block.End = blockIndex; - _block = block; - _index = blockIndex; - } - - public unsafe void CopyFromAscii(string data) - { - var block = _block; - if (block == null) - { - return; - } - - Debug.Assert(block.Next == null); - Debug.Assert(block.End == _index); - - var pool = block.Pool; - var blockIndex = _index; - var length = data.Length; - - var bytesLeftInBlock = block.Data.Offset + block.Data.Count - blockIndex; - var bytesLeftInBlockMinusSpan = bytesLeftInBlock - 3; - - fixed (char* pData = data) - { - var input = pData; - var inputEnd = pData + length; - var inputEndMinusSpan = inputEnd - 3; - - while (input < inputEnd) - { - if (bytesLeftInBlock == 0) - { - var nextBlock = pool.Lease(); - block.End = blockIndex; - Volatile.Write(ref block.Next, nextBlock); - block = nextBlock; - - blockIndex = block.Data.Offset; - bytesLeftInBlock = block.Data.Count; - bytesLeftInBlockMinusSpan = bytesLeftInBlock - 3; - } - - var output = (block.DataFixedPtr + block.End); - var copied = 0; - for (; input < inputEndMinusSpan && copied < bytesLeftInBlockMinusSpan; copied += 4) - { - *(output) = (byte)*(input); - *(output + 1) = (byte)*(input + 1); - *(output + 2) = (byte)*(input + 2); - *(output + 3) = (byte)*(input + 3); - output += 4; - input += 4; - } - for (; input < inputEnd && copied < bytesLeftInBlock; copied++) - { - *(output++) = (byte)*(input++); - } - - blockIndex += copied; - bytesLeftInBlockMinusSpan -= copied; - bytesLeftInBlock -= copied; - } - } - - block.End = blockIndex; - _block = block; - _index = blockIndex; - } - - private static byte[] NumericBytesScratch => _numericBytesScratch ?? CreateNumericBytesScratch(); - - [MethodImpl(MethodImplOptions.NoInlining)] - private static byte[] CreateNumericBytesScratch() - { - var bytes = new byte[_maxULongByteLength]; - _numericBytesScratch = bytes; - return bytes; - } - - public unsafe void CopyFromNumeric(ulong value) - { - const byte AsciiDigitStart = (byte)'0'; - - var block = _block; - if (block == null) - { - return; - } - - var blockIndex = _index; - var bytesLeftInBlock = block.Data.Offset + block.Data.Count - blockIndex; - var start = block.DataFixedPtr + blockIndex; - - if (value < 10) - { - if (bytesLeftInBlock < 1) - { - CopyFromNumericOverflow(value); - return; - } - _index = blockIndex + 1; - block.End = blockIndex + 1; - - *(start) = (byte)(((uint)value) + AsciiDigitStart); - } - else if (value < 100) - { - if (bytesLeftInBlock < 2) - { - CopyFromNumericOverflow(value); - return; - } - _index = blockIndex + 2; - block.End = blockIndex + 2; - - var val = (uint)value; - var tens = (byte)((val * 205u) >> 11); // div10, valid to 1028 - - *(start) = (byte)(tens + AsciiDigitStart); - *(start + 1) = (byte)(val - (tens * 10) + AsciiDigitStart); - } - else if (value < 1000) - { - if (bytesLeftInBlock < 3) - { - CopyFromNumericOverflow(value); - return; - } - _index = blockIndex + 3; - block.End = blockIndex + 3; - - var val = (uint)value; - var digit0 = (byte)((val * 41u) >> 12); // div100, valid to 1098 - var digits01 = (byte)((val * 205u) >> 11); // div10, valid to 1028 - - *(start) = (byte)(digit0 + AsciiDigitStart); - *(start + 1) = (byte)(digits01 - (digit0 * 10) + AsciiDigitStart); - *(start + 2) = (byte)(val - (digits01 * 10) + AsciiDigitStart); - } - else - { - CopyFromNumericOverflow(value); - } - } - - [MethodImpl(MethodImplOptions.NoInlining)] - private unsafe void CopyFromNumericOverflow(ulong value) - { - const byte AsciiDigitStart = (byte)'0'; - - var position = _maxULongByteLength; - var byteBuffer = NumericBytesScratch; - do - { - // Consider using Math.DivRem() if available - var quotient = value / 10; - byteBuffer[--position] = (byte)(AsciiDigitStart + (value - quotient * 10)); // 0x30 = '0' - value = quotient; - } - while (value != 0); - - CopyFrom(byteBuffer, position, _maxULongByteLength - position); - } - } -} diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolSlab.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolSlab.cs deleted file mode 100644 index 709a463789..0000000000 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolSlab.cs +++ /dev/null @@ -1,96 +0,0 @@ -using System; -using System.Runtime.InteropServices; - -namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure -{ - /// - /// Slab tracking object used by the byte buffer memory pool. A slab is a large allocation which is divided into smaller blocks. The - /// individual blocks are then treated as independent array segments. - /// - public class MemoryPoolSlab : IDisposable - { - /// - /// This handle pins the managed array in memory until the slab is disposed. This prevents it from being - /// relocated and enables any subsections of the array to be used as native memory pointers to P/Invoked API calls. - /// - private GCHandle _gcHandle; - - /// - /// The managed memory allocated in the large object heap. - /// - public byte[] Array; - - /// - /// The native memory pointer of the pinned Array. All block native addresses are pointers into the memory - /// ranging from ArrayPtr to ArrayPtr + Array.Length - /// - public IntPtr ArrayPtr; - - /// - /// True as long as the blocks from this slab are to be considered returnable to the pool. In order to shrink the - /// memory pool size an entire slab must be removed. That is done by (1) setting IsActive to false and removing the - /// slab from the pool's _slabs collection, (2) as each block currently in use is Return()ed to the pool it will - /// be allowed to be garbage collected rather than re-pooled, and (3) when all block tracking objects are garbage - /// collected and the slab is no longer references the slab will be garbage collected and the memory unpinned will - /// be unpinned by the slab's Dispose. - /// - public bool IsActive; - - /// - /// Part of the IDisposable implementation - /// - private bool _disposedValue = false; // To detect redundant calls - - public static MemoryPoolSlab Create(int length) - { - // allocate and pin requested memory length - var array = new byte[length]; - var gcHandle = GCHandle.Alloc(array, GCHandleType.Pinned); - - // allocate and return slab tracking object - return new MemoryPoolSlab - { - Array = array, - _gcHandle = gcHandle, - ArrayPtr = gcHandle.AddrOfPinnedObject(), - IsActive = true, - }; - } - - protected virtual void Dispose(bool disposing) - { - if (!_disposedValue) - { - _disposedValue = true; - - if (disposing) - { - // N/A: dispose managed state (managed objects). - } - - // free unmanaged resources (unmanaged objects) and override a finalizer below. - IsActive = false; - _gcHandle.Free(); - - // set large fields to null. - Array = null; - } - } - - // override a finalizer only if Dispose(bool disposing) above has code to free unmanaged resources. - ~MemoryPoolSlab() - { - // Do not change this code. Put cleanup code in Dispose(bool disposing) above. - Dispose(false); - } - - // This code added to correctly implement the disposable pattern. - public void Dispose() - { - // Do not change this code. Put cleanup code in Dispose(bool disposing) above. - Dispose(true); - // uncomment the following line if the finalizer is overridden above. - GC.SuppressFinalize(this); - } - } -} diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/UvWriteReq.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/UvWriteReq.cs index 93a06519a0..2d9ddccf2b 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/UvWriteReq.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/UvWriteReq.cs @@ -2,7 +2,10 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Buffers; using System.Collections.Generic; +using System.Diagnostics; +using System.IO.Pipelines; using System.Runtime.InteropServices; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.Extensions.Logging; @@ -14,7 +17,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking /// public class UvWriteReq : UvRequest { - private readonly static Libuv.uv_write_cb _uv_write_cb = (IntPtr ptr, int status) => UvWriteCb(ptr, status); + private static readonly Libuv.uv_write_cb _uv_write_cb = (IntPtr ptr, int status) => UvWriteCb(ptr, status); private IntPtr _bufs; @@ -22,7 +25,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking private object _state; private const int BUFFER_COUNT = 4; + private LibuvAwaitable _awaitable = new LibuvAwaitable(); private List _pins = new List(BUFFER_COUNT + 1); + private List _handles = new List(BUFFER_COUNT + 1); public UvWriteReq(IKestrelTrace logger) : base(logger) { @@ -39,11 +44,21 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking _bufs = handle + requestSize; } - public unsafe void Write( + public LibuvAwaitable WriteAsync(UvStreamHandle handle, ReadableBuffer buffer) + { + Write(handle, buffer, LibuvAwaitable.Callback, _awaitable); + return _awaitable; + } + + public LibuvAwaitable WriteAsync(UvStreamHandle handle, ArraySegment> bufs) + { + Write(handle, bufs, LibuvAwaitable.Callback, _awaitable); + return _awaitable; + } + + private unsafe void Write( UvStreamHandle handle, - MemoryPoolIterator start, - MemoryPoolIterator end, - int nBuffers, + ReadableBuffer buffer, Action callback, object state) { @@ -52,6 +67,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking // add GCHandle to keeps this SafeHandle alive while request processing _pins.Add(GCHandle.Alloc(this, GCHandleType.Normal)); + var nBuffers = 0; + foreach (var _ in buffer) + { + nBuffers++; + } + var pBuffers = (Libuv.uv_buf_t*)_bufs; if (nBuffers > BUFFER_COUNT) { @@ -61,19 +82,19 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking _pins.Add(gcHandle); pBuffers = (Libuv.uv_buf_t*)gcHandle.AddrOfPinnedObject(); } - - var block = start.Block; - for (var index = 0; index < nBuffers; index++) + var index = 0; + foreach (var memory in buffer) { - var blockStart = block == start.Block ? start.Index : block.Data.Offset; - var blockEnd = block == end.Block ? end.Index : block.Data.Offset + block.Data.Count; + // REVIEW: This isn't necessary for our default pool since the memory is + // already pinned but it also makes tests pass + var memoryHandle = memory.Pin(); + _handles.Add(memoryHandle); // create and pin each segment being written pBuffers[index] = Libuv.buf_init( - block.DataArrayPtr + blockStart, - blockEnd - blockStart); - - block = block.Next; + (IntPtr)memoryHandle.PinnedPointer, + memory.Length); + index++; } _callback = callback; @@ -89,7 +110,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking } } - public void Write( + private void Write( UvStreamHandle handle, ArraySegment> bufs, Action callback, @@ -170,7 +191,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking { pin.Free(); } + + foreach (var handle in req._handles) + { + handle.Free(); + } + req._pins.Clear(); + req._handles.Clear(); } private static void UvWriteCb(IntPtr ptr, int status) diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs index e027de1e57..2fafb67084 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs @@ -455,11 +455,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests .Setup(trace => trace.ConnectionHeadResponseBodyWrite(It.IsAny(), response.Length)) .Callback((connectionId, count) => logTcs.SetResult(null)); - using (var server = new TestServer(async httpContext => - { - await httpContext.Response.WriteAsync(response); - await httpContext.Response.Body.FlushAsync(); - }, new TestServiceContext { Log = mockKestrelTrace.Object })) + using (var server = new TestServer(async httpContext => + { + await httpContext.Response.WriteAsync(response); + await httpContext.Response.Body.FlushAsync(); + }, new TestServiceContext { Log = mockKestrelTrace.Object })) { using (var connection = server.CreateConnection()) { @@ -504,19 +504,24 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests "GET / HTTP/1.1", "", ""); - await connection.ReceiveEnd( + await connection.Receive( $"HTTP/1.1 200 OK", $"Date: {server.Context.DateHeaderValue}", "Content-Length: 11", "", "hello,"); + + await connection.WaitForConnectionClose(); } } + var logMessage = Assert.Single(testLogger.Messages, message => message.LogLevel == LogLevel.Error); + Assert.Equal( $"Response Content-Length mismatch: too many bytes written (12 of 11).", logMessage.Exception.Message); + } [Fact] diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/ResponseHeadersBenchmark.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/ResponseHeadersBenchmark.cs index b576735168..f5dab5e3e7 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/ResponseHeadersBenchmark.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/ResponseHeadersBenchmark.cs @@ -1,14 +1,13 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using BenchmarkDotNet.Attributes; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; -using Microsoft.AspNetCore.Testing; -using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Http.Internal; using System.Runtime.CompilerServices; using System.Text; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; +using BenchmarkDotNet.Attributes; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Http.Internal; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; +using Microsoft.AspNetCore.Testing; namespace Microsoft.AspNetCore.Server.Kestrel.Performance { @@ -19,7 +18,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance private static readonly byte[] _bytesServer = Encoding.ASCII.GetBytes("\r\nServer: Kestrel"); private static readonly DateHeaderValueManager _dateHeaderValueManager = new DateHeaderValueManager(); - private static readonly MemoryPool _memoryPool = new MemoryPool(); private FrameResponseHeaders _responseHeadersDirect; private HttpResponse _response; @@ -49,19 +47,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance } } - [Benchmark(OperationsPerInvoke = InnerLoopCount)] - public void OutputHeaders() - { - for (var i = 0; i < InnerLoopCount; i++) - { - var block = _memoryPool.Lease(); - var iter = new MemoryPoolIterator(block); - _responseHeadersDirect.CopyTo(ref iter); - - ReturnBlocks(block); - } - } - [MethodImpl(MethodImplOptions.NoInlining)] private void ContentLengthNumeric(int count) { @@ -168,6 +153,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance public void Setup() { var connectionContext = new MockConnection(new KestrelServerOptions()); + connectionContext.ListenerContext.ServiceContext.HttpParserFactory = f => new KestrelHttpParser(f.ConnectionContext.ListenerContext.ServiceContext.Log); var frame = new Frame(application: null, context: connectionContext); frame.Reset(); frame.InitializeHeaders(); @@ -194,16 +180,5 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance break; } } - - private static void ReturnBlocks(MemoryPoolBlock block) - { - while (block != null) - { - var returningBlock = block; - block = returningBlock.Next; - - returningBlock.Pool.Return(returningBlock); - } - } } } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedRequestTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedRequestTests.cs index 29ea2ba050..f387562c68 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedRequestTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedRequestTests.cs @@ -9,7 +9,6 @@ using System.Text; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Server.Kestrel; -using Microsoft.AspNetCore.Server.KestrelTests.TestHelpers; using Microsoft.AspNetCore.Testing; using Microsoft.Extensions.Internal; using Xunit; diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolBlockTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolBlockTests.cs deleted file mode 100644 index 2213f81f07..0000000000 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolBlockTests.cs +++ /dev/null @@ -1,133 +0,0 @@ -using System; -using System.Linq; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; -using System.Numerics; -using Xunit; - -namespace Microsoft.AspNetCore.Server.KestrelTests -{ - public class MemoryPoolBlockTests - { - - [Fact] - public void GetLengthBetweenIteratorsWorks() - { - using (var pool = new MemoryPool()) - { - var block = pool.Lease(); - block.End += 256; - TestAllLengths(block, 256); - pool.Return(block); - block = null; - - for (var fragment = 0; fragment < 256; fragment += 4) - { - var next = block; - block = pool.Lease(); - block.Next = next; - block.End += 4; - } - - TestAllLengths(block, 256); - - while(block != null) - { - var next = block.Next; - pool.Return(block); - block = next; - } - } - } - - private void TestAllLengths(MemoryPoolBlock block, int lengths) - { - for (var firstIndex = 0; firstIndex <= lengths; ++firstIndex) - { - for (var lastIndex = firstIndex; lastIndex <= lengths; ++lastIndex) - { - var first = block.GetIterator().Add(firstIndex); - var last = block.GetIterator().Add(lastIndex); - Assert.Equal(firstIndex, block.GetIterator().GetLength(first)); - Assert.Equal(lastIndex, block.GetIterator().GetLength(last)); - Assert.Equal(lastIndex - firstIndex, first.GetLength(last)); - } - } - } - - [Fact] - public void AddDoesNotAdvanceAtEndOfCurrentBlock() - { - using (var pool = new MemoryPool()) - { - var block1 = pool.Lease(); - var block2 = block1.Next = pool.Lease(); - - block1.End += 100; - block2.End += 200; - - var iter0 = block1.GetIterator(); - var iter100 = iter0.Add(100); - - var iter200a = iter0.Add(200); - var iter200b = iter100.Add(100); - - var iter300a = iter0.Add(300); - var iter300b = iter100.Add(200); - var iter300c = iter200a.Add(100); - - var iter300a2 = iter300a.Add(1); - var iter300b2 = iter300b.Add(1); - var iter300c2 = iter300c.Add(1); - - AssertIterator(iter0, block1, block1.Start); - AssertIterator(iter100, block1, block1.End); - AssertIterator(iter200a, block2, block2.Start+100); - AssertIterator(iter200b, block2, block2.Start + 100); - AssertIterator(iter300a, block2, block2.End); - AssertIterator(iter300b, block2, block2.End); - AssertIterator(iter300c, block2, block2.End); - AssertIterator(iter300a2, block2, block2.End); - AssertIterator(iter300b2, block2, block2.End); - AssertIterator(iter300c2, block2, block2.End); - - pool.Return(block1); - pool.Return(block2); - } - } - - [Fact] - public void IsEndCorrectlyTraversesBlocks() - { - using (var pool = new MemoryPool()) - { - var block1 = pool.Lease(); - var block2 = block1.Next = pool.Lease(); - var block3 = block2.Next = pool.Lease(); - var block4 = block3.Next = pool.Lease(); - - // There is no data in block2 or block4, so IsEnd should be true after 256 bytes are read. - block1.End += 128; - block3.End += 128; - - var iterStart = block1.GetIterator(); - var iterMid = iterStart.Add(128); - var iterEnd = iterMid.Add(128); - - Assert.False(iterStart.IsEnd); - Assert.False(iterMid.IsEnd); - Assert.True(iterEnd.IsEnd); - - pool.Return(block1); - pool.Return(block2); - pool.Return(block3); - pool.Return(block4); - } - } - - private void AssertIterator(MemoryPoolIterator iter, MemoryPoolBlock block, int index) - { - Assert.Same(block, iter.Block); - Assert.Equal(index, iter.Index); - } - } -} diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolExtensions.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolExtensions.cs deleted file mode 100644 index 1d62dd2793..0000000000 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolExtensions.cs +++ /dev/null @@ -1,16 +0,0 @@ -using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; - -namespace Microsoft.AspNetCore.Server.KestrelTests -{ - public static class MemoryPoolExtensions - { - public static MemoryPoolIterator Add(this MemoryPoolIterator iterator, int count) - { - for (int i = 0; i < count; i++) - { - iterator.Take(); - } - return iterator; - } - } -} diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolIteratorTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolIteratorTests.cs deleted file mode 100644 index 4643b5236b..0000000000 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolIteratorTests.cs +++ /dev/null @@ -1,406 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using System.Collections.Generic; -using System.IO.Pipelines; -using System.Linq; -using System.Numerics; -using System.Text; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; -using Xunit; -using MemoryPool = Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPool; -using MemoryPoolBlock = Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolBlock; - -namespace Microsoft.AspNetCore.Server.KestrelTests -{ - public class MemoryPoolIteratorTests : IDisposable - { - private readonly MemoryPool _pool; - - public MemoryPoolIteratorTests() - { - _pool = new MemoryPool(); - } - - public void Dispose() - { - _pool.Dispose(); - } - - [Fact] - public void Put() - { - var blocks = new MemoryPoolBlock[4]; - for (var i = 0; i < 4; ++i) - { - blocks[i] = _pool.Lease(); - blocks[i].End += 16; - - for (var j = 0; j < blocks.Length; ++j) - { - blocks[i].Array[blocks[i].Start + j] = 0x00; - } - - if (i != 0) - { - blocks[i - 1].Next = blocks[i]; - } - } - - // put FF at first block's head - var head = blocks[0].GetIterator(); - Assert.True(head.Put(0xFF)); - - // data is put at correct position - Assert.Equal(0xFF, blocks[0].Array[blocks[0].Start]); - Assert.Equal(0x00, blocks[0].Array[blocks[0].Start + 1]); - - // iterator is moved to next byte after put - Assert.Equal(1, head.Index - blocks[0].Start); - - for (var i = 0; i < 14; ++i) - { - // move itr to the end of the block 0 - head.Take(); - } - - // write to the end of block 0 - Assert.True(head.Put(0xFE)); - Assert.Equal(0xFE, blocks[0].Array[blocks[0].End - 1]); - Assert.Equal(0x00, blocks[1].Array[blocks[1].Start]); - - // put data across the block link - Assert.True(head.Put(0xFD)); - Assert.Equal(0xFD, blocks[1].Array[blocks[1].Start]); - Assert.Equal(0x00, blocks[1].Array[blocks[1].Start + 1]); - - // paint every block - head = blocks[0].GetIterator(); - for (var i = 0; i < 64; ++i) - { - Assert.True(head.Put((byte)i), $"Fail to put data at {i}."); - } - - // Can't put anything by the end - Assert.ThrowsAny(() => head.Put(0xFF)); - - for (var i = 0; i < 4; ++i) - { - _pool.Return(blocks[i]); - } - } - - [Fact] - public async Task PeekArraySegment() - { - using (var pipeFactory = new PipeFactory()) - { - // Arrange - var pipe = pipeFactory.Create(); - var buffer = pipe.Writer.Alloc(); - buffer.Append(ReadableBuffer.Create(new byte[] { 0, 1, 2, 3, 4, 5, 6, 7 })); - await buffer.FlushAsync(); - - // Act - var result = await pipe.Reader.PeekAsync(); - - // Assert - Assert.Equal(new byte[] {0, 1, 2, 3, 4, 5, 6, 7}, result); - - pipe.Writer.Complete(); - pipe.Reader.Complete(); - } - } - - [Fact] - public async Task PeekArraySegmentAtEndOfDataReturnsDefaultArraySegment() - { - using (var pipeFactory = new PipeFactory()) - { - // Arrange - var pipe = pipeFactory.Create(); - pipe.Writer.Complete(); - - // Act - var result = await pipe.Reader.PeekAsync(); - - // Assert - // Assert.Equals doesn't work since xunit tries to access the underlying array. - Assert.True(default(ArraySegment).Equals(result)); - - pipe.Reader.Complete(); - } - } - - [Fact] - public async Task PeekArraySegmentAtBlockBoundary() - { - using (var pipeFactory = new PipeFactory()) - { - var pipe = pipeFactory.Create(); - var buffer = pipe.Writer.Alloc(); - buffer.Append(ReadableBuffer.Create(new byte[] { 0, 1, 2, 3, 4, 5, 6, 7 })); - buffer.Append(ReadableBuffer.Create(new byte[] { 8, 9, 10, 11, 12, 13, 14, 15 })); - await buffer.FlushAsync(); - - // Act - var result = await pipe.Reader.PeekAsync(); - - // Assert - Assert.Equal(new byte[] { 0, 1, 2, 3, 4, 5, 6, 7 }, result); - - // Act - // Advance past the data in the first block - var readResult = pipe.Reader.ReadAsync().GetAwaiter().GetResult(); - pipe.Reader.Advance(readResult.Buffer.Move(readResult.Buffer.Start, 8)); - result = await pipe.Reader.PeekAsync(); - - // Assert - Assert.Equal(new byte[] { 8, 9, 10, 11, 12, 13, 14, 15 }, result); - - pipe.Writer.Complete(); - pipe.Reader.Complete(); - } - - } - - - [Fact] - public void EmptyIteratorBehaviourIsValid() - { - const byte byteCr = (byte)'\n'; - var end = default(MemoryPoolIterator); - - Assert.True(default(MemoryPoolIterator).IsDefault); - Assert.True(default(MemoryPoolIterator).IsEnd); - - default(MemoryPoolIterator).CopyFrom(default(ArraySegment)); - default(MemoryPoolIterator).CopyFromAscii(""); - Assert.ThrowsAny(() => default(MemoryPoolIterator).Put(byteCr)); - Assert.ThrowsAny(() => default(MemoryPoolIterator).GetLength(end)); - } - - [Theory] - [InlineData("a", "a", 1)] - [InlineData("ab", "a...", 1)] - [InlineData("abcde", "abcde", 5)] - [InlineData("abcde", "abcd...", 4)] - [InlineData("abcde", "abcde", 6)] - public void TestGetAsciiStringEscaped(string input, string expected, int maxChars) - { - // Arrange - var buffer = new Span(Encoding.ASCII.GetBytes(input)); - - // Act - var result = buffer.GetAsciiStringEscaped(maxChars); - - // Assert - Assert.Equal(expected, result); - } - - [Fact] - public void CorrectContentLengthsOutput() - { - using (var pool = new MemoryPool()) - { - var block = pool.Lease(); - try - { - for (var i = 0u; i <= 9u; i++) - { - block.Reset(); - var iter = new MemoryPoolIterator(block); - iter.CopyFromNumeric(i); - - Assert.Equal(block.Array[block.Start], (byte)(i + '0')); - Assert.Equal(block.End, block.Start + 1); - Assert.Equal(iter.Index, block.End); - } - for (var i = 10u; i <= 99u; i++) - { - block.Reset(); - var iter = new MemoryPoolIterator(block); - iter.CopyFromNumeric(i); - - Assert.Equal(block.Array[block.Start], (byte)((i / 10) + '0')); - Assert.Equal(block.Array[block.Start + 1], (byte)((i % 10) + '0')); - - Assert.Equal(block.End, block.Start + 2); - Assert.Equal(iter.Index, block.End); - } - for (var i = 100u; i <= 999u; i++) - { - block.Reset(); - var iter = new MemoryPoolIterator(block); - iter.CopyFromNumeric(i); - - Assert.Equal(block.Array[block.Start], (byte)((i / 100) + '0')); - Assert.Equal(block.Array[block.Start + 1], (byte)(((i % 100) / 10) + '0')); - Assert.Equal(block.Array[block.Start + 2], (byte)((i % 10) + '0')); - - Assert.Equal(block.End, block.Start + 3); - Assert.Equal(iter.Index, block.End); - } - for (var i = 1000u; i <= 9999u; i++) - { - block.Reset(); - var iter = new MemoryPoolIterator(block); - iter.CopyFromNumeric(i); - - Assert.Equal(block.Array[block.Start], (byte)((i / 1000) + '0')); - Assert.Equal(block.Array[block.Start + 1], (byte)(((i % 1000) / 100) + '0')); - Assert.Equal(block.Array[block.Start + 2], (byte)(((i % 100) / 10) + '0')); - Assert.Equal(block.Array[block.Start + 3], (byte)((i % 10) + '0')); - - Assert.Equal(block.End, block.Start + 4); - Assert.Equal(iter.Index, block.End); - } - { - block.Reset(); - var iter = new MemoryPoolIterator(block); - iter.CopyFromNumeric(ulong.MaxValue); - - var outputBytes = Encoding.ASCII.GetBytes(ulong.MaxValue.ToString("0")); - - for (var i = 0; i < outputBytes.Length; i++) - { - Assert.Equal(block.Array[block.Start + i], outputBytes[i]); - } - - Assert.Equal(block.End, block.Start + outputBytes.Length); - Assert.Equal(iter.Index, block.End); - } - } - finally - { - pool.Return(block); - } - } - } - - public static IEnumerable SeekByteLimitData - { - get - { - var vectorSpan = Vector.Count; - - // string input, char seek, int limit, int expectedBytesScanned, int expectedReturnValue - var data = new List(); - - // Non-vector inputs - - data.Add(new object[] { "hello, world", 'h', 12, 1, 'h' }); - data.Add(new object[] { "hello, world", ' ', 12, 7, ' ' }); - data.Add(new object[] { "hello, world", 'd', 12, 12, 'd' }); - data.Add(new object[] { "hello, world", '!', 12, 12, -1 }); - data.Add(new object[] { "hello, world", 'h', 13, 1, 'h' }); - data.Add(new object[] { "hello, world", ' ', 13, 7, ' ' }); - data.Add(new object[] { "hello, world", 'd', 13, 12, 'd' }); - data.Add(new object[] { "hello, world", '!', 13, 12, -1 }); - data.Add(new object[] { "hello, world", 'h', 5, 1, 'h' }); - data.Add(new object[] { "hello, world", 'o', 5, 5, 'o' }); - data.Add(new object[] { "hello, world", ',', 5, 5, -1 }); - data.Add(new object[] { "hello, world", 'd', 5, 5, -1 }); - data.Add(new object[] { "abba", 'a', 4, 1, 'a' }); - data.Add(new object[] { "abba", 'b', 4, 2, 'b' }); - - // Vector inputs - - // Single vector, no seek char in input, expect failure - data.Add(new object[] { new string('a', vectorSpan), 'b', vectorSpan, vectorSpan, -1 }); - // Two vectors, no seek char in input, expect failure - data.Add(new object[] { new string('a', vectorSpan * 2), 'b', vectorSpan * 2, vectorSpan * 2, -1 }); - // Two vectors plus non vector length (thus hitting slow path too), no seek char in input, expect failure - data.Add(new object[] { new string('a', vectorSpan * 2 + vectorSpan / 2), 'b', vectorSpan * 2 + vectorSpan / 2, vectorSpan * 2 + vectorSpan / 2, -1 }); - - // For each input length from 1/2 to 3 1/2 vector spans in 1/2 vector span increments... - for (var length = vectorSpan / 2; length <= vectorSpan * 3 + vectorSpan / 2; length += vectorSpan / 2) - { - // ...place the seek char at vector and input boundaries... - for (var i = Math.Min(vectorSpan - 1, length - 1); i < length; i += ((i + 1) % vectorSpan == 0) ? 1 : Math.Min(i + (vectorSpan - 1), length - 1)) - { - var input = new StringBuilder(new string('a', length)); - input[i] = 'b'; - - // ...and check with a seek byte limit before, at, and past the seek char position... - for (var limitOffset = -1; limitOffset <= 1; limitOffset++) - { - var limit = (i + 1) + limitOffset; - - if (limit >= i + 1) - { - // ...that Seek() succeeds when the seek char is within that limit... - data.Add(new object[] { input.ToString(), 'b', limit, i + 1, 'b' }); - } - else - { - // ...and fails when it's not. - data.Add(new object[] { input.ToString(), 'b', limit, Math.Min(length, limit), -1 }); - } - } - } - } - - return data; - } - } - - public static IEnumerable SeekIteratorLimitData - { - get - { - var vectorSpan = Vector.Count; - - // string input, char seek, char limitAt, int expectedReturnValue - var data = new List(); - - // Non-vector inputs - - data.Add(new object[] { "hello, world", 'h', 'd', 'h' }); - data.Add(new object[] { "hello, world", ' ', 'd', ' ' }); - data.Add(new object[] { "hello, world", 'd', 'd', 'd' }); - data.Add(new object[] { "hello, world", '!', 'd', -1 }); - data.Add(new object[] { "hello, world", 'h', 'w', 'h' }); - data.Add(new object[] { "hello, world", 'o', 'w', 'o' }); - data.Add(new object[] { "hello, world", 'r', 'w', -1 }); - data.Add(new object[] { "hello, world", 'd', 'w', -1 }); - - // Vector inputs - - // Single vector, no seek char in input, expect failure - data.Add(new object[] { new string('a', vectorSpan), 'b', 'b', -1 }); - // Two vectors, no seek char in input, expect failure - data.Add(new object[] { new string('a', vectorSpan * 2), 'b', 'b', -1 }); - // Two vectors plus non vector length (thus hitting slow path too), no seek char in input, expect failure - data.Add(new object[] { new string('a', vectorSpan * 2 + vectorSpan / 2), 'b', 'b', -1 }); - - // For each input length from 1/2 to 3 1/2 vector spans in 1/2 vector span increments... - for (var length = vectorSpan / 2; length <= vectorSpan * 3 + vectorSpan / 2; length += vectorSpan / 2) - { - // ...place the seek char at vector and input boundaries... - for (var i = Math.Min(vectorSpan - 1, length - 1); i < length; i += ((i + 1) % vectorSpan == 0) ? 1 : Math.Min(i + (vectorSpan - 1), length - 1)) - { - var input = new StringBuilder(new string('a', length)); - input[i] = 'b'; - - // ...along with sentinel characters to seek the limit iterator to... - input[i - 1] = 'A'; - if (i < length - 1) input[i + 1] = 'B'; - - // ...and check that Seek() succeeds with a limit iterator at or past the seek char position... - data.Add(new object[] { input.ToString(), 'b', 'b', 'b' }); - if (i < length - 1) data.Add(new object[] { input.ToString(), 'b', 'B', 'b' }); - - // ...and fails with a limit iterator before the seek char position. - data.Add(new object[] { input.ToString(), 'b', 'A', -1 }); - } - } - - return data; - } - } - } -} \ No newline at end of file diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/MultipleLoopTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/MultipleLoopTests.cs index 687cf6577e..d34e0c02a5 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/MultipleLoopTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/MultipleLoopTests.cs @@ -2,11 +2,11 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.IO.Pipelines; using System.Net; using System.Net.Sockets; using System.Runtime.InteropServices; using System.Threading; -using Microsoft.AspNetCore.Server.Kestrel; using Microsoft.AspNetCore.Server.Kestrel.Internal; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; @@ -55,7 +55,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests loop.Init(_uv); serverListenPipe.Init(loop, (a, b) => { }, false); serverListenPipe.Bind(pipeName); - serverListenPipe.Listen(128, (backlog, status, error, state) => + serverListenPipe.Listen(128, async (backlog, status, error, state) => { var serverConnectionPipe = new UvPipeHandle(_logger); serverConnectionPipe.Init(loop, (a, b) => { }, true); @@ -72,27 +72,15 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var writeRequest = new UvWriteReq(new KestrelTrace(new TestKestrelTrace())); writeRequest.Init(loop); - - var pool = new MemoryPool(); - var block = pool.Lease(); - block.GetIterator().CopyFrom(new ArraySegment(new byte[] { 1, 2, 3, 4 })); - - var start = new MemoryPoolIterator(block, 0); - var end = new MemoryPoolIterator(block, block.Data.Count); - writeRequest.Write( + + await writeRequest.WriteAsync( serverConnectionPipe, - start, - end, - 1, - (handle, status2, error2, state2) => - { - writeRequest.Dispose(); - serverConnectionPipe.Dispose(); - serverListenPipe.Dispose(); - pool.Return(block); - pool.Dispose(); - }, - null); + ReadableBuffer.Create(new byte[] { 1, 2, 3, 4 })); + + writeRequest.Dispose(); + serverConnectionPipe.Dispose(); + serverListenPipe.Dispose(); + }, null); var worker = new Thread(() => diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/NetworkingTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/NetworkingTests.cs index 90e8fd6cdf..c417007e2c 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/NetworkingTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/NetworkingTests.cs @@ -2,11 +2,11 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.IO.Pipelines; using System.Net; using System.Net.Sockets; using System.Runtime.InteropServices; using System.Threading.Tasks; -using Microsoft.AspNetCore.Server.Kestrel; using Microsoft.AspNetCore.Server.Kestrel.Internal; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; @@ -168,7 +168,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var data = Marshal.AllocCoTaskMem(500); tcp2.ReadStart( (a, b, c) => tcp2.Libuv.buf_init(data, 500), - (__, nread, state2) => + async (__, nread, state2) => { if (nread <= 0) { @@ -179,23 +179,12 @@ namespace Microsoft.AspNetCore.Server.KestrelTests for (var x = 0; x < 2; x++) { var req = new UvWriteReq(new KestrelTrace(new TestKestrelTrace())); - req.Init(loop); var pool = new MemoryPool(); - var block = pool.Lease(); - block.GetIterator().CopyFrom(new ArraySegment(new byte[] { 65, 66, 67, 68, 69 })); - - var start = new MemoryPoolIterator(block, 0); - var end = new MemoryPoolIterator(block, block.Data.Count); - req.Write( + req.Init(loop); + var block = ReadableBuffer.Create(new byte[] { 65, 66, 67, 68, 69 }); + + await req.WriteAsync( tcp2, - start, - end, - 1, - (_1, _2, _3, _4) => - { - pool.Return(block); - pool.Dispose(); - }, - null); + block); } } }, diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/SocketOutputTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/SocketOutputTests.cs index 3bc33f1e55..ba88696ff7 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/SocketOutputTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/SocketOutputTests.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Concurrent; +using System.IO.Pipelines; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel; @@ -47,7 +48,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests }, new KestrelServerOptions { - Limits = { MaxResponseBufferSize = 1024 * 1024 } + Limits = { MaxResponseBufferSize = (1024 * 1024) + 1 } } }; @@ -62,6 +63,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests // Arrange var mockLibuv = new MockLibuv(); using (var kestrelEngine = new KestrelEngine(mockLibuv, new TestServiceContext())) + using (var factory = new PipeFactory()) { var kestrelThread = new KestrelThread(kestrelEngine, maxLoops: 1); kestrelEngine.Threads.Add(kestrelThread); @@ -69,8 +71,15 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var socket = new MockSocket(mockLibuv, kestrelThread.Loop.ThreadId, new TestKestrelTrace()); var trace = new KestrelTrace(new TestKestrelTrace()); - var ltp = new InlineLoggingThreadPool(trace); - var socketOutput = new SocketOutput(kestrelThread, socket, new MockConnection(options), "0", trace, ltp); + var connection = new MockConnection(options); + var pipeOptions = new PipeOptions + { + ReaderScheduler = kestrelThread, + MaximumSizeHigh = options.Limits.MaxResponseBufferSize ?? 0, + MaximumSizeLow = options.Limits.MaxResponseBufferSize ?? 0, + }; + var pipe = factory.Create(pipeOptions); + var socketOutput = new SocketOutput(pipe, kestrelThread, socket, connection, "0", trace); // At least one run of this test should have a MaxResponseBufferSize < 1 MB. var bufferSize = 1024 * 1024; @@ -78,14 +87,12 @@ namespace Microsoft.AspNetCore.Server.KestrelTests // Act var writeTask = socketOutput.WriteAsync(buffer, default(CancellationToken)); - await mockLibuv.OnPostTask; // Assert - Assert.Equal(TaskStatus.RanToCompletion, writeTask.Status); + await writeTask.TimeoutAfter(TimeSpan.FromSeconds(5)); // Cleanup - var cleanupTask = socketOutput.WriteAsync( - default(ArraySegment), default(CancellationToken), socketDisconnect: true); + socketOutput.End(ProduceEndType.SocketDisconnect); } } @@ -105,6 +112,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests }; using (var kestrelEngine = new KestrelEngine(mockLibuv, new TestServiceContext())) + using (var factory = new PipeFactory()) { var kestrelThread = new KestrelThread(kestrelEngine, maxLoops: 1); kestrelEngine.Threads.Add(kestrelThread); @@ -112,9 +120,15 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var socket = new MockSocket(mockLibuv, kestrelThread.Loop.ThreadId, new TestKestrelTrace()); var trace = new KestrelTrace(new TestKestrelTrace()); - var ltp = new InlineLoggingThreadPool(trace); var options = new KestrelServerOptions { Limits = { MaxResponseBufferSize = null } }; - var socketOutput = new SocketOutput(kestrelThread, socket, new MockConnection(options), "0", trace, ltp); + var pipeOptions = new PipeOptions + { + ReaderScheduler = kestrelThread, + MaximumSizeHigh = options.Limits.MaxResponseBufferSize ?? 0, + MaximumSizeLow = options.Limits.MaxResponseBufferSize ?? 0, + }; + var pipe = factory.Create(pipeOptions); + var socketOutput = new SocketOutput(pipe, kestrelThread, socket, new MockConnection(options), "0", trace); // Don't want to allocate anything too huge for perf. This is at least larger than the default buffer. var bufferSize = 1024 * 1024; @@ -124,18 +138,17 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var writeTask = socketOutput.WriteAsync(buffer, default(CancellationToken)); // Assert - Assert.Equal(TaskStatus.RanToCompletion, writeTask.Status); + await writeTask.TimeoutAfter(TimeSpan.FromSeconds(5)); // Cleanup - var cleanupTask = socketOutput.WriteAsync( - default(ArraySegment), default(CancellationToken), socketDisconnect: true); + socketOutput.End(ProduceEndType.SocketDisconnect); // Wait for all writes to complete so the completeQueue isn't modified during enumeration. await mockLibuv.OnPostTask; foreach (var triggerCompleted in completeQueue) { - triggerCompleted(0); + await kestrelThread.PostAsync(cb => cb(0), triggerCompleted); } } } @@ -156,6 +169,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests }; using (var kestrelEngine = new KestrelEngine(mockLibuv, new TestServiceContext())) + using (var factory = new PipeFactory()) { var kestrelThread = new KestrelThread(kestrelEngine, maxLoops: 1); kestrelEngine.Threads.Add(kestrelThread); @@ -163,9 +177,15 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var socket = new MockSocket(mockLibuv, kestrelThread.Loop.ThreadId, new TestKestrelTrace()); var trace = new KestrelTrace(new TestKestrelTrace()); - var ltp = new InlineLoggingThreadPool(trace); var options = new KestrelServerOptions { Limits = { MaxResponseBufferSize = 0 } }; - var socketOutput = new SocketOutput(kestrelThread, socket, new MockConnection(options), "0", trace, ltp); + var pipeOptions = new PipeOptions + { + ReaderScheduler = kestrelThread, + MaximumSizeHigh = 1, + MaximumSizeLow = 1, + }; + var pipe = factory.Create(pipeOptions); + var socketOutput = new SocketOutput(pipe, kestrelThread, socket, new MockConnection(options), "0", trace); var bufferSize = 1; var buffer = new ArraySegment(new byte[bufferSize], 0, bufferSize); @@ -180,23 +200,21 @@ namespace Microsoft.AspNetCore.Server.KestrelTests await mockLibuv.OnPostTask; // Finishing the write should allow the task to complete. - Action triggerNextCompleted; - Assert.True(completeQueue.TryDequeue(out triggerNextCompleted)); - triggerNextCompleted(0); + Assert.True(completeQueue.TryDequeue(out var triggerNextCompleted)); + await kestrelThread.PostAsync(cb => cb(0), triggerNextCompleted); // Assert - Assert.Equal(TaskStatus.RanToCompletion, writeTask.Status); + await writeTask.TimeoutAfter(TimeSpan.FromSeconds(5)); // Cleanup - var cleanupTask = socketOutput.WriteAsync( - default(ArraySegment), default(CancellationToken), socketDisconnect: true); + socketOutput.End(ProduceEndType.SocketDisconnect); // Wait for all writes to complete so the completeQueue isn't modified during enumeration. await mockLibuv.OnPostTask; foreach (var triggerCompleted in completeQueue) { - triggerCompleted(0); + await kestrelThread.PostAsync(cb => cb(0), triggerCompleted); } } } @@ -219,6 +237,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests }; using (var kestrelEngine = new KestrelEngine(mockLibuv, new TestServiceContext())) + using (var factory = new PipeFactory()) { var kestrelThread = new KestrelThread(kestrelEngine, maxLoops: 1); kestrelEngine.Threads.Add(kestrelThread); @@ -226,11 +245,17 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var socket = new MockSocket(mockLibuv, kestrelThread.Loop.ThreadId, new TestKestrelTrace()); var trace = new KestrelTrace(new TestKestrelTrace()); - var ltp = new InlineLoggingThreadPool(trace); var mockConnection = new MockConnection(options); - var socketOutput = new SocketOutput(kestrelThread, socket, mockConnection, "0", trace, ltp); + var pipeOptions = new PipeOptions + { + ReaderScheduler = kestrelThread, + MaximumSizeHigh = options.Limits.MaxResponseBufferSize ?? 0, + MaximumSizeLow = options.Limits.MaxResponseBufferSize ?? 0, + }; + var pipe = factory.Create(pipeOptions); + var socketOutput = new SocketOutput(pipe, kestrelThread, socket, mockConnection, "0", trace); - var bufferSize = maxBytesPreCompleted; + var bufferSize = maxBytesPreCompleted - 1; var buffer = new ArraySegment(new byte[bufferSize], 0, bufferSize); // Act @@ -249,24 +274,21 @@ namespace Microsoft.AspNetCore.Server.KestrelTests Assert.False(writeTask2.IsCompleted); // Act - Action triggerNextCompleted; - Assert.True(completeQueue.TryDequeue(out triggerNextCompleted)); - triggerNextCompleted(0); + Assert.True(completeQueue.TryDequeue(out var triggerNextCompleted)); + await kestrelThread.PostAsync(cb => cb(0), triggerNextCompleted); - // Assert // Finishing the first write should allow the second write to pre-complete. - Assert.Equal(TaskStatus.RanToCompletion, writeTask2.Status); + await writeTask2.TimeoutAfter(TimeSpan.FromSeconds(5)); // Cleanup - var cleanupTask = socketOutput.WriteAsync( - default(ArraySegment), default(CancellationToken), socketDisconnect: true); + socketOutput.End(ProduceEndType.SocketDisconnect); // Wait for all writes to complete so the completeQueue isn't modified during enumeration. await mockLibuv.OnPostTask; foreach (var triggerCompleted in completeQueue) { - triggerCompleted(0); + await kestrelThread.PostAsync(cb => cb(0), triggerCompleted); } } } @@ -277,7 +299,6 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { var maxBytesPreCompleted = (int)options.Limits.MaxResponseBufferSize.Value; var completeQueue = new ConcurrentQueue>(); - var writeRequested = false; // Arrange var mockLibuv = new MockLibuv @@ -285,12 +306,12 @@ namespace Microsoft.AspNetCore.Server.KestrelTests OnWrite = (socket, buffers, triggerCompleted) => { completeQueue.Enqueue(triggerCompleted); - writeRequested = true; return 0; } }; using (var kestrelEngine = new KestrelEngine(mockLibuv, new TestServiceContext())) + using (var factory = new PipeFactory()) { var kestrelThread = new KestrelThread(kestrelEngine, maxLoops: 1); kestrelEngine.Threads.Add(kestrelThread); @@ -298,9 +319,15 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var socket = new MockSocket(mockLibuv, kestrelThread.Loop.ThreadId, new TestKestrelTrace()); var trace = new KestrelTrace(new TestKestrelTrace()); - var ltp = new InlineLoggingThreadPool(trace); var mockConnection = new MockConnection(options); - var socketOutput = new SocketOutput(kestrelThread, socket, mockConnection, "0", trace, ltp); + var pipeOptions = new PipeOptions + { + ReaderScheduler = kestrelThread, + MaximumSizeHigh = options.Limits.MaxResponseBufferSize ?? 0, + MaximumSizeLow = options.Limits.MaxResponseBufferSize ?? 0, + }; + var pipe = factory.Create(pipeOptions); + var socketOutput = new SocketOutput(pipe, kestrelThread, socket, mockConnection, "0", trace); var bufferSize = maxBytesPreCompleted / 2; var data = new byte[bufferSize]; @@ -313,163 +340,35 @@ namespace Microsoft.AspNetCore.Server.KestrelTests // The first write should pre-complete since it is <= _maxBytesPreCompleted. Assert.Equal(TaskStatus.RanToCompletion, writeTask1.Status); await mockLibuv.OnPostTask; - Assert.True(writeRequested); - writeRequested = false; + Assert.NotEmpty(completeQueue); // Add more bytes to the write-behind buffer to prevent the next write from - var iter = socketOutput.ProducingStart(); - iter.CopyFrom(halfWriteBehindBuffer); - socketOutput.ProducingComplete(iter); + var writableBuffer = socketOutput.Alloc(); + writableBuffer.Write(halfWriteBehindBuffer); + writableBuffer.Commit(); // Act var writeTask2 = socketOutput.WriteAsync(halfWriteBehindBuffer, default(CancellationToken)); - - // Assert - // Too many bytes are already pre-completed for the fourth write to pre-complete. - await mockLibuv.OnPostTask; - Assert.True(writeRequested); Assert.False(writeTask2.IsCompleted); - // 2 calls have been made to uv_write - Assert.Equal(2, completeQueue.Count); + var writeTask3 = socketOutput.WriteAsync(halfWriteBehindBuffer, default(CancellationToken)); + Assert.False(writeTask3.IsCompleted); - // Act - Action triggerNextCompleted; - Assert.True(completeQueue.TryDequeue(out triggerNextCompleted)); - triggerNextCompleted(0); + // Drain the write queue + while (completeQueue.TryDequeue(out var triggerNextCompleted)) + { + await kestrelThread.PostAsync(cb => cb(0), triggerNextCompleted); + } - // Assert - // Finishing the first write should allow the second write to pre-complete. - Assert.Equal(TaskStatus.RanToCompletion, writeTask2.Status); + var timeout = TimeSpan.FromSeconds(5); + + await writeTask2.TimeoutAfter(timeout); + await writeTask3.TimeoutAfter(timeout); + + Assert.Empty(completeQueue); // Cleanup - var cleanupTask = socketOutput.WriteAsync( - default(ArraySegment), default(CancellationToken), socketDisconnect: true); - - // Wait for all writes to complete so the completeQueue isn't modified during enumeration. - await mockLibuv.OnPostTask; - - foreach (var triggerCompleted in completeQueue) - { - triggerCompleted(0); - } - } - } - - [Theory] - [MemberData(nameof(PositiveMaxResponseBufferSizeData))] - public async Task OnlyWritesRequestingCancellationAreErroredOnCancellation(KestrelServerOptions options) - { - var maxBytesPreCompleted = (int)options.Limits.MaxResponseBufferSize.Value; - var completeQueue = new ConcurrentQueue>(); - - // Arrange - var mockLibuv = new MockLibuv - { - OnWrite = (socket, buffers, triggerCompleted) => - { - completeQueue.Enqueue(triggerCompleted); - return 0; - } - }; - - using (var kestrelEngine = new KestrelEngine(mockLibuv, new TestServiceContext())) - { - var kestrelThread = new KestrelThread(kestrelEngine, maxLoops: 1); - kestrelEngine.Threads.Add(kestrelThread); - await kestrelThread.StartAsync(); - - var socket = new MockSocket(mockLibuv, kestrelThread.Loop.ThreadId, new TestKestrelTrace()); - var trace = new KestrelTrace(new TestKestrelTrace()); - var ltp = new InlineLoggingThreadPool(trace); - - using (var mockConnection = new MockConnection(options)) - { - ISocketOutput socketOutput = new SocketOutput(kestrelThread, socket, mockConnection, "0", trace, ltp); - - var bufferSize = maxBytesPreCompleted; - - var data = new byte[bufferSize]; - var fullBuffer = new ArraySegment(data, 0, bufferSize); - - var cts = new CancellationTokenSource(); - - // Act - var task1Success = socketOutput.WriteAsync(fullBuffer, cancellationToken: cts.Token); - // task1 should complete successfully as < _maxBytesPreCompleted - - // First task is completed and successful - Assert.True(task1Success.IsCompleted); - Assert.False(task1Success.IsCanceled); - Assert.False(task1Success.IsFaulted); - - // following tasks should wait. - var task2Throw = socketOutput.WriteAsync(fullBuffer, cancellationToken: cts.Token); - var task3Success = socketOutput.WriteAsync(fullBuffer, cancellationToken: default(CancellationToken)); - - // Give time for tasks to percolate - await mockLibuv.OnPostTask; - - // Second task is not completed - Assert.False(task2Throw.IsCompleted); - Assert.False(task2Throw.IsCanceled); - Assert.False(task2Throw.IsFaulted); - - // Third task is not completed - Assert.False(task3Success.IsCompleted); - Assert.False(task3Success.IsCanceled); - Assert.False(task3Success.IsFaulted); - - cts.Cancel(); - - // Second task is now canceled - await Assert.ThrowsAsync(() => task2Throw); - Assert.True(task2Throw.IsCanceled); - - // Third task is now completed - await task3Success; - - // Fourth task immediately cancels as the token is canceled - var task4Throw = socketOutput.WriteAsync(fullBuffer, cancellationToken: cts.Token); - - Assert.True(task4Throw.IsCompleted); - Assert.True(task4Throw.IsCanceled); - Assert.False(task4Throw.IsFaulted); - - var task5Success = socketOutput.WriteAsync(fullBuffer, cancellationToken: default(CancellationToken)); - // task5 should complete immediately - - Assert.True(task5Success.IsCompleted); - Assert.False(task5Success.IsCanceled); - Assert.False(task5Success.IsFaulted); - - cts = new CancellationTokenSource(); - - var task6Success = socketOutput.WriteAsync(fullBuffer, cancellationToken: cts.Token); - // task6 should complete immediately but not cancel as its cancellation token isn't set - - Assert.True(task6Success.IsCompleted); - Assert.False(task6Success.IsCanceled); - Assert.False(task6Success.IsFaulted); - - // Cleanup - var cleanupTask = ((SocketOutput)socketOutput).WriteAsync( - default(ArraySegment), default(CancellationToken), socketDisconnect: true); - - // Allow for the socketDisconnect command to get posted to the libuv thread. - // Right now, the up to three pending writes are holding it up. - Action triggerNextCompleted; - Assert.True(completeQueue.TryDequeue(out triggerNextCompleted)); - triggerNextCompleted(0); - - // Wait for all writes to complete so the completeQueue isn't modified during enumeration. - await mockLibuv.OnPostTask; - - foreach (var triggerCompleted in completeQueue) - { - triggerCompleted(0); - } - } + socketOutput.End(ProduceEndType.SocketDisconnect); } } @@ -491,6 +390,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests }; using (var kestrelEngine = new KestrelEngine(mockLibuv, new TestServiceContext())) + using (var factory = new PipeFactory()) { var kestrelThread = new KestrelThread(kestrelEngine, maxLoops: 1); kestrelEngine.Threads.Add(kestrelThread); @@ -498,14 +398,20 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var socket = new MockSocket(mockLibuv, kestrelThread.Loop.ThreadId, new TestKestrelTrace()); var trace = new KestrelTrace(new TestKestrelTrace()); - var ltp = new InlineLoggingThreadPool(trace); using (var mockConnection = new MockConnection(options)) { + var pipeOptions = new PipeOptions + { + ReaderScheduler = kestrelThread, + MaximumSizeHigh = options.Limits.MaxResponseBufferSize ?? 0, + MaximumSizeLow = options.Limits.MaxResponseBufferSize ?? 0, + }; + var pipe = factory.Create(pipeOptions); var abortedSource = mockConnection.RequestAbortedSource; - ISocketOutput socketOutput = new SocketOutput(kestrelThread, socket, mockConnection, "0", trace, ltp); + var socketOutput = new SocketOutput(pipe, kestrelThread, socket, mockConnection, "0", trace); - var bufferSize = maxBytesPreCompleted; + var bufferSize = maxBytesPreCompleted - 1; var data = new byte[bufferSize]; var fullBuffer = new ArraySegment(data, 0, bufferSize); @@ -536,29 +442,25 @@ namespace Microsoft.AspNetCore.Server.KestrelTests Assert.False(task3Canceled.IsCanceled); Assert.False(task3Canceled.IsFaulted); - // Cause the first write to fail. - Action triggerNextCompleted; - Assert.True(completeQueue.TryDequeue(out triggerNextCompleted)); - triggerNextCompleted(-1); + + // Cause all writes to fail + while (completeQueue.TryDequeue(out var triggerNextCompleted)) + { + await kestrelThread.PostAsync(cb => cb(-1), triggerNextCompleted); + } // Second task is now completed - await task2Success; + await task2Success.TimeoutAfter(TimeSpan.FromSeconds(5)); // Third task is now canceled - await Assert.ThrowsAsync(() => task3Canceled); - Assert.True(task3Canceled.IsCanceled); + // TODO: Cancellation isn't supported right now + // await Assert.ThrowsAsync(() => task3Canceled); + // Assert.True(task3Canceled.IsCanceled); + + Assert.True(abortedSource.IsCancellationRequested); // Cleanup - var cleanupTask = ((SocketOutput)socketOutput).WriteAsync( - default(ArraySegment), default(CancellationToken), socketDisconnect: true); - - // Wait for all writes to complete so the completeQueue isn't modified during enumeration. - await mockLibuv.OnPostTask; - - foreach (var triggerCompleted in completeQueue) - { - triggerCompleted(0); - } + socketOutput.End(ProduceEndType.SocketDisconnect); } } } @@ -569,7 +471,6 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { var maxBytesPreCompleted = (int)options.Limits.MaxResponseBufferSize.Value; var completeQueue = new ConcurrentQueue>(); - var writeCalled = false; // Arrange var mockLibuv = new MockLibuv @@ -577,13 +478,12 @@ namespace Microsoft.AspNetCore.Server.KestrelTests OnWrite = (socket, buffers, triggerCompleted) => { completeQueue.Enqueue(triggerCompleted); - writeCalled = true; - return 0; } }; using (var kestrelEngine = new KestrelEngine(mockLibuv, new TestServiceContext())) + using (var factory = new PipeFactory()) { var kestrelThread = new KestrelThread(kestrelEngine, maxLoops: 1); kestrelEngine.Threads.Add(kestrelThread); @@ -591,182 +491,48 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var socket = new MockSocket(mockLibuv, kestrelThread.Loop.ThreadId, new TestKestrelTrace()); var trace = new KestrelTrace(new TestKestrelTrace()); - var ltp = new InlineLoggingThreadPool(trace); var mockConnection = new MockConnection(options); - var socketOutput = new SocketOutput(kestrelThread, socket, mockConnection, "0", trace, ltp); + var pipeOptions = new PipeOptions + { + ReaderScheduler = kestrelThread, + MaximumSizeHigh = options.Limits.MaxResponseBufferSize ?? 0, + MaximumSizeLow = options.Limits.MaxResponseBufferSize ?? 0, + }; + var pipe = factory.Create(pipeOptions); + var socketOutput = new SocketOutput(pipe, kestrelThread, socket, mockConnection, "0", trace); - var bufferSize = maxBytesPreCompleted; + var bufferSize = maxBytesPreCompleted - 1; var buffer = new ArraySegment(new byte[bufferSize], 0, bufferSize); // Act (Pre-complete the maximum number of bytes in preparation for the rest of the test) var writeTask1 = socketOutput.WriteAsync(buffer, default(CancellationToken)); // Assert - // The first write should pre-complete since it is <= _maxBytesPreCompleted. + // The first write should pre-complete since it is < _maxBytesPreCompleted. await mockLibuv.OnPostTask; Assert.Equal(TaskStatus.RanToCompletion, writeTask1.Status); - Assert.True(writeCalled); - // Arrange - writeCalled = false; + Assert.NotEmpty(completeQueue); // Act var writeTask2 = socketOutput.WriteAsync(buffer, default(CancellationToken)); var writeTask3 = socketOutput.WriteAsync(buffer, default(CancellationToken)); - await mockLibuv.OnPostTask; - Assert.True(writeCalled); - Action triggerNextCompleted; - Assert.True(completeQueue.TryDequeue(out triggerNextCompleted)); - triggerNextCompleted(0); + // Drain the write queue + while (completeQueue.TryDequeue(out var triggerNextCompleted)) + { + await kestrelThread.PostAsync(cb => cb(0), triggerNextCompleted); + } + + var timeout = TimeSpan.FromSeconds(5); // Assert // Too many bytes are already pre-completed for the third but not the second write to pre-complete. // https://github.com/aspnet/KestrelHttpServer/issues/356 - Assert.Equal(TaskStatus.RanToCompletion, writeTask2.Status); - Assert.False(writeTask3.IsCompleted); - - // Act - Assert.True(completeQueue.TryDequeue(out triggerNextCompleted)); - triggerNextCompleted(0); - - // Assert - // Finishing the first write should allow the third write to pre-complete. - Assert.Equal(TaskStatus.RanToCompletion, writeTask3.Status); + await writeTask2.TimeoutAfter(timeout); + await writeTask3.TimeoutAfter(timeout); // Cleanup - var cleanupTask = ((SocketOutput)socketOutput).WriteAsync( - default(ArraySegment), default(CancellationToken), socketDisconnect: true); - - // Wait for all writes to complete so the completeQueue isn't modified during enumeration. - await mockLibuv.OnPostTask; - - foreach (var triggerCompleted in completeQueue) - { - triggerCompleted(0); - } - } - } - - [Theory] - [MemberData(nameof(MaxResponseBufferSizeData))] - public async Task ProducingStartAndProducingCompleteCanBeUsedDirectly(KestrelServerOptions options) - { - int nBuffers = 0; - - var mockLibuv = new MockLibuv - { - OnWrite = (socket, buffers, triggerCompleted) => - { - nBuffers = buffers; - triggerCompleted(0); - return 0; - } - }; - - using (var kestrelEngine = new KestrelEngine(mockLibuv, new TestServiceContext())) - { - var kestrelThread = new KestrelThread(kestrelEngine, maxLoops: 1); - kestrelEngine.Threads.Add(kestrelThread); - await kestrelThread.StartAsync(); - - var socket = new MockSocket(mockLibuv, kestrelThread.Loop.ThreadId, new TestKestrelTrace()); - var trace = new KestrelTrace(new TestKestrelTrace()); - var ltp = new InlineLoggingThreadPool(trace); - var socketOutput = new SocketOutput(kestrelThread, socket, new MockConnection(options), "0", trace, ltp); - - // block 1 - var start = socketOutput.ProducingStart(); - start.Block.End = start.Block.Data.Offset + start.Block.Data.Count; - - // block 2 - var block2 = kestrelThread.Memory.Lease(); - block2.End = block2.Data.Offset + block2.Data.Count; - start.Block.Next = block2; - - var end = new MemoryPoolIterator(block2, block2.End); - - socketOutput.ProducingComplete(end); - - // A call to Write is required to ensure a write is scheduled - var ignore = socketOutput.WriteAsync(default(ArraySegment), default(CancellationToken)); - - await mockLibuv.OnPostTask; - Assert.Equal(2, nBuffers); - - // Cleanup - var cleanupTask = socketOutput.WriteAsync( - default(ArraySegment), default(CancellationToken), socketDisconnect: true); - } - } - - [Theory] - [MemberData(nameof(MaxResponseBufferSizeData))] - public async Task OnlyAllowsUpToThreeConcurrentWrites(KestrelServerOptions options) - { - var writeCalled = false; - var completeQueue = new ConcurrentQueue>(); - - var mockLibuv = new MockLibuv - { - OnWrite = (socket, buffers, triggerCompleted) => - { - writeCalled = true; - completeQueue.Enqueue(triggerCompleted); - return 0; - } - }; - - using (var kestrelEngine = new KestrelEngine(mockLibuv, new TestServiceContext())) - { - var kestrelThread = new KestrelThread(kestrelEngine, maxLoops: 1); - kestrelEngine.Threads.Add(kestrelThread); - await kestrelThread.StartAsync(); - - var socket = new MockSocket(mockLibuv, kestrelThread.Loop.ThreadId, new TestKestrelTrace()); - var trace = new KestrelTrace(new TestKestrelTrace()); - var ltp = new InlineLoggingThreadPool(trace); - var mockConnection = new MockConnection(options); - var socketOutput = new SocketOutput(kestrelThread, socket, mockConnection, "0", trace, ltp); - - var buffer = new ArraySegment(new byte[1]); - - // First three writes trigger uv_write - var ignore = socketOutput.WriteAsync(buffer, CancellationToken.None); - await mockLibuv.OnPostTask; - Assert.True(writeCalled); - writeCalled = false; - ignore = socketOutput.WriteAsync(buffer, CancellationToken.None); - await mockLibuv.OnPostTask; - Assert.True(writeCalled); - writeCalled = false; - ignore = socketOutput.WriteAsync(buffer, CancellationToken.None); - await mockLibuv.OnPostTask; - Assert.True(writeCalled); - writeCalled = false; - - // The fourth write won't trigger uv_write since the first three haven't completed - ignore = socketOutput.WriteAsync(buffer, CancellationToken.None); - await mockLibuv.OnPostTask; - Assert.False(writeCalled); - - // Complete 1st write allowing uv_write to be triggered again - Action triggerNextCompleted; - Assert.True(completeQueue.TryDequeue(out triggerNextCompleted)); - triggerNextCompleted(0); - await mockLibuv.OnPostTask; - Assert.True(writeCalled); - - // Cleanup - var cleanupTask = socketOutput.WriteAsync( - default(ArraySegment), default(CancellationToken), socketDisconnect: true); - - // Wait for all writes to complete so the completeQueue isn't modified during enumeration. - await mockLibuv.OnPostTask; - - foreach (var triggerCompleted in completeQueue) - { - triggerCompleted(0); - } + socketOutput.End(ProduceEndType.SocketDisconnect); } } @@ -789,6 +555,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests }; using (var kestrelEngine = new KestrelEngine(mockLibuv, new TestServiceContext())) + using (var factory = new PipeFactory()) { var kestrelThread = new KestrelThread(kestrelEngine, maxLoops: 1); kestrelEngine.Threads.Add(kestrelThread); @@ -796,8 +563,14 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var socket = new MockSocket(mockLibuv, kestrelThread.Loop.ThreadId, new TestKestrelTrace()); var trace = new KestrelTrace(new TestKestrelTrace()); - var ltp = new InlineLoggingThreadPool(trace); - var socketOutput = new SocketOutput(kestrelThread, socket, new MockConnection(new KestrelServerOptions()), "0", trace, ltp); + var pipeOptions = new PipeOptions + { + ReaderScheduler = kestrelThread, + MaximumSizeHigh = options.Limits.MaxResponseBufferSize ?? 0, + MaximumSizeLow = options.Limits.MaxResponseBufferSize ?? 0, + }; + var pipe = factory.Create(pipeOptions); + var socketOutput = new SocketOutput(pipe, kestrelThread, socket, new MockConnection(new KestrelServerOptions()), "0", trace); mockLibuv.KestrelThreadBlocker.Reset(); @@ -817,6 +590,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests // Write isn't called twice after the thread is unblocked await mockLibuv.OnPostTask; + Assert.False(writeCalled); // One call to ScheduleWrite Assert.Equal(1, mockLibuv.PostCount); @@ -824,17 +598,17 @@ namespace Microsoft.AspNetCore.Server.KestrelTests Assert.Equal(1, writeCount); // Cleanup - var cleanupTask = socketOutput.WriteAsync( - default(ArraySegment), default(CancellationToken), socketDisconnect: true); + socketOutput.End(ProduceEndType.SocketDisconnect); } } - [Fact] - public async Task ProducingStartAndProducingCompleteCanBeCalledAfterConnectionClose() + [Fact(Skip = "Commit throws with a non channel backed writable buffer")] + public async Task AllocCommitCanBeCalledAfterConnectionClose() { var mockLibuv = new MockLibuv(); using (var kestrelEngine = new KestrelEngine(mockLibuv, new TestServiceContext())) + using (var factory = new PipeFactory()) { var kestrelThread = new KestrelThread(kestrelEngine, maxLoops: 1); kestrelEngine.Threads.Add(kestrelThread); @@ -842,23 +616,23 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var socket = new MockSocket(mockLibuv, kestrelThread.Loop.ThreadId, new TestKestrelTrace()); var trace = new KestrelTrace(new TestKestrelTrace()); - var ltp = new InlineLoggingThreadPool(trace); var connection = new MockConnection(new KestrelServerOptions()); - var socketOutput = new SocketOutput(kestrelThread, socket, connection, "0", trace, ltp); + var pipeOptions = new PipeOptions + { + ReaderScheduler = kestrelThread, + }; + var pipe = factory.Create(pipeOptions); + var socketOutput = new SocketOutput(pipe, kestrelThread, socket, connection, "0", trace); // Close SocketOutput - var cleanupTask = socketOutput.WriteAsync( - default(ArraySegment), default(CancellationToken), socketDisconnect: true); + socketOutput.End(ProduceEndType.SocketDisconnect); await mockLibuv.OnPostTask; Assert.Equal(TaskStatus.RanToCompletion, connection.SocketClosed.Status); - var start = socketOutput.ProducingStart(); - - Assert.True(start.IsDefault); - // ProducingComplete should not throw given a default iterator - socketOutput.ProducingComplete(start); + var start = socketOutput.Alloc(); + start.Commit(); } } } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/StreamSocketOutputTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/StreamSocketOutputTests.cs index 669efdf99e..910a888569 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/StreamSocketOutputTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/StreamSocketOutputTests.cs @@ -3,6 +3,7 @@ using System; using System.IO; +using System.IO.Pipelines; using Microsoft.AspNetCore.Server.Kestrel.Adapter.Internal; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; using Microsoft.AspNetCore.Testing; @@ -19,13 +20,17 @@ namespace Microsoft.AspNetCore.Server.KestrelTests // Which happens if ProduceEnd is called in Frame without _responseStarted == true // As it calls ProduceStart with write immediate == true // This happens in WebSocket Upgrade over SSL + using (var factory = new PipeFactory()) + { + var socketOutput = new StreamSocketOutput(new ThrowsOnNullWriteStream(), factory.Create()); - ISocketOutput socketOutput = new StreamSocketOutput("id", new ThrowsOnNullWriteStream(), null, new TestKestrelTrace()); + // Should not throw + socketOutput.Write(default(ArraySegment), true); - // Should not throw - socketOutput.Write(default(ArraySegment), true); + Assert.True(true); - Assert.True(true); + socketOutput.Dispose(); + } } private class ThrowsOnNullWriteStream : Stream diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestInput.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/TestInput.cs index 19f1f81890..be520d99f1 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/TestInput.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/TestInput.cs @@ -12,7 +12,6 @@ using Microsoft.AspNetCore.Server.Kestrel.Internal; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; using Microsoft.AspNetCore.Testing; using Microsoft.Extensions.Internal; -using MemoryPool = Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPool; namespace Microsoft.AspNetCore.Server.KestrelTests { diff --git a/test/shared/MockSocketOutput.cs b/test/shared/MockSocketOutput.cs index 19c115d94e..fa7f8836d6 100644 --- a/test/shared/MockSocketOutput.cs +++ b/test/shared/MockSocketOutput.cs @@ -4,21 +4,20 @@ using System; using System.Threading; using System.Threading.Tasks; +using System.IO.Pipelines; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.Extensions.Internal; namespace Microsoft.AspNetCore.Testing { public class MockSocketOutput : ISocketOutput { - public void ProducingComplete(MemoryPoolIterator end) - { - } + private PipeFactory _factory = new PipeFactory(); + private IPipeWriter _writer; - public MemoryPoolIterator ProducingStart() + public MockSocketOutput() { - return new MemoryPoolIterator(); + _writer = _factory.Create().Writer; } public void Write(ArraySegment buffer, bool chunk = false) @@ -38,5 +37,10 @@ namespace Microsoft.AspNetCore.Testing { return TaskCache.CompletedTask; } + + public WritableBuffer Alloc() + { + return _writer.Alloc(); + } } } diff --git a/test/shared/TestConnection.cs b/test/shared/TestConnection.cs index 849962d378..aef4561448 100644 --- a/test/shared/TestConnection.cs +++ b/test/shared/TestConnection.cs @@ -8,7 +8,6 @@ using System.Net; using System.Net.Sockets; using System.Text; using System.Threading.Tasks; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; using Xunit; namespace Microsoft.AspNetCore.Testing @@ -21,6 +20,7 @@ namespace Microsoft.AspNetCore.Testing private Socket _socket; private NetworkStream _stream; private StreamReader _reader; + private static readonly TimeSpan Timeout = TimeSpan.FromMinutes(1); public TestConnection(int port) : this(port, AddressFamily.InterNetwork) @@ -82,7 +82,7 @@ namespace Microsoft.AspNetCore.Testing var task = _reader.ReadAsync(actual, offset, actual.Length - offset); if (!Debugger.IsAttached) { - Assert.True(await Task.WhenAny(task, Task.Delay(TimeSpan.FromMinutes(1))) == task, "TestConnection.Receive timed out."); + task = task.TimeoutAfter(Timeout); } var count = await task; if (count == 0) @@ -100,7 +100,7 @@ namespace Microsoft.AspNetCore.Testing await Receive(lines); _socket.Shutdown(SocketShutdown.Send); var ch = new char[128]; - var count = await _reader.ReadAsync(ch, 0, 128).TimeoutAfter(TimeSpan.FromMinutes(1)); + var count = await _reader.ReadAsync(ch, 0, 128).TimeoutAfter(Timeout); var text = new string(ch, 0, count); Assert.Equal("", text); } @@ -112,7 +112,7 @@ namespace Microsoft.AspNetCore.Testing try { var ch = new char[128]; - var count = await _reader.ReadAsync(ch, 0, 128).TimeoutAfter(TimeSpan.FromMinutes(1)); + var count = await _reader.ReadAsync(ch, 0, 128).TimeoutAfter(Timeout); var text = new string(ch, 0, count); Assert.Equal("", text); } diff --git a/tools/CodeGenerator/KnownHeaders.cs b/tools/CodeGenerator/KnownHeaders.cs index ae8756af2d..dee9665889 100644 --- a/tools/CodeGenerator/KnownHeaders.cs +++ b/tools/CodeGenerator/KnownHeaders.cs @@ -291,6 +291,7 @@ namespace CodeGenerator using System; using System.Collections.Generic; +using System.IO.Pipelines; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.Extensions.Primitives; using Microsoft.Net.Http.Headers; @@ -521,7 +522,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http return true; }} {(loop.ClassName == "FrameResponseHeaders" ? $@" - protected void CopyToFast(ref MemoryPoolIterator output) + protected void CopyToFast(ref WritableBuffer output) {{ var tempBits = _bits | (_contentLength.HasValue ? {1L << 63}L : 0); {Each(loop.Headers.Where(header => header.Identifier != "ContentLength").OrderBy(h => !h.PrimaryHeader), header => $@" @@ -529,7 +530,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http {{ {(header.EnhancedSetter == false ? "" : $@" if (_headers._raw{header.Identifier} != null) {{ - output.CopyFrom(_headers._raw{header.Identifier}, 0, _headers._raw{header.Identifier}.Length); + output.Write(_headers._raw{header.Identifier}); }} else ")} {{ @@ -539,8 +540,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var value = _headers._{header.Identifier}[i]; if (value != null) {{ - output.CopyFrom(_headerBytes, {header.BytesOffset}, {header.BytesCount}); - output.CopyFromAscii(value); + output.Write(new Span(_headerBytes, {header.BytesOffset}, {header.BytesCount})); + output.WriteAscii(value); }} }} }} @@ -553,8 +554,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http }}{(header.Identifier == "Server" ? $@" if ((tempBits & {1L << 63}L) != 0) {{ - output.CopyFrom(_headerBytes, {loop.Headers.First(x => x.Identifier == "ContentLength").BytesOffset}, {loop.Headers.First(x => x.Identifier == "ContentLength").BytesCount}); - output.CopyFromNumeric((ulong)ContentLength.Value); + output.Write(new Span(_headerBytes, {loop.Headers.First(x => x.Identifier == "ContentLength").BytesOffset}, {loop.Headers.First(x => x.Identifier == "ContentLength").BytesCount})); + output.WriteNumeric((ulong)ContentLength.Value); if((tempBits & ~{1L << 63}L) == 0) {{ From f4c6e0b1510d9151f85fa7d87d05c400f3357f2e Mon Sep 17 00:00:00 2001 From: David Fowler Date: Sat, 18 Mar 2017 01:21:31 -0700 Subject: [PATCH 1127/1662] Feedback from SocketOutput port (#1502) - Fix naming convention in LibuvAwaitable - Remove case statement in SocketOutput --- .../Internal/Http/SocketOutput.cs | 11 +++-------- .../Internal/Infrastructure/LibuvAwaitable.cs | 16 ++++++++-------- 2 files changed, 11 insertions(+), 16 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/SocketOutput.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/SocketOutput.cs index 1438f1c274..7c4412ef23 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/SocketOutput.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/SocketOutput.cs @@ -105,15 +105,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http public void End(ProduceEndType endType) { - switch (endType) + if (endType == ProduceEndType.SocketShutdown) { - case ProduceEndType.SocketShutdown: - // Graceful shutdown - _pipe.Reader.CancelPendingRead(); - break; - case ProduceEndType.SocketDisconnect: - // Not graceful - break; + // Graceful shutdown + _pipe.Reader.CancelPendingRead(); } lock (_contextLock) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/LibuvAwaitable.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/LibuvAwaitable.cs index 1bfd222e6c..8fc241858f 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/LibuvAwaitable.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/LibuvAwaitable.cs @@ -12,7 +12,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure { public class LibuvAwaitable : ICriticalNotifyCompletion where TRequest : UvRequest { - private readonly static Action CALLBACK_RAN = () => { }; + private readonly static Action _callbackCompleted = () => { }; private Action _callback; @@ -20,20 +20,20 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure private int _status; - public static Action Callback = (req, status, error, state) => + public static readonly Action Callback = (req, status, error, state) => { var awaitable = (LibuvAwaitable)state; awaitable._exception = error; awaitable._status = status; - var continuation = Interlocked.Exchange(ref awaitable._callback, CALLBACK_RAN); + var continuation = Interlocked.Exchange(ref awaitable._callback, _callbackCompleted); continuation?.Invoke(); }; public LibuvAwaitable GetAwaiter() => this; - public bool IsCompleted => _callback == CALLBACK_RAN; + public bool IsCompleted => _callback == _callbackCompleted; public UvWriteResult GetResult() { @@ -50,8 +50,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure public void OnCompleted(Action continuation) { - if (_callback == CALLBACK_RAN || - Interlocked.CompareExchange(ref _callback, continuation, null) == CALLBACK_RAN) + if (_callback == _callbackCompleted || + Interlocked.CompareExchange(ref _callback, continuation, null) == _callbackCompleted) { Task.Run(continuation); } @@ -65,8 +65,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure public struct UvWriteResult { - public int Status; - public Exception Error; + public int Status { get; } + public Exception Error { get; } public UvWriteResult(int status, Exception error) { From 5b814a55ac5cd18d4a8a6ceb8a66d0c39b95b1f4 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Sat, 18 Mar 2017 19:25:10 +0000 Subject: [PATCH 1128/1662] Speed up WritableBuffer.WriteXxx (#1504) * Speed up WritableBuffer.WriteAscii * Add Benchmarks * Non-standard header vals are still ascii * Speedup WriteNumeric * Don't advance for write * Remove cruft --- .../Internal/Http/FrameResponseHeaders.cs | 2 +- .../Internal/Http/PipelineExtensions.cs | 240 +++++++++++++++++- ...s => ResponseHeaderCollectionBenchmark.cs} | 43 +++- .../ResponseHeadersWritingBenchmark.cs | 151 +++++++++++ 4 files changed, 413 insertions(+), 23 deletions(-) rename test/Microsoft.AspNetCore.Server.Kestrel.Performance/{ResponseHeadersBenchmark.cs => ResponseHeaderCollectionBenchmark.cs} (88%) create mode 100644 test/Microsoft.AspNetCore.Server.Kestrel.Performance/ResponseHeadersWritingBenchmark.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameResponseHeaders.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameResponseHeaders.cs index 2a3f1979c9..439a76bd6a 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameResponseHeaders.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameResponseHeaders.cs @@ -49,7 +49,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http output.Write(_CrLf); output.WriteAscii(kv.Key); output.Write(_colonSpace); - output.Write(value); + output.WriteAscii(value); } } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/PipelineExtensions.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/PipelineExtensions.cs index a53b5d445b..0ab6f20a68 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/PipelineExtensions.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/PipelineExtensions.cs @@ -13,6 +13,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { public static class PipelineExtensions { + private const int _maxULongByteLength = 20; + + [ThreadStatic] + private static byte[] _numericBytesScratch; + public static ValueTask> PeekAsync(this IPipeReader pipelineReader) { var input = pipelineReader.ReadAsync(); @@ -90,18 +95,237 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http return result; } - public static void WriteAscii(this WritableBuffer buffer, string data) + public unsafe static void WriteAscii(this WritableBuffer buffer, string data) { - buffer.Write(Encoding.ASCII.GetBytes(data)); - } - public static void Write(this WritableBuffer buffer, string data) - { - buffer.Write(Encoding.UTF8.GetBytes(data)); + if (!string.IsNullOrEmpty(data)) + { + if (buffer.Memory.IsEmpty) + { + buffer.Ensure(); + } + + // Fast path, try copying to the available memory directly + if (data.Length <= buffer.Memory.Length) + { + fixed (char* input = data) + fixed (byte* output = &buffer.Memory.Span.DangerousGetPinnableReference()) + { + EncodeAsciiCharsToBytes(input, output, data.Length); + } + + buffer.Advance(data.Length); + } + else + { + buffer.WriteAsciiMultiWrite(data); + } + } } - public static void WriteNumeric(this WritableBuffer buffer, ulong number) + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public unsafe static void WriteNumeric(this WritableBuffer buffer, ulong number) { - buffer.Write(number.ToString()); + const byte AsciiDigitStart = (byte)'0'; + + if (buffer.Memory.IsEmpty) + { + buffer.Ensure(); + } + + // Fast path, try copying to the available memory directly + var bytesLeftInBlock = buffer.Memory.Length; + var simpleWrite = true; + fixed (byte* output = &buffer.Memory.Span.DangerousGetPinnableReference()) + { + var start = output; + if (number < 10 && bytesLeftInBlock >= 1) + { + *(start) = (byte)(((uint)number) + AsciiDigitStart); + buffer.Advance(1); + } + else if (number < 100 && bytesLeftInBlock >= 2) + { + var val = (uint)number; + var tens = (byte)((val * 205u) >> 11); // div10, valid to 1028 + + *(start) = (byte)(tens + AsciiDigitStart); + *(start + 1) = (byte)(val - (tens * 10) + AsciiDigitStart); + buffer.Advance(2); + } + else if (number < 1000 && bytesLeftInBlock >= 3) + { + var val = (uint)number; + var digit0 = (byte)((val * 41u) >> 12); // div100, valid to 1098 + var digits01 = (byte)((val * 205u) >> 11); // div10, valid to 1028 + + *(start) = (byte)(digit0 + AsciiDigitStart); + *(start + 1) = (byte)(digits01 - (digit0 * 10) + AsciiDigitStart); + *(start + 2) = (byte)(val - (digits01 * 10) + AsciiDigitStart); + buffer.Advance(3); + } + else + { + simpleWrite = false; + } + } + + if (!simpleWrite) + { + buffer.WriteNumericMultiWrite(number); + } + } + + [MethodImpl(MethodImplOptions.NoInlining)] + private static unsafe void WriteNumericMultiWrite(this WritableBuffer buffer, ulong number) + { + const byte AsciiDigitStart = (byte)'0'; + + var value = number; + var position = _maxULongByteLength; + var byteBuffer = NumericBytesScratch; + do + { + // Consider using Math.DivRem() if available + var quotient = value / 10; + byteBuffer[--position] = (byte)(AsciiDigitStart + (value - quotient * 10)); // 0x30 = '0' + value = quotient; + } + while (value != 0); + + var length = _maxULongByteLength - position; + buffer.Write(new ReadOnlySpan(byteBuffer, position, length)); + } + + [MethodImpl(MethodImplOptions.NoInlining)] + private unsafe static void WriteAsciiMultiWrite(this WritableBuffer buffer, string data) + { + var remaining = data.Length; + + fixed (char* input = data) + { + var inputSlice = input; + + while (remaining > 0) + { + var writable = Math.Min(remaining, buffer.Memory.Length); + + buffer.Ensure(writable); + + if (writable == 0) + { + continue; + } + + fixed (byte* output = &buffer.Memory.Span.DangerousGetPinnableReference()) + { + EncodeAsciiCharsToBytes(inputSlice, output, writable); + } + + inputSlice += writable; + remaining -= writable; + + buffer.Advance(writable); + } + } + } + + private unsafe static void EncodeAsciiCharsToBytes(char* input, byte* output, int length) + { + // Note: Not BIGENDIAN or check for non-ascii + const int Shift16Shift24 = (1 << 16) | (1 << 24); + const int Shift8Identity = (1 << 8) | (1); + + // Encode as bytes upto the first non-ASCII byte and return count encoded + int i = 0; + // Use Intrinsic switch + if (IntPtr.Size == 8) // 64 bit + { + if (length < 4) goto trailing; + + int unaligned = (int)(((ulong)input) & 0x7) >> 1; + // Unaligned chars + for (; i < unaligned; i++) + { + char ch = *(input + i); + *(output + i) = (byte)ch; // Cast convert + } + + // Aligned + int ulongDoubleCount = (length - i) & ~0x7; + for (; i < ulongDoubleCount; i += 8) + { + ulong inputUlong0 = *(ulong*)(input + i); + ulong inputUlong1 = *(ulong*)(input + i + 4); + // Pack 16 ASCII chars into 16 bytes + *(uint*)(output + i) = + ((uint)((inputUlong0 * Shift16Shift24) >> 24) & 0xffff) | + ((uint)((inputUlong0 * Shift8Identity) >> 24) & 0xffff0000); + *(uint*)(output + i + 4) = + ((uint)((inputUlong1 * Shift16Shift24) >> 24) & 0xffff) | + ((uint)((inputUlong1 * Shift8Identity) >> 24) & 0xffff0000); + } + if (length - 4 > i) + { + ulong inputUlong = *(ulong*)(input + i); + // Pack 8 ASCII chars into 8 bytes + *(uint*)(output + i) = + ((uint)((inputUlong * Shift16Shift24) >> 24) & 0xffff) | + ((uint)((inputUlong * Shift8Identity) >> 24) & 0xffff0000); + i += 4; + } + + trailing: + for (; i < length; i++) + { + char ch = *(input + i); + *(output + i) = (byte)ch; // Cast convert + } + } + else // 32 bit + { + // Unaligned chars + if ((unchecked((int)input) & 0x2) != 0) + { + char ch = *input; + i = 1; + *(output) = (byte)ch; // Cast convert + } + + // Aligned + int uintCount = (length - i) & ~0x3; + for (; i < uintCount; i += 4) + { + uint inputUint0 = *(uint*)(input + i); + uint inputUint1 = *(uint*)(input + i + 2); + // Pack 4 ASCII chars into 4 bytes + *(ushort*)(output + i) = (ushort)(inputUint0 | (inputUint0 >> 8)); + *(ushort*)(output + i + 2) = (ushort)(inputUint1 | (inputUint1 >> 8)); + } + if (length - 1 > i) + { + uint inputUint = *(uint*)(input + i); + // Pack 2 ASCII chars into 2 bytes + *(ushort*)(output + i) = (ushort)(inputUint | (inputUint >> 8)); + i += 2; + } + + if (i < length) + { + char ch = *(input + i); + *(output + i) = (byte)ch; // Cast convert + i = length; + } + } + } + + private static byte[] NumericBytesScratch => _numericBytesScratch ?? CreateNumericBytesScratch(); + + [MethodImpl(MethodImplOptions.NoInlining)] + private static byte[] CreateNumericBytesScratch() + { + var bytes = new byte[_maxULongByteLength]; + _numericBytesScratch = bytes; + return bytes; } } } \ No newline at end of file diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/ResponseHeadersBenchmark.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/ResponseHeaderCollectionBenchmark.cs similarity index 88% rename from test/Microsoft.AspNetCore.Server.Kestrel.Performance/ResponseHeadersBenchmark.cs rename to test/Microsoft.AspNetCore.Server.Kestrel.Performance/ResponseHeaderCollectionBenchmark.cs index f5dab5e3e7..691b0da43a 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/ResponseHeadersBenchmark.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/ResponseHeaderCollectionBenchmark.cs @@ -3,16 +3,16 @@ using System.Runtime.CompilerServices; using System.Text; -using BenchmarkDotNet.Attributes; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http.Internal; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; using Microsoft.AspNetCore.Testing; +using BenchmarkDotNet.Attributes; namespace Microsoft.AspNetCore.Server.Kestrel.Performance { [Config(typeof(CoreConfig))] - public class ResponseHeadersBenchmark + public class ResponseHeaderCollectionBenchmark { private const int InnerLoopCount = 512; @@ -21,27 +21,42 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance private FrameResponseHeaders _responseHeadersDirect; private HttpResponse _response; - [Params("ContentLengthNumeric", "ContentLengthString", "Plaintext", "Common", "Unknown")] - public string Type { get; set; } + public enum BenchmarkTypes + { + ContentLengthNumeric, + ContentLengthString, + Plaintext, + Common, + Unknown + } + + [Params( + BenchmarkTypes.ContentLengthNumeric, + BenchmarkTypes.ContentLengthString, + BenchmarkTypes.Plaintext, + BenchmarkTypes.Common, + BenchmarkTypes.Unknown + )] + public BenchmarkTypes Type { get; set; } [Benchmark(OperationsPerInvoke = InnerLoopCount)] public void SetHeaders() { switch (Type) { - case "ContentLengthNumeric": + case BenchmarkTypes.ContentLengthNumeric: ContentLengthNumeric(InnerLoopCount); break; - case "ContentLengthString": + case BenchmarkTypes.ContentLengthString: ContentLengthString(InnerLoopCount); break; - case "Plaintext": + case BenchmarkTypes.Plaintext: Plaintext(InnerLoopCount); break; - case "Common": + case BenchmarkTypes.Common: Common(InnerLoopCount); break; - case "Unknown": + case BenchmarkTypes.Unknown: Unknown(InnerLoopCount); break; } @@ -163,19 +178,19 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance switch (Type) { - case "ContentLengthNumeric": + case BenchmarkTypes.ContentLengthNumeric: ContentLengthNumeric(1); break; - case "ContentLengthString": + case BenchmarkTypes.ContentLengthString: ContentLengthString(1); break; - case "Plaintext": + case BenchmarkTypes.Plaintext: Plaintext(1); break; - case "Common": + case BenchmarkTypes.Common: Common(1); break; - case "Unknown": + case BenchmarkTypes.Unknown: Unknown(1); break; } diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/ResponseHeadersWritingBenchmark.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/ResponseHeadersWritingBenchmark.cs new file mode 100644 index 0000000000..dd89ce2546 --- /dev/null +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/ResponseHeadersWritingBenchmark.cs @@ -0,0 +1,151 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.IO.Pipelines; +using System.Net; +using System.Text; +using System.Threading; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Server.Kestrel.Internal; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; +using Microsoft.AspNetCore.Testing; +using BenchmarkDotNet.Attributes; +using Moq; + +namespace Microsoft.AspNetCore.Server.Kestrel.Performance +{ + [Config(typeof(CoreConfig))] + public class ResponseHeadersWritingBenchmark + { + private static readonly byte[] _helloWorldPayload = Encoding.ASCII.GetBytes("Hello, World!"); + + private readonly TestFrame _frame; + + public ResponseHeadersWritingBenchmark() + { + _frame = MakeFrame(); + } + + public enum BenchmarkTypes + { + TechEmpowerPlaintext, + PlaintextChunked, + PlaintextWithCookie, + PlaintextChunkedWithCookie, + LiveAspNet + } + + [Params( + BenchmarkTypes.TechEmpowerPlaintext, + BenchmarkTypes.PlaintextChunked, + BenchmarkTypes.PlaintextWithCookie, + BenchmarkTypes.PlaintextChunkedWithCookie, + BenchmarkTypes.LiveAspNet + )] + public BenchmarkTypes Type { get; set; } + + [Benchmark] + public async Task Output() + { + _frame.Reset(); + _frame.StatusCode = 200; + + Task writeTask = Task.CompletedTask; + switch (Type) + { + case BenchmarkTypes.TechEmpowerPlaintext: + writeTask = TechEmpowerPlaintext(); + break; + case BenchmarkTypes.PlaintextChunked: + writeTask = PlaintextChunked(); + break; + case BenchmarkTypes.PlaintextWithCookie: + writeTask = PlaintextWithCookie(); + break; + case BenchmarkTypes.PlaintextChunkedWithCookie: + writeTask = PlaintextChunkedWithCookie(); + break; + case BenchmarkTypes.LiveAspNet: + writeTask = LiveAspNet(); + break; + } + + await writeTask; + await _frame.ProduceEndAsync(); + } + + private Task TechEmpowerPlaintext() + { + var responseHeaders = _frame.ResponseHeaders; + responseHeaders["Content-Type"] = "text/plain"; + responseHeaders.ContentLength = _helloWorldPayload.Length; + return _frame.WriteAsync(new ArraySegment(_helloWorldPayload), default(CancellationToken)); + } + + private Task PlaintextChunked() + { + var responseHeaders = _frame.ResponseHeaders; + responseHeaders["Content-Type"] = "text/plain"; + return _frame.WriteAsync(new ArraySegment(_helloWorldPayload), default(CancellationToken)); + } + + private Task LiveAspNet() + { + var responseHeaders = _frame.ResponseHeaders; + responseHeaders["Content-Encoding"] = "gzip"; + responseHeaders["Content-Type"] = "text/html; charset=utf-8"; + responseHeaders["Strict-Transport-Security"] = "max-age=31536000; includeSubdomains"; + responseHeaders["Vary"] = "Accept-Encoding"; + responseHeaders["X-Powered-By"] = "ASP.NET"; + return _frame.WriteAsync(new ArraySegment(_helloWorldPayload), default(CancellationToken)); + } + + private Task PlaintextWithCookie() + { + var responseHeaders = _frame.ResponseHeaders; + responseHeaders["Content-Type"] = "text/plain"; + responseHeaders["Set-Cookie"] = "prov=20629ccd-8b0f-e8ef-2935-cd26609fc0bc; __qca=P0-1591065732-1479167353442; _ga=GA1.2.1298898376.1479167354; _gat=1; sgt=id=9519gfde_3347_4762_8762_df51458c8ec2; acct=t=why-is-%e0%a5%a7%e0%a5%a8%e0%a5%a9-numeric&s=why-is-%e0%a5%a7%e0%a5%a8%e0%a5%a9-numeric"; + responseHeaders.ContentLength = _helloWorldPayload.Length; + return _frame.WriteAsync(new ArraySegment(_helloWorldPayload), default(CancellationToken)); + } + + private Task PlaintextChunkedWithCookie() + { + var responseHeaders = _frame.ResponseHeaders; + responseHeaders["Content-Type"] = "text/plain"; + responseHeaders["Set-Cookie"] = "prov=20629ccd-8b0f-e8ef-2935-cd26609fc0bc; __qca=P0-1591065732-1479167353442; _ga=GA1.2.1298898376.1479167354; _gat=1; sgt=id=9519gfde_3347_4762_8762_df51458c8ec2; acct=t=why-is-%e0%a5%a7%e0%a5%a8%e0%a5%a9-numeric&s=why-is-%e0%a5%a7%e0%a5%a8%e0%a5%a9-numeric"; + return _frame.WriteAsync(new ArraySegment(_helloWorldPayload), default(CancellationToken)); + } + + private TestFrame MakeFrame() + { + var socketInput = new PipeFactory().Create(); + + var serviceContext = new ServiceContext + { + DateHeaderValueManager = new DateHeaderValueManager(), + ServerOptions = new KestrelServerOptions(), + Log = Mock.Of() + }; + var listenerContext = new ListenerContext(serviceContext) + { + ListenOptions = new ListenOptions(new IPEndPoint(IPAddress.Loopback, 5000)) + }; + var connectionContext = new ConnectionContext(listenerContext) + { + Input = socketInput, + Output = new MockSocketOutput(), + ConnectionControl = Mock.Of() + }; + connectionContext.ListenerContext.ServiceContext.HttpParserFactory = f => new Internal.Http.KestrelHttpParser(log: null); + + var frame = new TestFrame(application: null, context: connectionContext); + frame.Reset(); + frame.InitializeHeaders(); + + return frame; + } + } +} From 6d2001c67adea285a5e196438bad9b2546c8aa10 Mon Sep 17 00:00:00 2001 From: Justin Van Patten Date: Sat, 18 Mar 2017 12:42:31 -0700 Subject: [PATCH 1129/1662] Remove explicit static constructors (#1483) Explicit static cctors cause the C# compiler to not mark types as beforefieldinit, which means the JIT will add checks to each static method and instance constructor of the type to make sure that the static constructor was previously called. --- .../Internal/Infrastructure/HttpUtilities.cs | 48 +++++---- .../Internal/Infrastructure/KestrelTrace.cs | 102 ++++++++++-------- .../Internal/Networking/PlatformApis.cs | 10 +- 3 files changed, 87 insertions(+), 73 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/HttpUtilities.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/HttpUtilities.cs index 32481ef1b1..003c8ccc8e 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/HttpUtilities.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/HttpUtilities.cs @@ -41,29 +41,33 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure private readonly static ulong _mask5Chars = GetMaskAsLong(new byte[] { 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00 }); private readonly static ulong _mask4Chars = GetMaskAsLong(new byte[] { 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00 }); - private readonly static Tuple[] _knownMethods = new Tuple[8]; - - private readonly static string[] _methodNames = new string[9]; - - static HttpUtilities() + private readonly static Tuple[] _knownMethods = { - _knownMethods[0] = Tuple.Create(_mask4Chars, _httpPutMethodLong, HttpMethod.Put, 3); - _knownMethods[1] = Tuple.Create(_mask5Chars, _httpPostMethodLong, HttpMethod.Post, 4); - _knownMethods[2] = Tuple.Create(_mask5Chars, _httpHeadMethodLong, HttpMethod.Head, 4); - _knownMethods[3] = Tuple.Create(_mask6Chars, _httpTraceMethodLong, HttpMethod.Trace, 5); - _knownMethods[4] = Tuple.Create(_mask6Chars, _httpPatchMethodLong, HttpMethod.Patch, 5); - _knownMethods[5] = Tuple.Create(_mask7Chars, _httpDeleteMethodLong, HttpMethod.Delete, 6); - _knownMethods[6] = Tuple.Create(_mask8Chars, _httpConnectMethodLong, HttpMethod.Connect, 7); - _knownMethods[7] = Tuple.Create(_mask8Chars, _httpOptionsMethodLong, HttpMethod.Options, 7); - _methodNames[(byte)HttpMethod.Get] = HttpMethods.Get; - _methodNames[(byte)HttpMethod.Put] = HttpMethods.Put; - _methodNames[(byte)HttpMethod.Delete] = HttpMethods.Delete; - _methodNames[(byte)HttpMethod.Post] = HttpMethods.Post; - _methodNames[(byte)HttpMethod.Head] = HttpMethods.Head; - _methodNames[(byte)HttpMethod.Trace] = HttpMethods.Trace; - _methodNames[(byte)HttpMethod.Patch] = HttpMethods.Patch; - _methodNames[(byte)HttpMethod.Connect] = HttpMethods.Connect; - _methodNames[(byte)HttpMethod.Options] = HttpMethods.Options; + Tuple.Create(_mask4Chars, _httpPutMethodLong, HttpMethod.Put, 3), + Tuple.Create(_mask5Chars, _httpPostMethodLong, HttpMethod.Post, 4), + Tuple.Create(_mask5Chars, _httpHeadMethodLong, HttpMethod.Head, 4), + Tuple.Create(_mask6Chars, _httpTraceMethodLong, HttpMethod.Trace, 5), + Tuple.Create(_mask6Chars, _httpPatchMethodLong, HttpMethod.Patch, 5), + Tuple.Create(_mask7Chars, _httpDeleteMethodLong, HttpMethod.Delete, 6), + Tuple.Create(_mask8Chars, _httpConnectMethodLong, HttpMethod.Connect, 7), + Tuple.Create(_mask8Chars, _httpOptionsMethodLong, HttpMethod.Options, 7), + }; + + private readonly static string[] _methodNames = CreateMethodNames(); + + private static string[] CreateMethodNames() + { + var methodNames = new string[9]; + methodNames[(byte)HttpMethod.Get] = HttpMethods.Get; + methodNames[(byte)HttpMethod.Put] = HttpMethods.Put; + methodNames[(byte)HttpMethod.Delete] = HttpMethods.Delete; + methodNames[(byte)HttpMethod.Post] = HttpMethods.Post; + methodNames[(byte)HttpMethod.Head] = HttpMethods.Head; + methodNames[(byte)HttpMethod.Trace] = HttpMethods.Trace; + methodNames[(byte)HttpMethod.Patch] = HttpMethods.Patch; + methodNames[(byte)HttpMethod.Connect] = HttpMethods.Connect; + methodNames[(byte)HttpMethod.Options] = HttpMethods.Options; + return methodNames; } private unsafe static ulong GetAsciiStringAsLong(string str) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/KestrelTrace.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/KestrelTrace.cs index 9dcd15eedc..94f85518b6 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/KestrelTrace.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/KestrelTrace.cs @@ -12,52 +12,68 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal /// public class KestrelTrace : IKestrelTrace { - private static readonly Action _connectionStart; - private static readonly Action _connectionStop; - private static readonly Action _connectionPause; - private static readonly Action _connectionResume; - private static readonly Action _connectionReadFin; - private static readonly Action _connectionWriteFin; - private static readonly Action _connectionWroteFin; - private static readonly Action _connectionKeepAlive; - private static readonly Action _connectionDisconnect; - private static readonly Action _applicationError; - private static readonly Action _connectionError; - private static readonly Action _connectionDisconnectedWrite; - private static readonly Action _connectionHeadResponseBodyWrite; - private static readonly Action _notAllConnectionsClosedGracefully; - private static readonly Action _notAllConnectionsAborted; - private static readonly Action _connectionBadRequest; - private static readonly Action _connectionReset; - private static readonly Action _requestProcessingError; + private static readonly Action _connectionStart = + LoggerMessage.Define(LogLevel.Debug, 1, @"Connection id ""{ConnectionId}"" started."); + + private static readonly Action _connectionStop = + LoggerMessage.Define(LogLevel.Debug, 2, @"Connection id ""{ConnectionId}"" stopped."); + + // ConnectionRead: Reserved: 3 + + private static readonly Action _connectionPause = + LoggerMessage.Define(LogLevel.Debug, 4, @"Connection id ""{ConnectionId}"" paused."); + + private static readonly Action _connectionResume = + LoggerMessage.Define(LogLevel.Debug, 5, @"Connection id ""{ConnectionId}"" resumed."); + + private static readonly Action _connectionReadFin = + LoggerMessage.Define(LogLevel.Debug, 6, @"Connection id ""{ConnectionId}"" received FIN."); + + private static readonly Action _connectionWriteFin = + LoggerMessage.Define(LogLevel.Debug, 7, @"Connection id ""{ConnectionId}"" sending FIN."); + + private static readonly Action _connectionWroteFin = + LoggerMessage.Define(LogLevel.Debug, 8, @"Connection id ""{ConnectionId}"" sent FIN with status ""{Status}""."); + + private static readonly Action _connectionKeepAlive = + LoggerMessage.Define(LogLevel.Debug, 9, @"Connection id ""{ConnectionId}"" completed keep alive response."); + + private static readonly Action _connectionDisconnect = + LoggerMessage.Define(LogLevel.Debug, 10, @"Connection id ""{ConnectionId}"" disconnecting."); + + // ConnectionWrite: Reserved: 11 + + // ConnectionWriteCallback: Reserved: 12 + + private static readonly Action _applicationError = + LoggerMessage.Define(LogLevel.Error, 13, @"Connection id ""{ConnectionId}"": An unhandled exception was thrown by the application."); + + private static readonly Action _connectionError = + LoggerMessage.Define(LogLevel.Information, 14, @"Connection id ""{ConnectionId}"" communication error."); + + private static readonly Action _connectionDisconnectedWrite = + LoggerMessage.Define(LogLevel.Debug, 15, @"Connection id ""{ConnectionId}"" write of ""{count}"" bytes to disconnected client."); + + private static readonly Action _notAllConnectionsClosedGracefully = + LoggerMessage.Define(LogLevel.Debug, 16, "Some connections failed to close gracefully during server shutdown."); + + private static readonly Action _connectionBadRequest = + LoggerMessage.Define(LogLevel.Information, 17, @"Connection id ""{ConnectionId}"" bad request data: ""{message}"""); + + private static readonly Action _connectionHeadResponseBodyWrite = + LoggerMessage.Define(LogLevel.Debug, 18, @"Connection id ""{ConnectionId}"" write of ""{count}"" body bytes to non-body HEAD response."); + + private static readonly Action _connectionReset = + LoggerMessage.Define(LogLevel.Debug, 19, @"Connection id ""{ConnectionId}"" reset."); + + private static readonly Action _requestProcessingError = + LoggerMessage.Define(LogLevel.Information, 20, @"Connection id ""{ConnectionId}"" request processing ended abnormally."); + + private static readonly Action _notAllConnectionsAborted = + LoggerMessage.Define(LogLevel.Debug, 21, "Some connections failed to abort during server shutdown."); protected readonly ILogger _logger; - static KestrelTrace() - { - _connectionStart = LoggerMessage.Define(LogLevel.Debug, 1, @"Connection id ""{ConnectionId}"" started."); - _connectionStop = LoggerMessage.Define(LogLevel.Debug, 2, @"Connection id ""{ConnectionId}"" stopped."); - // ConnectionRead: Reserved: 3 - _connectionPause = LoggerMessage.Define(LogLevel.Debug, 4, @"Connection id ""{ConnectionId}"" paused."); - _connectionResume = LoggerMessage.Define(LogLevel.Debug, 5, @"Connection id ""{ConnectionId}"" resumed."); - _connectionReadFin = LoggerMessage.Define(LogLevel.Debug, 6, @"Connection id ""{ConnectionId}"" received FIN."); - _connectionWriteFin = LoggerMessage.Define(LogLevel.Debug, 7, @"Connection id ""{ConnectionId}"" sending FIN."); - _connectionWroteFin = LoggerMessage.Define(LogLevel.Debug, 8, @"Connection id ""{ConnectionId}"" sent FIN with status ""{Status}""."); - _connectionKeepAlive = LoggerMessage.Define(LogLevel.Debug, 9, @"Connection id ""{ConnectionId}"" completed keep alive response."); - _connectionDisconnect = LoggerMessage.Define(LogLevel.Debug, 10, @"Connection id ""{ConnectionId}"" disconnecting."); - // ConnectionWrite: Reserved: 11 - // ConnectionWriteCallback: Reserved: 12 - _applicationError = LoggerMessage.Define(LogLevel.Error, 13, @"Connection id ""{ConnectionId}"": An unhandled exception was thrown by the application."); - _connectionError = LoggerMessage.Define(LogLevel.Information, 14, @"Connection id ""{ConnectionId}"" communication error."); - _connectionDisconnectedWrite = LoggerMessage.Define(LogLevel.Debug, 15, @"Connection id ""{ConnectionId}"" write of ""{count}"" bytes to disconnected client."); - _notAllConnectionsClosedGracefully = LoggerMessage.Define(LogLevel.Debug, 16, "Some connections failed to close gracefully during server shutdown."); - _connectionBadRequest = LoggerMessage.Define(LogLevel.Information, 17, @"Connection id ""{ConnectionId}"" bad request data: ""{message}"""); - _connectionHeadResponseBodyWrite = LoggerMessage.Define(LogLevel.Debug, 18, @"Connection id ""{ConnectionId}"" write of ""{count}"" body bytes to non-body HEAD response."); - _connectionReset = LoggerMessage.Define(LogLevel.Debug, 19, @"Connection id ""{ConnectionId}"" reset."); - _requestProcessingError = LoggerMessage.Define(LogLevel.Information, 20, @"Connection id ""{ConnectionId}"" request processing ended abnormally."); - _notAllConnectionsAborted = LoggerMessage.Define(LogLevel.Debug, 21, "Some connections failed to abort during server shutdown."); - } - public KestrelTrace(ILogger logger) { _logger = logger; diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/PlatformApis.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/PlatformApis.cs index 6cd2341815..5bb37f60a9 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/PlatformApis.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/PlatformApis.cs @@ -10,15 +10,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking { public static class PlatformApis { - static PlatformApis() - { - IsWindows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows); - IsDarwin = RuntimeInformation.IsOSPlatform(OSPlatform.OSX); - } + public static bool IsWindows { get; } = RuntimeInformation.IsOSPlatform(OSPlatform.Windows); - public static bool IsWindows { get; } - - public static bool IsDarwin { get; } + public static bool IsDarwin { get; } = RuntimeInformation.IsOSPlatform(OSPlatform.OSX); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long VolatileRead(ref long value) From 1094cc06708f0ebb7be539e1f00900f12758a75f Mon Sep 17 00:00:00 2001 From: David Fowler Date: Sat, 18 Mar 2017 13:20:07 -0700 Subject: [PATCH 1130/1662] Use StreamSocketOutput for writing benchmarks (#1507) - Use StreamSocketOutput with a null stream to get a better picture of what actual performance looks like --- .../ResponseHeadersWritingBenchmark.cs | 51 +++++++++++-------- 1 file changed, 29 insertions(+), 22 deletions(-) diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/ResponseHeadersWritingBenchmark.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/ResponseHeadersWritingBenchmark.cs index dd89ce2546..0fb6aab65d 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/ResponseHeadersWritingBenchmark.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/ResponseHeadersWritingBenchmark.cs @@ -2,16 +2,18 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.IO; using System.IO.Pipelines; using System.Net; using System.Text; using System.Threading; using System.Threading.Tasks; +using BenchmarkDotNet.Attributes; +using Microsoft.AspNetCore.Server.Kestrel.Adapter.Internal; using Microsoft.AspNetCore.Server.Kestrel.Internal; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.AspNetCore.Testing; -using BenchmarkDotNet.Attributes; using Moq; namespace Microsoft.AspNetCore.Server.Kestrel.Performance @@ -21,21 +23,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance { private static readonly byte[] _helloWorldPayload = Encoding.ASCII.GetBytes("Hello, World!"); - private readonly TestFrame _frame; - - public ResponseHeadersWritingBenchmark() - { - _frame = MakeFrame(); - } - - public enum BenchmarkTypes - { - TechEmpowerPlaintext, - PlaintextChunked, - PlaintextWithCookie, - PlaintextChunkedWithCookie, - LiveAspNet - } + private TestFrame _frame; [Params( BenchmarkTypes.TechEmpowerPlaintext, @@ -119,9 +107,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance return _frame.WriteAsync(new ArraySegment(_helloWorldPayload), default(CancellationToken)); } - private TestFrame MakeFrame() + [Setup] + public void Setup() { - var socketInput = new PipeFactory().Create(); + var factory = new PipeFactory(); + var input = factory.Create(); + var output = factory.Create(); + var socketOutput = new StreamSocketOutput(Stream.Null, output); var serviceContext = new ServiceContext { @@ -129,23 +121,38 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance ServerOptions = new KestrelServerOptions(), Log = Mock.Of() }; + var listenerContext = new ListenerContext(serviceContext) { ListenOptions = new ListenOptions(new IPEndPoint(IPAddress.Loopback, 5000)) }; + var connectionContext = new ConnectionContext(listenerContext) { - Input = socketInput, - Output = new MockSocketOutput(), + Input = input, + Output = socketOutput, ConnectionControl = Mock.Of() }; - connectionContext.ListenerContext.ServiceContext.HttpParserFactory = f => new Internal.Http.KestrelHttpParser(log: null); + + connectionContext.ListenerContext.ServiceContext.HttpParserFactory = f => new KestrelHttpParser(log: null); var frame = new TestFrame(application: null, context: connectionContext); frame.Reset(); frame.InitializeHeaders(); - return frame; + // Start writing + var ignore = socketOutput.WriteOutputAsync(); + + _frame = frame; + } + + public enum BenchmarkTypes + { + TechEmpowerPlaintext, + PlaintextChunked, + PlaintextWithCookie, + PlaintextChunkedWithCookie, + LiveAspNet } } } From f6e5e74d9551df57effda19c856352608374cee7 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Sat, 18 Mar 2017 15:42:01 -0700 Subject: [PATCH 1131/1662] Update packages (#1509) * Update packages * React to API changes in corefxlab --- build/dependencies.props | 4 ++-- .../Internal/Http/KestrelHttpParser.cs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/build/dependencies.props b/build/dependencies.props index 74d0c3c23b..cc4fbc7fdc 100644 --- a/build/dependencies.props +++ b/build/dependencies.props @@ -1,8 +1,8 @@ 1.2.0-* - 0.1.0-e170313-1 - 0.1.0-e170313-1 + 0.1.0-* + 0.1.0-* 4.3.0 1.9.1 9.0.1 diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/KestrelHttpParser.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/KestrelHttpParser.cs index 71a49c2f45..e76515b042 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/KestrelHttpParser.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/KestrelHttpParser.cs @@ -36,7 +36,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http // Prepare the first span var span = buffer.First.Span; - var lineIndex = span.IndexOfVectorized(ByteLF); + var lineIndex = span.SequentialIndexOf(ByteLF); if (lineIndex >= 0) { consumed = buffer.Move(consumed, lineIndex + 1); @@ -255,7 +255,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http index = reader.Index; } - var endIndex = new Span(pBuffer + index, remaining).IndexOfVectorized(ByteLF); + var endIndex = new Span(pBuffer + index, remaining).SequentialIndexOf(ByteLF); var length = 0; if (endIndex != -1) From f1e0143d5172ad0d8146176f82c40d70aa793b9c Mon Sep 17 00:00:00 2001 From: David Fowler Date: Sun, 19 Mar 2017 01:31:11 -0700 Subject: [PATCH 1132/1662] React to corefxlab changes (#1510) * React to latest CoreFxLab changes --- .../Internal/Http/Connection.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Connection.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Connection.cs index 3708cf52a1..d2abc6ead2 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Connection.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Connection.cs @@ -301,7 +301,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if (flushTask?.IsCompleted == false) { OnPausePosted(); - if (await flushTask.Value) + var result = await flushTask.Value; + // If the reader isn't complete then resume + if (!result.IsCompleted) { OnResumePosted(); } From 2ed456fd68283b64943b29cf030d59c056d28027 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Sun, 19 Mar 2017 12:44:01 -0700 Subject: [PATCH 1133/1662] Faster Write implementation using cpblk (#1511) * Faster Write implementation - Use Unsafe.CopyBlockUnaligned to copy bytes to the WritableBuffer. This is temporary until we get newer corefx bits with a better span.CopyTo implementation. - Remove WritableBufferExtensions from Performance project - Split method into WriteFast and WriteMultiBuffer - Cache the span for the common case where the buffer is non empty. - Use ref locals instead of pinning pointers in fast path --- .../Adapter/Internal/StreamSocketOutput.cs | 6 +- .../Internal/Http/ChunkWriter.cs | 4 +- .../Internal/Http/Frame.cs | 14 ++-- .../Internal/Http/FrameHeaders.Generated.cs | 80 +++++++++---------- .../Internal/Http/FrameResponseHeaders.cs | 4 +- .../Internal/Http/PipelineExtensions.cs | 63 ++++++++++++++- .../WritableBufferExtensions.cs | 63 --------------- tools/CodeGenerator/KnownHeaders.cs | 6 +- 8 files changed, 116 insertions(+), 124 deletions(-) delete mode 100644 test/Microsoft.AspNetCore.Server.Kestrel.Performance/WritableBufferExtensions.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Adapter/Internal/StreamSocketOutput.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Adapter/Internal/StreamSocketOutput.cs index 0e17b99ae1..ed1d069f59 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Adapter/Internal/StreamSocketOutput.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Adapter/Internal/StreamSocketOutput.cs @@ -48,12 +48,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Adapter.Internal if (chunk) { ChunkWriter.WriteBeginChunkBytes(ref writableBuffer, buffer.Count); - writableBuffer.Write(buffer); + writableBuffer.WriteFast(buffer); ChunkWriter.WriteEndChunkBytes(ref writableBuffer); } else { - writableBuffer.Write(buffer); + writableBuffer.WriteFast(buffer); } } @@ -119,8 +119,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Adapter.Internal { _pipe.Reader.Advance(readResult.Buffer.End); } - - // REVIEW: Should we flush here? } } finally diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ChunkWriter.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ChunkWriter.cs index 9846d42a04..8b69ba4603 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ChunkWriter.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ChunkWriter.cs @@ -51,13 +51,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http public static int WriteBeginChunkBytes(ref WritableBuffer start, int dataCount) { var chunkSegment = BeginChunkBytes(dataCount); - start.Write(chunkSegment); + start.WriteFast(chunkSegment); return chunkSegment.Count; } public static void WriteEndChunkBytes(ref WritableBuffer start) { - start.Write(_endChunkBytes); + start.WriteFast(_endChunkBytes); } } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs index f5d1b49b84..8c5f032a1e 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs @@ -891,8 +891,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var hasTransferEncoding = responseHeaders.HasTransferEncoding; var transferCoding = FrameHeaders.GetFinalTransferCoding(responseHeaders.HeaderTransferEncoding); - var end = Output.Alloc(); - if (_keepAlive && hasConnection) { _keepAlive = (connectionOptions & ConnectionOptions.KeepAlive) == ConnectionOptions.KeepAlive; @@ -974,12 +972,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http responseHeaders.SetRawDate(dateHeaderValues.String, dateHeaderValues.Bytes); } - end.Write(_bytesHttpVersion11); - end.Write(statusBytes); - responseHeaders.CopyTo(ref end); - end.Write(_bytesEndHeaders); - - end.Commit(); + var writableBuffer = Output.Alloc(); + writableBuffer.WriteFast(_bytesHttpVersion11); + writableBuffer.WriteFast(statusBytes); + responseHeaders.CopyTo(ref writableBuffer); + writableBuffer.WriteFast(_bytesEndHeaders); + writableBuffer.Commit(); } public void ParseRequest(ReadableBuffer buffer, out ReadCursor consumed, out ReadCursor examined) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameHeaders.Generated.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameHeaders.Generated.cs index da9147f69f..ff13b9383c 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameHeaders.Generated.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameHeaders.Generated.cs @@ -7761,7 +7761,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { if (_headers._rawConnection != null) { - output.Write(_headers._rawConnection); + output.WriteFast(_headers._rawConnection); } else { @@ -7771,7 +7771,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var value = _headers._Connection[i]; if (value != null) { - output.Write(new Span(_headerBytes, 17, 14)); + output.WriteFast(new Span(_headerBytes, 17, 14)); output.WriteAscii(value); } } @@ -7787,7 +7787,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { if (_headers._rawDate != null) { - output.Write(_headers._rawDate); + output.WriteFast(_headers._rawDate); } else { @@ -7797,7 +7797,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var value = _headers._Date[i]; if (value != null) { - output.Write(new Span(_headerBytes, 31, 8)); + output.WriteFast(new Span(_headerBytes, 31, 8)); output.WriteAscii(value); } } @@ -7818,7 +7818,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var value = _headers._ContentType[i]; if (value != null) { - output.Write(new Span(_headerBytes, 133, 16)); + output.WriteFast(new Span(_headerBytes, 133, 16)); output.WriteAscii(value); } } @@ -7834,7 +7834,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { if (_headers._rawServer != null) { - output.Write(_headers._rawServer); + output.WriteFast(_headers._rawServer); } else { @@ -7844,7 +7844,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var value = _headers._Server[i]; if (value != null) { - output.Write(new Span(_headerBytes, 350, 10)); + output.WriteFast(new Span(_headerBytes, 350, 10)); output.WriteAscii(value); } } @@ -7858,7 +7858,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } if ((tempBits & -9223372036854775808L) != 0) { - output.Write(new Span(_headerBytes, 592, 18)); + output.WriteFast(new Span(_headerBytes, 592, 18)); output.WriteNumeric((ulong)ContentLength.Value); if((tempBits & ~-9223372036854775808L) == 0) @@ -7876,7 +7876,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var value = _headers._CacheControl[i]; if (value != null) { - output.Write(new Span(_headerBytes, 0, 17)); + output.WriteFast(new Span(_headerBytes, 0, 17)); output.WriteAscii(value); } } @@ -7897,7 +7897,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var value = _headers._KeepAlive[i]; if (value != null) { - output.Write(new Span(_headerBytes, 39, 14)); + output.WriteFast(new Span(_headerBytes, 39, 14)); output.WriteAscii(value); } } @@ -7918,7 +7918,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var value = _headers._Pragma[i]; if (value != null) { - output.Write(new Span(_headerBytes, 53, 10)); + output.WriteFast(new Span(_headerBytes, 53, 10)); output.WriteAscii(value); } } @@ -7939,7 +7939,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var value = _headers._Trailer[i]; if (value != null) { - output.Write(new Span(_headerBytes, 63, 11)); + output.WriteFast(new Span(_headerBytes, 63, 11)); output.WriteAscii(value); } } @@ -7955,7 +7955,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { if (_headers._rawTransferEncoding != null) { - output.Write(_headers._rawTransferEncoding); + output.WriteFast(_headers._rawTransferEncoding); } else { @@ -7965,7 +7965,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var value = _headers._TransferEncoding[i]; if (value != null) { - output.Write(new Span(_headerBytes, 74, 21)); + output.WriteFast(new Span(_headerBytes, 74, 21)); output.WriteAscii(value); } } @@ -7986,7 +7986,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var value = _headers._Upgrade[i]; if (value != null) { - output.Write(new Span(_headerBytes, 95, 11)); + output.WriteFast(new Span(_headerBytes, 95, 11)); output.WriteAscii(value); } } @@ -8007,7 +8007,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var value = _headers._Via[i]; if (value != null) { - output.Write(new Span(_headerBytes, 106, 7)); + output.WriteFast(new Span(_headerBytes, 106, 7)); output.WriteAscii(value); } } @@ -8028,7 +8028,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var value = _headers._Warning[i]; if (value != null) { - output.Write(new Span(_headerBytes, 113, 11)); + output.WriteFast(new Span(_headerBytes, 113, 11)); output.WriteAscii(value); } } @@ -8049,7 +8049,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var value = _headers._Allow[i]; if (value != null) { - output.Write(new Span(_headerBytes, 124, 9)); + output.WriteFast(new Span(_headerBytes, 124, 9)); output.WriteAscii(value); } } @@ -8070,7 +8070,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var value = _headers._ContentEncoding[i]; if (value != null) { - output.Write(new Span(_headerBytes, 149, 20)); + output.WriteFast(new Span(_headerBytes, 149, 20)); output.WriteAscii(value); } } @@ -8091,7 +8091,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var value = _headers._ContentLanguage[i]; if (value != null) { - output.Write(new Span(_headerBytes, 169, 20)); + output.WriteFast(new Span(_headerBytes, 169, 20)); output.WriteAscii(value); } } @@ -8112,7 +8112,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var value = _headers._ContentLocation[i]; if (value != null) { - output.Write(new Span(_headerBytes, 189, 20)); + output.WriteFast(new Span(_headerBytes, 189, 20)); output.WriteAscii(value); } } @@ -8133,7 +8133,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var value = _headers._ContentMD5[i]; if (value != null) { - output.Write(new Span(_headerBytes, 209, 15)); + output.WriteFast(new Span(_headerBytes, 209, 15)); output.WriteAscii(value); } } @@ -8154,7 +8154,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var value = _headers._ContentRange[i]; if (value != null) { - output.Write(new Span(_headerBytes, 224, 17)); + output.WriteFast(new Span(_headerBytes, 224, 17)); output.WriteAscii(value); } } @@ -8175,7 +8175,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var value = _headers._Expires[i]; if (value != null) { - output.Write(new Span(_headerBytes, 241, 11)); + output.WriteFast(new Span(_headerBytes, 241, 11)); output.WriteAscii(value); } } @@ -8196,7 +8196,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var value = _headers._LastModified[i]; if (value != null) { - output.Write(new Span(_headerBytes, 252, 17)); + output.WriteFast(new Span(_headerBytes, 252, 17)); output.WriteAscii(value); } } @@ -8217,7 +8217,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var value = _headers._AcceptRanges[i]; if (value != null) { - output.Write(new Span(_headerBytes, 269, 17)); + output.WriteFast(new Span(_headerBytes, 269, 17)); output.WriteAscii(value); } } @@ -8238,7 +8238,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var value = _headers._Age[i]; if (value != null) { - output.Write(new Span(_headerBytes, 286, 7)); + output.WriteFast(new Span(_headerBytes, 286, 7)); output.WriteAscii(value); } } @@ -8259,7 +8259,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var value = _headers._ETag[i]; if (value != null) { - output.Write(new Span(_headerBytes, 293, 8)); + output.WriteFast(new Span(_headerBytes, 293, 8)); output.WriteAscii(value); } } @@ -8280,7 +8280,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var value = _headers._Location[i]; if (value != null) { - output.Write(new Span(_headerBytes, 301, 12)); + output.WriteFast(new Span(_headerBytes, 301, 12)); output.WriteAscii(value); } } @@ -8301,7 +8301,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var value = _headers._ProxyAuthenticate[i]; if (value != null) { - output.Write(new Span(_headerBytes, 313, 22)); + output.WriteFast(new Span(_headerBytes, 313, 22)); output.WriteAscii(value); } } @@ -8322,7 +8322,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var value = _headers._RetryAfter[i]; if (value != null) { - output.Write(new Span(_headerBytes, 335, 15)); + output.WriteFast(new Span(_headerBytes, 335, 15)); output.WriteAscii(value); } } @@ -8343,7 +8343,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var value = _headers._SetCookie[i]; if (value != null) { - output.Write(new Span(_headerBytes, 360, 14)); + output.WriteFast(new Span(_headerBytes, 360, 14)); output.WriteAscii(value); } } @@ -8364,7 +8364,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var value = _headers._Vary[i]; if (value != null) { - output.Write(new Span(_headerBytes, 374, 8)); + output.WriteFast(new Span(_headerBytes, 374, 8)); output.WriteAscii(value); } } @@ -8385,7 +8385,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var value = _headers._WWWAuthenticate[i]; if (value != null) { - output.Write(new Span(_headerBytes, 382, 20)); + output.WriteFast(new Span(_headerBytes, 382, 20)); output.WriteAscii(value); } } @@ -8406,7 +8406,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var value = _headers._AccessControlAllowCredentials[i]; if (value != null) { - output.Write(new Span(_headerBytes, 402, 36)); + output.WriteFast(new Span(_headerBytes, 402, 36)); output.WriteAscii(value); } } @@ -8427,7 +8427,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var value = _headers._AccessControlAllowHeaders[i]; if (value != null) { - output.Write(new Span(_headerBytes, 438, 32)); + output.WriteFast(new Span(_headerBytes, 438, 32)); output.WriteAscii(value); } } @@ -8448,7 +8448,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var value = _headers._AccessControlAllowMethods[i]; if (value != null) { - output.Write(new Span(_headerBytes, 470, 32)); + output.WriteFast(new Span(_headerBytes, 470, 32)); output.WriteAscii(value); } } @@ -8469,7 +8469,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var value = _headers._AccessControlAllowOrigin[i]; if (value != null) { - output.Write(new Span(_headerBytes, 502, 31)); + output.WriteFast(new Span(_headerBytes, 502, 31)); output.WriteAscii(value); } } @@ -8490,7 +8490,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var value = _headers._AccessControlExposeHeaders[i]; if (value != null) { - output.Write(new Span(_headerBytes, 533, 33)); + output.WriteFast(new Span(_headerBytes, 533, 33)); output.WriteAscii(value); } } @@ -8511,7 +8511,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var value = _headers._AccessControlMaxAge[i]; if (value != null) { - output.Write(new Span(_headerBytes, 566, 26)); + output.WriteFast(new Span(_headerBytes, 566, 26)); output.WriteAscii(value); } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameResponseHeaders.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameResponseHeaders.cs index 439a76bd6a..ea51f47d10 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameResponseHeaders.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameResponseHeaders.cs @@ -46,9 +46,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { if (value != null) { - output.Write(_CrLf); + output.WriteFast(_CrLf); output.WriteAscii(kv.Key); - output.Write(_colonSpace); + output.WriteFast(_colonSpace); output.WriteAscii(value); } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/PipelineExtensions.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/PipelineExtensions.cs index 0ab6f20a68..d986106d03 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/PipelineExtensions.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/PipelineExtensions.cs @@ -95,6 +95,65 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http return result; } + // Temporary until the fast write implementation propagates from corefx + public unsafe static void WriteFast(this WritableBuffer buffer, ReadOnlySpan source) + { + var dest = buffer.Memory.Span; + var destLength = dest.Length; + + if (destLength == 0) + { + buffer.Ensure(); + + // Get the new span and length + dest = buffer.Memory.Span; + destLength = dest.Length; + } + + var sourceLength = source.Length; + if (sourceLength <= destLength) + { + ref byte pSource = ref source.DangerousGetPinnableReference(); + ref byte pDest = ref dest.DangerousGetPinnableReference(); + Unsafe.CopyBlockUnaligned(ref pDest, ref pSource, (uint)sourceLength); + buffer.Advance(sourceLength); + return; + } + + buffer.WriteMultiBuffer(source); + } + + private static unsafe void WriteMultiBuffer(this WritableBuffer buffer, ReadOnlySpan source) + { + var remaining = source.Length; + var offset = 0; + + fixed (byte* pSource = &source.DangerousGetPinnableReference()) + { + while (remaining > 0) + { + var writable = Math.Min(remaining, buffer.Memory.Length); + + buffer.Ensure(writable); + + if (writable == 0) + { + continue; + } + + fixed (byte* pDest = &buffer.Memory.Span.DangerousGetPinnableReference()) + { + Unsafe.CopyBlockUnaligned(pDest, pSource + offset, (uint)writable); + } + + remaining -= writable; + offset += writable; + + buffer.Advance(writable); + } + } + } + public unsafe static void WriteAscii(this WritableBuffer buffer, string data) { if (!string.IsNullOrEmpty(data)) @@ -193,7 +252,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http while (value != 0); var length = _maxULongByteLength - position; - buffer.Write(new ReadOnlySpan(byteBuffer, position, length)); + buffer.WriteFast(new ReadOnlySpan(byteBuffer, position, length)); } [MethodImpl(MethodImplOptions.NoInlining)] @@ -274,7 +333,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http i += 4; } - trailing: + trailing: for (; i < length; i++) { char ch = *(input + i); diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/WritableBufferExtensions.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/WritableBufferExtensions.cs deleted file mode 100644 index 04a538e4be..0000000000 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/WritableBufferExtensions.cs +++ /dev/null @@ -1,63 +0,0 @@ -using System; -using System.Collections.Generic; -using System.IO.Pipelines; -using System.Text; - -namespace Microsoft.AspNetCore.Server.Kestrel.Performance -{ - internal static class WritableBufferExtensions - { - public static void WriteFast(this WritableBuffer buffer, ReadOnlySpan source) - { - if (buffer.Memory.IsEmpty) - { - buffer.Ensure(); - } - - // Fast path, try copying to the available memory directly - if (source.Length <= buffer.Memory.Length) - { - source.CopyToFast(buffer.Memory.Span); - buffer.Advance(source.Length); - return; - } - - var remaining = source.Length; - var offset = 0; - - while (remaining > 0) - { - var writable = Math.Min(remaining, buffer.Memory.Length); - - buffer.Ensure(writable); - - if (writable == 0) - { - continue; - } - - source.Slice(offset, writable).CopyToFast(buffer.Memory.Span); - - remaining -= writable; - offset += writable; - - buffer.Advance(writable); - } - } - - private unsafe static void CopyToFast(this ReadOnlySpan source, Span destination) - { - if (destination.Length < source.Length) - { - throw new InvalidOperationException(); - } - - // Assume it fits - fixed (byte* pSource = &source.DangerousGetPinnableReference()) - fixed (byte* pDest = &destination.DangerousGetPinnableReference()) - { - Buffer.MemoryCopy(pSource, pDest, destination.Length, source.Length); - } - } - } -} diff --git a/tools/CodeGenerator/KnownHeaders.cs b/tools/CodeGenerator/KnownHeaders.cs index dee9665889..f12aea58d6 100644 --- a/tools/CodeGenerator/KnownHeaders.cs +++ b/tools/CodeGenerator/KnownHeaders.cs @@ -530,7 +530,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http {{ {(header.EnhancedSetter == false ? "" : $@" if (_headers._raw{header.Identifier} != null) {{ - output.Write(_headers._raw{header.Identifier}); + output.WriteFast(_headers._raw{header.Identifier}); }} else ")} {{ @@ -540,7 +540,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var value = _headers._{header.Identifier}[i]; if (value != null) {{ - output.Write(new Span(_headerBytes, {header.BytesOffset}, {header.BytesCount})); + output.WriteFast(new Span(_headerBytes, {header.BytesOffset}, {header.BytesCount})); output.WriteAscii(value); }} }} @@ -554,7 +554,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http }}{(header.Identifier == "Server" ? $@" if ((tempBits & {1L << 63}L) != 0) {{ - output.Write(new Span(_headerBytes, {loop.Headers.First(x => x.Identifier == "ContentLength").BytesOffset}, {loop.Headers.First(x => x.Identifier == "ContentLength").BytesCount})); + output.WriteFast(new Span(_headerBytes, {loop.Headers.First(x => x.Identifier == "ContentLength").BytesOffset}, {loop.Headers.First(x => x.Identifier == "ContentLength").BytesCount})); output.WriteNumeric((ulong)ContentLength.Value); if((tempBits & ~{1L << 63}L) == 0) From 39819d67082e2c666af9e74f8433248b38a1ca19 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Mon, 20 Mar 2017 00:11:41 -0700 Subject: [PATCH 1134/1662] Added fast path for single memory ReadableBuffer (#1512) * Special case single buffer * Added fast path for single span buffers in UvWriteReq --- .../Adapter/Internal/StreamSocketOutput.cs | 12 ++++- .../Internal/Networking/UvWriteReq.cs | 44 ++++++++++++++----- 2 files changed, 42 insertions(+), 14 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Adapter/Internal/StreamSocketOutput.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Adapter/Internal/StreamSocketOutput.cs index ed1d069f59..a5b618c8d4 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Adapter/Internal/StreamSocketOutput.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Adapter/Internal/StreamSocketOutput.cs @@ -109,11 +109,19 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Adapter.Internal await _outputStream.FlushAsync(); } - foreach (var memory in buffer) + if (buffer.IsSingleSpan) { - var array = memory.GetArray(); + var array = buffer.First.GetArray(); await _outputStream.WriteAsync(array.Array, array.Offset, array.Count); } + else + { + foreach (var memory in buffer) + { + var array = memory.GetArray(); + await _outputStream.WriteAsync(array.Array, array.Offset, array.Count); + } + } } finally { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/UvWriteReq.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/UvWriteReq.cs index 2d9ddccf2b..1134e71eaa 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/UvWriteReq.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/UvWriteReq.cs @@ -4,7 +4,6 @@ using System; using System.Buffers; using System.Collections.Generic; -using System.Diagnostics; using System.IO.Pipelines; using System.Runtime.InteropServices; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; @@ -68,9 +67,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking _pins.Add(GCHandle.Alloc(this, GCHandleType.Normal)); var nBuffers = 0; - foreach (var _ in buffer) + if (buffer.IsSingleSpan) { - nBuffers++; + nBuffers = 1; + } + else + { + foreach (var _ in buffer) + { + nBuffers++; + } } var pBuffers = (Libuv.uv_buf_t*)_bufs; @@ -82,19 +88,33 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking _pins.Add(gcHandle); pBuffers = (Libuv.uv_buf_t*)gcHandle.AddrOfPinnedObject(); } - var index = 0; - foreach (var memory in buffer) + + if (nBuffers == 1) { - // REVIEW: This isn't necessary for our default pool since the memory is - // already pinned but it also makes tests pass + var memory = buffer.First; var memoryHandle = memory.Pin(); _handles.Add(memoryHandle); - // create and pin each segment being written - pBuffers[index] = Libuv.buf_init( - (IntPtr)memoryHandle.PinnedPointer, - memory.Length); - index++; + // Fast path for single buffer + pBuffers[0] = Libuv.buf_init( + (IntPtr)memoryHandle.PinnedPointer, + memory.Length); + } + else + { + var index = 0; + foreach (var memory in buffer) + { + // This won't actually pin the buffer since we're already using pinned memory + var memoryHandle = memory.Pin(); + _handles.Add(memoryHandle); + + // create and pin each segment being written + pBuffers[index] = Libuv.buf_init( + (IntPtr)memoryHandle.PinnedPointer, + memory.Length); + index++; + } } _callback = callback; From 8923b0da702515c50f79813b60f1595ae1c7d238 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Mon, 20 Mar 2017 15:43:55 -0700 Subject: [PATCH 1135/1662] Use correct config for response buffer limit (#1516) --- .../Internal/Http/ListenerContext.cs | 2 +- .../FrameParsingOverheadBenchmark.cs | 2 +- .../RequestParsingBenchmark.cs | 2 +- .../ResponseHeaderCollectionBenchmark.cs | 2 +- .../ListenerContextTests.cs | 72 +++++++++++ .../SocketOutputTests.cs | 121 +++++++----------- test/shared/MockConnection.cs | 4 +- 7 files changed, 127 insertions(+), 78 deletions(-) create mode 100644 test/Microsoft.AspNetCore.Server.KestrelTests/ListenerContextTests.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ListenerContext.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ListenerContext.cs index 721a31bb60..4a94842ac3 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ListenerContext.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ListenerContext.cs @@ -68,7 +68,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http private long GetOutputResponseBufferSize() { - var bufferSize = ServiceContext.ServerOptions.Limits.MaxRequestBufferSize; + var bufferSize = ServiceContext.ServerOptions.Limits.MaxResponseBufferSize; if (bufferSize == 0) { // 0 = no buffering so we need to configure the pipe so the the writer waits on the reader directly diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameParsingOverheadBenchmark.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameParsingOverheadBenchmark.cs index 40bf9a6cd0..a772eee781 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameParsingOverheadBenchmark.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameParsingOverheadBenchmark.cs @@ -21,7 +21,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance [Setup] public void Setup() { - var connectionContext = new MockConnection(new KestrelServerOptions()); + var connectionContext = new MockConnection(); connectionContext.ListenerContext.ServiceContext.HttpParserFactory = frame => NullParser.Instance; _frame = new Frame(application: null, context: connectionContext); diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsingBenchmark.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsingBenchmark.cs index 0b2e0ee914..dc07d53270 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsingBenchmark.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsingBenchmark.cs @@ -21,7 +21,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance [Setup] public void Setup() { - var connectionContext = new MockConnection(new KestrelServerOptions()); + var connectionContext = new MockConnection(); connectionContext.ListenerContext.ServiceContext.HttpParserFactory = frame => new KestrelHttpParser(frame.ConnectionContext.ListenerContext.ServiceContext.Log); Frame = new Frame(application: null, context: connectionContext); diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/ResponseHeaderCollectionBenchmark.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/ResponseHeaderCollectionBenchmark.cs index 691b0da43a..48b79138b5 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/ResponseHeaderCollectionBenchmark.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/ResponseHeaderCollectionBenchmark.cs @@ -167,7 +167,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance [Setup] public void Setup() { - var connectionContext = new MockConnection(new KestrelServerOptions()); + var connectionContext = new MockConnection(); connectionContext.ListenerContext.ServiceContext.HttpParserFactory = f => new KestrelHttpParser(f.ConnectionContext.ListenerContext.ServiceContext.Log); var frame = new Frame(application: null, context: connectionContext); frame.Reset(); diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/ListenerContextTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/ListenerContextTests.cs new file mode 100644 index 0000000000..4004c95850 --- /dev/null +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/ListenerContextTests.cs @@ -0,0 +1,72 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System.IO.Pipelines; +using Microsoft.AspNetCore.Server.Kestrel.Internal; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; +using Microsoft.AspNetCore.Testing; +using Xunit; + +namespace Microsoft.AspNetCore.Server.KestrelTests +{ + public class ListenerContextTests + { + [Theory] + [InlineData(10, 10, 10)] + [InlineData(0, 1, 1)] + [InlineData(null, 0, 0)] + public void LibuvOutputPipeOptionsConfiguredCorrectly(long? maxResponseBufferSize, long expectedMaximumSizeLow, long expectedMaximumSizeHigh) + { + var serviceContext = new TestServiceContext(); + serviceContext.ServerOptions.Limits.MaxResponseBufferSize = maxResponseBufferSize; + serviceContext.ThreadPool = new LoggingThreadPool(null); + + var listenerContext = new ListenerContext(serviceContext) + { + Thread = new KestrelThread(new KestrelEngine(null, serviceContext)) + }; + + Assert.Equal(expectedMaximumSizeLow, listenerContext.LibuvOutputPipeOptions.MaximumSizeLow); + Assert.Equal(expectedMaximumSizeHigh, listenerContext.LibuvOutputPipeOptions.MaximumSizeHigh); + Assert.Same(listenerContext.Thread, listenerContext.LibuvOutputPipeOptions.ReaderScheduler); + Assert.Same(serviceContext.ThreadPool, listenerContext.LibuvOutputPipeOptions.WriterScheduler); + } + + [Theory] + [InlineData(10, 10, 10)] + [InlineData(null, 0, 0)] + public void LibuvInputPipeOptionsConfiguredCorrectly(long? maxRequestBufferSize, long expectedMaximumSizeLow, long expectedMaximumSizeHigh) + { + var serviceContext = new TestServiceContext(); + serviceContext.ServerOptions.Limits.MaxRequestBufferSize = maxRequestBufferSize; + serviceContext.ThreadPool = new LoggingThreadPool(null); + + var listenerContext = new ListenerContext(serviceContext) + { + Thread = new KestrelThread(new KestrelEngine(null, serviceContext)) + }; + + Assert.Equal(expectedMaximumSizeLow, listenerContext.LibuvInputPipeOptions.MaximumSizeLow); + Assert.Equal(expectedMaximumSizeHigh, listenerContext.LibuvInputPipeOptions.MaximumSizeHigh); + Assert.Same(serviceContext.ThreadPool, listenerContext.LibuvInputPipeOptions.ReaderScheduler); + Assert.Same(listenerContext.Thread, listenerContext.LibuvInputPipeOptions.WriterScheduler); + } + + [Theory] + [InlineData(10, 10, 10)] + [InlineData(null, 0, 0)] + public void AdaptedPipeOptionsConfiguredCorrectly(long? maxRequestBufferSize, long expectedMaximumSizeLow, long expectedMaximumSizeHigh) + { + var serviceContext = new TestServiceContext(); + serviceContext.ServerOptions.Limits.MaxRequestBufferSize = maxRequestBufferSize; + + var listenerContext = new ListenerContext(serviceContext); + + Assert.Equal(expectedMaximumSizeLow, listenerContext.AdaptedPipeOptions.MaximumSizeLow); + Assert.Equal(expectedMaximumSizeHigh, listenerContext.AdaptedPipeOptions.MaximumSizeHigh); + Assert.Same(InlineScheduler.Default, listenerContext.AdaptedPipeOptions.ReaderScheduler); + Assert.Same(InlineScheduler.Default, listenerContext.AdaptedPipeOptions.WriterScheduler); + } + } +} diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/SocketOutputTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/SocketOutputTests.cs index ba88696ff7..544c9af39b 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/SocketOutputTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/SocketOutputTests.cs @@ -9,7 +9,6 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel; using Microsoft.AspNetCore.Server.Kestrel.Internal; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.AspNetCore.Server.KestrelTests.TestHelpers; using Microsoft.AspNetCore.Testing; using Xunit; @@ -18,43 +17,19 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { public class SocketOutputTests { - public static TheoryData MaxResponseBufferSizeData => new TheoryData + public static TheoryData MaxResponseBufferSizeData => new TheoryData { - new KestrelServerOptions(), - new KestrelServerOptions - { - Limits = { MaxResponseBufferSize = 0 } - }, - new KestrelServerOptions - { - Limits = { MaxResponseBufferSize = 1024 } - }, - new KestrelServerOptions - { - Limits = { MaxResponseBufferSize = 1024 * 1024 } - }, - new KestrelServerOptions - { - Limits = { MaxResponseBufferSize = null } - }, + new KestrelServerOptions().Limits.MaxResponseBufferSize, 0, 1024, 1024 * 1024, null }; - public static TheoryData PositiveMaxResponseBufferSizeData => new TheoryData + public static TheoryData PositiveMaxResponseBufferSizeData => new TheoryData { - new KestrelServerOptions(), - new KestrelServerOptions - { - Limits = { MaxResponseBufferSize = 1024 } - }, - new KestrelServerOptions - { - Limits = { MaxResponseBufferSize = (1024 * 1024) + 1 } - } + (int)new KestrelServerOptions().Limits.MaxResponseBufferSize, 1024, (1024 * 1024) + 1 }; [Theory] [MemberData(nameof(MaxResponseBufferSizeData))] - public async Task CanWrite1MB(KestrelServerOptions options) + public async Task CanWrite1MB(long? maxResponseBufferSize) { // This test was added because when initially implementing write-behind buffering in // SocketOutput, the write callback would never be invoked for writes larger than @@ -71,15 +46,17 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var socket = new MockSocket(mockLibuv, kestrelThread.Loop.ThreadId, new TestKestrelTrace()); var trace = new KestrelTrace(new TestKestrelTrace()); - var connection = new MockConnection(options); + + // ListenerContext will set MaximumSizeHigh/Low to zero when MaxResponseBufferSize is null. + // This is verified in ListenerContextTests.LibuvOutputPipeOptionsConfiguredCorrectly. var pipeOptions = new PipeOptions { ReaderScheduler = kestrelThread, - MaximumSizeHigh = options.Limits.MaxResponseBufferSize ?? 0, - MaximumSizeLow = options.Limits.MaxResponseBufferSize ?? 0, + MaximumSizeHigh = maxResponseBufferSize ?? 0, + MaximumSizeLow = maxResponseBufferSize ?? 0, }; var pipe = factory.Create(pipeOptions); - var socketOutput = new SocketOutput(pipe, kestrelThread, socket, connection, "0", trace); + var socketOutput = new SocketOutput(pipe, kestrelThread, socket, new MockConnection(), "0", trace); // At least one run of this test should have a MaxResponseBufferSize < 1 MB. var bufferSize = 1024 * 1024; @@ -120,15 +97,17 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var socket = new MockSocket(mockLibuv, kestrelThread.Loop.ThreadId, new TestKestrelTrace()); var trace = new KestrelTrace(new TestKestrelTrace()); - var options = new KestrelServerOptions { Limits = { MaxResponseBufferSize = null } }; + + // ListenerContext will set MaximumSizeHigh/Low to zero when MaxResponseBufferSize is null. + // This is verified in ListenerContextTests.LibuvOutputPipeOptionsConfiguredCorrectly. var pipeOptions = new PipeOptions { ReaderScheduler = kestrelThread, - MaximumSizeHigh = options.Limits.MaxResponseBufferSize ?? 0, - MaximumSizeLow = options.Limits.MaxResponseBufferSize ?? 0, + MaximumSizeHigh = 0, + MaximumSizeLow = 0, }; var pipe = factory.Create(pipeOptions); - var socketOutput = new SocketOutput(pipe, kestrelThread, socket, new MockConnection(options), "0", trace); + var socketOutput = new SocketOutput(pipe, kestrelThread, socket, new MockConnection(), "0", trace); // Don't want to allocate anything too huge for perf. This is at least larger than the default buffer. var bufferSize = 1024 * 1024; @@ -177,7 +156,9 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var socket = new MockSocket(mockLibuv, kestrelThread.Loop.ThreadId, new TestKestrelTrace()); var trace = new KestrelTrace(new TestKestrelTrace()); - var options = new KestrelServerOptions { Limits = { MaxResponseBufferSize = 0 } }; + + // ListenerContext will set MaximumSizeHigh/Low to 1 when MaxResponseBufferSize is zero. + // This is verified in ListenerContextTests.LibuvOutputPipeOptionsConfiguredCorrectly. var pipeOptions = new PipeOptions { ReaderScheduler = kestrelThread, @@ -185,7 +166,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests MaximumSizeLow = 1, }; var pipe = factory.Create(pipeOptions); - var socketOutput = new SocketOutput(pipe, kestrelThread, socket, new MockConnection(options), "0", trace); + var socketOutput = new SocketOutput(pipe, kestrelThread, socket, new MockConnection(), "0", trace); var bufferSize = 1; var buffer = new ArraySegment(new byte[bufferSize], 0, bufferSize); @@ -221,9 +202,8 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [Theory] [MemberData(nameof(PositiveMaxResponseBufferSizeData))] - public async Task WritesDontCompleteImmediatelyWhenTooManyBytesAreAlreadyBuffered(KestrelServerOptions options) + public async Task WritesDontCompleteImmediatelyWhenTooManyBytesAreAlreadyBuffered(int maxResponseBufferSize) { - var maxBytesPreCompleted = (int)options.Limits.MaxResponseBufferSize.Value; var completeQueue = new ConcurrentQueue>(); // Arrange @@ -245,17 +225,16 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var socket = new MockSocket(mockLibuv, kestrelThread.Loop.ThreadId, new TestKestrelTrace()); var trace = new KestrelTrace(new TestKestrelTrace()); - var mockConnection = new MockConnection(options); var pipeOptions = new PipeOptions { ReaderScheduler = kestrelThread, - MaximumSizeHigh = options.Limits.MaxResponseBufferSize ?? 0, - MaximumSizeLow = options.Limits.MaxResponseBufferSize ?? 0, + MaximumSizeHigh = maxResponseBufferSize, + MaximumSizeLow = maxResponseBufferSize, }; var pipe = factory.Create(pipeOptions); - var socketOutput = new SocketOutput(pipe, kestrelThread, socket, mockConnection, "0", trace); + var socketOutput = new SocketOutput(pipe, kestrelThread, socket, new MockConnection(), "0", trace); - var bufferSize = maxBytesPreCompleted - 1; + var bufferSize = maxResponseBufferSize - 1; var buffer = new ArraySegment(new byte[bufferSize], 0, bufferSize); // Act @@ -295,9 +274,8 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [Theory] [MemberData(nameof(PositiveMaxResponseBufferSizeData))] - public async Task WritesDontCompleteImmediatelyWhenTooManyBytesIncludingNonImmediateAreAlreadyBuffered(KestrelServerOptions options) + public async Task WritesDontCompleteImmediatelyWhenTooManyBytesIncludingNonImmediateAreAlreadyBuffered(int maxResponseBufferSize) { - var maxBytesPreCompleted = (int)options.Limits.MaxResponseBufferSize.Value; var completeQueue = new ConcurrentQueue>(); // Arrange @@ -319,17 +297,16 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var socket = new MockSocket(mockLibuv, kestrelThread.Loop.ThreadId, new TestKestrelTrace()); var trace = new KestrelTrace(new TestKestrelTrace()); - var mockConnection = new MockConnection(options); var pipeOptions = new PipeOptions { ReaderScheduler = kestrelThread, - MaximumSizeHigh = options.Limits.MaxResponseBufferSize ?? 0, - MaximumSizeLow = options.Limits.MaxResponseBufferSize ?? 0, + MaximumSizeHigh = maxResponseBufferSize, + MaximumSizeLow = maxResponseBufferSize, }; var pipe = factory.Create(pipeOptions); - var socketOutput = new SocketOutput(pipe, kestrelThread, socket, mockConnection, "0", trace); + var socketOutput = new SocketOutput(pipe, kestrelThread, socket, new MockConnection(), "0", trace); - var bufferSize = maxBytesPreCompleted / 2; + var bufferSize = maxResponseBufferSize / 2; var data = new byte[bufferSize]; var halfWriteBehindBuffer = new ArraySegment(data, 0, bufferSize); @@ -374,9 +351,8 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [Theory] [MemberData(nameof(PositiveMaxResponseBufferSizeData))] - public async Task FailedWriteCompletesOrCancelsAllPendingTasks(KestrelServerOptions options) + public async Task FailedWriteCompletesOrCancelsAllPendingTasks(int maxResponseBufferSize) { - var maxBytesPreCompleted = (int)options.Limits.MaxResponseBufferSize.Value; var completeQueue = new ConcurrentQueue>(); // Arrange @@ -399,19 +375,19 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var socket = new MockSocket(mockLibuv, kestrelThread.Loop.ThreadId, new TestKestrelTrace()); var trace = new KestrelTrace(new TestKestrelTrace()); - using (var mockConnection = new MockConnection(options)) + using (var mockConnection = new MockConnection()) { var pipeOptions = new PipeOptions { ReaderScheduler = kestrelThread, - MaximumSizeHigh = options.Limits.MaxResponseBufferSize ?? 0, - MaximumSizeLow = options.Limits.MaxResponseBufferSize ?? 0, + MaximumSizeHigh = maxResponseBufferSize, + MaximumSizeLow = maxResponseBufferSize, }; var pipe = factory.Create(pipeOptions); var abortedSource = mockConnection.RequestAbortedSource; var socketOutput = new SocketOutput(pipe, kestrelThread, socket, mockConnection, "0", trace); - var bufferSize = maxBytesPreCompleted - 1; + var bufferSize = maxResponseBufferSize - 1; var data = new byte[bufferSize]; var fullBuffer = new ArraySegment(data, 0, bufferSize); @@ -467,9 +443,8 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [Theory] [MemberData(nameof(PositiveMaxResponseBufferSizeData))] - public async Task WritesDontGetCompletedTooQuickly(KestrelServerOptions options) + public async Task WritesDontGetCompletedTooQuickly(int maxResponseBufferSize) { - var maxBytesPreCompleted = (int)options.Limits.MaxResponseBufferSize.Value; var completeQueue = new ConcurrentQueue>(); // Arrange @@ -491,17 +466,16 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var socket = new MockSocket(mockLibuv, kestrelThread.Loop.ThreadId, new TestKestrelTrace()); var trace = new KestrelTrace(new TestKestrelTrace()); - var mockConnection = new MockConnection(options); var pipeOptions = new PipeOptions { ReaderScheduler = kestrelThread, - MaximumSizeHigh = options.Limits.MaxResponseBufferSize ?? 0, - MaximumSizeLow = options.Limits.MaxResponseBufferSize ?? 0, + MaximumSizeHigh = maxResponseBufferSize, + MaximumSizeLow = maxResponseBufferSize, }; var pipe = factory.Create(pipeOptions); - var socketOutput = new SocketOutput(pipe, kestrelThread, socket, mockConnection, "0", trace); + var socketOutput = new SocketOutput(pipe, kestrelThread, socket, new MockConnection(), "0", trace); - var bufferSize = maxBytesPreCompleted - 1; + var bufferSize = maxResponseBufferSize - 1; var buffer = new ArraySegment(new byte[bufferSize], 0, bufferSize); // Act (Pre-complete the maximum number of bytes in preparation for the rest of the test) @@ -538,7 +512,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [Theory] [MemberData(nameof(MaxResponseBufferSizeData))] - public async Task WritesAreAggregated(KestrelServerOptions options) + public async Task WritesAreAggregated(long? maxResponseBufferSize) { var writeCalled = false; var writeCount = 0; @@ -563,14 +537,17 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var socket = new MockSocket(mockLibuv, kestrelThread.Loop.ThreadId, new TestKestrelTrace()); var trace = new KestrelTrace(new TestKestrelTrace()); + + // ListenerContext will set MaximumSizeHigh/Low to zero when MaxResponseBufferSize is null. + // This is verified in ListenerContextTests.LibuvOutputPipeOptionsConfiguredCorrectly. var pipeOptions = new PipeOptions { ReaderScheduler = kestrelThread, - MaximumSizeHigh = options.Limits.MaxResponseBufferSize ?? 0, - MaximumSizeLow = options.Limits.MaxResponseBufferSize ?? 0, + MaximumSizeHigh = maxResponseBufferSize ?? 0, + MaximumSizeLow = maxResponseBufferSize ?? 0, }; var pipe = factory.Create(pipeOptions); - var socketOutput = new SocketOutput(pipe, kestrelThread, socket, new MockConnection(new KestrelServerOptions()), "0", trace); + var socketOutput = new SocketOutput(pipe, kestrelThread, socket, new MockConnection(), "0", trace); mockLibuv.KestrelThreadBlocker.Reset(); @@ -616,7 +593,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var socket = new MockSocket(mockLibuv, kestrelThread.Loop.ThreadId, new TestKestrelTrace()); var trace = new KestrelTrace(new TestKestrelTrace()); - var connection = new MockConnection(new KestrelServerOptions()); + var connection = new MockConnection(); var pipeOptions = new PipeOptions { ReaderScheduler = kestrelThread, diff --git a/test/shared/MockConnection.cs b/test/shared/MockConnection.cs index c68870cde6..56a9e84d56 100644 --- a/test/shared/MockConnection.cs +++ b/test/shared/MockConnection.cs @@ -16,11 +16,11 @@ namespace Microsoft.AspNetCore.Testing { private readonly TaskCompletionSource _socketClosedTcs = new TaskCompletionSource(); - public MockConnection(KestrelServerOptions options) + public MockConnection() { ConnectionControl = this; RequestAbortedSource = new CancellationTokenSource(); - ListenerContext = new ListenerContext(new ServiceContext {ServerOptions = options}) + ListenerContext = new ListenerContext(new ServiceContext()) { ListenOptions = new ListenOptions(new IPEndPoint(IPAddress.Loopback, 5000)) }; From 3b40ba52caff9320ca59f6be40a90dba40a00f50 Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Fri, 17 Mar 2017 13:54:48 -0700 Subject: [PATCH 1136/1662] Check if request is aborted before verifying response bytes written (#1498). --- .../Internal/Http/FrameOfT.cs | 6 +- .../ResponseTests.cs | 63 +++++++++++++++++-- 2 files changed, 62 insertions(+), 7 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameOfT.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameOfT.cs index 7af359cfc4..8b710aab17 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameOfT.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameOfT.cs @@ -94,7 +94,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http try { await _application.ProcessRequestAsync(context).ConfigureAwait(false); - VerifyResponseContentLength(); + + if (Volatile.Read(ref _requestAborted) == 0) + { + VerifyResponseContentLength(); + } } catch (Exception ex) { diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs index 2fafb67084..eabb1a5385 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs @@ -632,14 +632,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [Fact] public async Task WhenAppWritesLessThanContentLengthErrorLogged() { - string errorMessage = null; var logTcs = new TaskCompletionSource(); var mockTrace = new Mock(); mockTrace .Setup(trace => trace.ApplicationError(It.IsAny(), It.IsAny())) .Callback((connectionId, ex) => { - errorMessage = ex.Message; logTcs.SetResult(null); }); @@ -655,7 +653,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests "GET / HTTP/1.1", "", ""); - await connection.ReceiveEnd( + + // Don't use ReceiveEnd here, otherwise the FIN might + // abort the request before the server checks the + // response content length, in which case the check + // will be skipped. + await connection.Receive( $"HTTP/1.1 200 OK", $"Date: {server.Context.DateHeaderValue}", "Content-Length: 13", @@ -664,12 +667,60 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests // Wait for error message to be logged. await logTcs.Task.TimeoutAfter(TimeSpan.FromSeconds(10)); + + // The server should close the connection in this situation. + await connection.WaitForConnectionClose().TimeoutAfter(TimeSpan.FromSeconds(10)); } } - Assert.Equal( - $"Response Content-Length mismatch: too few bytes written (12 of 13).", - errorMessage); + mockTrace.Verify(trace => + trace.ApplicationError( + It.IsAny(), + It.Is(ex => + ex.Message.Equals($"Response Content-Length mismatch: too few bytes written (12 of 13).", StringComparison.Ordinal)))); + } + + [Fact] + public async Task WhenAppWritesLessThanContentLengthButRequestIsAbortedErrorNotLogged() + { + var abortTcs = new TaskCompletionSource(); + var mockTrace = new Mock(); + + using (var server = new TestServer(async httpContext => + { + httpContext.RequestAborted.Register(() => + { + abortTcs.SetResult(null); + }); + httpContext.Response.ContentLength = 12; + await httpContext.Response.WriteAsync("hello,"); + + // Wait until the request is aborted so we know Frame will skip the response content length check. + await abortTcs.Task.TimeoutAfter(TimeSpan.FromSeconds(10)); + }, new TestServiceContext { Log = mockTrace.Object })) + { + using (var connection = server.CreateConnection()) + { + await connection.Send( + "GET / HTTP/1.1", + "", + ""); + await connection.Receive( + $"HTTP/1.1 200 OK", + $"Date: {server.Context.DateHeaderValue}", + "Content-Length: 12", + "", + "hello,"); + } + } + + // Verify the request was really aborted. A timeout in the await inside + // the app func would cause a server error and skip the content length + // check altogether, making the test pass for the wrong reason. + Assert.True(abortTcs.Task.IsCompleted); + + // With the server disposed we know all connections were drained and all messages were logged. + mockTrace.Verify(trace => trace.ApplicationError(It.IsAny(), It.IsAny()), Times.Never); } [Fact] From cf576559b61c13f90093562a4aab8bd28d272bee Mon Sep 17 00:00:00 2001 From: David Fowler Date: Mon, 20 Mar 2017 23:58:26 -0700 Subject: [PATCH 1137/1662] Fix write after close (#1526) - Change Alloc to be a Write with a callback that exposes the WritableBuffer. This allows the ISocketOutput to implementation to not call the callback if the underlying socket is dead. - Added a new functional test --- .../Adapter/Internal/StreamSocketOutput.cs | 14 ++++++- .../Internal/Http/Frame.cs | 18 ++++---- .../Internal/Http/ISocketOutput.cs | 3 +- .../Internal/Http/SocketOutput.cs | 9 ++-- .../ResponseTests.cs | 42 +++++++++++++++++++ .../SocketOutputTests.cs | 21 +++++++--- test/shared/MockSocketOutput.cs | 8 +--- 7 files changed, 87 insertions(+), 28 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Adapter/Internal/StreamSocketOutput.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Adapter/Internal/StreamSocketOutput.cs index a5b618c8d4..92a32c2a28 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Adapter/Internal/StreamSocketOutput.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Adapter/Internal/StreamSocketOutput.cs @@ -83,9 +83,19 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Adapter.Internal return WriteAsync(default(ArraySegment), chunk: false, cancellationToken: cancellationToken); } - public WritableBuffer Alloc() + public void Write(Action callback, T state) { - return _pipe.Writer.Alloc(); + lock (_sync) + { + if (_completed) + { + return; + } + + var buffer = _pipe.Writer.Alloc(); + callback(buffer, state); + buffer.Commit(); + } } public async Task WriteOutputAsync() diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs index 8c5f032a1e..d900924e41 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs @@ -32,6 +32,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http private static readonly ArraySegment _endChunkedResponseBytes = CreateAsciiByteArraySegment("0\r\n\r\n"); private static readonly ArraySegment _continueBytes = CreateAsciiByteArraySegment("HTTP/1.1 100 Continue\r\n\r\n"); + private static readonly Action _writeHeaders = WriteResponseHeaders; private static readonly byte[] _bytesConnectionClose = Encoding.ASCII.GetBytes("\r\nConnection: close"); private static readonly byte[] _bytesConnectionKeepAlive = Encoding.ASCII.GetBytes("\r\nConnection: keep-alive"); @@ -784,9 +785,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _requestProcessingStatus = RequestProcessingStatus.ResponseStarted; - var statusBytes = ReasonPhrases.ToStatusBytes(StatusCode, ReasonPhrase); - - CreateResponseHeader(statusBytes, appCompleted); + CreateResponseHeader(appCompleted); } protected Task TryProduceInvalidRequestResponse() @@ -881,9 +880,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } } - private void CreateResponseHeader( - byte[] statusBytes, - bool appCompleted) + private void CreateResponseHeader(bool appCompleted) { var responseHeaders = FrameResponseHeaders; var hasConnection = responseHeaders.HasConnection; @@ -972,12 +969,17 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http responseHeaders.SetRawDate(dateHeaderValues.String, dateHeaderValues.Bytes); } - var writableBuffer = Output.Alloc(); + Output.Write(_writeHeaders, this); + } + + private static void WriteResponseHeaders(WritableBuffer writableBuffer, Frame frame) + { + var responseHeaders = frame.FrameResponseHeaders; writableBuffer.WriteFast(_bytesHttpVersion11); + var statusBytes = ReasonPhrases.ToStatusBytes(frame.StatusCode, frame.ReasonPhrase); writableBuffer.WriteFast(statusBytes); responseHeaders.CopyTo(ref writableBuffer); writableBuffer.WriteFast(_bytesEndHeaders); - writableBuffer.Commit(); } public void ParseRequest(ReadableBuffer buffer, out ReadCursor consumed, out ReadCursor examined) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ISocketOutput.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ISocketOutput.cs index fbefd3fa44..7298b42163 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ISocketOutput.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ISocketOutput.cs @@ -5,7 +5,6 @@ using System; using System.Threading; using System.Threading.Tasks; using System.IO.Pipelines; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { @@ -18,6 +17,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http Task WriteAsync(ArraySegment buffer, bool chunk = false, CancellationToken cancellationToken = default(CancellationToken)); void Flush(); Task FlushAsync(CancellationToken cancellationToken = default(CancellationToken)); - WritableBuffer Alloc(); + void Write(Action write, T state); } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/SocketOutput.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/SocketOutput.cs index 7c4412ef23..ef74217d12 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/SocketOutput.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/SocketOutput.cs @@ -186,17 +186,18 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http return WriteAsync(_emptyData, cancellationToken); } - public WritableBuffer Alloc() + public void Write(Action callback, T state) { lock (_contextLock) { if (_completed) { - // This is broken - return default(WritableBuffer); + return; } - return _pipe.Writer.Alloc(); + var buffer = _pipe.Writer.Alloc(); + callback(buffer, state); + buffer.Commit(); } } diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs index eabb1a5385..b0ae4f6c3e 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs @@ -5,6 +5,7 @@ using System; using System.Linq; using System.Net; using System.Net.Http; +using System.Net.Sockets; using System.Text; using System.Threading; using System.Threading.Tasks; @@ -988,6 +989,47 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } } + [Fact] + public async Task WriteAfterConnectionCloseNoops() + { + var connectionClosed = new ManualResetEventSlim(); + var requestStarted = new ManualResetEventSlim(); + var tcs = new TaskCompletionSource(); + + using (var server = new TestServer(async httpContext => + { + try + { + requestStarted.Set(); + connectionClosed.Wait(); + httpContext.Response.ContentLength = 12; + await httpContext.Response.WriteAsync("hello, world"); + tcs.TrySetResult(null); + } + catch (Exception ex) + { + tcs.TrySetException(ex); + } + }, new TestServiceContext())) + { + using (var connection = server.CreateConnection()) + { + await connection.Send( + "GET / HTTP/1.1", + "", + ""); + + requestStarted.Wait(); + connection.Shutdown(SocketShutdown.Send); + await connection.WaitForConnectionClose(); + } + + connectionClosed.Set(); + + await tcs.Task; + } + } + [Fact] public async Task AppCanWriteOwnBadRequestResponse() { diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/SocketOutputTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/SocketOutputTests.cs index 544c9af39b..e1257a8dd8 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/SocketOutputTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/SocketOutputTests.cs @@ -320,9 +320,11 @@ namespace Microsoft.AspNetCore.Server.KestrelTests Assert.NotEmpty(completeQueue); // Add more bytes to the write-behind buffer to prevent the next write from - var writableBuffer = socketOutput.Alloc(); - writableBuffer.Write(halfWriteBehindBuffer); - writableBuffer.Commit(); + socketOutput.Write((writableBuffer, state) => + { + writableBuffer.Write(state); + }, + halfWriteBehindBuffer); // Act var writeTask2 = socketOutput.WriteAsync(halfWriteBehindBuffer, default(CancellationToken)); @@ -579,7 +581,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } } - [Fact(Skip = "Commit throws with a non channel backed writable buffer")] + [Fact] public async Task AllocCommitCanBeCalledAfterConnectionClose() { var mockLibuv = new MockLibuv(); @@ -608,8 +610,15 @@ namespace Microsoft.AspNetCore.Server.KestrelTests Assert.Equal(TaskStatus.RanToCompletion, connection.SocketClosed.Status); - var start = socketOutput.Alloc(); - start.Commit(); + var called = false; + + socketOutput.Write((buffer, state) => + { + called = true; + }, + null); + + Assert.False(called); } } } diff --git a/test/shared/MockSocketOutput.cs b/test/shared/MockSocketOutput.cs index fa7f8836d6..a506b388fd 100644 --- a/test/shared/MockSocketOutput.cs +++ b/test/shared/MockSocketOutput.cs @@ -12,12 +12,8 @@ namespace Microsoft.AspNetCore.Testing { public class MockSocketOutput : ISocketOutput { - private PipeFactory _factory = new PipeFactory(); - private IPipeWriter _writer; - public MockSocketOutput() { - _writer = _factory.Create().Writer; } public void Write(ArraySegment buffer, bool chunk = false) @@ -38,9 +34,9 @@ namespace Microsoft.AspNetCore.Testing return TaskCache.CompletedTask; } - public WritableBuffer Alloc() + public void Write(Action write, T state) { - return _writer.Alloc(); + } } } From f546f1635615721774c024530ee308fee14bbc6b Mon Sep 17 00:00:00 2001 From: David Fowler Date: Tue, 21 Mar 2017 03:21:31 -0700 Subject: [PATCH 1138/1662] Forgot to WriteFast in SocketOutput (#1527) --- .../Internal/Http/SocketOutput.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/SocketOutput.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/SocketOutput.cs index ef74217d12..2017b1297b 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/SocketOutput.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/SocketOutput.cs @@ -89,7 +89,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http ChunkWriter.WriteBeginChunkBytes(ref writableBuffer, buffer.Count); } - writableBuffer.Write(buffer); + writableBuffer.WriteFast(buffer); if (chunk) { From 24ed93288e083c935bb64d676c22dfbfc9c8ffa8 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Tue, 21 Mar 2017 10:26:58 +0000 Subject: [PATCH 1139/1662] Use for rather than foreach on List (#1523) List enumerator is full fat --- .../Internal/Networking/UvWriteReq.cs | 27 +++++++++++-------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/UvWriteReq.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/UvWriteReq.cs index 1134e71eaa..c454859e3c 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/UvWriteReq.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/UvWriteReq.cs @@ -125,7 +125,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking { _callback = null; _state = null; - Unpin(this); + UnpinGcHandles(); throw; } } @@ -200,31 +200,36 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking { _callback = null; _state = null; - Unpin(this); + UnpinGcHandles(); throw; } } - private static void Unpin(UvWriteReq req) + // Safe handle has instance method called Unpin + // so using UnpinGcHandles to avoid conflict + private void UnpinGcHandles() { - foreach (var pin in req._pins) + var pinList = _pins; + var count = pinList.Count; + for (var i = 0; i < count; i++) { - pin.Free(); + pinList[i].Free(); } + pinList.Clear(); - foreach (var handle in req._handles) + var handleList = _handles; + count = handleList.Count; + for (var i = 0; i < count; i++) { - handle.Free(); + handleList[i].Free(); } - - req._pins.Clear(); - req._handles.Clear(); + handleList.Clear(); } private static void UvWriteCb(IntPtr ptr, int status) { var req = FromIntPtr(ptr); - Unpin(req); + req.UnpinGcHandles(); var callback = req._callback; req._callback = null; From 32d6b4296456a49e66b195459fe85ab2c462c4b9 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Tue, 21 Mar 2017 15:43:49 +0000 Subject: [PATCH 1140/1662] Respond to corefxlab rename (build break) (#1529) --- .../Adapter/Internal/AdaptedPipeline.cs | 2 +- .../Internal/Http/Connection.cs | 4 +-- .../Internal/Http/PipelineExtensions.cs | 34 +++++++++---------- .../Internal/Networking/UvWriteReq.cs | 2 +- .../MessageBodyTests.cs | 4 +-- 5 files changed, 22 insertions(+), 24 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Adapter/Internal/AdaptedPipeline.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Adapter/Internal/AdaptedPipeline.cs index cfd2c7d1f1..488d902d9d 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Adapter/Internal/AdaptedPipeline.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Adapter/Internal/AdaptedPipeline.cs @@ -67,7 +67,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Adapter.Internal try { - var array = block.Memory.GetArray(); + var array = block.Buffer.GetArray(); try { bytesRead = await _filteredStream.ReadAsync(array.Array, array.Offset, array.Count); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Connection.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Connection.cs index d2abc6ead2..dfa0810dc0 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Connection.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Connection.cs @@ -234,12 +234,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var currentWritableBuffer = Input.Writer.Alloc(MinAllocBufferSize); _currentWritableBuffer = currentWritableBuffer; void* dataPtr; - var tryGetPointer = currentWritableBuffer.Memory.TryGetPointer(out dataPtr); + var tryGetPointer = currentWritableBuffer.Buffer.TryGetPointer(out dataPtr); Debug.Assert(tryGetPointer); return handle.Libuv.buf_init( (IntPtr)dataPtr, - currentWritableBuffer.Memory.Length); + currentWritableBuffer.Buffer.Length); } private static void ReadCallback(UvStreamHandle handle, int status, object state) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/PipelineExtensions.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/PipelineExtensions.cs index d986106d03..d3bbe8a46c 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/PipelineExtensions.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/PipelineExtensions.cs @@ -2,11 +2,9 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.Diagnostics; +using System.Buffers; using System.IO.Pipelines; using System.Runtime.CompilerServices; -using System.Text; -using System.Threading; using System.Threading.Tasks; namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http @@ -85,12 +83,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http return buffer.ToArray(); } - public static ArraySegment GetArray(this Memory memory) + public static ArraySegment GetArray(this Buffer buffer) { ArraySegment result; - if (!memory.TryGetArray(out result)) + if (!buffer.TryGetArray(out result)) { - throw new InvalidOperationException("Memory backed by array was expected"); + throw new InvalidOperationException("Buffer backed by array was expected"); } return result; } @@ -98,7 +96,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http // Temporary until the fast write implementation propagates from corefx public unsafe static void WriteFast(this WritableBuffer buffer, ReadOnlySpan source) { - var dest = buffer.Memory.Span; + var dest = buffer.Buffer.Span; var destLength = dest.Length; if (destLength == 0) @@ -106,7 +104,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http buffer.Ensure(); // Get the new span and length - dest = buffer.Memory.Span; + dest = buffer.Buffer.Span; destLength = dest.Length; } @@ -132,7 +130,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { while (remaining > 0) { - var writable = Math.Min(remaining, buffer.Memory.Length); + var writable = Math.Min(remaining, buffer.Buffer.Length); buffer.Ensure(writable); @@ -141,7 +139,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http continue; } - fixed (byte* pDest = &buffer.Memory.Span.DangerousGetPinnableReference()) + fixed (byte* pDest = &buffer.Buffer.Span.DangerousGetPinnableReference()) { Unsafe.CopyBlockUnaligned(pDest, pSource + offset, (uint)writable); } @@ -158,16 +156,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { if (!string.IsNullOrEmpty(data)) { - if (buffer.Memory.IsEmpty) + if (buffer.Buffer.IsEmpty) { buffer.Ensure(); } // Fast path, try copying to the available memory directly - if (data.Length <= buffer.Memory.Length) + if (data.Length <= buffer.Buffer.Length) { fixed (char* input = data) - fixed (byte* output = &buffer.Memory.Span.DangerousGetPinnableReference()) + fixed (byte* output = &buffer.Buffer.Span.DangerousGetPinnableReference()) { EncodeAsciiCharsToBytes(input, output, data.Length); } @@ -186,15 +184,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { const byte AsciiDigitStart = (byte)'0'; - if (buffer.Memory.IsEmpty) + if (buffer.Buffer.IsEmpty) { buffer.Ensure(); } // Fast path, try copying to the available memory directly - var bytesLeftInBlock = buffer.Memory.Length; + var bytesLeftInBlock = buffer.Buffer.Length; var simpleWrite = true; - fixed (byte* output = &buffer.Memory.Span.DangerousGetPinnableReference()) + fixed (byte* output = &buffer.Buffer.Span.DangerousGetPinnableReference()) { var start = output; if (number < 10 && bytesLeftInBlock >= 1) @@ -266,7 +264,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http while (remaining > 0) { - var writable = Math.Min(remaining, buffer.Memory.Length); + var writable = Math.Min(remaining, buffer.Buffer.Length); buffer.Ensure(writable); @@ -275,7 +273,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http continue; } - fixed (byte* output = &buffer.Memory.Span.DangerousGetPinnableReference()) + fixed (byte* output = &buffer.Buffer.Span.DangerousGetPinnableReference()) { EncodeAsciiCharsToBytes(inputSlice, output, writable); } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/UvWriteReq.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/UvWriteReq.cs index c454859e3c..673c92bd94 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/UvWriteReq.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/UvWriteReq.cs @@ -26,7 +26,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking private LibuvAwaitable _awaitable = new LibuvAwaitable(); private List _pins = new List(BUFFER_COUNT + 1); - private List _handles = new List(BUFFER_COUNT + 1); + private List _handles = new List(BUFFER_COUNT + 1); public UvWriteReq(IKestrelTrace logger) : base(logger) { diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/MessageBodyTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/MessageBodyTests.cs index 0cce86969b..fcb7fdbcd0 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/MessageBodyTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/MessageBodyTests.cs @@ -285,7 +285,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var bytes = Encoding.ASCII.GetBytes(data[0]); var buffer = socketInput.Writer.Alloc(2048); ArraySegment block; - Assert.True(buffer.Memory.TryGetArray(out block)); + Assert.True(buffer.Buffer.TryGetArray(out block)); Buffer.BlockCopy(bytes, 0, block.Array, block.Offset, bytes.Length); buffer.Advance(bytes.Length); await buffer.FlushAsync(); @@ -296,7 +296,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests writeTcs = new TaskCompletionSource(); bytes = Encoding.ASCII.GetBytes(data[1]); buffer = socketInput.Writer.Alloc(2048); - Assert.True(buffer.Memory.TryGetArray(out block)); + Assert.True(buffer.Buffer.TryGetArray(out block)); Buffer.BlockCopy(bytes, 0, block.Array, block.Offset, bytes.Length); buffer.Advance(bytes.Length); await buffer.FlushAsync(); From 5fad3c7a3e67ba6b899f228986caed5fff370210 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Tue, 21 Mar 2017 09:52:24 -0700 Subject: [PATCH 1141/1662] Remove async from WriteAsync in SocketOutput (#1531) - SocketOutput.WriteAsync will be synchronous for a majority of cases (until you reach the limit) so no need to pay the async state machine cost until then. --- .../Internal/Http/SocketOutput.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/SocketOutput.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/SocketOutput.cs index 2017b1297b..fde232f36e 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/SocketOutput.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/SocketOutput.cs @@ -59,7 +59,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _onFlushCallback = OnFlush; } - public async Task WriteAsync( + public Task WriteAsync( ArraySegment buffer, CancellationToken cancellationToken, bool chunk = false) @@ -72,12 +72,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { _log.ConnectionDisconnectedWrite(_connectionId, buffer.Count, _lastWriteError); - return; + return TaskCache.CompletedTask; } if (_completed) { - return; + return TaskCache.CompletedTask; } writableBuffer = _pipe.Writer.Alloc(); @@ -100,7 +100,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http writableBuffer.Commit(); } - await FlushAsync(writableBuffer); + return FlushAsync(writableBuffer); } public void End(ProduceEndType endType) From ca5581461c75b61acf1cf6fd9409d9b2b2a4005e Mon Sep 17 00:00:00 2001 From: Nate McMaster Date: Tue, 21 Mar 2017 11:33:25 -0700 Subject: [PATCH 1142/1662] Update Travis to macOS Sierra [skip appveyor] --- .travis.yml | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index a4f56d9d3a..084c199f52 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,12 +6,7 @@ services: addons: apt: packages: - - gettext - - libcurl4-openssl-dev - - libicu-dev - - libssl-dev - libunwind8 - - zlib1g env: global: - DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true @@ -20,6 +15,7 @@ mono: none os: - linux - osx +osx_image: xcode8.2 branches: only: - master From 6c131ea240b928fd4b2ea39231b6dff58f63a4a3 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Tue, 21 Mar 2017 18:31:29 -0700 Subject: [PATCH 1143/1662] Verify scopeids are connectable using Socket before testing Kestrel (#1536) --- .../AddressRegistrationTests.cs | 43 ++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs index 572b45aa68..21dba18436 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs @@ -8,6 +8,7 @@ using System.Linq; using System.Net; using System.Net.NetworkInformation; using System.Net.Sockets; +using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; @@ -451,7 +452,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests // Dynamic port var ipv6Addresses = GetIPAddresses() .Where(ip => ip.AddressFamily == AddressFamily.InterNetworkV6) - .Where(ip => ip.ScopeId != 0); + .Where(ip => ip.ScopeId != 0) + .Where(ip => CanBindAndConnectToEndpoint(new IPEndPoint(ip, 0))); + foreach (var ip in ipv6Addresses) { dataset.Add($"http://[{ip}]:0/", GetTestUrls); @@ -531,6 +534,44 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } } + private static bool CanBindAndConnectToEndpoint(IPEndPoint endPoint) + { + try + { + using (var serverSocket = new Socket(endPoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp)) + { + serverSocket.Bind(endPoint); + serverSocket.Listen(1); + + var socketArgs = new SocketAsyncEventArgs + { + RemoteEndPoint = serverSocket.LocalEndPoint + }; + + var mre = new ManualResetEventSlim(); + socketArgs.Completed += (s, e) => + { + mre.Set(); + e.ConnectSocket?.Dispose(); + }; + + // Connect can take a couple minutes to time out. + if (Socket.ConnectAsync(SocketType.Stream, ProtocolType.Tcp, socketArgs)) + { + return mre.Wait(5000) && socketArgs.SocketError == SocketError.Success; + } + else + { + return socketArgs.SocketError == SocketError.Success; + } + } + } + catch (SocketException) + { + return false; + } + } + [AttributeUsage(AttributeTargets.Method, AllowMultiple = false)] private class PortSupportedConditionAttribute : Attribute, ITestCondition { From 72587baac3e93f59a29e3cc9d11831af32265bc8 Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Tue, 21 Mar 2017 19:25:56 -0700 Subject: [PATCH 1144/1662] Check that MaxRequestBufferSize is greater than or equal to MaxRequestHeadersTotalSize (#1491). --- .../KestrelServer.cs | 7 +++ .../MaxRequestBufferSizeTests.cs | 28 ++++++--- .../KestrelServerTests.cs | 58 ++++++++++++++----- 3 files changed, 71 insertions(+), 22 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServer.cs b/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServer.cs index 654544594b..04ece0d46d 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServer.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServer.cs @@ -247,6 +247,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel throw new InvalidOperationException( $"Maximum request buffer size ({Options.Limits.MaxRequestBufferSize.Value}) must be greater than or equal to maximum request line size ({Options.Limits.MaxRequestLineSize})."); } + + if (Options.Limits.MaxRequestBufferSize.HasValue && + Options.Limits.MaxRequestBufferSize < Options.Limits.MaxRequestHeadersTotalSize) + { + throw new InvalidOperationException( + $"Maximum request buffer size ({Options.Limits.MaxRequestBufferSize.Value}) must be greater than or equal to maximum request headers size ({Options.Limits.MaxRequestHeadersTotalSize})."); + } } private void StartLocalhost(KestrelEngine engine, ServerAddress parsedAddress) diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/MaxRequestBufferSizeTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/MaxRequestBufferSizeTests.cs index 3c09271a4f..d60ae18dc4 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/MaxRequestBufferSizeTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/MaxRequestBufferSizeTests.cs @@ -6,9 +6,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; using System.Net; -using System.Net.Security; using System.Net.Sockets; -using System.Security.Authentication; using System.Text; using System.Threading; using System.Threading.Tasks; @@ -24,13 +22,22 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { private const int _dataLength = 20 * 1024 * 1024; + private static readonly string[] _requestLines = new[] + { + "POST / HTTP/1.0\r\n", + $"Content-Length: {_dataLength}\r\n", + "\r\n" + }; + public static IEnumerable LargeUploadData { get { var maxRequestBufferSizeValues = new Tuple[] { - // Smallest buffer that can hold a POST request line to the root. - Tuple.Create((long?)"POST / HTTP/1.1\r\n".Length, true), + // Smallest buffer that can hold a test request line without causing + // the server to hang waiting for the end of the request line or + // a header line. + Tuple.Create((long?)(_requestLines.Max(line => line.Length)), true), // Small buffer, but large enough to hold all request headers. Tuple.Create((long?)16 * 1024, true), @@ -186,6 +193,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { options.Limits.MaxRequestLineSize = (int)maxRequestBufferSize; } + + if (maxRequestBufferSize.HasValue && + maxRequestBufferSize.Value < options.Limits.MaxRequestHeadersTotalSize) + { + options.Limits.MaxRequestHeadersTotalSize = (int)maxRequestBufferSize; + } }) .UseContentRoot(Directory.GetCurrentDirectory()) .Configure(app => app.Run(async context => @@ -246,9 +259,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { using (var writer = new StreamWriter(stream, Encoding.ASCII, bufferSize: 1024, leaveOpen: true)) { - await writer.WriteAsync("POST / HTTP/1.0\r\n"); - await writer.WriteAsync($"Content-Length: {contentLength}\r\n"); - await writer.WriteAsync("\r\n"); + foreach (var line in _requestLines) + { + await writer.WriteAsync(line); + } } } } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerTests.cs index 5225e5a16d..c22bdf6789 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerTests.cs @@ -24,25 +24,30 @@ namespace Microsoft.AspNetCore.Server.KestrelTests public void StartWithNonPositiveThreadCountThrows(int threadCount) { var testLogger = new TestApplicationErrorLogger { ThrowOnCriticalErrors = false }; - var server = CreateServer(new KestrelServerOptions() { ThreadCount = threadCount }, testLogger); - var exception = Assert.Throws(() => StartDummyApplication(server)); + using (var server = CreateServer(new KestrelServerOptions() { ThreadCount = threadCount }, testLogger)) + { + var exception = Assert.Throws(() => StartDummyApplication(server)); - Assert.Equal("threadCount", exception.ParamName); - Assert.Equal(1, testLogger.CriticalErrorsLogged); + Assert.Equal("threadCount", exception.ParamName); + Assert.Equal(1, testLogger.CriticalErrorsLogged); + } } [Fact] public void StartWithInvalidAddressThrows() { var testLogger = new TestApplicationErrorLogger { ThrowOnCriticalErrors = false }; - var server = CreateServer(new KestrelServerOptions(), testLogger); - server.Features.Get().Addresses.Add("http:/asdf"); - var exception = Assert.Throws(() => StartDummyApplication(server)); + using (var server = CreateServer(new KestrelServerOptions(), testLogger)) + { + server.Features.Get().Addresses.Add("http:/asdf"); - Assert.Contains("Invalid URL", exception.Message); - Assert.Equal(1, testLogger.CriticalErrorsLogged); + var exception = Assert.Throws(() => StartDummyApplication(server)); + + Assert.Contains("Invalid URL", exception.Message); + Assert.Equal(1, testLogger.CriticalErrorsLogged); + } } [Theory] @@ -77,14 +82,37 @@ namespace Microsoft.AspNetCore.Server.KestrelTests options.Limits.MaxRequestBufferSize = maxRequestBufferSize; options.Limits.MaxRequestLineSize = maxRequestLineSize; - var server = CreateServer(options, testLogger); + using (var server = CreateServer(options, testLogger)) + { + var exception = Assert.Throws(() => StartDummyApplication(server)); - var exception = Assert.Throws(() => StartDummyApplication(server)); + Assert.Equal( + $"Maximum request buffer size ({maxRequestBufferSize}) must be greater than or equal to maximum request line size ({maxRequestLineSize}).", + exception.Message); + Assert.Equal(1, testLogger.CriticalErrorsLogged); + } + } - Assert.Equal( - $"Maximum request buffer size ({maxRequestBufferSize}) must be greater than or equal to maximum request line size ({maxRequestLineSize}).", - exception.Message); - Assert.Equal(1, testLogger.CriticalErrorsLogged); + [Theory] + [InlineData(1, 2)] + [InlineData(int.MaxValue - 1, int.MaxValue)] + public void StartWithMaxRequestBufferSizeLessThanMaxRequestHeadersTotalSizeThrows(long maxRequestBufferSize, int maxRequestHeadersTotalSize) + { + var testLogger = new TestApplicationErrorLogger { ThrowOnCriticalErrors = false }; + var options = new KestrelServerOptions(); + options.Limits.MaxRequestBufferSize = maxRequestBufferSize; + options.Limits.MaxRequestLineSize = (int)maxRequestBufferSize; + options.Limits.MaxRequestHeadersTotalSize = maxRequestHeadersTotalSize; + + using (var server = CreateServer(options, testLogger)) + { + var exception = Assert.Throws(() => StartDummyApplication(server)); + + Assert.Equal( + $"Maximum request buffer size ({maxRequestBufferSize}) must be greater than or equal to maximum request headers size ({maxRequestHeadersTotalSize}).", + exception.Message); + Assert.Equal(1, testLogger.CriticalErrorsLogged); + } } [Fact] From 751a0e2e7e92fc2adc23092aeec5117a2afe5a1b Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Tue, 21 Mar 2017 19:35:41 -0700 Subject: [PATCH 1145/1662] Better checks for connection reset in RequestTests.ConnectionReset* tests (#1517) --- .../BadHttpRequestTests.cs | 43 ++++ .../RequestTests.cs | 205 +++++++----------- 2 files changed, 118 insertions(+), 130 deletions(-) diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/BadHttpRequestTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/BadHttpRequestTests.cs index d2f09dd2b9..36af57bd10 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/BadHttpRequestTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/BadHttpRequestTests.cs @@ -1,9 +1,15 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; using System.Collections.Generic; using System.Linq; +using System.Net.Sockets; using System.Threading.Tasks; +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Server.Kestrel.Internal; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.AspNetCore.Testing; using Microsoft.Extensions.Internal; @@ -103,6 +109,43 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests $"Allow: {allowedMethod}"); } + [Fact] + public async Task BadRequestLogsAreNotHigherThanInformation() + { + var maxLogLevel = LogLevel.Trace; + + var mockLogger = new Mock(); + mockLogger + .Setup(logger => logger.IsEnabled(It.IsAny())) + .Returns(true); + mockLogger + .Setup(logger => logger.Log(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny>())) + .Callback>((logLevel, eventId, state, ex, formatter) => + { + maxLogLevel = logLevel > maxLogLevel ? logLevel : maxLogLevel; + }); + + using (var server = new TestServer(async context => + { + await context.Request.Body.ReadAsync(new byte[1], 0, 1); + }, new TestServiceContext { Log = new KestrelTrace(mockLogger.Object) })) + { + using (var connection = new TestConnection(server.Port)) + { + await connection.SendAll( + "GET ? HTTP/1.1", + "", + ""); + await ReceiveBadRequestResponse(connection, "400 Bad Request", server.Context.DateHeaderValue); + } + } + + const int badRequestEventId = 17; + mockLogger.Verify(logger => logger.Log(LogLevel.Information, badRequestEventId, It.IsAny(), It.IsAny(), It.IsAny>())); + + Assert.Equal(LogLevel.Information, maxLogLevel); + } + private async Task TestBadRequest(string request, string expectedResponseStatusCode, string expectedExceptionMessage, string expectedAllowHeader = null) { BadHttpRequestException loggedException = null; diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs index 9a4ae90d6e..55c4e326bc 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs @@ -2,13 +2,11 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.Collections.Generic; using System.Globalization; using System.IO; using System.Net; using System.Net.Http; using System.Net.Sockets; -using System.Reflection; using System.Text; using System.Threading; using System.Threading.Tasks; @@ -22,7 +20,6 @@ using Microsoft.AspNetCore.Testing.xunit; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Internal; using Microsoft.Extensions.Logging; -using Microsoft.Extensions.Logging.Testing; using Moq; using Newtonsoft.Json; using Newtonsoft.Json.Linq; @@ -32,6 +29,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { public class RequestTests { + private const int _connectionStartedEventId = 1; + private const int _connectionResetEventId = 19; private const int _semaphoreWaitTimeout = 2500; [Theory] @@ -242,17 +241,34 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [Fact] public async Task ConnectionResetPriorToRequestIsLoggedAsDebug() { - var connectionStarted = new SemaphoreSlim(0); - var connectionResetLogged = new SemaphoreSlim(0); - var testSink = new ConnectionErrorTestSink( - () => connectionStarted.Release(), () => connectionResetLogged.Release(), () => { }); + var connectionStartedTcs = new TaskCompletionSource(); + + var mockLogger = new Mock(); + mockLogger + .Setup(logger => logger.IsEnabled(It.IsAny())) + .Returns(true); + mockLogger + .Setup(logger => logger.Log(LogLevel.Debug, _connectionStartedEventId, It.IsAny(), null, It.IsAny>())) + .Callback(() => + { + connectionStartedTcs.SetResult(null); + }); + + var mockLoggerFactory = new Mock(); + mockLoggerFactory + .Setup(factory => factory.CreateLogger("Microsoft.AspNetCore.Server.Kestrel")) + .Returns(mockLogger.Object); + mockLoggerFactory + .Setup(factory => factory.CreateLogger(It.IsNotIn(new[] { "Microsoft.AspNetCore.Server.Kestrel" }))) + .Returns(Mock.Of()); + var builder = new WebHostBuilder() - .UseLoggerFactory(new TestLoggerFactory(testSink, true)) + .UseLoggerFactory(mockLoggerFactory.Object) .UseKestrel() .UseUrls($"http://127.0.0.1:0") .Configure(app => app.Run(context => { - return Task.FromResult(0); + return TaskCache.CompletedTask; })); using (var host = builder.Build()) @@ -262,40 +278,44 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests using (var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)) { socket.Connect(new IPEndPoint(IPAddress.Loopback, host.GetPort())); + // Wait until connection is established - Assert.True(await connectionStarted.WaitAsync(_semaphoreWaitTimeout)); + await connectionStartedTcs.Task.TimeoutAfter(TimeSpan.FromSeconds(10)); // Force a reset socket.LingerState = new LingerOption(true, 0); } - - // Wait until connection error is logged - Assert.True(await connectionResetLogged.WaitAsync(_semaphoreWaitTimeout)); - - // Check the no log level higher than Debug was used for a reset before a request - Assert.Equal(LogLevel.Debug, testSink.MaxLogLevel); - - // Check for expected message - Assert.NotNull(testSink.ConnectionResetMessage); - Assert.Contains("reset", testSink.ConnectionResetMessage); } + + mockLogger.Verify(logger => logger.Log(LogLevel.Debug, _connectionResetEventId, It.IsAny(), null, It.IsAny>())); } [Fact] public async Task ConnectionResetBetweenRequestsIsLoggedAsDebug() { - var connectionStarted = new SemaphoreSlim(0); - var connectionResetLogged = new SemaphoreSlim(0); - var testSink = new ConnectionErrorTestSink( - () => { }, () => connectionResetLogged.Release(), () => { }); + var mockLogger = new Mock(); + mockLogger + .Setup(logger => logger.IsEnabled(It.IsAny())) + .Returns(true); + + var mockLoggerFactory = new Mock(); + mockLoggerFactory + .Setup(factory => factory.CreateLogger("Microsoft.AspNetCore.Server.Kestrel")) + .Returns(mockLogger.Object); + mockLoggerFactory + .Setup(factory => factory.CreateLogger(It.IsNotIn(new[] { "Microsoft.AspNetCore.Server.Kestrel" }))) + .Returns(Mock.Of()); + + var connectionStartedTcs = new TaskCompletionSource(); + var builder = new WebHostBuilder() - .UseLoggerFactory(new TestLoggerFactory(testSink, true)) + .UseLoggerFactory(mockLoggerFactory.Object) .UseKestrel() .UseUrls($"http://127.0.0.1:0") .Configure(app => app.Run(context => { - connectionStarted.Release(); - return Task.FromResult(0); + connectionStartedTcs.SetResult(null); + return TaskCache.CompletedTask; })); using (var host = builder.Build()) @@ -308,39 +328,42 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests socket.Send(Encoding.ASCII.GetBytes("GET / HTTP/1.1\r\n\r\n")); // Wait until connection is established - Assert.True(await connectionStarted.WaitAsync(_semaphoreWaitTimeout)); + await connectionStartedTcs.Task.TimeoutAfter(TimeSpan.FromSeconds(10)); // Force a reset socket.LingerState = new LingerOption(true, 0); } - - // Wait until connection error is logged - Assert.True(await connectionResetLogged.WaitAsync(_semaphoreWaitTimeout)); - - // Check the no log level higher than Debug was used for a reset between a requests - Assert.Equal(LogLevel.Debug, testSink.MaxLogLevel); - - // Check for expected message - Assert.NotNull(testSink.ConnectionResetMessage); - Assert.Contains("reset", testSink.ConnectionResetMessage); } + + mockLogger.Verify(logger => logger.Log(LogLevel.Debug, _connectionResetEventId, It.IsAny(), null, It.IsAny>())); } [Fact] - public async Task ConnectionResetMidRequestIsLoggedAsInformation() + public async Task ConnectionResetMidRequestIsLoggedAsDebug() { - var connectionStarted = new SemaphoreSlim(0); - var connectionResetLogged = new SemaphoreSlim(0); - var requestProcessingErrorLogged = new SemaphoreSlim(0); - var testSink = new ConnectionErrorTestSink( - () => connectionStarted.Release(), () => connectionResetLogged.Release(), () => requestProcessingErrorLogged.Release()); + var mockLogger = new Mock(); + mockLogger + .Setup(logger => logger.IsEnabled(It.IsAny())) + .Returns(true); + + var mockLoggerFactory = new Mock(); + mockLoggerFactory + .Setup(factory => factory.CreateLogger("Microsoft.AspNetCore.Server.Kestrel")) + .Returns(mockLogger.Object); + mockLoggerFactory + .Setup(factory => factory.CreateLogger(It.IsNotIn(new[] { "Microsoft.AspNetCore.Server.Kestrel" }))) + .Returns(Mock.Of()); + + var connectionStartedTcs = new TaskCompletionSource(); + var builder = new WebHostBuilder() - .UseLoggerFactory(new TestLoggerFactory(testSink, true)) + .UseLoggerFactory(mockLoggerFactory.Object) .UseKestrel() .UseUrls($"http://127.0.0.1:0") - .Configure(app => app.Run(context => + .Configure(app => app.Run(async context => { - return Task.FromResult(0); + connectionStartedTcs.SetResult(null); + await context.Request.Body.ReadAsync(new byte[1], 0, 1); })); using (var host = builder.Build()) @@ -350,33 +373,17 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests using (var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)) { socket.Connect(new IPEndPoint(IPAddress.Loopback, host.GetPort())); - socket.Send(Encoding.ASCII.GetBytes("GET")); + socket.Send(Encoding.ASCII.GetBytes("GET / HTTP/1.1\r\n\r\n")); // Wait until connection is established - Assert.True(await connectionStarted.WaitAsync(_semaphoreWaitTimeout)); + await connectionStartedTcs.Task.TimeoutAfter(TimeSpan.FromSeconds(10)); - // Ensure "GET" has been processed - // Sadly, there is no event/log for starting request line processing - await Task.Delay(1000); - - // Force a reset, give some time for the "GET" to be processed + // Force a reset socket.LingerState = new LingerOption(true, 0); } - - // Wait until connection error and request processingError is logged - var waitAsyncResults = await Task.WhenAll(connectionResetLogged.WaitAsync(_semaphoreWaitTimeout), requestProcessingErrorLogged.WaitAsync(_semaphoreWaitTimeout)); - - Assert.All(waitAsyncResults, Assert.True); - - // Check the no log level lower than Information was used for a reset mid-request - Assert.Equal(LogLevel.Information, testSink.MaxLogLevel); - - // Check for expected message - Assert.NotNull(testSink.ConnectionResetMessage); - Assert.Contains("reset", testSink.ConnectionResetMessage); - Assert.NotNull(testSink.RequestProcessingErrorMessage); - Assert.Contains("abnormal", testSink.RequestProcessingErrorMessage); } + + mockLogger.Verify(logger => logger.Log(LogLevel.Debug, _connectionResetEventId, It.IsAny(), null, It.IsAny>())); } [Fact] @@ -618,67 +625,5 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests Assert.NotEmpty(facts["RemotePort"].Value()); } } - - private class ConnectionErrorTestSink : ITestSink - { - private readonly Action _connectionStarted; - private readonly Action _connectionResetLogged; - private readonly Action _requestProcessingErrorLogged; - - public ConnectionErrorTestSink( - Action connectionStarted, - Action connectionResetLogged, - Action requestProcessingErrorLogged) - { - _connectionStarted = connectionStarted; - _connectionResetLogged = connectionResetLogged; - _requestProcessingErrorLogged = requestProcessingErrorLogged; - } - - public LogLevel MaxLogLevel { get; set; } - - public string ConnectionResetMessage { get; set; } - - public string RequestProcessingErrorMessage { get; set; } - - public Func BeginEnabled { get; set; } - - public List Scopes { get; set; } - - public Func WriteEnabled { get; set; } - - public List Writes { get; set; } - - public void Begin(BeginScopeContext context) - { - } - - public void Write(WriteContext context) - { - if (context.LoggerName == "Microsoft.AspNetCore.Server.Kestrel" && context.LogLevel > MaxLogLevel) - { - MaxLogLevel = context.LogLevel; - } - - const int connectionStartEventId = 1; - const int connectionResetEventId = 19; - const int requestProcessingErrorEventId = 20; - - if (context.EventId.Id == connectionStartEventId) - { - _connectionStarted(); - } - else if (context.EventId.Id == connectionResetEventId) - { - ConnectionResetMessage = context.Formatter(context.State, context.Exception); - _connectionResetLogged(); - } - else if (context.EventId.Id == requestProcessingErrorEventId) - { - RequestProcessingErrorMessage = context.Formatter(context.State, context.Exception); - _requestProcessingErrorLogged(); - } - } - } } } \ No newline at end of file From c65734667a3f33977af0134e9710a079abf40550 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Wed, 22 Mar 2017 02:16:28 -0700 Subject: [PATCH 1146/1662] Optimize calls into StreamSocketOuput to WriteFast further (#1538) * Optimize calls into StreamSocketOuput to WriteFast further - Added overloads to array, offset, length to avoid implicit conversions to ReadOnlySpan. - Use similar optimizations for multi buffer writes for strings and ints - Use ref locals in multi write instead of pointers and pinning --- .../Adapter/Internal/StreamSocketOutput.cs | 5 +- .../Internal/Http/FrameHeaders.Generated.cs | 72 +++++------ .../Internal/Http/PipelineExtensions.cs | 118 ++++++++++-------- tools/CodeGenerator/KnownHeaders.cs | 4 +- 4 files changed, 109 insertions(+), 90 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Adapter/Internal/StreamSocketOutput.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Adapter/Internal/StreamSocketOutput.cs index 92a32c2a28..34ef6ae317 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Adapter/Internal/StreamSocketOutput.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Adapter/Internal/StreamSocketOutput.cs @@ -118,8 +118,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Adapter.Internal { await _outputStream.FlushAsync(); } - - if (buffer.IsSingleSpan) + else if (buffer.IsSingleSpan) { var array = buffer.First.GetArray(); await _outputStream.WriteAsync(array.Array, array.Offset, array.Count); @@ -135,7 +134,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Adapter.Internal } finally { - _pipe.Reader.Advance(readResult.Buffer.End); + _pipe.Reader.Advance(buffer.End); } } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameHeaders.Generated.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameHeaders.Generated.cs index ff13b9383c..c4c43f0eb2 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameHeaders.Generated.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameHeaders.Generated.cs @@ -7771,7 +7771,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var value = _headers._Connection[i]; if (value != null) { - output.WriteFast(new Span(_headerBytes, 17, 14)); + output.WriteFast(_headerBytes, 17, 14); output.WriteAscii(value); } } @@ -7797,7 +7797,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var value = _headers._Date[i]; if (value != null) { - output.WriteFast(new Span(_headerBytes, 31, 8)); + output.WriteFast(_headerBytes, 31, 8); output.WriteAscii(value); } } @@ -7818,7 +7818,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var value = _headers._ContentType[i]; if (value != null) { - output.WriteFast(new Span(_headerBytes, 133, 16)); + output.WriteFast(_headerBytes, 133, 16); output.WriteAscii(value); } } @@ -7844,7 +7844,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var value = _headers._Server[i]; if (value != null) { - output.WriteFast(new Span(_headerBytes, 350, 10)); + output.WriteFast(_headerBytes, 350, 10); output.WriteAscii(value); } } @@ -7858,7 +7858,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } if ((tempBits & -9223372036854775808L) != 0) { - output.WriteFast(new Span(_headerBytes, 592, 18)); + output.WriteFast(_headerBytes, 592, 18); output.WriteNumeric((ulong)ContentLength.Value); if((tempBits & ~-9223372036854775808L) == 0) @@ -7876,7 +7876,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var value = _headers._CacheControl[i]; if (value != null) { - output.WriteFast(new Span(_headerBytes, 0, 17)); + output.WriteFast(_headerBytes, 0, 17); output.WriteAscii(value); } } @@ -7897,7 +7897,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var value = _headers._KeepAlive[i]; if (value != null) { - output.WriteFast(new Span(_headerBytes, 39, 14)); + output.WriteFast(_headerBytes, 39, 14); output.WriteAscii(value); } } @@ -7918,7 +7918,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var value = _headers._Pragma[i]; if (value != null) { - output.WriteFast(new Span(_headerBytes, 53, 10)); + output.WriteFast(_headerBytes, 53, 10); output.WriteAscii(value); } } @@ -7939,7 +7939,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var value = _headers._Trailer[i]; if (value != null) { - output.WriteFast(new Span(_headerBytes, 63, 11)); + output.WriteFast(_headerBytes, 63, 11); output.WriteAscii(value); } } @@ -7965,7 +7965,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var value = _headers._TransferEncoding[i]; if (value != null) { - output.WriteFast(new Span(_headerBytes, 74, 21)); + output.WriteFast(_headerBytes, 74, 21); output.WriteAscii(value); } } @@ -7986,7 +7986,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var value = _headers._Upgrade[i]; if (value != null) { - output.WriteFast(new Span(_headerBytes, 95, 11)); + output.WriteFast(_headerBytes, 95, 11); output.WriteAscii(value); } } @@ -8007,7 +8007,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var value = _headers._Via[i]; if (value != null) { - output.WriteFast(new Span(_headerBytes, 106, 7)); + output.WriteFast(_headerBytes, 106, 7); output.WriteAscii(value); } } @@ -8028,7 +8028,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var value = _headers._Warning[i]; if (value != null) { - output.WriteFast(new Span(_headerBytes, 113, 11)); + output.WriteFast(_headerBytes, 113, 11); output.WriteAscii(value); } } @@ -8049,7 +8049,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var value = _headers._Allow[i]; if (value != null) { - output.WriteFast(new Span(_headerBytes, 124, 9)); + output.WriteFast(_headerBytes, 124, 9); output.WriteAscii(value); } } @@ -8070,7 +8070,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var value = _headers._ContentEncoding[i]; if (value != null) { - output.WriteFast(new Span(_headerBytes, 149, 20)); + output.WriteFast(_headerBytes, 149, 20); output.WriteAscii(value); } } @@ -8091,7 +8091,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var value = _headers._ContentLanguage[i]; if (value != null) { - output.WriteFast(new Span(_headerBytes, 169, 20)); + output.WriteFast(_headerBytes, 169, 20); output.WriteAscii(value); } } @@ -8112,7 +8112,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var value = _headers._ContentLocation[i]; if (value != null) { - output.WriteFast(new Span(_headerBytes, 189, 20)); + output.WriteFast(_headerBytes, 189, 20); output.WriteAscii(value); } } @@ -8133,7 +8133,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var value = _headers._ContentMD5[i]; if (value != null) { - output.WriteFast(new Span(_headerBytes, 209, 15)); + output.WriteFast(_headerBytes, 209, 15); output.WriteAscii(value); } } @@ -8154,7 +8154,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var value = _headers._ContentRange[i]; if (value != null) { - output.WriteFast(new Span(_headerBytes, 224, 17)); + output.WriteFast(_headerBytes, 224, 17); output.WriteAscii(value); } } @@ -8175,7 +8175,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var value = _headers._Expires[i]; if (value != null) { - output.WriteFast(new Span(_headerBytes, 241, 11)); + output.WriteFast(_headerBytes, 241, 11); output.WriteAscii(value); } } @@ -8196,7 +8196,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var value = _headers._LastModified[i]; if (value != null) { - output.WriteFast(new Span(_headerBytes, 252, 17)); + output.WriteFast(_headerBytes, 252, 17); output.WriteAscii(value); } } @@ -8217,7 +8217,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var value = _headers._AcceptRanges[i]; if (value != null) { - output.WriteFast(new Span(_headerBytes, 269, 17)); + output.WriteFast(_headerBytes, 269, 17); output.WriteAscii(value); } } @@ -8238,7 +8238,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var value = _headers._Age[i]; if (value != null) { - output.WriteFast(new Span(_headerBytes, 286, 7)); + output.WriteFast(_headerBytes, 286, 7); output.WriteAscii(value); } } @@ -8259,7 +8259,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var value = _headers._ETag[i]; if (value != null) { - output.WriteFast(new Span(_headerBytes, 293, 8)); + output.WriteFast(_headerBytes, 293, 8); output.WriteAscii(value); } } @@ -8280,7 +8280,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var value = _headers._Location[i]; if (value != null) { - output.WriteFast(new Span(_headerBytes, 301, 12)); + output.WriteFast(_headerBytes, 301, 12); output.WriteAscii(value); } } @@ -8301,7 +8301,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var value = _headers._ProxyAuthenticate[i]; if (value != null) { - output.WriteFast(new Span(_headerBytes, 313, 22)); + output.WriteFast(_headerBytes, 313, 22); output.WriteAscii(value); } } @@ -8322,7 +8322,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var value = _headers._RetryAfter[i]; if (value != null) { - output.WriteFast(new Span(_headerBytes, 335, 15)); + output.WriteFast(_headerBytes, 335, 15); output.WriteAscii(value); } } @@ -8343,7 +8343,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var value = _headers._SetCookie[i]; if (value != null) { - output.WriteFast(new Span(_headerBytes, 360, 14)); + output.WriteFast(_headerBytes, 360, 14); output.WriteAscii(value); } } @@ -8364,7 +8364,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var value = _headers._Vary[i]; if (value != null) { - output.WriteFast(new Span(_headerBytes, 374, 8)); + output.WriteFast(_headerBytes, 374, 8); output.WriteAscii(value); } } @@ -8385,7 +8385,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var value = _headers._WWWAuthenticate[i]; if (value != null) { - output.WriteFast(new Span(_headerBytes, 382, 20)); + output.WriteFast(_headerBytes, 382, 20); output.WriteAscii(value); } } @@ -8406,7 +8406,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var value = _headers._AccessControlAllowCredentials[i]; if (value != null) { - output.WriteFast(new Span(_headerBytes, 402, 36)); + output.WriteFast(_headerBytes, 402, 36); output.WriteAscii(value); } } @@ -8427,7 +8427,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var value = _headers._AccessControlAllowHeaders[i]; if (value != null) { - output.WriteFast(new Span(_headerBytes, 438, 32)); + output.WriteFast(_headerBytes, 438, 32); output.WriteAscii(value); } } @@ -8448,7 +8448,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var value = _headers._AccessControlAllowMethods[i]; if (value != null) { - output.WriteFast(new Span(_headerBytes, 470, 32)); + output.WriteFast(_headerBytes, 470, 32); output.WriteAscii(value); } } @@ -8469,7 +8469,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var value = _headers._AccessControlAllowOrigin[i]; if (value != null) { - output.WriteFast(new Span(_headerBytes, 502, 31)); + output.WriteFast(_headerBytes, 502, 31); output.WriteAscii(value); } } @@ -8490,7 +8490,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var value = _headers._AccessControlExposeHeaders[i]; if (value != null) { - output.WriteFast(new Span(_headerBytes, 533, 33)); + output.WriteFast(_headerBytes, 533, 33); output.WriteAscii(value); } } @@ -8511,7 +8511,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var value = _headers._AccessControlMaxAge[i]; if (value != null) { - output.WriteFast(new Span(_headerBytes, 566, 26)); + output.WriteFast(_headerBytes, 566, 26); output.WriteAscii(value); } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/PipelineExtensions.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/PipelineExtensions.cs index d3bbe8a46c..6396b56781 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/PipelineExtensions.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/PipelineExtensions.cs @@ -94,7 +94,17 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } // Temporary until the fast write implementation propagates from corefx - public unsafe static void WriteFast(this WritableBuffer buffer, ReadOnlySpan source) + public unsafe static void WriteFast(this WritableBuffer buffer, byte[] source) + { + buffer.WriteFast(source, 0, source.Length); + } + + public unsafe static void WriteFast(this WritableBuffer buffer, ArraySegment source) + { + buffer.WriteFast(source.Array, source.Offset, source.Count); + } + + public unsafe static void WriteFast(this WritableBuffer buffer, byte[] source, int offset, int length) { var dest = buffer.Buffer.Span; var destLength = dest.Length; @@ -108,74 +118,79 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http destLength = dest.Length; } - var sourceLength = source.Length; + var sourceLength = length; if (sourceLength <= destLength) { - ref byte pSource = ref source.DangerousGetPinnableReference(); + ref byte pSource = ref source[offset]; ref byte pDest = ref dest.DangerousGetPinnableReference(); Unsafe.CopyBlockUnaligned(ref pDest, ref pSource, (uint)sourceLength); buffer.Advance(sourceLength); return; } - buffer.WriteMultiBuffer(source); + buffer.WriteMultiBuffer(source, offset, length); } - private static unsafe void WriteMultiBuffer(this WritableBuffer buffer, ReadOnlySpan source) + private static unsafe void WriteMultiBuffer(this WritableBuffer buffer, byte[] source, int offset, int length) { - var remaining = source.Length; - var offset = 0; + var remaining = length; - fixed (byte* pSource = &source.DangerousGetPinnableReference()) + while (remaining > 0) { - while (remaining > 0) + var writable = Math.Min(remaining, buffer.Buffer.Length); + + buffer.Ensure(writable); + + if (writable == 0) { - var writable = Math.Min(remaining, buffer.Buffer.Length); - - buffer.Ensure(writable); - - if (writable == 0) - { - continue; - } - - fixed (byte* pDest = &buffer.Buffer.Span.DangerousGetPinnableReference()) - { - Unsafe.CopyBlockUnaligned(pDest, pSource + offset, (uint)writable); - } - - remaining -= writable; - offset += writable; - - buffer.Advance(writable); + continue; } + + ref byte pSource = ref source[offset]; + ref byte pDest = ref buffer.Buffer.Span.DangerousGetPinnableReference(); + + Unsafe.CopyBlockUnaligned(ref pDest, ref pSource, (uint)writable); + + remaining -= writable; + offset += writable; + + buffer.Advance(writable); } } public unsafe static void WriteAscii(this WritableBuffer buffer, string data) { - if (!string.IsNullOrEmpty(data)) + if (string.IsNullOrEmpty(data)) { - if (buffer.Buffer.IsEmpty) + return; + } + + var dest = buffer.Buffer.Span; + var destLength = dest.Length; + var sourceLength = data.Length; + + if (destLength == 0) + { + buffer.Ensure(); + + dest = buffer.Buffer.Span; + destLength = dest.Length; + } + + // Fast path, try copying to the available memory directly + if (sourceLength <= destLength) + { + fixed (char* input = data) + fixed (byte* output = &dest.DangerousGetPinnableReference()) { - buffer.Ensure(); + EncodeAsciiCharsToBytes(input, output, sourceLength); } - // Fast path, try copying to the available memory directly - if (data.Length <= buffer.Buffer.Length) - { - fixed (char* input = data) - fixed (byte* output = &buffer.Buffer.Span.DangerousGetPinnableReference()) - { - EncodeAsciiCharsToBytes(input, output, data.Length); - } - - buffer.Advance(data.Length); - } - else - { - buffer.WriteAsciiMultiWrite(data); - } + buffer.Advance(sourceLength); + } + else + { + buffer.WriteAsciiMultiWrite(data); } } @@ -184,15 +199,20 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { const byte AsciiDigitStart = (byte)'0'; - if (buffer.Buffer.IsEmpty) + var span = buffer.Buffer.Span; + var bytesLeftInBlock = span.Length; + + if (bytesLeftInBlock == 0) { buffer.Ensure(); + + span = buffer.Buffer.Span; + bytesLeftInBlock = span.Length; } // Fast path, try copying to the available memory directly - var bytesLeftInBlock = buffer.Buffer.Length; var simpleWrite = true; - fixed (byte* output = &buffer.Buffer.Span.DangerousGetPinnableReference()) + fixed (byte* output = &span.DangerousGetPinnableReference()) { var start = output; if (number < 10 && bytesLeftInBlock >= 1) @@ -250,7 +270,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http while (value != 0); var length = _maxULongByteLength - position; - buffer.WriteFast(new ReadOnlySpan(byteBuffer, position, length)); + buffer.WriteFast(new ArraySegment(byteBuffer, position, length)); } [MethodImpl(MethodImplOptions.NoInlining)] diff --git a/tools/CodeGenerator/KnownHeaders.cs b/tools/CodeGenerator/KnownHeaders.cs index f12aea58d6..5d76a53305 100644 --- a/tools/CodeGenerator/KnownHeaders.cs +++ b/tools/CodeGenerator/KnownHeaders.cs @@ -540,7 +540,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var value = _headers._{header.Identifier}[i]; if (value != null) {{ - output.WriteFast(new Span(_headerBytes, {header.BytesOffset}, {header.BytesCount})); + output.WriteFast(_headerBytes, {header.BytesOffset}, {header.BytesCount}); output.WriteAscii(value); }} }} @@ -554,7 +554,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http }}{(header.Identifier == "Server" ? $@" if ((tempBits & {1L << 63}L) != 0) {{ - output.WriteFast(new Span(_headerBytes, {loop.Headers.First(x => x.Identifier == "ContentLength").BytesOffset}, {loop.Headers.First(x => x.Identifier == "ContentLength").BytesCount})); + output.WriteFast(_headerBytes, {loop.Headers.First(x => x.Identifier == "ContentLength").BytesOffset}, {loop.Headers.First(x => x.Identifier == "ContentLength").BytesCount}); output.WriteNumeric((ulong)ContentLength.Value); if((tempBits & ~{1L << 63}L) == 0) From fffb823e992a90145e319eb2d5702334e2d17a64 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Wed, 22 Mar 2017 10:33:38 -0700 Subject: [PATCH 1147/1662] Dispose socket in test after synchronous connect --- .../AddressRegistrationTests.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs index 21dba18436..27c5191b7d 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs @@ -562,6 +562,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } else { + socketArgs.ConnectSocket?.Dispose(); return socketArgs.SocketError == SocketError.Success; } } From ff99c4c865097f7b3dbbe64d30d489298a32df4c Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Thu, 23 Mar 2017 01:30:06 +0000 Subject: [PATCH 1148/1662] Fix benchmarks (broken) (#1515) * Fix benchmarks * Remove Moq from benchmarks --- .../FrameParsingOverheadBenchmark.cs | 1 + .../FrameWritingBenchmark.cs | 6 +-- ...pNetCore.Server.Kestrel.Performance.csproj | 1 - .../Mocks/MockConnectionControl.cs | 17 +++++++++ .../Mocks/MockTrace.cs | 37 +++++++++++++++++++ .../RequestParsingBenchmark.cs | 1 + .../ResponseHeaderCollectionBenchmark.cs | 1 + .../ResponseHeadersWritingBenchmark.cs | 8 ++-- test/shared/TestFrame.cs | 12 ++++++ 9 files changed, 76 insertions(+), 8 deletions(-) create mode 100644 test/Microsoft.AspNetCore.Server.Kestrel.Performance/Mocks/MockConnectionControl.cs create mode 100644 test/Microsoft.AspNetCore.Server.Kestrel.Performance/Mocks/MockTrace.cs diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameParsingOverheadBenchmark.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameParsingOverheadBenchmark.cs index a772eee781..2b5065707a 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameParsingOverheadBenchmark.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameParsingOverheadBenchmark.cs @@ -23,6 +23,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance { var connectionContext = new MockConnection(); connectionContext.ListenerContext.ServiceContext.HttpParserFactory = frame => NullParser.Instance; + connectionContext.ListenerContext.ServiceContext.ServerOptions = new KestrelServerOptions(); _frame = new Frame(application: null, context: connectionContext); } diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameWritingBenchmark.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameWritingBenchmark.cs index d632e337cd..ffb4e95b62 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameWritingBenchmark.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameWritingBenchmark.cs @@ -9,9 +9,7 @@ using System.Threading.Tasks; using BenchmarkDotNet.Attributes; using Microsoft.AspNetCore.Server.Kestrel.Internal; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.AspNetCore.Testing; -using Moq; namespace Microsoft.AspNetCore.Server.Kestrel.Performance { @@ -95,7 +93,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance { DateHeaderValueManager = new DateHeaderValueManager(), ServerOptions = new KestrelServerOptions(), - Log = Mock.Of() + Log = new MockTrace() }; var listenerContext = new ListenerContext(serviceContext) { @@ -105,7 +103,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance { Input = socketInput, Output = new MockSocketOutput(), - ConnectionControl = Mock.Of() + ConnectionControl = new MockConnectionControl() }; connectionContext.ListenerContext.ServiceContext.HttpParserFactory = f => new Internal.Http.KestrelHttpParser(log: null); diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Microsoft.AspNetCore.Server.Kestrel.Performance.csproj b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Microsoft.AspNetCore.Server.Kestrel.Performance.csproj index 88b306a3d0..8718f3f9ae 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Microsoft.AspNetCore.Server.Kestrel.Performance.csproj +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Microsoft.AspNetCore.Server.Kestrel.Performance.csproj @@ -24,7 +24,6 @@ - diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Mocks/MockConnectionControl.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Mocks/MockConnectionControl.cs new file mode 100644 index 0000000000..14e53e3f53 --- /dev/null +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Mocks/MockConnectionControl.cs @@ -0,0 +1,17 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; + +namespace Microsoft.AspNetCore.Server.Kestrel.Performance +{ + public class MockConnectionControl : IConnectionControl + { + public void CancelTimeout() { } + public void End(ProduceEndType endType) { } + public void Pause() { } + public void ResetTimeout(long milliseconds, TimeoutAction timeoutAction) { } + public void Resume() { } + public void SetTimeout(long milliseconds, TimeoutAction timeoutAction) { } + } +} diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Mocks/MockTrace.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Mocks/MockTrace.cs new file mode 100644 index 0000000000..f7737a63f9 --- /dev/null +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Mocks/MockTrace.cs @@ -0,0 +1,37 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; +using Microsoft.Extensions.Logging; + +namespace Microsoft.AspNetCore.Server.Kestrel.Performance +{ + public class MockTrace : IKestrelTrace + { + public void ApplicationError(string connectionId, Exception ex) { } + public IDisposable BeginScope(TState state) => null; + public void ConnectionBadRequest(string connectionId, BadHttpRequestException ex) { } + public void ConnectionDisconnect(string connectionId) { } + public void ConnectionDisconnectedWrite(string connectionId, int count, Exception ex) { } + public void ConnectionError(string connectionId, Exception ex) { } + public void ConnectionHeadResponseBodyWrite(string connectionId, long count) { } + public void ConnectionKeepAlive(string connectionId) { } + public void ConnectionPause(string connectionId) { } + public void ConnectionRead(string connectionId, int count) { } + public void ConnectionReadFin(string connectionId) { } + public void ConnectionReset(string connectionId) { } + public void ConnectionResume(string connectionId) { } + public void ConnectionStart(string connectionId) { } + public void ConnectionStop(string connectionId) { } + public void ConnectionWrite(string connectionId, int count) { } + public void ConnectionWriteCallback(string connectionId, int status) { } + public void ConnectionWriteFin(string connectionId) { } + public void ConnectionWroteFin(string connectionId, int status) { } + public bool IsEnabled(LogLevel logLevel) => false; + public void Log(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func formatter) { } + public void NotAllConnectionsAborted() { } + public void NotAllConnectionsClosedGracefully() { } + public void RequestProcessingError(string connectionId, Exception ex) { } + } +} diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsingBenchmark.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsingBenchmark.cs index dc07d53270..8e29354eeb 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsingBenchmark.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsingBenchmark.cs @@ -23,6 +23,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance { var connectionContext = new MockConnection(); connectionContext.ListenerContext.ServiceContext.HttpParserFactory = frame => new KestrelHttpParser(frame.ConnectionContext.ListenerContext.ServiceContext.Log); + connectionContext.ListenerContext.ServiceContext.ServerOptions = new KestrelServerOptions(); Frame = new Frame(application: null, context: connectionContext); PipelineFactory = new PipeFactory(); diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/ResponseHeaderCollectionBenchmark.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/ResponseHeaderCollectionBenchmark.cs index 48b79138b5..f8668024af 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/ResponseHeaderCollectionBenchmark.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/ResponseHeaderCollectionBenchmark.cs @@ -169,6 +169,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance { var connectionContext = new MockConnection(); connectionContext.ListenerContext.ServiceContext.HttpParserFactory = f => new KestrelHttpParser(f.ConnectionContext.ListenerContext.ServiceContext.Log); + connectionContext.ListenerContext.ServiceContext.ServerOptions = new KestrelServerOptions(); var frame = new Frame(application: null, context: connectionContext); frame.Reset(); frame.InitializeHeaders(); diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/ResponseHeadersWritingBenchmark.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/ResponseHeadersWritingBenchmark.cs index 0fb6aab65d..642ad4e57c 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/ResponseHeadersWritingBenchmark.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/ResponseHeadersWritingBenchmark.cs @@ -14,7 +14,6 @@ using Microsoft.AspNetCore.Server.Kestrel.Internal; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.AspNetCore.Testing; -using Moq; namespace Microsoft.AspNetCore.Server.Kestrel.Performance { @@ -39,6 +38,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance { _frame.Reset(); _frame.StatusCode = 200; + _frame.HttpVersionEnum = HttpVersion.Http11; + _frame.KeepAlive = true; Task writeTask = Task.CompletedTask; switch (Type) @@ -119,7 +120,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance { DateHeaderValueManager = new DateHeaderValueManager(), ServerOptions = new KestrelServerOptions(), - Log = Mock.Of() + Log = new MockTrace() }; var listenerContext = new ListenerContext(serviceContext) @@ -131,10 +132,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance { Input = input, Output = socketOutput, - ConnectionControl = Mock.Of() + ConnectionControl = new MockConnectionControl() }; connectionContext.ListenerContext.ServiceContext.HttpParserFactory = f => new KestrelHttpParser(log: null); + connectionContext.ListenerContext.ServiceContext.ServerOptions = new KestrelServerOptions(); var frame = new TestFrame(application: null, context: connectionContext); frame.Reset(); diff --git a/test/shared/TestFrame.cs b/test/shared/TestFrame.cs index 4ccba9bd4a..5eda865139 100644 --- a/test/shared/TestFrame.cs +++ b/test/shared/TestFrame.cs @@ -14,6 +14,18 @@ namespace Microsoft.AspNetCore.Testing { } + public HttpVersion HttpVersionEnum + { + get => _httpVersion; + set => _httpVersion = value; + } + + public bool KeepAlive + { + get => _keepAlive; + set => _keepAlive = value; + } + public Task ProduceEndAsync() { return ProduceEnd(); From f090b7a9c6774f094ef996fd8497eac33e2f4bce Mon Sep 17 00:00:00 2001 From: David Fowler Date: Thu, 23 Mar 2017 06:52:24 -0700 Subject: [PATCH 1149/1662] React to corefxlab changes (#1539) - Removed use of TryRead and follow the pin and use pattern in the other APIs https://github.com/dotnet/corefxlab/pull/1348 --- .../Internal/Http/KestrelHttpParser.cs | 4 ++-- .../Internal/Infrastructure/HttpUtilities.cs | 19 ++++++++++++++----- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/KestrelHttpParser.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/KestrelHttpParser.cs index e76515b042..5e3aa7097e 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/KestrelHttpParser.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/KestrelHttpParser.cs @@ -36,7 +36,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http // Prepare the first span var span = buffer.First.Span; - var lineIndex = span.SequentialIndexOf(ByteLF); + var lineIndex = span.IndexOf(ByteLF); if (lineIndex >= 0) { consumed = buffer.Move(consumed, lineIndex + 1); @@ -255,7 +255,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http index = reader.Index; } - var endIndex = new Span(pBuffer + index, remaining).SequentialIndexOf(ByteLF); + var endIndex = new Span(pBuffer + index, remaining).IndexOf(ByteLF); var length = 0; if (endIndex != -1) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/HttpUtilities.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/HttpUtilities.cs index 003c8ccc8e..b4dafbd3a7 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/HttpUtilities.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/HttpUtilities.cs @@ -270,23 +270,32 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure /// A reference to the known scheme, if the input matches any /// True when memory starts with known http or https schema [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static bool GetKnownHttpScheme(this Span span, out HttpScheme knownScheme) + public static unsafe bool GetKnownHttpScheme(this Span span, out HttpScheme knownScheme) { - if (span.TryRead(out var value)) + fixed (byte* data = &span.DangerousGetPinnableReference()) { - if ((value & _mask7Chars) == _httpSchemeLong) + return GetKnownHttpScheme(data, span.Length, out knownScheme); + } + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static unsafe bool GetKnownHttpScheme(byte* location, int length, out HttpScheme knownScheme) + { + if (length >= sizeof(ulong)) + { + var scheme = *(ulong*)location; + if ((scheme & _mask7Chars) == _httpSchemeLong) { knownScheme = HttpScheme.Http; return true; } - if (value == _httpsSchemeLong) + if (scheme == _httpsSchemeLong) { knownScheme = HttpScheme.Https; return true; } } - knownScheme = HttpScheme.Unknown; return false; } From 3e6303b6c15c571a0eca618042add2f246fe1ead Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Thu, 23 Mar 2017 21:52:29 -0700 Subject: [PATCH 1150/1662] Fix flakiness in connection reset logging tests. --- .../RequestTests.cs | 83 +++++++++++++------ 1 file changed, 59 insertions(+), 24 deletions(-) diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs index 55c4e326bc..10a718c1e8 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs @@ -30,6 +30,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests public class RequestTests { private const int _connectionStartedEventId = 1; + private const int _connectionKeepAliveEventId = 9; private const int _connectionResetEventId = 19; private const int _semaphoreWaitTimeout = 2500; @@ -241,7 +242,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [Fact] public async Task ConnectionResetPriorToRequestIsLoggedAsDebug() { - var connectionStartedTcs = new TaskCompletionSource(); + var connectionStarted = new SemaphoreSlim(0); + var connectionReset = new SemaphoreSlim(0); var mockLogger = new Mock(); mockLogger @@ -251,7 +253,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests .Setup(logger => logger.Log(LogLevel.Debug, _connectionStartedEventId, It.IsAny(), null, It.IsAny>())) .Callback(() => { - connectionStartedTcs.SetResult(null); + connectionStarted.Release(); + }); + mockLogger + .Setup(logger => logger.Log(LogLevel.Debug, _connectionResetEventId, It.IsAny(), null, It.IsAny>())) + .Callback(() => + { + connectionReset.Release(); }); var mockLoggerFactory = new Mock(); @@ -266,10 +274,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests .UseLoggerFactory(mockLoggerFactory.Object) .UseKestrel() .UseUrls($"http://127.0.0.1:0") - .Configure(app => app.Run(context => - { - return TaskCache.CompletedTask; - })); + .Configure(app => app.Run(context => TaskCache.CompletedTask)); using (var host = builder.Build()) { @@ -280,23 +285,42 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests socket.Connect(new IPEndPoint(IPAddress.Loopback, host.GetPort())); // Wait until connection is established - await connectionStartedTcs.Task.TimeoutAfter(TimeSpan.FromSeconds(10)); + await connectionStarted.WaitAsync(TimeSpan.FromSeconds(10)); // Force a reset socket.LingerState = new LingerOption(true, 0); } - } - mockLogger.Verify(logger => logger.Log(LogLevel.Debug, _connectionResetEventId, It.IsAny(), null, It.IsAny>())); + // If the reset is correctly logged as Debug, the wait below should complete shortly. + // This check MUST come before disposing the server, otherwise there's a race where the RST + // is still in flight when the connection is aborted, leading to the reset never being received + // and therefore not logged. + await connectionReset.WaitAsync(TimeSpan.FromSeconds(10)); + } } [Fact] public async Task ConnectionResetBetweenRequestsIsLoggedAsDebug() { + var requestDone = new SemaphoreSlim(0); + var connectionReset = new SemaphoreSlim(0); + var mockLogger = new Mock(); mockLogger .Setup(logger => logger.IsEnabled(It.IsAny())) .Returns(true); + mockLogger + .Setup(logger => logger.Log(LogLevel.Debug, _connectionKeepAliveEventId, It.IsAny(), null, It.IsAny>())) + .Callback(() => + { + requestDone.Release(); + }); + mockLogger + .Setup(logger => logger.Log(LogLevel.Debug, _connectionResetEventId, It.IsAny(), null, It.IsAny>())) + .Callback(() => + { + connectionReset.Release(); + }); var mockLoggerFactory = new Mock(); mockLoggerFactory @@ -306,17 +330,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests .Setup(factory => factory.CreateLogger(It.IsNotIn(new[] { "Microsoft.AspNetCore.Server.Kestrel" }))) .Returns(Mock.Of()); - var connectionStartedTcs = new TaskCompletionSource(); var builder = new WebHostBuilder() .UseLoggerFactory(mockLoggerFactory.Object) .UseKestrel() .UseUrls($"http://127.0.0.1:0") - .Configure(app => app.Run(context => - { - connectionStartedTcs.SetResult(null); - return TaskCache.CompletedTask; - })); + .Configure(app => app.Run(context => TaskCache.CompletedTask)); using (var host = builder.Build()) { @@ -327,24 +346,36 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests socket.Connect(new IPEndPoint(IPAddress.Loopback, host.GetPort())); socket.Send(Encoding.ASCII.GetBytes("GET / HTTP/1.1\r\n\r\n")); - // Wait until connection is established - await connectionStartedTcs.Task.TimeoutAfter(TimeSpan.FromSeconds(10)); + // Wait until request is done being processed + await requestDone.WaitAsync(TimeSpan.FromSeconds(10)); // Force a reset socket.LingerState = new LingerOption(true, 0); } - } - mockLogger.Verify(logger => logger.Log(LogLevel.Debug, _connectionResetEventId, It.IsAny(), null, It.IsAny>())); + // If the reset is correctly logged as Debug, the wait below should complete shortly. + // This check MUST come before disposing the server, otherwise there's a race where the RST + // is still in flight when the connection is aborted, leading to the reset never being received + // and therefore not logged. + await connectionReset.WaitAsync(TimeSpan.FromSeconds(10)); + } } [Fact] public async Task ConnectionResetMidRequestIsLoggedAsDebug() { + var connectionReset = new SemaphoreSlim(0); + var mockLogger = new Mock(); mockLogger .Setup(logger => logger.IsEnabled(It.IsAny())) .Returns(true); + mockLogger + .Setup(logger => logger.Log(LogLevel.Debug, _connectionResetEventId, It.IsAny(), null, It.IsAny>())) + .Callback(() => + { + connectionReset.Release(); + }); var mockLoggerFactory = new Mock(); mockLoggerFactory @@ -354,7 +385,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests .Setup(factory => factory.CreateLogger(It.IsNotIn(new[] { "Microsoft.AspNetCore.Server.Kestrel" }))) .Returns(Mock.Of()); - var connectionStartedTcs = new TaskCompletionSource(); + var requestStarted = new SemaphoreSlim(0); var builder = new WebHostBuilder() .UseLoggerFactory(mockLoggerFactory.Object) @@ -362,7 +393,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests .UseUrls($"http://127.0.0.1:0") .Configure(app => app.Run(async context => { - connectionStartedTcs.SetResult(null); + requestStarted.Release(); await context.Request.Body.ReadAsync(new byte[1], 0, 1); })); @@ -376,14 +407,18 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests socket.Send(Encoding.ASCII.GetBytes("GET / HTTP/1.1\r\n\r\n")); // Wait until connection is established - await connectionStartedTcs.Task.TimeoutAfter(TimeSpan.FromSeconds(10)); + await requestStarted.WaitAsync(TimeSpan.FromSeconds(10)); // Force a reset socket.LingerState = new LingerOption(true, 0); } - } - mockLogger.Verify(logger => logger.Log(LogLevel.Debug, _connectionResetEventId, It.IsAny(), null, It.IsAny>())); + // If the reset is correctly logged as Debug, the wait below should complete shortly. + // This check MUST come before disposing the server, otherwise there's a race where the RST + // is still in flight when the connection is aborted, leading to the reset never being received + // and therefore not logged. + await connectionReset.WaitAsync(TimeSpan.FromSeconds(10)); + } } [Fact] From d6d13a0986bdd78bb412a7eda8b93035aa1877cd Mon Sep 17 00:00:00 2001 From: Pranav K Date: Sun, 12 Mar 2017 20:10:02 -0700 Subject: [PATCH 1151/1662] Remove net451 as a cross-compile target --- .gitignore | 1 + .../LargeResponseApp/LargeResponseApp.csproj | 2 +- samples/SampleApp/SampleApp.csproj | 2 +- ...oft.AspNetCore.Server.Kestrel.Https.csproj | 2 +- .../Adapter/Internal/LoggingStream.cs | 5 +- .../Adapter/Internal/RawStream.cs | 5 +- .../Internal/Http/Frame.cs | 4 -- .../Internal/Http/FrameDuplexStream.cs | 43 ++++++++-------- .../Internal/Http/FrameRequestStream.cs | 11 ++-- .../Internal/Http/FrameResponseStream.cs | 9 ++-- .../Internal/Http/SocketOutput.cs | 2 +- .../Internal/Infrastructure/TaskUtilities.cs | 50 ------------------- ...Microsoft.AspNetCore.Server.Kestrel.csproj | 2 +- ...Core.Server.Kestrel.FunctionalTests.csproj | 2 + .../FrameRequestStreamTests.cs | 3 ++ .../FrameResponseStreamTests.cs | 3 ++ .../NetworkingTests.cs | 30 ----------- test/shared/TestResources.cs | 4 +- 18 files changed, 59 insertions(+), 121 deletions(-) delete mode 100644 src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/TaskUtilities.cs diff --git a/.gitignore b/.gitignore index d685f8ca52..e38451336c 100644 --- a/.gitignore +++ b/.gitignore @@ -34,3 +34,4 @@ launchSettings.json BenchmarkDotNet.Artifacts/ BDN.Generated/ binaries/ +global.json diff --git a/samples/LargeResponseApp/LargeResponseApp.csproj b/samples/LargeResponseApp/LargeResponseApp.csproj index 9feeea1d07..06e37972b7 100644 --- a/samples/LargeResponseApp/LargeResponseApp.csproj +++ b/samples/LargeResponseApp/LargeResponseApp.csproj @@ -3,7 +3,7 @@ - net451;netcoreapp1.1 + net46;netcoreapp1.1 false diff --git a/samples/SampleApp/SampleApp.csproj b/samples/SampleApp/SampleApp.csproj index fa311e28dc..1c71f51d36 100644 --- a/samples/SampleApp/SampleApp.csproj +++ b/samples/SampleApp/SampleApp.csproj @@ -3,7 +3,7 @@ - netcoreapp1.1;net451 + netcoreapp1.1;net46 false diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Https/Microsoft.AspNetCore.Server.Kestrel.Https.csproj b/src/Microsoft.AspNetCore.Server.Kestrel.Https/Microsoft.AspNetCore.Server.Kestrel.Https.csproj index 5187bdb18d..2e425cd7e4 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Https/Microsoft.AspNetCore.Server.Kestrel.Https.csproj +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Https/Microsoft.AspNetCore.Server.Kestrel.Https.csproj @@ -4,7 +4,7 @@ HTTPS support for the ASP.NET Core Kestrel cross-platform web server. - net451;netstandard1.3 + netstandard1.3;net46 true aspnetcore;kestrel CS1591;$(NoWarn) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Adapter/Internal/LoggingStream.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Adapter/Internal/LoggingStream.cs index 5421093a63..24fa1edb08 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Adapter/Internal/LoggingStream.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Adapter/Internal/LoggingStream.cs @@ -132,7 +132,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Adapter.Internal _logger.LogDebug(builder.ToString()); } -#if NET451 +#if NET46 // The below APM methods call the underlying Read/WriteAsync methods which will still be logged. public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback callback, object state) { @@ -209,6 +209,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Adapter.Internal }, tcs, cancellationToken); return tcs.Task; } +#elif NETSTANDARD1_3 +#else +#error target frameworks need to be updated. #endif } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Adapter/Internal/RawStream.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Adapter/Internal/RawStream.cs index 5cc97ee3e8..7433d5eb78 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Adapter/Internal/RawStream.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Adapter/Internal/RawStream.cs @@ -135,7 +135,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Adapter.Internal } } -#if NET451 +#if NET46 public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback callback, object state) { var task = ReadAsync(buffer, offset, count, default(CancellationToken), state); @@ -211,6 +211,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Adapter.Internal }, tcs, cancellationToken); return tcs.Task; } +#elif NETSTANDARD1_3 +#else +#error target frameworks need to be updated. #endif } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs index d900924e41..bdaae0f445 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs @@ -1382,14 +1382,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { // .NET 451 doesn't have pointer overloads for Encoding.GetString so we // copy to an array -#if NET451 - return Encoding.UTF8.GetString(path.ToArray()); -#else fixed (byte* pointer = &path.DangerousGetPinnableReference()) { return Encoding.UTF8.GetString(pointer, path.Length); } -#endif } public void OnHeader(Span name, Span value) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameDuplexStream.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameDuplexStream.cs index 7ec8b9a9bf..10469dc05d 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameDuplexStream.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameDuplexStream.cs @@ -1,7 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -#if NET451 +#if NET46 using System; #endif using System.IO; @@ -97,14 +97,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } } -#if NET451 - public override void Close() - { - _requestStream.Close(); - _responseStream.Close(); - } -#endif - protected override void Dispose(bool disposing) { if (disposing) @@ -124,7 +116,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http return _responseStream.FlushAsync(cancellationToken); } -#if NET451 +#if NET46 + public override void Close() + { + _requestStream.Close(); + _responseStream.Close(); + } + public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback callback, object state) { return _requestStream.BeginRead(buffer, offset, count, callback, state); @@ -134,6 +132,19 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { return _requestStream.EndRead(asyncResult); } + + public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback callback, object state) + { + return _responseStream.BeginWrite(buffer, offset, count, callback, state); + } + + public override void EndWrite(IAsyncResult asyncResult) + { + _responseStream.EndWrite(asyncResult); + } +#elif NETSTANDARD1_3 +#else +#error target frameworks need to be updated. #endif public override Task ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) @@ -146,18 +157,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http return _requestStream.CopyToAsync(destination, bufferSize, cancellationToken); } -#if NET451 - public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback callback, object state) - { - return _responseStream.BeginWrite(buffer, offset, count, callback, state); - } - - public override void EndWrite(IAsyncResult asyncResult) - { - _responseStream.EndWrite(asyncResult); - } -#endif - public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) { return _responseStream.WriteAsync(buffer, offset, count, cancellationToken); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameRequestStream.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameRequestStream.cs index b75effe5e8..a7b168a73d 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameRequestStream.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameRequestStream.cs @@ -74,7 +74,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http return ReadAsync(buffer, offset, count).Result; } -#if NET451 +#if NET46 public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback callback, object state) { var task = ReadAsync(buffer, offset, count, default(CancellationToken), state); @@ -112,6 +112,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http }, tcs, cancellationToken); return tcs.Task; } +#elif NETSTANDARD1_3 +#else +#error target frameworks need to be updated #endif public override Task ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) @@ -198,15 +201,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http case FrameStreamState.Open: if (cancellationToken.IsCancellationRequested) { - return TaskUtilities.GetCancelledZeroTask(cancellationToken); + return Task.FromCanceled(cancellationToken); } break; case FrameStreamState.Closed: throw new ObjectDisposedException(nameof(FrameRequestStream)); case FrameStreamState.Aborted: return _error != null ? - TaskUtilities.GetFaultedTask(_error) : - TaskUtilities.GetCancelledZeroTask(); + Task.FromException(_error) : + Task.FromCanceled(new CancellationToken(true)); } return null; } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameResponseStream.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameResponseStream.cs index 5a3c9159d5..e654a3d7e4 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameResponseStream.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameResponseStream.cs @@ -85,7 +85,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _frameControl.Write(new ArraySegment(buffer, offset, count)); } -#if NET451 +#if NET46 public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback callback, object state) { var task = WriteAsync(buffer, offset, count, default(CancellationToken), state); @@ -123,6 +123,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http }, tcs, cancellationToken); return tcs.Task; } +#elif NETSTANDARD1_3 +#else +#error target frameworks need to be updated. #endif public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) @@ -180,7 +183,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http case FrameStreamState.Open: if (cancellationToken.IsCancellationRequested) { - return TaskUtilities.GetCancelledTask(cancellationToken); + return Task.FromCanceled(cancellationToken); } break; case FrameStreamState.Closed: @@ -189,7 +192,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if (cancellationToken.IsCancellationRequested) { // Aborted state only throws on write if cancellationToken requests it - return TaskUtilities.GetCancelledTask(cancellationToken); + return Task.FromCanceled(cancellationToken); } break; } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/SocketOutput.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/SocketOutput.cs index fde232f36e..6f8148932c 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/SocketOutput.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/SocketOutput.cs @@ -166,7 +166,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { _connection.AbortAsync(); _cancelled = true; - return TaskUtilities.GetCancelledTask(cancellationToken); + return Task.FromCanceled(cancellationToken); } else if (_cancelled) { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/TaskUtilities.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/TaskUtilities.cs deleted file mode 100644 index 6ee8e895df..0000000000 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/TaskUtilities.cs +++ /dev/null @@ -1,50 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using System.Threading; -using System.Threading.Tasks; - -namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure -{ - public static class TaskUtilities - { - public static Task GetCancelledTask(CancellationToken cancellationToken) - { -#if NETSTANDARD1_3 - return Task.FromCanceled(cancellationToken); -#else - var tcs = new TaskCompletionSource(); - tcs.TrySetCanceled(); - return tcs.Task; -#endif - } - - public static Task GetCancelledZeroTask(CancellationToken cancellationToken = default(CancellationToken)) - { -#if NETSTANDARD1_3 - // Make sure cancellationToken is canceled before passing to Task.FromCanceled - if (!cancellationToken.IsCancellationRequested) - { - cancellationToken = new CancellationToken(true); - } - return Task.FromCanceled(cancellationToken); -#else - var tcs = new TaskCompletionSource(); - tcs.TrySetCanceled(); - return tcs.Task; -#endif - } - - public static Task GetFaultedTask(Exception error) - { -#if NETSTANDARD1_3 - return Task.FromException(error); -#else - var tcs = new TaskCompletionSource(); - tcs.SetException(error); - return tcs.Task; -#endif - } - } -} \ No newline at end of file diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Microsoft.AspNetCore.Server.Kestrel.csproj b/src/Microsoft.AspNetCore.Server.Kestrel/Microsoft.AspNetCore.Server.Kestrel.csproj index 73ba4a6cd3..796b8296c6 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Microsoft.AspNetCore.Server.Kestrel.csproj +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Microsoft.AspNetCore.Server.Kestrel.csproj @@ -4,7 +4,7 @@ ASP.NET Core Kestrel cross-platform web server. - net451;netstandard1.3 + netstandard1.3;net46 true aspnetcore;kestrel true diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests.csproj b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests.csproj index 9615b4a06d..81666785c9 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests.csproj +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests.csproj @@ -6,6 +6,8 @@ netcoreapp1.1;net46 netcoreapp1.1 x64 + true + true diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameRequestStreamTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameRequestStreamTests.cs index 32f3e37d73..47ce60b35a 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameRequestStreamTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameRequestStreamTests.cs @@ -90,6 +90,9 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var stream = new FrameRequestStream(); Assert.Throws(() => stream.BeginWrite(new byte[1], 0, 1, null, null)); } +#elif NETCOREAPP1_1 +#else +#error target frameworks need to be updated #endif [Fact] diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameResponseStreamTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameResponseStreamTests.cs index b1f155ad52..363eb26d30 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameResponseStreamTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameResponseStreamTests.cs @@ -61,6 +61,9 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var stream = new FrameResponseStream(new MockFrameControl()); Assert.Throws(() => stream.BeginRead(new byte[1], 0, 1, null, null)); } +#elif NETCOREAPP1_1 +#else +#error target frameworks need to be updated #endif [Fact] diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/NetworkingTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/NetworkingTests.cs index c417007e2c..2cf84068c4 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/NetworkingTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/NetworkingTests.cs @@ -131,18 +131,8 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var t = Task.Run(async () => { var socket = TestConnection.CreateConnectedLoopbackSocket(port); -#if NET46 - await Task.Factory.FromAsync( - socket.BeginSend, - socket.EndSend, - new[] { new ArraySegment(new byte[] { 1, 2, 3, 4, 5 }) }, - SocketFlags.None, - null, - TaskCreationOptions.None); -#else await socket.SendAsync(new[] { new ArraySegment(new byte[] { 1, 2, 3, 4, 5 }) }, SocketFlags.None); -#endif socket.Dispose(); }); loop.Run(); @@ -194,33 +184,13 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var t = Task.Run(async () => { var socket = TestConnection.CreateConnectedLoopbackSocket(port); -#if NET46 - await Task.Factory.FromAsync( - socket.BeginSend, - socket.EndSend, - new[] { new ArraySegment(new byte[] { 1, 2, 3, 4, 5 }) }, - SocketFlags.None, - null, - TaskCreationOptions.None); -#else await socket.SendAsync(new[] { new ArraySegment(new byte[] { 1, 2, 3, 4, 5 }) }, SocketFlags.None); -#endif socket.Shutdown(SocketShutdown.Send); var buffer = new ArraySegment(new byte[2048]); while (true) { -#if NET46 - var count = await Task.Factory.FromAsync( - socket.BeginReceive, - socket.EndReceive, - new[] { buffer }, - SocketFlags.None, - null, - TaskCreationOptions.None); -#else var count = await socket.ReceiveAsync(new[] { buffer }, SocketFlags.None); -#endif if (count <= 0) break; } socket.Dispose(); diff --git a/test/shared/TestResources.cs b/test/shared/TestResources.cs index ff0b12b050..37b2443622 100644 --- a/test/shared/TestResources.cs +++ b/test/shared/TestResources.cs @@ -11,8 +11,10 @@ namespace Microsoft.AspNetCore.Testing private static readonly string _testCertificatePath = #if NET46 Path.Combine(Directory.GetCurrentDirectory(), "testCert.pfx"); -#else +#elif NETCOREAPP1_1 Path.Combine(AppContext.BaseDirectory, "testCert.pfx"); +#else +#error Target frameworks need to be updated. #endif public static string TestCertificatePath => _testCertificatePath; From 0f28c49c5ec7d52ff1439bff3665814b8183eada Mon Sep 17 00:00:00 2001 From: David Fowler Date: Fri, 24 Mar 2017 11:06:16 -0700 Subject: [PATCH 1152/1662] Fix the invalid usages of Span (#1549) --- .../HttpParserTests.cs | 146 +++++++++--------- .../HttpUtilitiesTest.cs | 6 +- 2 files changed, 78 insertions(+), 74 deletions(-) diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/HttpParserTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/HttpParserTests.cs index 41b5af4a55..0f269514ba 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/HttpParserTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/HttpParserTests.cs @@ -32,39 +32,15 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { var parser = CreateParser(Mock.Of()); var buffer = ReadableBuffer.Create(Encoding.ASCII.GetBytes(requestLine)); + var requestHandler = new RequestHandler(); - string parsedMethod = null; - string parsedVersion = null; - string parsedRawTarget = null; - string parsedRawPath = null; - string parsedQuery = null; - var requestLineHandler = new Mock(); - requestLineHandler - .Setup(handler => handler.OnStartLine( - It.IsAny(), - It.IsAny(), - It.IsAny>(), - It.IsAny>(), - It.IsAny>(), - It.IsAny>(), - It.IsAny())) - .Callback, Span, Span, Span, bool>((method, version, target, path, query, customMethod, pathEncoded) => - { - parsedMethod = method != HttpMethod.Custom ? HttpUtilities.MethodToString(method) : customMethod.GetAsciiStringNonNullCharacters(); - parsedVersion = HttpUtilities.VersionToString(version); - parsedRawTarget = target.GetAsciiStringNonNullCharacters(); - parsedRawPath = path.GetAsciiStringNonNullCharacters(); - parsedQuery = query.GetAsciiStringNonNullCharacters(); - pathEncoded = false; - }); + Assert.True(parser.ParseRequestLine(requestHandler, buffer, out var consumed, out var examined)); - Assert.True(parser.ParseRequestLine(requestLineHandler.Object, buffer, out var consumed, out var examined)); - - Assert.Equal(parsedMethod, expectedMethod); - Assert.Equal(parsedVersion, expectedVersion); - Assert.Equal(parsedRawTarget, expectedRawTarget); - Assert.Equal(parsedRawPath, expectedRawPath); - Assert.Equal(parsedVersion, expectedVersion); + Assert.Equal(requestHandler.Method, expectedMethod); + Assert.Equal(requestHandler.Version, expectedVersion); + Assert.Equal(requestHandler.RawTarget, expectedRawTarget); + Assert.Equal(requestHandler.RawPath, expectedRawPath); + Assert.Equal(requestHandler.Version, expectedVersion); Assert.Equal(buffer.End, consumed); Assert.Equal(buffer.End, examined); } @@ -75,8 +51,9 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { var parser = CreateParser(Mock.Of()); var buffer = ReadableBuffer.Create(Encoding.ASCII.GetBytes(requestLine)); + var requestHandler = new RequestHandler(); - Assert.False(parser.ParseRequestLine(Mock.Of(), buffer, out var consumed, out var examined)); + Assert.False(parser.ParseRequestLine(requestHandler, buffer, out var consumed, out var examined)); } [Theory] @@ -85,8 +62,9 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { var parser = CreateParser(Mock.Of()); var buffer = ReadableBuffer.Create(Encoding.ASCII.GetBytes(requestLine)); + var requestHandler = new RequestHandler(); - Assert.False(parser.ParseRequestLine(Mock.Of(), buffer, out var consumed, out var examined)); + Assert.False(parser.ParseRequestLine(requestHandler, buffer, out var consumed, out var examined)); Assert.Equal(buffer.Start, consumed); Assert.Equal(buffer.End, examined); @@ -103,9 +81,10 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var parser = CreateParser(mockTrace.Object); var buffer = ReadableBuffer.Create(Encoding.ASCII.GetBytes(requestLine)); + var requestHandler = new RequestHandler(); var exception = Assert.Throws(() => - parser.ParseRequestLine(Mock.Of(), buffer, out var consumed, out var examined)); + parser.ParseRequestLine(requestHandler, buffer, out var consumed, out var examined)); Assert.Equal($"Invalid request line: '{requestLine.EscapeNonPrintable()}'", exception.Message); Assert.Equal(StatusCodes.Status400BadRequest, (exception as BadHttpRequestException).StatusCode); @@ -124,9 +103,10 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var parser = CreateParser(mockTrace.Object); var buffer = ReadableBuffer.Create(Encoding.ASCII.GetBytes(requestLine)); + var requestHandler = new RequestHandler(); var exception = Assert.Throws(() => - parser.ParseRequestLine(Mock.Of(), buffer, out var consumed, out var examined)); + parser.ParseRequestLine(requestHandler, buffer, out var consumed, out var examined)); Assert.Equal($"Invalid request line: '{method.EscapeNonPrintable()} / HTTP/1.1\\x0D\\x0A'", exception.Message); Assert.Equal(StatusCodes.Status400BadRequest, (exception as BadHttpRequestException).StatusCode); @@ -145,9 +125,10 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var parser = CreateParser(mockTrace.Object); var buffer = ReadableBuffer.Create(Encoding.ASCII.GetBytes(requestLine)); + var requestHandler = new RequestHandler(); var exception = Assert.Throws(() => - parser.ParseRequestLine(Mock.Of(), buffer, out var consumed, out var examined)); + parser.ParseRequestLine(requestHandler, buffer, out var consumed, out var examined)); Assert.Equal($"Unrecognized HTTP version: '{httpVersion}'", exception.Message); Assert.Equal(StatusCodes.Status505HttpVersionNotsupported, (exception as BadHttpRequestException).StatusCode); @@ -195,7 +176,8 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var parser = CreateParser(Mock.Of()); var buffer = ReadableBuffer.Create(Encoding.ASCII.GetBytes(rawHeaders)); - Assert.False(parser.ParseHeaders(Mock.Of(), buffer, out var consumed, out var examined, out var consumedBytes)); + var requestHandler = new RequestHandler(); + Assert.False(parser.ParseHeaders(requestHandler, buffer, out var consumed, out var examined, out var consumedBytes)); } [Theory] @@ -219,7 +201,8 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var parser = CreateParser(Mock.Of()); var buffer = ReadableBuffer.Create(Encoding.ASCII.GetBytes(rawHeaders)); - parser.ParseHeaders(Mock.Of(), buffer, out var consumed, out var examined, out var consumedBytes); + var requestHandler = new RequestHandler(); + parser.ParseHeaders(requestHandler, buffer, out var consumed, out var examined, out var consumedBytes); Assert.Equal(buffer.Start, consumed); Assert.Equal(buffer.End, examined); @@ -308,14 +291,15 @@ namespace Microsoft.AspNetCore.Server.KestrelTests const string headerLine = "Header: value\r\n\r"; var buffer1 = ReadableBuffer.Create(Encoding.ASCII.GetBytes(headerLine)); - Assert.False(parser.ParseHeaders(Mock.Of(), buffer1, out var consumed, out var examined, out var consumedBytes)); + var requestHandler = new RequestHandler(); + Assert.False(parser.ParseHeaders(requestHandler, buffer1, out var consumed, out var examined, out var consumedBytes)); Assert.Equal(buffer1.Move(buffer1.Start, headerLine.Length - 1), consumed); Assert.Equal(buffer1.End, examined); Assert.Equal(headerLine.Length - 1, consumedBytes); var buffer2 = ReadableBuffer.Create(Encoding.ASCII.GetBytes("\r\n")); - Assert.True(parser.ParseHeaders(Mock.Of(), buffer2, out consumed, out examined, out consumedBytes)); + Assert.True(parser.ParseHeaders(requestHandler, buffer2, out consumed, out examined, out consumedBytes)); Assert.Equal(buffer2.End, consumed); Assert.Equal(buffer2.End, examined); @@ -333,9 +317,10 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var parser = CreateParser(mockTrace.Object); var buffer = ReadableBuffer.Create(Encoding.ASCII.GetBytes(rawHeaders)); + var requestHandler = new RequestHandler(); var exception = Assert.Throws(() => - parser.ParseHeaders(Mock.Of(), buffer, out var consumed, out var examined, out var consumedBytes)); + parser.ParseHeaders(requestHandler, buffer, out var consumed, out var examined, out var consumedBytes)); Assert.Equal(expectedExceptionMessage, exception.Message); Assert.Equal(StatusCodes.Status400BadRequest, exception.StatusCode); @@ -353,9 +338,10 @@ namespace Microsoft.AspNetCore.Server.KestrelTests // Invalid request line var buffer = ReadableBuffer.Create(Encoding.ASCII.GetBytes("GET % HTTP/1.1\r\n")); + var requestHandler = new RequestHandler(); var exception = Assert.Throws(() => - parser.ParseRequestLine(Mock.Of(), buffer, out var consumed, out var examined)); + parser.ParseRequestLine(requestHandler, buffer, out var consumed, out var examined)); Assert.Equal("Invalid request line: ''", exception.Message); Assert.Equal(StatusCodes.Status400BadRequest, (exception as BadHttpRequestException).StatusCode); @@ -364,7 +350,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests buffer = ReadableBuffer.Create(Encoding.ASCII.GetBytes("GET / HTTP/1.2\r\n")); exception = Assert.Throws(() => - parser.ParseRequestLine(Mock.Of(), buffer, out var consumed, out var examined)); + parser.ParseRequestLine(requestHandler, buffer, out var consumed, out var examined)); Assert.Equal("Unrecognized HTTP version: ''", exception.Message); Assert.Equal(StatusCodes.Status505HttpVersionNotsupported, (exception as BadHttpRequestException).StatusCode); @@ -373,7 +359,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests buffer = ReadableBuffer.Create(Encoding.ASCII.GetBytes("Header: value\n\r\n")); exception = Assert.Throws(() => - parser.ParseHeaders(Mock.Of(), buffer, out var consumed, out var examined, out var consumedBytes)); + parser.ParseHeaders(requestHandler, buffer, out var consumed, out var examined, out var consumedBytes)); Assert.Equal("Invalid request header: ''", exception.Message); Assert.Equal(StatusCodes.Status400BadRequest, exception.StatusCode); @@ -387,21 +373,13 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var parser = CreateParser(Mock.Of()); var buffer = ReadableBuffer.Create(Encoding.ASCII.GetBytes($"{headerName}:{rawHeaderValue}\r\n")); - string parsedHeaderName = "unexpected"; - string parsedHeaderValue = "unexpected"; - var headersHandler = new Mock(); - headersHandler - .Setup(handler => handler.OnHeader(It.IsAny>(), It.IsAny>())) - .Callback, Span>((name, value) => - { - parsedHeaderName = name.GetAsciiStringNonNullCharacters(); - parsedHeaderValue = value.GetAsciiStringNonNullCharacters(); - }); + var requestHandler = new RequestHandler(); + parser.ParseHeaders(requestHandler, buffer, out var consumed, out var examined, out var consumedBytes); - parser.ParseHeaders(headersHandler.Object, buffer, out var consumed, out var examined, out var consumedBytes); - - Assert.Equal(headerName, parsedHeaderName); - Assert.Equal(expectedHeaderValue, parsedHeaderValue); + var pairs = requestHandler.Headers.ToArray(); + Assert.Equal(1, pairs.Length); + Assert.Equal(headerName, pairs[0].Key); + Assert.Equal(expectedHeaderValue, pairs[0].Value); Assert.Equal(buffer.End, consumed); Assert.Equal(buffer.End, examined); } @@ -413,20 +391,14 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var parser = CreateParser(Mock.Of()); var buffer = ReadableBuffer.Create(Encoding.ASCII.GetBytes(rawHeaders)); - var parsedHeaders = new List>(); - var headersHandler = new Mock(); - headersHandler - .Setup(handler => handler.OnHeader(It.IsAny>(), It.IsAny>())) - .Callback, Span>((name, value) => - { - parsedHeaders.Add(Tuple.Create(name.GetAsciiStringNonNullCharacters(), value.GetAsciiStringNonNullCharacters())); - }); + var requestHandler = new RequestHandler(); + parser.ParseHeaders(requestHandler, buffer, out var consumed, out var examined, out var consumedBytes); - parser.ParseHeaders(headersHandler.Object, buffer, out var consumed, out var examined, out var consumedBytes); + var parsedHeaders = requestHandler.Headers.ToArray(); - Assert.Equal(expectedHeaderNames.Count(), parsedHeaders.Count); - Assert.Equal(expectedHeaderNames, parsedHeaders.Select(t => t.Item1)); - Assert.Equal(expectedHeaderValues, parsedHeaders.Select(t => t.Item2)); + Assert.Equal(expectedHeaderNames.Count(), parsedHeaders.Length); + Assert.Equal(expectedHeaderNames, parsedHeaders.Select(t => t.Key)); + Assert.Equal(expectedHeaderValues, parsedHeaders.Select(t => t.Value)); Assert.Equal(buffer.End, consumed); Assert.Equal(buffer.End, examined); } @@ -444,5 +416,37 @@ namespace Microsoft.AspNetCore.Server.KestrelTests public static TheoryData UnrecognizedHttpVersionData => HttpParsingData.UnrecognizedHttpVersionData; public static IEnumerable RequestHeaderInvalidData => HttpParsingData.RequestHeaderInvalidData; + + private class RequestHandler : IHttpRequestLineHandler, IHttpHeadersHandler + { + public string Method { get; set; } + + public string Version { get; set; } + + public string RawTarget { get; set; } + + public string RawPath { get; set; } + + public string Query { get; set; } + + public bool PathEncoded { get; set; } + + public Dictionary Headers { get; } = new Dictionary(); + + public void OnHeader(Span name, Span value) + { + Headers[name.GetAsciiStringNonNullCharacters()] = value.GetAsciiStringNonNullCharacters(); + } + + public void OnStartLine(HttpMethod method, HttpVersion version, Span target, Span path, Span query, Span customMethod, bool pathEncoded) + { + Method = method != HttpMethod.Custom ? HttpUtilities.MethodToString(method) : customMethod.GetAsciiStringNonNullCharacters(); + Version = HttpUtilities.VersionToString(version); + RawTarget = target.GetAsciiStringNonNullCharacters(); + RawPath = path.GetAsciiStringNonNullCharacters(); + Query = query.GetAsciiStringNonNullCharacters(); + PathEncoded = pathEncoded; + } + } } -} +} \ No newline at end of file diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/HttpUtilitiesTest.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/HttpUtilitiesTest.cs index 18b7a111c9..e21ce86eff 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/HttpUtilitiesTest.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/HttpUtilitiesTest.cs @@ -120,11 +120,11 @@ namespace Microsoft.AspNetCore.Server.KestrelTests }); } - private void TestKnownStringsInterning(string input, string expected, Func, string> action) + private void TestKnownStringsInterning(string input, string expected, Func action) { // Act - var knownString1 = action(new Span(Encoding.ASCII.GetBytes(input))); - var knownString2 = action(new Span(Encoding.ASCII.GetBytes(input))); + var knownString1 = action(Encoding.ASCII.GetBytes(input)); + var knownString2 = action(Encoding.ASCII.GetBytes(input)); // Assert Assert.Equal(knownString1, expected); From 47f1db20e063c2da75d9d89653fad4eafe24446c Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Fri, 24 Mar 2017 16:46:40 -0700 Subject: [PATCH 1153/1662] Fix races on port acquisition in AddressRegistrationTests (#1520). --- .../AddressRegistrationTests.cs | 31 +++++-------------- 1 file changed, 8 insertions(+), 23 deletions(-) diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs index 27c5191b7d..5a605a74c6 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs @@ -505,32 +505,17 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests }); } - private static int _nextPort = 8001; - private static object _portLock = new object(); private static int GetNextPort() { - lock (_portLock) + using (var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)) { - using (var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)) - { - while (true) - { - try - { - var port = _nextPort++; - socket.Bind(new IPEndPoint(IPAddress.Loopback, port)); - return port; - } - catch (SocketException) - { - // Retry unless exhausted - if (_nextPort == 65536) - { - throw; - } - } - } - } + // Let the OS assign the next available port. Unless we cycle through all ports + // on a test run, the OS will always increment the port number when making these calls. + // This prevents races in parallel test runs where a test is already bound to + // a given port, and a new test is able to bind to the same port due to port + // reuse being enabled by default by the OS. + socket.Bind(new IPEndPoint(IPAddress.Loopback, 0)); + return ((IPEndPoint)socket.LocalEndPoint).Port; } } From db7348e776b91cdb183211ea8ea140e03936cf16 Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Mon, 27 Mar 2017 10:10:28 -0700 Subject: [PATCH 1154/1662] Fix flakiness in WhenAppWritesLessThanContentLengthButRequestIsAbortedErrorNotLogged. --- .../ResponseTests.cs | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs index b0ae4f6c3e..fad98eaeae 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs @@ -684,20 +684,21 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [Fact] public async Task WhenAppWritesLessThanContentLengthButRequestIsAbortedErrorNotLogged() { - var abortTcs = new TaskCompletionSource(); + var requestAborted = new SemaphoreSlim(0); var mockTrace = new Mock(); using (var server = new TestServer(async httpContext => { httpContext.RequestAborted.Register(() => { - abortTcs.SetResult(null); + requestAborted.Release(2); }); + httpContext.Response.ContentLength = 12; await httpContext.Response.WriteAsync("hello,"); // Wait until the request is aborted so we know Frame will skip the response content length check. - await abortTcs.Task.TimeoutAfter(TimeSpan.FromSeconds(10)); + await requestAborted.WaitAsync(TimeSpan.FromSeconds(10)); }, new TestServiceContext { Log = mockTrace.Object })) { using (var connection = server.CreateConnection()) @@ -713,12 +714,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests "", "hello,"); } - } - // Verify the request was really aborted. A timeout in the await inside - // the app func would cause a server error and skip the content length - // check altogether, making the test pass for the wrong reason. - Assert.True(abortTcs.Task.IsCompleted); + // Verify the request was really aborted. A timeout in + // the app would cause a server error and skip the content length + // check altogether, making the test pass for the wrong reason. + // Await before disposing the server to prevent races between the + // abort triggered by the connection RST and the abort called when + // disposing the server. + await requestAborted.WaitAsync(TimeSpan.FromSeconds(10)); + } // With the server disposed we know all connections were drained and all messages were logged. mockTrace.Verify(trace => trace.ApplicationError(It.IsAny(), It.IsAny()), Times.Never); From 200d8debc005bac2c15424b20c6b7bb4a50483cc Mon Sep 17 00:00:00 2001 From: Pranav K Date: Tue, 28 Mar 2017 14:27:54 -0700 Subject: [PATCH 1155/1662] Use the SDK version of GetOSPlatform --- ...Microsoft.AspNetCore.Server.Kestrel.FunctionalTests.csproj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests.csproj b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests.csproj index 81666785c9..ed0530aa99 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests.csproj +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests.csproj @@ -40,10 +40,10 @@ - + - + $(DefineConstants);$(OSPlatform.ToUpperInvariant()) From 7dd9d69fe11a0a748715ab6add8b0fe5702511a8 Mon Sep 17 00:00:00 2001 From: Pranav K Date: Wed, 29 Mar 2017 11:30:34 -0700 Subject: [PATCH 1156/1662] Updating to 2.0.0 Internal.AspNetCore.Sdk --- build/common.props | 2 +- build/dependencies.props | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/build/common.props b/build/common.props index f6342cb9d3..1021ec36b4 100644 --- a/build/common.props +++ b/build/common.props @@ -13,7 +13,7 @@ - + diff --git a/build/dependencies.props b/build/dependencies.props index cc4fbc7fdc..fec2f8c282 100644 --- a/build/dependencies.props +++ b/build/dependencies.props @@ -4,6 +4,7 @@ 0.1.0-* 0.1.0-* 4.3.0 + 2.0.0-* 1.9.1 9.0.1 4.7.1 @@ -11,4 +12,4 @@ 15.0.0 2.2.0 - + \ No newline at end of file From 792b71dbcbe2ce6bc7e0cf80ccf7556323e41745 Mon Sep 17 00:00:00 2001 From: Nate McMaster Date: Wed, 29 Mar 2017 12:18:03 -0700 Subject: [PATCH 1157/1662] Add VS Code settings (#1556) [ci skip] --- .gitignore | 3 -- .vscode/extensions.json | 8 ++++ .vscode/launch.json | 75 +++++++++++++++++++++++++++++++++++ .vscode/settings.json | 11 ++++++ .vscode/tasks.json | 87 +++++++++++++++++++++++++++++++++++++++++ 5 files changed, 181 insertions(+), 3 deletions(-) create mode 100644 .vscode/extensions.json create mode 100644 .vscode/launch.json create mode 100644 .vscode/settings.json create mode 100644 .vscode/tasks.json diff --git a/.gitignore b/.gitignore index e38451336c..f77341208e 100644 --- a/.gitignore +++ b/.gitignore @@ -8,7 +8,6 @@ packages/ artifacts/ PublishProfiles/ .vs/ -.vscode/ *.user *.suo *.cache @@ -26,8 +25,6 @@ nuget.exe *.ncrunchsolution *.*sdf *.ipch -project.lock.json -runtimes/ .build/ .testPublish/ launchSettings.json diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 0000000000..e69a4b3fda --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,8 @@ +{ + "recommendations": [ + "ms-vscode.csharp", + "EditorConfig.EditorConfig", + "k--kato.docomment", + "PeterJausovec.vscode-docker" + ] +} diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000000..e91f61ede0 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,75 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "name": "Attach: .NET Core", + "type": "coreclr", + "request": "attach", + "processId": "${command:pickProcess}" + }, + { + "name": "Debug: SampleApp", + "type": "coreclr", + "request": "launch", + "preLaunchTask": "Compile: solution", + "program": "${workspaceRoot}/samples/SampleApp/bin/Debug/netcoreapp1.1/SampleApp.dll", + "args": [], + "cwd": "${workspaceRoot}/samples/SampleApp", + "console": "internalConsole", + "stopAtEntry": false, + "internalConsoleOptions": "openOnSessionStart", + "launchBrowser": { + "enabled": true, + "args": "${auto-detect-url}", + "windows": { + "command": "cmd.exe", + "args": "/C start ${auto-detect-url}" + }, + "osx": { + "command": "open" + }, + "linux": { + "command": "xdg-open" + } + } + }, + { + "name": "Debug: LargeResponseApp", + "type": "coreclr", + "request": "launch", + "preLaunchTask": "Compile: solution", + "program": "${workspaceRoot}/samples/LargeResponseApp/bin/Debug/netcoreapp1.1/LargeResponseApp.dll", + "args": [], + "cwd": "${workspaceRoot}/samples/LargeResponseApp", + "console": "internalConsole", + "stopAtEntry": false, + "internalConsoleOptions": "openOnSessionStart", + "launchBrowser": { + "enabled": true, + "args": "${auto-detect-url}", + "windows": { + "command": "cmd.exe", + "args": "/C start ${auto-detect-url}" + }, + "osx": { + "command": "open" + }, + "linux": { + "command": "xdg-open" + } + } + }, + { + "name": "Debug: CodeGenerator", + "type": "coreclr", + "request": "launch", + "preLaunchTask": "Compile: CodeGenerator", + "program": "${workspaceRoot}/tools/CodeGenerator/bin/Debug/netcoreapp1.1/CodeGenerator.dll", + "args": [], + "cwd": "${workspaceRoot}", + "console": "internalConsole", + "stopAtEntry": true, + "internalConsoleOptions": "openOnSessionStart" + } + ] +} diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000000..2c3c5e92d1 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,11 @@ +{ + "[json]": { + "editor.tabSize": 2 + }, + "files.trimTrailingWhitespace": true, + "files.insertFinalNewline": true, + "files.associations": { + "*.props": "xml", + "*.targets": "xml" + } +} diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000000..1a78cbd21b --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,87 @@ +{ + "version": "2.0.0", + "options": { + "env": { + "DOTNET_SKIP_FIRST_TIME_EXPERIENCE": "true" + } + }, + "tasks": [ + { + "taskName": "Restore: solution", + "command": "dotnet", + "args": [ + "restore" + ] + }, + { + "taskName": "Compile: solution", + "isBuildCommand": true, + "command": "dotnet", + "args": [ + "build", + "${workspaceRoot}/KestrelHttpServer.sln" + ], + "problemMatcher": "$msCompile" + }, + { + "taskName": "Compile: CodeGenerator", + "command": "dotnet", + "args": [ + "build" + ], + "options": { + "cwd": "${workspaceRoot}/tools/CodeGenerator/" + }, + "problemMatcher": "$msCompile" + }, + { + "taskName": "Run: CodeGenerator", + "command": "dotnet", + "args": [ + "run" + ], + "options": { + "cwd": "${workspaceRoot}/tools/CodeGenerator/" + } + }, + { + "taskName": "Run: Benchmarks", + "command": "dotnet", + "args": [ + "run", + "-c", + "Release" + ], + "options": { + "cwd": "${workspaceRoot}/test/Microsoft.AspNetCore.Server.Kestrel.Performance/" + } + }, + { + "taskName": "Test: KestrelTests", + "isTestCommand": true, + "command": "dotnet", + "args": [ + "test", + "-f", + "netcoreapp1.1" + ], + "options": { + "cwd": "${workspaceRoot}/test/Microsoft.AspNetCore.Server.KestrelTests" + }, + "problemMatcher": "$msCompile" + }, + { + "taskName": "Test: FunctionalTests", + "command": "dotnet", + "args": [ + "test", + "-f", + "netcoreapp1.1" + ], + "options": { + "cwd": "${workspaceRoot}/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests" + }, + "problemMatcher": "$msCompile" + } + ] +} From 7f785588ef89c0c934cee432eb5452648ee2f3f0 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Wed, 29 Mar 2017 16:06:05 -0700 Subject: [PATCH 1158/1662] Transport agnostic kestrel refactoring (#1551) - Add transport interfaces - Create separate Core and Libuv projects #828 --- KestrelHttpServer.sln | 34 +- samples/SampleApp/SampleApp.csproj | 1 + samples/SampleApp/Startup.cs | 6 +- .../Adapter/ConnectionAdapterContext.cs | 0 .../Adapter/IAdaptedConnection.cs | 0 .../Adapter/IConnectionAdapter.cs | 1 - .../Adapter/Internal/AdaptedPipeline.cs | 24 +- .../Adapter/Internal/LoggingStream.cs | 0 .../Adapter/Internal/RawStream.cs | 1 - .../Adapter/Internal/StreamSocketOutput.cs | 2 +- ...istenOptionsConnectionLoggingExtensions.cs | 0 .../Adapter/LoggingConnectionAdapter.cs | 0 .../BadHttpRequestException.cs | 0 .../Internal/ConnectionHandler.cs | 128 + .../Internal/FrameConnection.cs | 159 + .../Internal/FrameConnectionContext.cs | 23 + .../Internal/Http/ChunkWriter.cs | 1 - .../Http/ConnectionLifetimeControl.cs | 45 + .../Internal/Http/ConnectionOptions.cs | 0 .../Internal/Http/DateHeaderValueManager.cs | 4 +- .../Internal/Http/Frame.FeatureCollection.cs | 1 - .../Internal/Http/Frame.Generated.cs | 0 .../Internal/Http/Frame.cs | 78 +- .../Internal/Http/FrameContext.cs | 14 + .../Internal/Http/FrameDuplexStream.cs | 0 .../Internal/Http/FrameHeaders.Generated.cs | 0 .../Internal/Http/FrameHeaders.cs | 0 .../Internal/Http/FrameOfT.cs | 35 +- .../Internal/Http/FrameRequestHeaders.cs | 0 .../Internal/Http/FrameRequestStream.cs | 1 - .../Internal/Http/FrameResponseHeaders.cs | 1 - .../Internal/Http/FrameResponseStream.cs | 1 - .../Internal/Http/FrameStreamState.cs | 0 .../Internal/Http/HttpMethod.cs | 0 .../Internal/Http/HttpScheme.cs | 0 .../Internal/Http/HttpVersion.cs | 0 .../Internal/Http/IFrameControl.cs | 0 .../Internal/Http/IHttpHeadersHandler.cs | 0 .../Internal/Http/IHttpParser.cs | 0 .../Internal/Http/IHttpRequestLineHandler.cs | 0 .../Internal/Http/ISocketOutput.cs | 2 +- .../Internal/Http/ITimeoutControl.cs} | 5 +- .../Internal/Http/KestrelHttpParser.cs | 1 - .../Internal/Http/MessageBody.cs | 10 +- .../Internal/Http/PathNormalizer.cs | 0 .../Internal/Http/PipelineExtensions.cs | 0 .../Internal/Http/ProduceEndType.cs | 0 .../Internal/Http/ReasonPhrases.cs | 0 .../Internal/Http/RequestProcessingStatus.cs | 0 .../Internal/Http/RequestRejectionReason.cs | 0 .../Internal/Http/SocketOutputProducer.cs} | 159 +- .../Internal/Http/TimeoutAction.cs | 0 .../Internal/Http/TransferCoding.cs | 0 .../Internal/Infrastructure/AsciiUtilities.cs | 0 .../CancellationTokenExtensions.cs | 0 .../Internal/Infrastructure/Constants.cs | 32 + .../Internal/Infrastructure/Disposable.cs | 0 .../Infrastructure/DisposableAction.cs | 0 .../Internal/Infrastructure/HttpUtilities.cs | 0 .../Internal/Infrastructure/IKestrelTrace.cs | 0 .../Internal/Infrastructure/ISystemClock.cs | 0 .../Internal/Infrastructure/IThreadPool.cs | 0 .../Infrastructure/InlineLoggingThreadPool.cs | 0 .../Internal/Infrastructure/KestrelTrace.cs | 0 .../Infrastructure/LoggingThreadPool.cs | 0 .../Internal/Infrastructure/Streams.cs | 0 .../Internal/Infrastructure/SystemClock.cs | 0 .../Internal/Infrastructure/UriUtilities.cs | 0 .../Internal/InternalKestrelServerOptions.cs | 0 .../Internal/KestrelServerOptionsSetup.cs | 0 .../Internal/ServiceContext.cs | 5 - .../KestrelServer.cs | 150 +- .../KestrelServerLimits.cs | 0 .../KestrelServerOptions.cs | 46 +- .../ListenOptions.cs | 5 +- .../ListenType.cs | 0 ...soft.AspNetCore.Server.Kestrel.Core.csproj | 32 + .../Properties/AssemblyInfo.cs | 2 - .../ServerAddress.cs | 0 .../KesterlServerOptionsSystemdExtensions.cs | 0 .../Exceptions/AddressInUseException.cs | 18 + .../Exceptions/ConnectionResetException.cs | 19 + .../Transport/IConnectionContext.cs | 21 + .../Transport/IConnectionHandler.cs | 10 + .../Transport/IConnectionInformation.cs | 23 + .../Transport/ITransport.cs | 15 + .../Transport/ITransportFactory.cs | 10 + .../ListenOptionsHttpsExtensions.cs | 1 - ...oft.AspNetCore.Server.Kestrel.Https.csproj | 3 +- .../baseline.net45.json | 292 - .../baseline.netcore.json | 292 - .../exceptions.net45.json | 14 - .../exceptions.netcore.json | 14 - .../Internal/Http/Connection.cs | 276 + .../Internal/Http/ConnectionContext.cs | 21 +- .../Internal/Http/ConnectionManager.cs | 18 +- .../Internal/Http/IAsyncDisposable.cs | 0 .../Internal/Http/Listener.cs | 6 +- .../Internal/Http/ListenerContext.cs | 45 + .../Internal/Http/ListenerPrimary.cs | 5 +- .../Internal/Http/ListenerSecondary.cs | 9 +- .../Internal/Http/SocketOutputConsumer.cs | 138 + .../Internal/Infrastructure/Constants.cs | 27 +- .../Infrastructure/KestrelEventSource.cs | 0 .../Internal/Infrastructure/KestrelThread.cs | 41 +- .../Internal/Infrastructure/LibuvAwaitable.cs | 3 +- .../Internal/Infrastructure/WriteReqPool.cs | 0 .../Internal/LibuvTransportContext.cs | 19 + .../Internal/Networking/Libuv.cs | 8 +- .../Internal/Networking/PlatformApis.cs | 0 .../Internal/Networking/SockAddr.cs | 0 .../Internal/Networking/UvAsyncHandle.cs | 6 +- .../Internal/Networking/UvConnectRequest.cs | 4 +- .../Internal/Networking/UvException.cs | 0 .../Internal/Networking/UvHandle.cs | 4 +- .../Internal/Networking/UvLoopHandle.cs | 2 +- .../Internal/Networking/UvMemory.cs | 8 +- .../Internal/Networking/UvPipeHandle.cs | 2 +- .../Internal/Networking/UvRequest.cs | 0 .../Internal/Networking/UvShutdownReq.cs | 4 +- .../Internal/Networking/UvStreamHandle.cs | 16 +- .../Internal/Networking/UvTcpHandle.cs | 3 +- .../Internal/Networking/UvTimerHandle.cs | 4 +- .../Internal/Networking/UvWriteReq.cs | 18 +- .../KestrelEngine.cs | 143 + .../LibuvTransportFactory.cs | 81 + .../LibuvTransportOptions.cs | 58 + ...Core.Server.Kestrel.Transport.Libuv.csproj | 24 + .../WebHostBuilderLibuvExtensions.cs | 50 + .../Internal/Http/Connection.cs | 432 - .../Internal/Http/IBufferSizeControl.cs | 13 - .../Internal/Http/ListenerContext.cs | 82 - .../Internal/KestrelEngine.cs | 130 - ...Microsoft.AspNetCore.Server.Kestrel.csproj | 18 +- .../WebHostBuilderKestrelExtensions.cs | 2 + .../baseline.net45.json | 12700 ---------------- .../baseline.netcore.json | 12700 ---------------- .../exceptions.net45.json | 46 - .../exceptions.netcore.json | 46 - .../BadHttpRequestTests.cs | 4 - .../GeneratedCodeTests.cs | 4 +- ...Core.Server.Kestrel.FunctionalTests.csproj | 1 + .../RequestHeaderLimitsTests.cs | 173 +- .../ResponseTests.cs | 1 - .../ThreadCountTests.cs | 3 +- .../FrameParsingOverheadBenchmark.cs | 17 +- .../FrameWritingBenchmark.cs | 23 +- .../Mocks/MockConnectionControl.cs | 17 - .../Mocks/MockConnectionInformation.cs | 38 + .../PipeThroughputBenchmark.cs | 2 - .../Program.cs | 1 - .../RequestParsingBenchmark.cs | 18 +- .../ResponseHeaderCollectionBenchmark.cs | 21 +- .../ResponseHeadersWritingBenchmark.cs | 21 +- .../.KestrelEventSourceTests.cs.swp | Bin 0 -> 12288 bytes .../AsciiDecoding.cs | 1 - .../ChunkedResponseTests.cs | 1 - .../ConnectionAdapterTests.cs | 1 - .../ConnectionTests.cs | 63 +- .../EngineTests.cs | 42 +- .../FrameResponseHeadersTests.cs | 21 +- .../FrameTests.cs | 56 +- .../KestrelEventSourceTests.cs | 4 +- .../KestrelServerOptionsTests.cs | 16 - .../KestrelServerTests.cs | 40 +- .../LibuvTransportFactoryTests.cs | 37 + .../LibuvTransportOptionsTests.cs | 28 + .../ListenerContextTests.cs | 72 - .../ListenerPrimaryTests.cs | 350 +- .../MessageBodyTests.cs | 4 +- ...soft.AspNetCore.Server.KestrelTests.csproj | 1 + .../MultipleLoopTests.cs | 16 +- .../NetworkingTests.cs | 9 +- .../PipeOptionsTests.cs | 73 + .../SocketOutputTests.cs | 413 +- .../StreamSocketOutputTests.cs | 2 - .../TestHelpers/MockConnectionHandler.cs | 66 + .../TestHelpers/MockLibuv.cs | 2 +- .../TestHelpers/MockSocket.cs | 2 +- .../TestHelpers/TestConstants.cs | 10 + .../TestInput.cs | 35 +- .../UvTimerHandleTests.cs | 4 +- .../WebHostBuilderKestrelExtensionsTests.cs | 1 - test/shared/HttpParsingData.cs | 2 +- test/shared/MockConnection.cs | 11 +- test/shared/MockSocketOutput.cs | 2 +- test/shared/PassThroughConnectionAdapter.cs | 1 - test/shared/TestFrame.cs | 2 +- test/shared/TestServer.cs | 27 +- test/shared/TestServiceContext.cs | 26 +- tools/CodeGenerator/CodeGenerator.csproj | 4 +- 191 files changed, 2575 insertions(+), 28167 deletions(-) rename src/{Microsoft.AspNetCore.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel.Core}/Adapter/ConnectionAdapterContext.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel.Core}/Adapter/IAdaptedConnection.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel.Core}/Adapter/IConnectionAdapter.cs (95%) rename src/{Microsoft.AspNetCore.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel.Core}/Adapter/Internal/AdaptedPipeline.cs (78%) rename src/{Microsoft.AspNetCore.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel.Core}/Adapter/Internal/LoggingStream.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel.Core}/Adapter/Internal/RawStream.cs (99%) rename src/{Microsoft.AspNetCore.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel.Core}/Adapter/Internal/StreamSocketOutput.cs (98%) rename src/{Microsoft.AspNetCore.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel.Core}/Adapter/ListenOptionsConnectionLoggingExtensions.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel.Core}/Adapter/LoggingConnectionAdapter.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel.Core}/BadHttpRequestException.cs (100%) create mode 100644 src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/ConnectionHandler.cs create mode 100644 src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnection.cs create mode 100644 src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnectionContext.cs rename src/{Microsoft.AspNetCore.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel.Core}/Internal/Http/ChunkWriter.cs (97%) create mode 100644 src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/ConnectionLifetimeControl.cs rename src/{Microsoft.AspNetCore.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel.Core}/Internal/Http/ConnectionOptions.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel.Core}/Internal/Http/DateHeaderValueManager.cs (97%) rename src/{Microsoft.AspNetCore.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel.Core}/Internal/Http/Frame.FeatureCollection.cs (99%) rename src/{Microsoft.AspNetCore.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel.Core}/Internal/Http/Frame.Generated.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel.Core}/Internal/Http/Frame.cs (96%) create mode 100644 src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameContext.cs rename src/{Microsoft.AspNetCore.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel.Core}/Internal/Http/FrameDuplexStream.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel.Core}/Internal/Http/FrameHeaders.Generated.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel.Core}/Internal/Http/FrameHeaders.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel.Core}/Internal/Http/FrameOfT.cs (89%) rename src/{Microsoft.AspNetCore.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel.Core}/Internal/Http/FrameRequestHeaders.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel.Core}/Internal/Http/FrameRequestStream.cs (99%) rename src/{Microsoft.AspNetCore.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel.Core}/Internal/Http/FrameResponseHeaders.cs (98%) rename src/{Microsoft.AspNetCore.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel.Core}/Internal/Http/FrameResponseStream.cs (98%) rename src/{Microsoft.AspNetCore.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel.Core}/Internal/Http/FrameStreamState.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel.Core}/Internal/Http/HttpMethod.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel.Core}/Internal/Http/HttpScheme.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel.Core}/Internal/Http/HttpVersion.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel.Core}/Internal/Http/IFrameControl.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel.Core}/Internal/Http/IHttpHeadersHandler.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel.Core}/Internal/Http/IHttpParser.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel.Core}/Internal/Http/IHttpRequestLineHandler.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel.Core}/Internal/Http/ISocketOutput.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel/Internal/Http/IConnectionControl.cs => Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/ITimeoutControl.cs} (76%) rename src/{Microsoft.AspNetCore.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel.Core}/Internal/Http/KestrelHttpParser.cs (99%) rename src/{Microsoft.AspNetCore.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel.Core}/Internal/Http/MessageBody.cs (98%) rename src/{Microsoft.AspNetCore.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel.Core}/Internal/Http/PathNormalizer.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel.Core}/Internal/Http/PipelineExtensions.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel.Core}/Internal/Http/ProduceEndType.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel.Core}/Internal/Http/ReasonPhrases.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel.Core}/Internal/Http/RequestProcessingStatus.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel.Core}/Internal/Http/RequestRejectionReason.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel/Internal/Http/SocketOutput.cs => Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/SocketOutputProducer.cs} (51%) rename src/{Microsoft.AspNetCore.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel.Core}/Internal/Http/TimeoutAction.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel.Core}/Internal/Http/TransferCoding.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel.Core}/Internal/Infrastructure/AsciiUtilities.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel.Core}/Internal/Infrastructure/CancellationTokenExtensions.cs (100%) create mode 100644 src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/Constants.cs rename src/{Microsoft.AspNetCore.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel.Core}/Internal/Infrastructure/Disposable.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel.Core}/Internal/Infrastructure/DisposableAction.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel.Core}/Internal/Infrastructure/HttpUtilities.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel.Core}/Internal/Infrastructure/IKestrelTrace.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel.Core}/Internal/Infrastructure/ISystemClock.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel.Core}/Internal/Infrastructure/IThreadPool.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel.Core}/Internal/Infrastructure/InlineLoggingThreadPool.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel.Core}/Internal/Infrastructure/KestrelTrace.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel.Core}/Internal/Infrastructure/LoggingThreadPool.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel.Core}/Internal/Infrastructure/Streams.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel.Core}/Internal/Infrastructure/SystemClock.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel.Core}/Internal/Infrastructure/UriUtilities.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel.Core}/Internal/InternalKestrelServerOptions.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel.Core}/Internal/KestrelServerOptionsSetup.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel.Core}/Internal/ServiceContext.cs (80%) rename src/{Microsoft.AspNetCore.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel.Core}/KestrelServer.cs (71%) rename src/{Microsoft.AspNetCore.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel.Core}/KestrelServerLimits.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel.Core}/KestrelServerOptions.cs (74%) rename src/{Microsoft.AspNetCore.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel.Core}/ListenOptions.cs (96%) rename src/{Microsoft.AspNetCore.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel.Core}/ListenType.cs (100%) create mode 100644 src/Microsoft.AspNetCore.Server.Kestrel.Core/Microsoft.AspNetCore.Server.Kestrel.Core.csproj rename src/{Microsoft.AspNetCore.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel.Core}/Properties/AssemblyInfo.cs (96%) rename src/{Microsoft.AspNetCore.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel.Core}/ServerAddress.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel.Core}/Systemd/KesterlServerOptionsSystemdExtensions.cs (100%) create mode 100644 src/Microsoft.AspNetCore.Server.Kestrel.Core/Transport/Exceptions/AddressInUseException.cs create mode 100644 src/Microsoft.AspNetCore.Server.Kestrel.Core/Transport/Exceptions/ConnectionResetException.cs create mode 100644 src/Microsoft.AspNetCore.Server.Kestrel.Core/Transport/IConnectionContext.cs create mode 100644 src/Microsoft.AspNetCore.Server.Kestrel.Core/Transport/IConnectionHandler.cs create mode 100644 src/Microsoft.AspNetCore.Server.Kestrel.Core/Transport/IConnectionInformation.cs create mode 100644 src/Microsoft.AspNetCore.Server.Kestrel.Core/Transport/ITransport.cs create mode 100644 src/Microsoft.AspNetCore.Server.Kestrel.Core/Transport/ITransportFactory.cs delete mode 100644 src/Microsoft.AspNetCore.Server.Kestrel.Https/baseline.net45.json delete mode 100644 src/Microsoft.AspNetCore.Server.Kestrel.Https/baseline.netcore.json delete mode 100644 src/Microsoft.AspNetCore.Server.Kestrel.Https/exceptions.net45.json delete mode 100644 src/Microsoft.AspNetCore.Server.Kestrel.Https/exceptions.netcore.json create mode 100644 src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Http/Connection.cs rename src/{Microsoft.AspNetCore.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv}/Internal/Http/ConnectionContext.cs (56%) rename src/{Microsoft.AspNetCore.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv}/Internal/Http/ConnectionManager.cs (87%) rename src/{Microsoft.AspNetCore.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv}/Internal/Http/IAsyncDisposable.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv}/Internal/Http/Listener.cs (96%) create mode 100644 src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Http/ListenerContext.cs rename src/{Microsoft.AspNetCore.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv}/Internal/Http/ListenerPrimary.cs (97%) rename src/{Microsoft.AspNetCore.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv}/Internal/Http/ListenerSecondary.cs (95%) create mode 100644 src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Http/SocketOutputConsumer.cs rename src/{Microsoft.AspNetCore.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv}/Internal/Infrastructure/Constants.cs (59%) rename src/{Microsoft.AspNetCore.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv}/Internal/Infrastructure/KestrelEventSource.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv}/Internal/Infrastructure/KestrelThread.cs (91%) rename src/{Microsoft.AspNetCore.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv}/Internal/Infrastructure/LibuvAwaitable.cs (99%) rename src/{Microsoft.AspNetCore.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv}/Internal/Infrastructure/WriteReqPool.cs (100%) create mode 100644 src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvTransportContext.cs rename src/{Microsoft.AspNetCore.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv}/Internal/Networking/Libuv.cs (99%) rename src/{Microsoft.AspNetCore.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv}/Internal/Networking/PlatformApis.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv}/Internal/Networking/SockAddr.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv}/Internal/Networking/UvAsyncHandle.cs (88%) rename src/{Microsoft.AspNetCore.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv}/Internal/Networking/UvConnectRequest.cs (90%) rename src/{Microsoft.AspNetCore.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv}/Internal/Networking/UvException.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv}/Internal/Networking/UvHandle.cs (93%) rename src/{Microsoft.AspNetCore.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv}/Internal/Networking/UvLoopHandle.cs (96%) rename src/{Microsoft.AspNetCore.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv}/Internal/Networking/UvMemory.cs (91%) rename src/{Microsoft.AspNetCore.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv}/Internal/Networking/UvPipeHandle.cs (90%) rename src/{Microsoft.AspNetCore.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv}/Internal/Networking/UvRequest.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv}/Internal/Networking/UvShutdownReq.cs (88%) rename src/{Microsoft.AspNetCore.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv}/Internal/Networking/UvStreamHandle.cs (86%) rename src/{Microsoft.AspNetCore.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv}/Internal/Networking/UvTcpHandle.cs (95%) rename src/{Microsoft.AspNetCore.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv}/Internal/Networking/UvTimerHandle.cs (90%) rename src/{Microsoft.AspNetCore.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv}/Internal/Networking/UvWriteReq.cs (91%) create mode 100644 src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/KestrelEngine.cs create mode 100644 src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/LibuvTransportFactory.cs create mode 100644 src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/LibuvTransportOptions.cs create mode 100644 src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.csproj create mode 100644 src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/WebHostBuilderLibuvExtensions.cs delete mode 100644 src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Connection.cs delete mode 100644 src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/IBufferSizeControl.cs delete mode 100644 src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ListenerContext.cs delete mode 100644 src/Microsoft.AspNetCore.Server.Kestrel/Internal/KestrelEngine.cs delete mode 100644 src/Microsoft.AspNetCore.Server.Kestrel/baseline.net45.json delete mode 100644 src/Microsoft.AspNetCore.Server.Kestrel/baseline.netcore.json delete mode 100644 src/Microsoft.AspNetCore.Server.Kestrel/exceptions.net45.json delete mode 100644 src/Microsoft.AspNetCore.Server.Kestrel/exceptions.netcore.json delete mode 100644 test/Microsoft.AspNetCore.Server.Kestrel.Performance/Mocks/MockConnectionControl.cs create mode 100644 test/Microsoft.AspNetCore.Server.Kestrel.Performance/Mocks/MockConnectionInformation.cs create mode 100644 test/Microsoft.AspNetCore.Server.KestrelTests/.KestrelEventSourceTests.cs.swp create mode 100644 test/Microsoft.AspNetCore.Server.KestrelTests/LibuvTransportFactoryTests.cs create mode 100644 test/Microsoft.AspNetCore.Server.KestrelTests/LibuvTransportOptionsTests.cs delete mode 100644 test/Microsoft.AspNetCore.Server.KestrelTests/ListenerContextTests.cs create mode 100644 test/Microsoft.AspNetCore.Server.KestrelTests/PipeOptionsTests.cs create mode 100644 test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockConnectionHandler.cs create mode 100644 test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/TestConstants.cs diff --git a/KestrelHttpServer.sln b/KestrelHttpServer.sln index 1df13131ef..24a8e79020 100644 --- a/KestrelHttpServer.sln +++ b/KestrelHttpServer.sln @@ -1,6 +1,6 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 15 -VisualStudioVersion = 15.0.26228.4 +VisualStudioVersion = 15.0.26228.9 MinimumVisualStudioVersion = 10.0.40219.1 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{7972A5D6-3385-4127-9277-428506DD44FF}" ProjectSection(SolutionItems) = preProject @@ -40,7 +40,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "shared", "shared", "{0EF2AC test\shared\TestServiceContext.cs = test\shared\TestServiceContext.cs EndProjectSection EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Server.Kestrel", "src\Microsoft.AspNetCore.Server.Kestrel\Microsoft.AspNetCore.Server.Kestrel.csproj", "{F510611A-3BEE-4B88-A613-5F4A74ED82A1}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Server.Kestrel.Core", "src\Microsoft.AspNetCore.Server.Kestrel.Core\Microsoft.AspNetCore.Server.Kestrel.Core.csproj", "{F510611A-3BEE-4B88-A613-5F4A74ED82A1}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Server.KestrelTests", "test\Microsoft.AspNetCore.Server.KestrelTests\Microsoft.AspNetCore.Server.KestrelTests.csproj", "{37F3BFB2-6454-49E5-9D7F-581BF755CCFE}" EndProject @@ -61,6 +61,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "TestResources", "TestResour test\shared\TestResources\testCert.pfx = test\shared\TestResources\testCert.pfx EndProjectSection EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv", "src\Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv\Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.csproj", "{A76B8C8C-0DC5-4DD3-9B1F-02E51A0915F4}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Server.Kestrel", "src\Microsoft.AspNetCore.Server.Kestrel\Microsoft.AspNetCore.Server.Kestrel.csproj", "{56139957-5C29-4E7D-89BD-7D20598B4EAF}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -167,6 +171,30 @@ Global {EBFE9719-A44B-4978-A71F-D5C254E7F35A}.Release|x64.Build.0 = Release|Any CPU {EBFE9719-A44B-4978-A71F-D5C254E7F35A}.Release|x86.ActiveCfg = Release|Any CPU {EBFE9719-A44B-4978-A71F-D5C254E7F35A}.Release|x86.Build.0 = Release|Any CPU + {A76B8C8C-0DC5-4DD3-9B1F-02E51A0915F4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A76B8C8C-0DC5-4DD3-9B1F-02E51A0915F4}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A76B8C8C-0DC5-4DD3-9B1F-02E51A0915F4}.Debug|x64.ActiveCfg = Debug|Any CPU + {A76B8C8C-0DC5-4DD3-9B1F-02E51A0915F4}.Debug|x64.Build.0 = Debug|Any CPU + {A76B8C8C-0DC5-4DD3-9B1F-02E51A0915F4}.Debug|x86.ActiveCfg = Debug|Any CPU + {A76B8C8C-0DC5-4DD3-9B1F-02E51A0915F4}.Debug|x86.Build.0 = Debug|Any CPU + {A76B8C8C-0DC5-4DD3-9B1F-02E51A0915F4}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A76B8C8C-0DC5-4DD3-9B1F-02E51A0915F4}.Release|Any CPU.Build.0 = Release|Any CPU + {A76B8C8C-0DC5-4DD3-9B1F-02E51A0915F4}.Release|x64.ActiveCfg = Release|Any CPU + {A76B8C8C-0DC5-4DD3-9B1F-02E51A0915F4}.Release|x64.Build.0 = Release|Any CPU + {A76B8C8C-0DC5-4DD3-9B1F-02E51A0915F4}.Release|x86.ActiveCfg = Release|Any CPU + {A76B8C8C-0DC5-4DD3-9B1F-02E51A0915F4}.Release|x86.Build.0 = Release|Any CPU + {56139957-5C29-4E7D-89BD-7D20598B4EAF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {56139957-5C29-4E7D-89BD-7D20598B4EAF}.Debug|Any CPU.Build.0 = Debug|Any CPU + {56139957-5C29-4E7D-89BD-7D20598B4EAF}.Debug|x64.ActiveCfg = Debug|Any CPU + {56139957-5C29-4E7D-89BD-7D20598B4EAF}.Debug|x64.Build.0 = Debug|Any CPU + {56139957-5C29-4E7D-89BD-7D20598B4EAF}.Debug|x86.ActiveCfg = Debug|Any CPU + {56139957-5C29-4E7D-89BD-7D20598B4EAF}.Debug|x86.Build.0 = Debug|Any CPU + {56139957-5C29-4E7D-89BD-7D20598B4EAF}.Release|Any CPU.ActiveCfg = Release|Any CPU + {56139957-5C29-4E7D-89BD-7D20598B4EAF}.Release|Any CPU.Build.0 = Release|Any CPU + {56139957-5C29-4E7D-89BD-7D20598B4EAF}.Release|x64.ActiveCfg = Release|Any CPU + {56139957-5C29-4E7D-89BD-7D20598B4EAF}.Release|x64.Build.0 = Release|Any CPU + {56139957-5C29-4E7D-89BD-7D20598B4EAF}.Release|x86.ActiveCfg = Release|Any CPU + {56139957-5C29-4E7D-89BD-7D20598B4EAF}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -182,5 +210,7 @@ Global {9559A5F1-080C-4909-B6CF-7E4B3DC55748} = {D3273454-EA07-41D2-BF0B-FCC3675C2483} {EBFE9719-A44B-4978-A71F-D5C254E7F35A} = {D3273454-EA07-41D2-BF0B-FCC3675C2483} {2822C132-BFFB-4D53-AC5B-E7E47DD81A6E} = {0EF2ACDF-012F-4472-A13A-4272419E2903} + {A76B8C8C-0DC5-4DD3-9B1F-02E51A0915F4} = {2D5D5227-4DBD-499A-96B1-76A36B03B750} + {56139957-5C29-4E7D-89BD-7D20598B4EAF} = {2D5D5227-4DBD-499A-96B1-76A36B03B750} EndGlobalSection EndGlobal diff --git a/samples/SampleApp/SampleApp.csproj b/samples/SampleApp/SampleApp.csproj index 1c71f51d36..b623456397 100644 --- a/samples/SampleApp/SampleApp.csproj +++ b/samples/SampleApp/SampleApp.csproj @@ -12,6 +12,7 @@ + diff --git a/samples/SampleApp/Startup.cs b/samples/SampleApp/Startup.cs index f8d32ebe1c..4a6f015a4c 100644 --- a/samples/SampleApp/Startup.cs +++ b/samples/SampleApp/Startup.cs @@ -61,9 +61,11 @@ namespace SampleApp // The following section should be used to demo sockets //options.ListenUnixSocket("/tmp/kestrel-test.sock"); - + }) + .UseLibuv(options => + { // Uncomment the following line to change the default number of libuv threads for all endpoints. - //options.ThreadCount = 4; + options.ThreadCount = 4; }) .UseContentRoot(Directory.GetCurrentDirectory()) .UseStartup() diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Adapter/ConnectionAdapterContext.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/ConnectionAdapterContext.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel/Adapter/ConnectionAdapterContext.cs rename to src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/ConnectionAdapterContext.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Adapter/IAdaptedConnection.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/IAdaptedConnection.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel/Adapter/IAdaptedConnection.cs rename to src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/IAdaptedConnection.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Adapter/IConnectionAdapter.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/IConnectionAdapter.cs similarity index 95% rename from src/Microsoft.AspNetCore.Server.Kestrel/Adapter/IConnectionAdapter.cs rename to src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/IConnectionAdapter.cs index cbdb12b3b3..65140d1952 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Adapter/IConnectionAdapter.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/IConnectionAdapter.cs @@ -1,7 +1,6 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System.IO; using System.Threading.Tasks; namespace Microsoft.AspNetCore.Server.Kestrel.Adapter diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Adapter/Internal/AdaptedPipeline.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/Internal/AdaptedPipeline.cs similarity index 78% rename from src/Microsoft.AspNetCore.Server.Kestrel/Adapter/Internal/AdaptedPipeline.cs rename to src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/Internal/AdaptedPipeline.cs index 488d902d9d..54674ae5d4 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Adapter/Internal/AdaptedPipeline.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/Internal/AdaptedPipeline.cs @@ -9,7 +9,7 @@ using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; namespace Microsoft.AspNetCore.Server.Kestrel.Adapter.Internal { - public class AdaptedPipeline : IDisposable + public class AdaptedPipeline { private const int MinAllocBufferSize = 2048; @@ -31,30 +31,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Adapter.Internal public ISocketOutput Output => _output; - public void Dispose() - { - Input.Writer.Complete(); - } - - public async Task StartAsync() + public async Task RunAsync() { var inputTask = ReadInputAsync(); var outputTask = _output.WriteOutputAsync(); - var result = await Task.WhenAny(inputTask, outputTask); + await inputTask; - if (result == inputTask) - { - // Close output - _output.Dispose(); - } - else - { - // Close input - Input.Writer.Complete(); - } + _output.Dispose(); - await Task.WhenAll(inputTask, outputTask); + await outputTask; } private async Task ReadInputAsync() diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Adapter/Internal/LoggingStream.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/Internal/LoggingStream.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel/Adapter/Internal/LoggingStream.cs rename to src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/Internal/LoggingStream.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Adapter/Internal/RawStream.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/Internal/RawStream.cs similarity index 99% rename from src/Microsoft.AspNetCore.Server.Kestrel/Adapter/Internal/RawStream.cs rename to src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/Internal/RawStream.cs index 7433d5eb78..6e21958576 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Adapter/Internal/RawStream.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/Internal/RawStream.cs @@ -7,7 +7,6 @@ using System.IO.Pipelines; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; -using Microsoft.Extensions.Internal; namespace Microsoft.AspNetCore.Server.Kestrel.Adapter.Internal { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Adapter/Internal/StreamSocketOutput.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/Internal/StreamSocketOutput.cs similarity index 98% rename from src/Microsoft.AspNetCore.Server.Kestrel/Adapter/Internal/StreamSocketOutput.cs rename to src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/Internal/StreamSocketOutput.cs index 34ef6ae317..11da4bc24b 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Adapter/Internal/StreamSocketOutput.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/Internal/StreamSocketOutput.cs @@ -16,7 +16,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Adapter.Internal private readonly Stream _outputStream; private readonly IPipe _pipe; - private object _sync = new object(); + private readonly object _sync = new object(); private bool _completed; public StreamSocketOutput(Stream outputStream, IPipe pipe) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Adapter/ListenOptionsConnectionLoggingExtensions.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/ListenOptionsConnectionLoggingExtensions.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel/Adapter/ListenOptionsConnectionLoggingExtensions.cs rename to src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/ListenOptionsConnectionLoggingExtensions.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Adapter/LoggingConnectionAdapter.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/LoggingConnectionAdapter.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel/Adapter/LoggingConnectionAdapter.cs rename to src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/LoggingConnectionAdapter.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/BadHttpRequestException.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/BadHttpRequestException.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel/BadHttpRequestException.cs rename to src/Microsoft.AspNetCore.Server.Kestrel.Core/BadHttpRequestException.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/ConnectionHandler.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/ConnectionHandler.cs new file mode 100644 index 0000000000..9a346f1805 --- /dev/null +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/ConnectionHandler.cs @@ -0,0 +1,128 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.IO.Pipelines; +using System.Threading; +using Microsoft.AspNetCore.Hosting.Server; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Transport; + +namespace Microsoft.AspNetCore.Server.Kestrel.Internal +{ + public class ConnectionHandler : IConnectionHandler + { + // Base32 encoding - in ascii sort order for easy text based sorting + private static readonly string _encode32Chars = "0123456789ABCDEFGHIJKLMNOPQRSTUV"; + + // Seed the _lastConnectionId for this application instance with + // the number of 100-nanosecond intervals that have elapsed since 12:00:00 midnight, January 1, 0001 + // for a roughly increasing _requestId over restarts + private static long _lastConnectionId = DateTime.UtcNow.Ticks; + + private readonly ServiceContext _serviceContext; + private readonly IHttpApplication _application; + + public ConnectionHandler(ServiceContext serviceContext, IHttpApplication application) + { + _serviceContext = serviceContext; + _application = application; + } + + public IConnectionContext OnConnection(IConnectionInformation connectionInfo) + { + var inputPipe = connectionInfo.PipeFactory.Create(GetInputPipeOptions(connectionInfo.InputWriterScheduler)); + var outputPipe = connectionInfo.PipeFactory.Create(GetOutputPipeOptions(connectionInfo.OutputWriterScheduler)); + + var connectionId = GenerateConnectionId(Interlocked.Increment(ref _lastConnectionId)); + + var frameContext = new FrameContext + { + ConnectionId = connectionId, + ConnectionInformation = connectionInfo, + ServiceContext = _serviceContext + }; + + // TODO: Untangle this mess + var frame = new Frame(_application, frameContext); + var outputProducer = new SocketOutputProducer(outputPipe.Writer, frame, connectionId, _serviceContext.Log); + frame.LifetimeControl = new ConnectionLifetimeControl(connectionId, outputPipe.Reader, outputProducer, _serviceContext.Log); + + var connection = new FrameConnection(new FrameConnectionContext + { + ConnectionId = connectionId, + ServiceContext = _serviceContext, + PipeFactory = connectionInfo.PipeFactory, + ConnectionAdapters = connectionInfo.ListenOptions.ConnectionAdapters, + Frame = frame, + Input = inputPipe, + Output = outputPipe, + OutputProducer = outputProducer + }); + + // Since data cannot be added to the inputPipe by the transport until OnConnection returns, + // Frame.RequestProcessingAsync is guaranteed to unblock the transport thread before calling + // application code. + connection.StartRequestProcessing(); + + return connection; + } + + // Internal for testing + internal PipeOptions GetInputPipeOptions(IScheduler writerScheduler) => new PipeOptions + { + ReaderScheduler = _serviceContext.ThreadPool, + WriterScheduler = writerScheduler, + MaximumSizeHigh = _serviceContext.ServerOptions.Limits.MaxRequestBufferSize ?? 0, + MaximumSizeLow = _serviceContext.ServerOptions.Limits.MaxRequestBufferSize ?? 0 + }; + + internal PipeOptions GetOutputPipeOptions(IScheduler readerScheduler) => new PipeOptions + { + ReaderScheduler = readerScheduler, + WriterScheduler = _serviceContext.ThreadPool, + MaximumSizeHigh = GetOutputResponseBufferSize(), + MaximumSizeLow = GetOutputResponseBufferSize() + }; + + private long GetOutputResponseBufferSize() + { + var bufferSize = _serviceContext.ServerOptions.Limits.MaxResponseBufferSize; + if (bufferSize == 0) + { + // 0 = no buffering so we need to configure the pipe so the the writer waits on the reader directly + return 1; + } + + // null means that we have no back pressure + return bufferSize ?? 0; + } + + private static unsafe string GenerateConnectionId(long id) + { + // The following routine is ~310% faster than calling long.ToString() on x64 + // and ~600% faster than calling long.ToString() on x86 in tight loops of 1 million+ iterations + // See: https://github.com/aspnet/Hosting/pull/385 + + // stackalloc to allocate array on stack rather than heap + char* charBuffer = stackalloc char[13]; + + charBuffer[0] = _encode32Chars[(int)(id >> 60) & 31]; + charBuffer[1] = _encode32Chars[(int)(id >> 55) & 31]; + charBuffer[2] = _encode32Chars[(int)(id >> 50) & 31]; + charBuffer[3] = _encode32Chars[(int)(id >> 45) & 31]; + charBuffer[4] = _encode32Chars[(int)(id >> 40) & 31]; + charBuffer[5] = _encode32Chars[(int)(id >> 35) & 31]; + charBuffer[6] = _encode32Chars[(int)(id >> 30) & 31]; + charBuffer[7] = _encode32Chars[(int)(id >> 25) & 31]; + charBuffer[8] = _encode32Chars[(int)(id >> 20) & 31]; + charBuffer[9] = _encode32Chars[(int)(id >> 15) & 31]; + charBuffer[10] = _encode32Chars[(int)(id >> 10) & 31]; + charBuffer[11] = _encode32Chars[(int)(id >> 5) & 31]; + charBuffer[12] = _encode32Chars[(int)id & 31]; + + // string ctor overload that takes char* + return new string(charBuffer, 0, 13); + } + } +} diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnection.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnection.cs new file mode 100644 index 0000000000..e601f5f0a7 --- /dev/null +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnection.cs @@ -0,0 +1,159 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Collections.Generic; +using System.IO; +using System.IO.Pipelines; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Server.Kestrel.Adapter; +using Microsoft.AspNetCore.Server.Kestrel.Adapter.Internal; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Transport; +using Microsoft.Extensions.Internal; +using Microsoft.Extensions.Logging; + +namespace Microsoft.AspNetCore.Server.Kestrel.Internal +{ + public class FrameConnection : IConnectionContext + { + private readonly FrameConnectionContext _context; + private readonly Frame _frame; + private readonly List _connectionAdapters; + private readonly TaskCompletionSource _frameStartedTcs = new TaskCompletionSource(); + + private AdaptedPipeline _adaptedPipeline; + private Stream _filteredStream; + private Task _adaptedPipelineTask = TaskCache.CompletedTask; + + public FrameConnection(FrameConnectionContext context) + { + _context = context; + _frame = context.Frame; + _connectionAdapters = context.ConnectionAdapters; + } + + public string ConnectionId => _context.ConnectionId; + public IPipeWriter Input => _context.Input.Writer; + public IPipeReader Output => _context.Output.Reader; + + private PipeFactory PipeFactory => _context.PipeFactory; + + // Internal for testing + internal PipeOptions AdaptedPipeOptions => new PipeOptions + { + ReaderScheduler = InlineScheduler.Default, + WriterScheduler = InlineScheduler.Default, + MaximumSizeHigh = _context.ServiceContext.ServerOptions.Limits.MaxRequestBufferSize ?? 0, + MaximumSizeLow = _context.ServiceContext.ServerOptions.Limits.MaxRequestBufferSize ?? 0 + }; + + private IKestrelTrace Log => _context.ServiceContext.Log; + + public void StartRequestProcessing() + { + _frame.Input = _context.Input.Reader; + _frame.Output = _context.OutputProducer; + + if (_connectionAdapters.Count == 0) + { + _frame.Start(); + _frameStartedTcs.SetResult(null); + } + else + { + // Ensure that IConnectionAdapter.OnConnectionAsync does not run on the transport thread. + _context.ServiceContext.ThreadPool.UnsafeRun(state => + { + // ApplyConnectionAdaptersAsync should never throw. If it succeeds, it will call _frame.Start(). + // Otherwise, it will close the connection. + var ignore = ((FrameConnection)state).ApplyConnectionAdaptersAsync(); + }, this); + } + } + + public async Task StopAsync() + { + await _frameStartedTcs.Task; + await _frame.StopAsync(); + await _adaptedPipelineTask; + } + + public void Abort(Exception ex) + { + _frame.Abort(ex); + } + + public void Timeout() + { + _frame.SetBadRequestState(RequestRejectionReason.RequestTimeout); + } + + private async Task ApplyConnectionAdaptersAsync() + { + try + { + var rawSocketOutput = _frame.Output; + var rawStream = new RawStream(_frame.Input, rawSocketOutput); + var adapterContext = new ConnectionAdapterContext(rawStream); + var adaptedConnections = new IAdaptedConnection[_connectionAdapters.Count]; + + for (var i = 0; i < _connectionAdapters.Count; i++) + { + var adaptedConnection = await _connectionAdapters[i].OnConnectionAsync(adapterContext); + adaptedConnections[i] = adaptedConnection; + adapterContext = new ConnectionAdapterContext(adaptedConnection.ConnectionStream); + } + + if (adapterContext.ConnectionStream != rawStream) + { + _filteredStream = adapterContext.ConnectionStream; + _adaptedPipeline = new AdaptedPipeline( + adapterContext.ConnectionStream, + PipeFactory.Create(AdaptedPipeOptions), + PipeFactory.Create(AdaptedPipeOptions)); + + _frame.Input = _adaptedPipeline.Input.Reader; + _frame.Output = _adaptedPipeline.Output; + + _adaptedPipelineTask = RunAdaptedPipeline(); + } + + _frame.AdaptedConnections = adaptedConnections; + _frame.Start(); + _frameStartedTcs.SetResult(null); + } + catch (Exception ex) + { + Log.LogError(0, ex, $"Uncaught exception from the {nameof(IConnectionAdapter.OnConnectionAsync)} method of an {nameof(IConnectionAdapter)}."); + _frameStartedTcs.SetResult(null); + CloseRawPipes(); + } + } + + private async Task RunAdaptedPipeline() + { + try + { + await _adaptedPipeline.RunAsync(); + } + catch (Exception ex) + { + // adaptedPipeline.RunAsync() shouldn't throw. + Log.LogError(0, ex, $"{nameof(FrameConnection)}.{nameof(ApplyConnectionAdaptersAsync)}"); + } + finally + { + CloseRawPipes(); + } + } + + private void CloseRawPipes() + { + _filteredStream?.Dispose(); + _context.OutputProducer.Dispose(); + _context.Input.Reader.Complete(); + } + } +} diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnectionContext.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnectionContext.cs new file mode 100644 index 0000000000..271c009385 --- /dev/null +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnectionContext.cs @@ -0,0 +1,23 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System.Collections.Generic; +using System.IO.Pipelines; +using Microsoft.AspNetCore.Server.Kestrel.Adapter; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; + +namespace Microsoft.AspNetCore.Server.Kestrel.Internal +{ + public class FrameConnectionContext + { + public string ConnectionId { get; set; } + public ServiceContext ServiceContext { get; set; } + public PipeFactory PipeFactory { get; set; } + public List ConnectionAdapters { get; set; } + public Frame Frame { get; set; } + public SocketOutputProducer OutputProducer { get; set; } + + public IPipe Input { get; set; } + public IPipe Output { get; set; } + } +} diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ChunkWriter.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/ChunkWriter.cs similarity index 97% rename from src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ChunkWriter.cs rename to src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/ChunkWriter.cs index 8b69ba4603..6ffbc577b9 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ChunkWriter.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/ChunkWriter.cs @@ -4,7 +4,6 @@ using System; using System.IO.Pipelines; using System.Text; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/ConnectionLifetimeControl.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/ConnectionLifetimeControl.cs new file mode 100644 index 0000000000..ae7d98ba3f --- /dev/null +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/ConnectionLifetimeControl.cs @@ -0,0 +1,45 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System.IO.Pipelines; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; + +namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http +{ + public class ConnectionLifetimeControl + { + public ConnectionLifetimeControl( + string connectionId, + IPipeReader outputPipeReader, + SocketOutputProducer outputProducer, + IKestrelTrace log) + { + ConnectionId = connectionId; + OutputReader = outputPipeReader; + OutputProducer = outputProducer; + Log = log; + } + + private string ConnectionId { get; } + private IPipeReader OutputReader { get; } + private SocketOutputProducer OutputProducer { get; } + private IKestrelTrace Log { get; } + + public void End(ProduceEndType endType) + { + switch (endType) + { + case ProduceEndType.ConnectionKeepAlive: + Log.ConnectionKeepAlive(ConnectionId); + break; + case ProduceEndType.SocketShutdown: + OutputReader.CancelPendingRead(); + goto case ProduceEndType.SocketDisconnect; + case ProduceEndType.SocketDisconnect: + OutputProducer.Dispose(); + Log.ConnectionDisconnect(ConnectionId); + break; + } + } + } +} diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ConnectionOptions.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/ConnectionOptions.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ConnectionOptions.cs rename to src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/ConnectionOptions.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/DateHeaderValueManager.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/DateHeaderValueManager.cs similarity index 97% rename from src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/DateHeaderValueManager.cs rename to src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/DateHeaderValueManager.cs index cb36c22d34..57f68967a4 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/DateHeaderValueManager.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/DateHeaderValueManager.cs @@ -6,7 +6,6 @@ using System.Text; using System.Threading; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.Net.Http.Headers; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { @@ -159,7 +158,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } // No requests since the last timer tick, we need to check if we're beyond the idle threshold - if ((now.Ticks - PlatformApis.VolatileRead(ref _lastRequestSeenTicks)) >= _timeWithoutRequestsUntilIdle.Ticks) + // TODO: Use PlatformApis.VolatileRead equivalent again + if ((now.Ticks - Interlocked.Read(ref _lastRequestSeenTicks)) >= _timeWithoutRequestsUntilIdle.Ticks) { // No requests since idle threshold so stop the timer if it's still running StopTimer(); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.FeatureCollection.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.FeatureCollection.cs similarity index 99% rename from src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.FeatureCollection.cs rename to src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.FeatureCollection.cs index 66be41e7e0..bffde30a58 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.FeatureCollection.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.FeatureCollection.cs @@ -5,7 +5,6 @@ using System; using System.Collections; using System.Collections.Generic; using System.IO; -using System.Linq; using System.Net; using System.Threading; using System.Threading.Tasks; diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.Generated.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.Generated.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.Generated.cs rename to src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.Generated.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.cs similarity index 96% rename from src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs rename to src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.cs index bdaae0f445..e91ca62917 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.cs @@ -16,6 +16,7 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Server.Kestrel.Adapter; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Transport; using Microsoft.Extensions.Internal; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Primitives; @@ -52,7 +53,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http protected Stack, object>> _onStarting; protected Stack, object>> _onCompleted; - private TaskCompletionSource _frameStartedTcs = new TaskCompletionSource(); private Task _requestProcessingTask; protected volatile bool _requestProcessingStopping; // volatile, see: https://msdn.microsoft.com/en-us/library/x13ttww7.aspx protected int _requestAborted; @@ -77,37 +77,39 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http protected long _responseBytesWritten; + private readonly FrameContext _frameContext; private readonly IHttpParser _parser; - public Frame(ConnectionContext context) + public Frame(FrameContext frameContext) { - ConnectionContext = context; - Input = context.Input; - Output = context.Output; + _frameContext = frameContext; - ServerOptions = context.ListenerContext.ServiceContext.ServerOptions; + ServerOptions = ServiceContext.ServerOptions; - _parser = context.ListenerContext.ServiceContext.HttpParserFactory(this); + _parser = ServiceContext.HttpParserFactory(this); FrameControl = this; _keepAliveMilliseconds = (long)ServerOptions.Limits.KeepAliveTimeout.TotalMilliseconds; _requestHeadersTimeoutMilliseconds = (long)ServerOptions.Limits.RequestHeadersTimeout.TotalMilliseconds; } - public ConnectionContext ConnectionContext { get; } - public IPipe Input { get; set; } + public ServiceContext ServiceContext => _frameContext.ServiceContext; + public IConnectionInformation ConnectionInformation => _frameContext.ConnectionInformation; + + public IPipeReader Input { get; set; } public ISocketOutput Output { get; set; } public IEnumerable AdaptedConnections { get; set; } + public ConnectionLifetimeControl LifetimeControl { get; set; } - protected IConnectionControl ConnectionControl => ConnectionContext.ConnectionControl; - protected IKestrelTrace Log => ConnectionContext.ListenerContext.ServiceContext.Log; + protected ITimeoutControl TimeoutControl => ConnectionInformation.TimeoutControl; + protected IKestrelTrace Log => ServiceContext.Log; - private DateHeaderValueManager DateHeaderValueManager => ConnectionContext.ListenerContext.ServiceContext.DateHeaderValueManager; + private DateHeaderValueManager DateHeaderValueManager => ServiceContext.DateHeaderValueManager; // Hold direct reference to ServerOptions since this is used very often in the request processing path private KestrelServerOptions ServerOptions { get; } - private IPEndPoint LocalEndPoint => ConnectionContext.LocalEndPoint; - private IPEndPoint RemoteEndPoint => ConnectionContext.RemoteEndPoint; - protected string ConnectionId => ConnectionContext.ConnectionId; + private IPEndPoint LocalEndPoint => ConnectionInformation.LocalEndPoint; + private IPEndPoint RemoteEndPoint => ConnectionInformation.RemoteEndPoint; + protected string ConnectionId => _frameContext.ConnectionId; public string ConnectionIdFeature { get; set; } public IPAddress RemoteIpAddress { get; set; } @@ -218,8 +220,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http public Stream DuplexStream { get; set; } - public Task FrameStartedTask => _frameStartedTcs.Task; - public CancellationToken RequestAborted { get @@ -392,7 +392,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { Reset(); _requestProcessingTask = RequestProcessingAsync(); - _frameStartedTcs.SetResult(null); } /// @@ -404,11 +403,24 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http public Task StopAsync() { _requestProcessingStopping = true; - Input.Reader.CancelPendingRead(); + Input.CancelPendingRead(); return _requestProcessingTask ?? TaskCache.CompletedTask; } + private void CancelRequestAbortedToken() + { + try + { + RequestAbortedSource.Cancel(); + _abortedCts = null; + } + catch (Exception ex) + { + Log.ApplicationError(ConnectionId, ex); + } + } + /// /// Immediate kill the connection and poison the request and response streams. /// @@ -421,24 +433,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _frameStreams?.RequestBody.Abort(error); _frameStreams?.ResponseBody.Abort(); - try - { - ConnectionControl.End(ProduceEndType.SocketDisconnect); - } - catch (Exception ex) - { - Log.LogError(0, ex, "Abort"); - } + LifetimeControl.End(ProduceEndType.SocketDisconnect); - try - { - RequestAbortedSource.Cancel(); - } - catch (Exception ex) - { - Log.LogError(0, ex, "Abort"); - } - _abortedCts = null; + // Potentially calling user code. CancelRequestAbortedToken logs any exceptions. + ServiceContext.ThreadPool.UnsafeRun(state => ((Frame)state).CancelRequestAbortedToken(), this); } } @@ -856,7 +854,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if (_keepAlive) { - ConnectionControl.End(ProduceEndType.ConnectionKeepAlive); + LifetimeControl.End(ProduceEndType.ConnectionKeepAlive); } if (HttpMethods.IsHead(Method) && _responseBytesWritten > 0) @@ -876,7 +874,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if (_keepAlive) { - ConnectionControl.End(ProduceEndType.ConnectionKeepAlive); + LifetimeControl.End(ProduceEndType.ConnectionKeepAlive); } } @@ -995,7 +993,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http break; } - ConnectionControl.ResetTimeout(_requestHeadersTimeoutMilliseconds, TimeoutAction.SendTimeoutResponse); + TimeoutControl.ResetTimeout(_requestHeadersTimeoutMilliseconds, TimeoutAction.SendTimeoutResponse); _requestProcessingStatus = RequestProcessingStatus.ParsingRequestLine; goto case RequestProcessingStatus.ParsingRequestLine; @@ -1060,7 +1058,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } if (result) { - ConnectionControl.CancelTimeout(); + TimeoutControl.CancelTimeout(); } return result; } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameContext.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameContext.cs new file mode 100644 index 0000000000..134afd77b7 --- /dev/null +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameContext.cs @@ -0,0 +1,14 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using Microsoft.AspNetCore.Server.Kestrel.Transport; + +namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http +{ + public class FrameContext + { + public string ConnectionId { get; set; } + public ServiceContext ServiceContext { get; set; } + public IConnectionInformation ConnectionInformation { get; set; } + } +} diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameDuplexStream.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameDuplexStream.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameDuplexStream.cs rename to src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameDuplexStream.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameHeaders.Generated.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameHeaders.Generated.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameHeaders.Generated.cs rename to src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameHeaders.Generated.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameHeaders.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameHeaders.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameHeaders.cs rename to src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameHeaders.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameOfT.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameOfT.cs similarity index 89% rename from src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameOfT.cs rename to src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameOfT.cs index 8b710aab17..37f3feedee 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameOfT.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameOfT.cs @@ -6,8 +6,7 @@ using System.IO; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Hosting.Server; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Exceptions; using Microsoft.Extensions.Logging; namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http @@ -16,8 +15,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { private readonly IHttpApplication _application; - public Frame(IHttpApplication application, ConnectionContext context) - : base(context) + public Frame(IHttpApplication application, FrameContext frameContext) + : base(frameContext) { _application = application; } @@ -34,13 +33,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { while (!_requestProcessingStopping) { - ConnectionControl.SetTimeout(_keepAliveMilliseconds, TimeoutAction.CloseConnection); + TimeoutControl.SetTimeout(_keepAliveMilliseconds, TimeoutAction.CloseConnection); InitializeHeaders(); while (!_requestProcessingStopping) { - var result = await Input.Reader.ReadAsync(); + var result = await Input.ReadAsync(); var examined = result.Buffer.End; var consumed = result.Buffer.End; @@ -52,13 +51,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { if (_requestProcessingStatus == RequestProcessingStatus.ParsingHeaders) { - throw BadHttpRequestException.GetException(RequestRejectionReason.MalformedRequestInvalidHeaders); + throw BadHttpRequestException.GetException(RequestRejectionReason + .MalformedRequestInvalidHeaders); } throw; } finally { - Input.Reader.Advance(consumed, examined); + Input.Advance(consumed, examined); } if (_requestProcessingStatus == RequestProcessingStatus.AppStarted) @@ -73,9 +73,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http case RequestProcessingStatus.RequestPending: return; case RequestProcessingStatus.ParsingRequestLine: - throw BadHttpRequestException.GetException(RequestRejectionReason.InvalidRequestLine); + throw BadHttpRequestException.GetException( + RequestRejectionReason.InvalidRequestLine); case RequestProcessingStatus.ParsingHeaders: - throw BadHttpRequestException.GetException(RequestRejectionReason.MalformedRequestInvalidHeaders); + throw BadHttpRequestException.GetException(RequestRejectionReason + .MalformedRequestInvalidHeaders); } } } @@ -190,15 +192,18 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http // SetBadRequestState logs the error. SetBadRequestState(ex); } - catch (IOException ex) when (ex.InnerException is UvException) + catch (ConnectionResetException ex) { // Don't log ECONNRESET errors made between requests. Browsers like IE will reset connections regularly. - if (_requestProcessingStatus != RequestProcessingStatus.RequestPending || - ((UvException)ex.InnerException).StatusCode != Constants.ECONNRESET) + if (_requestProcessingStatus != RequestProcessingStatus.RequestPending) { Log.RequestProcessingError(ConnectionId, ex); } } + catch (IOException ex) + { + Log.RequestProcessingError(ConnectionId, ex); + } catch (Exception ex) { Log.LogWarning(0, ex, "Connection processing ended abnormally"); @@ -207,12 +212,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { try { - Input.Reader.Complete(); + Input.Complete(); // If _requestAborted is set, the connection has already been closed. if (Volatile.Read(ref _requestAborted) == 0) { await TryProduceInvalidRequestResponse(); - ConnectionControl.End(ProduceEndType.SocketShutdown); + LifetimeControl.End(ProduceEndType.SocketShutdown); } } catch (Exception ex) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameRequestHeaders.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameRequestHeaders.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameRequestHeaders.cs rename to src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameRequestHeaders.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameRequestStream.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameRequestStream.cs similarity index 99% rename from src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameRequestStream.cs rename to src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameRequestStream.cs index a7b168a73d..3d084adafd 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameRequestStream.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameRequestStream.cs @@ -5,7 +5,6 @@ using System; using System.IO; using System.Threading; using System.Threading.Tasks; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.Extensions.Internal; namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameResponseHeaders.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameResponseHeaders.cs similarity index 98% rename from src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameResponseHeaders.cs rename to src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameResponseHeaders.cs index ea51f47d10..4b6d983327 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameResponseHeaders.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameResponseHeaders.cs @@ -6,7 +6,6 @@ using System.Collections; using System.Collections.Generic; using System.IO.Pipelines; using System.Runtime.CompilerServices; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.Extensions.Primitives; using Microsoft.Net.Http.Headers; diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameResponseStream.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameResponseStream.cs similarity index 98% rename from src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameResponseStream.cs rename to src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameResponseStream.cs index e654a3d7e4..3100520393 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameResponseStream.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameResponseStream.cs @@ -5,7 +5,6 @@ using System; using System.IO; using System.Threading; using System.Threading.Tasks; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameStreamState.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameStreamState.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameStreamState.cs rename to src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameStreamState.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/HttpMethod.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/HttpMethod.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/HttpMethod.cs rename to src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/HttpMethod.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/HttpScheme.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/HttpScheme.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/HttpScheme.cs rename to src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/HttpScheme.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/HttpVersion.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/HttpVersion.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/HttpVersion.cs rename to src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/HttpVersion.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/IFrameControl.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/IFrameControl.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/IFrameControl.cs rename to src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/IFrameControl.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/IHttpHeadersHandler.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/IHttpHeadersHandler.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/IHttpHeadersHandler.cs rename to src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/IHttpHeadersHandler.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/IHttpParser.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/IHttpParser.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/IHttpParser.cs rename to src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/IHttpParser.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/IHttpRequestLineHandler.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/IHttpRequestLineHandler.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/IHttpRequestLineHandler.cs rename to src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/IHttpRequestLineHandler.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ISocketOutput.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/ISocketOutput.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ISocketOutput.cs rename to src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/ISocketOutput.cs index 7298b42163..379dd52318 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ISocketOutput.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/ISocketOutput.cs @@ -2,9 +2,9 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.IO.Pipelines; using System.Threading; using System.Threading.Tasks; -using System.IO.Pipelines; namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/IConnectionControl.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/ITimeoutControl.cs similarity index 76% rename from src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/IConnectionControl.cs rename to src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/ITimeoutControl.cs index 2905913040..4fb389b545 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/IConnectionControl.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/ITimeoutControl.cs @@ -3,11 +3,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { - public interface IConnectionControl + public interface ITimeoutControl { - void Pause(); - void Resume(); - void End(ProduceEndType endType); void SetTimeout(long milliseconds, TimeoutAction timeoutAction); void ResetTimeout(long milliseconds, TimeoutAction timeoutAction); void CancelTimeout(); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/KestrelHttpParser.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/KestrelHttpParser.cs similarity index 99% rename from src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/KestrelHttpParser.cs rename to src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/KestrelHttpParser.cs index 5e3aa7097e..581281ca43 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/KestrelHttpParser.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/KestrelHttpParser.cs @@ -2,7 +2,6 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.Buffers; using System.IO.Pipelines; using System.Numerics; using System.Runtime.CompilerServices; diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/MessageBody.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/MessageBody.cs similarity index 98% rename from src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/MessageBody.cs rename to src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/MessageBody.cs index 8a817b82bb..03130d7628 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/MessageBody.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/MessageBody.cs @@ -215,9 +215,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http private void ConsumedBytes(int count) { - var scan = _context.Input.Reader.ReadAsync().GetResult().Buffer; + var scan = _context.Input.ReadAsync().GetResult().Buffer; var consumed = scan.Move(scan.Start, count); - _context.Input.Reader.Advance(consumed, consumed); + _context.Input.Advance(consumed, consumed); OnConsumedBytes(count); } @@ -304,7 +304,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http protected override ValueTask> PeekAsync(CancellationToken cancellationToken) { - return _context.Input.Reader.PeekAsync(); + return _context.Input.PeekAsync(); } } @@ -351,7 +351,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http return new ValueTask>(); } - var task = _context.Input.Reader.PeekAsync(); + var task = _context.Input.PeekAsync(); if (task.IsCompleted) { @@ -423,7 +423,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http : base(context) { RequestKeepAlive = keepAlive; - _input = _context.Input.Reader; + _input = _context.Input; _requestHeaders = headers; } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/PathNormalizer.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/PathNormalizer.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/PathNormalizer.cs rename to src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/PathNormalizer.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/PipelineExtensions.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/PipelineExtensions.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/PipelineExtensions.cs rename to src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/PipelineExtensions.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ProduceEndType.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/ProduceEndType.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ProduceEndType.cs rename to src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/ProduceEndType.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ReasonPhrases.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/ReasonPhrases.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ReasonPhrases.cs rename to src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/ReasonPhrases.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/RequestProcessingStatus.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/RequestProcessingStatus.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/RequestProcessingStatus.cs rename to src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/RequestProcessingStatus.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/RequestRejectionReason.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/RequestRejectionReason.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/RequestRejectionReason.cs rename to src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/RequestRejectionReason.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/SocketOutput.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/SocketOutputProducer.cs similarity index 51% rename from src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/SocketOutput.cs rename to src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/SocketOutputProducer.cs index 6f8148932c..956fd5a336 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/SocketOutput.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/SocketOutputProducer.cs @@ -6,18 +6,14 @@ using System.IO.Pipelines; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; using Microsoft.Extensions.Internal; namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { - public class SocketOutput : ISocketOutput + public class SocketOutputProducer : ISocketOutput, IDisposable { private static readonly ArraySegment _emptyData = new ArraySegment(new byte[0]); - private readonly KestrelThread _thread; - private readonly UvStreamHandle _socket; - private readonly Connection _connection; private readonly string _connectionId; private readonly IKestrelTrace _log; @@ -26,10 +22,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http private bool _cancelled = false; private bool _completed = false; - private Exception _lastWriteError; - private readonly WriteReqPool _writeReqPool; - private readonly IPipe _pipe; - private Task _writingTask; + + private readonly IPipeWriter _pipe; + private readonly Frame _frame; // https://github.com/dotnet/corefxlab/issues/1334 // Pipelines don't support multiple awaiters on flush @@ -38,24 +33,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http private readonly object _flushLock = new object(); private readonly Action _onFlushCallback; - public SocketOutput( - IPipe pipe, - KestrelThread thread, - UvStreamHandle socket, - Connection connection, - string connectionId, - IKestrelTrace log) + public SocketOutputProducer(IPipeWriter pipe, Frame frame, string connectionId, IKestrelTrace log) { _pipe = pipe; - // We need to have empty pipe at this moment so callback - // get's scheduled - _writingTask = StartWrites(); - _thread = thread; - _socket = socket; - _connection = connection; + _frame = frame; _connectionId = connectionId; _log = log; - _writeReqPool = thread.WriteReqPool; _onFlushCallback = OnFlush; } @@ -68,19 +51,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http lock (_contextLock) { - if (_socket.IsClosed) - { - _log.ConnectionDisconnectedWrite(_connectionId, buffer.Count, _lastWriteError); - - return TaskCache.CompletedTask; - } - if (_completed) { + // TODO: Get actual notification when the consumer stopped from Pipes, + // so we know if the socket is fully closed and why (for logging exceptions); + _log.ConnectionDisconnectedWrite(_connectionId, buffer.Count, ex: null); return TaskCache.CompletedTask; } - writableBuffer = _pipe.Writer.Alloc(); + writableBuffer = _pipe.Alloc(); if (buffer.Count > 0) { @@ -103,23 +82,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http return FlushAsync(writableBuffer); } - public void End(ProduceEndType endType) - { - if (endType == ProduceEndType.SocketShutdown) - { - // Graceful shutdown - _pipe.Reader.CancelPendingRead(); - } - - lock (_contextLock) - { - _completed = true; - } - - // We're done writing - _pipe.Writer.Complete(); - } - private Task FlushAsync(WritableBuffer writableBuffer) { var awaitable = writableBuffer.FlushAsync(); @@ -164,7 +126,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { if (cancellationToken.IsCancellationRequested) { - _connection.AbortAsync(); + _frame.Abort(); _cancelled = true; return Task.FromCanceled(cancellationToken); } @@ -186,7 +148,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http return WriteAsync(_emptyData, cancellationToken); } - public void Write(Action callback, T state) + void ISocketOutput.Write(Action callback, T state) { lock (_contextLock) { @@ -195,106 +157,19 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http return; } - var buffer = _pipe.Writer.Alloc(); + var buffer = _pipe.Alloc(); callback(buffer, state); buffer.Commit(); } } - public async Task StartWrites() + public void Dispose() { - while (true) + lock (_contextLock) { - var result = await _pipe.Reader.ReadAsync(); - var buffer = result.Buffer; - - try - { - if (!buffer.IsEmpty) - { - var writeReq = _writeReqPool.Allocate(); - var writeResult = await writeReq.WriteAsync(_socket, buffer); - _writeReqPool.Return(writeReq); - - // REVIEW: Locking here, do we need to take the context lock? - OnWriteCompleted(writeResult.Status, writeResult.Error); - } - - if (result.IsCancelled) - { - // Send a FIN - await ShutdownAsync(); - } - - if (buffer.IsEmpty && result.IsCompleted) - { - break; - } - } - finally - { - _pipe.Reader.Advance(result.Buffer.End); - } + _completed = true; + _pipe.Complete(); } - - // We're done reading - _pipe.Reader.Complete(); - - _socket.Dispose(); - _connection.OnSocketClosed(); - _log.ConnectionStop(_connectionId); - } - - private void OnWriteCompleted(int writeStatus, Exception writeError) - { - // Called inside _contextLock - var status = writeStatus; - var error = writeError; - - if (error != null) - { - // Abort the connection for any failed write - // Queued on threadpool so get it in as first op. - _connection.AbortAsync(); - _cancelled = true; - _lastWriteError = error; - } - - if (error == null) - { - _log.ConnectionWriteCallback(_connectionId, status); - } - else - { - // Log connection resets at a lower (Debug) level. - if (status == Constants.ECONNRESET) - { - _log.ConnectionReset(_connectionId); - } - else - { - _log.ConnectionError(_connectionId, error); - } - } - } - - private Task ShutdownAsync() - { - var tcs = new TaskCompletionSource(); - _log.ConnectionWriteFin(_connectionId); - - var shutdownReq = new UvShutdownReq(_log); - shutdownReq.Init(_thread.Loop); - shutdownReq.Shutdown(_socket, (req, status, state) => - { - req.Dispose(); - _log.ConnectionWroteFin(_connectionId, status); - - tcs.TrySetResult(null); - }, - this); - - return tcs.Task; } } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/TimeoutAction.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/TimeoutAction.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/TimeoutAction.cs rename to src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/TimeoutAction.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/TransferCoding.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/TransferCoding.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/TransferCoding.cs rename to src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/TransferCoding.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/AsciiUtilities.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/AsciiUtilities.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/AsciiUtilities.cs rename to src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/AsciiUtilities.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/CancellationTokenExtensions.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/CancellationTokenExtensions.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/CancellationTokenExtensions.cs rename to src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/CancellationTokenExtensions.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/Constants.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/Constants.cs new file mode 100644 index 0000000000..f18246c655 --- /dev/null +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/Constants.cs @@ -0,0 +1,32 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure +{ + internal static class Constants + { + public const int MaxExceptionDetailSize = 128; + + /// + /// The IPEndPoint Kestrel will bind to if nothing else is specified. + /// + public static readonly string DefaultServerAddress = "http://localhost:5000"; + + /// + /// Prefix of host name used to specify Unix sockets in the configuration. + /// + public const string UnixPipeHostPrefix = "unix:/"; + + /// + /// Prefix of host name used to specify pipe file descriptor in the configuration. + /// + public const string PipeDescriptorPrefix = "pipefd:"; + + /// + /// Prefix of host name used to specify socket descriptor in the configuration. + /// + public const string SocketDescriptorPrefix = "sockfd:"; + + public const string ServerName = "Kestrel"; + } +} diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/Disposable.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/Disposable.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/Disposable.cs rename to src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/Disposable.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/DisposableAction.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/DisposableAction.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/DisposableAction.cs rename to src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/DisposableAction.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/HttpUtilities.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/HttpUtilities.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/HttpUtilities.cs rename to src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/HttpUtilities.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/IKestrelTrace.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/IKestrelTrace.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/IKestrelTrace.cs rename to src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/IKestrelTrace.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/ISystemClock.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/ISystemClock.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/ISystemClock.cs rename to src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/ISystemClock.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/IThreadPool.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/IThreadPool.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/IThreadPool.cs rename to src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/IThreadPool.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/InlineLoggingThreadPool.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/InlineLoggingThreadPool.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/InlineLoggingThreadPool.cs rename to src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/InlineLoggingThreadPool.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/KestrelTrace.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/KestrelTrace.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/KestrelTrace.cs rename to src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/KestrelTrace.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/LoggingThreadPool.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/LoggingThreadPool.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/LoggingThreadPool.cs rename to src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/LoggingThreadPool.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/Streams.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/Streams.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/Streams.cs rename to src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/Streams.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/SystemClock.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/SystemClock.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/SystemClock.cs rename to src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/SystemClock.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/UriUtilities.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/UriUtilities.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/UriUtilities.cs rename to src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/UriUtilities.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/InternalKestrelServerOptions.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/InternalKestrelServerOptions.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel/Internal/InternalKestrelServerOptions.cs rename to src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/InternalKestrelServerOptions.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/KestrelServerOptionsSetup.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/KestrelServerOptionsSetup.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel/Internal/KestrelServerOptionsSetup.cs rename to src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/KestrelServerOptionsSetup.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/ServiceContext.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/ServiceContext.cs similarity index 80% rename from src/Microsoft.AspNetCore.Server.Kestrel/Internal/ServiceContext.cs rename to src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/ServiceContext.cs index 6233378f40..3c3750c6c2 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/ServiceContext.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/ServiceContext.cs @@ -2,7 +2,6 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; @@ -10,16 +9,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal { public class ServiceContext { - public IApplicationLifetime AppLifetime { get; set; } - public IKestrelTrace Log { get; set; } public IThreadPool ThreadPool { get; set; } public Func HttpParserFactory { get; set; } - public Func FrameFactory { get; set; } - public DateHeaderValueManager DateHeaderValueManager { get; set; } public KestrelServerOptions ServerOptions { get; set; } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServer.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/KestrelServer.cs similarity index 71% rename from src/Microsoft.AspNetCore.Server.Kestrel/KestrelServer.cs rename to src/Microsoft.AspNetCore.Server.Kestrel.Core/KestrelServer.cs index 04ece0d46d..02ac364178 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServer.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/KestrelServer.cs @@ -7,15 +7,16 @@ using System.IO; using System.Linq; using System.Net; using System.Reflection; +using System.Threading.Tasks; using Microsoft.AspNetCore.Builder; -using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting.Server; using Microsoft.AspNetCore.Hosting.Server.Features; using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Server.Kestrel.Internal; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; +using Microsoft.AspNetCore.Server.Kestrel.Transport; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Exceptions; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; @@ -23,21 +24,29 @@ namespace Microsoft.AspNetCore.Server.Kestrel { public class KestrelServer : IServer { - private Stack _disposables; - private readonly IApplicationLifetime _applicationLifetime; + //private Stack _disposables; + private readonly List _transports = new List(); + private readonly ILogger _logger; private readonly IServerAddressesFeature _serverAddresses; + private readonly ITransportFactory _transportFactory; - public KestrelServer(IOptions options, IApplicationLifetime applicationLifetime, ILoggerFactory loggerFactory) + private bool _isRunning; + private DateHeaderValueManager _dateHeaderValueManager; + + public KestrelServer( + IOptions options, + ITransportFactory transportFactory, + ILoggerFactory loggerFactory) { if (options == null) { throw new ArgumentNullException(nameof(options)); } - if (applicationLifetime == null) + if (transportFactory == null) { - throw new ArgumentNullException(nameof(applicationLifetime)); + throw new ArgumentNullException(nameof(transportFactory)); } if (loggerFactory == null) @@ -47,7 +56,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel Options = options.Value ?? new KestrelServerOptions(); InternalOptions = new InternalKestrelServerOptions(); - _applicationLifetime = applicationLifetime; + _transportFactory = transportFactory; _logger = loggerFactory.CreateLogger(typeof(KestrelServer).GetTypeInfo().Namespace); Features = new FeatureCollection(); _serverAddresses = new ServerAddressesFeature(); @@ -72,14 +81,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel ValidateOptions(); - if (_disposables != null) + if (_isRunning) { // The server has already started and/or has not been cleaned up yet throw new InvalidOperationException("Server has already started."); } - _disposables = new Stack(); + _isRunning = true; - var dateHeaderValueManager = new DateHeaderValueManager(); + _dateHeaderValueManager = new DateHeaderValueManager(); var trace = new KestrelTrace(_logger); IThreadPool threadPool; @@ -92,43 +101,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel threadPool = new InlineLoggingThreadPool(trace); } - var engine = new KestrelEngine(new ServiceContext + var serviceContext = new ServiceContext { - FrameFactory = context => - { - return new Frame(application, context); - }, - AppLifetime = _applicationLifetime, Log = trace, - HttpParserFactory = frame => new KestrelHttpParser(frame.ConnectionContext.ListenerContext.ServiceContext.Log), + HttpParserFactory = frame => new KestrelHttpParser(frame.ServiceContext.Log), ThreadPool = threadPool, - DateHeaderValueManager = dateHeaderValueManager, + DateHeaderValueManager = _dateHeaderValueManager, ServerOptions = Options - }); + }; - _disposables.Push(engine); - _disposables.Push(dateHeaderValueManager); - - var threadCount = Options.ThreadCount; - - if (threadCount <= 0) - { - throw new ArgumentOutOfRangeException(nameof(threadCount), - threadCount, - "ThreadCount must be positive."); - } - - if (!Constants.ECONNRESET.HasValue) - { - _logger.LogWarning("Unable to determine ECONNRESET value on this platform."); - } - - if (!Constants.EADDRINUSE.HasValue) - { - _logger.LogWarning("Unable to determine EADDRINUSE value on this platform."); - } - - engine.Start(threadCount); + var connectionHandler = new ConnectionHandler(serviceContext, application); var listenOptions = Options.ListenOptions; var hasListenOptions = listenOptions.Any(); @@ -137,7 +119,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel if (hasListenOptions && hasServerAddresses) { var joined = string.Join(", ", _serverAddresses.Addresses); - _logger.LogWarning($"Overriding address(es) '{joined}'. Binding to endpoints defined in {nameof(WebHostBuilderKestrelExtensions.UseKestrel)}() instead."); + _logger.LogWarning($"Overriding address(es) '{joined}'. Binding to endpoints defined in UseKestrel() instead."); _serverAddresses.Addresses.Clear(); } @@ -146,7 +128,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel _logger.LogDebug($"No listening endpoints were configured. Binding to {Constants.DefaultServerAddress} by default."); // "localhost" for both IPv4 and IPv6 can't be represented as an IPEndPoint. - StartLocalhost(engine, ServerAddress.FromUrl(Constants.DefaultServerAddress)); + StartLocalhost(connectionHandler, ServerAddress.FromUrl(Constants.DefaultServerAddress)); // If StartLocalhost doesn't throw, there is at least one listener. // The port cannot change for "localhost". @@ -181,7 +163,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel if (string.Equals(parsedAddress.Host, "localhost", StringComparison.OrdinalIgnoreCase)) { // "localhost" for both IPv4 and IPv6 can't be represented as an IPEndPoint. - StartLocalhost(engine, parsedAddress); + StartLocalhost(connectionHandler, parsedAddress); // If StartLocalhost doesn't throw, there is at least one listener. // The port cannot change for "localhost". @@ -201,18 +183,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel foreach (var endPoint in listenOptions) { + var transport = _transportFactory.Create(endPoint, connectionHandler); + _transports.Add(transport); + try { - _disposables.Push(engine.CreateServer(endPoint)); + transport.BindAsync().Wait(); } - catch (AggregateException ex) + catch (AggregateException ex) when (ex.InnerException is AddressInUseException) { - if ((ex.InnerException as UvException)?.StatusCode == Constants.EADDRINUSE) - { - throw new IOException($"Failed to bind to address {endPoint}: address already in use.", ex); - } - - throw; + throw new IOException($"Failed to bind to address {endPoint}: address already in use.", ex); } // If requested port was "0", replace with assigned dynamic port. @@ -229,14 +209,24 @@ namespace Microsoft.AspNetCore.Server.Kestrel public void Dispose() { - if (_disposables != null) + if (_transports != null) { - while (_disposables.Count > 0) + var tasks = new Task[_transports.Count]; + for (int i = 0; i < _transports.Count; i++) { - _disposables.Pop().Dispose(); + tasks[i] = _transports[i].UnbindAsync(); } - _disposables = null; + Task.WaitAll(tasks); + + // TODO: Do transport-agnostic connection management/shutdown. + for (int i = 0; i < _transports.Count; i++) + { + tasks[i] = _transports[i].StopAsync(); + } + Task.WaitAll(tasks); } + + _dateHeaderValueManager?.Dispose(); } private void ValidateOptions() @@ -256,7 +246,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel } } - private void StartLocalhost(KestrelEngine engine, ServerAddress parsedAddress) + private void StartLocalhost(ConnectionHandler connectionHandler, ServerAddress parsedAddress) { if (parsedAddress.Port == 0) { @@ -272,20 +262,18 @@ namespace Microsoft.AspNetCore.Server.Kestrel Scheme = parsedAddress.Scheme, }; - _disposables.Push(engine.CreateServer(ipv4ListenOptions)); + var transport = _transportFactory.Create(ipv4ListenOptions, connectionHandler); + _transports.Add(transport); + transport.BindAsync().Wait(); } - catch (AggregateException ex) when (ex.InnerException is UvException) + catch (AggregateException ex) when (ex.InnerException is AddressInUseException) { - var uvEx = (UvException)ex.InnerException; - if (uvEx.StatusCode == Constants.EADDRINUSE) - { throw new IOException($"Failed to bind to address {parsedAddress} on the IPv4 loopback interface: port already in use.", ex); - } - else - { - _logger.LogWarning(0, $"Unable to bind to {parsedAddress} on the IPv4 loopback interface: ({uvEx.Message})"); - exceptions.Add(uvEx); - } + } + catch (AggregateException ex) + { + _logger.LogWarning(0, $"Unable to bind to {parsedAddress} on the IPv4 loopback interface: ({ex.Message})"); + exceptions.Add(ex.InnerException); } try @@ -295,20 +283,18 @@ namespace Microsoft.AspNetCore.Server.Kestrel Scheme = parsedAddress.Scheme, }; - _disposables.Push(engine.CreateServer(ipv6ListenOptions)); + var transport = _transportFactory.Create(ipv6ListenOptions, connectionHandler); + _transports.Add(transport); + transport.BindAsync().Wait(); } - catch (AggregateException ex) when (ex.InnerException is UvException) + catch (AggregateException ex) when (ex.InnerException is AddressInUseException) { - var uvEx = (UvException)ex.InnerException; - if (uvEx.StatusCode == Constants.EADDRINUSE) - { - throw new IOException($"Failed to bind to address {parsedAddress} on the IPv6 loopback interface: port already in use.", ex); - } - else - { - _logger.LogWarning(0, $"Unable to bind to {parsedAddress} on the IPv6 loopback interface: ({uvEx.Message})"); - exceptions.Add(uvEx); - } + throw new IOException($"Failed to bind to address {parsedAddress} on the IPv6 loopback interface: port already in use.", ex); + } + catch (AggregateException ex) + { + _logger.LogWarning(0, $"Unable to bind to {parsedAddress} on the IPv6 loopback interface: ({ex.Message})"); + exceptions.Add(ex.InnerException); } if (exceptions.Count == 2) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServerLimits.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/KestrelServerLimits.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel/KestrelServerLimits.cs rename to src/Microsoft.AspNetCore.Server.Kestrel.Core/KestrelServerLimits.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServerOptions.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/KestrelServerOptions.cs similarity index 74% rename from src/Microsoft.AspNetCore.Server.Kestrel/KestrelServerOptions.cs rename to src/Microsoft.AspNetCore.Server.Kestrel.Core/KestrelServerOptions.cs index c458d1e5f7..e9aba3c672 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServerOptions.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/KestrelServerOptions.cs @@ -30,7 +30,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel /// /// Enables the Listen options callback to resolve and use services registered by the application during startup. - /// Typically initialized by . + /// Typically initialized by UseKestrel()"/>. /// public IServiceProvider ApplicationServices { get; set; } @@ -65,50 +65,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel /// public KestrelServerLimits Limits { get; } = new KestrelServerLimits(); - /// - /// The amount of time after the server begins shutting down before connections will be forcefully closed. - /// Kestrel will wait for the duration of the timeout for any ongoing request processing to complete before - /// terminating the connection. No new connections or requests will be accepted during this time. - /// - /// - /// Defaults to 5 seconds. - /// - public TimeSpan ShutdownTimeout { get; set; } = TimeSpan.FromSeconds(5); - - /// - /// The number of libuv I/O threads used to process requests. - /// - /// - /// Defaults to half of rounded down and clamped between 1 and 16. - /// - public int ThreadCount { get; set; } = ProcessorThreadCount; - - private static int ProcessorThreadCount - { - get - { - // Actual core count would be a better number - // rather than logical cores which includes hyper-threaded cores. - // Divide by 2 for hyper-threading, and good defaults (still need threads to do webserving). - var threadCount = Environment.ProcessorCount >> 1; - - if (threadCount < 1) - { - // Ensure shifted value is at least one - return 1; - } - - if (threadCount > 16) - { - // Receive Side Scaling RSS Processor count currently maxes out at 16 - // would be better to check the NIC's current hardware queues; but xplat... - return 16; - } - - return threadCount; - } - } - /// /// Bind to given IP address and port. /// diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/ListenOptions.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/ListenOptions.cs similarity index 96% rename from src/Microsoft.AspNetCore.Server.Kestrel/ListenOptions.cs rename to src/Microsoft.AspNetCore.Server.Kestrel.Core/ListenOptions.cs index 45ebe7917b..d20fb5d0bf 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/ListenOptions.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/ListenOptions.cs @@ -42,7 +42,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel /// The to bind to. /// Only set if the is . /// - public IPEndPoint IPEndPoint { get; internal set; } + public IPEndPoint IPEndPoint { get; set; } /// /// The absolute path to a Unix domain socket to bind to. @@ -82,7 +82,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel public List ConnectionAdapters { get; } = new List(); // Scheme is hopefully only a temporary measure for back compat with IServerAddressesFeature. - internal string Scheme { get; set; } = "http"; + // TODO: Allow connection adapters to configure the scheme + public string Scheme { get; set; } = "http"; public override string ToString() { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/ListenType.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/ListenType.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel/ListenType.cs rename to src/Microsoft.AspNetCore.Server.Kestrel.Core/ListenType.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Microsoft.AspNetCore.Server.Kestrel.Core.csproj b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Microsoft.AspNetCore.Server.Kestrel.Core.csproj new file mode 100644 index 0000000000..b7038ded2a --- /dev/null +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Microsoft.AspNetCore.Server.Kestrel.Core.csproj @@ -0,0 +1,32 @@ + + + + + + Core components of ASP.NET Core Kestrel cross-platform web server. + netstandard1.3;net46 + true + aspnetcore;kestrel + true + CS1591;$(NoWarn) + false + + + + + + + + + + + + + + + + + + + + diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Properties/AssemblyInfo.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Properties/AssemblyInfo.cs similarity index 96% rename from src/Microsoft.AspNetCore.Server.Kestrel/Properties/AssemblyInfo.cs rename to src/Microsoft.AspNetCore.Server.Kestrel.Core/Properties/AssemblyInfo.cs index a171d27c0f..8d850b7d81 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Properties/AssemblyInfo.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Properties/AssemblyInfo.cs @@ -1,8 +1,6 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System.Reflection; -using System.Resources; using System.Runtime.CompilerServices; [assembly: InternalsVisibleTo("Microsoft.AspNetCore.Server.Kestrel.FunctionalTests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")] diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/ServerAddress.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/ServerAddress.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel/ServerAddress.cs rename to src/Microsoft.AspNetCore.Server.Kestrel.Core/ServerAddress.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Systemd/KesterlServerOptionsSystemdExtensions.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Systemd/KesterlServerOptionsSystemdExtensions.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel/Systemd/KesterlServerOptionsSystemdExtensions.cs rename to src/Microsoft.AspNetCore.Server.Kestrel.Core/Systemd/KesterlServerOptionsSystemdExtensions.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Transport/Exceptions/AddressInUseException.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Transport/Exceptions/AddressInUseException.cs new file mode 100644 index 0000000000..2d9d3e10ae --- /dev/null +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Transport/Exceptions/AddressInUseException.cs @@ -0,0 +1,18 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; + +namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Exceptions +{ + public class AddressInUseException : InvalidOperationException + { + public AddressInUseException(string message) : base(message) + { + } + + public AddressInUseException(string message, Exception inner) : base(message, inner) + { + } + } +} diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Transport/Exceptions/ConnectionResetException.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Transport/Exceptions/ConnectionResetException.cs new file mode 100644 index 0000000000..87235175e0 --- /dev/null +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Transport/Exceptions/ConnectionResetException.cs @@ -0,0 +1,19 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.IO; + +namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Exceptions +{ + public class ConnectionResetException : IOException + { + public ConnectionResetException(string message) : base(message) + { + } + + public ConnectionResetException(string message, Exception inner) : base(message, inner) + { + } + } +} diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Transport/IConnectionContext.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Transport/IConnectionContext.cs new file mode 100644 index 0000000000..3e1b19119a --- /dev/null +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Transport/IConnectionContext.cs @@ -0,0 +1,21 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.IO.Pipelines; +using System.Threading.Tasks; + +namespace Microsoft.AspNetCore.Server.Kestrel.Transport +{ + public interface IConnectionContext + { + string ConnectionId { get; } + IPipeWriter Input { get; } + IPipeReader Output { get; } + + // TODO: Remove these (Use Pipes instead?) + Task StopAsync(); + void Abort(Exception ex); + void Timeout(); + } +} diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Transport/IConnectionHandler.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Transport/IConnectionHandler.cs new file mode 100644 index 0000000000..ba575773e3 --- /dev/null +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Transport/IConnectionHandler.cs @@ -0,0 +1,10 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +namespace Microsoft.AspNetCore.Server.Kestrel.Transport +{ + public interface IConnectionHandler + { + IConnectionContext OnConnection(IConnectionInformation connectionInfo); + } +} diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Transport/IConnectionInformation.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Transport/IConnectionInformation.cs new file mode 100644 index 0000000000..911b83a0df --- /dev/null +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Transport/IConnectionInformation.cs @@ -0,0 +1,23 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System.IO.Pipelines; +using System.Net; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; + +namespace Microsoft.AspNetCore.Server.Kestrel.Transport +{ + public interface IConnectionInformation + { + ListenOptions ListenOptions { get; } + IPEndPoint RemoteEndPoint { get; } + IPEndPoint LocalEndPoint { get; } + + PipeFactory PipeFactory { get; } + IScheduler InputWriterScheduler { get; } + IScheduler OutputWriterScheduler { get; } + + // TODO: Remove timeout management from transport + ITimeoutControl TimeoutControl { get; } + } +} diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Transport/ITransport.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Transport/ITransport.cs new file mode 100644 index 0000000000..7aeea940f6 --- /dev/null +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Transport/ITransport.cs @@ -0,0 +1,15 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System.Threading.Tasks; + +namespace Microsoft.AspNetCore.Server.Kestrel.Transport +{ + public interface ITransport + { + // Can only be called once per ITransport + Task BindAsync(); + Task UnbindAsync(); + Task StopAsync(); + } +} diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Transport/ITransportFactory.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Transport/ITransportFactory.cs new file mode 100644 index 0000000000..74eef3d3d6 --- /dev/null +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Transport/ITransportFactory.cs @@ -0,0 +1,10 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +namespace Microsoft.AspNetCore.Server.Kestrel.Transport +{ + public interface ITransportFactory + { + ITransport Create(ListenOptions listenOptions, IConnectionHandler handler); + } +} diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Https/ListenOptionsHttpsExtensions.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Https/ListenOptionsHttpsExtensions.cs index 148da6deb1..f757beb3b5 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Https/ListenOptionsHttpsExtensions.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Https/ListenOptionsHttpsExtensions.cs @@ -1,7 +1,6 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System; using System.IO; using System.Security.Cryptography.X509Certificates; using Microsoft.AspNetCore.Server.Kestrel; diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Https/Microsoft.AspNetCore.Server.Kestrel.Https.csproj b/src/Microsoft.AspNetCore.Server.Kestrel.Https/Microsoft.AspNetCore.Server.Kestrel.Https.csproj index 2e425cd7e4..f49fae3639 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Https/Microsoft.AspNetCore.Server.Kestrel.Https.csproj +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Https/Microsoft.AspNetCore.Server.Kestrel.Https.csproj @@ -8,10 +8,11 @@ true aspnetcore;kestrel CS1591;$(NoWarn) + false - + diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Https/baseline.net45.json b/src/Microsoft.AspNetCore.Server.Kestrel.Https/baseline.net45.json deleted file mode 100644 index f6e1715d55..0000000000 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Https/baseline.net45.json +++ /dev/null @@ -1,292 +0,0 @@ -{ - "AssemblyIdentity": "Microsoft.AspNetCore.Server.Kestrel.Https, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60", - "Types": [ - { - "Name": "Microsoft.AspNetCore.Hosting.KestrelServerOptionsHttpsExtensions", - "Visibility": "Public", - "Kind": "Class", - "Abstract": true, - "Static": true, - "Sealed": true, - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "UseHttps", - "Parameters": [ - { - "Name": "options", - "Type": "Microsoft.AspNetCore.Server.Kestrel.KestrelServerOptions" - }, - { - "Name": "fileName", - "Type": "System.String" - } - ], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.KestrelServerOptions", - "Static": true, - "Extension": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "UseHttps", - "Parameters": [ - { - "Name": "options", - "Type": "Microsoft.AspNetCore.Server.Kestrel.KestrelServerOptions" - }, - { - "Name": "fileName", - "Type": "System.String" - }, - { - "Name": "password", - "Type": "System.String" - } - ], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.KestrelServerOptions", - "Static": true, - "Extension": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "UseHttps", - "Parameters": [ - { - "Name": "options", - "Type": "Microsoft.AspNetCore.Server.Kestrel.KestrelServerOptions" - }, - { - "Name": "serverCertificate", - "Type": "System.Security.Cryptography.X509Certificates.X509Certificate2" - } - ], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.KestrelServerOptions", - "Static": true, - "Extension": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "UseHttps", - "Parameters": [ - { - "Name": "options", - "Type": "Microsoft.AspNetCore.Server.Kestrel.KestrelServerOptions" - }, - { - "Name": "httpsOptions", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Https.HttpsConnectionFilterOptions" - } - ], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.KestrelServerOptions", - "Static": true, - "Extension": true, - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Https.ClientCertificateMode", - "Visibility": "Public", - "Kind": "Enumeration", - "Sealed": true, - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Field", - "Name": "NoCertificate", - "Parameters": [], - "GenericParameter": [], - "Literal": "0" - }, - { - "Kind": "Field", - "Name": "AllowCertificate", - "Parameters": [], - "GenericParameter": [], - "Literal": "1" - }, - { - "Kind": "Field", - "Name": "RequireCertificate", - "Parameters": [], - "GenericParameter": [], - "Literal": "2" - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Https.HttpsConnectionFilter", - "Visibility": "Public", - "Kind": "Class", - "ImplementedInterfaces": [ - "Microsoft.AspNetCore.Server.Kestrel.Filter.IConnectionFilter" - ], - "Members": [ - { - "Kind": "Method", - "Name": "OnConnectionAsync", - "Parameters": [ - { - "Name": "context", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Filter.ConnectionFilterContext" - } - ], - "ReturnType": "System.Threading.Tasks.Task", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Filter.IConnectionFilter", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "options", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Https.HttpsConnectionFilterOptions" - }, - { - "Name": "previous", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Filter.IConnectionFilter" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Https.HttpsConnectionFilterOptions", - "Visibility": "Public", - "Kind": "Class", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "get_ServerCertificate", - "Parameters": [], - "ReturnType": "System.Security.Cryptography.X509Certificates.X509Certificate2", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_ServerCertificate", - "Parameters": [ - { - "Name": "value", - "Type": "System.Security.Cryptography.X509Certificates.X509Certificate2" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_ClientCertificateMode", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Https.ClientCertificateMode", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_ClientCertificateMode", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Https.ClientCertificateMode" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_ClientCertificateValidation", - "Parameters": [], - "ReturnType": "System.Func", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_ClientCertificateValidation", - "Parameters": [ - { - "Name": "value", - "Type": "System.Func" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_SslProtocols", - "Parameters": [], - "ReturnType": "System.Security.Authentication.SslProtocols", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_SslProtocols", - "Parameters": [ - { - "Name": "value", - "Type": "System.Security.Authentication.SslProtocols" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_CheckCertificateRevocation", - "Parameters": [], - "ReturnType": "System.Boolean", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_CheckCertificateRevocation", - "Parameters": [ - { - "Name": "value", - "Type": "System.Boolean" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - } - ] -} \ No newline at end of file diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Https/baseline.netcore.json b/src/Microsoft.AspNetCore.Server.Kestrel.Https/baseline.netcore.json deleted file mode 100644 index f6e1715d55..0000000000 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Https/baseline.netcore.json +++ /dev/null @@ -1,292 +0,0 @@ -{ - "AssemblyIdentity": "Microsoft.AspNetCore.Server.Kestrel.Https, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60", - "Types": [ - { - "Name": "Microsoft.AspNetCore.Hosting.KestrelServerOptionsHttpsExtensions", - "Visibility": "Public", - "Kind": "Class", - "Abstract": true, - "Static": true, - "Sealed": true, - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "UseHttps", - "Parameters": [ - { - "Name": "options", - "Type": "Microsoft.AspNetCore.Server.Kestrel.KestrelServerOptions" - }, - { - "Name": "fileName", - "Type": "System.String" - } - ], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.KestrelServerOptions", - "Static": true, - "Extension": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "UseHttps", - "Parameters": [ - { - "Name": "options", - "Type": "Microsoft.AspNetCore.Server.Kestrel.KestrelServerOptions" - }, - { - "Name": "fileName", - "Type": "System.String" - }, - { - "Name": "password", - "Type": "System.String" - } - ], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.KestrelServerOptions", - "Static": true, - "Extension": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "UseHttps", - "Parameters": [ - { - "Name": "options", - "Type": "Microsoft.AspNetCore.Server.Kestrel.KestrelServerOptions" - }, - { - "Name": "serverCertificate", - "Type": "System.Security.Cryptography.X509Certificates.X509Certificate2" - } - ], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.KestrelServerOptions", - "Static": true, - "Extension": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "UseHttps", - "Parameters": [ - { - "Name": "options", - "Type": "Microsoft.AspNetCore.Server.Kestrel.KestrelServerOptions" - }, - { - "Name": "httpsOptions", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Https.HttpsConnectionFilterOptions" - } - ], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.KestrelServerOptions", - "Static": true, - "Extension": true, - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Https.ClientCertificateMode", - "Visibility": "Public", - "Kind": "Enumeration", - "Sealed": true, - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Field", - "Name": "NoCertificate", - "Parameters": [], - "GenericParameter": [], - "Literal": "0" - }, - { - "Kind": "Field", - "Name": "AllowCertificate", - "Parameters": [], - "GenericParameter": [], - "Literal": "1" - }, - { - "Kind": "Field", - "Name": "RequireCertificate", - "Parameters": [], - "GenericParameter": [], - "Literal": "2" - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Https.HttpsConnectionFilter", - "Visibility": "Public", - "Kind": "Class", - "ImplementedInterfaces": [ - "Microsoft.AspNetCore.Server.Kestrel.Filter.IConnectionFilter" - ], - "Members": [ - { - "Kind": "Method", - "Name": "OnConnectionAsync", - "Parameters": [ - { - "Name": "context", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Filter.ConnectionFilterContext" - } - ], - "ReturnType": "System.Threading.Tasks.Task", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Filter.IConnectionFilter", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "options", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Https.HttpsConnectionFilterOptions" - }, - { - "Name": "previous", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Filter.IConnectionFilter" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Https.HttpsConnectionFilterOptions", - "Visibility": "Public", - "Kind": "Class", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "get_ServerCertificate", - "Parameters": [], - "ReturnType": "System.Security.Cryptography.X509Certificates.X509Certificate2", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_ServerCertificate", - "Parameters": [ - { - "Name": "value", - "Type": "System.Security.Cryptography.X509Certificates.X509Certificate2" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_ClientCertificateMode", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Https.ClientCertificateMode", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_ClientCertificateMode", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Https.ClientCertificateMode" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_ClientCertificateValidation", - "Parameters": [], - "ReturnType": "System.Func", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_ClientCertificateValidation", - "Parameters": [ - { - "Name": "value", - "Type": "System.Func" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_SslProtocols", - "Parameters": [], - "ReturnType": "System.Security.Authentication.SslProtocols", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_SslProtocols", - "Parameters": [ - { - "Name": "value", - "Type": "System.Security.Authentication.SslProtocols" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_CheckCertificateRevocation", - "Parameters": [], - "ReturnType": "System.Boolean", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_CheckCertificateRevocation", - "Parameters": [ - { - "Name": "value", - "Type": "System.Boolean" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - } - ] -} \ No newline at end of file diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Https/exceptions.net45.json b/src/Microsoft.AspNetCore.Server.Kestrel.Https/exceptions.net45.json deleted file mode 100644 index c063085fff..0000000000 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Https/exceptions.net45.json +++ /dev/null @@ -1,14 +0,0 @@ -[ - { - "OldTypeId": "public static class Microsoft.AspNetCore.Hosting.KestrelServerOptionsHttpsExtensions", - "Kind": "Removal" - }, - { - "OldTypeId": "public class Microsoft.AspNetCore.Server.Kestrel.Https.HttpsConnectionFilter : Microsoft.AspNetCore.Server.Kestrel.Filter.IConnectionFilter", - "Kind": "Removal" - }, - { - "OldTypeId": "public class Microsoft.AspNetCore.Server.Kestrel.Https.HttpsConnectionFilterOptions", - "Kind": "Removal" - } -] \ No newline at end of file diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Https/exceptions.netcore.json b/src/Microsoft.AspNetCore.Server.Kestrel.Https/exceptions.netcore.json deleted file mode 100644 index c063085fff..0000000000 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Https/exceptions.netcore.json +++ /dev/null @@ -1,14 +0,0 @@ -[ - { - "OldTypeId": "public static class Microsoft.AspNetCore.Hosting.KestrelServerOptionsHttpsExtensions", - "Kind": "Removal" - }, - { - "OldTypeId": "public class Microsoft.AspNetCore.Server.Kestrel.Https.HttpsConnectionFilter : Microsoft.AspNetCore.Server.Kestrel.Filter.IConnectionFilter", - "Kind": "Removal" - }, - { - "OldTypeId": "public class Microsoft.AspNetCore.Server.Kestrel.Https.HttpsConnectionFilterOptions", - "Kind": "Removal" - } -] \ No newline at end of file diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Http/Connection.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Http/Connection.cs new file mode 100644 index 0000000000..c1e0637f60 --- /dev/null +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Http/Connection.cs @@ -0,0 +1,276 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Diagnostics; +using System.IO; +using System.IO.Pipelines; +using System.Threading; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; +using Microsoft.AspNetCore.Server.Kestrel.Transport; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Exceptions; +using Microsoft.Extensions.Logging; + +namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http +{ + public class Connection : ConnectionContext, ITimeoutControl + { + private const int MinAllocBufferSize = 2048; + + private static readonly Action _readCallback = + (handle, status, state) => ReadCallback(handle, status, state); + + private static readonly Func _allocCallback = + (handle, suggestedsize, state) => AllocCallback(handle, suggestedsize, state); + + private readonly UvStreamHandle _socket; + private IConnectionContext _connectionContext; + + private TaskCompletionSource _socketClosedTcs = new TaskCompletionSource(); + + private long _lastTimestamp; + private long _timeoutTimestamp = long.MaxValue; + private TimeoutAction _timeoutAction; + private WritableBuffer? _currentWritableBuffer; + + public Connection(ListenerContext context, UvStreamHandle socket) : base(context) + { + _socket = socket; + socket.Connection = this; + TimeoutControl = this; + + var tcpHandle = _socket as UvTcpHandle; + if (tcpHandle != null) + { + RemoteEndPoint = tcpHandle.GetPeerIPEndPoint(); + LocalEndPoint = tcpHandle.GetSockIPEndPoint(); + } + + _lastTimestamp = Thread.Loop.Now(); + } + + // For testing + public Connection() + { + } + + public string ConnectionId { get; set; } + public IPipeWriter Input { get; set; } + public SocketOutputConsumer Output { get; set; } + + private IKestrelTrace Log => ListenerContext.TransportContext.Log; + private IConnectionHandler ConnectionHandler => ListenerContext.TransportContext.ConnectionHandler; + private KestrelThread Thread => ListenerContext.Thread; + + public void Start() + { + try + { + _connectionContext = ConnectionHandler.OnConnection(this); + ConnectionId = _connectionContext.ConnectionId; + + Log.ConnectionStart(ConnectionId); + KestrelEventSource.Log.ConnectionStart(this); + + Input = _connectionContext.Input; + Output = new SocketOutputConsumer(_connectionContext.Output, Thread, _socket, this, ConnectionId, Log); + + // Start socket prior to applying the ConnectionAdapter + _socket.ReadStart(_allocCallback, _readCallback, this); + _lastTimestamp = Thread.Loop.Now(); + } + catch (Exception e) + { + Log.LogError(0, e, "Connection.StartFrame"); + throw; + } + } + + public Task StopAsync() + { + return Task.WhenAll(_connectionContext.StopAsync(), _socketClosedTcs.Task); + } + + public virtual Task AbortAsync(Exception error = null) + { + _connectionContext.Abort(error); + return _socketClosedTcs.Task; + } + + // Called on Libuv thread + public virtual void OnSocketClosed() + { + KestrelEventSource.Log.ConnectionStop(this); + + Input.Complete(new TaskCanceledException("The request was aborted")); + _socketClosedTcs.TrySetResult(null); + } + + // Called on Libuv thread + public void Tick(long timestamp) + { + if (timestamp > PlatformApis.VolatileRead(ref _timeoutTimestamp)) + { + TimeoutControl.CancelTimeout(); + + if (_timeoutAction == TimeoutAction.SendTimeoutResponse) + { + _connectionContext.Timeout(); + } + + StopAsync(); + } + + Interlocked.Exchange(ref _lastTimestamp, timestamp); + } + + private static LibuvFunctions.uv_buf_t AllocCallback(UvStreamHandle handle, int suggestedSize, object state) + { + return ((Connection)state).OnAlloc(handle, suggestedSize); + } + + private unsafe LibuvFunctions.uv_buf_t OnAlloc(UvStreamHandle handle, int suggestedSize) + { + Debug.Assert(_currentWritableBuffer == null); + var currentWritableBuffer = Input.Alloc(MinAllocBufferSize); + _currentWritableBuffer = currentWritableBuffer; + void* dataPtr; + var tryGetPointer = currentWritableBuffer.Buffer.TryGetPointer(out dataPtr); + Debug.Assert(tryGetPointer); + + return handle.Libuv.buf_init( + (IntPtr)dataPtr, + currentWritableBuffer.Buffer.Length); + } + + private static void ReadCallback(UvStreamHandle handle, int status, object state) + { + ((Connection)state).OnRead(handle, status); + } + + private async void OnRead(UvStreamHandle handle, int status) + { + var normalRead = status >= 0; + var normalDone = status == Constants.EOF; + var errorDone = !(normalDone || normalRead); + var readCount = normalRead ? status : 0; + + if (normalRead) + { + Log.ConnectionRead(ConnectionId, readCount); + } + else + { + _socket.ReadStop(); + + if (normalDone) + { + Log.ConnectionReadFin(ConnectionId); + } + } + + IOException error = null; + WritableBufferAwaitable? flushTask = null; + if (errorDone) + { + Exception uvError; + handle.Libuv.Check(status, out uvError); + + // Log connection resets at a lower (Debug) level. + if (status == Constants.ECONNRESET) + { + Log.ConnectionReset(ConnectionId); + error = new ConnectionResetException(uvError.Message, uvError); + } + else + { + Log.ConnectionError(ConnectionId, uvError); + error = new IOException(uvError.Message, uvError); + } + + _currentWritableBuffer?.Commit(); + } + else + { + Debug.Assert(_currentWritableBuffer != null); + + var currentWritableBuffer = _currentWritableBuffer.Value; + currentWritableBuffer.Advance(readCount); + flushTask = currentWritableBuffer.FlushAsync(); + } + + _currentWritableBuffer = null; + if (flushTask?.IsCompleted == false) + { + Pause(); + var result = await flushTask.Value; + // If the reader isn't complete then resume + if (!result.IsCompleted) + { + Resume(); + } + } + + if (!normalRead) + { + Input.Complete(error); + var ignore = AbortAsync(error); + } + } + + private void Pause() + { + // It's possible that uv_close was called between the call to Thread.Post() and now. + if (!_socket.IsClosed) + { + _socket.ReadStop(); + } + } + + private void Resume() + { + // It's possible that uv_close was called even before the call to Resume(). + if (!_socket.IsClosed) + { + try + { + _socket.ReadStart(_allocCallback, _readCallback, this); + } + catch (UvException) + { + // ReadStart() can throw a UvException in some cases (e.g. socket is no longer connected). + // This should be treated the same as OnRead() seeing a "normalDone" condition. + Log.ConnectionReadFin(ConnectionId); + Input.Complete(); + } + } + } + + void ITimeoutControl.SetTimeout(long milliseconds, TimeoutAction timeoutAction) + { + Debug.Assert(_timeoutTimestamp == long.MaxValue, "Concurrent timeouts are not supported"); + + AssignTimeout(milliseconds, timeoutAction); + } + + void ITimeoutControl.ResetTimeout(long milliseconds, TimeoutAction timeoutAction) + { + AssignTimeout(milliseconds, timeoutAction); + } + + void ITimeoutControl.CancelTimeout() + { + Interlocked.Exchange(ref _timeoutTimestamp, long.MaxValue); + } + + private void AssignTimeout(long milliseconds, TimeoutAction timeoutAction) + { + _timeoutAction = timeoutAction; + + // Add KestrelThread.HeartbeatMilliseconds extra milliseconds since this can be called right before the next heartbeat. + Interlocked.Exchange(ref _timeoutTimestamp, _lastTimestamp + milliseconds + KestrelThread.HeartbeatMilliseconds); + } + } +} diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ConnectionContext.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Http/ConnectionContext.cs similarity index 56% rename from src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ConnectionContext.cs rename to src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Http/ConnectionContext.cs index 267f34ddaa..869935033e 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ConnectionContext.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Http/ConnectionContext.cs @@ -1,14 +1,13 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System; -using System.Net; using System.IO.Pipelines; -using Microsoft.AspNetCore.Http.Features; +using System.Net; +using Microsoft.AspNetCore.Server.Kestrel.Transport; namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { - public class ConnectionContext + public class ConnectionContext : IConnectionInformation { public ConnectionContext() { @@ -21,16 +20,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http public ListenerContext ListenerContext { get; set; } - public IPipe Input { get; set; } - - public ISocketOutput Output { get; set; } - - public IConnectionControl ConnectionControl { get; set; } - + public ListenOptions ListenOptions => ListenerContext.ListenOptions; public IPEndPoint RemoteEndPoint { get; set; } - public IPEndPoint LocalEndPoint { get; set; } - public string ConnectionId { get; set; } + public PipeFactory PipeFactory => ListenerContext.Thread.PipelineFactory; + public IScheduler InputWriterScheduler => ListenerContext.Thread; + public IScheduler OutputWriterScheduler => ListenerContext.Thread; + + public ITimeoutControl TimeoutControl { get; set; } } } \ No newline at end of file diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ConnectionManager.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Http/ConnectionManager.cs similarity index 87% rename from src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ConnectionManager.cs rename to src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Http/ConnectionManager.cs index dbea0eefed..302887aa8a 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ConnectionManager.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Http/ConnectionManager.cs @@ -4,7 +4,6 @@ using System; using System.Collections.Generic; using System.Threading.Tasks; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http @@ -12,12 +11,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http public class ConnectionManager { private readonly KestrelThread _thread; - private readonly IThreadPool _threadPool; - public ConnectionManager(KestrelThread thread, IThreadPool threadPool) + public ConnectionManager(KestrelThread thread) { _thread = thread; - _threadPool = threadPool; } public async Task WalkConnectionsAndCloseAsync(TimeSpan timeout) @@ -64,9 +61,18 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } }); - _threadPool.Run(() => + Task.Run(() => { - Task.WaitAll(tasks.ToArray()); + try + { + Task.WaitAll(tasks.ToArray()); + } + catch (Exception ex) + { + tcs.SetException(ex); + return; + } + tcs.SetResult(null); }); } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/IAsyncDisposable.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Http/IAsyncDisposable.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/IAsyncDisposable.cs rename to src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Http/IAsyncDisposable.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Listener.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Http/Listener.cs similarity index 96% rename from src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Listener.cs rename to src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Http/Listener.cs index a8624d1764..9666be8181 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Listener.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Http/Listener.cs @@ -5,6 +5,7 @@ using System; using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal; using Microsoft.Extensions.Logging; namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http @@ -16,14 +17,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { private bool _closed; - public Listener(ServiceContext serviceContext) - : base(serviceContext) + public Listener(LibuvTransportContext transportContext) : base(transportContext) { } protected UvStreamHandle ListenSocket { get; private set; } - public IKestrelTrace Log => ServiceContext.Log; + public IKestrelTrace Log => TransportContext.Log; public Task StartAsync( ListenOptions listenOptions, diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Http/ListenerContext.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Http/ListenerContext.cs new file mode 100644 index 0000000000..ac0d07f37f --- /dev/null +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Http/ListenerContext.cs @@ -0,0 +1,45 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal; + +namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http +{ + public class ListenerContext + { + public ListenerContext(LibuvTransportContext transportContext) + { + TransportContext = transportContext; + } + + public LibuvTransportContext TransportContext { get; set; } + + public ListenOptions ListenOptions { get; set; } + + public KestrelThread Thread { get; set; } + + /// + /// Creates a socket which can be used to accept an incoming connection. + /// + protected UvStreamHandle CreateAcceptSocket() + { + switch (ListenOptions.Type) + { + case ListenType.IPEndPoint: + case ListenType.FileHandle: + var tcpHandle = new UvTcpHandle(TransportContext.Log); + tcpHandle.Init(Thread.Loop, Thread.QueueCloseHandle); + tcpHandle.NoDelay(ListenOptions.NoDelay); + return tcpHandle; + case ListenType.SocketPath: + var pipeHandle = new UvPipeHandle(TransportContext.Log); + pipeHandle.Init(Thread.Loop, Thread.QueueCloseHandle); + return pipeHandle; + default: + throw new InvalidOperationException(); + } + } + } +} diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ListenerPrimary.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Http/ListenerPrimary.cs similarity index 97% rename from src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ListenerPrimary.cs rename to src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Http/ListenerPrimary.cs index ebf6267630..8d47e7871e 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ListenerPrimary.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Http/ListenerPrimary.cs @@ -8,6 +8,7 @@ using System.Runtime.InteropServices; using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal; using Microsoft.Extensions.Logging; namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http @@ -29,7 +30,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http // but it has no other functional significance private readonly ArraySegment> _dummyMessage = new ArraySegment>(new[] { new ArraySegment(new byte[] { 1, 2, 3, 4 }) }); - public ListenerPrimary(ServiceContext serviceContext) : base(serviceContext) + public ListenerPrimary(LibuvTransportContext transportContext) : base(transportContext) { } @@ -205,7 +206,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _bufPtr = _bufHandle.AddrOfPinnedObject(); } - public Libuv.uv_buf_t AllocCallback(UvStreamHandle dispatchPipe, int suggestedSize) + public LibuvFunctions.uv_buf_t AllocCallback(UvStreamHandle dispatchPipe, int suggestedSize) { return dispatchPipe.Libuv.buf_init(_bufPtr + _bytesRead, _bufferLength - _bytesRead); } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ListenerSecondary.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Http/ListenerSecondary.cs similarity index 95% rename from src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ListenerSecondary.cs rename to src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Http/ListenerSecondary.cs index c2486055f4..243a72472a 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ListenerSecondary.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Http/ListenerSecondary.cs @@ -7,6 +7,7 @@ using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal; using Microsoft.Extensions.Logging; namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http @@ -20,17 +21,17 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http private string _pipeName; private byte[] _pipeMessage; private IntPtr _ptr; - private Libuv.uv_buf_t _buf; + private LibuvFunctions.uv_buf_t _buf; private bool _closed; - public ListenerSecondary(ServiceContext serviceContext) : base(serviceContext) + public ListenerSecondary(LibuvTransportContext transportContext) : base(transportContext) { _ptr = Marshal.AllocHGlobal(4); } UvPipeHandle DispatchPipe { get; set; } - public IKestrelTrace Log => ServiceContext.Log; + public IKestrelTrace Log => TransportContext.Log; public Task StartAsync( string pipeName, @@ -101,7 +102,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http (handle, status2, state) => ((ListenerSecondary)state).ReadStartCallback(handle, status2), this); - writeReq.Init(Thread.Loop); + writeReq.Init(Thread.Loop); var result = await writeReq.WriteAsync( DispatchPipe, new ArraySegment>(new [] { new ArraySegment(_pipeMessage) })); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Http/SocketOutputConsumer.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Http/SocketOutputConsumer.cs new file mode 100644 index 0000000000..af6b5e2220 --- /dev/null +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Http/SocketOutputConsumer.cs @@ -0,0 +1,138 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.IO.Pipelines; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; + +namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http +{ + public class SocketOutputConsumer + { + private readonly KestrelThread _thread; + private readonly UvStreamHandle _socket; + private readonly Connection _connection; + private readonly string _connectionId; + private readonly IKestrelTrace _log; + + private readonly WriteReqPool _writeReqPool; + private readonly IPipeReader _pipe; + + public SocketOutputConsumer( + IPipeReader pipe, + KestrelThread thread, + UvStreamHandle socket, + Connection connection, + string connectionId, + IKestrelTrace log) + { + _pipe = pipe; + // We need to have empty pipe at this moment so callback + // get's scheduled + _thread = thread; + _socket = socket; + _connection = connection; + _connectionId = connectionId; + _log = log; + _writeReqPool = thread.WriteReqPool; + + var ignore = StartWrites(); + } + + public async Task StartWrites() + { + while (true) + { + var result = await _pipe.ReadAsync(); + var buffer = result.Buffer; + + try + { + if (!buffer.IsEmpty) + { + var writeReq = _writeReqPool.Allocate(); + var writeResult = await writeReq.WriteAsync(_socket, buffer); + _writeReqPool.Return(writeReq); + + // REVIEW: Locking here, do we need to take the context lock? + OnWriteCompleted(writeResult.Status, writeResult.Error); + } + + if (result.IsCancelled) + { + // Send a FIN + await ShutdownAsync(); + } + + if (buffer.IsEmpty && result.IsCompleted) + { + break; + } + } + finally + { + _pipe.Advance(result.Buffer.End); + } + } + + // We're done reading + _pipe.Complete(); + + _socket.Dispose(); + _connection.OnSocketClosed(); + _log.ConnectionStop(_connectionId); + } + + private void OnWriteCompleted(int writeStatus, Exception writeError) + { + // Called inside _contextLock + var status = writeStatus; + var error = writeError; + + if (error != null) + { + // Abort the connection for any failed write + // Queued on threadpool so get it in as first op. + _connection.AbortAsync(); + } + + if (error == null) + { + _log.ConnectionWriteCallback(_connectionId, status); + } + else + { + // Log connection resets at a lower (Debug) level. + if (status == Constants.ECONNRESET) + { + _log.ConnectionReset(_connectionId); + } + else + { + _log.ConnectionError(_connectionId, error); + } + } + } + + private Task ShutdownAsync() + { + var tcs = new TaskCompletionSource(); + _log.ConnectionWriteFin(_connectionId); + + var shutdownReq = new UvShutdownReq(_log); + shutdownReq.Init(_thread.Loop); + shutdownReq.Shutdown(_socket, (req, status, state) => + { + req.Dispose(); + _log.ConnectionWroteFin(_connectionId, status); + + tcs.TrySetResult(null); + }, + this); + + return tcs.Task; + } + } +} diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/Constants.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Infrastructure/Constants.cs similarity index 59% rename from src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/Constants.cs rename to src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Infrastructure/Constants.cs index 0b7a9eaaa2..10836774a1 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/Constants.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Infrastructure/Constants.cs @@ -1,7 +1,6 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System.Net; using System.Runtime.InteropServices; namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure @@ -10,34 +9,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure { public const int ListenBacklog = 128; - public const int MaxExceptionDetailSize = 128; - public const int EOF = -4095; public static readonly int? ECONNRESET = GetECONNRESET(); public static readonly int? EADDRINUSE = GetEADDRINUSE(); - /// - /// The IPEndPoint Kestrel will bind to if nothing else is specified. - /// - public static readonly string DefaultServerAddress = "http://localhost:5000"; - - /// - /// Prefix of host name used to specify Unix sockets in the configuration. - /// - public const string UnixPipeHostPrefix = "unix:/"; - - /// - /// Prefix of host name used to specify pipe file descriptor in the configuration. - /// - public const string PipeDescriptorPrefix = "pipefd:"; - - /// - /// Prefix of host name used to specify socket descriptor in the configuration. - /// - public const string SocketDescriptorPrefix = "sockfd:"; - - public const string ServerName = "Kestrel"; - private static int? GetECONNRESET() { if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/KestrelEventSource.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Infrastructure/KestrelEventSource.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/KestrelEventSource.cs rename to src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Infrastructure/KestrelEventSource.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/KestrelThread.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Infrastructure/KestrelThread.cs similarity index 91% rename from src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/KestrelThread.cs rename to src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Infrastructure/KestrelThread.cs index 1c42ccd055..5978ce4f9a 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/KestrelThread.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Infrastructure/KestrelThread.cs @@ -23,7 +23,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal { public const long HeartbeatMilliseconds = 1000; - private static readonly Libuv.uv_walk_cb _heartbeatWalkCallback = (ptr, arg) => + private static readonly LibuvFunctions.uv_walk_cb _heartbeatWalkCallback = (ptr, arg) => { var streamHandle = UvMemory.FromIntPtr(ptr) as UvStreamHandle; var thisHandle = GCHandle.FromIntPtr(arg); @@ -53,7 +53,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal private bool _initCompleted = false; private ExceptionDispatchInfo _closeError; private readonly IKestrelTrace _log; - private readonly IThreadPool _threadPool; private readonly TimeSpan _shutdownTimeout; private IntPtr _thisPtr; @@ -62,8 +61,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal _engine = engine; _appLifetime = engine.AppLifetime; _log = engine.Log; - _threadPool = engine.ThreadPool; - _shutdownTimeout = engine.ServerOptions.ShutdownTimeout; + _shutdownTimeout = engine.TransportOptions.ShutdownTimeout; _loop = new UvLoopHandle(_log); _post = new UvAsyncHandle(_log); _thread = new Thread(ThreadStart); @@ -76,13 +74,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal #endif QueueCloseHandle = PostCloseHandle; QueueCloseAsyncHandle = EnqueueCloseHandle; - Memory = new MemoryPool(); PipelineFactory = new PipeFactory(); WriteReqPool = new WriteReqPool(this, _log); - ConnectionManager = new ConnectionManager(this, _threadPool); + ConnectionManager = new ConnectionManager(this); } + // For testing - internal KestrelThread(KestrelEngine engine, int maxLoops) + public KestrelThread(KestrelEngine engine, int maxLoops) : this(engine) { _maxLoops = maxLoops; @@ -90,8 +88,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal public UvLoopHandle Loop { get { return _loop; } } - public MemoryPool Memory { get; } - public PipeFactory PipelineFactory { get; } public ConnectionManager ConnectionManager { get; } @@ -193,7 +189,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal } finally { - Memory.Dispose(); PipelineFactory.Dispose(); } } @@ -267,7 +262,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal Walk((ptr, arg) => callback(ptr), IntPtr.Zero); } - private void Walk(Libuv.uv_walk_cb callback, IntPtr arg) + private void Walk(LibuvFunctions.uv_walk_cb callback, IntPtr arg) { _engine.Libuv.walk( _loop, @@ -387,14 +382,34 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal work.CallbackAdapter(work.Callback, work.State); if (work.Completion != null) { - _threadPool.Complete(work.Completion); + ThreadPool.QueueUserWorkItem(o => + { + try + { + ((TaskCompletionSource)o).SetResult(null); + } + catch (Exception e) + { + _log.LogError(0, e, "KestrelThread.DoPostWork"); + } + }, work.Completion); } } catch (Exception ex) { if (work.Completion != null) { - _threadPool.Error(work.Completion, ex); + ThreadPool.QueueUserWorkItem(o => + { + try + { + ((TaskCompletionSource)o).TrySetException(ex); + } + catch (Exception e) + { + _log.LogError(0, e, "KestrelThread.DoPostWork"); + } + }, work.Completion); } else { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/LibuvAwaitable.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Infrastructure/LibuvAwaitable.cs similarity index 99% rename from src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/LibuvAwaitable.cs rename to src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Infrastructure/LibuvAwaitable.cs index 8fc241858f..110c1316f1 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/LibuvAwaitable.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Infrastructure/LibuvAwaitable.cs @@ -2,10 +2,9 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. using System; -using System.Net; -using System.Threading.Tasks; using System.Runtime.CompilerServices; using System.Threading; +using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/WriteReqPool.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Infrastructure/WriteReqPool.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/WriteReqPool.cs rename to src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Infrastructure/WriteReqPool.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvTransportContext.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvTransportContext.cs new file mode 100644 index 0000000000..5a94ff302d --- /dev/null +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvTransportContext.cs @@ -0,0 +1,19 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; + +namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal +{ + public class LibuvTransportContext + { + public LibuvTransportOptions Options { get; set; } + + public IApplicationLifetime AppLifetime { get; set; } + + public IKestrelTrace Log { get; set; } + + public IConnectionHandler ConnectionHandler { get; set; } + } +} diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/Libuv.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/Libuv.cs similarity index 99% rename from src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/Libuv.cs rename to src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/Libuv.cs index 21ed915e9f..b527524b6c 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/Libuv.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/Libuv.cs @@ -7,9 +7,9 @@ using System.Runtime.InteropServices; namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking { - public class Libuv + public class LibuvFunctions { - public Libuv() + public LibuvFunctions() { IsWindows = PlatformApis.IsWindows; @@ -60,7 +60,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking } // Second ctor that doesn't set any fields only to be used by MockLibuv - internal Libuv(bool onlyForTesting) + public LibuvFunctions(bool onlyForTesting) { } @@ -305,7 +305,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking unsafe protected delegate int uv_write2_func(UvRequest req, UvStreamHandle handle, uv_buf_t* bufs, int nbufs, UvStreamHandle sendHandle, uv_write_cb cb); protected uv_write2_func _uv_write2; - unsafe public void write2(UvRequest req, UvStreamHandle handle, Libuv.uv_buf_t* bufs, int nbufs, UvStreamHandle sendHandle, uv_write_cb cb) + unsafe public void write2(UvRequest req, UvStreamHandle handle, uv_buf_t* bufs, int nbufs, UvStreamHandle sendHandle, uv_write_cb cb) { req.Validate(); handle.Validate(); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/PlatformApis.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/PlatformApis.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/PlatformApis.cs rename to src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/PlatformApis.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/SockAddr.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/SockAddr.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/SockAddr.cs rename to src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/SockAddr.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/UvAsyncHandle.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvAsyncHandle.cs similarity index 88% rename from src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/UvAsyncHandle.cs rename to src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvAsyncHandle.cs index da0ae7c3d4..d1260b93c2 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/UvAsyncHandle.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvAsyncHandle.cs @@ -10,9 +10,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking { public class UvAsyncHandle : UvHandle { - private static readonly Libuv.uv_close_cb _destroyMemory = (handle) => DestroyMemory(handle); + private static readonly LibuvFunctions.uv_close_cb _destroyMemory = (handle) => DestroyMemory(handle); - private static readonly Libuv.uv_async_cb _uv_async_cb = (handle) => AsyncCb(handle); + private static readonly LibuvFunctions.uv_async_cb _uv_async_cb = (handle) => AsyncCb(handle); private Action _callback; private Action, IntPtr> _queueCloseHandle; @@ -25,7 +25,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking CreateMemory( loop.Libuv, loop.ThreadId, - loop.Libuv.handle_size(Libuv.HandleType.ASYNC)); + loop.Libuv.handle_size(LibuvFunctions.HandleType.ASYNC)); _callback = callback; _queueCloseHandle = queueCloseHandle; diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/UvConnectRequest.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvConnectRequest.cs similarity index 90% rename from src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/UvConnectRequest.cs rename to src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvConnectRequest.cs index 85df07621d..86f0312610 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/UvConnectRequest.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvConnectRequest.cs @@ -12,7 +12,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking /// public class UvConnectRequest : UvRequest { - private readonly static Libuv.uv_connect_cb _uv_connect_cb = (req, status) => UvConnectCb(req, status); + private readonly static LibuvFunctions.uv_connect_cb _uv_connect_cb = (req, status) => UvConnectCb(req, status); private Action _callback; private object _state; @@ -23,7 +23,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking public void Init(UvLoopHandle loop) { - var requestSize = loop.Libuv.req_size(Libuv.RequestType.CONNECT); + var requestSize = loop.Libuv.req_size(LibuvFunctions.RequestType.CONNECT); CreateMemory( loop.Libuv, loop.ThreadId, diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/UvException.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvException.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/UvException.cs rename to src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvException.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/UvHandle.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvHandle.cs similarity index 93% rename from src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/UvHandle.cs rename to src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvHandle.cs index 0203ac610c..a5ce314bdc 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/UvHandle.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvHandle.cs @@ -10,7 +10,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking { public abstract class UvHandle : UvMemory { - private static readonly Libuv.uv_close_cb _destroyMemory = (handle) => DestroyMemory(handle); + private static readonly LibuvFunctions.uv_close_cb _destroyMemory = (handle) => DestroyMemory(handle); private Action, IntPtr> _queueCloseHandle; protected UvHandle(IKestrelTrace logger) : base (logger) @@ -18,7 +18,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking } protected void CreateHandle( - Libuv uv, + LibuvFunctions uv, int threadId, int size, Action, IntPtr> queueCloseHandle) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/UvLoopHandle.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvLoopHandle.cs similarity index 96% rename from src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/UvLoopHandle.cs rename to src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvLoopHandle.cs index cbb654ccd1..b825c4eb7a 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/UvLoopHandle.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvLoopHandle.cs @@ -13,7 +13,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking { } - public void Init(Libuv uv) + public void Init(LibuvFunctions uv) { CreateMemory( uv, diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/UvMemory.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvMemory.cs similarity index 91% rename from src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/UvMemory.cs rename to src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvMemory.cs index 5b490ada94..3fb078ac17 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/UvMemory.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvMemory.cs @@ -14,7 +14,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking /// public abstract class UvMemory : SafeHandle { - protected Libuv _uv; + protected LibuvFunctions _uv; protected int _threadId; protected readonly IKestrelTrace _log; @@ -23,7 +23,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking _log = logger; } - public Libuv Libuv { get { return _uv; } } + public LibuvFunctions Libuv { get { return _uv; } } public override bool IsInvalid { @@ -45,7 +45,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking } } - unsafe protected void CreateMemory(Libuv uv, int threadId, int size) + unsafe protected void CreateMemory(LibuvFunctions uv, int threadId, int size) { _uv = uv; ThreadId = threadId; @@ -70,7 +70,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking Marshal.FreeCoTaskMem(memory); } - internal IntPtr InternalGetHandle() + public IntPtr InternalGetHandle() { return handle; } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/UvPipeHandle.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvPipeHandle.cs similarity index 90% rename from src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/UvPipeHandle.cs rename to src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvPipeHandle.cs index ef2d2d9bea..b4f479d7ca 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/UvPipeHandle.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvPipeHandle.cs @@ -17,7 +17,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking CreateHandle( loop.Libuv, loop.ThreadId, - loop.Libuv.handle_size(Libuv.HandleType.NAMED_PIPE), queueCloseHandle); + loop.Libuv.handle_size(LibuvFunctions.HandleType.NAMED_PIPE), queueCloseHandle); _uv.pipe_init(loop, this, ipc); } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/UvRequest.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvRequest.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/UvRequest.cs rename to src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvRequest.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/UvShutdownReq.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvShutdownReq.cs similarity index 88% rename from src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/UvShutdownReq.cs rename to src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvShutdownReq.cs index f69937e5b8..fb01064025 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/UvShutdownReq.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvShutdownReq.cs @@ -11,7 +11,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking /// public class UvShutdownReq : UvRequest { - private readonly static Libuv.uv_shutdown_cb _uv_shutdown_cb = UvShutdownCb; + private readonly static LibuvFunctions.uv_shutdown_cb _uv_shutdown_cb = UvShutdownCb; private Action _callback; private object _state; @@ -25,7 +25,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking CreateMemory( loop.Libuv, loop.ThreadId, - loop.Libuv.req_size(Libuv.RequestType.SHUTDOWN)); + loop.Libuv.req_size(LibuvFunctions.RequestType.SHUTDOWN)); } public void Shutdown(UvStreamHandle handle, Action callback, object state) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/UvStreamHandle.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvStreamHandle.cs similarity index 86% rename from src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/UvStreamHandle.cs rename to src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvStreamHandle.cs index 698a693c60..9b9af056cf 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/UvStreamHandle.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvStreamHandle.cs @@ -11,16 +11,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking { public abstract class UvStreamHandle : UvHandle { - private readonly static Libuv.uv_connection_cb _uv_connection_cb = (handle, status) => UvConnectionCb(handle, status); + private readonly static LibuvFunctions.uv_connection_cb _uv_connection_cb = (handle, status) => UvConnectionCb(handle, status); // Ref and out lamda params must be explicitly typed - private readonly static Libuv.uv_alloc_cb _uv_alloc_cb = (IntPtr handle, int suggested_size, out Libuv.uv_buf_t buf) => UvAllocCb(handle, suggested_size, out buf); - private readonly static Libuv.uv_read_cb _uv_read_cb = (IntPtr handle, int status, ref Libuv.uv_buf_t buf) => UvReadCb(handle, status, ref buf); + private readonly static LibuvFunctions.uv_alloc_cb _uv_alloc_cb = (IntPtr handle, int suggested_size, out LibuvFunctions.uv_buf_t buf) => UvAllocCb(handle, suggested_size, out buf); + private readonly static LibuvFunctions.uv_read_cb _uv_read_cb = (IntPtr handle, int status, ref LibuvFunctions.uv_buf_t buf) => UvReadCb(handle, status, ref buf); private Action _listenCallback; private object _listenState; private GCHandle _listenVitality; - private Func _allocCallback; + private Func _allocCallback; private Action _readCallback; private object _readState; private GCHandle _readVitality; @@ -75,7 +75,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking } public void ReadStart( - Func allocCallback, + Func allocCallback, Action readCallback, object state) { @@ -118,7 +118,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking _uv.read_stop(this); } - public int TryWrite(Libuv.uv_buf_t buf) + public int TryWrite(LibuvFunctions.uv_buf_t buf) { return _uv.try_write(this, new[] { buf }, 1); } @@ -141,7 +141,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking } } - private static void UvAllocCb(IntPtr handle, int suggested_size, out Libuv.uv_buf_t buf) + private static void UvAllocCb(IntPtr handle, int suggested_size, out LibuvFunctions.uv_buf_t buf) { var stream = FromIntPtr(handle); try @@ -156,7 +156,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking } } - private static void UvReadCb(IntPtr handle, int status, ref Libuv.uv_buf_t buf) + private static void UvReadCb(IntPtr handle, int status, ref LibuvFunctions.uv_buf_t buf) { var stream = FromIntPtr(handle); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/UvTcpHandle.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvTcpHandle.cs similarity index 95% rename from src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/UvTcpHandle.cs rename to src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvTcpHandle.cs index 402f2f37cd..5f124518c1 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/UvTcpHandle.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvTcpHandle.cs @@ -2,7 +2,6 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.Diagnostics; using System.Net; using System.Runtime.InteropServices; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; @@ -20,7 +19,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking CreateHandle( loop.Libuv, loop.ThreadId, - loop.Libuv.handle_size(Libuv.HandleType.TCP), queueCloseHandle); + loop.Libuv.handle_size(LibuvFunctions.HandleType.TCP), queueCloseHandle); _uv.tcp_init(loop, this); } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/UvTimerHandle.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvTimerHandle.cs similarity index 90% rename from src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/UvTimerHandle.cs rename to src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvTimerHandle.cs index efed9ab59c..62501c6c98 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/UvTimerHandle.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvTimerHandle.cs @@ -9,7 +9,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking { public class UvTimerHandle : UvHandle { - private readonly static Libuv.uv_timer_cb _uv_timer_cb = UvTimerCb; + private readonly static LibuvFunctions.uv_timer_cb _uv_timer_cb = UvTimerCb; private Action _callback; @@ -22,7 +22,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking CreateHandle( loop.Libuv, loop.ThreadId, - loop.Libuv.handle_size(Libuv.HandleType.TIMER), + loop.Libuv.handle_size(LibuvFunctions.HandleType.TIMER), queueCloseHandle); _uv.timer_init(loop, this); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/UvWriteReq.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvWriteReq.cs similarity index 91% rename from src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/UvWriteReq.cs rename to src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvWriteReq.cs index 673c92bd94..5462d2a2d4 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/UvWriteReq.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvWriteReq.cs @@ -16,7 +16,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking /// public class UvWriteReq : UvRequest { - private static readonly Libuv.uv_write_cb _uv_write_cb = (IntPtr ptr, int status) => UvWriteCb(ptr, status); + private static readonly LibuvFunctions.uv_write_cb _uv_write_cb = (IntPtr ptr, int status) => UvWriteCb(ptr, status); private IntPtr _bufs; @@ -34,8 +34,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking public void Init(UvLoopHandle loop) { - var requestSize = loop.Libuv.req_size(Libuv.RequestType.WRITE); - var bufferSize = Marshal.SizeOf() * BUFFER_COUNT; + var requestSize = loop.Libuv.req_size(LibuvFunctions.RequestType.WRITE); + var bufferSize = Marshal.SizeOf() * BUFFER_COUNT; CreateMemory( loop.Libuv, loop.ThreadId, @@ -79,14 +79,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking } } - var pBuffers = (Libuv.uv_buf_t*)_bufs; + var pBuffers = (LibuvFunctions.uv_buf_t*)_bufs; if (nBuffers > BUFFER_COUNT) { // create and pin buffer array when it's larger than the pre-allocated one - var bufArray = new Libuv.uv_buf_t[nBuffers]; + var bufArray = new LibuvFunctions.uv_buf_t[nBuffers]; var gcHandle = GCHandle.Alloc(bufArray, GCHandleType.Pinned); _pins.Add(gcHandle); - pBuffers = (Libuv.uv_buf_t*)gcHandle.AddrOfPinnedObject(); + pBuffers = (LibuvFunctions.uv_buf_t*)gcHandle.AddrOfPinnedObject(); } if (nBuffers == 1) @@ -161,15 +161,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking // add GCHandle to keeps this SafeHandle alive while request processing _pins.Add(GCHandle.Alloc(this, GCHandleType.Normal)); - var pBuffers = (Libuv.uv_buf_t*)_bufs; + var pBuffers = (LibuvFunctions.uv_buf_t*)_bufs; var nBuffers = bufs.Count; if (nBuffers > BUFFER_COUNT) { // create and pin buffer array when it's larger than the pre-allocated one - var bufArray = new Libuv.uv_buf_t[nBuffers]; + var bufArray = new LibuvFunctions.uv_buf_t[nBuffers]; var gcHandle = GCHandle.Alloc(bufArray, GCHandleType.Pinned); _pins.Add(gcHandle); - pBuffers = (Libuv.uv_buf_t*)gcHandle.AddrOfPinnedObject(); + pBuffers = (LibuvFunctions.uv_buf_t*)gcHandle.AddrOfPinnedObject(); } for (var index = 0; index < nBuffers; index++) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/KestrelEngine.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/KestrelEngine.cs new file mode 100644 index 0000000000..d4d9a48d85 --- /dev/null +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/KestrelEngine.cs @@ -0,0 +1,143 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; +using Microsoft.AspNetCore.Server.Kestrel.Transport; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Exceptions; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal; +using Microsoft.Extensions.Logging; + +namespace Microsoft.AspNetCore.Server.Kestrel.Internal +{ + public class KestrelEngine : ITransport + { + private readonly ListenOptions _listenOptions; + + private readonly List _listeners = new List(); + + public KestrelEngine(LibuvTransportContext context, ListenOptions listenOptions) + : this(new LibuvFunctions(), context, listenOptions) + { } + + // For testing + public KestrelEngine(LibuvFunctions uv, LibuvTransportContext context, ListenOptions listenOptions) + { + Libuv = uv; + TransportContext = context; + + _listenOptions = listenOptions; + } + + public LibuvFunctions Libuv { get; } + public LibuvTransportContext TransportContext { get; } + public List Threads { get; } = new List(); + + public IApplicationLifetime AppLifetime => TransportContext.AppLifetime; + public IKestrelTrace Log => TransportContext.Log; + public LibuvTransportOptions TransportOptions => TransportContext.Options; + + public async Task StopAsync() + { + try + { + await Task.WhenAll(Threads.Select(thread => thread.StopAsync(TimeSpan.FromSeconds(2.5))).ToArray()) + .ConfigureAwait(false); + } + catch (AggregateException aggEx) + { + // An uncaught exception was likely thrown from the libuv event loop. + // The original error that crashed one loop may have caused secondary errors in others. + // Make sure that the stack trace of the original error is logged. + foreach (var ex in aggEx.InnerExceptions) + { + Log.LogCritical("Failed to gracefully close Kestrel.", ex); + } + + throw; + } + + Threads.Clear(); +#if DEBUG + GC.Collect(); + GC.WaitForPendingFinalizers(); + GC.Collect(); +#endif + } + + public async Task BindAsync() + { + // TODO: Move thread management to LibuvTransportFactory + // TODO: Split endpoint management from thread management + for (var index = 0; index < TransportOptions.ThreadCount; index++) + { + Threads.Add(new KestrelThread(this)); + } + + foreach (var thread in Threads) + { + await thread.StartAsync().ConfigureAwait(false); + } + + try + { + if (TransportOptions.ThreadCount == 1) + { + var listener = new Listener(TransportContext); + _listeners.Add(listener); + await listener.StartAsync(_listenOptions, Threads[0]).ConfigureAwait(false); + } + else + { + var pipeName = (Libuv.IsWindows ? @"\\.\pipe\kestrel_" : "/tmp/kestrel_") + Guid.NewGuid().ToString("n"); + var pipeMessage = Guid.NewGuid().ToByteArray(); + + var listenerPrimary = new ListenerPrimary(TransportContext); + _listeners.Add(listenerPrimary); + await listenerPrimary.StartAsync(pipeName, pipeMessage, _listenOptions, Threads[0]).ConfigureAwait(false); + + foreach (var thread in Threads.Skip(1)) + { + var listenerSecondary = new ListenerSecondary(TransportContext); + _listeners.Add(listenerSecondary); + await listenerSecondary.StartAsync(pipeName, pipeMessage, _listenOptions, thread).ConfigureAwait(false); + } + } + } + catch (UvException ex) when (ex.StatusCode == Constants.EADDRINUSE) + { + await UnbindAsync().ConfigureAwait(false); + throw new AddressInUseException(ex.Message, ex); + } + catch + { + await UnbindAsync().ConfigureAwait(false); + throw; + } + } + + public async Task UnbindAsync() + { + var disposeTasks = _listeners.Select(listener => listener.DisposeAsync()).ToArray(); + + if (!await WaitAsync(Task.WhenAll(disposeTasks), TimeSpan.FromSeconds(2.5)).ConfigureAwait(false)) + { + Log.LogError(0, null, "Disposing listeners failed"); + } + + _listeners.Clear(); + } + + private static async Task WaitAsync(Task task, TimeSpan timeout) + { + return await Task.WhenAny(task, Task.Delay(timeout)).ConfigureAwait(false) == task; + } + } +} diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/LibuvTransportFactory.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/LibuvTransportFactory.cs new file mode 100644 index 0000000000..8985247f95 --- /dev/null +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/LibuvTransportFactory.cs @@ -0,0 +1,81 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Server.Kestrel.Internal; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal; +using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Options; + +namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv +{ + public class LibuvTransportFactory : ITransportFactory + { + private readonly LibuvTransportContext _baseTransportContext; + + public LibuvTransportFactory( + IOptions options, + IApplicationLifetime applicationLifetime, + ILoggerFactory loggerFactory) + { + if (options == null) + { + throw new ArgumentNullException(nameof(options)); + } + if (applicationLifetime == null) + { + throw new ArgumentNullException(nameof(applicationLifetime)); + } + if (loggerFactory == null) + { + throw new ArgumentNullException(nameof(loggerFactory)); + } + + // REVIEW: Should we change the logger namespace for transport logs? + var logger = loggerFactory.CreateLogger("Microsoft.AspNetCore.Server.Kestrel"); + // TODO: Add LibuvTrace + var trace = new KestrelTrace(logger); + + var threadCount = options.Value.ThreadCount; + + if (threadCount <= 0) + { + throw new ArgumentOutOfRangeException(nameof(threadCount), + threadCount, + "ThreadCount must be positive."); + } + + if (!Constants.ECONNRESET.HasValue) + { + trace.LogWarning("Unable to determine ECONNRESET value on this platform."); + } + + if (!Constants.EADDRINUSE.HasValue) + { + trace.LogWarning("Unable to determine EADDRINUSE value on this platform."); + } + + _baseTransportContext = new LibuvTransportContext + { + Options = options.Value, + AppLifetime = applicationLifetime, + Log = trace, + }; + } + + public ITransport Create(ListenOptions listenOptions, IConnectionHandler handler) + { + var transportContext = new LibuvTransportContext + { + Options = _baseTransportContext.Options, + AppLifetime = _baseTransportContext.AppLifetime, + Log = _baseTransportContext.Log, + ConnectionHandler = handler + }; + + return new KestrelEngine(transportContext, listenOptions); + } + } +} diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/LibuvTransportOptions.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/LibuvTransportOptions.cs new file mode 100644 index 0000000000..974607d8a9 --- /dev/null +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/LibuvTransportOptions.cs @@ -0,0 +1,58 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; + +namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv +{ + /// + /// Provides programmatic configuration of Libuv transport features. + /// + public class LibuvTransportOptions + { + /// + /// The number of libuv I/O threads used to process requests. + /// + /// + /// Defaults to half of rounded down and clamped between 1 and 16. + /// + public int ThreadCount { get; set; } = ProcessorThreadCount; + + // TODO: Move all shutdown timeout logic back into core project. + /// + /// The amount of time after the server begins shutting down before connections will be forcefully closed. + /// Kestrel will wait for the duration of the timeout for any ongoing request processing to complete before + /// terminating the connection. No new connections or requests will be accepted during this time. + /// + /// + /// Defaults to 5 seconds. + /// + public TimeSpan ShutdownTimeout { get; set; } = TimeSpan.FromSeconds(5); + + private static int ProcessorThreadCount + { + get + { + // Actual core count would be a better number + // rather than logical cores which includes hyper-threaded cores. + // Divide by 2 for hyper-threading, and good defaults (still need threads to do webserving). + var threadCount = Environment.ProcessorCount >> 1; + + if (threadCount < 1) + { + // Ensure shifted value is at least one + return 1; + } + + if (threadCount > 16) + { + // Receive Side Scaling RSS Processor count currently maxes out at 16 + // would be better to check the NIC's current hardware queues; but xplat... + return 16; + } + + return threadCount; + } + } + } +} diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.csproj b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.csproj new file mode 100644 index 0000000000..a9a71f3970 --- /dev/null +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.csproj @@ -0,0 +1,24 @@ + + + + + + Libuv transport for the ASP.NET Core Kestrel cross-platform web server. + netstandard1.3;net46 + true + aspnetcore;kestrel + true + CS1591;$(NoWarn) + false + + + + + + + + + + + + diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/WebHostBuilderLibuvExtensions.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/WebHostBuilderLibuvExtensions.cs new file mode 100644 index 0000000000..0cfa830f99 --- /dev/null +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/WebHostBuilderLibuvExtensions.cs @@ -0,0 +1,50 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using Microsoft.AspNetCore.Server.Kestrel.Transport; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv; +using Microsoft.Extensions.DependencyInjection; + +namespace Microsoft.AspNetCore.Hosting +{ + public static class WebHostBuilderLibuvExtensions + { + /// + /// Specify Libuv as the transport to be used by Kestrel. + /// + /// + /// The Microsoft.AspNetCore.Hosting.IWebHostBuilder to configure. + /// + /// + /// The Microsoft.AspNetCore.Hosting.IWebHostBuilder. + /// + public static IWebHostBuilder UseLibuv(this IWebHostBuilder hostBuilder) + { + return hostBuilder.ConfigureServices(services => + { + services.AddSingleton(); + }); + } + + /// + /// Specify Libuv as the transport to be used by Kestrel. + /// + /// + /// The Microsoft.AspNetCore.Hosting.IWebHostBuilder to configure. + /// + /// + /// A callback to configure Libuv options. + /// + /// + /// The Microsoft.AspNetCore.Hosting.IWebHostBuilder. + /// + public static IWebHostBuilder UseLibuv(this IWebHostBuilder hostBuilder, Action options) + { + return hostBuilder.UseLibuv().ConfigureServices(services => + { + services.Configure(options); + }); + } + } +} diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Connection.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Connection.cs deleted file mode 100644 index dfa0810dc0..0000000000 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Connection.cs +++ /dev/null @@ -1,432 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.IO; -using System.IO.Pipelines; -using System.Threading; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Server.Kestrel.Adapter; -using Microsoft.AspNetCore.Server.Kestrel.Adapter.Internal; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; -using Microsoft.Extensions.Internal; -using Microsoft.Extensions.Logging; - -namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http -{ - public class Connection : ConnectionContext, IConnectionControl - { - private const int MinAllocBufferSize = 2048; - - // Base32 encoding - in ascii sort order for easy text based sorting - private static readonly string _encode32Chars = "0123456789ABCDEFGHIJKLMNOPQRSTUV"; - - private static readonly Action _readCallback = - (handle, status, state) => ReadCallback(handle, status, state); - - private static readonly Func _allocCallback = - (handle, suggestedsize, state) => AllocCallback(handle, suggestedsize, state); - - // Seed the _lastConnectionId for this application instance with - // the number of 100-nanosecond intervals that have elapsed since 12:00:00 midnight, January 1, 0001 - // for a roughly increasing _requestId over restarts - private static long _lastConnectionId = DateTime.UtcNow.Ticks; - - private readonly UvStreamHandle _socket; - private readonly Frame _frame; - private readonly List _connectionAdapters; - private AdaptedPipeline _adaptedPipeline; - private Stream _filteredStream; - private Task _readInputTask; - - private TaskCompletionSource _socketClosedTcs = new TaskCompletionSource(); - - private long _lastTimestamp; - private long _timeoutTimestamp = long.MaxValue; - private TimeoutAction _timeoutAction; - private WritableBuffer? _currentWritableBuffer; - - public Connection(ListenerContext context, UvStreamHandle socket) : base(context) - { - _socket = socket; - _connectionAdapters = context.ListenOptions.ConnectionAdapters; - socket.Connection = this; - ConnectionControl = this; - - ConnectionId = GenerateConnectionId(Interlocked.Increment(ref _lastConnectionId)); - - Input = Thread.PipelineFactory.Create(ListenerContext.LibuvInputPipeOptions); - var outputPipe = Thread.PipelineFactory.Create(ListenerContext.LibuvOutputPipeOptions); - Output = new SocketOutput(outputPipe, Thread, _socket, this, ConnectionId, Log); - - var tcpHandle = _socket as UvTcpHandle; - if (tcpHandle != null) - { - RemoteEndPoint = tcpHandle.GetPeerIPEndPoint(); - LocalEndPoint = tcpHandle.GetSockIPEndPoint(); - } - - _frame = FrameFactory(this); - _lastTimestamp = Thread.Loop.Now(); - } - - // Internal for testing - internal Connection() - { - } - - public KestrelServerOptions ServerOptions => ListenerContext.ServiceContext.ServerOptions; - private Func FrameFactory => ListenerContext.ServiceContext.FrameFactory; - private IKestrelTrace Log => ListenerContext.ServiceContext.Log; - private IThreadPool ThreadPool => ListenerContext.ServiceContext.ThreadPool; - private KestrelThread Thread => ListenerContext.Thread; - - public void Start() - { - Log.ConnectionStart(ConnectionId); - KestrelEventSource.Log.ConnectionStart(this); - - // Start socket prior to applying the ConnectionAdapter - _socket.ReadStart(_allocCallback, _readCallback, this); - - // Dispatch to a thread pool so if the first read completes synchronously - // we won't be on IO thread - try - { - ThreadPool.UnsafeRun(state => ((Connection)state).StartFrame(), this); - } - catch (Exception e) - { - Log.LogError(0, e, "Connection.StartFrame"); - throw; - } - } - - private void StartFrame() - { - if (_connectionAdapters.Count == 0) - { - _frame.Start(); - } - else - { - // ApplyConnectionAdaptersAsync should never throw. If it succeeds, it will call _frame.Start(). - // Otherwise, it will close the connection. - var ignore = ApplyConnectionAdaptersAsync(); - } - } - - public Task StopAsync() - { - return Task.WhenAll(_frame.StopAsync(), _socketClosedTcs.Task); - } - - public virtual Task AbortAsync(Exception error = null) - { - // Frame.Abort calls user code while this method is always - // called from a libuv thread. - ThreadPool.Run(() => - { - _frame.Abort(error); - }); - - return _socketClosedTcs.Task; - } - - // Called on Libuv thread - public virtual void OnSocketClosed() - { - KestrelEventSource.Log.ConnectionStop(this); - - _frame.FrameStartedTask.ContinueWith((task, state) => - { - var connection = (Connection)state; - - if (connection._adaptedPipeline != null) - { - Task.WhenAll(connection._readInputTask, connection._frame.StopAsync()).ContinueWith((task2, state2) => - { - var connection2 = (Connection)state2; - connection2._filteredStream.Dispose(); - connection2._adaptedPipeline.Dispose(); - Input.Reader.Complete(); - }, connection); - } - }, this); - - Input.Writer.Complete(new TaskCanceledException("The request was aborted")); - _socketClosedTcs.TrySetResult(null); - } - - // Called on Libuv thread - public void Tick(long timestamp) - { - if (timestamp > PlatformApis.VolatileRead(ref _timeoutTimestamp)) - { - ConnectionControl.CancelTimeout(); - - if (_timeoutAction == TimeoutAction.SendTimeoutResponse) - { - _frame.SetBadRequestState(RequestRejectionReason.RequestTimeout); - } - - StopAsync(); - } - - Interlocked.Exchange(ref _lastTimestamp, timestamp); - } - - private async Task ApplyConnectionAdaptersAsync() - { - try - { - var rawStream = new RawStream(Input.Reader, Output); - var adapterContext = new ConnectionAdapterContext(rawStream); - var adaptedConnections = new IAdaptedConnection[_connectionAdapters.Count]; - - for (var i = 0; i < _connectionAdapters.Count; i++) - { - var adaptedConnection = await _connectionAdapters[i].OnConnectionAsync(adapterContext); - adaptedConnections[i] = adaptedConnection; - adapterContext = new ConnectionAdapterContext(adaptedConnection.ConnectionStream); - } - - if (adapterContext.ConnectionStream != rawStream) - { - _filteredStream = adapterContext.ConnectionStream; - _adaptedPipeline = new AdaptedPipeline( - adapterContext.ConnectionStream, - Thread.PipelineFactory.Create(ListenerContext.AdaptedPipeOptions), - Thread.PipelineFactory.Create(ListenerContext.AdaptedPipeOptions)); - - _frame.Input = _adaptedPipeline.Input; - _frame.Output = _adaptedPipeline.Output; - - // Don't attempt to read input if connection has already closed. - // This can happen if a client opens a connection and immediately closes it. - _readInputTask = _socketClosedTcs.Task.Status == TaskStatus.WaitingForActivation - ? _adaptedPipeline.StartAsync() - : TaskCache.CompletedTask; - } - - _frame.AdaptedConnections = adaptedConnections; - _frame.Start(); - } - catch (Exception ex) - { - Log.LogError(0, ex, $"Uncaught exception from the {nameof(IConnectionAdapter.OnConnectionAsync)} method of an {nameof(IConnectionAdapter)}."); - Input.Reader.Complete(); - ConnectionControl.End(ProduceEndType.SocketDisconnect); - } - } - - private static Libuv.uv_buf_t AllocCallback(UvStreamHandle handle, int suggestedSize, object state) - { - return ((Connection)state).OnAlloc(handle, suggestedSize); - } - - private unsafe Libuv.uv_buf_t OnAlloc(UvStreamHandle handle, int suggestedSize) - { - Debug.Assert(_currentWritableBuffer == null); - var currentWritableBuffer = Input.Writer.Alloc(MinAllocBufferSize); - _currentWritableBuffer = currentWritableBuffer; - void* dataPtr; - var tryGetPointer = currentWritableBuffer.Buffer.TryGetPointer(out dataPtr); - Debug.Assert(tryGetPointer); - - return handle.Libuv.buf_init( - (IntPtr)dataPtr, - currentWritableBuffer.Buffer.Length); - } - - private static void ReadCallback(UvStreamHandle handle, int status, object state) - { - ((Connection)state).OnRead(handle, status); - } - - private async void OnRead(UvStreamHandle handle, int status) - { - var normalRead = status >= 0; - var normalDone = status == Constants.EOF; - var errorDone = !(normalDone || normalRead); - var readCount = normalRead ? status : 0; - - if (normalRead) - { - Log.ConnectionRead(ConnectionId, readCount); - } - else - { - _socket.ReadStop(); - - if (normalDone) - { - Log.ConnectionReadFin(ConnectionId); - } - } - - IOException error = null; - WritableBufferAwaitable? flushTask = null; - if (errorDone) - { - Exception uvError; - handle.Libuv.Check(status, out uvError); - - // Log connection resets at a lower (Debug) level. - if (status == Constants.ECONNRESET) - { - Log.ConnectionReset(ConnectionId); - } - else - { - Log.ConnectionError(ConnectionId, uvError); - } - - error = new IOException(uvError.Message, uvError); - _currentWritableBuffer?.Commit(); - } - else - { - Debug.Assert(_currentWritableBuffer != null); - - var currentWritableBuffer = _currentWritableBuffer.Value; - currentWritableBuffer.Advance(readCount); - flushTask = currentWritableBuffer.FlushAsync(); - } - - _currentWritableBuffer = null; - if (flushTask?.IsCompleted == false) - { - OnPausePosted(); - var result = await flushTask.Value; - // If the reader isn't complete then resume - if (!result.IsCompleted) - { - OnResumePosted(); - } - } - - if (!normalRead) - { - Input.Writer.Complete(error); - var ignore = AbortAsync(error); - } - } - - void IConnectionControl.Pause() - { - Log.ConnectionPause(ConnectionId); - - // Even though this method is called on the event loop already, - // post anyway so the ReadStop() call doesn't get reordered - // relative to the ReadStart() call made in Resume(). - Thread.Post(state => state.OnPausePosted(), this); - } - - void IConnectionControl.Resume() - { - Log.ConnectionResume(ConnectionId); - - // This is called from the consuming thread. - Thread.Post(state => state.OnResumePosted(), this); - } - - private void OnPausePosted() - { - // It's possible that uv_close was called between the call to Thread.Post() and now. - if (!_socket.IsClosed) - { - _socket.ReadStop(); - } - } - - private void OnResumePosted() - { - // It's possible that uv_close was called even before the call to Resume(). - if (!_socket.IsClosed) - { - try - { - _socket.ReadStart(_allocCallback, _readCallback, this); - } - catch (UvException) - { - // ReadStart() can throw a UvException in some cases (e.g. socket is no longer connected). - // This should be treated the same as OnRead() seeing a "normalDone" condition. - Log.ConnectionReadFin(ConnectionId); - Input.Writer.Complete(); - } - } - } - - void IConnectionControl.End(ProduceEndType endType) - { - switch (endType) - { - case ProduceEndType.ConnectionKeepAlive: - Log.ConnectionKeepAlive(ConnectionId); - break; - case ProduceEndType.SocketShutdown: - case ProduceEndType.SocketDisconnect: - Log.ConnectionDisconnect(ConnectionId); - ((SocketOutput)Output).End(endType); - break; - } - } - - void IConnectionControl.SetTimeout(long milliseconds, TimeoutAction timeoutAction) - { - Debug.Assert(_timeoutTimestamp == long.MaxValue, "Concurrent timeouts are not supported"); - - AssignTimeout(milliseconds, timeoutAction); - } - - void IConnectionControl.ResetTimeout(long milliseconds, TimeoutAction timeoutAction) - { - AssignTimeout(milliseconds, timeoutAction); - } - - void IConnectionControl.CancelTimeout() - { - Interlocked.Exchange(ref _timeoutTimestamp, long.MaxValue); - } - - private void AssignTimeout(long milliseconds, TimeoutAction timeoutAction) - { - _timeoutAction = timeoutAction; - - // Add KestrelThread.HeartbeatMilliseconds extra milliseconds since this can be called right before the next heartbeat. - Interlocked.Exchange(ref _timeoutTimestamp, _lastTimestamp + milliseconds + KestrelThread.HeartbeatMilliseconds); - } - - private static unsafe string GenerateConnectionId(long id) - { - // The following routine is ~310% faster than calling long.ToString() on x64 - // and ~600% faster than calling long.ToString() on x86 in tight loops of 1 million+ iterations - // See: https://github.com/aspnet/Hosting/pull/385 - - // stackalloc to allocate array on stack rather than heap - char* charBuffer = stackalloc char[13]; - - charBuffer[0] = _encode32Chars[(int)(id >> 60) & 31]; - charBuffer[1] = _encode32Chars[(int)(id >> 55) & 31]; - charBuffer[2] = _encode32Chars[(int)(id >> 50) & 31]; - charBuffer[3] = _encode32Chars[(int)(id >> 45) & 31]; - charBuffer[4] = _encode32Chars[(int)(id >> 40) & 31]; - charBuffer[5] = _encode32Chars[(int)(id >> 35) & 31]; - charBuffer[6] = _encode32Chars[(int)(id >> 30) & 31]; - charBuffer[7] = _encode32Chars[(int)(id >> 25) & 31]; - charBuffer[8] = _encode32Chars[(int)(id >> 20) & 31]; - charBuffer[9] = _encode32Chars[(int)(id >> 15) & 31]; - charBuffer[10] = _encode32Chars[(int)(id >> 10) & 31]; - charBuffer[11] = _encode32Chars[(int)(id >> 5) & 31]; - charBuffer[12] = _encode32Chars[(int)id & 31]; - - // string ctor overload that takes char* - return new string(charBuffer, 0, 13); - } - } -} diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/IBufferSizeControl.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/IBufferSizeControl.cs deleted file mode 100644 index 3d05cfe4f0..0000000000 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/IBufferSizeControl.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; - -namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http -{ - public interface IBufferSizeControl - { - void Add(int count); - void Subtract(int count); - } -} diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ListenerContext.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ListenerContext.cs deleted file mode 100644 index 4a94842ac3..0000000000 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/ListenerContext.cs +++ /dev/null @@ -1,82 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using System.IO.Pipelines; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; - -namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http -{ - public class ListenerContext - { - public ListenerContext(ServiceContext serviceContext) - { - ServiceContext = serviceContext; - } - - public ServiceContext ServiceContext { get; set; } - - public ListenOptions ListenOptions { get; set; } - - public KestrelThread Thread { get; set; } - - /// - /// Creates a socket which can be used to accept an incoming connection. - /// - protected UvStreamHandle CreateAcceptSocket() - { - switch (ListenOptions.Type) - { - case ListenType.IPEndPoint: - case ListenType.FileHandle: - var tcpHandle = new UvTcpHandle(ServiceContext.Log); - tcpHandle.Init(Thread.Loop, Thread.QueueCloseHandle); - tcpHandle.NoDelay(ListenOptions.NoDelay); - return tcpHandle; - case ListenType.SocketPath: - var pipeHandle = new UvPipeHandle(ServiceContext.Log); - pipeHandle.Init(Thread.Loop, Thread.QueueCloseHandle); - return pipeHandle; - default: - throw new InvalidOperationException(); - } - } - - public PipeOptions LibuvInputPipeOptions => new PipeOptions - { - ReaderScheduler = ServiceContext.ThreadPool, - WriterScheduler = Thread, - MaximumSizeHigh = ServiceContext.ServerOptions.Limits.MaxRequestBufferSize ?? 0, - MaximumSizeLow = ServiceContext.ServerOptions.Limits.MaxRequestBufferSize ?? 0 - }; - - public PipeOptions LibuvOutputPipeOptions => new PipeOptions - { - ReaderScheduler = Thread, - WriterScheduler = ServiceContext.ThreadPool, - MaximumSizeHigh = GetOutputResponseBufferSize(), - MaximumSizeLow = GetOutputResponseBufferSize() - }; - - public PipeOptions AdaptedPipeOptions => new PipeOptions - { - ReaderScheduler = InlineScheduler.Default, - WriterScheduler = InlineScheduler.Default, - MaximumSizeHigh = ServiceContext.ServerOptions.Limits.MaxRequestBufferSize ?? 0, - MaximumSizeLow = ServiceContext.ServerOptions.Limits.MaxRequestBufferSize ?? 0 - }; - - private long GetOutputResponseBufferSize() - { - var bufferSize = ServiceContext.ServerOptions.Limits.MaxResponseBufferSize; - if (bufferSize == 0) - { - // 0 = no buffering so we need to configure the pipe so the the writer waits on the reader directly - return 1; - } - - // null means that we have no back pressure - return bufferSize ?? 0; - } - } -} diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/KestrelEngine.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/KestrelEngine.cs deleted file mode 100644 index 6f21130f6f..0000000000 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/KestrelEngine.cs +++ /dev/null @@ -1,130 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Hosting; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; -using Microsoft.Extensions.Logging; - -namespace Microsoft.AspNetCore.Server.Kestrel.Internal -{ - public class KestrelEngine : IDisposable - { - public KestrelEngine(ServiceContext context) - : this(new Libuv(), context) - { } - - // For testing - internal KestrelEngine(Libuv uv, ServiceContext context) - { - Libuv = uv; - ServiceContext = context; - Threads = new List(); - } - - public Libuv Libuv { get; private set; } - public ServiceContext ServiceContext { get; set; } - public List Threads { get; private set; } - - public IApplicationLifetime AppLifetime => ServiceContext.AppLifetime; - public IKestrelTrace Log => ServiceContext.Log; - public IThreadPool ThreadPool => ServiceContext.ThreadPool; - public KestrelServerOptions ServerOptions => ServiceContext.ServerOptions; - - public void Start(int count) - { - for (var index = 0; index < count; index++) - { - Threads.Add(new KestrelThread(this)); - } - - foreach (var thread in Threads) - { - thread.StartAsync().Wait(); - } - } - - public void Dispose() - { - try - { - Task.WaitAll(Threads.Select(thread => thread.StopAsync(TimeSpan.FromSeconds(2.5))).ToArray()); - } - catch (AggregateException aggEx) - { - // An uncaught exception was likely thrown from the libuv event loop. - // The original error that crashed one loop may have caused secondary errors in others. - // Make sure that the stack trace of the original error is logged. - foreach (var ex in aggEx.InnerExceptions) - { - Log.LogCritical("Failed to gracefully close Kestrel.", ex); - } - - throw; - } - - Threads.Clear(); -#if DEBUG - GC.Collect(); - GC.WaitForPendingFinalizers(); - GC.Collect(); -#endif - } - - public IDisposable CreateServer(ListenOptions listenOptions) - { - var listeners = new List(); - - try - { - if (Threads.Count == 1) - { - var listener = new Listener(ServiceContext); - listeners.Add(listener); - listener.StartAsync(listenOptions, Threads[0]).Wait(); - } - else - { - var pipeName = (Libuv.IsWindows ? @"\\.\pipe\kestrel_" : "/tmp/kestrel_") + Guid.NewGuid().ToString("n"); - var pipeMessage = Guid.NewGuid().ToByteArray(); - - var listenerPrimary = new ListenerPrimary(ServiceContext); - listeners.Add(listenerPrimary); - listenerPrimary.StartAsync(pipeName, pipeMessage, listenOptions, Threads[0]).Wait(); - - foreach (var thread in Threads.Skip(1)) - { - var listenerSecondary = new ListenerSecondary(ServiceContext); - listeners.Add(listenerSecondary); - listenerSecondary.StartAsync(pipeName, pipeMessage, listenOptions, thread).Wait(); - } - } - - return new Disposable(() => - { - DisposeListeners(listeners); - }); - } - catch - { - DisposeListeners(listeners); - throw; - } - } - - private void DisposeListeners(List listeners) - { - var disposeTasks = listeners.Select(listener => listener.DisposeAsync()).ToArray(); - - if (!Task.WaitAll(disposeTasks, TimeSpan.FromSeconds(2.5))) - { - Log.LogError(0, null, "Disposing listeners failed"); - } - } - } -} diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Microsoft.AspNetCore.Server.Kestrel.csproj b/src/Microsoft.AspNetCore.Server.Kestrel/Microsoft.AspNetCore.Server.Kestrel.csproj index 796b8296c6..27e7cc51fe 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Microsoft.AspNetCore.Server.Kestrel.csproj +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Microsoft.AspNetCore.Server.Kestrel.csproj @@ -7,25 +7,13 @@ netstandard1.3;net46 true aspnetcore;kestrel - true CS1591;$(NoWarn) + false - - - - - - - - - - - - - - + + diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/WebHostBuilderKestrelExtensions.cs b/src/Microsoft.AspNetCore.Server.Kestrel/WebHostBuilderKestrelExtensions.cs index 8d26d2deaa..a40b2ec8ae 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/WebHostBuilderKestrelExtensions.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/WebHostBuilderKestrelExtensions.cs @@ -23,6 +23,8 @@ namespace Microsoft.AspNetCore.Hosting /// public static IWebHostBuilder UseKestrel(this IWebHostBuilder hostBuilder) { + hostBuilder.UseLibuv(); + return hostBuilder.ConfigureServices(services => { services.AddTransient, KestrelServerOptionsSetup>(); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/baseline.net45.json b/src/Microsoft.AspNetCore.Server.Kestrel/baseline.net45.json deleted file mode 100644 index f8ee9ee327..0000000000 --- a/src/Microsoft.AspNetCore.Server.Kestrel/baseline.net45.json +++ /dev/null @@ -1,12700 +0,0 @@ -{ - "AssemblyIdentity": "Microsoft.AspNetCore.Server.Kestrel, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60", - "Types": [ - { - "Name": "Microsoft.AspNetCore.Hosting.WebHostBuilderKestrelExtensions", - "Visibility": "Public", - "Kind": "Class", - "Abstract": true, - "Static": true, - "Sealed": true, - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "UseKestrel", - "Parameters": [ - { - "Name": "hostBuilder", - "Type": "Microsoft.AspNetCore.Hosting.IWebHostBuilder" - } - ], - "ReturnType": "Microsoft.AspNetCore.Hosting.IWebHostBuilder", - "Static": true, - "Extension": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "UseKestrel", - "Parameters": [ - { - "Name": "hostBuilder", - "Type": "Microsoft.AspNetCore.Hosting.IWebHostBuilder" - }, - { - "Name": "options", - "Type": "System.Action" - } - ], - "ReturnType": "Microsoft.AspNetCore.Hosting.IWebHostBuilder", - "Static": true, - "Extension": true, - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Hosting.KestrelServerOptionsConnectionLoggingExtensions", - "Visibility": "Public", - "Kind": "Class", - "Abstract": true, - "Static": true, - "Sealed": true, - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "UseConnectionLogging", - "Parameters": [ - { - "Name": "options", - "Type": "Microsoft.AspNetCore.Server.Kestrel.KestrelServerOptions" - } - ], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.KestrelServerOptions", - "Static": true, - "Extension": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "UseConnectionLogging", - "Parameters": [ - { - "Name": "options", - "Type": "Microsoft.AspNetCore.Server.Kestrel.KestrelServerOptions" - }, - { - "Name": "loggerName", - "Type": "System.String" - } - ], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.KestrelServerOptions", - "Static": true, - "Extension": true, - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.BadHttpRequestException", - "Visibility": "Public", - "Kind": "Class", - "Sealed": true, - "BaseType": "System.IO.IOException", - "ImplementedInterfaces": [], - "Members": [], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.KestrelServer", - "Visibility": "Public", - "Kind": "Class", - "ImplementedInterfaces": [ - "Microsoft.AspNetCore.Hosting.Server.IServer" - ], - "Members": [ - { - "Kind": "Method", - "Name": "get_Features", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Http.Features.IFeatureCollection", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Hosting.Server.IServer", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_Options", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.KestrelServerOptions", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Start", - "Parameters": [ - { - "Name": "application", - "Type": "Microsoft.AspNetCore.Hosting.Server.IHttpApplication" - } - ], - "ReturnType": "System.Void", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Hosting.Server.IServer", - "Visibility": "Public", - "GenericParameter": [ - { - "ParameterName": "TContext", - "ParameterPosition": 0, - "BaseTypeOrInterfaces": [] - } - ] - }, - { - "Kind": "Method", - "Name": "Dispose", - "Parameters": [], - "ReturnType": "System.Void", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "System.IDisposable", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "options", - "Type": "Microsoft.Extensions.Options.IOptions" - }, - { - "Name": "applicationLifetime", - "Type": "Microsoft.AspNetCore.Hosting.IApplicationLifetime" - }, - { - "Name": "loggerFactory", - "Type": "Microsoft.Extensions.Logging.ILoggerFactory" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.KestrelServerOptions", - "Visibility": "Public", - "Kind": "Class", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "get_AddServerHeader", - "Parameters": [], - "ReturnType": "System.Boolean", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_AddServerHeader", - "Parameters": [ - { - "Name": "value", - "Type": "System.Boolean" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_ApplicationServices", - "Parameters": [], - "ReturnType": "System.IServiceProvider", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_ApplicationServices", - "Parameters": [ - { - "Name": "value", - "Type": "System.IServiceProvider" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_ConnectionFilter", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Filter.IConnectionFilter", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_ConnectionFilter", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Filter.IConnectionFilter" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_MaxRequestBufferSize", - "Parameters": [], - "ReturnType": "System.Nullable", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_MaxRequestBufferSize", - "Parameters": [ - { - "Name": "value", - "Type": "System.Nullable" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_NoDelay", - "Parameters": [], - "ReturnType": "System.Boolean", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_NoDelay", - "Parameters": [ - { - "Name": "value", - "Type": "System.Boolean" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_ShutdownTimeout", - "Parameters": [], - "ReturnType": "System.TimeSpan", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_ShutdownTimeout", - "Parameters": [ - { - "Name": "value", - "Type": "System.TimeSpan" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_ThreadCount", - "Parameters": [], - "ReturnType": "System.Int32", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_ThreadCount", - "Parameters": [ - { - "Name": "value", - "Type": "System.Int32" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.ServerAddress", - "Visibility": "Public", - "Kind": "Class", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "get_Host", - "Parameters": [], - "ReturnType": "System.String", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_PathBase", - "Parameters": [], - "ReturnType": "System.String", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_Port", - "Parameters": [], - "ReturnType": "System.Int32", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_Scheme", - "Parameters": [], - "ReturnType": "System.String", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_IsUnixPipe", - "Parameters": [], - "ReturnType": "System.Boolean", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_UnixPipePath", - "Parameters": [], - "ReturnType": "System.String", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ToString", - "Parameters": [], - "ReturnType": "System.String", - "Virtual": true, - "Override": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "GetHashCode", - "Parameters": [], - "ReturnType": "System.Int32", - "Virtual": true, - "Override": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Equals", - "Parameters": [ - { - "Name": "obj", - "Type": "System.Object" - } - ], - "ReturnType": "System.Boolean", - "Virtual": true, - "Override": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "FromUrl", - "Parameters": [ - { - "Name": "url", - "Type": "System.String" - } - ], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.ServerAddress", - "Static": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.KestrelEngine", - "Visibility": "Public", - "Kind": "Class", - "BaseType": "Microsoft.AspNetCore.Server.Kestrel.Internal.ServiceContext", - "ImplementedInterfaces": [ - "System.IDisposable" - ], - "Members": [ - { - "Kind": "Method", - "Name": "get_Libuv", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_Threads", - "Parameters": [], - "ReturnType": "System.Collections.Generic.List", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Start", - "Parameters": [ - { - "Name": "count", - "Type": "System.Int32" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Dispose", - "Parameters": [], - "ReturnType": "System.Void", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "System.IDisposable", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "CreateServer", - "Parameters": [ - { - "Name": "address", - "Type": "Microsoft.AspNetCore.Server.Kestrel.ServerAddress" - } - ], - "ReturnType": "System.IDisposable", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "context", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.ServiceContext" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.KestrelServerOptionsSetup", - "Visibility": "Public", - "Kind": "Class", - "ImplementedInterfaces": [ - "Microsoft.Extensions.Options.IConfigureOptions" - ], - "Members": [ - { - "Kind": "Method", - "Name": "Configure", - "Parameters": [ - { - "Name": "options", - "Type": "Microsoft.AspNetCore.Server.Kestrel.KestrelServerOptions" - } - ], - "ReturnType": "System.Void", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "Microsoft.Extensions.Options.IConfigureOptions", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "services", - "Type": "System.IServiceProvider" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.ServiceContext", - "Visibility": "Public", - "Kind": "Class", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "get_AppLifetime", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Hosting.IApplicationLifetime", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_AppLifetime", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.AspNetCore.Hosting.IApplicationLifetime" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_Log", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IKestrelTrace", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_Log", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IKestrelTrace" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_ThreadPool", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IThreadPool", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_ThreadPool", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IThreadPool" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_FrameFactory", - "Parameters": [], - "ReturnType": "System.Func", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_FrameFactory", - "Parameters": [ - { - "Name": "value", - "Type": "System.Func" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_DateHeaderValueManager", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.DateHeaderValueManager", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_DateHeaderValueManager", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.DateHeaderValueManager" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_ServerOptions", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.KestrelServerOptions", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_ServerOptions", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.AspNetCore.Server.Kestrel.KestrelServerOptions" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [], - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "context", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.ServiceContext" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Disposable", - "Visibility": "Public", - "Kind": "Class", - "ImplementedInterfaces": [ - "System.IDisposable" - ], - "Members": [ - { - "Kind": "Method", - "Name": "Dispose", - "Parameters": [ - { - "Name": "disposing", - "Type": "System.Boolean" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Dispose", - "Parameters": [], - "ReturnType": "System.Void", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "System.IDisposable", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "dispose", - "Type": "System.Action" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.KestrelThread", - "Visibility": "Public", - "Kind": "Class", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "get_Loop", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvLoopHandle", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_FatalError", - "Parameters": [], - "ReturnType": "System.Runtime.ExceptionServices.ExceptionDispatchInfo", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_QueueCloseHandle", - "Parameters": [], - "ReturnType": "System.Action, System.IntPtr>", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "StartAsync", - "Parameters": [], - "ReturnType": "System.Threading.Tasks.Task", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "AllowStop", - "Parameters": [], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Stop", - "Parameters": [ - { - "Name": "timeout", - "Type": "System.TimeSpan" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Post", - "Parameters": [ - { - "Name": "callback", - "Type": "System.Action" - }, - { - "Name": "state", - "Type": "System.Object" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "PostAsync", - "Parameters": [ - { - "Name": "callback", - "Type": "System.Action" - }, - { - "Name": "state", - "Type": "System.Object" - } - ], - "ReturnType": "System.Threading.Tasks.Task", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Walk", - "Parameters": [ - { - "Name": "callback", - "Type": "System.Action" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "engine", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.KestrelEngine" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.KestrelTrace", - "Visibility": "Public", - "Kind": "Class", - "ImplementedInterfaces": [ - "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IKestrelTrace" - ], - "Members": [ - { - "Kind": "Method", - "Name": "ConnectionStart", - "Parameters": [ - { - "Name": "connectionId", - "Type": "System.String" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IKestrelTrace", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ConnectionStop", - "Parameters": [ - { - "Name": "connectionId", - "Type": "System.String" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IKestrelTrace", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ConnectionRead", - "Parameters": [ - { - "Name": "connectionId", - "Type": "System.String" - }, - { - "Name": "count", - "Type": "System.Int32" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IKestrelTrace", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ConnectionPause", - "Parameters": [ - { - "Name": "connectionId", - "Type": "System.String" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IKestrelTrace", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ConnectionResume", - "Parameters": [ - { - "Name": "connectionId", - "Type": "System.String" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IKestrelTrace", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ConnectionReadFin", - "Parameters": [ - { - "Name": "connectionId", - "Type": "System.String" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IKestrelTrace", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ConnectionWriteFin", - "Parameters": [ - { - "Name": "connectionId", - "Type": "System.String" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IKestrelTrace", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ConnectionWroteFin", - "Parameters": [ - { - "Name": "connectionId", - "Type": "System.String" - }, - { - "Name": "status", - "Type": "System.Int32" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IKestrelTrace", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ConnectionKeepAlive", - "Parameters": [ - { - "Name": "connectionId", - "Type": "System.String" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IKestrelTrace", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ConnectionDisconnect", - "Parameters": [ - { - "Name": "connectionId", - "Type": "System.String" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IKestrelTrace", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ConnectionWrite", - "Parameters": [ - { - "Name": "connectionId", - "Type": "System.String" - }, - { - "Name": "count", - "Type": "System.Int32" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IKestrelTrace", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ConnectionWriteCallback", - "Parameters": [ - { - "Name": "connectionId", - "Type": "System.String" - }, - { - "Name": "status", - "Type": "System.Int32" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IKestrelTrace", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ApplicationError", - "Parameters": [ - { - "Name": "connectionId", - "Type": "System.String" - }, - { - "Name": "ex", - "Type": "System.Exception" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IKestrelTrace", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ConnectionError", - "Parameters": [ - { - "Name": "connectionId", - "Type": "System.String" - }, - { - "Name": "ex", - "Type": "System.Exception" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IKestrelTrace", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ConnectionDisconnectedWrite", - "Parameters": [ - { - "Name": "connectionId", - "Type": "System.String" - }, - { - "Name": "count", - "Type": "System.Int32" - }, - { - "Name": "ex", - "Type": "System.Exception" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IKestrelTrace", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "NotAllConnectionsClosedGracefully", - "Parameters": [], - "ReturnType": "System.Void", - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IKestrelTrace", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ConnectionBadRequest", - "Parameters": [ - { - "Name": "connectionId", - "Type": "System.String" - }, - { - "Name": "ex", - "Type": "Microsoft.AspNetCore.Server.Kestrel.BadHttpRequestException" - } - ], - "ReturnType": "System.Void", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IKestrelTrace", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Log", - "Parameters": [ - { - "Name": "logLevel", - "Type": "Microsoft.Extensions.Logging.LogLevel" - }, - { - "Name": "eventId", - "Type": "Microsoft.Extensions.Logging.EventId" - }, - { - "Name": "state", - "Type": "T0" - }, - { - "Name": "exception", - "Type": "System.Exception" - }, - { - "Name": "formatter", - "Type": "System.Func" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "ImplementedInterface": "Microsoft.Extensions.Logging.ILogger", - "Visibility": "Public", - "GenericParameter": [ - { - "ParameterName": "TState", - "ParameterPosition": 0, - "BaseTypeOrInterfaces": [] - } - ] - }, - { - "Kind": "Method", - "Name": "IsEnabled", - "Parameters": [ - { - "Name": "logLevel", - "Type": "Microsoft.Extensions.Logging.LogLevel" - } - ], - "ReturnType": "System.Boolean", - "Virtual": true, - "ImplementedInterface": "Microsoft.Extensions.Logging.ILogger", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "BeginScope", - "Parameters": [ - { - "Name": "state", - "Type": "T0" - } - ], - "ReturnType": "System.IDisposable", - "Virtual": true, - "ImplementedInterface": "Microsoft.Extensions.Logging.ILogger", - "Visibility": "Public", - "GenericParameter": [ - { - "ParameterName": "TState", - "ParameterPosition": 0, - "BaseTypeOrInterfaces": [] - } - ] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "logger", - "Type": "Microsoft.Extensions.Logging.ILogger" - } - ], - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "_logger", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Logging.ILogger", - "ReadOnly": true, - "Visibility": "Protected", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv", - "Visibility": "Public", - "Kind": "Class", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "Check", - "Parameters": [ - { - "Name": "statusCode", - "Type": "System.Int32" - } - ], - "ReturnType": "System.Int32", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Check", - "Parameters": [ - { - "Name": "statusCode", - "Type": "System.Int32" - }, - { - "Name": "error", - "Type": "System.Exception", - "Direction": "Out" - } - ], - "ReturnType": "System.Int32", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "loop_init", - "Parameters": [ - { - "Name": "handle", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvLoopHandle" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "loop_close", - "Parameters": [ - { - "Name": "handle", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvLoopHandle" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "run", - "Parameters": [ - { - "Name": "handle", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvLoopHandle" - }, - { - "Name": "mode", - "Type": "System.Int32" - } - ], - "ReturnType": "System.Int32", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "stop", - "Parameters": [ - { - "Name": "handle", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvLoopHandle" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ref", - "Parameters": [ - { - "Name": "handle", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvHandle" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "unref", - "Parameters": [ - { - "Name": "handle", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvHandle" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "uv_fileno", - "Parameters": [ - { - "Name": "handle", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvHandle" - }, - { - "Name": "socket", - "Type": "System.IntPtr", - "Direction": "Ref" - } - ], - "ReturnType": "System.Int32", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "close", - "Parameters": [ - { - "Name": "handle", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvHandle" - }, - { - "Name": "close_cb", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_close_cb" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "close", - "Parameters": [ - { - "Name": "handle", - "Type": "System.IntPtr" - }, - { - "Name": "close_cb", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_close_cb" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "async_init", - "Parameters": [ - { - "Name": "loop", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvLoopHandle" - }, - { - "Name": "handle", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvAsyncHandle" - }, - { - "Name": "cb", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_async_cb" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "async_send", - "Parameters": [ - { - "Name": "handle", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvAsyncHandle" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "unsafe_async_send", - "Parameters": [ - { - "Name": "handle", - "Type": "System.IntPtr" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "tcp_init", - "Parameters": [ - { - "Name": "loop", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvLoopHandle" - }, - { - "Name": "handle", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvTcpHandle" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "tcp_bind", - "Parameters": [ - { - "Name": "handle", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvTcpHandle" - }, - { - "Name": "addr", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.SockAddr", - "Direction": "Ref" - }, - { - "Name": "flags", - "Type": "System.Int32" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "tcp_open", - "Parameters": [ - { - "Name": "handle", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvTcpHandle" - }, - { - "Name": "hSocket", - "Type": "System.IntPtr" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "tcp_nodelay", - "Parameters": [ - { - "Name": "handle", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvTcpHandle" - }, - { - "Name": "enable", - "Type": "System.Boolean" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "pipe_init", - "Parameters": [ - { - "Name": "loop", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvLoopHandle" - }, - { - "Name": "handle", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvPipeHandle" - }, - { - "Name": "ipc", - "Type": "System.Boolean" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "pipe_bind", - "Parameters": [ - { - "Name": "handle", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvPipeHandle" - }, - { - "Name": "name", - "Type": "System.String" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "listen", - "Parameters": [ - { - "Name": "handle", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle" - }, - { - "Name": "backlog", - "Type": "System.Int32" - }, - { - "Name": "cb", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_connection_cb" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "accept", - "Parameters": [ - { - "Name": "server", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle" - }, - { - "Name": "client", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "pipe_connect", - "Parameters": [ - { - "Name": "req", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvConnectRequest" - }, - { - "Name": "handle", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvPipeHandle" - }, - { - "Name": "name", - "Type": "System.String" - }, - { - "Name": "cb", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_connect_cb" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "pipe_pending_count", - "Parameters": [ - { - "Name": "handle", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvPipeHandle" - } - ], - "ReturnType": "System.Int32", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "read_start", - "Parameters": [ - { - "Name": "handle", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle" - }, - { - "Name": "alloc_cb", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_alloc_cb" - }, - { - "Name": "read_cb", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_read_cb" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "read_stop", - "Parameters": [ - { - "Name": "handle", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "try_write", - "Parameters": [ - { - "Name": "handle", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle" - }, - { - "Name": "bufs", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_buf_t[]" - }, - { - "Name": "nbufs", - "Type": "System.Int32" - } - ], - "ReturnType": "System.Int32", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "write", - "Parameters": [ - { - "Name": "req", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvRequest" - }, - { - "Name": "handle", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle" - }, - { - "Name": "bufs", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_buf_t*" - }, - { - "Name": "nbufs", - "Type": "System.Int32" - }, - { - "Name": "cb", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_write_cb" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "write2", - "Parameters": [ - { - "Name": "req", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvRequest" - }, - { - "Name": "handle", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle" - }, - { - "Name": "bufs", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_buf_t*" - }, - { - "Name": "nbufs", - "Type": "System.Int32" - }, - { - "Name": "sendHandle", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle" - }, - { - "Name": "cb", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_write_cb" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "shutdown", - "Parameters": [ - { - "Name": "req", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvShutdownReq" - }, - { - "Name": "handle", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle" - }, - { - "Name": "cb", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_shutdown_cb" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "err_name", - "Parameters": [ - { - "Name": "err", - "Type": "System.Int32" - } - ], - "ReturnType": "System.String", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "strerror", - "Parameters": [ - { - "Name": "err", - "Type": "System.Int32" - } - ], - "ReturnType": "System.String", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "loop_size", - "Parameters": [], - "ReturnType": "System.Int32", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "handle_size", - "Parameters": [ - { - "Name": "handleType", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+HandleType" - } - ], - "ReturnType": "System.Int32", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "req_size", - "Parameters": [ - { - "Name": "reqType", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+RequestType" - } - ], - "ReturnType": "System.Int32", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ip4_addr", - "Parameters": [ - { - "Name": "ip", - "Type": "System.String" - }, - { - "Name": "port", - "Type": "System.Int32" - }, - { - "Name": "addr", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.SockAddr", - "Direction": "Out" - }, - { - "Name": "error", - "Type": "System.Exception", - "Direction": "Out" - } - ], - "ReturnType": "System.Int32", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ip6_addr", - "Parameters": [ - { - "Name": "ip", - "Type": "System.String" - }, - { - "Name": "port", - "Type": "System.Int32" - }, - { - "Name": "addr", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.SockAddr", - "Direction": "Out" - }, - { - "Name": "error", - "Type": "System.Exception", - "Direction": "Out" - } - ], - "ReturnType": "System.Int32", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "walk", - "Parameters": [ - { - "Name": "loop", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvLoopHandle" - }, - { - "Name": "walk_cb", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_walk_cb" - }, - { - "Name": "arg", - "Type": "System.IntPtr" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "tcp_getsockname", - "Parameters": [ - { - "Name": "handle", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvTcpHandle" - }, - { - "Name": "addr", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.SockAddr", - "Direction": "Out" - }, - { - "Name": "namelen", - "Type": "System.Int32", - "Direction": "Ref" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "tcp_getpeername", - "Parameters": [ - { - "Name": "handle", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvTcpHandle" - }, - { - "Name": "addr", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.SockAddr", - "Direction": "Out" - }, - { - "Name": "namelen", - "Type": "System.Int32", - "Direction": "Ref" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "buf_init", - "Parameters": [ - { - "Name": "memory", - "Type": "System.IntPtr" - }, - { - "Name": "len", - "Type": "System.Int32" - } - ], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_buf_t", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [], - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "IsWindows", - "Parameters": [], - "ReturnType": "System.Boolean", - "ReadOnly": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "_uv_loop_init", - "Parameters": [], - "ReturnType": "System.Func", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "_uv_loop_close", - "Parameters": [], - "ReturnType": "System.Func", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "_uv_run", - "Parameters": [], - "ReturnType": "System.Func", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "_uv_stop", - "Parameters": [], - "ReturnType": "System.Action", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "_uv_ref", - "Parameters": [], - "ReturnType": "System.Action", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "_uv_unref", - "Parameters": [], - "ReturnType": "System.Action", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "_uv_fileno", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_fileno_func", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "_uv_close", - "Parameters": [], - "ReturnType": "System.Action", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "_uv_async_init", - "Parameters": [], - "ReturnType": "System.Func", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "_uv_async_send", - "Parameters": [], - "ReturnType": "System.Func", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "_uv_unsafe_async_send", - "Parameters": [], - "ReturnType": "System.Func", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "_uv_tcp_init", - "Parameters": [], - "ReturnType": "System.Func", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "_uv_tcp_bind", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_tcp_bind_func", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "_uv_tcp_open", - "Parameters": [], - "ReturnType": "System.Func", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "_uv_tcp_nodelay", - "Parameters": [], - "ReturnType": "System.Func", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "_uv_pipe_init", - "Parameters": [], - "ReturnType": "System.Func", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "_uv_pipe_bind", - "Parameters": [], - "ReturnType": "System.Func", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "_uv_listen", - "Parameters": [], - "ReturnType": "System.Func", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "_uv_accept", - "Parameters": [], - "ReturnType": "System.Func", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "_uv_pipe_connect", - "Parameters": [], - "ReturnType": "System.Action", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "_uv_pipe_pending_count", - "Parameters": [], - "ReturnType": "System.Func", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "_uv_read_start", - "Parameters": [], - "ReturnType": "System.Func", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "_uv_read_stop", - "Parameters": [], - "ReturnType": "System.Func", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "_uv_try_write", - "Parameters": [], - "ReturnType": "System.Func", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "_uv_write", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_write_func", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "_uv_write2", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_write2_func", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "_uv_shutdown", - "Parameters": [], - "ReturnType": "System.Func", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "_uv_err_name", - "Parameters": [], - "ReturnType": "System.Func", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "_uv_strerror", - "Parameters": [], - "ReturnType": "System.Func", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "_uv_loop_size", - "Parameters": [], - "ReturnType": "System.Func", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "_uv_handle_size", - "Parameters": [], - "ReturnType": "System.Func", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "_uv_req_size", - "Parameters": [], - "ReturnType": "System.Func", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "_uv_ip4_addr", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_ip4_addr_func", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "_uv_ip6_addr", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_ip6_addr_func", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "_uv_walk", - "Parameters": [], - "ReturnType": "System.Func", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "_uv_tcp_getsockname", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_tcp_getsockname_func", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "_uv_tcp_getpeername", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_tcp_getpeername_func", - "Visibility": "Protected", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.PlatformApis", - "Visibility": "Public", - "Kind": "Class", - "Abstract": true, - "Static": true, - "Sealed": true, - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "get_IsWindows", - "Parameters": [], - "ReturnType": "System.Boolean", - "Static": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_IsDarwin", - "Parameters": [], - "ReturnType": "System.Boolean", - "Static": true, - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.SockAddr", - "Visibility": "Public", - "Kind": "Struct", - "Sealed": true, - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "GetIPEndPoint", - "Parameters": [], - "ReturnType": "System.Net.IPEndPoint", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "ignored", - "Type": "System.Int64" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvAsyncHandle", - "Visibility": "Public", - "Kind": "Class", - "BaseType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvHandle", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "Init", - "Parameters": [ - { - "Name": "loop", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvLoopHandle" - }, - { - "Name": "callback", - "Type": "System.Action" - }, - { - "Name": "queueCloseHandle", - "Type": "System.Action, System.IntPtr>" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Send", - "Parameters": [], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ReleaseHandle", - "Parameters": [], - "ReturnType": "System.Boolean", - "Virtual": true, - "Override": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "logger", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IKestrelTrace" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvConnectRequest", - "Visibility": "Public", - "Kind": "Class", - "BaseType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvRequest", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "Init", - "Parameters": [ - { - "Name": "loop", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvLoopHandle" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Connect", - "Parameters": [ - { - "Name": "pipe", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvPipeHandle" - }, - { - "Name": "name", - "Type": "System.String" - }, - { - "Name": "callback", - "Type": "System.Action" - }, - { - "Name": "state", - "Type": "System.Object" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "logger", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IKestrelTrace" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvException", - "Visibility": "Public", - "Kind": "Class", - "BaseType": "System.Exception", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "get_StatusCode", - "Parameters": [], - "ReturnType": "System.Int32", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "message", - "Type": "System.String" - }, - { - "Name": "statusCode", - "Type": "System.Int32" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvHandle", - "Visibility": "Public", - "Kind": "Class", - "Abstract": true, - "BaseType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvMemory", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "CreateHandle", - "Parameters": [ - { - "Name": "uv", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv" - }, - { - "Name": "threadId", - "Type": "System.Int32" - }, - { - "Name": "size", - "Type": "System.Int32" - }, - { - "Name": "queueCloseHandle", - "Type": "System.Action, System.IntPtr>" - } - ], - "ReturnType": "System.Void", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ReleaseHandle", - "Parameters": [], - "ReturnType": "System.Boolean", - "Virtual": true, - "Override": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Reference", - "Parameters": [], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Unreference", - "Parameters": [], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "logger", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IKestrelTrace" - } - ], - "Visibility": "Protected", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvLoopHandle", - "Visibility": "Public", - "Kind": "Class", - "BaseType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvMemory", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "Init", - "Parameters": [ - { - "Name": "uv", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Run", - "Parameters": [ - { - "Name": "mode", - "Type": "System.Int32", - "DefaultValue": "0" - } - ], - "ReturnType": "System.Int32", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Stop", - "Parameters": [], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ReleaseHandle", - "Parameters": [], - "ReturnType": "System.Boolean", - "Virtual": true, - "Override": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "logger", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IKestrelTrace" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvMemory", - "Visibility": "Public", - "Kind": "Class", - "Abstract": true, - "BaseType": "System.Runtime.InteropServices.SafeHandle", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "get_Libuv", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_IsInvalid", - "Parameters": [], - "ReturnType": "System.Boolean", - "Virtual": true, - "Override": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_ThreadId", - "Parameters": [], - "ReturnType": "System.Int32", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "CreateMemory", - "Parameters": [ - { - "Name": "uv", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv" - }, - { - "Name": "threadId", - "Type": "System.Int32" - }, - { - "Name": "size", - "Type": "System.Int32" - } - ], - "ReturnType": "System.Void", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "DestroyMemory", - "Parameters": [ - { - "Name": "memory", - "Type": "System.IntPtr" - } - ], - "ReturnType": "System.Void", - "Static": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "DestroyMemory", - "Parameters": [ - { - "Name": "memory", - "Type": "System.IntPtr" - }, - { - "Name": "gcHandlePtr", - "Type": "System.IntPtr" - } - ], - "ReturnType": "System.Void", - "Static": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Validate", - "Parameters": [ - { - "Name": "closed", - "Type": "System.Boolean", - "DefaultValue": "False" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "FromIntPtr", - "Parameters": [ - { - "Name": "handle", - "Type": "System.IntPtr" - } - ], - "ReturnType": "T0", - "Static": true, - "Visibility": "Public", - "GenericParameter": [ - { - "ParameterName": "THandle", - "ParameterPosition": 0, - "BaseTypeOrInterfaces": [] - } - ] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "logger", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IKestrelTrace" - } - ], - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "_uv", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "_threadId", - "Parameters": [], - "ReturnType": "System.Int32", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "_log", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IKestrelTrace", - "ReadOnly": true, - "Visibility": "Protected", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvPipeHandle", - "Visibility": "Public", - "Kind": "Class", - "BaseType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "Init", - "Parameters": [ - { - "Name": "loop", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvLoopHandle" - }, - { - "Name": "queueCloseHandle", - "Type": "System.Action, System.IntPtr>" - }, - { - "Name": "ipc", - "Type": "System.Boolean", - "DefaultValue": "False" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Bind", - "Parameters": [ - { - "Name": "name", - "Type": "System.String" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "PendingCount", - "Parameters": [], - "ReturnType": "System.Int32", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "logger", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IKestrelTrace" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvRequest", - "Visibility": "Public", - "Kind": "Class", - "BaseType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvMemory", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "ReleaseHandle", - "Parameters": [], - "ReturnType": "System.Boolean", - "Virtual": true, - "Override": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Pin", - "Parameters": [], - "ReturnType": "System.Void", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Unpin", - "Parameters": [], - "ReturnType": "System.Void", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "logger", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IKestrelTrace" - } - ], - "Visibility": "Protected", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvShutdownReq", - "Visibility": "Public", - "Kind": "Class", - "BaseType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvRequest", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "Init", - "Parameters": [ - { - "Name": "loop", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvLoopHandle" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Shutdown", - "Parameters": [ - { - "Name": "handle", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle" - }, - { - "Name": "callback", - "Type": "System.Action" - }, - { - "Name": "state", - "Type": "System.Object" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "logger", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IKestrelTrace" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle", - "Visibility": "Public", - "Kind": "Class", - "Abstract": true, - "BaseType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvHandle", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "get_Connection", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.Connection", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_Connection", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.Connection" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ReleaseHandle", - "Parameters": [], - "ReturnType": "System.Boolean", - "Virtual": true, - "Override": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Listen", - "Parameters": [ - { - "Name": "backlog", - "Type": "System.Int32" - }, - { - "Name": "callback", - "Type": "System.Action" - }, - { - "Name": "state", - "Type": "System.Object" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Accept", - "Parameters": [ - { - "Name": "handle", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ReadStart", - "Parameters": [ - { - "Name": "allocCallback", - "Type": "System.Func" - }, - { - "Name": "readCallback", - "Type": "System.Action" - }, - { - "Name": "state", - "Type": "System.Object" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ReadStop", - "Parameters": [], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "TryWrite", - "Parameters": [ - { - "Name": "buf", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_buf_t" - } - ], - "ReturnType": "System.Int32", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "logger", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IKestrelTrace" - } - ], - "Visibility": "Protected", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvTcpHandle", - "Visibility": "Public", - "Kind": "Class", - "BaseType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "Init", - "Parameters": [ - { - "Name": "loop", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvLoopHandle" - }, - { - "Name": "queueCloseHandle", - "Type": "System.Action, System.IntPtr>" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Bind", - "Parameters": [ - { - "Name": "address", - "Type": "Microsoft.AspNetCore.Server.Kestrel.ServerAddress" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "GetPeerIPEndPoint", - "Parameters": [], - "ReturnType": "System.Net.IPEndPoint", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "GetSockIPEndPoint", - "Parameters": [], - "ReturnType": "System.Net.IPEndPoint", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Open", - "Parameters": [ - { - "Name": "hSocket", - "Type": "System.IntPtr" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "NoDelay", - "Parameters": [ - { - "Name": "enable", - "Type": "System.Boolean" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "CreateIPEndpoint", - "Parameters": [ - { - "Name": "address", - "Type": "Microsoft.AspNetCore.Server.Kestrel.ServerAddress" - } - ], - "ReturnType": "System.Net.IPEndPoint", - "Static": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "logger", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IKestrelTrace" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvWriteReq", - "Visibility": "Public", - "Kind": "Class", - "BaseType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvRequest", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "Init", - "Parameters": [ - { - "Name": "loop", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvLoopHandle" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Write", - "Parameters": [ - { - "Name": "handle", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle" - }, - { - "Name": "start", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolIterator" - }, - { - "Name": "end", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolIterator" - }, - { - "Name": "nBuffers", - "Type": "System.Int32" - }, - { - "Name": "callback", - "Type": "System.Action" - }, - { - "Name": "state", - "Type": "System.Object" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Write2", - "Parameters": [ - { - "Name": "handle", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle" - }, - { - "Name": "bufs", - "Type": "System.ArraySegment>" - }, - { - "Name": "sendHandle", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle" - }, - { - "Name": "callback", - "Type": "System.Action" - }, - { - "Name": "state", - "Type": "System.Object" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "logger", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IKestrelTrace" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IKestrelTrace", - "Visibility": "Public", - "Kind": "Interface", - "Abstract": true, - "ImplementedInterfaces": [ - "Microsoft.Extensions.Logging.ILogger" - ], - "Members": [ - { - "Kind": "Method", - "Name": "ConnectionStart", - "Parameters": [ - { - "Name": "connectionId", - "Type": "System.String" - } - ], - "ReturnType": "System.Void", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ConnectionStop", - "Parameters": [ - { - "Name": "connectionId", - "Type": "System.String" - } - ], - "ReturnType": "System.Void", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ConnectionRead", - "Parameters": [ - { - "Name": "connectionId", - "Type": "System.String" - }, - { - "Name": "count", - "Type": "System.Int32" - } - ], - "ReturnType": "System.Void", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ConnectionPause", - "Parameters": [ - { - "Name": "connectionId", - "Type": "System.String" - } - ], - "ReturnType": "System.Void", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ConnectionResume", - "Parameters": [ - { - "Name": "connectionId", - "Type": "System.String" - } - ], - "ReturnType": "System.Void", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ConnectionReadFin", - "Parameters": [ - { - "Name": "connectionId", - "Type": "System.String" - } - ], - "ReturnType": "System.Void", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ConnectionWriteFin", - "Parameters": [ - { - "Name": "connectionId", - "Type": "System.String" - } - ], - "ReturnType": "System.Void", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ConnectionWroteFin", - "Parameters": [ - { - "Name": "connectionId", - "Type": "System.String" - }, - { - "Name": "status", - "Type": "System.Int32" - } - ], - "ReturnType": "System.Void", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ConnectionKeepAlive", - "Parameters": [ - { - "Name": "connectionId", - "Type": "System.String" - } - ], - "ReturnType": "System.Void", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ConnectionDisconnect", - "Parameters": [ - { - "Name": "connectionId", - "Type": "System.String" - } - ], - "ReturnType": "System.Void", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ConnectionWrite", - "Parameters": [ - { - "Name": "connectionId", - "Type": "System.String" - }, - { - "Name": "count", - "Type": "System.Int32" - } - ], - "ReturnType": "System.Void", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ConnectionWriteCallback", - "Parameters": [ - { - "Name": "connectionId", - "Type": "System.String" - }, - { - "Name": "status", - "Type": "System.Int32" - } - ], - "ReturnType": "System.Void", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ConnectionError", - "Parameters": [ - { - "Name": "connectionId", - "Type": "System.String" - }, - { - "Name": "ex", - "Type": "System.Exception" - } - ], - "ReturnType": "System.Void", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ConnectionDisconnectedWrite", - "Parameters": [ - { - "Name": "connectionId", - "Type": "System.String" - }, - { - "Name": "count", - "Type": "System.Int32" - }, - { - "Name": "ex", - "Type": "System.Exception" - } - ], - "ReturnType": "System.Void", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ConnectionBadRequest", - "Parameters": [ - { - "Name": "connectionId", - "Type": "System.String" - }, - { - "Name": "ex", - "Type": "Microsoft.AspNetCore.Server.Kestrel.BadHttpRequestException" - } - ], - "ReturnType": "System.Void", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "NotAllConnectionsClosedGracefully", - "Parameters": [], - "ReturnType": "System.Void", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ApplicationError", - "Parameters": [ - { - "Name": "connectionId", - "Type": "System.String" - }, - { - "Name": "ex", - "Type": "System.Exception" - } - ], - "ReturnType": "System.Void", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IThreadPool", - "Visibility": "Public", - "Kind": "Interface", - "Abstract": true, - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "Complete", - "Parameters": [ - { - "Name": "tcs", - "Type": "System.Threading.Tasks.TaskCompletionSource" - } - ], - "ReturnType": "System.Void", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Cancel", - "Parameters": [ - { - "Name": "tcs", - "Type": "System.Threading.Tasks.TaskCompletionSource" - } - ], - "ReturnType": "System.Void", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Error", - "Parameters": [ - { - "Name": "tcs", - "Type": "System.Threading.Tasks.TaskCompletionSource" - }, - { - "Name": "ex", - "Type": "System.Exception" - } - ], - "ReturnType": "System.Void", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Run", - "Parameters": [ - { - "Name": "action", - "Type": "System.Action" - } - ], - "ReturnType": "System.Void", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.LoggingThreadPool", - "Visibility": "Public", - "Kind": "Class", - "ImplementedInterfaces": [ - "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IThreadPool" - ], - "Members": [ - { - "Kind": "Method", - "Name": "Run", - "Parameters": [ - { - "Name": "action", - "Type": "System.Action" - } - ], - "ReturnType": "System.Void", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IThreadPool", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Complete", - "Parameters": [ - { - "Name": "tcs", - "Type": "System.Threading.Tasks.TaskCompletionSource" - } - ], - "ReturnType": "System.Void", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IThreadPool", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Cancel", - "Parameters": [ - { - "Name": "tcs", - "Type": "System.Threading.Tasks.TaskCompletionSource" - } - ], - "ReturnType": "System.Void", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IThreadPool", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Error", - "Parameters": [ - { - "Name": "tcs", - "Type": "System.Threading.Tasks.TaskCompletionSource" - }, - { - "Name": "ex", - "Type": "System.Exception" - } - ], - "ReturnType": "System.Void", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IThreadPool", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "log", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IKestrelTrace" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPool", - "Visibility": "Public", - "Kind": "Class", - "ImplementedInterfaces": [ - "System.IDisposable" - ], - "Members": [ - { - "Kind": "Method", - "Name": "Lease", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolBlock", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Return", - "Parameters": [ - { - "Name": "block", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolBlock" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Dispose", - "Parameters": [ - { - "Name": "disposing", - "Type": "System.Boolean" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Dispose", - "Parameters": [], - "ReturnType": "System.Void", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "System.IDisposable", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [], - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "MaxPooledBlockLength", - "Parameters": [], - "ReturnType": "System.Int32", - "Static": true, - "Visibility": "Public", - "GenericParameter": [], - "Constant": true, - "Literal": "4032" - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolBlock", - "Visibility": "Public", - "Kind": "Class", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "get_Pool", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPool", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_Slab", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolSlab", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_Array", - "Parameters": [], - "ReturnType": "System.Byte[]", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Finalize", - "Parameters": [], - "ReturnType": "System.Void", - "Virtual": true, - "Override": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Reset", - "Parameters": [], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ToString", - "Parameters": [], - "ReturnType": "System.String", - "Virtual": true, - "Override": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "GetIterator", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolIterator", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "dataArrayPtr", - "Type": "System.IntPtr" - } - ], - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "DataArrayPtr", - "Parameters": [], - "ReturnType": "System.IntPtr", - "ReadOnly": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "Data", - "Parameters": [], - "ReturnType": "System.ArraySegment", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "Start", - "Parameters": [], - "ReturnType": "System.Int32", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "End", - "Parameters": [], - "ReturnType": "System.Int32", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "Next", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolBlock", - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolIterator", - "Visibility": "Public", - "Kind": "Struct", - "Sealed": true, - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "get_IsDefault", - "Parameters": [], - "ReturnType": "System.Boolean", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_IsEnd", - "Parameters": [], - "ReturnType": "System.Boolean", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_Block", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolBlock", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_Index", - "Parameters": [], - "ReturnType": "System.Int32", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Take", - "Parameters": [], - "ReturnType": "System.Int32", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Skip", - "Parameters": [ - { - "Name": "bytesToSkip", - "Type": "System.Int32" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Peek", - "Parameters": [], - "ReturnType": "System.Int32", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "PeekLong", - "Parameters": [], - "ReturnType": "System.Int64", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Seek", - "Parameters": [ - { - "Name": "byte0Vector", - "Type": "System.Numerics.Vector`1[[System.Byte, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]", - "Direction": "Ref" - } - ], - "ReturnType": "System.Int32", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Seek", - "Parameters": [ - { - "Name": "byte0Vector", - "Type": "System.Numerics.Vector`1[[System.Byte, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]", - "Direction": "Ref" - }, - { - "Name": "byte1Vector", - "Type": "System.Numerics.Vector`1[[System.Byte, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]", - "Direction": "Ref" - } - ], - "ReturnType": "System.Int32", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Seek", - "Parameters": [ - { - "Name": "byte0Vector", - "Type": "System.Numerics.Vector`1[[System.Byte, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]", - "Direction": "Ref" - }, - { - "Name": "byte1Vector", - "Type": "System.Numerics.Vector`1[[System.Byte, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]", - "Direction": "Ref" - }, - { - "Name": "byte2Vector", - "Type": "System.Numerics.Vector`1[[System.Byte, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]", - "Direction": "Ref" - } - ], - "ReturnType": "System.Int32", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Put", - "Parameters": [ - { - "Name": "data", - "Type": "System.Byte" - } - ], - "ReturnType": "System.Boolean", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "GetLength", - "Parameters": [ - { - "Name": "end", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolIterator" - } - ], - "ReturnType": "System.Int32", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "CopyTo", - "Parameters": [ - { - "Name": "array", - "Type": "System.Byte[]" - }, - { - "Name": "offset", - "Type": "System.Int32" - }, - { - "Name": "count", - "Type": "System.Int32" - }, - { - "Name": "actual", - "Type": "System.Int32", - "Direction": "Out" - } - ], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolIterator", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "CopyFrom", - "Parameters": [ - { - "Name": "data", - "Type": "System.Byte[]" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "CopyFrom", - "Parameters": [ - { - "Name": "buffer", - "Type": "System.ArraySegment" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "CopyFrom", - "Parameters": [ - { - "Name": "data", - "Type": "System.Byte[]" - }, - { - "Name": "offset", - "Type": "System.Int32" - }, - { - "Name": "count", - "Type": "System.Int32" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "CopyFromAscii", - "Parameters": [ - { - "Name": "data", - "Type": "System.String" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "block", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolBlock" - } - ], - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "block", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolBlock" - }, - { - "Name": "index", - "Type": "System.Int32" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolIteratorExtensions", - "Visibility": "Public", - "Kind": "Class", - "Abstract": true, - "Static": true, - "Sealed": true, - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "GetAsciiString", - "Parameters": [ - { - "Name": "start", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolIterator" - }, - { - "Name": "end", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolIterator" - } - ], - "ReturnType": "System.String", - "Static": true, - "Extension": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "GetUtf8String", - "Parameters": [ - { - "Name": "start", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolIterator" - }, - { - "Name": "end", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolIterator" - } - ], - "ReturnType": "System.String", - "Static": true, - "Extension": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "GetArraySegment", - "Parameters": [ - { - "Name": "start", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolIterator" - }, - { - "Name": "end", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolIterator" - } - ], - "ReturnType": "System.ArraySegment", - "Static": true, - "Extension": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "GetKnownMethod", - "Parameters": [ - { - "Name": "begin", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolIterator" - }, - { - "Name": "knownMethod", - "Type": "System.String", - "Direction": "Out" - } - ], - "ReturnType": "System.Boolean", - "Static": true, - "Extension": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "GetKnownVersion", - "Parameters": [ - { - "Name": "begin", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolIterator" - }, - { - "Name": "knownVersion", - "Type": "System.String", - "Direction": "Out" - } - ], - "ReturnType": "System.Boolean", - "Static": true, - "Extension": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "HttpConnectMethod", - "Parameters": [], - "ReturnType": "System.String", - "Static": true, - "Visibility": "Public", - "GenericParameter": [], - "Constant": true, - "Literal": "\"CONNECT\"" - }, - { - "Kind": "Field", - "Name": "HttpDeleteMethod", - "Parameters": [], - "ReturnType": "System.String", - "Static": true, - "Visibility": "Public", - "GenericParameter": [], - "Constant": true, - "Literal": "\"DELETE\"" - }, - { - "Kind": "Field", - "Name": "HttpGetMethod", - "Parameters": [], - "ReturnType": "System.String", - "Static": true, - "Visibility": "Public", - "GenericParameter": [], - "Constant": true, - "Literal": "\"GET\"" - }, - { - "Kind": "Field", - "Name": "HttpHeadMethod", - "Parameters": [], - "ReturnType": "System.String", - "Static": true, - "Visibility": "Public", - "GenericParameter": [], - "Constant": true, - "Literal": "\"HEAD\"" - }, - { - "Kind": "Field", - "Name": "HttpPatchMethod", - "Parameters": [], - "ReturnType": "System.String", - "Static": true, - "Visibility": "Public", - "GenericParameter": [], - "Constant": true, - "Literal": "\"PATCH\"" - }, - { - "Kind": "Field", - "Name": "HttpPostMethod", - "Parameters": [], - "ReturnType": "System.String", - "Static": true, - "Visibility": "Public", - "GenericParameter": [], - "Constant": true, - "Literal": "\"POST\"" - }, - { - "Kind": "Field", - "Name": "HttpPutMethod", - "Parameters": [], - "ReturnType": "System.String", - "Static": true, - "Visibility": "Public", - "GenericParameter": [], - "Constant": true, - "Literal": "\"PUT\"" - }, - { - "Kind": "Field", - "Name": "HttpOptionsMethod", - "Parameters": [], - "ReturnType": "System.String", - "Static": true, - "Visibility": "Public", - "GenericParameter": [], - "Constant": true, - "Literal": "\"OPTIONS\"" - }, - { - "Kind": "Field", - "Name": "HttpTraceMethod", - "Parameters": [], - "ReturnType": "System.String", - "Static": true, - "Visibility": "Public", - "GenericParameter": [], - "Constant": true, - "Literal": "\"TRACE\"" - }, - { - "Kind": "Field", - "Name": "Http10Version", - "Parameters": [], - "ReturnType": "System.String", - "Static": true, - "Visibility": "Public", - "GenericParameter": [], - "Constant": true, - "Literal": "\"HTTP/1.0\"" - }, - { - "Kind": "Field", - "Name": "Http11Version", - "Parameters": [], - "ReturnType": "System.String", - "Static": true, - "Visibility": "Public", - "GenericParameter": [], - "Constant": true, - "Literal": "\"HTTP/1.1\"" - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolSlab", - "Visibility": "Public", - "Kind": "Class", - "ImplementedInterfaces": [ - "System.IDisposable" - ], - "Members": [ - { - "Kind": "Method", - "Name": "Create", - "Parameters": [ - { - "Name": "length", - "Type": "System.Int32" - } - ], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolSlab", - "Static": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Dispose", - "Parameters": [ - { - "Name": "disposing", - "Type": "System.Boolean" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Finalize", - "Parameters": [], - "ReturnType": "System.Void", - "Virtual": true, - "Override": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Dispose", - "Parameters": [], - "ReturnType": "System.Void", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "System.IDisposable", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [], - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "Array", - "Parameters": [], - "ReturnType": "System.Byte[]", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "ArrayPtr", - "Parameters": [], - "ReturnType": "System.IntPtr", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "IsActive", - "Parameters": [], - "ReturnType": "System.Boolean", - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.TaskUtilities", - "Visibility": "Public", - "Kind": "Class", - "Abstract": true, - "Static": true, - "Sealed": true, - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "GetCancelledTask", - "Parameters": [ - { - "Name": "cancellationToken", - "Type": "System.Threading.CancellationToken" - } - ], - "ReturnType": "System.Threading.Tasks.Task", - "Static": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "GetCancelledZeroTask", - "Parameters": [ - { - "Name": "cancellationToken", - "Type": "System.Threading.CancellationToken", - "DefaultValue": "default(System.Threading.CancellationToken)" - } - ], - "ReturnType": "System.Threading.Tasks.Task", - "Static": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "CompletedTask", - "Parameters": [], - "ReturnType": "System.Threading.Tasks.Task", - "Static": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "ZeroTask", - "Parameters": [], - "ReturnType": "System.Threading.Tasks.Task", - "Static": true, - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.BufferSizeControl", - "Visibility": "Public", - "Kind": "Class", - "ImplementedInterfaces": [ - "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.IBufferSizeControl" - ], - "Members": [ - { - "Kind": "Method", - "Name": "Add", - "Parameters": [ - { - "Name": "count", - "Type": "System.Int32" - } - ], - "ReturnType": "System.Void", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.IBufferSizeControl", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Subtract", - "Parameters": [ - { - "Name": "count", - "Type": "System.Int32" - } - ], - "ReturnType": "System.Void", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.IBufferSizeControl", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "maxSize", - "Type": "System.Int64" - }, - { - "Name": "connectionControl", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.IConnectionControl" - }, - { - "Name": "connectionThread", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.KestrelThread" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ChunkWriter", - "Visibility": "Public", - "Kind": "Class", - "Abstract": true, - "Static": true, - "Sealed": true, - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "BeginChunkBytes", - "Parameters": [ - { - "Name": "dataCount", - "Type": "System.Int32" - } - ], - "ReturnType": "System.ArraySegment", - "Static": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "WriteBeginChunkBytes", - "Parameters": [ - { - "Name": "start", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolIterator", - "Direction": "Ref" - }, - { - "Name": "dataCount", - "Type": "System.Int32" - } - ], - "ReturnType": "System.Int32", - "Static": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "WriteEndChunkBytes", - "Parameters": [ - { - "Name": "start", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolIterator", - "Direction": "Ref" - } - ], - "ReturnType": "System.Void", - "Static": true, - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.Connection", - "Visibility": "Public", - "Kind": "Class", - "BaseType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ConnectionContext", - "ImplementedInterfaces": [ - "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.IConnectionControl" - ], - "Members": [ - { - "Kind": "Method", - "Name": "Start", - "Parameters": [], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "StopAsync", - "Parameters": [], - "ReturnType": "System.Threading.Tasks.Task", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Abort", - "Parameters": [], - "ReturnType": "System.Void", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "OnSocketClosed", - "Parameters": [], - "ReturnType": "System.Void", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "context", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ListenerContext" - }, - { - "Name": "socket", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ConnectionContext", - "Visibility": "Public", - "Kind": "Class", - "BaseType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ListenerContext", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "get_SocketInput", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.SocketInput", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_SocketInput", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.SocketInput" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_SocketOutput", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ISocketOutput", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_SocketOutput", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ISocketOutput" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_ConnectionControl", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.IConnectionControl", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_ConnectionControl", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.IConnectionControl" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_RemoteEndPoint", - "Parameters": [], - "ReturnType": "System.Net.IPEndPoint", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_RemoteEndPoint", - "Parameters": [ - { - "Name": "value", - "Type": "System.Net.IPEndPoint" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_LocalEndPoint", - "Parameters": [], - "ReturnType": "System.Net.IPEndPoint", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_LocalEndPoint", - "Parameters": [ - { - "Name": "value", - "Type": "System.Net.IPEndPoint" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_ConnectionId", - "Parameters": [], - "ReturnType": "System.String", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_ConnectionId", - "Parameters": [ - { - "Name": "value", - "Type": "System.String" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_PrepareRequest", - "Parameters": [], - "ReturnType": "System.Action", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_PrepareRequest", - "Parameters": [ - { - "Name": "value", - "Type": "System.Action" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [], - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "context", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ListenerContext" - } - ], - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "context", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ConnectionContext" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ConnectionManager", - "Visibility": "Public", - "Kind": "Class", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "WalkConnectionsAndClose", - "Parameters": [], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "WaitForConnectionCloseAsync", - "Parameters": [], - "ReturnType": "System.Threading.Tasks.Task", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "thread", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.KestrelThread" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.DateHeaderValueManager", - "Visibility": "Public", - "Kind": "Class", - "ImplementedInterfaces": [ - "System.IDisposable" - ], - "Members": [ - { - "Kind": "Method", - "Name": "GetDateHeaderValues", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.DateHeaderValueManager+DateHeaderValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Dispose", - "Parameters": [], - "ReturnType": "System.Void", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "System.IDisposable", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.Frame", - "Visibility": "Public", - "Kind": "Class", - "Abstract": true, - "BaseType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ConnectionContext", - "ImplementedInterfaces": [ - "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.IFrameControl", - "Microsoft.AspNetCore.Http.Features.IFeatureCollection", - "Microsoft.AspNetCore.Http.Features.IHttpRequestFeature", - "Microsoft.AspNetCore.Http.Features.IHttpResponseFeature", - "Microsoft.AspNetCore.Http.Features.IHttpUpgradeFeature", - "Microsoft.AspNetCore.Http.Features.IHttpConnectionFeature", - "Microsoft.AspNetCore.Http.Features.IHttpRequestLifetimeFeature" - ], - "Members": [ - { - "Kind": "Method", - "Name": "get_ConnectionIdFeature", - "Parameters": [], - "ReturnType": "System.String", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_ConnectionIdFeature", - "Parameters": [ - { - "Name": "value", - "Type": "System.String" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_RemoteIpAddress", - "Parameters": [], - "ReturnType": "System.Net.IPAddress", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_RemoteIpAddress", - "Parameters": [ - { - "Name": "value", - "Type": "System.Net.IPAddress" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_RemotePort", - "Parameters": [], - "ReturnType": "System.Int32", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_RemotePort", - "Parameters": [ - { - "Name": "value", - "Type": "System.Int32" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_LocalIpAddress", - "Parameters": [], - "ReturnType": "System.Net.IPAddress", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_LocalIpAddress", - "Parameters": [ - { - "Name": "value", - "Type": "System.Net.IPAddress" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_LocalPort", - "Parameters": [], - "ReturnType": "System.Int32", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_LocalPort", - "Parameters": [ - { - "Name": "value", - "Type": "System.Int32" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_Scheme", - "Parameters": [], - "ReturnType": "System.String", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_Scheme", - "Parameters": [ - { - "Name": "value", - "Type": "System.String" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_Method", - "Parameters": [], - "ReturnType": "System.String", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_Method", - "Parameters": [ - { - "Name": "value", - "Type": "System.String" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_PathBase", - "Parameters": [], - "ReturnType": "System.String", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_PathBase", - "Parameters": [ - { - "Name": "value", - "Type": "System.String" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_Path", - "Parameters": [], - "ReturnType": "System.String", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_Path", - "Parameters": [ - { - "Name": "value", - "Type": "System.String" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_QueryString", - "Parameters": [], - "ReturnType": "System.String", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_QueryString", - "Parameters": [ - { - "Name": "value", - "Type": "System.String" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_RawTarget", - "Parameters": [], - "ReturnType": "System.String", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_RawTarget", - "Parameters": [ - { - "Name": "value", - "Type": "System.String" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HttpVersion", - "Parameters": [], - "ReturnType": "System.String", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HttpVersion", - "Parameters": [ - { - "Name": "value", - "Type": "System.String" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_RequestHeaders", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Http.IHeaderDictionary", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_RequestHeaders", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.AspNetCore.Http.IHeaderDictionary" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_RequestBody", - "Parameters": [], - "ReturnType": "System.IO.Stream", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_RequestBody", - "Parameters": [ - { - "Name": "value", - "Type": "System.IO.Stream" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_StatusCode", - "Parameters": [], - "ReturnType": "System.Int32", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_StatusCode", - "Parameters": [ - { - "Name": "value", - "Type": "System.Int32" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_ReasonPhrase", - "Parameters": [], - "ReturnType": "System.String", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_ReasonPhrase", - "Parameters": [ - { - "Name": "value", - "Type": "System.String" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_ResponseHeaders", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Http.IHeaderDictionary", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_ResponseHeaders", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.AspNetCore.Http.IHeaderDictionary" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_ResponseBody", - "Parameters": [], - "ReturnType": "System.IO.Stream", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_ResponseBody", - "Parameters": [ - { - "Name": "value", - "Type": "System.IO.Stream" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_DuplexStream", - "Parameters": [], - "ReturnType": "System.IO.Stream", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_DuplexStream", - "Parameters": [ - { - "Name": "value", - "Type": "System.IO.Stream" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_RequestAborted", - "Parameters": [], - "ReturnType": "System.Threading.CancellationToken", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_RequestAborted", - "Parameters": [ - { - "Name": "value", - "Type": "System.Threading.CancellationToken" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HasResponseStarted", - "Parameters": [], - "ReturnType": "System.Boolean", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_FrameRequestHeaders", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.FrameRequestHeaders", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_FrameResponseHeaders", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.FrameResponseHeaders", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "InitializeHeaders", - "Parameters": [], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "InitializeStreams", - "Parameters": [ - { - "Name": "messageBody", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.MessageBody" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "PauseStreams", - "Parameters": [], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ResumeStreams", - "Parameters": [], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "StopStreams", - "Parameters": [], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Reset", - "Parameters": [], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Start", - "Parameters": [], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Stop", - "Parameters": [], - "ReturnType": "System.Threading.Tasks.Task", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Abort", - "Parameters": [], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "RequestProcessingAsync", - "Parameters": [], - "ReturnType": "System.Threading.Tasks.Task", - "Virtual": true, - "Abstract": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "OnStarting", - "Parameters": [ - { - "Name": "callback", - "Type": "System.Func" - }, - { - "Name": "state", - "Type": "System.Object" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "OnCompleted", - "Parameters": [ - { - "Name": "callback", - "Type": "System.Func" - }, - { - "Name": "state", - "Type": "System.Object" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "FireOnStarting", - "Parameters": [], - "ReturnType": "System.Threading.Tasks.Task", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "FireOnCompleted", - "Parameters": [], - "ReturnType": "System.Threading.Tasks.Task", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Flush", - "Parameters": [], - "ReturnType": "System.Void", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.IFrameControl", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "FlushAsync", - "Parameters": [ - { - "Name": "cancellationToken", - "Type": "System.Threading.CancellationToken" - } - ], - "ReturnType": "System.Threading.Tasks.Task", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.IFrameControl", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Write", - "Parameters": [ - { - "Name": "data", - "Type": "System.ArraySegment" - } - ], - "ReturnType": "System.Void", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.IFrameControl", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "WriteAsync", - "Parameters": [ - { - "Name": "data", - "Type": "System.ArraySegment" - }, - { - "Name": "cancellationToken", - "Type": "System.Threading.CancellationToken" - } - ], - "ReturnType": "System.Threading.Tasks.Task", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.IFrameControl", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "WriteAsyncAwaited", - "Parameters": [ - { - "Name": "data", - "Type": "System.ArraySegment" - }, - { - "Name": "cancellationToken", - "Type": "System.Threading.CancellationToken" - } - ], - "ReturnType": "System.Threading.Tasks.Task", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ProduceContinue", - "Parameters": [], - "ReturnType": "System.Void", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.IFrameControl", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ProduceStartAndFireOnStarting", - "Parameters": [], - "ReturnType": "System.Threading.Tasks.Task", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "TryProduceInvalidRequestResponse", - "Parameters": [], - "ReturnType": "System.Threading.Tasks.Task", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ProduceEnd", - "Parameters": [], - "ReturnType": "System.Threading.Tasks.Task", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "TakeStartLine", - "Parameters": [ - { - "Name": "input", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.SocketInput" - } - ], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.Frame+RequestLineStatus", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "TakeMessageHeaders", - "Parameters": [ - { - "Name": "input", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.SocketInput" - }, - { - "Name": "requestHeaders", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.FrameRequestHeaders" - } - ], - "ReturnType": "System.Boolean", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "StatusCanHaveBody", - "Parameters": [ - { - "Name": "statusCode", - "Type": "System.Int32" - } - ], - "ReturnType": "System.Boolean", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "RejectRequest", - "Parameters": [ - { - "Name": "message", - "Type": "System.String" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "SetBadRequestState", - "Parameters": [ - { - "Name": "ex", - "Type": "Microsoft.AspNetCore.Server.Kestrel.BadHttpRequestException" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ReportApplicationError", - "Parameters": [ - { - "Name": "ex", - "Type": "System.Exception" - } - ], - "ReturnType": "System.Void", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ResetFeatureCollection", - "Parameters": [], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_FrameControl", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.IFrameControl", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_FrameControl", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.IFrameControl" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "context", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ConnectionContext" - } - ], - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "_requestRejected", - "Parameters": [], - "ReturnType": "System.Boolean", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "_onStarting", - "Parameters": [], - "ReturnType": "System.Collections.Generic.List, System.Object>>", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "_onCompleted", - "Parameters": [], - "ReturnType": "System.Collections.Generic.List, System.Object>>", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "_requestProcessingStopping", - "Parameters": [], - "ReturnType": "System.Boolean", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "_requestAborted", - "Parameters": [], - "ReturnType": "System.Int32", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "_requestProcessingStatus", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.Frame+RequestProcessingStatus", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "_keepAlive", - "Parameters": [], - "ReturnType": "System.Boolean", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "_applicationException", - "Parameters": [], - "ReturnType": "System.Exception", - "Visibility": "Protected", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.FrameHeaders", - "Visibility": "Public", - "Kind": "Class", - "Abstract": true, - "ImplementedInterfaces": [ - "Microsoft.AspNetCore.Http.IHeaderDictionary" - ], - "Members": [ - { - "Kind": "Method", - "Name": "get_Unknown", - "Parameters": [], - "ReturnType": "System.Collections.Generic.Dictionary", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ThrowReadOnlyException", - "Parameters": [], - "ReturnType": "System.Void", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ThrowArgumentException", - "Parameters": [], - "ReturnType": "System.Void", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ThrowKeyNotFoundException", - "Parameters": [], - "ReturnType": "System.Void", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ThrowDuplicateKeyException", - "Parameters": [], - "ReturnType": "System.Void", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "SetReadOnly", - "Parameters": [], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Reset", - "Parameters": [], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "AppendValue", - "Parameters": [ - { - "Name": "existing", - "Type": "Microsoft.Extensions.Primitives.StringValues" - }, - { - "Name": "append", - "Type": "System.String" - } - ], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Static": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "BitCount", - "Parameters": [ - { - "Name": "value", - "Type": "System.Int64" - } - ], - "ReturnType": "System.Int32", - "Static": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "GetCountFast", - "Parameters": [], - "ReturnType": "System.Int32", - "Virtual": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "GetValueFast", - "Parameters": [ - { - "Name": "key", - "Type": "System.String" - } - ], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Virtual": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "TryGetValueFast", - "Parameters": [ - { - "Name": "key", - "Type": "System.String" - }, - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues", - "Direction": "Out" - } - ], - "ReturnType": "System.Boolean", - "Virtual": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "SetValueFast", - "Parameters": [ - { - "Name": "key", - "Type": "System.String" - }, - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "AddValueFast", - "Parameters": [ - { - "Name": "key", - "Type": "System.String" - }, - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "RemoveFast", - "Parameters": [ - { - "Name": "key", - "Type": "System.String" - } - ], - "ReturnType": "System.Boolean", - "Virtual": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ClearFast", - "Parameters": [], - "ReturnType": "System.Void", - "Virtual": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "CopyToFast", - "Parameters": [ - { - "Name": "array", - "Type": "System.Collections.Generic.KeyValuePair[]" - }, - { - "Name": "arrayIndex", - "Type": "System.Int32" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "GetEnumeratorFast", - "Parameters": [], - "ReturnType": "System.Collections.Generic.IEnumerator>", - "Virtual": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ValidateHeaderCharacters", - "Parameters": [ - { - "Name": "headerValues", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Static": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ValidateHeaderCharacters", - "Parameters": [ - { - "Name": "headerCharacters", - "Type": "System.String" - } - ], - "ReturnType": "System.Void", - "Static": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [], - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "_isReadOnly", - "Parameters": [], - "ReturnType": "System.Boolean", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "MaybeUnknown", - "Parameters": [], - "ReturnType": "System.Collections.Generic.Dictionary", - "Visibility": "Protected", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.FrameRequestHeaders", - "Visibility": "Public", - "Kind": "Class", - "BaseType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.FrameHeaders", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "get_HeaderCacheControl", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderCacheControl", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderConnection", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderConnection", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderDate", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderDate", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderKeepAlive", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderKeepAlive", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderPragma", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderPragma", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderTrailer", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderTrailer", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderTransferEncoding", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderTransferEncoding", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderUpgrade", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderUpgrade", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderVia", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderVia", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderWarning", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderWarning", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderAllow", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderAllow", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderContentLength", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderContentLength", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderContentType", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderContentType", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderContentEncoding", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderContentEncoding", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderContentLanguage", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderContentLanguage", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderContentLocation", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderContentLocation", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderContentMD5", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderContentMD5", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderContentRange", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderContentRange", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderExpires", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderExpires", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderLastModified", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderLastModified", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderAccept", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderAccept", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderAcceptCharset", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderAcceptCharset", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderAcceptEncoding", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderAcceptEncoding", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderAcceptLanguage", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderAcceptLanguage", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderAuthorization", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderAuthorization", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderCookie", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderCookie", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderExpect", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderExpect", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderFrom", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderFrom", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderHost", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderHost", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderIfMatch", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderIfMatch", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderIfModifiedSince", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderIfModifiedSince", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderIfNoneMatch", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderIfNoneMatch", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderIfRange", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderIfRange", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderIfUnmodifiedSince", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderIfUnmodifiedSince", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderMaxForwards", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderMaxForwards", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderProxyAuthorization", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderProxyAuthorization", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderReferer", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderReferer", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderRange", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderRange", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderTE", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderTE", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderTranslate", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderTranslate", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderUserAgent", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderUserAgent", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderOrigin", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderOrigin", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderAccessControlRequestMethod", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderAccessControlRequestMethod", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderAccessControlRequestHeaders", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderAccessControlRequestHeaders", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "GetCountFast", - "Parameters": [], - "ReturnType": "System.Int32", - "Virtual": true, - "Override": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "GetValueFast", - "Parameters": [ - { - "Name": "key", - "Type": "System.String" - } - ], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Virtual": true, - "Override": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "TryGetValueFast", - "Parameters": [ - { - "Name": "key", - "Type": "System.String" - }, - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues", - "Direction": "Out" - } - ], - "ReturnType": "System.Boolean", - "Virtual": true, - "Override": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "SetValueFast", - "Parameters": [ - { - "Name": "key", - "Type": "System.String" - }, - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "Override": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "AddValueFast", - "Parameters": [ - { - "Name": "key", - "Type": "System.String" - }, - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "Override": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "RemoveFast", - "Parameters": [ - { - "Name": "key", - "Type": "System.String" - } - ], - "ReturnType": "System.Boolean", - "Virtual": true, - "Override": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ClearFast", - "Parameters": [], - "ReturnType": "System.Void", - "Virtual": true, - "Override": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "CopyToFast", - "Parameters": [ - { - "Name": "array", - "Type": "System.Collections.Generic.KeyValuePair[]" - }, - { - "Name": "arrayIndex", - "Type": "System.Int32" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "Override": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Append", - "Parameters": [ - { - "Name": "keyBytes", - "Type": "System.Byte[]" - }, - { - "Name": "keyOffset", - "Type": "System.Int32" - }, - { - "Name": "keyLength", - "Type": "System.Int32" - }, - { - "Name": "value", - "Type": "System.String" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "GetEnumerator", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.FrameRequestHeaders+Enumerator", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "GetEnumeratorFast", - "Parameters": [], - "ReturnType": "System.Collections.Generic.IEnumerator>", - "Virtual": true, - "Override": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.FrameResponseHeaders", - "Visibility": "Public", - "Kind": "Class", - "BaseType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.FrameHeaders", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "get_HeaderCacheControl", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderCacheControl", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderConnection", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderConnection", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderDate", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderDate", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderKeepAlive", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderKeepAlive", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderPragma", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderPragma", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderTrailer", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderTrailer", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderTransferEncoding", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderTransferEncoding", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderUpgrade", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderUpgrade", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderVia", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderVia", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderWarning", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderWarning", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderAllow", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderAllow", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderContentLength", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderContentLength", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderContentType", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderContentType", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderContentEncoding", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderContentEncoding", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderContentLanguage", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderContentLanguage", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderContentLocation", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderContentLocation", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderContentMD5", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderContentMD5", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderContentRange", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderContentRange", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderExpires", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderExpires", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderLastModified", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderLastModified", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderAcceptRanges", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderAcceptRanges", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderAge", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderAge", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderETag", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderETag", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderLocation", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderLocation", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderProxyAutheticate", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderProxyAutheticate", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderRetryAfter", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderRetryAfter", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderServer", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderServer", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderSetCookie", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderSetCookie", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderVary", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderVary", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderWWWAuthenticate", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderWWWAuthenticate", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderAccessControlAllowCredentials", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderAccessControlAllowCredentials", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderAccessControlAllowHeaders", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderAccessControlAllowHeaders", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderAccessControlAllowMethods", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderAccessControlAllowMethods", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderAccessControlAllowOrigin", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderAccessControlAllowOrigin", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderAccessControlExposeHeaders", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderAccessControlExposeHeaders", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderAccessControlMaxAge", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderAccessControlMaxAge", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "SetRawConnection", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - }, - { - "Name": "raw", - "Type": "System.Byte[]" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "SetRawDate", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - }, - { - "Name": "raw", - "Type": "System.Byte[]" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "SetRawTransferEncoding", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - }, - { - "Name": "raw", - "Type": "System.Byte[]" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "SetRawContentLength", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - }, - { - "Name": "raw", - "Type": "System.Byte[]" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "SetRawServer", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - }, - { - "Name": "raw", - "Type": "System.Byte[]" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "GetCountFast", - "Parameters": [], - "ReturnType": "System.Int32", - "Virtual": true, - "Override": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "GetValueFast", - "Parameters": [ - { - "Name": "key", - "Type": "System.String" - } - ], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Virtual": true, - "Override": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "TryGetValueFast", - "Parameters": [ - { - "Name": "key", - "Type": "System.String" - }, - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues", - "Direction": "Out" - } - ], - "ReturnType": "System.Boolean", - "Virtual": true, - "Override": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "SetValueFast", - "Parameters": [ - { - "Name": "key", - "Type": "System.String" - }, - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "Override": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "AddValueFast", - "Parameters": [ - { - "Name": "key", - "Type": "System.String" - }, - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "Override": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "RemoveFast", - "Parameters": [ - { - "Name": "key", - "Type": "System.String" - } - ], - "ReturnType": "System.Boolean", - "Virtual": true, - "Override": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ClearFast", - "Parameters": [], - "ReturnType": "System.Void", - "Virtual": true, - "Override": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "CopyToFast", - "Parameters": [ - { - "Name": "array", - "Type": "System.Collections.Generic.KeyValuePair[]" - }, - { - "Name": "arrayIndex", - "Type": "System.Int32" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "Override": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "CopyToFast", - "Parameters": [ - { - "Name": "output", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolIterator", - "Direction": "Ref" - } - ], - "ReturnType": "System.Void", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HasConnection", - "Parameters": [], - "ReturnType": "System.Boolean", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HasTransferEncoding", - "Parameters": [], - "ReturnType": "System.Boolean", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HasContentLength", - "Parameters": [], - "ReturnType": "System.Boolean", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HasServer", - "Parameters": [], - "ReturnType": "System.Boolean", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HasDate", - "Parameters": [], - "ReturnType": "System.Boolean", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "GetEnumerator", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.FrameResponseHeaders+Enumerator", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "GetEnumeratorFast", - "Parameters": [], - "ReturnType": "System.Collections.Generic.IEnumerator>", - "Virtual": true, - "Override": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "CopyTo", - "Parameters": [ - { - "Name": "output", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolIterator", - "Direction": "Ref" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.Frame", - "Visibility": "Public", - "Kind": "Class", - "BaseType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.Frame", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "RequestProcessingAsync", - "Parameters": [], - "ReturnType": "System.Threading.Tasks.Task", - "Virtual": true, - "Override": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "application", - "Type": "Microsoft.AspNetCore.Hosting.Server.IHttpApplication" - }, - { - "Name": "context", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ConnectionContext" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [ - { - "ParameterName": "TContext", - "ParameterPosition": 0, - "BaseTypeOrInterfaces": [] - } - ] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.IBufferSizeControl", - "Visibility": "Public", - "Kind": "Interface", - "Abstract": true, - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "Add", - "Parameters": [ - { - "Name": "count", - "Type": "System.Int32" - } - ], - "ReturnType": "System.Void", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Subtract", - "Parameters": [ - { - "Name": "count", - "Type": "System.Int32" - } - ], - "ReturnType": "System.Void", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.IConnectionControl", - "Visibility": "Public", - "Kind": "Interface", - "Abstract": true, - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "Pause", - "Parameters": [], - "ReturnType": "System.Void", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Resume", - "Parameters": [], - "ReturnType": "System.Void", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "End", - "Parameters": [ - { - "Name": "endType", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ProduceEndType" - } - ], - "ReturnType": "System.Void", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.IFrameControl", - "Visibility": "Public", - "Kind": "Interface", - "Abstract": true, - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "ProduceContinue", - "Parameters": [], - "ReturnType": "System.Void", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Write", - "Parameters": [ - { - "Name": "data", - "Type": "System.ArraySegment" - } - ], - "ReturnType": "System.Void", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "WriteAsync", - "Parameters": [ - { - "Name": "data", - "Type": "System.ArraySegment" - }, - { - "Name": "cancellationToken", - "Type": "System.Threading.CancellationToken" - } - ], - "ReturnType": "System.Threading.Tasks.Task", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Flush", - "Parameters": [], - "ReturnType": "System.Void", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "FlushAsync", - "Parameters": [ - { - "Name": "cancellationToken", - "Type": "System.Threading.CancellationToken" - } - ], - "ReturnType": "System.Threading.Tasks.Task", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ISocketOutput", - "Visibility": "Public", - "Kind": "Interface", - "Abstract": true, - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "Write", - "Parameters": [ - { - "Name": "buffer", - "Type": "System.ArraySegment" - }, - { - "Name": "chunk", - "Type": "System.Boolean", - "DefaultValue": "False" - } - ], - "ReturnType": "System.Void", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "WriteAsync", - "Parameters": [ - { - "Name": "buffer", - "Type": "System.ArraySegment" - }, - { - "Name": "chunk", - "Type": "System.Boolean", - "DefaultValue": "False" - }, - { - "Name": "cancellationToken", - "Type": "System.Threading.CancellationToken", - "DefaultValue": "default(System.Threading.CancellationToken)" - } - ], - "ReturnType": "System.Threading.Tasks.Task", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ProducingStart", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolIterator", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ProducingComplete", - "Parameters": [ - { - "Name": "end", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolIterator" - } - ], - "ReturnType": "System.Void", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.Listener", - "Visibility": "Public", - "Kind": "Class", - "Abstract": true, - "BaseType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ListenerContext", - "ImplementedInterfaces": [ - "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.IAsyncDisposable" - ], - "Members": [ - { - "Kind": "Method", - "Name": "get_ListenSocket", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "StartAsync", - "Parameters": [ - { - "Name": "address", - "Type": "Microsoft.AspNetCore.Server.Kestrel.ServerAddress" - }, - { - "Name": "thread", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.KestrelThread" - } - ], - "ReturnType": "System.Threading.Tasks.Task", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "CreateListenSocket", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle", - "Virtual": true, - "Abstract": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ConnectionCallback", - "Parameters": [ - { - "Name": "stream", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle" - }, - { - "Name": "status", - "Type": "System.Int32" - }, - { - "Name": "error", - "Type": "System.Exception" - }, - { - "Name": "state", - "Type": "System.Object" - } - ], - "ReturnType": "System.Void", - "Static": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "OnConnection", - "Parameters": [ - { - "Name": "listenSocket", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle" - }, - { - "Name": "status", - "Type": "System.Int32" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "Abstract": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "DispatchConnection", - "Parameters": [ - { - "Name": "socket", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "DisposeAsync", - "Parameters": [], - "ReturnType": "System.Threading.Tasks.Task", - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.IAsyncDisposable", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "serviceContext", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.ServiceContext" - } - ], - "Visibility": "Protected", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ListenerContext", - "Visibility": "Public", - "Kind": "Class", - "BaseType": "Microsoft.AspNetCore.Server.Kestrel.Internal.ServiceContext", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "get_ServerAddress", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.ServerAddress", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_ServerAddress", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.AspNetCore.Server.Kestrel.ServerAddress" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_Thread", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.KestrelThread", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_Thread", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.KestrelThread" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_Memory", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPool", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_Memory", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPool" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_ConnectionManager", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ConnectionManager", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_ConnectionManager", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ConnectionManager" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_WriteReqPool", - "Parameters": [], - "ReturnType": "System.Collections.Generic.Queue", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_WriteReqPool", - "Parameters": [ - { - "Name": "value", - "Type": "System.Collections.Generic.Queue" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [], - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "serviceContext", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.ServiceContext" - } - ], - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "listenerContext", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ListenerContext" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ListenerPrimary", - "Visibility": "Public", - "Kind": "Class", - "Abstract": true, - "BaseType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.Listener", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "StartAsync", - "Parameters": [ - { - "Name": "pipeName", - "Type": "System.String" - }, - { - "Name": "address", - "Type": "Microsoft.AspNetCore.Server.Kestrel.ServerAddress" - }, - { - "Name": "thread", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.KestrelThread" - } - ], - "ReturnType": "System.Threading.Tasks.Task", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "DispatchConnection", - "Parameters": [ - { - "Name": "socket", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "Override": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "DisposeAsync", - "Parameters": [], - "ReturnType": "System.Threading.Tasks.Task", - "Virtual": true, - "Override": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.IAsyncDisposable", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "serviceContext", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.ServiceContext" - } - ], - "Visibility": "Protected", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ListenerSecondary", - "Visibility": "Public", - "Kind": "Class", - "Abstract": true, - "BaseType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ListenerContext", - "ImplementedInterfaces": [ - "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.IAsyncDisposable" - ], - "Members": [ - { - "Kind": "Method", - "Name": "StartAsync", - "Parameters": [ - { - "Name": "pipeName", - "Type": "System.String" - }, - { - "Name": "address", - "Type": "Microsoft.AspNetCore.Server.Kestrel.ServerAddress" - }, - { - "Name": "thread", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.KestrelThread" - } - ], - "ReturnType": "System.Threading.Tasks.Task", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "CreateAcceptSocket", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle", - "Virtual": true, - "Abstract": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "DisposeAsync", - "Parameters": [], - "ReturnType": "System.Threading.Tasks.Task", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.IAsyncDisposable", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "serviceContext", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.ServiceContext" - } - ], - "Visibility": "Protected", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.MessageBody", - "Visibility": "Public", - "Kind": "Class", - "Abstract": true, - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "get_RequestKeepAlive", - "Parameters": [], - "ReturnType": "System.Boolean", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_RequestKeepAlive", - "Parameters": [ - { - "Name": "value", - "Type": "System.Boolean" - } - ], - "ReturnType": "System.Void", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ReadAsync", - "Parameters": [ - { - "Name": "buffer", - "Type": "System.ArraySegment" - }, - { - "Name": "cancellationToken", - "Type": "System.Threading.CancellationToken", - "DefaultValue": "default(System.Threading.CancellationToken)" - } - ], - "ReturnType": "System.Threading.Tasks.ValueTask", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Consume", - "Parameters": [ - { - "Name": "cancellationToken", - "Type": "System.Threading.CancellationToken", - "DefaultValue": "default(System.Threading.CancellationToken)" - } - ], - "ReturnType": "System.Threading.Tasks.Task", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ReadAsyncImplementation", - "Parameters": [ - { - "Name": "buffer", - "Type": "System.ArraySegment" - }, - { - "Name": "cancellationToken", - "Type": "System.Threading.CancellationToken" - } - ], - "ReturnType": "System.Threading.Tasks.ValueTask", - "Virtual": true, - "Abstract": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "For", - "Parameters": [ - { - "Name": "httpVersion", - "Type": "System.String" - }, - { - "Name": "headers", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.FrameRequestHeaders" - }, - { - "Name": "context", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.Frame" - } - ], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.MessageBody", - "Static": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "context", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.Frame" - } - ], - "Visibility": "Protected", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.PathNormalizer", - "Visibility": "Public", - "Kind": "Class", - "Abstract": true, - "Static": true, - "Sealed": true, - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "RemoveDotSegments", - "Parameters": [ - { - "Name": "path", - "Type": "System.String" - } - ], - "ReturnType": "System.String", - "Static": true, - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.PipeListener", - "Visibility": "Public", - "Kind": "Class", - "BaseType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.Listener", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "CreateListenSocket", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle", - "Virtual": true, - "Override": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "OnConnection", - "Parameters": [ - { - "Name": "listenSocket", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle" - }, - { - "Name": "status", - "Type": "System.Int32" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "Override": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "serviceContext", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.ServiceContext" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.PipeListenerPrimary", - "Visibility": "Public", - "Kind": "Class", - "BaseType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ListenerPrimary", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "CreateListenSocket", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle", - "Virtual": true, - "Override": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "OnConnection", - "Parameters": [ - { - "Name": "listenSocket", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle" - }, - { - "Name": "status", - "Type": "System.Int32" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "Override": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "serviceContext", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.ServiceContext" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.PipeListenerSecondary", - "Visibility": "Public", - "Kind": "Class", - "BaseType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ListenerSecondary", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "CreateAcceptSocket", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle", - "Virtual": true, - "Override": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "serviceContext", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.ServiceContext" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ProduceEndType", - "Visibility": "Public", - "Kind": "Enumeration", - "Sealed": true, - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Field", - "Name": "SocketShutdown", - "Parameters": [], - "GenericParameter": [], - "Literal": "0" - }, - { - "Kind": "Field", - "Name": "SocketDisconnect", - "Parameters": [], - "GenericParameter": [], - "Literal": "1" - }, - { - "Kind": "Field", - "Name": "ConnectionKeepAlive", - "Parameters": [], - "GenericParameter": [], - "Literal": "2" - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ReasonPhrases", - "Visibility": "Public", - "Kind": "Class", - "Abstract": true, - "Static": true, - "Sealed": true, - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "ToStatusBytes", - "Parameters": [ - { - "Name": "statusCode", - "Type": "System.Int32" - }, - { - "Name": "reasonPhrase", - "Type": "System.String", - "DefaultValue": "null" - } - ], - "ReturnType": "System.Byte[]", - "Static": true, - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.SocketInput", - "Visibility": "Public", - "Kind": "Class", - "ImplementedInterfaces": [ - "System.Runtime.CompilerServices.ICriticalNotifyCompletion", - "System.IDisposable" - ], - "Members": [ - { - "Kind": "Method", - "Name": "get_RemoteIntakeFin", - "Parameters": [], - "ReturnType": "System.Boolean", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_RemoteIntakeFin", - "Parameters": [ - { - "Name": "value", - "Type": "System.Boolean" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_IsCompleted", - "Parameters": [], - "ReturnType": "System.Boolean", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "IncomingStart", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolBlock", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "IncomingData", - "Parameters": [ - { - "Name": "buffer", - "Type": "System.Byte[]" - }, - { - "Name": "offset", - "Type": "System.Int32" - }, - { - "Name": "count", - "Type": "System.Int32" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "IncomingComplete", - "Parameters": [ - { - "Name": "count", - "Type": "System.Int32" - }, - { - "Name": "error", - "Type": "System.Exception" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "IncomingDeferred", - "Parameters": [], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "IncomingFin", - "Parameters": [], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ConsumingStart", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolIterator", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ConsumingComplete", - "Parameters": [ - { - "Name": "consumed", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolIterator" - }, - { - "Name": "examined", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolIterator" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "CompleteAwaiting", - "Parameters": [], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "AbortAwaiting", - "Parameters": [], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "GetAwaiter", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.SocketInput", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "OnCompleted", - "Parameters": [ - { - "Name": "continuation", - "Type": "System.Action" - } - ], - "ReturnType": "System.Void", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "System.Runtime.CompilerServices.INotifyCompletion", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "UnsafeOnCompleted", - "Parameters": [ - { - "Name": "continuation", - "Type": "System.Action" - } - ], - "ReturnType": "System.Void", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "System.Runtime.CompilerServices.ICriticalNotifyCompletion", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "GetResult", - "Parameters": [], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Dispose", - "Parameters": [], - "ReturnType": "System.Void", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "System.IDisposable", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "memory", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPool" - }, - { - "Name": "threadPool", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IThreadPool" - }, - { - "Name": "bufferSizeControl", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.IBufferSizeControl", - "DefaultValue": "null" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.SocketInputExtensions", - "Visibility": "Public", - "Kind": "Class", - "Abstract": true, - "Static": true, - "Sealed": true, - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "ReadAsync", - "Parameters": [ - { - "Name": "input", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.SocketInput" - }, - { - "Name": "buffer", - "Type": "System.Byte[]" - }, - { - "Name": "offset", - "Type": "System.Int32" - }, - { - "Name": "count", - "Type": "System.Int32" - } - ], - "ReturnType": "System.Threading.Tasks.ValueTask", - "Static": true, - "Extension": true, - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.SocketOutput", - "Visibility": "Public", - "Kind": "Class", - "ImplementedInterfaces": [ - "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ISocketOutput" - ], - "Members": [ - { - "Kind": "Method", - "Name": "WriteAsync", - "Parameters": [ - { - "Name": "buffer", - "Type": "System.ArraySegment" - }, - { - "Name": "cancellationToken", - "Type": "System.Threading.CancellationToken" - }, - { - "Name": "chunk", - "Type": "System.Boolean", - "DefaultValue": "False" - }, - { - "Name": "socketShutdownSend", - "Type": "System.Boolean", - "DefaultValue": "False" - }, - { - "Name": "socketDisconnect", - "Type": "System.Boolean", - "DefaultValue": "False" - }, - { - "Name": "isSync", - "Type": "System.Boolean", - "DefaultValue": "False" - } - ], - "ReturnType": "System.Threading.Tasks.Task", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "End", - "Parameters": [ - { - "Name": "endType", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ProduceEndType" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ProducingStart", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolIterator", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ISocketOutput", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ProducingComplete", - "Parameters": [ - { - "Name": "end", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolIterator" - } - ], - "ReturnType": "System.Void", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ISocketOutput", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "thread", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.KestrelThread" - }, - { - "Name": "socket", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle" - }, - { - "Name": "memory", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPool" - }, - { - "Name": "connection", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.Connection" - }, - { - "Name": "connectionId", - "Type": "System.String" - }, - { - "Name": "log", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IKestrelTrace" - }, - { - "Name": "threadPool", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IThreadPool" - }, - { - "Name": "writeReqPool", - "Type": "System.Collections.Generic.Queue" - } - ], - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "MaxPooledWriteReqs", - "Parameters": [], - "ReturnType": "System.Int32", - "Static": true, - "Visibility": "Public", - "GenericParameter": [], - "Constant": true, - "Literal": "1024" - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.TcpListener", - "Visibility": "Public", - "Kind": "Class", - "BaseType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.Listener", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "CreateListenSocket", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle", - "Virtual": true, - "Override": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "OnConnection", - "Parameters": [ - { - "Name": "listenSocket", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle" - }, - { - "Name": "status", - "Type": "System.Int32" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "Override": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "serviceContext", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.ServiceContext" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.TcpListenerPrimary", - "Visibility": "Public", - "Kind": "Class", - "BaseType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ListenerPrimary", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "CreateListenSocket", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle", - "Virtual": true, - "Override": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "OnConnection", - "Parameters": [ - { - "Name": "listenSocket", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle" - }, - { - "Name": "status", - "Type": "System.Int32" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "Override": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "serviceContext", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.ServiceContext" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.TcpListenerSecondary", - "Visibility": "Public", - "Kind": "Class", - "BaseType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ListenerSecondary", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "CreateAcceptSocket", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle", - "Virtual": true, - "Override": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "serviceContext", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.ServiceContext" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.UrlPathDecoder", - "Visibility": "Public", - "Kind": "Class", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "Unescape", - "Parameters": [ - { - "Name": "start", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolIterator" - }, - { - "Name": "end", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolIterator" - } - ], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolIterator", - "Static": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Filter.ConnectionFilterContext", - "Visibility": "Public", - "Kind": "Class", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "get_Address", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.ServerAddress", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_Address", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.AspNetCore.Server.Kestrel.ServerAddress" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_Connection", - "Parameters": [], - "ReturnType": "System.IO.Stream", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_Connection", - "Parameters": [ - { - "Name": "value", - "Type": "System.IO.Stream" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_PrepareRequest", - "Parameters": [], - "ReturnType": "System.Action", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_PrepareRequest", - "Parameters": [ - { - "Name": "value", - "Type": "System.Action" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Filter.IConnectionFilter", - "Visibility": "Public", - "Kind": "Interface", - "Abstract": true, - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "OnConnectionAsync", - "Parameters": [ - { - "Name": "context", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Filter.ConnectionFilterContext" - } - ], - "ReturnType": "System.Threading.Tasks.Task", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Filter.LoggingConnectionFilter", - "Visibility": "Public", - "Kind": "Class", - "ImplementedInterfaces": [ - "Microsoft.AspNetCore.Server.Kestrel.Filter.IConnectionFilter" - ], - "Members": [ - { - "Kind": "Method", - "Name": "OnConnectionAsync", - "Parameters": [ - { - "Name": "context", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Filter.ConnectionFilterContext" - } - ], - "ReturnType": "System.Threading.Tasks.Task", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Filter.IConnectionFilter", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "logger", - "Type": "Microsoft.Extensions.Logging.ILogger" - }, - { - "Name": "previous", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Filter.IConnectionFilter" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Filter.NoOpConnectionFilter", - "Visibility": "Public", - "Kind": "Class", - "ImplementedInterfaces": [ - "Microsoft.AspNetCore.Server.Kestrel.Filter.IConnectionFilter" - ], - "Members": [ - { - "Kind": "Method", - "Name": "OnConnectionAsync", - "Parameters": [ - { - "Name": "context", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Filter.ConnectionFilterContext" - } - ], - "ReturnType": "System.Threading.Tasks.Task", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Filter.IConnectionFilter", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Filter.Internal.FilteredStreamAdapter", - "Visibility": "Public", - "Kind": "Class", - "ImplementedInterfaces": [ - "System.IDisposable" - ], - "Members": [ - { - "Kind": "Method", - "Name": "get_SocketInput", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.SocketInput", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_SocketOutput", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ISocketOutput", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ReadInputAsync", - "Parameters": [], - "ReturnType": "System.Threading.Tasks.Task", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Abort", - "Parameters": [], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Dispose", - "Parameters": [], - "ReturnType": "System.Void", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "System.IDisposable", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "connectionId", - "Type": "System.String" - }, - { - "Name": "filteredStream", - "Type": "System.IO.Stream" - }, - { - "Name": "memory", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPool" - }, - { - "Name": "logger", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IKestrelTrace" - }, - { - "Name": "threadPool", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IThreadPool" - }, - { - "Name": "bufferSizeControl", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.IBufferSizeControl" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Filter.Internal.LibuvStream", - "Visibility": "Public", - "Kind": "Class", - "BaseType": "System.IO.Stream", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "get_CanRead", - "Parameters": [], - "ReturnType": "System.Boolean", - "Virtual": true, - "Override": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_CanSeek", - "Parameters": [], - "ReturnType": "System.Boolean", - "Virtual": true, - "Override": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_CanWrite", - "Parameters": [], - "ReturnType": "System.Boolean", - "Virtual": true, - "Override": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_Length", - "Parameters": [], - "ReturnType": "System.Int64", - "Virtual": true, - "Override": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_Position", - "Parameters": [], - "ReturnType": "System.Int64", - "Virtual": true, - "Override": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_Position", - "Parameters": [ - { - "Name": "value", - "Type": "System.Int64" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "Override": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Seek", - "Parameters": [ - { - "Name": "offset", - "Type": "System.Int64" - }, - { - "Name": "origin", - "Type": "System.IO.SeekOrigin" - } - ], - "ReturnType": "System.Int64", - "Virtual": true, - "Override": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "SetLength", - "Parameters": [ - { - "Name": "value", - "Type": "System.Int64" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "Override": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Read", - "Parameters": [ - { - "Name": "buffer", - "Type": "System.Byte[]" - }, - { - "Name": "offset", - "Type": "System.Int32" - }, - { - "Name": "count", - "Type": "System.Int32" - } - ], - "ReturnType": "System.Int32", - "Virtual": true, - "Override": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ReadAsync", - "Parameters": [ - { - "Name": "buffer", - "Type": "System.Byte[]" - }, - { - "Name": "offset", - "Type": "System.Int32" - }, - { - "Name": "count", - "Type": "System.Int32" - }, - { - "Name": "cancellationToken", - "Type": "System.Threading.CancellationToken" - } - ], - "ReturnType": "System.Threading.Tasks.Task", - "Virtual": true, - "Override": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Write", - "Parameters": [ - { - "Name": "buffer", - "Type": "System.Byte[]" - }, - { - "Name": "offset", - "Type": "System.Int32" - }, - { - "Name": "count", - "Type": "System.Int32" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "Override": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "WriteAsync", - "Parameters": [ - { - "Name": "buffer", - "Type": "System.Byte[]" - }, - { - "Name": "offset", - "Type": "System.Int32" - }, - { - "Name": "count", - "Type": "System.Int32" - }, - { - "Name": "token", - "Type": "System.Threading.CancellationToken" - } - ], - "ReturnType": "System.Threading.Tasks.Task", - "Virtual": true, - "Override": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Flush", - "Parameters": [], - "ReturnType": "System.Void", - "Virtual": true, - "Override": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "FlushAsync", - "Parameters": [ - { - "Name": "cancellationToken", - "Type": "System.Threading.CancellationToken" - } - ], - "ReturnType": "System.Threading.Tasks.Task", - "Virtual": true, - "Override": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "input", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.SocketInput" - }, - { - "Name": "output", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ISocketOutput" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Filter.Internal.StreamSocketOutput", - "Visibility": "Public", - "Kind": "Class", - "ImplementedInterfaces": [ - "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ISocketOutput" - ], - "Members": [ - { - "Kind": "Method", - "Name": "Write", - "Parameters": [ - { - "Name": "buffer", - "Type": "System.ArraySegment" - }, - { - "Name": "chunk", - "Type": "System.Boolean" - } - ], - "ReturnType": "System.Void", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ISocketOutput", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "WriteAsync", - "Parameters": [ - { - "Name": "buffer", - "Type": "System.ArraySegment" - }, - { - "Name": "chunk", - "Type": "System.Boolean" - }, - { - "Name": "cancellationToken", - "Type": "System.Threading.CancellationToken" - } - ], - "ReturnType": "System.Threading.Tasks.Task", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ISocketOutput", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ProducingStart", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolIterator", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ISocketOutput", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ProducingComplete", - "Parameters": [ - { - "Name": "end", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolIterator" - } - ], - "ReturnType": "System.Void", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ISocketOutput", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "connectionId", - "Type": "System.String" - }, - { - "Name": "outputStream", - "Type": "System.IO.Stream" - }, - { - "Name": "memory", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPool" - }, - { - "Name": "logger", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IKestrelTrace" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_fileno_func", - "Visibility": "Protected", - "Kind": "Class", - "Sealed": true, - "BaseType": "System.MulticastDelegate", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "Invoke", - "Parameters": [ - { - "Name": "handle", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvHandle" - }, - { - "Name": "socket", - "Type": "System.IntPtr", - "Direction": "Ref" - } - ], - "ReturnType": "System.Int32", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "BeginInvoke", - "Parameters": [ - { - "Name": "handle", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvHandle" - }, - { - "Name": "socket", - "Type": "System.IntPtr", - "Direction": "Ref" - }, - { - "Name": "callback", - "Type": "System.AsyncCallback" - }, - { - "Name": "object", - "Type": "System.Object" - } - ], - "ReturnType": "System.IAsyncResult", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "EndInvoke", - "Parameters": [ - { - "Name": "socket", - "Type": "System.IntPtr", - "Direction": "Ref" - }, - { - "Name": "result", - "Type": "System.IAsyncResult" - } - ], - "ReturnType": "System.Int32", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "object", - "Type": "System.Object" - }, - { - "Name": "method", - "Type": "System.IntPtr" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_close_cb", - "Visibility": "Public", - "Kind": "Class", - "Sealed": true, - "BaseType": "System.MulticastDelegate", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "Invoke", - "Parameters": [ - { - "Name": "handle", - "Type": "System.IntPtr" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "BeginInvoke", - "Parameters": [ - { - "Name": "handle", - "Type": "System.IntPtr" - }, - { - "Name": "callback", - "Type": "System.AsyncCallback" - }, - { - "Name": "object", - "Type": "System.Object" - } - ], - "ReturnType": "System.IAsyncResult", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "EndInvoke", - "Parameters": [ - { - "Name": "result", - "Type": "System.IAsyncResult" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "object", - "Type": "System.Object" - }, - { - "Name": "method", - "Type": "System.IntPtr" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_async_cb", - "Visibility": "Public", - "Kind": "Class", - "Sealed": true, - "BaseType": "System.MulticastDelegate", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "Invoke", - "Parameters": [ - { - "Name": "handle", - "Type": "System.IntPtr" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "BeginInvoke", - "Parameters": [ - { - "Name": "handle", - "Type": "System.IntPtr" - }, - { - "Name": "callback", - "Type": "System.AsyncCallback" - }, - { - "Name": "object", - "Type": "System.Object" - } - ], - "ReturnType": "System.IAsyncResult", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "EndInvoke", - "Parameters": [ - { - "Name": "result", - "Type": "System.IAsyncResult" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "object", - "Type": "System.Object" - }, - { - "Name": "method", - "Type": "System.IntPtr" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_tcp_bind_func", - "Visibility": "Protected", - "Kind": "Class", - "Sealed": true, - "BaseType": "System.MulticastDelegate", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "Invoke", - "Parameters": [ - { - "Name": "handle", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvTcpHandle" - }, - { - "Name": "addr", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.SockAddr", - "Direction": "Ref" - }, - { - "Name": "flags", - "Type": "System.Int32" - } - ], - "ReturnType": "System.Int32", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "BeginInvoke", - "Parameters": [ - { - "Name": "handle", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvTcpHandle" - }, - { - "Name": "addr", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.SockAddr", - "Direction": "Ref" - }, - { - "Name": "flags", - "Type": "System.Int32" - }, - { - "Name": "callback", - "Type": "System.AsyncCallback" - }, - { - "Name": "object", - "Type": "System.Object" - } - ], - "ReturnType": "System.IAsyncResult", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "EndInvoke", - "Parameters": [ - { - "Name": "addr", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.SockAddr", - "Direction": "Ref" - }, - { - "Name": "result", - "Type": "System.IAsyncResult" - } - ], - "ReturnType": "System.Int32", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "object", - "Type": "System.Object" - }, - { - "Name": "method", - "Type": "System.IntPtr" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_connection_cb", - "Visibility": "Public", - "Kind": "Class", - "Sealed": true, - "BaseType": "System.MulticastDelegate", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "Invoke", - "Parameters": [ - { - "Name": "server", - "Type": "System.IntPtr" - }, - { - "Name": "status", - "Type": "System.Int32" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "BeginInvoke", - "Parameters": [ - { - "Name": "server", - "Type": "System.IntPtr" - }, - { - "Name": "status", - "Type": "System.Int32" - }, - { - "Name": "callback", - "Type": "System.AsyncCallback" - }, - { - "Name": "object", - "Type": "System.Object" - } - ], - "ReturnType": "System.IAsyncResult", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "EndInvoke", - "Parameters": [ - { - "Name": "result", - "Type": "System.IAsyncResult" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "object", - "Type": "System.Object" - }, - { - "Name": "method", - "Type": "System.IntPtr" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_connect_cb", - "Visibility": "Public", - "Kind": "Class", - "Sealed": true, - "BaseType": "System.MulticastDelegate", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "Invoke", - "Parameters": [ - { - "Name": "req", - "Type": "System.IntPtr" - }, - { - "Name": "status", - "Type": "System.Int32" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "BeginInvoke", - "Parameters": [ - { - "Name": "req", - "Type": "System.IntPtr" - }, - { - "Name": "status", - "Type": "System.Int32" - }, - { - "Name": "callback", - "Type": "System.AsyncCallback" - }, - { - "Name": "object", - "Type": "System.Object" - } - ], - "ReturnType": "System.IAsyncResult", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "EndInvoke", - "Parameters": [ - { - "Name": "result", - "Type": "System.IAsyncResult" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "object", - "Type": "System.Object" - }, - { - "Name": "method", - "Type": "System.IntPtr" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_alloc_cb", - "Visibility": "Public", - "Kind": "Class", - "Sealed": true, - "BaseType": "System.MulticastDelegate", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "Invoke", - "Parameters": [ - { - "Name": "server", - "Type": "System.IntPtr" - }, - { - "Name": "suggested_size", - "Type": "System.Int32" - }, - { - "Name": "buf", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_buf_t", - "Direction": "Out" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "BeginInvoke", - "Parameters": [ - { - "Name": "server", - "Type": "System.IntPtr" - }, - { - "Name": "suggested_size", - "Type": "System.Int32" - }, - { - "Name": "buf", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_buf_t", - "Direction": "Out" - }, - { - "Name": "callback", - "Type": "System.AsyncCallback" - }, - { - "Name": "object", - "Type": "System.Object" - } - ], - "ReturnType": "System.IAsyncResult", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "EndInvoke", - "Parameters": [ - { - "Name": "buf", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_buf_t", - "Direction": "Out" - }, - { - "Name": "result", - "Type": "System.IAsyncResult" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "object", - "Type": "System.Object" - }, - { - "Name": "method", - "Type": "System.IntPtr" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_read_cb", - "Visibility": "Public", - "Kind": "Class", - "Sealed": true, - "BaseType": "System.MulticastDelegate", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "Invoke", - "Parameters": [ - { - "Name": "server", - "Type": "System.IntPtr" - }, - { - "Name": "nread", - "Type": "System.Int32" - }, - { - "Name": "buf", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_buf_t", - "Direction": "Ref" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "BeginInvoke", - "Parameters": [ - { - "Name": "server", - "Type": "System.IntPtr" - }, - { - "Name": "nread", - "Type": "System.Int32" - }, - { - "Name": "buf", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_buf_t", - "Direction": "Ref" - }, - { - "Name": "callback", - "Type": "System.AsyncCallback" - }, - { - "Name": "object", - "Type": "System.Object" - } - ], - "ReturnType": "System.IAsyncResult", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "EndInvoke", - "Parameters": [ - { - "Name": "buf", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_buf_t", - "Direction": "Ref" - }, - { - "Name": "result", - "Type": "System.IAsyncResult" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "object", - "Type": "System.Object" - }, - { - "Name": "method", - "Type": "System.IntPtr" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_write_cb", - "Visibility": "Public", - "Kind": "Class", - "Sealed": true, - "BaseType": "System.MulticastDelegate", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "Invoke", - "Parameters": [ - { - "Name": "req", - "Type": "System.IntPtr" - }, - { - "Name": "status", - "Type": "System.Int32" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "BeginInvoke", - "Parameters": [ - { - "Name": "req", - "Type": "System.IntPtr" - }, - { - "Name": "status", - "Type": "System.Int32" - }, - { - "Name": "callback", - "Type": "System.AsyncCallback" - }, - { - "Name": "object", - "Type": "System.Object" - } - ], - "ReturnType": "System.IAsyncResult", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "EndInvoke", - "Parameters": [ - { - "Name": "result", - "Type": "System.IAsyncResult" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "object", - "Type": "System.Object" - }, - { - "Name": "method", - "Type": "System.IntPtr" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_write_func", - "Visibility": "Protected", - "Kind": "Class", - "Sealed": true, - "BaseType": "System.MulticastDelegate", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "Invoke", - "Parameters": [ - { - "Name": "req", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvRequest" - }, - { - "Name": "handle", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle" - }, - { - "Name": "bufs", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_buf_t*" - }, - { - "Name": "nbufs", - "Type": "System.Int32" - }, - { - "Name": "cb", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_write_cb" - } - ], - "ReturnType": "System.Int32", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "BeginInvoke", - "Parameters": [ - { - "Name": "req", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvRequest" - }, - { - "Name": "handle", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle" - }, - { - "Name": "bufs", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_buf_t*" - }, - { - "Name": "nbufs", - "Type": "System.Int32" - }, - { - "Name": "cb", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_write_cb" - }, - { - "Name": "callback", - "Type": "System.AsyncCallback" - }, - { - "Name": "object", - "Type": "System.Object" - } - ], - "ReturnType": "System.IAsyncResult", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "EndInvoke", - "Parameters": [ - { - "Name": "result", - "Type": "System.IAsyncResult" - } - ], - "ReturnType": "System.Int32", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "object", - "Type": "System.Object" - }, - { - "Name": "method", - "Type": "System.IntPtr" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_write2_func", - "Visibility": "Protected", - "Kind": "Class", - "Sealed": true, - "BaseType": "System.MulticastDelegate", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "Invoke", - "Parameters": [ - { - "Name": "req", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvRequest" - }, - { - "Name": "handle", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle" - }, - { - "Name": "bufs", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_buf_t*" - }, - { - "Name": "nbufs", - "Type": "System.Int32" - }, - { - "Name": "sendHandle", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle" - }, - { - "Name": "cb", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_write_cb" - } - ], - "ReturnType": "System.Int32", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "BeginInvoke", - "Parameters": [ - { - "Name": "req", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvRequest" - }, - { - "Name": "handle", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle" - }, - { - "Name": "bufs", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_buf_t*" - }, - { - "Name": "nbufs", - "Type": "System.Int32" - }, - { - "Name": "sendHandle", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle" - }, - { - "Name": "cb", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_write_cb" - }, - { - "Name": "callback", - "Type": "System.AsyncCallback" - }, - { - "Name": "object", - "Type": "System.Object" - } - ], - "ReturnType": "System.IAsyncResult", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "EndInvoke", - "Parameters": [ - { - "Name": "result", - "Type": "System.IAsyncResult" - } - ], - "ReturnType": "System.Int32", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "object", - "Type": "System.Object" - }, - { - "Name": "method", - "Type": "System.IntPtr" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_shutdown_cb", - "Visibility": "Public", - "Kind": "Class", - "Sealed": true, - "BaseType": "System.MulticastDelegate", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "Invoke", - "Parameters": [ - { - "Name": "req", - "Type": "System.IntPtr" - }, - { - "Name": "status", - "Type": "System.Int32" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "BeginInvoke", - "Parameters": [ - { - "Name": "req", - "Type": "System.IntPtr" - }, - { - "Name": "status", - "Type": "System.Int32" - }, - { - "Name": "callback", - "Type": "System.AsyncCallback" - }, - { - "Name": "object", - "Type": "System.Object" - } - ], - "ReturnType": "System.IAsyncResult", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "EndInvoke", - "Parameters": [ - { - "Name": "result", - "Type": "System.IAsyncResult" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "object", - "Type": "System.Object" - }, - { - "Name": "method", - "Type": "System.IntPtr" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_ip4_addr_func", - "Visibility": "Protected", - "Kind": "Class", - "Sealed": true, - "BaseType": "System.MulticastDelegate", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "Invoke", - "Parameters": [ - { - "Name": "ip", - "Type": "System.String" - }, - { - "Name": "port", - "Type": "System.Int32" - }, - { - "Name": "addr", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.SockAddr", - "Direction": "Out" - } - ], - "ReturnType": "System.Int32", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "BeginInvoke", - "Parameters": [ - { - "Name": "ip", - "Type": "System.String" - }, - { - "Name": "port", - "Type": "System.Int32" - }, - { - "Name": "addr", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.SockAddr", - "Direction": "Out" - }, - { - "Name": "callback", - "Type": "System.AsyncCallback" - }, - { - "Name": "object", - "Type": "System.Object" - } - ], - "ReturnType": "System.IAsyncResult", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "EndInvoke", - "Parameters": [ - { - "Name": "addr", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.SockAddr", - "Direction": "Out" - }, - { - "Name": "result", - "Type": "System.IAsyncResult" - } - ], - "ReturnType": "System.Int32", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "object", - "Type": "System.Object" - }, - { - "Name": "method", - "Type": "System.IntPtr" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_ip6_addr_func", - "Visibility": "Protected", - "Kind": "Class", - "Sealed": true, - "BaseType": "System.MulticastDelegate", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "Invoke", - "Parameters": [ - { - "Name": "ip", - "Type": "System.String" - }, - { - "Name": "port", - "Type": "System.Int32" - }, - { - "Name": "addr", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.SockAddr", - "Direction": "Out" - } - ], - "ReturnType": "System.Int32", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "BeginInvoke", - "Parameters": [ - { - "Name": "ip", - "Type": "System.String" - }, - { - "Name": "port", - "Type": "System.Int32" - }, - { - "Name": "addr", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.SockAddr", - "Direction": "Out" - }, - { - "Name": "callback", - "Type": "System.AsyncCallback" - }, - { - "Name": "object", - "Type": "System.Object" - } - ], - "ReturnType": "System.IAsyncResult", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "EndInvoke", - "Parameters": [ - { - "Name": "addr", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.SockAddr", - "Direction": "Out" - }, - { - "Name": "result", - "Type": "System.IAsyncResult" - } - ], - "ReturnType": "System.Int32", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "object", - "Type": "System.Object" - }, - { - "Name": "method", - "Type": "System.IntPtr" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_walk_cb", - "Visibility": "Public", - "Kind": "Class", - "Sealed": true, - "BaseType": "System.MulticastDelegate", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "Invoke", - "Parameters": [ - { - "Name": "handle", - "Type": "System.IntPtr" - }, - { - "Name": "arg", - "Type": "System.IntPtr" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "BeginInvoke", - "Parameters": [ - { - "Name": "handle", - "Type": "System.IntPtr" - }, - { - "Name": "arg", - "Type": "System.IntPtr" - }, - { - "Name": "callback", - "Type": "System.AsyncCallback" - }, - { - "Name": "object", - "Type": "System.Object" - } - ], - "ReturnType": "System.IAsyncResult", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "EndInvoke", - "Parameters": [ - { - "Name": "result", - "Type": "System.IAsyncResult" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "object", - "Type": "System.Object" - }, - { - "Name": "method", - "Type": "System.IntPtr" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_tcp_getsockname_func", - "Visibility": "Public", - "Kind": "Class", - "Sealed": true, - "BaseType": "System.MulticastDelegate", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "Invoke", - "Parameters": [ - { - "Name": "handle", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvTcpHandle" - }, - { - "Name": "addr", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.SockAddr", - "Direction": "Out" - }, - { - "Name": "namelen", - "Type": "System.Int32", - "Direction": "Ref" - } - ], - "ReturnType": "System.Int32", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "BeginInvoke", - "Parameters": [ - { - "Name": "handle", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvTcpHandle" - }, - { - "Name": "addr", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.SockAddr", - "Direction": "Out" - }, - { - "Name": "namelen", - "Type": "System.Int32", - "Direction": "Ref" - }, - { - "Name": "callback", - "Type": "System.AsyncCallback" - }, - { - "Name": "object", - "Type": "System.Object" - } - ], - "ReturnType": "System.IAsyncResult", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "EndInvoke", - "Parameters": [ - { - "Name": "addr", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.SockAddr", - "Direction": "Out" - }, - { - "Name": "namelen", - "Type": "System.Int32", - "Direction": "Ref" - }, - { - "Name": "result", - "Type": "System.IAsyncResult" - } - ], - "ReturnType": "System.Int32", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "object", - "Type": "System.Object" - }, - { - "Name": "method", - "Type": "System.IntPtr" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_tcp_getpeername_func", - "Visibility": "Public", - "Kind": "Class", - "Sealed": true, - "BaseType": "System.MulticastDelegate", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "Invoke", - "Parameters": [ - { - "Name": "handle", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvTcpHandle" - }, - { - "Name": "addr", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.SockAddr", - "Direction": "Out" - }, - { - "Name": "namelen", - "Type": "System.Int32", - "Direction": "Ref" - } - ], - "ReturnType": "System.Int32", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "BeginInvoke", - "Parameters": [ - { - "Name": "handle", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvTcpHandle" - }, - { - "Name": "addr", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.SockAddr", - "Direction": "Out" - }, - { - "Name": "namelen", - "Type": "System.Int32", - "Direction": "Ref" - }, - { - "Name": "callback", - "Type": "System.AsyncCallback" - }, - { - "Name": "object", - "Type": "System.Object" - } - ], - "ReturnType": "System.IAsyncResult", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "EndInvoke", - "Parameters": [ - { - "Name": "addr", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.SockAddr", - "Direction": "Out" - }, - { - "Name": "namelen", - "Type": "System.Int32", - "Direction": "Ref" - }, - { - "Name": "result", - "Type": "System.IAsyncResult" - } - ], - "ReturnType": "System.Int32", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "object", - "Type": "System.Object" - }, - { - "Name": "method", - "Type": "System.IntPtr" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_buf_t", - "Visibility": "Public", - "Kind": "Struct", - "Sealed": true, - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "memory", - "Type": "System.IntPtr" - }, - { - "Name": "len", - "Type": "System.Int32" - }, - { - "Name": "IsWindows", - "Type": "System.Boolean" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+HandleType", - "Visibility": "Public", - "Kind": "Enumeration", - "Sealed": true, - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Field", - "Name": "Unknown", - "Parameters": [], - "GenericParameter": [], - "Literal": "0" - }, - { - "Kind": "Field", - "Name": "ASYNC", - "Parameters": [], - "GenericParameter": [], - "Literal": "1" - }, - { - "Kind": "Field", - "Name": "CHECK", - "Parameters": [], - "GenericParameter": [], - "Literal": "2" - }, - { - "Kind": "Field", - "Name": "FS_EVENT", - "Parameters": [], - "GenericParameter": [], - "Literal": "3" - }, - { - "Kind": "Field", - "Name": "FS_POLL", - "Parameters": [], - "GenericParameter": [], - "Literal": "4" - }, - { - "Kind": "Field", - "Name": "HANDLE", - "Parameters": [], - "GenericParameter": [], - "Literal": "5" - }, - { - "Kind": "Field", - "Name": "IDLE", - "Parameters": [], - "GenericParameter": [], - "Literal": "6" - }, - { - "Kind": "Field", - "Name": "NAMED_PIPE", - "Parameters": [], - "GenericParameter": [], - "Literal": "7" - }, - { - "Kind": "Field", - "Name": "POLL", - "Parameters": [], - "GenericParameter": [], - "Literal": "8" - }, - { - "Kind": "Field", - "Name": "PREPARE", - "Parameters": [], - "GenericParameter": [], - "Literal": "9" - }, - { - "Kind": "Field", - "Name": "PROCESS", - "Parameters": [], - "GenericParameter": [], - "Literal": "10" - }, - { - "Kind": "Field", - "Name": "STREAM", - "Parameters": [], - "GenericParameter": [], - "Literal": "11" - }, - { - "Kind": "Field", - "Name": "TCP", - "Parameters": [], - "GenericParameter": [], - "Literal": "12" - }, - { - "Kind": "Field", - "Name": "TIMER", - "Parameters": [], - "GenericParameter": [], - "Literal": "13" - }, - { - "Kind": "Field", - "Name": "TTY", - "Parameters": [], - "GenericParameter": [], - "Literal": "14" - }, - { - "Kind": "Field", - "Name": "UDP", - "Parameters": [], - "GenericParameter": [], - "Literal": "15" - }, - { - "Kind": "Field", - "Name": "SIGNAL", - "Parameters": [], - "GenericParameter": [], - "Literal": "16" - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+RequestType", - "Visibility": "Public", - "Kind": "Enumeration", - "Sealed": true, - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Field", - "Name": "Unknown", - "Parameters": [], - "GenericParameter": [], - "Literal": "0" - }, - { - "Kind": "Field", - "Name": "REQ", - "Parameters": [], - "GenericParameter": [], - "Literal": "1" - }, - { - "Kind": "Field", - "Name": "CONNECT", - "Parameters": [], - "GenericParameter": [], - "Literal": "2" - }, - { - "Kind": "Field", - "Name": "WRITE", - "Parameters": [], - "GenericParameter": [], - "Literal": "3" - }, - { - "Kind": "Field", - "Name": "SHUTDOWN", - "Parameters": [], - "GenericParameter": [], - "Literal": "4" - }, - { - "Kind": "Field", - "Name": "UDP_SEND", - "Parameters": [], - "GenericParameter": [], - "Literal": "5" - }, - { - "Kind": "Field", - "Name": "FS", - "Parameters": [], - "GenericParameter": [], - "Literal": "6" - }, - { - "Kind": "Field", - "Name": "WORK", - "Parameters": [], - "GenericParameter": [], - "Literal": "7" - }, - { - "Kind": "Field", - "Name": "GETADDRINFO", - "Parameters": [], - "GenericParameter": [], - "Literal": "8" - }, - { - "Kind": "Field", - "Name": "GETNAMEINFO", - "Parameters": [], - "GenericParameter": [], - "Literal": "9" - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.DateHeaderValueManager+DateHeaderValues", - "Visibility": "Public", - "Kind": "Class", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [], - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "Bytes", - "Parameters": [], - "ReturnType": "System.Byte[]", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "String", - "Parameters": [], - "ReturnType": "System.String", - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.Frame+RequestLineStatus", - "Visibility": "Protected", - "Kind": "Enumeration", - "Sealed": true, - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Field", - "Name": "Empty", - "Parameters": [], - "GenericParameter": [], - "Literal": "0" - }, - { - "Kind": "Field", - "Name": "MethodIncomplete", - "Parameters": [], - "GenericParameter": [], - "Literal": "1" - }, - { - "Kind": "Field", - "Name": "TargetIncomplete", - "Parameters": [], - "GenericParameter": [], - "Literal": "2" - }, - { - "Kind": "Field", - "Name": "VersionIncomplete", - "Parameters": [], - "GenericParameter": [], - "Literal": "3" - }, - { - "Kind": "Field", - "Name": "Incomplete", - "Parameters": [], - "GenericParameter": [], - "Literal": "4" - }, - { - "Kind": "Field", - "Name": "Done", - "Parameters": [], - "GenericParameter": [], - "Literal": "5" - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.Frame+RequestProcessingStatus", - "Visibility": "Protected", - "Kind": "Enumeration", - "Sealed": true, - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Field", - "Name": "RequestPending", - "Parameters": [], - "GenericParameter": [], - "Literal": "0" - }, - { - "Kind": "Field", - "Name": "RequestStarted", - "Parameters": [], - "GenericParameter": [], - "Literal": "1" - }, - { - "Kind": "Field", - "Name": "ResponseStarted", - "Parameters": [], - "GenericParameter": [], - "Literal": "2" - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.FrameRequestHeaders+Enumerator", - "Visibility": "Public", - "Kind": "Struct", - "Sealed": true, - "ImplementedInterfaces": [ - "System.Collections.Generic.IEnumerator>" - ], - "Members": [ - { - "Kind": "Method", - "Name": "MoveNext", - "Parameters": [], - "ReturnType": "System.Boolean", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "System.Collections.IEnumerator", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_Current", - "Parameters": [], - "ReturnType": "System.Collections.Generic.KeyValuePair", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "System.Collections.Generic.IEnumerator>", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Dispose", - "Parameters": [], - "ReturnType": "System.Void", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "System.IDisposable", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Reset", - "Parameters": [], - "ReturnType": "System.Void", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "System.Collections.IEnumerator", - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.FrameResponseHeaders+Enumerator", - "Visibility": "Public", - "Kind": "Struct", - "Sealed": true, - "ImplementedInterfaces": [ - "System.Collections.Generic.IEnumerator>" - ], - "Members": [ - { - "Kind": "Method", - "Name": "MoveNext", - "Parameters": [], - "ReturnType": "System.Boolean", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "System.Collections.IEnumerator", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_Current", - "Parameters": [], - "ReturnType": "System.Collections.Generic.KeyValuePair", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "System.Collections.Generic.IEnumerator>", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Dispose", - "Parameters": [], - "ReturnType": "System.Void", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "System.IDisposable", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Reset", - "Parameters": [], - "ReturnType": "System.Void", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "System.Collections.IEnumerator", - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - } - ] -} \ No newline at end of file diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/baseline.netcore.json b/src/Microsoft.AspNetCore.Server.Kestrel/baseline.netcore.json deleted file mode 100644 index e786e3a8e1..0000000000 --- a/src/Microsoft.AspNetCore.Server.Kestrel/baseline.netcore.json +++ /dev/null @@ -1,12700 +0,0 @@ -{ - "AssemblyIdentity": "Microsoft.AspNetCore.Server.Kestrel, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60", - "Types": [ - { - "Name": "Microsoft.AspNetCore.Hosting.WebHostBuilderKestrelExtensions", - "Visibility": "Public", - "Kind": "Class", - "Abstract": true, - "Static": true, - "Sealed": true, - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "UseKestrel", - "Parameters": [ - { - "Name": "hostBuilder", - "Type": "Microsoft.AspNetCore.Hosting.IWebHostBuilder" - } - ], - "ReturnType": "Microsoft.AspNetCore.Hosting.IWebHostBuilder", - "Static": true, - "Extension": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "UseKestrel", - "Parameters": [ - { - "Name": "hostBuilder", - "Type": "Microsoft.AspNetCore.Hosting.IWebHostBuilder" - }, - { - "Name": "options", - "Type": "System.Action" - } - ], - "ReturnType": "Microsoft.AspNetCore.Hosting.IWebHostBuilder", - "Static": true, - "Extension": true, - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Hosting.KestrelServerOptionsConnectionLoggingExtensions", - "Visibility": "Public", - "Kind": "Class", - "Abstract": true, - "Static": true, - "Sealed": true, - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "UseConnectionLogging", - "Parameters": [ - { - "Name": "options", - "Type": "Microsoft.AspNetCore.Server.Kestrel.KestrelServerOptions" - } - ], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.KestrelServerOptions", - "Static": true, - "Extension": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "UseConnectionLogging", - "Parameters": [ - { - "Name": "options", - "Type": "Microsoft.AspNetCore.Server.Kestrel.KestrelServerOptions" - }, - { - "Name": "loggerName", - "Type": "System.String" - } - ], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.KestrelServerOptions", - "Static": true, - "Extension": true, - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.BadHttpRequestException", - "Visibility": "Public", - "Kind": "Class", - "Sealed": true, - "BaseType": "System.IO.IOException", - "ImplementedInterfaces": [], - "Members": [], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.KestrelServer", - "Visibility": "Public", - "Kind": "Class", - "ImplementedInterfaces": [ - "Microsoft.AspNetCore.Hosting.Server.IServer" - ], - "Members": [ - { - "Kind": "Method", - "Name": "get_Features", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Http.Features.IFeatureCollection", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Hosting.Server.IServer", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_Options", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.KestrelServerOptions", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Start", - "Parameters": [ - { - "Name": "application", - "Type": "Microsoft.AspNetCore.Hosting.Server.IHttpApplication" - } - ], - "ReturnType": "System.Void", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Hosting.Server.IServer", - "Visibility": "Public", - "GenericParameter": [ - { - "ParameterName": "TContext", - "ParameterPosition": 0, - "BaseTypeOrInterfaces": [] - } - ] - }, - { - "Kind": "Method", - "Name": "Dispose", - "Parameters": [], - "ReturnType": "System.Void", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "System.IDisposable", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "options", - "Type": "Microsoft.Extensions.Options.IOptions" - }, - { - "Name": "applicationLifetime", - "Type": "Microsoft.AspNetCore.Hosting.IApplicationLifetime" - }, - { - "Name": "loggerFactory", - "Type": "Microsoft.Extensions.Logging.ILoggerFactory" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.KestrelServerOptions", - "Visibility": "Public", - "Kind": "Class", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "get_AddServerHeader", - "Parameters": [], - "ReturnType": "System.Boolean", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_AddServerHeader", - "Parameters": [ - { - "Name": "value", - "Type": "System.Boolean" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_ApplicationServices", - "Parameters": [], - "ReturnType": "System.IServiceProvider", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_ApplicationServices", - "Parameters": [ - { - "Name": "value", - "Type": "System.IServiceProvider" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_ConnectionFilter", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Filter.IConnectionFilter", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_ConnectionFilter", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Filter.IConnectionFilter" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_MaxRequestBufferSize", - "Parameters": [], - "ReturnType": "System.Nullable", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_MaxRequestBufferSize", - "Parameters": [ - { - "Name": "value", - "Type": "System.Nullable" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_NoDelay", - "Parameters": [], - "ReturnType": "System.Boolean", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_NoDelay", - "Parameters": [ - { - "Name": "value", - "Type": "System.Boolean" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_ShutdownTimeout", - "Parameters": [], - "ReturnType": "System.TimeSpan", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_ShutdownTimeout", - "Parameters": [ - { - "Name": "value", - "Type": "System.TimeSpan" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_ThreadCount", - "Parameters": [], - "ReturnType": "System.Int32", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_ThreadCount", - "Parameters": [ - { - "Name": "value", - "Type": "System.Int32" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.ServerAddress", - "Visibility": "Public", - "Kind": "Class", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "get_Host", - "Parameters": [], - "ReturnType": "System.String", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_PathBase", - "Parameters": [], - "ReturnType": "System.String", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_Port", - "Parameters": [], - "ReturnType": "System.Int32", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_Scheme", - "Parameters": [], - "ReturnType": "System.String", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_IsUnixPipe", - "Parameters": [], - "ReturnType": "System.Boolean", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_UnixPipePath", - "Parameters": [], - "ReturnType": "System.String", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ToString", - "Parameters": [], - "ReturnType": "System.String", - "Virtual": true, - "Override": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "GetHashCode", - "Parameters": [], - "ReturnType": "System.Int32", - "Virtual": true, - "Override": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Equals", - "Parameters": [ - { - "Name": "obj", - "Type": "System.Object" - } - ], - "ReturnType": "System.Boolean", - "Virtual": true, - "Override": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "FromUrl", - "Parameters": [ - { - "Name": "url", - "Type": "System.String" - } - ], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.ServerAddress", - "Static": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.KestrelEngine", - "Visibility": "Public", - "Kind": "Class", - "BaseType": "Microsoft.AspNetCore.Server.Kestrel.Internal.ServiceContext", - "ImplementedInterfaces": [ - "System.IDisposable" - ], - "Members": [ - { - "Kind": "Method", - "Name": "get_Libuv", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_Threads", - "Parameters": [], - "ReturnType": "System.Collections.Generic.List", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Start", - "Parameters": [ - { - "Name": "count", - "Type": "System.Int32" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Dispose", - "Parameters": [], - "ReturnType": "System.Void", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "System.IDisposable", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "CreateServer", - "Parameters": [ - { - "Name": "address", - "Type": "Microsoft.AspNetCore.Server.Kestrel.ServerAddress" - } - ], - "ReturnType": "System.IDisposable", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "context", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.ServiceContext" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.KestrelServerOptionsSetup", - "Visibility": "Public", - "Kind": "Class", - "ImplementedInterfaces": [ - "Microsoft.Extensions.Options.IConfigureOptions" - ], - "Members": [ - { - "Kind": "Method", - "Name": "Configure", - "Parameters": [ - { - "Name": "options", - "Type": "Microsoft.AspNetCore.Server.Kestrel.KestrelServerOptions" - } - ], - "ReturnType": "System.Void", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "Microsoft.Extensions.Options.IConfigureOptions", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "services", - "Type": "System.IServiceProvider" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.ServiceContext", - "Visibility": "Public", - "Kind": "Class", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "get_AppLifetime", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Hosting.IApplicationLifetime", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_AppLifetime", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.AspNetCore.Hosting.IApplicationLifetime" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_Log", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IKestrelTrace", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_Log", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IKestrelTrace" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_ThreadPool", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IThreadPool", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_ThreadPool", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IThreadPool" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_FrameFactory", - "Parameters": [], - "ReturnType": "System.Func", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_FrameFactory", - "Parameters": [ - { - "Name": "value", - "Type": "System.Func" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_DateHeaderValueManager", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.DateHeaderValueManager", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_DateHeaderValueManager", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.DateHeaderValueManager" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_ServerOptions", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.KestrelServerOptions", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_ServerOptions", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.AspNetCore.Server.Kestrel.KestrelServerOptions" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [], - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "context", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.ServiceContext" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Disposable", - "Visibility": "Public", - "Kind": "Class", - "ImplementedInterfaces": [ - "System.IDisposable" - ], - "Members": [ - { - "Kind": "Method", - "Name": "Dispose", - "Parameters": [ - { - "Name": "disposing", - "Type": "System.Boolean" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Dispose", - "Parameters": [], - "ReturnType": "System.Void", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "System.IDisposable", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "dispose", - "Type": "System.Action" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.KestrelThread", - "Visibility": "Public", - "Kind": "Class", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "get_Loop", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvLoopHandle", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_FatalError", - "Parameters": [], - "ReturnType": "System.Runtime.ExceptionServices.ExceptionDispatchInfo", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_QueueCloseHandle", - "Parameters": [], - "ReturnType": "System.Action, System.IntPtr>", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "StartAsync", - "Parameters": [], - "ReturnType": "System.Threading.Tasks.Task", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "AllowStop", - "Parameters": [], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Stop", - "Parameters": [ - { - "Name": "timeout", - "Type": "System.TimeSpan" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Post", - "Parameters": [ - { - "Name": "callback", - "Type": "System.Action" - }, - { - "Name": "state", - "Type": "System.Object" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "PostAsync", - "Parameters": [ - { - "Name": "callback", - "Type": "System.Action" - }, - { - "Name": "state", - "Type": "System.Object" - } - ], - "ReturnType": "System.Threading.Tasks.Task", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Walk", - "Parameters": [ - { - "Name": "callback", - "Type": "System.Action" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "engine", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.KestrelEngine" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.KestrelTrace", - "Visibility": "Public", - "Kind": "Class", - "ImplementedInterfaces": [ - "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IKestrelTrace" - ], - "Members": [ - { - "Kind": "Method", - "Name": "ConnectionStart", - "Parameters": [ - { - "Name": "connectionId", - "Type": "System.String" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IKestrelTrace", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ConnectionStop", - "Parameters": [ - { - "Name": "connectionId", - "Type": "System.String" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IKestrelTrace", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ConnectionRead", - "Parameters": [ - { - "Name": "connectionId", - "Type": "System.String" - }, - { - "Name": "count", - "Type": "System.Int32" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IKestrelTrace", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ConnectionPause", - "Parameters": [ - { - "Name": "connectionId", - "Type": "System.String" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IKestrelTrace", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ConnectionResume", - "Parameters": [ - { - "Name": "connectionId", - "Type": "System.String" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IKestrelTrace", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ConnectionReadFin", - "Parameters": [ - { - "Name": "connectionId", - "Type": "System.String" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IKestrelTrace", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ConnectionWriteFin", - "Parameters": [ - { - "Name": "connectionId", - "Type": "System.String" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IKestrelTrace", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ConnectionWroteFin", - "Parameters": [ - { - "Name": "connectionId", - "Type": "System.String" - }, - { - "Name": "status", - "Type": "System.Int32" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IKestrelTrace", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ConnectionKeepAlive", - "Parameters": [ - { - "Name": "connectionId", - "Type": "System.String" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IKestrelTrace", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ConnectionDisconnect", - "Parameters": [ - { - "Name": "connectionId", - "Type": "System.String" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IKestrelTrace", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ConnectionWrite", - "Parameters": [ - { - "Name": "connectionId", - "Type": "System.String" - }, - { - "Name": "count", - "Type": "System.Int32" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IKestrelTrace", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ConnectionWriteCallback", - "Parameters": [ - { - "Name": "connectionId", - "Type": "System.String" - }, - { - "Name": "status", - "Type": "System.Int32" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IKestrelTrace", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ApplicationError", - "Parameters": [ - { - "Name": "connectionId", - "Type": "System.String" - }, - { - "Name": "ex", - "Type": "System.Exception" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IKestrelTrace", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ConnectionError", - "Parameters": [ - { - "Name": "connectionId", - "Type": "System.String" - }, - { - "Name": "ex", - "Type": "System.Exception" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IKestrelTrace", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ConnectionDisconnectedWrite", - "Parameters": [ - { - "Name": "connectionId", - "Type": "System.String" - }, - { - "Name": "count", - "Type": "System.Int32" - }, - { - "Name": "ex", - "Type": "System.Exception" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IKestrelTrace", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "NotAllConnectionsClosedGracefully", - "Parameters": [], - "ReturnType": "System.Void", - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IKestrelTrace", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ConnectionBadRequest", - "Parameters": [ - { - "Name": "connectionId", - "Type": "System.String" - }, - { - "Name": "ex", - "Type": "Microsoft.AspNetCore.Server.Kestrel.BadHttpRequestException" - } - ], - "ReturnType": "System.Void", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IKestrelTrace", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Log", - "Parameters": [ - { - "Name": "logLevel", - "Type": "Microsoft.Extensions.Logging.LogLevel" - }, - { - "Name": "eventId", - "Type": "Microsoft.Extensions.Logging.EventId" - }, - { - "Name": "state", - "Type": "T0" - }, - { - "Name": "exception", - "Type": "System.Exception" - }, - { - "Name": "formatter", - "Type": "System.Func" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "ImplementedInterface": "Microsoft.Extensions.Logging.ILogger", - "Visibility": "Public", - "GenericParameter": [ - { - "ParameterName": "TState", - "ParameterPosition": 0, - "BaseTypeOrInterfaces": [] - } - ] - }, - { - "Kind": "Method", - "Name": "IsEnabled", - "Parameters": [ - { - "Name": "logLevel", - "Type": "Microsoft.Extensions.Logging.LogLevel" - } - ], - "ReturnType": "System.Boolean", - "Virtual": true, - "ImplementedInterface": "Microsoft.Extensions.Logging.ILogger", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "BeginScope", - "Parameters": [ - { - "Name": "state", - "Type": "T0" - } - ], - "ReturnType": "System.IDisposable", - "Virtual": true, - "ImplementedInterface": "Microsoft.Extensions.Logging.ILogger", - "Visibility": "Public", - "GenericParameter": [ - { - "ParameterName": "TState", - "ParameterPosition": 0, - "BaseTypeOrInterfaces": [] - } - ] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "logger", - "Type": "Microsoft.Extensions.Logging.ILogger" - } - ], - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "_logger", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Logging.ILogger", - "ReadOnly": true, - "Visibility": "Protected", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv", - "Visibility": "Public", - "Kind": "Class", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "Check", - "Parameters": [ - { - "Name": "statusCode", - "Type": "System.Int32" - } - ], - "ReturnType": "System.Int32", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Check", - "Parameters": [ - { - "Name": "statusCode", - "Type": "System.Int32" - }, - { - "Name": "error", - "Type": "System.Exception", - "Direction": "Out" - } - ], - "ReturnType": "System.Int32", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "loop_init", - "Parameters": [ - { - "Name": "handle", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvLoopHandle" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "loop_close", - "Parameters": [ - { - "Name": "handle", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvLoopHandle" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "run", - "Parameters": [ - { - "Name": "handle", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvLoopHandle" - }, - { - "Name": "mode", - "Type": "System.Int32" - } - ], - "ReturnType": "System.Int32", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "stop", - "Parameters": [ - { - "Name": "handle", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvLoopHandle" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ref", - "Parameters": [ - { - "Name": "handle", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvHandle" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "unref", - "Parameters": [ - { - "Name": "handle", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvHandle" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "uv_fileno", - "Parameters": [ - { - "Name": "handle", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvHandle" - }, - { - "Name": "socket", - "Type": "System.IntPtr", - "Direction": "Ref" - } - ], - "ReturnType": "System.Int32", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "close", - "Parameters": [ - { - "Name": "handle", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvHandle" - }, - { - "Name": "close_cb", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_close_cb" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "close", - "Parameters": [ - { - "Name": "handle", - "Type": "System.IntPtr" - }, - { - "Name": "close_cb", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_close_cb" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "async_init", - "Parameters": [ - { - "Name": "loop", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvLoopHandle" - }, - { - "Name": "handle", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvAsyncHandle" - }, - { - "Name": "cb", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_async_cb" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "async_send", - "Parameters": [ - { - "Name": "handle", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvAsyncHandle" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "unsafe_async_send", - "Parameters": [ - { - "Name": "handle", - "Type": "System.IntPtr" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "tcp_init", - "Parameters": [ - { - "Name": "loop", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvLoopHandle" - }, - { - "Name": "handle", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvTcpHandle" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "tcp_bind", - "Parameters": [ - { - "Name": "handle", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvTcpHandle" - }, - { - "Name": "addr", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.SockAddr", - "Direction": "Ref" - }, - { - "Name": "flags", - "Type": "System.Int32" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "tcp_open", - "Parameters": [ - { - "Name": "handle", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvTcpHandle" - }, - { - "Name": "hSocket", - "Type": "System.IntPtr" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "tcp_nodelay", - "Parameters": [ - { - "Name": "handle", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvTcpHandle" - }, - { - "Name": "enable", - "Type": "System.Boolean" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "pipe_init", - "Parameters": [ - { - "Name": "loop", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvLoopHandle" - }, - { - "Name": "handle", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvPipeHandle" - }, - { - "Name": "ipc", - "Type": "System.Boolean" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "pipe_bind", - "Parameters": [ - { - "Name": "handle", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvPipeHandle" - }, - { - "Name": "name", - "Type": "System.String" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "listen", - "Parameters": [ - { - "Name": "handle", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle" - }, - { - "Name": "backlog", - "Type": "System.Int32" - }, - { - "Name": "cb", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_connection_cb" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "accept", - "Parameters": [ - { - "Name": "server", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle" - }, - { - "Name": "client", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "pipe_connect", - "Parameters": [ - { - "Name": "req", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvConnectRequest" - }, - { - "Name": "handle", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvPipeHandle" - }, - { - "Name": "name", - "Type": "System.String" - }, - { - "Name": "cb", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_connect_cb" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "pipe_pending_count", - "Parameters": [ - { - "Name": "handle", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvPipeHandle" - } - ], - "ReturnType": "System.Int32", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "read_start", - "Parameters": [ - { - "Name": "handle", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle" - }, - { - "Name": "alloc_cb", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_alloc_cb" - }, - { - "Name": "read_cb", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_read_cb" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "read_stop", - "Parameters": [ - { - "Name": "handle", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "try_write", - "Parameters": [ - { - "Name": "handle", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle" - }, - { - "Name": "bufs", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_buf_t[]" - }, - { - "Name": "nbufs", - "Type": "System.Int32" - } - ], - "ReturnType": "System.Int32", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "write", - "Parameters": [ - { - "Name": "req", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvRequest" - }, - { - "Name": "handle", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle" - }, - { - "Name": "bufs", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_buf_t*" - }, - { - "Name": "nbufs", - "Type": "System.Int32" - }, - { - "Name": "cb", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_write_cb" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "write2", - "Parameters": [ - { - "Name": "req", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvRequest" - }, - { - "Name": "handle", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle" - }, - { - "Name": "bufs", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_buf_t*" - }, - { - "Name": "nbufs", - "Type": "System.Int32" - }, - { - "Name": "sendHandle", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle" - }, - { - "Name": "cb", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_write_cb" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "shutdown", - "Parameters": [ - { - "Name": "req", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvShutdownReq" - }, - { - "Name": "handle", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle" - }, - { - "Name": "cb", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_shutdown_cb" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "err_name", - "Parameters": [ - { - "Name": "err", - "Type": "System.Int32" - } - ], - "ReturnType": "System.String", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "strerror", - "Parameters": [ - { - "Name": "err", - "Type": "System.Int32" - } - ], - "ReturnType": "System.String", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "loop_size", - "Parameters": [], - "ReturnType": "System.Int32", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "handle_size", - "Parameters": [ - { - "Name": "handleType", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+HandleType" - } - ], - "ReturnType": "System.Int32", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "req_size", - "Parameters": [ - { - "Name": "reqType", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+RequestType" - } - ], - "ReturnType": "System.Int32", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ip4_addr", - "Parameters": [ - { - "Name": "ip", - "Type": "System.String" - }, - { - "Name": "port", - "Type": "System.Int32" - }, - { - "Name": "addr", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.SockAddr", - "Direction": "Out" - }, - { - "Name": "error", - "Type": "System.Exception", - "Direction": "Out" - } - ], - "ReturnType": "System.Int32", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ip6_addr", - "Parameters": [ - { - "Name": "ip", - "Type": "System.String" - }, - { - "Name": "port", - "Type": "System.Int32" - }, - { - "Name": "addr", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.SockAddr", - "Direction": "Out" - }, - { - "Name": "error", - "Type": "System.Exception", - "Direction": "Out" - } - ], - "ReturnType": "System.Int32", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "walk", - "Parameters": [ - { - "Name": "loop", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvLoopHandle" - }, - { - "Name": "walk_cb", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_walk_cb" - }, - { - "Name": "arg", - "Type": "System.IntPtr" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "tcp_getsockname", - "Parameters": [ - { - "Name": "handle", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvTcpHandle" - }, - { - "Name": "addr", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.SockAddr", - "Direction": "Out" - }, - { - "Name": "namelen", - "Type": "System.Int32", - "Direction": "Ref" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "tcp_getpeername", - "Parameters": [ - { - "Name": "handle", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvTcpHandle" - }, - { - "Name": "addr", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.SockAddr", - "Direction": "Out" - }, - { - "Name": "namelen", - "Type": "System.Int32", - "Direction": "Ref" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "buf_init", - "Parameters": [ - { - "Name": "memory", - "Type": "System.IntPtr" - }, - { - "Name": "len", - "Type": "System.Int32" - } - ], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_buf_t", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [], - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "IsWindows", - "Parameters": [], - "ReturnType": "System.Boolean", - "ReadOnly": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "_uv_loop_init", - "Parameters": [], - "ReturnType": "System.Func", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "_uv_loop_close", - "Parameters": [], - "ReturnType": "System.Func", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "_uv_run", - "Parameters": [], - "ReturnType": "System.Func", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "_uv_stop", - "Parameters": [], - "ReturnType": "System.Action", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "_uv_ref", - "Parameters": [], - "ReturnType": "System.Action", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "_uv_unref", - "Parameters": [], - "ReturnType": "System.Action", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "_uv_fileno", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_fileno_func", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "_uv_close", - "Parameters": [], - "ReturnType": "System.Action", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "_uv_async_init", - "Parameters": [], - "ReturnType": "System.Func", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "_uv_async_send", - "Parameters": [], - "ReturnType": "System.Func", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "_uv_unsafe_async_send", - "Parameters": [], - "ReturnType": "System.Func", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "_uv_tcp_init", - "Parameters": [], - "ReturnType": "System.Func", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "_uv_tcp_bind", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_tcp_bind_func", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "_uv_tcp_open", - "Parameters": [], - "ReturnType": "System.Func", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "_uv_tcp_nodelay", - "Parameters": [], - "ReturnType": "System.Func", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "_uv_pipe_init", - "Parameters": [], - "ReturnType": "System.Func", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "_uv_pipe_bind", - "Parameters": [], - "ReturnType": "System.Func", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "_uv_listen", - "Parameters": [], - "ReturnType": "System.Func", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "_uv_accept", - "Parameters": [], - "ReturnType": "System.Func", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "_uv_pipe_connect", - "Parameters": [], - "ReturnType": "System.Action", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "_uv_pipe_pending_count", - "Parameters": [], - "ReturnType": "System.Func", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "_uv_read_start", - "Parameters": [], - "ReturnType": "System.Func", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "_uv_read_stop", - "Parameters": [], - "ReturnType": "System.Func", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "_uv_try_write", - "Parameters": [], - "ReturnType": "System.Func", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "_uv_write", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_write_func", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "_uv_write2", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_write2_func", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "_uv_shutdown", - "Parameters": [], - "ReturnType": "System.Func", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "_uv_err_name", - "Parameters": [], - "ReturnType": "System.Func", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "_uv_strerror", - "Parameters": [], - "ReturnType": "System.Func", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "_uv_loop_size", - "Parameters": [], - "ReturnType": "System.Func", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "_uv_handle_size", - "Parameters": [], - "ReturnType": "System.Func", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "_uv_req_size", - "Parameters": [], - "ReturnType": "System.Func", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "_uv_ip4_addr", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_ip4_addr_func", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "_uv_ip6_addr", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_ip6_addr_func", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "_uv_walk", - "Parameters": [], - "ReturnType": "System.Func", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "_uv_tcp_getsockname", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_tcp_getsockname_func", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "_uv_tcp_getpeername", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_tcp_getpeername_func", - "Visibility": "Protected", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.PlatformApis", - "Visibility": "Public", - "Kind": "Class", - "Abstract": true, - "Static": true, - "Sealed": true, - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "get_IsWindows", - "Parameters": [], - "ReturnType": "System.Boolean", - "Static": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_IsDarwin", - "Parameters": [], - "ReturnType": "System.Boolean", - "Static": true, - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.SockAddr", - "Visibility": "Public", - "Kind": "Struct", - "Sealed": true, - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "GetIPEndPoint", - "Parameters": [], - "ReturnType": "System.Net.IPEndPoint", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "ignored", - "Type": "System.Int64" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvAsyncHandle", - "Visibility": "Public", - "Kind": "Class", - "BaseType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvHandle", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "Init", - "Parameters": [ - { - "Name": "loop", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvLoopHandle" - }, - { - "Name": "callback", - "Type": "System.Action" - }, - { - "Name": "queueCloseHandle", - "Type": "System.Action, System.IntPtr>" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Send", - "Parameters": [], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ReleaseHandle", - "Parameters": [], - "ReturnType": "System.Boolean", - "Virtual": true, - "Override": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "logger", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IKestrelTrace" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvConnectRequest", - "Visibility": "Public", - "Kind": "Class", - "BaseType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvRequest", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "Init", - "Parameters": [ - { - "Name": "loop", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvLoopHandle" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Connect", - "Parameters": [ - { - "Name": "pipe", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvPipeHandle" - }, - { - "Name": "name", - "Type": "System.String" - }, - { - "Name": "callback", - "Type": "System.Action" - }, - { - "Name": "state", - "Type": "System.Object" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "logger", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IKestrelTrace" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvException", - "Visibility": "Public", - "Kind": "Class", - "BaseType": "System.Exception", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "get_StatusCode", - "Parameters": [], - "ReturnType": "System.Int32", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "message", - "Type": "System.String" - }, - { - "Name": "statusCode", - "Type": "System.Int32" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvHandle", - "Visibility": "Public", - "Kind": "Class", - "Abstract": true, - "BaseType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvMemory", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "CreateHandle", - "Parameters": [ - { - "Name": "uv", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv" - }, - { - "Name": "threadId", - "Type": "System.Int32" - }, - { - "Name": "size", - "Type": "System.Int32" - }, - { - "Name": "queueCloseHandle", - "Type": "System.Action, System.IntPtr>" - } - ], - "ReturnType": "System.Void", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ReleaseHandle", - "Parameters": [], - "ReturnType": "System.Boolean", - "Virtual": true, - "Override": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Reference", - "Parameters": [], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Unreference", - "Parameters": [], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "logger", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IKestrelTrace" - } - ], - "Visibility": "Protected", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvLoopHandle", - "Visibility": "Public", - "Kind": "Class", - "BaseType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvMemory", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "Init", - "Parameters": [ - { - "Name": "uv", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Run", - "Parameters": [ - { - "Name": "mode", - "Type": "System.Int32", - "DefaultValue": "0" - } - ], - "ReturnType": "System.Int32", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Stop", - "Parameters": [], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ReleaseHandle", - "Parameters": [], - "ReturnType": "System.Boolean", - "Virtual": true, - "Override": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "logger", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IKestrelTrace" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvMemory", - "Visibility": "Public", - "Kind": "Class", - "Abstract": true, - "BaseType": "System.Runtime.InteropServices.SafeHandle", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "get_Libuv", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_IsInvalid", - "Parameters": [], - "ReturnType": "System.Boolean", - "Virtual": true, - "Override": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_ThreadId", - "Parameters": [], - "ReturnType": "System.Int32", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "CreateMemory", - "Parameters": [ - { - "Name": "uv", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv" - }, - { - "Name": "threadId", - "Type": "System.Int32" - }, - { - "Name": "size", - "Type": "System.Int32" - } - ], - "ReturnType": "System.Void", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "DestroyMemory", - "Parameters": [ - { - "Name": "memory", - "Type": "System.IntPtr" - } - ], - "ReturnType": "System.Void", - "Static": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "DestroyMemory", - "Parameters": [ - { - "Name": "memory", - "Type": "System.IntPtr" - }, - { - "Name": "gcHandlePtr", - "Type": "System.IntPtr" - } - ], - "ReturnType": "System.Void", - "Static": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Validate", - "Parameters": [ - { - "Name": "closed", - "Type": "System.Boolean", - "DefaultValue": "False" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "FromIntPtr", - "Parameters": [ - { - "Name": "handle", - "Type": "System.IntPtr" - } - ], - "ReturnType": "T0", - "Static": true, - "Visibility": "Public", - "GenericParameter": [ - { - "ParameterName": "THandle", - "ParameterPosition": 0, - "BaseTypeOrInterfaces": [] - } - ] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "logger", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IKestrelTrace" - } - ], - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "_uv", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "_threadId", - "Parameters": [], - "ReturnType": "System.Int32", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "_log", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IKestrelTrace", - "ReadOnly": true, - "Visibility": "Protected", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvPipeHandle", - "Visibility": "Public", - "Kind": "Class", - "BaseType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "Init", - "Parameters": [ - { - "Name": "loop", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvLoopHandle" - }, - { - "Name": "queueCloseHandle", - "Type": "System.Action, System.IntPtr>" - }, - { - "Name": "ipc", - "Type": "System.Boolean", - "DefaultValue": "False" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Bind", - "Parameters": [ - { - "Name": "name", - "Type": "System.String" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "PendingCount", - "Parameters": [], - "ReturnType": "System.Int32", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "logger", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IKestrelTrace" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvRequest", - "Visibility": "Public", - "Kind": "Class", - "BaseType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvMemory", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "ReleaseHandle", - "Parameters": [], - "ReturnType": "System.Boolean", - "Virtual": true, - "Override": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Pin", - "Parameters": [], - "ReturnType": "System.Void", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Unpin", - "Parameters": [], - "ReturnType": "System.Void", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "logger", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IKestrelTrace" - } - ], - "Visibility": "Protected", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvShutdownReq", - "Visibility": "Public", - "Kind": "Class", - "BaseType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvRequest", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "Init", - "Parameters": [ - { - "Name": "loop", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvLoopHandle" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Shutdown", - "Parameters": [ - { - "Name": "handle", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle" - }, - { - "Name": "callback", - "Type": "System.Action" - }, - { - "Name": "state", - "Type": "System.Object" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "logger", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IKestrelTrace" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle", - "Visibility": "Public", - "Kind": "Class", - "Abstract": true, - "BaseType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvHandle", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "get_Connection", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.Connection", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_Connection", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.Connection" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ReleaseHandle", - "Parameters": [], - "ReturnType": "System.Boolean", - "Virtual": true, - "Override": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Listen", - "Parameters": [ - { - "Name": "backlog", - "Type": "System.Int32" - }, - { - "Name": "callback", - "Type": "System.Action" - }, - { - "Name": "state", - "Type": "System.Object" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Accept", - "Parameters": [ - { - "Name": "handle", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ReadStart", - "Parameters": [ - { - "Name": "allocCallback", - "Type": "System.Func" - }, - { - "Name": "readCallback", - "Type": "System.Action" - }, - { - "Name": "state", - "Type": "System.Object" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ReadStop", - "Parameters": [], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "TryWrite", - "Parameters": [ - { - "Name": "buf", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_buf_t" - } - ], - "ReturnType": "System.Int32", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "logger", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IKestrelTrace" - } - ], - "Visibility": "Protected", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvTcpHandle", - "Visibility": "Public", - "Kind": "Class", - "BaseType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "Init", - "Parameters": [ - { - "Name": "loop", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvLoopHandle" - }, - { - "Name": "queueCloseHandle", - "Type": "System.Action, System.IntPtr>" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Bind", - "Parameters": [ - { - "Name": "address", - "Type": "Microsoft.AspNetCore.Server.Kestrel.ServerAddress" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "GetPeerIPEndPoint", - "Parameters": [], - "ReturnType": "System.Net.IPEndPoint", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "GetSockIPEndPoint", - "Parameters": [], - "ReturnType": "System.Net.IPEndPoint", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Open", - "Parameters": [ - { - "Name": "hSocket", - "Type": "System.IntPtr" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "NoDelay", - "Parameters": [ - { - "Name": "enable", - "Type": "System.Boolean" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "CreateIPEndpoint", - "Parameters": [ - { - "Name": "address", - "Type": "Microsoft.AspNetCore.Server.Kestrel.ServerAddress" - } - ], - "ReturnType": "System.Net.IPEndPoint", - "Static": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "logger", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IKestrelTrace" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvWriteReq", - "Visibility": "Public", - "Kind": "Class", - "BaseType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvRequest", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "Init", - "Parameters": [ - { - "Name": "loop", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvLoopHandle" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Write", - "Parameters": [ - { - "Name": "handle", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle" - }, - { - "Name": "start", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolIterator" - }, - { - "Name": "end", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolIterator" - }, - { - "Name": "nBuffers", - "Type": "System.Int32" - }, - { - "Name": "callback", - "Type": "System.Action" - }, - { - "Name": "state", - "Type": "System.Object" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Write2", - "Parameters": [ - { - "Name": "handle", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle" - }, - { - "Name": "bufs", - "Type": "System.ArraySegment>" - }, - { - "Name": "sendHandle", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle" - }, - { - "Name": "callback", - "Type": "System.Action" - }, - { - "Name": "state", - "Type": "System.Object" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "logger", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IKestrelTrace" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IKestrelTrace", - "Visibility": "Public", - "Kind": "Interface", - "Abstract": true, - "ImplementedInterfaces": [ - "Microsoft.Extensions.Logging.ILogger" - ], - "Members": [ - { - "Kind": "Method", - "Name": "ConnectionStart", - "Parameters": [ - { - "Name": "connectionId", - "Type": "System.String" - } - ], - "ReturnType": "System.Void", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ConnectionStop", - "Parameters": [ - { - "Name": "connectionId", - "Type": "System.String" - } - ], - "ReturnType": "System.Void", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ConnectionRead", - "Parameters": [ - { - "Name": "connectionId", - "Type": "System.String" - }, - { - "Name": "count", - "Type": "System.Int32" - } - ], - "ReturnType": "System.Void", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ConnectionPause", - "Parameters": [ - { - "Name": "connectionId", - "Type": "System.String" - } - ], - "ReturnType": "System.Void", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ConnectionResume", - "Parameters": [ - { - "Name": "connectionId", - "Type": "System.String" - } - ], - "ReturnType": "System.Void", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ConnectionReadFin", - "Parameters": [ - { - "Name": "connectionId", - "Type": "System.String" - } - ], - "ReturnType": "System.Void", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ConnectionWriteFin", - "Parameters": [ - { - "Name": "connectionId", - "Type": "System.String" - } - ], - "ReturnType": "System.Void", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ConnectionWroteFin", - "Parameters": [ - { - "Name": "connectionId", - "Type": "System.String" - }, - { - "Name": "status", - "Type": "System.Int32" - } - ], - "ReturnType": "System.Void", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ConnectionKeepAlive", - "Parameters": [ - { - "Name": "connectionId", - "Type": "System.String" - } - ], - "ReturnType": "System.Void", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ConnectionDisconnect", - "Parameters": [ - { - "Name": "connectionId", - "Type": "System.String" - } - ], - "ReturnType": "System.Void", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ConnectionWrite", - "Parameters": [ - { - "Name": "connectionId", - "Type": "System.String" - }, - { - "Name": "count", - "Type": "System.Int32" - } - ], - "ReturnType": "System.Void", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ConnectionWriteCallback", - "Parameters": [ - { - "Name": "connectionId", - "Type": "System.String" - }, - { - "Name": "status", - "Type": "System.Int32" - } - ], - "ReturnType": "System.Void", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ConnectionError", - "Parameters": [ - { - "Name": "connectionId", - "Type": "System.String" - }, - { - "Name": "ex", - "Type": "System.Exception" - } - ], - "ReturnType": "System.Void", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ConnectionDisconnectedWrite", - "Parameters": [ - { - "Name": "connectionId", - "Type": "System.String" - }, - { - "Name": "count", - "Type": "System.Int32" - }, - { - "Name": "ex", - "Type": "System.Exception" - } - ], - "ReturnType": "System.Void", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ConnectionBadRequest", - "Parameters": [ - { - "Name": "connectionId", - "Type": "System.String" - }, - { - "Name": "ex", - "Type": "Microsoft.AspNetCore.Server.Kestrel.BadHttpRequestException" - } - ], - "ReturnType": "System.Void", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "NotAllConnectionsClosedGracefully", - "Parameters": [], - "ReturnType": "System.Void", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ApplicationError", - "Parameters": [ - { - "Name": "connectionId", - "Type": "System.String" - }, - { - "Name": "ex", - "Type": "System.Exception" - } - ], - "ReturnType": "System.Void", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IThreadPool", - "Visibility": "Public", - "Kind": "Interface", - "Abstract": true, - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "Complete", - "Parameters": [ - { - "Name": "tcs", - "Type": "System.Threading.Tasks.TaskCompletionSource" - } - ], - "ReturnType": "System.Void", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Cancel", - "Parameters": [ - { - "Name": "tcs", - "Type": "System.Threading.Tasks.TaskCompletionSource" - } - ], - "ReturnType": "System.Void", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Error", - "Parameters": [ - { - "Name": "tcs", - "Type": "System.Threading.Tasks.TaskCompletionSource" - }, - { - "Name": "ex", - "Type": "System.Exception" - } - ], - "ReturnType": "System.Void", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Run", - "Parameters": [ - { - "Name": "action", - "Type": "System.Action" - } - ], - "ReturnType": "System.Void", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.LoggingThreadPool", - "Visibility": "Public", - "Kind": "Class", - "ImplementedInterfaces": [ - "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IThreadPool" - ], - "Members": [ - { - "Kind": "Method", - "Name": "Run", - "Parameters": [ - { - "Name": "action", - "Type": "System.Action" - } - ], - "ReturnType": "System.Void", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IThreadPool", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Complete", - "Parameters": [ - { - "Name": "tcs", - "Type": "System.Threading.Tasks.TaskCompletionSource" - } - ], - "ReturnType": "System.Void", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IThreadPool", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Cancel", - "Parameters": [ - { - "Name": "tcs", - "Type": "System.Threading.Tasks.TaskCompletionSource" - } - ], - "ReturnType": "System.Void", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IThreadPool", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Error", - "Parameters": [ - { - "Name": "tcs", - "Type": "System.Threading.Tasks.TaskCompletionSource" - }, - { - "Name": "ex", - "Type": "System.Exception" - } - ], - "ReturnType": "System.Void", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IThreadPool", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "log", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IKestrelTrace" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPool", - "Visibility": "Public", - "Kind": "Class", - "ImplementedInterfaces": [ - "System.IDisposable" - ], - "Members": [ - { - "Kind": "Method", - "Name": "Lease", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolBlock", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Return", - "Parameters": [ - { - "Name": "block", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolBlock" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Dispose", - "Parameters": [ - { - "Name": "disposing", - "Type": "System.Boolean" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Dispose", - "Parameters": [], - "ReturnType": "System.Void", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "System.IDisposable", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [], - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "MaxPooledBlockLength", - "Parameters": [], - "ReturnType": "System.Int32", - "Static": true, - "Visibility": "Public", - "GenericParameter": [], - "Constant": true, - "Literal": "4032" - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolBlock", - "Visibility": "Public", - "Kind": "Class", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "get_Pool", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPool", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_Slab", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolSlab", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_Array", - "Parameters": [], - "ReturnType": "System.Byte[]", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Finalize", - "Parameters": [], - "ReturnType": "System.Void", - "Virtual": true, - "Override": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Reset", - "Parameters": [], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ToString", - "Parameters": [], - "ReturnType": "System.String", - "Virtual": true, - "Override": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "GetIterator", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolIterator", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "dataArrayPtr", - "Type": "System.IntPtr" - } - ], - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "DataArrayPtr", - "Parameters": [], - "ReturnType": "System.IntPtr", - "ReadOnly": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "Data", - "Parameters": [], - "ReturnType": "System.ArraySegment", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "Start", - "Parameters": [], - "ReturnType": "System.Int32", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "End", - "Parameters": [], - "ReturnType": "System.Int32", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "Next", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolBlock", - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolIterator", - "Visibility": "Public", - "Kind": "Struct", - "Sealed": true, - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "get_IsDefault", - "Parameters": [], - "ReturnType": "System.Boolean", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_IsEnd", - "Parameters": [], - "ReturnType": "System.Boolean", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_Block", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolBlock", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_Index", - "Parameters": [], - "ReturnType": "System.Int32", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Take", - "Parameters": [], - "ReturnType": "System.Int32", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Skip", - "Parameters": [ - { - "Name": "bytesToSkip", - "Type": "System.Int32" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Peek", - "Parameters": [], - "ReturnType": "System.Int32", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "PeekLong", - "Parameters": [], - "ReturnType": "System.Int64", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Seek", - "Parameters": [ - { - "Name": "byte0Vector", - "Type": "System.Numerics.Vector`1[[System.Byte, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]]", - "Direction": "Ref" - } - ], - "ReturnType": "System.Int32", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Seek", - "Parameters": [ - { - "Name": "byte0Vector", - "Type": "System.Numerics.Vector`1[[System.Byte, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]]", - "Direction": "Ref" - }, - { - "Name": "byte1Vector", - "Type": "System.Numerics.Vector`1[[System.Byte, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]]", - "Direction": "Ref" - } - ], - "ReturnType": "System.Int32", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Seek", - "Parameters": [ - { - "Name": "byte0Vector", - "Type": "System.Numerics.Vector`1[[System.Byte, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]]", - "Direction": "Ref" - }, - { - "Name": "byte1Vector", - "Type": "System.Numerics.Vector`1[[System.Byte, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]]", - "Direction": "Ref" - }, - { - "Name": "byte2Vector", - "Type": "System.Numerics.Vector`1[[System.Byte, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]]", - "Direction": "Ref" - } - ], - "ReturnType": "System.Int32", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Put", - "Parameters": [ - { - "Name": "data", - "Type": "System.Byte" - } - ], - "ReturnType": "System.Boolean", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "GetLength", - "Parameters": [ - { - "Name": "end", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolIterator" - } - ], - "ReturnType": "System.Int32", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "CopyTo", - "Parameters": [ - { - "Name": "array", - "Type": "System.Byte[]" - }, - { - "Name": "offset", - "Type": "System.Int32" - }, - { - "Name": "count", - "Type": "System.Int32" - }, - { - "Name": "actual", - "Type": "System.Int32", - "Direction": "Out" - } - ], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolIterator", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "CopyFrom", - "Parameters": [ - { - "Name": "data", - "Type": "System.Byte[]" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "CopyFrom", - "Parameters": [ - { - "Name": "buffer", - "Type": "System.ArraySegment" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "CopyFrom", - "Parameters": [ - { - "Name": "data", - "Type": "System.Byte[]" - }, - { - "Name": "offset", - "Type": "System.Int32" - }, - { - "Name": "count", - "Type": "System.Int32" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "CopyFromAscii", - "Parameters": [ - { - "Name": "data", - "Type": "System.String" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "block", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolBlock" - } - ], - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "block", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolBlock" - }, - { - "Name": "index", - "Type": "System.Int32" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolIteratorExtensions", - "Visibility": "Public", - "Kind": "Class", - "Abstract": true, - "Static": true, - "Sealed": true, - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "GetAsciiString", - "Parameters": [ - { - "Name": "start", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolIterator" - }, - { - "Name": "end", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolIterator" - } - ], - "ReturnType": "System.String", - "Static": true, - "Extension": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "GetUtf8String", - "Parameters": [ - { - "Name": "start", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolIterator" - }, - { - "Name": "end", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolIterator" - } - ], - "ReturnType": "System.String", - "Static": true, - "Extension": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "GetArraySegment", - "Parameters": [ - { - "Name": "start", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolIterator" - }, - { - "Name": "end", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolIterator" - } - ], - "ReturnType": "System.ArraySegment", - "Static": true, - "Extension": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "GetKnownMethod", - "Parameters": [ - { - "Name": "begin", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolIterator" - }, - { - "Name": "knownMethod", - "Type": "System.String", - "Direction": "Out" - } - ], - "ReturnType": "System.Boolean", - "Static": true, - "Extension": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "GetKnownVersion", - "Parameters": [ - { - "Name": "begin", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolIterator" - }, - { - "Name": "knownVersion", - "Type": "System.String", - "Direction": "Out" - } - ], - "ReturnType": "System.Boolean", - "Static": true, - "Extension": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "HttpConnectMethod", - "Parameters": [], - "ReturnType": "System.String", - "Static": true, - "Visibility": "Public", - "GenericParameter": [], - "Constant": true, - "Literal": "\"CONNECT\"" - }, - { - "Kind": "Field", - "Name": "HttpDeleteMethod", - "Parameters": [], - "ReturnType": "System.String", - "Static": true, - "Visibility": "Public", - "GenericParameter": [], - "Constant": true, - "Literal": "\"DELETE\"" - }, - { - "Kind": "Field", - "Name": "HttpGetMethod", - "Parameters": [], - "ReturnType": "System.String", - "Static": true, - "Visibility": "Public", - "GenericParameter": [], - "Constant": true, - "Literal": "\"GET\"" - }, - { - "Kind": "Field", - "Name": "HttpHeadMethod", - "Parameters": [], - "ReturnType": "System.String", - "Static": true, - "Visibility": "Public", - "GenericParameter": [], - "Constant": true, - "Literal": "\"HEAD\"" - }, - { - "Kind": "Field", - "Name": "HttpPatchMethod", - "Parameters": [], - "ReturnType": "System.String", - "Static": true, - "Visibility": "Public", - "GenericParameter": [], - "Constant": true, - "Literal": "\"PATCH\"" - }, - { - "Kind": "Field", - "Name": "HttpPostMethod", - "Parameters": [], - "ReturnType": "System.String", - "Static": true, - "Visibility": "Public", - "GenericParameter": [], - "Constant": true, - "Literal": "\"POST\"" - }, - { - "Kind": "Field", - "Name": "HttpPutMethod", - "Parameters": [], - "ReturnType": "System.String", - "Static": true, - "Visibility": "Public", - "GenericParameter": [], - "Constant": true, - "Literal": "\"PUT\"" - }, - { - "Kind": "Field", - "Name": "HttpOptionsMethod", - "Parameters": [], - "ReturnType": "System.String", - "Static": true, - "Visibility": "Public", - "GenericParameter": [], - "Constant": true, - "Literal": "\"OPTIONS\"" - }, - { - "Kind": "Field", - "Name": "HttpTraceMethod", - "Parameters": [], - "ReturnType": "System.String", - "Static": true, - "Visibility": "Public", - "GenericParameter": [], - "Constant": true, - "Literal": "\"TRACE\"" - }, - { - "Kind": "Field", - "Name": "Http10Version", - "Parameters": [], - "ReturnType": "System.String", - "Static": true, - "Visibility": "Public", - "GenericParameter": [], - "Constant": true, - "Literal": "\"HTTP/1.0\"" - }, - { - "Kind": "Field", - "Name": "Http11Version", - "Parameters": [], - "ReturnType": "System.String", - "Static": true, - "Visibility": "Public", - "GenericParameter": [], - "Constant": true, - "Literal": "\"HTTP/1.1\"" - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolSlab", - "Visibility": "Public", - "Kind": "Class", - "ImplementedInterfaces": [ - "System.IDisposable" - ], - "Members": [ - { - "Kind": "Method", - "Name": "Create", - "Parameters": [ - { - "Name": "length", - "Type": "System.Int32" - } - ], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolSlab", - "Static": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Dispose", - "Parameters": [ - { - "Name": "disposing", - "Type": "System.Boolean" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Finalize", - "Parameters": [], - "ReturnType": "System.Void", - "Virtual": true, - "Override": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Dispose", - "Parameters": [], - "ReturnType": "System.Void", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "System.IDisposable", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [], - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "Array", - "Parameters": [], - "ReturnType": "System.Byte[]", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "ArrayPtr", - "Parameters": [], - "ReturnType": "System.IntPtr", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "IsActive", - "Parameters": [], - "ReturnType": "System.Boolean", - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.TaskUtilities", - "Visibility": "Public", - "Kind": "Class", - "Abstract": true, - "Static": true, - "Sealed": true, - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "GetCancelledTask", - "Parameters": [ - { - "Name": "cancellationToken", - "Type": "System.Threading.CancellationToken" - } - ], - "ReturnType": "System.Threading.Tasks.Task", - "Static": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "GetCancelledZeroTask", - "Parameters": [ - { - "Name": "cancellationToken", - "Type": "System.Threading.CancellationToken", - "DefaultValue": "default(System.Threading.CancellationToken)" - } - ], - "ReturnType": "System.Threading.Tasks.Task", - "Static": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "CompletedTask", - "Parameters": [], - "ReturnType": "System.Threading.Tasks.Task", - "Static": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "ZeroTask", - "Parameters": [], - "ReturnType": "System.Threading.Tasks.Task", - "Static": true, - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.BufferSizeControl", - "Visibility": "Public", - "Kind": "Class", - "ImplementedInterfaces": [ - "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.IBufferSizeControl" - ], - "Members": [ - { - "Kind": "Method", - "Name": "Add", - "Parameters": [ - { - "Name": "count", - "Type": "System.Int32" - } - ], - "ReturnType": "System.Void", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.IBufferSizeControl", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Subtract", - "Parameters": [ - { - "Name": "count", - "Type": "System.Int32" - } - ], - "ReturnType": "System.Void", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.IBufferSizeControl", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "maxSize", - "Type": "System.Int64" - }, - { - "Name": "connectionControl", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.IConnectionControl" - }, - { - "Name": "connectionThread", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.KestrelThread" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ChunkWriter", - "Visibility": "Public", - "Kind": "Class", - "Abstract": true, - "Static": true, - "Sealed": true, - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "BeginChunkBytes", - "Parameters": [ - { - "Name": "dataCount", - "Type": "System.Int32" - } - ], - "ReturnType": "System.ArraySegment", - "Static": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "WriteBeginChunkBytes", - "Parameters": [ - { - "Name": "start", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolIterator", - "Direction": "Ref" - }, - { - "Name": "dataCount", - "Type": "System.Int32" - } - ], - "ReturnType": "System.Int32", - "Static": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "WriteEndChunkBytes", - "Parameters": [ - { - "Name": "start", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolIterator", - "Direction": "Ref" - } - ], - "ReturnType": "System.Void", - "Static": true, - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.Connection", - "Visibility": "Public", - "Kind": "Class", - "BaseType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ConnectionContext", - "ImplementedInterfaces": [ - "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.IConnectionControl" - ], - "Members": [ - { - "Kind": "Method", - "Name": "Start", - "Parameters": [], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "StopAsync", - "Parameters": [], - "ReturnType": "System.Threading.Tasks.Task", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Abort", - "Parameters": [], - "ReturnType": "System.Void", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "OnSocketClosed", - "Parameters": [], - "ReturnType": "System.Void", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "context", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ListenerContext" - }, - { - "Name": "socket", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ConnectionContext", - "Visibility": "Public", - "Kind": "Class", - "BaseType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ListenerContext", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "get_SocketInput", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.SocketInput", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_SocketInput", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.SocketInput" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_SocketOutput", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ISocketOutput", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_SocketOutput", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ISocketOutput" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_ConnectionControl", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.IConnectionControl", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_ConnectionControl", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.IConnectionControl" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_RemoteEndPoint", - "Parameters": [], - "ReturnType": "System.Net.IPEndPoint", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_RemoteEndPoint", - "Parameters": [ - { - "Name": "value", - "Type": "System.Net.IPEndPoint" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_LocalEndPoint", - "Parameters": [], - "ReturnType": "System.Net.IPEndPoint", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_LocalEndPoint", - "Parameters": [ - { - "Name": "value", - "Type": "System.Net.IPEndPoint" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_ConnectionId", - "Parameters": [], - "ReturnType": "System.String", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_ConnectionId", - "Parameters": [ - { - "Name": "value", - "Type": "System.String" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_PrepareRequest", - "Parameters": [], - "ReturnType": "System.Action", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_PrepareRequest", - "Parameters": [ - { - "Name": "value", - "Type": "System.Action" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [], - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "context", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ListenerContext" - } - ], - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "context", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ConnectionContext" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ConnectionManager", - "Visibility": "Public", - "Kind": "Class", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "WalkConnectionsAndClose", - "Parameters": [], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "WaitForConnectionCloseAsync", - "Parameters": [], - "ReturnType": "System.Threading.Tasks.Task", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "thread", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.KestrelThread" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.DateHeaderValueManager", - "Visibility": "Public", - "Kind": "Class", - "ImplementedInterfaces": [ - "System.IDisposable" - ], - "Members": [ - { - "Kind": "Method", - "Name": "GetDateHeaderValues", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.DateHeaderValueManager+DateHeaderValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Dispose", - "Parameters": [], - "ReturnType": "System.Void", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "System.IDisposable", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.Frame", - "Visibility": "Public", - "Kind": "Class", - "Abstract": true, - "BaseType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ConnectionContext", - "ImplementedInterfaces": [ - "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.IFrameControl", - "Microsoft.AspNetCore.Http.Features.IFeatureCollection", - "Microsoft.AspNetCore.Http.Features.IHttpRequestFeature", - "Microsoft.AspNetCore.Http.Features.IHttpResponseFeature", - "Microsoft.AspNetCore.Http.Features.IHttpUpgradeFeature", - "Microsoft.AspNetCore.Http.Features.IHttpConnectionFeature", - "Microsoft.AspNetCore.Http.Features.IHttpRequestLifetimeFeature" - ], - "Members": [ - { - "Kind": "Method", - "Name": "get_ConnectionIdFeature", - "Parameters": [], - "ReturnType": "System.String", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_ConnectionIdFeature", - "Parameters": [ - { - "Name": "value", - "Type": "System.String" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_RemoteIpAddress", - "Parameters": [], - "ReturnType": "System.Net.IPAddress", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_RemoteIpAddress", - "Parameters": [ - { - "Name": "value", - "Type": "System.Net.IPAddress" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_RemotePort", - "Parameters": [], - "ReturnType": "System.Int32", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_RemotePort", - "Parameters": [ - { - "Name": "value", - "Type": "System.Int32" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_LocalIpAddress", - "Parameters": [], - "ReturnType": "System.Net.IPAddress", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_LocalIpAddress", - "Parameters": [ - { - "Name": "value", - "Type": "System.Net.IPAddress" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_LocalPort", - "Parameters": [], - "ReturnType": "System.Int32", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_LocalPort", - "Parameters": [ - { - "Name": "value", - "Type": "System.Int32" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_Scheme", - "Parameters": [], - "ReturnType": "System.String", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_Scheme", - "Parameters": [ - { - "Name": "value", - "Type": "System.String" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_Method", - "Parameters": [], - "ReturnType": "System.String", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_Method", - "Parameters": [ - { - "Name": "value", - "Type": "System.String" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_PathBase", - "Parameters": [], - "ReturnType": "System.String", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_PathBase", - "Parameters": [ - { - "Name": "value", - "Type": "System.String" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_Path", - "Parameters": [], - "ReturnType": "System.String", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_Path", - "Parameters": [ - { - "Name": "value", - "Type": "System.String" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_QueryString", - "Parameters": [], - "ReturnType": "System.String", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_QueryString", - "Parameters": [ - { - "Name": "value", - "Type": "System.String" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_RawTarget", - "Parameters": [], - "ReturnType": "System.String", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_RawTarget", - "Parameters": [ - { - "Name": "value", - "Type": "System.String" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HttpVersion", - "Parameters": [], - "ReturnType": "System.String", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HttpVersion", - "Parameters": [ - { - "Name": "value", - "Type": "System.String" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_RequestHeaders", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Http.IHeaderDictionary", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_RequestHeaders", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.AspNetCore.Http.IHeaderDictionary" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_RequestBody", - "Parameters": [], - "ReturnType": "System.IO.Stream", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_RequestBody", - "Parameters": [ - { - "Name": "value", - "Type": "System.IO.Stream" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_StatusCode", - "Parameters": [], - "ReturnType": "System.Int32", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_StatusCode", - "Parameters": [ - { - "Name": "value", - "Type": "System.Int32" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_ReasonPhrase", - "Parameters": [], - "ReturnType": "System.String", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_ReasonPhrase", - "Parameters": [ - { - "Name": "value", - "Type": "System.String" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_ResponseHeaders", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Http.IHeaderDictionary", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_ResponseHeaders", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.AspNetCore.Http.IHeaderDictionary" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_ResponseBody", - "Parameters": [], - "ReturnType": "System.IO.Stream", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_ResponseBody", - "Parameters": [ - { - "Name": "value", - "Type": "System.IO.Stream" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_DuplexStream", - "Parameters": [], - "ReturnType": "System.IO.Stream", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_DuplexStream", - "Parameters": [ - { - "Name": "value", - "Type": "System.IO.Stream" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_RequestAborted", - "Parameters": [], - "ReturnType": "System.Threading.CancellationToken", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_RequestAborted", - "Parameters": [ - { - "Name": "value", - "Type": "System.Threading.CancellationToken" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HasResponseStarted", - "Parameters": [], - "ReturnType": "System.Boolean", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_FrameRequestHeaders", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.FrameRequestHeaders", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_FrameResponseHeaders", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.FrameResponseHeaders", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "InitializeHeaders", - "Parameters": [], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "InitializeStreams", - "Parameters": [ - { - "Name": "messageBody", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.MessageBody" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "PauseStreams", - "Parameters": [], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ResumeStreams", - "Parameters": [], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "StopStreams", - "Parameters": [], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Reset", - "Parameters": [], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Start", - "Parameters": [], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Stop", - "Parameters": [], - "ReturnType": "System.Threading.Tasks.Task", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Abort", - "Parameters": [], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "RequestProcessingAsync", - "Parameters": [], - "ReturnType": "System.Threading.Tasks.Task", - "Virtual": true, - "Abstract": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "OnStarting", - "Parameters": [ - { - "Name": "callback", - "Type": "System.Func" - }, - { - "Name": "state", - "Type": "System.Object" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "OnCompleted", - "Parameters": [ - { - "Name": "callback", - "Type": "System.Func" - }, - { - "Name": "state", - "Type": "System.Object" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "FireOnStarting", - "Parameters": [], - "ReturnType": "System.Threading.Tasks.Task", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "FireOnCompleted", - "Parameters": [], - "ReturnType": "System.Threading.Tasks.Task", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Flush", - "Parameters": [], - "ReturnType": "System.Void", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.IFrameControl", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "FlushAsync", - "Parameters": [ - { - "Name": "cancellationToken", - "Type": "System.Threading.CancellationToken" - } - ], - "ReturnType": "System.Threading.Tasks.Task", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.IFrameControl", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Write", - "Parameters": [ - { - "Name": "data", - "Type": "System.ArraySegment" - } - ], - "ReturnType": "System.Void", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.IFrameControl", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "WriteAsync", - "Parameters": [ - { - "Name": "data", - "Type": "System.ArraySegment" - }, - { - "Name": "cancellationToken", - "Type": "System.Threading.CancellationToken" - } - ], - "ReturnType": "System.Threading.Tasks.Task", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.IFrameControl", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "WriteAsyncAwaited", - "Parameters": [ - { - "Name": "data", - "Type": "System.ArraySegment" - }, - { - "Name": "cancellationToken", - "Type": "System.Threading.CancellationToken" - } - ], - "ReturnType": "System.Threading.Tasks.Task", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ProduceContinue", - "Parameters": [], - "ReturnType": "System.Void", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.IFrameControl", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ProduceStartAndFireOnStarting", - "Parameters": [], - "ReturnType": "System.Threading.Tasks.Task", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "TryProduceInvalidRequestResponse", - "Parameters": [], - "ReturnType": "System.Threading.Tasks.Task", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ProduceEnd", - "Parameters": [], - "ReturnType": "System.Threading.Tasks.Task", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "TakeStartLine", - "Parameters": [ - { - "Name": "input", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.SocketInput" - } - ], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.Frame+RequestLineStatus", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "TakeMessageHeaders", - "Parameters": [ - { - "Name": "input", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.SocketInput" - }, - { - "Name": "requestHeaders", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.FrameRequestHeaders" - } - ], - "ReturnType": "System.Boolean", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "StatusCanHaveBody", - "Parameters": [ - { - "Name": "statusCode", - "Type": "System.Int32" - } - ], - "ReturnType": "System.Boolean", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "RejectRequest", - "Parameters": [ - { - "Name": "message", - "Type": "System.String" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "SetBadRequestState", - "Parameters": [ - { - "Name": "ex", - "Type": "Microsoft.AspNetCore.Server.Kestrel.BadHttpRequestException" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ReportApplicationError", - "Parameters": [ - { - "Name": "ex", - "Type": "System.Exception" - } - ], - "ReturnType": "System.Void", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ResetFeatureCollection", - "Parameters": [], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_FrameControl", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.IFrameControl", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_FrameControl", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.IFrameControl" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "context", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ConnectionContext" - } - ], - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "_requestRejected", - "Parameters": [], - "ReturnType": "System.Boolean", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "_onStarting", - "Parameters": [], - "ReturnType": "System.Collections.Generic.List, System.Object>>", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "_onCompleted", - "Parameters": [], - "ReturnType": "System.Collections.Generic.List, System.Object>>", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "_requestProcessingStopping", - "Parameters": [], - "ReturnType": "System.Boolean", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "_requestAborted", - "Parameters": [], - "ReturnType": "System.Int32", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "_requestProcessingStatus", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.Frame+RequestProcessingStatus", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "_keepAlive", - "Parameters": [], - "ReturnType": "System.Boolean", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "_applicationException", - "Parameters": [], - "ReturnType": "System.Exception", - "Visibility": "Protected", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.FrameHeaders", - "Visibility": "Public", - "Kind": "Class", - "Abstract": true, - "ImplementedInterfaces": [ - "Microsoft.AspNetCore.Http.IHeaderDictionary" - ], - "Members": [ - { - "Kind": "Method", - "Name": "get_Unknown", - "Parameters": [], - "ReturnType": "System.Collections.Generic.Dictionary", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ThrowReadOnlyException", - "Parameters": [], - "ReturnType": "System.Void", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ThrowArgumentException", - "Parameters": [], - "ReturnType": "System.Void", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ThrowKeyNotFoundException", - "Parameters": [], - "ReturnType": "System.Void", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ThrowDuplicateKeyException", - "Parameters": [], - "ReturnType": "System.Void", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "SetReadOnly", - "Parameters": [], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Reset", - "Parameters": [], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "AppendValue", - "Parameters": [ - { - "Name": "existing", - "Type": "Microsoft.Extensions.Primitives.StringValues" - }, - { - "Name": "append", - "Type": "System.String" - } - ], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Static": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "BitCount", - "Parameters": [ - { - "Name": "value", - "Type": "System.Int64" - } - ], - "ReturnType": "System.Int32", - "Static": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "GetCountFast", - "Parameters": [], - "ReturnType": "System.Int32", - "Virtual": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "GetValueFast", - "Parameters": [ - { - "Name": "key", - "Type": "System.String" - } - ], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Virtual": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "TryGetValueFast", - "Parameters": [ - { - "Name": "key", - "Type": "System.String" - }, - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues", - "Direction": "Out" - } - ], - "ReturnType": "System.Boolean", - "Virtual": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "SetValueFast", - "Parameters": [ - { - "Name": "key", - "Type": "System.String" - }, - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "AddValueFast", - "Parameters": [ - { - "Name": "key", - "Type": "System.String" - }, - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "RemoveFast", - "Parameters": [ - { - "Name": "key", - "Type": "System.String" - } - ], - "ReturnType": "System.Boolean", - "Virtual": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ClearFast", - "Parameters": [], - "ReturnType": "System.Void", - "Virtual": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "CopyToFast", - "Parameters": [ - { - "Name": "array", - "Type": "System.Collections.Generic.KeyValuePair[]" - }, - { - "Name": "arrayIndex", - "Type": "System.Int32" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "GetEnumeratorFast", - "Parameters": [], - "ReturnType": "System.Collections.Generic.IEnumerator>", - "Virtual": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ValidateHeaderCharacters", - "Parameters": [ - { - "Name": "headerValues", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Static": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ValidateHeaderCharacters", - "Parameters": [ - { - "Name": "headerCharacters", - "Type": "System.String" - } - ], - "ReturnType": "System.Void", - "Static": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [], - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "_isReadOnly", - "Parameters": [], - "ReturnType": "System.Boolean", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "MaybeUnknown", - "Parameters": [], - "ReturnType": "System.Collections.Generic.Dictionary", - "Visibility": "Protected", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.FrameRequestHeaders", - "Visibility": "Public", - "Kind": "Class", - "BaseType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.FrameHeaders", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "get_HeaderCacheControl", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderCacheControl", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderConnection", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderConnection", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderDate", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderDate", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderKeepAlive", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderKeepAlive", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderPragma", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderPragma", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderTrailer", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderTrailer", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderTransferEncoding", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderTransferEncoding", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderUpgrade", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderUpgrade", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderVia", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderVia", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderWarning", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderWarning", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderAllow", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderAllow", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderContentLength", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderContentLength", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderContentType", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderContentType", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderContentEncoding", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderContentEncoding", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderContentLanguage", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderContentLanguage", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderContentLocation", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderContentLocation", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderContentMD5", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderContentMD5", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderContentRange", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderContentRange", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderExpires", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderExpires", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderLastModified", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderLastModified", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderAccept", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderAccept", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderAcceptCharset", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderAcceptCharset", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderAcceptEncoding", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderAcceptEncoding", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderAcceptLanguage", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderAcceptLanguage", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderAuthorization", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderAuthorization", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderCookie", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderCookie", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderExpect", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderExpect", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderFrom", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderFrom", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderHost", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderHost", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderIfMatch", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderIfMatch", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderIfModifiedSince", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderIfModifiedSince", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderIfNoneMatch", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderIfNoneMatch", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderIfRange", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderIfRange", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderIfUnmodifiedSince", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderIfUnmodifiedSince", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderMaxForwards", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderMaxForwards", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderProxyAuthorization", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderProxyAuthorization", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderReferer", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderReferer", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderRange", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderRange", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderTE", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderTE", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderTranslate", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderTranslate", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderUserAgent", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderUserAgent", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderOrigin", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderOrigin", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderAccessControlRequestMethod", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderAccessControlRequestMethod", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderAccessControlRequestHeaders", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderAccessControlRequestHeaders", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "GetCountFast", - "Parameters": [], - "ReturnType": "System.Int32", - "Virtual": true, - "Override": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "GetValueFast", - "Parameters": [ - { - "Name": "key", - "Type": "System.String" - } - ], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Virtual": true, - "Override": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "TryGetValueFast", - "Parameters": [ - { - "Name": "key", - "Type": "System.String" - }, - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues", - "Direction": "Out" - } - ], - "ReturnType": "System.Boolean", - "Virtual": true, - "Override": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "SetValueFast", - "Parameters": [ - { - "Name": "key", - "Type": "System.String" - }, - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "Override": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "AddValueFast", - "Parameters": [ - { - "Name": "key", - "Type": "System.String" - }, - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "Override": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "RemoveFast", - "Parameters": [ - { - "Name": "key", - "Type": "System.String" - } - ], - "ReturnType": "System.Boolean", - "Virtual": true, - "Override": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ClearFast", - "Parameters": [], - "ReturnType": "System.Void", - "Virtual": true, - "Override": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "CopyToFast", - "Parameters": [ - { - "Name": "array", - "Type": "System.Collections.Generic.KeyValuePair[]" - }, - { - "Name": "arrayIndex", - "Type": "System.Int32" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "Override": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Append", - "Parameters": [ - { - "Name": "keyBytes", - "Type": "System.Byte[]" - }, - { - "Name": "keyOffset", - "Type": "System.Int32" - }, - { - "Name": "keyLength", - "Type": "System.Int32" - }, - { - "Name": "value", - "Type": "System.String" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "GetEnumerator", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.FrameRequestHeaders+Enumerator", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "GetEnumeratorFast", - "Parameters": [], - "ReturnType": "System.Collections.Generic.IEnumerator>", - "Virtual": true, - "Override": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.FrameResponseHeaders", - "Visibility": "Public", - "Kind": "Class", - "BaseType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.FrameHeaders", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "get_HeaderCacheControl", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderCacheControl", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderConnection", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderConnection", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderDate", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderDate", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderKeepAlive", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderKeepAlive", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderPragma", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderPragma", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderTrailer", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderTrailer", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderTransferEncoding", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderTransferEncoding", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderUpgrade", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderUpgrade", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderVia", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderVia", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderWarning", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderWarning", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderAllow", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderAllow", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderContentLength", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderContentLength", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderContentType", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderContentType", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderContentEncoding", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderContentEncoding", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderContentLanguage", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderContentLanguage", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderContentLocation", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderContentLocation", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderContentMD5", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderContentMD5", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderContentRange", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderContentRange", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderExpires", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderExpires", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderLastModified", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderLastModified", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderAcceptRanges", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderAcceptRanges", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderAge", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderAge", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderETag", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderETag", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderLocation", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderLocation", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderProxyAutheticate", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderProxyAutheticate", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderRetryAfter", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderRetryAfter", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderServer", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderServer", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderSetCookie", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderSetCookie", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderVary", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderVary", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderWWWAuthenticate", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderWWWAuthenticate", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderAccessControlAllowCredentials", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderAccessControlAllowCredentials", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderAccessControlAllowHeaders", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderAccessControlAllowHeaders", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderAccessControlAllowMethods", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderAccessControlAllowMethods", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderAccessControlAllowOrigin", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderAccessControlAllowOrigin", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderAccessControlExposeHeaders", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderAccessControlExposeHeaders", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderAccessControlMaxAge", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderAccessControlMaxAge", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "SetRawConnection", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - }, - { - "Name": "raw", - "Type": "System.Byte[]" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "SetRawDate", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - }, - { - "Name": "raw", - "Type": "System.Byte[]" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "SetRawTransferEncoding", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - }, - { - "Name": "raw", - "Type": "System.Byte[]" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "SetRawContentLength", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - }, - { - "Name": "raw", - "Type": "System.Byte[]" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "SetRawServer", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - }, - { - "Name": "raw", - "Type": "System.Byte[]" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "GetCountFast", - "Parameters": [], - "ReturnType": "System.Int32", - "Virtual": true, - "Override": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "GetValueFast", - "Parameters": [ - { - "Name": "key", - "Type": "System.String" - } - ], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Virtual": true, - "Override": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "TryGetValueFast", - "Parameters": [ - { - "Name": "key", - "Type": "System.String" - }, - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues", - "Direction": "Out" - } - ], - "ReturnType": "System.Boolean", - "Virtual": true, - "Override": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "SetValueFast", - "Parameters": [ - { - "Name": "key", - "Type": "System.String" - }, - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "Override": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "AddValueFast", - "Parameters": [ - { - "Name": "key", - "Type": "System.String" - }, - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "Override": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "RemoveFast", - "Parameters": [ - { - "Name": "key", - "Type": "System.String" - } - ], - "ReturnType": "System.Boolean", - "Virtual": true, - "Override": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ClearFast", - "Parameters": [], - "ReturnType": "System.Void", - "Virtual": true, - "Override": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "CopyToFast", - "Parameters": [ - { - "Name": "array", - "Type": "System.Collections.Generic.KeyValuePair[]" - }, - { - "Name": "arrayIndex", - "Type": "System.Int32" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "Override": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "CopyToFast", - "Parameters": [ - { - "Name": "output", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolIterator", - "Direction": "Ref" - } - ], - "ReturnType": "System.Void", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HasConnection", - "Parameters": [], - "ReturnType": "System.Boolean", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HasTransferEncoding", - "Parameters": [], - "ReturnType": "System.Boolean", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HasContentLength", - "Parameters": [], - "ReturnType": "System.Boolean", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HasServer", - "Parameters": [], - "ReturnType": "System.Boolean", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HasDate", - "Parameters": [], - "ReturnType": "System.Boolean", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "GetEnumerator", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.FrameResponseHeaders+Enumerator", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "GetEnumeratorFast", - "Parameters": [], - "ReturnType": "System.Collections.Generic.IEnumerator>", - "Virtual": true, - "Override": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "CopyTo", - "Parameters": [ - { - "Name": "output", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolIterator", - "Direction": "Ref" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.Frame", - "Visibility": "Public", - "Kind": "Class", - "BaseType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.Frame", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "RequestProcessingAsync", - "Parameters": [], - "ReturnType": "System.Threading.Tasks.Task", - "Virtual": true, - "Override": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "application", - "Type": "Microsoft.AspNetCore.Hosting.Server.IHttpApplication" - }, - { - "Name": "context", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ConnectionContext" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [ - { - "ParameterName": "TContext", - "ParameterPosition": 0, - "BaseTypeOrInterfaces": [] - } - ] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.IBufferSizeControl", - "Visibility": "Public", - "Kind": "Interface", - "Abstract": true, - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "Add", - "Parameters": [ - { - "Name": "count", - "Type": "System.Int32" - } - ], - "ReturnType": "System.Void", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Subtract", - "Parameters": [ - { - "Name": "count", - "Type": "System.Int32" - } - ], - "ReturnType": "System.Void", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.IConnectionControl", - "Visibility": "Public", - "Kind": "Interface", - "Abstract": true, - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "Pause", - "Parameters": [], - "ReturnType": "System.Void", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Resume", - "Parameters": [], - "ReturnType": "System.Void", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "End", - "Parameters": [ - { - "Name": "endType", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ProduceEndType" - } - ], - "ReturnType": "System.Void", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.IFrameControl", - "Visibility": "Public", - "Kind": "Interface", - "Abstract": true, - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "ProduceContinue", - "Parameters": [], - "ReturnType": "System.Void", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Write", - "Parameters": [ - { - "Name": "data", - "Type": "System.ArraySegment" - } - ], - "ReturnType": "System.Void", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "WriteAsync", - "Parameters": [ - { - "Name": "data", - "Type": "System.ArraySegment" - }, - { - "Name": "cancellationToken", - "Type": "System.Threading.CancellationToken" - } - ], - "ReturnType": "System.Threading.Tasks.Task", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Flush", - "Parameters": [], - "ReturnType": "System.Void", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "FlushAsync", - "Parameters": [ - { - "Name": "cancellationToken", - "Type": "System.Threading.CancellationToken" - } - ], - "ReturnType": "System.Threading.Tasks.Task", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ISocketOutput", - "Visibility": "Public", - "Kind": "Interface", - "Abstract": true, - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "Write", - "Parameters": [ - { - "Name": "buffer", - "Type": "System.ArraySegment" - }, - { - "Name": "chunk", - "Type": "System.Boolean", - "DefaultValue": "False" - } - ], - "ReturnType": "System.Void", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "WriteAsync", - "Parameters": [ - { - "Name": "buffer", - "Type": "System.ArraySegment" - }, - { - "Name": "chunk", - "Type": "System.Boolean", - "DefaultValue": "False" - }, - { - "Name": "cancellationToken", - "Type": "System.Threading.CancellationToken", - "DefaultValue": "default(System.Threading.CancellationToken)" - } - ], - "ReturnType": "System.Threading.Tasks.Task", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ProducingStart", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolIterator", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ProducingComplete", - "Parameters": [ - { - "Name": "end", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolIterator" - } - ], - "ReturnType": "System.Void", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.Listener", - "Visibility": "Public", - "Kind": "Class", - "Abstract": true, - "BaseType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ListenerContext", - "ImplementedInterfaces": [ - "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.IAsyncDisposable" - ], - "Members": [ - { - "Kind": "Method", - "Name": "get_ListenSocket", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "StartAsync", - "Parameters": [ - { - "Name": "address", - "Type": "Microsoft.AspNetCore.Server.Kestrel.ServerAddress" - }, - { - "Name": "thread", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.KestrelThread" - } - ], - "ReturnType": "System.Threading.Tasks.Task", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "CreateListenSocket", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle", - "Virtual": true, - "Abstract": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ConnectionCallback", - "Parameters": [ - { - "Name": "stream", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle" - }, - { - "Name": "status", - "Type": "System.Int32" - }, - { - "Name": "error", - "Type": "System.Exception" - }, - { - "Name": "state", - "Type": "System.Object" - } - ], - "ReturnType": "System.Void", - "Static": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "OnConnection", - "Parameters": [ - { - "Name": "listenSocket", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle" - }, - { - "Name": "status", - "Type": "System.Int32" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "Abstract": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "DispatchConnection", - "Parameters": [ - { - "Name": "socket", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "DisposeAsync", - "Parameters": [], - "ReturnType": "System.Threading.Tasks.Task", - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.IAsyncDisposable", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "serviceContext", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.ServiceContext" - } - ], - "Visibility": "Protected", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ListenerContext", - "Visibility": "Public", - "Kind": "Class", - "BaseType": "Microsoft.AspNetCore.Server.Kestrel.Internal.ServiceContext", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "get_ServerAddress", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.ServerAddress", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_ServerAddress", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.AspNetCore.Server.Kestrel.ServerAddress" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_Thread", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.KestrelThread", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_Thread", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.KestrelThread" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_Memory", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPool", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_Memory", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPool" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_ConnectionManager", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ConnectionManager", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_ConnectionManager", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ConnectionManager" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_WriteReqPool", - "Parameters": [], - "ReturnType": "System.Collections.Generic.Queue", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_WriteReqPool", - "Parameters": [ - { - "Name": "value", - "Type": "System.Collections.Generic.Queue" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [], - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "serviceContext", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.ServiceContext" - } - ], - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "listenerContext", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ListenerContext" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ListenerPrimary", - "Visibility": "Public", - "Kind": "Class", - "Abstract": true, - "BaseType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.Listener", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "StartAsync", - "Parameters": [ - { - "Name": "pipeName", - "Type": "System.String" - }, - { - "Name": "address", - "Type": "Microsoft.AspNetCore.Server.Kestrel.ServerAddress" - }, - { - "Name": "thread", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.KestrelThread" - } - ], - "ReturnType": "System.Threading.Tasks.Task", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "DispatchConnection", - "Parameters": [ - { - "Name": "socket", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "Override": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "DisposeAsync", - "Parameters": [], - "ReturnType": "System.Threading.Tasks.Task", - "Virtual": true, - "Override": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.IAsyncDisposable", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "serviceContext", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.ServiceContext" - } - ], - "Visibility": "Protected", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ListenerSecondary", - "Visibility": "Public", - "Kind": "Class", - "Abstract": true, - "BaseType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ListenerContext", - "ImplementedInterfaces": [ - "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.IAsyncDisposable" - ], - "Members": [ - { - "Kind": "Method", - "Name": "StartAsync", - "Parameters": [ - { - "Name": "pipeName", - "Type": "System.String" - }, - { - "Name": "address", - "Type": "Microsoft.AspNetCore.Server.Kestrel.ServerAddress" - }, - { - "Name": "thread", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.KestrelThread" - } - ], - "ReturnType": "System.Threading.Tasks.Task", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "CreateAcceptSocket", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle", - "Virtual": true, - "Abstract": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "DisposeAsync", - "Parameters": [], - "ReturnType": "System.Threading.Tasks.Task", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.IAsyncDisposable", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "serviceContext", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.ServiceContext" - } - ], - "Visibility": "Protected", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.MessageBody", - "Visibility": "Public", - "Kind": "Class", - "Abstract": true, - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "get_RequestKeepAlive", - "Parameters": [], - "ReturnType": "System.Boolean", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_RequestKeepAlive", - "Parameters": [ - { - "Name": "value", - "Type": "System.Boolean" - } - ], - "ReturnType": "System.Void", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ReadAsync", - "Parameters": [ - { - "Name": "buffer", - "Type": "System.ArraySegment" - }, - { - "Name": "cancellationToken", - "Type": "System.Threading.CancellationToken", - "DefaultValue": "default(System.Threading.CancellationToken)" - } - ], - "ReturnType": "System.Threading.Tasks.ValueTask", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Consume", - "Parameters": [ - { - "Name": "cancellationToken", - "Type": "System.Threading.CancellationToken", - "DefaultValue": "default(System.Threading.CancellationToken)" - } - ], - "ReturnType": "System.Threading.Tasks.Task", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ReadAsyncImplementation", - "Parameters": [ - { - "Name": "buffer", - "Type": "System.ArraySegment" - }, - { - "Name": "cancellationToken", - "Type": "System.Threading.CancellationToken" - } - ], - "ReturnType": "System.Threading.Tasks.ValueTask", - "Virtual": true, - "Abstract": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "For", - "Parameters": [ - { - "Name": "httpVersion", - "Type": "System.String" - }, - { - "Name": "headers", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.FrameRequestHeaders" - }, - { - "Name": "context", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.Frame" - } - ], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.MessageBody", - "Static": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "context", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.Frame" - } - ], - "Visibility": "Protected", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.PathNormalizer", - "Visibility": "Public", - "Kind": "Class", - "Abstract": true, - "Static": true, - "Sealed": true, - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "RemoveDotSegments", - "Parameters": [ - { - "Name": "path", - "Type": "System.String" - } - ], - "ReturnType": "System.String", - "Static": true, - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.PipeListener", - "Visibility": "Public", - "Kind": "Class", - "BaseType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.Listener", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "CreateListenSocket", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle", - "Virtual": true, - "Override": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "OnConnection", - "Parameters": [ - { - "Name": "listenSocket", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle" - }, - { - "Name": "status", - "Type": "System.Int32" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "Override": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "serviceContext", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.ServiceContext" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.PipeListenerPrimary", - "Visibility": "Public", - "Kind": "Class", - "BaseType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ListenerPrimary", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "CreateListenSocket", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle", - "Virtual": true, - "Override": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "OnConnection", - "Parameters": [ - { - "Name": "listenSocket", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle" - }, - { - "Name": "status", - "Type": "System.Int32" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "Override": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "serviceContext", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.ServiceContext" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.PipeListenerSecondary", - "Visibility": "Public", - "Kind": "Class", - "BaseType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ListenerSecondary", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "CreateAcceptSocket", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle", - "Virtual": true, - "Override": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "serviceContext", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.ServiceContext" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ProduceEndType", - "Visibility": "Public", - "Kind": "Enumeration", - "Sealed": true, - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Field", - "Name": "SocketShutdown", - "Parameters": [], - "GenericParameter": [], - "Literal": "0" - }, - { - "Kind": "Field", - "Name": "SocketDisconnect", - "Parameters": [], - "GenericParameter": [], - "Literal": "1" - }, - { - "Kind": "Field", - "Name": "ConnectionKeepAlive", - "Parameters": [], - "GenericParameter": [], - "Literal": "2" - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ReasonPhrases", - "Visibility": "Public", - "Kind": "Class", - "Abstract": true, - "Static": true, - "Sealed": true, - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "ToStatusBytes", - "Parameters": [ - { - "Name": "statusCode", - "Type": "System.Int32" - }, - { - "Name": "reasonPhrase", - "Type": "System.String", - "DefaultValue": "null" - } - ], - "ReturnType": "System.Byte[]", - "Static": true, - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.SocketInput", - "Visibility": "Public", - "Kind": "Class", - "ImplementedInterfaces": [ - "System.Runtime.CompilerServices.ICriticalNotifyCompletion", - "System.IDisposable" - ], - "Members": [ - { - "Kind": "Method", - "Name": "get_RemoteIntakeFin", - "Parameters": [], - "ReturnType": "System.Boolean", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_RemoteIntakeFin", - "Parameters": [ - { - "Name": "value", - "Type": "System.Boolean" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_IsCompleted", - "Parameters": [], - "ReturnType": "System.Boolean", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "IncomingStart", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolBlock", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "IncomingData", - "Parameters": [ - { - "Name": "buffer", - "Type": "System.Byte[]" - }, - { - "Name": "offset", - "Type": "System.Int32" - }, - { - "Name": "count", - "Type": "System.Int32" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "IncomingComplete", - "Parameters": [ - { - "Name": "count", - "Type": "System.Int32" - }, - { - "Name": "error", - "Type": "System.Exception" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "IncomingDeferred", - "Parameters": [], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "IncomingFin", - "Parameters": [], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ConsumingStart", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolIterator", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ConsumingComplete", - "Parameters": [ - { - "Name": "consumed", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolIterator" - }, - { - "Name": "examined", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolIterator" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "CompleteAwaiting", - "Parameters": [], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "AbortAwaiting", - "Parameters": [], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "GetAwaiter", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.SocketInput", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "OnCompleted", - "Parameters": [ - { - "Name": "continuation", - "Type": "System.Action" - } - ], - "ReturnType": "System.Void", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "System.Runtime.CompilerServices.INotifyCompletion", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "UnsafeOnCompleted", - "Parameters": [ - { - "Name": "continuation", - "Type": "System.Action" - } - ], - "ReturnType": "System.Void", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "System.Runtime.CompilerServices.ICriticalNotifyCompletion", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "GetResult", - "Parameters": [], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Dispose", - "Parameters": [], - "ReturnType": "System.Void", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "System.IDisposable", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "memory", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPool" - }, - { - "Name": "threadPool", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IThreadPool" - }, - { - "Name": "bufferSizeControl", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.IBufferSizeControl", - "DefaultValue": "null" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.SocketInputExtensions", - "Visibility": "Public", - "Kind": "Class", - "Abstract": true, - "Static": true, - "Sealed": true, - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "ReadAsync", - "Parameters": [ - { - "Name": "input", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.SocketInput" - }, - { - "Name": "buffer", - "Type": "System.Byte[]" - }, - { - "Name": "offset", - "Type": "System.Int32" - }, - { - "Name": "count", - "Type": "System.Int32" - } - ], - "ReturnType": "System.Threading.Tasks.ValueTask", - "Static": true, - "Extension": true, - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.SocketOutput", - "Visibility": "Public", - "Kind": "Class", - "ImplementedInterfaces": [ - "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ISocketOutput" - ], - "Members": [ - { - "Kind": "Method", - "Name": "WriteAsync", - "Parameters": [ - { - "Name": "buffer", - "Type": "System.ArraySegment" - }, - { - "Name": "cancellationToken", - "Type": "System.Threading.CancellationToken" - }, - { - "Name": "chunk", - "Type": "System.Boolean", - "DefaultValue": "False" - }, - { - "Name": "socketShutdownSend", - "Type": "System.Boolean", - "DefaultValue": "False" - }, - { - "Name": "socketDisconnect", - "Type": "System.Boolean", - "DefaultValue": "False" - }, - { - "Name": "isSync", - "Type": "System.Boolean", - "DefaultValue": "False" - } - ], - "ReturnType": "System.Threading.Tasks.Task", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "End", - "Parameters": [ - { - "Name": "endType", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ProduceEndType" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ProducingStart", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolIterator", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ISocketOutput", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ProducingComplete", - "Parameters": [ - { - "Name": "end", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolIterator" - } - ], - "ReturnType": "System.Void", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ISocketOutput", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "thread", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.KestrelThread" - }, - { - "Name": "socket", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle" - }, - { - "Name": "memory", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPool" - }, - { - "Name": "connection", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.Connection" - }, - { - "Name": "connectionId", - "Type": "System.String" - }, - { - "Name": "log", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IKestrelTrace" - }, - { - "Name": "threadPool", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IThreadPool" - }, - { - "Name": "writeReqPool", - "Type": "System.Collections.Generic.Queue" - } - ], - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "MaxPooledWriteReqs", - "Parameters": [], - "ReturnType": "System.Int32", - "Static": true, - "Visibility": "Public", - "GenericParameter": [], - "Constant": true, - "Literal": "1024" - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.TcpListener", - "Visibility": "Public", - "Kind": "Class", - "BaseType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.Listener", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "CreateListenSocket", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle", - "Virtual": true, - "Override": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "OnConnection", - "Parameters": [ - { - "Name": "listenSocket", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle" - }, - { - "Name": "status", - "Type": "System.Int32" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "Override": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "serviceContext", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.ServiceContext" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.TcpListenerPrimary", - "Visibility": "Public", - "Kind": "Class", - "BaseType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ListenerPrimary", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "CreateListenSocket", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle", - "Virtual": true, - "Override": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "OnConnection", - "Parameters": [ - { - "Name": "listenSocket", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle" - }, - { - "Name": "status", - "Type": "System.Int32" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "Override": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "serviceContext", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.ServiceContext" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.TcpListenerSecondary", - "Visibility": "Public", - "Kind": "Class", - "BaseType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ListenerSecondary", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "CreateAcceptSocket", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle", - "Virtual": true, - "Override": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "serviceContext", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.ServiceContext" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.UrlPathDecoder", - "Visibility": "Public", - "Kind": "Class", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "Unescape", - "Parameters": [ - { - "Name": "start", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolIterator" - }, - { - "Name": "end", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolIterator" - } - ], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolIterator", - "Static": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Filter.ConnectionFilterContext", - "Visibility": "Public", - "Kind": "Class", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "get_Address", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.ServerAddress", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_Address", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.AspNetCore.Server.Kestrel.ServerAddress" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_Connection", - "Parameters": [], - "ReturnType": "System.IO.Stream", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_Connection", - "Parameters": [ - { - "Name": "value", - "Type": "System.IO.Stream" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_PrepareRequest", - "Parameters": [], - "ReturnType": "System.Action", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_PrepareRequest", - "Parameters": [ - { - "Name": "value", - "Type": "System.Action" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Filter.IConnectionFilter", - "Visibility": "Public", - "Kind": "Interface", - "Abstract": true, - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "OnConnectionAsync", - "Parameters": [ - { - "Name": "context", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Filter.ConnectionFilterContext" - } - ], - "ReturnType": "System.Threading.Tasks.Task", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Filter.LoggingConnectionFilter", - "Visibility": "Public", - "Kind": "Class", - "ImplementedInterfaces": [ - "Microsoft.AspNetCore.Server.Kestrel.Filter.IConnectionFilter" - ], - "Members": [ - { - "Kind": "Method", - "Name": "OnConnectionAsync", - "Parameters": [ - { - "Name": "context", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Filter.ConnectionFilterContext" - } - ], - "ReturnType": "System.Threading.Tasks.Task", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Filter.IConnectionFilter", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "logger", - "Type": "Microsoft.Extensions.Logging.ILogger" - }, - { - "Name": "previous", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Filter.IConnectionFilter" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Filter.NoOpConnectionFilter", - "Visibility": "Public", - "Kind": "Class", - "ImplementedInterfaces": [ - "Microsoft.AspNetCore.Server.Kestrel.Filter.IConnectionFilter" - ], - "Members": [ - { - "Kind": "Method", - "Name": "OnConnectionAsync", - "Parameters": [ - { - "Name": "context", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Filter.ConnectionFilterContext" - } - ], - "ReturnType": "System.Threading.Tasks.Task", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Filter.IConnectionFilter", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Filter.Internal.FilteredStreamAdapter", - "Visibility": "Public", - "Kind": "Class", - "ImplementedInterfaces": [ - "System.IDisposable" - ], - "Members": [ - { - "Kind": "Method", - "Name": "get_SocketInput", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.SocketInput", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_SocketOutput", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ISocketOutput", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ReadInputAsync", - "Parameters": [], - "ReturnType": "System.Threading.Tasks.Task", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Abort", - "Parameters": [], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Dispose", - "Parameters": [], - "ReturnType": "System.Void", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "System.IDisposable", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "connectionId", - "Type": "System.String" - }, - { - "Name": "filteredStream", - "Type": "System.IO.Stream" - }, - { - "Name": "memory", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPool" - }, - { - "Name": "logger", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IKestrelTrace" - }, - { - "Name": "threadPool", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IThreadPool" - }, - { - "Name": "bufferSizeControl", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.IBufferSizeControl" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Filter.Internal.LibuvStream", - "Visibility": "Public", - "Kind": "Class", - "BaseType": "System.IO.Stream", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "get_CanRead", - "Parameters": [], - "ReturnType": "System.Boolean", - "Virtual": true, - "Override": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_CanSeek", - "Parameters": [], - "ReturnType": "System.Boolean", - "Virtual": true, - "Override": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_CanWrite", - "Parameters": [], - "ReturnType": "System.Boolean", - "Virtual": true, - "Override": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_Length", - "Parameters": [], - "ReturnType": "System.Int64", - "Virtual": true, - "Override": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_Position", - "Parameters": [], - "ReturnType": "System.Int64", - "Virtual": true, - "Override": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_Position", - "Parameters": [ - { - "Name": "value", - "Type": "System.Int64" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "Override": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Seek", - "Parameters": [ - { - "Name": "offset", - "Type": "System.Int64" - }, - { - "Name": "origin", - "Type": "System.IO.SeekOrigin" - } - ], - "ReturnType": "System.Int64", - "Virtual": true, - "Override": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "SetLength", - "Parameters": [ - { - "Name": "value", - "Type": "System.Int64" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "Override": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Read", - "Parameters": [ - { - "Name": "buffer", - "Type": "System.Byte[]" - }, - { - "Name": "offset", - "Type": "System.Int32" - }, - { - "Name": "count", - "Type": "System.Int32" - } - ], - "ReturnType": "System.Int32", - "Virtual": true, - "Override": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ReadAsync", - "Parameters": [ - { - "Name": "buffer", - "Type": "System.Byte[]" - }, - { - "Name": "offset", - "Type": "System.Int32" - }, - { - "Name": "count", - "Type": "System.Int32" - }, - { - "Name": "cancellationToken", - "Type": "System.Threading.CancellationToken" - } - ], - "ReturnType": "System.Threading.Tasks.Task", - "Virtual": true, - "Override": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Write", - "Parameters": [ - { - "Name": "buffer", - "Type": "System.Byte[]" - }, - { - "Name": "offset", - "Type": "System.Int32" - }, - { - "Name": "count", - "Type": "System.Int32" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "Override": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "WriteAsync", - "Parameters": [ - { - "Name": "buffer", - "Type": "System.Byte[]" - }, - { - "Name": "offset", - "Type": "System.Int32" - }, - { - "Name": "count", - "Type": "System.Int32" - }, - { - "Name": "token", - "Type": "System.Threading.CancellationToken" - } - ], - "ReturnType": "System.Threading.Tasks.Task", - "Virtual": true, - "Override": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Flush", - "Parameters": [], - "ReturnType": "System.Void", - "Virtual": true, - "Override": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "FlushAsync", - "Parameters": [ - { - "Name": "cancellationToken", - "Type": "System.Threading.CancellationToken" - } - ], - "ReturnType": "System.Threading.Tasks.Task", - "Virtual": true, - "Override": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "input", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.SocketInput" - }, - { - "Name": "output", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ISocketOutput" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Filter.Internal.StreamSocketOutput", - "Visibility": "Public", - "Kind": "Class", - "ImplementedInterfaces": [ - "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ISocketOutput" - ], - "Members": [ - { - "Kind": "Method", - "Name": "Write", - "Parameters": [ - { - "Name": "buffer", - "Type": "System.ArraySegment" - }, - { - "Name": "chunk", - "Type": "System.Boolean" - } - ], - "ReturnType": "System.Void", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ISocketOutput", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "WriteAsync", - "Parameters": [ - { - "Name": "buffer", - "Type": "System.ArraySegment" - }, - { - "Name": "chunk", - "Type": "System.Boolean" - }, - { - "Name": "cancellationToken", - "Type": "System.Threading.CancellationToken" - } - ], - "ReturnType": "System.Threading.Tasks.Task", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ISocketOutput", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ProducingStart", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolIterator", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ISocketOutput", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ProducingComplete", - "Parameters": [ - { - "Name": "end", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolIterator" - } - ], - "ReturnType": "System.Void", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ISocketOutput", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "connectionId", - "Type": "System.String" - }, - { - "Name": "outputStream", - "Type": "System.IO.Stream" - }, - { - "Name": "memory", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPool" - }, - { - "Name": "logger", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.IKestrelTrace" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_fileno_func", - "Visibility": "Protected", - "Kind": "Class", - "Sealed": true, - "BaseType": "System.MulticastDelegate", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "Invoke", - "Parameters": [ - { - "Name": "handle", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvHandle" - }, - { - "Name": "socket", - "Type": "System.IntPtr", - "Direction": "Ref" - } - ], - "ReturnType": "System.Int32", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "BeginInvoke", - "Parameters": [ - { - "Name": "handle", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvHandle" - }, - { - "Name": "socket", - "Type": "System.IntPtr", - "Direction": "Ref" - }, - { - "Name": "callback", - "Type": "System.AsyncCallback" - }, - { - "Name": "object", - "Type": "System.Object" - } - ], - "ReturnType": "System.IAsyncResult", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "EndInvoke", - "Parameters": [ - { - "Name": "socket", - "Type": "System.IntPtr", - "Direction": "Ref" - }, - { - "Name": "result", - "Type": "System.IAsyncResult" - } - ], - "ReturnType": "System.Int32", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "object", - "Type": "System.Object" - }, - { - "Name": "method", - "Type": "System.IntPtr" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_close_cb", - "Visibility": "Public", - "Kind": "Class", - "Sealed": true, - "BaseType": "System.MulticastDelegate", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "Invoke", - "Parameters": [ - { - "Name": "handle", - "Type": "System.IntPtr" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "BeginInvoke", - "Parameters": [ - { - "Name": "handle", - "Type": "System.IntPtr" - }, - { - "Name": "callback", - "Type": "System.AsyncCallback" - }, - { - "Name": "object", - "Type": "System.Object" - } - ], - "ReturnType": "System.IAsyncResult", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "EndInvoke", - "Parameters": [ - { - "Name": "result", - "Type": "System.IAsyncResult" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "object", - "Type": "System.Object" - }, - { - "Name": "method", - "Type": "System.IntPtr" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_async_cb", - "Visibility": "Public", - "Kind": "Class", - "Sealed": true, - "BaseType": "System.MulticastDelegate", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "Invoke", - "Parameters": [ - { - "Name": "handle", - "Type": "System.IntPtr" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "BeginInvoke", - "Parameters": [ - { - "Name": "handle", - "Type": "System.IntPtr" - }, - { - "Name": "callback", - "Type": "System.AsyncCallback" - }, - { - "Name": "object", - "Type": "System.Object" - } - ], - "ReturnType": "System.IAsyncResult", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "EndInvoke", - "Parameters": [ - { - "Name": "result", - "Type": "System.IAsyncResult" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "object", - "Type": "System.Object" - }, - { - "Name": "method", - "Type": "System.IntPtr" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_tcp_bind_func", - "Visibility": "Protected", - "Kind": "Class", - "Sealed": true, - "BaseType": "System.MulticastDelegate", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "Invoke", - "Parameters": [ - { - "Name": "handle", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvTcpHandle" - }, - { - "Name": "addr", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.SockAddr", - "Direction": "Ref" - }, - { - "Name": "flags", - "Type": "System.Int32" - } - ], - "ReturnType": "System.Int32", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "BeginInvoke", - "Parameters": [ - { - "Name": "handle", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvTcpHandle" - }, - { - "Name": "addr", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.SockAddr", - "Direction": "Ref" - }, - { - "Name": "flags", - "Type": "System.Int32" - }, - { - "Name": "callback", - "Type": "System.AsyncCallback" - }, - { - "Name": "object", - "Type": "System.Object" - } - ], - "ReturnType": "System.IAsyncResult", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "EndInvoke", - "Parameters": [ - { - "Name": "addr", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.SockAddr", - "Direction": "Ref" - }, - { - "Name": "result", - "Type": "System.IAsyncResult" - } - ], - "ReturnType": "System.Int32", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "object", - "Type": "System.Object" - }, - { - "Name": "method", - "Type": "System.IntPtr" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_connection_cb", - "Visibility": "Public", - "Kind": "Class", - "Sealed": true, - "BaseType": "System.MulticastDelegate", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "Invoke", - "Parameters": [ - { - "Name": "server", - "Type": "System.IntPtr" - }, - { - "Name": "status", - "Type": "System.Int32" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "BeginInvoke", - "Parameters": [ - { - "Name": "server", - "Type": "System.IntPtr" - }, - { - "Name": "status", - "Type": "System.Int32" - }, - { - "Name": "callback", - "Type": "System.AsyncCallback" - }, - { - "Name": "object", - "Type": "System.Object" - } - ], - "ReturnType": "System.IAsyncResult", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "EndInvoke", - "Parameters": [ - { - "Name": "result", - "Type": "System.IAsyncResult" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "object", - "Type": "System.Object" - }, - { - "Name": "method", - "Type": "System.IntPtr" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_connect_cb", - "Visibility": "Public", - "Kind": "Class", - "Sealed": true, - "BaseType": "System.MulticastDelegate", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "Invoke", - "Parameters": [ - { - "Name": "req", - "Type": "System.IntPtr" - }, - { - "Name": "status", - "Type": "System.Int32" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "BeginInvoke", - "Parameters": [ - { - "Name": "req", - "Type": "System.IntPtr" - }, - { - "Name": "status", - "Type": "System.Int32" - }, - { - "Name": "callback", - "Type": "System.AsyncCallback" - }, - { - "Name": "object", - "Type": "System.Object" - } - ], - "ReturnType": "System.IAsyncResult", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "EndInvoke", - "Parameters": [ - { - "Name": "result", - "Type": "System.IAsyncResult" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "object", - "Type": "System.Object" - }, - { - "Name": "method", - "Type": "System.IntPtr" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_alloc_cb", - "Visibility": "Public", - "Kind": "Class", - "Sealed": true, - "BaseType": "System.MulticastDelegate", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "Invoke", - "Parameters": [ - { - "Name": "server", - "Type": "System.IntPtr" - }, - { - "Name": "suggested_size", - "Type": "System.Int32" - }, - { - "Name": "buf", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_buf_t", - "Direction": "Out" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "BeginInvoke", - "Parameters": [ - { - "Name": "server", - "Type": "System.IntPtr" - }, - { - "Name": "suggested_size", - "Type": "System.Int32" - }, - { - "Name": "buf", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_buf_t", - "Direction": "Out" - }, - { - "Name": "callback", - "Type": "System.AsyncCallback" - }, - { - "Name": "object", - "Type": "System.Object" - } - ], - "ReturnType": "System.IAsyncResult", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "EndInvoke", - "Parameters": [ - { - "Name": "buf", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_buf_t", - "Direction": "Out" - }, - { - "Name": "result", - "Type": "System.IAsyncResult" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "object", - "Type": "System.Object" - }, - { - "Name": "method", - "Type": "System.IntPtr" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_read_cb", - "Visibility": "Public", - "Kind": "Class", - "Sealed": true, - "BaseType": "System.MulticastDelegate", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "Invoke", - "Parameters": [ - { - "Name": "server", - "Type": "System.IntPtr" - }, - { - "Name": "nread", - "Type": "System.Int32" - }, - { - "Name": "buf", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_buf_t", - "Direction": "Ref" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "BeginInvoke", - "Parameters": [ - { - "Name": "server", - "Type": "System.IntPtr" - }, - { - "Name": "nread", - "Type": "System.Int32" - }, - { - "Name": "buf", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_buf_t", - "Direction": "Ref" - }, - { - "Name": "callback", - "Type": "System.AsyncCallback" - }, - { - "Name": "object", - "Type": "System.Object" - } - ], - "ReturnType": "System.IAsyncResult", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "EndInvoke", - "Parameters": [ - { - "Name": "buf", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_buf_t", - "Direction": "Ref" - }, - { - "Name": "result", - "Type": "System.IAsyncResult" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "object", - "Type": "System.Object" - }, - { - "Name": "method", - "Type": "System.IntPtr" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_write_cb", - "Visibility": "Public", - "Kind": "Class", - "Sealed": true, - "BaseType": "System.MulticastDelegate", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "Invoke", - "Parameters": [ - { - "Name": "req", - "Type": "System.IntPtr" - }, - { - "Name": "status", - "Type": "System.Int32" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "BeginInvoke", - "Parameters": [ - { - "Name": "req", - "Type": "System.IntPtr" - }, - { - "Name": "status", - "Type": "System.Int32" - }, - { - "Name": "callback", - "Type": "System.AsyncCallback" - }, - { - "Name": "object", - "Type": "System.Object" - } - ], - "ReturnType": "System.IAsyncResult", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "EndInvoke", - "Parameters": [ - { - "Name": "result", - "Type": "System.IAsyncResult" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "object", - "Type": "System.Object" - }, - { - "Name": "method", - "Type": "System.IntPtr" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_write_func", - "Visibility": "Protected", - "Kind": "Class", - "Sealed": true, - "BaseType": "System.MulticastDelegate", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "Invoke", - "Parameters": [ - { - "Name": "req", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvRequest" - }, - { - "Name": "handle", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle" - }, - { - "Name": "bufs", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_buf_t*" - }, - { - "Name": "nbufs", - "Type": "System.Int32" - }, - { - "Name": "cb", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_write_cb" - } - ], - "ReturnType": "System.Int32", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "BeginInvoke", - "Parameters": [ - { - "Name": "req", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvRequest" - }, - { - "Name": "handle", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle" - }, - { - "Name": "bufs", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_buf_t*" - }, - { - "Name": "nbufs", - "Type": "System.Int32" - }, - { - "Name": "cb", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_write_cb" - }, - { - "Name": "callback", - "Type": "System.AsyncCallback" - }, - { - "Name": "object", - "Type": "System.Object" - } - ], - "ReturnType": "System.IAsyncResult", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "EndInvoke", - "Parameters": [ - { - "Name": "result", - "Type": "System.IAsyncResult" - } - ], - "ReturnType": "System.Int32", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "object", - "Type": "System.Object" - }, - { - "Name": "method", - "Type": "System.IntPtr" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_write2_func", - "Visibility": "Protected", - "Kind": "Class", - "Sealed": true, - "BaseType": "System.MulticastDelegate", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "Invoke", - "Parameters": [ - { - "Name": "req", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvRequest" - }, - { - "Name": "handle", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle" - }, - { - "Name": "bufs", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_buf_t*" - }, - { - "Name": "nbufs", - "Type": "System.Int32" - }, - { - "Name": "sendHandle", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle" - }, - { - "Name": "cb", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_write_cb" - } - ], - "ReturnType": "System.Int32", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "BeginInvoke", - "Parameters": [ - { - "Name": "req", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvRequest" - }, - { - "Name": "handle", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle" - }, - { - "Name": "bufs", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_buf_t*" - }, - { - "Name": "nbufs", - "Type": "System.Int32" - }, - { - "Name": "sendHandle", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvStreamHandle" - }, - { - "Name": "cb", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_write_cb" - }, - { - "Name": "callback", - "Type": "System.AsyncCallback" - }, - { - "Name": "object", - "Type": "System.Object" - } - ], - "ReturnType": "System.IAsyncResult", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "EndInvoke", - "Parameters": [ - { - "Name": "result", - "Type": "System.IAsyncResult" - } - ], - "ReturnType": "System.Int32", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "object", - "Type": "System.Object" - }, - { - "Name": "method", - "Type": "System.IntPtr" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_shutdown_cb", - "Visibility": "Public", - "Kind": "Class", - "Sealed": true, - "BaseType": "System.MulticastDelegate", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "Invoke", - "Parameters": [ - { - "Name": "req", - "Type": "System.IntPtr" - }, - { - "Name": "status", - "Type": "System.Int32" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "BeginInvoke", - "Parameters": [ - { - "Name": "req", - "Type": "System.IntPtr" - }, - { - "Name": "status", - "Type": "System.Int32" - }, - { - "Name": "callback", - "Type": "System.AsyncCallback" - }, - { - "Name": "object", - "Type": "System.Object" - } - ], - "ReturnType": "System.IAsyncResult", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "EndInvoke", - "Parameters": [ - { - "Name": "result", - "Type": "System.IAsyncResult" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "object", - "Type": "System.Object" - }, - { - "Name": "method", - "Type": "System.IntPtr" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_ip4_addr_func", - "Visibility": "Protected", - "Kind": "Class", - "Sealed": true, - "BaseType": "System.MulticastDelegate", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "Invoke", - "Parameters": [ - { - "Name": "ip", - "Type": "System.String" - }, - { - "Name": "port", - "Type": "System.Int32" - }, - { - "Name": "addr", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.SockAddr", - "Direction": "Out" - } - ], - "ReturnType": "System.Int32", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "BeginInvoke", - "Parameters": [ - { - "Name": "ip", - "Type": "System.String" - }, - { - "Name": "port", - "Type": "System.Int32" - }, - { - "Name": "addr", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.SockAddr", - "Direction": "Out" - }, - { - "Name": "callback", - "Type": "System.AsyncCallback" - }, - { - "Name": "object", - "Type": "System.Object" - } - ], - "ReturnType": "System.IAsyncResult", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "EndInvoke", - "Parameters": [ - { - "Name": "addr", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.SockAddr", - "Direction": "Out" - }, - { - "Name": "result", - "Type": "System.IAsyncResult" - } - ], - "ReturnType": "System.Int32", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "object", - "Type": "System.Object" - }, - { - "Name": "method", - "Type": "System.IntPtr" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_ip6_addr_func", - "Visibility": "Protected", - "Kind": "Class", - "Sealed": true, - "BaseType": "System.MulticastDelegate", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "Invoke", - "Parameters": [ - { - "Name": "ip", - "Type": "System.String" - }, - { - "Name": "port", - "Type": "System.Int32" - }, - { - "Name": "addr", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.SockAddr", - "Direction": "Out" - } - ], - "ReturnType": "System.Int32", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "BeginInvoke", - "Parameters": [ - { - "Name": "ip", - "Type": "System.String" - }, - { - "Name": "port", - "Type": "System.Int32" - }, - { - "Name": "addr", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.SockAddr", - "Direction": "Out" - }, - { - "Name": "callback", - "Type": "System.AsyncCallback" - }, - { - "Name": "object", - "Type": "System.Object" - } - ], - "ReturnType": "System.IAsyncResult", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "EndInvoke", - "Parameters": [ - { - "Name": "addr", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.SockAddr", - "Direction": "Out" - }, - { - "Name": "result", - "Type": "System.IAsyncResult" - } - ], - "ReturnType": "System.Int32", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "object", - "Type": "System.Object" - }, - { - "Name": "method", - "Type": "System.IntPtr" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_walk_cb", - "Visibility": "Public", - "Kind": "Class", - "Sealed": true, - "BaseType": "System.MulticastDelegate", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "Invoke", - "Parameters": [ - { - "Name": "handle", - "Type": "System.IntPtr" - }, - { - "Name": "arg", - "Type": "System.IntPtr" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "BeginInvoke", - "Parameters": [ - { - "Name": "handle", - "Type": "System.IntPtr" - }, - { - "Name": "arg", - "Type": "System.IntPtr" - }, - { - "Name": "callback", - "Type": "System.AsyncCallback" - }, - { - "Name": "object", - "Type": "System.Object" - } - ], - "ReturnType": "System.IAsyncResult", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "EndInvoke", - "Parameters": [ - { - "Name": "result", - "Type": "System.IAsyncResult" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "object", - "Type": "System.Object" - }, - { - "Name": "method", - "Type": "System.IntPtr" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_tcp_getsockname_func", - "Visibility": "Public", - "Kind": "Class", - "Sealed": true, - "BaseType": "System.MulticastDelegate", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "Invoke", - "Parameters": [ - { - "Name": "handle", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvTcpHandle" - }, - { - "Name": "addr", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.SockAddr", - "Direction": "Out" - }, - { - "Name": "namelen", - "Type": "System.Int32", - "Direction": "Ref" - } - ], - "ReturnType": "System.Int32", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "BeginInvoke", - "Parameters": [ - { - "Name": "handle", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvTcpHandle" - }, - { - "Name": "addr", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.SockAddr", - "Direction": "Out" - }, - { - "Name": "namelen", - "Type": "System.Int32", - "Direction": "Ref" - }, - { - "Name": "callback", - "Type": "System.AsyncCallback" - }, - { - "Name": "object", - "Type": "System.Object" - } - ], - "ReturnType": "System.IAsyncResult", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "EndInvoke", - "Parameters": [ - { - "Name": "addr", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.SockAddr", - "Direction": "Out" - }, - { - "Name": "namelen", - "Type": "System.Int32", - "Direction": "Ref" - }, - { - "Name": "result", - "Type": "System.IAsyncResult" - } - ], - "ReturnType": "System.Int32", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "object", - "Type": "System.Object" - }, - { - "Name": "method", - "Type": "System.IntPtr" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_tcp_getpeername_func", - "Visibility": "Public", - "Kind": "Class", - "Sealed": true, - "BaseType": "System.MulticastDelegate", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "Invoke", - "Parameters": [ - { - "Name": "handle", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvTcpHandle" - }, - { - "Name": "addr", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.SockAddr", - "Direction": "Out" - }, - { - "Name": "namelen", - "Type": "System.Int32", - "Direction": "Ref" - } - ], - "ReturnType": "System.Int32", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "BeginInvoke", - "Parameters": [ - { - "Name": "handle", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvTcpHandle" - }, - { - "Name": "addr", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.SockAddr", - "Direction": "Out" - }, - { - "Name": "namelen", - "Type": "System.Int32", - "Direction": "Ref" - }, - { - "Name": "callback", - "Type": "System.AsyncCallback" - }, - { - "Name": "object", - "Type": "System.Object" - } - ], - "ReturnType": "System.IAsyncResult", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "EndInvoke", - "Parameters": [ - { - "Name": "addr", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.SockAddr", - "Direction": "Out" - }, - { - "Name": "namelen", - "Type": "System.Int32", - "Direction": "Ref" - }, - { - "Name": "result", - "Type": "System.IAsyncResult" - } - ], - "ReturnType": "System.Int32", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "object", - "Type": "System.Object" - }, - { - "Name": "method", - "Type": "System.IntPtr" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+uv_buf_t", - "Visibility": "Public", - "Kind": "Struct", - "Sealed": true, - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "memory", - "Type": "System.IntPtr" - }, - { - "Name": "len", - "Type": "System.Int32" - }, - { - "Name": "IsWindows", - "Type": "System.Boolean" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+HandleType", - "Visibility": "Public", - "Kind": "Enumeration", - "Sealed": true, - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Field", - "Name": "Unknown", - "Parameters": [], - "GenericParameter": [], - "Literal": "0" - }, - { - "Kind": "Field", - "Name": "ASYNC", - "Parameters": [], - "GenericParameter": [], - "Literal": "1" - }, - { - "Kind": "Field", - "Name": "CHECK", - "Parameters": [], - "GenericParameter": [], - "Literal": "2" - }, - { - "Kind": "Field", - "Name": "FS_EVENT", - "Parameters": [], - "GenericParameter": [], - "Literal": "3" - }, - { - "Kind": "Field", - "Name": "FS_POLL", - "Parameters": [], - "GenericParameter": [], - "Literal": "4" - }, - { - "Kind": "Field", - "Name": "HANDLE", - "Parameters": [], - "GenericParameter": [], - "Literal": "5" - }, - { - "Kind": "Field", - "Name": "IDLE", - "Parameters": [], - "GenericParameter": [], - "Literal": "6" - }, - { - "Kind": "Field", - "Name": "NAMED_PIPE", - "Parameters": [], - "GenericParameter": [], - "Literal": "7" - }, - { - "Kind": "Field", - "Name": "POLL", - "Parameters": [], - "GenericParameter": [], - "Literal": "8" - }, - { - "Kind": "Field", - "Name": "PREPARE", - "Parameters": [], - "GenericParameter": [], - "Literal": "9" - }, - { - "Kind": "Field", - "Name": "PROCESS", - "Parameters": [], - "GenericParameter": [], - "Literal": "10" - }, - { - "Kind": "Field", - "Name": "STREAM", - "Parameters": [], - "GenericParameter": [], - "Literal": "11" - }, - { - "Kind": "Field", - "Name": "TCP", - "Parameters": [], - "GenericParameter": [], - "Literal": "12" - }, - { - "Kind": "Field", - "Name": "TIMER", - "Parameters": [], - "GenericParameter": [], - "Literal": "13" - }, - { - "Kind": "Field", - "Name": "TTY", - "Parameters": [], - "GenericParameter": [], - "Literal": "14" - }, - { - "Kind": "Field", - "Name": "UDP", - "Parameters": [], - "GenericParameter": [], - "Literal": "15" - }, - { - "Kind": "Field", - "Name": "SIGNAL", - "Parameters": [], - "GenericParameter": [], - "Literal": "16" - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv+RequestType", - "Visibility": "Public", - "Kind": "Enumeration", - "Sealed": true, - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Field", - "Name": "Unknown", - "Parameters": [], - "GenericParameter": [], - "Literal": "0" - }, - { - "Kind": "Field", - "Name": "REQ", - "Parameters": [], - "GenericParameter": [], - "Literal": "1" - }, - { - "Kind": "Field", - "Name": "CONNECT", - "Parameters": [], - "GenericParameter": [], - "Literal": "2" - }, - { - "Kind": "Field", - "Name": "WRITE", - "Parameters": [], - "GenericParameter": [], - "Literal": "3" - }, - { - "Kind": "Field", - "Name": "SHUTDOWN", - "Parameters": [], - "GenericParameter": [], - "Literal": "4" - }, - { - "Kind": "Field", - "Name": "UDP_SEND", - "Parameters": [], - "GenericParameter": [], - "Literal": "5" - }, - { - "Kind": "Field", - "Name": "FS", - "Parameters": [], - "GenericParameter": [], - "Literal": "6" - }, - { - "Kind": "Field", - "Name": "WORK", - "Parameters": [], - "GenericParameter": [], - "Literal": "7" - }, - { - "Kind": "Field", - "Name": "GETADDRINFO", - "Parameters": [], - "GenericParameter": [], - "Literal": "8" - }, - { - "Kind": "Field", - "Name": "GETNAMEINFO", - "Parameters": [], - "GenericParameter": [], - "Literal": "9" - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.DateHeaderValueManager+DateHeaderValues", - "Visibility": "Public", - "Kind": "Class", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [], - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "Bytes", - "Parameters": [], - "ReturnType": "System.Byte[]", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "String", - "Parameters": [], - "ReturnType": "System.String", - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.Frame+RequestLineStatus", - "Visibility": "Protected", - "Kind": "Enumeration", - "Sealed": true, - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Field", - "Name": "Empty", - "Parameters": [], - "GenericParameter": [], - "Literal": "0" - }, - { - "Kind": "Field", - "Name": "MethodIncomplete", - "Parameters": [], - "GenericParameter": [], - "Literal": "1" - }, - { - "Kind": "Field", - "Name": "TargetIncomplete", - "Parameters": [], - "GenericParameter": [], - "Literal": "2" - }, - { - "Kind": "Field", - "Name": "VersionIncomplete", - "Parameters": [], - "GenericParameter": [], - "Literal": "3" - }, - { - "Kind": "Field", - "Name": "Incomplete", - "Parameters": [], - "GenericParameter": [], - "Literal": "4" - }, - { - "Kind": "Field", - "Name": "Done", - "Parameters": [], - "GenericParameter": [], - "Literal": "5" - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.Frame+RequestProcessingStatus", - "Visibility": "Protected", - "Kind": "Enumeration", - "Sealed": true, - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Field", - "Name": "RequestPending", - "Parameters": [], - "GenericParameter": [], - "Literal": "0" - }, - { - "Kind": "Field", - "Name": "RequestStarted", - "Parameters": [], - "GenericParameter": [], - "Literal": "1" - }, - { - "Kind": "Field", - "Name": "ResponseStarted", - "Parameters": [], - "GenericParameter": [], - "Literal": "2" - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.FrameRequestHeaders+Enumerator", - "Visibility": "Public", - "Kind": "Struct", - "Sealed": true, - "ImplementedInterfaces": [ - "System.Collections.Generic.IEnumerator>" - ], - "Members": [ - { - "Kind": "Method", - "Name": "MoveNext", - "Parameters": [], - "ReturnType": "System.Boolean", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "System.Collections.IEnumerator", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_Current", - "Parameters": [], - "ReturnType": "System.Collections.Generic.KeyValuePair", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "System.Collections.Generic.IEnumerator>", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Dispose", - "Parameters": [], - "ReturnType": "System.Void", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "System.IDisposable", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Reset", - "Parameters": [], - "ReturnType": "System.Void", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "System.Collections.IEnumerator", - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.Http.FrameResponseHeaders+Enumerator", - "Visibility": "Public", - "Kind": "Struct", - "Sealed": true, - "ImplementedInterfaces": [ - "System.Collections.Generic.IEnumerator>" - ], - "Members": [ - { - "Kind": "Method", - "Name": "MoveNext", - "Parameters": [], - "ReturnType": "System.Boolean", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "System.Collections.IEnumerator", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_Current", - "Parameters": [], - "ReturnType": "System.Collections.Generic.KeyValuePair", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "System.Collections.Generic.IEnumerator>", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Dispose", - "Parameters": [], - "ReturnType": "System.Void", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "System.IDisposable", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Reset", - "Parameters": [], - "ReturnType": "System.Void", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "System.Collections.IEnumerator", - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - } - ] -} \ No newline at end of file diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/exceptions.net45.json b/src/Microsoft.AspNetCore.Server.Kestrel/exceptions.net45.json deleted file mode 100644 index 95752b8370..0000000000 --- a/src/Microsoft.AspNetCore.Server.Kestrel/exceptions.net45.json +++ /dev/null @@ -1,46 +0,0 @@ -[ - { - "OldTypeId": "public static class Microsoft.AspNetCore.Hosting.KestrelServerOptionsConnectionLoggingExtensions", - "Kind": "Removal" - }, - { - "OldTypeId": "public class Microsoft.AspNetCore.Server.Kestrel.Filter.ConnectionFilterContext", - "Kind": "Removal" - }, - { - "OldTypeId": "public interface Microsoft.AspNetCore.Server.Kestrel.Filter.IConnectionFilter", - "Kind": "Removal" - }, - { - "OldTypeId": "public class Microsoft.AspNetCore.Server.Kestrel.Filter.LoggingConnectionFilter : Microsoft.AspNetCore.Server.Kestrel.Filter.IConnectionFilter", - "Kind": "Removal" - }, - { - "OldTypeId": "public class Microsoft.AspNetCore.Server.Kestrel.Filter.NoOpConnectionFilter : Microsoft.AspNetCore.Server.Kestrel.Filter.IConnectionFilter", - "Kind": "Removal" - }, - { - "OldTypeId": "public class Microsoft.AspNetCore.Server.Kestrel.KestrelServerOptions", - "OldMemberId": "public Microsoft.AspNetCore.Server.Kestrel.Filter.IConnectionFilter get_ConnectionFilter()", - "Kind": "Removal" - }, - { - "OldTypeId": "public class Microsoft.AspNetCore.Server.Kestrel.KestrelServerOptions", - "OldMemberId": "public System.Void set_ConnectionFilter(Microsoft.AspNetCore.Server.Kestrel.Filter.IConnectionFilter value)", - "Kind": "Removal" - }, - { - "OldTypeId": "public class Microsoft.AspNetCore.Server.Kestrel.KestrelServerOptions", - "OldMemberId": "public System.Boolean get_NoDelay()", - "NewTypeId": "public class Microsoft.AspNetCore.Server.Kestrel.ListenOptions", - "NewMemberId": "public System.Boolean get_NoDelay()", - "Kind": "Modification" - }, - { - "OldTypeId": "public class Microsoft.AspNetCore.Server.Kestrel.KestrelServerOptions", - "OldMemberId": "public System.Void set_NoDelay(System.Boolean value)", - "NewTypeId": "public class Microsoft.AspNetCore.Server.Kestrel.ListenOptions", - "NewMemberId": "public System.Void set_NoDelay(System.Boolean value)", - "Kind": "Modification" - } -] \ No newline at end of file diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/exceptions.netcore.json b/src/Microsoft.AspNetCore.Server.Kestrel/exceptions.netcore.json deleted file mode 100644 index 95752b8370..0000000000 --- a/src/Microsoft.AspNetCore.Server.Kestrel/exceptions.netcore.json +++ /dev/null @@ -1,46 +0,0 @@ -[ - { - "OldTypeId": "public static class Microsoft.AspNetCore.Hosting.KestrelServerOptionsConnectionLoggingExtensions", - "Kind": "Removal" - }, - { - "OldTypeId": "public class Microsoft.AspNetCore.Server.Kestrel.Filter.ConnectionFilterContext", - "Kind": "Removal" - }, - { - "OldTypeId": "public interface Microsoft.AspNetCore.Server.Kestrel.Filter.IConnectionFilter", - "Kind": "Removal" - }, - { - "OldTypeId": "public class Microsoft.AspNetCore.Server.Kestrel.Filter.LoggingConnectionFilter : Microsoft.AspNetCore.Server.Kestrel.Filter.IConnectionFilter", - "Kind": "Removal" - }, - { - "OldTypeId": "public class Microsoft.AspNetCore.Server.Kestrel.Filter.NoOpConnectionFilter : Microsoft.AspNetCore.Server.Kestrel.Filter.IConnectionFilter", - "Kind": "Removal" - }, - { - "OldTypeId": "public class Microsoft.AspNetCore.Server.Kestrel.KestrelServerOptions", - "OldMemberId": "public Microsoft.AspNetCore.Server.Kestrel.Filter.IConnectionFilter get_ConnectionFilter()", - "Kind": "Removal" - }, - { - "OldTypeId": "public class Microsoft.AspNetCore.Server.Kestrel.KestrelServerOptions", - "OldMemberId": "public System.Void set_ConnectionFilter(Microsoft.AspNetCore.Server.Kestrel.Filter.IConnectionFilter value)", - "Kind": "Removal" - }, - { - "OldTypeId": "public class Microsoft.AspNetCore.Server.Kestrel.KestrelServerOptions", - "OldMemberId": "public System.Boolean get_NoDelay()", - "NewTypeId": "public class Microsoft.AspNetCore.Server.Kestrel.ListenOptions", - "NewMemberId": "public System.Boolean get_NoDelay()", - "Kind": "Modification" - }, - { - "OldTypeId": "public class Microsoft.AspNetCore.Server.Kestrel.KestrelServerOptions", - "OldMemberId": "public System.Void set_NoDelay(System.Boolean value)", - "NewTypeId": "public class Microsoft.AspNetCore.Server.Kestrel.ListenOptions", - "NewMemberId": "public System.Void set_NoDelay(System.Boolean value)", - "Kind": "Modification" - } -] \ No newline at end of file diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/BadHttpRequestTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/BadHttpRequestTests.cs index 36af57bd10..89deac4fa3 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/BadHttpRequestTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/BadHttpRequestTests.cs @@ -4,11 +4,7 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Net.Sockets; using System.Threading.Tasks; -using Microsoft.AspNetCore.Builder; -using Microsoft.AspNetCore.Hosting; -using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Server.Kestrel.Internal; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.AspNetCore.Testing; diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/GeneratedCodeTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/GeneratedCodeTests.cs index 3fa3d89026..b295ee52d7 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/GeneratedCodeTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/GeneratedCodeTests.cs @@ -13,8 +13,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [Fact] public void GeneratedCodeIsUpToDate() { - const string frameHeadersGeneratedPath = "../../../../../src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameHeaders.Generated.cs"; - const string frameGeneratedPath = "../../../../../src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.Generated.cs"; + const string frameHeadersGeneratedPath = "../../../../../src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameHeaders.Generated.cs"; + const string frameGeneratedPath = "../../../../../src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.Generated.cs"; var testFrameHeadersGeneratedPath = Path.GetTempFileName(); var testFrameGeneratedPath = Path.GetTempFileName(); diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests.csproj b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests.csproj index ed0530aa99..7e3f9f44ae 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests.csproj +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests.csproj @@ -16,6 +16,7 @@ + diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestHeaderLimitsTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestHeaderLimitsTests.cs index f7c1d8bc1a..8c62cc0971 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestHeaderLimitsTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestHeaderLimitsTests.cs @@ -2,15 +2,14 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Collections; +using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Testing; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; -using Xunit; using Microsoft.Extensions.Primitives; -using System.Collections; -using System.Collections.Generic; +using Xunit; namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { @@ -80,107 +79,107 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } } - [Theory] - [InlineData(1, 1)] - [InlineData(5, 5)] - [InlineData(100, 100)] - [InlineData(600, 100)] - [InlineData(700, 1)] - [InlineData(1, 700)] - public async Task ServerAcceptsHeadersAcrossSends(int header0Count, int header1Count) - { - var headers0 = MakeHeaders(header0Count); - var headers1 = MakeHeaders(header1Count, header0Count); + //[Theory] + //[InlineData(1, 1)] + //[InlineData(5, 5)] + //[InlineData(100, 100)] + //[InlineData(600, 100)] + //[InlineData(700, 1)] + //[InlineData(1, 700)] + //public async Task ServerAcceptsHeadersAcrossSends(int header0Count, int header1Count) + //{ + // var headers0 = MakeHeaders(header0Count); + // var headers1 = MakeHeaders(header1Count, header0Count); - using (var server = CreateServer(maxRequestHeaderCount: header0Count + header1Count)) - { - using (var connection = new TestConnection(server.Port)) - { - await connection.SendAll("GET / HTTP/1.1\r\n"); - // Wait for parsing to start - await WaitForCondition(TimeSpan.FromSeconds(1), () => server.Frame?.RequestHeaders != null); + // using (var server = CreateServer(maxRequestHeaderCount: header0Count + header1Count)) + // { + // using (var connection = new TestConnection(server.Port)) + // { + // await connection.SendAll("GET / HTTP/1.1\r\n"); + // // Wait for parsing to start + // await WaitForCondition(TimeSpan.FromSeconds(1), () => server.Frame?.RequestHeaders != null); - Assert.Equal(0, server.Frame.RequestHeaders.Count); + // Assert.Equal(0, server.Frame.RequestHeaders.Count); - await connection.SendAll(headers0); - // Wait for headers to be parsed - await WaitForCondition(TimeSpan.FromSeconds(1), () => server.Frame.RequestHeaders.Count >= header0Count); + // await connection.SendAll(headers0); + // // Wait for headers to be parsed + // await WaitForCondition(TimeSpan.FromSeconds(1), () => server.Frame.RequestHeaders.Count >= header0Count); - Assert.Equal(header0Count, server.Frame.RequestHeaders.Count); + // Assert.Equal(header0Count, server.Frame.RequestHeaders.Count); - await connection.SendAll(headers1); - // Wait for headers to be parsed - await WaitForCondition(TimeSpan.FromSeconds(1), () => server.Frame.RequestHeaders.Count >= header0Count + header1Count); + // await connection.SendAll(headers1); + // // Wait for headers to be parsed + // await WaitForCondition(TimeSpan.FromSeconds(1), () => server.Frame.RequestHeaders.Count >= header0Count + header1Count); - Assert.Equal(header0Count + header1Count, server.Frame.RequestHeaders.Count); + // Assert.Equal(header0Count + header1Count, server.Frame.RequestHeaders.Count); - await connection.SendAll("\r\n"); - await connection.ReceiveEnd( - "HTTP/1.1 200 OK", - $"Date: {server.Context.DateHeaderValue}", - "Transfer-Encoding: chunked", - "", - "c", - "hello, world", - "0", - "", - ""); - } - } - } + // await connection.SendAll("\r\n"); + // await connection.ReceiveEnd( + // "HTTP/1.1 200 OK", + // $"Date: {server.Context.DateHeaderValue}", + // "Transfer-Encoding: chunked", + // "", + // "c", + // "hello, world", + // "0", + // "", + // ""); + // } + // } + //} - [Theory] - [InlineData(1, 1)] - [InlineData(5, 5)] - public async Task ServerKeepsSameHeaderCollectionAcrossSends(int header0Count, int header1Count) - { - var headers0 = MakeHeaders(header0Count); - var headers1 = MakeHeaders(header0Count, header1Count); + //[Theory] + //[InlineData(1, 1)] + //[InlineData(5, 5)] + //public async Task ServerKeepsSameHeaderCollectionAcrossSends(int header0Count, int header1Count) + //{ + // var headers0 = MakeHeaders(header0Count); + // var headers1 = MakeHeaders(header0Count, header1Count); - using (var server = CreateServer(maxRequestHeaderCount: header0Count + header1Count)) - { - using (var connection = new TestConnection(server.Port)) - { - await connection.SendAll("GET / HTTP/1.1\r\n"); - // Wait for parsing to start - await WaitForCondition(TimeSpan.FromSeconds(1), () => server.Frame?.RequestHeaders != null); + // using (var server = CreateServer(maxRequestHeaderCount: header0Count + header1Count)) + // { + // using (var connection = new TestConnection(server.Port)) + // { + // await connection.SendAll("GET / HTTP/1.1\r\n"); + // // Wait for parsing to start + // await WaitForCondition(TimeSpan.FromSeconds(1), () => server.Frame?.RequestHeaders != null); - Assert.Equal(0, server.Frame.RequestHeaders.Count); + // Assert.Equal(0, server.Frame.RequestHeaders.Count); - var newRequestHeaders = new RequestHeadersWrapper(server.Frame.RequestHeaders); - server.Frame.RequestHeaders = newRequestHeaders; + // var newRequestHeaders = new RequestHeadersWrapper(server.Frame.RequestHeaders); + // server.Frame.RequestHeaders = newRequestHeaders; - Assert.Same(newRequestHeaders, server.Frame.RequestHeaders); + // Assert.Same(newRequestHeaders, server.Frame.RequestHeaders); - await connection.SendAll(headers0); - // Wait for headers to be parsed - await WaitForCondition(TimeSpan.FromSeconds(1), () => server.Frame.RequestHeaders.Count >= header0Count); + // await connection.SendAll(headers0); + // // Wait for headers to be parsed + // await WaitForCondition(TimeSpan.FromSeconds(1), () => server.Frame.RequestHeaders.Count >= header0Count); - Assert.Same(newRequestHeaders, server.Frame.RequestHeaders); - Assert.Equal(header0Count, server.Frame.RequestHeaders.Count); + // Assert.Same(newRequestHeaders, server.Frame.RequestHeaders); + // Assert.Equal(header0Count, server.Frame.RequestHeaders.Count); - await connection.SendAll(headers1); - // Wait for headers to be parsed - await WaitForCondition(TimeSpan.FromSeconds(1), () => server.Frame.RequestHeaders.Count >= header0Count + header1Count); + // await connection.SendAll(headers1); + // // Wait for headers to be parsed + // await WaitForCondition(TimeSpan.FromSeconds(1), () => server.Frame.RequestHeaders.Count >= header0Count + header1Count); - Assert.Equal(header0Count + header1Count, server.Frame.RequestHeaders.Count); + // Assert.Equal(header0Count + header1Count, server.Frame.RequestHeaders.Count); - Assert.Same(newRequestHeaders, server.Frame.RequestHeaders); + // Assert.Same(newRequestHeaders, server.Frame.RequestHeaders); - await connection.SendAll("\r\n"); - await connection.ReceiveEnd( - "HTTP/1.1 200 OK", - $"Date: {server.Context.DateHeaderValue}", - "Transfer-Encoding: chunked", - "", - "c", - "hello, world", - "0", - "", - ""); - } - } - } + // await connection.SendAll("\r\n"); + // await connection.ReceiveEnd( + // "HTTP/1.1 200 OK", + // $"Date: {server.Context.DateHeaderValue}", + // "Transfer-Encoding: chunked", + // "", + // "c", + // "hello, world", + // "0", + // "", + // ""); + // } + // } + //} [Theory] [InlineData(1)] diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs index fad98eaeae..a8e071e339 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs @@ -16,7 +16,6 @@ using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.AspNetCore.Testing; -using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Internal; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Primitives; diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ThreadCountTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ThreadCountTests.cs index cfd2e133af..67f5cbafbb 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ThreadCountTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ThreadCountTests.cs @@ -20,7 +20,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests public async Task OneToTenThreads(int threadCount) { var hostBuilder = new WebHostBuilder() - .UseKestrel(options => + .UseKestrel() + .UseLibuv(options => { options.ThreadCount = threadCount; }) diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameParsingOverheadBenchmark.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameParsingOverheadBenchmark.cs index 2b5065707a..a3d0092638 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameParsingOverheadBenchmark.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameParsingOverheadBenchmark.cs @@ -5,8 +5,8 @@ using System; using System.IO.Pipelines; using System.Text; using BenchmarkDotNet.Attributes; +using Microsoft.AspNetCore.Server.Kestrel.Internal; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; -using Microsoft.AspNetCore.Testing; namespace Microsoft.AspNetCore.Server.Kestrel.Performance { @@ -21,11 +21,18 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance [Setup] public void Setup() { - var connectionContext = new MockConnection(); - connectionContext.ListenerContext.ServiceContext.HttpParserFactory = frame => NullParser.Instance; - connectionContext.ListenerContext.ServiceContext.ServerOptions = new KestrelServerOptions(); + var serviceContext = new ServiceContext + { + HttpParserFactory = _ => NullParser.Instance, + ServerOptions = new KestrelServerOptions() + }; + var frameContext = new FrameContext + { + ServiceContext = serviceContext, + ConnectionInformation = new MockConnectionInformation() + }; - _frame = new Frame(application: null, context: connectionContext); + _frame = new Frame(application: null, frameContext: frameContext); } [Benchmark(Baseline = true, OperationsPerInvoke = InnerLoopCount)] diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameWritingBenchmark.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameWritingBenchmark.cs index ffb4e95b62..ae41da1959 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameWritingBenchmark.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameWritingBenchmark.cs @@ -3,7 +3,6 @@ using System; using System.IO.Pipelines; -using System.Net; using System.Threading; using System.Threading.Tasks; using BenchmarkDotNet.Attributes; @@ -93,21 +92,21 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance { DateHeaderValueManager = new DateHeaderValueManager(), ServerOptions = new KestrelServerOptions(), - Log = new MockTrace() + Log = new MockTrace(), + HttpParserFactory = f => new KestrelHttpParser(log: null) }; - var listenerContext = new ListenerContext(serviceContext) + var frameContext = new FrameContext { - ListenOptions = new ListenOptions(new IPEndPoint(IPAddress.Loopback, 5000)) + ServiceContext = serviceContext, + ConnectionInformation = new MockConnectionInformation() + }; + + var frame = new TestFrame(application: null, context: frameContext) + { + Input = socketInput.Reader, + Output = new MockSocketOutput() }; - var connectionContext = new ConnectionContext(listenerContext) - { - Input = socketInput, - Output = new MockSocketOutput(), - ConnectionControl = new MockConnectionControl() - }; - connectionContext.ListenerContext.ServiceContext.HttpParserFactory = f => new Internal.Http.KestrelHttpParser(log: null); - var frame = new TestFrame(application: null, context: connectionContext); frame.Reset(); frame.InitializeHeaders(); diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Mocks/MockConnectionControl.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Mocks/MockConnectionControl.cs deleted file mode 100644 index 14e53e3f53..0000000000 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Mocks/MockConnectionControl.cs +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; - -namespace Microsoft.AspNetCore.Server.Kestrel.Performance -{ - public class MockConnectionControl : IConnectionControl - { - public void CancelTimeout() { } - public void End(ProduceEndType endType) { } - public void Pause() { } - public void ResetTimeout(long milliseconds, TimeoutAction timeoutAction) { } - public void Resume() { } - public void SetTimeout(long milliseconds, TimeoutAction timeoutAction) { } - } -} diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Mocks/MockConnectionInformation.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Mocks/MockConnectionInformation.cs new file mode 100644 index 0000000000..9faa8d2f63 --- /dev/null +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Mocks/MockConnectionInformation.cs @@ -0,0 +1,38 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System.IO.Pipelines; +using System.Net; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Transport; + +namespace Microsoft.AspNetCore.Server.Kestrel.Performance +{ + public class MockConnectionInformation : IConnectionInformation + { + public ListenOptions ListenOptions { get; } + public IPEndPoint RemoteEndPoint { get; } + public IPEndPoint LocalEndPoint { get; } + + public PipeFactory PipeFactory { get; } + public IScheduler InputWriterScheduler { get; } + public IScheduler OutputWriterScheduler { get; } + + public ITimeoutControl TimeoutControl { get; } = new MockTimeoutControl(); + + private class MockTimeoutControl : ITimeoutControl + { + public void CancelTimeout() + { + } + + public void ResetTimeout(long milliseconds, TimeoutAction timeoutAction) + { + } + + public void SetTimeout(long milliseconds, TimeoutAction timeoutAction) + { + } + } + } +} diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/PipeThroughputBenchmark.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/PipeThroughputBenchmark.cs index abdd7ab8b7..957a66b19c 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/PipeThroughputBenchmark.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/PipeThroughputBenchmark.cs @@ -1,9 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System; using System.IO.Pipelines; -using System.Text; using System.Threading.Tasks; using BenchmarkDotNet.Attributes; diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Program.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Program.cs index 8a8d9c6d68..2c73b19ef8 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Program.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Program.cs @@ -1,7 +1,6 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System; using System.Reflection; using BenchmarkDotNet.Running; diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsingBenchmark.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsingBenchmark.cs index 8e29354eeb..68da390b7a 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsingBenchmark.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsingBenchmark.cs @@ -1,11 +1,10 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System; using System.IO.Pipelines; using BenchmarkDotNet.Attributes; +using Microsoft.AspNetCore.Server.Kestrel.Internal; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; -using Microsoft.AspNetCore.Testing; namespace Microsoft.AspNetCore.Server.Kestrel.Performance { @@ -21,11 +20,18 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance [Setup] public void Setup() { - var connectionContext = new MockConnection(); - connectionContext.ListenerContext.ServiceContext.HttpParserFactory = frame => new KestrelHttpParser(frame.ConnectionContext.ListenerContext.ServiceContext.Log); - connectionContext.ListenerContext.ServiceContext.ServerOptions = new KestrelServerOptions(); + var serviceContext = new ServiceContext + { + HttpParserFactory = f => new KestrelHttpParser(f.ServiceContext.Log), + ServerOptions = new KestrelServerOptions() + }; + var frameContext = new FrameContext + { + ServiceContext = serviceContext, + ConnectionInformation = new MockConnectionInformation() + }; - Frame = new Frame(application: null, context: connectionContext); + Frame = new Frame(application: null, frameContext: frameContext); PipelineFactory = new PipeFactory(); Pipe = PipelineFactory.Create(); } diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/ResponseHeaderCollectionBenchmark.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/ResponseHeaderCollectionBenchmark.cs index f8668024af..0d2852dcf3 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/ResponseHeaderCollectionBenchmark.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/ResponseHeaderCollectionBenchmark.cs @@ -3,11 +3,11 @@ using System.Runtime.CompilerServices; using System.Text; +using BenchmarkDotNet.Attributes; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http.Internal; +using Microsoft.AspNetCore.Server.Kestrel.Internal; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; -using Microsoft.AspNetCore.Testing; -using BenchmarkDotNet.Attributes; namespace Microsoft.AspNetCore.Server.Kestrel.Performance { @@ -167,10 +167,19 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance [Setup] public void Setup() { - var connectionContext = new MockConnection(); - connectionContext.ListenerContext.ServiceContext.HttpParserFactory = f => new KestrelHttpParser(f.ConnectionContext.ListenerContext.ServiceContext.Log); - connectionContext.ListenerContext.ServiceContext.ServerOptions = new KestrelServerOptions(); - var frame = new Frame(application: null, context: connectionContext); + var serviceContext = new ServiceContext + { + HttpParserFactory = f => new KestrelHttpParser(f.ServiceContext.Log), + ServerOptions = new KestrelServerOptions() + }; + var frameContext = new FrameContext + { + ServiceContext = serviceContext, + ConnectionInformation = new MockConnectionInformation() + }; + + var frame = new Frame(application: null, frameContext: frameContext); + frame.Reset(); frame.InitializeHeaders(); _responseHeadersDirect = (FrameResponseHeaders)frame.ResponseHeaders; diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/ResponseHeadersWritingBenchmark.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/ResponseHeadersWritingBenchmark.cs index 642ad4e57c..270f739286 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/ResponseHeadersWritingBenchmark.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/ResponseHeadersWritingBenchmark.cs @@ -4,7 +4,6 @@ using System; using System.IO; using System.IO.Pipelines; -using System.Net; using System.Text; using System.Threading; using System.Threading.Tasks; @@ -12,7 +11,6 @@ using BenchmarkDotNet.Attributes; using Microsoft.AspNetCore.Server.Kestrel.Adapter.Internal; using Microsoft.AspNetCore.Server.Kestrel.Internal; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.AspNetCore.Testing; namespace Microsoft.AspNetCore.Server.Kestrel.Performance @@ -120,25 +118,24 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance { DateHeaderValueManager = new DateHeaderValueManager(), ServerOptions = new KestrelServerOptions(), - Log = new MockTrace() + Log = new MockTrace(), + HttpParserFactory = f => new KestrelHttpParser(log: null) }; - var listenerContext = new ListenerContext(serviceContext) + var frameContext = new FrameContext { - ListenOptions = new ListenOptions(new IPEndPoint(IPAddress.Loopback, 5000)) + ServiceContext = serviceContext, + ConnectionInformation = new MockConnectionInformation() }; - var connectionContext = new ConnectionContext(listenerContext) + var socketOutputProducer = new SocketOutputProducer(output.Writer, null, null, null); + var frame = new TestFrame(application: null, context: frameContext) { - Input = input, + Input = input.Reader, Output = socketOutput, - ConnectionControl = new MockConnectionControl() + LifetimeControl = new ConnectionLifetimeControl(null, output.Reader, socketOutputProducer, serviceContext.Log) }; - connectionContext.ListenerContext.ServiceContext.HttpParserFactory = f => new KestrelHttpParser(log: null); - connectionContext.ListenerContext.ServiceContext.ServerOptions = new KestrelServerOptions(); - - var frame = new TestFrame(application: null, context: connectionContext); frame.Reset(); frame.InitializeHeaders(); diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/.KestrelEventSourceTests.cs.swp b/test/Microsoft.AspNetCore.Server.KestrelTests/.KestrelEventSourceTests.cs.swp new file mode 100644 index 0000000000000000000000000000000000000000..04ade1cbf73f343ab4f618eaa6ba2c9e7200634c GIT binary patch literal 12288 zcmeI2&u<$=6vwB%0&Rgi4DMwu#j~m7I&GpJOmJI6VyfCHL5Rb6cN`B|&nz>uCRW9t zzya}BfH-mH%#S-q{sZ_Q;JfzPaT+z^Oy5Xf@BDag-n`F_A~}Ae?Pt9szAIV`?G|Ha z*Z({zyZ7!g<|i@>%9X<_+u(8MaM*p?IJtAB89UgEkG*m}t~QQSHH(jpo?%YKA1NQ4 z${vT150t}P9553f>BL!Y$3b*_-dEwkIwh6{qH-C+&aeEtGiAcS7A{eXd6D?5PerRl z;8h`TgY7i$Y~QZE$KQVI_*F@o@+1O8fCvx)B0vO)01+SpM4%!N@@woL^shtjK-Vha zL5&Cy0U|&IhyW2F0z`la5CI}U1c(3;_@5AvDZcl=#@G)~`TKwQKY-tFGWIES0(}TY z&`s!%8;t!5{Q`XleG5&X5j246(7VuYZ!k87-iJ8!CUgt>`*p_tg1&)j(9ekZ6ZB&h z|NHU`)QA8PAOb{y2oM1xKm>>Y5deX&8An@wUhI{ljz?u}5PciE(>%`>fo3)v74nFAJGPj|!cN zCla;0QEil}QLDY%ZpfXsYTRwLnvHaH|9+#j+it1mPP3itrnUMOzj&-rZc&})%22g+ z6>#Ic3b?VX0&Y}Qz_m-e_vKV=?9NtMl+SZs{UXa&R{QwEve911zFg6#1_j6m(yKi_ zmYG*1_4;^-m?1&W`md^b?m zE=HJ1$Cs~|Ki~mx+K!_`Jt}5HCymdo3lC)ytee+yH9~n65Wz-uoMm|(R@2e?;Lq2+ zyclIV;WMjK-aXT(y#7Ro397Q4NTAo-$|#>NhD-O#HOX-8_~k4X<=X5yGk9%2 zmxO>i@QeK!;IUXj8caRqz)yfushSGQJ&zoXf@PS&dh;SCTHVdEJ z*)MPm?yL=bY#j&xa$l@tG?nE6MH%nF=5wb{CxJ&vor`{V$RAq7URv-@mhr{1=T70T J#Z0Aw{R literal 0 HcmV?d00001 diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/AsciiDecoding.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/AsciiDecoding.cs index 5252a96e9a..4e5528d440 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/AsciiDecoding.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/AsciiDecoding.cs @@ -3,7 +3,6 @@ using System; using System.Linq; -using Microsoft.AspNetCore.Server.Kestrel; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Xunit; diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedResponseTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedResponseTests.cs index ad35e4339a..ed28131ead 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedResponseTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedResponseTests.cs @@ -8,7 +8,6 @@ using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Server.Kestrel; -using Microsoft.AspNetCore.Server.KestrelTests.TestHelpers; using Microsoft.AspNetCore.Testing; using Xunit; diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionAdapterTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionAdapterTests.cs index c842e0e83e..21d1ab94f4 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionAdapterTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionAdapterTests.cs @@ -9,7 +9,6 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Server.Kestrel; using Microsoft.AspNetCore.Server.Kestrel.Adapter; -using Microsoft.AspNetCore.Server.KestrelTests.TestHelpers; using Microsoft.AspNetCore.Testing; using Xunit; diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionTests.cs index bd0b197235..a37e4c9a94 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionTests.cs @@ -1,18 +1,14 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System.Net; +using System; using System.Threading; using System.Threading.Tasks; -using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Server.Kestrel; using Microsoft.AspNetCore.Server.Kestrel.Internal; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; using Microsoft.AspNetCore.Server.KestrelTests.TestHelpers; using Microsoft.AspNetCore.Testing; -using Microsoft.Extensions.Internal; using Xunit; namespace Microsoft.AspNetCore.Server.KestrelTests @@ -22,43 +18,40 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [Fact] public async Task DoesNotEndConnectionOnZeroRead() { - var mockLibuv = new MockLibuv(); - var serviceContext = new TestServiceContext + using (var mockConnectionHandler = new MockConnectionHandler()) { - FrameFactory = connectionContext => new Frame( - new DummyApplication(httpContext => TaskCache.CompletedTask), connectionContext) - }; + var mockLibuv = new MockLibuv(); + var serviceContext = new TestServiceContext(); + serviceContext.TransportContext.ConnectionHandler = mockConnectionHandler; - // Ensure ProcessRequestAsync runs inline with the ReadCallback - serviceContext.ThreadPool = new InlineLoggingThreadPool(serviceContext.Log); + var engine = new KestrelEngine(mockLibuv, serviceContext.TransportContext, null); + var thread = new KestrelThread(engine); - using (var engine = new KestrelEngine(mockLibuv, serviceContext)) - { - engine.Start(count: 1); - - var listenerContext = new ListenerContext(serviceContext) + try { - ListenOptions = new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0)), - Thread = engine.Threads[0] - }; + await thread.StartAsync(); + await thread.PostAsync(_ => + { + var listenerContext = new ListenerContext(serviceContext.TransportContext) + { + Thread = thread + }; + var socket = new MockSocket(mockLibuv, Thread.CurrentThread.ManagedThreadId, serviceContext.Log); + var connection = new Connection(listenerContext, socket); + connection.Start(); - Connection connection = null; - await listenerContext.Thread.PostAsync(_ => - { - var socket = new MockSocket(mockLibuv, Thread.CurrentThread.ManagedThreadId, serviceContext.Log); - connection = new Connection(listenerContext, socket); - connection.Start(); - - Libuv.uv_buf_t ignored; - mockLibuv.AllocCallback(socket.InternalGetHandle(), 2048, out ignored); - // This runs the ProcessRequestAsync inline - mockLibuv.ReadCallback(socket.InternalGetHandle(), 0, ref ignored); - - var readAwaitable = connection.Input.Reader.ReadAsync(); + LibuvFunctions.uv_buf_t ignored; + mockLibuv.AllocCallback(socket.InternalGetHandle(), 2048, out ignored); + mockLibuv.ReadCallback(socket.InternalGetHandle(), 0, ref ignored); + }, (object)null); + var readAwaitable = await mockConnectionHandler.Input.Reader.ReadAsync(); Assert.False(readAwaitable.IsCompleted); - }, (object)null); - connection.ConnectionControl.End(ProduceEndType.SocketDisconnect); + } + finally + { + await thread.StopAsync(TimeSpan.FromSeconds(1)); + } } } } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs index f138f063ba..076729e510 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs @@ -15,8 +15,6 @@ using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Server.Kestrel; using Microsoft.AspNetCore.Server.Kestrel.Internal; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; -using Microsoft.AspNetCore.Server.KestrelTests.TestHelpers; using Microsoft.AspNetCore.Testing; using Microsoft.Extensions.Internal; using Xunit; @@ -38,35 +36,40 @@ namespace Microsoft.AspNetCore.Server.KestrelTests }; [Fact] - public void EngineCanStartAndStop() + public async Task EngineCanStartAndStop() { - var engine = new KestrelEngine(new TestServiceContext()); - engine.Start(1); - engine.Dispose(); + var serviceContext = new TestServiceContext(); + + // The engine can no longer start threads without binding to an endpoint. + var engine = new KestrelEngine(serviceContext.TransportContext, + new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0))); + + await engine.BindAsync(); + await engine.StopAsync(); } [Theory] [MemberData(nameof(ConnectionAdapterData))] - public void ListenerCanCreateAndDispose(ListenOptions listenOptions) + public async Task ListenerCanCreateAndDispose(ListenOptions listenOptions) { var testContext = new TestServiceContext(); testContext.App = TestApp.EchoApp; - var engine = new KestrelEngine(testContext); - engine.Start(1); - var started = engine.CreateServer(listenOptions); - started.Dispose(); - engine.Dispose(); + var engine = new KestrelEngine(testContext.TransportContext, listenOptions); + + await engine.BindAsync(); + await engine.UnbindAsync(); + await engine.StopAsync(); } [Theory] [MemberData(nameof(ConnectionAdapterData))] - public void ConnectionCanReadAndWrite(ListenOptions listenOptions) + public async Task ConnectionCanReadAndWrite(ListenOptions listenOptions) { var testContext = new TestServiceContext(); testContext.App = TestApp.EchoApp; - var engine = new KestrelEngine(testContext); - engine.Start(1); - var started = engine.CreateServer(listenOptions); + var engine = new KestrelEngine(testContext.TransportContext, listenOptions); + + await engine.BindAsync(); var socket = TestConnection.CreateConnectedLoopbackSocket(listenOptions.IPEndPoint.Port); var data = "Hello World"; @@ -78,8 +81,9 @@ namespace Microsoft.AspNetCore.Server.KestrelTests read += socket.Receive(buffer, read, buffer.Length - read, SocketFlags.None); } socket.Dispose(); - started.Dispose(); - engine.Dispose(); + + await engine.UnbindAsync(); + await engine.StopAsync(); } [Theory] @@ -798,7 +802,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests Assert.True(onStartingCalled); Assert.Equal(1, testLogger.ApplicationErrorsLogged); } - + [MemberData(nameof(ConnectionAdapterData))] public async Task ConnectionClosesWhenFinReceivedBeforeRequestCompletes(ListenOptions listenOptions) { diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameResponseHeadersTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameResponseHeadersTests.cs index 7b908fd642..d626512420 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameResponseHeadersTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameResponseHeadersTests.cs @@ -5,11 +5,9 @@ using System; using System.Collections.Generic; using System.Globalization; using System.IO.Pipelines; -using System.Net; using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Server.Kestrel; -using Microsoft.AspNetCore.Server.Kestrel.Internal; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; +using Microsoft.AspNetCore.Testing; using Microsoft.Extensions.Primitives; using Xunit; @@ -20,21 +18,12 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [Fact] public void InitialDictionaryIsEmpty() { - var serverOptions = new KestrelServerOptions(); - - var serviceContext = new ServiceContext + var frameContext = new FrameContext { - DateHeaderValueManager = new DateHeaderValueManager(), - ServerOptions = serverOptions, - HttpParserFactory = f => new NoopHttpParser(), + ServiceContext = new TestServiceContext() }; - var listenerContext = new ListenerContext(serviceContext) - { - ListenOptions = new ListenOptions(new IPEndPoint(IPAddress.Loopback, 5000)) - }; - var connectionContext = new ConnectionContext(listenerContext); - var frame = new Frame(application: null, context: connectionContext); + var frame = new Frame(application: null, frameContext: frameContext); frame.InitializeHeaders(); @@ -287,7 +276,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests public void Reset() { - + } } } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs index a87cd5e8a8..9e0a068f16 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs @@ -16,6 +16,7 @@ using Microsoft.AspNetCore.Server.Kestrel; using Microsoft.AspNetCore.Server.Kestrel.Internal; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Transport; using Microsoft.AspNetCore.Testing; using Microsoft.Extensions.Internal; using Microsoft.Extensions.Logging; @@ -29,14 +30,14 @@ namespace Microsoft.AspNetCore.Server.KestrelTests private readonly IPipe _input; private readonly TestFrame _frame; private readonly ServiceContext _serviceContext; - private readonly ConnectionContext _connectionContext; + private readonly FrameContext _frameContext; private readonly PipeFactory _pipelineFactory; private ReadCursor _consumed; private ReadCursor _examined; private class TestFrame : Frame { - public TestFrame(IHttpApplication application, ConnectionContext context) + public TestFrame(IHttpApplication application, FrameContext context) : base(application, context) { } @@ -49,29 +50,23 @@ namespace Microsoft.AspNetCore.Server.KestrelTests public FrameTests() { - var trace = new KestrelTrace(new TestKestrelTrace()); _pipelineFactory = new PipeFactory(); _input = _pipelineFactory.Create(); - _serviceContext = new ServiceContext + _serviceContext = new TestServiceContext(); + + _frameContext = new FrameContext { - DateHeaderValueManager = new DateHeaderValueManager(), - ServerOptions = new KestrelServerOptions(), - HttpParserFactory = frame => new KestrelHttpParser(trace), - Log = trace - }; - var listenerContext = new ListenerContext(_serviceContext) - { - ListenOptions = new ListenOptions(new IPEndPoint(IPAddress.Loopback, 5000)) - }; - _connectionContext = new ConnectionContext(listenerContext) - { - Input = _input, - Output = new MockSocketOutput(), - ConnectionControl = Mock.Of() + ServiceContext = _serviceContext, + ConnectionInformation = new MockConnectionInformation() + }; + + _frame = new TestFrame(application: null, context: _frameContext) + { + Input = _input.Reader, + Output = new MockSocketOutput() }; - _frame = new TestFrame(application: null, context: _connectionContext); _frame.Reset(); _frame.InitializeHeaders(); } @@ -295,8 +290,9 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [Fact] public async Task ParseRequestStartsRequestHeadersTimeoutOnFirstByteAvailable() { - var connectionControl = new Mock(); - _connectionContext.ConnectionControl = connectionControl.Object; + var connectionInfo = (MockConnectionInformation)_frameContext.ConnectionInformation; + var connectionControl = new Mock(); + connectionInfo.TimeoutControl = connectionControl.Object; await _input.Writer.WriteAsync(Encoding.ASCII.GetBytes("G")); @@ -418,8 +414,9 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [Fact] public void RequestProcessingAsyncEnablesKeepAliveTimeout() { - var connectionControl = new Mock(); - _connectionContext.ConnectionControl = connectionControl.Object; + var connectionInfo = (MockConnectionInformation)_frameContext.ConnectionInformation; + var connectionControl = new Mock(); + connectionInfo.TimeoutControl = connectionControl.Object; var requestProcessingTask = _frame.RequestProcessingAsync(); @@ -635,7 +632,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } } - public static TheoryData TargetInvalidData + public static TheoryData TargetInvalidData => HttpParsingData.TargetInvalidData; public static TheoryData MethodNotAllowedTargetData @@ -685,5 +682,16 @@ namespace Microsoft.AspNetCore.Server.KestrelTests return data; } } + + private class MockConnectionInformation : IConnectionInformation + { + public ListenOptions ListenOptions { get; } + public IPEndPoint RemoteEndPoint { get; } + public IPEndPoint LocalEndPoint { get; } + public PipeFactory PipeFactory { get; } + public IScheduler InputWriterScheduler { get; } + public IScheduler OutputWriterScheduler { get; } + public ITimeoutControl TimeoutControl { get; set; } = Mock.Of(); + } } } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelEventSourceTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelEventSourceTests.cs index 4661097172..1d5c1fdd81 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelEventSourceTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelEventSourceTests.cs @@ -4,7 +4,7 @@ using System; using System.Diagnostics.Tracing; using System.Reflection; -using Microsoft.AspNetCore.Server.Kestrel; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv; using Xunit; namespace Microsoft.AspNetCore.Server.KestrelTests @@ -14,7 +14,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [Fact] public void ExistsWithCorrectId() { - var esType = typeof(KestrelServer).GetTypeInfo().Assembly.GetType( + var esType = typeof(LibuvTransportFactory).GetTypeInfo().Assembly.GetType( "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.KestrelEventSource", throwOnError: true, ignoreCase: false diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerOptionsTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerOptionsTests.cs index 8b7fa7d599..3d1e3eb9a2 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerOptionsTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerOptionsTests.cs @@ -53,21 +53,5 @@ namespace Microsoft.AspNetCore.Server.KestrelTests Assert.True(o1.ListenOptions[0].NoDelay); Assert.False(o1.ListenOptions[1].NoDelay); } - - [Fact] - public void SetThreadCountUsingProcessorCount() - { - // Ideally we'd mock Environment.ProcessorCount to test edge cases. - var expected = Clamp(Environment.ProcessorCount >> 1, 1, 16); - - var information = new KestrelServerOptions(); - - Assert.Equal(expected, information.ThreadCount); - } - - private static int Clamp(int value, int min, int max) - { - return value < min ? min : value > max ? max : value; - } } } \ No newline at end of file diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerTests.cs index c22bdf6789..dd36a36669 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerTests.cs @@ -7,6 +7,7 @@ using System.Net; using Microsoft.AspNetCore.Hosting.Server; using Microsoft.AspNetCore.Hosting.Server.Features; using Microsoft.AspNetCore.Server.Kestrel; +using Microsoft.AspNetCore.Server.Kestrel.Transport; using Microsoft.AspNetCore.Testing; using Microsoft.Extensions.Internal; using Microsoft.Extensions.Logging; @@ -18,22 +19,6 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { public class KestrelServerTests { - [Theory] - [InlineData(0)] - [InlineData(-1337)] - public void StartWithNonPositiveThreadCountThrows(int threadCount) - { - var testLogger = new TestApplicationErrorLogger { ThrowOnCriticalErrors = false }; - - using (var server = CreateServer(new KestrelServerOptions() { ThreadCount = threadCount }, testLogger)) - { - var exception = Assert.Throws(() => StartDummyApplication(server)); - - Assert.Equal("threadCount", exception.ParamName); - Assert.Equal(1, testLogger.CriticalErrorsLogged); - } - } - [Fact] public void StartWithInvalidAddressThrows() { @@ -119,20 +104,35 @@ namespace Microsoft.AspNetCore.Server.KestrelTests public void LoggerCategoryNameIsKestrelServerNamespace() { var mockLoggerFactory = new Mock(); - new KestrelServer(Options.Create(null), new LifetimeNotImplemented(), mockLoggerFactory.Object); + new KestrelServer(Options.Create(null), Mock.Of(), mockLoggerFactory.Object); mockLoggerFactory.Verify(factory => factory.CreateLogger("Microsoft.AspNetCore.Server.Kestrel")); } + [Fact] + public void StartWithNoTrasnportFactoryThrows() + { + var exception = Assert.Throws(() => + new KestrelServer(Options.Create(null), null, Mock.Of())); + + Assert.Equal("transportFactory", exception.ParamName); + } + private static KestrelServer CreateServer(KestrelServerOptions options, ILogger testLogger) { - var lifetime = new LifetimeNotImplemented(); - - return new KestrelServer(Options.Create(options), lifetime, new KestrelTestLoggerFactory(testLogger)); + return new KestrelServer(Options.Create(options), new MockTransportFactory(), new KestrelTestLoggerFactory(testLogger)); } private static void StartDummyApplication(IServer server) { server.Start(new DummyApplication(context => TaskCache.CompletedTask)); } + + private class MockTransportFactory : ITransportFactory + { + public ITransport Create(ListenOptions listenOptions, IConnectionHandler handler) + { + return Mock.Of(); + } + } } } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/LibuvTransportFactoryTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/LibuvTransportFactoryTests.cs new file mode 100644 index 0000000000..2d0dc0c2b7 --- /dev/null +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/LibuvTransportFactoryTests.cs @@ -0,0 +1,37 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv; +using Microsoft.AspNetCore.Testing; +using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Options; +using Moq; +using Xunit; + +namespace Microsoft.AspNetCore.Server.KestrelTests +{ + public class LibuvTransportFactoryTests + { + [Theory] + [InlineData(0)] + [InlineData(-1337)] + public void StartWithNonPositiveThreadCountThrows(int threadCount) + { + var options = new LibuvTransportOptions() { ThreadCount = threadCount }; + + var exception = Assert.Throws(() => + new LibuvTransportFactory(Options.Create(options), new LifetimeNotImplemented(), Mock.Of())); + + Assert.Equal("threadCount", exception.ParamName); + } + + [Fact] + public void LoggerCategoryNameIsKestrelServerNamespace() + { + var mockLoggerFactory = new Mock(); + new LibuvTransportFactory(Options.Create(new LibuvTransportOptions()), new LifetimeNotImplemented(), mockLoggerFactory.Object); + mockLoggerFactory.Verify(factory => factory.CreateLogger("Microsoft.AspNetCore.Server.Kestrel")); + } + } +} diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/LibuvTransportOptionsTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/LibuvTransportOptionsTests.cs new file mode 100644 index 0000000000..df45392c07 --- /dev/null +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/LibuvTransportOptionsTests.cs @@ -0,0 +1,28 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv; +using Xunit; + +namespace Microsoft.AspNetCore.Server.KestrelTests +{ + public class LibuvTransportOptionsTests + { + [Fact] + public void SetThreadCountUsingProcessorCount() + { + // Ideally we'd mock Environment.ProcessorCount to test edge cases. + var expected = Clamp(Environment.ProcessorCount >> 1, 1, 16); + + var information = new LibuvTransportOptions(); + + Assert.Equal(expected, information.ThreadCount); + } + + private static int Clamp(int value, int min, int max) + { + return value < min ? min : value > max ? max : value; + } + } +} diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/ListenerContextTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/ListenerContextTests.cs deleted file mode 100644 index 4004c95850..0000000000 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/ListenerContextTests.cs +++ /dev/null @@ -1,72 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System.IO.Pipelines; -using Microsoft.AspNetCore.Server.Kestrel.Internal; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; -using Microsoft.AspNetCore.Testing; -using Xunit; - -namespace Microsoft.AspNetCore.Server.KestrelTests -{ - public class ListenerContextTests - { - [Theory] - [InlineData(10, 10, 10)] - [InlineData(0, 1, 1)] - [InlineData(null, 0, 0)] - public void LibuvOutputPipeOptionsConfiguredCorrectly(long? maxResponseBufferSize, long expectedMaximumSizeLow, long expectedMaximumSizeHigh) - { - var serviceContext = new TestServiceContext(); - serviceContext.ServerOptions.Limits.MaxResponseBufferSize = maxResponseBufferSize; - serviceContext.ThreadPool = new LoggingThreadPool(null); - - var listenerContext = new ListenerContext(serviceContext) - { - Thread = new KestrelThread(new KestrelEngine(null, serviceContext)) - }; - - Assert.Equal(expectedMaximumSizeLow, listenerContext.LibuvOutputPipeOptions.MaximumSizeLow); - Assert.Equal(expectedMaximumSizeHigh, listenerContext.LibuvOutputPipeOptions.MaximumSizeHigh); - Assert.Same(listenerContext.Thread, listenerContext.LibuvOutputPipeOptions.ReaderScheduler); - Assert.Same(serviceContext.ThreadPool, listenerContext.LibuvOutputPipeOptions.WriterScheduler); - } - - [Theory] - [InlineData(10, 10, 10)] - [InlineData(null, 0, 0)] - public void LibuvInputPipeOptionsConfiguredCorrectly(long? maxRequestBufferSize, long expectedMaximumSizeLow, long expectedMaximumSizeHigh) - { - var serviceContext = new TestServiceContext(); - serviceContext.ServerOptions.Limits.MaxRequestBufferSize = maxRequestBufferSize; - serviceContext.ThreadPool = new LoggingThreadPool(null); - - var listenerContext = new ListenerContext(serviceContext) - { - Thread = new KestrelThread(new KestrelEngine(null, serviceContext)) - }; - - Assert.Equal(expectedMaximumSizeLow, listenerContext.LibuvInputPipeOptions.MaximumSizeLow); - Assert.Equal(expectedMaximumSizeHigh, listenerContext.LibuvInputPipeOptions.MaximumSizeHigh); - Assert.Same(serviceContext.ThreadPool, listenerContext.LibuvInputPipeOptions.ReaderScheduler); - Assert.Same(listenerContext.Thread, listenerContext.LibuvInputPipeOptions.WriterScheduler); - } - - [Theory] - [InlineData(10, 10, 10)] - [InlineData(null, 0, 0)] - public void AdaptedPipeOptionsConfiguredCorrectly(long? maxRequestBufferSize, long expectedMaximumSizeLow, long expectedMaximumSizeHigh) - { - var serviceContext = new TestServiceContext(); - serviceContext.ServerOptions.Limits.MaxRequestBufferSize = maxRequestBufferSize; - - var listenerContext = new ListenerContext(serviceContext); - - Assert.Equal(expectedMaximumSizeLow, listenerContext.AdaptedPipeOptions.MaximumSizeLow); - Assert.Equal(expectedMaximumSizeHigh, listenerContext.AdaptedPipeOptions.MaximumSizeHigh); - Assert.Same(InlineScheduler.Default, listenerContext.AdaptedPipeOptions.ReaderScheduler); - Assert.Same(InlineScheduler.Default, listenerContext.AdaptedPipeOptions.WriterScheduler); - } - } -} diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/ListenerPrimaryTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/ListenerPrimaryTests.cs index 486b9ffda5..8045cb651a 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/ListenerPrimaryTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/ListenerPrimaryTests.cs @@ -12,8 +12,8 @@ using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Server.Kestrel; using Microsoft.AspNetCore.Server.Kestrel.Internal; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; +using Microsoft.AspNetCore.Server.KestrelTests.TestHelpers; using Microsoft.AspNetCore.Testing; using Microsoft.Extensions.Logging; using Xunit; @@ -25,273 +25,221 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [Fact] public async Task ConnectionsGetRoundRobinedToSecondaryListeners() { - var libuv = new Libuv(); + var libuv = new LibuvFunctions(); var serviceContextPrimary = new TestServiceContext { - FrameFactory = context => - { - return new Frame(new TestApplication(c => - { - return c.Response.WriteAsync("Primary"); - }), context); - } + App = c => c.Response.WriteAsync("Primary") }; - var serviceContextSecondary = new ServiceContext + var serviceContextSecondary = new TestServiceContext { - Log = serviceContextPrimary.Log, - AppLifetime = serviceContextPrimary.AppLifetime, - DateHeaderValueManager = serviceContextPrimary.DateHeaderValueManager, - ServerOptions = serviceContextPrimary.ServerOptions, - ThreadPool = serviceContextPrimary.ThreadPool, - HttpParserFactory = frame => new KestrelHttpParser(serviceContextPrimary.Log), - FrameFactory = context => - { - return new Frame(new TestApplication(c => - { - return c.Response.WriteAsync("Secondary"); - }), context); - } + App = c => c.Response.WriteAsync("Secondary") }; - using (var kestrelEngine = new KestrelEngine(libuv, serviceContextPrimary)) - { - var listenOptions = new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0)); + var listenOptions = new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0)); + var kestrelEngine = new KestrelEngine(libuv, serviceContextPrimary.TransportContext, listenOptions); - var pipeName = (libuv.IsWindows ? @"\\.\pipe\kestrel_" : "/tmp/kestrel_") + Guid.NewGuid().ToString("n"); - var pipeMessage = Guid.NewGuid().ToByteArray(); + var pipeName = (libuv.IsWindows ? @"\\.\pipe\kestrel_" : "/tmp/kestrel_") + Guid.NewGuid().ToString("n"); + var pipeMessage = Guid.NewGuid().ToByteArray(); - // Start primary listener - var kestrelThreadPrimary = new KestrelThread(kestrelEngine); - await kestrelThreadPrimary.StartAsync(); - var listenerPrimary = new ListenerPrimary(serviceContextPrimary); - await listenerPrimary.StartAsync(pipeName, pipeMessage, listenOptions, kestrelThreadPrimary); - var address = listenOptions.ToString(); + // Start primary listener + var kestrelThreadPrimary = new KestrelThread(kestrelEngine); + await kestrelThreadPrimary.StartAsync(); + var listenerPrimary = new ListenerPrimary(serviceContextPrimary.TransportContext); + await listenerPrimary.StartAsync(pipeName, pipeMessage, listenOptions, kestrelThreadPrimary); + var address = listenOptions.ToString(); - // Until a secondary listener is added, TCP connections get dispatched directly - Assert.Equal("Primary", await HttpClientSlim.GetStringAsync(address)); - Assert.Equal("Primary", await HttpClientSlim.GetStringAsync(address)); + // Until a secondary listener is added, TCP connections get dispatched directly + Assert.Equal("Primary", await HttpClientSlim.GetStringAsync(address)); + Assert.Equal("Primary", await HttpClientSlim.GetStringAsync(address)); - // Add secondary listener - var kestrelThreadSecondary = new KestrelThread(kestrelEngine); - await kestrelThreadSecondary.StartAsync(); - var listenerSecondary = new ListenerSecondary(serviceContextSecondary); - await listenerSecondary.StartAsync(pipeName, pipeMessage, listenOptions, kestrelThreadSecondary); + // Add secondary listener + var kestrelThreadSecondary = new KestrelThread(kestrelEngine); + await kestrelThreadSecondary.StartAsync(); + var listenerSecondary = new ListenerSecondary(serviceContextSecondary.TransportContext); + await listenerSecondary.StartAsync(pipeName, pipeMessage, listenOptions, kestrelThreadSecondary); - // Once a secondary listener is added, TCP connections start getting dispatched to it - await AssertResponseEventually(address, "Secondary", allowed: new[] { "Primary" }); + // Once a secondary listener is added, TCP connections start getting dispatched to it + await AssertResponseEventually(address, "Secondary", allowed: new[] { "Primary" }); - // TCP connections will still get round-robined to the primary listener - Assert.Equal("Primary", await HttpClientSlim.GetStringAsync(address)); - Assert.Equal("Secondary", await HttpClientSlim.GetStringAsync(address)); - Assert.Equal("Primary", await HttpClientSlim.GetStringAsync(address)); + // TCP connections will still get round-robined to the primary listener + Assert.Equal("Primary", await HttpClientSlim.GetStringAsync(address)); + Assert.Equal("Secondary", await HttpClientSlim.GetStringAsync(address)); + Assert.Equal("Primary", await HttpClientSlim.GetStringAsync(address)); - await listenerSecondary.DisposeAsync(); - await kestrelThreadSecondary.StopAsync(TimeSpan.FromSeconds(1)); + await listenerSecondary.DisposeAsync(); + await kestrelThreadSecondary.StopAsync(TimeSpan.FromSeconds(1)); - await listenerPrimary.DisposeAsync(); - await kestrelThreadPrimary.StopAsync(TimeSpan.FromSeconds(1)); - } + await listenerPrimary.DisposeAsync(); + await kestrelThreadPrimary.StopAsync(TimeSpan.FromSeconds(1)); } // https://github.com/aspnet/KestrelHttpServer/issues/1182 [Fact] public async Task NonListenerPipeConnectionsAreLoggedAndIgnored() { - var libuv = new Libuv(); - - var primaryTrace = new TestKestrelTrace(); + var libuv = new LibuvFunctions(); var serviceContextPrimary = new TestServiceContext { - Log = primaryTrace, - FrameFactory = context => - { - return new Frame(new TestApplication(c => - { - return c.Response.WriteAsync("Primary"); - }), context); - } + App = c => c.Response.WriteAsync("Primary") }; - var serviceContextSecondary = new ServiceContext + var serviceContextSecondary = new TestServiceContext { - Log = new TestKestrelTrace(), - AppLifetime = serviceContextPrimary.AppLifetime, DateHeaderValueManager = serviceContextPrimary.DateHeaderValueManager, ServerOptions = serviceContextPrimary.ServerOptions, ThreadPool = serviceContextPrimary.ThreadPool, - HttpParserFactory = frame => new KestrelHttpParser(serviceContextPrimary.Log), - FrameFactory = context => - { - return new Frame(new TestApplication(c => - { - return c.Response.WriteAsync("Secondary"); ; - }), context); - } + HttpParserFactory = serviceContextPrimary.HttpParserFactory, + App = c => c.Response.WriteAsync("Secondary") }; - using (var kestrelEngine = new KestrelEngine(libuv, serviceContextPrimary)) + var listenOptions = new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0)); + var kestrelEngine = new KestrelEngine(libuv, serviceContextPrimary.TransportContext, listenOptions); + + var pipeName = (libuv.IsWindows ? @"\\.\pipe\kestrel_" : "/tmp/kestrel_") + Guid.NewGuid().ToString("n"); + var pipeMessage = Guid.NewGuid().ToByteArray(); + + // Start primary listener + var kestrelThreadPrimary = new KestrelThread(kestrelEngine); + await kestrelThreadPrimary.StartAsync(); + var listenerPrimary = new ListenerPrimary(serviceContextPrimary.TransportContext); + await listenerPrimary.StartAsync(pipeName, pipeMessage, listenOptions, kestrelThreadPrimary); + var address = listenOptions.ToString(); + + // Add secondary listener + var kestrelThreadSecondary = new KestrelThread(kestrelEngine); + await kestrelThreadSecondary.StartAsync(); + var listenerSecondary = new ListenerSecondary(serviceContextSecondary.TransportContext); + await listenerSecondary.StartAsync(pipeName, pipeMessage, listenOptions, kestrelThreadSecondary); + + // TCP Connections get round-robined + await AssertResponseEventually(address, "Secondary", allowed: new[] { "Primary" }); + Assert.Equal("Primary", await HttpClientSlim.GetStringAsync(address)); + + // Create a pipe connection and keep it open without sending any data + var connectTcs = new TaskCompletionSource(); + var connectionTrace = new TestKestrelTrace(); + var pipe = new UvPipeHandle(connectionTrace); + + kestrelThreadPrimary.Post(_ => { - var listenOptions = new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0)); - var pipeName = (libuv.IsWindows ? @"\\.\pipe\kestrel_" : "/tmp/kestrel_") + Guid.NewGuid().ToString("n"); - var pipeMessage = Guid.NewGuid().ToByteArray(); + var connectReq = new UvConnectRequest(connectionTrace); - // Start primary listener - var kestrelThreadPrimary = new KestrelThread(kestrelEngine); - await kestrelThreadPrimary.StartAsync(); - var listenerPrimary = new ListenerPrimary(serviceContextPrimary); - await listenerPrimary.StartAsync(pipeName, pipeMessage, listenOptions, kestrelThreadPrimary); - var address = listenOptions.ToString(); + pipe.Init(kestrelThreadPrimary.Loop, kestrelThreadPrimary.QueueCloseHandle); + connectReq.Init(kestrelThreadPrimary.Loop); - // Add secondary listener - var kestrelThreadSecondary = new KestrelThread(kestrelEngine); - await kestrelThreadSecondary.StartAsync(); - var listenerSecondary = new ListenerSecondary(serviceContextSecondary); - await listenerSecondary.StartAsync(pipeName, pipeMessage, listenOptions, kestrelThreadSecondary); + connectReq.Connect( + pipe, + pipeName, + (req, status, ex, __) => + { + req.Dispose(); - // TCP Connections get round-robined - await AssertResponseEventually(address, "Secondary", allowed: new[] { "Primary" }); - Assert.Equal("Primary", await HttpClientSlim.GetStringAsync(address)); - - // Create a pipe connection and keep it open without sending any data - var connectTcs = new TaskCompletionSource(); - var connectionTrace = new TestKestrelTrace(); - var pipe = new UvPipeHandle(connectionTrace); - - kestrelThreadPrimary.Post(_ => - { - var connectReq = new UvConnectRequest(connectionTrace); - - pipe.Init(kestrelThreadPrimary.Loop, kestrelThreadPrimary.QueueCloseHandle); - connectReq.Init(kestrelThreadPrimary.Loop); - - connectReq.Connect( - pipe, - pipeName, - (req, status, ex, __) => + if (ex != null) { - req.Dispose(); + connectTcs.SetException(ex); + } + else + { + connectTcs.SetResult(null); + } + }, + null); + }, (object)null); - if (ex != null) - { - connectTcs.SetException(ex); - } - else - { - connectTcs.SetResult(null); - } - }, - null); - }, (object)null); + await connectTcs.Task; - await connectTcs.Task; + // TCP connections will still get round-robined between only the two listeners + Assert.Equal("Secondary", await HttpClientSlim.GetStringAsync(address)); + Assert.Equal("Primary", await HttpClientSlim.GetStringAsync(address)); + Assert.Equal("Secondary", await HttpClientSlim.GetStringAsync(address)); - // TCP connections will still get round-robined between only the two listeners - Assert.Equal("Secondary", await HttpClientSlim.GetStringAsync(address)); - Assert.Equal("Primary", await HttpClientSlim.GetStringAsync(address)); - Assert.Equal("Secondary", await HttpClientSlim.GetStringAsync(address)); + await kestrelThreadPrimary.PostAsync(_ => pipe.Dispose(), (object)null); - await kestrelThreadPrimary.PostAsync(_ => pipe.Dispose(), (object)null); + var primaryTrace = (TestKestrelTrace)serviceContextPrimary.Log; - // Wait up to 10 seconds for error to be logged - for (var i = 0; i < 10 && primaryTrace.Logger.TotalErrorsLogged == 0; i++) - { - await Task.Delay(100); - } - - // Same for after the non-listener pipe connection is closed - Assert.Equal("Primary", await HttpClientSlim.GetStringAsync(address)); - Assert.Equal("Secondary", await HttpClientSlim.GetStringAsync(address)); - Assert.Equal("Primary", await HttpClientSlim.GetStringAsync(address)); - - await listenerSecondary.DisposeAsync(); - await kestrelThreadSecondary.StopAsync(TimeSpan.FromSeconds(1)); - - await listenerPrimary.DisposeAsync(); - await kestrelThreadPrimary.StopAsync(TimeSpan.FromSeconds(1)); + // Wait up to 10 seconds for error to be logged + for (var i = 0; i < 10 && primaryTrace.Logger.TotalErrorsLogged == 0; i++) + { + await Task.Delay(100); } + // Same for after the non-listener pipe connection is closed + Assert.Equal("Primary", await HttpClientSlim.GetStringAsync(address)); + Assert.Equal("Secondary", await HttpClientSlim.GetStringAsync(address)); + Assert.Equal("Primary", await HttpClientSlim.GetStringAsync(address)); + + await listenerSecondary.DisposeAsync(); + await kestrelThreadSecondary.StopAsync(TimeSpan.FromSeconds(1)); + + await listenerPrimary.DisposeAsync(); + await kestrelThreadPrimary.StopAsync(TimeSpan.FromSeconds(1)); + Assert.Equal(1, primaryTrace.Logger.TotalErrorsLogged); var errorMessage = primaryTrace.Logger.Messages.First(m => m.LogLevel == LogLevel.Error); - Assert.Equal(Constants.EOF, Assert.IsType(errorMessage.Exception).StatusCode); + Assert.Equal(TestConstants.EOF, Assert.IsType(errorMessage.Exception).StatusCode); } [Fact] public async Task PipeConnectionsWithWrongMessageAreLoggedAndIgnored() { - var libuv = new Libuv(); - - var primaryTrace = new TestKestrelTrace(); + var libuv = new LibuvFunctions(); var serviceContextPrimary = new TestServiceContext { - Log = primaryTrace, - FrameFactory = context => - { - return new Frame(new TestApplication(c => - { - return c.Response.WriteAsync("Primary"); - }), context); - } + App = c => c.Response.WriteAsync("Primary") }; - var serviceContextSecondary = new ServiceContext + var serviceContextSecondary = new TestServiceContext { - Log = new TestKestrelTrace(), - AppLifetime = serviceContextPrimary.AppLifetime, DateHeaderValueManager = serviceContextPrimary.DateHeaderValueManager, ServerOptions = serviceContextPrimary.ServerOptions, ThreadPool = serviceContextPrimary.ThreadPool, - HttpParserFactory = frame => new KestrelHttpParser(serviceContextPrimary.Log), - FrameFactory = context => - { - return new Frame(new TestApplication(c => - { - return c.Response.WriteAsync("Secondary"); - }), context); - } + HttpParserFactory = serviceContextPrimary.HttpParserFactory, + App = c => c.Response.WriteAsync("Secondary") }; - using (var kestrelEngine = new KestrelEngine(libuv, serviceContextPrimary)) + var listenOptions = new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0)); + var kestrelEngine = new KestrelEngine(libuv, serviceContextPrimary.TransportContext, listenOptions); + + var pipeName = (libuv.IsWindows ? @"\\.\pipe\kestrel_" : "/tmp/kestrel_") + Guid.NewGuid().ToString("n"); + var pipeMessage = Guid.NewGuid().ToByteArray(); + + // Start primary listener + var kestrelThreadPrimary = new KestrelThread(kestrelEngine); + await kestrelThreadPrimary.StartAsync(); + var listenerPrimary = new ListenerPrimary(serviceContextPrimary.TransportContext); + await listenerPrimary.StartAsync(pipeName, pipeMessage, listenOptions, kestrelThreadPrimary); + var address = listenOptions.ToString(); + + // Add secondary listener with wrong pipe message + var kestrelThreadSecondary = new KestrelThread(kestrelEngine); + await kestrelThreadSecondary.StartAsync(); + var listenerSecondary = new ListenerSecondary(serviceContextSecondary.TransportContext); + await listenerSecondary.StartAsync(pipeName, Guid.NewGuid().ToByteArray(), listenOptions, kestrelThreadSecondary); + + var primaryTrace = (TestKestrelTrace)serviceContextPrimary.Log; + + // Wait up to 10 seconds for error to be logged + for (var i = 0; i < 10 && primaryTrace.Logger.TotalErrorsLogged == 0; i++) { - var listenOptions = new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0)); - var pipeName = (libuv.IsWindows ? @"\\.\pipe\kestrel_" : "/tmp/kestrel_") + Guid.NewGuid().ToString("n"); - var pipeMessage = Guid.NewGuid().ToByteArray(); - - // Start primary listener - var kestrelThreadPrimary = new KestrelThread(kestrelEngine); - await kestrelThreadPrimary.StartAsync(); - var listenerPrimary = new ListenerPrimary(serviceContextPrimary); - await listenerPrimary.StartAsync(pipeName, pipeMessage, listenOptions, kestrelThreadPrimary); - var address = listenOptions.ToString(); - - // Add secondary listener with wrong pipe message - var kestrelThreadSecondary = new KestrelThread(kestrelEngine); - await kestrelThreadSecondary.StartAsync(); - var listenerSecondary = new ListenerSecondary(serviceContextSecondary); - await listenerSecondary.StartAsync(pipeName, Guid.NewGuid().ToByteArray(), listenOptions, kestrelThreadSecondary); - - // Wait up to 10 seconds for error to be logged - for (var i = 0; i < 10 && primaryTrace.Logger.TotalErrorsLogged == 0; i++) - { - await Task.Delay(100); - } - - // TCP Connections don't get round-robined - Assert.Equal("Primary", await HttpClientSlim.GetStringAsync(address)); - Assert.Equal("Primary", await HttpClientSlim.GetStringAsync(address)); - Assert.Equal("Primary", await HttpClientSlim.GetStringAsync(address)); - - await listenerSecondary.DisposeAsync(); - await kestrelThreadSecondary.StopAsync(TimeSpan.FromSeconds(1)); - - await listenerPrimary.DisposeAsync(); - await kestrelThreadPrimary.StopAsync(TimeSpan.FromSeconds(1)); + await Task.Delay(100); } + // TCP Connections don't get round-robined + Assert.Equal("Primary", await HttpClientSlim.GetStringAsync(address)); + Assert.Equal("Primary", await HttpClientSlim.GetStringAsync(address)); + Assert.Equal("Primary", await HttpClientSlim.GetStringAsync(address)); + + await listenerSecondary.DisposeAsync(); + await kestrelThreadSecondary.StopAsync(TimeSpan.FromSeconds(1)); + + await listenerPrimary.DisposeAsync(); + await kestrelThreadPrimary.StopAsync(TimeSpan.FromSeconds(1)); + Assert.Equal(1, primaryTrace.Logger.TotalErrorsLogged); var errorMessage = primaryTrace.Logger.Messages.First(m => m.LogLevel == LogLevel.Error); Assert.IsType(errorMessage.Exception); diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/MessageBodyTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/MessageBodyTests.cs index fcb7fdbcd0..d5294de41d 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/MessageBodyTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/MessageBodyTests.cs @@ -4,7 +4,6 @@ using System; using System.Collections.Generic; using System.IO; -using System.IO.Pipelines; using System.Linq; using System.Text; using System.Threading; @@ -12,7 +11,6 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Server.Kestrel; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; -using Microsoft.AspNetCore.Testing; using Microsoft.Extensions.Internal; using Moq; using Xunit; @@ -281,7 +279,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests // The block returned by IncomingStart always has at least 2048 available bytes, // so no need to bounds check in this test. - var socketInput = input.FrameContext.Input; + var socketInput = input.Pipe; var bytes = Encoding.ASCII.GetBytes(data[0]); var buffer = socketInput.Writer.Alloc(2048); ArraySegment block; diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/Microsoft.AspNetCore.Server.KestrelTests.csproj b/test/Microsoft.AspNetCore.Server.KestrelTests/Microsoft.AspNetCore.Server.KestrelTests.csproj index 382492d093..1ee3019579 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/Microsoft.AspNetCore.Server.KestrelTests.csproj +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/Microsoft.AspNetCore.Server.KestrelTests.csproj @@ -16,6 +16,7 @@ + diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/MultipleLoopTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/MultipleLoopTests.cs index d34e0c02a5..e95605a33f 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/MultipleLoopTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/MultipleLoopTests.cs @@ -10,6 +10,7 @@ using System.Threading; using Microsoft.AspNetCore.Server.Kestrel.Internal; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; +using Microsoft.AspNetCore.Server.KestrelTests.TestHelpers; using Microsoft.AspNetCore.Testing; using Xunit; @@ -17,13 +18,12 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { public class MultipleLoopTests { - private readonly Libuv _uv; + private readonly LibuvFunctions _uv; private readonly IKestrelTrace _logger; public MultipleLoopTests() { - var engine = new KestrelEngine(new TestServiceContext()); - _uv = engine.Libuv; - _logger = engine.Log; + _uv = new LibuvFunctions(); + _logger = new TestKestrelTrace(); } [Fact] @@ -72,7 +72,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var writeRequest = new UvWriteReq(new KestrelTrace(new TestKestrelTrace())); writeRequest.Init(loop); - + await writeRequest.WriteAsync( serverConnectionPipe, ReadableBuffer.Create(new byte[] { 1, 2, 3, 4 })); @@ -101,7 +101,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests (handle2, cb, state2) => buf, (handle2, status2, state2) => { - if (status2 == Constants.EOF) + if (status2 == TestConstants.EOF) { clientConnectionPipe.Dispose(); } @@ -202,7 +202,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests (handle2, cb, state2) => buf, (handle2, status2, state2) => { - if (status2 == Constants.EOF) + if (status2 == TestConstants.EOF) { clientConnectionPipe.Dispose(); return; @@ -216,7 +216,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests (handle3, cb, state3) => buf2, (handle3, status3, state3) => { - if (status3 == Constants.EOF) + if (status3 == TestConstants.EOF) { clientConnectionTcp.Dispose(); } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/NetworkingTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/NetworkingTests.cs index 2cf84068c4..4799438634 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/NetworkingTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/NetworkingTests.cs @@ -20,13 +20,12 @@ namespace Microsoft.AspNetCore.Server.KestrelTests /// public class NetworkingTests { - private readonly Libuv _uv; + private readonly LibuvFunctions _uv; private readonly IKestrelTrace _logger; public NetworkingTests() { - var engine = new KestrelEngine(new TestServiceContext()); - _uv = engine.Libuv; - _logger = engine.Log; + _uv = new LibuvFunctions(); + _logger = new TestKestrelTrace(); } [Fact] @@ -171,7 +170,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var req = new UvWriteReq(new KestrelTrace(new TestKestrelTrace())); req.Init(loop); var block = ReadableBuffer.Create(new byte[] { 65, 66, 67, 68, 69 }); - + await req.WriteAsync( tcp2, block); diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/PipeOptionsTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/PipeOptionsTests.cs new file mode 100644 index 0000000000..924a4200e5 --- /dev/null +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/PipeOptionsTests.cs @@ -0,0 +1,73 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System.IO.Pipelines; +using Microsoft.AspNetCore.Server.Kestrel.Internal; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; +using Microsoft.AspNetCore.Testing; +using Moq; +using Xunit; + +namespace Microsoft.AspNetCore.Server.KestrelTests +{ + public class PipeOptionsTests + { + [Theory] + [InlineData(10, 10, 10)] + [InlineData(0, 1, 1)] + [InlineData(null, 0, 0)] + public void OutputPipeOptionsConfiguredCorrectly(long? maxResponseBufferSize, long expectedMaximumSizeLow, long expectedMaximumSizeHigh) + { + var serviceContext = new TestServiceContext(); + serviceContext.ServerOptions.Limits.MaxResponseBufferSize = maxResponseBufferSize; + serviceContext.ThreadPool = new LoggingThreadPool(null); + + var connectionHandler = new ConnectionHandler(serviceContext, application: null); + var mockScheduler = Mock.Of(); + var outputPipeOptions = connectionHandler.GetOutputPipeOptions(mockScheduler); + + Assert.Equal(expectedMaximumSizeLow, outputPipeOptions.MaximumSizeLow); + Assert.Equal(expectedMaximumSizeHigh, outputPipeOptions.MaximumSizeHigh); + Assert.Same(mockScheduler, outputPipeOptions.ReaderScheduler); + Assert.Same(serviceContext.ThreadPool, outputPipeOptions.WriterScheduler); + } + + [Theory] + [InlineData(10, 10, 10)] + [InlineData(null, 0, 0)] + public void LibuvInputPipeOptionsConfiguredCorrectly(long? maxRequestBufferSize, long expectedMaximumSizeLow, long expectedMaximumSizeHigh) + { + var serviceContext = new TestServiceContext(); + serviceContext.ServerOptions.Limits.MaxRequestBufferSize = maxRequestBufferSize; + serviceContext.ThreadPool = new LoggingThreadPool(null); + + var connectionHandler = new ConnectionHandler(serviceContext, application: null); + var mockScheduler = Mock.Of(); + var inputPipeOptions = connectionHandler.GetInputPipeOptions(mockScheduler); + + Assert.Equal(expectedMaximumSizeLow, inputPipeOptions.MaximumSizeLow); + Assert.Equal(expectedMaximumSizeHigh, inputPipeOptions.MaximumSizeHigh); + Assert.Same(serviceContext.ThreadPool, inputPipeOptions.ReaderScheduler); + Assert.Same(mockScheduler, inputPipeOptions.WriterScheduler); + } + + [Theory] + [InlineData(10, 10, 10)] + [InlineData(null, 0, 0)] + public void AdaptedPipeOptionsConfiguredCorrectly(long? maxRequestBufferSize, long expectedMaximumSizeLow, long expectedMaximumSizeHigh) + { + var serviceContext = new TestServiceContext(); + serviceContext.ServerOptions.Limits.MaxRequestBufferSize = maxRequestBufferSize; + + var connectionLifetime = new FrameConnection(new FrameConnectionContext + { + ServiceContext = serviceContext + }); + + Assert.Equal(expectedMaximumSizeLow, connectionLifetime.AdaptedPipeOptions.MaximumSizeLow); + Assert.Equal(expectedMaximumSizeHigh, connectionLifetime.AdaptedPipeOptions.MaximumSizeHigh); + Assert.Same(InlineScheduler.Default, connectionLifetime.AdaptedPipeOptions.ReaderScheduler); + Assert.Same(InlineScheduler.Default, connectionLifetime.AdaptedPipeOptions.WriterScheduler); + } + } +} diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/SocketOutputTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/SocketOutputTests.cs index e1257a8dd8..3232ef0287 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/SocketOutputTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/SocketOutputTests.cs @@ -15,8 +15,12 @@ using Xunit; namespace Microsoft.AspNetCore.Server.KestrelTests { - public class SocketOutputTests + public class SocketOutputTests : IDisposable { + private readonly PipeFactory _pipeFactory; + private readonly MockLibuv _mockLibuv; + private readonly KestrelThread _kestrelThread; + public static TheoryData MaxResponseBufferSizeData => new TheoryData { new KestrelServerOptions().Limits.MaxResponseBufferSize, 0, 1024, 1024 * 1024, null @@ -27,37 +31,41 @@ namespace Microsoft.AspNetCore.Server.KestrelTests (int)new KestrelServerOptions().Limits.MaxResponseBufferSize, 1024, (1024 * 1024) + 1 }; + public SocketOutputTests() + { + _pipeFactory = new PipeFactory(); + _mockLibuv = new MockLibuv(); + + var kestrelEngine = new KestrelEngine(_mockLibuv, new TestServiceContext().TransportContext, new ListenOptions(0)); + _kestrelThread = new KestrelThread(kestrelEngine, maxLoops: 1); + _kestrelThread.StartAsync().Wait(); + } + + public void Dispose() + { + _kestrelThread.StopAsync(TimeSpan.FromSeconds(1)).Wait(); + _pipeFactory.Dispose(); + } + [Theory] [MemberData(nameof(MaxResponseBufferSizeData))] public async Task CanWrite1MB(long? maxResponseBufferSize) { // This test was added because when initially implementing write-behind buffering in // SocketOutput, the write callback would never be invoked for writes larger than - // _maxBytesPreCompleted even after the write actually completed. + // maxResponseBufferSize even after the write actually completed. - // Arrange - var mockLibuv = new MockLibuv(); - using (var kestrelEngine = new KestrelEngine(mockLibuv, new TestServiceContext())) - using (var factory = new PipeFactory()) + // ConnectionHandler will set MaximumSizeHigh/Low to zero when MaxResponseBufferSize is null. + // This is verified in PipeOptionsTests.OutputPipeOptionsConfiguredCorrectly. + var pipeOptions = new PipeOptions { - var kestrelThread = new KestrelThread(kestrelEngine, maxLoops: 1); - kestrelEngine.Threads.Add(kestrelThread); - await kestrelThread.StartAsync(); - - var socket = new MockSocket(mockLibuv, kestrelThread.Loop.ThreadId, new TestKestrelTrace()); - var trace = new KestrelTrace(new TestKestrelTrace()); - - // ListenerContext will set MaximumSizeHigh/Low to zero when MaxResponseBufferSize is null. - // This is verified in ListenerContextTests.LibuvOutputPipeOptionsConfiguredCorrectly. - var pipeOptions = new PipeOptions - { - ReaderScheduler = kestrelThread, - MaximumSizeHigh = maxResponseBufferSize ?? 0, - MaximumSizeLow = maxResponseBufferSize ?? 0, - }; - var pipe = factory.Create(pipeOptions); - var socketOutput = new SocketOutput(pipe, kestrelThread, socket, new MockConnection(), "0", trace); + ReaderScheduler = _kestrelThread, + MaximumSizeHigh = maxResponseBufferSize ?? 0, + MaximumSizeLow = maxResponseBufferSize ?? 0, + }; + using (var socketOutput = CreateSocketOutput(pipeOptions)) + { // At least one run of this test should have a MaxResponseBufferSize < 1 MB. var bufferSize = 1024 * 1024; var buffer = new ArraySegment(new byte[bufferSize], 0, bufferSize); @@ -67,9 +75,6 @@ namespace Microsoft.AspNetCore.Server.KestrelTests // Assert await writeTask.TimeoutAfter(TimeSpan.FromSeconds(5)); - - // Cleanup - socketOutput.End(ProduceEndType.SocketDisconnect); } } @@ -79,36 +84,23 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var completeQueue = new ConcurrentQueue>(); // Arrange - var mockLibuv = new MockLibuv + _mockLibuv.OnWrite = (socket, buffers, triggerCompleted) => { - OnWrite = (socket, buffers, triggerCompleted) => - { - completeQueue.Enqueue(triggerCompleted); - return 0; - } + completeQueue.Enqueue(triggerCompleted); + return 0; }; - using (var kestrelEngine = new KestrelEngine(mockLibuv, new TestServiceContext())) - using (var factory = new PipeFactory()) + // ConnectionHandler will set MaximumSizeHigh/Low to zero when MaxResponseBufferSize is null. + // This is verified in PipeOptionsTests.OutputPipeOptionsConfiguredCorrectly. + var pipeOptions = new PipeOptions { - var kestrelThread = new KestrelThread(kestrelEngine, maxLoops: 1); - kestrelEngine.Threads.Add(kestrelThread); - await kestrelThread.StartAsync(); - - var socket = new MockSocket(mockLibuv, kestrelThread.Loop.ThreadId, new TestKestrelTrace()); - var trace = new KestrelTrace(new TestKestrelTrace()); - - // ListenerContext will set MaximumSizeHigh/Low to zero when MaxResponseBufferSize is null. - // This is verified in ListenerContextTests.LibuvOutputPipeOptionsConfiguredCorrectly. - var pipeOptions = new PipeOptions - { - ReaderScheduler = kestrelThread, - MaximumSizeHigh = 0, - MaximumSizeLow = 0, - }; - var pipe = factory.Create(pipeOptions); - var socketOutput = new SocketOutput(pipe, kestrelThread, socket, new MockConnection(), "0", trace); + ReaderScheduler = _kestrelThread, + MaximumSizeHigh = 0, + MaximumSizeLow = 0, + }; + using (var socketOutput = CreateSocketOutput(pipeOptions)) + { // Don't want to allocate anything too huge for perf. This is at least larger than the default buffer. var bufferSize = 1024 * 1024; var buffer = new ArraySegment(new byte[bufferSize], 0, bufferSize); @@ -120,14 +112,14 @@ namespace Microsoft.AspNetCore.Server.KestrelTests await writeTask.TimeoutAfter(TimeSpan.FromSeconds(5)); // Cleanup - socketOutput.End(ProduceEndType.SocketDisconnect); + socketOutput.Dispose(); // Wait for all writes to complete so the completeQueue isn't modified during enumeration. - await mockLibuv.OnPostTask; + await _mockLibuv.OnPostTask; foreach (var triggerCompleted in completeQueue) { - await kestrelThread.PostAsync(cb => cb(0), triggerCompleted); + await _kestrelThread.PostAsync(cb => cb(0), triggerCompleted); } } } @@ -138,36 +130,23 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var completeQueue = new ConcurrentQueue>(); // Arrange - var mockLibuv = new MockLibuv + _mockLibuv.OnWrite = (socket, buffers, triggerCompleted) => { - OnWrite = (socket, buffers, triggerCompleted) => - { - completeQueue.Enqueue(triggerCompleted); - return 0; - } + completeQueue.Enqueue(triggerCompleted); + return 0; }; - using (var kestrelEngine = new KestrelEngine(mockLibuv, new TestServiceContext())) - using (var factory = new PipeFactory()) + // ConnectionHandler will set MaximumSizeHigh/Low to 1 when MaxResponseBufferSize is zero. + // This is verified in PipeOptionsTests.OutputPipeOptionsConfiguredCorrectly. + var pipeOptions = new PipeOptions { - var kestrelThread = new KestrelThread(kestrelEngine, maxLoops: 1); - kestrelEngine.Threads.Add(kestrelThread); - await kestrelThread.StartAsync(); - - var socket = new MockSocket(mockLibuv, kestrelThread.Loop.ThreadId, new TestKestrelTrace()); - var trace = new KestrelTrace(new TestKestrelTrace()); - - // ListenerContext will set MaximumSizeHigh/Low to 1 when MaxResponseBufferSize is zero. - // This is verified in ListenerContextTests.LibuvOutputPipeOptionsConfiguredCorrectly. - var pipeOptions = new PipeOptions - { - ReaderScheduler = kestrelThread, - MaximumSizeHigh = 1, - MaximumSizeLow = 1, - }; - var pipe = factory.Create(pipeOptions); - var socketOutput = new SocketOutput(pipe, kestrelThread, socket, new MockConnection(), "0", trace); + ReaderScheduler = _kestrelThread, + MaximumSizeHigh = 1, + MaximumSizeLow = 1, + }; + using (var socketOutput = CreateSocketOutput(pipeOptions)) + { var bufferSize = 1; var buffer = new ArraySegment(new byte[bufferSize], 0, bufferSize); @@ -178,24 +157,24 @@ namespace Microsoft.AspNetCore.Server.KestrelTests Assert.False(writeTask.IsCompleted); // Act - await mockLibuv.OnPostTask; + await _mockLibuv.OnPostTask; // Finishing the write should allow the task to complete. Assert.True(completeQueue.TryDequeue(out var triggerNextCompleted)); - await kestrelThread.PostAsync(cb => cb(0), triggerNextCompleted); + await _kestrelThread.PostAsync(cb => cb(0), triggerNextCompleted); // Assert await writeTask.TimeoutAfter(TimeSpan.FromSeconds(5)); // Cleanup - socketOutput.End(ProduceEndType.SocketDisconnect); + socketOutput.Dispose(); // Wait for all writes to complete so the completeQueue isn't modified during enumeration. - await mockLibuv.OnPostTask; + await _mockLibuv.OnPostTask; foreach (var triggerCompleted in completeQueue) { - await kestrelThread.PostAsync(cb => cb(0), triggerCompleted); + await _kestrelThread.PostAsync(cb => cb(0), triggerCompleted); } } } @@ -207,33 +186,21 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var completeQueue = new ConcurrentQueue>(); // Arrange - var mockLibuv = new MockLibuv + _mockLibuv.OnWrite = (socket, buffers, triggerCompleted) => { - OnWrite = (socket, buffers, triggerCompleted) => - { - completeQueue.Enqueue(triggerCompleted); - return 0; - } + completeQueue.Enqueue(triggerCompleted); + return 0; }; - using (var kestrelEngine = new KestrelEngine(mockLibuv, new TestServiceContext())) - using (var factory = new PipeFactory()) + var pipeOptions = new PipeOptions { - var kestrelThread = new KestrelThread(kestrelEngine, maxLoops: 1); - kestrelEngine.Threads.Add(kestrelThread); - await kestrelThread.StartAsync(); - - var socket = new MockSocket(mockLibuv, kestrelThread.Loop.ThreadId, new TestKestrelTrace()); - var trace = new KestrelTrace(new TestKestrelTrace()); - var pipeOptions = new PipeOptions - { - ReaderScheduler = kestrelThread, - MaximumSizeHigh = maxResponseBufferSize, - MaximumSizeLow = maxResponseBufferSize, - }; - var pipe = factory.Create(pipeOptions); - var socketOutput = new SocketOutput(pipe, kestrelThread, socket, new MockConnection(), "0", trace); + ReaderScheduler = _kestrelThread, + MaximumSizeHigh = maxResponseBufferSize, + MaximumSizeLow = maxResponseBufferSize, + }; + using (var socketOutput = CreateSocketOutput(pipeOptions)) + { var bufferSize = maxResponseBufferSize - 1; var buffer = new ArraySegment(new byte[bufferSize], 0, bufferSize); @@ -246,7 +213,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests // Act var writeTask2 = socketOutput.WriteAsync(buffer, default(CancellationToken)); - await mockLibuv.OnPostTask; + await _mockLibuv.OnPostTask; // Assert // Too many bytes are already pre-completed for the second write to pre-complete. @@ -254,20 +221,20 @@ namespace Microsoft.AspNetCore.Server.KestrelTests // Act Assert.True(completeQueue.TryDequeue(out var triggerNextCompleted)); - await kestrelThread.PostAsync(cb => cb(0), triggerNextCompleted); + await _kestrelThread.PostAsync(cb => cb(0), triggerNextCompleted); // Finishing the first write should allow the second write to pre-complete. await writeTask2.TimeoutAfter(TimeSpan.FromSeconds(5)); // Cleanup - socketOutput.End(ProduceEndType.SocketDisconnect); + socketOutput.Dispose(); // Wait for all writes to complete so the completeQueue isn't modified during enumeration. - await mockLibuv.OnPostTask; + await _mockLibuv.OnPostTask; foreach (var triggerCompleted in completeQueue) { - await kestrelThread.PostAsync(cb => cb(0), triggerCompleted); + await _kestrelThread.PostAsync(cb => cb(0), triggerCompleted); } } } @@ -279,33 +246,21 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var completeQueue = new ConcurrentQueue>(); // Arrange - var mockLibuv = new MockLibuv + _mockLibuv.OnWrite = (socket, buffers, triggerCompleted) => { - OnWrite = (socket, buffers, triggerCompleted) => - { - completeQueue.Enqueue(triggerCompleted); - return 0; - } + completeQueue.Enqueue(triggerCompleted); + return 0; }; - using (var kestrelEngine = new KestrelEngine(mockLibuv, new TestServiceContext())) - using (var factory = new PipeFactory()) + var pipeOptions = new PipeOptions { - var kestrelThread = new KestrelThread(kestrelEngine, maxLoops: 1); - kestrelEngine.Threads.Add(kestrelThread); - await kestrelThread.StartAsync(); - - var socket = new MockSocket(mockLibuv, kestrelThread.Loop.ThreadId, new TestKestrelTrace()); - var trace = new KestrelTrace(new TestKestrelTrace()); - var pipeOptions = new PipeOptions - { - ReaderScheduler = kestrelThread, - MaximumSizeHigh = maxResponseBufferSize, - MaximumSizeLow = maxResponseBufferSize, - }; - var pipe = factory.Create(pipeOptions); - var socketOutput = new SocketOutput(pipe, kestrelThread, socket, new MockConnection(), "0", trace); + ReaderScheduler = _kestrelThread, + MaximumSizeHigh = maxResponseBufferSize, + MaximumSizeLow = maxResponseBufferSize, + }; + using (var socketOutput = CreateSocketOutput(pipeOptions)) + { var bufferSize = maxResponseBufferSize / 2; var data = new byte[bufferSize]; var halfWriteBehindBuffer = new ArraySegment(data, 0, bufferSize); @@ -316,11 +271,11 @@ namespace Microsoft.AspNetCore.Server.KestrelTests // Assert // The first write should pre-complete since it is <= _maxBytesPreCompleted. Assert.Equal(TaskStatus.RanToCompletion, writeTask1.Status); - await mockLibuv.OnPostTask; + await _mockLibuv.OnPostTask; Assert.NotEmpty(completeQueue); // Add more bytes to the write-behind buffer to prevent the next write from - socketOutput.Write((writableBuffer, state) => + ((ISocketOutput)socketOutput).Write((writableBuffer, state) => { writableBuffer.Write(state); }, @@ -336,7 +291,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests // Drain the write queue while (completeQueue.TryDequeue(out var triggerNextCompleted)) { - await kestrelThread.PostAsync(cb => cb(0), triggerNextCompleted); + await _kestrelThread.PostAsync(cb => cb(0), triggerNextCompleted); } var timeout = TimeSpan.FromSeconds(5); @@ -345,9 +300,6 @@ namespace Microsoft.AspNetCore.Server.KestrelTests await writeTask3.TimeoutAfter(timeout); Assert.Empty(completeQueue); - - // Cleanup - socketOutput.End(ProduceEndType.SocketDisconnect); } } @@ -358,37 +310,25 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var completeQueue = new ConcurrentQueue>(); // Arrange - var mockLibuv = new MockLibuv + _mockLibuv.OnWrite = (socket, buffers, triggerCompleted) => { - OnWrite = (socket, buffers, triggerCompleted) => - { - completeQueue.Enqueue(triggerCompleted); - return 0; - } + completeQueue.Enqueue(triggerCompleted); + return 0; }; - using (var kestrelEngine = new KestrelEngine(mockLibuv, new TestServiceContext())) - using (var factory = new PipeFactory()) + using (var mockConnection = new MockConnection()) { - var kestrelThread = new KestrelThread(kestrelEngine, maxLoops: 1); - kestrelEngine.Threads.Add(kestrelThread); - await kestrelThread.StartAsync(); + var abortedSource = mockConnection.RequestAbortedSource; - var socket = new MockSocket(mockLibuv, kestrelThread.Loop.ThreadId, new TestKestrelTrace()); - var trace = new KestrelTrace(new TestKestrelTrace()); - - using (var mockConnection = new MockConnection()) + var pipeOptions = new PipeOptions { - var pipeOptions = new PipeOptions - { - ReaderScheduler = kestrelThread, - MaximumSizeHigh = maxResponseBufferSize, - MaximumSizeLow = maxResponseBufferSize, - }; - var pipe = factory.Create(pipeOptions); - var abortedSource = mockConnection.RequestAbortedSource; - var socketOutput = new SocketOutput(pipe, kestrelThread, socket, mockConnection, "0", trace); + ReaderScheduler = _kestrelThread, + MaximumSizeHigh = maxResponseBufferSize, + MaximumSizeLow = maxResponseBufferSize, + }; + using (var socketOutput = CreateSocketOutput(pipeOptions, mockConnection)) + { var bufferSize = maxResponseBufferSize - 1; var data = new byte[bufferSize]; @@ -408,7 +348,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var task3Canceled = socketOutput.WriteAsync(fullBuffer, cancellationToken: abortedSource.Token); // Give time for tasks to percolate - await mockLibuv.OnPostTask; + await _mockLibuv.OnPostTask; // Second task is not completed Assert.False(task2Success.IsCompleted); @@ -420,11 +360,10 @@ namespace Microsoft.AspNetCore.Server.KestrelTests Assert.False(task3Canceled.IsCanceled); Assert.False(task3Canceled.IsFaulted); - // Cause all writes to fail while (completeQueue.TryDequeue(out var triggerNextCompleted)) { - await kestrelThread.PostAsync(cb => cb(-1), triggerNextCompleted); + await _kestrelThread.PostAsync(cb => cb(-1), triggerNextCompleted); } // Second task is now completed @@ -436,9 +375,6 @@ namespace Microsoft.AspNetCore.Server.KestrelTests // Assert.True(task3Canceled.IsCanceled); Assert.True(abortedSource.IsCancellationRequested); - - // Cleanup - socketOutput.End(ProduceEndType.SocketDisconnect); } } } @@ -450,33 +386,21 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var completeQueue = new ConcurrentQueue>(); // Arrange - var mockLibuv = new MockLibuv + _mockLibuv.OnWrite = (socket, buffers, triggerCompleted) => { - OnWrite = (socket, buffers, triggerCompleted) => - { - completeQueue.Enqueue(triggerCompleted); - return 0; - } + completeQueue.Enqueue(triggerCompleted); + return 0; }; - using (var kestrelEngine = new KestrelEngine(mockLibuv, new TestServiceContext())) - using (var factory = new PipeFactory()) + var pipeOptions = new PipeOptions { - var kestrelThread = new KestrelThread(kestrelEngine, maxLoops: 1); - kestrelEngine.Threads.Add(kestrelThread); - await kestrelThread.StartAsync(); - - var socket = new MockSocket(mockLibuv, kestrelThread.Loop.ThreadId, new TestKestrelTrace()); - var trace = new KestrelTrace(new TestKestrelTrace()); - var pipeOptions = new PipeOptions - { - ReaderScheduler = kestrelThread, - MaximumSizeHigh = maxResponseBufferSize, - MaximumSizeLow = maxResponseBufferSize, - }; - var pipe = factory.Create(pipeOptions); - var socketOutput = new SocketOutput(pipe, kestrelThread, socket, new MockConnection(), "0", trace); + ReaderScheduler = _kestrelThread, + MaximumSizeHigh = maxResponseBufferSize, + MaximumSizeLow = maxResponseBufferSize, + }; + using (var socketOutput = CreateSocketOutput(pipeOptions)) + { var bufferSize = maxResponseBufferSize - 1; var buffer = new ArraySegment(new byte[bufferSize], 0, bufferSize); @@ -485,7 +409,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests // Assert // The first write should pre-complete since it is < _maxBytesPreCompleted. - await mockLibuv.OnPostTask; + await _mockLibuv.OnPostTask; Assert.Equal(TaskStatus.RanToCompletion, writeTask1.Status); Assert.NotEmpty(completeQueue); @@ -496,7 +420,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests // Drain the write queue while (completeQueue.TryDequeue(out var triggerNextCompleted)) { - await kestrelThread.PostAsync(cb => cb(0), triggerNextCompleted); + await _kestrelThread.PostAsync(cb => cb(0), triggerNextCompleted); } var timeout = TimeSpan.FromSeconds(5); @@ -506,9 +430,6 @@ namespace Microsoft.AspNetCore.Server.KestrelTests // https://github.com/aspnet/KestrelHttpServer/issues/356 await writeTask2.TimeoutAfter(timeout); await writeTask3.TimeoutAfter(timeout); - - // Cleanup - socketOutput.End(ProduceEndType.SocketDisconnect); } } @@ -519,39 +440,26 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var writeCalled = false; var writeCount = 0; - var mockLibuv = new MockLibuv + _mockLibuv.OnWrite = (socket, buffers, triggerCompleted) => { - OnWrite = (socket, buffers, triggerCompleted) => - { - writeCount++; - triggerCompleted(0); - writeCalled = true; - return 0; - } + writeCount++; + triggerCompleted(0); + writeCalled = true; + return 0; }; - using (var kestrelEngine = new KestrelEngine(mockLibuv, new TestServiceContext())) - using (var factory = new PipeFactory()) + // ConnectionHandler will set MaximumSizeHigh/Low to zero when MaxResponseBufferSize is null. + // This is verified in PipeOptionsTests.OutputPipeOptionsConfiguredCorrectly. + var pipeOptions = new PipeOptions { - var kestrelThread = new KestrelThread(kestrelEngine, maxLoops: 1); - kestrelEngine.Threads.Add(kestrelThread); - await kestrelThread.StartAsync(); + ReaderScheduler = _kestrelThread, + MaximumSizeHigh = maxResponseBufferSize ?? 0, + MaximumSizeLow = maxResponseBufferSize ?? 0, + }; - var socket = new MockSocket(mockLibuv, kestrelThread.Loop.ThreadId, new TestKestrelTrace()); - var trace = new KestrelTrace(new TestKestrelTrace()); - - // ListenerContext will set MaximumSizeHigh/Low to zero when MaxResponseBufferSize is null. - // This is verified in ListenerContextTests.LibuvOutputPipeOptionsConfiguredCorrectly. - var pipeOptions = new PipeOptions - { - ReaderScheduler = kestrelThread, - MaximumSizeHigh = maxResponseBufferSize ?? 0, - MaximumSizeLow = maxResponseBufferSize ?? 0, - }; - var pipe = factory.Create(pipeOptions); - var socketOutput = new SocketOutput(pipe, kestrelThread, socket, new MockConnection(), "0", trace); - - mockLibuv.KestrelThreadBlocker.Reset(); + using (var socketOutput = CreateSocketOutput(pipeOptions)) + { + _mockLibuv.KestrelThreadBlocker.Reset(); var buffer = new ArraySegment(new byte[1]); @@ -560,66 +468,67 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var ignore = socketOutput.WriteAsync(buffer, CancellationToken.None); ignore = socketOutput.WriteAsync(buffer, CancellationToken.None); - mockLibuv.KestrelThreadBlocker.Set(); + _mockLibuv.KestrelThreadBlocker.Set(); - await mockLibuv.OnPostTask; + await _mockLibuv.OnPostTask; Assert.True(writeCalled); writeCalled = false; // Write isn't called twice after the thread is unblocked - await mockLibuv.OnPostTask; + await _mockLibuv.OnPostTask; Assert.False(writeCalled); // One call to ScheduleWrite - Assert.Equal(1, mockLibuv.PostCount); + Assert.Equal(1, _mockLibuv.PostCount); // One call to uv_write Assert.Equal(1, writeCount); - - // Cleanup - socketOutput.End(ProduceEndType.SocketDisconnect); } } [Fact] public async Task AllocCommitCanBeCalledAfterConnectionClose() { - var mockLibuv = new MockLibuv(); - - using (var kestrelEngine = new KestrelEngine(mockLibuv, new TestServiceContext())) - using (var factory = new PipeFactory()) + var pipeOptions = new PipeOptions { - var kestrelThread = new KestrelThread(kestrelEngine, maxLoops: 1); - kestrelEngine.Threads.Add(kestrelThread); - await kestrelThread.StartAsync(); - - var socket = new MockSocket(mockLibuv, kestrelThread.Loop.ThreadId, new TestKestrelTrace()); - var trace = new KestrelTrace(new TestKestrelTrace()); - var connection = new MockConnection(); - var pipeOptions = new PipeOptions - { - ReaderScheduler = kestrelThread, - }; - var pipe = factory.Create(pipeOptions); - var socketOutput = new SocketOutput(pipe, kestrelThread, socket, connection, "0", trace); + ReaderScheduler = _kestrelThread, + }; + using (var connection = new MockConnection()) + { + var socketOutput = CreateSocketOutput(pipeOptions, connection); // Close SocketOutput - socketOutput.End(ProduceEndType.SocketDisconnect); + socketOutput.Dispose(); - await mockLibuv.OnPostTask; + await _mockLibuv.OnPostTask; Assert.Equal(TaskStatus.RanToCompletion, connection.SocketClosed.Status); var called = false; - socketOutput.Write((buffer, state) => + ((ISocketOutput)socketOutput).Write((buffer, state) => { called = true; - }, + }, null); Assert.False(called); } } + + private SocketOutputProducer CreateSocketOutput(PipeOptions pipeOptions, MockConnection connection = null) + { + var pipe = _pipeFactory.Create(pipeOptions); + var serviceContext = new TestServiceContext(); + var trace = serviceContext.Log; + + var frame = new Frame(null, new FrameContext { ServiceContext = serviceContext }); + + var socket = new MockSocket(_mockLibuv, _kestrelThread.Loop.ThreadId, new TestKestrelTrace()); + var socketOutput = new SocketOutputProducer(pipe.Writer, frame, "0", trace); + var consumer = new SocketOutputConsumer(pipe.Reader, _kestrelThread, socket, connection ?? new MockConnection(), "0", trace); + + return socketOutput; + } } } \ No newline at end of file diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/StreamSocketOutputTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/StreamSocketOutputTests.cs index 910a888569..1dab5016f8 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/StreamSocketOutputTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/StreamSocketOutputTests.cs @@ -5,8 +5,6 @@ using System; using System.IO; using System.IO.Pipelines; using Microsoft.AspNetCore.Server.Kestrel.Adapter.Internal; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; -using Microsoft.AspNetCore.Testing; using Xunit; namespace Microsoft.AspNetCore.Server.KestrelTests diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockConnectionHandler.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockConnectionHandler.cs new file mode 100644 index 0000000000..6df2d283de --- /dev/null +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockConnectionHandler.cs @@ -0,0 +1,66 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.IO.Pipelines; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Server.Kestrel.Transport; +using Xunit; + +namespace Microsoft.AspNetCore.Server.KestrelTests.TestHelpers +{ + public class MockConnectionHandler : IConnectionHandler, IDisposable + { + private readonly PipeFactory _pipeFactory; + + public MockConnectionHandler() + { + _pipeFactory = new PipeFactory(); + } + + public IConnectionContext OnConnection(IConnectionInformation connectionInfo) + { + Assert.Null(Input); + + Input = _pipeFactory.Create(); + Output = _pipeFactory.Create(); + + return new TestConnectionContext + { + Input = Input.Writer, + Output = Output.Reader, + }; + } + + public IPipe Input { get; private set; } + public IPipe Output { get; private set; } + + public void Dispose() + { + Input?.Writer.Complete(); + _pipeFactory.Dispose(); + } + + private class TestConnectionContext : IConnectionContext + { + public string ConnectionId { get; } + public IPipeWriter Input { get; set; } + public IPipeReader Output { get; set; } + + public Task StopAsync() + { + throw new NotImplementedException(); + } + + public void Abort(Exception ex) + { + throw new NotImplementedException(); + } + + public void Timeout() + { + throw new NotImplementedException(); + } + } + } +} diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockLibuv.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockLibuv.cs index 55ad9161d4..8f809cf4fe 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockLibuv.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockLibuv.cs @@ -8,7 +8,7 @@ using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; namespace Microsoft.AspNetCore.Server.KestrelTests.TestHelpers { - public class MockLibuv : Libuv + public class MockLibuv : LibuvFunctions { private UvAsyncHandle _postHandle; private uv_async_cb _onPost; diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockSocket.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockSocket.cs index 7b398464d1..fbe24d07bb 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockSocket.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockSocket.cs @@ -6,7 +6,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests.TestHelpers { class MockSocket : UvStreamHandle { - public MockSocket(Libuv uv, int threadId, IKestrelTrace logger) : base(logger) + public MockSocket(LibuvFunctions uv, int threadId, IKestrelTrace logger) : base(logger) { CreateMemory(uv, threadId, IntPtr.Size); } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/TestConstants.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/TestConstants.cs new file mode 100644 index 0000000000..25f213c2a7 --- /dev/null +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/TestConstants.cs @@ -0,0 +1,10 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +namespace Microsoft.AspNetCore.Server.KestrelTests.TestHelpers +{ + public class TestConstants + { + public const int EOF = -4095; + } +} diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestInput.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/TestInput.cs index be520d99f1..cfa87eb55e 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/TestInput.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/TestInput.cs @@ -4,58 +4,43 @@ using System; using System.IO.Pipelines; using System.Text; -using System.Net; using System.Threading; using System.Threading.Tasks; -using Microsoft.AspNetCore.Server.Kestrel; -using Microsoft.AspNetCore.Server.Kestrel.Internal; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; using Microsoft.AspNetCore.Testing; using Microsoft.Extensions.Internal; namespace Microsoft.AspNetCore.Server.KestrelTests { - class TestInput : IConnectionControl, IFrameControl, IDisposable + class TestInput : ITimeoutControl, IFrameControl, IDisposable { private MemoryPool _memoryPool; private PipeFactory _pipelineFactory; public TestInput() { - var trace = new KestrelTrace(new TestKestrelTrace()); - var serviceContext = new ServiceContext - { - DateHeaderValueManager = new DateHeaderValueManager(), - ServerOptions = new KestrelServerOptions(), - HttpParserFactory = frame => new KestrelHttpParser(trace), - }; - var listenerContext = new ListenerContext(serviceContext) - { - ListenOptions = new ListenOptions(new IPEndPoint(IPAddress.Loopback, 5000)) - }; - var connectionContext = new ConnectionContext(listenerContext) - { - ConnectionControl = this - }; - var context = new Frame(null, connectionContext); - FrameContext = context; + var innerContext = new FrameContext { ServiceContext = new TestServiceContext() }; + + FrameContext = new Frame(null, innerContext); FrameContext.FrameControl = this; - FrameContext.ConnectionContext.ListenerContext.ServiceContext.Log = trace; _memoryPool = new MemoryPool(); _pipelineFactory = new PipeFactory(); - FrameContext.Input = _pipelineFactory.Create(); ; + Pipe = _pipelineFactory.Create(); + FrameContext.Input = Pipe.Reader; } + public IPipe Pipe { get; } + public Frame FrameContext { get; set; } public void Add(string text, bool fin = false) { var data = Encoding.ASCII.GetBytes(text); - FrameContext.Input.Writer.WriteAsync(data).Wait(); + Pipe.Writer.WriteAsync(data).Wait(); if (fin) { - FrameContext.Input.Writer.Complete(); + Pipe.Writer.Complete(); } } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/UvTimerHandleTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/UvTimerHandleTests.cs index b81d14d89a..cb5e416263 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/UvTimerHandleTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/UvTimerHandleTests.cs @@ -15,7 +15,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var trace = new TestKestrelTrace(); var loop = new UvLoopHandle(trace); - loop.Init(new Libuv()); + loop.Init(new LibuvFunctions()); var timer = new UvTimerHandle(trace); timer.Init(loop, (a, b) => { }); @@ -41,7 +41,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var trace = new TestKestrelTrace(); var loop = new UvLoopHandle(trace); - loop.Init(new Libuv()); + loop.Init(new LibuvFunctions()); var timer = new UvTimerHandle(trace); timer.Init(loop, (callback, handle) => { }); diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/WebHostBuilderKestrelExtensionsTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/WebHostBuilderKestrelExtensionsTests.cs index 12e1d9e350..4eeebba773 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/WebHostBuilderKestrelExtensionsTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/WebHostBuilderKestrelExtensionsTests.cs @@ -1,7 +1,6 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Server.Kestrel; using Microsoft.Extensions.DependencyInjection; diff --git a/test/shared/HttpParsingData.cs b/test/shared/HttpParsingData.cs index 1af1a2da1e..944a1f936d 100644 --- a/test/shared/HttpParsingData.cs +++ b/test/shared/HttpParsingData.cs @@ -1,10 +1,10 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; using System; using System.Collections.Generic; using System.Linq; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; using Xunit; namespace Microsoft.AspNetCore.Testing diff --git a/test/shared/MockConnection.cs b/test/shared/MockConnection.cs index 56a9e84d56..9c6528673c 100644 --- a/test/shared/MockConnection.cs +++ b/test/shared/MockConnection.cs @@ -2,12 +2,10 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.Net; using System.Threading; using System.Threading.Tasks; -using Microsoft.AspNetCore.Server.Kestrel; -using Microsoft.AspNetCore.Server.Kestrel.Internal; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal; using Microsoft.Extensions.Internal; namespace Microsoft.AspNetCore.Testing @@ -18,12 +16,9 @@ namespace Microsoft.AspNetCore.Testing public MockConnection() { - ConnectionControl = this; + TimeoutControl = this; RequestAbortedSource = new CancellationTokenSource(); - ListenerContext = new ListenerContext(new ServiceContext()) - { - ListenOptions = new ListenOptions(new IPEndPoint(IPAddress.Loopback, 5000)) - }; + ListenerContext = new ListenerContext(new LibuvTransportContext()); } public override Task AbortAsync(Exception error = null) diff --git a/test/shared/MockSocketOutput.cs b/test/shared/MockSocketOutput.cs index a506b388fd..c5cdc32cb2 100644 --- a/test/shared/MockSocketOutput.cs +++ b/test/shared/MockSocketOutput.cs @@ -2,9 +2,9 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.IO.Pipelines; using System.Threading; using System.Threading.Tasks; -using System.IO.Pipelines; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; using Microsoft.Extensions.Internal; diff --git a/test/shared/PassThroughConnectionAdapter.cs b/test/shared/PassThroughConnectionAdapter.cs index faa688a194..35d04ab469 100644 --- a/test/shared/PassThroughConnectionAdapter.cs +++ b/test/shared/PassThroughConnectionAdapter.cs @@ -6,7 +6,6 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Server.Kestrel.Adapter; using Microsoft.AspNetCore.Server.Kestrel.Adapter.Internal; -using Microsoft.AspNetCore.Testing; namespace Microsoft.AspNetCore.Testing { diff --git a/test/shared/TestFrame.cs b/test/shared/TestFrame.cs index 5eda865139..cc2d262bd4 100644 --- a/test/shared/TestFrame.cs +++ b/test/shared/TestFrame.cs @@ -9,7 +9,7 @@ namespace Microsoft.AspNetCore.Testing { public class TestFrame : Frame { - public TestFrame(IHttpApplication application, ConnectionContext context) + public TestFrame(IHttpApplication application, FrameContext context) : base(application, context) { } diff --git a/test/shared/TestServer.cs b/test/shared/TestServer.cs index ec0a8fbd12..bf72cd0486 100644 --- a/test/shared/TestServer.cs +++ b/test/shared/TestServer.cs @@ -7,7 +7,6 @@ using System.Net.Sockets; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Server.Kestrel; using Microsoft.AspNetCore.Server.Kestrel.Internal; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; namespace Microsoft.AspNetCore.Testing { @@ -17,9 +16,7 @@ namespace Microsoft.AspNetCore.Testing public class TestServer : IDisposable { private KestrelEngine _engine; - private IDisposable _server; private ListenOptions _listenOptions; - private Frame _frame; public TestServer(RequestDelegate app) : this(app, new TestServiceContext()) @@ -43,25 +40,21 @@ namespace Microsoft.AspNetCore.Testing public TestServer(RequestDelegate app, TestServiceContext context, ListenOptions listenOptions, IHttpContextFactory httpContextFactory) { - Context = context; _listenOptions = listenOptions; - context.FrameFactory = connectionContext => - { - _frame = new Frame(new DummyApplication(app, httpContextFactory), connectionContext); - return _frame; - }; + Context = context; + Context.App = app; + Context.TransportContext.ConnectionHandler = new ConnectionHandler(Context, new DummyApplication(app, httpContextFactory)); try { - _engine = new KestrelEngine(context); - _engine.Start(1); - _server = _engine.CreateServer(_listenOptions); + _engine = new KestrelEngine(context.TransportContext, _listenOptions); + _engine.BindAsync().Wait(); } catch { - _server?.Dispose(); - _engine?.Dispose(); + _engine.UnbindAsync().Wait(); + _engine.StopAsync().Wait(); throw; } } @@ -69,8 +62,6 @@ namespace Microsoft.AspNetCore.Testing public int Port => _listenOptions.IPEndPoint.Port; public AddressFamily AddressFamily => _listenOptions.IPEndPoint.AddressFamily; - public Frame Frame => _frame; - public TestServiceContext Context { get; } public TestConnection CreateConnection() @@ -80,8 +71,8 @@ namespace Microsoft.AspNetCore.Testing public void Dispose() { - _server.Dispose(); - _engine.Dispose(); + _engine.UnbindAsync().Wait(); + _engine.StopAsync().Wait(); } } } diff --git a/test/shared/TestServiceContext.cs b/test/shared/TestServiceContext.cs index ad78537efb..522acbd745 100644 --- a/test/shared/TestServiceContext.cs +++ b/test/shared/TestServiceContext.cs @@ -7,6 +7,8 @@ using Microsoft.AspNetCore.Server.Kestrel; using Microsoft.AspNetCore.Server.Kestrel.Internal; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal; namespace Microsoft.AspNetCore.Testing { @@ -16,21 +18,32 @@ namespace Microsoft.AspNetCore.Testing public TestServiceContext() { - AppLifetime = new LifetimeNotImplemented(); Log = new TestKestrelTrace(); ThreadPool = new LoggingThreadPool(Log); DateHeaderValueManager = new DateHeaderValueManager(systemClock: new MockSystemClock()); DateHeaderValue = DateHeaderValueManager.GetDateHeaderValues().String; - HttpParserFactory = frame => new KestrelHttpParser(Log); + HttpParserFactory = frame => new KestrelHttpParser(frame.ServiceContext.Log); ServerOptions = new KestrelServerOptions { - AddServerHeader = false, - ShutdownTimeout = TimeSpan.FromSeconds(5) + AddServerHeader = false + }; + + TransportContext = new LibuvTransportContext + { + AppLifetime = new LifetimeNotImplemented(), + Log = Log, + Options = new LibuvTransportOptions + { + ThreadCount = 1, + ShutdownTimeout = TimeSpan.FromSeconds(5) + } }; } public string DateHeaderValue { get; } + public LibuvTransportContext TransportContext { get; } + public RequestDelegate App { get @@ -39,11 +52,8 @@ namespace Microsoft.AspNetCore.Testing } set { + TransportContext.ConnectionHandler = new ConnectionHandler(this, new DummyApplication(value)); _app = value; - FrameFactory = connectionContext => - { - return new Frame(new DummyApplication(_app), connectionContext); - }; } } } diff --git a/tools/CodeGenerator/CodeGenerator.csproj b/tools/CodeGenerator/CodeGenerator.csproj index ac31790238..5f3f1c7203 100644 --- a/tools/CodeGenerator/CodeGenerator.csproj +++ b/tools/CodeGenerator/CodeGenerator.csproj @@ -1,4 +1,4 @@ - + @@ -14,7 +14,7 @@ - $(MSBuildThisFileDirectory)..\..\src\Microsoft.AspNetCore.Server.Kestrel\Internal\Http + $(MSBuildThisFileDirectory)..\..\src\Microsoft.AspNetCore.Server.Kestrel.Core\Internal\Http FrameHeaders.Generated.cs Frame.Generated.cs From 686829d226d87604c412083e4f3ccf51ad8d66d9 Mon Sep 17 00:00:00 2001 From: Nate McMaster Date: Wed, 29 Mar 2017 16:10:31 -0700 Subject: [PATCH 1159/1662] Add tests for WritableBuffer extensions and rename WriteAscii => WriteAsciiNoValidation --- .../Internal/Http/FrameHeaders.Generated.cs | 70 ++++---- .../Internal/Http/FrameResponseHeaders.cs | 4 +- .../Internal/Http/PipelineExtensions.cs | 10 +- ...Core.Server.Kestrel.FunctionalTests.csproj | 1 + .../xunit.runner.json | 5 + .../PipelineExtensionTests.cs | 167 ++++++++++++++++++ .../TestHelpers/AssertExtensions.cs | 27 +++ .../xunit.runner.json | 4 +- tools/CodeGenerator/KnownHeaders.cs | 2 +- 9 files changed, 250 insertions(+), 40 deletions(-) create mode 100644 test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/xunit.runner.json create mode 100644 test/Microsoft.AspNetCore.Server.KestrelTests/PipelineExtensionTests.cs create mode 100644 test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/AssertExtensions.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameHeaders.Generated.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameHeaders.Generated.cs index c4c43f0eb2..a8369ac971 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameHeaders.Generated.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameHeaders.Generated.cs @@ -7772,7 +7772,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if (value != null) { output.WriteFast(_headerBytes, 17, 14); - output.WriteAscii(value); + output.WriteAsciiNoValidation(value); } } } @@ -7798,7 +7798,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if (value != null) { output.WriteFast(_headerBytes, 31, 8); - output.WriteAscii(value); + output.WriteAsciiNoValidation(value); } } } @@ -7819,7 +7819,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if (value != null) { output.WriteFast(_headerBytes, 133, 16); - output.WriteAscii(value); + output.WriteAsciiNoValidation(value); } } } @@ -7845,7 +7845,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if (value != null) { output.WriteFast(_headerBytes, 350, 10); - output.WriteAscii(value); + output.WriteAsciiNoValidation(value); } } } @@ -7877,7 +7877,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if (value != null) { output.WriteFast(_headerBytes, 0, 17); - output.WriteAscii(value); + output.WriteAsciiNoValidation(value); } } } @@ -7898,7 +7898,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if (value != null) { output.WriteFast(_headerBytes, 39, 14); - output.WriteAscii(value); + output.WriteAsciiNoValidation(value); } } } @@ -7919,7 +7919,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if (value != null) { output.WriteFast(_headerBytes, 53, 10); - output.WriteAscii(value); + output.WriteAsciiNoValidation(value); } } } @@ -7940,7 +7940,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if (value != null) { output.WriteFast(_headerBytes, 63, 11); - output.WriteAscii(value); + output.WriteAsciiNoValidation(value); } } } @@ -7966,7 +7966,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if (value != null) { output.WriteFast(_headerBytes, 74, 21); - output.WriteAscii(value); + output.WriteAsciiNoValidation(value); } } } @@ -7987,7 +7987,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if (value != null) { output.WriteFast(_headerBytes, 95, 11); - output.WriteAscii(value); + output.WriteAsciiNoValidation(value); } } } @@ -8008,7 +8008,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if (value != null) { output.WriteFast(_headerBytes, 106, 7); - output.WriteAscii(value); + output.WriteAsciiNoValidation(value); } } } @@ -8029,7 +8029,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if (value != null) { output.WriteFast(_headerBytes, 113, 11); - output.WriteAscii(value); + output.WriteAsciiNoValidation(value); } } } @@ -8050,7 +8050,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if (value != null) { output.WriteFast(_headerBytes, 124, 9); - output.WriteAscii(value); + output.WriteAsciiNoValidation(value); } } } @@ -8071,7 +8071,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if (value != null) { output.WriteFast(_headerBytes, 149, 20); - output.WriteAscii(value); + output.WriteAsciiNoValidation(value); } } } @@ -8092,7 +8092,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if (value != null) { output.WriteFast(_headerBytes, 169, 20); - output.WriteAscii(value); + output.WriteAsciiNoValidation(value); } } } @@ -8113,7 +8113,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if (value != null) { output.WriteFast(_headerBytes, 189, 20); - output.WriteAscii(value); + output.WriteAsciiNoValidation(value); } } } @@ -8134,7 +8134,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if (value != null) { output.WriteFast(_headerBytes, 209, 15); - output.WriteAscii(value); + output.WriteAsciiNoValidation(value); } } } @@ -8155,7 +8155,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if (value != null) { output.WriteFast(_headerBytes, 224, 17); - output.WriteAscii(value); + output.WriteAsciiNoValidation(value); } } } @@ -8176,7 +8176,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if (value != null) { output.WriteFast(_headerBytes, 241, 11); - output.WriteAscii(value); + output.WriteAsciiNoValidation(value); } } } @@ -8197,7 +8197,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if (value != null) { output.WriteFast(_headerBytes, 252, 17); - output.WriteAscii(value); + output.WriteAsciiNoValidation(value); } } } @@ -8218,7 +8218,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if (value != null) { output.WriteFast(_headerBytes, 269, 17); - output.WriteAscii(value); + output.WriteAsciiNoValidation(value); } } } @@ -8239,7 +8239,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if (value != null) { output.WriteFast(_headerBytes, 286, 7); - output.WriteAscii(value); + output.WriteAsciiNoValidation(value); } } } @@ -8260,7 +8260,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if (value != null) { output.WriteFast(_headerBytes, 293, 8); - output.WriteAscii(value); + output.WriteAsciiNoValidation(value); } } } @@ -8281,7 +8281,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if (value != null) { output.WriteFast(_headerBytes, 301, 12); - output.WriteAscii(value); + output.WriteAsciiNoValidation(value); } } } @@ -8302,7 +8302,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if (value != null) { output.WriteFast(_headerBytes, 313, 22); - output.WriteAscii(value); + output.WriteAsciiNoValidation(value); } } } @@ -8323,7 +8323,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if (value != null) { output.WriteFast(_headerBytes, 335, 15); - output.WriteAscii(value); + output.WriteAsciiNoValidation(value); } } } @@ -8344,7 +8344,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if (value != null) { output.WriteFast(_headerBytes, 360, 14); - output.WriteAscii(value); + output.WriteAsciiNoValidation(value); } } } @@ -8365,7 +8365,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if (value != null) { output.WriteFast(_headerBytes, 374, 8); - output.WriteAscii(value); + output.WriteAsciiNoValidation(value); } } } @@ -8386,7 +8386,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if (value != null) { output.WriteFast(_headerBytes, 382, 20); - output.WriteAscii(value); + output.WriteAsciiNoValidation(value); } } } @@ -8407,7 +8407,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if (value != null) { output.WriteFast(_headerBytes, 402, 36); - output.WriteAscii(value); + output.WriteAsciiNoValidation(value); } } } @@ -8428,7 +8428,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if (value != null) { output.WriteFast(_headerBytes, 438, 32); - output.WriteAscii(value); + output.WriteAsciiNoValidation(value); } } } @@ -8449,7 +8449,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if (value != null) { output.WriteFast(_headerBytes, 470, 32); - output.WriteAscii(value); + output.WriteAsciiNoValidation(value); } } } @@ -8470,7 +8470,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if (value != null) { output.WriteFast(_headerBytes, 502, 31); - output.WriteAscii(value); + output.WriteAsciiNoValidation(value); } } } @@ -8491,7 +8491,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if (value != null) { output.WriteFast(_headerBytes, 533, 33); - output.WriteAscii(value); + output.WriteAsciiNoValidation(value); } } } @@ -8512,7 +8512,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if (value != null) { output.WriteFast(_headerBytes, 566, 26); - output.WriteAscii(value); + output.WriteAsciiNoValidation(value); } } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameResponseHeaders.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameResponseHeaders.cs index 4b6d983327..9fc752f6cd 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameResponseHeaders.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameResponseHeaders.cs @@ -46,9 +46,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if (value != null) { output.WriteFast(_CrLf); - output.WriteAscii(kv.Key); + output.WriteAsciiNoValidation(kv.Key); output.WriteFast(_colonSpace); - output.WriteAscii(value); + output.WriteAsciiNoValidation(value); } } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/PipelineExtensions.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/PipelineExtensions.cs index 6396b56781..4109119da9 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/PipelineExtensions.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/PipelineExtensions.cs @@ -158,7 +158,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } } - public unsafe static void WriteAscii(this WritableBuffer buffer, string data) + /// + /// Write string characters as ASCII without validating that characters fall in the ASCII range + /// + /// + /// ASCII character validation is done by + /// + /// the buffer + /// The string to write + public unsafe static void WriteAsciiNoValidation(this WritableBuffer buffer, string data) { if (string.IsNullOrEmpty(data)) { diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests.csproj b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests.csproj index 7e3f9f44ae..38068b0e25 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests.csproj +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests.csproj @@ -13,6 +13,7 @@ + diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/xunit.runner.json b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/xunit.runner.json new file mode 100644 index 0000000000..c76780941f --- /dev/null +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/xunit.runner.json @@ -0,0 +1,5 @@ +{ + "$schema": "http://json.schemastore.org/xunit.runner.schema", + "methodDisplay": "method", + "longRunningTestSeconds": 60 +} diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/PipelineExtensionTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/PipelineExtensionTests.cs new file mode 100644 index 0000000000..e5227dd63e --- /dev/null +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/PipelineExtensionTests.cs @@ -0,0 +1,167 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.IO.Pipelines; +using System.Text; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; +using Xunit; + +namespace Microsoft.AspNetCore.Server.KestrelTests +{ + public class PipelineExtensionTests : IDisposable + { + // ulong.MaxValue.ToString().Length + private const int _ulongMaxValueLength = 20; + + private readonly IPipe _pipe; + private readonly PipeFactory _pipeFactory = new PipeFactory(); + + public PipelineExtensionTests() + { + _pipe = _pipeFactory.Create(); + } + + public void Dispose() + { + _pipeFactory.Dispose(); + } + + [Theory] + [InlineData(ulong.MinValue)] + [InlineData(ulong.MaxValue)] + [InlineData(4_8_15_16_23_42)] + public async Task WritesNumericToAscii(ulong number) + { + var writer = _pipe.Writer.Alloc(); + writer.WriteNumeric(number); + await writer.FlushAsync(); + + var reader = await _pipe.Reader.ReadAsync(); + var numAsStr = number.ToString(); + var expected = Encoding.ASCII.GetBytes(numAsStr); + AssertExtensions.Equal(expected, reader.Buffer.Slice(0, numAsStr.Length).ToArray()); + } + + [Theory] + [InlineData(1)] + [InlineData(_ulongMaxValueLength / 2)] + [InlineData(_ulongMaxValueLength - 1)] + public void WritesNumericAcrossSpanBoundaries(int gapSize) + { + var writer = _pipe.Writer.Alloc(100); + // almost fill up the first block + var spacer = new Span(new byte[writer.Buffer.Length - gapSize]); + writer.Write(spacer); + + var bufferLength = writer.Buffer.Length; + writer.WriteNumeric(ulong.MaxValue); + Assert.NotEqual(bufferLength, writer.Buffer.Length); + + writer.FlushAsync().GetAwaiter().GetResult(); + + var reader = _pipe.Reader.ReadAsync().GetAwaiter().GetResult(); + var numAsString = ulong.MaxValue.ToString(); + var written = reader.Buffer.Slice(spacer.Length, numAsString.Length); + Assert.False(written.IsSingleSpan, "The buffer should cross spans"); + AssertExtensions.Equal(Encoding.ASCII.GetBytes(numAsString), written.ToArray()); + } + + [Theory] + [InlineData("\0abcxyz", new byte[] { 0, 97, 98, 99, 120, 121, 122 })] + [InlineData("!#$%i", new byte[] { 33, 35, 36, 37, 105 })] + [InlineData("!#$%", new byte[] { 33, 35, 36, 37 })] + [InlineData("!#$", new byte[] { 33, 35, 36 })] + [InlineData("!#", new byte[] { 33, 35 })] + [InlineData("!", new byte[] { 33 })] + // null or empty + [InlineData("", new byte[0])] + [InlineData(null, new byte[0])] + public async Task EncodesAsAscii(string input, byte[] expected) + { + var writer = _pipe.Writer.Alloc(); + writer.WriteAsciiNoValidation(input); + await writer.FlushAsync(); + var reader = await _pipe.Reader.ReadAsync(); + + if (expected.Length > 0) + { + AssertExtensions.Equal( + expected, + reader.Buffer.ToArray()); + } + else + { + Assert.Equal(0, reader.Buffer.Length); + } + } + + [Theory] + // non-ascii characters stored in 32 bits + [InlineData("𤭢𐐝")] + // non-ascii characters stored in 16 bits + [InlineData("ñ٢⛄⛵")] + public async Task WriteAsciiNoValidationWritesOnlyOneBytePerChar(string input) + { + // WriteAscii doesn't validate if characters are in the ASCII range + // but it shouldn't produce more than one byte per character + var writer = _pipe.Writer.Alloc(); + writer.WriteAsciiNoValidation(input); + await writer.FlushAsync(); + var reader = await _pipe.Reader.ReadAsync(); + + Assert.Equal(input.Length, reader.Buffer.Length); + } + + [Fact] + public async Task WriteAsciiNoValidation() + { + const byte maxAscii = 0x7f; + var writer = _pipe.Writer.Alloc(); + for (var i = 0; i < maxAscii; i++) + { + writer.WriteAsciiNoValidation(new string((char)i, 1)); + } + await writer.FlushAsync(); + + var reader = await _pipe.Reader.ReadAsync(); + var data = reader.Buffer.Slice(0, maxAscii).ToArray(); + for (var i = 0; i < maxAscii; i++) + { + Assert.Equal(i, data[i]); + } + } + + [Theory] + [InlineData(2, 1)] + [InlineData(3, 1)] + [InlineData(4, 2)] + [InlineData(5, 3)] + [InlineData(7, 4)] + [InlineData(8, 3)] + [InlineData(8, 4)] + [InlineData(8, 5)] + [InlineData(100, 48)] + public void WritesAsciiAcrossBlockBoundaries(int stringLength, int gapSize) + { + var testString = new string(' ', stringLength); + var writer = _pipe.Writer.Alloc(100); + // almost fill up the first block + var spacer = new Span(new byte[writer.Buffer.Length - gapSize]); + writer.Write(spacer); + Assert.Equal(gapSize, writer.Buffer.Span.Length); + + var bufferLength = writer.Buffer.Length; + writer.WriteAsciiNoValidation(testString); + Assert.NotEqual(bufferLength, writer.Buffer.Length); + + writer.FlushAsync().GetAwaiter().GetResult(); + + var reader = _pipe.Reader.ReadAsync().GetAwaiter().GetResult(); + var written = reader.Buffer.Slice(spacer.Length, stringLength); + Assert.False(written.IsSingleSpan, "The buffer should cross spans"); + AssertExtensions.Equal(Encoding.ASCII.GetBytes(testString), written.ToArray()); + } + } +} diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/AssertExtensions.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/AssertExtensions.cs new file mode 100644 index 0000000000..cb3fc36a3c --- /dev/null +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/AssertExtensions.cs @@ -0,0 +1,27 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using Xunit.Sdk; + +namespace Xunit +{ + public static class AssertExtensions + { + public static void Equal(byte[] expected, Span actual) + { + if (expected.Length != actual.Length) + { + throw new XunitException($"Expected length to be {expected.Length} but was {actual.Length}"); + } + + for (var i = 0; i < expected.Length; i++) + { + if (expected[i] != actual[i]) + { + throw new XunitException($@"Expected byte at index {i} to be '{expected[i]}' but was '{actual[i]}'"); + } + } + } + } +} diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/xunit.runner.json b/test/Microsoft.AspNetCore.Server.KestrelTests/xunit.runner.json index bbd346e81c..3a5192e57d 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/xunit.runner.json +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/xunit.runner.json @@ -1,4 +1,6 @@ { "$schema": "http://json.schemastore.org/xunit.runner.schema", - "appDomain": "denied" + "appDomain": "denied", + "methodDisplay": "method", + "longRunningTestSeconds": 60 } diff --git a/tools/CodeGenerator/KnownHeaders.cs b/tools/CodeGenerator/KnownHeaders.cs index 5d76a53305..3274b98646 100644 --- a/tools/CodeGenerator/KnownHeaders.cs +++ b/tools/CodeGenerator/KnownHeaders.cs @@ -541,7 +541,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http if (value != null) {{ output.WriteFast(_headerBytes, {header.BytesOffset}, {header.BytesCount}); - output.WriteAscii(value); + output.WriteAsciiNoValidation(value); }} }} }} From 6b6a8347cc05a1f029e3c0a46eefaaca2c9d13b5 Mon Sep 17 00:00:00 2001 From: Nate McMaster Date: Wed, 29 Mar 2017 16:17:06 -0700 Subject: [PATCH 1160/1662] Add Connection as a primary request header --- .../Internal/Http/FrameHeaders.Generated.cs | 120 +++++++++--------- tools/CodeGenerator/KnownHeaders.cs | 4 +- 2 files changed, 62 insertions(+), 62 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameHeaders.Generated.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameHeaders.Generated.cs index a8369ac971..8cc1ad75bd 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameHeaders.Generated.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameHeaders.Generated.cs @@ -2661,6 +2661,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http return; } + if ((tempBits & 2L) != 0) + { + _headers._Connection = default(StringValues); + if((tempBits & ~2L) == 0) + { + return; + } + tempBits &= ~2L; + } + if ((tempBits & 524288L) != 0) { _headers._Accept = default(StringValues); @@ -2701,16 +2711,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http tempBits &= ~1L; } - if ((tempBits & 2L) != 0) - { - _headers._Connection = default(StringValues); - if((tempBits & ~2L) == 0) - { - return; - } - tempBits &= ~2L; - } - if ((tempBits & 4L) != 0) { _headers._Date = default(StringValues); @@ -3511,6 +3511,38 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var stringValue = new StringValues(value); switch (keyLength) { + case 10: + { + if ((((pUL[0] & 16131858542891098079uL) == 5283922227757993795uL) && ((pUS[4] & 57311u) == 20047u))) + { + if ((_bits & 2L) != 0) + { + _headers._Connection = AppendValue(_headers._Connection, value); + } + else + { + _bits |= 2L; + _headers._Connection = stringValue; + } + return; + } + + if ((((pUL[0] & 16131858680330051551uL) == 4992030374873092949uL) && ((pUS[4] & 57311u) == 21582u))) + { + if ((_bits & 549755813888L) != 0) + { + _headers._UserAgent = AppendValue(_headers._UserAgent, value); + } + else + { + _bits |= 549755813888L; + _headers._UserAgent = stringValue; + } + return; + } + } + break; + case 6: { if ((((pUI[0] & 3755991007u) == 1162036033u) && ((pUS[2] & 57311u) == 21584u))) @@ -3546,24 +3578,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } } break; - - case 10: - { - if ((((pUL[0] & 16131858680330051551uL) == 4992030374873092949uL) && ((pUS[4] & 57311u) == 21582u))) - { - if ((_bits & 549755813888L) != 0) - { - _headers._UserAgent = AppendValue(_headers._UserAgent, value); - } - else - { - _bits |= 549755813888L; - _headers._UserAgent = stringValue; - } - return; - } - } - break; } AppendNonPrimaryHeaders(pKeyBytes, keyLength, value); @@ -3652,38 +3666,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } break; - case 10: - { - if ((((pUL[0] & 16131858542891098079uL) == 5283922227757993795uL) && ((pUS[4] & 57311u) == 20047u))) - { - if ((_bits & 2L) != 0) - { - _headers._Connection = AppendValue(_headers._Connection, value); - } - else - { - _bits |= 2L; - _headers._Connection = stringValue; - } - return; - } - - if ((((pUL[0] & 16131858680330051551uL) == 5281668125874799947uL) && ((pUS[4] & 57311u) == 17750u))) - { - if ((_bits & 8L) != 0) - { - _headers._KeepAlive = AppendValue(_headers._KeepAlive, value); - } - else - { - _bits |= 8L; - _headers._KeepAlive = stringValue; - } - return; - } - } - break; - case 4: { if ((((pUI[0] & 3755991007u) == 1163149636u))) @@ -3716,6 +3698,24 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } break; + case 10: + { + if ((((pUL[0] & 16131858680330051551uL) == 5281668125874799947uL) && ((pUS[4] & 57311u) == 17750u))) + { + if ((_bits & 8L) != 0) + { + _headers._KeepAlive = AppendValue(_headers._KeepAlive, value); + } + else + { + _bits |= 8L; + _headers._KeepAlive = stringValue; + } + return; + } + } + break; + case 6: { if ((((pUI[0] & 3755991007u) == 1195463248u) && ((pUS[2] & 57311u) == 16717u))) diff --git a/tools/CodeGenerator/KnownHeaders.cs b/tools/CodeGenerator/KnownHeaders.cs index 3274b98646..6f8ef86303 100644 --- a/tools/CodeGenerator/KnownHeaders.cs +++ b/tools/CodeGenerator/KnownHeaders.cs @@ -128,9 +128,9 @@ namespace CodeGenerator var requestPrimaryHeaders = new[] { "Accept", + "Connection", "Host", "User-Agent" - }; var responsePrimaryHeaders = new[] { @@ -633,4 +633,4 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http ")}}}"; } } -} \ No newline at end of file +} From e64bffd25c26f88d83929981d0de977748886b4c Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Wed, 29 Mar 2017 20:15:08 -0700 Subject: [PATCH 1161/1662] Remove deprecated property KestrelServerOptions.MaxRequestBufferSize (#1027). --- .../KestrelServerOptions.cs | 26 ---------------- .../KestrelServerOptionsTests.cs | 31 ------------------- 2 files changed, 57 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/KestrelServerOptions.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/KestrelServerOptions.cs index e9aba3c672..ca53bb1d49 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/KestrelServerOptions.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/KestrelServerOptions.cs @@ -34,32 +34,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel /// public IServiceProvider ApplicationServices { get; set; } - /// - /// - /// This property is obsolete and will be removed in a future version. - /// Use Limits.MaxRequestBufferSize instead. - /// - /// - /// Gets or sets the maximum size of the request buffer. - /// - /// - /// - /// When set to null, the size of the request buffer is unlimited. - /// Defaults to 1,048,576 bytes (1 MB). - /// - [Obsolete("This property is obsolete and will be removed in a future version. Use Limits.MaxRequestBufferSize instead.")] - public long? MaxRequestBufferSize - { - get - { - return Limits.MaxRequestBufferSize; - } - set - { - Limits.MaxRequestBufferSize = value; - } - } - /// /// Provides access to request limit options. /// diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerOptionsTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerOptionsTests.cs index 3d1e3eb9a2..8a33390342 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerOptionsTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerOptionsTests.cs @@ -1,10 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System; -using System.Linq; using System.Net; -using System.Reflection; using Microsoft.AspNetCore.Server.Kestrel; using Xunit; @@ -12,34 +9,6 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { public class KestrelServerOptionsTests { -#pragma warning disable CS0618 - [Fact] - public void MaxRequestBufferSizeIsMarkedObsolete() - { - Assert.NotNull(typeof(KestrelServerOptions) - .GetProperty(nameof(KestrelServerOptions.MaxRequestBufferSize)) - .GetCustomAttributes(false) - .OfType() - .SingleOrDefault()); - } - - [Fact] - public void MaxRequestBufferSizeGetsLimitsProperty() - { - var o = new KestrelServerOptions(); - o.Limits.MaxRequestBufferSize = 42; - Assert.Equal(42, o.MaxRequestBufferSize); - } - - [Fact] - public void MaxRequestBufferSizeSetsLimitsProperty() - { - var o = new KestrelServerOptions(); - o.MaxRequestBufferSize = 42; - Assert.Equal(42, o.Limits.MaxRequestBufferSize); - } -#pragma warning restore CS0612 - [Fact] public void NoDelayDefaultsToTrue() { From 1be31ae2ced3ba9e5c9ac7b362602eb0c53a3702 Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Wed, 29 Mar 2017 20:23:51 -0700 Subject: [PATCH 1162/1662] Throw if UseUrls specifies HTTPS or path base (#1519). --- .../KestrelServer.cs | 10 ++++ .../AddressRegistrationTests.cs | 7 --- .../RequestTests.cs | 58 ------------------- .../KestrelServerTests.cs | 37 ++++++++++++ 4 files changed, 47 insertions(+), 65 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/KestrelServer.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/KestrelServer.cs index 02ac364178..2b8678b5ff 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/KestrelServer.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/KestrelServer.cs @@ -146,6 +146,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel { var parsedAddress = ServerAddress.FromUrl(address); + if (parsedAddress.Scheme.Equals("https", StringComparison.OrdinalIgnoreCase)) + { + throw new InvalidOperationException($"HTTPS endpoints can only be configured using {nameof(KestrelServerOptions)}.{nameof(KestrelServerOptions.Listen)}()."); + } + + if (!string.IsNullOrEmpty(parsedAddress.PathBase)) + { + throw new InvalidOperationException($"A path base can only be configured using {nameof(IApplicationBuilder)}.UsePathBase()."); + } + if (!string.IsNullOrEmpty(parsedAddress.PathBase)) { _logger.LogWarning($"Path base in address {address} is not supported and will be ignored. To specify a path base, use {nameof(IApplicationBuilder)}.UsePathBase()."); diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs index 5a605a74c6..1abb18fe40 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs @@ -289,9 +289,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests dataset.Add($"http://*:{port}/", _ => new[] { $"http://127.0.0.1:{port}/" }); dataset.Add($"http://+:{port}/", _ => new[] { $"http://127.0.0.1:{port}/" }); - // Path after port - dataset.Add($"http://127.0.0.1:{port}/base/path", _ => new[] { $"http://127.0.0.1:{port}/base/path" }); - // Dynamic port and non-loopback addresses dataset.Add("http://127.0.0.1:0/", GetTestUrls); dataset.Add($"http://{Dns.GetHostName()}:0/", GetTestUrls); @@ -411,10 +408,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests dataset.Add($"http://127.0.0.1:{port}/;http://[::1]:{port}/", _ => new[] { $"http://127.0.0.1:{port}/", $"http://[::1]:{port}/" }); - // Path after port - dataset.Add($"http://[::1]:{port}/base/path", - _ => new[] { $"http://[::1]:{port}/base/path" }); - // Dynamic port and non-loopback addresses var ipv6Addresses = GetIPAddresses() .Where(ip => ip.AddressFamily == AddressFamily.InterNetworkV6) diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs index 10a718c1e8..6b9007c6d3 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs @@ -566,64 +566,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } } - [Theory] - [InlineData("/base", "/base")] - [InlineData("/base", "/base/")] - [InlineData("/base", "/base/something")] - [InlineData("/base", "/base/something/")] - [InlineData("/base/something", "/base/something")] - [InlineData("/base/something", "/base/something/")] - [InlineData("/base/something", "/base/something/more")] - [InlineData("/base/something", "/base/something/more/")] - public async Task DoesNotSplitPathBase(string registerPathBase, string requestPath) - { - var testLogger = new TestApplicationErrorLogger(); - - string contextPathBase = null; - string contextPath = null; - - var builder = new WebHostBuilder() - .UseKestrel() - .UseUrls($"http://127.0.0.1:0{registerPathBase}") - .ConfigureServices(services => - { - services.AddSingleton(new KestrelTestLoggerFactory(testLogger)); - }) - .Configure(app => - { - app.Run(context => - { - contextPathBase = context.Request.PathBase; - contextPath = context.Request.Path; - - return TaskCache.CompletedTask; - }); - }); - - using (var host = builder.Build()) - { - host.Start(); - - using (var connection = new TestConnection(host.GetPort())) - { - await connection.Send($"GET {requestPath} HTTP/1.1\r\n\r\n"); - await connection.Receive("HTTP/1.1 200 OK"); - } - - Assert.Single(testLogger.Messages, log => - log.LogLevel == LogLevel.Warning && - string.Equals( - $"Path base in address http://127.0.0.1:0{registerPathBase} is not supported and will be ignored. To specify a path base, use {nameof(IApplicationBuilder)}.UsePathBase().", - log.Message, - StringComparison.Ordinal)); - } - - Assert.Equal("", contextPathBase); - Assert.Equal(requestPath, contextPath); - - - } - private async Task TestRemoteIPAddress(string registerAddress, string requestAddress, string expectAddress) { var builder = new WebHostBuilder() diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerTests.cs index dd36a36669..2f103ff376 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerTests.cs @@ -14,6 +14,7 @@ using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using Moq; using Xunit; +using Microsoft.AspNetCore.Builder; namespace Microsoft.AspNetCore.Server.KestrelTests { @@ -35,6 +36,42 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } } + [Fact] + public void StartWithHttpsAddressThrows() + { + var testLogger = new TestApplicationErrorLogger { ThrowOnCriticalErrors = false }; + + using (var server = CreateServer(new KestrelServerOptions(), testLogger)) + { + server.Features.Get().Addresses.Add("https://127.0.0.1:0"); + + var exception = Assert.Throws(() => StartDummyApplication(server)); + + Assert.Equal( + $"HTTPS endpoints can only be configured using {nameof(KestrelServerOptions)}.{nameof(KestrelServerOptions.Listen)}().", + exception.Message); + Assert.Equal(1, testLogger.CriticalErrorsLogged); + } + } + + [Fact] + public void StartWithPathBaseInAddressThrows() + { + var testLogger = new TestApplicationErrorLogger { ThrowOnCriticalErrors = false }; + + using (var server = CreateServer(new KestrelServerOptions(), testLogger)) + { + server.Features.Get().Addresses.Add("http://127.0.0.1:0/base"); + + var exception = Assert.Throws(() => StartDummyApplication(server)); + + Assert.Equal( + $"A path base can only be configured using {nameof(IApplicationBuilder)}.UsePathBase().", + exception.Message); + Assert.Equal(1, testLogger.CriticalErrorsLogged); + } + } + [Theory] [InlineData("http://localhost:5000")] [InlineData("The value of the string shouldn't matter.")] From c3ad007b0d56d84d38fa33a6d62b6681d688ab44 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Thu, 30 Mar 2017 09:33:28 -0700 Subject: [PATCH 1163/1662] Fixed regression caused by transport refactoring (#1573) * Fixed regression caused by transport refactoring - Libuv should not close the socket until it has started it. Before this was enforced by calling ReadStart before starting the frame but the flow has changed. Now that closing the connection is communicated via the pipe, we need to start consuming writes after calling ReadStart. - Renamed OnSocketClosed to Close and moved dispose and logging into that method. Fixes #1571 --- .../Internal/Http/Connection.cs | 13 ++++++++++-- .../Internal/Http/SocketOutputConsumer.cs | 20 ++++++++----------- .../SocketOutputTests.cs | 1 + test/shared/MockConnection.cs | 2 +- 4 files changed, 21 insertions(+), 15 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Http/Connection.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Http/Connection.cs index c1e0637f60..8cf743bbdd 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Http/Connection.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Http/Connection.cs @@ -21,7 +21,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http private static readonly Action _readCallback = (handle, status, state) => ReadCallback(handle, status, state); - + private static readonly Func _allocCallback = (handle, suggestedsize, state) => AllocCallback(handle, suggestedsize, state); @@ -80,6 +80,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http // Start socket prior to applying the ConnectionAdapter _socket.ReadStart(_allocCallback, _readCallback, this); _lastTimestamp = Thread.Loop.Now(); + + // This *must* happen after socket.ReadStart + // The socket output consumer is the only thing that can close the connection. If the + // output pipe is already closed by the time we start then it's fine since, it'll close gracefully afterwards. + var ignore = Output.StartWrites(); } catch (Exception e) { @@ -100,8 +105,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } // Called on Libuv thread - public virtual void OnSocketClosed() + public virtual void Close() { + _socket.Dispose(); + + Log.ConnectionStop(ConnectionId); + KestrelEventSource.Log.ConnectionStop(this); Input.Complete(new TaskCanceledException("The request was aborted")); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Http/SocketOutputConsumer.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Http/SocketOutputConsumer.cs index af6b5e2220..6ff5c69ebb 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Http/SocketOutputConsumer.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Http/SocketOutputConsumer.cs @@ -37,8 +37,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _connectionId = connectionId; _log = log; _writeReqPool = thread.WriteReqPool; - - var ignore = StartWrites(); } public async Task StartWrites() @@ -56,7 +54,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var writeResult = await writeReq.WriteAsync(_socket, buffer); _writeReqPool.Return(writeReq); - // REVIEW: Locking here, do we need to take the context lock? OnWriteCompleted(writeResult.Status, writeResult.Error); } @@ -80,9 +77,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http // We're done reading _pipe.Complete(); - _socket.Dispose(); - _connection.OnSocketClosed(); - _log.ConnectionStop(_connectionId); + // Close the connection + _connection.Close(); } private void OnWriteCompleted(int writeStatus, Exception writeError) @@ -124,13 +120,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http var shutdownReq = new UvShutdownReq(_log); shutdownReq.Init(_thread.Loop); shutdownReq.Shutdown(_socket, (req, status, state) => - { - req.Dispose(); - _log.ConnectionWroteFin(_connectionId, status); + { + req.Dispose(); + _log.ConnectionWroteFin(_connectionId, status); - tcs.TrySetResult(null); - }, - this); + tcs.TrySetResult(null); + }, + this); return tcs.Task; } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/SocketOutputTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/SocketOutputTests.cs index 3232ef0287..351886a3ce 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/SocketOutputTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/SocketOutputTests.cs @@ -527,6 +527,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var socket = new MockSocket(_mockLibuv, _kestrelThread.Loop.ThreadId, new TestKestrelTrace()); var socketOutput = new SocketOutputProducer(pipe.Writer, frame, "0", trace); var consumer = new SocketOutputConsumer(pipe.Reader, _kestrelThread, socket, connection ?? new MockConnection(), "0", trace); + var ignore = consumer.StartWrites(); return socketOutput; } diff --git a/test/shared/MockConnection.cs b/test/shared/MockConnection.cs index 9c6528673c..aebb7807a4 100644 --- a/test/shared/MockConnection.cs +++ b/test/shared/MockConnection.cs @@ -27,7 +27,7 @@ namespace Microsoft.AspNetCore.Testing return TaskCache.CompletedTask; } - public override void OnSocketClosed() + public override void Close() { _socketClosedTcs.SetResult(null); } From b0bd5475cd6b84476c30639580fb56ef3663c673 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Thu, 30 Mar 2017 20:14:50 -0700 Subject: [PATCH 1164/1662] More decoupling (#1572) - Remove Libuv and Hosting dependency from Kestrel.Core - Kestrel.Https and Kestrel.Core depend on Hosting.Abstractions * wip * Added separate ServerAddressesFeature * Review feedback - Added TlsConnectionFeature to Https --- .../Internal/ServerAddressesFeature.cs | 16 ++++++++++++++ .../KestrelServer.cs | 10 ++++----- ...soft.AspNetCore.Server.Kestrel.Core.csproj | 6 ++++-- .../Internal/TlsConnectionFeature.cs | 21 +++++++++++++++++++ ...oft.AspNetCore.Server.Kestrel.Https.csproj | 1 + ...Microsoft.AspNetCore.Server.Kestrel.csproj | 4 ++++ 6 files changed, 51 insertions(+), 7 deletions(-) create mode 100644 src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/ServerAddressesFeature.cs create mode 100644 src/Microsoft.AspNetCore.Server.Kestrel.Https/Internal/TlsConnectionFeature.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/ServerAddressesFeature.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/ServerAddressesFeature.cs new file mode 100644 index 0000000000..76a9d960b5 --- /dev/null +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/ServerAddressesFeature.cs @@ -0,0 +1,16 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Collections.Generic; +using System.Text; +using Microsoft.AspNetCore.Hosting.Server.Features; + +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal +{ + internal class ServerAddressesFeature : IServerAddressesFeature + { + public ICollection Addresses { get; } = new List(); + public bool PreferHostingUrls { get; set; } + } +} diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/KestrelServer.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/KestrelServer.cs index 2b8678b5ff..3958755ea1 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/KestrelServer.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/KestrelServer.cs @@ -12,6 +12,7 @@ using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting.Server; using Microsoft.AspNetCore.Hosting.Server.Features; using Microsoft.AspNetCore.Http.Features; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal; using Microsoft.AspNetCore.Server.Kestrel.Internal; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; @@ -24,7 +25,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel { public class KestrelServer : IServer { - //private Stack _disposables; private readonly List _transports = new List(); private readonly ILogger _logger; @@ -60,7 +60,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel _logger = loggerFactory.CreateLogger(typeof(KestrelServer).GetTypeInfo().Namespace); Features = new FeatureCollection(); _serverAddresses = new ServerAddressesFeature(); - Features.Set(_serverAddresses); + Features.Set(_serverAddresses); Features.Set(InternalOptions); } @@ -278,11 +278,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel } catch (AggregateException ex) when (ex.InnerException is AddressInUseException) { - throw new IOException($"Failed to bind to address {parsedAddress} on the IPv4 loopback interface: port already in use.", ex); + throw new IOException($"Failed to bind to address {parsedAddress} on the IPv4 loopback interface: port already in use.", ex); } catch (AggregateException ex) { - _logger.LogWarning(0, $"Unable to bind to {parsedAddress} on the IPv4 loopback interface: ({ex.Message})"); + _logger.LogWarning(0, $"Unable to bind to {parsedAddress} on the IPv4 loopback interface: ({ex.Message})"); exceptions.Add(ex.InnerException); } @@ -329,4 +329,4 @@ namespace Microsoft.AspNetCore.Server.Kestrel return new IPEndPoint(ip, address.Port); } } -} +} \ No newline at end of file diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Microsoft.AspNetCore.Server.Kestrel.Core.csproj b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Microsoft.AspNetCore.Server.Kestrel.Core.csproj index b7038ded2a..931898c08b 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Microsoft.AspNetCore.Server.Kestrel.Core.csproj +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Microsoft.AspNetCore.Server.Kestrel.Core.csproj @@ -13,9 +13,11 @@ - - + + + + diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Https/Internal/TlsConnectionFeature.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Https/Internal/TlsConnectionFeature.cs new file mode 100644 index 0000000000..2fb85037b5 --- /dev/null +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Https/Internal/TlsConnectionFeature.cs @@ -0,0 +1,21 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Security.Cryptography.X509Certificates; +using System.Threading; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Http.Features; + +namespace Microsoft.AspNetCore.Server.Kestrel.Https.Internal +{ + internal class TlsConnectionFeature : ITlsConnectionFeature + { + public X509Certificate2 ClientCertificate { get; set; } + + public Task GetClientCertificateAsync(CancellationToken cancellationToken) + { + return Task.FromResult(ClientCertificate); + } + } +} diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Https/Microsoft.AspNetCore.Server.Kestrel.Https.csproj b/src/Microsoft.AspNetCore.Server.Kestrel.Https/Microsoft.AspNetCore.Server.Kestrel.Https.csproj index f49fae3639..6ee24eba77 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Https/Microsoft.AspNetCore.Server.Kestrel.Https.csproj +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Https/Microsoft.AspNetCore.Server.Kestrel.Https.csproj @@ -16,6 +16,7 @@ + diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Microsoft.AspNetCore.Server.Kestrel.csproj b/src/Microsoft.AspNetCore.Server.Kestrel/Microsoft.AspNetCore.Server.Kestrel.csproj index 27e7cc51fe..91e491c4f9 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Microsoft.AspNetCore.Server.Kestrel.csproj +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Microsoft.AspNetCore.Server.Kestrel.csproj @@ -11,6 +11,10 @@ false + + + + From 1bf9b057d4b3dd38fe2bfcd538b4bf33d275860d Mon Sep 17 00:00:00 2001 From: David Fowler Date: Fri, 31 Mar 2017 02:58:18 -0700 Subject: [PATCH 1165/1662] Converted test projects to run on netcoreapp2.0 * Converted test projects to run on netcoreapp2.0 * Set DOTNET_RUNTME_ID because of an issue in corehost and RID calculation. --- build/dependencies.props | 1 + samples/LargeResponseApp/LargeResponseApp.csproj | 2 +- samples/SampleApp/SampleApp.csproj | 2 +- .../GeneratedCodeTests.cs | 5 ++++- ...crosoft.AspNetCore.Server.Kestrel.FunctionalTests.csproj | 6 +++--- .../SystemdActivation/Dockerfile | 6 +++++- .../SystemdActivation/activate-kestrel.service | 2 +- .../SystemdActivation/docker.sh | 4 ++-- .../Microsoft.AspNetCore.Server.Kestrel.Performance.csproj | 2 +- .../ResponseHeadersWritingBenchmark.cs | 2 +- .../FrameRequestStreamTests.cs | 4 ++-- .../FrameResponseStreamTests.cs | 4 ++-- .../Microsoft.AspNetCore.Server.KestrelTests.csproj | 4 ++-- test/shared/TestResources.cs | 4 ++-- 14 files changed, 28 insertions(+), 20 deletions(-) diff --git a/build/dependencies.props b/build/dependencies.props index fec2f8c282..93b34f5c4e 100644 --- a/build/dependencies.props +++ b/build/dependencies.props @@ -9,6 +9,7 @@ 9.0.1 4.7.1 1.6.1 + 2.0.0-* 15.0.0 2.2.0 diff --git a/samples/LargeResponseApp/LargeResponseApp.csproj b/samples/LargeResponseApp/LargeResponseApp.csproj index 06e37972b7..6aad6e781e 100644 --- a/samples/LargeResponseApp/LargeResponseApp.csproj +++ b/samples/LargeResponseApp/LargeResponseApp.csproj @@ -3,7 +3,7 @@ - net46;netcoreapp1.1 + net46;netcoreapp2.0 false diff --git a/samples/SampleApp/SampleApp.csproj b/samples/SampleApp/SampleApp.csproj index b623456397..f8ee813b62 100644 --- a/samples/SampleApp/SampleApp.csproj +++ b/samples/SampleApp/SampleApp.csproj @@ -3,7 +3,7 @@ - netcoreapp1.1;net46 + netcoreapp2.0;net46 false diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/GeneratedCodeTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/GeneratedCodeTests.cs index b295ee52d7..386296d716 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/GeneratedCodeTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/GeneratedCodeTests.cs @@ -1,7 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -#if NETCOREAPP1_1 +#if NETCOREAPP2_0 using System.IO; using Xunit; @@ -41,4 +41,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } } +#elif NET46 +#else +#error Target framework needs to be updated #endif \ No newline at end of file diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests.csproj b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests.csproj index 38068b0e25..cbef1e8054 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests.csproj +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests.csproj @@ -3,8 +3,8 @@ - netcoreapp1.1;net46 - netcoreapp1.1 + netcoreapp2.0;net46 + netcoreapp2.0 x64 true true @@ -32,7 +32,7 @@ - + diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/SystemdActivation/Dockerfile b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/SystemdActivation/Dockerfile index 464f6a4ec0..5b071165d4 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/SystemdActivation/Dockerfile +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/SystemdActivation/Dockerfile @@ -1,8 +1,12 @@ -FROM microsoft/dotnet:1.1-runtime-deps +FROM microsoft/dotnet-nightly:2.0-runtime-deps # The "container" environment variable is read by systemd. ENV container=docker +# We're copying assets from an ubuntu machine over the container make the RID +# match +ENV DOTNET_RUNTIME_ID=ubuntu.14.04-x64 + # This is required by systemd and won't work without "dotnet run --privileged". VOLUME ["/sys/fs/cgroup"] diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/SystemdActivation/activate-kestrel.service b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/SystemdActivation/activate-kestrel.service index 392bf823cd..e21d5db863 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/SystemdActivation/activate-kestrel.service +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/SystemdActivation/activate-kestrel.service @@ -5,4 +5,4 @@ Requires=activate-kestrel.socket ExecStart=/usr/bin/dotnet SampleApp.dll WorkingDirectory=/publish NonBlocking=true - +Environment="DOTNET_RUNTIME_ID=ubuntu.14.04-x64" \ No newline at end of file diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/SystemdActivation/docker.sh b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/SystemdActivation/docker.sh index 7075a37d8c..8bef6049d8 100755 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/SystemdActivation/docker.sh +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/SystemdActivation/docker.sh @@ -3,8 +3,8 @@ set -e scriptDir=$(dirname "${BASH_SOURCE[0]}") -~/.dotnet/dotnet publish -f netcoreapp1.1 ./samples/SampleApp/ -cp -R ./samples/SampleApp/bin/Debug/netcoreapp1.1/publish/ $scriptDir +~/.dotnet/dotnet publish -f netcoreapp2.0 ./samples/SampleApp/ +cp -R ./samples/SampleApp/bin/Debug/netcoreapp2.0/publish/ $scriptDir cp -R ~/.dotnet/ $scriptDir image=$(docker build -qf $scriptDir/Dockerfile $scriptDir) diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Microsoft.AspNetCore.Server.Kestrel.Performance.csproj b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Microsoft.AspNetCore.Server.Kestrel.Performance.csproj index 8718f3f9ae..ce7fa7c2b0 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Microsoft.AspNetCore.Server.Kestrel.Performance.csproj +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Microsoft.AspNetCore.Server.Kestrel.Performance.csproj @@ -3,7 +3,7 @@ - netcoreapp1.1 + netcoreapp2.0 Exe true true diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/ResponseHeadersWritingBenchmark.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/ResponseHeadersWritingBenchmark.cs index 270f739286..ce2f941c41 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/ResponseHeadersWritingBenchmark.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/ResponseHeadersWritingBenchmark.cs @@ -36,7 +36,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance { _frame.Reset(); _frame.StatusCode = 200; - _frame.HttpVersionEnum = HttpVersion.Http11; + _frame.HttpVersionEnum = Internal.Http.HttpVersion.Http11; _frame.KeepAlive = true; Task writeTask = Task.CompletedTask; diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameRequestStreamTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameRequestStreamTests.cs index 47ce60b35a..28f1d800b7 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameRequestStreamTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameRequestStreamTests.cs @@ -90,9 +90,9 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var stream = new FrameRequestStream(); Assert.Throws(() => stream.BeginWrite(new byte[1], 0, 1, null, null)); } -#elif NETCOREAPP1_1 +#elif NETCOREAPP2_0 #else -#error target frameworks need to be updated +#error Target framework needs to be updated #endif [Fact] diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameResponseStreamTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameResponseStreamTests.cs index 363eb26d30..d097ee6161 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameResponseStreamTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameResponseStreamTests.cs @@ -61,9 +61,9 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var stream = new FrameResponseStream(new MockFrameControl()); Assert.Throws(() => stream.BeginRead(new byte[1], 0, 1, null, null)); } -#elif NETCOREAPP1_1 +#elif NETCOREAPP2_0 #else -#error target frameworks need to be updated +#error Target framework needs to be updated #endif [Fact] diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/Microsoft.AspNetCore.Server.KestrelTests.csproj b/test/Microsoft.AspNetCore.Server.KestrelTests/Microsoft.AspNetCore.Server.KestrelTests.csproj index 1ee3019579..7fb00ec5b2 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/Microsoft.AspNetCore.Server.KestrelTests.csproj +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/Microsoft.AspNetCore.Server.KestrelTests.csproj @@ -3,8 +3,8 @@ - netcoreapp1.1;net46 - netcoreapp1.1 + netcoreapp2.0;net46 + netcoreapp2.0 x64 true diff --git a/test/shared/TestResources.cs b/test/shared/TestResources.cs index 37b2443622..19341db11a 100644 --- a/test/shared/TestResources.cs +++ b/test/shared/TestResources.cs @@ -11,10 +11,10 @@ namespace Microsoft.AspNetCore.Testing private static readonly string _testCertificatePath = #if NET46 Path.Combine(Directory.GetCurrentDirectory(), "testCert.pfx"); -#elif NETCOREAPP1_1 +#elif NETCOREAPP2_0 Path.Combine(AppContext.BaseDirectory, "testCert.pfx"); #else -#error Target frameworks need to be updated. +#error Target framework needs to be updated #endif public static string TestCertificatePath => _testCertificatePath; From b4cec03f650f140c8a25cdea385099dd5bcd01ee Mon Sep 17 00:00:00 2001 From: David Fowler Date: Fri, 31 Mar 2017 10:19:27 -0700 Subject: [PATCH 1166/1662] Update libuv package (#1577) - The latest libuv package has a new linux RID that should let us remove the work around with setting the RID in the docker file and systemd service --- build/dependencies.props | 2 +- .../SystemdActivation/Dockerfile | 4 ---- .../SystemdActivation/activate-kestrel.service | 3 +-- 3 files changed, 2 insertions(+), 7 deletions(-) diff --git a/build/dependencies.props b/build/dependencies.props index 93b34f5c4e..ac2690b701 100644 --- a/build/dependencies.props +++ b/build/dependencies.props @@ -5,7 +5,7 @@ 0.1.0-* 4.3.0 2.0.0-* - 1.9.1 + 1.10.0-* 9.0.1 4.7.1 1.6.1 diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/SystemdActivation/Dockerfile b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/SystemdActivation/Dockerfile index 5b071165d4..ac2b561610 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/SystemdActivation/Dockerfile +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/SystemdActivation/Dockerfile @@ -3,10 +3,6 @@ FROM microsoft/dotnet-nightly:2.0-runtime-deps # The "container" environment variable is read by systemd. ENV container=docker -# We're copying assets from an ubuntu machine over the container make the RID -# match -ENV DOTNET_RUNTIME_ID=ubuntu.14.04-x64 - # This is required by systemd and won't work without "dotnet run --privileged". VOLUME ["/sys/fs/cgroup"] diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/SystemdActivation/activate-kestrel.service b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/SystemdActivation/activate-kestrel.service index e21d5db863..54cff82383 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/SystemdActivation/activate-kestrel.service +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/SystemdActivation/activate-kestrel.service @@ -4,5 +4,4 @@ Requires=activate-kestrel.socket [Service] ExecStart=/usr/bin/dotnet SampleApp.dll WorkingDirectory=/publish -NonBlocking=true -Environment="DOTNET_RUNTIME_ID=ubuntu.14.04-x64" \ No newline at end of file +NonBlocking=true \ No newline at end of file From 0ab49f4977a16e38b6db80731f4c2ab2615b4bd0 Mon Sep 17 00:00:00 2001 From: Ryan Nowak Date: Fri, 31 Mar 2017 10:34:40 -0700 Subject: [PATCH 1167/1662] Fix benchmarks on netcoreapp2.0 --- .../Microsoft.AspNetCore.Server.Kestrel.Performance.csproj | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Microsoft.AspNetCore.Server.Kestrel.Performance.csproj b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Microsoft.AspNetCore.Server.Kestrel.Performance.csproj index ce7fa7c2b0..ec86613394 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Microsoft.AspNetCore.Server.Kestrel.Performance.csproj +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Microsoft.AspNetCore.Server.Kestrel.Performance.csproj @@ -8,6 +8,12 @@ true true false + + + 2.0.0-* From 6b9d54265f0c9549b1b5768af6683781cd833823 Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Fri, 31 Mar 2017 11:08:55 -0700 Subject: [PATCH 1168/1662] Call ProduceEnd() before consuming request body if response has already started (#1530). --- .../Internal/Http/FrameOfT.cs | 22 +- .../ResponseTests.cs | 190 ++++++++++++++++-- 2 files changed, 191 insertions(+), 21 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameOfT.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameOfT.cs index 37f3feedee..9fdb0497ac 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameOfT.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameOfT.cs @@ -135,16 +135,30 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { ResumeStreams(); + if (HasResponseStarted) + { + // If the response has already started, call ProduceEnd() before + // consuming the rest of the request body to prevent + // delaying clients waiting for the chunk terminator: + // + // https://github.com/dotnet/corefx/issues/17330#issuecomment-288248663 + // + // ProduceEnd() must be called before _application.DisposeContext(), to ensure + // HttpContext.Response.StatusCode is correctly set when + // IHttpContextFactory.Dispose(HttpContext) is called. + await ProduceEnd(); + } + if (_keepAlive) { // Finish reading the request body in case the app did not. await messageBody.Consume(); } - // ProduceEnd() must be called before _application.DisposeContext(), to ensure - // HttpContext.Response.StatusCode is correctly set when - // IHttpContextFactory.Dispose(HttpContext) is called. - await ProduceEnd(); + if (!HasResponseStarted) + { + await ProduceEnd(); + } } else if (!HasResponseStarted) { diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs index a8e071e339..1e8fd21746 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs @@ -341,7 +341,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { readException = await Assert.ThrowsAsync( async () => await httpContext.Request.Body.ReadAsync(new byte[1], 0, 1)); - }, new TestServiceContext())) + })) { using (var connection = server.CreateConnection()) { @@ -370,7 +370,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { await httpContext.Response.WriteAsync("hello, "); await httpContext.Response.WriteAsync("world"); - }, new TestServiceContext())) + })) { using (var connection = server.CreateConnection()) { @@ -404,7 +404,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { httpContext.Response.StatusCode = statusCode; return TaskCache.CompletedTask; - }, new TestServiceContext())) + })) { using (var connection = server.CreateConnection()) { @@ -427,7 +427,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests using (var server = new TestServer(httpContext => { return TaskCache.CompletedTask; - }, new TestServiceContext())) + })) { using (var connection = server.CreateConnection()) { @@ -880,7 +880,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { httpContext.Response.ContentLength = 42; return TaskCache.CompletedTask; - }, new TestServiceContext())) + })) { using (var connection = server.CreateConnection()) { @@ -908,7 +908,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests httpContext.Response.ContentLength = 12; await httpContext.Response.WriteAsync("hello, world"); await flushed.WaitAsync(); - }, new TestServiceContext())) + })) { using (var connection = server.CreateConnection()) { @@ -939,7 +939,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests httpContext.Response.Body.Write(Encoding.ASCII.GetBytes("hello, world"), 0, 12); flushed.Wait(); return TaskCache.CompletedTask; - }, new TestServiceContext())) + })) { using (var connection = server.CreateConnection()) { @@ -970,7 +970,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests await httpContext.Response.WriteAsync(""); flushed.Wait(); await httpContext.Response.WriteAsync("hello, world"); - }, new TestServiceContext())) + })) { using (var connection = server.CreateConnection()) { @@ -1013,7 +1013,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { tcs.TrySetException(ex); } - }, new TestServiceContext())) + })) { using (var connection = server.CreateConnection()) { @@ -1053,7 +1053,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests await httpContext.Response.WriteAsync(ex.Message); responseWritten.Release(); } - }, new TestServiceContext())) + })) { using (var connection = server.CreateConnection()) { @@ -1084,7 +1084,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { httpContext.Response.Headers["Transfer-Encoding"] = responseTransferEncoding; await httpContext.Response.WriteAsync("hello, world"); - }, new TestServiceContext())) + })) { using (var connection = server.CreateConnection()) { @@ -1131,7 +1131,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests httpContext.Response.Headers["Connection"] = "keep-alive"; httpContext.Response.Headers["Transfer-Encoding"] = responseTransferEncoding; await httpContext.Response.WriteAsync("hello, world"); - }, new TestServiceContext())) + })) { using (var connection = server.CreateConnection()) { @@ -1177,7 +1177,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests // App would have to chunk manually, but here we don't care await httpContext.Response.WriteAsync("hello, world"); - }, new TestServiceContext())) + })) { using (var connection = server.CreateConnection()) { @@ -1225,7 +1225,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests // If OnStarting is not run before verifying writes, an error response will be sent. httpContext.Response.Body.Write(response, 0, response.Length); return TaskCache.CompletedTask; - }, new TestServiceContext())) + })) { using (var connection = server.CreateConnection()) { @@ -1266,7 +1266,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests httpContext.Response.Body.Write(response, 0, response.Length / 2); httpContext.Response.Body.Write(response, response.Length / 2, response.Length - response.Length / 2); return TaskCache.CompletedTask; - }, new TestServiceContext())) + })) { using (var connection = server.CreateConnection()) { @@ -1307,7 +1307,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests // If OnStarting is not run before verifying writes, an error response will be sent. return httpContext.Response.Body.WriteAsync(response, 0, response.Length); - }, new TestServiceContext())) + })) { using (var connection = server.CreateConnection()) { @@ -1347,7 +1347,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests // If OnStarting is not run before verifying writes, an error response will be sent. await httpContext.Response.Body.WriteAsync(response, 0, response.Length / 2); await httpContext.Response.Body.WriteAsync(response, response.Length / 2, response.Length - response.Length / 2); - }, new TestServiceContext())) + })) { using (var connection = server.CreateConnection()) { @@ -1371,6 +1371,162 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } } + [Fact] + public async Task WhenResponseAlreadyStartedResponseEndedBeforeConsumingRequestBody() + { + using (var server = new TestServer(async httpContext => + { + await httpContext.Response.WriteAsync("hello, world"); + })) + { + using (var connection = server.CreateConnection()) + { + await connection.Send( + "POST / HTTP/1.1", + "Content-Length: 1", + "", + ""); + + await connection.Receive( + "HTTP/1.1 200 OK", + $"Date: {server.Context.DateHeaderValue}", + $"Transfer-Encoding: chunked", + "", + "c", + "hello, world", + ""); + + // If the expected behavior is regressed, this will hang because the + // server will try to consume the request body before flushing the chunked + // terminator. + await connection.Receive( + "0", + "", + ""); + } + } + } + + [Fact] + public async Task WhenResponseNotStartedResponseEndedAfterConsumingRequestBody() + { + using (var server = new TestServer(httpContext => TaskCache.CompletedTask)) + { + using (var connection = server.CreateConnection()) + { + await connection.Send( + "POST / HTTP/1.1", + "Transfer-Encoding: chunked", + "", + "gg"); + + // If the expected behavior is regressed, this will receive + // a success response because the server flushed the response + // before reading the malformed chunk header in the request. + await connection.ReceiveForcedEnd( + "HTTP/1.1 400 Bad Request", + "Connection: close", + $"Date: {server.Context.DateHeaderValue}", + "Content-Length: 0", + "", + ""); + } + } + } + + [Fact] + public async Task Sending100ContinueDoesNotStartResponse() + { + using (var server = new TestServer(httpContext => + { + return httpContext.Request.Body.ReadAsync(new byte[1], 0, 1); + })) + { + using (var connection = server.CreateConnection()) + { + await connection.Send( + "POST / HTTP/1.1", + "Transfer-Encoding: chunked", + "Expect: 100-continue", + "", + ""); + + await connection.Receive( + "HTTP/1.1 100 Continue", + "", + ""); + + // Let the app finish + await connection.Send( + "1", + "a", + ""); + + // This will be consumed by Frame when it attempts to + // consume the request body and will cause an error. + await connection.Send( + "gg"); + + // If 100 Continue sets Frame.HasResponseStarted to true, + // a success response will be produced before the server sees the + // bad chunk header above, making this test fail. + await connection.ReceiveForcedEnd( + "HTTP/1.1 400 Bad Request", + "Connection: close", + $"Date: {server.Context.DateHeaderValue}", + "Content-Length: 0", + "", + ""); + } + } + } + + [Fact] + public async Task Sending100ContinueAndResponseSendsChunkTerminatorBeforeConsumingRequestBody() + { + using (var server = new TestServer(async httpContext => + { + await httpContext.Request.Body.ReadAsync(new byte[1], 0, 1); + await httpContext.Response.WriteAsync("hello, world"); + })) + { + using (var connection = server.CreateConnection()) + { + await connection.Send( + "POST / HTTP/1.1", + "Content-Length: 2", + "Expect: 100-continue", + "", + ""); + + await connection.Receive( + "HTTP/1.1 100 Continue", + "", + ""); + + await connection.Send( + "a"); + + await connection.Receive( + "HTTP/1.1 200 OK", + $"Date: {server.Context.DateHeaderValue}", + $"Transfer-Encoding: chunked", + "", + "c", + "hello, world", + ""); + + // If the expected behavior is regressed, this will hang because the + // server will try to consume the request body before flushing the chunked + // terminator. + await connection.Receive( + "0", + "", + ""); + } + } + } + public static TheoryData NullHeaderData { get From 83958886cc3fef2dcb0f3289009b3eb3e615e9fd Mon Sep 17 00:00:00 2001 From: Nate McMaster Date: Fri, 31 Mar 2017 09:09:01 -0700 Subject: [PATCH 1169/1662] Implement IHttpRequestIdentifierFeature on Frame This feature generates a unique ID per request. This unique ID can be used in event source and logging. Also, this change improves KestrelEventSource by moving it back into the Kestrel.Core assembly and de-coupling from the Libuv transport. This adds two new events, RequestStart and RequestStop, which can be used to identify the correlation between connection ID and request trace identifier. --- .vscode/tasks.json | 19 +- .../Internal/ConnectionHandler.cs | 43 +--- .../Internal/FrameConnection.cs | 6 + .../Internal/Http/Frame.FeatureCollection.cs | 190 +++++------------- .../Internal/Http/Frame.Generated.cs | 2 +- .../Internal/Http/Frame.cs | 24 ++- .../Internal/Http/FrameOfT.cs | 5 + .../Infrastructure/CorrelationIdGenerator.cs | 48 +++++ .../Internal/Infrastructure/IKestrelTrace.cs | 2 +- .../Infrastructure/KestrelEventSource.cs | 47 ++++- .../Internal/Infrastructure/KestrelTrace.cs | 8 +- .../Transport/IConnectionContext.cs | 1 + .../Internal/Http/Connection.cs | 9 +- .../EventSourceTests.cs | 35 +++- .../RequestTests.cs | 69 ++++++- .../ResponseTests.cs | 7 +- .../Mocks/MockTrace.cs | 2 +- .../FrameTests.cs | 27 +++ .../KestrelEventSourceTests.cs | 6 +- .../TestHelpers/MockConnectionHandler.cs | 5 + test/shared/TestConnection.cs | 2 + test/shared/TestServer.cs | 1 + tools/CodeGenerator/FrameFeatureCollection.cs | 3 +- 23 files changed, 343 insertions(+), 218 deletions(-) create mode 100644 src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/CorrelationIdGenerator.cs rename src/{Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv => Microsoft.AspNetCore.Server.Kestrel.Core}/Internal/Infrastructure/KestrelEventSource.cs (59%) diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 1a78cbd21b..b5ff23e775 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -21,7 +21,24 @@ "build", "${workspaceRoot}/KestrelHttpServer.sln" ], - "problemMatcher": "$msCompile" + "problemMatcher": "$msCompile", + // these have to defined here because of https://github.com/Microsoft/vscode/issues/20740 + "osx": { + "options": { + "env": { + // The location of .NET Framework reference assembiles. + // These may not be installed yet if you have not run build.sh. + "ReferenceAssemblyRoot": "${env.HOME}/.nuget/packages/netframeworkreferenceassemblies/4.6.1/content" + } + } + }, + "linux": { + "options": { + "env": { + "ReferenceAssemblyRoot": "${env.HOME}/.nuget/packages/netframeworkreferenceassemblies/4.6.1/content" + } + } + } }, { "taskName": "Compile: CodeGenerator", diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/ConnectionHandler.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/ConnectionHandler.cs index 9a346f1805..933e04b8ab 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/ConnectionHandler.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/ConnectionHandler.cs @@ -1,25 +1,16 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System; using System.IO.Pipelines; -using System.Threading; using Microsoft.AspNetCore.Hosting.Server; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Transport; namespace Microsoft.AspNetCore.Server.Kestrel.Internal { public class ConnectionHandler : IConnectionHandler { - // Base32 encoding - in ascii sort order for easy text based sorting - private static readonly string _encode32Chars = "0123456789ABCDEFGHIJKLMNOPQRSTUV"; - - // Seed the _lastConnectionId for this application instance with - // the number of 100-nanosecond intervals that have elapsed since 12:00:00 midnight, January 1, 0001 - // for a roughly increasing _requestId over restarts - private static long _lastConnectionId = DateTime.UtcNow.Ticks; - private readonly ServiceContext _serviceContext; private readonly IHttpApplication _application; @@ -34,7 +25,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal var inputPipe = connectionInfo.PipeFactory.Create(GetInputPipeOptions(connectionInfo.InputWriterScheduler)); var outputPipe = connectionInfo.PipeFactory.Create(GetOutputPipeOptions(connectionInfo.OutputWriterScheduler)); - var connectionId = GenerateConnectionId(Interlocked.Increment(ref _lastConnectionId)); + var connectionId = CorrelationIdGenerator.GetNextId(); var frameContext = new FrameContext { @@ -60,6 +51,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal OutputProducer = outputProducer }); + _serviceContext.Log.ConnectionStart(connectionId); + KestrelEventSource.Log.ConnectionStart(connection, connectionInfo); + // Since data cannot be added to the inputPipe by the transport until OnConnection returns, // Frame.RequestProcessingAsync is guaranteed to unblock the transport thread before calling // application code. @@ -97,32 +91,5 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal // null means that we have no back pressure return bufferSize ?? 0; } - - private static unsafe string GenerateConnectionId(long id) - { - // The following routine is ~310% faster than calling long.ToString() on x64 - // and ~600% faster than calling long.ToString() on x86 in tight loops of 1 million+ iterations - // See: https://github.com/aspnet/Hosting/pull/385 - - // stackalloc to allocate array on stack rather than heap - char* charBuffer = stackalloc char[13]; - - charBuffer[0] = _encode32Chars[(int)(id >> 60) & 31]; - charBuffer[1] = _encode32Chars[(int)(id >> 55) & 31]; - charBuffer[2] = _encode32Chars[(int)(id >> 50) & 31]; - charBuffer[3] = _encode32Chars[(int)(id >> 45) & 31]; - charBuffer[4] = _encode32Chars[(int)(id >> 40) & 31]; - charBuffer[5] = _encode32Chars[(int)(id >> 35) & 31]; - charBuffer[6] = _encode32Chars[(int)(id >> 30) & 31]; - charBuffer[7] = _encode32Chars[(int)(id >> 25) & 31]; - charBuffer[8] = _encode32Chars[(int)(id >> 20) & 31]; - charBuffer[9] = _encode32Chars[(int)(id >> 15) & 31]; - charBuffer[10] = _encode32Chars[(int)(id >> 10) & 31]; - charBuffer[11] = _encode32Chars[(int)(id >> 5) & 31]; - charBuffer[12] = _encode32Chars[(int)id & 31]; - - // string ctor overload that takes char* - return new string(charBuffer, 0, 13); - } } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnection.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnection.cs index e601f5f0a7..af5454f581 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnection.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnection.cs @@ -73,6 +73,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal } } + public void OnConnectionClosed() + { + Log.ConnectionStop(ConnectionId); + KestrelEventSource.Log.ConnectionStop(this); + } + public async Task StopAsync() { await _frameStartedTcs.Task; diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.FeatureCollection.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.FeatureCollection.cs index bffde30a58..c1dada9715 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.FeatureCollection.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.FeatureCollection.cs @@ -19,7 +19,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http IHttpResponseFeature, IHttpUpgradeFeature, IHttpConnectionFeature, - IHttpRequestLifetimeFeature + IHttpRequestLifetimeFeature, + IHttpRequestIdentifierFeature { // NOTE: When feature interfaces are added to or removed from this Frame class implementation, // then the list of `implementedFeatures` in the generated code project MUST also be updated. @@ -75,188 +76,89 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http string IHttpRequestFeature.Protocol { - get - { - return HttpVersion; - } - - set - { - HttpVersion = value; - } + get => HttpVersion; + set => HttpVersion = value; } string IHttpRequestFeature.Scheme { - get - { - return Scheme ?? "http"; - } - - set - { - Scheme = value; - } + get => Scheme ?? "http"; + set => Scheme = value; } string IHttpRequestFeature.Method { - get - { - return Method; - } - - set - { - Method = value; - } + get => Method; + set => Method = value; } string IHttpRequestFeature.PathBase { - get - { - return PathBase ?? ""; - } - - set - { - PathBase = value; - } + get => PathBase ?? ""; + set => PathBase = value; } string IHttpRequestFeature.Path { - get - { - return Path; - } - - set - { - Path = value; - } + get => Path; + set => Path = value; } string IHttpRequestFeature.QueryString { - get - { - return QueryString; - } - - set - { - QueryString = value; - } + get => QueryString; + set => QueryString = value; } string IHttpRequestFeature.RawTarget { - get - { - return RawTarget; - } - set - { - RawTarget = value; - } + get => RawTarget; + set => RawTarget = value; } IHeaderDictionary IHttpRequestFeature.Headers { - get - { - return RequestHeaders; - } - - set - { - RequestHeaders = value; - } + get => RequestHeaders; + set => RequestHeaders = value; } Stream IHttpRequestFeature.Body { - get - { - return RequestBody; - } - - set - { - RequestBody = value; - } + get => RequestBody; + set => RequestBody = value; } int IHttpResponseFeature.StatusCode { - get - { - return StatusCode; - } - - set - { - StatusCode = value; - } + get => StatusCode; + set => StatusCode = value; } string IHttpResponseFeature.ReasonPhrase { - get - { - return ReasonPhrase; - } - - set - { - ReasonPhrase = value; - } + get => ReasonPhrase; + set => ReasonPhrase = value; } IHeaderDictionary IHttpResponseFeature.Headers { - get - { - return ResponseHeaders; - } - - set - { - ResponseHeaders = value; - } + get => ResponseHeaders; + set => ResponseHeaders = value; } Stream IHttpResponseFeature.Body { - get - { - return ResponseBody; - } - - set - { - ResponseBody = value; - } + get => ResponseBody; + set => ResponseBody = value; } CancellationToken IHttpRequestLifetimeFeature.RequestAborted { - get - { - return RequestAborted; - } - set - { - RequestAborted = value; - } + get => RequestAborted; + set => RequestAborted = value; } - bool IHttpResponseFeature.HasStarted - { - get { return HasResponseStarted; } - } + bool IHttpResponseFeature.HasStarted => HasResponseStarted; bool IHttpUpgradeFeature.IsUpgradableRequest => _upgrade; @@ -266,38 +168,44 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http IPAddress IHttpConnectionFeature.RemoteIpAddress { - get { return RemoteIpAddress; } - set { RemoteIpAddress = value; } + get => RemoteIpAddress; + set => RemoteIpAddress = value; } IPAddress IHttpConnectionFeature.LocalIpAddress { - get { return LocalIpAddress; } - set { LocalIpAddress = value; } + get => LocalIpAddress; + set => LocalIpAddress = value; } int IHttpConnectionFeature.RemotePort { - get { return RemotePort; } - set { RemotePort = value; } + get => RemotePort; + set => RemotePort = value; } int IHttpConnectionFeature.LocalPort { - get { return LocalPort; } - set { LocalPort = value; } + get => LocalPort; + set => LocalPort = value; } string IHttpConnectionFeature.ConnectionId { - get { return ConnectionIdFeature; } - set { ConnectionIdFeature = value; } + get => ConnectionIdFeature; + set => ConnectionIdFeature = value; + } + + string IHttpRequestIdentifierFeature.TraceIdentifier + { + get => TraceIdentifier; + set => TraceIdentifier = value; } object IFeatureCollection.this[Type key] { - get { return FastFeatureGet(key); } - set { FastFeatureSet(key, value); } + get => FastFeatureGet(key); + set => FastFeatureSet(key, value); } TFeature IFeatureCollection.Get() diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.Generated.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.Generated.cs index 160d110c54..a1caf15e33 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.Generated.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.Generated.cs @@ -47,10 +47,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _currentIHttpRequestFeature = this; _currentIHttpResponseFeature = this; _currentIHttpUpgradeFeature = this; + _currentIHttpRequestIdentifierFeature = this; _currentIHttpRequestLifetimeFeature = this; _currentIHttpConnectionFeature = this; - _currentIHttpRequestIdentifierFeature = null; _currentIServiceProvidersFeature = null; _currentIHttpAuthenticationFeature = null; _currentIQueryFeature = null; diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.cs index e91ca62917..e5b10948e2 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.cs @@ -69,6 +69,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http protected HttpVersion _httpVersion; + private string _requestId; private int _remainingRequestHeadersBytesAllowed; private int _requestHeadersParsed; @@ -112,6 +113,24 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http protected string ConnectionId => _frameContext.ConnectionId; public string ConnectionIdFeature { get; set; } + + /// + /// The request id. + /// + public string TraceIdentifier + { + set => _requestId = value; + get + { + // don't generate an ID until it is requested + if (_requestId == null) + { + _requestId = CorrelationIdGenerator.GetNextId(); + } + return _requestId; + } + } + public IPAddress RemoteIpAddress { get; set; } public int RemotePort { get; set; } public IPAddress LocalIpAddress { get; set; } @@ -341,6 +360,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http ResetFeatureCollection(); + TraceIdentifier = null; Scheme = null; Method = null; PathBase = null; @@ -417,7 +437,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } catch (Exception ex) { - Log.ApplicationError(ConnectionId, ex); + Log.ApplicationError(ConnectionId, TraceIdentifier, ex); } } @@ -1196,7 +1216,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _applicationException = new AggregateException(_applicationException, ex); } - Log.ApplicationError(ConnectionId, ex); + Log.ApplicationError(ConnectionId, TraceIdentifier, ex); } public void OnStartLine(HttpMethod method, HttpVersion version, Span target, Span path, Span query, Span customMethod, bool pathEncoded) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameOfT.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameOfT.cs index 9fdb0497ac..dbf6a629e2 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameOfT.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameOfT.cs @@ -6,6 +6,7 @@ using System.IO; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Hosting.Server; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Transport.Exceptions; using Microsoft.Extensions.Logging; @@ -95,6 +96,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { try { + KestrelEventSource.Log.RequestStart(this); + await _application.ProcessRequestAsync(context).ConfigureAwait(false); if (Volatile.Read(ref _requestAborted) == 0) @@ -113,6 +116,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } finally { + KestrelEventSource.Log.RequestStop(this); + // Trigger OnStarting if it hasn't been called yet and the app hasn't // already failed. If an OnStarting callback throws we can go through // our normal error handling in ProduceEnd. diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/CorrelationIdGenerator.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/CorrelationIdGenerator.cs new file mode 100644 index 0000000000..81233b3a3f --- /dev/null +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/CorrelationIdGenerator.cs @@ -0,0 +1,48 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Threading; + +namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure +{ + internal static class CorrelationIdGenerator + { + // Base32 encoding - in ascii sort order for easy text based sorting + private static readonly string _encode32Chars = "0123456789ABCDEFGHIJKLMNOPQRSTUV"; + + // Seed the _lastConnectionId for this application instance with + // the number of 100-nanosecond intervals that have elapsed since 12:00:00 midnight, January 1, 0001 + // for a roughly increasing _lastId over restarts + private static long _lastId = DateTime.UtcNow.Ticks; + + public static string GetNextId() => GenerateId(Interlocked.Increment(ref _lastId)); + + private static unsafe string GenerateId(long id) + { + // The following routine is ~310% faster than calling long.ToString() on x64 + // and ~600% faster than calling long.ToString() on x86 in tight loops of 1 million+ iterations + // See: https://github.com/aspnet/Hosting/pull/385 + + // stackalloc to allocate array on stack rather than heap + char* charBuffer = stackalloc char[13]; + + charBuffer[0] = _encode32Chars[(int)(id >> 60) & 31]; + charBuffer[1] = _encode32Chars[(int)(id >> 55) & 31]; + charBuffer[2] = _encode32Chars[(int)(id >> 50) & 31]; + charBuffer[3] = _encode32Chars[(int)(id >> 45) & 31]; + charBuffer[4] = _encode32Chars[(int)(id >> 40) & 31]; + charBuffer[5] = _encode32Chars[(int)(id >> 35) & 31]; + charBuffer[6] = _encode32Chars[(int)(id >> 30) & 31]; + charBuffer[7] = _encode32Chars[(int)(id >> 25) & 31]; + charBuffer[8] = _encode32Chars[(int)(id >> 20) & 31]; + charBuffer[9] = _encode32Chars[(int)(id >> 15) & 31]; + charBuffer[10] = _encode32Chars[(int)(id >> 10) & 31]; + charBuffer[11] = _encode32Chars[(int)(id >> 5) & 31]; + charBuffer[12] = _encode32Chars[(int)id & 31]; + + // string ctor overload that takes char* + return new string(charBuffer, 0, 13); + } + } +} diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/IKestrelTrace.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/IKestrelTrace.cs index ff622fa69b..5e744b678e 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/IKestrelTrace.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/IKestrelTrace.cs @@ -45,6 +45,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure void NotAllConnectionsAborted(); - void ApplicationError(string connectionId, Exception ex); + void ApplicationError(string connectionId, string traceIdentifier, Exception ex); } } \ No newline at end of file diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Infrastructure/KestrelEventSource.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/KestrelEventSource.cs similarity index 59% rename from src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Infrastructure/KestrelEventSource.cs rename to src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/KestrelEventSource.cs index 552b65ff33..84d7702503 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Infrastructure/KestrelEventSource.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/KestrelEventSource.cs @@ -4,6 +4,7 @@ using System.Diagnostics.Tracing; using System.Runtime.CompilerServices; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Transport; namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure { @@ -25,16 +26,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure // - Avoid renaming methods or parameters marked with EventAttribute. EventSource uses these to form the event object. [NonEvent] - public void ConnectionStart(Connection connection) + public void ConnectionStart(IConnectionContext context, IConnectionInformation information) { // avoid allocating strings unless this event source is enabled if (IsEnabled()) { ConnectionStart( - connection.ConnectionId, - connection.ListenerContext.ListenOptions.Scheme, - connection.LocalEndPoint.ToString(), - connection.RemoteEndPoint.ToString()); + context.ConnectionId, + information.ListenOptions.Scheme, + information.LocalEndPoint.ToString(), + information.RemoteEndPoint.ToString()); } } @@ -55,7 +56,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure } [NonEvent] - public void ConnectionStop(Connection connection) + public void ConnectionStop(IConnectionContext connection) { if (IsEnabled()) { @@ -69,5 +70,39 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure { WriteEvent(2, connectionId); } + + [NonEvent] + public void RequestStart(Frame frame) + { + // avoid allocating the trace identifier unless logging is enabled + if (IsEnabled()) + { + RequestStart(frame.ConnectionIdFeature, frame.TraceIdentifier); + } + } + + [MethodImpl(MethodImplOptions.NoInlining)] + [Event(3, Level = EventLevel.Verbose)] + private void RequestStart(string connectionId, string requestId) + { + WriteEvent(3, connectionId, requestId); + } + + [NonEvent] + public void RequestStop(Frame frame) + { + // avoid allocating the trace identifier unless logging is enabled + if (IsEnabled()) + { + RequestStop(frame.ConnectionIdFeature, frame.TraceIdentifier); + } + } + + [MethodImpl(MethodImplOptions.NoInlining)] + [Event(4, Level = EventLevel.Verbose)] + private void RequestStop(string connectionId, string requestId) + { + WriteEvent(4, connectionId, requestId); + } } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/KestrelTrace.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/KestrelTrace.cs index 94f85518b6..50cd3c3f0a 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/KestrelTrace.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/KestrelTrace.cs @@ -45,8 +45,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal // ConnectionWriteCallback: Reserved: 12 - private static readonly Action _applicationError = - LoggerMessage.Define(LogLevel.Error, 13, @"Connection id ""{ConnectionId}"": An unhandled exception was thrown by the application."); + private static readonly Action _applicationError = + LoggerMessage.Define(LogLevel.Error, 13, @"Connection id ""{ConnectionId}"", Request id ""{TraceIdentifier}"": An unhandled exception was thrown by the application."); private static readonly Action _connectionError = LoggerMessage.Define(LogLevel.Information, 14, @"Connection id ""{ConnectionId}"" communication error."); @@ -142,9 +142,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal // Reserved: Event ID 12 } - public virtual void ApplicationError(string connectionId, Exception ex) + public virtual void ApplicationError(string connectionId, string traceIdentifier, Exception ex) { - _applicationError(_logger, connectionId, ex); + _applicationError(_logger, connectionId, traceIdentifier, ex); } public virtual void ConnectionError(string connectionId, Exception ex) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Transport/IConnectionContext.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Transport/IConnectionContext.cs index 3e1b19119a..1ef633d445 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Transport/IConnectionContext.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Transport/IConnectionContext.cs @@ -14,6 +14,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport IPipeReader Output { get; } // TODO: Remove these (Use Pipes instead?) + void OnConnectionClosed(); Task StopAsync(); void Abort(Exception ex); void Timeout(); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Http/Connection.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Http/Connection.cs index 8cf743bbdd..bff2e1021a 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Http/Connection.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Http/Connection.cs @@ -71,9 +71,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _connectionContext = ConnectionHandler.OnConnection(this); ConnectionId = _connectionContext.ConnectionId; - Log.ConnectionStart(ConnectionId); - KestrelEventSource.Log.ConnectionStart(this); - Input = _connectionContext.Input; Output = new SocketOutputConsumer(_connectionContext.Output, Thread, _socket, this, ConnectionId, Log); @@ -82,7 +79,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http _lastTimestamp = Thread.Loop.Now(); // This *must* happen after socket.ReadStart - // The socket output consumer is the only thing that can close the connection. If the + // The socket output consumer is the only thing that can close the connection. If the // output pipe is already closed by the time we start then it's fine since, it'll close gracefully afterwards. var ignore = Output.StartWrites(); } @@ -109,9 +106,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { _socket.Dispose(); - Log.ConnectionStop(ConnectionId); - - KestrelEventSource.Log.ConnectionStop(this); + _connectionContext.OnConnectionClosed(); Input.Complete(new TaskCanceledException("The request was aborted")); _socketClosedTcs.TrySetResult(null); diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/EventSourceTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/EventSourceTests.cs index 40610fe4c3..74180ccbab 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/EventSourceTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/EventSourceTests.cs @@ -27,10 +27,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests public async Task EmitsConnectionStartAndStop() { string connectionId = null; + string requestId = null; int port; using (var server = new TestServer(context => { connectionId = context.Features.Get().ConnectionId; + requestId = context.TraceIdentifier; return Task.CompletedTask; })) { @@ -47,16 +49,33 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests // capture list here as other tests executing in parallel may log events Assert.NotNull(connectionId); + Assert.NotNull(requestId); + var events = _listener.EventData.Where(e => e != null && GetProperty(e, "connectionId") == connectionId).ToList(); - var start = Assert.Single(events, e => e.EventName == "ConnectionStart"); - Assert.All(new[] { "connectionId", "scheme", "remoteEndPoint", "localEndPoint" }, p => Assert.Contains(p, start.PayloadNames)); - Assert.Equal("http", GetProperty(start, "scheme")); - Assert.Equal($"127.0.0.1:{port}", GetProperty(start, "localEndPoint")); - - var stop = Assert.Single(events, e => e.EventName == "ConnectionStop"); - Assert.All(new[] { "connectionId" }, p => Assert.Contains(p, stop.PayloadNames)); - Assert.Same(KestrelEventSource.Log, stop.EventSource); + { + var start = Assert.Single(events, e => e.EventName == "ConnectionStart"); + Assert.All(new[] { "connectionId", "scheme", "remoteEndPoint", "localEndPoint" }, p => Assert.Contains(p, start.PayloadNames)); + Assert.Equal("http", GetProperty(start, "scheme")); + Assert.Equal($"127.0.0.1:{port}", GetProperty(start, "localEndPoint")); + } + { + var stop = Assert.Single(events, e => e.EventName == "ConnectionStop"); + Assert.All(new[] { "connectionId" }, p => Assert.Contains(p, stop.PayloadNames)); + Assert.Same(KestrelEventSource.Log, stop.EventSource); + } + { + var requestStart = Assert.Single(events, e => e.EventName == "RequestStart"); + Assert.All(new[] { "connectionId", "requestId" }, p => Assert.Contains(p, requestStart.PayloadNames)); + Assert.Equal(requestId, GetProperty(requestStart, "requestId")); + Assert.Same(KestrelEventSource.Log, requestStart.EventSource); + } + { + var requestStop = Assert.Single(events, e => e.EventName == "RequestStop"); + Assert.All(new[] { "connectionId", "requestId" }, p => Assert.Contains(p, requestStop.PayloadNames)); + Assert.Equal(requestId, GetProperty(requestStop, "requestId")); + Assert.Same(KestrelEventSource.Log, requestStop.EventSource); + } } private string GetProperty(EventWrittenEventArgs data, string propName) diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs index 6b9007c6d3..9dc073f100 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Collections.Concurrent; using System.Globalization; using System.IO; using System.Net; @@ -566,6 +567,72 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } } + [Fact] + public async Task AppCanSetTraceIdentifier() + { + const string knownId = "xyz123"; + using (var server = new TestServer(async context => + { + context.TraceIdentifier = knownId; + await context.Response.WriteAsync(context.TraceIdentifier); + })) + { + var requestId = await HttpClientSlim.GetStringAsync($"http://{server.EndPoint}") + .TimeoutAfter(TimeSpan.FromSeconds(10)); + Assert.Equal(knownId, requestId); + } + } + + [Fact] + public async Task TraceIdentifierIsUnique() + { + const int IdentifierLength = 13; + const int iterations = 10; + + using (var server = new TestServer(async context => + { + Assert.Equal(IdentifierLength, Encoding.ASCII.GetByteCount(context.TraceIdentifier)); + context.Response.ContentLength = IdentifierLength; + await context.Response.WriteAsync(context.TraceIdentifier); + })) + { + var usedIds = new ConcurrentBag(); + var uri = $"http://{server.EndPoint}"; + + // requests on separate connections in parallel + Parallel.For(0, iterations, async i => + { + var id = await HttpClientSlim.GetStringAsync(uri); + Assert.DoesNotContain(id, usedIds.ToArray()); + usedIds.Add(id); + }); + + // requests on same connection + using (var connection = server.CreateConnection()) + { + var buffer = new char[IdentifierLength]; + for (var i = 0; i < iterations; i++) + { + await connection.Send("GET / HTTP/1.1", + "", + ""); + + await connection.Receive($"HTTP/1.1 200 OK", + $"Date: {server.Context.DateHeaderValue}", + $"Content-Length: {IdentifierLength}", + "", + "").TimeoutAfter(TimeSpan.FromSeconds(10)); + + var read = await connection.Reader.ReadAsync(buffer, 0, IdentifierLength); + Assert.Equal(IdentifierLength, read); + var id = new string(buffer, 0, read); + Assert.DoesNotContain(id, usedIds.ToArray()); + usedIds.Add(id); + } + } + } + } + private async Task TestRemoteIPAddress(string registerAddress, string requestAddress, string expectAddress) { var builder = new WebHostBuilder() @@ -603,4 +670,4 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } } } -} \ No newline at end of file +} diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs index 1e8fd21746..2b2854df79 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs @@ -635,8 +635,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests var logTcs = new TaskCompletionSource(); var mockTrace = new Mock(); mockTrace - .Setup(trace => trace.ApplicationError(It.IsAny(), It.IsAny())) - .Callback((connectionId, ex) => + .Setup(trace => trace.ApplicationError(It.IsAny(), It.IsAny(), It.IsAny())) + .Callback((connectionId, requestId, ex) => { logTcs.SetResult(null); }); @@ -675,6 +675,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests mockTrace.Verify(trace => trace.ApplicationError( + It.IsAny(), It.IsAny(), It.Is(ex => ex.Message.Equals($"Response Content-Length mismatch: too few bytes written (12 of 13).", StringComparison.Ordinal)))); @@ -724,7 +725,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } // With the server disposed we know all connections were drained and all messages were logged. - mockTrace.Verify(trace => trace.ApplicationError(It.IsAny(), It.IsAny()), Times.Never); + mockTrace.Verify(trace => trace.ApplicationError(It.IsAny(), It.IsAny(), It.IsAny()), Times.Never); } [Fact] diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Mocks/MockTrace.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Mocks/MockTrace.cs index f7737a63f9..915c4805d1 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Mocks/MockTrace.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Mocks/MockTrace.cs @@ -9,7 +9,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance { public class MockTrace : IKestrelTrace { - public void ApplicationError(string connectionId, Exception ex) { } + public void ApplicationError(string connectionId, string requestId, Exception ex) { } public IDisposable BeginScope(TState state) => null; public void ConnectionBadRequest(string connectionId, BadHttpRequestException ex) { } public void ConnectionDisconnect(string connectionId) { } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs index 9e0a068f16..70f63f8a72 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs @@ -123,6 +123,33 @@ namespace Microsoft.AspNetCore.Server.KestrelTests Assert.Equal("http", ((IFeatureCollection)_frame).Get().Scheme); } + [Fact] + public void ResetResetsTraceIdentifier() + { + _frame.TraceIdentifier = "xyz"; + + _frame.Reset(); + + var nextId = ((IFeatureCollection)_frame).Get().TraceIdentifier; + Assert.NotEqual("xyz", nextId); + + _frame.Reset(); + var secondId = ((IFeatureCollection)_frame).Get().TraceIdentifier; + Assert.NotEqual(nextId, secondId); + } + + [Fact] + public void TraceIdentifierGeneratesWhenNull() + { + _frame.TraceIdentifier = null; + var id = _frame.TraceIdentifier; + Assert.NotNull(id); + Assert.Equal(id, _frame.TraceIdentifier); + + _frame.TraceIdentifier = null; + Assert.NotEqual(id, _frame.TraceIdentifier); + } + [Fact] public async Task ResetResetsHeaderLimits() { diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelEventSourceTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelEventSourceTests.cs index 1d5c1fdd81..97a38802b6 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelEventSourceTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelEventSourceTests.cs @@ -4,7 +4,7 @@ using System; using System.Diagnostics.Tracing; using System.Reflection; -using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv; +using Microsoft.AspNetCore.Server.Kestrel; using Xunit; namespace Microsoft.AspNetCore.Server.KestrelTests @@ -14,7 +14,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [Fact] public void ExistsWithCorrectId() { - var esType = typeof(LibuvTransportFactory).GetTypeInfo().Assembly.GetType( + var esType = typeof(KestrelServer).GetTypeInfo().Assembly.GetType( "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.KestrelEventSource", throwOnError: true, ignoreCase: false @@ -27,4 +27,4 @@ namespace Microsoft.AspNetCore.Server.KestrelTests Assert.NotEmpty(EventSource.GenerateManifest(esType, "assemblyPathToIncludeInManifest")); } } -} \ No newline at end of file +} diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockConnectionHandler.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockConnectionHandler.cs index 6df2d283de..f50f3572c6 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockConnectionHandler.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockConnectionHandler.cs @@ -47,6 +47,11 @@ namespace Microsoft.AspNetCore.Server.KestrelTests.TestHelpers public IPipeWriter Input { get; set; } public IPipeReader Output { get; set; } + public void OnConnectionClosed() + { + throw new NotImplementedException(); + } + public Task StopAsync() { throw new NotImplementedException(); diff --git a/test/shared/TestConnection.cs b/test/shared/TestConnection.cs index aef4561448..33016bd473 100644 --- a/test/shared/TestConnection.cs +++ b/test/shared/TestConnection.cs @@ -32,6 +32,8 @@ namespace Microsoft.AspNetCore.Testing Create(port, addressFamily); } + public StreamReader Reader => _reader; + public void Create(int port, AddressFamily addressFamily) { _socket = CreateConnectedLoopbackSocket(port, addressFamily); diff --git a/test/shared/TestServer.cs b/test/shared/TestServer.cs index bf72cd0486..3763c61c53 100644 --- a/test/shared/TestServer.cs +++ b/test/shared/TestServer.cs @@ -59,6 +59,7 @@ namespace Microsoft.AspNetCore.Testing } } + public IPEndPoint EndPoint => _listenOptions.IPEndPoint; public int Port => _listenOptions.IPEndPoint.Port; public AddressFamily AddressFamily => _listenOptions.IPEndPoint.AddressFamily; diff --git a/tools/CodeGenerator/FrameFeatureCollection.cs b/tools/CodeGenerator/FrameFeatureCollection.cs index 22e6a9316b..6c85665fe9 100644 --- a/tools/CodeGenerator/FrameFeatureCollection.cs +++ b/tools/CodeGenerator/FrameFeatureCollection.cs @@ -61,8 +61,9 @@ namespace CodeGenerator typeof(IHttpRequestFeature), typeof(IHttpResponseFeature), typeof(IHttpUpgradeFeature), + typeof(IHttpRequestIdentifierFeature), typeof(IHttpRequestLifetimeFeature), - typeof(IHttpConnectionFeature) + typeof(IHttpConnectionFeature), }; return $@"// Copyright (c) .NET Foundation. All rights reserved. From 547ad80a272c94861453ae50daaa5f9addb0cc8f Mon Sep 17 00:00:00 2001 From: David Fowler Date: Sun, 2 Apr 2017 00:03:06 -0700 Subject: [PATCH 1170/1662] Don't update consumed if we didn't see a new line (#1592) * Don't update consumed if we didn't see a new line - The start line parser incorrectly updated the consumed cursor when it attempted to find new lines across buffers. This change fixes that and also removes passing the span by reference (which will be illegal). - Added a unit test --- .../Internal/Http/KestrelHttpParser.cs | 20 +++++++++++++------ .../HttpParserTests.cs | 15 ++++++++++++++ 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/KestrelHttpParser.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/KestrelHttpParser.cs index 581281ca43..ef8d48951c 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/KestrelHttpParser.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/KestrelHttpParser.cs @@ -41,7 +41,17 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http consumed = buffer.Move(consumed, lineIndex + 1); span = span.Slice(0, lineIndex + 1); } - else if (buffer.IsSingleSpan || !TryGetNewLineSpan(ref buffer, ref span, out consumed)) + else if (buffer.IsSingleSpan) + { + // No request line end + return false; + } + else if (TryGetNewLine(ref buffer, out var found)) + { + span = buffer.Slice(consumed, found).ToSpan(); + consumed = found; + } + else { // No request line end return false; @@ -429,16 +439,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http return true; } - [MethodImpl(MethodImplOptions.NoInlining)] - private static bool TryGetNewLineSpan(ref ReadableBuffer buffer, ref Span span, out ReadCursor end) + private static bool TryGetNewLine(ref ReadableBuffer buffer, out ReadCursor found) { var start = buffer.Start; - if (ReadCursorOperations.Seek(start, buffer.End, out end, ByteLF) != -1) + if (ReadCursorOperations.Seek(start, buffer.End, out found, ByteLF) != -1) { // Move 1 byte past the \n - end = buffer.Move(end, 1); - span = buffer.Slice(start, end).ToSpan(); + found = buffer.Move(found, 1); return true; } return false; diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/HttpParserTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/HttpParserTests.cs index 0f269514ba..99daa1a53d 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/HttpParserTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/HttpParserTests.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using System.IO.Pipelines; +using System.IO.Pipelines.Testing; using System.Linq; using System.Text; using Microsoft.AspNetCore.Http; @@ -365,6 +366,20 @@ namespace Microsoft.AspNetCore.Server.KestrelTests Assert.Equal(StatusCodes.Status400BadRequest, exception.StatusCode); } + [Fact] + public void ParseRequestLineSplitBufferWithoutNewLineDoesNotUpdateConsumed() + { + var parser = CreateParser(Mock.Of()); + var buffer = BufferUtilities.CreateBuffer("GET ", "/"); + + var requestHandler = new RequestHandler(); + var result = parser.ParseRequestLine(requestHandler, buffer, out var consumed, out var examined); + + Assert.False(result); + Assert.Equal(buffer.Start, consumed); + Assert.Equal(buffer.End, examined); + } + private void VerifyHeader( string headerName, string rawHeaderValue, From f787c5277c965dd7c761497a56192283cdd9b97c Mon Sep 17 00:00:00 2001 From: David Fowler Date: Sun, 2 Apr 2017 23:53:49 -0700 Subject: [PATCH 1171/1662] Remove unused span (#1599) --- .../Internal/Http/KestrelHttpParser.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/KestrelHttpParser.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/KestrelHttpParser.cs index ef8d48951c..b78d04b69c 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/KestrelHttpParser.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/KestrelHttpParser.cs @@ -181,8 +181,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http RejectRequestLine(data, length); } - var line = new Span(data, length); - handler.OnStartLine(method, httpVersion, targetBuffer, pathBuffer, query, customMethod, pathEncoded); } From 13ee32b7ab3325ea9a384c99444834df8a7a5acd Mon Sep 17 00:00:00 2001 From: Pavel Krymets Date: Mon, 3 Apr 2017 13:21:17 -0700 Subject: [PATCH 1172/1662] Fetch corefx lab sources and compile them into kestrel (#1581) --- .gitmodules | 3 + KestrelHttpServer.sln | 15 +++ build/corefxlab.props | 14 +++ build/dependencies.props | 1 + build/repo.targets | 19 +++ corefxlab | 1 + .../Adapter/Internal/AdaptedPipeline.cs | 2 +- .../Adapter/Internal/RawStream.cs | 2 +- .../Adapter/Internal/StreamSocketOutput.cs | 2 +- .../Internal/ConnectionHandler.cs | 2 +- .../Internal/FrameConnection.cs | 2 +- .../Internal/FrameConnectionContext.cs | 2 +- .../Internal/Http/ChunkWriter.cs | 2 +- .../Http/ConnectionLifetimeControl.cs | 2 +- .../Internal/Http/Frame.cs | 6 +- .../Internal/Http/FrameHeaders.Generated.cs | 3 +- .../Internal/Http/FrameResponseHeaders.cs | 2 +- .../Internal/Http/IHttpParser.cs | 2 +- .../Internal/Http/ISocketOutput.cs | 2 +- .../Internal/Http/KestrelHttpParser.cs | 2 +- .../Internal/Http/MessageBody.cs | 2 +- .../Internal/Http/PipelineExtensions.cs | 4 +- .../Internal/Http/SocketOutputProducer.cs | 2 +- .../Internal/Infrastructure/IThreadPool.cs | 2 +- ...soft.AspNetCore.Server.Kestrel.Core.csproj | 11 +- .../Transport/IConnectionContext.cs | 2 +- .../Transport/IConnectionInformation.cs | 2 +- .../Internal/Http/Connection.cs | 2 +- .../Internal/Http/ConnectionContext.cs | 2 +- .../Internal/Http/SocketOutputConsumer.cs | 2 +- .../Internal/Infrastructure/KestrelThread.cs | 2 +- .../Internal/Networking/UvWriteReq.cs | 3 +- .../DotSegmentRemovalBenchmark.cs | 6 +- .../FrameParsingOverheadBenchmark.cs | 2 +- .../FrameWritingBenchmark.cs | 2 +- .../KestrelHttpParserBenchmark.cs | 2 +- .../Mocks/MockConnectionInformation.cs | 2 +- .../PipeThroughputBenchmark.cs | 2 +- .../RequestParsingBenchmark.cs | 2 +- .../ResponseHeadersWritingBenchmark.cs | 2 +- .../FrameResponseHeadersTests.cs | 2 +- .../FrameTests.cs | 2 +- .../HttpParserTests.cs | 4 +- .../MultipleLoopTests.cs | 2 +- .../NetworkingTests.cs | 2 +- .../PipeOptionsTests.cs | 2 +- .../PipelineExtensionTests.cs | 2 +- .../SocketOutputTests.cs | 2 +- .../StreamSocketOutputTests.cs | 2 +- .../TestHelpers/MockConnectionHandler.cs | 2 +- .../TestInput.cs | 2 +- test/shared/MockSocketOutput.cs | 2 +- tools/CodeGenerator/KnownHeaders.cs | 3 +- tools/Internalizer/Internalizer.csproj | 7 ++ tools/Internalizer/Program.cs | 108 ++++++++++++++++++ 55 files changed, 229 insertions(+), 57 deletions(-) create mode 100644 .gitmodules create mode 100644 build/corefxlab.props create mode 160000 corefxlab create mode 100644 tools/Internalizer/Internalizer.csproj create mode 100644 tools/Internalizer/Program.cs diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000000..af6855653f --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "corefxlab"] + path = corefxlab + url = https://github.com/dotnet/corefxlab diff --git a/KestrelHttpServer.sln b/KestrelHttpServer.sln index 24a8e79020..820b9e6e27 100644 --- a/KestrelHttpServer.sln +++ b/KestrelHttpServer.sln @@ -65,6 +65,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Server EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Server.Kestrel", "src\Microsoft.AspNetCore.Server.Kestrel\Microsoft.AspNetCore.Server.Kestrel.csproj", "{56139957-5C29-4E7D-89BD-7D20598B4EAF}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Internalizer", "tools\Internalizer\Internalizer.csproj", "{6B04EAAA-08DE-464B-92DB-1D32BB86892C}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -195,6 +197,18 @@ Global {56139957-5C29-4E7D-89BD-7D20598B4EAF}.Release|x64.Build.0 = Release|Any CPU {56139957-5C29-4E7D-89BD-7D20598B4EAF}.Release|x86.ActiveCfg = Release|Any CPU {56139957-5C29-4E7D-89BD-7D20598B4EAF}.Release|x86.Build.0 = Release|Any CPU + {6B04EAAA-08DE-464B-92DB-1D32BB86892C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {6B04EAAA-08DE-464B-92DB-1D32BB86892C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {6B04EAAA-08DE-464B-92DB-1D32BB86892C}.Debug|x64.ActiveCfg = Debug|Any CPU + {6B04EAAA-08DE-464B-92DB-1D32BB86892C}.Debug|x64.Build.0 = Debug|Any CPU + {6B04EAAA-08DE-464B-92DB-1D32BB86892C}.Debug|x86.ActiveCfg = Debug|Any CPU + {6B04EAAA-08DE-464B-92DB-1D32BB86892C}.Debug|x86.Build.0 = Debug|Any CPU + {6B04EAAA-08DE-464B-92DB-1D32BB86892C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {6B04EAAA-08DE-464B-92DB-1D32BB86892C}.Release|Any CPU.Build.0 = Release|Any CPU + {6B04EAAA-08DE-464B-92DB-1D32BB86892C}.Release|x64.ActiveCfg = Release|Any CPU + {6B04EAAA-08DE-464B-92DB-1D32BB86892C}.Release|x64.Build.0 = Release|Any CPU + {6B04EAAA-08DE-464B-92DB-1D32BB86892C}.Release|x86.ActiveCfg = Release|Any CPU + {6B04EAAA-08DE-464B-92DB-1D32BB86892C}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -212,5 +226,6 @@ Global {2822C132-BFFB-4D53-AC5B-E7E47DD81A6E} = {0EF2ACDF-012F-4472-A13A-4272419E2903} {A76B8C8C-0DC5-4DD3-9B1F-02E51A0915F4} = {2D5D5227-4DBD-499A-96B1-76A36B03B750} {56139957-5C29-4E7D-89BD-7D20598B4EAF} = {2D5D5227-4DBD-499A-96B1-76A36B03B750} + {6B04EAAA-08DE-464B-92DB-1D32BB86892C} = {327F7880-D9AF-46BD-B45C-3B7E34A01DFD} EndGlobalSection EndGlobal diff --git a/build/corefxlab.props b/build/corefxlab.props new file mode 100644 index 0000000000..f44b11a994 --- /dev/null +++ b/build/corefxlab.props @@ -0,0 +1,14 @@ + + + + $(MSBuildThisFileDirectory)..\corefxlab\ + + + + + + + + + + diff --git a/build/dependencies.props b/build/dependencies.props index ac2690b701..9601cfeacf 100644 --- a/build/dependencies.props +++ b/build/dependencies.props @@ -4,6 +4,7 @@ 0.1.0-* 0.1.0-* 4.3.0 + 4.4.0-* 2.0.0-* 1.10.0-* 9.0.1 diff --git a/build/repo.targets b/build/repo.targets index d05edf3572..81a19d46b8 100644 --- a/build/repo.targets +++ b/build/repo.targets @@ -1,5 +1,24 @@ + + Internalize;$(CompileDependsOn) + + + + + + + + + + + + $(MSBuildThisFileDirectory)..\artifacts\corefxlabfiles.txt + + + + + diff --git a/corefxlab b/corefxlab new file mode 160000 index 0000000000..5afdb0ea1f --- /dev/null +++ b/corefxlab @@ -0,0 +1 @@ +Subproject commit 5afdb0ea1fb6842ef9662ed8ab9890a0e1d3c3b9 diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/Internal/AdaptedPipeline.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/Internal/AdaptedPipeline.cs index 54674ae5d4..4a1087976a 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/Internal/AdaptedPipeline.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/Internal/AdaptedPipeline.cs @@ -3,9 +3,9 @@ using System; using System.IO; -using System.IO.Pipelines; using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; namespace Microsoft.AspNetCore.Server.Kestrel.Adapter.Internal { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/Internal/RawStream.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/Internal/RawStream.cs index 6e21958576..c47e0a9369 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/Internal/RawStream.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/Internal/RawStream.cs @@ -3,10 +3,10 @@ using System; using System.IO; -using System.IO.Pipelines; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; namespace Microsoft.AspNetCore.Server.Kestrel.Adapter.Internal { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/Internal/StreamSocketOutput.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/Internal/StreamSocketOutput.cs index 11da4bc24b..7ec74cc6b7 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/Internal/StreamSocketOutput.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/Internal/StreamSocketOutput.cs @@ -3,10 +3,10 @@ using System; using System.IO; -using System.IO.Pipelines; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; namespace Microsoft.AspNetCore.Server.Kestrel.Adapter.Internal { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/ConnectionHandler.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/ConnectionHandler.cs index 933e04b8ab..265b7d7c33 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/ConnectionHandler.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/ConnectionHandler.cs @@ -1,10 +1,10 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System.IO.Pipelines; using Microsoft.AspNetCore.Hosting.Server; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; using Microsoft.AspNetCore.Server.Kestrel.Transport; namespace Microsoft.AspNetCore.Server.Kestrel.Internal diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnection.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnection.cs index af5454f581..fb5cb169c1 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnection.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnection.cs @@ -4,12 +4,12 @@ using System; using System.Collections.Generic; using System.IO; -using System.IO.Pipelines; using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Adapter; using Microsoft.AspNetCore.Server.Kestrel.Adapter.Internal; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; using Microsoft.AspNetCore.Server.Kestrel.Transport; using Microsoft.Extensions.Internal; using Microsoft.Extensions.Logging; diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnectionContext.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnectionContext.cs index 271c009385..a2dc0a1ec9 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnectionContext.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnectionContext.cs @@ -2,9 +2,9 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Collections.Generic; -using System.IO.Pipelines; using Microsoft.AspNetCore.Server.Kestrel.Adapter; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; namespace Microsoft.AspNetCore.Server.Kestrel.Internal { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/ChunkWriter.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/ChunkWriter.cs index 6ffbc577b9..80bd99a610 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/ChunkWriter.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/ChunkWriter.cs @@ -2,8 +2,8 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.IO.Pipelines; using System.Text; +using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/ConnectionLifetimeControl.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/ConnectionLifetimeControl.cs index ae7d98ba3f..7b794a5d3a 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/ConnectionLifetimeControl.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/ConnectionLifetimeControl.cs @@ -1,8 +1,8 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System.IO.Pipelines; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.cs index e5b10948e2..9c26aadb11 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.cs @@ -5,17 +5,17 @@ using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; -using System.IO.Pipelines; using System.Linq; using System.Net; using System.Runtime.CompilerServices; using System.Text; -using System.Text.Encodings.Web.Utf8; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Server.Kestrel.Adapter; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; +using Microsoft.AspNetCore.Server.Kestrel.Internal.System.Text.Encodings.Web.Utf8; using Microsoft.AspNetCore.Server.Kestrel.Transport; using Microsoft.Extensions.Internal; using Microsoft.Extensions.Logging; @@ -987,7 +987,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http responseHeaders.SetRawDate(dateHeaderValues.String, dateHeaderValues.Bytes); } - Output.Write(_writeHeaders, this); + Output.Write(_writeHeaders, this); } private static void WriteResponseHeaders(WritableBuffer writableBuffer, Frame frame) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameHeaders.Generated.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameHeaders.Generated.cs index 8cc1ad75bd..10d7f2b9a5 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameHeaders.Generated.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameHeaders.Generated.cs @@ -3,8 +3,7 @@ using System; using System.Collections.Generic; -using System.IO.Pipelines; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; using Microsoft.Extensions.Primitives; using Microsoft.Net.Http.Headers; diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameResponseHeaders.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameResponseHeaders.cs index 9fc752f6cd..ca69a0e26c 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameResponseHeaders.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameResponseHeaders.cs @@ -4,8 +4,8 @@ using System; using System.Collections; using System.Collections.Generic; -using System.IO.Pipelines; using System.Runtime.CompilerServices; +using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; using Microsoft.Extensions.Primitives; using Microsoft.Net.Http.Headers; diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/IHttpParser.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/IHttpParser.cs index ee888bea1f..a76ff2ed4b 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/IHttpParser.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/IHttpParser.cs @@ -1,7 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System.IO.Pipelines; +using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/ISocketOutput.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/ISocketOutput.cs index 379dd52318..c5fe3ef28c 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/ISocketOutput.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/ISocketOutput.cs @@ -2,9 +2,9 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.IO.Pipelines; using System.Threading; using System.Threading.Tasks; +using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/KestrelHttpParser.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/KestrelHttpParser.cs index b78d04b69c..d677d35697 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/KestrelHttpParser.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/KestrelHttpParser.cs @@ -2,10 +2,10 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.IO.Pipelines; using System.Numerics; using System.Runtime.CompilerServices; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; using Microsoft.Extensions.Logging; namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/MessageBody.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/MessageBody.cs index 03130d7628..5af47e057e 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/MessageBody.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/MessageBody.cs @@ -3,10 +3,10 @@ using System; using System.IO; -using System.IO.Pipelines; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; using Microsoft.Extensions.Internal; namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/PipelineExtensions.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/PipelineExtensions.cs index 4109119da9..2a02ce766c 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/PipelineExtensions.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/PipelineExtensions.cs @@ -2,10 +2,10 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.Buffers; -using System.IO.Pipelines; using System.Runtime.CompilerServices; using System.Threading.Tasks; +using Microsoft.AspNetCore.Server.Kestrel.Internal.System.Buffers; +using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/SocketOutputProducer.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/SocketOutputProducer.cs index 956fd5a336..c415985677 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/SocketOutputProducer.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/SocketOutputProducer.cs @@ -2,10 +2,10 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.IO.Pipelines; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; using Microsoft.Extensions.Internal; namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/IThreadPool.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/IThreadPool.cs index 48db68ff10..db15d24ea3 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/IThreadPool.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/IThreadPool.cs @@ -2,9 +2,9 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.IO.Pipelines; using System.Threading; using System.Threading.Tasks; +using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Microsoft.AspNetCore.Server.Kestrel.Core.csproj b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Microsoft.AspNetCore.Server.Kestrel.Core.csproj index 931898c08b..95bfdb9012 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Microsoft.AspNetCore.Server.Kestrel.Core.csproj +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Microsoft.AspNetCore.Server.Kestrel.Core.csproj @@ -1,6 +1,7 @@  + Core components of ASP.NET Core Kestrel cross-platform web server. @@ -8,7 +9,7 @@ true aspnetcore;kestrel true - CS1591;$(NoWarn) + CS1570;CS1571;CS1572;CS1573;CS1574;CS1591;$(NoWarn) false @@ -19,10 +20,9 @@ + - - @@ -31,4 +31,9 @@ + + + + + diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Transport/IConnectionContext.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Transport/IConnectionContext.cs index 1ef633d445..3dd426fc67 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Transport/IConnectionContext.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Transport/IConnectionContext.cs @@ -2,8 +2,8 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.IO.Pipelines; using System.Threading.Tasks; +using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; namespace Microsoft.AspNetCore.Server.Kestrel.Transport { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Transport/IConnectionInformation.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Transport/IConnectionInformation.cs index 911b83a0df..763c59e6c3 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Transport/IConnectionInformation.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Transport/IConnectionInformation.cs @@ -1,9 +1,9 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System.IO.Pipelines; using System.Net; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; namespace Microsoft.AspNetCore.Server.Kestrel.Transport { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Http/Connection.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Http/Connection.cs index bff2e1021a..e7911c6ed5 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Http/Connection.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Http/Connection.cs @@ -4,11 +4,11 @@ using System; using System.Diagnostics; using System.IO; -using System.IO.Pipelines; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; +using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; using Microsoft.AspNetCore.Server.Kestrel.Transport; using Microsoft.AspNetCore.Server.Kestrel.Transport.Exceptions; using Microsoft.Extensions.Logging; diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Http/ConnectionContext.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Http/ConnectionContext.cs index 869935033e..60376b6605 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Http/ConnectionContext.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Http/ConnectionContext.cs @@ -1,8 +1,8 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System.IO.Pipelines; using System.Net; +using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; using Microsoft.AspNetCore.Server.Kestrel.Transport; namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Http/SocketOutputConsumer.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Http/SocketOutputConsumer.cs index 6ff5c69ebb..5705fe623d 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Http/SocketOutputConsumer.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Http/SocketOutputConsumer.cs @@ -2,10 +2,10 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.IO.Pipelines; using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; +using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Infrastructure/KestrelThread.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Infrastructure/KestrelThread.cs index 5978ce4f9a..3cca5302ad 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Infrastructure/KestrelThread.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Infrastructure/KestrelThread.cs @@ -3,7 +3,6 @@ using System; using System.Collections.Generic; -using System.IO.Pipelines; using System.Runtime.ExceptionServices; using System.Runtime.InteropServices; using System.Threading; @@ -12,6 +11,7 @@ using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; +using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; using Microsoft.Extensions.Logging; namespace Microsoft.AspNetCore.Server.Kestrel.Internal diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvWriteReq.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvWriteReq.cs index 5462d2a2d4..8b4d84ed7b 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvWriteReq.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvWriteReq.cs @@ -4,9 +4,10 @@ using System; using System.Buffers; using System.Collections.Generic; -using System.IO.Pipelines; using System.Runtime.InteropServices; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Internal.System.Buffers; +using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; using Microsoft.Extensions.Logging; namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/DotSegmentRemovalBenchmark.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/DotSegmentRemovalBenchmark.cs index 64482a568c..eb626280d1 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/DotSegmentRemovalBenchmark.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/DotSegmentRemovalBenchmark.cs @@ -27,7 +27,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance [Benchmark(Baseline = true)] public unsafe int NoDotSegments() { - _noDotSegmentsAscii.CopyTo(_noDotSegmentsBytes); + _noDotSegmentsAscii.CopyTo(_noDotSegmentsBytes, 0); fixed (byte* start = _noDotSegmentsBytes) { @@ -38,7 +38,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance [Benchmark] public unsafe int SingleDotSegments() { - _singleDotSegmentsAscii.CopyTo(_singleDotSegmentsBytes); + _singleDotSegmentsAscii.CopyTo(_singleDotSegmentsBytes, 0); fixed (byte* start = _singleDotSegmentsBytes) { @@ -49,7 +49,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance [Benchmark] public unsafe int DoubleDotSegments() { - _doubleDotSegmentsAscii.CopyTo(_doubleDotSegmentsBytes); + _doubleDotSegmentsAscii.CopyTo(_doubleDotSegmentsBytes, 0); fixed (byte* start = _doubleDotSegmentsBytes) { diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameParsingOverheadBenchmark.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameParsingOverheadBenchmark.cs index a3d0092638..81b219f127 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameParsingOverheadBenchmark.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameParsingOverheadBenchmark.cs @@ -2,11 +2,11 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.IO.Pipelines; using System.Text; using BenchmarkDotNet.Attributes; using Microsoft.AspNetCore.Server.Kestrel.Internal; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; namespace Microsoft.AspNetCore.Server.Kestrel.Performance { diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameWritingBenchmark.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameWritingBenchmark.cs index ae41da1959..40053dc333 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameWritingBenchmark.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameWritingBenchmark.cs @@ -2,12 +2,12 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.IO.Pipelines; using System.Threading; using System.Threading.Tasks; using BenchmarkDotNet.Attributes; using Microsoft.AspNetCore.Server.Kestrel.Internal; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; using Microsoft.AspNetCore.Testing; namespace Microsoft.AspNetCore.Server.Kestrel.Performance diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/KestrelHttpParserBenchmark.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/KestrelHttpParserBenchmark.cs index 0a06b448d0..7c4a3eb6d3 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/KestrelHttpParserBenchmark.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/KestrelHttpParserBenchmark.cs @@ -2,9 +2,9 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.IO.Pipelines; using BenchmarkDotNet.Attributes; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; namespace Microsoft.AspNetCore.Server.Kestrel.Performance { diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Mocks/MockConnectionInformation.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Mocks/MockConnectionInformation.cs index 9faa8d2f63..62d57f3d75 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Mocks/MockConnectionInformation.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Mocks/MockConnectionInformation.cs @@ -1,9 +1,9 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System.IO.Pipelines; using System.Net; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; using Microsoft.AspNetCore.Server.Kestrel.Transport; namespace Microsoft.AspNetCore.Server.Kestrel.Performance diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/PipeThroughputBenchmark.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/PipeThroughputBenchmark.cs index 957a66b19c..152f8af1ef 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/PipeThroughputBenchmark.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/PipeThroughputBenchmark.cs @@ -1,9 +1,9 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System.IO.Pipelines; using System.Threading.Tasks; using BenchmarkDotNet.Attributes; +using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; namespace Microsoft.AspNetCore.Server.Kestrel.Performance { diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsingBenchmark.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsingBenchmark.cs index 68da390b7a..1ebf04ddb5 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsingBenchmark.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsingBenchmark.cs @@ -1,10 +1,10 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System.IO.Pipelines; using BenchmarkDotNet.Attributes; using Microsoft.AspNetCore.Server.Kestrel.Internal; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; namespace Microsoft.AspNetCore.Server.Kestrel.Performance { diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/ResponseHeadersWritingBenchmark.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/ResponseHeadersWritingBenchmark.cs index ce2f941c41..b0c739e641 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/ResponseHeadersWritingBenchmark.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/ResponseHeadersWritingBenchmark.cs @@ -3,7 +3,6 @@ using System; using System.IO; -using System.IO.Pipelines; using System.Text; using System.Threading; using System.Threading.Tasks; @@ -11,6 +10,7 @@ using BenchmarkDotNet.Attributes; using Microsoft.AspNetCore.Server.Kestrel.Adapter.Internal; using Microsoft.AspNetCore.Server.Kestrel.Internal; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; using Microsoft.AspNetCore.Testing; namespace Microsoft.AspNetCore.Server.Kestrel.Performance diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameResponseHeadersTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameResponseHeadersTests.cs index d626512420..c89e23c8c7 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameResponseHeadersTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameResponseHeadersTests.cs @@ -4,9 +4,9 @@ using System; using System.Collections.Generic; using System.Globalization; -using System.IO.Pipelines; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; using Microsoft.AspNetCore.Testing; using Microsoft.Extensions.Primitives; using Xunit; diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs index 70f63f8a72..97bf5451e5 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs @@ -4,7 +4,6 @@ using System; using System.Collections.Generic; using System.IO; -using System.IO.Pipelines; using System.Net; using System.Text; using System.Threading; @@ -16,6 +15,7 @@ using Microsoft.AspNetCore.Server.Kestrel; using Microsoft.AspNetCore.Server.Kestrel.Internal; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; using Microsoft.AspNetCore.Server.Kestrel.Transport; using Microsoft.AspNetCore.Testing; using Microsoft.Extensions.Internal; diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/HttpParserTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/HttpParserTests.cs index 99daa1a53d..cc542df620 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/HttpParserTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/HttpParserTests.cs @@ -3,14 +3,14 @@ using System; using System.Collections.Generic; -using System.IO.Pipelines; -using System.IO.Pipelines.Testing; using System.Linq; using System.Text; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Server.Kestrel; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; +using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.Testing; using Microsoft.AspNetCore.Testing; using Microsoft.Extensions.Logging; using Moq; diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/MultipleLoopTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/MultipleLoopTests.cs index e95605a33f..40c3dde7a6 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/MultipleLoopTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/MultipleLoopTests.cs @@ -2,7 +2,6 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.IO.Pipelines; using System.Net; using System.Net.Sockets; using System.Runtime.InteropServices; @@ -10,6 +9,7 @@ using System.Threading; using Microsoft.AspNetCore.Server.Kestrel.Internal; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; +using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; using Microsoft.AspNetCore.Server.KestrelTests.TestHelpers; using Microsoft.AspNetCore.Testing; using Xunit; diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/NetworkingTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/NetworkingTests.cs index 4799438634..f224da0e8d 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/NetworkingTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/NetworkingTests.cs @@ -2,7 +2,6 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.IO.Pipelines; using System.Net; using System.Net.Sockets; using System.Runtime.InteropServices; @@ -10,6 +9,7 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Internal; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; +using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; using Microsoft.AspNetCore.Testing; using Xunit; diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/PipeOptionsTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/PipeOptionsTests.cs index 924a4200e5..b418619615 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/PipeOptionsTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/PipeOptionsTests.cs @@ -1,9 +1,9 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System.IO.Pipelines; using Microsoft.AspNetCore.Server.Kestrel.Internal; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; using Microsoft.AspNetCore.Testing; using Moq; using Xunit; diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/PipelineExtensionTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/PipelineExtensionTests.cs index e5227dd63e..76496ec1ad 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/PipelineExtensionTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/PipelineExtensionTests.cs @@ -2,10 +2,10 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.IO.Pipelines; using System.Text; using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; using Xunit; namespace Microsoft.AspNetCore.Server.KestrelTests diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/SocketOutputTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/SocketOutputTests.cs index 351886a3ce..428f4f1363 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/SocketOutputTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/SocketOutputTests.cs @@ -3,12 +3,12 @@ using System; using System.Collections.Concurrent; -using System.IO.Pipelines; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel; using Microsoft.AspNetCore.Server.Kestrel.Internal; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; using Microsoft.AspNetCore.Server.KestrelTests.TestHelpers; using Microsoft.AspNetCore.Testing; using Xunit; diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/StreamSocketOutputTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/StreamSocketOutputTests.cs index 1dab5016f8..c122e4e658 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/StreamSocketOutputTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/StreamSocketOutputTests.cs @@ -3,8 +3,8 @@ using System; using System.IO; -using System.IO.Pipelines; using Microsoft.AspNetCore.Server.Kestrel.Adapter.Internal; +using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; using Xunit; namespace Microsoft.AspNetCore.Server.KestrelTests diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockConnectionHandler.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockConnectionHandler.cs index f50f3572c6..0fb74487f9 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockConnectionHandler.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockConnectionHandler.cs @@ -2,8 +2,8 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.IO.Pipelines; using System.Threading.Tasks; +using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; using Microsoft.AspNetCore.Server.Kestrel.Transport; using Xunit; diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestInput.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/TestInput.cs index cfa87eb55e..0b2fba1078 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/TestInput.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/TestInput.cs @@ -2,11 +2,11 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.IO.Pipelines; using System.Text; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; using Microsoft.AspNetCore.Testing; using Microsoft.Extensions.Internal; diff --git a/test/shared/MockSocketOutput.cs b/test/shared/MockSocketOutput.cs index c5cdc32cb2..31819dd1fa 100644 --- a/test/shared/MockSocketOutput.cs +++ b/test/shared/MockSocketOutput.cs @@ -2,10 +2,10 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.IO.Pipelines; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; using Microsoft.Extensions.Internal; namespace Microsoft.AspNetCore.Testing diff --git a/tools/CodeGenerator/KnownHeaders.cs b/tools/CodeGenerator/KnownHeaders.cs index 6f8ef86303..5d4f4eb717 100644 --- a/tools/CodeGenerator/KnownHeaders.cs +++ b/tools/CodeGenerator/KnownHeaders.cs @@ -291,8 +291,7 @@ namespace CodeGenerator using System; using System.Collections.Generic; -using System.IO.Pipelines; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; using Microsoft.Extensions.Primitives; using Microsoft.Net.Http.Headers; diff --git a/tools/Internalizer/Internalizer.csproj b/tools/Internalizer/Internalizer.csproj new file mode 100644 index 0000000000..b4ab265a95 --- /dev/null +++ b/tools/Internalizer/Internalizer.csproj @@ -0,0 +1,7 @@ + + + netcoreapp1.1 + Exe + false + + diff --git a/tools/Internalizer/Program.cs b/tools/Internalizer/Program.cs new file mode 100644 index 0000000000..4ba2bf1efd --- /dev/null +++ b/tools/Internalizer/Program.cs @@ -0,0 +1,108 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Collections.Concurrent; +using System.IO; +using System.Linq; +using System.Text; +using System.Text.RegularExpressions; +using System.Threading.Tasks; + +namespace Internalizer +{ + public class Program + { + private const string MicrosoftAspnetcoreServerKestrelInternal = "Microsoft.AspNetCore.Server.Kestrel.Internal"; + private const string DefaultUsings = +@"// This file was processed with Internalizer tool and should not be edited manually + +using System; +using System.Runtime; +using System.Buffers; + +"; + private static readonly UTF8Encoding _utf8Encoding = new UTF8Encoding(false); + private static readonly Regex _usingRegex = new Regex("using\\s+([\\w.]+)\\s*;", RegexOptions.Compiled); + private static readonly Regex _namespaceRegex = new Regex("namespace\\s+([\\w.]+)", RegexOptions.Compiled); + + public static int Main(string[] args) + { + if (args.Length < 1) + { + Console.Error.WriteLine("Missing path to file list"); + return 1; + } + Run(args[0]); + + return 0; + } + + public static void Run(string csFileList) + { + var files = File.ReadAllLines(csFileList); + var namespaces = new ConcurrentDictionary(); + + var fileContents = files.AsParallel().Select(file => + { + var text = File.ReadAllText(file); + return new FileEntry(path: file, oldText : text, newText : text); + }).ToArray(); + + Parallel.ForEach(fileContents, fileEntry => + { + fileEntry.NewText = ProcessNamespaces(fileEntry.NewText, namespaces); + }); + + Parallel.ForEach(fileContents, fileEntry => + { + fileEntry.NewText = ProcessUsings(fileEntry.NewText, namespaces); + if (fileEntry.NewText != fileEntry.OldText) + { + File.WriteAllText(fileEntry.Path, fileEntry.NewText, _utf8Encoding); + } + }); + + Console.WriteLine($"Successfully internalized {files.Length} file(s)."); + } + + private static string ProcessNamespaces(string contents, ConcurrentDictionary namespaces) + { + return _namespaceRegex.Replace(contents, match => + { + var ns = match.Groups[1].Value; + var newNamespace = $"{MicrosoftAspnetcoreServerKestrelInternal}.{ns}"; + + namespaces.AddOrUpdate(ns, newNamespace, (s, s1) => s1); + return $"namespace {newNamespace}"; + }); + } + + private static string ProcessUsings(string contents, ConcurrentDictionary namespaces) + { + return DefaultUsings + _usingRegex.Replace(contents, match => + { + var ns = match.Groups[1].Value; + if (namespaces.TryGetValue(ns, out var newNamespace)) + { + return $"using {newNamespace};"; + } + return match.Value; + }); + } + } + + public class FileEntry + { + public string Path { get; set; } + public string OldText { get; set; } + public string NewText { get; set; } + + public FileEntry(string path, string oldText, string newText) + { + Path = path; + OldText = oldText; + NewText = newText; + } + } +} From c7113e1c60c398cfcbe18892265519084d2f0793 Mon Sep 17 00:00:00 2001 From: Pavel Krymets Date: Mon, 3 Apr 2017 14:08:27 -0700 Subject: [PATCH 1173/1662] Revert "Fetch corefx lab sources and compile them into kestrel (#1581)" This reverts commit 13ee32b7ab3325ea9a384c99444834df8a7a5acd. --- .gitmodules | 3 - KestrelHttpServer.sln | 15 --- build/corefxlab.props | 14 --- build/dependencies.props | 1 - build/repo.targets | 19 --- corefxlab | 1 - .../Adapter/Internal/AdaptedPipeline.cs | 2 +- .../Adapter/Internal/RawStream.cs | 2 +- .../Adapter/Internal/StreamSocketOutput.cs | 2 +- .../Internal/ConnectionHandler.cs | 2 +- .../Internal/FrameConnection.cs | 2 +- .../Internal/FrameConnectionContext.cs | 2 +- .../Internal/Http/ChunkWriter.cs | 2 +- .../Http/ConnectionLifetimeControl.cs | 2 +- .../Internal/Http/Frame.cs | 6 +- .../Internal/Http/FrameHeaders.Generated.cs | 3 +- .../Internal/Http/FrameResponseHeaders.cs | 2 +- .../Internal/Http/IHttpParser.cs | 2 +- .../Internal/Http/ISocketOutput.cs | 2 +- .../Internal/Http/KestrelHttpParser.cs | 2 +- .../Internal/Http/MessageBody.cs | 2 +- .../Internal/Http/PipelineExtensions.cs | 4 +- .../Internal/Http/SocketOutputProducer.cs | 2 +- .../Internal/Infrastructure/IThreadPool.cs | 2 +- ...soft.AspNetCore.Server.Kestrel.Core.csproj | 11 +- .../Transport/IConnectionContext.cs | 2 +- .../Transport/IConnectionInformation.cs | 2 +- .../Internal/Http/Connection.cs | 2 +- .../Internal/Http/ConnectionContext.cs | 2 +- .../Internal/Http/SocketOutputConsumer.cs | 2 +- .../Internal/Infrastructure/KestrelThread.cs | 2 +- .../Internal/Networking/UvWriteReq.cs | 3 +- .../DotSegmentRemovalBenchmark.cs | 6 +- .../FrameParsingOverheadBenchmark.cs | 2 +- .../FrameWritingBenchmark.cs | 2 +- .../KestrelHttpParserBenchmark.cs | 2 +- .../Mocks/MockConnectionInformation.cs | 2 +- .../PipeThroughputBenchmark.cs | 2 +- .../RequestParsingBenchmark.cs | 2 +- .../ResponseHeadersWritingBenchmark.cs | 2 +- .../FrameResponseHeadersTests.cs | 2 +- .../FrameTests.cs | 2 +- .../HttpParserTests.cs | 4 +- .../MultipleLoopTests.cs | 2 +- .../NetworkingTests.cs | 2 +- .../PipeOptionsTests.cs | 2 +- .../PipelineExtensionTests.cs | 2 +- .../SocketOutputTests.cs | 2 +- .../StreamSocketOutputTests.cs | 2 +- .../TestHelpers/MockConnectionHandler.cs | 2 +- .../TestInput.cs | 2 +- test/shared/MockSocketOutput.cs | 2 +- tools/CodeGenerator/KnownHeaders.cs | 3 +- tools/Internalizer/Internalizer.csproj | 7 -- tools/Internalizer/Program.cs | 108 ------------------ 55 files changed, 57 insertions(+), 229 deletions(-) delete mode 100644 .gitmodules delete mode 100644 build/corefxlab.props delete mode 160000 corefxlab delete mode 100644 tools/Internalizer/Internalizer.csproj delete mode 100644 tools/Internalizer/Program.cs diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index af6855653f..0000000000 --- a/.gitmodules +++ /dev/null @@ -1,3 +0,0 @@ -[submodule "corefxlab"] - path = corefxlab - url = https://github.com/dotnet/corefxlab diff --git a/KestrelHttpServer.sln b/KestrelHttpServer.sln index 820b9e6e27..24a8e79020 100644 --- a/KestrelHttpServer.sln +++ b/KestrelHttpServer.sln @@ -65,8 +65,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Server EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Server.Kestrel", "src\Microsoft.AspNetCore.Server.Kestrel\Microsoft.AspNetCore.Server.Kestrel.csproj", "{56139957-5C29-4E7D-89BD-7D20598B4EAF}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Internalizer", "tools\Internalizer\Internalizer.csproj", "{6B04EAAA-08DE-464B-92DB-1D32BB86892C}" -EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -197,18 +195,6 @@ Global {56139957-5C29-4E7D-89BD-7D20598B4EAF}.Release|x64.Build.0 = Release|Any CPU {56139957-5C29-4E7D-89BD-7D20598B4EAF}.Release|x86.ActiveCfg = Release|Any CPU {56139957-5C29-4E7D-89BD-7D20598B4EAF}.Release|x86.Build.0 = Release|Any CPU - {6B04EAAA-08DE-464B-92DB-1D32BB86892C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {6B04EAAA-08DE-464B-92DB-1D32BB86892C}.Debug|Any CPU.Build.0 = Debug|Any CPU - {6B04EAAA-08DE-464B-92DB-1D32BB86892C}.Debug|x64.ActiveCfg = Debug|Any CPU - {6B04EAAA-08DE-464B-92DB-1D32BB86892C}.Debug|x64.Build.0 = Debug|Any CPU - {6B04EAAA-08DE-464B-92DB-1D32BB86892C}.Debug|x86.ActiveCfg = Debug|Any CPU - {6B04EAAA-08DE-464B-92DB-1D32BB86892C}.Debug|x86.Build.0 = Debug|Any CPU - {6B04EAAA-08DE-464B-92DB-1D32BB86892C}.Release|Any CPU.ActiveCfg = Release|Any CPU - {6B04EAAA-08DE-464B-92DB-1D32BB86892C}.Release|Any CPU.Build.0 = Release|Any CPU - {6B04EAAA-08DE-464B-92DB-1D32BB86892C}.Release|x64.ActiveCfg = Release|Any CPU - {6B04EAAA-08DE-464B-92DB-1D32BB86892C}.Release|x64.Build.0 = Release|Any CPU - {6B04EAAA-08DE-464B-92DB-1D32BB86892C}.Release|x86.ActiveCfg = Release|Any CPU - {6B04EAAA-08DE-464B-92DB-1D32BB86892C}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -226,6 +212,5 @@ Global {2822C132-BFFB-4D53-AC5B-E7E47DD81A6E} = {0EF2ACDF-012F-4472-A13A-4272419E2903} {A76B8C8C-0DC5-4DD3-9B1F-02E51A0915F4} = {2D5D5227-4DBD-499A-96B1-76A36B03B750} {56139957-5C29-4E7D-89BD-7D20598B4EAF} = {2D5D5227-4DBD-499A-96B1-76A36B03B750} - {6B04EAAA-08DE-464B-92DB-1D32BB86892C} = {327F7880-D9AF-46BD-B45C-3B7E34A01DFD} EndGlobalSection EndGlobal diff --git a/build/corefxlab.props b/build/corefxlab.props deleted file mode 100644 index f44b11a994..0000000000 --- a/build/corefxlab.props +++ /dev/null @@ -1,14 +0,0 @@ - - - - $(MSBuildThisFileDirectory)..\corefxlab\ - - - - - - - - - - diff --git a/build/dependencies.props b/build/dependencies.props index 9601cfeacf..ac2690b701 100644 --- a/build/dependencies.props +++ b/build/dependencies.props @@ -4,7 +4,6 @@ 0.1.0-* 0.1.0-* 4.3.0 - 4.4.0-* 2.0.0-* 1.10.0-* 9.0.1 diff --git a/build/repo.targets b/build/repo.targets index 81a19d46b8..d05edf3572 100644 --- a/build/repo.targets +++ b/build/repo.targets @@ -1,24 +1,5 @@ - - Internalize;$(CompileDependsOn) - - - - - - - - - - - - $(MSBuildThisFileDirectory)..\artifacts\corefxlabfiles.txt - - - - - diff --git a/corefxlab b/corefxlab deleted file mode 160000 index 5afdb0ea1f..0000000000 --- a/corefxlab +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 5afdb0ea1fb6842ef9662ed8ab9890a0e1d3c3b9 diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/Internal/AdaptedPipeline.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/Internal/AdaptedPipeline.cs index 4a1087976a..54674ae5d4 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/Internal/AdaptedPipeline.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/Internal/AdaptedPipeline.cs @@ -3,9 +3,9 @@ using System; using System.IO; +using System.IO.Pipelines; using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; -using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; namespace Microsoft.AspNetCore.Server.Kestrel.Adapter.Internal { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/Internal/RawStream.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/Internal/RawStream.cs index c47e0a9369..6e21958576 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/Internal/RawStream.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/Internal/RawStream.cs @@ -3,10 +3,10 @@ using System; using System.IO; +using System.IO.Pipelines; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; -using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; namespace Microsoft.AspNetCore.Server.Kestrel.Adapter.Internal { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/Internal/StreamSocketOutput.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/Internal/StreamSocketOutput.cs index 7ec74cc6b7..11da4bc24b 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/Internal/StreamSocketOutput.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/Internal/StreamSocketOutput.cs @@ -3,10 +3,10 @@ using System; using System.IO; +using System.IO.Pipelines; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; -using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; namespace Microsoft.AspNetCore.Server.Kestrel.Adapter.Internal { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/ConnectionHandler.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/ConnectionHandler.cs index 265b7d7c33..933e04b8ab 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/ConnectionHandler.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/ConnectionHandler.cs @@ -1,10 +1,10 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System.IO.Pipelines; using Microsoft.AspNetCore.Hosting.Server; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; -using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; using Microsoft.AspNetCore.Server.Kestrel.Transport; namespace Microsoft.AspNetCore.Server.Kestrel.Internal diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnection.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnection.cs index fb5cb169c1..af5454f581 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnection.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnection.cs @@ -4,12 +4,12 @@ using System; using System.Collections.Generic; using System.IO; +using System.IO.Pipelines; using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Adapter; using Microsoft.AspNetCore.Server.Kestrel.Adapter.Internal; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; -using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; using Microsoft.AspNetCore.Server.Kestrel.Transport; using Microsoft.Extensions.Internal; using Microsoft.Extensions.Logging; diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnectionContext.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnectionContext.cs index a2dc0a1ec9..271c009385 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnectionContext.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnectionContext.cs @@ -2,9 +2,9 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Collections.Generic; +using System.IO.Pipelines; using Microsoft.AspNetCore.Server.Kestrel.Adapter; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; -using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; namespace Microsoft.AspNetCore.Server.Kestrel.Internal { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/ChunkWriter.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/ChunkWriter.cs index 80bd99a610..6ffbc577b9 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/ChunkWriter.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/ChunkWriter.cs @@ -2,8 +2,8 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.IO.Pipelines; using System.Text; -using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/ConnectionLifetimeControl.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/ConnectionLifetimeControl.cs index 7b794a5d3a..ae7d98ba3f 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/ConnectionLifetimeControl.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/ConnectionLifetimeControl.cs @@ -1,8 +1,8 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System.IO.Pipelines; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; -using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.cs index 9c26aadb11..e5b10948e2 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.cs @@ -5,17 +5,17 @@ using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; +using System.IO.Pipelines; using System.Linq; using System.Net; using System.Runtime.CompilerServices; using System.Text; +using System.Text.Encodings.Web.Utf8; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Server.Kestrel.Adapter; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; -using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; -using Microsoft.AspNetCore.Server.Kestrel.Internal.System.Text.Encodings.Web.Utf8; using Microsoft.AspNetCore.Server.Kestrel.Transport; using Microsoft.Extensions.Internal; using Microsoft.Extensions.Logging; @@ -987,7 +987,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http responseHeaders.SetRawDate(dateHeaderValues.String, dateHeaderValues.Bytes); } - Output.Write(_writeHeaders, this); + Output.Write(_writeHeaders, this); } private static void WriteResponseHeaders(WritableBuffer writableBuffer, Frame frame) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameHeaders.Generated.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameHeaders.Generated.cs index 10d7f2b9a5..8cc1ad75bd 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameHeaders.Generated.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameHeaders.Generated.cs @@ -3,7 +3,8 @@ using System; using System.Collections.Generic; -using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; +using System.IO.Pipelines; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.Extensions.Primitives; using Microsoft.Net.Http.Headers; diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameResponseHeaders.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameResponseHeaders.cs index ca69a0e26c..9fc752f6cd 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameResponseHeaders.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameResponseHeaders.cs @@ -4,8 +4,8 @@ using System; using System.Collections; using System.Collections.Generic; +using System.IO.Pipelines; using System.Runtime.CompilerServices; -using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; using Microsoft.Extensions.Primitives; using Microsoft.Net.Http.Headers; diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/IHttpParser.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/IHttpParser.cs index a76ff2ed4b..ee888bea1f 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/IHttpParser.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/IHttpParser.cs @@ -1,7 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; +using System.IO.Pipelines; namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/ISocketOutput.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/ISocketOutput.cs index c5fe3ef28c..379dd52318 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/ISocketOutput.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/ISocketOutput.cs @@ -2,9 +2,9 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.IO.Pipelines; using System.Threading; using System.Threading.Tasks; -using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/KestrelHttpParser.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/KestrelHttpParser.cs index d677d35697..b78d04b69c 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/KestrelHttpParser.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/KestrelHttpParser.cs @@ -2,10 +2,10 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.IO.Pipelines; using System.Numerics; using System.Runtime.CompilerServices; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; -using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; using Microsoft.Extensions.Logging; namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/MessageBody.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/MessageBody.cs index 5af47e057e..03130d7628 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/MessageBody.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/MessageBody.cs @@ -3,10 +3,10 @@ using System; using System.IO; +using System.IO.Pipelines; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; using Microsoft.Extensions.Internal; namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/PipelineExtensions.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/PipelineExtensions.cs index 2a02ce766c..4109119da9 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/PipelineExtensions.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/PipelineExtensions.cs @@ -2,10 +2,10 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Buffers; +using System.IO.Pipelines; using System.Runtime.CompilerServices; using System.Threading.Tasks; -using Microsoft.AspNetCore.Server.Kestrel.Internal.System.Buffers; -using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/SocketOutputProducer.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/SocketOutputProducer.cs index c415985677..956fd5a336 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/SocketOutputProducer.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/SocketOutputProducer.cs @@ -2,10 +2,10 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.IO.Pipelines; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; -using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; using Microsoft.Extensions.Internal; namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/IThreadPool.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/IThreadPool.cs index db15d24ea3..48db68ff10 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/IThreadPool.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/IThreadPool.cs @@ -2,9 +2,9 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.IO.Pipelines; using System.Threading; using System.Threading.Tasks; -using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Microsoft.AspNetCore.Server.Kestrel.Core.csproj b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Microsoft.AspNetCore.Server.Kestrel.Core.csproj index 95bfdb9012..931898c08b 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Microsoft.AspNetCore.Server.Kestrel.Core.csproj +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Microsoft.AspNetCore.Server.Kestrel.Core.csproj @@ -1,7 +1,6 @@  - Core components of ASP.NET Core Kestrel cross-platform web server. @@ -9,7 +8,7 @@ true aspnetcore;kestrel true - CS1570;CS1571;CS1572;CS1573;CS1574;CS1591;$(NoWarn) + CS1591;$(NoWarn) false @@ -20,9 +19,10 @@ - + + @@ -31,9 +31,4 @@ - - - - - diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Transport/IConnectionContext.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Transport/IConnectionContext.cs index 3dd426fc67..1ef633d445 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Transport/IConnectionContext.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Transport/IConnectionContext.cs @@ -2,8 +2,8 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.IO.Pipelines; using System.Threading.Tasks; -using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; namespace Microsoft.AspNetCore.Server.Kestrel.Transport { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Transport/IConnectionInformation.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Transport/IConnectionInformation.cs index 763c59e6c3..911b83a0df 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Transport/IConnectionInformation.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Transport/IConnectionInformation.cs @@ -1,9 +1,9 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System.IO.Pipelines; using System.Net; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; -using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; namespace Microsoft.AspNetCore.Server.Kestrel.Transport { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Http/Connection.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Http/Connection.cs index e7911c6ed5..bff2e1021a 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Http/Connection.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Http/Connection.cs @@ -4,11 +4,11 @@ using System; using System.Diagnostics; using System.IO; +using System.IO.Pipelines; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; -using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; using Microsoft.AspNetCore.Server.Kestrel.Transport; using Microsoft.AspNetCore.Server.Kestrel.Transport.Exceptions; using Microsoft.Extensions.Logging; diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Http/ConnectionContext.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Http/ConnectionContext.cs index 60376b6605..869935033e 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Http/ConnectionContext.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Http/ConnectionContext.cs @@ -1,8 +1,8 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System.IO.Pipelines; using System.Net; -using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; using Microsoft.AspNetCore.Server.Kestrel.Transport; namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Http/SocketOutputConsumer.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Http/SocketOutputConsumer.cs index 5705fe623d..6ff5c69ebb 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Http/SocketOutputConsumer.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Http/SocketOutputConsumer.cs @@ -2,10 +2,10 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.IO.Pipelines; using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; -using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Infrastructure/KestrelThread.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Infrastructure/KestrelThread.cs index 3cca5302ad..5978ce4f9a 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Infrastructure/KestrelThread.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Infrastructure/KestrelThread.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; +using System.IO.Pipelines; using System.Runtime.ExceptionServices; using System.Runtime.InteropServices; using System.Threading; @@ -11,7 +12,6 @@ using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; -using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; using Microsoft.Extensions.Logging; namespace Microsoft.AspNetCore.Server.Kestrel.Internal diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvWriteReq.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvWriteReq.cs index 8b4d84ed7b..5462d2a2d4 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvWriteReq.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvWriteReq.cs @@ -4,10 +4,9 @@ using System; using System.Buffers; using System.Collections.Generic; +using System.IO.Pipelines; using System.Runtime.InteropServices; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; -using Microsoft.AspNetCore.Server.Kestrel.Internal.System.Buffers; -using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; using Microsoft.Extensions.Logging; namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/DotSegmentRemovalBenchmark.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/DotSegmentRemovalBenchmark.cs index eb626280d1..64482a568c 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/DotSegmentRemovalBenchmark.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/DotSegmentRemovalBenchmark.cs @@ -27,7 +27,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance [Benchmark(Baseline = true)] public unsafe int NoDotSegments() { - _noDotSegmentsAscii.CopyTo(_noDotSegmentsBytes, 0); + _noDotSegmentsAscii.CopyTo(_noDotSegmentsBytes); fixed (byte* start = _noDotSegmentsBytes) { @@ -38,7 +38,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance [Benchmark] public unsafe int SingleDotSegments() { - _singleDotSegmentsAscii.CopyTo(_singleDotSegmentsBytes, 0); + _singleDotSegmentsAscii.CopyTo(_singleDotSegmentsBytes); fixed (byte* start = _singleDotSegmentsBytes) { @@ -49,7 +49,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance [Benchmark] public unsafe int DoubleDotSegments() { - _doubleDotSegmentsAscii.CopyTo(_doubleDotSegmentsBytes, 0); + _doubleDotSegmentsAscii.CopyTo(_doubleDotSegmentsBytes); fixed (byte* start = _doubleDotSegmentsBytes) { diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameParsingOverheadBenchmark.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameParsingOverheadBenchmark.cs index 81b219f127..a3d0092638 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameParsingOverheadBenchmark.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameParsingOverheadBenchmark.cs @@ -2,11 +2,11 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.IO.Pipelines; using System.Text; using BenchmarkDotNet.Attributes; using Microsoft.AspNetCore.Server.Kestrel.Internal; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; -using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; namespace Microsoft.AspNetCore.Server.Kestrel.Performance { diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameWritingBenchmark.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameWritingBenchmark.cs index 40053dc333..ae41da1959 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameWritingBenchmark.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameWritingBenchmark.cs @@ -2,12 +2,12 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.IO.Pipelines; using System.Threading; using System.Threading.Tasks; using BenchmarkDotNet.Attributes; using Microsoft.AspNetCore.Server.Kestrel.Internal; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; -using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; using Microsoft.AspNetCore.Testing; namespace Microsoft.AspNetCore.Server.Kestrel.Performance diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/KestrelHttpParserBenchmark.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/KestrelHttpParserBenchmark.cs index 7c4a3eb6d3..0a06b448d0 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/KestrelHttpParserBenchmark.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/KestrelHttpParserBenchmark.cs @@ -2,9 +2,9 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.IO.Pipelines; using BenchmarkDotNet.Attributes; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; -using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; namespace Microsoft.AspNetCore.Server.Kestrel.Performance { diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Mocks/MockConnectionInformation.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Mocks/MockConnectionInformation.cs index 62d57f3d75..9faa8d2f63 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Mocks/MockConnectionInformation.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Mocks/MockConnectionInformation.cs @@ -1,9 +1,9 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System.IO.Pipelines; using System.Net; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; -using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; using Microsoft.AspNetCore.Server.Kestrel.Transport; namespace Microsoft.AspNetCore.Server.Kestrel.Performance diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/PipeThroughputBenchmark.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/PipeThroughputBenchmark.cs index 152f8af1ef..957a66b19c 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/PipeThroughputBenchmark.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/PipeThroughputBenchmark.cs @@ -1,9 +1,9 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System.IO.Pipelines; using System.Threading.Tasks; using BenchmarkDotNet.Attributes; -using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; namespace Microsoft.AspNetCore.Server.Kestrel.Performance { diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsingBenchmark.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsingBenchmark.cs index 1ebf04ddb5..68da390b7a 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsingBenchmark.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsingBenchmark.cs @@ -1,10 +1,10 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System.IO.Pipelines; using BenchmarkDotNet.Attributes; using Microsoft.AspNetCore.Server.Kestrel.Internal; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; -using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; namespace Microsoft.AspNetCore.Server.Kestrel.Performance { diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/ResponseHeadersWritingBenchmark.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/ResponseHeadersWritingBenchmark.cs index b0c739e641..ce2f941c41 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/ResponseHeadersWritingBenchmark.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/ResponseHeadersWritingBenchmark.cs @@ -3,6 +3,7 @@ using System; using System.IO; +using System.IO.Pipelines; using System.Text; using System.Threading; using System.Threading.Tasks; @@ -10,7 +11,6 @@ using BenchmarkDotNet.Attributes; using Microsoft.AspNetCore.Server.Kestrel.Adapter.Internal; using Microsoft.AspNetCore.Server.Kestrel.Internal; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; -using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; using Microsoft.AspNetCore.Testing; namespace Microsoft.AspNetCore.Server.Kestrel.Performance diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameResponseHeadersTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameResponseHeadersTests.cs index c89e23c8c7..d626512420 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameResponseHeadersTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameResponseHeadersTests.cs @@ -4,9 +4,9 @@ using System; using System.Collections.Generic; using System.Globalization; +using System.IO.Pipelines; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; -using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; using Microsoft.AspNetCore.Testing; using Microsoft.Extensions.Primitives; using Xunit; diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs index 97bf5451e5..70f63f8a72 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using System.IO; +using System.IO.Pipelines; using System.Net; using System.Text; using System.Threading; @@ -15,7 +16,6 @@ using Microsoft.AspNetCore.Server.Kestrel; using Microsoft.AspNetCore.Server.Kestrel.Internal; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; -using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; using Microsoft.AspNetCore.Server.Kestrel.Transport; using Microsoft.AspNetCore.Testing; using Microsoft.Extensions.Internal; diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/HttpParserTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/HttpParserTests.cs index cc542df620..99daa1a53d 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/HttpParserTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/HttpParserTests.cs @@ -3,14 +3,14 @@ using System; using System.Collections.Generic; +using System.IO.Pipelines; +using System.IO.Pipelines.Testing; using System.Linq; using System.Text; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Server.Kestrel; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; -using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; -using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.Testing; using Microsoft.AspNetCore.Testing; using Microsoft.Extensions.Logging; using Moq; diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/MultipleLoopTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/MultipleLoopTests.cs index 40c3dde7a6..e95605a33f 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/MultipleLoopTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/MultipleLoopTests.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.IO.Pipelines; using System.Net; using System.Net.Sockets; using System.Runtime.InteropServices; @@ -9,7 +10,6 @@ using System.Threading; using Microsoft.AspNetCore.Server.Kestrel.Internal; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; -using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; using Microsoft.AspNetCore.Server.KestrelTests.TestHelpers; using Microsoft.AspNetCore.Testing; using Xunit; diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/NetworkingTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/NetworkingTests.cs index f224da0e8d..4799438634 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/NetworkingTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/NetworkingTests.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.IO.Pipelines; using System.Net; using System.Net.Sockets; using System.Runtime.InteropServices; @@ -9,7 +10,6 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Internal; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; -using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; using Microsoft.AspNetCore.Testing; using Xunit; diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/PipeOptionsTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/PipeOptionsTests.cs index b418619615..924a4200e5 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/PipeOptionsTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/PipeOptionsTests.cs @@ -1,9 +1,9 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System.IO.Pipelines; using Microsoft.AspNetCore.Server.Kestrel.Internal; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; -using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; using Microsoft.AspNetCore.Testing; using Moq; using Xunit; diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/PipelineExtensionTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/PipelineExtensionTests.cs index 76496ec1ad..e5227dd63e 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/PipelineExtensionTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/PipelineExtensionTests.cs @@ -2,10 +2,10 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.IO.Pipelines; using System.Text; using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; -using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; using Xunit; namespace Microsoft.AspNetCore.Server.KestrelTests diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/SocketOutputTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/SocketOutputTests.cs index 428f4f1363..351886a3ce 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/SocketOutputTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/SocketOutputTests.cs @@ -3,12 +3,12 @@ using System; using System.Collections.Concurrent; +using System.IO.Pipelines; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel; using Microsoft.AspNetCore.Server.Kestrel.Internal; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; -using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; using Microsoft.AspNetCore.Server.KestrelTests.TestHelpers; using Microsoft.AspNetCore.Testing; using Xunit; diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/StreamSocketOutputTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/StreamSocketOutputTests.cs index c122e4e658..1dab5016f8 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/StreamSocketOutputTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/StreamSocketOutputTests.cs @@ -3,8 +3,8 @@ using System; using System.IO; +using System.IO.Pipelines; using Microsoft.AspNetCore.Server.Kestrel.Adapter.Internal; -using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; using Xunit; namespace Microsoft.AspNetCore.Server.KestrelTests diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockConnectionHandler.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockConnectionHandler.cs index 0fb74487f9..f50f3572c6 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockConnectionHandler.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockConnectionHandler.cs @@ -2,8 +2,8 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.IO.Pipelines; using System.Threading.Tasks; -using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; using Microsoft.AspNetCore.Server.Kestrel.Transport; using Xunit; diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestInput.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/TestInput.cs index 0b2fba1078..cfa87eb55e 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/TestInput.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/TestInput.cs @@ -2,11 +2,11 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.IO.Pipelines; using System.Text; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; -using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; using Microsoft.AspNetCore.Testing; using Microsoft.Extensions.Internal; diff --git a/test/shared/MockSocketOutput.cs b/test/shared/MockSocketOutput.cs index 31819dd1fa..c5cdc32cb2 100644 --- a/test/shared/MockSocketOutput.cs +++ b/test/shared/MockSocketOutput.cs @@ -2,10 +2,10 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.IO.Pipelines; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; -using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; using Microsoft.Extensions.Internal; namespace Microsoft.AspNetCore.Testing diff --git a/tools/CodeGenerator/KnownHeaders.cs b/tools/CodeGenerator/KnownHeaders.cs index 5d4f4eb717..6f8ef86303 100644 --- a/tools/CodeGenerator/KnownHeaders.cs +++ b/tools/CodeGenerator/KnownHeaders.cs @@ -291,7 +291,8 @@ namespace CodeGenerator using System; using System.Collections.Generic; -using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; +using System.IO.Pipelines; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.Extensions.Primitives; using Microsoft.Net.Http.Headers; diff --git a/tools/Internalizer/Internalizer.csproj b/tools/Internalizer/Internalizer.csproj deleted file mode 100644 index b4ab265a95..0000000000 --- a/tools/Internalizer/Internalizer.csproj +++ /dev/null @@ -1,7 +0,0 @@ - - - netcoreapp1.1 - Exe - false - - diff --git a/tools/Internalizer/Program.cs b/tools/Internalizer/Program.cs deleted file mode 100644 index 4ba2bf1efd..0000000000 --- a/tools/Internalizer/Program.cs +++ /dev/null @@ -1,108 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using System.Collections.Concurrent; -using System.IO; -using System.Linq; -using System.Text; -using System.Text.RegularExpressions; -using System.Threading.Tasks; - -namespace Internalizer -{ - public class Program - { - private const string MicrosoftAspnetcoreServerKestrelInternal = "Microsoft.AspNetCore.Server.Kestrel.Internal"; - private const string DefaultUsings = -@"// This file was processed with Internalizer tool and should not be edited manually - -using System; -using System.Runtime; -using System.Buffers; - -"; - private static readonly UTF8Encoding _utf8Encoding = new UTF8Encoding(false); - private static readonly Regex _usingRegex = new Regex("using\\s+([\\w.]+)\\s*;", RegexOptions.Compiled); - private static readonly Regex _namespaceRegex = new Regex("namespace\\s+([\\w.]+)", RegexOptions.Compiled); - - public static int Main(string[] args) - { - if (args.Length < 1) - { - Console.Error.WriteLine("Missing path to file list"); - return 1; - } - Run(args[0]); - - return 0; - } - - public static void Run(string csFileList) - { - var files = File.ReadAllLines(csFileList); - var namespaces = new ConcurrentDictionary(); - - var fileContents = files.AsParallel().Select(file => - { - var text = File.ReadAllText(file); - return new FileEntry(path: file, oldText : text, newText : text); - }).ToArray(); - - Parallel.ForEach(fileContents, fileEntry => - { - fileEntry.NewText = ProcessNamespaces(fileEntry.NewText, namespaces); - }); - - Parallel.ForEach(fileContents, fileEntry => - { - fileEntry.NewText = ProcessUsings(fileEntry.NewText, namespaces); - if (fileEntry.NewText != fileEntry.OldText) - { - File.WriteAllText(fileEntry.Path, fileEntry.NewText, _utf8Encoding); - } - }); - - Console.WriteLine($"Successfully internalized {files.Length} file(s)."); - } - - private static string ProcessNamespaces(string contents, ConcurrentDictionary namespaces) - { - return _namespaceRegex.Replace(contents, match => - { - var ns = match.Groups[1].Value; - var newNamespace = $"{MicrosoftAspnetcoreServerKestrelInternal}.{ns}"; - - namespaces.AddOrUpdate(ns, newNamespace, (s, s1) => s1); - return $"namespace {newNamespace}"; - }); - } - - private static string ProcessUsings(string contents, ConcurrentDictionary namespaces) - { - return DefaultUsings + _usingRegex.Replace(contents, match => - { - var ns = match.Groups[1].Value; - if (namespaces.TryGetValue(ns, out var newNamespace)) - { - return $"using {newNamespace};"; - } - return match.Value; - }); - } - } - - public class FileEntry - { - public string Path { get; set; } - public string OldText { get; set; } - public string NewText { get; set; } - - public FileEntry(string path, string oldText, string newText) - { - Path = path; - OldText = oldText; - NewText = newText; - } - } -} From f285b18f088cf2a006442800d9334dc9937340d0 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Mon, 3 Apr 2017 14:58:43 -0700 Subject: [PATCH 1174/1662] Ensure no data is written to a connection after uv_shutdown (#1600) --- .../Internal/Http/SocketOutputConsumer.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Http/SocketOutputConsumer.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Http/SocketOutputConsumer.cs index 6ff5c69ebb..c52ff69aed 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Http/SocketOutputConsumer.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Http/SocketOutputConsumer.cs @@ -61,6 +61,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { // Send a FIN await ShutdownAsync(); + // Ensure no data is written after uv_shutdown + break; } if (buffer.IsEmpty && result.IsCompleted) From 6bd0344880314778a7c774759402f90d21a0a0cc Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Mon, 3 Apr 2017 15:09:03 -0700 Subject: [PATCH 1175/1662] Add Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions project (#1582). - Changes the design to have one ConnectionHandler per endpoint. --- KestrelHttpServer.sln | 17 ++++- .../Internal/ConnectionHandler.cs | 10 +-- .../Internal/FrameConnection.cs | 2 +- .../Internal/Http/Frame.cs | 2 +- .../Internal/Http/FrameContext.cs | 2 +- .../Internal/Http/FrameOfT.cs | 2 +- .../Infrastructure/KestrelEventSource.cs | 6 +- .../KestrelServer.cs | 14 ++-- .../ListenOptions.cs | 3 +- ...soft.AspNetCore.Server.Kestrel.Core.csproj | 4 ++ .../Exceptions/AddressInUseException.cs | 2 +- .../Exceptions/ConnectionResetException.cs | 2 +- .../IConnectionContext.cs | 2 +- .../IConnectionHandler.cs | 2 +- .../IConnectionInformation.cs | 4 +- .../IEndPointInformation.cs | 39 +++++++++++ .../ITimeoutControl.cs | 2 +- .../ITransport.cs | 2 +- .../ITransportFactory.cs | 4 +- .../ListenType.cs | 4 +- ...rver.Kestrel.Transport.Abstractions.csproj | 19 +++++ .../TimeoutAction.cs | 2 +- .../Internal/Http/Connection.cs | 3 +- .../Internal/Http/ConnectionContext.cs | 3 +- .../Internal/Http/Listener.cs | 19 ++--- .../Internal/Http/ListenerContext.cs | 7 +- .../Internal/Http/ListenerPrimary.cs | 5 +- .../Internal/Http/ListenerSecondary.cs | 5 +- .../Internal/LibuvTransportContext.cs | 1 + .../KestrelEngine.cs | 19 +++-- .../LibuvTransportFactory.cs | 5 +- .../WebHostBuilderLibuvExtensions.cs | 2 +- .../Mocks/MockConnectionInformation.cs | 4 +- .../EngineTests.cs | 4 +- .../FrameTests.cs | 3 +- .../KestrelServerTests.cs | 6 +- .../ListenerPrimaryTests.cs | 70 ++++++------------- .../PipeOptionsTests.cs | 4 +- .../TestHelpers/MockConnectionHandler.cs | 2 +- .../TestInput.cs | 1 + test/shared/TestServer.cs | 3 +- test/shared/TestServiceContext.cs | 15 ---- 42 files changed, 181 insertions(+), 146 deletions(-) rename src/{Microsoft.AspNetCore.Server.Kestrel.Core/Transport => Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions}/Exceptions/AddressInUseException.cs (87%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Core/Transport => Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions}/Exceptions/ConnectionResetException.cs (87%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Core/Transport => Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions}/IConnectionContext.cs (89%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Core/Transport => Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions}/IConnectionHandler.cs (81%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Core/Transport => Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions}/IConnectionInformation.cs (79%) create mode 100644 src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/IEndPointInformation.cs rename src/{Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http => Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions}/ITimeoutControl.cs (85%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Core/Transport => Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions}/ITransport.cs (84%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Core/Transport => Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions}/ITransportFactory.cs (57%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Core => Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions}/ListenType.cs (69%) create mode 100644 src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.csproj rename src/{Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http => Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions}/TimeoutAction.cs (79%) diff --git a/KestrelHttpServer.sln b/KestrelHttpServer.sln index 24a8e79020..5e243d4c7c 100644 --- a/KestrelHttpServer.sln +++ b/KestrelHttpServer.sln @@ -1,6 +1,6 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 15 -VisualStudioVersion = 15.0.26228.9 +VisualStudioVersion = 15.0.26327.1 MinimumVisualStudioVersion = 10.0.40219.1 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{7972A5D6-3385-4127-9277-428506DD44FF}" ProjectSection(SolutionItems) = preProject @@ -65,6 +65,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Server EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Server.Kestrel", "src\Microsoft.AspNetCore.Server.Kestrel\Microsoft.AspNetCore.Server.Kestrel.csproj", "{56139957-5C29-4E7D-89BD-7D20598B4EAF}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions", "src\Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions\Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.csproj", "{2E9CB89D-EC8F-4DD9-A72B-08D5BABF752D}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -195,6 +197,18 @@ Global {56139957-5C29-4E7D-89BD-7D20598B4EAF}.Release|x64.Build.0 = Release|Any CPU {56139957-5C29-4E7D-89BD-7D20598B4EAF}.Release|x86.ActiveCfg = Release|Any CPU {56139957-5C29-4E7D-89BD-7D20598B4EAF}.Release|x86.Build.0 = Release|Any CPU + {2E9CB89D-EC8F-4DD9-A72B-08D5BABF752D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {2E9CB89D-EC8F-4DD9-A72B-08D5BABF752D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {2E9CB89D-EC8F-4DD9-A72B-08D5BABF752D}.Debug|x64.ActiveCfg = Debug|Any CPU + {2E9CB89D-EC8F-4DD9-A72B-08D5BABF752D}.Debug|x64.Build.0 = Debug|Any CPU + {2E9CB89D-EC8F-4DD9-A72B-08D5BABF752D}.Debug|x86.ActiveCfg = Debug|Any CPU + {2E9CB89D-EC8F-4DD9-A72B-08D5BABF752D}.Debug|x86.Build.0 = Debug|Any CPU + {2E9CB89D-EC8F-4DD9-A72B-08D5BABF752D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {2E9CB89D-EC8F-4DD9-A72B-08D5BABF752D}.Release|Any CPU.Build.0 = Release|Any CPU + {2E9CB89D-EC8F-4DD9-A72B-08D5BABF752D}.Release|x64.ActiveCfg = Release|Any CPU + {2E9CB89D-EC8F-4DD9-A72B-08D5BABF752D}.Release|x64.Build.0 = Release|Any CPU + {2E9CB89D-EC8F-4DD9-A72B-08D5BABF752D}.Release|x86.ActiveCfg = Release|Any CPU + {2E9CB89D-EC8F-4DD9-A72B-08D5BABF752D}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -212,5 +226,6 @@ Global {2822C132-BFFB-4D53-AC5B-E7E47DD81A6E} = {0EF2ACDF-012F-4472-A13A-4272419E2903} {A76B8C8C-0DC5-4DD3-9B1F-02E51A0915F4} = {2D5D5227-4DBD-499A-96B1-76A36B03B750} {56139957-5C29-4E7D-89BD-7D20598B4EAF} = {2D5D5227-4DBD-499A-96B1-76A36B03B750} + {2E9CB89D-EC8F-4DD9-A72B-08D5BABF752D} = {2D5D5227-4DBD-499A-96B1-76A36B03B750} EndGlobalSection EndGlobal diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/ConnectionHandler.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/ConnectionHandler.cs index 933e04b8ab..23ef1630eb 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/ConnectionHandler.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/ConnectionHandler.cs @@ -5,17 +5,19 @@ using System.IO.Pipelines; using Microsoft.AspNetCore.Hosting.Server; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; -using Microsoft.AspNetCore.Server.Kestrel.Transport; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions; namespace Microsoft.AspNetCore.Server.Kestrel.Internal { public class ConnectionHandler : IConnectionHandler { + private readonly ListenOptions _listenOptions; private readonly ServiceContext _serviceContext; private readonly IHttpApplication _application; - public ConnectionHandler(ServiceContext serviceContext, IHttpApplication application) + public ConnectionHandler(ListenOptions listenOptions, ServiceContext serviceContext, IHttpApplication application) { + _listenOptions = listenOptions; _serviceContext = serviceContext; _application = application; } @@ -44,7 +46,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal ConnectionId = connectionId, ServiceContext = _serviceContext, PipeFactory = connectionInfo.PipeFactory, - ConnectionAdapters = connectionInfo.ListenOptions.ConnectionAdapters, + ConnectionAdapters = _listenOptions.ConnectionAdapters, Frame = frame, Input = inputPipe, Output = outputPipe, @@ -52,7 +54,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal }); _serviceContext.Log.ConnectionStart(connectionId); - KestrelEventSource.Log.ConnectionStart(connection, connectionInfo); + KestrelEventSource.Log.ConnectionStart(_listenOptions, connection, connectionInfo); // Since data cannot be added to the inputPipe by the transport until OnConnection returns, // Frame.RequestProcessingAsync is guaranteed to unblock the transport thread before calling diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnection.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnection.cs index af5454f581..8c4805c839 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnection.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnection.cs @@ -10,7 +10,7 @@ using Microsoft.AspNetCore.Server.Kestrel.Adapter; using Microsoft.AspNetCore.Server.Kestrel.Adapter.Internal; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; -using Microsoft.AspNetCore.Server.Kestrel.Transport; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions; using Microsoft.Extensions.Internal; using Microsoft.Extensions.Logging; diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.cs index e5b10948e2..6c83f20b3e 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.cs @@ -16,7 +16,7 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Server.Kestrel.Adapter; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; -using Microsoft.AspNetCore.Server.Kestrel.Transport; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions; using Microsoft.Extensions.Internal; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Primitives; diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameContext.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameContext.cs index 134afd77b7..cbccf8684a 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameContext.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameContext.cs @@ -1,7 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using Microsoft.AspNetCore.Server.Kestrel.Transport; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions; namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameOfT.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameOfT.cs index dbf6a629e2..75edc1659c 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameOfT.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameOfT.cs @@ -7,7 +7,7 @@ using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Hosting.Server; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; -using Microsoft.AspNetCore.Server.Kestrel.Transport.Exceptions; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions; using Microsoft.Extensions.Logging; namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/KestrelEventSource.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/KestrelEventSource.cs index 84d7702503..18f1ab33fa 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/KestrelEventSource.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/KestrelEventSource.cs @@ -4,7 +4,7 @@ using System.Diagnostics.Tracing; using System.Runtime.CompilerServices; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; -using Microsoft.AspNetCore.Server.Kestrel.Transport; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions; namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure { @@ -26,14 +26,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure // - Avoid renaming methods or parameters marked with EventAttribute. EventSource uses these to form the event object. [NonEvent] - public void ConnectionStart(IConnectionContext context, IConnectionInformation information) + public void ConnectionStart(ListenOptions listenOptions, IConnectionContext context, IConnectionInformation information) { // avoid allocating strings unless this event source is enabled if (IsEnabled()) { ConnectionStart( context.ConnectionId, - information.ListenOptions.Scheme, + listenOptions.Scheme, information.LocalEndPoint.ToString(), information.RemoteEndPoint.ToString()); } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/KestrelServer.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/KestrelServer.cs index 3958755ea1..9d50baa24f 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/KestrelServer.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/KestrelServer.cs @@ -16,8 +16,7 @@ using Microsoft.AspNetCore.Server.Kestrel.Core.Internal; using Microsoft.AspNetCore.Server.Kestrel.Internal; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; -using Microsoft.AspNetCore.Server.Kestrel.Transport; -using Microsoft.AspNetCore.Server.Kestrel.Transport.Exceptions; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; @@ -110,8 +109,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel ServerOptions = Options }; - var connectionHandler = new ConnectionHandler(serviceContext, application); - var listenOptions = Options.ListenOptions; var hasListenOptions = listenOptions.Any(); var hasServerAddresses = _serverAddresses.Addresses.Any(); @@ -128,7 +125,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel _logger.LogDebug($"No listening endpoints were configured. Binding to {Constants.DefaultServerAddress} by default."); // "localhost" for both IPv4 and IPv6 can't be represented as an IPEndPoint. - StartLocalhost(connectionHandler, ServerAddress.FromUrl(Constants.DefaultServerAddress)); + StartLocalhost(ServerAddress.FromUrl(Constants.DefaultServerAddress), serviceContext, application); // If StartLocalhost doesn't throw, there is at least one listener. // The port cannot change for "localhost". @@ -173,7 +170,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel if (string.Equals(parsedAddress.Host, "localhost", StringComparison.OrdinalIgnoreCase)) { // "localhost" for both IPv4 and IPv6 can't be represented as an IPEndPoint. - StartLocalhost(connectionHandler, parsedAddress); + StartLocalhost(parsedAddress, serviceContext, application); // If StartLocalhost doesn't throw, there is at least one listener. // The port cannot change for "localhost". @@ -193,6 +190,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel foreach (var endPoint in listenOptions) { + var connectionHandler = new ConnectionHandler(endPoint, serviceContext, application); var transport = _transportFactory.Create(endPoint, connectionHandler); _transports.Add(transport); @@ -256,7 +254,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel } } - private void StartLocalhost(ConnectionHandler connectionHandler, ServerAddress parsedAddress) + private void StartLocalhost(ServerAddress parsedAddress, ServiceContext serviceContext, IHttpApplication application) { if (parsedAddress.Port == 0) { @@ -272,6 +270,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel Scheme = parsedAddress.Scheme, }; + var connectionHandler = new ConnectionHandler(ipv4ListenOptions, serviceContext, application); var transport = _transportFactory.Create(ipv4ListenOptions, connectionHandler); _transports.Add(transport); transport.BindAsync().Wait(); @@ -293,6 +292,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel Scheme = parsedAddress.Scheme, }; + var connectionHandler = new ConnectionHandler(ipv6ListenOptions, serviceContext, application); var transport = _transportFactory.Create(ipv6ListenOptions, connectionHandler); _transports.Add(transport); transport.BindAsync().Wait(); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/ListenOptions.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/ListenOptions.cs index d20fb5d0bf..5fadb48fb4 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/ListenOptions.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/ListenOptions.cs @@ -5,6 +5,7 @@ using System; using System.Collections.Generic; using System.Net; using Microsoft.AspNetCore.Server.Kestrel.Adapter; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions; namespace Microsoft.AspNetCore.Server.Kestrel { @@ -12,7 +13,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel /// Describes either an , Unix domain socket path, or a file descriptor for an already open /// socket that Kestrel should bind to or open. /// - public class ListenOptions + public class ListenOptions : IEndPointInformation { internal ListenOptions(IPEndPoint endPoint) { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Microsoft.AspNetCore.Server.Kestrel.Core.csproj b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Microsoft.AspNetCore.Server.Kestrel.Core.csproj index 931898c08b..8c520b639b 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Microsoft.AspNetCore.Server.Kestrel.Core.csproj +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Microsoft.AspNetCore.Server.Kestrel.Core.csproj @@ -25,6 +25,10 @@ + + + + diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Transport/Exceptions/AddressInUseException.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/Exceptions/AddressInUseException.cs similarity index 87% rename from src/Microsoft.AspNetCore.Server.Kestrel.Core/Transport/Exceptions/AddressInUseException.cs rename to src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/Exceptions/AddressInUseException.cs index 2d9d3e10ae..8144c4a9a3 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Transport/Exceptions/AddressInUseException.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/Exceptions/AddressInUseException.cs @@ -3,7 +3,7 @@ using System; -namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Exceptions +namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions { public class AddressInUseException : InvalidOperationException { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Transport/Exceptions/ConnectionResetException.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/Exceptions/ConnectionResetException.cs similarity index 87% rename from src/Microsoft.AspNetCore.Server.Kestrel.Core/Transport/Exceptions/ConnectionResetException.cs rename to src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/Exceptions/ConnectionResetException.cs index 87235175e0..32626d97ef 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Transport/Exceptions/ConnectionResetException.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/Exceptions/ConnectionResetException.cs @@ -4,7 +4,7 @@ using System; using System.IO; -namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Exceptions +namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions { public class ConnectionResetException : IOException { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Transport/IConnectionContext.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/IConnectionContext.cs similarity index 89% rename from src/Microsoft.AspNetCore.Server.Kestrel.Core/Transport/IConnectionContext.cs rename to src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/IConnectionContext.cs index 1ef633d445..cac404e67e 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Transport/IConnectionContext.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/IConnectionContext.cs @@ -5,7 +5,7 @@ using System; using System.IO.Pipelines; using System.Threading.Tasks; -namespace Microsoft.AspNetCore.Server.Kestrel.Transport +namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions { public interface IConnectionContext { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Transport/IConnectionHandler.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/IConnectionHandler.cs similarity index 81% rename from src/Microsoft.AspNetCore.Server.Kestrel.Core/Transport/IConnectionHandler.cs rename to src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/IConnectionHandler.cs index ba575773e3..81143f611f 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Transport/IConnectionHandler.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/IConnectionHandler.cs @@ -1,7 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -namespace Microsoft.AspNetCore.Server.Kestrel.Transport +namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions { public interface IConnectionHandler { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Transport/IConnectionInformation.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/IConnectionInformation.cs similarity index 79% rename from src/Microsoft.AspNetCore.Server.Kestrel.Core/Transport/IConnectionInformation.cs rename to src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/IConnectionInformation.cs index 911b83a0df..ee02110c0a 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Transport/IConnectionInformation.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/IConnectionInformation.cs @@ -3,13 +3,11 @@ using System.IO.Pipelines; using System.Net; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; -namespace Microsoft.AspNetCore.Server.Kestrel.Transport +namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions { public interface IConnectionInformation { - ListenOptions ListenOptions { get; } IPEndPoint RemoteEndPoint { get; } IPEndPoint LocalEndPoint { get; } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/IEndPointInformation.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/IEndPointInformation.cs new file mode 100644 index 0000000000..9fff985300 --- /dev/null +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/IEndPointInformation.cs @@ -0,0 +1,39 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System.Net; + +namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions +{ + public interface IEndPointInformation + { + /// + /// The type of interface being described: either an , Unix domain socket path, or a file descriptor. + /// + ListenType Type { get; } + + // IPEndPoint is mutable so port 0 can be updated to the bound port. + /// + /// The to bind to. + /// Only set if is . + /// + IPEndPoint IPEndPoint { get; set; } + + /// + /// The absolute path to a Unix domain socket to bind to. + /// Only set if is . + /// + string SocketPath { get; } + + /// + /// A file descriptor for the socket to open. + /// Only set if is . + /// + ulong FileHandle { get; } + + /// + /// Set to false to enable Nagle's algorithm for all connections. + /// + bool NoDelay { get; } + } +} diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/ITimeoutControl.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/ITimeoutControl.cs similarity index 85% rename from src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/ITimeoutControl.cs rename to src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/ITimeoutControl.cs index 4fb389b545..824263da13 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/ITimeoutControl.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/ITimeoutControl.cs @@ -1,7 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http +namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions { public interface ITimeoutControl { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Transport/ITransport.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/ITransport.cs similarity index 84% rename from src/Microsoft.AspNetCore.Server.Kestrel.Core/Transport/ITransport.cs rename to src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/ITransport.cs index 7aeea940f6..704101726c 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Transport/ITransport.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/ITransport.cs @@ -3,7 +3,7 @@ using System.Threading.Tasks; -namespace Microsoft.AspNetCore.Server.Kestrel.Transport +namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions { public interface ITransport { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Transport/ITransportFactory.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/ITransportFactory.cs similarity index 57% rename from src/Microsoft.AspNetCore.Server.Kestrel.Core/Transport/ITransportFactory.cs rename to src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/ITransportFactory.cs index 74eef3d3d6..44608be30f 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Transport/ITransportFactory.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/ITransportFactory.cs @@ -1,10 +1,10 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -namespace Microsoft.AspNetCore.Server.Kestrel.Transport +namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions { public interface ITransportFactory { - ITransport Create(ListenOptions listenOptions, IConnectionHandler handler); + ITransport Create(IEndPointInformation endPointInformation, IConnectionHandler handler); } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/ListenType.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/ListenType.cs similarity index 69% rename from src/Microsoft.AspNetCore.Server.Kestrel.Core/ListenType.cs rename to src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/ListenType.cs index 7ead1d91e0..3842d15545 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/ListenType.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/ListenType.cs @@ -1,10 +1,10 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -namespace Microsoft.AspNetCore.Server.Kestrel +namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions { /// - /// Enumerates the types. + /// Enumerates the types. /// public enum ListenType { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.csproj b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.csproj new file mode 100644 index 0000000000..127f06c668 --- /dev/null +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.csproj @@ -0,0 +1,19 @@ + + + + + + Transport abstractions for the ASP.NET Core Kestrel cross-platform web server. + netstandard1.3 + true + aspnetcore;kestrel + CS1591;$(NoWarn) + false + + + + + + + + diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/TimeoutAction.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/TimeoutAction.cs similarity index 79% rename from src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/TimeoutAction.cs rename to src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/TimeoutAction.cs index 33d832ce01..06aae8627e 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/TimeoutAction.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/TimeoutAction.cs @@ -1,7 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http +namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions { public enum TimeoutAction { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Http/Connection.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Http/Connection.cs index bff2e1021a..213f54db7b 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Http/Connection.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Http/Connection.cs @@ -9,8 +9,7 @@ using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; -using Microsoft.AspNetCore.Server.Kestrel.Transport; -using Microsoft.AspNetCore.Server.Kestrel.Transport.Exceptions; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions; using Microsoft.Extensions.Logging; namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Http/ConnectionContext.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Http/ConnectionContext.cs index 869935033e..25b64697b9 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Http/ConnectionContext.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Http/ConnectionContext.cs @@ -3,7 +3,7 @@ using System.IO.Pipelines; using System.Net; -using Microsoft.AspNetCore.Server.Kestrel.Transport; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions; namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { @@ -20,7 +20,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http public ListenerContext ListenerContext { get; set; } - public ListenOptions ListenOptions => ListenerContext.ListenOptions; public IPEndPoint RemoteEndPoint { get; set; } public IPEndPoint LocalEndPoint { get; set; } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Http/Listener.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Http/Listener.cs index 9666be8181..4f1243bc19 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Http/Listener.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Http/Listener.cs @@ -5,6 +5,7 @@ using System; using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions; using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal; using Microsoft.Extensions.Logging; @@ -26,10 +27,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http public IKestrelTrace Log => TransportContext.Log; public Task StartAsync( - ListenOptions listenOptions, + IEndPointInformation endPointInformation, KestrelThread thread) { - ListenOptions = listenOptions; + EndPointInformation = endPointInformation; Thread = thread; var tcs = new TaskCompletionSource(this); @@ -58,7 +59,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http /// private UvStreamHandle CreateListenSocket() { - switch (ListenOptions.Type) + switch (EndPointInformation.Type) { case ListenType.IPEndPoint: case ListenType.FileHandle: @@ -67,18 +68,18 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http try { socket.Init(Thread.Loop, Thread.QueueCloseHandle); - socket.NoDelay(ListenOptions.NoDelay); + socket.NoDelay(EndPointInformation.NoDelay); - if (ListenOptions.Type == ListenType.IPEndPoint) + if (EndPointInformation.Type == ListenType.IPEndPoint) { - socket.Bind(ListenOptions.IPEndPoint); + socket.Bind(EndPointInformation.IPEndPoint); // If requested port was "0", replace with assigned dynamic port. - ListenOptions.IPEndPoint = socket.GetSockIPEndPoint(); + EndPointInformation.IPEndPoint = socket.GetSockIPEndPoint(); } else { - socket.Open((IntPtr)ListenOptions.FileHandle); + socket.Open((IntPtr)EndPointInformation.FileHandle); } } catch @@ -94,7 +95,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http try { pipe.Init(Thread.Loop, Thread.QueueCloseHandle, false); - pipe.Bind(ListenOptions.SocketPath); + pipe.Bind(EndPointInformation.SocketPath); } catch { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Http/ListenerContext.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Http/ListenerContext.cs index ac0d07f37f..f0bb7b5b3a 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Http/ListenerContext.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Http/ListenerContext.cs @@ -3,6 +3,7 @@ using System; using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions; using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal; namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http @@ -16,7 +17,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http public LibuvTransportContext TransportContext { get; set; } - public ListenOptions ListenOptions { get; set; } + public IEndPointInformation EndPointInformation { get; set; } public KestrelThread Thread { get; set; } @@ -25,13 +26,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http /// protected UvStreamHandle CreateAcceptSocket() { - switch (ListenOptions.Type) + switch (EndPointInformation.Type) { case ListenType.IPEndPoint: case ListenType.FileHandle: var tcpHandle = new UvTcpHandle(TransportContext.Log); tcpHandle.Init(Thread.Loop, Thread.QueueCloseHandle); - tcpHandle.NoDelay(ListenOptions.NoDelay); + tcpHandle.NoDelay(EndPointInformation.NoDelay); return tcpHandle; case ListenType.SocketPath: var pipeHandle = new UvPipeHandle(TransportContext.Log); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Http/ListenerPrimary.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Http/ListenerPrimary.cs index 8d47e7871e..eebcd96e6d 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Http/ListenerPrimary.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Http/ListenerPrimary.cs @@ -8,6 +8,7 @@ using System.Runtime.InteropServices; using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions; using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal; using Microsoft.Extensions.Logging; @@ -39,7 +40,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http public async Task StartAsync( string pipeName, byte[] pipeMessage, - ListenOptions listenOptions, + IEndPointInformation endPointInformation, KestrelThread thread) { _pipeName = pipeName; @@ -52,7 +53,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http Marshal.StructureToPtr(fileCompletionInfo, _fileCompletionInfoPtr, false); } - await StartAsync(listenOptions, thread).ConfigureAwait(false); + await StartAsync(endPointInformation, thread).ConfigureAwait(false); await Thread.PostAsync(state => ((ListenerPrimary)state).PostCallback(), this).ConfigureAwait(false); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Http/ListenerSecondary.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Http/ListenerSecondary.cs index 243a72472a..1171484142 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Http/ListenerSecondary.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Http/ListenerSecondary.cs @@ -7,6 +7,7 @@ using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions; using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal; using Microsoft.Extensions.Logging; @@ -36,14 +37,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http public Task StartAsync( string pipeName, byte[] pipeMessage, - ListenOptions listenOptions, + IEndPointInformation endPointInformation, KestrelThread thread) { _pipeName = pipeName; _pipeMessage = pipeMessage; _buf = thread.Loop.Libuv.buf_init(_ptr, 4); - ListenOptions = listenOptions; + EndPointInformation = endPointInformation; Thread = thread; DispatchPipe = new UvPipeHandle(Log); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvTransportContext.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvTransportContext.cs index 5a94ff302d..e5400244cf 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvTransportContext.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvTransportContext.cs @@ -3,6 +3,7 @@ using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions; namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/KestrelEngine.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/KestrelEngine.cs index d4d9a48d85..3d883354ca 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/KestrelEngine.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/KestrelEngine.cs @@ -9,8 +9,7 @@ using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; -using Microsoft.AspNetCore.Server.Kestrel.Transport; -using Microsoft.AspNetCore.Server.Kestrel.Transport.Exceptions; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions; using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv; using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal; using Microsoft.Extensions.Logging; @@ -19,21 +18,21 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal { public class KestrelEngine : ITransport { - private readonly ListenOptions _listenOptions; + private readonly IEndPointInformation _endPointInformation; private readonly List _listeners = new List(); - public KestrelEngine(LibuvTransportContext context, ListenOptions listenOptions) - : this(new LibuvFunctions(), context, listenOptions) + public KestrelEngine(LibuvTransportContext context, IEndPointInformation endPointInformation) + : this(new LibuvFunctions(), context, endPointInformation) { } // For testing - public KestrelEngine(LibuvFunctions uv, LibuvTransportContext context, ListenOptions listenOptions) + public KestrelEngine(LibuvFunctions uv, LibuvTransportContext context, IEndPointInformation endPointInformation) { Libuv = uv; TransportContext = context; - _listenOptions = listenOptions; + _endPointInformation = endPointInformation; } public LibuvFunctions Libuv { get; } @@ -92,7 +91,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal { var listener = new Listener(TransportContext); _listeners.Add(listener); - await listener.StartAsync(_listenOptions, Threads[0]).ConfigureAwait(false); + await listener.StartAsync(_endPointInformation, Threads[0]).ConfigureAwait(false); } else { @@ -101,13 +100,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal var listenerPrimary = new ListenerPrimary(TransportContext); _listeners.Add(listenerPrimary); - await listenerPrimary.StartAsync(pipeName, pipeMessage, _listenOptions, Threads[0]).ConfigureAwait(false); + await listenerPrimary.StartAsync(pipeName, pipeMessage, _endPointInformation, Threads[0]).ConfigureAwait(false); foreach (var thread in Threads.Skip(1)) { var listenerSecondary = new ListenerSecondary(TransportContext); _listeners.Add(listenerSecondary); - await listenerSecondary.StartAsync(pipeName, pipeMessage, _listenOptions, thread).ConfigureAwait(false); + await listenerSecondary.StartAsync(pipeName, pipeMessage, _endPointInformation, thread).ConfigureAwait(false); } } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/LibuvTransportFactory.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/LibuvTransportFactory.cs index 8985247f95..526a77f0fa 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/LibuvTransportFactory.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/LibuvTransportFactory.cs @@ -5,6 +5,7 @@ using System; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Server.Kestrel.Internal; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions; using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; @@ -65,7 +66,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv }; } - public ITransport Create(ListenOptions listenOptions, IConnectionHandler handler) + public ITransport Create(IEndPointInformation endPointInformation, IConnectionHandler handler) { var transportContext = new LibuvTransportContext { @@ -75,7 +76,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv ConnectionHandler = handler }; - return new KestrelEngine(transportContext, listenOptions); + return new KestrelEngine(transportContext, endPointInformation); } } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/WebHostBuilderLibuvExtensions.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/WebHostBuilderLibuvExtensions.cs index 0cfa830f99..cadb2e7e83 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/WebHostBuilderLibuvExtensions.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/WebHostBuilderLibuvExtensions.cs @@ -2,7 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using Microsoft.AspNetCore.Server.Kestrel.Transport; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions; using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv; using Microsoft.Extensions.DependencyInjection; diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Mocks/MockConnectionInformation.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Mocks/MockConnectionInformation.cs index 9faa8d2f63..744ab1a601 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Mocks/MockConnectionInformation.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Mocks/MockConnectionInformation.cs @@ -3,14 +3,12 @@ using System.IO.Pipelines; using System.Net; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; -using Microsoft.AspNetCore.Server.Kestrel.Transport; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions; namespace Microsoft.AspNetCore.Server.Kestrel.Performance { public class MockConnectionInformation : IConnectionInformation { - public ListenOptions ListenOptions { get; } public IPEndPoint RemoteEndPoint { get; } public IPEndPoint LocalEndPoint { get; } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs index 076729e510..eed4aac30e 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs @@ -53,7 +53,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests public async Task ListenerCanCreateAndDispose(ListenOptions listenOptions) { var testContext = new TestServiceContext(); - testContext.App = TestApp.EchoApp; + testContext.TransportContext.ConnectionHandler = new ConnectionHandler(listenOptions, testContext, new DummyApplication(TestApp.EchoApp)); var engine = new KestrelEngine(testContext.TransportContext, listenOptions); await engine.BindAsync(); @@ -66,7 +66,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests public async Task ConnectionCanReadAndWrite(ListenOptions listenOptions) { var testContext = new TestServiceContext(); - testContext.App = TestApp.EchoApp; + testContext.TransportContext.ConnectionHandler = new ConnectionHandler(listenOptions, testContext, new DummyApplication(TestApp.EchoApp)); var engine = new KestrelEngine(testContext.TransportContext, listenOptions); await engine.BindAsync(); diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs index 70f63f8a72..5f5f353bb4 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs @@ -16,7 +16,7 @@ using Microsoft.AspNetCore.Server.Kestrel; using Microsoft.AspNetCore.Server.Kestrel.Internal; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; -using Microsoft.AspNetCore.Server.Kestrel.Transport; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions; using Microsoft.AspNetCore.Testing; using Microsoft.Extensions.Internal; using Microsoft.Extensions.Logging; @@ -712,7 +712,6 @@ namespace Microsoft.AspNetCore.Server.KestrelTests private class MockConnectionInformation : IConnectionInformation { - public ListenOptions ListenOptions { get; } public IPEndPoint RemoteEndPoint { get; } public IPEndPoint LocalEndPoint { get; } public PipeFactory PipeFactory { get; } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerTests.cs index 2f103ff376..24218aa8f7 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerTests.cs @@ -4,17 +4,17 @@ using System; using System.Linq; using System.Net; +using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting.Server; using Microsoft.AspNetCore.Hosting.Server.Features; using Microsoft.AspNetCore.Server.Kestrel; -using Microsoft.AspNetCore.Server.Kestrel.Transport; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions; using Microsoft.AspNetCore.Testing; using Microsoft.Extensions.Internal; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using Moq; using Xunit; -using Microsoft.AspNetCore.Builder; namespace Microsoft.AspNetCore.Server.KestrelTests { @@ -166,7 +166,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests private class MockTransportFactory : ITransportFactory { - public ITransport Create(ListenOptions listenOptions, IConnectionHandler handler) + public ITransport Create(IEndPointInformation endPointInformation, IConnectionHandler handler) { return Mock.Of(); } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/ListenerPrimaryTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/ListenerPrimaryTests.cs index 8045cb651a..48685f4890 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/ListenerPrimaryTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/ListenerPrimaryTests.cs @@ -6,9 +6,7 @@ using System.IO; using System.Linq; using System.Net; using System.Threading.Tasks; -using Microsoft.AspNetCore.Hosting.Server; using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Server.Kestrel; using Microsoft.AspNetCore.Server.Kestrel.Internal; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; @@ -26,18 +24,16 @@ namespace Microsoft.AspNetCore.Server.KestrelTests public async Task ConnectionsGetRoundRobinedToSecondaryListeners() { var libuv = new LibuvFunctions(); - - var serviceContextPrimary = new TestServiceContext - { - App = c => c.Response.WriteAsync("Primary") - }; - - var serviceContextSecondary = new TestServiceContext - { - App = c => c.Response.WriteAsync("Secondary") - }; - var listenOptions = new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0)); + + var serviceContextPrimary = new TestServiceContext(); + serviceContextPrimary.TransportContext.ConnectionHandler = new ConnectionHandler( + listenOptions, serviceContextPrimary, new DummyApplication(c => c.Response.WriteAsync("Primary"))); + + var serviceContextSecondary = new TestServiceContext(); + serviceContextSecondary.TransportContext.ConnectionHandler = new ConnectionHandler( + listenOptions, serviceContextSecondary, new DummyApplication(c => c.Response.WriteAsync("Secondary"))); + var kestrelEngine = new KestrelEngine(libuv, serviceContextPrimary.TransportContext, listenOptions); var pipeName = (libuv.IsWindows ? @"\\.\pipe\kestrel_" : "/tmp/kestrel_") + Guid.NewGuid().ToString("n"); @@ -80,11 +76,11 @@ namespace Microsoft.AspNetCore.Server.KestrelTests public async Task NonListenerPipeConnectionsAreLoggedAndIgnored() { var libuv = new LibuvFunctions(); + var listenOptions = new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0)); - var serviceContextPrimary = new TestServiceContext - { - App = c => c.Response.WriteAsync("Primary") - }; + var serviceContextPrimary = new TestServiceContext(); + serviceContextPrimary.TransportContext.ConnectionHandler = new ConnectionHandler( + listenOptions, serviceContextPrimary, new DummyApplication(c => c.Response.WriteAsync("Primary"))); var serviceContextSecondary = new TestServiceContext { @@ -92,10 +88,10 @@ namespace Microsoft.AspNetCore.Server.KestrelTests ServerOptions = serviceContextPrimary.ServerOptions, ThreadPool = serviceContextPrimary.ThreadPool, HttpParserFactory = serviceContextPrimary.HttpParserFactory, - App = c => c.Response.WriteAsync("Secondary") }; + serviceContextSecondary.TransportContext.ConnectionHandler = new ConnectionHandler( + listenOptions, serviceContextSecondary, new DummyApplication(c => c.Response.WriteAsync("Secondary"))); - var listenOptions = new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0)); var kestrelEngine = new KestrelEngine(libuv, serviceContextPrimary.TransportContext, listenOptions); var pipeName = (libuv.IsWindows ? @"\\.\pipe\kestrel_" : "/tmp/kestrel_") + Guid.NewGuid().ToString("n"); @@ -187,11 +183,11 @@ namespace Microsoft.AspNetCore.Server.KestrelTests public async Task PipeConnectionsWithWrongMessageAreLoggedAndIgnored() { var libuv = new LibuvFunctions(); + var listenOptions = new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0)); - var serviceContextPrimary = new TestServiceContext - { - App = c => c.Response.WriteAsync("Primary") - }; + var serviceContextPrimary = new TestServiceContext(); + serviceContextPrimary.TransportContext.ConnectionHandler = new ConnectionHandler( + listenOptions, serviceContextPrimary, new DummyApplication(c => c.Response.WriteAsync("Primary"))); var serviceContextSecondary = new TestServiceContext { @@ -199,10 +195,10 @@ namespace Microsoft.AspNetCore.Server.KestrelTests ServerOptions = serviceContextPrimary.ServerOptions, ThreadPool = serviceContextPrimary.ThreadPool, HttpParserFactory = serviceContextPrimary.HttpParserFactory, - App = c => c.Response.WriteAsync("Secondary") }; + serviceContextSecondary.TransportContext.ConnectionHandler = new ConnectionHandler( + listenOptions, serviceContextSecondary, new DummyApplication(c => c.Response.WriteAsync("Secondary"))); - var listenOptions = new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0)); var kestrelEngine = new KestrelEngine(libuv, serviceContextPrimary.TransportContext, listenOptions); var pipeName = (libuv.IsWindows ? @"\\.\pipe\kestrel_" : "/tmp/kestrel_") + Guid.NewGuid().ToString("n"); @@ -271,29 +267,5 @@ namespace Microsoft.AspNetCore.Server.KestrelTests Assert.True(false, $"'{address}' failed to respond with '{expected}' in {maxRetries} retries."); } - - private class TestApplication : IHttpApplication - { - private readonly Func _app; - - public TestApplication(Func app) - { - _app = app; - } - - public DefaultHttpContext CreateContext(IFeatureCollection contextFeatures) - { - return new DefaultHttpContext(contextFeatures); - } - - public Task ProcessRequestAsync(DefaultHttpContext context) - { - return _app(context); - } - - public void DisposeContext(DefaultHttpContext context, Exception exception) - { - } - } } } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/PipeOptionsTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/PipeOptionsTests.cs index 924a4200e5..ec5ac31ff1 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/PipeOptionsTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/PipeOptionsTests.cs @@ -22,7 +22,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests serviceContext.ServerOptions.Limits.MaxResponseBufferSize = maxResponseBufferSize; serviceContext.ThreadPool = new LoggingThreadPool(null); - var connectionHandler = new ConnectionHandler(serviceContext, application: null); + var connectionHandler = new ConnectionHandler(listenOptions: null, serviceContext: serviceContext, application: null); var mockScheduler = Mock.Of(); var outputPipeOptions = connectionHandler.GetOutputPipeOptions(mockScheduler); @@ -41,7 +41,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests serviceContext.ServerOptions.Limits.MaxRequestBufferSize = maxRequestBufferSize; serviceContext.ThreadPool = new LoggingThreadPool(null); - var connectionHandler = new ConnectionHandler(serviceContext, application: null); + var connectionHandler = new ConnectionHandler(listenOptions: null, serviceContext: serviceContext, application: null); var mockScheduler = Mock.Of(); var inputPipeOptions = connectionHandler.GetInputPipeOptions(mockScheduler); diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockConnectionHandler.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockConnectionHandler.cs index f50f3572c6..a7747457ac 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockConnectionHandler.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockConnectionHandler.cs @@ -4,7 +4,7 @@ using System; using System.IO.Pipelines; using System.Threading.Tasks; -using Microsoft.AspNetCore.Server.Kestrel.Transport; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions; using Xunit; namespace Microsoft.AspNetCore.Server.KestrelTests.TestHelpers diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestInput.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/TestInput.cs index cfa87eb55e..e017c983dd 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/TestInput.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/TestInput.cs @@ -7,6 +7,7 @@ using System.Text; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions; using Microsoft.AspNetCore.Testing; using Microsoft.Extensions.Internal; diff --git a/test/shared/TestServer.cs b/test/shared/TestServer.cs index 3763c61c53..fc4e91b195 100644 --- a/test/shared/TestServer.cs +++ b/test/shared/TestServer.cs @@ -43,8 +43,7 @@ namespace Microsoft.AspNetCore.Testing _listenOptions = listenOptions; Context = context; - Context.App = app; - Context.TransportContext.ConnectionHandler = new ConnectionHandler(Context, new DummyApplication(app, httpContextFactory)); + Context.TransportContext.ConnectionHandler = new ConnectionHandler(listenOptions, Context, new DummyApplication(app, httpContextFactory)); try { diff --git a/test/shared/TestServiceContext.cs b/test/shared/TestServiceContext.cs index 522acbd745..e01316b622 100644 --- a/test/shared/TestServiceContext.cs +++ b/test/shared/TestServiceContext.cs @@ -14,8 +14,6 @@ namespace Microsoft.AspNetCore.Testing { public class TestServiceContext : ServiceContext { - private RequestDelegate _app; - public TestServiceContext() { Log = new TestKestrelTrace(); @@ -43,18 +41,5 @@ namespace Microsoft.AspNetCore.Testing public string DateHeaderValue { get; } public LibuvTransportContext TransportContext { get; } - - public RequestDelegate App - { - get - { - return _app; - } - set - { - TransportContext.ConnectionHandler = new ConnectionHandler(this, new DummyApplication(value)); - _app = value; - } - } } } From f5d7caa9fa257cc0179e320e539c4c4e91579eff Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Mon, 3 Apr 2017 16:27:37 -0700 Subject: [PATCH 1176/1662] Remove swp file (#1601) --- .gitignore | 2 ++ .../.KestrelEventSourceTests.cs.swp | Bin 12288 -> 0 bytes 2 files changed, 2 insertions(+) delete mode 100644 test/Microsoft.AspNetCore.Server.KestrelTests/.KestrelEventSourceTests.cs.swp diff --git a/.gitignore b/.gitignore index f77341208e..7a34bbac8a 100644 --- a/.gitignore +++ b/.gitignore @@ -25,6 +25,8 @@ nuget.exe *.ncrunchsolution *.*sdf *.ipch +*.swp +*~ .build/ .testPublish/ launchSettings.json diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/.KestrelEventSourceTests.cs.swp b/test/Microsoft.AspNetCore.Server.KestrelTests/.KestrelEventSourceTests.cs.swp deleted file mode 100644 index 04ade1cbf73f343ab4f618eaa6ba2c9e7200634c..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 12288 zcmeI2&u<$=6vwB%0&Rgi4DMwu#j~m7I&GpJOmJI6VyfCHL5Rb6cN`B|&nz>uCRW9t zzya}BfH-mH%#S-q{sZ_Q;JfzPaT+z^Oy5Xf@BDag-n`F_A~}Ae?Pt9szAIV`?G|Ha z*Z({zyZ7!g<|i@>%9X<_+u(8MaM*p?IJtAB89UgEkG*m}t~QQSHH(jpo?%YKA1NQ4 z${vT150t}P9553f>BL!Y$3b*_-dEwkIwh6{qH-C+&aeEtGiAcS7A{eXd6D?5PerRl z;8h`TgY7i$Y~QZE$KQVI_*F@o@+1O8fCvx)B0vO)01+SpM4%!N@@woL^shtjK-Vha zL5&Cy0U|&IhyW2F0z`la5CI}U1c(3;_@5AvDZcl=#@G)~`TKwQKY-tFGWIES0(}TY z&`s!%8;t!5{Q`XleG5&X5j246(7VuYZ!k87-iJ8!CUgt>`*p_tg1&)j(9ekZ6ZB&h z|NHU`)QA8PAOb{y2oM1xKm>>Y5deX&8An@wUhI{ljz?u}5PciE(>%`>fo3)v74nFAJGPj|!cN zCla;0QEil}QLDY%ZpfXsYTRwLnvHaH|9+#j+it1mPP3itrnUMOzj&-rZc&})%22g+ z6>#Ic3b?VX0&Y}Qz_m-e_vKV=?9NtMl+SZs{UXa&R{QwEve911zFg6#1_j6m(yKi_ zmYG*1_4;^-m?1&W`md^b?m zE=HJ1$Cs~|Ki~mx+K!_`Jt}5HCymdo3lC)ytee+yH9~n65Wz-uoMm|(R@2e?;Lq2+ zyclIV;WMjK-aXT(y#7Ro397Q4NTAo-$|#>NhD-O#HOX-8_~k4X<=X5yGk9%2 zmxO>i@QeK!;IUXj8caRqz)yfushSGQJ&zoXf@PS&dh;SCTHVdEJ z*)MPm?yL=bY#j&xa$l@tG?nE6MH%nF=5wb{CxJ&vor`{V$RAq7URv-@mhr{1=T70T J#Z0Aw{R From fd5f3a771c41573a1a4a0521595c2b2c0ef00a3d Mon Sep 17 00:00:00 2001 From: Pavel Krymets Date: Mon, 3 Apr 2017 20:20:39 -0700 Subject: [PATCH 1177/1662] React to corefxlab changes (#1602) --- .../DotSegmentRemovalBenchmark.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/DotSegmentRemovalBenchmark.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/DotSegmentRemovalBenchmark.cs index 64482a568c..eb626280d1 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/DotSegmentRemovalBenchmark.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/DotSegmentRemovalBenchmark.cs @@ -27,7 +27,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance [Benchmark(Baseline = true)] public unsafe int NoDotSegments() { - _noDotSegmentsAscii.CopyTo(_noDotSegmentsBytes); + _noDotSegmentsAscii.CopyTo(_noDotSegmentsBytes, 0); fixed (byte* start = _noDotSegmentsBytes) { @@ -38,7 +38,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance [Benchmark] public unsafe int SingleDotSegments() { - _singleDotSegmentsAscii.CopyTo(_singleDotSegmentsBytes); + _singleDotSegmentsAscii.CopyTo(_singleDotSegmentsBytes, 0); fixed (byte* start = _singleDotSegmentsBytes) { @@ -49,7 +49,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance [Benchmark] public unsafe int DoubleDotSegments() { - _doubleDotSegmentsAscii.CopyTo(_doubleDotSegmentsBytes); + _doubleDotSegmentsAscii.CopyTo(_doubleDotSegmentsBytes, 0); fixed (byte* start = _doubleDotSegmentsBytes) { From 6a66323a99f92c3e4a926d362e55542193a3ed44 Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Mon, 3 Apr 2017 20:54:01 -0700 Subject: [PATCH 1178/1662] Remove Kestrel.Core dependency from Transport.Libuv (#1584). --- .../Internal/Infrastructure/IKestrelTrace.cs | 23 +--- .../Internal/Infrastructure/KestrelTrace.cs | 94 +--------------- .../KestrelServer.cs | 3 +- .../Internal/Http/Connection.cs | 3 +- .../Internal/Http/Listener.cs | 3 +- .../Internal/Http/ListenerSecondary.cs | 3 +- .../Internal/Http/SocketOutputConsumer.cs | 5 +- .../Internal/Infrastructure/ILibuvTrace.cs | 31 ++++++ .../Internal/Infrastructure/KestrelThread.cs | 3 +- .../Internal/Infrastructure/LibuvTrace.cs | 105 ++++++++++++++++++ .../Internal/Infrastructure/WriteReqPool.cs | 5 +- .../Internal/LibuvTransportContext.cs | 3 +- .../Internal/Networking/UvAsyncHandle.cs | 3 +- .../Internal/Networking/UvConnectRequest.cs | 3 +- .../Internal/Networking/UvHandle.cs | 3 +- .../Internal/Networking/UvLoopHandle.cs | 3 +- .../Internal/Networking/UvMemory.cs | 5 +- .../Internal/Networking/UvPipeHandle.cs | 3 +- .../Internal/Networking/UvRequest.cs | 3 +- .../Internal/Networking/UvShutdownReq.cs | 3 +- .../Internal/Networking/UvStreamHandle.cs | 3 +- .../Internal/Networking/UvTcpHandle.cs | 3 +- .../Internal/Networking/UvTimerHandle.cs | 3 +- .../Internal/Networking/UvWriteReq.cs | 3 +- .../KestrelEngine.cs | 3 +- .../LibuvTransportFactory.cs | 7 +- ...Core.Server.Kestrel.Transport.Libuv.csproj | 9 +- .../ConnectionTests.cs | 2 +- .../LibuvTransportFactoryTests.cs | 4 +- .../ListenerPrimaryTests.cs | 3 +- .../MultipleLoopTests.cs | 21 ++-- .../NetworkingTests.cs | 17 +-- .../SocketOutputTests.cs | 7 +- .../TestHelpers/MockSocket.cs | 9 +- .../UvStreamHandleTests.cs | 10 +- .../UvTimerHandleTests.cs | 15 ++- test/shared/TestKestrelTrace.cs | 15 --- test/shared/TestServiceContext.cs | 7 +- 38 files changed, 240 insertions(+), 208 deletions(-) create mode 100644 src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Infrastructure/ILibuvTrace.cs create mode 100644 src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Infrastructure/LibuvTrace.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/IKestrelTrace.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/IKestrelTrace.cs index 5e744b678e..6fc3c610fb 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/IKestrelTrace.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/IKestrelTrace.cs @@ -1,3 +1,6 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + using System; using Microsoft.Extensions.Logging; @@ -9,30 +12,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure void ConnectionStop(string connectionId); - void ConnectionRead(string connectionId, int count); - void ConnectionPause(string connectionId); void ConnectionResume(string connectionId); - void ConnectionReadFin(string connectionId); - - void ConnectionWriteFin(string connectionId); - - void ConnectionWroteFin(string connectionId, int status); - void ConnectionKeepAlive(string connectionId); void ConnectionDisconnect(string connectionId); - void ConnectionWrite(string connectionId, int count); - - void ConnectionWriteCallback(string connectionId, int status); - - void ConnectionError(string connectionId, Exception ex); - - void ConnectionReset(string connectionId); - void RequestProcessingError(string connectionId, Exception ex); void ConnectionDisconnectedWrite(string connectionId, int count, Exception ex); @@ -41,10 +28,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure void ConnectionBadRequest(string connectionId, BadHttpRequestException ex); - void NotAllConnectionsClosedGracefully(); - - void NotAllConnectionsAborted(); - void ApplicationError(string connectionId, string traceIdentifier, Exception ex); } } \ No newline at end of file diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/KestrelTrace.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/KestrelTrace.cs index 50cd3c3f0a..fb9a0a4736 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/KestrelTrace.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/KestrelTrace.cs @@ -18,60 +18,33 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal private static readonly Action _connectionStop = LoggerMessage.Define(LogLevel.Debug, 2, @"Connection id ""{ConnectionId}"" stopped."); - // ConnectionRead: Reserved: 3 - private static readonly Action _connectionPause = LoggerMessage.Define(LogLevel.Debug, 4, @"Connection id ""{ConnectionId}"" paused."); private static readonly Action _connectionResume = LoggerMessage.Define(LogLevel.Debug, 5, @"Connection id ""{ConnectionId}"" resumed."); - private static readonly Action _connectionReadFin = - LoggerMessage.Define(LogLevel.Debug, 6, @"Connection id ""{ConnectionId}"" received FIN."); - - private static readonly Action _connectionWriteFin = - LoggerMessage.Define(LogLevel.Debug, 7, @"Connection id ""{ConnectionId}"" sending FIN."); - - private static readonly Action _connectionWroteFin = - LoggerMessage.Define(LogLevel.Debug, 8, @"Connection id ""{ConnectionId}"" sent FIN with status ""{Status}""."); - private static readonly Action _connectionKeepAlive = LoggerMessage.Define(LogLevel.Debug, 9, @"Connection id ""{ConnectionId}"" completed keep alive response."); private static readonly Action _connectionDisconnect = LoggerMessage.Define(LogLevel.Debug, 10, @"Connection id ""{ConnectionId}"" disconnecting."); - // ConnectionWrite: Reserved: 11 - - // ConnectionWriteCallback: Reserved: 12 - private static readonly Action _applicationError = LoggerMessage.Define(LogLevel.Error, 13, @"Connection id ""{ConnectionId}"", Request id ""{TraceIdentifier}"": An unhandled exception was thrown by the application."); - private static readonly Action _connectionError = - LoggerMessage.Define(LogLevel.Information, 14, @"Connection id ""{ConnectionId}"" communication error."); - private static readonly Action _connectionDisconnectedWrite = LoggerMessage.Define(LogLevel.Debug, 15, @"Connection id ""{ConnectionId}"" write of ""{count}"" bytes to disconnected client."); - private static readonly Action _notAllConnectionsClosedGracefully = - LoggerMessage.Define(LogLevel.Debug, 16, "Some connections failed to close gracefully during server shutdown."); - private static readonly Action _connectionBadRequest = LoggerMessage.Define(LogLevel.Information, 17, @"Connection id ""{ConnectionId}"" bad request data: ""{message}"""); private static readonly Action _connectionHeadResponseBodyWrite = LoggerMessage.Define(LogLevel.Debug, 18, @"Connection id ""{ConnectionId}"" write of ""{count}"" body bytes to non-body HEAD response."); - private static readonly Action _connectionReset = - LoggerMessage.Define(LogLevel.Debug, 19, @"Connection id ""{ConnectionId}"" reset."); - private static readonly Action _requestProcessingError = LoggerMessage.Define(LogLevel.Information, 20, @"Connection id ""{ConnectionId}"" request processing ended abnormally."); - private static readonly Action _notAllConnectionsAborted = - LoggerMessage.Define(LogLevel.Debug, 21, "Some connections failed to abort during server shutdown."); - protected readonly ILogger _logger; public KestrelTrace(ILogger logger) @@ -89,12 +62,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal _connectionStop(_logger, connectionId, null); } - public virtual void ConnectionRead(string connectionId, int count) - { - // Don't log for now since this could be *too* verbose. - // Reserved: Event ID 3 - } - public virtual void ConnectionPause(string connectionId) { _connectionPause(_logger, connectionId, null); @@ -105,21 +72,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal _connectionResume(_logger, connectionId, null); } - public virtual void ConnectionReadFin(string connectionId) - { - _connectionReadFin(_logger, connectionId, null); - } - - public virtual void ConnectionWriteFin(string connectionId) - { - _connectionWriteFin(_logger, connectionId, null); - } - - public virtual void ConnectionWroteFin(string connectionId, int status) - { - _connectionWroteFin(_logger, connectionId, status, null); - } - public virtual void ConnectionKeepAlive(string connectionId) { _connectionKeepAlive(_logger, connectionId, null); @@ -130,28 +82,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal _connectionDisconnect(_logger, connectionId, null); } - public virtual void ConnectionWrite(string connectionId, int count) - { - // Don't log for now since this could be *too* verbose. - // Reserved: Event ID 11 - } - - public virtual void ConnectionWriteCallback(string connectionId, int status) - { - // Don't log for now since this could be *too* verbose. - // Reserved: Event ID 12 - } - public virtual void ApplicationError(string connectionId, string traceIdentifier, Exception ex) { _applicationError(_logger, connectionId, traceIdentifier, ex); } - public virtual void ConnectionError(string connectionId, Exception ex) - { - _connectionError(_logger, connectionId, ex); - } - public virtual void ConnectionDisconnectedWrite(string connectionId, int count, Exception ex) { _connectionDisconnectedWrite(_logger, connectionId, count, ex); @@ -162,44 +97,21 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal _connectionHeadResponseBodyWrite(_logger, connectionId, count, null); } - public virtual void NotAllConnectionsClosedGracefully() - { - _notAllConnectionsClosedGracefully(_logger, null); - } - - public virtual void NotAllConnectionsAborted() - { - _notAllConnectionsAborted(_logger, null); - } - public void ConnectionBadRequest(string connectionId, BadHttpRequestException ex) { _connectionBadRequest(_logger, connectionId, ex.Message, ex); } - public virtual void ConnectionReset(string connectionId) - { - _connectionReset(_logger, connectionId, null); - } - public virtual void RequestProcessingError(string connectionId, Exception ex) { _requestProcessingError(_logger, connectionId, ex); } public virtual void Log(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func formatter) - { - _logger.Log(logLevel, eventId, state, exception, formatter); - } + => _logger.Log(logLevel, eventId, state, exception, formatter); - public virtual bool IsEnabled(LogLevel logLevel) - { - return _logger.IsEnabled(logLevel); - } + public virtual bool IsEnabled(LogLevel logLevel) => _logger.IsEnabled(logLevel); - public virtual IDisposable BeginScope(TState state) - { - return _logger.BeginScope(state); - } + public virtual IDisposable BeginScope(TState state) => _logger.BeginScope(state); } } \ No newline at end of file diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/KestrelServer.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/KestrelServer.cs index 9d50baa24f..921d77fa78 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/KestrelServer.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/KestrelServer.cs @@ -6,7 +6,6 @@ using System.Collections.Generic; using System.IO; using System.Linq; using System.Net; -using System.Reflection; using System.Threading.Tasks; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting.Server; @@ -56,7 +55,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel Options = options.Value ?? new KestrelServerOptions(); InternalOptions = new InternalKestrelServerOptions(); _transportFactory = transportFactory; - _logger = loggerFactory.CreateLogger(typeof(KestrelServer).GetTypeInfo().Namespace); + _logger = loggerFactory.CreateLogger("Microsoft.AspNetCore.Server.Kestrel"); Features = new FeatureCollection(); _serverAddresses = new ServerAddressesFeature(); Features.Set(_serverAddresses); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Http/Connection.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Http/Connection.cs index 213f54db7b..66c88f630a 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Http/Connection.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Http/Connection.cs @@ -10,6 +10,7 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Infrastructure; using Microsoft.Extensions.Logging; namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http @@ -59,7 +60,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http public IPipeWriter Input { get; set; } public SocketOutputConsumer Output { get; set; } - private IKestrelTrace Log => ListenerContext.TransportContext.Log; + private ILibuvTrace Log => ListenerContext.TransportContext.Log; private IConnectionHandler ConnectionHandler => ListenerContext.TransportContext.ConnectionHandler; private KestrelThread Thread => ListenerContext.Thread; diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Http/Listener.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Http/Listener.cs index 4f1243bc19..ca4b780510 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Http/Listener.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Http/Listener.cs @@ -7,6 +7,7 @@ using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions; using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Infrastructure; using Microsoft.Extensions.Logging; namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http @@ -24,7 +25,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http protected UvStreamHandle ListenSocket { get; private set; } - public IKestrelTrace Log => TransportContext.Log; + public ILibuvTrace Log => TransportContext.Log; public Task StartAsync( IEndPointInformation endPointInformation, diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Http/ListenerSecondary.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Http/ListenerSecondary.cs index 1171484142..506832a72d 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Http/ListenerSecondary.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Http/ListenerSecondary.cs @@ -9,6 +9,7 @@ using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions; using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Infrastructure; using Microsoft.Extensions.Logging; namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http @@ -32,7 +33,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http UvPipeHandle DispatchPipe { get; set; } - public IKestrelTrace Log => TransportContext.Log; + public ILibuvTrace Log => TransportContext.Log; public Task StartAsync( string pipeName, diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Http/SocketOutputConsumer.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Http/SocketOutputConsumer.cs index c52ff69aed..7087a46e79 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Http/SocketOutputConsumer.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Http/SocketOutputConsumer.cs @@ -6,6 +6,7 @@ using System.IO.Pipelines; using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Infrastructure; namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { @@ -15,7 +16,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http private readonly UvStreamHandle _socket; private readonly Connection _connection; private readonly string _connectionId; - private readonly IKestrelTrace _log; + private readonly ILibuvTrace _log; private readonly WriteReqPool _writeReqPool; private readonly IPipeReader _pipe; @@ -26,7 +27,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http UvStreamHandle socket, Connection connection, string connectionId, - IKestrelTrace log) + ILibuvTrace log) { _pipe = pipe; // We need to have empty pipe at this moment so callback diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Infrastructure/ILibuvTrace.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Infrastructure/ILibuvTrace.cs new file mode 100644 index 0000000000..432d5370a1 --- /dev/null +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Infrastructure/ILibuvTrace.cs @@ -0,0 +1,31 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using Microsoft.Extensions.Logging; + +namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Infrastructure +{ + public interface ILibuvTrace : ILogger + { + void ConnectionRead(string connectionId, int count); + + void ConnectionReadFin(string connectionId); + + void ConnectionWriteFin(string connectionId); + + void ConnectionWroteFin(string connectionId, int status); + + void ConnectionWrite(string connectionId, int count); + + void ConnectionWriteCallback(string connectionId, int status); + + void ConnectionError(string connectionId, Exception ex); + + void ConnectionReset(string connectionId); + + void NotAllConnectionsClosedGracefully(); + + void NotAllConnectionsAborted(); + } +} diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Infrastructure/KestrelThread.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Infrastructure/KestrelThread.cs index 5978ce4f9a..fd3162f6ce 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Infrastructure/KestrelThread.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Infrastructure/KestrelThread.cs @@ -12,6 +12,7 @@ using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Infrastructure; using Microsoft.Extensions.Logging; namespace Microsoft.AspNetCore.Server.Kestrel.Internal @@ -52,7 +53,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal private bool _stopImmediate = false; private bool _initCompleted = false; private ExceptionDispatchInfo _closeError; - private readonly IKestrelTrace _log; + private readonly ILibuvTrace _log; private readonly TimeSpan _shutdownTimeout; private IntPtr _thisPtr; diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Infrastructure/LibuvTrace.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Infrastructure/LibuvTrace.cs new file mode 100644 index 0000000000..d113bf2010 --- /dev/null +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Infrastructure/LibuvTrace.cs @@ -0,0 +1,105 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using Microsoft.Extensions.Logging; + +namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Infrastructure +{ + public class LibuvTrace : ILibuvTrace + { + // ConnectionRead: Reserved: 3 + + private static readonly Action _connectionReadFin = + LoggerMessage.Define(LogLevel.Debug, 6, @"Connection id ""{ConnectionId}"" received FIN."); + + private static readonly Action _connectionWriteFin = + LoggerMessage.Define(LogLevel.Debug, 7, @"Connection id ""{ConnectionId}"" sending FIN."); + + private static readonly Action _connectionWroteFin = + LoggerMessage.Define(LogLevel.Debug, 8, @"Connection id ""{ConnectionId}"" sent FIN with status ""{Status}""."); + + // ConnectionWrite: Reserved: 11 + + // ConnectionWriteCallback: Reserved: 12 + + private static readonly Action _connectionError = + LoggerMessage.Define(LogLevel.Information, 14, @"Connection id ""{ConnectionId}"" communication error."); + + private static readonly Action _notAllConnectionsClosedGracefully = + LoggerMessage.Define(LogLevel.Debug, 16, "Some connections failed to close gracefully during server shutdown."); + + private static readonly Action _connectionReset = + LoggerMessage.Define(LogLevel.Debug, 19, @"Connection id ""{ConnectionId}"" reset."); + + private static readonly Action _notAllConnectionsAborted = + LoggerMessage.Define(LogLevel.Debug, 21, "Some connections failed to abort during server shutdown."); + + private readonly ILogger _logger; + + public LibuvTrace(ILogger logger) + { + _logger = logger; + } + + public void ConnectionRead(string connectionId, int count) + { + // Don't log for now since this could be *too* verbose. + // Reserved: Event ID 3 + } + + public void ConnectionReadFin(string connectionId) + { + _connectionReadFin(_logger, connectionId, null); + } + + public void ConnectionWriteFin(string connectionId) + { + _connectionWriteFin(_logger, connectionId, null); + } + + public void ConnectionWroteFin(string connectionId, int status) + { + _connectionWroteFin(_logger, connectionId, status, null); + } + + public void ConnectionWrite(string connectionId, int count) + { + // Don't log for now since this could be *too* verbose. + // Reserved: Event ID 11 + } + + public void ConnectionWriteCallback(string connectionId, int status) + { + // Don't log for now since this could be *too* verbose. + // Reserved: Event ID 12 + } + + public void ConnectionError(string connectionId, Exception ex) + { + _connectionError(_logger, connectionId, ex); + } + + public void ConnectionReset(string connectionId) + { + _connectionReset(_logger, connectionId, null); + } + + public void NotAllConnectionsClosedGracefully() + { + _notAllConnectionsClosedGracefully(_logger, null); + } + + public void NotAllConnectionsAborted() + { + _notAllConnectionsAborted(_logger, null); + } + + public IDisposable BeginScope(TState state) => _logger.BeginScope(state); + + public bool IsEnabled(LogLevel logLevel) => _logger.IsEnabled(logLevel); + + public void Log(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func formatter) + => _logger.Log(logLevel, eventId, state, exception, formatter); + } +} diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Infrastructure/WriteReqPool.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Infrastructure/WriteReqPool.cs index 1f89ec17e2..dc83eae51c 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Infrastructure/WriteReqPool.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Infrastructure/WriteReqPool.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Infrastructure; namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure { @@ -10,10 +11,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure private readonly KestrelThread _thread; private readonly Queue _pool = new Queue(_maxPooledWriteReqs); - private readonly IKestrelTrace _log; + private readonly ILibuvTrace _log; private bool _disposed; - public WriteReqPool(KestrelThread thread, IKestrelTrace log) + public WriteReqPool(KestrelThread thread, ILibuvTrace log) { _thread = thread; _log = log; diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvTransportContext.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvTransportContext.cs index e5400244cf..df8a8b1275 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvTransportContext.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvTransportContext.cs @@ -4,6 +4,7 @@ using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Infrastructure; namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal { @@ -13,7 +14,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal public IApplicationLifetime AppLifetime { get; set; } - public IKestrelTrace Log { get; set; } + public ILibuvTrace Log { get; set; } public IConnectionHandler ConnectionHandler { get; set; } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvAsyncHandle.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvAsyncHandle.cs index d1260b93c2..141ca6dcb7 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvAsyncHandle.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvAsyncHandle.cs @@ -5,6 +5,7 @@ using System; using System.Diagnostics; using System.Threading; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Infrastructure; namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking { @@ -16,7 +17,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking private Action _callback; private Action, IntPtr> _queueCloseHandle; - public UvAsyncHandle(IKestrelTrace logger) : base(logger) + public UvAsyncHandle(ILibuvTrace logger) : base(logger) { } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvConnectRequest.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvConnectRequest.cs index 86f0312610..204d8c4ba4 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvConnectRequest.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvConnectRequest.cs @@ -3,6 +3,7 @@ using System; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Infrastructure; using Microsoft.Extensions.Logging; namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking @@ -17,7 +18,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking private Action _callback; private object _state; - public UvConnectRequest(IKestrelTrace logger) : base (logger) + public UvConnectRequest(ILibuvTrace logger) : base (logger) { } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvHandle.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvHandle.cs index a5ce314bdc..41a074ae21 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvHandle.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvHandle.cs @@ -5,6 +5,7 @@ using System; using System.Diagnostics; using System.Threading; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Infrastructure; namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking { @@ -13,7 +14,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking private static readonly LibuvFunctions.uv_close_cb _destroyMemory = (handle) => DestroyMemory(handle); private Action, IntPtr> _queueCloseHandle; - protected UvHandle(IKestrelTrace logger) : base (logger) + protected UvHandle(ILibuvTrace logger) : base (logger) { } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvLoopHandle.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvLoopHandle.cs index b825c4eb7a..39bce92897 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvLoopHandle.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvLoopHandle.cs @@ -4,12 +4,13 @@ using System; using System.Threading; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Infrastructure; namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking { public class UvLoopHandle : UvMemory { - public UvLoopHandle(IKestrelTrace logger) : base(logger) + public UvLoopHandle(ILibuvTrace logger) : base(logger) { } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvMemory.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvMemory.cs index 3fb078ac17..3e67b6b399 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvMemory.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvMemory.cs @@ -6,6 +6,7 @@ using System.Diagnostics; using System.Runtime.InteropServices; using System.Threading; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Infrastructure; namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking { @@ -16,9 +17,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking { protected LibuvFunctions _uv; protected int _threadId; - protected readonly IKestrelTrace _log; + protected readonly ILibuvTrace _log; - protected UvMemory(IKestrelTrace logger) : base(IntPtr.Zero, true) + protected UvMemory(ILibuvTrace logger) : base(IntPtr.Zero, true) { _log = logger; } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvPipeHandle.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvPipeHandle.cs index b4f479d7ca..0ce7e1fe27 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvPipeHandle.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvPipeHandle.cs @@ -3,12 +3,13 @@ using System; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Infrastructure; namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking { public class UvPipeHandle : UvStreamHandle { - public UvPipeHandle(IKestrelTrace logger) : base(logger) + public UvPipeHandle(ILibuvTrace logger) : base(logger) { } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvRequest.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvRequest.cs index bffeb5d5e2..20a285304f 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvRequest.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvRequest.cs @@ -1,6 +1,7 @@ using System; using System.Runtime.InteropServices; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Infrastructure; namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking { @@ -8,7 +9,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking { private GCHandle _pin; - protected UvRequest(IKestrelTrace logger) : base (logger) + protected UvRequest(ILibuvTrace logger) : base (logger) { } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvShutdownReq.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvShutdownReq.cs index fb01064025..9d13b715b7 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvShutdownReq.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvShutdownReq.cs @@ -3,6 +3,7 @@ using System; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Infrastructure; namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking { @@ -16,7 +17,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking private Action _callback; private object _state; - public UvShutdownReq(IKestrelTrace logger) : base (logger) + public UvShutdownReq(ILibuvTrace logger) : base (logger) { } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvStreamHandle.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvStreamHandle.cs index 9b9af056cf..ee3b3abc7f 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvStreamHandle.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvStreamHandle.cs @@ -5,6 +5,7 @@ using System; using System.Runtime.InteropServices; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Infrastructure; using Microsoft.Extensions.Logging; namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking @@ -25,7 +26,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking private object _readState; private GCHandle _readVitality; - protected UvStreamHandle(IKestrelTrace logger) : base(logger) + protected UvStreamHandle(ILibuvTrace logger) : base(logger) { } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvTcpHandle.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvTcpHandle.cs index 5f124518c1..2c794509ae 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvTcpHandle.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvTcpHandle.cs @@ -5,12 +5,13 @@ using System; using System.Net; using System.Runtime.InteropServices; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Infrastructure; namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking { public class UvTcpHandle : UvStreamHandle { - public UvTcpHandle(IKestrelTrace logger) : base(logger) + public UvTcpHandle(ILibuvTrace logger) : base(logger) { } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvTimerHandle.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvTimerHandle.cs index 62501c6c98..77c288ae8c 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvTimerHandle.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvTimerHandle.cs @@ -3,6 +3,7 @@ using System; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Infrastructure; using Microsoft.Extensions.Logging; namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking @@ -13,7 +14,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking private Action _callback; - public UvTimerHandle(IKestrelTrace logger) : base(logger) + public UvTimerHandle(ILibuvTrace logger) : base(logger) { } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvWriteReq.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvWriteReq.cs index 5462d2a2d4..f680aa5892 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvWriteReq.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvWriteReq.cs @@ -7,6 +7,7 @@ using System.Collections.Generic; using System.IO.Pipelines; using System.Runtime.InteropServices; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Infrastructure; using Microsoft.Extensions.Logging; namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking @@ -28,7 +29,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking private List _pins = new List(BUFFER_COUNT + 1); private List _handles = new List(BUFFER_COUNT + 1); - public UvWriteReq(IKestrelTrace logger) : base(logger) + public UvWriteReq(ILibuvTrace logger) : base(logger) { } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/KestrelEngine.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/KestrelEngine.cs index 3d883354ca..2763dce1c6 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/KestrelEngine.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/KestrelEngine.cs @@ -12,6 +12,7 @@ using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions; using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv; using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Infrastructure; using Microsoft.Extensions.Logging; namespace Microsoft.AspNetCore.Server.Kestrel.Internal @@ -40,7 +41,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal public List Threads { get; } = new List(); public IApplicationLifetime AppLifetime => TransportContext.AppLifetime; - public IKestrelTrace Log => TransportContext.Log; + public ILibuvTrace Log => TransportContext.Log; public LibuvTransportOptions TransportOptions => TransportContext.Options; public async Task StopAsync() diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/LibuvTransportFactory.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/LibuvTransportFactory.cs index 526a77f0fa..a05f2972ba 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/LibuvTransportFactory.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/LibuvTransportFactory.cs @@ -7,6 +7,7 @@ using Microsoft.AspNetCore.Server.Kestrel.Internal; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions; using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Infrastructure; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; @@ -34,10 +35,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv throw new ArgumentNullException(nameof(loggerFactory)); } - // REVIEW: Should we change the logger namespace for transport logs? - var logger = loggerFactory.CreateLogger("Microsoft.AspNetCore.Server.Kestrel"); - // TODO: Add LibuvTrace - var trace = new KestrelTrace(logger); + var logger = loggerFactory.CreateLogger("Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv"); + var trace = new LibuvTrace(logger); var threadCount = options.Value.ThreadCount; diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.csproj b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.csproj index a9a71f3970..664ae179b1 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.csproj +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.csproj @@ -4,7 +4,7 @@ Libuv transport for the ASP.NET Core Kestrel cross-platform web server. - netstandard1.3;net46 + netstandard1.3 true aspnetcore;kestrel true @@ -13,12 +13,17 @@ + + + + + - + diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionTests.cs index a37e4c9a94..d74cdf6b90 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionTests.cs @@ -36,7 +36,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { Thread = thread }; - var socket = new MockSocket(mockLibuv, Thread.CurrentThread.ManagedThreadId, serviceContext.Log); + var socket = new MockSocket(mockLibuv, Thread.CurrentThread.ManagedThreadId, serviceContext.TransportContext.Log); var connection = new Connection(listenerContext, socket); connection.Start(); diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/LibuvTransportFactoryTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/LibuvTransportFactoryTests.cs index 2d0dc0c2b7..fb11478116 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/LibuvTransportFactoryTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/LibuvTransportFactoryTests.cs @@ -27,11 +27,11 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } [Fact] - public void LoggerCategoryNameIsKestrelServerNamespace() + public void LoggerCategoryNameIsLibuvTransportNamespace() { var mockLoggerFactory = new Mock(); new LibuvTransportFactory(Options.Create(new LibuvTransportOptions()), new LifetimeNotImplemented(), mockLoggerFactory.Object); - mockLoggerFactory.Verify(factory => factory.CreateLogger("Microsoft.AspNetCore.Server.Kestrel")); + mockLoggerFactory.Verify(factory => factory.CreateLogger("Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv")); } } } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/ListenerPrimaryTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/ListenerPrimaryTests.cs index 48685f4890..8730d598cb 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/ListenerPrimaryTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/ListenerPrimaryTests.cs @@ -11,6 +11,7 @@ using Microsoft.AspNetCore.Server.Kestrel; using Microsoft.AspNetCore.Server.Kestrel.Internal; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Infrastructure; using Microsoft.AspNetCore.Server.KestrelTests.TestHelpers; using Microsoft.AspNetCore.Testing; using Microsoft.Extensions.Logging; @@ -116,7 +117,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests // Create a pipe connection and keep it open without sending any data var connectTcs = new TaskCompletionSource(); - var connectionTrace = new TestKestrelTrace(); + var connectionTrace = new LibuvTrace(new TestApplicationErrorLogger()); var pipe = new UvPipeHandle(connectionTrace); kestrelThreadPrimary.Post(_ => diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/MultipleLoopTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/MultipleLoopTests.cs index e95605a33f..3743da9a78 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/MultipleLoopTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/MultipleLoopTests.cs @@ -7,9 +7,8 @@ using System.Net; using System.Net.Sockets; using System.Runtime.InteropServices; using System.Threading; -using Microsoft.AspNetCore.Server.Kestrel.Internal; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Infrastructure; using Microsoft.AspNetCore.Server.KestrelTests.TestHelpers; using Microsoft.AspNetCore.Testing; using Xunit; @@ -18,13 +17,8 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { public class MultipleLoopTests { - private readonly LibuvFunctions _uv; - private readonly IKestrelTrace _logger; - public MultipleLoopTests() - { - _uv = new LibuvFunctions(); - _logger = new TestKestrelTrace(); - } + private readonly LibuvFunctions _uv = new LibuvFunctions(); + private readonly ILibuvTrace _logger = new LibuvTrace(new TestApplicationErrorLogger()); [Fact] public void InitAndCloseServerPipe() @@ -41,7 +35,6 @@ namespace Microsoft.AspNetCore.Server.KestrelTests pipe.Dispose(); loop.Dispose(); - } [Fact] @@ -70,7 +63,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests return; } - var writeRequest = new UvWriteReq(new KestrelTrace(new TestKestrelTrace())); + var writeRequest = new UvWriteReq(_logger); writeRequest.Init(loop); await writeRequest.WriteAsync( @@ -87,7 +80,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { var loop2 = new UvLoopHandle(_logger); var clientConnectionPipe = new UvPipeHandle(_logger); - var connect = new UvConnectRequest(new KestrelTrace(new TestKestrelTrace())); + var connect = new UvConnectRequest(_logger); loop2.Init(_uv); clientConnectionPipe.Init(loop2, (a, b) => { }, true); @@ -163,7 +156,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests serverConnectionPipeAcceptedEvent.WaitOne(); - var writeRequest = new UvWriteReq(new KestrelTrace(new TestKestrelTrace())); + var writeRequest = new UvWriteReq(_logger); writeRequest.Init(loop); writeRequest.Write2( serverConnectionPipe, @@ -185,7 +178,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { var loop2 = new UvLoopHandle(_logger); var clientConnectionPipe = new UvPipeHandle(_logger); - var connect = new UvConnectRequest(new KestrelTrace(new TestKestrelTrace())); + var connect = new UvConnectRequest(_logger); loop2.Init(_uv); clientConnectionPipe.Init(loop2, (a, b) => { }, true); diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/NetworkingTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/NetworkingTests.cs index 4799438634..cb75b906c2 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/NetworkingTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/NetworkingTests.cs @@ -7,10 +7,10 @@ using System.Net; using System.Net.Sockets; using System.Runtime.InteropServices; using System.Threading.Tasks; -using Microsoft.AspNetCore.Server.Kestrel.Internal; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Infrastructure; using Microsoft.AspNetCore.Testing; +using Moq; using Xunit; namespace Microsoft.AspNetCore.Server.KestrelTests @@ -20,13 +20,8 @@ namespace Microsoft.AspNetCore.Server.KestrelTests /// public class NetworkingTests { - private readonly LibuvFunctions _uv; - private readonly IKestrelTrace _logger; - public NetworkingTests() - { - _uv = new LibuvFunctions(); - _logger = new TestKestrelTrace(); - } + private readonly LibuvFunctions _uv = new LibuvFunctions(); + private readonly ILibuvTrace _logger = new LibuvTrace(new TestApplicationErrorLogger()); [Fact] public void LoopCanBeInitAndClose() @@ -69,7 +64,6 @@ namespace Microsoft.AspNetCore.Server.KestrelTests loop.Dispose(); } - [Fact] public async Task SocketCanListenAndAccept() { @@ -98,7 +92,6 @@ namespace Microsoft.AspNetCore.Server.KestrelTests await t; } - [Fact] public async Task SocketCanRead() { @@ -167,7 +160,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { for (var x = 0; x < 2; x++) { - var req = new UvWriteReq(new KestrelTrace(new TestKestrelTrace())); + var req = new UvWriteReq(_logger); req.Init(loop); var block = ReadableBuffer.Create(new byte[] { 65, 66, 67, 68, 69 }); diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/SocketOutputTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/SocketOutputTests.cs index 351886a3ce..fc5e39df9d 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/SocketOutputTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/SocketOutputTests.cs @@ -520,13 +520,12 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { var pipe = _pipeFactory.Create(pipeOptions); var serviceContext = new TestServiceContext(); - var trace = serviceContext.Log; var frame = new Frame(null, new FrameContext { ServiceContext = serviceContext }); - var socket = new MockSocket(_mockLibuv, _kestrelThread.Loop.ThreadId, new TestKestrelTrace()); - var socketOutput = new SocketOutputProducer(pipe.Writer, frame, "0", trace); - var consumer = new SocketOutputConsumer(pipe.Reader, _kestrelThread, socket, connection ?? new MockConnection(), "0", trace); + var socket = new MockSocket(_mockLibuv, _kestrelThread.Loop.ThreadId, serviceContext.TransportContext.Log); + var socketOutput = new SocketOutputProducer(pipe.Writer, frame, "0", serviceContext.Log); + var consumer = new SocketOutputConsumer(pipe.Reader, _kestrelThread, socket, connection ?? new MockConnection(), "0", serviceContext.TransportContext.Log); var ignore = consumer.StartWrites(); return socketOutput; diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockSocket.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockSocket.cs index fbe24d07bb..5bbc793c6f 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockSocket.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockSocket.cs @@ -1,12 +1,15 @@ -using System; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Infrastructure; namespace Microsoft.AspNetCore.Server.KestrelTests.TestHelpers { class MockSocket : UvStreamHandle { - public MockSocket(LibuvFunctions uv, int threadId, IKestrelTrace logger) : base(logger) + public MockSocket(LibuvFunctions uv, int threadId, ILibuvTrace logger) : base(logger) { CreateMemory(uv, threadId, IntPtr.Size); } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/UvStreamHandleTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/UvStreamHandleTests.cs index 355447f545..153d1b28ef 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/UvStreamHandleTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/UvStreamHandleTests.cs @@ -1,9 +1,10 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Infrastructure; using Microsoft.AspNetCore.Server.KestrelTests.TestHelpers; +using Microsoft.AspNetCore.Testing; using Moq; using Xunit; @@ -14,12 +15,13 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [Fact] public void ReadStopIsIdempotent() { - var mockKestrelTrace = Mock.Of(); - var mockUvLoopHandle = new Mock(mockKestrelTrace).Object; + var libuvTrace = new LibuvTrace(new TestApplicationErrorLogger()); + + var mockUvLoopHandle = new Mock(libuvTrace).Object; mockUvLoopHandle.Init(new MockLibuv()); // Need to mock UvTcpHandle instead of UvStreamHandle, since the latter lacks an Init() method - var mockUvStreamHandle = new Mock(mockKestrelTrace).Object; + var mockUvStreamHandle = new Mock(libuvTrace).Object; mockUvStreamHandle.Init(mockUvLoopHandle, null); mockUvStreamHandle.ReadStop(); diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/UvTimerHandleTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/UvTimerHandleTests.cs index cb5e416263..628b078752 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/UvTimerHandleTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/UvTimerHandleTests.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Infrastructure; using Microsoft.AspNetCore.Testing; using Xunit; @@ -9,15 +10,15 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { public class UvTimerHandleTests { + private readonly ILibuvTrace _trace = new LibuvTrace(new TestApplicationErrorLogger()); + [Fact] public void TestTimeout() { - var trace = new TestKestrelTrace(); - - var loop = new UvLoopHandle(trace); + var loop = new UvLoopHandle(_trace); loop.Init(new LibuvFunctions()); - var timer = new UvTimerHandle(trace); + var timer = new UvTimerHandle(_trace); timer.Init(loop, (a, b) => { }); var callbackInvoked = false; @@ -38,12 +39,10 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [Fact] public void TestRepeat() { - var trace = new TestKestrelTrace(); - - var loop = new UvLoopHandle(trace); + var loop = new UvLoopHandle(_trace); loop.Init(new LibuvFunctions()); - var timer = new UvTimerHandle(trace); + var timer = new UvTimerHandle(_trace); timer.Init(loop, (callback, handle) => { }); var callbackCount = 0; diff --git a/test/shared/TestKestrelTrace.cs b/test/shared/TestKestrelTrace.cs index f9879bda37..93f1c87d40 100644 --- a/test/shared/TestKestrelTrace.cs +++ b/test/shared/TestKestrelTrace.cs @@ -17,20 +17,5 @@ namespace Microsoft.AspNetCore.Testing } public TestApplicationErrorLogger Logger { get; private set; } - - public override void ConnectionRead(string connectionId, int count) - { - //_logger.LogDebug(1, @"Connection id ""{ConnectionId}"" recv {count} bytes.", connectionId, count); - } - - public override void ConnectionWrite(string connectionId, int count) - { - //_logger.LogDebug(1, @"Connection id ""{ConnectionId}"" send {count} bytes.", connectionId, count); - } - - public override void ConnectionWriteCallback(string connectionId, int status) - { - //_logger.LogDebug(1, @"Connection id ""{ConnectionId}"" send finished with status {status}.", connectionId, status); - } } } \ No newline at end of file diff --git a/test/shared/TestServiceContext.cs b/test/shared/TestServiceContext.cs index e01316b622..2c1fb53846 100644 --- a/test/shared/TestServiceContext.cs +++ b/test/shared/TestServiceContext.cs @@ -9,6 +9,7 @@ using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv; using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Infrastructure; namespace Microsoft.AspNetCore.Testing { @@ -16,7 +17,9 @@ namespace Microsoft.AspNetCore.Testing { public TestServiceContext() { - Log = new TestKestrelTrace(); + var logger = new TestApplicationErrorLogger(); + + Log = new TestKestrelTrace(logger); ThreadPool = new LoggingThreadPool(Log); DateHeaderValueManager = new DateHeaderValueManager(systemClock: new MockSystemClock()); DateHeaderValue = DateHeaderValueManager.GetDateHeaderValues().String; @@ -29,7 +32,7 @@ namespace Microsoft.AspNetCore.Testing TransportContext = new LibuvTransportContext { AppLifetime = new LifetimeNotImplemented(), - Log = Log, + Log = new LibuvTrace(logger), Options = new LibuvTransportOptions { ThreadCount = 1, From e0de7f1e1e1e53456e978efcd3318e57a9a3a3ad Mon Sep 17 00:00:00 2001 From: Pranav K Date: Mon, 3 Apr 2017 21:41:10 -0700 Subject: [PATCH 1179/1662] Updating versions to 2.0.0-preview1 --- build/dependencies.props | 2 +- version.props | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/build/dependencies.props b/build/dependencies.props index ac2690b701..1c27397040 100644 --- a/build/dependencies.props +++ b/build/dependencies.props @@ -1,6 +1,6 @@ - 1.2.0-* + 2.0.0-* 0.1.0-* 0.1.0-* 4.3.0 diff --git a/version.props b/version.props index 29f91e170d..e5b7eb2dbe 100644 --- a/version.props +++ b/version.props @@ -1,7 +1,7 @@ - 1.2.0 + 2.0.0 preview1 From 7ceea5323aeb78c5c5a9b0f68f1e52d65073b16f Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Tue, 4 Apr 2017 13:45:02 -0700 Subject: [PATCH 1180/1662] Rename namespaces/directories/classes in Kestrel.Core and Transport.Libuv (#1582). - Put everything in the libuv transport package under `Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.*` namespaces. - Move stuff in Transport.Libuv/Internal/Http and Transport.Libuv/Internal/Infrastructure to Transport.Libuv/Internal (keep the Networking directory for the libuv wrappers). - Add `Libuv` prefix to most libuv internal classes. - Rename `KestrelEngine` to `LibuvTransport`. - Rename `SocketOutputConsumer` to `LibuvOutputConsumer`. - Rename `SocketOutputProducer` to `OutputProducer`. - Fix namespaces in `Microsoft.AspNetCore.Server.Kestrel.Core.` --- samples/SampleApp/Startup.cs | 2 +- .../Adapter/ConnectionAdapterContext.cs | 2 +- .../Adapter/IAdaptedConnection.cs | 2 +- .../Adapter/IConnectionAdapter.cs | 2 +- .../Adapter/Internal/AdaptedPipeline.cs | 4 +- .../Adapter/Internal/LoggingStream.cs | 2 +- .../Adapter/Internal/RawStream.cs | 4 +- .../Adapter/Internal/StreamSocketOutput.cs | 4 +- ...istenOptionsConnectionLoggingExtensions.cs | 4 +- .../Adapter/LoggingConnectionAdapter.cs | 4 +- .../BadHttpRequestException.cs | 6 +- .../Internal/ConnectionHandler.cs | 8 +-- .../Internal/FrameConnection.cs | 10 +-- .../Internal/FrameConnectionContext.cs | 8 +-- .../Internal/Http/ChunkWriter.cs | 2 +- .../Http/ConnectionLifetimeControl.cs | 8 +-- .../Internal/Http/ConnectionOptions.cs | 2 +- .../Internal/Http/DateHeaderValueManager.cs | 4 +- .../Internal/Http/Frame.FeatureCollection.cs | 2 +- .../Internal/Http/Frame.Generated.cs | 2 +- .../Internal/Http/Frame.cs | 6 +- .../Internal/Http/FrameContext.cs | 2 +- .../Internal/Http/FrameDuplexStream.cs | 2 +- .../Internal/Http/FrameHeaders.Generated.cs | 4 +- .../Internal/Http/FrameHeaders.cs | 2 +- .../Internal/Http/FrameOfT.cs | 4 +- .../Internal/Http/FrameRequestHeaders.cs | 4 +- .../Internal/Http/FrameRequestStream.cs | 2 +- .../Internal/Http/FrameResponseHeaders.cs | 2 +- .../Internal/Http/FrameResponseStream.cs | 2 +- .../Internal/Http/FrameStreamState.cs | 2 +- .../Internal/Http/HttpMethod.cs | 2 +- .../Internal/Http/HttpScheme.cs | 2 +- .../Internal/Http/HttpVersion.cs | 2 +- .../Internal/Http/IFrameControl.cs | 2 +- .../Internal/Http/IHttpHeadersHandler.cs | 2 +- .../Internal/Http/IHttpParser.cs | 2 +- .../Internal/Http/IHttpRequestLineHandler.cs | 2 +- .../Internal/Http/ISocketOutput.cs | 2 +- .../Internal/Http/KestrelHttpParser.cs | 4 +- .../Internal/Http/MessageBody.cs | 2 +- ...ketOutputProducer.cs => OutputProducer.cs} | 8 +-- .../Internal/Http/PathNormalizer.cs | 2 +- .../Internal/Http/PipelineExtensions.cs | 2 +- .../Internal/Http/ProduceEndType.cs | 2 +- .../Internal/Http/ReasonPhrases.cs | 2 +- .../Internal/Http/RequestProcessingStatus.cs | 2 +- .../Internal/Http/RequestRejectionReason.cs | 2 +- .../Internal/Http/TransferCoding.cs | 2 +- .../Internal/Infrastructure/AsciiUtilities.cs | 2 +- .../CancellationTokenExtensions.cs | 2 +- .../Internal/Infrastructure/Constants.cs | 2 +- .../Infrastructure/CorrelationIdGenerator.cs | 2 +- .../Internal/Infrastructure/Disposable.cs | 2 +- .../Infrastructure/DisposableAction.cs | 2 +- .../Internal/Infrastructure/HttpUtilities.cs | 4 +- .../Internal/Infrastructure/IKestrelTrace.cs | 2 +- .../Internal/Infrastructure/ISystemClock.cs | 2 +- .../Internal/Infrastructure/IThreadPool.cs | 2 +- .../Infrastructure/InlineLoggingThreadPool.cs | 2 +- .../Infrastructure/KestrelEventSource.cs | 4 +- .../Internal/Infrastructure/KestrelTrace.cs | 4 +- .../Infrastructure/LoggingThreadPool.cs | 2 +- .../Internal/Infrastructure/Streams.cs | 4 +- .../Internal/Infrastructure/SystemClock.cs | 2 +- .../Internal/Infrastructure/UriUtilities.cs | 2 +- .../Internal/InternalKestrelServerOptions.cs | 2 +- .../Internal/KestrelServerOptionsSetup.cs | 2 +- .../Internal/ServiceContext.cs | 6 +- .../KestrelServer.cs | 7 +- .../KestrelServerLimits.cs | 2 +- .../KestrelServerOptions.cs | 2 +- .../ListenOptions.cs | 4 +- .../ServerAddress.cs | 4 +- .../KesterlServerOptionsSystemdExtensions.cs | 2 +- .../HttpsConnectionAdapter.cs | 2 +- .../ListenOptionsHttpsExtensions.cs | 2 +- .../Internal/{Http => }/IAsyncDisposable.cs | 2 +- .../{Infrastructure => }/ILibuvTrace.cs | 2 +- .../{Infrastructure => }/LibuvAwaitable.cs | 4 +- .../Connection.cs => LibuvConnection.cs} | 30 ++++---- ...onContext.cs => LibuvConnectionContext.cs} | 8 +-- ...onManager.cs => LibuvConnectionManager.cs} | 14 ++-- .../Constants.cs => LibuvConstants.cs} | 4 +- ...tputConsumer.cs => LibuvOutputConsumer.cs} | 20 +++--- .../KestrelThread.cs => LibuvThread.cs} | 56 +++++++-------- .../{Infrastructure => }/LibuvTrace.cs | 2 +- .../Internal/LibuvTransportContext.cs | 2 - .../Internal/{Http => }/Listener.cs | 15 ++-- .../Internal/{Http => }/ListenerContext.cs | 7 +- .../Internal/{Http => }/ListenerPrimary.cs | 10 ++- .../Internal/{Http => }/ListenerSecondary.cs | 15 ++-- .../{Libuv.cs => LibuvFunctions.cs} | 2 +- .../Internal/Networking/PlatformApis.cs | 2 +- .../Internal/Networking/SockAddr.cs | 2 +- .../Internal/Networking/UvAsyncHandle.cs | 4 +- .../Internal/Networking/UvConnectRequest.cs | 4 +- .../Internal/Networking/UvException.cs | 2 +- .../Internal/Networking/UvHandle.cs | 4 +- .../Internal/Networking/UvLoopHandle.cs | 4 +- .../Internal/Networking/UvMemory.cs | 5 +- .../Internal/Networking/UvPipeHandle.cs | 4 +- .../Internal/Networking/UvRequest.cs | 7 +- .../Internal/Networking/UvShutdownReq.cs | 4 +- .../Internal/Networking/UvStreamHandle.cs | 7 +- .../Internal/Networking/UvTcpHandle.cs | 4 +- .../Internal/Networking/UvTimerHandle.cs | 4 +- .../Internal/Networking/UvWriteReq.cs | 4 +- .../{Infrastructure => }/WriteReqPool.cs | 16 +++-- .../{KestrelEngine.cs => LibuvTransport.cs} | 20 +++--- .../LibuvTransportFactory.cs | 9 +-- .../WebHostBuilderKestrelExtensions.cs | 4 +- .../AddressRegistrationTests.cs | 3 +- .../BadHttpRequestTests.cs | 5 +- .../EventSourceTests.cs | 2 +- .../KeepAliveTimeoutTests.cs | 1 + .../MaxRequestLineSizeTests.cs | 1 + .../RequestHeaderLimitsTests.cs | 1 + .../RequestHeadersTimeoutTests.cs | 1 + .../RequestTests.cs | 2 +- .../ResponseTests.cs | 5 +- .../DotSegmentRemovalBenchmark.cs | 2 +- .../FrameParsingOverheadBenchmark.cs | 5 +- .../FrameWritingBenchmark.cs | 5 +- .../KestrelHttpParserBenchmark.cs | 2 +- .../KnownStringsBenchmark.cs | 4 +- .../Mocks/MockTrace.cs | 3 +- .../RequestParsingBenchmark.cs | 5 +- .../ResponseHeaderCollectionBenchmark.cs | 5 +- .../ResponseHeadersWritingBenchmark.cs | 13 ++-- .../AsciiDecoding.cs | 2 +- .../ChunkWriterTests.cs | 2 +- .../ChunkedRequestTests.cs | 2 +- .../ChunkedResponseTests.cs | 2 +- .../ConnectionAdapterTests.cs | 4 +- .../ConnectionTests.cs | 12 ++-- .../CreateIPEndpointTests.cs | 2 +- .../DateHeaderValueManagerTests.cs | 2 +- .../EngineTests.cs | 33 ++++----- .../FrameHeadersTests.cs | 2 +- .../FrameRequestHeadersTests.cs | 4 +- .../FrameRequestStreamTests.cs | 2 +- .../FrameResponseHeadersTests.cs | 2 +- .../FrameResponseStreamTests.cs | 2 +- .../FrameTests.cs | 10 +-- .../HttpParserTests.cs | 6 +- .../HttpUtilitiesTest.cs | 4 +- .../HttpsConnectionAdapterTests.cs | 2 +- .../KestrelEventSourceTests.cs | 4 +- .../KestrelServerLimitsTests.cs | 2 +- .../KestrelServerOptionsTests.cs | 2 +- .../KestrelServerTests.cs | 2 +- ...utTests.cs => LibuvOutputConsumerTests.cs} | 63 ++++++++-------- .../ListenerPrimaryTests.cs | 72 +++++++++---------- .../LoggingThreadPoolTests.cs | 2 +- .../MessageBodyTests.cs | 4 +- .../MultipleLoopTests.cs | 4 +- .../NetworkingTests.cs | 5 +- .../PathNormalizerTests.cs | 2 +- .../PipeOptionsTests.cs | 4 +- .../PipelineExtensionTests.cs | 2 +- .../RequestTargetProcessingTests.cs | 6 +- .../ServerAddressTests.cs | 2 +- .../StreamSocketOutputTests.cs | 2 +- .../TestHelpers/MockFrameControl.cs | 2 +- .../TestHelpers/MockLibuv.cs | 2 +- .../TestHelpers/MockSocket.cs | 4 +- .../TestInput.cs | 2 +- .../UvStreamHandleTests.cs | 4 +- .../UvTimerHandleTests.cs | 4 +- .../WebHostBuilderKestrelExtensionsTests.cs | 2 +- test/shared/HttpParsingData.cs | 2 +- test/shared/MockConnection.cs | 4 +- test/shared/MockSocketOutput.cs | 2 +- test/shared/MockSystemClock.cs | 2 +- test/shared/PassThroughConnectionAdapter.cs | 4 +- test/shared/TestApplicationErrorLogger.cs | 3 +- test/shared/TestFrame.cs | 2 +- test/shared/TestKestrelTrace.cs | 2 +- test/shared/TestServer.cs | 19 ++--- test/shared/TestServiceContext.cs | 10 ++- tools/CodeGenerator/FrameFeatureCollection.cs | 2 +- tools/CodeGenerator/KnownHeaders.cs | 4 +- 183 files changed, 459 insertions(+), 493 deletions(-) rename src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/{SocketOutputProducer.cs => OutputProducer.cs} (94%) rename src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/{Http => }/IAsyncDisposable.cs (79%) rename src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/{Infrastructure => }/ILibuvTrace.cs (97%) rename src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/{Infrastructure => }/LibuvAwaitable.cs (93%) rename src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/{Http/Connection.cs => LibuvConnection.cs} (89%) rename src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/{Http/ConnectionContext.cs => LibuvConnectionContext.cs} (77%) rename src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/{Http/ConnectionManager.cs => LibuvConnectionManager.cs} (79%) rename src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/{Infrastructure/Constants.cs => LibuvConstants.cs} (92%) rename src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/{Http/SocketOutputConsumer.cs => LibuvOutputConsumer.cs} (88%) rename src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/{Infrastructure/KestrelThread.cs => LibuvThread.cs} (89%) rename src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/{Infrastructure => }/LibuvTrace.cs (99%) rename src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/{Http => }/Listener.cs (91%) rename src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/{Http => }/ListenerContext.cs (89%) rename src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/{Http => }/ListenerPrimary.cs (97%) rename src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/{Http => }/ListenerSecondary.cs (92%) rename src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/{Libuv.cs => LibuvFunctions.cs} (99%) rename src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/{Infrastructure => }/WriteReqPool.cs (80%) rename src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/{KestrelEngine.cs => LibuvTransport.cs} (85%) rename test/Microsoft.AspNetCore.Server.KestrelTests/{SocketOutputTests.cs => LibuvOutputConsumerTests.cs} (89%) diff --git a/samples/SampleApp/Startup.cs b/samples/SampleApp/Startup.cs index 4a6f015a4c..7f066dc7b5 100644 --- a/samples/SampleApp/Startup.cs +++ b/samples/SampleApp/Startup.cs @@ -8,7 +8,7 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Server.Kestrel.Internal; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal; using Microsoft.Extensions.Logging; namespace SampleApp diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/ConnectionAdapterContext.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/ConnectionAdapterContext.cs index 15a87c9075..380f56ffc8 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/ConnectionAdapterContext.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/ConnectionAdapterContext.cs @@ -3,7 +3,7 @@ using System.IO; -namespace Microsoft.AspNetCore.Server.Kestrel.Adapter +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Adapter { // Even though this only includes the non-adapted ConnectionStream currently, this is a context in case // we want to add more connection metadata later. diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/IAdaptedConnection.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/IAdaptedConnection.cs index aa8c2e820e..793d4b7e0a 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/IAdaptedConnection.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/IAdaptedConnection.cs @@ -4,7 +4,7 @@ using System.IO; using Microsoft.AspNetCore.Http.Features; -namespace Microsoft.AspNetCore.Server.Kestrel.Adapter +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Adapter { public interface IAdaptedConnection { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/IConnectionAdapter.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/IConnectionAdapter.cs index 65140d1952..57c9d904d9 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/IConnectionAdapter.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/IConnectionAdapter.cs @@ -3,7 +3,7 @@ using System.Threading.Tasks; -namespace Microsoft.AspNetCore.Server.Kestrel.Adapter +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Adapter { public interface IConnectionAdapter { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/Internal/AdaptedPipeline.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/Internal/AdaptedPipeline.cs index 54674ae5d4..7d943c0c8d 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/Internal/AdaptedPipeline.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/Internal/AdaptedPipeline.cs @@ -5,9 +5,9 @@ using System; using System.IO; using System.IO.Pipelines; using System.Threading.Tasks; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; -namespace Microsoft.AspNetCore.Server.Kestrel.Adapter.Internal +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal { public class AdaptedPipeline { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/Internal/LoggingStream.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/Internal/LoggingStream.cs index 24fa1edb08..520b456d3b 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/Internal/LoggingStream.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/Internal/LoggingStream.cs @@ -8,7 +8,7 @@ using System.Threading; using System.Threading.Tasks; using Microsoft.Extensions.Logging; -namespace Microsoft.AspNetCore.Server.Kestrel.Adapter.Internal +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal { internal class LoggingStream : Stream { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/Internal/RawStream.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/Internal/RawStream.cs index 6e21958576..170f068801 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/Internal/RawStream.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/Internal/RawStream.cs @@ -6,9 +6,9 @@ using System.IO; using System.IO.Pipelines; using System.Threading; using System.Threading.Tasks; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; -namespace Microsoft.AspNetCore.Server.Kestrel.Adapter.Internal +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal { public class RawStream : Stream { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/Internal/StreamSocketOutput.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/Internal/StreamSocketOutput.cs index 11da4bc24b..9b351e8874 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/Internal/StreamSocketOutput.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/Internal/StreamSocketOutput.cs @@ -6,9 +6,9 @@ using System.IO; using System.IO.Pipelines; using System.Threading; using System.Threading.Tasks; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; -namespace Microsoft.AspNetCore.Server.Kestrel.Adapter.Internal +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal { public class StreamSocketOutput : ISocketOutput { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/ListenOptionsConnectionLoggingExtensions.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/ListenOptionsConnectionLoggingExtensions.cs index 9d5affe345..2c99618aae 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/ListenOptionsConnectionLoggingExtensions.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/ListenOptionsConnectionLoggingExtensions.cs @@ -1,8 +1,8 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using Microsoft.AspNetCore.Server.Kestrel; -using Microsoft.AspNetCore.Server.Kestrel.Adapter; +using Microsoft.AspNetCore.Server.Kestrel.Core; +using Microsoft.AspNetCore.Server.Kestrel.Core.Adapter; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/LoggingConnectionAdapter.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/LoggingConnectionAdapter.cs index 6c25f4ba2f..d0c268b1b4 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/LoggingConnectionAdapter.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/LoggingConnectionAdapter.cs @@ -5,10 +5,10 @@ using System; using System.IO; using System.Threading.Tasks; using Microsoft.AspNetCore.Http.Features; -using Microsoft.AspNetCore.Server.Kestrel.Adapter.Internal; +using Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal; using Microsoft.Extensions.Logging; -namespace Microsoft.AspNetCore.Server.Kestrel.Adapter +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Adapter { public class LoggingConnectionAdapter : IConnectionAdapter { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/BadHttpRequestException.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/BadHttpRequestException.cs index 3c80a8a53a..5a19ea4565 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/BadHttpRequestException.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/BadHttpRequestException.cs @@ -3,11 +3,11 @@ using System.IO; using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; using Microsoft.Extensions.Primitives; -namespace Microsoft.AspNetCore.Server.Kestrel +namespace Microsoft.AspNetCore.Server.Kestrel.Core { public sealed class BadHttpRequestException : IOException { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/ConnectionHandler.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/ConnectionHandler.cs index 23ef1630eb..1376c975ed 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/ConnectionHandler.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/ConnectionHandler.cs @@ -3,11 +3,11 @@ using System.IO.Pipelines; using Microsoft.AspNetCore.Hosting.Server; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions; -namespace Microsoft.AspNetCore.Server.Kestrel.Internal +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal { public class ConnectionHandler : IConnectionHandler { @@ -38,7 +38,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal // TODO: Untangle this mess var frame = new Frame(_application, frameContext); - var outputProducer = new SocketOutputProducer(outputPipe.Writer, frame, connectionId, _serviceContext.Log); + var outputProducer = new OutputProducer(outputPipe.Writer, frame, connectionId, _serviceContext.Log); frame.LifetimeControl = new ConnectionLifetimeControl(connectionId, outputPipe.Reader, outputProducer, _serviceContext.Log); var connection = new FrameConnection(new FrameConnectionContext diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnection.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnection.cs index 8c4805c839..e59689b163 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnection.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnection.cs @@ -6,15 +6,15 @@ using System.Collections.Generic; using System.IO; using System.IO.Pipelines; using System.Threading.Tasks; -using Microsoft.AspNetCore.Server.Kestrel.Adapter; -using Microsoft.AspNetCore.Server.Kestrel.Adapter.Internal; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Core.Adapter; +using Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions; using Microsoft.Extensions.Internal; using Microsoft.Extensions.Logging; -namespace Microsoft.AspNetCore.Server.Kestrel.Internal +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal { public class FrameConnection : IConnectionContext { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnectionContext.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnectionContext.cs index 271c009385..61414ed429 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnectionContext.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnectionContext.cs @@ -3,10 +3,10 @@ using System.Collections.Generic; using System.IO.Pipelines; -using Microsoft.AspNetCore.Server.Kestrel.Adapter; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Core.Adapter; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; -namespace Microsoft.AspNetCore.Server.Kestrel.Internal +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal { public class FrameConnectionContext { @@ -15,7 +15,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal public PipeFactory PipeFactory { get; set; } public List ConnectionAdapters { get; set; } public Frame Frame { get; set; } - public SocketOutputProducer OutputProducer { get; set; } + public OutputProducer OutputProducer { get; set; } public IPipe Input { get; set; } public IPipe Output { get; set; } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/ChunkWriter.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/ChunkWriter.cs index 6ffbc577b9..27b7dadba5 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/ChunkWriter.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/ChunkWriter.cs @@ -5,7 +5,7 @@ using System; using System.IO.Pipelines; using System.Text; -namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { public static class ChunkWriter { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/ConnectionLifetimeControl.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/ConnectionLifetimeControl.cs index ae7d98ba3f..7e44f26f59 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/ConnectionLifetimeControl.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/ConnectionLifetimeControl.cs @@ -2,16 +2,16 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.IO.Pipelines; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; -namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { public class ConnectionLifetimeControl { public ConnectionLifetimeControl( string connectionId, IPipeReader outputPipeReader, - SocketOutputProducer outputProducer, + OutputProducer outputProducer, IKestrelTrace log) { ConnectionId = connectionId; @@ -22,7 +22,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http private string ConnectionId { get; } private IPipeReader OutputReader { get; } - private SocketOutputProducer OutputProducer { get; } + private OutputProducer OutputProducer { get; } private IKestrelTrace Log { get; } public void End(ProduceEndType endType) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/ConnectionOptions.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/ConnectionOptions.cs index 72d4eeb5d1..71817aed69 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/ConnectionOptions.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/ConnectionOptions.cs @@ -3,7 +3,7 @@ using System; -namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { [Flags] public enum ConnectionOptions diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/DateHeaderValueManager.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/DateHeaderValueManager.cs index 57f68967a4..349345e5fe 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/DateHeaderValueManager.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/DateHeaderValueManager.cs @@ -4,10 +4,10 @@ using System; using System.Text; using System.Threading; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; using Microsoft.Net.Http.Headers; -namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { /// /// Manages the generation of the date header value. diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.FeatureCollection.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.FeatureCollection.cs index c1dada9715..abf4bddf7d 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.FeatureCollection.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.FeatureCollection.cs @@ -12,7 +12,7 @@ using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http.Features; using Microsoft.Extensions.Primitives; -namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { public partial class Frame : IFeatureCollection, IHttpRequestFeature, diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.Generated.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.Generated.cs index a1caf15e33..181e54d667 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.Generated.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.Generated.cs @@ -4,7 +4,7 @@ using System; using System.Collections.Generic; -namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { public partial class Frame { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.cs index 6c83f20b3e..35e7f4cdea 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.cs @@ -14,8 +14,8 @@ using System.Text.Encodings.Web.Utf8; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Server.Kestrel.Adapter; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Core.Adapter; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions; using Microsoft.Extensions.Internal; using Microsoft.Extensions.Logging; @@ -23,7 +23,7 @@ using Microsoft.Extensions.Primitives; // ReSharper disable AccessToModifiedClosure -namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { public abstract partial class Frame : IFrameControl, IHttpRequestLineHandler, IHttpHeadersHandler { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameContext.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameContext.cs index cbccf8684a..28069ce4ae 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameContext.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameContext.cs @@ -3,7 +3,7 @@ using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions; -namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { public class FrameContext { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameDuplexStream.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameDuplexStream.cs index 10469dc05d..b427651405 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameDuplexStream.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameDuplexStream.cs @@ -8,7 +8,7 @@ using System.IO; using System.Threading; using System.Threading.Tasks; -namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { class FrameDuplexStream : Stream { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameHeaders.Generated.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameHeaders.Generated.cs index 8cc1ad75bd..8d182b0234 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameHeaders.Generated.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameHeaders.Generated.cs @@ -4,11 +4,11 @@ using System; using System.Collections.Generic; using System.IO.Pipelines; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; using Microsoft.Extensions.Primitives; using Microsoft.Net.Http.Headers; -namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { public partial class FrameRequestHeaders diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameHeaders.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameHeaders.cs index 312fc0dfd7..2432afa6a3 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameHeaders.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameHeaders.cs @@ -9,7 +9,7 @@ using System.Runtime.CompilerServices; using Microsoft.AspNetCore.Http; using Microsoft.Extensions.Primitives; -namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { public abstract class FrameHeaders : IHeaderDictionary { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameOfT.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameOfT.cs index 75edc1659c..0d4ffe7544 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameOfT.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameOfT.cs @@ -6,11 +6,11 @@ using System.IO; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Hosting.Server; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions; using Microsoft.Extensions.Logging; -namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { public class Frame : Frame { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameRequestHeaders.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameRequestHeaders.cs index b7432853b7..f210549803 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameRequestHeaders.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameRequestHeaders.cs @@ -5,11 +5,11 @@ using System; using System.Collections; using System.Collections.Generic; using System.Runtime.CompilerServices; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; using Microsoft.Extensions.Primitives; using Microsoft.Net.Http.Headers; -namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { public partial class FrameRequestHeaders : FrameHeaders { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameRequestStream.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameRequestStream.cs index 3d084adafd..93f0db1018 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameRequestStream.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameRequestStream.cs @@ -7,7 +7,7 @@ using System.Threading; using System.Threading.Tasks; using Microsoft.Extensions.Internal; -namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { class FrameRequestStream : Stream { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameResponseHeaders.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameResponseHeaders.cs index 9fc752f6cd..262496dd60 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameResponseHeaders.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameResponseHeaders.cs @@ -9,7 +9,7 @@ using System.Runtime.CompilerServices; using Microsoft.Extensions.Primitives; using Microsoft.Net.Http.Headers; -namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { public partial class FrameResponseHeaders : FrameHeaders { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameResponseStream.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameResponseStream.cs index 3100520393..699aa90f92 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameResponseStream.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameResponseStream.cs @@ -6,7 +6,7 @@ using System.IO; using System.Threading; using System.Threading.Tasks; -namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { class FrameResponseStream : Stream { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameStreamState.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameStreamState.cs index 8e1e26eaa5..a46cb733eb 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameStreamState.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameStreamState.cs @@ -1,7 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { enum FrameStreamState { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/HttpMethod.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/HttpMethod.cs index 88b4ed73c2..0aa230cf50 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/HttpMethod.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/HttpMethod.cs @@ -1,7 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { public enum HttpMethod: byte { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/HttpScheme.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/HttpScheme.cs index 23f0bed5b9..dfd4642f3d 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/HttpScheme.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/HttpScheme.cs @@ -1,7 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { public enum HttpScheme { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/HttpVersion.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/HttpVersion.cs index f3a015af88..5ca3e8bdba 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/HttpVersion.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/HttpVersion.cs @@ -1,7 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { public enum HttpVersion { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/IFrameControl.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/IFrameControl.cs index 0303188e3a..5ad87bc264 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/IFrameControl.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/IFrameControl.cs @@ -5,7 +5,7 @@ using System; using System.Threading; using System.Threading.Tasks; -namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { public interface IFrameControl { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/IHttpHeadersHandler.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/IHttpHeadersHandler.cs index 57468508d1..9a322f0da9 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/IHttpHeadersHandler.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/IHttpHeadersHandler.cs @@ -3,7 +3,7 @@ using System; -namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { public interface IHttpHeadersHandler { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/IHttpParser.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/IHttpParser.cs index ee888bea1f..0af7ef01b7 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/IHttpParser.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/IHttpParser.cs @@ -3,7 +3,7 @@ using System.IO.Pipelines; -namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { public interface IHttpParser { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/IHttpRequestLineHandler.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/IHttpRequestLineHandler.cs index 83481002b3..ac91138512 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/IHttpRequestLineHandler.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/IHttpRequestLineHandler.cs @@ -3,7 +3,7 @@ using System; -namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { public interface IHttpRequestLineHandler { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/ISocketOutput.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/ISocketOutput.cs index 379dd52318..494e6df8de 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/ISocketOutput.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/ISocketOutput.cs @@ -6,7 +6,7 @@ using System.IO.Pipelines; using System.Threading; using System.Threading.Tasks; -namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { /// /// Operations performed for buffered socket output diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/KestrelHttpParser.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/KestrelHttpParser.cs index b78d04b69c..c1131fd6c1 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/KestrelHttpParser.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/KestrelHttpParser.cs @@ -5,10 +5,10 @@ using System; using System.IO.Pipelines; using System.Numerics; using System.Runtime.CompilerServices; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; using Microsoft.Extensions.Logging; -namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { public class KestrelHttpParser : IHttpParser { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/MessageBody.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/MessageBody.cs index 03130d7628..837a30c027 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/MessageBody.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/MessageBody.cs @@ -9,7 +9,7 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.Extensions.Internal; -namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { public abstract class MessageBody { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/SocketOutputProducer.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/OutputProducer.cs similarity index 94% rename from src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/SocketOutputProducer.cs rename to src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/OutputProducer.cs index 956fd5a336..7aee461ca7 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/SocketOutputProducer.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/OutputProducer.cs @@ -5,12 +5,12 @@ using System; using System.IO.Pipelines; using System.Threading; using System.Threading.Tasks; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; using Microsoft.Extensions.Internal; -namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { - public class SocketOutputProducer : ISocketOutput, IDisposable + public class OutputProducer : ISocketOutput, IDisposable { private static readonly ArraySegment _emptyData = new ArraySegment(new byte[0]); @@ -33,7 +33,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http private readonly object _flushLock = new object(); private readonly Action _onFlushCallback; - public SocketOutputProducer(IPipeWriter pipe, Frame frame, string connectionId, IKestrelTrace log) + public OutputProducer(IPipeWriter pipe, Frame frame, string connectionId, IKestrelTrace log) { _pipe = pipe; _frame = frame; diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/PathNormalizer.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/PathNormalizer.cs index 99f49f287c..de076e1849 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/PathNormalizer.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/PathNormalizer.cs @@ -4,7 +4,7 @@ using System; using System.Diagnostics; -namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { public static class PathNormalizer { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/PipelineExtensions.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/PipelineExtensions.cs index 4109119da9..233544deb6 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/PipelineExtensions.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/PipelineExtensions.cs @@ -7,7 +7,7 @@ using System.IO.Pipelines; using System.Runtime.CompilerServices; using System.Threading.Tasks; -namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { public static class PipelineExtensions { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/ProduceEndType.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/ProduceEndType.cs index 06da2e11e6..72107f90e7 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/ProduceEndType.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/ProduceEndType.cs @@ -1,7 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { public enum ProduceEndType { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/ReasonPhrases.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/ReasonPhrases.cs index d3e916606e..36eaaacf87 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/ReasonPhrases.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/ReasonPhrases.cs @@ -6,7 +6,7 @@ using System.Globalization; using System.Text; using Microsoft.AspNetCore.Http; -namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { public static class ReasonPhrases { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/RequestProcessingStatus.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/RequestProcessingStatus.cs index e8ebb73784..f6e4248047 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/RequestProcessingStatus.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/RequestProcessingStatus.cs @@ -1,7 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { public enum RequestProcessingStatus { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/RequestRejectionReason.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/RequestRejectionReason.cs index 33aec0fc67..e6b70b7551 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/RequestRejectionReason.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/RequestRejectionReason.cs @@ -1,7 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { public enum RequestRejectionReason { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/TransferCoding.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/TransferCoding.cs index 3bfa8cc74b..39c52ba6aa 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/TransferCoding.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/TransferCoding.cs @@ -3,7 +3,7 @@ using System; -namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { [Flags] public enum TransferCoding diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/AsciiUtilities.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/AsciiUtilities.cs index 1959ca23d9..5a95493a28 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/AsciiUtilities.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/AsciiUtilities.cs @@ -1,7 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure { internal class AsciiUtilities { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/CancellationTokenExtensions.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/CancellationTokenExtensions.cs index 1d4275a314..c5d0392f00 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/CancellationTokenExtensions.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/CancellationTokenExtensions.cs @@ -4,7 +4,7 @@ using System; using System.Threading; -namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure { internal static class CancellationTokenExtensions { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/Constants.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/Constants.cs index f18246c655..8b22cd7cc4 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/Constants.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/Constants.cs @@ -1,7 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure { internal static class Constants { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/CorrelationIdGenerator.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/CorrelationIdGenerator.cs index 81233b3a3f..fc161d4116 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/CorrelationIdGenerator.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/CorrelationIdGenerator.cs @@ -4,7 +4,7 @@ using System; using System.Threading; -namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure { internal static class CorrelationIdGenerator { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/Disposable.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/Disposable.cs index fb0e68855f..620e749fe6 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/Disposable.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/Disposable.cs @@ -3,7 +3,7 @@ using System; -namespace Microsoft.AspNetCore.Server.Kestrel.Internal +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure { /// /// Summary description for Disposable diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/DisposableAction.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/DisposableAction.cs index 4336437ae9..ff65931e24 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/DisposableAction.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/DisposableAction.cs @@ -4,7 +4,7 @@ using System; using System.Threading; -namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure { internal class DisposableAction : IDisposable { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/HttpUtilities.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/HttpUtilities.cs index b4dafbd3a7..8e42f383e7 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/HttpUtilities.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/HttpUtilities.cs @@ -6,9 +6,9 @@ using System.Diagnostics; using System.Runtime.CompilerServices; using System.Text; using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; -namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure { public static class HttpUtilities { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/IKestrelTrace.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/IKestrelTrace.cs index 6fc3c610fb..f14c1b33c7 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/IKestrelTrace.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/IKestrelTrace.cs @@ -4,7 +4,7 @@ using System; using Microsoft.Extensions.Logging; -namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure { public interface IKestrelTrace : ILogger { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/ISystemClock.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/ISystemClock.cs index 0cf54d7e64..e29312dda8 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/ISystemClock.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/ISystemClock.cs @@ -3,7 +3,7 @@ using System; -namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure { /// /// Abstracts the system clock to facilitate testing. diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/IThreadPool.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/IThreadPool.cs index 48db68ff10..9f9037630f 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/IThreadPool.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/IThreadPool.cs @@ -6,7 +6,7 @@ using System.IO.Pipelines; using System.Threading; using System.Threading.Tasks; -namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure { public interface IThreadPool : IScheduler { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/InlineLoggingThreadPool.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/InlineLoggingThreadPool.cs index 8945ec0827..b81bbfab0a 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/InlineLoggingThreadPool.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/InlineLoggingThreadPool.cs @@ -6,7 +6,7 @@ using System.Threading; using System.Threading.Tasks; using Microsoft.Extensions.Logging; -namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure { public class InlineLoggingThreadPool : IThreadPool { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/KestrelEventSource.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/KestrelEventSource.cs index 18f1ab33fa..2e1b942de3 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/KestrelEventSource.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/KestrelEventSource.cs @@ -3,10 +3,10 @@ using System.Diagnostics.Tracing; using System.Runtime.CompilerServices; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions; -namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure { [EventSource(Name = "Microsoft-AspNetCore-Server-Kestrel")] public sealed class KestrelEventSource : EventSource diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/KestrelTrace.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/KestrelTrace.cs index fb9a0a4736..cc7204e203 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/KestrelTrace.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/KestrelTrace.cs @@ -2,10 +2,10 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; using Microsoft.Extensions.Logging; -namespace Microsoft.AspNetCore.Server.Kestrel.Internal +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal { /// /// Summary description for KestrelTrace diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/LoggingThreadPool.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/LoggingThreadPool.cs index d0cff5e9ac..6fcad137fd 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/LoggingThreadPool.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/LoggingThreadPool.cs @@ -6,7 +6,7 @@ using System.Threading; using System.Threading.Tasks; using Microsoft.Extensions.Logging; -namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure { public class LoggingThreadPool : IThreadPool { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/Streams.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/Streams.cs index 18712eed2f..61654b3e56 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/Streams.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/Streams.cs @@ -1,9 +1,9 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; -namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure { class Streams { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/SystemClock.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/SystemClock.cs index eb4e7e099e..1284ef9f4f 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/SystemClock.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/SystemClock.cs @@ -3,7 +3,7 @@ using System; -namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure { /// /// Provides access to the normal system clock. diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/UriUtilities.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/UriUtilities.cs index defcb9eb4f..272b30cabf 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/UriUtilities.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/UriUtilities.cs @@ -1,7 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure { public class UriUtilities { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/InternalKestrelServerOptions.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/InternalKestrelServerOptions.cs index e8d98268cd..68b8808ddc 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/InternalKestrelServerOptions.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/InternalKestrelServerOptions.cs @@ -1,7 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -namespace Microsoft.AspNetCore.Server.Kestrel.Internal +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal { public class InternalKestrelServerOptions { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/KestrelServerOptionsSetup.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/KestrelServerOptionsSetup.cs index 93fda55f07..18c96e2039 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/KestrelServerOptionsSetup.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/KestrelServerOptionsSetup.cs @@ -4,7 +4,7 @@ using System; using Microsoft.Extensions.Options; -namespace Microsoft.AspNetCore.Server.Kestrel.Internal +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal { public class KestrelServerOptionsSetup : IConfigureOptions { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/ServiceContext.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/ServiceContext.cs index 3c3750c6c2..41a37f2fe5 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/ServiceContext.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/ServiceContext.cs @@ -2,10 +2,10 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; -namespace Microsoft.AspNetCore.Server.Kestrel.Internal +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal { public class ServiceContext { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/KestrelServer.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/KestrelServer.cs index 921d77fa78..d84f6f7a19 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/KestrelServer.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/KestrelServer.cs @@ -12,14 +12,13 @@ using Microsoft.AspNetCore.Hosting.Server; using Microsoft.AspNetCore.Hosting.Server.Features; using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal; -using Microsoft.AspNetCore.Server.Kestrel.Internal; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; -namespace Microsoft.AspNetCore.Server.Kestrel +namespace Microsoft.AspNetCore.Server.Kestrel.Core { public class KestrelServer : IServer { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/KestrelServerLimits.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/KestrelServerLimits.cs index ac8a047542..b42d2db6a9 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/KestrelServerLimits.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/KestrelServerLimits.cs @@ -3,7 +3,7 @@ using System; -namespace Microsoft.AspNetCore.Server.Kestrel +namespace Microsoft.AspNetCore.Server.Kestrel.Core { public class KestrelServerLimits { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/KestrelServerOptions.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/KestrelServerOptions.cs index ca53bb1d49..b9a712e0ca 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/KestrelServerOptions.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/KestrelServerOptions.cs @@ -5,7 +5,7 @@ using System; using System.Collections.Generic; using System.Net; -namespace Microsoft.AspNetCore.Server.Kestrel +namespace Microsoft.AspNetCore.Server.Kestrel.Core { /// /// Provides programmatic configuration of Kestrel-specific features. diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/ListenOptions.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/ListenOptions.cs index 5fadb48fb4..8777ba98bc 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/ListenOptions.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/ListenOptions.cs @@ -4,10 +4,10 @@ using System; using System.Collections.Generic; using System.Net; -using Microsoft.AspNetCore.Server.Kestrel.Adapter; +using Microsoft.AspNetCore.Server.Kestrel.Core.Adapter; using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions; -namespace Microsoft.AspNetCore.Server.Kestrel +namespace Microsoft.AspNetCore.Server.Kestrel.Core { /// /// Describes either an , Unix domain socket path, or a file descriptor for an already open diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/ServerAddress.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/ServerAddress.cs index 7836c0658e..4f64268087 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/ServerAddress.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/ServerAddress.cs @@ -4,9 +4,9 @@ using System; using System.Diagnostics; using System.Globalization; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; -namespace Microsoft.AspNetCore.Server.Kestrel +namespace Microsoft.AspNetCore.Server.Kestrel.Core { public class ServerAddress { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Systemd/KesterlServerOptionsSystemdExtensions.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Systemd/KesterlServerOptionsSystemdExtensions.cs index ca24796a65..e26b4d4cc0 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Systemd/KesterlServerOptionsSystemdExtensions.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Systemd/KesterlServerOptionsSystemdExtensions.cs @@ -4,7 +4,7 @@ using System; using System.Diagnostics; using System.Globalization; -using Microsoft.AspNetCore.Server.Kestrel; +using Microsoft.AspNetCore.Server.Kestrel.Core; namespace Microsoft.AspNetCore.Hosting { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Https/HttpsConnectionAdapter.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Https/HttpsConnectionAdapter.cs index d56d440512..7f5aa71eb0 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Https/HttpsConnectionAdapter.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Https/HttpsConnectionAdapter.cs @@ -7,7 +7,7 @@ using System.Net.Security; using System.Security.Cryptography.X509Certificates; using System.Threading.Tasks; using Microsoft.AspNetCore.Http.Features; -using Microsoft.AspNetCore.Server.Kestrel.Adapter; +using Microsoft.AspNetCore.Server.Kestrel.Core.Adapter; using Microsoft.AspNetCore.Server.Kestrel.Https.Internal; using Microsoft.Extensions.Logging; diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Https/ListenOptionsHttpsExtensions.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Https/ListenOptionsHttpsExtensions.cs index f757beb3b5..856c91a1c2 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Https/ListenOptionsHttpsExtensions.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Https/ListenOptionsHttpsExtensions.cs @@ -3,7 +3,7 @@ using System.IO; using System.Security.Cryptography.X509Certificates; -using Microsoft.AspNetCore.Server.Kestrel; +using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.AspNetCore.Server.Kestrel.Https; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Http/IAsyncDisposable.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/IAsyncDisposable.cs similarity index 79% rename from src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Http/IAsyncDisposable.cs rename to src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/IAsyncDisposable.cs index 0a6115a6dd..8c98c2127c 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Http/IAsyncDisposable.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/IAsyncDisposable.cs @@ -3,7 +3,7 @@ using System.Threading.Tasks; -namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http +namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal { interface IAsyncDisposable { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Infrastructure/ILibuvTrace.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/ILibuvTrace.cs similarity index 97% rename from src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Infrastructure/ILibuvTrace.cs rename to src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/ILibuvTrace.cs index 432d5370a1..6f9d2c289a 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Infrastructure/ILibuvTrace.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/ILibuvTrace.cs @@ -4,7 +4,7 @@ using System; using Microsoft.Extensions.Logging; -namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Infrastructure +namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal { public interface ILibuvTrace : ILogger { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Infrastructure/LibuvAwaitable.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvAwaitable.cs similarity index 93% rename from src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Infrastructure/LibuvAwaitable.cs rename to src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvAwaitable.cs index 110c1316f1..da1a8661ef 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Infrastructure/LibuvAwaitable.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvAwaitable.cs @@ -5,9 +5,9 @@ using System; using System.Runtime.CompilerServices; using System.Threading; using System.Threading.Tasks; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking; -namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure +namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal { public class LibuvAwaitable : ICriticalNotifyCompletion where TRequest : UvRequest { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Http/Connection.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvConnection.cs similarity index 89% rename from src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Http/Connection.cs rename to src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvConnection.cs index 66c88f630a..01aa2b24e1 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Http/Connection.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvConnection.cs @@ -7,15 +7,13 @@ using System.IO; using System.IO.Pipelines; using System.Threading; using System.Threading.Tasks; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking; using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions; -using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Infrastructure; using Microsoft.Extensions.Logging; -namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http +namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal { - public class Connection : ConnectionContext, ITimeoutControl + public class LibuvConnection : LibuvConnectionContext, ITimeoutControl { private const int MinAllocBufferSize = 2048; @@ -35,7 +33,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http private TimeoutAction _timeoutAction; private WritableBuffer? _currentWritableBuffer; - public Connection(ListenerContext context, UvStreamHandle socket) : base(context) + public LibuvConnection(ListenerContext context, UvStreamHandle socket) : base(context) { _socket = socket; socket.Connection = this; @@ -52,17 +50,17 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } // For testing - public Connection() + public LibuvConnection() { } public string ConnectionId { get; set; } public IPipeWriter Input { get; set; } - public SocketOutputConsumer Output { get; set; } + public LibuvOutputConsumer Output { get; set; } private ILibuvTrace Log => ListenerContext.TransportContext.Log; private IConnectionHandler ConnectionHandler => ListenerContext.TransportContext.ConnectionHandler; - private KestrelThread Thread => ListenerContext.Thread; + private LibuvThread Thread => ListenerContext.Thread; public void Start() { @@ -72,7 +70,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http ConnectionId = _connectionContext.ConnectionId; Input = _connectionContext.Input; - Output = new SocketOutputConsumer(_connectionContext.Output, Thread, _socket, this, ConnectionId, Log); + Output = new LibuvOutputConsumer(_connectionContext.Output, Thread, _socket, this, ConnectionId, Log); // Start socket prior to applying the ConnectionAdapter _socket.ReadStart(_allocCallback, _readCallback, this); @@ -132,7 +130,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http private static LibuvFunctions.uv_buf_t AllocCallback(UvStreamHandle handle, int suggestedSize, object state) { - return ((Connection)state).OnAlloc(handle, suggestedSize); + return ((LibuvConnection)state).OnAlloc(handle, suggestedSize); } private unsafe LibuvFunctions.uv_buf_t OnAlloc(UvStreamHandle handle, int suggestedSize) @@ -151,13 +149,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http private static void ReadCallback(UvStreamHandle handle, int status, object state) { - ((Connection)state).OnRead(handle, status); + ((LibuvConnection)state).OnRead(handle, status); } private async void OnRead(UvStreamHandle handle, int status) { var normalRead = status >= 0; - var normalDone = status == Constants.EOF; + var normalDone = status == LibuvConstants.EOF; var errorDone = !(normalDone || normalRead); var readCount = normalRead ? status : 0; @@ -183,7 +181,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http handle.Libuv.Check(status, out uvError); // Log connection resets at a lower (Debug) level. - if (status == Constants.ECONNRESET) + if (status == LibuvConstants.ECONNRESET) { Log.ConnectionReset(ConnectionId); error = new ConnectionResetException(uvError.Message, uvError); @@ -273,8 +271,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { _timeoutAction = timeoutAction; - // Add KestrelThread.HeartbeatMilliseconds extra milliseconds since this can be called right before the next heartbeat. - Interlocked.Exchange(ref _timeoutTimestamp, _lastTimestamp + milliseconds + KestrelThread.HeartbeatMilliseconds); + // Add LibuvThread.HeartbeatMilliseconds extra milliseconds since this can be called right before the next heartbeat. + Interlocked.Exchange(ref _timeoutTimestamp, _lastTimestamp + milliseconds + LibuvThread.HeartbeatMilliseconds); } } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Http/ConnectionContext.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvConnectionContext.cs similarity index 77% rename from src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Http/ConnectionContext.cs rename to src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvConnectionContext.cs index 25b64697b9..b1a198c8f8 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Http/ConnectionContext.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvConnectionContext.cs @@ -5,15 +5,15 @@ using System.IO.Pipelines; using System.Net; using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions; -namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http +namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal { - public class ConnectionContext : IConnectionInformation + public class LibuvConnectionContext : IConnectionInformation { - public ConnectionContext() + public LibuvConnectionContext() { } - public ConnectionContext(ListenerContext context) + public LibuvConnectionContext(ListenerContext context) { ListenerContext = context; } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Http/ConnectionManager.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvConnectionManager.cs similarity index 79% rename from src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Http/ConnectionManager.cs rename to src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvConnectionManager.cs index 302887aa8a..14f314510d 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Http/ConnectionManager.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvConnectionManager.cs @@ -4,15 +4,15 @@ using System; using System.Collections.Generic; using System.Threading.Tasks; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking; -namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http +namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal { - public class ConnectionManager + public class LibuvConnectionManager { - private readonly KestrelThread _thread; + private readonly LibuvThread _thread; - public ConnectionManager(KestrelThread thread) + public LibuvConnectionManager(LibuvThread thread) { _thread = thread; } @@ -27,7 +27,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http return await WalkConnectionsAsync((connectionManager, tcs) => connectionManager.WalkConnectionsAndAbortCore(tcs), timeout).ConfigureAwait(false); } - private async Task WalkConnectionsAsync(Action> action, TimeSpan timeout) + private async Task WalkConnectionsAsync(Action> action, TimeSpan timeout) { var tcs = new TaskCompletionSource(); @@ -46,7 +46,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http WalkConnectionsCore(connection => connection.AbortAsync(), tcs); } - private void WalkConnectionsCore(Func action, TaskCompletionSource tcs) + private void WalkConnectionsCore(Func action, TaskCompletionSource tcs) { var tasks = new List(); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Infrastructure/Constants.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvConstants.cs similarity index 92% rename from src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Infrastructure/Constants.cs rename to src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvConstants.cs index 10836774a1..70424f7b0c 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Infrastructure/Constants.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvConstants.cs @@ -3,9 +3,9 @@ using System.Runtime.InteropServices; -namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure +namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal { - internal static class Constants + internal static class LibuvConstants { public const int ListenBacklog = 128; diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Http/SocketOutputConsumer.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvOutputConsumer.cs similarity index 88% rename from src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Http/SocketOutputConsumer.cs rename to src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvOutputConsumer.cs index 7087a46e79..e96cf35d85 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Http/SocketOutputConsumer.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvOutputConsumer.cs @@ -4,28 +4,26 @@ using System; using System.IO.Pipelines; using System.Threading.Tasks; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; -using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking; -namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http +namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal { - public class SocketOutputConsumer + public class LibuvOutputConsumer { - private readonly KestrelThread _thread; + private readonly LibuvThread _thread; private readonly UvStreamHandle _socket; - private readonly Connection _connection; + private readonly LibuvConnection _connection; private readonly string _connectionId; private readonly ILibuvTrace _log; private readonly WriteReqPool _writeReqPool; private readonly IPipeReader _pipe; - public SocketOutputConsumer( + public LibuvOutputConsumer( IPipeReader pipe, - KestrelThread thread, + LibuvThread thread, UvStreamHandle socket, - Connection connection, + LibuvConnection connection, string connectionId, ILibuvTrace log) { @@ -104,7 +102,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http else { // Log connection resets at a lower (Debug) level. - if (status == Constants.ECONNRESET) + if (status == LibuvConstants.ECONNRESET) { _log.ConnectionReset(_connectionId); } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Infrastructure/KestrelThread.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvThread.cs similarity index 89% rename from src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Infrastructure/KestrelThread.cs rename to src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvThread.cs index fd3162f6ce..aee08aa862 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Infrastructure/KestrelThread.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvThread.cs @@ -9,18 +9,12 @@ using System.Runtime.InteropServices; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Hosting; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; -using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking; using Microsoft.Extensions.Logging; -namespace Microsoft.AspNetCore.Server.Kestrel.Internal +namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal { - /// - /// Summary description for KestrelThread - /// - public class KestrelThread : IScheduler + public class LibuvThread : IScheduler { public const long HeartbeatMilliseconds = 1000; @@ -28,8 +22,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal { var streamHandle = UvMemory.FromIntPtr(ptr) as UvStreamHandle; var thisHandle = GCHandle.FromIntPtr(arg); - var kestrelThread = (KestrelThread)thisHandle.Target; - streamHandle?.Connection?.Tick(kestrelThread.Now); + var libuvThread = (LibuvThread)thisHandle.Target; + streamHandle?.Connection?.Tick(libuvThread.Now); }; // maximum times the work queues swapped and are processed in a single pass @@ -37,7 +31,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal // otherwise it needs to wait till the next pass of the libuv loop private readonly int _maxLoops = 8; - private readonly KestrelEngine _engine; + private readonly LibuvTransport _transport; private readonly IApplicationLifetime _appLifetime; private readonly Thread _thread; private readonly TaskCompletionSource _threadTcs = new TaskCompletionSource(); @@ -57,16 +51,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal private readonly TimeSpan _shutdownTimeout; private IntPtr _thisPtr; - public KestrelThread(KestrelEngine engine) + public LibuvThread(LibuvTransport transport) { - _engine = engine; - _appLifetime = engine.AppLifetime; - _log = engine.Log; - _shutdownTimeout = engine.TransportOptions.ShutdownTimeout; + _transport = transport; + _appLifetime = transport.AppLifetime; + _log = transport.Log; + _shutdownTimeout = transport.TransportOptions.ShutdownTimeout; _loop = new UvLoopHandle(_log); _post = new UvAsyncHandle(_log); _thread = new Thread(ThreadStart); - _thread.Name = "KestrelThread - libuv"; + _thread.Name = nameof(LibuvThread); _heartbeatTimer = new UvTimerHandle(_log); #if !DEBUG // Mark the thread as being as unimportant to keeping the process alive. @@ -77,12 +71,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal QueueCloseAsyncHandle = EnqueueCloseHandle; PipelineFactory = new PipeFactory(); WriteReqPool = new WriteReqPool(this, _log); - ConnectionManager = new ConnectionManager(this); + ConnectionManager = new LibuvConnectionManager(this); } // For testing - public KestrelThread(KestrelEngine engine, int maxLoops) - : this(engine) + public LibuvThread(LibuvTransport transport, int maxLoops) + : this(transport) { _maxLoops = maxLoops; } @@ -91,7 +85,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal public PipeFactory PipelineFactory { get; } - public ConnectionManager ConnectionManager { get; } + public LibuvConnectionManager ConnectionManager { get; } public WriteReqPool WriteReqPool { get; } @@ -140,7 +134,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal Post(t => t.OnStopImmediate()); if (!await WaitAsync(_threadTcs.Task, stepTimeout).ConfigureAwait(false)) { - _log.LogCritical("KestrelThread.StopAsync failed to terminate libuv thread."); + _log.LogCritical($"{nameof(LibuvThread)}.{nameof(StopAsync)} failed to terminate libuv thread."); } } } @@ -149,7 +143,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal // Until we rework this logic, ODEs are bound to happen sometimes. if (!await WaitAsync(_threadTcs.Task, stepTimeout).ConfigureAwait(false)) { - _log.LogCritical("KestrelThread.StopAsync failed to terminate libuv thread."); + _log.LogCritical($"{nameof(LibuvThread)}.{nameof(StopAsync)} failed to terminate libuv thread."); } } } @@ -236,7 +230,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal _post.Send(); } - private void Post(Action callback) + private void Post(Action callback) { Post(callback, this); } @@ -265,7 +259,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal private void Walk(LibuvFunctions.uv_walk_cb callback, IntPtr arg) { - _engine.Libuv.walk( + _transport.Libuv.walk( _loop, callback, arg @@ -293,7 +287,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal var tcs = (TaskCompletionSource)parameter; try { - _loop.Init(_engine.Libuv); + _loop.Init(_transport.Libuv); _post.Init(_loop, OnPost, EnqueueCloseHandle); _heartbeatTimer.Init(_loop, EnqueueCloseHandle); _heartbeatTimer.Start(OnHeartbeat, timeout: HeartbeatMilliseconds, repeat: HeartbeatMilliseconds); @@ -391,7 +385,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal } catch (Exception e) { - _log.LogError(0, e, "KestrelThread.DoPostWork"); + _log.LogError(0, e, $"{nameof(LibuvThread)}.{nameof(DoPostWork)}"); } }, work.Completion); } @@ -408,13 +402,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal } catch (Exception e) { - _log.LogError(0, e, "KestrelThread.DoPostWork"); + _log.LogError(0, e, $"{nameof(LibuvThread)}.{nameof(DoPostWork)}"); } }, work.Completion); } else { - _log.LogError(0, ex, "KestrelThread.DoPostWork"); + _log.LogError(0, ex, $"{nameof(LibuvThread)}.{nameof(DoPostWork)}"); throw; } } @@ -444,7 +438,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal } catch (Exception ex) { - _log.LogError(0, ex, "KestrelThread.DoPostCloseHandle"); + _log.LogError(0, ex, $"{nameof(LibuvThread)}.{nameof(DoPostCloseHandle)}"); throw; } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Infrastructure/LibuvTrace.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvTrace.cs similarity index 99% rename from src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Infrastructure/LibuvTrace.cs rename to src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvTrace.cs index d113bf2010..93623918d9 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Infrastructure/LibuvTrace.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvTrace.cs @@ -4,7 +4,7 @@ using System; using Microsoft.Extensions.Logging; -namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Infrastructure +namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal { public class LibuvTrace : ILibuvTrace { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvTransportContext.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvTransportContext.cs index df8a8b1275..78f21248c2 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvTransportContext.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvTransportContext.cs @@ -2,9 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using Microsoft.AspNetCore.Hosting; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions; -using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Infrastructure; namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Http/Listener.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Listener.cs similarity index 91% rename from src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Http/Listener.cs rename to src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Listener.cs index ca4b780510..aa03493751 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Http/Listener.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Listener.cs @@ -3,14 +3,11 @@ using System; using System.Threading.Tasks; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions; -using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal; -using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking; using Microsoft.Extensions.Logging; -namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http +namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal { /// /// Base class for listeners in Kestrel. Listens for incoming connections @@ -29,7 +26,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http public Task StartAsync( IEndPointInformation endPointInformation, - KestrelThread thread) + LibuvThread thread) { EndPointInformation = endPointInformation; Thread = thread; @@ -43,7 +40,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { var listener = ((Listener) tcs2.Task.AsyncState); listener.ListenSocket = listener.CreateListenSocket(); - ListenSocket.Listen(Constants.ListenBacklog, ConnectionCallback, this); + ListenSocket.Listen(LibuvConstants.ListenBacklog, ConnectionCallback, this); tcs2.SetResult(0); } catch (Exception ex) @@ -148,7 +145,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http protected virtual void DispatchConnection(UvStreamHandle socket) { - var connection = new Connection(this, socket); + var connection = new LibuvConnection(this, socket); connection.Start(); } @@ -156,7 +153,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { // Ensure the event loop is still running. // If the event loop isn't running and we try to wait on this Post - // to complete, then KestrelEngine will never be disposed and + // to complete, then LibuvTransport will never be disposed and // the exception that stopped the event loop will never be surfaced. if (Thread.FatalError == null && ListenSocket != null) { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Http/ListenerContext.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/ListenerContext.cs similarity index 89% rename from src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Http/ListenerContext.cs rename to src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/ListenerContext.cs index f0bb7b5b3a..b3b30328b5 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Http/ListenerContext.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/ListenerContext.cs @@ -2,11 +2,10 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions; -using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking; -namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http +namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal { public class ListenerContext { @@ -19,7 +18,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http public IEndPointInformation EndPointInformation { get; set; } - public KestrelThread Thread { get; set; } + public LibuvThread Thread { get; set; } /// /// Creates a socket which can be used to accept an incoming connection. diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Http/ListenerPrimary.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/ListenerPrimary.cs similarity index 97% rename from src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Http/ListenerPrimary.cs rename to src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/ListenerPrimary.cs index eebcd96e6d..7ebe34b709 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Http/ListenerPrimary.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/ListenerPrimary.cs @@ -6,13 +6,11 @@ using System.Collections.Generic; using System.IO; using System.Runtime.InteropServices; using System.Threading.Tasks; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions; -using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking; using Microsoft.Extensions.Logging; -namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http +namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal { /// /// A primary listener waits for incoming connections on a specified socket. Incoming @@ -41,7 +39,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http string pipeName, byte[] pipeMessage, IEndPointInformation endPointInformation, - KestrelThread thread) + LibuvThread thread) { _pipeName = pipeName; _pipeMessage = pipeMessage; @@ -64,7 +62,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http ListenPipe = new UvPipeHandle(Log); ListenPipe.Init(Thread.Loop, Thread.QueueCloseHandle, false); ListenPipe.Bind(_pipeName); - ListenPipe.Listen(Constants.ListenBacklog, + ListenPipe.Listen(LibuvConstants.ListenBacklog, (pipe, status, error, state) => ((ListenerPrimary)state).OnListenPipe(pipe, status, error), this); } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Http/ListenerSecondary.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/ListenerSecondary.cs similarity index 92% rename from src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Http/ListenerSecondary.cs rename to src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/ListenerSecondary.cs index 506832a72d..25c7d1ab6d 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Http/ListenerSecondary.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/ListenerSecondary.cs @@ -5,14 +5,11 @@ using System; using System.Runtime.InteropServices; using System.Threading; using System.Threading.Tasks; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions; -using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal; -using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking; using Microsoft.Extensions.Logging; -namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http +namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal { /// /// A secondary listener is delegated requests from a primary listener via a named pipe or @@ -39,7 +36,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http string pipeName, byte[] pipeMessage, IEndPointInformation endPointInformation, - KestrelThread thread) + LibuvThread thread) { _pipeName = pipeName; _pipeMessage = pipeMessage; @@ -130,7 +127,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { if (status < 0) { - if (status != Constants.EOF) + if (status != LibuvConstants.EOF) { Exception ex; Thread.Loop.Libuv.Check(status, out ex); @@ -161,7 +158,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http try { - var connection = new Connection(this, acceptSocket); + var connection = new LibuvConnection(this, acceptSocket); connection.Start(); } catch (UvException ex) @@ -184,7 +181,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { // Ensure the event loop is still running. // If the event loop isn't running and we try to wait on this Post - // to complete, then KestrelEngine will never be disposed and + // to complete, then LibuvTransport will never be disposed and // the exception that stopped the event loop will never be surfaced. if (Thread.FatalError == null) { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/Libuv.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/LibuvFunctions.cs similarity index 99% rename from src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/Libuv.cs rename to src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/LibuvFunctions.cs index b527524b6c..1d3cbccb96 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/Libuv.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/LibuvFunctions.cs @@ -5,7 +5,7 @@ using System; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; -namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking +namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking { public class LibuvFunctions { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/PlatformApis.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/PlatformApis.cs index 5bb37f60a9..ffc7619d73 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/PlatformApis.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/PlatformApis.cs @@ -6,7 +6,7 @@ using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Threading; -namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking +namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking { public static class PlatformApis { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/SockAddr.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/SockAddr.cs index 71e7c59b32..0f0210f91a 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/SockAddr.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/SockAddr.cs @@ -4,7 +4,7 @@ using System.Net; using System.Runtime.InteropServices; -namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking +namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking { [StructLayout(LayoutKind.Sequential)] public struct SockAddr diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvAsyncHandle.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvAsyncHandle.cs index 141ca6dcb7..d68a79c4ca 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvAsyncHandle.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvAsyncHandle.cs @@ -4,10 +4,8 @@ using System; using System.Diagnostics; using System.Threading; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; -using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Infrastructure; -namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking +namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking { public class UvAsyncHandle : UvHandle { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvConnectRequest.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvConnectRequest.cs index 204d8c4ba4..3e29e42520 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvConnectRequest.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvConnectRequest.cs @@ -2,11 +2,9 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; -using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Infrastructure; using Microsoft.Extensions.Logging; -namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking +namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking { /// /// Summary description for UvWriteRequest diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvException.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvException.cs index 5e7b26e998..fa7c4087fe 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvException.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvException.cs @@ -3,7 +3,7 @@ using System; -namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking +namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking { public class UvException : Exception { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvHandle.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvHandle.cs index 41a074ae21..0f33eee7c3 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvHandle.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvHandle.cs @@ -4,10 +4,8 @@ using System; using System.Diagnostics; using System.Threading; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; -using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Infrastructure; -namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking +namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking { public abstract class UvHandle : UvMemory { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvLoopHandle.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvLoopHandle.cs index 39bce92897..c1a47d163d 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvLoopHandle.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvLoopHandle.cs @@ -3,10 +3,8 @@ using System; using System.Threading; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; -using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Infrastructure; -namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking +namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking { public class UvLoopHandle : UvMemory { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvMemory.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvMemory.cs index 3e67b6b399..dcd5fdec2a 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvMemory.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvMemory.cs @@ -1,14 +1,13 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. #define TRACE + using System; using System.Diagnostics; using System.Runtime.InteropServices; using System.Threading; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; -using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Infrastructure; -namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking +namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking { /// /// Summary description for UvMemory diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvPipeHandle.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvPipeHandle.cs index 0ce7e1fe27..338cc1f643 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvPipeHandle.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvPipeHandle.cs @@ -2,10 +2,8 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; -using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Infrastructure; -namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking +namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking { public class UvPipeHandle : UvStreamHandle { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvRequest.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvRequest.cs index 20a285304f..3826ea9cde 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvRequest.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvRequest.cs @@ -1,9 +1,10 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + using System; using System.Runtime.InteropServices; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; -using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Infrastructure; -namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking +namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking { public class UvRequest : UvMemory { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvShutdownReq.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvShutdownReq.cs index 9d13b715b7..726d1b9867 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvShutdownReq.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvShutdownReq.cs @@ -2,10 +2,8 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; -using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Infrastructure; -namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking +namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking { /// /// Summary description for UvShutdownRequest diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvStreamHandle.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvStreamHandle.cs index ee3b3abc7f..714ddfbc0e 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvStreamHandle.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvStreamHandle.cs @@ -3,12 +3,9 @@ using System; using System.Runtime.InteropServices; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; -using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Infrastructure; using Microsoft.Extensions.Logging; -namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking +namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking { public abstract class UvStreamHandle : UvHandle { @@ -30,7 +27,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking { } - public Connection Connection { get; set; } + public LibuvConnection Connection { get; set; } protected override bool ReleaseHandle() { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvTcpHandle.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvTcpHandle.cs index 2c794509ae..260f04598e 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvTcpHandle.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvTcpHandle.cs @@ -4,10 +4,8 @@ using System; using System.Net; using System.Runtime.InteropServices; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; -using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Infrastructure; -namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking +namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking { public class UvTcpHandle : UvStreamHandle { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvTimerHandle.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvTimerHandle.cs index 77c288ae8c..85547e7d69 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvTimerHandle.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvTimerHandle.cs @@ -2,11 +2,9 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; -using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Infrastructure; using Microsoft.Extensions.Logging; -namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking +namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking { public class UvTimerHandle : UvHandle { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvWriteReq.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvWriteReq.cs index f680aa5892..0f5edff121 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvWriteReq.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvWriteReq.cs @@ -6,11 +6,9 @@ using System.Buffers; using System.Collections.Generic; using System.IO.Pipelines; using System.Runtime.InteropServices; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; -using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Infrastructure; using Microsoft.Extensions.Logging; -namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking +namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking { /// /// Summary description for UvWriteRequest diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Infrastructure/WriteReqPool.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/WriteReqPool.cs similarity index 80% rename from src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Infrastructure/WriteReqPool.cs rename to src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/WriteReqPool.cs index dc83eae51c..9a7ad2532a 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Infrastructure/WriteReqPool.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/WriteReqPool.cs @@ -1,20 +1,22 @@ -using System; -using System.Collections.Generic; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; -using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Infrastructure; +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure +using System; +using System.Collections.Generic; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking; + +namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal { public class WriteReqPool { private const int _maxPooledWriteReqs = 1024; - private readonly KestrelThread _thread; + private readonly LibuvThread _thread; private readonly Queue _pool = new Queue(_maxPooledWriteReqs); private readonly ILibuvTrace _log; private bool _disposed; - public WriteReqPool(KestrelThread thread, ILibuvTrace log) + public WriteReqPool(LibuvThread thread, ILibuvTrace log) { _thread = thread; _log = log; diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/KestrelEngine.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/LibuvTransport.cs similarity index 85% rename from src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/KestrelEngine.cs rename to src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/LibuvTransport.cs index 2763dce1c6..bf23beeb0e 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/KestrelEngine.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/LibuvTransport.cs @@ -6,29 +6,25 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Hosting; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions; -using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv; using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal; -using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking; using Microsoft.Extensions.Logging; -namespace Microsoft.AspNetCore.Server.Kestrel.Internal +namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv { - public class KestrelEngine : ITransport + public class LibuvTransport : ITransport { private readonly IEndPointInformation _endPointInformation; private readonly List _listeners = new List(); - public KestrelEngine(LibuvTransportContext context, IEndPointInformation endPointInformation) + public LibuvTransport(LibuvTransportContext context, IEndPointInformation endPointInformation) : this(new LibuvFunctions(), context, endPointInformation) { } // For testing - public KestrelEngine(LibuvFunctions uv, LibuvTransportContext context, IEndPointInformation endPointInformation) + public LibuvTransport(LibuvFunctions uv, LibuvTransportContext context, IEndPointInformation endPointInformation) { Libuv = uv; TransportContext = context; @@ -38,7 +34,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal public LibuvFunctions Libuv { get; } public LibuvTransportContext TransportContext { get; } - public List Threads { get; } = new List(); + public List Threads { get; } = new List(); public IApplicationLifetime AppLifetime => TransportContext.AppLifetime; public ILibuvTrace Log => TransportContext.Log; @@ -78,7 +74,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal // TODO: Split endpoint management from thread management for (var index = 0; index < TransportOptions.ThreadCount; index++) { - Threads.Add(new KestrelThread(this)); + Threads.Add(new LibuvThread(this)); } foreach (var thread in Threads) @@ -111,7 +107,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal } } } - catch (UvException ex) when (ex.StatusCode == Constants.EADDRINUSE) + catch (UvException ex) when (ex.StatusCode == LibuvConstants.EADDRINUSE) { await UnbindAsync().ConfigureAwait(false); throw new AddressInUseException(ex.Message, ex); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/LibuvTransportFactory.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/LibuvTransportFactory.cs index a05f2972ba..0a2d909580 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/LibuvTransportFactory.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/LibuvTransportFactory.cs @@ -3,11 +3,8 @@ using System; using Microsoft.AspNetCore.Hosting; -using Microsoft.AspNetCore.Server.Kestrel.Internal; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions; using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal; -using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Infrastructure; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; @@ -47,12 +44,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv "ThreadCount must be positive."); } - if (!Constants.ECONNRESET.HasValue) + if (!LibuvConstants.ECONNRESET.HasValue) { trace.LogWarning("Unable to determine ECONNRESET value on this platform."); } - if (!Constants.EADDRINUSE.HasValue) + if (!LibuvConstants.EADDRINUSE.HasValue) { trace.LogWarning("Unable to determine EADDRINUSE value on this platform."); } @@ -75,7 +72,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv ConnectionHandler = handler }; - return new KestrelEngine(transportContext, endPointInformation); + return new LibuvTransport(transportContext, endPointInformation); } } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/WebHostBuilderKestrelExtensions.cs b/src/Microsoft.AspNetCore.Server.Kestrel/WebHostBuilderKestrelExtensions.cs index a40b2ec8ae..3d3dad73cb 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/WebHostBuilderKestrelExtensions.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/WebHostBuilderKestrelExtensions.cs @@ -3,8 +3,8 @@ using System; using Microsoft.AspNetCore.Hosting.Server; -using Microsoft.AspNetCore.Server.Kestrel; -using Microsoft.AspNetCore.Server.Kestrel.Internal; +using Microsoft.AspNetCore.Server.Kestrel.Core; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Options; diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs index 1abb18fe40..1849113b0a 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs @@ -15,7 +15,8 @@ using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting.Server.Features; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http.Extensions; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Core; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; using Microsoft.AspNetCore.Testing; using Microsoft.AspNetCore.Testing.xunit; using Microsoft.Extensions.DependencyInjection; diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/BadHttpRequestTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/BadHttpRequestTests.cs index 89deac4fa3..4c59212c6c 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/BadHttpRequestTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/BadHttpRequestTests.cs @@ -5,8 +5,9 @@ using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; -using Microsoft.AspNetCore.Server.Kestrel.Internal; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Core; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; using Microsoft.AspNetCore.Testing; using Microsoft.Extensions.Internal; using Microsoft.Extensions.Logging; diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/EventSourceTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/EventSourceTests.cs index 74180ccbab..a0124e51a7 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/EventSourceTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/EventSourceTests.cs @@ -8,7 +8,7 @@ using System.Diagnostics.Tracing; using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Http.Features; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; using Microsoft.AspNetCore.Testing; using Xunit; diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/KeepAliveTimeoutTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/KeepAliveTimeoutTests.cs index 0648c1bf57..28e4ece5d8 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/KeepAliveTimeoutTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/KeepAliveTimeoutTests.cs @@ -7,6 +7,7 @@ using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http.Features; +using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.AspNetCore.Testing; using Xunit; diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/MaxRequestLineSizeTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/MaxRequestLineSizeTests.cs index 1f6e95e767..8e3dd5d22e 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/MaxRequestLineSizeTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/MaxRequestLineSizeTests.cs @@ -3,6 +3,7 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.AspNetCore.Testing; using Xunit; diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestHeaderLimitsTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestHeaderLimitsTests.cs index 8c62cc0971..65b4eaaef8 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestHeaderLimitsTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestHeaderLimitsTests.cs @@ -7,6 +7,7 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.AspNetCore.Testing; using Microsoft.Extensions.Primitives; using Xunit; diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestHeadersTimeoutTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestHeadersTimeoutTests.cs index b80a637058..e3807704a7 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestHeadersTimeoutTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestHeadersTimeoutTests.cs @@ -5,6 +5,7 @@ using System; using System.IO; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.AspNetCore.Testing; using Xunit; diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs index 9dc073f100..a8d20e1d69 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs @@ -15,7 +15,7 @@ using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http.Features; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking; using Microsoft.AspNetCore.Testing; using Microsoft.AspNetCore.Testing.xunit; using Microsoft.Extensions.DependencyInjection; diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs index 2b2854df79..d68624bd3b 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs @@ -13,8 +13,9 @@ using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http.Features; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Core; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; using Microsoft.AspNetCore.Testing; using Microsoft.Extensions.Internal; using Microsoft.Extensions.Logging; diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/DotSegmentRemovalBenchmark.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/DotSegmentRemovalBenchmark.cs index eb626280d1..5e65f9aa03 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/DotSegmentRemovalBenchmark.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/DotSegmentRemovalBenchmark.cs @@ -4,7 +4,7 @@ using System; using System.Text; using BenchmarkDotNet.Attributes; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; namespace Microsoft.AspNetCore.Server.Kestrel.Performance { diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameParsingOverheadBenchmark.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameParsingOverheadBenchmark.cs index a3d0092638..f98d7b7c56 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameParsingOverheadBenchmark.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameParsingOverheadBenchmark.cs @@ -5,8 +5,9 @@ using System; using System.IO.Pipelines; using System.Text; using BenchmarkDotNet.Attributes; -using Microsoft.AspNetCore.Server.Kestrel.Internal; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Core; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; namespace Microsoft.AspNetCore.Server.Kestrel.Performance { diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameWritingBenchmark.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameWritingBenchmark.cs index ae41da1959..c0762e0d82 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameWritingBenchmark.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameWritingBenchmark.cs @@ -6,8 +6,9 @@ using System.IO.Pipelines; using System.Threading; using System.Threading.Tasks; using BenchmarkDotNet.Attributes; -using Microsoft.AspNetCore.Server.Kestrel.Internal; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Core; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; using Microsoft.AspNetCore.Testing; namespace Microsoft.AspNetCore.Server.Kestrel.Performance diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/KestrelHttpParserBenchmark.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/KestrelHttpParserBenchmark.cs index 0a06b448d0..3f6961f030 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/KestrelHttpParserBenchmark.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/KestrelHttpParserBenchmark.cs @@ -4,7 +4,7 @@ using System; using System.IO.Pipelines; using BenchmarkDotNet.Attributes; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; namespace Microsoft.AspNetCore.Server.Kestrel.Performance { diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/KnownStringsBenchmark.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/KnownStringsBenchmark.cs index 2bdc526f9e..e19777aaab 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/KnownStringsBenchmark.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/KnownStringsBenchmark.cs @@ -4,8 +4,8 @@ using System; using System.Text; using BenchmarkDotNet.Attributes; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; namespace Microsoft.AspNetCore.Server.Kestrel.Performance { diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Mocks/MockTrace.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Mocks/MockTrace.cs index 915c4805d1..f98d3c15cf 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Mocks/MockTrace.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Mocks/MockTrace.cs @@ -2,7 +2,8 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Core; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; using Microsoft.Extensions.Logging; namespace Microsoft.AspNetCore.Server.Kestrel.Performance diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsingBenchmark.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsingBenchmark.cs index 68da390b7a..08507ef3b8 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsingBenchmark.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsingBenchmark.cs @@ -3,8 +3,9 @@ using System.IO.Pipelines; using BenchmarkDotNet.Attributes; -using Microsoft.AspNetCore.Server.Kestrel.Internal; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Core; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; namespace Microsoft.AspNetCore.Server.Kestrel.Performance { diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/ResponseHeaderCollectionBenchmark.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/ResponseHeaderCollectionBenchmark.cs index 0d2852dcf3..e1bd6e60dc 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/ResponseHeaderCollectionBenchmark.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/ResponseHeaderCollectionBenchmark.cs @@ -6,8 +6,9 @@ using System.Text; using BenchmarkDotNet.Attributes; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http.Internal; -using Microsoft.AspNetCore.Server.Kestrel.Internal; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Core; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; namespace Microsoft.AspNetCore.Server.Kestrel.Performance { diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/ResponseHeadersWritingBenchmark.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/ResponseHeadersWritingBenchmark.cs index ce2f941c41..b64789dbdb 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/ResponseHeadersWritingBenchmark.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/ResponseHeadersWritingBenchmark.cs @@ -8,9 +8,10 @@ using System.Text; using System.Threading; using System.Threading.Tasks; using BenchmarkDotNet.Attributes; -using Microsoft.AspNetCore.Server.Kestrel.Adapter.Internal; -using Microsoft.AspNetCore.Server.Kestrel.Internal; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Core; +using Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; using Microsoft.AspNetCore.Testing; namespace Microsoft.AspNetCore.Server.Kestrel.Performance @@ -36,7 +37,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance { _frame.Reset(); _frame.StatusCode = 200; - _frame.HttpVersionEnum = Internal.Http.HttpVersion.Http11; + _frame.HttpVersionEnum = HttpVersion.Http11; _frame.KeepAlive = true; Task writeTask = Task.CompletedTask; @@ -128,12 +129,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance ConnectionInformation = new MockConnectionInformation() }; - var socketOutputProducer = new SocketOutputProducer(output.Writer, null, null, null); + var outputProducer = new OutputProducer(output.Writer, null, null, null); var frame = new TestFrame(application: null, context: frameContext) { Input = input.Reader, Output = socketOutput, - LifetimeControl = new ConnectionLifetimeControl(null, output.Reader, socketOutputProducer, serviceContext.Log) + LifetimeControl = new ConnectionLifetimeControl(null, output.Reader, outputProducer, serviceContext.Log) }; frame.Reset(); diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/AsciiDecoding.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/AsciiDecoding.cs index 4e5528d440..8242a6bb43 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/AsciiDecoding.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/AsciiDecoding.cs @@ -3,7 +3,7 @@ using System; using System.Linq; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; using Xunit; namespace Microsoft.AspNetCore.Server.KestrelTests diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkWriterTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkWriterTests.cs index d66ac3f60b..d7a7f35770 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkWriterTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkWriterTests.cs @@ -3,7 +3,7 @@ using System.Linq; using System.Text; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; using Xunit; namespace Microsoft.AspNetCore.Server.KestrelTests diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedRequestTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedRequestTests.cs index f387562c68..0ed47420b9 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedRequestTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedRequestTests.cs @@ -8,7 +8,7 @@ using System.Net; using System.Text; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Server.Kestrel; +using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.AspNetCore.Testing; using Microsoft.Extensions.Internal; using Xunit; diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedResponseTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedResponseTests.cs index ed28131ead..c52c1fa5bc 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedResponseTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedResponseTests.cs @@ -7,7 +7,7 @@ using System.Text; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Server.Kestrel; +using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.AspNetCore.Testing; using Xunit; diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionAdapterTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionAdapterTests.cs index 21d1ab94f4..57e89f56f2 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionAdapterTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionAdapterTests.cs @@ -7,8 +7,8 @@ using System.Net; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Http.Features; -using Microsoft.AspNetCore.Server.Kestrel; -using Microsoft.AspNetCore.Server.Kestrel.Adapter; +using Microsoft.AspNetCore.Server.Kestrel.Core; +using Microsoft.AspNetCore.Server.Kestrel.Core.Adapter; using Microsoft.AspNetCore.Testing; using Xunit; diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionTests.cs index d74cdf6b90..0234cd08c2 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionTests.cs @@ -4,9 +4,9 @@ using System; using System.Threading; using System.Threading.Tasks; -using Microsoft.AspNetCore.Server.Kestrel.Internal; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking; using Microsoft.AspNetCore.Server.KestrelTests.TestHelpers; using Microsoft.AspNetCore.Testing; using Xunit; @@ -24,8 +24,8 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var serviceContext = new TestServiceContext(); serviceContext.TransportContext.ConnectionHandler = mockConnectionHandler; - var engine = new KestrelEngine(mockLibuv, serviceContext.TransportContext, null); - var thread = new KestrelThread(engine); + var transport = new LibuvTransport(mockLibuv, serviceContext.TransportContext, null); + var thread = new LibuvThread(transport); try { @@ -37,7 +37,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests Thread = thread }; var socket = new MockSocket(mockLibuv, Thread.CurrentThread.ManagedThreadId, serviceContext.TransportContext.Log); - var connection = new Connection(listenerContext, socket); + var connection = new LibuvConnection(listenerContext, socket); connection.Start(); LibuvFunctions.uv_buf_t ignored; diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/CreateIPEndpointTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/CreateIPEndpointTests.cs index a7bb17c55f..e8a3cdfd2c 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/CreateIPEndpointTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/CreateIPEndpointTests.cs @@ -2,7 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Net; -using Microsoft.AspNetCore.Server.Kestrel; +using Microsoft.AspNetCore.Server.Kestrel.Core; using Xunit; namespace Microsoft.AspNetCore.Server.KestrelTests diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/DateHeaderValueManagerTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/DateHeaderValueManagerTests.cs index 8e9802600b..810814219d 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/DateHeaderValueManagerTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/DateHeaderValueManagerTests.cs @@ -3,7 +3,7 @@ using System; using System.Threading.Tasks; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; using Microsoft.AspNetCore.Testing; using Xunit; diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs index eed4aac30e..81a14ee9a1 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs @@ -12,9 +12,10 @@ using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http.Features; -using Microsoft.AspNetCore.Server.Kestrel; -using Microsoft.AspNetCore.Server.Kestrel.Internal; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Core; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv; using Microsoft.AspNetCore.Testing; using Microsoft.Extensions.Internal; using Xunit; @@ -36,16 +37,16 @@ namespace Microsoft.AspNetCore.Server.KestrelTests }; [Fact] - public async Task EngineCanStartAndStop() + public async Task TransportCanStartAndStop() { var serviceContext = new TestServiceContext(); - // The engine can no longer start threads without binding to an endpoint. - var engine = new KestrelEngine(serviceContext.TransportContext, + // The transport can no longer start threads without binding to an endpoint. + var transport = new LibuvTransport(serviceContext.TransportContext, new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0))); - await engine.BindAsync(); - await engine.StopAsync(); + await transport.BindAsync(); + await transport.StopAsync(); } [Theory] @@ -54,11 +55,11 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { var testContext = new TestServiceContext(); testContext.TransportContext.ConnectionHandler = new ConnectionHandler(listenOptions, testContext, new DummyApplication(TestApp.EchoApp)); - var engine = new KestrelEngine(testContext.TransportContext, listenOptions); + var transport = new LibuvTransport(testContext.TransportContext, listenOptions); - await engine.BindAsync(); - await engine.UnbindAsync(); - await engine.StopAsync(); + await transport.BindAsync(); + await transport.UnbindAsync(); + await transport.StopAsync(); } [Theory] @@ -67,9 +68,9 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { var testContext = new TestServiceContext(); testContext.TransportContext.ConnectionHandler = new ConnectionHandler(listenOptions, testContext, new DummyApplication(TestApp.EchoApp)); - var engine = new KestrelEngine(testContext.TransportContext, listenOptions); + var transport = new LibuvTransport(testContext.TransportContext, listenOptions); - await engine.BindAsync(); + await transport.BindAsync(); var socket = TestConnection.CreateConnectedLoopbackSocket(listenOptions.IPEndPoint.Port); var data = "Hello World"; @@ -82,8 +83,8 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } socket.Dispose(); - await engine.UnbindAsync(); - await engine.StopAsync(); + await transport.UnbindAsync(); + await transport.StopAsync(); } [Theory] diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameHeadersTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameHeadersTests.cs index 24ec00d821..06a0b4cc15 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameHeadersTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameHeadersTests.cs @@ -3,7 +3,7 @@ using System; using System.Collections.Generic; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; using Microsoft.Extensions.Primitives; using Microsoft.Net.Http.Headers; using Xunit; diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameRequestHeadersTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameRequestHeadersTests.cs index 006ac65cd1..cc8baef3c6 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameRequestHeadersTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameRequestHeadersTests.cs @@ -5,8 +5,8 @@ using System; using System.Collections.Generic; using System.Text; using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Server.Kestrel; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Core; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; using Microsoft.Extensions.Primitives; using Xunit; diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameRequestStreamTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameRequestStreamTests.cs index 28f1d800b7..62d6a41ffd 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameRequestStreamTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameRequestStreamTests.cs @@ -4,7 +4,7 @@ using System; using System.IO; using System.Threading.Tasks; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; using Moq; using Xunit; diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameResponseHeadersTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameResponseHeadersTests.cs index d626512420..aea53a5bec 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameResponseHeadersTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameResponseHeadersTests.cs @@ -6,7 +6,7 @@ using System.Collections.Generic; using System.Globalization; using System.IO.Pipelines; using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; using Microsoft.AspNetCore.Testing; using Microsoft.Extensions.Primitives; using Xunit; diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameResponseStreamTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameResponseStreamTests.cs index d097ee6161..289125fbfc 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameResponseStreamTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameResponseStreamTests.cs @@ -4,7 +4,7 @@ using System; using System.IO; using System.Threading.Tasks; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; using Microsoft.AspNetCore.Server.KestrelTests.TestHelpers; using Xunit; diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs index 5f5f353bb4..f4fd2ae784 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs @@ -12,10 +12,10 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Hosting.Server; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http.Features; -using Microsoft.AspNetCore.Server.Kestrel; -using Microsoft.AspNetCore.Server.Kestrel.Internal; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Core; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions; using Microsoft.AspNetCore.Testing; using Microsoft.Extensions.Internal; @@ -248,7 +248,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests public void InitializeStreamsResetsStreams() { // Arrange - var messageBody = MessageBody.For(Kestrel.Internal.Http.HttpVersion.Http11, (FrameRequestHeaders)_frame.RequestHeaders, _frame); + var messageBody = MessageBody.For(Kestrel.Core.Internal.Http.HttpVersion.Http11, (FrameRequestHeaders)_frame.RequestHeaders, _frame); _frame.InitializeStreams(messageBody); var originalRequestBody = _frame.RequestBody; diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/HttpParserTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/HttpParserTests.cs index 99daa1a53d..d28eb02e07 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/HttpParserTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/HttpParserTests.cs @@ -8,9 +8,9 @@ using System.IO.Pipelines.Testing; using System.Linq; using System.Text; using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Server.Kestrel; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Core; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; using Microsoft.AspNetCore.Testing; using Microsoft.Extensions.Logging; using Moq; diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/HttpUtilitiesTest.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/HttpUtilitiesTest.cs index e21ce86eff..002ec387c4 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/HttpUtilitiesTest.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/HttpUtilitiesTest.cs @@ -3,8 +3,8 @@ using System; using System.Text; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; using Xunit; namespace Microsoft.AspNetCore.Server.KestrelTests diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/HttpsConnectionAdapterTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/HttpsConnectionAdapterTests.cs index 5df67aa16f..25c637b628 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/HttpsConnectionAdapterTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/HttpsConnectionAdapterTests.cs @@ -14,7 +14,7 @@ using System.Text; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http.Features; -using Microsoft.AspNetCore.Server.Kestrel; +using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.AspNetCore.Server.Kestrel.Https; using Microsoft.AspNetCore.Testing; using Microsoft.Extensions.Internal; diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelEventSourceTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelEventSourceTests.cs index 97a38802b6..fc51df41f3 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelEventSourceTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelEventSourceTests.cs @@ -4,7 +4,7 @@ using System; using System.Diagnostics.Tracing; using System.Reflection; -using Microsoft.AspNetCore.Server.Kestrel; +using Microsoft.AspNetCore.Server.Kestrel.Core; using Xunit; namespace Microsoft.AspNetCore.Server.KestrelTests @@ -15,7 +15,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests public void ExistsWithCorrectId() { var esType = typeof(KestrelServer).GetTypeInfo().Assembly.GetType( - "Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.KestrelEventSource", + "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure.KestrelEventSource", throwOnError: true, ignoreCase: false ); diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerLimitsTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerLimitsTests.cs index 2b95674e5b..ff30838839 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerLimitsTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerLimitsTests.cs @@ -2,7 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using Microsoft.AspNetCore.Server.Kestrel; +using Microsoft.AspNetCore.Server.Kestrel.Core; using Xunit; namespace Microsoft.AspNetCore.Server.KestrelTests diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerOptionsTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerOptionsTests.cs index 8a33390342..13a1d442b6 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerOptionsTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerOptionsTests.cs @@ -2,7 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Net; -using Microsoft.AspNetCore.Server.Kestrel; +using Microsoft.AspNetCore.Server.Kestrel.Core; using Xunit; namespace Microsoft.AspNetCore.Server.KestrelTests diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerTests.cs index 24218aa8f7..8c3e5fa0b2 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerTests.cs @@ -7,7 +7,7 @@ using System.Net; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting.Server; using Microsoft.AspNetCore.Hosting.Server.Features; -using Microsoft.AspNetCore.Server.Kestrel; +using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions; using Microsoft.AspNetCore.Testing; using Microsoft.Extensions.Internal; diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/SocketOutputTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/LibuvOutputConsumerTests.cs similarity index 89% rename from test/Microsoft.AspNetCore.Server.KestrelTests/SocketOutputTests.cs rename to test/Microsoft.AspNetCore.Server.KestrelTests/LibuvOutputConsumerTests.cs index fc5e39df9d..0b9a085180 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/SocketOutputTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/LibuvOutputConsumerTests.cs @@ -6,20 +6,21 @@ using System.Collections.Concurrent; using System.IO.Pipelines; using System.Threading; using System.Threading.Tasks; -using Microsoft.AspNetCore.Server.Kestrel; -using Microsoft.AspNetCore.Server.Kestrel.Internal; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Core; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal; using Microsoft.AspNetCore.Server.KestrelTests.TestHelpers; using Microsoft.AspNetCore.Testing; using Xunit; namespace Microsoft.AspNetCore.Server.KestrelTests { - public class SocketOutputTests : IDisposable + public class LibuvOutputConsumerTests : IDisposable { private readonly PipeFactory _pipeFactory; private readonly MockLibuv _mockLibuv; - private readonly KestrelThread _kestrelThread; + private readonly LibuvThread _libuvThread; public static TheoryData MaxResponseBufferSizeData => new TheoryData { @@ -31,19 +32,19 @@ namespace Microsoft.AspNetCore.Server.KestrelTests (int)new KestrelServerOptions().Limits.MaxResponseBufferSize, 1024, (1024 * 1024) + 1 }; - public SocketOutputTests() + public LibuvOutputConsumerTests() { _pipeFactory = new PipeFactory(); _mockLibuv = new MockLibuv(); - var kestrelEngine = new KestrelEngine(_mockLibuv, new TestServiceContext().TransportContext, new ListenOptions(0)); - _kestrelThread = new KestrelThread(kestrelEngine, maxLoops: 1); - _kestrelThread.StartAsync().Wait(); + var libuvTransport = new LibuvTransport(_mockLibuv, new TestServiceContext().TransportContext, new ListenOptions(0)); + _libuvThread = new LibuvThread(libuvTransport, maxLoops: 1); + _libuvThread.StartAsync().Wait(); } public void Dispose() { - _kestrelThread.StopAsync(TimeSpan.FromSeconds(1)).Wait(); + _libuvThread.StopAsync(TimeSpan.FromSeconds(1)).Wait(); _pipeFactory.Dispose(); } @@ -59,7 +60,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests // This is verified in PipeOptionsTests.OutputPipeOptionsConfiguredCorrectly. var pipeOptions = new PipeOptions { - ReaderScheduler = _kestrelThread, + ReaderScheduler = _libuvThread, MaximumSizeHigh = maxResponseBufferSize ?? 0, MaximumSizeLow = maxResponseBufferSize ?? 0, }; @@ -94,7 +95,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests // This is verified in PipeOptionsTests.OutputPipeOptionsConfiguredCorrectly. var pipeOptions = new PipeOptions { - ReaderScheduler = _kestrelThread, + ReaderScheduler = _libuvThread, MaximumSizeHigh = 0, MaximumSizeLow = 0, }; @@ -119,7 +120,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests foreach (var triggerCompleted in completeQueue) { - await _kestrelThread.PostAsync(cb => cb(0), triggerCompleted); + await _libuvThread.PostAsync(cb => cb(0), triggerCompleted); } } } @@ -140,7 +141,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests // This is verified in PipeOptionsTests.OutputPipeOptionsConfiguredCorrectly. var pipeOptions = new PipeOptions { - ReaderScheduler = _kestrelThread, + ReaderScheduler = _libuvThread, MaximumSizeHigh = 1, MaximumSizeLow = 1, }; @@ -161,7 +162,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests // Finishing the write should allow the task to complete. Assert.True(completeQueue.TryDequeue(out var triggerNextCompleted)); - await _kestrelThread.PostAsync(cb => cb(0), triggerNextCompleted); + await _libuvThread.PostAsync(cb => cb(0), triggerNextCompleted); // Assert await writeTask.TimeoutAfter(TimeSpan.FromSeconds(5)); @@ -174,7 +175,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests foreach (var triggerCompleted in completeQueue) { - await _kestrelThread.PostAsync(cb => cb(0), triggerCompleted); + await _libuvThread.PostAsync(cb => cb(0), triggerCompleted); } } } @@ -194,7 +195,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var pipeOptions = new PipeOptions { - ReaderScheduler = _kestrelThread, + ReaderScheduler = _libuvThread, MaximumSizeHigh = maxResponseBufferSize, MaximumSizeLow = maxResponseBufferSize, }; @@ -221,7 +222,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests // Act Assert.True(completeQueue.TryDequeue(out var triggerNextCompleted)); - await _kestrelThread.PostAsync(cb => cb(0), triggerNextCompleted); + await _libuvThread.PostAsync(cb => cb(0), triggerNextCompleted); // Finishing the first write should allow the second write to pre-complete. await writeTask2.TimeoutAfter(TimeSpan.FromSeconds(5)); @@ -234,7 +235,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests foreach (var triggerCompleted in completeQueue) { - await _kestrelThread.PostAsync(cb => cb(0), triggerCompleted); + await _libuvThread.PostAsync(cb => cb(0), triggerCompleted); } } } @@ -254,7 +255,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var pipeOptions = new PipeOptions { - ReaderScheduler = _kestrelThread, + ReaderScheduler = _libuvThread, MaximumSizeHigh = maxResponseBufferSize, MaximumSizeLow = maxResponseBufferSize, }; @@ -291,7 +292,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests // Drain the write queue while (completeQueue.TryDequeue(out var triggerNextCompleted)) { - await _kestrelThread.PostAsync(cb => cb(0), triggerNextCompleted); + await _libuvThread.PostAsync(cb => cb(0), triggerNextCompleted); } var timeout = TimeSpan.FromSeconds(5); @@ -322,7 +323,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var pipeOptions = new PipeOptions { - ReaderScheduler = _kestrelThread, + ReaderScheduler = _libuvThread, MaximumSizeHigh = maxResponseBufferSize, MaximumSizeLow = maxResponseBufferSize, }; @@ -363,7 +364,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests // Cause all writes to fail while (completeQueue.TryDequeue(out var triggerNextCompleted)) { - await _kestrelThread.PostAsync(cb => cb(-1), triggerNextCompleted); + await _libuvThread.PostAsync(cb => cb(-1), triggerNextCompleted); } // Second task is now completed @@ -394,7 +395,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var pipeOptions = new PipeOptions { - ReaderScheduler = _kestrelThread, + ReaderScheduler = _libuvThread, MaximumSizeHigh = maxResponseBufferSize, MaximumSizeLow = maxResponseBufferSize, }; @@ -420,7 +421,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests // Drain the write queue while (completeQueue.TryDequeue(out var triggerNextCompleted)) { - await _kestrelThread.PostAsync(cb => cb(0), triggerNextCompleted); + await _libuvThread.PostAsync(cb => cb(0), triggerNextCompleted); } var timeout = TimeSpan.FromSeconds(5); @@ -452,7 +453,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests // This is verified in PipeOptionsTests.OutputPipeOptionsConfiguredCorrectly. var pipeOptions = new PipeOptions { - ReaderScheduler = _kestrelThread, + ReaderScheduler = _libuvThread, MaximumSizeHigh = maxResponseBufferSize ?? 0, MaximumSizeLow = maxResponseBufferSize ?? 0, }; @@ -491,7 +492,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { var pipeOptions = new PipeOptions { - ReaderScheduler = _kestrelThread, + ReaderScheduler = _libuvThread, }; using (var connection = new MockConnection()) @@ -516,16 +517,16 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } } - private SocketOutputProducer CreateSocketOutput(PipeOptions pipeOptions, MockConnection connection = null) + private OutputProducer CreateSocketOutput(PipeOptions pipeOptions, MockConnection connection = null) { var pipe = _pipeFactory.Create(pipeOptions); var serviceContext = new TestServiceContext(); var frame = new Frame(null, new FrameContext { ServiceContext = serviceContext }); - var socket = new MockSocket(_mockLibuv, _kestrelThread.Loop.ThreadId, serviceContext.TransportContext.Log); - var socketOutput = new SocketOutputProducer(pipe.Writer, frame, "0", serviceContext.Log); - var consumer = new SocketOutputConsumer(pipe.Reader, _kestrelThread, socket, connection ?? new MockConnection(), "0", serviceContext.TransportContext.Log); + var socket = new MockSocket(_mockLibuv, _libuvThread.Loop.ThreadId, serviceContext.TransportContext.Log); + var socketOutput = new OutputProducer(pipe.Writer, frame, "0", serviceContext.Log); + var consumer = new LibuvOutputConsumer(pipe.Reader, _libuvThread, socket, connection ?? new MockConnection(), "0", serviceContext.TransportContext.Log); var ignore = consumer.StartWrites(); return socketOutput; diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/ListenerPrimaryTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/ListenerPrimaryTests.cs index 8730d598cb..797e7d00a4 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/ListenerPrimaryTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/ListenerPrimaryTests.cs @@ -7,11 +7,11 @@ using System.Linq; using System.Net; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Server.Kestrel; -using Microsoft.AspNetCore.Server.Kestrel.Internal; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; -using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Core; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking; using Microsoft.AspNetCore.Server.KestrelTests.TestHelpers; using Microsoft.AspNetCore.Testing; using Microsoft.Extensions.Logging; @@ -35,16 +35,16 @@ namespace Microsoft.AspNetCore.Server.KestrelTests serviceContextSecondary.TransportContext.ConnectionHandler = new ConnectionHandler( listenOptions, serviceContextSecondary, new DummyApplication(c => c.Response.WriteAsync("Secondary"))); - var kestrelEngine = new KestrelEngine(libuv, serviceContextPrimary.TransportContext, listenOptions); + var libuvTransport = new LibuvTransport(libuv, serviceContextPrimary.TransportContext, listenOptions); var pipeName = (libuv.IsWindows ? @"\\.\pipe\kestrel_" : "/tmp/kestrel_") + Guid.NewGuid().ToString("n"); var pipeMessage = Guid.NewGuid().ToByteArray(); // Start primary listener - var kestrelThreadPrimary = new KestrelThread(kestrelEngine); - await kestrelThreadPrimary.StartAsync(); + var libuvThreadPrimary = new LibuvThread(libuvTransport); + await libuvThreadPrimary.StartAsync(); var listenerPrimary = new ListenerPrimary(serviceContextPrimary.TransportContext); - await listenerPrimary.StartAsync(pipeName, pipeMessage, listenOptions, kestrelThreadPrimary); + await listenerPrimary.StartAsync(pipeName, pipeMessage, listenOptions, libuvThreadPrimary); var address = listenOptions.ToString(); // Until a secondary listener is added, TCP connections get dispatched directly @@ -52,10 +52,10 @@ namespace Microsoft.AspNetCore.Server.KestrelTests Assert.Equal("Primary", await HttpClientSlim.GetStringAsync(address)); // Add secondary listener - var kestrelThreadSecondary = new KestrelThread(kestrelEngine); - await kestrelThreadSecondary.StartAsync(); + var libuvThreadSecondary = new LibuvThread(libuvTransport); + await libuvThreadSecondary.StartAsync(); var listenerSecondary = new ListenerSecondary(serviceContextSecondary.TransportContext); - await listenerSecondary.StartAsync(pipeName, pipeMessage, listenOptions, kestrelThreadSecondary); + await listenerSecondary.StartAsync(pipeName, pipeMessage, listenOptions, libuvThreadSecondary); // Once a secondary listener is added, TCP connections start getting dispatched to it await AssertResponseEventually(address, "Secondary", allowed: new[] { "Primary" }); @@ -66,10 +66,10 @@ namespace Microsoft.AspNetCore.Server.KestrelTests Assert.Equal("Primary", await HttpClientSlim.GetStringAsync(address)); await listenerSecondary.DisposeAsync(); - await kestrelThreadSecondary.StopAsync(TimeSpan.FromSeconds(1)); + await libuvThreadSecondary.StopAsync(TimeSpan.FromSeconds(1)); await listenerPrimary.DisposeAsync(); - await kestrelThreadPrimary.StopAsync(TimeSpan.FromSeconds(1)); + await libuvThreadPrimary.StopAsync(TimeSpan.FromSeconds(1)); } // https://github.com/aspnet/KestrelHttpServer/issues/1182 @@ -93,23 +93,23 @@ namespace Microsoft.AspNetCore.Server.KestrelTests serviceContextSecondary.TransportContext.ConnectionHandler = new ConnectionHandler( listenOptions, serviceContextSecondary, new DummyApplication(c => c.Response.WriteAsync("Secondary"))); - var kestrelEngine = new KestrelEngine(libuv, serviceContextPrimary.TransportContext, listenOptions); + var libuvTransport = new LibuvTransport(libuv, serviceContextPrimary.TransportContext, listenOptions); var pipeName = (libuv.IsWindows ? @"\\.\pipe\kestrel_" : "/tmp/kestrel_") + Guid.NewGuid().ToString("n"); var pipeMessage = Guid.NewGuid().ToByteArray(); // Start primary listener - var kestrelThreadPrimary = new KestrelThread(kestrelEngine); - await kestrelThreadPrimary.StartAsync(); + var libuvThreadPrimary = new LibuvThread(libuvTransport); + await libuvThreadPrimary.StartAsync(); var listenerPrimary = new ListenerPrimary(serviceContextPrimary.TransportContext); - await listenerPrimary.StartAsync(pipeName, pipeMessage, listenOptions, kestrelThreadPrimary); + await listenerPrimary.StartAsync(pipeName, pipeMessage, listenOptions, libuvThreadPrimary); var address = listenOptions.ToString(); // Add secondary listener - var kestrelThreadSecondary = new KestrelThread(kestrelEngine); - await kestrelThreadSecondary.StartAsync(); + var libuvThreadSecondary = new LibuvThread(libuvTransport); + await libuvThreadSecondary.StartAsync(); var listenerSecondary = new ListenerSecondary(serviceContextSecondary.TransportContext); - await listenerSecondary.StartAsync(pipeName, pipeMessage, listenOptions, kestrelThreadSecondary); + await listenerSecondary.StartAsync(pipeName, pipeMessage, listenOptions, libuvThreadSecondary); // TCP Connections get round-robined await AssertResponseEventually(address, "Secondary", allowed: new[] { "Primary" }); @@ -120,12 +120,12 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var connectionTrace = new LibuvTrace(new TestApplicationErrorLogger()); var pipe = new UvPipeHandle(connectionTrace); - kestrelThreadPrimary.Post(_ => + libuvThreadPrimary.Post(_ => { var connectReq = new UvConnectRequest(connectionTrace); - pipe.Init(kestrelThreadPrimary.Loop, kestrelThreadPrimary.QueueCloseHandle); - connectReq.Init(kestrelThreadPrimary.Loop); + pipe.Init(libuvThreadPrimary.Loop, libuvThreadPrimary.QueueCloseHandle); + connectReq.Init(libuvThreadPrimary.Loop); connectReq.Connect( pipe, @@ -153,7 +153,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests Assert.Equal("Primary", await HttpClientSlim.GetStringAsync(address)); Assert.Equal("Secondary", await HttpClientSlim.GetStringAsync(address)); - await kestrelThreadPrimary.PostAsync(_ => pipe.Dispose(), (object)null); + await libuvThreadPrimary.PostAsync(_ => pipe.Dispose(), (object)null); var primaryTrace = (TestKestrelTrace)serviceContextPrimary.Log; @@ -169,10 +169,10 @@ namespace Microsoft.AspNetCore.Server.KestrelTests Assert.Equal("Primary", await HttpClientSlim.GetStringAsync(address)); await listenerSecondary.DisposeAsync(); - await kestrelThreadSecondary.StopAsync(TimeSpan.FromSeconds(1)); + await libuvThreadSecondary.StopAsync(TimeSpan.FromSeconds(1)); await listenerPrimary.DisposeAsync(); - await kestrelThreadPrimary.StopAsync(TimeSpan.FromSeconds(1)); + await libuvThreadPrimary.StopAsync(TimeSpan.FromSeconds(1)); Assert.Equal(1, primaryTrace.Logger.TotalErrorsLogged); var errorMessage = primaryTrace.Logger.Messages.First(m => m.LogLevel == LogLevel.Error); @@ -200,23 +200,23 @@ namespace Microsoft.AspNetCore.Server.KestrelTests serviceContextSecondary.TransportContext.ConnectionHandler = new ConnectionHandler( listenOptions, serviceContextSecondary, new DummyApplication(c => c.Response.WriteAsync("Secondary"))); - var kestrelEngine = new KestrelEngine(libuv, serviceContextPrimary.TransportContext, listenOptions); + var libuvTransport = new LibuvTransport(libuv, serviceContextPrimary.TransportContext, listenOptions); var pipeName = (libuv.IsWindows ? @"\\.\pipe\kestrel_" : "/tmp/kestrel_") + Guid.NewGuid().ToString("n"); var pipeMessage = Guid.NewGuid().ToByteArray(); // Start primary listener - var kestrelThreadPrimary = new KestrelThread(kestrelEngine); - await kestrelThreadPrimary.StartAsync(); + var libuvThreadPrimary = new LibuvThread(libuvTransport); + await libuvThreadPrimary.StartAsync(); var listenerPrimary = new ListenerPrimary(serviceContextPrimary.TransportContext); - await listenerPrimary.StartAsync(pipeName, pipeMessage, listenOptions, kestrelThreadPrimary); + await listenerPrimary.StartAsync(pipeName, pipeMessage, listenOptions, libuvThreadPrimary); var address = listenOptions.ToString(); // Add secondary listener with wrong pipe message - var kestrelThreadSecondary = new KestrelThread(kestrelEngine); - await kestrelThreadSecondary.StartAsync(); + var libuvThreadSecondary = new LibuvThread(libuvTransport); + await libuvThreadSecondary.StartAsync(); var listenerSecondary = new ListenerSecondary(serviceContextSecondary.TransportContext); - await listenerSecondary.StartAsync(pipeName, Guid.NewGuid().ToByteArray(), listenOptions, kestrelThreadSecondary); + await listenerSecondary.StartAsync(pipeName, Guid.NewGuid().ToByteArray(), listenOptions, libuvThreadSecondary); var primaryTrace = (TestKestrelTrace)serviceContextPrimary.Log; @@ -232,10 +232,10 @@ namespace Microsoft.AspNetCore.Server.KestrelTests Assert.Equal("Primary", await HttpClientSlim.GetStringAsync(address)); await listenerSecondary.DisposeAsync(); - await kestrelThreadSecondary.StopAsync(TimeSpan.FromSeconds(1)); + await libuvThreadSecondary.StopAsync(TimeSpan.FromSeconds(1)); await listenerPrimary.DisposeAsync(); - await kestrelThreadPrimary.StopAsync(TimeSpan.FromSeconds(1)); + await libuvThreadPrimary.StopAsync(TimeSpan.FromSeconds(1)); Assert.Equal(1, primaryTrace.Logger.TotalErrorsLogged); var errorMessage = primaryTrace.Logger.Messages.First(m => m.LogLevel == LogLevel.Error); diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/LoggingThreadPoolTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/LoggingThreadPoolTests.cs index 65f37daf44..3209179abc 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/LoggingThreadPoolTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/LoggingThreadPoolTests.cs @@ -4,7 +4,7 @@ using System; using System.Threading.Tasks; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; using Microsoft.AspNetCore.Testing; using Xunit; diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/MessageBodyTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/MessageBodyTests.cs index d5294de41d..da912b65a8 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/MessageBodyTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/MessageBodyTests.cs @@ -9,8 +9,8 @@ using System.Text; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Server.Kestrel; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Core; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; using Microsoft.Extensions.Internal; using Moq; using Xunit; diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/MultipleLoopTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/MultipleLoopTests.cs index 3743da9a78..3a0461d394 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/MultipleLoopTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/MultipleLoopTests.cs @@ -7,8 +7,8 @@ using System.Net; using System.Net.Sockets; using System.Runtime.InteropServices; using System.Threading; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; -using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking; using Microsoft.AspNetCore.Server.KestrelTests.TestHelpers; using Microsoft.AspNetCore.Testing; using Xunit; diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/NetworkingTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/NetworkingTests.cs index cb75b906c2..9a1bea061e 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/NetworkingTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/NetworkingTests.cs @@ -7,10 +7,9 @@ using System.Net; using System.Net.Sockets; using System.Runtime.InteropServices; using System.Threading.Tasks; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; -using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking; using Microsoft.AspNetCore.Testing; -using Moq; using Xunit; namespace Microsoft.AspNetCore.Server.KestrelTests diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/PathNormalizerTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/PathNormalizerTests.cs index d9b4cb6441..25d69b39bf 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/PathNormalizerTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/PathNormalizerTests.cs @@ -3,7 +3,7 @@ using System; using System.Text; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; using Xunit; namespace Microsoft.AspNetCore.Server.KestrelTests diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/PipeOptionsTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/PipeOptionsTests.cs index ec5ac31ff1..ff0ccdd5f0 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/PipeOptionsTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/PipeOptionsTests.cs @@ -2,8 +2,8 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.IO.Pipelines; -using Microsoft.AspNetCore.Server.Kestrel.Internal; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; using Microsoft.AspNetCore.Testing; using Moq; using Xunit; diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/PipelineExtensionTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/PipelineExtensionTests.cs index e5227dd63e..86137019fd 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/PipelineExtensionTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/PipelineExtensionTests.cs @@ -5,7 +5,7 @@ using System; using System.IO.Pipelines; using System.Text; using System.Threading.Tasks; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; using Xunit; namespace Microsoft.AspNetCore.Server.KestrelTests diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/RequestTargetProcessingTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/RequestTargetProcessingTests.cs index d60253405b..3dea2881cf 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/RequestTargetProcessingTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/RequestTargetProcessingTests.cs @@ -5,9 +5,9 @@ using System.Net; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http.Features; -using Microsoft.AspNetCore.Server.Kestrel; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Core; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; using Microsoft.AspNetCore.Testing; using Xunit; diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/ServerAddressTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/ServerAddressTests.cs index 340ea1db27..a412527653 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/ServerAddressTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/ServerAddressTests.cs @@ -2,7 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using Microsoft.AspNetCore.Server.Kestrel; +using Microsoft.AspNetCore.Server.Kestrel.Core; using Xunit; namespace Microsoft.AspNetCore.Server.KestrelTests diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/StreamSocketOutputTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/StreamSocketOutputTests.cs index 1dab5016f8..86814e8ba5 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/StreamSocketOutputTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/StreamSocketOutputTests.cs @@ -4,7 +4,7 @@ using System; using System.IO; using System.IO.Pipelines; -using Microsoft.AspNetCore.Server.Kestrel.Adapter.Internal; +using Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal; using Xunit; namespace Microsoft.AspNetCore.Server.KestrelTests diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockFrameControl.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockFrameControl.cs index 09cec798a4..bf4b4b0d3b 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockFrameControl.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockFrameControl.cs @@ -4,7 +4,7 @@ using System; using System.Threading; using System.Threading.Tasks; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; using Microsoft.Extensions.Internal; namespace Microsoft.AspNetCore.Server.KestrelTests.TestHelpers diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockLibuv.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockLibuv.cs index 8f809cf4fe..8c0dea28e2 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockLibuv.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockLibuv.cs @@ -4,7 +4,7 @@ using System; using System.Threading; using System.Threading.Tasks; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking; namespace Microsoft.AspNetCore.Server.KestrelTests.TestHelpers { diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockSocket.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockSocket.cs index 5bbc793c6f..a8ab5075f3 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockSocket.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockSocket.cs @@ -2,8 +2,8 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; -using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking; namespace Microsoft.AspNetCore.Server.KestrelTests.TestHelpers { diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestInput.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/TestInput.cs index e017c983dd..9bf6c5cc6d 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/TestInput.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/TestInput.cs @@ -6,7 +6,7 @@ using System.IO.Pipelines; using System.Text; using System.Threading; using System.Threading.Tasks; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions; using Microsoft.AspNetCore.Testing; using Microsoft.Extensions.Internal; diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/UvStreamHandleTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/UvStreamHandleTests.cs index 153d1b28ef..d08e8a39f3 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/UvStreamHandleTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/UvStreamHandleTests.cs @@ -1,8 +1,8 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; -using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking; using Microsoft.AspNetCore.Server.KestrelTests.TestHelpers; using Microsoft.AspNetCore.Testing; using Moq; diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/UvTimerHandleTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/UvTimerHandleTests.cs index 628b078752..832e699c18 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/UvTimerHandleTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/UvTimerHandleTests.cs @@ -1,8 +1,8 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; -using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking; using Microsoft.AspNetCore.Testing; using Xunit; diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/WebHostBuilderKestrelExtensionsTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/WebHostBuilderKestrelExtensionsTests.cs index 4eeebba773..6e88011a92 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/WebHostBuilderKestrelExtensionsTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/WebHostBuilderKestrelExtensionsTests.cs @@ -2,7 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using Microsoft.AspNetCore.Hosting; -using Microsoft.AspNetCore.Server.Kestrel; +using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.Extensions.DependencyInjection; using Xunit; diff --git a/test/shared/HttpParsingData.cs b/test/shared/HttpParsingData.cs index 944a1f936d..a4d3d5521f 100644 --- a/test/shared/HttpParsingData.cs +++ b/test/shared/HttpParsingData.cs @@ -4,7 +4,7 @@ using System; using System.Collections.Generic; using System.Linq; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; using Xunit; namespace Microsoft.AspNetCore.Testing diff --git a/test/shared/MockConnection.cs b/test/shared/MockConnection.cs index aebb7807a4..d37696f9c7 100644 --- a/test/shared/MockConnection.cs +++ b/test/shared/MockConnection.cs @@ -4,13 +4,13 @@ using System; using System.Threading; using System.Threading.Tasks; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal; using Microsoft.Extensions.Internal; namespace Microsoft.AspNetCore.Testing { - public class MockConnection : Connection, IDisposable + public class MockConnection : LibuvConnection, IDisposable { private readonly TaskCompletionSource _socketClosedTcs = new TaskCompletionSource(); diff --git a/test/shared/MockSocketOutput.cs b/test/shared/MockSocketOutput.cs index c5cdc32cb2..69dd468c23 100644 --- a/test/shared/MockSocketOutput.cs +++ b/test/shared/MockSocketOutput.cs @@ -5,7 +5,7 @@ using System; using System.IO.Pipelines; using System.Threading; using System.Threading.Tasks; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; using Microsoft.Extensions.Internal; namespace Microsoft.AspNetCore.Testing diff --git a/test/shared/MockSystemClock.cs b/test/shared/MockSystemClock.cs index 5a903c1f2e..0032f2de7c 100644 --- a/test/shared/MockSystemClock.cs +++ b/test/shared/MockSystemClock.cs @@ -2,7 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; namespace Microsoft.AspNetCore.Testing { diff --git a/test/shared/PassThroughConnectionAdapter.cs b/test/shared/PassThroughConnectionAdapter.cs index 35d04ab469..7384eaa613 100644 --- a/test/shared/PassThroughConnectionAdapter.cs +++ b/test/shared/PassThroughConnectionAdapter.cs @@ -4,8 +4,8 @@ using System.IO; using System.Threading.Tasks; using Microsoft.AspNetCore.Http.Features; -using Microsoft.AspNetCore.Server.Kestrel.Adapter; -using Microsoft.AspNetCore.Server.Kestrel.Adapter.Internal; +using Microsoft.AspNetCore.Server.Kestrel.Core.Adapter; +using Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal; namespace Microsoft.AspNetCore.Testing { diff --git a/test/shared/TestApplicationErrorLogger.cs b/test/shared/TestApplicationErrorLogger.cs index 76ee249a36..dcba1da052 100644 --- a/test/shared/TestApplicationErrorLogger.cs +++ b/test/shared/TestApplicationErrorLogger.cs @@ -4,7 +4,8 @@ using System; using System.Collections.Concurrent; using System.Linq; -using Microsoft.AspNetCore.Server.Kestrel.Internal; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; using Microsoft.Extensions.Logging; namespace Microsoft.AspNetCore.Testing diff --git a/test/shared/TestFrame.cs b/test/shared/TestFrame.cs index cc2d262bd4..65eb198c8b 100644 --- a/test/shared/TestFrame.cs +++ b/test/shared/TestFrame.cs @@ -3,7 +3,7 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Hosting.Server; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; namespace Microsoft.AspNetCore.Testing { diff --git a/test/shared/TestKestrelTrace.cs b/test/shared/TestKestrelTrace.cs index 93f1c87d40..8e0a469dc7 100644 --- a/test/shared/TestKestrelTrace.cs +++ b/test/shared/TestKestrelTrace.cs @@ -1,7 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using Microsoft.AspNetCore.Server.Kestrel.Internal; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal; namespace Microsoft.AspNetCore.Testing { diff --git a/test/shared/TestServer.cs b/test/shared/TestServer.cs index fc4e91b195..f9224babdb 100644 --- a/test/shared/TestServer.cs +++ b/test/shared/TestServer.cs @@ -5,8 +5,9 @@ using System; using System.Net; using System.Net.Sockets; using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Server.Kestrel; -using Microsoft.AspNetCore.Server.Kestrel.Internal; +using Microsoft.AspNetCore.Server.Kestrel.Core; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv; namespace Microsoft.AspNetCore.Testing { @@ -15,7 +16,7 @@ namespace Microsoft.AspNetCore.Testing /// public class TestServer : IDisposable { - private KestrelEngine _engine; + private LibuvTransport _transport; private ListenOptions _listenOptions; public TestServer(RequestDelegate app) @@ -47,13 +48,13 @@ namespace Microsoft.AspNetCore.Testing try { - _engine = new KestrelEngine(context.TransportContext, _listenOptions); - _engine.BindAsync().Wait(); + _transport = new LibuvTransport(context.TransportContext, _listenOptions); + _transport.BindAsync().Wait(); } catch { - _engine.UnbindAsync().Wait(); - _engine.StopAsync().Wait(); + _transport.UnbindAsync().Wait(); + _transport.StopAsync().Wait(); throw; } } @@ -71,8 +72,8 @@ namespace Microsoft.AspNetCore.Testing public void Dispose() { - _engine.UnbindAsync().Wait(); - _engine.StopAsync().Wait(); + _transport.UnbindAsync().Wait(); + _transport.StopAsync().Wait(); } } } diff --git a/test/shared/TestServiceContext.cs b/test/shared/TestServiceContext.cs index 2c1fb53846..ca9c28cecc 100644 --- a/test/shared/TestServiceContext.cs +++ b/test/shared/TestServiceContext.cs @@ -2,14 +2,12 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Server.Kestrel; -using Microsoft.AspNetCore.Server.Kestrel.Internal; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Core; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv; using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal; -using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Infrastructure; namespace Microsoft.AspNetCore.Testing { diff --git a/tools/CodeGenerator/FrameFeatureCollection.cs b/tools/CodeGenerator/FrameFeatureCollection.cs index 6c85665fe9..e487a36a94 100644 --- a/tools/CodeGenerator/FrameFeatureCollection.cs +++ b/tools/CodeGenerator/FrameFeatureCollection.cs @@ -72,7 +72,7 @@ namespace CodeGenerator using System; using System.Collections.Generic; -namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http {{ public partial class Frame {{{Each(allFeatures, feature => $@" diff --git a/tools/CodeGenerator/KnownHeaders.cs b/tools/CodeGenerator/KnownHeaders.cs index 6f8ef86303..e5feb937f2 100644 --- a/tools/CodeGenerator/KnownHeaders.cs +++ b/tools/CodeGenerator/KnownHeaders.cs @@ -292,11 +292,11 @@ namespace CodeGenerator using System; using System.Collections.Generic; using System.IO.Pipelines; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; using Microsoft.Extensions.Primitives; using Microsoft.Net.Http.Headers; -namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http {{ {Each(loops, loop => $@" public partial class {loop.ClassName} From b40d8b4248b6dad39bccc1a8d4aa1e10acbd5b2f Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Tue, 4 Apr 2017 21:30:33 -0700 Subject: [PATCH 1181/1662] Fix naming of IConnectionInformation.OutputReaderScheduler (#1608) --- .../Internal/ConnectionHandler.cs | 2 +- .../IConnectionInformation.cs | 2 +- .../Internal/LibuvConnectionContext.cs | 2 +- .../Mocks/MockConnectionInformation.cs | 2 +- test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/ConnectionHandler.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/ConnectionHandler.cs index 1376c975ed..c086397090 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/ConnectionHandler.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/ConnectionHandler.cs @@ -25,7 +25,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal public IConnectionContext OnConnection(IConnectionInformation connectionInfo) { var inputPipe = connectionInfo.PipeFactory.Create(GetInputPipeOptions(connectionInfo.InputWriterScheduler)); - var outputPipe = connectionInfo.PipeFactory.Create(GetOutputPipeOptions(connectionInfo.OutputWriterScheduler)); + var outputPipe = connectionInfo.PipeFactory.Create(GetOutputPipeOptions(connectionInfo.OutputReaderScheduler)); var connectionId = CorrelationIdGenerator.GetNextId(); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/IConnectionInformation.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/IConnectionInformation.cs index ee02110c0a..f0d4da9085 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/IConnectionInformation.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/IConnectionInformation.cs @@ -13,7 +13,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions PipeFactory PipeFactory { get; } IScheduler InputWriterScheduler { get; } - IScheduler OutputWriterScheduler { get; } + IScheduler OutputReaderScheduler { get; } // TODO: Remove timeout management from transport ITimeoutControl TimeoutControl { get; } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvConnectionContext.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvConnectionContext.cs index b1a198c8f8..e20796289d 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvConnectionContext.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvConnectionContext.cs @@ -25,7 +25,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal public PipeFactory PipeFactory => ListenerContext.Thread.PipelineFactory; public IScheduler InputWriterScheduler => ListenerContext.Thread; - public IScheduler OutputWriterScheduler => ListenerContext.Thread; + public IScheduler OutputReaderScheduler => ListenerContext.Thread; public ITimeoutControl TimeoutControl { get; set; } } diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Mocks/MockConnectionInformation.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Mocks/MockConnectionInformation.cs index 744ab1a601..6429e94220 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Mocks/MockConnectionInformation.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Mocks/MockConnectionInformation.cs @@ -14,7 +14,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance public PipeFactory PipeFactory { get; } public IScheduler InputWriterScheduler { get; } - public IScheduler OutputWriterScheduler { get; } + public IScheduler OutputReaderScheduler { get; } public ITimeoutControl TimeoutControl { get; } = new MockTimeoutControl(); diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs index f4fd2ae784..45949cb5f2 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs @@ -716,7 +716,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests public IPEndPoint LocalEndPoint { get; } public PipeFactory PipeFactory { get; } public IScheduler InputWriterScheduler { get; } - public IScheduler OutputWriterScheduler { get; } + public IScheduler OutputReaderScheduler { get; } public ITimeoutControl TimeoutControl { get; set; } = Mock.Of(); } } From adea477824c68d54e3ae6e1612b8c22500945aaa Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Wed, 5 Apr 2017 10:09:31 -0700 Subject: [PATCH 1182/1662] Re-write commented out tests in RequestHeaderLimitsTests as Frame tests (#1583). --- .../RequestHeaderLimitsTests.cs | 153 +----------------- .../FrameTests.cs | 128 +++++++++++++++ 2 files changed, 130 insertions(+), 151 deletions(-) diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestHeaderLimitsTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestHeaderLimitsTests.cs index 65b4eaaef8..d5087cc23f 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestHeaderLimitsTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestHeaderLimitsTests.cs @@ -1,15 +1,11 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System; -using System.Collections; -using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.AspNetCore.Testing; -using Microsoft.Extensions.Primitives; using Xunit; namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests @@ -80,108 +76,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } } - //[Theory] - //[InlineData(1, 1)] - //[InlineData(5, 5)] - //[InlineData(100, 100)] - //[InlineData(600, 100)] - //[InlineData(700, 1)] - //[InlineData(1, 700)] - //public async Task ServerAcceptsHeadersAcrossSends(int header0Count, int header1Count) - //{ - // var headers0 = MakeHeaders(header0Count); - // var headers1 = MakeHeaders(header1Count, header0Count); - - // using (var server = CreateServer(maxRequestHeaderCount: header0Count + header1Count)) - // { - // using (var connection = new TestConnection(server.Port)) - // { - // await connection.SendAll("GET / HTTP/1.1\r\n"); - // // Wait for parsing to start - // await WaitForCondition(TimeSpan.FromSeconds(1), () => server.Frame?.RequestHeaders != null); - - // Assert.Equal(0, server.Frame.RequestHeaders.Count); - - // await connection.SendAll(headers0); - // // Wait for headers to be parsed - // await WaitForCondition(TimeSpan.FromSeconds(1), () => server.Frame.RequestHeaders.Count >= header0Count); - - // Assert.Equal(header0Count, server.Frame.RequestHeaders.Count); - - // await connection.SendAll(headers1); - // // Wait for headers to be parsed - // await WaitForCondition(TimeSpan.FromSeconds(1), () => server.Frame.RequestHeaders.Count >= header0Count + header1Count); - - // Assert.Equal(header0Count + header1Count, server.Frame.RequestHeaders.Count); - - // await connection.SendAll("\r\n"); - // await connection.ReceiveEnd( - // "HTTP/1.1 200 OK", - // $"Date: {server.Context.DateHeaderValue}", - // "Transfer-Encoding: chunked", - // "", - // "c", - // "hello, world", - // "0", - // "", - // ""); - // } - // } - //} - - //[Theory] - //[InlineData(1, 1)] - //[InlineData(5, 5)] - //public async Task ServerKeepsSameHeaderCollectionAcrossSends(int header0Count, int header1Count) - //{ - // var headers0 = MakeHeaders(header0Count); - // var headers1 = MakeHeaders(header0Count, header1Count); - - // using (var server = CreateServer(maxRequestHeaderCount: header0Count + header1Count)) - // { - // using (var connection = new TestConnection(server.Port)) - // { - // await connection.SendAll("GET / HTTP/1.1\r\n"); - // // Wait for parsing to start - // await WaitForCondition(TimeSpan.FromSeconds(1), () => server.Frame?.RequestHeaders != null); - - // Assert.Equal(0, server.Frame.RequestHeaders.Count); - - // var newRequestHeaders = new RequestHeadersWrapper(server.Frame.RequestHeaders); - // server.Frame.RequestHeaders = newRequestHeaders; - - // Assert.Same(newRequestHeaders, server.Frame.RequestHeaders); - - // await connection.SendAll(headers0); - // // Wait for headers to be parsed - // await WaitForCondition(TimeSpan.FromSeconds(1), () => server.Frame.RequestHeaders.Count >= header0Count); - - // Assert.Same(newRequestHeaders, server.Frame.RequestHeaders); - // Assert.Equal(header0Count, server.Frame.RequestHeaders.Count); - - // await connection.SendAll(headers1); - // // Wait for headers to be parsed - // await WaitForCondition(TimeSpan.FromSeconds(1), () => server.Frame.RequestHeaders.Count >= header0Count + header1Count); - - // Assert.Equal(header0Count + header1Count, server.Frame.RequestHeaders.Count); - - // Assert.Same(newRequestHeaders, server.Frame.RequestHeaders); - - // await connection.SendAll("\r\n"); - // await connection.ReceiveEnd( - // "HTTP/1.1 200 OK", - // $"Date: {server.Context.DateHeaderValue}", - // "Transfer-Encoding: chunked", - // "", - // "c", - // "hello, world", - // "0", - // "", - // ""); - // } - // } - //} - [Theory] [InlineData(1)] [InlineData(5)] @@ -229,26 +123,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } } - private static async Task WaitForCondition(TimeSpan timeout, Func condition) - { - const int MaxWaitLoop = 150; - - var delay = (int)Math.Ceiling(timeout.TotalMilliseconds / MaxWaitLoop); - - var waitLoop = 0; - while (waitLoop < MaxWaitLoop && !condition()) - { - // Wait for parsing condition to trigger - await Task.Delay(delay); - waitLoop++; - } - } - - private static string MakeHeaders(int count, int startAt = 0) + private static string MakeHeaders(int count) { return string.Join("", Enumerable .Range(0, count) - .Select(i => $"Header-{startAt + i}: value{startAt + i}\r\n")); + .Select(i => $"Header-{i}: value{i}\r\n")); } private TestServer CreateServer(int? maxRequestHeaderCount = null, int? maxRequestHeadersTotalSize = null) @@ -270,33 +149,5 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests ServerOptions = options }); } - - private class RequestHeadersWrapper : IHeaderDictionary - { - IHeaderDictionary _innerHeaders; - - public RequestHeadersWrapper(IHeaderDictionary headers) - { - _innerHeaders = headers; - } - - public StringValues this[string key] { get => _innerHeaders[key]; set => _innerHeaders[key] = value; } - public long? ContentLength { get => _innerHeaders.ContentLength; set => _innerHeaders.ContentLength = value; } - public ICollection Keys => _innerHeaders.Keys; - public ICollection Values => _innerHeaders.Values; - public int Count => _innerHeaders.Count; - public bool IsReadOnly => _innerHeaders.IsReadOnly; - public void Add(string key, StringValues value) => _innerHeaders.Add(key, value); - public void Add(KeyValuePair item) => _innerHeaders.Add(item); - public void Clear() => _innerHeaders.Clear(); - public bool Contains(KeyValuePair item) => _innerHeaders.Contains(item); - public bool ContainsKey(string key) => _innerHeaders.ContainsKey(key); - public void CopyTo(KeyValuePair[] array, int arrayIndex) => _innerHeaders.CopyTo(array, arrayIndex); - public IEnumerator> GetEnumerator() => _innerHeaders.GetEnumerator(); - public bool Remove(string key) => _innerHeaders.Remove(key); - public bool Remove(KeyValuePair item) => _innerHeaders.Remove(item); - public bool TryGetValue(string key, out StringValues value) => _innerHeaders.TryGetValue(key, out value); - IEnumerator IEnumerable.GetEnumerator() => _innerHeaders.GetEnumerator(); - } } } \ No newline at end of file diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs index 45949cb5f2..2f7ac31e61 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs @@ -2,9 +2,11 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Collections; using System.Collections.Generic; using System.IO; using System.IO.Pipelines; +using System.Linq; using System.Net; using System.Text; using System.Threading; @@ -20,6 +22,7 @@ using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions; using Microsoft.AspNetCore.Testing; using Microsoft.Extensions.Internal; using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Primitives; using Moq; using Xunit; @@ -640,6 +643,103 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } } + [Theory] + [InlineData(1, 1)] + [InlineData(5, 5)] + [InlineData(100, 100)] + [InlineData(600, 100)] + [InlineData(700, 1)] + [InlineData(1, 700)] + public async Task AcceptsHeadersAcrossSends(int header0Count, int header1Count) + { + _serviceContext.ServerOptions.Limits.MaxRequestHeaderCount = header0Count + header1Count; + + var headers0 = MakeHeaders(header0Count); + var headers1 = MakeHeaders(header1Count, header0Count); + + var requestProcessingTask = _frame.RequestProcessingAsync(); + + await _input.Writer.WriteAsync(Encoding.ASCII.GetBytes("GET / HTTP/1.0\r\n")); + await WaitForCondition(TimeSpan.FromSeconds(1), () => _frame.RequestHeaders != null); + Assert.Equal(0, _frame.RequestHeaders.Count); + + await _input.Writer.WriteAsync(Encoding.ASCII.GetBytes(headers0)); + await WaitForCondition(TimeSpan.FromSeconds(1), () => _frame.RequestHeaders.Count >= header0Count); + Assert.Equal(header0Count, _frame.RequestHeaders.Count); + + await _input.Writer.WriteAsync(Encoding.ASCII.GetBytes(headers1)); + await WaitForCondition(TimeSpan.FromSeconds(1), () => _frame.RequestHeaders.Count >= header0Count + header1Count); + Assert.Equal(header0Count + header1Count, _frame.RequestHeaders.Count); + + await _input.Writer.WriteAsync(Encoding.ASCII.GetBytes("\r\n")); + Assert.Equal(header0Count + header1Count, _frame.RequestHeaders.Count); + + await requestProcessingTask.TimeoutAfter(TimeSpan.FromSeconds(10)); + } + + [Theory] + [InlineData(1, 1)] + [InlineData(5, 5)] + [InlineData(100, 100)] + [InlineData(600, 100)] + [InlineData(700, 1)] + [InlineData(1, 700)] + public async Task KeepsSameHeaderCollectionAcrossSends(int header0Count, int header1Count) + { + _serviceContext.ServerOptions.Limits.MaxRequestHeaderCount = header0Count + header1Count; + + var headers0 = MakeHeaders(header0Count); + var headers1 = MakeHeaders(header1Count, header0Count); + + var requestProcessingTask = _frame.RequestProcessingAsync(); + + await _input.Writer.WriteAsync(Encoding.ASCII.GetBytes("GET / HTTP/1.0\r\n")); + await WaitForCondition(TimeSpan.FromSeconds(1), () => _frame.RequestHeaders != null); + Assert.Equal(0, _frame.RequestHeaders.Count); + + var newRequestHeaders = new RequestHeadersWrapper(_frame.RequestHeaders); + _frame.RequestHeaders = newRequestHeaders; + Assert.Same(newRequestHeaders, _frame.RequestHeaders); + + await _input.Writer.WriteAsync(Encoding.ASCII.GetBytes(headers0)); + await WaitForCondition(TimeSpan.FromSeconds(1), () => _frame.RequestHeaders.Count >= header0Count); + Assert.Same(newRequestHeaders, _frame.RequestHeaders); + Assert.Equal(header0Count, _frame.RequestHeaders.Count); + + await _input.Writer.WriteAsync(Encoding.ASCII.GetBytes(headers1)); + await WaitForCondition(TimeSpan.FromSeconds(1), () => _frame.RequestHeaders.Count >= header0Count + header1Count); + Assert.Same(newRequestHeaders, _frame.RequestHeaders); + Assert.Equal(header0Count + header1Count, _frame.RequestHeaders.Count); + + await _input.Writer.WriteAsync(Encoding.ASCII.GetBytes("\r\n")); + Assert.Same(newRequestHeaders, _frame.RequestHeaders); + Assert.Equal(header0Count + header1Count, _frame.RequestHeaders.Count); + + await requestProcessingTask.TimeoutAfter(TimeSpan.FromSeconds(10)); + } + + private static async Task WaitForCondition(TimeSpan timeout, Func condition) + { + const int MaxWaitLoop = 150; + + var delay = (int)Math.Ceiling(timeout.TotalMilliseconds / MaxWaitLoop); + + var waitLoop = 0; + while (waitLoop < MaxWaitLoop && !condition()) + { + // Wait for parsing condition to trigger + await Task.Delay(delay); + waitLoop++; + } + } + + private static string MakeHeaders(int count, int startAt = 0) + { + return string.Join("", Enumerable + .Range(0, count) + .Select(i => $"Header-{startAt + i}: value{startAt + i}\r\n")); + } + public static IEnumerable RequestLineValidData => HttpParsingData.RequestLineValidData; public static IEnumerable RequestLineDotSegmentData => HttpParsingData.RequestLineDotSegmentData; @@ -719,5 +819,33 @@ namespace Microsoft.AspNetCore.Server.KestrelTests public IScheduler OutputReaderScheduler { get; } public ITimeoutControl TimeoutControl { get; set; } = Mock.Of(); } + + private class RequestHeadersWrapper : IHeaderDictionary + { + IHeaderDictionary _innerHeaders; + + public RequestHeadersWrapper(IHeaderDictionary headers) + { + _innerHeaders = headers; + } + + public StringValues this[string key] { get => _innerHeaders[key]; set => _innerHeaders[key] = value; } + public long? ContentLength { get => _innerHeaders.ContentLength; set => _innerHeaders.ContentLength = value; } + public ICollection Keys => _innerHeaders.Keys; + public ICollection Values => _innerHeaders.Values; + public int Count => _innerHeaders.Count; + public bool IsReadOnly => _innerHeaders.IsReadOnly; + public void Add(string key, StringValues value) => _innerHeaders.Add(key, value); + public void Add(KeyValuePair item) => _innerHeaders.Add(item); + public void Clear() => _innerHeaders.Clear(); + public bool Contains(KeyValuePair item) => _innerHeaders.Contains(item); + public bool ContainsKey(string key) => _innerHeaders.ContainsKey(key); + public void CopyTo(KeyValuePair[] array, int arrayIndex) => _innerHeaders.CopyTo(array, arrayIndex); + public IEnumerator> GetEnumerator() => _innerHeaders.GetEnumerator(); + public bool Remove(string key) => _innerHeaders.Remove(key); + public bool Remove(KeyValuePair item) => _innerHeaders.Remove(item); + public bool TryGetValue(string key, out StringValues value) => _innerHeaders.TryGetValue(key, out value); + IEnumerator IEnumerable.GetEnumerator() => _innerHeaders.GetEnumerator(); + } } } From bab4332a471d9d45657af10015da0b132abb61cc Mon Sep 17 00:00:00 2001 From: David Fowler Date: Wed, 5 Apr 2017 10:09:43 -0700 Subject: [PATCH 1183/1662] Add benchmark that drains the buffer without going through the pipe (#1611) --- .../RequestParsingBenchmark.cs | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsingBenchmark.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsingBenchmark.cs index 08507ef3b8..3a35b3d808 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsingBenchmark.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsingBenchmark.cs @@ -67,6 +67,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance } } + [Benchmark(OperationsPerInvoke = RequestParsingData.InnerLoopCount * RequestParsingData.Pipelining)] + public void PipelinedPlaintextTechEmpowerDrainBuffer() + { + for (var i = 0; i < RequestParsingData.InnerLoopCount; i++) + { + InsertData(RequestParsingData.PlaintextTechEmpowerPipelinedRequests); + ParseDataDrainBuffer(); + } + } + [Benchmark(OperationsPerInvoke = RequestParsingData.InnerLoopCount)] public void LiveAspNet() { @@ -115,6 +125,41 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance buffer.FlushAsync().GetAwaiter().GetResult(); } + private void ParseDataDrainBuffer() + { + var awaitable = Pipe.Reader.ReadAsync(); + if (!awaitable.IsCompleted) + { + // No more data + return; + } + + var readableBuffer = awaitable.GetResult().Buffer; + do + { + Frame.Reset(); + + if (!Frame.TakeStartLine(readableBuffer, out var consumed, out var examined)) + { + ErrorUtilities.ThrowInvalidRequestLine(); + } + + readableBuffer = readableBuffer.Slice(consumed); + + Frame.InitializeHeaders(); + + if (!Frame.TakeMessageHeaders(readableBuffer, out consumed, out examined)) + { + ErrorUtilities.ThrowInvalidRequestHeaders(); + } + + readableBuffer = readableBuffer.Slice(consumed); + } + while (readableBuffer.Length > 0); + + Pipe.Reader.Advance(readableBuffer.End); + } + private void ParseData() { do From 7d50f34b85d41820e14246560e3f87e318b68e18 Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Wed, 5 Apr 2017 11:23:04 -0700 Subject: [PATCH 1184/1662] Show unexpected error logs in assertion failures. --- .../HttpsTests.cs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/HttpsTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/HttpsTests.cs index 113ddc1830..dc075abf9e 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/HttpsTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/HttpsTests.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Collections.Generic; using System.Net; using System.Net.Security; using System.Net.Sockets; @@ -52,7 +53,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests Assert.Equal(1, loggerFactory.FilterLogger.LastEventId.Id); Assert.Equal(LogLevel.Information, loggerFactory.FilterLogger.LastLogLevel); - Assert.Equal(0, loggerFactory.ErrorLogger.TotalErrorsLogged); + Assert.True(loggerFactory.ErrorLogger.TotalErrorsLogged == 0, + userMessage: string.Join(Environment.NewLine, loggerFactory.ErrorLogger.ErrorMessages)); } [Fact] @@ -87,7 +89,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests Assert.Equal(1, loggerFactory.FilterLogger.LastEventId.Id); Assert.Equal(LogLevel.Information, loggerFactory.FilterLogger.LastLogLevel); - Assert.Equal(0, loggerFactory.ErrorLogger.TotalErrorsLogged); + Assert.True(loggerFactory.ErrorLogger.TotalErrorsLogged == 0, + userMessage: string.Join(Environment.NewLine, loggerFactory.ErrorLogger.ErrorMessages)); } // Regression test for https://github.com/aspnet/KestrelHttpServer/issues/1103#issuecomment-246971172 @@ -277,7 +280,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests private class ApplicationErrorLogger : ILogger { - public int TotalErrorsLogged { get; set; } + private List _errorMessages = new List(); + + public IEnumerable ErrorMessages => _errorMessages; + + public int TotalErrorsLogged => _errorMessages.Count; public bool ObjectDisposedExceptionLogged { get; set; } @@ -285,7 +292,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { if (logLevel == LogLevel.Error) { - TotalErrorsLogged++; + _errorMessages.Add(formatter(state, exception)); } if (exception is ObjectDisposedException) From dd02ba577fdb17ff540863df87286062a33579b7 Mon Sep 17 00:00:00 2001 From: Pavel Krymets Date: Wed, 5 Apr 2017 15:37:45 -0700 Subject: [PATCH 1185/1662] Use corefxlab and corefx by source (#1612) --- .../Adapter/Internal/AdaptedPipeline.cs | 2 +- .../Adapter/Internal/RawStream.cs | 2 +- .../Adapter/Internal/StreamSocketOutput.cs | 2 +- .../Internal/ConnectionHandler.cs | 2 +- .../Internal/FrameConnection.cs | 2 +- .../Internal/FrameConnectionContext.cs | 2 +- .../Internal/Http/ChunkWriter.cs | 2 +- .../Internal/Http/ConnectionLifetimeControl.cs | 2 +- .../Internal/Http/Frame.cs | 5 +++-- .../Internal/Http/FrameHeaders.Generated.cs | 2 +- .../Internal/Http/FrameRequestHeaders.cs | 2 +- .../Internal/Http/FrameResponseHeaders.cs | 2 +- .../Internal/Http/IHttpHeadersHandler.cs | 2 +- .../Internal/Http/IHttpParser.cs | 2 +- .../Internal/Http/IHttpRequestLineHandler.cs | 2 +- .../Internal/Http/ISocketOutput.cs | 2 +- .../Internal/Http/KestrelHttpParser.cs | 6 +++--- .../Internal/Http/MessageBody.cs | 2 +- .../Internal/Http/OutputProducer.cs | 2 +- .../Internal/Http/PathNormalizer.cs | 2 +- .../Internal/Http/PipelineExtensions.cs | 4 +++- .../Internal/Infrastructure/HttpUtilities.cs | 1 + .../Internal/Infrastructure/IThreadPool.cs | 2 +- .../Microsoft.AspNetCore.Server.Kestrel.Core.csproj | 6 ++---- .../IConnectionContext.cs | 2 +- .../IConnectionInformation.cs | 2 +- ....AspNetCore.Server.Kestrel.Transport.Abstractions.csproj | 6 ++++-- .../Internal/LibuvConnection.cs | 2 +- .../Internal/LibuvConnectionContext.cs | 2 +- .../Internal/LibuvOutputConsumer.cs | 2 +- .../Internal/LibuvThread.cs | 2 +- .../Internal/Networking/UvWriteReq.cs | 4 ++-- .../FrameParsingOverheadBenchmark.cs | 4 ++-- .../FrameWritingBenchmark.cs | 2 +- .../KestrelHttpParserBenchmark.cs | 4 ++-- .../KnownStringsBenchmark.cs | 1 + .../Mocks/MockConnectionInformation.cs | 2 +- .../PipeThroughputBenchmark.cs | 2 +- .../RequestParsingBenchmark.cs | 2 +- .../ResponseHeadersWritingBenchmark.cs | 2 +- .../AsciiDecoding.cs | 1 + .../FrameResponseHeadersTests.cs | 2 +- test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs | 2 +- .../HttpParserTests.cs | 6 +++--- .../HttpUtilitiesTest.cs | 1 + .../LibuvOutputConsumerTests.cs | 2 +- .../MultipleLoopTests.cs | 2 +- .../NetworkingTests.cs | 2 +- .../PathNormalizerTests.cs | 1 + .../PipeOptionsTests.cs | 2 +- .../PipelineExtensionTests.cs | 3 ++- .../StreamSocketOutputTests.cs | 2 +- .../TestHelpers/AssertExtensions.cs | 2 +- .../TestHelpers/MockConnectionHandler.cs | 2 +- test/Microsoft.AspNetCore.Server.KestrelTests/TestInput.cs | 2 +- test/shared/MockSocketOutput.cs | 2 +- tools/CodeGenerator/KnownHeaders.cs | 2 +- 57 files changed, 73 insertions(+), 64 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/Internal/AdaptedPipeline.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/Internal/AdaptedPipeline.cs index 7d943c0c8d..785c397468 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/Internal/AdaptedPipeline.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/Internal/AdaptedPipeline.cs @@ -3,9 +3,9 @@ using System; using System.IO; -using System.IO.Pipelines; using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/Internal/RawStream.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/Internal/RawStream.cs index 170f068801..9c32f272a9 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/Internal/RawStream.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/Internal/RawStream.cs @@ -3,10 +3,10 @@ using System; using System.IO; -using System.IO.Pipelines; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/Internal/StreamSocketOutput.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/Internal/StreamSocketOutput.cs index 9b351e8874..7fb38dc67c 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/Internal/StreamSocketOutput.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/Internal/StreamSocketOutput.cs @@ -3,10 +3,10 @@ using System; using System.IO; -using System.IO.Pipelines; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/ConnectionHandler.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/ConnectionHandler.cs index c086397090..ff075f35da 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/ConnectionHandler.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/ConnectionHandler.cs @@ -1,10 +1,10 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System.IO.Pipelines; using Microsoft.AspNetCore.Hosting.Server; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnection.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnection.cs index e59689b163..a80d3f6e92 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnection.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnection.cs @@ -4,12 +4,12 @@ using System; using System.Collections.Generic; using System.IO; -using System.IO.Pipelines; using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Core.Adapter; using Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions; using Microsoft.Extensions.Internal; using Microsoft.Extensions.Logging; diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnectionContext.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnectionContext.cs index 61414ed429..f04ea5f877 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnectionContext.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnectionContext.cs @@ -2,9 +2,9 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Collections.Generic; -using System.IO.Pipelines; using Microsoft.AspNetCore.Server.Kestrel.Core.Adapter; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/ChunkWriter.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/ChunkWriter.cs index 27b7dadba5..06ad5877ad 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/ChunkWriter.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/ChunkWriter.cs @@ -2,8 +2,8 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.IO.Pipelines; using System.Text; +using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/ConnectionLifetimeControl.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/ConnectionLifetimeControl.cs index 7e44f26f59..1d6efcd6db 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/ConnectionLifetimeControl.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/ConnectionLifetimeControl.cs @@ -1,8 +1,8 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System.IO.Pipelines; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.cs index 35e7f4cdea..53c723081e 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.cs @@ -5,17 +5,18 @@ using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; -using System.IO.Pipelines; using System.Linq; using System.Net; using System.Runtime.CompilerServices; using System.Text; -using System.Text.Encodings.Web.Utf8; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Server.Kestrel.Core.Adapter; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Internal.System; +using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; +using Microsoft.AspNetCore.Server.Kestrel.Internal.System.Text.Encodings.Web.Utf8; using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions; using Microsoft.Extensions.Internal; using Microsoft.Extensions.Logging; diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameHeaders.Generated.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameHeaders.Generated.cs index 8d182b0234..dd2f346ecc 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameHeaders.Generated.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameHeaders.Generated.cs @@ -3,8 +3,8 @@ using System; using System.Collections.Generic; -using System.IO.Pipelines; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; using Microsoft.Extensions.Primitives; using Microsoft.Net.Http.Headers; diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameRequestHeaders.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameRequestHeaders.cs index f210549803..c11b654a8e 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameRequestHeaders.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameRequestHeaders.cs @@ -1,11 +1,11 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System; using System.Collections; using System.Collections.Generic; using System.Runtime.CompilerServices; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Internal.System; using Microsoft.Extensions.Primitives; using Microsoft.Net.Http.Headers; diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameResponseHeaders.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameResponseHeaders.cs index 262496dd60..f0dc531e48 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameResponseHeaders.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameResponseHeaders.cs @@ -4,8 +4,8 @@ using System; using System.Collections; using System.Collections.Generic; -using System.IO.Pipelines; using System.Runtime.CompilerServices; +using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; using Microsoft.Extensions.Primitives; using Microsoft.Net.Http.Headers; diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/IHttpHeadersHandler.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/IHttpHeadersHandler.cs index 9a322f0da9..a9ad79559a 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/IHttpHeadersHandler.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/IHttpHeadersHandler.cs @@ -1,7 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System; +using Microsoft.AspNetCore.Server.Kestrel.Internal.System; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/IHttpParser.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/IHttpParser.cs index 0af7ef01b7..f9b8ec2e21 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/IHttpParser.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/IHttpParser.cs @@ -1,7 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System.IO.Pipelines; +using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/IHttpRequestLineHandler.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/IHttpRequestLineHandler.cs index ac91138512..05088aacc4 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/IHttpRequestLineHandler.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/IHttpRequestLineHandler.cs @@ -1,7 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System; +using Microsoft.AspNetCore.Server.Kestrel.Internal.System; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/ISocketOutput.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/ISocketOutput.cs index 494e6df8de..d12bd67310 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/ISocketOutput.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/ISocketOutput.cs @@ -2,9 +2,9 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.IO.Pipelines; using System.Threading; using System.Threading.Tasks; +using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/KestrelHttpParser.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/KestrelHttpParser.cs index c1131fd6c1..346a0abfe8 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/KestrelHttpParser.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/KestrelHttpParser.cs @@ -1,11 +1,11 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System; -using System.IO.Pipelines; using System.Numerics; using System.Runtime.CompilerServices; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Internal.System; +using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; using Microsoft.Extensions.Logging; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http @@ -70,7 +70,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http private unsafe void ParseRequestLine(T handler, byte* data, int length) where T : IHttpRequestLineHandler { int offset; - Span customMethod; + Span customMethod = default(Span); // Get Method and set the offset var method = HttpUtilities.GetKnownMethod(data, length, out offset); if (method == HttpMethod.Custom) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/MessageBody.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/MessageBody.cs index 837a30c027..97fff771fa 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/MessageBody.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/MessageBody.cs @@ -3,10 +3,10 @@ using System; using System.IO; -using System.IO.Pipelines; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; using Microsoft.Extensions.Internal; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/OutputProducer.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/OutputProducer.cs index 7aee461ca7..83294c7ed5 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/OutputProducer.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/OutputProducer.cs @@ -2,10 +2,10 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.IO.Pipelines; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; using Microsoft.Extensions.Internal; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/PathNormalizer.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/PathNormalizer.cs index de076e1849..645dd4629c 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/PathNormalizer.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/PathNormalizer.cs @@ -1,8 +1,8 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System; using System.Diagnostics; +using Microsoft.AspNetCore.Server.Kestrel.Internal.System; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/PipelineExtensions.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/PipelineExtensions.cs index 233544deb6..19ce278bea 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/PipelineExtensions.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/PipelineExtensions.cs @@ -3,9 +3,11 @@ using System; using System.Buffers; -using System.IO.Pipelines; using System.Runtime.CompilerServices; using System.Threading.Tasks; +using Microsoft.AspNetCore.Server.Kestrel.Internal.System; +using Microsoft.AspNetCore.Server.Kestrel.Internal.System.Buffers; +using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/HttpUtilities.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/HttpUtilities.cs index 8e42f383e7..7262abcca4 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/HttpUtilities.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/HttpUtilities.cs @@ -7,6 +7,7 @@ using System.Runtime.CompilerServices; using System.Text; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Internal.System; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/IThreadPool.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/IThreadPool.cs index 9f9037630f..819da220bc 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/IThreadPool.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/IThreadPool.cs @@ -2,9 +2,9 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.IO.Pipelines; using System.Threading; using System.Threading.Tasks; +using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Microsoft.AspNetCore.Server.Kestrel.Core.csproj b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Microsoft.AspNetCore.Server.Kestrel.Core.csproj index 8c520b639b..a07d94634f 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Microsoft.AspNetCore.Server.Kestrel.Core.csproj +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Microsoft.AspNetCore.Server.Kestrel.Core.csproj @@ -19,10 +19,8 @@ - - - - + + diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/IConnectionContext.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/IConnectionContext.cs index cac404e67e..3cba9448b8 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/IConnectionContext.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/IConnectionContext.cs @@ -2,8 +2,8 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.IO.Pipelines; using System.Threading.Tasks; +using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/IConnectionInformation.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/IConnectionInformation.cs index f0d4da9085..f819a34913 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/IConnectionInformation.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/IConnectionInformation.cs @@ -1,8 +1,8 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System.IO.Pipelines; using System.Net; +using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.csproj b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.csproj index 127f06c668..5bc4008a1b 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.csproj +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.csproj @@ -7,12 +7,14 @@ netstandard1.3 true aspnetcore;kestrel - CS1591;$(NoWarn) + CS1570;CS1571;CS1572;CS1573;CS1574;CS1591;$(NoWarn) false + true - + + diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvConnection.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvConnection.cs index 01aa2b24e1..53c5f48dcc 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvConnection.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvConnection.cs @@ -4,10 +4,10 @@ using System; using System.Diagnostics; using System.IO; -using System.IO.Pipelines; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking; +using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions; using Microsoft.Extensions.Logging; diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvConnectionContext.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvConnectionContext.cs index e20796289d..6627376b7d 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvConnectionContext.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvConnectionContext.cs @@ -1,8 +1,8 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System.IO.Pipelines; using System.Net; +using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions; namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvOutputConsumer.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvOutputConsumer.cs index e96cf35d85..c81cf3f9e9 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvOutputConsumer.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvOutputConsumer.cs @@ -2,8 +2,8 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.IO.Pipelines; using System.Threading.Tasks; +using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking; namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvThread.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvThread.cs index aee08aa862..393aaa6af5 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvThread.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvThread.cs @@ -3,13 +3,13 @@ using System; using System.Collections.Generic; -using System.IO.Pipelines; using System.Runtime.ExceptionServices; using System.Runtime.InteropServices; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking; +using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; using Microsoft.Extensions.Logging; namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvWriteReq.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvWriteReq.cs index 0f5edff121..77b651b2fd 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvWriteReq.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvWriteReq.cs @@ -2,10 +2,10 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.Buffers; using System.Collections.Generic; -using System.IO.Pipelines; using System.Runtime.InteropServices; +using Microsoft.AspNetCore.Server.Kestrel.Internal.System.Buffers; +using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; using Microsoft.Extensions.Logging; namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameParsingOverheadBenchmark.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameParsingOverheadBenchmark.cs index f98d7b7c56..f777f6b370 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameParsingOverheadBenchmark.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameParsingOverheadBenchmark.cs @@ -1,13 +1,13 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System; -using System.IO.Pipelines; using System.Text; using BenchmarkDotNet.Attributes; using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Internal.System; +using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; namespace Microsoft.AspNetCore.Server.Kestrel.Performance { diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameWritingBenchmark.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameWritingBenchmark.cs index c0762e0d82..72973e444a 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameWritingBenchmark.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameWritingBenchmark.cs @@ -2,13 +2,13 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.IO.Pipelines; using System.Threading; using System.Threading.Tasks; using BenchmarkDotNet.Attributes; using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; using Microsoft.AspNetCore.Testing; namespace Microsoft.AspNetCore.Server.Kestrel.Performance diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/KestrelHttpParserBenchmark.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/KestrelHttpParserBenchmark.cs index 3f6961f030..852fadd6d6 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/KestrelHttpParserBenchmark.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/KestrelHttpParserBenchmark.cs @@ -1,10 +1,10 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System; -using System.IO.Pipelines; using BenchmarkDotNet.Attributes; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Internal.System; +using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; namespace Microsoft.AspNetCore.Server.Kestrel.Performance { diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/KnownStringsBenchmark.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/KnownStringsBenchmark.cs index e19777aaab..d4745bba4f 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/KnownStringsBenchmark.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/KnownStringsBenchmark.cs @@ -6,6 +6,7 @@ using System.Text; using BenchmarkDotNet.Attributes; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Internal.System; namespace Microsoft.AspNetCore.Server.Kestrel.Performance { diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Mocks/MockConnectionInformation.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Mocks/MockConnectionInformation.cs index 6429e94220..fd1915cff7 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Mocks/MockConnectionInformation.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Mocks/MockConnectionInformation.cs @@ -1,8 +1,8 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System.IO.Pipelines; using System.Net; +using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions; namespace Microsoft.AspNetCore.Server.Kestrel.Performance diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/PipeThroughputBenchmark.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/PipeThroughputBenchmark.cs index 957a66b19c..152f8af1ef 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/PipeThroughputBenchmark.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/PipeThroughputBenchmark.cs @@ -1,9 +1,9 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System.IO.Pipelines; using System.Threading.Tasks; using BenchmarkDotNet.Attributes; +using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; namespace Microsoft.AspNetCore.Server.Kestrel.Performance { diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsingBenchmark.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsingBenchmark.cs index 3a35b3d808..2222e73e84 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsingBenchmark.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsingBenchmark.cs @@ -1,11 +1,11 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System.IO.Pipelines; using BenchmarkDotNet.Attributes; using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; namespace Microsoft.AspNetCore.Server.Kestrel.Performance { diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/ResponseHeadersWritingBenchmark.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/ResponseHeadersWritingBenchmark.cs index b64789dbdb..75b32c4d0f 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/ResponseHeadersWritingBenchmark.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/ResponseHeadersWritingBenchmark.cs @@ -3,7 +3,6 @@ using System; using System.IO; -using System.IO.Pipelines; using System.Text; using System.Threading; using System.Threading.Tasks; @@ -12,6 +11,7 @@ using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; using Microsoft.AspNetCore.Testing; namespace Microsoft.AspNetCore.Server.Kestrel.Performance diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/AsciiDecoding.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/AsciiDecoding.cs index 8242a6bb43..7d2a812930 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/AsciiDecoding.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/AsciiDecoding.cs @@ -4,6 +4,7 @@ using System; using System.Linq; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Internal.System; using Xunit; namespace Microsoft.AspNetCore.Server.KestrelTests diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameResponseHeadersTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameResponseHeadersTests.cs index aea53a5bec..86f420673b 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameResponseHeadersTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameResponseHeadersTests.cs @@ -4,9 +4,9 @@ using System; using System.Collections.Generic; using System.Globalization; -using System.IO.Pipelines; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; using Microsoft.AspNetCore.Testing; using Microsoft.Extensions.Primitives; using Xunit; diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs index 2f7ac31e61..bae0765e88 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs @@ -5,7 +5,6 @@ using System; using System.Collections; using System.Collections.Generic; using System.IO; -using System.IO.Pipelines; using System.Linq; using System.Net; using System.Text; @@ -18,6 +17,7 @@ using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions; using Microsoft.AspNetCore.Testing; using Microsoft.Extensions.Internal; diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/HttpParserTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/HttpParserTests.cs index d28eb02e07..db1d324ee0 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/HttpParserTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/HttpParserTests.cs @@ -1,16 +1,16 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System; using System.Collections.Generic; -using System.IO.Pipelines; -using System.IO.Pipelines.Testing; using System.Linq; using System.Text; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Internal.System; +using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; +using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.Testing; using Microsoft.AspNetCore.Testing; using Microsoft.Extensions.Logging; using Moq; diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/HttpUtilitiesTest.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/HttpUtilitiesTest.cs index 002ec387c4..37b227bd5c 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/HttpUtilitiesTest.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/HttpUtilitiesTest.cs @@ -5,6 +5,7 @@ using System; using System.Text; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Internal.System; using Xunit; namespace Microsoft.AspNetCore.Server.KestrelTests diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/LibuvOutputConsumerTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/LibuvOutputConsumerTests.cs index 0b9a085180..301897f6a6 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/LibuvOutputConsumerTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/LibuvOutputConsumerTests.cs @@ -3,13 +3,13 @@ using System; using System.Collections.Concurrent; -using System.IO.Pipelines; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv; using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal; +using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; using Microsoft.AspNetCore.Server.KestrelTests.TestHelpers; using Microsoft.AspNetCore.Testing; using Xunit; diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/MultipleLoopTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/MultipleLoopTests.cs index 3a0461d394..66a7b64fa6 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/MultipleLoopTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/MultipleLoopTests.cs @@ -2,13 +2,13 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.IO.Pipelines; using System.Net; using System.Net.Sockets; using System.Runtime.InteropServices; using System.Threading; using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal; using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking; +using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; using Microsoft.AspNetCore.Server.KestrelTests.TestHelpers; using Microsoft.AspNetCore.Testing; using Xunit; diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/NetworkingTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/NetworkingTests.cs index 9a1bea061e..11225a2e61 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/NetworkingTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/NetworkingTests.cs @@ -2,13 +2,13 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.IO.Pipelines; using System.Net; using System.Net.Sockets; using System.Runtime.InteropServices; using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal; using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking; +using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; using Microsoft.AspNetCore.Testing; using Xunit; diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/PathNormalizerTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/PathNormalizerTests.cs index 25d69b39bf..644580a10d 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/PathNormalizerTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/PathNormalizerTests.cs @@ -4,6 +4,7 @@ using System; using System.Text; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Internal.System; using Xunit; namespace Microsoft.AspNetCore.Server.KestrelTests diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/PipeOptionsTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/PipeOptionsTests.cs index ff0ccdd5f0..a542711393 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/PipeOptionsTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/PipeOptionsTests.cs @@ -1,9 +1,9 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System.IO.Pipelines; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; using Microsoft.AspNetCore.Testing; using Moq; using Xunit; diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/PipelineExtensionTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/PipelineExtensionTests.cs index 86137019fd..614e81bb39 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/PipelineExtensionTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/PipelineExtensionTests.cs @@ -2,10 +2,11 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.IO.Pipelines; using System.Text; using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Internal.System; +using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; using Xunit; namespace Microsoft.AspNetCore.Server.KestrelTests diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/StreamSocketOutputTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/StreamSocketOutputTests.cs index 86814e8ba5..bc481be73f 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/StreamSocketOutputTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/StreamSocketOutputTests.cs @@ -3,8 +3,8 @@ using System; using System.IO; -using System.IO.Pipelines; using Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal; +using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; using Xunit; namespace Microsoft.AspNetCore.Server.KestrelTests diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/AssertExtensions.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/AssertExtensions.cs index cb3fc36a3c..d6ddbee945 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/AssertExtensions.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/AssertExtensions.cs @@ -1,7 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System; +using Microsoft.AspNetCore.Server.Kestrel.Internal.System; using Xunit.Sdk; namespace Xunit diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockConnectionHandler.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockConnectionHandler.cs index a7747457ac..4b784346ae 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockConnectionHandler.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockConnectionHandler.cs @@ -2,8 +2,8 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.IO.Pipelines; using System.Threading.Tasks; +using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions; using Xunit; diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestInput.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/TestInput.cs index 9bf6c5cc6d..f5707b962c 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/TestInput.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/TestInput.cs @@ -2,11 +2,11 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.IO.Pipelines; using System.Text; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions; using Microsoft.AspNetCore.Testing; using Microsoft.Extensions.Internal; diff --git a/test/shared/MockSocketOutput.cs b/test/shared/MockSocketOutput.cs index 69dd468c23..f213514434 100644 --- a/test/shared/MockSocketOutput.cs +++ b/test/shared/MockSocketOutput.cs @@ -2,10 +2,10 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.IO.Pipelines; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; using Microsoft.Extensions.Internal; namespace Microsoft.AspNetCore.Testing diff --git a/tools/CodeGenerator/KnownHeaders.cs b/tools/CodeGenerator/KnownHeaders.cs index e5feb937f2..19f7ef5796 100644 --- a/tools/CodeGenerator/KnownHeaders.cs +++ b/tools/CodeGenerator/KnownHeaders.cs @@ -291,8 +291,8 @@ namespace CodeGenerator using System; using System.Collections.Generic; -using System.IO.Pipelines; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; using Microsoft.Extensions.Primitives; using Microsoft.Net.Http.Headers; From 3b016e683237b676e1cf75883834b728ecb20a11 Mon Sep 17 00:00:00 2001 From: Pranav K Date: Wed, 5 Apr 2017 17:44:16 -0700 Subject: [PATCH 1186/1662] Use 4.3.0 version of System.Threading.Tasks.Extensions --- .../Microsoft.AspNetCore.Server.Kestrel.Core.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Microsoft.AspNetCore.Server.Kestrel.Core.csproj b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Microsoft.AspNetCore.Server.Kestrel.Core.csproj index a07d94634f..20102b9aba 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Microsoft.AspNetCore.Server.Kestrel.Core.csproj +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Microsoft.AspNetCore.Server.Kestrel.Core.csproj @@ -20,7 +20,7 @@ - + From a594d0eeb82f5baa36b7f792aa2922982ff5e2e4 Mon Sep 17 00:00:00 2001 From: Mike Harder Date: Thu, 6 Apr 2017 15:49:23 -0700 Subject: [PATCH 1187/1662] Workaround for "Explicit RID still required for .NET Framework test projects" - Addresses #1617 --- ...crosoft.AspNetCore.Server.Kestrel.FunctionalTests.csproj | 6 ++++++ .../Microsoft.AspNetCore.Server.KestrelTests.csproj | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests.csproj b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests.csproj index cbef1e8054..21a47f7c0d 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests.csproj +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests.csproj @@ -8,6 +8,12 @@ x64 true true + + + exe diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/Microsoft.AspNetCore.Server.KestrelTests.csproj b/test/Microsoft.AspNetCore.Server.KestrelTests/Microsoft.AspNetCore.Server.KestrelTests.csproj index 7fb00ec5b2..748a4a79f9 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/Microsoft.AspNetCore.Server.KestrelTests.csproj +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/Microsoft.AspNetCore.Server.KestrelTests.csproj @@ -7,6 +7,12 @@ netcoreapp2.0 x64 true + + + exe From 26bd01337d60f07058a5352e50deb1609074354e Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Thu, 6 Apr 2017 18:49:52 -0700 Subject: [PATCH 1188/1662] Re-write UvStreamHandleTests.ReadStopIsIdempotent without Moq. --- .../UvStreamHandleTests.cs | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/UvStreamHandleTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/UvStreamHandleTests.cs index d08e8a39f3..0754287832 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/UvStreamHandleTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/UvStreamHandleTests.cs @@ -5,7 +5,6 @@ using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal; using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking; using Microsoft.AspNetCore.Server.KestrelTests.TestHelpers; using Microsoft.AspNetCore.Testing; -using Moq; using Xunit; namespace Microsoft.AspNetCore.Server.KestrelTests @@ -17,15 +16,16 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { var libuvTrace = new LibuvTrace(new TestApplicationErrorLogger()); - var mockUvLoopHandle = new Mock(libuvTrace).Object; - mockUvLoopHandle.Init(new MockLibuv()); + using (var uvLoopHandle = new UvLoopHandle(libuvTrace)) + using (var uvTcpHandle = new UvTcpHandle(libuvTrace)) + { + uvLoopHandle.Init(new MockLibuv()); + uvTcpHandle.Init(uvLoopHandle, null); - // Need to mock UvTcpHandle instead of UvStreamHandle, since the latter lacks an Init() method - var mockUvStreamHandle = new Mock(libuvTrace).Object; - mockUvStreamHandle.Init(mockUvLoopHandle, null); - - mockUvStreamHandle.ReadStop(); - mockUvStreamHandle.ReadStop(); + UvStreamHandle uvStreamHandle = uvTcpHandle; + uvStreamHandle.ReadStop(); + uvStreamHandle.ReadStop(); + } } } -} +} \ No newline at end of file From f253dbc0c074337ea7cb21c6809b88ab9be991bd Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Thu, 6 Apr 2017 19:09:40 -0700 Subject: [PATCH 1189/1662] Split transport-specific tests and general tests into distinct test projects (#1588). * Rename EngineTests to LibuvTransportTests. * Move libuv-specific tests into their own test project. * Move LibuvOutputConsumerTests.AllocCommitCanBeCalledAfterConnectionClose to new OutputProducerTests class and rename it to WritesNoopAfterConnectionCloses. * Remove TransportContext from TestServiceContext. * Make KestrelTests depend on Kestrel.Core only. * Rename Microsoft.AspNetCore.Server.Kestrel.KestrelTests to Microsoft.AspNetCore.Server.Kestrel.Core.Tests. * Add Microsoft.AspNetCore.Server.Kestrel.Tests test project for WebHostBuilderKestrelExtensionsTests. * Increase socket receive timeout in MaxRequestBufferSizeTests to mitigate flakiness. * Anything using TestServer should be a functional test. * Move out of LibuvTransportTests tests that are not specific to LibuvTransport. - Move to RequestTests: - Http11 (rename to Http11KeptAliveByDefault) - Http10ContentLength (rename to Http10NotKeptAliveByDefault) - Http10KeepAlive - Http10KeepAliveNotUsedIfResponseContentLengthNotSet (rename to Http10KeepAliveNotHonoredIfResponseContentLengthNotSet) - Http10ContentLengthKeepAlive (rename to Http10KeepAliveHonoredIfResponseContentLengthSet) - Expect100ContinueForBody (rename to Expect100ContinueHonored) - ZeroContentLengthAssumedOnNonKeepAliveRequestsWithoutContentLengthOrTransferEncodingHeader - ConnectionClosesWhenFinReceivedBeforeRequestCompletes (test was actually not marked as Theory, and was incorrect) - RequestsCanBeAbortedMidRead - RequestHeadersAreResetOnEachRequest - UpgradeRequestIsNotKeptAliveOrChunked - HeadersAndStreamsAreReused (rename to HeadersAndStreamsAreReusedAcrossRequests) - Move to ResponseTests: - Http10RequestReceivesHttp11Response (rename to Http11ResponseSentToHttp10Request) - ZeroContentLengthSetAutomaticallyAfterNoWrites - ZeroContentLengthSetAutomaticallyForNonKeepAliveRequests - ZeroContentLengthNotSetAutomaticallyForHeadRequests - ZeroContentLengthNotSetAutomaticallyForCertainStatusCodes - ConnectionClosedAfter101Response - ThrowingResultsIn500Response - ThrowingAfterWritingKillsConnection - ThrowingAfterPartialWriteKillsConnection - ThrowingInOnStartingResultsInFailedWritesAnd500Response - ThrowingInOnCompletedIsLoggedAndClosesConnection - FailedWritesResultInAbortedRequest - NoErrorsLoggedWhenServerEndsConnectionBeforeClient - NoResponseSentWhenConnectionIsClosedByServerBeforeClientFinishesSendingRequest - ResponseHeadersAreResetOnEachRequest - OnStartingCallbacksAreCalledInLastInFirstOutOrder - OnCompletedCallbacksAreCalledInLastInFirstOutOrder - Remove: - RePathEscapeTests (theory data to HttpParsingData) - ReDisconnectingClient (what was that testing?) --- KestrelHttpServer.sln | 37 +- .../Properties/AssemblyInfo.cs | 3 +- .../AsciiDecoding.cs | 2 +- .../ChunkWriterTests.cs | 2 +- .../CreateIPEndpointTests.cs | 2 +- .../DateHeaderValueManagerTests.cs | 2 +- .../FrameHeadersTests.cs | 2 +- .../FrameRequestHeadersTests.cs | 2 +- .../FrameRequestStreamTests.cs | 2 +- .../FrameResponseHeadersTests.cs | 2 +- .../FrameResponseStreamTests.cs | 4 +- .../FrameTests.cs | 2 +- .../HttpParserTests.cs | 2 +- .../HttpUtilitiesTest.cs | 2 +- .../KestrelEventSourceTests.cs | 2 +- .../KestrelServerLimitsTests.cs | 2 +- .../KestrelServerOptionsTests.cs | 2 +- .../KestrelServerTests.cs | 2 +- .../LoggingThreadPoolTests.cs | 2 +- .../MessageBodyTests.cs | 2 +- ...pNetCore.Server.Kestrel.Core.Tests.csproj} | 4 +- .../OutputProducerTests.cs | 61 + .../PathNormalizerTests.cs | 2 +- .../PipeOptionsTests.cs | 4 +- .../PipelineExtensionTests.cs | 2 +- .../ServerAddressTests.cs | 2 +- .../StreamSocketOutputTests.cs | 2 +- .../TestHelpers/AssertExtensions.cs | 0 .../TestHelpers/MockFrameControl.cs | 2 +- .../TestInput.cs | 2 +- .../xunit.runner.json | 0 .../ChunkedRequestTests.cs | 2 +- .../ChunkedResponseTests.cs | 2 +- .../ConnectionAdapterTests.cs | 2 +- .../DefaultHeaderTests.cs | 2 +- .../HttpsConnectionAdapterTests.cs | 2 +- .../MaxRequestBufferSizeTests.cs | 2 +- .../RequestTargetProcessingTests.cs | 2 +- .../RequestTests.cs | 564 +++++++ .../ResponseTests.cs | 757 +++++++++ .../TestServer.cs | 19 +- ...pNetCore.Server.Kestrel.Performance.csproj | 1 - ...oft.AspNetCore.Server.Kestrel.Tests.csproj | 31 + .../WebHostBuilderKestrelExtensionsTests.cs | 2 +- .../xunit.runner.json | 5 + .../EngineTests.cs | 1431 ----------------- .../ConnectionTests.cs | 16 +- .../LibuvOutputConsumerTests.cs | 66 +- .../LibuvTransportFactoryTests.cs | 3 +- .../LibuvTransportOptionsTests.cs | 3 +- .../LibuvTransportTests.cs | 80 + .../ListenerPrimaryTests.cs | 61 +- ...erver.Kestrel.Transport.Libuv.Tests.csproj | 35 + .../MultipleLoopTests.cs | 6 +- .../NetworkingTests.cs | 2 +- .../TestHelpers}/MockConnection.cs | 3 +- .../TestHelpers/MockConnectionHandler.cs | 2 +- .../TestHelpers/MockLibuv.cs | 2 +- .../TestHelpers/MockSocket.cs | 2 +- .../TestHelpers/TestConstants.cs | 2 +- .../TestHelpers/TestLibuvTransportContext.cs | 26 + .../UvStreamHandleTests.cs | 4 +- .../UvTimerHandleTests.cs | 2 +- .../xunit.runner.json | 6 + test/shared/HttpParsingData.cs | 2 + test/shared/TestApplicationErrorLogger.cs | 1 - test/shared/TestServiceContext.cs | 16 - 67 files changed, 1727 insertions(+), 1596 deletions(-) rename test/{Microsoft.AspNetCore.Server.KestrelTests => Microsoft.AspNetCore.Server.Kestrel.Core.Tests}/AsciiDecoding.cs (97%) rename test/{Microsoft.AspNetCore.Server.KestrelTests => Microsoft.AspNetCore.Server.Kestrel.Core.Tests}/ChunkWriterTests.cs (95%) rename test/{Microsoft.AspNetCore.Server.KestrelTests => Microsoft.AspNetCore.Server.Kestrel.Core.Tests}/CreateIPEndpointTests.cs (94%) rename test/{Microsoft.AspNetCore.Server.KestrelTests => Microsoft.AspNetCore.Server.Kestrel.Core.Tests}/DateHeaderValueManagerTests.cs (98%) rename test/{Microsoft.AspNetCore.Server.KestrelTests => Microsoft.AspNetCore.Server.Kestrel.Core.Tests}/FrameHeadersTests.cs (99%) rename test/{Microsoft.AspNetCore.Server.KestrelTests => Microsoft.AspNetCore.Server.Kestrel.Core.Tests}/FrameRequestHeadersTests.cs (99%) rename test/{Microsoft.AspNetCore.Server.KestrelTests => Microsoft.AspNetCore.Server.Kestrel.Core.Tests}/FrameRequestStreamTests.cs (99%) rename test/{Microsoft.AspNetCore.Server.KestrelTests => Microsoft.AspNetCore.Server.Kestrel.Core.Tests}/FrameResponseHeadersTests.cs (99%) rename test/{Microsoft.AspNetCore.Server.KestrelTests => Microsoft.AspNetCore.Server.Kestrel.Core.Tests}/FrameResponseStreamTests.cs (96%) rename test/{Microsoft.AspNetCore.Server.KestrelTests => Microsoft.AspNetCore.Server.Kestrel.Core.Tests}/FrameTests.cs (99%) rename test/{Microsoft.AspNetCore.Server.KestrelTests => Microsoft.AspNetCore.Server.Kestrel.Core.Tests}/HttpParserTests.cs (99%) rename test/{Microsoft.AspNetCore.Server.KestrelTests => Microsoft.AspNetCore.Server.Kestrel.Core.Tests}/HttpUtilitiesTest.cs (99%) rename test/{Microsoft.AspNetCore.Server.KestrelTests => Microsoft.AspNetCore.Server.Kestrel.Core.Tests}/KestrelEventSourceTests.cs (94%) rename test/{Microsoft.AspNetCore.Server.KestrelTests => Microsoft.AspNetCore.Server.Kestrel.Core.Tests}/KestrelServerLimitsTests.cs (99%) rename test/{Microsoft.AspNetCore.Server.KestrelTests => Microsoft.AspNetCore.Server.Kestrel.Core.Tests}/KestrelServerOptionsTests.cs (92%) rename test/{Microsoft.AspNetCore.Server.KestrelTests => Microsoft.AspNetCore.Server.Kestrel.Core.Tests}/KestrelServerTests.cs (99%) rename test/{Microsoft.AspNetCore.Server.KestrelTests => Microsoft.AspNetCore.Server.Kestrel.Core.Tests}/LoggingThreadPoolTests.cs (96%) rename test/{Microsoft.AspNetCore.Server.KestrelTests => Microsoft.AspNetCore.Server.Kestrel.Core.Tests}/MessageBodyTests.cs (99%) rename test/{Microsoft.AspNetCore.Server.KestrelTests/Microsoft.AspNetCore.Server.KestrelTests.csproj => Microsoft.AspNetCore.Server.Kestrel.Core.Tests/Microsoft.AspNetCore.Server.Kestrel.Core.Tests.csproj} (88%) create mode 100644 test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/OutputProducerTests.cs rename test/{Microsoft.AspNetCore.Server.KestrelTests => Microsoft.AspNetCore.Server.Kestrel.Core.Tests}/PathNormalizerTests.cs (97%) rename test/{Microsoft.AspNetCore.Server.KestrelTests => Microsoft.AspNetCore.Server.Kestrel.Core.Tests}/PipeOptionsTests.cs (94%) rename test/{Microsoft.AspNetCore.Server.KestrelTests => Microsoft.AspNetCore.Server.Kestrel.Core.Tests}/PipelineExtensionTests.cs (99%) rename test/{Microsoft.AspNetCore.Server.KestrelTests => Microsoft.AspNetCore.Server.Kestrel.Core.Tests}/ServerAddressTests.cs (98%) rename test/{Microsoft.AspNetCore.Server.KestrelTests => Microsoft.AspNetCore.Server.Kestrel.Core.Tests}/StreamSocketOutputTests.cs (98%) rename test/{Microsoft.AspNetCore.Server.KestrelTests => Microsoft.AspNetCore.Server.Kestrel.Core.Tests}/TestHelpers/AssertExtensions.cs (100%) rename test/{Microsoft.AspNetCore.Server.KestrelTests => Microsoft.AspNetCore.Server.Kestrel.Core.Tests}/TestHelpers/MockFrameControl.cs (92%) rename test/{Microsoft.AspNetCore.Server.KestrelTests => Microsoft.AspNetCore.Server.Kestrel.Core.Tests}/TestInput.cs (97%) rename test/{Microsoft.AspNetCore.Server.KestrelTests => Microsoft.AspNetCore.Server.Kestrel.Core.Tests}/xunit.runner.json (100%) rename test/{Microsoft.AspNetCore.Server.KestrelTests => Microsoft.AspNetCore.Server.Kestrel.FunctionalTests}/ChunkedRequestTests.cs (99%) rename test/{Microsoft.AspNetCore.Server.KestrelTests => Microsoft.AspNetCore.Server.Kestrel.FunctionalTests}/ChunkedResponseTests.cs (99%) rename test/{Microsoft.AspNetCore.Server.KestrelTests => Microsoft.AspNetCore.Server.Kestrel.FunctionalTests}/ConnectionAdapterTests.cs (99%) rename test/{Microsoft.AspNetCore.Server.KestrelTests => Microsoft.AspNetCore.Server.Kestrel.FunctionalTests}/DefaultHeaderTests.cs (96%) rename test/{Microsoft.AspNetCore.Server.KestrelTests => Microsoft.AspNetCore.Server.Kestrel.FunctionalTests}/HttpsConnectionAdapterTests.cs (99%) rename test/{Microsoft.AspNetCore.Server.KestrelTests => Microsoft.AspNetCore.Server.Kestrel.FunctionalTests}/RequestTargetProcessingTests.cs (98%) rename test/{shared => Microsoft.AspNetCore.Server.Kestrel.FunctionalTests}/TestServer.cs (73%) create mode 100644 test/Microsoft.AspNetCore.Server.Kestrel.Tests/Microsoft.AspNetCore.Server.Kestrel.Tests.csproj rename test/{Microsoft.AspNetCore.Server.KestrelTests => Microsoft.AspNetCore.Server.Kestrel.Tests}/WebHostBuilderKestrelExtensionsTests.cs (96%) create mode 100644 test/Microsoft.AspNetCore.Server.Kestrel.Tests/xunit.runner.json delete mode 100644 test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs rename test/{Microsoft.AspNetCore.Server.KestrelTests => Microsoft.AspNetCore.Server.Transport.Libuv.Tests}/ConnectionTests.cs (76%) rename test/{Microsoft.AspNetCore.Server.KestrelTests => Microsoft.AspNetCore.Server.Transport.Libuv.Tests}/LibuvOutputConsumerTests.cs (90%) rename test/{Microsoft.AspNetCore.Server.KestrelTests => Microsoft.AspNetCore.Server.Transport.Libuv.Tests}/LibuvTransportFactoryTests.cs (92%) rename test/{Microsoft.AspNetCore.Server.KestrelTests => Microsoft.AspNetCore.Server.Transport.Libuv.Tests}/LibuvTransportOptionsTests.cs (87%) create mode 100644 test/Microsoft.AspNetCore.Server.Transport.Libuv.Tests/LibuvTransportTests.cs rename test/{Microsoft.AspNetCore.Server.KestrelTests => Microsoft.AspNetCore.Server.Transport.Libuv.Tests}/ListenerPrimaryTests.cs (80%) create mode 100644 test/Microsoft.AspNetCore.Server.Transport.Libuv.Tests/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests.csproj rename test/{Microsoft.AspNetCore.Server.KestrelTests => Microsoft.AspNetCore.Server.Transport.Libuv.Tests}/MultipleLoopTests.cs (98%) rename test/{Microsoft.AspNetCore.Server.KestrelTests => Microsoft.AspNetCore.Server.Transport.Libuv.Tests}/NetworkingTests.cs (98%) rename test/{shared => Microsoft.AspNetCore.Server.Transport.Libuv.Tests/TestHelpers}/MockConnection.cs (92%) rename test/{Microsoft.AspNetCore.Server.KestrelTests => Microsoft.AspNetCore.Server.Transport.Libuv.Tests}/TestHelpers/MockConnectionHandler.cs (96%) rename test/{Microsoft.AspNetCore.Server.KestrelTests => Microsoft.AspNetCore.Server.Transport.Libuv.Tests}/TestHelpers/MockLibuv.cs (98%) rename test/{Microsoft.AspNetCore.Server.KestrelTests => Microsoft.AspNetCore.Server.Transport.Libuv.Tests}/TestHelpers/MockSocket.cs (89%) rename test/{Microsoft.AspNetCore.Server.KestrelTests => Microsoft.AspNetCore.Server.Transport.Libuv.Tests}/TestHelpers/TestConstants.cs (76%) create mode 100644 test/Microsoft.AspNetCore.Server.Transport.Libuv.Tests/TestHelpers/TestLibuvTransportContext.cs rename test/{Microsoft.AspNetCore.Server.KestrelTests => Microsoft.AspNetCore.Server.Transport.Libuv.Tests}/UvStreamHandleTests.cs (87%) rename test/{Microsoft.AspNetCore.Server.KestrelTests => Microsoft.AspNetCore.Server.Transport.Libuv.Tests}/UvTimerHandleTests.cs (96%) create mode 100644 test/Microsoft.AspNetCore.Server.Transport.Libuv.Tests/xunit.runner.json diff --git a/KestrelHttpServer.sln b/KestrelHttpServer.sln index 5e243d4c7c..5119c68fa0 100644 --- a/KestrelHttpServer.sln +++ b/KestrelHttpServer.sln @@ -1,6 +1,6 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 15 -VisualStudioVersion = 15.0.26327.1 +VisualStudioVersion = 15.0.26405.0 MinimumVisualStudioVersion = 10.0.40219.1 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{7972A5D6-3385-4127-9277-428506DD44FF}" ProjectSection(SolutionItems) = preProject @@ -24,11 +24,9 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "shared", "shared", "{0EF2AC test\shared\HttpParsingData.cs = test\shared\HttpParsingData.cs test\shared\KestrelTestLoggerFactory.cs = test\shared\KestrelTestLoggerFactory.cs test\shared\LifetimeNotImplemented.cs = test\shared\LifetimeNotImplemented.cs - test\shared\MockConnection.cs = test\shared\MockConnection.cs test\shared\MockFrameControl.cs = test\shared\MockFrameControl.cs test\shared\MockSocketOutput.cs = test\shared\MockSocketOutput.cs test\shared\MockSystemClock.cs = test\shared\MockSystemClock.cs - test\shared\SocketInputExtensions.cs = test\shared\SocketInputExtensions.cs test\shared\StringExtensions.cs = test\shared\StringExtensions.cs test\shared\TestApp.cs = test\shared\TestApp.cs test\shared\TestApplicationErrorLogger.cs = test\shared\TestApplicationErrorLogger.cs @@ -36,13 +34,12 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "shared", "shared", "{0EF2AC test\shared\TestFrame.cs = test\shared\TestFrame.cs test\shared\TestKestrelTrace.cs = test\shared\TestKestrelTrace.cs test\shared\TestResources.cs = test\shared\TestResources.cs - test\shared\TestServer.cs = test\shared\TestServer.cs test\shared\TestServiceContext.cs = test\shared\TestServiceContext.cs EndProjectSection EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Server.Kestrel.Core", "src\Microsoft.AspNetCore.Server.Kestrel.Core\Microsoft.AspNetCore.Server.Kestrel.Core.csproj", "{F510611A-3BEE-4B88-A613-5F4A74ED82A1}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Server.KestrelTests", "test\Microsoft.AspNetCore.Server.KestrelTests\Microsoft.AspNetCore.Server.KestrelTests.csproj", "{37F3BFB2-6454-49E5-9D7F-581BF755CCFE}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Server.Kestrel.Core.Tests", "test\Microsoft.AspNetCore.Server.Kestrel.Core.Tests\Microsoft.AspNetCore.Server.Kestrel.Core.Tests.csproj", "{37F3BFB2-6454-49E5-9D7F-581BF755CCFE}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SampleApp", "samples\SampleApp\SampleApp.csproj", "{2C3CB3DC-EEBF-4F52-9E1C-4F2F972E76C3}" EndProject @@ -67,6 +64,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Server EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions", "src\Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions\Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.csproj", "{2E9CB89D-EC8F-4DD9-A72B-08D5BABF752D}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests", "test\Microsoft.AspNetCore.Server.Transport.Libuv.Tests\Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests.csproj", "{D95A7EC3-48AC-4D03-B2E2-0DA3E13BD3A4}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Server.Kestrel.Tests", "test\Microsoft.AspNetCore.Server.Kestrel.Tests\Microsoft.AspNetCore.Server.Kestrel.Tests.csproj", "{4F1C30F8-CCAA-48D7-9DF6-2A84021F5BCC}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -209,6 +210,30 @@ Global {2E9CB89D-EC8F-4DD9-A72B-08D5BABF752D}.Release|x64.Build.0 = Release|Any CPU {2E9CB89D-EC8F-4DD9-A72B-08D5BABF752D}.Release|x86.ActiveCfg = Release|Any CPU {2E9CB89D-EC8F-4DD9-A72B-08D5BABF752D}.Release|x86.Build.0 = Release|Any CPU + {D95A7EC3-48AC-4D03-B2E2-0DA3E13BD3A4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D95A7EC3-48AC-4D03-B2E2-0DA3E13BD3A4}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D95A7EC3-48AC-4D03-B2E2-0DA3E13BD3A4}.Debug|x64.ActiveCfg = Debug|Any CPU + {D95A7EC3-48AC-4D03-B2E2-0DA3E13BD3A4}.Debug|x64.Build.0 = Debug|Any CPU + {D95A7EC3-48AC-4D03-B2E2-0DA3E13BD3A4}.Debug|x86.ActiveCfg = Debug|Any CPU + {D95A7EC3-48AC-4D03-B2E2-0DA3E13BD3A4}.Debug|x86.Build.0 = Debug|Any CPU + {D95A7EC3-48AC-4D03-B2E2-0DA3E13BD3A4}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D95A7EC3-48AC-4D03-B2E2-0DA3E13BD3A4}.Release|Any CPU.Build.0 = Release|Any CPU + {D95A7EC3-48AC-4D03-B2E2-0DA3E13BD3A4}.Release|x64.ActiveCfg = Release|Any CPU + {D95A7EC3-48AC-4D03-B2E2-0DA3E13BD3A4}.Release|x64.Build.0 = Release|Any CPU + {D95A7EC3-48AC-4D03-B2E2-0DA3E13BD3A4}.Release|x86.ActiveCfg = Release|Any CPU + {D95A7EC3-48AC-4D03-B2E2-0DA3E13BD3A4}.Release|x86.Build.0 = Release|Any CPU + {4F1C30F8-CCAA-48D7-9DF6-2A84021F5BCC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {4F1C30F8-CCAA-48D7-9DF6-2A84021F5BCC}.Debug|Any CPU.Build.0 = Debug|Any CPU + {4F1C30F8-CCAA-48D7-9DF6-2A84021F5BCC}.Debug|x64.ActiveCfg = Debug|Any CPU + {4F1C30F8-CCAA-48D7-9DF6-2A84021F5BCC}.Debug|x64.Build.0 = Debug|Any CPU + {4F1C30F8-CCAA-48D7-9DF6-2A84021F5BCC}.Debug|x86.ActiveCfg = Debug|Any CPU + {4F1C30F8-CCAA-48D7-9DF6-2A84021F5BCC}.Debug|x86.Build.0 = Debug|Any CPU + {4F1C30F8-CCAA-48D7-9DF6-2A84021F5BCC}.Release|Any CPU.ActiveCfg = Release|Any CPU + {4F1C30F8-CCAA-48D7-9DF6-2A84021F5BCC}.Release|Any CPU.Build.0 = Release|Any CPU + {4F1C30F8-CCAA-48D7-9DF6-2A84021F5BCC}.Release|x64.ActiveCfg = Release|Any CPU + {4F1C30F8-CCAA-48D7-9DF6-2A84021F5BCC}.Release|x64.Build.0 = Release|Any CPU + {4F1C30F8-CCAA-48D7-9DF6-2A84021F5BCC}.Release|x86.ActiveCfg = Release|Any CPU + {4F1C30F8-CCAA-48D7-9DF6-2A84021F5BCC}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -227,5 +252,7 @@ Global {A76B8C8C-0DC5-4DD3-9B1F-02E51A0915F4} = {2D5D5227-4DBD-499A-96B1-76A36B03B750} {56139957-5C29-4E7D-89BD-7D20598B4EAF} = {2D5D5227-4DBD-499A-96B1-76A36B03B750} {2E9CB89D-EC8F-4DD9-A72B-08D5BABF752D} = {2D5D5227-4DBD-499A-96B1-76A36B03B750} + {D95A7EC3-48AC-4D03-B2E2-0DA3E13BD3A4} = {D3273454-EA07-41D2-BF0B-FCC3675C2483} + {4F1C30F8-CCAA-48D7-9DF6-2A84021F5BCC} = {D3273454-EA07-41D2-BF0B-FCC3675C2483} EndGlobalSection EndGlobal diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Properties/AssemblyInfo.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Properties/AssemblyInfo.cs index 8d850b7d81..c93c4396ee 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Properties/AssemblyInfo.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Properties/AssemblyInfo.cs @@ -4,5 +4,6 @@ using System.Runtime.CompilerServices; [assembly: InternalsVisibleTo("Microsoft.AspNetCore.Server.Kestrel.FunctionalTests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")] -[assembly: InternalsVisibleTo("Microsoft.AspNetCore.Server.KestrelTests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")] +[assembly: InternalsVisibleTo("Microsoft.AspNetCore.Server.Kestrel.Core.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")] [assembly: InternalsVisibleTo("Microsoft.AspNetCore.Server.Kestrel.Performance, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")] +[assembly: InternalsVisibleTo("Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")] diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/AsciiDecoding.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/AsciiDecoding.cs similarity index 97% rename from test/Microsoft.AspNetCore.Server.KestrelTests/AsciiDecoding.cs rename to test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/AsciiDecoding.cs index 7d2a812930..63ed4d4b93 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/AsciiDecoding.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/AsciiDecoding.cs @@ -7,7 +7,7 @@ using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Internal.System; using Xunit; -namespace Microsoft.AspNetCore.Server.KestrelTests +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests { public class AsciiDecodingTests { diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkWriterTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/ChunkWriterTests.cs similarity index 95% rename from test/Microsoft.AspNetCore.Server.KestrelTests/ChunkWriterTests.cs rename to test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/ChunkWriterTests.cs index d7a7f35770..722c0281ab 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkWriterTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/ChunkWriterTests.cs @@ -6,7 +6,7 @@ using System.Text; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; using Xunit; -namespace Microsoft.AspNetCore.Server.KestrelTests +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests { public class ChunkWriterTests { diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/CreateIPEndpointTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/CreateIPEndpointTests.cs similarity index 94% rename from test/Microsoft.AspNetCore.Server.KestrelTests/CreateIPEndpointTests.cs rename to test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/CreateIPEndpointTests.cs index e8a3cdfd2c..bf120febd4 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/CreateIPEndpointTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/CreateIPEndpointTests.cs @@ -5,7 +5,7 @@ using System.Net; using Microsoft.AspNetCore.Server.Kestrel.Core; using Xunit; -namespace Microsoft.AspNetCore.Server.KestrelTests +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests { public class CreateIPEndpointTests { diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/DateHeaderValueManagerTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/DateHeaderValueManagerTests.cs similarity index 98% rename from test/Microsoft.AspNetCore.Server.KestrelTests/DateHeaderValueManagerTests.cs rename to test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/DateHeaderValueManagerTests.cs index 810814219d..875e0f5d73 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/DateHeaderValueManagerTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/DateHeaderValueManagerTests.cs @@ -7,7 +7,7 @@ using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; using Microsoft.AspNetCore.Testing; using Xunit; -namespace Microsoft.AspNetCore.Server.KestrelTests +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests { public class DateHeaderValueManagerTests { diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameHeadersTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameHeadersTests.cs similarity index 99% rename from test/Microsoft.AspNetCore.Server.KestrelTests/FrameHeadersTests.cs rename to test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameHeadersTests.cs index 06a0b4cc15..65774c6022 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameHeadersTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameHeadersTests.cs @@ -8,7 +8,7 @@ using Microsoft.Extensions.Primitives; using Microsoft.Net.Http.Headers; using Xunit; -namespace Microsoft.AspNetCore.Server.KestrelTests +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests { public class FrameHeadersTests { diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameRequestHeadersTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameRequestHeadersTests.cs similarity index 99% rename from test/Microsoft.AspNetCore.Server.KestrelTests/FrameRequestHeadersTests.cs rename to test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameRequestHeadersTests.cs index cc8baef3c6..182ffbadeb 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameRequestHeadersTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameRequestHeadersTests.cs @@ -10,7 +10,7 @@ using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; using Microsoft.Extensions.Primitives; using Xunit; -namespace Microsoft.AspNetCore.Server.KestrelTests +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests { public class FrameRequestHeadersTests { diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameRequestStreamTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameRequestStreamTests.cs similarity index 99% rename from test/Microsoft.AspNetCore.Server.KestrelTests/FrameRequestStreamTests.cs rename to test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameRequestStreamTests.cs index 62d6a41ffd..9f723aa903 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameRequestStreamTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameRequestStreamTests.cs @@ -8,7 +8,7 @@ using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; using Moq; using Xunit; -namespace Microsoft.AspNetCore.Server.KestrelTests +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests { public class FrameRequestStreamTests { diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameResponseHeadersTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameResponseHeadersTests.cs similarity index 99% rename from test/Microsoft.AspNetCore.Server.KestrelTests/FrameResponseHeadersTests.cs rename to test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameResponseHeadersTests.cs index 86f420673b..7ca2c6eed7 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameResponseHeadersTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameResponseHeadersTests.cs @@ -11,7 +11,7 @@ using Microsoft.AspNetCore.Testing; using Microsoft.Extensions.Primitives; using Xunit; -namespace Microsoft.AspNetCore.Server.KestrelTests +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests { public class FrameResponseHeadersTests { diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameResponseStreamTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameResponseStreamTests.cs similarity index 96% rename from test/Microsoft.AspNetCore.Server.KestrelTests/FrameResponseStreamTests.cs rename to test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameResponseStreamTests.cs index 289125fbfc..c6a3ec8a4d 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameResponseStreamTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameResponseStreamTests.cs @@ -5,10 +5,10 @@ using System; using System.IO; using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; -using Microsoft.AspNetCore.Server.KestrelTests.TestHelpers; +using Microsoft.AspNetCore.Server.Kestrel.Core.Tests.TestHelpers; using Xunit; -namespace Microsoft.AspNetCore.Server.KestrelTests +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests { public class FrameResponseStreamTests { diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameTests.cs similarity index 99% rename from test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs rename to test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameTests.cs index bae0765e88..b5c0b1546f 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameTests.cs @@ -26,7 +26,7 @@ using Microsoft.Extensions.Primitives; using Moq; using Xunit; -namespace Microsoft.AspNetCore.Server.KestrelTests +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests { public class FrameTests : IDisposable { diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/HttpParserTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/HttpParserTests.cs similarity index 99% rename from test/Microsoft.AspNetCore.Server.KestrelTests/HttpParserTests.cs rename to test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/HttpParserTests.cs index db1d324ee0..8ef554e4f5 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/HttpParserTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/HttpParserTests.cs @@ -16,7 +16,7 @@ using Microsoft.Extensions.Logging; using Moq; using Xunit; -namespace Microsoft.AspNetCore.Server.KestrelTests +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests { public class HttpParserTests { diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/HttpUtilitiesTest.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/HttpUtilitiesTest.cs similarity index 99% rename from test/Microsoft.AspNetCore.Server.KestrelTests/HttpUtilitiesTest.cs rename to test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/HttpUtilitiesTest.cs index 37b227bd5c..08efbb4d40 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/HttpUtilitiesTest.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/HttpUtilitiesTest.cs @@ -8,7 +8,7 @@ using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Internal.System; using Xunit; -namespace Microsoft.AspNetCore.Server.KestrelTests +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests { public class HttpUtilitiesTest { diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelEventSourceTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/KestrelEventSourceTests.cs similarity index 94% rename from test/Microsoft.AspNetCore.Server.KestrelTests/KestrelEventSourceTests.cs rename to test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/KestrelEventSourceTests.cs index fc51df41f3..4f1944387b 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelEventSourceTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/KestrelEventSourceTests.cs @@ -7,7 +7,7 @@ using System.Reflection; using Microsoft.AspNetCore.Server.Kestrel.Core; using Xunit; -namespace Microsoft.AspNetCore.Server.KestrelTests +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests { public class KestrelEventSourceTests { diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerLimitsTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/KestrelServerLimitsTests.cs similarity index 99% rename from test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerLimitsTests.cs rename to test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/KestrelServerLimitsTests.cs index ff30838839..a4bf75c59b 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerLimitsTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/KestrelServerLimitsTests.cs @@ -5,7 +5,7 @@ using System; using Microsoft.AspNetCore.Server.Kestrel.Core; using Xunit; -namespace Microsoft.AspNetCore.Server.KestrelTests +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests { public class KestrelServerLimitsTests { diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerOptionsTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/KestrelServerOptionsTests.cs similarity index 92% rename from test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerOptionsTests.cs rename to test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/KestrelServerOptionsTests.cs index 13a1d442b6..e0e97f2aac 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerOptionsTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/KestrelServerOptionsTests.cs @@ -5,7 +5,7 @@ using System.Net; using Microsoft.AspNetCore.Server.Kestrel.Core; using Xunit; -namespace Microsoft.AspNetCore.Server.KestrelTests +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests { public class KestrelServerOptionsTests { diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/KestrelServerTests.cs similarity index 99% rename from test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerTests.cs rename to test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/KestrelServerTests.cs index 8c3e5fa0b2..bbb3f21c1d 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/KestrelServerTests.cs @@ -16,7 +16,7 @@ using Microsoft.Extensions.Options; using Moq; using Xunit; -namespace Microsoft.AspNetCore.Server.KestrelTests +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests { public class KestrelServerTests { diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/LoggingThreadPoolTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/LoggingThreadPoolTests.cs similarity index 96% rename from test/Microsoft.AspNetCore.Server.KestrelTests/LoggingThreadPoolTests.cs rename to test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/LoggingThreadPoolTests.cs index 3209179abc..9616315bae 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/LoggingThreadPoolTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/LoggingThreadPoolTests.cs @@ -8,7 +8,7 @@ using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; using Microsoft.AspNetCore.Testing; using Xunit; -namespace Microsoft.AspNetCore.Server.KestrelTests +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests { public class LoggingThreadPoolTests { diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/MessageBodyTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/MessageBodyTests.cs similarity index 99% rename from test/Microsoft.AspNetCore.Server.KestrelTests/MessageBodyTests.cs rename to test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/MessageBodyTests.cs index da912b65a8..5b06b25acc 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/MessageBodyTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/MessageBodyTests.cs @@ -16,7 +16,7 @@ using Moq; using Xunit; using Xunit.Sdk; -namespace Microsoft.AspNetCore.Server.KestrelTests +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests { /// /// Summary description for MessageBodyTests diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/Microsoft.AspNetCore.Server.KestrelTests.csproj b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/Microsoft.AspNetCore.Server.Kestrel.Core.Tests.csproj similarity index 88% rename from test/Microsoft.AspNetCore.Server.KestrelTests/Microsoft.AspNetCore.Server.KestrelTests.csproj rename to test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/Microsoft.AspNetCore.Server.Kestrel.Core.Tests.csproj index 748a4a79f9..be64007718 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/Microsoft.AspNetCore.Server.KestrelTests.csproj +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/Microsoft.AspNetCore.Server.Kestrel.Core.Tests.csproj @@ -22,12 +22,12 @@ - - + + diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/OutputProducerTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/OutputProducerTests.cs new file mode 100644 index 0000000000..ff5591b109 --- /dev/null +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/OutputProducerTests.cs @@ -0,0 +1,61 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; +using Microsoft.AspNetCore.Testing; +using Moq; +using Xunit; + +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests +{ + public class OutputProducerTests + { + private readonly PipeFactory _pipeFactory; + + public OutputProducerTests() + { + _pipeFactory = new PipeFactory(); + } + + public void Dispose() + { + _pipeFactory.Dispose(); + } + + [Fact] + public void WritesNoopAfterConnectionCloses() + { + var pipeOptions = new PipeOptions + { + ReaderScheduler = Mock.Of(), + }; + + using (var socketOutput = CreateOutputProducer(pipeOptions)) + { + // Close + socketOutput.Dispose(); + + var called = false; + + ((ISocketOutput)socketOutput).Write((buffer, state) => + { + called = true; + }, + null); + + Assert.False(called); + } + } + + private OutputProducer CreateOutputProducer(PipeOptions pipeOptions) + { + var pipe = _pipeFactory.Create(pipeOptions); + var serviceContext = new TestServiceContext(); + var frame = new Frame(null, new FrameContext { ServiceContext = serviceContext }); + var socketOutput = new OutputProducer(pipe.Writer, frame, "0", serviceContext.Log); + + return socketOutput; + } + } +} diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/PathNormalizerTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/PathNormalizerTests.cs similarity index 97% rename from test/Microsoft.AspNetCore.Server.KestrelTests/PathNormalizerTests.cs rename to test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/PathNormalizerTests.cs index 644580a10d..1440c1ba6e 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/PathNormalizerTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/PathNormalizerTests.cs @@ -7,7 +7,7 @@ using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Internal.System; using Xunit; -namespace Microsoft.AspNetCore.Server.KestrelTests +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests { public class PathNormalizerTests { diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/PipeOptionsTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/PipeOptionsTests.cs similarity index 94% rename from test/Microsoft.AspNetCore.Server.KestrelTests/PipeOptionsTests.cs rename to test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/PipeOptionsTests.cs index a542711393..5a4cc05601 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/PipeOptionsTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/PipeOptionsTests.cs @@ -8,7 +8,7 @@ using Microsoft.AspNetCore.Testing; using Moq; using Xunit; -namespace Microsoft.AspNetCore.Server.KestrelTests +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests { public class PipeOptionsTests { @@ -35,7 +35,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [Theory] [InlineData(10, 10, 10)] [InlineData(null, 0, 0)] - public void LibuvInputPipeOptionsConfiguredCorrectly(long? maxRequestBufferSize, long expectedMaximumSizeLow, long expectedMaximumSizeHigh) + public void InputPipeOptionsConfiguredCorrectly(long? maxRequestBufferSize, long expectedMaximumSizeLow, long expectedMaximumSizeHigh) { var serviceContext = new TestServiceContext(); serviceContext.ServerOptions.Limits.MaxRequestBufferSize = maxRequestBufferSize; diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/PipelineExtensionTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/PipelineExtensionTests.cs similarity index 99% rename from test/Microsoft.AspNetCore.Server.KestrelTests/PipelineExtensionTests.cs rename to test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/PipelineExtensionTests.cs index 614e81bb39..ec85ef3b5e 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/PipelineExtensionTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/PipelineExtensionTests.cs @@ -9,7 +9,7 @@ using Microsoft.AspNetCore.Server.Kestrel.Internal.System; using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; using Xunit; -namespace Microsoft.AspNetCore.Server.KestrelTests +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests { public class PipelineExtensionTests : IDisposable { diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/ServerAddressTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/ServerAddressTests.cs similarity index 98% rename from test/Microsoft.AspNetCore.Server.KestrelTests/ServerAddressTests.cs rename to test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/ServerAddressTests.cs index a412527653..9c9c7a654b 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/ServerAddressTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/ServerAddressTests.cs @@ -5,7 +5,7 @@ using System; using Microsoft.AspNetCore.Server.Kestrel.Core; using Xunit; -namespace Microsoft.AspNetCore.Server.KestrelTests +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests { public class ServerAddressTests { diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/StreamSocketOutputTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/StreamSocketOutputTests.cs similarity index 98% rename from test/Microsoft.AspNetCore.Server.KestrelTests/StreamSocketOutputTests.cs rename to test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/StreamSocketOutputTests.cs index bc481be73f..0a3f383dd9 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/StreamSocketOutputTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/StreamSocketOutputTests.cs @@ -7,7 +7,7 @@ using Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal; using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; using Xunit; -namespace Microsoft.AspNetCore.Server.KestrelTests +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests { public class StreamSocketOutputTests { diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/AssertExtensions.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/TestHelpers/AssertExtensions.cs similarity index 100% rename from test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/AssertExtensions.cs rename to test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/TestHelpers/AssertExtensions.cs diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockFrameControl.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/TestHelpers/MockFrameControl.cs similarity index 92% rename from test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockFrameControl.cs rename to test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/TestHelpers/MockFrameControl.cs index bf4b4b0d3b..cf26ef8f68 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockFrameControl.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/TestHelpers/MockFrameControl.cs @@ -7,7 +7,7 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; using Microsoft.Extensions.Internal; -namespace Microsoft.AspNetCore.Server.KestrelTests.TestHelpers +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests.TestHelpers { public class MockFrameControl : IFrameControl { diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestInput.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/TestInput.cs similarity index 97% rename from test/Microsoft.AspNetCore.Server.KestrelTests/TestInput.cs rename to test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/TestInput.cs index f5707b962c..50f8c9c30d 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/TestInput.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/TestInput.cs @@ -11,7 +11,7 @@ using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions; using Microsoft.AspNetCore.Testing; using Microsoft.Extensions.Internal; -namespace Microsoft.AspNetCore.Server.KestrelTests +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests { class TestInput : ITimeoutControl, IFrameControl, IDisposable { diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/xunit.runner.json b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/xunit.runner.json similarity index 100% rename from test/Microsoft.AspNetCore.Server.KestrelTests/xunit.runner.json rename to test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/xunit.runner.json diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedRequestTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ChunkedRequestTests.cs similarity index 99% rename from test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedRequestTests.cs rename to test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ChunkedRequestTests.cs index 0ed47420b9..be1718d76a 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedRequestTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ChunkedRequestTests.cs @@ -13,7 +13,7 @@ using Microsoft.AspNetCore.Testing; using Microsoft.Extensions.Internal; using Xunit; -namespace Microsoft.AspNetCore.Server.KestrelTests +namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { public class ChunkedRequestTests { diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedResponseTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ChunkedResponseTests.cs similarity index 99% rename from test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedResponseTests.cs rename to test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ChunkedResponseTests.cs index c52c1fa5bc..d68283a1ab 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedResponseTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ChunkedResponseTests.cs @@ -11,7 +11,7 @@ using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.AspNetCore.Testing; using Xunit; -namespace Microsoft.AspNetCore.Server.KestrelTests +namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { public class ChunkedResponseTests { diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionAdapterTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ConnectionAdapterTests.cs similarity index 99% rename from test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionAdapterTests.cs rename to test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ConnectionAdapterTests.cs index 57e89f56f2..0d8150f62c 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionAdapterTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ConnectionAdapterTests.cs @@ -12,7 +12,7 @@ using Microsoft.AspNetCore.Server.Kestrel.Core.Adapter; using Microsoft.AspNetCore.Testing; using Xunit; -namespace Microsoft.AspNetCore.Server.KestrelTests +namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { public class ConnectionAdapterTests { diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/DefaultHeaderTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/DefaultHeaderTests.cs similarity index 96% rename from test/Microsoft.AspNetCore.Server.KestrelTests/DefaultHeaderTests.cs rename to test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/DefaultHeaderTests.cs index 2493387b9b..91ff1816cf 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/DefaultHeaderTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/DefaultHeaderTests.cs @@ -6,7 +6,7 @@ using Microsoft.AspNetCore.Testing; using Microsoft.Extensions.Internal; using Xunit; -namespace Microsoft.AspNetCore.Server.KestrelTests +namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { public class DefaultHeaderTests { diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/HttpsConnectionAdapterTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/HttpsConnectionAdapterTests.cs similarity index 99% rename from test/Microsoft.AspNetCore.Server.KestrelTests/HttpsConnectionAdapterTests.cs rename to test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/HttpsConnectionAdapterTests.cs index 25c637b628..e4d6e0eb22 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/HttpsConnectionAdapterTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/HttpsConnectionAdapterTests.cs @@ -20,7 +20,7 @@ using Microsoft.AspNetCore.Testing; using Microsoft.Extensions.Internal; using Xunit; -namespace Microsoft.AspNetCore.Server.KestrelTests +namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { public class HttpsConnectionAdapterTests { diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/MaxRequestBufferSizeTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/MaxRequestBufferSizeTests.cs index d60ae18dc4..8803ded61a 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/MaxRequestBufferSizeTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/MaxRequestBufferSizeTests.cs @@ -248,7 +248,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests // Timeouts large enough to prevent false positives, but small enough to fail quickly. socket.SendTimeout = 10 * 1000; - socket.ReceiveTimeout = 10 * 1000; + socket.ReceiveTimeout = 30 * 1000; socket.Connect(IPAddress.Loopback, port); diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/RequestTargetProcessingTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTargetProcessingTests.cs similarity index 98% rename from test/Microsoft.AspNetCore.Server.KestrelTests/RequestTargetProcessingTests.cs rename to test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTargetProcessingTests.cs index 3dea2881cf..3d9a55b9f6 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/RequestTargetProcessingTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTargetProcessingTests.cs @@ -11,7 +11,7 @@ using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; using Microsoft.AspNetCore.Testing; using Xunit; -namespace Microsoft.AspNetCore.Server.KestrelTests +namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { public class RequestTargetProcessingTests { diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs index a8d20e1d69..abb9dace50 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs @@ -5,6 +5,7 @@ using System; using System.Collections.Concurrent; using System.Globalization; using System.IO; +using System.Linq; using System.Net; using System.Net.Http; using System.Net.Sockets; @@ -15,6 +16,8 @@ using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http.Features; +using Microsoft.AspNetCore.Server.Kestrel.Core; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking; using Microsoft.AspNetCore.Testing; using Microsoft.AspNetCore.Testing.xunit; @@ -35,6 +38,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests private const int _connectionResetEventId = 19; private const int _semaphoreWaitTimeout = 2500; + public static TheoryData ConnectionAdapterData => new TheoryData + { + new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0)), + new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0)) + { + ConnectionAdapters = { new PassThroughConnectionAdapter() } + } + }; + [Theory] [InlineData(10 * 1024 * 1024, true)] // In the following dataset, send at least 2GB. @@ -633,6 +645,558 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } } + [Theory] + [MemberData(nameof(ConnectionAdapterData))] + public async Task Http11KeptAliveByDefault(ListenOptions listenOptions) + { + var testContext = new TestServiceContext(); + + using (var server = new TestServer(TestApp.EchoAppChunked, testContext, listenOptions)) + { + using (var connection = server.CreateConnection()) + { + await connection.Send( + "GET / HTTP/1.1", + "", + "GET / HTTP/1.1", + "Connection: close", + "Content-Length: 7", + "", + "Goodbye"); + await connection.ReceiveEnd( + "HTTP/1.1 200 OK", + $"Date: {testContext.DateHeaderValue}", + "Content-Length: 0", + "", + "HTTP/1.1 200 OK", + "Connection: close", + $"Date: {testContext.DateHeaderValue}", + "Content-Length: 7", + "", + "Goodbye"); + } + } + } + + [Theory] + [MemberData(nameof(ConnectionAdapterData))] + public async Task Http10NotKeptAliveByDefault(ListenOptions listenOptions) + { + var testContext = new TestServiceContext(); + + using (var server = new TestServer(TestApp.EchoApp, testContext, listenOptions)) + { + using (var connection = server.CreateConnection()) + { + await connection.Send( + "GET / HTTP/1.0", + "", + ""); + await connection.ReceiveForcedEnd( + "HTTP/1.1 200 OK", + "Connection: close", + $"Date: {testContext.DateHeaderValue}", + "Content-Length: 0", + "", + ""); + } + + using (var connection = server.CreateConnection()) + { + await connection.Send( + "POST / HTTP/1.0", + "Content-Length: 11", + "", + "Hello World"); + await connection.ReceiveForcedEnd( + "HTTP/1.1 200 OK", + "Connection: close", + $"Date: {testContext.DateHeaderValue}", + "", + "Hello World"); + } + } + } + + [Theory] + [MemberData(nameof(ConnectionAdapterData))] + public async Task Http10KeepAlive(ListenOptions listenOptions) + { + var testContext = new TestServiceContext(); + + using (var server = new TestServer(TestApp.EchoAppChunked, testContext, listenOptions)) + { + using (var connection = server.CreateConnection()) + { + await connection.Send( + "GET / HTTP/1.0", + "Connection: keep-alive", + "", + "POST / HTTP/1.0", + "Content-Length: 7", + "", + "Goodbye"); + await connection.Receive( + "HTTP/1.1 200 OK", + "Connection: keep-alive", + $"Date: {testContext.DateHeaderValue}", + "Content-Length: 0", + "\r\n"); + await connection.ReceiveForcedEnd( + "HTTP/1.1 200 OK", + "Connection: close", + $"Date: {testContext.DateHeaderValue}", + "Content-Length: 7", + "", + "Goodbye"); + } + } + } + + [Theory] + [MemberData(nameof(ConnectionAdapterData))] + public async Task Http10KeepAliveNotHonoredIfResponseContentLengthNotSet(ListenOptions listenOptions) + { + var testContext = new TestServiceContext(); + + using (var server = new TestServer(TestApp.EchoApp, testContext, listenOptions)) + { + using (var connection = server.CreateConnection()) + { + await connection.Send( + "GET / HTTP/1.0", + "Connection: keep-alive", + "", + ""); + + await connection.Receive( + "HTTP/1.1 200 OK", + "Connection: keep-alive", + $"Date: {testContext.DateHeaderValue}", + "Content-Length: 0", + "\r\n"); + + await connection.Send( + "POST / HTTP/1.0", + "Connection: keep-alive", + "Content-Length: 7", + "", + "Goodbye"); + + await connection.ReceiveForcedEnd( + "HTTP/1.1 200 OK", + "Connection: close", + $"Date: {testContext.DateHeaderValue}", + "", + "Goodbye"); + } + } + } + + [Theory] + [MemberData(nameof(ConnectionAdapterData))] + public async Task Http10KeepAliveHonoredIfResponseContentLengthSet(ListenOptions listenOptions) + { + var testContext = new TestServiceContext(); + + using (var server = new TestServer(TestApp.EchoAppChunked, testContext, listenOptions)) + { + using (var connection = server.CreateConnection()) + { + await connection.Send( + "POST / HTTP/1.0", + "Content-Length: 11", + "Connection: keep-alive", + "", + "Hello World"); + + await connection.Receive( + "HTTP/1.1 200 OK", + "Connection: keep-alive", + $"Date: {testContext.DateHeaderValue}", + "Content-Length: 11", + "", + "Hello World"); + + await connection.Send( + "POST / HTTP/1.0", + "Connection: keep-alive", + "Content-Length: 11", + "", + "Hello Again"); + + await connection.Receive( + "HTTP/1.1 200 OK", + "Connection: keep-alive", + $"Date: {testContext.DateHeaderValue}", + "Content-Length: 11", + "", + "Hello Again"); + + await connection.Send( + "POST / HTTP/1.0", + "Content-Length: 7", + "", + "Goodbye"); + + await connection.ReceiveForcedEnd( + "HTTP/1.1 200 OK", + "Connection: close", + $"Date: {testContext.DateHeaderValue}", + "Content-Length: 7", + "", + "Goodbye"); + } + } + } + + [Theory] + [MemberData(nameof(ConnectionAdapterData))] + public async Task Expect100ContinueHonored(ListenOptions listenOptions) + { + var testContext = new TestServiceContext(); + + using (var server = new TestServer(TestApp.EchoAppChunked, testContext, listenOptions)) + { + using (var connection = server.CreateConnection()) + { + await connection.Send( + "POST / HTTP/1.1", + "Expect: 100-continue", + "Connection: close", + "Content-Length: 11", + "\r\n"); + await connection.Receive( + "HTTP/1.1 100 Continue", + "", + ""); + await connection.Send("Hello World"); + await connection.ReceiveForcedEnd( + "HTTP/1.1 200 OK", + "Connection: close", + $"Date: {testContext.DateHeaderValue}", + "Content-Length: 11", + "", + "Hello World"); + } + } + } + + [Theory] + [MemberData(nameof(ConnectionAdapterData))] + public async Task ZeroContentLengthAssumedOnNonKeepAliveRequestsWithoutContentLengthOrTransferEncodingHeader(ListenOptions listenOptions) + { + var testContext = new TestServiceContext(); + + using (var server = new TestServer(async httpContext => + { + // This will hang if 0 content length is not assumed by the server + Assert.Equal(0, await httpContext.Request.Body.ReadAsync(new byte[1], 0, 1).TimeoutAfter(TimeSpan.FromSeconds(10))); + }, testContext, listenOptions)) + { + using (var connection = server.CreateConnection()) + { + // Use Send instead of SendEnd to ensure the connection will remain open while + // the app runs and reads 0 bytes from the body nonetheless. This checks that + // https://github.com/aspnet/KestrelHttpServer/issues/1104 is not regressing. + await connection.Send( + "GET / HTTP/1.1", + "Connection: close", + "", + ""); + await connection.ReceiveForcedEnd( + "HTTP/1.1 200 OK", + "Connection: close", + $"Date: {testContext.DateHeaderValue}", + "Content-Length: 0", + "", + ""); + } + + using (var connection = server.CreateConnection()) + { + await connection.Send( + "GET / HTTP/1.0", + "", + ""); + await connection.ReceiveForcedEnd( + "HTTP/1.1 200 OK", + "Connection: close", + $"Date: {testContext.DateHeaderValue}", + "Content-Length: 0", + "", + ""); + } + } + } + + [Theory] + [MemberData(nameof(ConnectionAdapterData))] + public async Task ConnectionClosesWhenFinReceivedBeforeRequestCompletes(ListenOptions listenOptions) + { + var testContext = new TestServiceContext(); + + using (var server = new TestServer(TestApp.EchoAppChunked, testContext, listenOptions)) + { + using (var connection = server.CreateConnection()) + { + await connection.Send( + "POST / HTTP/1.1"); + connection.Shutdown(SocketShutdown.Send); + await connection.ReceiveForcedEnd(); + } + + using (var connection = server.CreateConnection()) + { + await connection.Send( + "POST / HTTP/1.1", + "Content-Length: 7"); + connection.Shutdown(SocketShutdown.Send); + await connection.ReceiveForcedEnd(); + } + } + } + + [Theory] + [MemberData(nameof(ConnectionAdapterData))] + public async Task RequestsCanBeAbortedMidRead(ListenOptions listenOptions) + { + var testContext = new TestServiceContext(); + + var readTcs = new TaskCompletionSource(); + var registrationTcs = new TaskCompletionSource(); + var requestId = 0; + + using (var server = new TestServer(async httpContext => + { + requestId++; + + var response = httpContext.Response; + var request = httpContext.Request; + var lifetime = httpContext.Features.Get(); + + lifetime.RequestAborted.Register(() => registrationTcs.TrySetResult(requestId)); + + if (requestId == 1) + { + response.Headers["Content-Length"] = new[] { "5" }; + + await response.WriteAsync("World"); + } + else + { + var readTask = request.Body.CopyToAsync(Stream.Null); + + lifetime.Abort(); + + try + { + await readTask; + } + catch (Exception ex) + { + readTcs.SetException(ex); + throw; + } + + readTcs.SetException(new Exception("This shouldn't be reached.")); + } + }, testContext, listenOptions)) + { + using (var connection = server.CreateConnection()) + { + // Never send the body so CopyToAsync always fails. + await connection.Send( + "POST / HTTP/1.1", + "Content-Length: 5", + "", + "HelloPOST / HTTP/1.1", + "Content-Length: 5", + "", + ""); + + await connection.ReceiveForcedEnd( + "HTTP/1.1 200 OK", + $"Date: {testContext.DateHeaderValue}", + "Content-Length: 5", + "", + "World"); + } + } + + await Assert.ThrowsAsync(async () => await readTcs.Task); + + // The cancellation token for only the last request should be triggered. + var abortedRequestId = await registrationTcs.Task; + Assert.Equal(2, abortedRequestId); + } + + [Theory] + [MemberData(nameof(ConnectionAdapterData))] + public async Task RequestHeadersAreResetOnEachRequest(ListenOptions listenOptions) + { + var testContext = new TestServiceContext(); + + IHeaderDictionary originalRequestHeaders = null; + var firstRequest = true; + + using (var server = new TestServer(httpContext => + { + var requestFeature = httpContext.Features.Get(); + + if (firstRequest) + { + originalRequestHeaders = requestFeature.Headers; + requestFeature.Headers = new FrameRequestHeaders(); + firstRequest = false; + } + else + { + Assert.Same(originalRequestHeaders, requestFeature.Headers); + } + + return TaskCache.CompletedTask; + }, testContext, listenOptions)) + { + using (var connection = server.CreateConnection()) + { + await connection.Send( + "GET / HTTP/1.1", + "", + "GET / HTTP/1.1", + "", + ""); + await connection.ReceiveEnd( + "HTTP/1.1 200 OK", + $"Date: {testContext.DateHeaderValue}", + "Content-Length: 0", + "", + "HTTP/1.1 200 OK", + $"Date: {testContext.DateHeaderValue}", + "Content-Length: 0", + "", + ""); + } + } + } + + [Theory] + [MemberData(nameof(ConnectionAdapterData))] + public async Task UpgradeRequestIsNotKeptAliveOrChunked(ListenOptions listenOptions) + { + const string message = "Hello World"; + + var testContext = new TestServiceContext(); + + using (var server = new TestServer(async context => + { + var upgradeFeature = context.Features.Get(); + var duplexStream = await upgradeFeature.UpgradeAsync(); + + var buffer = new byte[message.Length]; + var read = 0; + while (read < message.Length) + { + read += await duplexStream.ReadAsync(buffer, read, buffer.Length - read).TimeoutAfter(TimeSpan.FromSeconds(10)); + } + + await duplexStream.WriteAsync(buffer, 0, read); + }, testContext, listenOptions)) + { + using (var connection = server.CreateConnection()) + { + await connection.Send( + "GET / HTTP/1.1", + "Connection: Upgrade", + "", + message); + await connection.ReceiveForcedEnd( + "HTTP/1.1 101 Switching Protocols", + "Connection: Upgrade", + $"Date: {testContext.DateHeaderValue}", + "", + message); + } + } + } + + [Theory] + [MemberData(nameof(ConnectionAdapterData))] + public async Task HeadersAndStreamsAreReusedAcrossRequests(ListenOptions listenOptions) + { + var testContext = new TestServiceContext(); + var streamCount = 0; + var requestHeadersCount = 0; + var responseHeadersCount = 0; + var loopCount = 20; + Stream lastStream = null; + IHeaderDictionary lastRequestHeaders = null; + IHeaderDictionary lastResponseHeaders = null; + + using (var server = new TestServer(async context => + { + if (context.Request.Body != lastStream) + { + lastStream = context.Request.Body; + streamCount++; + } + if (context.Request.Headers != lastRequestHeaders) + { + lastRequestHeaders = context.Request.Headers; + requestHeadersCount++; + } + if (context.Response.Headers != lastResponseHeaders) + { + lastResponseHeaders = context.Response.Headers; + responseHeadersCount++; + } + + var ms = new MemoryStream(); + await context.Request.Body.CopyToAsync(ms); + var request = ms.ToArray(); + + context.Response.ContentLength = request.Length; + + await context.Response.Body.WriteAsync(request, 0, request.Length); + }, testContext)) + { + using (var connection = server.CreateConnection()) + { + var requestData = + Enumerable.Repeat("GET / HTTP/1.1\r\n", loopCount) + .Concat(new[] { "GET / HTTP/1.1\r\nContent-Length: 7\r\nConnection: close\r\n\r\nGoodbye" }); + + var response = string.Join("\r\n", new string[] { + "HTTP/1.1 200 OK", + $"Date: {testContext.DateHeaderValue}", + "Content-Length: 0", + ""}); + + var lastResponse = string.Join("\r\n", new string[] + { + "HTTP/1.1 200 OK", + "Connection: close", + $"Date: {testContext.DateHeaderValue}", + "Content-Length: 7", + "", + "Goodbye" + }); + + var responseData = + Enumerable.Repeat(response, loopCount) + .Concat(new[] { lastResponse }); + + await connection.Send(requestData.ToArray()); + + await connection.ReceiveEnd(responseData.ToArray()); + } + + Assert.Equal(1, streamCount); + Assert.Equal(1, requestHeadersCount); + Assert.Equal(1, responseHeadersCount); + } + } + private async Task TestRemoteIPAddress(string registerAddress, string requestAddress, string expectAddress) { var builder = new WebHostBuilder() diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs index d68624bd3b..02b2590e16 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs @@ -2,6 +2,8 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Collections.Generic; +using System.IO; using System.Linq; using System.Net; using System.Net.Http; @@ -14,6 +16,7 @@ using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Server.Kestrel.Core; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; using Microsoft.AspNetCore.Testing; @@ -27,6 +30,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { public class ResponseTests { + public static TheoryData ConnectionAdapterData => new TheoryData + { + new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0)), + new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0)) + { + ConnectionAdapters = { new PassThroughConnectionAdapter() } + } + }; + [Fact] public async Task LargeDownload() { @@ -1529,6 +1541,751 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } } + [Theory] + [MemberData(nameof(ConnectionAdapterData))] + public async Task Http11ResponseSentToHttp10Request(ListenOptions listenOptions) + { + var serviceContext = new TestServiceContext(); + + using (var server = new TestServer(TestApp.EchoApp, serviceContext, listenOptions)) + { + using (var connection = server.CreateConnection()) + { + await connection.Send( + "POST / HTTP/1.0", + "Content-Length: 11", + "", + "Hello World"); + await connection.ReceiveEnd( + "HTTP/1.1 200 OK", + "Connection: close", + $"Date: {serviceContext.DateHeaderValue}", + "", + "Hello World"); + } + } + } + + [Theory] + [MemberData(nameof(ConnectionAdapterData))] + public async Task ZeroContentLengthSetAutomaticallyAfterNoWrites(ListenOptions listenOptions) + { + var testContext = new TestServiceContext(); + + using (var server = new TestServer(TestApp.EmptyApp, testContext, listenOptions)) + { + using (var connection = server.CreateConnection()) + { + await connection.Send( + "GET / HTTP/1.1", + "", + "GET / HTTP/1.0", + "Connection: keep-alive", + "", + ""); + await connection.ReceiveEnd( + "HTTP/1.1 200 OK", + $"Date: {testContext.DateHeaderValue}", + "Content-Length: 0", + "", + "HTTP/1.1 200 OK", + "Connection: keep-alive", + $"Date: {testContext.DateHeaderValue}", + "Content-Length: 0", + "", + ""); + } + } + } + + [Theory] + [MemberData(nameof(ConnectionAdapterData))] + public async Task ZeroContentLengthSetAutomaticallyForNonKeepAliveRequests(ListenOptions listenOptions) + { + var testContext = new TestServiceContext(); + + using (var server = new TestServer(async httpContext => + { + Assert.Equal(0, await httpContext.Request.Body.ReadAsync(new byte[1], 0, 1).TimeoutAfter(TimeSpan.FromSeconds(10))); + }, testContext, listenOptions)) + { + using (var connection = server.CreateConnection()) + { + await connection.Send( + "GET / HTTP/1.1", + "Connection: close", + "", + ""); + await connection.ReceiveEnd( + "HTTP/1.1 200 OK", + "Connection: close", + $"Date: {testContext.DateHeaderValue}", + "Content-Length: 0", + "", + ""); + } + + using (var connection = server.CreateConnection()) + { + await connection.Send( + "GET / HTTP/1.0", + "", + ""); + await connection.ReceiveEnd( + "HTTP/1.1 200 OK", + "Connection: close", + $"Date: {testContext.DateHeaderValue}", + "Content-Length: 0", + "", + ""); + } + } + } + + [Theory] + [MemberData(nameof(ConnectionAdapterData))] + public async Task ZeroContentLengthNotSetAutomaticallyForHeadRequests(ListenOptions listenOptions) + { + var testContext = new TestServiceContext(); + + using (var server = new TestServer(TestApp.EmptyApp, testContext, listenOptions)) + { + using (var connection = server.CreateConnection()) + { + await connection.Send( + "HEAD / HTTP/1.1", + "", + ""); + await connection.ReceiveEnd( + "HTTP/1.1 200 OK", + $"Date: {testContext.DateHeaderValue}", + "", + ""); + } + } + } + + [Theory] + [MemberData(nameof(ConnectionAdapterData))] + public async Task ZeroContentLengthNotSetAutomaticallyForCertainStatusCodes(ListenOptions listenOptions) + { + var testContext = new TestServiceContext(); + + using (var server = new TestServer(async httpContext => + { + var request = httpContext.Request; + var response = httpContext.Response; + + using (var reader = new StreamReader(request.Body, Encoding.ASCII)) + { + var statusString = await reader.ReadLineAsync(); + response.StatusCode = int.Parse(statusString); + } + }, testContext, listenOptions)) + { + using (var connection = server.CreateConnection()) + { + await connection.Send( + "POST / HTTP/1.1", + "Content-Length: 3", + "", + "204POST / HTTP/1.1", + "Content-Length: 3", + "", + "205POST / HTTP/1.1", + "Content-Length: 3", + "", + "304POST / HTTP/1.1", + "Content-Length: 3", + "", + "200"); + await connection.ReceiveEnd( + "HTTP/1.1 204 No Content", + $"Date: {testContext.DateHeaderValue}", + "", + "HTTP/1.1 205 Reset Content", + $"Date: {testContext.DateHeaderValue}", + "", + "HTTP/1.1 304 Not Modified", + $"Date: {testContext.DateHeaderValue}", + "", + "HTTP/1.1 200 OK", + $"Date: {testContext.DateHeaderValue}", + "Content-Length: 0", + "", + ""); + } + } + } + + [Theory] + [MemberData(nameof(ConnectionAdapterData))] + public async Task ConnectionClosedAfter101Response(ListenOptions listenOptions) + { + var testContext = new TestServiceContext(); + + using (var server = new TestServer(async httpContext => + { + var request = httpContext.Request; + var stream = await httpContext.Features.Get().UpgradeAsync(); + var response = Encoding.ASCII.GetBytes("hello, world"); + await stream.WriteAsync(response, 0, response.Length); + }, testContext, listenOptions)) + { + using (var connection = server.CreateConnection()) + { + await connection.Send( + "GET / HTTP/1.1", + "", + ""); + await connection.ReceiveForcedEnd( + "HTTP/1.1 101 Switching Protocols", + "Connection: Upgrade", + $"Date: {testContext.DateHeaderValue}", + "", + "hello, world"); + } + + using (var connection = server.CreateConnection()) + { + await connection.Send( + "GET / HTTP/1.0", + "Connection: keep-alive", + "", + ""); + await connection.ReceiveForcedEnd( + "HTTP/1.1 101 Switching Protocols", + "Connection: Upgrade", + $"Date: {testContext.DateHeaderValue}", + "", + "hello, world"); + } + } + } + + [Theory] + [MemberData(nameof(ConnectionAdapterData))] + public async Task ThrowingResultsIn500Response(ListenOptions listenOptions) + { + var testContext = new TestServiceContext(); + + bool onStartingCalled = false; + + var testLogger = new TestApplicationErrorLogger(); + testContext.Log = new KestrelTrace(testLogger); + + using (var server = new TestServer(httpContext => + { + var response = httpContext.Response; + response.OnStarting(_ => + { + onStartingCalled = true; + return TaskCache.CompletedTask; + }, null); + + // Anything added to the ResponseHeaders dictionary is ignored + response.Headers["Content-Length"] = "11"; + throw new Exception(); + }, testContext, listenOptions)) + { + using (var connection = server.CreateConnection()) + { + await connection.Send( + "GET / HTTP/1.1", + "", + "GET / HTTP/1.1", + "Connection: close", + "", + ""); + await connection.ReceiveForcedEnd( + "HTTP/1.1 500 Internal Server Error", + $"Date: {testContext.DateHeaderValue}", + "Content-Length: 0", + "", + "HTTP/1.1 500 Internal Server Error", + "Connection: close", + $"Date: {testContext.DateHeaderValue}", + "Content-Length: 0", + "", + ""); + } + } + + Assert.False(onStartingCalled); + Assert.Equal(2, testLogger.ApplicationErrorsLogged); + } + + [Theory] + [MemberData(nameof(ConnectionAdapterData))] + public async Task ThrowingInOnStartingResultsInFailedWritesAnd500Response(ListenOptions listenOptions) + { + var callback1Called = false; + var callback2CallCount = 0; + + var testContext = new TestServiceContext(); + var testLogger = new TestApplicationErrorLogger(); + testContext.Log = new KestrelTrace(testLogger); + + using (var server = new TestServer(async httpContext => + { + var onStartingException = new Exception(); + + var response = httpContext.Response; + response.OnStarting(_ => + { + callback1Called = true; + throw onStartingException; + }, null); + response.OnStarting(_ => + { + callback2CallCount++; + throw onStartingException; + }, null); + + var writeException = await Assert.ThrowsAsync(async () => await response.Body.FlushAsync()); + Assert.Same(onStartingException, writeException.InnerException); + }, testContext, listenOptions)) + { + using (var connection = server.CreateConnection()) + { + await connection.Send( + "GET / HTTP/1.1", + "", + "GET / HTTP/1.1", + "", + ""); + await connection.ReceiveEnd( + "HTTP/1.1 500 Internal Server Error", + $"Date: {testContext.DateHeaderValue}", + "Content-Length: 0", + "", + "HTTP/1.1 500 Internal Server Error", + $"Date: {testContext.DateHeaderValue}", + "Content-Length: 0", + "", + ""); + } + } + + // The first registered OnStarting callback should have been called, + // since they are called LIFO order and the other one failed. + Assert.False(callback1Called); + Assert.Equal(2, callback2CallCount); + Assert.Equal(2, testLogger.ApplicationErrorsLogged); + } + + [Theory] + [MemberData(nameof(ConnectionAdapterData))] + public async Task ThrowingInOnCompletedIsLoggedAndClosesConnection(ListenOptions listenOptions) + { + var testContext = new TestServiceContext(); + + var onCompletedCalled1 = false; + var onCompletedCalled2 = false; + + var testLogger = new TestApplicationErrorLogger(); + testContext.Log = new KestrelTrace(testLogger); + + using (var server = new TestServer(async httpContext => + { + var response = httpContext.Response; + response.OnCompleted(_ => + { + onCompletedCalled1 = true; + throw new Exception(); + }, null); + response.OnCompleted(_ => + { + onCompletedCalled2 = true; + throw new Exception(); + }, null); + + response.Headers["Content-Length"] = new[] { "11" }; + + await response.Body.WriteAsync(Encoding.ASCII.GetBytes("Hello World"), 0, 11); + }, testContext, listenOptions)) + { + using (var connection = server.CreateConnection()) + { + await connection.Send( + "GET / HTTP/1.1", + "", + ""); + await connection.ReceiveForcedEnd( + "HTTP/1.1 200 OK", + $"Date: {testContext.DateHeaderValue}", + "Content-Length: 11", + "", + "Hello World"); + } + } + + // All OnCompleted callbacks should be called even if they throw. + Assert.Equal(2, testLogger.ApplicationErrorsLogged); + Assert.True(onCompletedCalled1); + Assert.True(onCompletedCalled2); + } + + [Theory] + [MemberData(nameof(ConnectionAdapterData))] + public async Task ThrowingAfterWritingKillsConnection(ListenOptions listenOptions) + { + var testContext = new TestServiceContext(); + + bool onStartingCalled = false; + + var testLogger = new TestApplicationErrorLogger(); + testContext.Log = new KestrelTrace(testLogger); + + using (var server = new TestServer(async httpContext => + { + var response = httpContext.Response; + response.OnStarting(_ => + { + onStartingCalled = true; + return Task.FromResult(null); + }, null); + + response.Headers["Content-Length"] = new[] { "11" }; + await response.Body.WriteAsync(Encoding.ASCII.GetBytes("Hello World"), 0, 11); + throw new Exception(); + }, testContext, listenOptions)) + { + using (var connection = server.CreateConnection()) + { + await connection.Send( + "GET / HTTP/1.1", + "", + ""); + await connection.ReceiveForcedEnd( + "HTTP/1.1 200 OK", + $"Date: {testContext.DateHeaderValue}", + "Content-Length: 11", + "", + "Hello World"); + } + } + + Assert.True(onStartingCalled); + Assert.Equal(1, testLogger.ApplicationErrorsLogged); + } + + [Theory] + [MemberData(nameof(ConnectionAdapterData))] + public async Task ThrowingAfterPartialWriteKillsConnection(ListenOptions listenOptions) + { + var testContext = new TestServiceContext(); + + bool onStartingCalled = false; + + var testLogger = new TestApplicationErrorLogger(); + testContext.Log = new KestrelTrace(testLogger); + + using (var server = new TestServer(async httpContext => + { + var response = httpContext.Response; + response.OnStarting(_ => + { + onStartingCalled = true; + return Task.FromResult(null); + }, null); + + response.Headers["Content-Length"] = new[] { "11" }; + await response.Body.WriteAsync(Encoding.ASCII.GetBytes("Hello"), 0, 5); + throw new Exception(); + }, testContext, listenOptions)) + { + using (var connection = server.CreateConnection()) + { + await connection.Send( + "GET / HTTP/1.1", + "", + ""); + await connection.ReceiveForcedEnd( + "HTTP/1.1 200 OK", + $"Date: {testContext.DateHeaderValue}", + "Content-Length: 11", + "", + "Hello"); + } + } + + Assert.True(onStartingCalled); + Assert.Equal(1, testLogger.ApplicationErrorsLogged); + } + + [MemberData(nameof(ConnectionAdapterData))] + public async Task FailedWritesResultInAbortedRequest(ListenOptions listenOptions) + { + var testContext = new TestServiceContext(); + + // This should match _maxBytesPreCompleted in SocketOutput + var maxBytesPreCompleted = 65536; + // Ensure string is long enough to disable write-behind buffering + var largeString = new string('a', maxBytesPreCompleted + 1); + + var writeTcs = new TaskCompletionSource(); + var registrationWh = new ManualResetEventSlim(); + var connectionCloseWh = new ManualResetEventSlim(); + + using (var server = new TestServer(async httpContext => + { + var response = httpContext.Response; + var request = httpContext.Request; + var lifetime = httpContext.Features.Get(); + + lifetime.RequestAborted.Register(() => registrationWh.Set()); + + await request.Body.CopyToAsync(Stream.Null); + connectionCloseWh.Wait(); + + try + { + // Ensure write is long enough to disable write-behind buffering + for (int i = 0; i < 100; i++) + { + await response.WriteAsync(largeString, lifetime.RequestAborted); + registrationWh.Wait(1000); + } + } + catch (Exception ex) + { + writeTcs.SetException(ex); + throw; + } + + writeTcs.SetException(new Exception("This shouldn't be reached.")); + }, testContext, listenOptions)) + { + using (var connection = server.CreateConnection()) + { + await connection.Send( + "POST / HTTP/1.1", + "Content-Length: 5", + "", + "Hello"); + // Don't wait to receive the response. Just close the socket. + } + + connectionCloseWh.Set(); + + // Write failed + await Assert.ThrowsAsync(async () => await writeTcs.Task); + // RequestAborted tripped + Assert.True(registrationWh.Wait(1000)); + } + } + + [Theory] + [MemberData(nameof(ConnectionAdapterData))] + public async Task NoErrorsLoggedWhenServerEndsConnectionBeforeClient(ListenOptions listenOptions) + { + var testContext = new TestServiceContext(); + + var testLogger = new TestApplicationErrorLogger(); + testContext.Log = new KestrelTrace(testLogger); + + using (var server = new TestServer(async httpContext => + { + var response = httpContext.Response; + response.Headers["Content-Length"] = new[] { "11" }; + await response.Body.WriteAsync(Encoding.ASCII.GetBytes("Hello World"), 0, 11); + }, testContext, listenOptions)) + { + using (var connection = server.CreateConnection()) + { + await connection.Send( + "GET / HTTP/1.0", + "", + ""); + await connection.ReceiveForcedEnd( + "HTTP/1.1 200 OK", + "Connection: close", + $"Date: {testContext.DateHeaderValue}", + "Content-Length: 11", + "", + "Hello World"); + } + } + + Assert.Equal(0, testLogger.TotalErrorsLogged); + } + + [Theory] + [MemberData(nameof(ConnectionAdapterData))] + public async Task NoResponseSentWhenConnectionIsClosedByServerBeforeClientFinishesSendingRequest(ListenOptions listenOptions) + { + var testContext = new TestServiceContext(); + + using (var server = new TestServer(httpContext => + { + httpContext.Abort(); + return TaskCache.CompletedTask; + }, testContext, listenOptions)) + { + using (var connection = server.CreateConnection()) + { + await connection.Send( + "POST / HTTP/1.0", + "Content-Length: 1", + "", + ""); + await connection.ReceiveForcedEnd(); + } + } + } + + [Theory] + [MemberData(nameof(ConnectionAdapterData))] + public async Task ResponseHeadersAreResetOnEachRequest(ListenOptions listenOptions) + { + var testContext = new TestServiceContext(); + + IHeaderDictionary originalResponseHeaders = null; + var firstRequest = true; + + using (var server = new TestServer(httpContext => + { + var responseFeature = httpContext.Features.Get(); + + if (firstRequest) + { + originalResponseHeaders = responseFeature.Headers; + responseFeature.Headers = new FrameResponseHeaders(); + firstRequest = false; + } + else + { + Assert.Same(originalResponseHeaders, responseFeature.Headers); + } + + return TaskCache.CompletedTask; + }, testContext, listenOptions)) + { + using (var connection = server.CreateConnection()) + { + await connection.Send( + "GET / HTTP/1.1", + "", + "GET / HTTP/1.1", + "", + ""); + await connection.ReceiveEnd( + "HTTP/1.1 200 OK", + $"Date: {testContext.DateHeaderValue}", + "Content-Length: 0", + "", + "HTTP/1.1 200 OK", + $"Date: {testContext.DateHeaderValue}", + "Content-Length: 0", + "", + ""); + } + } + } + + [Theory] + [MemberData(nameof(ConnectionAdapterData))] + public async Task OnStartingCallbacksAreCalledInLastInFirstOutOrder(ListenOptions listenOptions) + { + const string response = "hello, world"; + + var testContext = new TestServiceContext(); + + var callOrder = new Stack(); + var onStartingTcs = new TaskCompletionSource(); + + using (var server = new TestServer(async context => + { + context.Response.OnStarting(_ => + { + callOrder.Push(1); + onStartingTcs.SetResult(null); + return TaskCache.CompletedTask; + }, null); + context.Response.OnStarting(_ => + { + callOrder.Push(2); + return TaskCache.CompletedTask; + }, null); + + context.Response.ContentLength = response.Length; + await context.Response.WriteAsync(response); + }, testContext, listenOptions)) + { + using (var connection = server.CreateConnection()) + { + await connection.Send( + "GET / HTTP/1.1", + "", + ""); + await connection.ReceiveEnd( + "HTTP/1.1 200 OK", + $"Date: {testContext.DateHeaderValue}", + $"Content-Length: {response.Length}", + "", + "hello, world"); + + // Wait for all callbacks to be called. + await onStartingTcs.Task.TimeoutAfter(TimeSpan.FromSeconds(10)); + } + } + + Assert.Equal(1, callOrder.Pop()); + Assert.Equal(2, callOrder.Pop()); + } + + [Theory] + [MemberData(nameof(ConnectionAdapterData))] + public async Task OnCompletedCallbacksAreCalledInLastInFirstOutOrder(ListenOptions listenOptions) + { + const string response = "hello, world"; + + var testContext = new TestServiceContext(); + + var callOrder = new Stack(); + var onCompletedTcs = new TaskCompletionSource(); + + using (var server = new TestServer(async context => + { + context.Response.OnCompleted(_ => + { + callOrder.Push(1); + onCompletedTcs.SetResult(null); + return TaskCache.CompletedTask; + }, null); + context.Response.OnCompleted(_ => + { + callOrder.Push(2); + return TaskCache.CompletedTask; + }, null); + + context.Response.ContentLength = response.Length; + await context.Response.WriteAsync(response); + }, testContext, listenOptions)) + { + using (var connection = server.CreateConnection()) + { + await connection.Send( + "GET / HTTP/1.1", + "", + ""); + await connection.ReceiveEnd( + "HTTP/1.1 200 OK", + $"Date: {testContext.DateHeaderValue}", + $"Content-Length: {response.Length}", + "", + "hello, world"); + + // Wait for all callbacks to be called. + await onCompletedTcs.Task.TimeoutAfter(TimeSpan.FromSeconds(10)); + } + } + + Assert.Equal(1, callOrder.Pop()); + Assert.Equal(2, callOrder.Pop()); + } + public static TheoryData NullHeaderData { get diff --git a/test/shared/TestServer.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/TestServer.cs similarity index 73% rename from test/shared/TestServer.cs rename to test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/TestServer.cs index f9224babdb..42bfa542ab 100644 --- a/test/shared/TestServer.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/TestServer.cs @@ -8,8 +8,10 @@ using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal; using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal; +using Microsoft.AspNetCore.Testing; -namespace Microsoft.AspNetCore.Testing +namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { /// /// Summary description for TestServer @@ -44,11 +46,21 @@ namespace Microsoft.AspNetCore.Testing _listenOptions = listenOptions; Context = context; - Context.TransportContext.ConnectionHandler = new ConnectionHandler(listenOptions, Context, new DummyApplication(app, httpContextFactory)); + TransportContext = new LibuvTransportContext() + { + AppLifetime = new LifetimeNotImplemented(), + ConnectionHandler = new ConnectionHandler(listenOptions, Context, new DummyApplication(app, httpContextFactory)), + Log = new LibuvTrace(new TestApplicationErrorLogger()), + Options = new LibuvTransportOptions() + { + ThreadCount = 1, + ShutdownTimeout = TimeSpan.FromSeconds(5) + } + }; try { - _transport = new LibuvTransport(context.TransportContext, _listenOptions); + _transport = new LibuvTransport(TransportContext, _listenOptions); _transport.BindAsync().Wait(); } catch @@ -64,6 +76,7 @@ namespace Microsoft.AspNetCore.Testing public AddressFamily AddressFamily => _listenOptions.IPEndPoint.AddressFamily; public TestServiceContext Context { get; } + public LibuvTransportContext TransportContext { get; } public TestConnection CreateConnection() { diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Microsoft.AspNetCore.Server.Kestrel.Performance.csproj b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Microsoft.AspNetCore.Server.Kestrel.Performance.csproj index ec86613394..f75a837b72 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Microsoft.AspNetCore.Server.Kestrel.Performance.csproj +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Microsoft.AspNetCore.Server.Kestrel.Performance.csproj @@ -20,7 +20,6 @@ - diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Tests/Microsoft.AspNetCore.Server.Kestrel.Tests.csproj b/test/Microsoft.AspNetCore.Server.Kestrel.Tests/Microsoft.AspNetCore.Server.Kestrel.Tests.csproj new file mode 100644 index 0000000000..a453a89214 --- /dev/null +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Tests/Microsoft.AspNetCore.Server.Kestrel.Tests.csproj @@ -0,0 +1,31 @@ + + + + + + netcoreapp2.0;net46 + netcoreapp2.0 + x64 + true + true + + + + + + + + + + + + + + + + + + + + + diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/WebHostBuilderKestrelExtensionsTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Tests/WebHostBuilderKestrelExtensionsTests.cs similarity index 96% rename from test/Microsoft.AspNetCore.Server.KestrelTests/WebHostBuilderKestrelExtensionsTests.cs rename to test/Microsoft.AspNetCore.Server.Kestrel.Tests/WebHostBuilderKestrelExtensionsTests.cs index 6e88011a92..fc5d6509ae 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/WebHostBuilderKestrelExtensionsTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Tests/WebHostBuilderKestrelExtensionsTests.cs @@ -6,7 +6,7 @@ using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.Extensions.DependencyInjection; using Xunit; -namespace Microsoft.AspNetCore.Server.KestrelTests +namespace Microsoft.AspNetCore.Server.Kestrel.Tests { public class WebHostBuilderKestrelExtensionsTests { diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Tests/xunit.runner.json b/test/Microsoft.AspNetCore.Server.Kestrel.Tests/xunit.runner.json new file mode 100644 index 0000000000..c76780941f --- /dev/null +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Tests/xunit.runner.json @@ -0,0 +1,5 @@ +{ + "$schema": "http://json.schemastore.org/xunit.runner.schema", + "methodDisplay": "method", + "longRunningTestSeconds": 60 +} diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs deleted file mode 100644 index 81a14ee9a1..0000000000 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs +++ /dev/null @@ -1,1431 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Net; -using System.Net.Sockets; -using System.Text; -using System.Threading; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Http.Features; -using Microsoft.AspNetCore.Server.Kestrel.Core; -using Microsoft.AspNetCore.Server.Kestrel.Core.Internal; -using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; -using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv; -using Microsoft.AspNetCore.Testing; -using Microsoft.Extensions.Internal; -using Xunit; - -namespace Microsoft.AspNetCore.Server.KestrelTests -{ - /// - /// Summary description for EngineTests - /// - public class EngineTests - { - public static TheoryData ConnectionAdapterData => new TheoryData - { - new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0)), - new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0)) - { - ConnectionAdapters = { new PassThroughConnectionAdapter() } - } - }; - - [Fact] - public async Task TransportCanStartAndStop() - { - var serviceContext = new TestServiceContext(); - - // The transport can no longer start threads without binding to an endpoint. - var transport = new LibuvTransport(serviceContext.TransportContext, - new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0))); - - await transport.BindAsync(); - await transport.StopAsync(); - } - - [Theory] - [MemberData(nameof(ConnectionAdapterData))] - public async Task ListenerCanCreateAndDispose(ListenOptions listenOptions) - { - var testContext = new TestServiceContext(); - testContext.TransportContext.ConnectionHandler = new ConnectionHandler(listenOptions, testContext, new DummyApplication(TestApp.EchoApp)); - var transport = new LibuvTransport(testContext.TransportContext, listenOptions); - - await transport.BindAsync(); - await transport.UnbindAsync(); - await transport.StopAsync(); - } - - [Theory] - [MemberData(nameof(ConnectionAdapterData))] - public async Task ConnectionCanReadAndWrite(ListenOptions listenOptions) - { - var testContext = new TestServiceContext(); - testContext.TransportContext.ConnectionHandler = new ConnectionHandler(listenOptions, testContext, new DummyApplication(TestApp.EchoApp)); - var transport = new LibuvTransport(testContext.TransportContext, listenOptions); - - await transport.BindAsync(); - - var socket = TestConnection.CreateConnectedLoopbackSocket(listenOptions.IPEndPoint.Port); - var data = "Hello World"; - socket.Send(Encoding.ASCII.GetBytes($"POST / HTTP/1.0\r\nContent-Length: 11\r\n\r\n{data}")); - var buffer = new byte[data.Length]; - var read = 0; - while (read < data.Length) - { - read += socket.Receive(buffer, read, buffer.Length - read, SocketFlags.None); - } - socket.Dispose(); - - await transport.UnbindAsync(); - await transport.StopAsync(); - } - - [Theory] - [MemberData(nameof(ConnectionAdapterData))] - public async Task Http10RequestReceivesHttp11Response(ListenOptions listenOptions) - { - var testContext = new TestServiceContext(); - - using (var server = new TestServer(TestApp.EchoApp, testContext, listenOptions)) - { - using (var connection = server.CreateConnection()) - { - await connection.Send( - "POST / HTTP/1.0", - "Content-Length: 11", - "", - "Hello World"); - await connection.ReceiveEnd( - "HTTP/1.1 200 OK", - "Connection: close", - $"Date: {testContext.DateHeaderValue}", - "", - "Hello World"); - } - } - } - - [Theory] - [MemberData(nameof(ConnectionAdapterData))] - public async Task Http11(ListenOptions listenOptions) - { - var testContext = new TestServiceContext(); - - using (var server = new TestServer(TestApp.EchoAppChunked, testContext, listenOptions)) - { - using (var connection = server.CreateConnection()) - { - await connection.Send( - "GET / HTTP/1.1", - "", - "GET / HTTP/1.1", - "Connection: close", - "Content-Length: 7", - "", - "Goodbye"); - await connection.ReceiveEnd( - "HTTP/1.1 200 OK", - $"Date: {testContext.DateHeaderValue}", - "Content-Length: 0", - "", - "HTTP/1.1 200 OK", - "Connection: close", - $"Date: {testContext.DateHeaderValue}", - "Content-Length: 7", - "", - "Goodbye"); - } - } - } - - [Theory] - [MemberData(nameof(ConnectionAdapterData))] - public async Task HeadersAndStreamsAreReused(ListenOptions listenOptions) - { - var testContext = new TestServiceContext(); - var streamCount = 0; - var requestHeadersCount = 0; - var responseHeadersCount = 0; - var loopCount = 20; - Stream lastStream = null; - IHeaderDictionary lastRequestHeaders = null; - IHeaderDictionary lastResponseHeaders = null; - - using (var server = new TestServer( - async context => - { - if (context.Request.Body != lastStream) - { - lastStream = context.Request.Body; - streamCount++; - } - if (context.Request.Headers != lastRequestHeaders) - { - lastRequestHeaders = context.Request.Headers; - requestHeadersCount++; - } - if (context.Response.Headers != lastResponseHeaders) - { - lastResponseHeaders = context.Response.Headers; - responseHeadersCount++; - } - - var ms = new MemoryStream(); - await context.Request.Body.CopyToAsync(ms); - var request = ms.ToArray(); - - context.Response.ContentLength = request.Length; - - await context.Response.Body.WriteAsync(request, 0, request.Length); - }, - testContext)) - { - - using (var connection = server.CreateConnection()) - { - var requestData = - Enumerable.Repeat("GET / HTTP/1.1\r\n", loopCount) - .Concat(new[] { "GET / HTTP/1.1\r\nContent-Length: 7\r\nConnection: close\r\n\r\nGoodbye" }); - - var response = string.Join("\r\n", new string[] { - "HTTP/1.1 200 OK", - $"Date: {testContext.DateHeaderValue}", - "Content-Length: 0", - ""}); - - var lastResponse = string.Join("\r\n", new string[] - { - "HTTP/1.1 200 OK", - "Connection: close", - $"Date: {testContext.DateHeaderValue}", - "Content-Length: 7", - "", - "Goodbye" - }); - - var responseData = - Enumerable.Repeat(response, loopCount) - .Concat(new[] { lastResponse }); - - await connection.Send(requestData.ToArray()); - - await connection.ReceiveEnd(responseData.ToArray()); - } - - Assert.Equal(1, streamCount); - Assert.Equal(1, requestHeadersCount); - Assert.Equal(1, responseHeadersCount); - } - } - - [Theory] - [MemberData(nameof(ConnectionAdapterData))] - public async Task Http10ContentLength(ListenOptions listenOptions) - { - var testContext = new TestServiceContext(); - - using (var server = new TestServer(TestApp.EchoApp, testContext, listenOptions)) - { - using (var connection = server.CreateConnection()) - { - await connection.Send( - "POST / HTTP/1.0", - "Content-Length: 11", - "", - "Hello World"); - await connection.ReceiveEnd( - "HTTP/1.1 200 OK", - "Connection: close", - $"Date: {testContext.DateHeaderValue}", - "", - "Hello World"); - } - } - } - - [Theory] - [MemberData(nameof(ConnectionAdapterData))] - public async Task Http10KeepAlive(ListenOptions listenOptions) - { - var testContext = new TestServiceContext(); - - using (var server = new TestServer(TestApp.EchoAppChunked, testContext, listenOptions)) - { - using (var connection = server.CreateConnection()) - { - await connection.Send( - "GET / HTTP/1.0", - "Connection: keep-alive", - "", - "POST / HTTP/1.0", - "Content-Length: 7", - "", - "Goodbye"); - await connection.Receive( - "HTTP/1.1 200 OK", - "Connection: keep-alive", - $"Date: {testContext.DateHeaderValue}", - "Content-Length: 0", - "\r\n"); - await connection.ReceiveEnd( - "HTTP/1.1 200 OK", - "Connection: close", - $"Date: {testContext.DateHeaderValue}", - "Content-Length: 7", - "", - "Goodbye"); - } - } - } - - [Theory] - [MemberData(nameof(ConnectionAdapterData))] - public async Task Http10KeepAliveNotUsedIfResponseContentLengthNotSet(ListenOptions listenOptions) - { - var testContext = new TestServiceContext(); - - using (var server = new TestServer(TestApp.EchoApp, testContext, listenOptions)) - { - using (var connection = server.CreateConnection()) - { - await connection.Send( - "GET / HTTP/1.0", - "Connection: keep-alive", - "", - "POST / HTTP/1.0", - "Connection: keep-alive", - "Content-Length: 7", - "", - "Goodbye"); - await connection.Receive( - "HTTP/1.1 200 OK", - "Connection: keep-alive", - $"Date: {testContext.DateHeaderValue}", - "Content-Length: 0", - "\r\n"); - await connection.ReceiveEnd( - "HTTP/1.1 200 OK", - "Connection: close", - $"Date: {testContext.DateHeaderValue}", - "", - "Goodbye"); - } - } - } - - [Theory] - [MemberData(nameof(ConnectionAdapterData))] - public async Task Http10KeepAliveContentLength(ListenOptions listenOptions) - { - var testContext = new TestServiceContext(); - - using (var server = new TestServer(TestApp.EchoAppChunked, testContext, listenOptions)) - { - using (var connection = server.CreateConnection()) - { - await connection.Send( - "POST / HTTP/1.0", - "Content-Length: 11", - "Connection: keep-alive", - "", - "Hello WorldPOST / HTTP/1.0", - "Content-Length: 7", - "", - "Goodbye"); - await connection.Receive( - "HTTP/1.1 200 OK", - "Connection: keep-alive", - $"Date: {testContext.DateHeaderValue}", - "Content-Length: 11", - "", - "Hello World"); - await connection.ReceiveEnd( - "HTTP/1.1 200 OK", - "Connection: close", - $"Date: {testContext.DateHeaderValue}", - "Content-Length: 7", - "", - "Goodbye"); - } - } - } - - [Theory] - [MemberData(nameof(ConnectionAdapterData))] - public async Task Expect100ContinueForBody(ListenOptions listenOptions) - { - var testContext = new TestServiceContext(); - - using (var server = new TestServer(TestApp.EchoAppChunked, testContext, listenOptions)) - { - using (var connection = server.CreateConnection()) - { - await connection.Send( - "POST / HTTP/1.1", - "Expect: 100-continue", - "Connection: close", - "Content-Length: 11", - "\r\n"); - await connection.Receive( - "HTTP/1.1 100 Continue", - "", - ""); - await connection.Send("Hello World"); - await connection.Receive( - "HTTP/1.1 200 OK", - "Connection: close", - $"Date: {testContext.DateHeaderValue}", - "Content-Length: 11", - "", - "Hello World"); - } - } - } - - [Theory] - [MemberData(nameof(ConnectionAdapterData))] - public async Task DisconnectingClient(ListenOptions listenOptions) - { - var testContext = new TestServiceContext(); - - using (var server = new TestServer(TestApp.EchoApp, testContext, listenOptions)) - { - var socket = TestConnection.CreateConnectedLoopbackSocket(server.Port); - await Task.Delay(200); - socket.Dispose(); - - await Task.Delay(200); - using (var connection = server.CreateConnection()) - { - await connection.Send( - "GET / HTTP/1.0", - "", - ""); - await connection.ReceiveEnd( - "HTTP/1.1 200 OK", - "Connection: close", - $"Date: {testContext.DateHeaderValue}", - "Content-Length: 0", - "", - ""); - } - } - } - - [Theory] - [MemberData(nameof(ConnectionAdapterData))] - public async Task ZeroContentLengthSetAutomaticallyAfterNoWrites(ListenOptions listenOptions) - { - var testContext = new TestServiceContext(); - - using (var server = new TestServer(TestApp.EmptyApp, testContext, listenOptions)) - { - using (var connection = server.CreateConnection()) - { - await connection.Send( - "GET / HTTP/1.1", - "", - "GET / HTTP/1.0", - "Connection: keep-alive", - "", - ""); - await connection.ReceiveEnd( - "HTTP/1.1 200 OK", - $"Date: {testContext.DateHeaderValue}", - "Content-Length: 0", - "", - "HTTP/1.1 200 OK", - "Connection: keep-alive", - $"Date: {testContext.DateHeaderValue}", - "Content-Length: 0", - "", - ""); - } - } - } - - [Theory] - [MemberData(nameof(ConnectionAdapterData))] - public async Task ZeroContentLengthSetAutomaticallyForNonKeepAliveRequests(ListenOptions listenOptions) - { - var testContext = new TestServiceContext(); - - using (var server = new TestServer(async httpContext => - { - Assert.Equal(0, await httpContext.Request.Body.ReadAsync(new byte[1], 0, 1).TimeoutAfter(TimeSpan.FromSeconds(10))); - }, testContext, listenOptions)) - { - using (var connection = server.CreateConnection()) - { - await connection.Send( - "GET / HTTP/1.1", - "Connection: close", - "", - ""); - await connection.ReceiveEnd( - "HTTP/1.1 200 OK", - "Connection: close", - $"Date: {testContext.DateHeaderValue}", - "Content-Length: 0", - "", - ""); - } - - using (var connection = server.CreateConnection()) - { - await connection.Send( - "GET / HTTP/1.0", - "", - ""); - await connection.ReceiveEnd( - "HTTP/1.1 200 OK", - "Connection: close", - $"Date: {testContext.DateHeaderValue}", - "Content-Length: 0", - "", - ""); - } - } - } - - [Theory] - [MemberData(nameof(ConnectionAdapterData))] - public async Task ZeroContentLengthNotSetAutomaticallyForHeadRequests(ListenOptions listenOptions) - { - var testContext = new TestServiceContext(); - - using (var server = new TestServer(TestApp.EmptyApp, testContext, listenOptions)) - { - using (var connection = server.CreateConnection()) - { - await connection.Send( - "HEAD / HTTP/1.1", - "", - ""); - await connection.ReceiveEnd( - "HTTP/1.1 200 OK", - $"Date: {testContext.DateHeaderValue}", - "", - ""); - } - } - } - - [Theory] - [MemberData(nameof(ConnectionAdapterData))] - public async Task ZeroContentLengthNotSetAutomaticallyForCertainStatusCodes(ListenOptions listenOptions) - { - var testContext = new TestServiceContext(); - - using (var server = new TestServer(async httpContext => - { - var request = httpContext.Request; - var response = httpContext.Response; - - using (var reader = new StreamReader(request.Body, Encoding.ASCII)) - { - var statusString = await reader.ReadLineAsync(); - response.StatusCode = int.Parse(statusString); - } - }, testContext, listenOptions)) - { - using (var connection = server.CreateConnection()) - { - await connection.Send( - "POST / HTTP/1.1", - "Content-Length: 3", - "", - "204POST / HTTP/1.1", - "Content-Length: 3", - "", - "205POST / HTTP/1.1", - "Content-Length: 3", - "", - "304POST / HTTP/1.1", - "Content-Length: 3", - "", - "200"); - await connection.ReceiveEnd( - "HTTP/1.1 204 No Content", - $"Date: {testContext.DateHeaderValue}", - "", - "HTTP/1.1 205 Reset Content", - $"Date: {testContext.DateHeaderValue}", - "", - "HTTP/1.1 304 Not Modified", - $"Date: {testContext.DateHeaderValue}", - "", - "HTTP/1.1 200 OK", - $"Date: {testContext.DateHeaderValue}", - "Content-Length: 0", - "", - ""); - } - } - } - - [Theory] - [MemberData(nameof(ConnectionAdapterData))] - public async Task ZeroContentLengthAssumedOnNonKeepAliveRequestsWithoutContentLengthOrTransferEncodingHeader(ListenOptions listenOptions) - { - var testContext = new TestServiceContext(); - - using (var server = new TestServer(async httpContext => - { - // This will hang if 0 content length is not assumed by the server - Assert.Equal(0, await httpContext.Request.Body.ReadAsync(new byte[1], 0, 1).TimeoutAfter(TimeSpan.FromSeconds(10))); - }, testContext, listenOptions)) - { - using (var connection = server.CreateConnection()) - { - // Use Send instead of SendEnd to ensure the connection will remain open while - // the app runs and reads 0 bytes from the body nonetheless. This checks that - // https://github.com/aspnet/KestrelHttpServer/issues/1104 is not regressing. - await connection.Send( - "GET / HTTP/1.1", - "Connection: close", - "", - ""); - await connection.ReceiveForcedEnd( - "HTTP/1.1 200 OK", - "Connection: close", - $"Date: {testContext.DateHeaderValue}", - "Content-Length: 0", - "", - ""); - } - - using (var connection = server.CreateConnection()) - { - await connection.Send( - "GET / HTTP/1.0", - "", - ""); - await connection.ReceiveForcedEnd( - "HTTP/1.1 200 OK", - "Connection: close", - $"Date: {testContext.DateHeaderValue}", - "Content-Length: 0", - "", - ""); - } - } - } - - [Theory] - [MemberData(nameof(ConnectionAdapterData))] - public async Task ConnectionClosedAfter101Response(ListenOptions listenOptions) - { - var testContext = new TestServiceContext(); - - using (var server = new TestServer(async httpContext => - { - var request = httpContext.Request; - var stream = await httpContext.Features.Get().UpgradeAsync(); - var response = Encoding.ASCII.GetBytes("hello, world"); - await stream.WriteAsync(response, 0, response.Length); - }, testContext, listenOptions)) - { - using (var connection = server.CreateConnection()) - { - await connection.Send( - "GET / HTTP/1.1", - "", - ""); - await connection.ReceiveForcedEnd( - "HTTP/1.1 101 Switching Protocols", - "Connection: Upgrade", - $"Date: {testContext.DateHeaderValue}", - "", - "hello, world"); - } - - using (var connection = server.CreateConnection()) - { - await connection.Send( - "GET / HTTP/1.0", - "Connection: keep-alive", - "", - ""); - await connection.ReceiveForcedEnd( - "HTTP/1.1 101 Switching Protocols", - "Connection: Upgrade", - $"Date: {testContext.DateHeaderValue}", - "", - "hello, world"); - } - } - } - - [Theory] - [MemberData(nameof(ConnectionAdapterData))] - public async Task ThrowingResultsIn500Response(ListenOptions listenOptions) - { - var testContext = new TestServiceContext(); - - bool onStartingCalled = false; - - var testLogger = new TestApplicationErrorLogger(); - testContext.Log = new KestrelTrace(testLogger); - - using (var server = new TestServer(httpContext => - { - var response = httpContext.Response; - response.OnStarting(_ => - { - onStartingCalled = true; - return TaskCache.CompletedTask; - }, null); - - // Anything added to the ResponseHeaders dictionary is ignored - response.Headers["Content-Length"] = "11"; - throw new Exception(); - }, testContext, listenOptions)) - { - using (var connection = server.CreateConnection()) - { - await connection.Send( - "GET / HTTP/1.1", - "", - "GET / HTTP/1.1", - "Connection: close", - "", - ""); - await connection.ReceiveForcedEnd( - "HTTP/1.1 500 Internal Server Error", - $"Date: {testContext.DateHeaderValue}", - "Content-Length: 0", - "", - "HTTP/1.1 500 Internal Server Error", - "Connection: close", - $"Date: {testContext.DateHeaderValue}", - "Content-Length: 0", - "", - ""); - } - } - - Assert.False(onStartingCalled); - Assert.Equal(2, testLogger.ApplicationErrorsLogged); - } - - [Theory] - [MemberData(nameof(ConnectionAdapterData))] - public async Task ThrowingAfterWritingKillsConnection(ListenOptions listenOptions) - { - var testContext = new TestServiceContext(); - - bool onStartingCalled = false; - - var testLogger = new TestApplicationErrorLogger(); - testContext.Log = new KestrelTrace(testLogger); - - using (var server = new TestServer(async httpContext => - { - var response = httpContext.Response; - response.OnStarting(_ => - { - onStartingCalled = true; - return Task.FromResult(null); - }, null); - - response.Headers["Content-Length"] = new[] { "11" }; - await response.Body.WriteAsync(Encoding.ASCII.GetBytes("Hello World"), 0, 11); - throw new Exception(); - }, testContext, listenOptions)) - { - using (var connection = server.CreateConnection()) - { - await connection.Send( - "GET / HTTP/1.1", - "", - ""); - await connection.ReceiveForcedEnd( - "HTTP/1.1 200 OK", - $"Date: {testContext.DateHeaderValue}", - "Content-Length: 11", - "", - "Hello World"); - } - } - - Assert.True(onStartingCalled); - Assert.Equal(1, testLogger.ApplicationErrorsLogged); - } - - [Theory] - [MemberData(nameof(ConnectionAdapterData))] - public async Task ThrowingAfterPartialWriteKillsConnection(ListenOptions listenOptions) - { - var testContext = new TestServiceContext(); - - bool onStartingCalled = false; - - var testLogger = new TestApplicationErrorLogger(); - testContext.Log = new KestrelTrace(testLogger); - - using (var server = new TestServer(async httpContext => - { - var response = httpContext.Response; - response.OnStarting(_ => - { - onStartingCalled = true; - return Task.FromResult(null); - }, null); - - response.Headers["Content-Length"] = new[] { "11" }; - await response.Body.WriteAsync(Encoding.ASCII.GetBytes("Hello"), 0, 5); - throw new Exception(); - }, testContext, listenOptions)) - { - using (var connection = server.CreateConnection()) - { - await connection.Send( - "GET / HTTP/1.1", - "", - ""); - await connection.ReceiveForcedEnd( - "HTTP/1.1 200 OK", - $"Date: {testContext.DateHeaderValue}", - "Content-Length: 11", - "", - "Hello"); - } - } - - Assert.True(onStartingCalled); - Assert.Equal(1, testLogger.ApplicationErrorsLogged); - } - - [MemberData(nameof(ConnectionAdapterData))] - public async Task ConnectionClosesWhenFinReceivedBeforeRequestCompletes(ListenOptions listenOptions) - { - var testContext = new TestServiceContext(); - - using (var server = new TestServer(TestApp.EchoAppChunked, testContext, listenOptions)) - { - using (var connection = server.CreateConnection()) - { - await connection.Send( - "GET / HTTP/1.1", - "", - "POST / HTTP/1.1"); - connection.Shutdown(SocketShutdown.Send); - await connection.ReceiveForcedEnd( - "HTTP/1.1 200 OK", - $"Date: {testContext.DateHeaderValue}", - "Content-Length: 0", - "", - "HTTP/1.1 400 Bad Request", - "Connection: close", - $"Date: {testContext.DateHeaderValue}", - "Content-Length: 0", - "", - ""); - } - - using (var connection = server.CreateConnection()) - { - await connection.Send( - "GET / HTTP/1.1", - "", - "POST / HTTP/1.1", - "Content-Length: 7"); - connection.Shutdown(SocketShutdown.Send); - await connection.ReceiveForcedEnd( - "HTTP/1.1 200 OK", - $"Date: {testContext.DateHeaderValue}", - "Content-Length: 0", - "", - "HTTP/1.1 400 Bad Request", - "Connection: close", - $"Date: {testContext.DateHeaderValue}", - "Content-Length: 0", - "", - ""); - } - } - } - - [Theory] - [MemberData(nameof(ConnectionAdapterData))] - public async Task ThrowingInOnStartingResultsInFailedWritesAnd500Response(ListenOptions listenOptions) - { - var callback1Called = false; - var callback2CallCount = 0; - - var testContext = new TestServiceContext(); - var testLogger = new TestApplicationErrorLogger(); - testContext.Log = new KestrelTrace(testLogger); - - using (var server = new TestServer(async httpContext => - { - var onStartingException = new Exception(); - - var response = httpContext.Response; - response.OnStarting(_ => - { - callback1Called = true; - throw onStartingException; - }, null); - response.OnStarting(_ => - { - callback2CallCount++; - throw onStartingException; - }, null); - - var writeException = await Assert.ThrowsAsync(async () => await response.Body.FlushAsync()); - Assert.Same(onStartingException, writeException.InnerException); - }, testContext, listenOptions)) - { - using (var connection = server.CreateConnection()) - { - await connection.Send( - "GET / HTTP/1.1", - "", - "GET / HTTP/1.1", - "", - ""); - await connection.ReceiveEnd( - "HTTP/1.1 500 Internal Server Error", - $"Date: {testContext.DateHeaderValue}", - "Content-Length: 0", - "", - "HTTP/1.1 500 Internal Server Error", - $"Date: {testContext.DateHeaderValue}", - "Content-Length: 0", - "", - ""); - } - } - - // The first registered OnStarting callback should have been called, - // since they are called LIFO order and the other one failed. - Assert.False(callback1Called); - Assert.Equal(2, callback2CallCount); - Assert.Equal(2, testLogger.ApplicationErrorsLogged); - } - - [Theory] - [MemberData(nameof(ConnectionAdapterData))] - public async Task ThrowingInOnCompletedIsLoggedAndClosesConnection(ListenOptions listenOptions) - { - var testContext = new TestServiceContext(); - - var onCompletedCalled1 = false; - var onCompletedCalled2 = false; - - var testLogger = new TestApplicationErrorLogger(); - testContext.Log = new KestrelTrace(testLogger); - - using (var server = new TestServer(async httpContext => - { - var response = httpContext.Response; - response.OnCompleted(_ => - { - onCompletedCalled1 = true; - throw new Exception(); - }, null); - response.OnCompleted(_ => - { - onCompletedCalled2 = true; - throw new Exception(); - }, null); - - response.Headers["Content-Length"] = new[] { "11" }; - - await response.Body.WriteAsync(Encoding.ASCII.GetBytes("Hello World"), 0, 11); - }, testContext, listenOptions)) - { - using (var connection = server.CreateConnection()) - { - await connection.Send( - "GET / HTTP/1.1", - "", - ""); - await connection.ReceiveForcedEnd( - "HTTP/1.1 200 OK", - $"Date: {testContext.DateHeaderValue}", - "Content-Length: 11", - "", - "Hello World"); - } - } - - // All OnCompleted callbacks should be called even if they throw. - Assert.Equal(2, testLogger.ApplicationErrorsLogged); - Assert.True(onCompletedCalled1); - Assert.True(onCompletedCalled2); - } - - [Theory] - [MemberData(nameof(ConnectionAdapterData))] - public async Task RequestsCanBeAbortedMidRead(ListenOptions listenOptions) - { - var testContext = new TestServiceContext(); - - var readTcs = new TaskCompletionSource(); - var registrationTcs = new TaskCompletionSource(); - var requestId = 0; - - using (var server = new TestServer(async httpContext => - { - requestId++; - - var response = httpContext.Response; - var request = httpContext.Request; - var lifetime = httpContext.Features.Get(); - - lifetime.RequestAborted.Register(() => registrationTcs.TrySetResult(requestId)); - - if (requestId == 1) - { - response.Headers["Content-Length"] = new[] { "5" }; - - await response.WriteAsync("World"); - } - else - { - var readTask = request.Body.CopyToAsync(Stream.Null); - - lifetime.Abort(); - - try - { - await readTask; - } - catch (Exception ex) - { - readTcs.SetException(ex); - throw; - } - - readTcs.SetException(new Exception("This shouldn't be reached.")); - } - }, testContext, listenOptions)) - { - using (var connection = server.CreateConnection()) - { - // Never send the body so CopyToAsync always fails. - await connection.Send( - "POST / HTTP/1.1", - "Content-Length: 5", - "", - "HelloPOST / HTTP/1.1", - "Content-Length: 5", - "", - ""); - - await connection.ReceiveForcedEnd( - "HTTP/1.1 200 OK", - $"Date: {testContext.DateHeaderValue}", - "Content-Length: 5", - "", - "World"); - } - } - - await Assert.ThrowsAsync(async () => await readTcs.Task); - - // The cancellation token for only the last request should be triggered. - var abortedRequestId = await registrationTcs.Task; - Assert.Equal(2, abortedRequestId); - } - - [MemberData(nameof(ConnectionAdapterData))] - public async Task FailedWritesResultInAbortedRequest(ListenOptions listenOptions) - { - var testContext = new TestServiceContext(); - - // This should match _maxBytesPreCompleted in SocketOutput - var maxBytesPreCompleted = 65536; - // Ensure string is long enough to disable write-behind buffering - var largeString = new string('a', maxBytesPreCompleted + 1); - - var writeTcs = new TaskCompletionSource(); - var registrationWh = new ManualResetEventSlim(); - var connectionCloseWh = new ManualResetEventSlim(); - - using (var server = new TestServer(async httpContext => - { - var response = httpContext.Response; - var request = httpContext.Request; - var lifetime = httpContext.Features.Get(); - - lifetime.RequestAborted.Register(() => registrationWh.Set()); - - await request.Body.CopyToAsync(Stream.Null); - connectionCloseWh.Wait(); - - try - { - // Ensure write is long enough to disable write-behind buffering - for (int i = 0; i < 100; i++) - { - await response.WriteAsync(largeString, lifetime.RequestAborted); - registrationWh.Wait(1000); - } - } - catch (Exception ex) - { - writeTcs.SetException(ex); - throw; - } - - writeTcs.SetException(new Exception("This shouldn't be reached.")); - }, testContext, listenOptions)) - { - using (var connection = server.CreateConnection()) - { - await connection.Send( - "POST / HTTP/1.1", - "Content-Length: 5", - "", - "Hello"); - // Don't wait to receive the response. Just close the socket. - } - - connectionCloseWh.Set(); - - // Write failed - await Assert.ThrowsAsync(async () => await writeTcs.Task); - // RequestAborted tripped - Assert.True(registrationWh.Wait(1000)); - } - } - - [Theory] - [MemberData(nameof(ConnectionAdapterData))] - public async Task NoErrorsLoggedWhenServerEndsConnectionBeforeClient(ListenOptions listenOptions) - { - var testContext = new TestServiceContext(); - - var testLogger = new TestApplicationErrorLogger(); - testContext.Log = new KestrelTrace(testLogger); - - using (var server = new TestServer(async httpContext => - { - var response = httpContext.Response; - response.Headers["Content-Length"] = new[] { "11" }; - await response.Body.WriteAsync(Encoding.ASCII.GetBytes("Hello World"), 0, 11); - }, testContext, listenOptions)) - { - using (var connection = server.CreateConnection()) - { - await connection.Send( - "GET / HTTP/1.0", - "", - ""); - await connection.ReceiveForcedEnd( - "HTTP/1.1 200 OK", - "Connection: close", - $"Date: {testContext.DateHeaderValue}", - "Content-Length: 11", - "", - "Hello World"); - } - } - - Assert.Equal(0, testLogger.TotalErrorsLogged); - } - - [Theory] - [MemberData(nameof(ConnectionAdapterData))] - public async Task NoResponseSentWhenConnectionIsClosedByServerBeforeClientFinishesSendingRequest(ListenOptions listenOptions) - { - var testContext = new TestServiceContext(); - - using (var server = new TestServer(httpContext => - { - httpContext.Abort(); - return TaskCache.CompletedTask; - }, testContext, listenOptions)) - { - using (var connection = server.CreateConnection()) - { - await connection.Send( - "POST / HTTP/1.0", - "Content-Length: 1", - "", - ""); - await connection.ReceiveForcedEnd(); - } - } - } - - [Theory] - [MemberData(nameof(ConnectionAdapterData))] - public async Task RequestHeadersAreResetOnEachRequest(ListenOptions listenOptions) - { - var testContext = new TestServiceContext(); - - IHeaderDictionary originalRequestHeaders = null; - var firstRequest = true; - - using (var server = new TestServer(httpContext => - { - var requestFeature = httpContext.Features.Get(); - - if (firstRequest) - { - originalRequestHeaders = requestFeature.Headers; - requestFeature.Headers = new FrameRequestHeaders(); - firstRequest = false; - } - else - { - Assert.Same(originalRequestHeaders, requestFeature.Headers); - } - - return TaskCache.CompletedTask; - }, testContext, listenOptions)) - { - using (var connection = server.CreateConnection()) - { - await connection.Send( - "GET / HTTP/1.1", - "", - "GET / HTTP/1.1", - "", - ""); - await connection.ReceiveEnd( - "HTTP/1.1 200 OK", - $"Date: {testContext.DateHeaderValue}", - "Content-Length: 0", - "", - "HTTP/1.1 200 OK", - $"Date: {testContext.DateHeaderValue}", - "Content-Length: 0", - "", - ""); - } - } - } - - [Theory] - [MemberData(nameof(ConnectionAdapterData))] - public async Task ResponseHeadersAreResetOnEachRequest(ListenOptions listenOptions) - { - var testContext = new TestServiceContext(); - - IHeaderDictionary originalResponseHeaders = null; - var firstRequest = true; - - using (var server = new TestServer(httpContext => - { - var responseFeature = httpContext.Features.Get(); - - if (firstRequest) - { - originalResponseHeaders = responseFeature.Headers; - responseFeature.Headers = new FrameResponseHeaders(); - firstRequest = false; - } - else - { - Assert.Same(originalResponseHeaders, responseFeature.Headers); - } - - return TaskCache.CompletedTask; - }, testContext, listenOptions)) - { - using (var connection = server.CreateConnection()) - { - await connection.Send( - "GET / HTTP/1.1", - "", - "GET / HTTP/1.1", - "", - ""); - await connection.ReceiveEnd( - "HTTP/1.1 200 OK", - $"Date: {testContext.DateHeaderValue}", - "Content-Length: 0", - "", - "HTTP/1.1 200 OK", - $"Date: {testContext.DateHeaderValue}", - "Content-Length: 0", - "", - ""); - } - } - } - - [Theory] - [InlineData("/%%2000", "/% 00")] - [InlineData("/%25%30%30", "/%00")] - public async Task PathEscapeTests(string inputPath, string expectedPath) - { - using (var server = new TestServer(async httpContext => - { - var path = httpContext.Request.Path.Value; - httpContext.Response.Headers["Content-Length"] = new[] { path.Length.ToString() }; - await httpContext.Response.WriteAsync(path); - })) - { - using (var connection = server.CreateConnection()) - { - await connection.Send( - $"GET {inputPath} HTTP/1.1", - "", - ""); - await connection.ReceiveEnd( - "HTTP/1.1 200 OK", - $"Date: {server.Context.DateHeaderValue}", - $"Content-Length: {expectedPath.Length.ToString()}", - "", - $"{expectedPath}"); - } - } - } - - [Theory] - [MemberData(nameof(ConnectionAdapterData))] - public async Task OnStartingCallbacksAreCalledInLastInFirstOutOrder(ListenOptions listenOptions) - { - const string response = "hello, world"; - - var testContext = new TestServiceContext(); - - var callOrder = new Stack(); - var onStartingTcs = new TaskCompletionSource(); - - using (var server = new TestServer(async context => - { - context.Response.OnStarting(_ => - { - callOrder.Push(1); - onStartingTcs.SetResult(null); - return TaskCache.CompletedTask; - }, null); - context.Response.OnStarting(_ => - { - callOrder.Push(2); - return TaskCache.CompletedTask; - }, null); - - context.Response.ContentLength = response.Length; - await context.Response.WriteAsync(response); - }, testContext, listenOptions)) - { - using (var connection = server.CreateConnection()) - { - await connection.Send( - "GET / HTTP/1.1", - "", - ""); - await connection.ReceiveEnd( - "HTTP/1.1 200 OK", - $"Date: {testContext.DateHeaderValue}", - $"Content-Length: {response.Length}", - "", - "hello, world"); - - // Wait for all callbacks to be called. - await onStartingTcs.Task.TimeoutAfter(TimeSpan.FromSeconds(10)); - } - } - - Assert.Equal(1, callOrder.Pop()); - Assert.Equal(2, callOrder.Pop()); - } - - [Theory] - [MemberData(nameof(ConnectionAdapterData))] - public async Task OnCompletedCallbacksAreCalledInLastInFirstOutOrder(ListenOptions listenOptions) - { - const string response = "hello, world"; - - var testContext = new TestServiceContext(); - - var callOrder = new Stack(); - var onCompletedTcs = new TaskCompletionSource(); - - using (var server = new TestServer(async context => - { - context.Response.OnCompleted(_ => - { - callOrder.Push(1); - onCompletedTcs.SetResult(null); - return TaskCache.CompletedTask; - }, null); - context.Response.OnCompleted(_ => - { - callOrder.Push(2); - return TaskCache.CompletedTask; - }, null); - - context.Response.ContentLength = response.Length; - await context.Response.WriteAsync(response); - }, testContext, listenOptions)) - { - using (var connection = server.CreateConnection()) - { - await connection.Send( - "GET / HTTP/1.1", - "", - ""); - await connection.ReceiveEnd( - "HTTP/1.1 200 OK", - $"Date: {testContext.DateHeaderValue}", - $"Content-Length: {response.Length}", - "", - "hello, world"); - - // Wait for all callbacks to be called. - await onCompletedTcs.Task.TimeoutAfter(TimeSpan.FromSeconds(10)); - } - } - - Assert.Equal(1, callOrder.Pop()); - Assert.Equal(2, callOrder.Pop()); - } - - [Theory] - [MemberData(nameof(ConnectionAdapterData))] - public async Task UpgradeRequestIsNotKeptAliveOrChunked(ListenOptions listenOptions) - { - const string message = "Hello World"; - - var testContext = new TestServiceContext(); - - using (var server = new TestServer(async context => - { - var upgradeFeature = context.Features.Get(); - var duplexStream = await upgradeFeature.UpgradeAsync(); - - var buffer = new byte[message.Length]; - var read = 0; - while (read < message.Length) - { - read += await duplexStream.ReadAsync(buffer, read, buffer.Length - read).TimeoutAfter(TimeSpan.FromSeconds(10)); - } - - await duplexStream.WriteAsync(buffer, 0, read); - }, testContext, listenOptions)) - { - using (var connection = server.CreateConnection()) - { - await connection.Send( - "GET / HTTP/1.1", - "Connection: Upgrade", - "", - message); - await connection.ReceiveForcedEnd( - "HTTP/1.1 101 Switching Protocols", - "Connection: Upgrade", - $"Date: {testContext.DateHeaderValue}", - "", - message); - } - } - } - } -} diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionTests.cs b/test/Microsoft.AspNetCore.Server.Transport.Libuv.Tests/ConnectionTests.cs similarity index 76% rename from test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionTests.cs rename to test/Microsoft.AspNetCore.Server.Transport.Libuv.Tests/ConnectionTests.cs index 0234cd08c2..d9110cba1e 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionTests.cs +++ b/test/Microsoft.AspNetCore.Server.Transport.Libuv.Tests/ConnectionTests.cs @@ -4,14 +4,12 @@ using System; using System.Threading; using System.Threading.Tasks; -using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv; using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal; using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking; -using Microsoft.AspNetCore.Server.KestrelTests.TestHelpers; -using Microsoft.AspNetCore.Testing; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests.TestHelpers; using Xunit; -namespace Microsoft.AspNetCore.Server.KestrelTests +namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests { public class ConnectionTests { @@ -21,10 +19,8 @@ namespace Microsoft.AspNetCore.Server.KestrelTests using (var mockConnectionHandler = new MockConnectionHandler()) { var mockLibuv = new MockLibuv(); - var serviceContext = new TestServiceContext(); - serviceContext.TransportContext.ConnectionHandler = mockConnectionHandler; - - var transport = new LibuvTransport(mockLibuv, serviceContext.TransportContext, null); + var transportContext = new TestLibuvTransportContext() { ConnectionHandler = mockConnectionHandler }; + var transport = new LibuvTransport(mockLibuv, transportContext, null); var thread = new LibuvThread(transport); try @@ -32,11 +28,11 @@ namespace Microsoft.AspNetCore.Server.KestrelTests await thread.StartAsync(); await thread.PostAsync(_ => { - var listenerContext = new ListenerContext(serviceContext.TransportContext) + var listenerContext = new ListenerContext(transportContext) { Thread = thread }; - var socket = new MockSocket(mockLibuv, Thread.CurrentThread.ManagedThreadId, serviceContext.TransportContext.Log); + var socket = new MockSocket(mockLibuv, Thread.CurrentThread.ManagedThreadId, transportContext.Log); var connection = new LibuvConnection(listenerContext, socket); connection.Start(); diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/LibuvOutputConsumerTests.cs b/test/Microsoft.AspNetCore.Server.Transport.Libuv.Tests/LibuvOutputConsumerTests.cs similarity index 90% rename from test/Microsoft.AspNetCore.Server.KestrelTests/LibuvOutputConsumerTests.cs rename to test/Microsoft.AspNetCore.Server.Transport.Libuv.Tests/LibuvOutputConsumerTests.cs index 301897f6a6..12bcbdfd95 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/LibuvOutputConsumerTests.cs +++ b/test/Microsoft.AspNetCore.Server.Transport.Libuv.Tests/LibuvOutputConsumerTests.cs @@ -7,14 +7,13 @@ using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; -using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv; -using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal; using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; -using Microsoft.AspNetCore.Server.KestrelTests.TestHelpers; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests.TestHelpers; using Microsoft.AspNetCore.Testing; using Xunit; -namespace Microsoft.AspNetCore.Server.KestrelTests +namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests { public class LibuvOutputConsumerTests : IDisposable { @@ -37,7 +36,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests _pipeFactory = new PipeFactory(); _mockLibuv = new MockLibuv(); - var libuvTransport = new LibuvTransport(_mockLibuv, new TestServiceContext().TransportContext, new ListenOptions(0)); + var libuvTransport = new LibuvTransport(_mockLibuv, new TestLibuvTransportContext(), new ListenOptions(0)); _libuvThread = new LibuvThread(libuvTransport, maxLoops: 1); _libuvThread.StartAsync().Wait(); } @@ -65,7 +64,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests MaximumSizeLow = maxResponseBufferSize ?? 0, }; - using (var socketOutput = CreateSocketOutput(pipeOptions)) + using (var socketOutput = CreateOutputProducer(pipeOptions)) { // At least one run of this test should have a MaxResponseBufferSize < 1 MB. var bufferSize = 1024 * 1024; @@ -100,7 +99,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests MaximumSizeLow = 0, }; - using (var socketOutput = CreateSocketOutput(pipeOptions)) + using (var socketOutput = CreateOutputProducer(pipeOptions)) { // Don't want to allocate anything too huge for perf. This is at least larger than the default buffer. var bufferSize = 1024 * 1024; @@ -146,7 +145,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests MaximumSizeLow = 1, }; - using (var socketOutput = CreateSocketOutput(pipeOptions)) + using (var socketOutput = CreateOutputProducer(pipeOptions)) { var bufferSize = 1; var buffer = new ArraySegment(new byte[bufferSize], 0, bufferSize); @@ -200,7 +199,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests MaximumSizeLow = maxResponseBufferSize, }; - using (var socketOutput = CreateSocketOutput(pipeOptions)) + using (var socketOutput = CreateOutputProducer(pipeOptions)) { var bufferSize = maxResponseBufferSize - 1; var buffer = new ArraySegment(new byte[bufferSize], 0, bufferSize); @@ -260,7 +259,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests MaximumSizeLow = maxResponseBufferSize, }; - using (var socketOutput = CreateSocketOutput(pipeOptions)) + using (var socketOutput = CreateOutputProducer(pipeOptions)) { var bufferSize = maxResponseBufferSize / 2; var data = new byte[bufferSize]; @@ -328,7 +327,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests MaximumSizeLow = maxResponseBufferSize, }; - using (var socketOutput = CreateSocketOutput(pipeOptions, mockConnection)) + using (var socketOutput = CreateOutputProducer(pipeOptions, mockConnection)) { var bufferSize = maxResponseBufferSize - 1; @@ -400,7 +399,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests MaximumSizeLow = maxResponseBufferSize, }; - using (var socketOutput = CreateSocketOutput(pipeOptions)) + using (var socketOutput = CreateOutputProducer(pipeOptions)) { var bufferSize = maxResponseBufferSize - 1; var buffer = new ArraySegment(new byte[bufferSize], 0, bufferSize); @@ -458,7 +457,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests MaximumSizeLow = maxResponseBufferSize ?? 0, }; - using (var socketOutput = CreateSocketOutput(pipeOptions)) + using (var socketOutput = CreateOutputProducer(pipeOptions)) { _mockLibuv.KestrelThreadBlocker.Reset(); @@ -487,46 +486,21 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } } - [Fact] - public async Task AllocCommitCanBeCalledAfterConnectionClose() - { - var pipeOptions = new PipeOptions - { - ReaderScheduler = _libuvThread, - }; + - using (var connection = new MockConnection()) - { - var socketOutput = CreateSocketOutput(pipeOptions, connection); - // Close SocketOutput - socketOutput.Dispose(); - - await _mockLibuv.OnPostTask; - - Assert.Equal(TaskStatus.RanToCompletion, connection.SocketClosed.Status); - - var called = false; - - ((ISocketOutput)socketOutput).Write((buffer, state) => - { - called = true; - }, - null); - - Assert.False(called); - } - } - - private OutputProducer CreateSocketOutput(PipeOptions pipeOptions, MockConnection connection = null) + private OutputProducer CreateOutputProducer(PipeOptions pipeOptions, MockConnection connection = null) { var pipe = _pipeFactory.Create(pipeOptions); - var serviceContext = new TestServiceContext(); + + var logger = new TestApplicationErrorLogger(); + var serviceContext = new TestServiceContext() { Log = new TestKestrelTrace(logger) }; + var transportContext = new TestLibuvTransportContext() { Log = new LibuvTrace(logger) }; var frame = new Frame(null, new FrameContext { ServiceContext = serviceContext }); - var socket = new MockSocket(_mockLibuv, _libuvThread.Loop.ThreadId, serviceContext.TransportContext.Log); + var socket = new MockSocket(_mockLibuv, _libuvThread.Loop.ThreadId, transportContext.Log); var socketOutput = new OutputProducer(pipe.Writer, frame, "0", serviceContext.Log); - var consumer = new LibuvOutputConsumer(pipe.Reader, _libuvThread, socket, connection ?? new MockConnection(), "0", serviceContext.TransportContext.Log); + var consumer = new LibuvOutputConsumer(pipe.Reader, _libuvThread, socket, connection ?? new MockConnection(), "0", transportContext.Log); var ignore = consumer.StartWrites(); return socketOutput; diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/LibuvTransportFactoryTests.cs b/test/Microsoft.AspNetCore.Server.Transport.Libuv.Tests/LibuvTransportFactoryTests.cs similarity index 92% rename from test/Microsoft.AspNetCore.Server.KestrelTests/LibuvTransportFactoryTests.cs rename to test/Microsoft.AspNetCore.Server.Transport.Libuv.Tests/LibuvTransportFactoryTests.cs index fb11478116..1e80201397 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/LibuvTransportFactoryTests.cs +++ b/test/Microsoft.AspNetCore.Server.Transport.Libuv.Tests/LibuvTransportFactoryTests.cs @@ -2,14 +2,13 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv; using Microsoft.AspNetCore.Testing; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using Moq; using Xunit; -namespace Microsoft.AspNetCore.Server.KestrelTests +namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests { public class LibuvTransportFactoryTests { diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/LibuvTransportOptionsTests.cs b/test/Microsoft.AspNetCore.Server.Transport.Libuv.Tests/LibuvTransportOptionsTests.cs similarity index 87% rename from test/Microsoft.AspNetCore.Server.KestrelTests/LibuvTransportOptionsTests.cs rename to test/Microsoft.AspNetCore.Server.Transport.Libuv.Tests/LibuvTransportOptionsTests.cs index df45392c07..8651bdb2ff 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/LibuvTransportOptionsTests.cs +++ b/test/Microsoft.AspNetCore.Server.Transport.Libuv.Tests/LibuvTransportOptionsTests.cs @@ -2,10 +2,9 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv; using Xunit; -namespace Microsoft.AspNetCore.Server.KestrelTests +namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests { public class LibuvTransportOptionsTests { diff --git a/test/Microsoft.AspNetCore.Server.Transport.Libuv.Tests/LibuvTransportTests.cs b/test/Microsoft.AspNetCore.Server.Transport.Libuv.Tests/LibuvTransportTests.cs new file mode 100644 index 0000000000..33c971a4b6 --- /dev/null +++ b/test/Microsoft.AspNetCore.Server.Transport.Libuv.Tests/LibuvTransportTests.cs @@ -0,0 +1,80 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System.Net; +using System.Net.Sockets; +using System.Text; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Server.Kestrel.Core; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests.TestHelpers; +using Microsoft.AspNetCore.Testing; +using Xunit; + +namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests +{ + public class LibuvTransportTests + { + public static TheoryData ConnectionAdapterData => new TheoryData + { + new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0)), + new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0)) + { + ConnectionAdapters = { new PassThroughConnectionAdapter() } + } + }; + + [Fact] + public async Task TransportCanBindAndStop() + { + var transportContext = new TestLibuvTransportContext(); + var transport = new LibuvTransport(transportContext, + new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0))); + + // The transport can no longer start threads without binding to an endpoint. + await transport.BindAsync(); + await transport.StopAsync(); + } + + [Theory] + [MemberData(nameof(ConnectionAdapterData))] + public async Task TransportCanBindUnbindAndStop(ListenOptions listenOptions) + { + var transportContext = new TestLibuvTransportContext(); + var transport = new LibuvTransport(transportContext, listenOptions); + + await transport.BindAsync(); + await transport.UnbindAsync(); + await transport.StopAsync(); + } + + [Theory] + [MemberData(nameof(ConnectionAdapterData))] + public async Task ConnectionCanReadAndWrite(ListenOptions listenOptions) + { + var transportContext = new TestLibuvTransportContext() + { + ConnectionHandler = new ConnectionHandler(listenOptions, new TestServiceContext(), new DummyApplication(TestApp.EchoApp)) + }; + var transport = new LibuvTransport(transportContext, listenOptions); + + await transport.BindAsync(); + + using (var socket = TestConnection.CreateConnectedLoopbackSocket(listenOptions.IPEndPoint.Port)) + { + var data = "Hello World"; + socket.Send(Encoding.ASCII.GetBytes($"POST / HTTP/1.0\r\nContent-Length: 11\r\n\r\n{data}")); + var buffer = new byte[data.Length]; + var read = 0; + while (read < data.Length) + { + read += socket.Receive(buffer, read, buffer.Length - read, SocketFlags.None); + } + } + + await transport.UnbindAsync(); + await transport.StopAsync(); + } + } +} diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/ListenerPrimaryTests.cs b/test/Microsoft.AspNetCore.Server.Transport.Libuv.Tests/ListenerPrimaryTests.cs similarity index 80% rename from test/Microsoft.AspNetCore.Server.KestrelTests/ListenerPrimaryTests.cs rename to test/Microsoft.AspNetCore.Server.Transport.Libuv.Tests/ListenerPrimaryTests.cs index 797e7d00a4..46defb4317 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/ListenerPrimaryTests.cs +++ b/test/Microsoft.AspNetCore.Server.Transport.Libuv.Tests/ListenerPrimaryTests.cs @@ -9,15 +9,14 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal; -using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv; using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal; using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking; -using Microsoft.AspNetCore.Server.KestrelTests.TestHelpers; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests.TestHelpers; using Microsoft.AspNetCore.Testing; using Microsoft.Extensions.Logging; using Xunit; -namespace Microsoft.AspNetCore.Server.KestrelTests +namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests { public class ListenerPrimaryTests { @@ -28,14 +27,16 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var listenOptions = new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0)); var serviceContextPrimary = new TestServiceContext(); - serviceContextPrimary.TransportContext.ConnectionHandler = new ConnectionHandler( + var transportContextPrimary = new TestLibuvTransportContext(); + transportContextPrimary.ConnectionHandler = new ConnectionHandler( listenOptions, serviceContextPrimary, new DummyApplication(c => c.Response.WriteAsync("Primary"))); var serviceContextSecondary = new TestServiceContext(); - serviceContextSecondary.TransportContext.ConnectionHandler = new ConnectionHandler( + var transportContextSecondary = new TestLibuvTransportContext(); + transportContextSecondary.ConnectionHandler = new ConnectionHandler( listenOptions, serviceContextSecondary, new DummyApplication(c => c.Response.WriteAsync("Secondary"))); - var libuvTransport = new LibuvTransport(libuv, serviceContextPrimary.TransportContext, listenOptions); + var libuvTransport = new LibuvTransport(libuv, transportContextPrimary, listenOptions); var pipeName = (libuv.IsWindows ? @"\\.\pipe\kestrel_" : "/tmp/kestrel_") + Guid.NewGuid().ToString("n"); var pipeMessage = Guid.NewGuid().ToByteArray(); @@ -43,7 +44,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests // Start primary listener var libuvThreadPrimary = new LibuvThread(libuvTransport); await libuvThreadPrimary.StartAsync(); - var listenerPrimary = new ListenerPrimary(serviceContextPrimary.TransportContext); + var listenerPrimary = new ListenerPrimary(transportContextPrimary); await listenerPrimary.StartAsync(pipeName, pipeMessage, listenOptions, libuvThreadPrimary); var address = listenOptions.ToString(); @@ -54,7 +55,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests // Add secondary listener var libuvThreadSecondary = new LibuvThread(libuvTransport); await libuvThreadSecondary.StartAsync(); - var listenerSecondary = new ListenerSecondary(serviceContextSecondary.TransportContext); + var listenerSecondary = new ListenerSecondary(transportContextSecondary); await listenerSecondary.StartAsync(pipeName, pipeMessage, listenOptions, libuvThreadSecondary); // Once a secondary listener is added, TCP connections start getting dispatched to it @@ -79,8 +80,11 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var libuv = new LibuvFunctions(); var listenOptions = new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0)); + var logger = new TestApplicationErrorLogger(); + var serviceContextPrimary = new TestServiceContext(); - serviceContextPrimary.TransportContext.ConnectionHandler = new ConnectionHandler( + var transportContextPrimary = new TestLibuvTransportContext() { Log = new LibuvTrace(logger) }; + transportContextPrimary.ConnectionHandler = new ConnectionHandler( listenOptions, serviceContextPrimary, new DummyApplication(c => c.Response.WriteAsync("Primary"))); var serviceContextSecondary = new TestServiceContext @@ -90,10 +94,11 @@ namespace Microsoft.AspNetCore.Server.KestrelTests ThreadPool = serviceContextPrimary.ThreadPool, HttpParserFactory = serviceContextPrimary.HttpParserFactory, }; - serviceContextSecondary.TransportContext.ConnectionHandler = new ConnectionHandler( + var transportContextSecondary = new TestLibuvTransportContext(); + transportContextSecondary.ConnectionHandler = new ConnectionHandler( listenOptions, serviceContextSecondary, new DummyApplication(c => c.Response.WriteAsync("Secondary"))); - var libuvTransport = new LibuvTransport(libuv, serviceContextPrimary.TransportContext, listenOptions); + var libuvTransport = new LibuvTransport(libuv, transportContextPrimary, listenOptions); var pipeName = (libuv.IsWindows ? @"\\.\pipe\kestrel_" : "/tmp/kestrel_") + Guid.NewGuid().ToString("n"); var pipeMessage = Guid.NewGuid().ToByteArray(); @@ -101,14 +106,14 @@ namespace Microsoft.AspNetCore.Server.KestrelTests // Start primary listener var libuvThreadPrimary = new LibuvThread(libuvTransport); await libuvThreadPrimary.StartAsync(); - var listenerPrimary = new ListenerPrimary(serviceContextPrimary.TransportContext); + var listenerPrimary = new ListenerPrimary(transportContextPrimary); await listenerPrimary.StartAsync(pipeName, pipeMessage, listenOptions, libuvThreadPrimary); var address = listenOptions.ToString(); // Add secondary listener var libuvThreadSecondary = new LibuvThread(libuvTransport); await libuvThreadSecondary.StartAsync(); - var listenerSecondary = new ListenerSecondary(serviceContextSecondary.TransportContext); + var listenerSecondary = new ListenerSecondary(transportContextSecondary); await listenerSecondary.StartAsync(pipeName, pipeMessage, listenOptions, libuvThreadSecondary); // TCP Connections get round-robined @@ -155,10 +160,8 @@ namespace Microsoft.AspNetCore.Server.KestrelTests await libuvThreadPrimary.PostAsync(_ => pipe.Dispose(), (object)null); - var primaryTrace = (TestKestrelTrace)serviceContextPrimary.Log; - // Wait up to 10 seconds for error to be logged - for (var i = 0; i < 10 && primaryTrace.Logger.TotalErrorsLogged == 0; i++) + for (var i = 0; i < 10 && logger.TotalErrorsLogged == 0; i++) { await Task.Delay(100); } @@ -174,8 +177,8 @@ namespace Microsoft.AspNetCore.Server.KestrelTests await listenerPrimary.DisposeAsync(); await libuvThreadPrimary.StopAsync(TimeSpan.FromSeconds(1)); - Assert.Equal(1, primaryTrace.Logger.TotalErrorsLogged); - var errorMessage = primaryTrace.Logger.Messages.First(m => m.LogLevel == LogLevel.Error); + Assert.Equal(1, logger.TotalErrorsLogged); + var errorMessage = logger.Messages.First(m => m.LogLevel == LogLevel.Error); Assert.Equal(TestConstants.EOF, Assert.IsType(errorMessage.Exception).StatusCode); } @@ -186,8 +189,11 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var libuv = new LibuvFunctions(); var listenOptions = new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0)); + var logger = new TestApplicationErrorLogger(); + var serviceContextPrimary = new TestServiceContext(); - serviceContextPrimary.TransportContext.ConnectionHandler = new ConnectionHandler( + var transportContextPrimary = new TestLibuvTransportContext() { Log = new LibuvTrace(logger) }; + transportContextPrimary.ConnectionHandler = new ConnectionHandler( listenOptions, serviceContextPrimary, new DummyApplication(c => c.Response.WriteAsync("Primary"))); var serviceContextSecondary = new TestServiceContext @@ -197,10 +203,11 @@ namespace Microsoft.AspNetCore.Server.KestrelTests ThreadPool = serviceContextPrimary.ThreadPool, HttpParserFactory = serviceContextPrimary.HttpParserFactory, }; - serviceContextSecondary.TransportContext.ConnectionHandler = new ConnectionHandler( + var transportContextSecondary = new TestLibuvTransportContext(); + transportContextSecondary.ConnectionHandler = new ConnectionHandler( listenOptions, serviceContextSecondary, new DummyApplication(c => c.Response.WriteAsync("Secondary"))); - var libuvTransport = new LibuvTransport(libuv, serviceContextPrimary.TransportContext, listenOptions); + var libuvTransport = new LibuvTransport(libuv, transportContextPrimary, listenOptions); var pipeName = (libuv.IsWindows ? @"\\.\pipe\kestrel_" : "/tmp/kestrel_") + Guid.NewGuid().ToString("n"); var pipeMessage = Guid.NewGuid().ToByteArray(); @@ -208,20 +215,18 @@ namespace Microsoft.AspNetCore.Server.KestrelTests // Start primary listener var libuvThreadPrimary = new LibuvThread(libuvTransport); await libuvThreadPrimary.StartAsync(); - var listenerPrimary = new ListenerPrimary(serviceContextPrimary.TransportContext); + var listenerPrimary = new ListenerPrimary(transportContextPrimary); await listenerPrimary.StartAsync(pipeName, pipeMessage, listenOptions, libuvThreadPrimary); var address = listenOptions.ToString(); // Add secondary listener with wrong pipe message var libuvThreadSecondary = new LibuvThread(libuvTransport); await libuvThreadSecondary.StartAsync(); - var listenerSecondary = new ListenerSecondary(serviceContextSecondary.TransportContext); + var listenerSecondary = new ListenerSecondary(transportContextSecondary); await listenerSecondary.StartAsync(pipeName, Guid.NewGuid().ToByteArray(), listenOptions, libuvThreadSecondary); - var primaryTrace = (TestKestrelTrace)serviceContextPrimary.Log; - // Wait up to 10 seconds for error to be logged - for (var i = 0; i < 10 && primaryTrace.Logger.TotalErrorsLogged == 0; i++) + for (var i = 0; i < 10 && logger.TotalErrorsLogged == 0; i++) { await Task.Delay(100); } @@ -237,8 +242,8 @@ namespace Microsoft.AspNetCore.Server.KestrelTests await listenerPrimary.DisposeAsync(); await libuvThreadPrimary.StopAsync(TimeSpan.FromSeconds(1)); - Assert.Equal(1, primaryTrace.Logger.TotalErrorsLogged); - var errorMessage = primaryTrace.Logger.Messages.First(m => m.LogLevel == LogLevel.Error); + Assert.Equal(1, logger.TotalErrorsLogged); + var errorMessage = logger.Messages.First(m => m.LogLevel == LogLevel.Error); Assert.IsType(errorMessage.Exception); Assert.Contains("Bad data", errorMessage.Exception.ToString()); } diff --git a/test/Microsoft.AspNetCore.Server.Transport.Libuv.Tests/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests.csproj b/test/Microsoft.AspNetCore.Server.Transport.Libuv.Tests/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests.csproj new file mode 100644 index 0000000000..ceb08babf0 --- /dev/null +++ b/test/Microsoft.AspNetCore.Server.Transport.Libuv.Tests/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests.csproj @@ -0,0 +1,35 @@ + + + + + + netcoreapp2.0;net46 + netcoreapp2.0 + x64 + true + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/MultipleLoopTests.cs b/test/Microsoft.AspNetCore.Server.Transport.Libuv.Tests/MultipleLoopTests.cs similarity index 98% rename from test/Microsoft.AspNetCore.Server.KestrelTests/MultipleLoopTests.cs rename to test/Microsoft.AspNetCore.Server.Transport.Libuv.Tests/MultipleLoopTests.cs index 66a7b64fa6..59f7a8f719 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/MultipleLoopTests.cs +++ b/test/Microsoft.AspNetCore.Server.Transport.Libuv.Tests/MultipleLoopTests.cs @@ -6,14 +6,14 @@ using System.Net; using System.Net.Sockets; using System.Runtime.InteropServices; using System.Threading; +using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal; using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking; -using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; -using Microsoft.AspNetCore.Server.KestrelTests.TestHelpers; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests.TestHelpers; using Microsoft.AspNetCore.Testing; using Xunit; -namespace Microsoft.AspNetCore.Server.KestrelTests +namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests { public class MultipleLoopTests { diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/NetworkingTests.cs b/test/Microsoft.AspNetCore.Server.Transport.Libuv.Tests/NetworkingTests.cs similarity index 98% rename from test/Microsoft.AspNetCore.Server.KestrelTests/NetworkingTests.cs rename to test/Microsoft.AspNetCore.Server.Transport.Libuv.Tests/NetworkingTests.cs index 11225a2e61..fd103c299f 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/NetworkingTests.cs +++ b/test/Microsoft.AspNetCore.Server.Transport.Libuv.Tests/NetworkingTests.cs @@ -12,7 +12,7 @@ using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; using Microsoft.AspNetCore.Testing; using Xunit; -namespace Microsoft.AspNetCore.Server.KestrelTests +namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests { /// /// Summary description for NetworkingTests diff --git a/test/shared/MockConnection.cs b/test/Microsoft.AspNetCore.Server.Transport.Libuv.Tests/TestHelpers/MockConnection.cs similarity index 92% rename from test/shared/MockConnection.cs rename to test/Microsoft.AspNetCore.Server.Transport.Libuv.Tests/TestHelpers/MockConnection.cs index d37696f9c7..a40892a1d0 100644 --- a/test/shared/MockConnection.cs +++ b/test/Microsoft.AspNetCore.Server.Transport.Libuv.Tests/TestHelpers/MockConnection.cs @@ -4,11 +4,10 @@ using System; using System.Threading; using System.Threading.Tasks; -using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal; using Microsoft.Extensions.Internal; -namespace Microsoft.AspNetCore.Testing +namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests.TestHelpers { public class MockConnection : LibuvConnection, IDisposable { diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockConnectionHandler.cs b/test/Microsoft.AspNetCore.Server.Transport.Libuv.Tests/TestHelpers/MockConnectionHandler.cs similarity index 96% rename from test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockConnectionHandler.cs rename to test/Microsoft.AspNetCore.Server.Transport.Libuv.Tests/TestHelpers/MockConnectionHandler.cs index 4b784346ae..44bda00009 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockConnectionHandler.cs +++ b/test/Microsoft.AspNetCore.Server.Transport.Libuv.Tests/TestHelpers/MockConnectionHandler.cs @@ -7,7 +7,7 @@ using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions; using Xunit; -namespace Microsoft.AspNetCore.Server.KestrelTests.TestHelpers +namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests.TestHelpers { public class MockConnectionHandler : IConnectionHandler, IDisposable { diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockLibuv.cs b/test/Microsoft.AspNetCore.Server.Transport.Libuv.Tests/TestHelpers/MockLibuv.cs similarity index 98% rename from test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockLibuv.cs rename to test/Microsoft.AspNetCore.Server.Transport.Libuv.Tests/TestHelpers/MockLibuv.cs index 8c0dea28e2..e18e2e8572 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockLibuv.cs +++ b/test/Microsoft.AspNetCore.Server.Transport.Libuv.Tests/TestHelpers/MockLibuv.cs @@ -6,7 +6,7 @@ using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking; -namespace Microsoft.AspNetCore.Server.KestrelTests.TestHelpers +namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests.TestHelpers { public class MockLibuv : LibuvFunctions { diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockSocket.cs b/test/Microsoft.AspNetCore.Server.Transport.Libuv.Tests/TestHelpers/MockSocket.cs similarity index 89% rename from test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockSocket.cs rename to test/Microsoft.AspNetCore.Server.Transport.Libuv.Tests/TestHelpers/MockSocket.cs index a8ab5075f3..110f8667ba 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/MockSocket.cs +++ b/test/Microsoft.AspNetCore.Server.Transport.Libuv.Tests/TestHelpers/MockSocket.cs @@ -5,7 +5,7 @@ using System; using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal; using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking; -namespace Microsoft.AspNetCore.Server.KestrelTests.TestHelpers +namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests.TestHelpers { class MockSocket : UvStreamHandle { diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/TestConstants.cs b/test/Microsoft.AspNetCore.Server.Transport.Libuv.Tests/TestHelpers/TestConstants.cs similarity index 76% rename from test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/TestConstants.cs rename to test/Microsoft.AspNetCore.Server.Transport.Libuv.Tests/TestHelpers/TestConstants.cs index 25f213c2a7..e9843bda85 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/TestHelpers/TestConstants.cs +++ b/test/Microsoft.AspNetCore.Server.Transport.Libuv.Tests/TestHelpers/TestConstants.cs @@ -1,7 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -namespace Microsoft.AspNetCore.Server.KestrelTests.TestHelpers +namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests.TestHelpers { public class TestConstants { diff --git a/test/Microsoft.AspNetCore.Server.Transport.Libuv.Tests/TestHelpers/TestLibuvTransportContext.cs b/test/Microsoft.AspNetCore.Server.Transport.Libuv.Tests/TestHelpers/TestLibuvTransportContext.cs new file mode 100644 index 0000000000..28b1da297d --- /dev/null +++ b/test/Microsoft.AspNetCore.Server.Transport.Libuv.Tests/TestHelpers/TestLibuvTransportContext.cs @@ -0,0 +1,26 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal; +using Microsoft.AspNetCore.Testing; + +namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests.TestHelpers +{ + public class TestLibuvTransportContext : LibuvTransportContext + { + public TestLibuvTransportContext() + { + var logger = new TestApplicationErrorLogger(); + + AppLifetime = new LifetimeNotImplemented(); + ConnectionHandler = new MockConnectionHandler(); + Log = new LibuvTrace(logger); + Options = new LibuvTransportOptions + { + ThreadCount = 1, + ShutdownTimeout = TimeSpan.FromSeconds(5) + }; + } + } +} diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/UvStreamHandleTests.cs b/test/Microsoft.AspNetCore.Server.Transport.Libuv.Tests/UvStreamHandleTests.cs similarity index 87% rename from test/Microsoft.AspNetCore.Server.KestrelTests/UvStreamHandleTests.cs rename to test/Microsoft.AspNetCore.Server.Transport.Libuv.Tests/UvStreamHandleTests.cs index 0754287832..d52e120add 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/UvStreamHandleTests.cs +++ b/test/Microsoft.AspNetCore.Server.Transport.Libuv.Tests/UvStreamHandleTests.cs @@ -3,11 +3,11 @@ using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal; using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking; -using Microsoft.AspNetCore.Server.KestrelTests.TestHelpers; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests.TestHelpers; using Microsoft.AspNetCore.Testing; using Xunit; -namespace Microsoft.AspNetCore.Server.KestrelTests +namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests { public class UvStreamHandleTests { diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/UvTimerHandleTests.cs b/test/Microsoft.AspNetCore.Server.Transport.Libuv.Tests/UvTimerHandleTests.cs similarity index 96% rename from test/Microsoft.AspNetCore.Server.KestrelTests/UvTimerHandleTests.cs rename to test/Microsoft.AspNetCore.Server.Transport.Libuv.Tests/UvTimerHandleTests.cs index 832e699c18..0eafb1a48b 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/UvTimerHandleTests.cs +++ b/test/Microsoft.AspNetCore.Server.Transport.Libuv.Tests/UvTimerHandleTests.cs @@ -6,7 +6,7 @@ using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking; using Microsoft.AspNetCore.Testing; using Xunit; -namespace Microsoft.AspNetCore.Server.KestrelTests +namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests { public class UvTimerHandleTests { diff --git a/test/Microsoft.AspNetCore.Server.Transport.Libuv.Tests/xunit.runner.json b/test/Microsoft.AspNetCore.Server.Transport.Libuv.Tests/xunit.runner.json new file mode 100644 index 0000000000..3a5192e57d --- /dev/null +++ b/test/Microsoft.AspNetCore.Server.Transport.Libuv.Tests/xunit.runner.json @@ -0,0 +1,6 @@ +{ + "$schema": "http://json.schemastore.org/xunit.runner.schema", + "appDomain": "denied", + "methodDisplay": "method", + "longRunningTestSeconds": 60 +} diff --git a/test/shared/HttpParsingData.cs b/test/shared/HttpParsingData.cs index a4d3d5521f..d3774bfd91 100644 --- a/test/shared/HttpParsingData.cs +++ b/test/shared/HttpParsingData.cs @@ -33,6 +33,8 @@ namespace Microsoft.AspNetCore.Testing Tuple.Create("/a%C3%A5a", "/a\u00E5a"), Tuple.Create("/%C3%A5/bc", "/\u00E5/bc"), Tuple.Create("/%25", "/%"), + Tuple.Create("/%25%30%30", "/%00"), + Tuple.Create("/%%2000", "/% 00"), Tuple.Create("/%2F", "/%2F"), Tuple.Create("http://host/abs/path", "/abs/path"), Tuple.Create("http://host/abs/path/", "/abs/path/"), diff --git a/test/shared/TestApplicationErrorLogger.cs b/test/shared/TestApplicationErrorLogger.cs index dcba1da052..d77a1c08ed 100644 --- a/test/shared/TestApplicationErrorLogger.cs +++ b/test/shared/TestApplicationErrorLogger.cs @@ -4,7 +4,6 @@ using System; using System.Collections.Concurrent; using System.Linq; -using Microsoft.AspNetCore.Server.Kestrel.Core.Internal; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; using Microsoft.Extensions.Logging; diff --git a/test/shared/TestServiceContext.cs b/test/shared/TestServiceContext.cs index ca9c28cecc..9223ad87f4 100644 --- a/test/shared/TestServiceContext.cs +++ b/test/shared/TestServiceContext.cs @@ -1,13 +1,10 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System; using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; -using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv; -using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal; namespace Microsoft.AspNetCore.Testing { @@ -26,21 +23,8 @@ namespace Microsoft.AspNetCore.Testing { AddServerHeader = false }; - - TransportContext = new LibuvTransportContext - { - AppLifetime = new LifetimeNotImplemented(), - Log = new LibuvTrace(logger), - Options = new LibuvTransportOptions - { - ThreadCount = 1, - ShutdownTimeout = TimeSpan.FromSeconds(5) - } - }; } public string DateHeaderValue { get; } - - public LibuvTransportContext TransportContext { get; } } } From 239b691ff5de11f1b23182016c7bc31f4dc20094 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Fri, 7 Apr 2017 08:35:53 -0700 Subject: [PATCH 1190/1662] A few HttpParser changes (#1624) - Renamed KestrelHttpParser to HttpParser - Removed the generic virtual dispatch as it turns out to be an order of magnitude slower than regular virtual dispatch. This change means we also lose the inlining of Frame.OnStartLine and Frame.OnHeader. --- .../Http/{KestrelHttpParser.cs => HttpParser.cs} | 12 ++++++------ .../Internal/Http/IHttpParser.cs | 4 ++-- .../KestrelServer.cs | 2 +- .../FrameResponseHeadersTests.cs | 4 ++-- .../HttpParserTests.cs | 2 +- .../FrameParsingOverheadBenchmark.cs | 4 ++-- .../FrameWritingBenchmark.cs | 2 +- .../KestrelHttpParserBenchmark.cs | 2 +- .../RequestParsingBenchmark.cs | 2 +- .../ResponseHeaderCollectionBenchmark.cs | 2 +- .../ResponseHeadersWritingBenchmark.cs | 2 +- test/shared/TestServiceContext.cs | 2 +- 12 files changed, 20 insertions(+), 20 deletions(-) rename src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/{KestrelHttpParser.cs => HttpParser.cs} (96%) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/KestrelHttpParser.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/HttpParser.cs similarity index 96% rename from src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/KestrelHttpParser.cs rename to src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/HttpParser.cs index 346a0abfe8..f5ac574008 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/KestrelHttpParser.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/HttpParser.cs @@ -10,9 +10,9 @@ using Microsoft.Extensions.Logging; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { - public class KestrelHttpParser : IHttpParser + public class HttpParser : IHttpParser { - public KestrelHttpParser(IKestrelTrace log) + public HttpParser(IKestrelTrace log) { Log = log; } @@ -28,7 +28,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http private const byte ByteQuestionMark = (byte)'?'; private const byte BytePercentage = (byte)'%'; - public unsafe bool ParseRequestLine(T handler, ReadableBuffer buffer, out ReadCursor consumed, out ReadCursor examined) where T : IHttpRequestLineHandler + public unsafe bool ParseRequestLine(IHttpRequestLineHandler handler, ReadableBuffer buffer, out ReadCursor consumed, out ReadCursor examined) { consumed = buffer.Start; examined = buffer.End; @@ -67,7 +67,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http return true; } - private unsafe void ParseRequestLine(T handler, byte* data, int length) where T : IHttpRequestLineHandler + private unsafe void ParseRequestLine(IHttpRequestLineHandler handler, byte* data, int length) { int offset; Span customMethod = default(Span); @@ -184,7 +184,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http handler.OnStartLine(method, httpVersion, targetBuffer, pathBuffer, query, customMethod, pathEncoded); } - public unsafe bool ParseHeaders(T handler, ReadableBuffer buffer, out ReadCursor consumed, out ReadCursor examined, out int consumedBytes) where T : IHttpHeadersHandler + public unsafe bool ParseHeaders(IHttpHeadersHandler handler, ReadableBuffer buffer, out ReadCursor consumed, out ReadCursor examined, out int consumedBytes) { consumed = buffer.Start; examined = buffer.End; @@ -347,7 +347,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http } [MethodImpl(MethodImplOptions.AggressiveInlining)] - private unsafe void TakeSingleHeader(byte* headerLine, int length, T handler) where T : IHttpHeadersHandler + private unsafe void TakeSingleHeader(byte* headerLine, int length, IHttpHeadersHandler handler) { // Skip CR, LF from end position var valueEnd = length - 3; diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/IHttpParser.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/IHttpParser.cs index f9b8ec2e21..8473fc4cc3 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/IHttpParser.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/IHttpParser.cs @@ -7,9 +7,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { public interface IHttpParser { - bool ParseRequestLine(T handler, ReadableBuffer buffer, out ReadCursor consumed, out ReadCursor examined) where T : IHttpRequestLineHandler; + bool ParseRequestLine(IHttpRequestLineHandler handler, ReadableBuffer buffer, out ReadCursor consumed, out ReadCursor examined); - bool ParseHeaders(T handler, ReadableBuffer buffer, out ReadCursor consumed, out ReadCursor examined, out int consumedBytes) where T : IHttpHeadersHandler; + bool ParseHeaders(IHttpHeadersHandler handler, ReadableBuffer buffer, out ReadCursor consumed, out ReadCursor examined, out int consumedBytes); void Reset(); } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/KestrelServer.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/KestrelServer.cs index d84f6f7a19..8cb36edf33 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/KestrelServer.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/KestrelServer.cs @@ -101,7 +101,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core var serviceContext = new ServiceContext { Log = trace, - HttpParserFactory = frame => new KestrelHttpParser(frame.ServiceContext.Log), + HttpParserFactory = frame => new HttpParser(frame.ServiceContext.Log), ThreadPool = threadPool, DateHeaderValueManager = _dateHeaderValueManager, ServerOptions = Options diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameResponseHeadersTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameResponseHeadersTests.cs index 7ca2c6eed7..c36da4188f 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameResponseHeadersTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameResponseHeadersTests.cs @@ -259,7 +259,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests private class NoopHttpParser : IHttpParser { - public bool ParseHeaders(T handler, ReadableBuffer buffer, out ReadCursor consumed, out ReadCursor examined, out int consumedBytes) where T : IHttpHeadersHandler + public bool ParseHeaders(IHttpHeadersHandler handler, ReadableBuffer buffer, out ReadCursor consumed, out ReadCursor examined, out int consumedBytes) { consumed = buffer.Start; examined = buffer.End; @@ -267,7 +267,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests return false; } - public bool ParseRequestLine(T handler, ReadableBuffer buffer, out ReadCursor consumed, out ReadCursor examined) where T : IHttpRequestLineHandler + public bool ParseRequestLine(IHttpRequestLineHandler handler, ReadableBuffer buffer, out ReadCursor consumed, out ReadCursor examined) { consumed = buffer.Start; examined = buffer.End; diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/HttpParserTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/HttpParserTests.cs index 8ef554e4f5..3600be4c40 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/HttpParserTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/HttpParserTests.cs @@ -418,7 +418,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests Assert.Equal(buffer.End, examined); } - private IHttpParser CreateParser(IKestrelTrace log) => new KestrelHttpParser(log); + private IHttpParser CreateParser(IKestrelTrace log) => new HttpParser(log); public static IEnumerable RequestLineValidData => HttpParsingData.RequestLineValidData; diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameParsingOverheadBenchmark.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameParsingOverheadBenchmark.cs index f777f6b370..1e05f8ea99 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameParsingOverheadBenchmark.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameParsingOverheadBenchmark.cs @@ -114,7 +114,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance public static readonly NullParser Instance = new NullParser(); - public bool ParseHeaders(T handler, ReadableBuffer buffer, out ReadCursor consumed, out ReadCursor examined, out int consumedBytes) where T : IHttpHeadersHandler + public bool ParseHeaders(IHttpHeadersHandler handler, ReadableBuffer buffer, out ReadCursor consumed, out ReadCursor examined, out int consumedBytes) { handler.OnHeader(new Span(_hostHeaderName), new Span(_hostHeaderValue)); handler.OnHeader(new Span(_acceptHeaderName), new Span(_acceptHeaderValue)); @@ -127,7 +127,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance return true; } - public bool ParseRequestLine(T handler, ReadableBuffer buffer, out ReadCursor consumed, out ReadCursor examined) where T : IHttpRequestLineHandler + public bool ParseRequestLine(IHttpRequestLineHandler handler, ReadableBuffer buffer, out ReadCursor consumed, out ReadCursor examined) { handler.OnStartLine(HttpMethod.Get, HttpVersion.Http11, diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameWritingBenchmark.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameWritingBenchmark.cs index 72973e444a..01f1b008fa 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameWritingBenchmark.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameWritingBenchmark.cs @@ -94,7 +94,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance DateHeaderValueManager = new DateHeaderValueManager(), ServerOptions = new KestrelServerOptions(), Log = new MockTrace(), - HttpParserFactory = f => new KestrelHttpParser(log: null) + HttpParserFactory = f => new HttpParser(log: null) }; var frameContext = new FrameContext { diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/KestrelHttpParserBenchmark.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/KestrelHttpParserBenchmark.cs index 852fadd6d6..d7e3e89511 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/KestrelHttpParserBenchmark.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/KestrelHttpParserBenchmark.cs @@ -12,7 +12,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance public class KestrelHttpParserBenchmark : IHttpRequestLineHandler, IHttpHeadersHandler { - private readonly KestrelHttpParser _parser = new KestrelHttpParser(log: null); + private readonly HttpParser _parser = new HttpParser(log: null); private ReadableBuffer _buffer; diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsingBenchmark.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsingBenchmark.cs index 2222e73e84..78844fe659 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsingBenchmark.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsingBenchmark.cs @@ -23,7 +23,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance { var serviceContext = new ServiceContext { - HttpParserFactory = f => new KestrelHttpParser(f.ServiceContext.Log), + HttpParserFactory = f => new HttpParser(f.ServiceContext.Log), ServerOptions = new KestrelServerOptions() }; var frameContext = new FrameContext diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/ResponseHeaderCollectionBenchmark.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/ResponseHeaderCollectionBenchmark.cs index e1bd6e60dc..0d32ed7079 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/ResponseHeaderCollectionBenchmark.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/ResponseHeaderCollectionBenchmark.cs @@ -170,7 +170,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance { var serviceContext = new ServiceContext { - HttpParserFactory = f => new KestrelHttpParser(f.ServiceContext.Log), + HttpParserFactory = f => new HttpParser(f.ServiceContext.Log), ServerOptions = new KestrelServerOptions() }; var frameContext = new FrameContext diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/ResponseHeadersWritingBenchmark.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/ResponseHeadersWritingBenchmark.cs index 75b32c4d0f..da56c4cc0b 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/ResponseHeadersWritingBenchmark.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/ResponseHeadersWritingBenchmark.cs @@ -120,7 +120,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance DateHeaderValueManager = new DateHeaderValueManager(), ServerOptions = new KestrelServerOptions(), Log = new MockTrace(), - HttpParserFactory = f => new KestrelHttpParser(log: null) + HttpParserFactory = f => new HttpParser(log: null) }; var frameContext = new FrameContext diff --git a/test/shared/TestServiceContext.cs b/test/shared/TestServiceContext.cs index 9223ad87f4..bf8e8eed40 100644 --- a/test/shared/TestServiceContext.cs +++ b/test/shared/TestServiceContext.cs @@ -18,7 +18,7 @@ namespace Microsoft.AspNetCore.Testing ThreadPool = new LoggingThreadPool(Log); DateHeaderValueManager = new DateHeaderValueManager(systemClock: new MockSystemClock()); DateHeaderValue = DateHeaderValueManager.GetDateHeaderValues().String; - HttpParserFactory = frame => new KestrelHttpParser(frame.ServiceContext.Log); + HttpParserFactory = frame => new HttpParser(frame.ServiceContext.Log); ServerOptions = new KestrelServerOptions { AddServerHeader = false From 53b0eea2ec2518725b49d52e7a6f517023afe990 Mon Sep 17 00:00:00 2001 From: Pavel Krymets Date: Fri, 7 Apr 2017 14:40:10 -0700 Subject: [PATCH 1191/1662] Use writable buffer writer (#1564) --- .../Adapter/Internal/StreamSocketOutput.cs | 14 +- .../Internal/Http/ChunkWriter.cs | 8 +- .../Internal/Http/Frame.cs | 10 +- .../Internal/Http/FrameHeaders.Generated.cs | 154 +++++++++--------- .../Internal/Http/FrameResponseHeaders.cs | 10 +- .../Internal/Http/OutputProducer.cs | 16 +- .../Internal/Http/PipelineExtensions.cs | 114 ++----------- .../PipelineExtensionTests.cs | 72 ++++---- .../RequestParsingBenchmark.cs | 2 +- tools/CodeGenerator/KnownHeaders.cs | 12 +- 10 files changed, 165 insertions(+), 247 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/Internal/StreamSocketOutput.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/Internal/StreamSocketOutput.cs index 7fb38dc67c..d7e7529f6d 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/Internal/StreamSocketOutput.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/Internal/StreamSocketOutput.cs @@ -41,19 +41,19 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal return; } - var writableBuffer = _pipe.Writer.Alloc(); - + var writableBuffer = _pipe.Writer.Alloc(1); + var writer = new WritableBufferWriter(writableBuffer); if (buffer.Count > 0) { if (chunk) { - ChunkWriter.WriteBeginChunkBytes(ref writableBuffer, buffer.Count); - writableBuffer.WriteFast(buffer); - ChunkWriter.WriteEndChunkBytes(ref writableBuffer); + ChunkWriter.WriteBeginChunkBytes(ref writer, buffer.Count); + writer.Write(buffer.Array, buffer.Offset, buffer.Count); + ChunkWriter.WriteEndChunkBytes(ref writer); } else { - writableBuffer.WriteFast(buffer); + writer.Write(buffer.Array, buffer.Offset, buffer.Count); } } @@ -92,7 +92,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal return; } - var buffer = _pipe.Writer.Alloc(); + var buffer = _pipe.Writer.Alloc(1); callback(buffer, state); buffer.Commit(); } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/ChunkWriter.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/ChunkWriter.cs index 06ad5877ad..bf34855007 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/ChunkWriter.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/ChunkWriter.cs @@ -47,16 +47,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http return new ArraySegment(bytes, offset, 10 - offset); } - public static int WriteBeginChunkBytes(ref WritableBuffer start, int dataCount) + public static int WriteBeginChunkBytes(ref WritableBufferWriter start, int dataCount) { var chunkSegment = BeginChunkBytes(dataCount); - start.WriteFast(chunkSegment); + start.Write(chunkSegment.Array, chunkSegment.Offset, chunkSegment.Count); return chunkSegment.Count; } - public static void WriteEndChunkBytes(ref WritableBuffer start) + public static void WriteEndChunkBytes(ref WritableBufferWriter start) { - start.WriteFast(_endChunkBytes); + start.Write(_endChunkBytes.Array, _endChunkBytes.Offset, _endChunkBytes.Count); } } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.cs index 53c723081e..d21c4c5563 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.cs @@ -993,12 +993,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http private static void WriteResponseHeaders(WritableBuffer writableBuffer, Frame frame) { + var writer = new WritableBufferWriter(writableBuffer); + var responseHeaders = frame.FrameResponseHeaders; - writableBuffer.WriteFast(_bytesHttpVersion11); + writer.Write(_bytesHttpVersion11); var statusBytes = ReasonPhrases.ToStatusBytes(frame.StatusCode, frame.ReasonPhrase); - writableBuffer.WriteFast(statusBytes); - responseHeaders.CopyTo(ref writableBuffer); - writableBuffer.WriteFast(_bytesEndHeaders); + writer.Write(statusBytes); + responseHeaders.CopyTo(ref writer); + writer.Write(_bytesEndHeaders); } public void ParseRequest(ReadableBuffer buffer, out ReadCursor consumed, out ReadCursor examined) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameHeaders.Generated.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameHeaders.Generated.cs index dd2f346ecc..2841efcc87 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameHeaders.Generated.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameHeaders.Generated.cs @@ -7753,7 +7753,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http return true; } - protected void CopyToFast(ref WritableBuffer output) + protected void CopyToFast(ref WritableBufferWriter output) { var tempBits = _bits | (_contentLength.HasValue ? -9223372036854775808L : 0); @@ -7761,7 +7761,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { if (_headers._rawConnection != null) { - output.WriteFast(_headers._rawConnection); + output.Write(_headers._rawConnection); } else { @@ -7771,8 +7771,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http var value = _headers._Connection[i]; if (value != null) { - output.WriteFast(_headerBytes, 17, 14); - output.WriteAsciiNoValidation(value); + output.Write(_headerBytes, 17, 14); + PipelineExtensions.WriteAsciiNoValidation(ref output, value); } } } @@ -7787,7 +7787,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { if (_headers._rawDate != null) { - output.WriteFast(_headers._rawDate); + output.Write(_headers._rawDate); } else { @@ -7797,8 +7797,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http var value = _headers._Date[i]; if (value != null) { - output.WriteFast(_headerBytes, 31, 8); - output.WriteAsciiNoValidation(value); + output.Write(_headerBytes, 31, 8); + PipelineExtensions.WriteAsciiNoValidation(ref output, value); } } } @@ -7818,8 +7818,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http var value = _headers._ContentType[i]; if (value != null) { - output.WriteFast(_headerBytes, 133, 16); - output.WriteAsciiNoValidation(value); + output.Write(_headerBytes, 133, 16); + PipelineExtensions.WriteAsciiNoValidation(ref output, value); } } } @@ -7834,7 +7834,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { if (_headers._rawServer != null) { - output.WriteFast(_headers._rawServer); + output.Write(_headers._rawServer); } else { @@ -7844,8 +7844,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http var value = _headers._Server[i]; if (value != null) { - output.WriteFast(_headerBytes, 350, 10); - output.WriteAsciiNoValidation(value); + output.Write(_headerBytes, 350, 10); + PipelineExtensions.WriteAsciiNoValidation(ref output, value); } } } @@ -7858,8 +7858,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http } if ((tempBits & -9223372036854775808L) != 0) { - output.WriteFast(_headerBytes, 592, 18); - output.WriteNumeric((ulong)ContentLength.Value); + output.Write(_headerBytes, 592, 18); + PipelineExtensions.WriteNumeric(ref output, (ulong)ContentLength.Value); if((tempBits & ~-9223372036854775808L) == 0) { @@ -7876,8 +7876,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http var value = _headers._CacheControl[i]; if (value != null) { - output.WriteFast(_headerBytes, 0, 17); - output.WriteAsciiNoValidation(value); + output.Write(_headerBytes, 0, 17); + PipelineExtensions.WriteAsciiNoValidation(ref output, value); } } } @@ -7897,8 +7897,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http var value = _headers._KeepAlive[i]; if (value != null) { - output.WriteFast(_headerBytes, 39, 14); - output.WriteAsciiNoValidation(value); + output.Write(_headerBytes, 39, 14); + PipelineExtensions.WriteAsciiNoValidation(ref output, value); } } } @@ -7918,8 +7918,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http var value = _headers._Pragma[i]; if (value != null) { - output.WriteFast(_headerBytes, 53, 10); - output.WriteAsciiNoValidation(value); + output.Write(_headerBytes, 53, 10); + PipelineExtensions.WriteAsciiNoValidation(ref output, value); } } } @@ -7939,8 +7939,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http var value = _headers._Trailer[i]; if (value != null) { - output.WriteFast(_headerBytes, 63, 11); - output.WriteAsciiNoValidation(value); + output.Write(_headerBytes, 63, 11); + PipelineExtensions.WriteAsciiNoValidation(ref output, value); } } } @@ -7955,7 +7955,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { if (_headers._rawTransferEncoding != null) { - output.WriteFast(_headers._rawTransferEncoding); + output.Write(_headers._rawTransferEncoding); } else { @@ -7965,8 +7965,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http var value = _headers._TransferEncoding[i]; if (value != null) { - output.WriteFast(_headerBytes, 74, 21); - output.WriteAsciiNoValidation(value); + output.Write(_headerBytes, 74, 21); + PipelineExtensions.WriteAsciiNoValidation(ref output, value); } } } @@ -7986,8 +7986,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http var value = _headers._Upgrade[i]; if (value != null) { - output.WriteFast(_headerBytes, 95, 11); - output.WriteAsciiNoValidation(value); + output.Write(_headerBytes, 95, 11); + PipelineExtensions.WriteAsciiNoValidation(ref output, value); } } } @@ -8007,8 +8007,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http var value = _headers._Via[i]; if (value != null) { - output.WriteFast(_headerBytes, 106, 7); - output.WriteAsciiNoValidation(value); + output.Write(_headerBytes, 106, 7); + PipelineExtensions.WriteAsciiNoValidation(ref output, value); } } } @@ -8028,8 +8028,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http var value = _headers._Warning[i]; if (value != null) { - output.WriteFast(_headerBytes, 113, 11); - output.WriteAsciiNoValidation(value); + output.Write(_headerBytes, 113, 11); + PipelineExtensions.WriteAsciiNoValidation(ref output, value); } } } @@ -8049,8 +8049,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http var value = _headers._Allow[i]; if (value != null) { - output.WriteFast(_headerBytes, 124, 9); - output.WriteAsciiNoValidation(value); + output.Write(_headerBytes, 124, 9); + PipelineExtensions.WriteAsciiNoValidation(ref output, value); } } } @@ -8070,8 +8070,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http var value = _headers._ContentEncoding[i]; if (value != null) { - output.WriteFast(_headerBytes, 149, 20); - output.WriteAsciiNoValidation(value); + output.Write(_headerBytes, 149, 20); + PipelineExtensions.WriteAsciiNoValidation(ref output, value); } } } @@ -8091,8 +8091,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http var value = _headers._ContentLanguage[i]; if (value != null) { - output.WriteFast(_headerBytes, 169, 20); - output.WriteAsciiNoValidation(value); + output.Write(_headerBytes, 169, 20); + PipelineExtensions.WriteAsciiNoValidation(ref output, value); } } } @@ -8112,8 +8112,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http var value = _headers._ContentLocation[i]; if (value != null) { - output.WriteFast(_headerBytes, 189, 20); - output.WriteAsciiNoValidation(value); + output.Write(_headerBytes, 189, 20); + PipelineExtensions.WriteAsciiNoValidation(ref output, value); } } } @@ -8133,8 +8133,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http var value = _headers._ContentMD5[i]; if (value != null) { - output.WriteFast(_headerBytes, 209, 15); - output.WriteAsciiNoValidation(value); + output.Write(_headerBytes, 209, 15); + PipelineExtensions.WriteAsciiNoValidation(ref output, value); } } } @@ -8154,8 +8154,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http var value = _headers._ContentRange[i]; if (value != null) { - output.WriteFast(_headerBytes, 224, 17); - output.WriteAsciiNoValidation(value); + output.Write(_headerBytes, 224, 17); + PipelineExtensions.WriteAsciiNoValidation(ref output, value); } } } @@ -8175,8 +8175,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http var value = _headers._Expires[i]; if (value != null) { - output.WriteFast(_headerBytes, 241, 11); - output.WriteAsciiNoValidation(value); + output.Write(_headerBytes, 241, 11); + PipelineExtensions.WriteAsciiNoValidation(ref output, value); } } } @@ -8196,8 +8196,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http var value = _headers._LastModified[i]; if (value != null) { - output.WriteFast(_headerBytes, 252, 17); - output.WriteAsciiNoValidation(value); + output.Write(_headerBytes, 252, 17); + PipelineExtensions.WriteAsciiNoValidation(ref output, value); } } } @@ -8217,8 +8217,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http var value = _headers._AcceptRanges[i]; if (value != null) { - output.WriteFast(_headerBytes, 269, 17); - output.WriteAsciiNoValidation(value); + output.Write(_headerBytes, 269, 17); + PipelineExtensions.WriteAsciiNoValidation(ref output, value); } } } @@ -8238,8 +8238,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http var value = _headers._Age[i]; if (value != null) { - output.WriteFast(_headerBytes, 286, 7); - output.WriteAsciiNoValidation(value); + output.Write(_headerBytes, 286, 7); + PipelineExtensions.WriteAsciiNoValidation(ref output, value); } } } @@ -8259,8 +8259,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http var value = _headers._ETag[i]; if (value != null) { - output.WriteFast(_headerBytes, 293, 8); - output.WriteAsciiNoValidation(value); + output.Write(_headerBytes, 293, 8); + PipelineExtensions.WriteAsciiNoValidation(ref output, value); } } } @@ -8280,8 +8280,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http var value = _headers._Location[i]; if (value != null) { - output.WriteFast(_headerBytes, 301, 12); - output.WriteAsciiNoValidation(value); + output.Write(_headerBytes, 301, 12); + PipelineExtensions.WriteAsciiNoValidation(ref output, value); } } } @@ -8301,8 +8301,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http var value = _headers._ProxyAuthenticate[i]; if (value != null) { - output.WriteFast(_headerBytes, 313, 22); - output.WriteAsciiNoValidation(value); + output.Write(_headerBytes, 313, 22); + PipelineExtensions.WriteAsciiNoValidation(ref output, value); } } } @@ -8322,8 +8322,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http var value = _headers._RetryAfter[i]; if (value != null) { - output.WriteFast(_headerBytes, 335, 15); - output.WriteAsciiNoValidation(value); + output.Write(_headerBytes, 335, 15); + PipelineExtensions.WriteAsciiNoValidation(ref output, value); } } } @@ -8343,8 +8343,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http var value = _headers._SetCookie[i]; if (value != null) { - output.WriteFast(_headerBytes, 360, 14); - output.WriteAsciiNoValidation(value); + output.Write(_headerBytes, 360, 14); + PipelineExtensions.WriteAsciiNoValidation(ref output, value); } } } @@ -8364,8 +8364,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http var value = _headers._Vary[i]; if (value != null) { - output.WriteFast(_headerBytes, 374, 8); - output.WriteAsciiNoValidation(value); + output.Write(_headerBytes, 374, 8); + PipelineExtensions.WriteAsciiNoValidation(ref output, value); } } } @@ -8385,8 +8385,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http var value = _headers._WWWAuthenticate[i]; if (value != null) { - output.WriteFast(_headerBytes, 382, 20); - output.WriteAsciiNoValidation(value); + output.Write(_headerBytes, 382, 20); + PipelineExtensions.WriteAsciiNoValidation(ref output, value); } } } @@ -8406,8 +8406,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http var value = _headers._AccessControlAllowCredentials[i]; if (value != null) { - output.WriteFast(_headerBytes, 402, 36); - output.WriteAsciiNoValidation(value); + output.Write(_headerBytes, 402, 36); + PipelineExtensions.WriteAsciiNoValidation(ref output, value); } } } @@ -8427,8 +8427,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http var value = _headers._AccessControlAllowHeaders[i]; if (value != null) { - output.WriteFast(_headerBytes, 438, 32); - output.WriteAsciiNoValidation(value); + output.Write(_headerBytes, 438, 32); + PipelineExtensions.WriteAsciiNoValidation(ref output, value); } } } @@ -8448,8 +8448,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http var value = _headers._AccessControlAllowMethods[i]; if (value != null) { - output.WriteFast(_headerBytes, 470, 32); - output.WriteAsciiNoValidation(value); + output.Write(_headerBytes, 470, 32); + PipelineExtensions.WriteAsciiNoValidation(ref output, value); } } } @@ -8469,8 +8469,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http var value = _headers._AccessControlAllowOrigin[i]; if (value != null) { - output.WriteFast(_headerBytes, 502, 31); - output.WriteAsciiNoValidation(value); + output.Write(_headerBytes, 502, 31); + PipelineExtensions.WriteAsciiNoValidation(ref output, value); } } } @@ -8490,8 +8490,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http var value = _headers._AccessControlExposeHeaders[i]; if (value != null) { - output.WriteFast(_headerBytes, 533, 33); - output.WriteAsciiNoValidation(value); + output.Write(_headerBytes, 533, 33); + PipelineExtensions.WriteAsciiNoValidation(ref output, value); } } } @@ -8511,8 +8511,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http var value = _headers._AccessControlMaxAge[i]; if (value != null) { - output.WriteFast(_headerBytes, 566, 26); - output.WriteAsciiNoValidation(value); + output.Write(_headerBytes, 566, 26); + PipelineExtensions.WriteAsciiNoValidation(ref output, value); } } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameResponseHeaders.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameResponseHeaders.cs index f0dc531e48..f5093f691f 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameResponseHeaders.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameResponseHeaders.cs @@ -34,7 +34,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http return GetEnumerator(); } - public void CopyTo(ref WritableBuffer output) + public void CopyTo(ref WritableBufferWriter output) { CopyToFast(ref output); if (MaybeUnknown != null) @@ -45,10 +45,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { if (value != null) { - output.WriteFast(_CrLf); - output.WriteAsciiNoValidation(kv.Key); - output.WriteFast(_colonSpace); - output.WriteAsciiNoValidation(value); + output.Write(_CrLf); + PipelineExtensions.WriteAsciiNoValidation(ref output, kv.Key); + output.Write(_colonSpace); + PipelineExtensions.WriteAsciiNoValidation(ref output, value); } } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/OutputProducer.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/OutputProducer.cs index 83294c7ed5..261db5c1d7 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/OutputProducer.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/OutputProducer.cs @@ -26,7 +26,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http private readonly IPipeWriter _pipe; private readonly Frame _frame; - // https://github.com/dotnet/corefxlab/issues/1334 + // https://github.com/dotnet/corefxlab/issues/1334 // Pipelines don't support multiple awaiters on flush // this is temporary until it does private TaskCompletionSource _flushTcs; @@ -59,20 +59,20 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http return TaskCache.CompletedTask; } - writableBuffer = _pipe.Alloc(); - + writableBuffer = _pipe.Alloc(1); + var writer = new WritableBufferWriter(writableBuffer); if (buffer.Count > 0) { if (chunk) { - ChunkWriter.WriteBeginChunkBytes(ref writableBuffer, buffer.Count); + ChunkWriter.WriteBeginChunkBytes(ref writer, buffer.Count); } - writableBuffer.WriteFast(buffer); + writer.Write(buffer.Array, buffer.Offset, buffer.Count); if (chunk) { - ChunkWriter.WriteEndChunkBytes(ref writableBuffer); + ChunkWriter.WriteEndChunkBytes(ref writer); } } @@ -95,7 +95,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http private Task FlushAsyncAwaited(WritableBufferAwaitable awaitable) { - // https://github.com/dotnet/corefxlab/issues/1334 + // https://github.com/dotnet/corefxlab/issues/1334 // Since the flush awaitable doesn't currently support multiple awaiters // we need to use a task to track the callbacks. // All awaiters get the same task @@ -157,7 +157,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http return; } - var buffer = _pipe.Alloc(); + var buffer = _pipe.Alloc(1); callback(buffer, state); buffer.Commit(); } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/PipelineExtensions.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/PipelineExtensions.cs index 19ce278bea..d9b27dfbbf 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/PipelineExtensions.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/PipelineExtensions.cs @@ -95,98 +95,17 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http return result; } - // Temporary until the fast write implementation propagates from corefx - public unsafe static void WriteFast(this WritableBuffer buffer, byte[] source) - { - buffer.WriteFast(source, 0, source.Length); - } - - public unsafe static void WriteFast(this WritableBuffer buffer, ArraySegment source) - { - buffer.WriteFast(source.Array, source.Offset, source.Count); - } - - public unsafe static void WriteFast(this WritableBuffer buffer, byte[] source, int offset, int length) - { - var dest = buffer.Buffer.Span; - var destLength = dest.Length; - - if (destLength == 0) - { - buffer.Ensure(); - - // Get the new span and length - dest = buffer.Buffer.Span; - destLength = dest.Length; - } - - var sourceLength = length; - if (sourceLength <= destLength) - { - ref byte pSource = ref source[offset]; - ref byte pDest = ref dest.DangerousGetPinnableReference(); - Unsafe.CopyBlockUnaligned(ref pDest, ref pSource, (uint)sourceLength); - buffer.Advance(sourceLength); - return; - } - - buffer.WriteMultiBuffer(source, offset, length); - } - - private static unsafe void WriteMultiBuffer(this WritableBuffer buffer, byte[] source, int offset, int length) - { - var remaining = length; - - while (remaining > 0) - { - var writable = Math.Min(remaining, buffer.Buffer.Length); - - buffer.Ensure(writable); - - if (writable == 0) - { - continue; - } - - ref byte pSource = ref source[offset]; - ref byte pDest = ref buffer.Buffer.Span.DangerousGetPinnableReference(); - - Unsafe.CopyBlockUnaligned(ref pDest, ref pSource, (uint)writable); - - remaining -= writable; - offset += writable; - - buffer.Advance(writable); - } - } - - /// - /// Write string characters as ASCII without validating that characters fall in the ASCII range - /// - /// - /// ASCII character validation is done by - /// - /// the buffer - /// The string to write - public unsafe static void WriteAsciiNoValidation(this WritableBuffer buffer, string data) + public unsafe static void WriteAsciiNoValidation(ref WritableBufferWriter buffer, string data) { if (string.IsNullOrEmpty(data)) { return; } - var dest = buffer.Buffer.Span; + var dest = buffer.Span; var destLength = dest.Length; var sourceLength = data.Length; - if (destLength == 0) - { - buffer.Ensure(); - - dest = buffer.Buffer.Span; - destLength = dest.Length; - } - // Fast path, try copying to the available memory directly if (sourceLength <= destLength) { @@ -200,26 +119,18 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http } else { - buffer.WriteAsciiMultiWrite(data); + WriteAsciiMultiWrite(ref buffer, data); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public unsafe static void WriteNumeric(this WritableBuffer buffer, ulong number) + public unsafe static void WriteNumeric(ref WritableBufferWriter buffer, ulong number) { const byte AsciiDigitStart = (byte)'0'; - var span = buffer.Buffer.Span; + var span = buffer.Span; var bytesLeftInBlock = span.Length; - if (bytesLeftInBlock == 0) - { - buffer.Ensure(); - - span = buffer.Buffer.Span; - bytesLeftInBlock = span.Length; - } - // Fast path, try copying to the available memory directly var simpleWrite = true; fixed (byte* output = &span.DangerousGetPinnableReference()) @@ -258,12 +169,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http if (!simpleWrite) { - buffer.WriteNumericMultiWrite(number); + WriteNumericMultiWrite(ref buffer, number); } } [MethodImpl(MethodImplOptions.NoInlining)] - private static unsafe void WriteNumericMultiWrite(this WritableBuffer buffer, ulong number) + private static void WriteNumericMultiWrite(ref WritableBufferWriter buffer, ulong number) { const byte AsciiDigitStart = (byte)'0'; @@ -280,11 +191,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http while (value != 0); var length = _maxULongByteLength - position; - buffer.WriteFast(new ArraySegment(byteBuffer, position, length)); + buffer.Write(byteBuffer, position, length); } [MethodImpl(MethodImplOptions.NoInlining)] - private unsafe static void WriteAsciiMultiWrite(this WritableBuffer buffer, string data) + private unsafe static void WriteAsciiMultiWrite(ref WritableBufferWriter buffer, string data) { var remaining = data.Length; @@ -294,16 +205,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http while (remaining > 0) { - var writable = Math.Min(remaining, buffer.Buffer.Length); - - buffer.Ensure(writable); + var writable = Math.Min(remaining, buffer.Span.Length); if (writable == 0) { + buffer.Ensure(); continue; } - fixed (byte* output = &buffer.Buffer.Span.DangerousGetPinnableReference()) + fixed (byte* output = &buffer.Span.DangerousGetPinnableReference()) { EncodeAsciiCharsToBytes(inputSlice, output, writable); } diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/PipelineExtensionTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/PipelineExtensionTests.cs index ec85ef3b5e..a580b92e06 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/PipelineExtensionTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/PipelineExtensionTests.cs @@ -33,13 +33,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests [InlineData(ulong.MinValue)] [InlineData(ulong.MaxValue)] [InlineData(4_8_15_16_23_42)] - public async Task WritesNumericToAscii(ulong number) + public void WritesNumericToAscii(ulong number) { - var writer = _pipe.Writer.Alloc(); - writer.WriteNumeric(number); - await writer.FlushAsync(); + var writerBuffer = _pipe.Writer.Alloc(); + var writer = new WritableBufferWriter(writerBuffer); + PipelineExtensions.WriteNumeric(ref writer, number); + writerBuffer.FlushAsync().GetAwaiter().GetResult(); - var reader = await _pipe.Reader.ReadAsync(); + var reader = _pipe.Reader.ReadAsync().GetAwaiter().GetResult(); var numAsStr = number.ToString(); var expected = Encoding.ASCII.GetBytes(numAsStr); AssertExtensions.Equal(expected, reader.Buffer.Slice(0, numAsStr.Length).ToArray()); @@ -51,16 +52,17 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests [InlineData(_ulongMaxValueLength - 1)] public void WritesNumericAcrossSpanBoundaries(int gapSize) { - var writer = _pipe.Writer.Alloc(100); + var writerBuffer = _pipe.Writer.Alloc(100); + var writer = new WritableBufferWriter(writerBuffer); // almost fill up the first block - var spacer = new Span(new byte[writer.Buffer.Length - gapSize]); + var spacer = new byte[writer.Span.Length - gapSize]; writer.Write(spacer); - var bufferLength = writer.Buffer.Length; - writer.WriteNumeric(ulong.MaxValue); - Assert.NotEqual(bufferLength, writer.Buffer.Length); + var bufferLength = writer.Span.Length; + PipelineExtensions.WriteNumeric(ref writer, ulong.MaxValue); + Assert.NotEqual(bufferLength, writer.Span.Length); - writer.FlushAsync().GetAwaiter().GetResult(); + writerBuffer.FlushAsync().GetAwaiter().GetResult(); var reader = _pipe.Reader.ReadAsync().GetAwaiter().GetResult(); var numAsString = ulong.MaxValue.ToString(); @@ -79,12 +81,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests // null or empty [InlineData("", new byte[0])] [InlineData(null, new byte[0])] - public async Task EncodesAsAscii(string input, byte[] expected) + public void EncodesAsAscii(string input, byte[] expected) { - var writer = _pipe.Writer.Alloc(); - writer.WriteAsciiNoValidation(input); - await writer.FlushAsync(); - var reader = await _pipe.Reader.ReadAsync(); + var writerBuffer = _pipe.Writer.Alloc(); + var writer = new WritableBufferWriter(writerBuffer); + PipelineExtensions.WriteAsciiNoValidation(ref writer, input); + writerBuffer.FlushAsync().GetAwaiter().GetResult(); + var reader = _pipe.Reader.ReadAsync().GetAwaiter().GetResult(); if (expected.Length > 0) { @@ -103,30 +106,32 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests [InlineData("𤭢𐐝")] // non-ascii characters stored in 16 bits [InlineData("ñ٢⛄⛵")] - public async Task WriteAsciiNoValidationWritesOnlyOneBytePerChar(string input) + public void WriteAsciiNoValidationWritesOnlyOneBytePerChar(string input) { // WriteAscii doesn't validate if characters are in the ASCII range // but it shouldn't produce more than one byte per character - var writer = _pipe.Writer.Alloc(); - writer.WriteAsciiNoValidation(input); - await writer.FlushAsync(); - var reader = await _pipe.Reader.ReadAsync(); + var writerBuffer = _pipe.Writer.Alloc(); + var writer = new WritableBufferWriter(writerBuffer); + PipelineExtensions.WriteAsciiNoValidation(ref writer, input); + writerBuffer.FlushAsync().GetAwaiter().GetResult(); + var reader = _pipe.Reader.ReadAsync().GetAwaiter().GetResult(); Assert.Equal(input.Length, reader.Buffer.Length); } [Fact] - public async Task WriteAsciiNoValidation() + public void WriteAsciiNoValidation() { const byte maxAscii = 0x7f; - var writer = _pipe.Writer.Alloc(); + var writerBuffer = _pipe.Writer.Alloc(); + var writer = new WritableBufferWriter(writerBuffer); for (var i = 0; i < maxAscii; i++) { - writer.WriteAsciiNoValidation(new string((char)i, 1)); + PipelineExtensions.WriteAsciiNoValidation(ref writer, new string((char)i, 1)); } - await writer.FlushAsync(); + writerBuffer.FlushAsync().GetAwaiter().GetResult(); - var reader = await _pipe.Reader.ReadAsync(); + var reader = _pipe.Reader.ReadAsync().GetAwaiter().GetResult(); var data = reader.Buffer.Slice(0, maxAscii).ToArray(); for (var i = 0; i < maxAscii; i++) { @@ -147,17 +152,18 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests public void WritesAsciiAcrossBlockBoundaries(int stringLength, int gapSize) { var testString = new string(' ', stringLength); - var writer = _pipe.Writer.Alloc(100); + var writerBuffer = _pipe.Writer.Alloc(100); + var writer = new WritableBufferWriter(writerBuffer); // almost fill up the first block - var spacer = new Span(new byte[writer.Buffer.Length - gapSize]); + var spacer = new byte[writer.Span.Length - gapSize]; writer.Write(spacer); - Assert.Equal(gapSize, writer.Buffer.Span.Length); + Assert.Equal(gapSize, writer.Span.Length); - var bufferLength = writer.Buffer.Length; - writer.WriteAsciiNoValidation(testString); - Assert.NotEqual(bufferLength, writer.Buffer.Length); + var bufferLength = writer.Span.Length; + PipelineExtensions.WriteAsciiNoValidation(ref writer, testString); + Assert.NotEqual(bufferLength, writer.Span.Length); - writer.FlushAsync().GetAwaiter().GetResult(); + writerBuffer.FlushAsync().GetAwaiter().GetResult(); var reader = _pipe.Reader.ReadAsync().GetAwaiter().GetResult(); var written = reader.Buffer.Slice(spacer.Length, stringLength); diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsingBenchmark.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsingBenchmark.cs index 78844fe659..d759bccc02 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsingBenchmark.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsingBenchmark.cs @@ -120,7 +120,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance private void InsertData(byte[] bytes) { var buffer = Pipe.Writer.Alloc(2048); - buffer.WriteFast(bytes); + buffer.Write(bytes); // There should not be any backpressure and task completes immediately buffer.FlushAsync().GetAwaiter().GetResult(); } diff --git a/tools/CodeGenerator/KnownHeaders.cs b/tools/CodeGenerator/KnownHeaders.cs index 19f7ef5796..b0cdf0b530 100644 --- a/tools/CodeGenerator/KnownHeaders.cs +++ b/tools/CodeGenerator/KnownHeaders.cs @@ -522,7 +522,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http return true; }} {(loop.ClassName == "FrameResponseHeaders" ? $@" - protected void CopyToFast(ref WritableBuffer output) + protected void CopyToFast(ref WritableBufferWriter output) {{ var tempBits = _bits | (_contentLength.HasValue ? {1L << 63}L : 0); {Each(loop.Headers.Where(header => header.Identifier != "ContentLength").OrderBy(h => !h.PrimaryHeader), header => $@" @@ -530,7 +530,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http {{ {(header.EnhancedSetter == false ? "" : $@" if (_headers._raw{header.Identifier} != null) {{ - output.WriteFast(_headers._raw{header.Identifier}); + output.Write(_headers._raw{header.Identifier}); }} else ")} {{ @@ -540,8 +540,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http var value = _headers._{header.Identifier}[i]; if (value != null) {{ - output.WriteFast(_headerBytes, {header.BytesOffset}, {header.BytesCount}); - output.WriteAsciiNoValidation(value); + output.Write(_headerBytes, {header.BytesOffset}, {header.BytesCount}); + PipelineExtensions.WriteAsciiNoValidation(ref output, value); }} }} }} @@ -554,8 +554,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http }}{(header.Identifier == "Server" ? $@" if ((tempBits & {1L << 63}L) != 0) {{ - output.WriteFast(_headerBytes, {loop.Headers.First(x => x.Identifier == "ContentLength").BytesOffset}, {loop.Headers.First(x => x.Identifier == "ContentLength").BytesCount}); - output.WriteNumeric((ulong)ContentLength.Value); + output.Write(_headerBytes, {loop.Headers.First(x => x.Identifier == "ContentLength").BytesOffset}, {loop.Headers.First(x => x.Identifier == "ContentLength").BytesCount}); + PipelineExtensions.WriteNumeric(ref output, (ulong)ContentLength.Value); if((tempBits & ~{1L << 63}L) == 0) {{ From 27584dc62000c6b545c321a5d93705d1d4f26a43 Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Fri, 7 Apr 2017 20:26:34 -0700 Subject: [PATCH 1192/1662] Add new MessageBody tests and refactor some existing ones. - No need to test with FIN since we consider that an error - Consolidate HTTP/1.0 and HTTP/1.1 tests that were the same except for the HTTP version - Add a few new tests --- .../MessageBodyTests.cs | 176 +++++++++++------- .../TestInput.cs | 7 +- 2 files changed, 106 insertions(+), 77 deletions(-) diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/MessageBodyTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/MessageBodyTests.cs index 5b06b25acc..95a35b2882 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/MessageBodyTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/MessageBodyTests.cs @@ -9,7 +9,6 @@ using System.Text; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; using Microsoft.Extensions.Internal; using Moq; @@ -18,146 +17,179 @@ using Xunit.Sdk; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests { - /// - /// Summary description for MessageBodyTests - /// public class MessageBodyTests { - [Fact] - public void Http10ConnectionClose() + [Theory] + [InlineData(HttpVersion.Http10)] + [InlineData(HttpVersion.Http11)] + public void CanReadFromContentLength(HttpVersion httpVersion) { using (var input = new TestInput()) { - var body = MessageBody.For(HttpVersion.Http10, new FrameRequestHeaders { HeaderContentLength = "5" }, input.FrameContext); + var body = MessageBody.For(httpVersion, new FrameRequestHeaders { HeaderContentLength = "5" }, input.FrameContext); var stream = new FrameRequestStream(); stream.StartAcceptingReads(body); - input.Add("Hello", true); + input.Add("Hello"); - var buffer1 = new byte[1024]; - var count1 = stream.Read(buffer1, 0, 1024); - AssertASCII("Hello", new ArraySegment(buffer1, 0, 5)); + var buffer = new byte[1024]; - var buffer2 = new byte[1024]; - var count2 = stream.Read(buffer2, 0, 1024); - Assert.Equal(0, count2); + var count = stream.Read(buffer, 0, buffer.Length); + Assert.Equal(5, count); + AssertASCII("Hello", new ArraySegment(buffer, 0, count)); + + count = stream.Read(buffer, 0, buffer.Length); + Assert.Equal(0, count); + } + } + + [Theory] + [InlineData(HttpVersion.Http10)] + [InlineData(HttpVersion.Http11)] + public async Task CanReadAsyncFromContentLength(HttpVersion httpVersion) + { + using (var input = new TestInput()) + { + var body = MessageBody.For(httpVersion, new FrameRequestHeaders { HeaderContentLength = "5" }, input.FrameContext); + var stream = new FrameRequestStream(); + stream.StartAcceptingReads(body); + + input.Add("Hello"); + + var buffer = new byte[1024]; + + var count = await stream.ReadAsync(buffer, 0, buffer.Length); + Assert.Equal(5, count); + AssertASCII("Hello", new ArraySegment(buffer, 0, count)); + + count = await stream.ReadAsync(buffer, 0, buffer.Length); + Assert.Equal(0, count); } } [Fact] - public async Task Http10ConnectionCloseAsync() + public void CanReadFromChunkedEncoding() { using (var input = new TestInput()) { - var body = MessageBody.For(HttpVersion.Http10, new FrameRequestHeaders { HeaderContentLength = "5" }, input.FrameContext); + var body = MessageBody.For(HttpVersion.Http11, new FrameRequestHeaders { HeaderTransferEncoding = "chunked" }, input.FrameContext); var stream = new FrameRequestStream(); stream.StartAcceptingReads(body); - input.Add("Hello", true); + input.Add("5\r\nHello\r\n"); - var buffer1 = new byte[1024]; - var count1 = await stream.ReadAsync(buffer1, 0, 1024); - AssertASCII("Hello", new ArraySegment(buffer1, 0, 5)); + var buffer = new byte[1024]; - var buffer2 = new byte[1024]; - var count2 = await stream.ReadAsync(buffer2, 0, 1024); - Assert.Equal(0, count2); + var count = stream.Read(buffer, 0, buffer.Length); + Assert.Equal(5, count); + AssertASCII("Hello", new ArraySegment(buffer, 0, count)); + + input.Add("0\r\n\r\n"); + + count = stream.Read(buffer, 0, buffer.Length); + Assert.Equal(0, count); } } [Fact] - public void Http10NoContentLength() + public async Task CanReadAsyncFromChunkedEncoding() { using (var input = new TestInput()) { - var body = MessageBody.For(HttpVersion.Http10, new FrameRequestHeaders(), input.FrameContext); + var body = MessageBody.For(HttpVersion.Http11, new FrameRequestHeaders { HeaderTransferEncoding = "chunked" }, input.FrameContext); var stream = new FrameRequestStream(); stream.StartAcceptingReads(body); - input.Add("Hello", true); + input.Add("5\r\nHello\r\n"); - var buffer1 = new byte[1024]; - Assert.Equal(0, stream.Read(buffer1, 0, 1024)); + var buffer = new byte[1024]; + + var count = await stream.ReadAsync(buffer, 0, buffer.Length); + Assert.Equal(5, count); + AssertASCII("Hello", new ArraySegment(buffer, 0, count)); + + input.Add("0\r\n\r\n"); + + count = await stream.ReadAsync(buffer, 0, buffer.Length); + Assert.Equal(0, count); } } - [Fact] - public async Task Http10NoContentLengthAsync() + [Theory] + [InlineData(HttpVersion.Http10)] + [InlineData(HttpVersion.Http11)] + public void CanReadFromRemainingData(HttpVersion httpVersion) { using (var input = new TestInput()) { - var body = MessageBody.For(HttpVersion.Http10, new FrameRequestHeaders(), input.FrameContext); + var body = MessageBody.For(httpVersion, new FrameRequestHeaders { HeaderConnection = "upgrade" }, input.FrameContext); var stream = new FrameRequestStream(); stream.StartAcceptingReads(body); - input.Add("Hello", true); + input.Add("Hello"); - var buffer1 = new byte[1024]; - Assert.Equal(0, await stream.ReadAsync(buffer1, 0, 1024)); + var buffer = new byte[1024]; + + var count = stream.Read(buffer, 0, buffer.Length); + Assert.Equal(5, count); + AssertASCII("Hello", new ArraySegment(buffer, 0, count)); } } - [Fact] - public void Http11NoContentLength() + [Theory] + [InlineData(HttpVersion.Http10)] + [InlineData(HttpVersion.Http11)] + public async Task CanReadAsyncFromRemainingData(HttpVersion httpVersion) { using (var input = new TestInput()) { - var body = MessageBody.For(HttpVersion.Http11, new FrameRequestHeaders(), input.FrameContext); + var body = MessageBody.For(httpVersion, new FrameRequestHeaders { HeaderConnection = "upgrade" }, input.FrameContext); var stream = new FrameRequestStream(); stream.StartAcceptingReads(body); - input.Add("Hello", true); + input.Add("Hello"); - var buffer1 = new byte[1024]; - Assert.Equal(0, stream.Read(buffer1, 0, 1024)); + var buffer = new byte[1024]; + + var count = await stream.ReadAsync(buffer, 0, buffer.Length); + Assert.Equal(5, count); + AssertASCII("Hello", new ArraySegment(buffer, 0, count)); } } - [Fact] - public async Task Http11NoContentLengthAsync() + [Theory] + [InlineData(HttpVersion.Http10)] + [InlineData(HttpVersion.Http11)] + public void ReadFromNoContentLengthReturnsZero(HttpVersion httpVersion) { using (var input = new TestInput()) { - var body = MessageBody.For(HttpVersion.Http11, new FrameRequestHeaders(), input.FrameContext); + var body = MessageBody.For(httpVersion, new FrameRequestHeaders(), input.FrameContext); var stream = new FrameRequestStream(); stream.StartAcceptingReads(body); - input.Add("Hello", true); + input.Add("Hello"); - var buffer1 = new byte[1024]; - Assert.Equal(0, await stream.ReadAsync(buffer1, 0, 1024)); + var buffer = new byte[1024]; + Assert.Equal(0, stream.Read(buffer, 0, buffer.Length)); } } - [Fact] - public void Http11NoContentLengthConnectionClose() + [Theory] + [InlineData(HttpVersion.Http10)] + [InlineData(HttpVersion.Http11)] + public async Task ReadAsyncFromNoContentLengthReturnsZero(HttpVersion httpVersion) { using (var input = new TestInput()) { - var body = MessageBody.For(HttpVersion.Http11, new FrameRequestHeaders { HeaderConnection = "close" }, input.FrameContext); + var body = MessageBody.For(httpVersion, new FrameRequestHeaders(), input.FrameContext); var stream = new FrameRequestStream(); stream.StartAcceptingReads(body); - input.Add("Hello", true); + input.Add("Hello"); - var buffer1 = new byte[1024]; - Assert.Equal(0, stream.Read(buffer1, 0, 1024)); - } - } - - [Fact] - public async Task Http11NoContentLengthConnectionCloseAsync() - { - using (var input = new TestInput()) - { - var body = MessageBody.For(HttpVersion.Http11, new FrameRequestHeaders { HeaderConnection = "close" }, input.FrameContext); - var stream = new FrameRequestStream(); - stream.StartAcceptingReads(body); - - input.Add("Hello", true); - - var buffer1 = new byte[1024]; - Assert.Equal(0, await stream.ReadAsync(buffer1, 0, 1024)); + var buffer = new byte[1024]; + Assert.Equal(0, await stream.ReadAsync(buffer, 0, buffer.Length)); } } @@ -176,7 +208,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests input.Add(largeInput); // Add a smaller block to the end so that SocketInput attempts to return the large // block to the memory pool. - input.Add("Hello", fin: true); + input.Add("Hello"); var ms = new MemoryStream(); @@ -324,7 +356,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests await Assert.ThrowsAsync(() => body.CopyToAsync(writeStream)); - input.Add(data[1], fin: headers.HeaderConnection == "close"); + input.Add(data[1]); // "Hello " should have been consumed var readBuffer = new byte[6]; @@ -350,10 +382,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests var stream = new FrameRequestStream(); stream.StartAcceptingReads(body); - input.Add("Hello", true); + input.Add("Hello"); var buffer = new byte[1024]; - Assert.Equal(5, stream.Read(buffer, 0, 1024)); + Assert.Equal(5, stream.Read(buffer, 0, buffer.Length)); AssertASCII("Hello", new ArraySegment(buffer, 0, 5)); } } diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/TestInput.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/TestInput.cs index 50f8c9c30d..73f6f170bf 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/TestInput.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/TestInput.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.IO; using System.Text; using System.Threading; using System.Threading.Tasks; @@ -35,14 +36,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests public Frame FrameContext { get; set; } - public void Add(string text, bool fin = false) + public void Add(string text) { var data = Encoding.ASCII.GetBytes(text); Pipe.Writer.WriteAsync(data).Wait(); - if (fin) - { - Pipe.Writer.Complete(); - } } public void ProduceContinue() From 0fd885e5ebbffab28de9fe5f583a6f381725521f Mon Sep 17 00:00:00 2001 From: David Fowler Date: Sat, 8 Apr 2017 01:22:06 -0700 Subject: [PATCH 1193/1662] Signal the reader after aborting the connection (#1636) - This will give it a chance to unwind gracefully before failing with an invalid request. Fixes #1632 --- .../Internal/LibuvConnection.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvConnection.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvConnection.cs index 53c5f48dcc..d0a5563de1 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvConnection.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvConnection.cs @@ -217,8 +217,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal if (!normalRead) { - Input.Complete(error); var ignore = AbortAsync(error); + + // Complete after aborting the connection + Input.Complete(error); } } From 58284bde5c1980e62996df54ffc477f8215e446d Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Sat, 8 Apr 2017 01:35:02 -0700 Subject: [PATCH 1194/1662] Don't dispose WriteReqPool and PipeFactory too soon (#1633) --- .../Internal/LibuvConnectionContext.cs | 2 +- .../Internal/LibuvThread.cs | 40 +++-------- .../MaxRequestBufferSizeTests.cs | 72 +++++++++++++++++++ 3 files changed, 84 insertions(+), 30 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvConnectionContext.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvConnectionContext.cs index 6627376b7d..4f76cc097f 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvConnectionContext.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvConnectionContext.cs @@ -23,7 +23,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal public IPEndPoint RemoteEndPoint { get; set; } public IPEndPoint LocalEndPoint { get; set; } - public PipeFactory PipeFactory => ListenerContext.Thread.PipelineFactory; + public PipeFactory PipeFactory => ListenerContext.Thread.PipeFactory; public IScheduler InputWriterScheduler => ListenerContext.Thread; public IScheduler OutputReaderScheduler => ListenerContext.Thread; diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvThread.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvThread.cs index 393aaa6af5..11b279c66f 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvThread.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvThread.cs @@ -69,7 +69,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal #endif QueueCloseHandle = PostCloseHandle; QueueCloseAsyncHandle = EnqueueCloseHandle; - PipelineFactory = new PipeFactory(); + PipeFactory = new PipeFactory(); WriteReqPool = new WriteReqPool(this, _log); ConnectionManager = new LibuvConnectionManager(this); } @@ -83,7 +83,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal public UvLoopHandle Loop { get { return _loop; } } - public PipeFactory PipelineFactory { get; } + public PipeFactory PipeFactory { get; } public LibuvConnectionManager ConnectionManager { get; } @@ -140,7 +140,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal } catch (ObjectDisposedException) { - // Until we rework this logic, ODEs are bound to happen sometimes. if (!await WaitAsync(_threadTcs.Task, stepTimeout).ConfigureAwait(false)) { _log.LogCritical($"{nameof(LibuvThread)}.{nameof(StopAsync)} failed to terminate libuv thread."); @@ -157,34 +156,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal private async Task DisposeConnectionsAsync() { - try + // Close and wait for all connections + if (!await ConnectionManager.WalkConnectionsAndCloseAsync(_shutdownTimeout).ConfigureAwait(false)) { - // Close and wait for all connections - if (!await ConnectionManager.WalkConnectionsAndCloseAsync(_shutdownTimeout).ConfigureAwait(false)) - { - _log.NotAllConnectionsClosedGracefully(); + _log.NotAllConnectionsClosedGracefully(); - if (!await ConnectionManager.WalkConnectionsAndAbortAsync(TimeSpan.FromSeconds(1)).ConfigureAwait(false)) - { - _log.NotAllConnectionsAborted(); - } + if (!await ConnectionManager.WalkConnectionsAndAbortAsync(TimeSpan.FromSeconds(1)).ConfigureAwait(false)) + { + _log.NotAllConnectionsAborted(); } - - var result = await WaitAsync(PostAsync(state => - { - var listener = state; - listener.WriteReqPool.Dispose(); - }, - this), _shutdownTimeout).ConfigureAwait(false); - - if (!result) - { - _log.LogError(0, null, "Disposing write requests failed"); - } - } - finally - { - PipelineFactory.Dispose(); } } @@ -334,8 +314,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal } finally { - _threadTcs.SetResult(null); + PipeFactory.Dispose(); + WriteReqPool.Dispose(); thisHandle.Free(); + _threadTcs.SetResult(null); } } diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/MaxRequestBufferSizeTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/MaxRequestBufferSizeTests.cs index 8803ded61a..9c53d9e18d 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/MaxRequestBufferSizeTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/MaxRequestBufferSizeTests.cs @@ -172,6 +172,78 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } } + [Fact] + public async Task ServerShutsDownGracefullyWhenMaxRequestBufferSizeExceeded() + { + // Parameters + var data = new byte[_dataLength]; + var bytesWrittenTimeout = TimeSpan.FromMilliseconds(100); + var bytesWrittenPollingInterval = TimeSpan.FromMilliseconds(bytesWrittenTimeout.TotalMilliseconds / 10); + var maxSendSize = 4096; + + var startReadingRequestBody = new ManualResetEvent(false); + var clientFinishedSendingRequestBody = new ManualResetEvent(false); + var lastBytesWritten = DateTime.MaxValue; + + using (var host = StartWebHost(16 * 1024, data, false, startReadingRequestBody, clientFinishedSendingRequestBody)) + { + var port = host.GetPort(); + using (var socket = CreateSocket(port)) + using (var stream = new NetworkStream(socket)) + { + await WritePostRequestHeaders(stream, data.Length); + + var bytesWritten = 0; + + Func sendFunc = async () => + { + while (bytesWritten < data.Length) + { + var size = Math.Min(data.Length - bytesWritten, maxSendSize); + await stream.WriteAsync(data, bytesWritten, size); + bytesWritten += size; + lastBytesWritten = DateTime.Now; + } + + clientFinishedSendingRequestBody.Set(); + }; + + var gnore = sendFunc(); + + // The minimum is (maxRequestBufferSize - maxSendSize + 1), since if bytesWritten is + // (maxRequestBufferSize - maxSendSize) or smaller, the client should be able to + // complete another send. + var minimumExpectedBytesWritten = (16 * 1024) - maxSendSize + 1; + + // The maximum is harder to determine, since there can be OS-level buffers in both the client + // and server, which allow the client to send more than maxRequestBufferSize before getting + // paused. We assume the combined buffers are smaller than the difference between + // data.Length and maxRequestBufferSize. + var maximumExpectedBytesWritten = data.Length - 1; + + // Block until the send task has gone a while without writing bytes AND + // the bytes written exceeds the minimum expected. This indicates the server buffer + // is full. + // + // If the send task is paused before the expected number of bytes have been + // written, keep waiting since the pause may have been caused by something else + // like a slow machine. + while ((DateTime.Now - lastBytesWritten) < bytesWrittenTimeout || + bytesWritten < minimumExpectedBytesWritten) + { + await Task.Delay(bytesWrittenPollingInterval); + } + + // Verify the number of bytes written before the client was paused. + Assert.InRange(bytesWritten, minimumExpectedBytesWritten, maximumExpectedBytesWritten); + + // Dispose host prior to closing connection to verify the server doesn't throw during shutdown + // if a connection no longer has alloc and read callbacks configured. + host.Dispose(); + } + } + } + private static IWebHost StartWebHost(long? maxRequestBufferSize, byte[] expectedBody, bool useConnectionAdapter, ManualResetEvent startReadingRequestBody, ManualResetEvent clientFinishedSendingRequestBody) { From d92c55dbfcd2b417cf7bef87caf813c4400c3bf8 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Sat, 8 Apr 2017 01:50:25 -0700 Subject: [PATCH 1195/1662] Fix spelling nit --- .../MaxRequestBufferSizeTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/MaxRequestBufferSizeTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/MaxRequestBufferSizeTests.cs index 9c53d9e18d..6452832639 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/MaxRequestBufferSizeTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/MaxRequestBufferSizeTests.cs @@ -208,7 +208,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests clientFinishedSendingRequestBody.Set(); }; - var gnore = sendFunc(); + var ignore = sendFunc(); // The minimum is (maxRequestBufferSize - maxSendSize + 1), since if bytesWritten is // (maxRequestBufferSize - maxSendSize) or smaller, the client should be able to From fb22629da619ddba79f907a26781f5fcf4c50f65 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Sun, 9 Apr 2017 07:45:26 +0100 Subject: [PATCH 1196/1662] Use Span.IndexOf rather than Contains (#1638) - Remove Contains method and use IndexOf (which is already vectorized) to look for CR in header values. --- .../Internal/Http/HttpParser.cs | 60 ++++--------------- 1 file changed, 11 insertions(+), 49 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/HttpParser.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/HttpParser.cs index f5ac574008..9b253fb20a 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/HttpParser.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/HttpParser.cs @@ -1,7 +1,6 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System.Numerics; using System.Runtime.CompilerServices; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Internal.System; @@ -379,13 +378,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http } // Check for CR in value - var i = valueStart + 1; - if (Contains(headerLine + i, valueEnd - i, ByteCR)) + var valueBuffer = new Span(headerLine + valueStart, valueEnd - valueStart + 1); + if (valueBuffer.IndexOf(ByteCR) >= 0) { RejectRequestHeader(headerLine, length); } // Ignore end whitespace + var lengthChanged = false; for (; valueEnd >= valueStart; valueEnd--) { var ch = headerLine[valueEnd]; @@ -393,50 +393,21 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { break; } + + lengthChanged = true; + } + + if (lengthChanged) + { + // Length changed + valueBuffer = new Span(headerLine + valueStart, valueEnd - valueStart + 1); } var nameBuffer = new Span(headerLine, nameEnd); - var valueBuffer = new Span(headerLine + valueStart, valueEnd - valueStart + 1); handler.OnHeader(nameBuffer, valueBuffer); } - [MethodImpl(MethodImplOptions.AggressiveInlining)] - private static unsafe bool Contains(byte* searchSpace, int length, byte value) - { - var i = 0; - if (Vector.IsHardwareAccelerated) - { - // Check Vector lengths - if (length - Vector.Count >= i) - { - var vValue = GetVector(value); - do - { - if (!Vector.Zero.Equals(Vector.Equals(vValue, Unsafe.Read>(searchSpace + i)))) - { - goto found; - } - - i += Vector.Count; - } while (length - Vector.Count >= i); - } - } - - // Check remaining for CR - for (; i <= length; i++) - { - var ch = searchSpace[i]; - if (ch == value) - { - goto found; - } - } - return false; - found: - return true; - } - [MethodImpl(MethodImplOptions.NoInlining)] private static bool TryGetNewLine(ref ReadableBuffer buffer, out ReadCursor found) { @@ -524,14 +495,5 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http public void Reset() { } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Vector GetVector(byte vectorByte) - { - // Vector .ctor doesn't become an intrinsic due to detection issue - // However this does cause it to become an intrinsic (with additional multiply and reg->reg copy) - // https://github.com/dotnet/coreclr/issues/7459#issuecomment-253965670 - return Vector.AsVectorByte(new Vector(vectorByte * 0x01010101u)); - } } } From 2863cca8ca0221bc935bdbad94c06414e72fa393 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Mon, 10 Apr 2017 00:02:18 +0100 Subject: [PATCH 1197/1662] FrameFeatureCollection benchmark (#1643) --- .../Internal/Http/Frame.Generated.cs | 4 +- .../FrameFeatureCollection.cs | 107 ++++++++++++++++++ .../FrameParsingOverheadBenchmark.cs | 49 -------- .../Mocks/NullParser.cs | 57 ++++++++++ tools/CodeGenerator/FrameFeatureCollection.cs | 4 +- 5 files changed, 168 insertions(+), 53 deletions(-) create mode 100644 test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameFeatureCollection.cs create mode 100644 test/Microsoft.AspNetCore.Server.Kestrel.Performance/Mocks/NullParser.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.Generated.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.Generated.cs index 181e54d667..28b0be9f78 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.Generated.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.Generated.cs @@ -63,7 +63,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http _currentIHttpSendFileFeature = null; } - private object FastFeatureGet(Type key) + internal object FastFeatureGet(Type key) { if (key == IHttpRequestFeatureType) { @@ -132,7 +132,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http return ExtraFeatureGet(key); } - private void FastFeatureSet(Type key, object feature) + internal void FastFeatureSet(Type key, object feature) { _featureRevision++; diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameFeatureCollection.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameFeatureCollection.cs new file mode 100644 index 0000000000..4115934774 --- /dev/null +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameFeatureCollection.cs @@ -0,0 +1,107 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using BenchmarkDotNet.Attributes; +using Microsoft.AspNetCore.Http.Features; +using Microsoft.AspNetCore.Server.Kestrel.Core; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; + +namespace Microsoft.AspNetCore.Server.Kestrel.Performance +{ + [Config(typeof(CoreConfig))] + public class FrameFeatureCollection + { + private readonly Frame _frame; + private IFeatureCollection _collection; + + [Benchmark(Baseline = true)] + public IHttpRequestFeature GetFirstViaFastFeature() + { + return (IHttpRequestFeature)GetFastFeature(typeof(IHttpRequestFeature)); + } + + [Benchmark] + public IHttpRequestFeature GetFirstViaType() + { + return (IHttpRequestFeature)Get(typeof(IHttpRequestFeature)); + } + + [Benchmark] + public IHttpRequestFeature GetFirstViaExtension() + { + return _collection.GetType(); + } + + [Benchmark] + public IHttpRequestFeature GetFirstViaGeneric() + { + return _collection.Get(); + } + + [Benchmark] + public IHttpSendFileFeature GetLastViaFastFeature() + { + return (IHttpSendFileFeature)GetFastFeature(typeof(IHttpSendFileFeature)); + } + + [Benchmark] + public IHttpSendFileFeature GetLastViaType() + { + return (IHttpSendFileFeature)Get(typeof(IHttpSendFileFeature)); + } + + [Benchmark] + public IHttpSendFileFeature GetLastViaExtension() + { + return _collection.GetType(); + } + + [Benchmark] + public IHttpSendFileFeature GetLastViaGeneric() + { + return _collection.Get (); + } + + private object Get(Type type) + { + return _collection[type]; + } + + private object GetFastFeature(Type type) + { + return _frame.FastFeatureGet(type); + } + + public FrameFeatureCollection() + { + var serviceContext = new ServiceContext + { + HttpParserFactory = _ => NullParser.Instance, + ServerOptions = new KestrelServerOptions() + }; + var frameContext = new FrameContext + { + ServiceContext = serviceContext, + ConnectionInformation = new MockConnectionInformation() + }; + + _frame = new Frame(application: null, frameContext: frameContext); + } + + [Setup] + public void Setup() + { + _collection = _frame; + } + + } + public static class IFeatureCollectionExtensions + { + public static T GetType(this IFeatureCollection collection) + { + return (T)collection[typeof(T)]; + } + } +} diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameParsingOverheadBenchmark.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameParsingOverheadBenchmark.cs index 1e05f8ea99..ac7f6869bf 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameParsingOverheadBenchmark.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameParsingOverheadBenchmark.cs @@ -1,12 +1,10 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System.Text; using BenchmarkDotNet.Attributes; using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; -using Microsoft.AspNetCore.Server.Kestrel.Internal.System; using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; namespace Microsoft.AspNetCore.Server.Kestrel.Performance @@ -100,52 +98,5 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance ErrorUtilities.ThrowInvalidRequestHeaders(); } } - - private class NullParser : IHttpParser - { - private readonly byte[] _startLine = Encoding.ASCII.GetBytes("GET /plaintext HTTP/1.1\r\n"); - private readonly byte[] _target = Encoding.ASCII.GetBytes("/plaintext"); - private readonly byte[] _hostHeaderName = Encoding.ASCII.GetBytes("Host"); - private readonly byte[] _hostHeaderValue = Encoding.ASCII.GetBytes("www.example.com"); - private readonly byte[] _acceptHeaderName = Encoding.ASCII.GetBytes("Accept"); - private readonly byte[] _acceptHeaderValue = Encoding.ASCII.GetBytes("text/plain,text/html;q=0.9,application/xhtml+xml;q=0.9,application/xml;q=0.8,*/*;q=0.7\r\n\r\n"); - private readonly byte[] _connectionHeaderName = Encoding.ASCII.GetBytes("Connection"); - private readonly byte[] _connectionHeaderValue = Encoding.ASCII.GetBytes("keep-alive"); - - public static readonly NullParser Instance = new NullParser(); - - public bool ParseHeaders(IHttpHeadersHandler handler, ReadableBuffer buffer, out ReadCursor consumed, out ReadCursor examined, out int consumedBytes) - { - handler.OnHeader(new Span(_hostHeaderName), new Span(_hostHeaderValue)); - handler.OnHeader(new Span(_acceptHeaderName), new Span(_acceptHeaderValue)); - handler.OnHeader(new Span(_connectionHeaderName), new Span(_connectionHeaderValue)); - - consumedBytes = 0; - consumed = buffer.Start; - examined = buffer.End; - - return true; - } - - public bool ParseRequestLine(IHttpRequestLineHandler handler, ReadableBuffer buffer, out ReadCursor consumed, out ReadCursor examined) - { - handler.OnStartLine(HttpMethod.Get, - HttpVersion.Http11, - new Span(_target), - new Span(_target), - Span.Empty, - Span.Empty, - false); - - consumed = buffer.Start; - examined = buffer.End; - - return true; - } - - public void Reset() - { - } - } } } diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Mocks/NullParser.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Mocks/NullParser.cs new file mode 100644 index 0000000000..d27bfc1f2b --- /dev/null +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Mocks/NullParser.cs @@ -0,0 +1,57 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System.Text; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Internal.System; +using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; + +namespace Microsoft.AspNetCore.Server.Kestrel.Performance +{ + public class NullParser : IHttpParser + { + private readonly byte[] _startLine = Encoding.ASCII.GetBytes("GET /plaintext HTTP/1.1\r\n"); + private readonly byte[] _target = Encoding.ASCII.GetBytes("/plaintext"); + private readonly byte[] _hostHeaderName = Encoding.ASCII.GetBytes("Host"); + private readonly byte[] _hostHeaderValue = Encoding.ASCII.GetBytes("www.example.com"); + private readonly byte[] _acceptHeaderName = Encoding.ASCII.GetBytes("Accept"); + private readonly byte[] _acceptHeaderValue = Encoding.ASCII.GetBytes("text/plain,text/html;q=0.9,application/xhtml+xml;q=0.9,application/xml;q=0.8,*/*;q=0.7\r\n\r\n"); + private readonly byte[] _connectionHeaderName = Encoding.ASCII.GetBytes("Connection"); + private readonly byte[] _connectionHeaderValue = Encoding.ASCII.GetBytes("keep-alive"); + + public static readonly NullParser Instance = new NullParser(); + + public bool ParseHeaders(IHttpHeadersHandler handler, ReadableBuffer buffer, out ReadCursor consumed, out ReadCursor examined, out int consumedBytes) + { + handler.OnHeader(new Span(_hostHeaderName), new Span(_hostHeaderValue)); + handler.OnHeader(new Span(_acceptHeaderName), new Span(_acceptHeaderValue)); + handler.OnHeader(new Span(_connectionHeaderName), new Span(_connectionHeaderValue)); + + consumedBytes = 0; + consumed = buffer.Start; + examined = buffer.End; + + return true; + } + + public bool ParseRequestLine(IHttpRequestLineHandler handler, ReadableBuffer buffer, out ReadCursor consumed, out ReadCursor examined) + { + handler.OnStartLine(HttpMethod.Get, + HttpVersion.Http11, + new Span(_target), + new Span(_target), + Span.Empty, + Span.Empty, + false); + + consumed = buffer.Start; + examined = buffer.End; + + return true; + } + + public void Reset() + { + } + } +} diff --git a/tools/CodeGenerator/FrameFeatureCollection.cs b/tools/CodeGenerator/FrameFeatureCollection.cs index e487a36a94..01b9c1cfa9 100644 --- a/tools/CodeGenerator/FrameFeatureCollection.cs +++ b/tools/CodeGenerator/FrameFeatureCollection.cs @@ -87,7 +87,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http _current{feature.Name} = null;")} }} - private object FastFeatureGet(Type key) + internal object FastFeatureGet(Type key) {{{Each(allFeatures, feature => $@" if (key == {feature.Name}Type) {{ @@ -96,7 +96,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http return ExtraFeatureGet(key); }} - private void FastFeatureSet(Type key, object feature) + internal void FastFeatureSet(Type key, object feature) {{ _featureRevision++; {Each(allFeatures, feature => $@" From 1faaefef306b96df1fcafaaafeadac0322956fa6 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Mon, 10 Apr 2017 11:43:12 -0700 Subject: [PATCH 1198/1662] Fix Libuv.Tests directory name (#1646) --- KestrelHttpServer.sln | 2 +- .../ConnectionTests.cs | 0 .../LibuvOutputConsumerTests.cs | 0 .../LibuvTransportFactoryTests.cs | 0 .../LibuvTransportOptionsTests.cs | 0 .../LibuvTransportTests.cs | 0 .../ListenerPrimaryTests.cs | 0 ...osoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests.csproj | 0 .../MultipleLoopTests.cs | 0 .../NetworkingTests.cs | 0 .../TestHelpers/MockConnection.cs | 0 .../TestHelpers/MockConnectionHandler.cs | 0 .../TestHelpers/MockLibuv.cs | 0 .../TestHelpers/MockSocket.cs | 0 .../TestHelpers/TestConstants.cs | 0 .../TestHelpers/TestLibuvTransportContext.cs | 0 .../UvStreamHandleTests.cs | 0 .../UvTimerHandleTests.cs | 0 .../xunit.runner.json | 0 19 files changed, 1 insertion(+), 1 deletion(-) rename test/{Microsoft.AspNetCore.Server.Transport.Libuv.Tests => Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests}/ConnectionTests.cs (100%) rename test/{Microsoft.AspNetCore.Server.Transport.Libuv.Tests => Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests}/LibuvOutputConsumerTests.cs (100%) rename test/{Microsoft.AspNetCore.Server.Transport.Libuv.Tests => Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests}/LibuvTransportFactoryTests.cs (100%) rename test/{Microsoft.AspNetCore.Server.Transport.Libuv.Tests => Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests}/LibuvTransportOptionsTests.cs (100%) rename test/{Microsoft.AspNetCore.Server.Transport.Libuv.Tests => Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests}/LibuvTransportTests.cs (100%) rename test/{Microsoft.AspNetCore.Server.Transport.Libuv.Tests => Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests}/ListenerPrimaryTests.cs (100%) rename test/{Microsoft.AspNetCore.Server.Transport.Libuv.Tests => Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests}/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests.csproj (100%) rename test/{Microsoft.AspNetCore.Server.Transport.Libuv.Tests => Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests}/MultipleLoopTests.cs (100%) rename test/{Microsoft.AspNetCore.Server.Transport.Libuv.Tests => Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests}/NetworkingTests.cs (100%) rename test/{Microsoft.AspNetCore.Server.Transport.Libuv.Tests => Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests}/TestHelpers/MockConnection.cs (100%) rename test/{Microsoft.AspNetCore.Server.Transport.Libuv.Tests => Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests}/TestHelpers/MockConnectionHandler.cs (100%) rename test/{Microsoft.AspNetCore.Server.Transport.Libuv.Tests => Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests}/TestHelpers/MockLibuv.cs (100%) rename test/{Microsoft.AspNetCore.Server.Transport.Libuv.Tests => Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests}/TestHelpers/MockSocket.cs (100%) rename test/{Microsoft.AspNetCore.Server.Transport.Libuv.Tests => Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests}/TestHelpers/TestConstants.cs (100%) rename test/{Microsoft.AspNetCore.Server.Transport.Libuv.Tests => Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests}/TestHelpers/TestLibuvTransportContext.cs (100%) rename test/{Microsoft.AspNetCore.Server.Transport.Libuv.Tests => Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests}/UvStreamHandleTests.cs (100%) rename test/{Microsoft.AspNetCore.Server.Transport.Libuv.Tests => Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests}/UvTimerHandleTests.cs (100%) rename test/{Microsoft.AspNetCore.Server.Transport.Libuv.Tests => Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests}/xunit.runner.json (100%) diff --git a/KestrelHttpServer.sln b/KestrelHttpServer.sln index 5119c68fa0..a2fc4e3108 100644 --- a/KestrelHttpServer.sln +++ b/KestrelHttpServer.sln @@ -64,7 +64,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Server EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions", "src\Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions\Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.csproj", "{2E9CB89D-EC8F-4DD9-A72B-08D5BABF752D}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests", "test\Microsoft.AspNetCore.Server.Transport.Libuv.Tests\Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests.csproj", "{D95A7EC3-48AC-4D03-B2E2-0DA3E13BD3A4}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests", "test\Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests\Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests.csproj", "{D95A7EC3-48AC-4D03-B2E2-0DA3E13BD3A4}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Server.Kestrel.Tests", "test\Microsoft.AspNetCore.Server.Kestrel.Tests\Microsoft.AspNetCore.Server.Kestrel.Tests.csproj", "{4F1C30F8-CCAA-48D7-9DF6-2A84021F5BCC}" EndProject diff --git a/test/Microsoft.AspNetCore.Server.Transport.Libuv.Tests/ConnectionTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/ConnectionTests.cs similarity index 100% rename from test/Microsoft.AspNetCore.Server.Transport.Libuv.Tests/ConnectionTests.cs rename to test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/ConnectionTests.cs diff --git a/test/Microsoft.AspNetCore.Server.Transport.Libuv.Tests/LibuvOutputConsumerTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/LibuvOutputConsumerTests.cs similarity index 100% rename from test/Microsoft.AspNetCore.Server.Transport.Libuv.Tests/LibuvOutputConsumerTests.cs rename to test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/LibuvOutputConsumerTests.cs diff --git a/test/Microsoft.AspNetCore.Server.Transport.Libuv.Tests/LibuvTransportFactoryTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/LibuvTransportFactoryTests.cs similarity index 100% rename from test/Microsoft.AspNetCore.Server.Transport.Libuv.Tests/LibuvTransportFactoryTests.cs rename to test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/LibuvTransportFactoryTests.cs diff --git a/test/Microsoft.AspNetCore.Server.Transport.Libuv.Tests/LibuvTransportOptionsTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/LibuvTransportOptionsTests.cs similarity index 100% rename from test/Microsoft.AspNetCore.Server.Transport.Libuv.Tests/LibuvTransportOptionsTests.cs rename to test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/LibuvTransportOptionsTests.cs diff --git a/test/Microsoft.AspNetCore.Server.Transport.Libuv.Tests/LibuvTransportTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/LibuvTransportTests.cs similarity index 100% rename from test/Microsoft.AspNetCore.Server.Transport.Libuv.Tests/LibuvTransportTests.cs rename to test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/LibuvTransportTests.cs diff --git a/test/Microsoft.AspNetCore.Server.Transport.Libuv.Tests/ListenerPrimaryTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/ListenerPrimaryTests.cs similarity index 100% rename from test/Microsoft.AspNetCore.Server.Transport.Libuv.Tests/ListenerPrimaryTests.cs rename to test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/ListenerPrimaryTests.cs diff --git a/test/Microsoft.AspNetCore.Server.Transport.Libuv.Tests/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests.csproj b/test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests.csproj similarity index 100% rename from test/Microsoft.AspNetCore.Server.Transport.Libuv.Tests/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests.csproj rename to test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests.csproj diff --git a/test/Microsoft.AspNetCore.Server.Transport.Libuv.Tests/MultipleLoopTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/MultipleLoopTests.cs similarity index 100% rename from test/Microsoft.AspNetCore.Server.Transport.Libuv.Tests/MultipleLoopTests.cs rename to test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/MultipleLoopTests.cs diff --git a/test/Microsoft.AspNetCore.Server.Transport.Libuv.Tests/NetworkingTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/NetworkingTests.cs similarity index 100% rename from test/Microsoft.AspNetCore.Server.Transport.Libuv.Tests/NetworkingTests.cs rename to test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/NetworkingTests.cs diff --git a/test/Microsoft.AspNetCore.Server.Transport.Libuv.Tests/TestHelpers/MockConnection.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/TestHelpers/MockConnection.cs similarity index 100% rename from test/Microsoft.AspNetCore.Server.Transport.Libuv.Tests/TestHelpers/MockConnection.cs rename to test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/TestHelpers/MockConnection.cs diff --git a/test/Microsoft.AspNetCore.Server.Transport.Libuv.Tests/TestHelpers/MockConnectionHandler.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/TestHelpers/MockConnectionHandler.cs similarity index 100% rename from test/Microsoft.AspNetCore.Server.Transport.Libuv.Tests/TestHelpers/MockConnectionHandler.cs rename to test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/TestHelpers/MockConnectionHandler.cs diff --git a/test/Microsoft.AspNetCore.Server.Transport.Libuv.Tests/TestHelpers/MockLibuv.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/TestHelpers/MockLibuv.cs similarity index 100% rename from test/Microsoft.AspNetCore.Server.Transport.Libuv.Tests/TestHelpers/MockLibuv.cs rename to test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/TestHelpers/MockLibuv.cs diff --git a/test/Microsoft.AspNetCore.Server.Transport.Libuv.Tests/TestHelpers/MockSocket.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/TestHelpers/MockSocket.cs similarity index 100% rename from test/Microsoft.AspNetCore.Server.Transport.Libuv.Tests/TestHelpers/MockSocket.cs rename to test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/TestHelpers/MockSocket.cs diff --git a/test/Microsoft.AspNetCore.Server.Transport.Libuv.Tests/TestHelpers/TestConstants.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/TestHelpers/TestConstants.cs similarity index 100% rename from test/Microsoft.AspNetCore.Server.Transport.Libuv.Tests/TestHelpers/TestConstants.cs rename to test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/TestHelpers/TestConstants.cs diff --git a/test/Microsoft.AspNetCore.Server.Transport.Libuv.Tests/TestHelpers/TestLibuvTransportContext.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/TestHelpers/TestLibuvTransportContext.cs similarity index 100% rename from test/Microsoft.AspNetCore.Server.Transport.Libuv.Tests/TestHelpers/TestLibuvTransportContext.cs rename to test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/TestHelpers/TestLibuvTransportContext.cs diff --git a/test/Microsoft.AspNetCore.Server.Transport.Libuv.Tests/UvStreamHandleTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/UvStreamHandleTests.cs similarity index 100% rename from test/Microsoft.AspNetCore.Server.Transport.Libuv.Tests/UvStreamHandleTests.cs rename to test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/UvStreamHandleTests.cs diff --git a/test/Microsoft.AspNetCore.Server.Transport.Libuv.Tests/UvTimerHandleTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/UvTimerHandleTests.cs similarity index 100% rename from test/Microsoft.AspNetCore.Server.Transport.Libuv.Tests/UvTimerHandleTests.cs rename to test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/UvTimerHandleTests.cs diff --git a/test/Microsoft.AspNetCore.Server.Transport.Libuv.Tests/xunit.runner.json b/test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/xunit.runner.json similarity index 100% rename from test/Microsoft.AspNetCore.Server.Transport.Libuv.Tests/xunit.runner.json rename to test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/xunit.runner.json From d29e4d4cf09bc5dc75a706f96ecb5edb1ea118b7 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Tue, 11 Apr 2017 03:30:18 +0100 Subject: [PATCH 1199/1662] Specialized struct generics rather than interface (#1640) Changed the IHttpParser interface to be generic. This lets use a struct to get better code generation and also should allow us to inline calls back into the handler from the parser. --- .../Adapter/Internal/StreamSocketOutput.cs | 2 +- .../Internal/Http/Frame.cs | 17 +++++++------- .../Internal/Http/FrameAdapter.cs | 23 +++++++++++++++++++ .../Internal/Http/HttpParser.cs | 10 ++++---- .../Internal/Http/IHttpParser.cs | 6 ++--- .../Internal/Http/ISocketOutput.cs | 2 +- .../Internal/ServiceContext.cs | 2 +- .../KestrelServer.cs | 2 +- .../FrameResponseHeadersTests.cs | 23 ------------------- .../HttpParserTests.cs | 3 +-- .../OutputProducerTests.cs | 4 ++-- .../FrameFeatureCollection.cs | 2 +- .../FrameParsingOverheadBenchmark.cs | 2 +- .../FrameWritingBenchmark.cs | 2 +- .../KestrelHttpParserBenchmark.cs | 22 +++++++++++++++--- .../Mocks/NullParser.cs | 8 +++---- .../RequestParsingBenchmark.cs | 2 +- .../ResponseHeaderCollectionBenchmark.cs | 2 +- .../ResponseHeadersWritingBenchmark.cs | 2 +- test/shared/MockSocketOutput.cs | 2 +- test/shared/TestServiceContext.cs | 2 +- 21 files changed, 78 insertions(+), 62 deletions(-) create mode 100644 src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameAdapter.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/Internal/StreamSocketOutput.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/Internal/StreamSocketOutput.cs index d7e7529f6d..926f0d1cc1 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/Internal/StreamSocketOutput.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/Internal/StreamSocketOutput.cs @@ -83,7 +83,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal return WriteAsync(default(ArraySegment), chunk: false, cancellationToken: cancellationToken); } - public void Write(Action callback, T state) + public void Write(Action callback, T state) where T : struct { lock (_sync) { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.cs index d21c4c5563..9c4035ff8e 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.cs @@ -26,7 +26,7 @@ using Microsoft.Extensions.Primitives; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { - public abstract partial class Frame : IFrameControl, IHttpRequestLineHandler, IHttpHeadersHandler + public abstract partial class Frame : IFrameControl { private const byte ByteAsterisk = (byte)'*'; private const byte ByteForwardSlash = (byte)'/'; @@ -34,7 +34,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http private static readonly ArraySegment _endChunkedResponseBytes = CreateAsciiByteArraySegment("0\r\n\r\n"); private static readonly ArraySegment _continueBytes = CreateAsciiByteArraySegment("HTTP/1.1 100 Continue\r\n\r\n"); - private static readonly Action _writeHeaders = WriteResponseHeaders; + private static readonly Action _writeHeaders = WriteResponseHeaders; private static readonly byte[] _bytesConnectionClose = Encoding.ASCII.GetBytes("\r\nConnection: close"); private static readonly byte[] _bytesConnectionKeepAlive = Encoding.ASCII.GetBytes("\r\nConnection: keep-alive"); @@ -80,7 +80,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http protected long _responseBytesWritten; private readonly FrameContext _frameContext; - private readonly IHttpParser _parser; + private readonly IHttpParser _parser; public Frame(FrameContext frameContext) { @@ -88,7 +88,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http ServerOptions = ServiceContext.ServerOptions; - _parser = ServiceContext.HttpParserFactory(this); + _parser = ServiceContext.HttpParserFactory(new FrameAdapter(this)); FrameControl = this; _keepAliveMilliseconds = (long)ServerOptions.Limits.KeepAliveTimeout.TotalMilliseconds; @@ -988,11 +988,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http responseHeaders.SetRawDate(dateHeaderValues.String, dateHeaderValues.Bytes); } - Output.Write(_writeHeaders, this); + Output.Write(_writeHeaders, new FrameAdapter(this)); } - private static void WriteResponseHeaders(WritableBuffer writableBuffer, Frame frame) + private static void WriteResponseHeaders(WritableBuffer writableBuffer, FrameAdapter frameAdapter) { + var frame = frameAdapter.Frame; var writer = new WritableBufferWriter(writableBuffer); var responseHeaders = frame.FrameResponseHeaders; @@ -1050,7 +1051,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http overLength = true; } - var result = _parser.ParseRequestLine(this, buffer, out consumed, out examined); + var result = _parser.ParseRequestLine(new FrameAdapter(this), buffer, out consumed, out examined); if (!result && overLength) { RejectRequest(RequestRejectionReason.RequestLineTooLong); @@ -1072,7 +1073,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http overLength = true; } - var result = _parser.ParseHeaders(this, buffer, out consumed, out examined, out var consumedBytes); + var result = _parser.ParseHeaders(new FrameAdapter(this), buffer, out consumed, out examined, out var consumedBytes); _remainingRequestHeadersBytesAllowed -= consumedBytes; if (!result && overLength) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameAdapter.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameAdapter.cs new file mode 100644 index 0000000000..6659b83bf8 --- /dev/null +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameAdapter.cs @@ -0,0 +1,23 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using Microsoft.AspNetCore.Server.Kestrel.Internal.System; + +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http +{ + public struct FrameAdapter : IHttpRequestLineHandler, IHttpHeadersHandler + { + public Frame Frame; + + public FrameAdapter(Frame frame) + { + Frame = frame; + } + + public void OnHeader(Span name, Span value) + => Frame.OnHeader(name, value); + + public void OnStartLine(HttpMethod method, HttpVersion version, Span target, Span path, Span query, Span customMethod, bool pathEncoded) + => Frame.OnStartLine(method, version, target, path, query, customMethod, pathEncoded); + } +} diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/HttpParser.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/HttpParser.cs index 9b253fb20a..43a7d94990 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/HttpParser.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/HttpParser.cs @@ -9,7 +9,7 @@ using Microsoft.Extensions.Logging; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { - public class HttpParser : IHttpParser + public class HttpParser : IHttpParser where TRequestHandler : IHttpHeadersHandler, IHttpRequestLineHandler { public HttpParser(IKestrelTrace log) { @@ -27,7 +27,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http private const byte ByteQuestionMark = (byte)'?'; private const byte BytePercentage = (byte)'%'; - public unsafe bool ParseRequestLine(IHttpRequestLineHandler handler, ReadableBuffer buffer, out ReadCursor consumed, out ReadCursor examined) + public unsafe bool ParseRequestLine(TRequestHandler handler, ReadableBuffer buffer, out ReadCursor consumed, out ReadCursor examined) { consumed = buffer.Start; examined = buffer.End; @@ -66,7 +66,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http return true; } - private unsafe void ParseRequestLine(IHttpRequestLineHandler handler, byte* data, int length) + private unsafe void ParseRequestLine(TRequestHandler handler, byte* data, int length) { int offset; Span customMethod = default(Span); @@ -183,7 +183,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http handler.OnStartLine(method, httpVersion, targetBuffer, pathBuffer, query, customMethod, pathEncoded); } - public unsafe bool ParseHeaders(IHttpHeadersHandler handler, ReadableBuffer buffer, out ReadCursor consumed, out ReadCursor examined, out int consumedBytes) + public unsafe bool ParseHeaders(TRequestHandler handler, ReadableBuffer buffer, out ReadCursor consumed, out ReadCursor examined, out int consumedBytes) { consumed = buffer.Start; examined = buffer.End; @@ -346,7 +346,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http } [MethodImpl(MethodImplOptions.AggressiveInlining)] - private unsafe void TakeSingleHeader(byte* headerLine, int length, IHttpHeadersHandler handler) + private unsafe void TakeSingleHeader(byte* headerLine, int length, TRequestHandler handler) { // Skip CR, LF from end position var valueEnd = length - 3; diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/IHttpParser.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/IHttpParser.cs index 8473fc4cc3..46dfc1b34b 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/IHttpParser.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/IHttpParser.cs @@ -5,11 +5,11 @@ using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { - public interface IHttpParser + public interface IHttpParser where TRequestHandler : IHttpHeadersHandler, IHttpRequestLineHandler { - bool ParseRequestLine(IHttpRequestLineHandler handler, ReadableBuffer buffer, out ReadCursor consumed, out ReadCursor examined); + bool ParseRequestLine(TRequestHandler handler, ReadableBuffer buffer, out ReadCursor consumed, out ReadCursor examined); - bool ParseHeaders(IHttpHeadersHandler handler, ReadableBuffer buffer, out ReadCursor consumed, out ReadCursor examined, out int consumedBytes); + bool ParseHeaders(TRequestHandler handler, ReadableBuffer buffer, out ReadCursor consumed, out ReadCursor examined, out int consumedBytes); void Reset(); } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/ISocketOutput.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/ISocketOutput.cs index d12bd67310..139a5000a0 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/ISocketOutput.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/ISocketOutput.cs @@ -17,6 +17,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http Task WriteAsync(ArraySegment buffer, bool chunk = false, CancellationToken cancellationToken = default(CancellationToken)); void Flush(); Task FlushAsync(CancellationToken cancellationToken = default(CancellationToken)); - void Write(Action write, T state); + void Write(Action write, T state) where T : struct; } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/ServiceContext.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/ServiceContext.cs index 41a37f2fe5..4df0cb751f 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/ServiceContext.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/ServiceContext.cs @@ -13,7 +13,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal public IThreadPool ThreadPool { get; set; } - public Func HttpParserFactory { get; set; } + public Func> HttpParserFactory { get; set; } public DateHeaderValueManager DateHeaderValueManager { get; set; } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/KestrelServer.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/KestrelServer.cs index 8cb36edf33..d5962ee0a1 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/KestrelServer.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/KestrelServer.cs @@ -101,7 +101,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core var serviceContext = new ServiceContext { Log = trace, - HttpParserFactory = frame => new HttpParser(frame.ServiceContext.Log), + HttpParserFactory = frameParser => new HttpParser(frameParser.Frame.ServiceContext.Log), ThreadPool = threadPool, DateHeaderValueManager = _dateHeaderValueManager, ServerOptions = Options diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameResponseHeadersTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameResponseHeadersTests.cs index c36da4188f..2d6f6bb706 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameResponseHeadersTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameResponseHeadersTests.cs @@ -256,28 +256,5 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests "42,000", "42.000", }; - - private class NoopHttpParser : IHttpParser - { - public bool ParseHeaders(IHttpHeadersHandler handler, ReadableBuffer buffer, out ReadCursor consumed, out ReadCursor examined, out int consumedBytes) - { - consumed = buffer.Start; - examined = buffer.End; - consumedBytes = 0; - return false; - } - - public bool ParseRequestLine(IHttpRequestLineHandler handler, ReadableBuffer buffer, out ReadCursor consumed, out ReadCursor examined) - { - consumed = buffer.Start; - examined = buffer.End; - return false; - } - - public void Reset() - { - - } - } } } \ No newline at end of file diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/HttpParserTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/HttpParserTests.cs index 3600be4c40..2a953005cc 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/HttpParserTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/HttpParserTests.cs @@ -5,7 +5,6 @@ using System.Collections.Generic; using System.Linq; using System.Text; using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Internal.System; @@ -418,7 +417,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests Assert.Equal(buffer.End, examined); } - private IHttpParser CreateParser(IKestrelTrace log) => new HttpParser(log); + private IHttpParser CreateParser(IKestrelTrace log) => new HttpParser(log); public static IEnumerable RequestLineValidData => HttpParsingData.RequestLineValidData; diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/OutputProducerTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/OutputProducerTests.cs index ff5591b109..e96126d087 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/OutputProducerTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/OutputProducerTests.cs @@ -38,11 +38,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests var called = false; - ((ISocketOutput)socketOutput).Write((buffer, state) => + ((ISocketOutput)socketOutput).Write((buffer, state) => { called = true; }, - null); + 0); Assert.False(called); } diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameFeatureCollection.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameFeatureCollection.cs index 4115934774..bd4ec5ae97 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameFeatureCollection.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameFeatureCollection.cs @@ -78,7 +78,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance { var serviceContext = new ServiceContext { - HttpParserFactory = _ => NullParser.Instance, + HttpParserFactory = _ => NullParser.Instance, ServerOptions = new KestrelServerOptions() }; var frameContext = new FrameContext diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameParsingOverheadBenchmark.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameParsingOverheadBenchmark.cs index ac7f6869bf..bb01a4fc01 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameParsingOverheadBenchmark.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameParsingOverheadBenchmark.cs @@ -22,7 +22,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance { var serviceContext = new ServiceContext { - HttpParserFactory = _ => NullParser.Instance, + HttpParserFactory = _ => NullParser.Instance, ServerOptions = new KestrelServerOptions() }; var frameContext = new FrameContext diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameWritingBenchmark.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameWritingBenchmark.cs index 01f1b008fa..3755e5df5c 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameWritingBenchmark.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameWritingBenchmark.cs @@ -94,7 +94,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance DateHeaderValueManager = new DateHeaderValueManager(), ServerOptions = new KestrelServerOptions(), Log = new MockTrace(), - HttpParserFactory = f => new HttpParser(log: null) + HttpParserFactory = f => new HttpParser(log: null) }; var frameContext = new FrameContext { diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/KestrelHttpParserBenchmark.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/KestrelHttpParserBenchmark.cs index d7e3e89511..c19bd6ddec 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/KestrelHttpParserBenchmark.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/KestrelHttpParserBenchmark.cs @@ -12,7 +12,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance public class KestrelHttpParserBenchmark : IHttpRequestLineHandler, IHttpHeadersHandler { - private readonly HttpParser _parser = new HttpParser(log: null); + private readonly HttpParser _parser = new HttpParser(log: null); private ReadableBuffer _buffer; @@ -53,14 +53,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance private void ParseData() { - if (!_parser.ParseRequestLine(this, _buffer, out var consumed, out var examined)) + if (!_parser.ParseRequestLine(new Adapter(this), _buffer, out var consumed, out var examined)) { ErrorUtilities.ThrowInvalidRequestHeaders(); } _buffer = _buffer.Slice(consumed, _buffer.End); - if (!_parser.ParseHeaders(this, _buffer, out consumed, out examined, out var consumedBytes)) + if (!_parser.ParseHeaders(new Adapter(this), _buffer, out consumed, out examined, out var consumedBytes)) { ErrorUtilities.ThrowInvalidRequestHeaders(); } @@ -73,5 +73,21 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance public void OnHeader(Span name, Span value) { } + + private struct Adapter : IHttpRequestLineHandler, IHttpHeadersHandler + { + public KestrelHttpParserBenchmark RequestHandler; + + public Adapter(KestrelHttpParserBenchmark requestHandler) + { + RequestHandler = requestHandler; + } + + public void OnHeader(Span name, Span value) + => RequestHandler.OnHeader(name, value); + + public void OnStartLine(HttpMethod method, HttpVersion version, Span target, Span path, Span query, Span customMethod, bool pathEncoded) + => RequestHandler.OnStartLine(method, version, target, path, query, customMethod, pathEncoded); + } } } diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Mocks/NullParser.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Mocks/NullParser.cs index d27bfc1f2b..54d71cf795 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Mocks/NullParser.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Mocks/NullParser.cs @@ -8,7 +8,7 @@ using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; namespace Microsoft.AspNetCore.Server.Kestrel.Performance { - public class NullParser : IHttpParser + public class NullParser : IHttpParser where TRequestHandler : struct, IHttpHeadersHandler, IHttpRequestLineHandler { private readonly byte[] _startLine = Encoding.ASCII.GetBytes("GET /plaintext HTTP/1.1\r\n"); private readonly byte[] _target = Encoding.ASCII.GetBytes("/plaintext"); @@ -19,9 +19,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance private readonly byte[] _connectionHeaderName = Encoding.ASCII.GetBytes("Connection"); private readonly byte[] _connectionHeaderValue = Encoding.ASCII.GetBytes("keep-alive"); - public static readonly NullParser Instance = new NullParser(); + public static readonly NullParser Instance = new NullParser(); - public bool ParseHeaders(IHttpHeadersHandler handler, ReadableBuffer buffer, out ReadCursor consumed, out ReadCursor examined, out int consumedBytes) + public bool ParseHeaders(TRequestHandler handler, ReadableBuffer buffer, out ReadCursor consumed, out ReadCursor examined, out int consumedBytes) { handler.OnHeader(new Span(_hostHeaderName), new Span(_hostHeaderValue)); handler.OnHeader(new Span(_acceptHeaderName), new Span(_acceptHeaderValue)); @@ -34,7 +34,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance return true; } - public bool ParseRequestLine(IHttpRequestLineHandler handler, ReadableBuffer buffer, out ReadCursor consumed, out ReadCursor examined) + public bool ParseRequestLine(TRequestHandler handler, ReadableBuffer buffer, out ReadCursor consumed, out ReadCursor examined) { handler.OnStartLine(HttpMethod.Get, HttpVersion.Http11, diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsingBenchmark.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsingBenchmark.cs index d759bccc02..593b4b8d46 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsingBenchmark.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsingBenchmark.cs @@ -23,7 +23,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance { var serviceContext = new ServiceContext { - HttpParserFactory = f => new HttpParser(f.ServiceContext.Log), + HttpParserFactory = f => new HttpParser(f.Frame.ServiceContext.Log), ServerOptions = new KestrelServerOptions() }; var frameContext = new FrameContext diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/ResponseHeaderCollectionBenchmark.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/ResponseHeaderCollectionBenchmark.cs index 0d32ed7079..9aaf5a61f5 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/ResponseHeaderCollectionBenchmark.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/ResponseHeaderCollectionBenchmark.cs @@ -170,7 +170,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance { var serviceContext = new ServiceContext { - HttpParserFactory = f => new HttpParser(f.ServiceContext.Log), + HttpParserFactory = f => new HttpParser(f.Frame.ServiceContext.Log), ServerOptions = new KestrelServerOptions() }; var frameContext = new FrameContext diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/ResponseHeadersWritingBenchmark.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/ResponseHeadersWritingBenchmark.cs index da56c4cc0b..5d5db64188 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/ResponseHeadersWritingBenchmark.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/ResponseHeadersWritingBenchmark.cs @@ -120,7 +120,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance DateHeaderValueManager = new DateHeaderValueManager(), ServerOptions = new KestrelServerOptions(), Log = new MockTrace(), - HttpParserFactory = f => new HttpParser(log: null) + HttpParserFactory = f => new HttpParser(log: null) }; var frameContext = new FrameContext diff --git a/test/shared/MockSocketOutput.cs b/test/shared/MockSocketOutput.cs index f213514434..9089bca83d 100644 --- a/test/shared/MockSocketOutput.cs +++ b/test/shared/MockSocketOutput.cs @@ -34,7 +34,7 @@ namespace Microsoft.AspNetCore.Testing return TaskCache.CompletedTask; } - public void Write(Action write, T state) + public void Write(Action write, T state) where T : struct { } diff --git a/test/shared/TestServiceContext.cs b/test/shared/TestServiceContext.cs index bf8e8eed40..808a03998d 100644 --- a/test/shared/TestServiceContext.cs +++ b/test/shared/TestServiceContext.cs @@ -18,7 +18,7 @@ namespace Microsoft.AspNetCore.Testing ThreadPool = new LoggingThreadPool(Log); DateHeaderValueManager = new DateHeaderValueManager(systemClock: new MockSystemClock()); DateHeaderValue = DateHeaderValueManager.GetDateHeaderValues().String; - HttpParserFactory = frame => new HttpParser(frame.ServiceContext.Log); + HttpParserFactory = frameAdapter => new HttpParser(frameAdapter.Frame.ServiceContext.Log); ServerOptions = new KestrelServerOptions { AddServerHeader = false From 99278c469161370b1015c67d18ae9388591a49af Mon Sep 17 00:00:00 2001 From: Mike Harder Date: Mon, 10 Apr 2017 22:03:00 -0700 Subject: [PATCH 1200/1662] Workaround for "Explicit RID still required for .NET Framework test projects" - Addresses #1617 --- ...t.AspNetCore.Server.Kestrel.Transport.Libuv.Tests.csproj | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests.csproj b/test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests.csproj index ceb08babf0..fb84173f97 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests.csproj +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests.csproj @@ -7,6 +7,12 @@ netcoreapp2.0 x64 true + + + exe From db159190bd42db998485502dd5e65676db640719 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Tue, 11 Apr 2017 23:13:59 -0700 Subject: [PATCH 1201/1662] Don't fail tests if port 5000 is in use (#1650) --- .../AddressRegistrationTests.cs | 37 +++++++++++++++---- 1 file changed, 29 insertions(+), 8 deletions(-) diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs index 1849113b0a..dcdbaa67a3 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs @@ -34,6 +34,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests await RegisterAddresses_Success(addressInput, testUrls); } + [ConditionalTheory, MemberData(nameof(AddressRegistrationDataIPv4Port5000Default))] + [PortSupportedCondition(5000)] + public async Task RegisterAddresses_IPv4Port5000Default_Success(string addressInput, Func testUrls) + { + await RegisterAddresses_Success(addressInput, testUrls); + } + [ConditionalTheory, MemberData(nameof(AddressRegistrationDataIPv4Port80))] [PortSupportedCondition(80)] public async Task RegisterAddresses_IPv4Port80_Success(string addressInput, Func testUrls) @@ -63,6 +70,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests await RegisterAddresses_Success(addressInput, testUrls); } + [ConditionalTheory, MemberData(nameof(AddressRegistrationDataIPv6Port5000Default))] + [IPv6SupportedCondition] + [PortSupportedCondition(5000)] + public async Task RegisterAddresses_IPv6Port5000Default_Success(string addressInput, Func testUrls) + { + await RegisterAddresses_Success(addressInput, testUrls); + } + [ConditionalTheory, MemberData(nameof(AddressRegistrationDataIPv6Port80))] [IPv6SupportedCondition] [PortSupportedCondition(80)] @@ -273,10 +288,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { var dataset = new TheoryData>(); - // Default host and port - dataset.Add(null, _ => new[] { "http://127.0.0.1:5000/" }); - dataset.Add(string.Empty, _ => new[] { "http://127.0.0.1:5000/" }); - // Static ports var port = GetNextPort(); @@ -305,6 +316,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } } + public static TheoryData> AddressRegistrationDataIPv4Port5000Default => + new TheoryData> + { + { null, _ => new[] { "http://127.0.0.1:5000/" } }, + { string.Empty, _ => new[] { "http://127.0.0.1:5000/" } } + }; + public static TheoryData> IPEndPointRegistrationDataRandomPort { get @@ -384,10 +402,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { var dataset = new TheoryData>(); - // Default host and port - dataset.Add(null, _ => new[] { "http://127.0.0.1:5000/", "http://[::1]:5000/" }); - dataset.Add(string.Empty, _ => new[] { "http://127.0.0.1:5000/", "http://[::1]:5000/" }); - // Static ports var port = GetNextPort(); @@ -422,6 +436,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } } + public static TheoryData> AddressRegistrationDataIPv6Port5000Default => + new TheoryData> + { + { null, _ => new[] { "http://127.0.0.1:5000/", "http://[::1]:5000/" } }, + { string.Empty, _ => new[] { "http://127.0.0.1:5000/", "http://[::1]:5000/" } } + }; + public static TheoryData> AddressRegistrationDataIPv6Port80 { get From 11ab602b2f379f0bfbec3625f6c02ea9d2ba6b66 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Wed, 12 Apr 2017 16:15:46 -0700 Subject: [PATCH 1202/1662] Make timeout logic transport agnostic (#1649) * Make timeout logic transport agnostic * PR feedback * More PR feedback --- .../Internal/ConnectionHandler.cs | 5 + .../Internal/FrameConnection.cs | 70 +++++++++- .../Internal/FrameConnectionContext.cs | 1 + .../Internal/Http/DateHeaderValueManager.cs | 129 +----------------- .../Internal/Http/Frame.cs | 13 +- .../Internal/Http/FrameOfT.cs | 2 +- .../Infrastructure/FrameConnectionManager.cs | 38 ++++++ .../Internal/Infrastructure/Heartbeat.cs | 70 ++++++++++ .../Infrastructure/IHeartbeatHandler.cs | 12 ++ .../Internal/Infrastructure/IKestrelTrace.cs | 3 + .../Internal/Infrastructure/ISystemClock.cs | 2 +- .../Infrastructure}/ITimeoutControl.cs | 6 +- .../Internal/Infrastructure/KestrelTrace.cs | 8 ++ .../Internal/Infrastructure}/TimeoutAction.cs | 2 +- .../Internal/ServiceContext.cs | 4 + .../KestrelServer.cs | 14 +- .../IConnectionContext.cs | 1 - .../IConnectionInformation.cs | 3 - .../Internal/LibuvConnection.cs | 52 +------ .../Internal/LibuvConnectionContext.cs | 2 - .../Internal/LibuvThread.cs | 25 ---- .../DateHeaderValueManagerTests.cs | 90 +++++------- .../FrameTests.cs | 15 +- .../HeartbeatTests.cs | 59 ++++++++ .../TestInput.cs | 14 +- .../KeepAliveTimeoutTests.cs | 60 ++++---- .../RequestHeadersTimeoutTests.cs | 44 +++--- .../TestHelpers/TimeoutTestServer.cs | 49 +++++++ .../Mocks/MockConnectionInformation.cs | 17 --- .../Mocks/MockTrace.cs | 1 + .../TestHelpers/MockConnection.cs | 1 - test/shared/TestApplicationErrorLogger.cs | 7 + test/shared/TestConnection.cs | 32 +++++ test/shared/TestServiceContext.cs | 4 +- 34 files changed, 479 insertions(+), 376 deletions(-) create mode 100644 src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/FrameConnectionManager.cs create mode 100644 src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/Heartbeat.cs create mode 100644 src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/IHeartbeatHandler.cs rename src/{Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions => Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure}/ITimeoutControl.cs (53%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions => Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure}/TimeoutAction.cs (78%) create mode 100644 test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/HeartbeatTests.cs create mode 100644 test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/TestHelpers/TimeoutTestServer.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/ConnectionHandler.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/ConnectionHandler.cs index ff075f35da..4cf062d7ca 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/ConnectionHandler.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/ConnectionHandler.cs @@ -1,6 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System.Threading; using Microsoft.AspNetCore.Hosting.Server; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; @@ -11,6 +12,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal { public class ConnectionHandler : IConnectionHandler { + private static long _lastFrameConnectionId = long.MinValue; + private readonly ListenOptions _listenOptions; private readonly ServiceContext _serviceContext; private readonly IHttpApplication _application; @@ -28,6 +31,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal var outputPipe = connectionInfo.PipeFactory.Create(GetOutputPipeOptions(connectionInfo.OutputReaderScheduler)); var connectionId = CorrelationIdGenerator.GetNextId(); + var frameConnectionId = Interlocked.Increment(ref _lastFrameConnectionId); var frameContext = new FrameContext { @@ -44,6 +48,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal var connection = new FrameConnection(new FrameConnectionContext { ConnectionId = connectionId, + FrameConnectionId = frameConnectionId, ServiceContext = _serviceContext, PipeFactory = connectionInfo.PipeFactory, ConnectionAdapters = _listenOptions.ConnectionAdapters, diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnection.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnection.cs index a80d3f6e92..19014e8e7a 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnection.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnection.cs @@ -3,7 +3,9 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using System.IO; +using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Core.Adapter; using Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal; @@ -16,13 +18,17 @@ using Microsoft.Extensions.Logging; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal { - public class FrameConnection : IConnectionContext + public class FrameConnection : IConnectionContext, ITimeoutControl { private readonly FrameConnectionContext _context; private readonly Frame _frame; private readonly List _connectionAdapters; private readonly TaskCompletionSource _frameStartedTcs = new TaskCompletionSource(); + private long _lastTimestamp; + private long _timeoutTimestamp = long.MaxValue; + private TimeoutAction _timeoutAction; + private AdaptedPipeline _adaptedPipeline; private Stream _filteredStream; private Task _adaptedPipelineTask = TaskCache.CompletedTask; @@ -32,6 +38,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal _context = context; _frame = context.Frame; _connectionAdapters = context.ConnectionAdapters; + context.ServiceContext.ConnectionManager.AddConnection(context.FrameConnectionId, this); } public string ConnectionId => _context.ConnectionId; @@ -55,11 +62,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal { _frame.Input = _context.Input.Reader; _frame.Output = _context.OutputProducer; + _frame.TimeoutControl = this; if (_connectionAdapters.Count == 0) { - _frame.Start(); - _frameStartedTcs.SetResult(null); + StartFrame(); } else { @@ -75,6 +82,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal public void OnConnectionClosed() { + _context.ServiceContext.ConnectionManager.RemoveConnection(_context.FrameConnectionId); Log.ConnectionStop(ConnectionId); KestrelEventSource.Log.ConnectionStop(this); } @@ -127,8 +135,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal } _frame.AdaptedConnections = adaptedConnections; - _frame.Start(); - _frameStartedTcs.SetResult(null); + StartFrame(); } catch (Exception ex) { @@ -161,5 +168,58 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal _context.OutputProducer.Dispose(); _context.Input.Reader.Complete(); } + + private void StartFrame() + { + _lastTimestamp = _context.ServiceContext.SystemClock.UtcNow.Ticks; + _frame.Start(); + _frameStartedTcs.SetResult(null); + } + + public void Tick(DateTimeOffset now) + { + var timestamp = now.Ticks; + + // TODO: Use PlatformApis.VolatileRead equivalent again + if (timestamp > Interlocked.Read(ref _timeoutTimestamp)) + { + CancelTimeout(); + + if (_timeoutAction == TimeoutAction.SendTimeoutResponse) + { + Timeout(); + } + + var ignore = StopAsync(); + } + + Interlocked.Exchange(ref _lastTimestamp, timestamp); + } + + public void SetTimeout(long ticks, TimeoutAction timeoutAction) + { + Debug.Assert(_timeoutTimestamp == long.MaxValue, "Concurrent timeouts are not supported"); + + AssignTimeout(ticks, timeoutAction); + } + + public void ResetTimeout(long ticks, TimeoutAction timeoutAction) + + { + AssignTimeout(ticks, timeoutAction); + } + + public void CancelTimeout() + { + Interlocked.Exchange(ref _timeoutTimestamp, long.MaxValue); + } + + private void AssignTimeout(long ticks, TimeoutAction timeoutAction) + { + _timeoutAction = timeoutAction; + + // Add Heartbeat.Interval since this can be called right before the next heartbeat. + Interlocked.Exchange(ref _timeoutTimestamp, _lastTimestamp + ticks + Heartbeat.Interval.Ticks); + } } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnectionContext.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnectionContext.cs index f04ea5f877..c4edded73e 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnectionContext.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnectionContext.cs @@ -11,6 +11,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal public class FrameConnectionContext { public string ConnectionId { get; set; } + public long FrameConnectionId { get; set; } public ServiceContext ServiceContext { get; set; } public PipeFactory PipeFactory { get; set; } public List ConnectionAdapters { get; set; } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/DateHeaderValueManager.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/DateHeaderValueManager.cs index 349345e5fe..b2cb874364 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/DateHeaderValueManager.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/DateHeaderValueManager.cs @@ -12,23 +12,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http /// /// Manages the generation of the date header value. /// - public class DateHeaderValueManager : IDisposable + public class DateHeaderValueManager : IHeartbeatHandler { private static readonly byte[] _datePreambleBytes = Encoding.ASCII.GetBytes("\r\nDate: "); - private readonly ISystemClock _systemClock; - private readonly TimeSpan _timeWithoutRequestsUntilIdle; - private readonly TimeSpan _timerInterval; - private readonly object _timerLocker = new object(); - private DateHeaderValues _dateValues; - private volatile bool _isDisposed = false; - private volatile bool _hadRequestsSinceLastTimerTick = false; - private Timer _dateValueTimer; - private long _lastRequestSeenTicks; - private volatile bool _timerIsRunning; - /// /// Initializes a new instance of the class. /// @@ -39,28 +28,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http // Internal for testing internal DateHeaderValueManager(ISystemClock systemClock) - : this( - systemClock: systemClock, - timeWithoutRequestsUntilIdle: TimeSpan.FromSeconds(10), - timerInterval: TimeSpan.FromSeconds(1)) { - } - - // Internal for testing - internal DateHeaderValueManager( - ISystemClock systemClock, - TimeSpan timeWithoutRequestsUntilIdle, - TimeSpan timerInterval) - { - if (systemClock == null) - { - throw new ArgumentNullException(nameof(systemClock)); - } - - _systemClock = systemClock; - _timeWithoutRequestsUntilIdle = timeWithoutRequestsUntilIdle; - _timerInterval = timerInterval; - _dateValueTimer = new Timer(TimerLoop, state: null, dueTime: Timeout.Infinite, period: Timeout.Infinite); + SetDateValues(systemClock.UtcNow); } /// @@ -68,102 +37,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http /// in accordance with http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.18 /// /// The value in string and byte[] format. - public DateHeaderValues GetDateHeaderValues() - { - _hadRequestsSinceLastTimerTick = !_isDisposed; - - if (!_timerIsRunning) - { - StartTimer(); - } - - return _dateValues; - } - - /// - /// Releases all resources used by the current instance of . - /// - public void Dispose() - { - if (!_isDisposed) - { - _isDisposed = true; - _hadRequestsSinceLastTimerTick = false; - - lock (_timerLocker) - { - if (_dateValueTimer != null) - { - _timerIsRunning = false; - _dateValueTimer.Dispose(); - _dateValueTimer = null; - } - } - } - } - - /// - /// Starts the timer - /// - private void StartTimer() - { - var now = _systemClock.UtcNow; - SetDateValues(now); - - if (!_isDisposed) - { - lock (_timerLocker) - { - if (!_timerIsRunning && _dateValueTimer != null) - { - _timerIsRunning = true; - _dateValueTimer.Change(_timerInterval, _timerInterval); - } - } - } - } - - /// - /// Stops the timer - /// - private void StopTimer() - { - if (!_isDisposed) - { - lock (_timerLocker) - { - if (_dateValueTimer != null) - { - _timerIsRunning = false; - _dateValueTimer.Change(Timeout.Infinite, Timeout.Infinite); - _hadRequestsSinceLastTimerTick = false; - } - } - } - } + public DateHeaderValues GetDateHeaderValues() => _dateValues; // Called by the Timer (background) thread - private void TimerLoop(object state) + public void OnHeartbeat(DateTimeOffset now) { - var now = _systemClock.UtcNow; - SetDateValues(now); - - if (_hadRequestsSinceLastTimerTick) - { - // We served requests since the last tick, reset the flag and return as we're still active - _hadRequestsSinceLastTimerTick = false; - Interlocked.Exchange(ref _lastRequestSeenTicks, now.Ticks); - return; - } - - // No requests since the last timer tick, we need to check if we're beyond the idle threshold - // TODO: Use PlatformApis.VolatileRead equivalent again - if ((now.Ticks - Interlocked.Read(ref _lastRequestSeenTicks)) >= _timeWithoutRequestsUntilIdle.Ticks) - { - // No requests since idle threshold so stop the timer if it's still running - StopTimer(); - } } /// diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.cs index 9c4035ff8e..875e406463 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.cs @@ -74,8 +74,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http private int _remainingRequestHeadersBytesAllowed; private int _requestHeadersParsed; - protected readonly long _keepAliveMilliseconds; - private readonly long _requestHeadersTimeoutMilliseconds; + protected readonly long _keepAliveTicks; + private readonly long _requestHeadersTimeoutTicks; protected long _responseBytesWritten; @@ -91,8 +91,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http _parser = ServiceContext.HttpParserFactory(new FrameAdapter(this)); FrameControl = this; - _keepAliveMilliseconds = (long)ServerOptions.Limits.KeepAliveTimeout.TotalMilliseconds; - _requestHeadersTimeoutMilliseconds = (long)ServerOptions.Limits.RequestHeadersTimeout.TotalMilliseconds; + _keepAliveTicks = ServerOptions.Limits.KeepAliveTimeout.Ticks; + _requestHeadersTimeoutTicks = ServerOptions.Limits.RequestHeadersTimeout.Ticks; } public ServiceContext ServiceContext => _frameContext.ServiceContext; @@ -102,10 +102,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http public ISocketOutput Output { get; set; } public IEnumerable AdaptedConnections { get; set; } public ConnectionLifetimeControl LifetimeControl { get; set; } + public ITimeoutControl TimeoutControl { get; set; } - protected ITimeoutControl TimeoutControl => ConnectionInformation.TimeoutControl; protected IKestrelTrace Log => ServiceContext.Log; - private DateHeaderValueManager DateHeaderValueManager => ServiceContext.DateHeaderValueManager; // Hold direct reference to ServerOptions since this is used very often in the request processing path private KestrelServerOptions ServerOptions { get; } @@ -1017,7 +1016,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http break; } - TimeoutControl.ResetTimeout(_requestHeadersTimeoutMilliseconds, TimeoutAction.SendTimeoutResponse); + TimeoutControl.ResetTimeout(_requestHeadersTimeoutTicks, TimeoutAction.SendTimeoutResponse); _requestProcessingStatus = RequestProcessingStatus.ParsingRequestLine; goto case RequestProcessingStatus.ParsingRequestLine; diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameOfT.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameOfT.cs index 0d4ffe7544..4073bc0837 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameOfT.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameOfT.cs @@ -34,7 +34,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { while (!_requestProcessingStopping) { - TimeoutControl.SetTimeout(_keepAliveMilliseconds, TimeoutAction.CloseConnection); + TimeoutControl.SetTimeout(_keepAliveTicks, TimeoutAction.CloseConnection); InitializeHeaders(); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/FrameConnectionManager.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/FrameConnectionManager.cs new file mode 100644 index 0000000000..a789ea7c1d --- /dev/null +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/FrameConnectionManager.cs @@ -0,0 +1,38 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Collections.Concurrent; + +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure +{ + public class FrameConnectionManager : IHeartbeatHandler + { + private readonly ConcurrentDictionary _connections + = new ConcurrentDictionary(); + + public void AddConnection(long id, FrameConnection connection) + { + if (!_connections.TryAdd(id, connection)) + { + throw new ArgumentException(nameof(id)); + } + } + + public void RemoveConnection(long id) + { + if (!_connections.TryRemove(id, out _)) + { + throw new ArgumentException(nameof(id)); + } + } + + public void OnHeartbeat(DateTimeOffset now) + { + foreach (var kvp in _connections) + { + kvp.Value.Tick(now); + } + } + } +} diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/Heartbeat.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/Heartbeat.cs new file mode 100644 index 0000000000..089b779e92 --- /dev/null +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/Heartbeat.cs @@ -0,0 +1,70 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Threading; +using Microsoft.Extensions.Logging; + +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure +{ + public class Heartbeat : IDisposable + { + public static readonly TimeSpan Interval = TimeSpan.FromSeconds(1); + + private readonly IHeartbeatHandler[] _callbacks; + private readonly TimeSpan _interval; + private readonly ISystemClock _systemClock; + private readonly IKestrelTrace _trace; + private readonly Timer _timer; + private int _executingOnHeartbeat; + + public Heartbeat(IHeartbeatHandler[] callbacks, ISystemClock systemClock, IKestrelTrace trace) + : this(callbacks, systemClock, trace, Interval) + { + } + + // For testing + internal Heartbeat(IHeartbeatHandler[] callbacks, ISystemClock systemClock, IKestrelTrace trace, TimeSpan interval) + { + _callbacks = callbacks; + _interval = interval; + _systemClock = systemClock; + _trace = trace; + _timer = new Timer(OnHeartbeat, state: this, dueTime: _interval, period: _interval); + } + + // Called by the Timer (background) thread + private void OnHeartbeat(object state) + { + var now = _systemClock.UtcNow; + + if (Interlocked.Exchange(ref _executingOnHeartbeat, 1) == 0) + { + try + { + foreach (var callback in _callbacks) + { + callback.OnHeartbeat(now); + } + } + catch (Exception ex) + { + _trace.LogError(0, ex, $"{nameof(Heartbeat)}.{nameof(OnHeartbeat)}"); + } + finally + { + Interlocked.Exchange(ref _executingOnHeartbeat, 0); + } + } + else + { + _trace.TimerSlow(_interval, now); + } + } + + public void Dispose() + { + _timer.Dispose(); + } + } +} diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/IHeartbeatHandler.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/IHeartbeatHandler.cs new file mode 100644 index 0000000000..e6a355e829 --- /dev/null +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/IHeartbeatHandler.cs @@ -0,0 +1,12 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; + +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure +{ + public interface IHeartbeatHandler + { + void OnHeartbeat(DateTimeOffset now); + } +} diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/IKestrelTrace.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/IKestrelTrace.cs index f14c1b33c7..67ef9b2b34 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/IKestrelTrace.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/IKestrelTrace.cs @@ -29,5 +29,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure void ConnectionBadRequest(string connectionId, BadHttpRequestException ex); void ApplicationError(string connectionId, string traceIdentifier, Exception ex); + + void TimerSlow(TimeSpan interval, DateTimeOffset now); + } } \ No newline at end of file diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/ISystemClock.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/ISystemClock.cs index e29312dda8..ddc5b1fd66 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/ISystemClock.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/ISystemClock.cs @@ -8,7 +8,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure /// /// Abstracts the system clock to facilitate testing. /// - internal interface ISystemClock + public interface ISystemClock { /// /// Retrieves the current system time in UTC. diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/ITimeoutControl.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/ITimeoutControl.cs similarity index 53% rename from src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/ITimeoutControl.cs rename to src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/ITimeoutControl.cs index 824263da13..d71b423873 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/ITimeoutControl.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/ITimeoutControl.cs @@ -1,12 +1,12 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure { public interface ITimeoutControl { - void SetTimeout(long milliseconds, TimeoutAction timeoutAction); - void ResetTimeout(long milliseconds, TimeoutAction timeoutAction); + void SetTimeout(long ticks, TimeoutAction timeoutAction); + void ResetTimeout(long ticks, TimeoutAction timeoutAction); void CancelTimeout(); } } \ No newline at end of file diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/KestrelTrace.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/KestrelTrace.cs index cc7204e203..a1079fa633 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/KestrelTrace.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/KestrelTrace.cs @@ -45,6 +45,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal private static readonly Action _requestProcessingError = LoggerMessage.Define(LogLevel.Information, 20, @"Connection id ""{ConnectionId}"" request processing ended abnormally."); + private static readonly Action _timerSlow = + LoggerMessage.Define(LogLevel.Warning, 21, @"Heartbeat took longer than ""{interval}"" at ""{now}""."); + protected readonly ILogger _logger; public KestrelTrace(ILogger logger) @@ -107,6 +110,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal _requestProcessingError(_logger, connectionId, ex); } + public virtual void TimerSlow(TimeSpan interval, DateTimeOffset now) + { + _timerSlow(_logger, interval, now, null); + } + public virtual void Log(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func formatter) => _logger.Log(logLevel, eventId, state, exception, formatter); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/TimeoutAction.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/TimeoutAction.cs similarity index 78% rename from src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/TimeoutAction.cs rename to src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/TimeoutAction.cs index 06aae8627e..96af620550 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/TimeoutAction.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/TimeoutAction.cs @@ -1,7 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure { public enum TimeoutAction { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/ServiceContext.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/ServiceContext.cs index 4df0cb751f..72017e5d43 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/ServiceContext.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/ServiceContext.cs @@ -15,8 +15,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal public Func> HttpParserFactory { get; set; } + public ISystemClock SystemClock { get; set; } + public DateHeaderValueManager DateHeaderValueManager { get; set; } + public FrameConnectionManager ConnectionManager { get; set; } + public KestrelServerOptions ServerOptions { get; set; } } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/KestrelServer.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/KestrelServer.cs index d5962ee0a1..6b8085e3a5 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/KestrelServer.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/KestrelServer.cs @@ -29,7 +29,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core private readonly ITransportFactory _transportFactory; private bool _isRunning; - private DateHeaderValueManager _dateHeaderValueManager; + private Heartbeat _heartbeat; public KestrelServer( IOptions options, @@ -85,9 +85,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core } _isRunning = true; - _dateHeaderValueManager = new DateHeaderValueManager(); var trace = new KestrelTrace(_logger); + var systemClock = new SystemClock(); + var dateHeaderValueManager = new DateHeaderValueManager(systemClock); + var connectionManager = new FrameConnectionManager(); + _heartbeat = new Heartbeat(new IHeartbeatHandler[] { dateHeaderValueManager, connectionManager }, systemClock, trace); + IThreadPool threadPool; if (InternalOptions.ThreadPoolDispatching) { @@ -103,7 +107,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core Log = trace, HttpParserFactory = frameParser => new HttpParser(frameParser.Frame.ServiceContext.Log), ThreadPool = threadPool, - DateHeaderValueManager = _dateHeaderValueManager, + SystemClock = systemClock, + DateHeaderValueManager = dateHeaderValueManager, + ConnectionManager = connectionManager, ServerOptions = Options }; @@ -232,7 +238,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core Task.WaitAll(tasks); } - _dateHeaderValueManager?.Dispose(); + _heartbeat?.Dispose(); } private void ValidateOptions() diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/IConnectionContext.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/IConnectionContext.cs index 3cba9448b8..e38bc5d359 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/IConnectionContext.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/IConnectionContext.cs @@ -17,6 +17,5 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions void OnConnectionClosed(); Task StopAsync(); void Abort(Exception ex); - void Timeout(); } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/IConnectionInformation.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/IConnectionInformation.cs index f819a34913..a06bd16dd9 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/IConnectionInformation.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/IConnectionInformation.cs @@ -14,8 +14,5 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions PipeFactory PipeFactory { get; } IScheduler InputWriterScheduler { get; } IScheduler OutputReaderScheduler { get; } - - // TODO: Remove timeout management from transport - ITimeoutControl TimeoutControl { get; } } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvConnection.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvConnection.cs index d0a5563de1..0e997c7b51 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvConnection.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvConnection.cs @@ -13,7 +13,7 @@ using Microsoft.Extensions.Logging; namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal { - public class LibuvConnection : LibuvConnectionContext, ITimeoutControl + public class LibuvConnection : LibuvConnectionContext { private const int MinAllocBufferSize = 2048; @@ -28,16 +28,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal private TaskCompletionSource _socketClosedTcs = new TaskCompletionSource(); - private long _lastTimestamp; - private long _timeoutTimestamp = long.MaxValue; - private TimeoutAction _timeoutAction; private WritableBuffer? _currentWritableBuffer; public LibuvConnection(ListenerContext context, UvStreamHandle socket) : base(context) { _socket = socket; socket.Connection = this; - TimeoutControl = this; var tcpHandle = _socket as UvTcpHandle; if (tcpHandle != null) @@ -45,8 +41,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal RemoteEndPoint = tcpHandle.GetPeerIPEndPoint(); LocalEndPoint = tcpHandle.GetSockIPEndPoint(); } - - _lastTimestamp = Thread.Loop.Now(); } // For testing @@ -74,7 +68,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal // Start socket prior to applying the ConnectionAdapter _socket.ReadStart(_allocCallback, _readCallback, this); - _lastTimestamp = Thread.Loop.Now(); // This *must* happen after socket.ReadStart // The socket output consumer is the only thing that can close the connection. If the @@ -110,24 +103,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal _socketClosedTcs.TrySetResult(null); } - // Called on Libuv thread - public void Tick(long timestamp) - { - if (timestamp > PlatformApis.VolatileRead(ref _timeoutTimestamp)) - { - TimeoutControl.CancelTimeout(); - - if (_timeoutAction == TimeoutAction.SendTimeoutResponse) - { - _connectionContext.Timeout(); - } - - StopAsync(); - } - - Interlocked.Exchange(ref _lastTimestamp, timestamp); - } - private static LibuvFunctions.uv_buf_t AllocCallback(UvStreamHandle handle, int suggestedSize, object state) { return ((LibuvConnection)state).OnAlloc(handle, suggestedSize); @@ -251,30 +226,5 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal } } } - - void ITimeoutControl.SetTimeout(long milliseconds, TimeoutAction timeoutAction) - { - Debug.Assert(_timeoutTimestamp == long.MaxValue, "Concurrent timeouts are not supported"); - - AssignTimeout(milliseconds, timeoutAction); - } - - void ITimeoutControl.ResetTimeout(long milliseconds, TimeoutAction timeoutAction) - { - AssignTimeout(milliseconds, timeoutAction); - } - - void ITimeoutControl.CancelTimeout() - { - Interlocked.Exchange(ref _timeoutTimestamp, long.MaxValue); - } - - private void AssignTimeout(long milliseconds, TimeoutAction timeoutAction) - { - _timeoutAction = timeoutAction; - - // Add LibuvThread.HeartbeatMilliseconds extra milliseconds since this can be called right before the next heartbeat. - Interlocked.Exchange(ref _timeoutTimestamp, _lastTimestamp + milliseconds + LibuvThread.HeartbeatMilliseconds); - } } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvConnectionContext.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvConnectionContext.cs index 4f76cc097f..6c9d0cfcf5 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvConnectionContext.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvConnectionContext.cs @@ -26,7 +26,5 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal public PipeFactory PipeFactory => ListenerContext.Thread.PipeFactory; public IScheduler InputWriterScheduler => ListenerContext.Thread; public IScheduler OutputReaderScheduler => ListenerContext.Thread; - - public ITimeoutControl TimeoutControl { get; set; } } } \ No newline at end of file diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvThread.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvThread.cs index 11b279c66f..5fb6f33d00 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvThread.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvThread.cs @@ -16,16 +16,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal { public class LibuvThread : IScheduler { - public const long HeartbeatMilliseconds = 1000; - - private static readonly LibuvFunctions.uv_walk_cb _heartbeatWalkCallback = (ptr, arg) => - { - var streamHandle = UvMemory.FromIntPtr(ptr) as UvStreamHandle; - var thisHandle = GCHandle.FromIntPtr(arg); - var libuvThread = (LibuvThread)thisHandle.Target; - streamHandle?.Connection?.Tick(libuvThread.Now); - }; - // maximum times the work queues swapped and are processed in a single pass // as completing a task may immediately have write data to put on the network // otherwise it needs to wait till the next pass of the libuv loop @@ -37,7 +27,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal private readonly TaskCompletionSource _threadTcs = new TaskCompletionSource(); private readonly UvLoopHandle _loop; private readonly UvAsyncHandle _post; - private readonly UvTimerHandle _heartbeatTimer; private Queue _workAdding = new Queue(1024); private Queue _workRunning = new Queue(1024); private Queue _closeHandleAdding = new Queue(256); @@ -49,7 +38,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal private ExceptionDispatchInfo _closeError; private readonly ILibuvTrace _log; private readonly TimeSpan _shutdownTimeout; - private IntPtr _thisPtr; public LibuvThread(LibuvTransport transport) { @@ -61,7 +49,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal _post = new UvAsyncHandle(_log); _thread = new Thread(ThreadStart); _thread.Name = nameof(LibuvThread); - _heartbeatTimer = new UvTimerHandle(_log); #if !DEBUG // Mark the thread as being as unimportant to keeping the process alive. // Don't do this for debug builds, so we know if the thread isn't terminating. @@ -170,7 +157,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal private void AllowStop() { - _heartbeatTimer.Stop(); _post.Unreference(); } @@ -269,8 +255,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal { _loop.Init(_transport.Libuv); _post.Init(_loop, OnPost, EnqueueCloseHandle); - _heartbeatTimer.Init(_loop, EnqueueCloseHandle); - _heartbeatTimer.Start(OnHeartbeat, timeout: HeartbeatMilliseconds, repeat: HeartbeatMilliseconds); _initCompleted = true; tcs.SetResult(0); } @@ -286,8 +270,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal try { - _thisPtr = GCHandle.ToIntPtr(thisHandle); - _loop.Run(); if (_stopImmediate) { @@ -298,7 +280,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal // run the loop one more time to delete the open handles _post.Reference(); _post.Dispose(); - _heartbeatTimer.Dispose(); // Ensure the Dispose operations complete in the event loop. _loop.Run(); @@ -333,12 +314,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal } while (wasWork && loopsRemaining > 0); } - private void OnHeartbeat(UvTimerHandle timer) - { - Now = Loop.Now(); - Walk(_heartbeatWalkCallback, _thisPtr); - } - private bool DoPostWork() { Queue queue; diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/DateHeaderValueManagerTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/DateHeaderValueManagerTests.cs index 875e0f5d73..8bcc60ea07 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/DateHeaderValueManagerTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/DateHeaderValueManagerTests.cs @@ -4,7 +4,9 @@ using System; using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; using Microsoft.AspNetCore.Testing; +using Moq; using Xunit; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests @@ -27,21 +29,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests { UtcNow = now }; - var timeWithoutRequestsUntilIdle = TimeSpan.FromSeconds(1); - var timerInterval = TimeSpan.FromSeconds(10); - var dateHeaderValueManager = new DateHeaderValueManager(systemClock, timeWithoutRequestsUntilIdle, timerInterval); - string result; - try - { - result = dateHeaderValueManager.GetDateHeaderValues().String; - } - finally - { - dateHeaderValueManager.Dispose(); - } - - Assert.Equal(now.ToString(Rfc1123DateFormat), result); + var dateHeaderValueManager = new DateHeaderValueManager(systemClock); + Assert.Equal(now.ToString(Rfc1123DateFormat), dateHeaderValueManager.GetDateHeaderValues().String); } [Fact] @@ -53,30 +43,22 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests { UtcNow = now }; - var timeWithoutRequestsUntilIdle = TimeSpan.FromSeconds(1); + var timerInterval = TimeSpan.FromSeconds(10); - var dateHeaderValueManager = new DateHeaderValueManager(systemClock, timeWithoutRequestsUntilIdle, timerInterval); - string result1; - string result2; + var dateHeaderValueManager = new DateHeaderValueManager(systemClock); - try + using (new Heartbeat(new IHeartbeatHandler[] { dateHeaderValueManager }, systemClock, null, timerInterval)) { - result1 = dateHeaderValueManager.GetDateHeaderValues().String; + Assert.Equal(now.ToString(Rfc1123DateFormat), dateHeaderValueManager.GetDateHeaderValues().String); systemClock.UtcNow = future; - result2 = dateHeaderValueManager.GetDateHeaderValues().String; - } - finally - { - dateHeaderValueManager.Dispose(); + Assert.Equal(now.ToString(Rfc1123DateFormat), dateHeaderValueManager.GetDateHeaderValues().String); } - Assert.Equal(now.ToString(Rfc1123DateFormat), result1); - Assert.Equal(now.ToString(Rfc1123DateFormat), result2); Assert.Equal(1, systemClock.UtcNowCalled); } [Fact] - public async Task GetDateHeaderValue_ReturnsUpdatedValueAfterIdle() + public async Task GetDateHeaderValue_ReturnsUpdatedValueAfterHeartbeat() { var now = DateTimeOffset.UtcNow; var future = now.AddSeconds(10); @@ -84,32 +66,30 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests { UtcNow = now }; - var timeWithoutRequestsUntilIdle = TimeSpan.FromMilliseconds(250); + var timerInterval = TimeSpan.FromMilliseconds(100); - var dateHeaderValueManager = new DateHeaderValueManager(systemClock, timeWithoutRequestsUntilIdle, timerInterval); - string result1; - string result2; + var dateHeaderValueManager = new DateHeaderValueManager(systemClock); - try + var heartbeatTcs = new TaskCompletionSource(); + var mockHeartbeatHandler = new Mock(); + + mockHeartbeatHandler.Setup(h => h.OnHeartbeat(future)).Callback(() => heartbeatTcs.TrySetResult(null)); + + using (new Heartbeat(new[] { dateHeaderValueManager, mockHeartbeatHandler.Object }, systemClock, null, timerInterval)) { - result1 = dateHeaderValueManager.GetDateHeaderValues().String; + Assert.Equal(now.ToString(Rfc1123DateFormat), dateHeaderValueManager.GetDateHeaderValues().String); + + // Wait for the next heartbeat before verifying GetDateHeaderValues picks up new time. systemClock.UtcNow = future; - // Wait for longer than the idle timeout to ensure the timer is stopped - await Task.Delay(TimeSpan.FromSeconds(1)); - result2 = dateHeaderValueManager.GetDateHeaderValues().String; - } - finally - { - dateHeaderValueManager.Dispose(); - } + await heartbeatTcs.Task; - Assert.Equal(now.ToString(Rfc1123DateFormat), result1); - Assert.Equal(future.ToString(Rfc1123DateFormat), result2); - Assert.True(systemClock.UtcNowCalled >= 2); + Assert.Equal(future.ToString(Rfc1123DateFormat), dateHeaderValueManager.GetDateHeaderValues().String); + Assert.True(systemClock.UtcNowCalled >= 2); + } } [Fact] - public void GetDateHeaderValue_ReturnsDateValueAfterDisposed() + public void GetDateHeaderValue_ReturnsLastDateValueAfterHeartbeatDisposed() { var now = DateTimeOffset.UtcNow; var future = now.AddSeconds(10); @@ -117,17 +97,17 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests { UtcNow = now }; - var timeWithoutRequestsUntilIdle = TimeSpan.FromSeconds(1); - var timerInterval = TimeSpan.FromSeconds(10); - var dateHeaderValueManager = new DateHeaderValueManager(systemClock, timeWithoutRequestsUntilIdle, timerInterval); - var result1 = dateHeaderValueManager.GetDateHeaderValues().String; - dateHeaderValueManager.Dispose(); + var timerInterval = TimeSpan.FromSeconds(10); + var dateHeaderValueManager = new DateHeaderValueManager(systemClock); + + using (new Heartbeat(new IHeartbeatHandler[] { dateHeaderValueManager }, systemClock, null, timerInterval)) + { + Assert.Equal(now.ToString(Rfc1123DateFormat), dateHeaderValueManager.GetDateHeaderValues().String); + } + systemClock.UtcNow = future; - var result2 = dateHeaderValueManager.GetDateHeaderValues().String; - - Assert.Equal(now.ToString(Rfc1123DateFormat), result1); - Assert.Equal(future.ToString(Rfc1123DateFormat), result2); + Assert.Equal(now.ToString(Rfc1123DateFormat), dateHeaderValueManager.GetDateHeaderValues().String); } } } diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameTests.cs index b5c0b1546f..33646df6ed 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameTests.cs @@ -13,7 +13,6 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Hosting.Server; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http.Features; -using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; @@ -67,7 +66,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests _frame = new TestFrame(application: null, context: _frameContext) { Input = _input.Reader, - Output = new MockSocketOutput() + Output = new MockSocketOutput(), + TimeoutControl = Mock.Of() }; _frame.Reset(); @@ -320,16 +320,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests [Fact] public async Task ParseRequestStartsRequestHeadersTimeoutOnFirstByteAvailable() { - var connectionInfo = (MockConnectionInformation)_frameContext.ConnectionInformation; var connectionControl = new Mock(); - connectionInfo.TimeoutControl = connectionControl.Object; + _frame.TimeoutControl = connectionControl.Object; await _input.Writer.WriteAsync(Encoding.ASCII.GetBytes("G")); _frame.ParseRequest((await _input.Reader.ReadAsync()).Buffer, out _consumed, out _examined); _input.Reader.Advance(_consumed, _examined); - var expectedRequestHeadersTimeout = (long)_serviceContext.ServerOptions.Limits.RequestHeadersTimeout.TotalMilliseconds; + var expectedRequestHeadersTimeout = _serviceContext.ServerOptions.Limits.RequestHeadersTimeout.Ticks; connectionControl.Verify(cc => cc.ResetTimeout(expectedRequestHeadersTimeout, TimeoutAction.SendTimeoutResponse)); } @@ -444,13 +443,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests [Fact] public void RequestProcessingAsyncEnablesKeepAliveTimeout() { - var connectionInfo = (MockConnectionInformation)_frameContext.ConnectionInformation; var connectionControl = new Mock(); - connectionInfo.TimeoutControl = connectionControl.Object; + _frame.TimeoutControl = connectionControl.Object; var requestProcessingTask = _frame.RequestProcessingAsync(); - var expectedKeepAliveTimeout = (long)_serviceContext.ServerOptions.Limits.KeepAliveTimeout.TotalMilliseconds; + var expectedKeepAliveTimeout = _serviceContext.ServerOptions.Limits.KeepAliveTimeout.Ticks; connectionControl.Verify(cc => cc.SetTimeout(expectedKeepAliveTimeout, TimeoutAction.CloseConnection)); _frame.StopAsync(); @@ -817,7 +815,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests public PipeFactory PipeFactory { get; } public IScheduler InputWriterScheduler { get; } public IScheduler OutputReaderScheduler { get; } - public ITimeoutControl TimeoutControl { get; set; } = Mock.Of(); } private class RequestHeadersWrapper : IHeaderDictionary diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/HeartbeatTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/HeartbeatTests.cs new file mode 100644 index 0000000000..8c7ea7d850 --- /dev/null +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/HeartbeatTests.cs @@ -0,0 +1,59 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Linq; +using System.Threading; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; +using Microsoft.AspNetCore.Testing; +using Microsoft.Extensions.Logging; +using Moq; +using Xunit; + +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests +{ + public class HeartbeatTests + { + [Fact] + public void BlockedHeartbeatDoesntCauseOverlapsAndIsLoggedAsError() + { + var systemClock = new MockSystemClock(); + var heartbeatInterval = TimeSpan.FromMilliseconds(10); + var heartbeatHandler = new Mock(); + var kestrelTrace = new Mock(); + var handlerMre = new ManualResetEventSlim(); + var traceMre = new ManualResetEventSlim(); + + heartbeatHandler.Setup(h => h.OnHeartbeat(systemClock.UtcNow)).Callback(() => handlerMre.Wait()); + kestrelTrace.Setup(t => t.TimerSlow(heartbeatInterval, systemClock.UtcNow)).Callback(() => traceMre.Set()); + + using (new Heartbeat(new[] {heartbeatHandler.Object}, systemClock, kestrelTrace.Object, heartbeatInterval)) + { + Assert.True(traceMre.Wait(TimeSpan.FromSeconds(10))); + } + + handlerMre.Set(); + + heartbeatHandler.Verify(h => h.OnHeartbeat(systemClock.UtcNow), Times.Once()); + kestrelTrace.Verify(t => t.TimerSlow(heartbeatInterval, systemClock.UtcNow), Times.AtLeastOnce()); + } + + [Fact] + public void ExceptionFromHeartbeatHandlerIsLoggedAsError() + { + var systemClock = new MockSystemClock(); + var heartbeatHandler = new Mock(); + var kestrelTrace = new TestKestrelTrace(); + var ex = new Exception(); + + heartbeatHandler.Setup(h => h.OnHeartbeat(systemClock.UtcNow)).Throws(ex); + + using (new Heartbeat(new[] { heartbeatHandler.Object }, systemClock, kestrelTrace)) + { + Assert.True(kestrelTrace.Logger.MessageLoggedTask.Wait(TimeSpan.FromSeconds(10))); + } + + Assert.Equal(ex, kestrelTrace.Logger.Messages.Single(message => message.LogLevel == LogLevel.Error).Exception); + } + } +} diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/TestInput.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/TestInput.cs index 73f6f170bf..56b959a738 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/TestInput.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/TestInput.cs @@ -14,7 +14,7 @@ using Microsoft.Extensions.Internal; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests { - class TestInput : ITimeoutControl, IFrameControl, IDisposable + class TestInput : IFrameControl, IDisposable { private MemoryPool _memoryPool; private PipeFactory _pipelineFactory; @@ -58,18 +58,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests { } - public void SetTimeout(long milliseconds, TimeoutAction timeoutAction) - { - } - - public void ResetTimeout(long milliseconds, TimeoutAction timeoutAction) - { - } - - public void CancelTimeout() - { - } - public void Abort() { } diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/KeepAliveTimeoutTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/KeepAliveTimeoutTests.cs index 28e4ece5d8..01b070dac6 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/KeepAliveTimeoutTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/KeepAliveTimeoutTests.cs @@ -2,12 +2,14 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Net; using System.Text; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Server.Kestrel.Core; +using Microsoft.AspNetCore.Server.Kestrel.FunctionalTests.TestHelpers; using Microsoft.AspNetCore.Testing; using Xunit; @@ -49,22 +51,22 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } } - private async Task ConnectionClosedWhenKeepAliveTimeoutExpires(TestServer server) + private async Task ConnectionClosedWhenKeepAliveTimeoutExpires(TimeoutTestServer server) { - using (var connection = new TestConnection(server.Port)) + using (var connection = server.CreateConnection()) { await connection.Send( "GET / HTTP/1.1", "", ""); - await ReceiveResponse(connection, server.Context); + await ReceiveResponse(connection); await connection.WaitForConnectionClose().TimeoutAfter(LongDelay); } } - private async Task ConnectionKeptAliveBetweenRequests(TestServer server) + private async Task ConnectionKeptAliveBetweenRequests(TimeoutTestServer server) { - using (var connection = new TestConnection(server.Port)) + using (var connection = server.CreateConnection()) { for (var i = 0; i < 10; i++) { @@ -77,14 +79,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests for (var i = 0; i < 10; i++) { - await ReceiveResponse(connection, server.Context); + await ReceiveResponse(connection); } } } - private async Task ConnectionNotTimedOutWhileRequestBeingSent(TestServer server) + private async Task ConnectionNotTimedOutWhileRequestBeingSent(TimeoutTestServer server) { - using (var connection = new TestConnection(server.Port)) + using (var connection = server.CreateConnection()) { var cts = new CancellationTokenSource(); cts.CancelAfter(LongDelay); @@ -108,13 +110,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests "0", "", ""); - await ReceiveResponse(connection, server.Context); + await ReceiveResponse(connection); } } - private async Task ConnectionNotTimedOutWhileAppIsRunning(TestServer server, CancellationTokenSource cts) + private async Task ConnectionNotTimedOutWhileAppIsRunning(TimeoutTestServer server, CancellationTokenSource cts) { - using (var connection = new TestConnection(server.Port)) + using (var connection = server.CreateConnection()) { await connection.Send( "GET /longrunning HTTP/1.1", @@ -127,28 +129,28 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests await Task.Delay(1000); } - await ReceiveResponse(connection, server.Context); + await ReceiveResponse(connection); await connection.Send( "GET / HTTP/1.1", "", ""); - await ReceiveResponse(connection, server.Context); + await ReceiveResponse(connection); } } - private async Task ConnectionTimesOutWhenOpenedButNoRequestSent(TestServer server) + private async Task ConnectionTimesOutWhenOpenedButNoRequestSent(TimeoutTestServer server) { - using (var connection = new TestConnection(server.Port)) + using (var connection = server.CreateConnection()) { await Task.Delay(LongDelay); await connection.WaitForConnectionClose().TimeoutAfter(LongDelay); } } - private async Task KeepAliveTimeoutDoesNotApplyToUpgradedConnections(TestServer server, CancellationTokenSource cts) + private async Task KeepAliveTimeoutDoesNotApplyToUpgradedConnections(TimeoutTestServer server, CancellationTokenSource cts) { - using (var connection = new TestConnection(server.Port)) + using (var connection = server.CreateConnection()) { await connection.Send( "GET /upgrade HTTP/1.1", @@ -157,7 +159,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests await connection.Receive( "HTTP/1.1 101 Switching Protocols", "Connection: Upgrade", - $"Date: {server.Context.DateHeaderValue}", + ""); + await connection.ReceiveStartsWith("Date: "); + await connection.Receive( "", ""); cts.CancelAfter(LongDelay); @@ -171,18 +175,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } } - private TestServer CreateServer(CancellationToken longRunningCt, CancellationToken upgradeCt) + private TimeoutTestServer CreateServer(CancellationToken longRunningCt, CancellationToken upgradeCt) { - return new TestServer(httpContext => App(httpContext, longRunningCt, upgradeCt), new TestServiceContext + return new TimeoutTestServer(httpContext => App(httpContext, longRunningCt, upgradeCt), new KestrelServerOptions { - ServerOptions = new KestrelServerOptions - { - AddServerHeader = false, - Limits = - { - KeepAliveTimeout = KeepAliveTimeout - } - } + AddServerHeader = false, + Limits = { KeepAliveTimeout = KeepAliveTimeout } }); } @@ -218,11 +216,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } } - private async Task ReceiveResponse(TestConnection connection, TestServiceContext testServiceContext) + private async Task ReceiveResponse(TestConnection connection) { await connection.Receive( "HTTP/1.1 200 OK", - $"Date: {testServiceContext.DateHeaderValue}", + ""); + await connection.ReceiveStartsWith("Date: "); + await connection.Receive( "Transfer-Encoding: chunked", "", "c", diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestHeadersTimeoutTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestHeadersTimeoutTests.cs index e3807704a7..4514ace0d2 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestHeadersTimeoutTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestHeadersTimeoutTests.cs @@ -6,6 +6,7 @@ using System.IO; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Server.Kestrel.Core; +using Microsoft.AspNetCore.Server.Kestrel.FunctionalTests.TestHelpers; using Microsoft.AspNetCore.Testing; using Xunit; @@ -37,18 +38,18 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } } - private async Task ConnectionAbortedWhenRequestHeadersNotReceivedInTime(TestServer server, string headers) + private async Task ConnectionAbortedWhenRequestHeadersNotReceivedInTime(TimeoutTestServer server, string headers) { using (var connection = server.CreateConnection()) { await connection.Send( "GET / HTTP/1.1", headers); - await ReceiveTimeoutResponse(connection, server.Context); + await ReceiveTimeoutResponse(connection); } } - private async Task RequestHeadersTimeoutCanceledAfterHeadersReceived(TestServer server) + private async Task RequestHeadersTimeoutCanceledAfterHeadersReceived(TimeoutTestServer server) { using (var connection = server.CreateConnection()) { @@ -60,20 +61,20 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests await Task.Delay(RequestHeadersTimeout); await connection.Send( "a"); - await ReceiveResponse(connection, server.Context); + await ReceiveResponse(connection); } } - private async Task ConnectionAbortedWhenRequestLineNotReceivedInTime(TestServer server, string requestLine) + private async Task ConnectionAbortedWhenRequestLineNotReceivedInTime(TimeoutTestServer server, string requestLine) { using (var connection = server.CreateConnection()) { await connection.Send(requestLine); - await ReceiveTimeoutResponse(connection, server.Context); + await ReceiveTimeoutResponse(connection); } } - private async Task TimeoutNotResetOnEachRequestLineCharacterReceived(TestServer server) + private async Task TimeoutNotResetOnEachRequestLineCharacterReceived(TimeoutTestServer server) { using (var connection = server.CreateConnection()) { @@ -88,31 +89,30 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } } - private TestServer CreateServer() + private TimeoutTestServer CreateServer() { - return new TestServer(async httpContext => + return new TimeoutTestServer(async httpContext => { await httpContext.Request.Body.ReadAsync(new byte[1], 0, 1); await httpContext.Response.WriteAsync("hello, world"); }, - new TestServiceContext + new KestrelServerOptions { - ServerOptions = new KestrelServerOptions + AddServerHeader = false, + Limits = { - AddServerHeader = false, - Limits = - { - RequestHeadersTimeout = RequestHeadersTimeout - } + RequestHeadersTimeout = RequestHeadersTimeout } }); } - private async Task ReceiveResponse(TestConnection connection, TestServiceContext testServiceContext) + private async Task ReceiveResponse(TestConnection connection) { await connection.Receive( "HTTP/1.1 200 OK", - $"Date: {testServiceContext.DateHeaderValue}", + ""); + await connection.ReceiveStartsWith("Date: "); + await connection.Receive( "Transfer-Encoding: chunked", "", "c", @@ -122,12 +122,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests ""); } - private async Task ReceiveTimeoutResponse(TestConnection connection, TestServiceContext testServiceContext) + private async Task ReceiveTimeoutResponse(TestConnection connection) { - await connection.ReceiveForcedEnd( + await connection.Receive( "HTTP/1.1 408 Request Timeout", "Connection: close", - $"Date: {testServiceContext.DateHeaderValue}", + ""); + await connection.ReceiveStartsWith("Date: "); + await connection.ReceiveForcedEnd( "Content-Length: 0", "", ""); diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/TestHelpers/TimeoutTestServer.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/TestHelpers/TimeoutTestServer.cs new file mode 100644 index 0000000000..9cf5e46e3d --- /dev/null +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/TestHelpers/TimeoutTestServer.cs @@ -0,0 +1,49 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Net; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Server.Kestrel.Core; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv; +using Microsoft.AspNetCore.Testing; +using Microsoft.Extensions.Options; + +namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests.TestHelpers +{ + public class TimeoutTestServer : IDisposable + { + private readonly KestrelServer _server; + private readonly ListenOptions _listenOptions; + + public TimeoutTestServer(RequestDelegate app, KestrelServerOptions serverOptions) + { + var loggerFactory = new KestrelTestLoggerFactory(new TestApplicationErrorLogger()); + var libuvTransportFactory = new LibuvTransportFactory(Options.Create(new LibuvTransportOptions()), new LifetimeNotImplemented(), loggerFactory); + + _listenOptions = new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0)); + serverOptions.ListenOptions.Add(_listenOptions); + _server = new KestrelServer(Options.Create(serverOptions), libuvTransportFactory, loggerFactory); + + try + { + _server.Start(new DummyApplication(app)); + } + catch + { + _server.Dispose(); + throw; + } + } + + public TestConnection CreateConnection() + { + return new TestConnection(_listenOptions.IPEndPoint.Port, _listenOptions.IPEndPoint.AddressFamily); + } + + public void Dispose() + { + _server?.Dispose(); + } + } +} diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Mocks/MockConnectionInformation.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Mocks/MockConnectionInformation.cs index fd1915cff7..7aa345898b 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Mocks/MockConnectionInformation.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Mocks/MockConnectionInformation.cs @@ -15,22 +15,5 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance public PipeFactory PipeFactory { get; } public IScheduler InputWriterScheduler { get; } public IScheduler OutputReaderScheduler { get; } - - public ITimeoutControl TimeoutControl { get; } = new MockTimeoutControl(); - - private class MockTimeoutControl : ITimeoutControl - { - public void CancelTimeout() - { - } - - public void ResetTimeout(long milliseconds, TimeoutAction timeoutAction) - { - } - - public void SetTimeout(long milliseconds, TimeoutAction timeoutAction) - { - } - } } } diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Mocks/MockTrace.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Mocks/MockTrace.cs index f98d3c15cf..bfb22e1d65 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Mocks/MockTrace.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Mocks/MockTrace.cs @@ -34,5 +34,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance public void NotAllConnectionsAborted() { } public void NotAllConnectionsClosedGracefully() { } public void RequestProcessingError(string connectionId, Exception ex) { } + public virtual void TimerSlow(TimeSpan interval, DateTimeOffset now) { } } } diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/TestHelpers/MockConnection.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/TestHelpers/MockConnection.cs index a40892a1d0..5e2802f976 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/TestHelpers/MockConnection.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/TestHelpers/MockConnection.cs @@ -15,7 +15,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests.TestHelpers public MockConnection() { - TimeoutControl = this; RequestAbortedSource = new CancellationTokenSource(); ListenerContext = new ListenerContext(new LibuvTransportContext()); } diff --git a/test/shared/TestApplicationErrorLogger.cs b/test/shared/TestApplicationErrorLogger.cs index d77a1c08ed..404b2cabc8 100644 --- a/test/shared/TestApplicationErrorLogger.cs +++ b/test/shared/TestApplicationErrorLogger.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Concurrent; +using System.Threading.Tasks; using System.Linq; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; using Microsoft.Extensions.Logging; @@ -14,6 +15,8 @@ namespace Microsoft.AspNetCore.Testing // Application errors are logged using 13 as the eventId. private const int ApplicationErrorEventId = 13; + private TaskCompletionSource _messageLoggedTcs = new TaskCompletionSource(); + public bool ThrowOnCriticalErrors { get; set; } = true; public ConcurrentBag Messages { get; } = new ConcurrentBag(); @@ -24,6 +27,8 @@ namespace Microsoft.AspNetCore.Testing public int ApplicationErrorsLogged => Messages.Count(message => message.EventId.Id == ApplicationErrorEventId); + public Task MessageLoggedTask => _messageLoggedTcs.Task; + public IDisposable BeginScope(TState state) { return new Disposable(() => { }); @@ -55,6 +60,8 @@ namespace Microsoft.AspNetCore.Testing Exception = exception, Message = formatter(state, exception) }); + + _messageLoggedTcs.TrySetResult(null); } public class LogMessage diff --git a/test/shared/TestConnection.cs b/test/shared/TestConnection.cs index 33016bd473..b3b377118d 100644 --- a/test/shared/TestConnection.cs +++ b/test/shared/TestConnection.cs @@ -126,6 +126,38 @@ namespace Microsoft.AspNetCore.Testing } } + public async Task ReceiveStartsWith(string prefix, int maxLineLength = 1024) + { + var actual = new char[maxLineLength]; + var offset = 0; + + while (offset < maxLineLength) + { + // Read one char at a time so we don't read past the end of the line. + var task = _reader.ReadAsync(actual, offset, 1); + if (!Debugger.IsAttached) + { + Assert.True(task.Wait(4000), "timeout"); + } + var count = await task; + if (count == 0) + { + break; + } + + Assert.True(count == 1); + offset++; + + if (actual[offset - 1] == '\n') + { + break; + } + } + + var actualLine = new string(actual, 0, offset); + Assert.StartsWith(prefix, actualLine); + } + public void Shutdown(SocketShutdown how) { _socket.Shutdown(how); diff --git a/test/shared/TestServiceContext.cs b/test/shared/TestServiceContext.cs index 808a03998d..5b9cbea147 100644 --- a/test/shared/TestServiceContext.cs +++ b/test/shared/TestServiceContext.cs @@ -16,7 +16,9 @@ namespace Microsoft.AspNetCore.Testing Log = new TestKestrelTrace(logger); ThreadPool = new LoggingThreadPool(Log); - DateHeaderValueManager = new DateHeaderValueManager(systemClock: new MockSystemClock()); + SystemClock = new MockSystemClock(); + DateHeaderValueManager = new DateHeaderValueManager(SystemClock); + ConnectionManager = new FrameConnectionManager(); DateHeaderValue = DateHeaderValueManager.GetDateHeaderValues().String; HttpParserFactory = frameAdapter => new HttpParser(frameAdapter.Frame.ServiceContext.Log); ServerOptions = new KestrelServerOptions From e043fa871ed55c31859960003f1e492d80e2daad Mon Sep 17 00:00:00 2001 From: Chris R Date: Tue, 11 Apr 2017 10:18:29 -0700 Subject: [PATCH 1203/1662] Make IServer Start and Stop async --- .../KestrelServer.cs | 50 ++++++++++++------- .../KestrelServerTests.cs | 3 +- .../TestHelpers/TimeoutTestServer.cs | 3 +- 3 files changed, 37 insertions(+), 19 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/KestrelServer.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/KestrelServer.cs index 6b8085e3a5..8a4612c282 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/KestrelServer.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/KestrelServer.cs @@ -6,6 +6,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; using System.Net; +using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting.Server; @@ -29,6 +30,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core private readonly ITransportFactory _transportFactory; private bool _isRunning; + private int _stopped; private Heartbeat _heartbeat; public KestrelServer( @@ -67,7 +69,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core private InternalKestrelServerOptions InternalOptions { get; } - public void Start(IHttpApplication application) + public async Task StartAsync(IHttpApplication application, CancellationToken cancellationToken) { try { @@ -129,7 +131,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core _logger.LogDebug($"No listening endpoints were configured. Binding to {Constants.DefaultServerAddress} by default."); // "localhost" for both IPv4 and IPv6 can't be represented as an IPEndPoint. - StartLocalhost(ServerAddress.FromUrl(Constants.DefaultServerAddress), serviceContext, application); + await StartLocalhostAsync(ServerAddress.FromUrl(Constants.DefaultServerAddress), serviceContext, application, cancellationToken); // If StartLocalhost doesn't throw, there is at least one listener. // The port cannot change for "localhost". @@ -174,7 +176,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core if (string.Equals(parsedAddress.Host, "localhost", StringComparison.OrdinalIgnoreCase)) { // "localhost" for both IPv4 and IPv6 can't be represented as an IPEndPoint. - StartLocalhost(parsedAddress, serviceContext, application); + await StartLocalhostAsync(parsedAddress, serviceContext, application, cancellationToken); // If StartLocalhost doesn't throw, there is at least one listener. // The port cannot change for "localhost". @@ -200,9 +202,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core try { - transport.BindAsync().Wait(); + await transport.BindAsync(); } - catch (AggregateException ex) when (ex.InnerException is AddressInUseException) + catch (AddressInUseException ex) { throw new IOException($"Failed to bind to address {endPoint}: address already in use.", ex); } @@ -219,8 +221,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core } } - public void Dispose() + // Graceful shutdown if possible + public async Task StopAsync(CancellationToken cancellationToken) { + if (Interlocked.Exchange(ref _stopped, 1) == 1) + { + return; + } + if (_transports != null) { var tasks = new Task[_transports.Count]; @@ -228,19 +236,27 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core { tasks[i] = _transports[i].UnbindAsync(); } - Task.WaitAll(tasks); + await Task.WhenAll(tasks); // TODO: Do transport-agnostic connection management/shutdown. for (int i = 0; i < _transports.Count; i++) { tasks[i] = _transports[i].StopAsync(); } - Task.WaitAll(tasks); + await Task.WhenAll(tasks); } _heartbeat?.Dispose(); } + // Ungraceful shutdown + public void Dispose() + { + var cancelledTokenSource = new CancellationTokenSource(); + cancelledTokenSource.Cancel(); + StopAsync(cancelledTokenSource.Token).GetAwaiter().GetResult(); + } + private void ValidateOptions() { if (Options.Limits.MaxRequestBufferSize.HasValue && @@ -258,7 +274,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core } } - private void StartLocalhost(ServerAddress parsedAddress, ServiceContext serviceContext, IHttpApplication application) + private async Task StartLocalhostAsync(ServerAddress parsedAddress, ServiceContext serviceContext, IHttpApplication application, CancellationToken cancellationToken) { if (parsedAddress.Port == 0) { @@ -277,16 +293,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core var connectionHandler = new ConnectionHandler(ipv4ListenOptions, serviceContext, application); var transport = _transportFactory.Create(ipv4ListenOptions, connectionHandler); _transports.Add(transport); - transport.BindAsync().Wait(); + await transport.BindAsync(); } - catch (AggregateException ex) when (ex.InnerException is AddressInUseException) + catch (AddressInUseException ex) { throw new IOException($"Failed to bind to address {parsedAddress} on the IPv4 loopback interface: port already in use.", ex); } - catch (AggregateException ex) + catch (Exception ex) { _logger.LogWarning(0, $"Unable to bind to {parsedAddress} on the IPv4 loopback interface: ({ex.Message})"); - exceptions.Add(ex.InnerException); + exceptions.Add(ex); } try @@ -299,16 +315,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core var connectionHandler = new ConnectionHandler(ipv6ListenOptions, serviceContext, application); var transport = _transportFactory.Create(ipv6ListenOptions, connectionHandler); _transports.Add(transport); - transport.BindAsync().Wait(); + await transport.BindAsync(); } - catch (AggregateException ex) when (ex.InnerException is AddressInUseException) + catch (AddressInUseException ex) { throw new IOException($"Failed to bind to address {parsedAddress} on the IPv6 loopback interface: port already in use.", ex); } - catch (AggregateException ex) + catch (Exception ex) { _logger.LogWarning(0, $"Unable to bind to {parsedAddress} on the IPv6 loopback interface: ({ex.Message})"); - exceptions.Add(ex.InnerException); + exceptions.Add(ex); } if (exceptions.Count == 2) diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/KestrelServerTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/KestrelServerTests.cs index bbb3f21c1d..2f1346c9d2 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/KestrelServerTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/KestrelServerTests.cs @@ -4,6 +4,7 @@ using System; using System.Linq; using System.Net; +using System.Threading; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting.Server; using Microsoft.AspNetCore.Hosting.Server.Features; @@ -161,7 +162,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests private static void StartDummyApplication(IServer server) { - server.Start(new DummyApplication(context => TaskCache.CompletedTask)); + server.StartAsync(new DummyApplication(context => TaskCache.CompletedTask), CancellationToken.None).GetAwaiter().GetResult(); } private class MockTransportFactory : ITransportFactory diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/TestHelpers/TimeoutTestServer.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/TestHelpers/TimeoutTestServer.cs index 9cf5e46e3d..6de0a5c82c 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/TestHelpers/TimeoutTestServer.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/TestHelpers/TimeoutTestServer.cs @@ -3,6 +3,7 @@ using System; using System.Net; +using System.Threading; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv; @@ -27,7 +28,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests.TestHelpers try { - _server.Start(new DummyApplication(app)); + _server.StartAsync(new DummyApplication(app), CancellationToken.None).GetAwaiter().GetResult(); } catch { From 8b6d933711162fd9dd35742c5ffe6299dc5f4c37 Mon Sep 17 00:00:00 2001 From: Chris R Date: Thu, 13 Apr 2017 07:26:51 -0700 Subject: [PATCH 1204/1662] Add ConfigureAwaits to prevent test deadlocks --- .../KestrelServer.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/KestrelServer.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/KestrelServer.cs index 8a4612c282..83058d881a 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/KestrelServer.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/KestrelServer.cs @@ -131,7 +131,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core _logger.LogDebug($"No listening endpoints were configured. Binding to {Constants.DefaultServerAddress} by default."); // "localhost" for both IPv4 and IPv6 can't be represented as an IPEndPoint. - await StartLocalhostAsync(ServerAddress.FromUrl(Constants.DefaultServerAddress), serviceContext, application, cancellationToken); + await StartLocalhostAsync(ServerAddress.FromUrl(Constants.DefaultServerAddress), serviceContext, application, cancellationToken).ConfigureAwait(false); // If StartLocalhost doesn't throw, there is at least one listener. // The port cannot change for "localhost". @@ -176,7 +176,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core if (string.Equals(parsedAddress.Host, "localhost", StringComparison.OrdinalIgnoreCase)) { // "localhost" for both IPv4 and IPv6 can't be represented as an IPEndPoint. - await StartLocalhostAsync(parsedAddress, serviceContext, application, cancellationToken); + await StartLocalhostAsync(parsedAddress, serviceContext, application, cancellationToken).ConfigureAwait(false); // If StartLocalhost doesn't throw, there is at least one listener. // The port cannot change for "localhost". @@ -202,7 +202,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core try { - await transport.BindAsync(); + await transport.BindAsync().ConfigureAwait(false); } catch (AddressInUseException ex) { @@ -236,14 +236,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core { tasks[i] = _transports[i].UnbindAsync(); } - await Task.WhenAll(tasks); + await Task.WhenAll(tasks).ConfigureAwait(false); // TODO: Do transport-agnostic connection management/shutdown. for (int i = 0; i < _transports.Count; i++) { tasks[i] = _transports[i].StopAsync(); } - await Task.WhenAll(tasks); + await Task.WhenAll(tasks).ConfigureAwait(false); } _heartbeat?.Dispose(); From 8258d300e2537d813f03b83610465a099cf3baf3 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Thu, 13 Apr 2017 09:29:43 -0700 Subject: [PATCH 1205/1662] Small tweaks to timer logic (#1668) - Avoid null refs in tests by ignoring null IKestrelTrace - Use a static callback for the timer callback Fixes #1667 --- .../Internal/Infrastructure/Heartbeat.cs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/Heartbeat.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/Heartbeat.cs index 089b779e92..94e58d8ea8 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/Heartbeat.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/Heartbeat.cs @@ -32,9 +32,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure _trace = trace; _timer = new Timer(OnHeartbeat, state: this, dueTime: _interval, period: _interval); } + + private static void OnHeartbeat(object state) + { + ((Heartbeat)state).OnHeartbeat(); + } // Called by the Timer (background) thread - private void OnHeartbeat(object state) + private void OnHeartbeat() { var now = _systemClock.UtcNow; @@ -58,7 +63,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure } else { - _trace.TimerSlow(_interval, now); + // Tests usually pass in a null trace + _trace?.TimerSlow(_interval, now); } } From ed4a27a827e470ca1abec3e283eb19b423458c5f Mon Sep 17 00:00:00 2001 From: Nate McMaster Date: Wed, 12 Apr 2017 14:40:58 -0700 Subject: [PATCH 1206/1662] Remove ListenOptions.Scheme and move IConnectionFilter to .Internal namespace Add an internal API to ListenOptions to determine if an endpoint is configured to use HTTPS. This is a temporary as the design of connection adapters and configuration will churn before release. --- .../ConnectionAdapterContext.cs | 2 +- .../{ => Internal}/IAdaptedConnection.cs | 2 +- .../{ => Internal}/IConnectionAdapter.cs | 3 +- .../Adapter/LoggingConnectionAdapter.cs | 2 ++ .../Internal/ConnectionHandler.cs | 2 +- .../Internal/FrameConnectionContext.cs | 2 +- .../Internal/Http/Frame.cs | 2 +- .../Infrastructure/KestrelEventSource.cs | 5 +--- .../KestrelServer.cs | 29 +++++++------------ .../ListenOptions.cs | 27 +++++++++-------- .../HttpsConnectionAdapter.cs | 4 ++- .../AddressRegistrationTests.cs | 16 ++++++++++ .../ConnectionAdapterTests.cs | 8 ++++- .../EventSourceTests.cs | 3 +- .../ListenerPrimaryTests.cs | 23 ++++++++++++--- test/shared/PassThroughConnectionAdapter.cs | 2 ++ 16 files changed, 83 insertions(+), 49 deletions(-) rename src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/{ => Internal}/ConnectionAdapterContext.cs (89%) rename src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/{ => Internal}/IAdaptedConnection.cs (85%) rename src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/{ => Internal}/IConnectionAdapter.cs (77%) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/ConnectionAdapterContext.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/Internal/ConnectionAdapterContext.cs similarity index 89% rename from src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/ConnectionAdapterContext.cs rename to src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/Internal/ConnectionAdapterContext.cs index 380f56ffc8..6d074b3a7c 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/ConnectionAdapterContext.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/Internal/ConnectionAdapterContext.cs @@ -3,7 +3,7 @@ using System.IO; -namespace Microsoft.AspNetCore.Server.Kestrel.Core.Adapter +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal { // Even though this only includes the non-adapted ConnectionStream currently, this is a context in case // we want to add more connection metadata later. diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/IAdaptedConnection.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/Internal/IAdaptedConnection.cs similarity index 85% rename from src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/IAdaptedConnection.cs rename to src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/Internal/IAdaptedConnection.cs index 793d4b7e0a..8c39b07c3e 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/IAdaptedConnection.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/Internal/IAdaptedConnection.cs @@ -4,7 +4,7 @@ using System.IO; using Microsoft.AspNetCore.Http.Features; -namespace Microsoft.AspNetCore.Server.Kestrel.Core.Adapter +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal { public interface IAdaptedConnection { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/IConnectionAdapter.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/Internal/IConnectionAdapter.cs similarity index 77% rename from src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/IConnectionAdapter.cs rename to src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/Internal/IConnectionAdapter.cs index 57c9d904d9..e0249d5545 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/IConnectionAdapter.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/Internal/IConnectionAdapter.cs @@ -3,10 +3,11 @@ using System.Threading.Tasks; -namespace Microsoft.AspNetCore.Server.Kestrel.Core.Adapter +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal { public interface IConnectionAdapter { + bool IsHttps { get; } Task OnConnectionAsync(ConnectionAdapterContext context); } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/LoggingConnectionAdapter.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/LoggingConnectionAdapter.cs index d0c268b1b4..d685e1027d 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/LoggingConnectionAdapter.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/LoggingConnectionAdapter.cs @@ -24,6 +24,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Adapter _logger = logger; } + public bool IsHttps => false; + public Task OnConnectionAsync(ConnectionAdapterContext context) { return Task.FromResult( diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/ConnectionHandler.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/ConnectionHandler.cs index 4cf062d7ca..db9236d9d8 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/ConnectionHandler.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/ConnectionHandler.cs @@ -59,7 +59,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal }); _serviceContext.Log.ConnectionStart(connectionId); - KestrelEventSource.Log.ConnectionStart(_listenOptions, connection, connectionInfo); + KestrelEventSource.Log.ConnectionStart(connection, connectionInfo); // Since data cannot be added to the inputPipe by the transport until OnConnection returns, // Frame.RequestProcessingAsync is guaranteed to unblock the transport thread before calling diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnectionContext.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnectionContext.cs index c4edded73e..1394f6c150 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnectionContext.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnectionContext.cs @@ -2,7 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Collections.Generic; -using Microsoft.AspNetCore.Server.Kestrel.Core.Adapter; +using Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.cs index 875e406463..4d84a1c6d4 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.cs @@ -12,7 +12,7 @@ using System.Text; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Server.Kestrel.Core.Adapter; +using Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Internal.System; using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/KestrelEventSource.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/KestrelEventSource.cs index 2e1b942de3..eb04b7f486 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/KestrelEventSource.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/KestrelEventSource.cs @@ -26,14 +26,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure // - Avoid renaming methods or parameters marked with EventAttribute. EventSource uses these to form the event object. [NonEvent] - public void ConnectionStart(ListenOptions listenOptions, IConnectionContext context, IConnectionInformation information) + public void ConnectionStart(IConnectionContext context, IConnectionInformation information) { // avoid allocating strings unless this event source is enabled if (IsEnabled()) { ConnectionStart( context.ConnectionId, - listenOptions.Scheme, information.LocalEndPoint.ToString(), information.RemoteEndPoint.ToString()); } @@ -42,14 +41,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure [MethodImpl(MethodImplOptions.NoInlining)] [Event(1, Level = EventLevel.Verbose)] private void ConnectionStart(string connectionId, - string scheme, string localEndPoint, string remoteEndPoint) { WriteEvent( 1, connectionId, - scheme, localEndPoint, remoteEndPoint ); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/KestrelServer.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/KestrelServer.cs index 83058d881a..5c5d204564 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/KestrelServer.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/KestrelServer.cs @@ -153,6 +153,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core { throw new InvalidOperationException($"HTTPS endpoints can only be configured using {nameof(KestrelServerOptions)}.{nameof(KestrelServerOptions.Listen)}()."); } + else if (!parsedAddress.Scheme.Equals("http", StringComparison.OrdinalIgnoreCase)) + { + throw new InvalidOperationException($"Unrecognized scheme in server address '{address}'. Only 'http://' is supported."); + } if (!string.IsNullOrEmpty(parsedAddress.PathBase)) { @@ -166,10 +170,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core if (parsedAddress.IsUnixPipe) { - listenOptions.Add(new ListenOptions(parsedAddress.UnixPipePath) - { - Scheme = parsedAddress.Scheme, - }); + listenOptions.Add(new ListenOptions(parsedAddress.UnixPipePath)); } else { @@ -185,10 +186,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core else { // These endPoints will be added later to _serverAddresses.Addresses - listenOptions.Add(new ListenOptions(CreateIPEndPoint(parsedAddress)) - { - Scheme = parsedAddress.Scheme, - }); + listenOptions.Add(new ListenOptions(CreateIPEndPoint(parsedAddress))); } } } @@ -209,8 +207,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core throw new IOException($"Failed to bind to address {endPoint}: address already in use.", ex); } - // If requested port was "0", replace with assigned dynamic port. - _serverAddresses.Addresses.Add(endPoint.ToString()); + _serverAddresses.Addresses.Add(endPoint.GetDisplayName()); } } catch (Exception ex) @@ -285,10 +282,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core try { - var ipv4ListenOptions = new ListenOptions(new IPEndPoint(IPAddress.Loopback, parsedAddress.Port)) - { - Scheme = parsedAddress.Scheme, - }; + var ipv4ListenOptions = new ListenOptions(new IPEndPoint(IPAddress.Loopback, parsedAddress.Port)); var connectionHandler = new ConnectionHandler(ipv4ListenOptions, serviceContext, application); var transport = _transportFactory.Create(ipv4ListenOptions, connectionHandler); @@ -307,10 +301,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core try { - var ipv6ListenOptions = new ListenOptions(new IPEndPoint(IPAddress.IPv6Loopback, parsedAddress.Port)) - { - Scheme = parsedAddress.Scheme, - }; + var ipv6ListenOptions = new ListenOptions(new IPEndPoint(IPAddress.IPv6Loopback, parsedAddress.Port)); var connectionHandler = new ConnectionHandler(ipv6ListenOptions, serviceContext, application); var transport = _transportFactory.Create(ipv6ListenOptions, connectionHandler); @@ -349,4 +340,4 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core return new IPEndPoint(ip, address.Port); } } -} \ No newline at end of file +} diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/ListenOptions.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/ListenOptions.cs index 8777ba98bc..2e009f542b 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/ListenOptions.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/ListenOptions.cs @@ -3,8 +3,9 @@ using System; using System.Collections.Generic; +using System.Linq; using System.Net; -using Microsoft.AspNetCore.Server.Kestrel.Core.Adapter; +using Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal; using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions; namespace Microsoft.AspNetCore.Server.Kestrel.Core @@ -82,26 +83,28 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core /// public List ConnectionAdapters { get; } = new List(); - // Scheme is hopefully only a temporary measure for back compat with IServerAddressesFeature. - // TODO: Allow connection adapters to configure the scheme - public string Scheme { get; set; } = "http"; - - public override string ToString() + /// + /// Gets the name of this endpoint to display on command-line when the web server starts. + /// + internal string GetDisplayName() { - // Use http scheme for all addresses. If https should be used for this endPoint, - // it can still be configured for this endPoint specifically. + var scheme = ConnectionAdapters.Any(f => f.IsHttps) + ? "https" + : "http"; + switch (Type) { case ListenType.IPEndPoint: - return $"{Scheme}://{IPEndPoint}"; + return $"{scheme}://{IPEndPoint}"; case ListenType.SocketPath: - return $"{Scheme}://unix:{SocketPath}"; + return $"{scheme}://unix:{SocketPath}"; case ListenType.FileHandle: - // This was never supported via --server.urls, so no need to include Scheme. - return "http://"; + return $"{scheme}://"; default: throw new InvalidOperationException(); } } + + public override string ToString() => GetDisplayName(); } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Https/HttpsConnectionAdapter.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Https/HttpsConnectionAdapter.cs index 7f5aa71eb0..298c501bea 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Https/HttpsConnectionAdapter.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Https/HttpsConnectionAdapter.cs @@ -7,7 +7,7 @@ using System.Net.Security; using System.Security.Cryptography.X509Certificates; using System.Threading.Tasks; using Microsoft.AspNetCore.Http.Features; -using Microsoft.AspNetCore.Server.Kestrel.Core.Adapter; +using Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal; using Microsoft.AspNetCore.Server.Kestrel.Https.Internal; using Microsoft.Extensions.Logging; @@ -40,6 +40,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Https _logger = loggerFactory?.CreateLogger(nameof(HttpsConnectionAdapter)); } + public bool IsHttps => true; + public async Task OnConnectionAsync(ConnectionAdapterContext context) { SslStream sslStream; diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs index dcdbaa67a3..eb84fd3331 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs @@ -260,6 +260,22 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } } + [Theory] + [InlineData("https://localhost")] + [InlineData("ftp://localhost")] + public void ThrowsForUnsupportedAddressFromHosting(string addr) + { + var hostBuilder = new WebHostBuilder() + .UseKestrel() + .UseUrls(addr) + .Configure(ConfigureEchoAddress); + + using (var host = hostBuilder.Build()) + { + Assert.Throws(() => host.Start()); + } + } + private void ThrowsWhenBindingLocalhostToAddressInUse(AddressFamily addressFamily, IPAddress address) { using (var socket = new Socket(addressFamily, SocketType.Stream, ProtocolType.Tcp)) diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ConnectionAdapterTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ConnectionAdapterTests.cs index 0d8150f62c..aecf4a30d7 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ConnectionAdapterTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ConnectionAdapterTests.cs @@ -8,7 +8,7 @@ using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Server.Kestrel.Core; -using Microsoft.AspNetCore.Server.Kestrel.Core.Adapter; +using Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal; using Microsoft.AspNetCore.Testing; using Xunit; @@ -112,6 +112,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { private RewritingStream _rewritingStream; + public bool IsHttps => false; + public Task OnConnectionAsync(ConnectionAdapterContext context) { _rewritingStream = new RewritingStream(context.ConnectionStream); @@ -123,6 +125,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests private class AsyncConnectionAdapter : IConnectionAdapter { + public bool IsHttps => false; + public async Task OnConnectionAsync(ConnectionAdapterContext context) { await Task.Delay(100); @@ -132,6 +136,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests private class ThrowingConnectionAdapter : IConnectionAdapter { + public bool IsHttps => false; + public Task OnConnectionAsync(ConnectionAdapterContext context) { throw new Exception(); diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/EventSourceTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/EventSourceTests.cs index a0124e51a7..f692537ea7 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/EventSourceTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/EventSourceTests.cs @@ -55,8 +55,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { var start = Assert.Single(events, e => e.EventName == "ConnectionStart"); - Assert.All(new[] { "connectionId", "scheme", "remoteEndPoint", "localEndPoint" }, p => Assert.Contains(p, start.PayloadNames)); - Assert.Equal("http", GetProperty(start, "scheme")); + Assert.All(new[] { "connectionId", "remoteEndPoint", "localEndPoint" }, p => Assert.Contains(p, start.PayloadNames)); Assert.Equal($"127.0.0.1:{port}", GetProperty(start, "localEndPoint")); } { diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/ListenerPrimaryTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/ListenerPrimaryTests.cs index 46defb4317..07658dcc23 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/ListenerPrimaryTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/ListenerPrimaryTests.cs @@ -9,6 +9,7 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions; using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal; using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking; using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests.TestHelpers; @@ -46,7 +47,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests await libuvThreadPrimary.StartAsync(); var listenerPrimary = new ListenerPrimary(transportContextPrimary); await listenerPrimary.StartAsync(pipeName, pipeMessage, listenOptions, libuvThreadPrimary); - var address = listenOptions.ToString(); + var address = GetUri(listenOptions); // Until a secondary listener is added, TCP connections get dispatched directly Assert.Equal("Primary", await HttpClientSlim.GetStringAsync(address)); @@ -108,7 +109,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests await libuvThreadPrimary.StartAsync(); var listenerPrimary = new ListenerPrimary(transportContextPrimary); await listenerPrimary.StartAsync(pipeName, pipeMessage, listenOptions, libuvThreadPrimary); - var address = listenOptions.ToString(); + var address = GetUri(listenOptions); // Add secondary listener var libuvThreadSecondary = new LibuvThread(libuvTransport); @@ -217,7 +218,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests await libuvThreadPrimary.StartAsync(); var listenerPrimary = new ListenerPrimary(transportContextPrimary); await listenerPrimary.StartAsync(pipeName, pipeMessage, listenOptions, libuvThreadPrimary); - var address = listenOptions.ToString(); + var address = GetUri(listenOptions); // Add secondary listener with wrong pipe message var libuvThreadSecondary = new LibuvThread(libuvTransport); @@ -249,7 +250,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests } private static async Task AssertResponseEventually( - string address, + Uri address, string expected, string[] allowed = null, int maxRetries = 100, @@ -273,5 +274,19 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests Assert.True(false, $"'{address}' failed to respond with '{expected}' in {maxRetries} retries."); } + + private static Uri GetUri(ListenOptions options) + { + if (options.Type != ListenType.IPEndPoint) + { + throw new InvalidOperationException($"Could not determine a proper URI for options with Type {options.Type}"); + } + + var scheme = options.ConnectionAdapters.Any(f => f.IsHttps) + ? "https" + : "http"; + + return new Uri($"{scheme}://{options.IPEndPoint}"); + } } } diff --git a/test/shared/PassThroughConnectionAdapter.cs b/test/shared/PassThroughConnectionAdapter.cs index 7384eaa613..6c4c35bf80 100644 --- a/test/shared/PassThroughConnectionAdapter.cs +++ b/test/shared/PassThroughConnectionAdapter.cs @@ -11,6 +11,8 @@ namespace Microsoft.AspNetCore.Testing { public class PassThroughConnectionAdapter : IConnectionAdapter { + public bool IsHttps => false; + public Task OnConnectionAsync(ConnectionAdapterContext context) { var adapted = new AdaptedConnection(new LoggingStream(context.ConnectionStream, new TestApplicationErrorLogger())); From 6036f27f52ca2a556f7d8a14e6b44923a6b02b62 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Thu, 13 Apr 2017 11:40:21 -0700 Subject: [PATCH 1207/1662] Fix deadlocks in startup and shutdown --- .../KestrelServer.cs | 4 +-- .../Internal/LibuvConnection.cs | 2 +- .../Internal/LibuvConnectionManager.cs | 2 +- .../Internal/LibuvThread.cs | 33 +++---------------- .../Internal/Listener.cs | 25 +++----------- .../Internal/ListenerPrimary.cs | 6 ++-- .../Internal/ListenerSecondary.cs | 5 ++- 7 files changed, 18 insertions(+), 59 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/KestrelServer.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/KestrelServer.cs index 5c5d204564..d963d6f022 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/KestrelServer.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/KestrelServer.cs @@ -287,7 +287,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core var connectionHandler = new ConnectionHandler(ipv4ListenOptions, serviceContext, application); var transport = _transportFactory.Create(ipv4ListenOptions, connectionHandler); _transports.Add(transport); - await transport.BindAsync(); + await transport.BindAsync().ConfigureAwait(false); } catch (AddressInUseException ex) { @@ -306,7 +306,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core var connectionHandler = new ConnectionHandler(ipv6ListenOptions, serviceContext, application); var transport = _transportFactory.Create(ipv6ListenOptions, connectionHandler); _transports.Add(transport); - await transport.BindAsync(); + await transport.BindAsync().ConfigureAwait(false); } catch (AddressInUseException ex) { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvConnection.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvConnection.cs index 0e997c7b51..483a4fd050 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvConnection.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvConnection.cs @@ -26,7 +26,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal private readonly UvStreamHandle _socket; private IConnectionContext _connectionContext; - private TaskCompletionSource _socketClosedTcs = new TaskCompletionSource(); + private TaskCompletionSource _socketClosedTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); private WritableBuffer? _currentWritableBuffer; diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvConnectionManager.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvConnectionManager.cs index 14f314510d..9cc99b919a 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvConnectionManager.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvConnectionManager.cs @@ -29,7 +29,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal private async Task WalkConnectionsAsync(Action> action, TimeSpan timeout) { - var tcs = new TaskCompletionSource(); + var tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); _thread.Post(state => action(state, tcs), this); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvThread.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvThread.cs index 5fb6f33d00..d183f20f72 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvThread.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvThread.cs @@ -24,7 +24,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal private readonly LibuvTransport _transport; private readonly IApplicationLifetime _appLifetime; private readonly Thread _thread; - private readonly TaskCompletionSource _threadTcs = new TaskCompletionSource(); + private readonly TaskCompletionSource _threadTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); private readonly UvLoopHandle _loop; private readonly UvAsyncHandle _post; private Queue _workAdding = new Queue(1024); @@ -87,7 +87,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal public Task StartAsync() { - var tcs = new TaskCompletionSource(); + var tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); _thread.Start(tcs); return tcs.Task; } @@ -203,7 +203,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal public Task PostAsync(Action callback, T state) { - var tcs = new TaskCompletionSource(); + var tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); lock (_workSync) { _workAdding.Enqueue(new Work @@ -332,36 +332,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal try { work.CallbackAdapter(work.Callback, work.State); - if (work.Completion != null) - { - ThreadPool.QueueUserWorkItem(o => - { - try - { - ((TaskCompletionSource)o).SetResult(null); - } - catch (Exception e) - { - _log.LogError(0, e, $"{nameof(LibuvThread)}.{nameof(DoPostWork)}"); - } - }, work.Completion); - } + work.Completion?.TrySetResult(null); } catch (Exception ex) { if (work.Completion != null) { - ThreadPool.QueueUserWorkItem(o => - { - try - { - ((TaskCompletionSource)o).TrySetException(ex); - } - catch (Exception e) - { - _log.LogError(0, e, $"{nameof(LibuvThread)}.{nameof(DoPostWork)}"); - } - }, work.Completion); + work.Completion.TrySetException(ex); } else { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Listener.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Listener.cs index aa03493751..d9d1cf1798 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Listener.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Listener.cs @@ -31,25 +31,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal EndPointInformation = endPointInformation; Thread = thread; - var tcs = new TaskCompletionSource(this); - - Thread.Post(state => + return Thread.PostAsync(listener => { - var tcs2 = state; - try - { - var listener = ((Listener) tcs2.Task.AsyncState); - listener.ListenSocket = listener.CreateListenSocket(); - ListenSocket.Listen(LibuvConstants.ListenBacklog, ConnectionCallback, this); - tcs2.SetResult(0); - } - catch (Exception ex) - { - tcs2.SetException(ex); - } - }, tcs); - - return tcs.Task; + listener.ListenSocket = listener.CreateListenSocket(); + listener.ListenSocket.Listen(LibuvConstants.ListenBacklog, ConnectionCallback, listener); + }, this); } /// @@ -157,9 +143,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal // the exception that stopped the event loop will never be surfaced. if (Thread.FatalError == null && ListenSocket != null) { - await Thread.PostAsync(state => + await Thread.PostAsync(listener => { - var listener = (Listener)state; listener.ListenSocket.Dispose(); listener._closed = true; diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/ListenerPrimary.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/ListenerPrimary.cs index 7ebe34b709..d1cdcd150f 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/ListenerPrimary.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/ListenerPrimary.cs @@ -53,8 +53,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal await StartAsync(endPointInformation, thread).ConfigureAwait(false); - await Thread.PostAsync(state => ((ListenerPrimary)state).PostCallback(), - this).ConfigureAwait(false); + await Thread.PostAsync(listener => listener.PostCallback(), this).ConfigureAwait(false); } private void PostCallback() @@ -175,9 +174,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal if (Thread.FatalError == null && ListenPipe != null) { - await Thread.PostAsync(state => + await Thread.PostAsync(listener => { - var listener = (ListenerPrimary)state; listener.ListenPipe.Dispose(); foreach (var dispatchPipe in listener._dispatchPipes) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/ListenerSecondary.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/ListenerSecondary.cs index 25c7d1ab6d..ced08d8126 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/ListenerSecondary.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/ListenerSecondary.cs @@ -46,7 +46,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal Thread = thread; DispatchPipe = new UvPipeHandle(Log); - var tcs = new TaskCompletionSource(this); + var tcs = new TaskCompletionSource(this, TaskCreationOptions.RunContinuationsAsynchronously); Thread.Post(StartCallback, tcs); return tcs.Task; } @@ -185,9 +185,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal // the exception that stopped the event loop will never be surfaced. if (Thread.FatalError == null) { - await Thread.PostAsync(state => + await Thread.PostAsync(listener => { - var listener = (ListenerSecondary)state; listener.DispatchPipe.Dispose(); listener.FreeBuffer(); From 3045cff3c5b17406329c2fb896e18f4d88416e5c Mon Sep 17 00:00:00 2001 From: Pavel Krymets Date: Thu, 13 Apr 2017 15:54:48 -0700 Subject: [PATCH 1208/1662] Fix adapted output pipe options (#1682) --- .../Internal/FrameConnection.cs | 14 +++++++-- .../PipeOptionsTests.cs | 29 +++++++++++++++---- 2 files changed, 35 insertions(+), 8 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnection.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnection.cs index 19014e8e7a..d847c2aca6 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnection.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnection.cs @@ -48,7 +48,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal private PipeFactory PipeFactory => _context.PipeFactory; // Internal for testing - internal PipeOptions AdaptedPipeOptions => new PipeOptions + internal PipeOptions AdaptedInputPipeOptions => new PipeOptions { ReaderScheduler = InlineScheduler.Default, WriterScheduler = InlineScheduler.Default, @@ -56,6 +56,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal MaximumSizeLow = _context.ServiceContext.ServerOptions.Limits.MaxRequestBufferSize ?? 0 }; + internal PipeOptions AdaptedOutputPipeOptions => new PipeOptions + { + ReaderScheduler = InlineScheduler.Default, + WriterScheduler = InlineScheduler.Default, + MaximumSizeHigh = _context.ServiceContext.ServerOptions.Limits.MaxResponseBufferSize ?? 0, + MaximumSizeLow = _context.ServiceContext.ServerOptions.Limits.MaxResponseBufferSize ?? 0 + }; + private IKestrelTrace Log => _context.ServiceContext.Log; public void StartRequestProcessing() @@ -125,8 +133,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal _filteredStream = adapterContext.ConnectionStream; _adaptedPipeline = new AdaptedPipeline( adapterContext.ConnectionStream, - PipeFactory.Create(AdaptedPipeOptions), - PipeFactory.Create(AdaptedPipeOptions)); + PipeFactory.Create(AdaptedInputPipeOptions), + PipeFactory.Create(AdaptedOutputPipeOptions)); _frame.Input = _adaptedPipeline.Input.Reader; _frame.Output = _adaptedPipeline.Output; diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/PipeOptionsTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/PipeOptionsTests.cs index 5a4cc05601..6183e278fe 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/PipeOptionsTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/PipeOptionsTests.cs @@ -54,7 +54,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests [Theory] [InlineData(10, 10, 10)] [InlineData(null, 0, 0)] - public void AdaptedPipeOptionsConfiguredCorrectly(long? maxRequestBufferSize, long expectedMaximumSizeLow, long expectedMaximumSizeHigh) + public void AdaptedInputPipeOptionsConfiguredCorrectly(long? maxRequestBufferSize, long expectedMaximumSizeLow, long expectedMaximumSizeHigh) { var serviceContext = new TestServiceContext(); serviceContext.ServerOptions.Limits.MaxRequestBufferSize = maxRequestBufferSize; @@ -64,10 +64,29 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests ServiceContext = serviceContext }); - Assert.Equal(expectedMaximumSizeLow, connectionLifetime.AdaptedPipeOptions.MaximumSizeLow); - Assert.Equal(expectedMaximumSizeHigh, connectionLifetime.AdaptedPipeOptions.MaximumSizeHigh); - Assert.Same(InlineScheduler.Default, connectionLifetime.AdaptedPipeOptions.ReaderScheduler); - Assert.Same(InlineScheduler.Default, connectionLifetime.AdaptedPipeOptions.WriterScheduler); + Assert.Equal(expectedMaximumSizeLow, connectionLifetime.AdaptedInputPipeOptions.MaximumSizeLow); + Assert.Equal(expectedMaximumSizeHigh, connectionLifetime.AdaptedInputPipeOptions.MaximumSizeHigh); + Assert.Same(InlineScheduler.Default, connectionLifetime.AdaptedInputPipeOptions.ReaderScheduler); + Assert.Same(InlineScheduler.Default, connectionLifetime.AdaptedInputPipeOptions.WriterScheduler); + } + + [Theory] + [InlineData(10, 10, 10)] + [InlineData(null, 0, 0)] + public void AdaptedOutputPipeOptionsConfiguredCorrectly(long? maxRequestBufferSize, long expectedMaximumSizeLow, long expectedMaximumSizeHigh) + { + var serviceContext = new TestServiceContext(); + serviceContext.ServerOptions.Limits.MaxResponseBufferSize = maxRequestBufferSize; + + var connectionLifetime = new FrameConnection(new FrameConnectionContext + { + ServiceContext = serviceContext + }); + + Assert.Equal(expectedMaximumSizeLow, connectionLifetime.AdaptedOutputPipeOptions.MaximumSizeLow); + Assert.Equal(expectedMaximumSizeHigh, connectionLifetime.AdaptedOutputPipeOptions.MaximumSizeHigh); + Assert.Same(InlineScheduler.Default, connectionLifetime.AdaptedOutputPipeOptions.ReaderScheduler); + Assert.Same(InlineScheduler.Default, connectionLifetime.AdaptedOutputPipeOptions.WriterScheduler); } } } From 0723d46ec43b70c0bef8604e7205c8571594c5ab Mon Sep 17 00:00:00 2001 From: John Luo Date: Sat, 8 Apr 2017 22:18:55 -0700 Subject: [PATCH 1209/1662] Honor PreferHostingUrls #1575 --- .../KestrelServer.cs | 172 ++++++++++-------- .../AddressRegistrationTests.cs | 72 +++++++- 2 files changed, 162 insertions(+), 82 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/KestrelServer.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/KestrelServer.cs index d963d6f022..b5fc7f7275 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/KestrelServer.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/KestrelServer.cs @@ -119,14 +119,36 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core var hasListenOptions = listenOptions.Any(); var hasServerAddresses = _serverAddresses.Addresses.Any(); - if (hasListenOptions && hasServerAddresses) + if (_serverAddresses.PreferHostingUrls && hasServerAddresses) { - var joined = string.Join(", ", _serverAddresses.Addresses); - _logger.LogWarning($"Overriding address(es) '{joined}'. Binding to endpoints defined in UseKestrel() instead."); + if (hasListenOptions) + { + var joined = string.Join(", ", _serverAddresses.Addresses); + _logger.LogInformation($"Overriding endpoints defined in UseKestrel() since {nameof(IServerAddressesFeature.PreferHostingUrls)} is set to true. Binding to address(es) '{joined}' instead."); - _serverAddresses.Addresses.Clear(); + listenOptions.Clear(); + } + + await BindToServerAddresses(listenOptions, serviceContext, application, cancellationToken).ConfigureAwait(false); } - else if (!hasListenOptions && !hasServerAddresses) + else if (hasListenOptions) + { + if (hasServerAddresses) + { + var joined = string.Join(", ", _serverAddresses.Addresses); + _logger.LogWarning($"Overriding address(es) '{joined}'. Binding to endpoints defined in UseKestrel() instead."); + + _serverAddresses.Addresses.Clear(); + } + + await BindToEndpoints(listenOptions, serviceContext, application).ConfigureAwait(false); + } + else if (hasServerAddresses) + { + // If no endpoints are configured directly using KestrelServerOptions, use those configured via the IServerAddressesFeature. + await BindToServerAddresses(listenOptions, serviceContext, application, cancellationToken).ConfigureAwait(false); + } + else { _logger.LogDebug($"No listening endpoints were configured. Binding to {Constants.DefaultServerAddress} by default."); @@ -136,78 +158,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core // If StartLocalhost doesn't throw, there is at least one listener. // The port cannot change for "localhost". _serverAddresses.Addresses.Add(Constants.DefaultServerAddress); - - return; - } - else if (!hasListenOptions) - { - // If no endpoints are configured directly using KestrelServerOptions, use those configured via the IServerAddressesFeature. - var copiedAddresses = _serverAddresses.Addresses.ToArray(); - _serverAddresses.Addresses.Clear(); - - foreach (var address in copiedAddresses) - { - var parsedAddress = ServerAddress.FromUrl(address); - - if (parsedAddress.Scheme.Equals("https", StringComparison.OrdinalIgnoreCase)) - { - throw new InvalidOperationException($"HTTPS endpoints can only be configured using {nameof(KestrelServerOptions)}.{nameof(KestrelServerOptions.Listen)}()."); - } - else if (!parsedAddress.Scheme.Equals("http", StringComparison.OrdinalIgnoreCase)) - { - throw new InvalidOperationException($"Unrecognized scheme in server address '{address}'. Only 'http://' is supported."); - } - - if (!string.IsNullOrEmpty(parsedAddress.PathBase)) - { - throw new InvalidOperationException($"A path base can only be configured using {nameof(IApplicationBuilder)}.UsePathBase()."); - } - - if (!string.IsNullOrEmpty(parsedAddress.PathBase)) - { - _logger.LogWarning($"Path base in address {address} is not supported and will be ignored. To specify a path base, use {nameof(IApplicationBuilder)}.UsePathBase()."); - } - - if (parsedAddress.IsUnixPipe) - { - listenOptions.Add(new ListenOptions(parsedAddress.UnixPipePath)); - } - else - { - if (string.Equals(parsedAddress.Host, "localhost", StringComparison.OrdinalIgnoreCase)) - { - // "localhost" for both IPv4 and IPv6 can't be represented as an IPEndPoint. - await StartLocalhostAsync(parsedAddress, serviceContext, application, cancellationToken).ConfigureAwait(false); - - // If StartLocalhost doesn't throw, there is at least one listener. - // The port cannot change for "localhost". - _serverAddresses.Addresses.Add(parsedAddress.ToString()); - } - else - { - // These endPoints will be added later to _serverAddresses.Addresses - listenOptions.Add(new ListenOptions(CreateIPEndPoint(parsedAddress))); - } - } - } - } - - foreach (var endPoint in listenOptions) - { - var connectionHandler = new ConnectionHandler(endPoint, serviceContext, application); - var transport = _transportFactory.Create(endPoint, connectionHandler); - _transports.Add(transport); - - try - { - await transport.BindAsync().ConfigureAwait(false); - } - catch (AddressInUseException ex) - { - throw new IOException($"Failed to bind to address {endPoint}: address already in use.", ex); - } - - _serverAddresses.Addresses.Add(endPoint.GetDisplayName()); } } catch (Exception ex) @@ -218,6 +168,72 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core } } + private async Task BindToServerAddresses(List listenOptions, ServiceContext serviceContext, IHttpApplication application, CancellationToken cancellationToken) + { + var copiedAddresses = _serverAddresses.Addresses.ToArray(); + _serverAddresses.Addresses.Clear(); + foreach (var address in copiedAddresses) + { + var parsedAddress = ServerAddress.FromUrl(address); + + if (parsedAddress.Scheme.Equals("https", StringComparison.OrdinalIgnoreCase)) + { + throw new InvalidOperationException($"HTTPS endpoints can only be configured using {nameof(KestrelServerOptions)}.{nameof(KestrelServerOptions.Listen)}()."); + } + else if (!parsedAddress.Scheme.Equals("http", StringComparison.OrdinalIgnoreCase)) + { + throw new InvalidOperationException($"Unrecognized scheme in server address '{address}'. Only 'http://' is supported."); + } + + if (!string.IsNullOrEmpty(parsedAddress.PathBase)) + { + throw new InvalidOperationException($"A path base can only be configured using {nameof(IApplicationBuilder)}.UsePathBase()."); + } + + if (parsedAddress.IsUnixPipe) + { + listenOptions.Add(new ListenOptions(parsedAddress.UnixPipePath)); + } + else if (string.Equals(parsedAddress.Host, "localhost", StringComparison.OrdinalIgnoreCase)) + { + // "localhost" for both IPv4 and IPv6 can't be represented as an IPEndPoint. + await StartLocalhostAsync(parsedAddress, serviceContext, application, cancellationToken).ConfigureAwait(false); + // If StartLocalhost doesn't throw, there is at least one listener. + // The port cannot change for "localhost". + _serverAddresses.Addresses.Add(parsedAddress.ToString()); + } + else + { + // These endPoints will be added later to _serverAddresses.Addresses + listenOptions.Add(new ListenOptions(CreateIPEndPoint(parsedAddress))); + } + } + + await BindToEndpoints(listenOptions, serviceContext, application).ConfigureAwait(false); + } + + private async Task BindToEndpoints(List listenOptions, ServiceContext serviceContext, IHttpApplication application) + { + foreach (var endPoint in listenOptions) + { + var connectionHandler = new ConnectionHandler(endPoint, serviceContext, application); + var transport = _transportFactory.Create(endPoint, connectionHandler); + _transports.Add(transport); + + try + { + await transport.BindAsync().ConfigureAwait(false); + } + catch (AddressInUseException ex) + { + throw new IOException($"Failed to bind to address {endPoint}: address already in use.", ex); + } + + // If requested port was "0", replace with assigned dynamic port. + _serverAddresses.Addresses.Add(endPoint.GetDisplayName()); + } + } + // Graceful shutdown if possible public async Task StopAsync(CancellationToken cancellationToken) { @@ -340,4 +356,4 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core return new IPEndPoint(ip, address.Port); } } -} +} \ No newline at end of file diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs index eb84fd3331..a09609ad2d 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs @@ -168,10 +168,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests var hostBuilder = new WebHostBuilder() .UseKestrel() - .ConfigureServices(services => - { - services.AddSingleton(new KestrelTestLoggerFactory(testLogger)); - }) + .UseLoggerFactory(_ => new KestrelTestLoggerFactory(testLogger)) .Configure(ConfigureEchoAddress); using (var host = hostBuilder.Build()) @@ -232,6 +229,73 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } } } + [ConditionalFact] + [PortSupportedCondition(5002)] + public async Task OverrideDirectConfigurationWithIServerAddressesFeature_Succeeds() + { + var overrideAddress = "http://localhost:5002"; + var testLogger = new TestApplicationErrorLogger(); + + var hostBuilder = new WebHostBuilder() + .UseKestrel(options => options.Listen(IPAddress.Loopback, 5001)) + .UseUrls(overrideAddress) + .PreferHostingUrls(true) + .UseLoggerFactory(_ => new KestrelTestLoggerFactory(testLogger)) + .Configure(ConfigureEchoAddress); + + using (var host = hostBuilder.Build()) + { + host.Start(); + + Assert.Equal(5002, host.GetPort()); + Assert.Single(testLogger.Messages, log => log.LogLevel == LogLevel.Information && + string.Equals($"Overriding endpoints defined in UseKestrel() since {nameof(IServerAddressesFeature.PreferHostingUrls)} is set to true. Binding to address(es) '{overrideAddress}' instead.", + log.Message, StringComparison.Ordinal)); + + Assert.Equal(new Uri(overrideAddress).ToString(), await HttpClientSlim.GetStringAsync(overrideAddress)); + } + } + + [ConditionalFact] + [PortSupportedCondition(5001)] + public async Task DoesNotOverrideDirectConfigurationWithIServerAddressesFeature_IfPreferHostingUrlsFalse() + { + var endPointAddress = "http://localhost:5001"; + + var hostBuilder = new WebHostBuilder() + .UseKestrel(options => options.Listen(IPAddress.Loopback, 5001)) + .UseUrls("http://localhost:5002") + .PreferHostingUrls(false) + .Configure(ConfigureEchoAddress); + + using (var host = hostBuilder.Build()) + { + host.Start(); + + Assert.Equal(5001, host.GetPort()); + Assert.Equal(new Uri(endPointAddress).ToString(), await HttpClientSlim.GetStringAsync(endPointAddress)); + } + } + + [ConditionalFact] + [PortSupportedCondition(5001)] + public async Task DoesNotOverrideDirectConfigurationWithIServerAddressesFeature_IfAddressesEmpty() + { + var endPointAddress = "http://localhost:5001"; + + var hostBuilder = new WebHostBuilder() + .UseKestrel(options => options.Listen(IPAddress.Loopback, 5001)) + .PreferHostingUrls(true) + .Configure(ConfigureEchoAddress); + + using (var host = hostBuilder.Build()) + { + host.Start(); + + Assert.Equal(5001, host.GetPort()); + Assert.Equal(new Uri(endPointAddress).ToString(), await HttpClientSlim.GetStringAsync(endPointAddress)); + } + } [Fact] public void ThrowsWhenBindingLocalhostToIPv4AddressInUse() From efa0a48fb1ff3401a7868ede31efdd1aca7ad28a Mon Sep 17 00:00:00 2001 From: Geoff Kizer Date: Thu, 13 Apr 2017 23:10:06 -0700 Subject: [PATCH 1210/1662] Add initial Socket transport for Kestrel (#1659) - This change adds the initial socket transport for Kestrel, all of the tests pass but there are still a couple of things that aren't done yet. - The functional tests support running both on both transports but tests aren't running for sockets right now. We need to parameterize these. - TimeoutServerTests hard code the libuv transport, this needs to support any transport. - There is no handling of connection stopping on application shutdown. This is being implemented in kestrel core so transports don't need to handle it. Sockets won't be the default transport until that is the case. - Performance needs to be looked at, today the SocketTransport doesn't dispatch by default and we're not buffering in kestrel.core, this can hurt as the number of kernel calls map 1:1 with application writes. --- KestrelHttpServer.sln | 15 ++ .../Internal/ConnectionHandler.cs | 12 +- .../IConnectionInformation.cs | 3 + .../Internal/LibuvConnectionContext.cs | 1 + ...re.Server.Kestrel.Transport.Sockets.csproj | 24 ++ .../SocketConnection.cs | 216 ++++++++++++++++++ .../SocketTransport.cs | 127 ++++++++++ .../SocketTransportFactory.cs | 44 ++++ .../WebHostBuilderSocketExtensions.cs | 29 +++ ...Microsoft.AspNetCore.Server.Kestrel.csproj | 1 + .../FrameTests.cs | 1 + .../PipeOptionsTests.cs | 4 +- .../TestServer.cs | 50 ++-- .../Mocks/MockConnectionInformation.cs | 1 + 14 files changed, 505 insertions(+), 23 deletions(-) create mode 100644 src/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.csproj create mode 100644 src/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets/SocketConnection.cs create mode 100644 src/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets/SocketTransport.cs create mode 100644 src/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets/SocketTransportFactory.cs create mode 100644 src/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets/WebHostBuilderSocketExtensions.cs diff --git a/KestrelHttpServer.sln b/KestrelHttpServer.sln index a2fc4e3108..2fba69b809 100644 --- a/KestrelHttpServer.sln +++ b/KestrelHttpServer.sln @@ -62,6 +62,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Server EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Server.Kestrel", "src\Microsoft.AspNetCore.Server.Kestrel\Microsoft.AspNetCore.Server.Kestrel.csproj", "{56139957-5C29-4E7D-89BD-7D20598B4EAF}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets", "src\Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets\Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.csproj", "{6950B18F-A3D2-41A4-AFEC-8B7C49517611}" +EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions", "src\Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions\Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.csproj", "{2E9CB89D-EC8F-4DD9-A72B-08D5BABF752D}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests", "test\Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests\Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests.csproj", "{D95A7EC3-48AC-4D03-B2E2-0DA3E13BD3A4}" @@ -198,6 +200,18 @@ Global {56139957-5C29-4E7D-89BD-7D20598B4EAF}.Release|x64.Build.0 = Release|Any CPU {56139957-5C29-4E7D-89BD-7D20598B4EAF}.Release|x86.ActiveCfg = Release|Any CPU {56139957-5C29-4E7D-89BD-7D20598B4EAF}.Release|x86.Build.0 = Release|Any CPU + {6950B18F-A3D2-41A4-AFEC-8B7C49517611}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {6950B18F-A3D2-41A4-AFEC-8B7C49517611}.Debug|Any CPU.Build.0 = Debug|Any CPU + {6950B18F-A3D2-41A4-AFEC-8B7C49517611}.Debug|x64.ActiveCfg = Debug|Any CPU + {6950B18F-A3D2-41A4-AFEC-8B7C49517611}.Debug|x64.Build.0 = Debug|Any CPU + {6950B18F-A3D2-41A4-AFEC-8B7C49517611}.Debug|x86.ActiveCfg = Debug|Any CPU + {6950B18F-A3D2-41A4-AFEC-8B7C49517611}.Debug|x86.Build.0 = Debug|Any CPU + {6950B18F-A3D2-41A4-AFEC-8B7C49517611}.Release|Any CPU.ActiveCfg = Release|Any CPU + {6950B18F-A3D2-41A4-AFEC-8B7C49517611}.Release|Any CPU.Build.0 = Release|Any CPU + {6950B18F-A3D2-41A4-AFEC-8B7C49517611}.Release|x64.ActiveCfg = Release|Any CPU + {6950B18F-A3D2-41A4-AFEC-8B7C49517611}.Release|x64.Build.0 = Release|Any CPU + {6950B18F-A3D2-41A4-AFEC-8B7C49517611}.Release|x86.ActiveCfg = Release|Any CPU + {6950B18F-A3D2-41A4-AFEC-8B7C49517611}.Release|x86.Build.0 = Release|Any CPU {2E9CB89D-EC8F-4DD9-A72B-08D5BABF752D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {2E9CB89D-EC8F-4DD9-A72B-08D5BABF752D}.Debug|Any CPU.Build.0 = Debug|Any CPU {2E9CB89D-EC8F-4DD9-A72B-08D5BABF752D}.Debug|x64.ActiveCfg = Debug|Any CPU @@ -251,6 +265,7 @@ Global {2822C132-BFFB-4D53-AC5B-E7E47DD81A6E} = {0EF2ACDF-012F-4472-A13A-4272419E2903} {A76B8C8C-0DC5-4DD3-9B1F-02E51A0915F4} = {2D5D5227-4DBD-499A-96B1-76A36B03B750} {56139957-5C29-4E7D-89BD-7D20598B4EAF} = {2D5D5227-4DBD-499A-96B1-76A36B03B750} + {6950B18F-A3D2-41A4-AFEC-8B7C49517611} = {2D5D5227-4DBD-499A-96B1-76A36B03B750} {2E9CB89D-EC8F-4DD9-A72B-08D5BABF752D} = {2D5D5227-4DBD-499A-96B1-76A36B03B750} {D95A7EC3-48AC-4D03-B2E2-0DA3E13BD3A4} = {D3273454-EA07-41D2-BF0B-FCC3675C2483} {4F1C30F8-CCAA-48D7-9DF6-2A84021F5BCC} = {D3273454-EA07-41D2-BF0B-FCC3675C2483} diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/ConnectionHandler.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/ConnectionHandler.cs index db9236d9d8..0ea0494d0e 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/ConnectionHandler.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/ConnectionHandler.cs @@ -27,8 +27,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal public IConnectionContext OnConnection(IConnectionInformation connectionInfo) { - var inputPipe = connectionInfo.PipeFactory.Create(GetInputPipeOptions(connectionInfo.InputWriterScheduler)); - var outputPipe = connectionInfo.PipeFactory.Create(GetOutputPipeOptions(connectionInfo.OutputReaderScheduler)); + var inputPipe = connectionInfo.PipeFactory.Create(GetInputPipeOptions(requiresDispatch: connectionInfo.RequiresDispatch, writerScheduler: connectionInfo.InputWriterScheduler)); + var outputPipe = connectionInfo.PipeFactory.Create(GetOutputPipeOptions(requiresDispatch: connectionInfo.RequiresDispatch, readerScheduler: connectionInfo.OutputReaderScheduler)); var connectionId = CorrelationIdGenerator.GetNextId(); var frameConnectionId = Interlocked.Increment(ref _lastFrameConnectionId); @@ -70,18 +70,18 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal } // Internal for testing - internal PipeOptions GetInputPipeOptions(IScheduler writerScheduler) => new PipeOptions + internal PipeOptions GetInputPipeOptions(bool requiresDispatch, IScheduler writerScheduler) => new PipeOptions { - ReaderScheduler = _serviceContext.ThreadPool, + ReaderScheduler = (requiresDispatch ? (IScheduler)_serviceContext.ThreadPool : (IScheduler)InlineScheduler.Default), WriterScheduler = writerScheduler, MaximumSizeHigh = _serviceContext.ServerOptions.Limits.MaxRequestBufferSize ?? 0, MaximumSizeLow = _serviceContext.ServerOptions.Limits.MaxRequestBufferSize ?? 0 }; - internal PipeOptions GetOutputPipeOptions(IScheduler readerScheduler) => new PipeOptions + internal PipeOptions GetOutputPipeOptions(bool requiresDispatch, IScheduler readerScheduler) => new PipeOptions { ReaderScheduler = readerScheduler, - WriterScheduler = _serviceContext.ThreadPool, + WriterScheduler = (requiresDispatch ? (IScheduler)_serviceContext.ThreadPool : (IScheduler)InlineScheduler.Default), MaximumSizeHigh = GetOutputResponseBufferSize(), MaximumSizeLow = GetOutputResponseBufferSize() }; diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/IConnectionInformation.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/IConnectionInformation.cs index a06bd16dd9..ca3cd9afbe 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/IConnectionInformation.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/IConnectionInformation.cs @@ -12,6 +12,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions IPEndPoint LocalEndPoint { get; } PipeFactory PipeFactory { get; } + + bool RequiresDispatch { get; } + IScheduler InputWriterScheduler { get; } IScheduler OutputReaderScheduler { get; } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvConnectionContext.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvConnectionContext.cs index 6c9d0cfcf5..b28739ed2e 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvConnectionContext.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvConnectionContext.cs @@ -24,6 +24,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal public IPEndPoint LocalEndPoint { get; set; } public PipeFactory PipeFactory => ListenerContext.Thread.PipeFactory; + public bool RequiresDispatch => true; public IScheduler InputWriterScheduler => ListenerContext.Thread; public IScheduler OutputReaderScheduler => ListenerContext.Thread; } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.csproj b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.csproj new file mode 100644 index 0000000000..911f42f7b2 --- /dev/null +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.csproj @@ -0,0 +1,24 @@ + + + + + + Managed socket transport for the ASP.NET Core Kestrel cross-platform web server. + netstandard1.3 + true + aspnetcore;kestrel + true + CS1591;$(NoWarn) + false + + + + + + + + + + + + diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets/SocketConnection.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets/SocketConnection.cs new file mode 100644 index 0000000000..922fb53186 --- /dev/null +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets/SocketConnection.cs @@ -0,0 +1,216 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using Microsoft.AspNetCore.Server.Kestrel.Internal.System.Buffers; +using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions; +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Net; +using System.Net.Sockets; +using System.Threading.Tasks; + +namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets +{ + internal sealed class SocketConnection : IConnectionInformation + { + private readonly Socket _socket; + private readonly SocketTransport _transport; + private readonly IPEndPoint _localEndPoint; + private readonly IPEndPoint _remoteEndPoint; + private IConnectionContext _connectionContext; + private IPipeWriter _input; + private IPipeReader _output; + private IList> _sendBufferList; + + private const int MinAllocBufferSize = 2048; // from libuv transport + + internal SocketConnection(Socket socket, SocketTransport transport) + { + Debug.Assert(socket != null); + Debug.Assert(transport != null); + + _socket = socket; + _transport = transport; + + _localEndPoint = (IPEndPoint)_socket.LocalEndPoint; + _remoteEndPoint = (IPEndPoint)_socket.RemoteEndPoint; + } + + public async void Start(IConnectionHandler connectionHandler) + { + _connectionContext = connectionHandler.OnConnection(this); + + _input = _connectionContext.Input; + _output = _connectionContext.Output; + + // Spawn send and receive logic + Task receiveTask = DoReceive(); + Task sendTask = DoSend(); + + // Wait for them to complete (note they won't throw exceptions) + await receiveTask; + await sendTask; + + _socket.Dispose(); + + _connectionContext.OnConnectionClosed(); + } + + private async Task DoReceive() + { + try + { + bool done = false; + while (!done) + { + // Ensure we have some reasonable amount of buffer space + WritableBuffer buffer = _input.Alloc(MinAllocBufferSize); + + int bytesReceived; + try + { + bytesReceived = await _socket.ReceiveAsync(GetArraySegment(buffer.Buffer), SocketFlags.None); + } + catch (Exception ex) + { + buffer.Commit(); + _connectionContext.Abort(ex); + _input.Complete(ex); + break; + } + + if (bytesReceived == 0) + { + // EOF + Exception ex = new TaskCanceledException(); + buffer.Commit(); + _connectionContext.Abort(ex); + _input.Complete(ex); + break; + } + + // record what data we filled into the buffer and push to pipe + buffer.Advance(bytesReceived); + var result = await buffer.FlushAsync(); + if (result.IsCompleted) + { + // Pipe consumer is shut down + _socket.Shutdown(SocketShutdown.Receive); + done = true; + } + } + } + catch (Exception) + { + // We don't expect any exceptions here, but eat it anyway as caller does not handle this. + Debug.Assert(false); + } + } + + private void SetupSendBuffers(ReadableBuffer buffer) + { + Debug.Assert(!buffer.IsEmpty); + Debug.Assert(!buffer.IsSingleSpan); + + if (_sendBufferList == null) + { + _sendBufferList = new List>(); + } + + // We should always clear the list after the send + Debug.Assert(_sendBufferList.Count == 0); + + foreach (var b in buffer) + { + _sendBufferList.Add(GetArraySegment(b)); + } + } + + private async Task DoSend() + { + try + { + bool done = false; + while (!done) + { + // Wait for data to write from the pipe producer + ReadResult result = await _output.ReadAsync(); + ReadableBuffer buffer = result.Buffer; + + try + { + if (!buffer.IsEmpty) + { + if (buffer.IsSingleSpan) + { + await _socket.SendAsync(GetArraySegment(buffer.First), SocketFlags.None); + } + else + { + SetupSendBuffers(buffer); + try + { + await _socket.SendAsync(_sendBufferList, SocketFlags.None); + } + finally + { + _sendBufferList.Clear(); + } + } + } + + if (result.IsCancelled) + { + // Send a FIN + _socket.Shutdown(SocketShutdown.Send); + break; + } + + if (buffer.IsEmpty && result.IsCompleted) + { + // Send a FIN + _socket.Shutdown(SocketShutdown.Send); + break; + } + } + finally + { + _output.Advance(buffer.End); + } + } + + // We're done reading + _output.Complete(); + } + catch (Exception ex) + { + _output.Complete(ex); + } + } + + private static ArraySegment GetArraySegment(Buffer buffer) + { + ArraySegment segment; + if (!buffer.TryGetArray(out segment)) + { + throw new InvalidOperationException(); + } + + return segment; + } + + public IPEndPoint RemoteEndPoint => _remoteEndPoint; + + public IPEndPoint LocalEndPoint => _localEndPoint; + + public PipeFactory PipeFactory => _transport.TransportFactory.PipeFactory; + + public bool RequiresDispatch => _transport.TransportFactory.ForceDispatch; + + public IScheduler InputWriterScheduler => InlineScheduler.Default; + + public IScheduler OutputReaderScheduler => InlineScheduler.Default; + } +} diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets/SocketTransport.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets/SocketTransport.cs new file mode 100644 index 0000000000..0a7aaa15ae --- /dev/null +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets/SocketTransport.cs @@ -0,0 +1,127 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions; +using System; +using System.Diagnostics; +using System.Net; +using System.Net.Sockets; +using System.Threading.Tasks; + +namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets +{ + internal sealed class SocketTransport : ITransport + { + private readonly SocketTransportFactory _transportFactory; + private readonly IEndPointInformation _endPointInformation; + private readonly IConnectionHandler _handler; + private Socket _listenSocket; + private Task _listenTask; + + internal SocketTransport(SocketTransportFactory transportFactory, IEndPointInformation endPointInformation, IConnectionHandler handler) + { + Debug.Assert(transportFactory != null); + Debug.Assert(endPointInformation != null); + Debug.Assert(endPointInformation.Type == ListenType.IPEndPoint); + Debug.Assert(handler != null); + + _transportFactory = transportFactory; + _endPointInformation = endPointInformation; + _handler = handler; + + _listenSocket = null; + _listenTask = null; + } + + public Task BindAsync() + { + if (_listenSocket != null) + { + throw new InvalidOperationException("Transport is already bound"); + } + + IPEndPoint endPoint = _endPointInformation.IPEndPoint; + + var listenSocket = new Socket(endPoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp); + + // Kestrel expects IPv6Any to bind to both IPv6 and IPv4 + if (endPoint.Address == IPAddress.IPv6Any) + { + listenSocket.DualMode = true; + } + + try + { + listenSocket.Bind(endPoint); + } + catch (SocketException e) when (e.SocketErrorCode == SocketError.AddressAlreadyInUse) + { + throw new AddressInUseException(e.Message, e); + } + + // If requested port was "0", replace with assigned dynamic port. + if (_endPointInformation.IPEndPoint.Port == 0) + { + _endPointInformation.IPEndPoint = (IPEndPoint)listenSocket.LocalEndPoint; + } + + listenSocket.Listen(512); + + _listenSocket = listenSocket; + + _listenTask = Task.Run(() => RunAcceptLoopAsync()); + + return Task.CompletedTask; + } + + public async Task UnbindAsync() + { + if (_listenSocket != null) + { + var listenSocket = _listenSocket; + _listenSocket = null; + + listenSocket.Dispose(); + + Debug.Assert(_listenTask != null); + await _listenTask; + _listenTask = null; + } + } + + public Task StopAsync() + { + return Task.CompletedTask; + } + + private async Task RunAcceptLoopAsync() + { + try + { + while (true) + { + Socket acceptSocket = await _listenSocket.AcceptAsync(); + + acceptSocket.NoDelay = _endPointInformation.NoDelay; + + SocketConnection connection = new SocketConnection(acceptSocket, this); + connection.Start(_handler); + } + } + catch (Exception) + { + if (_listenSocket == null) + { + // Means we must be unbinding. Eat the exception. + } + else + { + throw; + } + } + } + + internal SocketTransportFactory TransportFactory => _transportFactory; + } +} diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets/SocketTransportFactory.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets/SocketTransportFactory.cs new file mode 100644 index 0000000000..48f15ffc35 --- /dev/null +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets/SocketTransportFactory.cs @@ -0,0 +1,44 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions; +using System; + +namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets +{ + public sealed class SocketTransportFactory : ITransportFactory + { + private readonly PipeFactory _pipeFactory = new PipeFactory(); + private readonly bool _forceDispatch; + + public SocketTransportFactory(bool forceDispatch = false) + { + _forceDispatch = forceDispatch; + } + + public ITransport Create(IEndPointInformation endPointInformation, IConnectionHandler handler) + { + if (endPointInformation == null) + { + throw new ArgumentNullException(nameof(endPointInformation)); + } + + if (endPointInformation.Type != ListenType.IPEndPoint) + { + throw new ArgumentException("Only ListenType.IPEndPoint is supported", nameof(endPointInformation)); + } + + if (handler == null) + { + throw new ArgumentNullException(nameof(handler)); + } + + return new SocketTransport(this, endPointInformation, handler); + } + + internal PipeFactory PipeFactory => _pipeFactory; + + internal bool ForceDispatch => _forceDispatch; + } +} diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets/WebHostBuilderSocketExtensions.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets/WebHostBuilderSocketExtensions.cs new file mode 100644 index 0000000000..402a982c45 --- /dev/null +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets/WebHostBuilderSocketExtensions.cs @@ -0,0 +1,29 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets; +using Microsoft.Extensions.DependencyInjection; + +namespace Microsoft.AspNetCore.Hosting +{ + public static class WebHostBuilderSocketExtensions + { + /// + /// Specify Sockets as the transport to be used by Kestrel. + /// + /// + /// The Microsoft.AspNetCore.Hosting.IWebHostBuilder to configure. + /// + /// + /// The Microsoft.AspNetCore.Hosting.IWebHostBuilder. + /// + public static IWebHostBuilder UseSockets(this IWebHostBuilder hostBuilder) + { + return hostBuilder.ConfigureServices(services => + { + services.AddSingleton(); + }); + } + } +} diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Microsoft.AspNetCore.Server.Kestrel.csproj b/src/Microsoft.AspNetCore.Server.Kestrel/Microsoft.AspNetCore.Server.Kestrel.csproj index 91e491c4f9..8adf6b216c 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Microsoft.AspNetCore.Server.Kestrel.csproj +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Microsoft.AspNetCore.Server.Kestrel.csproj @@ -18,6 +18,7 @@ + diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameTests.cs index 33646df6ed..f2928ac9c2 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameTests.cs @@ -813,6 +813,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests public IPEndPoint RemoteEndPoint { get; } public IPEndPoint LocalEndPoint { get; } public PipeFactory PipeFactory { get; } + public bool RequiresDispatch { get; } public IScheduler InputWriterScheduler { get; } public IScheduler OutputReaderScheduler { get; } } diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/PipeOptionsTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/PipeOptionsTests.cs index 6183e278fe..b8fe2bb78b 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/PipeOptionsTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/PipeOptionsTests.cs @@ -24,7 +24,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests var connectionHandler = new ConnectionHandler(listenOptions: null, serviceContext: serviceContext, application: null); var mockScheduler = Mock.Of(); - var outputPipeOptions = connectionHandler.GetOutputPipeOptions(mockScheduler); + var outputPipeOptions = connectionHandler.GetOutputPipeOptions(requiresDispatch: true, readerScheduler: mockScheduler); Assert.Equal(expectedMaximumSizeLow, outputPipeOptions.MaximumSizeLow); Assert.Equal(expectedMaximumSizeHigh, outputPipeOptions.MaximumSizeHigh); @@ -43,7 +43,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests var connectionHandler = new ConnectionHandler(listenOptions: null, serviceContext: serviceContext, application: null); var mockScheduler = Mock.Of(); - var inputPipeOptions = connectionHandler.GetInputPipeOptions(mockScheduler); + var inputPipeOptions = connectionHandler.GetInputPipeOptions(requiresDispatch: true, writerScheduler: mockScheduler); Assert.Equal(expectedMaximumSizeLow, inputPipeOptions.MaximumSizeLow); Assert.Equal(expectedMaximumSizeHigh, inputPipeOptions.MaximumSizeHigh); diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/TestServer.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/TestServer.cs index 42bfa542ab..9a6681d7af 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/TestServer.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/TestServer.cs @@ -7,9 +7,11 @@ using System.Net.Sockets; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions; using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv; -using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets; using Microsoft.AspNetCore.Testing; +using Microsoft.Extensions.Options; namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { @@ -18,7 +20,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests /// public class TestServer : IDisposable { - private LibuvTransport _transport; + private ITransport _transport; private ListenOptions _listenOptions; public TestServer(RequestDelegate app) @@ -46,37 +48,55 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests _listenOptions = listenOptions; Context = context; - TransportContext = new LibuvTransportContext() - { - AppLifetime = new LifetimeNotImplemented(), - ConnectionHandler = new ConnectionHandler(listenOptions, Context, new DummyApplication(app, httpContextFactory)), - Log = new LibuvTrace(new TestApplicationErrorLogger()), - Options = new LibuvTransportOptions() - { - ThreadCount = 1, - ShutdownTimeout = TimeSpan.FromSeconds(5) - } - }; + + _transport = s_transportFactory.Create(listenOptions, new ConnectionHandler(listenOptions, context, new DummyApplication(app, httpContextFactory))); try { - _transport = new LibuvTransport(TransportContext, _listenOptions); _transport.BindAsync().Wait(); } catch { _transport.UnbindAsync().Wait(); _transport.StopAsync().Wait(); + _transport = null; throw; } } + // Switch this to test on socket transport + private static readonly ITransportFactory s_transportFactory = CreateLibuvTransportFactory(); +// private static readonly ITransportFactory s_transportFactory = CreateSocketTransportFactory(); + + private static ITransportFactory CreateLibuvTransportFactory() + { + var transportOptions = new LibuvTransportOptions() + { + ThreadCount = 1, + ShutdownTimeout = TimeSpan.FromSeconds(5) + }; + + var transportFactory = new LibuvTransportFactory( + Options.Create(transportOptions), + new LifetimeNotImplemented(), + new KestrelTestLoggerFactory(new TestApplicationErrorLogger())); + + return transportFactory; + } + + private static ITransportFactory CreateSocketTransportFactory() + { + // For now, force the socket transport to do threadpool dispatch for tests. + // There are a handful of tests that deadlock due to test issues if we don't do dispatch. + // We should clean these up, but for now, make them work by forcing dispatch. + return new SocketTransportFactory(true); + } + public IPEndPoint EndPoint => _listenOptions.IPEndPoint; public int Port => _listenOptions.IPEndPoint.Port; public AddressFamily AddressFamily => _listenOptions.IPEndPoint.AddressFamily; public TestServiceContext Context { get; } - public LibuvTransportContext TransportContext { get; } public TestConnection CreateConnection() { diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Mocks/MockConnectionInformation.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Mocks/MockConnectionInformation.cs index 7aa345898b..6928a6f70b 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Mocks/MockConnectionInformation.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Mocks/MockConnectionInformation.cs @@ -13,6 +13,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance public IPEndPoint LocalEndPoint { get; } public PipeFactory PipeFactory { get; } + public bool RequiresDispatch { get; } public IScheduler InputWriterScheduler { get; } public IScheduler OutputReaderScheduler { get; } } From aedd0618652ce430727b4fa37e52aecc2b2c38f2 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Fri, 14 Apr 2017 01:14:21 -0700 Subject: [PATCH 1211/1662] Tweaks to socket transport (#1687) - Style changes: Sort usings, use more var and C#7 - Added ConfigureAwait to stop dead locks with xunit - Remove duplicate handling of aborts in the receiver - Handle the case where output ends before input --- .../SocketConnection.cs | 96 +++++++++++-------- .../SocketTransport.cs | 9 +- .../SocketTransportFactory.cs | 2 +- 3 files changed, 60 insertions(+), 47 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets/SocketConnection.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets/SocketConnection.cs index 922fb53186..703fd9a35e 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets/SocketConnection.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets/SocketConnection.cs @@ -1,15 +1,15 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using Microsoft.AspNetCore.Server.Kestrel.Internal.System.Buffers; -using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; -using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions; using System; using System.Collections.Generic; using System.Diagnostics; using System.Net; using System.Net.Sockets; using System.Threading.Tasks; +using Microsoft.AspNetCore.Server.Kestrel.Internal.System.Buffers; +using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions; namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets { @@ -40,72 +40,89 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets public async void Start(IConnectionHandler connectionHandler) { - _connectionContext = connectionHandler.OnConnection(this); + try + { + _connectionContext = connectionHandler.OnConnection(this); - _input = _connectionContext.Input; - _output = _connectionContext.Output; + _input = _connectionContext.Input; + _output = _connectionContext.Output; - // Spawn send and receive logic - Task receiveTask = DoReceive(); - Task sendTask = DoSend(); + // Spawn send and receive logic + Task receiveTask = DoReceive(); + Task sendTask = DoSend(); - // Wait for them to complete (note they won't throw exceptions) - await receiveTask; - await sendTask; + // Wait for eiher of them to complete (note they won't throw exceptions) + await Task.WhenAny(receiveTask, sendTask); - _socket.Dispose(); + // Shut the socket down and wait for both sides to end + _socket.Shutdown(SocketShutdown.Both); - _connectionContext.OnConnectionClosed(); + // Now wait for both to complete + await receiveTask; + await sendTask; + + // Dispose the socket + _socket.Dispose(); + } + catch (Exception) + { + // TODO: Log + } + finally + { + // Mark the connection as closed after disposal + _connectionContext.OnConnectionClosed(); + } } - + private async Task DoReceive() { try { - bool done = false; - while (!done) + while (true) { // Ensure we have some reasonable amount of buffer space - WritableBuffer buffer = _input.Alloc(MinAllocBufferSize); + var buffer = _input.Alloc(MinAllocBufferSize); int bytesReceived; + try { bytesReceived = await _socket.ReceiveAsync(GetArraySegment(buffer.Buffer), SocketFlags.None); } - catch (Exception ex) + catch (Exception) { buffer.Commit(); - _connectionContext.Abort(ex); - _input.Complete(ex); - break; + throw; } if (bytesReceived == 0) { - // EOF - Exception ex = new TaskCanceledException(); buffer.Commit(); - _connectionContext.Abort(ex); - _input.Complete(ex); - break; + + // We receive a FIN so throw an exception so that we cancel the input + // with an error + throw new TaskCanceledException("The request was aborted"); } - // record what data we filled into the buffer and push to pipe + // Record what data we filled into the buffer and push to pipe buffer.Advance(bytesReceived); + var result = await buffer.FlushAsync(); if (result.IsCompleted) { - // Pipe consumer is shut down + // Pipe consumer is shut down, do we stop writing _socket.Shutdown(SocketShutdown.Receive); - done = true; + break; } } + + _input.Complete(); } - catch (Exception) + catch (Exception ex) { - // We don't expect any exceptions here, but eat it anyway as caller does not handle this. - Debug.Assert(false); + _connectionContext.Abort(ex); + _input.Complete(ex); } } @@ -132,12 +149,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets { try { - bool done = false; - while (!done) + while (true) { // Wait for data to write from the pipe producer - ReadResult result = await _output.ReadAsync(); - ReadableBuffer buffer = result.Buffer; + var result = await _output.ReadAsync(); + var buffer = result.Buffer; try { @@ -150,6 +166,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets else { SetupSendBuffers(buffer); + try { await _socket.SendAsync(_sendBufferList, SocketFlags.None); @@ -170,8 +187,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets if (buffer.IsEmpty && result.IsCompleted) { - // Send a FIN - _socket.Shutdown(SocketShutdown.Send); break; } } @@ -192,8 +207,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets private static ArraySegment GetArraySegment(Buffer buffer) { - ArraySegment segment; - if (!buffer.TryGetArray(out segment)) + if (!buffer.TryGetArray(out var segment)) { throw new InvalidOperationException(); } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets/SocketTransport.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets/SocketTransport.cs index 0a7aaa15ae..4832b5676a 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets/SocketTransport.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets/SocketTransport.cs @@ -1,13 +1,12 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; -using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions; using System; using System.Diagnostics; using System.Net; using System.Net.Sockets; using System.Threading.Tasks; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions; namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets { @@ -85,7 +84,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets listenSocket.Dispose(); Debug.Assert(_listenTask != null); - await _listenTask; + await _listenTask.ConfigureAwait(false); _listenTask = null; } } @@ -101,11 +100,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets { while (true) { - Socket acceptSocket = await _listenSocket.AcceptAsync(); + var acceptSocket = await _listenSocket.AcceptAsync(); acceptSocket.NoDelay = _endPointInformation.NoDelay; - SocketConnection connection = new SocketConnection(acceptSocket, this); + var connection = new SocketConnection(acceptSocket, this); connection.Start(_handler); } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets/SocketTransportFactory.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets/SocketTransportFactory.cs index 48f15ffc35..a31e4c45dc 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets/SocketTransportFactory.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets/SocketTransportFactory.cs @@ -1,9 +1,9 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions; -using System; namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets { From 9e37272f0646c9df25979cdc3a5c324a35682718 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Fri, 14 Apr 2017 01:39:56 -0700 Subject: [PATCH 1212/1662] Clean up the logic in DoReceive --- .../SocketConnection.cs | 28 ++++++++----------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets/SocketConnection.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets/SocketConnection.cs index 703fd9a35e..acb1915a01 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets/SocketConnection.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets/SocketConnection.cs @@ -84,30 +84,24 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets // Ensure we have some reasonable amount of buffer space var buffer = _input.Alloc(MinAllocBufferSize); - int bytesReceived; - try { - bytesReceived = await _socket.ReceiveAsync(GetArraySegment(buffer.Buffer), SocketFlags.None); + var bytesReceived = await _socket.ReceiveAsync(GetArraySegment(buffer.Buffer), SocketFlags.None); + + if (bytesReceived == 0) + { + // We receive a FIN so throw an exception so that we cancel the input + // with an error + throw new TaskCanceledException("The request was aborted"); + } + + buffer.Advance(bytesReceived); } - catch (Exception) + finally { buffer.Commit(); - throw; } - if (bytesReceived == 0) - { - buffer.Commit(); - - // We receive a FIN so throw an exception so that we cancel the input - // with an error - throw new TaskCanceledException("The request was aborted"); - } - - // Record what data we filled into the buffer and push to pipe - buffer.Advance(bytesReceived); - var result = await buffer.FlushAsync(); if (result.IsCompleted) { From c08c57f764333ea4c16dc33cf4731b968e2e03df Mon Sep 17 00:00:00 2001 From: Nate McMaster Date: Wed, 12 Apr 2017 12:05:22 -0700 Subject: [PATCH 1213/1662] Reject HTTP/1.1 requests that do not have a correct Host header Improves Kestrel to reject requests that don't conform to HTTP spec. RFC 7230 section 5.4: "A server MUST respond with a 400 (Bad Request) status code to any HTTP/1.1 request message that lacks a Host header field and to any request message that contains more than one Host header field or a Host header field with an invalid field-value." See https://tools.ietf.org/html/rfc7230#section-5.4. Other changes: - update VS code settings to work better with CLI 2.0 - update tests that were subject to infinite hangs --- .vscode/launch.json | 6 +- .vscode/tasks.json | 51 +++++-------- .../BadHttpRequestException.cs | 12 +++ .../Internal/Http/Frame.cs | 76 ++++++++++++++++++- .../Internal/Http/FrameOfT.cs | 2 + .../Internal/Http/RequestRejectionReason.cs | 3 + .../FrameTests.cs | 2 +- .../BadHttpRequestTests.cs | 33 +++++++- .../ChunkedRequestTests.cs | 19 +++++ .../ChunkedResponseTests.cs | 10 +++ .../DefaultHeaderTests.cs | 3 +- .../EventSourceTests.cs | 1 + .../HttpsTests.cs | 4 +- .../KeepAliveTimeoutTests.cs | 6 ++ .../MaxRequestBufferSizeTests.cs | 27 ++++--- .../MaxRequestLineSizeTests.cs | 24 +++--- ...Core.Server.Kestrel.FunctionalTests.csproj | 1 + .../RequestHeaderLimitsTests.cs | 10 ++- .../RequestHeadersTimeoutTests.cs | 9 ++- .../RequestTargetProcessingTests.cs | 7 ++ .../RequestTests.cs | 60 ++++++++++++--- .../ResponseTests.cs | 63 ++++++++++++++- .../TestServer.cs | 9 ++- ...erver.Kestrel.Transport.Libuv.Tests.csproj | 1 + test/shared/HttpParsingData.cs | 53 +++++++++++++ 25 files changed, 398 insertions(+), 94 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index e91f61ede0..f97435a509 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -12,8 +12,7 @@ "type": "coreclr", "request": "launch", "preLaunchTask": "Compile: solution", - "program": "${workspaceRoot}/samples/SampleApp/bin/Debug/netcoreapp1.1/SampleApp.dll", - "args": [], + "program": "${workspaceRoot}/samples/SampleApp/bin/Debug/netcoreapp2.0/SampleApp.dll", "cwd": "${workspaceRoot}/samples/SampleApp", "console": "internalConsole", "stopAtEntry": false, @@ -38,8 +37,7 @@ "type": "coreclr", "request": "launch", "preLaunchTask": "Compile: solution", - "program": "${workspaceRoot}/samples/LargeResponseApp/bin/Debug/netcoreapp1.1/LargeResponseApp.dll", - "args": [], + "program": "${workspaceRoot}/samples/LargeResponseApp/bin/Debug/netcoreapp2.0/LargeResponseApp.dll", "cwd": "${workspaceRoot}/samples/LargeResponseApp", "console": "internalConsole", "stopAtEntry": false, diff --git a/.vscode/tasks.json b/.vscode/tasks.json index b5ff23e775..db382e6056 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -5,10 +5,20 @@ "DOTNET_SKIP_FIRST_TIME_EXPERIENCE": "true" } }, + // requires that you first run build.cmd or build.sh to install local builds of dotnet + "windows": { + "command": "${env.LOCALAPPDATA}/Microsoft/dotnet/dotnet.exe" + }, + "osx": { + "command": "${env.HOME}/.dotnet/dotnet" + }, + "linux": { + "command": "${env.HOME}/.dotnet/dotnet" + }, + "suppressTaskName": true, "tasks": [ { "taskName": "Restore: solution", - "command": "dotnet", "args": [ "restore" ] @@ -16,7 +26,6 @@ { "taskName": "Compile: solution", "isBuildCommand": true, - "command": "dotnet", "args": [ "build", "${workspaceRoot}/KestrelHttpServer.sln" @@ -40,9 +49,16 @@ } } }, + { + "taskName": "Test", + "args": [ + "test" + ], + "problemMatcher": "$msCompile", + "isTestCommand": true + }, { "taskName": "Compile: CodeGenerator", - "command": "dotnet", "args": [ "build" ], @@ -53,7 +69,6 @@ }, { "taskName": "Run: CodeGenerator", - "command": "dotnet", "args": [ "run" ], @@ -63,7 +78,6 @@ }, { "taskName": "Run: Benchmarks", - "command": "dotnet", "args": [ "run", "-c", @@ -72,33 +86,6 @@ "options": { "cwd": "${workspaceRoot}/test/Microsoft.AspNetCore.Server.Kestrel.Performance/" } - }, - { - "taskName": "Test: KestrelTests", - "isTestCommand": true, - "command": "dotnet", - "args": [ - "test", - "-f", - "netcoreapp1.1" - ], - "options": { - "cwd": "${workspaceRoot}/test/Microsoft.AspNetCore.Server.KestrelTests" - }, - "problemMatcher": "$msCompile" - }, - { - "taskName": "Test: FunctionalTests", - "command": "dotnet", - "args": [ - "test", - "-f", - "netcoreapp1.1" - ], - "options": { - "cwd": "${workspaceRoot}/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests" - }, - "problemMatcher": "$msCompile" } ] } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/BadHttpRequestException.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/BadHttpRequestException.cs index 5a19ea4565..6bc10f460d 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/BadHttpRequestException.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/BadHttpRequestException.cs @@ -80,6 +80,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core case RequestRejectionReason.ConnectMethodRequired: ex = new BadHttpRequestException("Method not allowed.", StatusCodes.Status405MethodNotAllowed, HttpMethod.Connect); break; + case RequestRejectionReason.MissingHostHeader: + ex = new BadHttpRequestException("Request is missing Host header.", StatusCodes.Status400BadRequest); + break; + case RequestRejectionReason.MultipleHostHeaders: + ex = new BadHttpRequestException("Multiple Host headers.", StatusCodes.Status400BadRequest); + break; + case RequestRejectionReason.InvalidHostHeader: + ex = new BadHttpRequestException("Invalid Host header.", StatusCodes.Status400BadRequest); + break; default: ex = new BadHttpRequestException("Bad request.", StatusCodes.Status400BadRequest); break; @@ -116,6 +125,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core case RequestRejectionReason.LengthRequiredHttp10: ex = new BadHttpRequestException($"{detail} request contains no Content-Length header", StatusCodes.Status400BadRequest); break; + case RequestRejectionReason.InvalidHostHeader: + ex = new BadHttpRequestException($"Invalid Host header: '{detail}'", StatusCodes.Status400BadRequest); + break; default: ex = new BadHttpRequestException("Bad request.", StatusCodes.Status400BadRequest); break; diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.cs index 4d84a1c6d4..9dc9106e48 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.cs @@ -82,6 +82,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http private readonly FrameContext _frameContext; private readonly IHttpParser _parser; + private HttpRequestTarget _requestTargetForm = HttpRequestTarget.Unknown; + private Uri _absoluteRequestTarget; + public Frame(FrameContext frameContext) { _frameContext = frameContext; @@ -141,6 +144,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http public string Path { get; set; } public string QueryString { get; set; } public string RawTarget { get; set; } + public string HttpVersion { get @@ -365,6 +369,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http Method = null; PathBase = null; Path = null; + RawTarget = null; + _requestTargetForm = HttpRequestTarget.Unknown; + _absoluteRequestTarget = null; QueryString = null; _httpVersion = Http.HttpVersion.Unknown; StatusCode = StatusCodes.Status200OK; @@ -1266,6 +1273,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { Debug.Assert(target[0] == ByteForwardSlash, "Should only be called when path starts with /"); + _requestTargetForm = HttpRequestTarget.OriginForm; + // URIs are always encoded/escaped to ASCII https://tools.ietf.org/html/rfc3986#page-11 // Multibyte Internationalized Resource Identifiers (IRIs) are first converted to utf8; // then encoded/escaped to ASCII https://www.ietf.org/rfc/rfc3987.txt "Mapping of IRIs to URIs" @@ -1325,8 +1334,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http private void OnAuthorityFormTarget(HttpMethod method, Span target) { - // TODO Validate that target is a correct host[:port] string. - // Reject as 400 if not. This is just a quick scan for invalid characters + _requestTargetForm = HttpRequestTarget.AuthorityForm; + + // This is not complete validation. It is just a quick scan for invalid characters // but doesn't check that the target fully matches the URI spec. for (var i = 0; i < target.Length; i++) { @@ -1360,6 +1370,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http private void OnAsteriskFormTarget(HttpMethod method) { + _requestTargetForm = HttpRequestTarget.AsteriskForm; + // The asterisk-form of request-target is only used for a server-wide // OPTIONS request (https://tools.ietf.org/html/rfc7231#section-4.3.7). if (method != HttpMethod.Options) @@ -1374,6 +1386,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http private void OnAbsoluteFormTarget(Span target, Span query) { + _requestTargetForm = HttpRequestTarget.AbsoluteForm; + // absolute-form // https://tools.ietf.org/html/rfc7230#section-5.3.2 @@ -1394,6 +1408,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http RejectRequestTarget(target); } + _absoluteRequestTarget = uri; Path = uri.LocalPath; // don't use uri.Query because we need the unescaped version QueryString = query.GetAsciiStringNonNullCharacters(); @@ -1420,5 +1435,62 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http FrameRequestHeaders.Append(name, valueString); } + + protected void EnsureHostHeaderExists() + { + if (_httpVersion == Http.HttpVersion.Http10) + { + return; + } + + // https://tools.ietf.org/html/rfc7230#section-5.4 + // A server MUST respond with a 400 (Bad Request) status code to any + // HTTP/1.1 request message that lacks a Host header field and to any + // request message that contains more than one Host header field or a + // Host header field with an invalid field-value. + + var host = FrameRequestHeaders.HeaderHost; + if (host.Count <= 0) + { + RejectRequest(RequestRejectionReason.MissingHostHeader); + } + else if (host.Count > 1) + { + RejectRequest(RequestRejectionReason.MultipleHostHeaders); + } + else if (_requestTargetForm == HttpRequestTarget.AuthorityForm) + { + if (!host.Equals(RawTarget)) + { + RejectRequest(RequestRejectionReason.InvalidHostHeader, host.ToString()); + } + } + else if (_requestTargetForm == HttpRequestTarget.AbsoluteForm) + { + // If the target URI includes an authority component, then a + // client MUST send a field - value for Host that is identical to that + // authority component, excluding any userinfo subcomponent and its "@" + // delimiter. + + // System.Uri doesn't not tell us if the port was in the original string or not. + // When IsDefaultPort = true, we will allow Host: with or without the default port + var authorityAndPort = _absoluteRequestTarget.Authority + ":" + _absoluteRequestTarget.Port; + if ((host != _absoluteRequestTarget.Authority || !_absoluteRequestTarget.IsDefaultPort) + && host != authorityAndPort) + { + RejectRequest(RequestRejectionReason.InvalidHostHeader, host.ToString()); + } + } + } + + private enum HttpRequestTarget + { + Unknown = -1, + // origin-form is the most common + OriginForm, + AbsoluteForm, + AuthorityForm, + AsteriskForm + } } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameOfT.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameOfT.cs index 4073bc0837..b95a42c6a8 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameOfT.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameOfT.cs @@ -85,6 +85,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http if (!_requestProcessingStopping) { + EnsureHostHeaderExists(); + var messageBody = MessageBody.For(_httpVersion, FrameRequestHeaders, this); _keepAlive = messageBody.RequestKeepAlive; _upgrade = messageBody.RequestUpgrade; diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/RequestRejectionReason.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/RequestRejectionReason.cs index e6b70b7551..ea03aab6fa 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/RequestRejectionReason.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/RequestRejectionReason.cs @@ -27,5 +27,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http LengthRequiredHttp10, OptionsMethodRequired, ConnectMethodRequired, + MissingHostHeader, + MultipleHostHeaders, + InvalidHostHeader, } } diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameTests.cs index f2928ac9c2..8ace3c7338 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameTests.cs @@ -533,7 +533,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests { _frame.Start(); - var data = Encoding.ASCII.GetBytes("GET / HTTP/1.1\r\n\r\n"); + var data = Encoding.ASCII.GetBytes("GET / HTTP/1.1\r\nHost:\r\n\r\n"); await _input.Writer.WriteAsync(data); var requestProcessingTask = _frame.StopAsync(); diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/BadHttpRequestTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/BadHttpRequestTests.cs index 4c59212c6c..d97289edd8 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/BadHttpRequestTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/BadHttpRequestTests.cs @@ -67,7 +67,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests public Task BadRequestIfMethodRequiresLengthButNoContentLengthOrTransferEncodingInRequest(string method) { return TestBadRequest( - $"{method} / HTTP/1.1\r\n\r\n", + $"{method} / HTTP/1.1\r\nHost:\r\n\r\n", "411 Length Required", $"{method} request contains no Content-Length or Transfer-Encoding header"); } @@ -89,7 +89,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests public Task BadRequestIfContentLengthInvalid(string contentLength) { return TestBadRequest( - $"POST / HTTP/1.1\r\nContent-Length: {contentLength}\r\n\r\n", + $"POST / HTTP/1.1\r\nHost:\r\nContent-Length: {contentLength}\r\n\r\n", "400 Bad Request", $"Invalid content length: {contentLength}"); } @@ -106,6 +106,33 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests $"Allow: {allowedMethod}"); } + [Fact] + public Task BadRequestIfHostHeaderMissing() + { + return TestBadRequest( + "GET / HTTP/1.1\r\n\r\n", + "400 Bad Request", + "Request is missing Host header."); + } + + [Fact] + public Task BadRequestIfMultipleHostHeaders() + { + return TestBadRequest("GET / HTTP/1.1\r\nHost: localhost\r\nHost: localhost\r\n\r\n", + "400 Bad Request", + "Multiple Host headers."); + } + + [Theory] + [MemberData(nameof(InvalidHostHeaderData))] + public Task BadRequestIfHostHeaderDoesNotMatchRequestTarget(string requestTarget, string host) + { + return TestBadRequest( + $"{requestTarget} HTTP/1.1\r\nHost: {host}\r\n\r\n", + "400 Bad Request", + $"Invalid Host header: '{host.Trim()}'"); + } + [Fact] public async Task BadRequestLogsAreNotHigherThanInformation() { @@ -211,5 +238,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests public static TheoryData UnrecognizedHttpVersionData => HttpParsingData.UnrecognizedHttpVersionData; public static IEnumerable InvalidRequestHeaderData => HttpParsingData.RequestHeaderInvalidData; + + public static TheoryData InvalidHostHeaderData => HttpParsingData.HostHeaderInvalidData; } } diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ChunkedRequestTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ChunkedRequestTests.cs index be1718d76a..c6e8adbdb2 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ChunkedRequestTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ChunkedRequestTests.cs @@ -66,6 +66,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { await connection.Send( "POST / HTTP/1.0", + "Host:", "Transfer-Encoding: chunked", "", "5", "Hello", @@ -95,6 +96,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { await connection.Send( "POST / HTTP/1.0", + "Host:", "Transfer-Encoding: chunked", "Connection: keep-alive", "", @@ -146,15 +148,18 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { await connection.Send( "POST / HTTP/1.1", + "Host:", "Content-Length: 5", "", "HelloPOST / HTTP/1.1", + "Host:", "Transfer-Encoding: chunked", "", "C", "HelloChunked", "0", "", "POST / HTTP/1.1", + "Host:", "Content-Length: 7", "", "Goodbye"); @@ -225,6 +230,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests IEnumerable sendSequence = new string[] { "POST / HTTP/1.1", + "Host:", "Transfer-Encoding: chunked", "", "C", @@ -236,6 +242,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { sendSequence = sendSequence.Concat(new string[] { "POST / HTTP/1.1", + "Host:", "Transfer-Encoding: chunked", "", "C", @@ -247,6 +254,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests sendSequence = sendSequence.Concat(new string[] { "POST / HTTP/1.1", + "Host:", "Content-Length: 7", "", "Goodbye" @@ -286,6 +294,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { await connection.SendAll( "POST / HTTP/1.1", + "Host:", $"{transferEncodingHeaderLine}", $"{headerLine}", "", @@ -327,6 +336,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { await connection.SendAll( "POST / HTTP/1.1", + "Host:", $"{transferEncodingHeaderLine}", $"{headerLine}", "", @@ -396,6 +406,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests IEnumerable sendSequence = new string[] { "POST / HTTP/1.1", + "Host:", "Transfer-Encoding: chunked", "", "C;hello there", @@ -407,6 +418,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { sendSequence = sendSequence.Concat(new string[] { "POST / HTTP/1.1", + "Host:", "Transfer-Encoding: chunked", "", "C;hello there", @@ -418,6 +430,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests sendSequence = sendSequence.Concat(new string[] { "POST / HTTP/1.1", + "Host:", "Content-Length: 7", "", "Goodbye" @@ -459,6 +472,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { await connection.SendAll( "POST / HTTP/1.1", + "Host:", "Transfer-Encoding: chunked", "", "Cii"); @@ -502,6 +516,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { await connection.SendAll( "POST / HTTP/1.1", + "Host:", "Transfer-Encoding: chunked", "", "C", @@ -535,6 +550,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { await connection.SendAll( "POST / HTTP/1.1", + "Host:", "Transfer-Encoding: not-chunked", "", "C", @@ -557,6 +573,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { await connection.SendAll( "POST / HTTP/1.1", + "Host:", "Transfer-Encoding: not-chunked", "Content-Length: 22", "", @@ -579,6 +596,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { await connection.SendAll( "POST / HTTP/1.1", + "Host:", "Transfer-Encoding: chunked, not-chunked", "", "C", @@ -601,6 +619,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { await connection.SendAll( "POST / HTTP/1.1", + "Host:", "Transfer-Encoding: chunked, not-chunked", "Content-Length: 22", "", diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ChunkedResponseTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ChunkedResponseTests.cs index d68283a1ab..dc953808ce 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ChunkedResponseTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ChunkedResponseTests.cs @@ -41,6 +41,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { await connection.Send( "GET / HTTP/1.1", + "Host:", "", ""); await connection.ReceiveEnd( @@ -104,6 +105,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { await connection.Send( "GET / HTTP/1.1", + "Host: ", "Connection: close", "", ""); @@ -141,6 +143,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { await connection.Send( "GET / HTTP/1.1", + "Host: ", "", ""); await connection.ReceiveEnd( @@ -178,6 +181,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { await connection.Send( "GET / HTTP/1.1", + "Host: ", "", ""); await connection.ReceiveEnd( @@ -218,6 +222,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { await connection.Send( "GET / HTTP/1.1", + "Host: ", "", ""); @@ -256,6 +261,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { await connection.Send( "GET / HTTP/1.1", + "Host: ", "", ""); await connection.ReceiveEnd( @@ -289,6 +295,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests // client closing the connection. await connection.Send( "GET / HTTP/1.1", + "Host: ", "", ""); await connection.ReceiveForcedEnd( @@ -321,6 +328,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests // SendEnd is not called, so it isn't the client closing the connection. await connection.Send( "GET / HTTP/1.1", + "Host: ", "", ""); @@ -358,6 +366,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { await connection.Send( "GET / HTTP/1.1", + "Host: ", "", ""); await connection.Receive( @@ -401,6 +410,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { await connection.Send( "GET / HTTP/1.1", + "Host: ", "", ""); await connection.ReceiveEnd( diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/DefaultHeaderTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/DefaultHeaderTests.cs index 91ff1816cf..c9c1a94ae6 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/DefaultHeaderTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/DefaultHeaderTests.cs @@ -24,6 +24,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { await connection.Send( "GET / HTTP/1.1", + "Host:", "", "GET / HTTP/1.0", "", @@ -46,4 +47,4 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } } } -} \ No newline at end of file +} diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/EventSourceTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/EventSourceTests.cs index f692537ea7..e2f40011a7 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/EventSourceTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/EventSourceTests.cs @@ -40,6 +40,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests using (var connection = server.CreateConnection()) { await connection.SendAll("GET / HTTP/1.1", + "Host:", "", "") .TimeoutAfter(TimeSpan.FromSeconds(10)); diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/HttpsTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/HttpsTests.cs index dc075abf9e..391441ed5b 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/HttpsTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/HttpsTests.cs @@ -137,7 +137,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests enabledSslProtocols: SslProtocols.Tls11 | SslProtocols.Tls12, checkCertificateRevocation: false); - var request = Encoding.ASCII.GetBytes("GET / HTTP/1.1\r\n\r\n"); + var request = Encoding.ASCII.GetBytes("GET / HTTP/1.1\r\nHost:\r\n\r\n"); await sslStream.WriteAsync(request, 0, request.Length); await sslStream.ReadAsync(new byte[32], 0, 32); } @@ -187,7 +187,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests enabledSslProtocols: SslProtocols.Tls11 | SslProtocols.Tls12, checkCertificateRevocation: false); - var request = Encoding.ASCII.GetBytes("GET / HTTP/1.1\r\n\r\n"); + var request = Encoding.ASCII.GetBytes("GET / HTTP/1.1\r\nHost:\r\n\r\n"); await sslStream.WriteAsync(request, 0, request.Length); await sslStream.ReadAsync(new byte[32], 0, 32); } diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/KeepAliveTimeoutTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/KeepAliveTimeoutTests.cs index 01b070dac6..64dd29e7cc 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/KeepAliveTimeoutTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/KeepAliveTimeoutTests.cs @@ -57,6 +57,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { await connection.Send( "GET / HTTP/1.1", + "Host:", "", ""); await ReceiveResponse(connection); @@ -72,6 +73,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { await connection.Send( "GET / HTTP/1.1", + "Host:", "", ""); await Task.Delay(ShortDelay); @@ -93,6 +95,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests await connection.Send( "POST / HTTP/1.1", + "Host:", "Transfer-Encoding: chunked", "", ""); @@ -120,6 +123,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { await connection.Send( "GET /longrunning HTTP/1.1", + "Host:", "", ""); cts.CancelAfter(LongDelay); @@ -133,6 +137,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests await connection.Send( "GET / HTTP/1.1", + "Host:", "", ""); await ReceiveResponse(connection); @@ -154,6 +159,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { await connection.Send( "GET /upgrade HTTP/1.1", + "Host:", "", ""); await connection.Receive( diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/MaxRequestBufferSizeTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/MaxRequestBufferSizeTests.cs index 6452832639..2b9c7dcd46 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/MaxRequestBufferSizeTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/MaxRequestBufferSizeTests.cs @@ -89,8 +89,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests // Initialize data with random bytes (new Random()).NextBytes(data); - var startReadingRequestBody = new ManualResetEvent(false); - var clientFinishedSendingRequestBody = new ManualResetEvent(false); + var startReadingRequestBody = new TaskCompletionSource(); + var clientFinishedSendingRequestBody = new TaskCompletionSource(); var lastBytesWritten = DateTime.MaxValue; using (var host = StartWebHost(maxRequestBufferSize, data, connectionAdapter, startReadingRequestBody, clientFinishedSendingRequestBody)) @@ -114,7 +114,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } Assert.Equal(data.Length, bytesWritten); - clientFinishedSendingRequestBody.Set(); + clientFinishedSendingRequestBody.TrySetResult(null); }; var sendTask = sendFunc(); @@ -149,7 +149,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests Assert.InRange(bytesWritten, minimumExpectedBytesWritten, maximumExpectedBytesWritten); // Tell server to start reading request body - startReadingRequestBody.Set(); + startReadingRequestBody.TrySetResult(null); // Wait for sendTask to finish sending the remaining bytes await sendTask; @@ -160,7 +160,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests await sendTask; // Tell server to start reading request body - startReadingRequestBody.Set(); + startReadingRequestBody.TrySetResult(null); } using (var reader = new StreamReader(stream, Encoding.ASCII)) @@ -181,8 +181,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests var bytesWrittenPollingInterval = TimeSpan.FromMilliseconds(bytesWrittenTimeout.TotalMilliseconds / 10); var maxSendSize = 4096; - var startReadingRequestBody = new ManualResetEvent(false); - var clientFinishedSendingRequestBody = new ManualResetEvent(false); + var startReadingRequestBody = new TaskCompletionSource(); + var clientFinishedSendingRequestBody = new TaskCompletionSource(); var lastBytesWritten = DateTime.MaxValue; using (var host = StartWebHost(16 * 1024, data, false, startReadingRequestBody, clientFinishedSendingRequestBody)) @@ -205,7 +205,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests lastBytesWritten = DateTime.Now; } - clientFinishedSendingRequestBody.Set(); + clientFinishedSendingRequestBody.TrySetResult(null); }; var ignore = sendFunc(); @@ -244,8 +244,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } } - private static IWebHost StartWebHost(long? maxRequestBufferSize, byte[] expectedBody, bool useConnectionAdapter, ManualResetEvent startReadingRequestBody, - ManualResetEvent clientFinishedSendingRequestBody) + private static IWebHost StartWebHost(long? maxRequestBufferSize, + byte[] expectedBody, + bool useConnectionAdapter, + TaskCompletionSource startReadingRequestBody, + TaskCompletionSource clientFinishedSendingRequestBody) { var host = new WebHostBuilder() .UseKestrel(options => @@ -275,7 +278,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests .UseContentRoot(Directory.GetCurrentDirectory()) .Configure(app => app.Run(async context => { - startReadingRequestBody.WaitOne(); + await startReadingRequestBody.Task.TimeoutAfter(TimeSpan.FromSeconds(30)); var buffer = new byte[expectedBody.Length]; var bytesRead = 0; @@ -284,7 +287,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests bytesRead += await context.Request.Body.ReadAsync(buffer, bytesRead, buffer.Length - bytesRead); } - clientFinishedSendingRequestBody.WaitOne(); + await clientFinishedSendingRequestBody.Task.TimeoutAfter(TimeSpan.FromSeconds(30)); // Verify client didn't send extra bytes if (context.Request.Body.ReadByte() != -1) diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/MaxRequestLineSizeTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/MaxRequestLineSizeTests.cs index 8e3dd5d22e..0ac7785d11 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/MaxRequestLineSizeTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/MaxRequestLineSizeTests.cs @@ -12,18 +12,18 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests public class MaxRequestLineSizeTests { [Theory] - [InlineData("GET / HTTP/1.1\r\n\r\n", 16)] - [InlineData("GET / HTTP/1.1\r\n\r\n", 17)] - [InlineData("GET / HTTP/1.1\r\n\r\n", 137)] - [InlineData("POST /abc/de HTTP/1.1\r\nContent-Length: 0\r\n\r\n", 23)] - [InlineData("POST /abc/de HTTP/1.1\r\nContent-Length: 0\r\n\r\n", 24)] - [InlineData("POST /abc/de HTTP/1.1\r\nContent-Length: 0\r\n\r\n", 287)] - [InlineData("PUT /abc/de?f=ghi HTTP/1.1\r\nContent-Length: 0\r\n\r\n", 28)] - [InlineData("PUT /abc/de?f=ghi HTTP/1.1\r\nContent-Length: 0\r\n\r\n", 29)] - [InlineData("PUT /abc/de?f=ghi HTTP/1.1\r\nContent-Length: 0\r\n\r\n", 589)] - [InlineData("DELETE /a%20b%20c/d%20e?f=ghi HTTP/1.1\r\n\r\n", 40)] - [InlineData("DELETE /a%20b%20c/d%20e?f=ghi HTTP/1.1\r\n\r\n", 41)] - [InlineData("DELETE /a%20b%20c/d%20e?f=ghi HTTP/1.1\r\n\r\n", 1027)] + [InlineData("GET / HTTP/1.1\r\nHost:\r\n\r\n", 16)] + [InlineData("GET / HTTP/1.1\r\nHost:\r\n\r\n", 17)] + [InlineData("GET / HTTP/1.1\r\nHost:\r\n\r\n", 137)] + [InlineData("POST /abc/de HTTP/1.1\r\nHost:\r\nContent-Length: 0\r\n\r\n", 23)] + [InlineData("POST /abc/de HTTP/1.1\r\nHost:\r\nContent-Length: 0\r\n\r\n", 24)] + [InlineData("POST /abc/de HTTP/1.1\r\nHost:\r\nContent-Length: 0\r\n\r\n", 287)] + [InlineData("PUT /abc/de?f=ghi HTTP/1.1\r\nHost:\r\nContent-Length: 0\r\n\r\n", 28)] + [InlineData("PUT /abc/de?f=ghi HTTP/1.1\r\nHost:\r\nContent-Length: 0\r\n\r\n", 29)] + [InlineData("PUT /abc/de?f=ghi HTTP/1.1\r\nHost:\r\nContent-Length: 0\r\n\r\n", 589)] + [InlineData("DELETE /a%20b%20c/d%20e?f=ghi HTTP/1.1\r\nHost:\r\n\r\n", 40)] + [InlineData("DELETE /a%20b%20c/d%20e?f=ghi HTTP/1.1\r\nHost:\r\n\r\n", 41)] + [InlineData("DELETE /a%20b%20c/d%20e?f=ghi HTTP/1.1\r\nHost:\r\n\r\n", 1027)] public async Task ServerAcceptsRequestLineWithinLimit(string request, int limit) { using (var server = CreateServer(limit)) diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests.csproj b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests.csproj index 21a47f7c0d..cd10cab0df 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests.csproj +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests.csproj @@ -8,6 +8,7 @@ x64 true true + true + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + Cannot write to response body after connection has been upgraded. + + \ No newline at end of file diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.FeatureCollection.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.FeatureCollection.cs index 58180c0f69..bd1d8e2a56 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.FeatureCollection.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.FeatureCollection.cs @@ -244,7 +244,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http await FlushAsync(default(CancellationToken)); - return DuplexStream; + return _frameStreams.Upgrade(); } IEnumerator> IEnumerable>.GetEnumerator() => FastEnumerable().GetEnumerator(); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.cs index 5353364724..a63fec9407 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.cs @@ -241,8 +241,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http public IHeaderDictionary ResponseHeaders { get; set; } public Stream ResponseBody { get; set; } - public Stream DuplexStream { get; set; } - public CancellationToken RequestAborted { get @@ -323,31 +321,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http _frameStreams = new Streams(this); } - RequestBody = _frameStreams.RequestBody; - ResponseBody = _frameStreams.ResponseBody; - DuplexStream = _frameStreams.DuplexStream; - - _frameStreams.RequestBody.StartAcceptingReads(messageBody); - _frameStreams.ResponseBody.StartAcceptingWrites(); + (RequestBody, ResponseBody) = _frameStreams.Start(messageBody); } - public void PauseStreams() - { - _frameStreams.RequestBody.PauseAcceptingReads(); - _frameStreams.ResponseBody.PauseAcceptingWrites(); - } + public void PauseStreams() => _frameStreams.Pause(); - public void ResumeStreams() - { - _frameStreams.RequestBody.ResumeAcceptingReads(); - _frameStreams.ResponseBody.ResumeAcceptingWrites(); - } + public void ResumeStreams() => _frameStreams.Resume(); - public void StopStreams() - { - _frameStreams.RequestBody.StopAcceptingReads(); - _frameStreams.ResponseBody.StopAcceptingWrites(); - } + public void StopStreams() => _frameStreams.Stop(); public void Reset() { @@ -455,8 +436,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { _requestProcessingStopping = true; - _frameStreams?.RequestBody.Abort(error); - _frameStreams?.ResponseBody.Abort(); + _frameStreams?.Abort(error); LifetimeControl.End(ProduceEndType.SocketDisconnect); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameDuplexStream.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameDuplexStream.cs index b427651405..d1b7cab14d 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameDuplexStream.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameDuplexStream.cs @@ -10,7 +10,7 @@ using System.Threading.Tasks; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { - class FrameDuplexStream : Stream + internal class FrameDuplexStream : Stream { private readonly Stream _requestStream; private readonly Stream _responseStream; diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameRequestStream.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameRequestStream.cs index 93f0db1018..35bbf73302 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameRequestStream.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameRequestStream.cs @@ -5,11 +5,12 @@ using System; using System.IO; using System.Threading; using System.Threading.Tasks; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; using Microsoft.Extensions.Internal; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { - class FrameRequestStream : Stream + internal class FrameRequestStream : ReadOnlyStream { private MessageBody _body; private FrameStreamState _state; @@ -20,30 +21,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http _state = FrameStreamState.Closed; } - public override bool CanRead => true; - public override bool CanSeek => false; - public override bool CanWrite => false; - public override long Length - { - get - { - throw new NotSupportedException(); - } - } + => throw new NotSupportedException(); public override long Position { - get - { - throw new NotSupportedException(); - } - set - { - throw new NotSupportedException(); - } + get => throw new NotSupportedException(); + set => throw new NotSupportedException(); } public override void Flush() @@ -145,11 +131,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http return task; } - public override void Write(byte[] buffer, int offset, int count) - { - throw new NotSupportedException(); - } - public void StartAcceptingReads(MessageBody body) { // Only start if not aborted diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameResponseStream.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameResponseStream.cs index 699aa90f92..5f0931759b 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameResponseStream.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameResponseStream.cs @@ -5,10 +5,11 @@ using System; using System.IO; using System.Threading; using System.Threading.Tasks; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { - class FrameResponseStream : Stream + internal class FrameResponseStream : WriteOnlyStream { private IFrameControl _frameControl; private FrameStreamState _state; @@ -19,30 +20,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http _state = FrameStreamState.Closed; } - public override bool CanRead => false; - public override bool CanSeek => false; - public override bool CanWrite => true; - public override long Length - { - get - { - throw new NotSupportedException(); - } - } + => throw new NotSupportedException(); public override long Position { - get - { - throw new NotSupportedException(); - } - set - { - throw new NotSupportedException(); - } + get => throw new NotSupportedException(); + set => throw new NotSupportedException(); } public override void Flush() @@ -72,11 +58,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http throw new NotSupportedException(); } - public override int Read(byte[] buffer, int offset, int count) - { - throw new NotSupportedException(); - } - public override void Write(byte[] buffer, int offset, int count) { ValidateState(default(CancellationToken)); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/MessageBody.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/MessageBody.cs index 97fff771fa..ca26fe9095 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/MessageBody.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/MessageBody.cs @@ -24,6 +24,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http _context = context; } + public static MessageBody ZeroContentLengthClose => _zeroContentLengthClose; + public bool RequestKeepAlive { get; protected set; } public bool RequestUpgrade { get; protected set; } @@ -237,15 +239,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http var keepAlive = httpVersion != HttpVersion.Http10; var connection = headers.HeaderConnection; + var upgrade = false; if (connection.Count > 0) { var connectionOptions = FrameHeaders.ParseConnection(connection); - if ((connectionOptions & ConnectionOptions.Upgrade) == ConnectionOptions.Upgrade) - { - return new ForRemainingData(true, context); - } - + upgrade = (connectionOptions & ConnectionOptions.Upgrade) == ConnectionOptions.Upgrade; keepAlive = (connectionOptions & ConnectionOptions.KeepAlive) == ConnectionOptions.KeepAlive; } @@ -265,16 +264,26 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http context.RejectRequest(RequestRejectionReason.FinalTransferCodingNotChunked, transferEncoding.ToString()); } + if (upgrade) + { + context.RejectRequest(RequestRejectionReason.UpgradeRequestCannotHavePayload); + } + return new ForChunkedEncoding(keepAlive, headers, context); } if (headers.ContentLength.HasValue) { var contentLength = headers.ContentLength.Value; + if (contentLength == 0) { return keepAlive ? _zeroContentLengthKeepAlive : _zeroContentLengthClose; } + else if (upgrade) + { + context.RejectRequest(RequestRejectionReason.UpgradeRequestCannotHavePayload); + } return new ForContentLength(keepAlive, contentLength, context); } @@ -291,15 +300,20 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http } } + if (upgrade) + { + return new ForUpgrade(context); + } + return keepAlive ? _zeroContentLengthKeepAlive : _zeroContentLengthClose; } - private class ForRemainingData : MessageBody + private class ForUpgrade : MessageBody { - public ForRemainingData(bool upgrade, Frame context) + public ForUpgrade(Frame context) : base(context) { - RequestUpgrade = upgrade; + RequestUpgrade = true; } protected override ValueTask> PeekAsync(CancellationToken cancellationToken) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/RequestRejectionReason.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/RequestRejectionReason.cs index ea03aab6fa..730badcff8 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/RequestRejectionReason.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/RequestRejectionReason.cs @@ -30,5 +30,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http MissingHostHeader, MultipleHostHeaders, InvalidHostHeader, + UpgradeRequestCannotHavePayload, } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/ReadOnlyStream.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/ReadOnlyStream.cs new file mode 100644 index 0000000000..cf4b02a41f --- /dev/null +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/ReadOnlyStream.cs @@ -0,0 +1,29 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.IO; +using System.Threading; +using System.Threading.Tasks; + +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure +{ + public abstract class ReadOnlyStream : Stream + { + public override bool CanRead => true; + + public override bool CanWrite => false; + + public override int WriteTimeout + { + get => throw new NotSupportedException(); + set => throw new NotSupportedException(); + } + + public override void Write(byte[] buffer, int offset, int count) + => throw new NotSupportedException(); + + public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) + => throw new NotSupportedException(); + } +} diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/Streams.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/Streams.cs index 61654b3e56..c81f9c3985 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/Streams.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/Streams.cs @@ -1,21 +1,84 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; +using System.IO; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure { - class Streams + internal class Streams { + private static readonly ThrowingWriteOnlyStream _throwingResponseStream + = new ThrowingWriteOnlyStream(new InvalidOperationException(CoreStrings.ResponseStreamWasUpgraded)); + private readonly FrameResponseStream _response; + private readonly FrameRequestStream _request; + private readonly WrappingStream _upgradeableResponse; + private readonly FrameRequestStream _emptyRequest; + private readonly Stream _upgradeStream; + public Streams(IFrameControl frameControl) { - RequestBody = new FrameRequestStream(); - ResponseBody = new FrameResponseStream(frameControl); - DuplexStream = new FrameDuplexStream(RequestBody, ResponseBody); + _request = new FrameRequestStream(); + _emptyRequest = new FrameRequestStream(); + _response = new FrameResponseStream(frameControl); + _upgradeableResponse = new WrappingStream(_response); + _upgradeStream = new FrameDuplexStream(_request, _response); } - public FrameRequestStream RequestBody { get; } - public FrameResponseStream ResponseBody { get; } - public FrameDuplexStream DuplexStream { get; } + public Stream Upgrade() + { + // causes writes to context.Response.Body to throw + _upgradeableResponse.SetInnerStream(_throwingResponseStream); + // _upgradeStream always uses _response + return _upgradeStream; + } + + public (Stream request, Stream response) Start(MessageBody body) + { + _request.StartAcceptingReads(body); + _emptyRequest.StartAcceptingReads(MessageBody.ZeroContentLengthClose); + _response.StartAcceptingWrites(); + + if (body.RequestUpgrade) + { + // until Upgrade() is called, context.Response.Body should use the normal output stream + _upgradeableResponse.SetInnerStream(_response); + // upgradeable requests should never have a request body + return (_emptyRequest, _upgradeableResponse); + } + else + { + return (_request, _response); + } + } + + public void Pause() + { + _request.PauseAcceptingReads(); + _emptyRequest.PauseAcceptingReads(); + _response.PauseAcceptingWrites(); + } + + public void Resume() + { + _request.ResumeAcceptingReads(); + _emptyRequest.ResumeAcceptingReads(); + _response.ResumeAcceptingWrites(); + } + + public void Stop() + { + _request.StopAcceptingReads(); + _emptyRequest.StopAcceptingReads(); + _response.StopAcceptingWrites(); + } + + public void Abort(Exception error) + { + _request.Abort(error); + _emptyRequest.Abort(error); + _response.Abort(); + } } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/ThrowingWriteOnlyStream.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/ThrowingWriteOnlyStream.cs new file mode 100644 index 0000000000..aff2b7a6d4 --- /dev/null +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/ThrowingWriteOnlyStream.cs @@ -0,0 +1,45 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.IO; +using System.Threading; +using System.Threading.Tasks; + +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure +{ + public class ThrowingWriteOnlyStream : WriteOnlyStream + { + private readonly Exception _exception; + + public ThrowingWriteOnlyStream(Exception exception) + { + _exception = exception; + } + + public override bool CanSeek => false; + + public override long Length => throw new NotSupportedException(); + + public override long Position + { + get => throw new NotSupportedException(); + set => throw new NotSupportedException(); + } + + public override void Write(byte[] buffer, int offset, int count) + => throw _exception; + + public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) + => throw _exception; + + public override void Flush() + => throw _exception; + + public override long Seek(long offset, SeekOrigin origin) + => throw new NotSupportedException(); + + public override void SetLength(long value) + => throw new NotSupportedException(); + } +} diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/WrappingStream.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/WrappingStream.cs new file mode 100644 index 0000000000..64fbd85526 --- /dev/null +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/WrappingStream.cs @@ -0,0 +1,140 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.IO; +#if NET46 +using System.Runtime.Remoting; +#endif +using System.Threading; +using System.Threading.Tasks; + +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure +{ + internal class WrappingStream : Stream + { + private Stream _inner; + private bool _disposed; + + public WrappingStream(Stream inner) + { + _inner = inner; + } + + public void SetInnerStream(Stream inner) + { + if (_disposed) + { + throw new ObjectDisposedException(nameof(WrappingStream)); + } + + _inner = inner; + } + + public override bool CanRead => _inner.CanRead; + + public override bool CanSeek => _inner.CanSeek; + + public override bool CanWrite => _inner.CanWrite; + + public override bool CanTimeout => _inner.CanTimeout; + + public override long Length => _inner.Length; + + public override long Position + { + get => _inner.Position; + set => _inner.Position = value; + } + + public override int ReadTimeout + { + get => _inner.ReadTimeout; + set => _inner.ReadTimeout = value; + } + + public override int WriteTimeout + { + get => _inner.WriteTimeout; + set => _inner.WriteTimeout = value; + } + + public override void Flush() + => _inner.Flush(); + + public override Task FlushAsync(CancellationToken cancellationToken) + => _inner.FlushAsync(cancellationToken); + + public override int Read(byte[] buffer, int offset, int count) + => _inner.Read(buffer, offset, count); + + public override Task ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) + => _inner.ReadAsync(buffer, offset, count, cancellationToken); + + public override int ReadByte() + => _inner.ReadByte(); + + public override long Seek(long offset, SeekOrigin origin) + => _inner.Seek(offset, origin); + + public override void SetLength(long value) + => _inner.SetLength(value); + + public override void Write(byte[] buffer, int offset, int count) + => _inner.Write(buffer, offset, count); + + public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) + => _inner.WriteAsync(buffer, offset, count, cancellationToken); + + public override void WriteByte(byte value) + => _inner.WriteByte(value); + + public override Task CopyToAsync(Stream destination, int bufferSize, CancellationToken cancellationToken) + => _inner.CopyToAsync(destination, bufferSize, cancellationToken); + +#if NET46 + public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback callback, object state) + => _inner.BeginRead(buffer, offset, count, callback, state); + + public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback callback, object state) + => _inner.BeginWrite(buffer, offset, count, callback, state); + + public override int EndRead(IAsyncResult asyncResult) + => _inner.EndRead(asyncResult); + + public override void EndWrite(IAsyncResult asyncResult) + => _inner.EndWrite(asyncResult); + + public override ObjRef CreateObjRef(Type requestedType) + => _inner.CreateObjRef(requestedType); + + public override object InitializeLifetimeService() + => _inner.InitializeLifetimeService(); + + public override void Close() + => _inner.Close(); + +#elif NETSTANDARD1_3 +#else +#error Target framework should be updated +#endif + + public override bool Equals(object obj) + => _inner.Equals(obj); + + public override int GetHashCode() + => _inner.GetHashCode(); + + public override string ToString() + => _inner.ToString(); + + protected override void Dispose(bool disposing) + { + if (disposing) + { + _disposed = true; + _inner.Dispose(); + } + } + } +} diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/WriteOnlyStream.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/WriteOnlyStream.cs new file mode 100644 index 0000000000..c7042e2bb0 --- /dev/null +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/WriteOnlyStream.cs @@ -0,0 +1,29 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.IO; +using System.Threading; +using System.Threading.Tasks; + +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure +{ + public abstract class WriteOnlyStream : Stream + { + public override bool CanRead => false; + + public override bool CanWrite => true; + + public override int ReadTimeout + { + get => throw new NotSupportedException(); + set => throw new NotSupportedException(); + } + + public override int Read(byte[] buffer, int offset, int count) + => throw new NotSupportedException(); + + public override Task ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) + => throw new NotSupportedException(); + } +} diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Microsoft.AspNetCore.Server.Kestrel.Core.csproj b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Microsoft.AspNetCore.Server.Kestrel.Core.csproj index 20102b9aba..3e9d1e703d 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Microsoft.AspNetCore.Server.Kestrel.Core.csproj +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Microsoft.AspNetCore.Server.Kestrel.Core.csproj @@ -20,6 +20,7 @@ + @@ -33,4 +34,10 @@ + + + + + + diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Properties/CoreStrings.Designer.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Properties/CoreStrings.Designer.cs new file mode 100644 index 0000000000..0deecaa6d1 --- /dev/null +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Properties/CoreStrings.Designer.cs @@ -0,0 +1,44 @@ +// +namespace Microsoft.AspNetCore.Server.Kestrel.Core +{ + using System.Globalization; + using System.Reflection; + using System.Resources; + + internal static class CoreStrings + { + private static readonly ResourceManager _resourceManager + = new ResourceManager("Microsoft.AspNetCore.Server.Kestrel.Core.CoreStrings", typeof(CoreStrings).GetTypeInfo().Assembly); + + /// + /// Cannot write to response body after connection has been upgraded. + /// + internal static string ResponseStreamWasUpgraded + { + get => GetString("ResponseStreamWasUpgraded"); + } + + /// + /// Cannot write to response body after connection has been upgraded. + /// + internal static string FormatResponseStreamWasUpgraded() + => GetString("ResponseStreamWasUpgraded"); + + private static string GetString(string name, params string[] formatterNames) + { + var value = _resourceManager.GetString(name); + + System.Diagnostics.Debug.Assert(value != null); + + if (formatterNames != null) + { + for (var i = 0; i < formatterNames.Length; i++) + { + value = value.Replace("{" + formatterNames[i] + "}", "{" + i + "}"); + } + } + + return value; + } + } +} diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameRequestStreamTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameRequestStreamTests.cs index 9f723aa903..8adad18cca 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameRequestStreamTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameRequestStreamTests.cs @@ -3,6 +3,7 @@ using System; using System.IO; +using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; using Moq; diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameTests.cs index b6471a0228..d050e7f43d 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameTests.cs @@ -256,10 +256,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests var originalRequestBody = _frame.RequestBody; var originalResponseBody = _frame.ResponseBody; - var originalDuplexStream = _frame.DuplexStream; _frame.RequestBody = new MemoryStream(); _frame.ResponseBody = new MemoryStream(); - _frame.DuplexStream = new MemoryStream(); // Act _frame.InitializeStreams(messageBody); @@ -267,7 +265,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests // Assert Assert.Same(originalRequestBody, _frame.RequestBody); Assert.Same(originalResponseBody, _frame.ResponseBody); - Assert.Same(originalDuplexStream, _frame.DuplexStream); } [Theory] diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/StreamsTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/StreamsTests.cs new file mode 100644 index 0000000000..d9f8854a14 --- /dev/null +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/StreamsTests.cs @@ -0,0 +1,89 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Threading; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; +using Moq; +using Xunit; + +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests +{ + public class StreamsTests + { + [Fact] + public async Task StreamsThrowAfterAbort() + { + var streams = new Streams(Mock.Of()); + var (request, response) = streams.Start(new MockMessageBody()); + + var ex = new Exception("My error"); + streams.Abort(ex); + + await response.WriteAsync(new byte[1], 0, 1); + Assert.Same(ex, + await Assert.ThrowsAsync(() => request.ReadAsync(new byte[1], 0, 1))); + } + + [Fact] + public async Task StreamsThrowOnAbortAfterUpgrade() + { + var streams = new Streams(Mock.Of()); + var (request, response) = streams.Start(new MockMessageBody(upgradeable: true)); + + var upgrade = streams.Upgrade(); + var ex = new Exception("My error"); + streams.Abort(ex); + + var writeEx = await Assert.ThrowsAsync(() => response.WriteAsync(new byte[1], 0, 1)); + Assert.Equal(CoreStrings.ResponseStreamWasUpgraded, writeEx.Message); + + Assert.Same(ex, + await Assert.ThrowsAsync(() => request.ReadAsync(new byte[1], 0, 1))); + + Assert.Same(ex, + await Assert.ThrowsAsync(() => upgrade.ReadAsync(new byte[1], 0, 1))); + + await upgrade.WriteAsync(new byte[1], 0, 1); + } + + [Fact] + public async Task StreamsThrowOnUpgradeAfterAbort() + { + var streams = new Streams(Mock.Of()); + + var (request, response) = streams.Start(new MockMessageBody(upgradeable: true)); + var ex = new Exception("My error"); + streams.Abort(ex); + + var upgrade = streams.Upgrade(); + + var writeEx = await Assert.ThrowsAsync(() => response.WriteAsync(new byte[1], 0, 1)); + Assert.Equal(CoreStrings.ResponseStreamWasUpgraded, writeEx.Message); + + Assert.Same(ex, + await Assert.ThrowsAsync(() => request.ReadAsync(new byte[1], 0, 1))); + + Assert.Same(ex, + await Assert.ThrowsAsync(() => upgrade.ReadAsync(new byte[1], 0, 1))); + + await upgrade.WriteAsync(new byte[1], 0, 1); + } + + private class MockMessageBody : MessageBody + { + public MockMessageBody(bool upgradeable = false) + : base(null) + { + RequestUpgrade = upgradeable; + } + + protected override ValueTask> PeekAsync(CancellationToken cancellationToken) + { + return new ValueTask>(new ArraySegment(new byte[1])); + } + } + } +} diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/ThrowingWriteOnlyStreamTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/ThrowingWriteOnlyStreamTests.cs new file mode 100644 index 0000000000..7e6490e4f3 --- /dev/null +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/ThrowingWriteOnlyStreamTests.cs @@ -0,0 +1,29 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; +using Xunit; + +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests +{ + public class ThrowingWriteOnlyStreamTests + { + [Fact] + public async Task ThrowsOnWrite() + { + var ex = new Exception("my error"); + var stream = new ThrowingWriteOnlyStream(ex); + + Assert.True(stream.CanWrite); + Assert.False(stream.CanRead); + Assert.False(stream.CanSeek); + Assert.False(stream.CanTimeout); + Assert.Same(ex, Assert.Throws(() => stream.Write(new byte[1], 0, 1))); + Assert.Same(ex, await Assert.ThrowsAsync(() => stream.WriteAsync(new byte[1], 0, 1))); + Assert.Same(ex, Assert.Throws(() => stream.Flush())); + Assert.Same(ex, await Assert.ThrowsAsync(() => stream.FlushAsync())); + } + } +} diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/UpgradeTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/UpgradeTests.cs new file mode 100644 index 0000000000..d56ecf4d00 --- /dev/null +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/UpgradeTests.cs @@ -0,0 +1,174 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.IO; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Http.Features; +using Microsoft.AspNetCore.Server.Kestrel.Core; +using Microsoft.AspNetCore.Testing; +using Microsoft.Extensions.Internal; +using Xunit; + +namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests +{ + public class UpgradeTests + { + [Fact] + public async Task ResponseThrowsAfterUpgrade() + { + var upgrade = new TaskCompletionSource(); + using (var server = new TestServer(async context => + { + var feature = context.Features.Get(); + var stream = await feature.UpgradeAsync(); + + var ex = Assert.Throws(() => context.Response.Body.WriteByte((byte)' ')); + Assert.Equal(CoreStrings.ResponseStreamWasUpgraded, ex.Message); + + using (var writer = new StreamWriter(stream)) + { + writer.WriteLine("New protocol data"); + } + + upgrade.TrySetResult(true); + })) + { + using (var connection = server.CreateConnection()) + { + await connection.Send("GET / HTTP/1.1", + "Host:", + "Connection: Upgrade", + "", + ""); + await connection.Receive("HTTP/1.1 101 Switching Protocols", + "Connection: Upgrade", + $"Date: {server.Context.DateHeaderValue}", + "", + ""); + + await connection.Receive("New protocol data"); + await upgrade.Task.TimeoutAfter(TimeSpan.FromSeconds(30)); + } + } + } + + [Fact] + public async Task RequestBodyAlwaysEmptyAfterUpgrade() + { + const string send = "Custom protocol send"; + const string recv = "Custom protocol recv"; + + var upgrade = new TaskCompletionSource(); + using (var server = new TestServer(async context => + { + try + { + var feature = context.Features.Get(); + var stream = await feature.UpgradeAsync(); + + var buffer = new byte[128]; + var read = await context.Request.Body.ReadAsync(buffer, 0, 128).TimeoutAfter(TimeSpan.FromSeconds(10)); + Assert.Equal(0, read); + + using (var reader = new StreamReader(stream)) + using (var writer = new StreamWriter(stream)) + { + var line = await reader.ReadLineAsync(); + Assert.Equal(send, line); + await writer.WriteLineAsync(recv); + } + + upgrade.TrySetResult(true); + } + catch (Exception ex) + { + upgrade.SetException(ex); + throw; + } + })) + { + using (var connection = server.CreateConnection()) + { + await connection.Send("GET / HTTP/1.1", + "Host:", + "Connection: Upgrade", + "", + ""); + + await connection.Receive("HTTP/1.1 101 Switching Protocols", + "Connection: Upgrade", + $"Date: {server.Context.DateHeaderValue}", + "", + ""); + + await connection.Send(send + "\r\n"); + await connection.Receive(recv); + + await upgrade.Task.TimeoutAfter(TimeSpan.FromSeconds(30)); + } + } + } + + [Fact] + public async Task RejectsRequestWithContentLengthAndUpgrade() + { + using (var server = new TestServer(context => TaskCache.CompletedTask)) + using (var connection = server.CreateConnection()) + { + await connection.Send("POST / HTTP/1.1", + "Host:", + "Content-Length: 1", + "Connection: Upgrade", + "", + "1"); + + await connection.Receive("HTTP/1.1 400 Bad Request"); + } + } + + [Fact] + public async Task AcceptsRequestWithNoContentLengthAndUpgrade() + { + using (var server = new TestServer(context => TaskCache.CompletedTask)) + { + using (var connection = server.CreateConnection()) + { + await connection.Send("POST / HTTP/1.1", + "Host:", + "Content-Length: 0", + "Connection: Upgrade, keep-alive", + "", + ""); + await connection.Receive("HTTP/1.1 200 OK"); + } + + using (var connection = server.CreateConnection()) + { + await connection.Send("GET / HTTP/1.1", + "Host:", + "Connection: Upgrade", + "", + ""); + await connection.Receive("HTTP/1.1 200 OK"); + } + } + } + + [Fact] + public async Task RejectsRequestWithChunkedEncodingAndUpgrade() + { + using (var server = new TestServer(context => TaskCache.CompletedTask)) + using (var connection = server.CreateConnection()) + { + await connection.Send("POST / HTTP/1.1", + "Host:", + "Transfer-Encoding: chunked", + "Connection: Upgrade", + "", + ""); + await connection.Receive("HTTP/1.1 400 Bad Request"); + } + } + } +} From a14eabce9a1e7638a503ef18e738afc329ff7920 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Thu, 20 Apr 2017 16:33:05 -0700 Subject: [PATCH 1235/1662] RequestTests and ResponseTests cleanup (#1723) --- .../RequestTests.cs | 44 +++++++++++-------- .../ResponseTests.cs | 4 +- 2 files changed, 28 insertions(+), 20 deletions(-) diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs index 6b9d901880..11c494c242 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs @@ -21,7 +21,6 @@ using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking; using Microsoft.AspNetCore.Testing; using Microsoft.AspNetCore.Testing.xunit; -using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Internal; using Microsoft.Extensions.Logging; using Moq; @@ -144,7 +143,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { var builder = new WebHostBuilder() .UseKestrel() - .UseUrls($"http://127.0.0.1:0") + .UseUrls("http://127.0.0.1:0") .Configure(app => { app.Run(async context => @@ -174,7 +173,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests var builder = new WebHostBuilder() .UseKestrel() - .UseUrls($"http://127.0.0.1:0") + .UseUrls("http://127.0.0.1:0") .Configure(app => { app.Run(async context => @@ -217,7 +216,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests var dataRead = false; var builder = new WebHostBuilder() .UseKestrel() - .UseUrls($"http://127.0.0.1:0") + .UseUrls("http://127.0.0.1:0") .Configure(app => { app.Run(async context => @@ -280,13 +279,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests .Setup(factory => factory.CreateLogger("Microsoft.AspNetCore.Server.Kestrel")) .Returns(mockLogger.Object); mockLoggerFactory - .Setup(factory => factory.CreateLogger(It.IsNotIn(new[] { "Microsoft.AspNetCore.Server.Kestrel" }))) + .Setup(factory => factory.CreateLogger("Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv")) + .Returns(mockLogger.Object); + mockLoggerFactory + .Setup(factory => factory.CreateLogger(It.IsNotIn("Microsoft.AspNetCore.Server.Kestrel", "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv"))) .Returns(Mock.Of()); var builder = new WebHostBuilder() .UseLoggerFactory(mockLoggerFactory.Object) .UseKestrel() - .UseUrls($"http://127.0.0.1:0") + .UseUrls("http://127.0.0.1:0") .Configure(app => app.Run(context => TaskCache.CompletedTask)); using (var host = builder.Build()) @@ -298,7 +300,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests socket.Connect(new IPEndPoint(IPAddress.Loopback, host.GetPort())); // Wait until connection is established - await connectionStarted.WaitAsync(TimeSpan.FromSeconds(10)); + Assert.True(await connectionStarted.WaitAsync(TimeSpan.FromSeconds(10))); // Force a reset socket.LingerState = new LingerOption(true, 0); @@ -308,7 +310,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests // This check MUST come before disposing the server, otherwise there's a race where the RST // is still in flight when the connection is aborted, leading to the reset never being received // and therefore not logged. - await connectionReset.WaitAsync(TimeSpan.FromSeconds(10)); + Assert.True(await connectionReset.WaitAsync(TimeSpan.FromSeconds(10))); } } @@ -340,14 +342,17 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests .Setup(factory => factory.CreateLogger("Microsoft.AspNetCore.Server.Kestrel")) .Returns(mockLogger.Object); mockLoggerFactory - .Setup(factory => factory.CreateLogger(It.IsNotIn(new[] { "Microsoft.AspNetCore.Server.Kestrel" }))) + .Setup(factory => factory.CreateLogger("Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv")) + .Returns(mockLogger.Object); + mockLoggerFactory + .Setup(factory => factory.CreateLogger(It.IsNotIn("Microsoft.AspNetCore.Server.Kestrel", "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv"))) .Returns(Mock.Of()); var builder = new WebHostBuilder() .UseLoggerFactory(mockLoggerFactory.Object) .UseKestrel() - .UseUrls($"http://127.0.0.1:0") + .UseUrls("http://127.0.0.1:0") .Configure(app => app.Run(context => TaskCache.CompletedTask)); using (var host = builder.Build()) @@ -360,7 +365,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests socket.Send(Encoding.ASCII.GetBytes("GET / HTTP/1.1\r\nHost:\r\n\r\n")); // Wait until request is done being processed - await requestDone.WaitAsync(TimeSpan.FromSeconds(10)); + Assert.True(await requestDone.WaitAsync(TimeSpan.FromSeconds(10))); // Force a reset socket.LingerState = new LingerOption(true, 0); @@ -370,7 +375,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests // This check MUST come before disposing the server, otherwise there's a race where the RST // is still in flight when the connection is aborted, leading to the reset never being received // and therefore not logged. - await connectionReset.WaitAsync(TimeSpan.FromSeconds(10)); + Assert.True(await connectionReset.WaitAsync(TimeSpan.FromSeconds(10))); } } @@ -395,7 +400,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests .Setup(factory => factory.CreateLogger("Microsoft.AspNetCore.Server.Kestrel")) .Returns(mockLogger.Object); mockLoggerFactory - .Setup(factory => factory.CreateLogger(It.IsNotIn(new[] { "Microsoft.AspNetCore.Server.Kestrel" }))) + .Setup(factory => factory.CreateLogger("Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv")) + .Returns(mockLogger.Object); + mockLoggerFactory + .Setup(factory => factory.CreateLogger(It.IsNotIn("Microsoft.AspNetCore.Server.Kestrel", "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv"))) .Returns(Mock.Of()); var requestStarted = new SemaphoreSlim(0); @@ -403,7 +411,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests var builder = new WebHostBuilder() .UseLoggerFactory(mockLoggerFactory.Object) .UseKestrel() - .UseUrls($"http://127.0.0.1:0") + .UseUrls("http://127.0.0.1:0") .Configure(app => app.Run(async context => { requestStarted.Release(); @@ -420,7 +428,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests socket.Send(Encoding.ASCII.GetBytes("GET / HTTP/1.1\r\nHost:\r\n\r\n")); // Wait until connection is established - await requestStarted.WaitAsync(TimeSpan.FromSeconds(10)); + Assert.True(await requestStarted.WaitAsync(TimeSpan.FromSeconds(10))); // Force a reset socket.LingerState = new LingerOption(true, 0); @@ -430,7 +438,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests // This check MUST come before disposing the server, otherwise there's a race where the RST // is still in flight when the connection is aborted, leading to the reset never being received // and therefore not logged. - await connectionReset.WaitAsync(TimeSpan.FromSeconds(10)); + Assert.True(await connectionReset.WaitAsync(TimeSpan.FromSeconds(10))); } } @@ -444,7 +452,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests var builder = new WebHostBuilder() .UseKestrel() - .UseUrls($"http://127.0.0.1:0") + .UseUrls("http://127.0.0.1:0") .Configure(app => app.Run(async context => { requestStarted.Release(); @@ -488,7 +496,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests var requestAborted = new SemaphoreSlim(0); var builder = new WebHostBuilder() .UseKestrel() - .UseUrls($"http://127.0.0.1:0") + .UseUrls("http://127.0.0.1:0") .Configure(app => app.Run(async context => { appStarted.Release(); diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs index 7437ad005f..33f4adec23 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs @@ -722,7 +722,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests await httpContext.Response.WriteAsync("hello,"); // Wait until the request is aborted so we know Frame will skip the response content length check. - await requestAborted.WaitAsync(TimeSpan.FromSeconds(10)); + Assert.True(await requestAborted.WaitAsync(TimeSpan.FromSeconds(10))); }, new TestServiceContext { Log = mockTrace.Object })) { using (var connection = server.CreateConnection()) @@ -746,7 +746,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests // Await before disposing the server to prevent races between the // abort triggered by the connection RST and the abort called when // disposing the server. - await requestAborted.WaitAsync(TimeSpan.FromSeconds(10)); + Assert.True(await requestAborted.WaitAsync(TimeSpan.FromSeconds(10))); } // With the server disposed we know all connections were drained and all messages were logged. From dcea15dba7cc524966189bd15b1e027a019032a0 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Fri, 21 Apr 2017 01:54:44 -0700 Subject: [PATCH 1236/1662] Skipped newly failing AddressRegistration tests failing tests on OSX and Linux (#1732) * Unblock CI --- .../AddressRegistrationTests.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs index f89a055115..21be87955c 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs @@ -28,7 +28,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { public class AddressRegistrationTests { - [Theory, MemberData(nameof(AddressRegistrationDataIPv4))] + [ConditionalTheory, MemberData(nameof(AddressRegistrationDataIPv4))] + [OSSkipCondition(OperatingSystems.MacOSX, SkipReason = "Causing test failures")] public async Task RegisterAddresses_IPv4_Success(string addressInput, Func testUrls) { await RegisterAddresses_Success(addressInput, testUrls); @@ -89,6 +90,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [ConditionalTheory, MemberData(nameof(AddressRegistrationDataIPv6ScopeId))] [IPv6SupportedCondition] [IPv6ScopeIdPresentCondition] + [OSSkipCondition(OperatingSystems.MacOSX, SkipReason = "Causing test failures")] + [OSSkipCondition(OperatingSystems.Linux, SkipReason = "Causing test failures")] public async Task RegisterAddresses_IPv6ScopeId_Success(string addressInput, Func testUrls) { await RegisterAddresses_Success(addressInput, testUrls); From feb9d1281ea88dbaebabd10c0974ee9029b3aa60 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Fri, 21 Apr 2017 13:12:37 -0700 Subject: [PATCH 1237/1662] Tweak libuv shutdown sequence (#1735) * Tweak libuv shutdown sequence - Increase timeouts for thread and listener shutdowns - Remove post.Unreference call from AllowStopRude --- .../Internal/LibuvThread.cs | 4 ---- .../LibuvTransport.cs | 4 ++-- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvThread.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvThread.cs index db70ba2c1a..e816d2630b 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvThread.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvThread.cs @@ -5,7 +5,6 @@ using System; using System.Collections.Generic; using System.Diagnostics; using System.Runtime.ExceptionServices; -using System.Runtime.InteropServices; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Hosting; @@ -165,9 +164,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal handle?.Dispose(); } }); - - // uv_unref is idempotent so it's OK to call this here and in AllowStop. - _post.Unreference(); } private void OnStopImmediate() diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/LibuvTransport.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/LibuvTransport.cs index bf23beeb0e..502c8bddfc 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/LibuvTransport.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/LibuvTransport.cs @@ -44,7 +44,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv { try { - await Task.WhenAll(Threads.Select(thread => thread.StopAsync(TimeSpan.FromSeconds(2.5))).ToArray()) + await Task.WhenAll(Threads.Select(thread => thread.StopAsync(TimeSpan.FromSeconds(5))).ToArray()) .ConfigureAwait(false); } catch (AggregateException aggEx) @@ -123,7 +123,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv { var disposeTasks = _listeners.Select(listener => listener.DisposeAsync()).ToArray(); - if (!await WaitAsync(Task.WhenAll(disposeTasks), TimeSpan.FromSeconds(2.5)).ConfigureAwait(false)) + if (!await WaitAsync(Task.WhenAll(disposeTasks), TimeSpan.FromSeconds(5)).ConfigureAwait(false)) { Log.LogError(0, null, "Disposing listeners failed"); } From a749939be4fc7a2bec620c35cdf816a844233870 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Fri, 21 Apr 2017 13:13:05 -0700 Subject: [PATCH 1238/1662] Clean up libuv connection (#1726) * Clean up libuv connection - Cancel all pending flushes on the input writer before disposing the stream handle. - Complete the pipe before disposing the socket - Added logging for connection pause/resume. - Added test --- .../Internal/ILibuvTrace.cs | 4 + .../Internal/LibuvConnection.cs | 60 +++--- .../Internal/LibuvTrace.cs | 16 ++ .../Internal/Listener.cs | 4 +- .../Internal/ListenerSecondary.cs | 12 +- .../ConnectionTests.cs | 177 +++++++++++++++--- .../TestHelpers/MockConnectionHandler.cs | 35 +--- .../TestHelpers/MockLibuv.cs | 7 +- 8 files changed, 222 insertions(+), 93 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/ILibuvTrace.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/ILibuvTrace.cs index 3d406cf99c..46512ba482 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/ILibuvTrace.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/ILibuvTrace.cs @@ -23,5 +23,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal void ConnectionError(string connectionId, Exception ex); void ConnectionReset(string connectionId); + + void ConnectionPause(string connectionId); + + void ConnectionResume(string connectionId); } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvConnection.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvConnection.cs index 718c655b89..3c266d04e1 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvConnection.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvConnection.cs @@ -4,11 +4,10 @@ using System; using System.Diagnostics; using System.IO; -using System.Threading; using System.Threading.Tasks; -using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking; using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking; using Microsoft.Extensions.Logging; namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal @@ -53,7 +52,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal private IConnectionHandler ConnectionHandler => ListenerContext.TransportContext.ConnectionHandler; private LibuvThread Thread => ListenerContext.Thread; - public async void Start() + public async Task Start() { try { @@ -64,7 +63,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal Output = new LibuvOutputConsumer(_connectionContext.Output, Thread, _socket, ConnectionId, Log); // Start socket prior to applying the ConnectionAdapter - _socket.ReadStart(_allocCallback, _readCallback, this); + StartReading(); try { @@ -80,9 +79,17 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal } finally { - // Ensure the socket is disposed prior to completing in the input writer. - _socket.Dispose(); + // Make sure it isn't possible for a paused read to resume reading after calling uv_close + // on the stream handle + Input.CancelPendingFlush(); + + // Now, complete the input so that no more reads can happen Input.Complete(new TaskCanceledException("The request was aborted")); + + // We're done with the socket now + _socket.Dispose(); + + // Tell the kestrel we're done with this connection _connectionContext.OnConnectionClosed(); } } @@ -171,12 +178,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal _currentWritableBuffer = null; if (flushTask?.IsCompleted == false) { - Pause(); + Log.ConnectionPause(ConnectionId); + StopReading(); + var result = await flushTask.Value; // If the reader isn't complete then resume - if (!result.IsCompleted) + if (!result.IsCompleted && !result.IsCancelled) { - Resume(); + Log.ConnectionResume(ConnectionId); + StartReading(); } } @@ -189,31 +199,23 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal } } - private void Pause() + private void StopReading() { - // It's possible that uv_close was called between the call to Thread.Post() and now. - if (!_socket.IsClosed) - { - _socket.ReadStop(); - } + _socket.ReadStop(); } - private void Resume() + private void StartReading() { - // It's possible that uv_close was called even before the call to Resume(). - if (!_socket.IsClosed) + try { - try - { - _socket.ReadStart(_allocCallback, _readCallback, this); - } - catch (UvException) - { - // ReadStart() can throw a UvException in some cases (e.g. socket is no longer connected). - // This should be treated the same as OnRead() seeing a "normalDone" condition. - Log.ConnectionReadFin(ConnectionId); - Input.Complete(); - } + _socket.ReadStart(_allocCallback, _readCallback, this); + } + catch (UvException) + { + // ReadStart() can throw a UvException in some cases (e.g. socket is no longer connected). + // This should be treated the same as OnRead() seeing a "normalDone" condition. + Log.ConnectionReadFin(ConnectionId); + Input.Complete(); } } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvTrace.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvTrace.cs index 8b3668312c..7e938211fb 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvTrace.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvTrace.cs @@ -10,6 +10,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal { // ConnectionRead: Reserved: 3 + private static readonly Action _connectionPause = + LoggerMessage.Define(LogLevel.Debug, 4, @"Connection id ""{ConnectionId}"" paused."); + + private static readonly Action _connectionResume = + LoggerMessage.Define(LogLevel.Debug, 5, @"Connection id ""{ConnectionId}"" resumed."); + private static readonly Action _connectionReadFin = LoggerMessage.Define(LogLevel.Debug, 6, @"Connection id ""{ConnectionId}"" received FIN."); @@ -79,6 +85,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal _connectionReset(_logger, connectionId, null); } + public void ConnectionPause(string connectionId) + { + _connectionPause(_logger, connectionId, null); + } + + public void ConnectionResume(string connectionId) + { + _connectionResume(_logger, connectionId, null); + } + public IDisposable BeginScope(TState state) => _logger.BeginScope(state); public bool IsEnabled(LogLevel logLevel) => _logger.IsEnabled(logLevel); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Listener.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Listener.cs index d9d1cf1798..c1c562c574 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Listener.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Listener.cs @@ -95,7 +95,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal private static void ConnectionCallback(UvStreamHandle stream, int status, Exception error, object state) { - var listener = (Listener) state; + var listener = (Listener)state; if (error != null) { @@ -132,7 +132,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal protected virtual void DispatchConnection(UvStreamHandle socket) { var connection = new LibuvConnection(this, socket); - connection.Start(); + _ = connection.Start(); } public virtual async Task DisposeAsync() diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/ListenerSecondary.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/ListenerSecondary.cs index 0d45492472..4b43c9cf79 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/ListenerSecondary.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/ListenerSecondary.cs @@ -102,11 +102,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal (handle, status2, state) => ((ListenerSecondary)state).ReadStartCallback(handle, status2), this); - writeReq.Init(Thread); - var result = await writeReq.WriteAsync( - DispatchPipe, - new ArraySegment>(new [] { new ArraySegment(_pipeMessage) })); - + writeReq.Init(Thread); + var result = await writeReq.WriteAsync( + DispatchPipe, + new ArraySegment>(new[] { new ArraySegment(_pipeMessage) })); + if (result.Error != null) { tcs.SetException(result.Error); @@ -163,7 +163,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal try { var connection = new LibuvConnection(this, acceptSocket); - connection.Start(); + _ = connection.Start(); } catch (UvException ex) { diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/ConnectionTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/ConnectionTests.cs index d9110cba1e..2ce0000554 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/ConnectionTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/ConnectionTests.cs @@ -4,9 +4,12 @@ using System; using System.Threading; using System.Threading.Tasks; +using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal; using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking; using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests.TestHelpers; +using Microsoft.AspNetCore.Testing; +using Moq; using Xunit; namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests @@ -16,38 +19,160 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests [Fact] public async Task DoesNotEndConnectionOnZeroRead() { - using (var mockConnectionHandler = new MockConnectionHandler()) + var mockConnectionHandler = new MockConnectionHandler(); + var mockLibuv = new MockLibuv(); + var transportContext = new TestLibuvTransportContext() { ConnectionHandler = mockConnectionHandler }; + var transport = new LibuvTransport(mockLibuv, transportContext, null); + var thread = new LibuvThread(transport); + + try { - var mockLibuv = new MockLibuv(); - var transportContext = new TestLibuvTransportContext() { ConnectionHandler = mockConnectionHandler }; - var transport = new LibuvTransport(mockLibuv, transportContext, null); - var thread = new LibuvThread(transport); - - try + await thread.StartAsync(); + await thread.PostAsync(_ => { - await thread.StartAsync(); - await thread.PostAsync(_ => + var listenerContext = new ListenerContext(transportContext) { - var listenerContext = new ListenerContext(transportContext) - { - Thread = thread - }; - var socket = new MockSocket(mockLibuv, Thread.CurrentThread.ManagedThreadId, transportContext.Log); - var connection = new LibuvConnection(listenerContext, socket); - connection.Start(); + Thread = thread + }; + var socket = new MockSocket(mockLibuv, Thread.CurrentThread.ManagedThreadId, transportContext.Log); + var connection = new LibuvConnection(listenerContext, socket); + _ = connection.Start(); - LibuvFunctions.uv_buf_t ignored; - mockLibuv.AllocCallback(socket.InternalGetHandle(), 2048, out ignored); - mockLibuv.ReadCallback(socket.InternalGetHandle(), 0, ref ignored); - }, (object)null); + mockLibuv.AllocCallback(socket.InternalGetHandle(), 2048, out var ignored); + mockLibuv.ReadCallback(socket.InternalGetHandle(), 0, ref ignored); + }, (object)null); - var readAwaitable = await mockConnectionHandler.Input.Reader.ReadAsync(); - Assert.False(readAwaitable.IsCompleted); - } - finally + var readAwaitable = await mockConnectionHandler.Input.Reader.ReadAsync(); + Assert.False(readAwaitable.IsCompleted); + } + finally + { + await thread.StopAsync(TimeSpan.FromSeconds(1)); + } + } + + [Fact] + public async Task ConnectionDoesNotResumeAfterSocketCloseIfBackpressureIsApplied() + { + var mockConnectionHandler = new MockConnectionHandler(); + mockConnectionHandler.InputOptions.MaximumSizeHigh = 3; + var mockLibuv = new MockLibuv(); + var transportContext = new TestLibuvTransportContext() { ConnectionHandler = mockConnectionHandler }; + var transport = new LibuvTransport(mockLibuv, transportContext, null); + var thread = new LibuvThread(transport); + // We don't set the output writer scheduler here since we want to run the callback inline + mockConnectionHandler.OutputOptions.ReaderScheduler = thread; + Task connectionTask = null; + try + { + await thread.StartAsync(); + + // Write enough to make sure back pressure will be applied + await thread.PostAsync(_ => { - await thread.StopAsync(TimeSpan.FromSeconds(1)); - } + var listenerContext = new ListenerContext(transportContext) + { + Thread = thread + }; + var socket = new MockSocket(mockLibuv, Thread.CurrentThread.ManagedThreadId, transportContext.Log); + var connection = new LibuvConnection(listenerContext, socket); + connectionTask = connection.Start(); + + mockLibuv.AllocCallback(socket.InternalGetHandle(), 2048, out var ignored); + mockLibuv.ReadCallback(socket.InternalGetHandle(), 5, ref ignored); + + }, null); + + // Now assert that we removed the callback from libuv to stop reading + Assert.Null(mockLibuv.AllocCallback); + Assert.Null(mockLibuv.ReadCallback); + + // Now complete the output writer so that the connection closes + mockConnectionHandler.Output.Writer.Complete(); + + await connectionTask.TimeoutAfter(TimeSpan.FromSeconds(10)); + + // Assert that we don't try to start reading + Assert.Null(mockLibuv.AllocCallback); + Assert.Null(mockLibuv.ReadCallback); + } + finally + { + await thread.StopAsync(TimeSpan.FromSeconds(1)); + } + } + + [Fact] + public async Task ConnectionDoesNotResumeAfterReadCallbackScheduledAndSocketCloseIfBackpressureIsApplied() + { + var mockConnectionHandler = new MockConnectionHandler(); + mockConnectionHandler.InputOptions.MaximumSizeHigh = 3; + mockConnectionHandler.InputOptions.MaximumSizeLow = 3; + var mockLibuv = new MockLibuv(); + var transportContext = new TestLibuvTransportContext() { ConnectionHandler = mockConnectionHandler }; + var transport = new LibuvTransport(mockLibuv, transportContext, null); + var thread = new LibuvThread(transport); + var mockScheduler = new Mock(); + Action backPressure = null; + mockScheduler.Setup(m => m.Schedule(It.IsAny())).Callback(a => + { + backPressure = a; + }); + mockConnectionHandler.InputOptions.WriterScheduler = mockScheduler.Object; + mockConnectionHandler.OutputOptions.ReaderScheduler = thread; + Task connectionTask = null; + try + { + await thread.StartAsync(); + + // Write enough to make sure back pressure will be applied + await thread.PostAsync(_ => + { + var listenerContext = new ListenerContext(transportContext) + { + Thread = thread + }; + var socket = new MockSocket(mockLibuv, Thread.CurrentThread.ManagedThreadId, transportContext.Log); + var connection = new LibuvConnection(listenerContext, socket); + connectionTask = connection.Start(); + + mockLibuv.AllocCallback(socket.InternalGetHandle(), 2048, out var ignored); + mockLibuv.ReadCallback(socket.InternalGetHandle(), 5, ref ignored); + + }, null); + + // Now assert that we removed the callback from libuv to stop reading + Assert.Null(mockLibuv.AllocCallback); + Assert.Null(mockLibuv.ReadCallback); + + // Now release backpressure by reading the input + var result = await mockConnectionHandler.Input.Reader.ReadAsync(); + // Calling advance will call into our custom scheduler that captures the back pressure + // callback + mockConnectionHandler.Input.Reader.Advance(result.Buffer.End); + + // Cancel the current pending flush + mockConnectionHandler.Input.Writer.CancelPendingFlush(); + + // Now release the back pressure + await thread.PostAsync(a => a(), backPressure); + + // Assert that we don't try to start reading since the write was cancelled + Assert.Null(mockLibuv.AllocCallback); + Assert.Null(mockLibuv.ReadCallback); + + // Now complete the output writer and wait for the connection to close + mockConnectionHandler.Output.Writer.Complete(); + + await connectionTask.TimeoutAfter(TimeSpan.FromSeconds(10)); + + // Assert that we don't try to start reading + Assert.Null(mockLibuv.AllocCallback); + Assert.Null(mockLibuv.ReadCallback); + } + finally + { + await thread.StopAsync(TimeSpan.FromSeconds(1)); } } } diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/TestHelpers/MockConnectionHandler.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/TestHelpers/MockConnectionHandler.cs index 44bda00009..0ec0a04f12 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/TestHelpers/MockConnectionHandler.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/TestHelpers/MockConnectionHandler.cs @@ -9,21 +9,15 @@ using Xunit; namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests.TestHelpers { - public class MockConnectionHandler : IConnectionHandler, IDisposable + public class MockConnectionHandler : IConnectionHandler { - private readonly PipeFactory _pipeFactory; - - public MockConnectionHandler() - { - _pipeFactory = new PipeFactory(); - } + public PipeOptions InputOptions { get; set; } = new PipeOptions(); + public PipeOptions OutputOptions { get; set; } = new PipeOptions(); public IConnectionContext OnConnection(IConnectionInformation connectionInfo) { - Assert.Null(Input); - - Input = _pipeFactory.Create(); - Output = _pipeFactory.Create(); + Input = connectionInfo.PipeFactory.Create(InputOptions ?? new PipeOptions()); + Output = connectionInfo.PipeFactory.Create(OutputOptions ?? new PipeOptions()); return new TestConnectionContext { @@ -34,13 +28,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests.TestHelpers public IPipe Input { get; private set; } public IPipe Output { get; private set; } - - public void Dispose() - { - Input?.Writer.Complete(); - _pipeFactory.Dispose(); - } - + private class TestConnectionContext : IConnectionContext { public string ConnectionId { get; } @@ -49,22 +37,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests.TestHelpers public void OnConnectionClosed() { - throw new NotImplementedException(); - } - public Task StopAsync() - { - throw new NotImplementedException(); } public void Abort(Exception ex) { - throw new NotImplementedException(); - } - - public void Timeout() - { - throw new NotImplementedException(); } } } diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/TestHelpers/MockLibuv.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/TestHelpers/MockLibuv.cs index e18e2e8572..8906dbd872 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/TestHelpers/MockLibuv.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/TestHelpers/MockLibuv.cs @@ -120,7 +120,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests.TestHelpers _uv_err_name = errno => IntPtr.Zero; _uv_strerror = errno => IntPtr.Zero; _uv_read_start = UvReadStart; - _uv_read_stop = handle => 0; + _uv_read_stop = (handle) => + { + AllocCallback = null; + ReadCallback = null; + return 0; + }; _uv_unsafe_async_send = handle => { throw new Exception($"Why is this getting called?{Environment.NewLine}{_stackTrace}"); From 650a3ccc26983f692a26d69f397f36454eb1b4b7 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Fri, 21 Apr 2017 23:31:59 -0700 Subject: [PATCH 1239/1662] Pass exception to Complete (#1739) --- .../Internal/LibuvConnection.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvConnection.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvConnection.cs index 3c266d04e1..8637baf1ee 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvConnection.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvConnection.cs @@ -210,12 +210,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal { _socket.ReadStart(_allocCallback, _readCallback, this); } - catch (UvException) + catch (UvException ex) { // ReadStart() can throw a UvException in some cases (e.g. socket is no longer connected). // This should be treated the same as OnRead() seeing a "normalDone" condition. Log.ConnectionReadFin(ConnectionId); - Input.Complete(); + Input.Complete(new IOException(ex.Message, ex)); } } } From db44f5b672d4d21a1e471e9ca8f1247e36ba9a15 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Sun, 23 Apr 2017 20:22:49 -0700 Subject: [PATCH 1240/1662] Clean up LibuvOutputConsumer (#1744) * Clean up LibuvOutputConsumer - Added UvShutdownReq.ShutdownAsync - Added Debug.Assert in LibuvAwaitable since it should never race. --- .../Internal/LibuvAwaitable.cs | 10 +++- .../Internal/LibuvOutputConsumer.cs | 49 ++++++------------- .../Internal/Networking/UvShutdownReq.cs | 37 ++++++++++++-- 3 files changed, 54 insertions(+), 42 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvAwaitable.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvAwaitable.cs index da1a8661ef..5c038a4456 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvAwaitable.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvAwaitable.cs @@ -2,9 +2,9 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. using System; +using System.Diagnostics; using System.Runtime.CompilerServices; using System.Threading; -using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking; namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal @@ -49,10 +49,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal public void OnCompleted(Action continuation) { + // There should never be a race between IsCompleted and OnCompleted since both operations + // should always be on the libuv thread + if (_callback == _callbackCompleted || Interlocked.CompareExchange(ref _callback, continuation, null) == _callbackCompleted) { - Task.Run(continuation); + Debug.Fail($"{typeof(LibuvAwaitable)}.{nameof(OnCompleted)} raced with {nameof(IsCompleted)}, running callback inline."); + + // Just run it inline + continuation(); } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvOutputConsumer.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvOutputConsumer.cs index cdcaccfc36..8b62da54ed 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvOutputConsumer.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvOutputConsumer.cs @@ -14,8 +14,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal private readonly UvStreamHandle _socket; private readonly string _connectionId; private readonly ILibuvTrace _log; - - private readonly WriteReqPool _writeReqPool; private readonly IPipeReader _pipe; public LibuvOutputConsumer( @@ -26,17 +24,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal ILibuvTrace log) { _pipe = pipe; - // We need to have empty pipe at this moment so callback - // get's scheduled _thread = thread; _socket = socket; _connectionId = connectionId; _log = log; - _writeReqPool = thread.WriteReqPool; } public async Task WriteOutputAsync() { + var pool = _thread.WriteReqPool; + while (true) { var result = await _pipe.ReadAsync(); @@ -46,7 +43,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal { if (!buffer.IsEmpty) { - var writeReq = _writeReqPool.Allocate(); + var writeReq = pool.Allocate(); try { @@ -62,14 +59,23 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal finally { // Make sure we return the writeReq to the pool - _writeReqPool.Return(writeReq); + pool.Return(writeReq); } } if (result.IsCancelled) { // Send a FIN - await ShutdownAsync(); + _log.ConnectionWriteFin(_connectionId); + + using (var shutdownReq = new UvShutdownReq(_log)) + { + shutdownReq.Init(_thread); + var shutdownResult = await shutdownReq.ShutdownAsync(_socket); + + _log.ConnectionWroteFin(_connectionId, shutdownResult.Status); + } + // Ensure no data is written after uv_shutdown break; } @@ -105,32 +111,5 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal } } } - - private Task ShutdownAsync() - { - var tcs = new TaskCompletionSource(); - _log.ConnectionWriteFin(_connectionId); - - var shutdownReq = new UvShutdownReq(_log); - try - { - shutdownReq.Init(_thread); - shutdownReq.Shutdown(_socket, (req, status, state) => - { - req.Dispose(); - _log.ConnectionWroteFin(_connectionId, status); - - tcs.TrySetResult(null); - }, - this); - } - catch (Exception) - { - shutdownReq.Dispose(); - throw; - } - - return tcs.Task; - } } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvShutdownReq.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvShutdownReq.cs index 19af091f01..3b2f74e53c 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvShutdownReq.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvShutdownReq.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using Microsoft.Extensions.Logging; namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking { @@ -12,10 +13,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networkin { private readonly static LibuvFunctions.uv_shutdown_cb _uv_shutdown_cb = UvShutdownCb; - private Action _callback; + private Action _callback; private object _state; + private LibuvAwaitable _awaitable = new LibuvAwaitable(); - public UvShutdownReq(ILibuvTrace logger) : base (logger) + public UvShutdownReq(ILibuvTrace logger) : base(logger) { } @@ -24,14 +26,20 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networkin var loop = thread.Loop; CreateMemory( - loop.Libuv, + loop.Libuv, loop.ThreadId, loop.Libuv.req_size(LibuvFunctions.RequestType.SHUTDOWN)); base.Init(thread); } - public void Shutdown(UvStreamHandle handle, Action callback, object state) + public LibuvAwaitable ShutdownAsync(UvStreamHandle handle) + { + Shutdown(handle, LibuvAwaitable.Callback, _awaitable); + return _awaitable; + } + + public void Shutdown(UvStreamHandle handle, Action callback, object state) { _callback = callback; _state = state; @@ -41,9 +49,28 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networkin private static void UvShutdownCb(IntPtr ptr, int status) { var req = FromIntPtr(ptr); - req._callback(req, status, req._state); + + var callback = req._callback; req._callback = null; + + var state = req._state; req._state = null; + + Exception error = null; + if (status < 0) + { + req.Libuv.Check(status, out error); + } + + try + { + callback(req, status, error, state); + } + catch (Exception ex) + { + req._log.LogError(0, ex, "UvShutdownCb"); + throw; + } } } } \ No newline at end of file From 71d2abed0681666612fb6260d44716ba5125f0bc Mon Sep 17 00:00:00 2001 From: David Fowler Date: Sun, 23 Apr 2017 20:45:03 -0700 Subject: [PATCH 1241/1662] More clean up of LibuvConnection (#1743) * More clean up of LibuvConnection - Use C# 7 - Use Buffer.Pin to get access to the underlying pointer instead of using TryGetPointer. --- .../Internal/LibuvConnection.cs | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvConnection.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvConnection.cs index 8637baf1ee..ce0aef2565 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvConnection.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvConnection.cs @@ -5,6 +5,7 @@ using System; using System.Diagnostics; using System.IO; using System.Threading.Tasks; +using Microsoft.AspNetCore.Server.Kestrel.Internal.System.Buffers; using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions; using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking; @@ -26,13 +27,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal private IConnectionContext _connectionContext; private WritableBuffer? _currentWritableBuffer; + private BufferHandle _bufferHandle; public LibuvConnection(ListenerContext context, UvStreamHandle socket) : base(context) { _socket = socket; - var tcpHandle = _socket as UvTcpHandle; - if (tcpHandle != null) + if (_socket is UvTcpHandle tcpHandle) { RemoteEndPoint = tcpHandle.GetPeerIPEndPoint(); LocalEndPoint = tcpHandle.GetSockIPEndPoint(); @@ -110,13 +111,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal Debug.Assert(_currentWritableBuffer == null); var currentWritableBuffer = Input.Alloc(MinAllocBufferSize); _currentWritableBuffer = currentWritableBuffer; - void* dataPtr; - var tryGetPointer = currentWritableBuffer.Buffer.TryGetPointer(out dataPtr); - Debug.Assert(tryGetPointer); - return handle.Libuv.buf_init( - (IntPtr)dataPtr, - currentWritableBuffer.Buffer.Length); + _bufferHandle = currentWritableBuffer.Buffer.Pin(); + + return handle.Libuv.buf_init((IntPtr)_bufferHandle.PinnedPointer, currentWritableBuffer.Buffer.Length); } private static void ReadCallback(UvStreamHandle handle, int status, object state) @@ -149,8 +147,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal WritableBufferAwaitable? flushTask = null; if (errorDone) { - Exception uvError; - handle.Libuv.Check(status, out uvError); + handle.Libuv.Check(status, out var uvError); // Log connection resets at a lower (Debug) level. if (status == LibuvConstants.ECONNRESET) @@ -176,6 +173,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal } _currentWritableBuffer = null; + _bufferHandle.Free(); + if (flushTask?.IsCompleted == false) { Log.ConnectionPause(ConnectionId); From df9e48b1f07a30d7b491107bab6b4483f097295e Mon Sep 17 00:00:00 2001 From: Pavel Krymets Date: Mon, 24 Apr 2017 11:58:08 -0700 Subject: [PATCH 1242/1662] Add cancellation support for write async (#1736) --- .../Adapter/Internal/StreamSocketOutput.cs | 4 +- .../Internal/Http/OutputProducer.cs | 15 +- .../Internal/LibuvOutputConsumer.cs | 4 +- .../LibuvOutputConsumerTests.cs | 163 +++++++++++++++++- 4 files changed, 166 insertions(+), 20 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/Internal/StreamSocketOutput.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/Internal/StreamSocketOutput.cs index 926f0d1cc1..6055f271f5 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/Internal/StreamSocketOutput.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/Internal/StreamSocketOutput.cs @@ -12,8 +12,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal { public class StreamSocketOutput : ISocketOutput { - private static readonly ArraySegment _nullBuffer = new ArraySegment(new byte[0]); - private readonly Stream _outputStream; private readonly IPipe _pipe; private readonly object _sync = new object(); @@ -57,7 +55,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal } } - flushAwaiter = writableBuffer.FlushAsync(); + flushAwaiter = writableBuffer.FlushAsync(cancellationToken); } await flushAwaiter; diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/OutputProducer.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/OutputProducer.cs index 1ced4a5b25..d8695f6efb 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/OutputProducer.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/OutputProducer.cs @@ -77,12 +77,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http writableBuffer.Commit(); } - return FlushAsync(writableBuffer); + return FlushAsync(writableBuffer, cancellationToken); } - private Task FlushAsync(WritableBuffer writableBuffer) + private Task FlushAsync(WritableBuffer writableBuffer, + CancellationToken cancellationToken) { - var awaitable = writableBuffer.FlushAsync(); + var awaitable = writableBuffer.FlushAsync(cancellationToken); if (awaitable.IsCompleted) { AbortIfNeeded(awaitable); @@ -90,10 +91,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http // The flush task can't fail today return TaskCache.CompletedTask; } - return FlushAsyncAwaited(awaitable); + return FlushAsyncAwaited(awaitable, cancellationToken); } - private Task FlushAsyncAwaited(WritableBufferAwaitable awaitable) + private async Task FlushAsyncAwaited(WritableBufferAwaitable awaitable, CancellationToken cancellationToken) { // https://github.com/dotnet/corefxlab/issues/1334 // Since the flush awaitable doesn't currently support multiple awaiters @@ -112,8 +113,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http }); } } - - return _flushTcs.Task; + await _flushTcs.Task; + cancellationToken.ThrowIfCancellationRequested(); } private void AbortIfNeeded(WritableBufferAwaitable awaitable) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvOutputConsumer.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvOutputConsumer.cs index 8b62da54ed..54950c23f0 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvOutputConsumer.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvOutputConsumer.cs @@ -38,6 +38,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal { var result = await _pipe.ReadAsync(); var buffer = result.Buffer; + var consumed = buffer.End; try { @@ -53,6 +54,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal if (writeResult.Error != null) { + consumed = buffer.Start; throw writeResult.Error; } } @@ -87,7 +89,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal } finally { - _pipe.Advance(result.Buffer.End); + _pipe.Advance(consumed); } } } diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/LibuvOutputConsumerTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/LibuvOutputConsumerTests.cs index 15cfc81453..eb99d26fb2 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/LibuvOutputConsumerTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/LibuvOutputConsumerTests.cs @@ -208,7 +208,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests var bufferSize = maxResponseBufferSize - 1; var buffer = new ArraySegment(new byte[bufferSize], 0, bufferSize); - // Act + // Act var writeTask1 = socketOutput.WriteAsync(buffer, default(CancellationToken)); // Assert @@ -219,7 +219,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests var writeTask2 = socketOutput.WriteAsync(buffer, default(CancellationToken)); await _mockLibuv.OnPostTask; - // Assert + // Assert // Too many bytes are already pre-completed for the second write to pre-complete. Assert.False(writeTask2.IsCompleted); @@ -270,7 +270,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests var data = new byte[bufferSize]; var halfWriteBehindBuffer = new ArraySegment(data, 0, bufferSize); - // Act + // Act var writeTask1 = socketOutput.WriteAsync(halfWriteBehindBuffer, default(CancellationToken)); // Assert @@ -337,7 +337,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests var data = new byte[bufferSize]; var fullBuffer = new ArraySegment(data, 0, bufferSize); - // Act + // Act var task1Success = socketOutput.WriteAsync(fullBuffer, abortedSource.Token); // task1 should complete successfully as < _maxBytesPreCompleted @@ -358,7 +358,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests Assert.False(task2Success.IsCanceled); Assert.False(task2Success.IsFaulted); - // Third task is not completed + // Third task is not completed Assert.False(task3Canceled.IsCompleted); Assert.False(task3Canceled.IsCanceled); Assert.False(task3Canceled.IsFaulted); @@ -382,14 +382,159 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests Assert.False(task4Success.IsFaulted); // Third task is now canceled - // TODO: Cancellation isn't supported right now - // await Assert.ThrowsAsync(() => task3Canceled); - // Assert.True(task3Canceled.IsCanceled); + await Assert.ThrowsAsync(() => task3Canceled); + Assert.True(task3Canceled.IsCanceled); Assert.True(abortedSource.IsCancellationRequested); } } + [Theory] + [MemberData(nameof(PositiveMaxResponseBufferSizeData))] + public async Task CancelsBeforeWriteRequestCompletes(int maxResponseBufferSize) + { + var completeQueue = new ConcurrentQueue>(); + + // Arrange + _mockLibuv.OnWrite = (socket, buffers, triggerCompleted) => + { + completeQueue.Enqueue(triggerCompleted); + return 0; + }; + + var abortedSource = new CancellationTokenSource(); + + var pipeOptions = new PipeOptions + { + ReaderScheduler = _libuvThread, + MaximumSizeHigh = maxResponseBufferSize, + MaximumSizeLow = maxResponseBufferSize, + }; + + using (var socketOutput = CreateOutputProducer(pipeOptions)) + { + var bufferSize = maxResponseBufferSize - 1; + + var data = new byte[bufferSize]; + var fullBuffer = new ArraySegment(data, 0, bufferSize); + + // Act + var task1Success = socketOutput.WriteAsync(fullBuffer, abortedSource.Token); + // task1 should complete successfully as < _maxBytesPreCompleted + + // First task is completed and successful + Assert.True(task1Success.IsCompleted); + Assert.False(task1Success.IsCanceled); + Assert.False(task1Success.IsFaulted); + + // following tasks should wait. + var task3Canceled = socketOutput.WriteAsync(fullBuffer, abortedSource.Token); + + // Give time for tasks to percolate + await _mockLibuv.OnPostTask; + + // Third task is not completed + Assert.False(task3Canceled.IsCompleted); + Assert.False(task3Canceled.IsCanceled); + Assert.False(task3Canceled.IsFaulted); + + abortedSource.Cancel(); + + // Complete writes + while (completeQueue.TryDequeue(out var triggerNextCompleted)) + { + await _libuvThread.PostAsync(cb => cb(0), triggerNextCompleted); + } + + // A final write guarantees that the error is observed by OutputProducer, + // but doesn't return a canceled/faulted task. + var task4Success = socketOutput.WriteAsync(fullBuffer, default(CancellationToken)); + Assert.True(task4Success.IsCompleted); + Assert.False(task4Success.IsCanceled); + Assert.False(task4Success.IsFaulted); + + // Third task is now canceled + await Assert.ThrowsAsync(() => task3Canceled); + Assert.True(task3Canceled.IsCanceled); + + Assert.True(abortedSource.IsCancellationRequested); + } + } + + [Theory] + [MemberData(nameof(PositiveMaxResponseBufferSizeData))] + public async Task WriteAsyncWithTokenAfterCallWithoutIsCancelled(int maxResponseBufferSize) + { + var completeQueue = new ConcurrentQueue>(); + + // Arrange + _mockLibuv.OnWrite = (socket, buffers, triggerCompleted) => + { + completeQueue.Enqueue(triggerCompleted); + return 0; + }; + + var abortedSource = new CancellationTokenSource(); + + var pipeOptions = new PipeOptions + { + ReaderScheduler = _libuvThread, + MaximumSizeHigh = maxResponseBufferSize, + MaximumSizeLow = maxResponseBufferSize, + }; + + using (var socketOutput = CreateOutputProducer(pipeOptions)) + { + var bufferSize = maxResponseBufferSize; + + var data = new byte[bufferSize]; + var fullBuffer = new ArraySegment(data, 0, bufferSize); + + // Act + var task1Waits = socketOutput.WriteAsync(fullBuffer, default(CancellationToken)); + + // First task is not completed + Assert.False(task1Waits.IsCompleted); + Assert.False(task1Waits.IsCanceled); + Assert.False(task1Waits.IsFaulted); + + // following tasks should wait. + var task3Canceled = socketOutput.WriteAsync(fullBuffer, abortedSource.Token); + + // Give time for tasks to percolate + await _mockLibuv.OnPostTask; + + // Third task is not completed + Assert.False(task3Canceled.IsCompleted); + Assert.False(task3Canceled.IsCanceled); + Assert.False(task3Canceled.IsFaulted); + + abortedSource.Cancel(); + + // Complete writes + while (completeQueue.TryDequeue(out var triggerNextCompleted)) + { + await _libuvThread.PostAsync(cb => cb(0), triggerNextCompleted); + } + + // First task is completed + Assert.True(task1Waits.IsCompleted); + Assert.False(task1Waits.IsCanceled); + Assert.False(task1Waits.IsFaulted); + + // A final write guarantees that the error is observed by OutputProducer, + // but doesn't return a canceled/faulted task. + var task4Success = socketOutput.WriteAsync(fullBuffer, default(CancellationToken)); + Assert.True(task4Success.IsCompleted); + Assert.False(task4Success.IsCanceled); + Assert.False(task4Success.IsFaulted); + + // Third task is now canceled + await Assert.ThrowsAsync(() => task3Canceled); + Assert.True(task3Canceled.IsCanceled); + } + } + [Theory] [MemberData(nameof(PositiveMaxResponseBufferSizeData))] public async Task WritesDontGetCompletedTooQuickly(int maxResponseBufferSize) @@ -436,7 +581,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests var timeout = TimeSpan.FromSeconds(5); - // Assert + // Assert // Too many bytes are already pre-completed for the third but not the second write to pre-complete. // https://github.com/aspnet/KestrelHttpServer/issues/356 await writeTask2.TimeoutAfter(timeout); From 7e5604b2f5ad35ac1116b581ec2bfa7952473901 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Mon, 24 Apr 2017 11:58:52 -0700 Subject: [PATCH 1243/1662] Remove async from OnRead (#1746) - Remove async from fast path. - Added ApplyBackpressureAsync that pauses and resumes reading --- .../Internal/LibuvConnection.cs | 37 +++++++++++-------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvConnection.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvConnection.cs index ce0aef2565..0bfc0446c8 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvConnection.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvConnection.cs @@ -122,7 +122,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal ((LibuvConnection)state).OnRead(handle, status); } - private async void OnRead(UvStreamHandle handle, int status) + private void OnRead(UvStreamHandle handle, int status) { var normalRead = status >= 0; var normalDone = status == LibuvConstants.EOF; @@ -175,20 +175,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal _currentWritableBuffer = null; _bufferHandle.Free(); - if (flushTask?.IsCompleted == false) - { - Log.ConnectionPause(ConnectionId); - StopReading(); - - var result = await flushTask.Value; - // If the reader isn't complete then resume - if (!result.IsCompleted && !result.IsCancelled) - { - Log.ConnectionResume(ConnectionId); - StartReading(); - } - } - if (!normalRead) { _connectionContext.Abort(error); @@ -196,6 +182,27 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal // Complete after aborting the connection Input.Complete(error); } + else if (flushTask?.IsCompleted == false) + { + // We wrote too many bytes too the reader so pause reading and resume when + // we hit the low water mark + _ = ApplyBackpressureAsync(flushTask.Value); + } + } + + private async Task ApplyBackpressureAsync(WritableBufferAwaitable flushTask) + { + Log.ConnectionPause(ConnectionId); + StopReading(); + + var result = await flushTask; + + // If the reader isn't complete or cancelled then resume reading + if (!result.IsCompleted && !result.IsCancelled) + { + Log.ConnectionResume(ConnectionId); + StartReading(); + } } private void StopReading() From a98581670eb15177ad1d04b7aa9a09c2ea0c9135 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Mon, 24 Apr 2017 12:19:22 -0700 Subject: [PATCH 1244/1662] Schedule connection adapter reads on configured thread pool (#1741) * Schedule connection adapter reads on configured thread pool - This should speed up connection adapters as we don't block new reads. It *might* also help some of the test flakiness --- .../Internal/FrameConnection.cs | 2 +- .../PipeOptionsTests.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnection.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnection.cs index fef3f1847f..99bf9346d9 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnection.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnection.cs @@ -49,7 +49,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal // Internal for testing internal PipeOptions AdaptedInputPipeOptions => new PipeOptions { - ReaderScheduler = InlineScheduler.Default, + ReaderScheduler = _context.ServiceContext.ThreadPool, WriterScheduler = InlineScheduler.Default, MaximumSizeHigh = _context.ServiceContext.ServerOptions.Limits.MaxRequestBufferSize ?? 0, MaximumSizeLow = _context.ServiceContext.ServerOptions.Limits.MaxRequestBufferSize ?? 0 diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/PipeOptionsTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/PipeOptionsTests.cs index 2b544bd393..56cec36d96 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/PipeOptionsTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/PipeOptionsTests.cs @@ -66,7 +66,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests Assert.Equal(expectedMaximumSizeLow, connectionLifetime.AdaptedInputPipeOptions.MaximumSizeLow); Assert.Equal(expectedMaximumSizeHigh, connectionLifetime.AdaptedInputPipeOptions.MaximumSizeHigh); - Assert.Same(InlineScheduler.Default, connectionLifetime.AdaptedInputPipeOptions.ReaderScheduler); + Assert.Same(serviceContext.ThreadPool, connectionLifetime.AdaptedInputPipeOptions.ReaderScheduler); Assert.Same(InlineScheduler.Default, connectionLifetime.AdaptedInputPipeOptions.WriterScheduler); } From c22f8f5c59cb5d941e243fd6a794f4d593fe8ada Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Mon, 24 Apr 2017 16:47:48 -0700 Subject: [PATCH 1245/1662] Fix potential race in LibuvThread.StopAsync (#1756) --- .../Internal/LibuvThread.cs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvThread.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvThread.cs index e816d2630b..f5e4909635 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvThread.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvThread.cs @@ -102,10 +102,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal { var stepTimeout = TimeSpan.FromTicks(timeout.Ticks / 3); - Post(t => t.AllowStop()); - if (!await WaitAsync(_threadTcs.Task, stepTimeout).ConfigureAwait(false)) + try { - try + Post(t => t.AllowStop()); + if (!await WaitAsync(_threadTcs.Task, stepTimeout).ConfigureAwait(false)) { Post(t => t.OnStopRude()); if (!await WaitAsync(_threadTcs.Task, stepTimeout).ConfigureAwait(false)) @@ -117,12 +117,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal } } } - catch (ObjectDisposedException) + } + catch (ObjectDisposedException) + { + if (!await WaitAsync(_threadTcs.Task, stepTimeout).ConfigureAwait(false)) { - if (!await WaitAsync(_threadTcs.Task, stepTimeout).ConfigureAwait(false)) - { - _log.LogCritical($"{nameof(LibuvThread)}.{nameof(StopAsync)} failed to terminate libuv thread."); - } + _log.LogCritical($"{nameof(LibuvThread)}.{nameof(StopAsync)} failed to terminate libuv thread."); } } } From 089ff49643d03adde8ccdb3df8311c86fc789c7b Mon Sep 17 00:00:00 2001 From: Nate McMaster Date: Mon, 24 Apr 2017 14:37:41 -0700 Subject: [PATCH 1246/1662] Put hostname address registration into separate test --- .../AddressRegistrationTests.cs | 102 +++++++++--------- .../DnsIsReachableConditionAttribute.cs | 40 +++++++ .../IPv6ScopeIdPresentConditionAttribute.cs | 0 .../IPv6SupportedConditionAttribute.cs | 0 4 files changed, 94 insertions(+), 48 deletions(-) create mode 100644 test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/TestHelpers/DnsIsReachableConditionAttribute.cs rename test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/{ => TestHelpers}/IPv6ScopeIdPresentConditionAttribute.cs (100%) rename test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/{ => TestHelpers}/IPv6SupportedConditionAttribute.cs (100%) diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs index 21be87955c..c658dbc540 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs @@ -23,13 +23,32 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using Xunit; +using Xunit.Abstractions; namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { public class AddressRegistrationTests { - [ConditionalTheory, MemberData(nameof(AddressRegistrationDataIPv4))] - [OSSkipCondition(OperatingSystems.MacOSX, SkipReason = "Causing test failures")] + private readonly ILoggerFactory _logger; + + public AddressRegistrationTests(ITestOutputHelper output) => _logger = new LoggerFactory().AddXunit(output); + + [ConditionalFact] + [DnsHostNameIsResolvable] + public async Task RegisterAddresses_HostName_Success() + { + var hostName = Dns.GetHostName(); + string FixUrl(string url) + { + return url + .Replace("0.0.0.0", hostName) + .Replace("[::]", hostName); + } + + await RegisterAddresses_Success($"http://{hostName}:0", a => a.Addresses.Select(FixUrl).ToArray()); + } + + [Theory, MemberData(nameof(AddressRegistrationDataIPv4))] public async Task RegisterAddresses_IPv4_Success(string addressInput, Func testUrls) { await RegisterAddresses_Success(addressInput, testUrls); @@ -101,6 +120,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { var hostBuilder = new WebHostBuilder() .UseKestrel() + .UseLoggerFactory(_logger) .UseUrls(addressInput) .Configure(ConfigureEchoAddress); @@ -122,6 +142,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests private async Task RegisterIPEndPoint_Success(IPEndPoint endPoint, Func testUrl) { var hostBuilder = new WebHostBuilder() + .UseLoggerFactory(_logger) .UseKestrel(options => { options.Listen(endPoint, listenOptions => @@ -170,9 +191,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests var testLogger = new TestApplicationErrorLogger(); var hostBuilder = new WebHostBuilder() - .UseKestrel() - .UseLoggerFactory(_ => new KestrelTestLoggerFactory(testLogger)) - .Configure(ConfigureEchoAddress); + .UseLoggerFactory(_logger) + .UseKestrel() + .UseLoggerFactory(_ => new KestrelTestLoggerFactory(testLogger)) + .Configure(ConfigureEchoAddress); using (var host = hostBuilder.Build()) { @@ -199,6 +221,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests socket.Bind(new IPEndPoint(IPAddress.Loopback, port)); var hostBuilder = new WebHostBuilder() + .UseLoggerFactory(_logger) .UseKestrel() .UseUrls($"http://127.0.0.1:{port}") .Configure(ConfigureEchoAddress); @@ -221,6 +244,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests socket.Bind(new IPEndPoint(IPAddress.IPv6Loopback, port)); var hostBuilder = new WebHostBuilder() + .UseLoggerFactory(_logger) .UseKestrel() .UseUrls($"http://[::1]:{port}") .Configure(ConfigureEchoAddress); @@ -271,10 +295,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests var endPointAddress = $"http://localhost:{endPointPort}"; var hostBuilder = new WebHostBuilder() - .UseKestrel(options => options.Listen(IPAddress.Loopback, endPointPort)) - .UseUrls($"http://localhost:{useUrlsPort}") - .PreferHostingUrls(false) - .Configure(ConfigureEchoAddress); + .UseLoggerFactory(_logger) + .UseKestrel(options => options.Listen(IPAddress.Loopback, endPointPort)) + .UseUrls($"http://localhost:{useUrlsPort}") + .PreferHostingUrls(false) + .Configure(ConfigureEchoAddress); using (var host = hostBuilder.Build()) { @@ -292,9 +317,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests var endPointAddress = $"http://localhost:{endPointPort}"; var hostBuilder = new WebHostBuilder() - .UseKestrel(options => options.Listen(IPAddress.Loopback, endPointPort)) - .PreferHostingUrls(true) - .Configure(ConfigureEchoAddress); + .UseLoggerFactory(_logger) + .UseKestrel(options => options.Listen(IPAddress.Loopback, endPointPort)) + .PreferHostingUrls(true) + .Configure(ConfigureEchoAddress); using (var host = hostBuilder.Build()) { @@ -356,6 +382,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests socket.Bind(new IPEndPoint(address, port)); var hostBuilder = new WebHostBuilder() + .UseLoggerFactory(_logger) .UseKestrel() .UseUrls($"http://localhost:{port}") .Configure(ConfigureEchoAddress); @@ -389,15 +416,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests dataset.Add($"http://*:{port}/", _ => new[] { $"http://127.0.0.1:{port}/" }); dataset.Add($"http://+:{port}/", _ => new[] { $"http://127.0.0.1:{port}/" }); - // Dynamic port and non-loopback addresses - dataset.Add("http://127.0.0.1:0/", GetTestUrls); - dataset.Add($"http://{Dns.GetHostName()}:0/", GetTestUrls); + // Dynamic port addresses + dataset.Add("http://127.0.0.1:0/", f => f.Addresses.ToArray()); var ipv4Addresses = GetIPAddresses() .Where(ip => ip.AddressFamily == AddressFamily.InterNetwork); foreach (var ip in ipv4Addresses) { - dataset.Add($"http://{ip}:0/", GetTestUrls); + dataset.Add($"http://{ip}:0/", f => f.Addresses.ToArray()); } return dataset; @@ -425,8 +451,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests dataset.Add(new IPEndPoint(IPAddress.Loopback, port), _ => $"https://127.0.0.1:{port}/"); // IPv6 loopback - dataset.Add(new IPEndPoint(IPAddress.IPv6Loopback, port), _ => FixTestUrl($"http://[::1]:{port}/")); - dataset.Add(new IPEndPoint(IPAddress.IPv6Loopback, port), _ => FixTestUrl($"https://[::1]:{port}/")); + dataset.Add(new IPEndPoint(IPAddress.IPv6Loopback, port), _ => $"http://[::1]:{port}/"); + dataset.Add(new IPEndPoint(IPAddress.IPv6Loopback, port), _ => $"https://[::1]:{port}/"); // Any dataset.Add(new IPEndPoint(IPAddress.Any, port), _ => $"http://127.0.0.1:{port}/"); @@ -434,9 +460,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests // IPv6 Any dataset.Add(new IPEndPoint(IPAddress.IPv6Any, port), _ => $"http://127.0.0.1:{port}/"); - dataset.Add(new IPEndPoint(IPAddress.IPv6Any, port), _ => FixTestUrl($"http://[::1]:{port}/")); + dataset.Add(new IPEndPoint(IPAddress.IPv6Any, port), _ => $"http://[::1]:{port}/"); dataset.Add(new IPEndPoint(IPAddress.IPv6Any, port), _ => $"https://127.0.0.1:{port}/"); - dataset.Add(new IPEndPoint(IPAddress.IPv6Any, port), _ => FixTestUrl($"https://[::1]:{port}/")); + dataset.Add(new IPEndPoint(IPAddress.IPv6Any, port), _ => $"https://[::1]:{port}/"); // Dynamic port dataset.Add(new IPEndPoint(IPAddress.Loopback, 0), endPoint => $"http://127.0.0.1:{endPoint.Port}/"); @@ -446,8 +472,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests .Where(ip => ip.AddressFamily == AddressFamily.InterNetwork); foreach (var ip in ipv4Addresses) { - dataset.Add(new IPEndPoint(ip, 0), endPoint => FixTestUrl($"http://{endPoint}/")); - dataset.Add(new IPEndPoint(ip, 0), endPoint => FixTestUrl($"https://{endPoint}/")); + dataset.Add(new IPEndPoint(ip, 0), endPoint => $"http://{endPoint}/"); + dataset.Add(new IPEndPoint(ip, 0), endPoint => $"https://{endPoint}/"); } return dataset; @@ -476,9 +502,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests var dataset = new TheoryData>(); dataset.Add(new IPEndPoint(IPAddress.Loopback, 443), _ => "https://127.0.0.1/"); - dataset.Add(new IPEndPoint(IPAddress.IPv6Loopback, 443), _ => FixTestUrl("https://[::1]/")); + dataset.Add(new IPEndPoint(IPAddress.IPv6Loopback, 443), _ => "https://[::1]/"); dataset.Add(new IPEndPoint(IPAddress.Any, 443), _ => "https://127.0.0.1/"); - dataset.Add(new IPEndPoint(IPAddress.IPv6Any, 443), _ => FixTestUrl("https://[::1]/")); + dataset.Add(new IPEndPoint(IPAddress.IPv6Any, 443), _ => "https://[::1]/"); return dataset; } @@ -515,9 +541,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests var ipv6Addresses = GetIPAddresses() .Where(ip => ip.AddressFamily == AddressFamily.InterNetworkV6) .Where(ip => ip.ScopeId == 0); + foreach (var ip in ipv6Addresses) { - dataset.Add($"http://[{ip}]:0/", GetTestUrls); + dataset.Add($"http://[{ip}]:0/", f => f.Addresses.ToArray()); } return dataset; @@ -560,12 +587,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests foreach (var ip in ipv6Addresses) { - dataset.Add($"http://[{ip}]:0/", GetTestUrls); + dataset.Add($"http://[{ip}]:0/", f => f.Addresses.ToArray()); } // There may be no addresses with scope IDs and we need at least one data item in the // collection, otherwise xUnit fails the test run because a theory has no data. - dataset.Add("http://[::1]:0", GetTestUrls); + dataset.Add("http://[::1]:0", f => f.Addresses.ToArray()); return dataset; } @@ -579,27 +606,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests .Select(a => a.Address); } - private static string[] GetTestUrls(IServerAddressesFeature addressesFeature) - { - return addressesFeature.Addresses - .Select(FixTestUrl) - .ToArray(); - } - - private static string FixTestUrl(string url) - { - var fixedUrl = url.Replace("://+", "://localhost") - .Replace("0.0.0.0", Dns.GetHostName()) - .Replace("[::]", Dns.GetHostName()); - - if (!fixedUrl.EndsWith("/")) - { - fixedUrl = fixedUrl + "/"; - } - - return fixedUrl; - } - private void ConfigureEchoAddress(IApplicationBuilder app) { app.Run(context => diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/TestHelpers/DnsIsReachableConditionAttribute.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/TestHelpers/DnsIsReachableConditionAttribute.cs new file mode 100644 index 0000000000..76bf6dfa41 --- /dev/null +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/TestHelpers/DnsIsReachableConditionAttribute.cs @@ -0,0 +1,40 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Linq; +using System.Net; +using Microsoft.AspNetCore.Testing.xunit; + +namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests +{ + [AttributeUsage(AttributeTargets.Method, AllowMultiple = false)] + public class DnsHostNameIsResolvableAttribute : Attribute, ITestCondition + { + private string _hostname; + + public bool IsMet + { + get + { + try + { + _hostname = Dns.GetHostName(); + var addresses = Dns.GetHostAddresses(_hostname); + if (addresses.Any(i => !IPAddress.IsLoopback(i))) + { + return true; + } + } + catch + { } + + return false; + } + } + + public string SkipReason => _hostname != null + ? $"Could not resolve any non-loopback IP address(es) for hostname '{_hostname}'" + : "Could not determine hostname for current test machine"; + } +} diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/IPv6ScopeIdPresentConditionAttribute.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/TestHelpers/IPv6ScopeIdPresentConditionAttribute.cs similarity index 100% rename from test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/IPv6ScopeIdPresentConditionAttribute.cs rename to test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/TestHelpers/IPv6ScopeIdPresentConditionAttribute.cs diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/IPv6SupportedConditionAttribute.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/TestHelpers/IPv6SupportedConditionAttribute.cs similarity index 100% rename from test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/IPv6SupportedConditionAttribute.cs rename to test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/TestHelpers/IPv6SupportedConditionAttribute.cs From 39047638cc60a0b298a05f30b167d6ee6783383d Mon Sep 17 00:00:00 2001 From: Nate McMaster Date: Mon, 24 Apr 2017 15:36:18 -0700 Subject: [PATCH 1247/1662] Add debug logging in address binding when IPv6Any fails --- KestrelHttpServer.sln | 1 + .../CoreStrings.resx | 3 ++ .../Internal/AddressBinder.cs | 2 ++ .../Properties/CoreStrings.Designer.cs | 14 ++++++++++ .../AddressBinderTests.cs | 5 +++- test/shared/MockLogger.cs | 28 +++++++++++++++++++ 6 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 test/shared/MockLogger.cs diff --git a/KestrelHttpServer.sln b/KestrelHttpServer.sln index 2fba69b809..3c10b81d05 100644 --- a/KestrelHttpServer.sln +++ b/KestrelHttpServer.sln @@ -25,6 +25,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "shared", "shared", "{0EF2AC test\shared\KestrelTestLoggerFactory.cs = test\shared\KestrelTestLoggerFactory.cs test\shared\LifetimeNotImplemented.cs = test\shared\LifetimeNotImplemented.cs test\shared\MockFrameControl.cs = test\shared\MockFrameControl.cs + test\shared\MockLogger.cs = test\shared\MockLogger.cs test\shared\MockSocketOutput.cs = test\shared\MockSocketOutput.cs test\shared\MockSystemClock.cs = test\shared\MockSystemClock.cs test\shared\StringExtensions.cs = test\shared\StringExtensions.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/CoreStrings.resx b/src/Microsoft.AspNetCore.Server.Kestrel.Core/CoreStrings.resx index f1605f6630..03a86be5db 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/CoreStrings.resx +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/CoreStrings.resx @@ -117,6 +117,9 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + Failed to bind to http://[::]:{port} (IPv6Any). Attempting to bind to http://0.0.0.0:{port} instead. + Cannot write to response body after connection has been upgraded. diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/AddressBinder.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/AddressBinder.cs index e30418727b..d041c3bec0 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/AddressBinder.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/AddressBinder.cs @@ -206,6 +206,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal } catch (Exception ex) when (!(ex is IOException)) { + context.Logger.LogDebug(CoreStrings.FormatFallbackToIPv4Any(parsedAddress.Port)); + // for machines that do not support IPv6 options = new ListenOptions(new IPEndPoint(IPAddress.Any, parsedAddress.Port)); await BindEndpointAsync(options, context).ConfigureAwait(false); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Properties/CoreStrings.Designer.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Properties/CoreStrings.Designer.cs index 0deecaa6d1..c97aefeac9 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Properties/CoreStrings.Designer.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Properties/CoreStrings.Designer.cs @@ -10,6 +10,20 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core private static readonly ResourceManager _resourceManager = new ResourceManager("Microsoft.AspNetCore.Server.Kestrel.Core.CoreStrings", typeof(CoreStrings).GetTypeInfo().Assembly); + /// + /// Failed to bind to http://[::]:{port} (IPv6Any). Attempting to bind to http://0.0.0.0:{port} instead. + /// + internal static string FallbackToIPv4Any + { + get => GetString("FallbackToIPv4Any"); + } + + /// + /// Failed to bind to http://[::]:{port} (IPv6Any). Attempting to bind to http://0.0.0.0:{port} instead. + /// + internal static string FormatFallbackToIPv4Any(object port) + => string.Format(CultureInfo.CurrentCulture, GetString("FallbackToIPv4Any", "port"), port); + /// /// Cannot write to response body after connection has been upgraded. /// diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/AddressBinderTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/AddressBinderTests.cs index 762e3191f1..655bbaea25 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/AddressBinderTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/AddressBinderTests.cs @@ -8,6 +8,7 @@ using System.Net; using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal; using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions; +using Microsoft.AspNetCore.Testing; using Microsoft.Extensions.Logging.Abstractions; using Xunit; @@ -88,6 +89,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests [InlineData("http://contoso.com:80")] public async Task FallbackToIPv4WhenIPv6AnyBindFails(string address) { + var logger = new MockLogger(); var addresses = new ServerAddressesFeature(); addresses.Addresses.Add(address); var options = new List(); @@ -97,7 +99,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests await AddressBinder.BindAsync(addresses, options, - NullLogger.Instance, + logger, endpoint => { if (endpoint.IPEndPoint.Address == IPAddress.IPv6Any) @@ -116,6 +118,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests Assert.True(ipV4Attempt, "Should have attempted to bind to IPAddress.Any"); Assert.True(ipV6Attempt, "Should have attempted to bind to IPAddress.IPv6Any"); + Assert.Contains(logger.Messages, f => f.Equals(CoreStrings.FormatFallbackToIPv4Any(80))); } } } diff --git a/test/shared/MockLogger.cs b/test/shared/MockLogger.cs new file mode 100644 index 0000000000..677d0687de --- /dev/null +++ b/test/shared/MockLogger.cs @@ -0,0 +1,28 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Collections.Generic; +using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Logging.Abstractions.Internal; + +namespace Microsoft.AspNetCore.Testing +{ + public class MockLogger : ILogger + { + private List _messages = new List(); + + public IDisposable BeginScope(TState state) + => NullScope.Instance; + + public bool IsEnabled(LogLevel logLevel) + => true; + + public void Log(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func formatter) + { + _messages.Add(formatter(state, exception)); + } + + public IReadOnlyList Messages => _messages; + } +} From f26c31c1169adbcc8a7185a7527a4b9c86659ca1 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Mon, 24 Apr 2017 17:15:41 -0700 Subject: [PATCH 1248/1662] Fix scope id test failures on mac and linux (#1754) --- .../Internal/Networking/SockAddr.cs | 15 ++++++++++++++- .../Internal/Networking/UvTcpHandle.cs | 7 +++++++ .../AddressRegistrationTests.cs | 2 -- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/SockAddr.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/SockAddr.cs index 0f0210f91a..5386749623 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/SockAddr.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/SockAddr.cs @@ -93,7 +93,20 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networkin *((long*)(b + 8)) = _field2; } - return new IPEndPoint(new IPAddress(bytes, scopeid: _field3 & 0xFFFFFFFF), port); + return new IPEndPoint(new IPAddress(bytes, ScopeId), port); + } + } + + public uint ScopeId + { + get + { + return (uint)_field3; + } + set + { + _field3 &= unchecked ((long)0xFFFFFFFF00000000); + _field3 |= value; } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvTcpHandle.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvTcpHandle.cs index 260f04598e..1e3a1409cd 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvTcpHandle.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvTcpHandle.cs @@ -44,6 +44,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networkin { throw error1; } + + if (endPoint.Address.ScopeId != addr.ScopeId) + { + // IPAddress.ScopeId cannot be less than 0 or greater than 0xFFFFFFFF + // https://msdn.microsoft.com/en-us/library/system.net.ipaddress.scopeid(v=vs.110).aspx + addr.ScopeId = (uint)endPoint.Address.ScopeId; + } } _uv.tcp_bind(this, ref addr, 0); diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs index c658dbc540..9d717d3935 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs @@ -109,8 +109,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [ConditionalTheory, MemberData(nameof(AddressRegistrationDataIPv6ScopeId))] [IPv6SupportedCondition] [IPv6ScopeIdPresentCondition] - [OSSkipCondition(OperatingSystems.MacOSX, SkipReason = "Causing test failures")] - [OSSkipCondition(OperatingSystems.Linux, SkipReason = "Causing test failures")] public async Task RegisterAddresses_IPv6ScopeId_Success(string addressInput, Func testUrls) { await RegisterAddresses_Success(addressInput, testUrls); From 9e80fb65bd49183670a58f784fd7b90ab4d2ef11 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Mon, 24 Apr 2017 17:34:56 -0700 Subject: [PATCH 1249/1662] Removed the wrote after disconnect log (#1747) - It's not very useful --- .../Internal/Http/OutputProducer.cs | 3 --- .../Internal/Infrastructure/IKestrelTrace.cs | 2 -- .../Internal/Infrastructure/KestrelTrace.cs | 8 -------- .../Mocks/MockTrace.cs | 1 - 4 files changed, 14 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/OutputProducer.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/OutputProducer.cs index d8695f6efb..5e94d3e47f 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/OutputProducer.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/OutputProducer.cs @@ -51,9 +51,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { if (_completed) { - // TODO: Get actual notification when the consumer stopped from Pipes, - // so we know if the socket is fully closed and why (for logging exceptions); - _log.ConnectionDisconnectedWrite(_connectionId, buffer.Count, ex: null); return TaskCache.CompletedTask; } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/IKestrelTrace.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/IKestrelTrace.cs index 2f577007b4..680fecc7e2 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/IKestrelTrace.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/IKestrelTrace.cs @@ -22,8 +22,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure void RequestProcessingError(string connectionId, Exception ex); - void ConnectionDisconnectedWrite(string connectionId, int count, Exception ex); - void ConnectionHeadResponseBodyWrite(string connectionId, long count); void NotAllConnectionsClosedGracefully(); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/KestrelTrace.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/KestrelTrace.cs index e0a2a018aa..fac8fa080f 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/KestrelTrace.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/KestrelTrace.cs @@ -33,9 +33,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal private static readonly Action _applicationError = LoggerMessage.Define(LogLevel.Error, 13, @"Connection id ""{ConnectionId}"", Request id ""{TraceIdentifier}"": An unhandled exception was thrown by the application."); - private static readonly Action _connectionDisconnectedWrite = - LoggerMessage.Define(LogLevel.Debug, 15, @"Connection id ""{ConnectionId}"" write of ""{count}"" bytes to disconnected client."); - private static readonly Action _notAllConnectionsClosedGracefully = LoggerMessage.Define(LogLevel.Debug, 16, "Some connections failed to close gracefully during server shutdown."); @@ -99,11 +96,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal _applicationError(_logger, connectionId, traceIdentifier, ex); } - public virtual void ConnectionDisconnectedWrite(string connectionId, int count, Exception ex) - { - _connectionDisconnectedWrite(_logger, connectionId, count, ex); - } - public virtual void ConnectionHeadResponseBodyWrite(string connectionId, long count) { _connectionHeadResponseBodyWrite(_logger, connectionId, count, null); diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Mocks/MockTrace.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Mocks/MockTrace.cs index 6c60495590..87be9cde4d 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Mocks/MockTrace.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Mocks/MockTrace.cs @@ -14,7 +14,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance public IDisposable BeginScope(TState state) => null; public void ConnectionBadRequest(string connectionId, BadHttpRequestException ex) { } public void ConnectionDisconnect(string connectionId) { } - public void ConnectionDisconnectedWrite(string connectionId, int count, Exception ex) { } public void ConnectionError(string connectionId, Exception ex) { } public void ConnectionHeadResponseBodyWrite(string connectionId, long count) { } public void ConnectionKeepAlive(string connectionId) { } From e3e78bc461683f8ec485808ffc01ea091dbc5b54 Mon Sep 17 00:00:00 2001 From: Pavel Krymets Date: Mon, 24 Apr 2017 17:37:30 -0700 Subject: [PATCH 1250/1662] Fix LibuvOutputConsumerTests (#1757) * Fix LibuvOutputConsumerTests --- .../LibuvOutputConsumerTests.cs | 510 +++++++++--------- 1 file changed, 261 insertions(+), 249 deletions(-) diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/LibuvOutputConsumerTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/LibuvOutputConsumerTests.cs index eb99d26fb2..3d8fa5620c 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/LibuvOutputConsumerTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/LibuvOutputConsumerTests.cs @@ -248,291 +248,303 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests [MemberData(nameof(PositiveMaxResponseBufferSizeData))] public async Task WritesDontCompleteImmediatelyWhenTooManyBytesIncludingNonImmediateAreAlreadyBuffered(int maxResponseBufferSize) { - var completeQueue = new ConcurrentQueue>(); - - // Arrange - _mockLibuv.OnWrite = (socket, buffers, triggerCompleted) => + await Task.Run(async () => { - completeQueue.Enqueue(triggerCompleted); - return 0; - }; + var completeQueue = new ConcurrentQueue>(); - var pipeOptions = new PipeOptions - { - ReaderScheduler = _libuvThread, - MaximumSizeHigh = maxResponseBufferSize, - MaximumSizeLow = maxResponseBufferSize, - }; - - using (var socketOutput = CreateOutputProducer(pipeOptions)) - { - var bufferSize = maxResponseBufferSize / 2; - var data = new byte[bufferSize]; - var halfWriteBehindBuffer = new ArraySegment(data, 0, bufferSize); - - // Act - var writeTask1 = socketOutput.WriteAsync(halfWriteBehindBuffer, default(CancellationToken)); - - // Assert - // The first write should pre-complete since it is <= _maxBytesPreCompleted. - Assert.Equal(TaskStatus.RanToCompletion, writeTask1.Status); - await _mockLibuv.OnPostTask; - Assert.NotEmpty(completeQueue); - - // Add more bytes to the write-behind buffer to prevent the next write from - ((ISocketOutput)socketOutput).Write((writableBuffer, state) => + // Arrange + _mockLibuv.OnWrite = (socket, buffers, triggerCompleted) => { - writableBuffer.Write(state); - }, - halfWriteBehindBuffer); + completeQueue.Enqueue(triggerCompleted); + return 0; + }; - // Act - var writeTask2 = socketOutput.WriteAsync(halfWriteBehindBuffer, default(CancellationToken)); - Assert.False(writeTask2.IsCompleted); - - var writeTask3 = socketOutput.WriteAsync(halfWriteBehindBuffer, default(CancellationToken)); - Assert.False(writeTask3.IsCompleted); - - // Drain the write queue - while (completeQueue.TryDequeue(out var triggerNextCompleted)) + var pipeOptions = new PipeOptions { - await _libuvThread.PostAsync(cb => cb(0), triggerNextCompleted); + ReaderScheduler = _libuvThread, + MaximumSizeHigh = maxResponseBufferSize, + MaximumSizeLow = maxResponseBufferSize, + }; + + using (var socketOutput = CreateOutputProducer(pipeOptions)) + { + var bufferSize = maxResponseBufferSize / 2; + var data = new byte[bufferSize]; + var halfWriteBehindBuffer = new ArraySegment(data, 0, bufferSize); + + // Act + var writeTask1 = socketOutput.WriteAsync(halfWriteBehindBuffer, default(CancellationToken)); + + // Assert + // The first write should pre-complete since it is <= _maxBytesPreCompleted. + Assert.Equal(TaskStatus.RanToCompletion, writeTask1.Status); + await _mockLibuv.OnPostTask; + Assert.NotEmpty(completeQueue); + + // Add more bytes to the write-behind buffer to prevent the next write from + ((ISocketOutput) socketOutput).Write((writableBuffer, state) => + { + writableBuffer.Write(state); + }, + halfWriteBehindBuffer); + + // Act + var writeTask2 = socketOutput.WriteAsync(halfWriteBehindBuffer, default(CancellationToken)); + Assert.False(writeTask2.IsCompleted); + + var writeTask3 = socketOutput.WriteAsync(halfWriteBehindBuffer, default(CancellationToken)); + Assert.False(writeTask3.IsCompleted); + + // Drain the write queue + while (completeQueue.TryDequeue(out var triggerNextCompleted)) + { + await _libuvThread.PostAsync(cb => cb(0), triggerNextCompleted); + } + + var timeout = TimeSpan.FromSeconds(5); + + await writeTask2.TimeoutAfter(timeout); + await writeTask3.TimeoutAfter(timeout); + + Assert.Empty(completeQueue); } - - var timeout = TimeSpan.FromSeconds(5); - - await writeTask2.TimeoutAfter(timeout); - await writeTask3.TimeoutAfter(timeout); - - Assert.Empty(completeQueue); - } + }); } [Theory] [MemberData(nameof(PositiveMaxResponseBufferSizeData))] public async Task FailedWriteCompletesOrCancelsAllPendingTasks(int maxResponseBufferSize) { - var completeQueue = new ConcurrentQueue>(); - - // Arrange - _mockLibuv.OnWrite = (socket, buffers, triggerCompleted) => + await Task.Run(async () => { - completeQueue.Enqueue(triggerCompleted); - return 0; - }; + var completeQueue = new ConcurrentQueue>(); - var abortedSource = new CancellationTokenSource(); - - var pipeOptions = new PipeOptions - { - ReaderScheduler = _libuvThread, - MaximumSizeHigh = maxResponseBufferSize, - MaximumSizeLow = maxResponseBufferSize, - }; - - using (var socketOutput = CreateOutputProducer(pipeOptions, abortedSource)) - { - var bufferSize = maxResponseBufferSize - 1; - - var data = new byte[bufferSize]; - var fullBuffer = new ArraySegment(data, 0, bufferSize); - - // Act - var task1Success = socketOutput.WriteAsync(fullBuffer, abortedSource.Token); - // task1 should complete successfully as < _maxBytesPreCompleted - - // First task is completed and successful - Assert.True(task1Success.IsCompleted); - Assert.False(task1Success.IsCanceled); - Assert.False(task1Success.IsFaulted); - - // following tasks should wait. - var task2Success = socketOutput.WriteAsync(fullBuffer, default(CancellationToken)); - var task3Canceled = socketOutput.WriteAsync(fullBuffer, abortedSource.Token); - - // Give time for tasks to percolate - await _mockLibuv.OnPostTask; - - // Second task is not completed - Assert.False(task2Success.IsCompleted); - Assert.False(task2Success.IsCanceled); - Assert.False(task2Success.IsFaulted); - - // Third task is not completed - Assert.False(task3Canceled.IsCompleted); - Assert.False(task3Canceled.IsCanceled); - Assert.False(task3Canceled.IsFaulted); - - // Cause all writes to fail - while (completeQueue.TryDequeue(out var triggerNextCompleted)) + // Arrange + _mockLibuv.OnWrite = (socket, buffers, triggerCompleted) => { - await _libuvThread.PostAsync(cb => cb(-1), triggerNextCompleted); + completeQueue.Enqueue(triggerCompleted); + return 0; + }; + + var abortedSource = new CancellationTokenSource(); + + var pipeOptions = new PipeOptions + { + ReaderScheduler = _libuvThread, + MaximumSizeHigh = maxResponseBufferSize, + MaximumSizeLow = maxResponseBufferSize, + }; + + using (var socketOutput = CreateOutputProducer(pipeOptions, abortedSource)) + { + var bufferSize = maxResponseBufferSize - 1; + + var data = new byte[bufferSize]; + var fullBuffer = new ArraySegment(data, 0, bufferSize); + + // Act + var task1Success = socketOutput.WriteAsync(fullBuffer, abortedSource.Token); + // task1 should complete successfully as < _maxBytesPreCompleted + + // First task is completed and successful + Assert.True(task1Success.IsCompleted); + Assert.False(task1Success.IsCanceled); + Assert.False(task1Success.IsFaulted); + + // following tasks should wait. + var task2Success = socketOutput.WriteAsync(fullBuffer, default(CancellationToken)); + var task3Canceled = socketOutput.WriteAsync(fullBuffer, abortedSource.Token); + + // Give time for tasks to percolate + await _mockLibuv.OnPostTask; + + // Second task is not completed + Assert.False(task2Success.IsCompleted); + Assert.False(task2Success.IsCanceled); + Assert.False(task2Success.IsFaulted); + + // Third task is not completed + Assert.False(task3Canceled.IsCompleted); + Assert.False(task3Canceled.IsCanceled); + Assert.False(task3Canceled.IsFaulted); + + // Cause all writes to fail + while (completeQueue.TryDequeue(out var triggerNextCompleted)) + { + await _libuvThread.PostAsync(cb => cb(-1), triggerNextCompleted); + } + + // Second task is now completed + Assert.True(task2Success.IsCompleted); + Assert.False(task2Success.IsCanceled); + Assert.False(task2Success.IsFaulted); + + // A final write guarantees that the error is observed by OutputProducer, + // but doesn't return a canceled/faulted task. + var task4Success = socketOutput.WriteAsync(fullBuffer, default(CancellationToken)); + Assert.True(task4Success.IsCompleted); + Assert.False(task4Success.IsCanceled); + Assert.False(task4Success.IsFaulted); + + // Third task is now canceled + await Assert.ThrowsAsync(() => task3Canceled); + Assert.True(task3Canceled.IsCanceled); + + Assert.True(abortedSource.IsCancellationRequested); } - - // Second task is now completed - Assert.True(task2Success.IsCompleted); - Assert.False(task2Success.IsCanceled); - Assert.False(task2Success.IsFaulted); - - // A final write guarantees that the error is observed by OutputProducer, - // but doesn't return a canceled/faulted task. - var task4Success = socketOutput.WriteAsync(fullBuffer, default(CancellationToken)); - Assert.True(task4Success.IsCompleted); - Assert.False(task4Success.IsCanceled); - Assert.False(task4Success.IsFaulted); - - // Third task is now canceled - await Assert.ThrowsAsync(() => task3Canceled); - Assert.True(task3Canceled.IsCanceled); - - Assert.True(abortedSource.IsCancellationRequested); - } + }); } [Theory] [MemberData(nameof(PositiveMaxResponseBufferSizeData))] public async Task CancelsBeforeWriteRequestCompletes(int maxResponseBufferSize) { - var completeQueue = new ConcurrentQueue>(); - - // Arrange - _mockLibuv.OnWrite = (socket, buffers, triggerCompleted) => + await Task.Run(async () => { - completeQueue.Enqueue(triggerCompleted); - return 0; - }; + var completeQueue = new ConcurrentQueue>(); - var abortedSource = new CancellationTokenSource(); - - var pipeOptions = new PipeOptions - { - ReaderScheduler = _libuvThread, - MaximumSizeHigh = maxResponseBufferSize, - MaximumSizeLow = maxResponseBufferSize, - }; - - using (var socketOutput = CreateOutputProducer(pipeOptions)) - { - var bufferSize = maxResponseBufferSize - 1; - - var data = new byte[bufferSize]; - var fullBuffer = new ArraySegment(data, 0, bufferSize); - - // Act - var task1Success = socketOutput.WriteAsync(fullBuffer, abortedSource.Token); - // task1 should complete successfully as < _maxBytesPreCompleted - - // First task is completed and successful - Assert.True(task1Success.IsCompleted); - Assert.False(task1Success.IsCanceled); - Assert.False(task1Success.IsFaulted); - - // following tasks should wait. - var task3Canceled = socketOutput.WriteAsync(fullBuffer, abortedSource.Token); - - // Give time for tasks to percolate - await _mockLibuv.OnPostTask; - - // Third task is not completed - Assert.False(task3Canceled.IsCompleted); - Assert.False(task3Canceled.IsCanceled); - Assert.False(task3Canceled.IsFaulted); - - abortedSource.Cancel(); - - // Complete writes - while (completeQueue.TryDequeue(out var triggerNextCompleted)) + // Arrange + _mockLibuv.OnWrite = (socket, buffers, triggerCompleted) => { - await _libuvThread.PostAsync(cb => cb(0), triggerNextCompleted); + completeQueue.Enqueue(triggerCompleted); + return 0; + }; + + var abortedSource = new CancellationTokenSource(); + + var pipeOptions = new PipeOptions + { + ReaderScheduler = _libuvThread, + MaximumSizeHigh = maxResponseBufferSize, + MaximumSizeLow = maxResponseBufferSize, + }; + + using (var socketOutput = CreateOutputProducer(pipeOptions)) + { + var bufferSize = maxResponseBufferSize - 1; + + var data = new byte[bufferSize]; + var fullBuffer = new ArraySegment(data, 0, bufferSize); + + // Act + var task1Success = socketOutput.WriteAsync(fullBuffer, abortedSource.Token); + // task1 should complete successfully as < _maxBytesPreCompleted + + // First task is completed and successful + Assert.True(task1Success.IsCompleted); + Assert.False(task1Success.IsCanceled); + Assert.False(task1Success.IsFaulted); + + // following tasks should wait. + var task3Canceled = socketOutput.WriteAsync(fullBuffer, abortedSource.Token); + + // Give time for tasks to percolate + await _mockLibuv.OnPostTask; + + // Third task is not completed + Assert.False(task3Canceled.IsCompleted); + Assert.False(task3Canceled.IsCanceled); + Assert.False(task3Canceled.IsFaulted); + + abortedSource.Cancel(); + + // Complete writes + while (completeQueue.TryDequeue(out var triggerNextCompleted)) + { + await _libuvThread.PostAsync(cb => cb(0), triggerNextCompleted); + } + + // A final write guarantees that the error is observed by OutputProducer, + // but doesn't return a canceled/faulted task. + var task4Success = socketOutput.WriteAsync(fullBuffer, default(CancellationToken)); + Assert.True(task4Success.IsCompleted); + Assert.False(task4Success.IsCanceled); + Assert.False(task4Success.IsFaulted); + + // Third task is now canceled + await Assert.ThrowsAsync(() => task3Canceled); + Assert.True(task3Canceled.IsCanceled); + + Assert.True(abortedSource.IsCancellationRequested); } - - // A final write guarantees that the error is observed by OutputProducer, - // but doesn't return a canceled/faulted task. - var task4Success = socketOutput.WriteAsync(fullBuffer, default(CancellationToken)); - Assert.True(task4Success.IsCompleted); - Assert.False(task4Success.IsCanceled); - Assert.False(task4Success.IsFaulted); - - // Third task is now canceled - await Assert.ThrowsAsync(() => task3Canceled); - Assert.True(task3Canceled.IsCanceled); - - Assert.True(abortedSource.IsCancellationRequested); - } + }); } [Theory] [MemberData(nameof(PositiveMaxResponseBufferSizeData))] public async Task WriteAsyncWithTokenAfterCallWithoutIsCancelled(int maxResponseBufferSize) { - var completeQueue = new ConcurrentQueue>(); - - // Arrange - _mockLibuv.OnWrite = (socket, buffers, triggerCompleted) => + await Task.Run(async () => { - completeQueue.Enqueue(triggerCompleted); - return 0; - }; + var completeQueue = new ConcurrentQueue>(); - var abortedSource = new CancellationTokenSource(); - - var pipeOptions = new PipeOptions - { - ReaderScheduler = _libuvThread, - MaximumSizeHigh = maxResponseBufferSize, - MaximumSizeLow = maxResponseBufferSize, - }; - - using (var socketOutput = CreateOutputProducer(pipeOptions)) - { - var bufferSize = maxResponseBufferSize; - - var data = new byte[bufferSize]; - var fullBuffer = new ArraySegment(data, 0, bufferSize); - - // Act - var task1Waits = socketOutput.WriteAsync(fullBuffer, default(CancellationToken)); - - // First task is not completed - Assert.False(task1Waits.IsCompleted); - Assert.False(task1Waits.IsCanceled); - Assert.False(task1Waits.IsFaulted); - - // following tasks should wait. - var task3Canceled = socketOutput.WriteAsync(fullBuffer, abortedSource.Token); - - // Give time for tasks to percolate - await _mockLibuv.OnPostTask; - - // Third task is not completed - Assert.False(task3Canceled.IsCompleted); - Assert.False(task3Canceled.IsCanceled); - Assert.False(task3Canceled.IsFaulted); - - abortedSource.Cancel(); - - // Complete writes - while (completeQueue.TryDequeue(out var triggerNextCompleted)) + // Arrange + _mockLibuv.OnWrite = (socket, buffers, triggerCompleted) => { - await _libuvThread.PostAsync(cb => cb(0), triggerNextCompleted); + completeQueue.Enqueue(triggerCompleted); + return 0; + }; + + var abortedSource = new CancellationTokenSource(); + + var pipeOptions = new PipeOptions + { + ReaderScheduler = _libuvThread, + MaximumSizeHigh = maxResponseBufferSize, + MaximumSizeLow = maxResponseBufferSize, + }; + + using (var socketOutput = CreateOutputProducer(pipeOptions)) + { + var bufferSize = maxResponseBufferSize; + + var data = new byte[bufferSize]; + var fullBuffer = new ArraySegment(data, 0, bufferSize); + + // Act + var task1Waits = socketOutput.WriteAsync(fullBuffer, default(CancellationToken)); + + // First task is not completed + Assert.False(task1Waits.IsCompleted); + Assert.False(task1Waits.IsCanceled); + Assert.False(task1Waits.IsFaulted); + + // following tasks should wait. + var task3Canceled = socketOutput.WriteAsync(fullBuffer, abortedSource.Token); + + // Give time for tasks to percolate + await _mockLibuv.OnPostTask; + + // Third task is not completed + Assert.False(task3Canceled.IsCompleted); + Assert.False(task3Canceled.IsCanceled); + Assert.False(task3Canceled.IsFaulted); + + abortedSource.Cancel(); + + // Complete writes + while (completeQueue.TryDequeue(out var triggerNextCompleted)) + { + await _libuvThread.PostAsync(cb => cb(0), triggerNextCompleted); + } + + // First task is completed + Assert.True(task1Waits.IsCompleted); + Assert.False(task1Waits.IsCanceled); + Assert.False(task1Waits.IsFaulted); + + // A final write guarantees that the error is observed by OutputProducer, + // but doesn't return a canceled/faulted task. + var task4Success = socketOutput.WriteAsync(fullBuffer, default(CancellationToken)); + Assert.True(task4Success.IsCompleted); + Assert.False(task4Success.IsCanceled); + Assert.False(task4Success.IsFaulted); + + // Third task is now canceled + await Assert.ThrowsAsync(() => task3Canceled); + Assert.True(task3Canceled.IsCanceled); } - - // First task is completed - Assert.True(task1Waits.IsCompleted); - Assert.False(task1Waits.IsCanceled); - Assert.False(task1Waits.IsFaulted); - - // A final write guarantees that the error is observed by OutputProducer, - // but doesn't return a canceled/faulted task. - var task4Success = socketOutput.WriteAsync(fullBuffer, default(CancellationToken)); - Assert.True(task4Success.IsCompleted); - Assert.False(task4Success.IsCanceled); - Assert.False(task4Success.IsFaulted); - - // Third task is now canceled - await Assert.ThrowsAsync(() => task3Canceled); - Assert.True(task3Canceled.IsCanceled); - } + }); } [Theory] From a4def946a64062b75b0a144f6125f2c0df62d026 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Mon, 24 Apr 2017 23:48:47 -0700 Subject: [PATCH 1251/1662] Fix flaky 400 response tests (#1758) --- .../UpgradeTests.cs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/UpgradeTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/UpgradeTests.cs index d56ecf4d00..1249524bc5 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/UpgradeTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/UpgradeTests.cs @@ -123,7 +123,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests "", "1"); - await connection.Receive("HTTP/1.1 400 Bad Request"); + await connection.ReceiveForcedEnd( + "HTTP/1.1 400 Bad Request", + "Connection: close", + $"Date: {server.Context.DateHeaderValue}", + "Content-Length: 0", + "", + ""); } } @@ -167,7 +173,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests "Connection: Upgrade", "", ""); - await connection.Receive("HTTP/1.1 400 Bad Request"); + await connection.ReceiveForcedEnd( + "HTTP/1.1 400 Bad Request", + "Connection: close", + $"Date: {server.Context.DateHeaderValue}", + "Content-Length: 0", + "", + ""); } } } From 566a587126a1a091f05dba2804d5baf6ecea4118 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Tue, 25 Apr 2017 00:37:09 -0700 Subject: [PATCH 1252/1662] Added ApplicationSchedulingMode to KestrelServerOptions (#1759) * Added ApplicationSchedulingMode to KestrelServerOptions - Made default mode Default instead of ThreadPool --- samples/SampleApp/Startup.cs | 4 ++-- .../KestrelServer.cs | 20 ++++++++++++------- .../KestrelServerOptions.cs | 7 +++++++ .../SchedulingMode.cs | 12 +++++++++++ 4 files changed, 34 insertions(+), 9 deletions(-) create mode 100644 src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/SchedulingMode.cs diff --git a/samples/SampleApp/Startup.cs b/samples/SampleApp/Startup.cs index 8bf9350872..6c776817c1 100644 --- a/samples/SampleApp/Startup.cs +++ b/samples/SampleApp/Startup.cs @@ -8,7 +8,7 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Server.Kestrel.Core.Internal; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions; using Microsoft.Extensions.Logging; namespace SampleApp @@ -45,7 +45,7 @@ namespace SampleApp .UseKestrel(options => { // Run callbacks on the transport thread - options.UseTransportThread = true; + options.ApplicationSchedulingMode = SchedulingMode.Inline; options.Listen(IPAddress.Loopback, 5000, listenOptions => { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/KestrelServer.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/KestrelServer.cs index a442d30e93..b325ab723a 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/KestrelServer.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/KestrelServer.cs @@ -72,14 +72,20 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core var systemClock = new SystemClock(); var dateHeaderValueManager = new DateHeaderValueManager(systemClock); - IThreadPool threadPool; - if (serverOptions.UseTransportThread) + // TODO: This logic will eventually move into the IConnectionHandler and off + // the service context once we get to https://github.com/aspnet/KestrelHttpServer/issues/1662 + IThreadPool threadPool = null; + switch (serverOptions.ApplicationSchedulingMode) { - threadPool = new InlineLoggingThreadPool(trace); - } - else - { - threadPool = new LoggingThreadPool(trace); + case SchedulingMode.Default: + case SchedulingMode.ThreadPool: + threadPool = new LoggingThreadPool(trace); + break; + case SchedulingMode.Inline: + threadPool = new InlineLoggingThreadPool(trace); + break; + default: + throw new NotSupportedException($"Unknown transport mode {serverOptions.ApplicationSchedulingMode}"); } return new ServiceContext diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/KestrelServerOptions.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/KestrelServerOptions.cs index 9eb5084fd3..f97e5c3dd3 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/KestrelServerOptions.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/KestrelServerOptions.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using System.Net; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions; namespace Microsoft.AspNetCore.Server.Kestrel.Core { @@ -33,6 +34,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core /// public bool UseTransportThread { get; set; } + /// + /// Gets or sets a value that determines how Kestrel should schedule user callbacks. + /// + /// The default mode is + public SchedulingMode ApplicationSchedulingMode { get; set; } = SchedulingMode.Default; + /// /// Enables the Listen options callback to resolve and use services registered by the application during startup. /// Typically initialized by UseKestrel()"/>. diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/SchedulingMode.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/SchedulingMode.cs new file mode 100644 index 0000000000..5408bc1d11 --- /dev/null +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/SchedulingMode.cs @@ -0,0 +1,12 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions +{ + public enum SchedulingMode + { + Default, + ThreadPool, + Inline + } +} From 5b976a9fa3541e6c26086b647ddad7321654b4cb Mon Sep 17 00:00:00 2001 From: Pranav K Date: Tue, 25 Apr 2017 11:04:09 -0700 Subject: [PATCH 1253/1662] Use Bundled NETStandard.Library \ NETCoreApp versions instead of explicitly specifying one --- build/common.props | 2 +- build/dependencies.props | 4 +--- ...Microsoft.AspNetCore.Server.Kestrel.Performance.csproj | 8 +------- 3 files changed, 3 insertions(+), 11 deletions(-) diff --git a/build/common.props b/build/common.props index 1021ec36b4..e2f5702c6b 100644 --- a/build/common.props +++ b/build/common.props @@ -17,7 +17,7 @@ - + diff --git a/build/dependencies.props b/build/dependencies.props index 1c27397040..f80df326e7 100644 --- a/build/dependencies.props +++ b/build/dependencies.props @@ -8,9 +8,7 @@ 1.10.0-* 9.0.1 4.7.1 - 1.6.1 - 2.0.0-* 15.0.0 2.2.0 - \ No newline at end of file + diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Microsoft.AspNetCore.Server.Kestrel.Performance.csproj b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Microsoft.AspNetCore.Server.Kestrel.Performance.csproj index f75a837b72..54cd499106 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Microsoft.AspNetCore.Server.Kestrel.Performance.csproj +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Microsoft.AspNetCore.Server.Kestrel.Performance.csproj @@ -1,4 +1,4 @@ - + @@ -8,12 +8,6 @@ true true false - - - 2.0.0-* From eb1301f28d74a47ef657b1445c43f15037b26c4b Mon Sep 17 00:00:00 2001 From: Nate McMaster Date: Tue, 25 Apr 2017 14:33:06 -0700 Subject: [PATCH 1254/1662] Skip HostName binding test when network is unreachable --- .../AddressRegistrationTests.cs | 2 +- .../DnsIsReachableConditionAttribute.cs | 40 -------------- .../NetworkIsReachableAttribute.cs | 52 +++++++++++++++++++ 3 files changed, 53 insertions(+), 41 deletions(-) delete mode 100644 test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/TestHelpers/DnsIsReachableConditionAttribute.cs create mode 100644 test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/TestHelpers/NetworkIsReachableAttribute.cs diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs index 9d717d3935..abd6ec612c 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs @@ -34,7 +34,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests public AddressRegistrationTests(ITestOutputHelper output) => _logger = new LoggerFactory().AddXunit(output); [ConditionalFact] - [DnsHostNameIsResolvable] + [NetworkIsReachable] public async Task RegisterAddresses_HostName_Success() { var hostName = Dns.GetHostName(); diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/TestHelpers/DnsIsReachableConditionAttribute.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/TestHelpers/DnsIsReachableConditionAttribute.cs deleted file mode 100644 index 76bf6dfa41..0000000000 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/TestHelpers/DnsIsReachableConditionAttribute.cs +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using System.Linq; -using System.Net; -using Microsoft.AspNetCore.Testing.xunit; - -namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests -{ - [AttributeUsage(AttributeTargets.Method, AllowMultiple = false)] - public class DnsHostNameIsResolvableAttribute : Attribute, ITestCondition - { - private string _hostname; - - public bool IsMet - { - get - { - try - { - _hostname = Dns.GetHostName(); - var addresses = Dns.GetHostAddresses(_hostname); - if (addresses.Any(i => !IPAddress.IsLoopback(i))) - { - return true; - } - } - catch - { } - - return false; - } - } - - public string SkipReason => _hostname != null - ? $"Could not resolve any non-loopback IP address(es) for hostname '{_hostname}'" - : "Could not determine hostname for current test machine"; - } -} diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/TestHelpers/NetworkIsReachableAttribute.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/TestHelpers/NetworkIsReachableAttribute.cs new file mode 100644 index 0000000000..a17a321cba --- /dev/null +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/TestHelpers/NetworkIsReachableAttribute.cs @@ -0,0 +1,52 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Linq; +using System.Net; +using System.Net.Sockets; +using Microsoft.AspNetCore.Testing; +using Microsoft.AspNetCore.Testing.xunit; + +namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests +{ + [AttributeUsage(AttributeTargets.Method, AllowMultiple = false)] + public class NetworkIsReachableAttribute : Attribute, ITestCondition + { + private string _hostname; + private string _error; + + public bool IsMet + { + get + { + try + { + _hostname = Dns.GetHostName(); + + // if the network is unreachable on macOS, throws with SocketError.NetworkUnreachable + // if the network device is not configured, throws with SocketError.HostNotFound + // if the network is reachable, throws with SocketError.ConnectionRefused or succeeds + HttpClientSlim.GetStringAsync($"http://{_hostname}").GetAwaiter().GetResult(); + } + catch (SocketException ex) when ( + ex.SocketErrorCode == SocketError.NetworkUnreachable + || ex.SocketErrorCode == SocketError.HostNotFound) + { + _error = ex.Message; + return false; + } + catch + { + // Swallow other errors. Allows the test to throw the failures instead + } + + return true; + } + } + + public string SkipReason => _hostname != null + ? $"Test cannot run when network is unreachable. Socket exception: '{_error}'" + : "Could not determine hostname for current test machine"; + } +} From d9dad9400cf8b171166e76e9f0bc092f579f083d Mon Sep 17 00:00:00 2001 From: Pranav K Date: Tue, 25 Apr 2017 22:03:29 -0700 Subject: [PATCH 1255/1662] Branching for 2.0.0-preview1 --- NuGet.config | 4 ++-- build.ps1 | 2 +- build.sh | 2 +- build/dependencies.props | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/NuGet.config b/NuGet.config index 93f1ac47df..fa4304af9c 100644 --- a/NuGet.config +++ b/NuGet.config @@ -1,7 +1,7 @@ - + - + diff --git a/build.ps1 b/build.ps1 index 5bf0e2c113..225b1fe450 100644 --- a/build.ps1 +++ b/build.ps1 @@ -33,7 +33,7 @@ cd $PSScriptRoot $repoFolder = $PSScriptRoot $env:REPO_FOLDER = $repoFolder -$koreBuildZip="https://github.com/aspnet/KoreBuild/archive/dev.zip" +$koreBuildZip="https://github.com/aspnet/KoreBuild/archive/rel/2.0.0-preview1.zip" if ($env:KOREBUILD_ZIP) { $koreBuildZip=$env:KOREBUILD_ZIP diff --git a/build.sh b/build.sh index b0bcadb579..702b25c636 100755 --- a/build.sh +++ b/build.sh @@ -2,7 +2,7 @@ repoFolder="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" cd $repoFolder -koreBuildZip="https://github.com/aspnet/KoreBuild/archive/dev.zip" +koreBuildZip="https://github.com/aspnet/KoreBuild/archive/rel/2.0.0-preview1.zip" if [ ! -z $KOREBUILD_ZIP ]; then koreBuildZip=$KOREBUILD_ZIP fi diff --git a/build/dependencies.props b/build/dependencies.props index f80df326e7..baf2720bca 100644 --- a/build/dependencies.props +++ b/build/dependencies.props @@ -1,6 +1,6 @@ - 2.0.0-* + 2.0.0-preview1-* 0.1.0-* 0.1.0-* 4.3.0 From 099f8f1a479804aac2c68cd9a4f00259af0f9ece Mon Sep 17 00:00:00 2001 From: Pranav K Date: Wed, 26 Apr 2017 07:13:10 -0700 Subject: [PATCH 1256/1662] Updating package version to preview2 --- version.props | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version.props b/version.props index e5b7eb2dbe..f29a32b5bf 100644 --- a/version.props +++ b/version.props @@ -2,6 +2,6 @@ 2.0.0 - preview1 + preview2 From 9464003bdadc00efe618c1b97c50d274325ad33f Mon Sep 17 00:00:00 2001 From: Nate McMaster Date: Tue, 25 Apr 2017 15:53:30 -0700 Subject: [PATCH 1257/1662] Add wait in ListenerPrimaryTests to avoid race condition with List.Add --- .../Internal/ListenerPrimary.cs | 5 +++++ .../ListenerPrimaryTests.cs | 12 ++++++++++++ 2 files changed, 17 insertions(+) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/ListenerPrimary.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/ListenerPrimary.cs index 45145aadc5..2b0fd8b039 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/ListenerPrimary.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/ListenerPrimary.cs @@ -33,6 +33,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal { } + /// + /// For testing purposes. + /// + public int UvPipeCount => _dispatchPipes.Count; + private UvPipeHandle ListenPipe { get; set; } public async Task StartAsync( diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/ListenerPrimaryTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/ListenerPrimaryTests.cs index 0c9d5b52be..0edcfd37f5 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/ListenerPrimaryTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/ListenerPrimaryTests.cs @@ -53,12 +53,24 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests Assert.Equal("Primary", await HttpClientSlim.GetStringAsync(address)); Assert.Equal("Primary", await HttpClientSlim.GetStringAsync(address)); + var listenerCount = listenerPrimary.UvPipeCount; // Add secondary listener var libuvThreadSecondary = new LibuvThread(libuvTransport); await libuvThreadSecondary.StartAsync(); var listenerSecondary = new ListenerSecondary(transportContextSecondary); await listenerSecondary.StartAsync(pipeName, pipeMessage, listenOptions, libuvThreadSecondary); + var maxWait = Task.Delay(TimeSpan.FromSeconds(30)); + // wait for ListenerPrimary.ReadCallback to add the secondary pipe + while (listenerPrimary.UvPipeCount == listenerCount) + { + var completed = await Task.WhenAny(maxWait, Task.Delay(100)); + if (ReferenceEquals(completed, maxWait)) + { + throw new TimeoutException("Timed out waiting for secondary listener to become available"); + } + } + // Once a secondary listener is added, TCP connections start getting dispatched to it await AssertResponseEventually(address, "Secondary", allowed: new[] { "Primary" }); From 1a26dc02389aa4c3717f253a89dd3f6fc47ee6b4 Mon Sep 17 00:00:00 2001 From: BrennanConroy Date: Wed, 26 Apr 2017 13:44:55 -0700 Subject: [PATCH 1258/1662] React to Logging API changes (#1775) React to Logging API changes --- samples/SampleApp/Startup.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/samples/SampleApp/Startup.cs b/samples/SampleApp/Startup.cs index 6c776817c1..2bfe60835a 100644 --- a/samples/SampleApp/Startup.cs +++ b/samples/SampleApp/Startup.cs @@ -17,7 +17,6 @@ namespace SampleApp { public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory) { - loggerFactory.AddConsole(LogLevel.Trace); var logger = loggerFactory.CreateLogger("Default"); app.Run(async context => @@ -42,6 +41,10 @@ namespace SampleApp }; var host = new WebHostBuilder() + .ConfigureLogging((_, factory) => + { + factory.AddConsole(); + }) .UseKestrel(options => { // Run callbacks on the transport thread From c2f15fcac374328d8256b8345bfb5eb22e8add75 Mon Sep 17 00:00:00 2001 From: Nate McMaster Date: Wed, 26 Apr 2017 17:22:55 -0700 Subject: [PATCH 1259/1662] Move user-facing strings into resource files --- .../BadHttpRequestException.cs | 60 +- .../CoreStrings.resx | 183 ++++ .../Internal/AddressBinder.cs | 22 +- .../Internal/Http/Frame.cs | 14 +- .../Internal/Http/FrameHeaders.cs | 8 +- .../Internal/Http/FrameOfT.cs | 4 +- .../Internal/Http/FrameRequestStream.cs | 2 +- .../Internal/Http/FrameResponseHeaders.cs | 2 +- ...rameConnectionManagerShutdownExtensions.cs | 4 +- .../KestrelServer.cs | 10 +- .../KestrelServerLimits.cs | 10 +- .../KestrelServerOptions.cs | 2 +- .../Properties/CoreStrings.Designer.cs | 854 ++++++++++++++++++ .../ServerAddress.cs | 4 +- .../HttpsConnectionAdapter.cs | 5 +- .../HttpsStrings.resx | 126 +++ ...oft.AspNetCore.Server.Kestrel.Https.csproj | 6 + .../Properties/HttpsStrings.Designer.cs | 58 ++ ...re.Server.Kestrel.Transport.Sockets.csproj | 6 + .../Properties/SocketsStrings.Designer.cs | 58 ++ .../SocketTransport.cs | 2 +- .../SocketTransportFactory.cs | 2 +- .../SocketsStrings.resx | 126 +++ .../FrameResponseHeadersTests.cs | 7 +- .../FrameTests.cs | 20 +- .../HttpParserTests.cs | 10 +- .../KestrelServerTests.cs | 5 +- .../MessageBodyTests.cs | 6 +- .../AddressRegistrationTests.cs | 26 +- .../BadHttpRequestTests.cs | 24 +- test/shared/HttpParsingData.cs | 117 +-- 31 files changed, 1592 insertions(+), 191 deletions(-) create mode 100644 src/Microsoft.AspNetCore.Server.Kestrel.Https/HttpsStrings.resx create mode 100644 src/Microsoft.AspNetCore.Server.Kestrel.Https/Properties/HttpsStrings.Designer.cs create mode 100644 src/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets/Properties/SocketsStrings.Designer.cs create mode 100644 src/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets/SocketsStrings.resx diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/BadHttpRequestException.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/BadHttpRequestException.cs index c7d2e69042..034465d212 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/BadHttpRequestException.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/BadHttpRequestException.cs @@ -36,64 +36,64 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core switch (reason) { case RequestRejectionReason.InvalidRequestHeadersNoCRLF: - ex = new BadHttpRequestException("Invalid request headers: missing final CRLF in header fields.", StatusCodes.Status400BadRequest); + ex = new BadHttpRequestException(CoreStrings.BadRequest_InvalidRequestHeadersNoCRLF, StatusCodes.Status400BadRequest); break; case RequestRejectionReason.InvalidRequestLine: - ex = new BadHttpRequestException("Invalid request line.", StatusCodes.Status400BadRequest); + ex = new BadHttpRequestException(CoreStrings.BadRequest_InvalidRequestLine, StatusCodes.Status400BadRequest); break; case RequestRejectionReason.MalformedRequestInvalidHeaders: - ex = new BadHttpRequestException("Malformed request: invalid headers.", StatusCodes.Status400BadRequest); + ex = new BadHttpRequestException(CoreStrings.BadRequest_MalformedRequestInvalidHeaders, StatusCodes.Status400BadRequest); break; case RequestRejectionReason.MultipleContentLengths: - ex = new BadHttpRequestException("Multiple Content-Length headers.", StatusCodes.Status400BadRequest); + ex = new BadHttpRequestException(CoreStrings.BadRequest_MultipleContentLengths, StatusCodes.Status400BadRequest); break; case RequestRejectionReason.UnexpectedEndOfRequestContent: - ex = new BadHttpRequestException("Unexpected end of request content.", StatusCodes.Status400BadRequest); + ex = new BadHttpRequestException(CoreStrings.BadRequest_UnexpectedEndOfRequestContent, StatusCodes.Status400BadRequest); break; case RequestRejectionReason.BadChunkSuffix: - ex = new BadHttpRequestException("Bad chunk suffix.", StatusCodes.Status400BadRequest); + ex = new BadHttpRequestException(CoreStrings.BadRequest_BadChunkSuffix, StatusCodes.Status400BadRequest); break; case RequestRejectionReason.BadChunkSizeData: - ex = new BadHttpRequestException("Bad chunk size data.", StatusCodes.Status400BadRequest); + ex = new BadHttpRequestException(CoreStrings.BadRequest_BadChunkSizeData, StatusCodes.Status400BadRequest); break; case RequestRejectionReason.ChunkedRequestIncomplete: - ex = new BadHttpRequestException("Chunked request incomplete.", StatusCodes.Status400BadRequest); + ex = new BadHttpRequestException(CoreStrings.BadRequest_ChunkedRequestIncomplete, StatusCodes.Status400BadRequest); break; case RequestRejectionReason.InvalidCharactersInHeaderName: - ex = new BadHttpRequestException("Invalid characters in header name.", StatusCodes.Status400BadRequest); + ex = new BadHttpRequestException(CoreStrings.BadRequest_InvalidCharactersInHeaderName, StatusCodes.Status400BadRequest); break; case RequestRejectionReason.RequestLineTooLong: - ex = new BadHttpRequestException("Request line too long.", StatusCodes.Status414UriTooLong); + ex = new BadHttpRequestException(CoreStrings.BadRequest_RequestLineTooLong, StatusCodes.Status414UriTooLong); break; case RequestRejectionReason.HeadersExceedMaxTotalSize: - ex = new BadHttpRequestException("Request headers too long.", StatusCodes.Status431RequestHeaderFieldsTooLarge); + ex = new BadHttpRequestException(CoreStrings.BadRequest_HeadersExceedMaxTotalSize, StatusCodes.Status431RequestHeaderFieldsTooLarge); break; case RequestRejectionReason.TooManyHeaders: - ex = new BadHttpRequestException("Request contains too many headers.", StatusCodes.Status431RequestHeaderFieldsTooLarge); + ex = new BadHttpRequestException(CoreStrings.BadRequest_TooManyHeaders, StatusCodes.Status431RequestHeaderFieldsTooLarge); break; case RequestRejectionReason.RequestTimeout: - ex = new BadHttpRequestException("Request timed out.", StatusCodes.Status408RequestTimeout); + ex = new BadHttpRequestException(CoreStrings.BadRequest_RequestTimeout, StatusCodes.Status408RequestTimeout); break; case RequestRejectionReason.OptionsMethodRequired: - ex = new BadHttpRequestException("Method not allowed.", StatusCodes.Status405MethodNotAllowed, HttpMethod.Options); + ex = new BadHttpRequestException(CoreStrings.BadRequest_MethodNotAllowed, StatusCodes.Status405MethodNotAllowed, HttpMethod.Options); break; case RequestRejectionReason.ConnectMethodRequired: - ex = new BadHttpRequestException("Method not allowed.", StatusCodes.Status405MethodNotAllowed, HttpMethod.Connect); + ex = new BadHttpRequestException(CoreStrings.BadRequest_MethodNotAllowed, StatusCodes.Status405MethodNotAllowed, HttpMethod.Connect); break; case RequestRejectionReason.MissingHostHeader: - ex = new BadHttpRequestException("Request is missing Host header.", StatusCodes.Status400BadRequest); + ex = new BadHttpRequestException(CoreStrings.BadRequest_MissingHostHeader, StatusCodes.Status400BadRequest); break; case RequestRejectionReason.MultipleHostHeaders: - ex = new BadHttpRequestException("Multiple Host headers.", StatusCodes.Status400BadRequest); + ex = new BadHttpRequestException(CoreStrings.BadRequest_MultipleHostHeaders, StatusCodes.Status400BadRequest); break; case RequestRejectionReason.InvalidHostHeader: - ex = new BadHttpRequestException("Invalid Host header.", StatusCodes.Status400BadRequest); + ex = new BadHttpRequestException(CoreStrings.BadRequest_InvalidHostHeader, StatusCodes.Status400BadRequest); break; case RequestRejectionReason.UpgradeRequestCannotHavePayload: - ex = new BadHttpRequestException("Requests with 'Connection: Upgrade' cannot have content in the request body.", StatusCodes.Status400BadRequest); + ex = new BadHttpRequestException(CoreStrings.BadRequest_UpgradeRequestCannotHavePayload, StatusCodes.Status400BadRequest); break; default: - ex = new BadHttpRequestException("Bad request.", StatusCodes.Status400BadRequest); + ex = new BadHttpRequestException(CoreStrings.BadRequest, StatusCodes.Status400BadRequest); break; } return ex; @@ -105,34 +105,34 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core switch (reason) { case RequestRejectionReason.InvalidRequestLine: - ex = new BadHttpRequestException($"Invalid request line: '{detail}'", StatusCodes.Status400BadRequest); + ex = new BadHttpRequestException(CoreStrings.FormatBadRequest_InvalidRequestLine_Detail(detail), StatusCodes.Status400BadRequest); break; case RequestRejectionReason.InvalidRequestTarget: - ex = new BadHttpRequestException($"Invalid request target: '{detail}'", StatusCodes.Status400BadRequest); + ex = new BadHttpRequestException(CoreStrings.FormatBadRequest_InvalidRequestTarget_Detail(detail), StatusCodes.Status400BadRequest); break; case RequestRejectionReason.InvalidRequestHeader: - ex = new BadHttpRequestException($"Invalid request header: '{detail}'", StatusCodes.Status400BadRequest); + ex = new BadHttpRequestException(CoreStrings.FormatBadRequest_InvalidRequestHeader_Detail(detail), StatusCodes.Status400BadRequest); break; case RequestRejectionReason.InvalidContentLength: - ex = new BadHttpRequestException($"Invalid content length: {detail}", StatusCodes.Status400BadRequest); + ex = new BadHttpRequestException(CoreStrings.FormatBadRequest_InvalidContentLength_Detail(detail), StatusCodes.Status400BadRequest); break; case RequestRejectionReason.UnrecognizedHTTPVersion: - ex = new BadHttpRequestException($"Unrecognized HTTP version: '{detail}'", StatusCodes.Status505HttpVersionNotsupported); + ex = new BadHttpRequestException(CoreStrings.FormatBadRequest_UnrecognizedHTTPVersion(detail), StatusCodes.Status505HttpVersionNotsupported); break; case RequestRejectionReason.FinalTransferCodingNotChunked: - ex = new BadHttpRequestException($"Final transfer coding is not \"chunked\": \"{detail}\"", StatusCodes.Status400BadRequest); + ex = new BadHttpRequestException(CoreStrings.FormatBadRequest_FinalTransferCodingNotChunked(detail), StatusCodes.Status400BadRequest); break; case RequestRejectionReason.LengthRequired: - ex = new BadHttpRequestException($"{detail} request contains no Content-Length or Transfer-Encoding header", StatusCodes.Status411LengthRequired); + ex = new BadHttpRequestException(CoreStrings.FormatBadRequest_LengthRequired(detail), StatusCodes.Status411LengthRequired); break; case RequestRejectionReason.LengthRequiredHttp10: - ex = new BadHttpRequestException($"{detail} request contains no Content-Length header", StatusCodes.Status400BadRequest); + ex = new BadHttpRequestException(CoreStrings.FormatBadRequest_LengthRequiredHttp10(detail), StatusCodes.Status400BadRequest); break; case RequestRejectionReason.InvalidHostHeader: - ex = new BadHttpRequestException($"Invalid Host header: '{detail}'", StatusCodes.Status400BadRequest); + ex = new BadHttpRequestException(CoreStrings.FormatBadRequest_InvalidHostHeader_Detail(detail), StatusCodes.Status400BadRequest); break; default: - ex = new BadHttpRequestException("Bad request.", StatusCodes.Status400BadRequest); + ex = new BadHttpRequestException(CoreStrings.BadRequest, StatusCodes.Status400BadRequest); break; } return ex; diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/CoreStrings.resx b/src/Microsoft.AspNetCore.Server.Kestrel.Core/CoreStrings.resx index 03a86be5db..e85918600f 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/CoreStrings.resx +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/CoreStrings.resx @@ -117,10 +117,193 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + Bad request. + + + Bad chunk size data. + + + Bad chunk suffix. + + + Chunked request incomplete. + + + The message body length cannot be determined because the final transfer coding was set to '{detail}' instead of 'chunked'. + + + Request headers too long. + + + Invalid characters in header name. + + + Invalid content length: {detail} + + + Invalid Host header. + + + Invalid Host header: '{detail}' + + + Invalid request headers: missing final CRLF in header fields. + + + Invalid request header: '{detail}' + + + Invalid request line. + + + Invalid request line: '{detail}' + + + Invalid request target: '{detail}' + + + {detail} request contains no Content-Length or Transfer-Encoding header. + + + {detail} request contains no Content-Length header. + + + Malformed request: invalid headers. + + + Method not allowed. + + + Request is missing Host header. + + + Multiple Content-Length headers. + + + Multiple Host headers. + + + Request line too long. + + + Request timed out. + + + Request contains too many headers. + + + Unexpected end of request content. + + + Unrecognized HTTP version: '{detail}' + + + Requests with 'Connection: Upgrade' cannot have content in the request body. + Failed to bind to http://[::]:{port} (IPv6Any). Attempting to bind to http://0.0.0.0:{port} instead. Cannot write to response body after connection has been upgraded. + + Kestrel does not support big-endian architectures. + + + Maximum request buffer size ({requestBufferSize}) must be greater than or equal to maximum request header size ({requestHeaderSize}). + + + Maximum request buffer size ({requestBufferSize}) must be greater than or equal to maximum request line size ({requestLineSize}). + + + Server has already started. + + + Unknown transport mode: '{mode}'. + + + Invalid non-ASCII or control character in header: {character} + + + Invalid Content-Length: "{value}". Value must be a positive integral number. + + + Value must be null or a non-negative integer. + + + Value must be a positive integer. + + + Value must be null or a positive integer. + + + Unix socket path must be absolute. + + + Failed to bind to address {address}. + + + No listening endpoints were configured. Binding to {address} by default. + + + HTTPS endpoints can only be configured using {methodName}. + + + A path base can only be configured using {methodName}. + + + Dynamic port binding is not supported when binding to localhost. You must either bind to 127.0.0.1:0 or [::1]:0, or both. + + + Failed to bind to address {endpoint}: address already in use. + + + Invalid URL: '{url}'. + + + Unable to bind to {address} on the {interfaceName} interface: '{error}'. + + + Overriding address(es) '{addresses}'. Binding to endpoints defined in {methodName} instead. + + + Overriding endpoints defined in UseKestrel() because {settingName} is set to true. Binding to address(es) '{addresses}' instead. + + + Unrecognized scheme in server address '{address}'. Only 'http://' is supported. + + + Headers are read-only, response has already started. + + + An item with the same key has already been added. + + + Setting the header {name} is not allowed on responses with status code {statusCode}. + + + {name} cannot be set because the response has already started. + + + Request processing didn't complete within the shutdown timeout. + + + Response Content-Length mismatch: too few bytes written ({written} of {expected}). + + + Response Content-Length mismatch: too many bytes written ({written} of {expected}). + + + The response has been aborted due to an unhandled application exception. + + + Writing to the response body is invalid for responses with status code {statusCode}. + + + Connection shutdown abnormally. + + + Connection processing ended abnormally. + \ No newline at end of file diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/AddressBinder.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/AddressBinder.cs index d041c3bec0..b8a34d69f5 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/AddressBinder.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/AddressBinder.cs @@ -114,7 +114,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal } catch (AddressInUseException ex) { - throw new IOException($"Failed to bind to address {endpoint}: address already in use.", ex); + throw new IOException(CoreStrings.FormatEndpointAlreadyInUse(endpoint), ex); } context.ListenOptions.Add(endpoint); @@ -124,7 +124,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal { if (address.Port == 0) { - throw new InvalidOperationException("Dynamic port binding is not supported when binding to localhost. You must either bind to 127.0.0.1:0 or [::1]:0, or both."); + throw new InvalidOperationException(CoreStrings.DynamicPortOnLocalhostNotSupported); } var exceptions = new List(); @@ -135,7 +135,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal } catch (Exception ex) when (!(ex is IOException)) { - context.Logger.LogWarning(0, $"Unable to bind to {address} on the IPv4 loopback interface: ({ex.Message})"); + context.Logger.LogWarning(0, CoreStrings.NetworkInterfaceBindingFailed, address, "IPv4 loopback", ex.Message); exceptions.Add(ex); } @@ -145,13 +145,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal } catch (Exception ex) when (!(ex is IOException)) { - context.Logger.LogWarning(0, $"Unable to bind to {address} on the IPv6 loopback interface: ({ex.Message})"); + context.Logger.LogWarning(0, CoreStrings.NetworkInterfaceBindingFailed, address, "IPv6 loopback", ex.Message); exceptions.Add(ex); } if (exceptions.Count == 2) { - throw new IOException($"Failed to bind to address {address}.", new AggregateException(exceptions)); + throw new IOException(CoreStrings.FormatAddressBindingFailed(address), new AggregateException(exceptions)); } // If StartLocalhost doesn't throw, there is at least one listener. @@ -165,16 +165,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal if (parsedAddress.Scheme.Equals("https", StringComparison.OrdinalIgnoreCase)) { - throw new InvalidOperationException($"HTTPS endpoints can only be configured using {nameof(KestrelServerOptions)}.{nameof(KestrelServerOptions.Listen)}()."); + throw new InvalidOperationException(CoreStrings.FormatConfigureHttpsFromMethodCall($"{nameof(KestrelServerOptions)}.{nameof(KestrelServerOptions.Listen)}()")); } else if (!parsedAddress.Scheme.Equals("http", StringComparison.OrdinalIgnoreCase)) { - throw new InvalidOperationException($"Unrecognized scheme in server address '{address}'. Only 'http://' is supported."); + throw new InvalidOperationException(CoreStrings.FormatUnsupportedAddressScheme(address)); } if (!string.IsNullOrEmpty(parsedAddress.PathBase)) { - throw new InvalidOperationException($"A path base can only be configured using {nameof(IApplicationBuilder)}.UsePathBase()."); + throw new InvalidOperationException(CoreStrings.FormatConfigurePathBaseFromMethodCall($"{nameof(IApplicationBuilder)}.UsePathBase()")); } if (parsedAddress.IsUnixPipe) @@ -227,7 +227,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal { public async Task BindAsync(AddressBindContext context) { - context.Logger.LogDebug($"No listening endpoints were configured. Binding to {Constants.DefaultServerAddress} by default."); + context.Logger.LogDebug(CoreStrings.BindingToDefaultAddress, Constants.DefaultServerAddress); await BindLocalhostAsync(ServerAddress.FromUrl(Constants.DefaultServerAddress), context).ConfigureAwait(false); } @@ -243,7 +243,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal public override Task BindAsync(AddressBindContext context) { var joined = string.Join(", ", _addresses); - context.Logger.LogInformation($"Overriding endpoints defined in UseKestrel() since {nameof(IServerAddressesFeature.PreferHostingUrls)} is set to true. Binding to address(es) '{joined}' instead."); + context.Logger.LogInformation(CoreStrings.OverridingWithPreferHostingUrls, nameof(IServerAddressesFeature.PreferHostingUrls), joined); return base.BindAsync(context); } @@ -262,7 +262,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal public override Task BindAsync(AddressBindContext context) { var joined = string.Join(", ", _originalAddresses); - context.Logger.LogWarning($"Overriding address(es) {joined}. Binding to endpoints defined in UseKestrel() instead."); + context.Logger.LogWarning(CoreStrings.OverridingWithKestrelOptions, joined, "UseKestrel()"); return base.BindAsync(context); } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.cs index a63fec9407..01ae9a5c81 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.cs @@ -661,7 +661,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { _keepAlive = false; throw new InvalidOperationException( - $"Response Content-Length mismatch: too many bytes written ({_responseBytesWritten + count} of {responseHeaders.ContentLength.Value})."); + CoreStrings.FormatTooManyBytesWritten(_responseBytesWritten + count, responseHeaders.ContentLength.Value)); } _responseBytesWritten += count; @@ -702,7 +702,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http } ReportApplicationError(new InvalidOperationException( - $"Response Content-Length mismatch: too few bytes written ({_responseBytesWritten} of {responseHeaders.ContentLength.Value}).")); + CoreStrings.FormatTooFewBytesWritten(_responseBytesWritten, responseHeaders.ContentLength.Value))); } } @@ -1081,12 +1081,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http private void ThrowResponseAlreadyStartedException(string value) { - throw new InvalidOperationException($"{value} cannot be set, response has already started."); + throw new InvalidOperationException(CoreStrings.FormatParameterReadOnlyAfterResponseStarted(value)); } private void RejectNonBodyTransferEncodingResponse(bool appCompleted) { - var ex = new InvalidOperationException($"Transfer-Encoding set on a {StatusCode} non-body request."); + var ex = new InvalidOperationException(CoreStrings.FormatHeaderNotAllowedOnResponse("Transfer-Encoding", StatusCode)); if (!appCompleted) { // Back out of header creation surface exeception in user code @@ -1143,15 +1143,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http if (Method != "HEAD") { // Throw Exception for 204, 205, 304 responses. - throw new InvalidOperationException($"Write to non-body {StatusCode} response."); + throw new InvalidOperationException(CoreStrings.FormatWritingToResponseBodyNotSupported(StatusCode)); } } private void ThrowResponseAbortedException() { - throw new ObjectDisposedException( - "The response has been aborted due to an unhandled application exception.", - _applicationException); + throw new ObjectDisposedException(CoreStrings.UnhandledApplicationException, _applicationException); } public void RejectRequest(RequestRejectionReason reason) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameHeaders.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameHeaders.cs index 2432afa6a3..7331ceeadf 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameHeaders.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameHeaders.cs @@ -69,7 +69,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http protected void ThrowHeadersReadOnlyException() { - throw new InvalidOperationException("Headers are read-only, response has already started."); + throw new InvalidOperationException(CoreStrings.HeadersAreReadOnly); } protected void ThrowArgumentException() @@ -84,7 +84,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http protected void ThrowDuplicateKeyException() { - throw new ArgumentException("An item with the same key has already been added."); + throw new ArgumentException(CoreStrings.KeyAlreadyExists); } int ICollection>.Count => GetCountFast(); @@ -426,12 +426,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http private static void ThrowInvalidContentLengthException(long value) { - throw new ArgumentOutOfRangeException($"Invalid Content-Length: \"{value}\". Value must be a positive integral number."); + throw new ArgumentOutOfRangeException(CoreStrings.FormatInvalidContentLength_InvalidNumber(value)); } private static void ThrowInvalidHeaderCharacter(char ch) { - throw new InvalidOperationException(string.Format("Invalid non-ASCII or control character in header: 0x{0:X4}", (ushort)ch)); + throw new InvalidOperationException(CoreStrings.FormatInvalidAsciiOrControlChar(string.Format("0x{0:X4}", (ushort)ch))); } } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameOfT.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameOfT.cs index b95a42c6a8..fce5bcae6c 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameOfT.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameOfT.cs @@ -227,7 +227,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http } catch (Exception ex) { - Log.LogWarning(0, ex, "Connection processing ended abnormally"); + Log.LogWarning(0, ex, CoreStrings.RequestProcessingEndError); } finally { @@ -243,7 +243,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http } catch (Exception ex) { - Log.LogWarning(0, ex, "Connection shutdown abnormally"); + Log.LogWarning(0, ex, CoreStrings.ConnectionShutdownError); } } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameRequestStream.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameRequestStream.cs index 35bbf73302..f7a92e37a0 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameRequestStream.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameRequestStream.cs @@ -120,7 +120,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http } if (bufferSize <= 0) { - throw new ArgumentException($"{nameof(bufferSize)} must be positive.", nameof(bufferSize)); + throw new ArgumentException(CoreStrings.PositiveIntRequired, nameof(bufferSize)); } var task = ValidateState(cancellationToken); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameResponseHeaders.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameResponseHeaders.cs index f5093f691f..6409f372db 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameResponseHeaders.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameResponseHeaders.cs @@ -75,7 +75,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http private static void ThrowInvalidContentLengthException(string value) { - throw new InvalidOperationException($"Invalid Content-Length: \"{value}\". Value must be a positive integral number."); + throw new InvalidOperationException(CoreStrings.FormatInvalidContentLength_InvalidNumber(value)); } public partial struct Enumerator : IEnumerator> diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/FrameConnectionManagerShutdownExtensions.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/FrameConnectionManagerShutdownExtensions.cs index 7bbd1f1ca7..88aae5e6c7 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/FrameConnectionManagerShutdownExtensions.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/FrameConnectionManagerShutdownExtensions.cs @@ -1,9 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System; using System.Collections.Generic; -using System.Text; using System.Threading; using System.Threading.Tasks; @@ -27,7 +25,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure public static async Task AbortAllConnectionsAsync(this FrameConnectionManager connectionManager) { var abortTasks = new List(); - var canceledException = new TaskCanceledException("Request processing didn't complete within the shutdown timeout."); + var canceledException = new TaskCanceledException(CoreStrings.RequestProcessingAborted); connectionManager.Walk(connection => { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/KestrelServer.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/KestrelServer.cs index b325ab723a..8d1c26f453 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/KestrelServer.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/KestrelServer.cs @@ -85,7 +85,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core threadPool = new InlineLoggingThreadPool(trace); break; default: - throw new NotSupportedException($"Unknown transport mode {serverOptions.ApplicationSchedulingMode}"); + throw new NotSupportedException(CoreStrings.FormatUnknownTransportMode(serverOptions.ApplicationSchedulingMode)); } return new ServiceContext @@ -116,7 +116,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core { if (!BitConverter.IsLittleEndian) { - throw new PlatformNotSupportedException("Kestrel does not support big-endian architectures."); + throw new PlatformNotSupportedException(CoreStrings.BigEndianNotSupported); } ValidateOptions(); @@ -124,7 +124,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core if (_hasStarted) { // The server has already started and/or has not been cleaned up yet - throw new InvalidOperationException("Server has already started."); + throw new InvalidOperationException(CoreStrings.ServerAlreadyStarted); } _hasStarted = true; _heartbeat.Start(); @@ -196,14 +196,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core Options.Limits.MaxRequestBufferSize < Options.Limits.MaxRequestLineSize) { throw new InvalidOperationException( - $"Maximum request buffer size ({Options.Limits.MaxRequestBufferSize.Value}) must be greater than or equal to maximum request line size ({Options.Limits.MaxRequestLineSize})."); + CoreStrings.FormatMaxRequestBufferSmallerThanRequestLineBuffer(Options.Limits.MaxRequestBufferSize.Value, Options.Limits.MaxRequestLineSize)); } if (Options.Limits.MaxRequestBufferSize.HasValue && Options.Limits.MaxRequestBufferSize < Options.Limits.MaxRequestHeadersTotalSize) { throw new InvalidOperationException( - $"Maximum request buffer size ({Options.Limits.MaxRequestBufferSize.Value}) must be greater than or equal to maximum request headers size ({Options.Limits.MaxRequestHeadersTotalSize})."); + CoreStrings.FormatMaxRequestBufferSmallerThanRequestHeaderBuffer(Options.Limits.MaxRequestBufferSize.Value, Options.Limits.MaxRequestHeadersTotalSize)); } } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/KestrelServerLimits.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/KestrelServerLimits.cs index b42d2db6a9..9ed2293b6b 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/KestrelServerLimits.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/KestrelServerLimits.cs @@ -49,7 +49,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core { if (value.HasValue && value.Value < 0) { - throw new ArgumentOutOfRangeException(nameof(value), "Value must be null or a non-negative integer."); + throw new ArgumentOutOfRangeException(nameof(value), CoreStrings.NonNegativeNullableIntRequired); } _maxResponseBufferSize = value; } @@ -72,7 +72,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core { if (value.HasValue && value.Value <= 0) { - throw new ArgumentOutOfRangeException(nameof(value), "Value must be null or a positive integer."); + throw new ArgumentOutOfRangeException(nameof(value), CoreStrings.PositiveNullableIntRequired); } _maxRequestBufferSize = value; } @@ -94,7 +94,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core { if (value <= 0) { - throw new ArgumentOutOfRangeException(nameof(value), "Value must be a positive integer."); + throw new ArgumentOutOfRangeException(nameof(value), CoreStrings.PositiveIntRequired); } _maxRequestLineSize = value; } @@ -116,7 +116,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core { if (value <= 0) { - throw new ArgumentOutOfRangeException(nameof(value), "Value must a positive integer."); + throw new ArgumentOutOfRangeException(nameof(value), CoreStrings.PositiveIntRequired); } _maxRequestHeadersTotalSize = value; } @@ -138,7 +138,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core { if (value <= 0) { - throw new ArgumentOutOfRangeException(nameof(value), "Value must a positive integer."); + throw new ArgumentOutOfRangeException(nameof(value), CoreStrings.PositiveIntRequired); } _maxRequestHeaderCount = value; } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/KestrelServerOptions.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/KestrelServerOptions.cs index f97e5c3dd3..1f4301418a 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/KestrelServerOptions.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/KestrelServerOptions.cs @@ -121,7 +121,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core } if (socketPath.Length == 0 || socketPath[0] != '/') { - throw new ArgumentException("Unix socket path must be absolute.", nameof(socketPath)); + throw new ArgumentException(CoreStrings.UnixSocketPathMustBeAbsolute, nameof(socketPath)); } if (configure == null) { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Properties/CoreStrings.Designer.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Properties/CoreStrings.Designer.cs index c97aefeac9..1a86007def 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Properties/CoreStrings.Designer.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Properties/CoreStrings.Designer.cs @@ -10,6 +10,398 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core private static readonly ResourceManager _resourceManager = new ResourceManager("Microsoft.AspNetCore.Server.Kestrel.Core.CoreStrings", typeof(CoreStrings).GetTypeInfo().Assembly); + /// + /// Bad request. + /// + internal static string BadRequest + { + get => GetString("BadRequest"); + } + + /// + /// Bad request. + /// + internal static string FormatBadRequest() + => GetString("BadRequest"); + + /// + /// Bad chunk size data. + /// + internal static string BadRequest_BadChunkSizeData + { + get => GetString("BadRequest_BadChunkSizeData"); + } + + /// + /// Bad chunk size data. + /// + internal static string FormatBadRequest_BadChunkSizeData() + => GetString("BadRequest_BadChunkSizeData"); + + /// + /// Bad chunk suffix. + /// + internal static string BadRequest_BadChunkSuffix + { + get => GetString("BadRequest_BadChunkSuffix"); + } + + /// + /// Bad chunk suffix. + /// + internal static string FormatBadRequest_BadChunkSuffix() + => GetString("BadRequest_BadChunkSuffix"); + + /// + /// Chunked request incomplete. + /// + internal static string BadRequest_ChunkedRequestIncomplete + { + get => GetString("BadRequest_ChunkedRequestIncomplete"); + } + + /// + /// Chunked request incomplete. + /// + internal static string FormatBadRequest_ChunkedRequestIncomplete() + => GetString("BadRequest_ChunkedRequestIncomplete"); + + /// + /// The message body length cannot be determined because the final transfer coding was set to '{detail}' instead of 'chunked'. + /// + internal static string BadRequest_FinalTransferCodingNotChunked + { + get => GetString("BadRequest_FinalTransferCodingNotChunked"); + } + + /// + /// The message body length cannot be determined because the final transfer coding was set to '{detail}' instead of 'chunked'. + /// + internal static string FormatBadRequest_FinalTransferCodingNotChunked(object detail) + => string.Format(CultureInfo.CurrentCulture, GetString("BadRequest_FinalTransferCodingNotChunked", "detail"), detail); + + /// + /// Request headers too long. + /// + internal static string BadRequest_HeadersExceedMaxTotalSize + { + get => GetString("BadRequest_HeadersExceedMaxTotalSize"); + } + + /// + /// Request headers too long. + /// + internal static string FormatBadRequest_HeadersExceedMaxTotalSize() + => GetString("BadRequest_HeadersExceedMaxTotalSize"); + + /// + /// Invalid characters in header name. + /// + internal static string BadRequest_InvalidCharactersInHeaderName + { + get => GetString("BadRequest_InvalidCharactersInHeaderName"); + } + + /// + /// Invalid characters in header name. + /// + internal static string FormatBadRequest_InvalidCharactersInHeaderName() + => GetString("BadRequest_InvalidCharactersInHeaderName"); + + /// + /// Invalid content length: {detail} + /// + internal static string BadRequest_InvalidContentLength_Detail + { + get => GetString("BadRequest_InvalidContentLength_Detail"); + } + + /// + /// Invalid content length: {detail} + /// + internal static string FormatBadRequest_InvalidContentLength_Detail(object detail) + => string.Format(CultureInfo.CurrentCulture, GetString("BadRequest_InvalidContentLength_Detail", "detail"), detail); + + /// + /// Invalid Host header. + /// + internal static string BadRequest_InvalidHostHeader + { + get => GetString("BadRequest_InvalidHostHeader"); + } + + /// + /// Invalid Host header. + /// + internal static string FormatBadRequest_InvalidHostHeader() + => GetString("BadRequest_InvalidHostHeader"); + + /// + /// Invalid Host header: '{detail}' + /// + internal static string BadRequest_InvalidHostHeader_Detail + { + get => GetString("BadRequest_InvalidHostHeader_Detail"); + } + + /// + /// Invalid Host header: '{detail}' + /// + internal static string FormatBadRequest_InvalidHostHeader_Detail(object detail) + => string.Format(CultureInfo.CurrentCulture, GetString("BadRequest_InvalidHostHeader_Detail", "detail"), detail); + + /// + /// Invalid request headers: missing final CRLF in header fields. + /// + internal static string BadRequest_InvalidRequestHeadersNoCRLF + { + get => GetString("BadRequest_InvalidRequestHeadersNoCRLF"); + } + + /// + /// Invalid request headers: missing final CRLF in header fields. + /// + internal static string FormatBadRequest_InvalidRequestHeadersNoCRLF() + => GetString("BadRequest_InvalidRequestHeadersNoCRLF"); + + /// + /// Invalid request header: '{detail}' + /// + internal static string BadRequest_InvalidRequestHeader_Detail + { + get => GetString("BadRequest_InvalidRequestHeader_Detail"); + } + + /// + /// Invalid request header: '{detail}' + /// + internal static string FormatBadRequest_InvalidRequestHeader_Detail(object detail) + => string.Format(CultureInfo.CurrentCulture, GetString("BadRequest_InvalidRequestHeader_Detail", "detail"), detail); + + /// + /// Invalid request line. + /// + internal static string BadRequest_InvalidRequestLine + { + get => GetString("BadRequest_InvalidRequestLine"); + } + + /// + /// Invalid request line. + /// + internal static string FormatBadRequest_InvalidRequestLine() + => GetString("BadRequest_InvalidRequestLine"); + + /// + /// Invalid request line: '{detail}' + /// + internal static string BadRequest_InvalidRequestLine_Detail + { + get => GetString("BadRequest_InvalidRequestLine_Detail"); + } + + /// + /// Invalid request line: '{detail}' + /// + internal static string FormatBadRequest_InvalidRequestLine_Detail(object detail) + => string.Format(CultureInfo.CurrentCulture, GetString("BadRequest_InvalidRequestLine_Detail", "detail"), detail); + + /// + /// Invalid request target: '{detail}' + /// + internal static string BadRequest_InvalidRequestTarget_Detail + { + get => GetString("BadRequest_InvalidRequestTarget_Detail"); + } + + /// + /// Invalid request target: '{detail}' + /// + internal static string FormatBadRequest_InvalidRequestTarget_Detail(object detail) + => string.Format(CultureInfo.CurrentCulture, GetString("BadRequest_InvalidRequestTarget_Detail", "detail"), detail); + + /// + /// {detail} request contains no Content-Length or Transfer-Encoding header. + /// + internal static string BadRequest_LengthRequired + { + get => GetString("BadRequest_LengthRequired"); + } + + /// + /// {detail} request contains no Content-Length or Transfer-Encoding header. + /// + internal static string FormatBadRequest_LengthRequired(object detail) + => string.Format(CultureInfo.CurrentCulture, GetString("BadRequest_LengthRequired", "detail"), detail); + + /// + /// {detail} request contains no Content-Length header. + /// + internal static string BadRequest_LengthRequiredHttp10 + { + get => GetString("BadRequest_LengthRequiredHttp10"); + } + + /// + /// {detail} request contains no Content-Length header. + /// + internal static string FormatBadRequest_LengthRequiredHttp10(object detail) + => string.Format(CultureInfo.CurrentCulture, GetString("BadRequest_LengthRequiredHttp10", "detail"), detail); + + /// + /// Malformed request: invalid headers. + /// + internal static string BadRequest_MalformedRequestInvalidHeaders + { + get => GetString("BadRequest_MalformedRequestInvalidHeaders"); + } + + /// + /// Malformed request: invalid headers. + /// + internal static string FormatBadRequest_MalformedRequestInvalidHeaders() + => GetString("BadRequest_MalformedRequestInvalidHeaders"); + + /// + /// Method not allowed. + /// + internal static string BadRequest_MethodNotAllowed + { + get => GetString("BadRequest_MethodNotAllowed"); + } + + /// + /// Method not allowed. + /// + internal static string FormatBadRequest_MethodNotAllowed() + => GetString("BadRequest_MethodNotAllowed"); + + /// + /// Request is missing Host header. + /// + internal static string BadRequest_MissingHostHeader + { + get => GetString("BadRequest_MissingHostHeader"); + } + + /// + /// Request is missing Host header. + /// + internal static string FormatBadRequest_MissingHostHeader() + => GetString("BadRequest_MissingHostHeader"); + + /// + /// Multiple Content-Length headers. + /// + internal static string BadRequest_MultipleContentLengths + { + get => GetString("BadRequest_MultipleContentLengths"); + } + + /// + /// Multiple Content-Length headers. + /// + internal static string FormatBadRequest_MultipleContentLengths() + => GetString("BadRequest_MultipleContentLengths"); + + /// + /// Multiple Host headers. + /// + internal static string BadRequest_MultipleHostHeaders + { + get => GetString("BadRequest_MultipleHostHeaders"); + } + + /// + /// Multiple Host headers. + /// + internal static string FormatBadRequest_MultipleHostHeaders() + => GetString("BadRequest_MultipleHostHeaders"); + + /// + /// Request line too long. + /// + internal static string BadRequest_RequestLineTooLong + { + get => GetString("BadRequest_RequestLineTooLong"); + } + + /// + /// Request line too long. + /// + internal static string FormatBadRequest_RequestLineTooLong() + => GetString("BadRequest_RequestLineTooLong"); + + /// + /// Request timed out. + /// + internal static string BadRequest_RequestTimeout + { + get => GetString("BadRequest_RequestTimeout"); + } + + /// + /// Request timed out. + /// + internal static string FormatBadRequest_RequestTimeout() + => GetString("BadRequest_RequestTimeout"); + + /// + /// Request contains too many headers. + /// + internal static string BadRequest_TooManyHeaders + { + get => GetString("BadRequest_TooManyHeaders"); + } + + /// + /// Request contains too many headers. + /// + internal static string FormatBadRequest_TooManyHeaders() + => GetString("BadRequest_TooManyHeaders"); + + /// + /// Unexpected end of request content. + /// + internal static string BadRequest_UnexpectedEndOfRequestContent + { + get => GetString("BadRequest_UnexpectedEndOfRequestContent"); + } + + /// + /// Unexpected end of request content. + /// + internal static string FormatBadRequest_UnexpectedEndOfRequestContent() + => GetString("BadRequest_UnexpectedEndOfRequestContent"); + + /// + /// Unrecognized HTTP version: '{detail}' + /// + internal static string BadRequest_UnrecognizedHTTPVersion + { + get => GetString("BadRequest_UnrecognizedHTTPVersion"); + } + + /// + /// Unrecognized HTTP version: '{detail}' + /// + internal static string FormatBadRequest_UnrecognizedHTTPVersion(object detail) + => string.Format(CultureInfo.CurrentCulture, GetString("BadRequest_UnrecognizedHTTPVersion", "detail"), detail); + + /// + /// Requests with 'Connection: Upgrade' cannot have content in the request body. + /// + internal static string BadRequest_UpgradeRequestCannotHavePayload + { + get => GetString("BadRequest_UpgradeRequestCannotHavePayload"); + } + + /// + /// Requests with 'Connection: Upgrade' cannot have content in the request body. + /// + internal static string FormatBadRequest_UpgradeRequestCannotHavePayload() + => GetString("BadRequest_UpgradeRequestCannotHavePayload"); + /// /// Failed to bind to http://[::]:{port} (IPv6Any). Attempting to bind to http://0.0.0.0:{port} instead. /// @@ -38,6 +430,468 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core internal static string FormatResponseStreamWasUpgraded() => GetString("ResponseStreamWasUpgraded"); + /// + /// Kestrel does not support big-endian architectures. + /// + internal static string BigEndianNotSupported + { + get => GetString("BigEndianNotSupported"); + } + + /// + /// Kestrel does not support big-endian architectures. + /// + internal static string FormatBigEndianNotSupported() + => GetString("BigEndianNotSupported"); + + /// + /// Maximum request buffer size ({requestBufferSize}) must be greater than or equal to maximum request header size ({requestHeaderSize}). + /// + internal static string MaxRequestBufferSmallerThanRequestHeaderBuffer + { + get => GetString("MaxRequestBufferSmallerThanRequestHeaderBuffer"); + } + + /// + /// Maximum request buffer size ({requestBufferSize}) must be greater than or equal to maximum request header size ({requestHeaderSize}). + /// + internal static string FormatMaxRequestBufferSmallerThanRequestHeaderBuffer(object requestBufferSize, object requestHeaderSize) + => string.Format(CultureInfo.CurrentCulture, GetString("MaxRequestBufferSmallerThanRequestHeaderBuffer", "requestBufferSize", "requestHeaderSize"), requestBufferSize, requestHeaderSize); + + /// + /// Maximum request buffer size ({requestBufferSize}) must be greater than or equal to maximum request line size ({requestLineSize}). + /// + internal static string MaxRequestBufferSmallerThanRequestLineBuffer + { + get => GetString("MaxRequestBufferSmallerThanRequestLineBuffer"); + } + + /// + /// Maximum request buffer size ({requestBufferSize}) must be greater than or equal to maximum request line size ({requestLineSize}). + /// + internal static string FormatMaxRequestBufferSmallerThanRequestLineBuffer(object requestBufferSize, object requestLineSize) + => string.Format(CultureInfo.CurrentCulture, GetString("MaxRequestBufferSmallerThanRequestLineBuffer", "requestBufferSize", "requestLineSize"), requestBufferSize, requestLineSize); + + /// + /// Server has already started. + /// + internal static string ServerAlreadyStarted + { + get => GetString("ServerAlreadyStarted"); + } + + /// + /// Server has already started. + /// + internal static string FormatServerAlreadyStarted() + => GetString("ServerAlreadyStarted"); + + /// + /// Unknown transport mode: '{mode}'. + /// + internal static string UnknownTransportMode + { + get => GetString("UnknownTransportMode"); + } + + /// + /// Unknown transport mode: '{mode}'. + /// + internal static string FormatUnknownTransportMode(object mode) + => string.Format(CultureInfo.CurrentCulture, GetString("UnknownTransportMode", "mode"), mode); + + /// + /// Invalid non-ASCII or control character in header: {character} + /// + internal static string InvalidAsciiOrControlChar + { + get => GetString("InvalidAsciiOrControlChar"); + } + + /// + /// Invalid non-ASCII or control character in header: {character} + /// + internal static string FormatInvalidAsciiOrControlChar(object character) + => string.Format(CultureInfo.CurrentCulture, GetString("InvalidAsciiOrControlChar", "character"), character); + + /// + /// Invalid Content-Length: "{value}". Value must be a positive integral number. + /// + internal static string InvalidContentLength_InvalidNumber + { + get => GetString("InvalidContentLength_InvalidNumber"); + } + + /// + /// Invalid Content-Length: "{value}". Value must be a positive integral number. + /// + internal static string FormatInvalidContentLength_InvalidNumber(object value) + => string.Format(CultureInfo.CurrentCulture, GetString("InvalidContentLength_InvalidNumber", "value"), value); + + /// + /// Value must be null or a non-negative integer. + /// + internal static string NonNegativeNullableIntRequired + { + get => GetString("NonNegativeNullableIntRequired"); + } + + /// + /// Value must be null or a non-negative integer. + /// + internal static string FormatNonNegativeNullableIntRequired() + => GetString("NonNegativeNullableIntRequired"); + + /// + /// Value must be a positive integer. + /// + internal static string PositiveIntRequired + { + get => GetString("PositiveIntRequired"); + } + + /// + /// Value must be a positive integer. + /// + internal static string FormatPositiveIntRequired() + => GetString("PositiveIntRequired"); + + /// + /// Value must be null or a positive integer. + /// + internal static string PositiveNullableIntRequired + { + get => GetString("PositiveNullableIntRequired"); + } + + /// + /// Value must be null or a positive integer. + /// + internal static string FormatPositiveNullableIntRequired() + => GetString("PositiveNullableIntRequired"); + + /// + /// Unix socket path must be absolute. + /// + internal static string UnixSocketPathMustBeAbsolute + { + get => GetString("UnixSocketPathMustBeAbsolute"); + } + + /// + /// Unix socket path must be absolute. + /// + internal static string FormatUnixSocketPathMustBeAbsolute() + => GetString("UnixSocketPathMustBeAbsolute"); + + /// + /// Failed to bind to address {address}. + /// + internal static string AddressBindingFailed + { + get => GetString("AddressBindingFailed"); + } + + /// + /// Failed to bind to address {address}. + /// + internal static string FormatAddressBindingFailed(object address) + => string.Format(CultureInfo.CurrentCulture, GetString("AddressBindingFailed", "address"), address); + + /// + /// No listening endpoints were configured. Binding to {address} by default. + /// + internal static string BindingToDefaultAddress + { + get => GetString("BindingToDefaultAddress"); + } + + /// + /// No listening endpoints were configured. Binding to {address} by default. + /// + internal static string FormatBindingToDefaultAddress(object address) + => string.Format(CultureInfo.CurrentCulture, GetString("BindingToDefaultAddress", "address"), address); + + /// + /// HTTPS endpoints can only be configured using {methodName}. + /// + internal static string ConfigureHttpsFromMethodCall + { + get => GetString("ConfigureHttpsFromMethodCall"); + } + + /// + /// HTTPS endpoints can only be configured using {methodName}. + /// + internal static string FormatConfigureHttpsFromMethodCall(object methodName) + => string.Format(CultureInfo.CurrentCulture, GetString("ConfigureHttpsFromMethodCall", "methodName"), methodName); + + /// + /// A path base can only be configured using {methodName}. + /// + internal static string ConfigurePathBaseFromMethodCall + { + get => GetString("ConfigurePathBaseFromMethodCall"); + } + + /// + /// A path base can only be configured using {methodName}. + /// + internal static string FormatConfigurePathBaseFromMethodCall(object methodName) + => string.Format(CultureInfo.CurrentCulture, GetString("ConfigurePathBaseFromMethodCall", "methodName"), methodName); + + /// + /// Dynamic port binding is not supported when binding to localhost. You must either bind to 127.0.0.1:0 or [::1]:0, or both. + /// + internal static string DynamicPortOnLocalhostNotSupported + { + get => GetString("DynamicPortOnLocalhostNotSupported"); + } + + /// + /// Dynamic port binding is not supported when binding to localhost. You must either bind to 127.0.0.1:0 or [::1]:0, or both. + /// + internal static string FormatDynamicPortOnLocalhostNotSupported() + => GetString("DynamicPortOnLocalhostNotSupported"); + + /// + /// Failed to bind to address {endpoint}: address already in use. + /// + internal static string EndpointAlreadyInUse + { + get => GetString("EndpointAlreadyInUse"); + } + + /// + /// Failed to bind to address {endpoint}: address already in use. + /// + internal static string FormatEndpointAlreadyInUse(object endpoint) + => string.Format(CultureInfo.CurrentCulture, GetString("EndpointAlreadyInUse", "endpoint"), endpoint); + + /// + /// Invalid URL: '{url}'. + /// + internal static string InvalidUrl + { + get => GetString("InvalidUrl"); + } + + /// + /// Invalid URL: '{url}'. + /// + internal static string FormatInvalidUrl(object url) + => string.Format(CultureInfo.CurrentCulture, GetString("InvalidUrl", "url"), url); + + /// + /// Unable to bind to {address} on the {interfaceName} interface: '{error}'. + /// + internal static string NetworkInterfaceBindingFailed + { + get => GetString("NetworkInterfaceBindingFailed"); + } + + /// + /// Unable to bind to {address} on the {interfaceName} interface: '{error}'. + /// + internal static string FormatNetworkInterfaceBindingFailed(object address, object interfaceName, object error) + => string.Format(CultureInfo.CurrentCulture, GetString("NetworkInterfaceBindingFailed", "address", "interfaceName", "error"), address, interfaceName, error); + + /// + /// Overriding address(es) '{addresses}'. Binding to endpoints defined in {methodName} instead. + /// + internal static string OverridingWithKestrelOptions + { + get => GetString("OverridingWithKestrelOptions"); + } + + /// + /// Overriding address(es) '{addresses}'. Binding to endpoints defined in {methodName} instead. + /// + internal static string FormatOverridingWithKestrelOptions(object addresses, object methodName) + => string.Format(CultureInfo.CurrentCulture, GetString("OverridingWithKestrelOptions", "addresses", "methodName"), addresses, methodName); + + /// + /// Overriding endpoints defined in UseKestrel() because {settingName} is set to true. Binding to address(es) '{addresses}' instead. + /// + internal static string OverridingWithPreferHostingUrls + { + get => GetString("OverridingWithPreferHostingUrls"); + } + + /// + /// Overriding endpoints defined in UseKestrel() because {settingName} is set to true. Binding to address(es) '{addresses}' instead. + /// + internal static string FormatOverridingWithPreferHostingUrls(object settingName, object addresses) + => string.Format(CultureInfo.CurrentCulture, GetString("OverridingWithPreferHostingUrls", "settingName", "addresses"), settingName, addresses); + + /// + /// Unrecognized scheme in server address '{address}'. Only 'http://' is supported. + /// + internal static string UnsupportedAddressScheme + { + get => GetString("UnsupportedAddressScheme"); + } + + /// + /// Unrecognized scheme in server address '{address}'. Only 'http://' is supported. + /// + internal static string FormatUnsupportedAddressScheme(object address) + => string.Format(CultureInfo.CurrentCulture, GetString("UnsupportedAddressScheme", "address"), address); + + /// + /// Headers are read-only, response has already started. + /// + internal static string HeadersAreReadOnly + { + get => GetString("HeadersAreReadOnly"); + } + + /// + /// Headers are read-only, response has already started. + /// + internal static string FormatHeadersAreReadOnly() + => GetString("HeadersAreReadOnly"); + + /// + /// An item with the same key has already been added. + /// + internal static string KeyAlreadyExists + { + get => GetString("KeyAlreadyExists"); + } + + /// + /// An item with the same key has already been added. + /// + internal static string FormatKeyAlreadyExists() + => GetString("KeyAlreadyExists"); + + /// + /// Setting the header {name} is not allowed on responses with status code {statusCode}. + /// + internal static string HeaderNotAllowedOnResponse + { + get => GetString("HeaderNotAllowedOnResponse"); + } + + /// + /// Setting the header {name} is not allowed on responses with status code {statusCode}. + /// + internal static string FormatHeaderNotAllowedOnResponse(object name, object statusCode) + => string.Format(CultureInfo.CurrentCulture, GetString("HeaderNotAllowedOnResponse", "name", "statusCode"), name, statusCode); + + /// + /// {name} cannot be set because the response has already started. + /// + internal static string ParameterReadOnlyAfterResponseStarted + { + get => GetString("ParameterReadOnlyAfterResponseStarted"); + } + + /// + /// {name} cannot be set because the response has already started. + /// + internal static string FormatParameterReadOnlyAfterResponseStarted(object name) + => string.Format(CultureInfo.CurrentCulture, GetString("ParameterReadOnlyAfterResponseStarted", "name"), name); + + /// + /// Request processing didn't complete within the shutdown timeout. + /// + internal static string RequestProcessingAborted + { + get => GetString("RequestProcessingAborted"); + } + + /// + /// Request processing didn't complete within the shutdown timeout. + /// + internal static string FormatRequestProcessingAborted() + => GetString("RequestProcessingAborted"); + + /// + /// Response Content-Length mismatch: too few bytes written ({written} of {expected}). + /// + internal static string TooFewBytesWritten + { + get => GetString("TooFewBytesWritten"); + } + + /// + /// Response Content-Length mismatch: too few bytes written ({written} of {expected}). + /// + internal static string FormatTooFewBytesWritten(object written, object expected) + => string.Format(CultureInfo.CurrentCulture, GetString("TooFewBytesWritten", "written", "expected"), written, expected); + + /// + /// Response Content-Length mismatch: too many bytes written ({written} of {expected}). + /// + internal static string TooManyBytesWritten + { + get => GetString("TooManyBytesWritten"); + } + + /// + /// Response Content-Length mismatch: too many bytes written ({written} of {expected}). + /// + internal static string FormatTooManyBytesWritten(object written, object expected) + => string.Format(CultureInfo.CurrentCulture, GetString("TooManyBytesWritten", "written", "expected"), written, expected); + + /// + /// The response has been aborted due to an unhandled application exception. + /// + internal static string UnhandledApplicationException + { + get => GetString("UnhandledApplicationException"); + } + + /// + /// The response has been aborted due to an unhandled application exception. + /// + internal static string FormatUnhandledApplicationException() + => GetString("UnhandledApplicationException"); + + /// + /// Writing to the response body is invalid for responses with status code {statusCode}. + /// + internal static string WritingToResponseBodyNotSupported + { + get => GetString("WritingToResponseBodyNotSupported"); + } + + /// + /// Writing to the response body is invalid for responses with status code {statusCode}. + /// + internal static string FormatWritingToResponseBodyNotSupported(object statusCode) + => string.Format(CultureInfo.CurrentCulture, GetString("WritingToResponseBodyNotSupported", "statusCode"), statusCode); + + /// + /// Connection shutdown abnormally. + /// + internal static string ConnectionShutdownError + { + get => GetString("ConnectionShutdownError"); + } + + /// + /// Connection shutdown abnormally. + /// + internal static string FormatConnectionShutdownError() + => GetString("ConnectionShutdownError"); + + /// + /// Connection processing ended abnormally. + /// + internal static string RequestProcessingEndError + { + get => GetString("RequestProcessingEndError"); + } + + /// + /// Connection processing ended abnormally. + /// + internal static string FormatRequestProcessingEndError() + => GetString("RequestProcessingEndError"); + private static string GetString(string name, params string[] formatterNames) { var value = _resourceManager.GetString(name); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/ServerAddress.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/ServerAddress.cs index 4f64268087..0b7f019c85 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/ServerAddress.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/ServerAddress.cs @@ -69,7 +69,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core int schemeDelimiterStart = url.IndexOf("://", StringComparison.Ordinal); if (schemeDelimiterStart < 0) { - throw new FormatException($"Invalid URL: {url}"); + throw new FormatException(CoreStrings.FormatInvalidUrl(url)); } int schemeDelimiterEnd = schemeDelimiterStart + "://".Length; @@ -134,7 +134,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core if (string.IsNullOrEmpty(serverAddress.Host)) { - throw new FormatException($"Invalid URL: {url}"); + throw new FormatException(CoreStrings.FormatInvalidUrl(url)); } if (url[url.Length - 1] == '/') diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Https/HttpsConnectionAdapter.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Https/HttpsConnectionAdapter.cs index 298c501bea..f87d05e8e8 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Https/HttpsConnectionAdapter.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Https/HttpsConnectionAdapter.cs @@ -31,9 +31,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Https { throw new ArgumentNullException(nameof(options)); } + if (options.ServerCertificate == null) { - throw new ArgumentException("The server certificate parameter is required."); + throw new ArgumentException(HttpsStrings.ServiceCertificateRequired, nameof(options)); } _options = options; @@ -97,7 +98,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Https } catch (IOException ex) { - _logger?.LogInformation(1, ex, "Failed to authenticate HTTPS connection."); + _logger?.LogInformation(1, ex, HttpsStrings.AuthenticationFailed); sslStream.Dispose(); return _closedAdaptedConnection; } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Https/HttpsStrings.resx b/src/Microsoft.AspNetCore.Server.Kestrel.Https/HttpsStrings.resx new file mode 100644 index 0000000000..d0745abab8 --- /dev/null +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Https/HttpsStrings.resx @@ -0,0 +1,126 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + Failed to authenticate HTTPS connection. + + + The server certificate parameter is required. + + \ No newline at end of file diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Https/Microsoft.AspNetCore.Server.Kestrel.Https.csproj b/src/Microsoft.AspNetCore.Server.Kestrel.Https/Microsoft.AspNetCore.Server.Kestrel.Https.csproj index 6ee24eba77..6205bd9037 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Https/Microsoft.AspNetCore.Server.Kestrel.Https.csproj +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Https/Microsoft.AspNetCore.Server.Kestrel.Https.csproj @@ -24,4 +24,10 @@ + + + + + + diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Https/Properties/HttpsStrings.Designer.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Https/Properties/HttpsStrings.Designer.cs new file mode 100644 index 0000000000..1b86a18e5d --- /dev/null +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Https/Properties/HttpsStrings.Designer.cs @@ -0,0 +1,58 @@ +// +namespace Microsoft.AspNetCore.Server.Kestrel.Https +{ + using System.Globalization; + using System.Reflection; + using System.Resources; + + internal static class HttpsStrings + { + private static readonly ResourceManager _resourceManager + = new ResourceManager("Microsoft.AspNetCore.Server.Kestrel.Https.HttpsStrings", typeof(HttpsStrings).GetTypeInfo().Assembly); + + /// + /// Failed to authenticate HTTPS connection. + /// + internal static string AuthenticationFailed + { + get => GetString("AuthenticationFailed"); + } + + /// + /// Failed to authenticate HTTPS connection. + /// + internal static string FormatAuthenticationFailed() + => GetString("AuthenticationFailed"); + + /// + /// The server certificate parameter is required. + /// + internal static string ServiceCertificateRequired + { + get => GetString("ServiceCertificateRequired"); + } + + /// + /// The server certificate parameter is required. + /// + internal static string FormatServiceCertificateRequired() + => GetString("ServiceCertificateRequired"); + + private static string GetString(string name, params string[] formatterNames) + { + var value = _resourceManager.GetString(name); + + System.Diagnostics.Debug.Assert(value != null); + + if (formatterNames != null) + { + for (var i = 0; i < formatterNames.Length; i++) + { + value = value.Replace("{" + formatterNames[i] + "}", "{" + i + "}"); + } + } + + return value; + } + } +} diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.csproj b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.csproj index 911f42f7b2..960578b878 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.csproj +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.csproj @@ -21,4 +21,10 @@ + + + + + + diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets/Properties/SocketsStrings.Designer.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets/Properties/SocketsStrings.Designer.cs new file mode 100644 index 0000000000..9d2e7e0182 --- /dev/null +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets/Properties/SocketsStrings.Designer.cs @@ -0,0 +1,58 @@ +// +namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets +{ + using System.Globalization; + using System.Reflection; + using System.Resources; + + internal static class SocketsStrings + { + private static readonly ResourceManager _resourceManager + = new ResourceManager("Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.SocketsStrings", typeof(SocketsStrings).GetTypeInfo().Assembly); + + /// + /// Only ListenType.IPEndPoint is supported. + /// + internal static string OnlyIPEndPointsSupported + { + get => GetString("OnlyIPEndPointsSupported"); + } + + /// + /// Only ListenType.IPEndPoint is supported. + /// + internal static string FormatOnlyIPEndPointsSupported() + => GetString("OnlyIPEndPointsSupported"); + + /// + /// Transport is already bound. + /// + internal static string TransportAlreadyBound + { + get => GetString("TransportAlreadyBound"); + } + + /// + /// Transport is already bound. + /// + internal static string FormatTransportAlreadyBound() + => GetString("TransportAlreadyBound"); + + private static string GetString(string name, params string[] formatterNames) + { + var value = _resourceManager.GetString(name); + + System.Diagnostics.Debug.Assert(value != null); + + if (formatterNames != null) + { + for (var i = 0; i < formatterNames.Length; i++) + { + value = value.Replace("{" + formatterNames[i] + "}", "{" + i + "}"); + } + } + + return value; + } + } +} diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets/SocketTransport.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets/SocketTransport.cs index 4832b5676a..c55fbd550a 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets/SocketTransport.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets/SocketTransport.cs @@ -37,7 +37,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets { if (_listenSocket != null) { - throw new InvalidOperationException("Transport is already bound"); + throw new InvalidOperationException(SocketsStrings.TransportAlreadyBound); } IPEndPoint endPoint = _endPointInformation.IPEndPoint; diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets/SocketTransportFactory.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets/SocketTransportFactory.cs index 9dc2768bbf..3746f5d206 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets/SocketTransportFactory.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets/SocketTransportFactory.cs @@ -25,7 +25,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets if (endPointInformation.Type != ListenType.IPEndPoint) { - throw new ArgumentException("Only ListenType.IPEndPoint is supported", nameof(endPointInformation)); + throw new ArgumentException(SocketsStrings.OnlyIPEndPointsSupported, nameof(endPointInformation)); } if (handler == null) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets/SocketsStrings.resx b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets/SocketsStrings.resx new file mode 100644 index 0000000000..79cd2d7303 --- /dev/null +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets/SocketsStrings.resx @@ -0,0 +1,126 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + Only ListenType.IPEndPoint is supported. + + + Transport is already bound. + + \ No newline at end of file diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameResponseHeadersTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameResponseHeadersTests.cs index 2d6f6bb706..9ec614ef16 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameResponseHeadersTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameResponseHeadersTests.cs @@ -6,7 +6,6 @@ using System.Collections.Generic; using System.Globalization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; -using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; using Microsoft.AspNetCore.Testing; using Microsoft.Extensions.Primitives; using Xunit; @@ -149,7 +148,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests var dictionary = (IDictionary)headers; var exception = Assert.Throws(() => dictionary.Add("Content-Length", new[] { contentLength })); - Assert.Equal($"Invalid Content-Length: \"{contentLength}\". Value must be a positive integral number.", exception.Message); + Assert.Equal(CoreStrings.FormatInvalidContentLength_InvalidNumber(contentLength), exception.Message); } [Theory] @@ -160,7 +159,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests var dictionary = (IDictionary)headers; var exception = Assert.Throws(() => ((IHeaderDictionary)headers)["Content-Length"] = contentLength); - Assert.Equal($"Invalid Content-Length: \"{contentLength}\". Value must be a positive integral number.", exception.Message); + Assert.Equal(CoreStrings.FormatInvalidContentLength_InvalidNumber(contentLength), exception.Message); } [Theory] @@ -170,7 +169,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests var headers = new FrameResponseHeaders(); var exception = Assert.Throws(() => headers.HeaderContentLength = contentLength); - Assert.Equal($"Invalid Content-Length: \"{contentLength}\". Value must be a positive integral number.", exception.Message); + Assert.Equal(CoreStrings.FormatInvalidContentLength_InvalidNumber(contentLength), exception.Message); } [Theory] diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameTests.cs index d050e7f43d..0f0a2d4ffa 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameTests.cs @@ -94,7 +94,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests var exception = Assert.Throws(() => _frame.TakeMessageHeaders(readableBuffer, out _consumed, out _examined)); _input.Reader.Advance(_consumed, _examined); - Assert.Equal("Request headers too long.", exception.Message); + Assert.Equal(CoreStrings.BadRequest_HeadersExceedMaxTotalSize, exception.Message); Assert.Equal(StatusCodes.Status431RequestHeaderFieldsTooLarge, exception.StatusCode); } @@ -110,7 +110,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests var exception = Assert.Throws(() => _frame.TakeMessageHeaders(readableBuffer, out _consumed, out _examined)); _input.Reader.Advance(_consumed, _examined); - Assert.Equal("Request contains too many headers.", exception.Message); + Assert.Equal(CoreStrings.BadRequest_TooManyHeaders, exception.Message); Assert.Equal(StatusCodes.Status431RequestHeaderFieldsTooLarge, exception.StatusCode); } @@ -341,7 +341,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests var exception = Assert.Throws(() => _frame.TakeStartLine(readableBuffer, out _consumed, out _examined)); _input.Reader.Advance(_consumed, _examined); - Assert.Equal("Request line too long.", exception.Message); + Assert.Equal(CoreStrings.BadRequest_RequestLineTooLong, exception.Message); Assert.Equal(StatusCodes.Status414UriTooLong, exception.StatusCode); } @@ -356,7 +356,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests _frame.TakeStartLine(readableBuffer, out _consumed, out _examined)); _input.Reader.Advance(_consumed, _examined); - Assert.Equal($"Invalid request target: '{target}'", exception.Message); + Assert.Equal(CoreStrings.FormatBadRequest_InvalidRequestTarget_Detail(target), exception.Message); } [Theory] @@ -370,7 +370,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests _frame.TakeStartLine(readableBuffer, out _consumed, out _examined)); _input.Reader.Advance(_consumed, _examined); - Assert.Equal($"Invalid request target: '{target.EscapeNonPrintable()}'", exception.Message); + Assert.Equal(CoreStrings.FormatBadRequest_InvalidRequestTarget_Detail(target.EscapeNonPrintable()), exception.Message); } [Theory] @@ -386,7 +386,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests _frame.TakeStartLine(readableBuffer, out _consumed, out _examined)); _input.Reader.Advance(_consumed, _examined); - Assert.Equal($"Invalid request line: '{requestLine.EscapeNonPrintable()}'", exception.Message); + Assert.Equal(CoreStrings.FormatBadRequest_InvalidRequestLine_Detail(requestLine.EscapeNonPrintable()), exception.Message); } [Theory] @@ -402,7 +402,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests _frame.TakeStartLine(readableBuffer, out _consumed, out _examined)); _input.Reader.Advance(_consumed, _examined); - Assert.Equal($"Invalid request target: '{target.EscapeNonPrintable()}'", exception.Message); + Assert.Equal(CoreStrings.FormatBadRequest_InvalidRequestTarget_Detail(target.EscapeNonPrintable()), exception.Message); } [Theory] @@ -418,7 +418,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests _frame.TakeStartLine(readableBuffer, out _consumed, out _examined)); _input.Reader.Advance(_consumed, _examined); - Assert.Equal($"Invalid request target: '{target.EscapeNonPrintable()}'", exception.Message); + Assert.Equal(CoreStrings.FormatBadRequest_InvalidRequestTarget_Detail(target.EscapeNonPrintable()), exception.Message); } [Theory] @@ -433,7 +433,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests _input.Reader.Advance(_consumed, _examined); Assert.Equal(405, exception.StatusCode); - Assert.Equal("Method not allowed.", exception.Message); + Assert.Equal(CoreStrings.BadRequest_MethodNotAllowed, exception.Message); Assert.Equal(HttpUtilities.MethodToString(allowedMethod), exception.AllowedHeader); } @@ -629,7 +629,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests _frame.TakeStartLine(readableBuffer, out _consumed, out _examined)); _input.Reader.Advance(_consumed, _examined); - Assert.Equal("Invalid request target: ''", exception.Message); + Assert.Equal(CoreStrings.FormatBadRequest_InvalidRequestTarget_Detail(string.Empty), exception.Message); Assert.Equal(StatusCodes.Status400BadRequest, exception.StatusCode); } finally diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/HttpParserTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/HttpParserTests.cs index 2a953005cc..b9cc700f1a 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/HttpParserTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/HttpParserTests.cs @@ -86,7 +86,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests var exception = Assert.Throws(() => parser.ParseRequestLine(requestHandler, buffer, out var consumed, out var examined)); - Assert.Equal($"Invalid request line: '{requestLine.EscapeNonPrintable()}'", exception.Message); + Assert.Equal(CoreStrings.FormatBadRequest_InvalidRequestLine_Detail(requestLine.EscapeNonPrintable()), exception.Message); Assert.Equal(StatusCodes.Status400BadRequest, (exception as BadHttpRequestException).StatusCode); } @@ -108,7 +108,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests var exception = Assert.Throws(() => parser.ParseRequestLine(requestHandler, buffer, out var consumed, out var examined)); - Assert.Equal($"Invalid request line: '{method.EscapeNonPrintable()} / HTTP/1.1\\x0D\\x0A'", exception.Message); + Assert.Equal(CoreStrings.FormatBadRequest_InvalidRequestLine_Detail(method.EscapeNonPrintable() + @" / HTTP/1.1\x0D\x0A"), exception.Message); Assert.Equal(StatusCodes.Status400BadRequest, (exception as BadHttpRequestException).StatusCode); } @@ -130,7 +130,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests var exception = Assert.Throws(() => parser.ParseRequestLine(requestHandler, buffer, out var consumed, out var examined)); - Assert.Equal($"Unrecognized HTTP version: '{httpVersion}'", exception.Message); + Assert.Equal(CoreStrings.FormatBadRequest_UnrecognizedHTTPVersion(httpVersion), exception.Message); Assert.Equal(StatusCodes.Status505HttpVersionNotsupported, (exception as BadHttpRequestException).StatusCode); } @@ -352,7 +352,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests exception = Assert.Throws(() => parser.ParseRequestLine(requestHandler, buffer, out var consumed, out var examined)); - Assert.Equal("Unrecognized HTTP version: ''", exception.Message); + Assert.Equal(CoreStrings.FormatBadRequest_UnrecognizedHTTPVersion(string.Empty), exception.Message); Assert.Equal(StatusCodes.Status505HttpVersionNotsupported, (exception as BadHttpRequestException).StatusCode); // Invalid request header @@ -361,7 +361,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests exception = Assert.Throws(() => parser.ParseHeaders(requestHandler, buffer, out var consumed, out var examined, out var consumedBytes)); - Assert.Equal("Invalid request header: ''", exception.Message); + Assert.Equal(CoreStrings.FormatBadRequest_InvalidRequestHeader_Detail(string.Empty), exception.Message); Assert.Equal(StatusCodes.Status400BadRequest, exception.StatusCode); } diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/KestrelServerTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/KestrelServerTests.cs index 2f1346c9d2..75ab8a3dbb 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/KestrelServerTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/KestrelServerTests.cs @@ -8,7 +8,6 @@ using System.Threading; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting.Server; using Microsoft.AspNetCore.Hosting.Server.Features; -using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions; using Microsoft.AspNetCore.Testing; using Microsoft.Extensions.Internal; @@ -110,7 +109,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests var exception = Assert.Throws(() => StartDummyApplication(server)); Assert.Equal( - $"Maximum request buffer size ({maxRequestBufferSize}) must be greater than or equal to maximum request line size ({maxRequestLineSize}).", + CoreStrings.FormatMaxRequestBufferSmallerThanRequestLineBuffer(maxRequestBufferSize, maxRequestLineSize), exception.Message); Assert.Equal(1, testLogger.CriticalErrorsLogged); } @@ -132,7 +131,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests var exception = Assert.Throws(() => StartDummyApplication(server)); Assert.Equal( - $"Maximum request buffer size ({maxRequestBufferSize}) must be greater than or equal to maximum request headers size ({maxRequestHeadersTotalSize}).", + CoreStrings.FormatMaxRequestBufferSmallerThanRequestHeaderBuffer(maxRequestBufferSize, maxRequestHeadersTotalSize), exception.Message); Assert.Equal(1, testLogger.CriticalErrorsLogged); } diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/MessageBodyTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/MessageBodyTests.cs index 95a35b2882..6b69166ab6 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/MessageBodyTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/MessageBodyTests.cs @@ -231,7 +231,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests MessageBody.For(HttpVersion.Http11, new FrameRequestHeaders { HeaderTransferEncoding = "chunked, not-chunked" }, input.FrameContext)); Assert.Equal(StatusCodes.Status400BadRequest, ex.StatusCode); - Assert.Equal("Final transfer coding is not \"chunked\": \"chunked, not-chunked\"", ex.Message); + Assert.Equal(CoreStrings.FormatBadRequest_FinalTransferCodingNotChunked("chunked, not-chunked"), ex.Message); } } @@ -247,7 +247,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests MessageBody.For(HttpVersion.Http11, new FrameRequestHeaders(), input.FrameContext)); Assert.Equal(StatusCodes.Status411LengthRequired, ex.StatusCode); - Assert.Equal($"{method} request contains no Content-Length or Transfer-Encoding header", ex.Message); + Assert.Equal(CoreStrings.FormatBadRequest_LengthRequired(method), ex.Message); } } @@ -263,7 +263,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests MessageBody.For(HttpVersion.Http10, new FrameRequestHeaders(), input.FrameContext)); Assert.Equal(StatusCodes.Status400BadRequest, ex.StatusCode); - Assert.Equal($"{method} request contains no Content-Length header", ex.Message); + Assert.Equal(CoreStrings.FormatBadRequest_LengthRequiredHttp10(method), ex.Message); } } diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs index abd6ec612c..9525d7b406 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs @@ -200,7 +200,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests Assert.Equal(5000, host.GetPort()); Assert.Single(testLogger.Messages, log => log.LogLevel == LogLevel.Debug && - string.Equals($"No listening endpoints were configured. Binding to {Constants.DefaultServerAddress} by default.", + string.Equals(CoreStrings.FormatBindingToDefaultAddress(Constants.DefaultServerAddress), log.Message, StringComparison.Ordinal)); foreach (var address in addresses) @@ -227,7 +227,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests using (var host = hostBuilder.Build()) { var exception = Assert.Throws(() => host.Start()); - Assert.Equal($"Failed to bind to address http://127.0.0.1:{port}: address already in use.", exception.Message); + Assert.Equal(CoreStrings.FormatEndpointAlreadyInUse($"http://127.0.0.1:{port}"), exception.Message); } } } @@ -250,7 +250,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests using (var host = hostBuilder.Build()) { var exception = Assert.Throws(() => host.Start()); - Assert.Equal($"Failed to bind to address http://[::1]:{port}: address already in use.", exception.Message); + Assert.Equal(CoreStrings.FormatEndpointAlreadyInUse($"http://[::1]:{port}"), exception.Message); } } } @@ -277,7 +277,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests Assert.Equal(overrideAddressPort, host.GetPort()); Assert.Single(testLogger.Messages, log => log.LogLevel == LogLevel.Information && - string.Equals($"Overriding endpoints defined in UseKestrel() since {nameof(IServerAddressesFeature.PreferHostingUrls)} is set to true. Binding to address(es) '{overrideAddress}' instead.", + string.Equals(CoreStrings.FormatOverridingWithPreferHostingUrls(nameof(IServerAddressesFeature.PreferHostingUrls), overrideAddress), log.Message, StringComparison.Ordinal)); Assert.Equal(new Uri(overrideAddress).ToString(), await HttpClientSlim.GetStringAsync(overrideAddress)); @@ -389,7 +389,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { var exception = Assert.Throws(() => host.Start()); Assert.Equal( - $"Failed to bind to address http://{(addressFamily == AddressFamily.InterNetwork ? "127.0.0.1" : "[::1]")}:{port}: address already in use.", + CoreStrings.FormatEndpointAlreadyInUse($"http://{(addressFamily == AddressFamily.InterNetwork ? "127.0.0.1" : "[::1]")}:{port}"), exception.Message); } } @@ -677,21 +677,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests _portSupported = new Lazy(CanBindToPort); } - public bool IsMet - { - get - { - return _portSupported.Value; - } - } + public bool IsMet => _portSupported.Value; - public string SkipReason - { - get - { - return $"Cannot bind to port {_port} on the host."; - } - } + public string SkipReason => $"Cannot bind to port {_port} on the host."; private bool CanBindToPort() { diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/BadHttpRequestTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/BadHttpRequestTests.cs index d97289edd8..089b86006d 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/BadHttpRequestTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/BadHttpRequestTests.cs @@ -35,7 +35,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests return TestBadRequest( $"GET / {httpVersion}\r\n", "505 HTTP Version Not Supported", - $"Unrecognized HTTP version: '{httpVersion}'"); + CoreStrings.FormatBadRequest_UnrecognizedHTTPVersion(httpVersion)); } [Theory] @@ -69,7 +69,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests return TestBadRequest( $"{method} / HTTP/1.1\r\nHost:\r\n\r\n", "411 Length Required", - $"{method} request contains no Content-Length or Transfer-Encoding header"); + CoreStrings.FormatBadRequest_LengthRequired(method)); } [Theory] @@ -80,7 +80,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests return TestBadRequest( $"{method} / HTTP/1.0\r\n\r\n", "400 Bad Request", - $"{method} request contains no Content-Length header"); + CoreStrings.FormatBadRequest_LengthRequiredHttp10(method)); } [Theory] @@ -91,7 +91,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests return TestBadRequest( $"POST / HTTP/1.1\r\nHost:\r\nContent-Length: {contentLength}\r\n\r\n", "400 Bad Request", - $"Invalid content length: {contentLength}"); + CoreStrings.FormatBadRequest_InvalidContentLength_Detail(contentLength)); } [Theory] @@ -102,7 +102,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests return TestBadRequest( $"{request} HTTP/1.1\r\n", "405 Method Not Allowed", - "Method not allowed.", + CoreStrings.BadRequest_MethodNotAllowed, $"Allow: {allowedMethod}"); } @@ -112,7 +112,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests return TestBadRequest( "GET / HTTP/1.1\r\n\r\n", "400 Bad Request", - "Request is missing Host header."); + CoreStrings.BadRequest_MissingHostHeader); } [Fact] @@ -120,7 +120,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { return TestBadRequest("GET / HTTP/1.1\r\nHost: localhost\r\nHost: localhost\r\n\r\n", "400 Bad Request", - "Multiple Host headers."); + CoreStrings.BadRequest_MultipleHostHeaders); } [Theory] @@ -130,7 +130,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests return TestBadRequest( $"{requestTarget} HTTP/1.1\r\nHost: {host}\r\n\r\n", "400 Bad Request", - $"Invalid Host header: '{host.Trim()}'"); + CoreStrings.FormatBadRequest_InvalidHostHeader_Detail(host.Trim())); } [Fact] @@ -218,17 +218,17 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests foreach (var requestLine in HttpParsingData.RequestLineInvalidData) { - data.Add(requestLine, $"Invalid request line: '{requestLine.EscapeNonPrintable()}'"); + data.Add(requestLine, CoreStrings.FormatBadRequest_InvalidRequestLine_Detail(requestLine.EscapeNonPrintable())); } foreach (var target in HttpParsingData.TargetWithEncodedNullCharData) { - data.Add($"GET {target} HTTP/1.1\r\n", $"Invalid request target: '{target.EscapeNonPrintable()}'"); + data.Add($"GET {target} HTTP/1.1\r\n", CoreStrings.FormatBadRequest_InvalidRequestTarget_Detail(target.EscapeNonPrintable())); } foreach (var target in HttpParsingData.TargetWithNullCharData) { - data.Add($"GET {target} HTTP/1.1\r\n", $"Invalid request target: '{target.EscapeNonPrintable()}'"); + data.Add($"GET {target} HTTP/1.1\r\n", CoreStrings.FormatBadRequest_InvalidRequestTarget_Detail(target.EscapeNonPrintable())); } return data; @@ -239,6 +239,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests public static IEnumerable InvalidRequestHeaderData => HttpParsingData.RequestHeaderInvalidData; - public static TheoryData InvalidHostHeaderData => HttpParsingData.HostHeaderInvalidData; + public static TheoryData InvalidHostHeaderData => HttpParsingData.HostHeaderInvalidData; } } diff --git a/test/shared/HttpParsingData.cs b/test/shared/HttpParsingData.cs index 658fad2528..c25771cd48 100644 --- a/test/shared/HttpParsingData.cs +++ b/test/shared/HttpParsingData.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using System.Linq; +using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; using Xunit; @@ -356,76 +357,76 @@ namespace Microsoft.AspNetCore.Testing public static IEnumerable RequestHeaderInvalidData => new[] { // Missing CR - new[] { "Header: value\n\r\n", @"Invalid request header: 'Header: value\x0A'" }, - new[] { "Header-1: value1\nHeader-2: value2\r\n\r\n", @"Invalid request header: 'Header-1: value1\x0A'" }, - new[] { "Header-1: value1\r\nHeader-2: value2\n\r\n", @"Invalid request header: 'Header-2: value2\x0A'" }, + new[] { "Header: value\n\r\n", CoreStrings.FormatBadRequest_InvalidRequestHeader_Detail(@"Header: value\x0A") }, + new[] { "Header-1: value1\nHeader-2: value2\r\n\r\n", CoreStrings.FormatBadRequest_InvalidRequestHeader_Detail(@"Header-1: value1\x0A") }, + new[] { "Header-1: value1\r\nHeader-2: value2\n\r\n", CoreStrings.FormatBadRequest_InvalidRequestHeader_Detail(@"Header-2: value2\x0A") }, // Line folding - new[] { "Header: line1\r\n line2\r\n\r\n", @"Invalid request header: ' line2\x0D\x0A'" }, - new[] { "Header: line1\r\n\tline2\r\n\r\n", @"Invalid request header: '\x09line2\x0D\x0A'" }, - new[] { "Header: line1\r\n line2\r\n\r\n", @"Invalid request header: ' line2\x0D\x0A'" }, - new[] { "Header: line1\r\n \tline2\r\n\r\n", @"Invalid request header: ' \x09line2\x0D\x0A'" }, - new[] { "Header: line1\r\n\t line2\r\n\r\n", @"Invalid request header: '\x09 line2\x0D\x0A'" }, - new[] { "Header: line1\r\n\t\tline2\r\n\r\n", @"Invalid request header: '\x09\x09line2\x0D\x0A'" }, - new[] { "Header: line1\r\n \t\t line2\r\n\r\n", @"Invalid request header: ' \x09\x09 line2\x0D\x0A'" }, - new[] { "Header: line1\r\n \t \t line2\r\n\r\n", @"Invalid request header: ' \x09 \x09 line2\x0D\x0A'" }, - new[] { "Header-1: multi\r\n line\r\nHeader-2: value2\r\n\r\n", @"Invalid request header: ' line\x0D\x0A'" }, - new[] { "Header-1: value1\r\nHeader-2: multi\r\n line\r\n\r\n", @"Invalid request header: ' line\x0D\x0A'" }, - new[] { "Header-1: value1\r\n Header-2: value2\r\n\r\n", @"Invalid request header: ' Header-2: value2\x0D\x0A'" }, - new[] { "Header-1: value1\r\n\tHeader-2: value2\r\n\r\n", @"Invalid request header: '\x09Header-2: value2\x0D\x0A'" }, + new[] { "Header: line1\r\n line2\r\n\r\n", CoreStrings.FormatBadRequest_InvalidRequestHeader_Detail(@" line2\x0D\x0A") }, + new[] { "Header: line1\r\n\tline2\r\n\r\n", CoreStrings.FormatBadRequest_InvalidRequestHeader_Detail(@"\x09line2\x0D\x0A") }, + new[] { "Header: line1\r\n line2\r\n\r\n", CoreStrings.FormatBadRequest_InvalidRequestHeader_Detail(@" line2\x0D\x0A") }, + new[] { "Header: line1\r\n \tline2\r\n\r\n", CoreStrings.FormatBadRequest_InvalidRequestHeader_Detail(@" \x09line2\x0D\x0A") }, + new[] { "Header: line1\r\n\t line2\r\n\r\n", CoreStrings.FormatBadRequest_InvalidRequestHeader_Detail(@"\x09 line2\x0D\x0A") }, + new[] { "Header: line1\r\n\t\tline2\r\n\r\n", CoreStrings.FormatBadRequest_InvalidRequestHeader_Detail(@"\x09\x09line2\x0D\x0A") }, + new[] { "Header: line1\r\n \t\t line2\r\n\r\n", CoreStrings.FormatBadRequest_InvalidRequestHeader_Detail(@" \x09\x09 line2\x0D\x0A") }, + new[] { "Header: line1\r\n \t \t line2\r\n\r\n", CoreStrings.FormatBadRequest_InvalidRequestHeader_Detail(@" \x09 \x09 line2\x0D\x0A") }, + new[] { "Header-1: multi\r\n line\r\nHeader-2: value2\r\n\r\n", CoreStrings.FormatBadRequest_InvalidRequestHeader_Detail(@" line\x0D\x0A") }, + new[] { "Header-1: value1\r\nHeader-2: multi\r\n line\r\n\r\n", CoreStrings.FormatBadRequest_InvalidRequestHeader_Detail(@" line\x0D\x0A") }, + new[] { "Header-1: value1\r\n Header-2: value2\r\n\r\n", CoreStrings.FormatBadRequest_InvalidRequestHeader_Detail(@" Header-2: value2\x0D\x0A") }, + new[] { "Header-1: value1\r\n\tHeader-2: value2\r\n\r\n", CoreStrings.FormatBadRequest_InvalidRequestHeader_Detail(@"\x09Header-2: value2\x0D\x0A") }, // CR in value - new[] { "Header-1: value1\r\r\n", @"Invalid request header: 'Header-1: value1\x0D\x0D\x0A'" }, - new[] { "Header-1: val\rue1\r\n", @"Invalid request header: 'Header-1: val\x0Due1\x0D\x0A'" }, - new[] { "Header-1: value1\rHeader-2: value2\r\n\r\n", @"Invalid request header: 'Header-1: value1\x0DHeader-2: value2\x0D\x0A'" }, - new[] { "Header-1: value1\r\nHeader-2: value2\r\r\n", @"Invalid request header: 'Header-2: value2\x0D\x0D\x0A'" }, - new[] { "Header-1: value1\r\nHeader-2: v\ralue2\r\n", @"Invalid request header: 'Header-2: v\x0Dalue2\x0D\x0A'" }, - new[] { "Header-1: Value__\rVector16________Vector32\r\n", @"Invalid request header: 'Header-1: Value__\x0DVector16________Vector32\x0D\x0A'" }, - new[] { "Header-1: Value___Vector16\r________Vector32\r\n", @"Invalid request header: 'Header-1: Value___Vector16\x0D________Vector32\x0D\x0A'" }, - new[] { "Header-1: Value___Vector16_______\rVector32\r\n", @"Invalid request header: 'Header-1: Value___Vector16_______\x0DVector32\x0D\x0A'" }, - new[] { "Header-1: Value___Vector16________Vector32\r\r\n", @"Invalid request header: 'Header-1: Value___Vector16________Vector32\x0D\x0D\x0A'" }, - new[] { "Header-1: Value___Vector16________Vector32_\r\r\n", @"Invalid request header: 'Header-1: Value___Vector16________Vector32_\x0D\x0D\x0A'" }, - new[] { "Header-1: Value___Vector16________Vector32Value___Vector16_______\rVector32\r\n", @"Invalid request header: 'Header-1: Value___Vector16________Vector32Value___Vector16_______\x0DVector32\x0D\x0A'" }, - new[] { "Header-1: Value___Vector16________Vector32Value___Vector16________Vector32\r\r\n", @"Invalid request header: 'Header-1: Value___Vector16________Vector32Value___Vector16________Vector32\x0D\x0D\x0A'" }, - new[] { "Header-1: Value___Vector16________Vector32Value___Vector16________Vector32_\r\r\n", @"Invalid request header: 'Header-1: Value___Vector16________Vector32Value___Vector16________Vector32_\x0D\x0D\x0A'" }, + new[] { "Header-1: value1\r\r\n", CoreStrings.FormatBadRequest_InvalidRequestHeader_Detail(@"Header-1: value1\x0D\x0D\x0A") }, + new[] { "Header-1: val\rue1\r\n", CoreStrings.FormatBadRequest_InvalidRequestHeader_Detail(@"Header-1: val\x0Due1\x0D\x0A") }, + new[] { "Header-1: value1\rHeader-2: value2\r\n\r\n", CoreStrings.FormatBadRequest_InvalidRequestHeader_Detail(@"Header-1: value1\x0DHeader-2: value2\x0D\x0A") }, + new[] { "Header-1: value1\r\nHeader-2: value2\r\r\n", CoreStrings.FormatBadRequest_InvalidRequestHeader_Detail(@"Header-2: value2\x0D\x0D\x0A") }, + new[] { "Header-1: value1\r\nHeader-2: v\ralue2\r\n", CoreStrings.FormatBadRequest_InvalidRequestHeader_Detail(@"Header-2: v\x0Dalue2\x0D\x0A") }, + new[] { "Header-1: Value__\rVector16________Vector32\r\n", CoreStrings.FormatBadRequest_InvalidRequestHeader_Detail(@"Header-1: Value__\x0DVector16________Vector32\x0D\x0A") }, + new[] { "Header-1: Value___Vector16\r________Vector32\r\n", CoreStrings.FormatBadRequest_InvalidRequestHeader_Detail(@"Header-1: Value___Vector16\x0D________Vector32\x0D\x0A") }, + new[] { "Header-1: Value___Vector16_______\rVector32\r\n", CoreStrings.FormatBadRequest_InvalidRequestHeader_Detail(@"Header-1: Value___Vector16_______\x0DVector32\x0D\x0A") }, + new[] { "Header-1: Value___Vector16________Vector32\r\r\n", CoreStrings.FormatBadRequest_InvalidRequestHeader_Detail(@"Header-1: Value___Vector16________Vector32\x0D\x0D\x0A") }, + new[] { "Header-1: Value___Vector16________Vector32_\r\r\n", CoreStrings.FormatBadRequest_InvalidRequestHeader_Detail(@"Header-1: Value___Vector16________Vector32_\x0D\x0D\x0A") }, + new[] { "Header-1: Value___Vector16________Vector32Value___Vector16_______\rVector32\r\n", CoreStrings.FormatBadRequest_InvalidRequestHeader_Detail(@"Header-1: Value___Vector16________Vector32Value___Vector16_______\x0DVector32\x0D\x0A") }, + new[] { "Header-1: Value___Vector16________Vector32Value___Vector16________Vector32\r\r\n", CoreStrings.FormatBadRequest_InvalidRequestHeader_Detail(@"Header-1: Value___Vector16________Vector32Value___Vector16________Vector32\x0D\x0D\x0A") }, + new[] { "Header-1: Value___Vector16________Vector32Value___Vector16________Vector32_\r\r\n", CoreStrings.FormatBadRequest_InvalidRequestHeader_Detail(@"Header-1: Value___Vector16________Vector32Value___Vector16________Vector32_\x0D\x0D\x0A") }, // Missing colon - new[] { "Header-1 value1\r\n\r\n", @"Invalid request header: 'Header-1 value1\x0D\x0A'" }, - new[] { "Header-1 value1\r\nHeader-2: value2\r\n\r\n", @"Invalid request header: 'Header-1 value1\x0D\x0A'" }, - new[] { "Header-1: value1\r\nHeader-2 value2\r\n\r\n", @"Invalid request header: 'Header-2 value2\x0D\x0A'" }, - new[] { "\n", @"Invalid request header: '\x0A'" }, + new[] { "Header-1 value1\r\n\r\n", CoreStrings.FormatBadRequest_InvalidRequestHeader_Detail(@"Header-1 value1\x0D\x0A") }, + new[] { "Header-1 value1\r\nHeader-2: value2\r\n\r\n", CoreStrings.FormatBadRequest_InvalidRequestHeader_Detail(@"Header-1 value1\x0D\x0A") }, + new[] { "Header-1: value1\r\nHeader-2 value2\r\n\r\n", CoreStrings.FormatBadRequest_InvalidRequestHeader_Detail(@"Header-2 value2\x0D\x0A") }, + new[] { "\n", CoreStrings.FormatBadRequest_InvalidRequestHeader_Detail(@"\x0A") }, // Starting with whitespace - new[] { " Header: value\r\n\r\n", @"Invalid request header: ' Header: value\x0D\x0A'" }, - new[] { "\tHeader: value\r\n\r\n", @"Invalid request header: '\x09Header: value\x0D\x0A'" }, - new[] { " Header-1: value1\r\nHeader-2: value2\r\n\r\n", @"Invalid request header: ' Header-1: value1\x0D\x0A'" }, - new[] { "\tHeader-1: value1\r\nHeader-2: value2\r\n\r\n", @"Invalid request header: '\x09Header-1: value1\x0D\x0A'" }, + new[] { " Header: value\r\n\r\n", CoreStrings.FormatBadRequest_InvalidRequestHeader_Detail(@" Header: value\x0D\x0A") }, + new[] { "\tHeader: value\r\n\r\n", CoreStrings.FormatBadRequest_InvalidRequestHeader_Detail(@"\x09Header: value\x0D\x0A") }, + new[] { " Header-1: value1\r\nHeader-2: value2\r\n\r\n", CoreStrings.FormatBadRequest_InvalidRequestHeader_Detail(@" Header-1: value1\x0D\x0A") }, + new[] { "\tHeader-1: value1\r\nHeader-2: value2\r\n\r\n", CoreStrings.FormatBadRequest_InvalidRequestHeader_Detail(@"\x09Header-1: value1\x0D\x0A") }, // Whitespace in header name - new[] { "Header : value\r\n\r\n", @"Invalid request header: 'Header : value\x0D\x0A'" }, - new[] { "Header\t: value\r\n\r\n", @"Invalid request header: 'Header\x09: value\x0D\x0A'" }, - new[] { "Header\r: value\r\n\r\n", @"Invalid request header: 'Header\x0D: value\x0D\x0A'" }, - new[] { "Header_\rVector16: value\r\n\r\n", @"Invalid request header: 'Header_\x0DVector16: value\x0D\x0A'" }, - new[] { "Header__Vector16\r: value\r\n\r\n", @"Invalid request header: 'Header__Vector16\x0D: value\x0D\x0A'" }, - new[] { "Header__Vector16_\r: value\r\n\r\n", @"Invalid request header: 'Header__Vector16_\x0D: value\x0D\x0A'" }, - new[] { "Header_\rVector16________Vector32: value\r\n\r\n", @"Invalid request header: 'Header_\x0DVector16________Vector32: value\x0D\x0A'" }, - new[] { "Header__Vector16________Vector32\r: value\r\n\r\n", @"Invalid request header: 'Header__Vector16________Vector32\x0D: value\x0D\x0A'" }, - new[] { "Header__Vector16________Vector32_\r: value\r\n\r\n", @"Invalid request header: 'Header__Vector16________Vector32_\x0D: value\x0D\x0A'" }, - new[] { "Header__Vector16________Vector32Header_\rVector16________Vector32: value\r\n\r\n", @"Invalid request header: 'Header__Vector16________Vector32Header_\x0DVector16________Vector32: value\x0D\x0A'" }, - new[] { "Header__Vector16________Vector32Header__Vector16________Vector32\r: value\r\n\r\n", @"Invalid request header: 'Header__Vector16________Vector32Header__Vector16________Vector32\x0D: value\x0D\x0A'" }, - new[] { "Header__Vector16________Vector32Header__Vector16________Vector32_\r: value\r\n\r\n", @"Invalid request header: 'Header__Vector16________Vector32Header__Vector16________Vector32_\x0D: value\x0D\x0A'" }, - new[] { "Header 1: value1\r\nHeader-2: value2\r\n\r\n", @"Invalid request header: 'Header 1: value1\x0D\x0A'" }, - new[] { "Header 1 : value1\r\nHeader-2: value2\r\n\r\n", @"Invalid request header: 'Header 1 : value1\x0D\x0A'" }, - new[] { "Header 1\t: value1\r\nHeader-2: value2\r\n\r\n", @"Invalid request header: 'Header 1\x09: value1\x0D\x0A'" }, - new[] { "Header 1\r: value1\r\nHeader-2: value2\r\n\r\n", @"Invalid request header: 'Header 1\x0D: value1\x0D\x0A'" }, - new[] { "Header-1: value1\r\nHeader 2: value2\r\n\r\n", @"Invalid request header: 'Header 2: value2\x0D\x0A'" }, - new[] { "Header-1: value1\r\nHeader-2 : value2\r\n\r\n", @"Invalid request header: 'Header-2 : value2\x0D\x0A'" }, - new[] { "Header-1: value1\r\nHeader-2\t: value2\r\n\r\n", @"Invalid request header: 'Header-2\x09: value2\x0D\x0A'" }, + new[] { "Header : value\r\n\r\n", CoreStrings.FormatBadRequest_InvalidRequestHeader_Detail(@"Header : value\x0D\x0A") }, + new[] { "Header\t: value\r\n\r\n", CoreStrings.FormatBadRequest_InvalidRequestHeader_Detail(@"Header\x09: value\x0D\x0A") }, + new[] { "Header\r: value\r\n\r\n", CoreStrings.FormatBadRequest_InvalidRequestHeader_Detail(@"Header\x0D: value\x0D\x0A") }, + new[] { "Header_\rVector16: value\r\n\r\n", CoreStrings.FormatBadRequest_InvalidRequestHeader_Detail(@"Header_\x0DVector16: value\x0D\x0A") }, + new[] { "Header__Vector16\r: value\r\n\r\n", CoreStrings.FormatBadRequest_InvalidRequestHeader_Detail(@"Header__Vector16\x0D: value\x0D\x0A") }, + new[] { "Header__Vector16_\r: value\r\n\r\n", CoreStrings.FormatBadRequest_InvalidRequestHeader_Detail(@"Header__Vector16_\x0D: value\x0D\x0A") }, + new[] { "Header_\rVector16________Vector32: value\r\n\r\n", CoreStrings.FormatBadRequest_InvalidRequestHeader_Detail(@"Header_\x0DVector16________Vector32: value\x0D\x0A") }, + new[] { "Header__Vector16________Vector32\r: value\r\n\r\n", CoreStrings.FormatBadRequest_InvalidRequestHeader_Detail(@"Header__Vector16________Vector32\x0D: value\x0D\x0A") }, + new[] { "Header__Vector16________Vector32_\r: value\r\n\r\n", CoreStrings.FormatBadRequest_InvalidRequestHeader_Detail(@"Header__Vector16________Vector32_\x0D: value\x0D\x0A") }, + new[] { "Header__Vector16________Vector32Header_\rVector16________Vector32: value\r\n\r\n", CoreStrings.FormatBadRequest_InvalidRequestHeader_Detail(@"Header__Vector16________Vector32Header_\x0DVector16________Vector32: value\x0D\x0A") }, + new[] { "Header__Vector16________Vector32Header__Vector16________Vector32\r: value\r\n\r\n", CoreStrings.FormatBadRequest_InvalidRequestHeader_Detail(@"Header__Vector16________Vector32Header__Vector16________Vector32\x0D: value\x0D\x0A") }, + new[] { "Header__Vector16________Vector32Header__Vector16________Vector32_\r: value\r\n\r\n", CoreStrings.FormatBadRequest_InvalidRequestHeader_Detail(@"Header__Vector16________Vector32Header__Vector16________Vector32_\x0D: value\x0D\x0A") }, + new[] { "Header 1: value1\r\nHeader-2: value2\r\n\r\n", CoreStrings.FormatBadRequest_InvalidRequestHeader_Detail(@"Header 1: value1\x0D\x0A") }, + new[] { "Header 1 : value1\r\nHeader-2: value2\r\n\r\n", CoreStrings.FormatBadRequest_InvalidRequestHeader_Detail(@"Header 1 : value1\x0D\x0A") }, + new[] { "Header 1\t: value1\r\nHeader-2: value2\r\n\r\n", CoreStrings.FormatBadRequest_InvalidRequestHeader_Detail(@"Header 1\x09: value1\x0D\x0A") }, + new[] { "Header 1\r: value1\r\nHeader-2: value2\r\n\r\n", CoreStrings.FormatBadRequest_InvalidRequestHeader_Detail(@"Header 1\x0D: value1\x0D\x0A") }, + new[] { "Header-1: value1\r\nHeader 2: value2\r\n\r\n", CoreStrings.FormatBadRequest_InvalidRequestHeader_Detail(@"Header 2: value2\x0D\x0A") }, + new[] { "Header-1: value1\r\nHeader-2 : value2\r\n\r\n", CoreStrings.FormatBadRequest_InvalidRequestHeader_Detail(@"Header-2 : value2\x0D\x0A") }, + new[] { "Header-1: value1\r\nHeader-2\t: value2\r\n\r\n", CoreStrings.FormatBadRequest_InvalidRequestHeader_Detail(@"Header-2\x09: value2\x0D\x0A") }, // Headers not ending in CRLF line - new[] { "Header-1: value1\r\nHeader-2: value2\r\n\r\r", @"Invalid request headers: missing final CRLF in header fields." }, - new[] { "Header-1: value1\r\nHeader-2: value2\r\n\r ", @"Invalid request headers: missing final CRLF in header fields." }, - new[] { "Header-1: value1\r\nHeader-2: value2\r\n\r \n", @"Invalid request headers: missing final CRLF in header fields." }, + new[] { "Header-1: value1\r\nHeader-2: value2\r\n\r\r", CoreStrings.BadRequest_InvalidRequestHeadersNoCRLF }, + new[] { "Header-1: value1\r\nHeader-2: value2\r\n\r ", CoreStrings.BadRequest_InvalidRequestHeadersNoCRLF }, + new[] { "Header-1: value1\r\nHeader-2: value2\r\n\r \n", CoreStrings.BadRequest_InvalidRequestHeadersNoCRLF }, }; public static TheoryData HostHeaderData From 0755495ce55d337e35b45721f6e8e4031c913c56 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Thu, 27 Apr 2017 08:46:08 -0700 Subject: [PATCH 1260/1662] Remove Logging dependency from the http parser (#1780) * Remove Logging dependency from the http parser --- .../Internal/Http/HttpParser.cs | 13 ++++++++----- .../KestrelServer.cs | 4 ++-- .../HttpParserTests.cs | 4 ++-- .../FrameWritingBenchmark.cs | 2 +- .../KestrelHttpParserBenchmark.cs | 2 +- .../RequestParsingBenchmark.cs | 2 +- .../ResponseHeaderCollectionBenchmark.cs | 2 +- .../ResponseHeadersWritingBenchmark.cs | 2 +- test/shared/TestServiceContext.cs | 3 ++- 9 files changed, 19 insertions(+), 15 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/HttpParser.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/HttpParser.cs index ba8c0260e5..a9751e245c 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/HttpParser.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/HttpParser.cs @@ -5,18 +5,21 @@ using System.Runtime.CompilerServices; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Internal.System; using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; -using Microsoft.Extensions.Logging; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { public class HttpParser : IHttpParser where TRequestHandler : IHttpHeadersHandler, IHttpRequestLineHandler { - public HttpParser(IKestrelTrace log) + private bool _showErrorDetails; + + public HttpParser() : this(showErrorDetails: true) { - Log = log; } - private IKestrelTrace Log { get; } + public HttpParser(bool showErrorDetails) + { + _showErrorDetails = showErrorDetails; + } // byte types don't have a data type annotation so we pre-cast them; to avoid in-place casts private const byte ByteCR = (byte)'\r'; @@ -488,7 +491,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http private unsafe BadHttpRequestException GetInvalidRequestException(RequestRejectionReason reason, byte* detail, int length) => BadHttpRequestException.GetException( reason, - Log.IsEnabled(LogLevel.Information) + _showErrorDetails ? new Span(detail, length).GetAsciiStringEscaped(Constants.MaxExceptionDetailSize) : string.Empty); } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/KestrelServer.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/KestrelServer.cs index 8d1c26f453..2eb204c0eb 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/KestrelServer.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/KestrelServer.cs @@ -91,7 +91,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core return new ServiceContext { Log = trace, - HttpParserFactory = frameParser => new HttpParser(frameParser.Frame.ServiceContext.Log), + HttpParserFactory = frameParser => new HttpParser(frameParser.Frame.ServiceContext.Log.IsEnabled(LogLevel.Information)), ThreadPool = threadPool, SystemClock = systemClock, DateHeaderValueManager = dateHeaderValueManager, @@ -207,4 +207,4 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core } } } -} \ No newline at end of file +} diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/HttpParserTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/HttpParserTests.cs index b9cc700f1a..c98818f506 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/HttpParserTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/HttpParserTests.cs @@ -417,7 +417,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests Assert.Equal(buffer.End, examined); } - private IHttpParser CreateParser(IKestrelTrace log) => new HttpParser(log); + private IHttpParser CreateParser(IKestrelTrace log) => new HttpParser(log.IsEnabled(LogLevel.Information)); public static IEnumerable RequestLineValidData => HttpParsingData.RequestLineValidData; @@ -463,4 +463,4 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests } } } -} \ No newline at end of file +} diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameWritingBenchmark.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameWritingBenchmark.cs index 3755e5df5c..13d7827c7e 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameWritingBenchmark.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameWritingBenchmark.cs @@ -94,7 +94,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance DateHeaderValueManager = new DateHeaderValueManager(), ServerOptions = new KestrelServerOptions(), Log = new MockTrace(), - HttpParserFactory = f => new HttpParser(log: null) + HttpParserFactory = f => new HttpParser() }; var frameContext = new FrameContext { diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/KestrelHttpParserBenchmark.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/KestrelHttpParserBenchmark.cs index c19bd6ddec..858c973400 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/KestrelHttpParserBenchmark.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/KestrelHttpParserBenchmark.cs @@ -12,7 +12,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance public class KestrelHttpParserBenchmark : IHttpRequestLineHandler, IHttpHeadersHandler { - private readonly HttpParser _parser = new HttpParser(log: null); + private readonly HttpParser _parser = new HttpParser(); private ReadableBuffer _buffer; diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsingBenchmark.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsingBenchmark.cs index ab6b4e93d4..507e4aec80 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsingBenchmark.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsingBenchmark.cs @@ -24,7 +24,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance { var serviceContext = new ServiceContext { - HttpParserFactory = f => new HttpParser(f.Frame.ServiceContext.Log), + HttpParserFactory = f => new HttpParser(), ServerOptions = new KestrelServerOptions() }; var frameContext = new FrameContext diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/ResponseHeaderCollectionBenchmark.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/ResponseHeaderCollectionBenchmark.cs index 9aaf5a61f5..c912dc8932 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/ResponseHeaderCollectionBenchmark.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/ResponseHeaderCollectionBenchmark.cs @@ -170,7 +170,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance { var serviceContext = new ServiceContext { - HttpParserFactory = f => new HttpParser(f.Frame.ServiceContext.Log), + HttpParserFactory = f => new HttpParser(), ServerOptions = new KestrelServerOptions() }; var frameContext = new FrameContext diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/ResponseHeadersWritingBenchmark.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/ResponseHeadersWritingBenchmark.cs index 5d5db64188..c514ab2f09 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/ResponseHeadersWritingBenchmark.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/ResponseHeadersWritingBenchmark.cs @@ -120,7 +120,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance DateHeaderValueManager = new DateHeaderValueManager(), ServerOptions = new KestrelServerOptions(), Log = new MockTrace(), - HttpParserFactory = f => new HttpParser(log: null) + HttpParserFactory = f => new HttpParser() }; var frameContext = new FrameContext diff --git a/test/shared/TestServiceContext.cs b/test/shared/TestServiceContext.cs index b9f3d59be6..349ef91a43 100644 --- a/test/shared/TestServiceContext.cs +++ b/test/shared/TestServiceContext.cs @@ -5,6 +5,7 @@ using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; +using Microsoft.Extensions.Logging; namespace Microsoft.AspNetCore.Testing { @@ -20,7 +21,7 @@ namespace Microsoft.AspNetCore.Testing DateHeaderValueManager = new DateHeaderValueManager(SystemClock); ConnectionManager = new FrameConnectionManager(Log); DateHeaderValue = DateHeaderValueManager.GetDateHeaderValues().String; - HttpParserFactory = frameAdapter => new HttpParser(frameAdapter.Frame.ServiceContext.Log); + HttpParserFactory = frameAdapter => new HttpParser(frameAdapter.Frame.ServiceContext.Log.IsEnabled(LogLevel.Information)); ServerOptions = new KestrelServerOptions { AddServerHeader = false From 79ea2bb9b3788bc51a85fd0dac4a4100cf16e9e5 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Thu, 27 Apr 2017 16:56:07 -0700 Subject: [PATCH 1261/1662] Quick fix for SslStream ODEs in HttpsAdaptedConnection.PrepareRequest (#1786) --- .../Internal/FrameConnection.cs | 13 +++++--- .../HttpsTests.cs | 33 +++++++++++++++++++ 2 files changed, 42 insertions(+), 4 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnection.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnection.cs index 99bf9346d9..81093896ac 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnection.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnection.cs @@ -164,7 +164,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal { Log.LogError(0, ex, $"Uncaught exception from the {nameof(IConnectionAdapter.OnConnectionAsync)} method of an {nameof(IConnectionAdapter)}."); _frameStartedTcs.SetResult(false); - CloseRawPipes(); + _ = CloseRawPipesAsync(); } } @@ -181,15 +181,20 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal } finally { - CloseRawPipes(); + // Don't allow _adaptedPipelineTask to be held up by StopAsync() or else StopAsync() will never complete. + _ = CloseRawPipesAsync(); } } - private void CloseRawPipes() + private async Task CloseRawPipesAsync() { - _filteredStream?.Dispose(); _context.OutputProducer.Dispose(); _context.Input.Reader.Complete(); + + // Wait until request processing is complete before disposing the Stream. + await StopAsync(); + + _filteredStream?.Dispose(); } private void StartFrame() diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/HttpsTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/HttpsTests.cs index 391441ed5b..7890d6316c 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/HttpsTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/HttpsTests.cs @@ -196,6 +196,39 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests await tcs.Task.TimeoutAfter(TimeSpan.FromSeconds(10)); } + // Regression test for https://github.com/aspnet/KestrelHttpServer/issues/1693 + [Fact] + public async Task DoesNotThrowObjectDisposedExceptionOnEmptyConnection() + { + var loggerFactory = new HandshakeErrorLoggerFactory(); + var hostBuilder = new WebHostBuilder() + .UseKestrel(options => + { + options.Listen(new IPEndPoint(IPAddress.Loopback, 0), listenOptions => + { + listenOptions.UseHttps(TestResources.TestCertificatePath, "testPassword"); + }); + }) + .UseLoggerFactory(loggerFactory) + .Configure(app => app.Run(httpContext => Task.CompletedTask)); + + using (var host = hostBuilder.Build()) + { + host.Start(); + + using (var socket = await HttpClientSlim.GetSocket(new Uri($"https://127.0.0.1:{host.GetPort()}/"))) + using (var stream = new NetworkStream(socket, ownsSocket: false)) + using (var sslStream = new SslStream(stream, true, (sender, certificate, chain, errors) => true)) + { + await sslStream.AuthenticateAsClientAsync("127.0.0.1", clientCertificates: null, + enabledSslProtocols: SslProtocols.Tls11 | SslProtocols.Tls12, + checkCertificateRevocation: false); + } + } + + Assert.False(loggerFactory.ErrorLogger.ObjectDisposedExceptionLogged); + } + // Regression test for https://github.com/aspnet/KestrelHttpServer/pull/1197 [Fact] public void ConnectionFilterDoesNotLeakBlock() From 5b62024fc8c059b10c4e38b00cc468b0ac58a1c0 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Thu, 27 Apr 2017 17:55:35 -0700 Subject: [PATCH 1262/1662] * Properly handle FINs and resets in the SocketConnection (#1782) - FIN from the client shouldn't throw - Forced close from the server should throw - Properly wrap connection reset exceptions and other exceptions in IO exceptions - This gives kestrel control over when the output closes - Fixed one test that assumed libuv - Dispose the connection to yield the reader Fixes #1774 --- .../SocketConnection.cs | 59 ++++++++++++++----- .../RequestTests.cs | 5 +- 2 files changed, 48 insertions(+), 16 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets/SocketConnection.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets/SocketConnection.cs index d8378a43c3..7a1dab14c5 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets/SocketConnection.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets/SocketConnection.cs @@ -4,8 +4,10 @@ using System; using System.Collections.Generic; using System.Diagnostics; +using System.IO; using System.Net; using System.Net.Sockets; +using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Internal.System.Buffers; using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; @@ -23,8 +25,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets private IPipeWriter _input; private IPipeReader _output; private IList> _sendBufferList; - - private const int MinAllocBufferSize = 2048; // from libuv transport + private const int MinAllocBufferSize = 2048; internal SocketConnection(Socket socket, SocketTransport transport) { @@ -51,17 +52,20 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets Task receiveTask = DoReceive(); Task sendTask = DoSend(); - // Wait for eiher of them to complete (note they won't throw exceptions) - await Task.WhenAny(receiveTask, sendTask); - - // Shut the socket down and wait for both sides to end - _socket.Shutdown(SocketShutdown.Both); + // If the sending task completes then close the receive + // We don't need to do this in the other direction because the kestrel + // will trigger the output closing once the input is complete. + if (await Task.WhenAny(receiveTask, sendTask) == sendTask) + { + // Tell the reader it's being aborted + _socket.Dispose(); + } // Now wait for both to complete await receiveTask; await sendTask; - // Dispose the socket + // Dispose the socket(should noop if already called) _socket.Dispose(); } catch (Exception) @@ -90,9 +94,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets if (bytesReceived == 0) { - // We receive a FIN so throw an exception so that we cancel the input - // with an error - throw new TaskCanceledException("The request was aborted"); + // FIN + break; } buffer.Advance(bytesReceived); @@ -106,17 +109,45 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets if (result.IsCompleted) { // Pipe consumer is shut down, do we stop writing - _socket.Shutdown(SocketShutdown.Receive); break; } } + _connectionContext.Abort(ex: null); _input.Complete(); } catch (Exception ex) { - _connectionContext.Abort(ex); - _input.Complete(ex); + Exception error = null; + + if (ex is SocketException se) + { + if (se.SocketErrorCode == SocketError.ConnectionReset) + { + // Connection reset + error = new ConnectionResetException(ex.Message, ex); + } + else if (se.SocketErrorCode == SocketError.OperationAborted) + { + error = new TaskCanceledException("The request was aborted"); + } + } + + if (ex is ObjectDisposedException) + { + error = new TaskCanceledException("The request was aborted"); + } + else if (ex is IOException ioe) + { + error = ioe; + } + else if (error == null) + { + error = new IOException(ex.Message, ex); + } + + _connectionContext.Abort(error); + _input.Complete(error); } } diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs index 11c494c242..517b6a0cca 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs @@ -18,6 +18,7 @@ using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions; using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking; using Microsoft.AspNetCore.Testing; using Microsoft.AspNetCore.Testing.xunit; @@ -462,9 +463,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { await context.Request.Body.ReadAsync(new byte[1], 0, 1); } - catch (IOException ex) + catch (ConnectionResetException) { - expectedExceptionThrown = ex.InnerException is UvException && ex.InnerException.Message.Contains("ECONNRESET"); + expectedExceptionThrown = true; } appDone.Release(); From 005b884b7d9d74dcd495b4ae8b27f43b0a3b5763 Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Thu, 27 Apr 2017 18:07:57 -0700 Subject: [PATCH 1263/1662] Build rel/ branches on Travis and AppVeyor. --- .travis.yml | 1 + appveyor.yml | 1 + 2 files changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index 084c199f52..70902067d3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -23,6 +23,7 @@ branches: - dev - feature/dev-si - /^(.*\/)?ci-.*$/ + - /^rel\/.*/ before_install: - if test "$TRAVIS_OS_NAME" == "osx"; then brew update; brew install openssl; ln -s /usr/local/opt/openssl/lib/libcrypto.1.0.0.dylib /usr/local/lib/; ln -s /usr/local/opt/openssl/lib/libssl.1.0.0.dylib /usr/local/lib/; fi script: diff --git a/appveyor.yml b/appveyor.yml index 30450f6367..b17fb327df 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -7,6 +7,7 @@ branches: - dev - feature/dev-si - /^(.*\/)?ci-.*$/ + - /^rel\/.*/ build_script: - ps: .\build.ps1 clone_depth: 1 From 0e372edb2cd77c6865574e9cc2defb729f272f1a Mon Sep 17 00:00:00 2001 From: David Fowler Date: Thu, 27 Apr 2017 20:59:50 -0700 Subject: [PATCH 1264/1662] Removed UseTransportThread (#1781) --- .../KestrelServerOptions.cs | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/KestrelServerOptions.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/KestrelServerOptions.cs index f97e5c3dd3..6719702b9e 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/KestrelServerOptions.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/KestrelServerOptions.cs @@ -29,11 +29,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core /// public bool AddServerHeader { get; set; } = true; - /// - /// Gets or sets a value that determines if Kestrel should use the transport thread thread when executing user code. - /// - public bool UseTransportThread { get; set; } - /// /// Gets or sets a value that determines how Kestrel should schedule user callbacks. /// From 9185deecda2e045fb2d3566dd536181fe15bee35 Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Fri, 28 Apr 2017 09:56:29 -0700 Subject: [PATCH 1265/1662] Avoid port conflicts in AddressRegistrationTests (#1721). --- .../AddressRegistrationTests.cs | 519 +++++++++++------- 1 file changed, 314 insertions(+), 205 deletions(-) diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs index abd6ec612c..e6a112fa48 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs @@ -24,101 +24,145 @@ using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using Xunit; using Xunit.Abstractions; +using Xunit.Sdk; namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { public class AddressRegistrationTests { - private readonly ILoggerFactory _logger; + private const int MaxRetries = 10; - public AddressRegistrationTests(ITestOutputHelper output) => _logger = new LoggerFactory().AddXunit(output); + private readonly ILoggerFactory _loggerFactory; + + public AddressRegistrationTests(ITestOutputHelper output) => _loggerFactory = new LoggerFactory().AddXunit(output); [ConditionalFact] [NetworkIsReachable] public async Task RegisterAddresses_HostName_Success() { var hostName = Dns.GetHostName(); - string FixUrl(string url) - { - return url - .Replace("0.0.0.0", hostName) - .Replace("[::]", hostName); - } - - await RegisterAddresses_Success($"http://{hostName}:0", a => a.Addresses.Select(FixUrl).ToArray()); + await RegisterAddresses_Success($"http://{hostName}:0", $"http://{hostName}"); } - [Theory, MemberData(nameof(AddressRegistrationDataIPv4))] - public async Task RegisterAddresses_IPv4_Success(string addressInput, Func testUrls) + [Theory] + [MemberData(nameof(AddressRegistrationDataIPv4))] + public async Task RegisterAddresses_IPv4_Success(string addressInput, string testUrl) { - await RegisterAddresses_Success(addressInput, testUrls); + await RegisterAddresses_Success(addressInput, testUrl); } - [ConditionalTheory, MemberData(nameof(AddressRegistrationDataIPv4Port5000Default))] + [ConditionalTheory] + [MemberData(nameof(AddressRegistrationDataIPv4Port5000Default))] [PortSupportedCondition(5000)] - public async Task RegisterAddresses_IPv4Port5000Default_Success(string addressInput, Func testUrls) + public async Task RegisterAddresses_IPv4Port5000Default_Success(string addressInput, string testUrl) { - await RegisterAddresses_Success(addressInput, testUrls); + await RegisterAddresses_Success(addressInput, testUrl, 5000); } - [ConditionalTheory, MemberData(nameof(AddressRegistrationDataIPv4Port80))] + [ConditionalTheory] + [MemberData(nameof(AddressRegistrationDataIPv4Port80))] [PortSupportedCondition(80)] - public async Task RegisterAddresses_IPv4Port80_Success(string addressInput, Func testUrls) + public async Task RegisterAddresses_IPv4Port80_Success(string addressInput, string testUrl) { - await RegisterAddresses_Success(addressInput, testUrls); + await RegisterAddresses_Success(addressInput, testUrl, 80); } - [ConditionalTheory, MemberData(nameof(IPEndPointRegistrationDataRandomPort))] + [Fact] + public async Task RegisterAddresses_IPv4StaticPort_Success() + { + await RegisterAddresses_StaticPort_Success("http://127.0.0.1", "http://127.0.0.1"); + } + + [Fact] + public async Task RegisterAddresses_IPv4LocalhostStaticPort_Success() + { + await RegisterAddresses_StaticPort_Success("http://localhost", "http://127.0.0.1"); + } + + [Fact] + public async Task RegisterIPEndPoint_IPv4StaticPort_Success() + { + await RegisterIPEndPoint_StaticPort_Success(IPAddress.Loopback, $"http://127.0.0.1"); + } + + [ConditionalFact] [IPv6SupportedCondition] - public async Task RegisterIPEndPoint_RandomPort_Success(IPEndPoint endPoint, Func testUrl) + public async Task RegisterIPEndPoint_IPv6StaticPort_Success() + { + await RegisterIPEndPoint_StaticPort_Success(IPAddress.IPv6Loopback, $"http://[::1]"); + } + + [ConditionalTheory] + [MemberData(nameof(IPEndPointRegistrationDataDynamicPort))] + [IPv6SupportedCondition] + public async Task RegisterIPEndPoint_DynamicPort_Success(IPEndPoint endPoint, string testUrl) { await RegisterIPEndPoint_Success(endPoint, testUrl); } - [ConditionalTheory, MemberData(nameof(IPEndPointRegistrationDataPort443))] + [ConditionalTheory] + [MemberData(nameof(IPEndPointRegistrationDataPort443))] [IPv6SupportedCondition] [PortSupportedCondition(443)] - public async Task RegisterIPEndPoint_Port443_Success(IPEndPoint endpoint, Func testUrl) + public async Task RegisterIPEndPoint_Port443_Success(IPEndPoint endpoint, string testUrl) { - await RegisterIPEndPoint_Success(endpoint, testUrl); + await RegisterIPEndPoint_Success(endpoint, testUrl, 443); } - [ConditionalTheory, MemberData(nameof(AddressRegistrationDataIPv6))] + [ConditionalTheory] + [MemberData(nameof(AddressRegistrationDataIPv6))] [IPv6SupportedCondition] - public async Task RegisterAddresses_IPv6_Success(string addressInput, Func testUrls) + public async Task RegisterAddresses_IPv6_Success(string addressInput, string[] testUrls) { await RegisterAddresses_Success(addressInput, testUrls); } - [ConditionalTheory, MemberData(nameof(AddressRegistrationDataIPv6Port5000Default))] + [ConditionalTheory] + [MemberData(nameof(AddressRegistrationDataIPv6Port5000Default))] [IPv6SupportedCondition] [PortSupportedCondition(5000)] - public async Task RegisterAddresses_IPv6Port5000Default_Success(string addressInput, Func testUrls) + public async Task RegisterAddresses_IPv6Port5000Default_Success(string addressInput, string[] testUrls) { await RegisterAddresses_Success(addressInput, testUrls); } - [ConditionalTheory, MemberData(nameof(AddressRegistrationDataIPv6Port80))] + [ConditionalTheory] + [MemberData(nameof(AddressRegistrationDataIPv6Port80))] [IPv6SupportedCondition] [PortSupportedCondition(80)] - public async Task RegisterAddresses_IPv6Port80_Success(string addressInput, Func testUrls) + public async Task RegisterAddresses_IPv6Port80_Success(string addressInput, string[] testUrls) { await RegisterAddresses_Success(addressInput, testUrls); } - [ConditionalTheory, MemberData(nameof(AddressRegistrationDataIPv6ScopeId))] + [ConditionalTheory] + [MemberData(nameof(AddressRegistrationDataIPv6ScopeId))] [IPv6SupportedCondition] [IPv6ScopeIdPresentCondition] - public async Task RegisterAddresses_IPv6ScopeId_Success(string addressInput, Func testUrls) + public async Task RegisterAddresses_IPv6ScopeId_Success(string addressInput, string testUrl) { - await RegisterAddresses_Success(addressInput, testUrls); + await RegisterAddresses_Success(addressInput, testUrl); } - private async Task RegisterAddresses_Success(string addressInput, Func testUrls) + [ConditionalFact] + [IPv6SupportedCondition] + public async Task RegisterAddresses_IPv6StaticPort_Success() + { + await RegisterAddresses_StaticPort_Success("http://[::1]", "http://[::1]"); + } + + [ConditionalFact] + [IPv6SupportedCondition] + public async Task RegisterAddresses_IPv6LocalhostStaticPort_Success() + { + await RegisterAddresses_StaticPort_Success("http://localhost", new[] { "http://localhost", "http://127.0.0.1", "http://[::1]" }); + } + + private async Task RegisterAddresses_Success(string addressInput, string[] testUrls, int testPort = 0) { var hostBuilder = new WebHostBuilder() .UseKestrel() - .UseLoggerFactory(_logger) + .UseLoggerFactory(_loggerFactory) .UseUrls(addressInput) .Configure(ConfigureEchoAddress); @@ -126,7 +170,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { host.Start(); - foreach (var testUrl in testUrls(host.ServerFeatures.Get())) + foreach (var testUrl in testUrls.Select(testUrl => $"{testUrl}:{(testPort == 0 ? host.GetPort() : testPort)}")) { var response = await HttpClientSlim.GetStringAsync(testUrl, validateCertificate: false); @@ -137,15 +181,52 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } } - private async Task RegisterIPEndPoint_Success(IPEndPoint endPoint, Func testUrl) + private Task RegisterAddresses_Success(string addressInput, string testUrl, int testPort = 0) + => RegisterAddresses_Success(addressInput, new[] { testUrl }, testPort); + + private async Task RegisterAddresses_StaticPort_Success(string addressInput, string[] testUrls) + { + var retryCount = 0; + var errors = new List(); + + while (retryCount < MaxRetries) + { + try + { + var port = GetNextPort(); + await RegisterAddresses_Success($"{addressInput}:{port}", testUrls, port); + return; + } + catch (XunitException) + { + throw; + } + catch (Exception ex) + { + errors.Add(ex); + } + + retryCount++; + } + + if (errors.Any()) + { + throw new AggregateException(errors); + } + } + + private Task RegisterAddresses_StaticPort_Success(string addressInput, string testUrl) + => RegisterAddresses_StaticPort_Success(addressInput, new[] { testUrl }); + + private async Task RegisterIPEndPoint_Success(IPEndPoint endPoint, string testUrl, int testPort = 0) { var hostBuilder = new WebHostBuilder() - .UseLoggerFactory(_logger) + .UseLoggerFactory(_loggerFactory) .UseKestrel(options => { options.Listen(endPoint, listenOptions => { - if (testUrl(listenOptions.IPEndPoint).StartsWith("https")) + if (testUrl.StartsWith("https")) { listenOptions.UseHttps(TestResources.TestCertificatePath, "testPassword"); } @@ -157,15 +238,47 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { host.Start(); + var testUrlWithPort = $"{testUrl}:{(testPort == 0 ? host.GetPort() : testPort)}"; + var options = ((IOptions)host.Services.GetService(typeof(IOptions))).Value; Assert.Single(options.ListenOptions); - var listenOptions = options.ListenOptions[0]; - var response = await HttpClientSlim.GetStringAsync(testUrl(listenOptions.IPEndPoint), validateCertificate: false); + var response = await HttpClientSlim.GetStringAsync(testUrlWithPort, validateCertificate: false); // Compare the response with Uri.ToString(), rather than testUrl directly. // Required to handle IPv6 addresses with zone index, like "fe80::3%1" - Assert.Equal(new Uri(testUrl(listenOptions.IPEndPoint)).ToString(), response); + Assert.Equal(new Uri(testUrlWithPort).ToString(), response); + } + } + + private async Task RegisterIPEndPoint_StaticPort_Success(IPAddress address, string testUrl) + { + var retryCount = 0; + var errors = new List(); + + while (retryCount < MaxRetries) + { + try + { + var port = GetNextPort(); + await RegisterIPEndPoint_Success(new IPEndPoint(address, port), testUrl, port); + return; + } + catch (XunitException) + { + throw; + } + catch (Exception ex) + { + errors.Add(ex); + } + + retryCount++; + } + + if (errors.Any()) + { + throw new AggregateException(errors); } } @@ -189,7 +302,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests var testLogger = new TestApplicationErrorLogger(); var hostBuilder = new WebHostBuilder() - .UseLoggerFactory(_logger) + .UseLoggerFactory(_loggerFactory) .UseKestrel() .UseLoggerFactory(_ => new KestrelTestLoggerFactory(testLogger)) .Configure(ConfigureEchoAddress); @@ -215,11 +328,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { using (var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)) { - var port = GetNextPort(); - socket.Bind(new IPEndPoint(IPAddress.Loopback, port)); + socket.Bind(new IPEndPoint(IPAddress.Loopback, 0)); + var port = ((IPEndPoint)socket.LocalEndPoint).Port; var hostBuilder = new WebHostBuilder() - .UseLoggerFactory(_logger) + .UseLoggerFactory(_loggerFactory) .UseKestrel() .UseUrls($"http://127.0.0.1:{port}") .Configure(ConfigureEchoAddress); @@ -238,11 +351,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { using (var socket = new Socket(AddressFamily.InterNetworkV6, SocketType.Stream, ProtocolType.Tcp)) { - var port = GetNextPort(); - socket.Bind(new IPEndPoint(IPAddress.IPv6Loopback, port)); + socket.Bind(new IPEndPoint(IPAddress.IPv6Loopback, 0)); + var port = ((IPEndPoint)socket.LocalEndPoint).Port; var hostBuilder = new WebHostBuilder() - .UseLoggerFactory(_logger) + .UseLoggerFactory(_loggerFactory) .UseKestrel() .UseUrls($"http://[::1]:{port}") .Configure(ConfigureEchoAddress); @@ -258,15 +371,17 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [Fact] public async Task OverrideDirectConfigurationWithIServerAddressesFeature_Succeeds() { - var overrideAddressPort = GetNextPort(); - var listenOptionsPort = GetNextPort(); - - var overrideAddress = $"http://localhost:{overrideAddressPort}"; + var useUrlsAddress = $"http://127.0.0.1:0"; var testLogger = new TestApplicationErrorLogger(); - var hostBuilder = new WebHostBuilder() - .UseKestrel(options => options.Listen(IPAddress.Loopback, listenOptionsPort)) - .UseUrls(overrideAddress) + .UseKestrel(options => + { + options.Listen(new IPEndPoint(IPAddress.Loopback, 0), listenOptions => + { + listenOptions.UseHttps("testCert.pfx", "testPassword"); + }); + }) + .UseUrls(useUrlsAddress) .PreferHostingUrls(true) .UseLoggerFactory(_ => new KestrelTestLoggerFactory(testLogger)) .Configure(ConfigureEchoAddress); @@ -275,48 +390,75 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { host.Start(); - Assert.Equal(overrideAddressPort, host.GetPort()); + var port = host.GetPort(); + + // If this isn't working properly, we'll get the HTTPS endpoint defined in UseKestrel + // instead of the HTTP endpoint defined in UseUrls. + var serverAddresses = host.ServerFeatures.Get().Addresses; + Assert.Equal(1, serverAddresses.Count); + var useUrlsAddressWithPort = $"http://127.0.0.1:{port}"; + Assert.Equal(serverAddresses.First(), useUrlsAddressWithPort); + Assert.Single(testLogger.Messages, log => log.LogLevel == LogLevel.Information && - string.Equals($"Overriding endpoints defined in UseKestrel() since {nameof(IServerAddressesFeature.PreferHostingUrls)} is set to true. Binding to address(es) '{overrideAddress}' instead.", + string.Equals($"Overriding endpoints defined in UseKestrel() since {nameof(IServerAddressesFeature.PreferHostingUrls)} is set to true. Binding to address(es) '{useUrlsAddress}' instead.", log.Message, StringComparison.Ordinal)); - Assert.Equal(new Uri(overrideAddress).ToString(), await HttpClientSlim.GetStringAsync(overrideAddress)); + Assert.Equal(new Uri(useUrlsAddressWithPort).ToString(), await HttpClientSlim.GetStringAsync(useUrlsAddressWithPort)); } } [Fact] public async Task DoesNotOverrideDirectConfigurationWithIServerAddressesFeature_IfPreferHostingUrlsFalse() { - var endPointPort = GetNextPort(); - var useUrlsPort = GetNextPort(); - - var endPointAddress = $"http://localhost:{endPointPort}"; - + var useUrlsAddress = $"http://127.0.0.1:0"; + var testLogger = new TestApplicationErrorLogger(); var hostBuilder = new WebHostBuilder() - .UseLoggerFactory(_logger) - .UseKestrel(options => options.Listen(IPAddress.Loopback, endPointPort)) - .UseUrls($"http://localhost:{useUrlsPort}") + .UseLoggerFactory(_loggerFactory) + .UseKestrel(options => + { + options.Listen(new IPEndPoint(IPAddress.Loopback, 0), listenOptions => + { + listenOptions.UseHttps("testCert.pfx", "testPassword"); + }); + }) + .UseUrls($"http://127.0.0.1:0") .PreferHostingUrls(false) + .UseLoggerFactory(_ => new KestrelTestLoggerFactory(testLogger)) .Configure(ConfigureEchoAddress); using (var host = hostBuilder.Build()) { host.Start(); - Assert.Equal(endPointPort, host.GetPort()); - Assert.Equal(new Uri(endPointAddress).ToString(), await HttpClientSlim.GetStringAsync(endPointAddress)); + var port = host.GetPort(); + + // If this isn't working properly, we'll get the HTTP endpoint defined in UseUrls + // instead of the HTTPS endpoint defined in UseKestrel. + var serverAddresses = host.ServerFeatures.Get().Addresses; + Assert.Equal(1, serverAddresses.Count); + var endPointAddress = $"https://127.0.0.1:{port}"; + Assert.Equal(serverAddresses.First(), endPointAddress); + + Assert.Single(testLogger.Messages, log => log.LogLevel == LogLevel.Warning && + string.Equals($"Overriding address(es) {useUrlsAddress}. Binding to endpoints defined in UseKestrel() instead.", + log.Message, StringComparison.Ordinal)); + + Assert.Equal(new Uri(endPointAddress).ToString(), await HttpClientSlim.GetStringAsync(endPointAddress, validateCertificate: false)); } } [Fact] public async Task DoesNotOverrideDirectConfigurationWithIServerAddressesFeature_IfAddressesEmpty() { - var endPointPort = GetNextPort(); - var endPointAddress = $"http://localhost:{endPointPort}"; - var hostBuilder = new WebHostBuilder() - .UseLoggerFactory(_logger) - .UseKestrel(options => options.Listen(IPAddress.Loopback, endPointPort)) + .UseLoggerFactory(_loggerFactory) + .UseKestrel(options => + { + options.Listen(new IPEndPoint(IPAddress.Loopback, 0), listenOptions => + { + listenOptions.UseHttps("testCert.pfx", "testPassword"); + }); + }) .PreferHostingUrls(true) .Configure(ConfigureEchoAddress); @@ -324,8 +466,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { host.Start(); - Assert.Equal(endPointPort, host.GetPort()); - Assert.Equal(new Uri(endPointAddress).ToString(), await HttpClientSlim.GetStringAsync(endPointAddress)); + var port = host.GetPort(); + + // If this isn't working properly, we'll not get the HTTPS endpoint defined in UseKestrel. + var serverAddresses = host.ServerFeatures.Get().Addresses; + Assert.Equal(1, serverAddresses.Count); + var endPointAddress = $"https://127.0.0.1:{port}"; + Assert.Equal(serverAddresses.First(), endPointAddress); + + Assert.Equal(new Uri(endPointAddress).ToString(), await HttpClientSlim.GetStringAsync(endPointAddress, validateCertificate: false)); } } @@ -346,9 +495,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests public void ThrowsWhenBindingLocalhostToDynamicPort() { var hostBuilder = new WebHostBuilder() - .UseKestrel() - .UseUrls("http://localhost:0") - .Configure(ConfigureEchoAddress); + .UseKestrel() + .UseUrls("http://localhost:0") + .Configure(ConfigureEchoAddress); using (var host = hostBuilder.Build()) { @@ -362,9 +511,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests public void ThrowsForUnsupportedAddressFromHosting(string addr) { var hostBuilder = new WebHostBuilder() - .UseKestrel() - .UseUrls(addr) - .Configure(ConfigureEchoAddress); + .UseKestrel() + .UseUrls(addr) + .Configure(ConfigureEchoAddress); using (var host = hostBuilder.Build()) { @@ -376,11 +525,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { using (var socket = new Socket(addressFamily, SocketType.Stream, ProtocolType.Tcp)) { - var port = GetNextPort(); - socket.Bind(new IPEndPoint(address, port)); + socket.Bind(new IPEndPoint(address, 0)); + var port = ((IPEndPoint)socket.LocalEndPoint).Port; var hostBuilder = new WebHostBuilder() - .UseLoggerFactory(_logger) + .UseLoggerFactory(_loggerFactory) .UseKestrel() .UseUrls($"http://localhost:{port}") .Configure(ConfigureEchoAddress); @@ -395,202 +544,162 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } } - public static TheoryData> AddressRegistrationDataIPv4 + public static TheoryData AddressRegistrationDataIPv4 { get { - var dataset = new TheoryData>(); - - // Static ports - var port = GetNextPort(); + var dataset = new TheoryData(); // Loopback - dataset.Add($"http://127.0.0.1:{port}", _ => new[] { $"http://127.0.0.1:{port}/" }); - - // Localhost - dataset.Add($"http://localhost:{port}", _ => new[] { $"http://localhost:{port}/", $"http://127.0.0.1:{port}/" }); + dataset.Add("http://127.0.0.1:0", "http://127.0.0.1"); // Any - dataset.Add($"http://*:{port}/", _ => new[] { $"http://127.0.0.1:{port}/" }); - dataset.Add($"http://+:{port}/", _ => new[] { $"http://127.0.0.1:{port}/" }); - - // Dynamic port addresses - dataset.Add("http://127.0.0.1:0/", f => f.Addresses.ToArray()); + dataset.Add("http://*:0/", "http://127.0.0.1"); + dataset.Add("http://+:0/", "http://127.0.0.1"); + // Non-loopback addresses var ipv4Addresses = GetIPAddresses() .Where(ip => ip.AddressFamily == AddressFamily.InterNetwork); foreach (var ip in ipv4Addresses) { - dataset.Add($"http://{ip}:0/", f => f.Addresses.ToArray()); + dataset.Add($"http://{ip}:0/", $"http://{ip}"); } return dataset; } } - public static TheoryData> AddressRegistrationDataIPv4Port5000Default => - new TheoryData> + public static TheoryData AddressRegistrationDataIPv4Port5000Default => + new TheoryData { - { null, _ => new[] { "http://127.0.0.1:5000/" } }, - { string.Empty, _ => new[] { "http://127.0.0.1:5000/" } } + { null, "http://127.0.0.1:5000/" }, + { string.Empty, "http://127.0.0.1:5000/" } }; - public static TheoryData> IPEndPointRegistrationDataRandomPort + public static TheoryData IPEndPointRegistrationDataDynamicPort { get { - var dataset = new TheoryData>(); - - // Static port - var port = GetNextPort(); + var dataset = new TheoryData(); // Loopback - dataset.Add(new IPEndPoint(IPAddress.Loopback, port), _ => $"http://127.0.0.1:{port}/"); - dataset.Add(new IPEndPoint(IPAddress.Loopback, port), _ => $"https://127.0.0.1:{port}/"); + dataset.Add(new IPEndPoint(IPAddress.Loopback, 0), "http://127.0.0.1"); + dataset.Add(new IPEndPoint(IPAddress.Loopback, 0), "https://127.0.0.1"); // IPv6 loopback - dataset.Add(new IPEndPoint(IPAddress.IPv6Loopback, port), _ => $"http://[::1]:{port}/"); - dataset.Add(new IPEndPoint(IPAddress.IPv6Loopback, port), _ => $"https://[::1]:{port}/"); + dataset.Add(new IPEndPoint(IPAddress.IPv6Loopback, 0), "http://[::1]"); + dataset.Add(new IPEndPoint(IPAddress.IPv6Loopback, 0), "https://[::1]"); // Any - dataset.Add(new IPEndPoint(IPAddress.Any, port), _ => $"http://127.0.0.1:{port}/"); - dataset.Add(new IPEndPoint(IPAddress.Any, port), _ => $"https://127.0.0.1:{port}/"); + dataset.Add(new IPEndPoint(IPAddress.Any, 0), "http://127.0.0.1"); + dataset.Add(new IPEndPoint(IPAddress.Any, 0), "https://127.0.0.1"); // IPv6 Any - dataset.Add(new IPEndPoint(IPAddress.IPv6Any, port), _ => $"http://127.0.0.1:{port}/"); - dataset.Add(new IPEndPoint(IPAddress.IPv6Any, port), _ => $"http://[::1]:{port}/"); - dataset.Add(new IPEndPoint(IPAddress.IPv6Any, port), _ => $"https://127.0.0.1:{port}/"); - dataset.Add(new IPEndPoint(IPAddress.IPv6Any, port), _ => $"https://[::1]:{port}/"); - - // Dynamic port - dataset.Add(new IPEndPoint(IPAddress.Loopback, 0), endPoint => $"http://127.0.0.1:{endPoint.Port}/"); - dataset.Add(new IPEndPoint(IPAddress.Loopback, 0), endPoint => $"https://127.0.0.1:{endPoint.Port}/"); + dataset.Add(new IPEndPoint(IPAddress.IPv6Any, 0), "http://127.0.0.1"); + dataset.Add(new IPEndPoint(IPAddress.IPv6Any, 0), "http://[::1]"); + dataset.Add(new IPEndPoint(IPAddress.IPv6Any, 0), "https://127.0.0.1"); + dataset.Add(new IPEndPoint(IPAddress.IPv6Any, 0), "https://[::1]"); + // Non-loopback addresses var ipv4Addresses = GetIPAddresses() .Where(ip => ip.AddressFamily == AddressFamily.InterNetwork); foreach (var ip in ipv4Addresses) { - dataset.Add(new IPEndPoint(ip, 0), endPoint => $"http://{endPoint}/"); - dataset.Add(new IPEndPoint(ip, 0), endPoint => $"https://{endPoint}/"); + dataset.Add(new IPEndPoint(ip, 0), $"http://{ip}"); + dataset.Add(new IPEndPoint(ip, 0), $"https://{ip}"); } - return dataset; - } - } - - public static TheoryData> AddressRegistrationDataIPv4Port80 - { - get - { - var dataset = new TheoryData>(); - - // Default port for HTTP (80) - dataset.Add("http://127.0.0.1", _ => new[] { "http://127.0.0.1/" }); - dataset.Add("http://localhost", _ => new[] { "http://127.0.0.1/" }); - dataset.Add("http://*", _ => new[] { "http://127.0.0.1/" }); - - return dataset; - } - } - - public static TheoryData> IPEndPointRegistrationDataPort443 - { - get - { - var dataset = new TheoryData>(); - - dataset.Add(new IPEndPoint(IPAddress.Loopback, 443), _ => "https://127.0.0.1/"); - dataset.Add(new IPEndPoint(IPAddress.IPv6Loopback, 443), _ => "https://[::1]/"); - dataset.Add(new IPEndPoint(IPAddress.Any, 443), _ => "https://127.0.0.1/"); - dataset.Add(new IPEndPoint(IPAddress.IPv6Any, 443), _ => "https://[::1]/"); - - return dataset; - } - } - - public static TheoryData> AddressRegistrationDataIPv6 - { - get - { - var dataset = new TheoryData>(); - - // Static ports - var port = GetNextPort(); - - // Loopback - dataset.Add($"http://[::1]:{port}/", - _ => new[] { $"http://[::1]:{port}/" }); - - // Localhost - dataset.Add($"http://localhost:{port}", - _ => new[] { $"http://localhost:{port}/", $"http://127.0.0.1:{port}/", $"http://[::1]:{port}/" }); - - // Any - dataset.Add($"http://*:{port}/", - _ => new[] { $"http://127.0.0.1:{port}/", $"http://[::1]:{port}/" }); - dataset.Add($"http://+:{port}/", - _ => new[] { $"http://127.0.0.1:{port}/", $"http://[::1]:{port}/" }); - - // Explicit IPv4 and IPv6 on same port - dataset.Add($"http://127.0.0.1:{port}/;http://[::1]:{port}/", - _ => new[] { $"http://127.0.0.1:{port}/", $"http://[::1]:{port}/" }); - - // Dynamic port and non-loopback addresses var ipv6Addresses = GetIPAddresses() .Where(ip => ip.AddressFamily == AddressFamily.InterNetworkV6) .Where(ip => ip.ScopeId == 0); - foreach (var ip in ipv6Addresses) { - dataset.Add($"http://[{ip}]:0/", f => f.Addresses.ToArray()); + dataset.Add(new IPEndPoint(ip, 0), $"http://[{ip}]"); } return dataset; } } - public static TheoryData> AddressRegistrationDataIPv6Port5000Default => - new TheoryData> + public static TheoryData AddressRegistrationDataIPv4Port80 => + new TheoryData { - { null, _ => new[] { "http://127.0.0.1:5000/", "http://[::1]:5000/" } }, - { string.Empty, _ => new[] { "http://127.0.0.1:5000/", "http://[::1]:5000/" } } + // Default port for HTTP (80) + { "http://127.0.0.1", "http://127.0.0.1" }, + { "http://localhost", "http://127.0.0.1" }, + { "http://*", "http://127.0.0.1" } }; - public static TheoryData> AddressRegistrationDataIPv6Port80 + public static TheoryData IPEndPointRegistrationDataPort443 => + new TheoryData + { + + { new IPEndPoint(IPAddress.Loopback, 443), "https://127.0.0.1" }, + { new IPEndPoint(IPAddress.IPv6Loopback, 443), "https://[::1]" }, + { new IPEndPoint(IPAddress.Any, 443), "https://127.0.0.1" }, + { new IPEndPoint(IPAddress.IPv6Any, 443), "https://[::1]" } + }; + + public static TheoryData AddressRegistrationDataIPv6 { get { - var dataset = new TheoryData>(); + var dataset = new TheoryData(); - // Default port for HTTP (80) - dataset.Add("http://[::1]", _ => new[] { "http://[::1]/" }); - dataset.Add("http://localhost", _ => new[] { "http://127.0.0.1/", "http://[::1]/" }); - dataset.Add("http://*", _ => new[] { "http://[::1]/" }); + // Loopback + dataset.Add($"http://[::1]:0/", new[] { $"http://[::1]" }); + + // Any + dataset.Add($"http://*:0/", new[] { $"http://127.0.0.1", $"http://[::1]" }); + dataset.Add($"http://+:0/", new[] { $"http://127.0.0.1", $"http://[::1]" }); + + // Non-loopback addresses + var ipv6Addresses = GetIPAddresses() + .Where(ip => ip.AddressFamily == AddressFamily.InterNetworkV6) + .Where(ip => ip.ScopeId == 0); + foreach (var ip in ipv6Addresses) + { + dataset.Add($"http://[{ip}]:0/", new[] { $"http://[{ip}]" }); + } return dataset; } } - public static TheoryData> AddressRegistrationDataIPv6ScopeId + public static TheoryData AddressRegistrationDataIPv6Port5000Default => + new TheoryData + { + { null, new[] { "http://127.0.0.1:5000/", "http://[::1]:5000/" } }, + { string.Empty, new[] { "http://127.0.0.1:5000/", "http://[::1]:5000/" } } + }; + + public static TheoryData AddressRegistrationDataIPv6Port80 => + new TheoryData + { + // Default port for HTTP (80) + { "http://[::1]", new[] { "http://[::1]/" } }, + { "http://localhost", new[] { "http://127.0.0.1/", "http://[::1]/" } }, + { "http://*", new[] { "http://[::1]/" } } + }; + + public static TheoryData AddressRegistrationDataIPv6ScopeId { get { - var dataset = new TheoryData>(); + var dataset = new TheoryData(); - // Dynamic port var ipv6Addresses = GetIPAddresses() .Where(ip => ip.AddressFamily == AddressFamily.InterNetworkV6) .Where(ip => ip.ScopeId != 0) .Where(ip => CanBindAndConnectToEndpoint(new IPEndPoint(ip, 0))); - foreach (var ip in ipv6Addresses) { - dataset.Add($"http://[{ip}]:0/", f => f.Addresses.ToArray()); + dataset.Add($"http://[{ip}]:0/", $"http://[{ip}]"); } // There may be no addresses with scope IDs and we need at least one data item in the // collection, otherwise xUnit fails the test run because a theory has no data. - dataset.Add("http://[::1]:0", f => f.Addresses.ToArray()); + dataset.Add("http://[::1]:0", "http://[::1]"); return dataset; } From 749e282102787fef75c5ed3a6830e59871c13d1f Mon Sep 17 00:00:00 2001 From: David Fowler Date: Sat, 29 Apr 2017 00:41:48 -0700 Subject: [PATCH 1266/1662] Prepare for OnReader/WriterCallbacks changes (#1791) - This change does a few things: 1. It adds the events we will replace with pipe events to IConnectionContext and IConnectionInformation to get out of band notifications about pipe completions. 2. It also implements those callbacks and exposing slight changes we'll need to make once we have them. The idea is that we can delete/replace these methods once we have the new pipe API and things will keep working. --- .../Internal/FrameConnection.cs | 5 +- .../Internal/Http/OutputProducer.cs | 27 +++--- .../IConnectionContext.cs | 4 +- .../Internal/LibuvConnection.cs | 13 ++- .../Internal/LibuvConnectionContext.cs | 1 + .../SocketConnection.cs | 83 ++++++++++--------- .../Mocks/MockConnectionInformation.cs | 1 + .../LibuvOutputConsumerTests.cs | 19 +++-- .../TestHelpers/MockConnectionHandler.cs | 5 +- 9 files changed, 84 insertions(+), 74 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnection.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnection.cs index 99bf9346d9..25e44c1df4 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnection.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnection.cs @@ -87,8 +87,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal } } - public async void OnConnectionClosed() + public async void OnConnectionClosed(Exception ex) { + // Abort the connection (if it isn't already aborted) + _frame.Abort(ex); + Log.ConnectionStop(ConnectionId); KestrelEventSource.Log.ConnectionStop(this); _socketClosedTcs.SetResult(null); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/OutputProducer.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/OutputProducer.cs index 5e94d3e47f..c5fe3dee51 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/OutputProducer.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/OutputProducer.cs @@ -31,6 +31,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http // this is temporary until it does private TaskCompletionSource _flushTcs; private readonly object _flushLock = new object(); + private Action _flushCompleted; public OutputProducer(IPipeWriter pipe, Frame frame, string connectionId, IKestrelTrace log) { @@ -38,6 +39,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http _frame = frame; _connectionId = connectionId; _log = log; + _flushCompleted = OnFlushCompleted; } public Task WriteAsync( @@ -83,8 +85,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http var awaitable = writableBuffer.FlushAsync(cancellationToken); if (awaitable.IsCompleted) { - AbortIfNeeded(awaitable); - // The flush task can't fail today return TaskCache.CompletedTask; } @@ -103,27 +103,22 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { _flushTcs = new TaskCompletionSource(); - awaitable.OnCompleted(() => - { - AbortIfNeeded(awaitable); - _flushTcs.TrySetResult(null); - }); + awaitable.OnCompleted(_flushCompleted); } } await _flushTcs.Task; + + if (cancellationToken.IsCancellationRequested) + { + _frame.Abort(error: null); + } + cancellationToken.ThrowIfCancellationRequested(); } - private void AbortIfNeeded(WritableBufferAwaitable awaitable) + private void OnFlushCompleted() { - try - { - awaitable.GetResult(); - } - catch (Exception ex) - { - _frame.Abort(ex); - } + _flushTcs.TrySetResult(null); } void ISocketOutput.Write(ArraySegment buffer, bool chunk) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/IConnectionContext.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/IConnectionContext.cs index 84e491fed1..d05110b930 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/IConnectionContext.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/IConnectionContext.cs @@ -13,8 +13,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions IPipeWriter Input { get; } IPipeReader Output { get; } - // TODO: Remove these (Use Pipes Tasks instead?) - void OnConnectionClosed(); + // TODO: Remove these (https://github.com/aspnet/KestrelHttpServer/issues/1772) + void OnConnectionClosed(Exception ex); void Abort(Exception ex); } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvConnection.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvConnection.cs index 0bfc0446c8..d9dac68dd3 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvConnection.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvConnection.cs @@ -66,17 +66,18 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal // Start socket prior to applying the ConnectionAdapter StartReading(); + Exception error = null; + try { // This *must* happen after socket.ReadStart // The socket output consumer is the only thing that can close the connection. If the // output pipe is already closed by the time we start then it's fine since, it'll close gracefully afterwards. await Output.WriteOutputAsync(); - _connectionContext.Output.Complete(); } catch (UvException ex) { - _connectionContext.Output.Complete(ex); + error = new IOException(ex.Message, ex); } finally { @@ -91,7 +92,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal _socket.Dispose(); // Tell the kestrel we're done with this connection - _connectionContext.OnConnectionClosed(); + _connectionContext.OnConnectionClosed(error); + _connectionContext.Output.Complete(error); } } catch (Exception e) @@ -221,7 +223,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal // ReadStart() can throw a UvException in some cases (e.g. socket is no longer connected). // This should be treated the same as OnRead() seeing a "normalDone" condition. Log.ConnectionReadFin(ConnectionId); - Input.Complete(new IOException(ex.Message, ex)); + var error = new IOException(ex.Message, ex); + + _connectionContext.Abort(error); + Input.Complete(error); } } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvConnectionContext.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvConnectionContext.cs index 6c9d0cfcf5..0cec24835e 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvConnectionContext.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvConnectionContext.cs @@ -1,6 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; using System.Net; using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions; diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets/SocketConnection.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets/SocketConnection.cs index 7a1dab14c5..025c4188f8 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets/SocketConnection.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets/SocketConnection.cs @@ -7,7 +7,6 @@ using System.Diagnostics; using System.IO; using System.Net; using System.Net.Sockets; -using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Internal.System.Buffers; using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; @@ -72,15 +71,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets { // TODO: Log } - finally - { - // Mark the connection as closed after disposal - _connectionContext.OnConnectionClosed(); - } } private async Task DoReceive() { + Exception error = null; + try { while (true) @@ -112,40 +108,29 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets break; } } - - _connectionContext.Abort(ex: null); - _input.Complete(); + } + catch (SocketException ex) when (ex.SocketErrorCode == SocketError.ConnectionReset) + { + error = new ConnectionResetException(ex.Message, ex); + } + catch (SocketException ex) when (ex.SocketErrorCode == SocketError.OperationAborted) + { + error = new TaskCanceledException("The request was aborted"); + } + catch (ObjectDisposedException) + { + error = new TaskCanceledException("The request was aborted"); + } + catch (IOException ex) + { + error = ex; } catch (Exception ex) { - Exception error = null; - - if (ex is SocketException se) - { - if (se.SocketErrorCode == SocketError.ConnectionReset) - { - // Connection reset - error = new ConnectionResetException(ex.Message, ex); - } - else if (se.SocketErrorCode == SocketError.OperationAborted) - { - error = new TaskCanceledException("The request was aborted"); - } - } - - if (ex is ObjectDisposedException) - { - error = new TaskCanceledException("The request was aborted"); - } - else if (ex is IOException ioe) - { - error = ioe; - } - else if (error == null) - { - error = new IOException(ex.Message, ex); - } - + error = new IOException(ex.Message, ex); + } + finally + { _connectionContext.Abort(error); _input.Complete(error); } @@ -172,6 +157,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets private async Task DoSend() { + Exception error = null; + try { while (true) @@ -220,13 +207,27 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets _output.Advance(buffer.End); } } - - // We're done reading - _output.Complete(); + } + catch (SocketException ex) when (ex.SocketErrorCode == SocketError.OperationAborted) + { + error = null; + } + catch (ObjectDisposedException) + { + error = null; + } + catch (IOException ex) + { + error = ex; } catch (Exception ex) { - _output.Complete(ex); + error = new IOException(ex.Message, ex); + } + finally + { + _connectionContext.OnConnectionClosed(error); + _output.Complete(error); } } diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Mocks/MockConnectionInformation.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Mocks/MockConnectionInformation.cs index 6928a6f70b..2cec8398a0 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Mocks/MockConnectionInformation.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Mocks/MockConnectionInformation.cs @@ -1,6 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; using System.Net; using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions; diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/LibuvOutputConsumerTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/LibuvOutputConsumerTests.cs index 3d8fa5620c..bbaaea6054 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/LibuvOutputConsumerTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/LibuvOutputConsumerTests.cs @@ -9,10 +9,12 @@ using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions; using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal; using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking; using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests.TestHelpers; using Microsoft.AspNetCore.Testing; +using Moq; using Xunit; namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests @@ -282,11 +284,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests Assert.NotEmpty(completeQueue); // Add more bytes to the write-behind buffer to prevent the next write from - ((ISocketOutput) socketOutput).Write((writableBuffer, state) => - { - writableBuffer.Write(state); - }, - halfWriteBehindBuffer); + ((ISocketOutput)socketOutput).Write((writableBuffer, state) => + { + writableBuffer.Write(state); + }, + halfWriteBehindBuffer); // Act var writeTask2 = socketOutput.WriteAsync(halfWriteBehindBuffer, default(CancellationToken)); @@ -679,12 +681,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests frame.RequestAborted.Register(cts.Cancel); } - var ignore = WriteOutputAsync(consumer, pipe.Reader); + var ignore = WriteOutputAsync(consumer, pipe.Reader, frame); return socketOutput; } - private async Task WriteOutputAsync(LibuvOutputConsumer consumer, IPipeReader outputReader) + private async Task WriteOutputAsync(LibuvOutputConsumer consumer, IPipeReader outputReader, Frame frame) { // This WriteOutputAsync() calling code is equivalent to that in LibuvConnection. try @@ -692,10 +694,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests // Ensure that outputReader.Complete() runs on the LibuvThread. // Without ConfigureAwait(false), xunit will dispatch. await consumer.WriteOutputAsync().ConfigureAwait(false); + + frame.Abort(error: null); outputReader.Complete(); } catch (UvException ex) { + frame.Abort(ex); outputReader.Complete(ex); } } diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/TestHelpers/MockConnectionHandler.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/TestHelpers/MockConnectionHandler.cs index 0ec0a04f12..6e8c8b312e 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/TestHelpers/MockConnectionHandler.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/TestHelpers/MockConnectionHandler.cs @@ -35,12 +35,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests.TestHelpers public IPipeWriter Input { get; set; } public IPipeReader Output { get; set; } - public void OnConnectionClosed() + public void Abort(Exception ex) { - } - public void Abort(Exception ex) + public void OnConnectionClosed(Exception ex) { } } From 7122b6c4aaeac78a58fb7da9b928dc3508b4b448 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Sat, 29 Apr 2017 00:42:27 -0700 Subject: [PATCH 1267/1662] Fix flaky heartbeat test (#1794) --- .../Internal/Infrastructure/Heartbeat.cs | 12 ++---------- .../Internal/Infrastructure/IKestrelTrace.cs | 2 +- .../Internal/Infrastructure/KestrelTrace.cs | 6 +++--- .../DateHeaderValueManagerTests.cs | 9 +++------ .../HeartbeatTests.cs | 13 ++++++------- .../Mocks/MockTrace.cs | 2 +- 6 files changed, 16 insertions(+), 28 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/Heartbeat.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/Heartbeat.cs index 67cb24e79e..28a11f5580 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/Heartbeat.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/Heartbeat.cs @@ -12,29 +12,21 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure public static readonly TimeSpan Interval = TimeSpan.FromSeconds(1); private readonly IHeartbeatHandler[] _callbacks; - private readonly TimeSpan _interval; private readonly ISystemClock _systemClock; private readonly IKestrelTrace _trace; private Timer _timer; private int _executingOnHeartbeat; public Heartbeat(IHeartbeatHandler[] callbacks, ISystemClock systemClock, IKestrelTrace trace) - : this(callbacks, systemClock, trace, Interval) - { - } - - // For testing - internal Heartbeat(IHeartbeatHandler[] callbacks, ISystemClock systemClock, IKestrelTrace trace, TimeSpan interval) { _callbacks = callbacks; - _interval = interval; _systemClock = systemClock; _trace = trace; } public void Start() { - _timer = new Timer(OnHeartbeat, state: this, dueTime: _interval, period: _interval); + _timer = new Timer(OnHeartbeat, state: this, dueTime: Interval, period: Interval); } private static void OnHeartbeat(object state) @@ -67,7 +59,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure } else { - _trace.TimerSlow(_interval, now); + _trace.HeartbeatSlow(Interval, now); } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/IKestrelTrace.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/IKestrelTrace.cs index 680fecc7e2..1d88029d3d 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/IKestrelTrace.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/IKestrelTrace.cs @@ -32,7 +32,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure void NotAllConnectionsAborted(); - void TimerSlow(TimeSpan interval, DateTimeOffset now); + void HeartbeatSlow(TimeSpan interval, DateTimeOffset now); void ApplicationNeverCompleted(string connectionId); } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/KestrelTrace.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/KestrelTrace.cs index fac8fa080f..c7ef78a67c 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/KestrelTrace.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/KestrelTrace.cs @@ -48,7 +48,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal private static readonly Action _notAllConnectionsAborted = LoggerMessage.Define(LogLevel.Debug, 21, "Some connections failed to abort during server shutdown."); - private static readonly Action _timerSlow = + private static readonly Action _heartbeatSlow = LoggerMessage.Define(LogLevel.Warning, 22, @"Heartbeat took longer than ""{interval}"" at ""{now}""."); private static readonly Action _applicationNeverCompleted = @@ -121,9 +121,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal _notAllConnectionsAborted(_logger, null); } - public virtual void TimerSlow(TimeSpan interval, DateTimeOffset now) + public virtual void HeartbeatSlow(TimeSpan interval, DateTimeOffset now) { - _timerSlow(_logger, interval, now, null); + _heartbeatSlow(_logger, interval, now, null); } public virtual void ApplicationNeverCompleted(string connectionId) diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/DateHeaderValueManagerTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/DateHeaderValueManagerTests.cs index e6d5daa797..8af56589f8 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/DateHeaderValueManagerTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/DateHeaderValueManagerTests.cs @@ -43,11 +43,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests UtcNow = now }; - var timerInterval = TimeSpan.FromSeconds(10); var dateHeaderValueManager = new DateHeaderValueManager(systemClock); var testKestrelTrace = new TestKestrelTrace(); - using (var heartbeat = new Heartbeat(new IHeartbeatHandler[] { dateHeaderValueManager }, systemClock, testKestrelTrace, timerInterval)) + using (var heartbeat = new Heartbeat(new IHeartbeatHandler[] { dateHeaderValueManager }, systemClock, testKestrelTrace)) { Assert.Equal(now.ToString(Rfc1123DateFormat), dateHeaderValueManager.GetDateHeaderValues().String); systemClock.UtcNow = future; @@ -67,13 +66,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests UtcNow = now }; - var timerInterval = TimeSpan.FromMilliseconds(100); var dateHeaderValueManager = new DateHeaderValueManager(systemClock); var testKestrelTrace = new TestKestrelTrace(); var mockHeartbeatHandler = new Mock(); - using (var heartbeat = new Heartbeat(new[] { dateHeaderValueManager, mockHeartbeatHandler.Object }, systemClock, testKestrelTrace, timerInterval)) + using (var heartbeat = new Heartbeat(new[] { dateHeaderValueManager, mockHeartbeatHandler.Object }, systemClock, testKestrelTrace)) { heartbeat.OnHeartbeat(); @@ -99,11 +97,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests UtcNow = now }; - var timerInterval = TimeSpan.FromSeconds(10); var dateHeaderValueManager = new DateHeaderValueManager(systemClock); var testKestrelTrace = new TestKestrelTrace(); - using (var heatbeat = new Heartbeat(new IHeartbeatHandler[] { dateHeaderValueManager }, systemClock, testKestrelTrace, timerInterval)) + using (var heatbeat = new Heartbeat(new IHeartbeatHandler[] { dateHeaderValueManager }, systemClock, testKestrelTrace)) { heatbeat.OnHeartbeat(); Assert.Equal(now.ToString(Rfc1123DateFormat), dateHeaderValueManager.GetDateHeaderValues().String); diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/HeartbeatTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/HeartbeatTests.cs index 8151a5906c..1101f56ef0 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/HeartbeatTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/HeartbeatTests.cs @@ -19,39 +19,38 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests public void BlockedHeartbeatDoesntCauseOverlapsAndIsLoggedAsError() { var systemClock = new MockSystemClock(); - var heartbeatInterval = TimeSpan.FromMilliseconds(10); var heartbeatHandler = new Mock(); var kestrelTrace = new Mock(); var handlerMre = new ManualResetEventSlim(); var traceMre = new ManualResetEventSlim(); heartbeatHandler.Setup(h => h.OnHeartbeat(systemClock.UtcNow)).Callback(() => handlerMre.Wait()); - kestrelTrace.Setup(t => t.TimerSlow(heartbeatInterval, systemClock.UtcNow)).Callback(() => traceMre.Set()); + kestrelTrace.Setup(t => t.HeartbeatSlow(Heartbeat.Interval, systemClock.UtcNow)).Callback(() => traceMre.Set()); - using (var heartbeat = new Heartbeat(new[] { heartbeatHandler.Object }, systemClock, kestrelTrace.Object, heartbeatInterval)) + using (var heartbeat = new Heartbeat(new[] { heartbeatHandler.Object }, systemClock, kestrelTrace.Object)) { - heartbeat.Start(); + Task.Run(() => heartbeat.OnHeartbeat()); + Task.Run(() => heartbeat.OnHeartbeat()); Assert.True(traceMre.Wait(TimeSpan.FromSeconds(10))); } handlerMre.Set(); heartbeatHandler.Verify(h => h.OnHeartbeat(systemClock.UtcNow), Times.Once()); - kestrelTrace.Verify(t => t.TimerSlow(heartbeatInterval, systemClock.UtcNow), Times.AtLeastOnce()); + kestrelTrace.Verify(t => t.HeartbeatSlow(Heartbeat.Interval, systemClock.UtcNow), Times.Once()); } [Fact] public void ExceptionFromHeartbeatHandlerIsLoggedAsError() { var systemClock = new MockSystemClock(); - var heartbeatInterval = TimeSpan.FromMilliseconds(10); var heartbeatHandler = new Mock(); var kestrelTrace = new TestKestrelTrace(); var ex = new Exception(); heartbeatHandler.Setup(h => h.OnHeartbeat(systemClock.UtcNow)).Throws(ex); - using (var heartbeat = new Heartbeat(new[] { heartbeatHandler.Object }, systemClock, kestrelTrace, heartbeatInterval)) + using (var heartbeat = new Heartbeat(new[] { heartbeatHandler.Object }, systemClock, kestrelTrace)) { heartbeat.OnHeartbeat(); } diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Mocks/MockTrace.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Mocks/MockTrace.cs index 87be9cde4d..1ab3c8df70 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Mocks/MockTrace.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Mocks/MockTrace.cs @@ -33,7 +33,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance public void NotAllConnectionsAborted() { } public void NotAllConnectionsClosedGracefully() { } public void RequestProcessingError(string connectionId, Exception ex) { } - public void TimerSlow(TimeSpan interval, DateTimeOffset now) { } + public void HeartbeatSlow(TimeSpan interval, DateTimeOffset now) { } public void ApplicationNeverCompleted(string connectionId) { } } } From 9a5d6c8879182c737d7243d54a190887aae9d4e2 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Sat, 29 Apr 2017 01:15:10 -0700 Subject: [PATCH 1268/1662] More shutdown tweaks (#1760) * More shutdown tweaks - Added assert if loop has ended before starting the shutdown sequence. --- .../Internal/LibuvThread.cs | 36 +++++++++---------- 1 file changed, 16 insertions(+), 20 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvThread.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvThread.cs index f5e4909635..1591e57074 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvThread.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvThread.cs @@ -98,39 +98,35 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal } } - if (!_threadTcs.Task.IsCompleted) - { - var stepTimeout = TimeSpan.FromTicks(timeout.Ticks / 3); + Debug.Assert(!_threadTcs.Task.IsCompleted, "The loop thread was completed before calling uv_unref on the post handle."); - try + var stepTimeout = TimeSpan.FromTicks(timeout.Ticks / 3); + + try + { + Post(t => t.AllowStop()); + if (!await WaitAsync(_threadTcs.Task, stepTimeout).ConfigureAwait(false)) { - Post(t => t.AllowStop()); + Post(t => t.OnStopRude()); if (!await WaitAsync(_threadTcs.Task, stepTimeout).ConfigureAwait(false)) { - Post(t => t.OnStopRude()); + Post(t => t.OnStopImmediate()); if (!await WaitAsync(_threadTcs.Task, stepTimeout).ConfigureAwait(false)) { - Post(t => t.OnStopImmediate()); - if (!await WaitAsync(_threadTcs.Task, stepTimeout).ConfigureAwait(false)) - { - _log.LogCritical($"{nameof(LibuvThread)}.{nameof(StopAsync)} failed to terminate libuv thread."); - } + _log.LogCritical($"{nameof(LibuvThread)}.{nameof(StopAsync)} failed to terminate libuv thread."); } } } - catch (ObjectDisposedException) + } + catch (ObjectDisposedException) + { + if (!await WaitAsync(_threadTcs.Task, stepTimeout).ConfigureAwait(false)) { - if (!await WaitAsync(_threadTcs.Task, stepTimeout).ConfigureAwait(false)) - { - _log.LogCritical($"{nameof(LibuvThread)}.{nameof(StopAsync)} failed to terminate libuv thread."); - } + _log.LogCritical($"{nameof(LibuvThread)}.{nameof(StopAsync)} failed to terminate libuv thread."); } } - if (_closeError != null) - { - _closeError.Throw(); - } + _closeError?.Throw(); } #if DEBUG From 3375cf0e28c02056ccb6fa51d297971188357f0d Mon Sep 17 00:00:00 2001 From: Florian Greinacher Date: Sun, 30 Apr 2017 20:00:31 +0200 Subject: [PATCH 1269/1662] Update README.md (#1799) Kestrel is not (only) libuv-based anymore :) --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e26fd19c0e..383bb63208 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,6 @@ AppVeyor: [![AppVeyor](https://ci.appveyor.com/api/projects/status/nr0s92ykm57q0 Travis: [![Travis](https://travis-ci.org/aspnet/KestrelHttpServer.svg?branch=dev)](https://travis-ci.org/aspnet/KestrelHttpServer) -This repo contains a web server for ASP.NET Core based on [libuv](https://github.com/libuv/libuv). +This repo contains a cross-platform web server for ASP.NET Core. This project is part of ASP.NET Core. You can find samples, documentation and getting started instructions for ASP.NET Core at the [Home](https://github.com/aspnet/home) repo. From 4dc7946cd83577a4b6e5d0e537577ac2c2d9eb12 Mon Sep 17 00:00:00 2001 From: Nate McMaster Date: Thu, 27 Apr 2017 12:02:32 -0700 Subject: [PATCH 1270/1662] Implement new request trace identifier format The format: The trace identifier begins with connection ID and ends with a number that increments with each request per connection. Example: Connection ID = xyz Request 1 = "xyz:00000001" Request 2 = "xyz:00000002" ... Request 15 = "xyz:0000000F" Request 16 = "xyz:00000010" --- .../Internal/Http/Frame.cs | 4 +- .../Internal/Http/FrameRequestHeaders.cs | 2 +- .../Internal/Infrastructure/HttpUtilities.cs | 2 +- .../{AsciiUtilities.cs => StringUtilities.cs} | 46 ++++++++++++++++++- .../FrameTests.cs | 27 ++++++++++- .../StringUtilitiesTests.cs | 31 +++++++++++++ .../RequestTests.cs | 14 +++--- .../StringUtilitiesBenchmark.cs | 34 ++++++++++++++ 8 files changed, 148 insertions(+), 12 deletions(-) rename src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/{AsciiUtilities.cs => StringUtilities.cs} (64%) create mode 100644 test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/StringUtilitiesTests.cs create mode 100644 test/Microsoft.AspNetCore.Server.Kestrel.Performance/StringUtilitiesBenchmark.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.cs index 01ae9a5c81..40d1cf0c6e 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.cs @@ -73,6 +73,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http private string _requestId; private int _remainingRequestHeadersBytesAllowed; private int _requestHeadersParsed; + private uint _requestCount; protected readonly long _keepAliveTicks; private readonly long _requestHeadersTimeoutTicks; @@ -128,7 +129,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http // don't generate an ID until it is requested if (_requestId == null) { - _requestId = CorrelationIdGenerator.GetNextId(); + _requestId = StringUtilities.ConcatAsHexSuffix(ConnectionId, ':', _requestCount); } return _requestId; } @@ -388,6 +389,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http _requestHeadersParsed = 0; _responseBytesWritten = 0; + _requestCount++; } /// diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameRequestHeaders.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameRequestHeaders.cs index c11b654a8e..fb543805cb 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameRequestHeaders.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameRequestHeaders.cs @@ -44,7 +44,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http string key = new string('\0', keyLength); fixed (char* keyBuffer = key) { - if (!AsciiUtilities.TryGetAsciiString(pKeyBytes, keyBuffer, keyLength)) + if (!StringUtilities.TryGetAsciiString(pKeyBytes, keyBuffer, keyLength)) { throw BadHttpRequestException.GetException(RequestRejectionReason.InvalidCharactersInHeaderName); } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/HttpUtilities.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/HttpUtilities.cs index 7262abcca4..c78ddd17ff 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/HttpUtilities.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/HttpUtilities.cs @@ -119,7 +119,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure { // This version if AsciiUtilities returns null if there are any null (0 byte) characters // in the string - if (!AsciiUtilities.TryGetAsciiString(buffer, output, span.Length)) + if (!StringUtilities.TryGetAsciiString(buffer, output, span.Length)) { throw new InvalidOperationException(); } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/AsciiUtilities.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/StringUtilities.cs similarity index 64% rename from src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/AsciiUtilities.cs rename to src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/StringUtilities.cs index 5a95493a28..ab9ce0683c 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/AsciiUtilities.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/StringUtilities.cs @@ -3,7 +3,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure { - internal class AsciiUtilities + internal class StringUtilities { public static unsafe bool TryGetAsciiString(byte* input, char* output, int count) { @@ -75,5 +75,49 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure return isValid; } + + private static readonly string _encode16Chars = "0123456789ABCDEF"; + + /// + /// A faster version of String.Concat(, , .ToString("X8")) + /// + /// + /// + /// + /// + public static unsafe string ConcatAsHexSuffix(string str, char separator, uint number) + { + var length = 1 + 8; + if (str != null) + { + length += str.Length; + } + + // stackalloc to allocate array on stack rather than heap + char* charBuffer = stackalloc char[length]; + + var i = 0; + if (str != null) + { + for (i = 0; i < str.Length; i++) + { + charBuffer[i] = str[i]; + } + } + + charBuffer[i] = separator; + + charBuffer[i + 1] = _encode16Chars[(int)(number >> 28) & 0xF]; + charBuffer[i + 2] = _encode16Chars[(int)(number >> 24) & 0xF]; + charBuffer[i + 3] = _encode16Chars[(int)(number >> 20) & 0xF]; + charBuffer[i + 4] = _encode16Chars[(int)(number >> 16) & 0xF]; + charBuffer[i + 5] = _encode16Chars[(int)(number >> 12) & 0xF]; + charBuffer[i + 6] = _encode16Chars[(int)(number >> 8) & 0xF]; + charBuffer[i + 7] = _encode16Chars[(int)(number >> 4) & 0xF]; + charBuffer[i + 8] = _encode16Chars[(int)number & 0xF]; + + // string ctor overload that takes char* + return new string(charBuffer, 0, length); + } } } diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameTests.cs index 0f0a2d4ffa..6191ab0747 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameTests.cs @@ -141,6 +141,31 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests Assert.NotEqual(nextId, secondId); } + [Fact] + public void TraceIdentifierCountsRequestsPerFrame() + { + var connectionId = _frameContext.ConnectionId; + var feature = ((IFeatureCollection)_frame).Get(); + // Reset() is called once in the test ctor + var count = 1; + void Reset() + { + _frame.Reset(); + count++; + } + + var nextId = feature.TraceIdentifier; + Assert.Equal($"{connectionId}:00000001", nextId); + + Reset(); + var secondId = feature.TraceIdentifier; + Assert.Equal($"{connectionId}:00000002", secondId); + + var big = 1_000_000; + while (big-- > 0) Reset(); + Assert.Equal($"{connectionId}:{count:X8}", feature.TraceIdentifier); + } + [Fact] public void TraceIdentifierGeneratesWhenNull() { @@ -149,7 +174,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests Assert.NotNull(id); Assert.Equal(id, _frame.TraceIdentifier); - _frame.TraceIdentifier = null; + _frame.Reset(); Assert.NotEqual(id, _frame.TraceIdentifier); } diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/StringUtilitiesTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/StringUtilitiesTests.cs new file mode 100644 index 0000000000..5ef5f30cc1 --- /dev/null +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/StringUtilitiesTests.cs @@ -0,0 +1,31 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; +using Xunit; + +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests +{ + public class StringUtilitiesTests + { + [Theory] + [InlineData(uint.MinValue)] + [InlineData(0xF)] + [InlineData(0xA)] + [InlineData(0xFF)] + [InlineData(0xFFC59)] + [InlineData(uint.MaxValue)] + public void ConvertsToHex(uint value) + { + var str = CorrelationIdGenerator.GetNextId(); + Assert.Equal($"{str}:{value:X8}", StringUtilities.ConcatAsHexSuffix(str, ':', value)); + } + + [Fact] + public void HandlesNull() + { + uint value = 0x23BC0234; + Assert.Equal(":23BC0234", StringUtilities.ConcatAsHexSuffix(null, ':', value)); + } + } +} diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs index 517b6a0cca..6c2713a511 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs @@ -611,13 +611,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [Fact] public async Task TraceIdentifierIsUnique() { - const int IdentifierLength = 13; + const int identifierLength = 22; const int iterations = 10; using (var server = new TestServer(async context => { - Assert.Equal(IdentifierLength, Encoding.ASCII.GetByteCount(context.TraceIdentifier)); - context.Response.ContentLength = IdentifierLength; + Assert.Equal(identifierLength, Encoding.ASCII.GetByteCount(context.TraceIdentifier)); + context.Response.ContentLength = identifierLength; await context.Response.WriteAsync(context.TraceIdentifier); })) { @@ -635,7 +635,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests // requests on same connection using (var connection = server.CreateConnection()) { - var buffer = new char[IdentifierLength]; + var buffer = new char[identifierLength]; for (var i = 0; i < iterations; i++) { await connection.Send("GET / HTTP/1.1", @@ -645,12 +645,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests await connection.Receive($"HTTP/1.1 200 OK", $"Date: {server.Context.DateHeaderValue}", - $"Content-Length: {IdentifierLength}", + $"Content-Length: {identifierLength}", "", "").TimeoutAfter(TimeSpan.FromSeconds(10)); - var read = await connection.Reader.ReadAsync(buffer, 0, IdentifierLength); - Assert.Equal(IdentifierLength, read); + var read = await connection.Reader.ReadAsync(buffer, 0, identifierLength); + Assert.Equal(identifierLength, read); var id = new string(buffer, 0, read); Assert.DoesNotContain(id, usedIds.ToArray()); usedIds.Add(id); diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/StringUtilitiesBenchmark.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/StringUtilitiesBenchmark.cs new file mode 100644 index 0000000000..8097a8b744 --- /dev/null +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/StringUtilitiesBenchmark.cs @@ -0,0 +1,34 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using BenchmarkDotNet.Attributes; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; + +namespace Microsoft.AspNetCore.Server.Kestrel.Performance +{ + [Config(typeof(CoreConfig))] + public class StringUtilitiesBenchmark + { + private const int Iterations = 500_000; + + [Benchmark(Baseline = true, OperationsPerInvoke = Iterations)] + public void UintToString() + { + var connectionId = CorrelationIdGenerator.GetNextId(); + for (uint i = 0; i < Iterations; i++) + { + var id = connectionId + ':' + i.ToString("X8"); + } + } + + [Benchmark(OperationsPerInvoke = Iterations)] + public void ConcatAsHexSuffix() + { + var connectionId = CorrelationIdGenerator.GetNextId(); + for (uint i = 0; i < Iterations; i++) + { + var id = StringUtilities.ConcatAsHexSuffix(connectionId, ':', i); + } + } + } +} From 6a3d6d4273b94fcb9e573670564dbc0203628624 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Mon, 1 May 2017 11:41:10 -0700 Subject: [PATCH 1271/1662] Fix flaky tests that bind to discovered IP addresses (#1795) --- .../AddressRegistrationTests.cs | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs index 0c1ee75862..1ec090f996 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs @@ -19,7 +19,6 @@ using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; using Microsoft.AspNetCore.Testing; using Microsoft.AspNetCore.Testing.xunit; -using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using Xunit; @@ -559,7 +558,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests // Non-loopback addresses var ipv4Addresses = GetIPAddresses() - .Where(ip => ip.AddressFamily == AddressFamily.InterNetwork); + .Where(ip => ip.AddressFamily == AddressFamily.InterNetwork) + .Where(ip => CanBindAndConnectToEndpoint(new IPEndPoint(ip, 0))); + foreach (var ip in ipv4Addresses) { dataset.Add($"http://{ip}:0/", $"http://{ip}"); @@ -602,7 +603,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests // Non-loopback addresses var ipv4Addresses = GetIPAddresses() - .Where(ip => ip.AddressFamily == AddressFamily.InterNetwork); + .Where(ip => ip.AddressFamily == AddressFamily.InterNetwork) + .Where(ip => CanBindAndConnectToEndpoint(new IPEndPoint(ip, 0))); + foreach (var ip in ipv4Addresses) { dataset.Add(new IPEndPoint(ip, 0), $"http://{ip}"); @@ -611,7 +614,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests var ipv6Addresses = GetIPAddresses() .Where(ip => ip.AddressFamily == AddressFamily.InterNetworkV6) - .Where(ip => ip.ScopeId == 0); + .Where(ip => ip.ScopeId == 0) + .Where(ip => CanBindAndConnectToEndpoint(new IPEndPoint(ip, 0))); + foreach (var ip in ipv6Addresses) { dataset.Add(new IPEndPoint(ip, 0), $"http://[{ip}]"); @@ -656,7 +661,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests // Non-loopback addresses var ipv6Addresses = GetIPAddresses() .Where(ip => ip.AddressFamily == AddressFamily.InterNetworkV6) - .Where(ip => ip.ScopeId == 0); + .Where(ip => ip.ScopeId == 0) + .Where(ip => CanBindAndConnectToEndpoint(new IPEndPoint(ip, 0))); + foreach (var ip in ipv6Addresses) { dataset.Add($"http://[{ip}]:0/", new[] { $"http://[{ip}]" }); @@ -692,6 +699,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests .Where(ip => ip.AddressFamily == AddressFamily.InterNetworkV6) .Where(ip => ip.ScopeId != 0) .Where(ip => CanBindAndConnectToEndpoint(new IPEndPoint(ip, 0))); + foreach (var ip in ipv6Addresses) { dataset.Add($"http://[{ip}]:0/", $"http://[{ip}]"); From 0afb874555add3d74bfe572437efc70461cf9134 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Mon, 1 May 2017 11:41:10 -0700 Subject: [PATCH 1272/1662] Fix flaky tests that bind to discovered IP addresses (#1795) --- .../AddressRegistrationTests.cs | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs index e6a112fa48..18129506de 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs @@ -19,7 +19,6 @@ using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; using Microsoft.AspNetCore.Testing; using Microsoft.AspNetCore.Testing.xunit; -using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using Xunit; @@ -559,7 +558,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests // Non-loopback addresses var ipv4Addresses = GetIPAddresses() - .Where(ip => ip.AddressFamily == AddressFamily.InterNetwork); + .Where(ip => ip.AddressFamily == AddressFamily.InterNetwork) + .Where(ip => CanBindAndConnectToEndpoint(new IPEndPoint(ip, 0))); + foreach (var ip in ipv4Addresses) { dataset.Add($"http://{ip}:0/", $"http://{ip}"); @@ -602,7 +603,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests // Non-loopback addresses var ipv4Addresses = GetIPAddresses() - .Where(ip => ip.AddressFamily == AddressFamily.InterNetwork); + .Where(ip => ip.AddressFamily == AddressFamily.InterNetwork) + .Where(ip => CanBindAndConnectToEndpoint(new IPEndPoint(ip, 0))); + foreach (var ip in ipv4Addresses) { dataset.Add(new IPEndPoint(ip, 0), $"http://{ip}"); @@ -611,7 +614,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests var ipv6Addresses = GetIPAddresses() .Where(ip => ip.AddressFamily == AddressFamily.InterNetworkV6) - .Where(ip => ip.ScopeId == 0); + .Where(ip => ip.ScopeId == 0) + .Where(ip => CanBindAndConnectToEndpoint(new IPEndPoint(ip, 0))); + foreach (var ip in ipv6Addresses) { dataset.Add(new IPEndPoint(ip, 0), $"http://[{ip}]"); @@ -656,7 +661,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests // Non-loopback addresses var ipv6Addresses = GetIPAddresses() .Where(ip => ip.AddressFamily == AddressFamily.InterNetworkV6) - .Where(ip => ip.ScopeId == 0); + .Where(ip => ip.ScopeId == 0) + .Where(ip => CanBindAndConnectToEndpoint(new IPEndPoint(ip, 0))); + foreach (var ip in ipv6Addresses) { dataset.Add($"http://[{ip}]:0/", new[] { $"http://[{ip}]" }); @@ -692,6 +699,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests .Where(ip => ip.AddressFamily == AddressFamily.InterNetworkV6) .Where(ip => ip.ScopeId != 0) .Where(ip => CanBindAndConnectToEndpoint(new IPEndPoint(ip, 0))); + foreach (var ip in ipv6Addresses) { dataset.Add($"http://[{ip}]:0/", $"http://[{ip}]"); From 35b5d9265251dd7ae1b2f70085820d25a4ada1e9 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Mon, 1 May 2017 14:55:32 -0700 Subject: [PATCH 1273/1662] Fix EBUSY errors on uv_loop_close (#1798) * Fix race where ListenerPrimary is disposed before secondary listeners spin up - Since we only add listeners to dispatch pipes after receiving the "ack" message it's possible to have pipes that were created but not acked yet. We might miss disposal of those pipes if they were never added to the list of _dispatchPipes. #1761 --- .../Internal/LibuvThread.cs | 11 +++++++++++ .../Internal/ListenerPrimary.cs | 9 +++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvThread.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvThread.cs index 1591e57074..bc3e0139c5 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvThread.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvThread.cs @@ -264,6 +264,17 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal _post.Reference(); _post.Dispose(); + // We need this walk because we call ReadStop on on accepted connections when there's back pressure + // Calling ReadStop makes the handle as in-active which means the loop can + // end while there's still valid handles around. This makes loop.Dispose throw + // with an EBUSY. To avoid that, we walk all of the handles and dispose them. + Walk(ptr => + { + var handle = UvMemory.FromIntPtr(ptr); + // handle can be null because UvMemory.FromIntPtr looks up a weak reference + handle?.Dispose(); + }); + // Ensure the Dispose operations complete in the event loop. _loop.Run(); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/ListenerPrimary.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/ListenerPrimary.cs index 2b0fd8b039..7159d82c2c 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/ListenerPrimary.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/ListenerPrimary.cs @@ -18,7 +18,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal /// public class ListenerPrimary : Listener { + // The list of pipes that can be dispatched to (where we've confirmed the _pipeMessage) private readonly List _dispatchPipes = new List(); + // The list of pipes we've created but may not be part of _dispatchPipes + private readonly List _createdPipes = new List(); private int _dispatchIndex; private string _pipeName; private byte[] _pipeMessage; @@ -78,6 +81,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal } var dispatchPipe = new UvPipeHandle(Log); + // Add to the list of created pipes for disposal tracking + _createdPipes.Add(dispatchPipe); try { @@ -191,9 +196,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal { listener.ListenPipe.Dispose(); - foreach (var dispatchPipe in listener._dispatchPipes) + foreach (var pipe in listener._createdPipes) { - dispatchPipe.Dispose(); + pipe.Dispose(); } }, this).ConfigureAwait(false); } From 88461902cd1d064801545b9b9150d823ad85ca35 Mon Sep 17 00:00:00 2001 From: Pranav K Date: Mon, 1 May 2017 12:39:41 -0700 Subject: [PATCH 1274/1662] Use the bundled NETStandard.Library package in netstandard targeting libraries --- build/dependencies.props | 1 + 1 file changed, 1 insertion(+) diff --git a/build/dependencies.props b/build/dependencies.props index baf2720bca..f19193de97 100644 --- a/build/dependencies.props +++ b/build/dependencies.props @@ -8,6 +8,7 @@ 1.10.0-* 9.0.1 4.7.1 + $(BundledNETStandardPackageVersion) 15.0.0 2.2.0 From b21f84543aa76608ec6104a851a3cd18af6aa7bb Mon Sep 17 00:00:00 2001 From: David Fowler Date: Wed, 3 May 2017 19:35:09 -0700 Subject: [PATCH 1275/1662] Use WebHostBuilder as an implementation detail of TestServer (#1804) - This will make tests run more similarly so we can swap out the transport more easily. --- .../TestServer.cs | 95 ++++++++++--------- test/shared/TestServiceContext.cs | 7 +- 2 files changed, 55 insertions(+), 47 deletions(-) diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/TestServer.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/TestServer.cs index 630e87657b..73f2adfbf9 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/TestServer.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/TestServer.cs @@ -4,13 +4,16 @@ using System; using System.Net; using System.Net.Sockets; -using System.Threading; +using System.Reflection; +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Hosting.Server; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions; -using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv; -using Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets; using Microsoft.AspNetCore.Testing; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests @@ -18,12 +21,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests /// /// Summary description for TestServer /// - public class TestServer : IDisposable + public class TestServer : IDisposable, IStartup { - private static TimeSpan _shutdownTimeout = TimeSpan.FromSeconds(5); - - private KestrelServer _server; + private IWebHost _host; private ListenOptions _listenOptions; + private readonly RequestDelegate _app; public TestServer(RequestDelegate app) : this(app, new TestServiceContext()) @@ -47,54 +49,60 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests public TestServer(RequestDelegate app, TestServiceContext context, ListenOptions listenOptions, IHttpContextFactory httpContextFactory) { + _app = app; _listenOptions = listenOptions; - Context = context; - context.ServerOptions.ListenOptions.Add(_listenOptions); - // Switch this to test on socket transport - var transportFactory = CreateLibuvTransportFactory(context); - // var transportFactory = CreateSocketTransportFactory(context); + _host = new WebHostBuilder() + .UseKestrel(o => + { + o.ListenOptions.Add(_listenOptions); + }) + .ConfigureServices(services => + { + if (httpContextFactory != null) + { + services.AddSingleton(httpContextFactory); + } - _server = new KestrelServer(transportFactory, context); - var httpApplication = new DummyApplication(app, httpContextFactory); + services.AddSingleton(this); + services.AddSingleton(new KestrelTestLoggerFactory(context.ErrorLogger)); + services.AddSingleton(sp => + { + // Manually configure options on the TestServiceContext. + // We're doing this so we can use the same instance that was passed in + var configureOptions = sp.GetServices>(); + foreach (var c in configureOptions) + { + c.Configure(context.ServerOptions); + } + return new KestrelServer(sp.GetRequiredService(), context); + }); + }) + .UseSetting(WebHostDefaults.ApplicationKey, typeof(TestServer).GetTypeInfo().Assembly.FullName) + .Build(); - try - { - _server.StartAsync(httpApplication, CancellationToken.None).Wait(); - } - catch - { - _server.StopAsync(new CancellationTokenSource(_shutdownTimeout).Token).Wait(); - _server.Dispose(); - throw; - } + _host.Start(); } - private static ITransportFactory CreateLibuvTransportFactory(TestServiceContext context) - { - var transportOptions = new LibuvTransportOptions { ThreadCount = 1 }; - - var transportFactory = new LibuvTransportFactory( - Options.Create(transportOptions), - new LifetimeNotImplemented(), - new KestrelTestLoggerFactory(new TestApplicationErrorLogger())); - - return transportFactory; - } - - private static ITransportFactory CreateSocketTransportFactory(TestServiceContext context) - { - var options = new SocketTransportOptions(); - return new SocketTransportFactory(Options.Create(options)); - } - public IPEndPoint EndPoint => _listenOptions.IPEndPoint; public int Port => _listenOptions.IPEndPoint.Port; public AddressFamily AddressFamily => _listenOptions.IPEndPoint.AddressFamily; public TestServiceContext Context { get; } + void IStartup.Configure(IApplicationBuilder app) + { + app.Run(_app); + } + + IServiceProvider IStartup.ConfigureServices(IServiceCollection services) + { + // Unfortunately, this needs to be replaced in IStartup.ConfigureServices + services.AddSingleton(); + return services.BuildServiceProvider(); + } + public TestConnection CreateConnection() { return new TestConnection(Port, AddressFamily); @@ -102,8 +110,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests public void Dispose() { - _server.StopAsync(new CancellationTokenSource(_shutdownTimeout).Token).Wait(); - _server.Dispose(); + _host.Dispose(); } } } diff --git a/test/shared/TestServiceContext.cs b/test/shared/TestServiceContext.cs index 349ef91a43..b1b28f7014 100644 --- a/test/shared/TestServiceContext.cs +++ b/test/shared/TestServiceContext.cs @@ -13,9 +13,8 @@ namespace Microsoft.AspNetCore.Testing { public TestServiceContext() { - var logger = new TestApplicationErrorLogger(); - - Log = new TestKestrelTrace(logger); + ErrorLogger = new TestApplicationErrorLogger(); + Log = new TestKestrelTrace(ErrorLogger); ThreadPool = new LoggingThreadPool(Log); SystemClock = new MockSystemClock(); DateHeaderValueManager = new DateHeaderValueManager(SystemClock); @@ -28,6 +27,8 @@ namespace Microsoft.AspNetCore.Testing }; } + public TestApplicationErrorLogger ErrorLogger { get; } + public string DateHeaderValue { get; } } } From 9072e0ba26838bdedf4a9ec17ad5a809f37c8b26 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Wed, 3 May 2017 19:38:34 -0700 Subject: [PATCH 1276/1662] Added a ConnectionAbortedException to Transport.Abstractions (#1806) * Added a ConnectionAbortedException to Transport.Abstractions - To avoid hard coding TaskCanceledException in each transport - This PR tries to keep compatibility by converting the ConnectionAbortedException to a TaskCanceledException on exceptions in FrameRequestStream. The downside is that this conversion causes an async state machine to be created per call to ReadAsync. CopyToAsync isn't that bad because it's a single long running task. --- .../Internal/Http/FrameRequestStream.cs | 42 +++++++++++++++---- ...rameConnectionManagerShutdownExtensions.cs | 3 +- .../Exceptions/ConnectionAbortedException.cs | 21 ++++++++++ .../Internal/LibuvConnection.cs | 2 +- .../SocketConnection.cs | 4 +- 5 files changed, 61 insertions(+), 11 deletions(-) create mode 100644 src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/Exceptions/ConnectionAbortedException.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameRequestStream.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameRequestStream.cs index f7a92e37a0..4fa42fef79 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameRequestStream.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameRequestStream.cs @@ -3,9 +3,11 @@ using System; using System.IO; +using System.Runtime.ExceptionServices; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions; using Microsoft.Extensions.Internal; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http @@ -105,11 +107,24 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http public override Task ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) { var task = ValidateState(cancellationToken); - if (task == null) + if (task != null) { - return _body.ReadAsync(new ArraySegment(buffer, offset, count), cancellationToken); + return task; + } + + return ReadAsyncInternal(buffer, offset, count, cancellationToken); + } + + private async Task ReadAsyncInternal(byte[] buffer, int offset, int count, CancellationToken cancellationToken) + { + try + { + return await _body.ReadAsync(new ArraySegment(buffer, offset, count), cancellationToken); + } + catch (ConnectionAbortedException ex) + { + throw new TaskCanceledException("The request was aborted", ex); } - return task; } public override Task CopyToAsync(Stream destination, int bufferSize, CancellationToken cancellationToken) @@ -124,11 +139,24 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http } var task = ValidateState(cancellationToken); - if (task == null) + if (task != null) { - return _body.CopyToAsync(destination, cancellationToken); + return task; + } + + return CopyToAsyncInternal(destination, cancellationToken); + } + + private async Task CopyToAsyncInternal(Stream destination, CancellationToken cancellationToken) + { + try + { + await _body.CopyToAsync(destination, cancellationToken); + } + catch (ConnectionAbortedException ex) + { + throw new TaskCanceledException("The request was aborted", ex); } - return task; } public void StartAcceptingReads(MessageBody body) @@ -165,7 +193,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http public void Abort(Exception error = null) { // We don't want to throw an ODE until the app func actually completes. - // If the request is aborted, we throw an TaskCanceledException instead, + // If the request is aborted, we throw a TaskCanceledException instead, // unless error is not null, in which case we throw it. if (_state != FrameStreamState.Closed) { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/FrameConnectionManagerShutdownExtensions.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/FrameConnectionManagerShutdownExtensions.cs index 88aae5e6c7..9f43f2e2ad 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/FrameConnectionManagerShutdownExtensions.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/FrameConnectionManagerShutdownExtensions.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure { @@ -25,7 +26,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure public static async Task AbortAllConnectionsAsync(this FrameConnectionManager connectionManager) { var abortTasks = new List(); - var canceledException = new TaskCanceledException(CoreStrings.RequestProcessingAborted); + var canceledException = new ConnectionAbortedException(); connectionManager.Walk(connection => { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/Exceptions/ConnectionAbortedException.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/Exceptions/ConnectionAbortedException.cs new file mode 100644 index 0000000000..0975038e3d --- /dev/null +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/Exceptions/ConnectionAbortedException.cs @@ -0,0 +1,21 @@ +using System; + +namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions +{ + public class ConnectionAbortedException : OperationCanceledException + { + public ConnectionAbortedException() : + this("The connection was aborted") + { + + } + + public ConnectionAbortedException(string message) : base(message) + { + } + + public ConnectionAbortedException(string message, Exception inner) : base(message, inner) + { + } + } +} diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvConnection.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvConnection.cs index d9dac68dd3..d9b17193ee 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvConnection.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvConnection.cs @@ -86,7 +86,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal Input.CancelPendingFlush(); // Now, complete the input so that no more reads can happen - Input.Complete(new TaskCanceledException("The request was aborted")); + Input.Complete(new ConnectionAbortedException()); // We're done with the socket now _socket.Dispose(); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets/SocketConnection.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets/SocketConnection.cs index 025c4188f8..6d5c7e7cf6 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets/SocketConnection.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets/SocketConnection.cs @@ -115,11 +115,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets } catch (SocketException ex) when (ex.SocketErrorCode == SocketError.OperationAborted) { - error = new TaskCanceledException("The request was aborted"); + error = new ConnectionAbortedException(); } catch (ObjectDisposedException) { - error = new TaskCanceledException("The request was aborted"); + error = new ConnectionAbortedException(); } catch (IOException ex) { From 557cf29e4adf4af1b70aa3b6f8141bce558e6e2f Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Thu, 27 Apr 2017 12:39:36 -0700 Subject: [PATCH 1277/1662] arespr/knownmethods-optimizations cleanup --- .../Infrastructure/HttpUtilities.Generated.cs | 36 +++++++++---------- .../Internal/Infrastructure/HttpUtilities.cs | 31 +++++----------- ...Microsoft.AspNetCore.Server.Kestrel.csproj | 3 -- .../KnownStringsTests.cs | 7 ++-- .../GeneratedCodeTests.cs | 4 ++- tools/CodeGenerator/CodeGenerator.csproj | 21 ++++------- .../CombinationsWithoutRepetition.cs | 8 ++--- .../HttpUtilities/HttpUtilities.cs | 16 ++++----- .../HttpUtilitiesGeneratorHelpers.cs | 2 +- 9 files changed, 54 insertions(+), 74 deletions(-) rename src/{Microsoft.AspNetCore.Server.Kestrel => Microsoft.AspNetCore.Server.Kestrel.Core}/Internal/Infrastructure/HttpUtilities.Generated.cs (70%) rename test/{Microsoft.AspNetCore.Server.KestrelTests => Microsoft.AspNetCore.Server.Kestrel.Core.Tests}/KnownStringsTests.cs (94%) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/HttpUtilities.Generated.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/HttpUtilities.Generated.cs similarity index 70% rename from src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/HttpUtilities.Generated.cs rename to src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/HttpUtilities.Generated.cs index bc997c8f6f..1dd2e252c2 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/HttpUtilities.Generated.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/HttpUtilities.Generated.cs @@ -1,44 +1,44 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; using System.Runtime.CompilerServices; using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; -namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure { public static partial class HttpUtilities { // readonly primitive statics can be Jit'd to consts https://github.com/dotnet/coreclr/issues/1079 - private readonly static ulong _httpConnectMethodLong = GetAsciiStringAsLong("CONNECT "); - private readonly static ulong _httpDeleteMethodLong = GetAsciiStringAsLong("DELETE \0"); - private readonly static ulong _httpHeadMethodLong = GetAsciiStringAsLong("HEAD \0\0\0"); - private readonly static ulong _httpPatchMethodLong = GetAsciiStringAsLong("PATCH \0\0"); - private readonly static ulong _httpPostMethodLong = GetAsciiStringAsLong("POST \0\0\0"); - private readonly static ulong _httpPutMethodLong = GetAsciiStringAsLong("PUT \0\0\0\0"); - private readonly static ulong _httpOptionsMethodLong = GetAsciiStringAsLong("OPTIONS "); - private readonly static ulong _httpTraceMethodLong = GetAsciiStringAsLong("TRACE \0\0"); + private static readonly ulong _httpConnectMethodLong = GetAsciiStringAsLong("CONNECT "); + private static readonly ulong _httpDeleteMethodLong = GetAsciiStringAsLong("DELETE \0"); + private static readonly ulong _httpHeadMethodLong = GetAsciiStringAsLong("HEAD \0\0\0"); + private static readonly ulong _httpPatchMethodLong = GetAsciiStringAsLong("PATCH \0\0"); + private static readonly ulong _httpPostMethodLong = GetAsciiStringAsLong("POST \0\0\0"); + private static readonly ulong _httpPutMethodLong = GetAsciiStringAsLong("PUT \0\0\0\0"); + private static readonly ulong _httpOptionsMethodLong = GetAsciiStringAsLong("OPTIONS "); + private static readonly ulong _httpTraceMethodLong = GetAsciiStringAsLong("TRACE \0\0"); - private readonly static ulong _mask8Chars = GetMaskAsLong(new byte[] + private static readonly ulong _mask8Chars = GetMaskAsLong(new byte[] {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}); - private readonly static ulong _mask7Chars = GetMaskAsLong(new byte[] + private static readonly ulong _mask7Chars = GetMaskAsLong(new byte[] {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00}); - private readonly static ulong _mask6Chars = GetMaskAsLong(new byte[] + private static readonly ulong _mask6Chars = GetMaskAsLong(new byte[] {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00}); - private readonly static ulong _mask5Chars = GetMaskAsLong(new byte[] + private static readonly ulong _mask5Chars = GetMaskAsLong(new byte[] {0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00}); - private readonly static ulong _mask4Chars = GetMaskAsLong(new byte[] + private static readonly ulong _mask4Chars = GetMaskAsLong(new byte[] {0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00}); - private readonly static Tuple[] _knownMethods = + private static readonly Tuple[] _knownMethods = new Tuple[17]; - private readonly static string[] _methodNames = new string[9]; + private static readonly string[] _methodNames = new string[9]; static HttpUtilities() { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/HttpUtilities.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/HttpUtilities.cs index f36e1424ef..0acf137849 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/HttpUtilities.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/HttpUtilities.cs @@ -5,7 +5,6 @@ using System; using System.Diagnostics; using System.Runtime.CompilerServices; using System.Text; -using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Internal.System; @@ -20,10 +19,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure public const string HttpsUriScheme = "https://"; // readonly primitive statics can be Jit'd to consts https://github.com/dotnet/coreclr/issues/1079 - private readonly static ulong _httpSchemeLong = GetAsciiStringAsLong(HttpUriScheme + "\0"); - private readonly static ulong _httpsSchemeLong = GetAsciiStringAsLong(HttpsUriScheme); + private static readonly ulong _httpSchemeLong = GetAsciiStringAsLong(HttpUriScheme + "\0"); + private static readonly ulong _httpsSchemeLong = GetAsciiStringAsLong(HttpsUriScheme); - private const uint _httpGetMethodInt = 542393671; // retun of GetAsciiStringAsInt("GET "); const results in better codegen + private const uint _httpGetMethodInt = 542393671; // GetAsciiStringAsInt("GET "); const results in better codegen private const ulong _http10VersionLong = 3471766442030158920; // GetAsciiStringAsLong("HTTP/1.0"); const results in better codegen private const ulong _http11VersionLong = 3543824036068086856; // GetAsciiStringAsLong("HTTP/1.1"); const results in better codegen @@ -34,18 +33,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure _knownMethods[GetKnownMethodIndex(knownMethodUlong)] = new Tuple(mask, knownMethodUlong, knownMethod, length); } - private readonly static Tuple[] _knownMethods = - { - Tuple.Create(_mask4Chars, _httpPutMethodLong, HttpMethod.Put, 3), - Tuple.Create(_mask5Chars, _httpPostMethodLong, HttpMethod.Post, 4), - Tuple.Create(_mask5Chars, _httpHeadMethodLong, HttpMethod.Head, 4), - Tuple.Create(_mask6Chars, _httpTraceMethodLong, HttpMethod.Trace, 5), - Tuple.Create(_mask6Chars, _httpPatchMethodLong, HttpMethod.Patch, 5), - Tuple.Create(_mask7Chars, _httpDeleteMethodLong, HttpMethod.Delete, 6), - Tuple.Create(_mask8Chars, _httpConnectMethodLong, HttpMethod.Connect, 7), - Tuple.Create(_mask8Chars, _httpOptionsMethodLong, HttpMethod.Options, 7), - }; - private static void FillKnownMethodsGaps() { var knownMethods = _knownMethods; @@ -60,7 +47,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure } } - private unsafe static ulong GetAsciiStringAsLong(string str) + private static unsafe ulong GetAsciiStringAsLong(string str) { Debug.Assert(str.Length == 8, "String must be exactly 8 (ASCII) characters long."); @@ -72,7 +59,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure } } - private unsafe static uint GetAsciiStringAsInt(string str) + private static unsafe uint GetAsciiStringAsInt(string str) { Debug.Assert(str.Length == 4, "String must be exactly 4 (ASCII) characters long."); @@ -84,7 +71,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure } } - private unsafe static ulong GetMaskAsLong(byte[] bytes) + private static unsafe ulong GetMaskAsLong(byte[] bytes) { Debug.Assert(bytes.Length == 8, "Mask must be exactly 8 bytes long."); @@ -94,7 +81,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure } } - public unsafe static string GetAsciiStringNonNullCharacters(this Span span) + public static unsafe string GetAsciiStringNonNullCharacters(this Span span) { if (span.IsEmpty) { @@ -157,7 +144,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure } [MethodImpl(MethodImplOptions.AggressiveInlining)] - internal unsafe static HttpMethod GetKnownMethod(byte* data, int length, out int methodLength) + internal static unsafe HttpMethod GetKnownMethod(byte* data, int length, out int methodLength) { methodLength = 0; if (length < sizeof(uint)) @@ -229,7 +216,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure /// /// true if the input matches a known string, false otherwise. [MethodImpl(MethodImplOptions.AggressiveInlining)] - internal unsafe static HttpVersion GetKnownVersion(byte* location, int length) + internal static unsafe HttpVersion GetKnownVersion(byte* location, int length) { HttpVersion knownVersion; var version = *(ulong*)location; diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Microsoft.AspNetCore.Server.Kestrel.csproj b/src/Microsoft.AspNetCore.Server.Kestrel/Microsoft.AspNetCore.Server.Kestrel.csproj index 23de1c5087..8823cf1db8 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Microsoft.AspNetCore.Server.Kestrel.csproj +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Microsoft.AspNetCore.Server.Kestrel.csproj @@ -15,9 +15,6 @@ - - - diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/KnownStringsTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/KnownStringsTests.cs similarity index 94% rename from test/Microsoft.AspNetCore.Server.KestrelTests/KnownStringsTests.cs rename to test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/KnownStringsTests.cs index 1926eaa377..bbdca711c6 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/KnownStringsTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/KnownStringsTests.cs @@ -1,12 +1,13 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; using System.Collections.Generic; using System.Runtime.CompilerServices; using System.Text; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Internal.System; using Xunit; namespace Microsoft.AspNetCore.Server.KestrelTests diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/GeneratedCodeTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/GeneratedCodeTests.cs index 36db1894e1..983a18b5c8 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/GeneratedCodeTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/GeneratedCodeTests.cs @@ -15,10 +15,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { const string frameHeadersGeneratedPath = "../../../../../src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameHeaders.Generated.cs"; const string frameGeneratedPath = "../../../../../src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.Generated.cs"; - const string httpUtilitiesGeneratedPath = "../../../../../src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/HttpUtilities.Generated.cs"; + const string httpUtilitiesGeneratedPath = "../../../../../src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/HttpUtilities.Generated.cs"; + var testFrameHeadersGeneratedPath = Path.GetTempFileName(); var testFrameGeneratedPath = Path.GetTempFileName(); var testHttpUtilitiesGeneratedPath = Path.GetTempFileName(); + try { var currentFrameHeadersGenerated = File.ReadAllText(frameHeadersGeneratedPath); diff --git a/tools/CodeGenerator/CodeGenerator.csproj b/tools/CodeGenerator/CodeGenerator.csproj index 4205f6894b..5a7bd30966 100644 --- a/tools/CodeGenerator/CodeGenerator.csproj +++ b/tools/CodeGenerator/CodeGenerator.csproj @@ -6,28 +6,21 @@ netcoreapp1.1 Exe false + true + + + + - - - - - $(MSBuildThisFileDirectory)..\..\src\Microsoft.AspNetCore.Server.Kestrel.Core\Internal\Http - FrameHeaders.Generated.cs Frame.Generated.cs - - - - True - - - - True + $(MSBuildThisFileDirectory)..\..\src\Microsoft.AspNetCore.Server.Kestrel.Core + Internal\Http\FrameHeaders.Generated.cs Internal\Http\Frame.Generated.cs Internal\Infrastructure\HttpUtilities.Generated.cs diff --git a/tools/CodeGenerator/HttpUtilities/CombinationsWithoutRepetition.cs b/tools/CodeGenerator/HttpUtilities/CombinationsWithoutRepetition.cs index b7de0f4c4e..65a6b5a895 100644 --- a/tools/CodeGenerator/HttpUtilities/CombinationsWithoutRepetition.cs +++ b/tools/CodeGenerator/HttpUtilities/CombinationsWithoutRepetition.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -10,11 +10,10 @@ namespace CodeGenerator.HttpUtilities // C code for Algorithm L (Lexicographic combinations) in Section 7.2.1.3 of The Art of Computer Programming, Volume 4A: Combinatorial Algorithms, Part 1 : internal class CombinationsWithoutRepetition : IEnumerator { + private bool _firstElement; private int[] _pointers; private T[] _nElements; private readonly int _p; - public T[] Current { get; private set; } - object IEnumerator.Current => Current; public CombinationsWithoutRepetition(T[] nElements, int p) { @@ -26,7 +25,8 @@ namespace CodeGenerator.HttpUtilities ResetCurrent(); } - private bool _firstElement; + public T[] Current { get; private set; } + object IEnumerator.Current => Current; public bool MoveNext() { diff --git a/tools/CodeGenerator/HttpUtilities/HttpUtilities.cs b/tools/CodeGenerator/HttpUtilities/HttpUtilities.cs index 4c15dc75d6..4d8c2ca922 100644 --- a/tools/CodeGenerator/HttpUtilities/HttpUtilities.cs +++ b/tools/CodeGenerator/HttpUtilities/HttpUtilities.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -7,7 +7,7 @@ using System.Diagnostics; using System.Linq; using System.Text; using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; namespace CodeGenerator.HttpUtilities { @@ -66,9 +66,9 @@ namespace CodeGenerator.HttpUtilities using System; using System.Runtime.CompilerServices; using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; -namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure {{ public static partial class HttpUtilities {{ @@ -76,10 +76,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure {0} {1} - private readonly static Tuple[] _knownMethods = + private static readonly Tuple[] _knownMethods = new Tuple[{2}]; - private readonly static string[] _methodNames = new string[{3}]; + private static readonly string[] _methodNames = new string[{3}]; static HttpUtilities() {{ @@ -106,7 +106,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure var methodInfo = methodsInfo[index]; var httpMethodFieldName = GetHttpMethodFieldName(methodInfo); - result.AppendFormat(" private readonly static ulong {0} = GetAsciiStringAsLong(\"{1}\");", httpMethodFieldName, methodInfo.MethodAsciiString.Replace("\0", "\\0")); + result.AppendFormat(" private static readonly ulong {0} = GetAsciiStringAsLong(\"{1}\");", httpMethodFieldName, methodInfo.MethodAsciiString.Replace("\0", "\\0")); if (index < methodsInfo.Count - 1) { @@ -133,7 +133,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure var hexMaskString = HttpUtilitiesGeneratorHelpers.GeHexString(maskArray, "0x", ", "); var maskFieldName = GetMaskFieldName(maskBytesLength); - result.AppendFormat(" private readonly static ulong {0} = GetMaskAsLong(new byte[]\r\n {{{1}}});", maskFieldName, hexMaskString); + result.AppendFormat(" private static readonly ulong {0} = GetMaskAsLong(new byte[]\r\n {{{1}}});", maskFieldName, hexMaskString); result.AppendLine(); if (index < distinctLengths.Count - 1) { diff --git a/tools/CodeGenerator/HttpUtilities/HttpUtilitiesGeneratorHelpers.cs b/tools/CodeGenerator/HttpUtilities/HttpUtilitiesGeneratorHelpers.cs index 0cadd80aa0..1ac5de1e66 100644 --- a/tools/CodeGenerator/HttpUtilities/HttpUtilitiesGeneratorHelpers.cs +++ b/tools/CodeGenerator/HttpUtilities/HttpUtilitiesGeneratorHelpers.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; From 49a6be9b817bd2f5d9e865d68eb3b3adbab1f80c Mon Sep 17 00:00:00 2001 From: Pavel Krymets Date: Fri, 5 May 2017 10:24:16 -0700 Subject: [PATCH 1278/1662] Update InternalAspNetCoreSdkVersion --- build/dependencies.props | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/dependencies.props b/build/dependencies.props index f19193de97..d692d64f06 100644 --- a/build/dependencies.props +++ b/build/dependencies.props @@ -4,7 +4,7 @@ 0.1.0-* 0.1.0-* 4.3.0 - 2.0.0-* + 2.1.0-* 1.10.0-* 9.0.1 4.7.1 From cd1568d7f4c90a1079b8412a7db6cbbf2bc59de4 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Fri, 5 May 2017 12:52:10 -0700 Subject: [PATCH 1279/1662] Remove uv_shutdown because FIN is already sent during uv_close (#1811) * Remove uv_shutdown because FIN is already sent during uv_close #1808 --- .../Internal/LibuvConnection.cs | 3 + .../Internal/LibuvOutputConsumer.cs | 12 --- .../Internal/Networking/LibuvFunctions.cs | 14 ---- .../Internal/Networking/UvShutdownReq.cs | 76 ------------------- .../RequestTests.cs | 26 +++++++ 5 files changed, 29 insertions(+), 102 deletions(-) delete mode 100644 src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvShutdownReq.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvConnection.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvConnection.cs index d9b17193ee..f68d3ac024 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvConnection.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvConnection.cs @@ -88,6 +88,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal // Now, complete the input so that no more reads can happen Input.Complete(new ConnectionAbortedException()); + // Send a FIN + Log.ConnectionWriteFin(ConnectionId); + // We're done with the socket now _socket.Dispose(); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvOutputConsumer.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvOutputConsumer.cs index 54950c23f0..d00610fa53 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvOutputConsumer.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvOutputConsumer.cs @@ -67,18 +67,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal if (result.IsCancelled) { - // Send a FIN - _log.ConnectionWriteFin(_connectionId); - - using (var shutdownReq = new UvShutdownReq(_log)) - { - shutdownReq.Init(_thread); - var shutdownResult = await shutdownReq.ShutdownAsync(_socket); - - _log.ConnectionWroteFin(_connectionId, shutdownResult.Status); - } - - // Ensure no data is written after uv_shutdown break; } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/LibuvFunctions.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/LibuvFunctions.cs index 1d3cbccb96..84572dae53 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/LibuvFunctions.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/LibuvFunctions.cs @@ -42,7 +42,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networkin _uv_write = NativeMethods.uv_write; _uv_write2 = NativeMethods.uv_write2; } - _uv_shutdown = NativeMethods.uv_shutdown; _uv_err_name = NativeMethods.uv_err_name; _uv_strerror = NativeMethods.uv_strerror; _uv_loop_size = NativeMethods.uv_loop_size; @@ -312,16 +311,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networkin ThrowIfErrored(_uv_write2(req, handle, bufs, nbufs, sendHandle, cb)); } - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - public delegate void uv_shutdown_cb(IntPtr req, int status); - protected Func _uv_shutdown; - public void shutdown(UvShutdownReq req, UvStreamHandle handle, uv_shutdown_cb cb) - { - req.Validate(); - handle.Validate(); - ThrowIfErrored(_uv_shutdown(req, handle, cb)); - } - protected Func _uv_err_name; public string err_name(int err) { @@ -572,9 +561,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networkin [DllImport("libuv", CallingConvention = CallingConvention.Cdecl)] unsafe public static extern int uv_write2(UvRequest req, UvStreamHandle handle, uv_buf_t* bufs, int nbufs, UvStreamHandle sendHandle, uv_write_cb cb); - [DllImport("libuv", CallingConvention = CallingConvention.Cdecl)] - public static extern int uv_shutdown(UvShutdownReq req, UvStreamHandle handle, uv_shutdown_cb cb); - [DllImport("libuv", CallingConvention = CallingConvention.Cdecl)] public extern static IntPtr uv_err_name(int err); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvShutdownReq.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvShutdownReq.cs deleted file mode 100644 index 3b2f74e53c..0000000000 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvShutdownReq.cs +++ /dev/null @@ -1,76 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using Microsoft.Extensions.Logging; - -namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking -{ - /// - /// Summary description for UvShutdownRequest - /// - public class UvShutdownReq : UvRequest - { - private readonly static LibuvFunctions.uv_shutdown_cb _uv_shutdown_cb = UvShutdownCb; - - private Action _callback; - private object _state; - private LibuvAwaitable _awaitable = new LibuvAwaitable(); - - public UvShutdownReq(ILibuvTrace logger) : base(logger) - { - } - - public override void Init(LibuvThread thread) - { - var loop = thread.Loop; - - CreateMemory( - loop.Libuv, - loop.ThreadId, - loop.Libuv.req_size(LibuvFunctions.RequestType.SHUTDOWN)); - - base.Init(thread); - } - - public LibuvAwaitable ShutdownAsync(UvStreamHandle handle) - { - Shutdown(handle, LibuvAwaitable.Callback, _awaitable); - return _awaitable; - } - - public void Shutdown(UvStreamHandle handle, Action callback, object state) - { - _callback = callback; - _state = state; - _uv.shutdown(this, handle, _uv_shutdown_cb); - } - - private static void UvShutdownCb(IntPtr ptr, int status) - { - var req = FromIntPtr(ptr); - - var callback = req._callback; - req._callback = null; - - var state = req._state; - req._state = null; - - Exception error = null; - if (status < 0) - { - req.Libuv.Check(status, out error); - } - - try - { - callback(req, status, error, state); - } - catch (Exception ex) - { - req._log.LogError(0, ex, "UvShutdownCb"); - throw; - } - } - } -} \ No newline at end of file diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs index 6c2713a511..c4eb51dfdf 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs @@ -522,6 +522,32 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } } + [Fact] + public void AbortingTheConnectionSendsFIN() + { + var builder = new WebHostBuilder() + .UseKestrel() + .UseUrls("http://127.0.0.1:0") + .Configure(app => app.Run(context => + { + context.Abort(); + return Task.CompletedTask; + })); + + using (var host = builder.Build()) + { + host.Start(); + + using (var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)) + { + socket.Connect(new IPEndPoint(IPAddress.Loopback, host.GetPort())); + socket.Send(Encoding.ASCII.GetBytes("GET / HTTP/1.1\r\nHost:\r\n\r\n")); + int result = socket.Receive(new byte[32]); + Assert.Equal(0, result); + } + } + } + [Theory] [InlineData("http://localhost/abs/path", "/abs/path", null)] [InlineData("https://localhost/abs/path", "/abs/path", null)] // handles mismatch scheme From a9c165e666b941faae41af5159542a43066df478 Mon Sep 17 00:00:00 2001 From: Pavel Krymets Date: Fri, 5 May 2017 14:31:34 -0700 Subject: [PATCH 1280/1662] netcoreapp2.0 (#1810) --- .../LargeResponseApp/LargeResponseApp.csproj | 2 +- samples/SampleApp/SampleApp.csproj | 2 +- .../Adapter/Internal/LoggingStream.cs | 5 ---- .../Adapter/Internal/RawStream.cs | 5 ---- .../Internal/Http/FrameDuplexStream.cs | 7 ----- .../Internal/Http/FrameRequestStream.cs | 5 ---- .../Internal/Http/FrameResponseStream.cs | 5 ---- .../Internal/Infrastructure/WrappingStream.cs | 12 --------- ...soft.AspNetCore.Server.Kestrel.Core.csproj | 11 +------- .../HttpsConnectionAdapter.cs | 26 ++----------------- ...oft.AspNetCore.Server.Kestrel.Https.csproj | 6 +---- ...rver.Kestrel.Transport.Abstractions.csproj | 3 +-- ...Core.Server.Kestrel.Transport.Libuv.csproj | 4 +-- ...re.Server.Kestrel.Transport.Sockets.csproj | 2 +- ...Microsoft.AspNetCore.Server.Kestrel.csproj | 4 +-- .../FrameResponseStreamTests.cs | 5 ---- ...spNetCore.Server.Kestrel.Core.Tests.csproj | 10 +------ .../GeneratedCodeTests.cs | 9 +------ ...Core.Server.Kestrel.FunctionalTests.csproj | 12 ++------- ...oft.AspNetCore.Server.Kestrel.Tests.csproj | 6 +---- ...erver.Kestrel.Transport.Libuv.Tests.csproj | 10 +------ test/shared/TestResources.cs | 9 +------ tools/CodeGenerator/CodeGenerator.csproj | 2 +- 23 files changed, 19 insertions(+), 143 deletions(-) diff --git a/samples/LargeResponseApp/LargeResponseApp.csproj b/samples/LargeResponseApp/LargeResponseApp.csproj index 6aad6e781e..be9cd35512 100644 --- a/samples/LargeResponseApp/LargeResponseApp.csproj +++ b/samples/LargeResponseApp/LargeResponseApp.csproj @@ -3,7 +3,7 @@ - net46;netcoreapp2.0 + netcoreapp2.0 false diff --git a/samples/SampleApp/SampleApp.csproj b/samples/SampleApp/SampleApp.csproj index f8ee813b62..0387c8a91d 100644 --- a/samples/SampleApp/SampleApp.csproj +++ b/samples/SampleApp/SampleApp.csproj @@ -3,7 +3,7 @@ - netcoreapp2.0;net46 + netcoreapp2.0 false diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/Internal/LoggingStream.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/Internal/LoggingStream.cs index 520b456d3b..584bf6301d 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/Internal/LoggingStream.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/Internal/LoggingStream.cs @@ -132,7 +132,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal _logger.LogDebug(builder.ToString()); } -#if NET46 // The below APM methods call the underlying Read/WriteAsync methods which will still be logged. public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback callback, object state) { @@ -209,9 +208,5 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal }, tcs, cancellationToken); return tcs.Task; } -#elif NETSTANDARD1_3 -#else -#error target frameworks need to be updated. -#endif } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/Internal/RawStream.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/Internal/RawStream.cs index 9c32f272a9..0b5d31f3b3 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/Internal/RawStream.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/Internal/RawStream.cs @@ -134,7 +134,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal } } -#if NET46 public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback callback, object state) { var task = ReadAsync(buffer, offset, count, default(CancellationToken), state); @@ -210,9 +209,5 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal }, tcs, cancellationToken); return tcs.Task; } -#elif NETSTANDARD1_3 -#else -#error target frameworks need to be updated. -#endif } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameDuplexStream.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameDuplexStream.cs index d1b7cab14d..13bce2447c 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameDuplexStream.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameDuplexStream.cs @@ -1,9 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -#if NET46 using System; -#endif using System.IO; using System.Threading; using System.Threading.Tasks; @@ -116,7 +114,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http return _responseStream.FlushAsync(cancellationToken); } -#if NET46 public override void Close() { _requestStream.Close(); @@ -142,10 +139,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { _responseStream.EndWrite(asyncResult); } -#elif NETSTANDARD1_3 -#else -#error target frameworks need to be updated. -#endif public override Task ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameRequestStream.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameRequestStream.cs index 35bbf73302..72158f2f1a 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameRequestStream.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameRequestStream.cs @@ -59,7 +59,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http return ReadAsync(buffer, offset, count).Result; } -#if NET46 public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback callback, object state) { var task = ReadAsync(buffer, offset, count, default(CancellationToken), state); @@ -97,10 +96,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http }, tcs, cancellationToken); return tcs.Task; } -#elif NETSTANDARD1_3 -#else -#error target frameworks need to be updated -#endif public override Task ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameResponseStream.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameResponseStream.cs index 5f0931759b..23712d5cb4 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameResponseStream.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameResponseStream.cs @@ -65,7 +65,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http _frameControl.Write(new ArraySegment(buffer, offset, count)); } -#if NET46 public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback callback, object state) { var task = WriteAsync(buffer, offset, count, default(CancellationToken), state); @@ -103,10 +102,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http }, tcs, cancellationToken); return tcs.Task; } -#elif NETSTANDARD1_3 -#else -#error target frameworks need to be updated. -#endif public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/WrappingStream.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/WrappingStream.cs index 64fbd85526..a1c87ad8c8 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/WrappingStream.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/WrappingStream.cs @@ -3,9 +3,6 @@ using System; using System.IO; -#if NET46 -using System.Runtime.Remoting; -#endif using System.Threading; using System.Threading.Tasks; @@ -92,7 +89,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure public override Task CopyToAsync(Stream destination, int bufferSize, CancellationToken cancellationToken) => _inner.CopyToAsync(destination, bufferSize, cancellationToken); -#if NET46 public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback callback, object state) => _inner.BeginRead(buffer, offset, count, callback, state); @@ -105,20 +101,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure public override void EndWrite(IAsyncResult asyncResult) => _inner.EndWrite(asyncResult); - public override ObjRef CreateObjRef(Type requestedType) - => _inner.CreateObjRef(requestedType); - public override object InitializeLifetimeService() => _inner.InitializeLifetimeService(); public override void Close() => _inner.Close(); -#elif NETSTANDARD1_3 -#else -#error Target framework should be updated -#endif - public override bool Equals(object obj) => _inner.Equals(obj); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Microsoft.AspNetCore.Server.Kestrel.Core.csproj b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Microsoft.AspNetCore.Server.Kestrel.Core.csproj index 3e9d1e703d..f9f23ff830 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Microsoft.AspNetCore.Server.Kestrel.Core.csproj +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Microsoft.AspNetCore.Server.Kestrel.Core.csproj @@ -4,7 +4,7 @@ Core components of ASP.NET Core Kestrel cross-platform web server. - netstandard1.3;net46 + netcoreapp2.0 true aspnetcore;kestrel true @@ -19,21 +19,12 @@ - - - - - - - - - diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Https/HttpsConnectionAdapter.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Https/HttpsConnectionAdapter.cs index 298c501bea..28acb756a4 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Https/HttpsConnectionAdapter.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Https/HttpsConnectionAdapter.cs @@ -70,7 +70,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Https } } - var certificate2 = ConvertToX509Certificate2(certificate); + var certificate2 = (X509Certificate2)certificate; if (certificate2 == null) { return false; @@ -105,28 +105,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Https return new HttpsAdaptedConnection(sslStream); } - private static X509Certificate2 ConvertToX509Certificate2(X509Certificate certificate) - { - if (certificate == null) - { - return null; - } - - X509Certificate2 certificate2 = certificate as X509Certificate2; - if (certificate2 != null) - { - return certificate2; - } - -#if NETSTANDARD1_3 - // conversion X509Certificate to X509Certificate2 not supported - // https://github.com/dotnet/corefx/issues/4510 - return null; -#else - return new X509Certificate2(certificate); -#endif - } - private class HttpsAdaptedConnection : IAdaptedConnection { private readonly SslStream _sslStream; @@ -140,7 +118,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Https public void PrepareRequest(IFeatureCollection requestFeatures) { - var clientCertificate = ConvertToX509Certificate2(_sslStream.RemoteCertificate); + var clientCertificate = (X509Certificate2)_sslStream.RemoteCertificate; if (clientCertificate != null) { requestFeatures.Set(new TlsConnectionFeature { ClientCertificate = clientCertificate }); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Https/Microsoft.AspNetCore.Server.Kestrel.Https.csproj b/src/Microsoft.AspNetCore.Server.Kestrel.Https/Microsoft.AspNetCore.Server.Kestrel.Https.csproj index 6ee24eba77..4f764e9dff 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Https/Microsoft.AspNetCore.Server.Kestrel.Https.csproj +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Https/Microsoft.AspNetCore.Server.Kestrel.Https.csproj @@ -4,7 +4,7 @@ HTTPS support for the ASP.NET Core Kestrel cross-platform web server. - netstandard1.3;net46 + netcoreapp2.0 true aspnetcore;kestrel CS1591;$(NoWarn) @@ -20,8 +20,4 @@ - - - - diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.csproj b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.csproj index 8ea0de0a32..45adabecd7 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.csproj +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.csproj @@ -4,7 +4,7 @@ Transport abstractions for the ASP.NET Core Kestrel cross-platform web server. - netstandard1.3 + netcoreapp2.0 true aspnetcore;kestrel CS1570;CS1571;CS1572;CS1573;CS1574;CS1591;$(NoWarn) @@ -14,7 +14,6 @@ - diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.csproj b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.csproj index 664ae179b1..25552ef74c 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.csproj +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.csproj @@ -4,7 +4,7 @@ Libuv transport for the ASP.NET Core Kestrel cross-platform web server. - netstandard1.3 + netcoreapp2.0 true aspnetcore;kestrel true @@ -13,8 +13,6 @@ - - diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.csproj b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.csproj index 911f42f7b2..19374a028a 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.csproj +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.csproj @@ -4,7 +4,7 @@ Managed socket transport for the ASP.NET Core Kestrel cross-platform web server. - netstandard1.3 + netcoreapp2.0 true aspnetcore;kestrel true diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Microsoft.AspNetCore.Server.Kestrel.csproj b/src/Microsoft.AspNetCore.Server.Kestrel/Microsoft.AspNetCore.Server.Kestrel.csproj index 8adf6b216c..24171c9ed6 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Microsoft.AspNetCore.Server.Kestrel.csproj +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Microsoft.AspNetCore.Server.Kestrel.csproj @@ -4,7 +4,7 @@ ASP.NET Core Kestrel cross-platform web server. - netstandard1.3;net46 + netcoreapp2.0 true aspnetcore;kestrel CS1591;$(NoWarn) @@ -14,7 +14,7 @@ - + diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameResponseStreamTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameResponseStreamTests.cs index c6a3ec8a4d..12f0e0019c 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameResponseStreamTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameResponseStreamTests.cs @@ -54,17 +54,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests await Assert.ThrowsAsync(() => stream.ReadAsync(new byte[1], 0, 1)); } -#if NET46 [Fact] public void BeginReadThrows() { var stream = new FrameResponseStream(new MockFrameControl()); Assert.Throws(() => stream.BeginRead(new byte[1], 0, 1, null, null)); } -#elif NETCOREAPP2_0 -#else -#error Target framework needs to be updated -#endif [Fact] public void SeekThrows() diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/Microsoft.AspNetCore.Server.Kestrel.Core.Tests.csproj b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/Microsoft.AspNetCore.Server.Kestrel.Core.Tests.csproj index be64007718..22e86958d9 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/Microsoft.AspNetCore.Server.Kestrel.Core.Tests.csproj +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/Microsoft.AspNetCore.Server.Kestrel.Core.Tests.csproj @@ -3,16 +3,8 @@ - netcoreapp2.0;net46 - netcoreapp2.0 - x64 + netcoreapp2.0 true - - - exe diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/GeneratedCodeTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/GeneratedCodeTests.cs index 386296d716..43fc042215 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/GeneratedCodeTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/GeneratedCodeTests.cs @@ -1,8 +1,6 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -#if NETCOREAPP2_0 - using System.IO; using Xunit; @@ -39,9 +37,4 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } } } -} - -#elif NET46 -#else -#error Target framework needs to be updated -#endif \ No newline at end of file +} \ No newline at end of file diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests.csproj b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests.csproj index cd10cab0df..a3057f5317 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests.csproj +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests.csproj @@ -3,11 +3,7 @@ - netcoreapp2.0;net46 - netcoreapp2.0 - x64 - true - true + netcoreapp2.0 true - exe diff --git a/test/shared/TestResources.cs b/test/shared/TestResources.cs index 19341db11a..84a6880497 100644 --- a/test/shared/TestResources.cs +++ b/test/shared/TestResources.cs @@ -8,14 +8,7 @@ namespace Microsoft.AspNetCore.Testing { public static class TestResources { - private static readonly string _testCertificatePath = -#if NET46 - Path.Combine(Directory.GetCurrentDirectory(), "testCert.pfx"); -#elif NETCOREAPP2_0 - Path.Combine(AppContext.BaseDirectory, "testCert.pfx"); -#else -#error Target framework needs to be updated -#endif + private static readonly string _testCertificatePath = Path.Combine(AppContext.BaseDirectory, "testCert.pfx"); public static string TestCertificatePath => _testCertificatePath; } diff --git a/tools/CodeGenerator/CodeGenerator.csproj b/tools/CodeGenerator/CodeGenerator.csproj index 5f3f1c7203..bc27287098 100644 --- a/tools/CodeGenerator/CodeGenerator.csproj +++ b/tools/CodeGenerator/CodeGenerator.csproj @@ -3,7 +3,7 @@ - netcoreapp1.1 + netcoreapp2.0 Exe false From 6e2fdda162eb2d9e4a52d6d3e66dd113cbc020a6 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Fri, 5 May 2017 16:11:01 -0700 Subject: [PATCH 1281/1662] Simplify connection lifetime control flow (#1776) * Also make IAdaptedConnection disposable --- .../Adapter/Internal/AdaptedPipeline.cs | 26 ++- .../Adapter/Internal/IAdaptedConnection.cs | 3 +- .../LoggingConnectionAdapter.cs | 7 +- .../Adapter/Internal/RawStream.cs | 6 + ...istenOptionsConnectionLoggingExtensions.cs | 2 +- .../Internal/ConnectionHandler.cs | 2 +- .../Internal/FrameConnection.cs | 191 +++++++++--------- .../Internal/Http/Frame.cs | 65 ++---- .../Internal/Http/FrameOfT.cs | 17 +- .../HttpsConnectionAdapter.cs | 17 +- .../Internal/LibuvConnection.cs | 21 +- .../FrameConnectionManagerTests.cs | 10 +- .../FrameResponseHeadersTests.cs | 7 +- .../FrameTests.cs | 35 ++-- .../ConnectionAdapterTests.cs | 4 + .../HttpsTests.cs | 35 +++- .../ResponseTests.cs | 2 +- .../FrameParsingOverheadBenchmark.cs | 3 - .../FrameWritingBenchmark.cs | 1 - .../RequestParsingBenchmark.cs | 4 - .../ResponseHeaderCollectionBenchmark.cs | 1 - .../ResponseHeadersWritingBenchmark.cs | 1 - test/shared/PassThroughConnectionAdapter.cs | 5 +- 23 files changed, 229 insertions(+), 236 deletions(-) rename src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/{ => Internal}/LoggingConnectionAdapter.cs (91%) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/Internal/AdaptedPipeline.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/Internal/AdaptedPipeline.cs index 785c397468..c8240a2e21 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/Internal/AdaptedPipeline.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/Internal/AdaptedPipeline.cs @@ -5,7 +5,9 @@ using System; using System.IO; using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; +using Microsoft.Extensions.Logging; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal { @@ -15,16 +17,18 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal private readonly Stream _filteredStream; private readonly StreamSocketOutput _output; + private readonly IKestrelTrace _trace; public AdaptedPipeline( Stream filteredStream, IPipe inputPipe, - IPipe outputPipe) + IPipe outputPipe, + IKestrelTrace trace) { Input = inputPipe; _output = new StreamSocketOutput(filteredStream, outputPipe); - _filteredStream = filteredStream; + _trace = trace; } public IPipe Input { get; } @@ -33,14 +37,22 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal public async Task RunAsync() { - var inputTask = ReadInputAsync(); - var outputTask = _output.WriteOutputAsync(); + try + { + var inputTask = ReadInputAsync(); + var outputTask = _output.WriteOutputAsync(); - await inputTask; + await inputTask; - _output.Dispose(); + _output.Dispose(); - await outputTask; + await outputTask; + } + catch (Exception ex) + { + // adaptedPipeline.RunAsync() shouldn't throw, unless filtered stream's WriteAsync throws. + _trace.LogError(0, ex, $"{nameof(AdaptedPipeline)}.{nameof(RunAsync)}"); + } } private async Task ReadInputAsync() diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/Internal/IAdaptedConnection.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/Internal/IAdaptedConnection.cs index 8c39b07c3e..8129cdbb35 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/Internal/IAdaptedConnection.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/Internal/IAdaptedConnection.cs @@ -1,12 +1,13 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; using System.IO; using Microsoft.AspNetCore.Http.Features; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal { - public interface IAdaptedConnection + public interface IAdaptedConnection : IDisposable { Stream ConnectionStream { get; } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/LoggingConnectionAdapter.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/Internal/LoggingConnectionAdapter.cs similarity index 91% rename from src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/LoggingConnectionAdapter.cs rename to src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/Internal/LoggingConnectionAdapter.cs index d685e1027d..570075ecb7 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/LoggingConnectionAdapter.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/Internal/LoggingConnectionAdapter.cs @@ -5,10 +5,9 @@ using System; using System.IO; using System.Threading.Tasks; using Microsoft.AspNetCore.Http.Features; -using Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal; using Microsoft.Extensions.Logging; -namespace Microsoft.AspNetCore.Server.Kestrel.Core.Adapter +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal { public class LoggingConnectionAdapter : IConnectionAdapter { @@ -44,6 +43,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Adapter public void PrepareRequest(IFeatureCollection requestFeatures) { } + + public void Dispose() + { + } } } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/Internal/RawStream.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/Internal/RawStream.cs index 0b5d31f3b3..2423630c91 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/Internal/RawStream.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/Internal/RawStream.cs @@ -209,5 +209,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal }, tcs, cancellationToken); return tcs.Task; } + + protected override void Dispose(bool disposing) + { + // _output is disposed by ConnectionLifetimeControl + _input.Complete(); + } } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/ListenOptionsConnectionLoggingExtensions.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/ListenOptionsConnectionLoggingExtensions.cs index 2c99618aae..11306602c6 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/ListenOptionsConnectionLoggingExtensions.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/ListenOptionsConnectionLoggingExtensions.cs @@ -2,7 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using Microsoft.AspNetCore.Server.Kestrel.Core; -using Microsoft.AspNetCore.Server.Kestrel.Core.Adapter; +using Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/ConnectionHandler.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/ConnectionHandler.cs index db9236d9d8..921f87424c 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/ConnectionHandler.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/ConnectionHandler.cs @@ -62,7 +62,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal KestrelEventSource.Log.ConnectionStart(connection, connectionInfo); // Since data cannot be added to the inputPipe by the transport until OnConnection returns, - // Frame.RequestProcessingAsync is guaranteed to unblock the transport thread before calling + // Frame.ProcessRequestsAsync is guaranteed to unblock the transport thread before calling // application code. connection.StartRequestProcessing(); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnection.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnection.cs index 25e44c1df4..e0d0a9063d 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnection.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnection.cs @@ -21,23 +21,20 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal private readonly FrameConnectionContext _context; private readonly Frame _frame; private readonly List _connectionAdapters; - private readonly TaskCompletionSource _frameStartedTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); private readonly TaskCompletionSource _socketClosedTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); private long _lastTimestamp; private long _timeoutTimestamp = long.MaxValue; private TimeoutAction _timeoutAction; - private AdaptedPipeline _adaptedPipeline; + private Task _lifetimeTask; private Stream _filteredStream; - private Task _adaptedPipelineTask; public FrameConnection(FrameConnectionContext context) { _context = context; _frame = context.Frame; _connectionAdapters = context.ConnectionAdapters; - context.ServiceContext.ConnectionManager.AddConnection(context.FrameConnectionId, this); } public string ConnectionId => _context.ConnectionId; @@ -67,51 +64,82 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal public void StartRequestProcessing() { - _frame.Input = _context.Input.Reader; - _frame.Output = _context.OutputProducer; - _frame.TimeoutControl = this; + _lifetimeTask = ProcessRequestsAsync(); + } - if (_connectionAdapters.Count == 0) + private async Task ProcessRequestsAsync() + { + RawStream rawStream = null; + + try { - StartFrame(); - } - else - { - // Ensure that IConnectionAdapter.OnConnectionAsync does not run on the transport thread. - _context.ServiceContext.ThreadPool.UnsafeRun(state => + Task adaptedPipelineTask = Task.CompletedTask; + + if (_connectionAdapters.Count == 0) { - // ApplyConnectionAdaptersAsync should never throw. If it succeeds, it will call _frame.Start(). - // Otherwise, it will close the connection. - var ignore = ((FrameConnection)state).ApplyConnectionAdaptersAsync(); - }, this); + _frame.Input = _context.Input.Reader; + _frame.Output = _context.OutputProducer; + } + else + { + rawStream = new RawStream(_context.Input.Reader, _context.OutputProducer); + + try + { + var adaptedPipeline = await ApplyConnectionAdaptersAsync(rawStream); + + _frame.Input = adaptedPipeline.Input.Reader; + _frame.Output = adaptedPipeline.Output; + + adaptedPipelineTask = adaptedPipeline.RunAsync(); + } + catch (Exception ex) + { + Log.LogError(0, ex, $"Uncaught exception from the {nameof(IConnectionAdapter.OnConnectionAsync)} method of an {nameof(IConnectionAdapter)}."); + + // Since Frame.ProcessRequestsAsync() isn't called, we have to close the socket here. + _context.OutputProducer.Dispose(); + + await _socketClosedTcs.Task; + return; + } + + } + + _frame.TimeoutControl = this; + _lastTimestamp = _context.ServiceContext.SystemClock.UtcNow.Ticks; + _context.ServiceContext.ConnectionManager.AddConnection(_context.FrameConnectionId, this); + + await _frame.ProcessRequestsAsync(); + await adaptedPipelineTask; + await _socketClosedTcs.Task; + } + catch (Exception ex) + { + Log.LogError(0, ex, $"Unexpected exception in {nameof(FrameConnection)}.{nameof(ProcessRequestsAsync)}."); + } + finally + { + _context.ServiceContext.ConnectionManager.RemoveConnection(_context.FrameConnectionId); + rawStream?.Dispose(); + DisposeAdaptedConnections(); } } - public async void OnConnectionClosed(Exception ex) + public void OnConnectionClosed(Exception ex) { // Abort the connection (if it isn't already aborted) _frame.Abort(ex); Log.ConnectionStop(ConnectionId); KestrelEventSource.Log.ConnectionStop(this); - _socketClosedTcs.SetResult(null); - - // The connection is already in the "aborted" state by this point, but we want to track it - // until RequestProcessingAsync completes for graceful shutdown. - await StopAsync(); - - _context.ServiceContext.ConnectionManager.RemoveConnection(_context.FrameConnectionId); + _socketClosedTcs.TrySetResult(null); } - public async Task StopAsync() + public Task StopAsync() { - if (await _frameStartedTcs.Task) - { - await _frame.StopAsync(); - await (_adaptedPipelineTask ?? Task.CompletedTask); - } - - await _socketClosedTcs.Task; + _frame.Stop(); + return _lifetimeTask; } public void Abort(Exception ex) @@ -122,7 +150,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal public Task AbortAsync(Exception ex) { _frame.Abort(ex); - return StopAsync(); + return _lifetimeTask; } public void Timeout() @@ -130,76 +158,37 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal _frame.SetBadRequestState(RequestRejectionReason.RequestTimeout); } - private async Task ApplyConnectionAdaptersAsync() + private async Task ApplyConnectionAdaptersAsync(RawStream rawStream) { - try - { - var rawSocketOutput = _frame.Output; - var rawStream = new RawStream(_frame.Input, rawSocketOutput); - var adapterContext = new ConnectionAdapterContext(rawStream); - var adaptedConnections = new IAdaptedConnection[_connectionAdapters.Count]; + var adapterContext = new ConnectionAdapterContext(rawStream); + var adaptedConnections = new IAdaptedConnection[_connectionAdapters.Count]; - for (var i = 0; i < _connectionAdapters.Count; i++) + for (var i = 0; i < _connectionAdapters.Count; i++) + { + var adaptedConnection = await _connectionAdapters[i].OnConnectionAsync(adapterContext); + adaptedConnections[i] = adaptedConnection; + adapterContext = new ConnectionAdapterContext(adaptedConnection.ConnectionStream); + } + + _filteredStream = adapterContext.ConnectionStream; + _frame.AdaptedConnections = adaptedConnections; + + return new AdaptedPipeline(_filteredStream, + PipeFactory.Create(AdaptedInputPipeOptions), + PipeFactory.Create(AdaptedOutputPipeOptions), + Log); + } + + private void DisposeAdaptedConnections() + { + var adaptedConnections = _frame.AdaptedConnections; + if (adaptedConnections != null) + { + for (int i = adaptedConnections.Length - 1; i >= 0; i--) { - var adaptedConnection = await _connectionAdapters[i].OnConnectionAsync(adapterContext); - adaptedConnections[i] = adaptedConnection; - adapterContext = new ConnectionAdapterContext(adaptedConnection.ConnectionStream); + adaptedConnections[i].Dispose(); } - - if (adapterContext.ConnectionStream != rawStream) - { - _filteredStream = adapterContext.ConnectionStream; - _adaptedPipeline = new AdaptedPipeline( - adapterContext.ConnectionStream, - PipeFactory.Create(AdaptedInputPipeOptions), - PipeFactory.Create(AdaptedOutputPipeOptions)); - - _frame.Input = _adaptedPipeline.Input.Reader; - _frame.Output = _adaptedPipeline.Output; - - _adaptedPipelineTask = RunAdaptedPipeline(); - } - - _frame.AdaptedConnections = adaptedConnections; - StartFrame(); } - catch (Exception ex) - { - Log.LogError(0, ex, $"Uncaught exception from the {nameof(IConnectionAdapter.OnConnectionAsync)} method of an {nameof(IConnectionAdapter)}."); - _frameStartedTcs.SetResult(false); - CloseRawPipes(); - } - } - - private async Task RunAdaptedPipeline() - { - try - { - await _adaptedPipeline.RunAsync(); - } - catch (Exception ex) - { - // adaptedPipeline.RunAsync() shouldn't throw. - Log.LogError(0, ex, $"{nameof(FrameConnection)}.{nameof(ApplyConnectionAdaptersAsync)}"); - } - finally - { - CloseRawPipes(); - } - } - - private void CloseRawPipes() - { - _filteredStream?.Dispose(); - _context.OutputProducer.Dispose(); - _context.Input.Reader.Complete(); - } - - private void StartFrame() - { - _lastTimestamp = _context.ServiceContext.SystemClock.UtcNow.Ticks; - _frame.Start(); - _frameStartedTcs.SetResult(true); } public void Tick(DateTimeOffset now) @@ -216,7 +205,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal Timeout(); } - var ignore = StopAsync(); + _frame.Stop(); } Interlocked.Exchange(ref _lastTimestamp, timestamp); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.cs index 40d1cf0c6e..417fadb671 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.cs @@ -54,7 +54,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http protected Stack, object>> _onStarting; protected Stack, object>> _onCompleted; - private Task _requestProcessingTask; protected volatile bool _requestProcessingStopping; // volatile, see: https://msdn.microsoft.com/en-us/library/x13ttww7.aspx protected int _requestAborted; private CancellationTokenSource _abortedCts; @@ -104,7 +103,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http public IPipeReader Input { get; set; } public ISocketOutput Output { get; set; } - public IEnumerable AdaptedConnections { get; set; } + public IAdaptedConnection[] AdaptedConnections { get; set; } public ConnectionLifetimeControl LifetimeControl { get; set; } public ITimeoutControl TimeoutControl { get; set; } @@ -294,26 +293,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http public bool HasResponseStarted => _requestProcessingStatus == RequestProcessingStatus.ResponseStarted; - protected FrameRequestHeaders FrameRequestHeaders { get; private set; } + protected FrameRequestHeaders FrameRequestHeaders { get; } = new FrameRequestHeaders(); - protected FrameResponseHeaders FrameResponseHeaders { get; private set; } - - public void InitializeHeaders() - { - if (FrameRequestHeaders == null) - { - FrameRequestHeaders = new FrameRequestHeaders(); - } - - RequestHeaders = FrameRequestHeaders; - - if (FrameResponseHeaders == null) - { - FrameResponseHeaders = new FrameResponseHeaders(); - } - - ResponseHeaders = FrameResponseHeaders; - } + protected FrameResponseHeaders FrameResponseHeaders { get; } = new FrameResponseHeaders(); public void InitializeStreams(MessageBody messageBody) { @@ -333,9 +315,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http public void Reset() { - FrameRequestHeaders?.Reset(); - FrameResponseHeaders?.Reset(); - _onStarting = null; _onCompleted = null; @@ -366,6 +345,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http LocalPort = LocalEndPoint?.Port ?? 0; ConnectionIdFeature = ConnectionId; + FrameRequestHeaders.Reset(); + FrameResponseHeaders.Reset(); + RequestHeaders = FrameRequestHeaders; + ResponseHeaders = FrameResponseHeaders; + if (AdaptedConnections != null) { try @@ -393,27 +377,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http } /// - /// Called once by Connection class to begin the RequestProcessingAsync loop. + /// Stops the request processing loop between requests. + /// Called on all active connections when the server wants to initiate a shutdown + /// and after a keep-alive timeout. /// - public void Start() - { - Reset(); - _requestProcessingTask = RequestProcessingAsync(); - } - - /// - /// Should be called when the server wants to initiate a shutdown. The Task returned will - /// become complete when the RequestProcessingAsync function has exited. It is expected that - /// Stop will be called on all active connections, and Task.WaitAll() will be called on every - /// return value. - /// - public Task StopAsync() + public void Stop() { _requestProcessingStopping = true; Input.CancelPendingRead(); - - Debug.Assert(_requestProcessingTask != null); - return _requestProcessingTask ?? Task.CompletedTask; } private void CancelRequestAbortedToken() @@ -453,7 +424,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http /// The resulting Task from this loop is preserved in a field which is used when the server needs /// to drain and close all currently active connections. /// - public abstract Task RequestProcessingAsync(); + public abstract Task ProcessRequestsAsync(); public void OnStarting(Func callback, object state) { @@ -797,11 +768,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { if (_requestRejectedException != null) { - if (FrameRequestHeaders == null || FrameResponseHeaders == null) - { - InitializeHeaders(); - } - return ProduceEnd(); } @@ -1121,11 +1087,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http StatusCode = statusCode; ReasonPhrase = null; - if (FrameResponseHeaders == null) - { - InitializeHeaders(); - } - var responseHeaders = FrameResponseHeaders; responseHeaders.Reset(); var dateHeaderValues = DateHeaderValueManager.GetDateHeaderValues(); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameOfT.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameOfT.cs index fce5bcae6c..3be6a58c83 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameOfT.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameOfT.cs @@ -28,7 +28,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http /// The resulting Task from this loop is preserved in a field which is used when the server needs /// to drain and close all currently active connections. /// - public override async Task RequestProcessingAsync() + public override async Task ProcessRequestsAsync() { try { @@ -36,7 +36,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { TimeoutControl.SetTimeout(_keepAliveTicks, TimeoutAction.CloseConnection); - InitializeHeaders(); + Reset(); while (!_requestProcessingStopping) { @@ -77,8 +77,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http throw BadHttpRequestException.GetException( RequestRejectionReason.InvalidRequestLine); case RequestProcessingStatus.ParsingHeaders: - throw BadHttpRequestException.GetException(RequestRejectionReason - .MalformedRequestInvalidHeaders); + throw BadHttpRequestException.GetException( + RequestRejectionReason.MalformedRequestInvalidHeaders); } } } @@ -196,15 +196,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http // End the connection for non keep alive as data incoming may have been thrown off return; } - - // Don't reset frame state if we're exiting the loop. This avoids losing request rejection - // information (for 4xx response), and prevents ObjectDisposedException on HTTPS (ODEs - // will be thrown if PrepareRequest is not null and references objects disposed on connection - // close - see https://github.com/aspnet/KestrelHttpServer/issues/1103#issuecomment-250237677). - if (!_requestProcessingStopping) - { - Reset(); - } } } catch (BadHttpRequestException ex) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Https/HttpsConnectionAdapter.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Https/HttpsConnectionAdapter.cs index c231d38625..7c3bca81a3 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Https/HttpsConnectionAdapter.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Https/HttpsConnectionAdapter.cs @@ -43,7 +43,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Https public bool IsHttps => true; - public async Task OnConnectionAsync(ConnectionAdapterContext context) + public Task OnConnectionAsync(ConnectionAdapterContext context) + { + // Don't trust SslStream not to block. + return Task.Run(() => InnerOnConnectionAsync(context)); + } + + private async Task InnerOnConnectionAsync(ConnectionAdapterContext context) { SslStream sslStream; bool certificateRequired; @@ -127,6 +133,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Https requestFeatures.Get().Scheme = "https"; } + + public void Dispose() + { + _sslStream.Dispose(); + } } private class ClosedAdaptedConnection : IAdaptedConnection @@ -136,6 +147,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Https public void PrepareRequest(IFeatureCollection requestFeatures) { } + + public void Dispose() + { + } } } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvConnection.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvConnection.cs index f68d3ac024..3e8ad1e34c 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvConnection.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvConnection.cs @@ -63,21 +63,27 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal Input = _connectionContext.Input; Output = new LibuvOutputConsumer(_connectionContext.Output, Thread, _socket, ConnectionId, Log); - // Start socket prior to applying the ConnectionAdapter StartReading(); - Exception error = null; - try { // This *must* happen after socket.ReadStart // The socket output consumer is the only thing that can close the connection. If the // output pipe is already closed by the time we start then it's fine since, it'll close gracefully afterwards. await Output.WriteOutputAsync(); + + // Now, complete the input so that no more reads can happen + Input.Complete(new ConnectionAbortedException()); + _connectionContext.Output.Complete(); + _connectionContext.OnConnectionClosed(ex: null); } catch (UvException ex) { - error = new IOException(ex.Message, ex); + var ioEx = new IOException(ex.Message, ex); + + Input.Complete(ioEx); + _connectionContext.Output.Complete(ioEx); + _connectionContext.OnConnectionClosed(ioEx); } finally { @@ -85,18 +91,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal // on the stream handle Input.CancelPendingFlush(); - // Now, complete the input so that no more reads can happen - Input.Complete(new ConnectionAbortedException()); - // Send a FIN Log.ConnectionWriteFin(ConnectionId); // We're done with the socket now _socket.Dispose(); - - // Tell the kestrel we're done with this connection - _connectionContext.OnConnectionClosed(error); - _connectionContext.Output.Complete(error); } } catch (Exception e) diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameConnectionManagerTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameConnectionManagerTests.cs index 96d253065e..7aaafa4022 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameConnectionManagerTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameConnectionManagerTests.cs @@ -39,18 +39,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests FrameConnectionManager frameConnectionManager, Mock trace) { - var serviceContext = new TestServiceContext - { - ConnectionManager = frameConnectionManager - }; - - // The FrameConnection constructor adds itself to the connection manager. var frameConnection = new FrameConnection(new FrameConnectionContext { - ServiceContext = serviceContext, + ServiceContext = new TestServiceContext(), ConnectionId = connectionId }); + frameConnectionManager.AddConnection(0, frameConnection); + var connectionCount = 0; frameConnectionManager.Walk(_ => connectionCount++); diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameResponseHeadersTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameResponseHeadersTests.cs index 9ec614ef16..ff60650c98 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameResponseHeadersTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameResponseHeadersTests.cs @@ -6,8 +6,10 @@ using System.Collections.Generic; using System.Globalization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions; using Microsoft.AspNetCore.Testing; using Microsoft.Extensions.Primitives; +using Moq; using Xunit; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests @@ -19,12 +21,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests { var frameContext = new FrameContext { - ServiceContext = new TestServiceContext() + ServiceContext = new TestServiceContext(), + ConnectionInformation = Mock.Of() }; var frame = new Frame(application: null, frameContext: frameContext); - frame.InitializeHeaders(); + frame.Reset(); IDictionary headers = frame.ResponseHeaders; diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameTests.cs index 6191ab0747..43e076be7f 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameTests.cs @@ -60,7 +60,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests _frameContext = new FrameContext { ServiceContext = _serviceContext, - ConnectionInformation = new MockConnectionInformation() + ConnectionInformation = Mock.Of() }; _frame = new TestFrame(application: null, context: _frameContext) @@ -71,7 +71,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests }; _frame.Reset(); - _frame.InitializeHeaders(); } public void Dispose() @@ -245,28 +244,28 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests } [Fact] - public void InitializeHeadersResetsRequestHeaders() + public void ResetResetsRequestHeaders() { // Arrange var originalRequestHeaders = _frame.RequestHeaders; _frame.RequestHeaders = new FrameRequestHeaders(); // Act - _frame.InitializeHeaders(); + _frame.Reset(); // Assert Assert.Same(originalRequestHeaders, _frame.RequestHeaders); } [Fact] - public void InitializeHeadersResetsResponseHeaders() + public void ResetResetsResponseHeaders() { // Arrange var originalResponseHeaders = _frame.ResponseHeaders; _frame.ResponseHeaders = new FrameResponseHeaders(); // Act - _frame.InitializeHeaders(); + _frame.Reset(); // Assert Assert.Same(originalResponseHeaders, _frame.ResponseHeaders); @@ -463,17 +462,17 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests } [Fact] - public void RequestProcessingAsyncEnablesKeepAliveTimeout() + public void ProcessRequestsAsyncEnablesKeepAliveTimeout() { var connectionControl = new Mock(); _frame.TimeoutControl = connectionControl.Object; - _frame.Start(); + var requestProcessingTask = _frame.ProcessRequestsAsync(); var expectedKeepAliveTimeout = _serviceContext.ServerOptions.Limits.KeepAliveTimeout.Ticks; connectionControl.Verify(cc => cc.SetTimeout(expectedKeepAliveTimeout, TimeoutAction.CloseConnection)); - var requestProcessingTask = _frame.StopAsync(); + _frame.Stop(); _input.Writer.Complete(); requestProcessingTask.Wait(); @@ -553,12 +552,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests [Fact] public async Task RequestProcessingTaskIsUnwrapped() { - _frame.Start(); + var requestProcessingTask = _frame.ProcessRequestsAsync(); var data = Encoding.ASCII.GetBytes("GET / HTTP/1.1\r\nHost:\r\n\r\n"); await _input.Writer.WriteAsync(data); - var requestProcessingTask = _frame.StopAsync(); + _frame.Stop(); Assert.IsNotType(typeof(Task), requestProcessingTask); await requestProcessingTask.TimeoutAfter(TimeSpan.FromSeconds(10)); @@ -677,7 +676,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests var headers0 = MakeHeaders(header0Count); var headers1 = MakeHeaders(header1Count, header0Count); - var requestProcessingTask = _frame.RequestProcessingAsync(); + var requestProcessingTask = _frame.ProcessRequestsAsync(); await _input.Writer.WriteAsync(Encoding.ASCII.GetBytes("GET / HTTP/1.0\r\n")); await WaitForCondition(TimeSpan.FromSeconds(1), () => _frame.RequestHeaders != null); @@ -711,7 +710,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests var headers0 = MakeHeaders(header0Count); var headers1 = MakeHeaders(header1Count, header0Count); - var requestProcessingTask = _frame.RequestProcessingAsync(); + var requestProcessingTask = _frame.ProcessRequestsAsync(); await _input.Writer.WriteAsync(Encoding.ASCII.GetBytes("GET / HTTP/1.0\r\n")); await WaitForCondition(TimeSpan.FromSeconds(1), () => _frame.RequestHeaders != null); @@ -830,16 +829,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests } } - private class MockConnectionInformation : IConnectionInformation - { - public IPEndPoint RemoteEndPoint { get; } - public IPEndPoint LocalEndPoint { get; } - public PipeFactory PipeFactory { get; } - public bool RequiresDispatch { get; } - public IScheduler InputWriterScheduler { get; } - public IScheduler OutputReaderScheduler { get; } - } - private class RequestHeadersWrapper : IHeaderDictionary { IHeaderDictionary _innerHeaders; diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ConnectionAdapterTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ConnectionAdapterTests.cs index aecf4a30d7..906e81ae76 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ConnectionAdapterTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ConnectionAdapterTests.cs @@ -156,6 +156,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests public void PrepareRequest(IFeatureCollection requestFeatures) { } + + public void Dispose() + { + } } private class RewritingStream : Stream diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/HttpsTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/HttpsTests.cs index 391441ed5b..01987f3464 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/HttpsTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/HttpsTests.cs @@ -97,7 +97,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [Fact] public async Task DoesNotThrowObjectDisposedExceptionOnConnectionAbort() { - var x509Certificate2 = new X509Certificate2(TestResources.TestCertificatePath, "testPassword"); var loggerFactory = new HandshakeErrorLoggerFactory(); var hostBuilder = new WebHostBuilder() .UseKestrel(options => @@ -150,7 +149,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests public async Task DoesNotThrowObjectDisposedExceptionFromWriteAsyncAfterConnectionIsAborted() { var tcs = new TaskCompletionSource(); - var x509Certificate2 = new X509Certificate2(TestResources.TestCertificatePath, "testPassword"); var loggerFactory = new HandshakeErrorLoggerFactory(); var hostBuilder = new WebHostBuilder() .UseKestrel(options => @@ -196,6 +194,39 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests await tcs.Task.TimeoutAfter(TimeSpan.FromSeconds(10)); } + // Regression test for https://github.com/aspnet/KestrelHttpServer/issues/1693 + [Fact] + public async Task DoesNotThrowObjectDisposedExceptionOnEmptyConnection() + { + var loggerFactory = new HandshakeErrorLoggerFactory(); + var hostBuilder = new WebHostBuilder() + .UseKestrel(options => + { + options.Listen(new IPEndPoint(IPAddress.Loopback, 0), listenOptions => + { + listenOptions.UseHttps(TestResources.TestCertificatePath, "testPassword"); + }); + }) + .UseLoggerFactory(loggerFactory) + .Configure(app => app.Run(httpContext => Task.CompletedTask)); + + using (var host = hostBuilder.Build()) + { + host.Start(); + + using (var socket = await HttpClientSlim.GetSocket(new Uri($"https://127.0.0.1:{host.GetPort()}/"))) + using (var stream = new NetworkStream(socket, ownsSocket: false)) + using (var sslStream = new SslStream(stream, true, (sender, certificate, chain, errors) => true)) + { + await sslStream.AuthenticateAsClientAsync("127.0.0.1", clientCertificates: null, + enabledSslProtocols: SslProtocols.Tls11 | SslProtocols.Tls12, + checkCertificateRevocation: false); + } + } + + Assert.False(loggerFactory.ErrorLogger.ObjectDisposedExceptionLogged); + } + // Regression test for https://github.com/aspnet/KestrelHttpServer/pull/1197 [Fact] public void ConnectionFilterDoesNotLeakBlock() diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs index 33f4adec23..28d8a89bd3 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs @@ -147,7 +147,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests context.Response.OnStarting(() => Task.Run(() => onStartingCalled = true)); context.Response.OnCompleted(() => Task.Run(() => onCompletedCalled = true)); - // Prevent OnStarting call (see Frame.RequestProcessingAsync()). + // Prevent OnStarting call (see Frame.ProcessRequestsAsync()). throw new Exception(); }); }); diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameParsingOverheadBenchmark.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameParsingOverheadBenchmark.cs index bb01a4fc01..7128adae7d 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameParsingOverheadBenchmark.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameParsingOverheadBenchmark.cs @@ -70,8 +70,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance ErrorUtilities.ThrowInvalidRequestLine(); } - _frame.InitializeHeaders(); - if (!_frame.TakeMessageHeaders(_buffer, out consumed, out examined)) { ErrorUtilities.ThrowInvalidRequestHeaders(); @@ -91,7 +89,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance private void ParseRequestHeaders() { _frame.Reset(); - _frame.InitializeHeaders(); if (!_frame.TakeMessageHeaders(_buffer, out var consumed, out var examined)) { diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameWritingBenchmark.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameWritingBenchmark.cs index 13d7827c7e..b735e76ff9 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameWritingBenchmark.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameWritingBenchmark.cs @@ -109,7 +109,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance }; frame.Reset(); - frame.InitializeHeaders(); return frame; } diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsingBenchmark.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsingBenchmark.cs index 507e4aec80..1cff65290f 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsingBenchmark.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsingBenchmark.cs @@ -148,8 +148,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance readableBuffer = readableBuffer.Slice(consumed); - Frame.InitializeHeaders(); - if (!Frame.TakeMessageHeaders(readableBuffer, out consumed, out examined)) { ErrorUtilities.ThrowInvalidRequestHeaders(); @@ -187,8 +185,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance result = Pipe.Reader.ReadAsync().GetAwaiter().GetResult(); readableBuffer = result.Buffer; - Frame.InitializeHeaders(); - if (!Frame.TakeMessageHeaders(readableBuffer, out consumed, out examined)) { ErrorUtilities.ThrowInvalidRequestHeaders(); diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/ResponseHeaderCollectionBenchmark.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/ResponseHeaderCollectionBenchmark.cs index c912dc8932..b494e30867 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/ResponseHeaderCollectionBenchmark.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/ResponseHeaderCollectionBenchmark.cs @@ -182,7 +182,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance var frame = new Frame(application: null, frameContext: frameContext); frame.Reset(); - frame.InitializeHeaders(); _responseHeadersDirect = (FrameResponseHeaders)frame.ResponseHeaders; var context = new DefaultHttpContext(frame); _response = new DefaultHttpResponse(context); diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/ResponseHeadersWritingBenchmark.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/ResponseHeadersWritingBenchmark.cs index c514ab2f09..012deb1b70 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/ResponseHeadersWritingBenchmark.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/ResponseHeadersWritingBenchmark.cs @@ -138,7 +138,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance }; frame.Reset(); - frame.InitializeHeaders(); // Start writing var ignore = socketOutput.WriteOutputAsync(); diff --git a/test/shared/PassThroughConnectionAdapter.cs b/test/shared/PassThroughConnectionAdapter.cs index 6c4c35bf80..7d6fdd8222 100644 --- a/test/shared/PassThroughConnectionAdapter.cs +++ b/test/shared/PassThroughConnectionAdapter.cs @@ -4,7 +4,6 @@ using System.IO; using System.Threading.Tasks; using Microsoft.AspNetCore.Http.Features; -using Microsoft.AspNetCore.Server.Kestrel.Core.Adapter; using Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal; namespace Microsoft.AspNetCore.Testing @@ -31,6 +30,10 @@ namespace Microsoft.AspNetCore.Testing public void PrepareRequest(IFeatureCollection requestFeatures) { } + + public void Dispose() + { + } } } } From c48113ad805a53bc98a999a7004b6bb13763bf25 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Mon, 8 May 2017 20:44:13 -0700 Subject: [PATCH 1282/1662] Refactoring and of FrameConnection and Frame (#1816) * Refactoring and of FrameConnection and Frame - Building on top of the last refactoring of FrameConnection, this change aims to clean up the communication between the Frame and FrameConnection by removing some concepts and being consistent about the communication between Frame and FrameConnection with or without connection adapters. Changes include: - Removing ConnectionLifetimeControl, ISocketOutput, StreamSocketOutput - Moving more initialization of the frame to FrameConnection after the pipes are setup - OutputProducer communicates cancellation via the IPipeWriter instead of the output's IPipeReader. - Frame always communicates via the pipes and that communications flows through the layers to the transport. This means that each 1/2 of the adapted pipeline handles closing the right side of the transport at the right time, propagating exceptions as necessary. - This is how the flow looks now: -> -> [transport] [connection adapters] [frame] <- <- - Transports need to handle a ConnectionAbortedException on the output as a signal to stop writing and end the connection. This will no longer try to drain the output but will just stop writing and end the response immediately. - Remove frame.Abort when cancellation on Write fails. - Unify the connection shutdown logic - Dispose 1/2 initialized connection adapters #1815 --- KestrelHttpServer.sln | 3 +- .../Adapter/Internal/AdaptedPipeline.cs | 162 +++++++++++++----- .../Adapter/Internal/RawStream.cs | 34 ++-- .../Adapter/Internal/StreamSocketOutput.cs | 145 ---------------- .../Internal/ConnectionHandler.cs | 4 - .../Internal/FrameConnection.cs | 97 ++++++----- .../Internal/FrameConnectionContext.cs | 1 - .../Http/ConnectionLifetimeControl.cs | 45 ----- .../Internal/Http/Frame.cs | 9 +- .../Internal/Http/FrameOfT.cs | 2 +- .../Internal/Http/ISocketOutput.cs | 22 --- .../Internal/Http/OutputProducer.cs | 144 +++++++++------- .../Internal/LibuvOutputConsumer.cs | 57 +++--- .../SocketConnection.cs | 4 + .../FrameTests.cs | 4 +- .../OutputProducerTests.cs | 4 +- .../StreamSocketOutputTests.cs | 110 ------------ .../ConnectionAdapterTests.cs | 67 +++++++- .../RequestTests.cs | 18 +- .../TestServer.cs | 6 + .../FrameWritingBenchmark.cs | 9 +- ...pNetCore.Server.Kestrel.Performance.csproj | 3 +- .../ResponseHeadersWritingBenchmark.cs | 9 +- .../LibuvOutputConsumerTests.cs | 56 +++--- test/shared/MockSocketOutput.cs | 42 ----- 25 files changed, 419 insertions(+), 638 deletions(-) delete mode 100644 src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/Internal/StreamSocketOutput.cs delete mode 100644 src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/ConnectionLifetimeControl.cs delete mode 100644 src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/ISocketOutput.cs delete mode 100644 test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/StreamSocketOutputTests.cs delete mode 100644 test/shared/MockSocketOutput.cs diff --git a/KestrelHttpServer.sln b/KestrelHttpServer.sln index 3c10b81d05..210365479a 100644 --- a/KestrelHttpServer.sln +++ b/KestrelHttpServer.sln @@ -1,6 +1,6 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 15 -VisualStudioVersion = 15.0.26405.0 +VisualStudioVersion = 15.0.26403.7 MinimumVisualStudioVersion = 10.0.40219.1 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{7972A5D6-3385-4127-9277-428506DD44FF}" ProjectSection(SolutionItems) = preProject @@ -26,7 +26,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "shared", "shared", "{0EF2AC test\shared\LifetimeNotImplemented.cs = test\shared\LifetimeNotImplemented.cs test\shared\MockFrameControl.cs = test\shared\MockFrameControl.cs test\shared\MockLogger.cs = test\shared\MockLogger.cs - test\shared\MockSocketOutput.cs = test\shared\MockSocketOutput.cs test\shared\MockSystemClock.cs = test\shared\MockSystemClock.cs test\shared\StringExtensions.cs = test\shared\StringExtensions.cs test\shared\TestApp.cs = test\shared\TestApp.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/Internal/AdaptedPipeline.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/Internal/AdaptedPipeline.cs index c8240a2e21..b73cbdb50e 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/Internal/AdaptedPipeline.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/Internal/AdaptedPipeline.cs @@ -7,7 +7,7 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; -using Microsoft.Extensions.Logging; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal { @@ -15,77 +15,149 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal { private const int MinAllocBufferSize = 2048; - private readonly Stream _filteredStream; - private readonly StreamSocketOutput _output; private readonly IKestrelTrace _trace; + private readonly IPipeWriter _transportOutputPipeWriter; + private readonly IPipeReader _transportInputPipeReader; - public AdaptedPipeline( - Stream filteredStream, - IPipe inputPipe, - IPipe outputPipe, - IKestrelTrace trace) + public AdaptedPipeline(IPipeReader transportInputPipeReader, + IPipeWriter transportOutputPipeWriter, + IPipe inputPipe, + IPipe outputPipe, + IKestrelTrace trace) { + _transportInputPipeReader = transportInputPipeReader; + _transportOutputPipeWriter = transportOutputPipeWriter; Input = inputPipe; - _output = new StreamSocketOutput(filteredStream, outputPipe); - _filteredStream = filteredStream; + Output = outputPipe; _trace = trace; } public IPipe Input { get; } - public ISocketOutput Output => _output; + public IPipe Output { get; } - public async Task RunAsync() + public async Task RunAsync(Stream stream) { - try - { - var inputTask = ReadInputAsync(); - var outputTask = _output.WriteOutputAsync(); + var inputTask = ReadInputAsync(stream); + var outputTask = WriteOutputAsync(stream); - await inputTask; - - _output.Dispose(); - - await outputTask; - } - catch (Exception ex) - { - // adaptedPipeline.RunAsync() shouldn't throw, unless filtered stream's WriteAsync throws. - _trace.LogError(0, ex, $"{nameof(AdaptedPipeline)}.{nameof(RunAsync)}"); - } + await inputTask; + await outputTask; } - private async Task ReadInputAsync() + private async Task WriteOutputAsync(Stream stream) { - int bytesRead; + Exception error = null; - do + try { - var block = Input.Writer.Alloc(MinAllocBufferSize); - - try + if (stream == null) { - var array = block.Buffer.GetArray(); + return; + } + + while (true) + { + var readResult = await Output.Reader.ReadAsync(); + var buffer = readResult.Buffer; + try { - bytesRead = await _filteredStream.ReadAsync(array.Array, array.Offset, array.Count); - block.Advance(bytesRead); + if (buffer.IsEmpty && readResult.IsCompleted) + { + break; + } + + if (buffer.IsEmpty) + { + await stream.FlushAsync(); + } + else if (buffer.IsSingleSpan) + { + var array = buffer.First.GetArray(); + await stream.WriteAsync(array.Array, array.Offset, array.Count); + } + else + { + foreach (var memory in buffer) + { + var array = memory.GetArray(); + await stream.WriteAsync(array.Array, array.Offset, array.Count); + } + } } finally { - await block.FlushAsync(); + Output.Reader.Advance(buffer.End); } } - catch (Exception ex) + } + catch (Exception ex) + { + error = ex; + } + finally + { + Output.Reader.Complete(); + _transportOutputPipeWriter.Complete(error); + } + } + + private async Task ReadInputAsync(Stream stream) + { + Exception error = null; + + try + { + if (stream == null) { - Input.Writer.Complete(ex); - - // Don't rethrow the exception. It should be handled by the Pipeline consumer. - return; + // If the stream is null then we're going to abort the connection + throw new ConnectionAbortedException(); } - } while (bytesRead != 0); - Input.Writer.Complete(); + while (true) + { + + var outputBuffer = Input.Writer.Alloc(MinAllocBufferSize); + + var array = outputBuffer.Buffer.GetArray(); + try + { + var bytesRead = await stream.ReadAsync(array.Array, array.Offset, array.Count); + outputBuffer.Advance(bytesRead); + + if (bytesRead == 0) + { + // FIN + break; + } + } + finally + { + outputBuffer.Commit(); + } + + var result = await outputBuffer.FlushAsync(); + + if (result.IsCompleted) + { + break; + } + + } + } + catch (Exception ex) + { + // Don't rethrow the exception. It should be handled by the Pipeline consumer. + error = ex; + } + finally + { + Input.Writer.Complete(error); + // The application could have ended the input pipe so complete + // the transport pipe as well + _transportInputPipeReader.Complete(); + } } } -} +} \ No newline at end of file diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/Internal/RawStream.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/Internal/RawStream.cs index 2423630c91..cec2ba1e75 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/Internal/RawStream.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/Internal/RawStream.cs @@ -5,7 +5,6 @@ using System; using System.IO; using System.Threading; using System.Threading.Tasks; -using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal @@ -13,9 +12,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal public class RawStream : Stream { private readonly IPipeReader _input; - private readonly ISocketOutput _output; + private readonly IPipeWriter _output; - public RawStream(IPipeReader input, ISocketOutput output) + public RawStream(IPipeReader input, IPipeWriter output) { _input = input; _output = output; @@ -71,19 +70,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal public override void Write(byte[] buffer, int offset, int count) { - ArraySegment segment; - if (buffer != null) - { - segment = new ArraySegment(buffer, offset, count); - } - else - { - segment = default(ArraySegment); - } - _output.Write(segment); + WriteAsync(buffer, offset, count).GetAwaiter().GetResult(); } - public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken token) + public override async Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken token) { ArraySegment segment; if (buffer != null) @@ -94,17 +84,19 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal { segment = default(ArraySegment); } - return _output.WriteAsync(segment, cancellationToken: token); + var output = _output.Alloc(); + output.Write(segment); + await output.FlushAsync(token); } public override void Flush() { - _output.Flush(); + FlushAsync(CancellationToken.None).GetAwaiter().GetResult(); } public override Task FlushAsync(CancellationToken cancellationToken) { - return _output.FlushAsync(cancellationToken); + return WriteAsync(null, 0, 0, cancellationToken); } private async Task ReadAsync(ArraySegment buffer) @@ -209,11 +201,5 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal }, tcs, cancellationToken); return tcs.Task; } - - protected override void Dispose(bool disposing) - { - // _output is disposed by ConnectionLifetimeControl - _input.Complete(); - } } -} +} \ No newline at end of file diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/Internal/StreamSocketOutput.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/Internal/StreamSocketOutput.cs deleted file mode 100644 index 6055f271f5..0000000000 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/Internal/StreamSocketOutput.cs +++ /dev/null @@ -1,145 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using System.IO; -using System.Threading; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; -using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; - -namespace Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal -{ - public class StreamSocketOutput : ISocketOutput - { - private readonly Stream _outputStream; - private readonly IPipe _pipe; - private readonly object _sync = new object(); - private bool _completed; - - public StreamSocketOutput(Stream outputStream, IPipe pipe) - { - _outputStream = outputStream; - _pipe = pipe; - } - - public void Write(ArraySegment buffer, bool chunk) - { - WriteAsync(buffer, chunk, default(CancellationToken)).GetAwaiter().GetResult(); - } - - public async Task WriteAsync(ArraySegment buffer, bool chunk, CancellationToken cancellationToken) - { - var flushAwaiter = default(WritableBufferAwaitable); - - lock (_sync) - { - if (_completed) - { - return; - } - - var writableBuffer = _pipe.Writer.Alloc(1); - var writer = new WritableBufferWriter(writableBuffer); - if (buffer.Count > 0) - { - if (chunk) - { - ChunkWriter.WriteBeginChunkBytes(ref writer, buffer.Count); - writer.Write(buffer.Array, buffer.Offset, buffer.Count); - ChunkWriter.WriteEndChunkBytes(ref writer); - } - else - { - writer.Write(buffer.Array, buffer.Offset, buffer.Count); - } - } - - flushAwaiter = writableBuffer.FlushAsync(cancellationToken); - } - - await flushAwaiter; - } - - public void Dispose() - { - lock (_sync) - { - _completed = true; - } - - _pipe.Writer.Complete(); - } - - public void Flush() - { - FlushAsync(CancellationToken.None).GetAwaiter().GetResult(); - } - - public Task FlushAsync(CancellationToken cancellationToken) - { - return WriteAsync(default(ArraySegment), chunk: false, cancellationToken: cancellationToken); - } - - public void Write(Action callback, T state) where T : struct - { - lock (_sync) - { - if (_completed) - { - return; - } - - var buffer = _pipe.Writer.Alloc(1); - callback(buffer, state); - buffer.Commit(); - } - } - - public async Task WriteOutputAsync() - { - try - { - while (true) - { - var readResult = await _pipe.Reader.ReadAsync(); - var buffer = readResult.Buffer; - - try - { - if (buffer.IsEmpty && readResult.IsCompleted) - { - break; - } - - if (buffer.IsEmpty) - { - await _outputStream.FlushAsync(); - } - else if (buffer.IsSingleSpan) - { - var array = buffer.First.GetArray(); - await _outputStream.WriteAsync(array.Array, array.Offset, array.Count); - } - else - { - foreach (var memory in buffer) - { - var array = memory.GetArray(); - await _outputStream.WriteAsync(array.Array, array.Offset, array.Count); - } - } - } - finally - { - _pipe.Reader.Advance(buffer.End); - } - } - } - finally - { - _pipe.Reader.Complete(); - } - } - } -} diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/ConnectionHandler.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/ConnectionHandler.cs index 921f87424c..523af72020 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/ConnectionHandler.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/ConnectionHandler.cs @@ -40,10 +40,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal ServiceContext = _serviceContext }; - // TODO: Untangle this mess var frame = new Frame(_application, frameContext); - var outputProducer = new OutputProducer(outputPipe.Writer, frame, connectionId, _serviceContext.Log); - frame.LifetimeControl = new ConnectionLifetimeControl(connectionId, outputPipe.Reader, outputProducer, _serviceContext.Log); var connection = new FrameConnection(new FrameConnectionContext { @@ -55,7 +52,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal Frame = frame, Input = inputPipe, Output = outputPipe, - OutputProducer = outputProducer }); _serviceContext.Log.ConnectionStart(connectionId); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnection.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnection.cs index e0d0a9063d..b25f7a983d 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnection.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnection.cs @@ -28,7 +28,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal private TimeoutAction _timeoutAction; private Task _lifetimeTask; - private Stream _filteredStream; public FrameConnection(FrameConnectionContext context) { @@ -69,46 +68,39 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal private async Task ProcessRequestsAsync() { - RawStream rawStream = null; - try { - Task adaptedPipelineTask = Task.CompletedTask; + AdaptedPipeline adaptedPipeline = null; + var adaptedPipelineTask = Task.CompletedTask; + var input = _context.Input.Reader; + var output = _context.Output.Writer; - if (_connectionAdapters.Count == 0) + if (_connectionAdapters.Count > 0) { - _frame.Input = _context.Input.Reader; - _frame.Output = _context.OutputProducer; - } - else - { - rawStream = new RawStream(_context.Input.Reader, _context.OutputProducer); - - try - { - var adaptedPipeline = await ApplyConnectionAdaptersAsync(rawStream); - - _frame.Input = adaptedPipeline.Input.Reader; - _frame.Output = adaptedPipeline.Output; - - adaptedPipelineTask = adaptedPipeline.RunAsync(); - } - catch (Exception ex) - { - Log.LogError(0, ex, $"Uncaught exception from the {nameof(IConnectionAdapter.OnConnectionAsync)} method of an {nameof(IConnectionAdapter)}."); - - // Since Frame.ProcessRequestsAsync() isn't called, we have to close the socket here. - _context.OutputProducer.Dispose(); - - await _socketClosedTcs.Task; - return; - } + adaptedPipeline = new AdaptedPipeline(_context.Input.Reader, + _context.Output.Writer, + PipeFactory.Create(AdaptedInputPipeOptions), + PipeFactory.Create(AdaptedOutputPipeOptions), + Log); + input = adaptedPipeline.Input.Reader; + output = adaptedPipeline.Output.Writer; } + // Set these before the first await, this is to make sure that we don't yield control + // to the transport until we've added the connection to the connection manager _frame.TimeoutControl = this; - _lastTimestamp = _context.ServiceContext.SystemClock.UtcNow.Ticks; + _frame.Input = input; + _frame.Output = new OutputProducer(output, ConnectionId, Log); _context.ServiceContext.ConnectionManager.AddConnection(_context.FrameConnectionId, this); + _lastTimestamp = _context.ServiceContext.SystemClock.UtcNow.Ticks; + + if (adaptedPipeline != null) + { + // Stream can be null here and run async will close the connection in that case + var stream = await ApplyConnectionAdaptersAsync(); + adaptedPipelineTask = adaptedPipeline.RunAsync(stream); + } await _frame.ProcessRequestsAsync(); await adaptedPipelineTask; @@ -121,14 +113,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal finally { _context.ServiceContext.ConnectionManager.RemoveConnection(_context.FrameConnectionId); - rawStream?.Dispose(); DisposeAdaptedConnections(); } } public void OnConnectionClosed(Exception ex) { - // Abort the connection (if it isn't already aborted) + // Abort the connection (if not already aborted) _frame.Abort(ex); Log.ConnectionStop(ConnectionId); @@ -139,17 +130,21 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal public Task StopAsync() { _frame.Stop(); + return _lifetimeTask; } public void Abort(Exception ex) { + // Abort the connection (if not already aborted) _frame.Abort(ex); } public Task AbortAsync(Exception ex) { + // Abort the connection (if not already aborted) _frame.Abort(ex); + return _lifetimeTask; } @@ -158,25 +153,33 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal _frame.SetBadRequestState(RequestRejectionReason.RequestTimeout); } - private async Task ApplyConnectionAdaptersAsync(RawStream rawStream) + private async Task ApplyConnectionAdaptersAsync() { - var adapterContext = new ConnectionAdapterContext(rawStream); + var stream = new RawStream(_context.Input.Reader, _context.Output.Writer); + var adapterContext = new ConnectionAdapterContext(stream); var adaptedConnections = new IAdaptedConnection[_connectionAdapters.Count]; - for (var i = 0; i < _connectionAdapters.Count; i++) + try { - var adaptedConnection = await _connectionAdapters[i].OnConnectionAsync(adapterContext); - adaptedConnections[i] = adaptedConnection; - adapterContext = new ConnectionAdapterContext(adaptedConnection.ConnectionStream); + for (var i = 0; i < _connectionAdapters.Count; i++) + { + var adaptedConnection = await _connectionAdapters[i].OnConnectionAsync(adapterContext); + adaptedConnections[i] = adaptedConnection; + adapterContext = new ConnectionAdapterContext(adaptedConnection.ConnectionStream); + } + } + catch (Exception ex) + { + Log.LogError(0, ex, $"Uncaught exception from the {nameof(IConnectionAdapter.OnConnectionAsync)} method of an {nameof(IConnectionAdapter)}."); + + return null; + } + finally + { + _frame.AdaptedConnections = adaptedConnections; } - _filteredStream = adapterContext.ConnectionStream; - _frame.AdaptedConnections = adaptedConnections; - - return new AdaptedPipeline(_filteredStream, - PipeFactory.Create(AdaptedInputPipeOptions), - PipeFactory.Create(AdaptedOutputPipeOptions), - Log); + return adapterContext.ConnectionStream; } private void DisposeAdaptedConnections() diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnectionContext.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnectionContext.cs index 1394f6c150..d9a7c38148 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnectionContext.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnectionContext.cs @@ -16,7 +16,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal public PipeFactory PipeFactory { get; set; } public List ConnectionAdapters { get; set; } public Frame Frame { get; set; } - public OutputProducer OutputProducer { get; set; } public IPipe Input { get; set; } public IPipe Output { get; set; } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/ConnectionLifetimeControl.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/ConnectionLifetimeControl.cs deleted file mode 100644 index 1d6efcd6db..0000000000 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/ConnectionLifetimeControl.cs +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; -using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; - -namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http -{ - public class ConnectionLifetimeControl - { - public ConnectionLifetimeControl( - string connectionId, - IPipeReader outputPipeReader, - OutputProducer outputProducer, - IKestrelTrace log) - { - ConnectionId = connectionId; - OutputReader = outputPipeReader; - OutputProducer = outputProducer; - Log = log; - } - - private string ConnectionId { get; } - private IPipeReader OutputReader { get; } - private OutputProducer OutputProducer { get; } - private IKestrelTrace Log { get; } - - public void End(ProduceEndType endType) - { - switch (endType) - { - case ProduceEndType.ConnectionKeepAlive: - Log.ConnectionKeepAlive(ConnectionId); - break; - case ProduceEndType.SocketShutdown: - OutputReader.CancelPendingRead(); - goto case ProduceEndType.SocketDisconnect; - case ProduceEndType.SocketDisconnect: - OutputProducer.Dispose(); - Log.ConnectionDisconnect(ConnectionId); - break; - } - } - } -} diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.cs index 417fadb671..6a85d64757 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.cs @@ -102,9 +102,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http public IConnectionInformation ConnectionInformation => _frameContext.ConnectionInformation; public IPipeReader Input { get; set; } - public ISocketOutput Output { get; set; } + public OutputProducer Output { get; set; } public IAdaptedConnection[] AdaptedConnections { get; set; } - public ConnectionLifetimeControl LifetimeControl { get; set; } public ITimeoutControl TimeoutControl { get; set; } protected IKestrelTrace Log => ServiceContext.Log; @@ -411,7 +410,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http _frameStreams?.Abort(error); - LifetimeControl.End(ProduceEndType.SocketDisconnect); + Output.Abort(); // Potentially calling user code. CancelRequestAbortedToken logs any exceptions. ServiceContext.ThreadPool.UnsafeRun(state => ((Frame)state).CancelRequestAbortedToken(), this); @@ -827,7 +826,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http if (_keepAlive) { - LifetimeControl.End(ProduceEndType.ConnectionKeepAlive); + Log.ConnectionKeepAlive(ConnectionId); } if (HttpMethods.IsHead(Method) && _responseBytesWritten > 0) @@ -847,7 +846,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http if (_keepAlive) { - LifetimeControl.End(ProduceEndType.ConnectionKeepAlive); + Log.ConnectionKeepAlive(ConnectionId); } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameOfT.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameOfT.cs index 3be6a58c83..b0890e17ae 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameOfT.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameOfT.cs @@ -229,7 +229,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http if (Volatile.Read(ref _requestAborted) == 0) { await TryProduceInvalidRequestResponse(); - LifetimeControl.End(ProduceEndType.SocketShutdown); + Output.Dispose(); } } catch (Exception ex) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/ISocketOutput.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/ISocketOutput.cs deleted file mode 100644 index 139a5000a0..0000000000 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/ISocketOutput.cs +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using System.Threading; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; - -namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http -{ - /// - /// Operations performed for buffered socket output - /// - public interface ISocketOutput - { - void Write(ArraySegment buffer, bool chunk = false); - Task WriteAsync(ArraySegment buffer, bool chunk = false, CancellationToken cancellationToken = default(CancellationToken)); - void Flush(); - Task FlushAsync(CancellationToken cancellationToken = default(CancellationToken)); - void Write(Action write, T state) where T : struct; - } -} diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/OutputProducer.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/OutputProducer.cs index c5fe3dee51..0d024d6a7f 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/OutputProducer.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/OutputProducer.cs @@ -6,11 +6,12 @@ using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions; using Microsoft.Extensions.Internal; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { - public class OutputProducer : ISocketOutput, IDisposable + public class OutputProducer : IDisposable { private static readonly ArraySegment _emptyData = new ArraySegment(new byte[0]); @@ -24,7 +25,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http private bool _completed = false; private readonly IPipeWriter _pipe; - private readonly Frame _frame; // https://github.com/dotnet/corefxlab/issues/1334 // Pipelines don't support multiple awaiters on flush @@ -33,16 +33,90 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http private readonly object _flushLock = new object(); private Action _flushCompleted; - public OutputProducer(IPipeWriter pipe, Frame frame, string connectionId, IKestrelTrace log) + public OutputProducer(IPipeWriter pipe, string connectionId, IKestrelTrace log) { _pipe = pipe; - _frame = frame; _connectionId = connectionId; _log = log; _flushCompleted = OnFlushCompleted; } - public Task WriteAsync( + public void Write(ArraySegment buffer, bool chunk = false) + { + WriteAsync(buffer, default(CancellationToken), chunk).GetAwaiter().GetResult(); + } + + public Task WriteAsync(ArraySegment buffer, bool chunk = false, CancellationToken cancellationToken = default(CancellationToken)) + { + if (cancellationToken.IsCancellationRequested) + { + _cancelled = true; + return Task.FromCanceled(cancellationToken); + } + else if (_cancelled) + { + return TaskCache.CompletedTask; + } + + return WriteAsync(buffer, cancellationToken, chunk); + } + + public void Flush() + { + WriteAsync(_emptyData, default(CancellationToken)).GetAwaiter().GetResult(); + } + + public Task FlushAsync(CancellationToken cancellationToken = default(CancellationToken)) + { + return WriteAsync(_emptyData, cancellationToken); + } + + public void Write(Action callback, T state) + { + lock (_contextLock) + { + if (_completed) + { + return; + } + + var buffer = _pipe.Alloc(1); + callback(buffer, state); + buffer.Commit(); + } + } + + public void Dispose() + { + lock (_contextLock) + { + if (_completed) + { + return; + } + + _log.ConnectionDisconnect(_connectionId); + _completed = true; + _pipe.Complete(); + } + } + + public void Abort() + { + lock (_contextLock) + { + if (_completed) + { + return; + } + + _log.ConnectionDisconnect(_connectionId); + _completed = true; + _pipe.Complete(new ConnectionAbortedException()); + } + } + + private Task WriteAsync( ArraySegment buffer, CancellationToken cancellationToken, bool chunk = false) @@ -108,11 +182,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http } await _flushTcs.Task; - if (cancellationToken.IsCancellationRequested) - { - _frame.Abort(error: null); - } - cancellationToken.ThrowIfCancellationRequested(); } @@ -120,60 +189,5 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { _flushTcs.TrySetResult(null); } - - void ISocketOutput.Write(ArraySegment buffer, bool chunk) - { - WriteAsync(buffer, default(CancellationToken), chunk).GetAwaiter().GetResult(); - } - - Task ISocketOutput.WriteAsync(ArraySegment buffer, bool chunk, CancellationToken cancellationToken) - { - if (cancellationToken.IsCancellationRequested) - { - _frame.Abort(error: null); - _cancelled = true; - return Task.FromCanceled(cancellationToken); - } - else if (_cancelled) - { - return TaskCache.CompletedTask; - } - - return WriteAsync(buffer, cancellationToken, chunk); - } - - void ISocketOutput.Flush() - { - WriteAsync(_emptyData, default(CancellationToken)).GetAwaiter().GetResult(); - } - - Task ISocketOutput.FlushAsync(CancellationToken cancellationToken) - { - return WriteAsync(_emptyData, cancellationToken); - } - - void ISocketOutput.Write(Action callback, T state) - { - lock (_contextLock) - { - if (_completed) - { - return; - } - - var buffer = _pipe.Alloc(1); - callback(buffer, state); - buffer.Commit(); - } - } - - public void Dispose() - { - lock (_contextLock) - { - _completed = true; - _pipe.Complete(); - } - } } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvOutputConsumer.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvOutputConsumer.cs index d00610fa53..30b151a2c2 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvOutputConsumer.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvOutputConsumer.cs @@ -4,6 +4,7 @@ using System; using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions; using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking; namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal @@ -36,48 +37,50 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal while (true) { - var result = await _pipe.ReadAsync(); - var buffer = result.Buffer; - var consumed = buffer.End; - try { - if (!buffer.IsEmpty) + var result = await _pipe.ReadAsync(); + var buffer = result.Buffer; + var consumed = buffer.End; + + try { - var writeReq = pool.Allocate(); - - try + if (!buffer.IsEmpty) { - var writeResult = await writeReq.WriteAsync(_socket, buffer); + var writeReq = pool.Allocate(); - LogWriteInfo(writeResult.Status, writeResult.Error); - - if (writeResult.Error != null) + try { - consumed = buffer.Start; - throw writeResult.Error; + var writeResult = await writeReq.WriteAsync(_socket, buffer); + + LogWriteInfo(writeResult.Status, writeResult.Error); + + if (writeResult.Error != null) + { + consumed = buffer.Start; + throw writeResult.Error; + } + } + finally + { + // Make sure we return the writeReq to the pool + pool.Return(writeReq); } } - finally + + if (buffer.IsEmpty && result.IsCompleted) { - // Make sure we return the writeReq to the pool - pool.Return(writeReq); + break; } } - - if (result.IsCancelled) + finally { - break; - } - - if (buffer.IsEmpty && result.IsCompleted) - { - break; + _pipe.Advance(consumed); } } - finally + catch (ConnectionAbortedException) { - _pipe.Advance(consumed); + break; } } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets/SocketConnection.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets/SocketConnection.cs index 6d5c7e7cf6..28685c3b60 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets/SocketConnection.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets/SocketConnection.cs @@ -216,6 +216,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets { error = null; } + catch (ConnectionAbortedException) + { + error = null; + } catch (IOException ex) { error = ex; diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameTests.cs index 43e076be7f..eb2c93f583 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameTests.cs @@ -54,6 +54,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests { _pipelineFactory = new PipeFactory(); _input = _pipelineFactory.Create(); + var output = _pipelineFactory.Create(); _serviceContext = new TestServiceContext(); @@ -66,10 +67,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests _frame = new TestFrame(application: null, context: _frameContext) { Input = _input.Reader, - Output = new MockSocketOutput(), TimeoutControl = Mock.Of() }; + _frame.Output = new OutputProducer(output.Writer, "", Mock.Of()); + _frame.Reset(); } diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/OutputProducerTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/OutputProducerTests.cs index e96126d087..1e8ae196bd 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/OutputProducerTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/OutputProducerTests.cs @@ -38,7 +38,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests var called = false; - ((ISocketOutput)socketOutput).Write((buffer, state) => + socketOutput.Write((buffer, state) => { called = true; }, @@ -53,7 +53,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests var pipe = _pipeFactory.Create(pipeOptions); var serviceContext = new TestServiceContext(); var frame = new Frame(null, new FrameContext { ServiceContext = serviceContext }); - var socketOutput = new OutputProducer(pipe.Writer, frame, "0", serviceContext.Log); + var socketOutput = new OutputProducer(pipe.Writer, "0", serviceContext.Log); return socketOutput; } diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/StreamSocketOutputTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/StreamSocketOutputTests.cs deleted file mode 100644 index 0a3f383dd9..0000000000 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/StreamSocketOutputTests.cs +++ /dev/null @@ -1,110 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using System.IO; -using Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal; -using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; -using Xunit; - -namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests -{ - public class StreamSocketOutputTests - { - [Fact] - public void DoesNotThrowForNullBuffers() - { - // This test was added because SslStream throws if passed null buffers with (count == 0) - // Which happens if ProduceEnd is called in Frame without _responseStarted == true - // As it calls ProduceStart with write immediate == true - // This happens in WebSocket Upgrade over SSL - using (var factory = new PipeFactory()) - { - var socketOutput = new StreamSocketOutput(new ThrowsOnNullWriteStream(), factory.Create()); - - // Should not throw - socketOutput.Write(default(ArraySegment), true); - - Assert.True(true); - - socketOutput.Dispose(); - } - } - - private class ThrowsOnNullWriteStream : Stream - { - public override bool CanRead - { - get - { - throw new NotImplementedException(); - } - } - - public override bool CanSeek - { - get - { - throw new NotImplementedException(); - } - } - - public override bool CanWrite - { - get - { - throw new NotImplementedException(); - } - } - - public override long Length - { - get - { - throw new NotImplementedException(); - } - } - - public override long Position - { - get - { - throw new NotImplementedException(); - } - - set - { - throw new NotImplementedException(); - } - } - - public override void Flush() - { - throw new NotImplementedException(); - } - - public override int Read(byte[] buffer, int offset, int count) - { - throw new NotImplementedException(); - } - - public override long Seek(long offset, SeekOrigin origin) - { - throw new NotImplementedException(); - } - - public override void SetLength(long value) - { - throw new NotImplementedException(); - } - - public override void Write(byte[] buffer, int offset, int count) - { - if (buffer == null) - { - throw new ArgumentNullException(nameof(buffer)); - } - } - } - } -} diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ConnectionAdapterTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ConnectionAdapterTests.cs index 906e81ae76..eb5a857358 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ConnectionAdapterTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ConnectionAdapterTests.cs @@ -4,6 +4,7 @@ using System; using System.IO; using System.Net; +using System.Net.Sockets; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Http.Features; @@ -76,6 +77,70 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } } + [Fact] + public async Task ImmediateFinAfterOnConnectionAsyncClosesGracefully() + { + var listenOptions = new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0)) + { + ConnectionAdapters = { new AsyncConnectionAdapter() } + }; + + var serviceContext = new TestServiceContext(); + + using (var server = new TestServer(TestApp.EchoApp, serviceContext, listenOptions)) + { + using (var connection = server.CreateConnection()) + { + // FIN + connection.Shutdown(SocketShutdown.Send); + await connection.WaitForConnectionClose(); + } + } + } + + [Fact] + public async Task ImmediateFinAfterThrowingClosesGracefully() + { + var listenOptions = new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0)) + { + ConnectionAdapters = { new ThrowingConnectionAdapter() } + }; + + var serviceContext = new TestServiceContext(); + + using (var server = new TestServer(TestApp.EchoApp, serviceContext, listenOptions)) + { + using (var connection = server.CreateConnection()) + { + // FIN + connection.Shutdown(SocketShutdown.Send); + await connection.WaitForConnectionClose(); + } + } + } + + [Fact] + public async Task ImmediateShutdownAfterOnConnectionAsyncDoesNotCrash() + { + var listenOptions = new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0)) + { + ConnectionAdapters = { new AsyncConnectionAdapter() } + }; + + var serviceContext = new TestServiceContext(); + + var stopTask = Task.CompletedTask; + using (var server = new TestServer(TestApp.EchoApp, serviceContext, listenOptions)) + { + using (var connection = server.CreateConnection()) + { + stopTask = server.StopAsync(); + } + + await stopTask; + } + } + [Fact] public async Task ThrowingSynchronousConnectionAdapterDoesNotCrashServer() { @@ -121,7 +186,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } public int BytesRead => _rewritingStream.BytesRead; - } + } private class AsyncConnectionAdapter : IConnectionAdapter { diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs index c4eb51dfdf..5c58b48664 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs @@ -1051,24 +1051,28 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { using (var connection = server.CreateConnection()) { - // Never send the body so CopyToAsync always fails. + // Full request and response await connection.Send( "POST / HTTP/1.1", "Host:", "Content-Length: 5", "", - "HelloPOST / HTTP/1.1", - "Host:", - "Content-Length: 5", - "", - ""); + "Hello"); - await connection.ReceiveForcedEnd( + await connection.Receive( "HTTP/1.1 200 OK", $"Date: {testContext.DateHeaderValue}", "Content-Length: 5", "", "World"); + + // Never send the body so CopyToAsync always fails. + await connection.Send("POST / HTTP/1.1", + "Host:", + "Content-Length: 5", + "", + ""); + await connection.WaitForConnectionClose(); } } diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/TestServer.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/TestServer.cs index 73f2adfbf9..930c21cd08 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/TestServer.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/TestServer.cs @@ -5,6 +5,7 @@ using System; using System.Net; using System.Net.Sockets; using System.Reflection; +using System.Threading.Tasks; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting.Server; @@ -108,6 +109,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests return new TestConnection(Port, AddressFamily); } + public Task StopAsync() + { + return _host.StopAsync(); + } + public void Dispose() { _host.Dispose(); diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameWritingBenchmark.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameWritingBenchmark.cs index b735e76ff9..bef07b9063 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameWritingBenchmark.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameWritingBenchmark.cs @@ -87,7 +87,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance private TestFrame MakeFrame() { - var socketInput = new PipeFactory().Create(); + var factory = new PipeFactory(); + var input = factory.Create(); + var output = factory.Create(); var serviceContext = new ServiceContext { @@ -104,10 +106,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance var frame = new TestFrame(application: null, context: frameContext) { - Input = socketInput.Reader, - Output = new MockSocketOutput() + Input = input.Reader, }; + frame.Output = new OutputProducer(output.Writer, "", null); + frame.Reset(); return frame; diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Microsoft.AspNetCore.Server.Kestrel.Performance.csproj b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Microsoft.AspNetCore.Server.Kestrel.Performance.csproj index 54cd499106..42fcca542b 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Microsoft.AspNetCore.Server.Kestrel.Performance.csproj +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Microsoft.AspNetCore.Server.Kestrel.Performance.csproj @@ -1,4 +1,4 @@ - + @@ -14,7 +14,6 @@ - diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/ResponseHeadersWritingBenchmark.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/ResponseHeadersWritingBenchmark.cs index 012deb1b70..8f28af9ef6 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/ResponseHeadersWritingBenchmark.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/ResponseHeadersWritingBenchmark.cs @@ -8,7 +8,6 @@ using System.Threading; using System.Threading.Tasks; using BenchmarkDotNet.Attributes; using Microsoft.AspNetCore.Server.Kestrel.Core; -using Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; @@ -113,7 +112,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance var factory = new PipeFactory(); var input = factory.Create(); var output = factory.Create(); - var socketOutput = new StreamSocketOutput(Stream.Null, output); var serviceContext = new ServiceContext { @@ -129,19 +127,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance ConnectionInformation = new MockConnectionInformation() }; - var outputProducer = new OutputProducer(output.Writer, null, null, null); var frame = new TestFrame(application: null, context: frameContext) { Input = input.Reader, - Output = socketOutput, - LifetimeControl = new ConnectionLifetimeControl(null, output.Reader, outputProducer, serviceContext.Log) }; + frame.Output = new OutputProducer(output.Writer, "", null); frame.Reset(); - // Start writing - var ignore = socketOutput.WriteOutputAsync(); - _frame = frame; } diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/LibuvOutputConsumerTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/LibuvOutputConsumerTests.cs index bbaaea6054..13b3706657 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/LibuvOutputConsumerTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/LibuvOutputConsumerTests.cs @@ -9,7 +9,6 @@ using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; -using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions; using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal; using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking; using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests.TestHelpers; @@ -75,7 +74,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests var buffer = new ArraySegment(new byte[bufferSize], 0, bufferSize); // Act - var writeTask = socketOutput.WriteAsync(buffer, default(CancellationToken)); + var writeTask = socketOutput.WriteAsync(buffer); // Assert await writeTask.TimeoutAfter(TimeSpan.FromSeconds(5)); @@ -110,7 +109,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests var buffer = new ArraySegment(new byte[bufferSize], 0, bufferSize); // Act - var writeTask = socketOutput.WriteAsync(buffer, default(CancellationToken)); + var writeTask = socketOutput.WriteAsync(buffer); // Assert await writeTask.TimeoutAfter(TimeSpan.FromSeconds(5)); @@ -156,7 +155,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests var buffer = new ArraySegment(new byte[bufferSize], 0, bufferSize); // Act - var writeTask = socketOutput.WriteAsync(buffer, default(CancellationToken)); + var writeTask = socketOutput.WriteAsync(buffer); // Assert Assert.False(writeTask.IsCompleted); @@ -211,14 +210,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests var buffer = new ArraySegment(new byte[bufferSize], 0, bufferSize); // Act - var writeTask1 = socketOutput.WriteAsync(buffer, default(CancellationToken)); + var writeTask1 = socketOutput.WriteAsync(buffer); // Assert // The first write should pre-complete since it is <= _maxBytesPreCompleted. Assert.Equal(TaskStatus.RanToCompletion, writeTask1.Status); // Act - var writeTask2 = socketOutput.WriteAsync(buffer, default(CancellationToken)); + var writeTask2 = socketOutput.WriteAsync(buffer); await _mockLibuv.OnPostTask; // Assert @@ -275,7 +274,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests var halfWriteBehindBuffer = new ArraySegment(data, 0, bufferSize); // Act - var writeTask1 = socketOutput.WriteAsync(halfWriteBehindBuffer, default(CancellationToken)); + var writeTask1 = socketOutput.WriteAsync(halfWriteBehindBuffer); // Assert // The first write should pre-complete since it is <= _maxBytesPreCompleted. @@ -284,17 +283,17 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests Assert.NotEmpty(completeQueue); // Add more bytes to the write-behind buffer to prevent the next write from - ((ISocketOutput)socketOutput).Write((writableBuffer, state) => + socketOutput.Write((writableBuffer, state) => { writableBuffer.Write(state); }, halfWriteBehindBuffer); // Act - var writeTask2 = socketOutput.WriteAsync(halfWriteBehindBuffer, default(CancellationToken)); + var writeTask2 = socketOutput.WriteAsync(halfWriteBehindBuffer); Assert.False(writeTask2.IsCompleted); - var writeTask3 = socketOutput.WriteAsync(halfWriteBehindBuffer, default(CancellationToken)); + var writeTask3 = socketOutput.WriteAsync(halfWriteBehindBuffer); Assert.False(writeTask3.IsCompleted); // Drain the write queue @@ -345,7 +344,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests var fullBuffer = new ArraySegment(data, 0, bufferSize); // Act - var task1Success = socketOutput.WriteAsync(fullBuffer, abortedSource.Token); + var task1Success = socketOutput.WriteAsync(fullBuffer, cancellationToken: abortedSource.Token); // task1 should complete successfully as < _maxBytesPreCompleted // First task is completed and successful @@ -354,8 +353,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests Assert.False(task1Success.IsFaulted); // following tasks should wait. - var task2Success = socketOutput.WriteAsync(fullBuffer, default(CancellationToken)); - var task3Canceled = socketOutput.WriteAsync(fullBuffer, abortedSource.Token); + var task2Success = socketOutput.WriteAsync(fullBuffer); + var task3Canceled = socketOutput.WriteAsync(fullBuffer, cancellationToken: abortedSource.Token); // Give time for tasks to percolate await _mockLibuv.OnPostTask; @@ -383,7 +382,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests // A final write guarantees that the error is observed by OutputProducer, // but doesn't return a canceled/faulted task. - var task4Success = socketOutput.WriteAsync(fullBuffer, default(CancellationToken)); + var task4Success = socketOutput.WriteAsync(fullBuffer, cancellationToken: default(CancellationToken)); Assert.True(task4Success.IsCompleted); Assert.False(task4Success.IsCanceled); Assert.False(task4Success.IsFaulted); @@ -429,7 +428,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests var fullBuffer = new ArraySegment(data, 0, bufferSize); // Act - var task1Success = socketOutput.WriteAsync(fullBuffer, abortedSource.Token); + var task1Success = socketOutput.WriteAsync(fullBuffer, cancellationToken: abortedSource.Token); // task1 should complete successfully as < _maxBytesPreCompleted // First task is completed and successful @@ -438,7 +437,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests Assert.False(task1Success.IsFaulted); // following tasks should wait. - var task3Canceled = socketOutput.WriteAsync(fullBuffer, abortedSource.Token); + var task3Canceled = socketOutput.WriteAsync(fullBuffer, cancellationToken: abortedSource.Token); // Give time for tasks to percolate await _mockLibuv.OnPostTask; @@ -458,7 +457,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests // A final write guarantees that the error is observed by OutputProducer, // but doesn't return a canceled/faulted task. - var task4Success = socketOutput.WriteAsync(fullBuffer, default(CancellationToken)); + var task4Success = socketOutput.WriteAsync(fullBuffer); Assert.True(task4Success.IsCompleted); Assert.False(task4Success.IsCanceled); Assert.False(task4Success.IsFaulted); @@ -504,7 +503,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests var fullBuffer = new ArraySegment(data, 0, bufferSize); // Act - var task1Waits = socketOutput.WriteAsync(fullBuffer, default(CancellationToken)); + var task1Waits = socketOutput.WriteAsync(fullBuffer); // First task is not completed Assert.False(task1Waits.IsCompleted); @@ -512,7 +511,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests Assert.False(task1Waits.IsFaulted); // following tasks should wait. - var task3Canceled = socketOutput.WriteAsync(fullBuffer, abortedSource.Token); + var task3Canceled = socketOutput.WriteAsync(fullBuffer, cancellationToken: abortedSource.Token); // Give time for tasks to percolate await _mockLibuv.OnPostTask; @@ -537,7 +536,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests // A final write guarantees that the error is observed by OutputProducer, // but doesn't return a canceled/faulted task. - var task4Success = socketOutput.WriteAsync(fullBuffer, default(CancellationToken)); + var task4Success = socketOutput.WriteAsync(fullBuffer); Assert.True(task4Success.IsCompleted); Assert.False(task4Success.IsCanceled); Assert.False(task4Success.IsFaulted); @@ -575,7 +574,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests var buffer = new ArraySegment(new byte[bufferSize], 0, bufferSize); // Act (Pre-complete the maximum number of bytes in preparation for the rest of the test) - var writeTask1 = socketOutput.WriteAsync(buffer, default(CancellationToken)); + var writeTask1 = socketOutput.WriteAsync(buffer); // Assert // The first write should pre-complete since it is < _maxBytesPreCompleted. @@ -584,8 +583,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests Assert.NotEmpty(completeQueue); // Act - var writeTask2 = socketOutput.WriteAsync(buffer, default(CancellationToken)); - var writeTask3 = socketOutput.WriteAsync(buffer, default(CancellationToken)); + var writeTask2 = socketOutput.WriteAsync(buffer); + var writeTask3 = socketOutput.WriteAsync(buffer); // Drain the write queue while (completeQueue.TryDequeue(out var triggerNextCompleted)) @@ -635,8 +634,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests // Two calls to WriteAsync trigger uv_write once if both calls // are made before write is scheduled - var ignore = socketOutput.WriteAsync(buffer, CancellationToken.None); - ignore = socketOutput.WriteAsync(buffer, CancellationToken.None); + var ignore = socketOutput.WriteAsync(buffer); + ignore = socketOutput.WriteAsync(buffer); _mockLibuv.KestrelThreadBlocker.Set(); @@ -671,10 +670,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests var frame = new Frame(null, new FrameContext { ServiceContext = serviceContext }); var socket = new MockSocket(_mockLibuv, _libuvThread.Loop.ThreadId, transportContext.Log); - var socketOutput = new OutputProducer(pipe.Writer, frame, "0", serviceContext.Log); + var outputProducer = new OutputProducer(pipe.Writer, "0", serviceContext.Log); var consumer = new LibuvOutputConsumer(pipe.Reader, _libuvThread, socket, "0", transportContext.Log); - - frame.LifetimeControl = new ConnectionLifetimeControl("0", pipe.Reader, socketOutput, serviceContext.Log); + frame.Output = outputProducer; if (cts != null) { @@ -683,7 +681,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests var ignore = WriteOutputAsync(consumer, pipe.Reader, frame); - return socketOutput; + return outputProducer; } private async Task WriteOutputAsync(LibuvOutputConsumer consumer, IPipeReader outputReader, Frame frame) diff --git a/test/shared/MockSocketOutput.cs b/test/shared/MockSocketOutput.cs deleted file mode 100644 index 9089bca83d..0000000000 --- a/test/shared/MockSocketOutput.cs +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using System.Threading; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; -using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; -using Microsoft.Extensions.Internal; - -namespace Microsoft.AspNetCore.Testing -{ - public class MockSocketOutput : ISocketOutput - { - public MockSocketOutput() - { - } - - public void Write(ArraySegment buffer, bool chunk = false) - { - } - - public Task WriteAsync(ArraySegment buffer, bool chunk = false, CancellationToken cancellationToken = default(CancellationToken)) - { - return TaskCache.CompletedTask; - } - - public void Flush() - { - } - - public Task FlushAsync(CancellationToken cancellationToken = new CancellationToken()) - { - return TaskCache.CompletedTask; - } - - public void Write(Action write, T state) where T : struct - { - - } - } -} From c8b6a2be56c42ec1507ba0dd32aa66d6f0ac9761 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Tue, 9 May 2017 17:40:25 -0700 Subject: [PATCH 1283/1662] More FrameConnection refactoring (#1820) * More FrameConnection refactoring - This change reverts the change to complete the writer with an exception on abort because of the number of first chance exceptions that get thrown. - This change also moves connection logging into FrameConnection instead of being split between the ConnectionHandler and FrameConnection. - Fixed issues with LibuvOutputConsumerTests that leak WriteReq since cancelled writes no longer end the connection. --- .../Adapter/Internal/AdaptedPipeline.cs | 25 +++++---- .../Internal/ConnectionHandler.cs | 5 +- .../Internal/FrameConnection.cs | 18 +++--- .../Internal/FrameConnectionContext.cs | 3 +- .../Internal/Http/OutputProducer.cs | 19 ++----- .../Internal/LibuvOutputConsumer.cs | 55 +++++++++---------- .../SocketConnection.cs | 21 +++---- .../FrameTests.cs | 2 +- .../OutputProducerTests.cs | 2 +- .../FrameWritingBenchmark.cs | 2 +- .../ResponseHeadersWritingBenchmark.cs | 2 +- .../LibuvOutputConsumerTests.cs | 28 +++++++++- 12 files changed, 100 insertions(+), 82 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/Internal/AdaptedPipeline.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/Internal/AdaptedPipeline.cs index b73cbdb50e..cf2778603d 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/Internal/AdaptedPipeline.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/Internal/AdaptedPipeline.cs @@ -7,7 +7,6 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; -using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal { @@ -16,17 +15,17 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal private const int MinAllocBufferSize = 2048; private readonly IKestrelTrace _trace; - private readonly IPipeWriter _transportOutputPipeWriter; + private readonly IPipe _transportOutputPipe; private readonly IPipeReader _transportInputPipeReader; public AdaptedPipeline(IPipeReader transportInputPipeReader, - IPipeWriter transportOutputPipeWriter, + IPipe transportOutputPipe, IPipe inputPipe, IPipe outputPipe, IKestrelTrace trace) { _transportInputPipeReader = transportInputPipeReader; - _transportOutputPipeWriter = transportOutputPipeWriter; + _transportOutputPipe = transportOutputPipe; Input = inputPipe; Output = outputPipe; _trace = trace; @@ -58,18 +57,24 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal while (true) { - var readResult = await Output.Reader.ReadAsync(); - var buffer = readResult.Buffer; + var result = await Output.Reader.ReadAsync(); + var buffer = result.Buffer; try { - if (buffer.IsEmpty && readResult.IsCompleted) + if (result.IsCancelled) { + // Forward the cancellation to the transport pipe + _transportOutputPipe.Reader.CancelPendingRead(); break; } if (buffer.IsEmpty) { + if (result.IsCompleted) + { + break; + } await stream.FlushAsync(); } else if (buffer.IsSingleSpan) @@ -99,7 +104,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal finally { Output.Reader.Complete(); - _transportOutputPipeWriter.Complete(error); + _transportOutputPipe.Writer.Complete(error); } } @@ -111,8 +116,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal { if (stream == null) { - // If the stream is null then we're going to abort the connection - throw new ConnectionAbortedException(); + // REVIEW: Do we need an exception here? + return; } while (true) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/ConnectionHandler.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/ConnectionHandler.cs index 523af72020..ea3ba6e631 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/ConnectionHandler.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/ConnectionHandler.cs @@ -47,16 +47,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal ConnectionId = connectionId, FrameConnectionId = frameConnectionId, ServiceContext = _serviceContext, - PipeFactory = connectionInfo.PipeFactory, + ConnectionInformation = connectionInfo, ConnectionAdapters = _listenOptions.ConnectionAdapters, Frame = frame, Input = inputPipe, Output = outputPipe, }); - _serviceContext.Log.ConnectionStart(connectionId); - KestrelEventSource.Log.ConnectionStart(connection, connectionInfo); - // Since data cannot be added to the inputPipe by the transport until OnConnection returns, // Frame.ProcessRequestsAsync is guaranteed to unblock the transport thread before calling // application code. diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnection.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnection.cs index b25f7a983d..8ca4c36372 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnection.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnection.cs @@ -40,7 +40,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal public IPipeWriter Input => _context.Input.Writer; public IPipeReader Output => _context.Output.Reader; - private PipeFactory PipeFactory => _context.PipeFactory; + private PipeFactory PipeFactory => _context.ConnectionInformation.PipeFactory; // Internal for testing internal PipeOptions AdaptedInputPipeOptions => new PipeOptions @@ -70,21 +70,24 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal { try { + Log.ConnectionStart(ConnectionId); + KestrelEventSource.Log.ConnectionStart(this, _context.ConnectionInformation); + AdaptedPipeline adaptedPipeline = null; var adaptedPipelineTask = Task.CompletedTask; var input = _context.Input.Reader; - var output = _context.Output.Writer; + var output = _context.Output; if (_connectionAdapters.Count > 0) { - adaptedPipeline = new AdaptedPipeline(_context.Input.Reader, - _context.Output.Writer, + adaptedPipeline = new AdaptedPipeline(input, + output, PipeFactory.Create(AdaptedInputPipeOptions), PipeFactory.Create(AdaptedOutputPipeOptions), Log); input = adaptedPipeline.Input.Reader; - output = adaptedPipeline.Output.Writer; + output = adaptedPipeline.Output; } // Set these before the first await, this is to make sure that we don't yield control @@ -114,6 +117,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal { _context.ServiceContext.ConnectionManager.RemoveConnection(_context.FrameConnectionId); DisposeAdaptedConnections(); + + Log.ConnectionStop(ConnectionId); + KestrelEventSource.Log.ConnectionStop(this); } } @@ -122,8 +128,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal // Abort the connection (if not already aborted) _frame.Abort(ex); - Log.ConnectionStop(ConnectionId); - KestrelEventSource.Log.ConnectionStop(this); _socketClosedTcs.TrySetResult(null); } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnectionContext.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnectionContext.cs index d9a7c38148..24c30becbe 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnectionContext.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnectionContext.cs @@ -5,6 +5,7 @@ using System.Collections.Generic; using Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal { @@ -13,8 +14,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal public string ConnectionId { get; set; } public long FrameConnectionId { get; set; } public ServiceContext ServiceContext { get; set; } - public PipeFactory PipeFactory { get; set; } public List ConnectionAdapters { get; set; } + public IConnectionInformation ConnectionInformation { get; set; } public Frame Frame { get; set; } public IPipe Input { get; set; } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/OutputProducer.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/OutputProducer.cs index 0d024d6a7f..0f72b16648 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/OutputProducer.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/OutputProducer.cs @@ -6,7 +6,6 @@ using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; -using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions; using Microsoft.Extensions.Internal; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http @@ -21,10 +20,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http // This locks access to to all of the below fields private readonly object _contextLock = new object(); - private bool _cancelled = false; private bool _completed = false; - private readonly IPipeWriter _pipe; + private readonly IPipe _pipe; // https://github.com/dotnet/corefxlab/issues/1334 // Pipelines don't support multiple awaiters on flush @@ -33,7 +31,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http private readonly object _flushLock = new object(); private Action _flushCompleted; - public OutputProducer(IPipeWriter pipe, string connectionId, IKestrelTrace log) + public OutputProducer(IPipe pipe, string connectionId, IKestrelTrace log) { _pipe = pipe; _connectionId = connectionId; @@ -50,13 +48,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { if (cancellationToken.IsCancellationRequested) { - _cancelled = true; return Task.FromCanceled(cancellationToken); } - else if (_cancelled) - { - return TaskCache.CompletedTask; - } return WriteAsync(buffer, cancellationToken, chunk); } @@ -80,7 +73,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http return; } - var buffer = _pipe.Alloc(1); + var buffer = _pipe.Writer.Alloc(1); callback(buffer, state); buffer.Commit(); } @@ -97,7 +90,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http _log.ConnectionDisconnect(_connectionId); _completed = true; - _pipe.Complete(); + _pipe.Writer.Complete(); } } @@ -112,7 +105,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http _log.ConnectionDisconnect(_connectionId); _completed = true; - _pipe.Complete(new ConnectionAbortedException()); + _pipe.Reader.CancelPendingRead(); } } @@ -130,7 +123,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http return TaskCache.CompletedTask; } - writableBuffer = _pipe.Alloc(1); + writableBuffer = _pipe.Writer.Alloc(1); var writer = new WritableBufferWriter(writableBuffer); if (buffer.Count > 0) { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvOutputConsumer.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvOutputConsumer.cs index 30b151a2c2..97cfbd79cd 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvOutputConsumer.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvOutputConsumer.cs @@ -37,50 +37,47 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal while (true) { + var result = await _pipe.ReadAsync(); + var buffer = result.Buffer; + var consumed = buffer.End; + try { - var result = await _pipe.ReadAsync(); - var buffer = result.Buffer; - var consumed = buffer.End; - - try + if (result.IsCancelled) { - if (!buffer.IsEmpty) + break; + } + + if (!buffer.IsEmpty) + { + var writeReq = pool.Allocate(); + + try { - var writeReq = pool.Allocate(); + var writeResult = await writeReq.WriteAsync(_socket, buffer); - try + LogWriteInfo(writeResult.Status, writeResult.Error); + + if (writeResult.Error != null) { - var writeResult = await writeReq.WriteAsync(_socket, buffer); - - LogWriteInfo(writeResult.Status, writeResult.Error); - - if (writeResult.Error != null) - { - consumed = buffer.Start; - throw writeResult.Error; - } - } - finally - { - // Make sure we return the writeReq to the pool - pool.Return(writeReq); + consumed = buffer.Start; + throw writeResult.Error; } } - - if (buffer.IsEmpty && result.IsCompleted) + finally { - break; + // Make sure we return the writeReq to the pool + pool.Return(writeReq); } } - finally + else if (result.IsCompleted) { - _pipe.Advance(consumed); + break; } } - catch (ConnectionAbortedException) + finally { - break; + _pipe.Advance(consumed); } } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets/SocketConnection.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets/SocketConnection.cs index 28685c3b60..ff0a0c2202 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets/SocketConnection.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets/SocketConnection.cs @@ -167,6 +167,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets var result = await _output.ReadAsync(); var buffer = result.Buffer; + if (result.IsCancelled) + { + break; + } + try { if (!buffer.IsEmpty) @@ -189,15 +194,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets } } } - - if (result.IsCancelled) - { - // Send a FIN - _socket.Shutdown(SocketShutdown.Send); - break; - } - - if (buffer.IsEmpty && result.IsCompleted) + else if (result.IsCompleted) { break; } @@ -207,6 +204,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets _output.Advance(buffer.End); } } + + _socket.Shutdown(SocketShutdown.Send); } catch (SocketException ex) when (ex.SocketErrorCode == SocketError.OperationAborted) { @@ -216,10 +215,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets { error = null; } - catch (ConnectionAbortedException) - { - error = null; - } catch (IOException ex) { error = ex; diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameTests.cs index eb2c93f583..51ae37a73a 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameTests.cs @@ -70,7 +70,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests TimeoutControl = Mock.Of() }; - _frame.Output = new OutputProducer(output.Writer, "", Mock.Of()); + _frame.Output = new OutputProducer(output, "", Mock.Of()); _frame.Reset(); } diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/OutputProducerTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/OutputProducerTests.cs index 1e8ae196bd..1ec0f7656c 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/OutputProducerTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/OutputProducerTests.cs @@ -53,7 +53,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests var pipe = _pipeFactory.Create(pipeOptions); var serviceContext = new TestServiceContext(); var frame = new Frame(null, new FrameContext { ServiceContext = serviceContext }); - var socketOutput = new OutputProducer(pipe.Writer, "0", serviceContext.Log); + var socketOutput = new OutputProducer(pipe, "0", serviceContext.Log); return socketOutput; } diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameWritingBenchmark.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameWritingBenchmark.cs index bef07b9063..74bbdc19c5 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameWritingBenchmark.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameWritingBenchmark.cs @@ -109,7 +109,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance Input = input.Reader, }; - frame.Output = new OutputProducer(output.Writer, "", null); + frame.Output = new OutputProducer(output, "", null); frame.Reset(); diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/ResponseHeadersWritingBenchmark.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/ResponseHeadersWritingBenchmark.cs index 8f28af9ef6..483705f3a2 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/ResponseHeadersWritingBenchmark.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/ResponseHeadersWritingBenchmark.cs @@ -131,7 +131,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance { Input = input.Reader, }; - frame.Output = new OutputProducer(output.Writer, "", null); + frame.Output = new OutputProducer(output, "", null); frame.Reset(); diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/LibuvOutputConsumerTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/LibuvOutputConsumerTests.cs index 13b3706657..16f3361be8 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/LibuvOutputConsumerTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/LibuvOutputConsumerTests.cs @@ -392,6 +392,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests Assert.True(task3Canceled.IsCanceled); Assert.True(abortedSource.IsCancellationRequested); + + await _mockLibuv.OnPostTask; + + // Complete the 4th write + while (completeQueue.TryDequeue(out var triggerNextCompleted)) + { + await _libuvThread.PostAsync(cb => cb(0), triggerNextCompleted); + } } }); } @@ -467,6 +475,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests Assert.True(task3Canceled.IsCanceled); Assert.True(abortedSource.IsCancellationRequested); + + await _mockLibuv.OnPostTask; + + // Complete the 4th write + while (completeQueue.TryDequeue(out var triggerNextCompleted)) + { + await _libuvThread.PostAsync(cb => cb(0), triggerNextCompleted); + } } }); } @@ -544,6 +560,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests // Third task is now canceled await Assert.ThrowsAsync(() => task3Canceled); Assert.True(task3Canceled.IsCanceled); + + await _mockLibuv.OnPostTask; + + // Complete the 4th write + while (completeQueue.TryDequeue(out var triggerNextCompleted)) + { + await _libuvThread.PostAsync(cb => cb(0), triggerNextCompleted); + } } }); } @@ -586,6 +610,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests var writeTask2 = socketOutput.WriteAsync(buffer); var writeTask3 = socketOutput.WriteAsync(buffer); + await _mockLibuv.OnPostTask; + // Drain the write queue while (completeQueue.TryDequeue(out var triggerNextCompleted)) { @@ -670,7 +696,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests var frame = new Frame(null, new FrameContext { ServiceContext = serviceContext }); var socket = new MockSocket(_mockLibuv, _libuvThread.Loop.ThreadId, transportContext.Log); - var outputProducer = new OutputProducer(pipe.Writer, "0", serviceContext.Log); + var outputProducer = new OutputProducer(pipe, "0", serviceContext.Log); var consumer = new LibuvOutputConsumer(pipe.Reader, _libuvThread, socket, "0", transportContext.Log); frame.Output = outputProducer; From 90ee2252a006d50d0d5e68c7365b73648d6c63c9 Mon Sep 17 00:00:00 2001 From: Pavel Krymets Date: Wed, 10 May 2017 11:35:23 -0700 Subject: [PATCH 1284/1662] Remove unnecessary package references (#1825) --- build/dependencies.props | 3 --- 1 file changed, 3 deletions(-) diff --git a/build/dependencies.props b/build/dependencies.props index 195c468790..6e343231b3 100644 --- a/build/dependencies.props +++ b/build/dependencies.props @@ -1,9 +1,6 @@ 2.0.0-* - 0.1.0-* - 0.1.0-* - 4.3.0 2.1.0-* 1.10.0-* 9.0.1 From b9518e36840ce5be8e29d82e3f53bbaf0109b9e8 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Wed, 10 May 2017 15:29:43 -0700 Subject: [PATCH 1285/1662] Invert the dependency between connection adapters and Frame (#1822) * Invert the dependency between connection adapters and Frame - Removed PrepareRequest from IAdaptedConnection and instead added a feature collection to the ConnectionAdapterContext. This allows features to be set once by the adapter instead of per request. It's the Frame's job to copy features from the connection level feature collection into the per request feature collection. - Set the scheme to "https" based on the presence of ITlsConnectionFeature. - Always set ITlsConnection feature if the HttpsAdaptedConnection doesn't throw during the handshake --- .../Internal/ConnectionAdapterContext.cs | 6 ++++- .../Adapter/Internal/IAdaptedConnection.cs | 3 --- .../Internal/LoggingConnectionAdapter.cs | 4 --- .../Internal/FrameConnection.cs | 26 ++++++++++--------- .../Internal/Http/Frame.cs | 19 +++++++------- .../HttpsConnectionAdapter.cs | 21 +++++---------- .../ConnectionAdapterTests.cs | 5 ---- .../HttpsConnectionAdapterTests.cs | 4 ++- test/shared/PassThroughConnectionAdapter.cs | 4 --- 9 files changed, 37 insertions(+), 55 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/Internal/ConnectionAdapterContext.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/Internal/ConnectionAdapterContext.cs index 6d074b3a7c..1f87c8311e 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/Internal/ConnectionAdapterContext.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/Internal/ConnectionAdapterContext.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.IO; +using Microsoft.AspNetCore.Http.Features; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal { @@ -9,11 +10,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal // we want to add more connection metadata later. public class ConnectionAdapterContext { - internal ConnectionAdapterContext(Stream connectionStream) + internal ConnectionAdapterContext(IFeatureCollection features, Stream connectionStream) { + Features = features; ConnectionStream = connectionStream; } + public IFeatureCollection Features { get; } + public Stream ConnectionStream { get; } } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/Internal/IAdaptedConnection.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/Internal/IAdaptedConnection.cs index 8129cdbb35..5960490e2b 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/Internal/IAdaptedConnection.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/Internal/IAdaptedConnection.cs @@ -3,14 +3,11 @@ using System; using System.IO; -using Microsoft.AspNetCore.Http.Features; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal { public interface IAdaptedConnection : IDisposable { Stream ConnectionStream { get; } - - void PrepareRequest(IFeatureCollection requestFeatures); } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/Internal/LoggingConnectionAdapter.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/Internal/LoggingConnectionAdapter.cs index 570075ecb7..10d370df56 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/Internal/LoggingConnectionAdapter.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/Internal/LoggingConnectionAdapter.cs @@ -40,10 +40,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal public Stream ConnectionStream { get; } - public void PrepareRequest(IFeatureCollection requestFeatures) - { - } - public void Dispose() { } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnection.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnection.cs index 8ca4c36372..b9d7bcfc55 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnection.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnection.cs @@ -7,6 +7,7 @@ using System.Diagnostics; using System.IO; using System.Threading; using System.Threading.Tasks; +using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; @@ -20,7 +21,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal { private readonly FrameConnectionContext _context; private readonly Frame _frame; - private readonly List _connectionAdapters; + private List _adaptedConnections; private readonly TaskCompletionSource _socketClosedTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); private long _lastTimestamp; @@ -33,7 +34,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal { _context = context; _frame = context.Frame; - _connectionAdapters = context.ConnectionAdapters; } public string ConnectionId => _context.ConnectionId; @@ -78,7 +78,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal var input = _context.Input.Reader; var output = _context.Output; - if (_connectionAdapters.Count > 0) + if (_context.ConnectionAdapters.Count > 0) { adaptedPipeline = new AdaptedPipeline(input, output, @@ -159,17 +159,19 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal private async Task ApplyConnectionAdaptersAsync() { + var features = new FeatureCollection(); + var connectionAdapters = _context.ConnectionAdapters; var stream = new RawStream(_context.Input.Reader, _context.Output.Writer); - var adapterContext = new ConnectionAdapterContext(stream); - var adaptedConnections = new IAdaptedConnection[_connectionAdapters.Count]; + var adapterContext = new ConnectionAdapterContext(features, stream); + _adaptedConnections = new List(connectionAdapters.Count); try { - for (var i = 0; i < _connectionAdapters.Count; i++) + for (var i = 0; i < connectionAdapters.Count; i++) { - var adaptedConnection = await _connectionAdapters[i].OnConnectionAsync(adapterContext); - adaptedConnections[i] = adaptedConnection; - adapterContext = new ConnectionAdapterContext(adaptedConnection.ConnectionStream); + var adaptedConnection = await connectionAdapters[i].OnConnectionAsync(adapterContext); + _adaptedConnections.Add(adaptedConnection); + adapterContext = new ConnectionAdapterContext(features, adaptedConnection.ConnectionStream); } } catch (Exception ex) @@ -180,7 +182,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal } finally { - _frame.AdaptedConnections = adaptedConnections; + _frame.ConnectionFeatures = features; } return adapterContext.ConnectionStream; @@ -188,10 +190,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal private void DisposeAdaptedConnections() { - var adaptedConnections = _frame.AdaptedConnections; + var adaptedConnections = _adaptedConnections; if (adaptedConnections != null) { - for (int i = adaptedConnections.Length - 1; i >= 0; i--) + for (int i = adaptedConnections.Count - 1; i >= 0; i--) { adaptedConnections[i].Dispose(); } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.cs index 6a85d64757..52ea21fb96 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.cs @@ -12,7 +12,6 @@ using System.Text; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Internal.System; using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; @@ -21,6 +20,7 @@ using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions; using Microsoft.Extensions.Internal; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Primitives; +using Microsoft.AspNetCore.Http.Features; // ReSharper disable AccessToModifiedClosure @@ -103,7 +103,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http public IPipeReader Input { get; set; } public OutputProducer Output { get; set; } - public IAdaptedConnection[] AdaptedConnections { get; set; } + public IFeatureCollection ConnectionFeatures { get; set; } public ITimeoutControl TimeoutControl { get; set; } protected IKestrelTrace Log => ServiceContext.Log; @@ -349,18 +349,17 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http RequestHeaders = FrameRequestHeaders; ResponseHeaders = FrameResponseHeaders; - if (AdaptedConnections != null) + if (ConnectionFeatures != null) { - try + foreach (var feature in ConnectionFeatures) { - foreach (var adaptedConnection in AdaptedConnections) + // Set the scheme to https if there's an ITlsConnectionFeature + if (feature.Key == typeof(ITlsConnectionFeature)) { - adaptedConnection.PrepareRequest(this); + Scheme = "https"; } - } - catch (Exception ex) - { - Log.LogError(0, ex, $"Uncaught exception from the {nameof(IAdaptedConnection.PrepareRequest)} method of an {nameof(IAdaptedConnection)}."); + + FastFeatureSet(feature.Key, feature.Value); } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Https/HttpsConnectionAdapter.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Https/HttpsConnectionAdapter.cs index 7c3bca81a3..328f4263aa 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Https/HttpsConnectionAdapter.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Https/HttpsConnectionAdapter.cs @@ -109,6 +109,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Https return _closedAdaptedConnection; } + // Always set the feature even though the cert might be null + context.Features.Set(new TlsConnectionFeature + { + ClientCertificate = (X509Certificate2)sslStream.RemoteCertificate + }); + return new HttpsAdaptedConnection(sslStream); } @@ -123,17 +129,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Https public Stream ConnectionStream => _sslStream; - public void PrepareRequest(IFeatureCollection requestFeatures) - { - var clientCertificate = (X509Certificate2)_sslStream.RemoteCertificate; - if (clientCertificate != null) - { - requestFeatures.Set(new TlsConnectionFeature { ClientCertificate = clientCertificate }); - } - - requestFeatures.Get().Scheme = "https"; - } - public void Dispose() { _sslStream.Dispose(); @@ -144,10 +139,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Https { public Stream ConnectionStream { get; } = new ClosedStream(); - public void PrepareRequest(IFeatureCollection requestFeatures) - { - } - public void Dispose() { } diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ConnectionAdapterTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ConnectionAdapterTests.cs index eb5a857358..7c85fe99c5 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ConnectionAdapterTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ConnectionAdapterTests.cs @@ -7,7 +7,6 @@ using System.Net; using System.Net.Sockets; using System.Threading; using System.Threading.Tasks; -using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal; using Microsoft.AspNetCore.Testing; @@ -218,10 +217,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests public Stream ConnectionStream { get; } - public void PrepareRequest(IFeatureCollection requestFeatures) - { - } - public void Dispose() { } diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/HttpsConnectionAdapterTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/HttpsConnectionAdapterTests.cs index e4d6e0eb22..eb4b7976d1 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/HttpsConnectionAdapterTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/HttpsConnectionAdapterTests.cs @@ -94,7 +94,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests using (var server = new TestServer(context => { - Assert.Equal(context.Features.Get(), null); + var tlsFeature = context.Features.Get(); + Assert.NotNull(tlsFeature); + Assert.Null(tlsFeature.ClientCertificate); return context.Response.WriteAsync("hello world"); }, serviceContext, listenOptions)) diff --git a/test/shared/PassThroughConnectionAdapter.cs b/test/shared/PassThroughConnectionAdapter.cs index 7d6fdd8222..c018e49ad7 100644 --- a/test/shared/PassThroughConnectionAdapter.cs +++ b/test/shared/PassThroughConnectionAdapter.cs @@ -27,10 +27,6 @@ namespace Microsoft.AspNetCore.Testing public Stream ConnectionStream { get; } - public void PrepareRequest(IFeatureCollection requestFeatures) - { - } - public void Dispose() { } From 37f15bdd85cf9e32904232554202dc4a6052ef42 Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Wed, 10 May 2017 16:48:37 -0700 Subject: [PATCH 1286/1662] Create Frame in FrameConnection. --- .../Internal/ConnectionHandler.cs | 12 +----- .../Internal/FrameConnection.cs | 42 ++++++++++++++----- .../Internal/FrameConnectionContext.cs | 1 - .../Internal/Http/Frame.cs | 8 ++-- .../Internal/Http/FrameContext.cs | 5 +++ .../FrameResponseHeadersTests.cs | 22 +++++----- .../FrameTests.cs | 27 ++++-------- .../OutputProducerTests.cs | 1 + .../TestInput.cs | 16 ++++--- .../FrameParsingOverheadBenchmark.cs | 4 +- .../FrameWritingBenchmark.cs | 15 +++---- .../RequestParsingBenchmark.cs | 4 +- .../ResponseHeaderCollectionBenchmark.cs | 8 ++-- .../ResponseHeadersWritingBenchmark.cs | 14 +++---- .../LibuvOutputConsumerTests.cs | 15 ++++--- test/shared/TestFrame.cs | 5 ++- 16 files changed, 108 insertions(+), 91 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/ConnectionHandler.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/ConnectionHandler.cs index ea3ba6e631..96f510ea45 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/ConnectionHandler.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/ConnectionHandler.cs @@ -33,15 +33,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal var connectionId = CorrelationIdGenerator.GetNextId(); var frameConnectionId = Interlocked.Increment(ref _lastFrameConnectionId); - var frameContext = new FrameContext - { - ConnectionId = connectionId, - ConnectionInformation = connectionInfo, - ServiceContext = _serviceContext - }; - - var frame = new Frame(_application, frameContext); - var connection = new FrameConnection(new FrameConnectionContext { ConnectionId = connectionId, @@ -49,7 +40,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal ServiceContext = _serviceContext, ConnectionInformation = connectionInfo, ConnectionAdapters = _listenOptions.ConnectionAdapters, - Frame = frame, Input = inputPipe, Output = outputPipe, }); @@ -57,7 +47,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal // Since data cannot be added to the inputPipe by the transport until OnConnection returns, // Frame.ProcessRequestsAsync is guaranteed to unblock the transport thread before calling // application code. - connection.StartRequestProcessing(); + connection.StartRequestProcessing(_application); return connection; } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnection.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnection.cs index b9d7bcfc55..9b4da51ec1 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnection.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnection.cs @@ -8,6 +8,7 @@ using System.IO; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Http.Features; +using Microsoft.AspNetCore.Hosting.Server; using Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; @@ -20,9 +21,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal public class FrameConnection : IConnectionContext, ITimeoutControl { private readonly FrameConnectionContext _context; - private readonly Frame _frame; private List _adaptedConnections; private readonly TaskCompletionSource _socketClosedTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + private Frame _frame; private long _lastTimestamp; private long _timeoutTimestamp = long.MaxValue; @@ -33,7 +34,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal public FrameConnection(FrameConnectionContext context) { _context = context; - _frame = context.Frame; } public string ConnectionId => _context.ConnectionId; @@ -61,12 +61,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal private IKestrelTrace Log => _context.ServiceContext.Log; - public void StartRequestProcessing() + public void StartRequestProcessing(IHttpApplication application) { - _lifetimeTask = ProcessRequestsAsync(); + _lifetimeTask = ProcessRequestsAsync(application); } - private async Task ProcessRequestsAsync() + private async Task ProcessRequestsAsync(IHttpApplication application) { try { @@ -90,11 +90,19 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal output = adaptedPipeline.Output; } - // Set these before the first await, this is to make sure that we don't yield control - // to the transport until we've added the connection to the connection manager - _frame.TimeoutControl = this; - _frame.Input = input; - _frame.Output = new OutputProducer(output, ConnectionId, Log); + // _frame must be initialized before adding the connection to the connection manager + _frame = new Frame(application, new FrameContext + { + ConnectionId = _context.ConnectionId, + ConnectionInformation = _context.ConnectionInformation, + ServiceContext = _context.ServiceContext, + TimeoutControl = this, + Input = input, + Output = output + }); + + // Do this before the first await so we don't yield control to the transport until we've + // added the connection to the connection manager _context.ServiceContext.ConnectionManager.AddConnection(_context.FrameConnectionId, this); _lastTimestamp = _context.ServiceContext.SystemClock.UtcNow.Ticks; @@ -125,6 +133,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal public void OnConnectionClosed(Exception ex) { + Debug.Assert(_frame != null, $"nameof({_frame}) is null"); + // Abort the connection (if not already aborted) _frame.Abort(ex); @@ -133,6 +143,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal public Task StopAsync() { + Debug.Assert(_frame != null, $"nameof({_frame}) is null"); + _frame.Stop(); return _lifetimeTask; @@ -140,12 +152,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal public void Abort(Exception ex) { + Debug.Assert(_frame != null, $"nameof({_frame}) is null"); + // Abort the connection (if not already aborted) _frame.Abort(ex); } public Task AbortAsync(Exception ex) { + Debug.Assert(_frame != null, $"nameof({_frame}) is null"); + // Abort the connection (if not already aborted) _frame.Abort(ex); @@ -154,11 +170,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal public void Timeout() { + Debug.Assert(_frame != null, $"nameof({_frame}) is null"); + _frame.SetBadRequestState(RequestRejectionReason.RequestTimeout); } private async Task ApplyConnectionAdaptersAsync() { + Debug.Assert(_frame != null, $"nameof({_frame}) is null"); + var features = new FeatureCollection(); var connectionAdapters = _context.ConnectionAdapters; var stream = new RawStream(_context.Input.Reader, _context.Output.Writer); @@ -202,6 +222,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal public void Tick(DateTimeOffset now) { + Debug.Assert(_frame != null, $"nameof({_frame}) is null"); + var timestamp = now.Ticks; // TODO: Use PlatformApis.VolatileRead equivalent again diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnectionContext.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnectionContext.cs index 24c30becbe..98faa9b237 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnectionContext.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnectionContext.cs @@ -16,7 +16,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal public ServiceContext ServiceContext { get; set; } public List ConnectionAdapters { get; set; } public IConnectionInformation ConnectionInformation { get; set; } - public Frame Frame { get; set; } public IPipe Input { get; set; } public IPipe Output { get; set; } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.cs index 52ea21fb96..96abde3566 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.cs @@ -96,15 +96,17 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http FrameControl = this; _keepAliveTicks = ServerOptions.Limits.KeepAliveTimeout.Ticks; _requestHeadersTimeoutTicks = ServerOptions.Limits.RequestHeadersTimeout.Ticks; + + Output = new OutputProducer(frameContext.Output, frameContext.ConnectionId, frameContext.ServiceContext.Log); } public ServiceContext ServiceContext => _frameContext.ServiceContext; public IConnectionInformation ConnectionInformation => _frameContext.ConnectionInformation; - public IPipeReader Input { get; set; } - public OutputProducer Output { get; set; } public IFeatureCollection ConnectionFeatures { get; set; } - public ITimeoutControl TimeoutControl { get; set; } + public IPipeReader Input => _frameContext.Input; + public OutputProducer Output { get; } + public ITimeoutControl TimeoutControl => _frameContext.TimeoutControl; protected IKestrelTrace Log => ServiceContext.Log; private DateHeaderValueManager DateHeaderValueManager => ServiceContext.DateHeaderValueManager; diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameContext.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameContext.cs index 28069ce4ae..12d6c22e95 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameContext.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameContext.cs @@ -1,6 +1,8 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http @@ -10,5 +12,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http public string ConnectionId { get; set; } public ServiceContext ServiceContext { get; set; } public IConnectionInformation ConnectionInformation { get; set; } + public ITimeoutControl TimeoutControl { get; set; } + public IPipeReader Input { get; set; } + public IPipe Output { get; set; } } } diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameResponseHeadersTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameResponseHeadersTests.cs index ff60650c98..62c0f8a1de 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameResponseHeadersTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameResponseHeadersTests.cs @@ -6,6 +6,7 @@ using System.Collections.Generic; using System.Globalization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions; using Microsoft.AspNetCore.Testing; using Microsoft.Extensions.Primitives; @@ -22,7 +23,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests var frameContext = new FrameContext { ServiceContext = new TestServiceContext(), - ConnectionInformation = Mock.Of() + ConnectionInformation = Mock.Of(), + TimeoutControl = null }; var frame = new Frame(application: null, frameContext: frameContext); @@ -61,14 +63,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests [InlineData("Ser\u0080ver", "Data")] [InlineData("Server", "Da\u0080ta")] [InlineData("Unknown\u0080-Header", "Data")] - [InlineData("Server", "Data")] - [InlineData("Server", "Data")] - [InlineData("Unknown-Header", "Data")] - [InlineData("Server", "Data")] - [InlineData("erver", "Data")] - [InlineData("Server", "Data")] - [InlineData("Unknown-Header", "Data")] - [InlineData("Server", "Data")] + [InlineData("Ser™ver", "Data")] + [InlineData("Server", "Da™ta")] + [InlineData("Unknown™-Header", "Data")] + [InlineData("Ser™ver", "Data")] + [InlineData("šerver", "Data")] + [InlineData("Server", "Dašta")] + [InlineData("Unknownš-Header", "Data")] + [InlineData("Seršver", "Data")] public void AddingControlOrNonAsciiCharactersToHeadersThrows(string key, string value) { var responseHeaders = new FrameResponseHeaders(); @@ -259,4 +261,4 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests "42.000", }; } -} \ No newline at end of file +} diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameTests.cs index 51ae37a73a..331ac40675 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameTests.cs @@ -36,11 +36,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests private readonly PipeFactory _pipelineFactory; private ReadCursor _consumed; private ReadCursor _examined; + private Mock _timeoutControl; private class TestFrame : Frame { public TestFrame(IHttpApplication application, FrameContext context) - : base(application, context) + : base(application, context) { } @@ -57,21 +58,17 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests var output = _pipelineFactory.Create(); _serviceContext = new TestServiceContext(); - + _timeoutControl = new Mock(); _frameContext = new FrameContext { ServiceContext = _serviceContext, - ConnectionInformation = Mock.Of() - }; - - _frame = new TestFrame(application: null, context: _frameContext) - { + ConnectionInformation = Mock.Of(), + TimeoutControl = _timeoutControl.Object, Input = _input.Reader, - TimeoutControl = Mock.Of() + Output = output }; - _frame.Output = new OutputProducer(output, "", Mock.Of()); - + _frame = new TestFrame(application: null, context: _frameContext); _frame.Reset(); } @@ -343,16 +340,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests [Fact] public async Task ParseRequestStartsRequestHeadersTimeoutOnFirstByteAvailable() { - var connectionControl = new Mock(); - _frame.TimeoutControl = connectionControl.Object; - await _input.Writer.WriteAsync(Encoding.ASCII.GetBytes("G")); _frame.ParseRequest((await _input.Reader.ReadAsync()).Buffer, out _consumed, out _examined); _input.Reader.Advance(_consumed, _examined); var expectedRequestHeadersTimeout = _serviceContext.ServerOptions.Limits.RequestHeadersTimeout.Ticks; - connectionControl.Verify(cc => cc.ResetTimeout(expectedRequestHeadersTimeout, TimeoutAction.SendTimeoutResponse)); + _timeoutControl.Verify(cc => cc.ResetTimeout(expectedRequestHeadersTimeout, TimeoutAction.SendTimeoutResponse)); } [Fact] @@ -466,13 +460,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests [Fact] public void ProcessRequestsAsyncEnablesKeepAliveTimeout() { - var connectionControl = new Mock(); - _frame.TimeoutControl = connectionControl.Object; - var requestProcessingTask = _frame.ProcessRequestsAsync(); var expectedKeepAliveTimeout = _serviceContext.ServerOptions.Limits.KeepAliveTimeout.Ticks; - connectionControl.Verify(cc => cc.SetTimeout(expectedKeepAliveTimeout, TimeoutAction.CloseConnection)); + _timeoutControl.Verify(cc => cc.SetTimeout(expectedKeepAliveTimeout, TimeoutAction.CloseConnection)); _frame.Stop(); _input.Writer.Complete(); diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/OutputProducerTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/OutputProducerTests.cs index 1ec0f7656c..3bdc4fef58 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/OutputProducerTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/OutputProducerTests.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; using Microsoft.AspNetCore.Testing; using Moq; diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/TestInput.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/TestInput.cs index 56b959a738..25a38d495d 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/TestInput.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/TestInput.cs @@ -7,10 +7,12 @@ using System.Text; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions; using Microsoft.AspNetCore.Testing; using Microsoft.Extensions.Internal; +using Moq; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests { @@ -21,15 +23,17 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests public TestInput() { - var innerContext = new FrameContext { ServiceContext = new TestServiceContext() }; - - FrameContext = new Frame(null, innerContext); - FrameContext.FrameControl = this; - _memoryPool = new MemoryPool(); _pipelineFactory = new PipeFactory(); + Pipe = _pipelineFactory.Create(); - FrameContext.Input = Pipe.Reader; + + FrameContext = new Frame(null, new FrameContext + { + ServiceContext = new TestServiceContext(), + Input = Pipe.Reader + }); + FrameContext.FrameControl = this; } public IPipe Pipe { get; } diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameParsingOverheadBenchmark.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameParsingOverheadBenchmark.cs index 7128adae7d..71964abb79 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameParsingOverheadBenchmark.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameParsingOverheadBenchmark.cs @@ -6,6 +6,7 @@ using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; +using Microsoft.AspNetCore.Server.Kestrel.Performance.Mocks; namespace Microsoft.AspNetCore.Server.Kestrel.Performance { @@ -28,7 +29,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance var frameContext = new FrameContext { ServiceContext = serviceContext, - ConnectionInformation = new MockConnectionInformation() + ConnectionInformation = new MockConnectionInformation(), + TimeoutControl = new MockTimeoutControl() }; _frame = new Frame(application: null, frameContext: frameContext); diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameWritingBenchmark.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameWritingBenchmark.cs index 74bbdc19c5..b1ba1658fb 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameWritingBenchmark.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameWritingBenchmark.cs @@ -9,6 +9,7 @@ using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; +using Microsoft.AspNetCore.Server.Kestrel.Performance.Mocks; using Microsoft.AspNetCore.Testing; namespace Microsoft.AspNetCore.Server.Kestrel.Performance @@ -98,18 +99,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance Log = new MockTrace(), HttpParserFactory = f => new HttpParser() }; - var frameContext = new FrameContext + + var frame = new TestFrame(application: null, context: new FrameContext { ServiceContext = serviceContext, - ConnectionInformation = new MockConnectionInformation() - }; - - var frame = new TestFrame(application: null, context: frameContext) - { + ConnectionInformation = new MockConnectionInformation(), Input = input.Reader, - }; - - frame.Output = new OutputProducer(output, "", null); + Output = output + }); frame.Reset(); diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsingBenchmark.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsingBenchmark.cs index 1cff65290f..c6d5e5263c 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsingBenchmark.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsingBenchmark.cs @@ -30,11 +30,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance var frameContext = new FrameContext { ServiceContext = serviceContext, - ConnectionInformation = new MockConnectionInformation() + ConnectionInformation = new MockConnectionInformation(), + TimeoutControl = new MockTimeoutControl() }; Frame = new Frame(application: null, frameContext: frameContext); - Frame.TimeoutControl = new MockTimeoutControl(); PipelineFactory = new PipeFactory(); Pipe = PipelineFactory.Create(); } diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/ResponseHeaderCollectionBenchmark.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/ResponseHeaderCollectionBenchmark.cs index b494e30867..7a65a7d7a6 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/ResponseHeaderCollectionBenchmark.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/ResponseHeaderCollectionBenchmark.cs @@ -32,10 +32,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance } [Params( - BenchmarkTypes.ContentLengthNumeric, - BenchmarkTypes.ContentLengthString, - BenchmarkTypes.Plaintext, - BenchmarkTypes.Common, + BenchmarkTypes.ContentLengthNumeric, + BenchmarkTypes.ContentLengthString, + BenchmarkTypes.Plaintext, + BenchmarkTypes.Common, BenchmarkTypes.Unknown )] public BenchmarkTypes Type { get; set; } diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/ResponseHeadersWritingBenchmark.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/ResponseHeadersWritingBenchmark.cs index 483705f3a2..659b903a8e 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/ResponseHeadersWritingBenchmark.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/ResponseHeadersWritingBenchmark.cs @@ -11,6 +11,7 @@ using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; +using Microsoft.AspNetCore.Server.Kestrel.Performance.Mocks; using Microsoft.AspNetCore.Testing; namespace Microsoft.AspNetCore.Server.Kestrel.Performance @@ -121,17 +122,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance HttpParserFactory = f => new HttpParser() }; - var frameContext = new FrameContext + var frame = new TestFrame(application: null, context: new FrameContext { ServiceContext = serviceContext, - ConnectionInformation = new MockConnectionInformation() - }; - - var frame = new TestFrame(application: null, context: frameContext) - { + ConnectionInformation = new MockConnectionInformation(), + TimeoutControl = new MockTimeoutControl(), Input = input.Reader, - }; - frame.Output = new OutputProducer(output, "", null); + Output = output + }); frame.Reset(); diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/LibuvOutputConsumerTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/LibuvOutputConsumerTests.cs index 16f3361be8..e24e667b7d 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/LibuvOutputConsumerTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/LibuvOutputConsumerTests.cs @@ -693,12 +693,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests }; var transportContext = new TestLibuvTransportContext { Log = new LibuvTrace(logger) }; - var frame = new Frame(null, new FrameContext { ServiceContext = serviceContext }); - var socket = new MockSocket(_mockLibuv, _libuvThread.Loop.ThreadId, transportContext.Log); - var outputProducer = new OutputProducer(pipe, "0", serviceContext.Log); var consumer = new LibuvOutputConsumer(pipe.Reader, _libuvThread, socket, "0", transportContext.Log); - frame.Output = outputProducer; + + var frame = new Frame(null, new FrameContext + { + ServiceContext = serviceContext, + TimeoutControl = Mock.Of(), + Output = pipe + }); if (cts != null) { @@ -707,7 +710,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests var ignore = WriteOutputAsync(consumer, pipe.Reader, frame); - return outputProducer; + return frame.Output; } private async Task WriteOutputAsync(LibuvOutputConsumer consumer, IPipeReader outputReader, Frame frame) @@ -729,4 +732,4 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests } } } -} \ No newline at end of file +} diff --git a/test/shared/TestFrame.cs b/test/shared/TestFrame.cs index 65eb198c8b..74b8bac07c 100644 --- a/test/shared/TestFrame.cs +++ b/test/shared/TestFrame.cs @@ -4,13 +4,14 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Hosting.Server; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; namespace Microsoft.AspNetCore.Testing { public class TestFrame : Frame { public TestFrame(IHttpApplication application, FrameContext context) - : base(application, context) + : base(application, context) { } @@ -31,4 +32,4 @@ namespace Microsoft.AspNetCore.Testing return ProduceEnd(); } } -} \ No newline at end of file +} From e149852d62ce2341076d3be0c2a33ced5562bacd Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Fri, 12 May 2017 14:36:47 -0700 Subject: [PATCH 1287/1662] Skip flaky tests on TeamCity agents (#1832) --- .../KeepAliveTimeoutTests.cs | 7 +++++-- .../LoggingConnectionAdapterTests.cs | 6 +++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/KeepAliveTimeoutTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/KeepAliveTimeoutTests.cs index f2f0e67c75..707dd4f511 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/KeepAliveTimeoutTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/KeepAliveTimeoutTests.cs @@ -9,7 +9,7 @@ using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; using Microsoft.AspNetCore.Testing; -using Xunit; +using Microsoft.AspNetCore.Testing.xunit; namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { @@ -19,7 +19,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests private static readonly TimeSpan LongDelay = TimeSpan.FromSeconds(30); private static readonly TimeSpan ShortDelay = TimeSpan.FromSeconds(LongDelay.TotalSeconds / 10); - [Fact] + // This test is particularly flaky on some teamcity agents, so skip there for now. + // https://github.com/aspnet/KestrelHttpServer/issues/1684 + [ConditionalFact] + [EnvironmentVariableSkipCondition("TEAMCITY_VERSION", null)] public Task TestKeepAliveTimeout() { // Delays in these tests cannot be much longer than expected. diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/LoggingConnectionAdapterTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/LoggingConnectionAdapterTests.cs index 976969d8ac..39c77b3cdd 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/LoggingConnectionAdapterTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/LoggingConnectionAdapterTests.cs @@ -8,13 +8,17 @@ using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Testing; +using Microsoft.AspNetCore.Testing.xunit; using Xunit; namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { public class LoggingConnectionAdapterTests { - [Fact] + // This test is particularly flaky on some teamcity agents, so skip there for now. + // https://github.com/aspnet/KestrelHttpServer/issues/1697 + [ConditionalFact] + [EnvironmentVariableSkipCondition("TEAMCITY_VERSION", null)] public async Task LoggingConnectionAdapterCanBeAddedBeforeAndAfterHttpsAdapter() { var host = new WebHostBuilder() From cb1d0f3956f284e6f34901e32463284cf7fc5bc7 Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Fri, 12 May 2017 16:04:38 -0700 Subject: [PATCH 1288/1662] Prevent infinite loop in PipelineExtensions.PeekAsyncAwaited() (#1827). --- .../Internal/Http/PipelineExtensions.cs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/PipelineExtensions.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/PipelineExtensions.cs index d9b27dfbbf..1fe8107209 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/PipelineExtensions.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/PipelineExtensions.cs @@ -40,7 +40,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http } finally { - pipelineReader.Advance(result.Buffer.Start, result.Buffer.Start); + pipelineReader.Advance(result.Buffer.Start, result.Buffer.IsEmpty + ? result.Buffer.End + : result.Buffer.Start); } input = pipelineReader.ReadAsync(); } @@ -68,7 +70,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http } finally { - pipelineReader.Advance(result.Buffer.Start, result.Buffer.Start); + pipelineReader.Advance(result.Buffer.Start, result.Buffer.IsEmpty + ? result.Buffer.End + : result.Buffer.Start); } readingTask = pipelineReader.ReadAsync(); @@ -325,4 +329,4 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http return bytes; } } -} \ No newline at end of file +} From 1a706113d9f75999d9642ccc05b41593f7c0aa50 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Fri, 12 May 2017 18:26:52 -0700 Subject: [PATCH 1289/1662] Remove rogue ConfigureAwait (#1830) - We don't do it anywhere else, I assume this is left over from older legacy --- .../Internal/Http/FrameOfT.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameOfT.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameOfT.cs index b0890e17ae..c8ea98003f 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameOfT.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameOfT.cs @@ -100,7 +100,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { KestrelEventSource.Log.RequestStart(this); - await _application.ProcessRequestAsync(context).ConfigureAwait(false); + await _application.ProcessRequestAsync(context); if (Volatile.Read(ref _requestAborted) == 0) { From 01b8d5fad1753a1eda61124d1b08447a81a8f0c0 Mon Sep 17 00:00:00 2001 From: Kiran Challa Date: Sat, 13 May 2017 20:41:10 -0700 Subject: [PATCH 1290/1662] Skip flaky temporarily to unblock the mirror --- .../RequestTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs index 5c58b48664..0717a67a2a 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs @@ -315,7 +315,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } } - [Fact] + [Fact(Skip= "https://github.com/aspnet/KestrelHttpServer/issues/1835")] public async Task ConnectionResetBetweenRequestsIsLoggedAsDebug() { var requestDone = new SemaphoreSlim(0); From 41f1922502f475802c6cf3ba2cbe3653ab5d00fd Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Mon, 15 May 2017 11:02:16 -0700 Subject: [PATCH 1291/1662] Simplify LibuvConnection.OnRead() (#1828) * Simplify LibuvConnection.OnRead() - Fix a null reference that sometimes occurs given an EOF status --- .../Internal/LibuvConnection.cs | 104 ++++++++---------- ...ectionTests.cs => LibuvConnectionTests.cs} | 39 ++++++- 2 files changed, 82 insertions(+), 61 deletions(-) rename test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/{ConnectionTests.cs => LibuvConnectionTests.cs} (83%) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvConnection.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvConnection.cs index 3e8ad1e34c..96c147725b 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvConnection.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvConnection.cs @@ -40,11 +40,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal } } - // For testing - public LibuvConnection() - { - } - public string ConnectionId { get; set; } public IPipeWriter Input { get; set; } public LibuvOutputConsumer Output { get; set; } @@ -128,76 +123,72 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal private void OnRead(UvStreamHandle handle, int status) { - var normalRead = status >= 0; - var normalDone = status == LibuvConstants.EOF; - var errorDone = !(normalDone || normalRead); - var readCount = normalRead ? status : 0; - - if (normalRead) + if (status == 0) { - Log.ConnectionRead(ConnectionId, readCount); + // EAGAIN/EWOULDBLOCK so just return the buffer. + // http://docs.libuv.org/en/v1.x/stream.html#c.uv_read_cb + Debug.Assert(_currentWritableBuffer != null); + _currentWritableBuffer.Value.Commit(); + } + else if (status > 0) + { + Log.ConnectionRead(ConnectionId, status); + + Debug.Assert(_currentWritableBuffer != null); + var currentWritableBuffer = _currentWritableBuffer.Value; + currentWritableBuffer.Advance(status); + var flushTask = currentWritableBuffer.FlushAsync(); + + if (!flushTask.IsCompleted) + { + // We wrote too many bytes to the reader, so pause reading and resume when + // we hit the low water mark. + _ = ApplyBackpressureAsync(flushTask); + } } else { + // Given a negative status, it's possible that OnAlloc wasn't called. + _currentWritableBuffer?.Commit(); _socket.ReadStop(); - if (normalDone) + IOException error = null; + + if (status == LibuvConstants.EOF) { Log.ConnectionReadFin(ConnectionId); } - } - - IOException error = null; - WritableBufferAwaitable? flushTask = null; - if (errorDone) - { - handle.Libuv.Check(status, out var uvError); - - // Log connection resets at a lower (Debug) level. - if (status == LibuvConstants.ECONNRESET) - { - Log.ConnectionReset(ConnectionId); - error = new ConnectionResetException(uvError.Message, uvError); - } else { - Log.ConnectionError(ConnectionId, uvError); - error = new IOException(uvError.Message, uvError); + handle.Libuv.Check(status, out var uvError); + + // Log connection resets at a lower (Debug) level. + if (status == LibuvConstants.ECONNRESET) + { + Log.ConnectionReset(ConnectionId); + error = new ConnectionResetException(uvError.Message, uvError); + } + else + { + Log.ConnectionError(ConnectionId, uvError); + error = new IOException(uvError.Message, uvError); + } } - _currentWritableBuffer?.Commit(); - } - else - { - Debug.Assert(_currentWritableBuffer != null); - - var currentWritableBuffer = _currentWritableBuffer.Value; - currentWritableBuffer.Advance(readCount); - flushTask = currentWritableBuffer.FlushAsync(); - } - - _currentWritableBuffer = null; - _bufferHandle.Free(); - - if (!normalRead) - { _connectionContext.Abort(error); - // Complete after aborting the connection Input.Complete(error); } - else if (flushTask?.IsCompleted == false) - { - // We wrote too many bytes too the reader so pause reading and resume when - // we hit the low water mark - _ = ApplyBackpressureAsync(flushTask.Value); - } + + // Cleanup state from last OnAlloc. This is safe even if OnAlloc wasn't called. + _currentWritableBuffer = null; + _bufferHandle.Free(); } private async Task ApplyBackpressureAsync(WritableBufferAwaitable flushTask) { Log.ConnectionPause(ConnectionId); - StopReading(); + _socket.ReadStop(); var result = await flushTask; @@ -209,11 +200,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal } } - private void StopReading() - { - _socket.ReadStop(); - } - private void StartReading() { try @@ -223,7 +209,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal catch (UvException ex) { // ReadStart() can throw a UvException in some cases (e.g. socket is no longer connected). - // This should be treated the same as OnRead() seeing a "normalDone" condition. + // This should be treated the same as OnRead() seeing a negative status. Log.ConnectionReadFin(ConnectionId); var error = new IOException(ex.Message, ex); diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/ConnectionTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/LibuvConnectionTests.cs similarity index 83% rename from test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/ConnectionTests.cs rename to test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/LibuvConnectionTests.cs index 2ce0000554..7034a65711 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/ConnectionTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/LibuvConnectionTests.cs @@ -14,7 +14,7 @@ using Xunit; namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests { - public class ConnectionTests + public class LibuvConnectionTests { [Fact] public async Task DoesNotEndConnectionOnZeroRead() @@ -42,7 +42,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests mockLibuv.ReadCallback(socket.InternalGetHandle(), 0, ref ignored); }, (object)null); - var readAwaitable = await mockConnectionHandler.Input.Reader.ReadAsync(); + var readAwaitable = mockConnectionHandler.Input.Reader.ReadAsync(); Assert.False(readAwaitable.IsCompleted); } finally @@ -175,5 +175,40 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests await thread.StopAsync(TimeSpan.FromSeconds(1)); } } + + [Fact] + public async Task DoesNotThrowIfOnReadCallbackCalledWithEOFButAllocCallbackNotCalled() + { + var mockConnectionHandler = new MockConnectionHandler(); + var mockLibuv = new MockLibuv(); + var transportContext = new TestLibuvTransportContext() { ConnectionHandler = mockConnectionHandler }; + var transport = new LibuvTransport(mockLibuv, transportContext, null); + var thread = new LibuvThread(transport); + + try + { + await thread.StartAsync(); + await thread.PostAsync(_ => + { + var listenerContext = new ListenerContext(transportContext) + { + Thread = thread + }; + var socket = new MockSocket(mockLibuv, Thread.CurrentThread.ManagedThreadId, transportContext.Log); + var connection = new LibuvConnection(listenerContext, socket); + _ = connection.Start(); + + var ignored = new LibuvFunctions.uv_buf_t(); + mockLibuv.ReadCallback(socket.InternalGetHandle(), TestConstants.EOF, ref ignored); + }, (object)null); + + var readAwaitable = await mockConnectionHandler.Input.Reader.ReadAsync(); + Assert.True(readAwaitable.IsCompleted); + } + finally + { + await thread.StopAsync(TimeSpan.FromSeconds(1)); + } + } } } \ No newline at end of file From 9ab09dbe48844554f7f89b13c88c7c460c3e4b91 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Mon, 15 May 2017 11:03:04 -0700 Subject: [PATCH 1292/1662] Change Exception to UvException where possible (#1833) --- .../Internal/LibuvAwaitable.cs | 8 ++++---- .../Internal/Listener.cs | 2 +- .../Internal/ListenerPrimary.cs | 2 +- .../Internal/ListenerSecondary.cs | 7 +++---- .../Internal/Networking/LibuvFunctions.cs | 6 +++--- .../Internal/Networking/UvConnectRequest.cs | 6 +++--- .../Internal/Networking/UvStreamHandle.cs | 7 +++---- .../Internal/Networking/UvTcpHandle.cs | 6 ++---- .../Internal/Networking/UvWriteReq.cs | 12 ++++++------ 9 files changed, 26 insertions(+), 30 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvAwaitable.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvAwaitable.cs index 5c038a4456..7029a1c32e 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvAwaitable.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvAwaitable.cs @@ -15,11 +15,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal private Action _callback; - private Exception _exception; + private UvException _exception; private int _status; - public static readonly Action Callback = (req, status, error, state) => + public static readonly Action Callback = (req, status, error, state) => { var awaitable = (LibuvAwaitable)state; @@ -71,9 +71,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal public struct UvWriteResult { public int Status { get; } - public Exception Error { get; } + public UvException Error { get; } - public UvWriteResult(int status, Exception error) + public UvWriteResult(int status, UvException error) { Status = status; Error = error; diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Listener.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Listener.cs index c1c562c574..e5b0a267fa 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Listener.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Listener.cs @@ -93,7 +93,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal } } - private static void ConnectionCallback(UvStreamHandle stream, int status, Exception error, object state) + private static void ConnectionCallback(UvStreamHandle stream, int status, UvException error, object state) { var listener = (Listener)state; diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/ListenerPrimary.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/ListenerPrimary.cs index 7159d82c2c..d154d31d85 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/ListenerPrimary.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/ListenerPrimary.cs @@ -73,7 +73,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal (pipe, status, error, state) => ((ListenerPrimary)state).OnListenPipe(pipe, status, error), this); } - private void OnListenPipe(UvStreamHandle pipe, int status, Exception error) + private void OnListenPipe(UvStreamHandle pipe, int status, UvException error) { if (status < 0) { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/ListenerSecondary.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/ListenerSecondary.cs index 4b43c9cf79..2571f6bb67 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/ListenerSecondary.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/ListenerSecondary.cs @@ -78,13 +78,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal } } - private static void ConnectCallback(UvConnectRequest connect, int status, Exception error, TaskCompletionSource tcs) + private static void ConnectCallback(UvConnectRequest connect, int status, UvException error, TaskCompletionSource tcs) { var listener = (ListenerSecondary)tcs.Task.AsyncState; listener.ConnectedCallback(connect, status, error, tcs); } - private async void ConnectedCallback(UvConnectRequest connect, int status, Exception error, TaskCompletionSource tcs) + private async void ConnectedCallback(UvConnectRequest connect, int status, UvException error, TaskCompletionSource tcs) { connect.Dispose(); if (error != null) @@ -133,8 +133,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal { if (status != LibuvConstants.EOF) { - Exception ex; - Thread.Loop.Libuv.Check(status, out ex); + Thread.Loop.Libuv.Check(status, out var ex); Log.LogError(0, ex, "DispatchPipe.ReadStart"); } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/LibuvFunctions.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/LibuvFunctions.cs index 84572dae53..06e7030bef 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/LibuvFunctions.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/LibuvFunctions.cs @@ -82,7 +82,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networkin throw GetError(statusCode); } - public void Check(int statusCode, out Exception error) + public void Check(int statusCode, out UvException error) { // Note: method is explicitly small so the success case is easily inlined error = statusCode < 0 ? GetError(statusCode) : null; @@ -345,14 +345,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networkin protected delegate int uv_ip4_addr_func(string ip, int port, out SockAddr addr); protected uv_ip4_addr_func _uv_ip4_addr; - public void ip4_addr(string ip, int port, out SockAddr addr, out Exception error) + public void ip4_addr(string ip, int port, out SockAddr addr, out UvException error) { Check(_uv_ip4_addr(ip, port, out addr), out error); } protected delegate int uv_ip6_addr_func(string ip, int port, out SockAddr addr); protected uv_ip6_addr_func _uv_ip6_addr; - public void ip6_addr(string ip, int port, out SockAddr addr, out Exception error) + public void ip6_addr(string ip, int port, out SockAddr addr, out UvException error) { Check(_uv_ip6_addr(ip, port, out addr), out error); } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvConnectRequest.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvConnectRequest.cs index 0c0371e2bb..75c58b5434 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvConnectRequest.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvConnectRequest.cs @@ -13,7 +13,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networkin { private readonly static LibuvFunctions.uv_connect_cb _uv_connect_cb = (req, status) => UvConnectCb(req, status); - private Action _callback; + private Action _callback; private object _state; public UvConnectRequest(ILibuvTrace logger) : base (logger) @@ -39,7 +39,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networkin public void Connect( UvPipeHandle pipe, string name, - Action callback, + Action callback, object state) { _callback = callback; @@ -58,7 +58,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networkin var state = req._state; req._state = null; - Exception error = null; + UvException error = null; if (status < 0) { req.Libuv.Check(status, out error); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvStreamHandle.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvStreamHandle.cs index 92663696ce..d847512fda 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvStreamHandle.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvStreamHandle.cs @@ -14,7 +14,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networkin private readonly static LibuvFunctions.uv_alloc_cb _uv_alloc_cb = (IntPtr handle, int suggested_size, out LibuvFunctions.uv_buf_t buf) => UvAllocCb(handle, suggested_size, out buf); private readonly static LibuvFunctions.uv_read_cb _uv_read_cb = (IntPtr handle, int status, ref LibuvFunctions.uv_buf_t buf) => UvReadCb(handle, status, ref buf); - private Action _listenCallback; + private Action _listenCallback; private object _listenState; private GCHandle _listenVitality; @@ -40,7 +40,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networkin return base.ReleaseHandle(); } - public void Listen(int backlog, Action callback, object state) + public void Listen(int backlog, Action callback, object state) { if (_listenVitality.IsAllocated) { @@ -123,8 +123,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networkin { var stream = FromIntPtr(handle); - Exception error; - stream.Libuv.Check(status, out error); + stream.Libuv.Check(status, out var error); try { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvTcpHandle.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvTcpHandle.cs index 1e3a1409cd..7bb6e0e908 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvTcpHandle.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvTcpHandle.cs @@ -33,13 +33,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networkin SockAddr addr; var addressText = endPoint.Address.ToString(); - Exception error1; - _uv.ip4_addr(addressText, endPoint.Port, out addr, out error1); + _uv.ip4_addr(addressText, endPoint.Port, out addr, out var error1); if (error1 != null) { - Exception error2; - _uv.ip6_addr(addressText, endPoint.Port, out addr, out error2); + _uv.ip6_addr(addressText, endPoint.Port, out addr, out var error2); if (error2 != null) { throw error1; diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvWriteReq.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvWriteReq.cs index ab14ffdf2b..05b60ca679 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvWriteReq.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvWriteReq.cs @@ -19,7 +19,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networkin private IntPtr _bufs; - private Action _callback; + private Action _callback; private object _state; private const int BUFFER_COUNT = 4; @@ -64,7 +64,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networkin private unsafe void Write( UvStreamHandle handle, ReadableBuffer buffer, - Action callback, + Action callback, object state) { try @@ -136,7 +136,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networkin private void Write( UvStreamHandle handle, ArraySegment> bufs, - Action callback, + Action callback, object state) { WriteArraySegmentInternal(handle, bufs, sendHandle: null, callback: callback, state: state); @@ -146,7 +146,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networkin UvStreamHandle handle, ArraySegment> bufs, UvStreamHandle sendHandle, - Action callback, + Action callback, object state) { WriteArraySegmentInternal(handle, bufs, sendHandle, callback, state); @@ -156,7 +156,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networkin UvStreamHandle handle, ArraySegment> bufs, UvStreamHandle sendHandle, - Action callback, + Action callback, object state) { try @@ -237,7 +237,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networkin var state = req._state; req._state = null; - Exception error = null; + UvException error = null; if (status < 0) { req.Libuv.Check(status, out error); From cf16d601d6f5f8040ba9d090e7b54e1aa1360b16 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Mon, 15 May 2017 19:04:04 -0700 Subject: [PATCH 1293/1662] Remove synchronous Write APIs (#1838) --- .../Internal/Http/Frame.cs | 65 ++----------------- .../Internal/Http/FrameResponseStream.cs | 8 +-- .../Internal/Http/IFrameControl.cs | 2 - .../Internal/Http/OutputProducer.cs | 10 --- .../FrameTests.cs | 34 +++++----- .../TestHelpers/MockFrameControl.cs | 8 --- .../TestInput.cs | 14 +--- .../FrameWritingBenchmark.cs | 13 ---- 8 files changed, 24 insertions(+), 130 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.cs index 96abde3566..5ee289501e 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.cs @@ -503,64 +503,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http } } - public void Flush() - { - InitializeResponse(0).GetAwaiter().GetResult(); - Output.Flush(); - } - - public async Task FlushAsync(CancellationToken cancellationToken) + public async Task FlushAsync(CancellationToken cancellationToken = default(CancellationToken)) { await InitializeResponse(0); await Output.FlushAsync(cancellationToken); } - public void Write(ArraySegment data) - { - // For the first write, ensure headers are flushed if Write(Chunked) isn't called. - var firstWrite = !HasResponseStarted; - - if (firstWrite) - { - InitializeResponse(data.Count).GetAwaiter().GetResult(); - } - else - { - VerifyAndUpdateWrite(data.Count); - } - - if (_canHaveBody) - { - if (_autoChunk) - { - if (data.Count == 0) - { - if (firstWrite) - { - Flush(); - } - return; - } - WriteChunked(data); - } - else - { - CheckLastWrite(); - Output.Write(data); - } - } - else - { - HandleNonBodyResponseWrite(); - - if (firstWrite) - { - Flush(); - } - } - } - - public Task WriteAsync(ArraySegment data, CancellationToken cancellationToken) + public Task WriteAsync(ArraySegment data, CancellationToken cancellationToken = default(CancellationToken)) { if (!HasResponseStarted) { @@ -679,11 +628,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http } } - private void WriteChunked(ArraySegment data) - { - Output.Write(data, chunk: true); - } - private Task WriteChunkedAsync(ArraySegment data, CancellationToken cancellationToken) { return Output.WriteAsync(data, chunk: true, cancellationToken: cancellationToken); @@ -707,12 +651,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http return; } - StringValues expect; if (_httpVersion == Http.HttpVersion.Http11 && - RequestHeaders.TryGetValue("Expect", out expect) && + RequestHeaders.TryGetValue("Expect", out var expect) && (expect.FirstOrDefault() ?? "").Equals("100-continue", StringComparison.OrdinalIgnoreCase)) { - Output.Write(_continueBytes); + Output.WriteAsync(_continueBytes).GetAwaiter().GetResult(); } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameResponseStream.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameResponseStream.cs index 23712d5cb4..062be560c2 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameResponseStream.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameResponseStream.cs @@ -33,9 +33,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http public override void Flush() { - ValidateState(default(CancellationToken)); - - _frameControl.Flush(); + FlushAsync(default(CancellationToken)).GetAwaiter().GetResult(); } public override Task FlushAsync(CancellationToken cancellationToken) @@ -60,9 +58,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http public override void Write(byte[] buffer, int offset, int count) { - ValidateState(default(CancellationToken)); - - _frameControl.Write(new ArraySegment(buffer, offset, count)); + WriteAsync(buffer, offset, count, default(CancellationToken)).GetAwaiter().GetResult(); } public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback callback, object state) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/IFrameControl.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/IFrameControl.cs index 5ad87bc264..eed8069276 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/IFrameControl.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/IFrameControl.cs @@ -10,9 +10,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http public interface IFrameControl { void ProduceContinue(); - void Write(ArraySegment data); Task WriteAsync(ArraySegment data, CancellationToken cancellationToken); - void Flush(); Task FlushAsync(CancellationToken cancellationToken); } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/OutputProducer.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/OutputProducer.cs index 0f72b16648..378ed8bb4e 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/OutputProducer.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/OutputProducer.cs @@ -39,11 +39,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http _flushCompleted = OnFlushCompleted; } - public void Write(ArraySegment buffer, bool chunk = false) - { - WriteAsync(buffer, default(CancellationToken), chunk).GetAwaiter().GetResult(); - } - public Task WriteAsync(ArraySegment buffer, bool chunk = false, CancellationToken cancellationToken = default(CancellationToken)) { if (cancellationToken.IsCancellationRequested) @@ -54,11 +49,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http return WriteAsync(buffer, cancellationToken, chunk); } - public void Flush() - { - WriteAsync(_emptyData, default(CancellationToken)).GetAwaiter().GetResult(); - } - public Task FlushAsync(CancellationToken cancellationToken = default(CancellationToken)) { return WriteAsync(_emptyData, cancellationToken); diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameTests.cs index 331ac40675..1923a56d9d 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameTests.cs @@ -211,10 +211,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests } [Fact] - public void ThrowsWhenStatusCodeIsSetAfterResponseStarted() + public async Task ThrowsWhenStatusCodeIsSetAfterResponseStarted() { // Act - _frame.Write(new ArraySegment(new byte[1])); + await _frame.WriteAsync(new ArraySegment(new byte[1])); // Assert Assert.True(_frame.HasResponseStarted); @@ -222,10 +222,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests } [Fact] - public void ThrowsWhenReasonPhraseIsSetAfterResponseStarted() + public async Task ThrowsWhenReasonPhraseIsSetAfterResponseStarted() { // Act - _frame.Write(new ArraySegment(new byte[1])); + await _frame.WriteAsync(new ArraySegment(new byte[1])); // Assert Assert.True(_frame.HasResponseStarted); @@ -233,9 +233,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests } [Fact] - public void ThrowsWhenOnStartingIsSetAfterResponseStarted() + public async Task ThrowsWhenOnStartingIsSetAfterResponseStarted() { - _frame.Write(new ArraySegment(new byte[1])); + await _frame.WriteAsync(new ArraySegment(new byte[1])); // Act/Assert Assert.True(_frame.HasResponseStarted); @@ -472,13 +472,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests } [Fact] - public void WriteThrowsForNonBodyResponse() + public async Task WriteThrowsForNonBodyResponse() { // Arrange ((IHttpResponseFeature)_frame).StatusCode = StatusCodes.Status304NotModified; // Act/Assert - Assert.Throws(() => _frame.Write(new ArraySegment(new byte[1]))); + await Assert.ThrowsAsync(() => _frame.WriteAsync(new ArraySegment(new byte[1]))); } [Fact] @@ -493,14 +493,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests } [Fact] - public void WriteDoesNotThrowForHeadResponse() + public async Task WriteDoesNotThrowForHeadResponse() { // Arrange _frame.HttpVersion = "HTTP/1.1"; ((IHttpRequestFeature)_frame).Method = "HEAD"; // Act/Assert - _frame.Write(new ArraySegment(new byte[1])); + await _frame.WriteAsync(new ArraySegment(new byte[1])); } [Fact] @@ -515,7 +515,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests } [Fact] - public void ManuallySettingTransferEncodingThrowsForHeadResponse() + public async Task ManuallySettingTransferEncodingThrowsForHeadResponse() { // Arrange _frame.HttpVersion = "HTTP/1.1"; @@ -525,11 +525,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests _frame.ResponseHeaders.Add("Transfer-Encoding", "chunked"); // Assert - Assert.Throws(() => _frame.Flush()); + await Assert.ThrowsAsync(() => _frame.FlushAsync()); } [Fact] - public void ManuallySettingTransferEncodingThrowsForNoBodyResponse() + public async Task ManuallySettingTransferEncodingThrowsForNoBodyResponse() { // Arrange _frame.HttpVersion = "HTTP/1.1"; @@ -539,7 +539,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests _frame.ResponseHeaders.Add("Transfer-Encoding", "chunked"); // Assert - Assert.Throws(() => _frame.Flush()); + await Assert.ThrowsAsync(() => _frame.FlushAsync()); } [Fact] @@ -558,7 +558,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests } [Fact] - public void RequestAbortedTokenIsResetBeforeLastWriteWithContentLength() + public async Task RequestAbortedTokenIsResetBeforeLastWriteWithContentLength() { _frame.ResponseHeaders["Content-Length"] = "12"; @@ -567,11 +567,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests foreach (var ch in "hello, worl") { - _frame.Write(new ArraySegment(new[] { (byte)ch })); + await _frame.WriteAsync(new ArraySegment(new[] { (byte)ch })); Assert.Same(original, _frame.RequestAborted.WaitHandle); } - _frame.Write(new ArraySegment(new[] { (byte)'d' })); + await _frame.WriteAsync(new ArraySegment(new[] { (byte)'d' })); Assert.NotSame(original, _frame.RequestAborted.WaitHandle); } diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/TestHelpers/MockFrameControl.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/TestHelpers/MockFrameControl.cs index cf26ef8f68..f9e2d1bb5e 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/TestHelpers/MockFrameControl.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/TestHelpers/MockFrameControl.cs @@ -11,10 +11,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests.TestHelpers { public class MockFrameControl : IFrameControl { - public void Flush() - { - } - public Task FlushAsync(CancellationToken cancellationToken) { return TaskCache.CompletedTask; @@ -24,10 +20,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests.TestHelpers { } - public void Write(ArraySegment data) - { - } - public Task WriteAsync(ArraySegment data, CancellationToken cancellationToken) { return TaskCache.CompletedTask; diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/TestInput.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/TestInput.cs index 25a38d495d..1a6ce35dd3 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/TestInput.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/TestInput.cs @@ -36,7 +36,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests FrameContext.FrameControl = this; } - public IPipe Pipe { get; } + public IPipe Pipe { get; } public Frame FrameContext { get; set; } @@ -70,23 +70,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests { } - void IFrameControl.ProduceContinue() - { - } - - void IFrameControl.Write(ArraySegment data) - { - } - Task IFrameControl.WriteAsync(ArraySegment data, CancellationToken cancellationToken) { return TaskCache.CompletedTask; } - void IFrameControl.Flush() - { - } - Task IFrameControl.FlushAsync(CancellationToken cancellationToken) { return TaskCache.CompletedTask; diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameWritingBenchmark.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameWritingBenchmark.cs index b1ba1658fb..ff1a3b5298 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameWritingBenchmark.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameWritingBenchmark.cs @@ -9,7 +9,6 @@ using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; -using Microsoft.AspNetCore.Server.Kestrel.Performance.Mocks; using Microsoft.AspNetCore.Testing; namespace Microsoft.AspNetCore.Server.Kestrel.Performance @@ -38,18 +37,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance _frameChunked.RequestHeaders.Add("Transfer-Encoding", "chunked"); } - [Benchmark] - public void Write() - { - _frame.Write(new ArraySegment(_writeData)); - } - - [Benchmark] - public void WriteChunked() - { - _frameChunked.Write(new ArraySegment(_writeData)); - } - [Benchmark] public async Task WriteAsync() { From d22f689fd27035307b15bf01c1fbe4eab6872ec0 Mon Sep 17 00:00:00 2001 From: Pavel Krymets Date: Tue, 16 May 2017 16:54:03 -0700 Subject: [PATCH 1294/1662] Add support to use System.Memory as a package instead of internilized source (#1821) --- build/dependencies.props | 1 + .../Internal/Http/FrameAdapter.cs | 1 + .../Internal/Http/FrameRequestHeaders.cs | 1 + .../Internal/Http/HttpParser.cs | 1 + .../Internal/Http/IHttpHeadersHandler.cs | 1 + .../Internal/Http/IHttpRequestLineHandler.cs | 1 + .../Internal/Http/PathNormalizer.cs | 1 + ...oft.AspNetCore.Server.Kestrel.Transport.Abstractions.csproj | 3 +++ .../HttpParserTests.cs | 1 + .../TestHelpers/AssertExtensions.cs | 1 + .../KestrelHttpParserBenchmark.cs | 1 + .../Mocks/NullParser.cs | 1 + 12 files changed, 14 insertions(+) diff --git a/build/dependencies.props b/build/dependencies.props index 6e343231b3..68a0c2e10a 100644 --- a/build/dependencies.props +++ b/build/dependencies.props @@ -1,6 +1,7 @@ 2.0.0-* + 4.4.0-* 2.1.0-* 1.10.0-* 9.0.1 diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameAdapter.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameAdapter.cs index 6659b83bf8..1418fb8b44 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameAdapter.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameAdapter.cs @@ -1,6 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; using Microsoft.AspNetCore.Server.Kestrel.Internal.System; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameRequestHeaders.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameRequestHeaders.cs index fb543805cb..d1bfc945e3 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameRequestHeaders.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameRequestHeaders.cs @@ -1,6 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; using System.Collections; using System.Collections.Generic; using System.Runtime.CompilerServices; diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/HttpParser.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/HttpParser.cs index a9751e245c..3445dc2098 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/HttpParser.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/HttpParser.cs @@ -1,6 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; using System.Runtime.CompilerServices; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Internal.System; diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/IHttpHeadersHandler.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/IHttpHeadersHandler.cs index a9ad79559a..2cf4789c22 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/IHttpHeadersHandler.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/IHttpHeadersHandler.cs @@ -1,6 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; using Microsoft.AspNetCore.Server.Kestrel.Internal.System; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/IHttpRequestLineHandler.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/IHttpRequestLineHandler.cs index 05088aacc4..4cc1fe7478 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/IHttpRequestLineHandler.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/IHttpRequestLineHandler.cs @@ -1,6 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; using Microsoft.AspNetCore.Server.Kestrel.Internal.System; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/PathNormalizer.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/PathNormalizer.cs index 645dd4629c..7372fcb71a 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/PathNormalizer.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/PathNormalizer.cs @@ -1,6 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; using System.Diagnostics; using Microsoft.AspNetCore.Server.Kestrel.Internal.System; diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.csproj b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.csproj index 45adabecd7..cec4f50a65 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.csproj +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.csproj @@ -10,12 +10,15 @@ CS1570;CS1571;CS1572;CS1573;CS1574;CS1591;$(NoWarn) false true + false $(DefineConstants);KESTREL_BY_SOURCE + $(DefineConstants);SYSTEM_MEMORY + diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/HttpParserTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/HttpParserTests.cs index c98818f506..ee53a68d7f 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/HttpParserTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/HttpParserTests.cs @@ -1,6 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; using System.Collections.Generic; using System.Linq; using System.Text; diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/TestHelpers/AssertExtensions.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/TestHelpers/AssertExtensions.cs index d6ddbee945..1ca99370e5 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/TestHelpers/AssertExtensions.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/TestHelpers/AssertExtensions.cs @@ -1,6 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; using Microsoft.AspNetCore.Server.Kestrel.Internal.System; using Xunit.Sdk; diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/KestrelHttpParserBenchmark.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/KestrelHttpParserBenchmark.cs index 858c973400..30238b3223 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/KestrelHttpParserBenchmark.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/KestrelHttpParserBenchmark.cs @@ -1,6 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; using BenchmarkDotNet.Attributes; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Internal.System; diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Mocks/NullParser.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Mocks/NullParser.cs index 54d71cf795..1484b2af44 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Mocks/NullParser.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Mocks/NullParser.cs @@ -1,6 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; using System.Text; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Internal.System; From 643a43c3d64863eb54c4bf94803af5b5deec0ec8 Mon Sep 17 00:00:00 2001 From: Nate McMaster Date: Wed, 17 May 2017 09:36:40 -0700 Subject: [PATCH 1295/1662] Update test framework versions and fix issues with tests (#1834) --- build/dependencies.props | 4 ++-- .../FrameHeadersTests.cs | 21 ++++--------------- .../FrameRequestHeadersTests.cs | 5 +---- .../FrameResponseHeadersTests.cs | 5 ++--- ...spNetCore.Server.Kestrel.Core.Tests.csproj | 4 ---- .../OutputProducerTests.cs | 3 ++- ...Core.Server.Kestrel.FunctionalTests.csproj | 4 ---- .../ResponseTests.cs | 14 ++++++------- ...oft.AspNetCore.Server.Kestrel.Tests.csproj | 4 ---- ...erver.Kestrel.Transport.Libuv.Tests.csproj | 4 ---- 10 files changed, 18 insertions(+), 50 deletions(-) diff --git a/build/dependencies.props b/build/dependencies.props index 68a0c2e10a..7cace7d06b 100644 --- a/build/dependencies.props +++ b/build/dependencies.props @@ -7,7 +7,7 @@ 9.0.1 4.7.1 $(BundledNETStandardPackageVersion) - 15.0.0 - 2.2.0 + 15.3.0-* + 2.3.0-beta2-* diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameHeadersTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameHeadersTests.cs index 65774c6022..385f4d3ec4 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameHeadersTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameHeadersTests.cs @@ -21,7 +21,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests [InlineData(" ,,", ConnectionOptions.None)] [InlineData(",, ", ConnectionOptions.None)] [InlineData(" , ,", ConnectionOptions.None)] - [InlineData(" , ,", ConnectionOptions.None)] [InlineData(" , , ", ConnectionOptions.None)] [InlineData("keep-alive", ConnectionOptions.KeepAlive)] [InlineData("keep-alive, upgrade", ConnectionOptions.KeepAlive | ConnectionOptions.Upgrade)] @@ -31,8 +30,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests [InlineData("upgrade,,keep-alive", ConnectionOptions.KeepAlive | ConnectionOptions.Upgrade)] [InlineData("keep-alive,", ConnectionOptions.KeepAlive)] [InlineData("keep-alive,,", ConnectionOptions.KeepAlive)] - [InlineData(",keep-alive", ConnectionOptions.KeepAlive)] - [InlineData(",,keep-alive", ConnectionOptions.KeepAlive)] [InlineData("keep-alive, ", ConnectionOptions.KeepAlive)] [InlineData("keep-alive, ,", ConnectionOptions.KeepAlive)] [InlineData("keep-alive, , ", ConnectionOptions.KeepAlive)] @@ -45,8 +42,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests [InlineData(", , keep-alive", ConnectionOptions.KeepAlive)] [InlineData("upgrade,", ConnectionOptions.Upgrade)] [InlineData("upgrade,,", ConnectionOptions.Upgrade)] - [InlineData(",upgrade", ConnectionOptions.Upgrade)] - [InlineData(",,upgrade", ConnectionOptions.Upgrade)] [InlineData("upgrade, ", ConnectionOptions.Upgrade)] [InlineData("upgrade, ,", ConnectionOptions.Upgrade)] [InlineData("upgrade, , ", ConnectionOptions.Upgrade)] @@ -59,8 +54,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests [InlineData(", , upgrade", ConnectionOptions.Upgrade)] [InlineData("close,", ConnectionOptions.Close)] [InlineData("close,,", ConnectionOptions.Close)] - [InlineData(",close", ConnectionOptions.Close)] - [InlineData(",,close", ConnectionOptions.Close)] [InlineData("close, ", ConnectionOptions.Close)] [InlineData("close, ,", ConnectionOptions.Close)] [InlineData("close, , ", ConnectionOptions.Close)] @@ -83,17 +76,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests [InlineData("upgrade,close", ConnectionOptions.Close | ConnectionOptions.Upgrade)] [InlineData("close,upgrade", ConnectionOptions.Close | ConnectionOptions.Upgrade)] [InlineData("keep-alive2", ConnectionOptions.None)] - [InlineData("keep-alive2,", ConnectionOptions.None)] [InlineData("keep-alive2 ", ConnectionOptions.None)] [InlineData("keep-alive2 ,", ConnectionOptions.None)] [InlineData("keep-alive2,", ConnectionOptions.None)] [InlineData("upgrade2", ConnectionOptions.None)] - [InlineData("upgrade2,", ConnectionOptions.None)] [InlineData("upgrade2 ", ConnectionOptions.None)] [InlineData("upgrade2 ,", ConnectionOptions.None)] [InlineData("upgrade2,", ConnectionOptions.None)] [InlineData("close2", ConnectionOptions.None)] - [InlineData("close2,", ConnectionOptions.None)] [InlineData("close2 ", ConnectionOptions.None)] [InlineData("close2 ,", ConnectionOptions.None)] [InlineData("close2,", ConnectionOptions.None)] @@ -171,12 +161,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests [InlineData(" ,,", TransferCoding.None)] [InlineData(",, ", TransferCoding.None)] [InlineData(" , ,", TransferCoding.None)] - [InlineData(" , ,", TransferCoding.None)] [InlineData(" , , ", TransferCoding.None)] [InlineData("chunked,", TransferCoding.Chunked)] [InlineData("chunked,,", TransferCoding.Chunked)] - [InlineData(",chunked", TransferCoding.Chunked)] - [InlineData(",,chunked", TransferCoding.Chunked)] [InlineData("chunked, ", TransferCoding.Chunked)] [InlineData("chunked, ,", TransferCoding.Chunked)] [InlineData("chunked, , ", TransferCoding.Chunked)] @@ -241,7 +228,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests StringValues value; Assert.False(headers.TryGetValue("Content-Length", out value)); - Assert.Equal(null, frameHeaders.ContentLength); + Assert.Null(frameHeaders.ContentLength); Assert.False(frameHeaders.ContentLength.HasValue); frameHeaders.ContentLength = 1; @@ -258,7 +245,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests frameHeaders.ContentLength = null; Assert.False(headers.TryGetValue("Content-Length", out value)); - Assert.Equal(null, frameHeaders.ContentLength); + Assert.Null(frameHeaders.ContentLength); Assert.False(frameHeaders.ContentLength.HasValue); } @@ -276,14 +263,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests StringValues value; Assert.False(headers.TryGetValue("Content-Length", out value)); - Assert.Equal(null, frameHeaders.ContentLength); + Assert.Null(frameHeaders.ContentLength); Assert.False(frameHeaders.ContentLength.HasValue); Assert.Throws(() => frameHeaders.ContentLength = -1); Assert.Throws(() => frameHeaders.ContentLength = long.MinValue); Assert.False(headers.TryGetValue("Content-Length", out value)); - Assert.Equal(null, frameHeaders.ContentLength); + Assert.Null(frameHeaders.ContentLength); Assert.False(frameHeaders.ContentLength.HasValue); } } diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameRequestHeadersTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameRequestHeadersTests.cs index 182ffbadeb..88095e0d86 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameRequestHeadersTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameRequestHeadersTests.cs @@ -30,7 +30,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests headers["custom"] = new[] { "value" }; - Assert.NotNull(headers["custom"]); Assert.Equal(1, headers["custom"].Count); Assert.Equal("value", headers["custom"][0]); } @@ -43,8 +42,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests headers["host"] = new[] { "value" }; headers["content-length"] = new[] { "0" }; - Assert.NotNull(headers["host"]); - Assert.NotNull(headers["content-length"]); Assert.Equal(1, headers["host"].Count); Assert.Equal(1, headers["content-length"].Count); Assert.Equal("value", headers["host"][0]); @@ -307,7 +304,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests public void AppendThrowsWhenHeaderNameContainsNonASCIICharacters() { var headers = new FrameRequestHeaders(); - const string key = "\u00141d\017c"; + const string key = "\u00141\u00F3d\017c"; var encoding = Encoding.GetEncoding("iso-8859-1"); var exception = Assert.Throws( diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameResponseHeadersTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameResponseHeadersTests.cs index 62c0f8a1de..b7cf438e92 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameResponseHeadersTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameResponseHeadersTests.cs @@ -66,7 +66,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests [InlineData("Ser™ver", "Data")] [InlineData("Server", "Da™ta")] [InlineData("Unknown™-Header", "Data")] - [InlineData("Ser™ver", "Data")] [InlineData("šerver", "Data")] [InlineData("Server", "Dašta")] [InlineData("Unknownš-Header", "Data")] @@ -218,7 +217,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests dictionary.Remove("Content-Length"); - Assert.Equal(null, headers.ContentLength); + Assert.Null(headers.ContentLength); } [Fact] @@ -230,7 +229,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests dictionary.Clear(); - Assert.Equal(null, headers.ContentLength); + Assert.Null(headers.ContentLength); } private static long ParseLong(string value) diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/Microsoft.AspNetCore.Server.Kestrel.Core.Tests.csproj b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/Microsoft.AspNetCore.Server.Kestrel.Core.Tests.csproj index 22e86958d9..59ed18e9b2 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/Microsoft.AspNetCore.Server.Kestrel.Core.Tests.csproj +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/Microsoft.AspNetCore.Server.Kestrel.Core.Tests.csproj @@ -26,8 +26,4 @@ - - - - diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/OutputProducerTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/OutputProducerTests.cs index 3bdc4fef58..93c90b10df 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/OutputProducerTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/OutputProducerTests.cs @@ -1,6 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; @@ -10,7 +11,7 @@ using Xunit; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests { - public class OutputProducerTests + public class OutputProducerTests : IDisposable { private readonly PipeFactory _pipeFactory; diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests.csproj b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests.csproj index a3057f5317..6eacb4bd2c 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests.csproj +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests.csproj @@ -36,10 +36,6 @@ - - - - diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs index 28d8a89bd3..6b1d658aa8 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs @@ -1113,8 +1113,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [Theory] [InlineData("gzip")] [InlineData("chunked, gzip")] - [InlineData("gzip")] - [InlineData("chunked, gzip")] public async Task ConnectionClosedWhenChunkedIsNotFinalTransferCoding(string responseTransferEncoding) { using (var server = new TestServer(async httpContext => @@ -1160,8 +1158,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [Theory] [InlineData("gzip")] [InlineData("chunked, gzip")] - [InlineData("gzip")] - [InlineData("chunked, gzip")] public async Task ConnectionClosedWhenChunkedIsNotFinalTransferCodingEvenIfConnectionKeepAliveSetInResponse(string responseTransferEncoding) { using (var server = new TestServer(async httpContext => @@ -2064,6 +2060,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests Assert.Equal(1, testLogger.ApplicationErrorsLogged); } + [Theory] [MemberData(nameof(ConnectionAdapterData))] public async Task FailedWritesResultInAbortedRequest(ListenOptions listenOptions) { @@ -2077,9 +2074,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests var writeTcs = new TaskCompletionSource(); var registrationWh = new ManualResetEventSlim(); var connectionCloseWh = new ManualResetEventSlim(); + var requestStartWh = new ManualResetEventSlim(); using (var server = new TestServer(async httpContext => { + requestStartWh.Set(); var response = httpContext.Response; var request = httpContext.Request; var lifetime = httpContext.Features.Get(); @@ -2087,7 +2086,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests lifetime.RequestAborted.Register(() => registrationWh.Set()); await request.Body.CopyToAsync(Stream.Null); - connectionCloseWh.Wait(); + Assert.True(connectionCloseWh.Wait(10_000)); try { @@ -2115,13 +2114,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests "Content-Length: 5", "", "Hello"); - // Don't wait to receive the response. Just close the socket. + + Assert.True(requestStartWh.Wait(10_000)); } connectionCloseWh.Set(); // Write failed - await Assert.ThrowsAsync(async () => await writeTcs.Task); + await Assert.ThrowsAsync(async () => await writeTcs.Task).TimeoutAfter(TimeSpan.FromSeconds(15)); // RequestAborted tripped Assert.True(registrationWh.Wait(1000)); } diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Tests/Microsoft.AspNetCore.Server.Kestrel.Tests.csproj b/test/Microsoft.AspNetCore.Server.Kestrel.Tests/Microsoft.AspNetCore.Server.Kestrel.Tests.csproj index c5914bfcd9..b694a050ec 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Tests/Microsoft.AspNetCore.Server.Kestrel.Tests.csproj +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Tests/Microsoft.AspNetCore.Server.Kestrel.Tests.csproj @@ -20,8 +20,4 @@ - - - - diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests.csproj b/test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests.csproj index 3a36e44f3d..70611f88a0 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests.csproj +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests.csproj @@ -27,8 +27,4 @@ - - - - From 10f88aeafc2793329a923a36ce8967bf5e93bd63 Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Wed, 17 May 2017 10:57:39 -0700 Subject: [PATCH 1296/1662] Fix duplicate ID test warning. --- .../AddressRegistrationTests.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs index 1ec090f996..38ea0f1933 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs @@ -660,6 +660,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests // Non-loopback addresses var ipv6Addresses = GetIPAddresses() + .Where(ip => !ip.Equals(IPAddress.IPv6Loopback)) .Where(ip => ip.AddressFamily == AddressFamily.InterNetworkV6) .Where(ip => ip.ScopeId == 0) .Where(ip => CanBindAndConnectToEndpoint(new IPEndPoint(ip, 0))); From 7f0319f5dddea8887249315cf78ebd524b86a673 Mon Sep 17 00:00:00 2001 From: Nate McMaster Date: Wed, 17 May 2017 10:47:38 -0700 Subject: [PATCH 1297/1662] Throw InvalidOperationException from IHttpUpgradeFeature.UpgradeAsync when request is not upgradable --- .../CoreStrings.resx | 3 ++ .../Internal/Http/Frame.FeatureCollection.cs | 5 +++ .../Properties/CoreStrings.Designer.cs | 14 ++++++++ .../KeepAliveTimeoutTests.cs | 1 + .../ResponseTests.cs | 3 +- .../UpgradeTests.cs | 36 +++++++++++++++++++ 6 files changed, 61 insertions(+), 1 deletion(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/CoreStrings.resx b/src/Microsoft.AspNetCore.Server.Kestrel.Core/CoreStrings.resx index e85918600f..c024ae82a9 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/CoreStrings.resx +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/CoreStrings.resx @@ -306,4 +306,7 @@ Connection processing ended abnormally. + + Cannot upgrade a non-upgradable request. Check IHttpUpgradeFeature.IsUpgradableRequest to determine if a request can be upgraded. + \ No newline at end of file diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.FeatureCollection.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.FeatureCollection.cs index bd1d8e2a56..429c517899 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.FeatureCollection.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.FeatureCollection.cs @@ -230,6 +230,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http async Task IHttpUpgradeFeature.UpgradeAsync() { + if (!((IHttpUpgradeFeature)this).IsUpgradableRequest) + { + throw new InvalidOperationException(CoreStrings.CannotUpgradeNonUpgradableRequest); + } + StatusCode = StatusCodes.Status101SwitchingProtocols; ReasonPhrase = "Switching Protocols"; ResponseHeaders["Connection"] = "Upgrade"; diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Properties/CoreStrings.Designer.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Properties/CoreStrings.Designer.cs index 1a86007def..2971494a5b 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Properties/CoreStrings.Designer.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Properties/CoreStrings.Designer.cs @@ -892,6 +892,20 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core internal static string FormatRequestProcessingEndError() => GetString("RequestProcessingEndError"); + /// + /// Cannot upgrade a non-upgradable request. Check IHttpUpgradeFeature.IsUpgradableRequest to determine if a request can be upgraded. + /// + internal static string CannotUpgradeNonUpgradableRequest + { + get => GetString("CannotUpgradeNonUpgradableRequest"); + } + + /// + /// Cannot upgrade a non-upgradable request. Check IHttpUpgradeFeature.IsUpgradableRequest to determine if a request can be upgraded. + /// + internal static string FormatCannotUpgradeNonUpgradableRequest() + => GetString("CannotUpgradeNonUpgradableRequest"); + private static string GetString(string name, params string[] formatterNames) { var value = _resourceManager.GetString(name); diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/KeepAliveTimeoutTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/KeepAliveTimeoutTests.cs index 707dd4f511..4e6d0f1304 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/KeepAliveTimeoutTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/KeepAliveTimeoutTests.cs @@ -162,6 +162,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests await connection.Send( "GET /upgrade HTTP/1.1", "Host:", + "Connection: Upgrade", "", ""); await connection.Receive( diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs index 6b1d658aa8..39513f5002 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs @@ -1775,6 +1775,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests await connection.Send( "GET / HTTP/1.1", "Host:", + "Connection: Upgrade", "", ""); await connection.ReceiveForcedEnd( @@ -1789,7 +1790,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { await connection.Send( "GET / HTTP/1.0", - "Connection: keep-alive", + "Connection: keep-alive, Upgrade", "", ""); await connection.ReceiveForcedEnd( diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/UpgradeTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/UpgradeTests.cs index 1249524bc5..3696219f1c 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/UpgradeTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/UpgradeTests.cs @@ -182,5 +182,41 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests ""); } } + + [Fact] + public async Task ThrowsWhenUpgradingNonUpgradableRequest() + { + var upgradeTcs = new TaskCompletionSource(); + using (var server = new TestServer(async context => + { + var feature = context.Features.Get(); + Assert.False(feature.IsUpgradableRequest); + try + { + var stream = await feature.UpgradeAsync(); + } + catch (Exception e) + { + upgradeTcs.TrySetException(e); + } + finally + { + upgradeTcs.TrySetResult(false); + } + })) + { + using (var connection = server.CreateConnection()) + { + await connection.Send("GET / HTTP/1.1", + "Host:", + "", + ""); + await connection.Receive("HTTP/1.1 200 OK"); + } + } + + var ex = await Assert.ThrowsAsync(async () => await upgradeTcs.Task).TimeoutAfter(TimeSpan.FromSeconds(15)); + Assert.Equal(CoreStrings.CannotUpgradeNonUpgradableRequest, ex.Message); + } } } From f8a6433cd5bb6e34823796c8a39e3d19a77a424e Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Wed, 17 May 2017 17:01:34 -0700 Subject: [PATCH 1298/1662] Fix flaky ResponseTests.FailedWritesResultInAbortedRequest. --- .../ResponseTests.cs | 38 ++++++++----------- 1 file changed, 15 insertions(+), 23 deletions(-) diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs index 39513f5002..8fafc71d63 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs @@ -2063,40 +2063,32 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [Theory] [MemberData(nameof(ConnectionAdapterData))] - public async Task FailedWritesResultInAbortedRequest(ListenOptions listenOptions) + public async Task ThrowsOnWriteWithRequestAbortedTokenAfterRequestIsAborted(ListenOptions listenOptions) { - var testContext = new TestServiceContext(); - // This should match _maxBytesPreCompleted in SocketOutput var maxBytesPreCompleted = 65536; + // Ensure string is long enough to disable write-behind buffering var largeString = new string('a', maxBytesPreCompleted + 1); var writeTcs = new TaskCompletionSource(); - var registrationWh = new ManualResetEventSlim(); - var connectionCloseWh = new ManualResetEventSlim(); + var requestAbortedWh = new ManualResetEventSlim(); var requestStartWh = new ManualResetEventSlim(); using (var server = new TestServer(async httpContext => { requestStartWh.Set(); + var response = httpContext.Response; var request = httpContext.Request; var lifetime = httpContext.Features.Get(); - lifetime.RequestAborted.Register(() => registrationWh.Set()); - - await request.Body.CopyToAsync(Stream.Null); - Assert.True(connectionCloseWh.Wait(10_000)); + lifetime.RequestAborted.Register(() => requestAbortedWh.Set()); + Assert.True(requestAbortedWh.Wait(TimeSpan.FromSeconds(10))); try { - // Ensure write is long enough to disable write-behind buffering - for (int i = 0; i < 100; i++) - { - await response.WriteAsync(largeString, lifetime.RequestAborted); - registrationWh.Wait(1000); - } + await response.WriteAsync(largeString, lifetime.RequestAborted); } catch (Exception ex) { @@ -2105,26 +2097,26 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } writeTcs.SetException(new Exception("This shouldn't be reached.")); - }, testContext, listenOptions)) + }, new TestServiceContext(), listenOptions)) { using (var connection = server.CreateConnection()) { await connection.Send( "POST / HTTP/1.1", "Host:", - "Content-Length: 5", + "Content-Length: 0", "", - "Hello"); + ""); - Assert.True(requestStartWh.Wait(10_000)); + Assert.True(requestStartWh.Wait(TimeSpan.FromSeconds(10))); } - connectionCloseWh.Set(); + // Write failed - can throw TaskCanceledException or OperationCanceledException, + // dependending on how far the canceled write goes. + await Assert.ThrowsAnyAsync(async () => await writeTcs.Task).TimeoutAfter(TimeSpan.FromSeconds(15)); - // Write failed - await Assert.ThrowsAsync(async () => await writeTcs.Task).TimeoutAfter(TimeSpan.FromSeconds(15)); // RequestAborted tripped - Assert.True(registrationWh.Wait(1000)); + Assert.True(requestAbortedWh.Wait(TimeSpan.FromSeconds(1))); } } From 34ab089e7bd5f17f4a3ccf6e80f39810fe84fb7e Mon Sep 17 00:00:00 2001 From: Pavel Krymets Date: Thu, 18 May 2017 14:49:48 -0700 Subject: [PATCH 1299/1662] React to scheduler changes (#1846) --- .../Infrastructure/InlineLoggingThreadPool.cs | 11 +++++++++-- .../Internal/Infrastructure/LoggingThreadPool.cs | 6 +++--- .../Internal/LibuvThread.cs | 4 ++-- .../LibuvConnectionTests.cs | 4 ++-- 4 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/InlineLoggingThreadPool.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/InlineLoggingThreadPool.cs index 0160b59590..f762ff976b 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/InlineLoggingThreadPool.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/InlineLoggingThreadPool.cs @@ -33,9 +33,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure action(state); } - public void Schedule(Action action) + public void Schedule(Action action, object state) { - Run(action); + try + { + action(state); + } + catch (Exception e) + { + _log.LogError(0, e, "InlineLoggingThreadPool.Schedule"); + } } } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/LoggingThreadPool.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/LoggingThreadPool.cs index 1718967c50..184d956b18 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/LoggingThreadPool.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/LoggingThreadPool.cs @@ -18,7 +18,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure _log = log; // Curry and capture log in closures once - // The currying is done in functions of the same name to improve the + // The currying is done in functions of the same name to improve the // call stack for exceptions and profiling else it shows up as LoggingThreadPool.ctor>b__4_0 // and you aren't sure which of the 3 functions was called. RunAction(); @@ -50,9 +50,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure ThreadPool.QueueUserWorkItem(action, state); } - public void Schedule(Action action) + public void Schedule(Action action, object state) { - Run(action); + Run(() => action(state)); } } } \ No newline at end of file diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvThread.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvThread.cs index bc3e0139c5..299fffef7c 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvThread.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvThread.cs @@ -383,9 +383,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal return await Task.WhenAny(task, Task.Delay(timeout)).ConfigureAwait(false) == task; } - public void Schedule(Action action) + public void Schedule(Action action, object state) { - Post(state => state(), action); + Post(action, state); } private struct Work diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/LibuvConnectionTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/LibuvConnectionTests.cs index 7034a65711..de27f5774d 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/LibuvConnectionTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/LibuvConnectionTests.cs @@ -114,9 +114,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests var thread = new LibuvThread(transport); var mockScheduler = new Mock(); Action backPressure = null; - mockScheduler.Setup(m => m.Schedule(It.IsAny())).Callback(a => + mockScheduler.Setup(m => m.Schedule(It.IsAny>(), It.IsAny())).Callback, object>((a, o) => { - backPressure = a; + backPressure = () => a(o); }); mockConnectionHandler.InputOptions.WriterScheduler = mockScheduler.Object; mockConnectionHandler.OutputOptions.ReaderScheduler = thread; From 390582dcf16a95015d90bf74fc949499613db2d7 Mon Sep 17 00:00:00 2001 From: Nate McMaster Date: Sat, 20 May 2017 10:37:35 -0700 Subject: [PATCH 1300/1662] Target .NET Standard 2.0 (#1849) --- build/common.props | 4 ++-- build/dependencies.props | 4 ++-- .../LargeResponseApp/LargeResponseApp.csproj | 8 +++++-- samples/SampleApp/SampleApp.csproj | 8 +++++-- ...soft.AspNetCore.Server.Kestrel.Core.csproj | 3 ++- .../HttpsConnectionAdapter.cs | 22 ++++++++++++++++--- ...oft.AspNetCore.Server.Kestrel.Https.csproj | 2 +- ...rver.Kestrel.Transport.Abstractions.csproj | 6 +++-- ...Core.Server.Kestrel.Transport.Libuv.csproj | 2 +- ...re.Server.Kestrel.Transport.Sockets.csproj | 2 +- ...Microsoft.AspNetCore.Server.Kestrel.csproj | 2 +- .../FrameRequestStreamTests.cs | 2 +- ...spNetCore.Server.Kestrel.Core.Tests.csproj | 10 ++++++++- .../GeneratedCodeTests.cs | 7 +++++- ...Core.Server.Kestrel.FunctionalTests.csproj | 13 +++++++---- ...pNetCore.Server.Kestrel.Performance.csproj | 3 ++- ...oft.AspNetCore.Server.Kestrel.Tests.csproj | 3 ++- ...erver.Kestrel.Transport.Libuv.Tests.csproj | 10 ++++++++- test/shared/TestResources.cs | 5 ++--- 19 files changed, 85 insertions(+), 31 deletions(-) diff --git a/build/common.props b/build/common.props index e2f5702c6b..595790c41b 100644 --- a/build/common.props +++ b/build/common.props @@ -16,8 +16,8 @@ - - + + diff --git a/build/dependencies.props b/build/dependencies.props index 7cace7d06b..401361784f 100644 --- a/build/dependencies.props +++ b/build/dependencies.props @@ -1,12 +1,12 @@ 2.0.0-* - 4.4.0-* + 4.4.0-* 2.1.0-* 1.10.0-* 9.0.1 4.7.1 - $(BundledNETStandardPackageVersion) + 2.0.0-* 15.3.0-* 2.3.0-beta2-* diff --git a/samples/LargeResponseApp/LargeResponseApp.csproj b/samples/LargeResponseApp/LargeResponseApp.csproj index be9cd35512..19e6a615fc 100644 --- a/samples/LargeResponseApp/LargeResponseApp.csproj +++ b/samples/LargeResponseApp/LargeResponseApp.csproj @@ -1,9 +1,9 @@  - + - netcoreapp2.0 + netcoreapp2.0;net461 false @@ -11,4 +11,8 @@ + + + + diff --git a/samples/SampleApp/SampleApp.csproj b/samples/SampleApp/SampleApp.csproj index 0387c8a91d..e63d766922 100644 --- a/samples/SampleApp/SampleApp.csproj +++ b/samples/SampleApp/SampleApp.csproj @@ -1,9 +1,9 @@  - + - netcoreapp2.0 + netcoreapp2.0;net461 false @@ -20,4 +20,8 @@ + + + + diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Microsoft.AspNetCore.Server.Kestrel.Core.csproj b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Microsoft.AspNetCore.Server.Kestrel.Core.csproj index f9f23ff830..a5a3ceb117 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Microsoft.AspNetCore.Server.Kestrel.Core.csproj +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Microsoft.AspNetCore.Server.Kestrel.Core.csproj @@ -4,7 +4,7 @@ Core components of ASP.NET Core Kestrel cross-platform web server. - netcoreapp2.0 + netstandard2.0 true aspnetcore;kestrel true @@ -19,6 +19,7 @@ + diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Https/HttpsConnectionAdapter.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Https/HttpsConnectionAdapter.cs index 328f4263aa..5f17cfaf63 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Https/HttpsConnectionAdapter.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Https/HttpsConnectionAdapter.cs @@ -61,7 +61,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Https } else { - sslStream = new SslStream(context.ConnectionStream, leaveInnerStreamOpen: false, + sslStream = new SslStream(context.ConnectionStream, + leaveInnerStreamOpen: false, userCertificateValidationCallback: (sender, certificate, chain, sslPolicyErrors) => { if (certificate == null) @@ -77,7 +78,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Https } } - var certificate2 = (X509Certificate2)certificate; + var certificate2 = ConvertToX509Certificate2(certificate); if (certificate2 == null) { return false; @@ -112,12 +113,27 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Https // Always set the feature even though the cert might be null context.Features.Set(new TlsConnectionFeature { - ClientCertificate = (X509Certificate2)sslStream.RemoteCertificate + ClientCertificate = ConvertToX509Certificate2(sslStream.RemoteCertificate) }); return new HttpsAdaptedConnection(sslStream); } + private static X509Certificate2 ConvertToX509Certificate2(X509Certificate certificate) + { + if (certificate == null) + { + return null; + } + + if (certificate is X509Certificate2 cert2) + { + return cert2; + } + + return new X509Certificate2(certificate); + } + private class HttpsAdaptedConnection : IAdaptedConnection { private readonly SslStream _sslStream; diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Https/Microsoft.AspNetCore.Server.Kestrel.Https.csproj b/src/Microsoft.AspNetCore.Server.Kestrel.Https/Microsoft.AspNetCore.Server.Kestrel.Https.csproj index dc24ad8885..3631a1bd62 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Https/Microsoft.AspNetCore.Server.Kestrel.Https.csproj +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Https/Microsoft.AspNetCore.Server.Kestrel.Https.csproj @@ -4,7 +4,7 @@ HTTPS support for the ASP.NET Core Kestrel cross-platform web server. - netcoreapp2.0 + netstandard2.0 true aspnetcore;kestrel CS1591;$(NoWarn) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.csproj b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.csproj index cec4f50a65..b815a122bc 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.csproj +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.csproj @@ -4,7 +4,7 @@ Transport abstractions for the ASP.NET Core Kestrel cross-platform web server. - netcoreapp2.0 + netstandard2.0 true aspnetcore;kestrel CS1570;CS1571;CS1572;CS1573;CS1574;CS1591;$(NoWarn) @@ -18,7 +18,9 @@ - + + + diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.csproj b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.csproj index 25552ef74c..19c7d923b2 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.csproj +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.csproj @@ -4,7 +4,7 @@ Libuv transport for the ASP.NET Core Kestrel cross-platform web server. - netcoreapp2.0 + netstandard2.0 true aspnetcore;kestrel true diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.csproj b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.csproj index 69ce23ca38..eefdfe2be4 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.csproj +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.csproj @@ -4,7 +4,7 @@ Managed socket transport for the ASP.NET Core Kestrel cross-platform web server. - netcoreapp2.0 + netstandard2.0 true aspnetcore;kestrel true diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Microsoft.AspNetCore.Server.Kestrel.csproj b/src/Microsoft.AspNetCore.Server.Kestrel/Microsoft.AspNetCore.Server.Kestrel.csproj index 24171c9ed6..616830814d 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Microsoft.AspNetCore.Server.Kestrel.csproj +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Microsoft.AspNetCore.Server.Kestrel.csproj @@ -4,7 +4,7 @@ ASP.NET Core Kestrel cross-platform web server. - netcoreapp2.0 + netstandard2.0 true aspnetcore;kestrel CS1591;$(NoWarn) diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameRequestStreamTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameRequestStreamTests.cs index 8adad18cca..2250523f63 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameRequestStreamTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameRequestStreamTests.cs @@ -84,7 +84,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests await Assert.ThrowsAsync(() => stream.WriteAsync(new byte[1], 0, 1)); } -#if NET46 +#if NET461 [Fact] public void BeginWriteThrows() { diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/Microsoft.AspNetCore.Server.Kestrel.Core.Tests.csproj b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/Microsoft.AspNetCore.Server.Kestrel.Core.Tests.csproj index 59ed18e9b2..fb273003e7 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/Microsoft.AspNetCore.Server.Kestrel.Core.Tests.csproj +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/Microsoft.AspNetCore.Server.Kestrel.Core.Tests.csproj @@ -3,8 +3,16 @@ - netcoreapp2.0 + netcoreapp2.0;net461 + netcoreapp2.0 true + + + true + win7-x64 diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/GeneratedCodeTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/GeneratedCodeTests.cs index 637756f2ba..99b8e9d88b 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/GeneratedCodeTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/GeneratedCodeTests.cs @@ -1,6 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +#if NETCOREAPP2_0 using System.IO; using Xunit; @@ -44,4 +45,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } } } -} \ No newline at end of file +} +#elif NET461 +#else +#error Target framework needs to be updated +#endif diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests.csproj b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests.csproj index 6eacb4bd2c..a7766fba47 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests.csproj +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests.csproj @@ -3,14 +3,16 @@ - netcoreapp2.0 + netcoreapp2.0;net461 + netcoreapp2.0 true - exe + true + win7-x64 @@ -19,10 +21,13 @@ + + + + - diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Microsoft.AspNetCore.Server.Kestrel.Performance.csproj b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Microsoft.AspNetCore.Server.Kestrel.Performance.csproj index 42fcca542b..281f7d50dc 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Microsoft.AspNetCore.Server.Kestrel.Performance.csproj +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Microsoft.AspNetCore.Server.Kestrel.Performance.csproj @@ -3,7 +3,8 @@ - netcoreapp2.0 + netcoreapp2.0;net461 + netcoreapp2.0 Exe true true diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Tests/Microsoft.AspNetCore.Server.Kestrel.Tests.csproj b/test/Microsoft.AspNetCore.Server.Kestrel.Tests/Microsoft.AspNetCore.Server.Kestrel.Tests.csproj index b694a050ec..dfe42a4b6c 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Tests/Microsoft.AspNetCore.Server.Kestrel.Tests.csproj +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Tests/Microsoft.AspNetCore.Server.Kestrel.Tests.csproj @@ -3,7 +3,8 @@ - netcoreapp2.0 + netcoreapp2.0;net461 + netcoreapp2.0 diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests.csproj b/test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests.csproj index 70611f88a0..9fd8124c11 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests.csproj +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests.csproj @@ -3,9 +3,17 @@ - netcoreapp2.0 + netcoreapp2.0;net461 + netcoreapp2.0 true true + + + true + win7-x64 diff --git a/test/shared/TestResources.cs b/test/shared/TestResources.cs index 84a6880497..30e495bd2e 100644 --- a/test/shared/TestResources.cs +++ b/test/shared/TestResources.cs @@ -1,15 +1,14 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System; using System.IO; namespace Microsoft.AspNetCore.Testing { public static class TestResources { - private static readonly string _testCertificatePath = Path.Combine(AppContext.BaseDirectory, "testCert.pfx"); + private static readonly string _testCertificatePath = Path.Combine(Directory.GetCurrentDirectory(), "testCert.pfx"); public static string TestCertificatePath => _testCertificatePath; } -} \ No newline at end of file +} From 197eb43d8ac3264384cd895fd197d4f214669b76 Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Mon, 22 May 2017 12:23:02 -0700 Subject: [PATCH 1301/1662] Read request body concurrent to app execution. --- KestrelHttpServer.sln | 1 + .../Internal/Http/Frame.cs | 12 + .../Internal/Http/FrameOfT.cs | 27 +- .../Internal/Http/MessageBody.cs | 602 +++++++----------- .../Internal/Http/PipelineExtensions.cs | 61 -- .../FrameResponseHeadersTests.cs | 6 +- .../FrameTests.cs | 5 +- .../MessageBodyTests.cs | 192 ++++-- .../OutputProducerTests.cs | 10 +- .../StreamsTests.cs | 11 +- .../TestInput.cs | 14 +- .../ChunkedRequestTests.cs | 19 +- .../DefaultHeaderTests.cs | 2 +- .../RequestTests.cs | 147 +++++ .../LibuvOutputConsumerTests.cs | 4 + test/shared/MockConnectionInformation.cs | 22 + 16 files changed, 638 insertions(+), 497 deletions(-) create mode 100644 test/shared/MockConnectionInformation.cs diff --git a/KestrelHttpServer.sln b/KestrelHttpServer.sln index 210365479a..2b528d0f1b 100644 --- a/KestrelHttpServer.sln +++ b/KestrelHttpServer.sln @@ -24,6 +24,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "shared", "shared", "{0EF2AC test\shared\HttpParsingData.cs = test\shared\HttpParsingData.cs test\shared\KestrelTestLoggerFactory.cs = test\shared\KestrelTestLoggerFactory.cs test\shared\LifetimeNotImplemented.cs = test\shared\LifetimeNotImplemented.cs + test\shared\MockConnectionInformation.cs = test\shared\MockConnectionInformation.cs test\shared\MockFrameControl.cs = test\shared\MockFrameControl.cs test\shared\MockLogger.cs = test\shared\MockLogger.cs test\shared\MockSystemClock.cs = test\shared\MockSystemClock.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.cs index 5ee289501e..0387c0ce8e 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.cs @@ -98,8 +98,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http _requestHeadersTimeoutTicks = ServerOptions.Limits.RequestHeadersTimeout.Ticks; Output = new OutputProducer(frameContext.Output, frameContext.ConnectionId, frameContext.ServiceContext.Log); + RequestBodyPipe = CreateRequestBodyPipe(); } + public IPipe RequestBodyPipe { get; } + public ServiceContext ServiceContext => _frameContext.ServiceContext; public IConnectionInformation ConnectionInformation => _frameContext.ConnectionInformation; @@ -1365,6 +1368,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http } } + private IPipe CreateRequestBodyPipe() + => ConnectionInformation.PipeFactory.Create(new PipeOptions + { + ReaderScheduler = ServiceContext.ThreadPool, + WriterScheduler = ConnectionInformation.InputWriterScheduler, + MaximumSizeHigh = ServiceContext.ServerOptions.Limits.MaxRequestBufferSize ?? 0, + MaximumSizeLow = ServiceContext.ServerOptions.Limits.MaxRequestBufferSize ?? 0 + }); + private enum HttpRequestTarget { Unknown = -1, diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameOfT.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameOfT.cs index c8ea98003f..4fdda6d9f1 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameOfT.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameOfT.cs @@ -93,6 +93,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http InitializeStreams(messageBody); + var messageBodyTask = messageBody.StartAsync(); + var context = _application.CreateContext(this); try { @@ -156,12 +158,21 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http await ProduceEnd(); } - if (_keepAlive) + if (!_keepAlive) { - // Finish reading the request body in case the app did not. - await messageBody.Consume(); + messageBody.Cancel(); } + // An upgraded request has no defined request body length. + // Cancel any pending read so the read loop ends. + if (_upgrade) + { + Input.CancelPendingRead(); + } + + // Finish reading the request body in case the app did not. + await messageBody.ConsumeAsync(); + if (!HasResponseStarted) { await ProduceEnd(); @@ -189,6 +200,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http // to ensure InitializeStreams has been called. StopStreams(); } + + // At this point both the request body pipe reader and writer should be completed. + await messageBodyTask; + + // ForZeroContentLength does not complete the reader nor the writer + if (_keepAlive && !messageBody.IsEmpty) + { + RequestBodyPipe.Reset(); + } } if (!_keepAlive) @@ -225,6 +245,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http try { Input.Complete(); + // If _requestAborted is set, the connection has already been closed. if (Volatile.Read(ref _requestAborted) == 0) { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/MessageBody.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/MessageBody.cs index ca26fe9095..6ab87c8096 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/MessageBody.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/MessageBody.cs @@ -18,6 +18,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http private readonly Frame _context; private bool _send100Continue = true; + private volatile bool _canceled; protected MessageBody(Frame context) { @@ -30,179 +31,178 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http public bool RequestUpgrade { get; protected set; } - public Task ReadAsync(ArraySegment buffer, CancellationToken cancellationToken = default(CancellationToken)) + public virtual bool IsEmpty => false; + + public virtual async Task StartAsync() { - var task = PeekAsync(cancellationToken); + Exception error = null; - if (!task.IsCompleted) - { - TryProduceContinue(); - - // Incomplete Task await result - return ReadAsyncAwaited(task, buffer); - } - else - { - var readSegment = task.Result; - var consumed = CopyReadSegment(readSegment, buffer); - - return consumed == 0 ? TaskCache.DefaultCompletedTask : Task.FromResult(consumed); - } - } - - private async Task ReadAsyncAwaited(ValueTask> currentTask, ArraySegment buffer) - { - return CopyReadSegment(await currentTask, buffer); - } - - private int CopyReadSegment(ArraySegment readSegment, ArraySegment buffer) - { - var consumed = Math.Min(readSegment.Count, buffer.Count); - - if (consumed != 0) - { - Buffer.BlockCopy(readSegment.Array, readSegment.Offset, buffer.Array, buffer.Offset, consumed); - ConsumedBytes(consumed); - } - - return consumed; - } - - public Task CopyToAsync(Stream destination, CancellationToken cancellationToken = default(CancellationToken)) - { - var peekTask = PeekAsync(cancellationToken); - - while (peekTask.IsCompleted) - { - // ValueTask uses .GetAwaiter().GetResult() if necessary - var segment = peekTask.Result; - - if (segment.Count == 0) - { - return TaskCache.CompletedTask; - } - - Task destinationTask; - try - { - destinationTask = destination.WriteAsync(segment.Array, segment.Offset, segment.Count, cancellationToken); - } - catch - { - ConsumedBytes(segment.Count); - throw; - } - - if (!destinationTask.IsCompleted) - { - return CopyToAsyncDestinationAwaited(destinationTask, segment.Count, destination, cancellationToken); - } - - ConsumedBytes(segment.Count); - - // Surface errors if necessary - destinationTask.GetAwaiter().GetResult(); - - peekTask = PeekAsync(cancellationToken); - } - - TryProduceContinue(); - - return CopyToAsyncPeekAwaited(peekTask, destination, cancellationToken); - } - - private async Task CopyToAsyncPeekAwaited( - ValueTask> peekTask, - Stream destination, - CancellationToken cancellationToken = default(CancellationToken)) - { - while (true) - { - var segment = await peekTask; - - if (segment.Count == 0) - { - return; - } - - try - { - await destination.WriteAsync(segment.Array, segment.Offset, segment.Count, cancellationToken); - } - finally - { - ConsumedBytes(segment.Count); - } - - peekTask = PeekAsync(cancellationToken); - } - } - - private async Task CopyToAsyncDestinationAwaited( - Task destinationTask, - int bytesConsumed, - Stream destination, - CancellationToken cancellationToken = default(CancellationToken)) - { try { - await destinationTask; + while (true) + { + var awaitable = _context.Input.ReadAsync(); + + if (!awaitable.IsCompleted) + { + TryProduceContinue(); + } + + var result = await awaitable; + var readableBuffer = result.Buffer; + var consumed = readableBuffer.Start; + var examined = readableBuffer.End; + + try + { + if (_canceled) + { + break; + } + + if (!readableBuffer.IsEmpty) + { + var writableBuffer = _context.RequestBodyPipe.Writer.Alloc(1); + bool done; + + try + { + done = Read(readableBuffer, writableBuffer, out consumed, out examined); + } + finally + { + writableBuffer.Commit(); + } + + await writableBuffer.FlushAsync(); + + if (done) + { + break; + } + } + else if (result.IsCompleted) + { + _context.RejectRequest(RequestRejectionReason.UnexpectedEndOfRequestContent); + } + } + finally + { + _context.Input.Advance(consumed, examined); + } + } + } + catch (Exception ex) + { + error = ex; } finally { - ConsumedBytes(bytesConsumed); + _context.RequestBodyPipe.Writer.Complete(error); } - - var peekTask = PeekAsync(cancellationToken); - - if (!peekTask.IsCompleted) - { - TryProduceContinue(); - } - - await CopyToAsyncPeekAwaited(peekTask, destination, cancellationToken); } - public Task Consume(CancellationToken cancellationToken = default(CancellationToken)) + public void Cancel() + { + _canceled = true; + } + + public virtual async Task ReadAsync(ArraySegment buffer, CancellationToken cancellationToken = default(CancellationToken)) { while (true) { - var task = PeekAsync(cancellationToken); - if (!task.IsCompleted) - { - TryProduceContinue(); + var result = await _context.RequestBodyPipe.Reader.ReadAsync(); + var readableBuffer = result.Buffer; + var consumed = readableBuffer.End; - // Incomplete Task await result - return ConsumeAwaited(task, cancellationToken); - } - else + try { - // ValueTask uses .GetAwaiter().GetResult() if necessary - if (task.Result.Count == 0) + if (!readableBuffer.IsEmpty) { - // Completed Task, end of stream - return TaskCache.CompletedTask; + var actual = Math.Min(readableBuffer.Length, buffer.Count); + var slice = readableBuffer.Slice(0, actual); + consumed = readableBuffer.Move(readableBuffer.Start, actual); + slice.CopyTo(buffer); + return actual; } - - ConsumedBytes(task.Result.Count); + else if (result.IsCompleted) + { + return 0; + } + } + finally + { + _context.RequestBodyPipe.Reader.Advance(consumed); } } } - private async Task ConsumeAwaited(ValueTask> currentTask, CancellationToken cancellationToken) + public virtual async Task CopyToAsync(Stream destination, CancellationToken cancellationToken = default(CancellationToken)) { while (true) { - var count = (await currentTask).Count; + var result = await _context.RequestBodyPipe.Reader.ReadAsync(); + var readableBuffer = result.Buffer; + var consumed = readableBuffer.End; - if (count == 0) + try { - // Completed Task, end of stream - return; + if (!readableBuffer.IsEmpty) + { + foreach (var memory in readableBuffer) + { + var array = memory.GetArray(); + await destination.WriteAsync(array.Array, array.Offset, array.Count, cancellationToken); + } + } + else if (result.IsCompleted) + { + return; + } } + finally + { + _context.RequestBodyPipe.Reader.Advance(consumed); + } + } + } - ConsumedBytes(count); - currentTask = PeekAsync(cancellationToken); + public virtual async Task ConsumeAsync(CancellationToken cancellationToken = default(CancellationToken)) + { + Exception error = null; + + try + { + ReadResult result; + do + { + result = await _context.RequestBodyPipe.Reader.ReadAsync(); + _context.RequestBodyPipe.Reader.Advance(result.Buffer.End); + } while (!result.IsCompleted); + } + catch (Exception ex) + { + error = ex; + throw; + } + finally + { + _context.RequestBodyPipe.Reader.Complete(error); + } + } + + protected void Copy(ReadableBuffer readableBuffer, WritableBuffer writableBuffer) + { + if (readableBuffer.IsSingleSpan) + { + writableBuffer.Write(readableBuffer.First.Span); + } + else + { + foreach (var memory in readableBuffer) + { + writableBuffer.Write(memory.Span); + } } } @@ -215,20 +215,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http } } - private void ConsumedBytes(int count) - { - var scan = _context.Input.ReadAsync().GetResult().Buffer; - var consumed = scan.Move(scan.Start, count); - _context.Input.Advance(consumed, consumed); - - OnConsumedBytes(count); - } - - protected abstract ValueTask> PeekAsync(CancellationToken cancellationToken); - - protected virtual void OnConsumedBytes(int count) - { - } + protected abstract bool Read(ReadableBuffer readableBuffer, WritableBuffer writableBuffer, out ReadCursor consumed, out ReadCursor examined); public static MessageBody For( HttpVersion httpVersion, @@ -316,9 +303,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http RequestUpgrade = true; } - protected override ValueTask> PeekAsync(CancellationToken cancellationToken) + protected override bool Read(ReadableBuffer readableBuffer, WritableBuffer writableBuffer, out ReadCursor consumed, out ReadCursor examined) { - return _context.Input.PeekAsync(); + Copy(readableBuffer, writableBuffer); + consumed = readableBuffer.End; + examined = readableBuffer.End; + return false; } } @@ -330,17 +320,31 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http RequestKeepAlive = keepAlive; } - protected override ValueTask> PeekAsync(CancellationToken cancellationToken) + public override bool IsEmpty => true; + + public override Task StartAsync() { - return new ValueTask>(); + return Task.CompletedTask; } - protected override void OnConsumedBytes(int count) + public override Task ReadAsync(ArraySegment buffer, CancellationToken cancellationToken = default(CancellationToken)) { - if (count > 0) - { - throw new InvalidDataException("Consuming non-existent data"); - } + return Task.FromResult(0); + } + + public override Task CopyToAsync(Stream destination, CancellationToken cancellationToken = default(CancellationToken)) + { + return Task.CompletedTask; + } + + public override Task ConsumeAsync(CancellationToken cancellationToken = default(CancellationToken)) + { + return Task.CompletedTask; + } + + protected override bool Read(ReadableBuffer readableBuffer, WritableBuffer writableBuffer, out ReadCursor consumed, out ReadCursor examined) + { + throw new NotImplementedException(); } } @@ -357,65 +361,22 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http _inputLength = _contentLength; } - protected override ValueTask> PeekAsync(CancellationToken cancellationToken) + protected override bool Read(ReadableBuffer readableBuffer, WritableBuffer writableBuffer, out ReadCursor consumed, out ReadCursor examined) { - var limit = (int)Math.Min(_inputLength, int.MaxValue); - if (limit == 0) + if (_inputLength == 0) { - return new ValueTask>(); + throw new InvalidOperationException("Attempted to read from completed Content-Length request body."); } - var task = _context.Input.PeekAsync(); + var actual = (int)Math.Min(readableBuffer.Length, _inputLength); + _inputLength -= actual; - if (task.IsCompleted) - { - // .GetAwaiter().GetResult() done by ValueTask if needed - var actual = Math.Min(task.Result.Count, limit); + consumed = readableBuffer.Move(readableBuffer.Start, actual); + examined = consumed; - if (task.Result.Count == 0) - { - _context.RejectRequest(RequestRejectionReason.UnexpectedEndOfRequestContent); - } + Copy(readableBuffer.Slice(0, actual), writableBuffer); - if (task.Result.Count < _inputLength) - { - return task; - } - else - { - var result = task.Result; - var part = new ArraySegment(result.Array, result.Offset, (int)_inputLength); - return new ValueTask>(part); - } - } - else - { - return new ValueTask>(PeekAsyncAwaited(task)); - } - } - - private async Task> PeekAsyncAwaited(ValueTask> task) - { - var segment = await task; - - if (segment.Count == 0) - { - _context.RejectRequest(RequestRejectionReason.UnexpectedEndOfRequestContent); - } - - if (segment.Count <= _inputLength) - { - return segment; - } - else - { - return new ArraySegment(segment.Array, segment.Offset, (int)_inputLength); - } - } - - protected override void OnConsumedBytes(int count) - { - _inputLength -= count; + return _inputLength == 0; } } @@ -441,188 +402,84 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http _requestHeaders = headers; } - protected override ValueTask> PeekAsync(CancellationToken cancellationToken) + protected override bool Read(ReadableBuffer readableBuffer, WritableBuffer writableBuffer, out ReadCursor consumed, out ReadCursor examined) { - return new ValueTask>(PeekStateMachineAsync()); - } + consumed = default(ReadCursor); + examined = default(ReadCursor); - protected override void OnConsumedBytes(int count) - { - _inputLength -= count; - } - - private async Task> PeekStateMachineAsync() - { while (_mode < Mode.Trailer) { - while (_mode == Mode.Prefix) + if (_mode == Mode.Prefix) { - var result = await _input.ReadAsync(); - var buffer = result.Buffer; - var consumed = default(ReadCursor); - var examined = default(ReadCursor); + ParseChunkedPrefix(readableBuffer, out consumed, out examined); - try + if (_mode == Mode.Prefix) { - ParseChunkedPrefix(buffer, out consumed, out examined); - } - finally - { - _input.Advance(consumed, examined); - } - - if (_mode != Mode.Prefix) - { - break; - } - else if (result.IsCompleted) - { - _context.RejectRequest(RequestRejectionReason.ChunkedRequestIncomplete); + return false; } + readableBuffer = readableBuffer.Slice(consumed); } - while (_mode == Mode.Extension) + if (_mode == Mode.Extension) { - var result = await _input.ReadAsync(); - var buffer = result.Buffer; - var consumed = default(ReadCursor); - var examined = default(ReadCursor); + ParseExtension(readableBuffer, out consumed, out examined); - try + if (_mode == Mode.Extension) { - ParseExtension(buffer, out consumed, out examined); - } - finally - { - _input.Advance(consumed, examined); - } - - if (_mode != Mode.Extension) - { - break; - } - else if (result.IsCompleted) - { - _context.RejectRequest(RequestRejectionReason.ChunkedRequestIncomplete); + return false; } + readableBuffer = readableBuffer.Slice(consumed); } - while (_mode == Mode.Data) + if (_mode == Mode.Data) { - var result = await _input.ReadAsync(); - var buffer = result.Buffer; - ArraySegment segment; - try + ReadChunkedData(readableBuffer, writableBuffer, out consumed, out examined); + + if (_mode == Mode.Data) { - segment = PeekChunkedData(buffer); - } - finally - { - _input.Advance(buffer.Start, buffer.Start); + return false; } - if (segment.Count != 0) - { - return segment; - } - else if (_mode != Mode.Data) - { - break; - } - else if (result.IsCompleted) - { - _context.RejectRequest(RequestRejectionReason.ChunkedRequestIncomplete); - } + readableBuffer = readableBuffer.Slice(consumed); } - while (_mode == Mode.Suffix) + if (_mode == Mode.Suffix) { - var result = await _input.ReadAsync(); - var buffer = result.Buffer; - var consumed = default(ReadCursor); - var examined = default(ReadCursor); + ParseChunkedSuffix(readableBuffer, out consumed, out examined); - try + if (_mode == Mode.Suffix) { - ParseChunkedSuffix(buffer, out consumed, out examined); - } - finally - { - _input.Advance(consumed, examined); + return false; } - if (_mode != Mode.Suffix) - { - break; - } - else if (result.IsCompleted) - { - _context.RejectRequest(RequestRejectionReason.ChunkedRequestIncomplete); - } + readableBuffer = readableBuffer.Slice(consumed); } } // Chunks finished, parse trailers - while (_mode == Mode.Trailer) + if (_mode == Mode.Trailer) { - var result = await _input.ReadAsync(); - var buffer = result.Buffer; - var consumed = default(ReadCursor); - var examined = default(ReadCursor); + ParseChunkedTrailer(readableBuffer, out consumed, out examined); - try + if (_mode == Mode.Trailer) { - ParseChunkedTrailer(buffer, out consumed, out examined); - } - finally - { - _input.Advance(consumed, examined); - } - - if (_mode != Mode.Trailer) - { - break; - } - else if (result.IsCompleted) - { - _context.RejectRequest(RequestRejectionReason.ChunkedRequestIncomplete); + return false; } + readableBuffer = readableBuffer.Slice(consumed); } if (_mode == Mode.TrailerHeaders) { - while (true) + if (_context.TakeMessageHeaders(readableBuffer, out consumed, out examined)) { - var result = await _input.ReadAsync(); - var buffer = result.Buffer; - - if (buffer.IsEmpty && result.IsCompleted) - { - _context.RejectRequest(RequestRejectionReason.ChunkedRequestIncomplete); - } - - var consumed = default(ReadCursor); - var examined = default(ReadCursor); - - try - { - if (_context.TakeMessageHeaders(buffer, out consumed, out examined)) - { - break; - } - } - finally - { - _input.Advance(consumed, examined); - } + _mode = Mode.Complete; } - _mode = Mode.Complete; } - return default(ArraySegment); + return _mode == Mode.Complete; } private void ParseChunkedPrefix(ReadableBuffer buffer, out ReadCursor consumed, out ReadCursor examined) @@ -728,24 +585,19 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http } while (_mode == Mode.Extension); } - private ArraySegment PeekChunkedData(ReadableBuffer buffer) + private void ReadChunkedData(ReadableBuffer buffer, WritableBuffer writableBuffer, out ReadCursor consumed, out ReadCursor examined) { + var actual = Math.Min(buffer.Length, _inputLength); + consumed = buffer.Move(buffer.Start, actual); + examined = consumed; + + Copy(buffer.Slice(0, actual), writableBuffer); + + _inputLength -= actual; + if (_inputLength == 0) { _mode = Mode.Suffix; - return default(ArraySegment); - } - var segment = buffer.First.GetArray(); - - int actual = Math.Min(segment.Count, _inputLength); - // Nothing is consumed yet. ConsumedBytes(int) will move the iterator. - if (actual == segment.Count) - { - return segment; - } - else - { - return new ArraySegment(segment.Array, segment.Offset, actual); } } @@ -760,12 +612,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http return; } - var sufixBuffer = buffer.Slice(0, 2); - var sufixSpan = sufixBuffer.ToSpan(); - if (sufixSpan[0] == '\r' && sufixSpan[1] == '\n') + var suffixBuffer = buffer.Slice(0, 2); + var suffixSpan = suffixBuffer.ToSpan(); + if (suffixSpan[0] == '\r' && suffixSpan[1] == '\n') { - consumed = sufixBuffer.End; - examined = sufixBuffer.End; + consumed = suffixBuffer.End; + examined = suffixBuffer.End; _mode = Mode.Prefix; } else diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/PipelineExtensions.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/PipelineExtensions.cs index 1fe8107209..cdc6579650 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/PipelineExtensions.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/PipelineExtensions.cs @@ -18,67 +18,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http [ThreadStatic] private static byte[] _numericBytesScratch; - public static ValueTask> PeekAsync(this IPipeReader pipelineReader) - { - var input = pipelineReader.ReadAsync(); - while (input.IsCompleted) - { - var result = input.GetResult(); - try - { - if (!result.Buffer.IsEmpty) - { - var segment = result.Buffer.First; - var data = segment.GetArray(); - - return new ValueTask>(data); - } - else if (result.IsCompleted) - { - return default(ValueTask>); - } - } - finally - { - pipelineReader.Advance(result.Buffer.Start, result.Buffer.IsEmpty - ? result.Buffer.End - : result.Buffer.Start); - } - input = pipelineReader.ReadAsync(); - } - - return new ValueTask>(pipelineReader.PeekAsyncAwaited(input)); - } - - private static async Task> PeekAsyncAwaited(this IPipeReader pipelineReader, ReadableBufferAwaitable readingTask) - { - while (true) - { - var result = await readingTask; - - try - { - if (!result.Buffer.IsEmpty) - { - var segment = result.Buffer.First; - return segment.GetArray(); - } - else if (result.IsCompleted) - { - return default(ArraySegment); - } - } - finally - { - pipelineReader.Advance(result.Buffer.Start, result.Buffer.IsEmpty - ? result.Buffer.End - : result.Buffer.Start); - } - - readingTask = pipelineReader.ReadAsync(); - } - } - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Span ToSpan(this ReadableBuffer buffer) { diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameResponseHeadersTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameResponseHeadersTests.cs index b7cf438e92..fabae69f65 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameResponseHeadersTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameResponseHeadersTests.cs @@ -7,6 +7,7 @@ using System.Globalization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions; using Microsoft.AspNetCore.Testing; using Microsoft.Extensions.Primitives; @@ -23,7 +24,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests var frameContext = new FrameContext { ServiceContext = new TestServiceContext(), - ConnectionInformation = Mock.Of(), + ConnectionInformation = new MockConnectionInformation + { + PipeFactory = new PipeFactory() + }, TimeoutControl = null }; diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameTests.cs index 1923a56d9d..ca5eb53008 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameTests.cs @@ -62,7 +62,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests _frameContext = new FrameContext { ServiceContext = _serviceContext, - ConnectionInformation = Mock.Of(), + ConnectionInformation = new MockConnectionInformation + { + PipeFactory = _pipelineFactory + }, TimeoutControl = _timeoutControl.Object, Input = _input.Reader, Output = output diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/MessageBodyTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/MessageBodyTests.cs index 6b69166ab6..bf61a5df51 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/MessageBodyTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/MessageBodyTests.cs @@ -9,10 +9,14 @@ using System.Text; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; +using Microsoft.AspNetCore.Testing; using Microsoft.Extensions.Internal; +using Microsoft.Extensions.Logging; using Moq; using Xunit; +using Xunit.Abstractions; using Xunit.Sdk; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests @@ -22,7 +26,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests [Theory] [InlineData(HttpVersion.Http10)] [InlineData(HttpVersion.Http11)] - public void CanReadFromContentLength(HttpVersion httpVersion) + public async Task CanReadFromContentLength(HttpVersion httpVersion) { using (var input = new TestInput()) { @@ -30,6 +34,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests var stream = new FrameRequestStream(); stream.StartAcceptingReads(body); + var bodyTask = body.StartAsync(); + input.Add("Hello"); var buffer = new byte[1024]; @@ -40,6 +46,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests count = stream.Read(buffer, 0, buffer.Length); Assert.Equal(0, count); + + await bodyTask; } } @@ -54,6 +62,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests var stream = new FrameRequestStream(); stream.StartAcceptingReads(body); + var bodyTask = body.StartAsync(); + input.Add("Hello"); var buffer = new byte[1024]; @@ -64,11 +74,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests count = await stream.ReadAsync(buffer, 0, buffer.Length); Assert.Equal(0, count); + + await bodyTask; } } [Fact] - public void CanReadFromChunkedEncoding() + public async Task CanReadFromChunkedEncoding() { using (var input = new TestInput()) { @@ -76,6 +88,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests var stream = new FrameRequestStream(); stream.StartAcceptingReads(body); + var bodyTask = body.StartAsync(); + input.Add("5\r\nHello\r\n"); var buffer = new byte[1024]; @@ -88,6 +102,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests count = stream.Read(buffer, 0, buffer.Length); Assert.Equal(0, count); + + await bodyTask; } } @@ -100,6 +116,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests var stream = new FrameRequestStream(); stream.StartAcceptingReads(body); + var bodyTask = body.StartAsync(); + input.Add("5\r\nHello\r\n"); var buffer = new byte[1024]; @@ -112,13 +130,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests count = await stream.ReadAsync(buffer, 0, buffer.Length); Assert.Equal(0, count); + + await bodyTask; } } [Theory] [InlineData(HttpVersion.Http10)] [InlineData(HttpVersion.Http11)] - public void CanReadFromRemainingData(HttpVersion httpVersion) + public async Task CanReadFromRemainingData(HttpVersion httpVersion) { using (var input = new TestInput()) { @@ -126,6 +146,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests var stream = new FrameRequestStream(); stream.StartAcceptingReads(body); + var bodyTask = body.StartAsync(); + input.Add("Hello"); var buffer = new byte[1024]; @@ -133,6 +155,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests var count = stream.Read(buffer, 0, buffer.Length); Assert.Equal(5, count); AssertASCII("Hello", new ArraySegment(buffer, 0, count)); + + input.Fin(); + + await bodyTask; } } @@ -147,6 +173,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests var stream = new FrameRequestStream(); stream.StartAcceptingReads(body); + var bodyTask = body.StartAsync(); + input.Add("Hello"); var buffer = new byte[1024]; @@ -154,13 +182,17 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests var count = await stream.ReadAsync(buffer, 0, buffer.Length); Assert.Equal(5, count); AssertASCII("Hello", new ArraySegment(buffer, 0, count)); + + input.Fin(); + + await bodyTask; } } [Theory] [InlineData(HttpVersion.Http10)] [InlineData(HttpVersion.Http11)] - public void ReadFromNoContentLengthReturnsZero(HttpVersion httpVersion) + public async Task ReadFromNoContentLengthReturnsZero(HttpVersion httpVersion) { using (var input = new TestInput()) { @@ -168,10 +200,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests var stream = new FrameRequestStream(); stream.StartAcceptingReads(body); + var bodyTask = body.StartAsync(); + input.Add("Hello"); var buffer = new byte[1024]; Assert.Equal(0, stream.Read(buffer, 0, buffer.Length)); + + await bodyTask; } } @@ -186,10 +222,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests var stream = new FrameRequestStream(); stream.StartAcceptingReads(body); + var bodyTask = body.StartAsync(); + input.Add("Hello"); var buffer = new byte[1024]; Assert.Equal(0, await stream.ReadAsync(buffer, 0, buffer.Length)); + + await bodyTask; } } @@ -202,6 +242,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests var stream = new FrameRequestStream(); stream.StartAcceptingReads(body); + var bodyTask = body.StartAsync(); + // Input needs to be greater than 4032 bytes to allocate a block not backed by a slab. var largeInput = new string('a', 8192); @@ -217,8 +259,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests Assert.Equal(8197, requestArray.Length); AssertASCII(largeInput + "Hello", new ArraySegment(requestArray, 0, requestArray.Length)); - var count = await stream.ReadAsync(new byte[1], 0, 1); - Assert.Equal(0, count); + await bodyTask; } } @@ -267,6 +308,45 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests } } + [Fact] + public async Task CopyToAsyncDoesNotCompletePipeReader() + { + using (var input = new TestInput()) + { + var body = MessageBody.For(HttpVersion.Http10, new FrameRequestHeaders { HeaderContentLength = "5" }, input.FrameContext); + var bodyTask = body.StartAsync(); + + input.Add("Hello"); + + using (var ms = new MemoryStream()) + { + await body.CopyToAsync(ms); + } + + Assert.Equal(0, await body.ReadAsync(new ArraySegment(new byte[1]))); + + await bodyTask; + } + } + + [Fact] + public async Task ConsumeAsyncCompletesPipeReader() + { + using (var input = new TestInput()) + { + var body = MessageBody.For(HttpVersion.Http10, new FrameRequestHeaders { HeaderContentLength = "5" }, input.FrameContext); + var bodyTask = body.StartAsync(); + + input.Add("Hello"); + + await body.ConsumeAsync(); + + await Assert.ThrowsAsync(async () => await body.ReadAsync(new ArraySegment(new byte[1]))); + + await bodyTask; + } + } + public static IEnumerable StreamData => new[] { new object[] { new ThrowOnWriteSynchronousStream() }, @@ -306,14 +386,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests using (var input = new TestInput()) { var body = MessageBody.For(HttpVersion.Http11, headers, input.FrameContext); + var bodyTask = body.StartAsync(); var copyToAsyncTask = body.CopyToAsync(mockDestination.Object); // The block returned by IncomingStart always has at least 2048 available bytes, // so no need to bounds check in this test. - var socketInput = input.Pipe; var bytes = Encoding.ASCII.GetBytes(data[0]); - var buffer = socketInput.Writer.Alloc(2048); + var buffer = input.Pipe.Writer.Alloc(2048); ArraySegment block; Assert.True(buffer.Buffer.TryGetArray(out block)); Buffer.BlockCopy(bytes, 0, block.Array, block.Offset, bytes.Length); @@ -325,7 +405,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests writeTcs = new TaskCompletionSource(); bytes = Encoding.ASCII.GetBytes(data[1]); - buffer = socketInput.Writer.Alloc(2048); + buffer = input.Pipe.Writer.Alloc(2048); Assert.True(buffer.Buffer.TryGetArray(out block)); Buffer.BlockCopy(bytes, 0, block.Array, block.Offset, bytes.Length); buffer.Advance(bytes.Length); @@ -335,37 +415,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests if (headers.HeaderConnection == "close") { - socketInput.Writer.Complete(); + input.Pipe.Writer.Complete(); } await copyToAsyncTask; Assert.Equal(2, writeCount); - } - } - [Theory] - [MemberData(nameof(CombinedData))] - public async Task CopyToAsyncAdvancesRequestStreamWhenDestinationWriteAsyncThrows(Stream writeStream, FrameRequestHeaders headers, string[] data) - { - using (var input = new TestInput()) - { - var body = MessageBody.For(HttpVersion.Http11, headers, input.FrameContext); - - input.Add(data[0]); - - await Assert.ThrowsAsync(() => body.CopyToAsync(writeStream)); - - input.Add(data[1]); - - // "Hello " should have been consumed - var readBuffer = new byte[6]; - var count = await body.ReadAsync(new ArraySegment(readBuffer, 0, readBuffer.Length)); - Assert.Equal(6, count); - AssertASCII("World!", new ArraySegment(readBuffer, 0, 6)); - - count = await body.ReadAsync(new ArraySegment(readBuffer, 0, readBuffer.Length)); - Assert.Equal(0, count); + await bodyTask; } } @@ -374,7 +431,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests [InlineData("Keep-Alive, Upgrade")] [InlineData("upgrade, keep-alive")] [InlineData("Upgrade, Keep-Alive")] - public void ConnectionUpgradeKeepAlive(string headerConnection) + public async Task ConnectionUpgradeKeepAlive(string headerConnection) { using (var input = new TestInput()) { @@ -382,11 +439,74 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests var stream = new FrameRequestStream(); stream.StartAcceptingReads(body); + var bodyTask = body.StartAsync(); + input.Add("Hello"); var buffer = new byte[1024]; Assert.Equal(5, stream.Read(buffer, 0, buffer.Length)); AssertASCII("Hello", new ArraySegment(buffer, 0, 5)); + + input.Fin(); + + await bodyTask; + } + } + + [Fact] + public async Task StartAsyncDoesNotReturnAfterCancelingInput() + { + using (var input = new TestInput()) + { + var body = MessageBody.For(HttpVersion.Http11, new FrameRequestHeaders { HeaderContentLength = "2" }, input.FrameContext); + var stream = new FrameRequestStream(); + stream.StartAcceptingReads(body); + + var bodyTask = body.StartAsync(); + + // Add some input and consume it to ensure StartAsync is in the loop + input.Add("a"); + Assert.Equal(1, await stream.ReadAsync(new byte[1], 0, 1)); + + input.Pipe.Reader.CancelPendingRead(); + + // Add more input and verify is read + input.Add("b"); + Assert.Equal(1, await stream.ReadAsync(new byte[1], 0, 1)); + + // All input was read, body task should complete + await bodyTask; + } + } + + [Fact] + public async Task StartAsyncReturnsAfterCanceling() + { + using (var input = new TestInput()) + { + var body = MessageBody.For(HttpVersion.Http11, new FrameRequestHeaders { HeaderContentLength = "2" }, input.FrameContext); + var stream = new FrameRequestStream(); + stream.StartAcceptingReads(body); + + var bodyTask = body.StartAsync(); + + // Add some input and consume it to ensure StartAsync is in the loop + input.Add("a"); + Assert.Equal(1, await stream.ReadAsync(new byte[1], 0, 1)); + + body.Cancel(); + + // Add some more data. Checking for cancelation and exiting the loop + // should take priority over reading this data. + input.Add("b"); + + // Unblock the loop + input.Pipe.Reader.CancelPendingRead(); + + await bodyTask.TimeoutAfter(TimeSpan.FromSeconds(10)); + + // There shouldn't be any additional data available + Assert.Equal(0, await stream.ReadAsync(new byte[1], 0, 1)); } } @@ -480,4 +600,4 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests public override long Position { get; set; } } } -} \ No newline at end of file +} diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/OutputProducerTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/OutputProducerTests.cs index 93c90b10df..0298bbff95 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/OutputProducerTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/OutputProducerTests.cs @@ -54,7 +54,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests { var pipe = _pipeFactory.Create(pipeOptions); var serviceContext = new TestServiceContext(); - var frame = new Frame(null, new FrameContext { ServiceContext = serviceContext }); + var frameContext = new FrameContext + { + ServiceContext = serviceContext, + ConnectionInformation = new MockConnectionInformation + { + PipeFactory = _pipeFactory + } + }; + var frame = new Frame(null, frameContext); var socketOutput = new OutputProducer(pipe, "0", serviceContext.Log); return socketOutput; diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/StreamsTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/StreamsTests.cs index d9f8854a14..95eae94658 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/StreamsTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/StreamsTests.cs @@ -6,6 +6,7 @@ using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; using Moq; using Xunit; @@ -41,7 +42,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests Assert.Equal(CoreStrings.ResponseStreamWasUpgraded, writeEx.Message); Assert.Same(ex, - await Assert.ThrowsAsync(() => request.ReadAsync(new byte[1], 0, 1))); + await Assert.ThrowsAsync(() => request.ReadAsync(new byte[1], 0, 1))); Assert.Same(ex, await Assert.ThrowsAsync(() => upgrade.ReadAsync(new byte[1], 0, 1))); @@ -64,7 +65,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests Assert.Equal(CoreStrings.ResponseStreamWasUpgraded, writeEx.Message); Assert.Same(ex, - await Assert.ThrowsAsync(() => request.ReadAsync(new byte[1], 0, 1))); + await Assert.ThrowsAsync(() => request.ReadAsync(new byte[1], 0, 1))); Assert.Same(ex, await Assert.ThrowsAsync(() => upgrade.ReadAsync(new byte[1], 0, 1))); @@ -80,9 +81,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests RequestUpgrade = upgradeable; } - protected override ValueTask> PeekAsync(CancellationToken cancellationToken) + protected override bool Read(ReadableBuffer readableBuffer, WritableBuffer writableBuffer, out ReadCursor consumed, out ReadCursor examined) { - return new ValueTask>(new ArraySegment(new byte[1])); + consumed = default(ReadCursor); + examined = default(ReadCursor); + return true; } } } diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/TestInput.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/TestInput.cs index 1a6ce35dd3..df90641045 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/TestInput.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/TestInput.cs @@ -25,19 +25,24 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests { _memoryPool = new MemoryPool(); _pipelineFactory = new PipeFactory(); - Pipe = _pipelineFactory.Create(); FrameContext = new Frame(null, new FrameContext { ServiceContext = new TestServiceContext(), - Input = Pipe.Reader + Input = Pipe.Reader, + ConnectionInformation = new MockConnectionInformation + { + PipeFactory = _pipelineFactory + } }); FrameContext.FrameControl = this; } public IPipe Pipe { get; } + public PipeFactory PipeFactory => _pipelineFactory; + public Frame FrameContext { get; set; } public void Add(string text) @@ -46,6 +51,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests Pipe.Writer.WriteAsync(data).Wait(); } + public void Fin() + { + Pipe.Writer.Complete(); + } + public void ProduceContinue() { } diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ChunkedRequestTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ChunkedRequestTests.cs index c6e8adbdb2..ce0f9bf2df 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ChunkedRequestTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ChunkedRequestTests.cs @@ -72,9 +72,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests "5", "Hello", "6", " World", "0", - "", - ""); - await connection.ReceiveEnd( + "", + ""); + await connection.ReceiveForcedEnd( "HTTP/1.1 200 OK", "Connection: close", $"Date: {testContext.DateHeaderValue}", @@ -103,7 +103,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests "5", "Hello", "6", " World", "0", - "", + "", "POST / HTTP/1.0", "Content-Length: 7", "", @@ -115,7 +115,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests "Content-Length: 11", "", "Hello World"); - await connection.ReceiveEnd( + await connection.ReceiveForcedEnd( "HTTP/1.1 200 OK", "Connection: close", $"Date: {testContext.DateHeaderValue}", @@ -185,7 +185,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [MemberData(nameof(ConnectionAdapterData))] public async Task TrailingHeadersAreParsed(ListenOptions listenOptions) { - var testContext = new TestServiceContext(); var requestCount = 10; var requestsReceived = 0; @@ -196,8 +195,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests var buffer = new byte[200]; - Assert.True(string.IsNullOrEmpty(request.Headers["X-Trailer-Header"])); - while (await request.Body.ReadAsync(buffer, 0, buffer.Length) != 0) { ;// read to end @@ -217,11 +214,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests response.Headers["Content-Length"] = new[] { "11" }; await response.Body.WriteAsync(Encoding.ASCII.GetBytes("Hello World"), 0, 11); - }, testContext, listenOptions)) + }, new TestServiceContext(), listenOptions)) { var response = string.Join("\r\n", new string[] { "HTTP/1.1 200 OK", - $"Date: {testContext.DateHeaderValue}", + $"Date: {server.Context.DateHeaderValue}", "Content-Length: 11", "", "Hello World"}); @@ -372,8 +369,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests var buffer = new byte[200]; - Assert.True(string.IsNullOrEmpty(request.Headers["X-Trailer-Header"])); - while (await request.Body.ReadAsync(buffer, 0, buffer.Length) != 0) { ;// read to end diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/DefaultHeaderTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/DefaultHeaderTests.cs index c9c1a94ae6..167019d218 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/DefaultHeaderTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/DefaultHeaderTests.cs @@ -30,7 +30,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests "", ""); - await connection.ReceiveEnd( + await connection.ReceiveForcedEnd( "HTTP/1.1 200 OK", $"Date: {testContext.DateHeaderValue}", "Server: Kestrel", diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs index 0717a67a2a..0fb5db7212 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs @@ -1270,6 +1270,153 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } } + [Fact] + public async Task ServerConsumesKeepAliveContentLengthRequest() + { + // The app doesn't read the request body, so it should be consumed by the server + using (var server = new TestServer(context => Task.CompletedTask)) + { + using (var connection = server.CreateConnection()) + { + await connection.Send( + "POST / HTTP/1.1", + "Host:", + "Content-Length: 5", + "", + "hello"); + + await connection.Receive( + "HTTP/1.1 200 OK", + $"Date: {server.Context.DateHeaderValue}", + "Content-Length: 0", + "", + ""); + + // If the server consumed the previous request properly, the + // next request should be successful + await connection.Send( + "POST / HTTP/1.1", + "Host:", + "Content-Length: 5", + "", + "world"); + + await connection.Receive( + "HTTP/1.1 200 OK", + $"Date: {server.Context.DateHeaderValue}", + "Content-Length: 0", + "", + ""); + } + } + } + + [Fact] + public async Task ServerConsumesKeepAliveChunkedRequest() + { + // The app doesn't read the request body, so it should be consumed by the server + using (var server = new TestServer(context => Task.CompletedTask)) + { + using (var connection = server.CreateConnection()) + { + await connection.Send( + "POST / HTTP/1.1", + "Host:", + "Transfer-Encoding: chunked", + "", + "5", + "hello", + "5", + "world", + "0", + "Trailer: value", + "", + ""); + + await connection.Receive( + "HTTP/1.1 200 OK", + $"Date: {server.Context.DateHeaderValue}", + "Content-Length: 0", + "", + ""); + + // If the server consumed the previous request properly, the + // next request should be successful + await connection.Send( + "POST / HTTP/1.1", + "Host:", + "Content-Length: 5", + "", + "world"); + + await connection.Receive( + "HTTP/1.1 200 OK", + $"Date: {server.Context.DateHeaderValue}", + "Content-Length: 0", + "", + ""); + } + } + } + + [Fact] + public async Task NonKeepAliveRequestNotConsumedByAppCompletes() + { + // The app doesn't read the request body, so it should be consumed by the server + using (var server = new TestServer(context => Task.CompletedTask)) + { + using (var connection = server.CreateConnection()) + { + await connection.SendAll( + "POST / HTTP/1.0", + "Host:", + "Content-Length: 5", + "", + "hello"); + + await connection.ReceiveForcedEnd( + "HTTP/1.1 200 OK", + "Connection: close", + $"Date: {server.Context.DateHeaderValue}", + "Content-Length: 0", + "", + ""); + } + } + } + + [Fact] + public async Task UpgradedRequestNotConsumedByAppCompletes() + { + // The app doesn't read the request body, so it should be consumed by the server + using (var server = new TestServer(async context => + { + var upgradeFeature = context.Features.Get(); + var duplexStream = await upgradeFeature.UpgradeAsync(); + + var response = Encoding.ASCII.GetBytes("goodbye"); + await duplexStream.WriteAsync(response, 0, response.Length); + })) + { + using (var connection = server.CreateConnection()) + { + await connection.SendAll( + "GET / HTTP/1.1", + "Host:", + "Connection: upgrade", + "", + "hello"); + + await connection.ReceiveForcedEnd( + "HTTP/1.1 101 Switching Protocols", + "Connection: Upgrade", + $"Date: {server.Context.DateHeaderValue}", + "", + "goodbye"); + } + } + } + private async Task TestRemoteIPAddress(string registerAddress, string requestAddress, string expectAddress) { var builder = new WebHostBuilder() diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/LibuvOutputConsumerTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/LibuvOutputConsumerTests.cs index e24e667b7d..2d565d7168 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/LibuvOutputConsumerTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/LibuvOutputConsumerTests.cs @@ -699,6 +699,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests var frame = new Frame(null, new FrameContext { ServiceContext = serviceContext, + ConnectionInformation = new MockConnectionInformation + { + PipeFactory = _pipeFactory + }, TimeoutControl = Mock.Of(), Output = pipe }); diff --git a/test/shared/MockConnectionInformation.cs b/test/shared/MockConnectionInformation.cs new file mode 100644 index 0000000000..1a68548100 --- /dev/null +++ b/test/shared/MockConnectionInformation.cs @@ -0,0 +1,22 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System.Net; +using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions; + +namespace Microsoft.AspNetCore.Testing +{ + public class MockConnectionInformation : IConnectionInformation + { + public IPEndPoint RemoteEndPoint { get; } + + public IPEndPoint LocalEndPoint { get; } + + public PipeFactory PipeFactory { get; set; } + + public IScheduler InputWriterScheduler { get; } + + public IScheduler OutputReaderScheduler { get; } + } +} From 6c0af445e536b3752ea4e34462aebf82f85efa6d Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Wed, 24 May 2017 15:45:54 -0700 Subject: [PATCH 1302/1662] Fix flaky test and improve TestServer (#1859) --- .../FrameConnectionManagerTests.cs | 47 ++--- .../RequestTests.cs | 184 +++++++++--------- .../ResponseTests.cs | 4 +- .../TestServer.cs | 20 +- test/shared/KestrelTestLoggerFactory.cs | 5 + test/shared/TestApplicationErrorLogger.cs | 6 - test/shared/TestConnection.cs | 33 +++- test/shared/TestServiceContext.cs | 16 +- 8 files changed, 152 insertions(+), 163 deletions(-) diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/FrameConnectionManagerTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/FrameConnectionManagerTests.cs index 15093ec9c0..ab292378b0 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/FrameConnectionManagerTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/FrameConnectionManagerTests.cs @@ -5,11 +5,9 @@ using System; using System.Diagnostics; using System.Threading; using System.Threading.Tasks; -using Microsoft.AspNetCore.Builder; -using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; using Microsoft.AspNetCore.Testing; using Microsoft.AspNetCore.Testing.xunit; -using Microsoft.Extensions.Logging; using Moq; using Xunit; @@ -17,7 +15,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { public class FrameConnectionManagerTests { - private const int _applicationNeverCompletedId = 23; [ConditionalFact] [NoDebuggerCondition] @@ -31,45 +28,23 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests var logWh = new SemaphoreSlim(0); var appStartedWh = new SemaphoreSlim(0); - var mockLogger = new Mock(); - mockLogger - .Setup(logger => logger.IsEnabled(It.IsAny())) - .Returns(true); - mockLogger - .Setup(logger => logger.Log(LogLevel.Critical, _applicationNeverCompletedId, It.IsAny(), null, - It.IsAny>())) + var mockTrace = new Mock(); + mockTrace + .Setup(trace => trace.ApplicationNeverCompleted(It.IsAny())) .Callback(() => { logWh.Release(); }); - var mockLoggerFactory = new Mock(); - mockLoggerFactory - .Setup(factory => factory.CreateLogger("Microsoft.AspNetCore.Server.Kestrel")) - .Returns(mockLogger.Object); - mockLoggerFactory - .Setup(factory => factory.CreateLogger(It.IsNotIn("Microsoft.AspNetCore.Server.Kestrel"))) - .Returns(Mock.Of()); - - var builder = new WebHostBuilder() - .UseLoggerFactory(mockLoggerFactory.Object) - .UseKestrel() - .UseUrls("http://127.0.0.1:0") - .Configure(app => + using (var server = new TestServer(context => { - app.Run(context => - { - appStartedWh.Release(); - var tcs = new TaskCompletionSource(); - return tcs.Task; - }); - }); - - using (var host = builder.Build()) + appStartedWh.Release(); + var tcs = new TaskCompletionSource(); + return tcs.Task; + }, + new TestServiceContext(new KestrelTestLoggerFactory(), mockTrace.Object))) { - host.Start(); - - using (var connection = new TestConnection(host.GetPort())) + using (var connection = server.CreateConnection()) { await connection.Send("GET / HTTP/1.1", "Host:", diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs index 0fb5db7212..b8f65c99b9 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs @@ -19,7 +19,6 @@ using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions; -using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking; using Microsoft.AspNetCore.Testing; using Microsoft.AspNetCore.Testing.xunit; using Microsoft.Extensions.Internal; @@ -34,7 +33,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests public class RequestTests { private const int _connectionStartedEventId = 1; - private const int _connectionKeepAliveEventId = 9; private const int _connectionResetEventId = 19; private const int _semaphoreWaitTimeout = 2500; @@ -257,54 +255,48 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { var connectionStarted = new SemaphoreSlim(0); var connectionReset = new SemaphoreSlim(0); + var loggedHigherThanDebug = false; var mockLogger = new Mock(); mockLogger .Setup(logger => logger.IsEnabled(It.IsAny())) .Returns(true); mockLogger - .Setup(logger => logger.Log(LogLevel.Debug, _connectionStartedEventId, It.IsAny(), null, It.IsAny>())) - .Callback(() => + .Setup(logger => logger.Log(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny>())) + .Callback>((logLevel, eventId, state, exception, formatter) => { - connectionStarted.Release(); - }); - mockLogger - .Setup(logger => logger.Log(LogLevel.Debug, _connectionResetEventId, It.IsAny(), null, It.IsAny>())) - .Callback(() => - { - connectionReset.Release(); + if (eventId.Id == _connectionStartedEventId) + { + connectionStarted.Release(); + } + else if (eventId.Id == _connectionResetEventId) + { + connectionReset.Release(); + } + + if (logLevel > LogLevel.Debug) + { + loggedHigherThanDebug = true; + } }); var mockLoggerFactory = new Mock(); mockLoggerFactory - .Setup(factory => factory.CreateLogger("Microsoft.AspNetCore.Server.Kestrel")) - .Returns(mockLogger.Object); - mockLoggerFactory - .Setup(factory => factory.CreateLogger("Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv")) - .Returns(mockLogger.Object); - mockLoggerFactory - .Setup(factory => factory.CreateLogger(It.IsNotIn("Microsoft.AspNetCore.Server.Kestrel", "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv"))) + .Setup(factory => factory.CreateLogger(It.IsAny())) .Returns(Mock.Of()); + mockLoggerFactory + .Setup(factory => factory.CreateLogger(It.IsIn("Microsoft.AspNetCore.Server.Kestrel", "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv"))) + .Returns(mockLogger.Object); - var builder = new WebHostBuilder() - .UseLoggerFactory(mockLoggerFactory.Object) - .UseKestrel() - .UseUrls("http://127.0.0.1:0") - .Configure(app => app.Run(context => TaskCache.CompletedTask)); - - using (var host = builder.Build()) + using (var server = new TestServer(context => TaskCache.CompletedTask, new TestServiceContext(mockLoggerFactory.Object))) { - host.Start(); - - using (var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)) + using (var connection = server.CreateConnection()) { - socket.Connect(new IPEndPoint(IPAddress.Loopback, host.GetPort())); - // Wait until connection is established Assert.True(await connectionStarted.WaitAsync(TimeSpan.FromSeconds(10))); // Force a reset - socket.LingerState = new LingerOption(true, 0); + connection.Socket.LingerState = new LingerOption(true, 0); } // If the reset is correctly logged as Debug, the wait below should complete shortly. @@ -313,63 +305,64 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests // and therefore not logged. Assert.True(await connectionReset.WaitAsync(TimeSpan.FromSeconds(10))); } + + Assert.False(loggedHigherThanDebug); } - [Fact(Skip= "https://github.com/aspnet/KestrelHttpServer/issues/1835")] + [Fact] public async Task ConnectionResetBetweenRequestsIsLoggedAsDebug() { - var requestDone = new SemaphoreSlim(0); var connectionReset = new SemaphoreSlim(0); + var loggedHigherThanDebug = false; var mockLogger = new Mock(); mockLogger .Setup(logger => logger.IsEnabled(It.IsAny())) .Returns(true); mockLogger - .Setup(logger => logger.Log(LogLevel.Debug, _connectionKeepAliveEventId, It.IsAny(), null, It.IsAny>())) - .Callback(() => + .Setup(logger => logger.Log(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny>())) + .Callback>((logLevel, eventId, state, exception, formatter) => { - requestDone.Release(); - }); - mockLogger - .Setup(logger => logger.Log(LogLevel.Debug, _connectionResetEventId, It.IsAny(), null, It.IsAny>())) - .Callback(() => - { - connectionReset.Release(); + if (eventId.Id == _connectionResetEventId) + { + connectionReset.Release(); + } + + if (logLevel > LogLevel.Debug) + { + loggedHigherThanDebug = true; + } }); var mockLoggerFactory = new Mock(); mockLoggerFactory - .Setup(factory => factory.CreateLogger("Microsoft.AspNetCore.Server.Kestrel")) - .Returns(mockLogger.Object); - mockLoggerFactory - .Setup(factory => factory.CreateLogger("Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv")) - .Returns(mockLogger.Object); - mockLoggerFactory - .Setup(factory => factory.CreateLogger(It.IsNotIn("Microsoft.AspNetCore.Server.Kestrel", "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv"))) + .Setup(factory => factory.CreateLogger(It.IsAny())) .Returns(Mock.Of()); + mockLoggerFactory + .Setup(factory => factory.CreateLogger(It.IsIn("Microsoft.AspNetCore.Server.Kestrel", "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv"))) + .Returns(mockLogger.Object); - - var builder = new WebHostBuilder() - .UseLoggerFactory(mockLoggerFactory.Object) - .UseKestrel() - .UseUrls("http://127.0.0.1:0") - .Configure(app => app.Run(context => TaskCache.CompletedTask)); - - using (var host = builder.Build()) + using (var server = new TestServer(context => TaskCache.CompletedTask, new TestServiceContext(mockLoggerFactory.Object))) { - host.Start(); - - using (var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)) + using (var connection = server.CreateConnection()) { - socket.Connect(new IPEndPoint(IPAddress.Loopback, host.GetPort())); - socket.Send(Encoding.ASCII.GetBytes("GET / HTTP/1.1\r\nHost:\r\n\r\n")); + await connection.Send( + "GET / HTTP/1.1", + "Host:", + "", + ""); - // Wait until request is done being processed - Assert.True(await requestDone.WaitAsync(TimeSpan.FromSeconds(10))); + // Make sure the response is fully received, so a write failure (e.g. EPIPE) doesn't cause + // a more critical log message. + await connection.Receive( + "HTTP/1.1 200 OK", + $"Date: {server.Context.DateHeaderValue}", + "Content-Length: 0", + "", + ""); // Force a reset - socket.LingerState = new LingerOption(true, 0); + connection.Socket.LingerState = new LingerOption(true, 0); } // If the reset is correctly logged as Debug, the wait below should complete shortly. @@ -378,61 +371,64 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests // and therefore not logged. Assert.True(await connectionReset.WaitAsync(TimeSpan.FromSeconds(10))); } + + Assert.False(loggedHigherThanDebug); } [Fact] public async Task ConnectionResetMidRequestIsLoggedAsDebug() { + var requestStarted = new SemaphoreSlim(0); var connectionReset = new SemaphoreSlim(0); + var loggedHigherThanDebug = false; var mockLogger = new Mock(); mockLogger .Setup(logger => logger.IsEnabled(It.IsAny())) .Returns(true); mockLogger - .Setup(logger => logger.Log(LogLevel.Debug, _connectionResetEventId, It.IsAny(), null, It.IsAny>())) - .Callback(() => - { - connectionReset.Release(); - }); + .Setup(logger => logger.Log(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny>())) + .Callback>((logLevel, eventId, state, exception, formatter) => + { + if (eventId.Id == _connectionResetEventId) + { + connectionReset.Release(); + } + + if (logLevel > LogLevel.Debug) + { + loggedHigherThanDebug = true; + } + }); var mockLoggerFactory = new Mock(); mockLoggerFactory - .Setup(factory => factory.CreateLogger("Microsoft.AspNetCore.Server.Kestrel")) - .Returns(mockLogger.Object); - mockLoggerFactory - .Setup(factory => factory.CreateLogger("Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv")) - .Returns(mockLogger.Object); - mockLoggerFactory - .Setup(factory => factory.CreateLogger(It.IsNotIn("Microsoft.AspNetCore.Server.Kestrel", "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv"))) + .Setup(factory => factory.CreateLogger(It.IsAny())) .Returns(Mock.Of()); + mockLoggerFactory + .Setup(factory => factory.CreateLogger(It.IsIn("Microsoft.AspNetCore.Server.Kestrel", "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv"))) + .Returns(mockLogger.Object); - var requestStarted = new SemaphoreSlim(0); - - var builder = new WebHostBuilder() - .UseLoggerFactory(mockLoggerFactory.Object) - .UseKestrel() - .UseUrls("http://127.0.0.1:0") - .Configure(app => app.Run(async context => + using (var server = new TestServer(async context => { requestStarted.Release(); await context.Request.Body.ReadAsync(new byte[1], 0, 1); - })); - - using (var host = builder.Build()) + }, + new TestServiceContext(mockLoggerFactory.Object))) { - host.Start(); - - using (var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)) + using (var connection = server.CreateConnection()) { - socket.Connect(new IPEndPoint(IPAddress.Loopback, host.GetPort())); - socket.Send(Encoding.ASCII.GetBytes("GET / HTTP/1.1\r\nHost:\r\n\r\n")); + await connection.Send( + "GET / HTTP/1.1", + "Host:", + "", + ""); // Wait until connection is established Assert.True(await requestStarted.WaitAsync(TimeSpan.FromSeconds(10))); // Force a reset - socket.LingerState = new LingerOption(true, 0); + connection.Socket.LingerState = new LingerOption(true, 0); } // If the reset is correctly logged as Debug, the wait below should complete shortly. @@ -441,6 +437,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests // and therefore not logged. Assert.True(await connectionReset.WaitAsync(TimeSpan.FromSeconds(10))); } + + Assert.False(loggedHigherThanDebug); } [Fact] diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs index 8fafc71d63..5966eab03f 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs @@ -20,6 +20,7 @@ using Microsoft.AspNetCore.Server.Kestrel.Core.Internal; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; using Microsoft.AspNetCore.Testing; +using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Internal; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Primitives; @@ -300,7 +301,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests disposedTcs.TrySetResult(c.Response.StatusCode); }); - using (var server = new TestServer(handler, new TestServiceContext(), mockHttpContextFactory.Object)) + using (var server = new TestServer(handler, new TestServiceContext(), new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0)), + services => services.AddSingleton(mockHttpContextFactory.Object))) { if (!sendMalformedRequest) { diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/TestServer.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/TestServer.cs index 930c21cd08..ee2deb0b5e 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/TestServer.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/TestServer.cs @@ -34,21 +34,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } public TestServer(RequestDelegate app, TestServiceContext context) - : this(app, context, httpContextFactory: null) - { - } - - public TestServer(RequestDelegate app, TestServiceContext context, IHttpContextFactory httpContextFactory) - : this(app, context, new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0)), httpContextFactory) + : this(app, context, new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0))) { } public TestServer(RequestDelegate app, TestServiceContext context, ListenOptions listenOptions) - : this(app, context, listenOptions, null) + : this(app, context, listenOptions, _ => { }) { } - public TestServer(RequestDelegate app, TestServiceContext context, ListenOptions listenOptions, IHttpContextFactory httpContextFactory) + public TestServer(RequestDelegate app, TestServiceContext context, ListenOptions listenOptions, Action configureServices) { _app = app; _listenOptions = listenOptions; @@ -61,13 +56,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests }) .ConfigureServices(services => { - if (httpContextFactory != null) - { - services.AddSingleton(httpContextFactory); - } - services.AddSingleton(this); - services.AddSingleton(new KestrelTestLoggerFactory(context.ErrorLogger)); + services.AddSingleton(context.LoggerFactory); services.AddSingleton(sp => { // Manually configure options on the TestServiceContext. @@ -79,6 +69,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } return new KestrelServer(sp.GetRequiredService(), context); }); + + configureServices(services); }) .UseSetting(WebHostDefaults.ApplicationKey, typeof(TestServer).GetTypeInfo().Assembly.FullName) .Build(); diff --git a/test/shared/KestrelTestLoggerFactory.cs b/test/shared/KestrelTestLoggerFactory.cs index e8dbbd3408..80a94b0d1a 100644 --- a/test/shared/KestrelTestLoggerFactory.cs +++ b/test/shared/KestrelTestLoggerFactory.cs @@ -10,6 +10,11 @@ namespace Microsoft.AspNetCore.Testing { private readonly ILogger _testLogger; + public KestrelTestLoggerFactory() + : this(new TestApplicationErrorLogger()) + { + } + public KestrelTestLoggerFactory(ILogger testLogger) { _testLogger = testLogger; diff --git a/test/shared/TestApplicationErrorLogger.cs b/test/shared/TestApplicationErrorLogger.cs index 404b2cabc8..63f710cd7d 100644 --- a/test/shared/TestApplicationErrorLogger.cs +++ b/test/shared/TestApplicationErrorLogger.cs @@ -15,8 +15,6 @@ namespace Microsoft.AspNetCore.Testing // Application errors are logged using 13 as the eventId. private const int ApplicationErrorEventId = 13; - private TaskCompletionSource _messageLoggedTcs = new TaskCompletionSource(); - public bool ThrowOnCriticalErrors { get; set; } = true; public ConcurrentBag Messages { get; } = new ConcurrentBag(); @@ -27,8 +25,6 @@ namespace Microsoft.AspNetCore.Testing public int ApplicationErrorsLogged => Messages.Count(message => message.EventId.Id == ApplicationErrorEventId); - public Task MessageLoggedTask => _messageLoggedTcs.Task; - public IDisposable BeginScope(TState state) { return new Disposable(() => { }); @@ -60,8 +56,6 @@ namespace Microsoft.AspNetCore.Testing Exception = exception, Message = formatter(state, exception) }); - - _messageLoggedTcs.TrySetResult(null); } public class LogMessage diff --git a/test/shared/TestConnection.cs b/test/shared/TestConnection.cs index 0285a58e46..bc21df517e 100644 --- a/test/shared/TestConnection.cs +++ b/test/shared/TestConnection.cs @@ -17,35 +17,48 @@ namespace Microsoft.AspNetCore.Testing /// public class TestConnection : IDisposable { - private Socket _socket; - private NetworkStream _stream; - private StreamReader _reader; private static readonly TimeSpan Timeout = TimeSpan.FromMinutes(1); + private readonly bool _ownsSocket; + private readonly Socket _socket; + private readonly NetworkStream _stream; + private readonly StreamReader _reader; + public TestConnection(int port) : this(port, AddressFamily.InterNetwork) { } public TestConnection(int port, AddressFamily addressFamily) + : this(CreateConnectedLoopbackSocket(port, addressFamily), ownsSocket: true) { - Create(port, addressFamily); } - public StreamReader Reader => _reader; - - public void Create(int port, AddressFamily addressFamily) + public TestConnection(Socket socket) + : this(socket, ownsSocket: false) { - _socket = CreateConnectedLoopbackSocket(port, addressFamily); + } - _stream = new NetworkStream(_socket, false); + private TestConnection(Socket socket, bool ownsSocket) + { + _ownsSocket = ownsSocket; + _socket = socket; + _stream = new NetworkStream(_socket, ownsSocket: false); _reader = new StreamReader(_stream, Encoding.ASCII); } + public Socket Socket => _socket; + + public StreamReader Reader => _reader; + public void Dispose() { _stream.Dispose(); - _socket.Dispose(); + + if (_ownsSocket) + { + _socket.Dispose(); + } } public async Task SendAll(params string[] lines) diff --git a/test/shared/TestServiceContext.cs b/test/shared/TestServiceContext.cs index b1b28f7014..b06362b3fe 100644 --- a/test/shared/TestServiceContext.cs +++ b/test/shared/TestServiceContext.cs @@ -12,9 +12,19 @@ namespace Microsoft.AspNetCore.Testing public class TestServiceContext : ServiceContext { public TestServiceContext() + : this(new KestrelTestLoggerFactory()) { - ErrorLogger = new TestApplicationErrorLogger(); - Log = new TestKestrelTrace(ErrorLogger); + } + + public TestServiceContext(ILoggerFactory loggerFactory) + : this(loggerFactory, new KestrelTrace(loggerFactory.CreateLogger("Microsoft.AspNetCore.Server.Kestrel"))) + { + } + + public TestServiceContext(ILoggerFactory loggerFactory, IKestrelTrace kestrelTrace) + { + LoggerFactory = loggerFactory; + Log = kestrelTrace; ThreadPool = new LoggingThreadPool(Log); SystemClock = new MockSystemClock(); DateHeaderValueManager = new DateHeaderValueManager(SystemClock); @@ -27,7 +37,7 @@ namespace Microsoft.AspNetCore.Testing }; } - public TestApplicationErrorLogger ErrorLogger { get; } + public ILoggerFactory LoggerFactory { get; } public string DateHeaderValue { get; } } From 009759c7f68010bff72f6dac28f3573680fd6ba6 Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Thu, 25 May 2017 16:01:17 -0700 Subject: [PATCH 1303/1662] Fix broken microbenchmarks (#1861). --- .../FrameFeatureCollection.cs | 6 +++++- .../FrameParsingOverheadBenchmark.cs | 5 ++++- .../FrameWritingBenchmark.cs | 11 +++++++---- .../Mocks/MockConnectionInformation.cs | 2 +- .../RequestParsingBenchmark.cs | 14 +++++++++----- .../ResponseHeaderCollectionBenchmark.cs | 6 +++++- .../ResponseHeadersWritingBenchmark.cs | 11 +++++++---- 7 files changed, 38 insertions(+), 17 deletions(-) diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameFeatureCollection.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameFeatureCollection.cs index bd4ec5ae97..3d699f795f 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameFeatureCollection.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameFeatureCollection.cs @@ -7,6 +7,7 @@ using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; namespace Microsoft.AspNetCore.Server.Kestrel.Performance { @@ -84,7 +85,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance var frameContext = new FrameContext { ServiceContext = serviceContext, - ConnectionInformation = new MockConnectionInformation() + ConnectionInformation = new MockConnectionInformation + { + PipeFactory = new PipeFactory() + } }; _frame = new Frame(application: null, frameContext: frameContext); diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameParsingOverheadBenchmark.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameParsingOverheadBenchmark.cs index 71964abb79..6128d3c955 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameParsingOverheadBenchmark.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameParsingOverheadBenchmark.cs @@ -29,7 +29,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance var frameContext = new FrameContext { ServiceContext = serviceContext, - ConnectionInformation = new MockConnectionInformation(), + ConnectionInformation = new MockConnectionInformation + { + PipeFactory = new PipeFactory() + }, TimeoutControl = new MockTimeoutControl() }; diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameWritingBenchmark.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameWritingBenchmark.cs index ff1a3b5298..5eea9eafb2 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameWritingBenchmark.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameWritingBenchmark.cs @@ -75,9 +75,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance private TestFrame MakeFrame() { - var factory = new PipeFactory(); - var input = factory.Create(); - var output = factory.Create(); + var pipeFactory = new PipeFactory(); + var input = pipeFactory.Create(); + var output = pipeFactory.Create(); var serviceContext = new ServiceContext { @@ -90,7 +90,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance var frame = new TestFrame(application: null, context: new FrameContext { ServiceContext = serviceContext, - ConnectionInformation = new MockConnectionInformation(), + ConnectionInformation = new MockConnectionInformation + { + PipeFactory = pipeFactory + }, Input = input.Reader, Output = output }); diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Mocks/MockConnectionInformation.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Mocks/MockConnectionInformation.cs index 2cec8398a0..e02bd98be2 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Mocks/MockConnectionInformation.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Mocks/MockConnectionInformation.cs @@ -13,7 +13,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance public IPEndPoint RemoteEndPoint { get; } public IPEndPoint LocalEndPoint { get; } - public PipeFactory PipeFactory { get; } + public PipeFactory PipeFactory { get; set; } public bool RequiresDispatch { get; } public IScheduler InputWriterScheduler { get; } public IScheduler OutputReaderScheduler { get; } diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsingBenchmark.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsingBenchmark.cs index c6d5e5263c..c88f9408b2 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsingBenchmark.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsingBenchmark.cs @@ -17,26 +17,30 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance public Frame Frame { get; set; } - public PipeFactory PipelineFactory { get; set; } + public PipeFactory PipeFactory { get; set; } [Setup] public void Setup() { + PipeFactory = new PipeFactory(); + Pipe = PipeFactory.Create(); + var serviceContext = new ServiceContext { HttpParserFactory = f => new HttpParser(), - ServerOptions = new KestrelServerOptions() + ServerOptions = new KestrelServerOptions(), }; var frameContext = new FrameContext { ServiceContext = serviceContext, - ConnectionInformation = new MockConnectionInformation(), + ConnectionInformation = new MockConnectionInformation + { + PipeFactory = PipeFactory + }, TimeoutControl = new MockTimeoutControl() }; Frame = new Frame(application: null, frameContext: frameContext); - PipelineFactory = new PipeFactory(); - Pipe = PipelineFactory.Create(); } [Benchmark(Baseline = true, OperationsPerInvoke = RequestParsingData.InnerLoopCount)] diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/ResponseHeaderCollectionBenchmark.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/ResponseHeaderCollectionBenchmark.cs index 7a65a7d7a6..f4d894a645 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/ResponseHeaderCollectionBenchmark.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/ResponseHeaderCollectionBenchmark.cs @@ -9,6 +9,7 @@ using Microsoft.AspNetCore.Http.Internal; using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; namespace Microsoft.AspNetCore.Server.Kestrel.Performance { @@ -176,7 +177,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance var frameContext = new FrameContext { ServiceContext = serviceContext, - ConnectionInformation = new MockConnectionInformation() + ConnectionInformation = new MockConnectionInformation + { + PipeFactory = new PipeFactory() + } }; var frame = new Frame(application: null, frameContext: frameContext); diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/ResponseHeadersWritingBenchmark.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/ResponseHeadersWritingBenchmark.cs index 659b903a8e..1daf1b7e45 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/ResponseHeadersWritingBenchmark.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/ResponseHeadersWritingBenchmark.cs @@ -110,9 +110,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance [Setup] public void Setup() { - var factory = new PipeFactory(); - var input = factory.Create(); - var output = factory.Create(); + var pipeFactory = new PipeFactory(); + var input = pipeFactory.Create(); + var output = pipeFactory.Create(); var serviceContext = new ServiceContext { @@ -125,7 +125,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance var frame = new TestFrame(application: null, context: new FrameContext { ServiceContext = serviceContext, - ConnectionInformation = new MockConnectionInformation(), + ConnectionInformation = new MockConnectionInformation + { + PipeFactory = pipeFactory + }, TimeoutControl = new MockTimeoutControl(), Input = input.Reader, Output = output From c343628926800a9a9668500b15fc5b2f13805241 Mon Sep 17 00:00:00 2001 From: Nate McMaster Date: Fri, 26 May 2017 12:26:05 -0700 Subject: [PATCH 1304/1662] Implement max connection limits - Added new options to allow configuring the maximum number of concurrent connections and upgraded connections. - `KestrelServerLimits.MaxConcurrentConnections` defaults unlimited. - `KestrelServerLimits.MaxConcurrentUpgradedConnections` defaults to unlimited. - Calls to IHttpUpgradeFeature.UpgradeAsync() will throw when the MaxConcurrentUpgradedConnections limit has been reached. - Kestrel will close new connections without response when MaxConcurrentConnections is reached. --- .vscode/launch.json | 8 +- .vscode/tasks.json | 17 ++ .../CoreStrings.resx | 23 +- .../Internal/ConnectionHandler.cs | 7 + .../Internal/FrameConnection.cs | 9 + .../Internal/Http/Frame.FeatureCollection.cs | 16 +- .../Internal/Http/Frame.cs | 18 +- .../Internal/Http/FrameOfT.cs | 4 +- .../Internal/Http/FrameRequestStream.cs | 2 +- .../Infrastructure/FrameConnectionManager.cs | 24 ++- .../Internal/Infrastructure/IKestrelTrace.cs | 2 + .../Infrastructure/ITimeoutControl.cs | 2 +- .../Infrastructure/KestrelEventSource.cs | 10 + .../Internal/Infrastructure/KestrelTrace.cs | 10 +- .../Infrastructure/ResourceCounter.cs | 77 +++++++ .../Internal/RejectionConnection.cs | 46 ++++ .../KestrelServer.cs | 5 +- .../KestrelServerLimits.cs | 104 +++++---- .../Properties/CoreStrings.Designer.cs | 78 +++++-- .../FrameConnectionManagerTests.cs | 2 +- .../KestrelServerLimitsTests.cs | 62 +++++- .../ResourceCounterTests.cs | 56 +++++ .../ConnectionLimitTests.cs | 198 ++++++++++++++++++ .../FrameConnectionManagerTests.cs | 5 +- .../MaxRequestBufferSizeTests.cs | 8 +- .../RequestTests.cs | 5 +- .../UpgradeTests.cs | 123 +++++++++-- .../Mocks/MockTimeoutControl.cs | 6 +- .../Mocks/MockTrace.cs | 1 + test/shared/DisposableStack.cs | 20 ++ test/shared/EventRaisingResourceCounter.cs | 34 +++ test/shared/TestConnection.cs | 26 +++ test/shared/TestServiceContext.cs | 2 +- 33 files changed, 888 insertions(+), 122 deletions(-) create mode 100644 src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/ResourceCounter.cs create mode 100644 src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/RejectionConnection.cs create mode 100644 test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/ResourceCounterTests.cs create mode 100644 test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ConnectionLimitTests.cs create mode 100644 test/shared/DisposableStack.cs create mode 100644 test/shared/EventRaisingResourceCounter.cs diff --git a/.vscode/launch.json b/.vscode/launch.json index f97435a509..2db39e4359 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -7,6 +7,12 @@ "request": "attach", "processId": "${command:pickProcess}" }, + { + "name": "Attach: .NET Framework", + "type": "clr", + "request": "attach", + "processId": "${command:pickProcess}" + }, { "name": "Debug: SampleApp", "type": "coreclr", @@ -62,7 +68,7 @@ "type": "coreclr", "request": "launch", "preLaunchTask": "Compile: CodeGenerator", - "program": "${workspaceRoot}/tools/CodeGenerator/bin/Debug/netcoreapp1.1/CodeGenerator.dll", + "program": "${workspaceRoot}/tools/CodeGenerator/bin/Debug/netcoreapp2.0/CodeGenerator.dll", "args": [], "cwd": "${workspaceRoot}", "console": "internalConsole", diff --git a/.vscode/tasks.json b/.vscode/tasks.json index db382e6056..af0e4b2245 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -76,6 +76,23 @@ "cwd": "${workspaceRoot}/tools/CodeGenerator/" } }, + { + "taskName": "Run: resx generation", + "suppressTaskName": true, + "command": "build.cmd", + "args": [ + "/t:resx" + ], + "options": { + "cwd": "${workspaceRoot}" + }, + "osx": { + "command": "./build.sh" + }, + "linux": { + "command": "./build.sh" + } + }, { "taskName": "Run: Benchmarks", "args": [ diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/CoreStrings.resx b/src/Microsoft.AspNetCore.Server.Kestrel.Core/CoreStrings.resx index c024ae82a9..f2f873fe3b 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/CoreStrings.resx +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/CoreStrings.resx @@ -228,14 +228,17 @@ Invalid Content-Length: "{value}". Value must be a positive integral number. - - Value must be null or a non-negative integer. + + Value must be null or a non-negative number. - - Value must be a positive integer. + + Value must be a non-negative number. - - Value must be null or a positive integer. + + Value must be a positive number. + + + Value must be null or a positive number. Unix socket path must be absolute. @@ -309,4 +312,10 @@ Cannot upgrade a non-upgradable request. Check IHttpUpgradeFeature.IsUpgradableRequest to determine if a request can be upgraded. - \ No newline at end of file + + Request cannot be upgraded because the server has already opened the maximum number of upgraded connections. + + + IHttpUpgradeFeature.UpgradeAsync was already called and can only be called once per connection. + + diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/ConnectionHandler.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/ConnectionHandler.cs index 96f510ea45..bee5dec4e1 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/ConnectionHandler.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/ConnectionHandler.cs @@ -33,6 +33,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal var connectionId = CorrelationIdGenerator.GetNextId(); var frameConnectionId = Interlocked.Increment(ref _lastFrameConnectionId); + if (!_serviceContext.ConnectionManager.NormalConnectionCount.TryLockOne()) + { + var goAway = new RejectionConnection(inputPipe, outputPipe, connectionId, _serviceContext); + goAway.Reject(); + return goAway; + } + var connection = new FrameConnection(new FrameConnectionContext { ConnectionId = connectionId, diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnection.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnection.cs index 9b4da51ec1..dad0f21cd2 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnection.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnection.cs @@ -126,6 +126,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal _context.ServiceContext.ConnectionManager.RemoveConnection(_context.FrameConnectionId); DisposeAdaptedConnections(); + if (_frame.WasUpgraded) + { + _context.ServiceContext.ConnectionManager.UpgradedConnectionCount.ReleaseOne(); + } + else + { + _context.ServiceContext.ConnectionManager.NormalConnectionCount.ReleaseOne(); + } + Log.ConnectionStop(ConnectionId); KestrelEventSource.Log.ConnectionStop(this); } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.FeatureCollection.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.FeatureCollection.cs index 429c517899..6ec4f45348 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.FeatureCollection.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.FeatureCollection.cs @@ -160,7 +160,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http bool IHttpResponseFeature.HasStarted => HasResponseStarted; - bool IHttpUpgradeFeature.IsUpgradableRequest => _upgrade; + bool IHttpUpgradeFeature.IsUpgradableRequest => _upgradeAvailable; bool IFeatureCollection.IsReadOnly => false; @@ -235,6 +235,20 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http throw new InvalidOperationException(CoreStrings.CannotUpgradeNonUpgradableRequest); } + if (_wasUpgraded) + { + throw new InvalidOperationException(CoreStrings.UpgradeCannotBeCalledMultipleTimes); + } + + if (!ServiceContext.ConnectionManager.UpgradedConnectionCount.TryLockOne()) + { + throw new InvalidOperationException(CoreStrings.UpgradedConnectionLimitReached); + } + + _wasUpgraded = true; + + ServiceContext.ConnectionManager.NormalConnectionCount.ReleaseOne(); + StatusCode = StatusCodes.Status101SwitchingProtocols; ReasonPhrase = "Switching Protocols"; ResponseHeaders["Connection"] = "Upgrade"; diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.cs index 0387c0ce8e..374b9e6518 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.cs @@ -41,7 +41,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http private static readonly byte[] _bytesTransferEncodingChunked = Encoding.ASCII.GetBytes("\r\nTransfer-Encoding: chunked"); private static readonly byte[] _bytesHttpVersion11 = Encoding.ASCII.GetBytes("HTTP/1.1 "); private static readonly byte[] _bytesEndHeaders = Encoding.ASCII.GetBytes("\r\n\r\n"); - private static readonly byte[] _bytesServer = Encoding.ASCII.GetBytes("\r\nServer: Kestrel"); + private static readonly byte[] _bytesServer = Encoding.ASCII.GetBytes("\r\nServer: " + Constants.ServerName); private const string EmptyPath = "/"; private const string Asterisk = "*"; @@ -61,7 +61,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http protected RequestProcessingStatus _requestProcessingStatus; protected bool _keepAlive; - protected bool _upgrade; + protected bool _upgradeAvailable; + private volatile bool _wasUpgraded; private bool _canHaveBody; private bool _autoChunk; protected Exception _applicationException; @@ -138,6 +139,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http } } + public bool WasUpgraded => _wasUpgraded; public IPAddress RemoteIpAddress { get; set; } public int RemotePort { get; set; } public IPAddress LocalIpAddress { get; set; } @@ -208,10 +210,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http private int _statusCode; public int StatusCode { - get - { - return _statusCode; - } + get => _statusCode; set { if (HasResponseStarted) @@ -227,10 +226,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http public string ReasonPhrase { - get - { - return _reasonPhrase; - } + get => _reasonPhrase; + set { if (HasResponseStarted) @@ -1038,6 +1035,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http var dateHeaderValues = DateHeaderValueManager.GetDateHeaderValues(); responseHeaders.SetRawDate(dateHeaderValues.String, dateHeaderValues.Bytes); + responseHeaders.ContentLength = 0; if (ServerOptions.AddServerHeader) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameOfT.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameOfT.cs index 4fdda6d9f1..769cd8e9db 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameOfT.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameOfT.cs @@ -89,7 +89,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http var messageBody = MessageBody.For(_httpVersion, FrameRequestHeaders, this); _keepAlive = messageBody.RequestKeepAlive; - _upgrade = messageBody.RequestUpgrade; + _upgradeAvailable = messageBody.RequestUpgrade; InitializeStreams(messageBody); @@ -165,7 +165,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http // An upgraded request has no defined request body length. // Cancel any pending read so the read loop ends. - if (_upgrade) + if (_upgradeAvailable) { Input.CancelPendingRead(); } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameRequestStream.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameRequestStream.cs index 772668cf2c..be5f9fd66f 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameRequestStream.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameRequestStream.cs @@ -130,7 +130,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http } if (bufferSize <= 0) { - throw new ArgumentException(CoreStrings.PositiveIntRequired, nameof(bufferSize)); + throw new ArgumentException(CoreStrings.PositiveNumberRequired, nameof(bufferSize)); } var task = ValidateState(cancellationToken); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/FrameConnectionManager.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/FrameConnectionManager.cs index 3fd4987568..ed4c2d44ae 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/FrameConnectionManager.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/FrameConnectionManager.cs @@ -11,11 +11,28 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure private readonly ConcurrentDictionary _connectionReferences = new ConcurrentDictionary(); private readonly IKestrelTrace _trace; - public FrameConnectionManager(IKestrelTrace trace) + public FrameConnectionManager(IKestrelTrace trace, long? normalConnectionLimit, long? upgradedConnectionLimit) + : this(trace, GetCounter(normalConnectionLimit), GetCounter(upgradedConnectionLimit)) { + } + + public FrameConnectionManager(IKestrelTrace trace, ResourceCounter normalConnections, ResourceCounter upgradedConnections) + { + NormalConnectionCount = normalConnections; + UpgradedConnectionCount = upgradedConnections; _trace = trace; } + /// + /// TCP connections processed by Kestrel. + /// + public ResourceCounter NormalConnectionCount { get; } + + /// + /// Connections that have been switched to a different protocol. + /// + public ResourceCounter UpgradedConnectionCount { get; } + public void AddConnection(long id, FrameConnection connection) { if (!_connectionReferences.TryAdd(id, new FrameConnectionReference(connection))) @@ -52,5 +69,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure // If both conditions are false, the connection was removed during the heartbeat. } } + + private static ResourceCounter GetCounter(long? number) + => number.HasValue + ? ResourceCounter.Quota(number.Value) + : ResourceCounter.Unlimited; } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/IKestrelTrace.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/IKestrelTrace.cs index 1d88029d3d..91012fdbf5 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/IKestrelTrace.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/IKestrelTrace.cs @@ -16,6 +16,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure void ConnectionResume(string connectionId); + void ConnectionRejected(string connectionId); + void ConnectionKeepAlive(string connectionId); void ConnectionDisconnect(string connectionId); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/ITimeoutControl.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/ITimeoutControl.cs index d71b423873..e031495f1d 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/ITimeoutControl.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/ITimeoutControl.cs @@ -9,4 +9,4 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure void ResetTimeout(long ticks, TimeoutAction timeoutAction); void CancelTimeout(); } -} \ No newline at end of file +} diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/KestrelEventSource.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/KestrelEventSource.cs index eb04b7f486..04ead7ab1e 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/KestrelEventSource.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/KestrelEventSource.cs @@ -68,6 +68,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure WriteEvent(2, connectionId); } + [MethodImpl(MethodImplOptions.NoInlining)] + [Event(5, Level = EventLevel.Verbose)] + public void ConnectionRejected(string connectionId) + { + if (IsEnabled()) + { + WriteEvent(5, connectionId); + } + } + [NonEvent] public void RequestStart(Frame frame) { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/KestrelTrace.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/KestrelTrace.cs index c7ef78a67c..e04ca4e0b8 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/KestrelTrace.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/KestrelTrace.cs @@ -54,6 +54,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal private static readonly Action _applicationNeverCompleted = LoggerMessage.Define(LogLevel.Critical, 23, @"Connection id ""{ConnectionId}"" application never completed"); + private static readonly Action _connectionRejected = + LoggerMessage.Define(LogLevel.Warning, 24, @"Connection id ""{ConnectionId}"" rejected because the maximum number of concurrent connections has been reached."); + protected readonly ILogger _logger; public KestrelTrace(ILogger logger) @@ -86,6 +89,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal _connectionKeepAlive(_logger, connectionId, null); } + public void ConnectionRejected(string connectionId) + { + _connectionRejected(_logger, connectionId, null); + } + public virtual void ConnectionDisconnect(string connectionId) { _connectionDisconnect(_logger, connectionId, null); @@ -138,4 +146,4 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal public virtual IDisposable BeginScope(TState state) => _logger.BeginScope(state); } -} \ No newline at end of file +} diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/ResourceCounter.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/ResourceCounter.cs new file mode 100644 index 0000000000..68c96e25ac --- /dev/null +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/ResourceCounter.cs @@ -0,0 +1,77 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Diagnostics; +using System.Threading; + +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure +{ + public abstract class ResourceCounter + { + public abstract bool TryLockOne(); + public abstract void ReleaseOne(); + + public static ResourceCounter Unlimited { get; } = new UnlimitedCounter(); + public static ResourceCounter Quota(long amount) => new FiniteCounter(amount); + + private class UnlimitedCounter : ResourceCounter + { + public override bool TryLockOne() => true; + public override void ReleaseOne() + { + } + } + + internal class FiniteCounter : ResourceCounter + { + private readonly long _max; + private long _count; + + public FiniteCounter(long max) + { + if (max < 0) + { + throw new ArgumentOutOfRangeException(CoreStrings.NonNegativeNumberRequired); + } + + _max = max; + } + + public override bool TryLockOne() + { + var count = _count; + + // Exit if count == MaxValue as incrementing would overflow. + + while (count < _max && count != long.MaxValue) + { + var prev = Interlocked.CompareExchange(ref _count, count + 1, count); + if (prev == count) + { + return true; + } + + // Another thread changed the count before us. Try again with the new counter value. + count = prev; + } + + return false; + } + + public override void ReleaseOne() + { + Interlocked.Decrement(ref _count); + + Debug.Assert(_count >= 0, "Resource count is negative. More resources were released than were locked."); + } + + // for testing + internal long Count + { + get => _count; + set => _count = value; + } + } + } +} diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/RejectionConnection.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/RejectionConnection.cs new file mode 100644 index 0000000000..0cd9799db7 --- /dev/null +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/RejectionConnection.cs @@ -0,0 +1,46 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions; + +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal +{ + public class RejectionConnection : IConnectionContext + { + private readonly IKestrelTrace _log; + private readonly IPipe _input; + private readonly IPipe _output; + + public RejectionConnection(IPipe input, IPipe output, string connectionId, ServiceContext serviceContext) + { + ConnectionId = connectionId; + _log = serviceContext.Log; + _input = input; + _output = output; + } + + public string ConnectionId { get; } + public IPipeWriter Input => _input.Writer; + public IPipeReader Output => _output.Reader; + + public void Reject() + { + KestrelEventSource.Log.ConnectionRejected(ConnectionId); + _log.ConnectionRejected(ConnectionId); + _input.Reader.Complete(); + _output.Writer.Complete(); + } + + // TODO: Remove these (https://github.com/aspnet/KestrelHttpServer/issues/1772) + void IConnectionContext.OnConnectionClosed(Exception ex) + { + } + + void IConnectionContext.Abort(Exception ex) + { + } + } +} diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/KestrelServer.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/KestrelServer.cs index 2eb204c0eb..8781882b06 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/KestrelServer.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/KestrelServer.cs @@ -67,7 +67,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core var serverOptions = options.Value ?? new KestrelServerOptions(); var logger = loggerFactory.CreateLogger("Microsoft.AspNetCore.Server.Kestrel"); var trace = new KestrelTrace(logger); - var connectionManager = new FrameConnectionManager(trace); + var connectionManager = new FrameConnectionManager( + trace, + serverOptions.Limits.MaxConcurrentConnections, + serverOptions.Limits.MaxConcurrentUpgradedConnections); var systemClock = new SystemClock(); var dateHeaderValueManager = new DateHeaderValueManager(systemClock); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/KestrelServerLimits.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/KestrelServerLimits.cs index 9ed2293b6b..dc86c064e6 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/KestrelServerLimits.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/KestrelServerLimits.cs @@ -28,6 +28,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core private TimeSpan _requestHeadersTimeout = TimeSpan.FromSeconds(30); + // default to unlimited + private long? _maxConcurrentConnections = null; + private long? _maxConcurrentUpgradedConnections = null; + /// /// Gets or sets the maximum size of the response buffer before write /// calls begin to block or return tasks that don't complete until the @@ -41,15 +45,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core /// public long? MaxResponseBufferSize { - get - { - return _maxResponseBufferSize; - } + get => _maxResponseBufferSize; set { if (value.HasValue && value.Value < 0) { - throw new ArgumentOutOfRangeException(nameof(value), CoreStrings.NonNegativeNullableIntRequired); + throw new ArgumentOutOfRangeException(nameof(value), CoreStrings.NonNegativeNumberOrNullRequired); } _maxResponseBufferSize = value; } @@ -64,15 +65,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core /// public long? MaxRequestBufferSize { - get - { - return _maxRequestBufferSize; - } + get => _maxRequestBufferSize; set { if (value.HasValue && value.Value <= 0) { - throw new ArgumentOutOfRangeException(nameof(value), CoreStrings.PositiveNullableIntRequired); + throw new ArgumentOutOfRangeException(nameof(value), CoreStrings.PositiveNumberOrNullRequired); } _maxRequestBufferSize = value; } @@ -86,15 +84,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core /// public int MaxRequestLineSize { - get - { - return _maxRequestLineSize; - } + get => _maxRequestLineSize; set { if (value <= 0) { - throw new ArgumentOutOfRangeException(nameof(value), CoreStrings.PositiveIntRequired); + throw new ArgumentOutOfRangeException(nameof(value), CoreStrings.PositiveNumberRequired); } _maxRequestLineSize = value; } @@ -108,15 +103,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core /// public int MaxRequestHeadersTotalSize { - get - { - return _maxRequestHeadersTotalSize; - } + get => _maxRequestHeadersTotalSize; set { if (value <= 0) { - throw new ArgumentOutOfRangeException(nameof(value), CoreStrings.PositiveIntRequired); + throw new ArgumentOutOfRangeException(nameof(value), CoreStrings.PositiveNumberRequired); } _maxRequestHeadersTotalSize = value; } @@ -130,15 +122,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core /// public int MaxRequestHeaderCount { - get - { - return _maxRequestHeaderCount; - } + get => _maxRequestHeaderCount; set { if (value <= 0) { - throw new ArgumentOutOfRangeException(nameof(value), CoreStrings.PositiveIntRequired); + throw new ArgumentOutOfRangeException(nameof(value), CoreStrings.PositiveNumberRequired); } _maxRequestHeaderCount = value; } @@ -152,14 +141,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core /// public TimeSpan KeepAliveTimeout { - get - { - return _keepAliveTimeout; - } - set - { - _keepAliveTimeout = value; - } + get => _keepAliveTimeout; + set => _keepAliveTimeout = value; } /// @@ -170,13 +153,58 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core /// public TimeSpan RequestHeadersTimeout { - get - { - return _requestHeadersTimeout; - } + get => _requestHeadersTimeout; + set => _requestHeadersTimeout = value; + } + + /// + /// Gets or sets the maximum number of open HTTP/S connections. When set to null, the number of connections is unlimited. + /// + /// + /// + /// Defaults to null. + /// + /// + /// When a connection is upgraded to another protocol, such as WebSockets, its connection is counted against the + /// limit instead of . + /// + /// + public long? MaxConcurrentConnections + { + get => _maxConcurrentConnections; set { - _requestHeadersTimeout = value; + if (value.HasValue && value <= 0) + { + throw new ArgumentOutOfRangeException(nameof(value), CoreStrings.PositiveNumberOrNullRequired); + } + _maxConcurrentConnections = value; + } + } + + /// + /// Gets or sets the maximum number of open, upgraded connections. When set to null, the number of upgraded connections is unlimited. + /// An upgraded connection is one that has been switched from HTTP to another protocol, such as WebSockets. + /// + /// + /// + /// Defaults to null. + /// + /// + /// When a connection is upgraded to another protocol, such as WebSockets, its connection is counted against the + /// limit instead of . + /// + /// + public long? MaxConcurrentUpgradedConnections + { + get => _maxConcurrentUpgradedConnections; + set + { + if (value.HasValue && value < 0) + { + throw new ArgumentOutOfRangeException(nameof(value), CoreStrings.NonNegativeNumberOrNullRequired); + } + _maxConcurrentUpgradedConnections = value; } } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Properties/CoreStrings.Designer.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Properties/CoreStrings.Designer.cs index 2971494a5b..5303d1e5b8 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Properties/CoreStrings.Designer.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Properties/CoreStrings.Designer.cs @@ -529,46 +529,60 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core => string.Format(CultureInfo.CurrentCulture, GetString("InvalidContentLength_InvalidNumber", "value"), value); /// - /// Value must be null or a non-negative integer. + /// Value must be null or a non-negative number. /// - internal static string NonNegativeNullableIntRequired + internal static string NonNegativeNumberOrNullRequired { - get => GetString("NonNegativeNullableIntRequired"); + get => GetString("NonNegativeNumberOrNullRequired"); } /// - /// Value must be null or a non-negative integer. + /// Value must be null or a non-negative number. /// - internal static string FormatNonNegativeNullableIntRequired() - => GetString("NonNegativeNullableIntRequired"); + internal static string FormatNonNegativeNumberOrNullRequired() + => GetString("NonNegativeNumberOrNullRequired"); /// - /// Value must be a positive integer. + /// Value must be a non-negative number. /// - internal static string PositiveIntRequired + internal static string NonNegativeNumberRequired { - get => GetString("PositiveIntRequired"); + get => GetString("NonNegativeNumberRequired"); } /// - /// Value must be a positive integer. + /// Value must be a non-negative number. /// - internal static string FormatPositiveIntRequired() - => GetString("PositiveIntRequired"); + internal static string FormatNonNegativeNumberRequired() + => GetString("NonNegativeNumberRequired"); /// - /// Value must be null or a positive integer. + /// Value must be a positive number. /// - internal static string PositiveNullableIntRequired + internal static string PositiveNumberRequired { - get => GetString("PositiveNullableIntRequired"); + get => GetString("PositiveNumberRequired"); } /// - /// Value must be null or a positive integer. + /// Value must be a positive number. /// - internal static string FormatPositiveNullableIntRequired() - => GetString("PositiveNullableIntRequired"); + internal static string FormatPositiveNumberRequired() + => GetString("PositiveNumberRequired"); + + /// + /// Value must be null or a positive number. + /// + internal static string PositiveNumberOrNullRequired + { + get => GetString("PositiveNumberOrNullRequired"); + } + + /// + /// Value must be null or a positive number. + /// + internal static string FormatPositiveNumberOrNullRequired() + => GetString("PositiveNumberOrNullRequired"); /// /// Unix socket path must be absolute. @@ -906,6 +920,34 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core internal static string FormatCannotUpgradeNonUpgradableRequest() => GetString("CannotUpgradeNonUpgradableRequest"); + /// + /// Request cannot be upgraded because the server has already opened the maximum number of upgraded connections. + /// + internal static string UpgradedConnectionLimitReached + { + get => GetString("UpgradedConnectionLimitReached"); + } + + /// + /// Request cannot be upgraded because the server has already opened the maximum number of upgraded connections. + /// + internal static string FormatUpgradedConnectionLimitReached() + => GetString("UpgradedConnectionLimitReached"); + + /// + /// IHttpUpgradeFeature.UpgradeAsync was already called and can only be called once per connection. + /// + internal static string UpgradeCannotBeCalledMultipleTimes + { + get => GetString("UpgradeCannotBeCalledMultipleTimes"); + } + + /// + /// IHttpUpgradeFeature.UpgradeAsync was already called and can only be called once per connection. + /// + internal static string FormatUpgradeCannotBeCalledMultipleTimes() + => GetString("UpgradeCannotBeCalledMultipleTimes"); + private static string GetString(string name, params string[] formatterNames) { var value = _resourceManager.GetString(name); diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameConnectionManagerTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameConnectionManagerTests.cs index 7aaafa4022..a6e6bb4879 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameConnectionManagerTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameConnectionManagerTests.cs @@ -18,7 +18,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests { var connectionId = "0"; var trace = new Mock(); - var frameConnectionManager = new FrameConnectionManager(trace.Object); + var frameConnectionManager = new FrameConnectionManager(trace.Object, ResourceCounter.Unlimited, ResourceCounter.Unlimited); // Create FrameConnection in inner scope so it doesn't get rooted by the current frame. UnrootedConnectionsGetRemovedFromHeartbeatInnerScope(connectionId, frameConnectionManager, trace); diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/KestrelServerLimitsTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/KestrelServerLimitsTests.cs index a4bf75c59b..25db797284 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/KestrelServerLimitsTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/KestrelServerLimitsTests.cs @@ -105,10 +105,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests [InlineData(0)] public void MaxRequestHeadersTotalSizeInvalid(int value) { - Assert.Throws(() => - { - (new KestrelServerLimits()).MaxRequestHeadersTotalSize = value; - }); + var ex = Assert.Throws(() => new KestrelServerLimits().MaxRequestHeadersTotalSize = value); + Assert.StartsWith(CoreStrings.PositiveNumberRequired, ex.Message); } [Theory] @@ -187,5 +185,61 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests o.RequestHeadersTimeout = TimeSpan.FromSeconds(seconds); Assert.Equal(seconds, o.RequestHeadersTimeout.TotalSeconds); } + + [Fact] + public void MaxConnectionsDefault() + { + Assert.Null(new KestrelServerLimits().MaxConcurrentConnections); + Assert.Null(new KestrelServerLimits().MaxConcurrentUpgradedConnections); + } + + [Theory] + [InlineData(null)] + [InlineData(1u)] + [InlineData(long.MaxValue)] + public void MaxConnectionsValid(long? value) + { + var limits = new KestrelServerLimits + { + MaxConcurrentConnections = value + }; + + Assert.Equal(value, limits.MaxConcurrentConnections); + } + + [Theory] + [InlineData(long.MinValue)] + [InlineData(-1)] + [InlineData(0)] + public void MaxConnectionsInvalid(long value) + { + var ex = Assert.Throws(() => new KestrelServerLimits().MaxConcurrentConnections = value); + Assert.StartsWith(CoreStrings.PositiveNumberOrNullRequired, ex.Message); + } + + [Theory] + [InlineData(null)] + [InlineData(0)] + [InlineData(1)] + [InlineData(long.MaxValue)] + public void MaxUpgradedConnectionsValid(long? value) + { + var limits = new KestrelServerLimits + { + MaxConcurrentUpgradedConnections = value + }; + + Assert.Equal(value, limits.MaxConcurrentUpgradedConnections); + } + + + [Theory] + [InlineData(long.MinValue)] + [InlineData(-1)] + public void MaxUpgradedConnectionsInvalid(long value) + { + var ex = Assert.Throws(() => new KestrelServerLimits().MaxConcurrentUpgradedConnections = value); + Assert.StartsWith(CoreStrings.NonNegativeNumberOrNullRequired, ex.Message); + } } } diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/ResourceCounterTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/ResourceCounterTests.cs new file mode 100644 index 0000000000..118b195248 --- /dev/null +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/ResourceCounterTests.cs @@ -0,0 +1,56 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; +using Xunit; + +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests +{ + public class ResourceCounterTests + { + [Theory] + [InlineData(-1)] + [InlineData(long.MinValue)] + public void QuotaInvalid(long max) + { + Assert.Throws(() => ResourceCounter.Quota(max)); + } + + [Fact] + public void QuotaAcceptsUpToButNotMoreThanMax() + { + var counter = ResourceCounter.Quota(1); + Assert.True(counter.TryLockOne()); + Assert.False(counter.TryLockOne()); + } + + [Theory] + [InlineData(0)] + [InlineData(1)] + [InlineData(10)] + [InlineData(100)] + public void QuotaValid(long max) + { + var counter = ResourceCounter.Quota(max); + Parallel.For(0, max, i => + { + Assert.True(counter.TryLockOne()); + }); + + Parallel.For(0, 10, i => + { + Assert.False(counter.TryLockOne()); + }); + } + + [Fact] + public void QuotaDoesNotWrapAround() + { + var counter = new ResourceCounter.FiniteCounter(long.MaxValue); + counter.Count = long.MaxValue; + Assert.False(counter.TryLockOne()); + } + } +} diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ConnectionLimitTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ConnectionLimitTests.cs new file mode 100644 index 0000000000..64ecf16f56 --- /dev/null +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ConnectionLimitTests.cs @@ -0,0 +1,198 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.IO; +using System.Net.Sockets; +using System.Threading; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Http.Features; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Tests; +using Microsoft.AspNetCore.Testing; +using Xunit; + +namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests +{ + public class ConnectionLimitTests + { + [Fact] + public async Task ResetsCountWhenConnectionClosed() + { + var requestTcs = new TaskCompletionSource(); + var releasedTcs = new TaskCompletionSource(); + var lockedTcs = new TaskCompletionSource(); + var (serviceContext, counter) = SetupMaxConnections(max: 1); + counter.OnLock += (s, e) => lockedTcs.TrySetResult(e); + counter.OnRelease += (s, e) => releasedTcs.TrySetResult(null); + + using (var server = new TestServer(async context => + { + await context.Response.WriteAsync("Hello"); + await requestTcs.Task; + }, serviceContext)) + using (var connection = server.CreateConnection()) + { + await connection.SendEmptyGetAsKeepAlive(); ; + await connection.Receive("HTTP/1.1 200 OK"); + Assert.True(await lockedTcs.Task.TimeoutAfter(TimeSpan.FromSeconds(10))); + requestTcs.TrySetResult(null); + } + + await releasedTcs.Task.TimeoutAfter(TimeSpan.FromSeconds(10)); + } + + [Fact] + public async Task UpgradedConnectionsCountsAgainstDifferentLimit() + { + var (serviceContext, _) = SetupMaxConnections(max: 1); + using (var server = new TestServer(async context => + { + var feature = context.Features.Get(); + if (feature.IsUpgradableRequest) + { + var stream = await feature.UpgradeAsync(); + // keep it running until aborted + while (!context.RequestAborted.IsCancellationRequested) + { + await Task.Delay(100); + } + } + }, serviceContext)) + using (var disposables = new DisposableStack()) + { + var upgraded = server.CreateConnection(); + disposables.Push(upgraded); + + await upgraded.SendEmptyGetWithUpgrade(); + await upgraded.Receive("HTTP/1.1 101"); + // once upgraded, normal connection limit is decreased to allow room for more "normal" connections + + var connection = server.CreateConnection(); + disposables.Push(connection); + + await connection.SendEmptyGetAsKeepAlive(); + await connection.Receive("HTTP/1.1 200 OK"); + + using (var rejected = server.CreateConnection()) + { + try + { + // this may throw IOException, depending on how fast Kestrel closes the socket + await rejected.SendEmptyGetAsKeepAlive(); + } catch { } + + // connection should close without sending any data + await rejected.WaitForConnectionClose().TimeoutAfter(TimeSpan.FromSeconds(15)); + } + } + } + + [Fact] + public async Task RejectsConnectionsWhenLimitReached() + { + const int max = 10; + var (serviceContext, _) = SetupMaxConnections(max); + var requestTcs = new TaskCompletionSource(); + + using (var server = new TestServer(async context => + { + await context.Response.WriteAsync("Hello"); + await requestTcs.Task; + }, serviceContext)) + using (var disposables = new DisposableStack()) + { + for (var i = 0; i < max; i++) + { + var connection = server.CreateConnection(); + disposables.Push(connection); + + await connection.SendEmptyGetAsKeepAlive(); + await connection.Receive("HTTP/1.1 200 OK"); + } + + // limit has been reached + for (var i = 0; i < 10; i++) + { + using (var connection = server.CreateConnection()) + { + try + { + // this may throw IOException, depending on how fast Kestrel closes the socket + await connection.SendEmptyGetAsKeepAlive(); + } catch { } + + // connection should close without sending any data + await connection.WaitForConnectionClose().TimeoutAfter(TimeSpan.FromSeconds(15)); + } + } + + requestTcs.TrySetResult(null); + } + } + + [Fact] + public async Task ConnectionCountingReturnsToZero() + { + const int count = 500; + var opened = 0; + var closed = 0; + var openedTcs = new TaskCompletionSource(); + var closedTcs = new TaskCompletionSource(); + + var (serviceContext, counter) = SetupMaxConnections(uint.MaxValue); + + counter.OnLock += (o, e) => + { + if (e && Interlocked.Increment(ref opened) >= count) + { + openedTcs.TrySetResult(null); + } + }; + + counter.OnRelease += (o, e) => + { + if (Interlocked.Increment(ref closed) >= count) + { + closedTcs.TrySetResult(null); + } + }; + + using (var server = new TestServer(_ => Task.CompletedTask, serviceContext)) + { + // open a bunch of connections in parallel + Parallel.For(0, count, async i => + { + try + { + using (var connection = server.CreateConnection()) + { + await connection.SendEmptyGetAsKeepAlive(); + await connection.Receive("HTTP/1.1 200"); + } + } + catch (Exception ex) + { + closedTcs.TrySetException(ex); + } + }); + + // wait until resource counter has called lock for each connection + await openedTcs.Task.TimeoutAfter(TimeSpan.FromSeconds(60)); + // wait until resource counter has released all normal connections + await closedTcs.Task.TimeoutAfter(TimeSpan.FromSeconds(60)); + Assert.Equal(count, opened); + Assert.Equal(count, closed); + } + } + + private (TestServiceContext serviceContext, EventRaisingResourceCounter counter) SetupMaxConnections(long max) + { + var counter = new EventRaisingResourceCounter(ResourceCounter.Quota(max)); + var serviceContext = new TestServiceContext(); + serviceContext.ConnectionManager = new FrameConnectionManager(serviceContext.Log, counter, ResourceCounter.Unlimited); + return (serviceContext, counter); + } + } +} diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/FrameConnectionManagerTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/FrameConnectionManagerTests.cs index ab292378b0..ac71db8730 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/FrameConnectionManagerTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/FrameConnectionManagerTests.cs @@ -46,10 +46,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { using (var connection = server.CreateConnection()) { - await connection.Send("GET / HTTP/1.1", - "Host:", - "", - ""); + await connection.SendEmptyGet(); Assert.True(await appStartedWh.WaitAsync(TimeSpan.FromSeconds(10))); diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/MaxRequestBufferSizeTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/MaxRequestBufferSizeTests.cs index 698e3bd150..e05d50fc9d 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/MaxRequestBufferSizeTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/MaxRequestBufferSizeTests.cs @@ -55,7 +55,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests Tuple.Create((long?)_dataLength - 1, false), // Buffer is exactly the same size as data. Exposed race condition where - // IConnectionControl.Resume() was called after socket was disconnected. + // the connection was resumed after socket was disconnected. Tuple.Create((long?)_dataLength, false), // Largest possible buffer, should never trigger backpressure. @@ -244,9 +244,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } } - private static IWebHost StartWebHost(long? maxRequestBufferSize, - byte[] expectedBody, - bool useConnectionAdapter, + private static IWebHost StartWebHost(long? maxRequestBufferSize, + byte[] expectedBody, + bool useConnectionAdapter, TaskCompletionSource startReadingRequestBody, TaskCompletionSource clientFinishedSendingRequestBody) { diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs index b8f65c99b9..a5fbc348aa 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs @@ -662,10 +662,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests var buffer = new char[identifierLength]; for (var i = 0; i < iterations; i++) { - await connection.Send("GET / HTTP/1.1", - "Host:", - "", - ""); + await connection.SendEmptyGet(); await connection.Receive($"HTTP/1.1 200 OK", $"Date: {server.Context.DateHeaderValue}", diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/UpgradeTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/UpgradeTests.cs index 3696219f1c..d1d981bed6 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/UpgradeTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/UpgradeTests.cs @@ -6,14 +6,24 @@ using System.IO; using System.Threading.Tasks; using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Server.Kestrel.Core; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Tests; using Microsoft.AspNetCore.Testing; using Microsoft.Extensions.Internal; using Xunit; +using Xunit.Abstractions; namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { public class UpgradeTests { + private readonly ITestOutputHelper _output; + + public UpgradeTests(ITestOutputHelper output) + { + _output = output; + } + [Fact] public async Task ResponseThrowsAfterUpgrade() { @@ -36,11 +46,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { using (var connection = server.CreateConnection()) { - await connection.Send("GET / HTTP/1.1", - "Host:", - "Connection: Upgrade", - "", - ""); + await connection.SendEmptyGetWithUpgrade(); await connection.Receive("HTTP/1.1 101 Switching Protocols", "Connection: Upgrade", $"Date: {server.Context.DateHeaderValue}", @@ -90,11 +96,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { using (var connection = server.CreateConnection()) { - await connection.Send("GET / HTTP/1.1", - "Host:", - "Connection: Upgrade", - "", - ""); + await connection.SendEmptyGetWithUpgrade(); await connection.Receive("HTTP/1.1 101 Switching Protocols", "Connection: Upgrade", @@ -110,6 +112,45 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } } + [Fact] + public async Task UpgradeCannotBeCalledMultipleTimes() + { + var upgradeTcs = new TaskCompletionSource(); + using (var server = new TestServer(async context => + { + var feature = context.Features.Get(); + await feature.UpgradeAsync(); + + try + { + await feature.UpgradeAsync(); + } + catch (Exception e) + { + upgradeTcs.TrySetException(e); + throw; + } + + while (!context.RequestAborted.IsCancellationRequested) + { + await Task.Delay(100); + } + })) + using (var connection = server.CreateConnection()) + { + await connection.SendEmptyGetWithUpgrade(); + await connection.Receive("HTTP/1.1 101 Switching Protocols", + "Connection: Upgrade", + $"Date: {server.Context.DateHeaderValue}", + "", + ""); + await connection.WaitForConnectionClose().TimeoutAfter(TimeSpan.FromSeconds(15)); + } + + var ex = await Assert.ThrowsAsync(async () => await upgradeTcs.Task.TimeoutAfter(TimeSpan.FromSeconds(15))); + Assert.Equal(CoreStrings.UpgradeCannotBeCalledMultipleTimes, ex.Message); + } + [Fact] public async Task RejectsRequestWithContentLengthAndUpgrade() { @@ -151,11 +192,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests using (var connection = server.CreateConnection()) { - await connection.Send("GET / HTTP/1.1", - "Host:", - "Connection: Upgrade", - "", - ""); + await connection.SendEmptyGetWithUpgrade(); await connection.Receive("HTTP/1.1 200 OK"); } } @@ -207,10 +244,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { using (var connection = server.CreateConnection()) { - await connection.Send("GET / HTTP/1.1", - "Host:", - "", - ""); + await connection.SendEmptyGet(); await connection.Receive("HTTP/1.1 200 OK"); } } @@ -218,5 +252,56 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests var ex = await Assert.ThrowsAsync(async () => await upgradeTcs.Task).TimeoutAfter(TimeSpan.FromSeconds(15)); Assert.Equal(CoreStrings.CannotUpgradeNonUpgradableRequest, ex.Message); } + + [Fact] + public async Task RejectsUpgradeWhenLimitReached() + { + const int limit = 10; + var upgradeTcs = new TaskCompletionSource(); + var serviceContext = new TestServiceContext(); + serviceContext.ConnectionManager = new FrameConnectionManager(serviceContext.Log, ResourceCounter.Unlimited, ResourceCounter.Quota(limit)); + + using (var server = new TestServer(async context => + { + var feature = context.Features.Get(); + if (feature.IsUpgradableRequest) + { + try + { + var stream = await feature.UpgradeAsync(); + while (!context.RequestAborted.IsCancellationRequested) + { + await Task.Delay(100); + } + } + catch (InvalidOperationException ex) + { + upgradeTcs.TrySetException(ex); + } + } + }, serviceContext)) + { + using (var disposables = new DisposableStack()) + { + for (var i = 0; i < limit; i++) + { + var connection = server.CreateConnection(); + disposables.Push(connection); + + await connection.SendEmptyGetWithUpgradeAndKeepAlive(); + await connection.Receive("HTTP/1.1 101"); + } + + using (var connection = server.CreateConnection()) + { + await connection.SendEmptyGetWithUpgradeAndKeepAlive(); + await connection.Receive("HTTP/1.1 200"); + } + } + } + + var exception = await Assert.ThrowsAsync(async () => await upgradeTcs.Task.TimeoutAfter(TimeSpan.FromSeconds(60))); + Assert.Equal(CoreStrings.UpgradedConnectionLimitReached, exception.Message); + } } } diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Mocks/MockTimeoutControl.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Mocks/MockTimeoutControl.cs index 3acf5e626c..1f721f07d1 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Mocks/MockTimeoutControl.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Mocks/MockTimeoutControl.cs @@ -1,6 +1,6 @@ -using System; -using System.Collections.Generic; -using System.Text; +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; namespace Microsoft.AspNetCore.Server.Kestrel.Performance.Mocks diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Mocks/MockTrace.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Mocks/MockTrace.cs index 1ab3c8df70..30fb4f3e2f 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Mocks/MockTrace.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Mocks/MockTrace.cs @@ -22,6 +22,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance public void ConnectionReadFin(string connectionId) { } public void ConnectionReset(string connectionId) { } public void ConnectionResume(string connectionId) { } + public void ConnectionRejected(string connectionId) { } public void ConnectionStart(string connectionId) { } public void ConnectionStop(string connectionId) { } public void ConnectionWrite(string connectionId, int count) { } diff --git a/test/shared/DisposableStack.cs b/test/shared/DisposableStack.cs new file mode 100644 index 0000000000..325fc6f8c8 --- /dev/null +++ b/test/shared/DisposableStack.cs @@ -0,0 +1,20 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Collections.Generic; + +namespace Microsoft.AspNetCore.Server.Kestrel.Tests +{ + public class DisposableStack : Stack, IDisposable + where T : IDisposable + { + public void Dispose() + { + while (Count > 0) + { + Pop()?.Dispose(); + } + } + } +} diff --git a/test/shared/EventRaisingResourceCounter.cs b/test/shared/EventRaisingResourceCounter.cs new file mode 100644 index 0000000000..8f7d5efea3 --- /dev/null +++ b/test/shared/EventRaisingResourceCounter.cs @@ -0,0 +1,34 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; + +namespace Microsoft.AspNetCore.Server.Kestrel.Tests +{ + public class EventRaisingResourceCounter : ResourceCounter + { + private readonly ResourceCounter _wrapped; + + public EventRaisingResourceCounter(ResourceCounter wrapped) + { + _wrapped = wrapped; + } + + public event EventHandler OnRelease; + public event EventHandler OnLock; + + public override void ReleaseOne() + { + _wrapped.ReleaseOne(); + OnRelease?.Invoke(this, EventArgs.Empty); + } + + public override bool TryLockOne() + { + var retVal = _wrapped.TryLockOne(); + OnLock?.Invoke(this, retVal); + return retVal; + } + } +} diff --git a/test/shared/TestConnection.cs b/test/shared/TestConnection.cs index bc21df517e..f4ff0a2b62 100644 --- a/test/shared/TestConnection.cs +++ b/test/shared/TestConnection.cs @@ -61,6 +61,32 @@ namespace Microsoft.AspNetCore.Testing } } + public Task SendEmptyGet() + { + return Send("GET / HTTP/1.1", + "Host:", + "", + ""); + } + + public Task SendEmptyGetWithUpgradeAndKeepAlive() + => SendEmptyGetWithConnection("Upgrade, keep-alive"); + + public Task SendEmptyGetWithUpgrade() + => SendEmptyGetWithConnection("Upgrade"); + + public Task SendEmptyGetAsKeepAlive() + => SendEmptyGetWithConnection("keep-alive"); + + private Task SendEmptyGetWithConnection(string connection) + { + return Send("GET / HTTP/1.1", + "Host:", + "Connection: " + connection, + "", + ""); + } + public async Task SendAll(params string[] lines) { var text = string.Join("\r\n", lines); diff --git a/test/shared/TestServiceContext.cs b/test/shared/TestServiceContext.cs index b06362b3fe..9d59a66d44 100644 --- a/test/shared/TestServiceContext.cs +++ b/test/shared/TestServiceContext.cs @@ -28,7 +28,7 @@ namespace Microsoft.AspNetCore.Testing ThreadPool = new LoggingThreadPool(Log); SystemClock = new MockSystemClock(); DateHeaderValueManager = new DateHeaderValueManager(SystemClock); - ConnectionManager = new FrameConnectionManager(Log); + ConnectionManager = new FrameConnectionManager(Log, ResourceCounter.Unlimited, ResourceCounter.Unlimited); DateHeaderValue = DateHeaderValueManager.GetDateHeaderValues().String; HttpParserFactory = frameAdapter => new HttpParser(frameAdapter.Frame.ServiceContext.Log.IsEnabled(LogLevel.Information)); ServerOptions = new KestrelServerOptions From 402f979c1ccd4074823e381c3f294dd9361de355 Mon Sep 17 00:00:00 2001 From: Kiran Challa Date: Fri, 26 May 2017 12:41:53 -0700 Subject: [PATCH 1305/1662] Updated to use the latest shared runtime --- build/dependencies.props | 1 + 1 file changed, 1 insertion(+) diff --git a/build/dependencies.props b/build/dependencies.props index 401361784f..138ac50629 100644 --- a/build/dependencies.props +++ b/build/dependencies.props @@ -7,6 +7,7 @@ 9.0.1 4.7.1 2.0.0-* + 2.0.0-* 15.3.0-* 2.3.0-beta2-* From 402b337178cb35a07f65fae28a7b73036586dd4e Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Tue, 30 May 2017 12:47:36 -0700 Subject: [PATCH 1306/1662] Temporary workaround for GenerateResource task error on VS. --- .../Microsoft.AspNetCore.Server.Kestrel.Core.csproj | 2 ++ .../Microsoft.AspNetCore.Server.Kestrel.Https.csproj | 2 ++ ...Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.csproj | 2 ++ 3 files changed, 6 insertions(+) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Microsoft.AspNetCore.Server.Kestrel.Core.csproj b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Microsoft.AspNetCore.Server.Kestrel.Core.csproj index a5a3ceb117..2565c8cfb8 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Microsoft.AspNetCore.Server.Kestrel.Core.csproj +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Microsoft.AspNetCore.Server.Kestrel.Core.csproj @@ -10,6 +10,8 @@ true CS1591;$(NoWarn) false + + CurrentRuntime diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Https/Microsoft.AspNetCore.Server.Kestrel.Https.csproj b/src/Microsoft.AspNetCore.Server.Kestrel.Https/Microsoft.AspNetCore.Server.Kestrel.Https.csproj index 3631a1bd62..a9d552dc1b 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Https/Microsoft.AspNetCore.Server.Kestrel.Https.csproj +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Https/Microsoft.AspNetCore.Server.Kestrel.Https.csproj @@ -9,6 +9,8 @@ aspnetcore;kestrel CS1591;$(NoWarn) false + + CurrentRuntime diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.csproj b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.csproj index eefdfe2be4..eb63e0c381 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.csproj +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.csproj @@ -10,6 +10,8 @@ true CS1591;$(NoWarn) false + + CurrentRuntime From a334e885972e714eedd289c71e77573e6550485b Mon Sep 17 00:00:00 2001 From: Nate McMaster Date: Tue, 30 May 2017 14:16:07 -0700 Subject: [PATCH 1307/1662] Decrease connections used in ConnectionCountingReturnsToZero for slow test agents (#1872) --- .../ConnectionLimitTests.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ConnectionLimitTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ConnectionLimitTests.cs index 64ecf16f56..ffcde60a9d 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ConnectionLimitTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ConnectionLimitTests.cs @@ -135,7 +135,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [Fact] public async Task ConnectionCountingReturnsToZero() { - const int count = 500; + const int count = 100; var opened = 0; var closed = 0; var openedTcs = new TaskCompletionSource(); @@ -179,9 +179,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests }); // wait until resource counter has called lock for each connection - await openedTcs.Task.TimeoutAfter(TimeSpan.FromSeconds(60)); + await openedTcs.Task.TimeoutAfter(TimeSpan.FromSeconds(120)); // wait until resource counter has released all normal connections - await closedTcs.Task.TimeoutAfter(TimeSpan.FromSeconds(60)); + await closedTcs.Task.TimeoutAfter(TimeSpan.FromSeconds(120)); Assert.Equal(count, opened); Assert.Equal(count, closed); } From 8dc93a02339876dfae5a30e2ead274dff5d2bf2d Mon Sep 17 00:00:00 2001 From: Pranav K Date: Wed, 31 May 2017 19:36:51 -0700 Subject: [PATCH 1308/1662] Branching for rel/2.0.0-preview2 --- NuGet.config | 5 +++-- build/dependencies.props | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/NuGet.config b/NuGet.config index 93f1ac47df..c4bc056c4d 100644 --- a/NuGet.config +++ b/NuGet.config @@ -1,8 +1,9 @@  - + + - + \ No newline at end of file diff --git a/build/dependencies.props b/build/dependencies.props index 138ac50629..f482bbc6ca 100644 --- a/build/dependencies.props +++ b/build/dependencies.props @@ -1,6 +1,6 @@ - 2.0.0-* + 2.0.0-preview2-* 4.4.0-* 2.1.0-* 1.10.0-* From 69b4100bbcfa75eb9a0e9ac54b3dd3d1881b6713 Mon Sep 17 00:00:00 2001 From: Pranav K Date: Wed, 31 May 2017 19:53:24 -0700 Subject: [PATCH 1309/1662] Updating build scripts to point to 2.0.0-preview2 KoreBuild --- build.ps1 | 2 +- build.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/build.ps1 b/build.ps1 index 5bf0e2c113..3a2476b2b4 100644 --- a/build.ps1 +++ b/build.ps1 @@ -33,7 +33,7 @@ cd $PSScriptRoot $repoFolder = $PSScriptRoot $env:REPO_FOLDER = $repoFolder -$koreBuildZip="https://github.com/aspnet/KoreBuild/archive/dev.zip" +$koreBuildZip="https://github.com/aspnet/KoreBuild/archive/rel/2.0.0-preview2.zip" if ($env:KOREBUILD_ZIP) { $koreBuildZip=$env:KOREBUILD_ZIP diff --git a/build.sh b/build.sh index b0bcadb579..a40bdb87b1 100755 --- a/build.sh +++ b/build.sh @@ -2,7 +2,7 @@ repoFolder="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" cd $repoFolder -koreBuildZip="https://github.com/aspnet/KoreBuild/archive/dev.zip" +koreBuildZip="https://github.com/aspnet/KoreBuild/archive/rel/2.0.0-preview2.zip" if [ ! -z $KOREBUILD_ZIP ]; then koreBuildZip=$KOREBUILD_ZIP fi From c923ba3228f34c777b0d69b2aaa85e7aecd3118b Mon Sep 17 00:00:00 2001 From: Pranav K Date: Thu, 1 Jun 2017 10:47:16 -0700 Subject: [PATCH 1310/1662] Updating versions to preview3 --- NuGet.config | 1 + version.props | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/NuGet.config b/NuGet.config index 93f1ac47df..4e8a1f6de1 100644 --- a/NuGet.config +++ b/NuGet.config @@ -1,6 +1,7 @@  + diff --git a/version.props b/version.props index f29a32b5bf..11ac1d7f41 100644 --- a/version.props +++ b/version.props @@ -2,6 +2,6 @@ 2.0.0 - preview2 + preview3 From 3c731ceb1350d1049355d608640b08165f1a0154 Mon Sep 17 00:00:00 2001 From: Pavel Krymets Date: Fri, 2 Jun 2017 08:34:22 -0700 Subject: [PATCH 1311/1662] React to logging in DI changes (#1873) --- KestrelHttpServer.sln | 4 +- .../KestrelServerTests.cs | 2 +- ...spNetCore.Server.Kestrel.Core.Tests.csproj | 1 + .../AddressRegistrationTests.cs | 29 +++++----- .../FrameConnectionManagerTests.cs | 3 +- .../HttpsTests.cs | 56 +++++++++---------- ...erver.Kestrel.Transport.Libuv.Tests.csproj | 1 + ...actory.cs => KestrelTestLoggerProvider.cs} | 11 +--- test/shared/TestServiceContext.cs | 2 +- 9 files changed, 53 insertions(+), 56 deletions(-) rename test/shared/{KestrelTestLoggerFactory.cs => KestrelTestLoggerProvider.cs} (69%) diff --git a/KestrelHttpServer.sln b/KestrelHttpServer.sln index 2b528d0f1b..b5b6dc71f3 100644 --- a/KestrelHttpServer.sln +++ b/KestrelHttpServer.sln @@ -1,6 +1,6 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 15 -VisualStudioVersion = 15.0.26403.7 +VisualStudioVersion = 15.0.26510.0 MinimumVisualStudioVersion = 10.0.40219.1 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{7972A5D6-3385-4127-9277-428506DD44FF}" ProjectSection(SolutionItems) = preProject @@ -22,7 +22,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "shared", "shared", "{0EF2AC test\shared\DummyApplication.cs = test\shared\DummyApplication.cs test\shared\HttpClientSlim.cs = test\shared\HttpClientSlim.cs test\shared\HttpParsingData.cs = test\shared\HttpParsingData.cs - test\shared\KestrelTestLoggerFactory.cs = test\shared\KestrelTestLoggerFactory.cs + test\shared\KestrelTestLoggerProvider.cs = test\shared\KestrelTestLoggerProvider.cs test\shared\LifetimeNotImplemented.cs = test\shared\LifetimeNotImplemented.cs test\shared\MockConnectionInformation.cs = test\shared\MockConnectionInformation.cs test\shared\MockFrameControl.cs = test\shared\MockFrameControl.cs diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/KestrelServerTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/KestrelServerTests.cs index 75ab8a3dbb..a61feba7bc 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/KestrelServerTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/KestrelServerTests.cs @@ -156,7 +156,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests private static KestrelServer CreateServer(KestrelServerOptions options, ILogger testLogger) { - return new KestrelServer(Options.Create(options), new MockTransportFactory(), new KestrelTestLoggerFactory(testLogger)); + return new KestrelServer(Options.Create(options), new MockTransportFactory(), new LoggerFactory(new [] { new KestrelTestLoggerProvider(testLogger)} )); } private static void StartDummyApplication(IServer server) diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/Microsoft.AspNetCore.Server.Kestrel.Core.Tests.csproj b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/Microsoft.AspNetCore.Server.Kestrel.Core.Tests.csproj index fb273003e7..fba2976f4e 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/Microsoft.AspNetCore.Server.Kestrel.Core.Tests.csproj +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/Microsoft.AspNetCore.Server.Kestrel.Core.Tests.csproj @@ -26,6 +26,7 @@ + diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs index 38ea0f1933..35a472a0db 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs @@ -19,6 +19,7 @@ using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; using Microsoft.AspNetCore.Testing; using Microsoft.AspNetCore.Testing.xunit; +using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using Xunit; @@ -31,9 +32,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { private const int MaxRetries = 10; - private readonly ILoggerFactory _loggerFactory; + private readonly Action _configureLoggingDelegate; - public AddressRegistrationTests(ITestOutputHelper output) => _loggerFactory = new LoggerFactory().AddXunit(output); + public AddressRegistrationTests(ITestOutputHelper output) => _configureLoggingDelegate = builder => builder.AddXunit(output); [ConditionalFact] [NetworkIsReachable] @@ -161,7 +162,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { var hostBuilder = new WebHostBuilder() .UseKestrel() - .UseLoggerFactory(_loggerFactory) + .ConfigureLogging(_configureLoggingDelegate) .UseUrls(addressInput) .Configure(ConfigureEchoAddress); @@ -220,7 +221,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests private async Task RegisterIPEndPoint_Success(IPEndPoint endPoint, string testUrl, int testPort = 0) { var hostBuilder = new WebHostBuilder() - .UseLoggerFactory(_loggerFactory) + .ConfigureLogging(_configureLoggingDelegate) .UseKestrel(options => { options.Listen(endPoint, listenOptions => @@ -301,9 +302,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests var testLogger = new TestApplicationErrorLogger(); var hostBuilder = new WebHostBuilder() - .UseLoggerFactory(_loggerFactory) + .ConfigureLogging(_configureLoggingDelegate) .UseKestrel() - .UseLoggerFactory(_ => new KestrelTestLoggerFactory(testLogger)) + .ConfigureLogging(builder => builder + .AddProvider(new KestrelTestLoggerProvider(testLogger)) + .SetMinimumLevel(LogLevel.Debug)) .Configure(ConfigureEchoAddress); using (var host = hostBuilder.Build()) @@ -331,7 +334,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests var port = ((IPEndPoint)socket.LocalEndPoint).Port; var hostBuilder = new WebHostBuilder() - .UseLoggerFactory(_loggerFactory) + .ConfigureLogging(_configureLoggingDelegate) .UseKestrel() .UseUrls($"http://127.0.0.1:{port}") .Configure(ConfigureEchoAddress); @@ -354,7 +357,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests var port = ((IPEndPoint)socket.LocalEndPoint).Port; var hostBuilder = new WebHostBuilder() - .UseLoggerFactory(_loggerFactory) + .ConfigureLogging(_configureLoggingDelegate) .UseKestrel() .UseUrls($"http://[::1]:{port}") .Configure(ConfigureEchoAddress); @@ -382,7 +385,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests }) .UseUrls(useUrlsAddress) .PreferHostingUrls(true) - .UseLoggerFactory(_ => new KestrelTestLoggerFactory(testLogger)) + .ConfigureLogging(builder => builder.AddProvider(new KestrelTestLoggerProvider(testLogger))) .Configure(ConfigureEchoAddress); using (var host = hostBuilder.Build()) @@ -412,7 +415,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests var useUrlsAddress = $"http://127.0.0.1:0"; var testLogger = new TestApplicationErrorLogger(); var hostBuilder = new WebHostBuilder() - .UseLoggerFactory(_loggerFactory) + .ConfigureLogging(_configureLoggingDelegate) .UseKestrel(options => { options.Listen(new IPEndPoint(IPAddress.Loopback, 0), listenOptions => @@ -422,7 +425,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests }) .UseUrls($"http://127.0.0.1:0") .PreferHostingUrls(false) - .UseLoggerFactory(_ => new KestrelTestLoggerFactory(testLogger)) + .ConfigureLogging(builder => builder.AddProvider(new KestrelTestLoggerProvider(testLogger))) .Configure(ConfigureEchoAddress); using (var host = hostBuilder.Build()) @@ -450,7 +453,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests public async Task DoesNotOverrideDirectConfigurationWithIServerAddressesFeature_IfAddressesEmpty() { var hostBuilder = new WebHostBuilder() - .UseLoggerFactory(_loggerFactory) + .ConfigureLogging(_configureLoggingDelegate) .UseKestrel(options => { options.Listen(new IPEndPoint(IPAddress.Loopback, 0), listenOptions => @@ -528,7 +531,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests var port = ((IPEndPoint)socket.LocalEndPoint).Port; var hostBuilder = new WebHostBuilder() - .UseLoggerFactory(_loggerFactory) + .ConfigureLogging(_configureLoggingDelegate) .UseKestrel() .UseUrls($"http://localhost:{port}") .Configure(ConfigureEchoAddress); diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/FrameConnectionManagerTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/FrameConnectionManagerTests.cs index ac71db8730..0e71450a5e 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/FrameConnectionManagerTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/FrameConnectionManagerTests.cs @@ -8,6 +8,7 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; using Microsoft.AspNetCore.Testing; using Microsoft.AspNetCore.Testing.xunit; +using Microsoft.Extensions.Logging; using Moq; using Xunit; @@ -42,7 +43,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests var tcs = new TaskCompletionSource(); return tcs.Task; }, - new TestServiceContext(new KestrelTestLoggerFactory(), mockTrace.Object))) + new TestServiceContext(new LoggerFactory(), mockTrace.Object))) { using (var connection = server.CreateConnection()) { diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/HttpsTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/HttpsTests.cs index 01987f3464..fcb67652cc 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/HttpsTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/HttpsTests.cs @@ -11,6 +11,7 @@ using System.Security.Cryptography.X509Certificates; using System.Text; using System.Threading.Tasks; using Microsoft.AspNetCore.Builder; +using Microsoft.Extensions.DependencyInjection; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Server.Kestrel.Https; @@ -26,7 +27,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [Fact] public async Task EmptyRequestLoggedAsInformation() { - var loggerFactory = new HandshakeErrorLoggerFactory(); + var loggerProvider = new HandshakeErrorLoggerProvider(); var hostBuilder = new WebHostBuilder() .UseKestrel(options => @@ -36,7 +37,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests listenOptions.UseHttps(TestResources.TestCertificatePath, "testPassword"); }); }) - .UseLoggerFactory(loggerFactory) + .ConfigureLogging(builder => builder.AddProvider(loggerProvider)) .Configure(app => { }); using (var host = hostBuilder.Build()) @@ -48,19 +49,19 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests // Close socket immediately } - await loggerFactory.FilterLogger.LogTcs.Task.TimeoutAfter(TimeSpan.FromSeconds(10)); + await loggerProvider.FilterLogger.LogTcs.Task.TimeoutAfter(TimeSpan.FromSeconds(10)); } - Assert.Equal(1, loggerFactory.FilterLogger.LastEventId.Id); - Assert.Equal(LogLevel.Information, loggerFactory.FilterLogger.LastLogLevel); - Assert.True(loggerFactory.ErrorLogger.TotalErrorsLogged == 0, - userMessage: string.Join(Environment.NewLine, loggerFactory.ErrorLogger.ErrorMessages)); + Assert.Equal(1, loggerProvider.FilterLogger.LastEventId.Id); + Assert.Equal(LogLevel.Information, loggerProvider.FilterLogger.LastLogLevel); + Assert.True(loggerProvider.ErrorLogger.TotalErrorsLogged == 0, + userMessage: string.Join(Environment.NewLine, loggerProvider.ErrorLogger.ErrorMessages)); } [Fact] public async Task ClientHandshakeFailureLoggedAsInformation() { - var loggerFactory = new HandshakeErrorLoggerFactory(); + var loggerProvider = new HandshakeErrorLoggerProvider(); var hostBuilder = new WebHostBuilder() .UseKestrel(options => @@ -70,7 +71,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests listenOptions.UseHttps(TestResources.TestCertificatePath, "testPassword"); }); }) - .UseLoggerFactory(loggerFactory) + .ConfigureLogging(builder => builder.AddProvider(loggerProvider)) .Configure(app => { }); using (var host = hostBuilder.Build()) @@ -84,20 +85,20 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests await stream.WriteAsync(new byte[10], 0, 10); } - await loggerFactory.FilterLogger.LogTcs.Task.TimeoutAfter(TimeSpan.FromSeconds(10)); + await loggerProvider.FilterLogger.LogTcs.Task.TimeoutAfter(TimeSpan.FromSeconds(10)); } - Assert.Equal(1, loggerFactory.FilterLogger.LastEventId.Id); - Assert.Equal(LogLevel.Information, loggerFactory.FilterLogger.LastLogLevel); - Assert.True(loggerFactory.ErrorLogger.TotalErrorsLogged == 0, - userMessage: string.Join(Environment.NewLine, loggerFactory.ErrorLogger.ErrorMessages)); + Assert.Equal(1, loggerProvider.FilterLogger.LastEventId.Id); + Assert.Equal(LogLevel.Information, loggerProvider.FilterLogger.LastLogLevel); + Assert.True(loggerProvider.ErrorLogger.TotalErrorsLogged == 0, + userMessage: string.Join(Environment.NewLine, loggerProvider.ErrorLogger.ErrorMessages)); } // Regression test for https://github.com/aspnet/KestrelHttpServer/issues/1103#issuecomment-246971172 [Fact] public async Task DoesNotThrowObjectDisposedExceptionOnConnectionAbort() { - var loggerFactory = new HandshakeErrorLoggerFactory(); + var loggerProvider = new HandshakeErrorLoggerProvider(); var hostBuilder = new WebHostBuilder() .UseKestrel(options => { @@ -106,7 +107,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests listenOptions.UseHttps(TestResources.TestCertificatePath, "testPassword"); }); }) - .UseLoggerFactory(loggerFactory) + .ConfigureLogging(builder => builder.AddProvider(loggerProvider)) .Configure(app => app.Run(async httpContext => { var ct = httpContext.RequestAborted; @@ -142,14 +143,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } } - Assert.False(loggerFactory.ErrorLogger.ObjectDisposedExceptionLogged); + Assert.False(loggerProvider.ErrorLogger.ObjectDisposedExceptionLogged); } [Fact] public async Task DoesNotThrowObjectDisposedExceptionFromWriteAsyncAfterConnectionIsAborted() { var tcs = new TaskCompletionSource(); - var loggerFactory = new HandshakeErrorLoggerFactory(); + var loggerProvider = new HandshakeErrorLoggerProvider(); var hostBuilder = new WebHostBuilder() .UseKestrel(options => { @@ -158,7 +159,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests listenOptions.UseHttps(TestResources.TestCertificatePath, "testPassword"); }); }) - .UseLoggerFactory(loggerFactory) + .ConfigureLogging(builder => builder.AddProvider(loggerProvider)) .Configure(app => app.Run(async httpContext => { httpContext.Abort(); @@ -198,7 +199,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [Fact] public async Task DoesNotThrowObjectDisposedExceptionOnEmptyConnection() { - var loggerFactory = new HandshakeErrorLoggerFactory(); + var loggerProvider = new HandshakeErrorLoggerProvider(); var hostBuilder = new WebHostBuilder() .UseKestrel(options => { @@ -207,7 +208,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests listenOptions.UseHttps(TestResources.TestCertificatePath, "testPassword"); }); }) - .UseLoggerFactory(loggerFactory) + .ConfigureLogging(builder => builder.AddProvider(loggerProvider)) .Configure(app => app.Run(httpContext => Task.CompletedTask)); using (var host = hostBuilder.Build()) @@ -224,14 +225,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } } - Assert.False(loggerFactory.ErrorLogger.ObjectDisposedExceptionLogged); + Assert.False(loggerProvider.ErrorLogger.ObjectDisposedExceptionLogged); } // Regression test for https://github.com/aspnet/KestrelHttpServer/pull/1197 [Fact] public void ConnectionFilterDoesNotLeakBlock() { - var loggerFactory = new HandshakeErrorLoggerFactory(); + var loggerProvider = new HandshakeErrorLoggerProvider(); var hostBuilder = new WebHostBuilder() .UseKestrel(options => @@ -241,7 +242,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests listenOptions.UseHttps(TestResources.TestCertificatePath, "testPassword"); }); }) - .UseLoggerFactory(loggerFactory) + .ConfigureLogging(builder => builder.AddProvider(loggerProvider)) .Configure(app => { }); using (var host = hostBuilder.Build()) @@ -258,7 +259,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } } - private class HandshakeErrorLoggerFactory : ILoggerFactory + private class HandshakeErrorLoggerProvider : ILoggerProvider { public HttpsConnectionFilterLogger FilterLogger { get; } = new HttpsConnectionFilterLogger(); public ApplicationErrorLogger ErrorLogger { get; } = new ApplicationErrorLogger(); @@ -275,11 +276,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } } - public void AddProvider(ILoggerProvider provider) - { - throw new NotImplementedException(); - } - public void Dispose() { } diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests.csproj b/test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests.csproj index 9fd8124c11..d6e8bf6ba9 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests.csproj +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests.csproj @@ -27,6 +27,7 @@ + diff --git a/test/shared/KestrelTestLoggerFactory.cs b/test/shared/KestrelTestLoggerProvider.cs similarity index 69% rename from test/shared/KestrelTestLoggerFactory.cs rename to test/shared/KestrelTestLoggerProvider.cs index 80a94b0d1a..45462791d1 100644 --- a/test/shared/KestrelTestLoggerFactory.cs +++ b/test/shared/KestrelTestLoggerProvider.cs @@ -6,16 +6,16 @@ using Microsoft.Extensions.Logging; namespace Microsoft.AspNetCore.Testing { - public class KestrelTestLoggerFactory : ILoggerFactory + public class KestrelTestLoggerProvider : ILoggerProvider { private readonly ILogger _testLogger; - public KestrelTestLoggerFactory() + public KestrelTestLoggerProvider() : this(new TestApplicationErrorLogger()) { } - public KestrelTestLoggerFactory(ILogger testLogger) + public KestrelTestLoggerProvider(ILogger testLogger) { _testLogger = testLogger; } @@ -25,11 +25,6 @@ namespace Microsoft.AspNetCore.Testing return _testLogger; } - public void AddProvider(ILoggerProvider provider) - { - throw new NotImplementedException(); - } - public void Dispose() { throw new NotImplementedException(); diff --git a/test/shared/TestServiceContext.cs b/test/shared/TestServiceContext.cs index 9d59a66d44..5f4b572047 100644 --- a/test/shared/TestServiceContext.cs +++ b/test/shared/TestServiceContext.cs @@ -12,7 +12,7 @@ namespace Microsoft.AspNetCore.Testing public class TestServiceContext : ServiceContext { public TestServiceContext() - : this(new KestrelTestLoggerFactory()) + : this(new LoggerFactory(new[] { new KestrelTestLoggerProvider() })) { } From c6e228d1768c96f8a416f1e4886af3ef18eb1b17 Mon Sep 17 00:00:00 2001 From: Chris R Date: Thu, 1 Jun 2017 08:51:12 -0700 Subject: [PATCH 1312/1662] #1875 Add Configuration support and tests. --- KestrelHttpServer.sln | 10 ++ .../ConfigureDefaultKestrelServerOptions.cs | 116 +++++++++++++ .../KestrelStrings.resx | 135 ++++++++++++++++ ...Microsoft.AspNetCore.Server.Kestrel.csproj | 5 +- .../Properties/KestrelStrings.Designer.cs | 100 ++++++++++++ .../WebHostBuilderKestrelExtensions.cs | 5 + .../ConfigurationTests.cs | 153 ++++++++++++++++++ 7 files changed, 523 insertions(+), 1 deletion(-) create mode 100644 src/Microsoft.AspNetCore.Server.Kestrel/Internal/ConfigureDefaultKestrelServerOptions.cs create mode 100644 src/Microsoft.AspNetCore.Server.Kestrel/KestrelStrings.resx create mode 100644 src/Microsoft.AspNetCore.Server.Kestrel/Properties/KestrelStrings.Designer.cs create mode 100644 test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ConfigurationTests.cs diff --git a/KestrelHttpServer.sln b/KestrelHttpServer.sln index b5b6dc71f3..d907c16aee 100644 --- a/KestrelHttpServer.sln +++ b/KestrelHttpServer.sln @@ -71,6 +71,15 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Server EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Server.Kestrel.Tests", "test\Microsoft.AspNetCore.Server.Kestrel.Tests\Microsoft.AspNetCore.Server.Kestrel.Tests.csproj", "{4F1C30F8-CCAA-48D7-9DF6-2A84021F5BCC}" EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "build", "build", "{FD3692F8-F5C7-49A5-8D69-29F8A87A9DB7}" + ProjectSection(SolutionItems) = preProject + build\common.props = build\common.props + build\dependencies.props = build\dependencies.props + build\Key.snk = build\Key.snk + build\repo.props = build\repo.props + build\repo.targets = build\repo.targets + EndProjectSection +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -270,5 +279,6 @@ Global {2E9CB89D-EC8F-4DD9-A72B-08D5BABF752D} = {2D5D5227-4DBD-499A-96B1-76A36B03B750} {D95A7EC3-48AC-4D03-B2E2-0DA3E13BD3A4} = {D3273454-EA07-41D2-BF0B-FCC3675C2483} {4F1C30F8-CCAA-48D7-9DF6-2A84021F5BCC} = {D3273454-EA07-41D2-BF0B-FCC3675C2483} + {FD3692F8-F5C7-49A5-8D69-29F8A87A9DB7} = {7972A5D6-3385-4127-9277-428506DD44FF} EndGlobalSection EndGlobal diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/ConfigureDefaultKestrelServerOptions.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/ConfigureDefaultKestrelServerOptions.cs new file mode 100644 index 0000000000..02e1f0d561 --- /dev/null +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/ConfigureDefaultKestrelServerOptions.cs @@ -0,0 +1,116 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net; +using System.Security.Cryptography.X509Certificates; +using Microsoft.AspNetCore.Certificates.Configuration; +using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Server.Kestrel.Core; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Options; +using Microsoft.Extensions.Options.Infrastructure; + +namespace Microsoft.AspNetCore.Server.Kestrel.Internal +{ + public class ConfigureDefaultKestrelServerOptions : ConfigureDefaultOptions + { + private const string DefaultCertificateSubjectName = "CN=localhost"; + private const string DevelopmentSSLCertificateName = "localhost"; + + private readonly IServiceProvider _services; + private readonly IHostingEnvironment _hostingEnvironment; + private readonly IConfiguration _configurationRoot; + private readonly ILoggerFactory _loggerFactory; + + public ConfigureDefaultKestrelServerOptions( + IServiceProvider services, + IHostingEnvironment hostingEnvironment, + IConfiguration configurationRoot, + ILoggerFactory loggerFactory) + { + _services = services; + _hostingEnvironment = hostingEnvironment; + _configurationRoot = configurationRoot; + _loggerFactory = loggerFactory; + } + + public override void Configure(string name, KestrelServerOptions options) + { + // Don't assume KestrelServerOptionsSetup has already set the services. Needed for UseHttps. + options.ApplicationServices = _services; + BindConfiguration(options); + } + + private void BindConfiguration(KestrelServerOptions options) + { + var certificateLoader = new CertificateLoader(_configurationRoot.GetSection("Certificates"), _loggerFactory, _hostingEnvironment.EnvironmentName); + + foreach (var endPoint in _configurationRoot.GetSection("Microsoft:AspNetCore:Server:Kestrel:EndPoints").GetChildren()) + { + BindEndPoint(options, endPoint, certificateLoader); + } + } + + private void BindEndPoint( + KestrelServerOptions options, + IConfigurationSection endPoint, + CertificateLoader certificateLoader) + { + var configAddress = endPoint.GetValue("Address"); + var configPort = endPoint.GetValue("Port"); + + if (!IPAddress.TryParse(configAddress, out var address)) + { + throw new InvalidOperationException(KestrelStrings.FormatInvalidIp(configAddress)); + } + + if (!int.TryParse(configPort, out var port)) + { + throw new InvalidOperationException(KestrelStrings.FormatInvalidPort(configPort)); + } + + options.Listen(address, port, listenOptions => + { + var certificateConfig = endPoint.GetSection("Certificate"); + X509Certificate2 certificate = null; + if (certificateConfig.Exists()) + { + try + { + try + { + certificate = certificateLoader.Load(certificateConfig).FirstOrDefault(); + } + catch (KeyNotFoundException) when (certificateConfig.Value.Equals(DevelopmentSSLCertificateName, StringComparison.Ordinal) && _hostingEnvironment.IsDevelopment()) + { + var storeLoader = new CertificateStoreLoader(); + certificate = storeLoader.Load(DefaultCertificateSubjectName, "My", StoreLocation.CurrentUser, validOnly: false) ?? + storeLoader.Load(DefaultCertificateSubjectName, "My", StoreLocation.LocalMachine, validOnly: false); + + if (certificate == null) + { + var logger = _loggerFactory.CreateLogger("Microsoft.AspNetCore.Server.Kestrel.KestrelServerConfigureOptions"); + logger.LogError(KestrelStrings.NoCertFoundLog); + } + } + + if (certificate == null) + { + throw new InvalidOperationException(KestrelStrings.FormatNoCertForEndpoint(endPoint.Key)); + } + } + catch (Exception ex) + { + throw new InvalidOperationException(KestrelStrings.UnableToConfigureHttps, ex); + } + + listenOptions.UseHttps(certificate); + } + }); + } + } +} diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/KestrelStrings.resx b/src/Microsoft.AspNetCore.Server.Kestrel/KestrelStrings.resx new file mode 100644 index 0000000000..bf5c93410c --- /dev/null +++ b/src/Microsoft.AspNetCore.Server.Kestrel/KestrelStrings.resx @@ -0,0 +1,135 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + Invalid IP address in configuration: {configAddress}. + + + Invalid port in configuration: {configPort}. + + + No certificate found for endpoint {endPoint}. + + + Unable to configure HTTPS endpoint. For information on configuring HTTPS see https://go.microsoft.com/fwlink/?linkid=848054. + + + No HTTPS certificate was found for development. For information on configuring HTTPS see https://go.microsoft.com/fwlink/?linkid=848054. + + \ No newline at end of file diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Microsoft.AspNetCore.Server.Kestrel.csproj b/src/Microsoft.AspNetCore.Server.Kestrel/Microsoft.AspNetCore.Server.Kestrel.csproj index 616830814d..fbaa34e0b7 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Microsoft.AspNetCore.Server.Kestrel.csproj +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Microsoft.AspNetCore.Server.Kestrel.csproj @@ -4,7 +4,7 @@ ASP.NET Core Kestrel cross-platform web server. - netstandard2.0 + netstandard2.0;netcoreapp2.0 true aspnetcore;kestrel CS1591;$(NoWarn) @@ -12,11 +12,14 @@ + + + diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Properties/KestrelStrings.Designer.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Properties/KestrelStrings.Designer.cs new file mode 100644 index 0000000000..ee0b31857d --- /dev/null +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Properties/KestrelStrings.Designer.cs @@ -0,0 +1,100 @@ +// +namespace Microsoft.AspNetCore.Server.Kestrel +{ + using System.Globalization; + using System.Reflection; + using System.Resources; + + internal static class KestrelStrings + { + private static readonly ResourceManager _resourceManager + = new ResourceManager("Microsoft.AspNetCore.Server.Kestrel.KestrelStrings", typeof(KestrelStrings).GetTypeInfo().Assembly); + + /// + /// Invalid IP address in configuration: {configAddress}. + /// + internal static string InvalidIp + { + get => GetString("InvalidIp"); + } + + /// + /// Invalid IP address in configuration: {configAddress}. + /// + internal static string FormatInvalidIp(object configAddress) + => string.Format(CultureInfo.CurrentCulture, GetString("InvalidIp", "configAddress"), configAddress); + + /// + /// Invalid port in configuration: {configPort}. + /// + internal static string InvalidPort + { + get => GetString("InvalidPort"); + } + + /// + /// Invalid port in configuration: {configPort}. + /// + internal static string FormatInvalidPort(object configPort) + => string.Format(CultureInfo.CurrentCulture, GetString("InvalidPort", "configPort"), configPort); + + /// + /// No certificate found for endpoint {endPoint}. + /// + internal static string NoCertForEndpoint + { + get => GetString("NoCertForEndpoint"); + } + + /// + /// No certificate found for endpoint {endPoint}. + /// + internal static string FormatNoCertForEndpoint(object endPoint) + => string.Format(CultureInfo.CurrentCulture, GetString("NoCertForEndpoint", "endPoint"), endPoint); + + /// + /// Unable to configure HTTPS endpoint. For information on configuring HTTPS see https://go.microsoft.com/fwlink/?linkid=848054. + /// + internal static string UnableToConfigureHttps + { + get => GetString("UnableToConfigureHttps"); + } + + /// + /// Unable to configure HTTPS endpoint. For information on configuring HTTPS see https://go.microsoft.com/fwlink/?linkid=848054. + /// + internal static string FormatUnableToConfigureHttps() + => GetString("UnableToConfigureHttps"); + + /// + /// No HTTPS certificate was found for development. For information on configuring HTTPS see https://go.microsoft.com/fwlink/?linkid=848054. + /// + internal static string NoCertFoundLog + { + get => GetString("NoCertFoundLog"); + } + + /// + /// No HTTPS certificate was found for development. For information on configuring HTTPS see https://go.microsoft.com/fwlink/?linkid=848054. + /// + internal static string FormatNoCertFoundLog() + => GetString("NoCertFoundLog"); + + private static string GetString(string name, params string[] formatterNames) + { + var value = _resourceManager.GetString(name); + + System.Diagnostics.Debug.Assert(value != null); + + if (formatterNames != null) + { + for (var i = 0; i < formatterNames.Length; i++) + { + value = value.Replace("{" + formatterNames[i] + "}", "{" + i + "}"); + } + } + + return value; + } + } +} diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/WebHostBuilderKestrelExtensions.cs b/src/Microsoft.AspNetCore.Server.Kestrel/WebHostBuilderKestrelExtensions.cs index 3d3dad73cb..0823e62db1 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/WebHostBuilderKestrelExtensions.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/WebHostBuilderKestrelExtensions.cs @@ -3,10 +3,12 @@ using System; using Microsoft.AspNetCore.Hosting.Server; +using Microsoft.AspNetCore.Server.Kestrel.Internal; using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Options; +using Microsoft.Extensions.Options.Infrastructure; namespace Microsoft.AspNetCore.Hosting { @@ -28,6 +30,9 @@ namespace Microsoft.AspNetCore.Hosting return hostBuilder.ConfigureServices(services => { services.AddTransient, KestrelServerOptionsSetup>(); + // https://github.com/aspnet/DependencyInjection/issues/500 + services.AddTransient, ConfigureDefaults>(); + services.AddTransient, ConfigureDefaultKestrelServerOptions>(); services.AddSingleton(); }); } diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ConfigurationTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ConfigurationTests.cs new file mode 100644 index 0000000000..c7581dfd15 --- /dev/null +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ConfigurationTests.cs @@ -0,0 +1,153 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net.Http; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Hosting.Server.Features; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Http.Extensions; +using Microsoft.AspNetCore.Server.Kestrel.Core; +using Microsoft.AspNetCore.Testing; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Options; +using Microsoft.Extensions.Options.Infrastructure; +using Xunit; + +namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests +{ + public class ConfigurationTests + { + private void ConfigureEchoAddress(IApplicationBuilder app) + { + app.Run(context => + { + return context.Response.WriteAsync(context.Request.GetDisplayUrl()); + }); + } + + [Fact] + public void BindsKestrelToInvalidIp_FailsToStart() + { + var hostBuilder = new WebHostBuilder() + .UseKestrel() + .UseConfiguration(new ConfigurationBuilder().AddInMemoryCollection(new Dictionary() + { + { "Microsoft:AspNetCore:Server:Kestrel:Endpoints:0:Address", "ABCDEFGH" }, + { "Microsoft:AspNetCore:Server:Kestrel:Endpoints:0:Port", "0" } + }).Build()) + .ConfigureServices(services => + { + // Microsoft.AspNetCore.dll does this + services.AddTransient(typeof(IConfigureOptions<>), typeof(ConfigureDefaults<>)); + }) + .Configure(ConfigureEchoAddress); + + Assert.Throws(() => hostBuilder.Build()); + } + + [Theory] + [InlineData("127.0.0.1", "127.0.0.1")] + [InlineData("::1", "[::1]")] + public async Task BindsKestrelHttpEndPointFromConfiguration(string endPointAddress, string requestAddress) + { + var hostBuilder = new WebHostBuilder() + .UseKestrel() + .UseConfiguration(new ConfigurationBuilder().AddInMemoryCollection(new Dictionary() + { + { "Microsoft:AspNetCore:Server:Kestrel:Endpoints:0:Address", $"{endPointAddress}" }, + { "Microsoft:AspNetCore:Server:Kestrel:Endpoints:0:Port", "0" } + }).Build()) + .ConfigureServices(services => + { + // Microsoft.AspNetCore.dll does this + services.AddTransient(typeof(IConfigureOptions<>), typeof(ConfigureDefaults<>)); + }) + .Configure(ConfigureEchoAddress); + + using (var webHost = hostBuilder.Start()) + { + var port = GetWebHostPort(webHost); + + Assert.NotEqual(5000, port); // Default port + + Assert.NotEqual(0, port); + + using (var client = new HttpClient()) + { + var response = await client.GetStringAsync($"http://{requestAddress}:{port}"); + Assert.Equal($"http://{requestAddress}:{port}/", response); + } + } + } + + [Fact] + public async Task BindsKestrelHttpsEndPointFromConfiguration_ReferencedCertificateFile() + { + var hostBuilder = new WebHostBuilder() + .UseKestrel() + .UseConfiguration(new ConfigurationBuilder().AddInMemoryCollection(new Dictionary() + { + { "Microsoft:AspNetCore:Server:Kestrel:Endpoints:0:Address", "127.0.0.1" }, + { "Microsoft:AspNetCore:Server:Kestrel:Endpoints:0:Port", "0" }, + { "Microsoft:AspNetCore:Server:Kestrel:Endpoints:0:Certificate", "TestCert" }, + { "Certificates:TestCert:Source", "File" }, + { "Certificates:TestCert:Path", "testCert.pfx" }, + { "Certificates:TestCert:Password", "testPassword" } + }).Build()) + .ConfigureServices(services => + { + // Microsoft.AspNetCore.dll does this + services.AddTransient(typeof(IConfigureOptions<>), typeof(ConfigureDefaults<>)); + }) + .Configure(ConfigureEchoAddress); + + using (var webHost = hostBuilder.Start()) + { + var port = GetWebHostPort(webHost); + + var response = await HttpClientSlim.GetStringAsync($"https://127.0.0.1:{port}", validateCertificate: false); + Assert.Equal($"https://127.0.0.1:{port}/", response); + } + } + + [Fact] + public async Task BindsKestrelHttpsEndPointFromConfiguration_InlineCertificateFile() + { + var hostBuilder = new WebHostBuilder() + .UseKestrel() + .UseConfiguration(new ConfigurationBuilder().AddInMemoryCollection(new Dictionary() + { + { "Microsoft:AspNetCore:Server:Kestrel:Endpoints:0:Address", "127.0.0.1" }, + { "Microsoft:AspNetCore:Server:Kestrel:Endpoints:0:Port", "0" }, + { "Microsoft:AspNetCore:Server:Kestrel:Endpoints:0:Certificate:Source", "File" }, + { "Microsoft:AspNetCore:Server:Kestrel:Endpoints:0:Certificate:Path", "testCert.pfx" }, + { "Microsoft:AspNetCore:Server:Kestrel:Endpoints:0:Certificate:Password", "testPassword" } + }).Build()) + .ConfigureServices(services => + { + // Microsoft.AspNetCore.dll does this + services.AddTransient(typeof(IConfigureOptions<>), typeof(ConfigureDefaults<>)); + }) + .Configure(ConfigureEchoAddress); + + using (var webHost = hostBuilder.Start()) + { + var port = GetWebHostPort(webHost); + + var response = await HttpClientSlim.GetStringAsync($"https://127.0.0.1:{port}", validateCertificate: false); + Assert.Equal($"https://127.0.0.1:{port}/", response); + } + } + + private static int GetWebHostPort(IWebHost webHost) + => webHost.ServerFeatures.Get().Addresses + .Select(serverAddress => new Uri(serverAddress).Port) + .Single(); + } +} From 03907790849ac339870a9f917e2818cb9c3c102b Mon Sep 17 00:00:00 2001 From: Hao Kung Date: Mon, 5 Jun 2017 13:48:38 -0700 Subject: [PATCH 1313/1662] Revert " #1875 Add Configuration support and tests." This reverts commit c6e228d1768c96f8a416f1e4886af3ef18eb1b17. --- KestrelHttpServer.sln | 10 -- .../ConfigureDefaultKestrelServerOptions.cs | 116 ------------- .../KestrelStrings.resx | 135 ---------------- ...Microsoft.AspNetCore.Server.Kestrel.csproj | 5 +- .../Properties/KestrelStrings.Designer.cs | 100 ------------ .../WebHostBuilderKestrelExtensions.cs | 5 - .../ConfigurationTests.cs | 153 ------------------ 7 files changed, 1 insertion(+), 523 deletions(-) delete mode 100644 src/Microsoft.AspNetCore.Server.Kestrel/Internal/ConfigureDefaultKestrelServerOptions.cs delete mode 100644 src/Microsoft.AspNetCore.Server.Kestrel/KestrelStrings.resx delete mode 100644 src/Microsoft.AspNetCore.Server.Kestrel/Properties/KestrelStrings.Designer.cs delete mode 100644 test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ConfigurationTests.cs diff --git a/KestrelHttpServer.sln b/KestrelHttpServer.sln index d907c16aee..b5b6dc71f3 100644 --- a/KestrelHttpServer.sln +++ b/KestrelHttpServer.sln @@ -71,15 +71,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Server EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Server.Kestrel.Tests", "test\Microsoft.AspNetCore.Server.Kestrel.Tests\Microsoft.AspNetCore.Server.Kestrel.Tests.csproj", "{4F1C30F8-CCAA-48D7-9DF6-2A84021F5BCC}" EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "build", "build", "{FD3692F8-F5C7-49A5-8D69-29F8A87A9DB7}" - ProjectSection(SolutionItems) = preProject - build\common.props = build\common.props - build\dependencies.props = build\dependencies.props - build\Key.snk = build\Key.snk - build\repo.props = build\repo.props - build\repo.targets = build\repo.targets - EndProjectSection -EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -279,6 +270,5 @@ Global {2E9CB89D-EC8F-4DD9-A72B-08D5BABF752D} = {2D5D5227-4DBD-499A-96B1-76A36B03B750} {D95A7EC3-48AC-4D03-B2E2-0DA3E13BD3A4} = {D3273454-EA07-41D2-BF0B-FCC3675C2483} {4F1C30F8-CCAA-48D7-9DF6-2A84021F5BCC} = {D3273454-EA07-41D2-BF0B-FCC3675C2483} - {FD3692F8-F5C7-49A5-8D69-29F8A87A9DB7} = {7972A5D6-3385-4127-9277-428506DD44FF} EndGlobalSection EndGlobal diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/ConfigureDefaultKestrelServerOptions.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/ConfigureDefaultKestrelServerOptions.cs deleted file mode 100644 index 02e1f0d561..0000000000 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/ConfigureDefaultKestrelServerOptions.cs +++ /dev/null @@ -1,116 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using System.Collections.Generic; -using System.Linq; -using System.Net; -using System.Security.Cryptography.X509Certificates; -using Microsoft.AspNetCore.Certificates.Configuration; -using Microsoft.AspNetCore.Hosting; -using Microsoft.AspNetCore.Server.Kestrel.Core; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.Logging; -using Microsoft.Extensions.Options; -using Microsoft.Extensions.Options.Infrastructure; - -namespace Microsoft.AspNetCore.Server.Kestrel.Internal -{ - public class ConfigureDefaultKestrelServerOptions : ConfigureDefaultOptions - { - private const string DefaultCertificateSubjectName = "CN=localhost"; - private const string DevelopmentSSLCertificateName = "localhost"; - - private readonly IServiceProvider _services; - private readonly IHostingEnvironment _hostingEnvironment; - private readonly IConfiguration _configurationRoot; - private readonly ILoggerFactory _loggerFactory; - - public ConfigureDefaultKestrelServerOptions( - IServiceProvider services, - IHostingEnvironment hostingEnvironment, - IConfiguration configurationRoot, - ILoggerFactory loggerFactory) - { - _services = services; - _hostingEnvironment = hostingEnvironment; - _configurationRoot = configurationRoot; - _loggerFactory = loggerFactory; - } - - public override void Configure(string name, KestrelServerOptions options) - { - // Don't assume KestrelServerOptionsSetup has already set the services. Needed for UseHttps. - options.ApplicationServices = _services; - BindConfiguration(options); - } - - private void BindConfiguration(KestrelServerOptions options) - { - var certificateLoader = new CertificateLoader(_configurationRoot.GetSection("Certificates"), _loggerFactory, _hostingEnvironment.EnvironmentName); - - foreach (var endPoint in _configurationRoot.GetSection("Microsoft:AspNetCore:Server:Kestrel:EndPoints").GetChildren()) - { - BindEndPoint(options, endPoint, certificateLoader); - } - } - - private void BindEndPoint( - KestrelServerOptions options, - IConfigurationSection endPoint, - CertificateLoader certificateLoader) - { - var configAddress = endPoint.GetValue("Address"); - var configPort = endPoint.GetValue("Port"); - - if (!IPAddress.TryParse(configAddress, out var address)) - { - throw new InvalidOperationException(KestrelStrings.FormatInvalidIp(configAddress)); - } - - if (!int.TryParse(configPort, out var port)) - { - throw new InvalidOperationException(KestrelStrings.FormatInvalidPort(configPort)); - } - - options.Listen(address, port, listenOptions => - { - var certificateConfig = endPoint.GetSection("Certificate"); - X509Certificate2 certificate = null; - if (certificateConfig.Exists()) - { - try - { - try - { - certificate = certificateLoader.Load(certificateConfig).FirstOrDefault(); - } - catch (KeyNotFoundException) when (certificateConfig.Value.Equals(DevelopmentSSLCertificateName, StringComparison.Ordinal) && _hostingEnvironment.IsDevelopment()) - { - var storeLoader = new CertificateStoreLoader(); - certificate = storeLoader.Load(DefaultCertificateSubjectName, "My", StoreLocation.CurrentUser, validOnly: false) ?? - storeLoader.Load(DefaultCertificateSubjectName, "My", StoreLocation.LocalMachine, validOnly: false); - - if (certificate == null) - { - var logger = _loggerFactory.CreateLogger("Microsoft.AspNetCore.Server.Kestrel.KestrelServerConfigureOptions"); - logger.LogError(KestrelStrings.NoCertFoundLog); - } - } - - if (certificate == null) - { - throw new InvalidOperationException(KestrelStrings.FormatNoCertForEndpoint(endPoint.Key)); - } - } - catch (Exception ex) - { - throw new InvalidOperationException(KestrelStrings.UnableToConfigureHttps, ex); - } - - listenOptions.UseHttps(certificate); - } - }); - } - } -} diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/KestrelStrings.resx b/src/Microsoft.AspNetCore.Server.Kestrel/KestrelStrings.resx deleted file mode 100644 index bf5c93410c..0000000000 --- a/src/Microsoft.AspNetCore.Server.Kestrel/KestrelStrings.resx +++ /dev/null @@ -1,135 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 2.0 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - Invalid IP address in configuration: {configAddress}. - - - Invalid port in configuration: {configPort}. - - - No certificate found for endpoint {endPoint}. - - - Unable to configure HTTPS endpoint. For information on configuring HTTPS see https://go.microsoft.com/fwlink/?linkid=848054. - - - No HTTPS certificate was found for development. For information on configuring HTTPS see https://go.microsoft.com/fwlink/?linkid=848054. - - \ No newline at end of file diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Microsoft.AspNetCore.Server.Kestrel.csproj b/src/Microsoft.AspNetCore.Server.Kestrel/Microsoft.AspNetCore.Server.Kestrel.csproj index fbaa34e0b7..616830814d 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Microsoft.AspNetCore.Server.Kestrel.csproj +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Microsoft.AspNetCore.Server.Kestrel.csproj @@ -4,7 +4,7 @@ ASP.NET Core Kestrel cross-platform web server. - netstandard2.0;netcoreapp2.0 + netstandard2.0 true aspnetcore;kestrel CS1591;$(NoWarn) @@ -12,14 +12,11 @@ - - - diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Properties/KestrelStrings.Designer.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Properties/KestrelStrings.Designer.cs deleted file mode 100644 index ee0b31857d..0000000000 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Properties/KestrelStrings.Designer.cs +++ /dev/null @@ -1,100 +0,0 @@ -// -namespace Microsoft.AspNetCore.Server.Kestrel -{ - using System.Globalization; - using System.Reflection; - using System.Resources; - - internal static class KestrelStrings - { - private static readonly ResourceManager _resourceManager - = new ResourceManager("Microsoft.AspNetCore.Server.Kestrel.KestrelStrings", typeof(KestrelStrings).GetTypeInfo().Assembly); - - /// - /// Invalid IP address in configuration: {configAddress}. - /// - internal static string InvalidIp - { - get => GetString("InvalidIp"); - } - - /// - /// Invalid IP address in configuration: {configAddress}. - /// - internal static string FormatInvalidIp(object configAddress) - => string.Format(CultureInfo.CurrentCulture, GetString("InvalidIp", "configAddress"), configAddress); - - /// - /// Invalid port in configuration: {configPort}. - /// - internal static string InvalidPort - { - get => GetString("InvalidPort"); - } - - /// - /// Invalid port in configuration: {configPort}. - /// - internal static string FormatInvalidPort(object configPort) - => string.Format(CultureInfo.CurrentCulture, GetString("InvalidPort", "configPort"), configPort); - - /// - /// No certificate found for endpoint {endPoint}. - /// - internal static string NoCertForEndpoint - { - get => GetString("NoCertForEndpoint"); - } - - /// - /// No certificate found for endpoint {endPoint}. - /// - internal static string FormatNoCertForEndpoint(object endPoint) - => string.Format(CultureInfo.CurrentCulture, GetString("NoCertForEndpoint", "endPoint"), endPoint); - - /// - /// Unable to configure HTTPS endpoint. For information on configuring HTTPS see https://go.microsoft.com/fwlink/?linkid=848054. - /// - internal static string UnableToConfigureHttps - { - get => GetString("UnableToConfigureHttps"); - } - - /// - /// Unable to configure HTTPS endpoint. For information on configuring HTTPS see https://go.microsoft.com/fwlink/?linkid=848054. - /// - internal static string FormatUnableToConfigureHttps() - => GetString("UnableToConfigureHttps"); - - /// - /// No HTTPS certificate was found for development. For information on configuring HTTPS see https://go.microsoft.com/fwlink/?linkid=848054. - /// - internal static string NoCertFoundLog - { - get => GetString("NoCertFoundLog"); - } - - /// - /// No HTTPS certificate was found for development. For information on configuring HTTPS see https://go.microsoft.com/fwlink/?linkid=848054. - /// - internal static string FormatNoCertFoundLog() - => GetString("NoCertFoundLog"); - - private static string GetString(string name, params string[] formatterNames) - { - var value = _resourceManager.GetString(name); - - System.Diagnostics.Debug.Assert(value != null); - - if (formatterNames != null) - { - for (var i = 0; i < formatterNames.Length; i++) - { - value = value.Replace("{" + formatterNames[i] + "}", "{" + i + "}"); - } - } - - return value; - } - } -} diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/WebHostBuilderKestrelExtensions.cs b/src/Microsoft.AspNetCore.Server.Kestrel/WebHostBuilderKestrelExtensions.cs index 0823e62db1..3d3dad73cb 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/WebHostBuilderKestrelExtensions.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/WebHostBuilderKestrelExtensions.cs @@ -3,12 +3,10 @@ using System; using Microsoft.AspNetCore.Hosting.Server; -using Microsoft.AspNetCore.Server.Kestrel.Internal; using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Options; -using Microsoft.Extensions.Options.Infrastructure; namespace Microsoft.AspNetCore.Hosting { @@ -30,9 +28,6 @@ namespace Microsoft.AspNetCore.Hosting return hostBuilder.ConfigureServices(services => { services.AddTransient, KestrelServerOptionsSetup>(); - // https://github.com/aspnet/DependencyInjection/issues/500 - services.AddTransient, ConfigureDefaults>(); - services.AddTransient, ConfigureDefaultKestrelServerOptions>(); services.AddSingleton(); }); } diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ConfigurationTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ConfigurationTests.cs deleted file mode 100644 index c7581dfd15..0000000000 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ConfigurationTests.cs +++ /dev/null @@ -1,153 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using System.Collections.Generic; -using System.Linq; -using System.Net.Http; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Builder; -using Microsoft.AspNetCore.Hosting; -using Microsoft.AspNetCore.Hosting.Server.Features; -using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Http.Extensions; -using Microsoft.AspNetCore.Server.Kestrel.Core; -using Microsoft.AspNetCore.Testing; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Options; -using Microsoft.Extensions.Options.Infrastructure; -using Xunit; - -namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests -{ - public class ConfigurationTests - { - private void ConfigureEchoAddress(IApplicationBuilder app) - { - app.Run(context => - { - return context.Response.WriteAsync(context.Request.GetDisplayUrl()); - }); - } - - [Fact] - public void BindsKestrelToInvalidIp_FailsToStart() - { - var hostBuilder = new WebHostBuilder() - .UseKestrel() - .UseConfiguration(new ConfigurationBuilder().AddInMemoryCollection(new Dictionary() - { - { "Microsoft:AspNetCore:Server:Kestrel:Endpoints:0:Address", "ABCDEFGH" }, - { "Microsoft:AspNetCore:Server:Kestrel:Endpoints:0:Port", "0" } - }).Build()) - .ConfigureServices(services => - { - // Microsoft.AspNetCore.dll does this - services.AddTransient(typeof(IConfigureOptions<>), typeof(ConfigureDefaults<>)); - }) - .Configure(ConfigureEchoAddress); - - Assert.Throws(() => hostBuilder.Build()); - } - - [Theory] - [InlineData("127.0.0.1", "127.0.0.1")] - [InlineData("::1", "[::1]")] - public async Task BindsKestrelHttpEndPointFromConfiguration(string endPointAddress, string requestAddress) - { - var hostBuilder = new WebHostBuilder() - .UseKestrel() - .UseConfiguration(new ConfigurationBuilder().AddInMemoryCollection(new Dictionary() - { - { "Microsoft:AspNetCore:Server:Kestrel:Endpoints:0:Address", $"{endPointAddress}" }, - { "Microsoft:AspNetCore:Server:Kestrel:Endpoints:0:Port", "0" } - }).Build()) - .ConfigureServices(services => - { - // Microsoft.AspNetCore.dll does this - services.AddTransient(typeof(IConfigureOptions<>), typeof(ConfigureDefaults<>)); - }) - .Configure(ConfigureEchoAddress); - - using (var webHost = hostBuilder.Start()) - { - var port = GetWebHostPort(webHost); - - Assert.NotEqual(5000, port); // Default port - - Assert.NotEqual(0, port); - - using (var client = new HttpClient()) - { - var response = await client.GetStringAsync($"http://{requestAddress}:{port}"); - Assert.Equal($"http://{requestAddress}:{port}/", response); - } - } - } - - [Fact] - public async Task BindsKestrelHttpsEndPointFromConfiguration_ReferencedCertificateFile() - { - var hostBuilder = new WebHostBuilder() - .UseKestrel() - .UseConfiguration(new ConfigurationBuilder().AddInMemoryCollection(new Dictionary() - { - { "Microsoft:AspNetCore:Server:Kestrel:Endpoints:0:Address", "127.0.0.1" }, - { "Microsoft:AspNetCore:Server:Kestrel:Endpoints:0:Port", "0" }, - { "Microsoft:AspNetCore:Server:Kestrel:Endpoints:0:Certificate", "TestCert" }, - { "Certificates:TestCert:Source", "File" }, - { "Certificates:TestCert:Path", "testCert.pfx" }, - { "Certificates:TestCert:Password", "testPassword" } - }).Build()) - .ConfigureServices(services => - { - // Microsoft.AspNetCore.dll does this - services.AddTransient(typeof(IConfigureOptions<>), typeof(ConfigureDefaults<>)); - }) - .Configure(ConfigureEchoAddress); - - using (var webHost = hostBuilder.Start()) - { - var port = GetWebHostPort(webHost); - - var response = await HttpClientSlim.GetStringAsync($"https://127.0.0.1:{port}", validateCertificate: false); - Assert.Equal($"https://127.0.0.1:{port}/", response); - } - } - - [Fact] - public async Task BindsKestrelHttpsEndPointFromConfiguration_InlineCertificateFile() - { - var hostBuilder = new WebHostBuilder() - .UseKestrel() - .UseConfiguration(new ConfigurationBuilder().AddInMemoryCollection(new Dictionary() - { - { "Microsoft:AspNetCore:Server:Kestrel:Endpoints:0:Address", "127.0.0.1" }, - { "Microsoft:AspNetCore:Server:Kestrel:Endpoints:0:Port", "0" }, - { "Microsoft:AspNetCore:Server:Kestrel:Endpoints:0:Certificate:Source", "File" }, - { "Microsoft:AspNetCore:Server:Kestrel:Endpoints:0:Certificate:Path", "testCert.pfx" }, - { "Microsoft:AspNetCore:Server:Kestrel:Endpoints:0:Certificate:Password", "testPassword" } - }).Build()) - .ConfigureServices(services => - { - // Microsoft.AspNetCore.dll does this - services.AddTransient(typeof(IConfigureOptions<>), typeof(ConfigureDefaults<>)); - }) - .Configure(ConfigureEchoAddress); - - using (var webHost = hostBuilder.Start()) - { - var port = GetWebHostPort(webHost); - - var response = await HttpClientSlim.GetStringAsync($"https://127.0.0.1:{port}", validateCertificate: false); - Assert.Equal($"https://127.0.0.1:{port}/", response); - } - } - - private static int GetWebHostPort(IWebHost webHost) - => webHost.ServerFeatures.Get().Addresses - .Select(serverAddress => new Uri(serverAddress).Port) - .Single(); - } -} From f96c48c08d5e32e5c403d856028cf87b5523b8b3 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Wed, 7 Jun 2017 11:48:56 -0700 Subject: [PATCH 1314/1662] Add a request body size limit (#1877) - Implement IHttpMaxRequestBodySizeFeature --- .../BadHttpRequestException.cs | 3 + .../CoreStrings.resx | 11 +- .../Internal/Http/Frame.FeatureCollection.cs | 27 +- .../Internal/Http/Frame.Generated.cs | 16 + .../Internal/Http/Frame.cs | 44 +- .../Internal/Http/FrameOfT.cs | 40 +- .../Internal/Http/FrameRequestStream.cs | 8 - .../Internal/Http/FrameResponseStream.cs | 8 - .../Internal/Http/MessageBody.cs | 168 +++--- .../Internal/Http/RequestRejectionReason.cs | 1 + .../Internal/Infrastructure/Streams.cs | 7 - .../KestrelServerLimits.cs | 27 + .../Properties/CoreStrings.Designer.cs | 42 ++ .../FrameTests.cs | 23 +- .../KestrelServerLimitsTests.cs | 31 ++ .../MessageBodyTests.cs | 129 ++--- .../StreamsTests.cs | 7 - .../MaxRequestBodySizeTests.cs | 494 ++++++++++++++++++ .../RequestTests.cs | 5 +- test/shared/TestConnection.cs | 33 +- tools/CodeGenerator/FrameFeatureCollection.cs | 4 +- 21 files changed, 906 insertions(+), 222 deletions(-) create mode 100644 test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/MaxRequestBodySizeTests.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/BadHttpRequestException.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/BadHttpRequestException.cs index 034465d212..e778f76641 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/BadHttpRequestException.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/BadHttpRequestException.cs @@ -71,6 +71,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core case RequestRejectionReason.TooManyHeaders: ex = new BadHttpRequestException(CoreStrings.BadRequest_TooManyHeaders, StatusCodes.Status431RequestHeaderFieldsTooLarge); break; + case RequestRejectionReason.RequestBodyTooLarge: + ex = new BadHttpRequestException(CoreStrings.BadRequest_RequestBodyTooLarge, StatusCodes.Status413PayloadTooLarge); + break; case RequestRejectionReason.RequestTimeout: ex = new BadHttpRequestException(CoreStrings.BadRequest_RequestTimeout, StatusCodes.Status408RequestTimeout); break; diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/CoreStrings.resx b/src/Microsoft.AspNetCore.Server.Kestrel.Core/CoreStrings.resx index f2f873fe3b..4ccc38f2c0 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/CoreStrings.resx +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/CoreStrings.resx @@ -318,4 +318,13 @@ IHttpUpgradeFeature.UpgradeAsync was already called and can only be called once per connection. - + + Request body too large. + + + The maximum request body size cannot be modified after the app has already started reading from the request body. + + + The maximum request body size cannot be modified after the request has been upgraded. + + \ No newline at end of file diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.FeatureCollection.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.FeatureCollection.cs index 6ec4f45348..3358811e93 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.FeatureCollection.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.FeatureCollection.cs @@ -20,7 +20,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http IHttpUpgradeFeature, IHttpConnectionFeature, IHttpRequestLifetimeFeature, - IHttpRequestIdentifierFeature + IHttpRequestIdentifierFeature, + IHttpMaxRequestBodySizeFeature { // NOTE: When feature interfaces are added to or removed from this Frame class implementation, // then the list of `implementedFeatures` in the generated code project MUST also be updated. @@ -202,6 +203,30 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http set => TraceIdentifier = value; } + bool IHttpMaxRequestBodySizeFeature.IsReadOnly => HasStartedConsumingRequestBody || _wasUpgraded; + + long? IHttpMaxRequestBodySizeFeature.MaxRequestBodySize + { + get => MaxRequestBodySize; + set + { + if (HasStartedConsumingRequestBody) + { + throw new InvalidOperationException(CoreStrings.MaxRequestBodySizeCannotBeModifiedAfterRead); + } + if (_wasUpgraded) + { + throw new InvalidOperationException(CoreStrings.MaxRequestBodySizeCannotBeModifiedForUpgradedRequests); + } + if (value < 0) + { + throw new ArgumentOutOfRangeException(nameof(value), CoreStrings.NonNegativeNumberOrNullRequired); + } + + MaxRequestBodySize = value; + } + } + object IFeatureCollection.this[Type key] { get => FastFeatureGet(key); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.Generated.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.Generated.cs index 28b0be9f78..3a17316ade 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.Generated.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.Generated.cs @@ -23,6 +23,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http private static readonly Type ITlsConnectionFeatureType = typeof(global::Microsoft.AspNetCore.Http.Features.ITlsConnectionFeature); private static readonly Type IHttpWebSocketFeatureType = typeof(global::Microsoft.AspNetCore.Http.Features.IHttpWebSocketFeature); private static readonly Type ISessionFeatureType = typeof(global::Microsoft.AspNetCore.Http.Features.ISessionFeature); + private static readonly Type IHttpMaxRequestBodySizeFeatureType = typeof(global::Microsoft.AspNetCore.Http.Features.IHttpMaxRequestBodySizeFeature); private static readonly Type IHttpSendFileFeatureType = typeof(global::Microsoft.AspNetCore.Http.Features.IHttpSendFileFeature); private object _currentIHttpRequestFeature; @@ -40,6 +41,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http private object _currentITlsConnectionFeature; private object _currentIHttpWebSocketFeature; private object _currentISessionFeature; + private object _currentIHttpMaxRequestBodySizeFeature; private object _currentIHttpSendFileFeature; private void FastReset() @@ -50,6 +52,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http _currentIHttpRequestIdentifierFeature = this; _currentIHttpRequestLifetimeFeature = this; _currentIHttpConnectionFeature = this; + _currentIHttpMaxRequestBodySizeFeature = this; _currentIServiceProvidersFeature = null; _currentIHttpAuthenticationFeature = null; @@ -125,6 +128,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { return _currentISessionFeature; } + if (key == IHttpMaxRequestBodySizeFeatureType) + { + return _currentIHttpMaxRequestBodySizeFeature; + } if (key == IHttpSendFileFeatureType) { return _currentIHttpSendFileFeature; @@ -211,6 +218,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http _currentISessionFeature = feature; return; } + if (key == IHttpMaxRequestBodySizeFeatureType) + { + _currentIHttpMaxRequestBodySizeFeature = feature; + return; + } if (key == IHttpSendFileFeatureType) { _currentIHttpSendFileFeature = feature; @@ -281,6 +293,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { yield return new KeyValuePair(ISessionFeatureType, _currentISessionFeature as global::Microsoft.AspNetCore.Http.Features.ISessionFeature); } + if (_currentIHttpMaxRequestBodySizeFeature != null) + { + yield return new KeyValuePair(IHttpMaxRequestBodySizeFeatureType, _currentIHttpMaxRequestBodySizeFeature as global::Microsoft.AspNetCore.Http.Features.IHttpMaxRequestBodySizeFeature); + } if (_currentIHttpSendFileFeature != null) { yield return new KeyValuePair(IHttpSendFileFeatureType, _currentIHttpSendFileFeature as global::Microsoft.AspNetCore.Http.Features.IHttpSendFileFeature); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.cs index 374b9e6518..6919a10ccb 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.cs @@ -121,6 +121,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http protected string ConnectionId => _frameContext.ConnectionId; public string ConnectionIdFeature { get; set; } + public bool HasStartedConsumingRequestBody { get; set; } + public long? MaxRequestBodySize { get; set; } /// /// The request id. @@ -310,8 +312,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http public void PauseStreams() => _frameStreams.Pause(); - public void ResumeStreams() => _frameStreams.Resume(); - public void StopStreams() => _frameStreams.Stop(); public void Reset() @@ -326,6 +326,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http ResetFeatureCollection(); + HasStartedConsumingRequestBody = false; + MaxRequestBodySize = ServerOptions.Limits.MaxRequestBodySize; TraceIdentifier = null; Scheme = null; Method = null; @@ -368,7 +370,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http _manuallySetRequestAbortToken = null; _abortedCts = null; - // Allow to bytes for \r\n after headers + // Allow two bytes for \r\n after headers _remainingRequestHeadersBytesAllowed = ServerOptions.Limits.MaxRequestHeadersTotalSize + 2; _requestHeadersParsed = 0; @@ -949,7 +951,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http var result = _parser.ParseRequestLine(new FrameAdapter(this), buffer, out consumed, out examined); if (!result && overLength) { - RejectRequest(RequestRejectionReason.RequestLineTooLong); + ThrowRequestRejected(RequestRejectionReason.RequestLineTooLong); } return result; @@ -973,7 +975,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http if (!result && overLength) { - RejectRequest(RequestRejectionReason.HeadersExceedMaxTotalSize); + ThrowRequestRejected(RequestRejectionReason.HeadersExceedMaxTotalSize); } if (result) { @@ -1059,13 +1061,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http throw new ObjectDisposedException(CoreStrings.UnhandledApplicationException, _applicationException); } - public void RejectRequest(RequestRejectionReason reason) + public void ThrowRequestRejected(RequestRejectionReason reason) => throw BadHttpRequestException.GetException(reason); - public void RejectRequest(RequestRejectionReason reason, string detail) + public void ThrowRequestRejected(RequestRejectionReason reason, string detail) => throw BadHttpRequestException.GetException(reason, detail); - private void RejectRequestTarget(Span target) + private void ThrowRequestTargetRejected(Span target) => throw GetInvalidRequestTargetException(target); private BadHttpRequestException GetInvalidRequestTargetException(Span target) @@ -1207,7 +1209,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http } catch (InvalidOperationException) { - RejectRequestTarget(target); + ThrowRequestTargetRejected(target); } QueryString = query.GetAsciiStringNonNullCharacters(); @@ -1226,7 +1228,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http var ch = target[i]; if (!UriUtilities.IsValidAuthorityCharacter(ch)) { - RejectRequestTarget(target); + ThrowRequestTargetRejected(target); } } @@ -1234,7 +1236,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http // requests (https://tools.ietf.org/html/rfc7231#section-4.3.6). if (method != HttpMethod.Connect) { - RejectRequest(RequestRejectionReason.ConnectMethodRequired); + ThrowRequestRejected(RequestRejectionReason.ConnectMethodRequired); } // When making a CONNECT request to establish a tunnel through one or @@ -1259,7 +1261,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http // OPTIONS request (https://tools.ietf.org/html/rfc7231#section-4.3.7). if (method != HttpMethod.Options) { - RejectRequest(RequestRejectionReason.OptionsMethodRequired); + ThrowRequestRejected(RequestRejectionReason.OptionsMethodRequired); } RawTarget = Asterisk; @@ -1288,7 +1290,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http if (!Uri.TryCreate(RawTarget, UriKind.Absolute, out var uri)) { - RejectRequestTarget(target); + ThrowRequestTargetRejected(target); } _absoluteRequestTarget = uri; @@ -1312,7 +1314,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http _requestHeadersParsed++; if (_requestHeadersParsed > ServerOptions.Limits.MaxRequestHeaderCount) { - RejectRequest(RequestRejectionReason.TooManyHeaders); + ThrowRequestRejected(RequestRejectionReason.TooManyHeaders); } var valueString = value.GetAsciiStringNonNullCharacters(); @@ -1335,17 +1337,17 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http var host = FrameRequestHeaders.HeaderHost; if (host.Count <= 0) { - RejectRequest(RequestRejectionReason.MissingHostHeader); + ThrowRequestRejected(RequestRejectionReason.MissingHostHeader); } else if (host.Count > 1) { - RejectRequest(RequestRejectionReason.MultipleHostHeaders); + ThrowRequestRejected(RequestRejectionReason.MultipleHostHeaders); } else if (_requestTargetForm == HttpRequestTarget.AuthorityForm) { if (!host.Equals(RawTarget)) { - RejectRequest(RequestRejectionReason.InvalidHostHeader, host.ToString()); + ThrowRequestRejected(RequestRejectionReason.InvalidHostHeader, host.ToString()); } } else if (_requestTargetForm == HttpRequestTarget.AbsoluteForm) @@ -1361,7 +1363,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http if ((host != _absoluteRequestTarget.Authority || !_absoluteRequestTarget.IsDefaultPort) && host != authorityAndPort) { - RejectRequest(RequestRejectionReason.InvalidHostHeader, host.ToString()); + ThrowRequestRejected(RequestRejectionReason.InvalidHostHeader, host.ToString()); } } } @@ -1370,9 +1372,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http => ConnectionInformation.PipeFactory.Create(new PipeOptions { ReaderScheduler = ServiceContext.ThreadPool, - WriterScheduler = ConnectionInformation.InputWriterScheduler, - MaximumSizeHigh = ServiceContext.ServerOptions.Limits.MaxRequestBufferSize ?? 0, - MaximumSizeLow = ServiceContext.ServerOptions.Limits.MaxRequestBufferSize ?? 0 + WriterScheduler = InlineScheduler.Default, + MaximumSizeHigh = 1, + MaximumSizeLow = 1 }); private enum HttpRequestTarget diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameOfT.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameOfT.cs index 769cd8e9db..c660d0b60c 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameOfT.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameOfT.cs @@ -93,8 +93,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http InitializeStreams(messageBody); - var messageBodyTask = messageBody.StartAsync(); - var context = _application.CreateContext(this); try { @@ -142,8 +140,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http // If _requestAbort is set, the connection has already been closed. if (Volatile.Read(ref _requestAborted) == 0) { - ResumeStreams(); - if (HasResponseStarted) { // If the response has already started, call ProduceEnd() before @@ -158,21 +154,24 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http await ProduceEnd(); } - if (!_keepAlive) + // ForZeroContentLength does not complete the reader nor the writer + if (!messageBody.IsEmpty) { - messageBody.Cancel(); + if (_keepAlive) + { + // Finish reading the request body in case the app did not. + await messageBody.ConsumeAsync(); + // At this point both the request body pipe reader and writer should be completed. + RequestBodyPipe.Reset(); + } + else + { + RequestBodyPipe.Reader.Complete(); + messageBody.Cancel(); + Input.CancelPendingRead(); + } } - // An upgraded request has no defined request body length. - // Cancel any pending read so the read loop ends. - if (_upgradeAvailable) - { - Input.CancelPendingRead(); - } - - // Finish reading the request body in case the app did not. - await messageBody.ConsumeAsync(); - if (!HasResponseStarted) { await ProduceEnd(); @@ -200,15 +199,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http // to ensure InitializeStreams has been called. StopStreams(); } - - // At this point both the request body pipe reader and writer should be completed. - await messageBodyTask; - - // ForZeroContentLength does not complete the reader nor the writer - if (_keepAlive && !messageBody.IsEmpty) - { - RequestBodyPipe.Reset(); - } } if (!_keepAlive) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameRequestStream.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameRequestStream.cs index be5f9fd66f..ce518d17d8 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameRequestStream.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameRequestStream.cs @@ -169,14 +169,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http _state = FrameStreamState.Closed; } - public void ResumeAcceptingReads() - { - if (_state == FrameStreamState.Closed) - { - _state = FrameStreamState.Open; - } - } - public void StopAcceptingReads() { // Can't use dispose (or close) as can be disposed too early by user code diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameResponseStream.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameResponseStream.cs index 062be560c2..3a76f4bf1b 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameResponseStream.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameResponseStream.cs @@ -123,14 +123,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http _state = FrameStreamState.Closed; } - public void ResumeAcceptingWrites() - { - if (_state == FrameStreamState.Closed) - { - _state = FrameStreamState.Open; - } - } - public void StopAcceptingWrites() { // Can't use dispose (or close) as can be disposed too early by user code diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/MessageBody.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/MessageBody.cs index 6ab87c8096..bc6e3c0f8a 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/MessageBody.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/MessageBody.cs @@ -7,7 +7,6 @@ using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; -using Microsoft.Extensions.Internal; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { @@ -33,7 +32,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http public virtual bool IsEmpty => false; - public virtual async Task StartAsync() + private async Task PumpAsync() { Exception error = null; @@ -83,7 +82,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http } else if (result.IsCompleted) { - _context.RejectRequest(RequestRejectionReason.UnexpectedEndOfRequestContent); + _context.ThrowRequestRejected(RequestRejectionReason.UnexpectedEndOfRequestContent); } } finally @@ -109,6 +108,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http public virtual async Task ReadAsync(ArraySegment buffer, CancellationToken cancellationToken = default(CancellationToken)) { + TryInit(); + while (true) { var result = await _context.RequestBodyPipe.Reader.ReadAsync(); @@ -139,6 +140,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http public virtual async Task CopyToAsync(Stream destination, CancellationToken cancellationToken = default(CancellationToken)) { + TryInit(); + while (true) { var result = await _context.RequestBodyPipe.Reader.ReadAsync(); @@ -169,7 +172,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http public virtual async Task ConsumeAsync(CancellationToken cancellationToken = default(CancellationToken)) { - Exception error = null; + TryInit(); try { @@ -180,14 +183,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http _context.RequestBodyPipe.Reader.Advance(result.Buffer.End); } while (!result.IsCompleted); } - catch (Exception ex) - { - error = ex; - throw; - } finally { - _context.RequestBodyPipe.Reader.Complete(error); + _context.RequestBodyPipe.Reader.Complete(); } } @@ -215,7 +213,24 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http } } - protected abstract bool Read(ReadableBuffer readableBuffer, WritableBuffer writableBuffer, out ReadCursor consumed, out ReadCursor examined); + private void TryInit() + { + if (!_context.HasStartedConsumingRequestBody) + { + OnReadStart(); + _context.HasStartedConsumingRequestBody = true; + _ = PumpAsync(); + } + } + + protected virtual bool Read(ReadableBuffer readableBuffer, WritableBuffer writableBuffer, out ReadCursor consumed, out ReadCursor examined) + { + throw new NotImplementedException(); + } + + protected virtual void OnReadStart() + { + } public static MessageBody For( HttpVersion httpVersion, @@ -248,15 +263,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http // status code and then close the connection. if (transferCoding != TransferCoding.Chunked) { - context.RejectRequest(RequestRejectionReason.FinalTransferCodingNotChunked, transferEncoding.ToString()); + context.ThrowRequestRejected(RequestRejectionReason.FinalTransferCodingNotChunked, transferEncoding.ToString()); } if (upgrade) { - context.RejectRequest(RequestRejectionReason.UpgradeRequestCannotHavePayload); + context.ThrowRequestRejected(RequestRejectionReason.UpgradeRequestCannotHavePayload); } - return new ForChunkedEncoding(keepAlive, headers, context); + return new ForChunkedEncoding(keepAlive, context); } if (headers.ContentLength.HasValue) @@ -269,7 +284,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http } else if (upgrade) { - context.RejectRequest(RequestRejectionReason.UpgradeRequestCannotHavePayload); + context.ThrowRequestRejected(RequestRejectionReason.UpgradeRequestCannotHavePayload); } return new ForContentLength(keepAlive, contentLength, context); @@ -283,7 +298,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http if (HttpMethods.IsPost(context.Method) || HttpMethods.IsPut(context.Method)) { var requestRejectionReason = httpVersion == HttpVersion.Http11 ? RequestRejectionReason.LengthRequired : RequestRejectionReason.LengthRequiredHttp10; - context.RejectRequest(requestRejectionReason, context.Method); + context.ThrowRequestRejected(requestRejectionReason, context.Method); } } @@ -322,11 +337,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http public override bool IsEmpty => true; - public override Task StartAsync() - { - return Task.CompletedTask; - } - public override Task ReadAsync(ArraySegment buffer, CancellationToken cancellationToken = default(CancellationToken)) { return Task.FromResult(0); @@ -341,11 +351,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { return Task.CompletedTask; } - - protected override bool Read(ReadableBuffer readableBuffer, WritableBuffer writableBuffer, out ReadCursor consumed, out ReadCursor examined) - { - throw new NotImplementedException(); - } } private class ForContentLength : MessageBody @@ -378,6 +383,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http return _inputLength == 0; } + + protected override void OnReadStart() + { + if (_contentLength > _context.MaxRequestBodySize) + { + _context.ThrowRequestRejected(RequestRejectionReason.RequestBodyTooLarge); + } + } } /// @@ -387,19 +400,18 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { // byte consts don't have a data type annotation so we pre-cast it private const byte ByteCR = (byte)'\r'; + // "7FFFFFFF\r\n" is the largest chunk size that could be returned as an int. + private const int MaxChunkPrefixBytes = 10; - private readonly IPipeReader _input; - private readonly FrameRequestHeaders _requestHeaders; private int _inputLength; + private long _consumedBytes; private Mode _mode = Mode.Prefix; - public ForChunkedEncoding(bool keepAlive, FrameRequestHeaders headers, Frame context) + public ForChunkedEncoding(bool keepAlive, Frame context) : base(context) { RequestKeepAlive = keepAlive; - _input = _context.Input; - _requestHeaders = headers; } protected override bool Read(ReadableBuffer readableBuffer, WritableBuffer writableBuffer, out ReadCursor consumed, out ReadCursor examined) @@ -471,6 +483,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http readableBuffer = readableBuffer.Slice(consumed); } + // _consumedBytes aren't tracked for trailer headers, since headers have seperate limits. if (_mode == Mode.TrailerHeaders) { if (_context.TakeMessageHeaders(readableBuffer, out consumed, out examined)) @@ -482,6 +495,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http return _mode == Mode.Complete; } + private void AddAndCheckConsumedBytes(int consumedBytes) + { + _consumedBytes += consumedBytes; + + if (_consumedBytes > _context.MaxRequestBodySize) + { + _context.ThrowRequestRejected(RequestRejectionReason.RequestBodyTooLarge); + } + } + private void ParseChunkedPrefix(ReadableBuffer buffer, out ReadCursor consumed, out ReadCursor examined) { consumed = buffer.Start; @@ -499,13 +522,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http var chunkSize = CalculateChunkSize(ch1, 0); ch1 = ch2; - do + while (reader.ConsumedBytes < MaxChunkPrefixBytes) { if (ch1 == ';') { consumed = reader.Cursor; examined = reader.Cursor; + AddAndCheckConsumedBytes(reader.ConsumedBytes); _inputLength = chunkSize; _mode = Mode.Extension; return; @@ -523,23 +547,18 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http consumed = reader.Cursor; examined = reader.Cursor; + AddAndCheckConsumedBytes(reader.ConsumedBytes); _inputLength = chunkSize; - - if (chunkSize > 0) - { - _mode = Mode.Data; - } - else - { - _mode = Mode.Trailer; - } - + _mode = chunkSize > 0 ? Mode.Data : Mode.Trailer; return; } chunkSize = CalculateChunkSize(ch1, chunkSize); ch1 = ch2; - } while (ch1 != -1); + } + + // At this point, 10 bytes have been consumed which is enough to parse the max value "7FFFFFFF\r\n". + _context.ThrowRequestRejected(RequestRejectionReason.BadChunkSizeData); } private void ParseExtension(ReadableBuffer buffer, out ReadCursor consumed, out ReadCursor examined) @@ -548,39 +567,48 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http // Just drain the data consumed = buffer.Start; examined = buffer.Start; + do { ReadCursor extensionCursor; if (ReadCursorOperations.Seek(buffer.Start, buffer.End, out extensionCursor, ByteCR) == -1) { // End marker not found yet + consumed = buffer.End; examined = buffer.End; + AddAndCheckConsumedBytes(buffer.Length); return; }; + var charsToByteCRExclusive = buffer.Slice(0, extensionCursor).Length; + var sufixBuffer = buffer.Slice(extensionCursor); if (sufixBuffer.Length < 2) { + consumed = extensionCursor; examined = buffer.End; + AddAndCheckConsumedBytes(charsToByteCRExclusive); return; } sufixBuffer = sufixBuffer.Slice(0, 2); var sufixSpan = sufixBuffer.ToSpan(); - if (sufixSpan[1] == '\n') { + // We consumed the \r\n at the end of the extension, so switch modes. + _mode = _inputLength > 0 ? Mode.Data : Mode.Trailer; + consumed = sufixBuffer.End; examined = sufixBuffer.End; - if (_inputLength > 0) - { - _mode = Mode.Data; - } - else - { - _mode = Mode.Trailer; - } + AddAndCheckConsumedBytes(charsToByteCRExclusive + 2); + } + else + { + // Don't consume suffixSpan[1] in case it is also a \r. + buffer = buffer.Slice(charsToByteCRExclusive + 1); + consumed = extensionCursor; + AddAndCheckConsumedBytes(charsToByteCRExclusive + 1); } } while (_mode == Mode.Extension); } @@ -594,6 +622,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http Copy(buffer.Slice(0, actual), writableBuffer); _inputLength -= actual; + AddAndCheckConsumedBytes(actual); if (_inputLength == 0) { @@ -618,11 +647,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { consumed = suffixBuffer.End; examined = suffixBuffer.End; + AddAndCheckConsumedBytes(2); _mode = Mode.Prefix; } else { - _context.RejectRequest(RequestRejectionReason.BadChunkSuffix); + _context.ThrowRequestRejected(RequestRejectionReason.BadChunkSuffix); } } @@ -644,6 +674,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { consumed = trailerBuffer.End; examined = trailerBuffer.End; + AddAndCheckConsumedBytes(2); _mode = Mode.Complete; } else @@ -654,23 +685,30 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http private int CalculateChunkSize(int extraHexDigit, int currentParsedSize) { - checked + try { - if (extraHexDigit >= '0' && extraHexDigit <= '9') + checked { - return currentParsedSize * 0x10 + (extraHexDigit - '0'); - } - else if (extraHexDigit >= 'A' && extraHexDigit <= 'F') - { - return currentParsedSize * 0x10 + (extraHexDigit - ('A' - 10)); - } - else if (extraHexDigit >= 'a' && extraHexDigit <= 'f') - { - return currentParsedSize * 0x10 + (extraHexDigit - ('a' - 10)); + if (extraHexDigit >= '0' && extraHexDigit <= '9') + { + return currentParsedSize * 0x10 + (extraHexDigit - '0'); + } + else if (extraHexDigit >= 'A' && extraHexDigit <= 'F') + { + return currentParsedSize * 0x10 + (extraHexDigit - ('A' - 10)); + } + else if (extraHexDigit >= 'a' && extraHexDigit <= 'f') + { + return currentParsedSize * 0x10 + (extraHexDigit - ('a' - 10)); + } } } + catch (OverflowException ex) + { + throw new IOException(CoreStrings.BadRequest_BadChunkSizeData, ex); + } - _context.RejectRequest(RequestRejectionReason.BadChunkSizeData); + _context.ThrowRequestRejected(RequestRejectionReason.BadChunkSizeData); return -1; // can't happen, but compiler complains } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/RequestRejectionReason.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/RequestRejectionReason.cs index 730badcff8..b482c87a02 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/RequestRejectionReason.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/RequestRejectionReason.cs @@ -21,6 +21,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http RequestLineTooLong, HeadersExceedMaxTotalSize, TooManyHeaders, + RequestBodyTooLarge, RequestTimeout, FinalTransferCodingNotChunked, LengthRequired, diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/Streams.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/Streams.cs index c81f9c3985..994ee2d31c 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/Streams.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/Streams.cs @@ -60,13 +60,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure _response.PauseAcceptingWrites(); } - public void Resume() - { - _request.ResumeAcceptingReads(); - _emptyRequest.ResumeAcceptingReads(); - _response.ResumeAcceptingWrites(); - } - public void Stop() { _request.StopAcceptingReads(); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/KestrelServerLimits.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/KestrelServerLimits.cs index dc86c064e6..3e02eaad9f 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/KestrelServerLimits.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/KestrelServerLimits.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using Microsoft.AspNetCore.Http.Features; namespace Microsoft.AspNetCore.Server.Kestrel.Core { @@ -20,6 +21,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core // Matches the default large_client_header_buffers in nginx. private int _maxRequestHeadersTotalSize = 32 * 1024; + // Matches the default maxAllowedContentLength in IIS (~28.6 MB) + // https://www.iis.net/configreference/system.webserver/security/requestfiltering/requestlimits#005 + private long? _maxRequestBodySize = 30000000; + // Matches the default LimitRequestFields in Apache httpd. private int _maxRequestHeaderCount = 100; @@ -133,6 +138,28 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core } } + /// + /// Gets or sets the maximum allowed size of any request body in bytes. + /// When set to null, the maximum request body size is unlimited. + /// This limit has no effect on upgraded connections which are always unlimited. + /// This can be overridden per-request via . + /// + /// + /// Defaults to null (unlimited). + /// + public long? MaxRequestBodySize + { + get => _maxRequestBodySize; + set + { + if (value < 0) + { + throw new ArgumentOutOfRangeException(nameof(value), CoreStrings.NonNegativeNumberOrNullRequired); + } + _maxRequestBodySize = value; + } + } + /// /// Gets or sets the keep-alive timeout. /// diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Properties/CoreStrings.Designer.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Properties/CoreStrings.Designer.cs index 5303d1e5b8..877d6d308b 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Properties/CoreStrings.Designer.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Properties/CoreStrings.Designer.cs @@ -948,6 +948,48 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core internal static string FormatUpgradeCannotBeCalledMultipleTimes() => GetString("UpgradeCannotBeCalledMultipleTimes"); + /// + /// Request body too large. + /// + internal static string BadRequest_RequestBodyTooLarge + { + get => GetString("BadRequest_RequestBodyTooLarge"); + } + + /// + /// Request body too large. + /// + internal static string FormatBadRequest_RequestBodyTooLarge() + => GetString("BadRequest_RequestBodyTooLarge"); + + /// + /// The maximum request body size cannot be modified after the app has already started reading from the request body. + /// + internal static string MaxRequestBodySizeCannotBeModifiedAfterRead + { + get => GetString("MaxRequestBodySizeCannotBeModifiedAfterRead"); + } + + /// + /// The maximum request body size cannot be modified after the app has already started reading from the request body. + /// + internal static string FormatMaxRequestBodySizeCannotBeModifiedAfterRead() + => GetString("MaxRequestBodySizeCannotBeModifiedAfterRead"); + + /// + /// The maximum request body size cannot be modified after the request has be upgraded. + /// + internal static string MaxRequestBodySizeCannotBeModifiedForUpgradedRequests + { + get => GetString("MaxRequestBodySizeCannotBeModifiedForUpgradedRequests"); + } + + /// + /// The maximum request body size cannot be modified after the request has be upgraded. + /// + internal static string FormatMaxRequestBodySizeCannotBeModifiedForUpgradedRequests() + => GetString("MaxRequestBodySizeCannotBeModifiedForUpgradedRequests"); + private static string GetString(string name, params string[] formatterNames) { var value = _resourceManager.GetString(name); diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameTests.cs index ca5eb53008..e8d2481942 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameTests.cs @@ -6,7 +6,6 @@ using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; -using System.Net; using System.Text; using System.Threading; using System.Threading.Tasks; @@ -17,7 +16,6 @@ using Microsoft.AspNetCore.Server.Kestrel.Core.Internal; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; -using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions; using Microsoft.AspNetCore.Testing; using Microsoft.Extensions.Internal; using Microsoft.Extensions.Logging; @@ -733,6 +731,27 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests await requestProcessingTask.TimeoutAfter(TimeSpan.FromSeconds(10)); } + [Fact] + public void ThrowsWhenMaxRequestBodySizeIsSetAfterReadingFromRequestBody() + { + // Act + // This would normally be set by the MessageBody during the first read. + _frame.HasStartedConsumingRequestBody = true; + + // Assert + Assert.True(((IHttpMaxRequestBodySizeFeature)_frame).IsReadOnly); + var ex = Assert.Throws(() => ((IHttpMaxRequestBodySizeFeature)_frame).MaxRequestBodySize = 1); + Assert.Equal(CoreStrings.MaxRequestBodySizeCannotBeModifiedAfterRead, ex.Message); + } + + [Fact] + public void ThrowsWhenMaxRequestBodySizeIsSetToANegativeValue() + { + // Assert + var ex = Assert.Throws(() => ((IHttpMaxRequestBodySizeFeature)_frame).MaxRequestBodySize = -1); + Assert.StartsWith(CoreStrings.NonNegativeNumberOrNullRequired, ex.Message); + } + private static async Task WaitForCondition(TimeSpan timeout, Func condition) { const int MaxWaitLoop = 150; diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/KestrelServerLimitsTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/KestrelServerLimitsTests.cs index 25db797284..863dfd7ff4 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/KestrelServerLimitsTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/KestrelServerLimitsTests.cs @@ -241,5 +241,36 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests var ex = Assert.Throws(() => new KestrelServerLimits().MaxConcurrentUpgradedConnections = value); Assert.StartsWith(CoreStrings.NonNegativeNumberOrNullRequired, ex.Message); } + + [Fact] + public void MaxRequestBodySizeDefault() + { + // ~28.6 MB (https://www.iis.net/configreference/system.webserver/security/requestfiltering/requestlimits#005) + Assert.Equal(30000000, new KestrelServerLimits().MaxRequestBodySize); + } + + [Theory] + [InlineData(null)] + [InlineData(0)] + [InlineData(1)] + [InlineData(long.MaxValue)] + public void MaxRequestBodySizeValid(long? value) + { + var limits = new KestrelServerLimits + { + MaxRequestBodySize = value + }; + + Assert.Equal(value, limits.MaxRequestBodySize); + } + + [Theory] + [InlineData(long.MinValue)] + [InlineData(-1)] + public void MaxRequestBodySizeInvalid(long value) + { + var ex = Assert.Throws(() => new KestrelServerLimits().MaxRequestBodySize = value); + Assert.StartsWith(CoreStrings.NonNegativeNumberOrNullRequired, ex.Message); + } } } diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/MessageBodyTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/MessageBodyTests.cs index bf61a5df51..1bb42355f6 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/MessageBodyTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/MessageBodyTests.cs @@ -26,7 +26,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests [Theory] [InlineData(HttpVersion.Http10)] [InlineData(HttpVersion.Http11)] - public async Task CanReadFromContentLength(HttpVersion httpVersion) + public void CanReadFromContentLength(HttpVersion httpVersion) { using (var input = new TestInput()) { @@ -34,8 +34,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests var stream = new FrameRequestStream(); stream.StartAcceptingReads(body); - var bodyTask = body.StartAsync(); - input.Add("Hello"); var buffer = new byte[1024]; @@ -46,8 +44,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests count = stream.Read(buffer, 0, buffer.Length); Assert.Equal(0, count); - - await bodyTask; } } @@ -62,8 +58,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests var stream = new FrameRequestStream(); stream.StartAcceptingReads(body); - var bodyTask = body.StartAsync(); - input.Add("Hello"); var buffer = new byte[1024]; @@ -74,13 +68,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests count = await stream.ReadAsync(buffer, 0, buffer.Length); Assert.Equal(0, count); - - await bodyTask; } } [Fact] - public async Task CanReadFromChunkedEncoding() + public void CanReadFromChunkedEncoding() { using (var input = new TestInput()) { @@ -88,8 +80,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests var stream = new FrameRequestStream(); stream.StartAcceptingReads(body); - var bodyTask = body.StartAsync(); - input.Add("5\r\nHello\r\n"); var buffer = new byte[1024]; @@ -102,8 +92,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests count = stream.Read(buffer, 0, buffer.Length); Assert.Equal(0, count); - - await bodyTask; } } @@ -116,8 +104,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests var stream = new FrameRequestStream(); stream.StartAcceptingReads(body); - var bodyTask = body.StartAsync(); - input.Add("5\r\nHello\r\n"); var buffer = new byte[1024]; @@ -130,15 +116,74 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests count = await stream.ReadAsync(buffer, 0, buffer.Length); Assert.Equal(0, count); + } + } - await bodyTask; + [Fact] + public async Task ReadExitsGivenIncompleteChunkedExtension() + { + using (var input = new TestInput()) + { + var body = MessageBody.For(HttpVersion.Http11, new FrameRequestHeaders { HeaderTransferEncoding = "chunked" }, input.FrameContext); + var stream = new FrameRequestStream(); + stream.StartAcceptingReads(body); + + input.Add("5;\r\0"); + + var buffer = new byte[1024]; + var readTask = stream.ReadAsync(buffer, 0, buffer.Length); + + Assert.False(readTask.IsCompleted); + + input.Add("\r\r\r\nHello\r\n0\r\n\r\n"); + + Assert.Equal(5, await readTask.TimeoutAfter(TimeSpan.FromSeconds(10))); + Assert.Equal(0, await stream.ReadAsync(buffer, 0, buffer.Length)); + } + } + + [Fact] + public async Task ReadThrowsGivenChunkPrefixGreaterThanMaxInt() + { + using (var input = new TestInput()) + { + var body = MessageBody.For(HttpVersion.Http11, new FrameRequestHeaders { HeaderTransferEncoding = "chunked" }, input.FrameContext); + var stream = new FrameRequestStream(); + stream.StartAcceptingReads(body); + + input.Add("80000000\r\n"); + + var buffer = new byte[1024]; + var ex = await Assert.ThrowsAsync(async () => + await stream.ReadAsync(buffer, 0, buffer.Length)); + Assert.IsType(ex.InnerException); + Assert.Equal(CoreStrings.BadRequest_BadChunkSizeData, ex.Message); + } + } + + [Fact] + public async Task ReadThrowsGivenChunkPrefixGreaterThan8Bytes() + { + using (var input = new TestInput()) + { + var body = MessageBody.For(HttpVersion.Http11, new FrameRequestHeaders { HeaderTransferEncoding = "chunked" }, input.FrameContext); + var stream = new FrameRequestStream(); + stream.StartAcceptingReads(body); + + input.Add("012345678\r"); + + var buffer = new byte[1024]; + var ex = await Assert.ThrowsAsync(async () => + await stream.ReadAsync(buffer, 0, buffer.Length)); + + Assert.Equal(CoreStrings.BadRequest_BadChunkSizeData, ex.Message); } } [Theory] [InlineData(HttpVersion.Http10)] [InlineData(HttpVersion.Http11)] - public async Task CanReadFromRemainingData(HttpVersion httpVersion) + public void CanReadFromRemainingData(HttpVersion httpVersion) { using (var input = new TestInput()) { @@ -146,8 +191,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests var stream = new FrameRequestStream(); stream.StartAcceptingReads(body); - var bodyTask = body.StartAsync(); - input.Add("Hello"); var buffer = new byte[1024]; @@ -157,8 +200,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests AssertASCII("Hello", new ArraySegment(buffer, 0, count)); input.Fin(); - - await bodyTask; } } @@ -173,8 +214,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests var stream = new FrameRequestStream(); stream.StartAcceptingReads(body); - var bodyTask = body.StartAsync(); - input.Add("Hello"); var buffer = new byte[1024]; @@ -184,15 +223,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests AssertASCII("Hello", new ArraySegment(buffer, 0, count)); input.Fin(); - - await bodyTask; } } [Theory] [InlineData(HttpVersion.Http10)] [InlineData(HttpVersion.Http11)] - public async Task ReadFromNoContentLengthReturnsZero(HttpVersion httpVersion) + public void ReadFromNoContentLengthReturnsZero(HttpVersion httpVersion) { using (var input = new TestInput()) { @@ -200,14 +237,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests var stream = new FrameRequestStream(); stream.StartAcceptingReads(body); - var bodyTask = body.StartAsync(); - input.Add("Hello"); var buffer = new byte[1024]; Assert.Equal(0, stream.Read(buffer, 0, buffer.Length)); - - await bodyTask; } } @@ -222,14 +255,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests var stream = new FrameRequestStream(); stream.StartAcceptingReads(body); - var bodyTask = body.StartAsync(); - input.Add("Hello"); var buffer = new byte[1024]; Assert.Equal(0, await stream.ReadAsync(buffer, 0, buffer.Length)); - - await bodyTask; } } @@ -242,8 +271,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests var stream = new FrameRequestStream(); stream.StartAcceptingReads(body); - var bodyTask = body.StartAsync(); - // Input needs to be greater than 4032 bytes to allocate a block not backed by a slab. var largeInput = new string('a', 8192); @@ -258,8 +285,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests var requestArray = ms.ToArray(); Assert.Equal(8197, requestArray.Length); AssertASCII(largeInput + "Hello", new ArraySegment(requestArray, 0, requestArray.Length)); - - await bodyTask; } } @@ -314,8 +339,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests using (var input = new TestInput()) { var body = MessageBody.For(HttpVersion.Http10, new FrameRequestHeaders { HeaderContentLength = "5" }, input.FrameContext); - var bodyTask = body.StartAsync(); - input.Add("Hello"); using (var ms = new MemoryStream()) @@ -324,8 +347,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests } Assert.Equal(0, await body.ReadAsync(new ArraySegment(new byte[1]))); - - await bodyTask; } } @@ -335,15 +356,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests using (var input = new TestInput()) { var body = MessageBody.For(HttpVersion.Http10, new FrameRequestHeaders { HeaderContentLength = "5" }, input.FrameContext); - var bodyTask = body.StartAsync(); - input.Add("Hello"); await body.ConsumeAsync(); await Assert.ThrowsAsync(async () => await body.ReadAsync(new ArraySegment(new byte[1]))); - - await bodyTask; } } @@ -386,8 +403,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests using (var input = new TestInput()) { var body = MessageBody.For(HttpVersion.Http11, headers, input.FrameContext); - var bodyTask = body.StartAsync(); - var copyToAsyncTask = body.CopyToAsync(mockDestination.Object); // The block returned by IncomingStart always has at least 2048 available bytes, @@ -421,8 +436,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests await copyToAsyncTask; Assert.Equal(2, writeCount); - - await bodyTask; } } @@ -431,7 +444,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests [InlineData("Keep-Alive, Upgrade")] [InlineData("upgrade, keep-alive")] [InlineData("Upgrade, Keep-Alive")] - public async Task ConnectionUpgradeKeepAlive(string headerConnection) + public void ConnectionUpgradeKeepAlive(string headerConnection) { using (var input = new TestInput()) { @@ -439,8 +452,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests var stream = new FrameRequestStream(); stream.StartAcceptingReads(body); - var bodyTask = body.StartAsync(); - input.Add("Hello"); var buffer = new byte[1024]; @@ -448,8 +459,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests AssertASCII("Hello", new ArraySegment(buffer, 0, 5)); input.Fin(); - - await bodyTask; } } @@ -462,8 +471,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests var stream = new FrameRequestStream(); stream.StartAcceptingReads(body); - var bodyTask = body.StartAsync(); - // Add some input and consume it to ensure StartAsync is in the loop input.Add("a"); Assert.Equal(1, await stream.ReadAsync(new byte[1], 0, 1)); @@ -474,8 +481,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests input.Add("b"); Assert.Equal(1, await stream.ReadAsync(new byte[1], 0, 1)); - // All input was read, body task should complete - await bodyTask; } } @@ -488,8 +493,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests var stream = new FrameRequestStream(); stream.StartAcceptingReads(body); - var bodyTask = body.StartAsync(); - // Add some input and consume it to ensure StartAsync is in the loop input.Add("a"); Assert.Equal(1, await stream.ReadAsync(new byte[1], 0, 1)); @@ -503,8 +506,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests // Unblock the loop input.Pipe.Reader.CancelPendingRead(); - await bodyTask.TimeoutAfter(TimeSpan.FromSeconds(10)); - // There shouldn't be any additional data available Assert.Equal(0, await stream.ReadAsync(new byte[1], 0, 1)); } diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/StreamsTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/StreamsTests.cs index 95eae94658..6a7b108228 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/StreamsTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/StreamsTests.cs @@ -80,13 +80,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests { RequestUpgrade = upgradeable; } - - protected override bool Read(ReadableBuffer readableBuffer, WritableBuffer writableBuffer, out ReadCursor consumed, out ReadCursor examined) - { - consumed = default(ReadCursor); - examined = default(ReadCursor); - return true; - } } } } diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/MaxRequestBodySizeTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/MaxRequestBodySizeTests.cs new file mode 100644 index 0000000000..9d61ffb19f --- /dev/null +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/MaxRequestBodySizeTests.cs @@ -0,0 +1,494 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Text; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Http.Features; +using Microsoft.AspNetCore.Server.Kestrel.Core; +using Microsoft.AspNetCore.Testing; +using Xunit; + +namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests +{ + public class MaxRequestBodySizeTests + { + [Fact] + public async Task RejectsRequestWithContentLengthHeaderExceedingGlobalLimit() + { + // 4 GiB + var globalMaxRequestBodySize = 0x100000000; + BadHttpRequestException requestRejectedEx = null; + + using (var server = new TestServer(async context => + { + var buffer = new byte[1]; + requestRejectedEx = await Assert.ThrowsAsync( + async () => await context.Request.Body.ReadAsync(buffer, 0, 1)); + throw requestRejectedEx; + }, + new TestServiceContext { ServerOptions = { Limits = { MaxRequestBodySize = globalMaxRequestBodySize } } })) + { + using (var connection = server.CreateConnection()) + { + await connection.Send( + "POST / HTTP/1.1", + "Host:", + "Content-Length: " + (globalMaxRequestBodySize + 1), + "", + ""); + await connection.ReceiveForcedEnd( + "HTTP/1.1 413 Payload Too Large", + "Connection: close", + $"Date: {server.Context.DateHeaderValue}", + "Content-Length: 0", + "", + ""); + } + } + + Assert.NotNull(requestRejectedEx); + Assert.Equal(CoreStrings.BadRequest_RequestBodyTooLarge, requestRejectedEx.Message); + } + + [Fact] + public async Task RejectsRequestWithContentLengthHeaderExceedingPerRequestLimit() + { + // 8 GiB + var globalMaxRequestBodySize = 0x200000000; + // 4 GiB + var perRequestMaxRequestBodySize = 0x100000000; + BadHttpRequestException requestRejectedEx = null; + + using (var server = new TestServer(async context => + { + var feature = context.Features.Get(); + Assert.Equal(globalMaxRequestBodySize, feature.MaxRequestBodySize); + + // Disable the MaxRequestBodySize prior to calling Request.Body.ReadAsync(); + feature.MaxRequestBodySize = perRequestMaxRequestBodySize; + + var buffer = new byte[1]; + requestRejectedEx = await Assert.ThrowsAsync( + async () => await context.Request.Body.ReadAsync(buffer, 0, 1)); + throw requestRejectedEx; + }, + new TestServiceContext { ServerOptions = { Limits = { MaxRequestBodySize = globalMaxRequestBodySize } } })) + { + using (var connection = server.CreateConnection()) + { + await connection.Send( + "POST / HTTP/1.1", + "Host:", + "Content-Length: " + (perRequestMaxRequestBodySize + 1), + "", + ""); + await connection.ReceiveForcedEnd( + "HTTP/1.1 413 Payload Too Large", + "Connection: close", + $"Date: {server.Context.DateHeaderValue}", + "Content-Length: 0", + "", + ""); + } + } + + Assert.NotNull(requestRejectedEx); + Assert.Equal(CoreStrings.BadRequest_RequestBodyTooLarge, requestRejectedEx.Message); + } + + [Fact] + public async Task DoesNotRejectRequestWithContentLengthHeaderExceedingGlobalLimitIfLimitDisabledPerRequest() + { + using (var server = new TestServer(async context => + { + var feature = context.Features.Get(); + Assert.Equal(0, feature.MaxRequestBodySize); + + // Disable the MaxRequestBodySize prior to calling Request.Body.ReadAsync(); + feature.MaxRequestBodySize = null; + + var buffer = new byte[1]; + + Assert.Equal(1, await context.Request.Body.ReadAsync(buffer, 0, 1)); + Assert.Equal(buffer[0], (byte)'A'); + Assert.Equal(0, await context.Request.Body.ReadAsync(buffer, 0, 1)); + + context.Response.ContentLength = 1; + await context.Response.Body.WriteAsync(buffer, 0, 1); + }, + new TestServiceContext { ServerOptions = { Limits = { MaxRequestBodySize = 0 } } })) + { + using (var connection = server.CreateConnection()) + { + await connection.Send( + "POST / HTTP/1.1", + "Host:", + "Content-Length: 1", + "", + "A"); + await connection.Receive( + "HTTP/1.1 200 OK", + $"Date: {server.Context.DateHeaderValue}", + "Content-Length: 1", + "", + "A"); + } + } + } + + [Fact] + public async Task DoesNotRejectBodylessGetRequestWithZeroMaxRequestBodySize() + { + using (var server = new TestServer(context => Task.CompletedTask, + new TestServiceContext { ServerOptions = { Limits = { MaxRequestBodySize = 0 } } })) + { + using (var connection = server.CreateConnection()) + { + await connection.Send( + "GET / HTTP/1.1", + "Host:", + "", + "POST / HTTP/1.1", + "Host:", + "Content-Length: 1", + "", + "A"); + await connection.ReceiveForcedEnd( + "HTTP/1.1 200 OK", + $"Date: {server.Context.DateHeaderValue}", + "Content-Length: 0", + "", + "HTTP/1.1 413 Payload Too Large", + "Connection: close", + $"Date: {server.Context.DateHeaderValue}", + "Content-Length: 0", + "", + ""); + } + } + } + + [Fact] + public async Task SettingMaxRequestBodySizeAfterReadingFromRequestBodyThrows() + { + var perRequestMaxRequestBodySize = 0x10; + var payloadSize = perRequestMaxRequestBodySize + 1; + var payload = new string('A', payloadSize); + InvalidOperationException invalidOpEx = null; + + using (var server = new TestServer(async context => + { + var buffer = new byte[1]; + Assert.Equal(1, await context.Request.Body.ReadAsync(buffer, 0, 1)); + + var feature = context.Features.Get(); + Assert.Equal(new KestrelServerLimits().MaxRequestBodySize, feature.MaxRequestBodySize); + Assert.True(feature.IsReadOnly); + + invalidOpEx = Assert.Throws(() => + feature.MaxRequestBodySize = perRequestMaxRequestBodySize); + throw invalidOpEx; + })) + { + using (var connection = server.CreateConnection()) + { + await connection.Send( + "POST / HTTP/1.1", + "Host:", + "Content-Length: " + payloadSize, + "", + payload); + await connection.Receive( + "HTTP/1.1 500 Internal Server Error", + $"Date: {server.Context.DateHeaderValue}", + "Content-Length: 0", + "", + ""); + } + } + + Assert.NotNull(invalidOpEx); + Assert.Equal(CoreStrings.MaxRequestBodySizeCannotBeModifiedAfterRead, invalidOpEx.Message); + } + + [Fact] + public async Task SettingMaxRequestBodySizeAfterUpgradingRequestThrows() + { + InvalidOperationException invalidOpEx = null; + + using (var server = new TestServer(async context => + { + var upgradeFeature = context.Features.Get(); + var stream = await upgradeFeature.UpgradeAsync(); + + var feature = context.Features.Get(); + Assert.Equal(new KestrelServerLimits().MaxRequestBodySize, feature.MaxRequestBodySize); + Assert.True(feature.IsReadOnly); + + invalidOpEx = Assert.Throws(() => + feature.MaxRequestBodySize = 0x10); + throw invalidOpEx; + })) + { + using (var connection = server.CreateConnection()) + { + await connection.Send("GET / HTTP/1.1", + "Host:", + "Connection: Upgrade", + "", + ""); + await connection.Receive("HTTP/1.1 101 Switching Protocols", + "Connection: Upgrade", + $"Date: {server.Context.DateHeaderValue}", + "", + ""); + await connection.ReceiveForcedEnd(); + } + } + + Assert.NotNull(invalidOpEx); + Assert.Equal(CoreStrings.MaxRequestBodySizeCannotBeModifiedForUpgradedRequests, invalidOpEx.Message); + } + + [Fact] + public async Task EveryReadFailsWhenContentLengthHeaderExceedsGlobalLimit() + { + BadHttpRequestException requestRejectedEx1 = null; + BadHttpRequestException requestRejectedEx2 = null; + + using (var server = new TestServer(async context => + { + var buffer = new byte[1]; + requestRejectedEx1 = await Assert.ThrowsAsync( + async () => await context.Request.Body.ReadAsync(buffer, 0, 1)); + requestRejectedEx2 = await Assert.ThrowsAsync( + async () => await context.Request.Body.ReadAsync(buffer, 0, 1)); + throw requestRejectedEx2; + }, + new TestServiceContext { ServerOptions = { Limits = { MaxRequestBodySize = 0 } } })) + { + using (var connection = server.CreateConnection()) + { + await connection.Send( + "POST / HTTP/1.1", + "Host:", + "Content-Length: " + (new KestrelServerLimits().MaxRequestBodySize + 1), + "", + ""); + await connection.ReceiveForcedEnd( + "HTTP/1.1 413 Payload Too Large", + "Connection: close", + $"Date: {server.Context.DateHeaderValue}", + "Content-Length: 0", + "", + ""); + } + } + + Assert.NotNull(requestRejectedEx1); + Assert.NotNull(requestRejectedEx2); + Assert.Equal(CoreStrings.BadRequest_RequestBodyTooLarge, requestRejectedEx1.Message); + Assert.Equal(CoreStrings.BadRequest_RequestBodyTooLarge, requestRejectedEx2.Message); + } + + [Fact] + public async Task ChunkFramingAndExtensionsCountTowardsRequestBodySize() + { + var chunkedPayload = "5;random chunk extension\r\nHello\r\n6\r\n World\r\n0\r\n\r\n"; + var globalMaxRequestBodySize = chunkedPayload.Length - 1; + BadHttpRequestException requestRejectedEx = null; + + using (var server = new TestServer(async context => + { + var buffer = new byte[11]; + requestRejectedEx = await Assert.ThrowsAsync(async () => + { + var count = 0; + do + { + count = await context.Request.Body.ReadAsync(buffer, 0, 11); + } while (count != 0); + }); + + throw requestRejectedEx; + }, + new TestServiceContext { ServerOptions = { Limits = { MaxRequestBodySize = globalMaxRequestBodySize } } })) + { + using (var connection = server.CreateConnection()) + { + await connection.Send( + "POST / HTTP/1.1", + "Host:", + "Transfer-Encoding: chunked", + "", + chunkedPayload); + await connection.ReceiveForcedEnd( + "HTTP/1.1 413 Payload Too Large", + "Connection: close", + $"Date: {server.Context.DateHeaderValue}", + "Content-Length: 0", + "", + ""); + } + } + + Assert.NotNull(requestRejectedEx); + Assert.Equal(CoreStrings.BadRequest_RequestBodyTooLarge, requestRejectedEx.Message); + } + + [Fact] + public async Task TrailingHeadersDoNotCountTowardsRequestBodySize() + { + var chunkedPayload = $"5;random chunk extension\r\nHello\r\n6\r\n World\r\n0\r\n"; + var trailingHeaders = "Trailing-Header: trailing-value\r\n\r\n"; + var globalMaxRequestBodySize = chunkedPayload.Length; + + using (var server = new TestServer(async context => + { + var offset = 0; + var count = 0; + var buffer = new byte[11]; + + do + { + count = await context.Request.Body.ReadAsync(buffer, offset, 11 - offset); + offset += count; + } while (count != 0); + + Assert.Equal("Hello World", Encoding.ASCII.GetString(buffer)); + Assert.Equal("trailing-value", context.Request.Headers["Trailing-Header"].ToString()); + }, + new TestServiceContext { ServerOptions = { Limits = { MaxRequestBodySize = globalMaxRequestBodySize } } })) + { + using (var connection = server.CreateConnection()) + { + await connection.Send( + "POST / HTTP/1.1", + "Host:", + "Transfer-Encoding: chunked", + "", + chunkedPayload + trailingHeaders); + await connection.Receive( + "HTTP/1.1 200 OK", + $"Date: {server.Context.DateHeaderValue}", + "Content-Length: 0", + "", + ""); + } + } + } + + [Fact] + public async Task PerRequestMaxRequestBodySizeGetsReset() + { + var chunkedPayload = "5;random chunk extension\r\nHello\r\n6\r\n World\r\n0\r\n\r\n"; + var globalMaxRequestBodySize = chunkedPayload.Length - 1; + var firstRequest = true; + BadHttpRequestException requestRejectedEx = null; + + using (var server = new TestServer(async context => + { + var feature = context.Features.Get(); + Assert.Equal(globalMaxRequestBodySize, feature.MaxRequestBodySize); + + var buffer = new byte[11]; + var count = 0; + + if (firstRequest) + { + firstRequest = false; + feature.MaxRequestBodySize = chunkedPayload.Length; + + do + { + count = await context.Request.Body.ReadAsync(buffer, 0, 11); + } while (count != 0); + } + else + { + requestRejectedEx = await Assert.ThrowsAsync(async () => + { + do + { + count = await context.Request.Body.ReadAsync(buffer, 0, 11); + } while (count != 0); + }); + + throw requestRejectedEx; + } + }, + new TestServiceContext { ServerOptions = { Limits = { MaxRequestBodySize = globalMaxRequestBodySize } } })) + { + using (var connection = server.CreateConnection()) + { + await connection.Send( + "POST / HTTP/1.1", + "Host:", + "Transfer-Encoding: chunked", + "", + chunkedPayload + "POST / HTTP/1.1", + "Host:", + "Transfer-Encoding: chunked", + "", + chunkedPayload); + await connection.ReceiveForcedEnd( + "HTTP/1.1 200 OK", + $"Date: {server.Context.DateHeaderValue}", + "Content-Length: 0", + "", + "HTTP/1.1 413 Payload Too Large", + "Connection: close", + $"Date: {server.Context.DateHeaderValue}", + "Content-Length: 0", + "", + ""); + } + } + + Assert.NotNull(requestRejectedEx); + Assert.Equal(CoreStrings.BadRequest_RequestBodyTooLarge, requestRejectedEx.Message); + } + + [Fact] + public async Task EveryReadFailsWhenChunkedPayloadExceedsGlobalLimit() + { + BadHttpRequestException requestRejectedEx1 = null; + BadHttpRequestException requestRejectedEx2 = null; + + using (var server = new TestServer(async context => + { + var buffer = new byte[1]; + requestRejectedEx1 = await Assert.ThrowsAsync( + async () => await context.Request.Body.ReadAsync(buffer, 0, 1)); + requestRejectedEx2 = await Assert.ThrowsAsync( + async () => await context.Request.Body.ReadAsync(buffer, 0, 1)); + throw requestRejectedEx2; + }, + new TestServiceContext { ServerOptions = { Limits = { MaxRequestBodySize = 0 } } })) + { + using (var connection = server.CreateConnection()) + { + await connection.Send( + "POST / HTTP/1.1", + "Host:", + "Transfer-Encoding: chunked", + "", + "1\r\n"); + await connection.ReceiveForcedEnd( + "HTTP/1.1 413 Payload Too Large", + "Connection: close", + $"Date: {server.Context.DateHeaderValue}", + "Content-Length: 0", + "", + ""); + } + } + + Assert.NotNull(requestRejectedEx1); + Assert.NotNull(requestRejectedEx2); + Assert.Equal(CoreStrings.BadRequest_RequestBodyTooLarge, requestRejectedEx1.Message); + Assert.Equal(CoreStrings.BadRequest_RequestBodyTooLarge, requestRejectedEx2.Message); + } + } +} diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs index a5fbc348aa..50004ca37a 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs @@ -59,7 +59,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests Assert.True(bufferLength % 256 == 0, $"{nameof(bufferLength)} must be evenly divisible by 256"); var builder = new WebHostBuilder() - .UseKestrel() + .UseKestrel(o => + { + o.Limits.MaxRequestBodySize = contentLength; + }) .UseUrls("http://127.0.0.1:0/") .Configure(app => { diff --git a/test/shared/TestConnection.cs b/test/shared/TestConnection.cs index f4ff0a2b62..fc6458c287 100644 --- a/test/shared/TestConnection.cs +++ b/test/shared/TestConnection.cs @@ -117,20 +117,31 @@ namespace Microsoft.AspNetCore.Testing var expected = string.Join("\r\n", lines); var actual = new char[expected.Length]; var offset = 0; - while (offset < expected.Length) + + try { - var data = new byte[expected.Length]; - var task = _reader.ReadAsync(actual, offset, actual.Length - offset); - if (!Debugger.IsAttached) + while (offset < expected.Length) { - task = task.TimeoutAfter(Timeout); + var data = new byte[expected.Length]; + var task = _reader.ReadAsync(actual, offset, actual.Length - offset); + if (!Debugger.IsAttached) + { + task = task.TimeoutAfter(Timeout); + } + var count = await task.ConfigureAwait(false); + if (count == 0) + { + break; + } + offset += count; } - var count = await task.ConfigureAwait(false); - if (count == 0) - { - break; - } - offset += count; + } + catch (TimeoutException ex) when (offset != 0) + { + throw new TimeoutException($"Did not receive a complete response within {Timeout}.{Environment.NewLine}{Environment.NewLine}" + + $"Expected:{Environment.NewLine}{expected}{Environment.NewLine}{Environment.NewLine}" + + $"Actual:{Environment.NewLine}{new string(actual, 0, offset)}{Environment.NewLine}", + ex); } Assert.Equal(expected, new string(actual, 0, offset)); diff --git a/tools/CodeGenerator/FrameFeatureCollection.cs b/tools/CodeGenerator/FrameFeatureCollection.cs index 01b9c1cfa9..d97136380d 100644 --- a/tools/CodeGenerator/FrameFeatureCollection.cs +++ b/tools/CodeGenerator/FrameFeatureCollection.cs @@ -44,7 +44,8 @@ namespace CodeGenerator typeof(IItemsFeature), typeof(ITlsConnectionFeature), typeof(IHttpWebSocketFeature), - typeof(ISessionFeature) + typeof(ISessionFeature), + typeof(IHttpMaxRequestBodySizeFeature) }; var rareFeatures = new[] @@ -64,6 +65,7 @@ namespace CodeGenerator typeof(IHttpRequestIdentifierFeature), typeof(IHttpRequestLifetimeFeature), typeof(IHttpConnectionFeature), + typeof(IHttpMaxRequestBodySizeFeature) }; return $@"// Copyright (c) .NET Foundation. All rights reserved. From 3f771ef0bc8093d4ba929a71816a3ace0de22a39 Mon Sep 17 00:00:00 2001 From: Pranav K Date: Thu, 8 Jun 2017 13:47:01 -0700 Subject: [PATCH 1315/1662] Remove usage of TaskCache (#1889) * Remove usage of TaskCache --- .../Internal/Http/Frame.cs | 17 +++---- .../Internal/Http/FrameRequestStream.cs | 4 +- .../Internal/Http/OutputProducer.cs | 5 +- ...soft.AspNetCore.Server.Kestrel.Core.csproj | 1 - .../Internal/ClosedStream.cs | 5 +- ...oft.AspNetCore.Server.Kestrel.Https.csproj | 1 - ...Core.Server.Kestrel.Transport.Libuv.csproj | 1 - .../FrameTests.cs | 3 +- .../KestrelServerTests.cs | 4 +- .../MessageBodyTests.cs | 6 +-- .../TestHelpers/MockFrameControl.cs | 5 +- .../TestInput.cs | 9 +--- .../BadHttpRequestTests.cs | 3 +- .../ChunkedRequestTests.cs | 3 +- .../DefaultHeaderTests.cs | 3 +- .../HttpsConnectionAdapterTests.cs | 9 ++-- .../RequestTests.cs | 7 ++- .../ResponseTests.cs | 49 +++++++++---------- .../UpgradeTests.cs | 7 ++- test/shared/TestApp.cs | 3 +- 20 files changed, 60 insertions(+), 85 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.cs index 6919a10ccb..7db00bebb1 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.cs @@ -12,15 +12,14 @@ using System.Text; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Internal.System; using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; using Microsoft.AspNetCore.Server.Kestrel.Internal.System.Text.Encodings.Web.Utf8; using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions; -using Microsoft.Extensions.Internal; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Primitives; -using Microsoft.AspNetCore.Http.Features; // ReSharper disable AccessToModifiedClosure @@ -526,7 +525,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { if (data.Count == 0) { - return TaskCache.CompletedTask; + return Task.CompletedTask; } return WriteChunkedAsync(data, cancellationToken); } @@ -539,7 +538,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http else { HandleNonBodyResponseWrite(); - return TaskCache.CompletedTask; + return Task.CompletedTask; } } @@ -665,7 +664,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { if (HasResponseStarted) { - return TaskCache.CompletedTask; + return Task.CompletedTask; } if (_onStarting != null) @@ -681,7 +680,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http VerifyAndUpdateWrite(firstWriteByteCount); ProduceStart(appCompleted: false); - return TaskCache.CompletedTask; + return Task.CompletedTask; } private async Task InitializeResponseAwaited(int firstWriteByteCount) @@ -716,7 +715,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http return ProduceEnd(); } - return TaskCache.CompletedTask; + return Task.CompletedTask; } protected Task ProduceEnd() @@ -727,7 +726,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { // We can no longer change the response, so we simply close the connection. _requestProcessingStopping = true; - return TaskCache.CompletedTask; + return Task.CompletedTask; } // If the request was rejected, the error state has already been set by SetBadRequestState and @@ -780,7 +779,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http Log.ConnectionHeadResponseBodyWrite(ConnectionId, _responseBytesWritten); } - return TaskCache.CompletedTask; + return Task.CompletedTask; } private async Task WriteAutoChunkSuffixAwaited() diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameRequestStream.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameRequestStream.cs index ce518d17d8..65665d543b 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameRequestStream.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameRequestStream.cs @@ -3,12 +3,10 @@ using System; using System.IO; -using System.Runtime.ExceptionServices; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions; -using Microsoft.Extensions.Internal; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { @@ -42,7 +40,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http public override Task FlushAsync(CancellationToken cancellationToken) { // No-op. - return TaskCache.CompletedTask; + return Task.CompletedTask; } public override long Seek(long offset, SeekOrigin origin) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/OutputProducer.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/OutputProducer.cs index 378ed8bb4e..560c4440cc 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/OutputProducer.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/OutputProducer.cs @@ -6,7 +6,6 @@ using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; -using Microsoft.Extensions.Internal; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { @@ -110,7 +109,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { if (_completed) { - return TaskCache.CompletedTask; + return Task.CompletedTask; } writableBuffer = _pipe.Writer.Alloc(1); @@ -143,7 +142,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http if (awaitable.IsCompleted) { // The flush task can't fail today - return TaskCache.CompletedTask; + return Task.CompletedTask; } return FlushAsyncAwaited(awaitable, cancellationToken); } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Microsoft.AspNetCore.Server.Kestrel.Core.csproj b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Microsoft.AspNetCore.Server.Kestrel.Core.csproj index 2565c8cfb8..d408125990 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Microsoft.AspNetCore.Server.Kestrel.Core.csproj +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Microsoft.AspNetCore.Server.Kestrel.Core.csproj @@ -20,7 +20,6 @@ - diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Https/Internal/ClosedStream.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Https/Internal/ClosedStream.cs index 3e63d4d69b..a744faf0ec 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Https/Internal/ClosedStream.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Https/Internal/ClosedStream.cs @@ -5,12 +5,13 @@ using System; using System.IO; using System.Threading; using System.Threading.Tasks; -using Microsoft.Extensions.Internal; namespace Microsoft.AspNetCore.Server.Kestrel.Https.Internal { internal class ClosedStream : Stream { + private static readonly Task ZeroResultTask = Task.FromResult(result: 0); + public override bool CanRead => true; public override bool CanSeek => false; public override bool CanWrite => false; @@ -56,7 +57,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Https.Internal public override Task ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) { - return TaskCache.DefaultCompletedTask; + return ZeroResultTask; } public override void Write(byte[] buffer, int offset, int count) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Https/Microsoft.AspNetCore.Server.Kestrel.Https.csproj b/src/Microsoft.AspNetCore.Server.Kestrel.Https/Microsoft.AspNetCore.Server.Kestrel.Https.csproj index a9d552dc1b..d1801ffa01 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Https/Microsoft.AspNetCore.Server.Kestrel.Https.csproj +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Https/Microsoft.AspNetCore.Server.Kestrel.Https.csproj @@ -19,7 +19,6 @@ - diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.csproj b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.csproj index 19c7d923b2..725988a030 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.csproj +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.csproj @@ -17,7 +17,6 @@ - diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameTests.cs index e8d2481942..31822b16f8 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameTests.cs @@ -17,7 +17,6 @@ using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; using Microsoft.AspNetCore.Testing; -using Microsoft.Extensions.Internal; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Primitives; using Moq; @@ -240,7 +239,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests // Act/Assert Assert.True(_frame.HasResponseStarted); - Assert.Throws(() => ((IHttpResponseFeature)_frame).OnStarting(_ => TaskCache.CompletedTask, null)); + Assert.Throws(() => ((IHttpResponseFeature)_frame).OnStarting(_ => Task.CompletedTask, null)); } [Fact] diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/KestrelServerTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/KestrelServerTests.cs index a61feba7bc..bb9e6ee61c 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/KestrelServerTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/KestrelServerTests.cs @@ -5,12 +5,12 @@ using System; using System.Linq; using System.Net; using System.Threading; +using System.Threading.Tasks; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting.Server; using Microsoft.AspNetCore.Hosting.Server.Features; using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions; using Microsoft.AspNetCore.Testing; -using Microsoft.Extensions.Internal; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using Moq; @@ -161,7 +161,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests private static void StartDummyApplication(IServer server) { - server.StartAsync(new DummyApplication(context => TaskCache.CompletedTask), CancellationToken.None).GetAwaiter().GetResult(); + server.StartAsync(new DummyApplication(context => Task.CompletedTask), CancellationToken.None).GetAwaiter().GetResult(); } private class MockTransportFactory : ITransportFactory diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/MessageBodyTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/MessageBodyTests.cs index 1bb42355f6..fe502feb1e 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/MessageBodyTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/MessageBodyTests.cs @@ -9,14 +9,10 @@ using System.Text; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Server.Kestrel.Core.Internal; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; using Microsoft.AspNetCore.Testing; -using Microsoft.Extensions.Internal; -using Microsoft.Extensions.Logging; using Moq; using Xunit; -using Xunit.Abstractions; using Xunit.Sdk; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests @@ -398,7 +394,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests writeTcs.SetResult(buffer); writeCount++; }) - .Returns(TaskCache.CompletedTask); + .Returns(Task.CompletedTask); using (var input = new TestInput()) { diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/TestHelpers/MockFrameControl.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/TestHelpers/MockFrameControl.cs index f9e2d1bb5e..df99b9fb05 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/TestHelpers/MockFrameControl.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/TestHelpers/MockFrameControl.cs @@ -5,7 +5,6 @@ using System; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; -using Microsoft.Extensions.Internal; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests.TestHelpers { @@ -13,7 +12,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests.TestHelpers { public Task FlushAsync(CancellationToken cancellationToken) { - return TaskCache.CompletedTask; + return Task.CompletedTask; } public void ProduceContinue() @@ -22,7 +21,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests.TestHelpers public Task WriteAsync(ArraySegment data, CancellationToken cancellationToken) { - return TaskCache.CompletedTask; + return Task.CompletedTask; } } } diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/TestInput.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/TestInput.cs index df90641045..6f96c33711 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/TestInput.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/TestInput.cs @@ -2,17 +2,12 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.IO; using System.Text; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; -using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; -using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions; using Microsoft.AspNetCore.Testing; -using Microsoft.Extensions.Internal; -using Moq; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests { @@ -82,12 +77,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests Task IFrameControl.WriteAsync(ArraySegment data, CancellationToken cancellationToken) { - return TaskCache.CompletedTask; + return Task.CompletedTask; } Task IFrameControl.FlushAsync(CancellationToken cancellationToken) { - return TaskCache.CompletedTask; + return Task.CompletedTask; } public void Dispose() diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/BadHttpRequestTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/BadHttpRequestTests.cs index 089b86006d..923f0fdccc 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/BadHttpRequestTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/BadHttpRequestTests.cs @@ -9,7 +9,6 @@ using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; using Microsoft.AspNetCore.Testing; -using Microsoft.Extensions.Internal; using Microsoft.Extensions.Logging; using Moq; using Xunit; @@ -181,7 +180,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests .Setup(trace => trace.ConnectionBadRequest(It.IsAny(), It.IsAny())) .Callback((connectionId, exception) => loggedException = exception); - using (var server = new TestServer(context => TaskCache.CompletedTask, new TestServiceContext { Log = mockKestrelTrace.Object })) + using (var server = new TestServer(context => Task.CompletedTask, new TestServiceContext { Log = mockKestrelTrace.Object })) { using (var connection = server.CreateConnection()) { diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ChunkedRequestTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ChunkedRequestTests.cs index ce0f9bf2df..380f199768 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ChunkedRequestTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ChunkedRequestTests.cs @@ -10,7 +10,6 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.AspNetCore.Testing; -using Microsoft.Extensions.Internal; using Xunit; namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests @@ -538,7 +537,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests var testContext = new TestServiceContext(); using (var server = new TestServer(httpContext => { - return TaskCache.CompletedTask; + return Task.CompletedTask; }, testContext, listenOptions)) { using (var connection = server.CreateConnection()) diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/DefaultHeaderTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/DefaultHeaderTests.cs index 167019d218..757a5a0a63 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/DefaultHeaderTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/DefaultHeaderTests.cs @@ -3,7 +3,6 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Testing; -using Microsoft.Extensions.Internal; using Xunit; namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests @@ -18,7 +17,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests ServerOptions = { AddServerHeader = true } }; - using (var server = new TestServer(ctx => TaskCache.CompletedTask, testContext)) + using (var server = new TestServer(ctx => Task.CompletedTask, testContext)) { using (var connection = server.CreateConnection()) { diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/HttpsConnectionAdapterTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/HttpsConnectionAdapterTests.cs index eb4b7976d1..0f6b48097e 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/HttpsConnectionAdapterTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/HttpsConnectionAdapterTests.cs @@ -17,7 +17,6 @@ using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.AspNetCore.Server.Kestrel.Https; using Microsoft.AspNetCore.Testing; -using Microsoft.Extensions.Internal; using Xunit; namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests @@ -126,7 +125,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } }; - using (var server = new TestServer(context => TaskCache.CompletedTask, serviceContext, listenOptions)) + using (var server = new TestServer(context => Task.CompletedTask, serviceContext, listenOptions)) { using (var client = new TcpClient()) { @@ -256,7 +255,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } }; - using (var server = new TestServer(context => TaskCache.CompletedTask, serviceContext, listenOptions)) + using (var server = new TestServer(context => Task.CompletedTask, serviceContext, listenOptions)) { using (var client = new TcpClient()) { @@ -287,7 +286,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } }; - using (var server = new TestServer(context => TaskCache.CompletedTask, serviceContext, listenOptions)) + using (var server = new TestServer(context => Task.CompletedTask, serviceContext, listenOptions)) { using (var client = new TcpClient()) { @@ -316,7 +315,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } }; - using (var server = new TestServer(context => TaskCache.CompletedTask, serviceContext, listenOptions)) + using (var server = new TestServer(context => Task.CompletedTask, serviceContext, listenOptions)) { using (var client = new TcpClient()) { diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs index 50004ca37a..68daae3363 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs @@ -21,7 +21,6 @@ using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions; using Microsoft.AspNetCore.Testing; using Microsoft.AspNetCore.Testing.xunit; -using Microsoft.Extensions.Internal; using Microsoft.Extensions.Logging; using Moq; using Newtonsoft.Json; @@ -291,7 +290,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests .Setup(factory => factory.CreateLogger(It.IsIn("Microsoft.AspNetCore.Server.Kestrel", "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv"))) .Returns(mockLogger.Object); - using (var server = new TestServer(context => TaskCache.CompletedTask, new TestServiceContext(mockLoggerFactory.Object))) + using (var server = new TestServer(context => Task.CompletedTask, new TestServiceContext(mockLoggerFactory.Object))) { using (var connection = server.CreateConnection()) { @@ -345,7 +344,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests .Setup(factory => factory.CreateLogger(It.IsIn("Microsoft.AspNetCore.Server.Kestrel", "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv"))) .Returns(mockLogger.Object); - using (var server = new TestServer(context => TaskCache.CompletedTask, new TestServiceContext(mockLoggerFactory.Object))) + using (var server = new TestServer(context => Task.CompletedTask, new TestServiceContext(mockLoggerFactory.Object))) { using (var connection = server.CreateConnection()) { @@ -1105,7 +1104,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests Assert.Same(originalRequestHeaders, requestFeature.Headers); } - return TaskCache.CompletedTask; + return Task.CompletedTask; }, testContext, listenOptions)) { using (var connection = server.CreateConnection()) diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs index 5966eab03f..155a1dac95 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs @@ -21,7 +21,6 @@ using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; using Microsoft.AspNetCore.Testing; using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Internal; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Primitives; using Moq; @@ -182,7 +181,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { await context.Response.WriteAsync("hello, world"); await context.Response.Body.FlushAsync(); - ex = Assert.Throws(() => context.Response.OnStarting(_ => TaskCache.CompletedTask, null)); + ex = Assert.Throws(() => context.Response.OnStarting(_ => Task.CompletedTask, null)); }); }); @@ -220,7 +219,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests context => { context.Abort(); - return TaskCache.CompletedTask; + return Task.CompletedTask; }, expectedClientStatusCode: null, expectedServerStatusCode: 0); @@ -245,7 +244,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests return ResponseStatusCodeSetBeforeHttpContextDispose( context => { - return TaskCache.CompletedTask; + return Task.CompletedTask; }, expectedClientStatusCode: null, expectedServerStatusCode: HttpStatusCode.BadRequest, @@ -421,7 +420,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests using (var server = new TestServer(httpContext => { httpContext.Response.StatusCode = statusCode; - return TaskCache.CompletedTask; + return Task.CompletedTask; })) { using (var connection = server.CreateConnection()) @@ -445,7 +444,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { using (var server = new TestServer(httpContext => { - return TaskCache.CompletedTask; + return Task.CompletedTask; })) { using (var connection = server.CreateConnection()) @@ -516,7 +515,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests httpContext.Response.ContentLength = 11; httpContext.Response.Body.Write(Encoding.ASCII.GetBytes("hello,"), 0, 6); httpContext.Response.Body.Write(Encoding.ASCII.GetBytes(" world"), 0, 6); - return TaskCache.CompletedTask; + return Task.CompletedTask; }, serviceContext)) { using (var connection = server.CreateConnection()) @@ -592,7 +591,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests var response = Encoding.ASCII.GetBytes("hello, world"); httpContext.Response.ContentLength = 5; httpContext.Response.Body.Write(response, 0, response.Length); - return TaskCache.CompletedTask; + return Task.CompletedTask; }, serviceContext)) { using (var connection = server.CreateConnection()) @@ -764,7 +763,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests using (var server = new TestServer(httpContext => { httpContext.Response.ContentLength = 5; - return TaskCache.CompletedTask; + return Task.CompletedTask; }, serviceContext)) { using (var connection = server.CreateConnection()) @@ -912,7 +911,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests using (var server = new TestServer(httpContext => { httpContext.Response.ContentLength = 42; - return TaskCache.CompletedTask; + return Task.CompletedTask; })) { using (var connection = server.CreateConnection()) @@ -973,7 +972,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests httpContext.Response.ContentLength = 12; httpContext.Response.Body.Write(Encoding.ASCII.GetBytes("hello, world"), 0, 12); flushed.Wait(); - return TaskCache.CompletedTask; + return Task.CompletedTask; })) { using (var connection = server.CreateConnection()) @@ -1255,7 +1254,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { // Change response to chunked httpContext.Response.ContentLength = null; - return TaskCache.CompletedTask; + return Task.CompletedTask; }); var response = Encoding.ASCII.GetBytes("hello, world"); @@ -1263,7 +1262,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests // If OnStarting is not run before verifying writes, an error response will be sent. httpContext.Response.Body.Write(response, 0, response.Length); - return TaskCache.CompletedTask; + return Task.CompletedTask; })) { using (var connection = server.CreateConnection()) @@ -1296,7 +1295,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { // Change response to chunked httpContext.Response.ContentLength = null; - return TaskCache.CompletedTask; + return Task.CompletedTask; }); var response = Encoding.ASCII.GetBytes("hello, world"); @@ -1305,7 +1304,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests // If OnStarting is not run before verifying writes, an error response will be sent. httpContext.Response.Body.Write(response, 0, response.Length / 2); httpContext.Response.Body.Write(response, response.Length / 2, response.Length - response.Length / 2); - return TaskCache.CompletedTask; + return Task.CompletedTask; })) { using (var connection = server.CreateConnection()) @@ -1340,7 +1339,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { // Change response to chunked httpContext.Response.ContentLength = null; - return TaskCache.CompletedTask; + return Task.CompletedTask; }); var response = Encoding.ASCII.GetBytes("hello, world"); @@ -1380,7 +1379,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { // Change response to chunked httpContext.Response.ContentLength = null; - return TaskCache.CompletedTask; + return Task.CompletedTask; }); var response = Encoding.ASCII.GetBytes("hello, world"); @@ -1454,7 +1453,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [Fact] public async Task WhenResponseNotStartedResponseEndedAfterConsumingRequestBody() { - using (var server = new TestServer(httpContext => TaskCache.CompletedTask)) + using (var server = new TestServer(httpContext => Task.CompletedTask)) { using (var connection = server.CreateConnection()) { @@ -1822,7 +1821,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests response.OnStarting(_ => { onStartingCalled = true; - return TaskCache.CompletedTask; + return Task.CompletedTask; }, null); // Anything added to the ResponseHeaders dictionary is ignored @@ -2166,7 +2165,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests using (var server = new TestServer(httpContext => { httpContext.Abort(); - return TaskCache.CompletedTask; + return Task.CompletedTask; }, testContext, listenOptions)) { using (var connection = server.CreateConnection()) @@ -2205,7 +2204,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests Assert.Same(originalResponseHeaders, responseFeature.Headers); } - return TaskCache.CompletedTask; + return Task.CompletedTask; }, testContext, listenOptions)) { using (var connection = server.CreateConnection()) @@ -2249,12 +2248,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { callOrder.Push(1); onStartingTcs.SetResult(null); - return TaskCache.CompletedTask; + return Task.CompletedTask; }, null); context.Response.OnStarting(_ => { callOrder.Push(2); - return TaskCache.CompletedTask; + return Task.CompletedTask; }, null); context.Response.ContentLength = response.Length; @@ -2301,12 +2300,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { callOrder.Push(1); onCompletedTcs.SetResult(null); - return TaskCache.CompletedTask; + return Task.CompletedTask; }, null); context.Response.OnCompleted(_ => { callOrder.Push(2); - return TaskCache.CompletedTask; + return Task.CompletedTask; }, null); context.Response.ContentLength = response.Length; diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/UpgradeTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/UpgradeTests.cs index d1d981bed6..5fa497dd0e 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/UpgradeTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/UpgradeTests.cs @@ -9,7 +9,6 @@ using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Tests; using Microsoft.AspNetCore.Testing; -using Microsoft.Extensions.Internal; using Xunit; using Xunit.Abstractions; @@ -154,7 +153,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [Fact] public async Task RejectsRequestWithContentLengthAndUpgrade() { - using (var server = new TestServer(context => TaskCache.CompletedTask)) + using (var server = new TestServer(context => Task.CompletedTask)) using (var connection = server.CreateConnection()) { await connection.Send("POST / HTTP/1.1", @@ -177,7 +176,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [Fact] public async Task AcceptsRequestWithNoContentLengthAndUpgrade() { - using (var server = new TestServer(context => TaskCache.CompletedTask)) + using (var server = new TestServer(context => Task.CompletedTask)) { using (var connection = server.CreateConnection()) { @@ -201,7 +200,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [Fact] public async Task RejectsRequestWithChunkedEncodingAndUpgrade() { - using (var server = new TestServer(context => TaskCache.CompletedTask)) + using (var server = new TestServer(context => Task.CompletedTask)) using (var connection = server.CreateConnection()) { await connection.Send("POST / HTTP/1.1", diff --git a/test/shared/TestApp.cs b/test/shared/TestApp.cs index 54a4f33a90..ef4eca006b 100644 --- a/test/shared/TestApp.cs +++ b/test/shared/TestApp.cs @@ -4,7 +4,6 @@ using System.IO; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; -using Microsoft.Extensions.Internal; namespace Microsoft.AspNetCore.Testing { @@ -43,7 +42,7 @@ namespace Microsoft.AspNetCore.Testing public static Task EmptyApp(HttpContext httpContext) { - return TaskCache.CompletedTask; + return Task.CompletedTask; } } } \ No newline at end of file From fcc04f8c3dff565c3ed58deb4eb87ab3d54b7116 Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Thu, 8 Jun 2017 14:36:03 -0700 Subject: [PATCH 1316/1662] Add request body minimum data rate feature (#1874). --- KestrelHttpServer.sln | 1 - .../CoreStrings.resx | 62 ++-- .../IHttpRequestBodyMinimumDataRateFeature.cs | 18 + .../Features/MinimumDataRate.cs | 41 +++ .../Internal/FrameConnection.cs | 136 +++++++- .../Internal/Http/Frame.FeatureCollection.cs | 10 +- .../Internal/Http/Frame.Generated.cs | 16 + .../Internal/Http/Frame.cs | 5 + .../Internal/Http/FrameOfT.cs | 3 + .../Internal/Http/MessageBody.cs | 60 +++- .../Internal/Infrastructure/Constants.cs | 4 + .../Internal/Infrastructure/IKestrelTrace.cs | 6 + .../Infrastructure/ITimeoutControl.cs | 8 + .../Internal/Infrastructure/KestrelTrace.cs | 27 +- .../KestrelServerLimits.cs | 37 +- .../Properties/CoreStrings.Designer.cs | 32 +- .../FrameConnectionTests.cs | 324 ++++++++++++++++++ .../FrameTests.cs | 41 +++ .../KestrelServerLimitsTests.cs | 85 +++-- .../KestrelServerTests.cs | 27 +- .../MessageBodyTests.cs | 253 ++++++++++++-- .../MinimumDataRateTests.cs | 61 ++++ .../TestInput.cs | 55 +-- .../KeepAliveTimeoutTests.cs | 23 +- .../MaxRequestBufferSizeTests.cs | 3 +- .../RequestBodyTimeoutTests.cs | 172 ++++++++++ .../RequestHeadersTimeoutTests.cs | 6 +- .../RequestTests.cs | 5 +- .../Mocks/MockTimeoutControl.cs | 22 ++ .../Mocks/MockTrace.cs | 3 + test/shared/MockSystemClock.cs | 7 +- test/shared/TestServiceContext.cs | 3 +- tools/CodeGenerator/FrameFeatureCollection.cs | 9 +- 33 files changed, 1381 insertions(+), 184 deletions(-) create mode 100644 src/Microsoft.AspNetCore.Server.Kestrel.Core/Features/IHttpRequestBodyMinimumDataRateFeature.cs create mode 100644 src/Microsoft.AspNetCore.Server.Kestrel.Core/Features/MinimumDataRate.cs create mode 100644 test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameConnectionTests.cs create mode 100644 test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/MinimumDataRateTests.cs create mode 100644 test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestBodyTimeoutTests.cs diff --git a/KestrelHttpServer.sln b/KestrelHttpServer.sln index b5b6dc71f3..c1ba2b1753 100644 --- a/KestrelHttpServer.sln +++ b/KestrelHttpServer.sln @@ -25,7 +25,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "shared", "shared", "{0EF2AC test\shared\KestrelTestLoggerProvider.cs = test\shared\KestrelTestLoggerProvider.cs test\shared\LifetimeNotImplemented.cs = test\shared\LifetimeNotImplemented.cs test\shared\MockConnectionInformation.cs = test\shared\MockConnectionInformation.cs - test\shared\MockFrameControl.cs = test\shared\MockFrameControl.cs test\shared\MockLogger.cs = test\shared\MockLogger.cs test\shared\MockSystemClock.cs = test\shared\MockSystemClock.cs test\shared\StringExtensions.cs = test\shared\StringExtensions.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/CoreStrings.resx b/src/Microsoft.AspNetCore.Server.Kestrel.Core/CoreStrings.resx index 4ccc38f2c0..72d2a8aa5f 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/CoreStrings.resx +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/CoreStrings.resx @@ -1,17 +1,17 @@  - @@ -327,4 +327,10 @@ The maximum request body size cannot be modified after the request has been upgraded. - \ No newline at end of file + + Value must be a positive TimeSpan. + + + Value must be a non-negative TimeSpan. + + diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Features/IHttpRequestBodyMinimumDataRateFeature.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Features/IHttpRequestBodyMinimumDataRateFeature.cs new file mode 100644 index 0000000000..9190d73d18 --- /dev/null +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Features/IHttpRequestBodyMinimumDataRateFeature.cs @@ -0,0 +1,18 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Features +{ + /// + /// Represents a minimum data rate for the request body of an HTTP request. + /// + public interface IHttpRequestBodyMinimumDataRateFeature + { + /// + /// The minimum data rate in bytes/second at which the request body should be received. + /// Setting this property to null indicates no minimum data rate should be enforced. + /// This limit has no effect on upgraded connections which are always unlimited. + /// + MinimumDataRate MinimumDataRate { get; set; } + } +} diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Features/MinimumDataRate.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Features/MinimumDataRate.cs new file mode 100644 index 0000000000..c294d2df3d --- /dev/null +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Features/MinimumDataRate.cs @@ -0,0 +1,41 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; + +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Features +{ + public class MinimumDataRate + { + /// + /// Creates a new instance of . + /// + /// The minimum rate in bytes/second at which data should be processed. + /// The amount of time to delay enforcement of . + public MinimumDataRate(double rate, TimeSpan gracePeriod) + { + if (rate <= 0) + { + throw new ArgumentOutOfRangeException(nameof(rate), CoreStrings.PositiveNumberRequired); + } + + if (gracePeriod < TimeSpan.Zero) + { + throw new ArgumentOutOfRangeException(nameof(gracePeriod), CoreStrings.NonNegativeTimeSpanRequired); + } + + Rate = rate; + GracePeriod = gracePeriod; + } + + /// + /// The minimum rate in bytes/second at which data should be processed. + /// + public double Rate { get; } + + /// + /// The amount of time to delay enforcement of . + /// + public TimeSpan GracePeriod { get; } + } +} diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnection.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnection.cs index dad0f21cd2..9b222a755b 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnection.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnection.cs @@ -29,6 +29,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal private long _timeoutTimestamp = long.MaxValue; private TimeoutAction _timeoutAction; + private object _readTimingLock = new object(); + private bool _readTimingEnabled; + private bool _readTimingPauseRequested; + private long _readTimingElapsedTicks; + private long _readTimingBytesRead; + private Task _lifetimeTask; public FrameConnection(FrameConnectionContext context) @@ -36,6 +42,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal _context = context; } + // For testing + internal Frame Frame => _frame; + + public bool TimedOut { get; private set; } + public string ConnectionId => _context.ConnectionId; public IPipeWriter Input => _context.Input.Writer; public IPipeReader Output => _context.Output.Reader; @@ -91,15 +102,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal } // _frame must be initialized before adding the connection to the connection manager - _frame = new Frame(application, new FrameContext - { - ConnectionId = _context.ConnectionId, - ConnectionInformation = _context.ConnectionInformation, - ServiceContext = _context.ServiceContext, - TimeoutControl = this, - Input = input, - Output = output - }); + CreateFrame(application, input, output); // Do this before the first await so we don't yield control to the transport until we've // added the connection to the connection manager @@ -140,9 +143,22 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal } } + internal void CreateFrame(IHttpApplication application, IPipeReader input, IPipe output) + { + _frame = new Frame(application, new FrameContext + { + ConnectionId = _context.ConnectionId, + ConnectionInformation = _context.ConnectionInformation, + ServiceContext = _context.ServiceContext, + TimeoutControl = this, + Input = input, + Output = output + }); + } + public void OnConnectionClosed(Exception ex) { - Debug.Assert(_frame != null, $"nameof({_frame}) is null"); + Debug.Assert(_frame != null, $"{nameof(_frame)} is null"); // Abort the connection (if not already aborted) _frame.Abort(ex); @@ -152,7 +168,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal public Task StopAsync() { - Debug.Assert(_frame != null, $"nameof({_frame}) is null"); + Debug.Assert(_frame != null, $"{nameof(_frame)} is null"); _frame.Stop(); @@ -161,7 +177,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal public void Abort(Exception ex) { - Debug.Assert(_frame != null, $"nameof({_frame}) is null"); + Debug.Assert(_frame != null, $"{nameof(_frame)} is null"); // Abort the connection (if not already aborted) _frame.Abort(ex); @@ -169,7 +185,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal public Task AbortAsync(Exception ex) { - Debug.Assert(_frame != null, $"nameof({_frame}) is null"); + Debug.Assert(_frame != null, $"{nameof(_frame)} is null"); // Abort the connection (if not already aborted) _frame.Abort(ex); @@ -177,16 +193,25 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal return _lifetimeTask; } - public void Timeout() + public void SetTimeoutResponse() { - Debug.Assert(_frame != null, $"nameof({_frame}) is null"); + Debug.Assert(_frame != null, $"{nameof(_frame)} is null"); _frame.SetBadRequestState(RequestRejectionReason.RequestTimeout); } + public void Timeout() + { + Debug.Assert(_frame != null, $"{nameof(_frame)} is null"); + + TimedOut = true; + _readTimingEnabled = false; + _frame.Stop(); + } + private async Task ApplyConnectionAdaptersAsync() { - Debug.Assert(_frame != null, $"nameof({_frame}) is null"); + Debug.Assert(_frame != null, $"{nameof(_frame)} is null"); var features = new FeatureCollection(); var connectionAdapters = _context.ConnectionAdapters; @@ -231,7 +256,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal public void Tick(DateTimeOffset now) { - Debug.Assert(_frame != null, $"nameof({_frame}) is null"); + Debug.Assert(_frame != null, $"{nameof(_frame)} is null"); var timestamp = now.Ticks; @@ -242,10 +267,41 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal if (_timeoutAction == TimeoutAction.SendTimeoutResponse) { - Timeout(); + SetTimeoutResponse(); } - _frame.Stop(); + Timeout(); + } + else + { + lock (_readTimingLock) + { + if (_readTimingEnabled) + { + _readTimingElapsedTicks += timestamp - _lastTimestamp; + + if (_frame.RequestBodyMinimumDataRate?.Rate > 0 && _readTimingElapsedTicks > _frame.RequestBodyMinimumDataRate.GracePeriod.Ticks) + { + var elapsedSeconds = (double)_readTimingElapsedTicks / TimeSpan.TicksPerSecond; + var rate = Interlocked.Read(ref _readTimingBytesRead) / elapsedSeconds; + + if (rate < _frame.RequestBodyMinimumDataRate.Rate) + { + Log.RequestBodyMininumDataRateNotSatisfied(_context.ConnectionId, _frame.TraceIdentifier, _frame.RequestBodyMinimumDataRate.Rate); + Timeout(); + } + } + + // PauseTimingReads() cannot just set _timingReads to false. It needs to go through at least one tick + // before pausing, otherwise _readTimingElapsed might never be updated if PauseTimingReads() is always + // called before the next tick. + if (_readTimingPauseRequested) + { + _readTimingEnabled = false; + _readTimingPauseRequested = false; + } + } + } } Interlocked.Exchange(ref _lastTimestamp, timestamp); @@ -275,5 +331,47 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal // Add Heartbeat.Interval since this can be called right before the next heartbeat. Interlocked.Exchange(ref _timeoutTimestamp, _lastTimestamp + ticks + Heartbeat.Interval.Ticks); } + + public void StartTimingReads() + { + lock (_readTimingLock) + { + _readTimingElapsedTicks = 0; + _readTimingBytesRead = 0; + _readTimingEnabled = true; + } + } + + public void StopTimingReads() + { + lock (_readTimingLock) + { + _readTimingEnabled = false; + } + } + + public void PauseTimingReads() + { + lock (_readTimingLock) + { + _readTimingPauseRequested = true; + } + } + + public void ResumeTimingReads() + { + lock (_readTimingLock) + { + _readTimingEnabled = true; + + // In case pause and resume were both called between ticks + _readTimingPauseRequested = false; + } + } + + public void BytesRead(int count) + { + Interlocked.Add(ref _readTimingBytesRead, count); + } } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.FeatureCollection.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.FeatureCollection.cs index 3358811e93..fdfb0d6c30 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.FeatureCollection.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.FeatureCollection.cs @@ -10,6 +10,7 @@ using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http.Features; +using Microsoft.AspNetCore.Server.Kestrel.Core.Features; using Microsoft.Extensions.Primitives; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http @@ -21,7 +22,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http IHttpConnectionFeature, IHttpRequestLifetimeFeature, IHttpRequestIdentifierFeature, - IHttpMaxRequestBodySizeFeature + IHttpMaxRequestBodySizeFeature, + IHttpRequestBodyMinimumDataRateFeature { // NOTE: When feature interfaces are added to or removed from this Frame class implementation, // then the list of `implementedFeatures` in the generated code project MUST also be updated. @@ -227,6 +229,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http } } + MinimumDataRate IHttpRequestBodyMinimumDataRateFeature.MinimumDataRate + { + get => RequestBodyMinimumDataRate; + set => RequestBodyMinimumDataRate = value; + } + object IFeatureCollection.this[Type key] { get => FastFeatureGet(key); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.Generated.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.Generated.cs index 3a17316ade..ef0aa0faa6 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.Generated.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.Generated.cs @@ -24,6 +24,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http private static readonly Type IHttpWebSocketFeatureType = typeof(global::Microsoft.AspNetCore.Http.Features.IHttpWebSocketFeature); private static readonly Type ISessionFeatureType = typeof(global::Microsoft.AspNetCore.Http.Features.ISessionFeature); private static readonly Type IHttpMaxRequestBodySizeFeatureType = typeof(global::Microsoft.AspNetCore.Http.Features.IHttpMaxRequestBodySizeFeature); + private static readonly Type IHttpRequestBodyMinimumDataRateFeatureType = typeof(global::Microsoft.AspNetCore.Server.Kestrel.Core.Features.IHttpRequestBodyMinimumDataRateFeature); private static readonly Type IHttpSendFileFeatureType = typeof(global::Microsoft.AspNetCore.Http.Features.IHttpSendFileFeature); private object _currentIHttpRequestFeature; @@ -42,6 +43,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http private object _currentIHttpWebSocketFeature; private object _currentISessionFeature; private object _currentIHttpMaxRequestBodySizeFeature; + private object _currentIHttpRequestBodyMinimumDataRateFeature; private object _currentIHttpSendFileFeature; private void FastReset() @@ -53,6 +55,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http _currentIHttpRequestLifetimeFeature = this; _currentIHttpConnectionFeature = this; _currentIHttpMaxRequestBodySizeFeature = this; + _currentIHttpRequestBodyMinimumDataRateFeature = this; _currentIServiceProvidersFeature = null; _currentIHttpAuthenticationFeature = null; @@ -132,6 +135,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { return _currentIHttpMaxRequestBodySizeFeature; } + if (key == IHttpRequestBodyMinimumDataRateFeatureType) + { + return _currentIHttpRequestBodyMinimumDataRateFeature; + } if (key == IHttpSendFileFeatureType) { return _currentIHttpSendFileFeature; @@ -223,6 +230,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http _currentIHttpMaxRequestBodySizeFeature = feature; return; } + if (key == IHttpRequestBodyMinimumDataRateFeatureType) + { + _currentIHttpRequestBodyMinimumDataRateFeature = feature; + return; + } if (key == IHttpSendFileFeatureType) { _currentIHttpSendFileFeature = feature; @@ -297,6 +309,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { yield return new KeyValuePair(IHttpMaxRequestBodySizeFeatureType, _currentIHttpMaxRequestBodySizeFeature as global::Microsoft.AspNetCore.Http.Features.IHttpMaxRequestBodySizeFeature); } + if (_currentIHttpRequestBodyMinimumDataRateFeature != null) + { + yield return new KeyValuePair(IHttpRequestBodyMinimumDataRateFeatureType, _currentIHttpRequestBodyMinimumDataRateFeature as global::Microsoft.AspNetCore.Server.Kestrel.Core.Features.IHttpRequestBodyMinimumDataRateFeature); + } if (_currentIHttpSendFileFeature != null) { yield return new KeyValuePair(IHttpSendFileFeatureType, _currentIHttpSendFileFeature as global::Microsoft.AspNetCore.Http.Features.IHttpSendFileFeature); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.cs index 6919a10ccb..9ade0f5689 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.cs @@ -21,6 +21,7 @@ using Microsoft.Extensions.Internal; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Primitives; using Microsoft.AspNetCore.Http.Features; +using Microsoft.AspNetCore.Server.Kestrel.Core.Features; // ReSharper disable AccessToModifiedClosure @@ -300,6 +301,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http protected FrameResponseHeaders FrameResponseHeaders { get; } = new FrameResponseHeaders(); + public MinimumDataRate RequestBodyMinimumDataRate { get; set; } + public void InitializeStreams(MessageBody messageBody) { if (_frameStreams == null) @@ -376,6 +379,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http _responseBytesWritten = 0; _requestCount++; + + RequestBodyMinimumDataRate = ServerOptions.Limits.RequestBodyMinimumDataRate; } /// diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameOfT.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameOfT.cs index c660d0b60c..8eddab20db 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameOfT.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameOfT.cs @@ -160,7 +160,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http if (_keepAlive) { // Finish reading the request body in case the app did not. + TimeoutControl.SetTimeout(Constants.RequestBodyDrainTimeout.Ticks, TimeoutAction.SendTimeoutResponse); await messageBody.ConsumeAsync(); + TimeoutControl.CancelTimeout(); + // At this point both the request body pipe reader and writer should be completed. RequestBodyPipe.Reset(); } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/MessageBody.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/MessageBody.cs index bc6e3c0f8a..f964f55001 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/MessageBody.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/MessageBody.cs @@ -6,6 +6,7 @@ using System.IO; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http @@ -16,6 +17,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http private static readonly MessageBody _zeroContentLengthKeepAlive = new ForZeroContentLength(keepAlive: true); private readonly Frame _context; + private bool _send100Continue = true; private volatile bool _canceled; @@ -32,22 +34,32 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http public virtual bool IsEmpty => false; + private IKestrelTrace Log => _context.ServiceContext.Log; + private async Task PumpAsync() { Exception error = null; try { + var awaitable = _context.Input.ReadAsync(); + + if (!awaitable.IsCompleted) + { + TryProduceContinue(); + } + + TryStartTimingReads(); + while (true) { - var awaitable = _context.Input.ReadAsync(); + var result = await awaitable; - if (!awaitable.IsCompleted) + if (_context.TimeoutControl.TimedOut) { - TryProduceContinue(); + _context.ThrowRequestRejected(RequestRejectionReason.RequestTimeout); } - var result = await awaitable; var readableBuffer = result.Buffer; var consumed = readableBuffer.Start; var examined = readableBuffer.End; @@ -73,7 +85,22 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http writableBuffer.Commit(); } - await writableBuffer.FlushAsync(); + var writeAwaitable = writableBuffer.FlushAsync(); + var backpressure = false; + + if (!writeAwaitable.IsCompleted) + { + // Backpressure, stop controlling incoming data rate until data is read. + backpressure = true; + _context.TimeoutControl.PauseTimingReads(); + } + + await writeAwaitable; + + if (backpressure) + { + _context.TimeoutControl.ResumeTimingReads(); + } if (done) { @@ -84,6 +111,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { _context.ThrowRequestRejected(RequestRejectionReason.UnexpectedEndOfRequestContent); } + + awaitable = _context.Input.ReadAsync(); } finally { @@ -98,6 +127,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http finally { _context.RequestBodyPipe.Writer.Complete(error); + TryStopTimingReads(); } } @@ -191,6 +221,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http protected void Copy(ReadableBuffer readableBuffer, WritableBuffer writableBuffer) { + _context.TimeoutControl.BytesRead(readableBuffer.Length); + if (readableBuffer.IsSingleSpan) { writableBuffer.Write(readableBuffer.First.Span); @@ -232,6 +264,24 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { } + private void TryStartTimingReads() + { + if (!RequestUpgrade) + { + Log.RequestBodyStart(_context.ConnectionIdFeature, _context.TraceIdentifier); + _context.TimeoutControl.StartTimingReads(); + } + } + + private void TryStopTimingReads() + { + if (!RequestUpgrade) + { + Log.RequestBodyDone(_context.ConnectionIdFeature, _context.TraceIdentifier); + _context.TimeoutControl.StopTimingReads(); + } + } + public static MessageBody For( HttpVersion httpVersion, FrameRequestHeaders headers, diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/Constants.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/Constants.cs index 8b22cd7cc4..7f93242028 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/Constants.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/Constants.cs @@ -1,6 +1,8 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; + namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure { internal static class Constants @@ -28,5 +30,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure public const string SocketDescriptorPrefix = "sockfd:"; public const string ServerName = "Kestrel"; + + public static readonly TimeSpan RequestBodyDrainTimeout = TimeSpan.FromSeconds(5); } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/IKestrelTrace.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/IKestrelTrace.cs index 91012fdbf5..b7d68eb03a 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/IKestrelTrace.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/IKestrelTrace.cs @@ -37,5 +37,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure void HeartbeatSlow(TimeSpan interval, DateTimeOffset now); void ApplicationNeverCompleted(string connectionId); + + void RequestBodyStart(string connectionId, string traceIdentifier); + + void RequestBodyDone(string connectionId, string traceIdentifier); + + void RequestBodyMininumDataRateNotSatisfied(string connectionId, string traceIdentifier, double rate); } } \ No newline at end of file diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/ITimeoutControl.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/ITimeoutControl.cs index e031495f1d..6b23f37c94 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/ITimeoutControl.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/ITimeoutControl.cs @@ -5,8 +5,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure { public interface ITimeoutControl { + bool TimedOut { get; } + void SetTimeout(long ticks, TimeoutAction timeoutAction); void ResetTimeout(long ticks, TimeoutAction timeoutAction); void CancelTimeout(); + + void StartTimingReads(); + void PauseTimingReads(); + void ResumeTimingReads(); + void StopTimingReads(); + void BytesRead(int count); } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/KestrelTrace.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/KestrelTrace.cs index e04ca4e0b8..115d44184d 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/KestrelTrace.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/KestrelTrace.cs @@ -7,9 +7,6 @@ using Microsoft.Extensions.Logging; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal { - /// - /// Summary description for KestrelTrace - /// public class KestrelTrace : IKestrelTrace { private static readonly Action _connectionStart = @@ -57,6 +54,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal private static readonly Action _connectionRejected = LoggerMessage.Define(LogLevel.Warning, 24, @"Connection id ""{ConnectionId}"" rejected because the maximum number of concurrent connections has been reached."); + private static readonly Action _requestBodyStart = + LoggerMessage.Define(LogLevel.Debug, 25, @"Connection id ""{ConnectionId}"", Request id ""{TraceIdentifier}"": started reading request body."); + + private static readonly Action _requestBodyDone = + LoggerMessage.Define(LogLevel.Debug, 26, @"Connection id ""{ConnectionId}"", Request id ""{TraceIdentifier}"": done reading request body."); + + private static readonly Action _requestBodyMinimumDataRateNotSatisfied = + LoggerMessage.Define(LogLevel.Information, 27, @"Connection id ""{ConnectionId}"", Request id ""{TraceIdentifier}"": request body incoming data rate dropped below {Rate} bytes/second."); + protected readonly ILogger _logger; public KestrelTrace(ILogger logger) @@ -139,6 +145,21 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal _applicationNeverCompleted(_logger, connectionId, null); } + public virtual void RequestBodyStart(string connectionId, string traceIdentifier) + { + _requestBodyStart(_logger, connectionId, traceIdentifier, null); + } + + public virtual void RequestBodyDone(string connectionId, string traceIdentifier) + { + _requestBodyDone(_logger, connectionId, traceIdentifier, null); + } + + public void RequestBodyMininumDataRateNotSatisfied(string connectionId, string traceIdentifier, double rate) + { + _requestBodyMinimumDataRateNotSatisfied(_logger, connectionId, traceIdentifier, rate, null); + } + public virtual void Log(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func formatter) => _logger.Log(logLevel, eventId, state, exception, formatter); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/KestrelServerLimits.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/KestrelServerLimits.cs index 3e02eaad9f..a1f79fc799 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/KestrelServerLimits.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/KestrelServerLimits.cs @@ -2,7 +2,9 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Threading; using Microsoft.AspNetCore.Http.Features; +using Microsoft.AspNetCore.Server.Kestrel.Core.Features; namespace Microsoft.AspNetCore.Server.Kestrel.Core { @@ -11,8 +13,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core // Matches the non-configurable default response buffer size for Kestrel in 1.0.0 private long? _maxResponseBufferSize = 64 * 1024; - // Matches the default client_max_body_size in nginx. Also large enough that most requests - // should be under the limit. + // Matches the default client_max_body_size in nginx. + // Also large enough that most requests should be under the limit. private long? _maxRequestBufferSize = 1024 * 1024; // Matches the default large_client_header_buffers in nginx. @@ -33,7 +35,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core private TimeSpan _requestHeadersTimeout = TimeSpan.FromSeconds(30); - // default to unlimited + // Unlimited connections are allowed by default. private long? _maxConcurrentConnections = null; private long? _maxConcurrentUpgradedConnections = null; @@ -169,7 +171,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core public TimeSpan KeepAliveTimeout { get => _keepAliveTimeout; - set => _keepAliveTimeout = value; + set + { + if (value <= TimeSpan.Zero && value != Timeout.InfiniteTimeSpan) + { + throw new ArgumentOutOfRangeException(nameof(value), CoreStrings.PositiveTimeSpanRequired); + } + _keepAliveTimeout = value != Timeout.InfiniteTimeSpan ? value : TimeSpan.MaxValue; + } } /// @@ -181,7 +190,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core public TimeSpan RequestHeadersTimeout { get => _requestHeadersTimeout; - set => _requestHeadersTimeout = value; + set + { + if (value <= TimeSpan.Zero && value != Timeout.InfiniteTimeSpan) + { + throw new ArgumentOutOfRangeException(nameof(value), CoreStrings.PositiveTimeSpanRequired); + } + _requestHeadersTimeout = value != Timeout.InfiniteTimeSpan ? value : TimeSpan.MaxValue; + } } /// @@ -234,5 +250,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core _maxConcurrentUpgradedConnections = value; } } + + /// + /// Gets or sets the request body minimum data rate in bytes/second. + /// Setting this property to null indicates no minimum data rate should be enforced. + /// This limit has no effect on upgraded connections which are always unlimited. + /// This can be overridden per-request via . + /// + /// + /// Defaults to null. + /// + public MinimumDataRate RequestBodyMinimumDataRate { get; set; } = new MinimumDataRate(rate: 1, gracePeriod: TimeSpan.FromSeconds(5)); } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Properties/CoreStrings.Designer.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Properties/CoreStrings.Designer.cs index 877d6d308b..ce955e41d0 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Properties/CoreStrings.Designer.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Properties/CoreStrings.Designer.cs @@ -977,7 +977,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core => GetString("MaxRequestBodySizeCannotBeModifiedAfterRead"); /// - /// The maximum request body size cannot be modified after the request has be upgraded. + /// The maximum request body size cannot be modified after the request has been upgraded. /// internal static string MaxRequestBodySizeCannotBeModifiedForUpgradedRequests { @@ -985,11 +985,39 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core } /// - /// The maximum request body size cannot be modified after the request has be upgraded. + /// The maximum request body size cannot be modified after the request has been upgraded. /// internal static string FormatMaxRequestBodySizeCannotBeModifiedForUpgradedRequests() => GetString("MaxRequestBodySizeCannotBeModifiedForUpgradedRequests"); + /// + /// Value must be a positive TimeSpan. + /// + internal static string PositiveTimeSpanRequired + { + get => GetString("PositiveTimeSpanRequired"); + } + + /// + /// Value must be a positive TimeSpan. + /// + internal static string FormatPositiveTimeSpanRequired() + => GetString("PositiveTimeSpanRequired"); + + /// + /// Value must be a non-negative TimeSpan. + /// + internal static string NonNegativeTimeSpanRequired + { + get => GetString("NonNegativeTimeSpanRequired"); + } + + /// + /// Value must be a non-negative TimeSpan. + /// + internal static string FormatNonNegativeTimeSpanRequired() + => GetString("NonNegativeTimeSpanRequired"); + private static string GetString(string name, params string[] formatterNames) { var value = _resourceManager.GetString(name); diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameConnectionTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameConnectionTests.cs new file mode 100644 index 0000000000..9596ef625f --- /dev/null +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameConnectionTests.cs @@ -0,0 +1,324 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Collections.Generic; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal; +using Microsoft.AspNetCore.Server.Kestrel.Core.Features; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; +using Microsoft.AspNetCore.Testing; +using Moq; +using Xunit; + +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests +{ + public class FrameConnectionTests : IDisposable + { + private readonly PipeFactory _pipeFactory; + private readonly FrameConnectionContext _frameConnectionContext; + private readonly FrameConnection _frameConnection; + + public FrameConnectionTests() + { + _pipeFactory = new PipeFactory(); + + _frameConnectionContext = new FrameConnectionContext + { + ConnectionId = "0123456789", + ConnectionAdapters = new List(), + ConnectionInformation = new MockConnectionInformation + { + PipeFactory = _pipeFactory + }, + FrameConnectionId = long.MinValue, + Input = _pipeFactory.Create(), + Output = _pipeFactory.Create(), + ServiceContext = new TestServiceContext + { + SystemClock = new SystemClock() + } + }; + + _frameConnection = new FrameConnection(_frameConnectionContext); + } + + public void Dispose() + { + _pipeFactory.Dispose(); + } + + [Fact] + public void TimesOutWhenRequestBodyDoesNotSatisfyMinimumDataRate() + { + var requestBodyMinimumDataRate = 100; + var requestBodyGracePeriod = TimeSpan.FromSeconds(5); + + _frameConnectionContext.ServiceContext.ServerOptions.Limits.RequestBodyMinimumDataRate = + new MinimumDataRate(rate: requestBodyMinimumDataRate, gracePeriod: requestBodyGracePeriod); + + var mockLogger = new Mock(); + _frameConnectionContext.ServiceContext.Log = mockLogger.Object; + + _frameConnection.CreateFrame(new DummyApplication(context => Task.CompletedTask), _frameConnectionContext.Input.Reader, _frameConnectionContext.Output); + _frameConnection.Frame.Reset(); + + // Initialize timestamp + var now = DateTimeOffset.UtcNow; + _frameConnection.Tick(now); + + _frameConnection.StartTimingReads(); + + // Tick after grace period w/ low data rate + now += requestBodyGracePeriod + TimeSpan.FromSeconds(1); + _frameConnection.BytesRead(1); + _frameConnection.Tick(now); + + // Timed out + Assert.True(_frameConnection.TimedOut); + mockLogger.Verify(logger => + logger.RequestBodyMininumDataRateNotSatisfied(It.IsAny(), It.IsAny(), requestBodyMinimumDataRate), Times.Once); + } + + [Fact] + public void MinimumDataRateNotEnforcedDuringGracePeriod() + { + var requestBodyMinimumDataRate = 100; + var requestBodyGracePeriod = TimeSpan.FromSeconds(2); + + _frameConnectionContext.ServiceContext.ServerOptions.Limits.RequestBodyMinimumDataRate = + new MinimumDataRate(rate: requestBodyMinimumDataRate, gracePeriod: requestBodyGracePeriod); + + var mockLogger = new Mock(); + _frameConnectionContext.ServiceContext.Log = mockLogger.Object; + + _frameConnection.CreateFrame(new DummyApplication(context => Task.CompletedTask), _frameConnectionContext.Input.Reader, _frameConnectionContext.Output); + _frameConnection.Frame.Reset(); + + // Initialize timestamp + var now = DateTimeOffset.UtcNow; + _frameConnection.Tick(now); + + _frameConnection.StartTimingReads(); + + // Tick during grace period w/ low data rate + now += TimeSpan.FromSeconds(1); + _frameConnection.BytesRead(10); + _frameConnection.Tick(now); + + // Not timed out + Assert.False(_frameConnection.TimedOut); + mockLogger.Verify(logger => + logger.RequestBodyMininumDataRateNotSatisfied(It.IsAny(), It.IsAny(), requestBodyMinimumDataRate), Times.Never); + + // Tick after grace period w/ low data rate + now += TimeSpan.FromSeconds(2); + _frameConnection.BytesRead(10); + _frameConnection.Tick(now); + + // Timed out + Assert.True(_frameConnection.TimedOut); + mockLogger.Verify(logger => + logger.RequestBodyMininumDataRateNotSatisfied(It.IsAny(), It.IsAny(), requestBodyMinimumDataRate), Times.Once); + } + + [Fact] + public void DataRateIsAveragedOverTimeSpentReadingRequestBody() + { + var requestBodyMinimumDataRate = 100; + var requestBodyGracePeriod = TimeSpan.FromSeconds(1); + + _frameConnectionContext.ServiceContext.ServerOptions.Limits.RequestBodyMinimumDataRate = + new MinimumDataRate(rate: requestBodyMinimumDataRate, gracePeriod: requestBodyGracePeriod); + + var mockLogger = new Mock(); + _frameConnectionContext.ServiceContext.Log = mockLogger.Object; + + _frameConnection.CreateFrame(new DummyApplication(context => Task.CompletedTask), _frameConnectionContext.Input.Reader, _frameConnectionContext.Output); + _frameConnection.Frame.Reset(); + + // Initialize timestamp + var now = DateTimeOffset.UtcNow; + _frameConnection.Tick(now); + + _frameConnection.StartTimingReads(); + + // Tick after grace period to start enforcing minimum data rate + now += requestBodyGracePeriod; + _frameConnection.BytesRead(100); + _frameConnection.Tick(now); + + // Data rate: 200 bytes/second + now += TimeSpan.FromSeconds(1); + _frameConnection.BytesRead(300); + _frameConnection.Tick(now); + + // Not timed out + Assert.False(_frameConnection.TimedOut); + mockLogger.Verify(logger => + logger.RequestBodyMininumDataRateNotSatisfied(It.IsAny(), It.IsAny(), requestBodyMinimumDataRate), Times.Never); + + // Data rate: 150 bytes/second + now += TimeSpan.FromSeconds(1); + _frameConnection.BytesRead(50); + _frameConnection.Tick(now); + + // Not timed out + Assert.False(_frameConnection.TimedOut); + mockLogger.Verify(logger => + logger.RequestBodyMininumDataRateNotSatisfied(It.IsAny(), It.IsAny(), requestBodyMinimumDataRate), Times.Never); + + // Data rate: 115 bytes/second + now += TimeSpan.FromSeconds(1); + _frameConnection.BytesRead(10); + _frameConnection.Tick(now); + + // Not timed out + Assert.False(_frameConnection.TimedOut); + mockLogger.Verify(logger => + logger.RequestBodyMininumDataRateNotSatisfied(It.IsAny(), It.IsAny(), requestBodyMinimumDataRate), Times.Never); + + // Data rate: 50 bytes/second + now += TimeSpan.FromSeconds(6); + _frameConnection.BytesRead(40); + _frameConnection.Tick(now); + + // Timed out + Assert.True(_frameConnection.TimedOut); + mockLogger.Verify(logger => + logger.RequestBodyMininumDataRateNotSatisfied(It.IsAny(), It.IsAny(), requestBodyMinimumDataRate), Times.Once); + } + + [Fact] + public void PausedTimeDoesNotCountAgainstRequestBodyTimeout() + { + var requestBodyTimeout = TimeSpan.FromSeconds(5); + var systemClock = new MockSystemClock(); + + _frameConnectionContext.ServiceContext.ServerOptions.Limits.RequestBodyMinimumDataRate = + new MinimumDataRate(rate: 100, gracePeriod: TimeSpan.Zero); + _frameConnectionContext.ServiceContext.SystemClock = systemClock; + + var mockLogger = new Mock(); + _frameConnectionContext.ServiceContext.Log = mockLogger.Object; + + _frameConnection.CreateFrame(new DummyApplication(context => Task.CompletedTask), _frameConnectionContext.Input.Reader, _frameConnectionContext.Output); + _frameConnection.Frame.Reset(); + + // Initialize timestamp + _frameConnection.Tick(systemClock.UtcNow); + + _frameConnection.StartTimingReads(); + + // Tick at 1s, expected counted time is 1s, expected data rate is 400 bytes/second + systemClock.UtcNow += TimeSpan.FromSeconds(1); + _frameConnection.BytesRead(400); + _frameConnection.Tick(systemClock.UtcNow); + + // Pause at 1.5s + systemClock.UtcNow += TimeSpan.FromSeconds(0.5); + _frameConnection.PauseTimingReads(); + + // Tick at 2s, expected counted time is 2s, expected data rate is 400 bytes/second + systemClock.UtcNow += TimeSpan.FromSeconds(0.5); + _frameConnection.Tick(systemClock.UtcNow); + + // Tick at 6s, expected counted time is 2s, expected data rate is 400 bytes/second + systemClock.UtcNow += TimeSpan.FromSeconds(4); + _frameConnection.Tick(systemClock.UtcNow); + + // Not timed out + Assert.False(_frameConnection.TimedOut); + mockLogger.Verify( + logger => logger.RequestBodyMininumDataRateNotSatisfied(It.IsAny(), It.IsAny(), It.IsAny()), + Times.Never); + + // Resume at 6.5s + systemClock.UtcNow += TimeSpan.FromSeconds(0.5); + _frameConnection.ResumeTimingReads(); + + // Tick at 8s, expected counted time is 4s, expected data rate is 100 bytes/second + systemClock.UtcNow += TimeSpan.FromSeconds(1.5); + _frameConnection.Tick(systemClock.UtcNow); + + // Not timed out + Assert.False(_frameConnection.TimedOut); + mockLogger.Verify( + logger => logger.RequestBodyMininumDataRateNotSatisfied(It.IsAny(), It.IsAny(), It.IsAny()), + Times.Never); + + // Tick at 9s, expected counted time is 9s, expected data rate drops below 100 bytes/second + systemClock.UtcNow += TimeSpan.FromSeconds(1); + _frameConnection.Tick(systemClock.UtcNow); + + // Timed out + Assert.True(_frameConnection.TimedOut); + mockLogger.Verify( + logger => logger.RequestBodyMininumDataRateNotSatisfied(It.IsAny(), It.IsAny(), It.IsAny()), + Times.Once); + } + + [Fact] + public void NotPausedWhenResumeCalledBeforeNextTick() + { + var systemClock = new MockSystemClock(); + + _frameConnectionContext.ServiceContext.ServerOptions.Limits.RequestBodyMinimumDataRate = + new MinimumDataRate(rate: 100, gracePeriod: TimeSpan.Zero); + _frameConnectionContext.ServiceContext.SystemClock = systemClock; + + var mockLogger = new Mock(); + _frameConnectionContext.ServiceContext.Log = mockLogger.Object; + + _frameConnection.CreateFrame(new DummyApplication(context => Task.CompletedTask), _frameConnectionContext.Input.Reader, _frameConnectionContext.Output); + _frameConnection.Frame.Reset(); + + // Initialize timestamp + _frameConnection.Tick(systemClock.UtcNow); + + _frameConnection.StartTimingReads(); + + // Tick at 1s, expected counted time is 1s, expected data rate is 100 bytes/second + systemClock.UtcNow += TimeSpan.FromSeconds(1); + _frameConnection.BytesRead(100); + _frameConnection.Tick(systemClock.UtcNow); + + // Not timed out + Assert.False(_frameConnection.TimedOut); + mockLogger.Verify( + logger => logger.RequestBodyMininumDataRateNotSatisfied(It.IsAny(), It.IsAny(), It.IsAny()), + Times.Never); + + // Pause at 1.25s + systemClock.UtcNow += TimeSpan.FromSeconds(0.25); + _frameConnection.PauseTimingReads(); + + // Resume at 1.5s + systemClock.UtcNow += TimeSpan.FromSeconds(0.25); + _frameConnection.ResumeTimingReads(); + + // Tick at 2s, expected counted time is 2s, expected data rate is 100 bytes/second + systemClock.UtcNow += TimeSpan.FromSeconds(0.5); + _frameConnection.BytesRead(100); + _frameConnection.Tick(systemClock.UtcNow); + + // Not timed out + Assert.False(_frameConnection.TimedOut); + mockLogger.Verify( + logger => logger.RequestBodyMininumDataRateNotSatisfied(It.IsAny(), It.IsAny(), It.IsAny()), + Times.Never); + + // Tick at 3s, expected counted time is 3s, expected data rate drops below 100 bytes/second + systemClock.UtcNow += TimeSpan.FromSeconds(1); + _frameConnection.Tick(systemClock.UtcNow); + + // Timed out + Assert.True(_frameConnection.TimedOut); + mockLogger.Verify( + logger => logger.RequestBodyMininumDataRateNotSatisfied(It.IsAny(), It.IsAny(), It.IsAny()), + Times.Once); + } + } +} diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameTests.cs index e8d2481942..73fd432a15 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameTests.cs @@ -12,6 +12,7 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Hosting.Server; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http.Features; +using Microsoft.AspNetCore.Server.Kestrel.Core.Features; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; @@ -140,6 +141,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests Assert.NotEqual(nextId, secondId); } + [Fact] + public void ResetResetsRequestBodyMinimumDataRate() + { + _frame.RequestBodyMinimumDataRate = new MinimumDataRate(rate: 1, gracePeriod: TimeSpan.Zero); + + _frame.Reset(); + + Assert.Equal(_serviceContext.ServerOptions.Limits.RequestBodyMinimumDataRate, _frame.RequestBodyMinimumDataRate); + } + [Fact] public void TraceIdentifierCountsRequestsPerFrame() { @@ -243,6 +254,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests Assert.Throws(() => ((IHttpResponseFeature)_frame).OnStarting(_ => TaskCache.CompletedTask, null)); } + [Theory] + [MemberData(nameof(RequestBodyMinimumDataRateData))] + public void ConfiguringRequestBodyMinimumDataRateFeatureSetsRequestBodyMinimumDateRate(MinimumDataRate minimumDataRate) + { + ((IFeatureCollection)_frame).Get().MinimumDataRate = minimumDataRate; + + Assert.Same(minimumDataRate, _frame.RequestBodyMinimumDataRate); + } + [Fact] public void ResetResetsRequestHeaders() { @@ -844,6 +864,27 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests } } + public static TheoryData RequestBodyTimeoutDataValid => new TheoryData + { + TimeSpan.FromTicks(1), + TimeSpan.MaxValue, + Timeout.InfiniteTimeSpan, + TimeSpan.FromMilliseconds(-1) // Same as Timeout.InfiniteTimeSpan + }; + + public static TheoryData RequestBodyTimeoutDataInvalid => new TheoryData + { + TimeSpan.MinValue, + TimeSpan.FromTicks(-1), + TimeSpan.Zero + }; + + public static TheoryData RequestBodyMinimumDataRateData => new TheoryData + { + null, + new MinimumDataRate(rate: 1, gracePeriod: TimeSpan.Zero) + }; + private class RequestHeadersWrapper : IHeaderDictionary { IHeaderDictionary _innerHeaders; diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/KestrelServerLimitsTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/KestrelServerLimitsTests.cs index 863dfd7ff4..914ceeff11 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/KestrelServerLimitsTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/KestrelServerLimitsTests.cs @@ -2,7 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using Microsoft.AspNetCore.Server.Kestrel.Core; +using System.Threading; using Xunit; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests @@ -154,16 +154,26 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests } [Theory] - [InlineData(0)] - [InlineData(0.5)] - [InlineData(2.1)] - [InlineData(2.5)] - [InlineData(2.9)] - public void KeepAliveTimeoutValid(double seconds) + [MemberData(nameof(TimeoutValidData))] + public void KeepAliveTimeoutValid(TimeSpan value) { - var o = new KestrelServerLimits(); - o.KeepAliveTimeout = TimeSpan.FromSeconds(seconds); - Assert.Equal(seconds, o.KeepAliveTimeout.TotalSeconds); + Assert.Equal(value, new KestrelServerLimits { KeepAliveTimeout = value }.KeepAliveTimeout); + } + + [Fact] + public void KeepAliveTimeoutCanBeSetToInfinite() + { + Assert.Equal(TimeSpan.MaxValue, new KestrelServerLimits { KeepAliveTimeout = Timeout.InfiniteTimeSpan }.KeepAliveTimeout); + } + + [Theory] + [MemberData(nameof(TimeoutInvalidData))] + public void KeepAliveTimeoutInvalid(TimeSpan value) + { + var exception = Assert.Throws(() => new KestrelServerLimits { KeepAliveTimeout = value }); + + Assert.Equal("value", exception.ParamName); + Assert.StartsWith(CoreStrings.PositiveTimeSpanRequired, exception.Message); } [Fact] @@ -173,17 +183,26 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests } [Theory] - [InlineData(0)] - [InlineData(0.5)] - [InlineData(1.0)] - [InlineData(2.5)] - [InlineData(10)] - [InlineData(60)] - public void RequestHeadersTimeoutValid(double seconds) + [MemberData(nameof(TimeoutValidData))] + public void RequestHeadersTimeoutValid(TimeSpan value) { - var o = new KestrelServerLimits(); - o.RequestHeadersTimeout = TimeSpan.FromSeconds(seconds); - Assert.Equal(seconds, o.RequestHeadersTimeout.TotalSeconds); + Assert.Equal(value, new KestrelServerLimits { RequestHeadersTimeout = value }.RequestHeadersTimeout); + } + + [Fact] + public void RequestHeadersTimeoutCanBeSetToInfinite() + { + Assert.Equal(TimeSpan.MaxValue, new KestrelServerLimits { RequestHeadersTimeout = Timeout.InfiniteTimeSpan }.RequestHeadersTimeout); + } + + [Theory] + [MemberData(nameof(TimeoutInvalidData))] + public void RequestHeadersTimeoutInvalid(TimeSpan value) + { + var exception = Assert.Throws(() => new KestrelServerLimits { RequestHeadersTimeout = value }); + + Assert.Equal("value", exception.ParamName); + Assert.StartsWith(CoreStrings.PositiveTimeSpanRequired, exception.Message); } [Fact] @@ -272,5 +291,31 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests var ex = Assert.Throws(() => new KestrelServerLimits().MaxRequestBodySize = value); Assert.StartsWith(CoreStrings.NonNegativeNumberOrNullRequired, ex.Message); } + + [Fact] + public void RequestBodyMinimumDataRateDefault() + { + Assert.NotNull(new KestrelServerLimits().RequestBodyMinimumDataRate); + Assert.Equal(1, new KestrelServerLimits().RequestBodyMinimumDataRate.Rate); + Assert.Equal(TimeSpan.FromSeconds(5), new KestrelServerLimits().RequestBodyMinimumDataRate.GracePeriod); + } + + public static TheoryData TimeoutValidData => new TheoryData + { + TimeSpan.FromTicks(1), + TimeSpan.MaxValue, + }; + + public static TheoryData TimeoutInfiniteData => new TheoryData + { + Timeout.InfiniteTimeSpan, + }; + + public static TheoryData TimeoutInvalidData => new TheoryData + { + TimeSpan.MinValue, + TimeSpan.FromTicks(-1), + TimeSpan.Zero + }; } } diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/KestrelServerTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/KestrelServerTests.cs index a61feba7bc..843888df40 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/KestrelServerTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/KestrelServerTests.cs @@ -8,6 +8,7 @@ using System.Threading; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting.Server; using Microsoft.AspNetCore.Hosting.Server.Features; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions; using Microsoft.AspNetCore.Testing; using Microsoft.Extensions.Internal; @@ -100,9 +101,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests public void StartWithMaxRequestBufferSizeLessThanMaxRequestLineSizeThrows(long maxRequestBufferSize, int maxRequestLineSize) { var testLogger = new TestApplicationErrorLogger { ThrowOnCriticalErrors = false }; - var options = new KestrelServerOptions(); - options.Limits.MaxRequestBufferSize = maxRequestBufferSize; - options.Limits.MaxRequestLineSize = maxRequestLineSize; + var options = new KestrelServerOptions + { + Limits = + { + MaxRequestBufferSize = maxRequestBufferSize, + MaxRequestLineSize = maxRequestLineSize + } + }; using (var server = CreateServer(options, testLogger)) { @@ -121,10 +127,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests public void StartWithMaxRequestBufferSizeLessThanMaxRequestHeadersTotalSizeThrows(long maxRequestBufferSize, int maxRequestHeadersTotalSize) { var testLogger = new TestApplicationErrorLogger { ThrowOnCriticalErrors = false }; - var options = new KestrelServerOptions(); - options.Limits.MaxRequestBufferSize = maxRequestBufferSize; - options.Limits.MaxRequestLineSize = (int)maxRequestBufferSize; - options.Limits.MaxRequestHeadersTotalSize = maxRequestHeadersTotalSize; + var options = new KestrelServerOptions + { + Limits = + { + MaxRequestBufferSize = maxRequestBufferSize, + MaxRequestLineSize = (int)maxRequestBufferSize, + MaxRequestHeadersTotalSize = maxRequestHeadersTotalSize + } + }; using (var server = CreateServer(options, testLogger)) { @@ -146,7 +157,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests } [Fact] - public void StartWithNoTrasnportFactoryThrows() + public void StartWithNoTransportFactoryThrows() { var exception = Assert.Throws(() => new KestrelServer(Options.Create(null), null, Mock.Of())); diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/MessageBodyTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/MessageBodyTests.cs index 1bb42355f6..b884baa874 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/MessageBodyTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/MessageBodyTests.cs @@ -9,14 +9,12 @@ using System.Text; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Server.Kestrel.Core.Internal; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; using Microsoft.AspNetCore.Testing; using Microsoft.Extensions.Internal; -using Microsoft.Extensions.Logging; using Moq; using Xunit; -using Xunit.Abstractions; using Xunit.Sdk; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests @@ -30,7 +28,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests { using (var input = new TestInput()) { - var body = MessageBody.For(httpVersion, new FrameRequestHeaders { HeaderContentLength = "5" }, input.FrameContext); + var body = MessageBody.For(httpVersion, new FrameRequestHeaders { HeaderContentLength = "5" }, input.Frame); var stream = new FrameRequestStream(); stream.StartAcceptingReads(body); @@ -54,7 +52,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests { using (var input = new TestInput()) { - var body = MessageBody.For(httpVersion, new FrameRequestHeaders { HeaderContentLength = "5" }, input.FrameContext); + var body = MessageBody.For(httpVersion, new FrameRequestHeaders { HeaderContentLength = "5" }, input.Frame); var stream = new FrameRequestStream(); stream.StartAcceptingReads(body); @@ -76,7 +74,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests { using (var input = new TestInput()) { - var body = MessageBody.For(HttpVersion.Http11, new FrameRequestHeaders { HeaderTransferEncoding = "chunked" }, input.FrameContext); + var body = MessageBody.For(HttpVersion.Http11, new FrameRequestHeaders { HeaderTransferEncoding = "chunked" }, input.Frame); var stream = new FrameRequestStream(); stream.StartAcceptingReads(body); @@ -100,7 +98,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests { using (var input = new TestInput()) { - var body = MessageBody.For(HttpVersion.Http11, new FrameRequestHeaders { HeaderTransferEncoding = "chunked" }, input.FrameContext); + var body = MessageBody.For(HttpVersion.Http11, new FrameRequestHeaders { HeaderTransferEncoding = "chunked" }, input.Frame); var stream = new FrameRequestStream(); stream.StartAcceptingReads(body); @@ -124,7 +122,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests { using (var input = new TestInput()) { - var body = MessageBody.For(HttpVersion.Http11, new FrameRequestHeaders { HeaderTransferEncoding = "chunked" }, input.FrameContext); + var body = MessageBody.For(HttpVersion.Http11, new FrameRequestHeaders { HeaderTransferEncoding = "chunked" }, input.Frame); var stream = new FrameRequestStream(); stream.StartAcceptingReads(body); @@ -147,7 +145,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests { using (var input = new TestInput()) { - var body = MessageBody.For(HttpVersion.Http11, new FrameRequestHeaders { HeaderTransferEncoding = "chunked" }, input.FrameContext); + var body = MessageBody.For(HttpVersion.Http11, new FrameRequestHeaders { HeaderTransferEncoding = "chunked" }, input.Frame); var stream = new FrameRequestStream(); stream.StartAcceptingReads(body); @@ -166,7 +164,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests { using (var input = new TestInput()) { - var body = MessageBody.For(HttpVersion.Http11, new FrameRequestHeaders { HeaderTransferEncoding = "chunked" }, input.FrameContext); + var body = MessageBody.For(HttpVersion.Http11, new FrameRequestHeaders { HeaderTransferEncoding = "chunked" }, input.Frame); var stream = new FrameRequestStream(); stream.StartAcceptingReads(body); @@ -187,7 +185,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests { using (var input = new TestInput()) { - var body = MessageBody.For(httpVersion, new FrameRequestHeaders { HeaderConnection = "upgrade" }, input.FrameContext); + var body = MessageBody.For(httpVersion, new FrameRequestHeaders { HeaderConnection = "upgrade" }, input.Frame); var stream = new FrameRequestStream(); stream.StartAcceptingReads(body); @@ -210,7 +208,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests { using (var input = new TestInput()) { - var body = MessageBody.For(httpVersion, new FrameRequestHeaders { HeaderConnection = "upgrade" }, input.FrameContext); + var body = MessageBody.For(httpVersion, new FrameRequestHeaders { HeaderConnection = "upgrade" }, input.Frame); var stream = new FrameRequestStream(); stream.StartAcceptingReads(body); @@ -233,7 +231,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests { using (var input = new TestInput()) { - var body = MessageBody.For(httpVersion, new FrameRequestHeaders(), input.FrameContext); + var body = MessageBody.For(httpVersion, new FrameRequestHeaders(), input.Frame); var stream = new FrameRequestStream(); stream.StartAcceptingReads(body); @@ -251,7 +249,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests { using (var input = new TestInput()) { - var body = MessageBody.For(httpVersion, new FrameRequestHeaders(), input.FrameContext); + var body = MessageBody.For(httpVersion, new FrameRequestHeaders(), input.Frame); var stream = new FrameRequestStream(); stream.StartAcceptingReads(body); @@ -267,7 +265,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests { using (var input = new TestInput()) { - var body = MessageBody.For(HttpVersion.Http10, new FrameRequestHeaders { HeaderContentLength = "8197" }, input.FrameContext); + var body = MessageBody.For(HttpVersion.Http10, new FrameRequestHeaders { HeaderContentLength = "8197" }, input.Frame); var stream = new FrameRequestStream(); stream.StartAcceptingReads(body); @@ -294,7 +292,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests using (var input = new TestInput()) { var ex = Assert.Throws(() => - MessageBody.For(HttpVersion.Http11, new FrameRequestHeaders { HeaderTransferEncoding = "chunked, not-chunked" }, input.FrameContext)); + MessageBody.For(HttpVersion.Http11, new FrameRequestHeaders { HeaderTransferEncoding = "chunked, not-chunked" }, input.Frame)); Assert.Equal(StatusCodes.Status400BadRequest, ex.StatusCode); Assert.Equal(CoreStrings.FormatBadRequest_FinalTransferCodingNotChunked("chunked, not-chunked"), ex.Message); @@ -308,9 +306,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests { using (var input = new TestInput()) { - input.FrameContext.Method = method; + input.Frame.Method = method; var ex = Assert.Throws(() => - MessageBody.For(HttpVersion.Http11, new FrameRequestHeaders(), input.FrameContext)); + MessageBody.For(HttpVersion.Http11, new FrameRequestHeaders(), input.Frame)); Assert.Equal(StatusCodes.Status411LengthRequired, ex.StatusCode); Assert.Equal(CoreStrings.FormatBadRequest_LengthRequired(method), ex.Message); @@ -324,9 +322,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests { using (var input = new TestInput()) { - input.FrameContext.Method = method; + input.Frame.Method = method; var ex = Assert.Throws(() => - MessageBody.For(HttpVersion.Http10, new FrameRequestHeaders(), input.FrameContext)); + MessageBody.For(HttpVersion.Http10, new FrameRequestHeaders(), input.Frame)); Assert.Equal(StatusCodes.Status400BadRequest, ex.StatusCode); Assert.Equal(CoreStrings.FormatBadRequest_LengthRequiredHttp10(method), ex.Message); @@ -338,7 +336,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests { using (var input = new TestInput()) { - var body = MessageBody.For(HttpVersion.Http10, new FrameRequestHeaders { HeaderContentLength = "5" }, input.FrameContext); + var body = MessageBody.For(HttpVersion.Http10, new FrameRequestHeaders { HeaderContentLength = "5" }, input.Frame); + input.Add("Hello"); using (var ms = new MemoryStream()) @@ -355,7 +354,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests { using (var input = new TestInput()) { - var body = MessageBody.For(HttpVersion.Http10, new FrameRequestHeaders { HeaderContentLength = "5" }, input.FrameContext); + var body = MessageBody.For(HttpVersion.Http10, new FrameRequestHeaders { HeaderContentLength = "5" }, input.Frame); + input.Add("Hello"); await body.ConsumeAsync(); @@ -402,7 +402,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests using (var input = new TestInput()) { - var body = MessageBody.For(HttpVersion.Http11, headers, input.FrameContext); + var body = MessageBody.For(HttpVersion.Http11, headers, input.Frame); + var copyToAsyncTask = body.CopyToAsync(mockDestination.Object); // The block returned by IncomingStart always has at least 2048 available bytes, @@ -448,7 +449,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests { using (var input = new TestInput()) { - var body = MessageBody.For(HttpVersion.Http11, new FrameRequestHeaders { HeaderConnection = headerConnection }, input.FrameContext); + var body = MessageBody.For(HttpVersion.Http11, new FrameRequestHeaders { HeaderConnection = headerConnection }, input.Frame); var stream = new FrameRequestStream(); stream.StartAcceptingReads(body); @@ -463,15 +464,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests } [Fact] - public async Task StartAsyncDoesNotReturnAfterCancelingInput() + public async Task PumpAsyncDoesNotReturnAfterCancelingInput() { using (var input = new TestInput()) { - var body = MessageBody.For(HttpVersion.Http11, new FrameRequestHeaders { HeaderContentLength = "2" }, input.FrameContext); + var body = MessageBody.For(HttpVersion.Http11, new FrameRequestHeaders { HeaderContentLength = "2" }, input.Frame); var stream = new FrameRequestStream(); stream.StartAcceptingReads(body); - // Add some input and consume it to ensure StartAsync is in the loop + // Add some input and consume it to ensure PumpAsync is running input.Add("a"); Assert.Equal(1, await stream.ReadAsync(new byte[1], 0, 1)); @@ -485,15 +486,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests } [Fact] - public async Task StartAsyncReturnsAfterCanceling() + public async Task PumpAsyncReturnsAfterCanceling() { using (var input = new TestInput()) { - var body = MessageBody.For(HttpVersion.Http11, new FrameRequestHeaders { HeaderContentLength = "2" }, input.FrameContext); + var body = MessageBody.For(HttpVersion.Http11, new FrameRequestHeaders { HeaderContentLength = "2" }, input.Frame); var stream = new FrameRequestStream(); stream.StartAcceptingReads(body); - // Add some input and consume it to ensure StartAsync is in the loop + // Add some input and consume it to ensure PumpAsync is running input.Add("a"); Assert.Equal(1, await stream.ReadAsync(new byte[1], 0, 1)); @@ -511,6 +512,198 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests } } + [Fact] + public async Task ReadAsyncThrowsOnTimeout() + { + using (var input = new TestInput()) + { + var mockTimeoutControl = new Mock(); + + input.FrameContext.TimeoutControl = mockTimeoutControl.Object; + + var body = MessageBody.For(HttpVersion.Http11, new FrameRequestHeaders { HeaderContentLength = "5" }, input.Frame); + + // Add some input and read it to start PumpAsync + input.Add("a"); + Assert.Equal(1, await body.ReadAsync(new ArraySegment(new byte[1]))); + + // Time out on the next read + mockTimeoutControl + .Setup(timeoutControl => timeoutControl.TimedOut) + .Returns(true); + + input.Cancel(); + + var exception = await Assert.ThrowsAsync(() => body.ReadAsync(new ArraySegment(new byte[1]))); + Assert.Equal(StatusCodes.Status408RequestTimeout, exception.StatusCode); + } + } + + [Fact] + public async Task ConsumeAsyncThrowsOnTimeout() + { + using (var input = new TestInput()) + { + var mockTimeoutControl = new Mock(); + + input.FrameContext.TimeoutControl = mockTimeoutControl.Object; + + var body = MessageBody.For(HttpVersion.Http11, new FrameRequestHeaders { HeaderContentLength = "5" }, input.Frame); + + // Add some input and read it to start PumpAsync + input.Add("a"); + Assert.Equal(1, await body.ReadAsync(new ArraySegment(new byte[1]))); + + // Time out on the next read + mockTimeoutControl + .Setup(timeoutControl => timeoutControl.TimedOut) + .Returns(true); + + input.Cancel(); + + var exception = await Assert.ThrowsAsync(() => body.ConsumeAsync()); + Assert.Equal(StatusCodes.Status408RequestTimeout, exception.StatusCode); + } + } + + [Fact] + public async Task CopyToAsyncThrowsOnTimeout() + { + using (var input = new TestInput()) + { + var mockTimeoutControl = new Mock(); + + input.FrameContext.TimeoutControl = mockTimeoutControl.Object; + + var body = MessageBody.For(HttpVersion.Http11, new FrameRequestHeaders { HeaderContentLength = "5" }, input.Frame); + + // Add some input and read it to start PumpAsync + input.Add("a"); + Assert.Equal(1, await body.ReadAsync(new ArraySegment(new byte[1]))); + + // Time out on the next read + mockTimeoutControl + .Setup(timeoutControl => timeoutControl.TimedOut) + .Returns(true); + + input.Cancel(); + + using (var ms = new MemoryStream()) + { + var exception = await Assert.ThrowsAsync(() => body.CopyToAsync(ms)); + Assert.Equal(StatusCodes.Status408RequestTimeout, exception.StatusCode); + } + } + } + + [Fact] + public async Task LogsWhenStartsReadingRequestBody() + { + using (var input = new TestInput()) + { + var mockLogger = new Mock(); + input.Frame.ServiceContext.Log = mockLogger.Object; + input.Frame.ConnectionIdFeature = "ConnectionId"; + input.Frame.TraceIdentifier = "RequestId"; + + var body = MessageBody.For(HttpVersion.Http11, new FrameRequestHeaders { HeaderContentLength = "2" }, input.Frame); + var stream = new FrameRequestStream(); + stream.StartAcceptingReads(body); + + // Add some input and consume it to ensure PumpAsync is running + input.Add("a"); + Assert.Equal(1, await stream.ReadAsync(new byte[1], 0, 1)); + + mockLogger.Verify(logger => logger.RequestBodyStart("ConnectionId", "RequestId")); + + input.Fin(); + } + } + + [Fact] + public async Task LogsWhenStopsReadingRequestBody() + { + using (var input = new TestInput()) + { + var logEvent = new ManualResetEventSlim(); + var mockLogger = new Mock(); + mockLogger + .Setup(logger => logger.RequestBodyDone("ConnectionId", "RequestId")) + .Callback(() => logEvent.Set()); + input.Frame.ServiceContext.Log = mockLogger.Object; + input.Frame.ConnectionIdFeature = "ConnectionId"; + input.Frame.TraceIdentifier = "RequestId"; + + var body = MessageBody.For(HttpVersion.Http11, new FrameRequestHeaders { HeaderContentLength = "2" }, input.Frame); + var stream = new FrameRequestStream(); + stream.StartAcceptingReads(body); + + // Add some input and consume it to ensure PumpAsync is running + input.Add("a"); + Assert.Equal(1, await stream.ReadAsync(new byte[1], 0, 1)); + + input.Fin(); + + Assert.True(logEvent.Wait(TimeSpan.FromSeconds(10))); + } + } + + [Fact] + public async Task OnlyEnforcesRequestBodyTimeoutAfterSending100Continue() + { + using (var input = new TestInput()) + { + var produceContinueCalled = false; + var startTimingReadsCalledAfterProduceContinue = false; + + var mockFrameControl = new Mock(); + mockFrameControl + .Setup(frameControl => frameControl.ProduceContinue()) + .Callback(() => produceContinueCalled = true); + input.Frame.FrameControl = mockFrameControl.Object; + + var mockTimeoutControl = new Mock(); + mockTimeoutControl + .Setup(timeoutControl => timeoutControl.StartTimingReads()) + .Callback(() => startTimingReadsCalledAfterProduceContinue = produceContinueCalled); + + input.FrameContext.TimeoutControl = mockTimeoutControl.Object; + + var body = MessageBody.For(HttpVersion.Http11, new FrameRequestHeaders { HeaderContentLength = "5" }, input.Frame); + + // Add some input and read it to start PumpAsync + var readTask = body.ReadAsync(new ArraySegment(new byte[1])); + + Assert.True(startTimingReadsCalledAfterProduceContinue); + + input.Add("a"); + await readTask; + } + } + + [Fact] + public async Task DoesNotEnforceRequestBodyTimeoutOnUpgradeRequests() + { + using (var input = new TestInput()) + { + var mockTimeoutControl = new Mock(); + input.FrameContext.TimeoutControl = mockTimeoutControl.Object; + + var body = MessageBody.For(HttpVersion.Http11, new FrameRequestHeaders { HeaderConnection = "upgrade" }, input.Frame); + + // Add some input and read it to start PumpAsync + input.Add("a"); + Assert.Equal(1, await body.ReadAsync(new ArraySegment(new byte[1]))); + + input.Fin(); + + await Assert.ThrowsAsync(async () => await body.ReadAsync(new ArraySegment(new byte[1]))); + + mockTimeoutControl.Verify(timeoutControl => timeoutControl.StartTimingReads(), Times.Never); + mockTimeoutControl.Verify(timeoutControl => timeoutControl.StopTimingReads(), Times.Never); + } + } + private void AssertASCII(string expected, ArraySegment actual) { var encoding = Encoding.ASCII; diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/MinimumDataRateTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/MinimumDataRateTests.cs new file mode 100644 index 0000000000..79660bf799 --- /dev/null +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/MinimumDataRateTests.cs @@ -0,0 +1,61 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using Microsoft.AspNetCore.Server.Kestrel.Core.Features; +using Xunit; + +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests +{ + public class MinimumDataRateTests + { + [Theory] + [InlineData(double.Epsilon)] + [InlineData(double.MaxValue)] + public void RateValid(double value) + { + Assert.Equal(value, new MinimumDataRate(rate: value, gracePeriod: TimeSpan.Zero).Rate); + } + + [Theory] + [InlineData(double.MinValue)] + [InlineData(0)] + public void RateInvalid(double value) + { + var exception = Assert.Throws(() => new MinimumDataRate(rate: value, gracePeriod: TimeSpan.Zero)); + + Assert.Equal("rate", exception.ParamName); + Assert.StartsWith(CoreStrings.PositiveNumberRequired, exception.Message); + } + + [Theory] + [MemberData(nameof(GracePeriodValidData))] + public void GracePeriodValid(TimeSpan value) + { + Assert.Equal(value, new MinimumDataRate(rate: 1, gracePeriod: value).GracePeriod); + } + + [Theory] + [MemberData(nameof(GracePeriodInvalidData))] + public void GracePeriodInvalid(TimeSpan value) + { + var exception = Assert.Throws(() => new MinimumDataRate(rate: 1, gracePeriod: value)); + + Assert.Equal("gracePeriod", exception.ParamName); + Assert.StartsWith(CoreStrings.NonNegativeTimeSpanRequired, exception.Message); + } + + public static TheoryData GracePeriodValidData => new TheoryData + { + TimeSpan.Zero, + TimeSpan.FromTicks(1), + TimeSpan.MaxValue + }; + + public static TheoryData GracePeriodInvalidData => new TheoryData + { + TimeSpan.MinValue, + TimeSpan.FromTicks(-1) + }; + } +} diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/TestInput.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/TestInput.cs index df90641045..1a9cf1620f 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/TestInput.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/TestInput.cs @@ -2,21 +2,16 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.IO; using System.Text; -using System.Threading; -using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; -using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions; using Microsoft.AspNetCore.Testing; -using Microsoft.Extensions.Internal; using Moq; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests { - class TestInput : IFrameControl, IDisposable + class TestInput : IDisposable { private MemoryPool _memoryPool; private PipeFactory _pipelineFactory; @@ -27,23 +22,28 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests _pipelineFactory = new PipeFactory(); Pipe = _pipelineFactory.Create(); - FrameContext = new Frame(null, new FrameContext + FrameContext = new FrameContext { ServiceContext = new TestServiceContext(), Input = Pipe.Reader, ConnectionInformation = new MockConnectionInformation { PipeFactory = _pipelineFactory - } - }); - FrameContext.FrameControl = this; + }, + TimeoutControl = Mock.Of() + }; + + Frame = new Frame(null, FrameContext); + Frame.FrameControl = Mock.Of(); } public IPipe Pipe { get; } public PipeFactory PipeFactory => _pipelineFactory; - public Frame FrameContext { get; set; } + public FrameContext FrameContext { get; } + + public Frame Frame { get; set; } public void Add(string text) { @@ -56,38 +56,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests Pipe.Writer.Complete(); } - public void ProduceContinue() + public void Cancel() { - } - - public void Pause() - { - } - - public void Resume() - { - } - - public void End(ProduceEndType endType) - { - } - - public void Abort() - { - } - - public void Write(ArraySegment data, Action callback, object state) - { - } - - Task IFrameControl.WriteAsync(ArraySegment data, CancellationToken cancellationToken) - { - return TaskCache.CompletedTask; - } - - Task IFrameControl.FlushAsync(CancellationToken cancellationToken) - { - return TaskCache.CompletedTask; + Pipe.Reader.CancelPendingRead(); } public void Dispose() diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/KeepAliveTimeoutTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/KeepAliveTimeoutTests.cs index 4e6d0f1304..3f82032104 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/KeepAliveTimeoutTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/KeepAliveTimeoutTests.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.IO; using System.Text; using System.Threading; using System.Threading.Tasks; @@ -96,7 +97,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests cts.CancelAfter(LongDelay); await connection.Send( - "POST / HTTP/1.1", + "POST /consume HTTP/1.1", "Host:", "Transfer-Encoding: chunked", "", @@ -193,7 +194,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests ServerOptions = { AddServerHeader = false, - Limits = { KeepAliveTimeout = KeepAliveTimeout } + Limits = + { + KeepAliveTimeout = KeepAliveTimeout, + RequestBodyMinimumDataRate = null + } } }); } @@ -201,6 +206,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests private async Task App(HttpContext httpContext, CancellationToken longRunningCt, CancellationToken upgradeCt) { var ct = httpContext.RequestAborted; + var responseStream = httpContext.Response.Body; + var responseBytes = Encoding.ASCII.GetBytes("hello, world"); if (httpContext.Request.Path == "/longrunning") { @@ -208,8 +215,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { await Task.Delay(1000); } - - await httpContext.Response.WriteAsync("hello, world"); } else if (httpContext.Request.Path == "/upgrade") { @@ -220,14 +225,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests await Task.Delay(LongDelay); } - var responseBytes = Encoding.ASCII.GetBytes("hello, world"); - await stream.WriteAsync(responseBytes, 0, responseBytes.Length); + responseStream = stream; } } - else + else if (httpContext.Request.Path == "/consume") { - await httpContext.Response.WriteAsync("hello, world"); + var buffer = new byte[1024]; + while (await httpContext.Request.Body.ReadAsync(buffer, 0, buffer.Length) > 0) ; } + + await responseStream.WriteAsync(responseBytes, 0, responseBytes.Length); } private async Task ReceiveResponse(TestConnection connection) diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/MaxRequestBufferSizeTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/MaxRequestBufferSizeTests.cs index e05d50fc9d..1331ccf41e 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/MaxRequestBufferSizeTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/MaxRequestBufferSizeTests.cs @@ -8,7 +8,6 @@ using System.Linq; using System.Net; using System.Net.Sockets; using System.Text; -using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; @@ -274,6 +273,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { options.Limits.MaxRequestHeadersTotalSize = (int)maxRequestBufferSize; } + + options.Limits.RequestBodyMinimumDataRate = null; }) .UseContentRoot(Directory.GetCurrentDirectory()) .Configure(app => app.Run(async context => diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestBodyTimeoutTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestBodyTimeoutTests.cs new file mode 100644 index 0000000000..2351a696c8 --- /dev/null +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestBodyTimeoutTests.cs @@ -0,0 +1,172 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Threading; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Server.Kestrel.Core; +using Microsoft.AspNetCore.Server.Kestrel.Core.Features; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; +using Microsoft.AspNetCore.Testing; +using Xunit; + +namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests +{ + public class RequestBodyTimeoutTests + { + [Fact] + public async Task RequestTimesOutWhenRequestBodyNotReceivedAtDesiredMinimumRate() + { + var minimumDataRateGracePeriod = TimeSpan.FromSeconds(5); + var systemClock = new MockSystemClock(); + var serviceContext = new TestServiceContext + { + SystemClock = systemClock, + DateHeaderValueManager = new DateHeaderValueManager(systemClock) + }; + + var appRunningEvent = new ManualResetEventSlim(); + + using (var server = new TestServer(context => + { + context.Features.Get().MinimumDataRate = + new MinimumDataRate(rate: 1, gracePeriod: minimumDataRateGracePeriod); + + appRunningEvent.Set(); + return context.Request.Body.ReadAsync(new byte[1], 0, 1); + }, serviceContext)) + { + using (var connection = server.CreateConnection()) + { + await connection.Send( + "POST / HTTP/1.1", + "Host:", + "Content-Length: 1", + "", + ""); + + Assert.True(appRunningEvent.Wait(TimeSpan.FromSeconds(10))); + systemClock.UtcNow += minimumDataRateGracePeriod + TimeSpan.FromSeconds(1); + + await connection.Receive( + "HTTP/1.1 408 Request Timeout", + ""); + await connection.ReceiveForcedEnd( + "Connection: close", + $"Date: {serviceContext.DateHeaderValue}", + "Content-Length: 0", + "", + ""); + } + } + } + + [Fact] + public async Task RequestTimesWhenNotDrainedWithinDrainTimeoutPeriod() + { + // This test requires a real clock since we can't control when the drain timeout is set + var systemClock = new SystemClock(); + var serviceContext = new TestServiceContext + { + SystemClock = systemClock, + DateHeaderValueManager = new DateHeaderValueManager(systemClock) + }; + + var appRunningEvent = new ManualResetEventSlim(); + + using (var server = new TestServer(context => + { + context.Features.Get().MinimumDataRate = null; + + appRunningEvent.Set(); + return Task.CompletedTask; + }, serviceContext)) + { + using (var connection = server.CreateConnection()) + { + await connection.Send( + "POST / HTTP/1.1", + "Host:", + "Content-Length: 1", + "", + ""); + + Assert.True(appRunningEvent.Wait(TimeSpan.FromSeconds(10))); + + await connection.Receive( + "HTTP/1.1 408 Request Timeout", + "Connection: close", + ""); + await connection.ReceiveStartsWith( + "Date: "); + await connection.ReceiveForcedEnd( + "Content-Length: 0", + "", + ""); + } + } + } + + [Fact] + public async Task ConnectionClosedEvenIfAppSwallowsException() + { + var minimumDataRateGracePeriod = TimeSpan.FromSeconds(5); + var systemClock = new MockSystemClock(); + var serviceContext = new TestServiceContext + { + SystemClock = systemClock, + DateHeaderValueManager = new DateHeaderValueManager(systemClock) + }; + + var appRunningEvent = new ManualResetEventSlim(); + var exceptionSwallowedEvent = new ManualResetEventSlim(); + + using (var server = new TestServer(async context => + { + context.Features.Get().MinimumDataRate = + new MinimumDataRate(rate: 1, gracePeriod: minimumDataRateGracePeriod); + + appRunningEvent.Set(); + + try + { + await context.Request.Body.ReadAsync(new byte[1], 0, 1); + } + catch (BadHttpRequestException ex) when (ex.StatusCode == 408) + { + exceptionSwallowedEvent.Set(); + } + + var response = "hello, world"; + context.Response.ContentLength = response.Length; + await context.Response.WriteAsync("hello, world"); + }, serviceContext)) + { + using (var connection = server.CreateConnection()) + { + await connection.Send( + "POST / HTTP/1.1", + "Host:", + "Content-Length: 1", + "", + ""); + + Assert.True(appRunningEvent.Wait(TimeSpan.FromSeconds(10))); + systemClock.UtcNow += minimumDataRateGracePeriod + TimeSpan.FromSeconds(1); + Assert.True(exceptionSwallowedEvent.Wait(TimeSpan.FromSeconds(10))); + + await connection.Receive( + "HTTP/1.1 200 OK", + ""); + await connection.ReceiveForcedEnd( + $"Date: {serviceContext.DateHeaderValue}", + "Content-Length: 12", + "", + "hello, world"); + } + } + } + } +} diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestHeadersTimeoutTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestHeadersTimeoutTests.cs index a2608ef47a..a97d62f5b0 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestHeadersTimeoutTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestHeadersTimeoutTests.cs @@ -103,7 +103,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests ServerOptions = { AddServerHeader = false, - Limits = { RequestHeadersTimeout = RequestHeadersTimeout } + Limits = + { + RequestHeadersTimeout = RequestHeadersTimeout, + RequestBodyMinimumDataRate = null + } } }); } diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs index 50004ca37a..999e4f78a3 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs @@ -59,9 +59,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests Assert.True(bufferLength % 256 == 0, $"{nameof(bufferLength)} must be evenly divisible by 256"); var builder = new WebHostBuilder() - .UseKestrel(o => + .UseKestrel(options => { - o.Limits.MaxRequestBodySize = contentLength; + options.Limits.MaxRequestBodySize = contentLength; + options.Limits.RequestBodyMinimumDataRate = null; }) .UseUrls("http://127.0.0.1:0/") .Configure(app => diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Mocks/MockTimeoutControl.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Mocks/MockTimeoutControl.cs index 1f721f07d1..8bfd08387e 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Mocks/MockTimeoutControl.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Mocks/MockTimeoutControl.cs @@ -7,6 +7,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance.Mocks { public class MockTimeoutControl : ITimeoutControl { + public bool TimedOut { get; } + public void CancelTimeout() { } @@ -18,5 +20,25 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance.Mocks public void SetTimeout(long ticks, TimeoutAction timeoutAction) { } + + public void StartTimingReads() + { + } + + public void StopTimingReads() + { + } + + public void PauseTimingReads() + { + } + + public void ResumeTimingReads() + { + } + + public void BytesRead(int count) + { + } } } diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Mocks/MockTrace.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Mocks/MockTrace.cs index 30fb4f3e2f..480ec400a3 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Mocks/MockTrace.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Mocks/MockTrace.cs @@ -36,5 +36,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance public void RequestProcessingError(string connectionId, Exception ex) { } public void HeartbeatSlow(TimeSpan interval, DateTimeOffset now) { } public void ApplicationNeverCompleted(string connectionId) { } + public void RequestBodyStart(string connectionId, string traceIdentifier) { } + public void RequestBodyDone(string connectionId, string traceIdentifier) { } + public void RequestBodyMininumDataRateNotSatisfied(string connectionId, string traceIdentifier, double rate) { } } } diff --git a/test/shared/MockSystemClock.cs b/test/shared/MockSystemClock.cs index 0032f2de7c..3977653630 100644 --- a/test/shared/MockSystemClock.cs +++ b/test/shared/MockSystemClock.cs @@ -2,24 +2,25 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Threading; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; namespace Microsoft.AspNetCore.Testing { public class MockSystemClock : ISystemClock { - private DateTimeOffset _utcNow = DateTimeOffset.Now; + private long _utcNowTicks = DateTimeOffset.UtcNow.Ticks; public DateTimeOffset UtcNow { get { UtcNowCalled++; - return _utcNow; + return new DateTimeOffset(Interlocked.Read(ref _utcNowTicks), TimeSpan.Zero); } set { - _utcNow = value; + Interlocked.Exchange(ref _utcNowTicks, value.Ticks); } } diff --git a/test/shared/TestServiceContext.cs b/test/shared/TestServiceContext.cs index 5f4b572047..696178c0fa 100644 --- a/test/shared/TestServiceContext.cs +++ b/test/shared/TestServiceContext.cs @@ -29,7 +29,6 @@ namespace Microsoft.AspNetCore.Testing SystemClock = new MockSystemClock(); DateHeaderValueManager = new DateHeaderValueManager(SystemClock); ConnectionManager = new FrameConnectionManager(Log, ResourceCounter.Unlimited, ResourceCounter.Unlimited); - DateHeaderValue = DateHeaderValueManager.GetDateHeaderValues().String; HttpParserFactory = frameAdapter => new HttpParser(frameAdapter.Frame.ServiceContext.Log.IsEnabled(LogLevel.Information)); ServerOptions = new KestrelServerOptions { @@ -39,6 +38,6 @@ namespace Microsoft.AspNetCore.Testing public ILoggerFactory LoggerFactory { get; } - public string DateHeaderValue { get; } + public string DateHeaderValue => DateHeaderValueManager.GetDateHeaderValues().String; } } diff --git a/tools/CodeGenerator/FrameFeatureCollection.cs b/tools/CodeGenerator/FrameFeatureCollection.cs index d97136380d..be4b820fea 100644 --- a/tools/CodeGenerator/FrameFeatureCollection.cs +++ b/tools/CodeGenerator/FrameFeatureCollection.cs @@ -6,6 +6,7 @@ using System.Collections.Generic; using System.Linq; using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Http.Features.Authentication; +using Microsoft.AspNetCore.Server.Kestrel.Core.Features; namespace CodeGenerator { @@ -45,12 +46,13 @@ namespace CodeGenerator typeof(ITlsConnectionFeature), typeof(IHttpWebSocketFeature), typeof(ISessionFeature), - typeof(IHttpMaxRequestBodySizeFeature) + typeof(IHttpMaxRequestBodySizeFeature), + typeof(IHttpRequestBodyMinimumDataRateFeature), }; var rareFeatures = new[] { - typeof(IHttpSendFileFeature) + typeof(IHttpSendFileFeature), }; var allFeatures = alwaysFeatures.Concat(commonFeatures).Concat(sometimesFeatures).Concat(rareFeatures); @@ -65,7 +67,8 @@ namespace CodeGenerator typeof(IHttpRequestIdentifierFeature), typeof(IHttpRequestLifetimeFeature), typeof(IHttpConnectionFeature), - typeof(IHttpMaxRequestBodySizeFeature) + typeof(IHttpMaxRequestBodySizeFeature), + typeof(IHttpRequestBodyMinimumDataRateFeature), }; return $@"// Copyright (c) .NET Foundation. All rights reserved. From f67a105ff401b8576f085eb9384dc25c77752d3a Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Thu, 8 Jun 2017 15:08:49 -0700 Subject: [PATCH 1317/1662] Update defaults in KestrelServerLimits doc comments (#1891) --- .../KestrelServerLimits.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/KestrelServerLimits.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/KestrelServerLimits.cs index a1f79fc799..eb04cb9b90 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/KestrelServerLimits.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/KestrelServerLimits.cs @@ -147,7 +147,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core /// This can be overridden per-request via . /// /// - /// Defaults to null (unlimited). + /// Defaults to 30,000,000 bytes, which is approximately 28.6MB. /// public long? MaxRequestBodySize { @@ -258,7 +258,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core /// This can be overridden per-request via . /// /// - /// Defaults to null. + /// Defaults to 1 byte/second with a 5 second grace period. /// public MinimumDataRate RequestBodyMinimumDataRate { get; set; } = new MinimumDataRate(rate: 1, gracePeriod: TimeSpan.FromSeconds(5)); } From d879518a18c765a0571b4583ba85be705ca889fe Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Mon, 12 Jun 2017 11:11:40 -0700 Subject: [PATCH 1318/1662] Always complete RequestBodyPipe.Reader (#1893) * Disable test that leaks blocks in debug builds * Move some test helpers --- .../Internal/Http/FrameOfT.cs | 12 ++++++++---- .../Internal/Http/MessageBody.cs | 17 +++++------------ .../MessageBodyTests.cs | 4 ++-- .../FrameConnectionManagerTests.cs | 4 +++- .../{ => TestHelpers}/IWebHostPortExtensions.cs | 0 .../{ => TestHelpers}/TestServer.cs | 0 6 files changed, 18 insertions(+), 19 deletions(-) rename test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/{ => TestHelpers}/IWebHostPortExtensions.cs (100%) rename test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/{ => TestHelpers}/TestServer.cs (100%) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameOfT.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameOfT.cs index 8eddab20db..094cb3ca13 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameOfT.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameOfT.cs @@ -163,13 +163,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http TimeoutControl.SetTimeout(Constants.RequestBodyDrainTimeout.Ticks, TimeoutAction.SendTimeoutResponse); await messageBody.ConsumeAsync(); TimeoutControl.CancelTimeout(); - - // At this point both the request body pipe reader and writer should be completed. - RequestBodyPipe.Reset(); } else { - RequestBodyPipe.Reader.Complete(); messageBody.Cancel(); Input.CancelPendingRead(); } @@ -201,6 +197,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http // StopStreams should be called before the end of the "if (!_requestProcessingStopping)" block // to ensure InitializeStreams has been called. StopStreams(); + + if (HasStartedConsumingRequestBody) + { + RequestBodyPipe.Reader.Complete(); + + // At this point both the request body pipe reader and writer should be completed. + RequestBodyPipe.Reset(); + } } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/MessageBody.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/MessageBody.cs index f964f55001..eb987d9590 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/MessageBody.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/MessageBody.cs @@ -204,19 +204,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { TryInit(); - try + ReadResult result; + do { - ReadResult result; - do - { - result = await _context.RequestBodyPipe.Reader.ReadAsync(); - _context.RequestBodyPipe.Reader.Advance(result.Buffer.End); - } while (!result.IsCompleted); - } - finally - { - _context.RequestBodyPipe.Reader.Complete(); - } + result = await _context.RequestBodyPipe.Reader.ReadAsync(); + _context.RequestBodyPipe.Reader.Advance(result.Buffer.End); + } while (!result.IsCompleted); } protected void Copy(ReadableBuffer readableBuffer, WritableBuffer writableBuffer) diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/MessageBodyTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/MessageBodyTests.cs index 7a5f9caa7d..2c8b3b7f8b 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/MessageBodyTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/MessageBodyTests.cs @@ -349,7 +349,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests } [Fact] - public async Task ConsumeAsyncCompletesPipeReader() + public async Task ConsumeAsyncConsumesAllRemainingInput() { using (var input = new TestInput()) { @@ -359,7 +359,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests await body.ConsumeAsync(); - await Assert.ThrowsAsync(async () => await body.ReadAsync(new ArraySegment(new byte[1]))); + Assert.Equal(0, await body.ReadAsync(new ArraySegment(new byte[1]))); } } diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/FrameConnectionManagerTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/FrameConnectionManagerTests.cs index 0e71450a5e..3ecd575884 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/FrameConnectionManagerTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/FrameConnectionManagerTests.cs @@ -16,7 +16,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { public class FrameConnectionManagerTests { - +// This test causes MemoryPoolBlocks to be finalized which in turn causes an assert failure in debug builds. +#if !DEBUG [ConditionalFact] [NoDebuggerCondition] public async Task CriticalErrorLoggedIfApplicationDoesntComplete() @@ -65,6 +66,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests Assert.True(logWaitAttempts < 10); } } +#endif private class NoDebuggerConditionAttribute : Attribute, ITestCondition { diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/IWebHostPortExtensions.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/TestHelpers/IWebHostPortExtensions.cs similarity index 100% rename from test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/IWebHostPortExtensions.cs rename to test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/TestHelpers/IWebHostPortExtensions.cs diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/TestServer.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/TestHelpers/TestServer.cs similarity index 100% rename from test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/TestServer.cs rename to test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/TestHelpers/TestServer.cs From a97c08843c620171b8ca781fd1d7fe8b7af0ac4a Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Mon, 12 Jun 2017 11:12:01 -0700 Subject: [PATCH 1319/1662] Complete IPipeWriter in OutputProducer.Abort() (#1894) - This prevents MemoryPoolBlocks from leaking when writes fail --- .../Internal/Http/OutputProducer.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/OutputProducer.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/OutputProducer.cs index 560c4440cc..5f58ef6ae4 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/OutputProducer.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/OutputProducer.cs @@ -95,6 +95,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http _log.ConnectionDisconnect(_connectionId); _completed = true; _pipe.Reader.CancelPendingRead(); + _pipe.Writer.Complete(); } } From f4f6501b8d3c497c1427da2477da7656c2ea3be7 Mon Sep 17 00:00:00 2001 From: Pawel Kadluczka Date: Thu, 15 Jun 2017 15:49:47 -0700 Subject: [PATCH 1320/1662] Updating libuv dependency to 1.10.0 --- build/dependencies.props | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/dependencies.props b/build/dependencies.props index 138ac50629..b323cb0f4e 100644 --- a/build/dependencies.props +++ b/build/dependencies.props @@ -3,7 +3,7 @@ 2.0.0-* 4.4.0-* 2.1.0-* - 1.10.0-* + 1.10.0 9.0.1 4.7.1 2.0.0-* From 7afd279a6dd6c36712d74e8bfde86cbddc33a422 Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Mon, 19 Jun 2017 16:37:47 -0700 Subject: [PATCH 1321/1662] Don't pause and resume read timing on upgrade requests (#1904). --- .../Internal/Http/MessageBody.cs | 21 +++++- .../MessageBodyTests.cs | 29 +++++++++ .../RequestTests.cs | 64 +++++++++++++++++++ 3 files changed, 112 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/MessageBody.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/MessageBody.cs index f964f55001..0e07e1d0a3 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/MessageBody.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/MessageBody.cs @@ -8,6 +8,7 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; +using Microsoft.Extensions.Logging; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { @@ -92,14 +93,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { // Backpressure, stop controlling incoming data rate until data is read. backpressure = true; - _context.TimeoutControl.PauseTimingReads(); + TryPauseTimingReads(); } await writeAwaitable; if (backpressure) { - _context.TimeoutControl.ResumeTimingReads(); + TryResumeTimingReads(); } if (done) @@ -273,6 +274,22 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http } } + private void TryPauseTimingReads() + { + if (!RequestUpgrade) + { + _context.TimeoutControl.PauseTimingReads(); + } + } + + private void TryResumeTimingReads() + { + if (!RequestUpgrade) + { + _context.TimeoutControl.ResumeTimingReads(); + } + } + private void TryStopTimingReads() { if (!RequestUpgrade) diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/MessageBodyTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/MessageBodyTests.cs index b884baa874..c8dfaccfe6 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/MessageBodyTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/MessageBodyTests.cs @@ -648,6 +648,29 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests } } + [Fact] + public async Task PausesAndResumesRequestBodyTimeoutOnBackpressure() + { + using (var input = new TestInput()) + { + var mockTimeoutControl = new Mock(); + input.FrameContext.TimeoutControl = mockTimeoutControl.Object; + + var body = MessageBody.For(HttpVersion.Http11, new FrameRequestHeaders { HeaderContentLength = "12" }, input.Frame); + + // Add some input and read it to start PumpAsync + input.Add("hello,"); + Assert.Equal(6, await body.ReadAsync(new ArraySegment(new byte[6]))); + + input.Add(" world"); + Assert.Equal(6, await body.ReadAsync(new ArraySegment(new byte[6]))); + + // Due to the limits set on Frame.RequestBodyPipe, backpressure should be triggered on every write to that pipe. + mockTimeoutControl.Verify(timeoutControl => timeoutControl.PauseTimingReads(), Times.Exactly(2)); + mockTimeoutControl.Verify(timeoutControl => timeoutControl.ResumeTimingReads(), Times.Exactly(2)); + } + } + [Fact] public async Task OnlyEnforcesRequestBodyTimeoutAfterSending100Continue() { @@ -701,6 +724,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests mockTimeoutControl.Verify(timeoutControl => timeoutControl.StartTimingReads(), Times.Never); mockTimeoutControl.Verify(timeoutControl => timeoutControl.StopTimingReads(), Times.Never); + + // Due to the limits set on Frame.RequestBodyPipe, backpressure should be triggered on every + // write to that pipe. Verify that read timing pause and resume are not called on upgrade + // requests. + mockTimeoutControl.Verify(timeoutControl => timeoutControl.PauseTimingReads(), Times.Never); + mockTimeoutControl.Verify(timeoutControl => timeoutControl.ResumeTimingReads(), Times.Never); } } diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs index 999e4f78a3..da34b13bd6 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs @@ -17,7 +17,9 @@ using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Server.Kestrel.Core; +using Microsoft.AspNetCore.Server.Kestrel.Core.Features; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions; using Microsoft.AspNetCore.Testing; using Microsoft.AspNetCore.Testing.xunit; @@ -1416,6 +1418,68 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } } + [Fact] + public async Task DoesNotEnforceRequestBodyMinimumDataRateOnUpgradedRequest() + { + var appEvent = new ManualResetEventSlim(); + var delayEvent = new ManualResetEventSlim(); + var serviceContext = new TestServiceContext + { + SystemClock = new SystemClock() + }; + + using (var server = new TestServer(async context => + { + context.Features.Get().MinimumDataRate = new MinimumDataRate(rate: double.MaxValue, gracePeriod: TimeSpan.Zero); + + using (var stream = await context.Features.Get().UpgradeAsync()) + { + appEvent.Set(); + + // Read once to go through one set of TryPauseTimingReads()/TryResumeTimingReads() calls + await stream.ReadAsync(new byte[1], 0, 1); + + delayEvent.Wait(); + + // Read again to check that the connection is still alive + await stream.ReadAsync(new byte[1], 0, 1); + + // Send a response to distinguish from the timeout case where the 101 is still received, but without any content + var response = Encoding.ASCII.GetBytes("hello"); + await stream.WriteAsync(response, 0, response.Length); + } + }, serviceContext)) + { + using (var connection = server.CreateConnection()) + { + await connection.Send( + "GET / HTTP/1.1", + "Host:", + "Connection: upgrade", + "", + "a"); + + Assert.True(appEvent.Wait(TimeSpan.FromSeconds(10))); + + await Task.Delay(TimeSpan.FromSeconds(5)); + + delayEvent.Set(); + + await connection.Send("b"); + + await connection.Receive( + "HTTP/1.1 101 Switching Protocols", + "Connection: Upgrade", + ""); + await connection.ReceiveStartsWith( + $"Date: "); + await connection.ReceiveForcedEnd( + "", + "hello"); + } + } + } + private async Task TestRemoteIPAddress(string registerAddress, string requestAddress, string expectAddress) { var builder = new WebHostBuilder() From e1e7c9b81034430dcd22dad6f511d918e2057f89 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Tue, 20 Jun 2017 10:56:23 -0700 Subject: [PATCH 1322/1662] Wait until the writer is complete to reset RequestBodyPipe (#1902) --- .../Internal/Http/FrameOfT.cs | 21 +++--- .../Internal/Http/MessageBody.cs | 25 ++++++-- .../MessageBodyTests.cs | 64 ++++++++++++++++--- 3 files changed, 81 insertions(+), 29 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameOfT.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameOfT.cs index 094cb3ca13..5ecaaa0814 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameOfT.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameOfT.cs @@ -155,20 +155,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http } // ForZeroContentLength does not complete the reader nor the writer - if (!messageBody.IsEmpty) + if (!messageBody.IsEmpty && _keepAlive) { - if (_keepAlive) - { - // Finish reading the request body in case the app did not. - TimeoutControl.SetTimeout(Constants.RequestBodyDrainTimeout.Ticks, TimeoutAction.SendTimeoutResponse); - await messageBody.ConsumeAsync(); - TimeoutControl.CancelTimeout(); - } - else - { - messageBody.Cancel(); - Input.CancelPendingRead(); - } + // Finish reading the request body in case the app did not. + TimeoutControl.SetTimeout(Constants.RequestBodyDrainTimeout.Ticks, TimeoutAction.SendTimeoutResponse); + await messageBody.ConsumeAsync(); + TimeoutControl.CancelTimeout(); } if (!HasResponseStarted) @@ -202,6 +194,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { RequestBodyPipe.Reader.Complete(); + // Wait for MessageBody.PumpAsync() to call RequestBodyPipe.Writer.Complete(). + await messageBody.StopAsync(); + // At this point both the request body pipe reader and writer should be completed. RequestBodyPipe.Reset(); } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/MessageBody.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/MessageBody.cs index 2bc4ff6e5a..407dc15ec3 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/MessageBody.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/MessageBody.cs @@ -21,6 +21,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http private bool _send100Continue = true; private volatile bool _canceled; + private Task _pumpTask; protected MessageBody(Frame context) { @@ -132,11 +133,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http } } - public void Cancel() - { - _canceled = true; - } - public virtual async Task ReadAsync(ArraySegment buffer, CancellationToken cancellationToken = default(CancellationToken)) { TryInit(); @@ -213,6 +209,18 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http } while (!result.IsCompleted); } + public virtual Task StopAsync() + { + if (!_context.HasStartedConsumingRequestBody) + { + return Task.CompletedTask; + } + + _canceled = true; + _context.Input.CancelPendingRead(); + return _pumpTask; + } + protected void Copy(ReadableBuffer readableBuffer, WritableBuffer writableBuffer) { _context.TimeoutControl.BytesRead(readableBuffer.Length); @@ -245,7 +253,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { OnReadStart(); _context.HasStartedConsumingRequestBody = true; - _ = PumpAsync(); + _pumpTask = PumpAsync(); } } @@ -411,6 +419,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { return Task.CompletedTask; } + + public override Task StopAsync() + { + return Task.CompletedTask; + } } private class ForContentLength : MessageBody diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/MessageBodyTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/MessageBodyTests.cs index 3b1cf10a92..655582dcf1 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/MessageBodyTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/MessageBodyTests.cs @@ -23,7 +23,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests [Theory] [InlineData(HttpVersion.Http10)] [InlineData(HttpVersion.Http11)] - public void CanReadFromContentLength(HttpVersion httpVersion) + public async Task CanReadFromContentLength(HttpVersion httpVersion) { using (var input = new TestInput()) { @@ -41,6 +41,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests count = stream.Read(buffer, 0, buffer.Length); Assert.Equal(0, count); + + await body.StopAsync(); } } @@ -65,11 +67,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests count = await stream.ReadAsync(buffer, 0, buffer.Length); Assert.Equal(0, count); + + await body.StopAsync(); } } [Fact] - public void CanReadFromChunkedEncoding() + public async Task CanReadFromChunkedEncoding() { using (var input = new TestInput()) { @@ -89,6 +93,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests count = stream.Read(buffer, 0, buffer.Length); Assert.Equal(0, count); + + await body.StopAsync(); } } @@ -113,6 +119,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests count = await stream.ReadAsync(buffer, 0, buffer.Length); Assert.Equal(0, count); + + await body.StopAsync(); } } @@ -136,6 +144,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests Assert.Equal(5, await readTask.TimeoutAfter(TimeSpan.FromSeconds(10))); Assert.Equal(0, await stream.ReadAsync(buffer, 0, buffer.Length)); + + await body.StopAsync(); } } @@ -155,6 +165,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests await stream.ReadAsync(buffer, 0, buffer.Length)); Assert.IsType(ex.InnerException); Assert.Equal(CoreStrings.BadRequest_BadChunkSizeData, ex.Message); + + await body.StopAsync(); } } @@ -174,13 +186,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests await stream.ReadAsync(buffer, 0, buffer.Length)); Assert.Equal(CoreStrings.BadRequest_BadChunkSizeData, ex.Message); + + await body.StopAsync(); } } [Theory] [InlineData(HttpVersion.Http10)] [InlineData(HttpVersion.Http11)] - public void CanReadFromRemainingData(HttpVersion httpVersion) + public async Task CanReadFromRemainingData(HttpVersion httpVersion) { using (var input = new TestInput()) { @@ -197,6 +211,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests AssertASCII("Hello", new ArraySegment(buffer, 0, count)); input.Fin(); + + await body.StopAsync(); } } @@ -220,13 +236,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests AssertASCII("Hello", new ArraySegment(buffer, 0, count)); input.Fin(); + + await body.StopAsync(); } } [Theory] [InlineData(HttpVersion.Http10)] [InlineData(HttpVersion.Http11)] - public void ReadFromNoContentLengthReturnsZero(HttpVersion httpVersion) + public async Task ReadFromNoContentLengthReturnsZero(HttpVersion httpVersion) { using (var input = new TestInput()) { @@ -238,6 +256,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests var buffer = new byte[1024]; Assert.Equal(0, stream.Read(buffer, 0, buffer.Length)); + + await body.StopAsync(); } } @@ -256,6 +276,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests var buffer = new byte[1024]; Assert.Equal(0, await stream.ReadAsync(buffer, 0, buffer.Length)); + + await body.StopAsync(); } } @@ -282,6 +304,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests var requestArray = ms.ToArray(); Assert.Equal(8197, requestArray.Length); AssertASCII(largeInput + "Hello", new ArraySegment(requestArray, 0, requestArray.Length)); + + await body.StopAsync(); } } @@ -345,6 +369,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests } Assert.Equal(0, await body.ReadAsync(new ArraySegment(new byte[1]))); + + await body.StopAsync(); } } @@ -360,6 +386,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests await body.ConsumeAsync(); Assert.Equal(0, await body.ReadAsync(new ArraySegment(new byte[1]))); + + await body.StopAsync(); } } @@ -436,6 +464,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests await copyToAsyncTask; Assert.Equal(2, writeCount); + + await body.StopAsync(); } } @@ -444,7 +474,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests [InlineData("Keep-Alive, Upgrade")] [InlineData("upgrade, keep-alive")] [InlineData("Upgrade, Keep-Alive")] - public void ConnectionUpgradeKeepAlive(string headerConnection) + public async Task ConnectionUpgradeKeepAlive(string headerConnection) { using (var input = new TestInput()) { @@ -459,6 +489,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests AssertASCII("Hello", new ArraySegment(buffer, 0, 5)); input.Fin(); + + await body.StopAsync(); } } @@ -481,11 +513,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests input.Add("b"); Assert.Equal(1, await stream.ReadAsync(new byte[1], 0, 1)); + await body.StopAsync(); } } [Fact] - public async Task PumpAsyncReturnsAfterCanceling() + public async Task StopAsyncPreventsFurtherDataConsumption() { using (var input = new TestInput()) { @@ -497,15 +530,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests input.Add("a"); Assert.Equal(1, await stream.ReadAsync(new byte[1], 0, 1)); - body.Cancel(); + await body.StopAsync(); // Add some more data. Checking for cancelation and exiting the loop // should take priority over reading this data. input.Add("b"); - // Unblock the loop - input.Pipe.Reader.CancelPendingRead(); - // There shouldn't be any additional data available Assert.Equal(0, await stream.ReadAsync(new byte[1], 0, 1)); } @@ -535,6 +565,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests var exception = await Assert.ThrowsAsync(() => body.ReadAsync(new ArraySegment(new byte[1]))); Assert.Equal(StatusCodes.Status408RequestTimeout, exception.StatusCode); + + await body.StopAsync(); } } @@ -562,6 +594,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests var exception = await Assert.ThrowsAsync(() => body.ConsumeAsync()); Assert.Equal(StatusCodes.Status408RequestTimeout, exception.StatusCode); + + await body.StopAsync(); } } @@ -592,6 +626,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests var exception = await Assert.ThrowsAsync(() => body.CopyToAsync(ms)); Assert.Equal(StatusCodes.Status408RequestTimeout, exception.StatusCode); } + + await body.StopAsync(); } } @@ -616,6 +652,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests mockLogger.Verify(logger => logger.RequestBodyStart("ConnectionId", "RequestId")); input.Fin(); + + await body.StopAsync(); } } @@ -644,6 +682,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests input.Fin(); Assert.True(logEvent.Wait(TimeSpan.FromSeconds(10))); + + await body.StopAsync(); } } @@ -700,6 +740,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests input.Add("a"); await readTask; + + await body.StopAsync(); } } @@ -729,6 +771,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests // requests. mockTimeoutControl.Verify(timeoutControl => timeoutControl.PauseTimingReads(), Times.Never); mockTimeoutControl.Verify(timeoutControl => timeoutControl.ResumeTimingReads(), Times.Never); + + await body.StopAsync(); } } From ea2f1033d389dc9cd89b7c3b4b28f920ec121ed9 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Wed, 21 Jun 2017 14:58:57 -0700 Subject: [PATCH 1323/1662] Make Transport.Abstractions pubternal (#1911) * Remove Sockets transport dependency from primary package * Use deprecated travis images to keep systemd tests running https://blog.travis-ci.com/2017-06-21-trusty-updates-2017-Q2-launch --- .travis.yml | 1 + samples/SampleApp/Startup.cs | 2 +- .../Internal/AddressBinder.cs | 2 +- .../Internal/ConnectionHandler.cs | 2 +- .../Internal/FrameConnection.cs | 2 +- .../Internal/FrameConnectionContext.cs | 2 +- .../Internal/Http/Frame.cs | 2 +- .../Internal/Http/FrameContext.cs | 2 +- .../Internal/Http/FrameOfT.cs | 2 +- .../Internal/Http/FrameRequestStream.cs | 2 +- .../Infrastructure/FrameConnectionManagerShutdownExtensions.cs | 2 +- .../Internal/Infrastructure/KestrelEventSource.cs | 2 +- .../Internal/RejectionConnection.cs | 2 +- src/Microsoft.AspNetCore.Server.Kestrel.Core/KestrelServer.cs | 2 +- .../KestrelServerOptions.cs | 2 +- src/Microsoft.AspNetCore.Server.Kestrel.Core/ListenOptions.cs | 2 +- .../Exceptions/AddressInUseException.cs | 2 +- .../Exceptions/ConnectionAbortedException.cs | 2 +- .../Exceptions/ConnectionResetException.cs | 2 +- .../{ => Internal}/IConnectionContext.cs | 2 +- .../{ => Internal}/IConnectionHandler.cs | 2 +- .../{ => Internal}/IConnectionInformation.cs | 2 +- .../{ => Internal}/IEndPointInformation.cs | 2 +- .../{ => Internal}/ITransport.cs | 2 +- .../{ => Internal}/ITransportFactory.cs | 2 +- .../{ => Internal}/ListenType.cs | 2 +- .../{ => Internal}/SchedulingMode.cs | 2 +- .../Internal/LibuvConnection.cs | 2 +- .../Internal/LibuvConnectionContext.cs | 2 +- .../Internal/LibuvOutputConsumer.cs | 2 +- .../Internal/LibuvTransportContext.cs | 2 +- .../Internal/Listener.cs | 2 +- .../Internal/ListenerContext.cs | 2 +- .../Internal/ListenerPrimary.cs | 2 +- .../Internal/ListenerSecondary.cs | 2 +- .../LibuvTransport.cs | 2 +- .../LibuvTransportFactory.cs | 2 +- .../WebHostBuilderLibuvExtensions.cs | 2 +- .../SocketConnection.cs | 2 +- .../SocketTransport.cs | 2 +- .../SocketTransportFactory.cs | 2 +- .../WebHostBuilderSocketExtensions.cs | 2 +- .../Microsoft.AspNetCore.Server.Kestrel.csproj | 1 - .../AddressBinderTests.cs | 2 +- .../FrameResponseHeadersTests.cs | 2 +- .../KestrelServerTests.cs | 2 +- .../RequestTests.cs | 2 +- .../TestHelpers/TestServer.cs | 2 +- .../Mocks/MockConnectionInformation.cs | 2 +- .../ListenerPrimaryTests.cs | 2 +- .../TestHelpers/MockConnectionHandler.cs | 2 +- test/shared/MockConnectionInformation.cs | 2 +- 52 files changed, 51 insertions(+), 51 deletions(-) rename src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/{ => Internal}/IConnectionContext.cs (98%) rename src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/{ => Internal}/IConnectionHandler.cs (96%) rename src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/{ => Internal}/IConnectionInformation.cs (97%) rename src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/{ => Internal}/IEndPointInformation.cs (99%) rename src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/{ => Internal}/ITransport.cs (96%) rename src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/{ => Internal}/ITransportFactory.cs (96%) rename src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/{ => Internal}/ListenType.cs (96%) rename src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/{ => Internal}/SchedulingMode.cs (95%) diff --git a/.travis.yml b/.travis.yml index 70902067d3..d8dfd45204 100644 --- a/.travis.yml +++ b/.travis.yml @@ -29,3 +29,4 @@ before_install: script: - ./build.sh - if test "$TRAVIS_OS_NAME" != "osx"; then bash test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/SystemdActivation/docker.sh; fi +group: deprecated-2017Q2 diff --git a/samples/SampleApp/Startup.cs b/samples/SampleApp/Startup.cs index 2bfe60835a..53968834de 100644 --- a/samples/SampleApp/Startup.cs +++ b/samples/SampleApp/Startup.cs @@ -8,7 +8,7 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; using Microsoft.Extensions.Logging; namespace SampleApp diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/AddressBinder.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/AddressBinder.cs index b8a34d69f5..43f0c82abf 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/AddressBinder.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/AddressBinder.cs @@ -10,7 +10,7 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting.Server.Features; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; -using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; using Microsoft.Extensions.Logging; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/ConnectionHandler.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/ConnectionHandler.cs index bee5dec4e1..aee910fd25 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/ConnectionHandler.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/ConnectionHandler.cs @@ -6,7 +6,7 @@ using Microsoft.AspNetCore.Hosting.Server; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; -using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnection.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnection.cs index 9b222a755b..7ae2f4c36a 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnection.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnection.cs @@ -13,7 +13,7 @@ using Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; -using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; using Microsoft.Extensions.Logging; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnectionContext.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnectionContext.cs index 98faa9b237..165daf2ad5 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnectionContext.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnectionContext.cs @@ -5,7 +5,7 @@ using System.Collections.Generic; using Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; -using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.cs index a607dd404b..f81b13078e 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.cs @@ -18,7 +18,7 @@ using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Internal.System; using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; using Microsoft.AspNetCore.Server.Kestrel.Internal.System.Text.Encodings.Web.Utf8; -using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Primitives; diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameContext.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameContext.cs index 12d6c22e95..2916f8c863 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameContext.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameContext.cs @@ -3,7 +3,7 @@ using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; -using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameOfT.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameOfT.cs index 5ecaaa0814..9e83e5351b 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameOfT.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameOfT.cs @@ -7,7 +7,7 @@ using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Hosting.Server; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; -using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; using Microsoft.Extensions.Logging; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameRequestStream.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameRequestStream.cs index 65665d543b..6ae4b1c385 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameRequestStream.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameRequestStream.cs @@ -6,7 +6,7 @@ using System.IO; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; -using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/FrameConnectionManagerShutdownExtensions.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/FrameConnectionManagerShutdownExtensions.cs index 9f43f2e2ad..3adaa4ae84 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/FrameConnectionManagerShutdownExtensions.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/FrameConnectionManagerShutdownExtensions.cs @@ -4,7 +4,7 @@ using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; -using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/KestrelEventSource.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/KestrelEventSource.cs index 04ead7ab1e..628de18f67 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/KestrelEventSource.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/KestrelEventSource.cs @@ -4,7 +4,7 @@ using System.Diagnostics.Tracing; using System.Runtime.CompilerServices; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; -using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/RejectionConnection.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/RejectionConnection.cs index 0cd9799db7..cd081b00e7 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/RejectionConnection.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/RejectionConnection.cs @@ -4,7 +4,7 @@ using System; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; -using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/KestrelServer.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/KestrelServer.cs index 8781882b06..9fad21da80 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/KestrelServer.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/KestrelServer.cs @@ -11,7 +11,7 @@ using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; -using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/KestrelServerOptions.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/KestrelServerOptions.cs index f4752bda71..b97eecf850 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/KestrelServerOptions.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/KestrelServerOptions.cs @@ -4,7 +4,7 @@ using System; using System.Collections.Generic; using System.Net; -using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; namespace Microsoft.AspNetCore.Server.Kestrel.Core { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/ListenOptions.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/ListenOptions.cs index 2e009f542b..5508b46afe 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/ListenOptions.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/ListenOptions.cs @@ -6,7 +6,7 @@ using System.Collections.Generic; using System.Linq; using System.Net; using Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal; -using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; namespace Microsoft.AspNetCore.Server.Kestrel.Core { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/Exceptions/AddressInUseException.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/Exceptions/AddressInUseException.cs index 8144c4a9a3..72e1a5d774 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/Exceptions/AddressInUseException.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/Exceptions/AddressInUseException.cs @@ -3,7 +3,7 @@ using System; -namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions +namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal { public class AddressInUseException : InvalidOperationException { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/Exceptions/ConnectionAbortedException.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/Exceptions/ConnectionAbortedException.cs index 0975038e3d..817d9f9226 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/Exceptions/ConnectionAbortedException.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/Exceptions/ConnectionAbortedException.cs @@ -1,6 +1,6 @@ using System; -namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions +namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal { public class ConnectionAbortedException : OperationCanceledException { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/Exceptions/ConnectionResetException.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/Exceptions/ConnectionResetException.cs index 32626d97ef..1e0bef192d 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/Exceptions/ConnectionResetException.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/Exceptions/ConnectionResetException.cs @@ -4,7 +4,7 @@ using System; using System.IO; -namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions +namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal { public class ConnectionResetException : IOException { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/IConnectionContext.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/Internal/IConnectionContext.cs similarity index 98% rename from src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/IConnectionContext.cs rename to src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/Internal/IConnectionContext.cs index d05110b930..3ac42175ba 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/IConnectionContext.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/Internal/IConnectionContext.cs @@ -5,7 +5,7 @@ using System; using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; -namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions +namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal { public interface IConnectionContext { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/IConnectionHandler.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/Internal/IConnectionHandler.cs similarity index 96% rename from src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/IConnectionHandler.cs rename to src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/Internal/IConnectionHandler.cs index 81143f611f..f3bf1c6ef3 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/IConnectionHandler.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/Internal/IConnectionHandler.cs @@ -1,7 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions +namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal { public interface IConnectionHandler { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/IConnectionInformation.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/Internal/IConnectionInformation.cs similarity index 97% rename from src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/IConnectionInformation.cs rename to src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/Internal/IConnectionInformation.cs index 54e9135b59..fb5d7a4d5c 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/IConnectionInformation.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/Internal/IConnectionInformation.cs @@ -4,7 +4,7 @@ using System.Net; using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; -namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions +namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal { public interface IConnectionInformation { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/IEndPointInformation.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/Internal/IEndPointInformation.cs similarity index 99% rename from src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/IEndPointInformation.cs rename to src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/Internal/IEndPointInformation.cs index 9fff985300..7f025ffe23 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/IEndPointInformation.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/Internal/IEndPointInformation.cs @@ -3,7 +3,7 @@ using System.Net; -namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions +namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal { public interface IEndPointInformation { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/ITransport.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/Internal/ITransport.cs similarity index 96% rename from src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/ITransport.cs rename to src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/Internal/ITransport.cs index 704101726c..5a6dc0c20c 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/ITransport.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/Internal/ITransport.cs @@ -3,7 +3,7 @@ using System.Threading.Tasks; -namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions +namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal { public interface ITransport { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/ITransportFactory.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/Internal/ITransportFactory.cs similarity index 96% rename from src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/ITransportFactory.cs rename to src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/Internal/ITransportFactory.cs index 44608be30f..326b6c1cfc 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/ITransportFactory.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/Internal/ITransportFactory.cs @@ -1,7 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions +namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal { public interface ITransportFactory { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/ListenType.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/Internal/ListenType.cs similarity index 96% rename from src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/ListenType.cs rename to src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/Internal/ListenType.cs index 3842d15545..3616f1967e 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/ListenType.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/Internal/ListenType.cs @@ -1,7 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions +namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal { /// /// Enumerates the types. diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/SchedulingMode.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/Internal/SchedulingMode.cs similarity index 95% rename from src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/SchedulingMode.cs rename to src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/Internal/SchedulingMode.cs index 5408bc1d11..881006087c 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/SchedulingMode.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/Internal/SchedulingMode.cs @@ -1,7 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions +namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal { public enum SchedulingMode { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvConnection.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvConnection.cs index 96c147725b..2052ac45f2 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvConnection.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvConnection.cs @@ -7,7 +7,7 @@ using System.IO; using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Internal.System.Buffers; using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; -using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking; using Microsoft.Extensions.Logging; diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvConnectionContext.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvConnectionContext.cs index 0cec24835e..f377aa6bc3 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvConnectionContext.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvConnectionContext.cs @@ -4,7 +4,7 @@ using System; using System.Net; using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; -using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvOutputConsumer.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvOutputConsumer.cs index 97cfbd79cd..c49b5bde5b 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvOutputConsumer.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvOutputConsumer.cs @@ -4,7 +4,7 @@ using System; using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; -using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking; namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvTransportContext.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvTransportContext.cs index 78f21248c2..9256c85048 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvTransportContext.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvTransportContext.cs @@ -2,7 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using Microsoft.AspNetCore.Hosting; -using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Listener.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Listener.cs index e5b0a267fa..a4b6a8d6bb 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Listener.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Listener.cs @@ -3,7 +3,7 @@ using System; using System.Threading.Tasks; -using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking; using Microsoft.Extensions.Logging; diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/ListenerContext.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/ListenerContext.cs index b3b30328b5..217bac0d12 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/ListenerContext.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/ListenerContext.cs @@ -2,7 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking; namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/ListenerPrimary.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/ListenerPrimary.cs index d154d31d85..1218136148 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/ListenerPrimary.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/ListenerPrimary.cs @@ -6,7 +6,7 @@ using System.Collections.Generic; using System.IO; using System.Runtime.InteropServices; using System.Threading.Tasks; -using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking; using Microsoft.Extensions.Logging; diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/ListenerSecondary.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/ListenerSecondary.cs index 2571f6bb67..83a4c5f76c 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/ListenerSecondary.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/ListenerSecondary.cs @@ -5,7 +5,7 @@ using System; using System.Runtime.InteropServices; using System.Threading; using System.Threading.Tasks; -using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking; using Microsoft.Extensions.Logging; diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/LibuvTransport.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/LibuvTransport.cs index 502c8bddfc..5948bdc583 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/LibuvTransport.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/LibuvTransport.cs @@ -6,7 +6,7 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Hosting; -using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal; using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking; using Microsoft.Extensions.Logging; diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/LibuvTransportFactory.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/LibuvTransportFactory.cs index 0a2d909580..a698388bea 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/LibuvTransportFactory.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/LibuvTransportFactory.cs @@ -3,7 +3,7 @@ using System; using Microsoft.AspNetCore.Hosting; -using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/WebHostBuilderLibuvExtensions.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/WebHostBuilderLibuvExtensions.cs index 3078d7d533..3d7f2fe3ae 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/WebHostBuilderLibuvExtensions.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/WebHostBuilderLibuvExtensions.cs @@ -2,7 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv; using Microsoft.Extensions.DependencyInjection; diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets/SocketConnection.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets/SocketConnection.cs index ff0a0c2202..2f5dfe96b7 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets/SocketConnection.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets/SocketConnection.cs @@ -10,7 +10,7 @@ using System.Net.Sockets; using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Internal.System.Buffers; using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; -using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets/SocketTransport.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets/SocketTransport.cs index c55fbd550a..aed59a4def 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets/SocketTransport.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets/SocketTransport.cs @@ -6,7 +6,7 @@ using System.Diagnostics; using System.Net; using System.Net.Sockets; using System.Threading.Tasks; -using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets/SocketTransportFactory.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets/SocketTransportFactory.cs index 3746f5d206..b33ac050a3 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets/SocketTransportFactory.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets/SocketTransportFactory.cs @@ -3,7 +3,7 @@ using System; using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; -using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; using Microsoft.Extensions.Options; namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets/WebHostBuilderSocketExtensions.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets/WebHostBuilderSocketExtensions.cs index c8c7c83ff5..95d27e46db 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets/WebHostBuilderSocketExtensions.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets/WebHostBuilderSocketExtensions.cs @@ -2,7 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; using Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets; using Microsoft.Extensions.DependencyInjection; diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Microsoft.AspNetCore.Server.Kestrel.csproj b/src/Microsoft.AspNetCore.Server.Kestrel/Microsoft.AspNetCore.Server.Kestrel.csproj index 616830814d..eab9f18969 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Microsoft.AspNetCore.Server.Kestrel.csproj +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Microsoft.AspNetCore.Server.Kestrel.csproj @@ -18,7 +18,6 @@ - diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/AddressBinderTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/AddressBinderTests.cs index 655bbaea25..27c6d8c082 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/AddressBinderTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/AddressBinderTests.cs @@ -7,7 +7,7 @@ using System.IO; using System.Net; using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal; -using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; using Microsoft.AspNetCore.Testing; using Microsoft.Extensions.Logging.Abstractions; using Xunit; diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameResponseHeadersTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameResponseHeadersTests.cs index fabae69f65..d15fd32099 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameResponseHeadersTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameResponseHeadersTests.cs @@ -8,7 +8,7 @@ using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; -using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; using Microsoft.AspNetCore.Testing; using Microsoft.Extensions.Primitives; using Moq; diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/KestrelServerTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/KestrelServerTests.cs index 655dfdedee..a9f7a39561 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/KestrelServerTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/KestrelServerTests.cs @@ -10,7 +10,7 @@ using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting.Server; using Microsoft.AspNetCore.Hosting.Server.Features; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; -using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; using Microsoft.AspNetCore.Testing; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs index 650095e84c..0ab934384d 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs @@ -20,7 +20,7 @@ using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.AspNetCore.Server.Kestrel.Core.Features; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; -using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; using Microsoft.AspNetCore.Testing; using Microsoft.AspNetCore.Testing.xunit; using Microsoft.Extensions.Logging; diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/TestHelpers/TestServer.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/TestHelpers/TestServer.cs index ee2deb0b5e..6e85ab30fa 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/TestHelpers/TestServer.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/TestHelpers/TestServer.cs @@ -11,7 +11,7 @@ using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting.Server; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Server.Kestrel.Core; -using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; using Microsoft.AspNetCore.Testing; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Mocks/MockConnectionInformation.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Mocks/MockConnectionInformation.cs index e02bd98be2..fb34c33f51 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Mocks/MockConnectionInformation.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Mocks/MockConnectionInformation.cs @@ -4,7 +4,7 @@ using System; using System.Net; using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; -using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; namespace Microsoft.AspNetCore.Server.Kestrel.Performance { diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/ListenerPrimaryTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/ListenerPrimaryTests.cs index 0edcfd37f5..3d4eea1642 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/ListenerPrimaryTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/ListenerPrimaryTests.cs @@ -9,7 +9,7 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal; -using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal; using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking; using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests.TestHelpers; diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/TestHelpers/MockConnectionHandler.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/TestHelpers/MockConnectionHandler.cs index 6e8c8b312e..c8b965ef30 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/TestHelpers/MockConnectionHandler.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/TestHelpers/MockConnectionHandler.cs @@ -4,7 +4,7 @@ using System; using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; -using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; using Xunit; namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests.TestHelpers diff --git a/test/shared/MockConnectionInformation.cs b/test/shared/MockConnectionInformation.cs index 1a68548100..742bcd2aa2 100644 --- a/test/shared/MockConnectionInformation.cs +++ b/test/shared/MockConnectionInformation.cs @@ -3,7 +3,7 @@ using System.Net; using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; -using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; namespace Microsoft.AspNetCore.Testing { From c83f606b220714fa7b1b6a6a91b16d78cee6005f Mon Sep 17 00:00:00 2001 From: Pavel Krymets Date: Thu, 22 Jun 2017 10:04:02 -0700 Subject: [PATCH 1324/1662] Add a StressTest target (#1914) --- build/repo.targets | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/build/repo.targets b/build/repo.targets index d05edf3572..85c8e8c896 100644 --- a/build/repo.targets +++ b/build/repo.targets @@ -2,4 +2,10 @@ + + + + + + From 3084227314c784e34c6ca19402346bc0eafce2ea Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Fri, 23 Jun 2017 16:47:50 -0700 Subject: [PATCH 1325/1662] React to Testing#280. --- KestrelHttpServer.sln | 6 +- .../HttpClientSlimTests.cs | 109 --------------- .../TestHelpers/IWebHostPortExtensions.cs | 35 ----- test/shared/HttpClientSlim.cs | 130 ------------------ 4 files changed, 4 insertions(+), 276 deletions(-) delete mode 100644 test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/HttpClientSlimTests.cs delete mode 100644 test/shared/HttpClientSlim.cs diff --git a/KestrelHttpServer.sln b/KestrelHttpServer.sln index c1ba2b1753..56420c09fa 100644 --- a/KestrelHttpServer.sln +++ b/KestrelHttpServer.sln @@ -1,6 +1,6 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 15 -VisualStudioVersion = 15.0.26510.0 +VisualStudioVersion = 15.0.26621.2 MinimumVisualStudioVersion = 10.0.40219.1 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{7972A5D6-3385-4127-9277-428506DD44FF}" ProjectSection(SolutionItems) = preProject @@ -20,7 +20,6 @@ EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "shared", "shared", "{0EF2ACDF-012F-4472-A13A-4272419E2903}" ProjectSection(SolutionItems) = preProject test\shared\DummyApplication.cs = test\shared\DummyApplication.cs - test\shared\HttpClientSlim.cs = test\shared\HttpClientSlim.cs test\shared\HttpParsingData.cs = test\shared\HttpParsingData.cs test\shared\KestrelTestLoggerProvider.cs = test\shared\KestrelTestLoggerProvider.cs test\shared\LifetimeNotImplemented.cs = test\shared\LifetimeNotImplemented.cs @@ -270,4 +269,7 @@ Global {D95A7EC3-48AC-4D03-B2E2-0DA3E13BD3A4} = {D3273454-EA07-41D2-BF0B-FCC3675C2483} {4F1C30F8-CCAA-48D7-9DF6-2A84021F5BCC} = {D3273454-EA07-41D2-BF0B-FCC3675C2483} EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {2D10D020-6770-47CA-BB8D-2C23FE3AE071} + EndGlobalSection EndGlobal diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/HttpClientSlimTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/HttpClientSlimTests.cs deleted file mode 100644 index 7410d7d656..0000000000 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/HttpClientSlimTests.cs +++ /dev/null @@ -1,109 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using System.Net; -using System.Net.Http; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Builder; -using Microsoft.AspNetCore.Hosting; -using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Testing; -using Xunit; - -namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests -{ - public class HttpClientSlimTests - { - [Fact] - public async Task GetStringAsyncHttp() - { - using (var host = StartHost()) - { - Assert.Equal("test", await HttpClientSlim.GetStringAsync(host.GetUri())); - } - } - - [Fact] - public async Task GetStringAsyncHttps() - { - using (var host = StartHost(protocol: "https")) - { - Assert.Equal("test", await HttpClientSlim.GetStringAsync(host.GetUri(isHttps: true), validateCertificate: false)); - } - } - - [Fact] - public async Task GetStringAsyncThrowsForErrorResponse() - { - using (var host = StartHost(statusCode: StatusCodes.Status500InternalServerError)) - { - await Assert.ThrowsAnyAsync(() => HttpClientSlim.GetStringAsync(host.GetUri())); - } - } - - [Fact] - public async Task PostAsyncHttp() - { - using (var host = StartHost(handler: (context) => context.Request.Body.CopyToAsync(context.Response.Body))) - { - Assert.Equal("test post", await HttpClientSlim.PostAsync(host.GetUri(), new StringContent("test post"))); - } - } - - [Fact] - public async Task PostAsyncHttps() - { - using (var host = StartHost(protocol: "https", - handler: (context) => context.Request.Body.CopyToAsync(context.Response.Body))) - { - Assert.Equal("test post", await HttpClientSlim.PostAsync(host.GetUri(isHttps: true), - new StringContent("test post"), validateCertificate: false)); - } - } - - [Fact] - public async Task PostAsyncThrowsForErrorResponse() - { - using (var host = StartHost(statusCode: StatusCodes.Status500InternalServerError)) - { - await Assert.ThrowsAnyAsync( - () => HttpClientSlim.PostAsync(host.GetUri(), new StringContent(""))); - } - } - - private IWebHost StartHost(string protocol = "http", int statusCode = StatusCodes.Status200OK, Func handler = null) - { - var host = new WebHostBuilder() - .UseKestrel(options => - { - options.Listen(new IPEndPoint(IPAddress.Loopback, 0), listenOptions => - { - if (protocol == "https") - { - listenOptions.UseHttps(TestResources.TestCertificatePath, "testPassword"); - } - }); - }) - .Configure((app) => - { - app.Run(context => - { - context.Response.StatusCode = statusCode; - if (handler == null) - { - return context.Response.WriteAsync("test"); - } - else - { - return handler(context); - } - }); - }) - .Build(); - - host.Start(); - return host; - } - } -} diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/TestHelpers/IWebHostPortExtensions.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/TestHelpers/IWebHostPortExtensions.cs index 11e8f4fa0f..2f3ae47c24 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/TestHelpers/IWebHostPortExtensions.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/TestHelpers/IWebHostPortExtensions.cs @@ -10,24 +10,11 @@ namespace Microsoft.AspNetCore.Hosting { public static class IWebHostPortExtensions { - public static string GetHost(this IWebHost host, bool isHttps = false) - { - return host.GetUri(isHttps).Host; - } - public static int GetPort(this IWebHost host) { return host.GetPorts().First(); } - public static int GetPort(this IWebHost host, string scheme) - { - return host.GetUris() - .Where(u => u.Scheme.Equals(scheme, StringComparison.OrdinalIgnoreCase)) - .Select(u => u.Port) - .First(); - } - public static IEnumerable GetPorts(this IWebHost host) { return host.GetUris() @@ -39,27 +26,5 @@ namespace Microsoft.AspNetCore.Hosting return host.ServerFeatures.Get().Addresses .Select(a => new Uri(a)); } - - public static Uri GetUri(this IWebHost host, bool isHttps = false) - { - var uri = host.GetUris().First(); - - if (isHttps && uri.Scheme == "http") - { - var uriBuilder = new UriBuilder(uri) - { - Scheme = "https", - }; - - if (uri.Port == 80) - { - uriBuilder.Port = 443; - } - - return uriBuilder.Uri; - } - - return uri; - } } } diff --git a/test/shared/HttpClientSlim.cs b/test/shared/HttpClientSlim.cs deleted file mode 100644 index a85b03aa40..0000000000 --- a/test/shared/HttpClientSlim.cs +++ /dev/null @@ -1,130 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using System.IO; -using System.Net; -using System.Net.Http; -using System.Net.Security; -using System.Net.Sockets; -using System.Security.Authentication; -using System.Text; -using System.Threading.Tasks; - -namespace Microsoft.AspNetCore.Testing -{ - // Lightweight version of HttpClient implemented using Socket and SslStream - public static class HttpClientSlim - { - public static async Task GetStringAsync(string requestUri, bool validateCertificate = true) - => await GetStringAsync(new Uri(requestUri), validateCertificate).ConfigureAwait(false); - - public static async Task GetStringAsync(Uri requestUri, bool validateCertificate = true) - { - using (var stream = await GetStream(requestUri, validateCertificate).ConfigureAwait(false)) - { - using (var writer = new StreamWriter(stream, Encoding.ASCII, bufferSize: 1024, leaveOpen: true)) - { - await writer.WriteAsync($"GET {requestUri.PathAndQuery} HTTP/1.0\r\n").ConfigureAwait(false); - await writer.WriteAsync($"Host: {requestUri.Authority}\r\n").ConfigureAwait(false); - await writer.WriteAsync("\r\n").ConfigureAwait(false); - } - - return await ReadResponse(stream).ConfigureAwait(false); - } - } - - public static async Task PostAsync(string requestUri, HttpContent content, bool validateCertificate = true) - => await PostAsync(new Uri(requestUri), content, validateCertificate).ConfigureAwait(false); - - public static async Task PostAsync(Uri requestUri, HttpContent content, bool validateCertificate = true) - { - using (var stream = await GetStream(requestUri, validateCertificate)) - { - using (var writer = new StreamWriter(stream, Encoding.ASCII, bufferSize: 1024, leaveOpen: true)) - { - await writer.WriteAsync($"POST {requestUri.PathAndQuery} HTTP/1.0\r\n").ConfigureAwait(false); - await writer.WriteAsync($"Host: {requestUri.Authority}\r\n").ConfigureAwait(false); - await writer.WriteAsync($"Content-Type: {content.Headers.ContentType}\r\n").ConfigureAwait(false); - await writer.WriteAsync($"Content-Length: {content.Headers.ContentLength}\r\n").ConfigureAwait(false); - await writer.WriteAsync("\r\n").ConfigureAwait(false); - } - - await content.CopyToAsync(stream).ConfigureAwait(false); - - return await ReadResponse(stream).ConfigureAwait(false); - } - } - - private static async Task ReadResponse(Stream stream) - { - using (var reader = new StreamReader(stream, Encoding.ASCII, detectEncodingFromByteOrderMarks: true, - bufferSize: 1024, leaveOpen: true)) - { - var response = await reader.ReadToEndAsync().ConfigureAwait(false); - - var status = GetStatus(response); - new HttpResponseMessage(status).EnsureSuccessStatusCode(); - - var body = response.Substring(response.IndexOf("\r\n\r\n") + 4); - return body; - } - - } - - private static HttpStatusCode GetStatus(string response) - { - var statusStart = response.IndexOf(' ') + 1; - var statusEnd = response.IndexOf(' ', statusStart) - 1; - var statusLength = statusEnd - statusStart + 1; - return (HttpStatusCode)int.Parse(response.Substring(statusStart, statusLength)); - } - - private static async Task GetStream(Uri requestUri, bool validateCertificate) - { - var socket = await GetSocket(requestUri); - var stream = new NetworkStream(socket, ownsSocket: true); - - if (requestUri.Scheme.Equals("https", StringComparison.OrdinalIgnoreCase)) - { - var sslStream = new SslStream(stream, leaveInnerStreamOpen: false, userCertificateValidationCallback: - validateCertificate ? null : (RemoteCertificateValidationCallback)((a, b, c, d) => true)); - - await sslStream.AuthenticateAsClientAsync(requestUri.Host, clientCertificates: null, - enabledSslProtocols: SslProtocols.Tls11 | SslProtocols.Tls12, - checkCertificateRevocation: validateCertificate).ConfigureAwait(false); - return sslStream; - } - else - { - return stream; - } - } - - public static async Task GetSocket(Uri requestUri) - { - var tcs = new TaskCompletionSource(); - - var socketArgs = new SocketAsyncEventArgs(); - socketArgs.RemoteEndPoint = new DnsEndPoint(requestUri.DnsSafeHost, requestUri.Port); - socketArgs.Completed += (s, e) => tcs.TrySetResult(e.ConnectSocket); - - // Must use static ConnectAsync(), since instance Connect() does not support DNS names on OSX/Linux. - if (Socket.ConnectAsync(SocketType.Stream, ProtocolType.Tcp, socketArgs)) - { - await tcs.Task.ConfigureAwait(false); - } - - var socket = socketArgs.ConnectSocket; - - if (socket == null) - { - throw new SocketException((int)socketArgs.SocketError); - } - else - { - return socket; - } - } - } -} From 3fcd909d909c8810f09faca183de65c6d25f5bcf Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Mon, 26 Jun 2017 15:51:09 -0700 Subject: [PATCH 1326/1662] Temporarily disable systemd activation test (#1918) --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index d8dfd45204..6a7abcfffd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -28,5 +28,5 @@ before_install: - if test "$TRAVIS_OS_NAME" == "osx"; then brew update; brew install openssl; ln -s /usr/local/opt/openssl/lib/libcrypto.1.0.0.dylib /usr/local/lib/; ln -s /usr/local/opt/openssl/lib/libssl.1.0.0.dylib /usr/local/lib/; fi script: - ./build.sh - - if test "$TRAVIS_OS_NAME" != "osx"; then bash test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/SystemdActivation/docker.sh; fi -group: deprecated-2017Q2 +# Temporarily disabled systemd activation test: https://github.com/aspnet/KestrelHttpServer/issues/1912#issuecomment-311162419 +# - if test "$TRAVIS_OS_NAME" != "osx"; then bash test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/SystemdActivation/docker.sh; fi From 9b4be69e9d80bc1187b0b7d3ba302ff997ee8fb5 Mon Sep 17 00:00:00 2001 From: Nate McMaster Date: Tue, 27 Jun 2017 16:56:27 -0700 Subject: [PATCH 1327/1662] Do not enforce timeouts when the debugger is attached --- .../Internal/FrameConnection.cs | 19 ++++--- .../Internal/FrameConnectionContext.cs | 1 - .../Infrastructure/DebuggerWrapper.cs | 17 ++++++ .../Internal/Infrastructure/IDebugger.cs | 10 ++++ .../FrameConnectionTests.cs | 52 ++++++++++++++++--- test/shared/DummyApplication.cs | 5 ++ 6 files changed, 88 insertions(+), 16 deletions(-) create mode 100644 src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/DebuggerWrapper.cs create mode 100644 src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/IDebugger.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnection.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnection.cs index 7ae2f4c36a..6a0364f1f3 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnection.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnection.cs @@ -44,6 +44,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal // For testing internal Frame Frame => _frame; + internal IDebugger Debugger { get; set; } = DebuggerWrapper.Singleton; + public bool TimedOut { get; private set; } @@ -263,14 +265,17 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal // TODO: Use PlatformApis.VolatileRead equivalent again if (timestamp > Interlocked.Read(ref _timeoutTimestamp)) { - CancelTimeout(); - - if (_timeoutAction == TimeoutAction.SendTimeoutResponse) + if (!Debugger.IsAttached) { - SetTimeoutResponse(); - } + CancelTimeout(); - Timeout(); + if (_timeoutAction == TimeoutAction.SendTimeoutResponse) + { + SetTimeoutResponse(); + } + + Timeout(); + } } else { @@ -285,7 +290,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal var elapsedSeconds = (double)_readTimingElapsedTicks / TimeSpan.TicksPerSecond; var rate = Interlocked.Read(ref _readTimingBytesRead) / elapsedSeconds; - if (rate < _frame.RequestBodyMinimumDataRate.Rate) + if (rate < _frame.RequestBodyMinimumDataRate.Rate && !Debugger.IsAttached) { Log.RequestBodyMininumDataRateNotSatisfied(_context.ConnectionId, _frame.TraceIdentifier, _frame.RequestBodyMinimumDataRate.Rate); Timeout(); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnectionContext.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnectionContext.cs index 165daf2ad5..9f01593810 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnectionContext.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnectionContext.cs @@ -3,7 +3,6 @@ using System.Collections.Generic; using Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal; -using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/DebuggerWrapper.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/DebuggerWrapper.cs new file mode 100644 index 0000000000..df2b2644d9 --- /dev/null +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/DebuggerWrapper.cs @@ -0,0 +1,17 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System.Diagnostics; + +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure +{ + internal sealed class DebuggerWrapper : IDebugger + { + private DebuggerWrapper() + { } + + public static IDebugger Singleton { get; } = new DebuggerWrapper(); + + public bool IsAttached => Debugger.IsAttached; + } +} diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/IDebugger.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/IDebugger.cs new file mode 100644 index 0000000000..cb1448fd4f --- /dev/null +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/IDebugger.cs @@ -0,0 +1,10 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure +{ + public interface IDebugger + { + bool IsAttached { get; } + } +} diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameConnectionTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameConnectionTests.cs index 9596ef625f..c28f731ae4 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameConnectionTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameConnectionTests.cs @@ -50,19 +50,60 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests _pipeFactory.Dispose(); } + [Fact] + public void DoesNotTimeOutWhenDebuggerIsAttached() + { + var mockDebugger = new Mock(); + mockDebugger.SetupGet(g => g.IsAttached).Returns(true); + _frameConnection.Debugger = mockDebugger.Object; + _frameConnection.CreateFrame(new DummyApplication(), _frameConnectionContext.Input.Reader, _frameConnectionContext.Output); + + var now = DateTimeOffset.Now; + _frameConnection.Tick(now); + _frameConnection.SetTimeout(1, TimeoutAction.SendTimeoutResponse); + _frameConnection.Tick(now.AddTicks(2).Add(Heartbeat.Interval)); + + Assert.False(_frameConnection.TimedOut); + } + + [Fact] + public void DoesNotTimeOutWhenRequestBodyDoesNotSatisfyMinimumDataRateButDebuggerIsAttached() + { + var mockDebugger = new Mock(); + mockDebugger.SetupGet(g => g.IsAttached).Returns(true); + _frameConnection.Debugger = mockDebugger.Object; + var requestBodyMinimumDataRate = 100; + var mockLogger = new Mock(); + mockLogger.Setup(l => l.RequestBodyMininumDataRateNotSatisfied(It.IsAny(), It.IsAny(), It.IsAny())).Throws(new InvalidOperationException("Should not log")); + + TickBodyWithMinimumDataRate(mockLogger.Object, requestBodyMinimumDataRate); + + Assert.False(_frameConnection.TimedOut); + } + [Fact] public void TimesOutWhenRequestBodyDoesNotSatisfyMinimumDataRate() { var requestBodyMinimumDataRate = 100; + var mockLogger = new Mock(); + TickBodyWithMinimumDataRate(mockLogger.Object, requestBodyMinimumDataRate); + + // Timed out + Assert.True(_frameConnection.TimedOut); + mockLogger.Verify(logger => + logger.RequestBodyMininumDataRateNotSatisfied(It.IsAny(), It.IsAny(), requestBodyMinimumDataRate), Times.Once); + } + + private void TickBodyWithMinimumDataRate(IKestrelTrace logger, int requestBodyMinimumDataRate) + { var requestBodyGracePeriod = TimeSpan.FromSeconds(5); _frameConnectionContext.ServiceContext.ServerOptions.Limits.RequestBodyMinimumDataRate = new MinimumDataRate(rate: requestBodyMinimumDataRate, gracePeriod: requestBodyGracePeriod); - var mockLogger = new Mock(); - _frameConnectionContext.ServiceContext.Log = mockLogger.Object; + _frameConnectionContext.ServiceContext.Log = logger; - _frameConnection.CreateFrame(new DummyApplication(context => Task.CompletedTask), _frameConnectionContext.Input.Reader, _frameConnectionContext.Output); + _frameConnection.CreateFrame(new DummyApplication(), _frameConnectionContext.Input.Reader, _frameConnectionContext.Output); _frameConnection.Frame.Reset(); // Initialize timestamp @@ -75,11 +116,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests now += requestBodyGracePeriod + TimeSpan.FromSeconds(1); _frameConnection.BytesRead(1); _frameConnection.Tick(now); - - // Timed out - Assert.True(_frameConnection.TimedOut); - mockLogger.Verify(logger => - logger.RequestBodyMininumDataRateNotSatisfied(It.IsAny(), It.IsAny(), requestBodyMinimumDataRate), Times.Once); } [Fact] diff --git a/test/shared/DummyApplication.cs b/test/shared/DummyApplication.cs index e944bf3562..389a799b2d 100644 --- a/test/shared/DummyApplication.cs +++ b/test/shared/DummyApplication.cs @@ -14,6 +14,11 @@ namespace Microsoft.AspNetCore.Testing private readonly RequestDelegate _requestDelegate; private readonly IHttpContextFactory _httpContextFactory; + public DummyApplication() + : this(_ => Task.CompletedTask) + { + } + public DummyApplication(RequestDelegate requestDelegate) : this(requestDelegate, null) { From 697ed9bd82c2db2d78b4a3e72769ea4caa126286 Mon Sep 17 00:00:00 2001 From: Pranav K Date: Thu, 29 Jun 2017 08:25:54 -0700 Subject: [PATCH 1328/1662] Update dependencies.props * Update Moq to 4.7.49. * Add NETStandardImplicitPackageVersion --- build/dependencies.props | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/build/dependencies.props b/build/dependencies.props index b323cb0f4e..a1d51e5e9f 100644 --- a/build/dependencies.props +++ b/build/dependencies.props @@ -1,11 +1,12 @@ - + 2.0.0-* 4.4.0-* 2.1.0-* 1.10.0 9.0.1 - 4.7.1 + 4.7.49 + 2.0.0-* 2.0.0-* 2.0.0-* 15.3.0-* From be1605a8d54676a78b47eb623451f3f73f346143 Mon Sep 17 00:00:00 2001 From: Ryan Brandenburg Date: Wed, 28 Jun 2017 16:33:57 -0700 Subject: [PATCH 1329/1662] Remove NETStandard.Library.NETFramework and update Moq --- build/common.props | 4 ---- 1 file changed, 4 deletions(-) diff --git a/build/common.props b/build/common.props index 595790c41b..c4cad36e29 100644 --- a/build/common.props +++ b/build/common.props @@ -16,8 +16,4 @@ - - - - From a247a3d8e6af8d3d22cd43d32680265046179843 Mon Sep 17 00:00:00 2001 From: Aristarkh Zagorodnikov Date: Thu, 29 Jun 2017 21:01:03 +0300 Subject: [PATCH 1330/1662] Attempting to fix systemd activation with minimal changes (#1925) --- .travis.yml | 3 +- .../SystemdActivation/Dockerfile | 40 +++++++++++-------- .../SystemdActivation/activate-kestrel.socket | 4 +- 3 files changed, 28 insertions(+), 19 deletions(-) diff --git a/.travis.yml b/.travis.yml index 6a7abcfffd..70902067d3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -28,5 +28,4 @@ before_install: - if test "$TRAVIS_OS_NAME" == "osx"; then brew update; brew install openssl; ln -s /usr/local/opt/openssl/lib/libcrypto.1.0.0.dylib /usr/local/lib/; ln -s /usr/local/opt/openssl/lib/libssl.1.0.0.dylib /usr/local/lib/; fi script: - ./build.sh -# Temporarily disabled systemd activation test: https://github.com/aspnet/KestrelHttpServer/issues/1912#issuecomment-311162419 -# - if test "$TRAVIS_OS_NAME" != "osx"; then bash test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/SystemdActivation/docker.sh; fi + - if test "$TRAVIS_OS_NAME" != "osx"; then bash test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/SystemdActivation/docker.sh; fi diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/SystemdActivation/Dockerfile b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/SystemdActivation/Dockerfile index ac2b561610..59b592bd85 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/SystemdActivation/Dockerfile +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/SystemdActivation/Dockerfile @@ -3,26 +3,34 @@ FROM microsoft/dotnet-nightly:2.0-runtime-deps # The "container" environment variable is read by systemd. ENV container=docker -# This is required by systemd and won't work without "dotnet run --privileged". -VOLUME ["/sys/fs/cgroup"] +# Install and configure systemd which requires dbus for graceful shutdown. +RUN ["apt-get", "-o", "Acquire::Check-Valid-Until=false", "update"] +RUN ["apt-get", "install", "-y", "--no-install-recommends", "systemd-sysv"] + +# Set proper systemd default target. +RUN ["systemctl", "set-default", "multi-user.target"] + +# Remove non-vital systemd services. +RUN ["find", "/etc/systemd/system", "/lib/systemd/system", \ + "-path", "*.wants/*", \ + "-not", "-name", "*systemd-journald*", \ + "-not", "-name", "*systemd-tmpfiles*", \ + "-not", "-name", "*systemd-user-sessions*", \ + "-delete"] + +# Copy .NET installation. +ADD .dotnet/ /usr/share/dotnet/ +RUN ["ln", "-s", "/usr/share/dotnet/dotnet", "/usr/bin/dotnet"] # Create activate-kestrel.service to launch the "publish" app on new requests to 8080. EXPOSE 8080 -ADD .dotnet/ /usr/share/dotnet/ ADD publish/ /publish/ -ADD activate-kestrel.socket /etc/systemd/system/activate-kestrel.socket ADD activate-kestrel.service /etc/systemd/system/activate-kestrel.service +ADD activate-kestrel.socket /etc/systemd/system/activate-kestrel.socket -# Install and configure systemd which requires dbus for graceful shutdown. -RUN ["apt-get", "-o", "Acquire::Check-Valid-Until=false", "update"] -RUN ["apt-get", "install", "-y", "dbus"] -RUN ["systemctl", "mask", "getty.target", "console-getty.service"] -RUN ["cp", "/lib/systemd/system/dbus.service", "/etc/systemd/system/"] -RUN ["sed", "-i", "s/OOMScoreAdjust=-900//", "/etc/systemd/system/dbus.service"] +# Automatically start activate-kestrel.socket on boot. +RUN ["systemctl", "enable", "activate-kestrel.socket"] -# Automatically start activate-kestrel.service on boot. -RUN ["ln", "-s", "/usr/share/dotnet/dotnet", "/usr/bin/dotnet"] -RUN ["ln", "-s", "/usr/lib/systemd/system/activate-kestrel.service", "/etc/systemd/system/multi-user.target.wants/activate-kestrel.service"] - -# Launch systemd. -CMD ["/sbin/init"] +# Launch systemd, with workaround for docker/docker#27202, technique based on comments from docker/docker#9212. +CMD ["/bin/bash", "-c", "exec /sbin/init --log-target=journal 3>&1"] +STOPSIGNAL SIGRTMIN+3 diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/SystemdActivation/activate-kestrel.socket b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/SystemdActivation/activate-kestrel.socket index 1407c09f88..8b8e48e9c8 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/SystemdActivation/activate-kestrel.socket +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/SystemdActivation/activate-kestrel.socket @@ -1,7 +1,9 @@ [Unit] -Description=Kestrel Activation +PartOf=activate-kestrel.service [Socket] ListenStream=8080 NoDelay=true +[Install] +WantedBy=multi-user.target From 3ba8c2d3f0d2d4859586d4d14a1b064ef70c750c Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Thu, 29 Jun 2017 11:50:21 -0700 Subject: [PATCH 1331/1662] Add ListenHandleTests (#1923) --- .../ListenHandleTests.cs | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ListenHandleTests.cs diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ListenHandleTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ListenHandleTests.cs new file mode 100644 index 0000000000..71278e954c --- /dev/null +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ListenHandleTests.cs @@ -0,0 +1,40 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System.Net; +using System.Net.Sockets; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Server.Kestrel.Core; +using Microsoft.AspNetCore.Testing; +using Microsoft.AspNetCore.Testing.xunit; + +namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests +{ + [OSSkipCondition(OperatingSystems.Windows, SkipReason = "Listening to open TCP socket and/or pipe handles is not supported on Windows.")] + public class ListenHandleTests + { + [ConditionalFact] + public async Task CanListenToOpenTcpSocketHandle() + { + using (var listenSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)) + { + listenSocket.Bind(new IPEndPoint(IPAddress.Loopback, 0)); + + using (var server = new TestServer(_ => Task.CompletedTask, new TestServiceContext(), new ListenOptions((ulong)listenSocket.Handle))) + { + using (var connection = new TestConnection(((IPEndPoint)listenSocket.LocalEndPoint).Port)) + { + await connection.SendEmptyGet(); + + await connection.Receive( + "HTTP/1.1 200 OK", + $"Date: {server.Context.DateHeaderValue}", + "Content-Length: 0", + "", + ""); + } + } + } + } + } +} From f2061ed71601f73491366768048878c2662d4345 Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Thu, 29 Jun 2017 17:16:34 -0700 Subject: [PATCH 1332/1662] Rename request body min rate APIs (#1901). --- .../CoreStrings.resx | 3 + ... => IHttpMinRequestBodyDataRateFeature.cs} | 4 +- .../Features/MinimumDataRate.cs | 41 ------ .../Internal/FrameConnection.cs | 6 +- .../Internal/Http/Frame.FeatureCollection.cs | 8 +- .../Internal/Http/Frame.Generated.cs | 18 +-- .../Internal/Http/Frame.cs | 5 +- .../KestrelServerLimits.cs | 4 +- .../MinDataRate.cs | 44 ++++++ .../Properties/CoreStrings.Designer.cs | 14 ++ .../FrameConnectionTests.cs | 128 ++++++++++-------- .../FrameTests.cs | 18 +-- .../HeartbeatTests.cs | 6 + .../KestrelServerLimitsTests.cs | 8 +- ...umDataRateTests.cs => MinDataRateTests.cs} | 32 +++-- .../KeepAliveTimeoutTests.cs | 2 +- .../MaxRequestBufferSizeTests.cs | 2 +- .../RequestBodyTimeoutTests.cs | 22 +-- .../RequestHeadersTimeoutTests.cs | 2 +- .../RequestTests.cs | 5 +- tools/CodeGenerator/FrameFeatureCollection.cs | 4 +- 21 files changed, 206 insertions(+), 170 deletions(-) rename src/Microsoft.AspNetCore.Server.Kestrel.Core/Features/{IHttpRequestBodyMinimumDataRateFeature.cs => IHttpMinRequestBodyDataRateFeature.cs} (85%) delete mode 100644 src/Microsoft.AspNetCore.Server.Kestrel.Core/Features/MinimumDataRate.cs create mode 100644 src/Microsoft.AspNetCore.Server.Kestrel.Core/MinDataRate.cs rename test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/{MinimumDataRateTests.cs => MinDataRateTests.cs} (55%) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/CoreStrings.resx b/src/Microsoft.AspNetCore.Server.Kestrel.Core/CoreStrings.resx index 72d2a8aa5f..13454c5127 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/CoreStrings.resx +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/CoreStrings.resx @@ -333,4 +333,7 @@ Value must be a non-negative TimeSpan. + + The request body rate enforcement grace period must be greater than {heartbeatInterval} second. + diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Features/IHttpRequestBodyMinimumDataRateFeature.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Features/IHttpMinRequestBodyDataRateFeature.cs similarity index 85% rename from src/Microsoft.AspNetCore.Server.Kestrel.Core/Features/IHttpRequestBodyMinimumDataRateFeature.cs rename to src/Microsoft.AspNetCore.Server.Kestrel.Core/Features/IHttpMinRequestBodyDataRateFeature.cs index 9190d73d18..af5ee4e66f 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Features/IHttpRequestBodyMinimumDataRateFeature.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Features/IHttpMinRequestBodyDataRateFeature.cs @@ -6,13 +6,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Features /// /// Represents a minimum data rate for the request body of an HTTP request. /// - public interface IHttpRequestBodyMinimumDataRateFeature + public interface IHttpMinRequestBodyDataRateFeature { /// /// The minimum data rate in bytes/second at which the request body should be received. /// Setting this property to null indicates no minimum data rate should be enforced. /// This limit has no effect on upgraded connections which are always unlimited. /// - MinimumDataRate MinimumDataRate { get; set; } + MinDataRate MinDataRate { get; set; } } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Features/MinimumDataRate.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Features/MinimumDataRate.cs deleted file mode 100644 index c294d2df3d..0000000000 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Features/MinimumDataRate.cs +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; - -namespace Microsoft.AspNetCore.Server.Kestrel.Core.Features -{ - public class MinimumDataRate - { - /// - /// Creates a new instance of . - /// - /// The minimum rate in bytes/second at which data should be processed. - /// The amount of time to delay enforcement of . - public MinimumDataRate(double rate, TimeSpan gracePeriod) - { - if (rate <= 0) - { - throw new ArgumentOutOfRangeException(nameof(rate), CoreStrings.PositiveNumberRequired); - } - - if (gracePeriod < TimeSpan.Zero) - { - throw new ArgumentOutOfRangeException(nameof(gracePeriod), CoreStrings.NonNegativeTimeSpanRequired); - } - - Rate = rate; - GracePeriod = gracePeriod; - } - - /// - /// The minimum rate in bytes/second at which data should be processed. - /// - public double Rate { get; } - - /// - /// The amount of time to delay enforcement of . - /// - public TimeSpan GracePeriod { get; } - } -} diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnection.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnection.cs index 6a0364f1f3..085716a841 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnection.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnection.cs @@ -285,14 +285,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal { _readTimingElapsedTicks += timestamp - _lastTimestamp; - if (_frame.RequestBodyMinimumDataRate?.Rate > 0 && _readTimingElapsedTicks > _frame.RequestBodyMinimumDataRate.GracePeriod.Ticks) + if (_frame.MinRequestBodyDataRate?.BytesPerSecond > 0 && _readTimingElapsedTicks > _frame.MinRequestBodyDataRate.GracePeriod.Ticks) { var elapsedSeconds = (double)_readTimingElapsedTicks / TimeSpan.TicksPerSecond; var rate = Interlocked.Read(ref _readTimingBytesRead) / elapsedSeconds; - if (rate < _frame.RequestBodyMinimumDataRate.Rate && !Debugger.IsAttached) + if (rate < _frame.MinRequestBodyDataRate.BytesPerSecond && !Debugger.IsAttached) { - Log.RequestBodyMininumDataRateNotSatisfied(_context.ConnectionId, _frame.TraceIdentifier, _frame.RequestBodyMinimumDataRate.Rate); + Log.RequestBodyMininumDataRateNotSatisfied(_context.ConnectionId, _frame.TraceIdentifier, _frame.MinRequestBodyDataRate.BytesPerSecond); Timeout(); } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.FeatureCollection.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.FeatureCollection.cs index fdfb0d6c30..e9737e5b21 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.FeatureCollection.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.FeatureCollection.cs @@ -23,7 +23,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http IHttpRequestLifetimeFeature, IHttpRequestIdentifierFeature, IHttpMaxRequestBodySizeFeature, - IHttpRequestBodyMinimumDataRateFeature + IHttpMinRequestBodyDataRateFeature { // NOTE: When feature interfaces are added to or removed from this Frame class implementation, // then the list of `implementedFeatures` in the generated code project MUST also be updated. @@ -229,10 +229,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http } } - MinimumDataRate IHttpRequestBodyMinimumDataRateFeature.MinimumDataRate + MinDataRate IHttpMinRequestBodyDataRateFeature.MinDataRate { - get => RequestBodyMinimumDataRate; - set => RequestBodyMinimumDataRate = value; + get => MinRequestBodyDataRate; + set => MinRequestBodyDataRate = value; } object IFeatureCollection.this[Type key] diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.Generated.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.Generated.cs index ef0aa0faa6..f2b9c90d10 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.Generated.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.Generated.cs @@ -24,7 +24,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http private static readonly Type IHttpWebSocketFeatureType = typeof(global::Microsoft.AspNetCore.Http.Features.IHttpWebSocketFeature); private static readonly Type ISessionFeatureType = typeof(global::Microsoft.AspNetCore.Http.Features.ISessionFeature); private static readonly Type IHttpMaxRequestBodySizeFeatureType = typeof(global::Microsoft.AspNetCore.Http.Features.IHttpMaxRequestBodySizeFeature); - private static readonly Type IHttpRequestBodyMinimumDataRateFeatureType = typeof(global::Microsoft.AspNetCore.Server.Kestrel.Core.Features.IHttpRequestBodyMinimumDataRateFeature); + private static readonly Type IHttpMinRequestBodyDataRateFeatureType = typeof(global::Microsoft.AspNetCore.Server.Kestrel.Core.Features.IHttpMinRequestBodyDataRateFeature); private static readonly Type IHttpSendFileFeatureType = typeof(global::Microsoft.AspNetCore.Http.Features.IHttpSendFileFeature); private object _currentIHttpRequestFeature; @@ -43,7 +43,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http private object _currentIHttpWebSocketFeature; private object _currentISessionFeature; private object _currentIHttpMaxRequestBodySizeFeature; - private object _currentIHttpRequestBodyMinimumDataRateFeature; + private object _currentIHttpMinRequestBodyDataRateFeature; private object _currentIHttpSendFileFeature; private void FastReset() @@ -55,7 +55,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http _currentIHttpRequestLifetimeFeature = this; _currentIHttpConnectionFeature = this; _currentIHttpMaxRequestBodySizeFeature = this; - _currentIHttpRequestBodyMinimumDataRateFeature = this; + _currentIHttpMinRequestBodyDataRateFeature = this; _currentIServiceProvidersFeature = null; _currentIHttpAuthenticationFeature = null; @@ -135,9 +135,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { return _currentIHttpMaxRequestBodySizeFeature; } - if (key == IHttpRequestBodyMinimumDataRateFeatureType) + if (key == IHttpMinRequestBodyDataRateFeatureType) { - return _currentIHttpRequestBodyMinimumDataRateFeature; + return _currentIHttpMinRequestBodyDataRateFeature; } if (key == IHttpSendFileFeatureType) { @@ -230,9 +230,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http _currentIHttpMaxRequestBodySizeFeature = feature; return; } - if (key == IHttpRequestBodyMinimumDataRateFeatureType) + if (key == IHttpMinRequestBodyDataRateFeatureType) { - _currentIHttpRequestBodyMinimumDataRateFeature = feature; + _currentIHttpMinRequestBodyDataRateFeature = feature; return; } if (key == IHttpSendFileFeatureType) @@ -309,9 +309,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { yield return new KeyValuePair(IHttpMaxRequestBodySizeFeatureType, _currentIHttpMaxRequestBodySizeFeature as global::Microsoft.AspNetCore.Http.Features.IHttpMaxRequestBodySizeFeature); } - if (_currentIHttpRequestBodyMinimumDataRateFeature != null) + if (_currentIHttpMinRequestBodyDataRateFeature != null) { - yield return new KeyValuePair(IHttpRequestBodyMinimumDataRateFeatureType, _currentIHttpRequestBodyMinimumDataRateFeature as global::Microsoft.AspNetCore.Server.Kestrel.Core.Features.IHttpRequestBodyMinimumDataRateFeature); + yield return new KeyValuePair(IHttpMinRequestBodyDataRateFeatureType, _currentIHttpMinRequestBodyDataRateFeature as global::Microsoft.AspNetCore.Server.Kestrel.Core.Features.IHttpMinRequestBodyDataRateFeature); } if (_currentIHttpSendFileFeature != null) { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.cs index f81b13078e..90171989c3 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.cs @@ -13,7 +13,6 @@ using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http.Features; -using Microsoft.AspNetCore.Server.Kestrel.Core.Features; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Internal.System; using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; @@ -300,7 +299,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http protected FrameResponseHeaders FrameResponseHeaders { get; } = new FrameResponseHeaders(); - public MinimumDataRate RequestBodyMinimumDataRate { get; set; } + public MinDataRate MinRequestBodyDataRate { get; set; } public void InitializeStreams(MessageBody messageBody) { @@ -379,7 +378,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http _responseBytesWritten = 0; _requestCount++; - RequestBodyMinimumDataRate = ServerOptions.Limits.RequestBodyMinimumDataRate; + MinRequestBodyDataRate = ServerOptions.Limits.MinRequestBodyDataRate; } /// diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/KestrelServerLimits.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/KestrelServerLimits.cs index eb04cb9b90..5eaa4c2c9a 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/KestrelServerLimits.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/KestrelServerLimits.cs @@ -255,11 +255,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core /// Gets or sets the request body minimum data rate in bytes/second. /// Setting this property to null indicates no minimum data rate should be enforced. /// This limit has no effect on upgraded connections which are always unlimited. - /// This can be overridden per-request via . + /// This can be overridden per-request via . /// /// /// Defaults to 1 byte/second with a 5 second grace period. /// - public MinimumDataRate RequestBodyMinimumDataRate { get; set; } = new MinimumDataRate(rate: 1, gracePeriod: TimeSpan.FromSeconds(5)); + public MinDataRate MinRequestBodyDataRate { get; set; } = new MinDataRate(bytesPerSecond: 1, gracePeriod: TimeSpan.FromSeconds(5)); } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/MinDataRate.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/MinDataRate.cs new file mode 100644 index 0000000000..34cbdc577d --- /dev/null +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/MinDataRate.cs @@ -0,0 +1,44 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; + +namespace Microsoft.AspNetCore.Server.Kestrel.Core +{ + public class MinDataRate + { + /// + /// Creates a new instance of . + /// + /// The minimum rate in bytes/second at which data should be processed. + /// The amount of time to delay enforcement of , + /// starting at the time data is first read or written. + public MinDataRate(double bytesPerSecond, TimeSpan gracePeriod) + { + if (bytesPerSecond < 0) + { + throw new ArgumentOutOfRangeException(nameof(bytesPerSecond), CoreStrings.NonNegativeNumberRequired); + } + + if (gracePeriod <= Heartbeat.Interval) + { + throw new ArgumentOutOfRangeException(nameof(gracePeriod), CoreStrings.FormatMinimumGracePeriodRequired(Heartbeat.Interval.TotalSeconds)); + } + + BytesPerSecond = bytesPerSecond; + GracePeriod = gracePeriod; + } + + /// + /// The minimum rate in bytes/second at which data should be processed. + /// + public double BytesPerSecond { get; } + + /// + /// The amount of time to delay enforcement of , + /// starting at the time data is first read or written. + /// + public TimeSpan GracePeriod { get; } + } +} diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Properties/CoreStrings.Designer.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Properties/CoreStrings.Designer.cs index ce955e41d0..5fb571f55b 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Properties/CoreStrings.Designer.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Properties/CoreStrings.Designer.cs @@ -1018,6 +1018,20 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core internal static string FormatNonNegativeTimeSpanRequired() => GetString("NonNegativeTimeSpanRequired"); + /// + /// The request body rate enforcement grace period must be greater than {heartbeatInterval} seconds. + /// + internal static string MinimumGracePeriodRequired + { + get => GetString("MinimumGracePeriodRequired"); + } + + /// + /// The request body rate enforcement grace period must be greater than {heartbeatInterval} seconds. + /// + internal static string FormatMinimumGracePeriodRequired(object heartbeatInterval) + => string.Format(CultureInfo.CurrentCulture, GetString("MinimumGracePeriodRequired", "heartbeatInterval"), heartbeatInterval); + private static string GetString(string name, params string[] formatterNames) { var value = _resourceManager.GetString(name); diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameConnectionTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameConnectionTests.cs index c28f731ae4..790ce56d7e 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameConnectionTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameConnectionTests.cs @@ -5,7 +5,6 @@ using System; using System.Collections.Generic; using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal; -using Microsoft.AspNetCore.Server.Kestrel.Core.Features; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; @@ -72,11 +71,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests var mockDebugger = new Mock(); mockDebugger.SetupGet(g => g.IsAttached).Returns(true); _frameConnection.Debugger = mockDebugger.Object; - var requestBodyMinimumDataRate = 100; + var bytesPerSecond = 100; var mockLogger = new Mock(); mockLogger.Setup(l => l.RequestBodyMininumDataRateNotSatisfied(It.IsAny(), It.IsAny(), It.IsAny())).Throws(new InvalidOperationException("Should not log")); - TickBodyWithMinimumDataRate(mockLogger.Object, requestBodyMinimumDataRate); + TickBodyWithMinimumDataRate(mockLogger.Object, bytesPerSecond); Assert.False(_frameConnection.TimedOut); } @@ -84,22 +83,22 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests [Fact] public void TimesOutWhenRequestBodyDoesNotSatisfyMinimumDataRate() { - var requestBodyMinimumDataRate = 100; + var bytesPerSecond = 100; var mockLogger = new Mock(); - TickBodyWithMinimumDataRate(mockLogger.Object, requestBodyMinimumDataRate); + TickBodyWithMinimumDataRate(mockLogger.Object, bytesPerSecond); // Timed out Assert.True(_frameConnection.TimedOut); mockLogger.Verify(logger => - logger.RequestBodyMininumDataRateNotSatisfied(It.IsAny(), It.IsAny(), requestBodyMinimumDataRate), Times.Once); + logger.RequestBodyMininumDataRateNotSatisfied(It.IsAny(), It.IsAny(), bytesPerSecond), Times.Once); } - private void TickBodyWithMinimumDataRate(IKestrelTrace logger, int requestBodyMinimumDataRate) + private void TickBodyWithMinimumDataRate(IKestrelTrace logger, int bytesPerSecond) { - var requestBodyGracePeriod = TimeSpan.FromSeconds(5); + var gracePeriod = TimeSpan.FromSeconds(5); - _frameConnectionContext.ServiceContext.ServerOptions.Limits.RequestBodyMinimumDataRate = - new MinimumDataRate(rate: requestBodyMinimumDataRate, gracePeriod: requestBodyGracePeriod); + _frameConnectionContext.ServiceContext.ServerOptions.Limits.MinRequestBodyDataRate = + new MinDataRate(bytesPerSecond: bytesPerSecond, gracePeriod: gracePeriod); _frameConnectionContext.ServiceContext.Log = logger; @@ -113,19 +112,19 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests _frameConnection.StartTimingReads(); // Tick after grace period w/ low data rate - now += requestBodyGracePeriod + TimeSpan.FromSeconds(1); + now += gracePeriod + TimeSpan.FromSeconds(1); _frameConnection.BytesRead(1); _frameConnection.Tick(now); } [Fact] - public void MinimumDataRateNotEnforcedDuringGracePeriod() + public void RequestBodyMinimumDataRateNotEnforcedDuringGracePeriod() { - var requestBodyMinimumDataRate = 100; - var requestBodyGracePeriod = TimeSpan.FromSeconds(2); + var bytesPerSecond = 100; + var gracePeriod = TimeSpan.FromSeconds(2); - _frameConnectionContext.ServiceContext.ServerOptions.Limits.RequestBodyMinimumDataRate = - new MinimumDataRate(rate: requestBodyMinimumDataRate, gracePeriod: requestBodyGracePeriod); + _frameConnectionContext.ServiceContext.ServerOptions.Limits.MinRequestBodyDataRate = + new MinDataRate(bytesPerSecond: bytesPerSecond, gracePeriod: gracePeriod); var mockLogger = new Mock(); _frameConnectionContext.ServiceContext.Log = mockLogger.Object; @@ -147,7 +146,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests // Not timed out Assert.False(_frameConnection.TimedOut); mockLogger.Verify(logger => - logger.RequestBodyMininumDataRateNotSatisfied(It.IsAny(), It.IsAny(), requestBodyMinimumDataRate), Times.Never); + logger.RequestBodyMininumDataRateNotSatisfied(It.IsAny(), It.IsAny(), bytesPerSecond), Times.Never); // Tick after grace period w/ low data rate now += TimeSpan.FromSeconds(2); @@ -157,17 +156,17 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests // Timed out Assert.True(_frameConnection.TimedOut); mockLogger.Verify(logger => - logger.RequestBodyMininumDataRateNotSatisfied(It.IsAny(), It.IsAny(), requestBodyMinimumDataRate), Times.Once); + logger.RequestBodyMininumDataRateNotSatisfied(It.IsAny(), It.IsAny(), bytesPerSecond), Times.Once); } [Fact] - public void DataRateIsAveragedOverTimeSpentReadingRequestBody() + public void RequestBodyDataRateIsAveragedOverTimeSpentReadingRequestBody() { - var requestBodyMinimumDataRate = 100; - var requestBodyGracePeriod = TimeSpan.FromSeconds(1); + var bytesPerSecond = 100; + var gracePeriod = TimeSpan.FromSeconds(2); - _frameConnectionContext.ServiceContext.ServerOptions.Limits.RequestBodyMinimumDataRate = - new MinimumDataRate(rate: requestBodyMinimumDataRate, gracePeriod: requestBodyGracePeriod); + _frameConnectionContext.ServiceContext.ServerOptions.Limits.MinRequestBodyDataRate = + new MinDataRate(bytesPerSecond: bytesPerSecond, gracePeriod: gracePeriod); var mockLogger = new Mock(); _frameConnectionContext.ServiceContext.Log = mockLogger.Object; @@ -181,60 +180,69 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests _frameConnection.StartTimingReads(); - // Tick after grace period to start enforcing minimum data rate - now += requestBodyGracePeriod; - _frameConnection.BytesRead(100); + // Set base data rate to 200 bytes/second + now += gracePeriod; + _frameConnection.BytesRead(400); _frameConnection.Tick(now); // Data rate: 200 bytes/second now += TimeSpan.FromSeconds(1); - _frameConnection.BytesRead(300); + _frameConnection.BytesRead(200); _frameConnection.Tick(now); // Not timed out Assert.False(_frameConnection.TimedOut); mockLogger.Verify(logger => - logger.RequestBodyMininumDataRateNotSatisfied(It.IsAny(), It.IsAny(), requestBodyMinimumDataRate), Times.Never); + logger.RequestBodyMininumDataRateNotSatisfied(It.IsAny(), It.IsAny(), bytesPerSecond), Times.Never); // Data rate: 150 bytes/second now += TimeSpan.FromSeconds(1); - _frameConnection.BytesRead(50); + _frameConnection.BytesRead(0); _frameConnection.Tick(now); // Not timed out Assert.False(_frameConnection.TimedOut); mockLogger.Verify(logger => - logger.RequestBodyMininumDataRateNotSatisfied(It.IsAny(), It.IsAny(), requestBodyMinimumDataRate), Times.Never); + logger.RequestBodyMininumDataRateNotSatisfied(It.IsAny(), It.IsAny(), bytesPerSecond), Times.Never); - // Data rate: 115 bytes/second + // Data rate: 120 bytes/second now += TimeSpan.FromSeconds(1); - _frameConnection.BytesRead(10); + _frameConnection.BytesRead(0); _frameConnection.Tick(now); // Not timed out Assert.False(_frameConnection.TimedOut); mockLogger.Verify(logger => - logger.RequestBodyMininumDataRateNotSatisfied(It.IsAny(), It.IsAny(), requestBodyMinimumDataRate), Times.Never); + logger.RequestBodyMininumDataRateNotSatisfied(It.IsAny(), It.IsAny(), bytesPerSecond), Times.Never); - // Data rate: 50 bytes/second - now += TimeSpan.FromSeconds(6); - _frameConnection.BytesRead(40); + // Data rate: 100 bytes/second + now += TimeSpan.FromSeconds(1); + _frameConnection.BytesRead(0); + _frameConnection.Tick(now); + + // Not timed out + Assert.False(_frameConnection.TimedOut); + mockLogger.Verify(logger => + logger.RequestBodyMininumDataRateNotSatisfied(It.IsAny(), It.IsAny(), bytesPerSecond), Times.Never); + + // Data rate: ~85 bytes/second + now += TimeSpan.FromSeconds(1); + _frameConnection.BytesRead(0); _frameConnection.Tick(now); // Timed out Assert.True(_frameConnection.TimedOut); mockLogger.Verify(logger => - logger.RequestBodyMininumDataRateNotSatisfied(It.IsAny(), It.IsAny(), requestBodyMinimumDataRate), Times.Once); + logger.RequestBodyMininumDataRateNotSatisfied(It.IsAny(), It.IsAny(), bytesPerSecond), Times.Once); } [Fact] - public void PausedTimeDoesNotCountAgainstRequestBodyTimeout() + public void RequestBodyDataRateNotComputedOnPausedTime() { - var requestBodyTimeout = TimeSpan.FromSeconds(5); var systemClock = new MockSystemClock(); - _frameConnectionContext.ServiceContext.ServerOptions.Limits.RequestBodyMinimumDataRate = - new MinimumDataRate(rate: 100, gracePeriod: TimeSpan.Zero); + _frameConnectionContext.ServiceContext.ServerOptions.Limits.MinRequestBodyDataRate = + new MinDataRate(bytesPerSecond: 100, gracePeriod: TimeSpan.FromSeconds(2)); _frameConnectionContext.ServiceContext.SystemClock = systemClock; var mockLogger = new Mock(); @@ -248,21 +256,21 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests _frameConnection.StartTimingReads(); - // Tick at 1s, expected counted time is 1s, expected data rate is 400 bytes/second - systemClock.UtcNow += TimeSpan.FromSeconds(1); - _frameConnection.BytesRead(400); + // Tick at 3s, expected counted time is 3s, expected data rate is 200 bytes/second + systemClock.UtcNow += TimeSpan.FromSeconds(3); + _frameConnection.BytesRead(600); _frameConnection.Tick(systemClock.UtcNow); - // Pause at 1.5s + // Pause at 3.5s systemClock.UtcNow += TimeSpan.FromSeconds(0.5); _frameConnection.PauseTimingReads(); - // Tick at 2s, expected counted time is 2s, expected data rate is 400 bytes/second + // Tick at 4s, expected counted time is 4s (first tick after pause goes through), expected data rate is 150 bytes/second systemClock.UtcNow += TimeSpan.FromSeconds(0.5); _frameConnection.Tick(systemClock.UtcNow); - // Tick at 6s, expected counted time is 2s, expected data rate is 400 bytes/second - systemClock.UtcNow += TimeSpan.FromSeconds(4); + // Tick at 6s, expected counted time is 4s, expected data rate is 150 bytes/second + systemClock.UtcNow += TimeSpan.FromSeconds(2); _frameConnection.Tick(systemClock.UtcNow); // Not timed out @@ -275,7 +283,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests systemClock.UtcNow += TimeSpan.FromSeconds(0.5); _frameConnection.ResumeTimingReads(); - // Tick at 8s, expected counted time is 4s, expected data rate is 100 bytes/second + // Tick at 9s, expected counted time is 6s, expected data rate is 100 bytes/second systemClock.UtcNow += TimeSpan.FromSeconds(1.5); _frameConnection.Tick(systemClock.UtcNow); @@ -285,7 +293,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests logger => logger.RequestBodyMininumDataRateNotSatisfied(It.IsAny(), It.IsAny(), It.IsAny()), Times.Never); - // Tick at 9s, expected counted time is 9s, expected data rate drops below 100 bytes/second + // Tick at 10s, expected counted time is 7s, expected data rate drops below 100 bytes/second systemClock.UtcNow += TimeSpan.FromSeconds(1); _frameConnection.Tick(systemClock.UtcNow); @@ -297,12 +305,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests } [Fact] - public void NotPausedWhenResumeCalledBeforeNextTick() + public void ReadTimingNotPausedWhenResumeCalledBeforeNextTick() { var systemClock = new MockSystemClock(); - _frameConnectionContext.ServiceContext.ServerOptions.Limits.RequestBodyMinimumDataRate = - new MinimumDataRate(rate: 100, gracePeriod: TimeSpan.Zero); + _frameConnectionContext.ServiceContext.ServerOptions.Limits.MinRequestBodyDataRate = + new MinDataRate(bytesPerSecond: 100, gracePeriod: TimeSpan.FromSeconds(2)); _frameConnectionContext.ServiceContext.SystemClock = systemClock; var mockLogger = new Mock(); @@ -316,9 +324,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests _frameConnection.StartTimingReads(); - // Tick at 1s, expected counted time is 1s, expected data rate is 100 bytes/second - systemClock.UtcNow += TimeSpan.FromSeconds(1); - _frameConnection.BytesRead(100); + // Tick at 2s, expected counted time is 2s, expected data rate is 100 bytes/second + systemClock.UtcNow += TimeSpan.FromSeconds(2); + _frameConnection.BytesRead(200); _frameConnection.Tick(systemClock.UtcNow); // Not timed out @@ -327,15 +335,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests logger => logger.RequestBodyMininumDataRateNotSatisfied(It.IsAny(), It.IsAny(), It.IsAny()), Times.Never); - // Pause at 1.25s + // Pause at 2.25s systemClock.UtcNow += TimeSpan.FromSeconds(0.25); _frameConnection.PauseTimingReads(); - // Resume at 1.5s + // Resume at 2.5s systemClock.UtcNow += TimeSpan.FromSeconds(0.25); _frameConnection.ResumeTimingReads(); - // Tick at 2s, expected counted time is 2s, expected data rate is 100 bytes/second + // Tick at 3s, expected counted time is 3s, expected data rate is 100 bytes/second systemClock.UtcNow += TimeSpan.FromSeconds(0.5); _frameConnection.BytesRead(100); _frameConnection.Tick(systemClock.UtcNow); @@ -346,7 +354,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests logger => logger.RequestBodyMininumDataRateNotSatisfied(It.IsAny(), It.IsAny(), It.IsAny()), Times.Never); - // Tick at 3s, expected counted time is 3s, expected data rate drops below 100 bytes/second + // Tick at 4s, expected counted time is 4s, expected data rate drops below 100 bytes/second systemClock.UtcNow += TimeSpan.FromSeconds(1); _frameConnection.Tick(systemClock.UtcNow); diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameTests.cs index 72105a2185..bd368df0c6 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameTests.cs @@ -141,13 +141,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests } [Fact] - public void ResetResetsRequestBodyMinimumDataRate() + public void ResetResetsMinRequestBodyDataRate() { - _frame.RequestBodyMinimumDataRate = new MinimumDataRate(rate: 1, gracePeriod: TimeSpan.Zero); + _frame.MinRequestBodyDataRate = new MinDataRate(bytesPerSecond: 1, gracePeriod: TimeSpan.MaxValue); _frame.Reset(); - Assert.Equal(_serviceContext.ServerOptions.Limits.RequestBodyMinimumDataRate, _frame.RequestBodyMinimumDataRate); + Assert.Equal(_serviceContext.ServerOptions.Limits.MinRequestBodyDataRate, _frame.MinRequestBodyDataRate); } [Fact] @@ -254,12 +254,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests } [Theory] - [MemberData(nameof(RequestBodyMinimumDataRateData))] - public void ConfiguringRequestBodyMinimumDataRateFeatureSetsRequestBodyMinimumDateRate(MinimumDataRate minimumDataRate) + [MemberData(nameof(MinRequestBodyDataRateData))] + public void ConfiguringIHttpMinRequestBodyDataRateFeatureSetsMinRequestBodyDataRate(MinDataRate minDataRate) { - ((IFeatureCollection)_frame).Get().MinimumDataRate = minimumDataRate; + ((IFeatureCollection)_frame).Get().MinDataRate = minDataRate; - Assert.Same(minimumDataRate, _frame.RequestBodyMinimumDataRate); + Assert.Same(minDataRate, _frame.MinRequestBodyDataRate); } [Fact] @@ -878,10 +878,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests TimeSpan.Zero }; - public static TheoryData RequestBodyMinimumDataRateData => new TheoryData + public static TheoryData MinRequestBodyDataRateData => new TheoryData { null, - new MinimumDataRate(rate: 1, gracePeriod: TimeSpan.Zero) + new MinDataRate(bytesPerSecond: 1, gracePeriod: TimeSpan.MaxValue) }; private class RequestHeadersWrapper : IHeaderDictionary diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/HeartbeatTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/HeartbeatTests.cs index 1101f56ef0..6cd3b27000 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/HeartbeatTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/HeartbeatTests.cs @@ -15,6 +15,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests { public class HeartbeatTests { + [Fact] + public void HeartbeatIntervalIsOneSecond() + { + Assert.Equal(TimeSpan.FromSeconds(1), Heartbeat.Interval); + } + [Fact] public void BlockedHeartbeatDoesntCauseOverlapsAndIsLoggedAsError() { diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/KestrelServerLimitsTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/KestrelServerLimitsTests.cs index 914ceeff11..60c532c545 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/KestrelServerLimitsTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/KestrelServerLimitsTests.cs @@ -293,11 +293,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests } [Fact] - public void RequestBodyMinimumDataRateDefault() + public void MinRequestBodyDataRateDefault() { - Assert.NotNull(new KestrelServerLimits().RequestBodyMinimumDataRate); - Assert.Equal(1, new KestrelServerLimits().RequestBodyMinimumDataRate.Rate); - Assert.Equal(TimeSpan.FromSeconds(5), new KestrelServerLimits().RequestBodyMinimumDataRate.GracePeriod); + Assert.NotNull(new KestrelServerLimits().MinRequestBodyDataRate); + Assert.Equal(1, new KestrelServerLimits().MinRequestBodyDataRate.BytesPerSecond); + Assert.Equal(TimeSpan.FromSeconds(5), new KestrelServerLimits().MinRequestBodyDataRate.GracePeriod); } public static TheoryData TimeoutValidData => new TheoryData diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/MinimumDataRateTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/MinDataRateTests.cs similarity index 55% rename from test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/MinimumDataRateTests.cs rename to test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/MinDataRateTests.cs index 79660bf799..bd21c01f6d 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/MinimumDataRateTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/MinDataRateTests.cs @@ -2,60 +2,62 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using Microsoft.AspNetCore.Server.Kestrel.Core.Features; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; using Xunit; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests { - public class MinimumDataRateTests + public class MinDataRateTests { [Theory] + [InlineData(0)] [InlineData(double.Epsilon)] [InlineData(double.MaxValue)] - public void RateValid(double value) + public void BytesPerSecondValid(double value) { - Assert.Equal(value, new MinimumDataRate(rate: value, gracePeriod: TimeSpan.Zero).Rate); + Assert.Equal(value, new MinDataRate(bytesPerSecond: value, gracePeriod: TimeSpan.MaxValue).BytesPerSecond); } [Theory] [InlineData(double.MinValue)] - [InlineData(0)] - public void RateInvalid(double value) + [InlineData(-double.Epsilon)] + public void BytesPerSecondInvalid(double value) { - var exception = Assert.Throws(() => new MinimumDataRate(rate: value, gracePeriod: TimeSpan.Zero)); + var exception = Assert.Throws(() => new MinDataRate(bytesPerSecond: value, gracePeriod: TimeSpan.MaxValue)); - Assert.Equal("rate", exception.ParamName); - Assert.StartsWith(CoreStrings.PositiveNumberRequired, exception.Message); + Assert.Equal("bytesPerSecond", exception.ParamName); + Assert.StartsWith(CoreStrings.NonNegativeNumberRequired, exception.Message); } [Theory] [MemberData(nameof(GracePeriodValidData))] public void GracePeriodValid(TimeSpan value) { - Assert.Equal(value, new MinimumDataRate(rate: 1, gracePeriod: value).GracePeriod); + Assert.Equal(value, new MinDataRate(bytesPerSecond: 1, gracePeriod: value).GracePeriod); } [Theory] [MemberData(nameof(GracePeriodInvalidData))] public void GracePeriodInvalid(TimeSpan value) { - var exception = Assert.Throws(() => new MinimumDataRate(rate: 1, gracePeriod: value)); + var exception = Assert.Throws(() => new MinDataRate(bytesPerSecond: 1, gracePeriod: value)); Assert.Equal("gracePeriod", exception.ParamName); - Assert.StartsWith(CoreStrings.NonNegativeTimeSpanRequired, exception.Message); + Assert.StartsWith(CoreStrings.FormatMinimumGracePeriodRequired(Heartbeat.Interval.TotalSeconds), exception.Message); } public static TheoryData GracePeriodValidData => new TheoryData { - TimeSpan.Zero, - TimeSpan.FromTicks(1), + Heartbeat.Interval + TimeSpan.FromTicks(1), TimeSpan.MaxValue }; public static TheoryData GracePeriodInvalidData => new TheoryData { TimeSpan.MinValue, - TimeSpan.FromTicks(-1) + TimeSpan.FromTicks(-1), + TimeSpan.Zero, + Heartbeat.Interval }; } } diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/KeepAliveTimeoutTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/KeepAliveTimeoutTests.cs index 3f82032104..b9a7d049b1 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/KeepAliveTimeoutTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/KeepAliveTimeoutTests.cs @@ -197,7 +197,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests Limits = { KeepAliveTimeout = KeepAliveTimeout, - RequestBodyMinimumDataRate = null + MinRequestBodyDataRate = null } } }); diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/MaxRequestBufferSizeTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/MaxRequestBufferSizeTests.cs index 1331ccf41e..40536f5d28 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/MaxRequestBufferSizeTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/MaxRequestBufferSizeTests.cs @@ -274,7 +274,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests options.Limits.MaxRequestHeadersTotalSize = (int)maxRequestBufferSize; } - options.Limits.RequestBodyMinimumDataRate = null; + options.Limits.MinRequestBodyDataRate = null; }) .UseContentRoot(Directory.GetCurrentDirectory()) .Configure(app => app.Run(async context => diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestBodyTimeoutTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestBodyTimeoutTests.cs index 2351a696c8..073b646e2d 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestBodyTimeoutTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestBodyTimeoutTests.cs @@ -17,9 +17,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests public class RequestBodyTimeoutTests { [Fact] - public async Task RequestTimesOutWhenRequestBodyNotReceivedAtDesiredMinimumRate() + public async Task RequestTimesOutWhenRequestBodyNotReceivedAtSpecifiedMinimumRate() { - var minimumDataRateGracePeriod = TimeSpan.FromSeconds(5); + var gracePeriod = TimeSpan.FromSeconds(5); var systemClock = new MockSystemClock(); var serviceContext = new TestServiceContext { @@ -31,8 +31,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests using (var server = new TestServer(context => { - context.Features.Get().MinimumDataRate = - new MinimumDataRate(rate: 1, gracePeriod: minimumDataRateGracePeriod); + context.Features.Get().MinDataRate = + new MinDataRate(bytesPerSecond: 1, gracePeriod: gracePeriod); appRunningEvent.Set(); return context.Request.Body.ReadAsync(new byte[1], 0, 1); @@ -48,7 +48,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests ""); Assert.True(appRunningEvent.Wait(TimeSpan.FromSeconds(10))); - systemClock.UtcNow += minimumDataRateGracePeriod + TimeSpan.FromSeconds(1); + systemClock.UtcNow += gracePeriod + TimeSpan.FromSeconds(1); await connection.Receive( "HTTP/1.1 408 Request Timeout", @@ -64,7 +64,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } [Fact] - public async Task RequestTimesWhenNotDrainedWithinDrainTimeoutPeriod() + public async Task RequestTimesOutWhenNotDrainedWithinDrainTimeoutPeriod() { // This test requires a real clock since we can't control when the drain timeout is set var systemClock = new SystemClock(); @@ -78,7 +78,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests using (var server = new TestServer(context => { - context.Features.Get().MinimumDataRate = null; + context.Features.Get().MinDataRate = null; appRunningEvent.Set(); return Task.CompletedTask; @@ -112,7 +112,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [Fact] public async Task ConnectionClosedEvenIfAppSwallowsException() { - var minimumDataRateGracePeriod = TimeSpan.FromSeconds(5); + var gracePeriod = TimeSpan.FromSeconds(5); var systemClock = new MockSystemClock(); var serviceContext = new TestServiceContext { @@ -125,8 +125,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests using (var server = new TestServer(async context => { - context.Features.Get().MinimumDataRate = - new MinimumDataRate(rate: 1, gracePeriod: minimumDataRateGracePeriod); + context.Features.Get().MinDataRate = + new MinDataRate(bytesPerSecond: 1, gracePeriod: gracePeriod); appRunningEvent.Set(); @@ -154,7 +154,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests ""); Assert.True(appRunningEvent.Wait(TimeSpan.FromSeconds(10))); - systemClock.UtcNow += minimumDataRateGracePeriod + TimeSpan.FromSeconds(1); + systemClock.UtcNow += gracePeriod + TimeSpan.FromSeconds(1); Assert.True(exceptionSwallowedEvent.Wait(TimeSpan.FromSeconds(10))); await connection.Receive( diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestHeadersTimeoutTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestHeadersTimeoutTests.cs index a97d62f5b0..2520467a72 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestHeadersTimeoutTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestHeadersTimeoutTests.cs @@ -106,7 +106,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests Limits = { RequestHeadersTimeout = RequestHeadersTimeout, - RequestBodyMinimumDataRate = null + MinRequestBodyDataRate = null } } }); diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs index 0ab934384d..c808346744 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs @@ -63,7 +63,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests .UseKestrel(options => { options.Limits.MaxRequestBodySize = contentLength; - options.Limits.RequestBodyMinimumDataRate = null; + options.Limits.MinRequestBodyDataRate = null; }) .UseUrls("http://127.0.0.1:0/") .Configure(app => @@ -1429,7 +1429,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests using (var server = new TestServer(async context => { - context.Features.Get().MinimumDataRate = new MinimumDataRate(rate: double.MaxValue, gracePeriod: TimeSpan.Zero); + context.Features.Get().MinDataRate = + new MinDataRate(bytesPerSecond: double.MaxValue, gracePeriod: Heartbeat.Interval + TimeSpan.FromTicks(1)); using (var stream = await context.Features.Get().UpgradeAsync()) { diff --git a/tools/CodeGenerator/FrameFeatureCollection.cs b/tools/CodeGenerator/FrameFeatureCollection.cs index be4b820fea..636f333854 100644 --- a/tools/CodeGenerator/FrameFeatureCollection.cs +++ b/tools/CodeGenerator/FrameFeatureCollection.cs @@ -47,7 +47,7 @@ namespace CodeGenerator typeof(IHttpWebSocketFeature), typeof(ISessionFeature), typeof(IHttpMaxRequestBodySizeFeature), - typeof(IHttpRequestBodyMinimumDataRateFeature), + typeof(IHttpMinRequestBodyDataRateFeature), }; var rareFeatures = new[] @@ -68,7 +68,7 @@ namespace CodeGenerator typeof(IHttpRequestLifetimeFeature), typeof(IHttpConnectionFeature), typeof(IHttpMaxRequestBodySizeFeature), - typeof(IHttpRequestBodyMinimumDataRateFeature), + typeof(IHttpMinRequestBodyDataRateFeature), }; return $@"// Copyright (c) .NET Foundation. All rights reserved. From 68ba9a9445c9f5a46f7b2efd435bf2f84f8113d5 Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Fri, 30 Jun 2017 12:22:31 -0700 Subject: [PATCH 1333/1662] Avoid torn reads from _frame.MinReadBodyDataRate in FrameConnection.Tick(). --- .../Internal/FrameConnection.cs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnection.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnection.cs index 085716a841..6d053da559 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnection.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnection.cs @@ -283,16 +283,19 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal { if (_readTimingEnabled) { + // Reference in local var to avoid torn reads in case the min rate is changed via IHttpMinRequestBodyDataRateFeature + var minRequestBodyDataRate = _frame.MinRequestBodyDataRate; + _readTimingElapsedTicks += timestamp - _lastTimestamp; - if (_frame.MinRequestBodyDataRate?.BytesPerSecond > 0 && _readTimingElapsedTicks > _frame.MinRequestBodyDataRate.GracePeriod.Ticks) + if (minRequestBodyDataRate?.BytesPerSecond > 0 && _readTimingElapsedTicks > minRequestBodyDataRate.GracePeriod.Ticks) { var elapsedSeconds = (double)_readTimingElapsedTicks / TimeSpan.TicksPerSecond; var rate = Interlocked.Read(ref _readTimingBytesRead) / elapsedSeconds; - if (rate < _frame.MinRequestBodyDataRate.BytesPerSecond && !Debugger.IsAttached) + if (rate < minRequestBodyDataRate.BytesPerSecond && !Debugger.IsAttached) { - Log.RequestBodyMininumDataRateNotSatisfied(_context.ConnectionId, _frame.TraceIdentifier, _frame.MinRequestBodyDataRate.BytesPerSecond); + Log.RequestBodyMininumDataRateNotSatisfied(_context.ConnectionId, _frame.TraceIdentifier, minRequestBodyDataRate.BytesPerSecond); Timeout(); } } From 81c2b57dda19a9a1c85d1b11144edf45327fef28 Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Fri, 30 Jun 2017 14:58:44 -0700 Subject: [PATCH 1334/1662] Increase default request min rate to 240 bytes/second (#1929). --- .../KestrelServerLimits.cs | 6 ++++-- .../KestrelServerLimitsTests.cs | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/KestrelServerLimits.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/KestrelServerLimits.cs index 5eaa4c2c9a..528f78be57 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/KestrelServerLimits.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/KestrelServerLimits.cs @@ -258,8 +258,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core /// This can be overridden per-request via . /// /// - /// Defaults to 1 byte/second with a 5 second grace period. + /// Defaults to 240 bytes/second with a 5 second grace period. /// - public MinDataRate MinRequestBodyDataRate { get; set; } = new MinDataRate(bytesPerSecond: 1, gracePeriod: TimeSpan.FromSeconds(5)); + public MinDataRate MinRequestBodyDataRate { get; set; } = + // Matches the default IIS minBytesPerSecond + new MinDataRate(bytesPerSecond: 240, gracePeriod: TimeSpan.FromSeconds(5)); } } diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/KestrelServerLimitsTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/KestrelServerLimitsTests.cs index 60c532c545..bab86a04e7 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/KestrelServerLimitsTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/KestrelServerLimitsTests.cs @@ -296,7 +296,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests public void MinRequestBodyDataRateDefault() { Assert.NotNull(new KestrelServerLimits().MinRequestBodyDataRate); - Assert.Equal(1, new KestrelServerLimits().MinRequestBodyDataRate.BytesPerSecond); + Assert.Equal(240, new KestrelServerLimits().MinRequestBodyDataRate.BytesPerSecond); Assert.Equal(TimeSpan.FromSeconds(5), new KestrelServerLimits().MinRequestBodyDataRate.GracePeriod); } From 6e45de220561b70e0d8273e9b2738677ec94ca01 Mon Sep 17 00:00:00 2001 From: Aristarkh Zagorodnikov Date: Mon, 3 Jul 2017 07:06:13 +0300 Subject: [PATCH 1335/1662] Improved systemd activation tests (#1930) * Added BASE_PORT envvar for SampleApp to allow for multiple instances to coexist * Moved to systemd-socket-activate for activation tests * Style fixes --- samples/SampleApp/Startup.cs | 15 +++++++-- .../SystemdActivation/Dockerfile | 31 ++++++------------- .../activate-kestrel.service | 7 ----- .../SystemdActivation/activate-kestrel.socket | 9 ------ .../SystemdActivation/docker-entrypoint.sh | 10 ++++++ .../SystemdActivation/docker.sh | 11 +++++-- 6 files changed, 40 insertions(+), 43 deletions(-) delete mode 100644 test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/SystemdActivation/activate-kestrel.service delete mode 100644 test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/SystemdActivation/activate-kestrel.socket create mode 100644 test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/SystemdActivation/docker-entrypoint.sh diff --git a/samples/SampleApp/Startup.cs b/samples/SampleApp/Startup.cs index 53968834de..18b4baacf4 100644 --- a/samples/SampleApp/Startup.cs +++ b/samples/SampleApp/Startup.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Globalization; using System.IO; using System.Net; using System.Threading.Tasks; @@ -9,6 +10,7 @@ using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; +using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Logging; namespace SampleApp @@ -40,6 +42,15 @@ namespace SampleApp Console.WriteLine("Unobserved exception: {0}", e.Exception); }; + var configuration = new ConfigurationBuilder() + .AddEnvironmentVariables() + .Build(); + + if (!ushort.TryParse(configuration["BASE_PORT"], NumberStyles.None, CultureInfo.InvariantCulture, out var basePort)) + { + basePort = 5000; + } + var host = new WebHostBuilder() .ConfigureLogging((_, factory) => { @@ -50,7 +61,7 @@ namespace SampleApp // Run callbacks on the transport thread options.ApplicationSchedulingMode = SchedulingMode.Inline; - options.Listen(IPAddress.Loopback, 5000, listenOptions => + options.Listen(IPAddress.Loopback, basePort, listenOptions => { // Uncomment the following to enable Nagle's algorithm for this endpoint. //listenOptions.NoDelay = false; @@ -58,7 +69,7 @@ namespace SampleApp listenOptions.UseConnectionLogging(); }); - options.Listen(IPAddress.Loopback, 5001, listenOptions => + options.Listen(IPAddress.Loopback, basePort + 1, listenOptions => { listenOptions.UseHttps("testCert.pfx", "testPassword"); listenOptions.UseConnectionLogging(); diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/SystemdActivation/Dockerfile b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/SystemdActivation/Dockerfile index 59b592bd85..8fd99946ee 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/SystemdActivation/Dockerfile +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/SystemdActivation/Dockerfile @@ -3,34 +3,21 @@ FROM microsoft/dotnet-nightly:2.0-runtime-deps # The "container" environment variable is read by systemd. ENV container=docker -# Install and configure systemd which requires dbus for graceful shutdown. +# Install and configure dependencies. RUN ["apt-get", "-o", "Acquire::Check-Valid-Until=false", "update"] -RUN ["apt-get", "install", "-y", "--no-install-recommends", "systemd-sysv"] - -# Set proper systemd default target. -RUN ["systemctl", "set-default", "multi-user.target"] - -# Remove non-vital systemd services. -RUN ["find", "/etc/systemd/system", "/lib/systemd/system", \ - "-path", "*.wants/*", \ - "-not", "-name", "*systemd-journald*", \ - "-not", "-name", "*systemd-tmpfiles*", \ - "-not", "-name", "*systemd-user-sessions*", \ - "-delete"] +RUN ["apt-get", "install", "-y", "--no-install-recommends", "systemd", "socat"] # Copy .NET installation. ADD .dotnet/ /usr/share/dotnet/ RUN ["ln", "-s", "/usr/share/dotnet/dotnet", "/usr/bin/dotnet"] -# Create activate-kestrel.service to launch the "publish" app on new requests to 8080. -EXPOSE 8080 +# Copy "publish" app. ADD publish/ /publish/ -ADD activate-kestrel.service /etc/systemd/system/activate-kestrel.service -ADD activate-kestrel.socket /etc/systemd/system/activate-kestrel.socket -# Automatically start activate-kestrel.socket on boot. -RUN ["systemctl", "enable", "activate-kestrel.socket"] +# Expose target ports. +EXPOSE 8080 8081 8082 -# Launch systemd, with workaround for docker/docker#27202, technique based on comments from docker/docker#9212. -CMD ["/bin/bash", "-c", "exec /sbin/init --log-target=journal 3>&1"] -STOPSIGNAL SIGRTMIN+3 +# Set entrypoint. +COPY ./docker-entrypoint.sh / +RUN chmod +x /docker-entrypoint.sh +ENTRYPOINT ["/docker-entrypoint.sh"] diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/SystemdActivation/activate-kestrel.service b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/SystemdActivation/activate-kestrel.service deleted file mode 100644 index 54cff82383..0000000000 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/SystemdActivation/activate-kestrel.service +++ /dev/null @@ -1,7 +0,0 @@ -[Unit] -Requires=activate-kestrel.socket - -[Service] -ExecStart=/usr/bin/dotnet SampleApp.dll -WorkingDirectory=/publish -NonBlocking=true \ No newline at end of file diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/SystemdActivation/activate-kestrel.socket b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/SystemdActivation/activate-kestrel.socket deleted file mode 100644 index 8b8e48e9c8..0000000000 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/SystemdActivation/activate-kestrel.socket +++ /dev/null @@ -1,9 +0,0 @@ -[Unit] -PartOf=activate-kestrel.service - -[Socket] -ListenStream=8080 -NoDelay=true - -[Install] -WantedBy=multi-user.target diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/SystemdActivation/docker-entrypoint.sh b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/SystemdActivation/docker-entrypoint.sh new file mode 100644 index 0000000000..db0de9d602 --- /dev/null +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/SystemdActivation/docker-entrypoint.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +set -e + +cd /publish +systemd-socket-activate -l 8080 -E BASE_PORT=7000 dotnet SampleApp.dll & +socat TCP-LISTEN:8081,fork TCP-CONNECT:127.0.0.1:7000 & +socat TCP-LISTEN:8082,fork TCP-CONNECT:127.0.0.1:7001 & +trap 'exit 0' SIGTERM +wait diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/SystemdActivation/docker.sh b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/SystemdActivation/docker.sh index 8bef6049d8..cce561474d 100755 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/SystemdActivation/docker.sh +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/SystemdActivation/docker.sh @@ -8,9 +8,14 @@ cp -R ./samples/SampleApp/bin/Debug/netcoreapp2.0/publish/ $scriptDir cp -R ~/.dotnet/ $scriptDir image=$(docker build -qf $scriptDir/Dockerfile $scriptDir) -container=$(docker run -Ptd --privileged $image) +container=$(docker run -Pd $image) -# Try to connect to SampleApp once a second up to 10 times. -for i in {1..10}; do curl $(docker port $container 8080/tcp) && exit 0 || sleep 1; done +# Try to connect to SampleApp once a second up to 10 times via all available ports. +for i in {1..10}; do + curl -f http://$(docker port $container 8080/tcp) \ + && curl -f http://$(docker port $container 8081/tcp) \ + && curl -fk https://$(docker port $container 8082/tcp) \ + && exit 0 || sleep 1; +done exit -1 From e9ffcdb41411758dcc299c63e688b114c200c480 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Mon, 3 Jul 2017 11:07:17 -0700 Subject: [PATCH 1336/1662] Add feature to optionally disallow synchronous IO (#1919) * Allow synchronous IO by default --- .../CoreStrings.resx | 62 +++++---- .../Internal/Http/Frame.FeatureCollection.cs | 7 + .../Internal/Http/Frame.Generated.cs | 16 +++ .../Internal/Http/Frame.cs | 4 +- .../Internal/Http/FrameRequestStream.cs | 18 ++- .../Internal/Http/FrameResponseStream.cs | 12 +- .../Internal/Infrastructure/Streams.cs | 9 +- .../KestrelServerOptions.cs | 9 ++ .../Properties/CoreStrings.Designer.cs | 32 ++++- .../FrameRequestStreamTests.cs | 75 +++++++---- .../FrameResponseStreamTests.cs | 57 ++++++-- .../KestrelServerOptionsTests.cs | 8 ++ .../MessageBodyTests.cs | 45 ++++--- .../StreamsTests.cs | 8 +- .../MaxRequestBufferSizeTests.cs | 2 +- .../RequestTests.cs | 124 ++++++++++++++++++ .../ResponseTests.cs | 114 +++++++++++++++- .../UpgradeTests.cs | 6 +- tools/CodeGenerator/FrameFeatureCollection.cs | 6 +- 19 files changed, 503 insertions(+), 111 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/CoreStrings.resx b/src/Microsoft.AspNetCore.Server.Kestrel.Core/CoreStrings.resx index 13454c5127..16e59e4c3a 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/CoreStrings.resx +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/CoreStrings.resx @@ -1,17 +1,17 @@  - @@ -336,4 +336,10 @@ The request body rate enforcement grace period must be greater than {heartbeatInterval} second. - + + Synchronous operations are disallowed. Call ReadAsync or set AllowSynchronousIO to true instead. + + + Synchronous operations are disallowed. Call WriteAsync or set AllowSynchronousIO to true instead. + + \ No newline at end of file diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.FeatureCollection.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.FeatureCollection.cs index e9737e5b21..cbc30427e5 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.FeatureCollection.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.FeatureCollection.cs @@ -22,6 +22,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http IHttpConnectionFeature, IHttpRequestLifetimeFeature, IHttpRequestIdentifierFeature, + IHttpBodyControlFeature, IHttpMaxRequestBodySizeFeature, IHttpMinRequestBodyDataRateFeature { @@ -205,6 +206,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http set => TraceIdentifier = value; } + bool IHttpBodyControlFeature.AllowSynchronousIO + { + get => AllowSynchronousIO; + set => AllowSynchronousIO = value; + } + bool IHttpMaxRequestBodySizeFeature.IsReadOnly => HasStartedConsumingRequestBody || _wasUpgraded; long? IHttpMaxRequestBodySizeFeature.MaxRequestBodySize diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.Generated.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.Generated.cs index f2b9c90d10..6aba909708 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.Generated.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.Generated.cs @@ -25,6 +25,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http private static readonly Type ISessionFeatureType = typeof(global::Microsoft.AspNetCore.Http.Features.ISessionFeature); private static readonly Type IHttpMaxRequestBodySizeFeatureType = typeof(global::Microsoft.AspNetCore.Http.Features.IHttpMaxRequestBodySizeFeature); private static readonly Type IHttpMinRequestBodyDataRateFeatureType = typeof(global::Microsoft.AspNetCore.Server.Kestrel.Core.Features.IHttpMinRequestBodyDataRateFeature); + private static readonly Type IHttpBodyControlFeatureType = typeof(global::Microsoft.AspNetCore.Http.Features.IHttpBodyControlFeature); private static readonly Type IHttpSendFileFeatureType = typeof(global::Microsoft.AspNetCore.Http.Features.IHttpSendFileFeature); private object _currentIHttpRequestFeature; @@ -44,6 +45,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http private object _currentISessionFeature; private object _currentIHttpMaxRequestBodySizeFeature; private object _currentIHttpMinRequestBodyDataRateFeature; + private object _currentIHttpBodyControlFeature; private object _currentIHttpSendFileFeature; private void FastReset() @@ -56,6 +58,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http _currentIHttpConnectionFeature = this; _currentIHttpMaxRequestBodySizeFeature = this; _currentIHttpMinRequestBodyDataRateFeature = this; + _currentIHttpBodyControlFeature = this; _currentIServiceProvidersFeature = null; _currentIHttpAuthenticationFeature = null; @@ -139,6 +142,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { return _currentIHttpMinRequestBodyDataRateFeature; } + if (key == IHttpBodyControlFeatureType) + { + return _currentIHttpBodyControlFeature; + } if (key == IHttpSendFileFeatureType) { return _currentIHttpSendFileFeature; @@ -235,6 +242,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http _currentIHttpMinRequestBodyDataRateFeature = feature; return; } + if (key == IHttpBodyControlFeatureType) + { + _currentIHttpBodyControlFeature = feature; + return; + } if (key == IHttpSendFileFeatureType) { _currentIHttpSendFileFeature = feature; @@ -313,6 +325,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { yield return new KeyValuePair(IHttpMinRequestBodyDataRateFeatureType, _currentIHttpMinRequestBodyDataRateFeature as global::Microsoft.AspNetCore.Server.Kestrel.Core.Features.IHttpMinRequestBodyDataRateFeature); } + if (_currentIHttpBodyControlFeature != null) + { + yield return new KeyValuePair(IHttpBodyControlFeatureType, _currentIHttpBodyControlFeature as global::Microsoft.AspNetCore.Http.Features.IHttpBodyControlFeature); + } if (_currentIHttpSendFileFeature != null) { yield return new KeyValuePair(IHttpSendFileFeatureType, _currentIHttpSendFileFeature as global::Microsoft.AspNetCore.Http.Features.IHttpSendFileFeature); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.cs index 90171989c3..c9e7ba118b 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.cs @@ -122,6 +122,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http public string ConnectionIdFeature { get; set; } public bool HasStartedConsumingRequestBody { get; set; } public long? MaxRequestBodySize { get; set; } + public bool AllowSynchronousIO { get; set; } /// /// The request id. @@ -305,7 +306,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { if (_frameStreams == null) { - _frameStreams = new Streams(this); + _frameStreams = new Streams(bodyControl: this, frameControl: this); } (RequestBody, ResponseBody) = _frameStreams.Start(messageBody); @@ -329,6 +330,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http HasStartedConsumingRequestBody = false; MaxRequestBodySize = ServerOptions.Limits.MaxRequestBodySize; + AllowSynchronousIO = ServerOptions.AllowSynchronousIO; TraceIdentifier = null; Scheme = null; Method = null; diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameRequestStream.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameRequestStream.cs index 6ae4b1c385..aa2e9de5a7 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameRequestStream.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameRequestStream.cs @@ -7,17 +7,20 @@ using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; +using Microsoft.AspNetCore.Http.Features; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { internal class FrameRequestStream : ReadOnlyStream { + private readonly IHttpBodyControlFeature _bodyControl; private MessageBody _body; private FrameStreamState _state; private Exception _error; - public FrameRequestStream() + public FrameRequestStream(IHttpBodyControlFeature bodyControl) { + _bodyControl = bodyControl; _state = FrameStreamState.Closed; } @@ -34,13 +37,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http public override void Flush() { - // No-op. + throw new NotSupportedException(); } public override Task FlushAsync(CancellationToken cancellationToken) { - // No-op. - return Task.CompletedTask; + throw new NotSupportedException(); } public override long Seek(long offset, SeekOrigin origin) @@ -55,8 +57,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http public override int Read(byte[] buffer, int offset, int count) { - // ValueTask uses .GetAwaiter().GetResult() if necessary - return ReadAsync(buffer, offset, count).Result; + if (!_bodyControl.AllowSynchronousIO) + { + throw new InvalidOperationException(CoreStrings.SynchronousReadsDisallowed); + } + + return ReadAsync(buffer, offset, count).GetAwaiter().GetResult(); } public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback callback, object state) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameResponseStream.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameResponseStream.cs index 3a76f4bf1b..d4c6784b4c 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameResponseStream.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameResponseStream.cs @@ -6,16 +6,19 @@ using System.IO; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; +using Microsoft.AspNetCore.Http.Features; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { internal class FrameResponseStream : WriteOnlyStream { - private IFrameControl _frameControl; + private readonly IHttpBodyControlFeature _bodyControl; + private readonly IFrameControl _frameControl; private FrameStreamState _state; - public FrameResponseStream(IFrameControl frameControl) + public FrameResponseStream(IHttpBodyControlFeature bodyControl, IFrameControl frameControl) { + _bodyControl = bodyControl; _frameControl = frameControl; _state = FrameStreamState.Closed; } @@ -58,6 +61,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http public override void Write(byte[] buffer, int offset, int count) { + if (!_bodyControl.AllowSynchronousIO) + { + throw new InvalidOperationException(CoreStrings.SynchronousWritesDisallowed); + } + WriteAsync(buffer, offset, count, default(CancellationToken)).GetAwaiter().GetResult(); } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/Streams.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/Streams.cs index 994ee2d31c..a7762c6990 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/Streams.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/Streams.cs @@ -3,6 +3,7 @@ using System; using System.IO; +using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure @@ -17,11 +18,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure private readonly FrameRequestStream _emptyRequest; private readonly Stream _upgradeStream; - public Streams(IFrameControl frameControl) + public Streams(IHttpBodyControlFeature bodyControl, IFrameControl frameControl) { - _request = new FrameRequestStream(); - _emptyRequest = new FrameRequestStream(); - _response = new FrameResponseStream(frameControl); + _request = new FrameRequestStream(bodyControl); + _emptyRequest = new FrameRequestStream(bodyControl); + _response = new FrameResponseStream(bodyControl, frameControl); _upgradeableResponse = new WrappingStream(_response); _upgradeStream = new FrameDuplexStream(_request, _response); } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/KestrelServerOptions.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/KestrelServerOptions.cs index b97eecf850..136b983533 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/KestrelServerOptions.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/KestrelServerOptions.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using System.Net; +using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; namespace Microsoft.AspNetCore.Server.Kestrel.Core @@ -35,6 +36,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core /// The default mode is public SchedulingMode ApplicationSchedulingMode { get; set; } = SchedulingMode.Default; + /// + /// Gets or sets a value that controls whether synchronous IO is allowed for the and + /// + /// + /// Defaults to true. + /// + public bool AllowSynchronousIO { get; set; } = true; + /// /// Enables the Listen options callback to resolve and use services registered by the application during startup. /// Typically initialized by UseKestrel()"/>. diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Properties/CoreStrings.Designer.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Properties/CoreStrings.Designer.cs index 5fb571f55b..aa43e6b644 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Properties/CoreStrings.Designer.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Properties/CoreStrings.Designer.cs @@ -1019,7 +1019,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core => GetString("NonNegativeTimeSpanRequired"); /// - /// The request body rate enforcement grace period must be greater than {heartbeatInterval} seconds. + /// The request body rate enforcement grace period must be greater than {heartbeatInterval} second. /// internal static string MinimumGracePeriodRequired { @@ -1027,11 +1027,39 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core } /// - /// The request body rate enforcement grace period must be greater than {heartbeatInterval} seconds. + /// The request body rate enforcement grace period must be greater than {heartbeatInterval} second. /// internal static string FormatMinimumGracePeriodRequired(object heartbeatInterval) => string.Format(CultureInfo.CurrentCulture, GetString("MinimumGracePeriodRequired", "heartbeatInterval"), heartbeatInterval); + /// + /// Synchronous operations are disallowed. Call ReadAsync or set AllowSynchronousIO to true instead. + /// + internal static string SynchronousReadsDisallowed + { + get => GetString("SynchronousReadsDisallowed"); + } + + /// + /// Synchronous operations are disallowed. Call ReadAsync or set AllowSynchronousIO to true instead. + /// + internal static string FormatSynchronousReadsDisallowed() + => GetString("SynchronousReadsDisallowed"); + + /// + /// Synchronous operations are disallowed. Call WriteAsync or set AllowSynchronousIO to true instead. + /// + internal static string SynchronousWritesDisallowed + { + get => GetString("SynchronousWritesDisallowed"); + } + + /// + /// Synchronous operations are disallowed. Call WriteAsync or set AllowSynchronousIO to true instead. + /// + internal static string FormatSynchronousWritesDisallowed() + => GetString("SynchronousWritesDisallowed"); + private static string GetString(string name, params string[] formatterNames) { var value = _resourceManager.GetString(name); diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameRequestStreamTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameRequestStreamTests.cs index 2250523f63..12a1a87c81 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameRequestStreamTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameRequestStreamTests.cs @@ -5,6 +5,7 @@ using System; using System.IO; using System.Threading; using System.Threading.Tasks; +using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; using Moq; using Xunit; @@ -16,49 +17,49 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests [Fact] public void CanReadReturnsTrue() { - var stream = new FrameRequestStream(); + var stream = new FrameRequestStream(Mock.Of()); Assert.True(stream.CanRead); } [Fact] public void CanSeekReturnsFalse() { - var stream = new FrameRequestStream(); + var stream = new FrameRequestStream(Mock.Of()); Assert.False(stream.CanSeek); } [Fact] public void CanWriteReturnsFalse() { - var stream = new FrameRequestStream(); + var stream = new FrameRequestStream(Mock.Of()); Assert.False(stream.CanWrite); } [Fact] public void SeekThrows() { - var stream = new FrameRequestStream(); + var stream = new FrameRequestStream(Mock.Of()); Assert.Throws(() => stream.Seek(0, SeekOrigin.Begin)); } [Fact] public void LengthThrows() { - var stream = new FrameRequestStream(); + var stream = new FrameRequestStream(Mock.Of()); Assert.Throws(() => stream.Length); } [Fact] public void SetLengthThrows() { - var stream = new FrameRequestStream(); + var stream = new FrameRequestStream(Mock.Of()); Assert.Throws(() => stream.SetLength(0)); } [Fact] public void PositionThrows() { - var stream = new FrameRequestStream(); + var stream = new FrameRequestStream(Mock.Of()); Assert.Throws(() => stream.Position); Assert.Throws(() => stream.Position = 0); } @@ -66,21 +67,21 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests [Fact] public void WriteThrows() { - var stream = new FrameRequestStream(); + var stream = new FrameRequestStream(Mock.Of()); Assert.Throws(() => stream.Write(new byte[1], 0, 1)); } [Fact] public void WriteByteThrows() { - var stream = new FrameRequestStream(); + var stream = new FrameRequestStream(Mock.Of()); Assert.Throws(() => stream.WriteByte(0)); } [Fact] public async Task WriteAsyncThrows() { - var stream = new FrameRequestStream(); + var stream = new FrameRequestStream(Mock.Of()); await Assert.ThrowsAsync(() => stream.WriteAsync(new byte[1], 0, 1)); } @@ -88,7 +89,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests [Fact] public void BeginWriteThrows() { - var stream = new FrameRequestStream(); + var stream = new FrameRequestStream(Mock.Of()); Assert.Throws(() => stream.BeginWrite(new byte[1], 0, 1, null, null)); } #elif NETCOREAPP2_0 @@ -97,23 +98,47 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests #endif [Fact] - public void FlushDoesNotThrow() + public void FlushThrows() { - var stream = new FrameRequestStream(); - stream.Flush(); + var stream = new FrameRequestStream(Mock.Of()); + Assert.Throws(() => stream.Flush()); } [Fact] - public async Task FlushAsyncDoesNotThrow() + public async Task FlushAsyncThrows() { - var stream = new FrameRequestStream(); - await stream.FlushAsync(); + var stream = new FrameRequestStream(Mock.Of()); + await Assert.ThrowsAsync(() => stream.FlushAsync()); + } + + [Fact] + public async Task SynchronousReadsThrowIfDisallowedByIHttpBodyControlFeature() + { + var allowSynchronousIO = false; + var mockBodyControl = new Mock(); + mockBodyControl.Setup(m => m.AllowSynchronousIO).Returns(() => allowSynchronousIO); + var mockMessageBody = new Mock((Frame)null); + mockMessageBody.Setup(m => m.ReadAsync(It.IsAny>(), CancellationToken.None)).ReturnsAsync(0); + + var stream = new FrameRequestStream(mockBodyControl.Object); + stream.StartAcceptingReads(mockMessageBody.Object); + + Assert.Equal(0, await stream.ReadAsync(new byte[1], 0, 1)); + + var ioEx = Assert.Throws(() => stream.Read(new byte[1], 0, 1)); + Assert.Equal("Synchronous operations are disallowed. Call ReadAsync or set AllowSynchronousIO to true instead.", ioEx.Message); + + var ioEx2 = Assert.Throws(() => stream.CopyTo(Stream.Null)); + Assert.Equal("Synchronous operations are disallowed. Call ReadAsync or set AllowSynchronousIO to true instead.", ioEx2.Message); + + allowSynchronousIO = true; + Assert.Equal(0, stream.Read(new byte[1], 0, 1)); } [Fact] public void AbortCausesReadToCancel() { - var stream = new FrameRequestStream(); + var stream = new FrameRequestStream(Mock.Of()); stream.StartAcceptingReads(null); stream.Abort(); var task = stream.ReadAsync(new byte[1], 0, 1); @@ -123,7 +148,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests [Fact] public void AbortWithErrorCausesReadToCancel() { - var stream = new FrameRequestStream(); + var stream = new FrameRequestStream(Mock.Of()); stream.StartAcceptingReads(null); var error = new Exception(); stream.Abort(error); @@ -135,7 +160,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests [Fact] public void StopAcceptingReadsCausesReadToThrowObjectDisposedException() { - var stream = new FrameRequestStream(); + var stream = new FrameRequestStream(Mock.Of()); stream.StartAcceptingReads(null); stream.StopAcceptingReads(); Assert.Throws(() => { stream.ReadAsync(new byte[1], 0, 1); }); @@ -144,7 +169,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests [Fact] public void AbortCausesCopyToAsyncToCancel() { - var stream = new FrameRequestStream(); + var stream = new FrameRequestStream(Mock.Of()); stream.StartAcceptingReads(null); stream.Abort(); var task = stream.CopyToAsync(Mock.Of()); @@ -154,7 +179,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests [Fact] public void AbortWithErrorCausesCopyToAsyncToCancel() { - var stream = new FrameRequestStream(); + var stream = new FrameRequestStream(Mock.Of()); stream.StartAcceptingReads(null); var error = new Exception(); stream.Abort(error); @@ -166,7 +191,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests [Fact] public void StopAcceptingReadsCausesCopyToAsyncToThrowObjectDisposedException() { - var stream = new FrameRequestStream(); + var stream = new FrameRequestStream(Mock.Of()); stream.StartAcceptingReads(null); stream.StopAcceptingReads(); Assert.Throws(() => { stream.CopyToAsync(Mock.Of()); }); @@ -175,7 +200,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests [Fact] public void NullDestinationCausesCopyToAsyncToThrowArgumentNullException() { - var stream = new FrameRequestStream(); + var stream = new FrameRequestStream(Mock.Of()); stream.StartAcceptingReads(null); Assert.Throws(() => { stream.CopyToAsync(null); }); } @@ -183,7 +208,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests [Fact] public void ZeroBufferSizeCausesCopyToAsyncToThrowArgumentException() { - var stream = new FrameRequestStream(); + var stream = new FrameRequestStream(Mock.Of()); stream.StartAcceptingReads(null); Assert.Throws(() => { stream.CopyToAsync(Mock.Of(), 0); }); } diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameResponseStreamTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameResponseStreamTests.cs index 12f0e0019c..14cc4ebb7e 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameResponseStreamTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameResponseStreamTests.cs @@ -3,9 +3,12 @@ using System; using System.IO; +using System.Threading; using System.Threading.Tasks; +using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Core.Tests.TestHelpers; +using Moq; using Xunit; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests @@ -15,79 +18,111 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests [Fact] public void CanReadReturnsFalse() { - var stream = new FrameResponseStream(new MockFrameControl()); + var stream = new FrameResponseStream(Mock.Of(), new MockFrameControl()); Assert.False(stream.CanRead); } [Fact] public void CanSeekReturnsFalse() { - var stream = new FrameResponseStream(new MockFrameControl()); + var stream = new FrameResponseStream(Mock.Of(), new MockFrameControl()); Assert.False(stream.CanSeek); } [Fact] public void CanWriteReturnsTrue() { - var stream = new FrameResponseStream(new MockFrameControl()); + var stream = new FrameResponseStream(Mock.Of(), new MockFrameControl()); Assert.True(stream.CanWrite); } [Fact] public void ReadThrows() { - var stream = new FrameResponseStream(new MockFrameControl()); + var stream = new FrameResponseStream(Mock.Of(), new MockFrameControl()); Assert.Throws(() => stream.Read(new byte[1], 0, 1)); } [Fact] public void ReadByteThrows() { - var stream = new FrameResponseStream(new MockFrameControl()); + var stream = new FrameResponseStream(Mock.Of(), new MockFrameControl()); Assert.Throws(() => stream.ReadByte()); } [Fact] public async Task ReadAsyncThrows() { - var stream = new FrameResponseStream(new MockFrameControl()); + var stream = new FrameResponseStream(Mock.Of(), new MockFrameControl()); await Assert.ThrowsAsync(() => stream.ReadAsync(new byte[1], 0, 1)); } [Fact] public void BeginReadThrows() { - var stream = new FrameResponseStream(new MockFrameControl()); + var stream = new FrameResponseStream(Mock.Of(), new MockFrameControl()); Assert.Throws(() => stream.BeginRead(new byte[1], 0, 1, null, null)); } [Fact] public void SeekThrows() { - var stream = new FrameResponseStream(new MockFrameControl()); + var stream = new FrameResponseStream(Mock.Of(), new MockFrameControl()); Assert.Throws(() => stream.Seek(0, SeekOrigin.Begin)); } [Fact] public void LengthThrows() { - var stream = new FrameResponseStream(new MockFrameControl()); + var stream = new FrameResponseStream(Mock.Of(), new MockFrameControl()); Assert.Throws(() => stream.Length); } [Fact] public void SetLengthThrows() { - var stream = new FrameResponseStream(new MockFrameControl()); + var stream = new FrameResponseStream(Mock.Of(), new MockFrameControl()); Assert.Throws(() => stream.SetLength(0)); } [Fact] public void PositionThrows() { - var stream = new FrameResponseStream(new MockFrameControl()); + var stream = new FrameResponseStream(Mock.Of(), new MockFrameControl()); Assert.Throws(() => stream.Position); Assert.Throws(() => stream.Position = 0); } + + [Fact] + public void StopAcceptingWritesCausesWriteToThrowObjectDisposedException() + { + var stream = new FrameResponseStream(Mock.Of(), Mock.Of()); + stream.StartAcceptingWrites(); + stream.StopAcceptingWrites(); + Assert.Throws(() => { stream.WriteAsync(new byte[1], 0, 1); }); + } + + [Fact] + public async Task SynchronousWritesThrowIfDisallowedByIHttpBodyControlFeature() + { + var allowSynchronousIO = false; + var mockBodyControl = new Mock(); + mockBodyControl.Setup(m => m.AllowSynchronousIO).Returns(() => allowSynchronousIO); + var mockFrameControl = new Mock(); + mockFrameControl.Setup(m => m.WriteAsync(It.IsAny>(), CancellationToken.None)).Returns(Task.CompletedTask); + + var stream = new FrameResponseStream(mockBodyControl.Object, mockFrameControl.Object); + stream.StartAcceptingWrites(); + + // WriteAsync doesn't throw. + await stream.WriteAsync(new byte[1], 0, 1); + + var ioEx = Assert.Throws(() => stream.Write(new byte[1], 0, 1)); + Assert.Equal("Synchronous operations are disallowed. Call WriteAsync or set AllowSynchronousIO to true instead.", ioEx.Message); + + allowSynchronousIO = true; + // If IHttpBodyControlFeature.AllowSynchronousIO is true, Write no longer throws. + stream.Write(new byte[1], 0, 1); + } } } diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/KestrelServerOptionsTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/KestrelServerOptionsTests.cs index e0e97f2aac..f0209cbea4 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/KestrelServerOptionsTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/KestrelServerOptionsTests.cs @@ -22,5 +22,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests Assert.True(o1.ListenOptions[0].NoDelay); Assert.False(o1.ListenOptions[1].NoDelay); } + + [Fact] + public void AllowSynchronousIODefaultsToTrue() + { + var options = new KestrelServerOptions(); + + Assert.True(options.AllowSynchronousIO); + } } } \ No newline at end of file diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/MessageBodyTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/MessageBodyTests.cs index 655582dcf1..c6d2283301 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/MessageBodyTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/MessageBodyTests.cs @@ -9,6 +9,7 @@ using System.Text; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; using Microsoft.AspNetCore.Testing; @@ -28,7 +29,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests using (var input = new TestInput()) { var body = MessageBody.For(httpVersion, new FrameRequestHeaders { HeaderContentLength = "5" }, input.Frame); - var stream = new FrameRequestStream(); + var mockBodyControl = new Mock(); + mockBodyControl.Setup(m => m.AllowSynchronousIO).Returns(true); + var stream = new FrameRequestStream(mockBodyControl.Object); stream.StartAcceptingReads(body); input.Add("Hello"); @@ -54,7 +57,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests using (var input = new TestInput()) { var body = MessageBody.For(httpVersion, new FrameRequestHeaders { HeaderContentLength = "5" }, input.Frame); - var stream = new FrameRequestStream(); + var stream = new FrameRequestStream(Mock.Of()); stream.StartAcceptingReads(body); input.Add("Hello"); @@ -78,7 +81,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests using (var input = new TestInput()) { var body = MessageBody.For(HttpVersion.Http11, new FrameRequestHeaders { HeaderTransferEncoding = "chunked" }, input.Frame); - var stream = new FrameRequestStream(); + var mockBodyControl = new Mock(); + mockBodyControl.Setup(m => m.AllowSynchronousIO).Returns(true); + var stream = new FrameRequestStream(mockBodyControl.Object); stream.StartAcceptingReads(body); input.Add("5\r\nHello\r\n"); @@ -104,7 +109,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests using (var input = new TestInput()) { var body = MessageBody.For(HttpVersion.Http11, new FrameRequestHeaders { HeaderTransferEncoding = "chunked" }, input.Frame); - var stream = new FrameRequestStream(); + var stream = new FrameRequestStream(Mock.Of()); stream.StartAcceptingReads(body); input.Add("5\r\nHello\r\n"); @@ -130,7 +135,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests using (var input = new TestInput()) { var body = MessageBody.For(HttpVersion.Http11, new FrameRequestHeaders { HeaderTransferEncoding = "chunked" }, input.Frame); - var stream = new FrameRequestStream(); + var stream = new FrameRequestStream(Mock.Of()); stream.StartAcceptingReads(body); input.Add("5;\r\0"); @@ -155,7 +160,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests using (var input = new TestInput()) { var body = MessageBody.For(HttpVersion.Http11, new FrameRequestHeaders { HeaderTransferEncoding = "chunked" }, input.Frame); - var stream = new FrameRequestStream(); + var stream = new FrameRequestStream(Mock.Of()); stream.StartAcceptingReads(body); input.Add("80000000\r\n"); @@ -176,7 +181,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests using (var input = new TestInput()) { var body = MessageBody.For(HttpVersion.Http11, new FrameRequestHeaders { HeaderTransferEncoding = "chunked" }, input.Frame); - var stream = new FrameRequestStream(); + var stream = new FrameRequestStream(Mock.Of()); stream.StartAcceptingReads(body); input.Add("012345678\r"); @@ -199,7 +204,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests using (var input = new TestInput()) { var body = MessageBody.For(httpVersion, new FrameRequestHeaders { HeaderConnection = "upgrade" }, input.Frame); - var stream = new FrameRequestStream(); + var mockBodyControl = new Mock(); + mockBodyControl.Setup(m => m.AllowSynchronousIO).Returns(true); + var stream = new FrameRequestStream(mockBodyControl.Object); stream.StartAcceptingReads(body); input.Add("Hello"); @@ -224,7 +231,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests using (var input = new TestInput()) { var body = MessageBody.For(httpVersion, new FrameRequestHeaders { HeaderConnection = "upgrade" }, input.Frame); - var stream = new FrameRequestStream(); + var stream = new FrameRequestStream(Mock.Of()); stream.StartAcceptingReads(body); input.Add("Hello"); @@ -249,7 +256,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests using (var input = new TestInput()) { var body = MessageBody.For(httpVersion, new FrameRequestHeaders(), input.Frame); - var stream = new FrameRequestStream(); + var mockBodyControl = new Mock(); + mockBodyControl.Setup(m => m.AllowSynchronousIO).Returns(true); + var stream = new FrameRequestStream(mockBodyControl.Object); stream.StartAcceptingReads(body); input.Add("Hello"); @@ -269,7 +278,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests using (var input = new TestInput()) { var body = MessageBody.For(httpVersion, new FrameRequestHeaders(), input.Frame); - var stream = new FrameRequestStream(); + var stream = new FrameRequestStream(Mock.Of()); stream.StartAcceptingReads(body); input.Add("Hello"); @@ -287,7 +296,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests using (var input = new TestInput()) { var body = MessageBody.For(HttpVersion.Http10, new FrameRequestHeaders { HeaderContentLength = "8197" }, input.Frame); - var stream = new FrameRequestStream(); + var stream = new FrameRequestStream(Mock.Of()); stream.StartAcceptingReads(body); // Input needs to be greater than 4032 bytes to allocate a block not backed by a slab. @@ -479,13 +488,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests using (var input = new TestInput()) { var body = MessageBody.For(HttpVersion.Http11, new FrameRequestHeaders { HeaderConnection = headerConnection }, input.Frame); - var stream = new FrameRequestStream(); + var stream = new FrameRequestStream(Mock.Of()); stream.StartAcceptingReads(body); input.Add("Hello"); var buffer = new byte[1024]; - Assert.Equal(5, stream.Read(buffer, 0, buffer.Length)); + Assert.Equal(5, await stream.ReadAsync(buffer, 0, buffer.Length)); AssertASCII("Hello", new ArraySegment(buffer, 0, 5)); input.Fin(); @@ -500,7 +509,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests using (var input = new TestInput()) { var body = MessageBody.For(HttpVersion.Http11, new FrameRequestHeaders { HeaderContentLength = "2" }, input.Frame); - var stream = new FrameRequestStream(); + var stream = new FrameRequestStream(Mock.Of()); stream.StartAcceptingReads(body); // Add some input and consume it to ensure PumpAsync is running @@ -523,7 +532,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests using (var input = new TestInput()) { var body = MessageBody.For(HttpVersion.Http11, new FrameRequestHeaders { HeaderContentLength = "2" }, input.Frame); - var stream = new FrameRequestStream(); + var stream = new FrameRequestStream(Mock.Of()); stream.StartAcceptingReads(body); // Add some input and consume it to ensure PumpAsync is running @@ -642,7 +651,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests input.Frame.TraceIdentifier = "RequestId"; var body = MessageBody.For(HttpVersion.Http11, new FrameRequestHeaders { HeaderContentLength = "2" }, input.Frame); - var stream = new FrameRequestStream(); + var stream = new FrameRequestStream(Mock.Of()); stream.StartAcceptingReads(body); // Add some input and consume it to ensure PumpAsync is running @@ -672,7 +681,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests input.Frame.TraceIdentifier = "RequestId"; var body = MessageBody.For(HttpVersion.Http11, new FrameRequestHeaders { HeaderContentLength = "2" }, input.Frame); - var stream = new FrameRequestStream(); + var stream = new FrameRequestStream(Mock.Of()); stream.StartAcceptingReads(body); // Add some input and consume it to ensure PumpAsync is running diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/StreamsTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/StreamsTests.cs index 6a7b108228..b2657bc60a 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/StreamsTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/StreamsTests.cs @@ -4,9 +4,11 @@ using System; using System.Threading; using System.Threading.Tasks; +using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; +using Microsoft.AspNetCore.Testing; using Moq; using Xunit; @@ -17,7 +19,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests [Fact] public async Task StreamsThrowAfterAbort() { - var streams = new Streams(Mock.Of()); + var streams = new Streams(Mock.Of(), Mock.Of()); var (request, response) = streams.Start(new MockMessageBody()); var ex = new Exception("My error"); @@ -31,7 +33,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests [Fact] public async Task StreamsThrowOnAbortAfterUpgrade() { - var streams = new Streams(Mock.Of()); + var streams = new Streams(Mock.Of(), Mock.Of()); var (request, response) = streams.Start(new MockMessageBody(upgradeable: true)); var upgrade = streams.Upgrade(); @@ -53,7 +55,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests [Fact] public async Task StreamsThrowOnUpgradeAfterAbort() { - var streams = new Streams(Mock.Of()); + var streams = new Streams(Mock.Of(), Mock.Of()); var (request, response) = streams.Start(new MockMessageBody(upgradeable: true)); var ex = new Exception("My error"); diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/MaxRequestBufferSizeTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/MaxRequestBufferSizeTests.cs index 40536f5d28..6b3d66de1a 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/MaxRequestBufferSizeTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/MaxRequestBufferSizeTests.cs @@ -291,7 +291,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests await clientFinishedSendingRequestBody.Task.TimeoutAfter(TimeSpan.FromSeconds(120)); // Verify client didn't send extra bytes - if (context.Request.Body.ReadByte() != -1) + if (await context.Request.Body.ReadAsync(new byte[1], 0, 1) != 0) { context.Response.StatusCode = StatusCodes.Status500InternalServerError; await context.Response.WriteAsync("Client sent more bytes than expectedBody.Length"); diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs index c808346744..a130aadde3 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs @@ -1480,6 +1480,130 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } } + [Fact] + public async Task SynchronousReadsAllowedByDefault() + { + var firstRequest = true; + + using (var server = new TestServer(async context => + { + var bodyControlFeature = context.Features.Get(); + Assert.True(bodyControlFeature.AllowSynchronousIO); + + var buffer = new byte[6]; + var offset = 0; + + // The request body is 5 bytes long. The 6th byte (buffer[5]) is only used for writing the response body. + buffer[5] = (byte)(firstRequest ? '1' : '2'); + + if (firstRequest) + { + while (offset < 5) + { + offset += context.Request.Body.Read(buffer, offset, 5 - offset); + } + + firstRequest = false; + } + else + { + bodyControlFeature.AllowSynchronousIO = false; + + // Synchronous reads now throw. + var ioEx = Assert.Throws(() => context.Request.Body.Read(new byte[1], 0, 1)); + Assert.Equal("Synchronous operations are disallowed. Call ReadAsync or set AllowSynchronousIO to true instead.", ioEx.Message); + + var ioEx2 = Assert.Throws(() => context.Request.Body.CopyTo(Stream.Null)); + Assert.Equal("Synchronous operations are disallowed. Call ReadAsync or set AllowSynchronousIO to true instead.", ioEx2.Message); + + while (offset < 5) + { + offset += await context.Request.Body.ReadAsync(buffer, offset, 5 - offset); + } + } + + Assert.Equal(0, await context.Request.Body.ReadAsync(new byte[1], 0, 1)); + Assert.Equal("Hello", Encoding.ASCII.GetString(buffer, 0, 5)); + + context.Response.ContentLength = 6; + await context.Response.Body.WriteAsync(buffer, 0, 6); + })) + { + using (var connection = server.CreateConnection()) + { + await connection.Send( + "POST / HTTP/1.1", + "Host:", + "Content-Length: 5", + "", + "HelloPOST / HTTP/1.1", + "Host:", + "Content-Length: 5", + "", + "Hello"); + await connection.Receive( + "HTTP/1.1 200 OK", + $"Date: {server.Context.DateHeaderValue}", + "Content-Length: 6", + "", + "Hello1HTTP/1.1 200 OK", + $"Date: {server.Context.DateHeaderValue}", + "Content-Length: 6", + "", + "Hello2"); + } + } + } + + [Fact] + public async Task SynchronousReadsCanBeDisallowedGlobally() + { + var testContext = new TestServiceContext + { + ServerOptions = { AllowSynchronousIO = false } + }; + + using (var server = new TestServer(async context => + { + var bodyControlFeature = context.Features.Get(); + Assert.False(bodyControlFeature.AllowSynchronousIO); + + // Synchronous reads now throw. + var ioEx = Assert.Throws(() => context.Request.Body.Read(new byte[1], 0, 1)); + Assert.Equal("Synchronous operations are disallowed. Call ReadAsync or set AllowSynchronousIO to true instead.", ioEx.Message); + + var ioEx2 = Assert.Throws(() => context.Request.Body.CopyTo(Stream.Null)); + Assert.Equal("Synchronous operations are disallowed. Call ReadAsync or set AllowSynchronousIO to true instead.", ioEx2.Message); + + var buffer = new byte[5]; + var offset = 0; + while (offset < 5) + { + offset += await context.Request.Body.ReadAsync(buffer, offset, 5 - offset); + } + + Assert.Equal(0, await context.Request.Body.ReadAsync(new byte[1], 0, 1)); + Assert.Equal("Hello", Encoding.ASCII.GetString(buffer)); + }, testContext)) + { + using (var connection = server.CreateConnection()) + { + await connection.Send( + "POST / HTTP/1.1", + "Host:", + "Content-Length: 5", + "", + "Hello"); + await connection.Receive( + "HTTP/1.1 200 OK", + $"Date: {server.Context.DateHeaderValue}", + "Content-Length: 0", + "", + ""); + } + } + } + private async Task TestRemoteIPAddress(string registerAddress, string requestAddress, string expectAddress) { var builder = new WebHostBuilder() diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs index 155a1dac95..f43a1e5c2b 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs @@ -508,7 +508,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests public async Task ThrowsAndClosesConnectionWhenAppWritesMoreThanContentLengthWrite() { var testLogger = new TestApplicationErrorLogger(); - var serviceContext = new TestServiceContext { Log = new TestKestrelTrace(testLogger) }; + var serviceContext = new TestServiceContext + { + Log = new TestKestrelTrace(testLogger), + ServerOptions = { AllowSynchronousIO = true } + }; using (var server = new TestServer(httpContext => { @@ -536,7 +540,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } } - var logMessage = Assert.Single(testLogger.Messages, message => message.LogLevel == LogLevel.Error); Assert.Equal( @@ -584,7 +587,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests public async Task InternalServerErrorAndConnectionClosedOnWriteWithMoreThanContentLengthAndResponseNotStarted() { var testLogger = new TestApplicationErrorLogger(); - var serviceContext = new TestServiceContext { Log = new TestKestrelTrace(testLogger) }; + var serviceContext = new TestServiceContext + { + Log = new TestKestrelTrace(testLogger), + ServerOptions = { AllowSynchronousIO = true } + }; using (var server = new TestServer(httpContext => { @@ -966,6 +973,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests public async Task HeadResponseBodyNotWrittenWithSyncWrite() { var flushed = new SemaphoreSlim(0, 1); + var serviceContext = new TestServiceContext { ServerOptions = { AllowSynchronousIO = true } }; using (var server = new TestServer(httpContext => { @@ -973,7 +981,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests httpContext.Response.Body.Write(Encoding.ASCII.GetBytes("hello, world"), 0, 12); flushed.Wait(); return Task.CompletedTask; - })) + }, serviceContext)) { using (var connection = server.CreateConnection()) { @@ -1248,6 +1256,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [Fact] public async Task FirstWriteVerifiedAfterOnStarting() { + var serviceContext = new TestServiceContext { ServerOptions = { AllowSynchronousIO = true } }; + using (var server = new TestServer(httpContext => { httpContext.Response.OnStarting(() => @@ -1263,7 +1273,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests // If OnStarting is not run before verifying writes, an error response will be sent. httpContext.Response.Body.Write(response, 0, response.Length); return Task.CompletedTask; - })) + }, serviceContext)) { using (var connection = server.CreateConnection()) { @@ -1289,6 +1299,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [Fact] public async Task SubsequentWriteVerifiedAfterOnStarting() { + var serviceContext = new TestServiceContext { ServerOptions = { AllowSynchronousIO = true } }; + using (var server = new TestServer(httpContext => { httpContext.Response.OnStarting(() => @@ -1305,7 +1317,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests httpContext.Response.Body.Write(response, 0, response.Length / 2); httpContext.Response.Body.Write(response, response.Length / 2, response.Length - response.Length / 2); return Task.CompletedTask; - })) + }, serviceContext)) { using (var connection = server.CreateConnection()) { @@ -2335,6 +2347,96 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests Assert.Equal(2, callOrder.Pop()); } + + [Fact] + public async Task SynchronousWritesAllowedByDefault() + { + var firstRequest = true; + + using (var server = new TestServer(async context => + { + var bodyControlFeature = context.Features.Get(); + Assert.True(bodyControlFeature.AllowSynchronousIO); + + context.Response.ContentLength = 6; + + if (firstRequest) + { + context.Response.Body.Write(Encoding.ASCII.GetBytes("Hello1"), 0, 6); + firstRequest = false; + } + else + { + bodyControlFeature.AllowSynchronousIO = false; + + // Synchronous writes now throw. + var ioEx = Assert.Throws(() => context.Response.Body.Write(Encoding.ASCII.GetBytes("What!?"), 0, 6)); + Assert.Equal("Synchronous operations are disallowed. Call WriteAsync or set AllowSynchronousIO to true instead.", ioEx.Message); + + await context.Response.Body.WriteAsync(Encoding.ASCII.GetBytes("Hello2"), 0, 6); + } + })) + { + using (var connection = server.CreateConnection()) + { + await connection.SendEmptyGet(); + await connection.Receive( + "HTTP/1.1 200 OK", + $"Date: {server.Context.DateHeaderValue}", + "Content-Length: 6", + "", + "Hello1"); + + await connection.SendEmptyGet(); + await connection.Receive( + "HTTP/1.1 200 OK", + $"Date: {server.Context.DateHeaderValue}", + "Content-Length: 6", + "", + "Hello2"); + } + } + } + + [Fact] + public async Task SynchronousWritesCanBeDisallowedGlobally() + { + var testContext = new TestServiceContext + { + ServerOptions = { AllowSynchronousIO = false } + }; + + using (var server = new TestServer(context => + { + var bodyControlFeature = context.Features.Get(); + Assert.False(bodyControlFeature.AllowSynchronousIO); + + context.Response.ContentLength = 6; + + // Synchronous writes now throw. + var ioEx = Assert.Throws(() => context.Response.Body.Write(Encoding.ASCII.GetBytes("What!?"), 0, 6)); + Assert.Equal("Synchronous operations are disallowed. Call WriteAsync or set AllowSynchronousIO to true instead.", ioEx.Message); + + return context.Response.Body.WriteAsync(Encoding.ASCII.GetBytes("Hello!"), 0, 6); + }, testContext)) + { + using (var connection = server.CreateConnection()) + { + await connection.Send( + "GET / HTTP/1.1", + "Host:", + "", + ""); + await connection.Receive( + "HTTP/1.1 200 OK", + $"Date: {server.Context.DateHeaderValue}", + "Content-Length: 6", + "", + "Hello!"); + } + } + } + public static TheoryData NullHeaderData { get diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/UpgradeTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/UpgradeTests.cs index 5fa497dd0e..8a24951173 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/UpgradeTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/UpgradeTests.cs @@ -32,12 +32,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests var feature = context.Features.Get(); var stream = await feature.UpgradeAsync(); - var ex = Assert.Throws(() => context.Response.Body.WriteByte((byte)' ')); + var ex = await Assert.ThrowsAsync(() => context.Response.Body.WriteAsync(new byte[1], 0, 1)); Assert.Equal(CoreStrings.ResponseStreamWasUpgraded, ex.Message); using (var writer = new StreamWriter(stream)) { - writer.WriteLine("New protocol data"); + await writer.WriteLineAsync("New protocol data"); + await writer.FlushAsync(); } upgrade.TrySetResult(true); @@ -82,6 +83,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests var line = await reader.ReadLineAsync(); Assert.Equal(send, line); await writer.WriteLineAsync(recv); + await writer.FlushAsync(); } upgrade.TrySetResult(true); diff --git a/tools/CodeGenerator/FrameFeatureCollection.cs b/tools/CodeGenerator/FrameFeatureCollection.cs index 636f333854..5d5f83c11a 100644 --- a/tools/CodeGenerator/FrameFeatureCollection.cs +++ b/tools/CodeGenerator/FrameFeatureCollection.cs @@ -28,14 +28,14 @@ namespace CodeGenerator typeof(IHttpRequestIdentifierFeature), typeof(IServiceProvidersFeature), typeof(IHttpRequestLifetimeFeature), - typeof(IHttpConnectionFeature) + typeof(IHttpConnectionFeature), }; var commonFeatures = new[] { typeof(IHttpAuthenticationFeature), typeof(IQueryFeature), - typeof(IFormFeature) + typeof(IFormFeature), }; var sometimesFeatures = new[] @@ -48,6 +48,7 @@ namespace CodeGenerator typeof(ISessionFeature), typeof(IHttpMaxRequestBodySizeFeature), typeof(IHttpMinRequestBodyDataRateFeature), + typeof(IHttpBodyControlFeature), }; var rareFeatures = new[] @@ -69,6 +70,7 @@ namespace CodeGenerator typeof(IHttpConnectionFeature), typeof(IHttpMaxRequestBodySizeFeature), typeof(IHttpMinRequestBodyDataRateFeature), + typeof(IHttpBodyControlFeature), }; return $@"// Copyright (c) .NET Foundation. All rights reserved. From 00d17dea79284a7e3d43be07247e0ab04ed4b932 Mon Sep 17 00:00:00 2001 From: Aristarkh Zagorodnikov Date: Mon, 3 Jul 2017 21:11:23 +0300 Subject: [PATCH 1337/1662] Domain socket handles (#1922) * UvPipeHandle.Open(IntPtr) and underlying interop * LibuvConstants.ENOTSUP * IEndpointInformation.HandleType along with ListenOptions extra ctor and handle type re-specification * Exception-based auto-detection of socket type in Listener, accept socket creation support for detected handle types in ListenerContext * Added systemd Unix socket activation tests --- .../ListenOptions.cs | 43 ++++++ .../Internal/FileHandleType.cs | 15 ++ .../Internal/IEndPointInformation.cs | 7 + .../Internal/LibuvConstants.cs | 14 ++ .../Internal/Listener.cs | 132 ++++++++++++------ .../Internal/ListenerContext.cs | 62 ++++++-- .../Internal/Networking/LibuvFunctions.cs | 11 ++ .../Internal/Networking/UvPipeHandle.cs | 5 + .../SystemdActivation/Dockerfile | 2 +- .../SystemdActivation/docker-entrypoint.sh | 4 + .../SystemdActivation/docker.sh | 3 + 11 files changed, 248 insertions(+), 50 deletions(-) create mode 100644 src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/Internal/FileHandleType.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/ListenOptions.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/ListenOptions.cs index 5508b46afe..46bae7fba3 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/ListenOptions.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/ListenOptions.cs @@ -16,6 +16,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core /// public class ListenOptions : IEndPointInformation { + private FileHandleType _handleType; + internal ListenOptions(IPEndPoint endPoint) { Type = ListenType.IPEndPoint; @@ -29,9 +31,24 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core } internal ListenOptions(ulong fileHandle) + : this(fileHandle, FileHandleType.Auto) + { + } + + internal ListenOptions(ulong fileHandle, FileHandleType handleType) { Type = ListenType.FileHandle; FileHandle = fileHandle; + switch (handleType) + { + case FileHandleType.Auto: + case FileHandleType.Tcp: + case FileHandleType.Pipe: + _handleType = handleType; + break; + default: + throw new NotSupportedException(); + } } /// @@ -39,6 +56,32 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core /// public ListenType Type { get; } + public FileHandleType HandleType + { + get => _handleType; + set + { + if (value == _handleType) + { + return; + } + if (Type != ListenType.FileHandle || _handleType != FileHandleType.Auto) + { + throw new InvalidOperationException(); + } + + switch (value) + { + case FileHandleType.Tcp: + case FileHandleType.Pipe: + _handleType = value; + break; + default: + throw new ArgumentException(nameof(HandleType)); + } + } + } + // IPEndPoint is mutable so port 0 can be updated to the bound port. /// /// The to bind to. diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/Internal/FileHandleType.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/Internal/FileHandleType.cs new file mode 100644 index 0000000000..bb70e4ec34 --- /dev/null +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/Internal/FileHandleType.cs @@ -0,0 +1,15 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal +{ + /// + /// Enumerates the types. + /// + public enum FileHandleType + { + Auto, + Tcp, + Pipe + } +} diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/Internal/IEndPointInformation.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/Internal/IEndPointInformation.cs index 7f025ffe23..1b7abfa497 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/Internal/IEndPointInformation.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/Internal/IEndPointInformation.cs @@ -31,6 +31,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal /// ulong FileHandle { get; } + // HandleType is mutable so it can be re-specified later. + /// + /// The type of file descriptor being used. + /// Only set if is . + /// + FileHandleType HandleType { get; set; } + /// /// Set to false to enable Nagle's algorithm for all connections. /// diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvConstants.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvConstants.cs index 70424f7b0c..1e7c8f319d 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvConstants.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvConstants.cs @@ -12,6 +12,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal public const int EOF = -4095; public static readonly int? ECONNRESET = GetECONNRESET(); public static readonly int? EADDRINUSE = GetEADDRINUSE(); + public static readonly int? ENOTSUP = GetENOTSUP(); private static int? GetECONNRESET() { @@ -46,5 +47,18 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal } return null; } + + private static int? GetENOTSUP() + { + if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) + { + return -95; + } + else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) + { + return -45; + } + return null; + } } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Listener.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Listener.cs index a4b6a8d6bb..26c6fba06a 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Listener.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Listener.cs @@ -46,53 +46,103 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal switch (EndPointInformation.Type) { case ListenType.IPEndPoint: - case ListenType.FileHandle: - var socket = new UvTcpHandle(Log); - - try - { - socket.Init(Thread.Loop, Thread.QueueCloseHandle); - socket.NoDelay(EndPointInformation.NoDelay); - - if (EndPointInformation.Type == ListenType.IPEndPoint) - { - socket.Bind(EndPointInformation.IPEndPoint); - - // If requested port was "0", replace with assigned dynamic port. - EndPointInformation.IPEndPoint = socket.GetSockIPEndPoint(); - } - else - { - socket.Open((IntPtr)EndPointInformation.FileHandle); - } - } - catch - { - socket.Dispose(); - throw; - } - - return socket; + return ListenTcp(useFileHandle: false); case ListenType.SocketPath: - var pipe = new UvPipeHandle(Log); - - try - { - pipe.Init(Thread.Loop, Thread.QueueCloseHandle, false); - pipe.Bind(EndPointInformation.SocketPath); - } - catch - { - pipe.Dispose(); - throw; - } - - return pipe; + return ListenPipe(useFileHandle: false); + case ListenType.FileHandle: + return ListenHandle(); default: throw new NotSupportedException(); } } + private UvTcpHandle ListenTcp(bool useFileHandle) + { + var socket = new UvTcpHandle(Log); + + try + { + socket.Init(Thread.Loop, Thread.QueueCloseHandle); + socket.NoDelay(EndPointInformation.NoDelay); + + if (!useFileHandle) + { + socket.Bind(EndPointInformation.IPEndPoint); + + // If requested port was "0", replace with assigned dynamic port. + EndPointInformation.IPEndPoint = socket.GetSockIPEndPoint(); + } + else + { + socket.Open((IntPtr)EndPointInformation.FileHandle); + } + } + catch + { + socket.Dispose(); + throw; + } + + return socket; + } + + private UvPipeHandle ListenPipe(bool useFileHandle) + { + var pipe = new UvPipeHandle(Log); + + try + { + pipe.Init(Thread.Loop, Thread.QueueCloseHandle, false); + + if (!useFileHandle) + { + pipe.Bind(EndPointInformation.SocketPath); + } + else + { + pipe.Open((IntPtr)EndPointInformation.FileHandle); + } + } + catch + { + pipe.Dispose(); + throw; + } + + return pipe; + } + + private UvStreamHandle ListenHandle() + { + switch (EndPointInformation.HandleType) + { + case FileHandleType.Auto: + break; + case FileHandleType.Tcp: + return ListenTcp(useFileHandle: true); + case FileHandleType.Pipe: + return ListenPipe(useFileHandle: true); + default: + throw new NotSupportedException(); + } + + UvStreamHandle handle; + try + { + handle = ListenTcp(useFileHandle: true); + EndPointInformation.HandleType = FileHandleType.Tcp; + return handle; + } + catch (UvException exception) when (exception.StatusCode == LibuvConstants.ENOTSUP) + { + Log.LogDebug(0, exception, "Listener.ListenHandle"); + } + + handle = ListenPipe(useFileHandle: true); + EndPointInformation.HandleType = FileHandleType.Pipe; + return handle; + } + private static void ConnectionCallback(UvStreamHandle stream, int status, UvException error, object state) { var listener = (Listener)state; diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/ListenerContext.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/ListenerContext.cs index 217bac0d12..37ea4eed36 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/ListenerContext.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/ListenerContext.cs @@ -28,18 +28,64 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal switch (EndPointInformation.Type) { case ListenType.IPEndPoint: - case ListenType.FileHandle: - var tcpHandle = new UvTcpHandle(TransportContext.Log); - tcpHandle.Init(Thread.Loop, Thread.QueueCloseHandle); - tcpHandle.NoDelay(EndPointInformation.NoDelay); - return tcpHandle; + return AcceptTcp(); case ListenType.SocketPath: - var pipeHandle = new UvPipeHandle(TransportContext.Log); - pipeHandle.Init(Thread.Loop, Thread.QueueCloseHandle); - return pipeHandle; + return AcceptPipe(); + case ListenType.FileHandle: + return AcceptHandle(); default: throw new InvalidOperationException(); } } + + private UvTcpHandle AcceptTcp() + { + var socket = new UvTcpHandle(TransportContext.Log); + + try + { + socket.Init(Thread.Loop, Thread.QueueCloseHandle); + socket.NoDelay(EndPointInformation.NoDelay); + } + catch + { + socket.Dispose(); + throw; + } + + return socket; + } + + private UvPipeHandle AcceptPipe() + { + var pipe = new UvPipeHandle(TransportContext.Log); + + try + { + pipe.Init(Thread.Loop, Thread.QueueCloseHandle); + } + catch + { + pipe.Dispose(); + throw; + } + + return pipe; + } + + private UvStreamHandle AcceptHandle() + { + switch (EndPointInformation.HandleType) + { + case FileHandleType.Auto: + throw new InvalidOperationException("Cannot accept on a non-specific file handle, listen should be performed first."); + case FileHandleType.Tcp: + return AcceptTcp(); + case FileHandleType.Pipe: + return AcceptPipe(); + default: + throw new NotSupportedException(); + } + } } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/LibuvFunctions.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/LibuvFunctions.cs index 06e7030bef..d5452242e6 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/LibuvFunctions.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/LibuvFunctions.cs @@ -30,6 +30,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networkin _uv_tcp_nodelay = NativeMethods.uv_tcp_nodelay; _uv_pipe_init = NativeMethods.uv_pipe_init; _uv_pipe_bind = NativeMethods.uv_pipe_bind; + _uv_pipe_open = NativeMethods.uv_pipe_open; _uv_listen = NativeMethods.uv_listen; _uv_accept = NativeMethods.uv_accept; _uv_pipe_connect = NativeMethods.uv_pipe_connect; @@ -229,6 +230,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networkin ThrowIfErrored(_uv_pipe_bind(handle, name)); } + protected Func _uv_pipe_open; + public void pipe_open(UvPipeHandle handle, IntPtr hSocket) + { + handle.Validate(); + ThrowIfErrored(_uv_pipe_open(handle, hSocket)); + } + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] public delegate void uv_connection_cb(IntPtr server, int status); protected Func _uv_listen; @@ -534,6 +542,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networkin [DllImport("libuv", CallingConvention = CallingConvention.Cdecl)] public static extern int uv_pipe_bind(UvPipeHandle loop, string name); + [DllImport("libuv", CallingConvention = CallingConvention.Cdecl)] + public static extern int uv_pipe_open(UvPipeHandle handle, IntPtr hSocket); + [DllImport("libuv", CallingConvention = CallingConvention.Cdecl)] public static extern int uv_listen(UvStreamHandle handle, int backlog, uv_connection_cb cb); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvPipeHandle.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvPipeHandle.cs index 338cc1f643..9afdb67712 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvPipeHandle.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvPipeHandle.cs @@ -21,6 +21,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networkin _uv.pipe_init(loop, this, ipc); } + public void Open(IntPtr fileDescriptor) + { + _uv.pipe_open(this, fileDescriptor); + } + public void Bind(string name) { _uv.pipe_bind(this, name); diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/SystemdActivation/Dockerfile b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/SystemdActivation/Dockerfile index 8fd99946ee..5aee5312dd 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/SystemdActivation/Dockerfile +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/SystemdActivation/Dockerfile @@ -15,7 +15,7 @@ RUN ["ln", "-s", "/usr/share/dotnet/dotnet", "/usr/bin/dotnet"] ADD publish/ /publish/ # Expose target ports. -EXPOSE 8080 8081 8082 +EXPOSE 8080 8081 8082 8083 8084 8085 # Set entrypoint. COPY ./docker-entrypoint.sh / diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/SystemdActivation/docker-entrypoint.sh b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/SystemdActivation/docker-entrypoint.sh index db0de9d602..c85c5fe0bd 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/SystemdActivation/docker-entrypoint.sh +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/SystemdActivation/docker-entrypoint.sh @@ -6,5 +6,9 @@ cd /publish systemd-socket-activate -l 8080 -E BASE_PORT=7000 dotnet SampleApp.dll & socat TCP-LISTEN:8081,fork TCP-CONNECT:127.0.0.1:7000 & socat TCP-LISTEN:8082,fork TCP-CONNECT:127.0.0.1:7001 & +systemd-socket-activate -l /tmp/activate-kestrel.sock -E BASE_PORT=7100 dotnet SampleApp.dll & +socat TCP-LISTEN:8083,fork UNIX-CLIENT:/tmp/activate-kestrel.sock & +socat TCP-LISTEN:8084,fork TCP-CONNECT:127.0.0.1:7100 & +socat TCP-LISTEN:8085,fork TCP-CONNECT:127.0.0.1:7101 & trap 'exit 0' SIGTERM wait diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/SystemdActivation/docker.sh b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/SystemdActivation/docker.sh index cce561474d..eec694cdd7 100755 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/SystemdActivation/docker.sh +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/SystemdActivation/docker.sh @@ -15,6 +15,9 @@ for i in {1..10}; do curl -f http://$(docker port $container 8080/tcp) \ && curl -f http://$(docker port $container 8081/tcp) \ && curl -fk https://$(docker port $container 8082/tcp) \ + && curl -f http://$(docker port $container 8083/tcp) \ + && curl -f http://$(docker port $container 8084/tcp) \ + && curl -fk https://$(docker port $container 8085/tcp) \ && exit 0 || sleep 1; done From eea0c6490e1c65d91044b82269a98a790e8b172a Mon Sep 17 00:00:00 2001 From: Nate McMaster Date: Mon, 3 Jul 2017 11:37:23 -0700 Subject: [PATCH 1338/1662] Fix flaky test: ConnectionResetMidRequestIsLoggedAsDebug (#1933) --- ...spNetCore.Server.Kestrel.Core.Tests.csproj | 1 - ...Core.Server.Kestrel.FunctionalTests.csproj | 1 - .../RequestTests.cs | 26 ++++++++++++------- ...erver.Kestrel.Transport.Libuv.Tests.csproj | 1 - 4 files changed, 17 insertions(+), 12 deletions(-) diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/Microsoft.AspNetCore.Server.Kestrel.Core.Tests.csproj b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/Microsoft.AspNetCore.Server.Kestrel.Core.Tests.csproj index fba2976f4e..d4f68d8023 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/Microsoft.AspNetCore.Server.Kestrel.Core.Tests.csproj +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/Microsoft.AspNetCore.Server.Kestrel.Core.Tests.csproj @@ -12,7 +12,6 @@ Remove when fixed. --> true - win7-x64 diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests.csproj b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests.csproj index a7766fba47..e96a61c766 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests.csproj +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests.csproj @@ -12,7 +12,6 @@ Remove when fixed. --> true - win7-x64 diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs index a130aadde3..4fb7a4bc86 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs @@ -28,6 +28,7 @@ using Moq; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using Xunit; +using Xunit.Abstractions; namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { @@ -37,6 +38,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests private const int _connectionResetEventId = 19; private const int _semaphoreWaitTimeout = 2500; + private readonly ITestOutputHelper _output; + + public RequestTests(ITestOutputHelper output) + { + _output = output; + } + public static TheoryData ConnectionAdapterData => new TheoryData { new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0)), @@ -385,6 +393,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { var requestStarted = new SemaphoreSlim(0); var connectionReset = new SemaphoreSlim(0); + var connectionClosing = new SemaphoreSlim(0); var loggedHigherThanDebug = false; var mockLogger = new Mock(); @@ -395,6 +404,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests .Setup(logger => logger.Log(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny>())) .Callback>((logLevel, eventId, state, exception, formatter) => { + _output.WriteLine(logLevel + ": " + formatter(state, exception)); + if (eventId.Id == _connectionResetEventId) { connectionReset.Release(); @@ -417,20 +428,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests using (var server = new TestServer(async context => { requestStarted.Release(); - await context.Request.Body.ReadAsync(new byte[1], 0, 1); + await connectionClosing.WaitAsync(); }, new TestServiceContext(mockLoggerFactory.Object))) { using (var connection = server.CreateConnection()) { - await connection.Send( - "GET / HTTP/1.1", - "Host:", - "", - ""); + await connection.SendEmptyGet(); // Wait until connection is established - Assert.True(await requestStarted.WaitAsync(TimeSpan.FromSeconds(10))); + Assert.True(await requestStarted.WaitAsync(TimeSpan.FromSeconds(30)), "request should have started"); // Force a reset connection.Socket.LingerState = new LingerOption(true, 0); @@ -440,10 +447,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests // This check MUST come before disposing the server, otherwise there's a race where the RST // is still in flight when the connection is aborted, leading to the reset never being received // and therefore not logged. - Assert.True(await connectionReset.WaitAsync(TimeSpan.FromSeconds(10))); + Assert.True(await connectionReset.WaitAsync(TimeSpan.FromSeconds(30)), "Connection reset event should have been logged"); + connectionClosing.Release(); } - Assert.False(loggedHigherThanDebug); + Assert.False(loggedHigherThanDebug, "Logged event should not have been higher than debug."); } [Fact] diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests.csproj b/test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests.csproj index d6e8bf6ba9..a4fa5d8d2b 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests.csproj +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests.csproj @@ -13,7 +13,6 @@ Remove when fixed. --> true - win7-x64 From cf195d36a341f6814e563ca4555e7d7c87ffcb88 Mon Sep 17 00:00:00 2001 From: Pranav K Date: Mon, 3 Jul 2017 14:06:38 -0700 Subject: [PATCH 1339/1662] Update LICENSE.txt text --- LICENSE.txt | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/LICENSE.txt b/LICENSE.txt index 3d50203c08..7b2956ecee 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -1,13 +1,14 @@ -Copyright (c) .NET Foundation. All rights reserved. +Copyright (c) .NET Foundation and Contributors + +All rights reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use -these files except in compliance with the License. You may obtain a copy of the +this file except in compliance with the License. You may obtain a copy of the License at -http://www.apache.org/licenses/LICENSE-2.0 + http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. - From 7d74ba14405947152e267393536f8ee752bd07b1 Mon Sep 17 00:00:00 2001 From: Nate McMaster Date: Thu, 6 Jul 2017 10:38:10 -0700 Subject: [PATCH 1340/1662] React to aspnet/BuildTools#293 [ci skip] --- build/dependencies.props | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/dependencies.props b/build/dependencies.props index a1d51e5e9f..61b110fb9d 100644 --- a/build/dependencies.props +++ b/build/dependencies.props @@ -2,7 +2,7 @@ 2.0.0-* 4.4.0-* - 2.1.0-* + 2.0.1-* 1.10.0 9.0.1 4.7.49 From a262ba12664e5cd21c698bb04ae2afa41e6d1b38 Mon Sep 17 00:00:00 2001 From: Ryan Brandenburg Date: Thu, 6 Jul 2017 12:17:43 -0700 Subject: [PATCH 1341/1662] Set "TreatWarningsAsErrors" before NuGet restore * Ensures our build stays clean of NuGet warnings --- build/common.props | 1 + 1 file changed, 1 insertion(+) diff --git a/build/common.props b/build/common.props index c4cad36e29..2a03e28988 100644 --- a/build/common.props +++ b/build/common.props @@ -10,6 +10,7 @@ true true $(VersionSuffix)-$(BuildNumber) + true From 0e733c8a4242641daff8c52117148da5b3a3efcd Mon Sep 17 00:00:00 2001 From: Pranav K Date: Thu, 6 Jul 2017 15:08:29 -0700 Subject: [PATCH 1342/1662] Update version suffix for 2.0.0 RTM release --- version.props | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version.props b/version.props index 11ac1d7f41..e55a656d79 100644 --- a/version.props +++ b/version.props @@ -2,6 +2,6 @@ 2.0.0 - preview3 + rtm From a4ed948d1ed619c2489091388862eb49041ab200 Mon Sep 17 00:00:00 2001 From: Ryan Brandenburg Date: Thu, 6 Jul 2017 15:14:51 -0700 Subject: [PATCH 1343/1662] Remove NETSTandard.Library.NETFramework --- build/dependencies.props | 1 - samples/LargeResponseApp/LargeResponseApp.csproj | 4 ---- samples/SampleApp/SampleApp.csproj | 4 ---- 3 files changed, 9 deletions(-) diff --git a/build/dependencies.props b/build/dependencies.props index 61b110fb9d..ea2c0becd5 100644 --- a/build/dependencies.props +++ b/build/dependencies.props @@ -7,7 +7,6 @@ 9.0.1 4.7.49 2.0.0-* - 2.0.0-* 2.0.0-* 15.3.0-* 2.3.0-beta2-* diff --git a/samples/LargeResponseApp/LargeResponseApp.csproj b/samples/LargeResponseApp/LargeResponseApp.csproj index 19e6a615fc..1649a43c54 100644 --- a/samples/LargeResponseApp/LargeResponseApp.csproj +++ b/samples/LargeResponseApp/LargeResponseApp.csproj @@ -11,8 +11,4 @@ - - - - diff --git a/samples/SampleApp/SampleApp.csproj b/samples/SampleApp/SampleApp.csproj index e63d766922..fbd339a9ac 100644 --- a/samples/SampleApp/SampleApp.csproj +++ b/samples/SampleApp/SampleApp.csproj @@ -20,8 +20,4 @@ - - - - From bd8a2c8a6255f7fe8f289e72e7bca206245c1fc3 Mon Sep 17 00:00:00 2001 From: Nate McMaster Date: Fri, 7 Jul 2017 10:40:39 -0700 Subject: [PATCH 1344/1662] Add XML docs for the public HTTPs APIs shipping in 2.0 (#1942) --- .../ClientCertificateMode.cs | 14 +++++++++++ .../HttpsConnectionAdapterOptions.cs | 25 +++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Https/ClientCertificateMode.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Https/ClientCertificateMode.cs index 9697cb6476..caff5e041a 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Https/ClientCertificateMode.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Https/ClientCertificateMode.cs @@ -3,10 +3,24 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Https { + /// + /// Describes the client certificate requirements for a HTTPS connection. + /// public enum ClientCertificateMode { + /// + /// A client certificate is not required and will not be requested from clients. + /// NoCertificate, + + /// + /// A client certificate will be requested; however, authentication will not fail if a certificate is not provided by the client. + /// AllowCertificate, + + /// + /// A client certificate will be requested, and the client must provide a valid certificate for authentication to succeed. + /// RequireCertificate } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Https/HttpsConnectionAdapterOptions.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Https/HttpsConnectionAdapterOptions.cs index 728c842c65..d10fdbf23b 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Https/HttpsConnectionAdapterOptions.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Https/HttpsConnectionAdapterOptions.cs @@ -8,18 +8,43 @@ using System.Security.Cryptography.X509Certificates; namespace Microsoft.AspNetCore.Server.Kestrel.Https { + /// + /// Settings for how Kestrel should handle HTTPS connections. + /// public class HttpsConnectionAdapterOptions { + /// + /// Initializes a new instance of . + /// public HttpsConnectionAdapterOptions() { ClientCertificateMode = ClientCertificateMode.NoCertificate; SslProtocols = SslProtocols.Tls12 | SslProtocols.Tls11; } + /// + /// Specifies the server certificate used to authenticate HTTPS connections. + /// public X509Certificate2 ServerCertificate { get; set; } + + /// + /// Specifies the client certificate requirements for a HTTPS connection. Defaults to . + /// public ClientCertificateMode ClientCertificateMode { get; set; } + + /// + /// Specifies a callback for additional client certificate validation that will be invoked during authentication. + /// public Func ClientCertificateValidation { get; set; } + + /// + /// Specifies allowable SSL protocols. Defaults to and . + /// public SslProtocols SslProtocols { get; set; } + + /// + /// Specifies whether the certificate revocation list is checked during authentication. + /// public bool CheckCertificateRevocation { get; set; } } } From a3c157cb6117507428f5e2fce48035348051026f Mon Sep 17 00:00:00 2001 From: Nate McMaster Date: Fri, 7 Jul 2017 09:16:51 -0700 Subject: [PATCH 1345/1662] Validate certificate EKU when it is provided --- KestrelHttpServer.sln | 17 ++++- .../HttpsConnectionAdapter.cs | 50 +++++++++++++- .../HttpsConnectionAdapterOptions.cs | 5 ++ .../HttpsStrings.resx | 3 + .../Properties/AssemblyInfo.cs | 6 ++ .../Properties/HttpsStrings.Designer.cs | 14 ++++ ...spNetCore.Server.Kestrel.Core.Tests.csproj | 2 +- .../HttpsConnectionAdapterTests.cs | 62 ++++++++++++++++++ ...Core.Server.Kestrel.FunctionalTests.csproj | 2 +- test/shared/TestCertificates/eku.client.ini | 12 ++++ test/shared/TestCertificates/eku.client.pfx | Bin 0 -> 2317 bytes .../TestCertificates/eku.code_signing.ini | 12 ++++ .../TestCertificates/eku.code_signing.pfx | Bin 0 -> 2317 bytes .../TestCertificates/eku.multiple_usages.ini | 12 ++++ .../TestCertificates/eku.multiple_usages.pfx | Bin 0 -> 2325 bytes test/shared/TestCertificates/eku.server.ini | 12 ++++ test/shared/TestCertificates/eku.server.pfx | Bin 0 -> 2317 bytes .../TestCertificates/make-test-certs.sh | 62 ++++++++++++++++++ .../shared/TestCertificates/no_extensions.ini | 13 ++++ .../shared/TestCertificates/no_extensions.pfx | Bin 0 -> 2293 bytes .../testCert.pfx | Bin test/shared/TestResources.cs | 5 +- 22 files changed, 281 insertions(+), 8 deletions(-) create mode 100644 src/Microsoft.AspNetCore.Server.Kestrel.Https/Properties/AssemblyInfo.cs create mode 100644 test/shared/TestCertificates/eku.client.ini create mode 100644 test/shared/TestCertificates/eku.client.pfx create mode 100644 test/shared/TestCertificates/eku.code_signing.ini create mode 100644 test/shared/TestCertificates/eku.code_signing.pfx create mode 100644 test/shared/TestCertificates/eku.multiple_usages.ini create mode 100644 test/shared/TestCertificates/eku.multiple_usages.pfx create mode 100644 test/shared/TestCertificates/eku.server.ini create mode 100644 test/shared/TestCertificates/eku.server.pfx create mode 100755 test/shared/TestCertificates/make-test-certs.sh create mode 100644 test/shared/TestCertificates/no_extensions.ini create mode 100644 test/shared/TestCertificates/no_extensions.pfx rename test/shared/{TestResources => TestCertificates}/testCert.pfx (100%) diff --git a/KestrelHttpServer.sln b/KestrelHttpServer.sln index 56420c09fa..a5e8db2e49 100644 --- a/KestrelHttpServer.sln +++ b/KestrelHttpServer.sln @@ -1,6 +1,6 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 15 -VisualStudioVersion = 15.0.26621.2 +VisualStudioVersion = 15.0.26706.0 MinimumVisualStudioVersion = 10.0.40219.1 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{7972A5D6-3385-4127-9277-428506DD44FF}" ProjectSection(SolutionItems) = preProject @@ -52,9 +52,20 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Server EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Server.Kestrel.Performance", "test\Microsoft.AspNetCore.Server.Kestrel.Performance\Microsoft.AspNetCore.Server.Kestrel.Performance.csproj", "{EBFE9719-A44B-4978-A71F-D5C254E7F35A}" EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "TestResources", "TestResources", "{2822C132-BFFB-4D53-AC5B-E7E47DD81A6E}" +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "TestCertificates", "TestCertificates", "{2822C132-BFFB-4D53-AC5B-E7E47DD81A6E}" ProjectSection(SolutionItems) = preProject - test\shared\TestResources\testCert.pfx = test\shared\TestResources\testCert.pfx + test\shared\TestCertificates\eku.client.ini = test\shared\TestCertificates\eku.client.ini + test\shared\TestCertificates\eku.client.pfx = test\shared\TestCertificates\eku.client.pfx + test\shared\TestCertificates\eku.code_signing.ini = test\shared\TestCertificates\eku.code_signing.ini + test\shared\TestCertificates\eku.code_signing.pfx = test\shared\TestCertificates\eku.code_signing.pfx + test\shared\TestCertificates\eku.multiple_usages.ini = test\shared\TestCertificates\eku.multiple_usages.ini + test\shared\TestCertificates\eku.multiple_usages.pfx = test\shared\TestCertificates\eku.multiple_usages.pfx + test\shared\TestCertificates\eku.server.ini = test\shared\TestCertificates\eku.server.ini + test\shared\TestCertificates\eku.server.pfx = test\shared\TestCertificates\eku.server.pfx + test\shared\TestCertificates\make-test-certs.sh = test\shared\TestCertificates\make-test-certs.sh + test\shared\TestCertificates\no_extensions.ini = test\shared\TestCertificates\no_extensions.ini + test\shared\TestCertificates\no_extensions.pfx = test\shared\TestCertificates\no_extensions.pfx + test\shared\TestCertificates\testCert.pfx = test\shared\TestCertificates\testCert.pfx EndProjectSection EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv", "src\Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv\Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.csproj", "{A76B8C8C-0DC5-4DD3-9B1F-02E51A0915F4}" diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Https/HttpsConnectionAdapter.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Https/HttpsConnectionAdapter.cs index 5f17cfaf63..4cf33b1832 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Https/HttpsConnectionAdapter.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Https/HttpsConnectionAdapter.cs @@ -3,6 +3,7 @@ using System; using System.IO; +using System.Linq; using System.Net.Security; using System.Security.Cryptography.X509Certificates; using System.Threading.Tasks; @@ -15,9 +16,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Https { public class HttpsConnectionAdapter : IConnectionAdapter { + // See http://oid-info.com/get/1.3.6.1.5.5.7.3.1 + // Indicates that a certificate can be used as a SSL server certificate + private const string ServerAuthenticationOid = "1.3.6.1.5.5.7.3.1"; + private static readonly ClosedAdaptedConnection _closedAdaptedConnection = new ClosedAdaptedConnection(); private readonly HttpsConnectionAdapterOptions _options; + private readonly X509Certificate2 _serverCertificate; private readonly ILogger _logger; public HttpsConnectionAdapter(HttpsConnectionAdapterOptions options) @@ -37,6 +43,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Https throw new ArgumentException(HttpsStrings.ServiceCertificateRequired, nameof(options)); } + // capture the certificate now so it can be switched after validation + _serverCertificate = options.ServerCertificate; + + EnsureCertificateIsAllowedForServerAuth(_serverCertificate); + _options = options; _logger = loggerFactory?.CreateLogger(nameof(HttpsConnectionAdapter)); } @@ -100,7 +111,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Https try { - await sslStream.AuthenticateAsServerAsync(_options.ServerCertificate, certificateRequired, + await sslStream.AuthenticateAsServerAsync(_serverCertificate, certificateRequired, _options.SslProtocols, _options.CheckCertificateRevocation); } catch (IOException ex) @@ -119,6 +130,43 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Https return new HttpsAdaptedConnection(sslStream); } + private static void EnsureCertificateIsAllowedForServerAuth(X509Certificate2 certificate) + { + /* If the Extended Key Usage extension is included, then we check that the serverAuth usage is included. (http://oid-info.com/get/1.3.6.1.5.5.7.3.1) + * If the Extended Key Usage extension is not included, then we assume the certificate is allowed for all usages. + * + * See also https://blogs.msdn.microsoft.com/kaushal/2012/02/17/client-certificates-vs-server-certificates/ + * + * From https://tools.ietf.org/html/rfc3280#section-4.2.1.13 "Certificate Extensions: Extended Key Usage" + * + * If the (Extended Key Usage) extension is present, then the certificate MUST only be used + * for one of the purposes indicated. If multiple purposes are + * indicated the application need not recognize all purposes indicated, + * as long as the intended purpose is present. Certificate using + * applications MAY require that a particular purpose be indicated in + * order for the certificate to be acceptable to that application. + */ + + var hasEkuExtension = false; + + foreach (var extension in certificate.Extensions.OfType()) + { + hasEkuExtension = true; + foreach (var oid in extension.EnhancedKeyUsages) + { + if (oid.Value.Equals(ServerAuthenticationOid, StringComparison.Ordinal)) + { + return; + } + } + } + + if (hasEkuExtension) + { + throw new InvalidOperationException(HttpsStrings.FormatInvalidServerCertificateEku(certificate.Thumbprint)); + } + } + private static X509Certificate2 ConvertToX509Certificate2(X509Certificate certificate) { if (certificate == null) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Https/HttpsConnectionAdapterOptions.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Https/HttpsConnectionAdapterOptions.cs index d10fdbf23b..f09ea10bc1 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Https/HttpsConnectionAdapterOptions.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Https/HttpsConnectionAdapterOptions.cs @@ -23,7 +23,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Https } /// + /// /// Specifies the server certificate used to authenticate HTTPS connections. + /// + /// + /// If the server certificate has an Extended Key Usage extension, the usages must include Server Authentication (OID 1.3.6.1.5.5.7.3.1). + /// /// public X509Certificate2 ServerCertificate { get; set; } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Https/HttpsStrings.resx b/src/Microsoft.AspNetCore.Server.Kestrel.Https/HttpsStrings.resx index d0745abab8..b7ab3141db 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Https/HttpsStrings.resx +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Https/HttpsStrings.resx @@ -120,6 +120,9 @@ Failed to authenticate HTTPS connection. + + Certificate {thumbprint} cannot be used as an SSL server certificate. It has an Extended Key Usage extension but the usages do not include Server Authentication (OID 1.3.6.1.5.5.7.3.1). + The server certificate parameter is required. diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Https/Properties/AssemblyInfo.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Https/Properties/AssemblyInfo.cs new file mode 100644 index 0000000000..3bb5150c92 --- /dev/null +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Https/Properties/AssemblyInfo.cs @@ -0,0 +1,6 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System.Runtime.CompilerServices; + +[assembly: InternalsVisibleTo("Microsoft.AspNetCore.Server.Kestrel.FunctionalTests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")] diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Https/Properties/HttpsStrings.Designer.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Https/Properties/HttpsStrings.Designer.cs index 1b86a18e5d..03676ba6a7 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Https/Properties/HttpsStrings.Designer.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Https/Properties/HttpsStrings.Designer.cs @@ -24,6 +24,20 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Https internal static string FormatAuthenticationFailed() => GetString("AuthenticationFailed"); + /// + /// Certificate {thumbprint} cannot be used as an SSL server certificate. It has an Extended Key Usage extension but the usages do not include Server Authentication (OID 1.3.6.1.5.5.7.3.1). + /// + internal static string InvalidServerCertificateEku + { + get => GetString("InvalidServerCertificateEku"); + } + + /// + /// Certificate {thumbprint} cannot be used as an SSL server certificate. It has an Extended Key Usage extension but the usages do not include Server Authentication (OID 1.3.6.1.5.5.7.3.1). + /// + internal static string FormatInvalidServerCertificateEku(object thumbprint) + => string.Format(CultureInfo.CurrentCulture, GetString("InvalidServerCertificateEku", "thumbprint"), thumbprint); + /// /// The server certificate parameter is required. /// diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/Microsoft.AspNetCore.Server.Kestrel.Core.Tests.csproj b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/Microsoft.AspNetCore.Server.Kestrel.Core.Tests.csproj index d4f68d8023..5289c063ab 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/Microsoft.AspNetCore.Server.Kestrel.Core.Tests.csproj +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/Microsoft.AspNetCore.Server.Kestrel.Core.Tests.csproj @@ -17,7 +17,7 @@ - + diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/HttpsConnectionAdapterTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/HttpsConnectionAdapterTests.cs index 0f6b48097e..d75728f8f0 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/HttpsConnectionAdapterTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/HttpsConnectionAdapterTests.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using System.IO; +using System.Linq; using System.Net; using System.Net.Http; using System.Net.Security; @@ -18,12 +19,19 @@ using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.AspNetCore.Server.Kestrel.Https; using Microsoft.AspNetCore.Testing; using Xunit; +using Xunit.Abstractions; namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { public class HttpsConnectionAdapterTests { private static X509Certificate2 _x509Certificate2 = new X509Certificate2(TestResources.TestCertificatePath, "testPassword"); + private readonly ITestOutputHelper _output; + + public HttpsConnectionAdapterTests(ITestOutputHelper output) + { + _output = output; + } // https://github.com/aspnet/KestrelHttpServer/issues/240 // This test currently fails on mono because of an issue with SslStream. @@ -367,6 +375,60 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } } + [Theory] + [InlineData("no_extensions.pfx")] + public void AcceptsCertificateWithoutExtensions(string testCertName) + { + var certPath = TestResources.GetCertPath(testCertName); + _output.WriteLine("Loading " + certPath); + var cert = new X509Certificate2(certPath, "testPassword"); + Assert.Empty(cert.Extensions.OfType()); + + new HttpsConnectionAdapter(new HttpsConnectionAdapterOptions + { + ServerCertificate = cert, + }); + } + + [Theory] + [InlineData("eku.server.pfx")] + [InlineData("eku.multiple_usages.pfx")] + public void ValidatesEnhancedKeyUsageOnCertificate(string testCertName) + { + var certPath = TestResources.GetCertPath(testCertName); + _output.WriteLine("Loading " + certPath); + var cert = new X509Certificate2(certPath, "testPassword"); + Assert.NotEmpty(cert.Extensions); + var eku = Assert.Single(cert.Extensions.OfType()); + Assert.NotEmpty(eku.EnhancedKeyUsages); + + new HttpsConnectionAdapter(new HttpsConnectionAdapterOptions + { + ServerCertificate = cert, + }); + } + + [Theory] + [InlineData("eku.code_signing.pfx")] + [InlineData("eku.client.pfx")] + public void ThrowsForCertificatesMissingServerEku(string testCertName) + { + var certPath = TestResources.GetCertPath(testCertName); + _output.WriteLine("Loading " + certPath); + var cert = new X509Certificate2(certPath, "testPassword"); + Assert.NotEmpty(cert.Extensions); + var eku = Assert.Single(cert.Extensions.OfType()); + Assert.NotEmpty(eku.EnhancedKeyUsages); + + var ex = Assert.Throws(() => + new HttpsConnectionAdapter(new HttpsConnectionAdapterOptions + { + ServerCertificate = cert, + })); + + Assert.Equal(HttpsStrings.FormatInvalidServerCertificateEku(cert.Thumbprint), ex.Message); + } + private static async Task App(HttpContext httpContext) { var request = httpContext.Request; diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests.csproj b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests.csproj index e96a61c766..9265ff3a69 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests.csproj +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests.csproj @@ -16,7 +16,7 @@ - + diff --git a/test/shared/TestCertificates/eku.client.ini b/test/shared/TestCertificates/eku.client.ini new file mode 100644 index 0000000000..e2f2d8ab74 --- /dev/null +++ b/test/shared/TestCertificates/eku.client.ini @@ -0,0 +1,12 @@ +# See https://www.openssl.org/docs/man1.0.2/apps/req.html for details on file format + +[ req ] +prompt = no +distinguished_name = testdn + +[ testdn ] +commonName = testcertonly + +# see https://www.openssl.org/docs/man1.0.2/apps/x509v3_config.html +[ req_extensions ] +extendedKeyUsage = clientAuth diff --git a/test/shared/TestCertificates/eku.client.pfx b/test/shared/TestCertificates/eku.client.pfx new file mode 100644 index 0000000000000000000000000000000000000000..32c76a1928a22fbfd6b901b0fd4e74c696252a7b GIT binary patch literal 2317 zcmV+o3G((Zf(Z!%0Ru3C2+sxyDuzgg_YDCD0ic2izyyK_yfA_YxG;hPZw3h}hDe6@ z4FLxRpn?NnFoFYI0s#Opf&*0s2`Yw2hW8Bt2LUh~1_~;MNQU6vv zQ93pPI%1syX_30Jg6-gACGu-Pkr7LszMdREjFiKDBa-i#2%Hqnx;CrJGqPUbpB(0M zreXhKI0HI{G5<$zo!&f0U$x52jBJoL?gE)5_ zksb>J)UbVGIBou!r0Q_74>_ODum&dQb2E%s6CoUq?-4LTCSc8z8}0DG=1q5E6&m2oel7oxSbXs zGm5Z&G9Fxp8xn;vbi+9eml1$#dCYW1%Sf`}fw)TC*NYJiZxpd$vL|A^m)OkOXqflQ zfV&0YAY2CUfd13-wf~fv3j@lV0bJWZVV*w*BdRDcOZCA0MLV8#fVndT3tSWcY58;d zMX>=wDey-c?lhH(F@Z>HQ69uwzGc3_WpDn*{z;B)Q^8caHF>D{*70sXsp2_xy*3$$ ze)}YaC~zP3;K5aSRYPn(p0vfVnEAu(I8X{(H;xDDbPFF~$s+&%a*n#;PxjXxtc|-A zKJ@_%fH3e9XA)ctu$v0uwt9WPzz{#KZ>O!Y8xGoH!JqaRcQlnmXfcsMSC9mAwct>9 z>HGVMlFm+#L##S%2qlcGz^_3uvvKNfwCPf@i~=`*=@9M+;lof#k0aHQh9QX>p7ue} zn1}hi14NXReuJB&ZFPcGi1rzhD}J@TM6P4MH3&;->>qsQTJ|8UKZp}BL*jxkVU*}bEp%59z`Eb zYv}b69@?urh_#>qgfB^&7nf32R|~6qcPX0<$(w&g}ZLMahmnA~Dro*Z2K)n0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b/test/shared/TestCertificates/eku.code_signing.ini new file mode 100644 index 0000000000..d6a6c118f6 --- /dev/null +++ b/test/shared/TestCertificates/eku.code_signing.ini @@ -0,0 +1,12 @@ +# See https://www.openssl.org/docs/man1.0.2/apps/req.html for details on file format + +[ req ] +prompt = no +distinguished_name = testdn + +[ testdn ] +commonName = testcertonly + +# see https://www.openssl.org/docs/man1.0.2/apps/x509v3_config.html +[ req_extensions ] +extendedKeyUsage = codeSigning diff --git a/test/shared/TestCertificates/eku.code_signing.pfx b/test/shared/TestCertificates/eku.code_signing.pfx new file mode 100644 index 0000000000000000000000000000000000000000..050dfd05feccca028d7fd2027f7a6705b7cd9f13 GIT binary patch literal 2317 zcmY+Ec{J3G9>!-g#%?A?DN81MF|y5!niiC;?1U+@43RBcW-Q}pouUycls#{WvSgA% zqq6T=#=cd^7Q*lp427o1k*A-9I4zhh_d`OD2c<9Pm!+N||b$&TaA50teH zH$#;T=LR>aqs8FEZ%bUXF`|u)2GpL5SUHHVqhkD>Qgz{D_Cc3?T~$ zttM%CnuQLLac8+()kF}Z`D@E=^Ow^P>U)*2tu^9b%zpaW_f8e$%GGbU$H%llxw1XY za68(nldQ4Ec0X4bso%8V4u>#0`?%;h>V#oDiONZN2?v`L3%oN-d#Ml`VVqBQOO*H= zT-PTmGizP4HRO^?TV|lN-oFp~UZksMj$6%E%$QQR>Vm#1q_FR3$suJE*ysc|CCr~d zbb1;%Y0;irHnW6p`SD_qi=e|t>=I|IY7D0iX~+u z=j_;g3_T<|*W%SvmGS_sCxY=>t3WAZUX>9P&zE(|qANb;8d($ScJ8`+hGbN@wuCb5 zr79oxN1H`vXd!6n0kynWemN1TtM!J|?QOMi!DF(*UkWVV;xR{q*CXnd;4N{iJd-IM zca(?5CMOnj^P^s8hL$a(RS$b=&@Ddto~)cI;+IY+y5-nY&V$1aeu(@?i5Raq6h40@ z!TFPNwD}>8ts? zWiIfx3-MKt0cr443dMDaN-l4fAm0#-b59)xY&H%Y%~>m7wwjR5)6Z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001 diff --git a/test/shared/TestCertificates/eku.multiple_usages.ini b/test/shared/TestCertificates/eku.multiple_usages.ini new file mode 100644 index 0000000000..128af9a6fb --- /dev/null +++ b/test/shared/TestCertificates/eku.multiple_usages.ini @@ -0,0 +1,12 @@ +# See https://www.openssl.org/docs/man1.0.2/apps/req.html for details on file format + +[ req ] +prompt = no +distinguished_name = req_distinguished_name + +[ req_distinguished_name ] +commonName = testcertonly + +# see https://www.openssl.org/docs/man1.0.2/apps/x509v3_config.html +[ req_extensions ] +extendedKeyUsage = serverAuth,clientAuth diff --git a/test/shared/TestCertificates/eku.multiple_usages.pfx b/test/shared/TestCertificates/eku.multiple_usages.pfx new file mode 100644 index 0000000000000000000000000000000000000000..3bbbd9c0d43b2c1b79bd0f31b27a333865ebf47f GIT binary patch literal 2325 zcmV+w3F`JRf(a1<0Ru3C2-gM)Duzgg_YDCD0ic2i$OM82#4v&gz%YUXcLoV6hDe6@ z4FLxRpn?NvFoFYQ0s#Opf&*O!2`Yw2hW8Bt2LUh~1_~;MNQU9+Nyq6#WyGx?-_wsgVPLVRSA4_G@Z;Bf0~FfCYC> zZS_GSTjE2X5!oU}k5SnInCra`DZFAKW~#%+&SQTNJejb?|wdF-;#m1&`ot&m1qiwbqQzS>`=MTDfAefQ|z*DYf4^nQpe8<`*~ zv5-QjU2|jwkDp3~1b53hL4I9buzt-c55)AcY!NW)k(58Owln z#ZpGHbp>P+V0G5Jm*VFkUn*;l<@ofLV!8Ydy9!N!=69zrlW=alGIlzj48;4m%yVW5 z1|i->+uiE1tvD8ld9p{gfCnBJm%LmFjrjw|5Q{R0W?345&U2#Sln7qjNe*qlloM0< z;dMPlk517IR#zVGXx?@wRBW$rs}ruZrzm=#@yjLbj~(V!D*pkI2NOeUJo(WgaKyH zi?JYn#DlrY+%J~x1MF)uPUt00>0T8&O)&&mQP%SeayhmM;??HNM+XoS(Z~Aw6w!1*zxn^f()S@`2R5wVl?qa*|3A8z<^uC7%I*^S|XNj*~mpU;a!T!xlx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yRCaLhwROMj?Ptd z>sHOvP7CK&Rn^!{a>>wT89MXAnMEz&zU%glmphr=R<5wGF1&A!1eN(s5>zD@2X@tX zS{8n+^FOc_RwJOKbSgiM0#14uh3Vte&Dul`LNb`2#XEK=vMrb9OM=Tk7`m!xW@h(< z(UKhYkzxJ8 zK}SZ2>l(1+HE+pt+u+qiYIcbRPA=E6^7LnV+@?&ICofq^p-?)KUg20ctV`gE3Mmoa z30yXut@K(+&maj+F$tt}WT3`jb?;ofQs!+wHP`xIogm(|OKWJifA_|rjX_0a*6k?e zrFLj8=H9QC`v7yPMl1ncYNYh+kE#d=Vr-(e=i~hM-AKn30@GgQ>Q+zr5s`XI!TMUpCbP&qw;!5xpO-N*)#$q%#R=MS03Xgh zfcuX~slXwWd0IM}NG&6E1TY(1q2cBOSW^*3ApNCr2VnWqlDhFXvuUZLhO7=)>kLwg%l%_*-bP1D6j zR<2(xZwZ8H>S9jiXQ+xG?v*N|;T5Don4}S!lw!`z6hXMwpj9*7qZ_6wYUSWg%a2#H z7E7o`@xdKm4R7n*U)`N!L$Ffrc=5 zda8jEuy@3E-R*w^Ur-^rN!#ya$RmBE3Q?S69PS~X`=8H~p#1MMgP88h;i?9bGfLP& zjR{&g^zeXK*IKL=X8;EzmRhB--r)ZkGZ#m`2;wLmQxyFwl>U2(6<(3O` z#D$lHdheGC*+L}MKP*MW1Z)8O?7bQvA;dQjnz>0$-nl1 zrw5J|sI~~#xUZt*e^{6cToy1OJMWZ%)LBgN7t0jb+g&^AbHVKHBku>Jp-ed)_j9&e z^cp@ME=>17EHG>=cl=Y7-z4k)P*r<^x)C&&C^E(kd5c5quz?x=0Ggqdq4dFQf#TfXjOl4(if_Bj93iFf)_v86cwo69b56 lE3V|wQ`ptY#7Xy0xkTqNKhXL*h*k8*0{@S8dd}~a{1?thN#+0m literal 0 HcmV?d00001 diff --git a/test/shared/TestCertificates/make-test-certs.sh b/test/shared/TestCertificates/make-test-certs.sh new file mode 100755 index 0000000000..e489408b1c --- /dev/null +++ b/test/shared/TestCertificates/make-test-certs.sh @@ -0,0 +1,62 @@ +#!/usr/bin/env bash + +# +# Should be obvious, but don't use the certs created here for anything real. This is just meant for our testing. +# + +set -euo pipefail + +__machine_has() { + hash "$1" > /dev/null 2>&1 + return $? +} + +# +# Main +# + +if ! __machine_has openssl; then + echo 'OpenSSL is required to create the test certificates.' 1>&2 + exit 1 +fi + +# See https://www.openssl.org/docs/man1.0.2/apps/x509.html for more details on the openssl conf file + +if [[ $# == 0 ]]; then + echo "Usage: ${BASH_SOURCE[0]} ..." + echo "" + echo "Arguments:" + echo " Multiple allowed. Path to the *.ini file that configures a cert." +fi + +# loop over all arguments +while [[ $# > 0 ]]; do + # bashism for trimming the extension + config=$1 + shift + cert_name="${config%.*}" + key="$cert_name.pem" + cert="$cert_name.crt" + pfx="$cert_name.pfx" + + echo "Creating cert $cert_name" + + # see https://www.openssl.org/docs/man1.0.2/apps/req.html + openssl req -x509 \ + -days 1 \ + -config $config \ + -nodes \ + -newkey rsa:2048 \ + -keyout $key \ + -extensions req_extensions \ + -out $cert + + # See https://www.openssl.org/docs/man1.0.2/apps/pkcs12.html + openssl pkcs12 -export \ + -in $cert \ + -inkey $key \ + -out $pfx \ + -password pass:testPassword # so secure ;) + + rm $key $cert +done diff --git a/test/shared/TestCertificates/no_extensions.ini b/test/shared/TestCertificates/no_extensions.ini new file mode 100644 index 0000000000..df234f06a6 --- /dev/null +++ b/test/shared/TestCertificates/no_extensions.ini @@ -0,0 +1,13 @@ +# See https://www.openssl.org/docs/man1.0.2/apps/req.html for details on file format + +[ req ] +prompt = no +distinguished_name = testdn + +[ testdn ] +commonName = testcertonly + +# see https://www.openssl.org/docs/man1.0.2/apps/x509v3_config.html +[ req_extensions ] +# keyUsages = +# extendedKeyUsage = diff --git a/test/shared/TestCertificates/no_extensions.pfx b/test/shared/TestCertificates/no_extensions.pfx new file mode 100644 index 0000000000000000000000000000000000000000..b4be4b5edaabdecc5de68d713b1981b259357733 GIT binary patch liter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2B^?pX>Sj+Fyg?bqDZgj;VNgY>{d%z)Q5P8?zF@GvGZ%LLhn2Y^oxM=OwN$gPv zii@C8g!V9qGvk-PI%bdZuGyfkQ-(G=Uz``yt^V&qSN@Qs$vF`%7T&y1{b^cDsLn@zz;PvEI%xLF2NRXFRs+1+>!F=tLl^&(;C9&x%Kh1Rk zkgRcBz)e3nu*@tJwL>KKI&zwRn6Et=uL`*urdR`q$`31u3h#HwHE*moH|k z_P<5OeJliQ^NcvS2-!B|Nrx`5ufa0{%o}$ zry8!4F&3VK4_)UNmP}o$W;5u~z=;x9?NmRqCv=RZglUNZI@?W~v(?1caUKLU(mbZ; zW?q8mOf(LWUJGWg;QsAH-+@f _testCertificatePath; + public static string TestCertificatePath { get; } = Path.Combine(_baseDir, "testCert.pfx"); + public static string GetCertPath(string name) => Path.Combine(_baseDir, name); } } From ec72c255f60efa17ce8bea69936e01dd71f61960 Mon Sep 17 00:00:00 2001 From: Nate McMaster Date: Fri, 7 Jul 2017 09:40:20 -0700 Subject: [PATCH 1346/1662] Make HttpsConnectionAdapter pubternal --- .../{ => Internal}/HttpsConnectionAdapter.cs | 3 +-- .../ListenOptionsHttpsExtensions.cs | 1 + .../HttpsConnectionAdapterTests.cs | 1 + .../HttpsTests.cs | 5 ++--- 4 files changed, 5 insertions(+), 5 deletions(-) rename src/Microsoft.AspNetCore.Server.Kestrel.Https/{ => Internal}/HttpsConnectionAdapter.cs (98%) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Https/HttpsConnectionAdapter.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Https/Internal/HttpsConnectionAdapter.cs similarity index 98% rename from src/Microsoft.AspNetCore.Server.Kestrel.Https/HttpsConnectionAdapter.cs rename to src/Microsoft.AspNetCore.Server.Kestrel.Https/Internal/HttpsConnectionAdapter.cs index 4cf33b1832..68e7268ab0 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Https/HttpsConnectionAdapter.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Https/Internal/HttpsConnectionAdapter.cs @@ -9,10 +9,9 @@ using System.Security.Cryptography.X509Certificates; using System.Threading.Tasks; using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal; -using Microsoft.AspNetCore.Server.Kestrel.Https.Internal; using Microsoft.Extensions.Logging; -namespace Microsoft.AspNetCore.Server.Kestrel.Https +namespace Microsoft.AspNetCore.Server.Kestrel.Https.Internal { public class HttpsConnectionAdapter : IConnectionAdapter { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Https/ListenOptionsHttpsExtensions.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Https/ListenOptionsHttpsExtensions.cs index 856c91a1c2..7cf8ab1b9e 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Https/ListenOptionsHttpsExtensions.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Https/ListenOptionsHttpsExtensions.cs @@ -5,6 +5,7 @@ using System.IO; using System.Security.Cryptography.X509Certificates; using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.AspNetCore.Server.Kestrel.Https; +using Microsoft.AspNetCore.Server.Kestrel.Https.Internal; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/HttpsConnectionAdapterTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/HttpsConnectionAdapterTests.cs index d75728f8f0..5ef04a4392 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/HttpsConnectionAdapterTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/HttpsConnectionAdapterTests.cs @@ -17,6 +17,7 @@ using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.AspNetCore.Server.Kestrel.Https; +using Microsoft.AspNetCore.Server.Kestrel.Https.Internal; using Microsoft.AspNetCore.Testing; using Xunit; using Xunit.Abstractions; diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/HttpsTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/HttpsTests.cs index fcb67652cc..9a7f147b2b 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/HttpsTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/HttpsTests.cs @@ -7,15 +7,14 @@ using System.Net; using System.Net.Security; using System.Net.Sockets; using System.Security.Authentication; -using System.Security.Cryptography.X509Certificates; using System.Text; using System.Threading.Tasks; using Microsoft.AspNetCore.Builder; -using Microsoft.Extensions.DependencyInjection; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Server.Kestrel.Https; +using Microsoft.AspNetCore.Server.Kestrel.Https.Internal; using Microsoft.AspNetCore.Testing; +using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Abstractions.Internal; using Xunit; From 5185ebe45f88b7fecd06459be18064b04a09953e Mon Sep 17 00:00:00 2001 From: Nate McMaster Date: Fri, 7 Jul 2017 16:27:20 -0700 Subject: [PATCH 1347/1662] Fix typo in type name (#1948) --- ...mdExtensions.cs => KestrelServerOptionsSystemdExtensions.cs} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename src/Microsoft.AspNetCore.Server.Kestrel.Core/Systemd/{KesterlServerOptionsSystemdExtensions.cs => KestrelServerOptionsSystemdExtensions.cs} (96%) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Systemd/KesterlServerOptionsSystemdExtensions.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Systemd/KestrelServerOptionsSystemdExtensions.cs similarity index 96% rename from src/Microsoft.AspNetCore.Server.Kestrel.Core/Systemd/KesterlServerOptionsSystemdExtensions.cs rename to src/Microsoft.AspNetCore.Server.Kestrel.Core/Systemd/KestrelServerOptionsSystemdExtensions.cs index e26b4d4cc0..6def39159d 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Systemd/KesterlServerOptionsSystemdExtensions.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Systemd/KestrelServerOptionsSystemdExtensions.cs @@ -8,7 +8,7 @@ using Microsoft.AspNetCore.Server.Kestrel.Core; namespace Microsoft.AspNetCore.Hosting { - public static class KesterlServerOptionsSystemdExtensions + public static class KestrelServerOptionsSystemdExtensions { // SD_LISTEN_FDS_START https://www.freedesktop.org/software/systemd/man/sd_listen_fds.html private const ulong SdListenFdsStart = 3; From eca4bfe6c3254bef221be1f23b68a0112ce86618 Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Fri, 7 Jul 2017 22:37:25 -0700 Subject: [PATCH 1348/1662] Add response minimum data rate feature. --- .../CoreStrings.resx | 3 + .../IHttpMinRequestBodyDataRateFeature.cs | 4 +- .../IHttpMinResponseDataRateFeature.cs | 18 ++ .../Internal/FrameConnection.cs | 129 ++++++++++--- .../Internal/Http/Frame.FeatureCollection.cs | 9 +- .../Internal/Http/Frame.Generated.cs | 16 ++ .../Internal/Http/Frame.cs | 7 +- .../Internal/Http/OutputProducer.cs | 20 +- .../Internal/Infrastructure/IKestrelTrace.cs | 2 + .../Infrastructure/ITimeoutControl.cs | 3 + .../Internal/Infrastructure/KestrelTrace.cs | 10 +- .../KestrelServerLimits.cs | 24 +++ .../MinDataRate.cs | 4 +- .../Properties/CoreStrings.Designer.cs | 14 ++ .../Internal/LibuvAwaitable.cs | 2 +- .../Internal/LibuvConnection.cs | 18 +- .../Internal/LibuvOutputConsumer.cs | 31 +++- .../FrameConnectionTests.cs | 173 +++++++++++++++++- .../FrameTests.cs | 25 ++- .../KestrelServerLimitsTests.cs | 8 + .../MinDataRateTests.cs | 4 +- .../OutputProducerTests.cs | 15 +- .../RequestTests.cs | 8 +- .../ResponseTests.cs | 156 +++++++++++++++- .../Mocks/MockTimeoutControl.cs | 8 + .../Mocks/MockTrace.cs | 1 + .../LibuvOutputConsumerTests.cs | 76 ++++---- .../TestHelpers/MockLibuv.cs | 43 ++++- test/shared/TestServiceContext.cs | 1 + tools/CodeGenerator/FrameFeatureCollection.cs | 2 + 30 files changed, 708 insertions(+), 126 deletions(-) create mode 100644 src/Microsoft.AspNetCore.Server.Kestrel.Core/Features/IHttpMinResponseDataRateFeature.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/CoreStrings.resx b/src/Microsoft.AspNetCore.Server.Kestrel.Core/CoreStrings.resx index 16e59e4c3a..63f8986ab5 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/CoreStrings.resx +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/CoreStrings.resx @@ -342,4 +342,7 @@ Synchronous operations are disallowed. Call WriteAsync or set AllowSynchronousIO to true instead. + + Value must be a positive number. To disable a minimum data rate, use null where a MinDataRate instance is expected. + \ No newline at end of file diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Features/IHttpMinRequestBodyDataRateFeature.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Features/IHttpMinRequestBodyDataRateFeature.cs index af5ee4e66f..f80bd99772 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Features/IHttpMinRequestBodyDataRateFeature.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Features/IHttpMinRequestBodyDataRateFeature.cs @@ -4,12 +4,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Features { /// - /// Represents a minimum data rate for the request body of an HTTP request. + /// Feature to set the minimum data rate at which the the request body must be sent by the client. /// public interface IHttpMinRequestBodyDataRateFeature { /// - /// The minimum data rate in bytes/second at which the request body should be received. + /// The minimum data rate in bytes/second at which the request body must be sent by the client. /// Setting this property to null indicates no minimum data rate should be enforced. /// This limit has no effect on upgraded connections which are always unlimited. /// diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Features/IHttpMinResponseDataRateFeature.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Features/IHttpMinResponseDataRateFeature.cs new file mode 100644 index 0000000000..f901a338d9 --- /dev/null +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Features/IHttpMinResponseDataRateFeature.cs @@ -0,0 +1,18 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Features +{ + /// + /// Feature to set the minimum data rate at which the response must be received by the client. + /// + public interface IHttpMinResponseDataRateFeature + { + /// + /// The minimum data rate in bytes/second at which the response must be received by the client. + /// Setting this property to null indicates no minimum data rate should be enforced. + /// This limit has no effect on upgraded connections which are always unlimited. + /// + MinDataRate MinDataRate { get; set; } + } +} diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnection.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnection.cs index 6d053da559..1574d3bf7e 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnection.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnection.cs @@ -7,8 +7,8 @@ using System.Diagnostics; using System.IO; using System.Threading; using System.Threading.Tasks; -using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Hosting.Server; +using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; @@ -35,6 +35,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal private long _readTimingElapsedTicks; private long _readTimingBytesRead; + private object _writeTimingLock = new object(); + private int _writeTimingWrites; + private long _writeTimingTimeoutTimestamp; + private Task _lifetimeTask; public FrameConnection(FrameConnectionContext context) @@ -46,7 +50,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal internal Frame Frame => _frame; internal IDebugger Debugger { get; set; } = DebuggerWrapper.Singleton; - public bool TimedOut { get; private set; } public string ConnectionId => _context.ConnectionId; @@ -207,7 +210,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal Debug.Assert(_frame != null, $"{nameof(_frame)} is null"); TimedOut = true; - _readTimingEnabled = false; _frame.Stop(); } @@ -262,6 +264,20 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal var timestamp = now.Ticks; + CheckForTimeout(timestamp); + CheckForReadDataRateTimeout(timestamp); + CheckForWriteDataRateTimeout(timestamp); + + Interlocked.Exchange(ref _lastTimestamp, timestamp); + } + + private void CheckForTimeout(long timestamp) + { + if (TimedOut) + { + return; + } + // TODO: Use PlatformApis.VolatileRead equivalent again if (timestamp > Interlocked.Read(ref _timeoutTimestamp)) { @@ -277,42 +293,67 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal Timeout(); } } - else + } + + private void CheckForReadDataRateTimeout(long timestamp) + { + // The only time when both a timeout is set and the read data rate could be enforced is + // when draining the request body. Since there's already a (short) timeout set for draining, + // it's safe to not check the data rate at this point. + if (TimedOut || Interlocked.Read(ref _timeoutTimestamp) != long.MaxValue) { - lock (_readTimingLock) + return; + } + + lock (_readTimingLock) + { + if (_readTimingEnabled) { - if (_readTimingEnabled) + // Reference in local var to avoid torn reads in case the min rate is changed via IHttpMinRequestBodyDataRateFeature + var minRequestBodyDataRate = _frame.MinRequestBodyDataRate; + + _readTimingElapsedTicks += timestamp - _lastTimestamp; + + if (minRequestBodyDataRate?.BytesPerSecond > 0 && _readTimingElapsedTicks > minRequestBodyDataRate.GracePeriod.Ticks) { - // Reference in local var to avoid torn reads in case the min rate is changed via IHttpMinRequestBodyDataRateFeature - var minRequestBodyDataRate = _frame.MinRequestBodyDataRate; + var elapsedSeconds = (double)_readTimingElapsedTicks / TimeSpan.TicksPerSecond; + var rate = Interlocked.Read(ref _readTimingBytesRead) / elapsedSeconds; - _readTimingElapsedTicks += timestamp - _lastTimestamp; - - if (minRequestBodyDataRate?.BytesPerSecond > 0 && _readTimingElapsedTicks > minRequestBodyDataRate.GracePeriod.Ticks) + if (rate < minRequestBodyDataRate.BytesPerSecond && !Debugger.IsAttached) { - var elapsedSeconds = (double)_readTimingElapsedTicks / TimeSpan.TicksPerSecond; - var rate = Interlocked.Read(ref _readTimingBytesRead) / elapsedSeconds; - - if (rate < minRequestBodyDataRate.BytesPerSecond && !Debugger.IsAttached) - { - Log.RequestBodyMininumDataRateNotSatisfied(_context.ConnectionId, _frame.TraceIdentifier, minRequestBodyDataRate.BytesPerSecond); - Timeout(); - } + Log.RequestBodyMininumDataRateNotSatisfied(_context.ConnectionId, _frame.TraceIdentifier, minRequestBodyDataRate.BytesPerSecond); + Timeout(); } + } - // PauseTimingReads() cannot just set _timingReads to false. It needs to go through at least one tick - // before pausing, otherwise _readTimingElapsed might never be updated if PauseTimingReads() is always - // called before the next tick. - if (_readTimingPauseRequested) - { - _readTimingEnabled = false; - _readTimingPauseRequested = false; - } + // PauseTimingReads() cannot just set _timingReads to false. It needs to go through at least one tick + // before pausing, otherwise _readTimingElapsed might never be updated if PauseTimingReads() is always + // called before the next tick. + if (_readTimingPauseRequested) + { + _readTimingEnabled = false; + _readTimingPauseRequested = false; } } } + } - Interlocked.Exchange(ref _lastTimestamp, timestamp); + private void CheckForWriteDataRateTimeout(long timestamp) + { + if (TimedOut) + { + return; + } + + lock (_writeTimingLock) + { + if (_writeTimingWrites > 0 && timestamp > _writeTimingTimeoutTimestamp && !Debugger.IsAttached) + { + TimedOut = true; + Log.ResponseMininumDataRateNotSatisfied(_frame.ConnectionIdFeature, _frame.TraceIdentifier); + Abort(new TimeoutException()); + } + } } public void SetTimeout(long ticks, TimeoutAction timeoutAction) @@ -381,5 +422,37 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal { Interlocked.Add(ref _readTimingBytesRead, count); } + + public void StartTimingWrite(int size) + { + lock (_writeTimingLock) + { + var minResponseDataRate = _frame.MinResponseDataRate; + + if (minResponseDataRate != null) + { + var timeoutTicks = Math.Max( + minResponseDataRate.GracePeriod.Ticks, + TimeSpan.FromSeconds(size / minResponseDataRate.BytesPerSecond).Ticks); + + if (_writeTimingWrites == 0) + { + // Add Heartbeat.Interval since this can be called right before the next heartbeat. + _writeTimingTimeoutTimestamp = _lastTimestamp + Heartbeat.Interval.Ticks; + } + + _writeTimingTimeoutTimestamp += timeoutTicks; + _writeTimingWrites++; + } + } + } + + public void StopTimingWrite() + { + lock (_writeTimingLock) + { + _writeTimingWrites--; + } + } } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.FeatureCollection.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.FeatureCollection.cs index cbc30427e5..3cf9d22fac 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.FeatureCollection.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.FeatureCollection.cs @@ -24,7 +24,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http IHttpRequestIdentifierFeature, IHttpBodyControlFeature, IHttpMaxRequestBodySizeFeature, - IHttpMinRequestBodyDataRateFeature + IHttpMinRequestBodyDataRateFeature, + IHttpMinResponseDataRateFeature { // NOTE: When feature interfaces are added to or removed from this Frame class implementation, // then the list of `implementedFeatures` in the generated code project MUST also be updated. @@ -242,6 +243,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http set => MinRequestBodyDataRate = value; } + MinDataRate IHttpMinResponseDataRateFeature.MinDataRate + { + get => MinResponseDataRate; + set => MinResponseDataRate = value; + } + object IFeatureCollection.this[Type key] { get => FastFeatureGet(key); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.Generated.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.Generated.cs index 6aba909708..c4403a60ce 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.Generated.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.Generated.cs @@ -25,6 +25,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http private static readonly Type ISessionFeatureType = typeof(global::Microsoft.AspNetCore.Http.Features.ISessionFeature); private static readonly Type IHttpMaxRequestBodySizeFeatureType = typeof(global::Microsoft.AspNetCore.Http.Features.IHttpMaxRequestBodySizeFeature); private static readonly Type IHttpMinRequestBodyDataRateFeatureType = typeof(global::Microsoft.AspNetCore.Server.Kestrel.Core.Features.IHttpMinRequestBodyDataRateFeature); + private static readonly Type IHttpMinResponseDataRateFeatureType = typeof(global::Microsoft.AspNetCore.Server.Kestrel.Core.Features.IHttpMinResponseDataRateFeature); private static readonly Type IHttpBodyControlFeatureType = typeof(global::Microsoft.AspNetCore.Http.Features.IHttpBodyControlFeature); private static readonly Type IHttpSendFileFeatureType = typeof(global::Microsoft.AspNetCore.Http.Features.IHttpSendFileFeature); @@ -45,6 +46,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http private object _currentISessionFeature; private object _currentIHttpMaxRequestBodySizeFeature; private object _currentIHttpMinRequestBodyDataRateFeature; + private object _currentIHttpMinResponseDataRateFeature; private object _currentIHttpBodyControlFeature; private object _currentIHttpSendFileFeature; @@ -58,6 +60,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http _currentIHttpConnectionFeature = this; _currentIHttpMaxRequestBodySizeFeature = this; _currentIHttpMinRequestBodyDataRateFeature = this; + _currentIHttpMinResponseDataRateFeature = this; _currentIHttpBodyControlFeature = this; _currentIServiceProvidersFeature = null; @@ -142,6 +145,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { return _currentIHttpMinRequestBodyDataRateFeature; } + if (key == IHttpMinResponseDataRateFeatureType) + { + return _currentIHttpMinResponseDataRateFeature; + } if (key == IHttpBodyControlFeatureType) { return _currentIHttpBodyControlFeature; @@ -242,6 +249,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http _currentIHttpMinRequestBodyDataRateFeature = feature; return; } + if (key == IHttpMinResponseDataRateFeatureType) + { + _currentIHttpMinResponseDataRateFeature = feature; + return; + } if (key == IHttpBodyControlFeatureType) { _currentIHttpBodyControlFeature = feature; @@ -325,6 +337,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { yield return new KeyValuePair(IHttpMinRequestBodyDataRateFeatureType, _currentIHttpMinRequestBodyDataRateFeature as global::Microsoft.AspNetCore.Server.Kestrel.Core.Features.IHttpMinRequestBodyDataRateFeature); } + if (_currentIHttpMinResponseDataRateFeature != null) + { + yield return new KeyValuePair(IHttpMinResponseDataRateFeatureType, _currentIHttpMinResponseDataRateFeature as global::Microsoft.AspNetCore.Server.Kestrel.Core.Features.IHttpMinResponseDataRateFeature); + } if (_currentIHttpBodyControlFeature != null) { yield return new KeyValuePair(IHttpBodyControlFeatureType, _currentIHttpBodyControlFeature as global::Microsoft.AspNetCore.Http.Features.IHttpBodyControlFeature); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.cs index c9e7ba118b..e6b1187438 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.cs @@ -97,7 +97,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http _keepAliveTicks = ServerOptions.Limits.KeepAliveTimeout.Ticks; _requestHeadersTimeoutTicks = ServerOptions.Limits.RequestHeadersTimeout.Ticks; - Output = new OutputProducer(frameContext.Output, frameContext.ConnectionId, frameContext.ServiceContext.Log); + Output = new OutputProducer(frameContext.Output, frameContext.ConnectionId, frameContext.ServiceContext.Log, TimeoutControl); RequestBodyPipe = CreateRequestBodyPipe(); } @@ -302,6 +302,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http public MinDataRate MinRequestBodyDataRate { get; set; } + public MinDataRate MinResponseDataRate { get; set; } + public void InitializeStreams(MessageBody messageBody) { if (_frameStreams == null) @@ -381,6 +383,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http _requestCount++; MinRequestBodyDataRate = ServerOptions.Limits.MinRequestBodyDataRate; + MinResponseDataRate = ServerOptions.Limits.MinResponseDataRate; } /// @@ -418,7 +421,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http _frameStreams?.Abort(error); - Output.Abort(); + Output.Abort(error); // Potentially calling user code. CancelRequestAbortedToken logs any exceptions. ServiceContext.ThreadPool.UnsafeRun(state => ((Frame)state).CancelRequestAbortedToken(), this); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/OutputProducer.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/OutputProducer.cs index 5f58ef6ae4..d9fce78492 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/OutputProducer.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/OutputProducer.cs @@ -14,6 +14,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http private static readonly ArraySegment _emptyData = new ArraySegment(new byte[0]); private readonly string _connectionId; + private readonly ITimeoutControl _timeoutControl; private readonly IKestrelTrace _log; // This locks access to to all of the below fields @@ -30,10 +31,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http private readonly object _flushLock = new object(); private Action _flushCompleted; - public OutputProducer(IPipe pipe, string connectionId, IKestrelTrace log) + public OutputProducer( + IPipe pipe, + string connectionId, + IKestrelTrace log, + ITimeoutControl timeoutControl) { _pipe = pipe; _connectionId = connectionId; + _timeoutControl = timeoutControl; _log = log; _flushCompleted = OnFlushCompleted; } @@ -83,7 +89,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http } } - public void Abort() + public void Abort(Exception error) { lock (_contextLock) { @@ -94,8 +100,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http _log.ConnectionDisconnect(_connectionId); _completed = true; + _pipe.Reader.CancelPendingRead(); - _pipe.Writer.Complete(); + _pipe.Writer.Complete(error); } } @@ -145,10 +152,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http // The flush task can't fail today return Task.CompletedTask; } - return FlushAsyncAwaited(awaitable, cancellationToken); + return FlushAsyncAwaited(awaitable, writableBuffer.BytesWritten, cancellationToken); } - private async Task FlushAsyncAwaited(WritableBufferAwaitable awaitable, CancellationToken cancellationToken) + private async Task FlushAsyncAwaited(WritableBufferAwaitable awaitable, int count, CancellationToken cancellationToken) { // https://github.com/dotnet/corefxlab/issues/1334 // Since the flush awaitable doesn't currently support multiple awaiters @@ -163,7 +170,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http awaitable.OnCompleted(_flushCompleted); } } + + _timeoutControl.StartTimingWrite(count); await _flushTcs.Task; + _timeoutControl.StopTimingWrite(); cancellationToken.ThrowIfCancellationRequested(); } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/IKestrelTrace.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/IKestrelTrace.cs index b7d68eb03a..456e132274 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/IKestrelTrace.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/IKestrelTrace.cs @@ -43,5 +43,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure void RequestBodyDone(string connectionId, string traceIdentifier); void RequestBodyMininumDataRateNotSatisfied(string connectionId, string traceIdentifier, double rate); + + void ResponseMininumDataRateNotSatisfied(string connectionId, string traceIdentifier); } } \ No newline at end of file diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/ITimeoutControl.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/ITimeoutControl.cs index 6b23f37c94..4ed025ac72 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/ITimeoutControl.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/ITimeoutControl.cs @@ -16,5 +16,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure void ResumeTimingReads(); void StopTimingReads(); void BytesRead(int count); + + void StartTimingWrite(int size); + void StopTimingWrite(); } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/KestrelTrace.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/KestrelTrace.cs index 115d44184d..ab6eb51293 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/KestrelTrace.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/KestrelTrace.cs @@ -61,7 +61,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal LoggerMessage.Define(LogLevel.Debug, 26, @"Connection id ""{ConnectionId}"", Request id ""{TraceIdentifier}"": done reading request body."); private static readonly Action _requestBodyMinimumDataRateNotSatisfied = - LoggerMessage.Define(LogLevel.Information, 27, @"Connection id ""{ConnectionId}"", Request id ""{TraceIdentifier}"": request body incoming data rate dropped below {Rate} bytes/second."); + LoggerMessage.Define(LogLevel.Information, 27, @"Connection id ""{ConnectionId}"", Request id ""{TraceIdentifier}"": the request timed out because it was not sent by the client at a minimum of {Rate} bytes/second."); + + private static readonly Action _responseMinimumDataRateNotSatisfied = + LoggerMessage.Define(LogLevel.Information, 28, @"Connection id ""{ConnectionId}"", Request id ""{TraceIdentifier}"": the connection was closed becuase the response was not read by the client at the specified minimum data rate."); protected readonly ILogger _logger; @@ -160,6 +163,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal _requestBodyMinimumDataRateNotSatisfied(_logger, connectionId, traceIdentifier, rate, null); } + public void ResponseMininumDataRateNotSatisfied(string connectionId, string traceIdentifier) + { + _responseMinimumDataRateNotSatisfied(_logger, connectionId, traceIdentifier, null); + } + public virtual void Log(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func formatter) => _logger.Log(logLevel, eventId, state, exception, formatter); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/KestrelServerLimits.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/KestrelServerLimits.cs index 528f78be57..eb061cf500 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/KestrelServerLimits.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/KestrelServerLimits.cs @@ -263,5 +263,29 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core public MinDataRate MinRequestBodyDataRate { get; set; } = // Matches the default IIS minBytesPerSecond new MinDataRate(bytesPerSecond: 240, gracePeriod: TimeSpan.FromSeconds(5)); + + /// + /// Gets or sets the response minimum data rate in bytes/second. + /// Setting this property to null indicates no minimum data rate should be enforced. + /// This limit has no effect on upgraded connections which are always unlimited. + /// This can be overridden per-request via . + /// + /// + /// + /// Defaults to 240 bytes/second with a 5 second grace period. + /// + /// + /// Contrary to the request body minimum data rate, this rate applies to the response status line and headers as well. + /// + /// + /// This rate is enforced per write operation instead of being averaged over the life of the response. Whenever the server + /// writes a chunk of data, a timer is set to the maximum of the grace period set in this property or the length of the write in + /// bytes divided by the data rate (i.e. the maximum amount of time that write should take to complete with the specified data rate). + /// The connection is aborted if the write has not completed by the time that timer expires. + /// + /// + public MinDataRate MinResponseDataRate { get; set; } = + // Matches the default IIS minBytesPerSecond + new MinDataRate(bytesPerSecond: 240, gracePeriod: TimeSpan.FromSeconds(5)); } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/MinDataRate.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/MinDataRate.cs index 34cbdc577d..0e320b37f1 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/MinDataRate.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/MinDataRate.cs @@ -16,9 +16,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core /// starting at the time data is first read or written. public MinDataRate(double bytesPerSecond, TimeSpan gracePeriod) { - if (bytesPerSecond < 0) + if (bytesPerSecond <= 0) { - throw new ArgumentOutOfRangeException(nameof(bytesPerSecond), CoreStrings.NonNegativeNumberRequired); + throw new ArgumentOutOfRangeException(nameof(bytesPerSecond), CoreStrings.PositiveNumberOrNullMinDataRateRequired); } if (gracePeriod <= Heartbeat.Interval) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Properties/CoreStrings.Designer.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Properties/CoreStrings.Designer.cs index aa43e6b644..4598adc6fa 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Properties/CoreStrings.Designer.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Properties/CoreStrings.Designer.cs @@ -1060,6 +1060,20 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core internal static string FormatSynchronousWritesDisallowed() => GetString("SynchronousWritesDisallowed"); + /// + /// Value must be a positive number. To disable a minimum data rate, use null where a MinDataRate instance is expected. + /// + internal static string PositiveNumberOrNullMinDataRateRequired + { + get => GetString("PositiveNumberOrNullMinDataRateRequired"); + } + + /// + /// Value must be a positive number. To disable a minimum data rate, use null where a MinDataRate instance is expected. + /// + internal static string FormatPositiveNumberOrNullMinDataRateRequired() + => GetString("PositiveNumberOrNullMinDataRateRequired"); + private static string GetString(string name, params string[] formatterNames) { var value = _resourceManager.GetString(name); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvAwaitable.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvAwaitable.cs index 7029a1c32e..8ee11ff42e 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvAwaitable.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvAwaitable.cs @@ -79,4 +79,4 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal Error = error; } } -} \ No newline at end of file +} diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvConnection.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvConnection.cs index 2052ac45f2..2bac70080e 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvConnection.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvConnection.cs @@ -60,28 +60,26 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal StartReading(); + Exception error = null; + try { // This *must* happen after socket.ReadStart // The socket output consumer is the only thing that can close the connection. If the // output pipe is already closed by the time we start then it's fine since, it'll close gracefully afterwards. await Output.WriteOutputAsync(); - - // Now, complete the input so that no more reads can happen - Input.Complete(new ConnectionAbortedException()); - _connectionContext.Output.Complete(); - _connectionContext.OnConnectionClosed(ex: null); } catch (UvException ex) { - var ioEx = new IOException(ex.Message, ex); - - Input.Complete(ioEx); - _connectionContext.Output.Complete(ioEx); - _connectionContext.OnConnectionClosed(ioEx); + error = new IOException(ex.Message, ex); } finally { + // Now, complete the input so that no more reads can happen + Input.Complete(error ?? new ConnectionAbortedException()); + _connectionContext.Output.Complete(error); + _connectionContext.OnConnectionClosed(error); + // Make sure it isn't possible for a paused read to resume reading after calling uv_close // on the stream handle Input.CancelPendingFlush(); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvOutputConsumer.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvOutputConsumer.cs index c49b5bde5b..957ceb9595 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvOutputConsumer.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvOutputConsumer.cs @@ -4,7 +4,6 @@ using System; using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; -using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking; namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal @@ -29,6 +28,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal _socket = socket; _connectionId = connectionId; _log = log; + + _pipe.OnWriterCompleted(OnWriterCompleted, this); } public async Task WriteOutputAsync() @@ -37,7 +38,18 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal while (true) { - var result = await _pipe.ReadAsync(); + ReadResult result; + + try + { + result = await _pipe.ReadAsync(); + } + catch + { + // Handled in OnWriterCompleted + return; + } + var buffer = result.Buffer; var consumed = buffer.End; @@ -54,6 +66,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal try { + if (_socket.IsClosed) + { + break; + } + var writeResult = await writeReq.WriteAsync(_socket, buffer); LogWriteInfo(writeResult.Status, writeResult.Error); @@ -82,6 +99,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal } } + private static void OnWriterCompleted(Exception ex, object state) + { + // Cut off writes if the writer is completed with an error. If a write request is pending, this will cancel it. + if (ex != null) + { + var libuvOutputConsumer = (LibuvOutputConsumer)state; + libuvOutputConsumer._socket.Dispose(); + } + } + private void LogWriteInfo(int status, Exception error) { if (error == null) diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameConnectionTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameConnectionTests.cs index 790ce56d7e..8c1d74eb24 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameConnectionTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameConnectionTests.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; +using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal; @@ -129,7 +130,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests var mockLogger = new Mock(); _frameConnectionContext.ServiceContext.Log = mockLogger.Object; - _frameConnection.CreateFrame(new DummyApplication(context => Task.CompletedTask), _frameConnectionContext.Input.Reader, _frameConnectionContext.Output); + _frameConnection.CreateFrame(new DummyApplication(), _frameConnectionContext.Input.Reader, _frameConnectionContext.Output); _frameConnection.Frame.Reset(); // Initialize timestamp @@ -171,7 +172,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests var mockLogger = new Mock(); _frameConnectionContext.ServiceContext.Log = mockLogger.Object; - _frameConnection.CreateFrame(new DummyApplication(context => Task.CompletedTask), _frameConnectionContext.Input.Reader, _frameConnectionContext.Output); + _frameConnection.CreateFrame(new DummyApplication(), _frameConnectionContext.Input.Reader, _frameConnectionContext.Output); _frameConnection.Frame.Reset(); // Initialize timestamp @@ -248,7 +249,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests var mockLogger = new Mock(); _frameConnectionContext.ServiceContext.Log = mockLogger.Object; - _frameConnection.CreateFrame(new DummyApplication(context => Task.CompletedTask), _frameConnectionContext.Input.Reader, _frameConnectionContext.Output); + _frameConnection.CreateFrame(new DummyApplication(), _frameConnectionContext.Input.Reader, _frameConnectionContext.Output); _frameConnection.Frame.Reset(); // Initialize timestamp @@ -316,7 +317,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests var mockLogger = new Mock(); _frameConnectionContext.ServiceContext.Log = mockLogger.Object; - _frameConnection.CreateFrame(new DummyApplication(context => Task.CompletedTask), _frameConnectionContext.Input.Reader, _frameConnectionContext.Output); + _frameConnection.CreateFrame(new DummyApplication(), _frameConnectionContext.Input.Reader, _frameConnectionContext.Output); _frameConnection.Frame.Reset(); // Initialize timestamp @@ -364,5 +365,169 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests logger => logger.RequestBodyMininumDataRateNotSatisfied(It.IsAny(), It.IsAny(), It.IsAny()), Times.Once); } + + [Fact] + public void ReadTimingNotEnforcedWhenTimeoutIsSet() + { + var systemClock = new MockSystemClock(); + var timeout = TimeSpan.FromSeconds(5); + + _frameConnectionContext.ServiceContext.ServerOptions.Limits.MinRequestBodyDataRate = + new MinDataRate(bytesPerSecond: 100, gracePeriod: TimeSpan.FromSeconds(2)); + _frameConnectionContext.ServiceContext.SystemClock = systemClock; + + var mockLogger = new Mock(); + _frameConnectionContext.ServiceContext.Log = mockLogger.Object; + + _frameConnection.CreateFrame(new DummyApplication(), _frameConnectionContext.Input.Reader, _frameConnectionContext.Output); + _frameConnection.Frame.Reset(); + + var startTime = systemClock.UtcNow; + + // Initialize timestamp + _frameConnection.Tick(startTime); + + _frameConnection.StartTimingReads(); + + _frameConnection.SetTimeout(timeout.Ticks, TimeoutAction.CloseConnection); + + // Tick beyond grace period with low data rate + systemClock.UtcNow += TimeSpan.FromSeconds(3); + _frameConnection.BytesRead(1); + _frameConnection.Tick(systemClock.UtcNow); + + // Not timed out + Assert.False(_frameConnection.TimedOut); + + // Tick just past timeout period, adjusted by Heartbeat.Interval + systemClock.UtcNow = startTime + timeout + Heartbeat.Interval + TimeSpan.FromTicks(1); + _frameConnection.Tick(systemClock.UtcNow); + + // Timed out + Assert.True(_frameConnection.TimedOut); + } + + [Fact] + public void WriteTimingAbortsConnectionWhenWriteDoesNotCompleteWithMinimumDataRate() + { + var systemClock = new MockSystemClock(); + var aborted = new ManualResetEventSlim(); + + _frameConnectionContext.ServiceContext.ServerOptions.Limits.MinResponseDataRate = + new MinDataRate(bytesPerSecond: 100, gracePeriod: TimeSpan.FromSeconds(2)); + _frameConnectionContext.ServiceContext.SystemClock = systemClock; + + var mockLogger = new Mock(); + _frameConnectionContext.ServiceContext.Log = mockLogger.Object; + + _frameConnection.CreateFrame(new DummyApplication(), _frameConnectionContext.Input.Reader, _frameConnectionContext.Output); + _frameConnection.Frame.Reset(); + _frameConnection.Frame.RequestAborted.Register(() => + { + aborted.Set(); + }); + + // Initialize timestamp + _frameConnection.Tick(systemClock.UtcNow); + + // Should complete within 4 seconds, but the timeout is adjusted by adding Heartbeat.Interval + _frameConnection.StartTimingWrite(400); + + // Tick just past 4s plus Heartbeat.Interval + systemClock.UtcNow += TimeSpan.FromSeconds(4) + Heartbeat.Interval + TimeSpan.FromTicks(1); + _frameConnection.Tick(systemClock.UtcNow); + + Assert.True(_frameConnection.TimedOut); + Assert.True(aborted.Wait(TimeSpan.FromSeconds(10))); + } + + [Fact] + public void WriteTimingAbortsConnectionWhenSmallWriteDoesNotCompleteWithinGracePeriod() + { + var systemClock = new MockSystemClock(); + var minResponseDataRate = new MinDataRate(bytesPerSecond: 100, gracePeriod: TimeSpan.FromSeconds(5)); + var aborted = new ManualResetEventSlim(); + + _frameConnectionContext.ServiceContext.ServerOptions.Limits.MinResponseDataRate = minResponseDataRate; + _frameConnectionContext.ServiceContext.SystemClock = systemClock; + + var mockLogger = new Mock(); + _frameConnectionContext.ServiceContext.Log = mockLogger.Object; + + _frameConnection.CreateFrame(new DummyApplication(), _frameConnectionContext.Input.Reader, _frameConnectionContext.Output); + _frameConnection.Frame.Reset(); + _frameConnection.Frame.RequestAborted.Register(() => + { + aborted.Set(); + }); + + // Initialize timestamp + var startTime = systemClock.UtcNow; + _frameConnection.Tick(startTime); + + // Should complete within 1 second, but the timeout is adjusted by adding Heartbeat.Interval + _frameConnection.StartTimingWrite(100); + + // Tick just past 1s plus Heartbeat.Interval + systemClock.UtcNow += TimeSpan.FromSeconds(1) + Heartbeat.Interval + TimeSpan.FromTicks(1); + _frameConnection.Tick(systemClock.UtcNow); + + // Still within grace period, not timed out + Assert.False(_frameConnection.TimedOut); + + // Tick just past grace period (adjusted by Heartbeat.Interval) + systemClock.UtcNow = startTime + minResponseDataRate.GracePeriod + Heartbeat.Interval + TimeSpan.FromTicks(1); + _frameConnection.Tick(systemClock.UtcNow); + + Assert.True(_frameConnection.TimedOut); + Assert.True(aborted.Wait(TimeSpan.FromSeconds(10))); + } + + [Fact] + public void WriteTimingTimeoutPushedOnConcurrentWrite() + { + var systemClock = new MockSystemClock(); + var aborted = new ManualResetEventSlim(); + + _frameConnectionContext.ServiceContext.ServerOptions.Limits.MinResponseDataRate = + new MinDataRate(bytesPerSecond: 100, gracePeriod: TimeSpan.FromSeconds(2)); + _frameConnectionContext.ServiceContext.SystemClock = systemClock; + + var mockLogger = new Mock(); + _frameConnectionContext.ServiceContext.Log = mockLogger.Object; + + _frameConnection.CreateFrame(new DummyApplication(), _frameConnectionContext.Input.Reader, _frameConnectionContext.Output); + _frameConnection.Frame.Reset(); + _frameConnection.Frame.RequestAborted.Register(() => + { + aborted.Set(); + }); + + // Initialize timestamp + _frameConnection.Tick(systemClock.UtcNow); + + // Should complete within 5 seconds, but the timeout is adjusted by adding Heartbeat.Interval + _frameConnection.StartTimingWrite(500); + + // Start a concurrent write after 3 seconds, which should complete within 3 seconds (adjusted by Heartbeat.Interval) + _frameConnection.StartTimingWrite(300); + + // Tick just past 5s plus Heartbeat.Interval, when the first write should have completed + systemClock.UtcNow += TimeSpan.FromSeconds(5) + Heartbeat.Interval + TimeSpan.FromTicks(1); + _frameConnection.Tick(systemClock.UtcNow); + + // Not timed out because the timeout was pushed by the second write + Assert.False(_frameConnection.TimedOut); + + // Complete the first write, this should have no effect on the timeout + _frameConnection.StopTimingWrite(); + + // Tick just past +3s, when the second write should have completed + systemClock.UtcNow += TimeSpan.FromSeconds(3) + TimeSpan.FromTicks(1); + _frameConnection.Tick(systemClock.UtcNow); + + Assert.True(_frameConnection.TimedOut); + Assert.True(aborted.Wait(TimeSpan.FromSeconds(10))); + } } } diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameTests.cs index bd368df0c6..9531abb48e 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameTests.cs @@ -147,7 +147,17 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests _frame.Reset(); - Assert.Equal(_serviceContext.ServerOptions.Limits.MinRequestBodyDataRate, _frame.MinRequestBodyDataRate); + Assert.Same(_serviceContext.ServerOptions.Limits.MinRequestBodyDataRate, _frame.MinRequestBodyDataRate); + } + + [Fact] + public void ResetResetsMinResponseDataRate() + { + _frame.MinResponseDataRate = new MinDataRate(bytesPerSecond: 1, gracePeriod: TimeSpan.MaxValue); + + _frame.Reset(); + + Assert.Same(_serviceContext.ServerOptions.Limits.MinResponseDataRate, _frame.MinResponseDataRate); } [Fact] @@ -254,7 +264,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests } [Theory] - [MemberData(nameof(MinRequestBodyDataRateData))] + [MemberData(nameof(MinDataRateData))] public void ConfiguringIHttpMinRequestBodyDataRateFeatureSetsMinRequestBodyDataRate(MinDataRate minDataRate) { ((IFeatureCollection)_frame).Get().MinDataRate = minDataRate; @@ -262,6 +272,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests Assert.Same(minDataRate, _frame.MinRequestBodyDataRate); } + [Theory] + [MemberData(nameof(MinDataRateData))] + public void ConfiguringIHttpMinResponseDataRateFeatureSetsMinResponseDataRate(MinDataRate minDataRate) + { + ((IFeatureCollection)_frame).Get().MinDataRate = minDataRate; + + Assert.Same(minDataRate, _frame.MinResponseDataRate); + } + [Fact] public void ResetResetsRequestHeaders() { @@ -878,7 +897,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests TimeSpan.Zero }; - public static TheoryData MinRequestBodyDataRateData => new TheoryData + public static TheoryData MinDataRateData => new TheoryData { null, new MinDataRate(bytesPerSecond: 1, gracePeriod: TimeSpan.MaxValue) diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/KestrelServerLimitsTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/KestrelServerLimitsTests.cs index bab86a04e7..66de5d41e5 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/KestrelServerLimitsTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/KestrelServerLimitsTests.cs @@ -300,6 +300,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests Assert.Equal(TimeSpan.FromSeconds(5), new KestrelServerLimits().MinRequestBodyDataRate.GracePeriod); } + [Fact] + public void MinResponseBodyDataRateDefault() + { + Assert.NotNull(new KestrelServerLimits().MinResponseDataRate); + Assert.Equal(240, new KestrelServerLimits().MinResponseDataRate.BytesPerSecond); + Assert.Equal(TimeSpan.FromSeconds(5), new KestrelServerLimits().MinResponseDataRate.GracePeriod); + } + public static TheoryData TimeoutValidData => new TheoryData { TimeSpan.FromTicks(1), diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/MinDataRateTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/MinDataRateTests.cs index bd21c01f6d..a87bfa7709 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/MinDataRateTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/MinDataRateTests.cs @@ -10,7 +10,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests public class MinDataRateTests { [Theory] - [InlineData(0)] [InlineData(double.Epsilon)] [InlineData(double.MaxValue)] public void BytesPerSecondValid(double value) @@ -21,12 +20,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests [Theory] [InlineData(double.MinValue)] [InlineData(-double.Epsilon)] + [InlineData(0)] public void BytesPerSecondInvalid(double value) { var exception = Assert.Throws(() => new MinDataRate(bytesPerSecond: value, gracePeriod: TimeSpan.MaxValue)); Assert.Equal("bytesPerSecond", exception.ParamName); - Assert.StartsWith(CoreStrings.NonNegativeNumberRequired, exception.Message); + Assert.StartsWith(CoreStrings.PositiveNumberOrNullMinDataRateRequired, exception.Message); } [Theory] diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/OutputProducerTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/OutputProducerTests.cs index 0298bbff95..027e26f44e 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/OutputProducerTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/OutputProducerTests.cs @@ -54,16 +54,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests { var pipe = _pipeFactory.Create(pipeOptions); var serviceContext = new TestServiceContext(); - var frameContext = new FrameContext - { - ServiceContext = serviceContext, - ConnectionInformation = new MockConnectionInformation - { - PipeFactory = _pipeFactory - } - }; - var frame = new Frame(null, frameContext); - var socketOutput = new OutputProducer(pipe, "0", serviceContext.Log); + var socketOutput = new OutputProducer( + pipe, + "0", + serviceContext.Log, + Mock.Of()); return socketOutput; } diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs index 4fb7a4bc86..8d8f997b03 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs @@ -1519,10 +1519,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests // Synchronous reads now throw. var ioEx = Assert.Throws(() => context.Request.Body.Read(new byte[1], 0, 1)); - Assert.Equal("Synchronous operations are disallowed. Call ReadAsync or set AllowSynchronousIO to true instead.", ioEx.Message); + Assert.Equal(CoreStrings.SynchronousReadsDisallowed, ioEx.Message); var ioEx2 = Assert.Throws(() => context.Request.Body.CopyTo(Stream.Null)); - Assert.Equal("Synchronous operations are disallowed. Call ReadAsync or set AllowSynchronousIO to true instead.", ioEx2.Message); + Assert.Equal(CoreStrings.SynchronousReadsDisallowed, ioEx2.Message); while (offset < 5) { @@ -1578,10 +1578,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests // Synchronous reads now throw. var ioEx = Assert.Throws(() => context.Request.Body.Read(new byte[1], 0, 1)); - Assert.Equal("Synchronous operations are disallowed. Call ReadAsync or set AllowSynchronousIO to true instead.", ioEx.Message); + Assert.Equal(CoreStrings.SynchronousReadsDisallowed, ioEx.Message); var ioEx2 = Assert.Throws(() => context.Request.Body.CopyTo(Stream.Null)); - Assert.Equal("Synchronous operations are disallowed. Call ReadAsync or set AllowSynchronousIO to true instead.", ioEx2.Message); + Assert.Equal(CoreStrings.SynchronousReadsDisallowed, ioEx2.Message); var buffer = new byte[5]; var offset = 0; diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs index f43a1e5c2b..7f26aec3bf 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs @@ -7,7 +7,10 @@ using System.IO; using System.Linq; using System.Net; using System.Net.Http; +using System.Net.Security; using System.Net.Sockets; +using System.Security.Authentication; +using System.Security.Cryptography.X509Certificates; using System.Text; using System.Threading; using System.Threading.Tasks; @@ -19,12 +22,15 @@ using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Https; +using Microsoft.AspNetCore.Server.Kestrel.Https.Internal; using Microsoft.AspNetCore.Testing; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Primitives; using Moq; using Xunit; +using Xunit.Sdk; namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { @@ -2371,7 +2377,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests // Synchronous writes now throw. var ioEx = Assert.Throws(() => context.Response.Body.Write(Encoding.ASCII.GetBytes("What!?"), 0, 6)); - Assert.Equal("Synchronous operations are disallowed. Call WriteAsync or set AllowSynchronousIO to true instead.", ioEx.Message); + Assert.Equal(CoreStrings.SynchronousWritesDisallowed, ioEx.Message); await context.Response.Body.WriteAsync(Encoding.ASCII.GetBytes("Hello2"), 0, 6); } @@ -2415,7 +2421,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests // Synchronous writes now throw. var ioEx = Assert.Throws(() => context.Response.Body.Write(Encoding.ASCII.GetBytes("What!?"), 0, 6)); - Assert.Equal("Synchronous operations are disallowed. Call WriteAsync or set AllowSynchronousIO to true instead.", ioEx.Message); + Assert.Equal(CoreStrings.SynchronousWritesDisallowed, ioEx.Message); return context.Response.Body.WriteAsync(Encoding.ASCII.GetBytes("Hello!"), 0, 6); }, testContext)) @@ -2437,6 +2443,152 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } } + [Fact] + public async Task ConnectionClosedWhenResponseDoesNotSatisfyMinimumDataRate() + { + var chunkSize = 64 * 1024; + var chunks = 128; + + var messageLogged = new ManualResetEventSlim(); + + var mockKestrelTrace = new Mock(); + mockKestrelTrace + .Setup(trace => trace.ResponseMininumDataRateNotSatisfied(It.IsAny(), It.IsAny())) + .Callback(() => messageLogged.Set()); + + var testContext = new TestServiceContext + { + Log = mockKestrelTrace.Object, + SystemClock = new SystemClock(), + ServerOptions = + { + Limits = + { + MinResponseDataRate = new MinDataRate(bytesPerSecond: double.MaxValue, gracePeriod: TimeSpan.FromSeconds(2)) + } + } + }; + + var aborted = new ManualResetEventSlim(); + + using (var server = new TestServer(async context => + { + context.RequestAborted.Register(() => + { + aborted.Set(); + }); + + context.Response.ContentLength = chunks * chunkSize; + + for (var i = 0; i < chunks; i++) + { + await context.Response.WriteAsync(new string('a', chunkSize), context.RequestAborted); + } + }, testContext)) + { + using (var connection = server.CreateConnection()) + { + await connection.Send( + "GET / HTTP/1.1", + "Host:", + "", + ""); + + Assert.True(aborted.Wait(TimeSpan.FromSeconds(60))); + + await connection.Receive( + "HTTP/1.1 200 OK", + ""); + await connection.ReceiveStartsWith("Date: "); + await connection.Receive( + $"Content-Length: {chunks * chunkSize}", + "", + ""); + + await Assert.ThrowsAsync(async () => await connection.ReceiveForcedEnd( + new string('a', chunks * chunkSize))); + + Assert.True(messageLogged.Wait(TimeSpan.FromSeconds(10))); + } + } + } + + [Fact] + public async Task HttpsConnectionClosedWhenResponseDoesNotSatisfyMinimumDataRate() + { + const int chunkSize = 64 * 1024; + const int chunks = 128; + + var certificate = new X509Certificate2(TestResources.TestCertificatePath, "testPassword"); + + var messageLogged = new ManualResetEventSlim(); + var aborted = new ManualResetEventSlim(); + + var mockKestrelTrace = new Mock(); + mockKestrelTrace + .Setup(trace => trace.ResponseMininumDataRateNotSatisfied(It.IsAny(), It.IsAny())) + .Callback(() => messageLogged.Set()); + + var testContext = new TestServiceContext + { + Log = mockKestrelTrace.Object, + SystemClock = new SystemClock(), + ServerOptions = + { + Limits = + { + MinResponseDataRate = new MinDataRate(bytesPerSecond: double.MaxValue, gracePeriod: TimeSpan.FromSeconds(2)) + } + } + }; + + var listenOptions = new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0)) + { + ConnectionAdapters = + { + new HttpsConnectionAdapter(new HttpsConnectionAdapterOptions { ServerCertificate = certificate }) + } + }; + + using (var server = new TestServer(async context => + { + context.RequestAborted.Register(() => + { + aborted.Set(); + }); + + context.Response.ContentLength = chunks * chunkSize; + + for (var i = 0; i < chunks; i++) + { + await context.Response.WriteAsync(new string('a', chunkSize), context.RequestAborted); + } + }, testContext, listenOptions)) + { + using (var client = new TcpClient()) + { + await client.ConnectAsync(IPAddress.Loopback, server.Port); + + using (var sslStream = new SslStream(client.GetStream(), false, (sender, cert, chain, errors) => true, null)) + { + await sslStream.AuthenticateAsClientAsync("localhost", new X509CertificateCollection(), SslProtocols.Tls12 | SslProtocols.Tls11, false); + + var request = Encoding.ASCII.GetBytes("GET / HTTP/1.1\r\nHost:\r\n\r\n"); + await sslStream.WriteAsync(request, 0, request.Length); + + Assert.True(aborted.Wait(TimeSpan.FromSeconds(60))); + + using (var reader = new StreamReader(sslStream, encoding: Encoding.ASCII, detectEncodingFromByteOrderMarks: false, bufferSize: 1024, leaveOpen: false)) + { + await reader.ReadToEndAsync().TimeoutAfter(TimeSpan.FromSeconds(30)); + } + + Assert.True(messageLogged.Wait(TimeSpan.FromSeconds(10))); + } + } + } + } + public static TheoryData NullHeaderData { get diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Mocks/MockTimeoutControl.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Mocks/MockTimeoutControl.cs index 8bfd08387e..e0a54ef642 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Mocks/MockTimeoutControl.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Mocks/MockTimeoutControl.cs @@ -40,5 +40,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance.Mocks public void BytesRead(int count) { } + + public void StartTimingWrite(int size) + { + } + + public void StopTimingWrite() + { + } } } diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Mocks/MockTrace.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Mocks/MockTrace.cs index 480ec400a3..77290ee718 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Mocks/MockTrace.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Mocks/MockTrace.cs @@ -39,5 +39,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance public void RequestBodyStart(string connectionId, string traceIdentifier) { } public void RequestBodyDone(string connectionId, string traceIdentifier) { } public void RequestBodyMininumDataRateNotSatisfied(string connectionId, string traceIdentifier, double rate) { } + public void ResponseMininumDataRateNotSatisfied(string connectionId, string traceIdentifier) { } } } diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/LibuvOutputConsumerTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/LibuvOutputConsumerTests.cs index 2d565d7168..c91ef7994f 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/LibuvOutputConsumerTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/LibuvOutputConsumerTests.cs @@ -67,14 +67,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests MaximumSizeLow = maxResponseBufferSize ?? 0, }; - using (var socketOutput = CreateOutputProducer(pipeOptions)) + using (var outputProducer = CreateOutputProducer(pipeOptions)) { // At least one run of this test should have a MaxResponseBufferSize < 1 MB. var bufferSize = 1024 * 1024; var buffer = new ArraySegment(new byte[bufferSize], 0, bufferSize); // Act - var writeTask = socketOutput.WriteAsync(buffer); + var writeTask = outputProducer.WriteAsync(buffer); // Assert await writeTask.TimeoutAfter(TimeSpan.FromSeconds(5)); @@ -102,20 +102,20 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests MaximumSizeLow = 0, }; - using (var socketOutput = CreateOutputProducer(pipeOptions)) + using (var outputProducer = CreateOutputProducer(pipeOptions)) { // Don't want to allocate anything too huge for perf. This is at least larger than the default buffer. var bufferSize = 1024 * 1024; var buffer = new ArraySegment(new byte[bufferSize], 0, bufferSize); // Act - var writeTask = socketOutput.WriteAsync(buffer); + var writeTask = outputProducer.WriteAsync(buffer); // Assert await writeTask.TimeoutAfter(TimeSpan.FromSeconds(5)); // Cleanup - socketOutput.Dispose(); + outputProducer.Dispose(); // Wait for all writes to complete so the completeQueue isn't modified during enumeration. await _mockLibuv.OnPostTask; @@ -149,13 +149,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests MaximumSizeLow = 1, }; - using (var socketOutput = CreateOutputProducer(pipeOptions)) + using (var outputProducer = CreateOutputProducer(pipeOptions)) { var bufferSize = 1; var buffer = new ArraySegment(new byte[bufferSize], 0, bufferSize); // Act - var writeTask = socketOutput.WriteAsync(buffer); + var writeTask = outputProducer.WriteAsync(buffer); // Assert Assert.False(writeTask.IsCompleted); @@ -171,7 +171,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests await writeTask.TimeoutAfter(TimeSpan.FromSeconds(5)); // Cleanup - socketOutput.Dispose(); + outputProducer.Dispose(); // Wait for all writes to complete so the completeQueue isn't modified during enumeration. await _mockLibuv.OnPostTask; @@ -204,20 +204,20 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests MaximumSizeLow = maxResponseBufferSize, }; - using (var socketOutput = CreateOutputProducer(pipeOptions)) + using (var outputProducer = CreateOutputProducer(pipeOptions)) { var bufferSize = maxResponseBufferSize - 1; var buffer = new ArraySegment(new byte[bufferSize], 0, bufferSize); // Act - var writeTask1 = socketOutput.WriteAsync(buffer); + var writeTask1 = outputProducer.WriteAsync(buffer); // Assert // The first write should pre-complete since it is <= _maxBytesPreCompleted. Assert.Equal(TaskStatus.RanToCompletion, writeTask1.Status); // Act - var writeTask2 = socketOutput.WriteAsync(buffer); + var writeTask2 = outputProducer.WriteAsync(buffer); await _mockLibuv.OnPostTask; // Assert @@ -232,7 +232,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests await writeTask2.TimeoutAfter(TimeSpan.FromSeconds(5)); // Cleanup - socketOutput.Dispose(); + outputProducer.Dispose(); // Wait for all writes to complete so the completeQueue isn't modified during enumeration. await _mockLibuv.OnPostTask; @@ -267,14 +267,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests MaximumSizeLow = maxResponseBufferSize, }; - using (var socketOutput = CreateOutputProducer(pipeOptions)) + using (var outputProducer = CreateOutputProducer(pipeOptions)) { var bufferSize = maxResponseBufferSize / 2; var data = new byte[bufferSize]; var halfWriteBehindBuffer = new ArraySegment(data, 0, bufferSize); // Act - var writeTask1 = socketOutput.WriteAsync(halfWriteBehindBuffer); + var writeTask1 = outputProducer.WriteAsync(halfWriteBehindBuffer); // Assert // The first write should pre-complete since it is <= _maxBytesPreCompleted. @@ -283,17 +283,17 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests Assert.NotEmpty(completeQueue); // Add more bytes to the write-behind buffer to prevent the next write from - socketOutput.Write((writableBuffer, state) => + outputProducer.Write((writableBuffer, state) => { writableBuffer.Write(state); }, halfWriteBehindBuffer); // Act - var writeTask2 = socketOutput.WriteAsync(halfWriteBehindBuffer); + var writeTask2 = outputProducer.WriteAsync(halfWriteBehindBuffer); Assert.False(writeTask2.IsCompleted); - var writeTask3 = socketOutput.WriteAsync(halfWriteBehindBuffer); + var writeTask3 = outputProducer.WriteAsync(halfWriteBehindBuffer); Assert.False(writeTask3.IsCompleted); // Drain the write queue @@ -336,7 +336,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests MaximumSizeLow = maxResponseBufferSize, }; - using (var socketOutput = CreateOutputProducer(pipeOptions, abortedSource)) + using (var outputProducer = CreateOutputProducer(pipeOptions, abortedSource)) { var bufferSize = maxResponseBufferSize - 1; @@ -344,7 +344,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests var fullBuffer = new ArraySegment(data, 0, bufferSize); // Act - var task1Success = socketOutput.WriteAsync(fullBuffer, cancellationToken: abortedSource.Token); + var task1Success = outputProducer.WriteAsync(fullBuffer, cancellationToken: abortedSource.Token); // task1 should complete successfully as < _maxBytesPreCompleted // First task is completed and successful @@ -353,8 +353,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests Assert.False(task1Success.IsFaulted); // following tasks should wait. - var task2Success = socketOutput.WriteAsync(fullBuffer); - var task3Canceled = socketOutput.WriteAsync(fullBuffer, cancellationToken: abortedSource.Token); + var task2Success = outputProducer.WriteAsync(fullBuffer); + var task3Canceled = outputProducer.WriteAsync(fullBuffer, cancellationToken: abortedSource.Token); // Give time for tasks to percolate await _mockLibuv.OnPostTask; @@ -382,7 +382,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests // A final write guarantees that the error is observed by OutputProducer, // but doesn't return a canceled/faulted task. - var task4Success = socketOutput.WriteAsync(fullBuffer, cancellationToken: default(CancellationToken)); + var task4Success = outputProducer.WriteAsync(fullBuffer, cancellationToken: default(CancellationToken)); Assert.True(task4Success.IsCompleted); Assert.False(task4Success.IsCanceled); Assert.False(task4Success.IsFaulted); @@ -428,7 +428,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests MaximumSizeLow = maxResponseBufferSize, }; - using (var socketOutput = CreateOutputProducer(pipeOptions)) + using (var outputProducer = CreateOutputProducer(pipeOptions)) { var bufferSize = maxResponseBufferSize - 1; @@ -436,7 +436,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests var fullBuffer = new ArraySegment(data, 0, bufferSize); // Act - var task1Success = socketOutput.WriteAsync(fullBuffer, cancellationToken: abortedSource.Token); + var task1Success = outputProducer.WriteAsync(fullBuffer, cancellationToken: abortedSource.Token); // task1 should complete successfully as < _maxBytesPreCompleted // First task is completed and successful @@ -445,7 +445,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests Assert.False(task1Success.IsFaulted); // following tasks should wait. - var task3Canceled = socketOutput.WriteAsync(fullBuffer, cancellationToken: abortedSource.Token); + var task3Canceled = outputProducer.WriteAsync(fullBuffer, cancellationToken: abortedSource.Token); // Give time for tasks to percolate await _mockLibuv.OnPostTask; @@ -465,7 +465,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests // A final write guarantees that the error is observed by OutputProducer, // but doesn't return a canceled/faulted task. - var task4Success = socketOutput.WriteAsync(fullBuffer); + var task4Success = outputProducer.WriteAsync(fullBuffer); Assert.True(task4Success.IsCompleted); Assert.False(task4Success.IsCanceled); Assert.False(task4Success.IsFaulted); @@ -511,7 +511,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests MaximumSizeLow = maxResponseBufferSize, }; - using (var socketOutput = CreateOutputProducer(pipeOptions)) + using (var outputProducer = CreateOutputProducer(pipeOptions)) { var bufferSize = maxResponseBufferSize; @@ -519,7 +519,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests var fullBuffer = new ArraySegment(data, 0, bufferSize); // Act - var task1Waits = socketOutput.WriteAsync(fullBuffer); + var task1Waits = outputProducer.WriteAsync(fullBuffer); // First task is not completed Assert.False(task1Waits.IsCompleted); @@ -527,7 +527,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests Assert.False(task1Waits.IsFaulted); // following tasks should wait. - var task3Canceled = socketOutput.WriteAsync(fullBuffer, cancellationToken: abortedSource.Token); + var task3Canceled = outputProducer.WriteAsync(fullBuffer, cancellationToken: abortedSource.Token); // Give time for tasks to percolate await _mockLibuv.OnPostTask; @@ -552,7 +552,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests // A final write guarantees that the error is observed by OutputProducer, // but doesn't return a canceled/faulted task. - var task4Success = socketOutput.WriteAsync(fullBuffer); + var task4Success = outputProducer.WriteAsync(fullBuffer); Assert.True(task4Success.IsCompleted); Assert.False(task4Success.IsCanceled); Assert.False(task4Success.IsFaulted); @@ -592,13 +592,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests MaximumSizeLow = maxResponseBufferSize, }; - using (var socketOutput = CreateOutputProducer(pipeOptions)) + using (var outputProducer = CreateOutputProducer(pipeOptions)) { var bufferSize = maxResponseBufferSize - 1; var buffer = new ArraySegment(new byte[bufferSize], 0, bufferSize); // Act (Pre-complete the maximum number of bytes in preparation for the rest of the test) - var writeTask1 = socketOutput.WriteAsync(buffer); + var writeTask1 = outputProducer.WriteAsync(buffer); // Assert // The first write should pre-complete since it is < _maxBytesPreCompleted. @@ -607,8 +607,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests Assert.NotEmpty(completeQueue); // Act - var writeTask2 = socketOutput.WriteAsync(buffer); - var writeTask3 = socketOutput.WriteAsync(buffer); + var writeTask2 = outputProducer.WriteAsync(buffer); + var writeTask3 = outputProducer.WriteAsync(buffer); await _mockLibuv.OnPostTask; @@ -652,7 +652,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests MaximumSizeLow = maxResponseBufferSize ?? 0, }; - using (var socketOutput = CreateOutputProducer(pipeOptions)) + using (var outputProducer = CreateOutputProducer(pipeOptions)) { _mockLibuv.KestrelThreadBlocker.Reset(); @@ -660,8 +660,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests // Two calls to WriteAsync trigger uv_write once if both calls // are made before write is scheduled - var ignore = socketOutput.WriteAsync(buffer); - ignore = socketOutput.WriteAsync(buffer); + var ignore = outputProducer.WriteAsync(buffer); + ignore = outputProducer.WriteAsync(buffer); _mockLibuv.KestrelThreadBlocker.Set(); @@ -736,4 +736,4 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests } } } -} +} \ No newline at end of file diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/TestHelpers/MockLibuv.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/TestHelpers/MockLibuv.cs index 8906dbd872..4f334bcfea 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/TestHelpers/MockLibuv.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/TestHelpers/MockLibuv.cs @@ -38,18 +38,29 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests.TestHelpers _uv_async_send = postHandle => { - lock (_postLock) + // Attempt to run the async send logic inline; this should succeed most of the time. + // In the rare cases where it fails to acquire the lock, use Task.Run() so this call + // never blocks, since the real libuv never blocks. + if (Monitor.TryEnter(_postLock)) { - if (_completedOnPostTcs) + try { - _onPostTcs = new TaskCompletionSource(); - _completedOnPostTcs = false; + UvAsyncSend(); } - - PostCount++; - - _sendCalled = true; - _loopWh.Set(); + finally + { + Monitor.Exit(_postLock); + } + } + else + { + Task.Run(() => + { + lock (_postLock) + { + UvAsyncSend(); + } + }); } return 0; @@ -160,5 +171,19 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests.TestHelpers { return OnWrite(handle, nbufs, status => cb(req.InternalGetHandle(), status)); } + + private void UvAsyncSend() + { + if (_completedOnPostTcs) + { + _onPostTcs = new TaskCompletionSource(); + _completedOnPostTcs = false; + } + + PostCount++; + + _sendCalled = true; + _loopWh.Set(); + } } } diff --git a/test/shared/TestServiceContext.cs b/test/shared/TestServiceContext.cs index 696178c0fa..2d9b772e43 100644 --- a/test/shared/TestServiceContext.cs +++ b/test/shared/TestServiceContext.cs @@ -1,6 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; diff --git a/tools/CodeGenerator/FrameFeatureCollection.cs b/tools/CodeGenerator/FrameFeatureCollection.cs index 5d5f83c11a..5fd8d0a8f5 100644 --- a/tools/CodeGenerator/FrameFeatureCollection.cs +++ b/tools/CodeGenerator/FrameFeatureCollection.cs @@ -48,6 +48,7 @@ namespace CodeGenerator typeof(ISessionFeature), typeof(IHttpMaxRequestBodySizeFeature), typeof(IHttpMinRequestBodyDataRateFeature), + typeof(IHttpMinResponseDataRateFeature), typeof(IHttpBodyControlFeature), }; @@ -70,6 +71,7 @@ namespace CodeGenerator typeof(IHttpConnectionFeature), typeof(IHttpMaxRequestBodySizeFeature), typeof(IHttpMinRequestBodyDataRateFeature), + typeof(IHttpMinResponseDataRateFeature), typeof(IHttpBodyControlFeature), }; From 5b8d876d551ac29d361e49ac51ac0d0917d662e3 Mon Sep 17 00:00:00 2001 From: Pranav K Date: Mon, 10 Jul 2017 11:43:55 -0700 Subject: [PATCH 1349/1662] Branching for 2.0.0 rtm --- NuGet.config | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NuGet.config b/NuGet.config index 4e8a1f6de1..37f0d27ea0 100644 --- a/NuGet.config +++ b/NuGet.config @@ -2,7 +2,7 @@ - + From 3dc1b5df52a2c6ffacbe7ea02609b5c0926e9698 Mon Sep 17 00:00:00 2001 From: Pranav K Date: Mon, 10 Jul 2017 11:57:58 -0700 Subject: [PATCH 1350/1662] Updating KoreBuild branch --- build.ps1 | 2 +- build.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/build.ps1 b/build.ps1 index 5bf0e2c113..1785334385 100644 --- a/build.ps1 +++ b/build.ps1 @@ -33,7 +33,7 @@ cd $PSScriptRoot $repoFolder = $PSScriptRoot $env:REPO_FOLDER = $repoFolder -$koreBuildZip="https://github.com/aspnet/KoreBuild/archive/dev.zip" +$koreBuildZip="https://github.com/aspnet/KoreBuild/archive/rel/2.0.0.zip" if ($env:KOREBUILD_ZIP) { $koreBuildZip=$env:KOREBUILD_ZIP diff --git a/build.sh b/build.sh index b0bcadb579..5e27ed8efb 100755 --- a/build.sh +++ b/build.sh @@ -2,7 +2,7 @@ repoFolder="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" cd $repoFolder -koreBuildZip="https://github.com/aspnet/KoreBuild/archive/dev.zip" +koreBuildZip="https://github.com/aspnet/KoreBuild/archive/rel/2.0.0.zip" if [ ! -z $KOREBUILD_ZIP ]; then koreBuildZip=$KOREBUILD_ZIP fi From 6e70b1bccaf71555c3092f76f86df605533316e8 Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Mon, 10 Jul 2017 15:12:01 -0700 Subject: [PATCH 1351/1662] Fix flakiness in MaxRequestBufferSizeTests.LargeUpload (#1850). --- .../AddressRegistrationTests.cs | 5 ++++- .../MaxRequestBufferSizeTests.cs | 14 ++++++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs index 35a472a0db..fbbd9038ab 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs @@ -34,7 +34,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests private readonly Action _configureLoggingDelegate; - public AddressRegistrationTests(ITestOutputHelper output) => _configureLoggingDelegate = builder => builder.AddXunit(output); + public AddressRegistrationTests(ITestOutputHelper output) + { + _configureLoggingDelegate = builder => builder.AddXunit(output); + } [ConditionalFact] [NetworkIsReachable] diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/MaxRequestBufferSizeTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/MaxRequestBufferSizeTests.cs index 6b3d66de1a..9cda0bbde0 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/MaxRequestBufferSizeTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/MaxRequestBufferSizeTests.cs @@ -13,7 +13,9 @@ using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Testing; +using Microsoft.Extensions.Logging; using Xunit; +using Xunit.Abstractions; namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { @@ -28,6 +30,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests "\r\n" }; + private readonly Action _configureLoggingDelegate; + + public MaxRequestBufferSizeTests(ITestOutputHelper output) + { + _configureLoggingDelegate = builder => builder.AddXunit(output); + } + public static IEnumerable LargeUploadData { get @@ -243,13 +252,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } } - private static IWebHost StartWebHost(long? maxRequestBufferSize, + private IWebHost StartWebHost(long? maxRequestBufferSize, byte[] expectedBody, bool useConnectionAdapter, TaskCompletionSource startReadingRequestBody, TaskCompletionSource clientFinishedSendingRequestBody) { var host = new WebHostBuilder() + .ConfigureLogging(_configureLoggingDelegate) .UseKestrel(options => { options.Listen(new IPEndPoint(IPAddress.Loopback, 0), listenOptions => @@ -279,7 +289,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests .UseContentRoot(Directory.GetCurrentDirectory()) .Configure(app => app.Run(async context => { - await startReadingRequestBody.Task.TimeoutAfter(TimeSpan.FromSeconds(30)); + await startReadingRequestBody.Task.TimeoutAfter(TimeSpan.FromSeconds(120)); var buffer = new byte[expectedBody.Length]; var bytesRead = 0; From 1e8702f8bbbd486b920c1d77ccc5f506b70db393 Mon Sep 17 00:00:00 2001 From: Ryan Brandenburg Date: Fri, 7 Jul 2017 14:56:23 -0700 Subject: [PATCH 1352/1662] Skip first time experience on Appveyor --- appveyor.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/appveyor.yml b/appveyor.yml index b17fb327df..6f07ee6b3e 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,4 +1,4 @@ -init: +init: - git config --global core.autocrlf true branches: only: @@ -11,6 +11,10 @@ branches: build_script: - ps: .\build.ps1 clone_depth: 1 +environment: + global: + DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true + DOTNET_CLI_TELEMETRY_OPTOUT: 1 test: off deploy: off os: Visual Studio 2017 From b0dc76a6aed9a1664a3540b030f3b2adf8f194f7 Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Tue, 11 Jul 2017 12:59:29 -0700 Subject: [PATCH 1353/1662] Fix flakiness in RejectsRequestWithContentLengthAndUpgrade (#1742). --- .../UpgradeTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/UpgradeTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/UpgradeTests.cs index 8a24951173..f16c7c6466 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/UpgradeTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/UpgradeTests.cs @@ -163,7 +163,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests "Content-Length: 1", "Connection: Upgrade", "", - "1"); + ""); await connection.ReceiveForcedEnd( "HTTP/1.1 400 Bad Request", From fd1758fdfc15bce07269601c1c04acceb603d46d Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Tue, 11 Jul 2017 14:29:50 -0700 Subject: [PATCH 1354/1662] Make StopAsync multi-thread safe (#1666). --- .../KestrelServer.cs | 50 +++++---- .../KestrelServerTests.cs | 106 +++++++++++++++++- 2 files changed, 136 insertions(+), 20 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/KestrelServer.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/KestrelServer.cs index 9fad21da80..e52e3895ce 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/KestrelServer.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/KestrelServer.cs @@ -25,7 +25,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core private readonly ITransportFactory _transportFactory; private bool _hasStarted; - private int _stopped; + private int _stopping; + private readonly TaskCompletionSource _stoppedTcs = new TaskCompletionSource(); public KestrelServer(IOptions options, ITransportFactory transportFactory, ILoggerFactory loggerFactory) : this(transportFactory, CreateServiceContext(options, loggerFactory)) @@ -154,35 +155,46 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core // Graceful shutdown if possible public async Task StopAsync(CancellationToken cancellationToken) { - if (Interlocked.Exchange(ref _stopped, 1) == 1) + if (Interlocked.Exchange(ref _stopping, 1) == 1) { + await _stoppedTcs.Task.ConfigureAwait(false); return; } - var tasks = new Task[_transports.Count]; - for (int i = 0; i < _transports.Count; i++) + try { - tasks[i] = _transports[i].UnbindAsync(); - } - await Task.WhenAll(tasks).ConfigureAwait(false); - - if (!await ConnectionManager.CloseAllConnectionsAsync(cancellationToken).ConfigureAwait(false)) - { - Trace.NotAllConnectionsClosedGracefully(); - - if (!await ConnectionManager.AbortAllConnectionsAsync().ConfigureAwait(false)) + var tasks = new Task[_transports.Count]; + for (int i = 0; i < _transports.Count; i++) { - Trace.NotAllConnectionsAborted(); + tasks[i] = _transports[i].UnbindAsync(); } - } + await Task.WhenAll(tasks).ConfigureAwait(false); - for (int i = 0; i < _transports.Count; i++) + if (!await ConnectionManager.CloseAllConnectionsAsync(cancellationToken).ConfigureAwait(false)) + { + Trace.NotAllConnectionsClosedGracefully(); + + if (!await ConnectionManager.AbortAllConnectionsAsync().ConfigureAwait(false)) + { + Trace.NotAllConnectionsAborted(); + } + } + + for (int i = 0; i < _transports.Count; i++) + { + tasks[i] = _transports[i].StopAsync(); + } + await Task.WhenAll(tasks).ConfigureAwait(false); + + _heartbeat.Dispose(); + } + catch (Exception ex) { - tasks[i] = _transports[i].StopAsync(); + _stoppedTcs.TrySetException(ex); + throw; } - await Task.WhenAll(tasks).ConfigureAwait(false); - _heartbeat.Dispose(); + _stoppedTcs.TrySetResult(null); } // Ungraceful shutdown diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/KestrelServerTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/KestrelServerTests.cs index a9f7a39561..e948fb9ce2 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/KestrelServerTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/KestrelServerTests.cs @@ -9,7 +9,6 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting.Server; using Microsoft.AspNetCore.Hosting.Server.Features; -using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; using Microsoft.AspNetCore.Testing; using Microsoft.Extensions.Logging; @@ -165,6 +164,111 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests Assert.Equal("transportFactory", exception.ParamName); } + [Fact] + public async Task StopAsyncCallsCompleteWhenFirstCallCompletes() + { + var options = new KestrelServerOptions + { + ListenOptions = + { + new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0)) + } + }; + + var unbind = new SemaphoreSlim(0); + var stop = new SemaphoreSlim(0); + + var mockTransport = new Mock(); + mockTransport + .Setup(transport => transport.BindAsync()) + .Returns(Task.CompletedTask); + mockTransport + .Setup(transport => transport.UnbindAsync()) + .Returns(async () => await unbind.WaitAsync()); + mockTransport + .Setup(transport => transport.StopAsync()) + .Returns(async () => await stop.WaitAsync()); + + var mockTransportFactory = new Mock(); + mockTransportFactory + .Setup(transportFactory => transportFactory.Create(It.IsAny(), It.IsAny())) + .Returns(mockTransport.Object); + + var server = new KestrelServer(Options.Create(options), mockTransportFactory.Object, Mock.Of()); + await server.StartAsync(new DummyApplication(), CancellationToken.None); + + var stopTask1 = server.StopAsync(default(CancellationToken)); + var stopTask2 = server.StopAsync(default(CancellationToken)); + var stopTask3 = server.StopAsync(default(CancellationToken)); + + Assert.False(stopTask1.IsCompleted); + Assert.False(stopTask2.IsCompleted); + Assert.False(stopTask3.IsCompleted); + + unbind.Release(); + stop.Release(); + + await Task.WhenAll(new[] { stopTask1, stopTask2, stopTask3 }).TimeoutAfter(TimeSpan.FromSeconds(10)); + + mockTransport.Verify(transport => transport.UnbindAsync(), Times.Once); + mockTransport.Verify(transport => transport.StopAsync(), Times.Once); + } + + [Fact] + public async Task StopAsyncCallsCompleteWithThrownException() + { + var options = new KestrelServerOptions + { + ListenOptions = + { + new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0)) + } + }; + + var unbind = new SemaphoreSlim(0); + var unbindException = new InvalidOperationException(); + + var mockTransport = new Mock(); + mockTransport + .Setup(transport => transport.BindAsync()) + .Returns(Task.CompletedTask); + mockTransport + .Setup(transport => transport.UnbindAsync()) + .Returns(async () => + { + await unbind.WaitAsync(); + throw unbindException; + }); + mockTransport + .Setup(transport => transport.StopAsync()) + .Returns(Task.CompletedTask); + + var mockTransportFactory = new Mock(); + mockTransportFactory + .Setup(transportFactory => transportFactory.Create(It.IsAny(), It.IsAny())) + .Returns(mockTransport.Object); + + var server = new KestrelServer(Options.Create(options), mockTransportFactory.Object, Mock.Of()); + await server.StartAsync(new DummyApplication(), CancellationToken.None); + + var stopTask1 = server.StopAsync(default(CancellationToken)); + var stopTask2 = server.StopAsync(default(CancellationToken)); + var stopTask3 = server.StopAsync(default(CancellationToken)); + + Assert.False(stopTask1.IsCompleted); + Assert.False(stopTask2.IsCompleted); + Assert.False(stopTask3.IsCompleted); + + unbind.Release(); + + var timeout = TimeSpan.FromSeconds(10); + Assert.Same(unbindException, await Assert.ThrowsAsync(() => stopTask1.TimeoutAfter(timeout))); + Assert.Same(unbindException, await Assert.ThrowsAsync(() => stopTask2.TimeoutAfter(timeout))); + Assert.Same(unbindException, await Assert.ThrowsAsync(() => stopTask3.TimeoutAfter(timeout))); + + mockTransport.Verify(transport => transport.UnbindAsync(), Times.Once); + } + private static KestrelServer CreateServer(KestrelServerOptions options, ILogger testLogger) { return new KestrelServer(Options.Create(options), new MockTransportFactory(), new LoggerFactory(new [] { new KestrelTestLoggerProvider(testLogger)} )); From 7ebbdad9746f21b5966c62d68717fa68e21df72d Mon Sep 17 00:00:00 2001 From: David Fowler Date: Wed, 12 Jul 2017 11:45:08 -0700 Subject: [PATCH 1355/1662] Add support for connection scopes if logging is enabled (#1953) * Add support for connection scopes if logging is enabled - Don't create a scope if logging isn't on - Copied the pattern we use in Hosting --- .../Internal/ConnectionLogScope.cs | 63 +++++++++ .../Internal/FrameConnection.cs | 123 ++++++++++-------- .../FrameConnectionTests.cs | 22 ++++ test/shared/TestApplicationErrorLogger.cs | 3 + test/shared/TestServiceContext.cs | 13 +- 5 files changed, 168 insertions(+), 56 deletions(-) create mode 100644 src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/ConnectionLogScope.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/ConnectionLogScope.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/ConnectionLogScope.cs new file mode 100644 index 0000000000..3d1b882e82 --- /dev/null +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/ConnectionLogScope.cs @@ -0,0 +1,63 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Collections; +using System.Collections.Generic; +using System.Globalization; + +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal +{ + public class ConnectionLogScope : IReadOnlyList> + { + private readonly string _connectionId; + + private string _cachedToString; + + public ConnectionLogScope(string connectionId) + { + _connectionId = connectionId; + } + + public KeyValuePair this[int index] + { + get + { + if (index == 0) + { + return new KeyValuePair("ConnectionId", _connectionId); + } + + throw new ArgumentOutOfRangeException(nameof(index)); + } + } + + public int Count => 1; + + public IEnumerator> GetEnumerator() + { + for (int i = 0; i < Count; ++i) + { + yield return this[i]; + } + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + + public override string ToString() + { + if (_cachedToString == null) + { + _cachedToString = string.Format( + CultureInfo.InvariantCulture, + "ConnectionId:{0}", + _connectionId); + } + + return _cachedToString; + } + } +} diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnection.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnection.cs index 1574d3bf7e..85b754ce9c 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnection.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnection.cs @@ -2,8 +2,10 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Collections; using System.Collections.Generic; using System.Diagnostics; +using System.Globalization; using System.IO; using System.Threading; using System.Threading.Tasks; @@ -79,72 +81,75 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal public void StartRequestProcessing(IHttpApplication application) { - _lifetimeTask = ProcessRequestsAsync(application); + _lifetimeTask = ProcessRequestsAsync(application); } private async Task ProcessRequestsAsync(IHttpApplication application) { - try + using (BeginConnectionScope()) { - Log.ConnectionStart(ConnectionId); - KestrelEventSource.Log.ConnectionStart(this, _context.ConnectionInformation); - - AdaptedPipeline adaptedPipeline = null; - var adaptedPipelineTask = Task.CompletedTask; - var input = _context.Input.Reader; - var output = _context.Output; - - if (_context.ConnectionAdapters.Count > 0) + try { - adaptedPipeline = new AdaptedPipeline(input, - output, - PipeFactory.Create(AdaptedInputPipeOptions), - PipeFactory.Create(AdaptedOutputPipeOptions), - Log); + Log.ConnectionStart(ConnectionId); + KestrelEventSource.Log.ConnectionStart(this, _context.ConnectionInformation); - input = adaptedPipeline.Input.Reader; - output = adaptedPipeline.Output; + AdaptedPipeline adaptedPipeline = null; + var adaptedPipelineTask = Task.CompletedTask; + var input = _context.Input.Reader; + var output = _context.Output; + + if (_context.ConnectionAdapters.Count > 0) + { + adaptedPipeline = new AdaptedPipeline(input, + output, + PipeFactory.Create(AdaptedInputPipeOptions), + PipeFactory.Create(AdaptedOutputPipeOptions), + Log); + + input = adaptedPipeline.Input.Reader; + output = adaptedPipeline.Output; + } + + // _frame must be initialized before adding the connection to the connection manager + CreateFrame(application, input, output); + + // Do this before the first await so we don't yield control to the transport until we've + // added the connection to the connection manager + _context.ServiceContext.ConnectionManager.AddConnection(_context.FrameConnectionId, this); + _lastTimestamp = _context.ServiceContext.SystemClock.UtcNow.Ticks; + + if (adaptedPipeline != null) + { + // Stream can be null here and run async will close the connection in that case + var stream = await ApplyConnectionAdaptersAsync(); + adaptedPipelineTask = adaptedPipeline.RunAsync(stream); + } + + await _frame.ProcessRequestsAsync(); + await adaptedPipelineTask; + await _socketClosedTcs.Task; } - - // _frame must be initialized before adding the connection to the connection manager - CreateFrame(application, input, output); - - // Do this before the first await so we don't yield control to the transport until we've - // added the connection to the connection manager - _context.ServiceContext.ConnectionManager.AddConnection(_context.FrameConnectionId, this); - _lastTimestamp = _context.ServiceContext.SystemClock.UtcNow.Ticks; - - if (adaptedPipeline != null) + catch (Exception ex) { - // Stream can be null here and run async will close the connection in that case - var stream = await ApplyConnectionAdaptersAsync(); - adaptedPipelineTask = adaptedPipeline.RunAsync(stream); + Log.LogError(0, ex, $"Unexpected exception in {nameof(FrameConnection)}.{nameof(ProcessRequestsAsync)}."); } - - await _frame.ProcessRequestsAsync(); - await adaptedPipelineTask; - await _socketClosedTcs.Task; - } - catch (Exception ex) - { - Log.LogError(0, ex, $"Unexpected exception in {nameof(FrameConnection)}.{nameof(ProcessRequestsAsync)}."); - } - finally - { - _context.ServiceContext.ConnectionManager.RemoveConnection(_context.FrameConnectionId); - DisposeAdaptedConnections(); - - if (_frame.WasUpgraded) + finally { - _context.ServiceContext.ConnectionManager.UpgradedConnectionCount.ReleaseOne(); - } - else - { - _context.ServiceContext.ConnectionManager.NormalConnectionCount.ReleaseOne(); - } + _context.ServiceContext.ConnectionManager.RemoveConnection(_context.FrameConnectionId); + DisposeAdaptedConnections(); - Log.ConnectionStop(ConnectionId); - KestrelEventSource.Log.ConnectionStop(this); + if (_frame.WasUpgraded) + { + _context.ServiceContext.ConnectionManager.UpgradedConnectionCount.ReleaseOne(); + } + else + { + _context.ServiceContext.ConnectionManager.NormalConnectionCount.ReleaseOne(); + } + + Log.ConnectionStop(ConnectionId); + KestrelEventSource.Log.ConnectionStop(this); + } } } @@ -454,5 +459,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal _writeTimingWrites--; } } + + private IDisposable BeginConnectionScope() + { + if (Log.IsEnabled(LogLevel.Critical)) + { + return Log.BeginScope(new ConnectionLogScope(ConnectionId)); + } + + return null; + } } } diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameConnectionTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameConnectionTests.cs index 8c1d74eb24..faa662f899 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameConnectionTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameConnectionTests.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; +using System.Linq; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal; @@ -529,5 +530,26 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests Assert.True(_frameConnection.TimedOut); Assert.True(aborted.Wait(TimeSpan.FromSeconds(10))); } + + [Fact] + public async Task StartRequestProcessingCreatesLogScopeWithConnectionId() + { + _frameConnection.StartRequestProcessing(new DummyApplication()); + + _frameConnection.OnConnectionClosed(ex: null); + + await _frameConnection.StopAsync().TimeoutAfter(TimeSpan.FromSeconds(5)); + + var scopeObjects = ((TestKestrelTrace)_frameConnectionContext.ServiceContext.Log) + .Logger + .Scopes + .OfType>>() + .ToList(); + + Assert.Equal(1, scopeObjects.Count); + var pairs = scopeObjects[0].ToDictionary(p => p.Key, p => p.Value); + Assert.True(pairs.ContainsKey("ConnectionId")); + Assert.Equal(_frameConnection.ConnectionId, pairs["ConnectionId"]); + } } } diff --git a/test/shared/TestApplicationErrorLogger.cs b/test/shared/TestApplicationErrorLogger.cs index 63f710cd7d..936624f1a8 100644 --- a/test/shared/TestApplicationErrorLogger.cs +++ b/test/shared/TestApplicationErrorLogger.cs @@ -19,6 +19,8 @@ namespace Microsoft.AspNetCore.Testing public ConcurrentBag Messages { get; } = new ConcurrentBag(); + public ConcurrentBag Scopes { get; } = new ConcurrentBag(); + public int TotalErrorsLogged => Messages.Count(message => message.LogLevel == LogLevel.Error); public int CriticalErrorsLogged => Messages.Count(message => message.LogLevel == LogLevel.Critical); @@ -27,6 +29,7 @@ namespace Microsoft.AspNetCore.Testing public IDisposable BeginScope(TState state) { + Scopes.Add(state); return new Disposable(() => { }); } diff --git a/test/shared/TestServiceContext.cs b/test/shared/TestServiceContext.cs index 2d9b772e43..61487222d7 100644 --- a/test/shared/TestServiceContext.cs +++ b/test/shared/TestServiceContext.cs @@ -13,8 +13,12 @@ namespace Microsoft.AspNetCore.Testing public class TestServiceContext : ServiceContext { public TestServiceContext() - : this(new LoggerFactory(new[] { new KestrelTestLoggerProvider() })) { + var logger = new TestApplicationErrorLogger(); + var kestrelTrace = new TestKestrelTrace(logger); + var loggerFactory = new LoggerFactory(new[] { new KestrelTestLoggerProvider(logger) }); + + Initialize(loggerFactory, kestrelTrace); } public TestServiceContext(ILoggerFactory loggerFactory) @@ -23,6 +27,11 @@ namespace Microsoft.AspNetCore.Testing } public TestServiceContext(ILoggerFactory loggerFactory, IKestrelTrace kestrelTrace) + { + Initialize(loggerFactory, kestrelTrace); + } + + private void Initialize(ILoggerFactory loggerFactory, IKestrelTrace kestrelTrace) { LoggerFactory = loggerFactory; Log = kestrelTrace; @@ -37,7 +46,7 @@ namespace Microsoft.AspNetCore.Testing }; } - public ILoggerFactory LoggerFactory { get; } + public ILoggerFactory LoggerFactory { get; set; } public string DateHeaderValue => DateHeaderValueManager.GetDateHeaderValues().String; } From 095230cb859208a419989044fcd93696e0d2d306 Mon Sep 17 00:00:00 2001 From: Mike Harder Date: Wed, 12 Jul 2017 16:55:47 -0700 Subject: [PATCH 1356/1662] Update Newtonsoft.Json to 10.0.1 (#1958) - Matches other repos --- build/dependencies.props | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/dependencies.props b/build/dependencies.props index ea2c0becd5..277585e4fd 100644 --- a/build/dependencies.props +++ b/build/dependencies.props @@ -4,7 +4,7 @@ 4.4.0-* 2.0.1-* 1.10.0 - 9.0.1 + 10.0.1 4.7.49 2.0.0-* 2.0.0-* From f0e572075bec9d4866ed27c8b524c62eaa9470c8 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Mon, 17 Jul 2017 14:57:26 -0700 Subject: [PATCH 1357/1662] Fix FlushAsync when a ConnectionAdapter is configured (#1957) * Also remove async void everywhere --- .../Adapter/Internal/RawStream.cs | 12 +++---- .../Internal/ListenerSecondary.cs | 4 +-- .../SocketConnection.cs | 2 +- .../SocketTransport.cs | 2 +- .../ConnectionAdapterTests.cs | 34 +++++++++++++++++++ 5 files changed, 42 insertions(+), 12 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/Internal/RawStream.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/Internal/RawStream.cs index cec2ba1e75..7b4ffc3340 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/Internal/RawStream.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/Internal/RawStream.cs @@ -75,17 +75,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal public override async Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken token) { - ArraySegment segment; + var output = _output.Alloc(); + if (buffer != null) { - segment = new ArraySegment(buffer, offset, count); + output.Write(new ArraySegment(buffer, offset, count)); } - else - { - segment = default(ArraySegment); - } - var output = _output.Alloc(); - output.Write(segment); + await output.FlushAsync(token); } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/ListenerSecondary.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/ListenerSecondary.cs index 83a4c5f76c..59615c3121 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/ListenerSecondary.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/ListenerSecondary.cs @@ -81,10 +81,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal private static void ConnectCallback(UvConnectRequest connect, int status, UvException error, TaskCompletionSource tcs) { var listener = (ListenerSecondary)tcs.Task.AsyncState; - listener.ConnectedCallback(connect, status, error, tcs); + _ = listener.ConnectedCallback(connect, status, error, tcs); } - private async void ConnectedCallback(UvConnectRequest connect, int status, UvException error, TaskCompletionSource tcs) + private async Task ConnectedCallback(UvConnectRequest connect, int status, UvException error, TaskCompletionSource tcs) { connect.Dispose(); if (error != null) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets/SocketConnection.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets/SocketConnection.cs index 2f5dfe96b7..5a3f64d17b 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets/SocketConnection.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets/SocketConnection.cs @@ -38,7 +38,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets _remoteEndPoint = (IPEndPoint)_socket.RemoteEndPoint; } - public async void Start(IConnectionHandler connectionHandler) + public async Task StartAsync(IConnectionHandler connectionHandler) { try { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets/SocketTransport.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets/SocketTransport.cs index aed59a4def..fd6d3b57da 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets/SocketTransport.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets/SocketTransport.cs @@ -105,7 +105,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets acceptSocket.NoDelay = _endPointInformation.NoDelay; var connection = new SocketConnection(acceptSocket, this); - connection.Start(_handler); + _ = connection.StartAsync(_handler); } } catch (Exception) diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ConnectionAdapterTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ConnectionAdapterTests.cs index 7c85fe99c5..21e175d8e0 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ConnectionAdapterTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ConnectionAdapterTests.cs @@ -7,6 +7,7 @@ using System.Net; using System.Net.Sockets; using System.Threading; using System.Threading.Tasks; +using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal; using Microsoft.AspNetCore.Testing; @@ -172,6 +173,39 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } } + [Fact] + public async Task CanFlushAsyncWithConnectionAdapter() + { + var listenOptions = new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0)) + { + ConnectionAdapters = { new PassThroughConnectionAdapter() } + }; + + var serviceContext = new TestServiceContext(); + + using (var server = new TestServer(async context => + { + await context.Response.WriteAsync("Hello "); + await context.Response.Body.FlushAsync(); + await context.Response.WriteAsync("World!"); + }, serviceContext, listenOptions)) + { + using (var connection = server.CreateConnection()) + { + await connection.Send( + "GET / HTTP/1.0", + "", + ""); + await connection.ReceiveEnd( + "HTTP/1.1 200 OK", + "Connection: close", + $"Date: {serviceContext.DateHeaderValue}", + "", + "Hello World!"); + } + } + } + private class RewritingConnectionAdapter : IConnectionAdapter { private RewritingStream _rewritingStream; From ecb26d9bbc93fef1ef03fe5a38414c5b79d7c21d Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Wed, 19 Jul 2017 15:26:29 -0700 Subject: [PATCH 1358/1662] Reenable a connection adapter test on TeamCity (#1961) - Add more tracing to help diagnose failures if they pop up again --- .../LoggingConnectionAdapterTests.cs | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/LoggingConnectionAdapterTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/LoggingConnectionAdapterTests.cs index 39c77b3cdd..24e72aa336 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/LoggingConnectionAdapterTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/LoggingConnectionAdapterTests.cs @@ -8,20 +8,30 @@ using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Testing; -using Microsoft.AspNetCore.Testing.xunit; +using Microsoft.Extensions.Logging; using Xunit; +using Xunit.Abstractions; namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { public class LoggingConnectionAdapterTests { - // This test is particularly flaky on some teamcity agents, so skip there for now. - // https://github.com/aspnet/KestrelHttpServer/issues/1697 - [ConditionalFact] - [EnvironmentVariableSkipCondition("TEAMCITY_VERSION", null)] + private readonly ITestOutputHelper _output; + + public LoggingConnectionAdapterTests(ITestOutputHelper output) + { + _output = output; + } + + [Fact] public async Task LoggingConnectionAdapterCanBeAddedBeforeAndAfterHttpsAdapter() { var host = new WebHostBuilder() + .ConfigureLogging(builder => + { + builder.SetMinimumLevel(LogLevel.Trace); + builder.AddXunit(_output); + }) .UseKestrel(options => { options.Listen(new IPEndPoint(IPAddress.Loopback, 0), listenOptions => From 94305530b112d1c9dcbe5fb038cbceda3e211628 Mon Sep 17 00:00:00 2001 From: Ryan Brandenburg Date: Fri, 21 Jul 2017 13:00:26 -0700 Subject: [PATCH 1359/1662] 2.0.0-rtm to 2.1.0-preview1 --- version.props | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/version.props b/version.props index e55a656d79..5a5f18889b 100644 --- a/version.props +++ b/version.props @@ -1,7 +1,7 @@ - 2.0.0 - rtm + 2.1.0 + preview1 From 7de05402288f9c323fec0de42d564d1453dc11aa Mon Sep 17 00:00:00 2001 From: Ryan Brandenburg Date: Mon, 24 Jul 2017 17:57:01 -0700 Subject: [PATCH 1360/1662] Set AspNetCoreVersion --- build/dependencies.props | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build/dependencies.props b/build/dependencies.props index 277585e4fd..b049a15c2d 100644 --- a/build/dependencies.props +++ b/build/dependencies.props @@ -1,6 +1,6 @@ - + - 2.0.0-* + 2.1.0-* 4.4.0-* 2.0.1-* 1.10.0 From 58bcca9509090640a5ed934e95985fa7def288c5 Mon Sep 17 00:00:00 2001 From: Pranav K Date: Tue, 25 Jul 2017 15:13:48 -0700 Subject: [PATCH 1361/1662] Updating to InternalAspNetCoreSdkVersion 2.1.1-* --- build/dependencies.props | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/dependencies.props b/build/dependencies.props index b049a15c2d..5f059feb6a 100644 --- a/build/dependencies.props +++ b/build/dependencies.props @@ -2,7 +2,7 @@ 2.1.0-* 4.4.0-* - 2.0.1-* + 2.1.1-* 1.10.0 10.0.1 4.7.49 From a88e43bc67180e8e837d6219e58685a582379146 Mon Sep 17 00:00:00 2001 From: Nate McMaster Date: Tue, 25 Jul 2017 16:33:00 -0700 Subject: [PATCH 1362/1662] Update bootstrappers to use the compiled version of KoreBuild [ci skip] --- .gitignore | 1 + build.cmd | 2 +- build.ps1 | 218 ++++++++++++++++++++++++++++++++----------- build.sh | 224 +++++++++++++++++++++++++++++++++++++-------- build/common.props | 2 +- version.props | 7 -- version.xml | 8 ++ 7 files changed, 362 insertions(+), 100 deletions(-) delete mode 100644 version.props create mode 100644 version.xml diff --git a/.gitignore b/.gitignore index 708c4155fa..8e1cee9e15 100644 --- a/.gitignore +++ b/.gitignore @@ -35,3 +35,4 @@ BenchmarkDotNet.Artifacts/ BDN.Generated/ binaries/ global.json +korebuild-lock.txt diff --git a/build.cmd b/build.cmd index 7d4894cb4a..b6c8d24864 100644 --- a/build.cmd +++ b/build.cmd @@ -1,2 +1,2 @@ @ECHO OFF -PowerShell -NoProfile -NoLogo -ExecutionPolicy unrestricted -Command "[System.Threading.Thread]::CurrentThread.CurrentCulture = ''; [System.Threading.Thread]::CurrentThread.CurrentUICulture = '';& '%~dp0build.ps1' %*; exit $LASTEXITCODE" \ No newline at end of file +PowerShell -NoProfile -NoLogo -ExecutionPolicy unrestricted -Command "[System.Threading.Thread]::CurrentThread.CurrentCulture = ''; [System.Threading.Thread]::CurrentThread.CurrentUICulture = '';& '%~dp0build.ps1' %*; exit $LASTEXITCODE" diff --git a/build.ps1 b/build.ps1 index 5bf0e2c113..d5eb4d5cf2 100644 --- a/build.ps1 +++ b/build.ps1 @@ -1,67 +1,177 @@ -$ErrorActionPreference = "Stop" +#!/usr/bin/env powershell +#requires -version 4 -function DownloadWithRetry([string] $url, [string] $downloadLocation, [int] $retries) -{ - while($true) - { - try - { - Invoke-WebRequest $url -OutFile $downloadLocation - break - } - catch - { - $exceptionMessage = $_.Exception.Message - Write-Host "Failed to download '$url': $exceptionMessage" - if ($retries -gt 0) { - $retries-- - Write-Host "Waiting 10 seconds before retrying. Retries left: $retries" - Start-Sleep -Seconds 10 +<# +.SYNOPSIS +Build this repository +.DESCRIPTION +Downloads korebuild if required. Then builds the repository. + +.PARAMETER Path +The folder to build. Defaults to the folder containing this script. + +.PARAMETER Channel +The channel of KoreBuild to download. Overrides the value from the config file. + +.PARAMETER DotNetHome +The directory where .NET Core tools will be stored. + +.PARAMETER ToolsSource +The base url where build tools can be downloaded. Overrides the value from the config file. + +.PARAMETER Update +Updates KoreBuild to the latest version even if a lock file is present. + +.PARAMETER ConfigFile +The path to the configuration file that stores values. Defaults to version.xml. + +.PARAMETER MSBuildArgs +Arguments to be passed to MSBuild + +.NOTES +This function will create a file $PSScriptRoot/korebuild-lock.txt. This lock file can be committed to source, but does not have to be. +When the lockfile is not present, KoreBuild will create one using latest available version from $Channel. + +The $ConfigFile is expected to be an XML file. It is optional, and the configuration values in it are optional as well. + +.EXAMPLE +Example config file: +```xml + + + + dev + https://aspnetcore.blob.core.windows.net/buildtools + + +``` +#> +[CmdletBinding(PositionalBinding = $false)] +param( + [string]$Path = $PSScriptRoot, + [Alias('c')] + [string]$Channel, + [Alias('d')] + [string]$DotNetHome, + [Alias('s')] + [string]$ToolsSource, + [Alias('u')] + [switch]$Update, + [string]$ConfigFile = (Join-Path $PSScriptRoot 'version.xml'), + [Parameter(ValueFromRemainingArguments = $true)] + [string[]]$MSBuildArgs +) + +Set-StrictMode -Version 2 +$ErrorActionPreference = 'Stop' + +# +# Functions +# + +function Get-KoreBuild { + + $lockFile = Join-Path $Path 'korebuild-lock.txt' + + if (!(Test-Path $lockFile) -or $Update) { + Get-RemoteFile "$ToolsSource/korebuild/channels/$Channel/latest.txt" $lockFile + } + + $version = Get-Content $lockFile | Where-Object { $_ -like 'version:*' } | Select-Object -first 1 + if (!$version) { + Write-Error "Failed to parse version from $lockFile. Expected a line that begins with 'version:'" + } + $version = $version.TrimStart('version:').Trim() + $korebuildPath = Join-Paths $DotNetHome ('buildtools', 'korebuild', $version) + + if (!(Test-Path $korebuildPath)) { + Write-Host -ForegroundColor Magenta "Downloading KoreBuild $version" + New-Item -ItemType Directory -Path $korebuildPath | Out-Null + $remotePath = "$ToolsSource/korebuild/artifacts/$version/korebuild.$version.zip" + + try { + $tmpfile = Join-Path ([IO.Path]::GetTempPath()) "KoreBuild-$([guid]::NewGuid()).zip" + Get-RemoteFile $remotePath $tmpfile + if (Get-Command -Name 'Expand-Archive' -ErrorAction Ignore) { + # Use built-in commands where possible as they are cross-plat compatible + Expand-Archive -Path $tmpfile -DestinationPath $korebuildPath } - else - { - $exception = $_.Exception - throw $exception + else { + # Fallback to old approach for old installations of PowerShell + Add-Type -AssemblyName System.IO.Compression.FileSystem + [System.IO.Compression.ZipFile]::ExtractToDirectory($tmpfile, $korebuildPath) } } + catch { + Remove-Item -Recurse -Force $korebuildPath -ErrorAction Ignore + throw + } + finally { + Remove-Item $tmpfile -ErrorAction Ignore + } } + + return $korebuildPath } -cd $PSScriptRoot - -$repoFolder = $PSScriptRoot -$env:REPO_FOLDER = $repoFolder - -$koreBuildZip="https://github.com/aspnet/KoreBuild/archive/dev.zip" -if ($env:KOREBUILD_ZIP) -{ - $koreBuildZip=$env:KOREBUILD_ZIP +function Join-Paths([string]$path, [string[]]$childPaths) { + $childPaths | ForEach-Object { $path = Join-Path $path $_ } + return $path } -$buildFolder = ".build" -$buildFile="$buildFolder\KoreBuild.ps1" - -if (!(Test-Path $buildFolder)) { - Write-Host "Downloading KoreBuild from $koreBuildZip" - - $tempFolder=$env:TEMP + "\KoreBuild-" + [guid]::NewGuid() - New-Item -Path "$tempFolder" -Type directory | Out-Null - - $localZipFile="$tempFolder\korebuild.zip" - - DownloadWithRetry -url $koreBuildZip -downloadLocation $localZipFile -retries 6 - - Add-Type -AssemblyName System.IO.Compression.FileSystem - [System.IO.Compression.ZipFile]::ExtractToDirectory($localZipFile, $tempFolder) - - New-Item -Path "$buildFolder" -Type directory | Out-Null - copy-item "$tempFolder\**\build\*" $buildFolder -Recurse - - # Cleanup - if (Test-Path $tempFolder) { - Remove-Item -Recurse -Force $tempFolder +function Get-RemoteFile([string]$RemotePath, [string]$LocalPath) { + if ($RemotePath -notlike 'http*') { + Copy-Item $RemotePath $LocalPath + return } + + $retries = 10 + while ($retries -gt 0) { + $retries -= 1 + try { + Invoke-WebRequest -UseBasicParsing -Uri $RemotePath -OutFile $LocalPath + return + } + catch { + Write-Verbose "Request failed. $retries retries remaining" + } + } + + Write-Error "Download failed: '$RemotePath'." } -&"$buildFile" @args +# +# Main +# + +# Load configuration or set defaults + +if (Test-Path $ConfigFile) { + [xml] $config = Get-Content $ConfigFile + if (!($Channel)) { [string] $Channel = Select-Xml -Xml $config -XPath '/Project/PropertyGroup/KoreBuildChannel' } + if (!($ToolsSource)) { [string] $ToolsSource = Select-Xml -Xml $config -XPath '/Project/PropertyGroup/KoreBuildToolsSource' } +} + +if (!$DotNetHome) { + $DotNetHome = if ($env:DOTNET_HOME) { $env:DOTNET_HOME } ` + elseif ($env:USERPROFILE) { Join-Path $env:USERPROFILE '.dotnet'} ` + elseif ($env:HOME) {Join-Path $env:HOME '.dotnet'}` + else { Join-Path $PSScriptRoot '.dotnet'} +} + +if (!$Channel) { $Channel = 'dev' } +if (!$ToolsSource) { $ToolsSource = 'https://aspnetcore.blob.core.windows.net/buildtools' } + +# Execute + +$korebuildPath = Get-KoreBuild +Import-Module -Force -Scope Local (Join-Path $korebuildPath 'KoreBuild.psd1') + +try { + Install-Tools $ToolsSource $DotNetHome + Invoke-RepositoryBuild $Path @MSBuildArgs +} +finally { + Remove-Module 'KoreBuild' -ErrorAction Ignore +} diff --git a/build.sh b/build.sh index b0bcadb579..ab590e62f1 100755 --- a/build.sh +++ b/build.sh @@ -1,46 +1,196 @@ #!/usr/bin/env bash -repoFolder="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -cd $repoFolder -koreBuildZip="https://github.com/aspnet/KoreBuild/archive/dev.zip" -if [ ! -z $KOREBUILD_ZIP ]; then - koreBuildZip=$KOREBUILD_ZIP -fi +set -euo pipefail -buildFolder=".build" -buildFile="$buildFolder/KoreBuild.sh" +# +# variables +# -if test ! -d $buildFolder; then - echo "Downloading KoreBuild from $koreBuildZip" +RESET="\033[0m" +RED="\033[0;31m" +MAGENTA="\033[0;95m" +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +[ -z "${DOTNET_HOME:-}"] && DOTNET_HOME="$HOME/.dotnet" +config_file="$DIR/version.xml" +verbose=false +update=false +repo_path="$DIR" +channel='' +tools_source='' - tempFolder="/tmp/KoreBuild-$(uuidgen)" - mkdir $tempFolder +# +# Functions +# +__usage() { + echo "Usage: $(basename ${BASH_SOURCE[0]}) [options] [[--] ...]" + echo "" + echo "Arguments:" + echo " ... Arguments passed to MSBuild. Variable number of arguments allowed." + echo "" + echo "Options:" + echo " --verbose Show verbose output." + echo " -c|--channel The channel of KoreBuild to download. Overrides the value from the config file.." + echo " --config-file TThe path to the configuration file that stores values. Defaults to version.xml." + echo " -d|--dotnet-home The directory where .NET Core tools will be stored. Defaults to '\$DOTNET_HOME' or '\$HOME/.dotnet." + echo " --path The directory to build. Defaults to the directory containing the script." + echo " -s|--tools-source The base url where build tools can be downloaded. Overrides the value from the config file." + echo " -u|--update Update to the latest KoreBuild even if the lock file is present." + echo "" + echo "Description:" + echo " This function will create a file \$DIR/korebuild-lock.txt. This lock file can be committed to source, but does not have to be." + echo " When the lockfile is not present, KoreBuild will create one using latest available version from \$channel." - localZipFile="$tempFolder/korebuild.zip" - - retries=6 - until (wget -O $localZipFile $koreBuildZip 2>/dev/null || curl -o $localZipFile --location $koreBuildZip 2>/dev/null) - do - echo "Failed to download '$koreBuildZip'" - if [ "$retries" -le 0 ]; then - exit 1 - fi - retries=$((retries - 1)) - echo "Waiting 10 seconds before retrying. Retries left: $retries" - sleep 10s - done - - unzip -q -d $tempFolder $localZipFile - - mkdir $buildFolder - cp -r $tempFolder/**/build/** $buildFolder - - chmod +x $buildFile - - # Cleanup - if test -d $tempFolder; then - rm -rf $tempFolder + if [[ "${1:-}" != '--no-exit' ]]; then + exit 2 fi +} + +get_korebuild() { + local lock_file="$repo_path/korebuild-lock.txt" + if [ ! -f $lock_file ] || [ "$update" = true ]; then + __get_remote_file "$tools_source/korebuild/channels/$channel/latest.txt" $lock_file + fi + local version="$(grep 'version:*' -m 1 $lock_file)" + if [[ "$version" == '' ]]; then + __error "Failed to parse version from $lock_file. Expected a line that begins with 'version:'" + return 1 + fi + version="$(echo ${version#version:} | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')" + local korebuild_path="$DOTNET_HOME/buildtools/korebuild/$version" + + { + if [ ! -d "$korebuild_path" ]; then + mkdir -p "$korebuild_path" + local remote_path="$tools_source/korebuild/artifacts/$version/korebuild.$version.zip" + tmpfile="$(mktemp)" + echo -e "${MAGENTA}Downloading KoreBuild ${version}${RESET}" + if __get_remote_file $remote_path $tmpfile; then + unzip -q -d "$korebuild_path" $tmpfile + fi + rm $tmpfile || true + fi + + source "$korebuild_path/KoreBuild.sh" + } || { + if [ -d "$korebuild_path" ]; then + echo "Cleaning up after failed installation" + rm -rf "$korebuild_path" || true + fi + return 1 + } +} + +__error() { + echo -e "${RED}$@${RESET}" 1>&2 +} + +__machine_has() { + hash "$1" > /dev/null 2>&1 + return $? +} + +__get_remote_file() { + local remote_path=$1 + local local_path=$2 + + if [[ "$remote_path" != 'http'* ]]; then + cp $remote_path $local_path + return 0 + fi + + failed=false + if __machine_has wget; then + wget --tries 10 --quiet -O $local_path $remote_path || failed=true + fi + + if [ "$failed" = true ] && __machine_has curl; then + failed=false + curl --retry 10 -sSL -f --create-dirs -o $local_path $remote_path || failed=true + fi + + if [ "$failed" = true ]; then + __error "Download failed: $remote_path" 1>&2 + return 1 + fi +} + +__read_dom () { local IFS=\> ; read -d \< ENTITY CONTENT ;} + +# +# main +# + +while [[ $# > 0 ]]; do + case $1 in + -\?|-h|--help) + __usage --no-exit + exit 0 + ;; + -c|--channel|-Channel) + shift + channel=${1:-} + [ -z "$channel" ] && __usage + ;; + --config-file|-ConfigFile) + shift + config_file="${1:-}" + [ -z "$config_file" ] && __usage + ;; + -d|--dotnet-home|-DotNetHome) + shift + DOTNET_HOME=${1:-} + [ -z "$DOTNET_HOME" ] && __usage + ;; + --path|-Path) + shift + repo_path="${1:-}" + [ -z "$repo_path" ] && __usage + ;; + -s|--tools-source|-ToolsSource) + shift + tools_source="${1:-}" + [ -z "$tools_source" ] && __usage + ;; + -u|--update|-Update) + update=true + ;; + --verbose|-Verbose) + verbose=true + ;; + --) + shift + break + ;; + *) + break + ;; + esac + shift +done + +if ! __machine_has unzip; then + __error 'Missing required command: unzip' + exit 1 fi -$buildFile -r $repoFolder "$@" +if ! __machine_has curl && ! __machine_has wget; then + __error 'Missing required command. Either wget or curl is required.' + exit 1 +fi + +if [ -f $config_file ]; then + comment=false + while __read_dom; do + if [ "$comment" = true ]; then [[ $CONTENT == *'-->'* ]] && comment=false ; continue; fi + if [[ $ENTITY == '!--'* ]]; then comment=true; continue; fi + if [ -z "$channel" ] && [[ $ENTITY == "KoreBuildChannel" ]]; then channel=$CONTENT; fi + if [ -z "$tools_source" ] && [[ $ENTITY == "KoreBuildToolsSource" ]]; then tools_source=$CONTENT; fi + done < $config_file +fi + +[ -z "$channel" ] && channel='dev' +[ -z "$tools_source" ] && tools_source='https://aspnetcore.blob.core.windows.net/buildtools' + +get_korebuild +install_tools "$tools_source" "$DOTNET_HOME" +invoke_repository_build "$repo_path" $@ diff --git a/build/common.props b/build/common.props index 2a03e28988..7c10a3ca71 100644 --- a/build/common.props +++ b/build/common.props @@ -1,6 +1,6 @@ - + Microsoft ASP.NET Core diff --git a/version.props b/version.props deleted file mode 100644 index 5a5f18889b..0000000000 --- a/version.props +++ /dev/null @@ -1,7 +0,0 @@ - - - - 2.1.0 - preview1 - - diff --git a/version.xml b/version.xml new file mode 100644 index 0000000000..3c05022b7d --- /dev/null +++ b/version.xml @@ -0,0 +1,8 @@ + + + + dev + 2.1.0 + preview1 + + From d64238e93733bdcd65d122051741c5e7680ea086 Mon Sep 17 00:00:00 2001 From: Nate McMaster Date: Wed, 26 Jul 2017 10:28:03 -0700 Subject: [PATCH 1363/1662] Fix syntax warning when running build.sh on older versions of bash [ci skip] --- build.sh | 41 +++++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/build.sh b/build.sh index ab590e62f1..5568c6182a 100755 --- a/build.sh +++ b/build.sh @@ -10,7 +10,7 @@ RESET="\033[0m" RED="\033[0;31m" MAGENTA="\033[0;95m" DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -[ -z "${DOTNET_HOME:-}"] && DOTNET_HOME="$HOME/.dotnet" +[ -z "${DOTNET_HOME:-}" ] && DOTNET_HOME="$HOME/.dotnet" config_file="$DIR/version.xml" verbose=false update=false @@ -22,7 +22,7 @@ tools_source='' # Functions # __usage() { - echo "Usage: $(basename ${BASH_SOURCE[0]}) [options] [[--] ...]" + echo "Usage: $(basename "${BASH_SOURCE[0]}") [options] [[--] ...]" echo "" echo "Arguments:" echo " ... Arguments passed to MSBuild. Variable number of arguments allowed." @@ -46,16 +46,17 @@ __usage() { } get_korebuild() { + local version local lock_file="$repo_path/korebuild-lock.txt" - if [ ! -f $lock_file ] || [ "$update" = true ]; then - __get_remote_file "$tools_source/korebuild/channels/$channel/latest.txt" $lock_file + if [ ! -f "$lock_file" ] || [ "$update" = true ]; then + __get_remote_file "$tools_source/korebuild/channels/$channel/latest.txt" "$lock_file" fi - local version="$(grep 'version:*' -m 1 $lock_file)" + version="$(grep 'version:*' -m 1 "$lock_file")" if [[ "$version" == '' ]]; then __error "Failed to parse version from $lock_file. Expected a line that begins with 'version:'" return 1 fi - version="$(echo ${version#version:} | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')" + version="$(echo "${version#version:}" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')" local korebuild_path="$DOTNET_HOME/buildtools/korebuild/$version" { @@ -64,10 +65,10 @@ get_korebuild() { local remote_path="$tools_source/korebuild/artifacts/$version/korebuild.$version.zip" tmpfile="$(mktemp)" echo -e "${MAGENTA}Downloading KoreBuild ${version}${RESET}" - if __get_remote_file $remote_path $tmpfile; then - unzip -q -d "$korebuild_path" $tmpfile + if __get_remote_file "$remote_path" "$tmpfile"; then + unzip -q -d "$korebuild_path" "$tmpfile" fi - rm $tmpfile || true + rm "$tmpfile" || true fi source "$korebuild_path/KoreBuild.sh" @@ -81,7 +82,7 @@ get_korebuild() { } __error() { - echo -e "${RED}$@${RESET}" 1>&2 + echo -e "${RED}$*${RESET}" 1>&2 } __machine_has() { @@ -94,18 +95,18 @@ __get_remote_file() { local local_path=$2 if [[ "$remote_path" != 'http'* ]]; then - cp $remote_path $local_path + cp "$remote_path" "$local_path" return 0 fi failed=false if __machine_has wget; then - wget --tries 10 --quiet -O $local_path $remote_path || failed=true + wget --tries 10 --quiet -O "$local_path" "$remote_path" || failed=true fi if [ "$failed" = true ] && __machine_has curl; then failed=false - curl --retry 10 -sSL -f --create-dirs -o $local_path $remote_path || failed=true + curl --retry 10 -sSL -f --create-dirs -o "$local_path" "$remote_path" || failed=true fi if [ "$failed" = true ]; then @@ -114,13 +115,13 @@ __get_remote_file() { fi } -__read_dom () { local IFS=\> ; read -d \< ENTITY CONTENT ;} +__read_dom () { local IFS=\> ; read -r -d \< ENTITY CONTENT ;} # # main # -while [[ $# > 0 ]]; do +while [[ $# -gt 0 ]]; do case $1 in -\?|-h|--help) __usage --no-exit @@ -128,7 +129,7 @@ while [[ $# > 0 ]]; do ;; -c|--channel|-Channel) shift - channel=${1:-} + channel="${1:-}" [ -z "$channel" ] && __usage ;; --config-file|-ConfigFile) @@ -138,7 +139,7 @@ while [[ $# > 0 ]]; do ;; -d|--dotnet-home|-DotNetHome) shift - DOTNET_HOME=${1:-} + DOTNET_HOME="${1:-}" [ -z "$DOTNET_HOME" ] && __usage ;; --path|-Path) @@ -178,14 +179,14 @@ if ! __machine_has curl && ! __machine_has wget; then exit 1 fi -if [ -f $config_file ]; then +if [ -f "$config_file" ]; then comment=false while __read_dom; do if [ "$comment" = true ]; then [[ $CONTENT == *'-->'* ]] && comment=false ; continue; fi if [[ $ENTITY == '!--'* ]]; then comment=true; continue; fi if [ -z "$channel" ] && [[ $ENTITY == "KoreBuildChannel" ]]; then channel=$CONTENT; fi if [ -z "$tools_source" ] && [[ $ENTITY == "KoreBuildToolsSource" ]]; then tools_source=$CONTENT; fi - done < $config_file + done < "$config_file" fi [ -z "$channel" ] && channel='dev' @@ -193,4 +194,4 @@ fi get_korebuild install_tools "$tools_source" "$DOTNET_HOME" -invoke_repository_build "$repo_path" $@ +invoke_repository_build "$repo_path" "$@" From fd6617d1019b8e5009ad3f8a8991483e8bff7eb1 Mon Sep 17 00:00:00 2001 From: Pavel Krymets Date: Wed, 26 Jul 2017 15:51:06 -0700 Subject: [PATCH 1364/1662] React to pipeline changes (#1969) --- .../Adapter/Internal/RawStream.cs | 3 ++- .../Internal/FrameConnection.cs | 4 ++-- .../Internal/Http/MessageBody.cs | 7 ++++--- .../Internal/Http/OutputProducer.cs | 2 +- .../Internal/Infrastructure/ITimeoutControl.cs | 4 ++-- .../Mocks/MockTimeoutControl.cs | 4 ++-- .../PipeThroughputBenchmark.cs | 2 +- 7 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/Internal/RawStream.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/Internal/RawStream.cs index 7b4ffc3340..94c318a8e3 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/Internal/RawStream.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/Internal/RawStream.cs @@ -105,7 +105,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal { if (!readableBuffer.IsEmpty) { - var count = Math.Min(readableBuffer.Length, buffer.Count); + // buffer.Count is int + var count = (int) Math.Min(readableBuffer.Length, buffer.Count); readableBuffer = readableBuffer.Slice(0, count); readableBuffer.CopyTo(buffer); return count; diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnection.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnection.cs index 85b754ce9c..0c033b2b9f 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnection.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnection.cs @@ -423,12 +423,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal } } - public void BytesRead(int count) + public void BytesRead(long count) { Interlocked.Add(ref _readTimingBytesRead, count); } - public void StartTimingWrite(int size) + public void StartTimingWrite(long size) { lock (_writeTimingLock) { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/MessageBody.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/MessageBody.cs index 407dc15ec3..3ce0cd76ea 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/MessageBody.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/MessageBody.cs @@ -147,7 +147,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { if (!readableBuffer.IsEmpty) { - var actual = Math.Min(readableBuffer.Length, buffer.Count); + // buffer.Count is int + var actual = (int) Math.Min(readableBuffer.Length, buffer.Count); var slice = readableBuffer.Slice(0, actual); consumed = readableBuffer.Move(readableBuffer.Start, actual); slice.CopyTo(buffer); @@ -476,7 +477,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http // "7FFFFFFF\r\n" is the largest chunk size that could be returned as an int. private const int MaxChunkPrefixBytes = 10; - private int _inputLength; + private long _inputLength; private long _consumedBytes; private Mode _mode = Mode.Prefix; @@ -568,7 +569,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http return _mode == Mode.Complete; } - private void AddAndCheckConsumedBytes(int consumedBytes) + private void AddAndCheckConsumedBytes(long consumedBytes) { _consumedBytes += consumedBytes; diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/OutputProducer.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/OutputProducer.cs index d9fce78492..51ed5c1f67 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/OutputProducer.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/OutputProducer.cs @@ -155,7 +155,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http return FlushAsyncAwaited(awaitable, writableBuffer.BytesWritten, cancellationToken); } - private async Task FlushAsyncAwaited(WritableBufferAwaitable awaitable, int count, CancellationToken cancellationToken) + private async Task FlushAsyncAwaited(WritableBufferAwaitable awaitable, long count, CancellationToken cancellationToken) { // https://github.com/dotnet/corefxlab/issues/1334 // Since the flush awaitable doesn't currently support multiple awaiters diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/ITimeoutControl.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/ITimeoutControl.cs index 4ed025ac72..2e2c34ff55 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/ITimeoutControl.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/ITimeoutControl.cs @@ -15,9 +15,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure void PauseTimingReads(); void ResumeTimingReads(); void StopTimingReads(); - void BytesRead(int count); + void BytesRead(long count); - void StartTimingWrite(int size); + void StartTimingWrite(long size); void StopTimingWrite(); } } diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Mocks/MockTimeoutControl.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Mocks/MockTimeoutControl.cs index e0a54ef642..24f76b8203 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Mocks/MockTimeoutControl.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Mocks/MockTimeoutControl.cs @@ -37,11 +37,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance.Mocks { } - public void BytesRead(int count) + public void BytesRead(long count) { } - public void StartTimingWrite(int size) + public void StartTimingWrite(long size) { } diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/PipeThroughputBenchmark.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/PipeThroughputBenchmark.cs index 152f8af1ef..09d79ed693 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/PipeThroughputBenchmark.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/PipeThroughputBenchmark.cs @@ -38,7 +38,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance var reading = Task.Run(async () => { - int remaining = InnerLoopCount * _writeLenght; + long remaining = InnerLoopCount * _writeLenght; while (remaining != 0) { var result = await _pipe.Reader.ReadAsync(); From 6584a8b5fdaba0a79c52b981cac88472bcc92d1a Mon Sep 17 00:00:00 2001 From: Nate McMaster Date: Wed, 12 Jul 2017 12:47:58 -0700 Subject: [PATCH 1365/1662] Shorten folder names Remove the Microsoft.AspNetCore.Server prefix from csproj and their folders. This is required to help us avoid max path issues on Windows. --- .travis.yml | 2 +- .vscode/tasks.json | 31 ++++++++++++------- KestrelHttpServer.sln | 22 ++++++------- build/repo.props | 2 +- .../LargeResponseApp/LargeResponseApp.csproj | 2 +- samples/SampleApp/SampleApp.csproj | 4 +-- .../Adapter/Internal/AdaptedPipeline.cs | 0 .../Internal/ConnectionAdapterContext.cs | 0 .../Adapter/Internal/IAdaptedConnection.cs | 0 .../Adapter/Internal/IConnectionAdapter.cs | 0 .../Internal/LoggingConnectionAdapter.cs | 0 .../Adapter/Internal/LoggingStream.cs | 0 .../Adapter/Internal/RawStream.cs | 0 ...istenOptionsConnectionLoggingExtensions.cs | 0 .../BadHttpRequestException.cs | 0 .../CoreStrings.resx | 0 .../IHttpMinRequestBodyDataRateFeature.cs | 0 .../IHttpMinResponseDataRateFeature.cs | 0 .../Internal/AddressBinder.cs | 0 .../Internal/ConnectionHandler.cs | 0 .../Internal/ConnectionLogScope.cs | 0 .../Internal/FrameConnection.cs | 0 .../Internal/FrameConnectionContext.cs | 0 .../Internal/Http/ChunkWriter.cs | 0 .../Internal/Http/ConnectionOptions.cs | 0 .../Internal/Http/DateHeaderValueManager.cs | 0 .../Internal/Http/Frame.FeatureCollection.cs | 0 .../Internal/Http/Frame.Generated.cs | 0 .../Internal/Http/Frame.cs | 0 .../Internal/Http/FrameAdapter.cs | 0 .../Internal/Http/FrameContext.cs | 0 .../Internal/Http/FrameDuplexStream.cs | 0 .../Internal/Http/FrameHeaders.Generated.cs | 0 .../Internal/Http/FrameHeaders.cs | 0 .../Internal/Http/FrameOfT.cs | 0 .../Internal/Http/FrameRequestHeaders.cs | 0 .../Internal/Http/FrameRequestStream.cs | 0 .../Internal/Http/FrameResponseHeaders.cs | 0 .../Internal/Http/FrameResponseStream.cs | 0 .../Internal/Http/FrameStreamState.cs | 0 .../Internal/Http/HttpMethod.cs | 0 .../Internal/Http/HttpParser.cs | 0 .../Internal/Http/HttpScheme.cs | 0 .../Internal/Http/HttpVersion.cs | 0 .../Internal/Http/IFrameControl.cs | 0 .../Internal/Http/IHttpHeadersHandler.cs | 0 .../Internal/Http/IHttpParser.cs | 0 .../Internal/Http/IHttpRequestLineHandler.cs | 0 .../Internal/Http/MessageBody.cs | 0 .../Internal/Http/OutputProducer.cs | 0 .../Internal/Http/PathNormalizer.cs | 0 .../Internal/Http/PipelineExtensions.cs | 0 .../Internal/Http/ProduceEndType.cs | 0 .../Internal/Http/ReasonPhrases.cs | 0 .../Internal/Http/RequestProcessingStatus.cs | 0 .../Internal/Http/RequestRejectionReason.cs | 0 .../Internal/Http/TransferCoding.cs | 0 .../CancellationTokenExtensions.cs | 0 .../Internal/Infrastructure/Constants.cs | 0 .../Infrastructure/CorrelationIdGenerator.cs | 0 .../Infrastructure/DebuggerWrapper.cs | 0 .../Internal/Infrastructure/Disposable.cs | 0 .../Infrastructure/DisposableAction.cs | 0 .../Infrastructure/FrameConnectionManager.cs | 0 ...rameConnectionManagerShutdownExtensions.cs | 0 .../FrameConnectionReference.cs | 0 .../Infrastructure/FrameHeartbeatManager.cs | 0 .../Internal/Infrastructure/Heartbeat.cs | 0 .../Infrastructure/HttpUtilities.Generated.cs | 0 .../Internal/Infrastructure/HttpUtilities.cs | 0 .../Internal/Infrastructure/IDebugger.cs | 0 .../Infrastructure/IHeartbeatHandler.cs | 0 .../Internal/Infrastructure/IKestrelTrace.cs | 0 .../Internal/Infrastructure/ISystemClock.cs | 0 .../Internal/Infrastructure/IThreadPool.cs | 0 .../Infrastructure/ITimeoutControl.cs | 0 .../Infrastructure/InlineLoggingThreadPool.cs | 0 .../Infrastructure/KestrelEventSource.cs | 0 .../Internal/Infrastructure/KestrelTrace.cs | 0 .../Infrastructure/LoggingThreadPool.cs | 0 .../Internal/Infrastructure/ReadOnlyStream.cs | 0 .../Infrastructure/ResourceCounter.cs | 0 .../Internal/Infrastructure/Streams.cs | 0 .../Infrastructure/StringUtilities.cs | 0 .../Internal/Infrastructure/SystemClock.cs | 0 .../Infrastructure/ThrowingWriteOnlyStream.cs | 0 .../Internal/Infrastructure/TimeoutAction.cs | 0 .../Internal/Infrastructure/UriUtilities.cs | 0 .../Internal/Infrastructure/WrappingStream.cs | 0 .../Infrastructure/WriteOnlyStream.cs | 0 .../Internal/KestrelServerOptionsSetup.cs | 0 .../Internal/RejectionConnection.cs | 0 .../Internal/ServerAddressesFeature.cs | 0 .../Internal/ServiceContext.cs | 0 .../Kestrel.Core.csproj} | 4 ++- .../KestrelServer.cs | 0 .../KestrelServerLimits.cs | 0 .../KestrelServerOptions.cs | 0 .../ListenOptions.cs | 0 .../MinDataRate.cs | 0 .../Properties/AssemblyInfo.cs | 0 .../Properties/CoreStrings.Designer.cs | 0 .../ServerAddress.cs | 0 .../KestrelServerOptionsSystemdExtensions.cs | 0 .../ClientCertificateMode.cs | 0 .../HttpsConnectionAdapterOptions.cs | 0 .../HttpsStrings.resx | 0 .../Internal/ClosedStream.cs | 0 .../Internal/HttpsConnectionAdapter.cs | 0 .../Internal/TlsConnectionFeature.cs | 0 .../Kestrel.Https.csproj} | 4 ++- .../ListenOptionsHttpsExtensions.cs | 0 .../Properties/AssemblyInfo.cs | 0 .../Properties/HttpsStrings.Designer.cs | 0 .../Exceptions/AddressInUseException.cs | 0 .../Exceptions/ConnectionAbortedException.cs | 0 .../Exceptions/ConnectionResetException.cs | 0 .../Internal/FileHandleType.cs | 0 .../Internal/IConnectionContext.cs | 0 .../Internal/IConnectionHandler.cs | 0 .../Internal/IConnectionInformation.cs | 0 .../Internal/IEndPointInformation.cs | 0 .../Internal/ITransport.cs | 0 .../Internal/ITransportFactory.cs | 0 .../Internal/ListenType.cs | 0 .../Internal/SchedulingMode.cs | 0 .../Kestrel.Transport.Abstractions.csproj} | 2 ++ .../Internal/IAsyncDisposable.cs | 0 .../Internal/ILibuvTrace.cs | 0 .../Internal/LibuvAwaitable.cs | 0 .../Internal/LibuvConnection.cs | 0 .../Internal/LibuvConnectionContext.cs | 0 .../Internal/LibuvConstants.cs | 0 .../Internal/LibuvOutputConsumer.cs | 0 .../Internal/LibuvThread.cs | 0 .../Internal/LibuvTrace.cs | 0 .../Internal/LibuvTransportContext.cs | 0 .../Internal/Listener.cs | 0 .../Internal/ListenerContext.cs | 0 .../Internal/ListenerPrimary.cs | 0 .../Internal/ListenerSecondary.cs | 0 .../Internal/Networking/LibuvFunctions.cs | 0 .../Internal/Networking/PlatformApis.cs | 0 .../Internal/Networking/SockAddr.cs | 0 .../Internal/Networking/UvAsyncHandle.cs | 0 .../Internal/Networking/UvConnectRequest.cs | 0 .../Internal/Networking/UvException.cs | 0 .../Internal/Networking/UvHandle.cs | 0 .../Internal/Networking/UvLoopHandle.cs | 0 .../Internal/Networking/UvMemory.cs | 0 .../Internal/Networking/UvPipeHandle.cs | 0 .../Internal/Networking/UvRequest.cs | 0 .../Internal/Networking/UvStreamHandle.cs | 0 .../Internal/Networking/UvTcpHandle.cs | 0 .../Internal/Networking/UvTimerHandle.cs | 0 .../Internal/Networking/UvWriteReq.cs | 0 .../Internal/WriteReqPool.cs | 0 .../Kestrel.Transport.Libuv.csproj} | 4 ++- .../LibuvTransport.cs | 0 .../LibuvTransportFactory.cs | 0 .../LibuvTransportOptions.cs | 0 .../WebHostBuilderLibuvExtensions.cs | 0 .../Kestrel.Transport.Sockets.csproj} | 4 ++- .../Properties/SocketsStrings.Designer.cs | 0 .../SocketConnection.cs | 0 .../SocketTransport.cs | 0 .../SocketTransportFactory.cs | 0 .../SocketTransportOptions.cs | 0 .../SocketsStrings.resx | 0 .../WebHostBuilderSocketExtensions.cs | 0 .../Kestrel.csproj} | 6 ++-- .../WebHostBuilderKestrelExtensions.cs | 0 .../AddressBinderTests.cs | 0 .../AsciiDecoding.cs | 0 .../ChunkWriterTests.cs | 0 .../DateHeaderValueManagerTests.cs | 0 .../FrameConnectionManagerTests.cs | 0 .../FrameConnectionTests.cs | 0 .../FrameHeadersTests.cs | 0 .../FrameRequestHeadersTests.cs | 0 .../FrameRequestStreamTests.cs | 0 .../FrameResponseHeadersTests.cs | 0 .../FrameResponseStreamTests.cs | 0 .../FrameTests.cs | 0 .../HeartbeatTests.cs | 0 .../HttpParserTests.cs | 0 .../HttpUtilitiesTest.cs | 0 .../Kestrel.Core.Tests.csproj} | 4 ++- .../KestrelEventSourceTests.cs | 0 .../KestrelServerLimitsTests.cs | 0 .../KestrelServerOptionsTests.cs | 0 .../KestrelServerTests.cs | 0 .../KnownStringsTests.cs | 0 .../MessageBodyTests.cs | 0 .../MinDataRateTests.cs | 0 .../OutputProducerTests.cs | 0 .../PathNormalizerTests.cs | 0 .../PipeOptionsTests.cs | 0 .../PipelineExtensionTests.cs | 0 .../ResourceCounterTests.cs | 0 .../ServerAddressTests.cs | 0 .../StreamsTests.cs | 0 .../StringUtilitiesTests.cs | 0 .../TestHelpers/AssertExtensions.cs | 0 .../TestHelpers/MockFrameControl.cs | 0 .../TestInput.cs | 0 .../ThrowingWriteOnlyStreamTests.cs | 0 .../xunit.runner.json | 0 .../AddressRegistrationTests.cs | 0 .../BadHttpRequestTests.cs | 0 .../ChunkedRequestTests.cs | 0 .../ChunkedResponseTests.cs | 0 .../ConnectionAdapterTests.cs | 0 .../ConnectionLimitTests.cs | 0 .../DefaultHeaderTests.cs | 0 .../EventSourceTests.cs | 0 .../FrameConnectionManagerTests.cs | 0 .../GeneratedCodeTests.cs | 6 ++-- .../HttpsConnectionAdapterTests.cs | 0 .../HttpsTests.cs | 0 .../KeepAliveTimeoutTests.cs | 0 .../Kestrel.FunctionalTests.csproj} | 6 ++-- .../ListenHandleTests.cs | 0 .../LoggingConnectionAdapterTests.cs | 0 .../MaxRequestBodySizeTests.cs | 0 .../MaxRequestBufferSizeTests.cs | 0 .../MaxRequestLineSizeTests.cs | 0 .../Properties/AssemblyInfo.cs | 0 .../RequestBodyTimeoutTests.cs | 0 .../RequestHeaderLimitsTests.cs | 0 .../RequestHeadersTimeoutTests.cs | 0 .../RequestTargetProcessingTests.cs | 0 .../RequestTests.cs | 0 .../ResponseTests.cs | 0 .../SystemdActivation/Dockerfile | 0 .../SystemdActivation/docker-entrypoint.sh | 0 .../SystemdActivation/docker.sh | 0 .../IPv6ScopeIdPresentConditionAttribute.cs | 0 .../IPv6SupportedConditionAttribute.cs | 0 .../TestHelpers/IWebHostPortExtensions.cs | 0 .../NetworkIsReachableAttribute.cs | 0 .../TestHelpers/TestServer.cs | 0 .../ThreadCountTests.cs | 0 .../UpgradeTests.cs | 0 .../xunit.runner.json | 0 .../DotSegmentRemovalBenchmark.cs | 0 .../ErrorUtilities.cs | 0 .../FrameFeatureCollection.cs | 0 .../FrameParsingOverheadBenchmark.cs | 0 .../FrameWritingBenchmark.cs | 0 .../Kestrel.Performance.csproj} | 4 ++- .../KestrelHttpParserBenchmark.cs | 0 .../KnownStringsBenchmark.cs | 0 .../Mocks/MockConnectionInformation.cs | 0 .../Mocks/MockTimeoutControl.cs | 0 .../Mocks/MockTrace.cs | 0 .../Mocks/NullParser.cs | 0 .../PipeThroughputBenchmark.cs | 0 .../Program.cs | 0 .../Readme.md | 0 .../RequestParsingBenchmark.cs | 0 .../RequestParsingData.cs | 0 .../ResponseHeaderCollectionBenchmark.cs | 0 .../ResponseHeadersWritingBenchmark.cs | 0 .../StringUtilitiesBenchmark.cs | 0 .../configs/CoreConfig.cs | 0 .../Kestrel.Tests.csproj} | 4 ++- .../WebHostBuilderKestrelExtensionsTests.cs | 0 .../xunit.runner.json | 0 .../Kestrel.Transport.Libuv.Tests.csproj} | 6 ++-- .../LibuvConnectionTests.cs | 0 .../LibuvOutputConsumerTests.cs | 0 .../LibuvTransportFactoryTests.cs | 0 .../LibuvTransportOptionsTests.cs | 0 .../LibuvTransportTests.cs | 0 .../ListenerPrimaryTests.cs | 0 .../MultipleLoopTests.cs | 0 .../NetworkingTests.cs | 0 .../TestHelpers/MockConnectionHandler.cs | 0 .../TestHelpers/MockLibuv.cs | 0 .../TestHelpers/MockSocket.cs | 0 .../TestHelpers/TestConstants.cs | 0 .../TestHelpers/TestLibuvTransportContext.cs | 0 .../UvStreamHandleTests.cs | 0 .../UvTimerHandleTests.cs | 0 .../xunit.runner.json | 0 tools/CodeGenerator/CodeGenerator.csproj | 4 +-- tools/CodeGenerator/FrameFeatureCollection.cs | 2 +- 288 files changed, 77 insertions(+), 46 deletions(-) rename src/{Microsoft.AspNetCore.Server.Kestrel.Core => Kestrel.Core}/Adapter/Internal/AdaptedPipeline.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Core => Kestrel.Core}/Adapter/Internal/ConnectionAdapterContext.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Core => Kestrel.Core}/Adapter/Internal/IAdaptedConnection.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Core => Kestrel.Core}/Adapter/Internal/IConnectionAdapter.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Core => Kestrel.Core}/Adapter/Internal/LoggingConnectionAdapter.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Core => Kestrel.Core}/Adapter/Internal/LoggingStream.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Core => Kestrel.Core}/Adapter/Internal/RawStream.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Core => Kestrel.Core}/Adapter/ListenOptionsConnectionLoggingExtensions.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Core => Kestrel.Core}/BadHttpRequestException.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Core => Kestrel.Core}/CoreStrings.resx (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Core => Kestrel.Core}/Features/IHttpMinRequestBodyDataRateFeature.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Core => Kestrel.Core}/Features/IHttpMinResponseDataRateFeature.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Core => Kestrel.Core}/Internal/AddressBinder.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Core => Kestrel.Core}/Internal/ConnectionHandler.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Core => Kestrel.Core}/Internal/ConnectionLogScope.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Core => Kestrel.Core}/Internal/FrameConnection.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Core => Kestrel.Core}/Internal/FrameConnectionContext.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Core => Kestrel.Core}/Internal/Http/ChunkWriter.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Core => Kestrel.Core}/Internal/Http/ConnectionOptions.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Core => Kestrel.Core}/Internal/Http/DateHeaderValueManager.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Core => Kestrel.Core}/Internal/Http/Frame.FeatureCollection.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Core => Kestrel.Core}/Internal/Http/Frame.Generated.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Core => Kestrel.Core}/Internal/Http/Frame.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Core => Kestrel.Core}/Internal/Http/FrameAdapter.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Core => Kestrel.Core}/Internal/Http/FrameContext.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Core => Kestrel.Core}/Internal/Http/FrameDuplexStream.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Core => Kestrel.Core}/Internal/Http/FrameHeaders.Generated.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Core => Kestrel.Core}/Internal/Http/FrameHeaders.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Core => Kestrel.Core}/Internal/Http/FrameOfT.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Core => Kestrel.Core}/Internal/Http/FrameRequestHeaders.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Core => Kestrel.Core}/Internal/Http/FrameRequestStream.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Core => Kestrel.Core}/Internal/Http/FrameResponseHeaders.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Core => Kestrel.Core}/Internal/Http/FrameResponseStream.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Core => Kestrel.Core}/Internal/Http/FrameStreamState.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Core => Kestrel.Core}/Internal/Http/HttpMethod.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Core => Kestrel.Core}/Internal/Http/HttpParser.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Core => Kestrel.Core}/Internal/Http/HttpScheme.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Core => Kestrel.Core}/Internal/Http/HttpVersion.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Core => Kestrel.Core}/Internal/Http/IFrameControl.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Core => Kestrel.Core}/Internal/Http/IHttpHeadersHandler.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Core => Kestrel.Core}/Internal/Http/IHttpParser.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Core => Kestrel.Core}/Internal/Http/IHttpRequestLineHandler.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Core => Kestrel.Core}/Internal/Http/MessageBody.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Core => Kestrel.Core}/Internal/Http/OutputProducer.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Core => Kestrel.Core}/Internal/Http/PathNormalizer.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Core => Kestrel.Core}/Internal/Http/PipelineExtensions.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Core => Kestrel.Core}/Internal/Http/ProduceEndType.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Core => Kestrel.Core}/Internal/Http/ReasonPhrases.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Core => Kestrel.Core}/Internal/Http/RequestProcessingStatus.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Core => Kestrel.Core}/Internal/Http/RequestRejectionReason.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Core => Kestrel.Core}/Internal/Http/TransferCoding.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Core => Kestrel.Core}/Internal/Infrastructure/CancellationTokenExtensions.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Core => Kestrel.Core}/Internal/Infrastructure/Constants.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Core => Kestrel.Core}/Internal/Infrastructure/CorrelationIdGenerator.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Core => Kestrel.Core}/Internal/Infrastructure/DebuggerWrapper.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Core => Kestrel.Core}/Internal/Infrastructure/Disposable.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Core => Kestrel.Core}/Internal/Infrastructure/DisposableAction.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Core => Kestrel.Core}/Internal/Infrastructure/FrameConnectionManager.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Core => Kestrel.Core}/Internal/Infrastructure/FrameConnectionManagerShutdownExtensions.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Core => Kestrel.Core}/Internal/Infrastructure/FrameConnectionReference.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Core => Kestrel.Core}/Internal/Infrastructure/FrameHeartbeatManager.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Core => Kestrel.Core}/Internal/Infrastructure/Heartbeat.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Core => Kestrel.Core}/Internal/Infrastructure/HttpUtilities.Generated.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Core => Kestrel.Core}/Internal/Infrastructure/HttpUtilities.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Core => Kestrel.Core}/Internal/Infrastructure/IDebugger.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Core => Kestrel.Core}/Internal/Infrastructure/IHeartbeatHandler.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Core => Kestrel.Core}/Internal/Infrastructure/IKestrelTrace.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Core => Kestrel.Core}/Internal/Infrastructure/ISystemClock.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Core => Kestrel.Core}/Internal/Infrastructure/IThreadPool.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Core => Kestrel.Core}/Internal/Infrastructure/ITimeoutControl.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Core => Kestrel.Core}/Internal/Infrastructure/InlineLoggingThreadPool.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Core => Kestrel.Core}/Internal/Infrastructure/KestrelEventSource.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Core => Kestrel.Core}/Internal/Infrastructure/KestrelTrace.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Core => Kestrel.Core}/Internal/Infrastructure/LoggingThreadPool.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Core => Kestrel.Core}/Internal/Infrastructure/ReadOnlyStream.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Core => Kestrel.Core}/Internal/Infrastructure/ResourceCounter.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Core => Kestrel.Core}/Internal/Infrastructure/Streams.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Core => Kestrel.Core}/Internal/Infrastructure/StringUtilities.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Core => Kestrel.Core}/Internal/Infrastructure/SystemClock.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Core => Kestrel.Core}/Internal/Infrastructure/ThrowingWriteOnlyStream.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Core => Kestrel.Core}/Internal/Infrastructure/TimeoutAction.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Core => Kestrel.Core}/Internal/Infrastructure/UriUtilities.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Core => Kestrel.Core}/Internal/Infrastructure/WrappingStream.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Core => Kestrel.Core}/Internal/Infrastructure/WriteOnlyStream.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Core => Kestrel.Core}/Internal/KestrelServerOptionsSetup.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Core => Kestrel.Core}/Internal/RejectionConnection.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Core => Kestrel.Core}/Internal/ServerAddressesFeature.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Core => Kestrel.Core}/Internal/ServiceContext.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Core/Microsoft.AspNetCore.Server.Kestrel.Core.csproj => Kestrel.Core/Kestrel.Core.csproj} (85%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Core => Kestrel.Core}/KestrelServer.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Core => Kestrel.Core}/KestrelServerLimits.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Core => Kestrel.Core}/KestrelServerOptions.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Core => Kestrel.Core}/ListenOptions.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Core => Kestrel.Core}/MinDataRate.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Core => Kestrel.Core}/Properties/AssemblyInfo.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Core => Kestrel.Core}/Properties/CoreStrings.Designer.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Core => Kestrel.Core}/ServerAddress.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Core => Kestrel.Core}/Systemd/KestrelServerOptionsSystemdExtensions.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Https => Kestrel.Https}/ClientCertificateMode.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Https => Kestrel.Https}/HttpsConnectionAdapterOptions.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Https => Kestrel.Https}/HttpsStrings.resx (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Https => Kestrel.Https}/Internal/ClosedStream.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Https => Kestrel.Https}/Internal/HttpsConnectionAdapter.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Https => Kestrel.Https}/Internal/TlsConnectionFeature.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Https/Microsoft.AspNetCore.Server.Kestrel.Https.csproj => Kestrel.Https/Kestrel.Https.csproj} (80%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Https => Kestrel.Https}/ListenOptionsHttpsExtensions.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Https => Kestrel.Https}/Properties/AssemblyInfo.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Https => Kestrel.Https}/Properties/HttpsStrings.Designer.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions => Kestrel.Transport.Abstractions}/Exceptions/AddressInUseException.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions => Kestrel.Transport.Abstractions}/Exceptions/ConnectionAbortedException.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions => Kestrel.Transport.Abstractions}/Exceptions/ConnectionResetException.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions => Kestrel.Transport.Abstractions}/Internal/FileHandleType.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions => Kestrel.Transport.Abstractions}/Internal/IConnectionContext.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions => Kestrel.Transport.Abstractions}/Internal/IConnectionHandler.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions => Kestrel.Transport.Abstractions}/Internal/IConnectionInformation.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions => Kestrel.Transport.Abstractions}/Internal/IEndPointInformation.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions => Kestrel.Transport.Abstractions}/Internal/ITransport.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions => Kestrel.Transport.Abstractions}/Internal/ITransportFactory.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions => Kestrel.Transport.Abstractions}/Internal/ListenType.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions => Kestrel.Transport.Abstractions}/Internal/SchedulingMode.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.csproj => Kestrel.Transport.Abstractions/Kestrel.Transport.Abstractions.csproj} (87%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv => Kestrel.Transport.Libuv}/Internal/IAsyncDisposable.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv => Kestrel.Transport.Libuv}/Internal/ILibuvTrace.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv => Kestrel.Transport.Libuv}/Internal/LibuvAwaitable.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv => Kestrel.Transport.Libuv}/Internal/LibuvConnection.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv => Kestrel.Transport.Libuv}/Internal/LibuvConnectionContext.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv => Kestrel.Transport.Libuv}/Internal/LibuvConstants.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv => Kestrel.Transport.Libuv}/Internal/LibuvOutputConsumer.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv => Kestrel.Transport.Libuv}/Internal/LibuvThread.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv => Kestrel.Transport.Libuv}/Internal/LibuvTrace.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv => Kestrel.Transport.Libuv}/Internal/LibuvTransportContext.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv => Kestrel.Transport.Libuv}/Internal/Listener.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv => Kestrel.Transport.Libuv}/Internal/ListenerContext.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv => Kestrel.Transport.Libuv}/Internal/ListenerPrimary.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv => Kestrel.Transport.Libuv}/Internal/ListenerSecondary.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv => Kestrel.Transport.Libuv}/Internal/Networking/LibuvFunctions.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv => Kestrel.Transport.Libuv}/Internal/Networking/PlatformApis.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv => Kestrel.Transport.Libuv}/Internal/Networking/SockAddr.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv => Kestrel.Transport.Libuv}/Internal/Networking/UvAsyncHandle.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv => Kestrel.Transport.Libuv}/Internal/Networking/UvConnectRequest.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv => Kestrel.Transport.Libuv}/Internal/Networking/UvException.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv => Kestrel.Transport.Libuv}/Internal/Networking/UvHandle.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv => Kestrel.Transport.Libuv}/Internal/Networking/UvLoopHandle.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv => Kestrel.Transport.Libuv}/Internal/Networking/UvMemory.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv => Kestrel.Transport.Libuv}/Internal/Networking/UvPipeHandle.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv => Kestrel.Transport.Libuv}/Internal/Networking/UvRequest.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv => Kestrel.Transport.Libuv}/Internal/Networking/UvStreamHandle.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv => Kestrel.Transport.Libuv}/Internal/Networking/UvTcpHandle.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv => Kestrel.Transport.Libuv}/Internal/Networking/UvTimerHandle.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv => Kestrel.Transport.Libuv}/Internal/Networking/UvWriteReq.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv => Kestrel.Transport.Libuv}/Internal/WriteReqPool.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.csproj => Kestrel.Transport.Libuv/Kestrel.Transport.Libuv.csproj} (77%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv => Kestrel.Transport.Libuv}/LibuvTransport.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv => Kestrel.Transport.Libuv}/LibuvTransportFactory.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv => Kestrel.Transport.Libuv}/LibuvTransportOptions.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv => Kestrel.Transport.Libuv}/WebHostBuilderLibuvExtensions.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.csproj => Kestrel.Transport.Sockets/Kestrel.Transport.Sockets.csproj} (79%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets => Kestrel.Transport.Sockets}/Properties/SocketsStrings.Designer.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets => Kestrel.Transport.Sockets}/SocketConnection.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets => Kestrel.Transport.Sockets}/SocketTransport.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets => Kestrel.Transport.Sockets}/SocketTransportFactory.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets => Kestrel.Transport.Sockets}/SocketTransportOptions.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets => Kestrel.Transport.Sockets}/SocketsStrings.resx (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets => Kestrel.Transport.Sockets}/WebHostBuilderSocketExtensions.cs (100%) rename src/{Microsoft.AspNetCore.Server.Kestrel/Microsoft.AspNetCore.Server.Kestrel.csproj => Kestrel/Kestrel.csproj} (67%) rename src/{Microsoft.AspNetCore.Server.Kestrel => Kestrel}/WebHostBuilderKestrelExtensions.cs (100%) rename test/{Microsoft.AspNetCore.Server.Kestrel.Core.Tests => Kestrel.Core.Tests}/AddressBinderTests.cs (100%) rename test/{Microsoft.AspNetCore.Server.Kestrel.Core.Tests => Kestrel.Core.Tests}/AsciiDecoding.cs (100%) rename test/{Microsoft.AspNetCore.Server.Kestrel.Core.Tests => Kestrel.Core.Tests}/ChunkWriterTests.cs (100%) rename test/{Microsoft.AspNetCore.Server.Kestrel.Core.Tests => Kestrel.Core.Tests}/DateHeaderValueManagerTests.cs (100%) rename test/{Microsoft.AspNetCore.Server.Kestrel.Core.Tests => Kestrel.Core.Tests}/FrameConnectionManagerTests.cs (100%) rename test/{Microsoft.AspNetCore.Server.Kestrel.Core.Tests => Kestrel.Core.Tests}/FrameConnectionTests.cs (100%) rename test/{Microsoft.AspNetCore.Server.Kestrel.Core.Tests => Kestrel.Core.Tests}/FrameHeadersTests.cs (100%) rename test/{Microsoft.AspNetCore.Server.Kestrel.Core.Tests => Kestrel.Core.Tests}/FrameRequestHeadersTests.cs (100%) rename test/{Microsoft.AspNetCore.Server.Kestrel.Core.Tests => Kestrel.Core.Tests}/FrameRequestStreamTests.cs (100%) rename test/{Microsoft.AspNetCore.Server.Kestrel.Core.Tests => Kestrel.Core.Tests}/FrameResponseHeadersTests.cs (100%) rename test/{Microsoft.AspNetCore.Server.Kestrel.Core.Tests => Kestrel.Core.Tests}/FrameResponseStreamTests.cs (100%) rename test/{Microsoft.AspNetCore.Server.Kestrel.Core.Tests => Kestrel.Core.Tests}/FrameTests.cs (100%) rename test/{Microsoft.AspNetCore.Server.Kestrel.Core.Tests => Kestrel.Core.Tests}/HeartbeatTests.cs (100%) rename test/{Microsoft.AspNetCore.Server.Kestrel.Core.Tests => Kestrel.Core.Tests}/HttpParserTests.cs (100%) rename test/{Microsoft.AspNetCore.Server.Kestrel.Core.Tests => Kestrel.Core.Tests}/HttpUtilitiesTest.cs (100%) rename test/{Microsoft.AspNetCore.Server.Kestrel.Core.Tests/Microsoft.AspNetCore.Server.Kestrel.Core.Tests.csproj => Kestrel.Core.Tests/Kestrel.Core.Tests.csproj} (85%) rename test/{Microsoft.AspNetCore.Server.Kestrel.Core.Tests => Kestrel.Core.Tests}/KestrelEventSourceTests.cs (100%) rename test/{Microsoft.AspNetCore.Server.Kestrel.Core.Tests => Kestrel.Core.Tests}/KestrelServerLimitsTests.cs (100%) rename test/{Microsoft.AspNetCore.Server.Kestrel.Core.Tests => Kestrel.Core.Tests}/KestrelServerOptionsTests.cs (100%) rename test/{Microsoft.AspNetCore.Server.Kestrel.Core.Tests => Kestrel.Core.Tests}/KestrelServerTests.cs (100%) rename test/{Microsoft.AspNetCore.Server.Kestrel.Core.Tests => Kestrel.Core.Tests}/KnownStringsTests.cs (100%) rename test/{Microsoft.AspNetCore.Server.Kestrel.Core.Tests => Kestrel.Core.Tests}/MessageBodyTests.cs (100%) rename test/{Microsoft.AspNetCore.Server.Kestrel.Core.Tests => Kestrel.Core.Tests}/MinDataRateTests.cs (100%) rename test/{Microsoft.AspNetCore.Server.Kestrel.Core.Tests => Kestrel.Core.Tests}/OutputProducerTests.cs (100%) rename test/{Microsoft.AspNetCore.Server.Kestrel.Core.Tests => Kestrel.Core.Tests}/PathNormalizerTests.cs (100%) rename test/{Microsoft.AspNetCore.Server.Kestrel.Core.Tests => Kestrel.Core.Tests}/PipeOptionsTests.cs (100%) rename test/{Microsoft.AspNetCore.Server.Kestrel.Core.Tests => Kestrel.Core.Tests}/PipelineExtensionTests.cs (100%) rename test/{Microsoft.AspNetCore.Server.Kestrel.Core.Tests => Kestrel.Core.Tests}/ResourceCounterTests.cs (100%) rename test/{Microsoft.AspNetCore.Server.Kestrel.Core.Tests => Kestrel.Core.Tests}/ServerAddressTests.cs (100%) rename test/{Microsoft.AspNetCore.Server.Kestrel.Core.Tests => Kestrel.Core.Tests}/StreamsTests.cs (100%) rename test/{Microsoft.AspNetCore.Server.Kestrel.Core.Tests => Kestrel.Core.Tests}/StringUtilitiesTests.cs (100%) rename test/{Microsoft.AspNetCore.Server.Kestrel.Core.Tests => Kestrel.Core.Tests}/TestHelpers/AssertExtensions.cs (100%) rename test/{Microsoft.AspNetCore.Server.Kestrel.Core.Tests => Kestrel.Core.Tests}/TestHelpers/MockFrameControl.cs (100%) rename test/{Microsoft.AspNetCore.Server.Kestrel.Core.Tests => Kestrel.Core.Tests}/TestInput.cs (100%) rename test/{Microsoft.AspNetCore.Server.Kestrel.Core.Tests => Kestrel.Core.Tests}/ThrowingWriteOnlyStreamTests.cs (100%) rename test/{Microsoft.AspNetCore.Server.Kestrel.Core.Tests => Kestrel.Core.Tests}/xunit.runner.json (100%) rename test/{Microsoft.AspNetCore.Server.Kestrel.FunctionalTests => Kestrel.FunctionalTests}/AddressRegistrationTests.cs (100%) rename test/{Microsoft.AspNetCore.Server.Kestrel.FunctionalTests => Kestrel.FunctionalTests}/BadHttpRequestTests.cs (100%) rename test/{Microsoft.AspNetCore.Server.Kestrel.FunctionalTests => Kestrel.FunctionalTests}/ChunkedRequestTests.cs (100%) rename test/{Microsoft.AspNetCore.Server.Kestrel.FunctionalTests => Kestrel.FunctionalTests}/ChunkedResponseTests.cs (100%) rename test/{Microsoft.AspNetCore.Server.Kestrel.FunctionalTests => Kestrel.FunctionalTests}/ConnectionAdapterTests.cs (100%) rename test/{Microsoft.AspNetCore.Server.Kestrel.FunctionalTests => Kestrel.FunctionalTests}/ConnectionLimitTests.cs (100%) rename test/{Microsoft.AspNetCore.Server.Kestrel.FunctionalTests => Kestrel.FunctionalTests}/DefaultHeaderTests.cs (100%) rename test/{Microsoft.AspNetCore.Server.Kestrel.FunctionalTests => Kestrel.FunctionalTests}/EventSourceTests.cs (100%) rename test/{Microsoft.AspNetCore.Server.Kestrel.FunctionalTests => Kestrel.FunctionalTests}/FrameConnectionManagerTests.cs (100%) rename test/{Microsoft.AspNetCore.Server.Kestrel.FunctionalTests => Kestrel.FunctionalTests}/GeneratedCodeTests.cs (88%) rename test/{Microsoft.AspNetCore.Server.Kestrel.FunctionalTests => Kestrel.FunctionalTests}/HttpsConnectionAdapterTests.cs (100%) rename test/{Microsoft.AspNetCore.Server.Kestrel.FunctionalTests => Kestrel.FunctionalTests}/HttpsTests.cs (100%) rename test/{Microsoft.AspNetCore.Server.Kestrel.FunctionalTests => Kestrel.FunctionalTests}/KeepAliveTimeoutTests.cs (100%) rename test/{Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests.csproj => Kestrel.FunctionalTests/Kestrel.FunctionalTests.csproj} (86%) rename test/{Microsoft.AspNetCore.Server.Kestrel.FunctionalTests => Kestrel.FunctionalTests}/ListenHandleTests.cs (100%) rename test/{Microsoft.AspNetCore.Server.Kestrel.FunctionalTests => Kestrel.FunctionalTests}/LoggingConnectionAdapterTests.cs (100%) rename test/{Microsoft.AspNetCore.Server.Kestrel.FunctionalTests => Kestrel.FunctionalTests}/MaxRequestBodySizeTests.cs (100%) rename test/{Microsoft.AspNetCore.Server.Kestrel.FunctionalTests => Kestrel.FunctionalTests}/MaxRequestBufferSizeTests.cs (100%) rename test/{Microsoft.AspNetCore.Server.Kestrel.FunctionalTests => Kestrel.FunctionalTests}/MaxRequestLineSizeTests.cs (100%) rename test/{Microsoft.AspNetCore.Server.Kestrel.FunctionalTests => Kestrel.FunctionalTests}/Properties/AssemblyInfo.cs (100%) rename test/{Microsoft.AspNetCore.Server.Kestrel.FunctionalTests => Kestrel.FunctionalTests}/RequestBodyTimeoutTests.cs (100%) rename test/{Microsoft.AspNetCore.Server.Kestrel.FunctionalTests => Kestrel.FunctionalTests}/RequestHeaderLimitsTests.cs (100%) rename test/{Microsoft.AspNetCore.Server.Kestrel.FunctionalTests => Kestrel.FunctionalTests}/RequestHeadersTimeoutTests.cs (100%) rename test/{Microsoft.AspNetCore.Server.Kestrel.FunctionalTests => Kestrel.FunctionalTests}/RequestTargetProcessingTests.cs (100%) rename test/{Microsoft.AspNetCore.Server.Kestrel.FunctionalTests => Kestrel.FunctionalTests}/RequestTests.cs (100%) rename test/{Microsoft.AspNetCore.Server.Kestrel.FunctionalTests => Kestrel.FunctionalTests}/ResponseTests.cs (100%) rename test/{Microsoft.AspNetCore.Server.Kestrel.FunctionalTests => Kestrel.FunctionalTests}/SystemdActivation/Dockerfile (100%) rename test/{Microsoft.AspNetCore.Server.Kestrel.FunctionalTests => Kestrel.FunctionalTests}/SystemdActivation/docker-entrypoint.sh (100%) rename test/{Microsoft.AspNetCore.Server.Kestrel.FunctionalTests => Kestrel.FunctionalTests}/SystemdActivation/docker.sh (100%) rename test/{Microsoft.AspNetCore.Server.Kestrel.FunctionalTests => Kestrel.FunctionalTests}/TestHelpers/IPv6ScopeIdPresentConditionAttribute.cs (100%) rename test/{Microsoft.AspNetCore.Server.Kestrel.FunctionalTests => Kestrel.FunctionalTests}/TestHelpers/IPv6SupportedConditionAttribute.cs (100%) rename test/{Microsoft.AspNetCore.Server.Kestrel.FunctionalTests => Kestrel.FunctionalTests}/TestHelpers/IWebHostPortExtensions.cs (100%) rename test/{Microsoft.AspNetCore.Server.Kestrel.FunctionalTests => Kestrel.FunctionalTests}/TestHelpers/NetworkIsReachableAttribute.cs (100%) rename test/{Microsoft.AspNetCore.Server.Kestrel.FunctionalTests => Kestrel.FunctionalTests}/TestHelpers/TestServer.cs (100%) rename test/{Microsoft.AspNetCore.Server.Kestrel.FunctionalTests => Kestrel.FunctionalTests}/ThreadCountTests.cs (100%) rename test/{Microsoft.AspNetCore.Server.Kestrel.FunctionalTests => Kestrel.FunctionalTests}/UpgradeTests.cs (100%) rename test/{Microsoft.AspNetCore.Server.Kestrel.FunctionalTests => Kestrel.FunctionalTests}/xunit.runner.json (100%) rename test/{Microsoft.AspNetCore.Server.Kestrel.Performance => Kestrel.Performance}/DotSegmentRemovalBenchmark.cs (100%) rename test/{Microsoft.AspNetCore.Server.Kestrel.Performance => Kestrel.Performance}/ErrorUtilities.cs (100%) rename test/{Microsoft.AspNetCore.Server.Kestrel.Performance => Kestrel.Performance}/FrameFeatureCollection.cs (100%) rename test/{Microsoft.AspNetCore.Server.Kestrel.Performance => Kestrel.Performance}/FrameParsingOverheadBenchmark.cs (100%) rename test/{Microsoft.AspNetCore.Server.Kestrel.Performance => Kestrel.Performance}/FrameWritingBenchmark.cs (100%) rename test/{Microsoft.AspNetCore.Server.Kestrel.Performance/Microsoft.AspNetCore.Server.Kestrel.Performance.csproj => Kestrel.Performance/Kestrel.Performance.csproj} (77%) rename test/{Microsoft.AspNetCore.Server.Kestrel.Performance => Kestrel.Performance}/KestrelHttpParserBenchmark.cs (100%) rename test/{Microsoft.AspNetCore.Server.Kestrel.Performance => Kestrel.Performance}/KnownStringsBenchmark.cs (100%) rename test/{Microsoft.AspNetCore.Server.Kestrel.Performance => Kestrel.Performance}/Mocks/MockConnectionInformation.cs (100%) rename test/{Microsoft.AspNetCore.Server.Kestrel.Performance => Kestrel.Performance}/Mocks/MockTimeoutControl.cs (100%) rename test/{Microsoft.AspNetCore.Server.Kestrel.Performance => Kestrel.Performance}/Mocks/MockTrace.cs (100%) rename test/{Microsoft.AspNetCore.Server.Kestrel.Performance => Kestrel.Performance}/Mocks/NullParser.cs (100%) rename test/{Microsoft.AspNetCore.Server.Kestrel.Performance => Kestrel.Performance}/PipeThroughputBenchmark.cs (100%) rename test/{Microsoft.AspNetCore.Server.Kestrel.Performance => Kestrel.Performance}/Program.cs (100%) rename test/{Microsoft.AspNetCore.Server.Kestrel.Performance => Kestrel.Performance}/Readme.md (100%) rename test/{Microsoft.AspNetCore.Server.Kestrel.Performance => Kestrel.Performance}/RequestParsingBenchmark.cs (100%) rename test/{Microsoft.AspNetCore.Server.Kestrel.Performance => Kestrel.Performance}/RequestParsingData.cs (100%) rename test/{Microsoft.AspNetCore.Server.Kestrel.Performance => Kestrel.Performance}/ResponseHeaderCollectionBenchmark.cs (100%) rename test/{Microsoft.AspNetCore.Server.Kestrel.Performance => Kestrel.Performance}/ResponseHeadersWritingBenchmark.cs (100%) rename test/{Microsoft.AspNetCore.Server.Kestrel.Performance => Kestrel.Performance}/StringUtilitiesBenchmark.cs (100%) rename test/{Microsoft.AspNetCore.Server.Kestrel.Performance => Kestrel.Performance}/configs/CoreConfig.cs (100%) rename test/{Microsoft.AspNetCore.Server.Kestrel.Tests/Microsoft.AspNetCore.Server.Kestrel.Tests.csproj => Kestrel.Tests/Kestrel.Tests.csproj} (76%) rename test/{Microsoft.AspNetCore.Server.Kestrel.Tests => Kestrel.Tests}/WebHostBuilderKestrelExtensionsTests.cs (100%) rename test/{Microsoft.AspNetCore.Server.Kestrel.Tests => Kestrel.Tests}/xunit.runner.json (100%) rename test/{Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests.csproj => Kestrel.Transport.Libuv.Tests/Kestrel.Transport.Libuv.Tests.csproj} (79%) rename test/{Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests => Kestrel.Transport.Libuv.Tests}/LibuvConnectionTests.cs (100%) rename test/{Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests => Kestrel.Transport.Libuv.Tests}/LibuvOutputConsumerTests.cs (100%) rename test/{Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests => Kestrel.Transport.Libuv.Tests}/LibuvTransportFactoryTests.cs (100%) rename test/{Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests => Kestrel.Transport.Libuv.Tests}/LibuvTransportOptionsTests.cs (100%) rename test/{Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests => Kestrel.Transport.Libuv.Tests}/LibuvTransportTests.cs (100%) rename test/{Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests => Kestrel.Transport.Libuv.Tests}/ListenerPrimaryTests.cs (100%) rename test/{Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests => Kestrel.Transport.Libuv.Tests}/MultipleLoopTests.cs (100%) rename test/{Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests => Kestrel.Transport.Libuv.Tests}/NetworkingTests.cs (100%) rename test/{Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests => Kestrel.Transport.Libuv.Tests}/TestHelpers/MockConnectionHandler.cs (100%) rename test/{Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests => Kestrel.Transport.Libuv.Tests}/TestHelpers/MockLibuv.cs (100%) rename test/{Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests => Kestrel.Transport.Libuv.Tests}/TestHelpers/MockSocket.cs (100%) rename test/{Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests => Kestrel.Transport.Libuv.Tests}/TestHelpers/TestConstants.cs (100%) rename test/{Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests => Kestrel.Transport.Libuv.Tests}/TestHelpers/TestLibuvTransportContext.cs (100%) rename test/{Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests => Kestrel.Transport.Libuv.Tests}/UvStreamHandleTests.cs (100%) rename test/{Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests => Kestrel.Transport.Libuv.Tests}/UvTimerHandleTests.cs (100%) rename test/{Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests => Kestrel.Transport.Libuv.Tests}/xunit.runner.json (100%) diff --git a/.travis.yml b/.travis.yml index 70902067d3..73fb758d81 100644 --- a/.travis.yml +++ b/.travis.yml @@ -28,4 +28,4 @@ before_install: - if test "$TRAVIS_OS_NAME" == "osx"; then brew update; brew install openssl; ln -s /usr/local/opt/openssl/lib/libcrypto.1.0.0.dylib /usr/local/lib/; ln -s /usr/local/opt/openssl/lib/libssl.1.0.0.dylib /usr/local/lib/; fi script: - ./build.sh - - if test "$TRAVIS_OS_NAME" != "osx"; then bash test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/SystemdActivation/docker.sh; fi + - if test "$TRAVIS_OS_NAME" != "osx"; then bash test/Kestrel.FunctionalTests/SystemdActivation/docker.sh; fi diff --git a/.vscode/tasks.json b/.vscode/tasks.json index af0e4b2245..97f0b7ad07 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -7,13 +7,13 @@ }, // requires that you first run build.cmd or build.sh to install local builds of dotnet "windows": { - "command": "${env.LOCALAPPDATA}/Microsoft/dotnet/dotnet.exe" + "command": "${env:USERPROFILE}/.dotnet/x64/dotnet.exe" }, "osx": { - "command": "${env.HOME}/.dotnet/dotnet" + "command": "${env:HOME}/.dotnet/dotnet" }, "linux": { - "command": "${env.HOME}/.dotnet/dotnet" + "command": "${env:HOME}/.dotnet/dotnet" }, "suppressTaskName": true, "tasks": [ @@ -25,10 +25,17 @@ }, { "taskName": "Compile: solution", - "isBuildCommand": true, + "group": { + "isDefault": true, + "kind": "build" + }, + "presentation": { + "panel": "dedicated" + }, "args": [ "build", - "${workspaceRoot}/KestrelHttpServer.sln" + "${workspaceRoot}/KestrelHttpServer.sln", + "/p:GenerateFullPaths=true" ], "problemMatcher": "$msCompile", // these have to defined here because of https://github.com/Microsoft/vscode/issues/20740 @@ -37,14 +44,14 @@ "env": { // The location of .NET Framework reference assembiles. // These may not be installed yet if you have not run build.sh. - "ReferenceAssemblyRoot": "${env.HOME}/.nuget/packages/netframeworkreferenceassemblies/4.6.1/content" + "ReferenceAssemblyRoot": "${env:HOME}/.dotnet/buildtools/netfx/4.6.1/" } } }, "linux": { "options": { "env": { - "ReferenceAssemblyRoot": "${env.HOME}/.nuget/packages/netframeworkreferenceassemblies/4.6.1/content" + "ReferenceAssemblyRoot": "${env:HOME}/.dotnet/buildtools/netfx/4.6.1/" } } } @@ -52,15 +59,17 @@ { "taskName": "Test", "args": [ - "test" + "test", + "/p:GenerateFullPaths=true" ], "problemMatcher": "$msCompile", - "isTestCommand": true + "group": "test" }, { "taskName": "Compile: CodeGenerator", "args": [ - "build" + "build", + "/p:GenerateFullPaths=true" ], "options": { "cwd": "${workspaceRoot}/tools/CodeGenerator/" @@ -101,7 +110,7 @@ "Release" ], "options": { - "cwd": "${workspaceRoot}/test/Microsoft.AspNetCore.Server.Kestrel.Performance/" + "cwd": "${workspaceRoot}/test/Kestrel.Performance/" } } ] diff --git a/KestrelHttpServer.sln b/KestrelHttpServer.sln index a5e8db2e49..4c9791d022 100644 --- a/KestrelHttpServer.sln +++ b/KestrelHttpServer.sln @@ -36,9 +36,9 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "shared", "shared", "{0EF2AC test\shared\TestServiceContext.cs = test\shared\TestServiceContext.cs EndProjectSection EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Server.Kestrel.Core", "src\Microsoft.AspNetCore.Server.Kestrel.Core\Microsoft.AspNetCore.Server.Kestrel.Core.csproj", "{F510611A-3BEE-4B88-A613-5F4A74ED82A1}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Kestrel.Core", "src\Kestrel.Core\Kestrel.Core.csproj", "{F510611A-3BEE-4B88-A613-5F4A74ED82A1}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Server.Kestrel.Core.Tests", "test\Microsoft.AspNetCore.Server.Kestrel.Core.Tests\Microsoft.AspNetCore.Server.Kestrel.Core.Tests.csproj", "{37F3BFB2-6454-49E5-9D7F-581BF755CCFE}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Kestrel.Core.Tests", "test\Kestrel.Core.Tests\Kestrel.Core.Tests.csproj", "{37F3BFB2-6454-49E5-9D7F-581BF755CCFE}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SampleApp", "samples\SampleApp\SampleApp.csproj", "{2C3CB3DC-EEBF-4F52-9E1C-4F2F972E76C3}" EndProject @@ -46,11 +46,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LargeResponseApp", "samples EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CodeGenerator", "tools\CodeGenerator\CodeGenerator.csproj", "{BD2D4D29-1BD9-40D0-BB31-337D5416B63C}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Server.Kestrel.Https", "src\Microsoft.AspNetCore.Server.Kestrel.Https\Microsoft.AspNetCore.Server.Kestrel.Https.csproj", "{5F64B3C3-0C2E-431A-B820-A81BBFC863DA}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Kestrel.Https", "src\Kestrel.Https\Kestrel.Https.csproj", "{5F64B3C3-0C2E-431A-B820-A81BBFC863DA}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Server.Kestrel.FunctionalTests", "test\Microsoft.AspNetCore.Server.Kestrel.FunctionalTests\Microsoft.AspNetCore.Server.Kestrel.FunctionalTests.csproj", "{9559A5F1-080C-4909-B6CF-7E4B3DC55748}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Kestrel.FunctionalTests", "test\Kestrel.FunctionalTests\Kestrel.FunctionalTests.csproj", "{9559A5F1-080C-4909-B6CF-7E4B3DC55748}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Server.Kestrel.Performance", "test\Microsoft.AspNetCore.Server.Kestrel.Performance\Microsoft.AspNetCore.Server.Kestrel.Performance.csproj", "{EBFE9719-A44B-4978-A71F-D5C254E7F35A}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Kestrel.Performance", "test\Kestrel.Performance\Kestrel.Performance.csproj", "{EBFE9719-A44B-4978-A71F-D5C254E7F35A}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "TestCertificates", "TestCertificates", "{2822C132-BFFB-4D53-AC5B-E7E47DD81A6E}" ProjectSection(SolutionItems) = preProject @@ -68,17 +68,17 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "TestCertificates", "TestCer test\shared\TestCertificates\testCert.pfx = test\shared\TestCertificates\testCert.pfx EndProjectSection EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv", "src\Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv\Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.csproj", "{A76B8C8C-0DC5-4DD3-9B1F-02E51A0915F4}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Kestrel.Transport.Libuv", "src\Kestrel.Transport.Libuv\Kestrel.Transport.Libuv.csproj", "{A76B8C8C-0DC5-4DD3-9B1F-02E51A0915F4}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Server.Kestrel", "src\Microsoft.AspNetCore.Server.Kestrel\Microsoft.AspNetCore.Server.Kestrel.csproj", "{56139957-5C29-4E7D-89BD-7D20598B4EAF}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Kestrel", "src\Kestrel\Kestrel.csproj", "{56139957-5C29-4E7D-89BD-7D20598B4EAF}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets", "src\Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets\Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.csproj", "{6950B18F-A3D2-41A4-AFEC-8B7C49517611}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Kestrel.Transport.Sockets", "src\Kestrel.Transport.Sockets\Kestrel.Transport.Sockets.csproj", "{6950B18F-A3D2-41A4-AFEC-8B7C49517611}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions", "src\Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions\Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.csproj", "{2E9CB89D-EC8F-4DD9-A72B-08D5BABF752D}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Kestrel.Transport.Abstractions", "src\Kestrel.Transport.Abstractions\Kestrel.Transport.Abstractions.csproj", "{2E9CB89D-EC8F-4DD9-A72B-08D5BABF752D}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests", "test\Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests\Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests.csproj", "{D95A7EC3-48AC-4D03-B2E2-0DA3E13BD3A4}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Kestrel.Transport.Libuv.Tests", "test\Kestrel.Transport.Libuv.Tests\Kestrel.Transport.Libuv.Tests.csproj", "{D95A7EC3-48AC-4D03-B2E2-0DA3E13BD3A4}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Server.Kestrel.Tests", "test\Microsoft.AspNetCore.Server.Kestrel.Tests\Microsoft.AspNetCore.Server.Kestrel.Tests.csproj", "{4F1C30F8-CCAA-48D7-9DF6-2A84021F5BCC}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Kestrel.Tests", "test\Kestrel.Tests\Kestrel.Tests.csproj", "{4F1C30F8-CCAA-48D7-9DF6-2A84021F5BCC}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/build/repo.props b/build/repo.props index a5d5b0f21d..c1b53db759 100644 --- a/build/repo.props +++ b/build/repo.props @@ -1,5 +1,5 @@ - + diff --git a/samples/LargeResponseApp/LargeResponseApp.csproj b/samples/LargeResponseApp/LargeResponseApp.csproj index 1649a43c54..a53054ca27 100644 --- a/samples/LargeResponseApp/LargeResponseApp.csproj +++ b/samples/LargeResponseApp/LargeResponseApp.csproj @@ -8,7 +8,7 @@ - + diff --git a/samples/SampleApp/SampleApp.csproj b/samples/SampleApp/SampleApp.csproj index fbd339a9ac..d08c315d06 100644 --- a/samples/SampleApp/SampleApp.csproj +++ b/samples/SampleApp/SampleApp.csproj @@ -12,8 +12,8 @@ - - + + diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/Internal/AdaptedPipeline.cs b/src/Kestrel.Core/Adapter/Internal/AdaptedPipeline.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/Internal/AdaptedPipeline.cs rename to src/Kestrel.Core/Adapter/Internal/AdaptedPipeline.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/Internal/ConnectionAdapterContext.cs b/src/Kestrel.Core/Adapter/Internal/ConnectionAdapterContext.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/Internal/ConnectionAdapterContext.cs rename to src/Kestrel.Core/Adapter/Internal/ConnectionAdapterContext.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/Internal/IAdaptedConnection.cs b/src/Kestrel.Core/Adapter/Internal/IAdaptedConnection.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/Internal/IAdaptedConnection.cs rename to src/Kestrel.Core/Adapter/Internal/IAdaptedConnection.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/Internal/IConnectionAdapter.cs b/src/Kestrel.Core/Adapter/Internal/IConnectionAdapter.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/Internal/IConnectionAdapter.cs rename to src/Kestrel.Core/Adapter/Internal/IConnectionAdapter.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/Internal/LoggingConnectionAdapter.cs b/src/Kestrel.Core/Adapter/Internal/LoggingConnectionAdapter.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/Internal/LoggingConnectionAdapter.cs rename to src/Kestrel.Core/Adapter/Internal/LoggingConnectionAdapter.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/Internal/LoggingStream.cs b/src/Kestrel.Core/Adapter/Internal/LoggingStream.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/Internal/LoggingStream.cs rename to src/Kestrel.Core/Adapter/Internal/LoggingStream.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/Internal/RawStream.cs b/src/Kestrel.Core/Adapter/Internal/RawStream.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/Internal/RawStream.cs rename to src/Kestrel.Core/Adapter/Internal/RawStream.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/ListenOptionsConnectionLoggingExtensions.cs b/src/Kestrel.Core/Adapter/ListenOptionsConnectionLoggingExtensions.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Core/Adapter/ListenOptionsConnectionLoggingExtensions.cs rename to src/Kestrel.Core/Adapter/ListenOptionsConnectionLoggingExtensions.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/BadHttpRequestException.cs b/src/Kestrel.Core/BadHttpRequestException.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Core/BadHttpRequestException.cs rename to src/Kestrel.Core/BadHttpRequestException.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/CoreStrings.resx b/src/Kestrel.Core/CoreStrings.resx similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Core/CoreStrings.resx rename to src/Kestrel.Core/CoreStrings.resx diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Features/IHttpMinRequestBodyDataRateFeature.cs b/src/Kestrel.Core/Features/IHttpMinRequestBodyDataRateFeature.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Core/Features/IHttpMinRequestBodyDataRateFeature.cs rename to src/Kestrel.Core/Features/IHttpMinRequestBodyDataRateFeature.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Features/IHttpMinResponseDataRateFeature.cs b/src/Kestrel.Core/Features/IHttpMinResponseDataRateFeature.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Core/Features/IHttpMinResponseDataRateFeature.cs rename to src/Kestrel.Core/Features/IHttpMinResponseDataRateFeature.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/AddressBinder.cs b/src/Kestrel.Core/Internal/AddressBinder.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/AddressBinder.cs rename to src/Kestrel.Core/Internal/AddressBinder.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/ConnectionHandler.cs b/src/Kestrel.Core/Internal/ConnectionHandler.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/ConnectionHandler.cs rename to src/Kestrel.Core/Internal/ConnectionHandler.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/ConnectionLogScope.cs b/src/Kestrel.Core/Internal/ConnectionLogScope.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/ConnectionLogScope.cs rename to src/Kestrel.Core/Internal/ConnectionLogScope.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnection.cs b/src/Kestrel.Core/Internal/FrameConnection.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnection.cs rename to src/Kestrel.Core/Internal/FrameConnection.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnectionContext.cs b/src/Kestrel.Core/Internal/FrameConnectionContext.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnectionContext.cs rename to src/Kestrel.Core/Internal/FrameConnectionContext.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/ChunkWriter.cs b/src/Kestrel.Core/Internal/Http/ChunkWriter.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/ChunkWriter.cs rename to src/Kestrel.Core/Internal/Http/ChunkWriter.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/ConnectionOptions.cs b/src/Kestrel.Core/Internal/Http/ConnectionOptions.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/ConnectionOptions.cs rename to src/Kestrel.Core/Internal/Http/ConnectionOptions.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/DateHeaderValueManager.cs b/src/Kestrel.Core/Internal/Http/DateHeaderValueManager.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/DateHeaderValueManager.cs rename to src/Kestrel.Core/Internal/Http/DateHeaderValueManager.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.FeatureCollection.cs b/src/Kestrel.Core/Internal/Http/Frame.FeatureCollection.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.FeatureCollection.cs rename to src/Kestrel.Core/Internal/Http/Frame.FeatureCollection.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.Generated.cs b/src/Kestrel.Core/Internal/Http/Frame.Generated.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.Generated.cs rename to src/Kestrel.Core/Internal/Http/Frame.Generated.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.cs b/src/Kestrel.Core/Internal/Http/Frame.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.cs rename to src/Kestrel.Core/Internal/Http/Frame.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameAdapter.cs b/src/Kestrel.Core/Internal/Http/FrameAdapter.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameAdapter.cs rename to src/Kestrel.Core/Internal/Http/FrameAdapter.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameContext.cs b/src/Kestrel.Core/Internal/Http/FrameContext.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameContext.cs rename to src/Kestrel.Core/Internal/Http/FrameContext.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameDuplexStream.cs b/src/Kestrel.Core/Internal/Http/FrameDuplexStream.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameDuplexStream.cs rename to src/Kestrel.Core/Internal/Http/FrameDuplexStream.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameHeaders.Generated.cs b/src/Kestrel.Core/Internal/Http/FrameHeaders.Generated.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameHeaders.Generated.cs rename to src/Kestrel.Core/Internal/Http/FrameHeaders.Generated.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameHeaders.cs b/src/Kestrel.Core/Internal/Http/FrameHeaders.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameHeaders.cs rename to src/Kestrel.Core/Internal/Http/FrameHeaders.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameOfT.cs b/src/Kestrel.Core/Internal/Http/FrameOfT.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameOfT.cs rename to src/Kestrel.Core/Internal/Http/FrameOfT.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameRequestHeaders.cs b/src/Kestrel.Core/Internal/Http/FrameRequestHeaders.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameRequestHeaders.cs rename to src/Kestrel.Core/Internal/Http/FrameRequestHeaders.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameRequestStream.cs b/src/Kestrel.Core/Internal/Http/FrameRequestStream.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameRequestStream.cs rename to src/Kestrel.Core/Internal/Http/FrameRequestStream.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameResponseHeaders.cs b/src/Kestrel.Core/Internal/Http/FrameResponseHeaders.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameResponseHeaders.cs rename to src/Kestrel.Core/Internal/Http/FrameResponseHeaders.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameResponseStream.cs b/src/Kestrel.Core/Internal/Http/FrameResponseStream.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameResponseStream.cs rename to src/Kestrel.Core/Internal/Http/FrameResponseStream.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameStreamState.cs b/src/Kestrel.Core/Internal/Http/FrameStreamState.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameStreamState.cs rename to src/Kestrel.Core/Internal/Http/FrameStreamState.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/HttpMethod.cs b/src/Kestrel.Core/Internal/Http/HttpMethod.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/HttpMethod.cs rename to src/Kestrel.Core/Internal/Http/HttpMethod.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/HttpParser.cs b/src/Kestrel.Core/Internal/Http/HttpParser.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/HttpParser.cs rename to src/Kestrel.Core/Internal/Http/HttpParser.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/HttpScheme.cs b/src/Kestrel.Core/Internal/Http/HttpScheme.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/HttpScheme.cs rename to src/Kestrel.Core/Internal/Http/HttpScheme.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/HttpVersion.cs b/src/Kestrel.Core/Internal/Http/HttpVersion.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/HttpVersion.cs rename to src/Kestrel.Core/Internal/Http/HttpVersion.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/IFrameControl.cs b/src/Kestrel.Core/Internal/Http/IFrameControl.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/IFrameControl.cs rename to src/Kestrel.Core/Internal/Http/IFrameControl.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/IHttpHeadersHandler.cs b/src/Kestrel.Core/Internal/Http/IHttpHeadersHandler.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/IHttpHeadersHandler.cs rename to src/Kestrel.Core/Internal/Http/IHttpHeadersHandler.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/IHttpParser.cs b/src/Kestrel.Core/Internal/Http/IHttpParser.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/IHttpParser.cs rename to src/Kestrel.Core/Internal/Http/IHttpParser.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/IHttpRequestLineHandler.cs b/src/Kestrel.Core/Internal/Http/IHttpRequestLineHandler.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/IHttpRequestLineHandler.cs rename to src/Kestrel.Core/Internal/Http/IHttpRequestLineHandler.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/MessageBody.cs b/src/Kestrel.Core/Internal/Http/MessageBody.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/MessageBody.cs rename to src/Kestrel.Core/Internal/Http/MessageBody.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/OutputProducer.cs b/src/Kestrel.Core/Internal/Http/OutputProducer.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/OutputProducer.cs rename to src/Kestrel.Core/Internal/Http/OutputProducer.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/PathNormalizer.cs b/src/Kestrel.Core/Internal/Http/PathNormalizer.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/PathNormalizer.cs rename to src/Kestrel.Core/Internal/Http/PathNormalizer.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/PipelineExtensions.cs b/src/Kestrel.Core/Internal/Http/PipelineExtensions.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/PipelineExtensions.cs rename to src/Kestrel.Core/Internal/Http/PipelineExtensions.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/ProduceEndType.cs b/src/Kestrel.Core/Internal/Http/ProduceEndType.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/ProduceEndType.cs rename to src/Kestrel.Core/Internal/Http/ProduceEndType.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/ReasonPhrases.cs b/src/Kestrel.Core/Internal/Http/ReasonPhrases.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/ReasonPhrases.cs rename to src/Kestrel.Core/Internal/Http/ReasonPhrases.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/RequestProcessingStatus.cs b/src/Kestrel.Core/Internal/Http/RequestProcessingStatus.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/RequestProcessingStatus.cs rename to src/Kestrel.Core/Internal/Http/RequestProcessingStatus.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/RequestRejectionReason.cs b/src/Kestrel.Core/Internal/Http/RequestRejectionReason.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/RequestRejectionReason.cs rename to src/Kestrel.Core/Internal/Http/RequestRejectionReason.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/TransferCoding.cs b/src/Kestrel.Core/Internal/Http/TransferCoding.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/TransferCoding.cs rename to src/Kestrel.Core/Internal/Http/TransferCoding.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/CancellationTokenExtensions.cs b/src/Kestrel.Core/Internal/Infrastructure/CancellationTokenExtensions.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/CancellationTokenExtensions.cs rename to src/Kestrel.Core/Internal/Infrastructure/CancellationTokenExtensions.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/Constants.cs b/src/Kestrel.Core/Internal/Infrastructure/Constants.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/Constants.cs rename to src/Kestrel.Core/Internal/Infrastructure/Constants.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/CorrelationIdGenerator.cs b/src/Kestrel.Core/Internal/Infrastructure/CorrelationIdGenerator.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/CorrelationIdGenerator.cs rename to src/Kestrel.Core/Internal/Infrastructure/CorrelationIdGenerator.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/DebuggerWrapper.cs b/src/Kestrel.Core/Internal/Infrastructure/DebuggerWrapper.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/DebuggerWrapper.cs rename to src/Kestrel.Core/Internal/Infrastructure/DebuggerWrapper.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/Disposable.cs b/src/Kestrel.Core/Internal/Infrastructure/Disposable.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/Disposable.cs rename to src/Kestrel.Core/Internal/Infrastructure/Disposable.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/DisposableAction.cs b/src/Kestrel.Core/Internal/Infrastructure/DisposableAction.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/DisposableAction.cs rename to src/Kestrel.Core/Internal/Infrastructure/DisposableAction.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/FrameConnectionManager.cs b/src/Kestrel.Core/Internal/Infrastructure/FrameConnectionManager.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/FrameConnectionManager.cs rename to src/Kestrel.Core/Internal/Infrastructure/FrameConnectionManager.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/FrameConnectionManagerShutdownExtensions.cs b/src/Kestrel.Core/Internal/Infrastructure/FrameConnectionManagerShutdownExtensions.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/FrameConnectionManagerShutdownExtensions.cs rename to src/Kestrel.Core/Internal/Infrastructure/FrameConnectionManagerShutdownExtensions.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/FrameConnectionReference.cs b/src/Kestrel.Core/Internal/Infrastructure/FrameConnectionReference.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/FrameConnectionReference.cs rename to src/Kestrel.Core/Internal/Infrastructure/FrameConnectionReference.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/FrameHeartbeatManager.cs b/src/Kestrel.Core/Internal/Infrastructure/FrameHeartbeatManager.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/FrameHeartbeatManager.cs rename to src/Kestrel.Core/Internal/Infrastructure/FrameHeartbeatManager.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/Heartbeat.cs b/src/Kestrel.Core/Internal/Infrastructure/Heartbeat.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/Heartbeat.cs rename to src/Kestrel.Core/Internal/Infrastructure/Heartbeat.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/HttpUtilities.Generated.cs b/src/Kestrel.Core/Internal/Infrastructure/HttpUtilities.Generated.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/HttpUtilities.Generated.cs rename to src/Kestrel.Core/Internal/Infrastructure/HttpUtilities.Generated.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/HttpUtilities.cs b/src/Kestrel.Core/Internal/Infrastructure/HttpUtilities.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/HttpUtilities.cs rename to src/Kestrel.Core/Internal/Infrastructure/HttpUtilities.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/IDebugger.cs b/src/Kestrel.Core/Internal/Infrastructure/IDebugger.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/IDebugger.cs rename to src/Kestrel.Core/Internal/Infrastructure/IDebugger.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/IHeartbeatHandler.cs b/src/Kestrel.Core/Internal/Infrastructure/IHeartbeatHandler.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/IHeartbeatHandler.cs rename to src/Kestrel.Core/Internal/Infrastructure/IHeartbeatHandler.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/IKestrelTrace.cs b/src/Kestrel.Core/Internal/Infrastructure/IKestrelTrace.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/IKestrelTrace.cs rename to src/Kestrel.Core/Internal/Infrastructure/IKestrelTrace.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/ISystemClock.cs b/src/Kestrel.Core/Internal/Infrastructure/ISystemClock.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/ISystemClock.cs rename to src/Kestrel.Core/Internal/Infrastructure/ISystemClock.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/IThreadPool.cs b/src/Kestrel.Core/Internal/Infrastructure/IThreadPool.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/IThreadPool.cs rename to src/Kestrel.Core/Internal/Infrastructure/IThreadPool.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/ITimeoutControl.cs b/src/Kestrel.Core/Internal/Infrastructure/ITimeoutControl.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/ITimeoutControl.cs rename to src/Kestrel.Core/Internal/Infrastructure/ITimeoutControl.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/InlineLoggingThreadPool.cs b/src/Kestrel.Core/Internal/Infrastructure/InlineLoggingThreadPool.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/InlineLoggingThreadPool.cs rename to src/Kestrel.Core/Internal/Infrastructure/InlineLoggingThreadPool.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/KestrelEventSource.cs b/src/Kestrel.Core/Internal/Infrastructure/KestrelEventSource.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/KestrelEventSource.cs rename to src/Kestrel.Core/Internal/Infrastructure/KestrelEventSource.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/KestrelTrace.cs b/src/Kestrel.Core/Internal/Infrastructure/KestrelTrace.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/KestrelTrace.cs rename to src/Kestrel.Core/Internal/Infrastructure/KestrelTrace.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/LoggingThreadPool.cs b/src/Kestrel.Core/Internal/Infrastructure/LoggingThreadPool.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/LoggingThreadPool.cs rename to src/Kestrel.Core/Internal/Infrastructure/LoggingThreadPool.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/ReadOnlyStream.cs b/src/Kestrel.Core/Internal/Infrastructure/ReadOnlyStream.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/ReadOnlyStream.cs rename to src/Kestrel.Core/Internal/Infrastructure/ReadOnlyStream.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/ResourceCounter.cs b/src/Kestrel.Core/Internal/Infrastructure/ResourceCounter.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/ResourceCounter.cs rename to src/Kestrel.Core/Internal/Infrastructure/ResourceCounter.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/Streams.cs b/src/Kestrel.Core/Internal/Infrastructure/Streams.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/Streams.cs rename to src/Kestrel.Core/Internal/Infrastructure/Streams.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/StringUtilities.cs b/src/Kestrel.Core/Internal/Infrastructure/StringUtilities.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/StringUtilities.cs rename to src/Kestrel.Core/Internal/Infrastructure/StringUtilities.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/SystemClock.cs b/src/Kestrel.Core/Internal/Infrastructure/SystemClock.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/SystemClock.cs rename to src/Kestrel.Core/Internal/Infrastructure/SystemClock.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/ThrowingWriteOnlyStream.cs b/src/Kestrel.Core/Internal/Infrastructure/ThrowingWriteOnlyStream.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/ThrowingWriteOnlyStream.cs rename to src/Kestrel.Core/Internal/Infrastructure/ThrowingWriteOnlyStream.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/TimeoutAction.cs b/src/Kestrel.Core/Internal/Infrastructure/TimeoutAction.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/TimeoutAction.cs rename to src/Kestrel.Core/Internal/Infrastructure/TimeoutAction.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/UriUtilities.cs b/src/Kestrel.Core/Internal/Infrastructure/UriUtilities.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/UriUtilities.cs rename to src/Kestrel.Core/Internal/Infrastructure/UriUtilities.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/WrappingStream.cs b/src/Kestrel.Core/Internal/Infrastructure/WrappingStream.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/WrappingStream.cs rename to src/Kestrel.Core/Internal/Infrastructure/WrappingStream.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/WriteOnlyStream.cs b/src/Kestrel.Core/Internal/Infrastructure/WriteOnlyStream.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/WriteOnlyStream.cs rename to src/Kestrel.Core/Internal/Infrastructure/WriteOnlyStream.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/KestrelServerOptionsSetup.cs b/src/Kestrel.Core/Internal/KestrelServerOptionsSetup.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/KestrelServerOptionsSetup.cs rename to src/Kestrel.Core/Internal/KestrelServerOptionsSetup.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/RejectionConnection.cs b/src/Kestrel.Core/Internal/RejectionConnection.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/RejectionConnection.cs rename to src/Kestrel.Core/Internal/RejectionConnection.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/ServerAddressesFeature.cs b/src/Kestrel.Core/Internal/ServerAddressesFeature.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/ServerAddressesFeature.cs rename to src/Kestrel.Core/Internal/ServerAddressesFeature.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/ServiceContext.cs b/src/Kestrel.Core/Internal/ServiceContext.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/ServiceContext.cs rename to src/Kestrel.Core/Internal/ServiceContext.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Microsoft.AspNetCore.Server.Kestrel.Core.csproj b/src/Kestrel.Core/Kestrel.Core.csproj similarity index 85% rename from src/Microsoft.AspNetCore.Server.Kestrel.Core/Microsoft.AspNetCore.Server.Kestrel.Core.csproj rename to src/Kestrel.Core/Kestrel.Core.csproj index d408125990..46181aa528 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Microsoft.AspNetCore.Server.Kestrel.Core.csproj +++ b/src/Kestrel.Core/Kestrel.Core.csproj @@ -3,6 +3,8 @@ + Microsoft.AspNetCore.Server.Kestrel.Core + Microsoft.AspNetCore.Server.Kestrel.Core Core components of ASP.NET Core Kestrel cross-platform web server. netstandard2.0 true @@ -24,7 +26,7 @@ - + diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/KestrelServer.cs b/src/Kestrel.Core/KestrelServer.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Core/KestrelServer.cs rename to src/Kestrel.Core/KestrelServer.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/KestrelServerLimits.cs b/src/Kestrel.Core/KestrelServerLimits.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Core/KestrelServerLimits.cs rename to src/Kestrel.Core/KestrelServerLimits.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/KestrelServerOptions.cs b/src/Kestrel.Core/KestrelServerOptions.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Core/KestrelServerOptions.cs rename to src/Kestrel.Core/KestrelServerOptions.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/ListenOptions.cs b/src/Kestrel.Core/ListenOptions.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Core/ListenOptions.cs rename to src/Kestrel.Core/ListenOptions.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/MinDataRate.cs b/src/Kestrel.Core/MinDataRate.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Core/MinDataRate.cs rename to src/Kestrel.Core/MinDataRate.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Properties/AssemblyInfo.cs b/src/Kestrel.Core/Properties/AssemblyInfo.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Core/Properties/AssemblyInfo.cs rename to src/Kestrel.Core/Properties/AssemblyInfo.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Properties/CoreStrings.Designer.cs b/src/Kestrel.Core/Properties/CoreStrings.Designer.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Core/Properties/CoreStrings.Designer.cs rename to src/Kestrel.Core/Properties/CoreStrings.Designer.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/ServerAddress.cs b/src/Kestrel.Core/ServerAddress.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Core/ServerAddress.cs rename to src/Kestrel.Core/ServerAddress.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Systemd/KestrelServerOptionsSystemdExtensions.cs b/src/Kestrel.Core/Systemd/KestrelServerOptionsSystemdExtensions.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Core/Systemd/KestrelServerOptionsSystemdExtensions.cs rename to src/Kestrel.Core/Systemd/KestrelServerOptionsSystemdExtensions.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Https/ClientCertificateMode.cs b/src/Kestrel.Https/ClientCertificateMode.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Https/ClientCertificateMode.cs rename to src/Kestrel.Https/ClientCertificateMode.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Https/HttpsConnectionAdapterOptions.cs b/src/Kestrel.Https/HttpsConnectionAdapterOptions.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Https/HttpsConnectionAdapterOptions.cs rename to src/Kestrel.Https/HttpsConnectionAdapterOptions.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Https/HttpsStrings.resx b/src/Kestrel.Https/HttpsStrings.resx similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Https/HttpsStrings.resx rename to src/Kestrel.Https/HttpsStrings.resx diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Https/Internal/ClosedStream.cs b/src/Kestrel.Https/Internal/ClosedStream.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Https/Internal/ClosedStream.cs rename to src/Kestrel.Https/Internal/ClosedStream.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Https/Internal/HttpsConnectionAdapter.cs b/src/Kestrel.Https/Internal/HttpsConnectionAdapter.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Https/Internal/HttpsConnectionAdapter.cs rename to src/Kestrel.Https/Internal/HttpsConnectionAdapter.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Https/Internal/TlsConnectionFeature.cs b/src/Kestrel.Https/Internal/TlsConnectionFeature.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Https/Internal/TlsConnectionFeature.cs rename to src/Kestrel.Https/Internal/TlsConnectionFeature.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Https/Microsoft.AspNetCore.Server.Kestrel.Https.csproj b/src/Kestrel.Https/Kestrel.Https.csproj similarity index 80% rename from src/Microsoft.AspNetCore.Server.Kestrel.Https/Microsoft.AspNetCore.Server.Kestrel.Https.csproj rename to src/Kestrel.Https/Kestrel.Https.csproj index d1801ffa01..ac3ae037a5 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Https/Microsoft.AspNetCore.Server.Kestrel.Https.csproj +++ b/src/Kestrel.Https/Kestrel.Https.csproj @@ -3,6 +3,8 @@ + Microsoft.AspNetCore.Server.Kestrel.Https + Microsoft.AspNetCore.Server.Kestrel.Https HTTPS support for the ASP.NET Core Kestrel cross-platform web server. netstandard2.0 true @@ -14,7 +16,7 @@ - + diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Https/ListenOptionsHttpsExtensions.cs b/src/Kestrel.Https/ListenOptionsHttpsExtensions.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Https/ListenOptionsHttpsExtensions.cs rename to src/Kestrel.Https/ListenOptionsHttpsExtensions.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Https/Properties/AssemblyInfo.cs b/src/Kestrel.Https/Properties/AssemblyInfo.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Https/Properties/AssemblyInfo.cs rename to src/Kestrel.Https/Properties/AssemblyInfo.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Https/Properties/HttpsStrings.Designer.cs b/src/Kestrel.Https/Properties/HttpsStrings.Designer.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Https/Properties/HttpsStrings.Designer.cs rename to src/Kestrel.Https/Properties/HttpsStrings.Designer.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/Exceptions/AddressInUseException.cs b/src/Kestrel.Transport.Abstractions/Exceptions/AddressInUseException.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/Exceptions/AddressInUseException.cs rename to src/Kestrel.Transport.Abstractions/Exceptions/AddressInUseException.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/Exceptions/ConnectionAbortedException.cs b/src/Kestrel.Transport.Abstractions/Exceptions/ConnectionAbortedException.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/Exceptions/ConnectionAbortedException.cs rename to src/Kestrel.Transport.Abstractions/Exceptions/ConnectionAbortedException.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/Exceptions/ConnectionResetException.cs b/src/Kestrel.Transport.Abstractions/Exceptions/ConnectionResetException.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/Exceptions/ConnectionResetException.cs rename to src/Kestrel.Transport.Abstractions/Exceptions/ConnectionResetException.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/Internal/FileHandleType.cs b/src/Kestrel.Transport.Abstractions/Internal/FileHandleType.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/Internal/FileHandleType.cs rename to src/Kestrel.Transport.Abstractions/Internal/FileHandleType.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/Internal/IConnectionContext.cs b/src/Kestrel.Transport.Abstractions/Internal/IConnectionContext.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/Internal/IConnectionContext.cs rename to src/Kestrel.Transport.Abstractions/Internal/IConnectionContext.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/Internal/IConnectionHandler.cs b/src/Kestrel.Transport.Abstractions/Internal/IConnectionHandler.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/Internal/IConnectionHandler.cs rename to src/Kestrel.Transport.Abstractions/Internal/IConnectionHandler.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/Internal/IConnectionInformation.cs b/src/Kestrel.Transport.Abstractions/Internal/IConnectionInformation.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/Internal/IConnectionInformation.cs rename to src/Kestrel.Transport.Abstractions/Internal/IConnectionInformation.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/Internal/IEndPointInformation.cs b/src/Kestrel.Transport.Abstractions/Internal/IEndPointInformation.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/Internal/IEndPointInformation.cs rename to src/Kestrel.Transport.Abstractions/Internal/IEndPointInformation.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/Internal/ITransport.cs b/src/Kestrel.Transport.Abstractions/Internal/ITransport.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/Internal/ITransport.cs rename to src/Kestrel.Transport.Abstractions/Internal/ITransport.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/Internal/ITransportFactory.cs b/src/Kestrel.Transport.Abstractions/Internal/ITransportFactory.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/Internal/ITransportFactory.cs rename to src/Kestrel.Transport.Abstractions/Internal/ITransportFactory.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/Internal/ListenType.cs b/src/Kestrel.Transport.Abstractions/Internal/ListenType.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/Internal/ListenType.cs rename to src/Kestrel.Transport.Abstractions/Internal/ListenType.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/Internal/SchedulingMode.cs b/src/Kestrel.Transport.Abstractions/Internal/SchedulingMode.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/Internal/SchedulingMode.cs rename to src/Kestrel.Transport.Abstractions/Internal/SchedulingMode.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.csproj b/src/Kestrel.Transport.Abstractions/Kestrel.Transport.Abstractions.csproj similarity index 87% rename from src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.csproj rename to src/Kestrel.Transport.Abstractions/Kestrel.Transport.Abstractions.csproj index b815a122bc..0051d3dabd 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.csproj +++ b/src/Kestrel.Transport.Abstractions/Kestrel.Transport.Abstractions.csproj @@ -3,6 +3,8 @@ + Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions + Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions Transport abstractions for the ASP.NET Core Kestrel cross-platform web server. netstandard2.0 true diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/IAsyncDisposable.cs b/src/Kestrel.Transport.Libuv/Internal/IAsyncDisposable.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/IAsyncDisposable.cs rename to src/Kestrel.Transport.Libuv/Internal/IAsyncDisposable.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/ILibuvTrace.cs b/src/Kestrel.Transport.Libuv/Internal/ILibuvTrace.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/ILibuvTrace.cs rename to src/Kestrel.Transport.Libuv/Internal/ILibuvTrace.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvAwaitable.cs b/src/Kestrel.Transport.Libuv/Internal/LibuvAwaitable.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvAwaitable.cs rename to src/Kestrel.Transport.Libuv/Internal/LibuvAwaitable.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvConnection.cs b/src/Kestrel.Transport.Libuv/Internal/LibuvConnection.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvConnection.cs rename to src/Kestrel.Transport.Libuv/Internal/LibuvConnection.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvConnectionContext.cs b/src/Kestrel.Transport.Libuv/Internal/LibuvConnectionContext.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvConnectionContext.cs rename to src/Kestrel.Transport.Libuv/Internal/LibuvConnectionContext.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvConstants.cs b/src/Kestrel.Transport.Libuv/Internal/LibuvConstants.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvConstants.cs rename to src/Kestrel.Transport.Libuv/Internal/LibuvConstants.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvOutputConsumer.cs b/src/Kestrel.Transport.Libuv/Internal/LibuvOutputConsumer.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvOutputConsumer.cs rename to src/Kestrel.Transport.Libuv/Internal/LibuvOutputConsumer.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvThread.cs b/src/Kestrel.Transport.Libuv/Internal/LibuvThread.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvThread.cs rename to src/Kestrel.Transport.Libuv/Internal/LibuvThread.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvTrace.cs b/src/Kestrel.Transport.Libuv/Internal/LibuvTrace.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvTrace.cs rename to src/Kestrel.Transport.Libuv/Internal/LibuvTrace.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvTransportContext.cs b/src/Kestrel.Transport.Libuv/Internal/LibuvTransportContext.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvTransportContext.cs rename to src/Kestrel.Transport.Libuv/Internal/LibuvTransportContext.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Listener.cs b/src/Kestrel.Transport.Libuv/Internal/Listener.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Listener.cs rename to src/Kestrel.Transport.Libuv/Internal/Listener.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/ListenerContext.cs b/src/Kestrel.Transport.Libuv/Internal/ListenerContext.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/ListenerContext.cs rename to src/Kestrel.Transport.Libuv/Internal/ListenerContext.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/ListenerPrimary.cs b/src/Kestrel.Transport.Libuv/Internal/ListenerPrimary.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/ListenerPrimary.cs rename to src/Kestrel.Transport.Libuv/Internal/ListenerPrimary.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/ListenerSecondary.cs b/src/Kestrel.Transport.Libuv/Internal/ListenerSecondary.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/ListenerSecondary.cs rename to src/Kestrel.Transport.Libuv/Internal/ListenerSecondary.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/LibuvFunctions.cs b/src/Kestrel.Transport.Libuv/Internal/Networking/LibuvFunctions.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/LibuvFunctions.cs rename to src/Kestrel.Transport.Libuv/Internal/Networking/LibuvFunctions.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/PlatformApis.cs b/src/Kestrel.Transport.Libuv/Internal/Networking/PlatformApis.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/PlatformApis.cs rename to src/Kestrel.Transport.Libuv/Internal/Networking/PlatformApis.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/SockAddr.cs b/src/Kestrel.Transport.Libuv/Internal/Networking/SockAddr.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/SockAddr.cs rename to src/Kestrel.Transport.Libuv/Internal/Networking/SockAddr.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvAsyncHandle.cs b/src/Kestrel.Transport.Libuv/Internal/Networking/UvAsyncHandle.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvAsyncHandle.cs rename to src/Kestrel.Transport.Libuv/Internal/Networking/UvAsyncHandle.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvConnectRequest.cs b/src/Kestrel.Transport.Libuv/Internal/Networking/UvConnectRequest.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvConnectRequest.cs rename to src/Kestrel.Transport.Libuv/Internal/Networking/UvConnectRequest.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvException.cs b/src/Kestrel.Transport.Libuv/Internal/Networking/UvException.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvException.cs rename to src/Kestrel.Transport.Libuv/Internal/Networking/UvException.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvHandle.cs b/src/Kestrel.Transport.Libuv/Internal/Networking/UvHandle.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvHandle.cs rename to src/Kestrel.Transport.Libuv/Internal/Networking/UvHandle.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvLoopHandle.cs b/src/Kestrel.Transport.Libuv/Internal/Networking/UvLoopHandle.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvLoopHandle.cs rename to src/Kestrel.Transport.Libuv/Internal/Networking/UvLoopHandle.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvMemory.cs b/src/Kestrel.Transport.Libuv/Internal/Networking/UvMemory.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvMemory.cs rename to src/Kestrel.Transport.Libuv/Internal/Networking/UvMemory.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvPipeHandle.cs b/src/Kestrel.Transport.Libuv/Internal/Networking/UvPipeHandle.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvPipeHandle.cs rename to src/Kestrel.Transport.Libuv/Internal/Networking/UvPipeHandle.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvRequest.cs b/src/Kestrel.Transport.Libuv/Internal/Networking/UvRequest.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvRequest.cs rename to src/Kestrel.Transport.Libuv/Internal/Networking/UvRequest.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvStreamHandle.cs b/src/Kestrel.Transport.Libuv/Internal/Networking/UvStreamHandle.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvStreamHandle.cs rename to src/Kestrel.Transport.Libuv/Internal/Networking/UvStreamHandle.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvTcpHandle.cs b/src/Kestrel.Transport.Libuv/Internal/Networking/UvTcpHandle.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvTcpHandle.cs rename to src/Kestrel.Transport.Libuv/Internal/Networking/UvTcpHandle.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvTimerHandle.cs b/src/Kestrel.Transport.Libuv/Internal/Networking/UvTimerHandle.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvTimerHandle.cs rename to src/Kestrel.Transport.Libuv/Internal/Networking/UvTimerHandle.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvWriteReq.cs b/src/Kestrel.Transport.Libuv/Internal/Networking/UvWriteReq.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/Networking/UvWriteReq.cs rename to src/Kestrel.Transport.Libuv/Internal/Networking/UvWriteReq.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/WriteReqPool.cs b/src/Kestrel.Transport.Libuv/Internal/WriteReqPool.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/WriteReqPool.cs rename to src/Kestrel.Transport.Libuv/Internal/WriteReqPool.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.csproj b/src/Kestrel.Transport.Libuv/Kestrel.Transport.Libuv.csproj similarity index 77% rename from src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.csproj rename to src/Kestrel.Transport.Libuv/Kestrel.Transport.Libuv.csproj index 725988a030..78b2e79bc8 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.csproj +++ b/src/Kestrel.Transport.Libuv/Kestrel.Transport.Libuv.csproj @@ -3,6 +3,8 @@ + Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv + Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv Libuv transport for the ASP.NET Core Kestrel cross-platform web server. netstandard2.0 true @@ -20,7 +22,7 @@ - + diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/LibuvTransport.cs b/src/Kestrel.Transport.Libuv/LibuvTransport.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/LibuvTransport.cs rename to src/Kestrel.Transport.Libuv/LibuvTransport.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/LibuvTransportFactory.cs b/src/Kestrel.Transport.Libuv/LibuvTransportFactory.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/LibuvTransportFactory.cs rename to src/Kestrel.Transport.Libuv/LibuvTransportFactory.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/LibuvTransportOptions.cs b/src/Kestrel.Transport.Libuv/LibuvTransportOptions.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/LibuvTransportOptions.cs rename to src/Kestrel.Transport.Libuv/LibuvTransportOptions.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/WebHostBuilderLibuvExtensions.cs b/src/Kestrel.Transport.Libuv/WebHostBuilderLibuvExtensions.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/WebHostBuilderLibuvExtensions.cs rename to src/Kestrel.Transport.Libuv/WebHostBuilderLibuvExtensions.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.csproj b/src/Kestrel.Transport.Sockets/Kestrel.Transport.Sockets.csproj similarity index 79% rename from src/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.csproj rename to src/Kestrel.Transport.Sockets/Kestrel.Transport.Sockets.csproj index eb63e0c381..f28cf1a9f3 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.csproj +++ b/src/Kestrel.Transport.Sockets/Kestrel.Transport.Sockets.csproj @@ -3,6 +3,8 @@ + Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets + Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets Managed socket transport for the ASP.NET Core Kestrel cross-platform web server. netstandard2.0 true @@ -20,7 +22,7 @@ - + diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets/Properties/SocketsStrings.Designer.cs b/src/Kestrel.Transport.Sockets/Properties/SocketsStrings.Designer.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets/Properties/SocketsStrings.Designer.cs rename to src/Kestrel.Transport.Sockets/Properties/SocketsStrings.Designer.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets/SocketConnection.cs b/src/Kestrel.Transport.Sockets/SocketConnection.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets/SocketConnection.cs rename to src/Kestrel.Transport.Sockets/SocketConnection.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets/SocketTransport.cs b/src/Kestrel.Transport.Sockets/SocketTransport.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets/SocketTransport.cs rename to src/Kestrel.Transport.Sockets/SocketTransport.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets/SocketTransportFactory.cs b/src/Kestrel.Transport.Sockets/SocketTransportFactory.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets/SocketTransportFactory.cs rename to src/Kestrel.Transport.Sockets/SocketTransportFactory.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets/SocketTransportOptions.cs b/src/Kestrel.Transport.Sockets/SocketTransportOptions.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets/SocketTransportOptions.cs rename to src/Kestrel.Transport.Sockets/SocketTransportOptions.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets/SocketsStrings.resx b/src/Kestrel.Transport.Sockets/SocketsStrings.resx similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets/SocketsStrings.resx rename to src/Kestrel.Transport.Sockets/SocketsStrings.resx diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets/WebHostBuilderSocketExtensions.cs b/src/Kestrel.Transport.Sockets/WebHostBuilderSocketExtensions.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets/WebHostBuilderSocketExtensions.cs rename to src/Kestrel.Transport.Sockets/WebHostBuilderSocketExtensions.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Microsoft.AspNetCore.Server.Kestrel.csproj b/src/Kestrel/Kestrel.csproj similarity index 67% rename from src/Microsoft.AspNetCore.Server.Kestrel/Microsoft.AspNetCore.Server.Kestrel.csproj rename to src/Kestrel/Kestrel.csproj index eab9f18969..0afd53fb6d 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Microsoft.AspNetCore.Server.Kestrel.csproj +++ b/src/Kestrel/Kestrel.csproj @@ -3,6 +3,8 @@ + Microsoft.AspNetCore.Server.Kestrel + Microsoft.AspNetCore.Server.Kestrel ASP.NET Core Kestrel cross-platform web server. netstandard2.0 true @@ -16,8 +18,8 @@ - - + + diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/WebHostBuilderKestrelExtensions.cs b/src/Kestrel/WebHostBuilderKestrelExtensions.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel/WebHostBuilderKestrelExtensions.cs rename to src/Kestrel/WebHostBuilderKestrelExtensions.cs diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/AddressBinderTests.cs b/test/Kestrel.Core.Tests/AddressBinderTests.cs similarity index 100% rename from test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/AddressBinderTests.cs rename to test/Kestrel.Core.Tests/AddressBinderTests.cs diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/AsciiDecoding.cs b/test/Kestrel.Core.Tests/AsciiDecoding.cs similarity index 100% rename from test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/AsciiDecoding.cs rename to test/Kestrel.Core.Tests/AsciiDecoding.cs diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/ChunkWriterTests.cs b/test/Kestrel.Core.Tests/ChunkWriterTests.cs similarity index 100% rename from test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/ChunkWriterTests.cs rename to test/Kestrel.Core.Tests/ChunkWriterTests.cs diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/DateHeaderValueManagerTests.cs b/test/Kestrel.Core.Tests/DateHeaderValueManagerTests.cs similarity index 100% rename from test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/DateHeaderValueManagerTests.cs rename to test/Kestrel.Core.Tests/DateHeaderValueManagerTests.cs diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameConnectionManagerTests.cs b/test/Kestrel.Core.Tests/FrameConnectionManagerTests.cs similarity index 100% rename from test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameConnectionManagerTests.cs rename to test/Kestrel.Core.Tests/FrameConnectionManagerTests.cs diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameConnectionTests.cs b/test/Kestrel.Core.Tests/FrameConnectionTests.cs similarity index 100% rename from test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameConnectionTests.cs rename to test/Kestrel.Core.Tests/FrameConnectionTests.cs diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameHeadersTests.cs b/test/Kestrel.Core.Tests/FrameHeadersTests.cs similarity index 100% rename from test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameHeadersTests.cs rename to test/Kestrel.Core.Tests/FrameHeadersTests.cs diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameRequestHeadersTests.cs b/test/Kestrel.Core.Tests/FrameRequestHeadersTests.cs similarity index 100% rename from test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameRequestHeadersTests.cs rename to test/Kestrel.Core.Tests/FrameRequestHeadersTests.cs diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameRequestStreamTests.cs b/test/Kestrel.Core.Tests/FrameRequestStreamTests.cs similarity index 100% rename from test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameRequestStreamTests.cs rename to test/Kestrel.Core.Tests/FrameRequestStreamTests.cs diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameResponseHeadersTests.cs b/test/Kestrel.Core.Tests/FrameResponseHeadersTests.cs similarity index 100% rename from test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameResponseHeadersTests.cs rename to test/Kestrel.Core.Tests/FrameResponseHeadersTests.cs diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameResponseStreamTests.cs b/test/Kestrel.Core.Tests/FrameResponseStreamTests.cs similarity index 100% rename from test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameResponseStreamTests.cs rename to test/Kestrel.Core.Tests/FrameResponseStreamTests.cs diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameTests.cs b/test/Kestrel.Core.Tests/FrameTests.cs similarity index 100% rename from test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameTests.cs rename to test/Kestrel.Core.Tests/FrameTests.cs diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/HeartbeatTests.cs b/test/Kestrel.Core.Tests/HeartbeatTests.cs similarity index 100% rename from test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/HeartbeatTests.cs rename to test/Kestrel.Core.Tests/HeartbeatTests.cs diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/HttpParserTests.cs b/test/Kestrel.Core.Tests/HttpParserTests.cs similarity index 100% rename from test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/HttpParserTests.cs rename to test/Kestrel.Core.Tests/HttpParserTests.cs diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/HttpUtilitiesTest.cs b/test/Kestrel.Core.Tests/HttpUtilitiesTest.cs similarity index 100% rename from test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/HttpUtilitiesTest.cs rename to test/Kestrel.Core.Tests/HttpUtilitiesTest.cs diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/Microsoft.AspNetCore.Server.Kestrel.Core.Tests.csproj b/test/Kestrel.Core.Tests/Kestrel.Core.Tests.csproj similarity index 85% rename from test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/Microsoft.AspNetCore.Server.Kestrel.Core.Tests.csproj rename to test/Kestrel.Core.Tests/Kestrel.Core.Tests.csproj index 5289c063ab..469209bfd9 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/Microsoft.AspNetCore.Server.Kestrel.Core.Tests.csproj +++ b/test/Kestrel.Core.Tests/Kestrel.Core.Tests.csproj @@ -3,6 +3,8 @@ + Microsoft.AspNetCore.Server.Kestrel.Core.Tests + Microsoft.AspNetCore.Server.Kestrel.Core.Tests netcoreapp2.0;net461 netcoreapp2.0 true @@ -21,7 +23,7 @@ - + diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/KestrelEventSourceTests.cs b/test/Kestrel.Core.Tests/KestrelEventSourceTests.cs similarity index 100% rename from test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/KestrelEventSourceTests.cs rename to test/Kestrel.Core.Tests/KestrelEventSourceTests.cs diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/KestrelServerLimitsTests.cs b/test/Kestrel.Core.Tests/KestrelServerLimitsTests.cs similarity index 100% rename from test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/KestrelServerLimitsTests.cs rename to test/Kestrel.Core.Tests/KestrelServerLimitsTests.cs diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/KestrelServerOptionsTests.cs b/test/Kestrel.Core.Tests/KestrelServerOptionsTests.cs similarity index 100% rename from test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/KestrelServerOptionsTests.cs rename to test/Kestrel.Core.Tests/KestrelServerOptionsTests.cs diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/KestrelServerTests.cs b/test/Kestrel.Core.Tests/KestrelServerTests.cs similarity index 100% rename from test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/KestrelServerTests.cs rename to test/Kestrel.Core.Tests/KestrelServerTests.cs diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/KnownStringsTests.cs b/test/Kestrel.Core.Tests/KnownStringsTests.cs similarity index 100% rename from test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/KnownStringsTests.cs rename to test/Kestrel.Core.Tests/KnownStringsTests.cs diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/MessageBodyTests.cs b/test/Kestrel.Core.Tests/MessageBodyTests.cs similarity index 100% rename from test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/MessageBodyTests.cs rename to test/Kestrel.Core.Tests/MessageBodyTests.cs diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/MinDataRateTests.cs b/test/Kestrel.Core.Tests/MinDataRateTests.cs similarity index 100% rename from test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/MinDataRateTests.cs rename to test/Kestrel.Core.Tests/MinDataRateTests.cs diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/OutputProducerTests.cs b/test/Kestrel.Core.Tests/OutputProducerTests.cs similarity index 100% rename from test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/OutputProducerTests.cs rename to test/Kestrel.Core.Tests/OutputProducerTests.cs diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/PathNormalizerTests.cs b/test/Kestrel.Core.Tests/PathNormalizerTests.cs similarity index 100% rename from test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/PathNormalizerTests.cs rename to test/Kestrel.Core.Tests/PathNormalizerTests.cs diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/PipeOptionsTests.cs b/test/Kestrel.Core.Tests/PipeOptionsTests.cs similarity index 100% rename from test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/PipeOptionsTests.cs rename to test/Kestrel.Core.Tests/PipeOptionsTests.cs diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/PipelineExtensionTests.cs b/test/Kestrel.Core.Tests/PipelineExtensionTests.cs similarity index 100% rename from test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/PipelineExtensionTests.cs rename to test/Kestrel.Core.Tests/PipelineExtensionTests.cs diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/ResourceCounterTests.cs b/test/Kestrel.Core.Tests/ResourceCounterTests.cs similarity index 100% rename from test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/ResourceCounterTests.cs rename to test/Kestrel.Core.Tests/ResourceCounterTests.cs diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/ServerAddressTests.cs b/test/Kestrel.Core.Tests/ServerAddressTests.cs similarity index 100% rename from test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/ServerAddressTests.cs rename to test/Kestrel.Core.Tests/ServerAddressTests.cs diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/StreamsTests.cs b/test/Kestrel.Core.Tests/StreamsTests.cs similarity index 100% rename from test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/StreamsTests.cs rename to test/Kestrel.Core.Tests/StreamsTests.cs diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/StringUtilitiesTests.cs b/test/Kestrel.Core.Tests/StringUtilitiesTests.cs similarity index 100% rename from test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/StringUtilitiesTests.cs rename to test/Kestrel.Core.Tests/StringUtilitiesTests.cs diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/TestHelpers/AssertExtensions.cs b/test/Kestrel.Core.Tests/TestHelpers/AssertExtensions.cs similarity index 100% rename from test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/TestHelpers/AssertExtensions.cs rename to test/Kestrel.Core.Tests/TestHelpers/AssertExtensions.cs diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/TestHelpers/MockFrameControl.cs b/test/Kestrel.Core.Tests/TestHelpers/MockFrameControl.cs similarity index 100% rename from test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/TestHelpers/MockFrameControl.cs rename to test/Kestrel.Core.Tests/TestHelpers/MockFrameControl.cs diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/TestInput.cs b/test/Kestrel.Core.Tests/TestInput.cs similarity index 100% rename from test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/TestInput.cs rename to test/Kestrel.Core.Tests/TestInput.cs diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/ThrowingWriteOnlyStreamTests.cs b/test/Kestrel.Core.Tests/ThrowingWriteOnlyStreamTests.cs similarity index 100% rename from test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/ThrowingWriteOnlyStreamTests.cs rename to test/Kestrel.Core.Tests/ThrowingWriteOnlyStreamTests.cs diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/xunit.runner.json b/test/Kestrel.Core.Tests/xunit.runner.json similarity index 100% rename from test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/xunit.runner.json rename to test/Kestrel.Core.Tests/xunit.runner.json diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs b/test/Kestrel.FunctionalTests/AddressRegistrationTests.cs similarity index 100% rename from test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs rename to test/Kestrel.FunctionalTests/AddressRegistrationTests.cs diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/BadHttpRequestTests.cs b/test/Kestrel.FunctionalTests/BadHttpRequestTests.cs similarity index 100% rename from test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/BadHttpRequestTests.cs rename to test/Kestrel.FunctionalTests/BadHttpRequestTests.cs diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ChunkedRequestTests.cs b/test/Kestrel.FunctionalTests/ChunkedRequestTests.cs similarity index 100% rename from test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ChunkedRequestTests.cs rename to test/Kestrel.FunctionalTests/ChunkedRequestTests.cs diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ChunkedResponseTests.cs b/test/Kestrel.FunctionalTests/ChunkedResponseTests.cs similarity index 100% rename from test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ChunkedResponseTests.cs rename to test/Kestrel.FunctionalTests/ChunkedResponseTests.cs diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ConnectionAdapterTests.cs b/test/Kestrel.FunctionalTests/ConnectionAdapterTests.cs similarity index 100% rename from test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ConnectionAdapterTests.cs rename to test/Kestrel.FunctionalTests/ConnectionAdapterTests.cs diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ConnectionLimitTests.cs b/test/Kestrel.FunctionalTests/ConnectionLimitTests.cs similarity index 100% rename from test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ConnectionLimitTests.cs rename to test/Kestrel.FunctionalTests/ConnectionLimitTests.cs diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/DefaultHeaderTests.cs b/test/Kestrel.FunctionalTests/DefaultHeaderTests.cs similarity index 100% rename from test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/DefaultHeaderTests.cs rename to test/Kestrel.FunctionalTests/DefaultHeaderTests.cs diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/EventSourceTests.cs b/test/Kestrel.FunctionalTests/EventSourceTests.cs similarity index 100% rename from test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/EventSourceTests.cs rename to test/Kestrel.FunctionalTests/EventSourceTests.cs diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/FrameConnectionManagerTests.cs b/test/Kestrel.FunctionalTests/FrameConnectionManagerTests.cs similarity index 100% rename from test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/FrameConnectionManagerTests.cs rename to test/Kestrel.FunctionalTests/FrameConnectionManagerTests.cs diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/GeneratedCodeTests.cs b/test/Kestrel.FunctionalTests/GeneratedCodeTests.cs similarity index 88% rename from test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/GeneratedCodeTests.cs rename to test/Kestrel.FunctionalTests/GeneratedCodeTests.cs index 99b8e9d88b..5a6b03781c 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/GeneratedCodeTests.cs +++ b/test/Kestrel.FunctionalTests/GeneratedCodeTests.cs @@ -12,9 +12,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [Fact] public void GeneratedCodeIsUpToDate() { - const string frameHeadersGeneratedPath = "../../../../../src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameHeaders.Generated.cs"; - const string frameGeneratedPath = "../../../../../src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.Generated.cs"; - const string httpUtilitiesGeneratedPath = "../../../../../src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/HttpUtilities.Generated.cs"; + const string frameHeadersGeneratedPath = "../../../../../src/Kestrel.Core/Internal/Http/FrameHeaders.Generated.cs"; + const string frameGeneratedPath = "../../../../../src/Kestrel.Core/Internal/Http/Frame.Generated.cs"; + const string httpUtilitiesGeneratedPath = "../../../../../src/Kestrel.Core/Internal/Infrastructure/HttpUtilities.Generated.cs"; var testFrameHeadersGeneratedPath = Path.GetTempFileName(); var testFrameGeneratedPath = Path.GetTempFileName(); diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/HttpsConnectionAdapterTests.cs b/test/Kestrel.FunctionalTests/HttpsConnectionAdapterTests.cs similarity index 100% rename from test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/HttpsConnectionAdapterTests.cs rename to test/Kestrel.FunctionalTests/HttpsConnectionAdapterTests.cs diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/HttpsTests.cs b/test/Kestrel.FunctionalTests/HttpsTests.cs similarity index 100% rename from test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/HttpsTests.cs rename to test/Kestrel.FunctionalTests/HttpsTests.cs diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/KeepAliveTimeoutTests.cs b/test/Kestrel.FunctionalTests/KeepAliveTimeoutTests.cs similarity index 100% rename from test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/KeepAliveTimeoutTests.cs rename to test/Kestrel.FunctionalTests/KeepAliveTimeoutTests.cs diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests.csproj b/test/Kestrel.FunctionalTests/Kestrel.FunctionalTests.csproj similarity index 86% rename from test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests.csproj rename to test/Kestrel.FunctionalTests/Kestrel.FunctionalTests.csproj index 9265ff3a69..d1e519263f 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests.csproj +++ b/test/Kestrel.FunctionalTests/Kestrel.FunctionalTests.csproj @@ -3,6 +3,8 @@ + Microsoft.AspNetCore.Server.Kestrel.FunctionalTests + Microsoft.AspNetCore.Server.Kestrel.FunctionalTests netcoreapp2.0;net461 netcoreapp2.0 true @@ -25,8 +27,8 @@ - - + + diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ListenHandleTests.cs b/test/Kestrel.FunctionalTests/ListenHandleTests.cs similarity index 100% rename from test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ListenHandleTests.cs rename to test/Kestrel.FunctionalTests/ListenHandleTests.cs diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/LoggingConnectionAdapterTests.cs b/test/Kestrel.FunctionalTests/LoggingConnectionAdapterTests.cs similarity index 100% rename from test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/LoggingConnectionAdapterTests.cs rename to test/Kestrel.FunctionalTests/LoggingConnectionAdapterTests.cs diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/MaxRequestBodySizeTests.cs b/test/Kestrel.FunctionalTests/MaxRequestBodySizeTests.cs similarity index 100% rename from test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/MaxRequestBodySizeTests.cs rename to test/Kestrel.FunctionalTests/MaxRequestBodySizeTests.cs diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/MaxRequestBufferSizeTests.cs b/test/Kestrel.FunctionalTests/MaxRequestBufferSizeTests.cs similarity index 100% rename from test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/MaxRequestBufferSizeTests.cs rename to test/Kestrel.FunctionalTests/MaxRequestBufferSizeTests.cs diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/MaxRequestLineSizeTests.cs b/test/Kestrel.FunctionalTests/MaxRequestLineSizeTests.cs similarity index 100% rename from test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/MaxRequestLineSizeTests.cs rename to test/Kestrel.FunctionalTests/MaxRequestLineSizeTests.cs diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/Properties/AssemblyInfo.cs b/test/Kestrel.FunctionalTests/Properties/AssemblyInfo.cs similarity index 100% rename from test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/Properties/AssemblyInfo.cs rename to test/Kestrel.FunctionalTests/Properties/AssemblyInfo.cs diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestBodyTimeoutTests.cs b/test/Kestrel.FunctionalTests/RequestBodyTimeoutTests.cs similarity index 100% rename from test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestBodyTimeoutTests.cs rename to test/Kestrel.FunctionalTests/RequestBodyTimeoutTests.cs diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestHeaderLimitsTests.cs b/test/Kestrel.FunctionalTests/RequestHeaderLimitsTests.cs similarity index 100% rename from test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestHeaderLimitsTests.cs rename to test/Kestrel.FunctionalTests/RequestHeaderLimitsTests.cs diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestHeadersTimeoutTests.cs b/test/Kestrel.FunctionalTests/RequestHeadersTimeoutTests.cs similarity index 100% rename from test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestHeadersTimeoutTests.cs rename to test/Kestrel.FunctionalTests/RequestHeadersTimeoutTests.cs diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTargetProcessingTests.cs b/test/Kestrel.FunctionalTests/RequestTargetProcessingTests.cs similarity index 100% rename from test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTargetProcessingTests.cs rename to test/Kestrel.FunctionalTests/RequestTargetProcessingTests.cs diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs b/test/Kestrel.FunctionalTests/RequestTests.cs similarity index 100% rename from test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs rename to test/Kestrel.FunctionalTests/RequestTests.cs diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs b/test/Kestrel.FunctionalTests/ResponseTests.cs similarity index 100% rename from test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs rename to test/Kestrel.FunctionalTests/ResponseTests.cs diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/SystemdActivation/Dockerfile b/test/Kestrel.FunctionalTests/SystemdActivation/Dockerfile similarity index 100% rename from test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/SystemdActivation/Dockerfile rename to test/Kestrel.FunctionalTests/SystemdActivation/Dockerfile diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/SystemdActivation/docker-entrypoint.sh b/test/Kestrel.FunctionalTests/SystemdActivation/docker-entrypoint.sh similarity index 100% rename from test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/SystemdActivation/docker-entrypoint.sh rename to test/Kestrel.FunctionalTests/SystemdActivation/docker-entrypoint.sh diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/SystemdActivation/docker.sh b/test/Kestrel.FunctionalTests/SystemdActivation/docker.sh similarity index 100% rename from test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/SystemdActivation/docker.sh rename to test/Kestrel.FunctionalTests/SystemdActivation/docker.sh diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/TestHelpers/IPv6ScopeIdPresentConditionAttribute.cs b/test/Kestrel.FunctionalTests/TestHelpers/IPv6ScopeIdPresentConditionAttribute.cs similarity index 100% rename from test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/TestHelpers/IPv6ScopeIdPresentConditionAttribute.cs rename to test/Kestrel.FunctionalTests/TestHelpers/IPv6ScopeIdPresentConditionAttribute.cs diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/TestHelpers/IPv6SupportedConditionAttribute.cs b/test/Kestrel.FunctionalTests/TestHelpers/IPv6SupportedConditionAttribute.cs similarity index 100% rename from test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/TestHelpers/IPv6SupportedConditionAttribute.cs rename to test/Kestrel.FunctionalTests/TestHelpers/IPv6SupportedConditionAttribute.cs diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/TestHelpers/IWebHostPortExtensions.cs b/test/Kestrel.FunctionalTests/TestHelpers/IWebHostPortExtensions.cs similarity index 100% rename from test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/TestHelpers/IWebHostPortExtensions.cs rename to test/Kestrel.FunctionalTests/TestHelpers/IWebHostPortExtensions.cs diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/TestHelpers/NetworkIsReachableAttribute.cs b/test/Kestrel.FunctionalTests/TestHelpers/NetworkIsReachableAttribute.cs similarity index 100% rename from test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/TestHelpers/NetworkIsReachableAttribute.cs rename to test/Kestrel.FunctionalTests/TestHelpers/NetworkIsReachableAttribute.cs diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/TestHelpers/TestServer.cs b/test/Kestrel.FunctionalTests/TestHelpers/TestServer.cs similarity index 100% rename from test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/TestHelpers/TestServer.cs rename to test/Kestrel.FunctionalTests/TestHelpers/TestServer.cs diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ThreadCountTests.cs b/test/Kestrel.FunctionalTests/ThreadCountTests.cs similarity index 100% rename from test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ThreadCountTests.cs rename to test/Kestrel.FunctionalTests/ThreadCountTests.cs diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/UpgradeTests.cs b/test/Kestrel.FunctionalTests/UpgradeTests.cs similarity index 100% rename from test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/UpgradeTests.cs rename to test/Kestrel.FunctionalTests/UpgradeTests.cs diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/xunit.runner.json b/test/Kestrel.FunctionalTests/xunit.runner.json similarity index 100% rename from test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/xunit.runner.json rename to test/Kestrel.FunctionalTests/xunit.runner.json diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/DotSegmentRemovalBenchmark.cs b/test/Kestrel.Performance/DotSegmentRemovalBenchmark.cs similarity index 100% rename from test/Microsoft.AspNetCore.Server.Kestrel.Performance/DotSegmentRemovalBenchmark.cs rename to test/Kestrel.Performance/DotSegmentRemovalBenchmark.cs diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/ErrorUtilities.cs b/test/Kestrel.Performance/ErrorUtilities.cs similarity index 100% rename from test/Microsoft.AspNetCore.Server.Kestrel.Performance/ErrorUtilities.cs rename to test/Kestrel.Performance/ErrorUtilities.cs diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameFeatureCollection.cs b/test/Kestrel.Performance/FrameFeatureCollection.cs similarity index 100% rename from test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameFeatureCollection.cs rename to test/Kestrel.Performance/FrameFeatureCollection.cs diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameParsingOverheadBenchmark.cs b/test/Kestrel.Performance/FrameParsingOverheadBenchmark.cs similarity index 100% rename from test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameParsingOverheadBenchmark.cs rename to test/Kestrel.Performance/FrameParsingOverheadBenchmark.cs diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameWritingBenchmark.cs b/test/Kestrel.Performance/FrameWritingBenchmark.cs similarity index 100% rename from test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameWritingBenchmark.cs rename to test/Kestrel.Performance/FrameWritingBenchmark.cs diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Microsoft.AspNetCore.Server.Kestrel.Performance.csproj b/test/Kestrel.Performance/Kestrel.Performance.csproj similarity index 77% rename from test/Microsoft.AspNetCore.Server.Kestrel.Performance/Microsoft.AspNetCore.Server.Kestrel.Performance.csproj rename to test/Kestrel.Performance/Kestrel.Performance.csproj index 281f7d50dc..2508e6c7f2 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Microsoft.AspNetCore.Server.Kestrel.Performance.csproj +++ b/test/Kestrel.Performance/Kestrel.Performance.csproj @@ -3,6 +3,8 @@ + Microsoft.AspNetCore.Server.Kestrel.Performance + Microsoft.AspNetCore.Server.Kestrel.Performance netcoreapp2.0;net461 netcoreapp2.0 Exe @@ -18,7 +20,7 @@ - + diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/KestrelHttpParserBenchmark.cs b/test/Kestrel.Performance/KestrelHttpParserBenchmark.cs similarity index 100% rename from test/Microsoft.AspNetCore.Server.Kestrel.Performance/KestrelHttpParserBenchmark.cs rename to test/Kestrel.Performance/KestrelHttpParserBenchmark.cs diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/KnownStringsBenchmark.cs b/test/Kestrel.Performance/KnownStringsBenchmark.cs similarity index 100% rename from test/Microsoft.AspNetCore.Server.Kestrel.Performance/KnownStringsBenchmark.cs rename to test/Kestrel.Performance/KnownStringsBenchmark.cs diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Mocks/MockConnectionInformation.cs b/test/Kestrel.Performance/Mocks/MockConnectionInformation.cs similarity index 100% rename from test/Microsoft.AspNetCore.Server.Kestrel.Performance/Mocks/MockConnectionInformation.cs rename to test/Kestrel.Performance/Mocks/MockConnectionInformation.cs diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Mocks/MockTimeoutControl.cs b/test/Kestrel.Performance/Mocks/MockTimeoutControl.cs similarity index 100% rename from test/Microsoft.AspNetCore.Server.Kestrel.Performance/Mocks/MockTimeoutControl.cs rename to test/Kestrel.Performance/Mocks/MockTimeoutControl.cs diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Mocks/MockTrace.cs b/test/Kestrel.Performance/Mocks/MockTrace.cs similarity index 100% rename from test/Microsoft.AspNetCore.Server.Kestrel.Performance/Mocks/MockTrace.cs rename to test/Kestrel.Performance/Mocks/MockTrace.cs diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Mocks/NullParser.cs b/test/Kestrel.Performance/Mocks/NullParser.cs similarity index 100% rename from test/Microsoft.AspNetCore.Server.Kestrel.Performance/Mocks/NullParser.cs rename to test/Kestrel.Performance/Mocks/NullParser.cs diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/PipeThroughputBenchmark.cs b/test/Kestrel.Performance/PipeThroughputBenchmark.cs similarity index 100% rename from test/Microsoft.AspNetCore.Server.Kestrel.Performance/PipeThroughputBenchmark.cs rename to test/Kestrel.Performance/PipeThroughputBenchmark.cs diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Program.cs b/test/Kestrel.Performance/Program.cs similarity index 100% rename from test/Microsoft.AspNetCore.Server.Kestrel.Performance/Program.cs rename to test/Kestrel.Performance/Program.cs diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Readme.md b/test/Kestrel.Performance/Readme.md similarity index 100% rename from test/Microsoft.AspNetCore.Server.Kestrel.Performance/Readme.md rename to test/Kestrel.Performance/Readme.md diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsingBenchmark.cs b/test/Kestrel.Performance/RequestParsingBenchmark.cs similarity index 100% rename from test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsingBenchmark.cs rename to test/Kestrel.Performance/RequestParsingBenchmark.cs diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsingData.cs b/test/Kestrel.Performance/RequestParsingData.cs similarity index 100% rename from test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsingData.cs rename to test/Kestrel.Performance/RequestParsingData.cs diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/ResponseHeaderCollectionBenchmark.cs b/test/Kestrel.Performance/ResponseHeaderCollectionBenchmark.cs similarity index 100% rename from test/Microsoft.AspNetCore.Server.Kestrel.Performance/ResponseHeaderCollectionBenchmark.cs rename to test/Kestrel.Performance/ResponseHeaderCollectionBenchmark.cs diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/ResponseHeadersWritingBenchmark.cs b/test/Kestrel.Performance/ResponseHeadersWritingBenchmark.cs similarity index 100% rename from test/Microsoft.AspNetCore.Server.Kestrel.Performance/ResponseHeadersWritingBenchmark.cs rename to test/Kestrel.Performance/ResponseHeadersWritingBenchmark.cs diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/StringUtilitiesBenchmark.cs b/test/Kestrel.Performance/StringUtilitiesBenchmark.cs similarity index 100% rename from test/Microsoft.AspNetCore.Server.Kestrel.Performance/StringUtilitiesBenchmark.cs rename to test/Kestrel.Performance/StringUtilitiesBenchmark.cs diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/configs/CoreConfig.cs b/test/Kestrel.Performance/configs/CoreConfig.cs similarity index 100% rename from test/Microsoft.AspNetCore.Server.Kestrel.Performance/configs/CoreConfig.cs rename to test/Kestrel.Performance/configs/CoreConfig.cs diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Tests/Microsoft.AspNetCore.Server.Kestrel.Tests.csproj b/test/Kestrel.Tests/Kestrel.Tests.csproj similarity index 76% rename from test/Microsoft.AspNetCore.Server.Kestrel.Tests/Microsoft.AspNetCore.Server.Kestrel.Tests.csproj rename to test/Kestrel.Tests/Kestrel.Tests.csproj index dfe42a4b6c..b05d9659a9 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Tests/Microsoft.AspNetCore.Server.Kestrel.Tests.csproj +++ b/test/Kestrel.Tests/Kestrel.Tests.csproj @@ -3,6 +3,8 @@ + Microsoft.AspNetCore.Server.Kestrel.Tests + Microsoft.AspNetCore.Server.Kestrel.Tests netcoreapp2.0;net461 netcoreapp2.0 @@ -12,7 +14,7 @@ - + diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Tests/WebHostBuilderKestrelExtensionsTests.cs b/test/Kestrel.Tests/WebHostBuilderKestrelExtensionsTests.cs similarity index 100% rename from test/Microsoft.AspNetCore.Server.Kestrel.Tests/WebHostBuilderKestrelExtensionsTests.cs rename to test/Kestrel.Tests/WebHostBuilderKestrelExtensionsTests.cs diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Tests/xunit.runner.json b/test/Kestrel.Tests/xunit.runner.json similarity index 100% rename from test/Microsoft.AspNetCore.Server.Kestrel.Tests/xunit.runner.json rename to test/Kestrel.Tests/xunit.runner.json diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests.csproj b/test/Kestrel.Transport.Libuv.Tests/Kestrel.Transport.Libuv.Tests.csproj similarity index 79% rename from test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests.csproj rename to test/Kestrel.Transport.Libuv.Tests/Kestrel.Transport.Libuv.Tests.csproj index a4fa5d8d2b..575504ff6f 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests.csproj +++ b/test/Kestrel.Transport.Libuv.Tests/Kestrel.Transport.Libuv.Tests.csproj @@ -3,6 +3,8 @@ + Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests + Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests netcoreapp2.0;net461 netcoreapp2.0 true @@ -21,8 +23,8 @@ - - + + diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/LibuvConnectionTests.cs b/test/Kestrel.Transport.Libuv.Tests/LibuvConnectionTests.cs similarity index 100% rename from test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/LibuvConnectionTests.cs rename to test/Kestrel.Transport.Libuv.Tests/LibuvConnectionTests.cs diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/LibuvOutputConsumerTests.cs b/test/Kestrel.Transport.Libuv.Tests/LibuvOutputConsumerTests.cs similarity index 100% rename from test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/LibuvOutputConsumerTests.cs rename to test/Kestrel.Transport.Libuv.Tests/LibuvOutputConsumerTests.cs diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/LibuvTransportFactoryTests.cs b/test/Kestrel.Transport.Libuv.Tests/LibuvTransportFactoryTests.cs similarity index 100% rename from test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/LibuvTransportFactoryTests.cs rename to test/Kestrel.Transport.Libuv.Tests/LibuvTransportFactoryTests.cs diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/LibuvTransportOptionsTests.cs b/test/Kestrel.Transport.Libuv.Tests/LibuvTransportOptionsTests.cs similarity index 100% rename from test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/LibuvTransportOptionsTests.cs rename to test/Kestrel.Transport.Libuv.Tests/LibuvTransportOptionsTests.cs diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/LibuvTransportTests.cs b/test/Kestrel.Transport.Libuv.Tests/LibuvTransportTests.cs similarity index 100% rename from test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/LibuvTransportTests.cs rename to test/Kestrel.Transport.Libuv.Tests/LibuvTransportTests.cs diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/ListenerPrimaryTests.cs b/test/Kestrel.Transport.Libuv.Tests/ListenerPrimaryTests.cs similarity index 100% rename from test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/ListenerPrimaryTests.cs rename to test/Kestrel.Transport.Libuv.Tests/ListenerPrimaryTests.cs diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/MultipleLoopTests.cs b/test/Kestrel.Transport.Libuv.Tests/MultipleLoopTests.cs similarity index 100% rename from test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/MultipleLoopTests.cs rename to test/Kestrel.Transport.Libuv.Tests/MultipleLoopTests.cs diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/NetworkingTests.cs b/test/Kestrel.Transport.Libuv.Tests/NetworkingTests.cs similarity index 100% rename from test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/NetworkingTests.cs rename to test/Kestrel.Transport.Libuv.Tests/NetworkingTests.cs diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/TestHelpers/MockConnectionHandler.cs b/test/Kestrel.Transport.Libuv.Tests/TestHelpers/MockConnectionHandler.cs similarity index 100% rename from test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/TestHelpers/MockConnectionHandler.cs rename to test/Kestrel.Transport.Libuv.Tests/TestHelpers/MockConnectionHandler.cs diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/TestHelpers/MockLibuv.cs b/test/Kestrel.Transport.Libuv.Tests/TestHelpers/MockLibuv.cs similarity index 100% rename from test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/TestHelpers/MockLibuv.cs rename to test/Kestrel.Transport.Libuv.Tests/TestHelpers/MockLibuv.cs diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/TestHelpers/MockSocket.cs b/test/Kestrel.Transport.Libuv.Tests/TestHelpers/MockSocket.cs similarity index 100% rename from test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/TestHelpers/MockSocket.cs rename to test/Kestrel.Transport.Libuv.Tests/TestHelpers/MockSocket.cs diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/TestHelpers/TestConstants.cs b/test/Kestrel.Transport.Libuv.Tests/TestHelpers/TestConstants.cs similarity index 100% rename from test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/TestHelpers/TestConstants.cs rename to test/Kestrel.Transport.Libuv.Tests/TestHelpers/TestConstants.cs diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/TestHelpers/TestLibuvTransportContext.cs b/test/Kestrel.Transport.Libuv.Tests/TestHelpers/TestLibuvTransportContext.cs similarity index 100% rename from test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/TestHelpers/TestLibuvTransportContext.cs rename to test/Kestrel.Transport.Libuv.Tests/TestHelpers/TestLibuvTransportContext.cs diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/UvStreamHandleTests.cs b/test/Kestrel.Transport.Libuv.Tests/UvStreamHandleTests.cs similarity index 100% rename from test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/UvStreamHandleTests.cs rename to test/Kestrel.Transport.Libuv.Tests/UvStreamHandleTests.cs diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/UvTimerHandleTests.cs b/test/Kestrel.Transport.Libuv.Tests/UvTimerHandleTests.cs similarity index 100% rename from test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/UvTimerHandleTests.cs rename to test/Kestrel.Transport.Libuv.Tests/UvTimerHandleTests.cs diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/xunit.runner.json b/test/Kestrel.Transport.Libuv.Tests/xunit.runner.json similarity index 100% rename from test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/xunit.runner.json rename to test/Kestrel.Transport.Libuv.Tests/xunit.runner.json diff --git a/tools/CodeGenerator/CodeGenerator.csproj b/tools/CodeGenerator/CodeGenerator.csproj index 1569f84cbd..143a966654 100644 --- a/tools/CodeGenerator/CodeGenerator.csproj +++ b/tools/CodeGenerator/CodeGenerator.csproj @@ -10,7 +10,7 @@ - + @@ -19,7 +19,7 @@ - $(MSBuildThisFileDirectory)..\..\src\Microsoft.AspNetCore.Server.Kestrel.Core + $(MSBuildThisFileDirectory)..\..\src\Kestrel.Core Internal\Http\FrameHeaders.Generated.cs Internal\Http\Frame.Generated.cs Internal\Infrastructure\HttpUtilities.Generated.cs diff --git a/tools/CodeGenerator/FrameFeatureCollection.cs b/tools/CodeGenerator/FrameFeatureCollection.cs index 5fd8d0a8f5..d05139d919 100644 --- a/tools/CodeGenerator/FrameFeatureCollection.cs +++ b/tools/CodeGenerator/FrameFeatureCollection.cs @@ -60,7 +60,7 @@ namespace CodeGenerator var allFeatures = alwaysFeatures.Concat(commonFeatures).Concat(sometimesFeatures).Concat(rareFeatures); // NOTE: This list MUST always match the set of feature interfaces implemented by Frame. - // See also: src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.FeatureCollection.cs + // See also: src/Kestrel/Http/Frame.FeatureCollection.cs var implementedFeatures = new[] { typeof(IHttpRequestFeature), From cfce9dce6c48118bbebf07b734a297f134e2d19f Mon Sep 17 00:00:00 2001 From: John Luo Date: Wed, 2 Aug 2017 12:44:46 -0700 Subject: [PATCH 1366/1662] Update __get_remote_file logic --- build.sh | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/build.sh b/build.sh index 5568c6182a..8eace4c20d 100755 --- a/build.sh +++ b/build.sh @@ -99,17 +99,16 @@ __get_remote_file() { return 0 fi - failed=false + local succeeded=false if __machine_has wget; then - wget --tries 10 --quiet -O "$local_path" "$remote_path" || failed=true + wget --tries 10 --quiet -O "$local_path" "$remote_path" && succeeded=true fi - if [ "$failed" = true ] && __machine_has curl; then - failed=false - curl --retry 10 -sSL -f --create-dirs -o "$local_path" "$remote_path" || failed=true + if [ "$succeeded" = false ] && __machine_has curl; then + curl --retry 10 -sSL -f --create-dirs -o "$local_path" "$remote_path" && succeeded=true fi - if [ "$failed" = true ]; then + if [ "$succeeded" = false ]; then __error "Download failed: $remote_path" 1>&2 return 1 fi From 06d596102adc09c6a2a7b86357c82b35d7722e39 Mon Sep 17 00:00:00 2001 From: John Luo Date: Wed, 2 Aug 2017 14:32:33 -0700 Subject: [PATCH 1367/1662] Ensure fallback to curl after failed wget --- build.sh | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/build.sh b/build.sh index 8eace4c20d..11cdbe5504 100755 --- a/build.sh +++ b/build.sh @@ -99,16 +99,19 @@ __get_remote_file() { return 0 fi - local succeeded=false + local failed=false if __machine_has wget; then - wget --tries 10 --quiet -O "$local_path" "$remote_path" && succeeded=true + wget --tries 10 --quiet -O "$local_path" "$remote_path" || failed=true + else + failed=true fi - if [ "$succeeded" = false ] && __machine_has curl; then - curl --retry 10 -sSL -f --create-dirs -o "$local_path" "$remote_path" && succeeded=true + if [ "$failed" = true ] && __machine_has curl; then + failed=false + curl --retry 10 -sSL -f --create-dirs -o "$local_path" "$remote_path" || failed=true fi - if [ "$succeeded" = false ]; then + if [ "$failed" = true ]; then __error "Download failed: $remote_path" 1>&2 return 1 fi From d68f8165e19934ddb66bf61fcf2c74212de42293 Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Fri, 4 Aug 2017 17:45:07 -0700 Subject: [PATCH 1368/1662] Disable test ConnectionClosedWhenResponseDoesNotSatisfyMinimumDataRate on Linux. --- test/Kestrel.FunctionalTests/ResponseTests.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/Kestrel.FunctionalTests/ResponseTests.cs b/test/Kestrel.FunctionalTests/ResponseTests.cs index 7f26aec3bf..d0a4b3deef 100644 --- a/test/Kestrel.FunctionalTests/ResponseTests.cs +++ b/test/Kestrel.FunctionalTests/ResponseTests.cs @@ -25,6 +25,7 @@ using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Https; using Microsoft.AspNetCore.Server.Kestrel.Https.Internal; using Microsoft.AspNetCore.Testing; +using Microsoft.AspNetCore.Testing.xunit; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Primitives; @@ -2443,7 +2444,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } } - [Fact] + [ConditionalFact] + [OSSkipCondition(OperatingSystems.Linux, SkipReason = "Flaky test (https://github.com/aspnet/KestrelHttpServer/issues/1955)")] public async Task ConnectionClosedWhenResponseDoesNotSatisfyMinimumDataRate() { var chunkSize = 64 * 1024; From 659fa967a1900653f7a82f02624c7c7995a3b786 Mon Sep 17 00:00:00 2001 From: Pavel Krymets Date: Mon, 7 Aug 2017 13:58:19 -0700 Subject: [PATCH 1369/1662] Consume corefxlab packages and private build of C# compiler (#1976) --- NuGet.config | 1 + build/common.props | 2 ++ build/dependencies.props | 2 ++ samples/LargeResponseApp/LargeResponseApp.csproj | 4 ++++ samples/SampleApp/SampleApp.csproj | 1 + src/Kestrel.Core/Adapter/Internal/AdaptedPipeline.cs | 2 +- src/Kestrel.Core/Adapter/Internal/RawStream.cs | 2 +- src/Kestrel.Core/Internal/ConnectionHandler.cs | 3 +-- src/Kestrel.Core/Internal/FrameConnection.cs | 4 +--- src/Kestrel.Core/Internal/FrameConnectionContext.cs | 2 +- src/Kestrel.Core/Internal/Http/ChunkWriter.cs | 2 +- src/Kestrel.Core/Internal/Http/Frame.cs | 5 ++--- src/Kestrel.Core/Internal/Http/FrameAdapter.cs | 1 - src/Kestrel.Core/Internal/Http/FrameContext.cs | 2 +- .../Internal/Http/FrameHeaders.Generated.cs | 2 +- src/Kestrel.Core/Internal/Http/FrameRequestHeaders.cs | 1 - src/Kestrel.Core/Internal/Http/FrameResponseHeaders.cs | 2 +- src/Kestrel.Core/Internal/Http/HttpParser.cs | 3 +-- src/Kestrel.Core/Internal/Http/IHttpHeadersHandler.cs | 1 - src/Kestrel.Core/Internal/Http/IHttpParser.cs | 2 +- .../Internal/Http/IHttpRequestLineHandler.cs | 1 - src/Kestrel.Core/Internal/Http/MessageBody.cs | 3 +-- src/Kestrel.Core/Internal/Http/OutputProducer.cs | 2 +- src/Kestrel.Core/Internal/Http/PathNormalizer.cs | 1 - src/Kestrel.Core/Internal/Http/PipelineExtensions.cs | 6 +----- .../Internal/Infrastructure/HttpUtilities.cs | 1 - .../Internal/Infrastructure/IThreadPool.cs | 2 +- src/Kestrel.Core/Internal/RejectionConnection.cs | 2 +- src/Kestrel.Core/Kestrel.Core.csproj | 4 ++++ .../Internal/IConnectionContext.cs | 3 +-- .../Internal/IConnectionInformation.cs | 2 +- .../Kestrel.Transport.Abstractions.csproj | 10 ++++++---- .../Internal/LibuvConnection.cs | 8 ++++---- .../Internal/LibuvConnectionContext.cs | 3 +-- .../Internal/LibuvOutputConsumer.cs | 2 +- src/Kestrel.Transport.Libuv/Internal/LibuvThread.cs | 2 +- .../Internal/Networking/UvWriteReq.cs | 10 +++++----- src/Kestrel.Transport.Sockets/SocketConnection.cs | 3 +-- .../SocketTransportFactory.cs | 2 +- test/Kestrel.Core.Tests/AsciiDecoding.cs | 1 - test/Kestrel.Core.Tests/FrameConnectionTests.cs | 2 +- test/Kestrel.Core.Tests/FrameResponseHeadersTests.cs | 5 +---- test/Kestrel.Core.Tests/FrameTests.cs | 2 +- test/Kestrel.Core.Tests/HttpParserTests.cs | 5 ++--- test/Kestrel.Core.Tests/HttpUtilitiesTest.cs | 1 - test/Kestrel.Core.Tests/KnownStringsTests.cs | 1 - test/Kestrel.Core.Tests/OutputProducerTests.cs | 2 +- test/Kestrel.Core.Tests/PathNormalizerTests.cs | 1 - test/Kestrel.Core.Tests/PipeOptionsTests.cs | 2 +- test/Kestrel.Core.Tests/PipelineExtensionTests.cs | 4 +--- test/Kestrel.Core.Tests/StreamsTests.cs | 3 --- .../Kestrel.Core.Tests/TestHelpers/AssertExtensions.cs | 1 - test/Kestrel.Core.Tests/TestInput.cs | 2 +- .../SystemdActivation/docker.sh | 7 ++++--- test/Kestrel.Performance/FrameFeatureCollection.cs | 2 +- .../FrameParsingOverheadBenchmark.cs | 2 +- test/Kestrel.Performance/FrameWritingBenchmark.cs | 2 +- test/Kestrel.Performance/KestrelHttpParserBenchmark.cs | 3 +-- test/Kestrel.Performance/KnownStringsBenchmark.cs | 1 - .../Mocks/MockConnectionInformation.cs | 3 +-- test/Kestrel.Performance/Mocks/NullParser.cs | 3 +-- test/Kestrel.Performance/PipeThroughputBenchmark.cs | 2 +- test/Kestrel.Performance/RequestParsingBenchmark.cs | 2 +- .../ResponseHeaderCollectionBenchmark.cs | 2 +- .../ResponseHeadersWritingBenchmark.cs | 3 +-- .../LibuvConnectionTests.cs | 2 +- .../LibuvOutputConsumerTests.cs | 2 +- .../Kestrel.Transport.Libuv.Tests/MultipleLoopTests.cs | 2 +- test/Kestrel.Transport.Libuv.Tests/NetworkingTests.cs | 2 +- .../TestHelpers/MockConnectionHandler.cs | 4 +--- test/shared/MockConnectionInformation.cs | 2 +- tools/CodeGenerator/KnownHeaders.cs | 2 +- 72 files changed, 84 insertions(+), 107 deletions(-) diff --git a/NuGet.config b/NuGet.config index 4e8a1f6de1..29b1318efd 100644 --- a/NuGet.config +++ b/NuGet.config @@ -5,5 +5,6 @@ + diff --git a/build/common.props b/build/common.props index 7c10a3ca71..593929425b 100644 --- a/build/common.props +++ b/build/common.props @@ -11,10 +11,12 @@ true $(VersionSuffix)-$(BuildNumber) true + 7.2 + diff --git a/build/dependencies.props b/build/dependencies.props index 5f059feb6a..73c5dee642 100644 --- a/build/dependencies.props +++ b/build/dependencies.props @@ -2,12 +2,14 @@ 2.1.0-* 4.4.0-* + 0.1.0-* 2.1.1-* 1.10.0 10.0.1 4.7.49 2.0.0-* 2.0.0-* + 2.6.0-rdonly-ref-61915-01 15.3.0-* 2.3.0-beta2-* diff --git a/samples/LargeResponseApp/LargeResponseApp.csproj b/samples/LargeResponseApp/LargeResponseApp.csproj index a53054ca27..d147ace444 100644 --- a/samples/LargeResponseApp/LargeResponseApp.csproj +++ b/samples/LargeResponseApp/LargeResponseApp.csproj @@ -11,4 +11,8 @@ + + + + diff --git a/samples/SampleApp/SampleApp.csproj b/samples/SampleApp/SampleApp.csproj index d08c315d06..9d017fa070 100644 --- a/samples/SampleApp/SampleApp.csproj +++ b/samples/SampleApp/SampleApp.csproj @@ -18,6 +18,7 @@ + diff --git a/src/Kestrel.Core/Adapter/Internal/AdaptedPipeline.cs b/src/Kestrel.Core/Adapter/Internal/AdaptedPipeline.cs index cf2778603d..8f6db82a0d 100644 --- a/src/Kestrel.Core/Adapter/Internal/AdaptedPipeline.cs +++ b/src/Kestrel.Core/Adapter/Internal/AdaptedPipeline.cs @@ -6,7 +6,7 @@ using System.IO; using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; -using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; +using System.IO.Pipelines; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal { diff --git a/src/Kestrel.Core/Adapter/Internal/RawStream.cs b/src/Kestrel.Core/Adapter/Internal/RawStream.cs index 94c318a8e3..a2bd9a0078 100644 --- a/src/Kestrel.Core/Adapter/Internal/RawStream.cs +++ b/src/Kestrel.Core/Adapter/Internal/RawStream.cs @@ -2,10 +2,10 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.IO.Pipelines; using System.IO; using System.Threading; using System.Threading.Tasks; -using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal { diff --git a/src/Kestrel.Core/Internal/ConnectionHandler.cs b/src/Kestrel.Core/Internal/ConnectionHandler.cs index aee910fd25..1d46a91f64 100644 --- a/src/Kestrel.Core/Internal/ConnectionHandler.cs +++ b/src/Kestrel.Core/Internal/ConnectionHandler.cs @@ -1,11 +1,10 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System.IO.Pipelines; using System.Threading; using Microsoft.AspNetCore.Hosting.Server; -using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; -using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal diff --git a/src/Kestrel.Core/Internal/FrameConnection.cs b/src/Kestrel.Core/Internal/FrameConnection.cs index 0c033b2b9f..ef3c6e15b4 100644 --- a/src/Kestrel.Core/Internal/FrameConnection.cs +++ b/src/Kestrel.Core/Internal/FrameConnection.cs @@ -2,11 +2,10 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.Collections; using System.Collections.Generic; using System.Diagnostics; -using System.Globalization; using System.IO; +using System.IO.Pipelines; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Hosting.Server; @@ -14,7 +13,6 @@ using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; -using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; using Microsoft.Extensions.Logging; diff --git a/src/Kestrel.Core/Internal/FrameConnectionContext.cs b/src/Kestrel.Core/Internal/FrameConnectionContext.cs index 9f01593810..963d353021 100644 --- a/src/Kestrel.Core/Internal/FrameConnectionContext.cs +++ b/src/Kestrel.Core/Internal/FrameConnectionContext.cs @@ -2,8 +2,8 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Collections.Generic; +using System.IO.Pipelines; using Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal; -using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal diff --git a/src/Kestrel.Core/Internal/Http/ChunkWriter.cs b/src/Kestrel.Core/Internal/Http/ChunkWriter.cs index bf34855007..a394fb414e 100644 --- a/src/Kestrel.Core/Internal/Http/ChunkWriter.cs +++ b/src/Kestrel.Core/Internal/Http/ChunkWriter.cs @@ -2,8 +2,8 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.IO.Pipelines; using System.Text; -using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { diff --git a/src/Kestrel.Core/Internal/Http/Frame.cs b/src/Kestrel.Core/Internal/Http/Frame.cs index e6b1187438..8c6f648be3 100644 --- a/src/Kestrel.Core/Internal/Http/Frame.cs +++ b/src/Kestrel.Core/Internal/Http/Frame.cs @@ -5,18 +5,17 @@ using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; +using System.IO.Pipelines; using System.Linq; using System.Net; using System.Runtime.CompilerServices; using System.Text; +using System.Text.Encodings.Web.Utf8; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; -using Microsoft.AspNetCore.Server.Kestrel.Internal.System; -using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; -using Microsoft.AspNetCore.Server.Kestrel.Internal.System.Text.Encodings.Web.Utf8; using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Primitives; diff --git a/src/Kestrel.Core/Internal/Http/FrameAdapter.cs b/src/Kestrel.Core/Internal/Http/FrameAdapter.cs index 1418fb8b44..d0a30c0640 100644 --- a/src/Kestrel.Core/Internal/Http/FrameAdapter.cs +++ b/src/Kestrel.Core/Internal/Http/FrameAdapter.cs @@ -2,7 +2,6 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using Microsoft.AspNetCore.Server.Kestrel.Internal.System; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { diff --git a/src/Kestrel.Core/Internal/Http/FrameContext.cs b/src/Kestrel.Core/Internal/Http/FrameContext.cs index 2916f8c863..ac5d4de636 100644 --- a/src/Kestrel.Core/Internal/Http/FrameContext.cs +++ b/src/Kestrel.Core/Internal/Http/FrameContext.cs @@ -1,8 +1,8 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System.IO.Pipelines; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; -using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http diff --git a/src/Kestrel.Core/Internal/Http/FrameHeaders.Generated.cs b/src/Kestrel.Core/Internal/Http/FrameHeaders.Generated.cs index 2841efcc87..e4a0ea6d38 100644 --- a/src/Kestrel.Core/Internal/Http/FrameHeaders.Generated.cs +++ b/src/Kestrel.Core/Internal/Http/FrameHeaders.Generated.cs @@ -4,7 +4,7 @@ using System; using System.Collections.Generic; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; -using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; +using System.IO.Pipelines; using Microsoft.Extensions.Primitives; using Microsoft.Net.Http.Headers; diff --git a/src/Kestrel.Core/Internal/Http/FrameRequestHeaders.cs b/src/Kestrel.Core/Internal/Http/FrameRequestHeaders.cs index d1bfc945e3..241a086ea8 100644 --- a/src/Kestrel.Core/Internal/Http/FrameRequestHeaders.cs +++ b/src/Kestrel.Core/Internal/Http/FrameRequestHeaders.cs @@ -6,7 +6,6 @@ using System.Collections; using System.Collections.Generic; using System.Runtime.CompilerServices; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; -using Microsoft.AspNetCore.Server.Kestrel.Internal.System; using Microsoft.Extensions.Primitives; using Microsoft.Net.Http.Headers; diff --git a/src/Kestrel.Core/Internal/Http/FrameResponseHeaders.cs b/src/Kestrel.Core/Internal/Http/FrameResponseHeaders.cs index 6409f372db..e7dedeb7dd 100644 --- a/src/Kestrel.Core/Internal/Http/FrameResponseHeaders.cs +++ b/src/Kestrel.Core/Internal/Http/FrameResponseHeaders.cs @@ -2,10 +2,10 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.IO.Pipelines; using System.Collections; using System.Collections.Generic; using System.Runtime.CompilerServices; -using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; using Microsoft.Extensions.Primitives; using Microsoft.Net.Http.Headers; diff --git a/src/Kestrel.Core/Internal/Http/HttpParser.cs b/src/Kestrel.Core/Internal/Http/HttpParser.cs index 3445dc2098..49d3326ec4 100644 --- a/src/Kestrel.Core/Internal/Http/HttpParser.cs +++ b/src/Kestrel.Core/Internal/Http/HttpParser.cs @@ -2,10 +2,9 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.IO.Pipelines; using System.Runtime.CompilerServices; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; -using Microsoft.AspNetCore.Server.Kestrel.Internal.System; -using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { diff --git a/src/Kestrel.Core/Internal/Http/IHttpHeadersHandler.cs b/src/Kestrel.Core/Internal/Http/IHttpHeadersHandler.cs index 2cf4789c22..9a322f0da9 100644 --- a/src/Kestrel.Core/Internal/Http/IHttpHeadersHandler.cs +++ b/src/Kestrel.Core/Internal/Http/IHttpHeadersHandler.cs @@ -2,7 +2,6 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using Microsoft.AspNetCore.Server.Kestrel.Internal.System; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { diff --git a/src/Kestrel.Core/Internal/Http/IHttpParser.cs b/src/Kestrel.Core/Internal/Http/IHttpParser.cs index 54cdf8e92e..a0a477d0f0 100644 --- a/src/Kestrel.Core/Internal/Http/IHttpParser.cs +++ b/src/Kestrel.Core/Internal/Http/IHttpParser.cs @@ -1,7 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; +using System.IO.Pipelines; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { diff --git a/src/Kestrel.Core/Internal/Http/IHttpRequestLineHandler.cs b/src/Kestrel.Core/Internal/Http/IHttpRequestLineHandler.cs index 4cc1fe7478..ac91138512 100644 --- a/src/Kestrel.Core/Internal/Http/IHttpRequestLineHandler.cs +++ b/src/Kestrel.Core/Internal/Http/IHttpRequestLineHandler.cs @@ -2,7 +2,6 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using Microsoft.AspNetCore.Server.Kestrel.Internal.System; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { diff --git a/src/Kestrel.Core/Internal/Http/MessageBody.cs b/src/Kestrel.Core/Internal/Http/MessageBody.cs index 3ce0cd76ea..60e780375e 100644 --- a/src/Kestrel.Core/Internal/Http/MessageBody.cs +++ b/src/Kestrel.Core/Internal/Http/MessageBody.cs @@ -3,12 +3,11 @@ using System; using System.IO; +using System.IO.Pipelines; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; -using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; -using Microsoft.Extensions.Logging; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { diff --git a/src/Kestrel.Core/Internal/Http/OutputProducer.cs b/src/Kestrel.Core/Internal/Http/OutputProducer.cs index 51ed5c1f67..f84571053d 100644 --- a/src/Kestrel.Core/Internal/Http/OutputProducer.cs +++ b/src/Kestrel.Core/Internal/Http/OutputProducer.cs @@ -2,10 +2,10 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.IO.Pipelines; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; -using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { diff --git a/src/Kestrel.Core/Internal/Http/PathNormalizer.cs b/src/Kestrel.Core/Internal/Http/PathNormalizer.cs index 7372fcb71a..de076e1849 100644 --- a/src/Kestrel.Core/Internal/Http/PathNormalizer.cs +++ b/src/Kestrel.Core/Internal/Http/PathNormalizer.cs @@ -3,7 +3,6 @@ using System; using System.Diagnostics; -using Microsoft.AspNetCore.Server.Kestrel.Internal.System; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { diff --git a/src/Kestrel.Core/Internal/Http/PipelineExtensions.cs b/src/Kestrel.Core/Internal/Http/PipelineExtensions.cs index cdc6579650..0f53b2783a 100644 --- a/src/Kestrel.Core/Internal/Http/PipelineExtensions.cs +++ b/src/Kestrel.Core/Internal/Http/PipelineExtensions.cs @@ -2,12 +2,8 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.Buffers; +using System.IO.Pipelines; using System.Runtime.CompilerServices; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Server.Kestrel.Internal.System; -using Microsoft.AspNetCore.Server.Kestrel.Internal.System.Buffers; -using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { diff --git a/src/Kestrel.Core/Internal/Infrastructure/HttpUtilities.cs b/src/Kestrel.Core/Internal/Infrastructure/HttpUtilities.cs index 0acf137849..8d7e5518c5 100644 --- a/src/Kestrel.Core/Internal/Infrastructure/HttpUtilities.cs +++ b/src/Kestrel.Core/Internal/Infrastructure/HttpUtilities.cs @@ -6,7 +6,6 @@ using System.Diagnostics; using System.Runtime.CompilerServices; using System.Text; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; -using Microsoft.AspNetCore.Server.Kestrel.Internal.System; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure { diff --git a/src/Kestrel.Core/Internal/Infrastructure/IThreadPool.cs b/src/Kestrel.Core/Internal/Infrastructure/IThreadPool.cs index 92fa225bc8..c78a4db61d 100644 --- a/src/Kestrel.Core/Internal/Infrastructure/IThreadPool.cs +++ b/src/Kestrel.Core/Internal/Infrastructure/IThreadPool.cs @@ -2,8 +2,8 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.IO.Pipelines; using System.Threading; -using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure { diff --git a/src/Kestrel.Core/Internal/RejectionConnection.cs b/src/Kestrel.Core/Internal/RejectionConnection.cs index cd081b00e7..b14985c499 100644 --- a/src/Kestrel.Core/Internal/RejectionConnection.cs +++ b/src/Kestrel.Core/Internal/RejectionConnection.cs @@ -2,8 +2,8 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.IO.Pipelines; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; -using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal diff --git a/src/Kestrel.Core/Kestrel.Core.csproj b/src/Kestrel.Core/Kestrel.Core.csproj index 46181aa528..14304428dc 100644 --- a/src/Kestrel.Core/Kestrel.Core.csproj +++ b/src/Kestrel.Core/Kestrel.Core.csproj @@ -23,6 +23,10 @@ + + + + diff --git a/src/Kestrel.Transport.Abstractions/Internal/IConnectionContext.cs b/src/Kestrel.Transport.Abstractions/Internal/IConnectionContext.cs index 3ac42175ba..864037e68d 100644 --- a/src/Kestrel.Transport.Abstractions/Internal/IConnectionContext.cs +++ b/src/Kestrel.Transport.Abstractions/Internal/IConnectionContext.cs @@ -2,8 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; +using System.IO.Pipelines; namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal { diff --git a/src/Kestrel.Transport.Abstractions/Internal/IConnectionInformation.cs b/src/Kestrel.Transport.Abstractions/Internal/IConnectionInformation.cs index fb5d7a4d5c..4004824002 100644 --- a/src/Kestrel.Transport.Abstractions/Internal/IConnectionInformation.cs +++ b/src/Kestrel.Transport.Abstractions/Internal/IConnectionInformation.cs @@ -1,8 +1,8 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System.IO.Pipelines; using System.Net; -using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal { diff --git a/src/Kestrel.Transport.Abstractions/Kestrel.Transport.Abstractions.csproj b/src/Kestrel.Transport.Abstractions/Kestrel.Transport.Abstractions.csproj index 0051d3dabd..64b219c6c4 100644 --- a/src/Kestrel.Transport.Abstractions/Kestrel.Transport.Abstractions.csproj +++ b/src/Kestrel.Transport.Abstractions/Kestrel.Transport.Abstractions.csproj @@ -13,16 +13,18 @@ false true false - $(DefineConstants);KESTREL_BY_SOURCE - $(DefineConstants);SYSTEM_MEMORY - - + + + + + + diff --git a/src/Kestrel.Transport.Libuv/Internal/LibuvConnection.cs b/src/Kestrel.Transport.Libuv/Internal/LibuvConnection.cs index 2bac70080e..026c0a7fa3 100644 --- a/src/Kestrel.Transport.Libuv/Internal/LibuvConnection.cs +++ b/src/Kestrel.Transport.Libuv/Internal/LibuvConnection.cs @@ -2,11 +2,11 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Buffers; using System.Diagnostics; using System.IO; using System.Threading.Tasks; -using Microsoft.AspNetCore.Server.Kestrel.Internal.System.Buffers; -using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; +using System.IO.Pipelines; using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking; using Microsoft.Extensions.Logging; @@ -109,7 +109,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal var currentWritableBuffer = Input.Alloc(MinAllocBufferSize); _currentWritableBuffer = currentWritableBuffer; - _bufferHandle = currentWritableBuffer.Buffer.Pin(); + _bufferHandle = currentWritableBuffer.Buffer.Retain(true); return handle.Libuv.buf_init((IntPtr)_bufferHandle.PinnedPointer, currentWritableBuffer.Buffer.Length); } @@ -180,7 +180,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal // Cleanup state from last OnAlloc. This is safe even if OnAlloc wasn't called. _currentWritableBuffer = null; - _bufferHandle.Free(); + _bufferHandle.Dispose(); } private async Task ApplyBackpressureAsync(WritableBufferAwaitable flushTask) diff --git a/src/Kestrel.Transport.Libuv/Internal/LibuvConnectionContext.cs b/src/Kestrel.Transport.Libuv/Internal/LibuvConnectionContext.cs index f377aa6bc3..af43c47d3a 100644 --- a/src/Kestrel.Transport.Libuv/Internal/LibuvConnectionContext.cs +++ b/src/Kestrel.Transport.Libuv/Internal/LibuvConnectionContext.cs @@ -1,9 +1,8 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System; using System.Net; -using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; +using System.IO.Pipelines; using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal diff --git a/src/Kestrel.Transport.Libuv/Internal/LibuvOutputConsumer.cs b/src/Kestrel.Transport.Libuv/Internal/LibuvOutputConsumer.cs index 957ceb9595..92b3febcd7 100644 --- a/src/Kestrel.Transport.Libuv/Internal/LibuvOutputConsumer.cs +++ b/src/Kestrel.Transport.Libuv/Internal/LibuvOutputConsumer.cs @@ -2,8 +2,8 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.IO.Pipelines; using System.Threading.Tasks; -using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking; namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal diff --git a/src/Kestrel.Transport.Libuv/Internal/LibuvThread.cs b/src/Kestrel.Transport.Libuv/Internal/LibuvThread.cs index 299fffef7c..6b27b447ea 100644 --- a/src/Kestrel.Transport.Libuv/Internal/LibuvThread.cs +++ b/src/Kestrel.Transport.Libuv/Internal/LibuvThread.cs @@ -4,11 +4,11 @@ using System; using System.Collections.Generic; using System.Diagnostics; +using System.IO.Pipelines; using System.Runtime.ExceptionServices; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Hosting; -using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking; using Microsoft.Extensions.Logging; diff --git a/src/Kestrel.Transport.Libuv/Internal/Networking/UvWriteReq.cs b/src/Kestrel.Transport.Libuv/Internal/Networking/UvWriteReq.cs index 05b60ca679..857e98ea75 100644 --- a/src/Kestrel.Transport.Libuv/Internal/Networking/UvWriteReq.cs +++ b/src/Kestrel.Transport.Libuv/Internal/Networking/UvWriteReq.cs @@ -2,10 +2,10 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Buffers; using System.Collections.Generic; using System.Runtime.InteropServices; -using Microsoft.AspNetCore.Server.Kestrel.Internal.System.Buffers; -using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; +using System.IO.Pipelines; using Microsoft.Extensions.Logging; namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking @@ -95,7 +95,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networkin if (nBuffers == 1) { var memory = buffer.First; - var memoryHandle = memory.Pin(); + var memoryHandle = memory.Retain(true); _handles.Add(memoryHandle); // Fast path for single buffer @@ -109,7 +109,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networkin foreach (var memory in buffer) { // This won't actually pin the buffer since we're already using pinned memory - var memoryHandle = memory.Pin(); + var memoryHandle = memory.Retain(true); _handles.Add(memoryHandle); // create and pin each segment being written @@ -221,7 +221,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networkin count = handleList.Count; for (var i = 0; i < count; i++) { - handleList[i].Free(); + handleList[i].Dispose(); } handleList.Clear(); } diff --git a/src/Kestrel.Transport.Sockets/SocketConnection.cs b/src/Kestrel.Transport.Sockets/SocketConnection.cs index 5a3f64d17b..0070f7af89 100644 --- a/src/Kestrel.Transport.Sockets/SocketConnection.cs +++ b/src/Kestrel.Transport.Sockets/SocketConnection.cs @@ -8,8 +8,7 @@ using System.IO; using System.Net; using System.Net.Sockets; using System.Threading.Tasks; -using Microsoft.AspNetCore.Server.Kestrel.Internal.System.Buffers; -using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; +using System.IO.Pipelines; using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets diff --git a/src/Kestrel.Transport.Sockets/SocketTransportFactory.cs b/src/Kestrel.Transport.Sockets/SocketTransportFactory.cs index b33ac050a3..849b168342 100644 --- a/src/Kestrel.Transport.Sockets/SocketTransportFactory.cs +++ b/src/Kestrel.Transport.Sockets/SocketTransportFactory.cs @@ -2,7 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; +using System.IO.Pipelines; using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; using Microsoft.Extensions.Options; diff --git a/test/Kestrel.Core.Tests/AsciiDecoding.cs b/test/Kestrel.Core.Tests/AsciiDecoding.cs index 63ed4d4b93..ba61f1bad2 100644 --- a/test/Kestrel.Core.Tests/AsciiDecoding.cs +++ b/test/Kestrel.Core.Tests/AsciiDecoding.cs @@ -4,7 +4,6 @@ using System; using System.Linq; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; -using Microsoft.AspNetCore.Server.Kestrel.Internal.System; using Xunit; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests diff --git a/test/Kestrel.Core.Tests/FrameConnectionTests.cs b/test/Kestrel.Core.Tests/FrameConnectionTests.cs index faa662f899..9cf86bc7dc 100644 --- a/test/Kestrel.Core.Tests/FrameConnectionTests.cs +++ b/test/Kestrel.Core.Tests/FrameConnectionTests.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.IO.Pipelines; using System.Collections.Generic; using System.Linq; using System.Threading; @@ -9,7 +10,6 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; -using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; using Microsoft.AspNetCore.Testing; using Moq; using Xunit; diff --git a/test/Kestrel.Core.Tests/FrameResponseHeadersTests.cs b/test/Kestrel.Core.Tests/FrameResponseHeadersTests.cs index d15fd32099..dabf1d85ee 100644 --- a/test/Kestrel.Core.Tests/FrameResponseHeadersTests.cs +++ b/test/Kestrel.Core.Tests/FrameResponseHeadersTests.cs @@ -2,16 +2,13 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.IO.Pipelines; using System.Collections.Generic; using System.Globalization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; -using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; -using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; -using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; using Microsoft.AspNetCore.Testing; using Microsoft.Extensions.Primitives; -using Moq; using Xunit; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests diff --git a/test/Kestrel.Core.Tests/FrameTests.cs b/test/Kestrel.Core.Tests/FrameTests.cs index 9531abb48e..64274972b8 100644 --- a/test/Kestrel.Core.Tests/FrameTests.cs +++ b/test/Kestrel.Core.Tests/FrameTests.cs @@ -5,6 +5,7 @@ using System; using System.Collections; using System.Collections.Generic; using System.IO; +using System.IO.Pipelines; using System.Linq; using System.Text; using System.Threading; @@ -16,7 +17,6 @@ using Microsoft.AspNetCore.Server.Kestrel.Core.Features; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; -using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; using Microsoft.AspNetCore.Testing; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Primitives; diff --git a/test/Kestrel.Core.Tests/HttpParserTests.cs b/test/Kestrel.Core.Tests/HttpParserTests.cs index ee53a68d7f..d7f54601b2 100644 --- a/test/Kestrel.Core.Tests/HttpParserTests.cs +++ b/test/Kestrel.Core.Tests/HttpParserTests.cs @@ -2,15 +2,14 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.IO.Pipelines; +using System.IO.Pipelines.Testing; using System.Collections.Generic; using System.Linq; using System.Text; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; -using Microsoft.AspNetCore.Server.Kestrel.Internal.System; -using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; -using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.Testing; using Microsoft.AspNetCore.Testing; using Microsoft.Extensions.Logging; using Moq; diff --git a/test/Kestrel.Core.Tests/HttpUtilitiesTest.cs b/test/Kestrel.Core.Tests/HttpUtilitiesTest.cs index 08efbb4d40..af012742cb 100644 --- a/test/Kestrel.Core.Tests/HttpUtilitiesTest.cs +++ b/test/Kestrel.Core.Tests/HttpUtilitiesTest.cs @@ -5,7 +5,6 @@ using System; using System.Text; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; -using Microsoft.AspNetCore.Server.Kestrel.Internal.System; using Xunit; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests diff --git a/test/Kestrel.Core.Tests/KnownStringsTests.cs b/test/Kestrel.Core.Tests/KnownStringsTests.cs index bbdca711c6..75565d04f4 100644 --- a/test/Kestrel.Core.Tests/KnownStringsTests.cs +++ b/test/Kestrel.Core.Tests/KnownStringsTests.cs @@ -7,7 +7,6 @@ using System.Runtime.CompilerServices; using System.Text; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; -using Microsoft.AspNetCore.Server.Kestrel.Internal.System; using Xunit; namespace Microsoft.AspNetCore.Server.KestrelTests diff --git a/test/Kestrel.Core.Tests/OutputProducerTests.cs b/test/Kestrel.Core.Tests/OutputProducerTests.cs index 027e26f44e..d539a4012c 100644 --- a/test/Kestrel.Core.Tests/OutputProducerTests.cs +++ b/test/Kestrel.Core.Tests/OutputProducerTests.cs @@ -2,9 +2,9 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.IO.Pipelines; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; -using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; using Microsoft.AspNetCore.Testing; using Moq; using Xunit; diff --git a/test/Kestrel.Core.Tests/PathNormalizerTests.cs b/test/Kestrel.Core.Tests/PathNormalizerTests.cs index 1440c1ba6e..60a1e9b1c9 100644 --- a/test/Kestrel.Core.Tests/PathNormalizerTests.cs +++ b/test/Kestrel.Core.Tests/PathNormalizerTests.cs @@ -4,7 +4,6 @@ using System; using System.Text; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; -using Microsoft.AspNetCore.Server.Kestrel.Internal.System; using Xunit; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests diff --git a/test/Kestrel.Core.Tests/PipeOptionsTests.cs b/test/Kestrel.Core.Tests/PipeOptionsTests.cs index 56cec36d96..d35ac3c8a4 100644 --- a/test/Kestrel.Core.Tests/PipeOptionsTests.cs +++ b/test/Kestrel.Core.Tests/PipeOptionsTests.cs @@ -1,9 +1,9 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System.IO.Pipelines; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; -using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; using Microsoft.AspNetCore.Testing; using Moq; using Xunit; diff --git a/test/Kestrel.Core.Tests/PipelineExtensionTests.cs b/test/Kestrel.Core.Tests/PipelineExtensionTests.cs index a580b92e06..b79bb20a75 100644 --- a/test/Kestrel.Core.Tests/PipelineExtensionTests.cs +++ b/test/Kestrel.Core.Tests/PipelineExtensionTests.cs @@ -2,11 +2,9 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.IO.Pipelines; using System.Text; -using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; -using Microsoft.AspNetCore.Server.Kestrel.Internal.System; -using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; using Xunit; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests diff --git a/test/Kestrel.Core.Tests/StreamsTests.cs b/test/Kestrel.Core.Tests/StreamsTests.cs index b2657bc60a..7b6d73c1c1 100644 --- a/test/Kestrel.Core.Tests/StreamsTests.cs +++ b/test/Kestrel.Core.Tests/StreamsTests.cs @@ -2,13 +2,10 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; -using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; -using Microsoft.AspNetCore.Testing; using Moq; using Xunit; diff --git a/test/Kestrel.Core.Tests/TestHelpers/AssertExtensions.cs b/test/Kestrel.Core.Tests/TestHelpers/AssertExtensions.cs index 1ca99370e5..cb3fc36a3c 100644 --- a/test/Kestrel.Core.Tests/TestHelpers/AssertExtensions.cs +++ b/test/Kestrel.Core.Tests/TestHelpers/AssertExtensions.cs @@ -2,7 +2,6 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using Microsoft.AspNetCore.Server.Kestrel.Internal.System; using Xunit.Sdk; namespace Xunit diff --git a/test/Kestrel.Core.Tests/TestInput.cs b/test/Kestrel.Core.Tests/TestInput.cs index 1a9cf1620f..ccd07a034a 100644 --- a/test/Kestrel.Core.Tests/TestInput.cs +++ b/test/Kestrel.Core.Tests/TestInput.cs @@ -2,10 +2,10 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.IO.Pipelines; using System.Text; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; -using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; using Microsoft.AspNetCore.Testing; using Moq; diff --git a/test/Kestrel.FunctionalTests/SystemdActivation/docker.sh b/test/Kestrel.FunctionalTests/SystemdActivation/docker.sh index eec694cdd7..1f4a62b3a6 100755 --- a/test/Kestrel.FunctionalTests/SystemdActivation/docker.sh +++ b/test/Kestrel.FunctionalTests/SystemdActivation/docker.sh @@ -3,7 +3,8 @@ set -e scriptDir=$(dirname "${BASH_SOURCE[0]}") -~/.dotnet/dotnet publish -f netcoreapp2.0 ./samples/SampleApp/ +PATH="$HOME/.dotnet/:$PATH" +dotnet publish -f netcoreapp2.0 ./samples/SampleApp/ cp -R ./samples/SampleApp/bin/Debug/netcoreapp2.0/publish/ $scriptDir cp -R ~/.dotnet/ $scriptDir @@ -11,14 +12,14 @@ image=$(docker build -qf $scriptDir/Dockerfile $scriptDir) container=$(docker run -Pd $image) # Try to connect to SampleApp once a second up to 10 times via all available ports. -for i in {1..10}; do +for i in {1..10}; do curl -f http://$(docker port $container 8080/tcp) \ && curl -f http://$(docker port $container 8081/tcp) \ && curl -fk https://$(docker port $container 8082/tcp) \ && curl -f http://$(docker port $container 8083/tcp) \ && curl -f http://$(docker port $container 8084/tcp) \ && curl -fk https://$(docker port $container 8085/tcp) \ - && exit 0 || sleep 1; + && exit 0 || sleep 1; done exit -1 diff --git a/test/Kestrel.Performance/FrameFeatureCollection.cs b/test/Kestrel.Performance/FrameFeatureCollection.cs index 3d699f795f..6f1ee3d2bf 100644 --- a/test/Kestrel.Performance/FrameFeatureCollection.cs +++ b/test/Kestrel.Performance/FrameFeatureCollection.cs @@ -2,12 +2,12 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.IO.Pipelines; using BenchmarkDotNet.Attributes; using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; -using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; namespace Microsoft.AspNetCore.Server.Kestrel.Performance { diff --git a/test/Kestrel.Performance/FrameParsingOverheadBenchmark.cs b/test/Kestrel.Performance/FrameParsingOverheadBenchmark.cs index 6128d3c955..d570ee1f8d 100644 --- a/test/Kestrel.Performance/FrameParsingOverheadBenchmark.cs +++ b/test/Kestrel.Performance/FrameParsingOverheadBenchmark.cs @@ -1,11 +1,11 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System.IO.Pipelines; using BenchmarkDotNet.Attributes; using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; -using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; using Microsoft.AspNetCore.Server.Kestrel.Performance.Mocks; namespace Microsoft.AspNetCore.Server.Kestrel.Performance diff --git a/test/Kestrel.Performance/FrameWritingBenchmark.cs b/test/Kestrel.Performance/FrameWritingBenchmark.cs index 5eea9eafb2..664aebe15c 100644 --- a/test/Kestrel.Performance/FrameWritingBenchmark.cs +++ b/test/Kestrel.Performance/FrameWritingBenchmark.cs @@ -2,13 +2,13 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.IO.Pipelines; using System.Threading; using System.Threading.Tasks; using BenchmarkDotNet.Attributes; using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; -using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; using Microsoft.AspNetCore.Testing; namespace Microsoft.AspNetCore.Server.Kestrel.Performance diff --git a/test/Kestrel.Performance/KestrelHttpParserBenchmark.cs b/test/Kestrel.Performance/KestrelHttpParserBenchmark.cs index 30238b3223..d1e9d5a7aa 100644 --- a/test/Kestrel.Performance/KestrelHttpParserBenchmark.cs +++ b/test/Kestrel.Performance/KestrelHttpParserBenchmark.cs @@ -2,10 +2,9 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.IO.Pipelines; using BenchmarkDotNet.Attributes; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; -using Microsoft.AspNetCore.Server.Kestrel.Internal.System; -using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; namespace Microsoft.AspNetCore.Server.Kestrel.Performance { diff --git a/test/Kestrel.Performance/KnownStringsBenchmark.cs b/test/Kestrel.Performance/KnownStringsBenchmark.cs index 9aa3ffdf53..69bf2d5adb 100644 --- a/test/Kestrel.Performance/KnownStringsBenchmark.cs +++ b/test/Kestrel.Performance/KnownStringsBenchmark.cs @@ -6,7 +6,6 @@ using System.Text; using BenchmarkDotNet.Attributes; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; -using Microsoft.AspNetCore.Server.Kestrel.Internal.System; namespace Microsoft.AspNetCore.Server.Kestrel.Performance { diff --git a/test/Kestrel.Performance/Mocks/MockConnectionInformation.cs b/test/Kestrel.Performance/Mocks/MockConnectionInformation.cs index fb34c33f51..2f01186143 100644 --- a/test/Kestrel.Performance/Mocks/MockConnectionInformation.cs +++ b/test/Kestrel.Performance/Mocks/MockConnectionInformation.cs @@ -1,9 +1,8 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System; using System.Net; -using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; +using System.IO.Pipelines; using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; namespace Microsoft.AspNetCore.Server.Kestrel.Performance diff --git a/test/Kestrel.Performance/Mocks/NullParser.cs b/test/Kestrel.Performance/Mocks/NullParser.cs index 1484b2af44..ac4e36508c 100644 --- a/test/Kestrel.Performance/Mocks/NullParser.cs +++ b/test/Kestrel.Performance/Mocks/NullParser.cs @@ -2,10 +2,9 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.IO.Pipelines; using System.Text; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; -using Microsoft.AspNetCore.Server.Kestrel.Internal.System; -using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; namespace Microsoft.AspNetCore.Server.Kestrel.Performance { diff --git a/test/Kestrel.Performance/PipeThroughputBenchmark.cs b/test/Kestrel.Performance/PipeThroughputBenchmark.cs index 09d79ed693..e4322d2a47 100644 --- a/test/Kestrel.Performance/PipeThroughputBenchmark.cs +++ b/test/Kestrel.Performance/PipeThroughputBenchmark.cs @@ -1,9 +1,9 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System.IO.Pipelines; using System.Threading.Tasks; using BenchmarkDotNet.Attributes; -using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; namespace Microsoft.AspNetCore.Server.Kestrel.Performance { diff --git a/test/Kestrel.Performance/RequestParsingBenchmark.cs b/test/Kestrel.Performance/RequestParsingBenchmark.cs index c88f9408b2..f155b2a86d 100644 --- a/test/Kestrel.Performance/RequestParsingBenchmark.cs +++ b/test/Kestrel.Performance/RequestParsingBenchmark.cs @@ -1,11 +1,11 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System.IO.Pipelines; using BenchmarkDotNet.Attributes; using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; -using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; using Microsoft.AspNetCore.Server.Kestrel.Performance.Mocks; namespace Microsoft.AspNetCore.Server.Kestrel.Performance diff --git a/test/Kestrel.Performance/ResponseHeaderCollectionBenchmark.cs b/test/Kestrel.Performance/ResponseHeaderCollectionBenchmark.cs index f4d894a645..8423f95c02 100644 --- a/test/Kestrel.Performance/ResponseHeaderCollectionBenchmark.cs +++ b/test/Kestrel.Performance/ResponseHeaderCollectionBenchmark.cs @@ -1,6 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System.IO.Pipelines; using System.Runtime.CompilerServices; using System.Text; using BenchmarkDotNet.Attributes; @@ -9,7 +10,6 @@ using Microsoft.AspNetCore.Http.Internal; using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; -using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; namespace Microsoft.AspNetCore.Server.Kestrel.Performance { diff --git a/test/Kestrel.Performance/ResponseHeadersWritingBenchmark.cs b/test/Kestrel.Performance/ResponseHeadersWritingBenchmark.cs index 1daf1b7e45..85929d7211 100644 --- a/test/Kestrel.Performance/ResponseHeadersWritingBenchmark.cs +++ b/test/Kestrel.Performance/ResponseHeadersWritingBenchmark.cs @@ -2,7 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.IO; +using System.IO.Pipelines; using System.Text; using System.Threading; using System.Threading.Tasks; @@ -10,7 +10,6 @@ using BenchmarkDotNet.Attributes; using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; -using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; using Microsoft.AspNetCore.Server.Kestrel.Performance.Mocks; using Microsoft.AspNetCore.Testing; diff --git a/test/Kestrel.Transport.Libuv.Tests/LibuvConnectionTests.cs b/test/Kestrel.Transport.Libuv.Tests/LibuvConnectionTests.cs index de27f5774d..5f6e341d74 100644 --- a/test/Kestrel.Transport.Libuv.Tests/LibuvConnectionTests.cs +++ b/test/Kestrel.Transport.Libuv.Tests/LibuvConnectionTests.cs @@ -2,9 +2,9 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.IO.Pipelines; using System.Threading; using System.Threading.Tasks; -using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal; using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking; using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests.TestHelpers; diff --git a/test/Kestrel.Transport.Libuv.Tests/LibuvOutputConsumerTests.cs b/test/Kestrel.Transport.Libuv.Tests/LibuvOutputConsumerTests.cs index c91ef7994f..973b0e387c 100644 --- a/test/Kestrel.Transport.Libuv.Tests/LibuvOutputConsumerTests.cs +++ b/test/Kestrel.Transport.Libuv.Tests/LibuvOutputConsumerTests.cs @@ -3,12 +3,12 @@ using System; using System.Collections.Concurrent; +using System.IO.Pipelines; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; -using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal; using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking; using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests.TestHelpers; diff --git a/test/Kestrel.Transport.Libuv.Tests/MultipleLoopTests.cs b/test/Kestrel.Transport.Libuv.Tests/MultipleLoopTests.cs index e57b16b30a..c079e405cc 100644 --- a/test/Kestrel.Transport.Libuv.Tests/MultipleLoopTests.cs +++ b/test/Kestrel.Transport.Libuv.Tests/MultipleLoopTests.cs @@ -2,11 +2,11 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.IO.Pipelines; using System.Net; using System.Net.Sockets; using System.Runtime.InteropServices; using System.Threading; -using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal; using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking; using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests.TestHelpers; diff --git a/test/Kestrel.Transport.Libuv.Tests/NetworkingTests.cs b/test/Kestrel.Transport.Libuv.Tests/NetworkingTests.cs index 72aab202ba..0378022eed 100644 --- a/test/Kestrel.Transport.Libuv.Tests/NetworkingTests.cs +++ b/test/Kestrel.Transport.Libuv.Tests/NetworkingTests.cs @@ -8,7 +8,7 @@ using System.Runtime.InteropServices; using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal; using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking; -using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; +using System.IO.Pipelines; using Microsoft.AspNetCore.Testing; using Xunit; diff --git a/test/Kestrel.Transport.Libuv.Tests/TestHelpers/MockConnectionHandler.cs b/test/Kestrel.Transport.Libuv.Tests/TestHelpers/MockConnectionHandler.cs index c8b965ef30..a8096d7181 100644 --- a/test/Kestrel.Transport.Libuv.Tests/TestHelpers/MockConnectionHandler.cs +++ b/test/Kestrel.Transport.Libuv.Tests/TestHelpers/MockConnectionHandler.cs @@ -2,10 +2,8 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; +using System.IO.Pipelines; using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; -using Xunit; namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests.TestHelpers { diff --git a/test/shared/MockConnectionInformation.cs b/test/shared/MockConnectionInformation.cs index 742bcd2aa2..db6ee00fda 100644 --- a/test/shared/MockConnectionInformation.cs +++ b/test/shared/MockConnectionInformation.cs @@ -1,8 +1,8 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System.IO.Pipelines; using System.Net; -using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; namespace Microsoft.AspNetCore.Testing diff --git a/tools/CodeGenerator/KnownHeaders.cs b/tools/CodeGenerator/KnownHeaders.cs index b0cdf0b530..16aac8269f 100644 --- a/tools/CodeGenerator/KnownHeaders.cs +++ b/tools/CodeGenerator/KnownHeaders.cs @@ -292,7 +292,7 @@ namespace CodeGenerator using System; using System.Collections.Generic; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; -using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; +using System.IO.Pipelines; using Microsoft.Extensions.Primitives; using Microsoft.Net.Http.Headers; From d3fb5e76f1fdf6a581c65316af4170f46d40fe7c Mon Sep 17 00:00:00 2001 From: Nate McMaster Date: Wed, 9 Aug 2017 16:48:02 -0700 Subject: [PATCH 1370/1662] Remove dependency on a custom task to detect when compiling on macOS (#1987) MSBuild.IsOSPlatform is new to MSBuild 15.3 and can be used to determine when we are building on macOS. --- .../Kestrel.FunctionalTests.csproj | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/test/Kestrel.FunctionalTests/Kestrel.FunctionalTests.csproj b/test/Kestrel.FunctionalTests/Kestrel.FunctionalTests.csproj index d1e519263f..845ea0f84c 100644 --- a/test/Kestrel.FunctionalTests/Kestrel.FunctionalTests.csproj +++ b/test/Kestrel.FunctionalTests/Kestrel.FunctionalTests.csproj @@ -7,6 +7,7 @@ Microsoft.AspNetCore.Server.Kestrel.FunctionalTests netcoreapp2.0;net461 netcoreapp2.0 + $(DefineConstants);MACOS true - - - - - $(DefineConstants);$(OSPlatform.ToUpperInvariant()) - - - From 02028b65c797aa51f93b28f48a2f805bf03e9576 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Fri, 11 Aug 2017 16:30:03 -0700 Subject: [PATCH 1371/1662] Stop using ConcurrentBag in tests for complex types (#1990) dotnet/corefx#23068 --- test/Kestrel.Core.Tests/FrameConnectionTests.cs | 11 +++++++---- test/Kestrel.FunctionalTests/EventSourceTests.cs | 4 ++-- test/shared/TestApplicationErrorLogger.cs | 12 ++++++------ 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/test/Kestrel.Core.Tests/FrameConnectionTests.cs b/test/Kestrel.Core.Tests/FrameConnectionTests.cs index 9cf86bc7dc..555838c820 100644 --- a/test/Kestrel.Core.Tests/FrameConnectionTests.cs +++ b/test/Kestrel.Core.Tests/FrameConnectionTests.cs @@ -535,10 +535,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests public async Task StartRequestProcessingCreatesLogScopeWithConnectionId() { _frameConnection.StartRequestProcessing(new DummyApplication()); - - _frameConnection.OnConnectionClosed(ex: null); - - await _frameConnection.StopAsync().TimeoutAfter(TimeSpan.FromSeconds(5)); var scopeObjects = ((TestKestrelTrace)_frameConnectionContext.ServiceContext.Log) .Logger @@ -546,10 +542,17 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests .OfType>>() .ToList(); + _frameConnection.OnConnectionClosed(ex: null); + + await _frameConnection.StopAsync().TimeoutAfter(TimeSpan.FromSeconds(5)); + Assert.Equal(1, scopeObjects.Count); var pairs = scopeObjects[0].ToDictionary(p => p.Key, p => p.Value); Assert.True(pairs.ContainsKey("ConnectionId")); Assert.Equal(_frameConnection.ConnectionId, pairs["ConnectionId"]); + + // Verify the scope was disposed after request processing completed + Assert.True(((TestKestrelTrace)_frameConnectionContext.ServiceContext.Log).Logger.Scopes.IsEmpty); } } } diff --git a/test/Kestrel.FunctionalTests/EventSourceTests.cs b/test/Kestrel.FunctionalTests/EventSourceTests.cs index e2f40011a7..639e8d5153 100644 --- a/test/Kestrel.FunctionalTests/EventSourceTests.cs +++ b/test/Kestrel.FunctionalTests/EventSourceTests.cs @@ -84,7 +84,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests private class TestEventListener : EventListener { private volatile bool _disposed; - private ConcurrentBag _events = new ConcurrentBag(); + private ConcurrentQueue _events = new ConcurrentQueue(); public IEnumerable EventData => _events; @@ -92,7 +92,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { if (!_disposed) { - _events.Add(eventData); + _events.Enqueue(eventData); } } diff --git a/test/shared/TestApplicationErrorLogger.cs b/test/shared/TestApplicationErrorLogger.cs index 936624f1a8..144b251802 100644 --- a/test/shared/TestApplicationErrorLogger.cs +++ b/test/shared/TestApplicationErrorLogger.cs @@ -3,7 +3,6 @@ using System; using System.Collections.Concurrent; -using System.Threading.Tasks; using System.Linq; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; using Microsoft.Extensions.Logging; @@ -17,9 +16,9 @@ namespace Microsoft.AspNetCore.Testing public bool ThrowOnCriticalErrors { get; set; } = true; - public ConcurrentBag Messages { get; } = new ConcurrentBag(); + public ConcurrentQueue Messages { get; } = new ConcurrentQueue(); - public ConcurrentBag Scopes { get; } = new ConcurrentBag(); + public ConcurrentQueue Scopes { get; } = new ConcurrentQueue(); public int TotalErrorsLogged => Messages.Count(message => message.LogLevel == LogLevel.Error); @@ -29,8 +28,9 @@ namespace Microsoft.AspNetCore.Testing public IDisposable BeginScope(TState state) { - Scopes.Add(state); - return new Disposable(() => { }); + Scopes.Enqueue(state); + + return new Disposable(() => { Scopes.TryDequeue(out _); }); } public bool IsEnabled(LogLevel logLevel) @@ -52,7 +52,7 @@ namespace Microsoft.AspNetCore.Testing } } - Messages.Add(new LogMessage + Messages.Enqueue(new LogMessage { LogLevel = logLevel, EventId = eventId, From d3cf0494e79807c00136f3f66fbdaefb80e231fb Mon Sep 17 00:00:00 2001 From: Nate McMaster Date: Fri, 11 Aug 2017 17:22:40 -0700 Subject: [PATCH 1372/1662] Upgrade to xunit 2.3.0-beta3 --- build/dependencies.props | 4 ++-- test/Kestrel.Core.Tests/FrameHeadersTests.cs | 12 ++++++------ test/Kestrel.Core.Tests/FrameTests.cs | 6 +++--- test/Kestrel.Core.Tests/HttpParserTests.cs | 2 +- test/Kestrel.Core.Tests/KestrelServerTests.cs | 4 ++-- 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/build/dependencies.props b/build/dependencies.props index 73c5dee642..c32a5f7a7c 100644 --- a/build/dependencies.props +++ b/build/dependencies.props @@ -10,7 +10,7 @@ 2.0.0-* 2.0.0-* 2.6.0-rdonly-ref-61915-01 - 15.3.0-* - 2.3.0-beta2-* + 15.3.0 + 2.3.0-beta3-build3705 diff --git a/test/Kestrel.Core.Tests/FrameHeadersTests.cs b/test/Kestrel.Core.Tests/FrameHeadersTests.cs index 385f4d3ec4..283645615e 100644 --- a/test/Kestrel.Core.Tests/FrameHeadersTests.cs +++ b/test/Kestrel.Core.Tests/FrameHeadersTests.cs @@ -217,11 +217,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests [Fact] public void ValidContentLengthsAccepted() { - ValidContentLengthsAccepted(new FrameRequestHeaders()); - ValidContentLengthsAccepted(new FrameResponseHeaders()); + ValidContentLengthsAcceptedImpl(new FrameRequestHeaders()); + ValidContentLengthsAcceptedImpl(new FrameResponseHeaders()); } - private static void ValidContentLengthsAccepted(FrameHeaders frameHeaders) + private static void ValidContentLengthsAcceptedImpl(FrameHeaders frameHeaders) { IDictionary headers = frameHeaders; @@ -252,11 +252,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests [Fact] public void InvalidContentLengthsRejected() { - InvalidContentLengthsRejected(new FrameRequestHeaders()); - InvalidContentLengthsRejected(new FrameResponseHeaders()); + InvalidContentLengthsRejectedImpl(new FrameRequestHeaders()); + InvalidContentLengthsRejectedImpl(new FrameResponseHeaders()); } - private static void InvalidContentLengthsRejected(FrameHeaders frameHeaders) + private static void InvalidContentLengthsRejectedImpl(FrameHeaders frameHeaders) { IDictionary headers = frameHeaders; diff --git a/test/Kestrel.Core.Tests/FrameTests.cs b/test/Kestrel.Core.Tests/FrameTests.cs index 64274972b8..081861975d 100644 --- a/test/Kestrel.Core.Tests/FrameTests.cs +++ b/test/Kestrel.Core.Tests/FrameTests.cs @@ -590,7 +590,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests await _input.Writer.WriteAsync(data); _frame.Stop(); - Assert.IsNotType(typeof(Task), requestProcessingTask); + Assert.IsNotType>(requestProcessingTask); await requestProcessingTask.TimeoutAfter(TimeSpan.FromSeconds(10)); _input.Writer.Complete(); @@ -812,9 +812,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests .Select(i => $"Header-{startAt + i}: value{startAt + i}\r\n")); } - public static IEnumerable RequestLineValidData => HttpParsingData.RequestLineValidData; + public static IEnumerable RequestLineValidData => HttpParsingData.RequestLineValidData; - public static IEnumerable RequestLineDotSegmentData => HttpParsingData.RequestLineDotSegmentData; + public static IEnumerable RequestLineDotSegmentData => HttpParsingData.RequestLineDotSegmentData; public static TheoryData TargetWithEncodedNullCharData { diff --git a/test/Kestrel.Core.Tests/HttpParserTests.cs b/test/Kestrel.Core.Tests/HttpParserTests.cs index d7f54601b2..d79c5c3ea2 100644 --- a/test/Kestrel.Core.Tests/HttpParserTests.cs +++ b/test/Kestrel.Core.Tests/HttpParserTests.cs @@ -419,7 +419,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests private IHttpParser CreateParser(IKestrelTrace log) => new HttpParser(log.IsEnabled(LogLevel.Information)); - public static IEnumerable RequestLineValidData => HttpParsingData.RequestLineValidData; + public static IEnumerable RequestLineValidData => HttpParsingData.RequestLineValidData; public static IEnumerable RequestLineIncompleteData => HttpParsingData.RequestLineIncompleteData.Select(requestLine => new[] { requestLine }); diff --git a/test/Kestrel.Core.Tests/KestrelServerTests.cs b/test/Kestrel.Core.Tests/KestrelServerTests.cs index e948fb9ce2..c6ae3b5a7a 100644 --- a/test/Kestrel.Core.Tests/KestrelServerTests.cs +++ b/test/Kestrel.Core.Tests/KestrelServerTests.cs @@ -90,7 +90,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests StartDummyApplication(server); var warning = testLogger.Messages.Single(log => log.LogLevel == LogLevel.Warning); - Assert.True(warning.Message.Contains("Overriding")); + Assert.Contains("Overriding", warning.Message); } } @@ -271,7 +271,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests private static KestrelServer CreateServer(KestrelServerOptions options, ILogger testLogger) { - return new KestrelServer(Options.Create(options), new MockTransportFactory(), new LoggerFactory(new [] { new KestrelTestLoggerProvider(testLogger)} )); + return new KestrelServer(Options.Create(options), new MockTransportFactory(), new LoggerFactory(new[] { new KestrelTestLoggerProvider(testLogger) })); } private static void StartDummyApplication(IServer server) From f3745608af5020eaa3e83cd5a21aeaa2b85b618b Mon Sep 17 00:00:00 2001 From: Pranav K Date: Tue, 15 Aug 2017 16:11:07 -0700 Subject: [PATCH 1373/1662] Switch to v3 NuGet feed --- NuGet.config | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NuGet.config b/NuGet.config index 29b1318efd..2dfd335477 100644 --- a/NuGet.config +++ b/NuGet.config @@ -5,6 +5,6 @@ - + From 5c775073a4abb5d241f1a1b9587d3d23a6fbe14f Mon Sep 17 00:00:00 2001 From: David Fowler Date: Wed, 16 Aug 2017 00:02:48 -0700 Subject: [PATCH 1374/1662] Initial bedrock refactoring (#1995) - Added Protocols.Abstractions - IConnectionHandler.OnConnection takes an IFeatureCollection instead of IConnectionInfo - Removed IConnectionContext and IConnectionInformation replaced with IConnectionTransportFeature - Updated FrameConnectionContext and FrameContext to have the relevant state instead of flowing the ConnectionInformation. - Updated tests --- KestrelHttpServer.sln | 17 +- src/Kestrel.Core/Internal/AddressBinder.cs | 2 +- .../Internal/ConnectionHandler.cs | 63 ++++- src/Kestrel.Core/Internal/FrameConnection.cs | 17 +- .../Internal/FrameConnectionContext.cs | 6 +- src/Kestrel.Core/Internal/Http/Frame.cs | 9 +- .../Internal/Http/FrameContext.cs | 7 +- src/Kestrel.Core/Internal/Http/FrameOfT.cs | 2 +- .../Internal/Http/FrameRequestStream.cs | 1 + ...rameConnectionManagerShutdownExtensions.cs | 1 + .../Infrastructure/KestrelEventSource.cs | 13 +- .../Internal/RejectionConnection.cs | 13 +- .../Internal/IConnectionContext.cs | 19 -- .../Internal/IConnectionHandler.cs | 4 +- .../Internal/IConnectionInformation.cs | 19 -- .../Internal/TransportConnection.Features.cs | 215 ++++++++++++++++++ .../Internal/TransportConnection.cs | 33 +++ .../Kestrel.Transport.Abstractions.csproj | 10 +- .../Internal/LibuvConnection.cs | 39 ++-- .../Internal/LibuvConnectionContext.cs | 17 +- src/Kestrel.Transport.Libuv/LibuvTransport.cs | 1 + .../SocketConnection.cs | 39 ++-- .../SocketTransport.cs | 1 + .../ConnectionContext.cs | 17 ++ .../ConnectionDelegate.cs | 9 + .../DefaultConnectionContext.cs | 48 ++++ .../Exceptions/AddressInUseException.cs | 2 +- .../Exceptions/ConnectionAbortedException.cs | 2 +- .../Exceptions/ConnectionResetException.cs | 2 +- .../Features/IConnectionApplicationFeature.cs | 18 ++ .../Features/IConnectionIdFeature.cs | 11 + .../Features/IConnectionTransportFeature.cs | 18 ++ .../IConnectionBuilder.cs | 15 ++ src/Protocols.Abstractions/PipeConnection.cs | 23 ++ .../Protocols.Abstractions.csproj | 30 +++ test/Kestrel.Core.Tests/AddressBinderTests.cs | 1 + .../FrameConnectionTests.cs | 5 +- .../FrameResponseHeadersTests.cs | 5 +- test/Kestrel.Core.Tests/FrameTests.cs | 5 +- test/Kestrel.Core.Tests/TestInput.cs | 5 +- test/Kestrel.FunctionalTests/RequestTests.cs | 1 + .../FrameFeatureCollection.cs | 7 +- .../FrameParsingOverheadBenchmark.cs | 5 +- .../FrameWritingBenchmark.cs | 5 +- .../Mocks/MockConnectionInformation.cs | 20 -- .../RequestParsingBenchmark.cs | 5 +- .../ResponseHeaderCollectionBenchmark.cs | 5 +- .../ResponseHeadersWritingBenchmark.cs | 5 +- .../LibuvOutputConsumerTests.cs | 5 +- .../TestHelpers/MockConnectionHandler.cs | 25 +- test/shared/MockConnectionInformation.cs | 22 -- 51 files changed, 632 insertions(+), 237 deletions(-) delete mode 100644 src/Kestrel.Transport.Abstractions/Internal/IConnectionContext.cs delete mode 100644 src/Kestrel.Transport.Abstractions/Internal/IConnectionInformation.cs create mode 100644 src/Kestrel.Transport.Abstractions/Internal/TransportConnection.Features.cs create mode 100644 src/Kestrel.Transport.Abstractions/Internal/TransportConnection.cs create mode 100644 src/Protocols.Abstractions/ConnectionContext.cs create mode 100644 src/Protocols.Abstractions/ConnectionDelegate.cs create mode 100644 src/Protocols.Abstractions/DefaultConnectionContext.cs rename src/{Kestrel.Transport.Abstractions => Protocols.Abstractions}/Exceptions/AddressInUseException.cs (85%) rename src/{Kestrel.Transport.Abstractions => Protocols.Abstractions}/Exceptions/ConnectionAbortedException.cs (84%) rename src/{Kestrel.Transport.Abstractions => Protocols.Abstractions}/Exceptions/ConnectionResetException.cs (86%) create mode 100644 src/Protocols.Abstractions/Features/IConnectionApplicationFeature.cs create mode 100644 src/Protocols.Abstractions/Features/IConnectionIdFeature.cs create mode 100644 src/Protocols.Abstractions/Features/IConnectionTransportFeature.cs create mode 100644 src/Protocols.Abstractions/IConnectionBuilder.cs create mode 100644 src/Protocols.Abstractions/PipeConnection.cs create mode 100644 src/Protocols.Abstractions/Protocols.Abstractions.csproj delete mode 100644 test/Kestrel.Performance/Mocks/MockConnectionInformation.cs delete mode 100644 test/shared/MockConnectionInformation.cs diff --git a/KestrelHttpServer.sln b/KestrelHttpServer.sln index 4c9791d022..60221f61ae 100644 --- a/KestrelHttpServer.sln +++ b/KestrelHttpServer.sln @@ -1,6 +1,6 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 15 -VisualStudioVersion = 15.0.26706.0 +VisualStudioVersion = 15.0.26730.0 MinimumVisualStudioVersion = 10.0.40219.1 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{7972A5D6-3385-4127-9277-428506DD44FF}" ProjectSection(SolutionItems) = preProject @@ -80,6 +80,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Kestrel.Transport.Libuv.Tes EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Kestrel.Tests", "test\Kestrel.Tests\Kestrel.Tests.csproj", "{4F1C30F8-CCAA-48D7-9DF6-2A84021F5BCC}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Protocols.Abstractions", "src\Protocols.Abstractions\Protocols.Abstractions.csproj", "{6956CF5C-3163-4398-8628-4ECA569245B5}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -258,6 +260,18 @@ Global {4F1C30F8-CCAA-48D7-9DF6-2A84021F5BCC}.Release|x64.Build.0 = Release|Any CPU {4F1C30F8-CCAA-48D7-9DF6-2A84021F5BCC}.Release|x86.ActiveCfg = Release|Any CPU {4F1C30F8-CCAA-48D7-9DF6-2A84021F5BCC}.Release|x86.Build.0 = Release|Any CPU + {6956CF5C-3163-4398-8628-4ECA569245B5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {6956CF5C-3163-4398-8628-4ECA569245B5}.Debug|Any CPU.Build.0 = Debug|Any CPU + {6956CF5C-3163-4398-8628-4ECA569245B5}.Debug|x64.ActiveCfg = Debug|Any CPU + {6956CF5C-3163-4398-8628-4ECA569245B5}.Debug|x64.Build.0 = Debug|Any CPU + {6956CF5C-3163-4398-8628-4ECA569245B5}.Debug|x86.ActiveCfg = Debug|Any CPU + {6956CF5C-3163-4398-8628-4ECA569245B5}.Debug|x86.Build.0 = Debug|Any CPU + {6956CF5C-3163-4398-8628-4ECA569245B5}.Release|Any CPU.ActiveCfg = Release|Any CPU + {6956CF5C-3163-4398-8628-4ECA569245B5}.Release|Any CPU.Build.0 = Release|Any CPU + {6956CF5C-3163-4398-8628-4ECA569245B5}.Release|x64.ActiveCfg = Release|Any CPU + {6956CF5C-3163-4398-8628-4ECA569245B5}.Release|x64.Build.0 = Release|Any CPU + {6956CF5C-3163-4398-8628-4ECA569245B5}.Release|x86.ActiveCfg = Release|Any CPU + {6956CF5C-3163-4398-8628-4ECA569245B5}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -279,6 +293,7 @@ Global {2E9CB89D-EC8F-4DD9-A72B-08D5BABF752D} = {2D5D5227-4DBD-499A-96B1-76A36B03B750} {D95A7EC3-48AC-4D03-B2E2-0DA3E13BD3A4} = {D3273454-EA07-41D2-BF0B-FCC3675C2483} {4F1C30F8-CCAA-48D7-9DF6-2A84021F5BCC} = {D3273454-EA07-41D2-BF0B-FCC3675C2483} + {6956CF5C-3163-4398-8628-4ECA569245B5} = {2D5D5227-4DBD-499A-96B1-76A36B03B750} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {2D10D020-6770-47CA-BB8D-2C23FE3AE071} diff --git a/src/Kestrel.Core/Internal/AddressBinder.cs b/src/Kestrel.Core/Internal/AddressBinder.cs index 43f0c82abf..e4d1d18b93 100644 --- a/src/Kestrel.Core/Internal/AddressBinder.cs +++ b/src/Kestrel.Core/Internal/AddressBinder.cs @@ -9,8 +9,8 @@ using System.Net; using System.Threading.Tasks; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting.Server.Features; +using Microsoft.AspNetCore.Protocols; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; -using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; using Microsoft.Extensions.Logging; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal diff --git a/src/Kestrel.Core/Internal/ConnectionHandler.cs b/src/Kestrel.Core/Internal/ConnectionHandler.cs index 1d46a91f64..0dc7fbcbf0 100644 --- a/src/Kestrel.Core/Internal/ConnectionHandler.cs +++ b/src/Kestrel.Core/Internal/ConnectionHandler.cs @@ -2,8 +2,12 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.IO.Pipelines; +using System.Net; using System.Threading; using Microsoft.AspNetCore.Hosting.Server; +using Microsoft.AspNetCore.Http.Features; +using Microsoft.AspNetCore.Protocols; +using Microsoft.AspNetCore.Protocols.Features; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; @@ -24,38 +28,73 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal _application = application; } - public IConnectionContext OnConnection(IConnectionInformation connectionInfo) + public void OnConnection(IFeatureCollection features) { - var inputPipe = connectionInfo.PipeFactory.Create(GetInputPipeOptions(connectionInfo.InputWriterScheduler)); - var outputPipe = connectionInfo.PipeFactory.Create(GetOutputPipeOptions(connectionInfo.OutputReaderScheduler)); + var connectionContext = new DefaultConnectionContext(features); + + var transportFeature = connectionContext.Features.Get(); + + var inputPipe = transportFeature.PipeFactory.Create(GetInputPipeOptions(transportFeature.InputWriterScheduler)); + var outputPipe = transportFeature.PipeFactory.Create(GetOutputPipeOptions(transportFeature.OutputReaderScheduler)); var connectionId = CorrelationIdGenerator.GetNextId(); var frameConnectionId = Interlocked.Increment(ref _lastFrameConnectionId); + // Set the transport and connection id + connectionContext.ConnectionId = connectionId; + transportFeature.Connection = new PipeConnection(inputPipe.Reader, outputPipe.Writer); + var applicationConnection = new PipeConnection(outputPipe.Reader, inputPipe.Writer); + if (!_serviceContext.ConnectionManager.NormalConnectionCount.TryLockOne()) { - var goAway = new RejectionConnection(inputPipe, outputPipe, connectionId, _serviceContext); + var goAway = new RejectionConnection(inputPipe, outputPipe, connectionId, _serviceContext) + { + Connection = applicationConnection + }; + + connectionContext.Features.Set(goAway); + goAway.Reject(); - return goAway; + return; } - var connection = new FrameConnection(new FrameConnectionContext + var frameConnectionContext = new FrameConnectionContext { ConnectionId = connectionId, FrameConnectionId = frameConnectionId, ServiceContext = _serviceContext, - ConnectionInformation = connectionInfo, + PipeFactory = connectionContext.PipeFactory, ConnectionAdapters = _listenOptions.ConnectionAdapters, Input = inputPipe, - Output = outputPipe, - }); + Output = outputPipe + }; + + var connectionFeature = connectionContext.Features.Get(); + + if (connectionFeature != null) + { + if (connectionFeature.LocalIpAddress != null) + { + frameConnectionContext.LocalEndPoint = new IPEndPoint(connectionFeature.LocalIpAddress, connectionFeature.LocalPort); + } + + if (connectionFeature.RemoteIpAddress != null) + { + frameConnectionContext.RemoteEndPoint = new IPEndPoint(connectionFeature.RemoteIpAddress, connectionFeature.RemotePort); + } + } + + var connection = new FrameConnection(frameConnectionContext) + { + Connection = applicationConnection + }; + + connectionContext.Features.Set(connection); // Since data cannot be added to the inputPipe by the transport until OnConnection returns, // Frame.ProcessRequestsAsync is guaranteed to unblock the transport thread before calling // application code. - connection.StartRequestProcessing(_application); - - return connection; + connection.StartRequestProcessing(_application); } // Internal for testing diff --git a/src/Kestrel.Core/Internal/FrameConnection.cs b/src/Kestrel.Core/Internal/FrameConnection.cs index ef3c6e15b4..dbe08fce25 100644 --- a/src/Kestrel.Core/Internal/FrameConnection.cs +++ b/src/Kestrel.Core/Internal/FrameConnection.cs @@ -6,19 +6,20 @@ using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.IO.Pipelines; +using System.Net; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Hosting.Server; using Microsoft.AspNetCore.Http.Features; +using Microsoft.AspNetCore.Protocols.Features; using Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; -using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; using Microsoft.Extensions.Logging; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal { - public class FrameConnection : IConnectionContext, ITimeoutControl + public class FrameConnection : IConnectionApplicationFeature, ITimeoutControl { private readonly FrameConnectionContext _context; private List _adaptedConnections; @@ -55,8 +56,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal public string ConnectionId => _context.ConnectionId; public IPipeWriter Input => _context.Input.Writer; public IPipeReader Output => _context.Output.Reader; + public IPEndPoint LocalEndPoint => _context.LocalEndPoint; + public IPEndPoint RemoteEndPoint => _context.RemoteEndPoint; - private PipeFactory PipeFactory => _context.ConnectionInformation.PipeFactory; + private PipeFactory PipeFactory => _context.PipeFactory; // Internal for testing internal PipeOptions AdaptedInputPipeOptions => new PipeOptions @@ -77,6 +80,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal private IKestrelTrace Log => _context.ServiceContext.Log; + public IPipeConnection Connection { get; set; } + public void StartRequestProcessing(IHttpApplication application) { _lifetimeTask = ProcessRequestsAsync(application); @@ -89,7 +94,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal try { Log.ConnectionStart(ConnectionId); - KestrelEventSource.Log.ConnectionStart(this, _context.ConnectionInformation); + KestrelEventSource.Log.ConnectionStart(this); AdaptedPipeline adaptedPipeline = null; var adaptedPipelineTask = Task.CompletedTask; @@ -156,7 +161,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal _frame = new Frame(application, new FrameContext { ConnectionId = _context.ConnectionId, - ConnectionInformation = _context.ConnectionInformation, + PipeFactory = PipeFactory, + LocalEndPoint = LocalEndPoint, + RemoteEndPoint = RemoteEndPoint, ServiceContext = _context.ServiceContext, TimeoutControl = this, Input = input, diff --git a/src/Kestrel.Core/Internal/FrameConnectionContext.cs b/src/Kestrel.Core/Internal/FrameConnectionContext.cs index 963d353021..57b08141f3 100644 --- a/src/Kestrel.Core/Internal/FrameConnectionContext.cs +++ b/src/Kestrel.Core/Internal/FrameConnectionContext.cs @@ -3,8 +3,8 @@ using System.Collections.Generic; using System.IO.Pipelines; +using System.Net; using Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal; -using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal { @@ -14,7 +14,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal public long FrameConnectionId { get; set; } public ServiceContext ServiceContext { get; set; } public List ConnectionAdapters { get; set; } - public IConnectionInformation ConnectionInformation { get; set; } + public PipeFactory PipeFactory { get; set; } + public IPEndPoint LocalEndPoint { get; set; } + public IPEndPoint RemoteEndPoint { get; set; } public IPipe Input { get; set; } public IPipe Output { get; set; } diff --git a/src/Kestrel.Core/Internal/Http/Frame.cs b/src/Kestrel.Core/Internal/Http/Frame.cs index 8c6f648be3..251e256d41 100644 --- a/src/Kestrel.Core/Internal/Http/Frame.cs +++ b/src/Kestrel.Core/Internal/Http/Frame.cs @@ -15,8 +15,8 @@ using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http.Features; +using Microsoft.AspNetCore.Protocols; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; -using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Primitives; @@ -103,7 +103,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http public IPipe RequestBodyPipe { get; } public ServiceContext ServiceContext => _frameContext.ServiceContext; - public IConnectionInformation ConnectionInformation => _frameContext.ConnectionInformation; + private IPEndPoint LocalEndPoint => _frameContext.LocalEndPoint; + private IPEndPoint RemoteEndPoint => _frameContext.RemoteEndPoint; public IFeatureCollection ConnectionFeatures { get; set; } public IPipeReader Input => _frameContext.Input; @@ -114,8 +115,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http private DateHeaderValueManager DateHeaderValueManager => ServiceContext.DateHeaderValueManager; // Hold direct reference to ServerOptions since this is used very often in the request processing path private KestrelServerOptions ServerOptions { get; } - private IPEndPoint LocalEndPoint => ConnectionInformation.LocalEndPoint; - private IPEndPoint RemoteEndPoint => ConnectionInformation.RemoteEndPoint; protected string ConnectionId => _frameContext.ConnectionId; public string ConnectionIdFeature { get; set; } @@ -1376,7 +1375,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http } private IPipe CreateRequestBodyPipe() - => ConnectionInformation.PipeFactory.Create(new PipeOptions + => _frameContext.PipeFactory.Create(new PipeOptions { ReaderScheduler = ServiceContext.ThreadPool, WriterScheduler = InlineScheduler.Default, diff --git a/src/Kestrel.Core/Internal/Http/FrameContext.cs b/src/Kestrel.Core/Internal/Http/FrameContext.cs index ac5d4de636..67274af488 100644 --- a/src/Kestrel.Core/Internal/Http/FrameContext.cs +++ b/src/Kestrel.Core/Internal/Http/FrameContext.cs @@ -2,8 +2,9 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.IO.Pipelines; +using System.Net; +using Microsoft.AspNetCore.Protocols; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; -using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { @@ -11,7 +12,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { public string ConnectionId { get; set; } public ServiceContext ServiceContext { get; set; } - public IConnectionInformation ConnectionInformation { get; set; } + public PipeFactory PipeFactory { get; set; } + public IPEndPoint RemoteEndPoint { get; set; } + public IPEndPoint LocalEndPoint { get; set; } public ITimeoutControl TimeoutControl { get; set; } public IPipeReader Input { get; set; } public IPipe Output { get; set; } diff --git a/src/Kestrel.Core/Internal/Http/FrameOfT.cs b/src/Kestrel.Core/Internal/Http/FrameOfT.cs index 9e83e5351b..79ac93384a 100644 --- a/src/Kestrel.Core/Internal/Http/FrameOfT.cs +++ b/src/Kestrel.Core/Internal/Http/FrameOfT.cs @@ -6,8 +6,8 @@ using System.IO; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Hosting.Server; +using Microsoft.AspNetCore.Protocols; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; -using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; using Microsoft.Extensions.Logging; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http diff --git a/src/Kestrel.Core/Internal/Http/FrameRequestStream.cs b/src/Kestrel.Core/Internal/Http/FrameRequestStream.cs index aa2e9de5a7..5adc0a6e71 100644 --- a/src/Kestrel.Core/Internal/Http/FrameRequestStream.cs +++ b/src/Kestrel.Core/Internal/Http/FrameRequestStream.cs @@ -8,6 +8,7 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; using Microsoft.AspNetCore.Http.Features; +using Microsoft.AspNetCore.Protocols; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { diff --git a/src/Kestrel.Core/Internal/Infrastructure/FrameConnectionManagerShutdownExtensions.cs b/src/Kestrel.Core/Internal/Infrastructure/FrameConnectionManagerShutdownExtensions.cs index 3adaa4ae84..1a0df064db 100644 --- a/src/Kestrel.Core/Internal/Infrastructure/FrameConnectionManagerShutdownExtensions.cs +++ b/src/Kestrel.Core/Internal/Infrastructure/FrameConnectionManagerShutdownExtensions.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; +using Microsoft.AspNetCore.Protocols; using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure diff --git a/src/Kestrel.Core/Internal/Infrastructure/KestrelEventSource.cs b/src/Kestrel.Core/Internal/Infrastructure/KestrelEventSource.cs index 628de18f67..4191141bbb 100644 --- a/src/Kestrel.Core/Internal/Infrastructure/KestrelEventSource.cs +++ b/src/Kestrel.Core/Internal/Infrastructure/KestrelEventSource.cs @@ -2,7 +2,10 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Diagnostics.Tracing; +using System.Net; using System.Runtime.CompilerServices; +using Microsoft.AspNetCore.Http.Features; +using Microsoft.AspNetCore.Protocols; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; @@ -26,15 +29,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure // - Avoid renaming methods or parameters marked with EventAttribute. EventSource uses these to form the event object. [NonEvent] - public void ConnectionStart(IConnectionContext context, IConnectionInformation information) + public void ConnectionStart(FrameConnection connection) { // avoid allocating strings unless this event source is enabled if (IsEnabled()) { ConnectionStart( - context.ConnectionId, - information.LocalEndPoint.ToString(), - information.RemoteEndPoint.ToString()); + connection.ConnectionId, + connection.LocalEndPoint.ToString(), + connection.RemoteEndPoint.ToString()); } } @@ -53,7 +56,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure } [NonEvent] - public void ConnectionStop(IConnectionContext connection) + public void ConnectionStop(FrameConnection connection) { if (IsEnabled()) { diff --git a/src/Kestrel.Core/Internal/RejectionConnection.cs b/src/Kestrel.Core/Internal/RejectionConnection.cs index b14985c499..776a637258 100644 --- a/src/Kestrel.Core/Internal/RejectionConnection.cs +++ b/src/Kestrel.Core/Internal/RejectionConnection.cs @@ -3,12 +3,12 @@ using System; using System.IO.Pipelines; +using Microsoft.AspNetCore.Protocols.Features; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; -using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal { - public class RejectionConnection : IConnectionContext + public class RejectionConnection : IConnectionApplicationFeature { private readonly IKestrelTrace _log; private readonly IPipe _input; @@ -26,6 +26,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal public IPipeWriter Input => _input.Writer; public IPipeReader Output => _output.Reader; + public IPipeConnection Connection { get; set; } + public void Reject() { KestrelEventSource.Log.ConnectionRejected(ConnectionId); @@ -34,13 +36,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal _output.Writer.Complete(); } - // TODO: Remove these (https://github.com/aspnet/KestrelHttpServer/issues/1772) - void IConnectionContext.OnConnectionClosed(Exception ex) + void IConnectionApplicationFeature.OnConnectionClosed(Exception ex) { } - void IConnectionContext.Abort(Exception ex) + void IConnectionApplicationFeature.Abort(Exception ex) { } } -} +} \ No newline at end of file diff --git a/src/Kestrel.Transport.Abstractions/Internal/IConnectionContext.cs b/src/Kestrel.Transport.Abstractions/Internal/IConnectionContext.cs deleted file mode 100644 index 864037e68d..0000000000 --- a/src/Kestrel.Transport.Abstractions/Internal/IConnectionContext.cs +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using System.IO.Pipelines; - -namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal -{ - public interface IConnectionContext - { - string ConnectionId { get; } - IPipeWriter Input { get; } - IPipeReader Output { get; } - - // TODO: Remove these (https://github.com/aspnet/KestrelHttpServer/issues/1772) - void OnConnectionClosed(Exception ex); - void Abort(Exception ex); - } -} diff --git a/src/Kestrel.Transport.Abstractions/Internal/IConnectionHandler.cs b/src/Kestrel.Transport.Abstractions/Internal/IConnectionHandler.cs index f3bf1c6ef3..9ae3f89c3f 100644 --- a/src/Kestrel.Transport.Abstractions/Internal/IConnectionHandler.cs +++ b/src/Kestrel.Transport.Abstractions/Internal/IConnectionHandler.cs @@ -1,10 +1,12 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using Microsoft.AspNetCore.Http.Features; + namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal { public interface IConnectionHandler { - IConnectionContext OnConnection(IConnectionInformation connectionInfo); + void OnConnection(IFeatureCollection features); } } diff --git a/src/Kestrel.Transport.Abstractions/Internal/IConnectionInformation.cs b/src/Kestrel.Transport.Abstractions/Internal/IConnectionInformation.cs deleted file mode 100644 index 4004824002..0000000000 --- a/src/Kestrel.Transport.Abstractions/Internal/IConnectionInformation.cs +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System.IO.Pipelines; -using System.Net; - -namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal -{ - public interface IConnectionInformation - { - IPEndPoint RemoteEndPoint { get; } - IPEndPoint LocalEndPoint { get; } - - PipeFactory PipeFactory { get; } - - IScheduler InputWriterScheduler { get; } - IScheduler OutputReaderScheduler { get; } - } -} diff --git a/src/Kestrel.Transport.Abstractions/Internal/TransportConnection.Features.cs b/src/Kestrel.Transport.Abstractions/Internal/TransportConnection.Features.cs new file mode 100644 index 0000000000..fd5d60050b --- /dev/null +++ b/src/Kestrel.Transport.Abstractions/Internal/TransportConnection.Features.cs @@ -0,0 +1,215 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.IO.Pipelines; +using System.Net; +using System.Text; +using Microsoft.AspNetCore.Http.Features; +using Microsoft.AspNetCore.Protocols.Features; + +namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal +{ + public partial class TransportConnection : IFeatureCollection, + IHttpConnectionFeature, + IConnectionIdFeature, + IConnectionTransportFeature + { + private static readonly Type IHttpConnectionFeatureType = typeof(IHttpConnectionFeature); + private static readonly Type IConnectionIdFeatureType = typeof(IConnectionIdFeature); + private static readonly Type IConnectionTransportFeatureType = typeof(IConnectionTransportFeature); + private static readonly Type IConnectionApplicationFeatureType = typeof(IConnectionApplicationFeature); + + private object _currentIHttpConnectionFeature; + private object _currentIConnectionIdFeature; + private object _currentIConnectionTransportFeature; + private object _currentIConnectionApplicationFeature; + + private int _featureRevision; + + private List> MaybeExtra; + + private object ExtraFeatureGet(Type key) + { + if (MaybeExtra == null) + { + return null; + } + for (var i = 0; i < MaybeExtra.Count; i++) + { + var kv = MaybeExtra[i]; + if (kv.Key == key) + { + return kv.Value; + } + } + return null; + } + + private void ExtraFeatureSet(Type key, object value) + { + if (MaybeExtra == null) + { + MaybeExtra = new List>(2); + } + + for (var i = 0; i < MaybeExtra.Count; i++) + { + if (MaybeExtra[i].Key == key) + { + MaybeExtra[i] = new KeyValuePair(key, value); + return; + } + } + MaybeExtra.Add(new KeyValuePair(key, value)); + } + + bool IFeatureCollection.IsReadOnly => false; + + int IFeatureCollection.Revision => _featureRevision; + + string IHttpConnectionFeature.ConnectionId + { + get => ConnectionId; + set => ConnectionId = value; + } + + IPAddress IHttpConnectionFeature.RemoteIpAddress + { + get => RemoteAddress; + set => RemoteAddress = value; + } + + IPAddress IHttpConnectionFeature.LocalIpAddress + { + get => LocalAddress; + set => LocalAddress = value; + } + + int IHttpConnectionFeature.RemotePort + { + get => RemotePort; + set => RemotePort = value; + } + + int IHttpConnectionFeature.LocalPort + { + get => LocalPort; + set => LocalPort = value; + } + + PipeFactory IConnectionTransportFeature.PipeFactory => PipeFactory; + + IPipeConnection IConnectionTransportFeature.Connection + { + get => Transport; + set => Transport = value; + } + + object IFeatureCollection.this[Type key] + { + get => FastFeatureGet(key); + set => FastFeatureSet(key, value); + } + + TFeature IFeatureCollection.Get() + { + return (TFeature)FastFeatureGet(typeof(TFeature)); + } + + void IFeatureCollection.Set(TFeature instance) + { + FastFeatureSet(typeof(TFeature), instance); + } + + IEnumerator> IEnumerable>.GetEnumerator() => FastEnumerable().GetEnumerator(); + + IEnumerator IEnumerable.GetEnumerator() => FastEnumerable().GetEnumerator(); + + private object FastFeatureGet(Type key) + { + if (key == IHttpConnectionFeatureType) + { + return _currentIHttpConnectionFeature; + } + + if (key == IConnectionIdFeatureType) + { + return _currentIConnectionIdFeature; + } + + if (key == IConnectionTransportFeatureType) + { + return _currentIConnectionTransportFeature; + } + + if (key == IConnectionApplicationFeatureType) + { + return _currentIConnectionApplicationFeature; + } + + return ExtraFeatureGet(key); + } + + private void FastFeatureSet(Type key, object feature) + { + _featureRevision++; + + if (key == IHttpConnectionFeatureType) + { + _currentIHttpConnectionFeature = feature; + return; + } + + if (key == IConnectionIdFeatureType) + { + _currentIConnectionIdFeature = feature; + return; + } + + if (key == IConnectionTransportFeatureType) + { + _currentIConnectionTransportFeature = feature; + return; + } + + if (key == IConnectionApplicationFeatureType) + { + _currentIConnectionApplicationFeature = feature; + return; + } + + ExtraFeatureSet(key, feature); + } + + private IEnumerable> FastEnumerable() + { + if (_currentIHttpConnectionFeature != null) + { + yield return new KeyValuePair(IHttpConnectionFeatureType, _currentIHttpConnectionFeature); + } + + if (_currentIConnectionIdFeature != null) + { + yield return new KeyValuePair(IConnectionIdFeatureType, _currentIConnectionIdFeature); + } + + if (_currentIConnectionTransportFeature != null) + { + yield return new KeyValuePair(IConnectionTransportFeatureType, _currentIConnectionTransportFeature); + } + + if (_currentIConnectionApplicationFeature != null) + { + yield return new KeyValuePair(IConnectionApplicationFeatureType, _currentIConnectionApplicationFeature); + } + + if (MaybeExtra != null) + { + foreach (var item in MaybeExtra) + { + yield return item; + } + } + } + } +} diff --git a/src/Kestrel.Transport.Abstractions/Internal/TransportConnection.cs b/src/Kestrel.Transport.Abstractions/Internal/TransportConnection.cs new file mode 100644 index 0000000000..a499dc8e6a --- /dev/null +++ b/src/Kestrel.Transport.Abstractions/Internal/TransportConnection.cs @@ -0,0 +1,33 @@ +using System; +using System.Collections.Generic; +using System.IO.Pipelines; +using System.Net; +using System.Text; +using Microsoft.AspNetCore.Protocols.Features; + +namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal +{ + public abstract partial class TransportConnection + { + public TransportConnection() + { + _currentIConnectionIdFeature = this; + _currentIConnectionTransportFeature = this; + _currentIHttpConnectionFeature = this; + } + + public IPAddress RemoteAddress { get; set; } + public int RemotePort { get; set; } + public IPAddress LocalAddress { get; set; } + public int LocalPort { get; set; } + + public string ConnectionId { get; set; } + + public virtual PipeFactory PipeFactory { get; } + public virtual IScheduler InputWriterScheduler { get; } + public virtual IScheduler OutputReaderScheduler { get; } + + public IPipeConnection Transport { get; set; } + public IConnectionApplicationFeature Application => (IConnectionApplicationFeature)_currentIConnectionApplicationFeature; + } +} diff --git a/src/Kestrel.Transport.Abstractions/Kestrel.Transport.Abstractions.csproj b/src/Kestrel.Transport.Abstractions/Kestrel.Transport.Abstractions.csproj index 64b219c6c4..3ecaa3a789 100644 --- a/src/Kestrel.Transport.Abstractions/Kestrel.Transport.Abstractions.csproj +++ b/src/Kestrel.Transport.Abstractions/Kestrel.Transport.Abstractions.csproj @@ -16,15 +16,7 @@ - - - - - - - - - + diff --git a/src/Kestrel.Transport.Libuv/Internal/LibuvConnection.cs b/src/Kestrel.Transport.Libuv/Internal/LibuvConnection.cs index 026c0a7fa3..db47620cd8 100644 --- a/src/Kestrel.Transport.Libuv/Internal/LibuvConnection.cs +++ b/src/Kestrel.Transport.Libuv/Internal/LibuvConnection.cs @@ -5,15 +5,16 @@ using System; using System.Buffers; using System.Diagnostics; using System.IO; -using System.Threading.Tasks; using System.IO.Pipelines; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Protocols; using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking; using Microsoft.Extensions.Logging; namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal { - public class LibuvConnection : LibuvConnectionContext + public partial class LibuvConnection : LibuvConnectionContext { private const int MinAllocBufferSize = 2048; @@ -24,7 +25,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal (handle, suggestedsize, state) => AllocCallback(handle, suggestedsize, state); private readonly UvStreamHandle _socket; - private IConnectionContext _connectionContext; private WritableBuffer? _currentWritableBuffer; private BufferHandle _bufferHandle; @@ -35,14 +35,21 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal if (_socket is UvTcpHandle tcpHandle) { - RemoteEndPoint = tcpHandle.GetPeerIPEndPoint(); - LocalEndPoint = tcpHandle.GetSockIPEndPoint(); + var remoteEndPoint = tcpHandle.GetPeerIPEndPoint(); + var localEndPoint = tcpHandle.GetSockIPEndPoint(); + + RemoteAddress = remoteEndPoint.Address; + RemotePort = remoteEndPoint.Port; + + LocalAddress = localEndPoint.Address; + LocalPort = localEndPoint.Port; } } - public string ConnectionId { get; set; } - public IPipeWriter Input { get; set; } - public LibuvOutputConsumer Output { get; set; } + public IPipeWriter Input => Application.Connection.Output; + public IPipeReader Output => Application.Connection.Input; + + public LibuvOutputConsumer OutputConsumer { get; set; } private ILibuvTrace Log => ListenerContext.TransportContext.Log; private IConnectionHandler ConnectionHandler => ListenerContext.TransportContext.ConnectionHandler; @@ -52,11 +59,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal { try { - _connectionContext = ConnectionHandler.OnConnection(this); - ConnectionId = _connectionContext.ConnectionId; + ConnectionHandler.OnConnection(this); - Input = _connectionContext.Input; - Output = new LibuvOutputConsumer(_connectionContext.Output, Thread, _socket, ConnectionId, Log); + OutputConsumer = new LibuvOutputConsumer(Output, Thread, _socket, ConnectionId, Log); StartReading(); @@ -67,7 +72,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal // This *must* happen after socket.ReadStart // The socket output consumer is the only thing that can close the connection. If the // output pipe is already closed by the time we start then it's fine since, it'll close gracefully afterwards. - await Output.WriteOutputAsync(); + await OutputConsumer.WriteOutputAsync(); } catch (UvException ex) { @@ -77,8 +82,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal { // Now, complete the input so that no more reads can happen Input.Complete(error ?? new ConnectionAbortedException()); - _connectionContext.Output.Complete(error); - _connectionContext.OnConnectionClosed(error); + Output.Complete(error); + Application.OnConnectionClosed(error); // Make sure it isn't possible for a paused read to resume reading after calling uv_close // on the stream handle @@ -173,7 +178,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal } } - _connectionContext.Abort(error); + Application.Abort(error); // Complete after aborting the connection Input.Complete(error); } @@ -211,7 +216,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal Log.ConnectionReadFin(ConnectionId); var error = new IOException(ex.Message, ex); - _connectionContext.Abort(error); + Application.Abort(error); Input.Complete(error); } } diff --git a/src/Kestrel.Transport.Libuv/Internal/LibuvConnectionContext.cs b/src/Kestrel.Transport.Libuv/Internal/LibuvConnectionContext.cs index af43c47d3a..fafb3aad57 100644 --- a/src/Kestrel.Transport.Libuv/Internal/LibuvConnectionContext.cs +++ b/src/Kestrel.Transport.Libuv/Internal/LibuvConnectionContext.cs @@ -7,24 +7,17 @@ using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal { - public class LibuvConnectionContext : IConnectionInformation + public class LibuvConnectionContext : TransportConnection { - public LibuvConnectionContext() - { - } - public LibuvConnectionContext(ListenerContext context) { ListenerContext = context; } public ListenerContext ListenerContext { get; set; } - - public IPEndPoint RemoteEndPoint { get; set; } - public IPEndPoint LocalEndPoint { get; set; } - - public PipeFactory PipeFactory => ListenerContext.Thread.PipeFactory; - public IScheduler InputWriterScheduler => ListenerContext.Thread; - public IScheduler OutputReaderScheduler => ListenerContext.Thread; + + public override PipeFactory PipeFactory => ListenerContext.Thread.PipeFactory; + public override IScheduler InputWriterScheduler => ListenerContext.Thread; + public override IScheduler OutputReaderScheduler => ListenerContext.Thread; } } \ No newline at end of file diff --git a/src/Kestrel.Transport.Libuv/LibuvTransport.cs b/src/Kestrel.Transport.Libuv/LibuvTransport.cs index 5948bdc583..f3d376c3f3 100644 --- a/src/Kestrel.Transport.Libuv/LibuvTransport.cs +++ b/src/Kestrel.Transport.Libuv/LibuvTransport.cs @@ -6,6 +6,7 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Protocols; using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal; using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking; diff --git a/src/Kestrel.Transport.Sockets/SocketConnection.cs b/src/Kestrel.Transport.Sockets/SocketConnection.cs index 0070f7af89..86f5df0d4f 100644 --- a/src/Kestrel.Transport.Sockets/SocketConnection.cs +++ b/src/Kestrel.Transport.Sockets/SocketConnection.cs @@ -10,16 +10,15 @@ using System.Net.Sockets; using System.Threading.Tasks; using System.IO.Pipelines; using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; +using Microsoft.AspNetCore.Protocols; namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets { - internal sealed class SocketConnection : IConnectionInformation + internal sealed class SocketConnection : TransportConnection { private readonly Socket _socket; private readonly SocketTransport _transport; - private readonly IPEndPoint _localEndPoint; - private readonly IPEndPoint _remoteEndPoint; - private IConnectionContext _connectionContext; + private IPipeWriter _input; private IPipeReader _output; private IList> _sendBufferList; @@ -33,18 +32,24 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets _socket = socket; _transport = transport; - _localEndPoint = (IPEndPoint)_socket.LocalEndPoint; - _remoteEndPoint = (IPEndPoint)_socket.RemoteEndPoint; + var localEndPoint = (IPEndPoint)_socket.LocalEndPoint; + var remoteEndPoint = (IPEndPoint)_socket.RemoteEndPoint; + + LocalAddress = localEndPoint.Address; + LocalPort = localEndPoint.Port; + + RemoteAddress = remoteEndPoint.Address; + RemotePort = remoteEndPoint.Port; } public async Task StartAsync(IConnectionHandler connectionHandler) { try { - _connectionContext = connectionHandler.OnConnection(this); + connectionHandler.OnConnection(this); - _input = _connectionContext.Input; - _output = _connectionContext.Output; + _input = Application.Connection.Output; + _output = Application.Connection.Input; // Spawn send and receive logic Task receiveTask = DoReceive(); @@ -130,7 +135,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets } finally { - _connectionContext.Abort(error); + Application.Abort(error); _input.Complete(error); } } @@ -224,7 +229,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets } finally { - _connectionContext.OnConnectionClosed(error); + Application.OnConnectionClosed(error); _output.Complete(error); } } @@ -239,14 +244,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets return segment; } - public IPEndPoint RemoteEndPoint => _remoteEndPoint; - - public IPEndPoint LocalEndPoint => _localEndPoint; - - public PipeFactory PipeFactory => _transport.TransportFactory.PipeFactory; - - public IScheduler InputWriterScheduler => InlineScheduler.Default; - - public IScheduler OutputReaderScheduler => TaskRunScheduler.Default; + public override PipeFactory PipeFactory => _transport.TransportFactory.PipeFactory; + public override IScheduler InputWriterScheduler => InlineScheduler.Default; + public override IScheduler OutputReaderScheduler => TaskRunScheduler.Default; } } diff --git a/src/Kestrel.Transport.Sockets/SocketTransport.cs b/src/Kestrel.Transport.Sockets/SocketTransport.cs index fd6d3b57da..83a4cb2909 100644 --- a/src/Kestrel.Transport.Sockets/SocketTransport.cs +++ b/src/Kestrel.Transport.Sockets/SocketTransport.cs @@ -6,6 +6,7 @@ using System.Diagnostics; using System.Net; using System.Net.Sockets; using System.Threading.Tasks; +using Microsoft.AspNetCore.Protocols; using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets diff --git a/src/Protocols.Abstractions/ConnectionContext.cs b/src/Protocols.Abstractions/ConnectionContext.cs new file mode 100644 index 0000000000..ebbcb458a1 --- /dev/null +++ b/src/Protocols.Abstractions/ConnectionContext.cs @@ -0,0 +1,17 @@ +using System; +using System.IO.Pipelines; +using Microsoft.AspNetCore.Http.Features; + +namespace Microsoft.AspNetCore.Protocols +{ + public abstract class ConnectionContext + { + public abstract string ConnectionId { get; set; } + + public abstract IFeatureCollection Features { get; } + + public abstract IPipeConnection Transport { get; set; } + + public abstract PipeFactory PipeFactory { get; } + } +} diff --git a/src/Protocols.Abstractions/ConnectionDelegate.cs b/src/Protocols.Abstractions/ConnectionDelegate.cs new file mode 100644 index 0000000000..a0656c0496 --- /dev/null +++ b/src/Protocols.Abstractions/ConnectionDelegate.cs @@ -0,0 +1,9 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Threading.Tasks; + +namespace Microsoft.AspNetCore.Protocols +{ + public delegate Task ConnectionDelegate(ConnectionContext connection); +} diff --git a/src/Protocols.Abstractions/DefaultConnectionContext.cs b/src/Protocols.Abstractions/DefaultConnectionContext.cs new file mode 100644 index 0000000000..0a759630bf --- /dev/null +++ b/src/Protocols.Abstractions/DefaultConnectionContext.cs @@ -0,0 +1,48 @@ +using System; +using System.Collections.Generic; +using System.IO.Pipelines; +using System.Text; +using Microsoft.AspNetCore.Http.Features; +using Microsoft.AspNetCore.Protocols.Features; + +namespace Microsoft.AspNetCore.Protocols +{ + public class DefaultConnectionContext : ConnectionContext + { + private FeatureReferences _features; + + public DefaultConnectionContext(IFeatureCollection features) + { + _features = new FeatureReferences(features); + } + + private IConnectionIdFeature ConnectionIdFeature => + _features.Fetch(ref _features.Cache.ConnectionId, _ => null); + + private IConnectionTransportFeature ConnectionTransportFeature => + _features.Fetch(ref _features.Cache.ConnectionTransport, _ => null); + + public override string ConnectionId + { + get => ConnectionIdFeature.ConnectionId; + set => ConnectionIdFeature.ConnectionId = value; + } + + public override IFeatureCollection Features => _features.Collection; + + public override PipeFactory PipeFactory => ConnectionTransportFeature.PipeFactory; + + public override IPipeConnection Transport + { + get => ConnectionTransportFeature.Connection; + set => ConnectionTransportFeature.Connection = value; + } + + struct FeatureInterfaces + { + public IConnectionIdFeature ConnectionId; + + public IConnectionTransportFeature ConnectionTransport; + } + } +} diff --git a/src/Kestrel.Transport.Abstractions/Exceptions/AddressInUseException.cs b/src/Protocols.Abstractions/Exceptions/AddressInUseException.cs similarity index 85% rename from src/Kestrel.Transport.Abstractions/Exceptions/AddressInUseException.cs rename to src/Protocols.Abstractions/Exceptions/AddressInUseException.cs index 72e1a5d774..3a0dddc671 100644 --- a/src/Kestrel.Transport.Abstractions/Exceptions/AddressInUseException.cs +++ b/src/Protocols.Abstractions/Exceptions/AddressInUseException.cs @@ -3,7 +3,7 @@ using System; -namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal +namespace Microsoft.AspNetCore.Protocols { public class AddressInUseException : InvalidOperationException { diff --git a/src/Kestrel.Transport.Abstractions/Exceptions/ConnectionAbortedException.cs b/src/Protocols.Abstractions/Exceptions/ConnectionAbortedException.cs similarity index 84% rename from src/Kestrel.Transport.Abstractions/Exceptions/ConnectionAbortedException.cs rename to src/Protocols.Abstractions/Exceptions/ConnectionAbortedException.cs index 817d9f9226..b1119b9c2e 100644 --- a/src/Kestrel.Transport.Abstractions/Exceptions/ConnectionAbortedException.cs +++ b/src/Protocols.Abstractions/Exceptions/ConnectionAbortedException.cs @@ -1,6 +1,6 @@ using System; -namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal +namespace Microsoft.AspNetCore.Protocols { public class ConnectionAbortedException : OperationCanceledException { diff --git a/src/Kestrel.Transport.Abstractions/Exceptions/ConnectionResetException.cs b/src/Protocols.Abstractions/Exceptions/ConnectionResetException.cs similarity index 86% rename from src/Kestrel.Transport.Abstractions/Exceptions/ConnectionResetException.cs rename to src/Protocols.Abstractions/Exceptions/ConnectionResetException.cs index 1e0bef192d..a19379628c 100644 --- a/src/Kestrel.Transport.Abstractions/Exceptions/ConnectionResetException.cs +++ b/src/Protocols.Abstractions/Exceptions/ConnectionResetException.cs @@ -4,7 +4,7 @@ using System; using System.IO; -namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal +namespace Microsoft.AspNetCore.Protocols { public class ConnectionResetException : IOException { diff --git a/src/Protocols.Abstractions/Features/IConnectionApplicationFeature.cs b/src/Protocols.Abstractions/Features/IConnectionApplicationFeature.cs new file mode 100644 index 0000000000..a610cd06d6 --- /dev/null +++ b/src/Protocols.Abstractions/Features/IConnectionApplicationFeature.cs @@ -0,0 +1,18 @@ +using System; +using System.IO.Pipelines; + +namespace Microsoft.AspNetCore.Protocols.Features +{ + public interface IConnectionApplicationFeature + { + IPipeConnection Connection { get; set; } + + // TODO: Remove these (https://github.com/aspnet/KestrelHttpServer/issues/1772) + // REVIEW: These are around for now because handling pipe events messes with the order + // of operations an that breaks tons of tests. Instead, we preserve the existing semantics + // and ordering. + void Abort(Exception exception); + + void OnConnectionClosed(Exception exception); + } +} diff --git a/src/Protocols.Abstractions/Features/IConnectionIdFeature.cs b/src/Protocols.Abstractions/Features/IConnectionIdFeature.cs new file mode 100644 index 0000000000..1b94c5b4cc --- /dev/null +++ b/src/Protocols.Abstractions/Features/IConnectionIdFeature.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Microsoft.AspNetCore.Protocols.Features +{ + public interface IConnectionIdFeature + { + string ConnectionId { get; set; } + } +} diff --git a/src/Protocols.Abstractions/Features/IConnectionTransportFeature.cs b/src/Protocols.Abstractions/Features/IConnectionTransportFeature.cs new file mode 100644 index 0000000000..463797265e --- /dev/null +++ b/src/Protocols.Abstractions/Features/IConnectionTransportFeature.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.IO.Pipelines; +using System.Text; + +namespace Microsoft.AspNetCore.Protocols.Features +{ + public interface IConnectionTransportFeature + { + PipeFactory PipeFactory { get; } + + IPipeConnection Connection { get; set; } + + IScheduler InputWriterScheduler { get; } + + IScheduler OutputReaderScheduler { get; } + } +} diff --git a/src/Protocols.Abstractions/IConnectionBuilder.cs b/src/Protocols.Abstractions/IConnectionBuilder.cs new file mode 100644 index 0000000000..7f75d27643 --- /dev/null +++ b/src/Protocols.Abstractions/IConnectionBuilder.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Microsoft.AspNetCore.Protocols +{ + public interface IConnectionBuilder + { + IServiceProvider ApplicationServices { get; } + + IConnectionBuilder Use(Func middleware); + + ConnectionDelegate Build(); + } +} diff --git a/src/Protocols.Abstractions/PipeConnection.cs b/src/Protocols.Abstractions/PipeConnection.cs new file mode 100644 index 0000000000..31b3a7a74c --- /dev/null +++ b/src/Protocols.Abstractions/PipeConnection.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace System.IO.Pipelines +{ + public class PipeConnection : IPipeConnection + { + public PipeConnection(IPipeReader reader, IPipeWriter writer) + { + Input = reader; + Output = writer; + } + + public IPipeReader Input { get; } + + public IPipeWriter Output { get; } + + public void Dispose() + { + } + } +} diff --git a/src/Protocols.Abstractions/Protocols.Abstractions.csproj b/src/Protocols.Abstractions/Protocols.Abstractions.csproj new file mode 100644 index 0000000000..233f0c3a2b --- /dev/null +++ b/src/Protocols.Abstractions/Protocols.Abstractions.csproj @@ -0,0 +1,30 @@ + + + + + Microsoft.AspNetCore.Protocols.Abstractions + Microsoft.AspNetCore.Protocols.Abstractions + Core components of ASP.NET Core networking protocol stack. + netstandard2.0 + true + aspnetcore + true + CS1591;$(NoWarn) + false + + CurrentRuntime + + + + + + + + + + + + + + + diff --git a/test/Kestrel.Core.Tests/AddressBinderTests.cs b/test/Kestrel.Core.Tests/AddressBinderTests.cs index 27c6d8c082..2c957e6030 100644 --- a/test/Kestrel.Core.Tests/AddressBinderTests.cs +++ b/test/Kestrel.Core.Tests/AddressBinderTests.cs @@ -6,6 +6,7 @@ using System.Collections.Generic; using System.IO; using System.Net; using System.Threading.Tasks; +using Microsoft.AspNetCore.Protocols; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal; using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; using Microsoft.AspNetCore.Testing; diff --git a/test/Kestrel.Core.Tests/FrameConnectionTests.cs b/test/Kestrel.Core.Tests/FrameConnectionTests.cs index 555838c820..5b7afe2176 100644 --- a/test/Kestrel.Core.Tests/FrameConnectionTests.cs +++ b/test/Kestrel.Core.Tests/FrameConnectionTests.cs @@ -30,10 +30,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests { ConnectionId = "0123456789", ConnectionAdapters = new List(), - ConnectionInformation = new MockConnectionInformation - { - PipeFactory = _pipeFactory - }, + PipeFactory = _pipeFactory, FrameConnectionId = long.MinValue, Input = _pipeFactory.Create(), Output = _pipeFactory.Create(), diff --git a/test/Kestrel.Core.Tests/FrameResponseHeadersTests.cs b/test/Kestrel.Core.Tests/FrameResponseHeadersTests.cs index dabf1d85ee..8cd807bc18 100644 --- a/test/Kestrel.Core.Tests/FrameResponseHeadersTests.cs +++ b/test/Kestrel.Core.Tests/FrameResponseHeadersTests.cs @@ -21,10 +21,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests var frameContext = new FrameContext { ServiceContext = new TestServiceContext(), - ConnectionInformation = new MockConnectionInformation - { - PipeFactory = new PipeFactory() - }, + PipeFactory = new PipeFactory(), TimeoutControl = null }; diff --git a/test/Kestrel.Core.Tests/FrameTests.cs b/test/Kestrel.Core.Tests/FrameTests.cs index 081861975d..0f2682fcf6 100644 --- a/test/Kestrel.Core.Tests/FrameTests.cs +++ b/test/Kestrel.Core.Tests/FrameTests.cs @@ -60,10 +60,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests _frameContext = new FrameContext { ServiceContext = _serviceContext, - ConnectionInformation = new MockConnectionInformation - { - PipeFactory = _pipelineFactory - }, + PipeFactory = _pipelineFactory, TimeoutControl = _timeoutControl.Object, Input = _input.Reader, Output = output diff --git a/test/Kestrel.Core.Tests/TestInput.cs b/test/Kestrel.Core.Tests/TestInput.cs index ccd07a034a..018dcb1117 100644 --- a/test/Kestrel.Core.Tests/TestInput.cs +++ b/test/Kestrel.Core.Tests/TestInput.cs @@ -26,10 +26,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests { ServiceContext = new TestServiceContext(), Input = Pipe.Reader, - ConnectionInformation = new MockConnectionInformation - { - PipeFactory = _pipelineFactory - }, + PipeFactory = _pipelineFactory, TimeoutControl = Mock.Of() }; diff --git a/test/Kestrel.FunctionalTests/RequestTests.cs b/test/Kestrel.FunctionalTests/RequestTests.cs index 8d8f997b03..7cf85fa7ce 100644 --- a/test/Kestrel.FunctionalTests/RequestTests.cs +++ b/test/Kestrel.FunctionalTests/RequestTests.cs @@ -16,6 +16,7 @@ using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http.Features; +using Microsoft.AspNetCore.Protocols; using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.AspNetCore.Server.Kestrel.Core.Features; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; diff --git a/test/Kestrel.Performance/FrameFeatureCollection.cs b/test/Kestrel.Performance/FrameFeatureCollection.cs index 6f1ee3d2bf..ca85ab5aca 100644 --- a/test/Kestrel.Performance/FrameFeatureCollection.cs +++ b/test/Kestrel.Performance/FrameFeatureCollection.cs @@ -62,7 +62,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance [Benchmark] public IHttpSendFileFeature GetLastViaGeneric() { - return _collection.Get (); + return _collection.Get(); } private object Get(Type type) @@ -85,10 +85,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance var frameContext = new FrameContext { ServiceContext = serviceContext, - ConnectionInformation = new MockConnectionInformation - { - PipeFactory = new PipeFactory() - } + PipeFactory = new PipeFactory() }; _frame = new Frame(application: null, frameContext: frameContext); diff --git a/test/Kestrel.Performance/FrameParsingOverheadBenchmark.cs b/test/Kestrel.Performance/FrameParsingOverheadBenchmark.cs index d570ee1f8d..ab6259e04a 100644 --- a/test/Kestrel.Performance/FrameParsingOverheadBenchmark.cs +++ b/test/Kestrel.Performance/FrameParsingOverheadBenchmark.cs @@ -29,10 +29,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance var frameContext = new FrameContext { ServiceContext = serviceContext, - ConnectionInformation = new MockConnectionInformation - { - PipeFactory = new PipeFactory() - }, + PipeFactory = new PipeFactory(), TimeoutControl = new MockTimeoutControl() }; diff --git a/test/Kestrel.Performance/FrameWritingBenchmark.cs b/test/Kestrel.Performance/FrameWritingBenchmark.cs index 664aebe15c..940b5d2f8c 100644 --- a/test/Kestrel.Performance/FrameWritingBenchmark.cs +++ b/test/Kestrel.Performance/FrameWritingBenchmark.cs @@ -90,10 +90,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance var frame = new TestFrame(application: null, context: new FrameContext { ServiceContext = serviceContext, - ConnectionInformation = new MockConnectionInformation - { - PipeFactory = pipeFactory - }, + PipeFactory = pipeFactory, Input = input.Reader, Output = output }); diff --git a/test/Kestrel.Performance/Mocks/MockConnectionInformation.cs b/test/Kestrel.Performance/Mocks/MockConnectionInformation.cs deleted file mode 100644 index 2f01186143..0000000000 --- a/test/Kestrel.Performance/Mocks/MockConnectionInformation.cs +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System.Net; -using System.IO.Pipelines; -using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; - -namespace Microsoft.AspNetCore.Server.Kestrel.Performance -{ - public class MockConnectionInformation : IConnectionInformation - { - public IPEndPoint RemoteEndPoint { get; } - public IPEndPoint LocalEndPoint { get; } - - public PipeFactory PipeFactory { get; set; } - public bool RequiresDispatch { get; } - public IScheduler InputWriterScheduler { get; } - public IScheduler OutputReaderScheduler { get; } - } -} diff --git a/test/Kestrel.Performance/RequestParsingBenchmark.cs b/test/Kestrel.Performance/RequestParsingBenchmark.cs index f155b2a86d..06f3dac080 100644 --- a/test/Kestrel.Performance/RequestParsingBenchmark.cs +++ b/test/Kestrel.Performance/RequestParsingBenchmark.cs @@ -33,10 +33,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance var frameContext = new FrameContext { ServiceContext = serviceContext, - ConnectionInformation = new MockConnectionInformation - { - PipeFactory = PipeFactory - }, + PipeFactory = PipeFactory, TimeoutControl = new MockTimeoutControl() }; diff --git a/test/Kestrel.Performance/ResponseHeaderCollectionBenchmark.cs b/test/Kestrel.Performance/ResponseHeaderCollectionBenchmark.cs index 8423f95c02..57d9b53f70 100644 --- a/test/Kestrel.Performance/ResponseHeaderCollectionBenchmark.cs +++ b/test/Kestrel.Performance/ResponseHeaderCollectionBenchmark.cs @@ -177,10 +177,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance var frameContext = new FrameContext { ServiceContext = serviceContext, - ConnectionInformation = new MockConnectionInformation - { - PipeFactory = new PipeFactory() - } + PipeFactory = new PipeFactory() }; var frame = new Frame(application: null, frameContext: frameContext); diff --git a/test/Kestrel.Performance/ResponseHeadersWritingBenchmark.cs b/test/Kestrel.Performance/ResponseHeadersWritingBenchmark.cs index 85929d7211..abef01feb0 100644 --- a/test/Kestrel.Performance/ResponseHeadersWritingBenchmark.cs +++ b/test/Kestrel.Performance/ResponseHeadersWritingBenchmark.cs @@ -124,10 +124,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance var frame = new TestFrame(application: null, context: new FrameContext { ServiceContext = serviceContext, - ConnectionInformation = new MockConnectionInformation - { - PipeFactory = pipeFactory - }, + PipeFactory = pipeFactory, TimeoutControl = new MockTimeoutControl(), Input = input.Reader, Output = output diff --git a/test/Kestrel.Transport.Libuv.Tests/LibuvOutputConsumerTests.cs b/test/Kestrel.Transport.Libuv.Tests/LibuvOutputConsumerTests.cs index 973b0e387c..5bf0ff1b3a 100644 --- a/test/Kestrel.Transport.Libuv.Tests/LibuvOutputConsumerTests.cs +++ b/test/Kestrel.Transport.Libuv.Tests/LibuvOutputConsumerTests.cs @@ -699,10 +699,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests var frame = new Frame(null, new FrameContext { ServiceContext = serviceContext, - ConnectionInformation = new MockConnectionInformation - { - PipeFactory = _pipeFactory - }, + PipeFactory = _pipeFactory, TimeoutControl = Mock.Of(), Output = pipe }); diff --git a/test/Kestrel.Transport.Libuv.Tests/TestHelpers/MockConnectionHandler.cs b/test/Kestrel.Transport.Libuv.Tests/TestHelpers/MockConnectionHandler.cs index a8096d7181..5b3480b0e6 100644 --- a/test/Kestrel.Transport.Libuv.Tests/TestHelpers/MockConnectionHandler.cs +++ b/test/Kestrel.Transport.Libuv.Tests/TestHelpers/MockConnectionHandler.cs @@ -3,6 +3,9 @@ using System; using System.IO.Pipelines; +using Microsoft.AspNetCore.Http.Features; +using Microsoft.AspNetCore.Protocols; +using Microsoft.AspNetCore.Protocols.Features; using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests.TestHelpers @@ -12,26 +15,28 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests.TestHelpers public PipeOptions InputOptions { get; set; } = new PipeOptions(); public PipeOptions OutputOptions { get; set; } = new PipeOptions(); - public IConnectionContext OnConnection(IConnectionInformation connectionInfo) + public void OnConnection(IFeatureCollection features) { - Input = connectionInfo.PipeFactory.Create(InputOptions ?? new PipeOptions()); - Output = connectionInfo.PipeFactory.Create(OutputOptions ?? new PipeOptions()); + var connectionContext = new DefaultConnectionContext(features); - return new TestConnectionContext + Input = connectionContext.PipeFactory.Create(InputOptions ?? new PipeOptions()); + Output = connectionContext.PipeFactory.Create(OutputOptions ?? new PipeOptions()); + + var context = new TestConnectionContext { - Input = Input.Writer, - Output = Output.Reader, + Connection = new PipeConnection(Output.Reader, Input.Writer) }; + + connectionContext.Features.Set(context); } public IPipe Input { get; private set; } public IPipe Output { get; private set; } - - private class TestConnectionContext : IConnectionContext + + private class TestConnectionContext : IConnectionApplicationFeature { public string ConnectionId { get; } - public IPipeWriter Input { get; set; } - public IPipeReader Output { get; set; } + public IPipeConnection Connection { get; set; } public void Abort(Exception ex) { diff --git a/test/shared/MockConnectionInformation.cs b/test/shared/MockConnectionInformation.cs deleted file mode 100644 index db6ee00fda..0000000000 --- a/test/shared/MockConnectionInformation.cs +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System.IO.Pipelines; -using System.Net; -using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; - -namespace Microsoft.AspNetCore.Testing -{ - public class MockConnectionInformation : IConnectionInformation - { - public IPEndPoint RemoteEndPoint { get; } - - public IPEndPoint LocalEndPoint { get; } - - public PipeFactory PipeFactory { get; set; } - - public IScheduler InputWriterScheduler { get; } - - public IScheduler OutputReaderScheduler { get; } - } -} From c10ac85cf2cf510f2d6ad6b3f41a446339f8e76e Mon Sep 17 00:00:00 2001 From: Nate McMaster Date: Wed, 16 Aug 2017 09:37:49 -0700 Subject: [PATCH 1375/1662] Add fixes for problems discovered by xunit.analyzers (#1999) * Add fixes to tests for problems discovered by xunit.analyzers 0.6.1 * PR feedback. Add comments about why we have a #pragma --- test/Kestrel.Core.Tests/FrameConnectionTests.cs | 2 +- test/Kestrel.Core.Tests/FrameTests.cs | 4 ++++ test/Kestrel.Core.Tests/HttpParserTests.cs | 6 +++++- test/Kestrel.Core.Tests/HttpUtilitiesTest.cs | 5 +++-- test/Kestrel.FunctionalTests/HttpsConnectionAdapterTests.cs | 2 +- test/Kestrel.FunctionalTests/RequestTests.cs | 5 ++--- 6 files changed, 16 insertions(+), 8 deletions(-) diff --git a/test/Kestrel.Core.Tests/FrameConnectionTests.cs b/test/Kestrel.Core.Tests/FrameConnectionTests.cs index 5b7afe2176..0304ce3f7f 100644 --- a/test/Kestrel.Core.Tests/FrameConnectionTests.cs +++ b/test/Kestrel.Core.Tests/FrameConnectionTests.cs @@ -543,7 +543,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests await _frameConnection.StopAsync().TimeoutAfter(TimeSpan.FromSeconds(5)); - Assert.Equal(1, scopeObjects.Count); + Assert.Single(scopeObjects); var pairs = scopeObjects[0].ToDictionary(p => p.Key, p => p.Value); Assert.True(pairs.ContainsKey("ConnectionId")); Assert.Equal(_frameConnection.ConnectionId, pairs["ConnectionId"]); diff --git a/test/Kestrel.Core.Tests/FrameTests.cs b/test/Kestrel.Core.Tests/FrameTests.cs index 0f2682fcf6..d6a1c76637 100644 --- a/test/Kestrel.Core.Tests/FrameTests.cs +++ b/test/Kestrel.Core.Tests/FrameTests.cs @@ -332,7 +332,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests string requestLine, string expectedMethod, string expectedRawTarget, +// This warns that theory methods should use all of their parameters, +// but this method is using a shared data collection with HttpParserTests.ParsesRequestLine and others. +#pragma warning disable xUnit1026 string expectedRawPath, +#pragma warning restore xUnit1026 string expectedDecodedPath, string expectedQueryString, string expectedHttpVersion) diff --git a/test/Kestrel.Core.Tests/HttpParserTests.cs b/test/Kestrel.Core.Tests/HttpParserTests.cs index d79c5c3ea2..2113d756ea 100644 --- a/test/Kestrel.Core.Tests/HttpParserTests.cs +++ b/test/Kestrel.Core.Tests/HttpParserTests.cs @@ -26,8 +26,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests string expectedMethod, string expectedRawTarget, string expectedRawPath, +// This warns that theory methods should use all of their parameters, +// but this method is using a shared data collection with FrameTests.TakeStartLineSetsFrameProperties and others. +#pragma warning disable xUnit1026 string expectedDecodedPath, string expectedQueryString, +#pragma warning restore xUnit1026 string expectedVersion) { var parser = CreateParser(Mock.Of()); @@ -391,7 +395,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests parser.ParseHeaders(requestHandler, buffer, out var consumed, out var examined, out var consumedBytes); var pairs = requestHandler.Headers.ToArray(); - Assert.Equal(1, pairs.Length); + Assert.Single(pairs); Assert.Equal(headerName, pairs[0].Key); Assert.Equal(expectedHeaderValue, pairs[0].Value); Assert.Equal(buffer.End, consumed); diff --git a/test/Kestrel.Core.Tests/HttpUtilitiesTest.cs b/test/Kestrel.Core.Tests/HttpUtilitiesTest.cs index af012742cb..8966c181b0 100644 --- a/test/Kestrel.Core.Tests/HttpUtilitiesTest.cs +++ b/test/Kestrel.Core.Tests/HttpUtilitiesTest.cs @@ -64,14 +64,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests var block = new Span(Encoding.ASCII.GetBytes(input)); // Act - HttpVersion knownVersion; - var result = block.GetKnownVersion(out knownVersion, out var length); + var result = block.GetKnownVersion(out HttpVersion knownVersion, out var length); string toString = null; if (knownVersion != HttpVersion.Unknown) { toString = HttpUtilities.VersionToString(knownVersion); } + // Assert + Assert.Equal(version, knownVersion); Assert.Equal(expectedResult, result); Assert.Equal(expectedKnownString, toString); Assert.Equal(expectedKnownString?.Length ?? 0, length); diff --git a/test/Kestrel.FunctionalTests/HttpsConnectionAdapterTests.cs b/test/Kestrel.FunctionalTests/HttpsConnectionAdapterTests.cs index 5ef04a4392..ebf6081761 100644 --- a/test/Kestrel.FunctionalTests/HttpsConnectionAdapterTests.cs +++ b/test/Kestrel.FunctionalTests/HttpsConnectionAdapterTests.cs @@ -232,7 +232,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests using (var client = new TcpClient()) { var stream = await OpenSslStream(client, server); - var ex = await Assert.ThrowsAsync(typeof(IOException), + var ex = await Assert.ThrowsAsync( async () => await stream.AuthenticateAsClientAsync("localhost", new X509CertificateCollection(), SslProtocols.Tls, false)); } } diff --git a/test/Kestrel.FunctionalTests/RequestTests.cs b/test/Kestrel.FunctionalTests/RequestTests.cs index 7cf85fa7ce..0177877722 100644 --- a/test/Kestrel.FunctionalTests/RequestTests.cs +++ b/test/Kestrel.FunctionalTests/RequestTests.cs @@ -1184,9 +1184,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } } - [Theory] - [MemberData(nameof(ConnectionAdapterData))] - public async Task HeadersAndStreamsAreReusedAcrossRequests(ListenOptions listenOptions) + [Fact] + public async Task HeadersAndStreamsAreReusedAcrossRequests() { var testContext = new TestServiceContext(); var streamCount = 0; From 0fafd19ec9ac6fa04718e82c1fd418dd76406a30 Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Wed, 16 Aug 2017 10:04:44 -0700 Subject: [PATCH 1376/1662] Initial HTTP/2 support. What works: - HTTP/2 over TLS1.2 with ALPN - Request and response flow - Headers are compressed and decompressed with HPACK - Request body can be read by streams (if present) - MVC template app with individual auth works fine - PRIORITY frames are validated - RST_STREAM frames are validated and abort streams - SETTINGS frames are validated and ACKed - PING frames are validated and ACKed - GOAWAY frames stop connections - WINDOW_UPDATE frames are validated - CONTINUATION frames are sent for large header blocks What doesn't work yet: - Flow control in either direction - It's not possible to encode a single header across more than one frame - Affects only a very large header (name and value combined ~16KB long) - Request trailers - Response trailers - Limits and timeouts in `KestrelServerLimits` are not enforced on HTTP/2 - HPACK use is very limited on the send side - Literals are not Huffman-encoded - Common headers (e.g. "server: Kestrel") are never indexed - Honoring client settings - Some error checking is still missing (e.g. validating incoming frame size) --- .vscode/launch.json | 24 + KestrelHttpServer.sln | 17 +- .../Adapter/Internal/AdaptedPipeline.cs | 2 +- .../Adapter/Internal/RawStream.cs | 2 +- .../Features/IHttp2StreamIdFeature.cs | 10 + .../ITlsApplicationProtocolFeature.cs | 11 + src/Kestrel.Core/Internal/FrameConnection.cs | 61 +- .../Internal/Http/FrameRequestStream.cs | 4 +- .../Internal/Http/IMessageBody.cs | 17 + src/Kestrel.Core/Internal/Http/MessageBody.cs | 2 +- .../Internal/Http/RequestRejectionReason.cs | 1 + .../Internal/Http2/HPack/DynamicTable.cs | 72 + .../Internal/Http2/HPack/HPackDecoder.cs | 277 +++ .../Internal/Http2/HPack/HPackEncoder.cs | 154 ++ .../Internal/Http2/HPack/HeaderField.cs | 17 + .../Internal/Http2/HPack/Huffman.cs | 363 ++++ .../Internal/Http2/HPack/IntegerDecoder.cs | 45 + .../Internal/Http2/HPack/IntegerEncoder.cs | 59 + .../Internal/Http2/HPack/StaticTable.cs | 101 ++ .../Internal/Http2/HPack/StatusCodes.cs | 222 +++ .../Internal/Http2/Http2Connection.cs | 498 ++++++ .../Internal/Http2/Http2ConnectionContext.cs | 20 + .../Http2/Http2ConnectionErrorException.cs | 18 + .../Http2/Http2ContinuationFrameFlags.cs | 14 + .../Internal/Http2/Http2DataFrameFlags.cs | 15 + .../Internal/Http2/Http2ErrorCode.cs | 25 + .../Internal/Http2/Http2Frame.Continuation.cs | 24 + .../Internal/Http2/Http2Frame.Data.cs | 44 + .../Internal/Http2/Http2Frame.GoAway.cs | 42 + .../Internal/Http2/Http2Frame.Headers.cs | 72 + .../Internal/Http2/Http2Frame.Ping.cs | 24 + .../Internal/Http2/Http2Frame.Priority.cs | 57 + .../Internal/Http2/Http2Frame.RstStream.cs | 29 + .../Internal/Http2/Http2Frame.Settings.cs | 42 + .../Internal/Http2/Http2Frame.WindowUpdate.cs | 29 + src/Kestrel.Core/Internal/Http2/Http2Frame.cs | 70 + .../Internal/Http2/Http2FrameReader.cs | 34 + .../Internal/Http2/Http2FrameType.cs | 19 + .../Internal/Http2/Http2FrameWriter.cs | 192 +++ .../Internal/Http2/Http2HeadersFrameFlags.cs | 17 + .../Internal/Http2/Http2MessageBody.cs | 262 +++ .../Internal/Http2/Http2PeerSetting.cs | 18 + .../Internal/Http2/Http2PeerSettings.cs | 106 ++ .../Internal/Http2/Http2PingFrameFlags.cs | 14 + .../Internal/Http2/Http2SettingsFrameFlags.cs | 14 + .../Internal/Http2/Http2SettingsParameter.cs | 15 + ...tp2SettingsParameterOutOfRangeException.cs | 18 + .../Http2/Http2Stream.FeatureCollection.cs | 289 ++++ .../Internal/Http2/Http2Stream.Generated.cs | 378 ++++ .../Internal/Http2/Http2Stream.cs | 1031 +++++++++++ .../Internal/Http2/Http2StreamContext.cs | 20 + .../Internal/Http2/Http2StreamOfT.cs | 172 ++ .../Internal/Http2/Http2Streams.cs | 48 + .../Internal/Http2/IHttp2FrameWriter.cs | 24 + .../Http2/IHttp2StreamLifetimeHandler.cs | 10 + src/Kestrel.Tls/ClosedStream.cs | 68 + src/Kestrel.Tls/Kestrel.Tls.csproj | 26 + src/Kestrel.Tls/ListenOptionsTlsExtensions.cs | 29 + src/Kestrel.Tls/OpenSsl.cs | 268 +++ src/Kestrel.Tls/Properties/AssemblyInfo.cs | 6 + src/Kestrel.Tls/README.md | 5 + .../TlsApplicationProtocolFeature.cs | 17 + src/Kestrel.Tls/TlsConnectionAdapter.cs | 109 ++ .../TlsConnectionAdapterOptions.cs | 12 + src/Kestrel.Tls/TlsConnectionFeature.cs | 21 + src/Kestrel.Tls/TlsStream.cs | 231 +++ .../Internal/LibuvConnectionContext.cs | 2 +- .../FrameConnectionTests.cs | 2 +- test/Kestrel.Core.Tests/HPackEncoderTests.cs | 130 ++ .../Http2ConnectionTests.cs | 1520 +++++++++++++++++ test/Kestrel.Core.Tests/HuffmanTests.cs | 329 ++++ .../Kestrel.Core.Tests/IntegerDecoderTests.cs | 52 + .../Kestrel.Core.Tests/IntegerEncoderTests.cs | 37 + .../GeneratedCodeTests.cs | 8 +- tools/CodeGenerator/CodeGenerator.csproj | 2 +- tools/CodeGenerator/FrameFeatureCollection.cs | 12 +- tools/CodeGenerator/Program.cs | 20 +- 77 files changed, 8039 insertions(+), 32 deletions(-) create mode 100644 src/Kestrel.Core/Features/IHttp2StreamIdFeature.cs create mode 100644 src/Kestrel.Core/Features/ITlsApplicationProtocolFeature.cs create mode 100644 src/Kestrel.Core/Internal/Http/IMessageBody.cs create mode 100644 src/Kestrel.Core/Internal/Http2/HPack/DynamicTable.cs create mode 100644 src/Kestrel.Core/Internal/Http2/HPack/HPackDecoder.cs create mode 100644 src/Kestrel.Core/Internal/Http2/HPack/HPackEncoder.cs create mode 100644 src/Kestrel.Core/Internal/Http2/HPack/HeaderField.cs create mode 100644 src/Kestrel.Core/Internal/Http2/HPack/Huffman.cs create mode 100644 src/Kestrel.Core/Internal/Http2/HPack/IntegerDecoder.cs create mode 100644 src/Kestrel.Core/Internal/Http2/HPack/IntegerEncoder.cs create mode 100644 src/Kestrel.Core/Internal/Http2/HPack/StaticTable.cs create mode 100644 src/Kestrel.Core/Internal/Http2/HPack/StatusCodes.cs create mode 100644 src/Kestrel.Core/Internal/Http2/Http2Connection.cs create mode 100644 src/Kestrel.Core/Internal/Http2/Http2ConnectionContext.cs create mode 100644 src/Kestrel.Core/Internal/Http2/Http2ConnectionErrorException.cs create mode 100644 src/Kestrel.Core/Internal/Http2/Http2ContinuationFrameFlags.cs create mode 100644 src/Kestrel.Core/Internal/Http2/Http2DataFrameFlags.cs create mode 100644 src/Kestrel.Core/Internal/Http2/Http2ErrorCode.cs create mode 100644 src/Kestrel.Core/Internal/Http2/Http2Frame.Continuation.cs create mode 100644 src/Kestrel.Core/Internal/Http2/Http2Frame.Data.cs create mode 100644 src/Kestrel.Core/Internal/Http2/Http2Frame.GoAway.cs create mode 100644 src/Kestrel.Core/Internal/Http2/Http2Frame.Headers.cs create mode 100644 src/Kestrel.Core/Internal/Http2/Http2Frame.Ping.cs create mode 100644 src/Kestrel.Core/Internal/Http2/Http2Frame.Priority.cs create mode 100644 src/Kestrel.Core/Internal/Http2/Http2Frame.RstStream.cs create mode 100644 src/Kestrel.Core/Internal/Http2/Http2Frame.Settings.cs create mode 100644 src/Kestrel.Core/Internal/Http2/Http2Frame.WindowUpdate.cs create mode 100644 src/Kestrel.Core/Internal/Http2/Http2Frame.cs create mode 100644 src/Kestrel.Core/Internal/Http2/Http2FrameReader.cs create mode 100644 src/Kestrel.Core/Internal/Http2/Http2FrameType.cs create mode 100644 src/Kestrel.Core/Internal/Http2/Http2FrameWriter.cs create mode 100644 src/Kestrel.Core/Internal/Http2/Http2HeadersFrameFlags.cs create mode 100644 src/Kestrel.Core/Internal/Http2/Http2MessageBody.cs create mode 100644 src/Kestrel.Core/Internal/Http2/Http2PeerSetting.cs create mode 100644 src/Kestrel.Core/Internal/Http2/Http2PeerSettings.cs create mode 100644 src/Kestrel.Core/Internal/Http2/Http2PingFrameFlags.cs create mode 100644 src/Kestrel.Core/Internal/Http2/Http2SettingsFrameFlags.cs create mode 100644 src/Kestrel.Core/Internal/Http2/Http2SettingsParameter.cs create mode 100644 src/Kestrel.Core/Internal/Http2/Http2SettingsParameterOutOfRangeException.cs create mode 100644 src/Kestrel.Core/Internal/Http2/Http2Stream.FeatureCollection.cs create mode 100644 src/Kestrel.Core/Internal/Http2/Http2Stream.Generated.cs create mode 100644 src/Kestrel.Core/Internal/Http2/Http2Stream.cs create mode 100644 src/Kestrel.Core/Internal/Http2/Http2StreamContext.cs create mode 100644 src/Kestrel.Core/Internal/Http2/Http2StreamOfT.cs create mode 100644 src/Kestrel.Core/Internal/Http2/Http2Streams.cs create mode 100644 src/Kestrel.Core/Internal/Http2/IHttp2FrameWriter.cs create mode 100644 src/Kestrel.Core/Internal/Http2/IHttp2StreamLifetimeHandler.cs create mode 100644 src/Kestrel.Tls/ClosedStream.cs create mode 100644 src/Kestrel.Tls/Kestrel.Tls.csproj create mode 100644 src/Kestrel.Tls/ListenOptionsTlsExtensions.cs create mode 100644 src/Kestrel.Tls/OpenSsl.cs create mode 100644 src/Kestrel.Tls/Properties/AssemblyInfo.cs create mode 100644 src/Kestrel.Tls/README.md create mode 100644 src/Kestrel.Tls/TlsApplicationProtocolFeature.cs create mode 100644 src/Kestrel.Tls/TlsConnectionAdapter.cs create mode 100644 src/Kestrel.Tls/TlsConnectionAdapterOptions.cs create mode 100644 src/Kestrel.Tls/TlsConnectionFeature.cs create mode 100644 src/Kestrel.Tls/TlsStream.cs create mode 100644 test/Kestrel.Core.Tests/HPackEncoderTests.cs create mode 100644 test/Kestrel.Core.Tests/Http2ConnectionTests.cs create mode 100644 test/Kestrel.Core.Tests/HuffmanTests.cs create mode 100644 test/Kestrel.Core.Tests/IntegerDecoderTests.cs create mode 100644 test/Kestrel.Core.Tests/IntegerEncoderTests.cs diff --git a/.vscode/launch.json b/.vscode/launch.json index 2db39e4359..db6faceb9c 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -13,6 +13,30 @@ "request": "attach", "processId": "${command:pickProcess}" }, + { + "name": "Debug: TlsApp", + "type": "coreclr", + "request": "launch", + "program": "${workspaceRoot}/samples/TlsApp/bin/Debug/netcoreapp2.0/TlsApp.dll", + "cwd": "${workspaceRoot}/samples/TlsApp", + "console": "internalConsole", + "stopAtEntry": false, + "internalConsoleOptions": "openOnSessionStart", + "launchBrowser": { + "enabled": true, + "args": "https://127.0.0.1:5000", + "windows": { + "command": "cmd.exe", + "args": "/C start ${auto-detect-url}" + }, + "osx": { + "command": "open" + }, + "linux": { + "command": "xdg-open" + } + } + }, { "name": "Debug: SampleApp", "type": "coreclr", diff --git a/KestrelHttpServer.sln b/KestrelHttpServer.sln index 60221f61ae..44ad81ebae 100644 --- a/KestrelHttpServer.sln +++ b/KestrelHttpServer.sln @@ -82,6 +82,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Kestrel.Tests", "test\Kestr EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Protocols.Abstractions", "src\Protocols.Abstractions\Protocols.Abstractions.csproj", "{6956CF5C-3163-4398-8628-4ECA569245B5}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Kestrel.Tls", "src\Kestrel.Tls\Kestrel.Tls.csproj", "{924AE57C-1EBA-4A1D-A039-8C100B7507A5}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -272,12 +274,23 @@ Global {6956CF5C-3163-4398-8628-4ECA569245B5}.Release|x64.Build.0 = Release|Any CPU {6956CF5C-3163-4398-8628-4ECA569245B5}.Release|x86.ActiveCfg = Release|Any CPU {6956CF5C-3163-4398-8628-4ECA569245B5}.Release|x86.Build.0 = Release|Any CPU + {924AE57C-1EBA-4A1D-A039-8C100B7507A5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {924AE57C-1EBA-4A1D-A039-8C100B7507A5}.Debug|Any CPU.Build.0 = Debug|Any CPU + {924AE57C-1EBA-4A1D-A039-8C100B7507A5}.Debug|x64.ActiveCfg = Debug|x64 + {924AE57C-1EBA-4A1D-A039-8C100B7507A5}.Debug|x64.Build.0 = Debug|x64 + {924AE57C-1EBA-4A1D-A039-8C100B7507A5}.Debug|x86.ActiveCfg = Debug|x86 + {924AE57C-1EBA-4A1D-A039-8C100B7507A5}.Debug|x86.Build.0 = Debug|x86 + {924AE57C-1EBA-4A1D-A039-8C100B7507A5}.Release|Any CPU.ActiveCfg = Release|Any CPU + {924AE57C-1EBA-4A1D-A039-8C100B7507A5}.Release|Any CPU.Build.0 = Release|Any CPU + {924AE57C-1EBA-4A1D-A039-8C100B7507A5}.Release|x64.ActiveCfg = Release|x64 + {924AE57C-1EBA-4A1D-A039-8C100B7507A5}.Release|x64.Build.0 = Release|x64 + {924AE57C-1EBA-4A1D-A039-8C100B7507A5}.Release|x86.ActiveCfg = Release|x86 + {924AE57C-1EBA-4A1D-A039-8C100B7507A5}.Release|x86.Build.0 = Release|x86 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection GlobalSection(NestedProjects) = preSolution - {0EF2ACDF-012F-4472-A13A-4272419E2903} = {D3273454-EA07-41D2-BF0B-FCC3675C2483} {F510611A-3BEE-4B88-A613-5F4A74ED82A1} = {2D5D5227-4DBD-499A-96B1-76A36B03B750} {37F3BFB2-6454-49E5-9D7F-581BF755CCFE} = {D3273454-EA07-41D2-BF0B-FCC3675C2483} {2C3CB3DC-EEBF-4F52-9E1C-4F2F972E76C3} = {8A3D00B8-1CCF-4BE6-A060-11104CE2D9CE} @@ -286,7 +299,6 @@ Global {5F64B3C3-0C2E-431A-B820-A81BBFC863DA} = {2D5D5227-4DBD-499A-96B1-76A36B03B750} {9559A5F1-080C-4909-B6CF-7E4B3DC55748} = {D3273454-EA07-41D2-BF0B-FCC3675C2483} {EBFE9719-A44B-4978-A71F-D5C254E7F35A} = {D3273454-EA07-41D2-BF0B-FCC3675C2483} - {2822C132-BFFB-4D53-AC5B-E7E47DD81A6E} = {0EF2ACDF-012F-4472-A13A-4272419E2903} {A76B8C8C-0DC5-4DD3-9B1F-02E51A0915F4} = {2D5D5227-4DBD-499A-96B1-76A36B03B750} {56139957-5C29-4E7D-89BD-7D20598B4EAF} = {2D5D5227-4DBD-499A-96B1-76A36B03B750} {6950B18F-A3D2-41A4-AFEC-8B7C49517611} = {2D5D5227-4DBD-499A-96B1-76A36B03B750} @@ -294,6 +306,7 @@ Global {D95A7EC3-48AC-4D03-B2E2-0DA3E13BD3A4} = {D3273454-EA07-41D2-BF0B-FCC3675C2483} {4F1C30F8-CCAA-48D7-9DF6-2A84021F5BCC} = {D3273454-EA07-41D2-BF0B-FCC3675C2483} {6956CF5C-3163-4398-8628-4ECA569245B5} = {2D5D5227-4DBD-499A-96B1-76A36B03B750} + {924AE57C-1EBA-4A1D-A039-8C100B7507A5} = {2D5D5227-4DBD-499A-96B1-76A36B03B750} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {2D10D020-6770-47CA-BB8D-2C23FE3AE071} diff --git a/src/Kestrel.Core/Adapter/Internal/AdaptedPipeline.cs b/src/Kestrel.Core/Adapter/Internal/AdaptedPipeline.cs index 8f6db82a0d..823fa67b52 100644 --- a/src/Kestrel.Core/Adapter/Internal/AdaptedPipeline.cs +++ b/src/Kestrel.Core/Adapter/Internal/AdaptedPipeline.cs @@ -165,4 +165,4 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal } } } -} \ No newline at end of file +} diff --git a/src/Kestrel.Core/Adapter/Internal/RawStream.cs b/src/Kestrel.Core/Adapter/Internal/RawStream.cs index a2bd9a0078..fdd4470637 100644 --- a/src/Kestrel.Core/Adapter/Internal/RawStream.cs +++ b/src/Kestrel.Core/Adapter/Internal/RawStream.cs @@ -199,4 +199,4 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal return tcs.Task; } } -} \ No newline at end of file +} diff --git a/src/Kestrel.Core/Features/IHttp2StreamIdFeature.cs b/src/Kestrel.Core/Features/IHttp2StreamIdFeature.cs new file mode 100644 index 0000000000..30ad135062 --- /dev/null +++ b/src/Kestrel.Core/Features/IHttp2StreamIdFeature.cs @@ -0,0 +1,10 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Features +{ + public interface IHttp2StreamIdFeature + { + int StreamId { get; } + } +} diff --git a/src/Kestrel.Core/Features/ITlsApplicationProtocolFeature.cs b/src/Kestrel.Core/Features/ITlsApplicationProtocolFeature.cs new file mode 100644 index 0000000000..7ad37730d5 --- /dev/null +++ b/src/Kestrel.Core/Features/ITlsApplicationProtocolFeature.cs @@ -0,0 +1,11 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Features +{ + // TODO: this should be merged with ITlsConnectionFeature + public interface ITlsApplicationProtocolFeature + { + string ApplicationProtocol { get; } + } +} diff --git a/src/Kestrel.Core/Internal/FrameConnection.cs b/src/Kestrel.Core/Internal/FrameConnection.cs index dbe08fce25..e1b2dbde37 100644 --- a/src/Kestrel.Core/Internal/FrameConnection.cs +++ b/src/Kestrel.Core/Internal/FrameConnection.cs @@ -13,7 +13,9 @@ using Microsoft.AspNetCore.Hosting.Server; using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Protocols.Features; using Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal; +using Microsoft.AspNetCore.Server.Kestrel.Core.Features; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; using Microsoft.Extensions.Logging; @@ -21,10 +23,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal { public class FrameConnection : IConnectionApplicationFeature, ITimeoutControl { + private const int Http2ConnectionNotStarted = 0; + private const int Http2ConnectionStarted = 1; + private const int Http2ConnectionClosed = 2; + private readonly FrameConnectionContext _context; private List _adaptedConnections; private readonly TaskCompletionSource _socketClosedTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); private Frame _frame; + private Http2Connection _http2Connection; + private volatile int _http2ConnectionState; private long _lastTimestamp; private long _timeoutTimestamp = long.MaxValue; @@ -116,6 +124,20 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal // _frame must be initialized before adding the connection to the connection manager CreateFrame(application, input, output); + // _http2Connection must be initialized before yield control to the transport thread, + // to prevent a race condition where _http2Connection.Abort() is called just as + // _http2Connection is about to be initialized. + _http2Connection = new Http2Connection(new Http2ConnectionContext + { + ConnectionId = _context.ConnectionId, + ServiceContext = _context.ServiceContext, + PipeFactory = PipeFactory, + LocalEndPoint = LocalEndPoint, + RemoteEndPoint = RemoteEndPoint, + Input = input, + Output = output + }); + // Do this before the first await so we don't yield control to the transport until we've // added the connection to the connection manager _context.ServiceContext.ConnectionManager.AddConnection(_context.FrameConnectionId, this); @@ -128,7 +150,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal adaptedPipelineTask = adaptedPipeline.RunAsync(stream); } - await _frame.ProcessRequestsAsync(); + if (_frame.ConnectionFeatures?.Get()?.ApplicationProtocol == "h2" && + Interlocked.CompareExchange(ref _http2ConnectionState, Http2ConnectionStarted, Http2ConnectionNotStarted) == Http2ConnectionNotStarted) + { + await _http2Connection.ProcessAsync(application); + } + else + { + await _frame.ProcessRequestsAsync(); + } + await adaptedPipelineTask; await _socketClosedTcs.Task; } @@ -173,10 +204,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal public void OnConnectionClosed(Exception ex) { - Debug.Assert(_frame != null, $"{nameof(_frame)} is null"); - - // Abort the connection (if not already aborted) - _frame.Abort(ex); + Abort(ex); _socketClosedTcs.TrySetResult(null); } @@ -185,7 +213,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal { Debug.Assert(_frame != null, $"{nameof(_frame)} is null"); - _frame.Stop(); + if (Interlocked.Exchange(ref _http2ConnectionState, Http2ConnectionClosed) == Http2ConnectionStarted) + { + _http2Connection.Stop(); + } + else + { + _frame.Stop(); + } return _lifetimeTask; } @@ -195,15 +230,19 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal Debug.Assert(_frame != null, $"{nameof(_frame)} is null"); // Abort the connection (if not already aborted) - _frame.Abort(ex); + if (Interlocked.Exchange(ref _http2ConnectionState, Http2ConnectionClosed) == Http2ConnectionStarted) + { + _http2Connection.Abort(ex); + } + else + { + _frame.Abort(ex); + } } public Task AbortAsync(Exception ex) { - Debug.Assert(_frame != null, $"{nameof(_frame)} is null"); - - // Abort the connection (if not already aborted) - _frame.Abort(ex); + Abort(ex); return _lifetimeTask; } diff --git a/src/Kestrel.Core/Internal/Http/FrameRequestStream.cs b/src/Kestrel.Core/Internal/Http/FrameRequestStream.cs index 5adc0a6e71..e04966ba94 100644 --- a/src/Kestrel.Core/Internal/Http/FrameRequestStream.cs +++ b/src/Kestrel.Core/Internal/Http/FrameRequestStream.cs @@ -15,7 +15,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http internal class FrameRequestStream : ReadOnlyStream { private readonly IHttpBodyControlFeature _bodyControl; - private MessageBody _body; + private IMessageBody _body; private FrameStreamState _state; private Exception _error; @@ -159,7 +159,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http } } - public void StartAcceptingReads(MessageBody body) + public void StartAcceptingReads(IMessageBody body) { // Only start if not aborted if (_state == FrameStreamState.Closed) diff --git a/src/Kestrel.Core/Internal/Http/IMessageBody.cs b/src/Kestrel.Core/Internal/Http/IMessageBody.cs new file mode 100644 index 0000000000..1f21fb47d1 --- /dev/null +++ b/src/Kestrel.Core/Internal/Http/IMessageBody.cs @@ -0,0 +1,17 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.IO; +using System.Threading; +using System.Threading.Tasks; + +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http +{ + public interface IMessageBody + { + Task ReadAsync(ArraySegment buffer, CancellationToken cancellationToken = default(CancellationToken)); + + Task CopyToAsync(Stream destination, CancellationToken cancellationToken = default(CancellationToken)); + } +} diff --git a/src/Kestrel.Core/Internal/Http/MessageBody.cs b/src/Kestrel.Core/Internal/Http/MessageBody.cs index 60e780375e..164f7f69ca 100644 --- a/src/Kestrel.Core/Internal/Http/MessageBody.cs +++ b/src/Kestrel.Core/Internal/Http/MessageBody.cs @@ -11,7 +11,7 @@ using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { - public abstract class MessageBody + public abstract class MessageBody : IMessageBody { private static readonly MessageBody _zeroContentLengthClose = new ForZeroContentLength(keepAlive: false); private static readonly MessageBody _zeroContentLengthKeepAlive = new ForZeroContentLength(keepAlive: true); diff --git a/src/Kestrel.Core/Internal/Http/RequestRejectionReason.cs b/src/Kestrel.Core/Internal/Http/RequestRejectionReason.cs index b482c87a02..0a7cb1eeb1 100644 --- a/src/Kestrel.Core/Internal/Http/RequestRejectionReason.cs +++ b/src/Kestrel.Core/Internal/Http/RequestRejectionReason.cs @@ -32,5 +32,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http MultipleHostHeaders, InvalidHostHeader, UpgradeRequestCannotHavePayload, + RequestBodyExceedsContentLength } } diff --git a/src/Kestrel.Core/Internal/Http2/HPack/DynamicTable.cs b/src/Kestrel.Core/Internal/Http2/HPack/DynamicTable.cs new file mode 100644 index 0000000000..0b58c69ba6 --- /dev/null +++ b/src/Kestrel.Core/Internal/Http2/HPack/DynamicTable.cs @@ -0,0 +1,72 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; + +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2.HPack +{ + public class DynamicTable + { + private readonly HeaderField[] _buffer; + private int _maxSize = 4096; + private int _size; + private int _count; + private int _insertIndex; + private int _removeIndex; + + public DynamicTable(int maxSize) + { + _buffer = new HeaderField[maxSize]; + _maxSize = maxSize; + } + + public int Count => _count; + + public int Size => _size; + + public HeaderField this[int index] + { + get + { + if (index >= _count) + { + throw new IndexOutOfRangeException(); + } + + return _buffer[_insertIndex == 0 ? _buffer.Length - 1 : _insertIndex - index - 1]; + } + } + + public void Insert(string name, string value) + { + var entrySize = name.Length + value.Length + 32; + EnsureSize(_maxSize - entrySize); + + if (_maxSize < entrySize) + { + throw new InvalidOperationException($"Unable to add entry of size {entrySize} to dynamic table of size {_maxSize}."); + } + + _buffer[_insertIndex] = new HeaderField(name, value); + _insertIndex = (_insertIndex + 1) % _buffer.Length; + _size += entrySize; + _count++; + } + + public void Resize(int maxSize) + { + _maxSize = maxSize; + EnsureSize(_maxSize); + } + + public void EnsureSize(int size) + { + while (_count > 0 && _size > size) + { + _size -= _buffer[_removeIndex].Name.Length + _buffer[_removeIndex].Value.Length + 32; + _count--; + _removeIndex = (_removeIndex + 1) % _buffer.Length; + } + } + } +} diff --git a/src/Kestrel.Core/Internal/Http2/HPack/HPackDecoder.cs b/src/Kestrel.Core/Internal/Http2/HPack/HPackDecoder.cs new file mode 100644 index 0000000000..33a1e014ad --- /dev/null +++ b/src/Kestrel.Core/Internal/Http2/HPack/HPackDecoder.cs @@ -0,0 +1,277 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Collections.Generic; +using System.Text; +using Microsoft.AspNetCore.Http; +using Microsoft.Extensions.Logging; + +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2.HPack +{ + public class HPackDecoder + { + private enum State + { + Ready, + HeaderFieldIndex, + HeaderNameIndex, + HeaderNameLength, + HeaderNameLengthContinue, + HeaderName, + HeaderValueLength, + HeaderValueLengthContinue, + HeaderValue, + DynamicTableSize + } + + private const byte IndexedHeaderFieldMask = 0x80; + private const byte LiteralHeaderFieldWithIncrementalIndexingMask = 0x40; + private const byte LiteralHeaderFieldWithoutIndexingMask = 0x00; + private const byte LiteralHeaderFieldNeverIndexedMask = 0x10; + private const byte DynamicTableSizeUpdateMask = 0x20; + private const byte HuffmanMask = 0x80; + + private const int IndexedHeaderFieldPrefix = 7; + private const int LiteralHeaderFieldWithIncrementalIndexingPrefix = 6; + private const int LiteralHeaderFieldWithoutIndexingPrefix = 4; + private const int LiteralHeaderFieldNeverIndexedPrefix = 4; + private const int DynamicTableSizeUpdatePrefix = 5; + private const int StringLengthPrefix = 7; + + private readonly DynamicTable _dynamicTable = new DynamicTable(4096); + private readonly IntegerDecoder _integerDecoder = new IntegerDecoder(); + + private State _state = State.Ready; + // TODO: add new HTTP/2 header size limit and allocate accordingly + private byte[] _stringOctets = new byte[Http2Frame.MinAllowedMaxFrameSize]; + private string _headerName = string.Empty; + private string _headerValue = string.Empty; + private int _stringLength; + private int _stringIndex; + private bool _index; + private bool _huffman; + + public void Decode(Span data, IHeaderDictionary headers) + { + for (var i = 0; i < data.Length; i++) + { + OnByte(data[i], headers); + } + } + + public void OnByte(byte b, IHeaderDictionary headers) + { + switch (_state) + { + case State.Ready: + if ((b & IndexedHeaderFieldMask) == IndexedHeaderFieldMask) + { + if (_integerDecoder.BeginDecode((byte)(b & ~IndexedHeaderFieldMask), IndexedHeaderFieldPrefix)) + { + OnIndexedHeaderField(_integerDecoder.Value, headers); + } + else + { + _state = State.HeaderFieldIndex; + } + } + else if ((b & LiteralHeaderFieldWithIncrementalIndexingMask) == LiteralHeaderFieldWithIncrementalIndexingMask) + { + _index = true; + var val = b & ~LiteralHeaderFieldWithIncrementalIndexingMask; + + if (val == 0) + { + _state = State.HeaderNameLength; + } + else if (_integerDecoder.BeginDecode((byte)val, LiteralHeaderFieldWithIncrementalIndexingPrefix)) + { + OnIndexedHeaderName(_integerDecoder.Value); + } + else + { + _state = State.HeaderNameIndex; + } + } + else if ((b & LiteralHeaderFieldWithoutIndexingMask) == LiteralHeaderFieldWithoutIndexingMask) + { + _index = false; + var val = b & ~LiteralHeaderFieldWithoutIndexingMask; + + if (val == 0) + { + _state = State.HeaderNameLength; + } + else if (_integerDecoder.BeginDecode((byte)val, LiteralHeaderFieldWithoutIndexingPrefix)) + { + OnIndexedHeaderName(_integerDecoder.Value); + } + else + { + _state = State.HeaderNameIndex; + } + } + else if ((b & LiteralHeaderFieldNeverIndexedMask) == LiteralHeaderFieldNeverIndexedMask) + { + _index = false; + var val = b & ~LiteralHeaderFieldNeverIndexedMask; + + if (val == 0) + { + _state = State.HeaderNameLength; + } + else if (_integerDecoder.BeginDecode((byte)val, LiteralHeaderFieldNeverIndexedPrefix)) + { + OnIndexedHeaderName(_integerDecoder.Value); + } + else + { + _state = State.HeaderNameIndex; + } + } + else if ((b & DynamicTableSizeUpdateMask) == DynamicTableSizeUpdateMask) + { + if (_integerDecoder.BeginDecode((byte)(b & ~DynamicTableSizeUpdateMask), DynamicTableSizeUpdatePrefix)) + { + // TODO: validate that it's less than what's defined via SETTINGS + _dynamicTable.Resize(_integerDecoder.Value); + } + else + { + _state = State.DynamicTableSize; + } + } + else + { + throw new InvalidOperationException(); + } + + break; + case State.HeaderFieldIndex: + if (_integerDecoder.Decode(b)) + { + OnIndexedHeaderField(_integerDecoder.Value, headers); + } + + break; + case State.HeaderNameIndex: + if (_integerDecoder.Decode(b)) + { + OnIndexedHeaderName(_integerDecoder.Value); + } + + break; + case State.HeaderNameLength: + _huffman = (b & HuffmanMask) == HuffmanMask; + + if (_integerDecoder.BeginDecode((byte)(b & ~HuffmanMask), StringLengthPrefix)) + { + OnStringLength(_integerDecoder.Value, nextState: State.HeaderName); + } + else + { + _state = State.HeaderNameLengthContinue; + } + + break; + case State.HeaderNameLengthContinue: + if (_integerDecoder.Decode(b)) + { + OnStringLength(_integerDecoder.Value, nextState: State.HeaderName); + } + + break; + case State.HeaderName: + _stringOctets[_stringIndex++] = b; + + if (_stringIndex == _stringLength) + { + _headerName = OnString(nextState: State.HeaderValueLength); + } + + break; + case State.HeaderValueLength: + _huffman = (b & HuffmanMask) == HuffmanMask; + + if (_integerDecoder.BeginDecode((byte)(b & ~HuffmanMask), StringLengthPrefix)) + { + OnStringLength(_integerDecoder.Value, nextState: State.HeaderValue); + } + else + { + _state = State.HeaderValueLengthContinue; + } + + break; + case State.HeaderValueLengthContinue: + if (_integerDecoder.Decode(b)) + { + OnStringLength(_integerDecoder.Value, nextState: State.HeaderValue); + } + + break; + case State.HeaderValue: + _stringOctets[_stringIndex++] = b; + + if (_stringIndex == _stringLength) + { + _headerValue = OnString(nextState: State.Ready); + headers.Append(_headerName, _headerValue); + + if (_index) + { + _dynamicTable.Insert(_headerName, _headerValue); + } + } + + break; + case State.DynamicTableSize: + if (_integerDecoder.Decode(b)) + { + // TODO: validate that it's less than what's defined via SETTINGS + _dynamicTable.Resize(_integerDecoder.Value); + _state = State.Ready; + } + + break; + default: + // Can't happen + throw new InvalidOperationException(); + } + } + + private void OnIndexedHeaderField(int index, IHeaderDictionary headers) + { + var header = GetHeader(index); + headers.Append(header.Name, header.Value); + _state = State.Ready; + } + + private void OnIndexedHeaderName(int index) + { + var header = GetHeader(index); + _headerName = header.Name; + _state = State.HeaderValueLength; + } + + private void OnStringLength(int length, State nextState) + { + _stringLength = length; + _stringIndex = 0; + _state = nextState; + } + + private string OnString(State nextState) + { + _state = nextState; + return _huffman + ? Huffman.Decode(_stringOctets, 0, _stringLength) + : Encoding.ASCII.GetString(_stringOctets, 0, _stringLength); + } + + private HeaderField GetHeader(int index) => index <= StaticTable.Instance.Length + ? StaticTable.Instance[index - 1] + : _dynamicTable[index - StaticTable.Instance.Length - 1]; + } +} diff --git a/src/Kestrel.Core/Internal/Http2/HPack/HPackEncoder.cs b/src/Kestrel.Core/Internal/Http2/HPack/HPackEncoder.cs new file mode 100644 index 0000000000..25206fed5b --- /dev/null +++ b/src/Kestrel.Core/Internal/Http2/HPack/HPackEncoder.cs @@ -0,0 +1,154 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Collections; +using System.Collections.Generic; +using Microsoft.AspNetCore.Http; +using Microsoft.Extensions.Primitives; + +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2.HPack +{ + public class HPackEncoder + { + private IEnumerator> _enumerator; + + public bool BeginEncode(IEnumerable> headers, Span buffer, out int length) + { + _enumerator = headers.GetEnumerator(); + _enumerator.MoveNext(); + + return Encode(buffer, out length); + } + + public bool BeginEncode(int statusCode, IEnumerable> headers, Span buffer, out int length) + { + _enumerator = headers.GetEnumerator(); + _enumerator.MoveNext(); + + var statusCodeLength = EncodeStatusCode(statusCode, buffer); + var done = Encode(buffer.Slice(statusCodeLength), out var headersLength); + length = statusCodeLength + headersLength; + + return done; + } + + public bool Encode(Span buffer, out int length) + { + length = 0; + + do + { + if (!EncodeHeader(_enumerator.Current.Key, _enumerator.Current.Value, buffer.Slice(length), out var headerLength)) + { + return false; + } + + length += headerLength; + } while (_enumerator.MoveNext()); + + return true; + } + + private int EncodeStatusCode(int statusCode, Span buffer) + { + switch (statusCode) + { + case 200: + case 204: + case 206: + case 304: + case 400: + case 404: + case 500: + buffer[0] = (byte)(0x80 | StaticTable.Instance.StatusIndex[statusCode]); + return 1; + default: + // Send as Literal Header Field Without Indexing - Indexed Name + buffer[0] = 0x08; + + var statusBytes = StatusCodes.ToStatusBytes(statusCode); + buffer[1] = (byte)statusBytes.Length; + ((Span)statusBytes).CopyTo(buffer.Slice(2)); + + return 2 + statusBytes.Length; + } + } + + private bool EncodeHeader(string name, string value, Span buffer, out int length) + { + var i = 0; + length = 0; + + if (buffer.Length == 0) + { + return false; + } + + buffer[i++] = 0; + + if (i == buffer.Length) + { + return false; + } + + if (!EncodeString(name, buffer.Slice(i), out var nameLength, lowercase: true)) + { + return false; + } + + i += nameLength; + + if (i >= buffer.Length) + { + return false; + } + + if (!EncodeString(value, buffer.Slice(i), out var valueLength, lowercase: false)) + { + return false; + } + + i += valueLength; + + length = i; + return true; + } + + private bool EncodeString(string s, Span buffer, out int length, bool lowercase) + { + const int toLowerMask = 0x20; + + var i = 0; + length = 0; + + if (buffer.Length == 0) + { + return false; + } + + buffer[0] = 0; + + if (!IntegerEncoder.Encode(s.Length, 7, buffer, out var nameLength)) + { + return false; + } + + i += nameLength; + + // TODO: use huffman encoding + for (var j = 0; j < s.Length; j++) + { + if (i >= buffer.Length) + { + return false; + } + + buffer[i++] = (byte)(s[j] | (lowercase ? toLowerMask : 0)); + } + + length = i; + return true; + } + } +} diff --git a/src/Kestrel.Core/Internal/Http2/HPack/HeaderField.cs b/src/Kestrel.Core/Internal/Http2/HPack/HeaderField.cs new file mode 100644 index 0000000000..9c3872cad2 --- /dev/null +++ b/src/Kestrel.Core/Internal/Http2/HPack/HeaderField.cs @@ -0,0 +1,17 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2.HPack +{ + public struct HeaderField + { + public HeaderField(string name, string value) + { + Name = name; + Value = value; + } + + public string Name { get; } + public string Value { get; } + } +} diff --git a/src/Kestrel.Core/Internal/Http2/HPack/Huffman.cs b/src/Kestrel.Core/Internal/Http2/HPack/Huffman.cs new file mode 100644 index 0000000000..7c9e52f446 --- /dev/null +++ b/src/Kestrel.Core/Internal/Http2/HPack/Huffman.cs @@ -0,0 +1,363 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Collections.Generic; +using System.Text; + +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2.HPack +{ + public class Huffman + { + // TODO: this can be constructed from _decodingTable + private static readonly (uint code, int bitLength)[] _encodingTable = new (uint code, int bitLength)[] + { + (0b11111111_11000000_00000000_00000000, 13), + (0b11111111_11111111_10110000_00000000, 23), + (0b11111111_11111111_11111110_00100000, 28), + (0b11111111_11111111_11111110_00110000, 28), + (0b11111111_11111111_11111110_01000000, 28), + (0b11111111_11111111_11111110_01010000, 28), + (0b11111111_11111111_11111110_01100000, 28), + (0b11111111_11111111_11111110_01110000, 28), + (0b11111111_11111111_11111110_10000000, 28), + (0b11111111_11111111_11101010_00000000, 24), + (0b11111111_11111111_11111111_11110000, 30), + (0b11111111_11111111_11111110_10010000, 28), + (0b11111111_11111111_11111110_10100000, 28), + (0b11111111_11111111_11111111_11110100, 30), + (0b11111111_11111111_11111110_10110000, 28), + (0b11111111_11111111_11111110_11000000, 28), + (0b11111111_11111111_11111110_11010000, 28), + (0b11111111_11111111_11111110_11100000, 28), + (0b11111111_11111111_11111110_11110000, 28), + (0b11111111_11111111_11111111_00000000, 28), + (0b11111111_11111111_11111111_00010000, 28), + (0b11111111_11111111_11111111_00100000, 28), + (0b11111111_11111111_11111111_11111000, 30), + (0b11111111_11111111_11111111_00110000, 28), + (0b11111111_11111111_11111111_01000000, 28), + (0b11111111_11111111_11111111_01010000, 28), + (0b11111111_11111111_11111111_01100000, 28), + (0b11111111_11111111_11111111_01110000, 28), + (0b11111111_11111111_11111111_10000000, 28), + (0b11111111_11111111_11111111_10010000, 28), + (0b11111111_11111111_11111111_10100000, 28), + (0b11111111_11111111_11111111_10110000, 28), + (0b01010000_00000000_00000000_00000000, 6), + (0b11111110_00000000_00000000_00000000, 10), + (0b11111110_01000000_00000000_00000000, 10), + (0b11111111_10100000_00000000_00000000, 12), + (0b11111111_11001000_00000000_00000000, 13), + (0b01010100_00000000_00000000_00000000, 6), + (0b11111000_00000000_00000000_00000000, 8), + (0b11111111_01000000_00000000_00000000, 11), + (0b11111110_10000000_00000000_00000000, 10), + (0b11111110_11000000_00000000_00000000, 10), + (0b11111001_00000000_00000000_00000000, 8), + (0b11111111_01100000_00000000_00000000, 11), + (0b11111010_00000000_00000000_00000000, 8), + (0b01011000_00000000_00000000_00000000, 6), + (0b01011100_00000000_00000000_00000000, 6), + (0b01100000_00000000_00000000_00000000, 6), + (0b00000000_00000000_00000000_00000000, 5), + (0b00001000_00000000_00000000_00000000, 5), + (0b00010000_00000000_00000000_00000000, 5), + (0b01100100_00000000_00000000_00000000, 6), + (0b01101000_00000000_00000000_00000000, 6), + (0b01101100_00000000_00000000_00000000, 6), + (0b01110000_00000000_00000000_00000000, 6), + (0b01110100_00000000_00000000_00000000, 6), + (0b01111000_00000000_00000000_00000000, 6), + (0b01111100_00000000_00000000_00000000, 6), + (0b10111000_00000000_00000000_00000000, 7), + (0b11111011_00000000_00000000_00000000, 8), + (0b11111111_11111000_00000000_00000000, 15), + (0b10000000_00000000_00000000_00000000, 6), + (0b11111111_10110000_00000000_00000000, 12), + (0b11111111_00000000_00000000_00000000, 10), + (0b11111111_11010000_00000000_00000000, 13), + (0b10000100_00000000_00000000_00000000, 6), + (0b10111010_00000000_00000000_00000000, 7), + (0b10111100_00000000_00000000_00000000, 7), + (0b10111110_00000000_00000000_00000000, 7), + (0b11000000_00000000_00000000_00000000, 7), + (0b11000010_00000000_00000000_00000000, 7), + (0b11000100_00000000_00000000_00000000, 7), + (0b11000110_00000000_00000000_00000000, 7), + (0b11001000_00000000_00000000_00000000, 7), + (0b11001010_00000000_00000000_00000000, 7), + (0b11001100_00000000_00000000_00000000, 7), + (0b11001110_00000000_00000000_00000000, 7), + (0b11010000_00000000_00000000_00000000, 7), + (0b11010010_00000000_00000000_00000000, 7), + (0b11010100_00000000_00000000_00000000, 7), + (0b11010110_00000000_00000000_00000000, 7), + (0b11011000_00000000_00000000_00000000, 7), + (0b11011010_00000000_00000000_00000000, 7), + (0b11011100_00000000_00000000_00000000, 7), + (0b11011110_00000000_00000000_00000000, 7), + (0b11100000_00000000_00000000_00000000, 7), + (0b11100010_00000000_00000000_00000000, 7), + (0b11100100_00000000_00000000_00000000, 7), + (0b11111100_00000000_00000000_00000000, 8), + (0b11100110_00000000_00000000_00000000, 7), + (0b11111101_00000000_00000000_00000000, 8), + (0b11111111_11011000_00000000_00000000, 13), + (0b11111111_11111110_00000000_00000000, 19), + (0b11111111_11100000_00000000_00000000, 13), + (0b11111111_11110000_00000000_00000000, 14), + (0b10001000_00000000_00000000_00000000, 6), + (0b11111111_11111010_00000000_00000000, 15), + (0b00011000_00000000_00000000_00000000, 5), + (0b10001100_00000000_00000000_00000000, 6), + (0b00100000_00000000_00000000_00000000, 5), + (0b10010000_00000000_00000000_00000000, 6), + (0b00101000_00000000_00000000_00000000, 5), + (0b10010100_00000000_00000000_00000000, 6), + (0b10011000_00000000_00000000_00000000, 6), + (0b10011100_00000000_00000000_00000000, 6), + (0b00110000_00000000_00000000_00000000, 5), + (0b11101000_00000000_00000000_00000000, 7), + (0b11101010_00000000_00000000_00000000, 7), + (0b10100000_00000000_00000000_00000000, 6), + (0b10100100_00000000_00000000_00000000, 6), + (0b10101000_00000000_00000000_00000000, 6), + (0b00111000_00000000_00000000_00000000, 5), + (0b10101100_00000000_00000000_00000000, 6), + (0b11101100_00000000_00000000_00000000, 7), + (0b10110000_00000000_00000000_00000000, 6), + (0b01000000_00000000_00000000_00000000, 5), + (0b01001000_00000000_00000000_00000000, 5), + (0b10110100_00000000_00000000_00000000, 6), + (0b11101110_00000000_00000000_00000000, 7), + (0b11110000_00000000_00000000_00000000, 7), + (0b11110010_00000000_00000000_00000000, 7), + (0b11110100_00000000_00000000_00000000, 7), + (0b11110110_00000000_00000000_00000000, 7), + (0b11111111_11111100_00000000_00000000, 15), + (0b11111111_10000000_00000000_00000000, 11), + (0b11111111_11110100_00000000_00000000, 14), + (0b11111111_11101000_00000000_00000000, 13), + (0b11111111_11111111_11111111_11000000, 28), + (0b11111111_11111110_01100000_00000000, 20), + (0b11111111_11111111_01001000_00000000, 22), + (0b11111111_11111110_01110000_00000000, 20), + (0b11111111_11111110_10000000_00000000, 20), + (0b11111111_11111111_01001100_00000000, 22), + (0b11111111_11111111_01010000_00000000, 22), + (0b11111111_11111111_01010100_00000000, 22), + (0b11111111_11111111_10110010_00000000, 23), + (0b11111111_11111111_01011000_00000000, 22), + (0b11111111_11111111_10110100_00000000, 23), + (0b11111111_11111111_10110110_00000000, 23), + (0b11111111_11111111_10111000_00000000, 23), + (0b11111111_11111111_10111010_00000000, 23), + (0b11111111_11111111_10111100_00000000, 23), + (0b11111111_11111111_11101011_00000000, 24), + (0b11111111_11111111_10111110_00000000, 23), + (0b11111111_11111111_11101100_00000000, 24), + (0b11111111_11111111_11101101_00000000, 24), + (0b11111111_11111111_01011100_00000000, 22), + (0b11111111_11111111_11000000_00000000, 23), + (0b11111111_11111111_11101110_00000000, 24), + (0b11111111_11111111_11000010_00000000, 23), + (0b11111111_11111111_11000100_00000000, 23), + (0b11111111_11111111_11000110_00000000, 23), + (0b11111111_11111111_11001000_00000000, 23), + (0b11111111_11111110_11100000_00000000, 21), + (0b11111111_11111111_01100000_00000000, 22), + (0b11111111_11111111_11001010_00000000, 23), + (0b11111111_11111111_01100100_00000000, 22), + (0b11111111_11111111_11001100_00000000, 23), + (0b11111111_11111111_11001110_00000000, 23), + (0b11111111_11111111_11101111_00000000, 24), + (0b11111111_11111111_01101000_00000000, 22), + (0b11111111_11111110_11101000_00000000, 21), + (0b11111111_11111110_10010000_00000000, 20), + (0b11111111_11111111_01101100_00000000, 22), + (0b11111111_11111111_01110000_00000000, 22), + (0b11111111_11111111_11010000_00000000, 23), + (0b11111111_11111111_11010010_00000000, 23), + (0b11111111_11111110_11110000_00000000, 21), + (0b11111111_11111111_11010100_00000000, 23), + (0b11111111_11111111_01110100_00000000, 22), + (0b11111111_11111111_01111000_00000000, 22), + (0b11111111_11111111_11110000_00000000, 24), + (0b11111111_11111110_11111000_00000000, 21), + (0b11111111_11111111_01111100_00000000, 22), + (0b11111111_11111111_11010110_00000000, 23), + (0b11111111_11111111_11011000_00000000, 23), + (0b11111111_11111111_00000000_00000000, 21), + (0b11111111_11111111_00001000_00000000, 21), + (0b11111111_11111111_10000000_00000000, 22), + (0b11111111_11111111_00010000_00000000, 21), + (0b11111111_11111111_11011010_00000000, 23), + (0b11111111_11111111_10000100_00000000, 22), + (0b11111111_11111111_11011100_00000000, 23), + (0b11111111_11111111_11011110_00000000, 23), + (0b11111111_11111110_10100000_00000000, 20), + (0b11111111_11111111_10001000_00000000, 22), + (0b11111111_11111111_10001100_00000000, 22), + (0b11111111_11111111_10010000_00000000, 22), + (0b11111111_11111111_11100000_00000000, 23), + (0b11111111_11111111_10010100_00000000, 22), + (0b11111111_11111111_10011000_00000000, 22), + (0b11111111_11111111_11100010_00000000, 23), + (0b11111111_11111111_11111000_00000000, 26), + (0b11111111_11111111_11111000_01000000, 26), + (0b11111111_11111110_10110000_00000000, 20), + (0b11111111_11111110_00100000_00000000, 19), + (0b11111111_11111111_10011100_00000000, 22), + (0b11111111_11111111_11100100_00000000, 23), + (0b11111111_11111111_10100000_00000000, 22), + (0b11111111_11111111_11110110_00000000, 25), + (0b11111111_11111111_11111000_10000000, 26), + (0b11111111_11111111_11111000_11000000, 26), + (0b11111111_11111111_11111001_00000000, 26), + (0b11111111_11111111_11111011_11000000, 27), + (0b11111111_11111111_11111011_11100000, 27), + (0b11111111_11111111_11111001_01000000, 26), + (0b11111111_11111111_11110001_00000000, 24), + (0b11111111_11111111_11110110_10000000, 25), + (0b11111111_11111110_01000000_00000000, 19), + (0b11111111_11111111_00011000_00000000, 21), + (0b11111111_11111111_11111001_10000000, 26), + (0b11111111_11111111_11111100_00000000, 27), + (0b11111111_11111111_11111100_00100000, 27), + (0b11111111_11111111_11111001_11000000, 26), + (0b11111111_11111111_11111100_01000000, 27), + (0b11111111_11111111_11110010_00000000, 24), + (0b11111111_11111111_00100000_00000000, 21), + (0b11111111_11111111_00101000_00000000, 21), + (0b11111111_11111111_11111010_00000000, 26), + (0b11111111_11111111_11111010_01000000, 26), + (0b11111111_11111111_11111111_11010000, 28), + (0b11111111_11111111_11111100_01100000, 27), + (0b11111111_11111111_11111100_10000000, 27), + (0b11111111_11111111_11111100_10100000, 27), + (0b11111111_11111110_11000000_00000000, 20), + (0b11111111_11111111_11110011_00000000, 24), + (0b11111111_11111110_11010000_00000000, 20), + (0b11111111_11111111_00110000_00000000, 21), + (0b11111111_11111111_10100100_00000000, 22), + (0b11111111_11111111_00111000_00000000, 21), + (0b11111111_11111111_01000000_00000000, 21), + (0b11111111_11111111_11100110_00000000, 23), + (0b11111111_11111111_10101000_00000000, 22), + (0b11111111_11111111_10101100_00000000, 22), + (0b11111111_11111111_11110111_00000000, 25), + (0b11111111_11111111_11110111_10000000, 25), + (0b11111111_11111111_11110100_00000000, 24), + (0b11111111_11111111_11110101_00000000, 24), + (0b11111111_11111111_11111010_10000000, 26), + (0b11111111_11111111_11101000_00000000, 23), + (0b11111111_11111111_11111010_11000000, 26), + (0b11111111_11111111_11111100_11000000, 27), + (0b11111111_11111111_11111011_00000000, 26), + (0b11111111_11111111_11111011_01000000, 26), + (0b11111111_11111111_11111100_11100000, 27), + (0b11111111_11111111_11111101_00000000, 27), + (0b11111111_11111111_11111101_00100000, 27), + (0b11111111_11111111_11111101_01000000, 27), + (0b11111111_11111111_11111101_01100000, 27), + (0b11111111_11111111_11111111_11100000, 28), + (0b11111111_11111111_11111101_10000000, 27), + (0b11111111_11111111_11111101_10100000, 27), + (0b11111111_11111111_11111101_11000000, 27), + (0b11111111_11111111_11111101_11100000, 27), + (0b11111111_11111111_11111110_00000000, 27), + (0b11111111_11111111_11111011_10000000, 26), + (0b11111111_11111111_11111111_11111100, 30) + }; + + private static readonly (int codeLength, int[] codes)[] _decodingTable = new[] + { + (5, new[] { 48, 49, 50, 97, 99, 101, 105, 111, 115, 116 }), + (6, new[] { 32, 37, 45, 46, 47, 51, 52, 53, 54, 55, 56, 57, 61, 65, 95, 98, 100, 102, 103, 104, 108, 109, 110, 112, 114, 117 }), + (7, new[] { 58, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 89, 106, 107, 113, 118, 119, 120, 121, 122 }), + (8, new[] { 38, 42, 44, 59, 88, 90 }), + (10, new[] { 33, 34, 40, 41, 63 }), + (11, new[] { 39, 43, 124 }), + (12, new[] { 35, 62 }), + (13, new[] { 0, 36, 64, 91, 93, 126 }), + (14, new[] { 94, 125 }), + (15, new[] { 60, 96, 123 }), + (19, new[] { 92, 195, 208 }), + (20, new[] { 128, 130, 131, 162, 184, 194, 224, 226 }), + (21, new[] { 153, 161, 167, 172, 176, 177, 179, 209, 216, 217, 227, 229, 230 }), + (22, new[] { 129, 132, 133, 134, 136, 146, 154, 156, 160, 163, 164, 169, 170, 173, 178, 181, 185, 186, 187, 189, 190, 196, 198, 228, 232, 233 }), + (23, new[] { 1, 135, 137, 138, 139, 140, 141, 143, 147, 149, 150, 151, 152, 155, 157, 158, 165, 166, 168, 174, 175, 180, 182, 183, 188, 191, 197, 231, 239 }), + (24, new[] { 9, 142, 144, 145, 148, 159, 171, 206, 215, 225, 236, 237 }), + (25, new[] { 199, 207, 234, 235 }), + (26, new[] { 192, 193, 200, 201, 202, 205, 210, 213, 218, 219, 238, 240, 242, 243, 255 }), + (27, new[] { 203, 204, 211, 212, 214, 221, 222, 223, 241, 244, 245, 246, 247, 248, 250, 251, 252, 253, 254 }), + (28, new[] { 2, 3, 4, 5, 6, 7, 8, 11, 12, 14, 15, 16, 17, 18, 19, 20, 21, 23, 24, 25, 26, 27, 28, 29, 30, 31, 127, 220, 249 }), + (30, new[] { 10, 13, 22, 256 }) + }; + + public static (uint encoded, int bitLength) Encode(int data) + { + return _encodingTable[data]; + } + + public static string Decode(byte[] data, int offset, int count) + { + var sb = new StringBuilder(); + + var i = offset; + var lastDecodedBits = 0; + while (i < count) + { + var next = (uint)(data[i] << 24 + lastDecodedBits); + next |= (i + 1 < data.Length ? (uint)(data[i + 1] << 16 + lastDecodedBits) : 0); + next |= (i + 2 < data.Length ? (uint)(data[i + 2] << 8 + lastDecodedBits) : 0); + next |= (i + 3 < data.Length ? (uint)(data[i + 3] << lastDecodedBits) : 0); + + var ones = (uint)(int.MinValue >> (8 - lastDecodedBits - 1)); + if (i == count - 1 && (next & ones) == ones) + { + // Padding + break; + } + + var ch = Decode(next, out var decodedBits); + sb.Append((char)ch); + + lastDecodedBits += decodedBits; + i += lastDecodedBits / 8; + lastDecodedBits %= 8; + } + + return sb.ToString(); + } + + public static int Decode(uint data, out int decodedBits) + { + var codeMax = 0; + + for (var i = 0; i < _decodingTable.Length; i++) + { + var (codeLength, codes) = _decodingTable[i]; + var mask = int.MinValue >> (codeLength - 1); + + if (i > 0) + { + codeMax <<= codeLength - _decodingTable[i - 1].codeLength; + } + + codeMax += codes.Length; + + var masked = (data & mask) >> (32 - codeLength); + + if (masked < codeMax) + { + decodedBits = codeLength; + return codes[codes.Length - (codeMax - masked)]; + } + } + + throw new Exception(); + } + } +} diff --git a/src/Kestrel.Core/Internal/Http2/HPack/IntegerDecoder.cs b/src/Kestrel.Core/Internal/Http2/HPack/IntegerDecoder.cs new file mode 100644 index 0000000000..c3bac3eb09 --- /dev/null +++ b/src/Kestrel.Core/Internal/Http2/HPack/IntegerDecoder.cs @@ -0,0 +1,45 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Collections.Generic; + +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2.HPack +{ + public class IntegerDecoder + { + private int _i; + private int _m; + + public int Value { get; private set; } + + public bool BeginDecode(byte b, int prefixLength) + { + if (b < ((1 << prefixLength) - 1)) + { + Value = b; + return true; + } + else + { + _i = b; + _m = 0; + return false; + } + } + + public bool Decode(byte b) + { + _i = _i + (b & 127) * (1 << _m); + _m = _m + 7; + + if ((b & 128) != 128) + { + Value = _i; + return true; + } + + return false; + } + } +} diff --git a/src/Kestrel.Core/Internal/Http2/HPack/IntegerEncoder.cs b/src/Kestrel.Core/Internal/Http2/HPack/IntegerEncoder.cs new file mode 100644 index 0000000000..6385459d14 --- /dev/null +++ b/src/Kestrel.Core/Internal/Http2/HPack/IntegerEncoder.cs @@ -0,0 +1,59 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; + +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2.HPack +{ + public static class IntegerEncoder + { + public static bool Encode(int i, int n, Span buffer, out int length) + { + var j = 0; + length = 0; + + if (buffer.Length == 0) + { + return false; + } + + if (i < (1 << n) - 1) + { + buffer[j] &= MaskHigh(8 - n); + buffer[j++] |= (byte)i; + } + else + { + buffer[j] &= MaskHigh(8 - n); + buffer[j++] |= (byte)((1 << n) - 1); + + if (j == buffer.Length) + { + return false; + } + + i = i - ((1 << n) - 1); + while (i >= 128) + { + buffer[j++] = (byte)(i % 128 + 128); + + if (j > buffer.Length) + { + return false; + } + + i = i / 128; + } + buffer[j++] = (byte)i; + } + + length = j; + return true; + } + + private static byte MaskHigh(int n) + { + return (byte)(sbyte.MinValue >> (n - 1)); + } + } +} diff --git a/src/Kestrel.Core/Internal/Http2/HPack/StaticTable.cs b/src/Kestrel.Core/Internal/Http2/HPack/StaticTable.cs new file mode 100644 index 0000000000..06612cc778 --- /dev/null +++ b/src/Kestrel.Core/Internal/Http2/HPack/StaticTable.cs @@ -0,0 +1,101 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Collections.Generic; + +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2.HPack +{ + public class StaticTable + { + private static readonly StaticTable _instance = new StaticTable(); + + private readonly Dictionary _statusIndex = new Dictionary + { + [200] = 8, + [204] = 9, + [206] = 10, + [304] = 11, + [400] = 12, + [404] = 13, + [500] = 14, + }; + + private StaticTable() + { + } + + public static StaticTable Instance => _instance; + + public int Length => _staticTable.Length; + + public HeaderField this[int index] => _staticTable[index]; + + public IReadOnlyDictionary StatusIndex => _statusIndex; + + private readonly HeaderField[] _staticTable = new HeaderField[] + { + new HeaderField(":authority", ""), + new HeaderField(":method", "GET"), + new HeaderField(":method", "POST"), + new HeaderField(":path", "/"), + new HeaderField(":path", "/index.html"), + new HeaderField(":scheme", "http"), + new HeaderField(":scheme", "https"), + new HeaderField(":status", "200"), + new HeaderField(":status", "204"), + new HeaderField(":status", "206"), + new HeaderField(":status", "304"), + new HeaderField(":status", "400"), + new HeaderField(":status", "404"), + new HeaderField(":status", "500"), + new HeaderField("accept-charset", ""), + new HeaderField("accept-encoding", "gzip, deflate"), + new HeaderField("accept-language", ""), + new HeaderField("accept-ranges", ""), + new HeaderField("accept", ""), + new HeaderField("access-control-allow-origin", ""), + new HeaderField("age", ""), + new HeaderField("allow", ""), + new HeaderField("authorization", ""), + new HeaderField("cache-control", ""), + new HeaderField("content-disposition", ""), + new HeaderField("content-encoding", ""), + new HeaderField("content-language", ""), + new HeaderField("content-length", ""), + new HeaderField("content-location", ""), + new HeaderField("content-range", ""), + new HeaderField("content-type", ""), + new HeaderField("cookie", ""), + new HeaderField("date", ""), + new HeaderField("etag", ""), + new HeaderField("expect", ""), + new HeaderField("expires", ""), + new HeaderField("from", ""), + new HeaderField("host", ""), + new HeaderField("if-match", ""), + new HeaderField("if-modified-since", ""), + new HeaderField("if-none-match", ""), + new HeaderField("if-range", ""), + new HeaderField("if-unmodifiedsince", ""), + new HeaderField("last-modified", ""), + new HeaderField("link", ""), + new HeaderField("location", ""), + new HeaderField("max-forwards", ""), + new HeaderField("proxy-authenticate", ""), + new HeaderField("proxy-authorization", ""), + new HeaderField("range", ""), + new HeaderField("referer", ""), + new HeaderField("refresh", ""), + new HeaderField("retry-after", ""), + new HeaderField("server", ""), + new HeaderField("set-cookie", ""), + new HeaderField("strict-transport-security", ""), + new HeaderField("transfer-encoding", ""), + new HeaderField("user-agent", ""), + new HeaderField("vary", ""), + new HeaderField("via", ""), + new HeaderField("www-authenticate", "") + }; + } +} diff --git a/src/Kestrel.Core/Internal/Http2/HPack/StatusCodes.cs b/src/Kestrel.Core/Internal/Http2/HPack/StatusCodes.cs new file mode 100644 index 0000000000..056d5a8a1a --- /dev/null +++ b/src/Kestrel.Core/Internal/Http2/HPack/StatusCodes.cs @@ -0,0 +1,222 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System.Globalization; +using System.Text; + +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2.HPack +{ + public static class StatusCodes + { + private static readonly byte[] _bytesStatus100 = CreateStatusBytes(Microsoft.AspNetCore.Http.StatusCodes.Status100Continue); + private static readonly byte[] _bytesStatus101 = CreateStatusBytes(Microsoft.AspNetCore.Http.StatusCodes.Status101SwitchingProtocols); + private static readonly byte[] _bytesStatus102 = CreateStatusBytes(Microsoft.AspNetCore.Http.StatusCodes.Status102Processing); + + private static readonly byte[] _bytesStatus200 = CreateStatusBytes(Microsoft.AspNetCore.Http.StatusCodes.Status200OK); + private static readonly byte[] _bytesStatus201 = CreateStatusBytes(Microsoft.AspNetCore.Http.StatusCodes.Status201Created); + private static readonly byte[] _bytesStatus202 = CreateStatusBytes(Microsoft.AspNetCore.Http.StatusCodes.Status202Accepted); + private static readonly byte[] _bytesStatus203 = CreateStatusBytes(Microsoft.AspNetCore.Http.StatusCodes.Status203NonAuthoritative); + private static readonly byte[] _bytesStatus204 = CreateStatusBytes(Microsoft.AspNetCore.Http.StatusCodes.Status204NoContent); + private static readonly byte[] _bytesStatus205 = CreateStatusBytes(Microsoft.AspNetCore.Http.StatusCodes.Status205ResetContent); + private static readonly byte[] _bytesStatus206 = CreateStatusBytes(Microsoft.AspNetCore.Http.StatusCodes.Status206PartialContent); + private static readonly byte[] _bytesStatus207 = CreateStatusBytes(Microsoft.AspNetCore.Http.StatusCodes.Status207MultiStatus); + private static readonly byte[] _bytesStatus208 = CreateStatusBytes(Microsoft.AspNetCore.Http.StatusCodes.Status208AlreadyReported); + private static readonly byte[] _bytesStatus226 = CreateStatusBytes(Microsoft.AspNetCore.Http.StatusCodes.Status226IMUsed); + + private static readonly byte[] _bytesStatus300 = CreateStatusBytes(Microsoft.AspNetCore.Http.StatusCodes.Status300MultipleChoices); + private static readonly byte[] _bytesStatus301 = CreateStatusBytes(Microsoft.AspNetCore.Http.StatusCodes.Status301MovedPermanently); + private static readonly byte[] _bytesStatus302 = CreateStatusBytes(Microsoft.AspNetCore.Http.StatusCodes.Status302Found); + private static readonly byte[] _bytesStatus303 = CreateStatusBytes(Microsoft.AspNetCore.Http.StatusCodes.Status303SeeOther); + private static readonly byte[] _bytesStatus304 = CreateStatusBytes(Microsoft.AspNetCore.Http.StatusCodes.Status304NotModified); + private static readonly byte[] _bytesStatus305 = CreateStatusBytes(Microsoft.AspNetCore.Http.StatusCodes.Status305UseProxy); + private static readonly byte[] _bytesStatus306 = CreateStatusBytes(Microsoft.AspNetCore.Http.StatusCodes.Status306SwitchProxy); + private static readonly byte[] _bytesStatus307 = CreateStatusBytes(Microsoft.AspNetCore.Http.StatusCodes.Status307TemporaryRedirect); + private static readonly byte[] _bytesStatus308 = CreateStatusBytes(Microsoft.AspNetCore.Http.StatusCodes.Status308PermanentRedirect); + + private static readonly byte[] _bytesStatus400 = CreateStatusBytes(Microsoft.AspNetCore.Http.StatusCodes.Status400BadRequest); + private static readonly byte[] _bytesStatus401 = CreateStatusBytes(Microsoft.AspNetCore.Http.StatusCodes.Status401Unauthorized); + private static readonly byte[] _bytesStatus402 = CreateStatusBytes(Microsoft.AspNetCore.Http.StatusCodes.Status402PaymentRequired); + private static readonly byte[] _bytesStatus403 = CreateStatusBytes(Microsoft.AspNetCore.Http.StatusCodes.Status403Forbidden); + private static readonly byte[] _bytesStatus404 = CreateStatusBytes(Microsoft.AspNetCore.Http.StatusCodes.Status404NotFound); + private static readonly byte[] _bytesStatus405 = CreateStatusBytes(Microsoft.AspNetCore.Http.StatusCodes.Status405MethodNotAllowed); + private static readonly byte[] _bytesStatus406 = CreateStatusBytes(Microsoft.AspNetCore.Http.StatusCodes.Status406NotAcceptable); + private static readonly byte[] _bytesStatus407 = CreateStatusBytes(Microsoft.AspNetCore.Http.StatusCodes.Status407ProxyAuthenticationRequired); + private static readonly byte[] _bytesStatus408 = CreateStatusBytes(Microsoft.AspNetCore.Http.StatusCodes.Status408RequestTimeout); + private static readonly byte[] _bytesStatus409 = CreateStatusBytes(Microsoft.AspNetCore.Http.StatusCodes.Status409Conflict); + private static readonly byte[] _bytesStatus410 = CreateStatusBytes(Microsoft.AspNetCore.Http.StatusCodes.Status410Gone); + private static readonly byte[] _bytesStatus411 = CreateStatusBytes(Microsoft.AspNetCore.Http.StatusCodes.Status411LengthRequired); + private static readonly byte[] _bytesStatus412 = CreateStatusBytes(Microsoft.AspNetCore.Http.StatusCodes.Status412PreconditionFailed); + private static readonly byte[] _bytesStatus413 = CreateStatusBytes(Microsoft.AspNetCore.Http.StatusCodes.Status413PayloadTooLarge); + private static readonly byte[] _bytesStatus414 = CreateStatusBytes(Microsoft.AspNetCore.Http.StatusCodes.Status414UriTooLong); + private static readonly byte[] _bytesStatus415 = CreateStatusBytes(Microsoft.AspNetCore.Http.StatusCodes.Status415UnsupportedMediaType); + private static readonly byte[] _bytesStatus416 = CreateStatusBytes(Microsoft.AspNetCore.Http.StatusCodes.Status416RangeNotSatisfiable); + private static readonly byte[] _bytesStatus417 = CreateStatusBytes(Microsoft.AspNetCore.Http.StatusCodes.Status417ExpectationFailed); + private static readonly byte[] _bytesStatus418 = CreateStatusBytes(Microsoft.AspNetCore.Http.StatusCodes.Status418ImATeapot); + private static readonly byte[] _bytesStatus419 = CreateStatusBytes(Microsoft.AspNetCore.Http.StatusCodes.Status419AuthenticationTimeout); + private static readonly byte[] _bytesStatus421 = CreateStatusBytes(Microsoft.AspNetCore.Http.StatusCodes.Status421MisdirectedRequest); + private static readonly byte[] _bytesStatus422 = CreateStatusBytes(Microsoft.AspNetCore.Http.StatusCodes.Status422UnprocessableEntity); + private static readonly byte[] _bytesStatus423 = CreateStatusBytes(Microsoft.AspNetCore.Http.StatusCodes.Status423Locked); + private static readonly byte[] _bytesStatus424 = CreateStatusBytes(Microsoft.AspNetCore.Http.StatusCodes.Status424FailedDependency); + private static readonly byte[] _bytesStatus426 = CreateStatusBytes(Microsoft.AspNetCore.Http.StatusCodes.Status426UpgradeRequired); + private static readonly byte[] _bytesStatus428 = CreateStatusBytes(Microsoft.AspNetCore.Http.StatusCodes.Status428PreconditionRequired); + private static readonly byte[] _bytesStatus429 = CreateStatusBytes(Microsoft.AspNetCore.Http.StatusCodes.Status429TooManyRequests); + private static readonly byte[] _bytesStatus431 = CreateStatusBytes(Microsoft.AspNetCore.Http.StatusCodes.Status431RequestHeaderFieldsTooLarge); + private static readonly byte[] _bytesStatus451 = CreateStatusBytes(Microsoft.AspNetCore.Http.StatusCodes.Status451UnavailableForLegalReasons); + + private static readonly byte[] _bytesStatus500 = CreateStatusBytes(Microsoft.AspNetCore.Http.StatusCodes.Status500InternalServerError); + private static readonly byte[] _bytesStatus501 = CreateStatusBytes(Microsoft.AspNetCore.Http.StatusCodes.Status501NotImplemented); + private static readonly byte[] _bytesStatus502 = CreateStatusBytes(Microsoft.AspNetCore.Http.StatusCodes.Status502BadGateway); + private static readonly byte[] _bytesStatus503 = CreateStatusBytes(Microsoft.AspNetCore.Http.StatusCodes.Status503ServiceUnavailable); + private static readonly byte[] _bytesStatus504 = CreateStatusBytes(Microsoft.AspNetCore.Http.StatusCodes.Status504GatewayTimeout); + private static readonly byte[] _bytesStatus505 = CreateStatusBytes(Microsoft.AspNetCore.Http.StatusCodes.Status505HttpVersionNotsupported); + private static readonly byte[] _bytesStatus506 = CreateStatusBytes(Microsoft.AspNetCore.Http.StatusCodes.Status506VariantAlsoNegotiates); + private static readonly byte[] _bytesStatus507 = CreateStatusBytes(Microsoft.AspNetCore.Http.StatusCodes.Status507InsufficientStorage); + private static readonly byte[] _bytesStatus508 = CreateStatusBytes(Microsoft.AspNetCore.Http.StatusCodes.Status508LoopDetected); + private static readonly byte[] _bytesStatus510 = CreateStatusBytes(Microsoft.AspNetCore.Http.StatusCodes.Status510NotExtended); + private static readonly byte[] _bytesStatus511 = CreateStatusBytes(Microsoft.AspNetCore.Http.StatusCodes.Status511NetworkAuthenticationRequired); + + private static byte[] CreateStatusBytes(int statusCode) + { + return Encoding.ASCII.GetBytes(statusCode.ToString(CultureInfo.InvariantCulture)); + } + + public static byte[] ToStatusBytes(int statusCode) + { + switch (statusCode) + { + case Microsoft.AspNetCore.Http.StatusCodes.Status100Continue: + return _bytesStatus100; + case Microsoft.AspNetCore.Http.StatusCodes.Status101SwitchingProtocols: + return _bytesStatus101; + case Microsoft.AspNetCore.Http.StatusCodes.Status102Processing: + return _bytesStatus102; + + case Microsoft.AspNetCore.Http.StatusCodes.Status200OK: + return _bytesStatus200; + case Microsoft.AspNetCore.Http.StatusCodes.Status201Created: + return _bytesStatus201; + case Microsoft.AspNetCore.Http.StatusCodes.Status202Accepted: + return _bytesStatus202; + case Microsoft.AspNetCore.Http.StatusCodes.Status203NonAuthoritative: + return _bytesStatus203; + case Microsoft.AspNetCore.Http.StatusCodes.Status204NoContent: + return _bytesStatus204; + case Microsoft.AspNetCore.Http.StatusCodes.Status205ResetContent: + return _bytesStatus205; + case Microsoft.AspNetCore.Http.StatusCodes.Status206PartialContent: + return _bytesStatus206; + case Microsoft.AspNetCore.Http.StatusCodes.Status207MultiStatus: + return _bytesStatus207; + case Microsoft.AspNetCore.Http.StatusCodes.Status208AlreadyReported: + return _bytesStatus208; + case Microsoft.AspNetCore.Http.StatusCodes.Status226IMUsed: + return _bytesStatus226; + + case Microsoft.AspNetCore.Http.StatusCodes.Status300MultipleChoices: + return _bytesStatus300; + case Microsoft.AspNetCore.Http.StatusCodes.Status301MovedPermanently: + return _bytesStatus301; + case Microsoft.AspNetCore.Http.StatusCodes.Status302Found: + return _bytesStatus302; + case Microsoft.AspNetCore.Http.StatusCodes.Status303SeeOther: + return _bytesStatus303; + case Microsoft.AspNetCore.Http.StatusCodes.Status304NotModified: + return _bytesStatus304; + case Microsoft.AspNetCore.Http.StatusCodes.Status305UseProxy: + return _bytesStatus305; + case Microsoft.AspNetCore.Http.StatusCodes.Status306SwitchProxy: + return _bytesStatus306; + case Microsoft.AspNetCore.Http.StatusCodes.Status307TemporaryRedirect: + return _bytesStatus307; + case Microsoft.AspNetCore.Http.StatusCodes.Status308PermanentRedirect: + return _bytesStatus308; + + case Microsoft.AspNetCore.Http.StatusCodes.Status400BadRequest: + return _bytesStatus400; + case Microsoft.AspNetCore.Http.StatusCodes.Status401Unauthorized: + return _bytesStatus401; + case Microsoft.AspNetCore.Http.StatusCodes.Status402PaymentRequired: + return _bytesStatus402; + case Microsoft.AspNetCore.Http.StatusCodes.Status403Forbidden: + return _bytesStatus403; + case Microsoft.AspNetCore.Http.StatusCodes.Status404NotFound: + return _bytesStatus404; + case Microsoft.AspNetCore.Http.StatusCodes.Status405MethodNotAllowed: + return _bytesStatus405; + case Microsoft.AspNetCore.Http.StatusCodes.Status406NotAcceptable: + return _bytesStatus406; + case Microsoft.AspNetCore.Http.StatusCodes.Status407ProxyAuthenticationRequired: + return _bytesStatus407; + case Microsoft.AspNetCore.Http.StatusCodes.Status408RequestTimeout: + return _bytesStatus408; + case Microsoft.AspNetCore.Http.StatusCodes.Status409Conflict: + return _bytesStatus409; + case Microsoft.AspNetCore.Http.StatusCodes.Status410Gone: + return _bytesStatus410; + case Microsoft.AspNetCore.Http.StatusCodes.Status411LengthRequired: + return _bytesStatus411; + case Microsoft.AspNetCore.Http.StatusCodes.Status412PreconditionFailed: + return _bytesStatus412; + case Microsoft.AspNetCore.Http.StatusCodes.Status413PayloadTooLarge: + return _bytesStatus413; + case Microsoft.AspNetCore.Http.StatusCodes.Status414UriTooLong: + return _bytesStatus414; + case Microsoft.AspNetCore.Http.StatusCodes.Status415UnsupportedMediaType: + return _bytesStatus415; + case Microsoft.AspNetCore.Http.StatusCodes.Status416RangeNotSatisfiable: + return _bytesStatus416; + case Microsoft.AspNetCore.Http.StatusCodes.Status417ExpectationFailed: + return _bytesStatus417; + case Microsoft.AspNetCore.Http.StatusCodes.Status418ImATeapot: + return _bytesStatus418; + case Microsoft.AspNetCore.Http.StatusCodes.Status419AuthenticationTimeout: + return _bytesStatus419; + case Microsoft.AspNetCore.Http.StatusCodes.Status421MisdirectedRequest: + return _bytesStatus421; + case Microsoft.AspNetCore.Http.StatusCodes.Status422UnprocessableEntity: + return _bytesStatus422; + case Microsoft.AspNetCore.Http.StatusCodes.Status423Locked: + return _bytesStatus423; + case Microsoft.AspNetCore.Http.StatusCodes.Status424FailedDependency: + return _bytesStatus424; + case Microsoft.AspNetCore.Http.StatusCodes.Status426UpgradeRequired: + return _bytesStatus426; + case Microsoft.AspNetCore.Http.StatusCodes.Status428PreconditionRequired: + return _bytesStatus428; + case Microsoft.AspNetCore.Http.StatusCodes.Status429TooManyRequests: + return _bytesStatus429; + case Microsoft.AspNetCore.Http.StatusCodes.Status431RequestHeaderFieldsTooLarge: + return _bytesStatus431; + case Microsoft.AspNetCore.Http.StatusCodes.Status451UnavailableForLegalReasons: + return _bytesStatus451; + + case Microsoft.AspNetCore.Http.StatusCodes.Status500InternalServerError: + return _bytesStatus500; + case Microsoft.AspNetCore.Http.StatusCodes.Status501NotImplemented: + return _bytesStatus501; + case Microsoft.AspNetCore.Http.StatusCodes.Status502BadGateway: + return _bytesStatus502; + case Microsoft.AspNetCore.Http.StatusCodes.Status503ServiceUnavailable: + return _bytesStatus503; + case Microsoft.AspNetCore.Http.StatusCodes.Status504GatewayTimeout: + return _bytesStatus504; + case Microsoft.AspNetCore.Http.StatusCodes.Status505HttpVersionNotsupported: + return _bytesStatus505; + case Microsoft.AspNetCore.Http.StatusCodes.Status506VariantAlsoNegotiates: + return _bytesStatus506; + case Microsoft.AspNetCore.Http.StatusCodes.Status507InsufficientStorage: + return _bytesStatus507; + case Microsoft.AspNetCore.Http.StatusCodes.Status508LoopDetected: + return _bytesStatus508; + case Microsoft.AspNetCore.Http.StatusCodes.Status510NotExtended: + return _bytesStatus510; + case Microsoft.AspNetCore.Http.StatusCodes.Status511NetworkAuthenticationRequired: + return _bytesStatus511; + + default: + return Encoding.ASCII.GetBytes(statusCode.ToString(CultureInfo.InvariantCulture)); + + } + } + } +} diff --git a/src/Kestrel.Core/Internal/Http2/Http2Connection.cs b/src/Kestrel.Core/Internal/Http2/Http2Connection.cs new file mode 100644 index 0000000000..4e3476d104 --- /dev/null +++ b/src/Kestrel.Core/Internal/Http2/Http2Connection.cs @@ -0,0 +1,498 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Collections.Concurrent; +using System.Collections.Generic; +using System.IO.Pipelines; +using System.Text; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Hosting.Server; +using Microsoft.AspNetCore.Protocols; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2.HPack; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; +using Microsoft.Extensions.Logging; + +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 +{ + public class Http2Connection : ITimeoutControl, IHttp2StreamLifetimeHandler + { + public static byte[] ClientPreface { get; } = Encoding.ASCII.GetBytes("PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n"); + + private readonly Http2ConnectionContext _context; + private readonly Http2FrameWriter _frameWriter; + private readonly HPackDecoder _hpackDecoder; + + private readonly Http2PeerSettings _serverSettings = new Http2PeerSettings(); + private readonly Http2PeerSettings _clientSettings = new Http2PeerSettings(); + + private readonly Http2Frame _incomingFrame = new Http2Frame(); + + private Http2Stream _currentHeadersStream; + private int _lastStreamId; + + private bool _stopping; + + private readonly ConcurrentDictionary _streams = new ConcurrentDictionary(); + + public Http2Connection(Http2ConnectionContext context) + { + _context = context; + _frameWriter = new Http2FrameWriter(context.Output); + _hpackDecoder = new HPackDecoder(); + } + + public string ConnectionId => _context.ConnectionId; + + public IPipeReader Input => _context.Input; + + public IKestrelTrace Log => _context.ServiceContext.Log; + + bool ITimeoutControl.TimedOut => throw new NotImplementedException(); + + public void Abort(Exception ex) + { + _stopping = true; + _frameWriter.Abort(ex); + } + + public void Stop() + { + _stopping = true; + Input.CancelPendingRead(); + } + + public async Task ProcessAsync(IHttpApplication application) + { + Exception error = null; + var errorCode = Http2ErrorCode.NO_ERROR; + + try + { + while (!_stopping) + { + var result = await Input.ReadAsync(); + var readableBuffer = result.Buffer; + var consumed = readableBuffer.Start; + var examined = readableBuffer.End; + + try + { + if (!readableBuffer.IsEmpty) + { + if (ParsePreface(readableBuffer, out consumed, out examined)) + { + break; + } + } + else if (result.IsCompleted) + { + return; + } + } + finally + { + Input.Advance(consumed, examined); + } + } + + if (!_stopping) + { + await _frameWriter.WriteSettingsAsync(_serverSettings); + } + + while (!_stopping) + { + var result = await Input.ReadAsync(); + var readableBuffer = result.Buffer; + var consumed = readableBuffer.Start; + var examined = readableBuffer.End; + + try + { + if (!readableBuffer.IsEmpty) + { + if (Http2FrameReader.ReadFrame(readableBuffer, _incomingFrame, out consumed, out examined)) + { + Log.LogTrace($"Connection id {ConnectionId} received {_incomingFrame.Type} frame with flags 0x{_incomingFrame.Flags:x} and length {_incomingFrame.Length} for stream ID {_incomingFrame.StreamId}"); + await ProcessFrameAsync(application); + } + } + else if (result.IsCompleted) + { + return; + } + } + finally + { + Input.Advance(consumed, examined); + } + } + } + catch (ConnectionAbortedException ex) + { + // TODO: log + error = ex; + } + catch (Http2ConnectionErrorException ex) + { + // TODO: log + error = ex; + errorCode = ex.ErrorCode; + } + catch (Exception ex) + { + // TODO: log + error = ex; + errorCode = Http2ErrorCode.INTERNAL_ERROR; + } + finally + { + try + { + foreach (var stream in _streams.Values) + { + stream.Abort(error); + } + + await _frameWriter.WriteGoAwayAsync(_lastStreamId, errorCode); + } + finally + { + Input.Complete(); + _frameWriter.Abort(ex: null); + } + } + } + + private bool ParsePreface(ReadableBuffer readableBuffer, out ReadCursor consumed, out ReadCursor examined) + { + consumed = readableBuffer.Start; + examined = readableBuffer.End; + + if (readableBuffer.Length < ClientPreface.Length) + { + return false; + } + + var span = readableBuffer.IsSingleSpan + ? readableBuffer.First.Span + : readableBuffer.ToSpan(); + + for (var i = 0; i < ClientPreface.Length; i++) + { + if (ClientPreface[i] != span[i]) + { + throw new Exception("Invalid HTTP/2 connection preface."); + } + } + + consumed = examined = readableBuffer.Move(readableBuffer.Start, ClientPreface.Length); + return true; + } + + private Task ProcessFrameAsync(IHttpApplication application) + { + switch (_incomingFrame.Type) + { + case Http2FrameType.DATA: + return ProcessDataFrameAsync(); + case Http2FrameType.HEADERS: + return ProcessHeadersFrameAsync(application); + case Http2FrameType.PRIORITY: + return ProcessPriorityFrameAsync(); + case Http2FrameType.RST_STREAM: + return ProcessRstStreamFrameAsync(); + case Http2FrameType.SETTINGS: + return ProcessSettingsFrameAsync(); + case Http2FrameType.PING: + return ProcessPingFrameAsync(); + case Http2FrameType.GOAWAY: + return ProcessGoAwayFrameAsync(); + case Http2FrameType.WINDOW_UPDATE: + return ProcessWindowUpdateFrameAsync(); + case Http2FrameType.CONTINUATION: + return ProcessContinuationFrameAsync(application); + } + + return Task.CompletedTask; + } + + private Task ProcessDataFrameAsync() + { + if (_currentHeadersStream != null) + { + throw new Http2ConnectionErrorException(Http2ErrorCode.PROTOCOL_ERROR); + } + + if (_incomingFrame.StreamId == 0) + { + throw new Http2ConnectionErrorException(Http2ErrorCode.PROTOCOL_ERROR); + } + + if (_incomingFrame.DataHasPadding && _incomingFrame.DataPadLength >= _incomingFrame.Length) + { + throw new Http2ConnectionErrorException(Http2ErrorCode.PROTOCOL_ERROR); + } + + if (_streams.TryGetValue(_incomingFrame.StreamId, out var stream) && !stream.MessageBody.IsCompleted) + { + return stream.MessageBody.OnDataAsync(_incomingFrame.DataPayload, + endStream: (_incomingFrame.DataFlags & Http2DataFrameFlags.END_STREAM) == Http2DataFrameFlags.END_STREAM); + } + + return _frameWriter.WriteRstStreamAsync(_incomingFrame.StreamId, Http2ErrorCode.STREAM_CLOSED); + } + + private Task ProcessHeadersFrameAsync(IHttpApplication application) + { + if (_currentHeadersStream != null) + { + throw new Http2ConnectionErrorException(Http2ErrorCode.PROTOCOL_ERROR); + } + + if (_incomingFrame.StreamId == 0) + { + throw new Http2ConnectionErrorException(Http2ErrorCode.PROTOCOL_ERROR); + } + + if (_incomingFrame.HeadersHasPadding && _incomingFrame.HeadersPadLength >= _incomingFrame.Length) + { + throw new Http2ConnectionErrorException(Http2ErrorCode.PROTOCOL_ERROR); + } + + _currentHeadersStream = new Http2Stream(application, new Http2StreamContext + { + ConnectionId = ConnectionId, + StreamId = _incomingFrame.StreamId, + ServiceContext = _context.ServiceContext, + PipeFactory = _context.PipeFactory, + LocalEndPoint = _context.LocalEndPoint, + RemoteEndPoint = _context.RemoteEndPoint, + StreamLifetimeHandler = this, + FrameWriter = _frameWriter + }); + _currentHeadersStream.ExpectBody = (_incomingFrame.HeadersFlags & Http2HeadersFrameFlags.END_STREAM) == 0; + _currentHeadersStream.Reset(); + + _streams[_incomingFrame.StreamId] = _currentHeadersStream; + + _hpackDecoder.Decode(_incomingFrame.HeadersPayload, _currentHeadersStream.RequestHeaders); + + if ((_incomingFrame.HeadersFlags & Http2HeadersFrameFlags.END_HEADERS) == Http2HeadersFrameFlags.END_HEADERS) + { + _lastStreamId = _incomingFrame.StreamId; + _ = _currentHeadersStream.ProcessRequestAsync(); + _currentHeadersStream = null; + } + + return Task.CompletedTask; + } + + private Task ProcessPriorityFrameAsync() + { + if (_currentHeadersStream != null) + { + throw new Http2ConnectionErrorException(Http2ErrorCode.PROTOCOL_ERROR); + } + + if (_incomingFrame.StreamId == 0) + { + throw new Http2ConnectionErrorException(Http2ErrorCode.PROTOCOL_ERROR); + } + + if (_incomingFrame.Length != 5) + { + throw new Http2ConnectionErrorException(Http2ErrorCode.FRAME_SIZE_ERROR); + } + + return Task.CompletedTask; + } + + private Task ProcessRstStreamFrameAsync() + { + if (_currentHeadersStream != null) + { + throw new Http2ConnectionErrorException(Http2ErrorCode.PROTOCOL_ERROR); + } + + if (_incomingFrame.StreamId == 0) + { + throw new Http2ConnectionErrorException(Http2ErrorCode.PROTOCOL_ERROR); + } + + if (_incomingFrame.Length != 4) + { + throw new Http2ConnectionErrorException(Http2ErrorCode.FRAME_SIZE_ERROR); + } + + if (_streams.TryGetValue(_incomingFrame.StreamId, out var stream)) + { + stream.Abort(error: null); + } + else if (_incomingFrame.StreamId > _lastStreamId) + { + throw new Http2ConnectionErrorException(Http2ErrorCode.PROTOCOL_ERROR); + } + + return Task.CompletedTask; + } + + private Task ProcessSettingsFrameAsync() + { + if (_currentHeadersStream != null) + { + throw new Http2ConnectionErrorException(Http2ErrorCode.PROTOCOL_ERROR); + } + + if (_incomingFrame.StreamId != 0) + { + throw new Http2ConnectionErrorException(Http2ErrorCode.PROTOCOL_ERROR); + } + + if ((_incomingFrame.SettingsFlags & Http2SettingsFrameFlags.ACK) == Http2SettingsFrameFlags.ACK && _incomingFrame.Length != 0) + { + throw new Http2ConnectionErrorException(Http2ErrorCode.FRAME_SIZE_ERROR); + } + + if (_incomingFrame.Length % 6 != 0) + { + throw new Http2ConnectionErrorException(Http2ErrorCode.FRAME_SIZE_ERROR); + } + + try + { + _clientSettings.ParseFrame(_incomingFrame); + return _frameWriter.WriteSettingsAckAsync(); + } + catch (Http2SettingsParameterOutOfRangeException ex) + { + throw new Http2ConnectionErrorException(ex.Parameter == Http2SettingsParameter.SETTINGS_INITIAL_WINDOW_SIZE + ? Http2ErrorCode.FLOW_CONTROL_ERROR + : Http2ErrorCode.PROTOCOL_ERROR); + } + } + + private Task ProcessPingFrameAsync() + { + if (_currentHeadersStream != null) + { + throw new Http2ConnectionErrorException(Http2ErrorCode.PROTOCOL_ERROR); + } + + if (_incomingFrame.Length != 8) + { + throw new Http2ConnectionErrorException(Http2ErrorCode.FRAME_SIZE_ERROR); + } + + return _frameWriter.WritePingAsync(Http2PingFrameFlags.ACK, _incomingFrame.Payload); + } + + private Task ProcessGoAwayFrameAsync() + { + if (_currentHeadersStream != null) + { + throw new Http2ConnectionErrorException(Http2ErrorCode.PROTOCOL_ERROR); + } + + Stop(); + return Task.CompletedTask; + } + + private Task ProcessWindowUpdateFrameAsync() + { + if (_currentHeadersStream != null) + { + throw new Http2ConnectionErrorException(Http2ErrorCode.PROTOCOL_ERROR); + } + + if (_incomingFrame.Length != 4) + { + throw new Http2ConnectionErrorException(Http2ErrorCode.FRAME_SIZE_ERROR); + } + + if (_incomingFrame.StreamId == 0) + { + if (_incomingFrame.WindowUpdateSizeIncrement == 0) + { + throw new Http2ConnectionErrorException(Http2ErrorCode.PROTOCOL_ERROR); + } + } + else + { + if (_incomingFrame.WindowUpdateSizeIncrement == 0) + { + return _frameWriter.WriteRstStreamAsync(_incomingFrame.StreamId, Http2ErrorCode.PROTOCOL_ERROR); + } + } + + return Task.CompletedTask; + } + + private Task ProcessContinuationFrameAsync(IHttpApplication application) + { + if (_currentHeadersStream == null || _incomingFrame.StreamId != _currentHeadersStream.StreamId) + { + throw new Http2ConnectionErrorException(Http2ErrorCode.PROTOCOL_ERROR); + } + + _hpackDecoder.Decode(_incomingFrame.HeadersPayload, _currentHeadersStream.RequestHeaders); + + if ((_incomingFrame.ContinuationFlags & Http2ContinuationFrameFlags.END_HEADERS) == Http2ContinuationFrameFlags.END_HEADERS) + { + _lastStreamId = _currentHeadersStream.StreamId; + _ = _currentHeadersStream.ProcessRequestAsync(); + _currentHeadersStream = null; + } + + return Task.CompletedTask; + } + + void IHttp2StreamLifetimeHandler.OnStreamCompleted(int streamId) + { + _streams.TryRemove(streamId, out _); + } + + void ITimeoutControl.SetTimeout(long ticks, TimeoutAction timeoutAction) + { + } + + void ITimeoutControl.ResetTimeout(long ticks, TimeoutAction timeoutAction) + { + } + + void ITimeoutControl.CancelTimeout() + { + } + + void ITimeoutControl.StartTimingReads() + { + } + + void ITimeoutControl.PauseTimingReads() + { + } + + void ITimeoutControl.ResumeTimingReads() + { + } + + void ITimeoutControl.StopTimingReads() + { + } + + void ITimeoutControl.BytesRead(long count) + { + } + + void ITimeoutControl.StartTimingWrite(long size) + { + } + + void ITimeoutControl.StopTimingWrite() + { + } + } +} diff --git a/src/Kestrel.Core/Internal/Http2/Http2ConnectionContext.cs b/src/Kestrel.Core/Internal/Http2/Http2ConnectionContext.cs new file mode 100644 index 0000000000..ff22a1afb0 --- /dev/null +++ b/src/Kestrel.Core/Internal/Http2/Http2ConnectionContext.cs @@ -0,0 +1,20 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System.IO.Pipelines; +using System.Net; + +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 +{ + public class Http2ConnectionContext + { + public string ConnectionId { get; set; } + public ServiceContext ServiceContext { get; set; } + public PipeFactory PipeFactory { get; set; } + public IPEndPoint LocalEndPoint { get; set; } + public IPEndPoint RemoteEndPoint { get; set; } + + public IPipeReader Input { get; set; } + public IPipe Output { get; set; } + } +} diff --git a/src/Kestrel.Core/Internal/Http2/Http2ConnectionErrorException.cs b/src/Kestrel.Core/Internal/Http2/Http2ConnectionErrorException.cs new file mode 100644 index 0000000000..b1b9136774 --- /dev/null +++ b/src/Kestrel.Core/Internal/Http2/Http2ConnectionErrorException.cs @@ -0,0 +1,18 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; + +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 +{ + public class Http2ConnectionErrorException : Exception + { + public Http2ConnectionErrorException(Http2ErrorCode errorCode) + : base($"HTTP/2 connection error: {errorCode}") + { + ErrorCode = errorCode; + } + + public Http2ErrorCode ErrorCode { get; } + } +} diff --git a/src/Kestrel.Core/Internal/Http2/Http2ContinuationFrameFlags.cs b/src/Kestrel.Core/Internal/Http2/Http2ContinuationFrameFlags.cs new file mode 100644 index 0000000000..65e65bc0bc --- /dev/null +++ b/src/Kestrel.Core/Internal/Http2/Http2ContinuationFrameFlags.cs @@ -0,0 +1,14 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; + +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 +{ + [Flags] + public enum Http2ContinuationFrameFlags : byte + { + NONE = 0x0, + END_HEADERS = 0x4, + } +} diff --git a/src/Kestrel.Core/Internal/Http2/Http2DataFrameFlags.cs b/src/Kestrel.Core/Internal/Http2/Http2DataFrameFlags.cs new file mode 100644 index 0000000000..735a4aea30 --- /dev/null +++ b/src/Kestrel.Core/Internal/Http2/Http2DataFrameFlags.cs @@ -0,0 +1,15 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; + +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 +{ + [Flags] + public enum Http2DataFrameFlags : byte + { + NONE = 0x0, + END_STREAM = 0x1, + PADDED = 0x8 + } +} diff --git a/src/Kestrel.Core/Internal/Http2/Http2ErrorCode.cs b/src/Kestrel.Core/Internal/Http2/Http2ErrorCode.cs new file mode 100644 index 0000000000..2f14f191ba --- /dev/null +++ b/src/Kestrel.Core/Internal/Http2/Http2ErrorCode.cs @@ -0,0 +1,25 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; + +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 +{ + public enum Http2ErrorCode : uint + { + NO_ERROR = 0x0, + PROTOCOL_ERROR = 0x1, + INTERNAL_ERROR = 0x2, + FLOW_CONTROL_ERROR = 0x3, + SETTINGS_TIMEOUT = 0x4, + STREAM_CLOSED = 0x5, + FRAME_SIZE_ERROR = 0x6, + REFUSED_STREAM = 0x7, + CANCEL = 0x8, + COMPRESSION_ERROR = 0x9, + CONNECT_ERROR = 0xa, + ENHANCE_YOUR_CALM = 0xb, + INADEQUATE_SECURITY = 0xc, + HTTP_1_1_REQUIRED = 0xd, + } +} diff --git a/src/Kestrel.Core/Internal/Http2/Http2Frame.Continuation.cs b/src/Kestrel.Core/Internal/Http2/Http2Frame.Continuation.cs new file mode 100644 index 0000000000..e184ff64db --- /dev/null +++ b/src/Kestrel.Core/Internal/Http2/Http2Frame.Continuation.cs @@ -0,0 +1,24 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; + +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 +{ + public partial class Http2Frame + { + public Http2ContinuationFrameFlags ContinuationFlags + { + get => (Http2ContinuationFrameFlags)Flags; + set => Flags = (byte)value; + } + + public void PrepareContinuation(Http2ContinuationFrameFlags flags, int streamId) + { + Length = MinAllowedMaxFrameSize - HeaderLength; + Type = Http2FrameType.CONTINUATION; + ContinuationFlags = flags; + StreamId = streamId; + } + } +} diff --git a/src/Kestrel.Core/Internal/Http2/Http2Frame.Data.cs b/src/Kestrel.Core/Internal/Http2/Http2Frame.Data.cs new file mode 100644 index 0000000000..78adb78c57 --- /dev/null +++ b/src/Kestrel.Core/Internal/Http2/Http2Frame.Data.cs @@ -0,0 +1,44 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; + +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 +{ + public partial class Http2Frame + { + public Http2DataFrameFlags DataFlags + { + get => (Http2DataFrameFlags)Flags; + set => Flags = (byte)value; + } + + public bool DataHasPadding => (DataFlags & Http2DataFrameFlags.PADDED) == Http2DataFrameFlags.PADDED; + + public byte DataPadLength + { + get => DataHasPadding ? _data[PayloadOffset] : (byte)0; + set => _data[PayloadOffset] = value; + } + + public ArraySegment DataPayload => DataHasPadding + ? new ArraySegment(_data, PayloadOffset + 1, Length - DataPadLength - 1) + : new ArraySegment(_data, PayloadOffset, Length); + + public void PrepareData(int streamId, byte? padLength = null) + { + var padded = padLength != null; + + Length = MinAllowedMaxFrameSize - HeaderLength; + Type = Http2FrameType.DATA; + DataFlags = padded ? Http2DataFrameFlags.PADDED : Http2DataFrameFlags.NONE; + StreamId = streamId; + + if (padded) + { + DataPadLength = padLength.Value; + Payload.Slice(Length - padLength.Value).Fill(0); + } + } + } +} diff --git a/src/Kestrel.Core/Internal/Http2/Http2Frame.GoAway.cs b/src/Kestrel.Core/Internal/Http2/Http2Frame.GoAway.cs new file mode 100644 index 0000000000..3e430de8b0 --- /dev/null +++ b/src/Kestrel.Core/Internal/Http2/Http2Frame.GoAway.cs @@ -0,0 +1,42 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 +{ + public partial class Http2Frame + { + public int GoAwayLastStreamId + { + get => (Payload[0] << 24) | (Payload[1] << 16) | (Payload[2] << 16) | Payload[3]; + set + { + Payload[0] = (byte)((value >> 24) & 0xff); + Payload[1] = (byte)((value >> 16) & 0xff); + Payload[2] = (byte)((value >> 8) & 0xff); + Payload[3] = (byte)(value & 0xff); + } + } + + public Http2ErrorCode GoAwayErrorCode + { + get => (Http2ErrorCode)((Payload[4] << 24) | (Payload[5] << 16) | (Payload[6] << 16) | Payload[7]); + set + { + Payload[4] = (byte)(((uint)value >> 24) & 0xff); + Payload[5] = (byte)(((uint)value >> 16) & 0xff); + Payload[6] = (byte)(((uint)value >> 8) & 0xff); + Payload[7] = (byte)((uint)value & 0xff); + } + } + + public void PrepareGoAway(int lastStreamId, Http2ErrorCode errorCode) + { + Length = 8; + Type = Http2FrameType.GOAWAY; + Flags = 0; + StreamId = 0; + GoAwayLastStreamId = lastStreamId; + GoAwayErrorCode = errorCode; + } + } +} diff --git a/src/Kestrel.Core/Internal/Http2/Http2Frame.Headers.cs b/src/Kestrel.Core/Internal/Http2/Http2Frame.Headers.cs new file mode 100644 index 0000000000..52c20bde94 --- /dev/null +++ b/src/Kestrel.Core/Internal/Http2/Http2Frame.Headers.cs @@ -0,0 +1,72 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; + +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 +{ + public partial class Http2Frame + { + public Http2HeadersFrameFlags HeadersFlags + { + get => (Http2HeadersFrameFlags)Flags; + set => Flags = (byte)value; + } + + public bool HeadersHasPadding => (HeadersFlags & Http2HeadersFrameFlags.PADDED) == Http2HeadersFrameFlags.PADDED; + + public byte HeadersPadLength + { + get => HeadersHasPadding ? _data[HeaderLength] : (byte)0; + set => _data[HeaderLength] = value; + } + + public bool HeadersHasPriority => (HeadersFlags & Http2HeadersFrameFlags.PRIORITY) == Http2HeadersFrameFlags.PRIORITY; + + public byte HeadersPriority + { + get => _data[HeadersPriorityOffset]; + set => _data[HeadersPriorityOffset] = value; + } + + private int HeadersPriorityOffset => PayloadOffset + (HeadersHasPadding ? 1 : 0) + 4; + + public int HeadersStreamDependency + { + get + { + var offset = HeadersStreamDependencyOffset; + + return (int)((uint)((_data[offset] << 24) + | (_data[offset + 1] << 16) + | (_data[offset + 2] << 8) + | _data[offset + 3]) & 0x7fffffff); + } + set + { + var offset = HeadersStreamDependencyOffset; + + _data[offset] = (byte)((value & 0xff000000) >> 24); + _data[offset + 1] = (byte)((value & 0x00ff0000) >> 16); + _data[offset + 2] = (byte)((value & 0x0000ff00) >> 8); + _data[offset + 3] = (byte)(value & 0x000000ff); + } + } + + private int HeadersStreamDependencyOffset => PayloadOffset + (HeadersHasPadding ? 1 : 0); + + public Span HeadersPayload => new Span(_data, HeadersPayloadOffset, HeadersPayloadLength); + + private int HeadersPayloadOffset => PayloadOffset + (HeadersHasPadding ? 1 : 0) + (HeadersHasPriority ? 5 : 0); + + private int HeadersPayloadLength => Length - ((HeadersHasPadding ? 1 : 0) + (HeadersHasPriority ? 5 : 0)) - HeadersPadLength; + + public void PrepareHeaders(Http2HeadersFrameFlags flags, int streamId) + { + Length = MinAllowedMaxFrameSize - HeaderLength; + Type = Http2FrameType.HEADERS; + HeadersFlags = flags; + StreamId = streamId; + } + } +} diff --git a/src/Kestrel.Core/Internal/Http2/Http2Frame.Ping.cs b/src/Kestrel.Core/Internal/Http2/Http2Frame.Ping.cs new file mode 100644 index 0000000000..932d717ac1 --- /dev/null +++ b/src/Kestrel.Core/Internal/Http2/Http2Frame.Ping.cs @@ -0,0 +1,24 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; + +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 +{ + public partial class Http2Frame + { + public Http2PingFrameFlags PingFlags + { + get => (Http2PingFrameFlags)Flags; + set => Flags = (byte)value; + } + + public void PreparePing(Http2PingFrameFlags flags) + { + Length = 8; + Type = Http2FrameType.PING; + PingFlags = flags; + StreamId = 0; + } + } +} diff --git a/src/Kestrel.Core/Internal/Http2/Http2Frame.Priority.cs b/src/Kestrel.Core/Internal/Http2/Http2Frame.Priority.cs new file mode 100644 index 0000000000..02f9bf02f9 --- /dev/null +++ b/src/Kestrel.Core/Internal/Http2/Http2Frame.Priority.cs @@ -0,0 +1,57 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 +{ + public partial class Http2Frame + { + public int PriorityStreamDependency + { + get => ((_data[PayloadOffset] << 24) + | (_data[PayloadOffset + 1] << 16) + | (_data[PayloadOffset + 2] << 8) + | _data[PayloadOffset + 3]) & 0x7fffffff; + set + { + _data[PayloadOffset] = (byte)((value & 0x7f000000) >> 24); + _data[PayloadOffset + 1] = (byte)((value & 0x00ff0000) >> 16); + _data[PayloadOffset + 2] = (byte)((value & 0x0000ff00) >> 8); + _data[PayloadOffset + 3] = (byte)(value & 0x000000ff); + } + } + + + public bool PriorityIsExclusive + { + get => (_data[PayloadOffset] & 0x80000000) != 0; + set + { + if (value) + { + _data[PayloadOffset] |= 0x80; + } + else + { + _data[PayloadOffset] &= 0x7f; + } + } + } + + public byte PriorityWeight + { + get => _data[PayloadOffset + 4]; + set => _data[PayloadOffset] = value; + } + + + public void PreparePriority(int streamId, int streamDependency, bool exclusive, byte weight) + { + Length = 5; + Type = Http2FrameType.PRIORITY; + StreamId = streamId; + PriorityStreamDependency = streamDependency; + PriorityIsExclusive = exclusive; + PriorityWeight = weight; + } + } +} diff --git a/src/Kestrel.Core/Internal/Http2/Http2Frame.RstStream.cs b/src/Kestrel.Core/Internal/Http2/Http2Frame.RstStream.cs new file mode 100644 index 0000000000..8a0bcdfd6c --- /dev/null +++ b/src/Kestrel.Core/Internal/Http2/Http2Frame.RstStream.cs @@ -0,0 +1,29 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 +{ + public partial class Http2Frame + { + public Http2ErrorCode RstStreamErrorCode + { + get => (Http2ErrorCode)((Payload[0] << 24) | (Payload[1] << 16) | (Payload[2] << 16) | Payload[3]); + set + { + Payload[0] = (byte)(((uint)value >> 24) & 0xff); + Payload[1] = (byte)(((uint)value >> 16) & 0xff); + Payload[2] = (byte)(((uint)value >> 8) & 0xff); + Payload[3] = (byte)((uint)value & 0xff); + } + } + + public void PrepareRstStream(int streamId, Http2ErrorCode errorCode) + { + Length = 4; + Type = Http2FrameType.RST_STREAM; + Flags = 0; + StreamId = streamId; + RstStreamErrorCode = errorCode; + } + } +} diff --git a/src/Kestrel.Core/Internal/Http2/Http2Frame.Settings.cs b/src/Kestrel.Core/Internal/Http2/Http2Frame.Settings.cs new file mode 100644 index 0000000000..04cc78b209 --- /dev/null +++ b/src/Kestrel.Core/Internal/Http2/Http2Frame.Settings.cs @@ -0,0 +1,42 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Linq; + +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 +{ + public partial class Http2Frame + { + public Http2SettingsFrameFlags SettingsFlags + { + get => (Http2SettingsFrameFlags)Flags; + set => Flags = (byte)value; + } + + public void PrepareSettings(Http2SettingsFrameFlags flags, Http2PeerSettings settings = null) + { + var settingCount = settings?.Count() ?? 0; + + Length = 6 * settingCount; + Type = Http2FrameType.SETTINGS; + SettingsFlags = flags; + StreamId = 0; + + if (settings != null) + { + Span payload = Payload; + foreach (var setting in settings) + { + payload[0] = (byte)((ushort)setting.Parameter >> 8); + payload[1] = (byte)(ushort)setting.Parameter; + payload[2] = (byte)(setting.Value >> 24); + payload[3] = (byte)(setting.Value >> 16); + payload[4] = (byte)(setting.Value >> 8); + payload[5] = (byte)setting.Value; + payload = payload.Slice(6); + } + } + } + } +} diff --git a/src/Kestrel.Core/Internal/Http2/Http2Frame.WindowUpdate.cs b/src/Kestrel.Core/Internal/Http2/Http2Frame.WindowUpdate.cs new file mode 100644 index 0000000000..6958b376f5 --- /dev/null +++ b/src/Kestrel.Core/Internal/Http2/Http2Frame.WindowUpdate.cs @@ -0,0 +1,29 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 +{ + public partial class Http2Frame + { + public int WindowUpdateSizeIncrement + { + get => ((Payload[0] << 24) | (Payload[1] << 16) | (Payload[2] << 16) | Payload[3]) & 0x7fffffff; + set + { + Payload[0] = (byte)(((uint)value >> 24) & 0x7f); + Payload[1] = (byte)(((uint)value >> 16) & 0xff); + Payload[2] = (byte)(((uint)value >> 8) & 0xff); + Payload[3] = (byte)((uint)value & 0xff); + } + } + + public void PrepareWindowUpdate(int streamId, int sizeIncrement) + { + Length = 4; + Type = Http2FrameType.WINDOW_UPDATE; + Flags = 0; + StreamId = streamId; + WindowUpdateSizeIncrement = sizeIncrement; + } + } +} diff --git a/src/Kestrel.Core/Internal/Http2/Http2Frame.cs b/src/Kestrel.Core/Internal/Http2/Http2Frame.cs new file mode 100644 index 0000000000..3e9e15750d --- /dev/null +++ b/src/Kestrel.Core/Internal/Http2/Http2Frame.cs @@ -0,0 +1,70 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; + +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 +{ + public partial class Http2Frame + { + public const int MinAllowedMaxFrameSize = 16 * 1024; + public const int MaxAllowedMaxFrameSize = 16 * 1024 * 1024 - 1; + public const int HeaderLength = 9; + + private const int LengthOffset = 0; + private const int TypeOffset = 3; + private const int FlagsOffset = 4; + private const int StreamIdOffset = 5; + private const int PayloadOffset = 9; + + private readonly byte[] _data = new byte[MinAllowedMaxFrameSize]; + + public ArraySegment Raw => new ArraySegment(_data, 0, HeaderLength + Length); + + public int Length + { + get => (_data[LengthOffset] << 16) | (_data[LengthOffset + 1] << 8) | _data[LengthOffset + 2]; + set + { + _data[LengthOffset] = (byte)((value & 0x00ff0000) >> 16); + _data[LengthOffset + 1] = (byte)((value & 0x0000ff00) >> 8); + _data[LengthOffset + 2] = (byte)(value & 0x000000ff); + } + } + + public Http2FrameType Type + { + get => (Http2FrameType)_data[TypeOffset]; + set + { + _data[TypeOffset] = (byte)value; + } + } + + public byte Flags + { + get => _data[FlagsOffset]; + set + { + _data[FlagsOffset] = (byte)value; + } + } + + public int StreamId + { + get => (int)((uint)((_data[StreamIdOffset] << 24) + | (_data[StreamIdOffset + 1] << 16) + | (_data[StreamIdOffset + 2] << 8) + | _data[StreamIdOffset + 3]) & 0x7fffffff); + set + { + _data[StreamIdOffset] = (byte)((value & 0xff000000) >> 24); + _data[StreamIdOffset + 1] = (byte)((value & 0x00ff0000) >> 16); + _data[StreamIdOffset + 2] = (byte)((value & 0x0000ff00) >> 8); + _data[StreamIdOffset + 3] = (byte)(value & 0x000000ff); + } + } + + public Span Payload => new Span(_data, PayloadOffset, Length); + } +} diff --git a/src/Kestrel.Core/Internal/Http2/Http2FrameReader.cs b/src/Kestrel.Core/Internal/Http2/Http2FrameReader.cs new file mode 100644 index 0000000000..2a45009277 --- /dev/null +++ b/src/Kestrel.Core/Internal/Http2/Http2FrameReader.cs @@ -0,0 +1,34 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System.IO.Pipelines; + +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 +{ + public static class Http2FrameReader + { + public static bool ReadFrame(ReadableBuffer readableBuffer, Http2Frame frame, out ReadCursor consumed, out ReadCursor examined) + { + consumed = readableBuffer.Start; + examined = readableBuffer.End; + + if (readableBuffer.Length < Http2Frame.HeaderLength) + { + return false; + } + + var headerSlice = readableBuffer.Slice(0, Http2Frame.HeaderLength); + headerSlice.CopyTo(frame.Raw); + + if (readableBuffer.Length < Http2Frame.HeaderLength + frame.Length) + { + return false; + } + + readableBuffer.Slice(Http2Frame.HeaderLength, frame.Length).CopyTo(frame.Payload); + consumed = examined = readableBuffer.Move(readableBuffer.Start, Http2Frame.HeaderLength + frame.Length); + + return true; + } + } +} diff --git a/src/Kestrel.Core/Internal/Http2/Http2FrameType.cs b/src/Kestrel.Core/Internal/Http2/Http2FrameType.cs new file mode 100644 index 0000000000..a09272a6be --- /dev/null +++ b/src/Kestrel.Core/Internal/Http2/Http2FrameType.cs @@ -0,0 +1,19 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 +{ + public enum Http2FrameType : byte + { + DATA = 0x0, + HEADERS = 0x1, + PRIORITY = 0x2, + RST_STREAM = 0x3, + SETTINGS = 0x4, + PUSH_PROMISE = 0x5, + PING = 0x6, + GOAWAY = 0x7, + WINDOW_UPDATE = 0x8, + CONTINUATION = 0x9 + } +} diff --git a/src/Kestrel.Core/Internal/Http2/Http2FrameWriter.cs b/src/Kestrel.Core/Internal/Http2/Http2FrameWriter.cs new file mode 100644 index 0000000000..698f6a19c5 --- /dev/null +++ b/src/Kestrel.Core/Internal/Http2/Http2FrameWriter.cs @@ -0,0 +1,192 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Collections.Generic; +using System.IO.Pipelines; +using System.Threading; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2.HPack; +using Microsoft.Extensions.Logging; + +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 +{ + public class Http2FrameWriter : IHttp2FrameWriter + { + private static readonly ArraySegment _emptyData = new ArraySegment(new byte[0]); + + private readonly Http2Frame _outgoingFrame = new Http2Frame(); + private readonly object _writeLock = new object(); + private readonly HPackEncoder _hpackEncoder = new HPackEncoder(); + private readonly IPipe _output; + + private bool _completed; + + public Http2FrameWriter(IPipe output) + { + _output = output; + } + + public void Abort(Exception ex) + { + lock (_writeLock) + { + _completed = true; + _output.Reader.CancelPendingRead(); + _output.Writer.Complete(ex); + } + } + + public Task FlushAsync(CancellationToken cancellationToken) + { + return WriteAsync(_emptyData); + } + + public Task Write100ContinueAsync(int streamId) + { + return Task.CompletedTask; + } + + public Task WriteHeadersAsync(int streamId, int statusCode, IHeaderDictionary headers) + { + var tasks = new List(); + + lock (_writeLock) + { + _outgoingFrame.PrepareHeaders(Http2HeadersFrameFlags.NONE, streamId); + + var done = _hpackEncoder.BeginEncode(statusCode, EnumerateHeaders(headers), _outgoingFrame.Payload, out var payloadLength); + _outgoingFrame.Length = payloadLength; + + if (done) + { + _outgoingFrame.HeadersFlags = Http2HeadersFrameFlags.END_HEADERS; + } + + tasks.Add(WriteAsync(_outgoingFrame.Raw)); + + while (!done) + { + _outgoingFrame.PrepareContinuation(Http2ContinuationFrameFlags.NONE, streamId); + + done = _hpackEncoder.Encode(_outgoingFrame.Payload, out var length); + _outgoingFrame.Length = length; + + if (done) + { + _outgoingFrame.ContinuationFlags = Http2ContinuationFrameFlags.END_HEADERS; + } + + tasks.Add(WriteAsync(_outgoingFrame.Raw)); + } + + return Task.WhenAll(tasks); + } + } + + public Task WriteDataAsync(int streamId, Span data, CancellationToken cancellationToken) + => WriteDataAsync(streamId, data, endStream: false, cancellationToken: cancellationToken); + + public Task WriteDataAsync(int streamId, Span data, bool endStream, CancellationToken cancellationToken) + { + var tasks = new List(); + + lock (_writeLock) + { + _outgoingFrame.PrepareData(streamId); + + while (data.Length > _outgoingFrame.Length) + { + data.Slice(0, _outgoingFrame.Length).CopyTo(_outgoingFrame.Payload); + data = data.Slice(_outgoingFrame.Length); + + tasks.Add(WriteAsync(_outgoingFrame.Raw, cancellationToken)); + } + + _outgoingFrame.Length = data.Length; + + if (endStream) + { + _outgoingFrame.DataFlags = Http2DataFrameFlags.END_STREAM; + } + + data.CopyTo(_outgoingFrame.Payload); + + tasks.Add(WriteAsync(_outgoingFrame.Raw, cancellationToken)); + + return Task.WhenAll(tasks); + } + } + + public Task WriteRstStreamAsync(int streamId, Http2ErrorCode errorCode) + { + lock (_writeLock) + { + _outgoingFrame.PrepareRstStream(streamId, errorCode); + return WriteAsync(_outgoingFrame.Raw); + } + } + + public Task WriteSettingsAsync(Http2PeerSettings settings) + { + lock (_writeLock) + { + // TODO: actually send settings + _outgoingFrame.PrepareSettings(Http2SettingsFrameFlags.NONE); + return WriteAsync(_outgoingFrame.Raw); + } + } + + public Task WriteSettingsAckAsync() + { + lock (_writeLock) + { + _outgoingFrame.PrepareSettings(Http2SettingsFrameFlags.ACK); + return WriteAsync(_outgoingFrame.Raw); + } + } + + public Task WritePingAsync(Http2PingFrameFlags flags, Span payload) + { + lock (_writeLock) + { + _outgoingFrame.PreparePing(Http2PingFrameFlags.ACK); + payload.CopyTo(_outgoingFrame.Payload); + return WriteAsync(_outgoingFrame.Raw); + } + } + + public Task WriteGoAwayAsync(int lastStreamId, Http2ErrorCode errorCode) + { + lock (_writeLock) + { + _outgoingFrame.PrepareGoAway(lastStreamId, errorCode); + return WriteAsync(_outgoingFrame.Raw); + } + } + + private async Task WriteAsync(ArraySegment data, CancellationToken cancellationToken = default(CancellationToken)) + { + if (_completed) + { + return; + } + + var writeableBuffer = _output.Writer.Alloc(1); + writeableBuffer.Write(data); + await writeableBuffer.FlushAsync(cancellationToken); + } + + private static IEnumerable> EnumerateHeaders(IHeaderDictionary headers) + { + foreach (var header in headers) + { + foreach (var value in header.Value) + { + yield return new KeyValuePair(header.Key, value); + } + } + } + } +} diff --git a/src/Kestrel.Core/Internal/Http2/Http2HeadersFrameFlags.cs b/src/Kestrel.Core/Internal/Http2/Http2HeadersFrameFlags.cs new file mode 100644 index 0000000000..564371e1be --- /dev/null +++ b/src/Kestrel.Core/Internal/Http2/Http2HeadersFrameFlags.cs @@ -0,0 +1,17 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; + +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 +{ + [Flags] + public enum Http2HeadersFrameFlags : byte + { + NONE = 0x0, + END_STREAM = 0x1, + END_HEADERS = 0x4, + PADDED = 0x8, + PRIORITY = 0x20 + } +} diff --git a/src/Kestrel.Core/Internal/Http2/Http2MessageBody.cs b/src/Kestrel.Core/Internal/Http2/Http2MessageBody.cs new file mode 100644 index 0000000000..81ab3a5595 --- /dev/null +++ b/src/Kestrel.Core/Internal/Http2/Http2MessageBody.cs @@ -0,0 +1,262 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.IO; +using System.IO.Pipelines; +using System.Threading; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; + +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 +{ + public abstract class Http2MessageBody : IMessageBody + { + private static readonly Http2MessageBody _emptyMessageBody = new ForEmpty(); + + private readonly Http2Stream _context; + + private bool _send100Continue = true; + + protected Http2MessageBody(Http2Stream context) + { + _context = context; + } + + public bool IsCompleted { get; protected set; } + + public virtual async Task OnDataAsync(ArraySegment data, bool endStream) + { + try + { + if (data.Count > 0) + { + var writableBuffer = _context.RequestBodyPipe.Writer.Alloc(1); + bool done; + + try + { + done = Read(data, writableBuffer); + } + finally + { + writableBuffer.Commit(); + } + + await writableBuffer.FlushAsync(); + } + + if (endStream) + { + IsCompleted = true; + _context.RequestBodyPipe.Writer.Complete(); + } + } + catch (Exception ex) + { + _context.RequestBodyPipe.Writer.Complete(ex); + } + } + + public virtual async Task ReadAsync(ArraySegment buffer, CancellationToken cancellationToken = default(CancellationToken)) + { + TryInit(); + + while (true) + { + var result = await _context.RequestBodyPipe.Reader.ReadAsync(); + var readableBuffer = result.Buffer; + var consumed = readableBuffer.End; + + try + { + if (!readableBuffer.IsEmpty) + { + // buffer.Count is int + var actual = (int)Math.Min(readableBuffer.Length, buffer.Count); + var slice = readableBuffer.Slice(0, actual); + consumed = readableBuffer.Move(readableBuffer.Start, actual); + slice.CopyTo(buffer); + return actual; + } + else if (result.IsCompleted) + { + return 0; + } + } + finally + { + _context.RequestBodyPipe.Reader.Advance(consumed); + } + } + } + + public virtual async Task CopyToAsync(Stream destination, CancellationToken cancellationToken = default(CancellationToken)) + { + TryInit(); + + while (true) + { + var result = await _context.RequestBodyPipe.Reader.ReadAsync(); + var readableBuffer = result.Buffer; + var consumed = readableBuffer.End; + + try + { + if (!readableBuffer.IsEmpty) + { + foreach (var memory in readableBuffer) + { + var array = memory.GetArray(); + await destination.WriteAsync(array.Array, array.Offset, array.Count, cancellationToken); + } + } + else if (result.IsCompleted) + { + return; + } + } + finally + { + _context.RequestBodyPipe.Reader.Advance(consumed); + } + } + } + + public virtual Task StopAsync() + { + _context.RequestBodyPipe.Reader.Complete(); + _context.RequestBodyPipe.Writer.Complete(); + return Task.CompletedTask; + } + + protected void Copy(Span data, WritableBuffer writableBuffer) + { + writableBuffer.Write(data); + } + + private void TryProduceContinue() + { + if (_send100Continue) + { + _context.HttpStreamControl.ProduceContinue(); + _send100Continue = false; + } + } + + private void TryInit() + { + if (!_context.HasStartedConsumingRequestBody) + { + OnReadStart(); + _context.HasStartedConsumingRequestBody = true; + } + } + + protected virtual bool Read(Span readableBuffer, WritableBuffer writableBuffer) + { + throw new NotImplementedException(); + } + + protected virtual void OnReadStart() + { + } + + public static Http2MessageBody For( + FrameRequestHeaders headers, + Http2Stream context) + { + if (!context.ExpectBody) + { + return _emptyMessageBody; + } + + if (headers.ContentLength.HasValue) + { + var contentLength = headers.ContentLength.Value; + + return new ForContentLength(contentLength, context); + } + + return new ForRemainingData(context); + } + + private class ForEmpty : Http2MessageBody + { + public ForEmpty() + : base(context: null) + { + IsCompleted = true; + } + + public override Task OnDataAsync(ArraySegment data, bool endStream) + { + throw new NotImplementedException(); + } + + public override Task ReadAsync(ArraySegment buffer, CancellationToken cancellationToken) + { + return Task.FromResult(0); + } + + public override Task CopyToAsync(Stream destination, CancellationToken cancellationToken) + { + return Task.CompletedTask; + } + } + + private class ForRemainingData : Http2MessageBody + { + public ForRemainingData(Http2Stream context) + : base(context) + { + } + + protected override bool Read(Span data, WritableBuffer writableBuffer) + { + Copy(data, writableBuffer); + return false; + } + } + + private class ForContentLength : Http2MessageBody + { + private readonly long _contentLength; + private long _inputLength; + + public ForContentLength(long contentLength, Http2Stream context) + : base(context) + { + _contentLength = contentLength; + _inputLength = _contentLength; + } + + protected override bool Read(Span data, WritableBuffer writableBuffer) + { + if (_inputLength == 0) + { + throw new InvalidOperationException("Attempted to read from completed Content-Length request body."); + } + + if (data.Length > _inputLength) + { + _context.ThrowRequestRejected(RequestRejectionReason.RequestBodyExceedsContentLength); + } + + _inputLength -= data.Length; + + Copy(data, writableBuffer); + + return _inputLength == 0; + } + + protected override void OnReadStart() + { + if (_contentLength > _context.MaxRequestBodySize) + { + _context.ThrowRequestRejected(RequestRejectionReason.RequestBodyTooLarge); + } + } + } + } +} diff --git a/src/Kestrel.Core/Internal/Http2/Http2PeerSetting.cs b/src/Kestrel.Core/Internal/Http2/Http2PeerSetting.cs new file mode 100644 index 0000000000..f21b3ca929 --- /dev/null +++ b/src/Kestrel.Core/Internal/Http2/Http2PeerSetting.cs @@ -0,0 +1,18 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 +{ + public struct Http2PeerSetting + { + public Http2PeerSetting(Http2SettingsParameter parameter, uint value) + { + Parameter = parameter; + Value = value; + } + + public Http2SettingsParameter Parameter { get; } + + public uint Value { get; } + } +} diff --git a/src/Kestrel.Core/Internal/Http2/Http2PeerSettings.cs b/src/Kestrel.Core/Internal/Http2/Http2PeerSettings.cs new file mode 100644 index 0000000000..af94d593df --- /dev/null +++ b/src/Kestrel.Core/Internal/Http2/Http2PeerSettings.cs @@ -0,0 +1,106 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Collections; +using System.Collections.Generic; + +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 +{ + public class Http2PeerSettings : IEnumerable + { + public const uint DefaultHeaderTableSize = 4096; + public const bool DefaultEnablePush = true; + public const uint DefaultMaxConcurrentStreams = uint.MaxValue; + public const uint DefaultInitialWindowSize = 65535; + public const uint DefaultMaxFrameSize = 16384; + public const uint DefaultMaxHeaderListSize = uint.MaxValue; + + public uint HeaderTableSize { get; set; } = DefaultHeaderTableSize; + + public bool EnablePush { get; set; } = DefaultEnablePush; + + public uint MaxConcurrentStreams { get; set; } = DefaultMaxConcurrentStreams; + + public uint InitialWindowSize { get; set; } = DefaultInitialWindowSize; + + public uint MaxFrameSize { get; set; } = DefaultMaxFrameSize; + + public uint MaxHeaderListSize { get; set; } = DefaultMaxHeaderListSize; + + public void ParseFrame(Http2Frame frame) + { + var settingsCount = frame.Length / 6; + + for (var i = 0; i < settingsCount; i++) + { + var offset = i * 6; + var id = (Http2SettingsParameter)((frame.Payload[offset] << 8) | frame.Payload[offset + 1]); + var value = (uint)((frame.Payload[offset + 2] << 24) + | (frame.Payload[offset + 3] << 16) + | (frame.Payload[offset + 4] << 8) + | frame.Payload[offset + 5]); + + switch (id) + { + case Http2SettingsParameter.SETTINGS_HEADER_TABLE_SIZE: + HeaderTableSize = value; + break; + case Http2SettingsParameter.SETTINGS_ENABLE_PUSH: + if (value != 0 && value != 1) + { + throw new Http2SettingsParameterOutOfRangeException(Http2SettingsParameter.SETTINGS_ENABLE_PUSH, + lowerBound: 0, + upperBound: 1); + } + + EnablePush = value == 1; + break; + case Http2SettingsParameter.SETTINGS_MAX_CONCURRENT_STREAMS: + MaxConcurrentStreams = value; + break; + case Http2SettingsParameter.SETTINGS_INITIAL_WINDOW_SIZE: + if (value > int.MaxValue) + { + throw new Http2SettingsParameterOutOfRangeException(Http2SettingsParameter.SETTINGS_INITIAL_WINDOW_SIZE, + lowerBound: 0, + upperBound: int.MaxValue); + } + + InitialWindowSize = value; + break; + case Http2SettingsParameter.SETTINGS_MAX_FRAME_SIZE: + if (value < Http2Frame.MinAllowedMaxFrameSize || value > Http2Frame.MaxAllowedMaxFrameSize) + { + throw new Http2SettingsParameterOutOfRangeException(Http2SettingsParameter.SETTINGS_MAX_FRAME_SIZE, + lowerBound: Http2Frame.MinAllowedMaxFrameSize, + upperBound: Http2Frame.MaxAllowedMaxFrameSize); + } + + MaxFrameSize = value; + break; + case Http2SettingsParameter.SETTINGS_MAX_HEADER_LIST_SIZE: + MaxHeaderListSize = value; + break; + default: + // http://httpwg.org/specs/rfc7540.html#rfc.section.6.5.2 + // + // An endpoint that receives a SETTINGS frame with any unknown or unsupported identifier MUST ignore that setting. + break; + } + } + } + + public IEnumerator GetEnumerator() + { + yield return new Http2PeerSetting(Http2SettingsParameter.SETTINGS_HEADER_TABLE_SIZE, HeaderTableSize); + yield return new Http2PeerSetting(Http2SettingsParameter.SETTINGS_ENABLE_PUSH, EnablePush ? 1u : 0); + yield return new Http2PeerSetting(Http2SettingsParameter.SETTINGS_MAX_CONCURRENT_STREAMS, MaxConcurrentStreams); + yield return new Http2PeerSetting(Http2SettingsParameter.SETTINGS_INITIAL_WINDOW_SIZE, InitialWindowSize); + yield return new Http2PeerSetting(Http2SettingsParameter.SETTINGS_MAX_FRAME_SIZE, MaxFrameSize); + yield return new Http2PeerSetting(Http2SettingsParameter.SETTINGS_MAX_HEADER_LIST_SIZE, MaxHeaderListSize); + } + + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); + } +} diff --git a/src/Kestrel.Core/Internal/Http2/Http2PingFrameFlags.cs b/src/Kestrel.Core/Internal/Http2/Http2PingFrameFlags.cs new file mode 100644 index 0000000000..da5163f7e7 --- /dev/null +++ b/src/Kestrel.Core/Internal/Http2/Http2PingFrameFlags.cs @@ -0,0 +1,14 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; + +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 +{ + [Flags] + public enum Http2PingFrameFlags : byte + { + NONE = 0x0, + ACK = 0x1 + } +} diff --git a/src/Kestrel.Core/Internal/Http2/Http2SettingsFrameFlags.cs b/src/Kestrel.Core/Internal/Http2/Http2SettingsFrameFlags.cs new file mode 100644 index 0000000000..5b0b8666cd --- /dev/null +++ b/src/Kestrel.Core/Internal/Http2/Http2SettingsFrameFlags.cs @@ -0,0 +1,14 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; + +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 +{ + [Flags] + public enum Http2SettingsFrameFlags : byte + { + NONE = 0x0, + ACK = 0x1, + } +} diff --git a/src/Kestrel.Core/Internal/Http2/Http2SettingsParameter.cs b/src/Kestrel.Core/Internal/Http2/Http2SettingsParameter.cs new file mode 100644 index 0000000000..918422a4c2 --- /dev/null +++ b/src/Kestrel.Core/Internal/Http2/Http2SettingsParameter.cs @@ -0,0 +1,15 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 +{ + public enum Http2SettingsParameter : ushort + { + SETTINGS_HEADER_TABLE_SIZE = 0x1, + SETTINGS_ENABLE_PUSH = 0x2, + SETTINGS_MAX_CONCURRENT_STREAMS = 0x3, + SETTINGS_INITIAL_WINDOW_SIZE = 0x4, + SETTINGS_MAX_FRAME_SIZE = 0x5, + SETTINGS_MAX_HEADER_LIST_SIZE = 0x6, + } +} diff --git a/src/Kestrel.Core/Internal/Http2/Http2SettingsParameterOutOfRangeException.cs b/src/Kestrel.Core/Internal/Http2/Http2SettingsParameterOutOfRangeException.cs new file mode 100644 index 0000000000..95db1c9d58 --- /dev/null +++ b/src/Kestrel.Core/Internal/Http2/Http2SettingsParameterOutOfRangeException.cs @@ -0,0 +1,18 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; + +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 +{ + public class Http2SettingsParameterOutOfRangeException : Exception + { + public Http2SettingsParameterOutOfRangeException(Http2SettingsParameter parameter, uint lowerBound, uint upperBound) + : base($"HTTP/2 SETTINGS parameter {parameter} must be set to a value between {lowerBound} and {upperBound}") + { + Parameter = parameter; + } + + public Http2SettingsParameter Parameter { get; } + } +} diff --git a/src/Kestrel.Core/Internal/Http2/Http2Stream.FeatureCollection.cs b/src/Kestrel.Core/Internal/Http2/Http2Stream.FeatureCollection.cs new file mode 100644 index 0000000000..2adb8074d7 --- /dev/null +++ b/src/Kestrel.Core/Internal/Http2/Http2Stream.FeatureCollection.cs @@ -0,0 +1,289 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Collections; +using System.Collections.Generic; +using System.IO; +using System.Net; +using System.Threading; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Http.Features; +using Microsoft.AspNetCore.Server.Kestrel.Core.Features; +using Microsoft.Extensions.Primitives; + +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 +{ + public partial class Http2Stream : IFeatureCollection, + IHttpRequestFeature, + IHttpResponseFeature, + IHttpUpgradeFeature, + IHttpConnectionFeature, + IHttpRequestLifetimeFeature, + IHttpRequestIdentifierFeature, + IHttpBodyControlFeature, + IHttpMaxRequestBodySizeFeature, + IHttpMinRequestBodyDataRateFeature, + IHttpMinResponseDataRateFeature, + IHttp2StreamIdFeature + { + // NOTE: When feature interfaces are added to or removed from this Frame class implementation, + // then the list of `implementedFeatures` in the generated code project MUST also be updated. + // See also: tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/FrameFeatureCollection.cs + + private int _featureRevision; + + private List> MaybeExtra; + + public void ResetFeatureCollection() + { + FastReset(); + MaybeExtra?.Clear(); + _featureRevision++; + } + + private object ExtraFeatureGet(Type key) + { + if (MaybeExtra == null) + { + return null; + } + for (var i = 0; i < MaybeExtra.Count; i++) + { + var kv = MaybeExtra[i]; + if (kv.Key == key) + { + return kv.Value; + } + } + return null; + } + + private void ExtraFeatureSet(Type key, object value) + { + if (MaybeExtra == null) + { + MaybeExtra = new List>(2); + } + + for (var i = 0; i < MaybeExtra.Count; i++) + { + if (MaybeExtra[i].Key == key) + { + MaybeExtra[i] = new KeyValuePair(key, value); + return; + } + } + MaybeExtra.Add(new KeyValuePair(key, value)); + } + + string IHttpRequestFeature.Protocol + { + get => HttpVersion; + set => throw new InvalidOperationException(); + } + + string IHttpRequestFeature.Scheme + { + get => Scheme ?? "http"; + set => Scheme = value; + } + + string IHttpRequestFeature.Method + { + get => Method; + set => Method = value; + } + + string IHttpRequestFeature.PathBase + { + get => PathBase ?? ""; + set => PathBase = value; + } + + string IHttpRequestFeature.Path + { + get => Path; + set => Path = value; + } + + string IHttpRequestFeature.QueryString + { + get => QueryString; + set => QueryString = value; + } + + string IHttpRequestFeature.RawTarget + { + get => RawTarget; + set => RawTarget = value; + } + + IHeaderDictionary IHttpRequestFeature.Headers + { + get => RequestHeaders; + set => RequestHeaders = value; + } + + Stream IHttpRequestFeature.Body + { + get => RequestBody; + set => RequestBody = value; + } + + int IHttpResponseFeature.StatusCode + { + get => StatusCode; + set => StatusCode = value; + } + + string IHttpResponseFeature.ReasonPhrase + { + get => ReasonPhrase; + set => ReasonPhrase = value; + } + + IHeaderDictionary IHttpResponseFeature.Headers + { + get => ResponseHeaders; + set => ResponseHeaders = value; + } + + Stream IHttpResponseFeature.Body + { + get => ResponseBody; + set => ResponseBody = value; + } + + CancellationToken IHttpRequestLifetimeFeature.RequestAborted + { + get => RequestAborted; + set => RequestAborted = value; + } + + bool IHttpResponseFeature.HasStarted => HasResponseStarted; + + bool IHttpUpgradeFeature.IsUpgradableRequest => false; + + bool IFeatureCollection.IsReadOnly => false; + + int IFeatureCollection.Revision => _featureRevision; + + IPAddress IHttpConnectionFeature.RemoteIpAddress + { + get => RemoteIpAddress; + set => RemoteIpAddress = value; + } + + IPAddress IHttpConnectionFeature.LocalIpAddress + { + get => LocalIpAddress; + set => LocalIpAddress = value; + } + + int IHttpConnectionFeature.RemotePort + { + get => RemotePort; + set => RemotePort = value; + } + + int IHttpConnectionFeature.LocalPort + { + get => LocalPort; + set => LocalPort = value; + } + + string IHttpConnectionFeature.ConnectionId + { + get => ConnectionIdFeature; + set => ConnectionIdFeature = value; + } + + string IHttpRequestIdentifierFeature.TraceIdentifier + { + get => TraceIdentifier; + set => TraceIdentifier = value; + } + + bool IHttpBodyControlFeature.AllowSynchronousIO + { + get => AllowSynchronousIO; + set => AllowSynchronousIO = value; + } + + bool IHttpMaxRequestBodySizeFeature.IsReadOnly => HasStartedConsumingRequestBody; + + long? IHttpMaxRequestBodySizeFeature.MaxRequestBodySize + { + get => MaxRequestBodySize; + set + { + if (HasStartedConsumingRequestBody) + { + throw new InvalidOperationException(CoreStrings.MaxRequestBodySizeCannotBeModifiedAfterRead); + } + if (value < 0) + { + throw new ArgumentOutOfRangeException(nameof(value), CoreStrings.NonNegativeNumberOrNullRequired); + } + + MaxRequestBodySize = value; + } + } + + MinDataRate IHttpMinRequestBodyDataRateFeature.MinDataRate + { + get => throw new NotImplementedException(); + set => throw new NotImplementedException(); + } + + MinDataRate IHttpMinResponseDataRateFeature.MinDataRate + { + get => throw new NotImplementedException(); + set => throw new NotImplementedException(); + } + + object IFeatureCollection.this[Type key] + { + get => FastFeatureGet(key); + set => FastFeatureSet(key, value); + } + + TFeature IFeatureCollection.Get() + { + return (TFeature)FastFeatureGet(typeof(TFeature)); + } + + void IFeatureCollection.Set(TFeature instance) + { + FastFeatureSet(typeof(TFeature), instance); + } + + void IHttpResponseFeature.OnStarting(Func callback, object state) + { + OnStarting(callback, state); + } + + void IHttpResponseFeature.OnCompleted(Func callback, object state) + { + OnCompleted(callback, state); + } + + Task IHttpUpgradeFeature.UpgradeAsync() + { + throw new NotImplementedException(); + } + + IEnumerator> IEnumerable>.GetEnumerator() => FastEnumerable().GetEnumerator(); + + IEnumerator IEnumerable.GetEnumerator() => FastEnumerable().GetEnumerator(); + + void IHttpRequestLifetimeFeature.Abort() + { + Abort(error: null); + } + + int IHttp2StreamIdFeature.StreamId => StreamId; + } +} diff --git a/src/Kestrel.Core/Internal/Http2/Http2Stream.Generated.cs b/src/Kestrel.Core/Internal/Http2/Http2Stream.Generated.cs new file mode 100644 index 0000000000..4652b01e41 --- /dev/null +++ b/src/Kestrel.Core/Internal/Http2/Http2Stream.Generated.cs @@ -0,0 +1,378 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Collections.Generic; + +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 +{ + public partial class Http2Stream + { + private static readonly Type IHttpRequestFeatureType = typeof(global::Microsoft.AspNetCore.Http.Features.IHttpRequestFeature); + private static readonly Type IHttpResponseFeatureType = typeof(global::Microsoft.AspNetCore.Http.Features.IHttpResponseFeature); + private static readonly Type IHttpRequestIdentifierFeatureType = typeof(global::Microsoft.AspNetCore.Http.Features.IHttpRequestIdentifierFeature); + private static readonly Type IServiceProvidersFeatureType = typeof(global::Microsoft.AspNetCore.Http.Features.IServiceProvidersFeature); + private static readonly Type IHttpRequestLifetimeFeatureType = typeof(global::Microsoft.AspNetCore.Http.Features.IHttpRequestLifetimeFeature); + private static readonly Type IHttpConnectionFeatureType = typeof(global::Microsoft.AspNetCore.Http.Features.IHttpConnectionFeature); + private static readonly Type IHttpAuthenticationFeatureType = typeof(global::Microsoft.AspNetCore.Http.Features.Authentication.IHttpAuthenticationFeature); + private static readonly Type IQueryFeatureType = typeof(global::Microsoft.AspNetCore.Http.Features.IQueryFeature); + private static readonly Type IFormFeatureType = typeof(global::Microsoft.AspNetCore.Http.Features.IFormFeature); + private static readonly Type IHttpUpgradeFeatureType = typeof(global::Microsoft.AspNetCore.Http.Features.IHttpUpgradeFeature); + private static readonly Type IResponseCookiesFeatureType = typeof(global::Microsoft.AspNetCore.Http.Features.IResponseCookiesFeature); + private static readonly Type IItemsFeatureType = typeof(global::Microsoft.AspNetCore.Http.Features.IItemsFeature); + private static readonly Type ITlsConnectionFeatureType = typeof(global::Microsoft.AspNetCore.Http.Features.ITlsConnectionFeature); + private static readonly Type IHttpWebSocketFeatureType = typeof(global::Microsoft.AspNetCore.Http.Features.IHttpWebSocketFeature); + private static readonly Type ISessionFeatureType = typeof(global::Microsoft.AspNetCore.Http.Features.ISessionFeature); + private static readonly Type IHttpMaxRequestBodySizeFeatureType = typeof(global::Microsoft.AspNetCore.Http.Features.IHttpMaxRequestBodySizeFeature); + private static readonly Type IHttpMinRequestBodyDataRateFeatureType = typeof(global::Microsoft.AspNetCore.Server.Kestrel.Core.Features.IHttpMinRequestBodyDataRateFeature); + private static readonly Type IHttpMinResponseDataRateFeatureType = typeof(global::Microsoft.AspNetCore.Server.Kestrel.Core.Features.IHttpMinResponseDataRateFeature); + private static readonly Type IHttpBodyControlFeatureType = typeof(global::Microsoft.AspNetCore.Http.Features.IHttpBodyControlFeature); + private static readonly Type IHttpSendFileFeatureType = typeof(global::Microsoft.AspNetCore.Http.Features.IHttpSendFileFeature); + private static readonly Type IHttp2StreamIdFeatureType = typeof(global::Microsoft.AspNetCore.Server.Kestrel.Core.Features.IHttp2StreamIdFeature); + + private object _currentIHttpRequestFeature; + private object _currentIHttpResponseFeature; + private object _currentIHttpRequestIdentifierFeature; + private object _currentIServiceProvidersFeature; + private object _currentIHttpRequestLifetimeFeature; + private object _currentIHttpConnectionFeature; + private object _currentIHttpAuthenticationFeature; + private object _currentIQueryFeature; + private object _currentIFormFeature; + private object _currentIHttpUpgradeFeature; + private object _currentIResponseCookiesFeature; + private object _currentIItemsFeature; + private object _currentITlsConnectionFeature; + private object _currentIHttpWebSocketFeature; + private object _currentISessionFeature; + private object _currentIHttpMaxRequestBodySizeFeature; + private object _currentIHttpMinRequestBodyDataRateFeature; + private object _currentIHttpMinResponseDataRateFeature; + private object _currentIHttpBodyControlFeature; + private object _currentIHttpSendFileFeature; + private object _currentIHttp2StreamIdFeature; + + private void FastReset() + { + _currentIHttpRequestFeature = this; + _currentIHttpResponseFeature = this; + _currentIHttpUpgradeFeature = this; + _currentIHttpRequestIdentifierFeature = this; + _currentIHttpRequestLifetimeFeature = this; + _currentIHttpConnectionFeature = this; + _currentIHttpMaxRequestBodySizeFeature = this; + _currentIHttpMinRequestBodyDataRateFeature = this; + _currentIHttpMinResponseDataRateFeature = this; + _currentIHttpBodyControlFeature = this; + _currentIHttp2StreamIdFeature = this; + + _currentIServiceProvidersFeature = null; + _currentIHttpAuthenticationFeature = null; + _currentIQueryFeature = null; + _currentIFormFeature = null; + _currentIResponseCookiesFeature = null; + _currentIItemsFeature = null; + _currentITlsConnectionFeature = null; + _currentIHttpWebSocketFeature = null; + _currentISessionFeature = null; + _currentIHttpSendFileFeature = null; + } + + internal object FastFeatureGet(Type key) + { + if (key == IHttpRequestFeatureType) + { + return _currentIHttpRequestFeature; + } + if (key == IHttpResponseFeatureType) + { + return _currentIHttpResponseFeature; + } + if (key == IHttpRequestIdentifierFeatureType) + { + return _currentIHttpRequestIdentifierFeature; + } + if (key == IServiceProvidersFeatureType) + { + return _currentIServiceProvidersFeature; + } + if (key == IHttpRequestLifetimeFeatureType) + { + return _currentIHttpRequestLifetimeFeature; + } + if (key == IHttpConnectionFeatureType) + { + return _currentIHttpConnectionFeature; + } + if (key == IHttpAuthenticationFeatureType) + { + return _currentIHttpAuthenticationFeature; + } + if (key == IQueryFeatureType) + { + return _currentIQueryFeature; + } + if (key == IFormFeatureType) + { + return _currentIFormFeature; + } + if (key == IHttpUpgradeFeatureType) + { + return _currentIHttpUpgradeFeature; + } + if (key == IResponseCookiesFeatureType) + { + return _currentIResponseCookiesFeature; + } + if (key == IItemsFeatureType) + { + return _currentIItemsFeature; + } + if (key == ITlsConnectionFeatureType) + { + return _currentITlsConnectionFeature; + } + if (key == IHttpWebSocketFeatureType) + { + return _currentIHttpWebSocketFeature; + } + if (key == ISessionFeatureType) + { + return _currentISessionFeature; + } + if (key == IHttpMaxRequestBodySizeFeatureType) + { + return _currentIHttpMaxRequestBodySizeFeature; + } + if (key == IHttpMinRequestBodyDataRateFeatureType) + { + return _currentIHttpMinRequestBodyDataRateFeature; + } + if (key == IHttpMinResponseDataRateFeatureType) + { + return _currentIHttpMinResponseDataRateFeature; + } + if (key == IHttpBodyControlFeatureType) + { + return _currentIHttpBodyControlFeature; + } + if (key == IHttpSendFileFeatureType) + { + return _currentIHttpSendFileFeature; + } + if (key == IHttp2StreamIdFeatureType) + { + return _currentIHttp2StreamIdFeature; + } + return ExtraFeatureGet(key); + } + + internal void FastFeatureSet(Type key, object feature) + { + _featureRevision++; + + if (key == IHttpRequestFeatureType) + { + _currentIHttpRequestFeature = feature; + return; + } + if (key == IHttpResponseFeatureType) + { + _currentIHttpResponseFeature = feature; + return; + } + if (key == IHttpRequestIdentifierFeatureType) + { + _currentIHttpRequestIdentifierFeature = feature; + return; + } + if (key == IServiceProvidersFeatureType) + { + _currentIServiceProvidersFeature = feature; + return; + } + if (key == IHttpRequestLifetimeFeatureType) + { + _currentIHttpRequestLifetimeFeature = feature; + return; + } + if (key == IHttpConnectionFeatureType) + { + _currentIHttpConnectionFeature = feature; + return; + } + if (key == IHttpAuthenticationFeatureType) + { + _currentIHttpAuthenticationFeature = feature; + return; + } + if (key == IQueryFeatureType) + { + _currentIQueryFeature = feature; + return; + } + if (key == IFormFeatureType) + { + _currentIFormFeature = feature; + return; + } + if (key == IHttpUpgradeFeatureType) + { + _currentIHttpUpgradeFeature = feature; + return; + } + if (key == IResponseCookiesFeatureType) + { + _currentIResponseCookiesFeature = feature; + return; + } + if (key == IItemsFeatureType) + { + _currentIItemsFeature = feature; + return; + } + if (key == ITlsConnectionFeatureType) + { + _currentITlsConnectionFeature = feature; + return; + } + if (key == IHttpWebSocketFeatureType) + { + _currentIHttpWebSocketFeature = feature; + return; + } + if (key == ISessionFeatureType) + { + _currentISessionFeature = feature; + return; + } + if (key == IHttpMaxRequestBodySizeFeatureType) + { + _currentIHttpMaxRequestBodySizeFeature = feature; + return; + } + if (key == IHttpMinRequestBodyDataRateFeatureType) + { + _currentIHttpMinRequestBodyDataRateFeature = feature; + return; + } + if (key == IHttpMinResponseDataRateFeatureType) + { + _currentIHttpMinResponseDataRateFeature = feature; + return; + } + if (key == IHttpBodyControlFeatureType) + { + _currentIHttpBodyControlFeature = feature; + return; + } + if (key == IHttpSendFileFeatureType) + { + _currentIHttpSendFileFeature = feature; + return; + } + if (key == IHttp2StreamIdFeatureType) + { + _currentIHttp2StreamIdFeature = feature; + return; + }; + ExtraFeatureSet(key, feature); + } + + private IEnumerable> FastEnumerable() + { + if (_currentIHttpRequestFeature != null) + { + yield return new KeyValuePair(IHttpRequestFeatureType, _currentIHttpRequestFeature as global::Microsoft.AspNetCore.Http.Features.IHttpRequestFeature); + } + if (_currentIHttpResponseFeature != null) + { + yield return new KeyValuePair(IHttpResponseFeatureType, _currentIHttpResponseFeature as global::Microsoft.AspNetCore.Http.Features.IHttpResponseFeature); + } + if (_currentIHttpRequestIdentifierFeature != null) + { + yield return new KeyValuePair(IHttpRequestIdentifierFeatureType, _currentIHttpRequestIdentifierFeature as global::Microsoft.AspNetCore.Http.Features.IHttpRequestIdentifierFeature); + } + if (_currentIServiceProvidersFeature != null) + { + yield return new KeyValuePair(IServiceProvidersFeatureType, _currentIServiceProvidersFeature as global::Microsoft.AspNetCore.Http.Features.IServiceProvidersFeature); + } + if (_currentIHttpRequestLifetimeFeature != null) + { + yield return new KeyValuePair(IHttpRequestLifetimeFeatureType, _currentIHttpRequestLifetimeFeature as global::Microsoft.AspNetCore.Http.Features.IHttpRequestLifetimeFeature); + } + if (_currentIHttpConnectionFeature != null) + { + yield return new KeyValuePair(IHttpConnectionFeatureType, _currentIHttpConnectionFeature as global::Microsoft.AspNetCore.Http.Features.IHttpConnectionFeature); + } + if (_currentIHttpAuthenticationFeature != null) + { + yield return new KeyValuePair(IHttpAuthenticationFeatureType, _currentIHttpAuthenticationFeature as global::Microsoft.AspNetCore.Http.Features.Authentication.IHttpAuthenticationFeature); + } + if (_currentIQueryFeature != null) + { + yield return new KeyValuePair(IQueryFeatureType, _currentIQueryFeature as global::Microsoft.AspNetCore.Http.Features.IQueryFeature); + } + if (_currentIFormFeature != null) + { + yield return new KeyValuePair(IFormFeatureType, _currentIFormFeature as global::Microsoft.AspNetCore.Http.Features.IFormFeature); + } + if (_currentIHttpUpgradeFeature != null) + { + yield return new KeyValuePair(IHttpUpgradeFeatureType, _currentIHttpUpgradeFeature as global::Microsoft.AspNetCore.Http.Features.IHttpUpgradeFeature); + } + if (_currentIResponseCookiesFeature != null) + { + yield return new KeyValuePair(IResponseCookiesFeatureType, _currentIResponseCookiesFeature as global::Microsoft.AspNetCore.Http.Features.IResponseCookiesFeature); + } + if (_currentIItemsFeature != null) + { + yield return new KeyValuePair(IItemsFeatureType, _currentIItemsFeature as global::Microsoft.AspNetCore.Http.Features.IItemsFeature); + } + if (_currentITlsConnectionFeature != null) + { + yield return new KeyValuePair(ITlsConnectionFeatureType, _currentITlsConnectionFeature as global::Microsoft.AspNetCore.Http.Features.ITlsConnectionFeature); + } + if (_currentIHttpWebSocketFeature != null) + { + yield return new KeyValuePair(IHttpWebSocketFeatureType, _currentIHttpWebSocketFeature as global::Microsoft.AspNetCore.Http.Features.IHttpWebSocketFeature); + } + if (_currentISessionFeature != null) + { + yield return new KeyValuePair(ISessionFeatureType, _currentISessionFeature as global::Microsoft.AspNetCore.Http.Features.ISessionFeature); + } + if (_currentIHttpMaxRequestBodySizeFeature != null) + { + yield return new KeyValuePair(IHttpMaxRequestBodySizeFeatureType, _currentIHttpMaxRequestBodySizeFeature as global::Microsoft.AspNetCore.Http.Features.IHttpMaxRequestBodySizeFeature); + } + if (_currentIHttpMinRequestBodyDataRateFeature != null) + { + yield return new KeyValuePair(IHttpMinRequestBodyDataRateFeatureType, _currentIHttpMinRequestBodyDataRateFeature as global::Microsoft.AspNetCore.Server.Kestrel.Core.Features.IHttpMinRequestBodyDataRateFeature); + } + if (_currentIHttpMinResponseDataRateFeature != null) + { + yield return new KeyValuePair(IHttpMinResponseDataRateFeatureType, _currentIHttpMinResponseDataRateFeature as global::Microsoft.AspNetCore.Server.Kestrel.Core.Features.IHttpMinResponseDataRateFeature); + } + if (_currentIHttpBodyControlFeature != null) + { + yield return new KeyValuePair(IHttpBodyControlFeatureType, _currentIHttpBodyControlFeature as global::Microsoft.AspNetCore.Http.Features.IHttpBodyControlFeature); + } + if (_currentIHttpSendFileFeature != null) + { + yield return new KeyValuePair(IHttpSendFileFeatureType, _currentIHttpSendFileFeature as global::Microsoft.AspNetCore.Http.Features.IHttpSendFileFeature); + } + if (_currentIHttp2StreamIdFeature != null) + { + yield return new KeyValuePair(IHttp2StreamIdFeatureType, _currentIHttp2StreamIdFeature as global::Microsoft.AspNetCore.Server.Kestrel.Core.Features.IHttp2StreamIdFeature); + } + + if (MaybeExtra != null) + { + foreach(var item in MaybeExtra) + { + yield return item; + } + } + } + } +} diff --git a/src/Kestrel.Core/Internal/Http2/Http2Stream.cs b/src/Kestrel.Core/Internal/Http2/Http2Stream.cs new file mode 100644 index 0000000000..0415cb3449 --- /dev/null +++ b/src/Kestrel.Core/Internal/Http2/Http2Stream.cs @@ -0,0 +1,1031 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.IO; +using System.IO.Pipelines; +using System.Linq; +using System.Net; +using System.Text; +using System.Text.Encodings.Web.Utf8; +using System.Threading; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Http.Features; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; +using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Primitives; + +// ReSharper disable AccessToModifiedClosure + +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 +{ + public abstract partial class Http2Stream : IFrameControl + { + private const byte ByteAsterisk = (byte)'*'; + private const byte ByteForwardSlash = (byte)'/'; + private const byte BytePercentage = (byte)'%'; + + private static readonly byte[] _bytesServer = Encoding.ASCII.GetBytes("\r\nServer: " + Constants.ServerName); + + private const string EmptyPath = "/"; + private const string Asterisk = "*"; + + private readonly object _onStartingSync = new Object(); + private readonly object _onCompletedSync = new Object(); + + private Http2StreamContext _context; + private Http2Streams _streams; + + protected Stack, object>> _onStarting; + protected Stack, object>> _onCompleted; + + protected int _requestAborted; + private CancellationTokenSource _abortedCts; + private CancellationToken? _manuallySetRequestAbortToken; + + protected RequestProcessingStatus _requestProcessingStatus; + private bool _canHaveBody; + protected Exception _applicationException; + private BadHttpRequestException _requestRejectedException; + + private string _requestId; + + protected long _responseBytesWritten; + + private HttpRequestTarget _requestTargetForm = HttpRequestTarget.Unknown; + private Uri _absoluteRequestTarget; + + public Http2Stream(Http2StreamContext context) + { + _context = context; + HttpStreamControl = this; + ServerOptions = context.ServiceContext.ServerOptions; + RequestBodyPipe = CreateRequestBodyPipe(); + } + + public IFrameControl HttpStreamControl { get; set; } + + public Http2MessageBody MessageBody { get; protected set; } + public IPipe RequestBodyPipe { get; } + + protected string ConnectionId => _context.ConnectionId; + public int StreamId => _context.StreamId; + public ServiceContext ServiceContext => _context.ServiceContext; + + // Hold direct reference to ServerOptions since this is used very often in the request processing path + private KestrelServerOptions ServerOptions { get; } + + public IFeatureCollection ConnectionFeatures { get; set; } + protected IHttp2StreamLifetimeHandler StreamLifetimeHandler => _context.StreamLifetimeHandler; + public IHttp2FrameWriter Output => _context.FrameWriter; + + protected IKestrelTrace Log => ServiceContext.Log; + private DateHeaderValueManager DateHeaderValueManager => ServiceContext.DateHeaderValueManager; + + private IPEndPoint LocalEndPoint => _context.LocalEndPoint; + private IPEndPoint RemoteEndPoint => _context.RemoteEndPoint; + + public string ConnectionIdFeature { get; set; } + public bool HasStartedConsumingRequestBody { get; set; } + public long? MaxRequestBodySize { get; set; } + public bool AllowSynchronousIO { get; set; } + + public bool ExpectBody { get; set; } + + /// + /// The request id. + /// + public string TraceIdentifier + { + set => _requestId = value; + get + { + // don't generate an ID until it is requested + if (_requestId == null) + { + _requestId = StringUtilities.ConcatAsHexSuffix(ConnectionId, ':', (uint)StreamId); + } + return _requestId; + } + } + + public IPAddress RemoteIpAddress { get; set; } + public int RemotePort { get; set; } + public IPAddress LocalIpAddress { get; set; } + public int LocalPort { get; set; } + public string Scheme { get; set; } + public string Method { get; set; } + public string PathBase { get; set; } + public string Path { get; set; } + public string QueryString { get; set; } + public string RawTarget { get; set; } + + public string HttpVersion => "HTTP/2"; + + public IHeaderDictionary RequestHeaders { get; set; } + public Stream RequestBody { get; set; } + + private int _statusCode; + public int StatusCode + { + get => _statusCode; + set + { + if (HasResponseStarted) + { + ThrowResponseAlreadyStartedException(nameof(StatusCode)); + } + + _statusCode = value; + } + } + + private string _reasonPhrase; + + public string ReasonPhrase + { + get => _reasonPhrase; + + set + { + if (HasResponseStarted) + { + ThrowResponseAlreadyStartedException(nameof(ReasonPhrase)); + } + + _reasonPhrase = value; + } + } + + public IHeaderDictionary ResponseHeaders { get; set; } + public Stream ResponseBody { get; set; } + + public CancellationToken RequestAborted + { + get + { + // If a request abort token was previously explicitly set, return it. + if (_manuallySetRequestAbortToken.HasValue) + { + return _manuallySetRequestAbortToken.Value; + } + // Otherwise, get the abort CTS. If we have one, which would mean that someone previously + // asked for the RequestAborted token, simply return its token. If we don't, + // check to see whether we've already aborted, in which case just return an + // already canceled token. Finally, force a source into existence if we still + // don't have one, and return its token. + var cts = _abortedCts; + return + cts != null ? cts.Token : + (Volatile.Read(ref _requestAborted) == 1) ? new CancellationToken(true) : + RequestAbortedSource.Token; + } + set + { + // Set an abort token, overriding one we create internally. This setter and associated + // field exist purely to support IHttpRequestLifetimeFeature.set_RequestAborted. + _manuallySetRequestAbortToken = value; + } + } + + private CancellationTokenSource RequestAbortedSource + { + get + { + // Get the abort token, lazily-initializing it if necessary. + // Make sure it's canceled if an abort request already came in. + + // EnsureInitialized can return null since _abortedCts is reset to null + // after it's already been initialized to a non-null value. + // If EnsureInitialized does return null, this property was accessed between + // requests so it's safe to return an ephemeral CancellationTokenSource. + var cts = LazyInitializer.EnsureInitialized(ref _abortedCts, () => new CancellationTokenSource()) + ?? new CancellationTokenSource(); + + if (Volatile.Read(ref _requestAborted) == 1) + { + cts.Cancel(); + } + return cts; + } + } + + public bool HasResponseStarted => _requestProcessingStatus == RequestProcessingStatus.ResponseStarted; + + protected FrameRequestHeaders FrameRequestHeaders { get; } = new FrameRequestHeaders(); + + protected FrameResponseHeaders FrameResponseHeaders { get; } = new FrameResponseHeaders(); + + public void InitializeStreams(Http2MessageBody messageBody) + { + if (_streams == null) + { + _streams = new Http2Streams(bodyControl: this, httpStreamControl: this); + } + + (RequestBody, ResponseBody) = _streams.Start(messageBody); + } + + public void PauseStreams() => _streams.Pause(); + + public void StopStreams() => _streams.Stop(); + + public void Reset() + { + _onStarting = null; + _onCompleted = null; + + _requestProcessingStatus = RequestProcessingStatus.RequestPending; + _applicationException = null; + + ResetFeatureCollection(); + + HasStartedConsumingRequestBody = false; + MaxRequestBodySize = ServerOptions.Limits.MaxRequestBodySize; + AllowSynchronousIO = ServerOptions.AllowSynchronousIO; + TraceIdentifier = null; + Scheme = null; + Method = null; + PathBase = null; + Path = null; + RawTarget = null; + _requestTargetForm = HttpRequestTarget.Unknown; + _absoluteRequestTarget = null; + QueryString = null; + StatusCode = StatusCodes.Status200OK; + ReasonPhrase = null; + + RemoteIpAddress = RemoteEndPoint?.Address; + RemotePort = RemoteEndPoint?.Port ?? 0; + + LocalIpAddress = LocalEndPoint?.Address; + LocalPort = LocalEndPoint?.Port ?? 0; + ConnectionIdFeature = ConnectionId; + + FrameRequestHeaders.Reset(); + FrameResponseHeaders.Reset(); + RequestHeaders = FrameRequestHeaders; + ResponseHeaders = FrameResponseHeaders; + + if (ConnectionFeatures != null) + { + foreach (var feature in ConnectionFeatures) + { + // Set the scheme to https if there's an ITlsConnectionFeature + if (feature.Key == typeof(ITlsConnectionFeature)) + { + Scheme = "https"; + } + + FastFeatureSet(feature.Key, feature.Value); + } + } + + _manuallySetRequestAbortToken = null; + _abortedCts = null; + + _responseBytesWritten = 0; + } + + private void CancelRequestAbortedToken() + { + try + { + RequestAbortedSource.Cancel(); + _abortedCts = null; + } + catch (Exception ex) + { + Log.ApplicationError(ConnectionId, TraceIdentifier, ex); + } + } + + public void Abort(Exception error) + { + if (Interlocked.Exchange(ref _requestAborted, 1) == 0) + { + _streams?.Abort(error); + + // Potentially calling user code. CancelRequestAbortedToken logs any exceptions. + ServiceContext.ThreadPool.UnsafeRun(state => ((Http2Stream)state).CancelRequestAbortedToken(), this); + } + } + + public abstract Task ProcessRequestAsync(); + + public void OnStarting(Func callback, object state) + { + lock (_onStartingSync) + { + if (HasResponseStarted) + { + ThrowResponseAlreadyStartedException(nameof(OnStarting)); + } + + if (_onStarting == null) + { + _onStarting = new Stack, object>>(); + } + _onStarting.Push(new KeyValuePair, object>(callback, state)); + } + } + + public void OnCompleted(Func callback, object state) + { + lock (_onCompletedSync) + { + if (_onCompleted == null) + { + _onCompleted = new Stack, object>>(); + } + _onCompleted.Push(new KeyValuePair, object>(callback, state)); + } + } + + protected async Task FireOnStarting() + { + Stack, object>> onStarting = null; + lock (_onStartingSync) + { + onStarting = _onStarting; + _onStarting = null; + } + if (onStarting != null) + { + try + { + foreach (var entry in onStarting) + { + await entry.Key.Invoke(entry.Value); + } + } + catch (Exception ex) + { + ReportApplicationError(ex); + } + } + } + + protected async Task FireOnCompleted() + { + Stack, object>> onCompleted = null; + lock (_onCompletedSync) + { + onCompleted = _onCompleted; + _onCompleted = null; + } + if (onCompleted != null) + { + foreach (var entry in onCompleted) + { + try + { + await entry.Key.Invoke(entry.Value); + } + catch (Exception ex) + { + ReportApplicationError(ex); + } + } + } + } + + public async Task FlushAsync(CancellationToken cancellationToken = default(CancellationToken)) + { + await InitializeResponse(0); + await Output.FlushAsync(cancellationToken); + } + + public Task WriteAsync(ArraySegment data, CancellationToken cancellationToken = default(CancellationToken)) + { + if (!HasResponseStarted) + { + return WriteAsyncAwaited(data, cancellationToken); + } + + VerifyAndUpdateWrite(data.Count); + + if (_canHaveBody) + { + CheckLastWrite(); + return Output.WriteDataAsync(StreamId, data, cancellationToken: cancellationToken); + } + else + { + HandleNonBodyResponseWrite(); + return Task.CompletedTask; + } + } + + public async Task WriteAsyncAwaited(ArraySegment data, CancellationToken cancellationToken) + { + await InitializeResponseAwaited(data.Count); + + // WriteAsyncAwaited is only called for the first write to the body. + // Ensure headers are flushed if Write(Chunked)Async isn't called. + if (_canHaveBody) + { + CheckLastWrite(); + await Output.WriteDataAsync(StreamId, data, cancellationToken: cancellationToken); + } + else + { + HandleNonBodyResponseWrite(); + await FlushAsync(cancellationToken); + } + } + + private void VerifyAndUpdateWrite(int count) + { + var responseHeaders = FrameResponseHeaders; + + if (responseHeaders != null && + !responseHeaders.HasTransferEncoding && + responseHeaders.ContentLength.HasValue && + _responseBytesWritten + count > responseHeaders.ContentLength.Value) + { + throw new InvalidOperationException( + CoreStrings.FormatTooManyBytesWritten(_responseBytesWritten + count, responseHeaders.ContentLength.Value)); + } + + _responseBytesWritten += count; + } + + private void CheckLastWrite() + { + var responseHeaders = FrameResponseHeaders; + + // Prevent firing request aborted token if this is the last write, to avoid + // aborting the request if the app is still running when the client receives + // the final bytes of the response and gracefully closes the connection. + // + // Called after VerifyAndUpdateWrite(), so _responseBytesWritten has already been updated. + if (responseHeaders != null && + !responseHeaders.HasTransferEncoding && + responseHeaders.ContentLength.HasValue && + _responseBytesWritten == responseHeaders.ContentLength.Value) + { + _abortedCts = null; + } + } + + protected void VerifyResponseContentLength() + { + var responseHeaders = FrameResponseHeaders; + + if (!HttpMethods.IsHead(Method) && + !responseHeaders.HasTransferEncoding && + responseHeaders.ContentLength.HasValue && + _responseBytesWritten < responseHeaders.ContentLength.Value) + { + // We need to close the connection if any bytes were written since the client + // cannot be certain of how many bytes it will receive. + if (_responseBytesWritten > 0) + { + // TODO: HTTP/2 + } + + ReportApplicationError(new InvalidOperationException( + CoreStrings.FormatTooFewBytesWritten(_responseBytesWritten, responseHeaders.ContentLength.Value))); + } + } + + private static ArraySegment CreateAsciiByteArraySegment(string text) + { + var bytes = Encoding.ASCII.GetBytes(text); + return new ArraySegment(bytes); + } + + public void ProduceContinue() + { + if (HasResponseStarted) + { + return; + } + + if (RequestHeaders.TryGetValue("Expect", out var expect) && + (expect.FirstOrDefault() ?? "").Equals("100-continue", StringComparison.OrdinalIgnoreCase)) + { + Output.Write100ContinueAsync(StreamId).GetAwaiter().GetResult(); + } + } + + public Task InitializeResponse(int firstWriteByteCount) + { + if (HasResponseStarted) + { + return Task.CompletedTask; + } + + if (_onStarting != null) + { + return InitializeResponseAwaited(firstWriteByteCount); + } + + if (_applicationException != null) + { + ThrowResponseAbortedException(); + } + + VerifyAndUpdateWrite(firstWriteByteCount); + + return ProduceStart(appCompleted: false); + } + + private async Task InitializeResponseAwaited(int firstWriteByteCount) + { + await FireOnStarting(); + + if (_applicationException != null) + { + ThrowResponseAbortedException(); + } + + VerifyAndUpdateWrite(firstWriteByteCount); + + await ProduceStart(appCompleted: false); + } + + private Task ProduceStart(bool appCompleted) + { + if (HasResponseStarted) + { + return Task.CompletedTask; + } + + _requestProcessingStatus = RequestProcessingStatus.ResponseStarted; + + return CreateResponseHeader(appCompleted); + } + + protected Task TryProduceInvalidRequestResponse() + { + if (_requestRejectedException != null) + { + return ProduceEnd(); + } + + return Task.CompletedTask; + } + + protected Task ProduceEnd() + { + if (_requestRejectedException != null || _applicationException != null) + { + if (HasResponseStarted) + { + // We can no longer change the response, so we simply close the connection. + return Task.CompletedTask; + } + + // If the request was rejected, the error state has already been set by SetBadRequestState and + // that should take precedence. + if (_requestRejectedException != null) + { + SetErrorResponseException(_requestRejectedException); + } + else + { + // 500 Internal Server Error + SetErrorResponseHeaders(statusCode: StatusCodes.Status500InternalServerError); + } + } + + if (!HasResponseStarted) + { + return ProduceEndAwaited(); + } + + return WriteSuffix(); + } + + private async Task ProduceEndAwaited() + { + await ProduceStart(appCompleted: true); + + // Force flush + await Output.FlushAsync(default(CancellationToken)); + + await WriteSuffix(); + } + + private Task WriteSuffix() + { + if (HttpMethods.IsHead(Method) && _responseBytesWritten > 0) + { + Log.ConnectionHeadResponseBodyWrite(ConnectionId, _responseBytesWritten); + } + + return Output.WriteDataAsync(StreamId, Span.Empty, endStream: true, cancellationToken: default(CancellationToken)); + } + + private Task CreateResponseHeader(bool appCompleted) + { + var responseHeaders = FrameResponseHeaders; + var hasConnection = responseHeaders.HasConnection; + var connectionOptions = FrameHeaders.ParseConnection(responseHeaders.HeaderConnection); + var hasTransferEncoding = responseHeaders.HasTransferEncoding; + var transferCoding = FrameHeaders.GetFinalTransferCoding(responseHeaders.HeaderTransferEncoding); + + // https://tools.ietf.org/html/rfc7230#section-3.3.1 + // If any transfer coding other than + // chunked is applied to a response payload body, the sender MUST either + // apply chunked as the final transfer coding or terminate the message + // by closing the connection. + if (hasTransferEncoding && transferCoding == TransferCoding.Chunked) + { + // TODO: this is an error in HTTP/2 + } + + // Set whether response can have body + _canHaveBody = StatusCanHaveBody(StatusCode) && Method != "HEAD"; + + // Don't set the Content-Length or Transfer-Encoding headers + // automatically for HEAD requests or 204, 205, 304 responses. + if (_canHaveBody) + { + if (appCompleted) + { + // Since the app has completed and we are only now generating + // the headers we can safely set the Content-Length to 0. + responseHeaders.ContentLength = 0; + } + } + else if (hasTransferEncoding) + { + RejectNonBodyTransferEncodingResponse(appCompleted); + } + + responseHeaders.SetReadOnly(); + + if (ServerOptions.AddServerHeader && !responseHeaders.HasServer) + { + responseHeaders.SetRawServer(Constants.ServerName, _bytesServer); + } + + if (!responseHeaders.HasDate) + { + var dateHeaderValues = DateHeaderValueManager.GetDateHeaderValues(); + responseHeaders.SetRawDate(dateHeaderValues.String, dateHeaderValues.Bytes); + } + + return Output.WriteHeadersAsync(StreamId, StatusCode, responseHeaders); + } + + public bool StatusCanHaveBody(int statusCode) + { + // List of status codes taken from Microsoft.Net.Http.Server.Response + return statusCode != StatusCodes.Status204NoContent && + statusCode != StatusCodes.Status205ResetContent && + statusCode != StatusCodes.Status304NotModified; + } + + private void ThrowResponseAlreadyStartedException(string value) + { + throw new InvalidOperationException(CoreStrings.FormatParameterReadOnlyAfterResponseStarted(value)); + } + + private void RejectNonBodyTransferEncodingResponse(bool appCompleted) + { + var ex = new InvalidOperationException(CoreStrings.FormatHeaderNotAllowedOnResponse("Transfer-Encoding", StatusCode)); + if (!appCompleted) + { + // Back out of header creation surface exeception in user code + _requestProcessingStatus = RequestProcessingStatus.AppStarted; + throw ex; + } + else + { + ReportApplicationError(ex); + + // 500 Internal Server Error + SetErrorResponseHeaders(statusCode: StatusCodes.Status500InternalServerError); + } + } + + private void SetErrorResponseException(BadHttpRequestException ex) + { + SetErrorResponseHeaders(ex.StatusCode); + + if (!StringValues.IsNullOrEmpty(ex.AllowedHeader)) + { + FrameResponseHeaders.HeaderAllow = ex.AllowedHeader; + } + } + + private void SetErrorResponseHeaders(int statusCode) + { + Debug.Assert(!HasResponseStarted, $"{nameof(SetErrorResponseHeaders)} called after response had already started."); + + StatusCode = statusCode; + ReasonPhrase = null; + + var responseHeaders = FrameResponseHeaders; + responseHeaders.Reset(); + var dateHeaderValues = DateHeaderValueManager.GetDateHeaderValues(); + + responseHeaders.SetRawDate(dateHeaderValues.String, dateHeaderValues.Bytes); + + responseHeaders.ContentLength = 0; + + if (ServerOptions.AddServerHeader) + { + responseHeaders.SetRawServer(Constants.ServerName, _bytesServer); + } + } + + public void HandleNonBodyResponseWrite() + { + // Writes to HEAD response are ignored and logged at the end of the request + if (Method != "HEAD") + { + // Throw Exception for 204, 205, 304 responses. + throw new InvalidOperationException(CoreStrings.FormatWritingToResponseBodyNotSupported(StatusCode)); + } + } + + private void ThrowResponseAbortedException() + { + throw new ObjectDisposedException(CoreStrings.UnhandledApplicationException, _applicationException); + } + + public void ThrowRequestRejected(RequestRejectionReason reason) + => throw BadHttpRequestException.GetException(reason); + + public void ThrowRequestRejected(RequestRejectionReason reason, string detail) + => throw BadHttpRequestException.GetException(reason, detail); + + private void ThrowRequestTargetRejected(Span target) + => throw GetInvalidRequestTargetException(target); + + private BadHttpRequestException GetInvalidRequestTargetException(Span target) + => BadHttpRequestException.GetException( + RequestRejectionReason.InvalidRequestTarget, + Log.IsEnabled(LogLevel.Information) + ? target.GetAsciiStringEscaped(Constants.MaxExceptionDetailSize) + : string.Empty); + + public void SetBadRequestState(RequestRejectionReason reason) + { + SetBadRequestState(BadHttpRequestException.GetException(reason)); + } + + public void SetBadRequestState(BadHttpRequestException ex) + { + Log.ConnectionBadRequest(ConnectionId, ex); + + if (!HasResponseStarted) + { + SetErrorResponseException(ex); + } + + _requestRejectedException = ex; + } + + protected void ReportApplicationError(Exception ex) + { + if (_applicationException == null) + { + _applicationException = ex; + } + else if (_applicationException is AggregateException) + { + _applicationException = new AggregateException(_applicationException, ex).Flatten(); + } + else + { + _applicationException = new AggregateException(_applicationException, ex); + } + + Log.ApplicationError(ConnectionId, TraceIdentifier, ex); + } + + private void OnOriginFormTarget(HttpMethod method, Http.HttpVersion version, Span target, Span path, Span query, Span customMethod, bool pathEncoded) + { + Debug.Assert(target[0] == ByteForwardSlash, "Should only be called when path starts with /"); + + _requestTargetForm = HttpRequestTarget.OriginForm; + + // URIs are always encoded/escaped to ASCII https://tools.ietf.org/html/rfc3986#page-11 + // Multibyte Internationalized Resource Identifiers (IRIs) are first converted to utf8; + // then encoded/escaped to ASCII https://www.ietf.org/rfc/rfc3987.txt "Mapping of IRIs to URIs" + string requestUrlPath = null; + string rawTarget = null; + + try + { + // Read raw target before mutating memory. + rawTarget = target.GetAsciiStringNonNullCharacters(); + + if (pathEncoded) + { + // URI was encoded, unescape and then parse as UTF-8 + var pathLength = UrlEncoder.Decode(path, path); + + // Removing dot segments must be done after unescaping. From RFC 3986: + // + // URI producing applications should percent-encode data octets that + // correspond to characters in the reserved set unless these characters + // are specifically allowed by the URI scheme to represent data in that + // component. If a reserved character is found in a URI component and + // no delimiting role is known for that character, then it must be + // interpreted as representing the data octet corresponding to that + // character's encoding in US-ASCII. + // + // https://tools.ietf.org/html/rfc3986#section-2.2 + pathLength = PathNormalizer.RemoveDotSegments(path.Slice(0, pathLength)); + + requestUrlPath = GetUtf8String(path.Slice(0, pathLength)); + } + else + { + var pathLength = PathNormalizer.RemoveDotSegments(path); + + if (path.Length == pathLength && query.Length == 0) + { + // If no decoding was required, no dot segments were removed and + // there is no query, the request path is the same as the raw target + requestUrlPath = rawTarget; + } + else + { + requestUrlPath = path.Slice(0, pathLength).GetAsciiStringNonNullCharacters(); + } + } + } + catch (InvalidOperationException) + { + ThrowRequestTargetRejected(target); + } + + QueryString = query.GetAsciiStringNonNullCharacters(); + RawTarget = rawTarget; + Path = requestUrlPath; + } + + private void OnAuthorityFormTarget(HttpMethod method, Span target) + { + _requestTargetForm = HttpRequestTarget.AuthorityForm; + + // This is not complete validation. It is just a quick scan for invalid characters + // but doesn't check that the target fully matches the URI spec. + for (var i = 0; i < target.Length; i++) + { + var ch = target[i]; + if (!UriUtilities.IsValidAuthorityCharacter(ch)) + { + ThrowRequestTargetRejected(target); + } + } + + // The authority-form of request-target is only used for CONNECT + // requests (https://tools.ietf.org/html/rfc7231#section-4.3.6). + if (method != HttpMethod.Connect) + { + ThrowRequestRejected(RequestRejectionReason.ConnectMethodRequired); + } + + // When making a CONNECT request to establish a tunnel through one or + // more proxies, a client MUST send only the target URI's authority + // component (excluding any userinfo and its "@" delimiter) as the + // request-target.For example, + // + // CONNECT www.example.com:80 HTTP/1.1 + // + // Allowed characters in the 'host + port' section of authority. + // See https://tools.ietf.org/html/rfc3986#section-3.2 + RawTarget = target.GetAsciiStringNonNullCharacters(); + Path = string.Empty; + QueryString = string.Empty; + } + + private void OnAsteriskFormTarget(HttpMethod method) + { + _requestTargetForm = HttpRequestTarget.AsteriskForm; + + // The asterisk-form of request-target is only used for a server-wide + // OPTIONS request (https://tools.ietf.org/html/rfc7231#section-4.3.7). + if (method != HttpMethod.Options) + { + ThrowRequestRejected(RequestRejectionReason.OptionsMethodRequired); + } + + RawTarget = Asterisk; + Path = string.Empty; + QueryString = string.Empty; + } + + private void OnAbsoluteFormTarget(Span target, Span query) + { + _requestTargetForm = HttpRequestTarget.AbsoluteForm; + + // absolute-form + // https://tools.ietf.org/html/rfc7230#section-5.3.2 + + // This code should be the edge-case. + + // From the spec: + // a server MUST accept the absolute-form in requests, even though + // HTTP/1.1 clients will only send them in requests to proxies. + + RawTarget = target.GetAsciiStringNonNullCharacters(); + + // Validation of absolute URIs is slow, but clients + // should not be sending this form anyways, so perf optimization + // not high priority + + if (!Uri.TryCreate(RawTarget, UriKind.Absolute, out var uri)) + { + ThrowRequestTargetRejected(target); + } + + _absoluteRequestTarget = uri; + Path = uri.LocalPath; + // don't use uri.Query because we need the unescaped version + QueryString = query.GetAsciiStringNonNullCharacters(); + } + + private unsafe static string GetUtf8String(Span path) + { + // .NET 451 doesn't have pointer overloads for Encoding.GetString so we + // copy to an array + fixed (byte* pointer = &path.DangerousGetPinnableReference()) + { + return Encoding.UTF8.GetString(pointer, path.Length); + } + } + + public void OnHeader(Span name, Span value) + { + // TODO: move validation of header count and size to HPACK decoding + var valueString = value.GetAsciiStringNonNullCharacters(); + + FrameRequestHeaders.Append(name, valueString); + } + + protected void EnsureHostHeaderExists() + { + // https://tools.ietf.org/html/rfc7230#section-5.4 + // A server MUST respond with a 400 (Bad Request) status code to any + // HTTP/1.1 request message that lacks a Host header field and to any + // request message that contains more than one Host header field or a + // Host header field with an invalid field-value. + + var host = FrameRequestHeaders.HeaderHost; + if (host.Count <= 0) + { + ThrowRequestRejected(RequestRejectionReason.MissingHostHeader); + } + else if (host.Count > 1) + { + ThrowRequestRejected(RequestRejectionReason.MultipleHostHeaders); + } + else if (_requestTargetForm == HttpRequestTarget.AuthorityForm) + { + if (!host.Equals(RawTarget)) + { + ThrowRequestRejected(RequestRejectionReason.InvalidHostHeader, host.ToString()); + } + } + else if (_requestTargetForm == HttpRequestTarget.AbsoluteForm) + { + // If the target URI includes an authority component, then a + // client MUST send a field - value for Host that is identical to that + // authority component, excluding any userinfo subcomponent and its "@" + // delimiter. + + // System.Uri doesn't not tell us if the port was in the original string or not. + // When IsDefaultPort = true, we will allow Host: with or without the default port + var authorityAndPort = _absoluteRequestTarget.Authority + ":" + _absoluteRequestTarget.Port; + if ((host != _absoluteRequestTarget.Authority || !_absoluteRequestTarget.IsDefaultPort) + && host != authorityAndPort) + { + ThrowRequestRejected(RequestRejectionReason.InvalidHostHeader, host.ToString()); + } + } + } + + private IPipe CreateRequestBodyPipe() + => _context.PipeFactory.Create(new PipeOptions + { + ReaderScheduler = ServiceContext.ThreadPool, + WriterScheduler = InlineScheduler.Default, + MaximumSizeHigh = 1, + MaximumSizeLow = 1 + }); + + private enum HttpRequestTarget + { + Unknown = -1, + // origin-form is the most common + OriginForm, + AbsoluteForm, + AuthorityForm, + AsteriskForm + } + } +} diff --git a/src/Kestrel.Core/Internal/Http2/Http2StreamContext.cs b/src/Kestrel.Core/Internal/Http2/Http2StreamContext.cs new file mode 100644 index 0000000000..af7174c754 --- /dev/null +++ b/src/Kestrel.Core/Internal/Http2/Http2StreamContext.cs @@ -0,0 +1,20 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System.IO.Pipelines; +using System.Net; + +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 +{ + public class Http2StreamContext + { + public string ConnectionId { get; set; } + public int StreamId { get; set; } + public ServiceContext ServiceContext { get; set; } + public PipeFactory PipeFactory { get; set; } + public IPEndPoint RemoteEndPoint { get; set; } + public IPEndPoint LocalEndPoint { get; set; } + public IHttp2StreamLifetimeHandler StreamLifetimeHandler { get; set; } + public IHttp2FrameWriter FrameWriter { get; set; } + } +} diff --git a/src/Kestrel.Core/Internal/Http2/Http2StreamOfT.cs b/src/Kestrel.Core/Internal/Http2/Http2StreamOfT.cs new file mode 100644 index 0000000000..79b7493411 --- /dev/null +++ b/src/Kestrel.Core/Internal/Http2/Http2StreamOfT.cs @@ -0,0 +1,172 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.IO; +using System.Threading; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Hosting.Server; +using Microsoft.AspNetCore.Protocols; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; +using Microsoft.Extensions.Logging; + +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 +{ + public class Http2Stream : Http2Stream + { + private readonly IHttpApplication _application; + + public Http2Stream(IHttpApplication application, Http2StreamContext context) + : base(context) + { + _application = application; + } + + public override async Task ProcessRequestAsync() + { + try + { + Method = RequestHeaders[":method"]; + Scheme = RequestHeaders[":scheme"]; + + var path = RequestHeaders[":path"].ToString(); + var queryIndex = path.IndexOf('?'); + + Path = queryIndex == -1 ? path : path.Substring(0, queryIndex); + QueryString = queryIndex == -1 ? string.Empty : path.Substring(queryIndex); + + RequestHeaders["Host"] = RequestHeaders[":authority"]; + + // TODO: figure out what the equivalent for HTTP/2 is + // EnsureHostHeaderExists(); + + MessageBody = Http2MessageBody.For(FrameRequestHeaders, this); + + InitializeStreams(MessageBody); + + var context = _application.CreateContext(this); + try + { + try + { + //KestrelEventSource.Log.RequestStart(this); + + await _application.ProcessRequestAsync(context); + + if (Volatile.Read(ref _requestAborted) == 0) + { + VerifyResponseContentLength(); + } + } + catch (Exception ex) + { + ReportApplicationError(ex); + + if (ex is BadHttpRequestException) + { + throw; + } + } + finally + { + //KestrelEventSource.Log.RequestStop(this); + + // Trigger OnStarting if it hasn't been called yet and the app hasn't + // already failed. If an OnStarting callback throws we can go through + // our normal error handling in ProduceEnd. + // https://github.com/aspnet/KestrelHttpServer/issues/43 + if (!HasResponseStarted && _applicationException == null && _onStarting != null) + { + await FireOnStarting(); + } + + PauseStreams(); + + if (_onCompleted != null) + { + await FireOnCompleted(); + } + } + + // If _requestAbort is set, the connection has already been closed. + if (Volatile.Read(ref _requestAborted) == 0) + { + await ProduceEnd(); + } + else if (!HasResponseStarted) + { + // If the request was aborted and no response was sent, there's no + // meaningful status code to log. + StatusCode = 0; + } + } + catch (BadHttpRequestException ex) + { + // Handle BadHttpRequestException thrown during app execution or remaining message body consumption. + // This has to be caught here so StatusCode is set properly before disposing the HttpContext + // (DisposeContext logs StatusCode). + SetBadRequestState(ex); + } + finally + { + _application.DisposeContext(context, _applicationException); + + // StopStreams should be called before the end of the "if (!_requestProcessingStopping)" block + // to ensure InitializeStreams has been called. + StopStreams(); + + if (HasStartedConsumingRequestBody) + { + RequestBodyPipe.Reader.Complete(); + + // Wait for MessageBody.PumpAsync() to call RequestBodyPipe.Writer.Complete(). + await MessageBody.StopAsync(); + + // At this point both the request body pipe reader and writer should be completed. + RequestBodyPipe.Reset(); + } + } + } + catch (BadHttpRequestException ex) + { + // Handle BadHttpRequestException thrown during request line or header parsing. + // SetBadRequestState logs the error. + SetBadRequestState(ex); + } + catch (ConnectionResetException ex) + { + // Don't log ECONNRESET errors made between requests. Browsers like IE will reset connections regularly. + if (_requestProcessingStatus != RequestProcessingStatus.RequestPending) + { + Log.RequestProcessingError(ConnectionId, ex); + } + } + catch (IOException ex) + { + Log.RequestProcessingError(ConnectionId, ex); + } + catch (Exception ex) + { + Log.LogWarning(0, ex, CoreStrings.RequestProcessingEndError); + } + finally + { + try + { + if (Volatile.Read(ref _requestAborted) == 0) + { + await TryProduceInvalidRequestResponse(); + } + } + catch (Exception ex) + { + Log.LogWarning(0, ex, CoreStrings.ConnectionShutdownError); + } + finally + { + StreamLifetimeHandler.OnStreamCompleted(StreamId); + } + } + } + } +} diff --git a/src/Kestrel.Core/Internal/Http2/Http2Streams.cs b/src/Kestrel.Core/Internal/Http2/Http2Streams.cs new file mode 100644 index 0000000000..b433f7c22c --- /dev/null +++ b/src/Kestrel.Core/Internal/Http2/Http2Streams.cs @@ -0,0 +1,48 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.IO; +using Microsoft.AspNetCore.Http.Features; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; + +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 +{ + internal class Http2Streams + { + private readonly FrameResponseStream _response; + private readonly FrameRequestStream _request; + + public Http2Streams(IHttpBodyControlFeature bodyControl, IFrameControl httpStreamControl) + { + _request = new FrameRequestStream(bodyControl); + _response = new FrameResponseStream(bodyControl, httpStreamControl); + } + + public (Stream request, Stream response) Start(Http2MessageBody body) + { + _request.StartAcceptingReads(body); + _response.StartAcceptingWrites(); + + return (_request, _response); + } + + public void Pause() + { + _request.PauseAcceptingReads(); + _response.PauseAcceptingWrites(); + } + + public void Stop() + { + _request.StopAcceptingReads(); + _response.StopAcceptingWrites(); + } + + public void Abort(Exception error) + { + _request.Abort(error); + _response.Abort(); + } + } +} diff --git a/src/Kestrel.Core/Internal/Http2/IHttp2FrameWriter.cs b/src/Kestrel.Core/Internal/Http2/IHttp2FrameWriter.cs new file mode 100644 index 0000000000..c4615dac51 --- /dev/null +++ b/src/Kestrel.Core/Internal/Http2/IHttp2FrameWriter.cs @@ -0,0 +1,24 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Threading; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Http; + +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 +{ + public interface IHttp2FrameWriter + { + void Abort(Exception error); + Task FlushAsync(CancellationToken cancellationToken); + Task Write100ContinueAsync(int streamId); + Task WriteHeadersAsync(int streamId, int statusCode, IHeaderDictionary headers); + Task WriteDataAsync(int streamId, Span data, CancellationToken cancellationToken); + Task WriteDataAsync(int streamId, Span data, bool endStream, CancellationToken cancellationToken); + Task WriteRstStreamAsync(int streamId, Http2ErrorCode errorCode); + Task WriteSettingsAckAsync(); + Task WritePingAsync(Http2PingFrameFlags flags, Span payload); + Task WriteGoAwayAsync(int lastStreamId, Http2ErrorCode errorCode); + } +} diff --git a/src/Kestrel.Core/Internal/Http2/IHttp2StreamLifetimeHandler.cs b/src/Kestrel.Core/Internal/Http2/IHttp2StreamLifetimeHandler.cs new file mode 100644 index 0000000000..fcb9c89637 --- /dev/null +++ b/src/Kestrel.Core/Internal/Http2/IHttp2StreamLifetimeHandler.cs @@ -0,0 +1,10 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 +{ + public interface IHttp2StreamLifetimeHandler + { + void OnStreamCompleted(int streamId); + } +} diff --git a/src/Kestrel.Tls/ClosedStream.cs b/src/Kestrel.Tls/ClosedStream.cs new file mode 100644 index 0000000000..511869b29f --- /dev/null +++ b/src/Kestrel.Tls/ClosedStream.cs @@ -0,0 +1,68 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.IO; +using System.Threading; +using System.Threading.Tasks; + +namespace Microsoft.AspNetCore.Server.Kestrel.Tls +{ + internal class ClosedStream : Stream + { + private static readonly Task ZeroResultTask = Task.FromResult(result: 0); + + public override bool CanRead => true; + public override bool CanSeek => false; + public override bool CanWrite => false; + + public override long Length + { + get + { + throw new NotSupportedException(); + } + } + + public override long Position + { + get + { + throw new NotSupportedException(); + } + set + { + throw new NotSupportedException(); + } + } + + public override void Flush() + { + } + + public override long Seek(long offset, SeekOrigin origin) + { + throw new NotSupportedException(); + } + + public override void SetLength(long value) + { + throw new NotSupportedException(); + } + + public override int Read(byte[] buffer, int offset, int count) + { + return 0; + } + + public override Task ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) + { + return ZeroResultTask; + } + + public override void Write(byte[] buffer, int offset, int count) + { + throw new NotSupportedException(); + } + } +} diff --git a/src/Kestrel.Tls/Kestrel.Tls.csproj b/src/Kestrel.Tls/Kestrel.Tls.csproj new file mode 100644 index 0000000000..3a7bc3d924 --- /dev/null +++ b/src/Kestrel.Tls/Kestrel.Tls.csproj @@ -0,0 +1,26 @@ + + + + + + Microsoft.AspNetCore.Server.Kestrel.Tls + Microsoft.AspNetCore.Server.Kestrel.Tls + netstandard2.0 + true + aspnetcore;kestrel + CS1591;$(NoWarn) + false + + CurrentRuntime + true + + + + + + + + + + + diff --git a/src/Kestrel.Tls/ListenOptionsTlsExtensions.cs b/src/Kestrel.Tls/ListenOptionsTlsExtensions.cs new file mode 100644 index 0000000000..85011e6227 --- /dev/null +++ b/src/Kestrel.Tls/ListenOptionsTlsExtensions.cs @@ -0,0 +1,29 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using Microsoft.AspNetCore.Server.Kestrel.Core; +using Microsoft.AspNetCore.Server.Kestrel.Tls; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; + +namespace Microsoft.AspNetCore.Hosting +{ + public static class ListenOptionsTlsExtensions + { + public static ListenOptions UseTls(this ListenOptions listenOptions, string certificatePath, string privateKeyPath) + { + return listenOptions.UseTls(new TlsConnectionAdapterOptions + { + CertificatePath = certificatePath, + PrivateKeyPath = privateKeyPath + }); + } + + public static ListenOptions UseTls(this ListenOptions listenOptions, TlsConnectionAdapterOptions tlsOptions) + { + var loggerFactory = listenOptions.KestrelServerOptions.ApplicationServices.GetRequiredService(); + listenOptions.ConnectionAdapters.Add(new TlsConnectionAdapter(tlsOptions, loggerFactory)); + return listenOptions; + } + } +} diff --git a/src/Kestrel.Tls/OpenSsl.cs b/src/Kestrel.Tls/OpenSsl.cs new file mode 100644 index 0000000000..17568e4b9c --- /dev/null +++ b/src/Kestrel.Tls/OpenSsl.cs @@ -0,0 +1,268 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Runtime.InteropServices; +using System.Text; + +namespace Microsoft.AspNetCore.Server.Kestrel.Tls +{ + public static class OpenSsl + { + public const int OPENSSL_NPN_NEGOTIATED = 1; + public const int SSL_TLSEXT_ERR_OK = 0; + public const int SSL_TLSEXT_ERR_NOACK = 3; + + private const int BIO_C_SET_BUF_MEM_EOF_RETURN = 130; + private const int SSL_CTRL_SET_ECDH_AUTO = 94; + + public static int SSL_library_init() + { + return NativeMethods.SSL_library_init(); + } + + public static void SSL_load_error_strings() + { + NativeMethods.SSL_load_error_strings(); + } + + public static void OpenSSL_add_all_algorithms() + { + NativeMethods.OPENSSL_add_all_algorithms_noconf(); + } + + public static IntPtr TLSv1_2_method() + { + return NativeMethods.TLSv1_2_method(); + } + + public static IntPtr SSL_CTX_new(IntPtr method) + { + return NativeMethods.SSL_CTX_new(method); + } + + public static void SSL_CTX_free(IntPtr ctx) + { + NativeMethods.SSL_CTX_free(ctx); + } + + public static int SSL_CTX_set_ecdh_auto(IntPtr ctx, int onoff) + { + return (int)NativeMethods.SSL_CTX_ctrl(ctx, SSL_CTRL_SET_ECDH_AUTO, onoff, IntPtr.Zero); + } + + public static int SSL_CTX_use_certificate_file(IntPtr ctx, string file, int type) + { + var ptr = Marshal.StringToHGlobalAnsi(file); + var error = NativeMethods.SSL_CTX_use_certificate_file(ctx, ptr, type); + Marshal.FreeHGlobal(ptr); + + return error; + } + + public static int SSL_CTX_use_PrivateKey_file(IntPtr ctx, string file, int type) + { + var ptr = Marshal.StringToHGlobalAnsi(file); + var error = NativeMethods.SSL_CTX_use_PrivateKey_file(ctx, ptr, type); + Marshal.FreeHGlobal(ptr); + + return error; + } + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + public unsafe delegate int alpn_select_cb_t(IntPtr ssl, out byte* @out, out byte outlen, byte* @in, uint inlen, IntPtr arg); + + public unsafe static void SSL_CTX_set_alpn_select_cb(IntPtr ctx, alpn_select_cb_t cb, IntPtr arg) + { + NativeMethods.SSL_CTX_set_alpn_select_cb(ctx, cb, arg); + } + + public static unsafe int SSL_select_next_proto(out byte* @out, out byte outlen, byte* server, uint server_len, byte* client, uint client_len) + { + return NativeMethods.SSL_select_next_proto(out @out, out outlen, server, server_len, client, client_len); + } + + public static unsafe void SSL_get0_alpn_selected(IntPtr ssl, out string protocol) + { + NativeMethods.SSL_get0_alpn_selected(ssl, out var data, out var length); + + protocol = data != null + ? Marshal.PtrToStringAnsi((IntPtr)data, length) + : null; + } + + public static IntPtr SSL_new(IntPtr ctx) + { + return NativeMethods.SSL_new(ctx); + } + + public static void SSL_free(IntPtr ssl) + { + NativeMethods.SSL_free(ssl); + } + + public static int SSL_get_error(IntPtr ssl, int ret) + { + return NativeMethods.SSL_get_error(ssl, ret); + } + + public static void SSL_set_accept_state(IntPtr ssl) + { + NativeMethods.SSL_set_accept_state(ssl); + } + + public static int SSL_do_handshake(IntPtr ssl) + { + return NativeMethods.SSL_do_handshake(ssl); + } + + public static unsafe int SSL_read(IntPtr ssl, byte[] buffer, int offset, int count) + { + fixed (byte* ptr = buffer) + { + return NativeMethods.SSL_read(ssl, (IntPtr)(ptr + offset), count); + } + } + + public static unsafe int SSL_write(IntPtr ssl, byte[] buffer, int offset, int count) + { + fixed (byte* ptr = buffer) + { + return NativeMethods.SSL_write(ssl, (IntPtr)(ptr + offset), count); + } + } + + public static void SSL_set_bio(IntPtr ssl, IntPtr rbio, IntPtr wbio) + { + NativeMethods.SSL_set_bio(ssl, rbio, wbio); + } + + public static IntPtr BIO_new(IntPtr type) + { + return NativeMethods.BIO_new(type); + } + + public static unsafe int BIO_read(IntPtr b, byte[] buffer, int offset, int count) + { + fixed (byte* ptr = buffer) + { + return NativeMethods.BIO_read(b, (IntPtr)(ptr + offset), count); + } + } + + public static unsafe int BIO_write(IntPtr b, byte[] buffer, int offset, int count) + { + fixed (byte* ptr = buffer) + { + return NativeMethods.BIO_write(b, (IntPtr)(ptr + offset), count); + } + } + + public static long BIO_ctrl_pending(IntPtr b) + { + return NativeMethods.BIO_ctrl_pending(b); + } + + public static long BIO_set_mem_eof_return(IntPtr b, int v) + { + return NativeMethods.BIO_ctrl(b, BIO_C_SET_BUF_MEM_EOF_RETURN, v, IntPtr.Zero); + } + + public static IntPtr BIO_s_mem() + { + return NativeMethods.BIO_s_mem(); + } + + public static void ERR_load_BIO_strings() + { + NativeMethods.ERR_load_BIO_strings(); + } + + private class NativeMethods + { + [DllImport("libssl", CallingConvention = CallingConvention.Cdecl)] + public static extern int SSL_library_init(); + + [DllImport("libssl", CallingConvention = CallingConvention.Cdecl)] + public static extern void SSL_load_error_strings(); + + [DllImport("libssl", CallingConvention = CallingConvention.Cdecl)] + public static extern void OPENSSL_add_all_algorithms_noconf(); + + [DllImport("libssl", CallingConvention = CallingConvention.Cdecl)] + public static extern IntPtr TLSv1_2_method(); + + [DllImport("libssl", CallingConvention = CallingConvention.Cdecl)] + public static extern IntPtr SSL_CTX_new(IntPtr method); + + [DllImport("libssl", CallingConvention = CallingConvention.Cdecl)] + public static extern IntPtr SSL_CTX_free(IntPtr ctx); + + [DllImport("libssl", CallingConvention = CallingConvention.Cdecl)] + public static extern long SSL_CTX_ctrl(IntPtr ctx, int cmd, long larg, IntPtr parg); + + [DllImport("libssl", CallingConvention = CallingConvention.Cdecl)] + public static extern int SSL_CTX_use_certificate_file(IntPtr ctx, IntPtr file, int type); + + [DllImport("libssl", CallingConvention = CallingConvention.Cdecl)] + public static extern int SSL_CTX_use_PrivateKey_file(IntPtr ctx, IntPtr file, int type); + + [DllImport("libssl", CallingConvention = CallingConvention.Cdecl)] + public static extern void SSL_CTX_set_alpn_select_cb(IntPtr ctx, alpn_select_cb_t cb, IntPtr arg); + + [DllImport("libssl", CallingConvention = CallingConvention.Cdecl)] + public static extern unsafe int SSL_select_next_proto(out byte* @out, out byte outlen, byte* server, uint server_len, byte* client, uint client_len); + + [DllImport("libssl", CallingConvention = CallingConvention.Cdecl)] + public static extern unsafe void SSL_get0_alpn_selected(IntPtr ssl, out byte* data, out int len); + + [DllImport("libssl", CallingConvention = CallingConvention.Cdecl)] + public static extern IntPtr SSL_new(IntPtr ctx); + + [DllImport("libssl", CallingConvention = CallingConvention.Cdecl)] + public static extern IntPtr SSL_free(IntPtr ssl); + + [DllImport("libssl", CallingConvention = CallingConvention.Cdecl)] + public static extern int SSL_get_error(IntPtr ssl, int ret); + + [DllImport("libssl", CallingConvention = CallingConvention.Cdecl)] + public static extern void SSL_set_accept_state(IntPtr ssl); + + [DllImport("libssl", CallingConvention = CallingConvention.Cdecl)] + public static extern int SSL_do_handshake(IntPtr ssl); + + [DllImport("libssl", CallingConvention = CallingConvention.Cdecl)] + public static extern int SSL_read(IntPtr ssl, IntPtr buf, int len); + + [DllImport("libssl", CallingConvention = CallingConvention.Cdecl)] + public static extern int SSL_write(IntPtr ssl, IntPtr buf, int len); + + [DllImport("libssl", CallingConvention = CallingConvention.Cdecl)] + public static extern void SSL_set_bio(IntPtr ssl, IntPtr rbio, IntPtr wbio); + + [DllImport("libssl", CallingConvention = CallingConvention.Cdecl)] + public static extern IntPtr BIO_new(IntPtr type); + + [DllImport("libssl", CallingConvention = CallingConvention.Cdecl)] + public static extern int BIO_read(IntPtr b, IntPtr buf, int len); + + [DllImport("libssl", CallingConvention = CallingConvention.Cdecl)] + public static extern int BIO_write(IntPtr b, IntPtr buf, int len); + + [DllImport("libssl", CallingConvention = CallingConvention.Cdecl)] + public static extern long BIO_ctrl(IntPtr bp, int cmd, long larg, IntPtr parg); + + [DllImport("libssl", CallingConvention = CallingConvention.Cdecl)] + public static extern long BIO_ctrl_pending(IntPtr bp); + + [DllImport("libssl", CallingConvention = CallingConvention.Cdecl)] + public static extern IntPtr BIO_s_mem(); + + [DllImport("libssl", CallingConvention = CallingConvention.Cdecl)] + public static extern void ERR_load_BIO_strings(); + } + } +} diff --git a/src/Kestrel.Tls/Properties/AssemblyInfo.cs b/src/Kestrel.Tls/Properties/AssemblyInfo.cs new file mode 100644 index 0000000000..3bb5150c92 --- /dev/null +++ b/src/Kestrel.Tls/Properties/AssemblyInfo.cs @@ -0,0 +1,6 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System.Runtime.CompilerServices; + +[assembly: InternalsVisibleTo("Microsoft.AspNetCore.Server.Kestrel.FunctionalTests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")] diff --git a/src/Kestrel.Tls/README.md b/src/Kestrel.Tls/README.md new file mode 100644 index 0000000000..9012206247 --- /dev/null +++ b/src/Kestrel.Tls/README.md @@ -0,0 +1,5 @@ +# NOT FOR PRODUCTION USE + +The code in this package contains the bare minimum to make Kestrel work with TLS 1.2 with ALPN support. It has not been audited nor hardened in any way. DO NOT USE THIS IN PRODUCTION. + +This package is temporary and will be removed once `SslStream` supports ALPN. diff --git a/src/Kestrel.Tls/TlsApplicationProtocolFeature.cs b/src/Kestrel.Tls/TlsApplicationProtocolFeature.cs new file mode 100644 index 0000000000..b3bcee74cc --- /dev/null +++ b/src/Kestrel.Tls/TlsApplicationProtocolFeature.cs @@ -0,0 +1,17 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using Microsoft.AspNetCore.Server.Kestrel.Core.Features; + +namespace Microsoft.AspNetCore.Server.Kestrel.Tls +{ + internal class TlsApplicationProtocolFeature : ITlsApplicationProtocolFeature + { + public TlsApplicationProtocolFeature(string applicationProtocol) + { + ApplicationProtocol = applicationProtocol; + } + + public string ApplicationProtocol { get; } + } +} diff --git a/src/Kestrel.Tls/TlsConnectionAdapter.cs b/src/Kestrel.Tls/TlsConnectionAdapter.cs new file mode 100644 index 0000000000..0dae1b701c --- /dev/null +++ b/src/Kestrel.Tls/TlsConnectionAdapter.cs @@ -0,0 +1,109 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Http.Features; +using Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal; +using Microsoft.AspNetCore.Server.Kestrel.Core.Features; +using Microsoft.Extensions.Logging; + +namespace Microsoft.AspNetCore.Server.Kestrel.Tls +{ + public class TlsConnectionAdapter : IConnectionAdapter + { + private static readonly ClosedAdaptedConnection _closedAdaptedConnection = new ClosedAdaptedConnection(); + private static readonly HashSet _serverProtocols = new HashSet(new[] { "h2", "http/1.1" }); + + private readonly TlsConnectionAdapterOptions _options; + private readonly ILogger _logger; + + private string _applicationProtocol; + + public TlsConnectionAdapter(TlsConnectionAdapterOptions options) + : this(options, loggerFactory: null) + { + } + + public TlsConnectionAdapter(TlsConnectionAdapterOptions options, ILoggerFactory loggerFactory) + { + if (options == null) + { + throw new ArgumentNullException(nameof(options)); + } + + if (options.CertificatePath == null) + { + throw new ArgumentException("Certificate path must be non-null.", nameof(options)); + } + + if (options.PrivateKeyPath == null) + { + throw new ArgumentException("Private key path must be non-null.", nameof(options)); + } + + _options = options; + _logger = loggerFactory?.CreateLogger(nameof(TlsConnectionAdapter)); + } + + public bool IsHttps => true; + + public Task OnConnectionAsync(ConnectionAdapterContext context) + { + // Don't trust TlsStream not to block. + return Task.Run(() => InnerOnConnectionAsync(context)); + } + + private async Task InnerOnConnectionAsync(ConnectionAdapterContext context) + { + var tlsStream = new TlsStream(context.ConnectionStream, _options.CertificatePath, _options.PrivateKeyPath, _serverProtocols); + + try + { + await tlsStream.DoHandshakeAsync(); + _applicationProtocol = tlsStream.GetNegotiatedApplicationProtocol(); + } + catch (IOException ex) + { + _logger?.LogInformation(1, ex, "Authentication failed."); + tlsStream.Dispose(); + return _closedAdaptedConnection; + } + + // Always set the feature even though the cert might be null + context.Features.Set(new TlsConnectionFeature()); + context.Features.Set(new TlsApplicationProtocolFeature(_applicationProtocol)); + + return new TlsAdaptedConnection(tlsStream); + } + + private class TlsAdaptedConnection : IAdaptedConnection + { + private readonly TlsStream _tlsStream; + + public TlsAdaptedConnection(TlsStream tlsStream) + { + _tlsStream = tlsStream; + } + + public Stream ConnectionStream => _tlsStream; + + public void Dispose() + { + _tlsStream.Dispose(); + } + } + + private class ClosedAdaptedConnection : IAdaptedConnection + { + public Stream ConnectionStream { get; } = new ClosedStream(); + + public void Dispose() + { + } + } + } +} diff --git a/src/Kestrel.Tls/TlsConnectionAdapterOptions.cs b/src/Kestrel.Tls/TlsConnectionAdapterOptions.cs new file mode 100644 index 0000000000..0d49b62b69 --- /dev/null +++ b/src/Kestrel.Tls/TlsConnectionAdapterOptions.cs @@ -0,0 +1,12 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +namespace Microsoft.AspNetCore.Server.Kestrel.Tls +{ + public class TlsConnectionAdapterOptions + { + public string CertificatePath { get; set; } = string.Empty; + + public string PrivateKeyPath { get; set; } = string.Empty; + } +} diff --git a/src/Kestrel.Tls/TlsConnectionFeature.cs b/src/Kestrel.Tls/TlsConnectionFeature.cs new file mode 100644 index 0000000000..007fbd0f8a --- /dev/null +++ b/src/Kestrel.Tls/TlsConnectionFeature.cs @@ -0,0 +1,21 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Security.Cryptography.X509Certificates; +using System.Threading; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Http.Features; + +namespace Microsoft.AspNetCore.Server.Kestrel.Tls +{ + internal class TlsConnectionFeature : ITlsConnectionFeature + { + public X509Certificate2 ClientCertificate { get; set; } + + public Task GetClientCertificateAsync(CancellationToken cancellationToken) + { + return Task.FromResult(ClientCertificate); + } + } +} diff --git a/src/Kestrel.Tls/TlsStream.cs b/src/Kestrel.Tls/TlsStream.cs new file mode 100644 index 0000000000..6cf8c5e8e0 --- /dev/null +++ b/src/Kestrel.Tls/TlsStream.cs @@ -0,0 +1,231 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Runtime.InteropServices; +using System.Text; +using System.Threading; +using System.Threading.Tasks; + +namespace Microsoft.AspNetCore.Server.Kestrel.Tls +{ + public class TlsStream : Stream + { + private static unsafe OpenSsl.alpn_select_cb_t _alpnSelectCallback = AlpnSelectCallback; + + private readonly Stream _innerStream; + private readonly byte[] _protocols; + private readonly GCHandle _protocolsHandle; + + private IntPtr _ctx; + private IntPtr _ssl; + private IntPtr _inputBio; + private IntPtr _outputBio; + + private readonly byte[] _inputBuffer = new byte[1024 * 1024]; + private readonly byte[] _outputBuffer = new byte[1024 * 1024]; + + static TlsStream() + { + OpenSsl.SSL_library_init(); + OpenSsl.SSL_load_error_strings(); + OpenSsl.ERR_load_BIO_strings(); + OpenSsl.OpenSSL_add_all_algorithms(); + } + + public TlsStream(Stream innerStream, string certificatePath, string privateKeyPath, IEnumerable protocols) + { + _innerStream = innerStream; + _protocols = ToWireFormat(protocols); + _protocolsHandle = GCHandle.Alloc(_protocols); + + _ctx = OpenSsl.SSL_CTX_new(OpenSsl.TLSv1_2_method()); + + if (_ctx == IntPtr.Zero) + { + throw new Exception("Unable to create SSL context."); + } + + OpenSsl.SSL_CTX_set_ecdh_auto(_ctx, 1); + + if (OpenSsl.SSL_CTX_use_certificate_file(_ctx, certificatePath, 1) != 1) + { + throw new Exception("Unable to load certificate file."); + } + + if (OpenSsl.SSL_CTX_use_PrivateKey_file(_ctx, privateKeyPath, 1) != 1) + { + throw new Exception("Unable to load private key file."); + } + + OpenSsl.SSL_CTX_set_alpn_select_cb(_ctx, _alpnSelectCallback, GCHandle.ToIntPtr(_protocolsHandle)); + + _ssl = OpenSsl.SSL_new(_ctx); + + _inputBio = OpenSsl.BIO_new(OpenSsl.BIO_s_mem()); + OpenSsl.BIO_set_mem_eof_return(_inputBio, -1); + + _outputBio = OpenSsl.BIO_new(OpenSsl.BIO_s_mem()); + OpenSsl.BIO_set_mem_eof_return(_outputBio, -1); + + OpenSsl.SSL_set_bio(_ssl, _inputBio, _outputBio); + } + + ~TlsStream() + { + if (_ssl != IntPtr.Zero) + { + OpenSsl.SSL_free(_ssl); + } + + if (_ctx != IntPtr.Zero) + { + // This frees the BIOs. + OpenSsl.SSL_CTX_free(_ctx); + } + + if (_protocolsHandle.IsAllocated) + { + _protocolsHandle.Free(); + } + } + + public override bool CanRead => true; + public override bool CanWrite => true; + + public override bool CanSeek => false; + public override long Length => throw new NotSupportedException(); + public override long Position + { + get => throw new NotSupportedException(); + set => throw new NotSupportedException(); + } + public override long Seek(long offset, SeekOrigin origin) => throw new NotSupportedException(); + public override void SetLength(long value) => throw new NotSupportedException(); + + public override void Flush() + { + FlushAsync(default(CancellationToken)).GetAwaiter().GetResult(); + } + + public override int Read(byte[] buffer, int offset, int count) + { + return ReadAsync(buffer, offset, count).GetAwaiter().GetResult(); + } + + public override void Write(byte[] buffer, int offset, int count) + { + WriteAsync(buffer, offset, count).GetAwaiter().GetResult(); + } + + public override async Task FlushAsync(CancellationToken cancellationToken) + { + var pending = OpenSsl.BIO_ctrl_pending(_outputBio); + + while (pending > 0) + { + var count = OpenSsl.BIO_read(_outputBio, _outputBuffer, 0, _outputBuffer.Length); + await _innerStream.WriteAsync(_outputBuffer, 0, count, cancellationToken); + + pending = OpenSsl.BIO_ctrl_pending(_outputBio); + } + } + + public override async Task ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) + { + if (OpenSsl.BIO_ctrl_pending(_inputBio) == 0) + { + var bytesRead = await _innerStream.ReadAsync(_inputBuffer, 0, _inputBuffer.Length, cancellationToken); + OpenSsl.BIO_write(_inputBio, _inputBuffer, 0, bytesRead); + } + + return OpenSsl.SSL_read(_ssl, buffer, offset, count); + } + + public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) + { + OpenSsl.SSL_write(_ssl, buffer, offset, count); + + return FlushAsync(cancellationToken); + } + + public async Task DoHandshakeAsync(CancellationToken cancellationToken = default(CancellationToken)) + { + OpenSsl.SSL_set_accept_state(_ssl); + + var count = 0; + + try + { + while ((count = await _innerStream.ReadAsync(_inputBuffer, 0, _inputBuffer.Length, cancellationToken)) > 0) + { + if (count == 0) + { + throw new IOException("TLS handshake failed: the inner stream was closed."); + } + + OpenSsl.BIO_write(_inputBio, _inputBuffer, 0, count); + + var ret = OpenSsl.SSL_do_handshake(_ssl); + + if (ret != 1) + { + var error = OpenSsl.SSL_get_error(_ssl, ret); + + if (error != 2) + { + throw new IOException($"TLS handshake failed: {nameof(OpenSsl.SSL_do_handshake)} error {error}."); + } + } + + await FlushAsync(cancellationToken); + + if (ret == 1) + { + return; + } + } + } + finally + { + _protocolsHandle.Free(); + } + } + + public string GetNegotiatedApplicationProtocol() + { + OpenSsl.SSL_get0_alpn_selected(_ssl, out var protocol); + return protocol; + } + + private static unsafe int AlpnSelectCallback(IntPtr ssl, out byte* @out, out byte outlen, byte* @in, uint inlen, IntPtr arg) + { + var protocols = GCHandle.FromIntPtr(arg); + var server = (byte[])protocols.Target; + + fixed (byte* serverPtr = server) + { + return OpenSsl.SSL_select_next_proto(out @out, out outlen, serverPtr, (uint)server.Length, @in, (uint)inlen) == OpenSsl.OPENSSL_NPN_NEGOTIATED + ? OpenSsl.SSL_TLSEXT_ERR_OK + : OpenSsl.SSL_TLSEXT_ERR_NOACK; + } + } + + private static byte[] ToWireFormat(IEnumerable protocols) + { + var buffer = new byte[protocols.Count() + protocols.Sum(protocol => protocol.Length)]; + + var offset = 0; + foreach (var protocol in protocols) + { + buffer[offset++] = (byte)protocol.Length; + offset += Encoding.ASCII.GetBytes(protocol, 0, protocol.Length, buffer, offset); + } + + return buffer; + } + } +} diff --git a/src/Kestrel.Transport.Libuv/Internal/LibuvConnectionContext.cs b/src/Kestrel.Transport.Libuv/Internal/LibuvConnectionContext.cs index fafb3aad57..e1319c8317 100644 --- a/src/Kestrel.Transport.Libuv/Internal/LibuvConnectionContext.cs +++ b/src/Kestrel.Transport.Libuv/Internal/LibuvConnectionContext.cs @@ -20,4 +20,4 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal public override IScheduler InputWriterScheduler => ListenerContext.Thread; public override IScheduler OutputReaderScheduler => ListenerContext.Thread; } -} \ No newline at end of file +} diff --git a/test/Kestrel.Core.Tests/FrameConnectionTests.cs b/test/Kestrel.Core.Tests/FrameConnectionTests.cs index 0304ce3f7f..1891872223 100644 --- a/test/Kestrel.Core.Tests/FrameConnectionTests.cs +++ b/test/Kestrel.Core.Tests/FrameConnectionTests.cs @@ -532,7 +532,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests public async Task StartRequestProcessingCreatesLogScopeWithConnectionId() { _frameConnection.StartRequestProcessing(new DummyApplication()); - + var scopeObjects = ((TestKestrelTrace)_frameConnectionContext.ServiceContext.Log) .Logger .Scopes diff --git a/test/Kestrel.Core.Tests/HPackEncoderTests.cs b/test/Kestrel.Core.Tests/HPackEncoderTests.cs new file mode 100644 index 0000000000..de07eeec72 --- /dev/null +++ b/test/Kestrel.Core.Tests/HPackEncoderTests.cs @@ -0,0 +1,130 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Collections.Generic; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2.HPack; +using Xunit; + +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests +{ + public class HPackEncoderTests + { + [Fact] + public void EncodesHeadersInSinglePayloadWhenSpaceAvailable() + { + var encoder = new HPackEncoder(); + + var statusCode = 200; + var headers = new [] + { + new KeyValuePair("date", "Mon, 24 Jul 2017 19:22:30 GMT"), + new KeyValuePair("content-type", "text/html; charset=utf-8"), + new KeyValuePair("server", "Kestrel") + }; + + var expectedPayload = new byte[] + { + 0x88, 0x00, 0x04, 0x64, 0x61, 0x74, 0x65, 0x1d, + 0x4d, 0x6f, 0x6e, 0x2c, 0x20, 0x32, 0x34, 0x20, + 0x4a, 0x75, 0x6c, 0x20, 0x32, 0x30, 0x31, 0x37, + 0x20, 0x31, 0x39, 0x3a, 0x32, 0x32, 0x3a, 0x33, + 0x30, 0x20, 0x47, 0x4d, 0x54, 0x00, 0x0c, 0x63, + 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x2d, 0x74, + 0x79, 0x70, 0x65, 0x18, 0x74, 0x65, 0x78, 0x74, + 0x2f, 0x68, 0x74, 0x6d, 0x6c, 0x3b, 0x20, 0x63, + 0x68, 0x61, 0x72, 0x73, 0x65, 0x74, 0x3d, 0x75, + 0x74, 0x66, 0x2d, 0x38, 0x00, 0x06, 0x73, 0x65, + 0x72, 0x76, 0x65, 0x72, 0x07, 0x4b, 0x65, 0x73, + 0x74, 0x72, 0x65, 0x6c + }; + + var payload = new byte[1024]; + Assert.True(encoder.BeginEncode(statusCode, headers, payload, out var length)); + Assert.Equal(expectedPayload.Length, length); + + for (var i = 0; i < length; i++) + { + Assert.True(expectedPayload[i] == payload[i], $"{expectedPayload[i]} != {payload[i]} at {i} (len {length})"); + } + + Assert.Equal(expectedPayload, new ArraySegment(payload, 0, length)); + } + + [Theory] + [InlineData(true)] + [InlineData(false)] + public void EncodesHeadersInMultiplePayloadsWhenSpaceNotAvailable(bool exactSize) + { + var encoder = new HPackEncoder(); + + var statusCode = 200; + var headers = new [] + { + new KeyValuePair("date", "Mon, 24 Jul 2017 19:22:30 GMT"), + new KeyValuePair("content-type", "text/html; charset=utf-8"), + new KeyValuePair("server", "Kestrel") + }; + + var expectedStatusCodePayload = new byte[] + { + 0x88 + }; + + var expectedDateHeaderPayload = new byte[] + { + 0x00, 0x04, 0x64, 0x61, 0x74, 0x65, 0x1d, 0x4d, + 0x6f, 0x6e, 0x2c, 0x20, 0x32, 0x34, 0x20, 0x4a, + 0x75, 0x6c, 0x20, 0x32, 0x30, 0x31, 0x37, 0x20, + 0x31, 0x39, 0x3a, 0x32, 0x32, 0x3a, 0x33, 0x30, + 0x20, 0x47, 0x4d, 0x54 + }; + + var expectedContentTypeHeaderPayload = new byte[] + { + 0x00, 0x0c, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, + 0x74, 0x2d, 0x74, 0x79, 0x70, 0x65, 0x18, 0x74, + 0x65, 0x78, 0x74, 0x2f, 0x68, 0x74, 0x6d, 0x6c, + 0x3b, 0x20, 0x63, 0x68, 0x61, 0x72, 0x73, 0x65, + 0x74, 0x3d, 0x75, 0x74, 0x66, 0x2d, 0x38 + }; + + var expectedServerHeaderPayload = new byte[] + { + 0x00, 0x06, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, + 0x07, 0x4b, 0x65, 0x73, 0x74, 0x72, 0x65, 0x6c + }; + + Span payload = new byte[1024]; + var offset = 0; + + // When !exactSize, slices are one byte short of fitting the next header + var sliceLength = expectedStatusCodePayload.Length + (exactSize ? 0 : expectedDateHeaderPayload.Length - 1); + Assert.False(encoder.BeginEncode(statusCode, headers, payload.Slice(offset, sliceLength), out var length)); + Assert.Equal(expectedStatusCodePayload.Length, length); + Assert.Equal(expectedStatusCodePayload, payload.Slice(0, length).ToArray()); + + offset += length; + + sliceLength = expectedDateHeaderPayload.Length + (exactSize ? 0 : expectedContentTypeHeaderPayload.Length - 1); + Assert.False(encoder.Encode(payload.Slice(offset, sliceLength), out length)); + Assert.Equal(expectedDateHeaderPayload.Length, length); + Assert.Equal(expectedDateHeaderPayload, payload.Slice(offset, length).ToArray()); + + offset += length; + + sliceLength = expectedContentTypeHeaderPayload.Length + (exactSize ? 0 : expectedServerHeaderPayload.Length - 1); + Assert.False(encoder.Encode(payload.Slice(offset, sliceLength), out length)); + Assert.Equal(expectedContentTypeHeaderPayload.Length, length); + Assert.Equal(expectedContentTypeHeaderPayload, payload.Slice(offset, length).ToArray()); + + offset += length; + + sliceLength = expectedServerHeaderPayload.Length; + Assert.True(encoder.Encode(payload.Slice(offset, sliceLength), out length)); + Assert.Equal(expectedServerHeaderPayload.Length, length); + Assert.Equal(expectedServerHeaderPayload, payload.Slice(offset, length).ToArray()); + } + } +} diff --git a/test/Kestrel.Core.Tests/Http2ConnectionTests.cs b/test/Kestrel.Core.Tests/Http2ConnectionTests.cs new file mode 100644 index 0000000000..0e1e4668fc --- /dev/null +++ b/test/Kestrel.Core.Tests/Http2ConnectionTests.cs @@ -0,0 +1,1520 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Collections.Concurrent; +using System.Collections.Generic; +using System.IO; +using System.IO.Pipelines; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Server.Kestrel.Core.Features; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2.HPack; +using Microsoft.AspNetCore.Testing; +using Microsoft.Extensions.Primitives; +using Xunit; + +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests +{ + public class Http2ConnectionTests : IDisposable + { + private static readonly string _largeHeaderA = new string('a', Http2Frame.MinAllowedMaxFrameSize - Http2Frame.HeaderLength - 8); + + private static readonly string _largeHeaderB = new string('b', Http2Frame.MinAllowedMaxFrameSize - Http2Frame.HeaderLength - 8); + + private static readonly IEnumerable> _postRequestHeaders = new [] + { + new KeyValuePair(":method", "POST"), + new KeyValuePair(":path", "/"), + new KeyValuePair(":authority", "127.0.0.1"), + new KeyValuePair(":scheme", "https"), + }; + + private static readonly IEnumerable> _browserRequestHeaders = new [] + { + new KeyValuePair(":method", "GET"), + new KeyValuePair(":path", "/"), + new KeyValuePair(":authority", "127.0.0.1"), + new KeyValuePair(":scheme", "https"), + new KeyValuePair("user-agent", "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:54.0) Gecko/20100101 Firefox/54.0"), + new KeyValuePair("accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"), + new KeyValuePair("accept-language", "en-US,en;q=0.5"), + new KeyValuePair("accept-encoding", "gzip, deflate, br"), + new KeyValuePair("upgrade-insecure-requests", "1"), + }; + + private static readonly IEnumerable> _oneContinuationRequestHeaders = new [] + { + new KeyValuePair(":method", "GET"), + new KeyValuePair(":path", "/"), + new KeyValuePair(":authority", "127.0.0.1"), + new KeyValuePair(":scheme", "https"), + new KeyValuePair("a", _largeHeaderA) + }; + + private static readonly IEnumerable> _twoContinuationsRequestHeaders = new [] + { + new KeyValuePair(":method", "GET"), + new KeyValuePair(":path", "/"), + new KeyValuePair(":authority", "127.0.0.1"), + new KeyValuePair(":scheme", "https"), + new KeyValuePair("a", _largeHeaderA), + new KeyValuePair("b", _largeHeaderB) + }; + + private static readonly byte[] _helloBytes = Encoding.ASCII.GetBytes("hello"); + private static readonly byte[] _worldBytes = Encoding.ASCII.GetBytes("world"); + private static readonly byte[] _helloWorldBytes = Encoding.ASCII.GetBytes("hello, world"); + private static readonly byte[] _noData = new byte[0]; + + private readonly PipeFactory _pipeFactory = new PipeFactory(); + private readonly IPipe _inputPipe; + private readonly IPipe _outputPipe; + private readonly Http2ConnectionContext _connectionContext; + private readonly Http2Connection _connection; + private readonly HPackEncoder _hpackEncoder = new HPackEncoder(); + private readonly HPackDecoder _hpackDecoder = new HPackDecoder(); + private readonly Http2PeerSettings _clientSettings = new Http2PeerSettings(); + + private readonly ConcurrentDictionary> _runningStreams = new ConcurrentDictionary>(); + private readonly Dictionary _receivedHeaders = new Dictionary(StringComparer.OrdinalIgnoreCase); + private readonly HashSet _abortedStreamIds = new HashSet(); + private readonly object _abortedStreamIdsLock = new object(); + + private readonly RequestDelegate _noopApplication; + private readonly RequestDelegate _readHeadersApplication; + private readonly RequestDelegate _bufferingApplication; + private readonly RequestDelegate _echoApplication; + private readonly RequestDelegate _echoWaitForAbortApplication; + private readonly RequestDelegate _largeHeadersApplication; + private readonly RequestDelegate _waitForAbortApplication; + private readonly RequestDelegate _waitForAbortFlushingApplication; + + private Task _connectionTask; + + public Http2ConnectionTests() + { + _inputPipe = _pipeFactory.Create(); + _outputPipe = _pipeFactory.Create(); + + _noopApplication = context => Task.CompletedTask; + + _readHeadersApplication = context => + { + foreach (var header in context.Request.Headers) + { + _receivedHeaders[header.Key] = header.Value.ToString(); + } + + return Task.CompletedTask; + }; + + _bufferingApplication = async context => + { + var data = new List(); + var buffer = new byte[1024]; + var received = 0; + + while ((received = await context.Request.Body.ReadAsync(buffer, 0, buffer.Length)) > 0) + { + data.AddRange(new ArraySegment(buffer, 0, received)); + } + + await context.Response.Body.WriteAsync(data.ToArray(), 0, data.Count); + }; + + _echoApplication = async context => + { + var buffer = new byte[Http2Frame.MinAllowedMaxFrameSize]; + var received = 0; + + while ((received = await context.Request.Body.ReadAsync(buffer, 0, buffer.Length)) > 0) + { + await context.Response.Body.WriteAsync(buffer, 0, received); + } + }; + + _echoWaitForAbortApplication = async context => + { + var buffer = new byte[Http2Frame.MinAllowedMaxFrameSize]; + var received = 0; + + while ((received = await context.Request.Body.ReadAsync(buffer, 0, buffer.Length)) > 0) + { + await context.Response.Body.WriteAsync(buffer, 0, received); + } + + var sem = new SemaphoreSlim(0); + + context.RequestAborted.Register(() => + { + sem.Release(); + }); + + await sem.WaitAsync().TimeoutAfter(TimeSpan.FromSeconds(10)); + }; + + _largeHeadersApplication = context => + { + context.Response.Headers["a"] = _largeHeaderA; + context.Response.Headers["b"] = _largeHeaderB; + + return Task.CompletedTask; + }; + + _waitForAbortApplication = async context => + { + var streamIdFeature = context.Features.Get(); + var sem = new SemaphoreSlim(0); + + context.RequestAborted.Register(() => + { + lock (_abortedStreamIdsLock) + { + _abortedStreamIds.Add(streamIdFeature.StreamId); + } + + sem.Release(); + }); + + await sem.WaitAsync().TimeoutAfter(TimeSpan.FromSeconds(10)); + + _runningStreams[streamIdFeature.StreamId].TrySetResult(null); + }; + + _waitForAbortFlushingApplication = async context => + { + var streamIdFeature = context.Features.Get(); + var sem = new SemaphoreSlim(0); + + context.RequestAborted.Register(() => + { + lock (_abortedStreamIdsLock) + { + _abortedStreamIds.Add(streamIdFeature.StreamId); + } + + sem.Release(); + }); + + await sem.WaitAsync().TimeoutAfter(TimeSpan.FromSeconds(10)); + + await context.Response.Body.FlushAsync(); + + _runningStreams[streamIdFeature.StreamId].TrySetResult(null); + }; + + _connectionContext = new Http2ConnectionContext + { + ServiceContext = new TestServiceContext(), + PipeFactory = _pipeFactory, + Input = _inputPipe.Reader, + Output = _outputPipe + }; + _connection = new Http2Connection(_connectionContext); + } + + public void Dispose() + { + _pipeFactory.Dispose(); + } + + [Fact] + public async Task DATA_Received_ReadByStream() + { + await InitializeConnectionAsync(_echoApplication); + + await StartStreamAsync(1, _browserRequestHeaders, endStream: false); + await SendDataAsync(1, _helloWorldBytes, endStream: true); + + await ExpectAsync(Http2FrameType.HEADERS, + withLength: 37, + withFlags: (byte)Http2HeadersFrameFlags.END_HEADERS, + withStreamId: 1); + var dataFrame = await ExpectAsync(Http2FrameType.DATA, + withLength: 12, + withFlags: (byte)Http2DataFrameFlags.NONE, + withStreamId: 1); + await ExpectAsync(Http2FrameType.DATA, + withLength: 0, + withFlags: (byte)Http2DataFrameFlags.END_STREAM, + withStreamId: 1); + + await StopConnectionAsync(expectedLastStreamId: 1, ignoreNonGoAwayFrames: false); + + Assert.Equal(dataFrame.DataPayload, _helloWorldBytes); + } + + [Fact] + public async Task DATA_Received_Multiple_ReadByStream() + { + await InitializeConnectionAsync(_bufferingApplication); + + await StartStreamAsync(1, _browserRequestHeaders, endStream: false); + + for (var i = 0; i < _helloWorldBytes.Length; i++) + { + await SendDataAsync(1, new ArraySegment(_helloWorldBytes, i, 1), endStream: false); + } + + await SendDataAsync(1, _noData, endStream: true); + + await ExpectAsync(Http2FrameType.HEADERS, + withLength: 37, + withFlags: (byte)Http2HeadersFrameFlags.END_HEADERS, + withStreamId: 1); + var dataFrame = await ExpectAsync(Http2FrameType.DATA, + withLength: 12, + withFlags: (byte)Http2DataFrameFlags.NONE, + withStreamId: 1); + await ExpectAsync(Http2FrameType.DATA, + withLength: 0, + withFlags: (byte)Http2DataFrameFlags.END_STREAM, + withStreamId: 1); + + await StopConnectionAsync(expectedLastStreamId: 1, ignoreNonGoAwayFrames: false); + + Assert.Equal(dataFrame.DataPayload, _helloWorldBytes); + } + + [Fact] + public async Task DATA_Received_Multiplexed_ReadByStreams() + { + await InitializeConnectionAsync(_echoApplication); + + await StartStreamAsync(1, _browserRequestHeaders, endStream: false); + await StartStreamAsync(3, _browserRequestHeaders, endStream: false); + + await SendDataAsync(1, _helloBytes, endStream: false); + + await ExpectAsync(Http2FrameType.HEADERS, + withLength: 37, + withFlags: (byte)Http2HeadersFrameFlags.END_HEADERS, + withStreamId: 1); + var stream1DataFrame1 = await ExpectAsync(Http2FrameType.DATA, + withLength: 5, + withFlags: (byte)Http2DataFrameFlags.NONE, + withStreamId: 1); + + await SendDataAsync(3, _helloBytes, endStream: false); + + await ExpectAsync(Http2FrameType.HEADERS, + withLength: 37, + withFlags: (byte)Http2HeadersFrameFlags.END_HEADERS, + withStreamId: 3); + var stream3DataFrame1 = await ExpectAsync(Http2FrameType.DATA, + withLength: 5, + withFlags: (byte)Http2DataFrameFlags.NONE, + withStreamId: 3); + + await SendDataAsync(3, _worldBytes, endStream: false); + + var stream3DataFrame2 = await ExpectAsync(Http2FrameType.DATA, + withLength: 5, + withFlags: (byte)Http2DataFrameFlags.NONE, + withStreamId: 3); + + await SendDataAsync(1, _worldBytes, endStream: false); + + var stream1DataFrame2 = await ExpectAsync(Http2FrameType.DATA, + withLength: 5, + withFlags: (byte)Http2DataFrameFlags.NONE, + withStreamId: 1); + + await SendDataAsync(1, _noData, endStream: true); + + await ExpectAsync(Http2FrameType.DATA, + withLength: 0, + withFlags: (byte)Http2DataFrameFlags.END_STREAM, + withStreamId: 1); + + await SendDataAsync(3, _noData, endStream: true); + + await ExpectAsync(Http2FrameType.DATA, + withLength: 0, + withFlags: (byte)Http2DataFrameFlags.END_STREAM, + withStreamId: 3); + + await StopConnectionAsync(expectedLastStreamId: 3, ignoreNonGoAwayFrames: false); + + Assert.Equal(stream1DataFrame1.DataPayload, _helloBytes); + Assert.Equal(stream1DataFrame2.DataPayload, _worldBytes); + Assert.Equal(stream3DataFrame1.DataPayload, _helloBytes); + Assert.Equal(stream3DataFrame2.DataPayload, _worldBytes); + } + + [Theory] + [InlineData(0)] + [InlineData(1)] + [InlineData(255)] + public async Task DATA_Received_WithPadding_ReadByStream(byte padLength) + { + await InitializeConnectionAsync(_echoApplication); + + await StartStreamAsync(1, _browserRequestHeaders, endStream: false); + await SendDataWithPaddingAsync(1, _helloWorldBytes, padLength, endStream: true); + + await ExpectAsync(Http2FrameType.HEADERS, + withLength: 37, + withFlags: (byte)Http2HeadersFrameFlags.END_HEADERS, + withStreamId: 1); + var dataFrame = await ExpectAsync(Http2FrameType.DATA, + withLength: 12, + withFlags: (byte)Http2DataFrameFlags.NONE, + withStreamId: 1); + await ExpectAsync(Http2FrameType.DATA, + withLength: 0, + withFlags: (byte)Http2DataFrameFlags.END_STREAM, + withStreamId: 1); + + await StopConnectionAsync(expectedLastStreamId: 1, ignoreNonGoAwayFrames: false); + + Assert.Equal(dataFrame.DataPayload, _helloWorldBytes); + } + + [Fact] + public async Task DATA_Received_StreamIdZero_ConnectionError() + { + await InitializeConnectionAsync(_noopApplication); + + await SendDataAsync(0, _noData, endStream: false); + + await WaitForConnectionErrorAsync(expectedLastStreamId: 0, expectedErrorCode: Http2ErrorCode.PROTOCOL_ERROR, ignoreNonGoAwayFrames: false); + } + + [Fact] + public async Task DATA_Received_PaddingEqualToFramePayloadLength_ConnectionError() + { + await InitializeConnectionAsync(_echoApplication); + + await StartStreamAsync(1, _browserRequestHeaders, endStream: false); + await SendInvalidDataFrameAsync(1, frameLength: 5, padLength: 5); + + await WaitForConnectionErrorAsync(expectedLastStreamId: 1, expectedErrorCode: Http2ErrorCode.PROTOCOL_ERROR, ignoreNonGoAwayFrames: true); + } + + [Fact] + public async Task DATA_Received_PaddingGreaterThanFramePayloadLength_ConnectionError() + { + await InitializeConnectionAsync(_echoApplication); + + await StartStreamAsync(1, _browserRequestHeaders, endStream: false); + await SendInvalidDataFrameAsync(1, frameLength: 5, padLength: 6); + + await WaitForConnectionErrorAsync(expectedLastStreamId: 1, expectedErrorCode: Http2ErrorCode.PROTOCOL_ERROR, ignoreNonGoAwayFrames: true); + } + + [Fact] + public async Task DATA_Received_FrameLengthZeroPaddingZero_ConnectionError() + { + await InitializeConnectionAsync(_echoApplication); + + await StartStreamAsync(1, _browserRequestHeaders, endStream: false); + await SendInvalidDataFrameAsync(1, frameLength: 0, padLength: 0); + + await WaitForConnectionErrorAsync(expectedLastStreamId: 1, expectedErrorCode: Http2ErrorCode.PROTOCOL_ERROR, ignoreNonGoAwayFrames: true); + } + + [Fact] + public async Task DATA_Received_InterleavedWithHeaders_ConnectionError() + { + await InitializeConnectionAsync(_noopApplication); + + await SendHeadersAsync(1, Http2HeadersFrameFlags.NONE, _browserRequestHeaders); + await SendDataAsync(1, _helloWorldBytes, endStream: true); + + await WaitForConnectionErrorAsync(expectedLastStreamId: 0, expectedErrorCode: Http2ErrorCode.PROTOCOL_ERROR, ignoreNonGoAwayFrames: false); + } + + [Fact] + public async Task DATA_Received_StreamIdle_StreamError() + { + await InitializeConnectionAsync(_noopApplication); + + await SendDataAsync(1, _helloWorldBytes, endStream: false); + + await WaitForStreamErrorAsync(expectedStreamId: 1, expectedErrorCode: Http2ErrorCode.STREAM_CLOSED, ignoreNonRstStreamFrames: false); + + await StopConnectionAsync(expectedLastStreamId: 0, ignoreNonGoAwayFrames: false); + } + + [Fact] + public async Task DATA_Received_StreamHalfClosedRemote_StreamError() + { + await InitializeConnectionAsync(_echoWaitForAbortApplication); + + await StartStreamAsync(1, _postRequestHeaders, endStream: false); + await SendDataAsync(1, _helloBytes, endStream: true); + await SendDataAsync(1, _worldBytes, endStream: true); + + await WaitForStreamErrorAsync(expectedStreamId: 1, expectedErrorCode: Http2ErrorCode.STREAM_CLOSED, ignoreNonRstStreamFrames: true); + + await StopConnectionAsync(expectedLastStreamId: 1, ignoreNonGoAwayFrames: true); + } + + [Fact] + public async Task DATA_Received_StreamClosed_StreamError() + { + await InitializeConnectionAsync(_noopApplication); + + await StartStreamAsync(1, _postRequestHeaders, endStream: true); + + await ExpectAsync(Http2FrameType.HEADERS, + withLength: 55, + withFlags: (byte)Http2HeadersFrameFlags.END_HEADERS, + withStreamId: 1); + await ExpectAsync(Http2FrameType.DATA, + withLength: 0, + withFlags: (byte)Http2DataFrameFlags.END_STREAM, + withStreamId: 1); + + await SendDataAsync(1, _helloWorldBytes, endStream: false); + + await WaitForStreamErrorAsync(expectedStreamId: 1, expectedErrorCode: Http2ErrorCode.STREAM_CLOSED, ignoreNonRstStreamFrames: false); + + await StopConnectionAsync(expectedLastStreamId: 1, ignoreNonGoAwayFrames: false); + } + + [Fact] + public async Task DATA_Received_StreamClosedImplicitly_StreamError() + { + // http://httpwg.org/specs/rfc7540.html#rfc.section.5.1.1 + // + // The first use of a new stream identifier implicitly closes all streams in the "idle" state that + // might have been initiated by that peer with a lower-valued stream identifier. For example, if a + // client sends a HEADERS frame on stream 7 without ever sending a frame on stream 5, then stream 5 + // transitions to the "closed" state when the first frame for stream 7 is sent or received. + + await InitializeConnectionAsync(_noopApplication); + + await StartStreamAsync(3, _browserRequestHeaders, endStream: true); + + await ExpectAsync(Http2FrameType.HEADERS, + withLength: 55, + withFlags: (byte)Http2HeadersFrameFlags.END_HEADERS, + withStreamId: 3); + await ExpectAsync(Http2FrameType.DATA, + withLength: 0, + withFlags: (byte)Http2DataFrameFlags.END_STREAM, + withStreamId: 3); + + await SendDataAsync(1, _helloWorldBytes, endStream: true); + + await WaitForStreamErrorAsync(expectedStreamId: 1, expectedErrorCode: Http2ErrorCode.STREAM_CLOSED, ignoreNonRstStreamFrames: false); + + await StopConnectionAsync(expectedLastStreamId: 3, ignoreNonGoAwayFrames: false); + } + + [Fact] + public async Task HEADERS_Received_Decoded() + { + await InitializeConnectionAsync(_readHeadersApplication); + + await StartStreamAsync(1, _browserRequestHeaders, endStream: true); + + await ExpectAsync(Http2FrameType.HEADERS, + withLength: 55, + withFlags: (byte)Http2HeadersFrameFlags.END_HEADERS, + withStreamId: 1); + await ExpectAsync(Http2FrameType.DATA, + withLength: 0, + withFlags: (byte)Http2DataFrameFlags.END_STREAM, + withStreamId: 1); + + VerifyDecodedRequestHeaders(_browserRequestHeaders); + + await StopConnectionAsync(expectedLastStreamId: 1, ignoreNonGoAwayFrames: false); + } + + [Theory] + [InlineData(0)] + [InlineData(1)] + [InlineData(255)] + public async Task HEADERS_Received_WithPadding_Decoded(byte padLength) + { + await InitializeConnectionAsync(_readHeadersApplication); + + await SendHeadersWithPaddingAsync(1, _browserRequestHeaders, padLength, endStream: true); + + await ExpectAsync(Http2FrameType.HEADERS, + withLength: 55, + withFlags: (byte)Http2HeadersFrameFlags.END_HEADERS, + withStreamId: 1); + await ExpectAsync(Http2FrameType.DATA, + withLength: 0, + withFlags: (byte)Http2DataFrameFlags.END_STREAM, + withStreamId: 1); + + VerifyDecodedRequestHeaders(_browserRequestHeaders); + + await StopConnectionAsync(expectedLastStreamId: 1, ignoreNonGoAwayFrames: false); + } + + [Fact] + public async Task HEADERS_Received_WithPriority_Decoded() + { + await InitializeConnectionAsync(_readHeadersApplication); + + await SendHeadersWithPriorityAsync(1, _browserRequestHeaders, priority: 42, streamDependency: 0, endStream: true); + + await ExpectAsync(Http2FrameType.HEADERS, + withLength: 55, + withFlags: (byte)Http2HeadersFrameFlags.END_HEADERS, + withStreamId: 1); + await ExpectAsync(Http2FrameType.DATA, + withLength: 0, + withFlags: (byte)Http2DataFrameFlags.END_STREAM, + withStreamId: 1); + + VerifyDecodedRequestHeaders(_browserRequestHeaders); + + await StopConnectionAsync(expectedLastStreamId: 1, ignoreNonGoAwayFrames: false); + } + + [Theory] + [InlineData(0)] + [InlineData(1)] + [InlineData(255)] + public async Task HEADERS_Received_WithPriorityAndPadding_Decoded(byte padLength) + { + await InitializeConnectionAsync(_readHeadersApplication); + + await SendHeadersWithPaddingAndPriorityAsync(1, _browserRequestHeaders, padLength, priority: 42, streamDependency: 0, endStream: true); + + await ExpectAsync(Http2FrameType.HEADERS, + withLength: 55, + withFlags: (byte)Http2HeadersFrameFlags.END_HEADERS, + withStreamId: 1); + await ExpectAsync(Http2FrameType.DATA, + withLength: 0, + withFlags: (byte)Http2DataFrameFlags.END_STREAM, + withStreamId: 1); + + VerifyDecodedRequestHeaders(_browserRequestHeaders); + + await StopConnectionAsync(expectedLastStreamId: 1, ignoreNonGoAwayFrames: false); + } + + [Fact] + public async Task HEADERS_Received_StreamIdZero_ConnectionError() + { + await InitializeConnectionAsync(_noopApplication); + + await StartStreamAsync(0, _browserRequestHeaders, endStream: true); + + await WaitForConnectionErrorAsync(expectedLastStreamId: 0, expectedErrorCode: Http2ErrorCode.PROTOCOL_ERROR, ignoreNonGoAwayFrames: false); + } + + [Theory] + [InlineData(0)] + [InlineData(1)] + [InlineData(255)] + public async Task HEADERS_Received_PaddingEqualToFramePayloadLength_ConnectionError(byte padLength) + { + await InitializeConnectionAsync(_noopApplication); + + await SendInvalidHeadersFrameAsync(1, frameLength: padLength, padLength: padLength); + + await WaitForConnectionErrorAsync(expectedLastStreamId: 0, expectedErrorCode: Http2ErrorCode.PROTOCOL_ERROR, ignoreNonGoAwayFrames: false); + } + + [Theory] + [InlineData(0, 1)] + [InlineData(1, 2)] + [InlineData(254, 255)] + public async Task HEADERS_Received_PaddingGreaterThanFramePayloadLength_ConnectionError(int frameLength, byte padLength) + { + await InitializeConnectionAsync(_noopApplication); + + await SendInvalidHeadersFrameAsync(1, frameLength, padLength); + + await WaitForConnectionErrorAsync(expectedLastStreamId: 0, expectedErrorCode: Http2ErrorCode.PROTOCOL_ERROR, ignoreNonGoAwayFrames: false); + } + + [Fact] + public async Task HEADERS_Received_InterleavedWithHeaders_ConnectionError() + { + await InitializeConnectionAsync(_noopApplication); + + await SendHeadersAsync(1, Http2HeadersFrameFlags.NONE, _browserRequestHeaders); + await SendHeadersAsync(3, Http2HeadersFrameFlags.NONE, _browserRequestHeaders); + + await WaitForConnectionErrorAsync(expectedLastStreamId: 0, expectedErrorCode: Http2ErrorCode.PROTOCOL_ERROR, ignoreNonGoAwayFrames: false); + } + + [Fact] + public async Task PRIORITY_Received_StreamIdZero_ConnectionError() + { + await InitializeConnectionAsync(_noopApplication); + + await SendPriorityAsync(0); + + await WaitForConnectionErrorAsync(expectedLastStreamId: 0, expectedErrorCode: Http2ErrorCode.PROTOCOL_ERROR, ignoreNonGoAwayFrames: false); + } + + [Theory] + [InlineData(4)] + [InlineData(6)] + public async Task PRIORITY_Received_LengthNotFive_ConnectionError(int length) + { + await InitializeConnectionAsync(_noopApplication); + + await SendInvalidPriorityFrameAsync(1, length); + + await WaitForConnectionErrorAsync(expectedLastStreamId: 0, expectedErrorCode: Http2ErrorCode.FRAME_SIZE_ERROR, ignoreNonGoAwayFrames: false); + } + + [Fact] + public async Task PRIORITY_Received_InterleavedWithHeaders_ConnectionError() + { + await InitializeConnectionAsync(_noopApplication); + + await SendHeadersAsync(1, Http2HeadersFrameFlags.NONE, _browserRequestHeaders); + await SendPriorityAsync(1); + + await WaitForConnectionErrorAsync(expectedLastStreamId: 0, expectedErrorCode: Http2ErrorCode.PROTOCOL_ERROR, ignoreNonGoAwayFrames: false); + } + + [Fact] + public async Task RST_STREAM_Received_AbortsStream() + { + await InitializeConnectionAsync(_waitForAbortApplication); + + await StartStreamAsync(1, _browserRequestHeaders, endStream: true); + await SendRstStreamAsync(1); + + // No data is received from the stream since it was aborted before writing anything + + await StopConnectionAsync(expectedLastStreamId: 1, ignoreNonGoAwayFrames: false); + + await WaitForAllStreamsAsync(); + Assert.Contains(1, _abortedStreamIds); + } + + [Fact] + public async Task RST_STREAM_Received_AbortsStream_FlushedDataIsSent() + { + await InitializeConnectionAsync(_waitForAbortFlushingApplication); + + await StartStreamAsync(1, _browserRequestHeaders, endStream: true); + await SendRstStreamAsync(1); + + await ExpectAsync(Http2FrameType.HEADERS, + withLength: 37, + withFlags: (byte)Http2HeadersFrameFlags.END_HEADERS, + withStreamId: 1); + + // No END_STREAM DATA frame is received since the stream was aborted + + await StopConnectionAsync(expectedLastStreamId: 1, ignoreNonGoAwayFrames: false); + + Assert.Contains(1, _abortedStreamIds); + } + + [Fact] + public async Task RST_STREAM_Received_StreamIdZero_ConnectionError() + { + await InitializeConnectionAsync(_noopApplication); + + await SendRstStreamAsync(0); + + await WaitForConnectionErrorAsync(expectedLastStreamId: 0, expectedErrorCode: Http2ErrorCode.PROTOCOL_ERROR, ignoreNonGoAwayFrames: false); + } + + [Theory] + [InlineData(3)] + [InlineData(5)] + public async Task RST_STREAM_Received_LengthNotFour_ConnectionError(int length) + { + await InitializeConnectionAsync(_noopApplication); + + // Start stream 1 so it's legal to send it RST_STREAM frames + await StartStreamAsync(1, _browserRequestHeaders, endStream: true); + + await SendInvalidRstStreamFrameAsync(1, length); + + await WaitForConnectionErrorAsync(expectedLastStreamId: 1, expectedErrorCode: Http2ErrorCode.FRAME_SIZE_ERROR, ignoreNonGoAwayFrames: true); + } + + [Fact] + public async Task RST_STREAM_Received_InterleavedWithHeaders_ConnectionError() + { + await InitializeConnectionAsync(_noopApplication); + + await SendHeadersAsync(1, Http2HeadersFrameFlags.NONE, _browserRequestHeaders); + await SendRstStreamAsync(1); + + await WaitForConnectionErrorAsync(expectedLastStreamId: 0, expectedErrorCode: Http2ErrorCode.PROTOCOL_ERROR, ignoreNonGoAwayFrames: false); + } + + [Fact] + public async Task SETTINGS_Received_Sends_ACK() + { + await InitializeConnectionAsync(_noopApplication); + + await StopConnectionAsync(expectedLastStreamId: 0, ignoreNonGoAwayFrames: false); + } + + [Fact] + public async Task SETTINGS_Received_StreamIdZero_ConnectionError() + { + await InitializeConnectionAsync(_noopApplication); + + await SendSettingsWithInvalidStreamIdAsync(1); + + await WaitForConnectionErrorAsync(expectedLastStreamId: 0, expectedErrorCode: Http2ErrorCode.PROTOCOL_ERROR, ignoreNonGoAwayFrames: false); + } + + [Theory] + [InlineData(Http2SettingsParameter.SETTINGS_ENABLE_PUSH, 2, Http2ErrorCode.PROTOCOL_ERROR)] + [InlineData(Http2SettingsParameter.SETTINGS_ENABLE_PUSH, uint.MaxValue, Http2ErrorCode.PROTOCOL_ERROR)] + [InlineData(Http2SettingsParameter.SETTINGS_INITIAL_WINDOW_SIZE, (uint)int.MaxValue + 1, Http2ErrorCode.FLOW_CONTROL_ERROR)] + [InlineData(Http2SettingsParameter.SETTINGS_INITIAL_WINDOW_SIZE, uint.MaxValue, Http2ErrorCode.FLOW_CONTROL_ERROR)] + [InlineData(Http2SettingsParameter.SETTINGS_MAX_FRAME_SIZE, 0, Http2ErrorCode.PROTOCOL_ERROR)] + [InlineData(Http2SettingsParameter.SETTINGS_MAX_FRAME_SIZE, 1, Http2ErrorCode.PROTOCOL_ERROR)] + [InlineData(Http2SettingsParameter.SETTINGS_MAX_FRAME_SIZE, 16 * 1024 - 1, Http2ErrorCode.PROTOCOL_ERROR)] + [InlineData(Http2SettingsParameter.SETTINGS_MAX_FRAME_SIZE, 16 * 1024 * 1024, Http2ErrorCode.PROTOCOL_ERROR)] + [InlineData(Http2SettingsParameter.SETTINGS_MAX_FRAME_SIZE, uint.MaxValue, Http2ErrorCode.PROTOCOL_ERROR)] + public async Task SETTINGS_Received_InvalidParameterValue_ConnectionError(Http2SettingsParameter parameter, uint value, Http2ErrorCode expectedErrorCode) + { + await InitializeConnectionAsync(_noopApplication); + + await SendSettingsWithInvalidParameterValueAsync(parameter, value); + + await WaitForConnectionErrorAsync(expectedLastStreamId: 0, expectedErrorCode: expectedErrorCode, ignoreNonGoAwayFrames: false); + } + + [Fact] + public async Task SETTINGS_Received_InterleavedWithHeaders_ConnectionError() + { + await InitializeConnectionAsync(_noopApplication); + + await SendHeadersAsync(1, Http2HeadersFrameFlags.NONE, _browserRequestHeaders); + await SendSettingsAsync(); + + await WaitForConnectionErrorAsync(expectedLastStreamId: 0, expectedErrorCode: Http2ErrorCode.PROTOCOL_ERROR, ignoreNonGoAwayFrames: false); + } + + [Theory] + [InlineData(1)] + [InlineData(16 * 1024 - 9)] // Min. max. frame size minus header length + public async Task SETTINGS_Received_WithACK_LengthNotZero_ConnectionError(int length) + { + await InitializeConnectionAsync(_noopApplication); + + await SendSettingsAckWithInvalidLengthAsync(length); + + await WaitForConnectionErrorAsync(expectedLastStreamId: 0, expectedErrorCode: Http2ErrorCode.FRAME_SIZE_ERROR, ignoreNonGoAwayFrames: false); + } + + [Theory] + [InlineData(1)] + [InlineData(5)] + [InlineData(7)] + [InlineData(34)] + [InlineData(37)] + public async Task SETTINGS_Received_LengthNotMultipleOfSix_ConnectionError(int length) + { + await InitializeConnectionAsync(_noopApplication); + + await SendSettingsWithInvalidLengthAsync(length); + + await WaitForConnectionErrorAsync(expectedLastStreamId: 0, expectedErrorCode: Http2ErrorCode.FRAME_SIZE_ERROR, ignoreNonGoAwayFrames: false); + } + + [Fact] + public async Task PING_Received_Sends_ACK() + { + await InitializeConnectionAsync(_noopApplication); + + await SendPingAsync(); + await ExpectAsync(Http2FrameType.PING, + withLength: 8, + withFlags: (byte)Http2PingFrameFlags.ACK, + withStreamId: 0); + + await StopConnectionAsync(expectedLastStreamId: 0, ignoreNonGoAwayFrames: false); + } + + [Fact] + public async Task PING_Received_InterleavedWithHeaders_ConnectionError() + { + await InitializeConnectionAsync(_noopApplication); + + await SendHeadersAsync(1, Http2HeadersFrameFlags.NONE, _browserRequestHeaders); + await SendPingAsync(); + + await WaitForConnectionErrorAsync(expectedLastStreamId: 0, expectedErrorCode: Http2ErrorCode.PROTOCOL_ERROR, ignoreNonGoAwayFrames: false); + } + + [Theory] + [InlineData(0)] + [InlineData(1)] + [InlineData(7)] + [InlineData(9)] + public async Task PING_Received_LengthNotEight_ConnectionError(int length) + { + await InitializeConnectionAsync(_noopApplication); + + await SendPingWithInvalidLengthAsync(length); + + await WaitForConnectionErrorAsync(expectedLastStreamId: 0, expectedErrorCode: Http2ErrorCode.FRAME_SIZE_ERROR, ignoreNonGoAwayFrames: false); + } + + [Fact] + public async Task GOAWAY_Received_ConnectionStops() + { + await InitializeConnectionAsync(_noopApplication); + + await SendGoAwayAsync(); + + await WaitForConnectionStopAsync(expectedLastStreamId: 0, ignoreNonGoAwayFrames: false); + } + + [Fact] + public async Task GOAWAY_Received_AbortsAllStreams() + { + await InitializeConnectionAsync(_waitForAbortApplication); + + // Start some streams + await StartStreamAsync(1, _browserRequestHeaders, endStream: true); + await StartStreamAsync(3, _browserRequestHeaders, endStream: true); + await StartStreamAsync(5, _browserRequestHeaders, endStream: true); + + await SendGoAwayAsync(); + + await WaitForConnectionStopAsync(expectedLastStreamId: 5, ignoreNonGoAwayFrames: true); + + await WaitForAllStreamsAsync(); + Assert.Contains(1, _abortedStreamIds); + Assert.Contains(3, _abortedStreamIds); + Assert.Contains(5, _abortedStreamIds); + } + + [Fact] + public async Task GOAWAY_Received_InterleavedWithHeaders_ConnectionError() + { + await InitializeConnectionAsync(_noopApplication); + + await SendHeadersAsync(1, Http2HeadersFrameFlags.NONE, _browserRequestHeaders); + await SendGoAwayAsync(); + + await WaitForConnectionErrorAsync(expectedLastStreamId: 0, expectedErrorCode: Http2ErrorCode.PROTOCOL_ERROR, ignoreNonGoAwayFrames: false); + } + + [Fact] + public async Task WINDOW_UPDATE_Received_InterleavedWithHeaders_ConnectionError() + { + await InitializeConnectionAsync(_noopApplication); + + await SendHeadersAsync(1, Http2HeadersFrameFlags.NONE, _browserRequestHeaders); + await SendWindowUpdateAsync(1, sizeIncrement: 42); + + await WaitForConnectionErrorAsync(expectedLastStreamId: 0, expectedErrorCode: Http2ErrorCode.PROTOCOL_ERROR, ignoreNonGoAwayFrames: false); + } + + [Theory] + [InlineData(0, 3)] + [InlineData(0, 5)] + [InlineData(1, 3)] + [InlineData(1, 5)] + public async Task WINDOW_UPDATE_Received_LengthNotFour_ConnectionError(int streamId, int length) + { + await InitializeConnectionAsync(_noopApplication); + + await SendInvalidWindowUpdateAsync(streamId, sizeIncrement: 42, length: length); + + await WaitForConnectionErrorAsync(expectedLastStreamId: 0, expectedErrorCode: Http2ErrorCode.FRAME_SIZE_ERROR, ignoreNonGoAwayFrames: false); + } + + [Fact] + public async Task WINDOW_UPDATE_Received_OnConnection_SizeIncrementZero_ConnectionError() + { + await InitializeConnectionAsync(_noopApplication); + + await SendWindowUpdateAsync(0, sizeIncrement: 0); + + await WaitForConnectionErrorAsync(expectedLastStreamId: 0, expectedErrorCode: Http2ErrorCode.PROTOCOL_ERROR, ignoreNonGoAwayFrames: false); + } + + [Fact] + public async Task WINDOW_UPDATE_Received_OnStream_SizeIncrementZero_StreamError() + { + await InitializeConnectionAsync(_waitForAbortApplication); + + await StartStreamAsync(1, _browserRequestHeaders, endStream: true); + await SendWindowUpdateAsync(1, sizeIncrement: 0); + + await WaitForStreamErrorAsync(expectedStreamId: 1, expectedErrorCode: Http2ErrorCode.PROTOCOL_ERROR, ignoreNonRstStreamFrames: true); + + await StopConnectionAsync(expectedLastStreamId: 1, ignoreNonGoAwayFrames: true); + } + + [Fact] + public async Task CONTINUATION_Received_Decoded() + { + await InitializeConnectionAsync(_readHeadersApplication); + + await StartStreamAsync(1, _twoContinuationsRequestHeaders, endStream: true); + + await ExpectAsync(Http2FrameType.HEADERS, + withLength: 55, + withFlags: (byte)Http2HeadersFrameFlags.END_HEADERS, + withStreamId: 1); + await ExpectAsync(Http2FrameType.DATA, + withLength: 0, + withFlags: (byte)Http2HeadersFrameFlags.END_STREAM, + withStreamId: 1); + + VerifyDecodedRequestHeaders(_twoContinuationsRequestHeaders); + + await StopConnectionAsync(expectedLastStreamId: 1, ignoreNonGoAwayFrames: false); + } + + [Fact] + public async Task CONTINUATION_Received_StreamIdMismatch_ConnectionError() + { + await InitializeConnectionAsync(_readHeadersApplication); + + await SendHeadersAsync(1, Http2HeadersFrameFlags.NONE, _oneContinuationRequestHeaders); + await SendContinuationAsync(3, Http2ContinuationFrameFlags.END_HEADERS); + + await WaitForConnectionErrorAsync(expectedLastStreamId: 0, expectedErrorCode: Http2ErrorCode.PROTOCOL_ERROR, ignoreNonGoAwayFrames: false); + } + + [Fact] + public async Task CONTINUATION_Sent_WhenHeadersLargerThanFrameLength() + { + await InitializeConnectionAsync(_largeHeadersApplication); + + await StartStreamAsync(1, _browserRequestHeaders, endStream: true); + + var headersFrame = await ExpectAsync(Http2FrameType.HEADERS, + withLength: 55, + withFlags: (byte)Http2HeadersFrameFlags.NONE, + withStreamId: 1); + var continuationFrame1 = await ExpectAsync(Http2FrameType.CONTINUATION, + withLength: 16373, + withFlags: (byte)Http2ContinuationFrameFlags.NONE, + withStreamId: 1); + var continuationFrame2 = await ExpectAsync(Http2FrameType.CONTINUATION, + withLength: 16373, + withFlags: (byte)Http2ContinuationFrameFlags.END_HEADERS, + withStreamId: 1); + await ExpectAsync(Http2FrameType.DATA, + withLength: 0, + withFlags: (byte)Http2DataFrameFlags.END_STREAM, + withStreamId: 1); + + await StopConnectionAsync(expectedLastStreamId: 1, ignoreNonGoAwayFrames: false); + + var responseHeaders = new FrameResponseHeaders(); + _hpackDecoder.Decode(headersFrame.HeadersPayload, responseHeaders); + _hpackDecoder.Decode(continuationFrame1.HeadersPayload, responseHeaders); + _hpackDecoder.Decode(continuationFrame2.HeadersPayload, responseHeaders); + + var responseHeadersDictionary = (IDictionary)responseHeaders; + Assert.Equal(5, responseHeadersDictionary.Count); + Assert.Contains("date", responseHeadersDictionary.Keys, StringComparer.OrdinalIgnoreCase); + Assert.Equal("200", responseHeadersDictionary[":status"]); + Assert.Equal("0", responseHeadersDictionary["content-length"]); + Assert.Equal(_largeHeaderA, responseHeadersDictionary["a"]); + Assert.Equal(_largeHeaderB, responseHeadersDictionary["b"]); + } + + [Fact] + public async Task ConnectionError_AbortsAllStreams() + { + await InitializeConnectionAsync(_waitForAbortApplication); + + // Start some streams + await StartStreamAsync(1, _browserRequestHeaders, endStream: true); + await StartStreamAsync(3, _browserRequestHeaders, endStream: true); + await StartStreamAsync(5, _browserRequestHeaders, endStream: true); + + // Cause a connection error by sending an invalid frame + await SendDataAsync(0, _noData, endStream: false); + + await WaitForConnectionErrorAsync(expectedLastStreamId: 5, expectedErrorCode: Http2ErrorCode.PROTOCOL_ERROR, ignoreNonGoAwayFrames: false); + + await WaitForAllStreamsAsync(); + Assert.Contains(1, _abortedStreamIds); + Assert.Contains(3, _abortedStreamIds); + Assert.Contains(5, _abortedStreamIds); + } + + private async Task InitializeConnectionAsync(RequestDelegate application) + { + _connectionTask = _connection.ProcessAsync(new DummyApplication(application)); + + await SendPreambleAsync().ConfigureAwait(false); + await SendSettingsAsync(); + + await ExpectAsync(Http2FrameType.SETTINGS, + withLength: 0, + withFlags: 0, + withStreamId: 0); + + await ExpectAsync(Http2FrameType.SETTINGS, + withLength: 0, + withFlags: (byte)Http2SettingsFrameFlags.ACK, + withStreamId: 0); + } + + private async Task StartStreamAsync(int streamId, IEnumerable> headers, bool endStream) + { + var tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + _runningStreams[streamId] = tcs; + + var frame = new Http2Frame(); + frame.PrepareHeaders(Http2HeadersFrameFlags.NONE, streamId); + var done = _hpackEncoder.BeginEncode(headers, frame.HeadersPayload, out var length); + frame.Length = length; + + if (done) + { + frame.HeadersFlags = Http2HeadersFrameFlags.END_HEADERS; + } + + if (endStream) + { + frame.HeadersFlags |= Http2HeadersFrameFlags.END_STREAM; + } + + await SendAsync(frame.Raw); + + while (!done) + { + frame.PrepareContinuation(Http2ContinuationFrameFlags.NONE, streamId); + done = _hpackEncoder.Encode(frame.HeadersPayload, out length); + frame.Length = length; + + if (done) + { + frame.ContinuationFlags = Http2ContinuationFrameFlags.END_HEADERS; + } + + await SendAsync(frame.Raw); + } + } + + private async Task SendHeadersWithPaddingAsync(int streamId, IEnumerable> headers, byte padLength, bool endStream) + { + var tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + _runningStreams[streamId] = tcs; + + var frame = new Http2Frame(); + + frame.PrepareHeaders(Http2HeadersFrameFlags.END_HEADERS | Http2HeadersFrameFlags.PADDED, streamId); + frame.HeadersPadLength = padLength; + + _hpackEncoder.BeginEncode(headers, frame.HeadersPayload, out var length); + + frame.Length = 1 + length + padLength; + frame.Payload.Slice(1 + length).Fill(0); + + if (endStream) + { + frame.HeadersFlags |= Http2HeadersFrameFlags.END_STREAM; + } + + await SendAsync(frame.Raw); + } + + private async Task SendHeadersWithPriorityAsync(int streamId, IEnumerable> headers, byte priority, int streamDependency, bool endStream) + { + var tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + _runningStreams[streamId] = tcs; + + var frame = new Http2Frame(); + frame.PrepareHeaders(Http2HeadersFrameFlags.END_HEADERS | Http2HeadersFrameFlags.PRIORITY, streamId); + frame.HeadersPriority = priority; + frame.HeadersStreamDependency = streamDependency; + + _hpackEncoder.BeginEncode(headers, frame.HeadersPayload, out var length); + + frame.Length = 5 + length; + + if (endStream) + { + frame.HeadersFlags |= Http2HeadersFrameFlags.END_STREAM; + } + + await SendAsync(frame.Raw); + } + + private async Task SendHeadersWithPaddingAndPriorityAsync(int streamId, IEnumerable> headers, byte padLength, byte priority, int streamDependency, bool endStream) + { + var tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + _runningStreams[streamId] = tcs; + + var frame = new Http2Frame(); + frame.PrepareHeaders(Http2HeadersFrameFlags.END_HEADERS | Http2HeadersFrameFlags.PADDED | Http2HeadersFrameFlags.PRIORITY, streamId); + frame.HeadersPadLength = padLength; + frame.HeadersPriority = priority; + frame.HeadersStreamDependency = streamDependency; + + _hpackEncoder.BeginEncode(headers, frame.HeadersPayload, out var length); + + frame.Length = 6 + length + padLength; + frame.Payload.Slice(6 + length).Fill(0); + + if (endStream) + { + frame.HeadersFlags |= Http2HeadersFrameFlags.END_STREAM; + } + + await SendAsync(frame.Raw); + } + + private Task SendStreamDataAsync(int streamId, Span data) + { + var tasks = new List(); + var frame = new Http2Frame(); + + frame.PrepareData(streamId); + + while (data.Length > frame.Length) + { + data.Slice(0, frame.Length).CopyTo(frame.Payload); + data = data.Slice(frame.Length); + tasks.Add(SendAsync(frame.Raw)); + } + + frame.Length = data.Length; + frame.DataFlags = Http2DataFrameFlags.END_STREAM; + data.CopyTo(frame.Payload); + tasks.Add(SendAsync(frame.Raw)); + + return Task.WhenAll(tasks); + } + + private Task WaitForAllStreamsAsync() + { + return Task.WhenAll(_runningStreams.Values.Select(tcs => tcs.Task)).TimeoutAfter(TimeSpan.FromSeconds(30)); + } + + private async Task SendAsync(ArraySegment span) + { + var writableBuffer = _inputPipe.Writer.Alloc(1); + writableBuffer.Write(span); + await writableBuffer.FlushAsync(); + } + + private Task SendPreambleAsync() => SendAsync(new ArraySegment(Http2Connection.ClientPreface)); + + private Task SendSettingsAsync() + { + var frame = new Http2Frame(); + frame.PrepareSettings(Http2SettingsFrameFlags.NONE, _clientSettings); + return SendAsync(frame.Raw); + } + + private Task SendSettingsAckWithInvalidLengthAsync(int length) + { + var frame = new Http2Frame(); + frame.PrepareSettings(Http2SettingsFrameFlags.ACK); + frame.Length = length; + return SendAsync(frame.Raw); + } + + private Task SendSettingsWithInvalidStreamIdAsync(int streamId) + { + var frame = new Http2Frame(); + frame.PrepareSettings(Http2SettingsFrameFlags.NONE, _clientSettings); + frame.StreamId = streamId; + return SendAsync(frame.Raw); + } + + private Task SendSettingsWithInvalidLengthAsync(int length) + { + var frame = new Http2Frame(); + frame.PrepareSettings(Http2SettingsFrameFlags.NONE, _clientSettings); + frame.Length = length; + return SendAsync(frame.Raw); + } + + private Task SendSettingsWithInvalidParameterValueAsync(Http2SettingsParameter parameter, uint value) + { + var frame = new Http2Frame(); + frame.PrepareSettings(Http2SettingsFrameFlags.NONE); + frame.Length = 6; + + frame.Payload[0] = (byte)((ushort)parameter >> 8); + frame.Payload[1] = (byte)(ushort)parameter; + frame.Payload[2] = (byte)(value >> 24); + frame.Payload[3] = (byte)(value >> 16); + frame.Payload[4] = (byte)(value >> 8); + frame.Payload[5] = (byte)value; + + return SendAsync(frame.Raw); + } + + private async Task SendHeadersAsync(int streamId, Http2HeadersFrameFlags flags, IEnumerable> headers) + { + var frame = new Http2Frame(); + + frame.PrepareHeaders(flags, streamId); + var done = _hpackEncoder.BeginEncode(headers, frame.Payload, out var length); + frame.Length = length; + + await SendAsync(frame.Raw); + + return done; + } + + private Task SendInvalidHeadersFrameAsync(int streamId, int frameLength, byte padLength) + { + Assert.True(padLength >= frameLength, $"{nameof(padLength)} must be greater than or equal to {nameof(frameLength)} to create an invalid frame."); + + var frame = new Http2Frame(); + + frame.PrepareHeaders(Http2HeadersFrameFlags.PADDED, streamId); + frame.Payload[0] = padLength; + + // Set length last so .Payload can be written to + frame.Length = frameLength; + + return SendAsync(frame.Raw); + } + + private async Task SendContinuationAsync(int streamId, Http2ContinuationFrameFlags flags) + { + var frame = new Http2Frame(); + + frame.PrepareContinuation(flags, streamId); + var done =_hpackEncoder.Encode(frame.Payload, out var length); + frame.Length = length; + + await SendAsync(frame.Raw); + + return done; + } + + private Task SendDataAsync(int streamId, Span data, bool endStream) + { + var frame = new Http2Frame(); + + frame.PrepareData(streamId); + frame.Length = data.Length; + frame.DataFlags = endStream ? Http2DataFrameFlags.END_STREAM : Http2DataFrameFlags.NONE; + data.CopyTo(frame.DataPayload); + + return SendAsync(frame.Raw); + } + + private Task SendDataWithPaddingAsync(int streamId, Span data, byte padLength, bool endStream) + { + var frame = new Http2Frame(); + + frame.PrepareData(streamId, padLength); + frame.Length = data.Length + 1 + padLength; + data.CopyTo(frame.DataPayload); + + if (endStream) + { + frame.DataFlags |= Http2DataFrameFlags.END_STREAM; + } + + return SendAsync(frame.Raw); + } + + private Task SendInvalidDataFrameAsync(int streamId, int frameLength, byte padLength) + { + Assert.True(padLength >= frameLength, $"{nameof(padLength)} must be greater than or equal to {nameof(frameLength)} to create an invalid frame."); + + var frame = new Http2Frame(); + + frame.PrepareData(streamId); + frame.DataFlags = Http2DataFrameFlags.PADDED; + frame.Payload[0] = padLength; + + // Set length last so .Payload can be written to + frame.Length = frameLength; + + return SendAsync(frame.Raw); + } + + private Task SendPingAsync() + { + var pingFrame = new Http2Frame(); + pingFrame.PreparePing(Http2PingFrameFlags.NONE); + return SendAsync(pingFrame.Raw); + } + + private Task SendPingWithInvalidLengthAsync(int length) + { + var pingFrame = new Http2Frame(); + pingFrame.PreparePing(Http2PingFrameFlags.NONE); + pingFrame.Length = length; + return SendAsync(pingFrame.Raw); + } + + private Task SendPriorityAsync(int streamId) + { + var priorityFrame = new Http2Frame(); + priorityFrame.PreparePriority(streamId, streamDependency: 0, exclusive: false, weight: 0); + return SendAsync(priorityFrame.Raw); + } + + private Task SendInvalidPriorityFrameAsync(int streamId, int length) + { + var priorityFrame = new Http2Frame(); + priorityFrame.PreparePriority(streamId, streamDependency: 0, exclusive: false, weight: 0); + priorityFrame.Length = length; + return SendAsync(priorityFrame.Raw); + } + + private Task SendRstStreamAsync(int streamId) + { + var rstStreamFrame = new Http2Frame(); + rstStreamFrame.PrepareRstStream(streamId, Http2ErrorCode.CANCEL); + return SendAsync(rstStreamFrame.Raw); + } + + private Task SendInvalidRstStreamFrameAsync(int streamId, int length) + { + var frame = new Http2Frame(); + frame.PrepareRstStream(streamId, Http2ErrorCode.CANCEL); + frame.Length = length; + return SendAsync(frame.Raw); + } + + private Task SendGoAwayAsync() + { + var frame = new Http2Frame(); + frame.PrepareGoAway(0, Http2ErrorCode.NO_ERROR); + return SendAsync(frame.Raw); + } + + private Task SendWindowUpdateAsync(int streamId, int sizeIncrement) + { + var frame = new Http2Frame(); + frame.PrepareWindowUpdate(streamId, sizeIncrement); + return SendAsync(frame.Raw); + } + + private Task SendInvalidWindowUpdateAsync(int streamId, int sizeIncrement, int length) + { + var frame = new Http2Frame(); + frame.PrepareWindowUpdate(streamId, sizeIncrement); + frame.Length = length; + return SendAsync(frame.Raw); + } + + private async Task ReceiveFrameAsync() + { + var frame = new Http2Frame(); + + while (true) + { + var result = await _outputPipe.Reader.ReadAsync(); + var buffer = result.Buffer; + var consumed = buffer.Start; + var examined = buffer.End; + + try + { + Assert.True(buffer.Length > 0); + + if (Http2FrameReader.ReadFrame(buffer, frame, out consumed, out examined)) + { + return frame; + } + } + finally + { + _outputPipe.Reader.Advance(consumed, examined); + } + } + } + + private async Task ReceiveSettingsAck() + { + var frame = await ReceiveFrameAsync(); + + Assert.Equal(Http2FrameType.SETTINGS, frame.Type); + Assert.Equal(Http2SettingsFrameFlags.ACK, frame.SettingsFlags); + } + + private async Task ExpectAsync(Http2FrameType type, int withLength, byte withFlags, int withStreamId) + { + var frame = await ReceiveFrameAsync(); + + Assert.Equal(type, frame.Type); + Assert.Equal(withLength, frame.Length); + Assert.Equal(withFlags, frame.Flags); + Assert.Equal(withStreamId, frame.StreamId); + + return frame; + } + + private Task StopConnectionAsync(int expectedLastStreamId, bool ignoreNonGoAwayFrames) + { + _inputPipe.Writer.Complete(); + + return WaitForConnectionStopAsync(expectedLastStreamId, ignoreNonGoAwayFrames); + } + + private Task WaitForConnectionStopAsync(int expectedLastStreamId, bool ignoreNonGoAwayFrames) + { + return WaitForConnectionErrorAsync(expectedLastStreamId, Http2ErrorCode.NO_ERROR, ignoreNonGoAwayFrames); + } + + private async Task WaitForConnectionErrorAsync(int expectedLastStreamId, Http2ErrorCode expectedErrorCode, bool ignoreNonGoAwayFrames) + { + var frame = await ReceiveFrameAsync(); + + if (ignoreNonGoAwayFrames) + { + while (frame.Type != Http2FrameType.GOAWAY) + { + frame = await ReceiveFrameAsync(); + } + } + + Assert.Equal(Http2FrameType.GOAWAY, frame.Type); + Assert.Equal(8, frame.Length); + Assert.Equal(0, frame.Flags); + Assert.Equal(0, frame.StreamId); + Assert.Equal(expectedLastStreamId, frame.GoAwayLastStreamId); + Assert.Equal(expectedErrorCode, frame.GoAwayErrorCode); + + await _connectionTask; + _inputPipe.Writer.Complete(); + } + + private async Task WaitForStreamErrorAsync(int expectedStreamId, Http2ErrorCode expectedErrorCode, bool ignoreNonRstStreamFrames) + { + var frame = await ReceiveFrameAsync(); + + if (ignoreNonRstStreamFrames) + { + while (frame.Type != Http2FrameType.RST_STREAM) + { + frame = await ReceiveFrameAsync(); + } + } + + Assert.Equal(Http2FrameType.RST_STREAM, frame.Type); + Assert.Equal(4, frame.Length); + Assert.Equal(0, frame.Flags); + Assert.Equal(expectedStreamId, frame.StreamId); + Assert.Equal(expectedErrorCode, frame.RstStreamErrorCode); + } + + private void VerifyDecodedRequestHeaders(IEnumerable> expectedHeaders) + { + foreach (var header in expectedHeaders) + { + Assert.True(_receivedHeaders.TryGetValue(header.Key, out var value), header.Key); + Assert.Equal(header.Value, value, ignoreCase: true); + } + } + } +} diff --git a/test/Kestrel.Core.Tests/HuffmanTests.cs b/test/Kestrel.Core.Tests/HuffmanTests.cs new file mode 100644 index 0000000000..7e0375c5da --- /dev/null +++ b/test/Kestrel.Core.Tests/HuffmanTests.cs @@ -0,0 +1,329 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2.HPack; +using Xunit; + +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests +{ + public class HuffmanTests + { + [Fact] + public void HuffmanDecodeString() + { + // h e.......e l........l l o.......o + var encodedHello = new byte[] { 0b100111_00, 0b101_10100, 0b0_101000_0, 0b0111_1111 }; + + Assert.Equal("hello", Huffman.Decode(encodedHello, 0, encodedHello.Length)); + + var encodedHeader = new byte[] + { + 0xb6, 0xb9, 0xac, 0x1c, 0x85, 0x58, 0xd5, 0x20, 0xa4, 0xb6, 0xc2, 0xad, 0x61, 0x7b, 0x5a, 0x54, 0x25, 0x1f + }; + + Assert.Equal("upgrade-insecure-requests", Huffman.Decode(encodedHeader, 0, encodedHeader.Length)); + + encodedHeader = new byte[] + { + // "t + 0xfe, 0x53 + }; + + Assert.Equal("\"t", Huffman.Decode(encodedHeader, 0, encodedHeader.Length)); + } + + [Theory] + [MemberData(nameof(HuffmanData))] + public void HuffmanEncode(int code, uint expectedEncoded, int expectedBitLength) + { + var (encoded, bitLength) = Huffman.Encode(code); + Assert.Equal(expectedEncoded, encoded); + Assert.Equal(expectedBitLength, bitLength); + } + + [Theory] + [MemberData(nameof(HuffmanData))] + public void HuffmanDecode(int code, uint encoded, int bitLength) + { + Assert.Equal(code, Huffman.Decode(encoded, out var decodedBits)); + Assert.Equal(bitLength, decodedBits); + } + + [Theory] + [MemberData(nameof(HuffmanData))] + public void HuffmanEncodeDecode(int code, uint encoded, int bitLength) + { + Assert.Equal(code, Huffman.Decode(Huffman.Encode(code).encoded, out var decodedBits)); + Assert.Equal(bitLength, decodedBits); + } + + public static TheoryData HuffmanData + { + get + { + var data = new TheoryData(); + + data.Add(0, 0b11111111_11000000_00000000_00000000, 13); + data.Add(1, 0b11111111_11111111_10110000_00000000, 23); + data.Add(2, 0b11111111_11111111_11111110_00100000, 28); + data.Add(3, 0b11111111_11111111_11111110_00110000, 28); + data.Add(4, 0b11111111_11111111_11111110_01000000, 28); + data.Add(5, 0b11111111_11111111_11111110_01010000, 28); + data.Add(6, 0b11111111_11111111_11111110_01100000, 28); + data.Add(7, 0b11111111_11111111_11111110_01110000, 28); + data.Add(8, 0b11111111_11111111_11111110_10000000, 28); + data.Add(9, 0b11111111_11111111_11101010_00000000, 24); + data.Add(10, 0b11111111_11111111_11111111_11110000, 30); + data.Add(11, 0b11111111_11111111_11111110_10010000, 28); + data.Add(12, 0b11111111_11111111_11111110_10100000, 28); + data.Add(13, 0b11111111_11111111_11111111_11110100, 30); + data.Add(14, 0b11111111_11111111_11111110_10110000, 28); + data.Add(15, 0b11111111_11111111_11111110_11000000, 28); + data.Add(16, 0b11111111_11111111_11111110_11010000, 28); + data.Add(17, 0b11111111_11111111_11111110_11100000, 28); + data.Add(18, 0b11111111_11111111_11111110_11110000, 28); + data.Add(19, 0b11111111_11111111_11111111_00000000, 28); + data.Add(20, 0b11111111_11111111_11111111_00010000, 28); + data.Add(21, 0b11111111_11111111_11111111_00100000, 28); + data.Add(22, 0b11111111_11111111_11111111_11111000, 30); + data.Add(23, 0b11111111_11111111_11111111_00110000, 28); + data.Add(24, 0b11111111_11111111_11111111_01000000, 28); + data.Add(25, 0b11111111_11111111_11111111_01010000, 28); + data.Add(26, 0b11111111_11111111_11111111_01100000, 28); + data.Add(27, 0b11111111_11111111_11111111_01110000, 28); + data.Add(28, 0b11111111_11111111_11111111_10000000, 28); + data.Add(29, 0b11111111_11111111_11111111_10010000, 28); + data.Add(30, 0b11111111_11111111_11111111_10100000, 28); + data.Add(31, 0b11111111_11111111_11111111_10110000, 28); + data.Add(32, 0b01010000_00000000_00000000_00000000, 6); + data.Add(33, 0b11111110_00000000_00000000_00000000, 10); + data.Add(34, 0b11111110_01000000_00000000_00000000, 10); + data.Add(35, 0b11111111_10100000_00000000_00000000, 12); + data.Add(36, 0b11111111_11001000_00000000_00000000, 13); + data.Add(37, 0b01010100_00000000_00000000_00000000, 6); + data.Add(38, 0b11111000_00000000_00000000_00000000, 8); + data.Add(39, 0b11111111_01000000_00000000_00000000, 11); + data.Add(40, 0b11111110_10000000_00000000_00000000, 10); + data.Add(41, 0b11111110_11000000_00000000_00000000, 10); + data.Add(42, 0b11111001_00000000_00000000_00000000, 8); + data.Add(43, 0b11111111_01100000_00000000_00000000, 11); + data.Add(44, 0b11111010_00000000_00000000_00000000, 8); + data.Add(45, 0b01011000_00000000_00000000_00000000, 6); + data.Add(46, 0b01011100_00000000_00000000_00000000, 6); + data.Add(47, 0b01100000_00000000_00000000_00000000, 6); + data.Add(48, 0b00000000_00000000_00000000_00000000, 5); + data.Add(49, 0b00001000_00000000_00000000_00000000, 5); + data.Add(50, 0b00010000_00000000_00000000_00000000, 5); + data.Add(51, 0b01100100_00000000_00000000_00000000, 6); + data.Add(52, 0b01101000_00000000_00000000_00000000, 6); + data.Add(53, 0b01101100_00000000_00000000_00000000, 6); + data.Add(54, 0b01110000_00000000_00000000_00000000, 6); + data.Add(55, 0b01110100_00000000_00000000_00000000, 6); + data.Add(56, 0b01111000_00000000_00000000_00000000, 6); + data.Add(57, 0b01111100_00000000_00000000_00000000, 6); + data.Add(58, 0b10111000_00000000_00000000_00000000, 7); + data.Add(59, 0b11111011_00000000_00000000_00000000, 8); + data.Add(60, 0b11111111_11111000_00000000_00000000, 15); + data.Add(61, 0b10000000_00000000_00000000_00000000, 6); + data.Add(62, 0b11111111_10110000_00000000_00000000, 12); + data.Add(63, 0b11111111_00000000_00000000_00000000, 10); + data.Add(64, 0b11111111_11010000_00000000_00000000, 13); + data.Add(65, 0b10000100_00000000_00000000_00000000, 6); + data.Add(66, 0b10111010_00000000_00000000_00000000, 7); + data.Add(67, 0b10111100_00000000_00000000_00000000, 7); + data.Add(68, 0b10111110_00000000_00000000_00000000, 7); + data.Add(69, 0b11000000_00000000_00000000_00000000, 7); + data.Add(70, 0b11000010_00000000_00000000_00000000, 7); + data.Add(71, 0b11000100_00000000_00000000_00000000, 7); + data.Add(72, 0b11000110_00000000_00000000_00000000, 7); + data.Add(73, 0b11001000_00000000_00000000_00000000, 7); + data.Add(74, 0b11001010_00000000_00000000_00000000, 7); + data.Add(75, 0b11001100_00000000_00000000_00000000, 7); + data.Add(76, 0b11001110_00000000_00000000_00000000, 7); + data.Add(77, 0b11010000_00000000_00000000_00000000, 7); + data.Add(78, 0b11010010_00000000_00000000_00000000, 7); + data.Add(79, 0b11010100_00000000_00000000_00000000, 7); + data.Add(80, 0b11010110_00000000_00000000_00000000, 7); + data.Add(81, 0b11011000_00000000_00000000_00000000, 7); + data.Add(82, 0b11011010_00000000_00000000_00000000, 7); + data.Add(83, 0b11011100_00000000_00000000_00000000, 7); + data.Add(84, 0b11011110_00000000_00000000_00000000, 7); + data.Add(85, 0b11100000_00000000_00000000_00000000, 7); + data.Add(86, 0b11100010_00000000_00000000_00000000, 7); + data.Add(87, 0b11100100_00000000_00000000_00000000, 7); + data.Add(88, 0b11111100_00000000_00000000_00000000, 8); + data.Add(89, 0b11100110_00000000_00000000_00000000, 7); + data.Add(90, 0b11111101_00000000_00000000_00000000, 8); + data.Add(91, 0b11111111_11011000_00000000_00000000, 13); + data.Add(92, 0b11111111_11111110_00000000_00000000, 19); + data.Add(93, 0b11111111_11100000_00000000_00000000, 13); + data.Add(94, 0b11111111_11110000_00000000_00000000, 14); + data.Add(95, 0b10001000_00000000_00000000_00000000, 6); + data.Add(96, 0b11111111_11111010_00000000_00000000, 15); + data.Add(97, 0b00011000_00000000_00000000_00000000, 5); + data.Add(98, 0b10001100_00000000_00000000_00000000, 6); + data.Add(99, 0b00100000_00000000_00000000_00000000, 5); + data.Add(100, 0b10010000_00000000_00000000_00000000, 6); + data.Add(101, 0b00101000_00000000_00000000_00000000, 5); + data.Add(102, 0b10010100_00000000_00000000_00000000, 6); + data.Add(103, 0b10011000_00000000_00000000_00000000, 6); + data.Add(104, 0b10011100_00000000_00000000_00000000, 6); + data.Add(105, 0b00110000_00000000_00000000_00000000, 5); + data.Add(106, 0b11101000_00000000_00000000_00000000, 7); + data.Add(107, 0b11101010_00000000_00000000_00000000, 7); + data.Add(108, 0b10100000_00000000_00000000_00000000, 6); + data.Add(109, 0b10100100_00000000_00000000_00000000, 6); + data.Add(110, 0b10101000_00000000_00000000_00000000, 6); + data.Add(111, 0b00111000_00000000_00000000_00000000, 5); + data.Add(112, 0b10101100_00000000_00000000_00000000, 6); + data.Add(113, 0b11101100_00000000_00000000_00000000, 7); + data.Add(114, 0b10110000_00000000_00000000_00000000, 6); + data.Add(115, 0b01000000_00000000_00000000_00000000, 5); + data.Add(116, 0b01001000_00000000_00000000_00000000, 5); + data.Add(117, 0b10110100_00000000_00000000_00000000, 6); + data.Add(118, 0b11101110_00000000_00000000_00000000, 7); + data.Add(119, 0b11110000_00000000_00000000_00000000, 7); + data.Add(120, 0b11110010_00000000_00000000_00000000, 7); + data.Add(121, 0b11110100_00000000_00000000_00000000, 7); + data.Add(122, 0b11110110_00000000_00000000_00000000, 7); + data.Add(123, 0b11111111_11111100_00000000_00000000, 15); + data.Add(124, 0b11111111_10000000_00000000_00000000, 11); + data.Add(125, 0b11111111_11110100_00000000_00000000, 14); + data.Add(126, 0b11111111_11101000_00000000_00000000, 13); + data.Add(127, 0b11111111_11111111_11111111_11000000, 28); + data.Add(128, 0b11111111_11111110_01100000_00000000, 20); + data.Add(129, 0b11111111_11111111_01001000_00000000, 22); + data.Add(130, 0b11111111_11111110_01110000_00000000, 20); + data.Add(131, 0b11111111_11111110_10000000_00000000, 20); + data.Add(132, 0b11111111_11111111_01001100_00000000, 22); + data.Add(133, 0b11111111_11111111_01010000_00000000, 22); + data.Add(134, 0b11111111_11111111_01010100_00000000, 22); + data.Add(135, 0b11111111_11111111_10110010_00000000, 23); + data.Add(136, 0b11111111_11111111_01011000_00000000, 22); + data.Add(137, 0b11111111_11111111_10110100_00000000, 23); + data.Add(138, 0b11111111_11111111_10110110_00000000, 23); + data.Add(139, 0b11111111_11111111_10111000_00000000, 23); + data.Add(140, 0b11111111_11111111_10111010_00000000, 23); + data.Add(141, 0b11111111_11111111_10111100_00000000, 23); + data.Add(142, 0b11111111_11111111_11101011_00000000, 24); + data.Add(143, 0b11111111_11111111_10111110_00000000, 23); + data.Add(144, 0b11111111_11111111_11101100_00000000, 24); + data.Add(145, 0b11111111_11111111_11101101_00000000, 24); + data.Add(146, 0b11111111_11111111_01011100_00000000, 22); + data.Add(147, 0b11111111_11111111_11000000_00000000, 23); + data.Add(148, 0b11111111_11111111_11101110_00000000, 24); + data.Add(149, 0b11111111_11111111_11000010_00000000, 23); + data.Add(150, 0b11111111_11111111_11000100_00000000, 23); + data.Add(151, 0b11111111_11111111_11000110_00000000, 23); + data.Add(152, 0b11111111_11111111_11001000_00000000, 23); + data.Add(153, 0b11111111_11111110_11100000_00000000, 21); + data.Add(154, 0b11111111_11111111_01100000_00000000, 22); + data.Add(155, 0b11111111_11111111_11001010_00000000, 23); + data.Add(156, 0b11111111_11111111_01100100_00000000, 22); + data.Add(157, 0b11111111_11111111_11001100_00000000, 23); + data.Add(158, 0b11111111_11111111_11001110_00000000, 23); + data.Add(159, 0b11111111_11111111_11101111_00000000, 24); + data.Add(160, 0b11111111_11111111_01101000_00000000, 22); + data.Add(161, 0b11111111_11111110_11101000_00000000, 21); + data.Add(162, 0b11111111_11111110_10010000_00000000, 20); + data.Add(163, 0b11111111_11111111_01101100_00000000, 22); + data.Add(164, 0b11111111_11111111_01110000_00000000, 22); + data.Add(165, 0b11111111_11111111_11010000_00000000, 23); + data.Add(166, 0b11111111_11111111_11010010_00000000, 23); + data.Add(167, 0b11111111_11111110_11110000_00000000, 21); + data.Add(168, 0b11111111_11111111_11010100_00000000, 23); + data.Add(169, 0b11111111_11111111_01110100_00000000, 22); + data.Add(170, 0b11111111_11111111_01111000_00000000, 22); + data.Add(171, 0b11111111_11111111_11110000_00000000, 24); + data.Add(172, 0b11111111_11111110_11111000_00000000, 21); + data.Add(173, 0b11111111_11111111_01111100_00000000, 22); + data.Add(174, 0b11111111_11111111_11010110_00000000, 23); + data.Add(175, 0b11111111_11111111_11011000_00000000, 23); + data.Add(176, 0b11111111_11111111_00000000_00000000, 21); + data.Add(177, 0b11111111_11111111_00001000_00000000, 21); + data.Add(178, 0b11111111_11111111_10000000_00000000, 22); + data.Add(179, 0b11111111_11111111_00010000_00000000, 21); + data.Add(180, 0b11111111_11111111_11011010_00000000, 23); + data.Add(181, 0b11111111_11111111_10000100_00000000, 22); + data.Add(182, 0b11111111_11111111_11011100_00000000, 23); + data.Add(183, 0b11111111_11111111_11011110_00000000, 23); + data.Add(184, 0b11111111_11111110_10100000_00000000, 20); + data.Add(185, 0b11111111_11111111_10001000_00000000, 22); + data.Add(186, 0b11111111_11111111_10001100_00000000, 22); + data.Add(187, 0b11111111_11111111_10010000_00000000, 22); + data.Add(188, 0b11111111_11111111_11100000_00000000, 23); + data.Add(189, 0b11111111_11111111_10010100_00000000, 22); + data.Add(190, 0b11111111_11111111_10011000_00000000, 22); + data.Add(191, 0b11111111_11111111_11100010_00000000, 23); + data.Add(192, 0b11111111_11111111_11111000_00000000, 26); + data.Add(193, 0b11111111_11111111_11111000_01000000, 26); + data.Add(194, 0b11111111_11111110_10110000_00000000, 20); + data.Add(195, 0b11111111_11111110_00100000_00000000, 19); + data.Add(196, 0b11111111_11111111_10011100_00000000, 22); + data.Add(197, 0b11111111_11111111_11100100_00000000, 23); + data.Add(198, 0b11111111_11111111_10100000_00000000, 22); + data.Add(199, 0b11111111_11111111_11110110_00000000, 25); + data.Add(200, 0b11111111_11111111_11111000_10000000, 26); + data.Add(201, 0b11111111_11111111_11111000_11000000, 26); + data.Add(202, 0b11111111_11111111_11111001_00000000, 26); + data.Add(203, 0b11111111_11111111_11111011_11000000, 27); + data.Add(204, 0b11111111_11111111_11111011_11100000, 27); + data.Add(205, 0b11111111_11111111_11111001_01000000, 26); + data.Add(206, 0b11111111_11111111_11110001_00000000, 24); + data.Add(207, 0b11111111_11111111_11110110_10000000, 25); + data.Add(208, 0b11111111_11111110_01000000_00000000, 19); + data.Add(209, 0b11111111_11111111_00011000_00000000, 21); + data.Add(210, 0b11111111_11111111_11111001_10000000, 26); + data.Add(211, 0b11111111_11111111_11111100_00000000, 27); + data.Add(212, 0b11111111_11111111_11111100_00100000, 27); + data.Add(213, 0b11111111_11111111_11111001_11000000, 26); + data.Add(214, 0b11111111_11111111_11111100_01000000, 27); + data.Add(215, 0b11111111_11111111_11110010_00000000, 24); + data.Add(216, 0b11111111_11111111_00100000_00000000, 21); + data.Add(217, 0b11111111_11111111_00101000_00000000, 21); + data.Add(218, 0b11111111_11111111_11111010_00000000, 26); + data.Add(219, 0b11111111_11111111_11111010_01000000, 26); + data.Add(220, 0b11111111_11111111_11111111_11010000, 28); + data.Add(221, 0b11111111_11111111_11111100_01100000, 27); + data.Add(222, 0b11111111_11111111_11111100_10000000, 27); + data.Add(223, 0b11111111_11111111_11111100_10100000, 27); + data.Add(224, 0b11111111_11111110_11000000_00000000, 20); + data.Add(225, 0b11111111_11111111_11110011_00000000, 24); + data.Add(226, 0b11111111_11111110_11010000_00000000, 20); + data.Add(227, 0b11111111_11111111_00110000_00000000, 21); + data.Add(228, 0b11111111_11111111_10100100_00000000, 22); + data.Add(229, 0b11111111_11111111_00111000_00000000, 21); + data.Add(230, 0b11111111_11111111_01000000_00000000, 21); + data.Add(231, 0b11111111_11111111_11100110_00000000, 23); + data.Add(232, 0b11111111_11111111_10101000_00000000, 22); + data.Add(233, 0b11111111_11111111_10101100_00000000, 22); + data.Add(234, 0b11111111_11111111_11110111_00000000, 25); + data.Add(235, 0b11111111_11111111_11110111_10000000, 25); + data.Add(236, 0b11111111_11111111_11110100_00000000, 24); + data.Add(237, 0b11111111_11111111_11110101_00000000, 24); + data.Add(238, 0b11111111_11111111_11111010_10000000, 26); + data.Add(239, 0b11111111_11111111_11101000_00000000, 23); + data.Add(240, 0b11111111_11111111_11111010_11000000, 26); + data.Add(241, 0b11111111_11111111_11111100_11000000, 27); + data.Add(242, 0b11111111_11111111_11111011_00000000, 26); + data.Add(243, 0b11111111_11111111_11111011_01000000, 26); + data.Add(244, 0b11111111_11111111_11111100_11100000, 27); + data.Add(245, 0b11111111_11111111_11111101_00000000, 27); + data.Add(246, 0b11111111_11111111_11111101_00100000, 27); + data.Add(247, 0b11111111_11111111_11111101_01000000, 27); + data.Add(248, 0b11111111_11111111_11111101_01100000, 27); + data.Add(249, 0b11111111_11111111_11111111_11100000, 28); + data.Add(250, 0b11111111_11111111_11111101_10000000, 27); + data.Add(251, 0b11111111_11111111_11111101_10100000, 27); + data.Add(252, 0b11111111_11111111_11111101_11000000, 27); + data.Add(253, 0b11111111_11111111_11111101_11100000, 27); + data.Add(254, 0b11111111_11111111_11111110_00000000, 27); + data.Add(255, 0b11111111_11111111_11111011_10000000, 26); + data.Add(256, 0b11111111_11111111_11111111_11111100, 30); + + return data; + } + } + } +} diff --git a/test/Kestrel.Core.Tests/IntegerDecoderTests.cs b/test/Kestrel.Core.Tests/IntegerDecoderTests.cs new file mode 100644 index 0000000000..c9e259b0ff --- /dev/null +++ b/test/Kestrel.Core.Tests/IntegerDecoderTests.cs @@ -0,0 +1,52 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2.HPack; +using Xunit; + +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests +{ + public class IntegerDecoderTests + { + [Theory] + [MemberData(nameof(IntegerData))] + public void IntegerDecode(int i, int prefixLength, byte[] octets) + { + var decoder = new IntegerDecoder(); + var result = decoder.BeginDecode(octets[0], prefixLength); + + if (octets.Length == 1) + { + Assert.True(result); + } + else + { + var j = 1; + + for (; j < octets.Length - 1; j++) + { + Assert.False(decoder.Decode(octets[j])); + } + + Assert.True(decoder.Decode(octets[j])); + } + + Assert.Equal(i, decoder.Value); + } + + public static TheoryData IntegerData + { + get + { + var data = new TheoryData(); + + data.Add(10, 5, new byte[] { 10 }); + data.Add(1337, 5, new byte[] { 0x1f, 0x9a, 0x0a }); + data.Add(42, 8, new byte[] { 42 }); + + return data; + } + } + } +} diff --git a/test/Kestrel.Core.Tests/IntegerEncoderTests.cs b/test/Kestrel.Core.Tests/IntegerEncoderTests.cs new file mode 100644 index 0000000000..2c4811c81c --- /dev/null +++ b/test/Kestrel.Core.Tests/IntegerEncoderTests.cs @@ -0,0 +1,37 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2.HPack; +using Xunit; + +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests +{ + public class IntegerEncoderTests + { + [Theory] + [MemberData(nameof(IntegerData))] + public void IntegerEncode(int i, int prefixLength, byte[] expectedOctets) + { + var buffer = new byte[expectedOctets.Length]; + + Assert.True(IntegerEncoder.Encode(i, prefixLength, buffer, out var octets)); + Assert.Equal(expectedOctets.Length, octets); + Assert.Equal(expectedOctets, buffer); + } + + public static TheoryData IntegerData + { + get + { + var data = new TheoryData(); + + data.Add(10, 5, new byte[] { 10 }); + data.Add(1337, 5, new byte[] { 0x1f, 0x9a, 0x0a }); + data.Add(42, 8, new byte[] { 42 }); + + return data; + } + } + } +} diff --git a/test/Kestrel.FunctionalTests/GeneratedCodeTests.cs b/test/Kestrel.FunctionalTests/GeneratedCodeTests.cs index 5a6b03781c..548a028a8a 100644 --- a/test/Kestrel.FunctionalTests/GeneratedCodeTests.cs +++ b/test/Kestrel.FunctionalTests/GeneratedCodeTests.cs @@ -14,26 +14,31 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { const string frameHeadersGeneratedPath = "../../../../../src/Kestrel.Core/Internal/Http/FrameHeaders.Generated.cs"; const string frameGeneratedPath = "../../../../../src/Kestrel.Core/Internal/Http/Frame.Generated.cs"; + const string http2StreamGeneratedPath = "../../../../../src/Kestrel.Core/Internal/Http2/Http2Stream.Generated.cs"; const string httpUtilitiesGeneratedPath = "../../../../../src/Kestrel.Core/Internal/Infrastructure/HttpUtilities.Generated.cs"; var testFrameHeadersGeneratedPath = Path.GetTempFileName(); var testFrameGeneratedPath = Path.GetTempFileName(); + var testHttp2StreamGeneratedPath = Path.GetTempFileName(); var testHttpUtilitiesGeneratedPath = Path.GetTempFileName(); try { var currentFrameHeadersGenerated = File.ReadAllText(frameHeadersGeneratedPath); var currentFrameGenerated = File.ReadAllText(frameGeneratedPath); + var currentHttp2StreamGenerated = File.ReadAllText(http2StreamGeneratedPath); var currentHttpUtilitiesGenerated = File.ReadAllText(httpUtilitiesGeneratedPath); - CodeGenerator.Program.Run(testFrameHeadersGeneratedPath, testFrameGeneratedPath, testHttpUtilitiesGeneratedPath); + CodeGenerator.Program.Run(testFrameHeadersGeneratedPath, testFrameGeneratedPath, testHttp2StreamGeneratedPath, testHttpUtilitiesGeneratedPath); var testFrameHeadersGenerated = File.ReadAllText(testFrameHeadersGeneratedPath); var testFrameGenerated = File.ReadAllText(testFrameGeneratedPath); + var testHttp2StreamGenerated = File.ReadAllText(testHttp2StreamGeneratedPath); var testHttpUtilitiesGenerated = File.ReadAllText(testHttpUtilitiesGeneratedPath); Assert.Equal(currentFrameHeadersGenerated, testFrameHeadersGenerated, ignoreLineEndingDifferences: true); Assert.Equal(currentFrameGenerated, testFrameGenerated, ignoreLineEndingDifferences: true); + Assert.Equal(currentHttp2StreamGenerated, testHttp2StreamGenerated, ignoreLineEndingDifferences: true); Assert.Equal(currentHttpUtilitiesGenerated, testHttpUtilitiesGenerated, ignoreLineEndingDifferences: true); } @@ -41,6 +46,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { File.Delete(testFrameHeadersGeneratedPath); File.Delete(testFrameGeneratedPath); + File.Delete(testHttp2StreamGeneratedPath); File.Delete(testHttpUtilitiesGeneratedPath); } } diff --git a/tools/CodeGenerator/CodeGenerator.csproj b/tools/CodeGenerator/CodeGenerator.csproj index 143a966654..91cec270ff 100644 --- a/tools/CodeGenerator/CodeGenerator.csproj +++ b/tools/CodeGenerator/CodeGenerator.csproj @@ -20,7 +20,7 @@ $(MSBuildThisFileDirectory)..\..\src\Kestrel.Core - Internal\Http\FrameHeaders.Generated.cs Internal\Http\Frame.Generated.cs Internal\Infrastructure\HttpUtilities.Generated.cs + Internal/Http/FrameHeaders.Generated.cs Internal/Http/Frame.Generated.cs Internal/Http2/Http2Stream.Generated.cs Internal/Infrastructure/HttpUtilities.Generated.cs diff --git a/tools/CodeGenerator/FrameFeatureCollection.cs b/tools/CodeGenerator/FrameFeatureCollection.cs index d05139d919..b32dacbb72 100644 --- a/tools/CodeGenerator/FrameFeatureCollection.cs +++ b/tools/CodeGenerator/FrameFeatureCollection.cs @@ -19,8 +19,10 @@ namespace CodeGenerator return values.Select(formatter).Aggregate((a, b) => a + b); } - public static string GeneratedFile() + public static string GeneratedFile(string className, string namespaceSuffix, IEnumerable additionalFeatures = null) { + additionalFeatures = additionalFeatures ?? new Type[] { }; + var alwaysFeatures = new[] { typeof(IHttpRequestFeature), @@ -57,7 +59,7 @@ namespace CodeGenerator typeof(IHttpSendFileFeature), }; - var allFeatures = alwaysFeatures.Concat(commonFeatures).Concat(sometimesFeatures).Concat(rareFeatures); + var allFeatures = alwaysFeatures.Concat(commonFeatures).Concat(sometimesFeatures).Concat(rareFeatures).Concat(additionalFeatures); // NOTE: This list MUST always match the set of feature interfaces implemented by Frame. // See also: src/Kestrel/Http/Frame.FeatureCollection.cs @@ -73,7 +75,7 @@ namespace CodeGenerator typeof(IHttpMinRequestBodyDataRateFeature), typeof(IHttpMinResponseDataRateFeature), typeof(IHttpBodyControlFeature), - }; + }.Concat(additionalFeatures); return $@"// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. @@ -81,9 +83,9 @@ namespace CodeGenerator using System; using System.Collections.Generic; -namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.{namespaceSuffix} {{ - public partial class Frame + public partial class {className} {{{Each(allFeatures, feature => $@" private static readonly Type {feature.Name}Type = typeof(global::{feature.FullName});")} {Each(allFeatures, feature => $@" diff --git a/tools/CodeGenerator/Program.cs b/tools/CodeGenerator/Program.cs index 24be8360b9..59c190a2be 100644 --- a/tools/CodeGenerator/Program.cs +++ b/tools/CodeGenerator/Program.cs @@ -3,6 +3,9 @@ using System; using System.IO; +using Microsoft.AspNetCore.Server.Kestrel.Core.Features; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2; namespace CodeGenerator { @@ -26,15 +29,16 @@ namespace CodeGenerator return 1; } - Run(args[0], args[1], args[2]); + Run(args[0], args[1], args[2], args[3]); return 0; } - public static void Run(string knownHeadersPath, string frameFeaturesCollectionPath, string httpUtilitiesPath) + public static void Run(string knownHeadersPath, string frameFeatureCollectionPath, string http2StreamFeatureCollectionPath, string httpUtilitiesPath) { var knownHeadersContent = KnownHeaders.GeneratedFile(); - var frameFeatureCollectionContent = FrameFeatureCollection.GeneratedFile(); + var frameFeatureCollectionContent = FrameFeatureCollection.GeneratedFile(nameof(Frame), "Http"); + var http2StreamFeatureCollectionContent = FrameFeatureCollection.GeneratedFile(nameof(Http2Stream), "Http2", new[] { typeof(IHttp2StreamIdFeature) }); var httpUtilitiesContent = HttpUtilities.HttpUtilities.GeneratedFile(); var existingKnownHeaders = File.Exists(knownHeadersPath) ? File.ReadAllText(knownHeadersPath) : ""; @@ -43,10 +47,16 @@ namespace CodeGenerator File.WriteAllText(knownHeadersPath, knownHeadersContent); } - var existingFrameFeatureCollection = File.Exists(frameFeaturesCollectionPath) ? File.ReadAllText(frameFeaturesCollectionPath) : ""; + var existingFrameFeatureCollection = File.Exists(frameFeatureCollectionPath) ? File.ReadAllText(frameFeatureCollectionPath) : ""; if (!string.Equals(frameFeatureCollectionContent, existingFrameFeatureCollection)) { - File.WriteAllText(frameFeaturesCollectionPath, frameFeatureCollectionContent); + File.WriteAllText(frameFeatureCollectionPath, frameFeatureCollectionContent); + } + + var existingHttp2StreamFeatureCollection = File.Exists(http2StreamFeatureCollectionPath) ? File.ReadAllText(http2StreamFeatureCollectionPath) : ""; + if (!string.Equals(http2StreamFeatureCollectionContent, existingHttp2StreamFeatureCollection)) + { + File.WriteAllText(http2StreamFeatureCollectionPath, http2StreamFeatureCollectionContent); } var existingHttpUtilities = File.Exists(httpUtilitiesPath) ? File.ReadAllText(httpUtilitiesPath) : ""; From 26f1d4baa3a2f98edbf1d6f5996cf07dfc0693cc Mon Sep 17 00:00:00 2001 From: Nate McMaster Date: Wed, 16 Aug 2017 13:03:34 -0700 Subject: [PATCH 1377/1662] Use PackageLineup PackageLineup is a way to manage PackageReference versions across large projects. It removes the version information from the repository and instead pulls the information from an external "lineup" file. --- appveyor.yml => .appveyor.yml | 0 CONTRIBUTING.md | 2 +- build/common.props => Directory.Build.props | 19 ++++--- Directory.Build.targets | 14 +++++ KestrelHttpServer.sln | 55 ++++++++++++++----- NuGet.config | 1 - README.md | 9 +++ .../DotSegmentRemovalBenchmark.cs | 0 .../Kestrel.Performance/ErrorUtilities.cs | 0 .../FrameFeatureCollection.cs | 0 .../FrameParsingOverheadBenchmark.cs | 0 .../FrameWritingBenchmark.cs | 0 .../Kestrel.Performance.csproj | 10 ++-- .../KestrelHttpParserBenchmark.cs | 0 .../KnownStringsBenchmark.cs | 0 .../Mocks/MockTimeoutControl.cs | 0 .../Kestrel.Performance/Mocks/MockTrace.cs | 0 .../Kestrel.Performance/Mocks/NullParser.cs | 0 .../PipeThroughputBenchmark.cs | 0 .../Kestrel.Performance/Program.cs | 0 .../Kestrel.Performance/README.md | 2 +- .../RequestParsingBenchmark.cs | 0 .../Kestrel.Performance/RequestParsingData.cs | 0 .../ResponseHeaderCollectionBenchmark.cs | 0 .../ResponseHeadersWritingBenchmark.cs | 0 .../StringUtilitiesBenchmark.cs | 0 .../Kestrel.Performance/configs/CoreConfig.cs | 0 build/dependencies.props | 16 ------ build/repo.props | 3 +- .../LargeResponseApp/LargeResponseApp.csproj | 6 -- samples/SampleApp/SampleApp.csproj | 5 +- src/Directory.Build.props | 7 +++ src/Kestrel.Core/Kestrel.Core.csproj | 20 +++---- src/Kestrel.Https/Kestrel.Https.csproj | 6 +- src/Kestrel.Tls/Kestrel.Tls.csproj | 6 +- .../Kestrel.Transport.Abstractions.csproj | 2 - .../Kestrel.Transport.Libuv.csproj | 10 ++-- .../Kestrel.Transport.Sockets.csproj | 8 +-- src/Kestrel/Kestrel.csproj | 4 +- .../Protocols.Abstractions.csproj | 19 +++---- test/Directory.Build.props | 24 ++++++++ test/Kestrel.Core.Tests/HuffmanTests.cs | 9 ++- .../Kestrel.Core.Tests.csproj | 19 +------ .../AddressRegistrationTests.cs | 6 +- .../Kestrel.FunctionalTests.csproj | 21 ++----- .../Kestrel.FunctionalTests/xunit.runner.json | 5 -- test/Kestrel.Tests/Kestrel.Tests.csproj | 12 ---- test/Kestrel.Tests/xunit.runner.json | 5 -- .../Kestrel.Transport.Libuv.Tests.csproj | 19 +------ .../xunit.runner.json | 6 -- .../xunit.runner.json | 0 tools/CodeGenerator/CodeGenerator.csproj | 6 +- 52 files changed, 164 insertions(+), 192 deletions(-) rename appveyor.yml => .appveyor.yml (100%) rename build/common.props => Directory.Build.props (51%) create mode 100644 Directory.Build.targets rename {test => benchmarks}/Kestrel.Performance/DotSegmentRemovalBenchmark.cs (100%) rename {test => benchmarks}/Kestrel.Performance/ErrorUtilities.cs (100%) rename {test => benchmarks}/Kestrel.Performance/FrameFeatureCollection.cs (100%) rename {test => benchmarks}/Kestrel.Performance/FrameParsingOverheadBenchmark.cs (100%) rename {test => benchmarks}/Kestrel.Performance/FrameWritingBenchmark.cs (100%) rename {test => benchmarks}/Kestrel.Performance/Kestrel.Performance.csproj (71%) rename {test => benchmarks}/Kestrel.Performance/KestrelHttpParserBenchmark.cs (100%) rename {test => benchmarks}/Kestrel.Performance/KnownStringsBenchmark.cs (100%) rename {test => benchmarks}/Kestrel.Performance/Mocks/MockTimeoutControl.cs (100%) rename {test => benchmarks}/Kestrel.Performance/Mocks/MockTrace.cs (100%) rename {test => benchmarks}/Kestrel.Performance/Mocks/NullParser.cs (100%) rename {test => benchmarks}/Kestrel.Performance/PipeThroughputBenchmark.cs (100%) rename {test => benchmarks}/Kestrel.Performance/Program.cs (100%) rename test/Kestrel.Performance/Readme.md => benchmarks/Kestrel.Performance/README.md (81%) rename {test => benchmarks}/Kestrel.Performance/RequestParsingBenchmark.cs (100%) rename {test => benchmarks}/Kestrel.Performance/RequestParsingData.cs (100%) rename {test => benchmarks}/Kestrel.Performance/ResponseHeaderCollectionBenchmark.cs (100%) rename {test => benchmarks}/Kestrel.Performance/ResponseHeadersWritingBenchmark.cs (100%) rename {test => benchmarks}/Kestrel.Performance/StringUtilitiesBenchmark.cs (100%) rename {test => benchmarks}/Kestrel.Performance/configs/CoreConfig.cs (100%) delete mode 100644 build/dependencies.props create mode 100644 src/Directory.Build.props create mode 100644 test/Directory.Build.props delete mode 100644 test/Kestrel.FunctionalTests/xunit.runner.json delete mode 100644 test/Kestrel.Tests/xunit.runner.json delete mode 100644 test/Kestrel.Transport.Libuv.Tests/xunit.runner.json rename test/{Kestrel.Core.Tests => }/xunit.runner.json (100%) diff --git a/appveyor.yml b/.appveyor.yml similarity index 100% rename from appveyor.yml rename to .appveyor.yml diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 64ff041d5c..952d5b87f3 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,4 +1,4 @@ Contributing -====== +============ Information on contributing to this repo is in the [Contributing Guide](https://github.com/aspnet/Home/blob/dev/CONTRIBUTING.md) in the Home repo. diff --git a/build/common.props b/Directory.Build.props similarity index 51% rename from build/common.props rename to Directory.Build.props index 593929425b..d491401790 100644 --- a/build/common.props +++ b/Directory.Build.props @@ -1,22 +1,27 @@ - - + Microsoft ASP.NET Core https://github.com/aspnet/KestrelHttpServer git - $(MSBuildThisFileDirectory)Key.snk + $(MSBuildThisFileDirectory)build\Key.snk true true $(VersionSuffix)-$(BuildNumber) true - 7.2 + latest - - - + + + KRB4002 + + diff --git a/Directory.Build.targets b/Directory.Build.targets new file mode 100644 index 0000000000..9989b1046b --- /dev/null +++ b/Directory.Build.targets @@ -0,0 +1,14 @@ + + + + <_BootstrapperFile Condition=" $([MSBuild]::IsOSUnixLike()) ">build.sh + <_BootstrapperFile Condition="! $([MSBuild]::IsOSUnixLike()) ">build.cmd + <_BootstrapperError> + Package references have not been pinned. Run './$(_BootstrapperFile) /t:Pin'. + Also, you can run './$(_BootstrapperFile) /t:Restore' which will pin *and* restore packages. '$(_BootstrapperFile)' can be found in '$(MSBuildThisFileDirectory)'. + + + + + + diff --git a/KestrelHttpServer.sln b/KestrelHttpServer.sln index 44ad81ebae..31cb00a5f7 100644 --- a/KestrelHttpServer.sln +++ b/KestrelHttpServer.sln @@ -1,17 +1,37 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 15 -VisualStudioVersion = 15.0.26730.0 +VisualStudioVersion = 15.0.26814.0 MinimumVisualStudioVersion = 10.0.40219.1 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{7972A5D6-3385-4127-9277-428506DD44FF}" ProjectSection(SolutionItems) = preProject + .appveyor.yml = .appveyor.yml + .gitattributes = .gitattributes + .gitignore = .gitignore + .travis.yml = .travis.yml build.cmd = build.cmd - makefile.shade = makefile.shade + build.ps1 = build.ps1 + build.sh = build.sh + CONTRIBUTING.md = CONTRIBUTING.md + Directory.Build.props = Directory.Build.props + Directory.Build.targets = Directory.Build.targets + LICENSE.txt = LICENSE.txt NuGet.Config = NuGet.Config + NuGetPackageVerifier.json = NuGetPackageVerifier.json + README.md = README.md + ToProjectReferences.ps1 = ToProjectReferences.ps1 + version.xml = version.xml EndProjectSection EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{2D5D5227-4DBD-499A-96B1-76A36B03B750}" + ProjectSection(SolutionItems) = preProject + src\Directory.Build.props = src\Directory.Build.props + EndProjectSection EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{D3273454-EA07-41D2-BF0B-FCC3675C2483}" + ProjectSection(SolutionItems) = preProject + test\Directory.Build.props = test\Directory.Build.props + test\xunit.runner.json = test\xunit.runner.json + EndProjectSection EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "samples", "samples", "{8A3D00B8-1CCF-4BE6-A060-11104CE2D9CE}" EndProject @@ -50,7 +70,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Kestrel.Https", "src\Kestre EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Kestrel.FunctionalTests", "test\Kestrel.FunctionalTests\Kestrel.FunctionalTests.csproj", "{9559A5F1-080C-4909-B6CF-7E4B3DC55748}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Kestrel.Performance", "test\Kestrel.Performance\Kestrel.Performance.csproj", "{EBFE9719-A44B-4978-A71F-D5C254E7F35A}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Kestrel.Performance", "benchmarks\Kestrel.Performance\Kestrel.Performance.csproj", "{EBFE9719-A44B-4978-A71F-D5C254E7F35A}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "TestCertificates", "TestCertificates", "{2822C132-BFFB-4D53-AC5B-E7E47DD81A6E}" ProjectSection(SolutionItems) = preProject @@ -80,9 +100,17 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Kestrel.Transport.Libuv.Tes EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Kestrel.Tests", "test\Kestrel.Tests\Kestrel.Tests.csproj", "{4F1C30F8-CCAA-48D7-9DF6-2A84021F5BCC}" EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "benchmarks", "benchmarks", "{A95C3BE1-B850-4265-97A0-777ADCCD437F}" +EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Protocols.Abstractions", "src\Protocols.Abstractions\Protocols.Abstractions.csproj", "{6956CF5C-3163-4398-8628-4ECA569245B5}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Kestrel.Tls", "src\Kestrel.Tls\Kestrel.Tls.csproj", "{924AE57C-1EBA-4A1D-A039-8C100B7507A5}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Kestrel.Tls", "src\Kestrel.Tls\Kestrel.Tls.csproj", "{924AE57C-1EBA-4A1D-A039-8C100B7507A5}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "build", "build", "{C2910A13-B2C2-46D8-81D8-7E166F4F5981}" + ProjectSection(SolutionItems) = preProject + build\repo.props = build\repo.props + build\repo.targets = build\repo.targets + EndProjectSection EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -276,16 +304,16 @@ Global {6956CF5C-3163-4398-8628-4ECA569245B5}.Release|x86.Build.0 = Release|Any CPU {924AE57C-1EBA-4A1D-A039-8C100B7507A5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {924AE57C-1EBA-4A1D-A039-8C100B7507A5}.Debug|Any CPU.Build.0 = Debug|Any CPU - {924AE57C-1EBA-4A1D-A039-8C100B7507A5}.Debug|x64.ActiveCfg = Debug|x64 - {924AE57C-1EBA-4A1D-A039-8C100B7507A5}.Debug|x64.Build.0 = Debug|x64 - {924AE57C-1EBA-4A1D-A039-8C100B7507A5}.Debug|x86.ActiveCfg = Debug|x86 - {924AE57C-1EBA-4A1D-A039-8C100B7507A5}.Debug|x86.Build.0 = Debug|x86 + {924AE57C-1EBA-4A1D-A039-8C100B7507A5}.Debug|x64.ActiveCfg = Debug|Any CPU + {924AE57C-1EBA-4A1D-A039-8C100B7507A5}.Debug|x64.Build.0 = Debug|Any CPU + {924AE57C-1EBA-4A1D-A039-8C100B7507A5}.Debug|x86.ActiveCfg = Debug|Any CPU + {924AE57C-1EBA-4A1D-A039-8C100B7507A5}.Debug|x86.Build.0 = Debug|Any CPU {924AE57C-1EBA-4A1D-A039-8C100B7507A5}.Release|Any CPU.ActiveCfg = Release|Any CPU {924AE57C-1EBA-4A1D-A039-8C100B7507A5}.Release|Any CPU.Build.0 = Release|Any CPU - {924AE57C-1EBA-4A1D-A039-8C100B7507A5}.Release|x64.ActiveCfg = Release|x64 - {924AE57C-1EBA-4A1D-A039-8C100B7507A5}.Release|x64.Build.0 = Release|x64 - {924AE57C-1EBA-4A1D-A039-8C100B7507A5}.Release|x86.ActiveCfg = Release|x86 - {924AE57C-1EBA-4A1D-A039-8C100B7507A5}.Release|x86.Build.0 = Release|x86 + {924AE57C-1EBA-4A1D-A039-8C100B7507A5}.Release|x64.ActiveCfg = Release|Any CPU + {924AE57C-1EBA-4A1D-A039-8C100B7507A5}.Release|x64.Build.0 = Release|Any CPU + {924AE57C-1EBA-4A1D-A039-8C100B7507A5}.Release|x86.ActiveCfg = Release|Any CPU + {924AE57C-1EBA-4A1D-A039-8C100B7507A5}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -298,7 +326,8 @@ Global {BD2D4D29-1BD9-40D0-BB31-337D5416B63C} = {327F7880-D9AF-46BD-B45C-3B7E34A01DFD} {5F64B3C3-0C2E-431A-B820-A81BBFC863DA} = {2D5D5227-4DBD-499A-96B1-76A36B03B750} {9559A5F1-080C-4909-B6CF-7E4B3DC55748} = {D3273454-EA07-41D2-BF0B-FCC3675C2483} - {EBFE9719-A44B-4978-A71F-D5C254E7F35A} = {D3273454-EA07-41D2-BF0B-FCC3675C2483} + {EBFE9719-A44B-4978-A71F-D5C254E7F35A} = {A95C3BE1-B850-4265-97A0-777ADCCD437F} + {2822C132-BFFB-4D53-AC5B-E7E47DD81A6E} = {0EF2ACDF-012F-4472-A13A-4272419E2903} {A76B8C8C-0DC5-4DD3-9B1F-02E51A0915F4} = {2D5D5227-4DBD-499A-96B1-76A36B03B750} {56139957-5C29-4E7D-89BD-7D20598B4EAF} = {2D5D5227-4DBD-499A-96B1-76A36B03B750} {6950B18F-A3D2-41A4-AFEC-8B7C49517611} = {2D5D5227-4DBD-499A-96B1-76A36B03B750} diff --git a/NuGet.config b/NuGet.config index 2dfd335477..c88189696c 100644 --- a/NuGet.config +++ b/NuGet.config @@ -3,7 +3,6 @@ - diff --git a/README.md b/README.md index 383bb63208..448d756847 100644 --- a/README.md +++ b/README.md @@ -10,3 +10,12 @@ Travis: [![Travis](https://travis-ci.org/aspnet/KestrelHttpServer.svg?branch=dev This repo contains a cross-platform web server for ASP.NET Core. This project is part of ASP.NET Core. You can find samples, documentation and getting started instructions for ASP.NET Core at the [Home](https://github.com/aspnet/home) repo. + +## Building from source + +To run a complete build on command line only, execute `build.cmd` or `build.sh` without arguments. + +Before opening this project in Visual Studio or VS Code, execute `build.cmd /t:Restore` (Windows) or `./build.sh /t:Restore` (Linux/macOS). +This will execute only the part of the build script that downloads and initializes a few required build tools and packages. + +See [developer documentation](https://github.com/aspnet/Home/wiki) for more details. diff --git a/test/Kestrel.Performance/DotSegmentRemovalBenchmark.cs b/benchmarks/Kestrel.Performance/DotSegmentRemovalBenchmark.cs similarity index 100% rename from test/Kestrel.Performance/DotSegmentRemovalBenchmark.cs rename to benchmarks/Kestrel.Performance/DotSegmentRemovalBenchmark.cs diff --git a/test/Kestrel.Performance/ErrorUtilities.cs b/benchmarks/Kestrel.Performance/ErrorUtilities.cs similarity index 100% rename from test/Kestrel.Performance/ErrorUtilities.cs rename to benchmarks/Kestrel.Performance/ErrorUtilities.cs diff --git a/test/Kestrel.Performance/FrameFeatureCollection.cs b/benchmarks/Kestrel.Performance/FrameFeatureCollection.cs similarity index 100% rename from test/Kestrel.Performance/FrameFeatureCollection.cs rename to benchmarks/Kestrel.Performance/FrameFeatureCollection.cs diff --git a/test/Kestrel.Performance/FrameParsingOverheadBenchmark.cs b/benchmarks/Kestrel.Performance/FrameParsingOverheadBenchmark.cs similarity index 100% rename from test/Kestrel.Performance/FrameParsingOverheadBenchmark.cs rename to benchmarks/Kestrel.Performance/FrameParsingOverheadBenchmark.cs diff --git a/test/Kestrel.Performance/FrameWritingBenchmark.cs b/benchmarks/Kestrel.Performance/FrameWritingBenchmark.cs similarity index 100% rename from test/Kestrel.Performance/FrameWritingBenchmark.cs rename to benchmarks/Kestrel.Performance/FrameWritingBenchmark.cs diff --git a/test/Kestrel.Performance/Kestrel.Performance.csproj b/benchmarks/Kestrel.Performance/Kestrel.Performance.csproj similarity index 71% rename from test/Kestrel.Performance/Kestrel.Performance.csproj rename to benchmarks/Kestrel.Performance/Kestrel.Performance.csproj index 2508e6c7f2..3a982816ef 100644 --- a/test/Kestrel.Performance/Kestrel.Performance.csproj +++ b/benchmarks/Kestrel.Performance/Kestrel.Performance.csproj @@ -1,7 +1,5 @@  - - Microsoft.AspNetCore.Server.Kestrel.Performance Microsoft.AspNetCore.Server.Kestrel.Performance @@ -14,9 +12,9 @@ - - - + + + @@ -24,7 +22,7 @@ - + diff --git a/test/Kestrel.Performance/KestrelHttpParserBenchmark.cs b/benchmarks/Kestrel.Performance/KestrelHttpParserBenchmark.cs similarity index 100% rename from test/Kestrel.Performance/KestrelHttpParserBenchmark.cs rename to benchmarks/Kestrel.Performance/KestrelHttpParserBenchmark.cs diff --git a/test/Kestrel.Performance/KnownStringsBenchmark.cs b/benchmarks/Kestrel.Performance/KnownStringsBenchmark.cs similarity index 100% rename from test/Kestrel.Performance/KnownStringsBenchmark.cs rename to benchmarks/Kestrel.Performance/KnownStringsBenchmark.cs diff --git a/test/Kestrel.Performance/Mocks/MockTimeoutControl.cs b/benchmarks/Kestrel.Performance/Mocks/MockTimeoutControl.cs similarity index 100% rename from test/Kestrel.Performance/Mocks/MockTimeoutControl.cs rename to benchmarks/Kestrel.Performance/Mocks/MockTimeoutControl.cs diff --git a/test/Kestrel.Performance/Mocks/MockTrace.cs b/benchmarks/Kestrel.Performance/Mocks/MockTrace.cs similarity index 100% rename from test/Kestrel.Performance/Mocks/MockTrace.cs rename to benchmarks/Kestrel.Performance/Mocks/MockTrace.cs diff --git a/test/Kestrel.Performance/Mocks/NullParser.cs b/benchmarks/Kestrel.Performance/Mocks/NullParser.cs similarity index 100% rename from test/Kestrel.Performance/Mocks/NullParser.cs rename to benchmarks/Kestrel.Performance/Mocks/NullParser.cs diff --git a/test/Kestrel.Performance/PipeThroughputBenchmark.cs b/benchmarks/Kestrel.Performance/PipeThroughputBenchmark.cs similarity index 100% rename from test/Kestrel.Performance/PipeThroughputBenchmark.cs rename to benchmarks/Kestrel.Performance/PipeThroughputBenchmark.cs diff --git a/test/Kestrel.Performance/Program.cs b/benchmarks/Kestrel.Performance/Program.cs similarity index 100% rename from test/Kestrel.Performance/Program.cs rename to benchmarks/Kestrel.Performance/Program.cs diff --git a/test/Kestrel.Performance/Readme.md b/benchmarks/Kestrel.Performance/README.md similarity index 81% rename from test/Kestrel.Performance/Readme.md rename to benchmarks/Kestrel.Performance/README.md index 4088c38007..63db0c3d7e 100644 --- a/test/Kestrel.Performance/Readme.md +++ b/benchmarks/Kestrel.Performance/README.md @@ -8,4 +8,4 @@ To run all use `All` as parameter ``` dotnet run -c Release All ``` -Using no parameter will list all available benchmarks \ No newline at end of file +Using no parameter will list all available benchmarks diff --git a/test/Kestrel.Performance/RequestParsingBenchmark.cs b/benchmarks/Kestrel.Performance/RequestParsingBenchmark.cs similarity index 100% rename from test/Kestrel.Performance/RequestParsingBenchmark.cs rename to benchmarks/Kestrel.Performance/RequestParsingBenchmark.cs diff --git a/test/Kestrel.Performance/RequestParsingData.cs b/benchmarks/Kestrel.Performance/RequestParsingData.cs similarity index 100% rename from test/Kestrel.Performance/RequestParsingData.cs rename to benchmarks/Kestrel.Performance/RequestParsingData.cs diff --git a/test/Kestrel.Performance/ResponseHeaderCollectionBenchmark.cs b/benchmarks/Kestrel.Performance/ResponseHeaderCollectionBenchmark.cs similarity index 100% rename from test/Kestrel.Performance/ResponseHeaderCollectionBenchmark.cs rename to benchmarks/Kestrel.Performance/ResponseHeaderCollectionBenchmark.cs diff --git a/test/Kestrel.Performance/ResponseHeadersWritingBenchmark.cs b/benchmarks/Kestrel.Performance/ResponseHeadersWritingBenchmark.cs similarity index 100% rename from test/Kestrel.Performance/ResponseHeadersWritingBenchmark.cs rename to benchmarks/Kestrel.Performance/ResponseHeadersWritingBenchmark.cs diff --git a/test/Kestrel.Performance/StringUtilitiesBenchmark.cs b/benchmarks/Kestrel.Performance/StringUtilitiesBenchmark.cs similarity index 100% rename from test/Kestrel.Performance/StringUtilitiesBenchmark.cs rename to benchmarks/Kestrel.Performance/StringUtilitiesBenchmark.cs diff --git a/test/Kestrel.Performance/configs/CoreConfig.cs b/benchmarks/Kestrel.Performance/configs/CoreConfig.cs similarity index 100% rename from test/Kestrel.Performance/configs/CoreConfig.cs rename to benchmarks/Kestrel.Performance/configs/CoreConfig.cs diff --git a/build/dependencies.props b/build/dependencies.props deleted file mode 100644 index c32a5f7a7c..0000000000 --- a/build/dependencies.props +++ /dev/null @@ -1,16 +0,0 @@ - - - 2.1.0-* - 4.4.0-* - 0.1.0-* - 2.1.1-* - 1.10.0 - 10.0.1 - 4.7.49 - 2.0.0-* - 2.0.0-* - 2.6.0-rdonly-ref-61915-01 - 15.3.0 - 2.3.0-beta3-build3705 - - diff --git a/build/repo.props b/build/repo.props index c1b53db759..c5d91e8a2c 100644 --- a/build/repo.props +++ b/build/repo.props @@ -1,5 +1,6 @@ - + + diff --git a/samples/LargeResponseApp/LargeResponseApp.csproj b/samples/LargeResponseApp/LargeResponseApp.csproj index d147ace444..247595b135 100644 --- a/samples/LargeResponseApp/LargeResponseApp.csproj +++ b/samples/LargeResponseApp/LargeResponseApp.csproj @@ -1,7 +1,5 @@  - - netcoreapp2.0;net461 false @@ -11,8 +9,4 @@ - - - - diff --git a/samples/SampleApp/SampleApp.csproj b/samples/SampleApp/SampleApp.csproj index 9d017fa070..5dd0ddf608 100644 --- a/samples/SampleApp/SampleApp.csproj +++ b/samples/SampleApp/SampleApp.csproj @@ -1,7 +1,5 @@  - - netcoreapp2.0;net461 false @@ -17,8 +15,7 @@ - - + diff --git a/src/Directory.Build.props b/src/Directory.Build.props new file mode 100644 index 0000000000..5236edee58 --- /dev/null +++ b/src/Directory.Build.props @@ -0,0 +1,7 @@ + + + + + + + diff --git a/src/Kestrel.Core/Kestrel.Core.csproj b/src/Kestrel.Core/Kestrel.Core.csproj index 14304428dc..fa14ffb523 100644 --- a/src/Kestrel.Core/Kestrel.Core.csproj +++ b/src/Kestrel.Core/Kestrel.Core.csproj @@ -1,7 +1,5 @@  - - Microsoft.AspNetCore.Server.Kestrel.Core Microsoft.AspNetCore.Server.Kestrel.Core @@ -12,21 +10,19 @@ true CS1591;$(NoWarn) false - - CurrentRuntime - - - - - - + + + + + + - - + + diff --git a/src/Kestrel.Https/Kestrel.Https.csproj b/src/Kestrel.Https/Kestrel.Https.csproj index ac3ae037a5..284c7f6fb3 100644 --- a/src/Kestrel.Https/Kestrel.Https.csproj +++ b/src/Kestrel.Https/Kestrel.Https.csproj @@ -1,7 +1,5 @@  - - Microsoft.AspNetCore.Server.Kestrel.Https Microsoft.AspNetCore.Server.Kestrel.Https @@ -11,8 +9,6 @@ aspnetcore;kestrel CS1591;$(NoWarn) false - - CurrentRuntime @@ -20,7 +16,7 @@ - + diff --git a/src/Kestrel.Tls/Kestrel.Tls.csproj b/src/Kestrel.Tls/Kestrel.Tls.csproj index 3a7bc3d924..08ef9da8e2 100644 --- a/src/Kestrel.Tls/Kestrel.Tls.csproj +++ b/src/Kestrel.Tls/Kestrel.Tls.csproj @@ -1,7 +1,5 @@  - - Microsoft.AspNetCore.Server.Kestrel.Tls Microsoft.AspNetCore.Server.Kestrel.Tls @@ -10,8 +8,6 @@ aspnetcore;kestrel CS1591;$(NoWarn) false - - CurrentRuntime true @@ -20,7 +16,7 @@ - + diff --git a/src/Kestrel.Transport.Abstractions/Kestrel.Transport.Abstractions.csproj b/src/Kestrel.Transport.Abstractions/Kestrel.Transport.Abstractions.csproj index 3ecaa3a789..a9e754a8ad 100644 --- a/src/Kestrel.Transport.Abstractions/Kestrel.Transport.Abstractions.csproj +++ b/src/Kestrel.Transport.Abstractions/Kestrel.Transport.Abstractions.csproj @@ -1,7 +1,5 @@  - - Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions diff --git a/src/Kestrel.Transport.Libuv/Kestrel.Transport.Libuv.csproj b/src/Kestrel.Transport.Libuv/Kestrel.Transport.Libuv.csproj index 78b2e79bc8..d7324df34d 100644 --- a/src/Kestrel.Transport.Libuv/Kestrel.Transport.Libuv.csproj +++ b/src/Kestrel.Transport.Libuv/Kestrel.Transport.Libuv.csproj @@ -1,7 +1,5 @@  - - Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv @@ -15,10 +13,10 @@ - - - - + + + + diff --git a/src/Kestrel.Transport.Sockets/Kestrel.Transport.Sockets.csproj b/src/Kestrel.Transport.Sockets/Kestrel.Transport.Sockets.csproj index f28cf1a9f3..9d1f419dc3 100644 --- a/src/Kestrel.Transport.Sockets/Kestrel.Transport.Sockets.csproj +++ b/src/Kestrel.Transport.Sockets/Kestrel.Transport.Sockets.csproj @@ -1,7 +1,5 @@  - - Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets @@ -12,13 +10,11 @@ true CS1591;$(NoWarn) false - - CurrentRuntime - - + + diff --git a/src/Kestrel/Kestrel.csproj b/src/Kestrel/Kestrel.csproj index 0afd53fb6d..ab269185a2 100644 --- a/src/Kestrel/Kestrel.csproj +++ b/src/Kestrel/Kestrel.csproj @@ -1,7 +1,5 @@  - - Microsoft.AspNetCore.Server.Kestrel Microsoft.AspNetCore.Server.Kestrel @@ -14,7 +12,7 @@ - + diff --git a/src/Protocols.Abstractions/Protocols.Abstractions.csproj b/src/Protocols.Abstractions/Protocols.Abstractions.csproj index 233f0c3a2b..32fd561e98 100644 --- a/src/Protocols.Abstractions/Protocols.Abstractions.csproj +++ b/src/Protocols.Abstractions/Protocols.Abstractions.csproj @@ -1,5 +1,4 @@ - Microsoft.AspNetCore.Protocols.Abstractions @@ -11,20 +10,16 @@ true CS1591;$(NoWarn) false - - CurrentRuntime - - - - - - - - - + + + + + + + diff --git a/test/Directory.Build.props b/test/Directory.Build.props new file mode 100644 index 0000000000..7039b276a4 --- /dev/null +++ b/test/Directory.Build.props @@ -0,0 +1,24 @@ + + + + + + true + + + + + + + + + + + + + + + diff --git a/test/Kestrel.Core.Tests/HuffmanTests.cs b/test/Kestrel.Core.Tests/HuffmanTests.cs index 7e0375c5da..f075bbc7ba 100644 --- a/test/Kestrel.Core.Tests/HuffmanTests.cs +++ b/test/Kestrel.Core.Tests/HuffmanTests.cs @@ -52,7 +52,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests [Theory] [MemberData(nameof(HuffmanData))] - public void HuffmanEncodeDecode(int code, uint encoded, int bitLength) + public void HuffmanEncodeDecode( + int code, +// Suppresses the warning about an unused theory parameter because +// this test shares data with other methods +#pragma warning disable xUnit1026 + uint encoded, +#pragma warning restore xUnit1026 + int bitLength) { Assert.Equal(code, Huffman.Decode(Huffman.Encode(code).encoded, out var decodedBits)); Assert.Equal(bitLength, decodedBits); diff --git a/test/Kestrel.Core.Tests/Kestrel.Core.Tests.csproj b/test/Kestrel.Core.Tests/Kestrel.Core.Tests.csproj index 469209bfd9..a23522d606 100644 --- a/test/Kestrel.Core.Tests/Kestrel.Core.Tests.csproj +++ b/test/Kestrel.Core.Tests/Kestrel.Core.Tests.csproj @@ -1,23 +1,14 @@  - - Microsoft.AspNetCore.Server.Kestrel.Core.Tests Microsoft.AspNetCore.Server.Kestrel.Core.Tests netcoreapp2.0;net461 netcoreapp2.0 true - - - true - @@ -27,13 +18,9 @@ - - - - - - - + + + diff --git a/test/Kestrel.FunctionalTests/AddressRegistrationTests.cs b/test/Kestrel.FunctionalTests/AddressRegistrationTests.cs index fbbd9038ab..b9f6e4303a 100644 --- a/test/Kestrel.FunctionalTests/AddressRegistrationTests.cs +++ b/test/Kestrel.FunctionalTests/AddressRegistrationTests.cs @@ -383,7 +383,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { options.Listen(new IPEndPoint(IPAddress.Loopback, 0), listenOptions => { - listenOptions.UseHttps("testCert.pfx", "testPassword"); + listenOptions.UseHttps(TestResources.TestCertificatePath, "testPassword"); }); }) .UseUrls(useUrlsAddress) @@ -423,7 +423,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { options.Listen(new IPEndPoint(IPAddress.Loopback, 0), listenOptions => { - listenOptions.UseHttps("testCert.pfx", "testPassword"); + listenOptions.UseHttps(TestResources.TestCertificatePath, "testPassword"); }); }) .UseUrls($"http://127.0.0.1:0") @@ -461,7 +461,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { options.Listen(new IPEndPoint(IPAddress.Loopback, 0), listenOptions => { - listenOptions.UseHttps("testCert.pfx", "testPassword"); + listenOptions.UseHttps(TestResources.TestCertificatePath, "testPassword"); }); }) .PreferHostingUrls(true) diff --git a/test/Kestrel.FunctionalTests/Kestrel.FunctionalTests.csproj b/test/Kestrel.FunctionalTests/Kestrel.FunctionalTests.csproj index 845ea0f84c..3ed0a438b9 100644 --- a/test/Kestrel.FunctionalTests/Kestrel.FunctionalTests.csproj +++ b/test/Kestrel.FunctionalTests/Kestrel.FunctionalTests.csproj @@ -1,7 +1,5 @@  - - Microsoft.AspNetCore.Server.Kestrel.FunctionalTests Microsoft.AspNetCore.Server.Kestrel.FunctionalTests @@ -9,18 +7,11 @@ netcoreapp2.0 $(DefineConstants);MACOS true - - - true - @@ -33,14 +24,10 @@ - - - - - - - - + + + + diff --git a/test/Kestrel.FunctionalTests/xunit.runner.json b/test/Kestrel.FunctionalTests/xunit.runner.json deleted file mode 100644 index c76780941f..0000000000 --- a/test/Kestrel.FunctionalTests/xunit.runner.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "$schema": "http://json.schemastore.org/xunit.runner.schema", - "methodDisplay": "method", - "longRunningTestSeconds": 60 -} diff --git a/test/Kestrel.Tests/Kestrel.Tests.csproj b/test/Kestrel.Tests/Kestrel.Tests.csproj index b05d9659a9..91bb00eb96 100644 --- a/test/Kestrel.Tests/Kestrel.Tests.csproj +++ b/test/Kestrel.Tests/Kestrel.Tests.csproj @@ -1,7 +1,5 @@  - - Microsoft.AspNetCore.Server.Kestrel.Tests Microsoft.AspNetCore.Server.Kestrel.Tests @@ -9,18 +7,8 @@ netcoreapp2.0 - - - - - - - - - - diff --git a/test/Kestrel.Tests/xunit.runner.json b/test/Kestrel.Tests/xunit.runner.json deleted file mode 100644 index c76780941f..0000000000 --- a/test/Kestrel.Tests/xunit.runner.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "$schema": "http://json.schemastore.org/xunit.runner.schema", - "methodDisplay": "method", - "longRunningTestSeconds": 60 -} diff --git a/test/Kestrel.Transport.Libuv.Tests/Kestrel.Transport.Libuv.Tests.csproj b/test/Kestrel.Transport.Libuv.Tests/Kestrel.Transport.Libuv.Tests.csproj index 575504ff6f..4c4aa8b562 100644 --- a/test/Kestrel.Transport.Libuv.Tests/Kestrel.Transport.Libuv.Tests.csproj +++ b/test/Kestrel.Transport.Libuv.Tests/Kestrel.Transport.Libuv.Tests.csproj @@ -1,7 +1,5 @@  - - Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests @@ -9,17 +7,10 @@ netcoreapp2.0 true true - - - true - @@ -28,13 +19,9 @@ - - - - - - - + + + diff --git a/test/Kestrel.Transport.Libuv.Tests/xunit.runner.json b/test/Kestrel.Transport.Libuv.Tests/xunit.runner.json deleted file mode 100644 index 3a5192e57d..0000000000 --- a/test/Kestrel.Transport.Libuv.Tests/xunit.runner.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "$schema": "http://json.schemastore.org/xunit.runner.schema", - "appDomain": "denied", - "methodDisplay": "method", - "longRunningTestSeconds": 60 -} diff --git a/test/Kestrel.Core.Tests/xunit.runner.json b/test/xunit.runner.json similarity index 100% rename from test/Kestrel.Core.Tests/xunit.runner.json rename to test/xunit.runner.json diff --git a/tools/CodeGenerator/CodeGenerator.csproj b/tools/CodeGenerator/CodeGenerator.csproj index 91cec270ff..51021280d2 100644 --- a/tools/CodeGenerator/CodeGenerator.csproj +++ b/tools/CodeGenerator/CodeGenerator.csproj @@ -1,7 +1,5 @@  - - netcoreapp2.0 Exe @@ -14,8 +12,8 @@ - - + + From 87db7cceb665452855a589d75b57ab9805c24335 Mon Sep 17 00:00:00 2001 From: Nate McMaster Date: Wed, 16 Aug 2017 14:56:01 -0700 Subject: [PATCH 1378/1662] Stop producing Microsoft.AspNetCore.Server.Kestrel.Tls as a package --- src/Kestrel.Tls/Kestrel.Tls.csproj | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Kestrel.Tls/Kestrel.Tls.csproj b/src/Kestrel.Tls/Kestrel.Tls.csproj index 08ef9da8e2..8ab28b166c 100644 --- a/src/Kestrel.Tls/Kestrel.Tls.csproj +++ b/src/Kestrel.Tls/Kestrel.Tls.csproj @@ -9,6 +9,7 @@ CS1591;$(NoWarn) false true + false From b613f44ccdb91b20d720ec011cacb74848a0c7ab Mon Sep 17 00:00:00 2001 From: Nate McMaster Date: Thu, 17 Aug 2017 12:52:03 -0700 Subject: [PATCH 1379/1662] Add packages to README [ci skip] --- README.md | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 448d756847..1af1c38364 100644 --- a/README.md +++ b/README.md @@ -3,9 +3,11 @@ KestrelHttpServer [![Join the chat at https://gitter.im/aspnet/KestrelHttpServer](https://badges.gitter.im/aspnet/KestrelHttpServer.svg)](https://gitter.im/aspnet/KestrelHttpServer?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) -AppVeyor: [![AppVeyor](https://ci.appveyor.com/api/projects/status/nr0s92ykm57q0bjv/branch/dev?svg=true)](https://ci.appveyor.com/project/aspnetci/KestrelHttpServer/branch/dev) +[![Travis build status][travis-badge]](https://travis-ci.org/aspnet/KestrelHttpServer/branches) +[![AppVeyor build status][appveyor-badge]](https://ci.appveyor.com/project/aspnetci/KestrelHttpServer/branch/dev) -Travis: [![Travis](https://travis-ci.org/aspnet/KestrelHttpServer.svg?branch=dev)](https://travis-ci.org/aspnet/KestrelHttpServer) +[travis-badge]: https://img.shields.io/travis/aspnet/KestrelHttpServer.svg?label=travis-ci&branch=dev&style=flat-square +[appveyor-badge]: https://img.shields.io/appveyor/ci/aspnetci/KestrelHttpServer/dev.svg?label=appveyor&style=flat-square This repo contains a cross-platform web server for ASP.NET Core. @@ -19,3 +21,23 @@ Before opening this project in Visual Studio or VS Code, execute `build.cmd /t:R This will execute only the part of the build script that downloads and initializes a few required build tools and packages. See [developer documentation](https://github.com/aspnet/Home/wiki) for more details. + +## Packages + +Kestrel is available as a NuGet package. + + Package name | Stable | Nightly (`dev` branch) +--------------------------------------------|---------------------------------------------|------------------------------------------ +`Microsoft.AspNetCore.Server.Kestrel` | [![NuGet][main-nuget-badge]][main-nuget] | [![MyGet][main-myget-badge]][main-myget] +`Microsoft.AspNetCore.Server.Kestrel.Https` | [![NuGet][https-nuget-badge]][https-nuget] | [![MyGet][https-myget-badge]][https-myget] + + +[main-nuget]: https://www.nuget.org/packages/Microsoft.AspNetCore.Server.Kestrel/ +[main-nuget-badge]: https://img.shields.io/nuget/v/Microsoft.AspNetCore.Server.Kestrel.svg?style=flat-square&label=nuget +[main-myget]: https://dotnet.myget.org/feed/aspnetcore-dev/package/nuget/Microsoft.AspNetCore.Server.Kestrel +[main-myget-badge]: https://img.shields.io/dotnet.myget/aspnetcore-dev/vpre/Microsoft.AspNetCore.Server.Kestrel.svg?style=flat-square&label=myget + +[https-nuget]: https://www.nuget.org/packages/Microsoft.AspNetCore.Server.Kestrel.Https/ +[https-nuget-badge]: https://img.shields.io/nuget/v/Microsoft.AspNetCore.Server.Kestrel.Https.svg?style=flat-square&label=nuget +[https-myget]: https://dotnet.myget.org/feed/aspnetcore-dev/package/nuget/Microsoft.AspNetCore.Server.Kestrel.Https +[https-myget-badge]: https://img.shields.io/dotnet.myget/aspnetcore-dev/vpre/Microsoft.AspNetCore.Server.Kestrel.Https.svg?style=flat-square&label=myget From 442ee800393c79b311b35cf2fe5c531c9fbe0195 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Mon, 10 Apr 2017 06:43:09 +0100 Subject: [PATCH 1380/1662] Less awaits for Reponse Write(Async) --- .../FrameWritingBenchmark.cs | 4 +- src/Kestrel.Core/Internal/Http/Frame.cs | 163 +++++++++++++----- .../Internal/Http/OutputProducer.cs | 7 +- test/Kestrel.Core.Tests/FrameTests.cs | 11 +- 4 files changed, 133 insertions(+), 52 deletions(-) diff --git a/benchmarks/Kestrel.Performance/FrameWritingBenchmark.cs b/benchmarks/Kestrel.Performance/FrameWritingBenchmark.cs index 940b5d2f8c..42af59555d 100644 --- a/benchmarks/Kestrel.Performance/FrameWritingBenchmark.cs +++ b/benchmarks/Kestrel.Performance/FrameWritingBenchmark.cs @@ -52,13 +52,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance [Benchmark] public async Task WriteAsyncAwaited() { - await _frame.WriteAsyncAwaited(new ArraySegment(_writeData), default(CancellationToken)); + await _frame.WriteAsyncAwaited(Task.CompletedTask, new ArraySegment(_writeData), default(CancellationToken)); } [Benchmark] public async Task WriteAsyncAwaitedChunked() { - await _frameChunked.WriteAsyncAwaited(new ArraySegment(_writeData), default(CancellationToken)); + await _frameChunked.WriteAsyncAwaited(Task.CompletedTask, new ArraySegment(_writeData), default(CancellationToken)); } [Benchmark] diff --git a/src/Kestrel.Core/Internal/Http/Frame.cs b/src/Kestrel.Core/Internal/Http/Frame.cs index 251e256d41..46d38c6d6e 100644 --- a/src/Kestrel.Core/Internal/Http/Frame.cs +++ b/src/Kestrel.Core/Internal/Http/Frame.cs @@ -463,22 +463,94 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http } } - protected async Task FireOnStarting() + protected Task FireOnStarting() { - Stack, object>> onStarting = null; + Stack, object>> onStarting; lock (_onStartingSync) { onStarting = _onStarting; _onStarting = null; } - if (onStarting != null) + + if (onStarting == null) + { + return Task.CompletedTask; + } + else + { + return FireOnStartingMayAwait(onStarting); + } + + } + + private Task FireOnStartingMayAwait(Stack, object>> onStarting) + { + try + { + var count = onStarting.Count; + for(var i = 0; i < count; i++) + { + var entry = onStarting.Pop(); + var task = entry.Key.Invoke(entry.Value); + if (!ReferenceEquals(task, Task.CompletedTask)) + { + return FireOnStartingAwaited(task, onStarting); + } + } + } + catch (Exception ex) + { + ReportApplicationError(ex); + } + + return Task.CompletedTask; + } + + private async Task FireOnStartingAwaited(Task currentTask, Stack, object>> onStarting) + { + try + { + await currentTask; + + var count = onStarting.Count; + for (var i = 0; i < count; i++) + { + var entry = onStarting.Pop(); + await entry.Key.Invoke(entry.Value); + } + } + catch (Exception ex) + { + ReportApplicationError(ex); + } + } + + protected Task FireOnCompleted() + { + Stack, object>> onCompleted; + lock (_onCompletedSync) + { + onCompleted = _onCompleted; + _onCompleted = null; + } + + if (onCompleted == null) + { + return Task.CompletedTask; + } + else + { + return FireOnCompletedAwaited(onCompleted); + } + } + + private async Task FireOnCompletedAwaited(Stack, object>> onCompleted) + { + foreach (var entry in onCompleted) { try { - foreach (var entry in onStarting) - { - await entry.Key.Invoke(entry.Value); - } + await entry.Key.Invoke(entry.Value); } catch (Exception ex) { @@ -487,44 +559,46 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http } } - protected async Task FireOnCompleted() + public Task FlushAsync(CancellationToken cancellationToken = default(CancellationToken)) { - Stack, object>> onCompleted = null; - lock (_onCompletedSync) + if (!HasResponseStarted) { - onCompleted = _onCompleted; - _onCompleted = null; - } - if (onCompleted != null) - { - foreach (var entry in onCompleted) + var initializeTask = InitializeResponseAsync(0); + // If return is Task.CompletedTask no awaiting is required + if (!ReferenceEquals(initializeTask, Task.CompletedTask)) { - try - { - await entry.Key.Invoke(entry.Value); - } - catch (Exception ex) - { - ReportApplicationError(ex); - } + return FlushAsyncAwaited(initializeTask, cancellationToken); } } + + return Output.FlushAsync(cancellationToken); } - public async Task FlushAsync(CancellationToken cancellationToken = default(CancellationToken)) + [MethodImpl(MethodImplOptions.NoInlining)] + private async Task FlushAsyncAwaited(Task initializeTask, CancellationToken cancellationToken) { - await InitializeResponse(0); + await initializeTask; await Output.FlushAsync(cancellationToken); } public Task WriteAsync(ArraySegment data, CancellationToken cancellationToken = default(CancellationToken)) { - if (!HasResponseStarted) - { - return WriteAsyncAwaited(data, cancellationToken); - } + // For the first write, ensure headers are flushed if Write(Chunked)Async isn't called. + var firstWrite = !HasResponseStarted; - VerifyAndUpdateWrite(data.Count); + if (firstWrite) + { + var initializeTask = InitializeResponseAsync(data.Count); + // If return is Task.CompletedTask no awaiting is required + if (!ReferenceEquals(initializeTask, Task.CompletedTask)) + { + return WriteAsyncAwaited(initializeTask, data, cancellationToken); + } + } + else + { + VerifyAndUpdateWrite(data.Count); + } if (_canHaveBody) { @@ -532,7 +606,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { if (data.Count == 0) { - return Task.CompletedTask; + return !firstWrite ? Task.CompletedTask : FlushAsync(cancellationToken); } return WriteChunkedAsync(data, cancellationToken); } @@ -545,13 +619,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http else { HandleNonBodyResponseWrite(); - return Task.CompletedTask; + return !firstWrite ? Task.CompletedTask : FlushAsync(cancellationToken); } } - public async Task WriteAsyncAwaited(ArraySegment data, CancellationToken cancellationToken) + public async Task WriteAsyncAwaited(Task initializeTask, ArraySegment data, CancellationToken cancellationToken) { - await InitializeResponseAwaited(data.Count); + await initializeTask; // WriteAsyncAwaited is only called for the first write to the body. // Ensure headers are flushed if Write(Chunked)Async isn't called. @@ -667,16 +741,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http } } - public Task InitializeResponse(int firstWriteByteCount) + public Task InitializeResponseAsync(int firstWriteByteCount) { - if (HasResponseStarted) + var startingTask = FireOnStarting(); + // If return is Task.CompletedTask no awaiting is required + if (!ReferenceEquals(startingTask, Task.CompletedTask)) { - return Task.CompletedTask; - } - - if (_onStarting != null) - { - return InitializeResponseAwaited(firstWriteByteCount); + return InitializeResponseAwaited(startingTask, firstWriteByteCount); } if (_applicationException != null) @@ -690,9 +761,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http return Task.CompletedTask; } - private async Task InitializeResponseAwaited(int firstWriteByteCount) + [MethodImpl(MethodImplOptions.NoInlining)] + public async Task InitializeResponseAwaited(Task startingTask, int firstWriteByteCount) { - await FireOnStarting(); + await startingTask; if (_applicationException != null) { @@ -757,6 +829,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http return WriteSuffix(); } + [MethodImpl(MethodImplOptions.NoInlining)] private async Task ProduceEndAwaited() { ProduceStart(appCompleted: true); diff --git a/src/Kestrel.Core/Internal/Http/OutputProducer.cs b/src/Kestrel.Core/Internal/Http/OutputProducer.cs index f84571053d..b44af9f1b7 100644 --- a/src/Kestrel.Core/Internal/Http/OutputProducer.cs +++ b/src/Kestrel.Core/Internal/Http/OutputProducer.cs @@ -2,7 +2,9 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Diagnostics; using System.IO.Pipelines; +using System.Runtime.CompilerServices; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; @@ -143,8 +145,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http return FlushAsync(writableBuffer, cancellationToken); } - private Task FlushAsync(WritableBuffer writableBuffer, - CancellationToken cancellationToken) + // Single caller, at end of method - so inline + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private Task FlushAsync(WritableBuffer writableBuffer, CancellationToken cancellationToken) { var awaitable = writableBuffer.FlushAsync(cancellationToken); if (awaitable.IsCompleted) diff --git a/test/Kestrel.Core.Tests/FrameTests.cs b/test/Kestrel.Core.Tests/FrameTests.cs index d6a1c76637..d5f14333bf 100644 --- a/test/Kestrel.Core.Tests/FrameTests.cs +++ b/test/Kestrel.Core.Tests/FrameTests.cs @@ -641,13 +641,18 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests // Need to compare WaitHandle ref since CancellationToken is struct var original = _frame.RequestAborted.WaitHandle; - foreach (var ch in "hello, worl") + // Only first write can be WriteAsyncAwaited + var startingTask = _frame.InitializeResponseAwaited(Task.CompletedTask, 1); + await _frame.WriteAsyncAwaited(startingTask, new ArraySegment(new[] { (byte)'h' }), default(CancellationToken)); + Assert.Same(original, _frame.RequestAborted.WaitHandle); + + foreach (var ch in "ello, worl") { - await _frame.WriteAsyncAwaited(new ArraySegment(new[] { (byte)ch }), default(CancellationToken)); + await _frame.WriteAsync(new ArraySegment(new[] { (byte)ch }), default(CancellationToken)); Assert.Same(original, _frame.RequestAborted.WaitHandle); } - await _frame.WriteAsyncAwaited(new ArraySegment(new[] { (byte)'d' }), default(CancellationToken)); + await _frame.WriteAsync(new ArraySegment(new[] { (byte)'d' }), default(CancellationToken)); Assert.NotSame(original, _frame.RequestAborted.WaitHandle); } From 14f122fb9fda05ac652bca5210941d95f21bd940 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Thu, 17 Aug 2017 16:58:55 -0700 Subject: [PATCH 1381/1662] Measure Writing in FrameWritingBenchmark --- .../FrameWritingBenchmark.cs | 122 ++++++++++++------ src/Kestrel.Core/Internal/Http/Frame.cs | 6 + src/Kestrel.Core/Internal/Http/MessageBody.cs | 3 + src/Kestrel.Core/Properties/AssemblyInfo.cs | 2 +- 4 files changed, 89 insertions(+), 44 deletions(-) diff --git a/benchmarks/Kestrel.Performance/FrameWritingBenchmark.cs b/benchmarks/Kestrel.Performance/FrameWritingBenchmark.cs index 42af59555d..3e0aae0be1 100644 --- a/benchmarks/Kestrel.Performance/FrameWritingBenchmark.cs +++ b/benchmarks/Kestrel.Performance/FrameWritingBenchmark.cs @@ -3,6 +3,7 @@ using System; using System.IO.Pipelines; +using System.Text; using System.Threading; using System.Threading.Tasks; using BenchmarkDotNet.Attributes; @@ -16,68 +17,85 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance [Config(typeof(CoreConfig))] public class FrameWritingBenchmark { + // Standard completed task + private static readonly Func _syncTaskFunc = (obj) => Task.CompletedTask; + // Non-standard completed task + private static readonly Task _psuedoAsyncTask = Task.FromResult(27); + private static readonly Func _psuedoAsyncTaskFunc = (obj) => _psuedoAsyncTask; + private readonly TestFrame _frame; - private readonly TestFrame _frameChunked; + private readonly IPipe _outputPipe; + private readonly byte[] _writeData; public FrameWritingBenchmark() { - _frame = MakeFrame(); - _frameChunked = MakeFrame(); - _writeData = new byte[1]; + var pipeFactory = new PipeFactory(); + + _outputPipe = pipeFactory.Create(); + _frame = MakeFrame(pipeFactory); + _writeData = Encoding.ASCII.GetBytes("Hello, World!"); } + [Params(true, false)] + public bool WithHeaders { get; set; } + + [Params(true, false)] + public bool Chunked { get; set; } + + [Params(Startup.None, Startup.Sync, Startup.Async)] + public Startup OnStarting { get; set; } + [Setup] public void Setup() { _frame.Reset(); - _frame.RequestHeaders.Add("Content-Length", "1073741824"); + if (Chunked) + { + _frame.RequestHeaders.Add("Transfer-Encoding", "chunked"); + } + else + { + _frame.RequestHeaders.ContentLength = _writeData.Length; + } - _frameChunked.Reset(); - _frameChunked.RequestHeaders.Add("Transfer-Encoding", "chunked"); + if (!WithHeaders) + { + _frame.FlushAsync().GetAwaiter().GetResult(); + } + + ResetState(); + } + + private void ResetState() + { + if (WithHeaders) + { + _frame.ResetState(); + + switch (OnStarting) + { + case Startup.Sync: + _frame.OnStarting(_syncTaskFunc, null); + break; + case Startup.Async: + _frame.OnStarting(_psuedoAsyncTaskFunc, null); + break; + } + } } [Benchmark] - public async Task WriteAsync() + public Task WriteAsync() { - await _frame.WriteAsync(new ArraySegment(_writeData), default(CancellationToken)); + ResetState(); + + return _frame.ResponseBody.WriteAsync(_writeData, 0, _writeData.Length, default(CancellationToken)); } - [Benchmark] - public async Task WriteAsyncChunked() + private TestFrame MakeFrame(PipeFactory pipeFactory) { - await _frameChunked.WriteAsync(new ArraySegment(_writeData), default(CancellationToken)); - } - - [Benchmark] - public async Task WriteAsyncAwaited() - { - await _frame.WriteAsyncAwaited(Task.CompletedTask, new ArraySegment(_writeData), default(CancellationToken)); - } - - [Benchmark] - public async Task WriteAsyncAwaitedChunked() - { - await _frameChunked.WriteAsyncAwaited(Task.CompletedTask, new ArraySegment(_writeData), default(CancellationToken)); - } - - [Benchmark] - public async Task ProduceEnd() - { - await _frame.ProduceEndAsync(); - } - - [Benchmark] - public async Task ProduceEndChunked() - { - await _frameChunked.ProduceEndAsync(); - } - - private TestFrame MakeFrame() - { - var pipeFactory = new PipeFactory(); var input = pipeFactory.Create(); - var output = pipeFactory.Create(); var serviceContext = new ServiceContext { @@ -92,12 +110,30 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance ServiceContext = serviceContext, PipeFactory = pipeFactory, Input = input.Reader, - Output = output + Output = _outputPipe }); frame.Reset(); + frame.InitializeStreams(MessageBody.ZeroContentLengthKeepAlive); return frame; } + + [Cleanup] + public void Cleanup() + { + var reader = _outputPipe.Reader; + if (reader.TryRead(out var readResult)) + { + reader.Advance(readResult.Buffer.End); + } + } + + public enum Startup + { + None, + Sync, + Async + } } } diff --git a/src/Kestrel.Core/Internal/Http/Frame.cs b/src/Kestrel.Core/Internal/Http/Frame.cs index 46d38c6d6e..bdced76b67 100644 --- a/src/Kestrel.Core/Internal/Http/Frame.cs +++ b/src/Kestrel.Core/Internal/Http/Frame.cs @@ -316,6 +316,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http public void StopStreams() => _frameStreams.Stop(); + // For testing + internal void ResetState() + { + _requestProcessingStatus = RequestProcessingStatus.RequestPending; + } + public void Reset() { _onStarting = null; diff --git a/src/Kestrel.Core/Internal/Http/MessageBody.cs b/src/Kestrel.Core/Internal/Http/MessageBody.cs index 164f7f69ca..86e9abf729 100644 --- a/src/Kestrel.Core/Internal/Http/MessageBody.cs +++ b/src/Kestrel.Core/Internal/Http/MessageBody.cs @@ -16,6 +16,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http private static readonly MessageBody _zeroContentLengthClose = new ForZeroContentLength(keepAlive: false); private static readonly MessageBody _zeroContentLengthKeepAlive = new ForZeroContentLength(keepAlive: true); + // For testing + internal static MessageBody ZeroContentLengthKeepAlive => _zeroContentLengthKeepAlive; + private readonly Frame _context; private bool _send100Continue = true; diff --git a/src/Kestrel.Core/Properties/AssemblyInfo.cs b/src/Kestrel.Core/Properties/AssemblyInfo.cs index c93c4396ee..bd1d32689a 100644 --- a/src/Kestrel.Core/Properties/AssemblyInfo.cs +++ b/src/Kestrel.Core/Properties/AssemblyInfo.cs @@ -5,5 +5,5 @@ using System.Runtime.CompilerServices; [assembly: InternalsVisibleTo("Microsoft.AspNetCore.Server.Kestrel.FunctionalTests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")] [assembly: InternalsVisibleTo("Microsoft.AspNetCore.Server.Kestrel.Core.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")] -[assembly: InternalsVisibleTo("Microsoft.AspNetCore.Server.Kestrel.Performance, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")] +[assembly: InternalsVisibleTo("Kestrel.Performance, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")] [assembly: InternalsVisibleTo("Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")] From fd66472b3976e7d60a0a3023d367b5620f16e5a4 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Thu, 17 Aug 2017 17:00:46 -0700 Subject: [PATCH 1382/1662] Get Kestrel.Performance working again --- Directory.Build.targets | 2 +- benchmarks/Kestrel.Performance/Kestrel.Performance.csproj | 3 ++- benchmarks/Kestrel.Performance/README.md | 4 ++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/Directory.Build.targets b/Directory.Build.targets index 9989b1046b..8296c12835 100644 --- a/Directory.Build.targets +++ b/Directory.Build.targets @@ -1,5 +1,5 @@ - + <_BootstrapperFile Condition=" $([MSBuild]::IsOSUnixLike()) ">build.sh <_BootstrapperFile Condition="! $([MSBuild]::IsOSUnixLike()) ">build.cmd diff --git a/benchmarks/Kestrel.Performance/Kestrel.Performance.csproj b/benchmarks/Kestrel.Performance/Kestrel.Performance.csproj index 3a982816ef..bee6d2f9a3 100644 --- a/benchmarks/Kestrel.Performance/Kestrel.Performance.csproj +++ b/benchmarks/Kestrel.Performance/Kestrel.Performance.csproj @@ -1,7 +1,8 @@  - Microsoft.AspNetCore.Server.Kestrel.Performance + + Kestrel.Performance Microsoft.AspNetCore.Server.Kestrel.Performance netcoreapp2.0;net461 netcoreapp2.0 diff --git a/benchmarks/Kestrel.Performance/README.md b/benchmarks/Kestrel.Performance/README.md index 63db0c3d7e..91991f82ff 100644 --- a/benchmarks/Kestrel.Performance/README.md +++ b/benchmarks/Kestrel.Performance/README.md @@ -2,10 +2,10 @@ To run a specific benchmark add it as parameter ``` -dotnet run -c Release RequestParsing +dotnet run -f netcoreapp2.0 -c Release RequestParsing ``` To run all use `All` as parameter ``` -dotnet run -c Release All +dotnet run -f netcoreapp2.0 -c Release All ``` Using no parameter will list all available benchmarks From 7f23ff08ce96af04e80defe13a4211badb22e29b Mon Sep 17 00:00:00 2001 From: Nate McMaster Date: Fri, 18 Aug 2017 10:57:48 -0700 Subject: [PATCH 1383/1662] React to changes in BenchmarkDotNet 0.10.9 (#2006) * fixup! React to changes in BenchmarkDotNet 0.10.9 --- benchmarks/Kestrel.Performance/FrameFeatureCollection.cs | 2 +- .../Kestrel.Performance/FrameParsingOverheadBenchmark.cs | 2 +- benchmarks/Kestrel.Performance/FrameWritingBenchmark.cs | 4 ++-- benchmarks/Kestrel.Performance/Kestrel.Performance.csproj | 2 +- benchmarks/Kestrel.Performance/PipeThroughputBenchmark.cs | 2 +- benchmarks/Kestrel.Performance/RequestParsingBenchmark.cs | 2 +- .../Kestrel.Performance/ResponseHeaderCollectionBenchmark.cs | 2 +- .../Kestrel.Performance/ResponseHeadersWritingBenchmark.cs | 2 +- 8 files changed, 9 insertions(+), 9 deletions(-) diff --git a/benchmarks/Kestrel.Performance/FrameFeatureCollection.cs b/benchmarks/Kestrel.Performance/FrameFeatureCollection.cs index ca85ab5aca..2e157f41d7 100644 --- a/benchmarks/Kestrel.Performance/FrameFeatureCollection.cs +++ b/benchmarks/Kestrel.Performance/FrameFeatureCollection.cs @@ -91,7 +91,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance _frame = new Frame(application: null, frameContext: frameContext); } - [Setup] + [IterationSetup] public void Setup() { _collection = _frame; diff --git a/benchmarks/Kestrel.Performance/FrameParsingOverheadBenchmark.cs b/benchmarks/Kestrel.Performance/FrameParsingOverheadBenchmark.cs index ab6259e04a..f27fb8c947 100644 --- a/benchmarks/Kestrel.Performance/FrameParsingOverheadBenchmark.cs +++ b/benchmarks/Kestrel.Performance/FrameParsingOverheadBenchmark.cs @@ -18,7 +18,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance public ReadableBuffer _buffer; public Frame _frame; - [Setup] + [IterationSetup] public void Setup() { var serviceContext = new ServiceContext diff --git a/benchmarks/Kestrel.Performance/FrameWritingBenchmark.cs b/benchmarks/Kestrel.Performance/FrameWritingBenchmark.cs index 3e0aae0be1..bc0fa20588 100644 --- a/benchmarks/Kestrel.Performance/FrameWritingBenchmark.cs +++ b/benchmarks/Kestrel.Performance/FrameWritingBenchmark.cs @@ -46,7 +46,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance [Params(Startup.None, Startup.Sync, Startup.Async)] public Startup OnStarting { get; set; } - [Setup] + [IterationSetup] public void Setup() { _frame.Reset(); @@ -119,7 +119,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance return frame; } - [Cleanup] + [IterationCleanup] public void Cleanup() { var reader = _outputPipe.Reader; diff --git a/benchmarks/Kestrel.Performance/Kestrel.Performance.csproj b/benchmarks/Kestrel.Performance/Kestrel.Performance.csproj index bee6d2f9a3..4a6f234f0a 100644 --- a/benchmarks/Kestrel.Performance/Kestrel.Performance.csproj +++ b/benchmarks/Kestrel.Performance/Kestrel.Performance.csproj @@ -23,7 +23,7 @@ - + diff --git a/benchmarks/Kestrel.Performance/PipeThroughputBenchmark.cs b/benchmarks/Kestrel.Performance/PipeThroughputBenchmark.cs index e4322d2a47..7af128c11d 100644 --- a/benchmarks/Kestrel.Performance/PipeThroughputBenchmark.cs +++ b/benchmarks/Kestrel.Performance/PipeThroughputBenchmark.cs @@ -16,7 +16,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance private IPipe _pipe; private PipeFactory _pipelineFactory; - [Setup] + [IterationSetup] public void Setup() { _pipelineFactory = new PipeFactory(); diff --git a/benchmarks/Kestrel.Performance/RequestParsingBenchmark.cs b/benchmarks/Kestrel.Performance/RequestParsingBenchmark.cs index 06f3dac080..b4f14656e4 100644 --- a/benchmarks/Kestrel.Performance/RequestParsingBenchmark.cs +++ b/benchmarks/Kestrel.Performance/RequestParsingBenchmark.cs @@ -19,7 +19,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance public PipeFactory PipeFactory { get; set; } - [Setup] + [IterationSetup] public void Setup() { PipeFactory = new PipeFactory(); diff --git a/benchmarks/Kestrel.Performance/ResponseHeaderCollectionBenchmark.cs b/benchmarks/Kestrel.Performance/ResponseHeaderCollectionBenchmark.cs index 57d9b53f70..54f7907ce3 100644 --- a/benchmarks/Kestrel.Performance/ResponseHeaderCollectionBenchmark.cs +++ b/benchmarks/Kestrel.Performance/ResponseHeaderCollectionBenchmark.cs @@ -166,7 +166,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance } } - [Setup] + [IterationSetup] public void Setup() { var serviceContext = new ServiceContext diff --git a/benchmarks/Kestrel.Performance/ResponseHeadersWritingBenchmark.cs b/benchmarks/Kestrel.Performance/ResponseHeadersWritingBenchmark.cs index abef01feb0..980ef84648 100644 --- a/benchmarks/Kestrel.Performance/ResponseHeadersWritingBenchmark.cs +++ b/benchmarks/Kestrel.Performance/ResponseHeadersWritingBenchmark.cs @@ -106,7 +106,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance return _frame.WriteAsync(new ArraySegment(_helloWorldPayload), default(CancellationToken)); } - [Setup] + [IterationSetup] public void Setup() { var pipeFactory = new PipeFactory(); From 59b77bb357f50946ecea310feb8db53473e0e165 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Fri, 18 Aug 2017 22:46:19 +0100 Subject: [PATCH 1384/1662] Async Main samples (#2004) --- samples/LargeResponseApp/Startup.cs | 5 ++--- samples/SampleApp/Startup.cs | 4 ++-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/samples/LargeResponseApp/Startup.cs b/samples/LargeResponseApp/Startup.cs index 47ecd8a08b..c2b7d30a1b 100644 --- a/samples/LargeResponseApp/Startup.cs +++ b/samples/LargeResponseApp/Startup.cs @@ -15,7 +15,6 @@ namespace LargeResponseApp private const int _chunkSize = 4096; private const int _defaultNumChunks = 16; private static byte[] _chunk = Encoding.UTF8.GetBytes(new string('a', _chunkSize)); - private static Task _emptyTask = Task.FromResult(null); public void Configure(IApplicationBuilder app) { @@ -38,7 +37,7 @@ namespace LargeResponseApp }); } - public static void Main(string[] args) + public static Task Main(string[] args) { var host = new WebHostBuilder() .UseKestrel(options => @@ -49,7 +48,7 @@ namespace LargeResponseApp .UseStartup() .Build(); - host.Run(); + return host.RunAsync(); } } } diff --git a/samples/SampleApp/Startup.cs b/samples/SampleApp/Startup.cs index 18b4baacf4..e89e97790b 100644 --- a/samples/SampleApp/Startup.cs +++ b/samples/SampleApp/Startup.cs @@ -35,7 +35,7 @@ namespace SampleApp }); } - public static void Main(string[] args) + public static Task Main(string[] args) { TaskScheduler.UnobservedTaskException += (sender, e) => { @@ -89,7 +89,7 @@ namespace SampleApp .UseStartup() .Build(); - host.Run(); + return host.RunAsync(); } } } \ No newline at end of file From 2e6687031d1ebb77fff4af77a88fdac64af8b7a9 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Mon, 21 Aug 2017 12:11:27 -0700 Subject: [PATCH 1385/1662] Added initial connection middleware pipeline (#2003) * Added initial connection middleware pipeline - Implemented IConnectionBuilder on ListenOptions. Kept IConnectionAdapter for now. - Delay the configure callback for ListenOptions until the server has started. - Added ConnectionLimitMiddleware and HttpConnectionMiddleware - Expose ConnectionAborted and ConnectionClosed on ConnectionContext and IConnectionTransportFeature - Updated the tests - Removed IConnectionApplicationFeature - Moved Application to IConnectionTransportFeature --- .../FrameWritingBenchmark.cs | 19 ++- .../ResponseHeadersWritingBenchmark.cs | 7 +- .../Adapter/Internal/AdaptedPipeline.cs | 34 +++-- .../Internal/ConnectionHandler.cs | 112 +++++--------- .../ConnectionLimitBuilderExtensions.cs | 16 ++ .../Internal/ConnectionLimitMiddleware.cs | 32 ++++ src/Kestrel.Core/Internal/FrameConnection.cs | 52 +++---- .../Internal/FrameConnectionContext.cs | 7 +- src/Kestrel.Core/Internal/Http/Frame.cs | 4 +- .../Internal/Http/FrameContext.cs | 4 +- .../Internal/Http/OutputProducer.cs | 19 ++- .../Internal/Http2/Http2Connection.cs | 4 +- .../Internal/Http2/Http2ConnectionContext.cs | 4 +- .../Internal/Http2/Http2FrameWriter.cs | 14 +- .../HttpConnectionBuilderExtensions.cs | 26 ++++ .../Internal/HttpConnectionMiddleware.cs | 91 ++++++++++++ .../Internal/RejectionConnection.cs | 47 ------ src/Kestrel.Core/KestrelServer.cs | 11 +- src/Kestrel.Core/KestrelServerOptions.cs | 9 +- src/Kestrel.Core/ListenOptions.cs | 31 +++- .../Internal/TransportConnection.Features.cs | 38 +++-- .../Internal/TransportConnection.cs | 33 ++++- .../Internal/LibuvConnection.cs | 10 +- .../SocketConnection.cs | 8 +- .../ConnectionContext.cs | 6 + .../DefaultConnectionContext.cs | 9 +- .../Features/IConnectionApplicationFeature.cs | 18 --- .../Features/IConnectionTransportFeature.cs | 9 +- .../PipeFactoryExtensions.cs | 21 +++ .../FrameConnectionTests.cs | 27 ++-- .../FrameResponseHeadersTests.cs | 6 +- test/Kestrel.Core.Tests/FrameTests.cs | 137 +++++++++--------- .../Http2ConnectionTests.cs | 20 ++- .../KestrelServerOptionsTests.cs | 4 +- test/Kestrel.Core.Tests/MessageBodyTests.cs | 8 +- .../Kestrel.Core.Tests/OutputProducerTests.cs | 3 +- test/Kestrel.Core.Tests/PipeOptionsTests.cs | 8 +- test/Kestrel.Core.Tests/TestInput.cs | 19 ++- test/Kestrel.FunctionalTests/RequestTests.cs | 3 +- .../LibuvOutputConsumerTests.cs | 9 +- .../LibuvTransportTests.cs | 6 +- .../ListenerPrimaryTests.cs | 63 ++++++-- .../TestHelpers/MockConnectionHandler.cs | 22 +-- 43 files changed, 618 insertions(+), 412 deletions(-) create mode 100644 src/Kestrel.Core/Internal/ConnectionLimitBuilderExtensions.cs create mode 100644 src/Kestrel.Core/Internal/ConnectionLimitMiddleware.cs create mode 100644 src/Kestrel.Core/Internal/HttpConnectionBuilderExtensions.cs create mode 100644 src/Kestrel.Core/Internal/HttpConnectionMiddleware.cs delete mode 100644 src/Kestrel.Core/Internal/RejectionConnection.cs delete mode 100644 src/Protocols.Abstractions/Features/IConnectionApplicationFeature.cs create mode 100644 src/Protocols.Abstractions/PipeFactoryExtensions.cs diff --git a/benchmarks/Kestrel.Performance/FrameWritingBenchmark.cs b/benchmarks/Kestrel.Performance/FrameWritingBenchmark.cs index bc0fa20588..82f943f525 100644 --- a/benchmarks/Kestrel.Performance/FrameWritingBenchmark.cs +++ b/benchmarks/Kestrel.Performance/FrameWritingBenchmark.cs @@ -24,16 +24,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance private static readonly Func _psuedoAsyncTaskFunc = (obj) => _psuedoAsyncTask; private readonly TestFrame _frame; - private readonly IPipe _outputPipe; + private (IPipeConnection Transport, IPipeConnection Application) _pair; private readonly byte[] _writeData; public FrameWritingBenchmark() { - var pipeFactory = new PipeFactory(); - - _outputPipe = pipeFactory.Create(); - _frame = MakeFrame(pipeFactory); + _frame = MakeFrame(); _writeData = Encoding.ASCII.GetBytes("Hello, World!"); } @@ -93,9 +90,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance return _frame.ResponseBody.WriteAsync(_writeData, 0, _writeData.Length, default(CancellationToken)); } - private TestFrame MakeFrame(PipeFactory pipeFactory) + private TestFrame MakeFrame() { - var input = pipeFactory.Create(); + var pipeFactory = new PipeFactory(); + var pair = pipeFactory.CreateConnectionPair(); + _pair = pair; var serviceContext = new ServiceContext { @@ -109,8 +108,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance { ServiceContext = serviceContext, PipeFactory = pipeFactory, - Input = input.Reader, - Output = _outputPipe + Application = pair.Application, + Transport = pair.Transport }); frame.Reset(); @@ -122,7 +121,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance [IterationCleanup] public void Cleanup() { - var reader = _outputPipe.Reader; + var reader = _pair.Application.Input; if (reader.TryRead(out var readResult)) { reader.Advance(readResult.Buffer.End); diff --git a/benchmarks/Kestrel.Performance/ResponseHeadersWritingBenchmark.cs b/benchmarks/Kestrel.Performance/ResponseHeadersWritingBenchmark.cs index 980ef84648..52ffb6bb77 100644 --- a/benchmarks/Kestrel.Performance/ResponseHeadersWritingBenchmark.cs +++ b/benchmarks/Kestrel.Performance/ResponseHeadersWritingBenchmark.cs @@ -110,8 +110,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance public void Setup() { var pipeFactory = new PipeFactory(); - var input = pipeFactory.Create(); - var output = pipeFactory.Create(); + var pair = pipeFactory.CreateConnectionPair(); var serviceContext = new ServiceContext { @@ -126,8 +125,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance ServiceContext = serviceContext, PipeFactory = pipeFactory, TimeoutControl = new MockTimeoutControl(), - Input = input.Reader, - Output = output + Application = pair.Application, + Transport = pair.Transport }); frame.Reset(); diff --git a/src/Kestrel.Core/Adapter/Internal/AdaptedPipeline.cs b/src/Kestrel.Core/Adapter/Internal/AdaptedPipeline.cs index 823fa67b52..72c1780d08 100644 --- a/src/Kestrel.Core/Adapter/Internal/AdaptedPipeline.cs +++ b/src/Kestrel.Core/Adapter/Internal/AdaptedPipeline.cs @@ -5,36 +5,36 @@ using System; using System.IO; using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; -using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; using System.IO.Pipelines; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal { - public class AdaptedPipeline + public class AdaptedPipeline : IPipeConnection { private const int MinAllocBufferSize = 2048; - private readonly IKestrelTrace _trace; - private readonly IPipe _transportOutputPipe; - private readonly IPipeReader _transportInputPipeReader; + private readonly IPipeConnection _transport; + private readonly IPipeConnection _application; - public AdaptedPipeline(IPipeReader transportInputPipeReader, - IPipe transportOutputPipe, + public AdaptedPipeline(IPipeConnection transport, + IPipeConnection application, IPipe inputPipe, - IPipe outputPipe, - IKestrelTrace trace) + IPipe outputPipe) { - _transportInputPipeReader = transportInputPipeReader; - _transportOutputPipe = transportOutputPipe; + _transport = transport; + _application = application; Input = inputPipe; Output = outputPipe; - _trace = trace; } public IPipe Input { get; } public IPipe Output { get; } + IPipeReader IPipeConnection.Input => Input.Reader; + + IPipeWriter IPipeConnection.Output => Output.Writer; + public async Task RunAsync(Stream stream) { var inputTask = ReadInputAsync(stream); @@ -65,7 +65,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal if (result.IsCancelled) { // Forward the cancellation to the transport pipe - _transportOutputPipe.Reader.CancelPendingRead(); + _application.Input.CancelPendingRead(); break; } @@ -104,7 +104,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal finally { Output.Reader.Complete(); - _transportOutputPipe.Writer.Complete(error); + _transport.Output.Complete(); } } @@ -161,8 +161,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal Input.Writer.Complete(error); // The application could have ended the input pipe so complete // the transport pipe as well - _transportInputPipeReader.Complete(); + _transport.Input.Complete(); } } + + public void Dispose() + { + } } } diff --git a/src/Kestrel.Core/Internal/ConnectionHandler.cs b/src/Kestrel.Core/Internal/ConnectionHandler.cs index 0dc7fbcbf0..d94de12429 100644 --- a/src/Kestrel.Core/Internal/ConnectionHandler.cs +++ b/src/Kestrel.Core/Internal/ConnectionHandler.cs @@ -1,31 +1,27 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; using System.IO.Pipelines; -using System.Net; -using System.Threading; -using Microsoft.AspNetCore.Hosting.Server; +using System.Threading.Tasks; using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Protocols; using Microsoft.AspNetCore.Protocols.Features; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; +using Microsoft.Extensions.Logging; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal { - public class ConnectionHandler : IConnectionHandler + public class ConnectionHandler : IConnectionHandler { - private static long _lastFrameConnectionId = long.MinValue; - - private readonly ListenOptions _listenOptions; private readonly ServiceContext _serviceContext; - private readonly IHttpApplication _application; + private readonly ConnectionDelegate _connectionDelegate; - public ConnectionHandler(ListenOptions listenOptions, ServiceContext serviceContext, IHttpApplication application) + public ConnectionHandler(ServiceContext serviceContext, ConnectionDelegate connectionDelegate) { - _listenOptions = listenOptions; _serviceContext = serviceContext; - _application = application; + _connectionDelegate = connectionDelegate; } public void OnConnection(IFeatureCollection features) @@ -34,89 +30,57 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal var transportFeature = connectionContext.Features.Get(); - var inputPipe = transportFeature.PipeFactory.Create(GetInputPipeOptions(transportFeature.InputWriterScheduler)); - var outputPipe = transportFeature.PipeFactory.Create(GetOutputPipeOptions(transportFeature.OutputReaderScheduler)); + // REVIEW: Unfortunately, we still need to use the service context to create the pipes since the settings + // for the scheduler and limits are specified here + var inputOptions = GetInputPipeOptions(_serviceContext, transportFeature.InputWriterScheduler); + var outputOptions = GetOutputPipeOptions(_serviceContext, transportFeature.OutputReaderScheduler); - var connectionId = CorrelationIdGenerator.GetNextId(); - var frameConnectionId = Interlocked.Increment(ref _lastFrameConnectionId); + var pair = connectionContext.PipeFactory.CreateConnectionPair(inputOptions, outputOptions); // Set the transport and connection id - connectionContext.ConnectionId = connectionId; - transportFeature.Connection = new PipeConnection(inputPipe.Reader, outputPipe.Writer); - var applicationConnection = new PipeConnection(outputPipe.Reader, inputPipe.Writer); + connectionContext.ConnectionId = CorrelationIdGenerator.GetNextId(); + connectionContext.Transport = pair.Transport; - if (!_serviceContext.ConnectionManager.NormalConnectionCount.TryLockOne()) + // This *must* be set before returning from OnConnection + transportFeature.Application = pair.Application; + + // REVIEW: This task should be tracked by the server for graceful shutdown + // Today it's handled specifically for http but not for aribitrary middleware + _ = Execute(connectionContext); + } + + private async Task Execute(ConnectionContext connectionContext) + { + try { - var goAway = new RejectionConnection(inputPipe, outputPipe, connectionId, _serviceContext) - { - Connection = applicationConnection - }; - - connectionContext.Features.Set(goAway); - - goAway.Reject(); - return; + await _connectionDelegate(connectionContext); } - - var frameConnectionContext = new FrameConnectionContext + catch (Exception ex) { - ConnectionId = connectionId, - FrameConnectionId = frameConnectionId, - ServiceContext = _serviceContext, - PipeFactory = connectionContext.PipeFactory, - ConnectionAdapters = _listenOptions.ConnectionAdapters, - Input = inputPipe, - Output = outputPipe - }; - - var connectionFeature = connectionContext.Features.Get(); - - if (connectionFeature != null) - { - if (connectionFeature.LocalIpAddress != null) - { - frameConnectionContext.LocalEndPoint = new IPEndPoint(connectionFeature.LocalIpAddress, connectionFeature.LocalPort); - } - - if (connectionFeature.RemoteIpAddress != null) - { - frameConnectionContext.RemoteEndPoint = new IPEndPoint(connectionFeature.RemoteIpAddress, connectionFeature.RemotePort); - } + _serviceContext.Log.LogCritical(0, ex, $"{nameof(ConnectionHandler)}.{nameof(Execute)}() {connectionContext.ConnectionId}"); } - - var connection = new FrameConnection(frameConnectionContext) - { - Connection = applicationConnection - }; - - connectionContext.Features.Set(connection); - - // Since data cannot be added to the inputPipe by the transport until OnConnection returns, - // Frame.ProcessRequestsAsync is guaranteed to unblock the transport thread before calling - // application code. - connection.StartRequestProcessing(_application); } // Internal for testing - internal PipeOptions GetInputPipeOptions(IScheduler writerScheduler) => new PipeOptions + internal static PipeOptions GetInputPipeOptions(ServiceContext serviceContext, IScheduler writerScheduler) => new PipeOptions { - ReaderScheduler = _serviceContext.ThreadPool, + ReaderScheduler = serviceContext.ThreadPool, WriterScheduler = writerScheduler, - MaximumSizeHigh = _serviceContext.ServerOptions.Limits.MaxRequestBufferSize ?? 0, - MaximumSizeLow = _serviceContext.ServerOptions.Limits.MaxRequestBufferSize ?? 0 + MaximumSizeHigh = serviceContext.ServerOptions.Limits.MaxRequestBufferSize ?? 0, + MaximumSizeLow = serviceContext.ServerOptions.Limits.MaxRequestBufferSize ?? 0 }; - internal PipeOptions GetOutputPipeOptions(IScheduler readerScheduler) => new PipeOptions + internal static PipeOptions GetOutputPipeOptions(ServiceContext serviceContext, IScheduler readerScheduler) => new PipeOptions { ReaderScheduler = readerScheduler, - WriterScheduler = _serviceContext.ThreadPool, - MaximumSizeHigh = GetOutputResponseBufferSize(), - MaximumSizeLow = GetOutputResponseBufferSize() + WriterScheduler = serviceContext.ThreadPool, + MaximumSizeHigh = GetOutputResponseBufferSize(serviceContext), + MaximumSizeLow = GetOutputResponseBufferSize(serviceContext) }; - private long GetOutputResponseBufferSize() + private static long GetOutputResponseBufferSize(ServiceContext serviceContext) { - var bufferSize = _serviceContext.ServerOptions.Limits.MaxResponseBufferSize; + var bufferSize = serviceContext.ServerOptions.Limits.MaxResponseBufferSize; if (bufferSize == 0) { // 0 = no buffering so we need to configure the pipe so the the writer waits on the reader directly diff --git a/src/Kestrel.Core/Internal/ConnectionLimitBuilderExtensions.cs b/src/Kestrel.Core/Internal/ConnectionLimitBuilderExtensions.cs new file mode 100644 index 0000000000..2c02fa664c --- /dev/null +++ b/src/Kestrel.Core/Internal/ConnectionLimitBuilderExtensions.cs @@ -0,0 +1,16 @@ +using Microsoft.AspNetCore.Protocols; + +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal +{ + public static class ConnectionLimitBuilderExtensions + { + public static IConnectionBuilder UseConnectionLimit(this IConnectionBuilder builder, ServiceContext serviceContext) + { + return builder.Use(next => + { + var middleware = new ConnectionLimitMiddleware(next, serviceContext); + return middleware.OnConnectionAsync; + }); + } + } +} diff --git a/src/Kestrel.Core/Internal/ConnectionLimitMiddleware.cs b/src/Kestrel.Core/Internal/ConnectionLimitMiddleware.cs new file mode 100644 index 0000000000..cd058bc235 --- /dev/null +++ b/src/Kestrel.Core/Internal/ConnectionLimitMiddleware.cs @@ -0,0 +1,32 @@ +using System.Threading.Tasks; +using Microsoft.AspNetCore.Protocols; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; + +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal +{ + public class ConnectionLimitMiddleware + { + private readonly ServiceContext _serviceContext; + private readonly ConnectionDelegate _next; + + public ConnectionLimitMiddleware(ConnectionDelegate next, ServiceContext serviceContext) + { + _next = next; + _serviceContext = serviceContext; + } + + public Task OnConnectionAsync(ConnectionContext connection) + { + if (!_serviceContext.ConnectionManager.NormalConnectionCount.TryLockOne()) + { + KestrelEventSource.Log.ConnectionRejected(connection.ConnectionId); + _serviceContext.Log.ConnectionRejected(connection.ConnectionId); + connection.Transport.Input.Complete(); + connection.Transport.Output.Complete(); + return Task.CompletedTask; + } + + return _next(connection); + } + } +} diff --git a/src/Kestrel.Core/Internal/FrameConnection.cs b/src/Kestrel.Core/Internal/FrameConnection.cs index e1b2dbde37..f11c6102a1 100644 --- a/src/Kestrel.Core/Internal/FrameConnection.cs +++ b/src/Kestrel.Core/Internal/FrameConnection.cs @@ -11,7 +11,6 @@ using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Hosting.Server; using Microsoft.AspNetCore.Http.Features; -using Microsoft.AspNetCore.Protocols.Features; using Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal; using Microsoft.AspNetCore.Server.Kestrel.Core.Features; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; @@ -21,14 +20,14 @@ using Microsoft.Extensions.Logging; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal { - public class FrameConnection : IConnectionApplicationFeature, ITimeoutControl + public class FrameConnection : ITimeoutControl { private const int Http2ConnectionNotStarted = 0; private const int Http2ConnectionStarted = 1; private const int Http2ConnectionClosed = 2; private readonly FrameConnectionContext _context; - private List _adaptedConnections; + private IList _adaptedConnections; private readonly TaskCompletionSource _socketClosedTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); private Frame _frame; private Http2Connection _http2Connection; @@ -62,8 +61,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal public bool TimedOut { get; private set; } public string ConnectionId => _context.ConnectionId; - public IPipeWriter Input => _context.Input.Writer; - public IPipeReader Output => _context.Output.Reader; public IPEndPoint LocalEndPoint => _context.LocalEndPoint; public IPEndPoint RemoteEndPoint => _context.RemoteEndPoint; @@ -88,14 +85,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal private IKestrelTrace Log => _context.ServiceContext.Log; - public IPipeConnection Connection { get; set; } - - public void StartRequestProcessing(IHttpApplication application) + public Task StartRequestProcessing(IHttpApplication application) { - _lifetimeTask = ProcessRequestsAsync(application); + return _lifetimeTask = ProcessRequestsAsync(application); } - private async Task ProcessRequestsAsync(IHttpApplication application) + private async Task ProcessRequestsAsync(IHttpApplication httpApplication) { using (BeginConnectionScope()) { @@ -106,23 +101,22 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal AdaptedPipeline adaptedPipeline = null; var adaptedPipelineTask = Task.CompletedTask; - var input = _context.Input.Reader; - var output = _context.Output; + var transport = _context.Transport; + var application = _context.Application; + if (_context.ConnectionAdapters.Count > 0) { - adaptedPipeline = new AdaptedPipeline(input, - output, - PipeFactory.Create(AdaptedInputPipeOptions), - PipeFactory.Create(AdaptedOutputPipeOptions), - Log); + adaptedPipeline = new AdaptedPipeline(transport, + application, + PipeFactory.Create(AdaptedInputPipeOptions), + PipeFactory.Create(AdaptedOutputPipeOptions)); - input = adaptedPipeline.Input.Reader; - output = adaptedPipeline.Output; + transport = adaptedPipeline; } // _frame must be initialized before adding the connection to the connection manager - CreateFrame(application, input, output); + CreateFrame(httpApplication, transport, application); // _http2Connection must be initialized before yield control to the transport thread, // to prevent a race condition where _http2Connection.Abort() is called just as @@ -130,12 +124,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal _http2Connection = new Http2Connection(new Http2ConnectionContext { ConnectionId = _context.ConnectionId, - ServiceContext = _context.ServiceContext, + ServiceContext = _context.ServiceContext, PipeFactory = PipeFactory, LocalEndPoint = LocalEndPoint, RemoteEndPoint = RemoteEndPoint, - Input = input, - Output = output + Application = application, + Transport = transport }); // Do this before the first await so we don't yield control to the transport until we've @@ -153,7 +147,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal if (_frame.ConnectionFeatures?.Get()?.ApplicationProtocol == "h2" && Interlocked.CompareExchange(ref _http2ConnectionState, Http2ConnectionStarted, Http2ConnectionNotStarted) == Http2ConnectionNotStarted) { - await _http2Connection.ProcessAsync(application); + await _http2Connection.ProcessAsync(httpApplication); } else { @@ -187,9 +181,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal } } - internal void CreateFrame(IHttpApplication application, IPipeReader input, IPipe output) + internal void CreateFrame(IHttpApplication httpApplication, IPipeConnection transport, IPipeConnection application) { - _frame = new Frame(application, new FrameContext + _frame = new Frame(httpApplication, new FrameContext { ConnectionId = _context.ConnectionId, PipeFactory = PipeFactory, @@ -197,8 +191,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal RemoteEndPoint = RemoteEndPoint, ServiceContext = _context.ServiceContext, TimeoutControl = this, - Input = input, - Output = output + Transport = transport, + Application = application }); } @@ -268,7 +262,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal var features = new FeatureCollection(); var connectionAdapters = _context.ConnectionAdapters; - var stream = new RawStream(_context.Input.Reader, _context.Output.Writer); + var stream = new RawStream(_context.Transport.Input, _context.Transport.Output); var adapterContext = new ConnectionAdapterContext(features, stream); _adaptedConnections = new List(connectionAdapters.Count); diff --git a/src/Kestrel.Core/Internal/FrameConnectionContext.cs b/src/Kestrel.Core/Internal/FrameConnectionContext.cs index 57b08141f3..5f5c5c2dfa 100644 --- a/src/Kestrel.Core/Internal/FrameConnectionContext.cs +++ b/src/Kestrel.Core/Internal/FrameConnectionContext.cs @@ -13,12 +13,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal public string ConnectionId { get; set; } public long FrameConnectionId { get; set; } public ServiceContext ServiceContext { get; set; } - public List ConnectionAdapters { get; set; } + public IList ConnectionAdapters { get; set; } public PipeFactory PipeFactory { get; set; } public IPEndPoint LocalEndPoint { get; set; } public IPEndPoint RemoteEndPoint { get; set; } - - public IPipe Input { get; set; } - public IPipe Output { get; set; } + public IPipeConnection Transport { get; set; } + public IPipeConnection Application { get; set; } } } diff --git a/src/Kestrel.Core/Internal/Http/Frame.cs b/src/Kestrel.Core/Internal/Http/Frame.cs index bdced76b67..1debda07d0 100644 --- a/src/Kestrel.Core/Internal/Http/Frame.cs +++ b/src/Kestrel.Core/Internal/Http/Frame.cs @@ -96,7 +96,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http _keepAliveTicks = ServerOptions.Limits.KeepAliveTimeout.Ticks; _requestHeadersTimeoutTicks = ServerOptions.Limits.RequestHeadersTimeout.Ticks; - Output = new OutputProducer(frameContext.Output, frameContext.ConnectionId, frameContext.ServiceContext.Log, TimeoutControl); + Output = new OutputProducer(frameContext.Application.Input, frameContext.Transport.Output, frameContext.ConnectionId, frameContext.ServiceContext.Log, TimeoutControl); RequestBodyPipe = CreateRequestBodyPipe(); } @@ -107,7 +107,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http private IPEndPoint RemoteEndPoint => _frameContext.RemoteEndPoint; public IFeatureCollection ConnectionFeatures { get; set; } - public IPipeReader Input => _frameContext.Input; + public IPipeReader Input => _frameContext.Transport.Input; public OutputProducer Output { get; } public ITimeoutControl TimeoutControl => _frameContext.TimeoutControl; diff --git a/src/Kestrel.Core/Internal/Http/FrameContext.cs b/src/Kestrel.Core/Internal/Http/FrameContext.cs index 67274af488..5a52c03ea5 100644 --- a/src/Kestrel.Core/Internal/Http/FrameContext.cs +++ b/src/Kestrel.Core/Internal/Http/FrameContext.cs @@ -16,7 +16,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http public IPEndPoint RemoteEndPoint { get; set; } public IPEndPoint LocalEndPoint { get; set; } public ITimeoutControl TimeoutControl { get; set; } - public IPipeReader Input { get; set; } - public IPipe Output { get; set; } + public IPipeConnection Transport { get; set; } + public IPipeConnection Application { get; set; } } } diff --git a/src/Kestrel.Core/Internal/Http/OutputProducer.cs b/src/Kestrel.Core/Internal/Http/OutputProducer.cs index b44af9f1b7..2bd85c9047 100644 --- a/src/Kestrel.Core/Internal/Http/OutputProducer.cs +++ b/src/Kestrel.Core/Internal/Http/OutputProducer.cs @@ -24,7 +24,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http private bool _completed = false; - private readonly IPipe _pipe; + private readonly IPipeWriter _pipeWriter; + private readonly IPipeReader _outputPipeReader; // https://github.com/dotnet/corefxlab/issues/1334 // Pipelines don't support multiple awaiters on flush @@ -34,12 +35,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http private Action _flushCompleted; public OutputProducer( - IPipe pipe, + IPipeReader outputPipeReader, + IPipeWriter pipeWriter, string connectionId, IKestrelTrace log, ITimeoutControl timeoutControl) { - _pipe = pipe; + _outputPipeReader = outputPipeReader; + _pipeWriter = pipeWriter; _connectionId = connectionId; _timeoutControl = timeoutControl; _log = log; @@ -70,7 +73,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http return; } - var buffer = _pipe.Writer.Alloc(1); + var buffer = _pipeWriter.Alloc(1); callback(buffer, state); buffer.Commit(); } @@ -87,7 +90,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http _log.ConnectionDisconnect(_connectionId); _completed = true; - _pipe.Writer.Complete(); + _pipeWriter.Complete(); } } @@ -103,8 +106,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http _log.ConnectionDisconnect(_connectionId); _completed = true; - _pipe.Reader.CancelPendingRead(); - _pipe.Writer.Complete(error); + _outputPipeReader.CancelPendingRead(); + _pipeWriter.Complete(error); } } @@ -122,7 +125,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http return Task.CompletedTask; } - writableBuffer = _pipe.Writer.Alloc(1); + writableBuffer = _pipeWriter.Alloc(1); var writer = new WritableBufferWriter(writableBuffer); if (buffer.Count > 0) { diff --git a/src/Kestrel.Core/Internal/Http2/Http2Connection.cs b/src/Kestrel.Core/Internal/Http2/Http2Connection.cs index 4e3476d104..5419790ff2 100644 --- a/src/Kestrel.Core/Internal/Http2/Http2Connection.cs +++ b/src/Kestrel.Core/Internal/Http2/Http2Connection.cs @@ -40,13 +40,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 public Http2Connection(Http2ConnectionContext context) { _context = context; - _frameWriter = new Http2FrameWriter(context.Output); + _frameWriter = new Http2FrameWriter(context.Transport.Output, context.Application.Input); _hpackDecoder = new HPackDecoder(); } public string ConnectionId => _context.ConnectionId; - public IPipeReader Input => _context.Input; + public IPipeReader Input => _context.Transport.Input; public IKestrelTrace Log => _context.ServiceContext.Log; diff --git a/src/Kestrel.Core/Internal/Http2/Http2ConnectionContext.cs b/src/Kestrel.Core/Internal/Http2/Http2ConnectionContext.cs index ff22a1afb0..2956040b16 100644 --- a/src/Kestrel.Core/Internal/Http2/Http2ConnectionContext.cs +++ b/src/Kestrel.Core/Internal/Http2/Http2ConnectionContext.cs @@ -14,7 +14,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 public IPEndPoint LocalEndPoint { get; set; } public IPEndPoint RemoteEndPoint { get; set; } - public IPipeReader Input { get; set; } - public IPipe Output { get; set; } + public IPipeConnection Transport { get; set; } + public IPipeConnection Application { get; set; } } } diff --git a/src/Kestrel.Core/Internal/Http2/Http2FrameWriter.cs b/src/Kestrel.Core/Internal/Http2/Http2FrameWriter.cs index 698f6a19c5..6623f489b8 100644 --- a/src/Kestrel.Core/Internal/Http2/Http2FrameWriter.cs +++ b/src/Kestrel.Core/Internal/Http2/Http2FrameWriter.cs @@ -19,13 +19,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 private readonly Http2Frame _outgoingFrame = new Http2Frame(); private readonly object _writeLock = new object(); private readonly HPackEncoder _hpackEncoder = new HPackEncoder(); - private readonly IPipe _output; + private readonly IPipeWriter _outputWriter; + private readonly IPipeReader _outputReader; private bool _completed; - public Http2FrameWriter(IPipe output) + public Http2FrameWriter(IPipeWriter outputPipeWriter, IPipeReader outputPipeReader) { - _output = output; + _outputWriter = outputPipeWriter; + _outputReader = outputPipeReader; } public void Abort(Exception ex) @@ -33,8 +35,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 lock (_writeLock) { _completed = true; - _output.Reader.CancelPendingRead(); - _output.Writer.Complete(ex); + _outputReader.CancelPendingRead(); + _outputWriter.Complete(ex); } } @@ -173,7 +175,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 return; } - var writeableBuffer = _output.Writer.Alloc(1); + var writeableBuffer = _outputWriter.Alloc(1); writeableBuffer.Write(data); await writeableBuffer.FlushAsync(cancellationToken); } diff --git a/src/Kestrel.Core/Internal/HttpConnectionBuilderExtensions.cs b/src/Kestrel.Core/Internal/HttpConnectionBuilderExtensions.cs new file mode 100644 index 0000000000..ca3ca5c9ab --- /dev/null +++ b/src/Kestrel.Core/Internal/HttpConnectionBuilderExtensions.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Text; +using Microsoft.AspNetCore.Hosting.Server; +using Microsoft.AspNetCore.Protocols; +using Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal; + +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal +{ + public static class HttpConnectionBuilderExtensions + { + public static IConnectionBuilder UseHttpServer(this IConnectionBuilder builder, ServiceContext serviceContext, IHttpApplication application) + { + return builder.UseHttpServer(Array.Empty(), serviceContext, application); + } + + public static IConnectionBuilder UseHttpServer(this IConnectionBuilder builder, IList adapters, ServiceContext serviceContext, IHttpApplication application) + { + var middleware = new HttpConnectionMiddleware(adapters, serviceContext, application); + return builder.Use(next => + { + return middleware.OnConnectionAsync; + }); + } + } +} diff --git a/src/Kestrel.Core/Internal/HttpConnectionMiddleware.cs b/src/Kestrel.Core/Internal/HttpConnectionMiddleware.cs new file mode 100644 index 0000000000..e79658de2c --- /dev/null +++ b/src/Kestrel.Core/Internal/HttpConnectionMiddleware.cs @@ -0,0 +1,91 @@ +using System.Collections.Generic; +using System.Net; +using System.Threading; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Hosting.Server; +using Microsoft.AspNetCore.Http.Features; +using Microsoft.AspNetCore.Protocols; +using Microsoft.AspNetCore.Protocols.Features; +using Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal; + +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal +{ + public class HttpConnectionMiddleware + { + private static long _lastFrameConnectionId = long.MinValue; + + private readonly IList _connectionAdapters; + private readonly ServiceContext _serviceContext; + private readonly IHttpApplication _application; + + public HttpConnectionMiddleware(IList adapters, ServiceContext serviceContext, IHttpApplication application) + { + _serviceContext = serviceContext; + _application = application; + + // Keeping these around for now so progress can be made without updating tests + _connectionAdapters = adapters; + } + + public Task OnConnectionAsync(ConnectionContext connectionContext) + { + // We need the transport feature so that we can cancel the output reader that the transport is using + // This is a bit of a hack but it preserves the existing semantics + var transportFeature = connectionContext.Features.Get(); + + var frameConnectionId = Interlocked.Increment(ref _lastFrameConnectionId); + + var frameConnectionContext = new FrameConnectionContext + { + ConnectionId = connectionContext.ConnectionId, + FrameConnectionId = frameConnectionId, + ServiceContext = _serviceContext, + PipeFactory = connectionContext.PipeFactory, + ConnectionAdapters = _connectionAdapters, + Transport = connectionContext.Transport, + Application = transportFeature.Application + }; + + var connectionFeature = connectionContext.Features.Get(); + + if (connectionFeature != null) + { + if (connectionFeature.LocalIpAddress != null) + { + frameConnectionContext.LocalEndPoint = new IPEndPoint(connectionFeature.LocalIpAddress, connectionFeature.LocalPort); + } + + if (connectionFeature.RemoteIpAddress != null) + { + frameConnectionContext.RemoteEndPoint = new IPEndPoint(connectionFeature.RemoteIpAddress, connectionFeature.RemotePort); + } + } + + var connection = new FrameConnection(frameConnectionContext); + + // The order here is important, start request processing so that + // the frame is created before this yields. Events need to be wired up + // afterwards + var processingTask = connection.StartRequestProcessing(_application); + + // Wire up the events an forward calls to the frame connection + // It's important that these execute synchronously because graceful + // connection close is order sensative (for now) + connectionContext.ConnectionAborted.ContinueWith((task, state) => + { + // Unwrap the aggregate exception + ((FrameConnection)state).Abort(task.Exception?.InnerException); + }, + connection, TaskContinuationOptions.ExecuteSynchronously); + + connectionContext.ConnectionClosed.ContinueWith((task, state) => + { + // Unwrap the aggregate exception + ((FrameConnection)state).OnConnectionClosed(task.Exception?.InnerException); + }, + connection, TaskContinuationOptions.ExecuteSynchronously); + + return processingTask; + } + } +} diff --git a/src/Kestrel.Core/Internal/RejectionConnection.cs b/src/Kestrel.Core/Internal/RejectionConnection.cs deleted file mode 100644 index 776a637258..0000000000 --- a/src/Kestrel.Core/Internal/RejectionConnection.cs +++ /dev/null @@ -1,47 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using System.IO.Pipelines; -using Microsoft.AspNetCore.Protocols.Features; -using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; - -namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal -{ - public class RejectionConnection : IConnectionApplicationFeature - { - private readonly IKestrelTrace _log; - private readonly IPipe _input; - private readonly IPipe _output; - - public RejectionConnection(IPipe input, IPipe output, string connectionId, ServiceContext serviceContext) - { - ConnectionId = connectionId; - _log = serviceContext.Log; - _input = input; - _output = output; - } - - public string ConnectionId { get; } - public IPipeWriter Input => _input.Writer; - public IPipeReader Output => _output.Reader; - - public IPipeConnection Connection { get; set; } - - public void Reject() - { - KestrelEventSource.Log.ConnectionRejected(ConnectionId); - _log.ConnectionRejected(ConnectionId); - _input.Reader.Complete(); - _output.Writer.Complete(); - } - - void IConnectionApplicationFeature.OnConnectionClosed(Exception ex) - { - } - - void IConnectionApplicationFeature.Abort(Exception ex) - { - } - } -} \ No newline at end of file diff --git a/src/Kestrel.Core/KestrelServer.cs b/src/Kestrel.Core/KestrelServer.cs index e52e3895ce..a1f5864f97 100644 --- a/src/Kestrel.Core/KestrelServer.cs +++ b/src/Kestrel.Core/KestrelServer.cs @@ -135,7 +135,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core async Task OnBind(ListenOptions endpoint) { - var connectionHandler = new ConnectionHandler(endpoint, ServiceContext, application); + // Add the connection limit middleware + endpoint.UseConnectionLimit(ServiceContext); + + // Configure the user delegate + endpoint.Configure(endpoint); + + // Add the HTTP middleware as the terminal connection middleware + endpoint.UseHttpServer(endpoint.ConnectionAdapters, ServiceContext, application); + + var connectionHandler = new ConnectionHandler(ServiceContext, endpoint.Build()); var transport = _transportFactory.Create(endpoint, connectionHandler); _transports.Add(transport); diff --git a/src/Kestrel.Core/KestrelServerOptions.cs b/src/Kestrel.Core/KestrelServerOptions.cs index 136b983533..6a33639710 100644 --- a/src/Kestrel.Core/KestrelServerOptions.cs +++ b/src/Kestrel.Core/KestrelServerOptions.cs @@ -100,8 +100,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core throw new ArgumentNullException(nameof(configure)); } - var listenOptions = new ListenOptions(endPoint) { KestrelServerOptions = this }; - configure(listenOptions); + var listenOptions = new ListenOptions(endPoint) { KestrelServerOptions = this, Configure = configure }; ListenOptions.Add(listenOptions); } @@ -132,8 +131,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core throw new ArgumentNullException(nameof(configure)); } - var listenOptions = new ListenOptions(socketPath) { KestrelServerOptions = this }; - configure(listenOptions); + var listenOptions = new ListenOptions(socketPath) { KestrelServerOptions = this, Configure = configure }; ListenOptions.Add(listenOptions); } @@ -156,8 +154,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core throw new ArgumentNullException(nameof(configure)); } - var listenOptions = new ListenOptions(handle) { KestrelServerOptions = this }; - configure(listenOptions); + var listenOptions = new ListenOptions(handle) { KestrelServerOptions = this, Configure = configure }; ListenOptions.Add(listenOptions); } } diff --git a/src/Kestrel.Core/ListenOptions.cs b/src/Kestrel.Core/ListenOptions.cs index 46bae7fba3..f1f66209a2 100644 --- a/src/Kestrel.Core/ListenOptions.cs +++ b/src/Kestrel.Core/ListenOptions.cs @@ -5,6 +5,8 @@ using System; using System.Collections.Generic; using System.Linq; using System.Net; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Protocols; using Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal; using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; @@ -14,9 +16,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core /// Describes either an , Unix domain socket path, or a file descriptor for an already open /// socket that Kestrel should bind to or open. /// - public class ListenOptions : IEndPointInformation + public class ListenOptions : IEndPointInformation, IConnectionBuilder { private FileHandleType _handleType; + private readonly List> _components = new List>(); internal ListenOptions(IPEndPoint endPoint) { @@ -126,6 +129,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core /// public List ConnectionAdapters { get; } = new List(); + public IServiceProvider ApplicationServices => KestrelServerOptions?.ApplicationServices; + + internal Action Configure { get; set; } = _ => { }; + /// /// Gets the name of this endpoint to display on command-line when the web server starts. /// @@ -149,5 +156,27 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core } public override string ToString() => GetDisplayName(); + + public IConnectionBuilder Use(Func middleware) + { + _components.Add(middleware); + return this; + } + + public ConnectionDelegate Build() + { + ConnectionDelegate app = context => + { + return Task.CompletedTask; + }; + + for (int i = _components.Count - 1; i >= 0; i--) + { + var component = _components[i]; + app = component(app); + } + + return app; + } } } diff --git a/src/Kestrel.Transport.Abstractions/Internal/TransportConnection.Features.cs b/src/Kestrel.Transport.Abstractions/Internal/TransportConnection.Features.cs index fd5d60050b..7a8cd3ce29 100644 --- a/src/Kestrel.Transport.Abstractions/Internal/TransportConnection.Features.cs +++ b/src/Kestrel.Transport.Abstractions/Internal/TransportConnection.Features.cs @@ -3,7 +3,7 @@ using System.Collections; using System.Collections.Generic; using System.IO.Pipelines; using System.Net; -using System.Text; +using System.Threading.Tasks; using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Protocols.Features; @@ -17,12 +17,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal private static readonly Type IHttpConnectionFeatureType = typeof(IHttpConnectionFeature); private static readonly Type IConnectionIdFeatureType = typeof(IConnectionIdFeature); private static readonly Type IConnectionTransportFeatureType = typeof(IConnectionTransportFeature); - private static readonly Type IConnectionApplicationFeatureType = typeof(IConnectionApplicationFeature); private object _currentIHttpConnectionFeature; private object _currentIConnectionIdFeature; private object _currentIConnectionTransportFeature; - private object _currentIConnectionApplicationFeature; private int _featureRevision; @@ -99,12 +97,28 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal PipeFactory IConnectionTransportFeature.PipeFactory => PipeFactory; - IPipeConnection IConnectionTransportFeature.Connection + IPipeConnection IConnectionTransportFeature.Transport { get => Transport; set => Transport = value; } + IPipeConnection IConnectionTransportFeature.Application + { + get => Application; + set => Application = value; + } + + Task IConnectionTransportFeature.ConnectionAborted + { + get => _abortTcs.Task; + } + + Task IConnectionTransportFeature.ConnectionClosed + { + get => _closedTcs.Task; + } + object IFeatureCollection.this[Type key] { get => FastFeatureGet(key); @@ -142,11 +156,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal return _currentIConnectionTransportFeature; } - if (key == IConnectionApplicationFeatureType) - { - return _currentIConnectionApplicationFeature; - } - return ExtraFeatureGet(key); } @@ -172,12 +181,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal return; } - if (key == IConnectionApplicationFeatureType) - { - _currentIConnectionApplicationFeature = feature; - return; - } - ExtraFeatureSet(key, feature); } @@ -198,11 +201,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal yield return new KeyValuePair(IConnectionTransportFeatureType, _currentIConnectionTransportFeature); } - if (_currentIConnectionApplicationFeature != null) - { - yield return new KeyValuePair(IConnectionApplicationFeatureType, _currentIConnectionApplicationFeature); - } - if (MaybeExtra != null) { foreach (var item in MaybeExtra) diff --git a/src/Kestrel.Transport.Abstractions/Internal/TransportConnection.cs b/src/Kestrel.Transport.Abstractions/Internal/TransportConnection.cs index a499dc8e6a..a447fae39c 100644 --- a/src/Kestrel.Transport.Abstractions/Internal/TransportConnection.cs +++ b/src/Kestrel.Transport.Abstractions/Internal/TransportConnection.cs @@ -1,14 +1,15 @@ using System; -using System.Collections.Generic; using System.IO.Pipelines; using System.Net; -using System.Text; -using Microsoft.AspNetCore.Protocols.Features; +using System.Threading.Tasks; namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal { public abstract partial class TransportConnection { + private readonly TaskCompletionSource _abortTcs = new TaskCompletionSource(); + private readonly TaskCompletionSource _closedTcs = new TaskCompletionSource(); + public TransportConnection() { _currentIConnectionIdFeature = this; @@ -28,6 +29,30 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal public virtual IScheduler OutputReaderScheduler { get; } public IPipeConnection Transport { get; set; } - public IConnectionApplicationFeature Application => (IConnectionApplicationFeature)_currentIConnectionApplicationFeature; + public IPipeConnection Application { get; set; } + + protected void Abort(Exception exception) + { + if (exception == null) + { + _abortTcs.TrySetResult(null); + } + else + { + _abortTcs.TrySetException(exception); + } + } + + protected void Close(Exception exception) + { + if (exception == null) + { + _closedTcs.TrySetResult(null); + } + else + { + _closedTcs.TrySetException(exception); + } + } } } diff --git a/src/Kestrel.Transport.Libuv/Internal/LibuvConnection.cs b/src/Kestrel.Transport.Libuv/Internal/LibuvConnection.cs index db47620cd8..1ed08a309e 100644 --- a/src/Kestrel.Transport.Libuv/Internal/LibuvConnection.cs +++ b/src/Kestrel.Transport.Libuv/Internal/LibuvConnection.cs @@ -46,8 +46,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal } } - public IPipeWriter Input => Application.Connection.Output; - public IPipeReader Output => Application.Connection.Input; + public IPipeWriter Input => Application.Output; + public IPipeReader Output => Application.Input; public LibuvOutputConsumer OutputConsumer { get; set; } @@ -83,7 +83,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal // Now, complete the input so that no more reads can happen Input.Complete(error ?? new ConnectionAbortedException()); Output.Complete(error); - Application.OnConnectionClosed(error); + Close(error); // Make sure it isn't possible for a paused read to resume reading after calling uv_close // on the stream handle @@ -178,7 +178,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal } } - Application.Abort(error); + Abort(error); // Complete after aborting the connection Input.Complete(error); } @@ -216,7 +216,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal Log.ConnectionReadFin(ConnectionId); var error = new IOException(ex.Message, ex); - Application.Abort(error); + Abort(error); Input.Complete(error); } } diff --git a/src/Kestrel.Transport.Sockets/SocketConnection.cs b/src/Kestrel.Transport.Sockets/SocketConnection.cs index 86f5df0d4f..e39e605d6a 100644 --- a/src/Kestrel.Transport.Sockets/SocketConnection.cs +++ b/src/Kestrel.Transport.Sockets/SocketConnection.cs @@ -48,8 +48,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets { connectionHandler.OnConnection(this); - _input = Application.Connection.Output; - _output = Application.Connection.Input; + _input = Application.Output; + _output = Application.Input; // Spawn send and receive logic Task receiveTask = DoReceive(); @@ -135,7 +135,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets } finally { - Application.Abort(error); + Abort(error); _input.Complete(error); } } @@ -229,7 +229,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets } finally { - Application.OnConnectionClosed(error); + Close(error); _output.Complete(error); } } diff --git a/src/Protocols.Abstractions/ConnectionContext.cs b/src/Protocols.Abstractions/ConnectionContext.cs index ebbcb458a1..c10a884f48 100644 --- a/src/Protocols.Abstractions/ConnectionContext.cs +++ b/src/Protocols.Abstractions/ConnectionContext.cs @@ -1,5 +1,7 @@ using System; using System.IO.Pipelines; +using System.Threading; +using System.Threading.Tasks; using Microsoft.AspNetCore.Http.Features; namespace Microsoft.AspNetCore.Protocols @@ -13,5 +15,9 @@ namespace Microsoft.AspNetCore.Protocols public abstract IPipeConnection Transport { get; set; } public abstract PipeFactory PipeFactory { get; } + + public abstract Task ConnectionAborted { get; } + + public abstract Task ConnectionClosed { get; } } } diff --git a/src/Protocols.Abstractions/DefaultConnectionContext.cs b/src/Protocols.Abstractions/DefaultConnectionContext.cs index 0a759630bf..814d4470f7 100644 --- a/src/Protocols.Abstractions/DefaultConnectionContext.cs +++ b/src/Protocols.Abstractions/DefaultConnectionContext.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.IO.Pipelines; using System.Text; +using System.Threading.Tasks; using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Protocols.Features; @@ -34,10 +35,14 @@ namespace Microsoft.AspNetCore.Protocols public override IPipeConnection Transport { - get => ConnectionTransportFeature.Connection; - set => ConnectionTransportFeature.Connection = value; + get => ConnectionTransportFeature.Transport; + set => ConnectionTransportFeature.Transport = value; } + public override Task ConnectionAborted => ConnectionTransportFeature.ConnectionAborted; + + public override Task ConnectionClosed => ConnectionTransportFeature.ConnectionClosed; + struct FeatureInterfaces { public IConnectionIdFeature ConnectionId; diff --git a/src/Protocols.Abstractions/Features/IConnectionApplicationFeature.cs b/src/Protocols.Abstractions/Features/IConnectionApplicationFeature.cs deleted file mode 100644 index a610cd06d6..0000000000 --- a/src/Protocols.Abstractions/Features/IConnectionApplicationFeature.cs +++ /dev/null @@ -1,18 +0,0 @@ -using System; -using System.IO.Pipelines; - -namespace Microsoft.AspNetCore.Protocols.Features -{ - public interface IConnectionApplicationFeature - { - IPipeConnection Connection { get; set; } - - // TODO: Remove these (https://github.com/aspnet/KestrelHttpServer/issues/1772) - // REVIEW: These are around for now because handling pipe events messes with the order - // of operations an that breaks tons of tests. Instead, we preserve the existing semantics - // and ordering. - void Abort(Exception exception); - - void OnConnectionClosed(Exception exception); - } -} diff --git a/src/Protocols.Abstractions/Features/IConnectionTransportFeature.cs b/src/Protocols.Abstractions/Features/IConnectionTransportFeature.cs index 463797265e..e9cccb4a3e 100644 --- a/src/Protocols.Abstractions/Features/IConnectionTransportFeature.cs +++ b/src/Protocols.Abstractions/Features/IConnectionTransportFeature.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.IO.Pipelines; using System.Text; +using System.Threading.Tasks; namespace Microsoft.AspNetCore.Protocols.Features { @@ -9,10 +10,16 @@ namespace Microsoft.AspNetCore.Protocols.Features { PipeFactory PipeFactory { get; } - IPipeConnection Connection { get; set; } + IPipeConnection Transport { get; set; } + + IPipeConnection Application { get; set; } IScheduler InputWriterScheduler { get; } IScheduler OutputReaderScheduler { get; } + + Task ConnectionAborted { get; } + + Task ConnectionClosed { get; } } } diff --git a/src/Protocols.Abstractions/PipeFactoryExtensions.cs b/src/Protocols.Abstractions/PipeFactoryExtensions.cs new file mode 100644 index 0000000000..9ded8a8f9d --- /dev/null +++ b/src/Protocols.Abstractions/PipeFactoryExtensions.cs @@ -0,0 +1,21 @@ +namespace System.IO.Pipelines +{ + public static class PipeFactoryExtensions + { + public static (IPipeConnection Transport, IPipeConnection Application) CreateConnectionPair(this PipeFactory pipeFactory) + { + return pipeFactory.CreateConnectionPair(new PipeOptions(), new PipeOptions()); + } + + public static (IPipeConnection Transport, IPipeConnection Application) CreateConnectionPair(this PipeFactory pipeFactory, PipeOptions inputOptions, PipeOptions outputOptions) + { + var input = pipeFactory.Create(inputOptions); + var output = pipeFactory.Create(outputOptions); + + var transportToApplication = new PipeConnection(output.Reader, input.Writer); + var applicationToTransport = new PipeConnection(input.Reader, output.Writer); + + return (applicationToTransport, transportToApplication); + } + } +} diff --git a/test/Kestrel.Core.Tests/FrameConnectionTests.cs b/test/Kestrel.Core.Tests/FrameConnectionTests.cs index 1891872223..e77de9b870 100644 --- a/test/Kestrel.Core.Tests/FrameConnectionTests.cs +++ b/test/Kestrel.Core.Tests/FrameConnectionTests.cs @@ -25,6 +25,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests public FrameConnectionTests() { _pipeFactory = new PipeFactory(); + var pair = _pipeFactory.CreateConnectionPair(); _frameConnectionContext = new FrameConnectionContext { @@ -32,8 +33,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests ConnectionAdapters = new List(), PipeFactory = _pipeFactory, FrameConnectionId = long.MinValue, - Input = _pipeFactory.Create(), - Output = _pipeFactory.Create(), + Application = pair.Application, + Transport = pair.Transport, ServiceContext = new TestServiceContext { SystemClock = new SystemClock() @@ -54,7 +55,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests var mockDebugger = new Mock(); mockDebugger.SetupGet(g => g.IsAttached).Returns(true); _frameConnection.Debugger = mockDebugger.Object; - _frameConnection.CreateFrame(new DummyApplication(), _frameConnectionContext.Input.Reader, _frameConnectionContext.Output); + _frameConnection.CreateFrame(new DummyApplication(), _frameConnectionContext.Transport, _frameConnectionContext.Application); var now = DateTimeOffset.Now; _frameConnection.Tick(now); @@ -101,7 +102,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests _frameConnectionContext.ServiceContext.Log = logger; - _frameConnection.CreateFrame(new DummyApplication(), _frameConnectionContext.Input.Reader, _frameConnectionContext.Output); + _frameConnection.CreateFrame(new DummyApplication(), _frameConnectionContext.Transport, _frameConnectionContext.Application); _frameConnection.Frame.Reset(); // Initialize timestamp @@ -128,7 +129,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests var mockLogger = new Mock(); _frameConnectionContext.ServiceContext.Log = mockLogger.Object; - _frameConnection.CreateFrame(new DummyApplication(), _frameConnectionContext.Input.Reader, _frameConnectionContext.Output); + _frameConnection.CreateFrame(new DummyApplication(), _frameConnectionContext.Transport, _frameConnectionContext.Application); _frameConnection.Frame.Reset(); // Initialize timestamp @@ -170,7 +171,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests var mockLogger = new Mock(); _frameConnectionContext.ServiceContext.Log = mockLogger.Object; - _frameConnection.CreateFrame(new DummyApplication(), _frameConnectionContext.Input.Reader, _frameConnectionContext.Output); + _frameConnection.CreateFrame(new DummyApplication(), _frameConnectionContext.Transport, _frameConnectionContext.Application); _frameConnection.Frame.Reset(); // Initialize timestamp @@ -247,7 +248,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests var mockLogger = new Mock(); _frameConnectionContext.ServiceContext.Log = mockLogger.Object; - _frameConnection.CreateFrame(new DummyApplication(), _frameConnectionContext.Input.Reader, _frameConnectionContext.Output); + _frameConnection.CreateFrame(new DummyApplication(), _frameConnectionContext.Transport, _frameConnectionContext.Application); _frameConnection.Frame.Reset(); // Initialize timestamp @@ -315,7 +316,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests var mockLogger = new Mock(); _frameConnectionContext.ServiceContext.Log = mockLogger.Object; - _frameConnection.CreateFrame(new DummyApplication(), _frameConnectionContext.Input.Reader, _frameConnectionContext.Output); + _frameConnection.CreateFrame(new DummyApplication(), _frameConnectionContext.Transport, _frameConnectionContext.Application); _frameConnection.Frame.Reset(); // Initialize timestamp @@ -377,7 +378,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests var mockLogger = new Mock(); _frameConnectionContext.ServiceContext.Log = mockLogger.Object; - _frameConnection.CreateFrame(new DummyApplication(), _frameConnectionContext.Input.Reader, _frameConnectionContext.Output); + _frameConnection.CreateFrame(new DummyApplication(), _frameConnectionContext.Transport, _frameConnectionContext.Application); _frameConnection.Frame.Reset(); var startTime = systemClock.UtcNow; @@ -418,7 +419,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests var mockLogger = new Mock(); _frameConnectionContext.ServiceContext.Log = mockLogger.Object; - _frameConnection.CreateFrame(new DummyApplication(), _frameConnectionContext.Input.Reader, _frameConnectionContext.Output); + _frameConnection.CreateFrame(new DummyApplication(), _frameConnectionContext.Transport, _frameConnectionContext.Application); _frameConnection.Frame.Reset(); _frameConnection.Frame.RequestAborted.Register(() => { @@ -452,7 +453,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests var mockLogger = new Mock(); _frameConnectionContext.ServiceContext.Log = mockLogger.Object; - _frameConnection.CreateFrame(new DummyApplication(), _frameConnectionContext.Input.Reader, _frameConnectionContext.Output); + _frameConnection.CreateFrame(new DummyApplication(), _frameConnectionContext.Transport, _frameConnectionContext.Application); _frameConnection.Frame.Reset(); _frameConnection.Frame.RequestAborted.Register(() => { @@ -494,7 +495,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests var mockLogger = new Mock(); _frameConnectionContext.ServiceContext.Log = mockLogger.Object; - _frameConnection.CreateFrame(new DummyApplication(), _frameConnectionContext.Input.Reader, _frameConnectionContext.Output); + _frameConnection.CreateFrame(new DummyApplication(), _frameConnectionContext.Transport, _frameConnectionContext.Application); _frameConnection.Frame.Reset(); _frameConnection.Frame.RequestAborted.Register(() => { @@ -531,7 +532,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests [Fact] public async Task StartRequestProcessingCreatesLogScopeWithConnectionId() { - _frameConnection.StartRequestProcessing(new DummyApplication()); + _ = _frameConnection.StartRequestProcessing(new DummyApplication()); var scopeObjects = ((TestKestrelTrace)_frameConnectionContext.ServiceContext.Log) .Logger diff --git a/test/Kestrel.Core.Tests/FrameResponseHeadersTests.cs b/test/Kestrel.Core.Tests/FrameResponseHeadersTests.cs index 8cd807bc18..7c3dfa0f08 100644 --- a/test/Kestrel.Core.Tests/FrameResponseHeadersTests.cs +++ b/test/Kestrel.Core.Tests/FrameResponseHeadersTests.cs @@ -18,10 +18,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests [Fact] public void InitialDictionaryIsEmpty() { + var factory = new PipeFactory(); + var pair = factory.CreateConnectionPair(); var frameContext = new FrameContext { ServiceContext = new TestServiceContext(), - PipeFactory = new PipeFactory(), + PipeFactory = factory, + Application = pair.Application, + Transport = pair.Transport, TimeoutControl = null }; diff --git a/test/Kestrel.Core.Tests/FrameTests.cs b/test/Kestrel.Core.Tests/FrameTests.cs index d5f14333bf..2910bedc14 100644 --- a/test/Kestrel.Core.Tests/FrameTests.cs +++ b/test/Kestrel.Core.Tests/FrameTests.cs @@ -27,7 +27,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests { public class FrameTests : IDisposable { - private readonly IPipe _input; + private readonly IPipeConnection _transport; + private readonly IPipeConnection _application; private readonly TestFrame _frame; private readonly ServiceContext _serviceContext; private readonly FrameContext _frameContext; @@ -52,8 +53,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests public FrameTests() { _pipelineFactory = new PipeFactory(); - _input = _pipelineFactory.Create(); - var output = _pipelineFactory.Create(); + var pair = _pipelineFactory.CreateConnectionPair(); + + _transport = pair.Transport; + _application = pair.Application; _serviceContext = new TestServiceContext(); _timeoutControl = new Mock(); @@ -62,8 +65,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests ServiceContext = _serviceContext, PipeFactory = _pipelineFactory, TimeoutControl = _timeoutControl.Object, - Input = _input.Reader, - Output = output + Application = pair.Application, + Transport = pair.Transport }; _frame = new TestFrame(application: null, context: _frameContext); @@ -72,8 +75,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests public void Dispose() { - _input.Reader.Complete(); - _input.Writer.Complete(); + _transport.Input.Complete(); + _application.Output.Complete(); + + _application.Input.Complete(); + _application.Output.Complete(); + _pipelineFactory.Dispose(); } @@ -84,11 +91,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests _serviceContext.ServerOptions.Limits.MaxRequestHeadersTotalSize = headerLine.Length - 1; _frame.Reset(); - await _input.Writer.WriteAsync(Encoding.ASCII.GetBytes($"{headerLine}\r\n")); - var readableBuffer = (await _input.Reader.ReadAsync()).Buffer; + await _application.Output.WriteAsync(Encoding.ASCII.GetBytes($"{headerLine}\r\n")); + var readableBuffer = (await _transport.Input.ReadAsync()).Buffer; var exception = Assert.Throws(() => _frame.TakeMessageHeaders(readableBuffer, out _consumed, out _examined)); - _input.Reader.Advance(_consumed, _examined); + _transport.Input.Advance(_consumed, _examined); Assert.Equal(CoreStrings.BadRequest_HeadersExceedMaxTotalSize, exception.Message); Assert.Equal(StatusCodes.Status431RequestHeaderFieldsTooLarge, exception.StatusCode); @@ -100,11 +107,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests const string headerLines = "Header-1: value1\r\nHeader-2: value2\r\n"; _serviceContext.ServerOptions.Limits.MaxRequestHeaderCount = 1; - await _input.Writer.WriteAsync(Encoding.ASCII.GetBytes($"{headerLines}\r\n")); - var readableBuffer = (await _input.Reader.ReadAsync()).Buffer; + await _application.Output.WriteAsync(Encoding.ASCII.GetBytes($"{headerLines}\r\n")); + var readableBuffer = (await _transport.Input.ReadAsync()).Buffer; var exception = Assert.Throws(() => _frame.TakeMessageHeaders(readableBuffer, out _consumed, out _examined)); - _input.Reader.Advance(_consumed, _examined); + _transport.Input.Advance(_consumed, _examined); Assert.Equal(CoreStrings.BadRequest_TooManyHeaders, exception.Message); Assert.Equal(StatusCodes.Status431RequestHeaderFieldsTooLarge, exception.StatusCode); @@ -205,11 +212,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests options.Limits.MaxRequestHeaderCount = 1; _serviceContext.ServerOptions = options; - await _input.Writer.WriteAsync(Encoding.ASCII.GetBytes($"{headerLine1}\r\n")); - var readableBuffer = (await _input.Reader.ReadAsync()).Buffer; + await _application.Output.WriteAsync(Encoding.ASCII.GetBytes($"{headerLine1}\r\n")); + var readableBuffer = (await _transport.Input.ReadAsync()).Buffer; var takeMessageHeaders = _frame.TakeMessageHeaders(readableBuffer, out _consumed, out _examined); - _input.Reader.Advance(_consumed, _examined); + _transport.Input.Advance(_consumed, _examined); Assert.True(takeMessageHeaders); Assert.Equal(1, _frame.RequestHeaders.Count); @@ -217,11 +224,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests _frame.Reset(); - await _input.Writer.WriteAsync(Encoding.ASCII.GetBytes($"{headerLine2}\r\n")); - readableBuffer = (await _input.Reader.ReadAsync()).Buffer; + await _application.Output.WriteAsync(Encoding.ASCII.GetBytes($"{headerLine2}\r\n")); + readableBuffer = (await _transport.Input.ReadAsync()).Buffer; takeMessageHeaders = _frame.TakeMessageHeaders(readableBuffer, out _consumed, out _examined); - _input.Reader.Advance(_consumed, _examined); + _transport.Input.Advance(_consumed, _examined); Assert.True(takeMessageHeaders); Assert.Equal(1, _frame.RequestHeaders.Count); @@ -332,8 +339,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests string requestLine, string expectedMethod, string expectedRawTarget, -// This warns that theory methods should use all of their parameters, -// but this method is using a shared data collection with HttpParserTests.ParsesRequestLine and others. + // This warns that theory methods should use all of their parameters, + // but this method is using a shared data collection with HttpParserTests.ParsesRequestLine and others. #pragma warning disable xUnit1026 string expectedRawPath, #pragma warning restore xUnit1026 @@ -342,11 +349,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests string expectedHttpVersion) { var requestLineBytes = Encoding.ASCII.GetBytes(requestLine); - await _input.Writer.WriteAsync(requestLineBytes); - var readableBuffer = (await _input.Reader.ReadAsync()).Buffer; + await _application.Output.WriteAsync(requestLineBytes); + var readableBuffer = (await _transport.Input.ReadAsync()).Buffer; var returnValue = _frame.TakeStartLine(readableBuffer, out _consumed, out _examined); - _input.Reader.Advance(_consumed, _examined); + _transport.Input.Advance(_consumed, _examined); Assert.True(returnValue); Assert.Equal(expectedMethod, _frame.Method); @@ -365,11 +372,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests string expectedQueryString) { var requestLineBytes = Encoding.ASCII.GetBytes(requestLine); - await _input.Writer.WriteAsync(requestLineBytes); - var readableBuffer = (await _input.Reader.ReadAsync()).Buffer; + await _application.Output.WriteAsync(requestLineBytes); + var readableBuffer = (await _transport.Input.ReadAsync()).Buffer; var returnValue = _frame.TakeStartLine(readableBuffer, out _consumed, out _examined); - _input.Reader.Advance(_consumed, _examined); + _transport.Input.Advance(_consumed, _examined); Assert.True(returnValue); Assert.Equal(expectedRawTarget, _frame.RawTarget); @@ -380,10 +387,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests [Fact] public async Task ParseRequestStartsRequestHeadersTimeoutOnFirstByteAvailable() { - await _input.Writer.WriteAsync(Encoding.ASCII.GetBytes("G")); + await _application.Output.WriteAsync(Encoding.ASCII.GetBytes("G")); - _frame.ParseRequest((await _input.Reader.ReadAsync()).Buffer, out _consumed, out _examined); - _input.Reader.Advance(_consumed, _examined); + _frame.ParseRequest((await _transport.Input.ReadAsync()).Buffer, out _consumed, out _examined); + _transport.Input.Advance(_consumed, _examined); var expectedRequestHeadersTimeout = _serviceContext.ServerOptions.Limits.RequestHeadersTimeout.Ticks; _timeoutControl.Verify(cc => cc.ResetTimeout(expectedRequestHeadersTimeout, TimeoutAction.SendTimeoutResponse)); @@ -395,11 +402,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests _serviceContext.ServerOptions.Limits.MaxRequestLineSize = "GET / HTTP/1.1\r\n".Length; var requestLineBytes = Encoding.ASCII.GetBytes("GET /a HTTP/1.1\r\n"); - await _input.Writer.WriteAsync(requestLineBytes); + await _application.Output.WriteAsync(requestLineBytes); - var readableBuffer = (await _input.Reader.ReadAsync()).Buffer; + var readableBuffer = (await _transport.Input.ReadAsync()).Buffer; var exception = Assert.Throws(() => _frame.TakeStartLine(readableBuffer, out _consumed, out _examined)); - _input.Reader.Advance(_consumed, _examined); + _transport.Input.Advance(_consumed, _examined); Assert.Equal(CoreStrings.BadRequest_RequestLineTooLong, exception.Message); Assert.Equal(StatusCodes.Status414UriTooLong, exception.StatusCode); @@ -409,12 +416,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests [MemberData(nameof(TargetWithEncodedNullCharData))] public async Task TakeStartLineThrowsOnEncodedNullCharInTarget(string target) { - await _input.Writer.WriteAsync(Encoding.ASCII.GetBytes($"GET {target} HTTP/1.1\r\n")); - var readableBuffer = (await _input.Reader.ReadAsync()).Buffer; + await _application.Output.WriteAsync(Encoding.ASCII.GetBytes($"GET {target} HTTP/1.1\r\n")); + var readableBuffer = (await _transport.Input.ReadAsync()).Buffer; var exception = Assert.Throws(() => _frame.TakeStartLine(readableBuffer, out _consumed, out _examined)); - _input.Reader.Advance(_consumed, _examined); + _transport.Input.Advance(_consumed, _examined); Assert.Equal(CoreStrings.FormatBadRequest_InvalidRequestTarget_Detail(target), exception.Message); } @@ -423,12 +430,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests [MemberData(nameof(TargetWithNullCharData))] public async Task TakeStartLineThrowsOnNullCharInTarget(string target) { - await _input.Writer.WriteAsync(Encoding.ASCII.GetBytes($"GET {target} HTTP/1.1\r\n")); - var readableBuffer = (await _input.Reader.ReadAsync()).Buffer; + await _application.Output.WriteAsync(Encoding.ASCII.GetBytes($"GET {target} HTTP/1.1\r\n")); + var readableBuffer = (await _transport.Input.ReadAsync()).Buffer; var exception = Assert.Throws(() => _frame.TakeStartLine(readableBuffer, out _consumed, out _examined)); - _input.Reader.Advance(_consumed, _examined); + _transport.Input.Advance(_consumed, _examined); Assert.Equal(CoreStrings.FormatBadRequest_InvalidRequestTarget_Detail(target.EscapeNonPrintable()), exception.Message); } @@ -439,12 +446,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests { var requestLine = $"{method} / HTTP/1.1\r\n"; - await _input.Writer.WriteAsync(Encoding.ASCII.GetBytes(requestLine)); - var readableBuffer = (await _input.Reader.ReadAsync()).Buffer; + await _application.Output.WriteAsync(Encoding.ASCII.GetBytes(requestLine)); + var readableBuffer = (await _transport.Input.ReadAsync()).Buffer; var exception = Assert.Throws(() => _frame.TakeStartLine(readableBuffer, out _consumed, out _examined)); - _input.Reader.Advance(_consumed, _examined); + _transport.Input.Advance(_consumed, _examined); Assert.Equal(CoreStrings.FormatBadRequest_InvalidRequestLine_Detail(requestLine.EscapeNonPrintable()), exception.Message); } @@ -455,12 +462,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests { var target = $"/{queryString}"; - await _input.Writer.WriteAsync(Encoding.ASCII.GetBytes($"GET {target} HTTP/1.1\r\n")); - var readableBuffer = (await _input.Reader.ReadAsync()).Buffer; + await _application.Output.WriteAsync(Encoding.ASCII.GetBytes($"GET {target} HTTP/1.1\r\n")); + var readableBuffer = (await _transport.Input.ReadAsync()).Buffer; var exception = Assert.Throws(() => _frame.TakeStartLine(readableBuffer, out _consumed, out _examined)); - _input.Reader.Advance(_consumed, _examined); + _transport.Input.Advance(_consumed, _examined); Assert.Equal(CoreStrings.FormatBadRequest_InvalidRequestTarget_Detail(target.EscapeNonPrintable()), exception.Message); } @@ -471,12 +478,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests { var requestLine = $"{method} {target} HTTP/1.1\r\n"; - await _input.Writer.WriteAsync(Encoding.ASCII.GetBytes(requestLine)); - var readableBuffer = (await _input.Reader.ReadAsync()).Buffer; + await _application.Output.WriteAsync(Encoding.ASCII.GetBytes(requestLine)); + var readableBuffer = (await _transport.Input.ReadAsync()).Buffer; var exception = Assert.Throws(() => _frame.TakeStartLine(readableBuffer, out _consumed, out _examined)); - _input.Reader.Advance(_consumed, _examined); + _transport.Input.Advance(_consumed, _examined); Assert.Equal(CoreStrings.FormatBadRequest_InvalidRequestTarget_Detail(target.EscapeNonPrintable()), exception.Message); } @@ -485,12 +492,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests [MemberData(nameof(MethodNotAllowedTargetData))] public async Task TakeStartLineThrowsWhenMethodNotAllowed(string requestLine, HttpMethod allowedMethod) { - await _input.Writer.WriteAsync(Encoding.ASCII.GetBytes(requestLine)); - var readableBuffer = (await _input.Reader.ReadAsync()).Buffer; + await _application.Output.WriteAsync(Encoding.ASCII.GetBytes(requestLine)); + var readableBuffer = (await _transport.Input.ReadAsync()).Buffer; var exception = Assert.Throws(() => _frame.TakeStartLine(readableBuffer, out _consumed, out _examined)); - _input.Reader.Advance(_consumed, _examined); + _transport.Input.Advance(_consumed, _examined); Assert.Equal(405, exception.StatusCode); Assert.Equal(CoreStrings.BadRequest_MethodNotAllowed, exception.Message); @@ -506,7 +513,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests _timeoutControl.Verify(cc => cc.SetTimeout(expectedKeepAliveTimeout, TimeoutAction.CloseConnection)); _frame.Stop(); - _input.Writer.Complete(); + _application.Output.Complete(); requestProcessingTask.Wait(); } @@ -588,13 +595,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests var requestProcessingTask = _frame.ProcessRequestsAsync(); var data = Encoding.ASCII.GetBytes("GET / HTTP/1.1\r\nHost:\r\n\r\n"); - await _input.Writer.WriteAsync(data); + await _application.Output.WriteAsync(data); _frame.Stop(); Assert.IsNotType>(requestProcessingTask); await requestProcessingTask.TimeoutAfter(TimeSpan.FromSeconds(10)); - _input.Writer.Complete(); + _application.Output.Complete(); } [Fact] @@ -684,12 +691,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests _serviceContext.Log = mockTrace.Object; - await _input.Writer.WriteAsync(Encoding.ASCII.GetBytes($"GET /%00 HTTP/1.1\r\n")); - var readableBuffer = (await _input.Reader.ReadAsync()).Buffer; + await _application.Output.WriteAsync(Encoding.ASCII.GetBytes($"GET /%00 HTTP/1.1\r\n")); + var readableBuffer = (await _transport.Input.ReadAsync()).Buffer; var exception = Assert.Throws(() => _frame.TakeStartLine(readableBuffer, out _consumed, out _examined)); - _input.Reader.Advance(_consumed, _examined); + _transport.Input.Advance(_consumed, _examined); Assert.Equal(CoreStrings.FormatBadRequest_InvalidRequestTarget_Detail(string.Empty), exception.Message); Assert.Equal(StatusCodes.Status400BadRequest, exception.StatusCode); @@ -716,19 +723,19 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests var requestProcessingTask = _frame.ProcessRequestsAsync(); - await _input.Writer.WriteAsync(Encoding.ASCII.GetBytes("GET / HTTP/1.0\r\n")); + await _application.Output.WriteAsync(Encoding.ASCII.GetBytes("GET / HTTP/1.0\r\n")); await WaitForCondition(TimeSpan.FromSeconds(1), () => _frame.RequestHeaders != null); Assert.Equal(0, _frame.RequestHeaders.Count); - await _input.Writer.WriteAsync(Encoding.ASCII.GetBytes(headers0)); + await _application.Output.WriteAsync(Encoding.ASCII.GetBytes(headers0)); await WaitForCondition(TimeSpan.FromSeconds(1), () => _frame.RequestHeaders.Count >= header0Count); Assert.Equal(header0Count, _frame.RequestHeaders.Count); - await _input.Writer.WriteAsync(Encoding.ASCII.GetBytes(headers1)); + await _application.Output.WriteAsync(Encoding.ASCII.GetBytes(headers1)); await WaitForCondition(TimeSpan.FromSeconds(1), () => _frame.RequestHeaders.Count >= header0Count + header1Count); Assert.Equal(header0Count + header1Count, _frame.RequestHeaders.Count); - await _input.Writer.WriteAsync(Encoding.ASCII.GetBytes("\r\n")); + await _application.Output.WriteAsync(Encoding.ASCII.GetBytes("\r\n")); Assert.Equal(header0Count + header1Count, _frame.RequestHeaders.Count); await requestProcessingTask.TimeoutAfter(TimeSpan.FromSeconds(10)); @@ -750,7 +757,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests var requestProcessingTask = _frame.ProcessRequestsAsync(); - await _input.Writer.WriteAsync(Encoding.ASCII.GetBytes("GET / HTTP/1.0\r\n")); + await _application.Output.WriteAsync(Encoding.ASCII.GetBytes("GET / HTTP/1.0\r\n")); await WaitForCondition(TimeSpan.FromSeconds(1), () => _frame.RequestHeaders != null); Assert.Equal(0, _frame.RequestHeaders.Count); @@ -758,17 +765,17 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests _frame.RequestHeaders = newRequestHeaders; Assert.Same(newRequestHeaders, _frame.RequestHeaders); - await _input.Writer.WriteAsync(Encoding.ASCII.GetBytes(headers0)); + await _application.Output.WriteAsync(Encoding.ASCII.GetBytes(headers0)); await WaitForCondition(TimeSpan.FromSeconds(1), () => _frame.RequestHeaders.Count >= header0Count); Assert.Same(newRequestHeaders, _frame.RequestHeaders); Assert.Equal(header0Count, _frame.RequestHeaders.Count); - await _input.Writer.WriteAsync(Encoding.ASCII.GetBytes(headers1)); + await _application.Output.WriteAsync(Encoding.ASCII.GetBytes(headers1)); await WaitForCondition(TimeSpan.FromSeconds(1), () => _frame.RequestHeaders.Count >= header0Count + header1Count); Assert.Same(newRequestHeaders, _frame.RequestHeaders); Assert.Equal(header0Count + header1Count, _frame.RequestHeaders.Count); - await _input.Writer.WriteAsync(Encoding.ASCII.GetBytes("\r\n")); + await _application.Output.WriteAsync(Encoding.ASCII.GetBytes("\r\n")); Assert.Same(newRequestHeaders, _frame.RequestHeaders); Assert.Equal(header0Count + header1Count, _frame.RequestHeaders.Count); diff --git a/test/Kestrel.Core.Tests/Http2ConnectionTests.cs b/test/Kestrel.Core.Tests/Http2ConnectionTests.cs index 0e1e4668fc..67743cad1f 100644 --- a/test/Kestrel.Core.Tests/Http2ConnectionTests.cs +++ b/test/Kestrel.Core.Tests/Http2ConnectionTests.cs @@ -73,8 +73,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests private static readonly byte[] _noData = new byte[0]; private readonly PipeFactory _pipeFactory = new PipeFactory(); - private readonly IPipe _inputPipe; - private readonly IPipe _outputPipe; + private readonly (IPipeConnection Transport, IPipeConnection Application) _pair; private readonly Http2ConnectionContext _connectionContext; private readonly Http2Connection _connection; private readonly HPackEncoder _hpackEncoder = new HPackEncoder(); @@ -99,8 +98,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests public Http2ConnectionTests() { - _inputPipe = _pipeFactory.Create(); - _outputPipe = _pipeFactory.Create(); + _pair = _pipeFactory.CreateConnectionPair(); _noopApplication = context => Task.CompletedTask; @@ -213,8 +211,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests { ServiceContext = new TestServiceContext(), PipeFactory = _pipeFactory, - Input = _inputPipe.Reader, - Output = _outputPipe + Application = _pair.Application, + Transport = _pair.Transport }; _connection = new Http2Connection(_connectionContext); } @@ -1201,7 +1199,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests private async Task SendAsync(ArraySegment span) { - var writableBuffer = _inputPipe.Writer.Alloc(1); + var writableBuffer = _pair.Application.Output.Alloc(1); writableBuffer.Write(span); await writableBuffer.FlushAsync(); } @@ -1413,7 +1411,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests while (true) { - var result = await _outputPipe.Reader.ReadAsync(); + var result = await _pair.Application.Input.ReadAsync(); var buffer = result.Buffer; var consumed = buffer.Start; var examined = buffer.End; @@ -1429,7 +1427,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests } finally { - _outputPipe.Reader.Advance(consumed, examined); + _pair.Application.Input.Advance(consumed, examined); } } } @@ -1456,7 +1454,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests private Task StopConnectionAsync(int expectedLastStreamId, bool ignoreNonGoAwayFrames) { - _inputPipe.Writer.Complete(); + _pair.Application.Output.Complete(); return WaitForConnectionStopAsync(expectedLastStreamId, ignoreNonGoAwayFrames); } @@ -1486,7 +1484,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests Assert.Equal(expectedErrorCode, frame.GoAwayErrorCode); await _connectionTask; - _inputPipe.Writer.Complete(); + _pair.Application.Output.Complete(); } private async Task WaitForStreamErrorAsync(int expectedStreamId, Http2ErrorCode expectedErrorCode, bool ignoreNonRstStreamFrames) diff --git a/test/Kestrel.Core.Tests/KestrelServerOptionsTests.cs b/test/Kestrel.Core.Tests/KestrelServerOptionsTests.cs index f0209cbea4..b34f92a1d4 100644 --- a/test/Kestrel.Core.Tests/KestrelServerOptionsTests.cs +++ b/test/Kestrel.Core.Tests/KestrelServerOptionsTests.cs @@ -2,7 +2,6 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Net; -using Microsoft.AspNetCore.Server.Kestrel.Core; using Xunit; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests @@ -19,6 +18,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests d.NoDelay = false; }); + // Execute the callback + o1.ListenOptions[1].Configure(o1.ListenOptions[1]); + Assert.True(o1.ListenOptions[0].NoDelay); Assert.False(o1.ListenOptions[1].NoDelay); } diff --git a/test/Kestrel.Core.Tests/MessageBodyTests.cs b/test/Kestrel.Core.Tests/MessageBodyTests.cs index c6d2283301..0d5a11ee27 100644 --- a/test/Kestrel.Core.Tests/MessageBodyTests.cs +++ b/test/Kestrel.Core.Tests/MessageBodyTests.cs @@ -445,7 +445,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests // The block returned by IncomingStart always has at least 2048 available bytes, // so no need to bounds check in this test. var bytes = Encoding.ASCII.GetBytes(data[0]); - var buffer = input.Pipe.Writer.Alloc(2048); + var buffer = input.Application.Output.Alloc(2048); ArraySegment block; Assert.True(buffer.Buffer.TryGetArray(out block)); Buffer.BlockCopy(bytes, 0, block.Array, block.Offset, bytes.Length); @@ -457,7 +457,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests writeTcs = new TaskCompletionSource(); bytes = Encoding.ASCII.GetBytes(data[1]); - buffer = input.Pipe.Writer.Alloc(2048); + buffer = input.Application.Output.Alloc(2048); Assert.True(buffer.Buffer.TryGetArray(out block)); Buffer.BlockCopy(bytes, 0, block.Array, block.Offset, bytes.Length); buffer.Advance(bytes.Length); @@ -467,7 +467,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests if (headers.HeaderConnection == "close") { - input.Pipe.Writer.Complete(); + input.Application.Output.Complete(); } await copyToAsyncTask; @@ -516,7 +516,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests input.Add("a"); Assert.Equal(1, await stream.ReadAsync(new byte[1], 0, 1)); - input.Pipe.Reader.CancelPendingRead(); + input.Transport.Input.CancelPendingRead(); // Add more input and verify is read input.Add("b"); diff --git a/test/Kestrel.Core.Tests/OutputProducerTests.cs b/test/Kestrel.Core.Tests/OutputProducerTests.cs index d539a4012c..f95b13052e 100644 --- a/test/Kestrel.Core.Tests/OutputProducerTests.cs +++ b/test/Kestrel.Core.Tests/OutputProducerTests.cs @@ -55,7 +55,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests var pipe = _pipeFactory.Create(pipeOptions); var serviceContext = new TestServiceContext(); var socketOutput = new OutputProducer( - pipe, + pipe.Reader, + pipe.Writer, "0", serviceContext.Log, Mock.Of()); diff --git a/test/Kestrel.Core.Tests/PipeOptionsTests.cs b/test/Kestrel.Core.Tests/PipeOptionsTests.cs index d35ac3c8a4..2d0db7c073 100644 --- a/test/Kestrel.Core.Tests/PipeOptionsTests.cs +++ b/test/Kestrel.Core.Tests/PipeOptionsTests.cs @@ -1,7 +1,9 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System.Collections.Generic; using System.IO.Pipelines; +using Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; using Microsoft.AspNetCore.Testing; @@ -22,9 +24,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests serviceContext.ServerOptions.Limits.MaxResponseBufferSize = maxResponseBufferSize; serviceContext.ThreadPool = new LoggingThreadPool(null); - var connectionHandler = new ConnectionHandler(listenOptions: null, serviceContext: serviceContext, application: null); var mockScheduler = Mock.Of(); - var outputPipeOptions = connectionHandler.GetOutputPipeOptions(readerScheduler: mockScheduler); + var outputPipeOptions = ConnectionHandler.GetOutputPipeOptions(serviceContext, readerScheduler: mockScheduler); Assert.Equal(expectedMaximumSizeLow, outputPipeOptions.MaximumSizeLow); Assert.Equal(expectedMaximumSizeHigh, outputPipeOptions.MaximumSizeHigh); @@ -41,9 +42,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests serviceContext.ServerOptions.Limits.MaxRequestBufferSize = maxRequestBufferSize; serviceContext.ThreadPool = new LoggingThreadPool(null); - var connectionHandler = new ConnectionHandler(listenOptions: null, serviceContext: serviceContext, application: null); var mockScheduler = Mock.Of(); - var inputPipeOptions = connectionHandler.GetInputPipeOptions(writerScheduler: mockScheduler); + var inputPipeOptions = ConnectionHandler.GetInputPipeOptions(serviceContext, writerScheduler: mockScheduler); Assert.Equal(expectedMaximumSizeLow, inputPipeOptions.MaximumSizeLow); Assert.Equal(expectedMaximumSizeHigh, inputPipeOptions.MaximumSizeHigh); diff --git a/test/Kestrel.Core.Tests/TestInput.cs b/test/Kestrel.Core.Tests/TestInput.cs index 018dcb1117..220f9393cd 100644 --- a/test/Kestrel.Core.Tests/TestInput.cs +++ b/test/Kestrel.Core.Tests/TestInput.cs @@ -20,12 +20,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests { _memoryPool = new MemoryPool(); _pipelineFactory = new PipeFactory(); - Pipe = _pipelineFactory.Create(); + var pair = _pipelineFactory.CreateConnectionPair(); + Transport = pair.Transport; + Application = pair.Application; FrameContext = new FrameContext { ServiceContext = new TestServiceContext(), - Input = Pipe.Reader, + Application = Application, + Transport = Transport, PipeFactory = _pipelineFactory, TimeoutControl = Mock.Of() }; @@ -34,28 +37,30 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests Frame.FrameControl = Mock.Of(); } - public IPipe Pipe { get; } + public IPipeConnection Transport { get; } + + public IPipeConnection Application { get; } public PipeFactory PipeFactory => _pipelineFactory; - public FrameContext FrameContext { get; } + public FrameContext FrameContext { get; } public Frame Frame { get; set; } public void Add(string text) { var data = Encoding.ASCII.GetBytes(text); - Pipe.Writer.WriteAsync(data).Wait(); + Application.Output.WriteAsync(data).Wait(); } public void Fin() { - Pipe.Writer.Complete(); + Application.Output.Complete(); } public void Cancel() { - Pipe.Reader.CancelPendingRead(); + Transport.Input.CancelPendingRead(); } public void Dispose() diff --git a/test/Kestrel.FunctionalTests/RequestTests.cs b/test/Kestrel.FunctionalTests/RequestTests.cs index 0177877722..3a55e9a4cf 100644 --- a/test/Kestrel.FunctionalTests/RequestTests.cs +++ b/test/Kestrel.FunctionalTests/RequestTests.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Concurrent; +using System.Diagnostics; using System.Globalization; using System.IO; using System.Linq; @@ -37,7 +38,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { private const int _connectionStartedEventId = 1; private const int _connectionResetEventId = 19; - private const int _semaphoreWaitTimeout = 2500; + private static readonly int _semaphoreWaitTimeout = Debugger.IsAttached ? 10000 : 2500; private readonly ITestOutputHelper _output; diff --git a/test/Kestrel.Transport.Libuv.Tests/LibuvOutputConsumerTests.cs b/test/Kestrel.Transport.Libuv.Tests/LibuvOutputConsumerTests.cs index 5bf0ff1b3a..cd604be6f1 100644 --- a/test/Kestrel.Transport.Libuv.Tests/LibuvOutputConsumerTests.cs +++ b/test/Kestrel.Transport.Libuv.Tests/LibuvOutputConsumerTests.cs @@ -683,7 +683,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests private OutputProducer CreateOutputProducer(PipeOptions pipeOptions, CancellationTokenSource cts = null) { - var pipe = _pipeFactory.Create(pipeOptions); + var pair = _pipeFactory.CreateConnectionPair(pipeOptions, pipeOptions); var logger = new TestApplicationErrorLogger(); var serviceContext = new TestServiceContext @@ -694,14 +694,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests var transportContext = new TestLibuvTransportContext { Log = new LibuvTrace(logger) }; var socket = new MockSocket(_mockLibuv, _libuvThread.Loop.ThreadId, transportContext.Log); - var consumer = new LibuvOutputConsumer(pipe.Reader, _libuvThread, socket, "0", transportContext.Log); + var consumer = new LibuvOutputConsumer(pair.Application.Input, _libuvThread, socket, "0", transportContext.Log); var frame = new Frame(null, new FrameContext { ServiceContext = serviceContext, PipeFactory = _pipeFactory, TimeoutControl = Mock.Of(), - Output = pipe + Application = pair.Application, + Transport = pair.Transport }); if (cts != null) @@ -709,7 +710,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests frame.RequestAborted.Register(cts.Cancel); } - var ignore = WriteOutputAsync(consumer, pipe.Reader, frame); + var ignore = WriteOutputAsync(consumer, pair.Application.Input, frame); return frame.Output; } diff --git a/test/Kestrel.Transport.Libuv.Tests/LibuvTransportTests.cs b/test/Kestrel.Transport.Libuv.Tests/LibuvTransportTests.cs index 33c971a4b6..6f3e9126a7 100644 --- a/test/Kestrel.Transport.Libuv.Tests/LibuvTransportTests.cs +++ b/test/Kestrel.Transport.Libuv.Tests/LibuvTransportTests.cs @@ -53,10 +53,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests [MemberData(nameof(ConnectionAdapterData))] public async Task ConnectionCanReadAndWrite(ListenOptions listenOptions) { + var serviceContext = new TestServiceContext(); + listenOptions.UseHttpServer(listenOptions.ConnectionAdapters, serviceContext, new DummyApplication(TestApp.EchoApp)); + var transportContext = new TestLibuvTransportContext() { - ConnectionHandler = new ConnectionHandler(listenOptions, new TestServiceContext(), new DummyApplication(TestApp.EchoApp)) + ConnectionHandler = new ConnectionHandler(serviceContext, listenOptions.Build()) }; + var transport = new LibuvTransport(transportContext, listenOptions); await transport.BindAsync(); diff --git a/test/Kestrel.Transport.Libuv.Tests/ListenerPrimaryTests.cs b/test/Kestrel.Transport.Libuv.Tests/ListenerPrimaryTests.cs index 3d4eea1642..f751fa2de6 100644 --- a/test/Kestrel.Transport.Libuv.Tests/ListenerPrimaryTests.cs +++ b/test/Kestrel.Transport.Libuv.Tests/ListenerPrimaryTests.cs @@ -2,11 +2,13 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Collections.Generic; using System.IO; using System.Linq; using System.Net; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Protocols; using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal; using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; @@ -25,17 +27,20 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests public async Task ConnectionsGetRoundRobinedToSecondaryListeners() { var libuv = new LibuvFunctions(); + var listenOptions = new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0)); var serviceContextPrimary = new TestServiceContext(); var transportContextPrimary = new TestLibuvTransportContext(); - transportContextPrimary.ConnectionHandler = new ConnectionHandler( - listenOptions, serviceContextPrimary, new DummyApplication(c => c.Response.WriteAsync("Primary"))); + var builderPrimary = new ConnectionBuilder(); + builderPrimary.UseHttpServer(serviceContextPrimary, new DummyApplication(c => c.Response.WriteAsync("Primary"))); + transportContextPrimary.ConnectionHandler = new ConnectionHandler(serviceContextPrimary, builderPrimary.Build()); var serviceContextSecondary = new TestServiceContext(); + var builderSecondary = new ConnectionBuilder(); + builderSecondary.UseHttpServer(serviceContextSecondary, new DummyApplication(c => c.Response.WriteAsync("Secondary"))); var transportContextSecondary = new TestLibuvTransportContext(); - transportContextSecondary.ConnectionHandler = new ConnectionHandler( - listenOptions, serviceContextSecondary, new DummyApplication(c => c.Response.WriteAsync("Secondary"))); + transportContextSecondary.ConnectionHandler = new ConnectionHandler(serviceContextSecondary, builderSecondary.Build()); var libuvTransport = new LibuvTransport(libuv, transportContextPrimary, listenOptions); @@ -92,13 +97,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests { var libuv = new LibuvFunctions(); var listenOptions = new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0)); - var logger = new TestApplicationErrorLogger(); var serviceContextPrimary = new TestServiceContext(); + var builderPrimary = new ConnectionBuilder(); + builderPrimary.UseHttpServer(serviceContextPrimary, new DummyApplication(c => c.Response.WriteAsync("Primary"))); var transportContextPrimary = new TestLibuvTransportContext() { Log = new LibuvTrace(logger) }; - transportContextPrimary.ConnectionHandler = new ConnectionHandler( - listenOptions, serviceContextPrimary, new DummyApplication(c => c.Response.WriteAsync("Primary"))); + transportContextPrimary.ConnectionHandler = new ConnectionHandler(serviceContextPrimary, builderPrimary.Build()); var serviceContextSecondary = new TestServiceContext { @@ -107,9 +112,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests ThreadPool = serviceContextPrimary.ThreadPool, HttpParserFactory = serviceContextPrimary.HttpParserFactory, }; + var builderSecondary = new ConnectionBuilder(); + builderSecondary.UseHttpServer(serviceContextSecondary, new DummyApplication(c => c.Response.WriteAsync("Secondary"))); var transportContextSecondary = new TestLibuvTransportContext(); - transportContextSecondary.ConnectionHandler = new ConnectionHandler( - listenOptions, serviceContextSecondary, new DummyApplication(c => c.Response.WriteAsync("Secondary"))); + transportContextSecondary.ConnectionHandler = new ConnectionHandler(serviceContextSecondary, builderSecondary.Build()); var libuvTransport = new LibuvTransport(libuv, transportContextPrimary, listenOptions); @@ -205,9 +211,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests var logger = new TestApplicationErrorLogger(); var serviceContextPrimary = new TestServiceContext(); + var builderPrimary = new ConnectionBuilder(); + builderPrimary.UseHttpServer(serviceContextPrimary, new DummyApplication(c => c.Response.WriteAsync("Primary"))); var transportContextPrimary = new TestLibuvTransportContext() { Log = new LibuvTrace(logger) }; - transportContextPrimary.ConnectionHandler = new ConnectionHandler( - listenOptions, serviceContextPrimary, new DummyApplication(c => c.Response.WriteAsync("Primary"))); + transportContextPrimary.ConnectionHandler = new ConnectionHandler(serviceContextPrimary, builderPrimary.Build()); var serviceContextSecondary = new TestServiceContext { @@ -216,9 +223,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests ThreadPool = serviceContextPrimary.ThreadPool, HttpParserFactory = serviceContextPrimary.HttpParserFactory, }; + var builderSecondary = new ConnectionBuilder(); + builderSecondary.UseHttpServer(serviceContextSecondary, new DummyApplication(c => c.Response.WriteAsync("Secondary"))); var transportContextSecondary = new TestLibuvTransportContext(); - transportContextSecondary.ConnectionHandler = new ConnectionHandler( - listenOptions, serviceContextSecondary, new DummyApplication(c => c.Response.WriteAsync("Secondary"))); + transportContextSecondary.ConnectionHandler = new ConnectionHandler(serviceContextSecondary, builderSecondary.Build()); var libuvTransport = new LibuvTransport(libuv, transportContextPrimary, listenOptions); @@ -300,5 +308,34 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests return new Uri($"{scheme}://{options.IPEndPoint}"); } + + private class ConnectionBuilder : IConnectionBuilder + { + private readonly List> _components = new List>(); + + public IServiceProvider ApplicationServices { get; set; } + + public IConnectionBuilder Use(Func middleware) + { + _components.Add(middleware); + return this; + } + + public ConnectionDelegate Build() + { + ConnectionDelegate app = context => + { + return Task.CompletedTask; + }; + + for (int i = _components.Count - 1; i >= 0; i--) + { + var component = _components[i]; + app = component(app); + } + + return app; + } + } } } diff --git a/test/Kestrel.Transport.Libuv.Tests/TestHelpers/MockConnectionHandler.cs b/test/Kestrel.Transport.Libuv.Tests/TestHelpers/MockConnectionHandler.cs index 5b3480b0e6..ef856124fe 100644 --- a/test/Kestrel.Transport.Libuv.Tests/TestHelpers/MockConnectionHandler.cs +++ b/test/Kestrel.Transport.Libuv.Tests/TestHelpers/MockConnectionHandler.cs @@ -22,29 +22,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests.TestHelpers Input = connectionContext.PipeFactory.Create(InputOptions ?? new PipeOptions()); Output = connectionContext.PipeFactory.Create(OutputOptions ?? new PipeOptions()); - var context = new TestConnectionContext - { - Connection = new PipeConnection(Output.Reader, Input.Writer) - }; + var feature = connectionContext.Features.Get(); - connectionContext.Features.Set(context); + connectionContext.Transport = new PipeConnection(Input.Reader, Output.Writer); + feature.Application = new PipeConnection(Output.Reader, Input.Writer); } public IPipe Input { get; private set; } public IPipe Output { get; private set; } - - private class TestConnectionContext : IConnectionApplicationFeature - { - public string ConnectionId { get; } - public IPipeConnection Connection { get; set; } - - public void Abort(Exception ex) - { - } - - public void OnConnectionClosed(Exception ex) - { - } - } } } From 11a9b6498de2f21dc91881259645ad2994b6b59b Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Tue, 22 Aug 2017 01:01:05 +0100 Subject: [PATCH 1386/1662] Don't alloc IEnumerable in Reset for ITlsConnectionFeature (#2009) * Don't alloc IEnumerable for ITlsConnectionFeature * Delegate to ConnectionFeatures and determine scheme once --- .../Internal/Http/Frame.FeatureCollection.cs | 4 ++-- src/Kestrel.Core/Internal/Http/Frame.cs | 18 ++++++------------ .../Http2/Http2Stream.FeatureCollection.cs | 4 ++-- src/Kestrel.Core/Internal/Http2/Http2Stream.cs | 18 ++++++------------ 4 files changed, 16 insertions(+), 28 deletions(-) diff --git a/src/Kestrel.Core/Internal/Http/Frame.FeatureCollection.cs b/src/Kestrel.Core/Internal/Http/Frame.FeatureCollection.cs index 3cf9d22fac..f2457d0696 100644 --- a/src/Kestrel.Core/Internal/Http/Frame.FeatureCollection.cs +++ b/src/Kestrel.Core/Internal/Http/Frame.FeatureCollection.cs @@ -251,13 +251,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http object IFeatureCollection.this[Type key] { - get => FastFeatureGet(key); + get => FastFeatureGet(key) ?? ConnectionFeatures?[key]; set => FastFeatureSet(key, value); } TFeature IFeatureCollection.Get() { - return (TFeature)FastFeatureGet(typeof(TFeature)); + return (TFeature)(FastFeatureGet(typeof(TFeature)) ?? ConnectionFeatures?[typeof(TFeature)]); } void IFeatureCollection.Set(TFeature instance) diff --git a/src/Kestrel.Core/Internal/Http/Frame.cs b/src/Kestrel.Core/Internal/Http/Frame.cs index 1debda07d0..d8eb4096f8 100644 --- a/src/Kestrel.Core/Internal/Http/Frame.cs +++ b/src/Kestrel.Core/Internal/Http/Frame.cs @@ -83,6 +83,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http private HttpRequestTarget _requestTargetForm = HttpRequestTarget.Unknown; private Uri _absoluteRequestTarget; + private string _scheme = null; public Frame(FrameContext frameContext) { @@ -338,7 +339,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http MaxRequestBodySize = ServerOptions.Limits.MaxRequestBodySize; AllowSynchronousIO = ServerOptions.AllowSynchronousIO; TraceIdentifier = null; - Scheme = null; Method = null; PathBase = null; Path = null; @@ -362,20 +362,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http RequestHeaders = FrameRequestHeaders; ResponseHeaders = FrameResponseHeaders; - if (ConnectionFeatures != null) + if (_scheme == null) { - foreach (var feature in ConnectionFeatures) - { - // Set the scheme to https if there's an ITlsConnectionFeature - if (feature.Key == typeof(ITlsConnectionFeature)) - { - Scheme = "https"; - } - - FastFeatureSet(feature.Key, feature.Value); - } + var tlsFeature = ConnectionFeatures?[typeof(ITlsConnectionFeature)]; + _scheme = tlsFeature != null ? "https" : "http"; } + Scheme = _scheme; + _manuallySetRequestAbortToken = null; _abortedCts = null; diff --git a/src/Kestrel.Core/Internal/Http2/Http2Stream.FeatureCollection.cs b/src/Kestrel.Core/Internal/Http2/Http2Stream.FeatureCollection.cs index 2adb8074d7..c5df791ce8 100644 --- a/src/Kestrel.Core/Internal/Http2/Http2Stream.FeatureCollection.cs +++ b/src/Kestrel.Core/Internal/Http2/Http2Stream.FeatureCollection.cs @@ -246,13 +246,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 object IFeatureCollection.this[Type key] { - get => FastFeatureGet(key); + get => FastFeatureGet(key) ?? ConnectionFeatures?[key]; set => FastFeatureSet(key, value); } TFeature IFeatureCollection.Get() { - return (TFeature)FastFeatureGet(typeof(TFeature)); + return (TFeature)(FastFeatureGet(typeof(TFeature)) ?? ConnectionFeatures?[typeof(TFeature)]); } void IFeatureCollection.Set(TFeature instance) diff --git a/src/Kestrel.Core/Internal/Http2/Http2Stream.cs b/src/Kestrel.Core/Internal/Http2/Http2Stream.cs index 0415cb3449..c7b6b4b3ac 100644 --- a/src/Kestrel.Core/Internal/Http2/Http2Stream.cs +++ b/src/Kestrel.Core/Internal/Http2/Http2Stream.cs @@ -58,6 +58,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 private HttpRequestTarget _requestTargetForm = HttpRequestTarget.Unknown; private Uri _absoluteRequestTarget; + private string _scheme = null; public Http2Stream(Http2StreamContext context) { @@ -248,7 +249,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 MaxRequestBodySize = ServerOptions.Limits.MaxRequestBodySize; AllowSynchronousIO = ServerOptions.AllowSynchronousIO; TraceIdentifier = null; - Scheme = null; Method = null; PathBase = null; Path = null; @@ -271,20 +271,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 RequestHeaders = FrameRequestHeaders; ResponseHeaders = FrameResponseHeaders; - if (ConnectionFeatures != null) + if (_scheme == null) { - foreach (var feature in ConnectionFeatures) - { - // Set the scheme to https if there's an ITlsConnectionFeature - if (feature.Key == typeof(ITlsConnectionFeature)) - { - Scheme = "https"; - } - - FastFeatureSet(feature.Key, feature.Value); - } + var tlsFeature = ConnectionFeatures?[typeof(ITlsConnectionFeature)]; + _scheme = tlsFeature != null ? "https" : "http"; } + Scheme = _scheme; + _manuallySetRequestAbortToken = null; _abortedCts = null; From dc9ed604651e4da99592ba2ccb1c976255c04af3 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Tue, 22 Aug 2017 14:32:58 -0700 Subject: [PATCH 1387/1662] Create the connection logging scope in ConnectionHandler (#2013) - Instead of doing it on the FrameConnection only. This will make sure all middleware logs get the connection id as part of their scope. --- .../Internal/ConnectionHandler.cs | 27 ++- src/Kestrel.Core/Internal/FrameConnection.cs | 163 ++++++++---------- .../ConnectionHandlerTests.cs | 70 ++++++++ .../FrameConnectionTests.cs | 24 --- 4 files changed, 167 insertions(+), 117 deletions(-) create mode 100644 test/Kestrel.Core.Tests/ConnectionHandlerTests.cs diff --git a/src/Kestrel.Core/Internal/ConnectionHandler.cs b/src/Kestrel.Core/Internal/ConnectionHandler.cs index d94de12429..5e3513b5ac 100644 --- a/src/Kestrel.Core/Internal/ConnectionHandler.cs +++ b/src/Kestrel.Core/Internal/ConnectionHandler.cs @@ -24,6 +24,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal _connectionDelegate = connectionDelegate; } + private IKestrelTrace Log => _serviceContext.Log; + public void OnConnection(IFeatureCollection features) { var connectionContext = new DefaultConnectionContext(features); @@ -51,14 +53,31 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal private async Task Execute(ConnectionContext connectionContext) { - try + using (BeginConnectionScope(connectionContext)) { - await _connectionDelegate(connectionContext); + Log.ConnectionStart(connectionContext.ConnectionId); + + try + { + await _connectionDelegate(connectionContext); + } + catch (Exception ex) + { + Log.LogCritical(0, ex, $"{nameof(ConnectionHandler)}.{nameof(Execute)}() {connectionContext.ConnectionId}"); + } + + Log.ConnectionStop(connectionContext.ConnectionId); } - catch (Exception ex) + } + + private IDisposable BeginConnectionScope(ConnectionContext connectionContext) + { + if (Log.IsEnabled(LogLevel.Critical)) { - _serviceContext.Log.LogCritical(0, ex, $"{nameof(ConnectionHandler)}.{nameof(Execute)}() {connectionContext.ConnectionId}"); + return Log.BeginScope(new ConnectionLogScope(connectionContext.ConnectionId)); } + + return null; } // Internal for testing diff --git a/src/Kestrel.Core/Internal/FrameConnection.cs b/src/Kestrel.Core/Internal/FrameConnection.cs index f11c6102a1..f2e3a3e172 100644 --- a/src/Kestrel.Core/Internal/FrameConnection.cs +++ b/src/Kestrel.Core/Internal/FrameConnection.cs @@ -92,92 +92,87 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal private async Task ProcessRequestsAsync(IHttpApplication httpApplication) { - using (BeginConnectionScope()) + try { - try + KestrelEventSource.Log.ConnectionStart(this); + + AdaptedPipeline adaptedPipeline = null; + var adaptedPipelineTask = Task.CompletedTask; + var transport = _context.Transport; + var application = _context.Application; + + + if (_context.ConnectionAdapters.Count > 0) { - Log.ConnectionStart(ConnectionId); - KestrelEventSource.Log.ConnectionStart(this); + adaptedPipeline = new AdaptedPipeline(transport, + application, + PipeFactory.Create(AdaptedInputPipeOptions), + PipeFactory.Create(AdaptedOutputPipeOptions)); - AdaptedPipeline adaptedPipeline = null; - var adaptedPipelineTask = Task.CompletedTask; - var transport = _context.Transport; - var application = _context.Application; - - - if (_context.ConnectionAdapters.Count > 0) - { - adaptedPipeline = new AdaptedPipeline(transport, - application, - PipeFactory.Create(AdaptedInputPipeOptions), - PipeFactory.Create(AdaptedOutputPipeOptions)); - - transport = adaptedPipeline; - } - - // _frame must be initialized before adding the connection to the connection manager - CreateFrame(httpApplication, transport, application); - - // _http2Connection must be initialized before yield control to the transport thread, - // to prevent a race condition where _http2Connection.Abort() is called just as - // _http2Connection is about to be initialized. - _http2Connection = new Http2Connection(new Http2ConnectionContext - { - ConnectionId = _context.ConnectionId, - ServiceContext = _context.ServiceContext, - PipeFactory = PipeFactory, - LocalEndPoint = LocalEndPoint, - RemoteEndPoint = RemoteEndPoint, - Application = application, - Transport = transport - }); - - // Do this before the first await so we don't yield control to the transport until we've - // added the connection to the connection manager - _context.ServiceContext.ConnectionManager.AddConnection(_context.FrameConnectionId, this); - _lastTimestamp = _context.ServiceContext.SystemClock.UtcNow.Ticks; - - if (adaptedPipeline != null) - { - // Stream can be null here and run async will close the connection in that case - var stream = await ApplyConnectionAdaptersAsync(); - adaptedPipelineTask = adaptedPipeline.RunAsync(stream); - } - - if (_frame.ConnectionFeatures?.Get()?.ApplicationProtocol == "h2" && - Interlocked.CompareExchange(ref _http2ConnectionState, Http2ConnectionStarted, Http2ConnectionNotStarted) == Http2ConnectionNotStarted) - { - await _http2Connection.ProcessAsync(httpApplication); - } - else - { - await _frame.ProcessRequestsAsync(); - } - - await adaptedPipelineTask; - await _socketClosedTcs.Task; + transport = adaptedPipeline; } - catch (Exception ex) + + // _frame must be initialized before adding the connection to the connection manager + CreateFrame(httpApplication, transport, application); + + // _http2Connection must be initialized before yield control to the transport thread, + // to prevent a race condition where _http2Connection.Abort() is called just as + // _http2Connection is about to be initialized. + _http2Connection = new Http2Connection(new Http2ConnectionContext { - Log.LogError(0, ex, $"Unexpected exception in {nameof(FrameConnection)}.{nameof(ProcessRequestsAsync)}."); - } - finally + ConnectionId = _context.ConnectionId, + ServiceContext = _context.ServiceContext, + PipeFactory = PipeFactory, + LocalEndPoint = LocalEndPoint, + RemoteEndPoint = RemoteEndPoint, + Application = application, + Transport = transport + }); + + // Do this before the first await so we don't yield control to the transport until we've + // added the connection to the connection manager + _context.ServiceContext.ConnectionManager.AddConnection(_context.FrameConnectionId, this); + _lastTimestamp = _context.ServiceContext.SystemClock.UtcNow.Ticks; + + if (adaptedPipeline != null) { - _context.ServiceContext.ConnectionManager.RemoveConnection(_context.FrameConnectionId); - DisposeAdaptedConnections(); - - if (_frame.WasUpgraded) - { - _context.ServiceContext.ConnectionManager.UpgradedConnectionCount.ReleaseOne(); - } - else - { - _context.ServiceContext.ConnectionManager.NormalConnectionCount.ReleaseOne(); - } - - Log.ConnectionStop(ConnectionId); - KestrelEventSource.Log.ConnectionStop(this); + // Stream can be null here and run async will close the connection in that case + var stream = await ApplyConnectionAdaptersAsync(); + adaptedPipelineTask = adaptedPipeline.RunAsync(stream); } + + if (_frame.ConnectionFeatures?.Get()?.ApplicationProtocol == "h2" && + Interlocked.CompareExchange(ref _http2ConnectionState, Http2ConnectionStarted, Http2ConnectionNotStarted) == Http2ConnectionNotStarted) + { + await _http2Connection.ProcessAsync(httpApplication); + } + else + { + await _frame.ProcessRequestsAsync(); + } + + await adaptedPipelineTask; + await _socketClosedTcs.Task; + } + catch (Exception ex) + { + Log.LogError(0, ex, $"Unexpected exception in {nameof(FrameConnection)}.{nameof(ProcessRequestsAsync)}."); + } + finally + { + _context.ServiceContext.ConnectionManager.RemoveConnection(_context.FrameConnectionId); + DisposeAdaptedConnections(); + + if (_frame.WasUpgraded) + { + _context.ServiceContext.ConnectionManager.UpgradedConnectionCount.ReleaseOne(); + } + else + { + _context.ServiceContext.ConnectionManager.NormalConnectionCount.ReleaseOne(); + } + + KestrelEventSource.Log.ConnectionStop(this); } } @@ -497,15 +492,5 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal _writeTimingWrites--; } } - - private IDisposable BeginConnectionScope() - { - if (Log.IsEnabled(LogLevel.Critical)) - { - return Log.BeginScope(new ConnectionLogScope(ConnectionId)); - } - - return null; - } } } diff --git a/test/Kestrel.Core.Tests/ConnectionHandlerTests.cs b/test/Kestrel.Core.Tests/ConnectionHandlerTests.cs new file mode 100644 index 0000000000..b21387675e --- /dev/null +++ b/test/Kestrel.Core.Tests/ConnectionHandlerTests.cs @@ -0,0 +1,70 @@ +using System; +using System.Collections.Generic; +using System.IO.Pipelines; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Http.Features; +using Microsoft.AspNetCore.Protocols.Features; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal; +using Microsoft.AspNetCore.Testing; +using Xunit; + +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests +{ + public class ConnectionHandlerTests + { + [Fact] + public void OnConnectionCreatesLogScopeWithConnectionId() + { + var serviceContext = new TestServiceContext(); + var tcs = new TaskCompletionSource(); + var handler = new ConnectionHandler(serviceContext, _ => tcs.Task); + + var connection = new TestConnection(); + + handler.OnConnection(connection); + + // The scope should be created + var scopeObjects = ((TestKestrelTrace)serviceContext.Log) + .Logger + .Scopes + .OfType>>() + .ToList(); + + Assert.Single(scopeObjects); + var pairs = scopeObjects[0].ToDictionary(p => p.Key, p => p.Value); + Assert.True(pairs.ContainsKey("ConnectionId")); + Assert.Equal(connection.ConnectionId, pairs["ConnectionId"]); + + tcs.TrySetResult(null); + + // Verify the scope was disposed after request processing completed + Assert.True(((TestKestrelTrace)serviceContext.Log).Logger.Scopes.IsEmpty); + } + + private class TestConnection : FeatureCollection, IConnectionIdFeature, IConnectionTransportFeature + { + public TestConnection() + { + Set(this); + Set(this); + } + + public PipeFactory PipeFactory { get; } = new PipeFactory(); + + public IPipeConnection Transport { get; set; } + public IPipeConnection Application { get; set; } + + public IScheduler InputWriterScheduler => TaskRunScheduler.Default; + + public IScheduler OutputReaderScheduler => TaskRunScheduler.Default; + + public Task ConnectionAborted => Task.CompletedTask; + + public Task ConnectionClosed => Task.CompletedTask; + + public string ConnectionId { get; set; } + } + } +} diff --git a/test/Kestrel.Core.Tests/FrameConnectionTests.cs b/test/Kestrel.Core.Tests/FrameConnectionTests.cs index e77de9b870..b2418bf61a 100644 --- a/test/Kestrel.Core.Tests/FrameConnectionTests.cs +++ b/test/Kestrel.Core.Tests/FrameConnectionTests.cs @@ -528,29 +528,5 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests Assert.True(_frameConnection.TimedOut); Assert.True(aborted.Wait(TimeSpan.FromSeconds(10))); } - - [Fact] - public async Task StartRequestProcessingCreatesLogScopeWithConnectionId() - { - _ = _frameConnection.StartRequestProcessing(new DummyApplication()); - - var scopeObjects = ((TestKestrelTrace)_frameConnectionContext.ServiceContext.Log) - .Logger - .Scopes - .OfType>>() - .ToList(); - - _frameConnection.OnConnectionClosed(ex: null); - - await _frameConnection.StopAsync().TimeoutAfter(TimeSpan.FromSeconds(5)); - - Assert.Single(scopeObjects); - var pairs = scopeObjects[0].ToDictionary(p => p.Key, p => p.Value); - Assert.True(pairs.ContainsKey("ConnectionId")); - Assert.Equal(_frameConnection.ConnectionId, pairs["ConnectionId"]); - - // Verify the scope was disposed after request processing completed - Assert.True(((TestKestrelTrace)_frameConnectionContext.ServiceContext.Log).Logger.Scopes.IsEmpty); - } } } From a145734d43233fc347574c7be09d52c47ad43f46 Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Thu, 24 Aug 2017 10:17:05 -0700 Subject: [PATCH 1388/1662] Fix flakiness in ConnectionClosedWhenResponseDoesNotSatisfyMinimumDataRate (#1955). --- test/Kestrel.FunctionalTests/ResponseTests.cs | 60 ++++++++++--------- 1 file changed, 31 insertions(+), 29 deletions(-) diff --git a/test/Kestrel.FunctionalTests/ResponseTests.cs b/test/Kestrel.FunctionalTests/ResponseTests.cs index d0a4b3deef..05328b3a2c 100644 --- a/test/Kestrel.FunctionalTests/ResponseTests.cs +++ b/test/Kestrel.FunctionalTests/ResponseTests.cs @@ -2444,15 +2444,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } } - [ConditionalFact] - [OSSkipCondition(OperatingSystems.Linux, SkipReason = "Flaky test (https://github.com/aspnet/KestrelHttpServer/issues/1955)")] - public async Task ConnectionClosedWhenResponseDoesNotSatisfyMinimumDataRate() + [Fact] + public void ConnectionClosedWhenResponseDoesNotSatisfyMinimumDataRate() { var chunkSize = 64 * 1024; var chunks = 128; + var responseSize = chunks * chunkSize; + var requestAborted = new ManualResetEventSlim(); var messageLogged = new ManualResetEventSlim(); - var mockKestrelTrace = new Mock(); mockKestrelTrace .Setup(trace => trace.ResponseMininumDataRateNotSatisfied(It.IsAny(), It.IsAny())) @@ -2471,16 +2471,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } }; - var aborted = new ManualResetEventSlim(); - using (var server = new TestServer(async context => { - context.RequestAborted.Register(() => - { - aborted.Set(); - }); + context.RequestAborted.Register(() => requestAborted.Set()); - context.Response.ContentLength = chunks * chunkSize; + context.Response.ContentLength = responseSize; for (var i = 0; i < chunks; i++) { @@ -2488,29 +2483,36 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } }, testContext)) { - using (var connection = server.CreateConnection()) + using (var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)) { - await connection.Send( - "GET / HTTP/1.1", - "Host:", - "", - ""); + socket.ReceiveBufferSize = 1; - Assert.True(aborted.Wait(TimeSpan.FromSeconds(60))); + socket.Connect(new IPEndPoint(IPAddress.Loopback, server.Port)); + socket.Send(Encoding.ASCII.GetBytes("GET / HTTP/1.1\r\nHost: \r\n\r\n")); - await connection.Receive( - "HTTP/1.1 200 OK", - ""); - await connection.ReceiveStartsWith("Date: "); - await connection.Receive( - $"Content-Length: {chunks * chunkSize}", - "", - ""); + Assert.True(messageLogged.Wait(TimeSpan.FromSeconds(60)), "The expected message was not logged within the timeout period."); + Assert.True(requestAborted.Wait(TimeSpan.FromSeconds(60)), "The request was not aborted within the timeout period."); - await Assert.ThrowsAsync(async () => await connection.ReceiveForcedEnd( - new string('a', chunks * chunkSize))); + var totalReceived = 0; + var received = 0; - Assert.True(messageLogged.Wait(TimeSpan.FromSeconds(10))); + try + { + var buffer = new byte[chunkSize]; + + do + { + received = socket.Receive(buffer); + totalReceived += received; + } while (received > 0 && totalReceived < responseSize); + } + catch (IOException) + { + // Socket.Receive could throw, and that is fine + } + + // Since we expect writes to be cut off by the rate control, we should never see the entire response + Assert.NotEqual(responseSize, totalReceived); } } } From 4735154ecd4f450c11ed63091eaf05b1fa875ff5 Mon Sep 17 00:00:00 2001 From: Nate McMaster Date: Sat, 26 Aug 2017 11:18:15 -0700 Subject: [PATCH 1389/1662] Install .NET Core 1.1.2 --- build/repo.props | 3 +++ 1 file changed, 3 insertions(+) diff --git a/build/repo.props b/build/repo.props index c5d91e8a2c..de0440bdd2 100644 --- a/build/repo.props +++ b/build/repo.props @@ -1,5 +1,8 @@ + + + From 088f7e32ae7f3c256871c0d5bffcf0fe2ecf35a0 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Sun, 27 Aug 2017 01:14:45 +0100 Subject: [PATCH 1390/1662] Reset StatusCode & ReasonPhrase directly (#2025) --- src/Kestrel.Core/Internal/Http/Frame.cs | 4 ++-- src/Kestrel.Core/Internal/Http2/Http2Stream.cs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Kestrel.Core/Internal/Http/Frame.cs b/src/Kestrel.Core/Internal/Http/Frame.cs index d8eb4096f8..4c4121df62 100644 --- a/src/Kestrel.Core/Internal/Http/Frame.cs +++ b/src/Kestrel.Core/Internal/Http/Frame.cs @@ -347,8 +347,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http _absoluteRequestTarget = null; QueryString = null; _httpVersion = Http.HttpVersion.Unknown; - StatusCode = StatusCodes.Status200OK; - ReasonPhrase = null; + _statusCode = StatusCodes.Status200OK; + _reasonPhrase = null; RemoteIpAddress = RemoteEndPoint?.Address; RemotePort = RemoteEndPoint?.Port ?? 0; diff --git a/src/Kestrel.Core/Internal/Http2/Http2Stream.cs b/src/Kestrel.Core/Internal/Http2/Http2Stream.cs index c7b6b4b3ac..ea3fc33144 100644 --- a/src/Kestrel.Core/Internal/Http2/Http2Stream.cs +++ b/src/Kestrel.Core/Internal/Http2/Http2Stream.cs @@ -256,8 +256,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 _requestTargetForm = HttpRequestTarget.Unknown; _absoluteRequestTarget = null; QueryString = null; - StatusCode = StatusCodes.Status200OK; - ReasonPhrase = null; + _statusCode = StatusCodes.Status200OK; + _reasonPhrase = null; RemoteIpAddress = RemoteEndPoint?.Address; RemotePort = RemoteEndPoint?.Port ?? 0; From 09be7c416a032ed55a3cefa8b1554af92bb54abf Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Sun, 27 Aug 2017 01:18:16 +0100 Subject: [PATCH 1391/1662] Use preparsed version, rather than reparsing (#2021) Current path is: Parser -> HttpVersion Enum -> Get Version String -> Set `HttpVersion` with string -> Convert back to Enum Can just set the enum directly since its already parsed. Also using the const rather than strings; where the strings are in code --- src/Kestrel.Core/Internal/Http/Frame.cs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Kestrel.Core/Internal/Http/Frame.cs b/src/Kestrel.Core/Internal/Http/Frame.cs index 4c4121df62..3c56334f26 100644 --- a/src/Kestrel.Core/Internal/Http/Frame.cs +++ b/src/Kestrel.Core/Internal/Http/Frame.cs @@ -158,11 +158,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { if (_httpVersion == Http.HttpVersion.Http11) { - return "HTTP/1.1"; + return HttpUtilities.Http11Version; } if (_httpVersion == Http.HttpVersion.Http10) { - return "HTTP/1.0"; + return HttpUtilities.Http10Version; } return string.Empty; @@ -173,11 +173,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { // GetKnownVersion returns versions which ReferenceEquals interned string // As most common path, check for this only in fast-path and inline - if (ReferenceEquals(value, "HTTP/1.1")) + if (ReferenceEquals(value, HttpUtilities.Http11Version)) { _httpVersion = Http.HttpVersion.Http11; } - else if (ReferenceEquals(value, "HTTP/1.0")) + else if (ReferenceEquals(value, HttpUtilities.Http10Version)) { _httpVersion = Http.HttpVersion.Http10; } @@ -191,11 +191,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http [MethodImpl(MethodImplOptions.NoInlining)] private void HttpVersionSetSlow(string value) { - if (value == "HTTP/1.1") + if (value == HttpUtilities.Http11Version) { _httpVersion = Http.HttpVersion.Http11; } - else if (value == "HTTP/1.0") + else if (value == HttpUtilities.Http10Version) { _httpVersion = Http.HttpVersion.Http10; } @@ -1224,7 +1224,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http Method = method != HttpMethod.Custom ? HttpUtilities.MethodToString(method) ?? string.Empty : customMethod.GetAsciiStringNonNullCharacters(); - HttpVersion = HttpUtilities.VersionToString(version); + _httpVersion = version; Debug.Assert(RawTarget != null, "RawTarget was not set"); Debug.Assert(Method != null, "Method was not set"); From 7854c0604a3e6e50a0bea84c4fa9d9e6ca5d7057 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Sat, 26 Aug 2017 20:19:55 -0700 Subject: [PATCH 1392/1662] Remove the events on ConnectionContext (#2023) - Use the pipe events and removed the Tasks from ConnectionContext - Remove OnConnectionClosed from FrameConnection. Since the `FrameConnetion` is a single middleware, not the entire pipeline, we shouldn't need to wait on the connection close there. - It seems like the callbacks are rooted on the pipe even after they fire. This needs to be investigated in pipelines. --- src/Kestrel.Core/Internal/FrameConnection.cs | 9 ----- .../Internal/HttpConnectionMiddleware.cs | 37 +++++++++++-------- .../Internal/IConnectionHandler.cs | 1 + .../Internal/TransportConnection.Features.cs | 10 ----- .../Internal/TransportConnection.cs | 29 +-------------- .../Internal/LibuvConnection.cs | 6 --- .../SocketConnection.cs | 17 +++------ .../ConnectionContext.cs | 4 -- .../DefaultConnectionContext.cs | 10 +---- .../Features/IConnectionTransportFeature.cs | 10 +---- .../ConnectionHandlerTests.cs | 4 -- test/Kestrel.FunctionalTests/RequestTests.cs | 2 + .../TestHelpers/MockConnectionHandler.cs | 1 + 13 files changed, 34 insertions(+), 106 deletions(-) diff --git a/src/Kestrel.Core/Internal/FrameConnection.cs b/src/Kestrel.Core/Internal/FrameConnection.cs index f2e3a3e172..8171817b7a 100644 --- a/src/Kestrel.Core/Internal/FrameConnection.cs +++ b/src/Kestrel.Core/Internal/FrameConnection.cs @@ -28,7 +28,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal private readonly FrameConnectionContext _context; private IList _adaptedConnections; - private readonly TaskCompletionSource _socketClosedTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); private Frame _frame; private Http2Connection _http2Connection; private volatile int _http2ConnectionState; @@ -152,7 +151,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal } await adaptedPipelineTask; - await _socketClosedTcs.Task; } catch (Exception ex) { @@ -191,13 +189,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal }); } - public void OnConnectionClosed(Exception ex) - { - Abort(ex); - - _socketClosedTcs.TrySetResult(null); - } - public Task StopAsync() { Debug.Assert(_frame != null, $"{nameof(_frame)} is null"); diff --git a/src/Kestrel.Core/Internal/HttpConnectionMiddleware.cs b/src/Kestrel.Core/Internal/HttpConnectionMiddleware.cs index e79658de2c..221371535b 100644 --- a/src/Kestrel.Core/Internal/HttpConnectionMiddleware.cs +++ b/src/Kestrel.Core/Internal/HttpConnectionMiddleware.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Net; using System.Threading; using System.Threading.Tasks; @@ -63,25 +64,29 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal var connection = new FrameConnection(frameConnectionContext); - // The order here is important, start request processing so that - // the frame is created before this yields. Events need to be wired up - // afterwards var processingTask = connection.StartRequestProcessing(_application); - // Wire up the events an forward calls to the frame connection - // It's important that these execute synchronously because graceful - // connection close is order sensative (for now) - connectionContext.ConnectionAborted.ContinueWith((task, state) => - { - // Unwrap the aggregate exception - ((FrameConnection)state).Abort(task.Exception?.InnerException); - }, - connection, TaskContinuationOptions.ExecuteSynchronously); + var inputTcs = new TaskCompletionSource(); - connectionContext.ConnectionClosed.ContinueWith((task, state) => + // Abort the frame when the transport writer completes + connectionContext.Transport.Input.OnWriterCompleted((error, state) => { - // Unwrap the aggregate exception - ((FrameConnection)state).OnConnectionClosed(task.Exception?.InnerException); + var tcs = (TaskCompletionSource)state; + + if (error != null) + { + tcs.TrySetException(error); + } + else + { + tcs.TrySetResult(null); + } + }, + inputTcs); + + inputTcs.Task.ContinueWith((task, state) => + { + ((FrameConnection)state).Abort(task.Exception?.InnerException); }, connection, TaskContinuationOptions.ExecuteSynchronously); diff --git a/src/Kestrel.Transport.Abstractions/Internal/IConnectionHandler.cs b/src/Kestrel.Transport.Abstractions/Internal/IConnectionHandler.cs index 9ae3f89c3f..41b5c57839 100644 --- a/src/Kestrel.Transport.Abstractions/Internal/IConnectionHandler.cs +++ b/src/Kestrel.Transport.Abstractions/Internal/IConnectionHandler.cs @@ -1,6 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System.Threading.Tasks; using Microsoft.AspNetCore.Http.Features; namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal diff --git a/src/Kestrel.Transport.Abstractions/Internal/TransportConnection.Features.cs b/src/Kestrel.Transport.Abstractions/Internal/TransportConnection.Features.cs index 7a8cd3ce29..2ac096eb24 100644 --- a/src/Kestrel.Transport.Abstractions/Internal/TransportConnection.Features.cs +++ b/src/Kestrel.Transport.Abstractions/Internal/TransportConnection.Features.cs @@ -109,16 +109,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal set => Application = value; } - Task IConnectionTransportFeature.ConnectionAborted - { - get => _abortTcs.Task; - } - - Task IConnectionTransportFeature.ConnectionClosed - { - get => _closedTcs.Task; - } - object IFeatureCollection.this[Type key] { get => FastFeatureGet(key); diff --git a/src/Kestrel.Transport.Abstractions/Internal/TransportConnection.cs b/src/Kestrel.Transport.Abstractions/Internal/TransportConnection.cs index a447fae39c..c269a8f928 100644 --- a/src/Kestrel.Transport.Abstractions/Internal/TransportConnection.cs +++ b/src/Kestrel.Transport.Abstractions/Internal/TransportConnection.cs @@ -1,15 +1,11 @@ using System; using System.IO.Pipelines; using System.Net; -using System.Threading.Tasks; namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal { public abstract partial class TransportConnection { - private readonly TaskCompletionSource _abortTcs = new TaskCompletionSource(); - private readonly TaskCompletionSource _closedTcs = new TaskCompletionSource(); - public TransportConnection() { _currentIConnectionIdFeature = this; @@ -31,28 +27,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal public IPipeConnection Transport { get; set; } public IPipeConnection Application { get; set; } - protected void Abort(Exception exception) - { - if (exception == null) - { - _abortTcs.TrySetResult(null); - } - else - { - _abortTcs.TrySetException(exception); - } - } - - protected void Close(Exception exception) - { - if (exception == null) - { - _closedTcs.TrySetResult(null); - } - else - { - _closedTcs.TrySetException(exception); - } - } + public IPipeWriter Input => Application.Output; + public IPipeReader Output => Application.Input; } } diff --git a/src/Kestrel.Transport.Libuv/Internal/LibuvConnection.cs b/src/Kestrel.Transport.Libuv/Internal/LibuvConnection.cs index 1ed08a309e..26f3ed4ac3 100644 --- a/src/Kestrel.Transport.Libuv/Internal/LibuvConnection.cs +++ b/src/Kestrel.Transport.Libuv/Internal/LibuvConnection.cs @@ -46,9 +46,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal } } - public IPipeWriter Input => Application.Output; - public IPipeReader Output => Application.Input; - public LibuvOutputConsumer OutputConsumer { get; set; } private ILibuvTrace Log => ListenerContext.TransportContext.Log; @@ -83,7 +80,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal // Now, complete the input so that no more reads can happen Input.Complete(error ?? new ConnectionAbortedException()); Output.Complete(error); - Close(error); // Make sure it isn't possible for a paused read to resume reading after calling uv_close // on the stream handle @@ -178,7 +174,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal } } - Abort(error); // Complete after aborting the connection Input.Complete(error); } @@ -216,7 +211,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal Log.ConnectionReadFin(ConnectionId); var error = new IOException(ex.Message, ex); - Abort(error); Input.Complete(error); } } diff --git a/src/Kestrel.Transport.Sockets/SocketConnection.cs b/src/Kestrel.Transport.Sockets/SocketConnection.cs index e39e605d6a..4f11d7cd1f 100644 --- a/src/Kestrel.Transport.Sockets/SocketConnection.cs +++ b/src/Kestrel.Transport.Sockets/SocketConnection.cs @@ -19,8 +19,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets private readonly Socket _socket; private readonly SocketTransport _transport; - private IPipeWriter _input; - private IPipeReader _output; private IList> _sendBufferList; private const int MinAllocBufferSize = 2048; @@ -48,9 +46,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets { connectionHandler.OnConnection(this); - _input = Application.Output; - _output = Application.Input; - // Spawn send and receive logic Task receiveTask = DoReceive(); Task sendTask = DoSend(); @@ -86,7 +81,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets while (true) { // Ensure we have some reasonable amount of buffer space - var buffer = _input.Alloc(MinAllocBufferSize); + var buffer = Input.Alloc(MinAllocBufferSize); try { @@ -135,8 +130,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets } finally { - Abort(error); - _input.Complete(error); + Input.Complete(error); } } @@ -168,7 +162,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets while (true) { // Wait for data to write from the pipe producer - var result = await _output.ReadAsync(); + var result = await Output.ReadAsync(); var buffer = result.Buffer; if (result.IsCancelled) @@ -205,7 +199,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets } finally { - _output.Advance(buffer.End); + Output.Advance(buffer.End); } } @@ -229,8 +223,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets } finally { - Close(error); - _output.Complete(error); + Output.Complete(error); } } diff --git a/src/Protocols.Abstractions/ConnectionContext.cs b/src/Protocols.Abstractions/ConnectionContext.cs index c10a884f48..f2ddc754ae 100644 --- a/src/Protocols.Abstractions/ConnectionContext.cs +++ b/src/Protocols.Abstractions/ConnectionContext.cs @@ -15,9 +15,5 @@ namespace Microsoft.AspNetCore.Protocols public abstract IPipeConnection Transport { get; set; } public abstract PipeFactory PipeFactory { get; } - - public abstract Task ConnectionAborted { get; } - - public abstract Task ConnectionClosed { get; } } } diff --git a/src/Protocols.Abstractions/DefaultConnectionContext.cs b/src/Protocols.Abstractions/DefaultConnectionContext.cs index 814d4470f7..b81fc16f06 100644 --- a/src/Protocols.Abstractions/DefaultConnectionContext.cs +++ b/src/Protocols.Abstractions/DefaultConnectionContext.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.IO.Pipelines; -using System.Text; -using System.Threading.Tasks; +using System.IO.Pipelines; using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Protocols.Features; @@ -39,10 +35,6 @@ namespace Microsoft.AspNetCore.Protocols set => ConnectionTransportFeature.Transport = value; } - public override Task ConnectionAborted => ConnectionTransportFeature.ConnectionAborted; - - public override Task ConnectionClosed => ConnectionTransportFeature.ConnectionClosed; - struct FeatureInterfaces { public IConnectionIdFeature ConnectionId; diff --git a/src/Protocols.Abstractions/Features/IConnectionTransportFeature.cs b/src/Protocols.Abstractions/Features/IConnectionTransportFeature.cs index e9cccb4a3e..8f27924126 100644 --- a/src/Protocols.Abstractions/Features/IConnectionTransportFeature.cs +++ b/src/Protocols.Abstractions/Features/IConnectionTransportFeature.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.IO.Pipelines; -using System.Text; -using System.Threading.Tasks; +using System.IO.Pipelines; namespace Microsoft.AspNetCore.Protocols.Features { @@ -17,9 +13,5 @@ namespace Microsoft.AspNetCore.Protocols.Features IScheduler InputWriterScheduler { get; } IScheduler OutputReaderScheduler { get; } - - Task ConnectionAborted { get; } - - Task ConnectionClosed { get; } } } diff --git a/test/Kestrel.Core.Tests/ConnectionHandlerTests.cs b/test/Kestrel.Core.Tests/ConnectionHandlerTests.cs index b21387675e..45450bf9bd 100644 --- a/test/Kestrel.Core.Tests/ConnectionHandlerTests.cs +++ b/test/Kestrel.Core.Tests/ConnectionHandlerTests.cs @@ -60,10 +60,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests public IScheduler OutputReaderScheduler => TaskRunScheduler.Default; - public Task ConnectionAborted => Task.CompletedTask; - - public Task ConnectionClosed => Task.CompletedTask; - public string ConnectionId { get; set; } } } diff --git a/test/Kestrel.FunctionalTests/RequestTests.cs b/test/Kestrel.FunctionalTests/RequestTests.cs index 3a55e9a4cf..281e5e057f 100644 --- a/test/Kestrel.FunctionalTests/RequestTests.cs +++ b/test/Kestrel.FunctionalTests/RequestTests.cs @@ -990,6 +990,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests public async Task ConnectionClosesWhenFinReceivedBeforeRequestCompletes(ListenOptions listenOptions) { var testContext = new TestServiceContext(); + // FIN callbacks are scheduled so run inline to make this test more reliable + testContext.ThreadPool = new InlineLoggingThreadPool(testContext.Log); using (var server = new TestServer(TestApp.EchoAppChunked, testContext, listenOptions)) { diff --git a/test/Kestrel.Transport.Libuv.Tests/TestHelpers/MockConnectionHandler.cs b/test/Kestrel.Transport.Libuv.Tests/TestHelpers/MockConnectionHandler.cs index ef856124fe..f1615378ee 100644 --- a/test/Kestrel.Transport.Libuv.Tests/TestHelpers/MockConnectionHandler.cs +++ b/test/Kestrel.Transport.Libuv.Tests/TestHelpers/MockConnectionHandler.cs @@ -3,6 +3,7 @@ using System; using System.IO.Pipelines; +using System.Threading.Tasks; using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Protocols; using Microsoft.AspNetCore.Protocols.Features; From 9d8556e7c4af2b4039b8ef8ae44104aca87a44f5 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Sat, 26 Aug 2017 21:20:06 -0700 Subject: [PATCH 1393/1662] Added FrameConnection.OnConnectionClosed back (#2028) --- src/Kestrel.Core/Internal/FrameConnection.cs | 9 ++++ .../Internal/HttpConnectionMiddleware.cs | 42 ++++++++++++------- 2 files changed, 36 insertions(+), 15 deletions(-) diff --git a/src/Kestrel.Core/Internal/FrameConnection.cs b/src/Kestrel.Core/Internal/FrameConnection.cs index 8171817b7a..f2e3a3e172 100644 --- a/src/Kestrel.Core/Internal/FrameConnection.cs +++ b/src/Kestrel.Core/Internal/FrameConnection.cs @@ -28,6 +28,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal private readonly FrameConnectionContext _context; private IList _adaptedConnections; + private readonly TaskCompletionSource _socketClosedTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); private Frame _frame; private Http2Connection _http2Connection; private volatile int _http2ConnectionState; @@ -151,6 +152,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal } await adaptedPipelineTask; + await _socketClosedTcs.Task; } catch (Exception ex) { @@ -189,6 +191,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal }); } + public void OnConnectionClosed(Exception ex) + { + Abort(ex); + + _socketClosedTcs.TrySetResult(null); + } + public Task StopAsync() { Debug.Assert(_frame != null, $"{nameof(_frame)} is null"); diff --git a/src/Kestrel.Core/Internal/HttpConnectionMiddleware.cs b/src/Kestrel.Core/Internal/HttpConnectionMiddleware.cs index 221371535b..b47ea9d603 100644 --- a/src/Kestrel.Core/Internal/HttpConnectionMiddleware.cs +++ b/src/Kestrel.Core/Internal/HttpConnectionMiddleware.cs @@ -13,6 +13,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal { public class HttpConnectionMiddleware { + private static Action _completeTcs = CompleteTcs; + private static long _lastFrameConnectionId = long.MinValue; private readonly IList _connectionAdapters; @@ -67,22 +69,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal var processingTask = connection.StartRequestProcessing(_application); var inputTcs = new TaskCompletionSource(); + var outputTcs = new TaskCompletionSource(); - // Abort the frame when the transport writer completes - connectionContext.Transport.Input.OnWriterCompleted((error, state) => - { - var tcs = (TaskCompletionSource)state; - - if (error != null) - { - tcs.TrySetException(error); - } - else - { - tcs.TrySetResult(null); - } - }, - inputTcs); + // The reason we don't fire events directly from these callbacks is because it seems + // like the transport callbacks root the state object (even after it fires) + connectionContext.Transport.Input.OnWriterCompleted(_completeTcs, inputTcs); + connectionContext.Transport.Output.OnReaderCompleted(_completeTcs, outputTcs); inputTcs.Task.ContinueWith((task, state) => { @@ -90,7 +82,27 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal }, connection, TaskContinuationOptions.ExecuteSynchronously); + outputTcs.Task.ContinueWith((task, state) => + { + ((FrameConnection)state).OnConnectionClosed(task.Exception?.InnerException); + }, + connection, TaskContinuationOptions.ExecuteSynchronously); + return processingTask; } + + private static void CompleteTcs(Exception error, object state) + { + var tcs = (TaskCompletionSource)state; + + if (error != null) + { + tcs.TrySetException(error); + } + else + { + tcs.TrySetResult(null); + } + } } } From 5bf7d3b28a2fcca56a7d24fd7e79c13dedae657b Mon Sep 17 00:00:00 2001 From: Damir Ainullin Date: Mon, 28 Aug 2017 06:11:00 +0300 Subject: [PATCH 1394/1662] Fix typo in FrameTests (#2033) --- test/Kestrel.Core.Tests/FrameTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Kestrel.Core.Tests/FrameTests.cs b/test/Kestrel.Core.Tests/FrameTests.cs index 2910bedc14..57c8287284 100644 --- a/test/Kestrel.Core.Tests/FrameTests.cs +++ b/test/Kestrel.Core.Tests/FrameTests.cs @@ -76,7 +76,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests public void Dispose() { _transport.Input.Complete(); - _application.Output.Complete(); + _transport.Output.Complete(); _application.Input.Complete(); _application.Output.Complete(); From e7743cbb78cac6d01b90a0d718cf043663688bb1 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Tue, 29 Aug 2017 20:21:45 +0100 Subject: [PATCH 1395/1662] Shorter LibuvThread locks (#2034) --- .../Internal/LibuvThread.cs | 38 +++++++++++-------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/src/Kestrel.Transport.Libuv/Internal/LibuvThread.cs b/src/Kestrel.Transport.Libuv/Internal/LibuvThread.cs index 6b27b447ea..726f3bfb6a 100644 --- a/src/Kestrel.Transport.Libuv/Internal/LibuvThread.cs +++ b/src/Kestrel.Transport.Libuv/Internal/LibuvThread.cs @@ -32,6 +32,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal private Queue _closeHandleAdding = new Queue(256); private Queue _closeHandleRunning = new Queue(256); private readonly object _workSync = new object(); + private readonly object _closeHandleSync = new object(); private readonly object _startSync = new object(); private bool _stopImmediate = false; private bool _initCompleted = false; @@ -170,14 +171,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal public void Post(Action callback, T state) { + var work = new Work + { + CallbackAdapter = CallbackAdapter.PostCallbackAdapter, + Callback = callback, + State = state + }; + lock (_workSync) { - _workAdding.Enqueue(new Work - { - CallbackAdapter = CallbackAdapter.PostCallbackAdapter, - Callback = callback, - State = state - }); + _workAdding.Enqueue(work); } _post.Send(); } @@ -190,15 +193,17 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal public Task PostAsync(Action callback, T state) { var tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var work = new Work + { + CallbackAdapter = CallbackAdapter.PostAsyncCallbackAdapter, + Callback = callback, + State = state, + Completion = tcs + }; + lock (_workSync) { - _workAdding.Enqueue(new Work - { - CallbackAdapter = CallbackAdapter.PostAsyncCallbackAdapter, - Callback = callback, - State = state, - Completion = tcs - }); + _workAdding.Enqueue(work); } _post.Send(); return tcs.Task; @@ -226,9 +231,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal private void EnqueueCloseHandle(Action callback, IntPtr handle) { - lock (_workSync) + var closeHandle = new CloseHandle { Callback = callback, Handle = handle }; + lock (_closeHandleSync) { - _closeHandleAdding.Enqueue(new CloseHandle { Callback = callback, Handle = handle }); + _closeHandleAdding.Enqueue(closeHandle); } } @@ -352,7 +358,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal private bool DoPostCloseHandle() { Queue queue; - lock (_workSync) + lock (_closeHandleSync) { queue = _closeHandleAdding; _closeHandleAdding = _closeHandleRunning; From 284367db9ffca9ecc3eb734a068e52f682f569fa Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Wed, 30 Aug 2017 11:30:20 -0700 Subject: [PATCH 1396/1662] Improve ConnectionLimitMiddleware and connection pipeline building (#2010) * Improve ConnectionLimitMiddleware and connection pipeline building * Add IDecrementConcurrentConnectionCountFeature * Flow connection features from connection middleware --- .../FrameFeatureCollection.cs | 1 + .../FrameParsingOverheadBenchmark.cs | 2 + .../FrameWritingBenchmark.cs | 2 + .../RequestParsingBenchmark.cs | 2 + .../ResponseHeaderCollectionBenchmark.cs | 2 + .../ResponseHeadersWritingBenchmark.cs | 2 + ...crementConcurrentConnectionCountFeature.cs | 17 +++++ .../ConnectionLimitBuilderExtensions.cs | 16 ----- .../Internal/ConnectionLimitMiddleware.cs | 62 ++++++++++++++++--- src/Kestrel.Core/Internal/FrameConnection.cs | 16 ++--- .../Internal/FrameConnectionContext.cs | 2 + .../Internal/Http/Frame.FeatureCollection.cs | 6 +- src/Kestrel.Core/Internal/Http/Frame.cs | 2 +- .../Internal/Http/FrameContext.cs | 2 + .../Internal/HttpConnectionMiddleware.cs | 1 + .../Infrastructure/FrameConnectionManager.cs | 12 +--- src/Kestrel.Core/KestrelServer.cs | 17 ++--- src/Kestrel.Core/KestrelServerLimits.cs | 2 +- src/Kestrel.Core/KestrelServerOptions.cs | 9 ++- src/Kestrel.Core/ListenOptions.cs | 2 - .../FrameConnectionManagerTests.cs | 2 +- .../FrameConnectionTests.cs | 6 +- .../FrameResponseHeadersTests.cs | 4 +- test/Kestrel.Core.Tests/FrameTests.cs | 1 + .../KestrelServerOptionsTests.cs | 3 - test/Kestrel.Core.Tests/TestInput.cs | 2 + .../ConnectionLimitTests.cs | 48 ++++++++------ .../TestHelpers/TestServer.cs | 1 - test/Kestrel.FunctionalTests/UpgradeTests.cs | 2 +- .../LibuvOutputConsumerTests.cs | 2 + test/shared/TestServiceContext.cs | 2 +- 31 files changed, 156 insertions(+), 94 deletions(-) create mode 100644 src/Kestrel.Core/Features/IDecrementConcurrentConnectionCountFeature.cs delete mode 100644 src/Kestrel.Core/Internal/ConnectionLimitBuilderExtensions.cs diff --git a/benchmarks/Kestrel.Performance/FrameFeatureCollection.cs b/benchmarks/Kestrel.Performance/FrameFeatureCollection.cs index 2e157f41d7..5bb4f8603a 100644 --- a/benchmarks/Kestrel.Performance/FrameFeatureCollection.cs +++ b/benchmarks/Kestrel.Performance/FrameFeatureCollection.cs @@ -85,6 +85,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance var frameContext = new FrameContext { ServiceContext = serviceContext, + ConnectionFeatures = new FeatureCollection(), PipeFactory = new PipeFactory() }; diff --git a/benchmarks/Kestrel.Performance/FrameParsingOverheadBenchmark.cs b/benchmarks/Kestrel.Performance/FrameParsingOverheadBenchmark.cs index f27fb8c947..dd905485c4 100644 --- a/benchmarks/Kestrel.Performance/FrameParsingOverheadBenchmark.cs +++ b/benchmarks/Kestrel.Performance/FrameParsingOverheadBenchmark.cs @@ -3,6 +3,7 @@ using System.IO.Pipelines; using BenchmarkDotNet.Attributes; +using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; @@ -29,6 +30,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance var frameContext = new FrameContext { ServiceContext = serviceContext, + ConnectionFeatures = new FeatureCollection(), PipeFactory = new PipeFactory(), TimeoutControl = new MockTimeoutControl() }; diff --git a/benchmarks/Kestrel.Performance/FrameWritingBenchmark.cs b/benchmarks/Kestrel.Performance/FrameWritingBenchmark.cs index 82f943f525..bd280dec1d 100644 --- a/benchmarks/Kestrel.Performance/FrameWritingBenchmark.cs +++ b/benchmarks/Kestrel.Performance/FrameWritingBenchmark.cs @@ -7,6 +7,7 @@ using System.Text; using System.Threading; using System.Threading.Tasks; using BenchmarkDotNet.Attributes; +using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; @@ -107,6 +108,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance var frame = new TestFrame(application: null, context: new FrameContext { ServiceContext = serviceContext, + ConnectionFeatures = new FeatureCollection(), PipeFactory = pipeFactory, Application = pair.Application, Transport = pair.Transport diff --git a/benchmarks/Kestrel.Performance/RequestParsingBenchmark.cs b/benchmarks/Kestrel.Performance/RequestParsingBenchmark.cs index b4f14656e4..406c7a9f87 100644 --- a/benchmarks/Kestrel.Performance/RequestParsingBenchmark.cs +++ b/benchmarks/Kestrel.Performance/RequestParsingBenchmark.cs @@ -3,6 +3,7 @@ using System.IO.Pipelines; using BenchmarkDotNet.Attributes; +using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; @@ -33,6 +34,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance var frameContext = new FrameContext { ServiceContext = serviceContext, + ConnectionFeatures = new FeatureCollection(), PipeFactory = PipeFactory, TimeoutControl = new MockTimeoutControl() }; diff --git a/benchmarks/Kestrel.Performance/ResponseHeaderCollectionBenchmark.cs b/benchmarks/Kestrel.Performance/ResponseHeaderCollectionBenchmark.cs index 54f7907ce3..c8d26ed2dc 100644 --- a/benchmarks/Kestrel.Performance/ResponseHeaderCollectionBenchmark.cs +++ b/benchmarks/Kestrel.Performance/ResponseHeaderCollectionBenchmark.cs @@ -6,6 +6,7 @@ using System.Runtime.CompilerServices; using System.Text; using BenchmarkDotNet.Attributes; using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Http.Internal; using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal; @@ -177,6 +178,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance var frameContext = new FrameContext { ServiceContext = serviceContext, + ConnectionFeatures = new FeatureCollection(), PipeFactory = new PipeFactory() }; diff --git a/benchmarks/Kestrel.Performance/ResponseHeadersWritingBenchmark.cs b/benchmarks/Kestrel.Performance/ResponseHeadersWritingBenchmark.cs index 52ffb6bb77..ab5c5dd260 100644 --- a/benchmarks/Kestrel.Performance/ResponseHeadersWritingBenchmark.cs +++ b/benchmarks/Kestrel.Performance/ResponseHeadersWritingBenchmark.cs @@ -7,6 +7,7 @@ using System.Text; using System.Threading; using System.Threading.Tasks; using BenchmarkDotNet.Attributes; +using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; @@ -123,6 +124,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance var frame = new TestFrame(application: null, context: new FrameContext { ServiceContext = serviceContext, + ConnectionFeatures = new FeatureCollection(), PipeFactory = pipeFactory, TimeoutControl = new MockTimeoutControl(), Application = pair.Application, diff --git a/src/Kestrel.Core/Features/IDecrementConcurrentConnectionCountFeature.cs b/src/Kestrel.Core/Features/IDecrementConcurrentConnectionCountFeature.cs new file mode 100644 index 0000000000..d34b1d1439 --- /dev/null +++ b/src/Kestrel.Core/Features/IDecrementConcurrentConnectionCountFeature.cs @@ -0,0 +1,17 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Features +{ + /// + /// A connection feature allowing middleware to stop counting connections towards . + /// This is used by Kestrel internally to stop counting upgraded connections towards this limit. + /// + public interface IDecrementConcurrentConnectionCountFeature + { + /// + /// Idempotent method to stop counting a connection towards . + /// + void ReleaseConnection(); + } +} diff --git a/src/Kestrel.Core/Internal/ConnectionLimitBuilderExtensions.cs b/src/Kestrel.Core/Internal/ConnectionLimitBuilderExtensions.cs deleted file mode 100644 index 2c02fa664c..0000000000 --- a/src/Kestrel.Core/Internal/ConnectionLimitBuilderExtensions.cs +++ /dev/null @@ -1,16 +0,0 @@ -using Microsoft.AspNetCore.Protocols; - -namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal -{ - public static class ConnectionLimitBuilderExtensions - { - public static IConnectionBuilder UseConnectionLimit(this IConnectionBuilder builder, ServiceContext serviceContext) - { - return builder.Use(next => - { - var middleware = new ConnectionLimitMiddleware(next, serviceContext); - return middleware.OnConnectionAsync; - }); - } - } -} diff --git a/src/Kestrel.Core/Internal/ConnectionLimitMiddleware.cs b/src/Kestrel.Core/Internal/ConnectionLimitMiddleware.cs index cd058bc235..fd6823773f 100644 --- a/src/Kestrel.Core/Internal/ConnectionLimitMiddleware.cs +++ b/src/Kestrel.Core/Internal/ConnectionLimitMiddleware.cs @@ -1,32 +1,74 @@ -using System.Threading.Tasks; +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System.Threading.Tasks; using Microsoft.AspNetCore.Protocols; +using Microsoft.AspNetCore.Server.Kestrel.Core.Features; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal { public class ConnectionLimitMiddleware { - private readonly ServiceContext _serviceContext; private readonly ConnectionDelegate _next; + private readonly ResourceCounter _concurrentConnectionCounter; + private readonly IKestrelTrace _trace; - public ConnectionLimitMiddleware(ConnectionDelegate next, ServiceContext serviceContext) + public ConnectionLimitMiddleware(ConnectionDelegate next, long connectionLimit, IKestrelTrace trace) + : this(next, ResourceCounter.Quota(connectionLimit), trace) { - _next = next; - _serviceContext = serviceContext; } - public Task OnConnectionAsync(ConnectionContext connection) + // For Testing + internal ConnectionLimitMiddleware(ConnectionDelegate next, ResourceCounter concurrentConnectionCounter, IKestrelTrace trace) { - if (!_serviceContext.ConnectionManager.NormalConnectionCount.TryLockOne()) + _next = next; + _concurrentConnectionCounter = concurrentConnectionCounter; + _trace = trace; + } + + public async Task OnConnectionAsync(ConnectionContext connection) + { + if (!_concurrentConnectionCounter.TryLockOne()) { KestrelEventSource.Log.ConnectionRejected(connection.ConnectionId); - _serviceContext.Log.ConnectionRejected(connection.ConnectionId); + _trace.ConnectionRejected(connection.ConnectionId); connection.Transport.Input.Complete(); connection.Transport.Output.Complete(); - return Task.CompletedTask; + return; } - return _next(connection); + var releasor = new ConnectionReleasor(_concurrentConnectionCounter); + + try + { + connection.Features.Set(releasor); + await _next(connection); + } + finally + { + releasor.ReleaseConnection(); + } + } + + private class ConnectionReleasor : IDecrementConcurrentConnectionCountFeature + { + private readonly ResourceCounter _concurrentConnectionCounter; + private bool _connectionReleased; + + public ConnectionReleasor(ResourceCounter normalConnectionCounter) + { + _concurrentConnectionCounter = normalConnectionCounter; + } + + public void ReleaseConnection() + { + if (!_connectionReleased) + { + _connectionReleased = true; + _concurrentConnectionCounter.ReleaseOne(); + } + } } } } diff --git a/src/Kestrel.Core/Internal/FrameConnection.cs b/src/Kestrel.Core/Internal/FrameConnection.cs index f2e3a3e172..9232c515da 100644 --- a/src/Kestrel.Core/Internal/FrameConnection.cs +++ b/src/Kestrel.Core/Internal/FrameConnection.cs @@ -141,7 +141,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal adaptedPipelineTask = adaptedPipeline.RunAsync(stream); } - if (_frame.ConnectionFeatures?.Get()?.ApplicationProtocol == "h2" && + if (_frame.ConnectionFeatures.Get()?.ApplicationProtocol == "h2" && Interlocked.CompareExchange(ref _http2ConnectionState, Http2ConnectionStarted, Http2ConnectionNotStarted) == Http2ConnectionNotStarted) { await _http2Connection.ProcessAsync(httpApplication); @@ -167,10 +167,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal { _context.ServiceContext.ConnectionManager.UpgradedConnectionCount.ReleaseOne(); } - else - { - _context.ServiceContext.ConnectionManager.NormalConnectionCount.ReleaseOne(); - } KestrelEventSource.Log.ConnectionStop(this); } @@ -181,6 +177,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal _frame = new Frame(httpApplication, new FrameContext { ConnectionId = _context.ConnectionId, + ConnectionFeatures = _context.ConnectionFeatures, PipeFactory = PipeFactory, LocalEndPoint = LocalEndPoint, RemoteEndPoint = RemoteEndPoint, @@ -255,10 +252,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal { Debug.Assert(_frame != null, $"{nameof(_frame)} is null"); - var features = new FeatureCollection(); var connectionAdapters = _context.ConnectionAdapters; var stream = new RawStream(_context.Transport.Input, _context.Transport.Output); - var adapterContext = new ConnectionAdapterContext(features, stream); + var adapterContext = new ConnectionAdapterContext(_frame.ConnectionFeatures, stream); _adaptedConnections = new List(connectionAdapters.Count); try @@ -267,7 +263,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal { var adaptedConnection = await connectionAdapters[i].OnConnectionAsync(adapterContext); _adaptedConnections.Add(adaptedConnection); - adapterContext = new ConnectionAdapterContext(features, adaptedConnection.ConnectionStream); + adapterContext = new ConnectionAdapterContext(_frame.ConnectionFeatures, adaptedConnection.ConnectionStream); } } catch (Exception ex) @@ -276,10 +272,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal return null; } - finally - { - _frame.ConnectionFeatures = features; - } return adapterContext.ConnectionStream; } diff --git a/src/Kestrel.Core/Internal/FrameConnectionContext.cs b/src/Kestrel.Core/Internal/FrameConnectionContext.cs index 5f5c5c2dfa..c8beb6ab45 100644 --- a/src/Kestrel.Core/Internal/FrameConnectionContext.cs +++ b/src/Kestrel.Core/Internal/FrameConnectionContext.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; using System.IO.Pipelines; using System.Net; +using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal @@ -13,6 +14,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal public string ConnectionId { get; set; } public long FrameConnectionId { get; set; } public ServiceContext ServiceContext { get; set; } + public IFeatureCollection ConnectionFeatures { get; set; } public IList ConnectionAdapters { get; set; } public PipeFactory PipeFactory { get; set; } public IPEndPoint LocalEndPoint { get; set; } diff --git a/src/Kestrel.Core/Internal/Http/Frame.FeatureCollection.cs b/src/Kestrel.Core/Internal/Http/Frame.FeatureCollection.cs index f2457d0696..c922e2d1cf 100644 --- a/src/Kestrel.Core/Internal/Http/Frame.FeatureCollection.cs +++ b/src/Kestrel.Core/Internal/Http/Frame.FeatureCollection.cs @@ -251,13 +251,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http object IFeatureCollection.this[Type key] { - get => FastFeatureGet(key) ?? ConnectionFeatures?[key]; + get => FastFeatureGet(key) ?? ConnectionFeatures[key]; set => FastFeatureSet(key, value); } TFeature IFeatureCollection.Get() { - return (TFeature)(FastFeatureGet(typeof(TFeature)) ?? ConnectionFeatures?[typeof(TFeature)]); + return (TFeature)(FastFeatureGet(typeof(TFeature)) ?? ConnectionFeatures[typeof(TFeature)]); } void IFeatureCollection.Set(TFeature instance) @@ -294,7 +294,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http _wasUpgraded = true; - ServiceContext.ConnectionManager.NormalConnectionCount.ReleaseOne(); + ConnectionFeatures.Get()?.ReleaseConnection(); StatusCode = StatusCodes.Status101SwitchingProtocols; ReasonPhrase = "Switching Protocols"; diff --git a/src/Kestrel.Core/Internal/Http/Frame.cs b/src/Kestrel.Core/Internal/Http/Frame.cs index 3c56334f26..6195d79d5e 100644 --- a/src/Kestrel.Core/Internal/Http/Frame.cs +++ b/src/Kestrel.Core/Internal/Http/Frame.cs @@ -107,7 +107,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http private IPEndPoint LocalEndPoint => _frameContext.LocalEndPoint; private IPEndPoint RemoteEndPoint => _frameContext.RemoteEndPoint; - public IFeatureCollection ConnectionFeatures { get; set; } + public IFeatureCollection ConnectionFeatures => _frameContext.ConnectionFeatures; public IPipeReader Input => _frameContext.Transport.Input; public OutputProducer Output { get; } public ITimeoutControl TimeoutControl => _frameContext.TimeoutControl; diff --git a/src/Kestrel.Core/Internal/Http/FrameContext.cs b/src/Kestrel.Core/Internal/Http/FrameContext.cs index 5a52c03ea5..399c9ac6fe 100644 --- a/src/Kestrel.Core/Internal/Http/FrameContext.cs +++ b/src/Kestrel.Core/Internal/Http/FrameContext.cs @@ -3,6 +3,7 @@ using System.IO.Pipelines; using System.Net; +using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Protocols; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; @@ -12,6 +13,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { public string ConnectionId { get; set; } public ServiceContext ServiceContext { get; set; } + public IFeatureCollection ConnectionFeatures { get; set; } public PipeFactory PipeFactory { get; set; } public IPEndPoint RemoteEndPoint { get; set; } public IPEndPoint LocalEndPoint { get; set; } diff --git a/src/Kestrel.Core/Internal/HttpConnectionMiddleware.cs b/src/Kestrel.Core/Internal/HttpConnectionMiddleware.cs index b47ea9d603..62c51fb0f5 100644 --- a/src/Kestrel.Core/Internal/HttpConnectionMiddleware.cs +++ b/src/Kestrel.Core/Internal/HttpConnectionMiddleware.cs @@ -43,6 +43,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal ConnectionId = connectionContext.ConnectionId, FrameConnectionId = frameConnectionId, ServiceContext = _serviceContext, + ConnectionFeatures = connectionContext.Features, PipeFactory = connectionContext.PipeFactory, ConnectionAdapters = _connectionAdapters, Transport = connectionContext.Transport, diff --git a/src/Kestrel.Core/Internal/Infrastructure/FrameConnectionManager.cs b/src/Kestrel.Core/Internal/Infrastructure/FrameConnectionManager.cs index ed4c2d44ae..dc4d969ad7 100644 --- a/src/Kestrel.Core/Internal/Infrastructure/FrameConnectionManager.cs +++ b/src/Kestrel.Core/Internal/Infrastructure/FrameConnectionManager.cs @@ -11,23 +11,17 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure private readonly ConcurrentDictionary _connectionReferences = new ConcurrentDictionary(); private readonly IKestrelTrace _trace; - public FrameConnectionManager(IKestrelTrace trace, long? normalConnectionLimit, long? upgradedConnectionLimit) - : this(trace, GetCounter(normalConnectionLimit), GetCounter(upgradedConnectionLimit)) + public FrameConnectionManager(IKestrelTrace trace, long? upgradedConnectionLimit) + : this(trace, GetCounter(upgradedConnectionLimit)) { } - public FrameConnectionManager(IKestrelTrace trace, ResourceCounter normalConnections, ResourceCounter upgradedConnections) + public FrameConnectionManager(IKestrelTrace trace, ResourceCounter upgradedConnections) { - NormalConnectionCount = normalConnections; UpgradedConnectionCount = upgradedConnections; _trace = trace; } - /// - /// TCP connections processed by Kestrel. - /// - public ResourceCounter NormalConnectionCount { get; } - /// /// Connections that have been switched to a different protocol. /// diff --git a/src/Kestrel.Core/KestrelServer.cs b/src/Kestrel.Core/KestrelServer.cs index a1f5864f97..528ea80e7a 100644 --- a/src/Kestrel.Core/KestrelServer.cs +++ b/src/Kestrel.Core/KestrelServer.cs @@ -70,7 +70,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core var trace = new KestrelTrace(logger); var connectionManager = new FrameConnectionManager( trace, - serverOptions.Limits.MaxConcurrentConnections, serverOptions.Limits.MaxConcurrentUpgradedConnections); var systemClock = new SystemClock(); @@ -135,16 +134,18 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core async Task OnBind(ListenOptions endpoint) { - // Add the connection limit middleware - endpoint.UseConnectionLimit(ServiceContext); - - // Configure the user delegate - endpoint.Configure(endpoint); - // Add the HTTP middleware as the terminal connection middleware endpoint.UseHttpServer(endpoint.ConnectionAdapters, ServiceContext, application); - var connectionHandler = new ConnectionHandler(ServiceContext, endpoint.Build()); + var connectionDelegate = endpoint.Build(); + + // Add the connection limit middleware + if (Options.Limits.MaxConcurrentConnections.HasValue) + { + connectionDelegate = new ConnectionLimitMiddleware(connectionDelegate, Options.Limits.MaxConcurrentConnections.Value, Trace).OnConnectionAsync; + } + + var connectionHandler = new ConnectionHandler(ServiceContext, connectionDelegate); var transport = _transportFactory.Create(endpoint, connectionHandler); _transports.Add(transport); diff --git a/src/Kestrel.Core/KestrelServerLimits.cs b/src/Kestrel.Core/KestrelServerLimits.cs index eb061cf500..6cd16e9a6b 100644 --- a/src/Kestrel.Core/KestrelServerLimits.cs +++ b/src/Kestrel.Core/KestrelServerLimits.cs @@ -201,7 +201,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core } /// - /// Gets or sets the maximum number of open HTTP/S connections. When set to null, the number of connections is unlimited. + /// Gets or sets the maximum number of open connections. When set to null, the number of connections is unlimited. /// /// /// diff --git a/src/Kestrel.Core/KestrelServerOptions.cs b/src/Kestrel.Core/KestrelServerOptions.cs index 6a33639710..136b983533 100644 --- a/src/Kestrel.Core/KestrelServerOptions.cs +++ b/src/Kestrel.Core/KestrelServerOptions.cs @@ -100,7 +100,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core throw new ArgumentNullException(nameof(configure)); } - var listenOptions = new ListenOptions(endPoint) { KestrelServerOptions = this, Configure = configure }; + var listenOptions = new ListenOptions(endPoint) { KestrelServerOptions = this }; + configure(listenOptions); ListenOptions.Add(listenOptions); } @@ -131,7 +132,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core throw new ArgumentNullException(nameof(configure)); } - var listenOptions = new ListenOptions(socketPath) { KestrelServerOptions = this, Configure = configure }; + var listenOptions = new ListenOptions(socketPath) { KestrelServerOptions = this }; + configure(listenOptions); ListenOptions.Add(listenOptions); } @@ -154,7 +156,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core throw new ArgumentNullException(nameof(configure)); } - var listenOptions = new ListenOptions(handle) { KestrelServerOptions = this, Configure = configure }; + var listenOptions = new ListenOptions(handle) { KestrelServerOptions = this }; + configure(listenOptions); ListenOptions.Add(listenOptions); } } diff --git a/src/Kestrel.Core/ListenOptions.cs b/src/Kestrel.Core/ListenOptions.cs index f1f66209a2..f56b3c98be 100644 --- a/src/Kestrel.Core/ListenOptions.cs +++ b/src/Kestrel.Core/ListenOptions.cs @@ -131,8 +131,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core public IServiceProvider ApplicationServices => KestrelServerOptions?.ApplicationServices; - internal Action Configure { get; set; } = _ => { }; - /// /// Gets the name of this endpoint to display on command-line when the web server starts. /// diff --git a/test/Kestrel.Core.Tests/FrameConnectionManagerTests.cs b/test/Kestrel.Core.Tests/FrameConnectionManagerTests.cs index a6e6bb4879..a476c32ad1 100644 --- a/test/Kestrel.Core.Tests/FrameConnectionManagerTests.cs +++ b/test/Kestrel.Core.Tests/FrameConnectionManagerTests.cs @@ -18,7 +18,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests { var connectionId = "0"; var trace = new Mock(); - var frameConnectionManager = new FrameConnectionManager(trace.Object, ResourceCounter.Unlimited, ResourceCounter.Unlimited); + var frameConnectionManager = new FrameConnectionManager(trace.Object, ResourceCounter.Unlimited); // Create FrameConnection in inner scope so it doesn't get rooted by the current frame. UnrootedConnectionsGetRemovedFromHeartbeatInnerScope(connectionId, frameConnectionManager, trace); diff --git a/test/Kestrel.Core.Tests/FrameConnectionTests.cs b/test/Kestrel.Core.Tests/FrameConnectionTests.cs index b2418bf61a..847910d677 100644 --- a/test/Kestrel.Core.Tests/FrameConnectionTests.cs +++ b/test/Kestrel.Core.Tests/FrameConnectionTests.cs @@ -2,11 +2,10 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.IO.Pipelines; using System.Collections.Generic; -using System.Linq; +using System.IO.Pipelines; using System.Threading; -using System.Threading.Tasks; +using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; @@ -31,6 +30,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests { ConnectionId = "0123456789", ConnectionAdapters = new List(), + ConnectionFeatures = new FeatureCollection(), PipeFactory = _pipeFactory, FrameConnectionId = long.MinValue, Application = pair.Application, diff --git a/test/Kestrel.Core.Tests/FrameResponseHeadersTests.cs b/test/Kestrel.Core.Tests/FrameResponseHeadersTests.cs index 7c3dfa0f08..0bc399629c 100644 --- a/test/Kestrel.Core.Tests/FrameResponseHeadersTests.cs +++ b/test/Kestrel.Core.Tests/FrameResponseHeadersTests.cs @@ -2,10 +2,11 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.IO.Pipelines; using System.Collections.Generic; using System.Globalization; +using System.IO.Pipelines; using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; using Microsoft.AspNetCore.Testing; using Microsoft.Extensions.Primitives; @@ -23,6 +24,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests var frameContext = new FrameContext { ServiceContext = new TestServiceContext(), + ConnectionFeatures = new FeatureCollection(), PipeFactory = factory, Application = pair.Application, Transport = pair.Transport, diff --git a/test/Kestrel.Core.Tests/FrameTests.cs b/test/Kestrel.Core.Tests/FrameTests.cs index 57c8287284..eb7317c498 100644 --- a/test/Kestrel.Core.Tests/FrameTests.cs +++ b/test/Kestrel.Core.Tests/FrameTests.cs @@ -63,6 +63,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests _frameContext = new FrameContext { ServiceContext = _serviceContext, + ConnectionFeatures = new FeatureCollection(), PipeFactory = _pipelineFactory, TimeoutControl = _timeoutControl.Object, Application = pair.Application, diff --git a/test/Kestrel.Core.Tests/KestrelServerOptionsTests.cs b/test/Kestrel.Core.Tests/KestrelServerOptionsTests.cs index b34f92a1d4..2597862f80 100644 --- a/test/Kestrel.Core.Tests/KestrelServerOptionsTests.cs +++ b/test/Kestrel.Core.Tests/KestrelServerOptionsTests.cs @@ -18,9 +18,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests d.NoDelay = false; }); - // Execute the callback - o1.ListenOptions[1].Configure(o1.ListenOptions[1]); - Assert.True(o1.ListenOptions[0].NoDelay); Assert.False(o1.ListenOptions[1].NoDelay); } diff --git a/test/Kestrel.Core.Tests/TestInput.cs b/test/Kestrel.Core.Tests/TestInput.cs index 220f9393cd..9033c90d24 100644 --- a/test/Kestrel.Core.Tests/TestInput.cs +++ b/test/Kestrel.Core.Tests/TestInput.cs @@ -4,6 +4,7 @@ using System; using System.IO.Pipelines; using System.Text; +using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; using Microsoft.AspNetCore.Testing; @@ -27,6 +28,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests FrameContext = new FrameContext { ServiceContext = new TestServiceContext(), + ConnectionFeatures = new FeatureCollection(), Application = Application, Transport = Transport, PipeFactory = _pipelineFactory, diff --git a/test/Kestrel.FunctionalTests/ConnectionLimitTests.cs b/test/Kestrel.FunctionalTests/ConnectionLimitTests.cs index ffcde60a9d..0e63b8e88b 100644 --- a/test/Kestrel.FunctionalTests/ConnectionLimitTests.cs +++ b/test/Kestrel.FunctionalTests/ConnectionLimitTests.cs @@ -2,12 +2,13 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.IO; -using System.Net.Sockets; +using System.Net; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http.Features; +using Microsoft.AspNetCore.Server.Kestrel.Core; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Tests; using Microsoft.AspNetCore.Testing; @@ -23,15 +24,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests var requestTcs = new TaskCompletionSource(); var releasedTcs = new TaskCompletionSource(); var lockedTcs = new TaskCompletionSource(); - var (serviceContext, counter) = SetupMaxConnections(max: 1); + var counter = new EventRaisingResourceCounter(ResourceCounter.Quota(1)); counter.OnLock += (s, e) => lockedTcs.TrySetResult(e); counter.OnRelease += (s, e) => releasedTcs.TrySetResult(null); - using (var server = new TestServer(async context => + using (var server = CreateServerWithMaxConnections(async context => { await context.Response.WriteAsync("Hello"); await requestTcs.Task; - }, serviceContext)) + }, counter)) using (var connection = server.CreateConnection()) { await connection.SendEmptyGetAsKeepAlive(); ; @@ -46,8 +47,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [Fact] public async Task UpgradedConnectionsCountsAgainstDifferentLimit() { - var (serviceContext, _) = SetupMaxConnections(max: 1); - using (var server = new TestServer(async context => + using (var server = CreateServerWithMaxConnections(async context => { var feature = context.Features.Get(); if (feature.IsUpgradableRequest) @@ -59,7 +59,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests await Task.Delay(100); } } - }, serviceContext)) + }, max: 1)) using (var disposables = new DisposableStack()) { var upgraded = server.CreateConnection(); @@ -81,7 +81,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { // this may throw IOException, depending on how fast Kestrel closes the socket await rejected.SendEmptyGetAsKeepAlive(); - } catch { } + } + catch { } // connection should close without sending any data await rejected.WaitForConnectionClose().TimeoutAfter(TimeSpan.FromSeconds(15)); @@ -93,14 +94,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests public async Task RejectsConnectionsWhenLimitReached() { const int max = 10; - var (serviceContext, _) = SetupMaxConnections(max); var requestTcs = new TaskCompletionSource(); - using (var server = new TestServer(async context => + using (var server = CreateServerWithMaxConnections(async context => { await context.Response.WriteAsync("Hello"); await requestTcs.Task; - }, serviceContext)) + }, max)) using (var disposables = new DisposableStack()) { for (var i = 0; i < max; i++) @@ -141,7 +141,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests var openedTcs = new TaskCompletionSource(); var closedTcs = new TaskCompletionSource(); - var (serviceContext, counter) = SetupMaxConnections(uint.MaxValue); + var counter = new EventRaisingResourceCounter(ResourceCounter.Quota(uint.MaxValue)); counter.OnLock += (o, e) => { @@ -159,7 +159,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } }; - using (var server = new TestServer(_ => Task.CompletedTask, serviceContext)) + using (var server = CreateServerWithMaxConnections(_ => Task.CompletedTask, counter)) { // open a bunch of connections in parallel Parallel.For(0, count, async i => @@ -187,12 +187,24 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } } - private (TestServiceContext serviceContext, EventRaisingResourceCounter counter) SetupMaxConnections(long max) + private TestServer CreateServerWithMaxConnections(RequestDelegate app, long max) { - var counter = new EventRaisingResourceCounter(ResourceCounter.Quota(max)); var serviceContext = new TestServiceContext(); - serviceContext.ConnectionManager = new FrameConnectionManager(serviceContext.Log, counter, ResourceCounter.Unlimited); - return (serviceContext, counter); + serviceContext.ServerOptions.Limits.MaxConcurrentConnections = max; + return new TestServer(app, serviceContext); + } + + private TestServer CreateServerWithMaxConnections(RequestDelegate app, ResourceCounter concurrentConnectionCounter) + { + var serviceContext = new TestServiceContext(); + var listenOptions = new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0)); + listenOptions.Use(next => + { + var middleware = new ConnectionLimitMiddleware(next, concurrentConnectionCounter, serviceContext.Log); + return middleware.OnConnectionAsync; + }); + + return new TestServer(app, serviceContext, listenOptions); } } } diff --git a/test/Kestrel.FunctionalTests/TestHelpers/TestServer.cs b/test/Kestrel.FunctionalTests/TestHelpers/TestServer.cs index 6e85ab30fa..5e36ddf4af 100644 --- a/test/Kestrel.FunctionalTests/TestHelpers/TestServer.cs +++ b/test/Kestrel.FunctionalTests/TestHelpers/TestServer.cs @@ -14,7 +14,6 @@ using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; using Microsoft.AspNetCore.Testing; using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests diff --git a/test/Kestrel.FunctionalTests/UpgradeTests.cs b/test/Kestrel.FunctionalTests/UpgradeTests.cs index f16c7c6466..d2578dd393 100644 --- a/test/Kestrel.FunctionalTests/UpgradeTests.cs +++ b/test/Kestrel.FunctionalTests/UpgradeTests.cs @@ -260,7 +260,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests const int limit = 10; var upgradeTcs = new TaskCompletionSource(); var serviceContext = new TestServiceContext(); - serviceContext.ConnectionManager = new FrameConnectionManager(serviceContext.Log, ResourceCounter.Unlimited, ResourceCounter.Quota(limit)); + serviceContext.ConnectionManager = new FrameConnectionManager(serviceContext.Log, ResourceCounter.Quota(limit)); using (var server = new TestServer(async context => { diff --git a/test/Kestrel.Transport.Libuv.Tests/LibuvOutputConsumerTests.cs b/test/Kestrel.Transport.Libuv.Tests/LibuvOutputConsumerTests.cs index cd604be6f1..09a88c883d 100644 --- a/test/Kestrel.Transport.Libuv.Tests/LibuvOutputConsumerTests.cs +++ b/test/Kestrel.Transport.Libuv.Tests/LibuvOutputConsumerTests.cs @@ -6,6 +6,7 @@ using System.Collections.Concurrent; using System.IO.Pipelines; using System.Threading; using System.Threading.Tasks; +using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; @@ -699,6 +700,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests var frame = new Frame(null, new FrameContext { ServiceContext = serviceContext, + ConnectionFeatures = new FeatureCollection(), PipeFactory = _pipeFactory, TimeoutControl = Mock.Of(), Application = pair.Application, diff --git a/test/shared/TestServiceContext.cs b/test/shared/TestServiceContext.cs index 61487222d7..5661d3678f 100644 --- a/test/shared/TestServiceContext.cs +++ b/test/shared/TestServiceContext.cs @@ -38,7 +38,7 @@ namespace Microsoft.AspNetCore.Testing ThreadPool = new LoggingThreadPool(Log); SystemClock = new MockSystemClock(); DateHeaderValueManager = new DateHeaderValueManager(SystemClock); - ConnectionManager = new FrameConnectionManager(Log, ResourceCounter.Unlimited, ResourceCounter.Unlimited); + ConnectionManager = new FrameConnectionManager(Log, ResourceCounter.Unlimited); HttpParserFactory = frameAdapter => new HttpParser(frameAdapter.Frame.ServiceContext.Log.IsEnabled(LogLevel.Information)); ServerOptions = new KestrelServerOptions { From f0ade24cf784fbadd8dfa3644497981d2144377f Mon Sep 17 00:00:00 2001 From: Vladimir Sadov Date: Wed, 6 Sep 2017 15:52:47 -0700 Subject: [PATCH 1397/1662] Updating to new toolset compiler. (#2043) * Updating to new toolset compiler. Now includes ref escaping rules. * newer version. --- Directory.Build.props | 2 +- src/Kestrel.Core/Internal/Http/HttpParser.cs | 9 ++++----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/Directory.Build.props b/Directory.Build.props index d491401790..b73f252569 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -14,7 +14,7 @@ - + + CurrentRuntime diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/baseline.netcore.json b/src/Kestrel.Core/baseline.netcore.json similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Core/baseline.netcore.json rename to src/Kestrel.Core/baseline.netcore.json diff --git a/src/Kestrel.Https/Kestrel.Https.csproj b/src/Kestrel.Https/Kestrel.Https.csproj index 284c7f6fb3..e99a6f7423 100644 --- a/src/Kestrel.Https/Kestrel.Https.csproj +++ b/src/Kestrel.Https/Kestrel.Https.csproj @@ -8,7 +8,8 @@ true aspnetcore;kestrel CS1591;$(NoWarn) - false + + CurrentRuntime diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Https/baseline.netcore.json b/src/Kestrel.Https/baseline.netcore.json similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Https/baseline.netcore.json rename to src/Kestrel.Https/baseline.netcore.json diff --git a/src/Kestrel.Transport.Abstractions/Kestrel.Transport.Abstractions.csproj b/src/Kestrel.Transport.Abstractions/Kestrel.Transport.Abstractions.csproj index a9e754a8ad..cfbd7353cf 100644 --- a/src/Kestrel.Transport.Abstractions/Kestrel.Transport.Abstractions.csproj +++ b/src/Kestrel.Transport.Abstractions/Kestrel.Transport.Abstractions.csproj @@ -8,7 +8,6 @@ true aspnetcore;kestrel CS1570;CS1571;CS1572;CS1573;CS1574;CS1591;$(NoWarn) - false true false diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/baseline.netcore.json b/src/Kestrel.Transport.Abstractions/baseline.netcore.json similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions/baseline.netcore.json rename to src/Kestrel.Transport.Abstractions/baseline.netcore.json diff --git a/src/Kestrel.Transport.Libuv/Kestrel.Transport.Libuv.csproj b/src/Kestrel.Transport.Libuv/Kestrel.Transport.Libuv.csproj index d7324df34d..4251d64cea 100644 --- a/src/Kestrel.Transport.Libuv/Kestrel.Transport.Libuv.csproj +++ b/src/Kestrel.Transport.Libuv/Kestrel.Transport.Libuv.csproj @@ -9,7 +9,6 @@ aspnetcore;kestrel true CS1591;$(NoWarn) - false diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/baseline.netcore.json b/src/Kestrel.Transport.Libuv/baseline.netcore.json similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/baseline.netcore.json rename to src/Kestrel.Transport.Libuv/baseline.netcore.json diff --git a/src/Kestrel.Transport.Sockets/Kestrel.Transport.Sockets.csproj b/src/Kestrel.Transport.Sockets/Kestrel.Transport.Sockets.csproj index 9d1f419dc3..af86b481a2 100644 --- a/src/Kestrel.Transport.Sockets/Kestrel.Transport.Sockets.csproj +++ b/src/Kestrel.Transport.Sockets/Kestrel.Transport.Sockets.csproj @@ -9,7 +9,8 @@ aspnetcore;kestrel true CS1591;$(NoWarn) - false + + CurrentRuntime diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets/baseline.netcore.json b/src/Kestrel.Transport.Sockets/baseline.netcore.json similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets/baseline.netcore.json rename to src/Kestrel.Transport.Sockets/baseline.netcore.json diff --git a/src/Kestrel/Kestrel.csproj b/src/Kestrel/Kestrel.csproj index ab269185a2..cdd0e1bc70 100644 --- a/src/Kestrel/Kestrel.csproj +++ b/src/Kestrel/Kestrel.csproj @@ -8,7 +8,6 @@ true aspnetcore;kestrel CS1591;$(NoWarn) - false diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/baseline.netcore.json b/src/Kestrel/baseline.netcore.json similarity index 100% rename from src/Microsoft.AspNetCore.Server.Kestrel/baseline.netcore.json rename to src/Kestrel/baseline.netcore.json From 551c1ebc0b699dd2a39c6a19a07e351d2736ece6 Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Wed, 27 Sep 2017 10:14:39 -0700 Subject: [PATCH 1417/1662] Configure enabled protocols per endpoint and add HTTP/2 w/ prior knowledge support (#2067). --- src/Kestrel.Core/CoreStrings.resx | 9 ++ src/Kestrel.Core/HttpProtocols.cs | 16 ++++ src/Kestrel.Core/Internal/HttpConnection.cs | 57 ++++++++++- .../HttpConnectionBuilderExtensions.cs | 14 +-- .../Internal/HttpConnectionContext.cs | 1 + .../Internal/HttpConnectionMiddleware.cs | 8 +- src/Kestrel.Core/KestrelServer.cs | 2 +- src/Kestrel.Core/ListenOptions.cs | 6 ++ .../Properties/CoreStrings.Designer.cs | 42 ++++++++ src/Kestrel.Tls/ListenOptionsTlsExtensions.cs | 3 +- src/Kestrel.Tls/TlsConnectionAdapter.cs | 15 ++- .../TlsConnectionAdapterOptions.cs | 4 + .../Kestrel.Core.Tests/HttpConnectionTests.cs | 10 ++ test/Kestrel.Core.Tests/ListenOptionsTests.cs | 18 ++++ .../HttpProtocolSelectionTests.cs | 96 +++++++++++++++++++ .../LibuvTransportTests.cs | 2 +- .../ListenerPrimaryTests.cs | 12 +-- 17 files changed, 292 insertions(+), 23 deletions(-) create mode 100644 src/Kestrel.Core/HttpProtocols.cs create mode 100644 test/Kestrel.Core.Tests/ListenOptionsTests.cs create mode 100644 test/Kestrel.FunctionalTests/HttpProtocolSelectionTests.cs diff --git a/src/Kestrel.Core/CoreStrings.resx b/src/Kestrel.Core/CoreStrings.resx index eb0cff90a5..6fea320658 100644 --- a/src/Kestrel.Core/CoreStrings.resx +++ b/src/Kestrel.Core/CoreStrings.resx @@ -351,4 +351,13 @@ Timespan must be positive and finite. + + An endpoint must be configured to serve at least one protocol. + + + Using both HTTP/1.x and HTTP/2 on the same endpoint requires the use of TLS. + + + HTTP/2 over TLS was not negotiated on an HTTP/2-only endpoint. + \ No newline at end of file diff --git a/src/Kestrel.Core/HttpProtocols.cs b/src/Kestrel.Core/HttpProtocols.cs new file mode 100644 index 0000000000..09524bf156 --- /dev/null +++ b/src/Kestrel.Core/HttpProtocols.cs @@ -0,0 +1,16 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; + +namespace Microsoft.AspNetCore.Server.Kestrel.Core +{ + [Flags] + public enum HttpProtocols + { + None = 0x0, + Http1 = 0x1, + Http2 = 0x2, + Http1AndHttp2 = Http1 | Http2, + } +} diff --git a/src/Kestrel.Core/Internal/HttpConnection.cs b/src/Kestrel.Core/Internal/HttpConnection.cs index 9ccca7d182..099446058b 100644 --- a/src/Kestrel.Core/Internal/HttpConnection.cs +++ b/src/Kestrel.Core/Internal/HttpConnection.cs @@ -10,6 +10,7 @@ using System.Net; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Hosting.Server; +using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal; using Microsoft.AspNetCore.Server.Kestrel.Core.Features; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; @@ -135,8 +136,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal adaptedPipelineTask = adaptedPipeline.RunAsync(stream); } - if (_http1Connection.ConnectionFeatures.Get()?.ApplicationProtocol == "h2" && - Interlocked.CompareExchange(ref _http2ConnectionState, Http2ConnectionStarted, Http2ConnectionNotStarted) == Http2ConnectionNotStarted) + var protocol = SelectProtocol(); + + if (protocol == HttpProtocols.None) + { + Abort(ex: null); + } + + // One of these has to run even if no protocol was selected so the abort propagates and everything completes properly + if (protocol == HttpProtocols.Http2 && Interlocked.CompareExchange(ref _http2ConnectionState, Http2ConnectionStarted, Http2ConnectionNotStarted) == Http2ConnectionNotStarted) { await _http2Connection.ProcessAsync(httpApplication); } @@ -207,6 +215,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal public Task StopProcessingNextRequestAsync() { Debug.Assert(_http1Connection != null, $"{nameof(_http1Connection)} is null"); + Debug.Assert(_http2Connection != null, $"{nameof(_http2Connection)} is null"); if (Interlocked.Exchange(ref _http2ConnectionState, Http2ConnectionClosed) == Http2ConnectionStarted) { @@ -223,6 +232,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal public void Abort(Exception ex) { Debug.Assert(_http1Connection != null, $"{nameof(_http1Connection)} is null"); + Debug.Assert(_http2Connection != null, $"{nameof(_http2Connection)} is null"); // Abort the connection (if not already aborted) if (Interlocked.Exchange(ref _http2ConnectionState, Http2ConnectionClosed) == Http2ConnectionStarted) @@ -245,6 +255,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal public void SendTimeoutResponse() { Debug.Assert(_http1Connection != null, $"{nameof(_http1Connection)} is null"); + Debug.Assert(_http2Connection != null, $"{nameof(_http2Connection)} is null"); RequestTimedOut = true; _http1Connection.SendTimeoutResponse(); @@ -253,6 +264,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal public void StopProcessingNextRequest() { Debug.Assert(_http1Connection != null, $"{nameof(_http1Connection)} is null"); + Debug.Assert(_http2Connection != null, $"{nameof(_http2Connection)} is null"); _http1Connection.StopProcessingNextRequest(); } @@ -260,10 +272,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal private async Task ApplyConnectionAdaptersAsync() { Debug.Assert(_http1Connection != null, $"{nameof(_http1Connection)} is null"); + Debug.Assert(_http2Connection != null, $"{nameof(_http2Connection)} is null"); var connectionAdapters = _context.ConnectionAdapters; var stream = new RawStream(_context.Transport.Input, _context.Transport.Output); - var adapterContext = new ConnectionAdapterContext(_http1Connection.ConnectionFeatures, stream); + var adapterContext = new ConnectionAdapterContext(_context.ConnectionFeatures, stream); _adaptedConnections = new List(connectionAdapters.Count); try @@ -272,7 +285,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal { var adaptedConnection = await connectionAdapters[i].OnConnectionAsync(adapterContext); _adaptedConnections.Add(adaptedConnection); - adapterContext = new ConnectionAdapterContext(_http1Connection.ConnectionFeatures, adaptedConnection.ConnectionStream); + adapterContext = new ConnectionAdapterContext(_context.ConnectionFeatures, adaptedConnection.ConnectionStream); } } catch (Exception ex) @@ -290,16 +303,50 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal var adaptedConnections = _adaptedConnections; if (adaptedConnections != null) { - for (int i = adaptedConnections.Count - 1; i >= 0; i--) + for (var i = adaptedConnections.Count - 1; i >= 0; i--) { adaptedConnections[i].Dispose(); } } } + private HttpProtocols SelectProtocol() + { + var hasTls = _context.ConnectionFeatures.Get() != null; + var applicationProtocol = _context.ConnectionFeatures.Get()?.ApplicationProtocol; + var http1Enabled = (_context.Protocols & HttpProtocols.Http1) == HttpProtocols.Http1; + var http2Enabled = (_context.Protocols & HttpProtocols.Http2) == HttpProtocols.Http2; + + string error = null; + + if (_context.Protocols == HttpProtocols.None) + { + error = CoreStrings.EndPointRequiresAtLeastOneProtocol; + } + + if (!hasTls && http1Enabled && http2Enabled) + { + error = CoreStrings.EndPointRequiresTlsForHttp1AndHttp2; + } + + if (!http1Enabled && http2Enabled && hasTls && applicationProtocol != "h2") + { + error = CoreStrings.EndPointHttp2NotNegotiated; + } + + if (error != null) + { + Log.LogError(0, error); + return HttpProtocols.None; + } + + return http2Enabled && (!hasTls || applicationProtocol == "h2") ? HttpProtocols.Http2 : HttpProtocols.Http1; + } + public void Tick(DateTimeOffset now) { Debug.Assert(_http1Connection != null, $"{nameof(_http1Connection)} is null"); + Debug.Assert(_http2Connection != null, $"{nameof(_http2Connection)} is null"); var timestamp = now.Ticks; diff --git a/src/Kestrel.Core/Internal/HttpConnectionBuilderExtensions.cs b/src/Kestrel.Core/Internal/HttpConnectionBuilderExtensions.cs index ca3ca5c9ab..ed57343f27 100644 --- a/src/Kestrel.Core/Internal/HttpConnectionBuilderExtensions.cs +++ b/src/Kestrel.Core/Internal/HttpConnectionBuilderExtensions.cs @@ -1,6 +1,8 @@ -using System; +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; using System.Collections.Generic; -using System.Text; using Microsoft.AspNetCore.Hosting.Server; using Microsoft.AspNetCore.Protocols; using Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal; @@ -9,14 +11,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal { public static class HttpConnectionBuilderExtensions { - public static IConnectionBuilder UseHttpServer(this IConnectionBuilder builder, ServiceContext serviceContext, IHttpApplication application) + public static IConnectionBuilder UseHttpServer(this IConnectionBuilder builder, ServiceContext serviceContext, IHttpApplication application, HttpProtocols protocols) { - return builder.UseHttpServer(Array.Empty(), serviceContext, application); + return builder.UseHttpServer(Array.Empty(), serviceContext, application, protocols); } - public static IConnectionBuilder UseHttpServer(this IConnectionBuilder builder, IList adapters, ServiceContext serviceContext, IHttpApplication application) + public static IConnectionBuilder UseHttpServer(this IConnectionBuilder builder, IList adapters, ServiceContext serviceContext, IHttpApplication application, HttpProtocols protocols) { - var middleware = new HttpConnectionMiddleware(adapters, serviceContext, application); + var middleware = new HttpConnectionMiddleware(adapters, serviceContext, application, protocols); return builder.Use(next => { return middleware.OnConnectionAsync; diff --git a/src/Kestrel.Core/Internal/HttpConnectionContext.cs b/src/Kestrel.Core/Internal/HttpConnectionContext.cs index 9993070689..67298c0544 100644 --- a/src/Kestrel.Core/Internal/HttpConnectionContext.cs +++ b/src/Kestrel.Core/Internal/HttpConnectionContext.cs @@ -13,6 +13,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal { public string ConnectionId { get; set; } public long HttpConnectionId { get; set; } + public HttpProtocols Protocols { get; set; } public ServiceContext ServiceContext { get; set; } public IFeatureCollection ConnectionFeatures { get; set; } public IList ConnectionAdapters { get; set; } diff --git a/src/Kestrel.Core/Internal/HttpConnectionMiddleware.cs b/src/Kestrel.Core/Internal/HttpConnectionMiddleware.cs index 4b342f20c1..d2b0757fcb 100644 --- a/src/Kestrel.Core/Internal/HttpConnectionMiddleware.cs +++ b/src/Kestrel.Core/Internal/HttpConnectionMiddleware.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.IO.Pipelines; using System.Net; using System.Threading; using System.Threading.Tasks; @@ -8,6 +9,8 @@ using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Protocols; using Microsoft.AspNetCore.Protocols.Features; using Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal { @@ -20,11 +23,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal private readonly IList _connectionAdapters; private readonly ServiceContext _serviceContext; private readonly IHttpApplication _application; + private readonly HttpProtocols _protocols; - public HttpConnectionMiddleware(IList adapters, ServiceContext serviceContext, IHttpApplication application) + public HttpConnectionMiddleware(IList adapters, ServiceContext serviceContext, IHttpApplication application, HttpProtocols protocols) { _serviceContext = serviceContext; _application = application; + _protocols = protocols; // Keeping these around for now so progress can be made without updating tests _connectionAdapters = adapters; @@ -42,6 +47,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal { ConnectionId = connectionContext.ConnectionId, HttpConnectionId = httpConnectionId, + Protocols = _protocols, ServiceContext = _serviceContext, ConnectionFeatures = connectionContext.Features, PipeFactory = connectionContext.PipeFactory, diff --git a/src/Kestrel.Core/KestrelServer.cs b/src/Kestrel.Core/KestrelServer.cs index 8182c1e6c9..fac999d904 100644 --- a/src/Kestrel.Core/KestrelServer.cs +++ b/src/Kestrel.Core/KestrelServer.cs @@ -135,7 +135,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core async Task OnBind(ListenOptions endpoint) { // Add the HTTP middleware as the terminal connection middleware - endpoint.UseHttpServer(endpoint.ConnectionAdapters, ServiceContext, application); + endpoint.UseHttpServer(endpoint.ConnectionAdapters, ServiceContext, application, endpoint.Protocols); var connectionDelegate = endpoint.Build(); diff --git a/src/Kestrel.Core/ListenOptions.cs b/src/Kestrel.Core/ListenOptions.cs index f56b3c98be..19e94c43a6 100644 --- a/src/Kestrel.Core/ListenOptions.cs +++ b/src/Kestrel.Core/ListenOptions.cs @@ -118,6 +118,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core /// public bool NoDelay { get; set; } = true; + /// + /// The protocols enabled on this endpoint. + /// + /// Defaults to HTTP/1.x only. + public HttpProtocols Protocols { get; set; } = HttpProtocols.Http1; + /// /// Gets the that allows each connection /// to be intercepted and transformed. diff --git a/src/Kestrel.Core/Properties/CoreStrings.Designer.cs b/src/Kestrel.Core/Properties/CoreStrings.Designer.cs index 0d7341ba08..2fa3c085eb 100644 --- a/src/Kestrel.Core/Properties/CoreStrings.Designer.cs +++ b/src/Kestrel.Core/Properties/CoreStrings.Designer.cs @@ -1102,6 +1102,48 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core internal static string FormatPositiveFiniteTimeSpanRequired() => GetString("PositiveFiniteTimeSpanRequired"); + /// + /// An endpoint must be configured to serve at least one protocol. + /// + internal static string EndPointRequiresAtLeastOneProtocol + { + get => GetString("EndPointRequiresAtLeastOneProtocol"); + } + + /// + /// An endpoint must be configured to serve at least one protocol. + /// + internal static string FormatEndPointRequiresAtLeastOneProtocol() + => GetString("EndPointRequiresAtLeastOneProtocol"); + + /// + /// Using both HTTP/1.x and HTTP/2 on the same endpoint requires the use of TLS. + /// + internal static string EndPointRequiresTlsForHttp1AndHttp2 + { + get => GetString("EndPointRequiresTlsForHttp1AndHttp2"); + } + + /// + /// Using both HTTP/1.x and HTTP/2 on the same endpoint requires the use of TLS. + /// + internal static string FormatEndPointRequiresTlsForHttp1AndHttp2() + => GetString("EndPointRequiresTlsForHttp1AndHttp2"); + + /// + /// HTTP/2 over TLS was not negotiated on an HTTP/2-only endpoint. + /// + internal static string EndPointHttp2NotNegotiated + { + get => GetString("EndPointHttp2NotNegotiated"); + } + + /// + /// HTTP/2 over TLS was not negotiated on an HTTP/2-only endpoint. + /// + internal static string FormatEndPointHttp2NotNegotiated() + => GetString("EndPointHttp2NotNegotiated"); + private static string GetString(string name, params string[] formatterNames) { var value = _resourceManager.GetString(name); diff --git a/src/Kestrel.Tls/ListenOptionsTlsExtensions.cs b/src/Kestrel.Tls/ListenOptionsTlsExtensions.cs index 85011e6227..cb2c459152 100644 --- a/src/Kestrel.Tls/ListenOptionsTlsExtensions.cs +++ b/src/Kestrel.Tls/ListenOptionsTlsExtensions.cs @@ -15,7 +15,8 @@ namespace Microsoft.AspNetCore.Hosting return listenOptions.UseTls(new TlsConnectionAdapterOptions { CertificatePath = certificatePath, - PrivateKeyPath = privateKeyPath + PrivateKeyPath = privateKeyPath, + Protocols = listenOptions.Protocols }); } diff --git a/src/Kestrel.Tls/TlsConnectionAdapter.cs b/src/Kestrel.Tls/TlsConnectionAdapter.cs index 0dae1b701c..539c8404f3 100644 --- a/src/Kestrel.Tls/TlsConnectionAdapter.cs +++ b/src/Kestrel.Tls/TlsConnectionAdapter.cs @@ -4,9 +4,9 @@ using System; using System.Collections.Generic; using System.IO; -using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Http.Features; +using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal; using Microsoft.AspNetCore.Server.Kestrel.Core.Features; using Microsoft.Extensions.Logging; @@ -16,7 +16,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Tls public class TlsConnectionAdapter : IConnectionAdapter { private static readonly ClosedAdaptedConnection _closedAdaptedConnection = new ClosedAdaptedConnection(); - private static readonly HashSet _serverProtocols = new HashSet(new[] { "h2", "http/1.1" }); + private static readonly List _serverProtocols = new List(); private readonly TlsConnectionAdapterOptions _options; private readonly ILogger _logger; @@ -47,6 +47,17 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Tls _options = options; _logger = loggerFactory?.CreateLogger(nameof(TlsConnectionAdapter)); + + // Order is important. If HTTP/2 is enabled, we prefer it over HTTP/1.1. So add it first. + if ((options.Protocols & HttpProtocols.Http2) == HttpProtocols.Http2) + { + _serverProtocols.Add("h2"); + } + + if ((options.Protocols & HttpProtocols.Http1) == HttpProtocols.Http1) + { + _serverProtocols.Add("http/1.1"); + } } public bool IsHttps => true; diff --git a/src/Kestrel.Tls/TlsConnectionAdapterOptions.cs b/src/Kestrel.Tls/TlsConnectionAdapterOptions.cs index 0d49b62b69..88d107ffdd 100644 --- a/src/Kestrel.Tls/TlsConnectionAdapterOptions.cs +++ b/src/Kestrel.Tls/TlsConnectionAdapterOptions.cs @@ -1,6 +1,8 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using Microsoft.AspNetCore.Server.Kestrel.Core; + namespace Microsoft.AspNetCore.Server.Kestrel.Tls { public class TlsConnectionAdapterOptions @@ -8,5 +10,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Tls public string CertificatePath { get; set; } = string.Empty; public string PrivateKeyPath { get; set; } = string.Empty; + + public HttpProtocols Protocols { get; set; } } } diff --git a/test/Kestrel.Core.Tests/HttpConnectionTests.cs b/test/Kestrel.Core.Tests/HttpConnectionTests.cs index f1f887ddc2..4eebb7a7ae 100644 --- a/test/Kestrel.Core.Tests/HttpConnectionTests.cs +++ b/test/Kestrel.Core.Tests/HttpConnectionTests.cs @@ -56,6 +56,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests mockDebugger.SetupGet(g => g.IsAttached).Returns(true); _httpConnection.Debugger = mockDebugger.Object; _httpConnection.CreateHttp1Connection(new DummyApplication(), _httpConnectionContext.Transport, _httpConnectionContext.Application); + _httpConnection.CreateHttp2Connection(new DummyApplication(), _httpConnectionContext.Transport, _httpConnectionContext.Application); var now = DateTimeOffset.Now; _httpConnection.Tick(now); @@ -103,6 +104,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests _httpConnectionContext.ServiceContext.Log = logger; _httpConnection.CreateHttp1Connection(new DummyApplication(), _httpConnectionContext.Transport, _httpConnectionContext.Application); + _httpConnection.CreateHttp2Connection(new DummyApplication(), _httpConnectionContext.Transport, _httpConnectionContext.Application); _httpConnection.Http1Connection.Reset(); // Initialize timestamp @@ -130,6 +132,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests _httpConnectionContext.ServiceContext.Log = mockLogger.Object; _httpConnection.CreateHttp1Connection(new DummyApplication(), _httpConnectionContext.Transport, _httpConnectionContext.Application); + _httpConnection.CreateHttp2Connection(new DummyApplication(), _httpConnectionContext.Transport, _httpConnectionContext.Application); _httpConnection.Http1Connection.Reset(); // Initialize timestamp @@ -172,6 +175,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests _httpConnectionContext.ServiceContext.Log = mockLogger.Object; _httpConnection.CreateHttp1Connection(new DummyApplication(), _httpConnectionContext.Transport, _httpConnectionContext.Application); + _httpConnection.CreateHttp2Connection(new DummyApplication(), _httpConnectionContext.Transport, _httpConnectionContext.Application); _httpConnection.Http1Connection.Reset(); // Initialize timestamp @@ -249,6 +253,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests _httpConnectionContext.ServiceContext.Log = mockLogger.Object; _httpConnection.CreateHttp1Connection(new DummyApplication(), _httpConnectionContext.Transport, _httpConnectionContext.Application); + _httpConnection.CreateHttp2Connection(new DummyApplication(), _httpConnectionContext.Transport, _httpConnectionContext.Application); _httpConnection.Http1Connection.Reset(); // Initialize timestamp @@ -317,6 +322,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests _httpConnectionContext.ServiceContext.Log = mockLogger.Object; _httpConnection.CreateHttp1Connection(new DummyApplication(), _httpConnectionContext.Transport, _httpConnectionContext.Application); + _httpConnection.CreateHttp2Connection(new DummyApplication(), _httpConnectionContext.Transport, _httpConnectionContext.Application); _httpConnection.Http1Connection.Reset(); // Initialize timestamp @@ -379,6 +385,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests _httpConnectionContext.ServiceContext.Log = mockLogger.Object; _httpConnection.CreateHttp1Connection(new DummyApplication(), _httpConnectionContext.Transport, _httpConnectionContext.Application); + _httpConnection.CreateHttp2Connection(new DummyApplication(), _httpConnectionContext.Transport, _httpConnectionContext.Application); _httpConnection.Http1Connection.Reset(); var startTime = systemClock.UtcNow; @@ -420,6 +427,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests _httpConnectionContext.ServiceContext.Log = mockLogger.Object; _httpConnection.CreateHttp1Connection(new DummyApplication(), _httpConnectionContext.Transport, _httpConnectionContext.Application); + _httpConnection.CreateHttp2Connection(new DummyApplication(), _httpConnectionContext.Transport, _httpConnectionContext.Application); _httpConnection.Http1Connection.Reset(); _httpConnection.Http1Connection.RequestAborted.Register(() => { @@ -454,6 +462,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests _httpConnectionContext.ServiceContext.Log = mockLogger.Object; _httpConnection.CreateHttp1Connection(new DummyApplication(), _httpConnectionContext.Transport, _httpConnectionContext.Application); + _httpConnection.CreateHttp2Connection(new DummyApplication(), _httpConnectionContext.Transport, _httpConnectionContext.Application); _httpConnection.Http1Connection.Reset(); _httpConnection.Http1Connection.RequestAborted.Register(() => { @@ -496,6 +505,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests _httpConnectionContext.ServiceContext.Log = mockLogger.Object; _httpConnection.CreateHttp1Connection(new DummyApplication(), _httpConnectionContext.Transport, _httpConnectionContext.Application); + _httpConnection.CreateHttp2Connection(new DummyApplication(), _httpConnectionContext.Transport, _httpConnectionContext.Application); _httpConnection.Http1Connection.Reset(); _httpConnection.Http1Connection.RequestAborted.Register(() => { diff --git a/test/Kestrel.Core.Tests/ListenOptionsTests.cs b/test/Kestrel.Core.Tests/ListenOptionsTests.cs new file mode 100644 index 0000000000..89d495876f --- /dev/null +++ b/test/Kestrel.Core.Tests/ListenOptionsTests.cs @@ -0,0 +1,18 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System.Net; +using Xunit; + +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests +{ + public class ListenOptionsTests + { + [Fact] + public void ProtocolsDefault() + { + var listenOptions = new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0)); + Assert.Equal(HttpProtocols.Http1, listenOptions.Protocols); + } + } +} diff --git a/test/Kestrel.FunctionalTests/HttpProtocolSelectionTests.cs b/test/Kestrel.FunctionalTests/HttpProtocolSelectionTests.cs new file mode 100644 index 0000000000..7b665d5ef1 --- /dev/null +++ b/test/Kestrel.FunctionalTests/HttpProtocolSelectionTests.cs @@ -0,0 +1,96 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Net; +using System.Text; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Server.Kestrel.Core; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2; +using Microsoft.AspNetCore.Testing; +using Microsoft.Extensions.Logging; +using Moq; +using Xunit; + +namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests +{ + public class HttpProtocolSelectionTests + { + [Fact] + public Task Server_NoProtocols_Error() + { + return TestError(HttpProtocols.None, CoreStrings.EndPointRequiresAtLeastOneProtocol); + } + + [Fact] + public Task Server_Http1AndHttp2_Cleartext_Error() + { + return TestError(HttpProtocols.Http1AndHttp2, CoreStrings.EndPointRequiresTlsForHttp1AndHttp2); + } + + [Fact] + public Task Server_Http1Only_Cleartext_Success() + { + return TestSuccess(HttpProtocols.Http1, "GET / HTTP/1.1\r\nHost:\r\n\r\n", "HTTP/1.1 200 OK"); + } + + [Fact] + public Task Server_Http2Only_Cleartext_Success() + { + // Expect a SETTINGS frame (type 0x4) with no payload and no flags + return TestSuccess(HttpProtocols.Http2, Encoding.ASCII.GetString(Http2Connection.ClientPreface), "\x00\x00\x00\x04\x00\x00\x00\x00\x00"); + } + + private async Task TestSuccess(HttpProtocols serverProtocols, string request, string expectedResponse) + { + var builder = new WebHostBuilder() + .UseKestrel(options => + { + options.Listen(IPAddress.Loopback, 0, listenOptions => listenOptions.Protocols = serverProtocols); + }) + .Configure(app => app.Run(context => Task.CompletedTask)); + + using (var host = builder.Build()) + { + host.Start(); + + using (var connection = new TestConnection(host.GetPort())) + { + await connection.Send(request); + await connection.Receive(expectedResponse); + } + } + } + + private async Task TestError(HttpProtocols serverProtocols, string expectedErrorMessage) + where TException : Exception + { + var logger = new TestApplicationErrorLogger(); + var loggerProvider = new Mock(); + loggerProvider + .Setup(provider => provider.CreateLogger(It.IsAny())) + .Returns(logger); + + var builder = new WebHostBuilder() + .ConfigureLogging(loggingBuilder => loggingBuilder.AddProvider(loggerProvider.Object)) + .UseKestrel(options => options.Listen(IPAddress.Loopback, 0, listenOptions => listenOptions.Protocols = serverProtocols)) + .Configure(app => app.Run(context => Task.CompletedTask)); + + using (var host = builder.Build()) + { + host.Start(); + + using (var connection = new TestConnection(host.GetPort())) + { + await connection.WaitForConnectionClose().TimeoutAfter(TimeSpan.FromSeconds(30)); + } + } + + Assert.Single(logger.Messages, message => message.LogLevel == LogLevel.Error + && message.EventId.Id == 0 + && message.Message == expectedErrorMessage); + } + } +} diff --git a/test/Kestrel.Transport.Libuv.Tests/LibuvTransportTests.cs b/test/Kestrel.Transport.Libuv.Tests/LibuvTransportTests.cs index 6f3e9126a7..d3739ae07f 100644 --- a/test/Kestrel.Transport.Libuv.Tests/LibuvTransportTests.cs +++ b/test/Kestrel.Transport.Libuv.Tests/LibuvTransportTests.cs @@ -54,7 +54,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests public async Task ConnectionCanReadAndWrite(ListenOptions listenOptions) { var serviceContext = new TestServiceContext(); - listenOptions.UseHttpServer(listenOptions.ConnectionAdapters, serviceContext, new DummyApplication(TestApp.EchoApp)); + listenOptions.UseHttpServer(listenOptions.ConnectionAdapters, serviceContext, new DummyApplication(TestApp.EchoApp), HttpProtocols.Http1); var transportContext = new TestLibuvTransportContext() { diff --git a/test/Kestrel.Transport.Libuv.Tests/ListenerPrimaryTests.cs b/test/Kestrel.Transport.Libuv.Tests/ListenerPrimaryTests.cs index f751fa2de6..41ee4a7f19 100644 --- a/test/Kestrel.Transport.Libuv.Tests/ListenerPrimaryTests.cs +++ b/test/Kestrel.Transport.Libuv.Tests/ListenerPrimaryTests.cs @@ -33,12 +33,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests var serviceContextPrimary = new TestServiceContext(); var transportContextPrimary = new TestLibuvTransportContext(); var builderPrimary = new ConnectionBuilder(); - builderPrimary.UseHttpServer(serviceContextPrimary, new DummyApplication(c => c.Response.WriteAsync("Primary"))); + builderPrimary.UseHttpServer(serviceContextPrimary, new DummyApplication(c => c.Response.WriteAsync("Primary")), HttpProtocols.Http1); transportContextPrimary.ConnectionHandler = new ConnectionHandler(serviceContextPrimary, builderPrimary.Build()); var serviceContextSecondary = new TestServiceContext(); var builderSecondary = new ConnectionBuilder(); - builderSecondary.UseHttpServer(serviceContextSecondary, new DummyApplication(c => c.Response.WriteAsync("Secondary"))); + builderSecondary.UseHttpServer(serviceContextSecondary, new DummyApplication(c => c.Response.WriteAsync("Secondary")), HttpProtocols.Http1); var transportContextSecondary = new TestLibuvTransportContext(); transportContextSecondary.ConnectionHandler = new ConnectionHandler(serviceContextSecondary, builderSecondary.Build()); @@ -101,7 +101,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests var serviceContextPrimary = new TestServiceContext(); var builderPrimary = new ConnectionBuilder(); - builderPrimary.UseHttpServer(serviceContextPrimary, new DummyApplication(c => c.Response.WriteAsync("Primary"))); + builderPrimary.UseHttpServer(serviceContextPrimary, new DummyApplication(c => c.Response.WriteAsync("Primary")), HttpProtocols.Http1); var transportContextPrimary = new TestLibuvTransportContext() { Log = new LibuvTrace(logger) }; transportContextPrimary.ConnectionHandler = new ConnectionHandler(serviceContextPrimary, builderPrimary.Build()); @@ -113,7 +113,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests HttpParserFactory = serviceContextPrimary.HttpParserFactory, }; var builderSecondary = new ConnectionBuilder(); - builderSecondary.UseHttpServer(serviceContextSecondary, new DummyApplication(c => c.Response.WriteAsync("Secondary"))); + builderSecondary.UseHttpServer(serviceContextSecondary, new DummyApplication(c => c.Response.WriteAsync("Secondary")), HttpProtocols.Http1); var transportContextSecondary = new TestLibuvTransportContext(); transportContextSecondary.ConnectionHandler = new ConnectionHandler(serviceContextSecondary, builderSecondary.Build()); @@ -212,7 +212,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests var serviceContextPrimary = new TestServiceContext(); var builderPrimary = new ConnectionBuilder(); - builderPrimary.UseHttpServer(serviceContextPrimary, new DummyApplication(c => c.Response.WriteAsync("Primary"))); + builderPrimary.UseHttpServer(serviceContextPrimary, new DummyApplication(c => c.Response.WriteAsync("Primary")), HttpProtocols.Http1); var transportContextPrimary = new TestLibuvTransportContext() { Log = new LibuvTrace(logger) }; transportContextPrimary.ConnectionHandler = new ConnectionHandler(serviceContextPrimary, builderPrimary.Build()); @@ -224,7 +224,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests HttpParserFactory = serviceContextPrimary.HttpParserFactory, }; var builderSecondary = new ConnectionBuilder(); - builderSecondary.UseHttpServer(serviceContextSecondary, new DummyApplication(c => c.Response.WriteAsync("Secondary"))); + builderSecondary.UseHttpServer(serviceContextSecondary, new DummyApplication(c => c.Response.WriteAsync("Secondary")), HttpProtocols.Http1); var transportContextSecondary = new TestLibuvTransportContext(); transportContextSecondary.ConnectionHandler = new ConnectionHandler(serviceContextSecondary, builderSecondary.Build()); From bb9840a5529405fb0a78d8acf748e9390786e9b0 Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Wed, 20 Sep 2017 18:34:54 -0700 Subject: [PATCH 1418/1662] HTTP/2: do not ACK PING frames received with ACK set. --- .../Internal/Http2/Http2Connection.cs | 5 +++++ .../Http2ConnectionTests.cs | 22 ++++++++++++++----- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/src/Kestrel.Core/Internal/Http2/Http2Connection.cs b/src/Kestrel.Core/Internal/Http2/Http2Connection.cs index 3622686dfd..269cc034e2 100644 --- a/src/Kestrel.Core/Internal/Http2/Http2Connection.cs +++ b/src/Kestrel.Core/Internal/Http2/Http2Connection.cs @@ -413,6 +413,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 throw new Http2ConnectionErrorException(Http2ErrorCode.FRAME_SIZE_ERROR); } + if ((_incomingFrame.PingFlags & Http2PingFrameFlags.ACK) == Http2PingFrameFlags.ACK) + { + return Task.CompletedTask; + } + return _frameWriter.WritePingAsync(Http2PingFrameFlags.ACK, _incomingFrame.Payload); } diff --git a/test/Kestrel.Core.Tests/Http2ConnectionTests.cs b/test/Kestrel.Core.Tests/Http2ConnectionTests.cs index 7b3a96221a..0de04f62df 100644 --- a/test/Kestrel.Core.Tests/Http2ConnectionTests.cs +++ b/test/Kestrel.Core.Tests/Http2ConnectionTests.cs @@ -923,11 +923,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests } [Fact] - public async Task PING_Received_Sends_ACK() + public async Task PING_Received_SendsACK() { await InitializeConnectionAsync(_noopApplication); - await SendPingAsync(); + await SendPingAsync(Http2PingFrameFlags.NONE); await ExpectAsync(Http2FrameType.PING, withLength: 8, withFlags: (byte)Http2PingFrameFlags.ACK, @@ -936,13 +936,23 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests await StopConnectionAsync(expectedLastStreamId: 0, ignoreNonGoAwayFrames: false); } + [Fact] + public async Task PING_Received_WithACK_DoesNotSendACK() + { + await InitializeConnectionAsync(_noopApplication); + + await SendPingAsync(Http2PingFrameFlags.ACK); + + await StopConnectionAsync(expectedLastStreamId: 0, ignoreNonGoAwayFrames: false); + } + [Fact] public async Task PING_Received_InterleavedWithHeaders_ConnectionError() { await InitializeConnectionAsync(_noopApplication); await SendHeadersAsync(1, Http2HeadersFrameFlags.NONE, _browserRequestHeaders); - await SendPingAsync(); + await SendPingAsync(Http2PingFrameFlags.NONE); await WaitForConnectionErrorAsync(expectedLastStreamId: 0, expectedErrorCode: Http2ErrorCode.PROTOCOL_ERROR, ignoreNonGoAwayFrames: false); } @@ -1160,7 +1170,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests await SendUnknownFrameTypeAsync(streamId: 1); // Check that the connection is still alive - await SendPingAsync(); + await SendPingAsync(Http2PingFrameFlags.NONE); await ExpectAsync(Http2FrameType.PING, withLength: 8, withFlags: (byte)Http2PingFrameFlags.ACK, @@ -1502,10 +1512,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests return SendAsync(frame.Raw); } - private Task SendPingAsync() + private Task SendPingAsync(Http2PingFrameFlags flags) { var pingFrame = new Http2Frame(); - pingFrame.PreparePing(Http2PingFrameFlags.NONE); + pingFrame.PreparePing(flags); return SendAsync(pingFrame.Raw); } From 1b1137b8803771ba94c05dc3ab52c7f617e15c10 Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Mon, 2 Oct 2017 10:24:57 -0700 Subject: [PATCH 1419/1662] HTTP/2: connection error when receiving frames disallowed by stream states. --- .../Internal/Http/Http1OutputProducer.cs | 3 +- .../Internal/Http2/Http2Connection.cs | 150 +++++++++++++----- .../Internal/Http2/Http2FrameWriter.cs | 7 +- .../Internal/Http2/Http2MessageBody.cs | 4 +- .../Internal/Http2/Http2OutputProducer.cs | 5 +- .../Internal/Http2/Http2Stream.cs | 6 +- .../Internal/Infrastructure/Constants.cs | 2 + .../Http2ConnectionTests.cs | 108 ++++++++++--- 8 files changed, 210 insertions(+), 75 deletions(-) diff --git a/src/Kestrel.Core/Internal/Http/Http1OutputProducer.cs b/src/Kestrel.Core/Internal/Http/Http1OutputProducer.cs index 61ec44467d..6ff341bb71 100644 --- a/src/Kestrel.Core/Internal/Http/Http1OutputProducer.cs +++ b/src/Kestrel.Core/Internal/Http/Http1OutputProducer.cs @@ -14,7 +14,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { public class Http1OutputProducer : IHttpOutputProducer { - private static readonly ArraySegment _emptyData = new ArraySegment(new byte[0]); private static readonly ArraySegment _continueBytes = new ArraySegment(Encoding.ASCII.GetBytes("HTTP/1.1 100 Continue\r\n\r\n")); private static readonly byte[] _bytesHttpVersion11 = Encoding.ASCII.GetBytes("HTTP/1.1 "); private static readonly byte[] _bytesEndHeaders = Encoding.ASCII.GetBytes("\r\n\r\n"); @@ -71,7 +70,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http public Task FlushAsync(CancellationToken cancellationToken = default(CancellationToken)) { - return WriteAsync(_emptyData, cancellationToken); + return WriteAsync(Constants.EmptyData, cancellationToken); } public void Write(Action callback, T state) diff --git a/src/Kestrel.Core/Internal/Http2/Http2Connection.cs b/src/Kestrel.Core/Internal/Http2/Http2Connection.cs index 269cc034e2..7baa89c2c7 100644 --- a/src/Kestrel.Core/Internal/Http2/Http2Connection.cs +++ b/src/Kestrel.Core/Internal/Http2/Http2Connection.cs @@ -30,7 +30,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 private readonly Http2Frame _incomingFrame = new Http2Frame(); private Http2Stream _currentHeadersStream; - private int _lastStreamId; + private int _highestOpenedStreamId; private bool _stopping; @@ -156,7 +156,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 stream.Abort(error); } - await _frameWriter.WriteGoAwayAsync(_lastStreamId, errorCode); + await _frameWriter.WriteGoAwayAsync(_highestOpenedStreamId, errorCode); } finally { @@ -247,16 +247,37 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 throw new Http2ConnectionErrorException(Http2ErrorCode.PROTOCOL_ERROR); } - if (_streams.TryGetValue(_incomingFrame.StreamId, out var stream) && !stream.HasReceivedEndStream) + ThrowIfIncomingFrameSentToIdleStream(); + + if (_streams.TryGetValue(_incomingFrame.StreamId, out var stream) && !stream.EndStreamReceived) { return stream.OnDataAsync(_incomingFrame.DataPayload, endStream: (_incomingFrame.DataFlags & Http2DataFrameFlags.END_STREAM) == Http2DataFrameFlags.END_STREAM); } - return _frameWriter.WriteRstStreamAsync(_incomingFrame.StreamId, Http2ErrorCode.STREAM_CLOSED); + // http://httpwg.org/specs/rfc7540.html#rfc.section.5.1 + // + // ...an endpoint that receives any frames after receiving a frame with the + // END_STREAM flag set MUST treat that as a connection error (Section 5.4.1) + // of type STREAM_CLOSED, unless the frame is permitted as described below. + // + // (The allowed frame types for this situation are WINDOW_UPDATE, RST_STREAM and PRIORITY) + // + // If we couldn't find the stream, it was either alive previously but closed with + // END_STREAM or RST_STREAM, or it was implicitly closed when the client opened + // a new stream with a higher ID. Per the spec, we should send RST_STREAM if + // the stream was closed with RST_STREAM or implicitly, but the spec also says + // in http://httpwg.org/specs/rfc7540.html#rfc.section.5.4.1 that + // + // An endpoint can end a connection at any time. In particular, an endpoint MAY + // choose to treat a stream error as a connection error. + // + // We choose to do that here so we don't have to keep state to track implicitly closed + // streams vs. streams closed with END_STREAM or RST_STREAM. + throw new Http2ConnectionErrorException(Http2ErrorCode.STREAM_CLOSED); } - private Task ProcessHeadersFrameAsync(IHttpApplication application) + private async Task ProcessHeadersFrameAsync(IHttpApplication application) { if (_currentHeadersStream != null) { @@ -278,33 +299,66 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 throw new Http2ConnectionErrorException(Http2ErrorCode.PROTOCOL_ERROR); } - _currentHeadersStream = new Http2Stream(application, new Http2StreamContext + if (_streams.TryGetValue(_incomingFrame.StreamId, out var stream)) { - ConnectionId = ConnectionId, - StreamId = _incomingFrame.StreamId, - ServiceContext = _context.ServiceContext, - ConnectionFeatures = _context.ConnectionFeatures, - PipeFactory = _context.PipeFactory, - LocalEndPoint = _context.LocalEndPoint, - RemoteEndPoint = _context.RemoteEndPoint, - StreamLifetimeHandler = this, - FrameWriter = _frameWriter - }); - _currentHeadersStream.ExpectData = (_incomingFrame.HeadersFlags & Http2HeadersFrameFlags.END_STREAM) == 0; - _currentHeadersStream.Reset(); - - _streams[_incomingFrame.StreamId] = _currentHeadersStream; - - _hpackDecoder.Decode(_incomingFrame.HeadersPayload, _currentHeadersStream.RequestHeaders); - - if ((_incomingFrame.HeadersFlags & Http2HeadersFrameFlags.END_HEADERS) == Http2HeadersFrameFlags.END_HEADERS) - { - _lastStreamId = _incomingFrame.StreamId; - _ = _currentHeadersStream.ProcessRequestsAsync(); - _currentHeadersStream = null; + // http://httpwg.org/specs/rfc7540.html#rfc.section.5.1 + // + // ...an endpoint that receives any frames after receiving a frame with the + // END_STREAM flag set MUST treat that as a connection error (Section 5.4.1) + // of type STREAM_CLOSED, unless the frame is permitted as described below. + // + // (The allowed frame types for this situation are WINDOW_UPDATE, RST_STREAM and PRIORITY) + if (stream.EndStreamReceived) + { + throw new Http2ConnectionErrorException(Http2ErrorCode.STREAM_CLOSED); + } + // TODO: trailers } + else if (_incomingFrame.StreamId <= _highestOpenedStreamId) + { + // http://httpwg.org/specs/rfc7540.html#rfc.section.5.1.1 + // + // The first use of a new stream identifier implicitly closes all streams in the "idle" + // state that might have been initiated by that peer with a lower-valued stream identifier. + // + // If we couldn't find the stream, it was previously closed (either implicitly or with + // END_STREAM or RST_STREAM). + throw new Http2ConnectionErrorException(Http2ErrorCode.STREAM_CLOSED); + } + else + { + // Start a new stream + _currentHeadersStream = new Http2Stream(application, new Http2StreamContext + { + ConnectionId = ConnectionId, + StreamId = _incomingFrame.StreamId, + ServiceContext = _context.ServiceContext, + ConnectionFeatures = _context.ConnectionFeatures, + PipeFactory = _context.PipeFactory, + LocalEndPoint = _context.LocalEndPoint, + RemoteEndPoint = _context.RemoteEndPoint, + StreamLifetimeHandler = this, + FrameWriter = _frameWriter + }); - return Task.CompletedTask; + if ((_incomingFrame.HeadersFlags & Http2HeadersFrameFlags.END_STREAM) == Http2HeadersFrameFlags.END_STREAM) + { + await _currentHeadersStream.OnDataAsync(Constants.EmptyData, endStream: true); + } + + _currentHeadersStream.Reset(); + + _streams[_incomingFrame.StreamId] = _currentHeadersStream; + + _hpackDecoder.Decode(_incomingFrame.HeadersPayload, _currentHeadersStream.RequestHeaders); + + if ((_incomingFrame.HeadersFlags & Http2HeadersFrameFlags.END_HEADERS) == Http2HeadersFrameFlags.END_HEADERS) + { + _highestOpenedStreamId = _incomingFrame.StreamId; + _ = _currentHeadersStream.ProcessRequestsAsync(); + _currentHeadersStream = null; + } + } } private Task ProcessPriorityFrameAsync() @@ -349,14 +403,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 throw new Http2ConnectionErrorException(Http2ErrorCode.FRAME_SIZE_ERROR); } + ThrowIfIncomingFrameSentToIdleStream(); + if (_streams.TryGetValue(_incomingFrame.StreamId, out var stream)) { stream.Abort(error: null); } - else if (_incomingFrame.StreamId > _lastStreamId) - { - throw new Http2ConnectionErrorException(Http2ErrorCode.PROTOCOL_ERROR); - } return Task.CompletedTask; } @@ -449,16 +501,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 throw new Http2ConnectionErrorException(Http2ErrorCode.FRAME_SIZE_ERROR); } - if (_incomingFrame.StreamId == 0) + ThrowIfIncomingFrameSentToIdleStream(); + + if (_incomingFrame.WindowUpdateSizeIncrement == 0) { - if (_incomingFrame.WindowUpdateSizeIncrement == 0) + if (_incomingFrame.StreamId == 0) { throw new Http2ConnectionErrorException(Http2ErrorCode.PROTOCOL_ERROR); } - } - else - { - if (_incomingFrame.WindowUpdateSizeIncrement == 0) + else { return _frameWriter.WriteRstStreamAsync(_incomingFrame.StreamId, Http2ErrorCode.PROTOCOL_ERROR); } @@ -478,7 +529,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 if ((_incomingFrame.ContinuationFlags & Http2ContinuationFrameFlags.END_HEADERS) == Http2ContinuationFrameFlags.END_HEADERS) { - _lastStreamId = _currentHeadersStream.StreamId; + _highestOpenedStreamId = _currentHeadersStream.StreamId; _ = _currentHeadersStream.ProcessRequestsAsync(); _currentHeadersStream = null; } @@ -496,6 +547,25 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 return Task.CompletedTask; } + private void ThrowIfIncomingFrameSentToIdleStream() + { + // http://httpwg.org/specs/rfc7540.html#rfc.section.5.1 + // 5.1. Stream states + // ... + // idle: + // ... + // Receiving any frame other than HEADERS or PRIORITY on a stream in this state MUST be + // treated as a connection error (Section 5.4.1) of type PROTOCOL_ERROR. + // + // If the stream ID in the incoming frame is higher than the highest opened stream ID so + // far, then the incoming frame's target stream is in the idle state, which is the implicit + // initial state for all streams. + if (_incomingFrame.StreamId > _highestOpenedStreamId) + { + throw new Http2ConnectionErrorException(Http2ErrorCode.PROTOCOL_ERROR); + } + } + void IHttp2StreamLifetimeHandler.OnStreamCompleted(int streamId) { _streams.TryRemove(streamId, out _); diff --git a/src/Kestrel.Core/Internal/Http2/Http2FrameWriter.cs b/src/Kestrel.Core/Internal/Http2/Http2FrameWriter.cs index a8c85e7b68..fb2468d0c4 100644 --- a/src/Kestrel.Core/Internal/Http2/Http2FrameWriter.cs +++ b/src/Kestrel.Core/Internal/Http2/Http2FrameWriter.cs @@ -7,16 +7,13 @@ using System.IO.Pipelines; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2.HPack; -using Microsoft.Extensions.Logging; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 { public class Http2FrameWriter : IHttp2FrameWriter { - private static readonly ArraySegment _emptyData = new ArraySegment(new byte[0]); - private readonly Http2Frame _outgoingFrame = new Http2Frame(); private readonly object _writeLock = new object(); private readonly HPackEncoder _hpackEncoder = new HPackEncoder(); @@ -48,7 +45,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 public Task FlushAsync(CancellationToken cancellationToken) { - return WriteAsync(_emptyData); + return WriteAsync(Constants.EmptyData); } public Task Write100ContinueAsync(int streamId) diff --git a/src/Kestrel.Core/Internal/Http2/Http2MessageBody.cs b/src/Kestrel.Core/Internal/Http2/Http2MessageBody.cs index 26013948dc..71a308a8f7 100644 --- a/src/Kestrel.Core/Internal/Http2/Http2MessageBody.cs +++ b/src/Kestrel.Core/Internal/Http2/Http2MessageBody.cs @@ -29,9 +29,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 HttpRequestHeaders headers, Http2Stream context) { - if (!context.ExpectData) + if (context.EndStreamReceived) { - return MessageBody.ZeroContentLengthClose; + return ZeroContentLengthClose; } return new ForHttp2(context); diff --git a/src/Kestrel.Core/Internal/Http2/Http2OutputProducer.cs b/src/Kestrel.Core/Internal/Http2/Http2OutputProducer.cs index 1b7d43b284..93f549b5ce 100644 --- a/src/Kestrel.Core/Internal/Http2/Http2OutputProducer.cs +++ b/src/Kestrel.Core/Internal/Http2/Http2OutputProducer.cs @@ -6,13 +6,12 @@ using System.IO.Pipelines; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 { public class Http2OutputProducer : IHttpOutputProducer { - private static readonly ArraySegment _emptyData = new ArraySegment(new byte[0]); - private readonly int _streamId; private readonly IHttp2FrameWriter _frameWriter; @@ -47,7 +46,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 public Task WriteStreamSuffixAsync(CancellationToken cancellationToken) { - return _frameWriter.WriteDataAsync(_streamId, _emptyData, endStream: true, cancellationToken: cancellationToken); + return _frameWriter.WriteDataAsync(_streamId, Constants.EmptyData, endStream: true, cancellationToken: cancellationToken); } public void WriteResponseHeaders(int statusCode, string ReasonPhrase, HttpResponseHeaders responseHeaders) diff --git a/src/Kestrel.Core/Internal/Http2/Http2Stream.cs b/src/Kestrel.Core/Internal/Http2/Http2Stream.cs index 71457fae4c..b8f9db04ee 100644 --- a/src/Kestrel.Core/Internal/Http2/Http2Stream.cs +++ b/src/Kestrel.Core/Internal/Http2/Http2Stream.cs @@ -24,12 +24,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 public int StreamId => _context.StreamId; - public bool HasReceivedEndStream { get; private set; } + public bool EndStreamReceived { get; private set; } protected IHttp2StreamLifetimeHandler StreamLifetimeHandler => _context.StreamLifetimeHandler; - public bool ExpectData { get; set; } - public override bool IsUpgradableRequest => false; protected override void OnReset() @@ -91,7 +89,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 if (endStream) { - HasReceivedEndStream = true; + EndStreamReceived = true; RequestBodyPipe.Writer.Complete(); } } diff --git a/src/Kestrel.Core/Internal/Infrastructure/Constants.cs b/src/Kestrel.Core/Internal/Infrastructure/Constants.cs index 7f93242028..6db5d384ee 100644 --- a/src/Kestrel.Core/Internal/Infrastructure/Constants.cs +++ b/src/Kestrel.Core/Internal/Infrastructure/Constants.cs @@ -32,5 +32,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure public const string ServerName = "Kestrel"; public static readonly TimeSpan RequestBodyDrainTimeout = TimeSpan.FromSeconds(5); + + public static readonly ArraySegment EmptyData = new ArraySegment(new byte[0]); } } diff --git a/test/Kestrel.Core.Tests/Http2ConnectionTests.cs b/test/Kestrel.Core.Tests/Http2ConnectionTests.cs index 0de04f62df..873233df34 100644 --- a/test/Kestrel.Core.Tests/Http2ConnectionTests.cs +++ b/test/Kestrel.Core.Tests/Http2ConnectionTests.cs @@ -467,33 +467,30 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests } [Fact] - public async Task DATA_Received_StreamIdle_StreamError() + public async Task DATA_Received_StreamIdle_ConnectionError() { await InitializeConnectionAsync(_noopApplication); await SendDataAsync(1, _helloWorldBytes, endStream: false); - await WaitForStreamErrorAsync(expectedStreamId: 1, expectedErrorCode: Http2ErrorCode.STREAM_CLOSED, ignoreNonRstStreamFrames: false); - - await StopConnectionAsync(expectedLastStreamId: 0, ignoreNonGoAwayFrames: false); + await WaitForConnectionErrorAsync(expectedLastStreamId: 0, expectedErrorCode: Http2ErrorCode.PROTOCOL_ERROR, ignoreNonGoAwayFrames: false); } [Fact] - public async Task DATA_Received_StreamHalfClosedRemote_StreamError() + public async Task DATA_Received_StreamHalfClosedRemote_ConnectionError() { - await InitializeConnectionAsync(_echoWaitForAbortApplication); + // Use _waitForAbortApplication so we know the stream will still be active when we send the illegal DATA frame + await InitializeConnectionAsync(_waitForAbortApplication); - await StartStreamAsync(1, _postRequestHeaders, endStream: false); - await SendDataAsync(1, _helloBytes, endStream: true); - await SendDataAsync(1, _worldBytes, endStream: true); + await StartStreamAsync(1, _postRequestHeaders, endStream: true); - await WaitForStreamErrorAsync(expectedStreamId: 1, expectedErrorCode: Http2ErrorCode.STREAM_CLOSED, ignoreNonRstStreamFrames: true); + await SendDataAsync(1, _helloWorldBytes, endStream: false); - await StopConnectionAsync(expectedLastStreamId: 1, ignoreNonGoAwayFrames: true); + await WaitForConnectionErrorAsync(expectedLastStreamId: 1, expectedErrorCode: Http2ErrorCode.STREAM_CLOSED, ignoreNonGoAwayFrames: false); } [Fact] - public async Task DATA_Received_StreamClosed_StreamError() + public async Task DATA_Received_StreamClosed_ConnectionError() { await InitializeConnectionAsync(_noopApplication); @@ -510,13 +507,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests await SendDataAsync(1, _helloWorldBytes, endStream: false); - await WaitForStreamErrorAsync(expectedStreamId: 1, expectedErrorCode: Http2ErrorCode.STREAM_CLOSED, ignoreNonRstStreamFrames: false); - - await StopConnectionAsync(expectedLastStreamId: 1, ignoreNonGoAwayFrames: false); + await WaitForConnectionErrorAsync(expectedLastStreamId: 1, expectedErrorCode: Http2ErrorCode.STREAM_CLOSED, ignoreNonGoAwayFrames: false); } [Fact] - public async Task DATA_Received_StreamClosedImplicitly_StreamError() + public async Task DATA_Received_StreamClosedImplicitly_ConnectionError() { // http://httpwg.org/specs/rfc7540.html#rfc.section.5.1.1 // @@ -540,9 +535,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests await SendDataAsync(1, _helloWorldBytes, endStream: true); - await WaitForStreamErrorAsync(expectedStreamId: 1, expectedErrorCode: Http2ErrorCode.STREAM_CLOSED, ignoreNonRstStreamFrames: false); - - await StopConnectionAsync(expectedLastStreamId: 3, ignoreNonGoAwayFrames: false); + await WaitForConnectionErrorAsync(expectedLastStreamId: 3, expectedErrorCode: Http2ErrorCode.STREAM_CLOSED, ignoreNonGoAwayFrames: false); } [Fact] @@ -655,6 +648,63 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests await WaitForConnectionErrorAsync(expectedLastStreamId: 0, expectedErrorCode: Http2ErrorCode.PROTOCOL_ERROR, ignoreNonGoAwayFrames: false); } + [Fact] + public async Task HEADERS_Received_StreamClosed_ConnectionError() + { + await InitializeConnectionAsync(_noopApplication); + + await StartStreamAsync(1, _browserRequestHeaders, endStream: true); + + await ExpectAsync(Http2FrameType.HEADERS, + withLength: 55, + withFlags: (byte)Http2HeadersFrameFlags.END_HEADERS, + withStreamId: 1); + await ExpectAsync(Http2FrameType.DATA, + withLength: 0, + withFlags: (byte)Http2DataFrameFlags.END_STREAM, + withStreamId: 1); + + // Try to re-use the stream ID (http://httpwg.org/specs/rfc7540.html#rfc.section.5.1.1) + await StartStreamAsync(1, _browserRequestHeaders, endStream: true); + + await WaitForConnectionErrorAsync(expectedLastStreamId: 1, expectedErrorCode: Http2ErrorCode.STREAM_CLOSED, ignoreNonGoAwayFrames: false); + } + + [Fact] + public async Task HEADERS_Received_StreamHalfClosedRemote_ConnectionError() + { + // Use _waitForAbortApplication so we know the stream will still be active when we send the illegal DATA frame + await InitializeConnectionAsync(_waitForAbortApplication); + + await StartStreamAsync(1, _browserRequestHeaders, endStream: true); + + await SendHeadersAsync(1, Http2HeadersFrameFlags.NONE, _browserRequestHeaders); + + await WaitForConnectionErrorAsync(expectedLastStreamId: 1, expectedErrorCode: Http2ErrorCode.STREAM_CLOSED, ignoreNonGoAwayFrames: false); + } + + [Fact] + public async Task HEADERS_Received_StreamClosedImplicitly_ConnectionError() + { + await InitializeConnectionAsync(_noopApplication); + + await StartStreamAsync(3, _browserRequestHeaders, endStream: true); + + await ExpectAsync(Http2FrameType.HEADERS, + withLength: 55, + withFlags: (byte)Http2HeadersFrameFlags.END_HEADERS, + withStreamId: 3); + await ExpectAsync(Http2FrameType.DATA, + withLength: 0, + withFlags: (byte)Http2DataFrameFlags.END_STREAM, + withStreamId: 3); + + // Stream 1 was implicitly closed by opening stream 3 before (http://httpwg.org/specs/rfc7540.html#rfc.section.5.1.1) + await StartStreamAsync(1, _browserRequestHeaders, endStream: true); + + await WaitForConnectionErrorAsync(expectedLastStreamId: 3, expectedErrorCode: Http2ErrorCode.STREAM_CLOSED, ignoreNonGoAwayFrames: false); + } + [Theory] [InlineData(0)] [InlineData(1)] @@ -811,6 +861,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests await WaitForConnectionErrorAsync(expectedLastStreamId: 0, expectedErrorCode: Http2ErrorCode.PROTOCOL_ERROR, ignoreNonGoAwayFrames: false); } + [Fact] + public async Task RST_STREAM_Received_StreamIdle_ConnectionError() + { + await InitializeConnectionAsync(_noopApplication); + + await SendRstStreamAsync(1); + + await WaitForConnectionErrorAsync(expectedLastStreamId: 0, expectedErrorCode: Http2ErrorCode.PROTOCOL_ERROR, ignoreNonGoAwayFrames: false); + } + [Theory] [InlineData(3)] [InlineData(5)] @@ -1077,6 +1137,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests await WaitForConnectionErrorAsync(expectedLastStreamId: 0, expectedErrorCode: Http2ErrorCode.PROTOCOL_ERROR, ignoreNonGoAwayFrames: false); } + [Fact] + public async Task WINDOW_UPDATE_Received_StreamIdle_ConnectionError() + { + await InitializeConnectionAsync(_waitForAbortApplication); + + await SendWindowUpdateAsync(1, sizeIncrement: 1); + + await WaitForConnectionErrorAsync(expectedLastStreamId: 0, expectedErrorCode: Http2ErrorCode.PROTOCOL_ERROR, ignoreNonGoAwayFrames: false); + } + [Fact] public async Task WINDOW_UPDATE_Received_OnStream_SizeIncrementZero_StreamError() { From 83e208436858a2b435e7a9dd0f6ea228bc842e4b Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Tue, 3 Oct 2017 14:34:14 -0700 Subject: [PATCH 1420/1662] Fix flaky MaxRequestBodySizeTest (#2092) - Don't attempt to send any data after the request might already be rejected. --- test/Kestrel.FunctionalTests/MaxRequestBodySizeTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Kestrel.FunctionalTests/MaxRequestBodySizeTests.cs b/test/Kestrel.FunctionalTests/MaxRequestBodySizeTests.cs index 9d61ffb19f..925fc11f63 100644 --- a/test/Kestrel.FunctionalTests/MaxRequestBodySizeTests.cs +++ b/test/Kestrel.FunctionalTests/MaxRequestBodySizeTests.cs @@ -153,7 +153,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests "Host:", "Content-Length: 1", "", - "A"); + ""); await connection.ReceiveForcedEnd( "HTTP/1.1 200 OK", $"Date: {server.Context.DateHeaderValue}", From 156ddfc4e86a8fabaad100349f105e300bcf1234 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Wed, 4 Oct 2017 12:38:19 -0700 Subject: [PATCH 1421/1662] Fix EOF handling of TlsStream.ReadAsync (#2094) --- src/Kestrel.Tls/TlsStream.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/Kestrel.Tls/TlsStream.cs b/src/Kestrel.Tls/TlsStream.cs index 6cf8c5e8e0..0b1b583167 100644 --- a/src/Kestrel.Tls/TlsStream.cs +++ b/src/Kestrel.Tls/TlsStream.cs @@ -139,6 +139,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Tls if (OpenSsl.BIO_ctrl_pending(_inputBio) == 0) { var bytesRead = await _innerStream.ReadAsync(_inputBuffer, 0, _inputBuffer.Length, cancellationToken); + + if (bytesRead == 0) + { + return 0; + } + OpenSsl.BIO_write(_inputBio, _inputBuffer, 0, bytesRead); } From 11ce1395e52f1954f6ccc87937ce7cf95d926f9f Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Wed, 4 Oct 2017 12:59:41 -0700 Subject: [PATCH 1422/1662] HPACK fixes and improvements. --- src/Kestrel.Core/CoreStrings.resx | 24 + .../Internal/Http/Http1Connection.cs | 12 - .../Internal/Http/HttpProtocol.cs | 12 + .../Internal/Http2/HPack/DynamicTable.cs | 52 +- .../Internal/Http2/HPack/HPackDecoder.cs | 208 +++++-- .../Http2/HPack/HPackDecodingException.cs | 19 + .../Internal/Http2/HPack/HeaderField.cs | 23 +- .../Internal/Http2/HPack/Huffman.cs | 99 +++- .../Http2/HPack/HuffmanDecodingException.cs | 15 + .../Internal/Http2/HPack/IntegerDecoder.cs | 3 - .../Internal/Http2/HPack/StaticTable.cs | 129 ++-- .../Internal/Http2/Http2Connection.cs | 25 +- .../Properties/CoreStrings.Designer.cs | 112 ++++ test/Kestrel.Core.Tests/DynamicTableTests.cs | 158 +++++ test/Kestrel.Core.Tests/HPackDecoderTests.cs | 560 ++++++++++++++++++ .../Http2ConnectionTests.cs | 136 ++++- test/Kestrel.Core.Tests/HuffmanTests.cs | 153 ++++- 17 files changed, 1522 insertions(+), 218 deletions(-) create mode 100644 src/Kestrel.Core/Internal/Http2/HPack/HPackDecodingException.cs create mode 100644 src/Kestrel.Core/Internal/Http2/HPack/HuffmanDecodingException.cs create mode 100644 test/Kestrel.Core.Tests/DynamicTableTests.cs create mode 100644 test/Kestrel.Core.Tests/HPackDecoderTests.cs diff --git a/src/Kestrel.Core/CoreStrings.resx b/src/Kestrel.Core/CoreStrings.resx index 6fea320658..7127c41905 100644 --- a/src/Kestrel.Core/CoreStrings.resx +++ b/src/Kestrel.Core/CoreStrings.resx @@ -360,4 +360,28 @@ HTTP/2 over TLS was not negotiated on an HTTP/2-only endpoint. + + A dynamic table size of {size} octets is greater than the configured maximum size of {maxSize} octets. + + + Index {index} is outside the bounds of the header field table. + + + Input data could not be fully decoded. + + + Input data contains the EOS symbol. + + + The destination buffer is not large enough to store the decoded data. + + + Huffman decoding error. + + + Decoded string length of {length} octets is greater than the configured maximum length of {maxStringLength} octets. + + + The header block was incomplete and could not be fully decoded. + \ No newline at end of file diff --git a/src/Kestrel.Core/Internal/Http/Http1Connection.cs b/src/Kestrel.Core/Internal/Http/Http1Connection.cs index 9eb06465c1..9357a9d742 100644 --- a/src/Kestrel.Core/Internal/Http/Http1Connection.cs +++ b/src/Kestrel.Core/Internal/Http/Http1Connection.cs @@ -344,18 +344,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http } } - public void OnHeader(Span name, Span value) - { - _requestHeadersParsed++; - if (_requestHeadersParsed > ServerOptions.Limits.MaxRequestHeaderCount) - { - ThrowRequestRejected(RequestRejectionReason.TooManyHeaders); - } - var valueString = value.GetAsciiStringNonNullCharacters(); - - HttpRequestHeaders.Append(name, valueString); - } - protected void EnsureHostHeaderExists() { if (_httpVersion == Http.HttpVersion.Http10) diff --git a/src/Kestrel.Core/Internal/Http/HttpProtocol.cs b/src/Kestrel.Core/Internal/Http/HttpProtocol.cs index e99f929a1f..7ac194dd6e 100644 --- a/src/Kestrel.Core/Internal/Http/HttpProtocol.cs +++ b/src/Kestrel.Core/Internal/Http/HttpProtocol.cs @@ -418,6 +418,18 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http } } + public void OnHeader(Span name, Span value) + { + _requestHeadersParsed++; + if (_requestHeadersParsed > ServerOptions.Limits.MaxRequestHeaderCount) + { + ThrowRequestRejected(RequestRejectionReason.TooManyHeaders); + } + var valueString = value.GetAsciiStringNonNullCharacters(); + + HttpRequestHeaders.Append(name, valueString); + } + public async Task ProcessRequestsAsync() { try diff --git a/src/Kestrel.Core/Internal/Http2/HPack/DynamicTable.cs b/src/Kestrel.Core/Internal/Http2/HPack/DynamicTable.cs index 0b58c69ba6..6a13e49b82 100644 --- a/src/Kestrel.Core/Internal/Http2/HPack/DynamicTable.cs +++ b/src/Kestrel.Core/Internal/Http2/HPack/DynamicTable.cs @@ -7,8 +7,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2.HPack { public class DynamicTable { - private readonly HeaderField[] _buffer; - private int _maxSize = 4096; + private HeaderField[] _buffer; + private int _maxSize; private int _size; private int _count; private int _insertIndex; @@ -16,7 +16,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2.HPack public DynamicTable(int maxSize) { - _buffer = new HeaderField[maxSize]; + _buffer = new HeaderField[maxSize / HeaderField.RfcOverhead]; _maxSize = maxSize; } @@ -24,6 +24,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2.HPack public int Size => _size; + public int MaxSize => _maxSize; + public HeaderField this[int index] { get @@ -37,33 +39,53 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2.HPack } } - public void Insert(string name, string value) + public void Insert(Span name, Span value) { - var entrySize = name.Length + value.Length + 32; - EnsureSize(_maxSize - entrySize); + var entryLength = HeaderField.GetLength(name.Length, value.Length); + EnsureAvailable(entryLength); - if (_maxSize < entrySize) + if (entryLength > _maxSize) { - throw new InvalidOperationException($"Unable to add entry of size {entrySize} to dynamic table of size {_maxSize}."); + // http://httpwg.org/specs/rfc7541.html#rfc.section.4.4 + // It is not an error to attempt to add an entry that is larger than the maximum size; + // an attempt to add an entry larger than the maximum size causes the table to be emptied + // of all existing entries and results in an empty table. + return; } - _buffer[_insertIndex] = new HeaderField(name, value); + var entry = new HeaderField(name, value); + _buffer[_insertIndex] = entry; _insertIndex = (_insertIndex + 1) % _buffer.Length; - _size += entrySize; + _size += entry.Length; _count++; } public void Resize(int maxSize) { - _maxSize = maxSize; - EnsureSize(_maxSize); + if (maxSize > _maxSize) + { + var newBuffer = new HeaderField[maxSize / HeaderField.RfcOverhead]; + + for (var i = 0; i < Count; i++) + { + newBuffer[i] = _buffer[i]; + } + + _buffer = newBuffer; + _maxSize = maxSize; + } + else + { + _maxSize = maxSize; + EnsureAvailable(0); + } } - public void EnsureSize(int size) + private void EnsureAvailable(int available) { - while (_count > 0 && _size > size) + while (_count > 0 && _maxSize - _size < available) { - _size -= _buffer[_removeIndex].Name.Length + _buffer[_removeIndex].Value.Length + 32; + _size -= _buffer[_removeIndex].Length; _count--; _removeIndex = (_removeIndex + 1) % _buffer.Length; } diff --git a/src/Kestrel.Core/Internal/Http2/HPack/HPackDecoder.cs b/src/Kestrel.Core/Internal/Http2/HPack/HPackDecoder.cs index 33a1e014ad..3df0d7af86 100644 --- a/src/Kestrel.Core/Internal/Http2/HPack/HPackDecoder.cs +++ b/src/Kestrel.Core/Internal/Http2/HPack/HPackDecoder.cs @@ -2,10 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.Collections.Generic; -using System.Text; -using Microsoft.AspNetCore.Http; -using Microsoft.Extensions.Logging; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2.HPack { @@ -22,14 +19,57 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2.HPack HeaderValueLength, HeaderValueLengthContinue, HeaderValue, - DynamicTableSize + DynamicTableSizeUpdate } + // TODO: add new configurable limit + public const int MaxStringOctets = 4096; + + // http://httpwg.org/specs/rfc7541.html#rfc.section.6.1 + // 0 1 2 3 4 5 6 7 + // +---+---+---+---+---+---+---+---+ + // | 1 | Index (7+) | + // +---+---------------------------+ private const byte IndexedHeaderFieldMask = 0x80; - private const byte LiteralHeaderFieldWithIncrementalIndexingMask = 0x40; - private const byte LiteralHeaderFieldWithoutIndexingMask = 0x00; - private const byte LiteralHeaderFieldNeverIndexedMask = 0x10; - private const byte DynamicTableSizeUpdateMask = 0x20; + private const byte IndexedHeaderFieldRepresentation = 0x80; + + // http://httpwg.org/specs/rfc7541.html#rfc.section.6.2.1 + // 0 1 2 3 4 5 6 7 + // +---+---+---+---+---+---+---+---+ + // | 0 | 1 | Index (6+) | + // +---+---+-----------------------+ + private const byte LiteralHeaderFieldWithIncrementalIndexingMask = 0xc0; + private const byte LiteralHeaderFieldWithIncrementalIndexingRepresentation = 0x40; + + // http://httpwg.org/specs/rfc7541.html#rfc.section.6.2.2 + // 0 1 2 3 4 5 6 7 + // +---+---+---+---+---+---+---+---+ + // | 0 | 0 | 0 | 0 | Index (4+) | + // +---+---+-----------------------+ + private const byte LiteralHeaderFieldWithoutIndexingMask = 0xf0; + private const byte LiteralHeaderFieldWithoutIndexingRepresentation = 0x00; + + // http://httpwg.org/specs/rfc7541.html#rfc.section.6.2.3 + // 0 1 2 3 4 5 6 7 + // +---+---+---+---+---+---+---+---+ + // | 0 | 0 | 0 | 1 | Index (4+) | + // +---+---+-----------------------+ + private const byte LiteralHeaderFieldNeverIndexedMask = 0xf0; + private const byte LiteralHeaderFieldNeverIndexedRepresentation = 0x10; + + // http://httpwg.org/specs/rfc7541.html#rfc.section.6.3 + // 0 1 2 3 4 5 6 7 + // +---+---+---+---+---+---+---+---+ + // | 0 | 0 | 1 | Max size (5+) | + // +---+---------------------------+ + private const byte DynamicTableSizeUpdateMask = 0xe0; + private const byte DynamicTableSizeUpdateRepresentation = 0x20; + + // http://httpwg.org/specs/rfc7541.html#rfc.section.5.2 + // 0 1 2 3 4 5 6 7 + // +---+---+---+---+---+---+---+---+ + // | H | String Length (7+) | + // +---+---------------------------+ private const byte HuffmanMask = 0x80; private const int IndexedHeaderFieldPrefix = 7; @@ -39,44 +79,67 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2.HPack private const int DynamicTableSizeUpdatePrefix = 5; private const int StringLengthPrefix = 7; - private readonly DynamicTable _dynamicTable = new DynamicTable(4096); + private readonly int _maxDynamicTableSize; + private readonly DynamicTable _dynamicTable; private readonly IntegerDecoder _integerDecoder = new IntegerDecoder(); + private readonly byte[] _stringOctets = new byte[MaxStringOctets]; + private readonly byte[] _headerNameOctets = new byte[MaxStringOctets]; + private readonly byte[] _headerValueOctets = new byte[MaxStringOctets]; private State _state = State.Ready; - // TODO: add new HTTP/2 header size limit and allocate accordingly - private byte[] _stringOctets = new byte[Http2Frame.MinAllowedMaxFrameSize]; - private string _headerName = string.Empty; - private string _headerValue = string.Empty; - private int _stringLength; + private byte[] _headerName; private int _stringIndex; + private int _stringLength; + private int _headerNameLength; + private int _headerValueLength; private bool _index; private bool _huffman; - public void Decode(Span data, IHeaderDictionary headers) + public HPackDecoder(int maxDynamicTableSize) + : this(maxDynamicTableSize, new DynamicTable(maxDynamicTableSize)) + { + _maxDynamicTableSize = maxDynamicTableSize; + } + + // For testing. + internal HPackDecoder(int maxDynamicTableSize, DynamicTable dynamicTable) + { + _maxDynamicTableSize = maxDynamicTableSize; + _dynamicTable = dynamicTable; + } + + public void Decode(Span data, bool endHeaders, IHttpHeadersHandler handler) { for (var i = 0; i < data.Length; i++) { - OnByte(data[i], headers); + OnByte(data[i], handler); + } + + if (endHeaders && _state != State.Ready) + { + throw new HPackDecodingException(CoreStrings.HPackErrorIncompleteHeaderBlock); } } - public void OnByte(byte b, IHeaderDictionary headers) + public void OnByte(byte b, IHttpHeadersHandler handler) { switch (_state) { case State.Ready: - if ((b & IndexedHeaderFieldMask) == IndexedHeaderFieldMask) + if ((b & IndexedHeaderFieldMask) == IndexedHeaderFieldRepresentation) { - if (_integerDecoder.BeginDecode((byte)(b & ~IndexedHeaderFieldMask), IndexedHeaderFieldPrefix)) + var val = b & ~IndexedHeaderFieldMask; + + if (_integerDecoder.BeginDecode((byte)val, IndexedHeaderFieldPrefix)) { - OnIndexedHeaderField(_integerDecoder.Value, headers); + OnIndexedHeaderField(_integerDecoder.Value, handler); } else { _state = State.HeaderFieldIndex; } } - else if ((b & LiteralHeaderFieldWithIncrementalIndexingMask) == LiteralHeaderFieldWithIncrementalIndexingMask) + else if ((b & LiteralHeaderFieldWithIncrementalIndexingMask) == LiteralHeaderFieldWithIncrementalIndexingRepresentation) { _index = true; var val = b & ~LiteralHeaderFieldWithIncrementalIndexingMask; @@ -94,7 +157,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2.HPack _state = State.HeaderNameIndex; } } - else if ((b & LiteralHeaderFieldWithoutIndexingMask) == LiteralHeaderFieldWithoutIndexingMask) + else if ((b & LiteralHeaderFieldWithoutIndexingMask) == LiteralHeaderFieldWithoutIndexingRepresentation) { _index = false; var val = b & ~LiteralHeaderFieldWithoutIndexingMask; @@ -112,7 +175,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2.HPack _state = State.HeaderNameIndex; } } - else if ((b & LiteralHeaderFieldNeverIndexedMask) == LiteralHeaderFieldNeverIndexedMask) + else if ((b & LiteralHeaderFieldNeverIndexedMask) == LiteralHeaderFieldNeverIndexedRepresentation) { _index = false; var val = b & ~LiteralHeaderFieldNeverIndexedMask; @@ -130,7 +193,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2.HPack _state = State.HeaderNameIndex; } } - else if ((b & DynamicTableSizeUpdateMask) == DynamicTableSizeUpdateMask) + else if ((b & DynamicTableSizeUpdateMask) == DynamicTableSizeUpdateRepresentation) { if (_integerDecoder.BeginDecode((byte)(b & ~DynamicTableSizeUpdateMask), DynamicTableSizeUpdatePrefix)) { @@ -139,19 +202,20 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2.HPack } else { - _state = State.DynamicTableSize; + _state = State.DynamicTableSizeUpdate; } } else { - throw new InvalidOperationException(); + // Can't happen + throw new HPackDecodingException($"Byte value {b} does not encode a valid header field representation."); } break; case State.HeaderFieldIndex: if (_integerDecoder.Decode(b)) { - OnIndexedHeaderField(_integerDecoder.Value, headers); + OnIndexedHeaderField(_integerDecoder.Value, handler); } break; @@ -163,7 +227,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2.HPack break; case State.HeaderNameLength: - _huffman = (b & HuffmanMask) == HuffmanMask; + _huffman = (b & HuffmanMask) != 0; if (_integerDecoder.BeginDecode((byte)(b & ~HuffmanMask), StringLengthPrefix)) { @@ -187,12 +251,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2.HPack if (_stringIndex == _stringLength) { - _headerName = OnString(nextState: State.HeaderValueLength); + OnString(nextState: State.HeaderValueLength); } break; case State.HeaderValueLength: - _huffman = (b & HuffmanMask) == HuffmanMask; + _huffman = (b & HuffmanMask) != 0; if (_integerDecoder.BeginDecode((byte)(b & ~HuffmanMask), StringLengthPrefix)) { @@ -216,20 +280,29 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2.HPack if (_stringIndex == _stringLength) { - _headerValue = OnString(nextState: State.Ready); - headers.Append(_headerName, _headerValue); + OnString(nextState: State.Ready); + + var headerNameSpan = new Span(_headerName, 0, _headerNameLength); + var headerValueSpan = new Span(_headerValueOctets, 0, _headerValueLength); + + handler.OnHeader(headerNameSpan, headerValueSpan); if (_index) { - _dynamicTable.Insert(_headerName, _headerValue); + _dynamicTable.Insert(headerNameSpan, headerValueSpan); } } break; - case State.DynamicTableSize: + case State.DynamicTableSizeUpdate: if (_integerDecoder.Decode(b)) { - // TODO: validate that it's less than what's defined via SETTINGS + if (_integerDecoder.Value > _maxDynamicTableSize) + { + throw new HPackDecodingException( + CoreStrings.FormatHPackErrorDynamicTableSizeUpdateTooLarge(_integerDecoder.Value, _maxDynamicTableSize)); + } + _dynamicTable.Resize(_integerDecoder.Value); _state = State.Ready; } @@ -237,14 +310,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2.HPack break; default: // Can't happen - throw new InvalidOperationException(); + throw new HPackDecodingException("The HPACK decoder reached an invalid state."); } } - private void OnIndexedHeaderField(int index, IHeaderDictionary headers) + private void OnIndexedHeaderField(int index, IHttpHeadersHandler handler) { var header = GetHeader(index); - headers.Append(header.Name, header.Value); + handler.OnHeader(new Span(header.Name), new Span(header.Value)); _state = State.Ready; } @@ -252,26 +325,69 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2.HPack { var header = GetHeader(index); _headerName = header.Name; + _headerNameLength = header.Name.Length; _state = State.HeaderValueLength; } private void OnStringLength(int length, State nextState) { + if (length > _stringOctets.Length) + { + throw new HPackDecodingException(CoreStrings.FormatHPackStringLengthTooLarge(length, _stringOctets.Length)); + } + _stringLength = length; _stringIndex = 0; _state = nextState; } - private string OnString(State nextState) + private void OnString(State nextState) { + int Decode(byte[] dst) + { + if (_huffman) + { + return Huffman.Decode(_stringOctets, 0, _stringLength, dst); + } + else + { + Buffer.BlockCopy(_stringOctets, 0, dst, 0, _stringLength); + return _stringLength; + } + } + + try + { + if (_state == State.HeaderName) + { + _headerName = _headerNameOctets; + _headerNameLength = Decode(_headerNameOctets); + } + else + { + _headerValueLength = Decode(_headerValueOctets); + } + } + catch (HuffmanDecodingException ex) + { + throw new HPackDecodingException(CoreStrings.HPackHuffmanError, ex); + } + _state = nextState; - return _huffman - ? Huffman.Decode(_stringOctets, 0, _stringLength) - : Encoding.ASCII.GetString(_stringOctets, 0, _stringLength); } - private HeaderField GetHeader(int index) => index <= StaticTable.Instance.Length - ? StaticTable.Instance[index - 1] - : _dynamicTable[index - StaticTable.Instance.Length - 1]; + private HeaderField GetHeader(int index) + { + try + { + return index <= StaticTable.Instance.Count + ? StaticTable.Instance[index - 1] + : _dynamicTable[index - StaticTable.Instance.Count - 1]; + } + catch (IndexOutOfRangeException ex) + { + throw new HPackDecodingException(CoreStrings.FormatHPackErrorIndexOutOfRange(index), ex); + } + } } } diff --git a/src/Kestrel.Core/Internal/Http2/HPack/HPackDecodingException.cs b/src/Kestrel.Core/Internal/Http2/HPack/HPackDecodingException.cs new file mode 100644 index 0000000000..7ae0ddddf5 --- /dev/null +++ b/src/Kestrel.Core/Internal/Http2/HPack/HPackDecodingException.cs @@ -0,0 +1,19 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; + +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2.HPack +{ + public class HPackDecodingException : Exception + { + public HPackDecodingException(string message) + : base(message) + { + } + public HPackDecodingException(string message, Exception innerException) + : base(message, innerException) + { + } + } +} diff --git a/src/Kestrel.Core/Internal/Http2/HPack/HeaderField.cs b/src/Kestrel.Core/Internal/Http2/HPack/HeaderField.cs index 9c3872cad2..73eb4d726e 100644 --- a/src/Kestrel.Core/Internal/Http2/HPack/HeaderField.cs +++ b/src/Kestrel.Core/Internal/Http2/HPack/HeaderField.cs @@ -1,17 +1,30 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; + namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2.HPack { public struct HeaderField { - public HeaderField(string name, string value) + // http://httpwg.org/specs/rfc7541.html#rfc.section.4.1 + public const int RfcOverhead = 32; + + public HeaderField(Span name, Span value) { - Name = name; - Value = value; + Name = new byte[name.Length]; + name.CopyTo(Name); + + Value = new byte[value.Length]; + value.CopyTo(Value); } - public string Name { get; } - public string Value { get; } + public byte[] Name { get; } + + public byte[] Value { get; } + + public int Length => GetLength(Name.Length, Value.Length); + + public static int GetLength(int nameLength, int valueLenth) => nameLength + valueLenth + 32; } } diff --git a/src/Kestrel.Core/Internal/Http2/HPack/Huffman.cs b/src/Kestrel.Core/Internal/Http2/HPack/Huffman.cs index 7c9e52f446..f0d489c952 100644 --- a/src/Kestrel.Core/Internal/Http2/HPack/Huffman.cs +++ b/src/Kestrel.Core/Internal/Http2/HPack/Huffman.cs @@ -2,8 +2,6 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.Collections.Generic; -using System.Text; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2.HPack { @@ -301,45 +299,108 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2.HPack return _encodingTable[data]; } - public static string Decode(byte[] data, int offset, int count) + /// + /// Decodes a Huffman encoded string from a byte array. + /// + /// The source byte array containing the encoded data. + /// The offset in the byte array where the coded data starts. + /// The number of bytes to decode. + /// The destination byte array to store the decoded data. + /// The number of decoded symbols. + public static int Decode(byte[] src, int offset, int count, byte[] dst) { - var sb = new StringBuilder(); - var i = offset; + var j = 0; var lastDecodedBits = 0; while (i < count) { - var next = (uint)(data[i] << 24 + lastDecodedBits); - next |= (i + 1 < data.Length ? (uint)(data[i + 1] << 16 + lastDecodedBits) : 0); - next |= (i + 2 < data.Length ? (uint)(data[i + 2] << 8 + lastDecodedBits) : 0); - next |= (i + 3 < data.Length ? (uint)(data[i + 3] << lastDecodedBits) : 0); + var next = (uint)(src[i] << 24 + lastDecodedBits); + next |= (i + 1 < src.Length ? (uint)(src[i + 1] << 16 + lastDecodedBits) : 0); + next |= (i + 2 < src.Length ? (uint)(src[i + 2] << 8 + lastDecodedBits) : 0); + next |= (i + 3 < src.Length ? (uint)(src[i + 3] << lastDecodedBits) : 0); var ones = (uint)(int.MinValue >> (8 - lastDecodedBits - 1)); - if (i == count - 1 && (next & ones) == ones) + if (i == count - 1 && lastDecodedBits > 0 && (next & ones) == ones) { - // Padding + // The remaining 7 or less bits are all 1, which is padding. + // We specifically check that lastDecodedBits > 0 because padding + // longer than 7 bits should be treated as a decoding error. + // http://httpwg.org/specs/rfc7541.html#rfc.section.5.2 break; } - var ch = Decode(next, out var decodedBits); - sb.Append((char)ch); + // The longest possible symbol size is 30 bits. If we're at the last 4 bytes + // of the input, we need to make sure we pass the correct number of valid bits + // left, otherwise the trailing 0s in next may form a valid symbol. + var validBits = Math.Min(30, (8 - lastDecodedBits) + (count - i - 1) * 8); + var ch = Decode(next, validBits, out var decodedBits); + if (ch == -1) + { + // No valid symbol could be decoded with the bits in next + throw new HuffmanDecodingException(CoreStrings.HPackHuffmanErrorIncomplete); + } + else if (ch == 256) + { + // A Huffman-encoded string literal containing the EOS symbol MUST be treated as a decoding error. + // http://httpwg.org/specs/rfc7541.html#rfc.section.5.2 + throw new HuffmanDecodingException(CoreStrings.HPackHuffmanErrorEOS); + } + + if (j == dst.Length) + { + throw new HuffmanDecodingException(CoreStrings.HPackHuffmanErrorDestinationTooSmall); + } + + dst[j++] = (byte)ch; + + // If we crossed a byte boundary, advance i so we start at the next byte that's not fully decoded. lastDecodedBits += decodedBits; i += lastDecodedBits / 8; + + // Modulo 8 since we only care about how many bits were decoded in the last byte that we processed. lastDecodedBits %= 8; } - return sb.ToString(); + return j; } - public static int Decode(uint data, out int decodedBits) + /// + /// Decodes a single symbol from a 32-bit word. + /// + /// A 32-bit word containing a Huffman encoded symbol. + /// + /// The number of bits in that may contain an encoded symbol. + /// This is not the exact number of bits that encode the symbol. Instead, it prevents + /// decoding the lower bits of if they don't contain any + /// encoded data. + /// + /// The number of bits decoded from . + /// The decoded symbol. + public static int Decode(uint data, int validBits, out int decodedBits) { + // The code below implements the decoding logic for a canonical Huffman code. + // + // To decode a symbol, we scan the decoding table, which is sorted by ascending symbol bit length. + // For each bit length b, we determine the maximum b-bit encoded value, plus one (that is codeMax). + // This is done with the following logic: + // + // if we're at the first entry in the table, + // codeMax = the # of symbols encoded in b bits + // else, + // left-shift codeMax by the difference between b and the previous entry's bit length, + // then increment codeMax by the # of symbols encoded in b bits + // + // Next, we look at the value v encoded in the highest b bits of data. If v is less than codeMax, + // those bits correspond to a Huffman encoded symbol. We find the corresponding decoded + // symbol in the list of values associated with bit length b in the decoding table by indexing it + // with codeMax - v. + var codeMax = 0; - for (var i = 0; i < _decodingTable.Length; i++) + for (var i = 0; i < _decodingTable.Length && _decodingTable[i].codeLength <= validBits; i++) { var (codeLength, codes) = _decodingTable[i]; - var mask = int.MinValue >> (codeLength - 1); if (i > 0) { @@ -348,6 +409,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2.HPack codeMax += codes.Length; + var mask = int.MinValue >> (codeLength - 1); var masked = (data & mask) >> (32 - codeLength); if (masked < codeMax) @@ -357,7 +419,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2.HPack } } - throw new Exception(); + decodedBits = 0; + return -1; } } } diff --git a/src/Kestrel.Core/Internal/Http2/HPack/HuffmanDecodingException.cs b/src/Kestrel.Core/Internal/Http2/HPack/HuffmanDecodingException.cs new file mode 100644 index 0000000000..3bd992ab4b --- /dev/null +++ b/src/Kestrel.Core/Internal/Http2/HPack/HuffmanDecodingException.cs @@ -0,0 +1,15 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; + +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2.HPack +{ + public class HuffmanDecodingException : Exception + { + public HuffmanDecodingException(string message) + : base(message) + { + } + } +} diff --git a/src/Kestrel.Core/Internal/Http2/HPack/IntegerDecoder.cs b/src/Kestrel.Core/Internal/Http2/HPack/IntegerDecoder.cs index c3bac3eb09..5bc051a9a3 100644 --- a/src/Kestrel.Core/Internal/Http2/HPack/IntegerDecoder.cs +++ b/src/Kestrel.Core/Internal/Http2/HPack/IntegerDecoder.cs @@ -1,9 +1,6 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System; -using System.Collections.Generic; - namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2.HPack { public class IntegerDecoder diff --git a/src/Kestrel.Core/Internal/Http2/HPack/StaticTable.cs b/src/Kestrel.Core/Internal/Http2/HPack/StaticTable.cs index 06612cc778..c28a78ff8d 100644 --- a/src/Kestrel.Core/Internal/Http2/HPack/StaticTable.cs +++ b/src/Kestrel.Core/Internal/Http2/HPack/StaticTable.cs @@ -1,8 +1,8 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System; using System.Collections.Generic; +using System.Text; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2.HPack { @@ -27,7 +27,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2.HPack public static StaticTable Instance => _instance; - public int Length => _staticTable.Length; + public int Count => _staticTable.Length; public HeaderField this[int index] => _staticTable[index]; @@ -35,67 +35,70 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2.HPack private readonly HeaderField[] _staticTable = new HeaderField[] { - new HeaderField(":authority", ""), - new HeaderField(":method", "GET"), - new HeaderField(":method", "POST"), - new HeaderField(":path", "/"), - new HeaderField(":path", "/index.html"), - new HeaderField(":scheme", "http"), - new HeaderField(":scheme", "https"), - new HeaderField(":status", "200"), - new HeaderField(":status", "204"), - new HeaderField(":status", "206"), - new HeaderField(":status", "304"), - new HeaderField(":status", "400"), - new HeaderField(":status", "404"), - new HeaderField(":status", "500"), - new HeaderField("accept-charset", ""), - new HeaderField("accept-encoding", "gzip, deflate"), - new HeaderField("accept-language", ""), - new HeaderField("accept-ranges", ""), - new HeaderField("accept", ""), - new HeaderField("access-control-allow-origin", ""), - new HeaderField("age", ""), - new HeaderField("allow", ""), - new HeaderField("authorization", ""), - new HeaderField("cache-control", ""), - new HeaderField("content-disposition", ""), - new HeaderField("content-encoding", ""), - new HeaderField("content-language", ""), - new HeaderField("content-length", ""), - new HeaderField("content-location", ""), - new HeaderField("content-range", ""), - new HeaderField("content-type", ""), - new HeaderField("cookie", ""), - new HeaderField("date", ""), - new HeaderField("etag", ""), - new HeaderField("expect", ""), - new HeaderField("expires", ""), - new HeaderField("from", ""), - new HeaderField("host", ""), - new HeaderField("if-match", ""), - new HeaderField("if-modified-since", ""), - new HeaderField("if-none-match", ""), - new HeaderField("if-range", ""), - new HeaderField("if-unmodifiedsince", ""), - new HeaderField("last-modified", ""), - new HeaderField("link", ""), - new HeaderField("location", ""), - new HeaderField("max-forwards", ""), - new HeaderField("proxy-authenticate", ""), - new HeaderField("proxy-authorization", ""), - new HeaderField("range", ""), - new HeaderField("referer", ""), - new HeaderField("refresh", ""), - new HeaderField("retry-after", ""), - new HeaderField("server", ""), - new HeaderField("set-cookie", ""), - new HeaderField("strict-transport-security", ""), - new HeaderField("transfer-encoding", ""), - new HeaderField("user-agent", ""), - new HeaderField("vary", ""), - new HeaderField("via", ""), - new HeaderField("www-authenticate", "") + CreateHeaderField(":authority", ""), + CreateHeaderField(":method", "GET"), + CreateHeaderField(":method", "POST"), + CreateHeaderField(":path", "/"), + CreateHeaderField(":path", "/index.html"), + CreateHeaderField(":scheme", "http"), + CreateHeaderField(":scheme", "https"), + CreateHeaderField(":status", "200"), + CreateHeaderField(":status", "204"), + CreateHeaderField(":status", "206"), + CreateHeaderField(":status", "304"), + CreateHeaderField(":status", "400"), + CreateHeaderField(":status", "404"), + CreateHeaderField(":status", "500"), + CreateHeaderField("accept-charset", ""), + CreateHeaderField("accept-encoding", "gzip, deflate"), + CreateHeaderField("accept-language", ""), + CreateHeaderField("accept-ranges", ""), + CreateHeaderField("accept", ""), + CreateHeaderField("access-control-allow-origin", ""), + CreateHeaderField("age", ""), + CreateHeaderField("allow", ""), + CreateHeaderField("authorization", ""), + CreateHeaderField("cache-control", ""), + CreateHeaderField("content-disposition", ""), + CreateHeaderField("content-encoding", ""), + CreateHeaderField("content-language", ""), + CreateHeaderField("content-length", ""), + CreateHeaderField("content-location", ""), + CreateHeaderField("content-range", ""), + CreateHeaderField("content-type", ""), + CreateHeaderField("cookie", ""), + CreateHeaderField("date", ""), + CreateHeaderField("etag", ""), + CreateHeaderField("expect", ""), + CreateHeaderField("expires", ""), + CreateHeaderField("from", ""), + CreateHeaderField("host", ""), + CreateHeaderField("if-match", ""), + CreateHeaderField("if-modified-since", ""), + CreateHeaderField("if-none-match", ""), + CreateHeaderField("if-range", ""), + CreateHeaderField("if-unmodifiedsince", ""), + CreateHeaderField("last-modified", ""), + CreateHeaderField("link", ""), + CreateHeaderField("location", ""), + CreateHeaderField("max-forwards", ""), + CreateHeaderField("proxy-authenticate", ""), + CreateHeaderField("proxy-authorization", ""), + CreateHeaderField("range", ""), + CreateHeaderField("referer", ""), + CreateHeaderField("refresh", ""), + CreateHeaderField("retry-after", ""), + CreateHeaderField("server", ""), + CreateHeaderField("set-cookie", ""), + CreateHeaderField("strict-transport-security", ""), + CreateHeaderField("transfer-encoding", ""), + CreateHeaderField("user-agent", ""), + CreateHeaderField("vary", ""), + CreateHeaderField("via", ""), + CreateHeaderField("www-authenticate", "") }; + + private static HeaderField CreateHeaderField(string name, string value) + => new HeaderField(Encoding.ASCII.GetBytes(name), Encoding.ASCII.GetBytes(value)); } } diff --git a/src/Kestrel.Core/Internal/Http2/Http2Connection.cs b/src/Kestrel.Core/Internal/Http2/Http2Connection.cs index 7baa89c2c7..b4e54e7b01 100644 --- a/src/Kestrel.Core/Internal/Http2/Http2Connection.cs +++ b/src/Kestrel.Core/Internal/Http2/Http2Connection.cs @@ -16,7 +16,7 @@ using Microsoft.Extensions.Logging; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 { - public class Http2Connection : ITimeoutControl, IHttp2StreamLifetimeHandler + public class Http2Connection : ITimeoutControl, IHttp2StreamLifetimeHandler, IHttpHeadersHandler { public static byte[] ClientPreface { get; } = Encoding.ASCII.GetBytes("PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n"); @@ -40,7 +40,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 { _context = context; _frameWriter = new Http2FrameWriter(context.Transport.Output, context.Application.Input); - _hpackDecoder = new HPackDecoder(); + _hpackDecoder = new HPackDecoder((int)_serverSettings.HeaderTableSize); } public string ConnectionId => _context.ConnectionId; @@ -141,6 +141,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 error = ex; errorCode = ex.ErrorCode; } + catch (HPackDecodingException ex) + { + // TODO: log + error = ex; + errorCode = Http2ErrorCode.COMPRESSION_ERROR; + } catch (Exception ex) { // TODO: log @@ -350,9 +356,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 _streams[_incomingFrame.StreamId] = _currentHeadersStream; - _hpackDecoder.Decode(_incomingFrame.HeadersPayload, _currentHeadersStream.RequestHeaders); + var endHeaders = (_incomingFrame.HeadersFlags & Http2HeadersFrameFlags.END_HEADERS) == Http2HeadersFrameFlags.END_HEADERS; + _hpackDecoder.Decode(_incomingFrame.HeadersPayload, endHeaders, handler: this); - if ((_incomingFrame.HeadersFlags & Http2HeadersFrameFlags.END_HEADERS) == Http2HeadersFrameFlags.END_HEADERS) + if (endHeaders) { _highestOpenedStreamId = _incomingFrame.StreamId; _ = _currentHeadersStream.ProcessRequestsAsync(); @@ -525,9 +532,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 throw new Http2ConnectionErrorException(Http2ErrorCode.PROTOCOL_ERROR); } - _hpackDecoder.Decode(_incomingFrame.HeadersPayload, _currentHeadersStream.RequestHeaders); + var endHeaders = (_incomingFrame.ContinuationFlags & Http2ContinuationFrameFlags.END_HEADERS) == Http2ContinuationFrameFlags.END_HEADERS; + _hpackDecoder.Decode(_incomingFrame.HeadersPayload, endHeaders, handler: this); - if ((_incomingFrame.ContinuationFlags & Http2ContinuationFrameFlags.END_HEADERS) == Http2ContinuationFrameFlags.END_HEADERS) + if (endHeaders) { _highestOpenedStreamId = _currentHeadersStream.StreamId; _ = _currentHeadersStream.ProcessRequestsAsync(); @@ -571,6 +579,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 _streams.TryRemove(streamId, out _); } + public void OnHeader(Span name, Span value) + { + _currentHeadersStream.OnHeader(name, value); + } + void ITimeoutControl.SetTimeout(long ticks, TimeoutAction timeoutAction) { } diff --git a/src/Kestrel.Core/Properties/CoreStrings.Designer.cs b/src/Kestrel.Core/Properties/CoreStrings.Designer.cs index 2fa3c085eb..7084b94b0c 100644 --- a/src/Kestrel.Core/Properties/CoreStrings.Designer.cs +++ b/src/Kestrel.Core/Properties/CoreStrings.Designer.cs @@ -1144,6 +1144,118 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core internal static string FormatEndPointHttp2NotNegotiated() => GetString("EndPointHttp2NotNegotiated"); + /// + /// A dynamic table size of {size} octets is greater than the configured maximum size of {maxSize} octets. + /// + internal static string HPackErrorDynamicTableSizeUpdateTooLarge + { + get => GetString("HPackErrorDynamicTableSizeUpdateTooLarge"); + } + + /// + /// A dynamic table size of {size} octets is greater than the configured maximum size of {maxSize} octets. + /// + internal static string FormatHPackErrorDynamicTableSizeUpdateTooLarge(object size, object maxSize) + => string.Format(CultureInfo.CurrentCulture, GetString("HPackErrorDynamicTableSizeUpdateTooLarge", "size", "maxSize"), size, maxSize); + + /// + /// Index {index} is outside the bounds of the header field table. + /// + internal static string HPackErrorIndexOutOfRange + { + get => GetString("HPackErrorIndexOutOfRange"); + } + + /// + /// Index {index} is outside the bounds of the header field table. + /// + internal static string FormatHPackErrorIndexOutOfRange(object index) + => string.Format(CultureInfo.CurrentCulture, GetString("HPackErrorIndexOutOfRange", "index"), index); + + /// + /// Input data could not be fully decoded. + /// + internal static string HPackHuffmanErrorIncomplete + { + get => GetString("HPackHuffmanErrorIncomplete"); + } + + /// + /// Input data could not be fully decoded. + /// + internal static string FormatHPackHuffmanErrorIncomplete() + => GetString("HPackHuffmanErrorIncomplete"); + + /// + /// Input data contains the EOS symbol. + /// + internal static string HPackHuffmanErrorEOS + { + get => GetString("HPackHuffmanErrorEOS"); + } + + /// + /// Input data contains the EOS symbol. + /// + internal static string FormatHPackHuffmanErrorEOS() + => GetString("HPackHuffmanErrorEOS"); + + /// + /// The destination buffer is not large enough to store the decoded data. + /// + internal static string HPackHuffmanErrorDestinationTooSmall + { + get => GetString("HPackHuffmanErrorDestinationTooSmall"); + } + + /// + /// The destination buffer is not large enough to store the decoded data. + /// + internal static string FormatHPackHuffmanErrorDestinationTooSmall() + => GetString("HPackHuffmanErrorDestinationTooSmall"); + + /// + /// Huffman decoding error. + /// + internal static string HPackHuffmanError + { + get => GetString("HPackHuffmanError"); + } + + /// + /// Huffman decoding error. + /// + internal static string FormatHPackHuffmanError() + => GetString("HPackHuffmanError"); + + /// + /// Decoded string length of {length} octets is greater than the configured maximum length of {maxStringLength} octets. + /// + internal static string HPackStringLengthTooLarge + { + get => GetString("HPackStringLengthTooLarge"); + } + + /// + /// Decoded string length of {length} octets is greater than the configured maximum length of {maxStringLength} octets. + /// + internal static string FormatHPackStringLengthTooLarge(object length, object maxStringLength) + => string.Format(CultureInfo.CurrentCulture, GetString("HPackStringLengthTooLarge", "length", "maxStringLength"), length, maxStringLength); + + /// + /// The header block was incomplete and could not be fully decoded. + /// + internal static string HPackErrorIncompleteHeaderBlock + { + get => GetString("HPackErrorIncompleteHeaderBlock"); + } + + /// + /// The header block was incomplete and could not be fully decoded. + /// + internal static string FormatHPackErrorIncompleteHeaderBlock() + => GetString("HPackErrorIncompleteHeaderBlock"); + private static string GetString(string name, params string[] formatterNames) { var value = _resourceManager.GetString(name); diff --git a/test/Kestrel.Core.Tests/DynamicTableTests.cs b/test/Kestrel.Core.Tests/DynamicTableTests.cs new file mode 100644 index 0000000000..0943272c72 --- /dev/null +++ b/test/Kestrel.Core.Tests/DynamicTableTests.cs @@ -0,0 +1,158 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Linq; +using System.Text; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2.HPack; +using Xunit; + +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests +{ + public class DynamicTableTests + { + private readonly HeaderField _header1 = new HeaderField(Encoding.ASCII.GetBytes("header-1"), Encoding.ASCII.GetBytes("value1")); + private readonly HeaderField _header2 = new HeaderField(Encoding.ASCII.GetBytes("header-02"), Encoding.ASCII.GetBytes("value_2")); + + [Fact] + public void DynamicTableIsInitiallyEmpty() + { + var dynamicTable = new DynamicTable(4096); + Assert.Equal(0, dynamicTable.Count); + Assert.Equal(0, dynamicTable.Size); + Assert.Equal(4096, dynamicTable.MaxSize); + } + + [Fact] + public void CountIsNumberOfEntriesInDynamicTable() + { + var dynamicTable = new DynamicTable(4096); + + dynamicTable.Insert(_header1.Name, _header1.Value); + Assert.Equal(1, dynamicTable.Count); + + dynamicTable.Insert(_header2.Name, _header2.Value); + Assert.Equal(2, dynamicTable.Count); + } + + [Fact] + public void SizeIsCurrentDynamicTableSize() + { + var dynamicTable = new DynamicTable(4096); + Assert.Equal(0, dynamicTable.Size); + + dynamicTable.Insert(_header1.Name, _header1.Value); + Assert.Equal(_header1.Length, dynamicTable.Size); + + dynamicTable.Insert(_header2.Name, _header2.Value); + Assert.Equal(_header1.Length + _header2.Length, dynamicTable.Size); + } + + [Fact] + public void FirstEntryIsMostRecentEntry() + { + var dynamicTable = new DynamicTable(4096); + dynamicTable.Insert(_header1.Name, _header1.Value); + dynamicTable.Insert(_header2.Name, _header2.Value); + + VerifyTableEntries(dynamicTable, _header2, _header1); + } + + [Fact] + public void ThrowsIndexOutOfRangeException() + { + var dynamicTable = new DynamicTable(4096); + Assert.Throws(() => dynamicTable[0]); + + dynamicTable.Insert(_header1.Name, _header1.Value); + Assert.Throws(() => dynamicTable[1]); + } + + [Fact] + public void NoOpWhenInsertingEntryLargerThanMaxSize() + { + var dynamicTable = new DynamicTable(_header1.Length - 1); + dynamicTable.Insert(_header1.Name, _header1.Value); + + Assert.Equal(0, dynamicTable.Count); + Assert.Equal(0, dynamicTable.Size); + } + + [Fact] + public void NoOpWhenInsertingEntryLargerThanRemainingSpace() + { + var dynamicTable = new DynamicTable(_header1.Length); + dynamicTable.Insert(_header1.Name, _header1.Value); + + VerifyTableEntries(dynamicTable, _header1); + + dynamicTable.Insert(_header2.Name, _header2.Value); + + Assert.Equal(0, dynamicTable.Count); + Assert.Equal(0, dynamicTable.Size); + } + + [Fact] + public void ResizingEvictsOldestEntries() + { + var dynamicTable = new DynamicTable(4096); + dynamicTable.Insert(_header1.Name, _header1.Value); + dynamicTable.Insert(_header2.Name, _header2.Value); + + VerifyTableEntries(dynamicTable, _header2, _header1); + + dynamicTable.Resize(_header2.Length); + + VerifyTableEntries(dynamicTable, _header2); + } + + [Fact] + public void ResizingToZeroEvictsAllEntries() + { + var dynamicTable = new DynamicTable(4096); + dynamicTable.Insert(_header1.Name, _header1.Value); + dynamicTable.Insert(_header2.Name, _header2.Value); + + dynamicTable.Resize(0); + + Assert.Equal(0, dynamicTable.Count); + Assert.Equal(0, dynamicTable.Size); + } + + [Fact] + public void CanBeResizedToLargerMaxSize() + { + var dynamicTable = new DynamicTable(_header1.Length); + dynamicTable.Insert(_header1.Name, _header1.Value); + dynamicTable.Insert(_header2.Name, _header2.Value); + + // _header2 is larger than _header1, so an attempt at inserting it + // would first clear the table then return without actually inserting it, + // given it is larger than the current max size. + Assert.Equal(0, dynamicTable.Count); + Assert.Equal(0, dynamicTable.Size); + + dynamicTable.Resize(dynamicTable.MaxSize + _header2.Length); + dynamicTable.Insert(_header2.Name, _header2.Value); + + VerifyTableEntries(dynamicTable, _header2); + } + + private void VerifyTableEntries(DynamicTable dynamicTable, params HeaderField[] entries) + { + Assert.Equal(entries.Length, dynamicTable.Count); + Assert.Equal(entries.Sum(e => e.Length), dynamicTable.Size); + + for (var i = 0; i < entries.Length; i++) + { + var headerField = dynamicTable[i]; + + Assert.NotSame(entries[i].Name, headerField.Name); + Assert.Equal(entries[i].Name, headerField.Name); + + Assert.NotSame(entries[i].Value, headerField.Value); + Assert.Equal(entries[i].Value, headerField.Value); + } + } + } +} diff --git a/test/Kestrel.Core.Tests/HPackDecoderTests.cs b/test/Kestrel.Core.Tests/HPackDecoderTests.cs new file mode 100644 index 0000000000..a20c0be120 --- /dev/null +++ b/test/Kestrel.Core.Tests/HPackDecoderTests.cs @@ -0,0 +1,560 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2.HPack; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; +using Xunit; + +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests +{ + public class HPackDecoderTests : IHttpHeadersHandler + { + private const int DynamicTableInitialMaxSize = 4096; + + // Indexed Header Field Representation - Static Table - Index 2 (:method: GET) + private static readonly byte[] _indexedHeaderStatic = new byte[] { 0x82 }; + + // Indexed Header Field Representation - Dynamic Table - Index 62 (first index in dynamic table) + private static readonly byte[] _indexedHeaderDynamic = new byte[] { 0xbe }; + + // Literal Header Field with Incremental Indexing Representation - New Name + private static readonly byte[] _literalHeaderFieldWithIndexingNewName = new byte[] { 0x40 }; + + // Literal Header Field with Incremental Indexing Representation - Indexed Name - Index 58 (user-agent) + private static readonly byte[] _literalHeaderFieldWithIndexingIndexedName = new byte[] { 0x7a }; + + // Literal Header Field without Indexing Representation - New Name + private static readonly byte[] _literalHeaderFieldWithoutIndexingNewName = new byte[] { 0x00 }; + + // Literal Header Field without Indexing Representation - Indexed Name - Index 58 (user-agent) + private static readonly byte[] _literalHeaderFieldWithoutIndexingIndexedName = new byte[] { 0x0f, 0x2b }; + + // Literal Header Field Never Indexed Representation - New Name + private static readonly byte[] _literalHeaderFieldNeverIndexedNewName = new byte[] { 0x10 }; + + // Literal Header Field Never Indexed Representation - Indexed Name - Index 58 (user-agent) + private static readonly byte[] _literalHeaderFieldNeverIndexedIndexedName = new byte[] { 0x1f, 0x2b }; + + private const string _userAgentString = "user-agent"; + + private static readonly byte[] _userAgentBytes = Encoding.ASCII.GetBytes(_userAgentString); + + private const string _headerNameString = "new-header"; + + private static readonly byte[] _headerNameBytes = Encoding.ASCII.GetBytes(_headerNameString); + + // n e w - h e a d e r * + // 10101000 10111110 00010110 10011100 10100011 10010000 10110110 01111111 + private static readonly byte[] _headerNameHuffmanBytes = new byte[] { 0xa8, 0xbe, 0x16, 0x9c, 0xa3, 0x90, 0xb6, 0x7f }; + + private const string _headerValueString = "value"; + + private static readonly byte[] _headerValueBytes = Encoding.ASCII.GetBytes(_headerValueString); + + // v a l u e * + // 11101110 00111010 00101101 00101111 + private static readonly byte[] _headerValueHuffmanBytes = new byte [] { 0xee, 0x3a, 0x2d, 0x2f }; + + private static readonly byte[] _headerName = new byte[] { (byte)_headerNameBytes.Length } + .Concat(_headerNameBytes) + .ToArray(); + + private static readonly byte[] _headerNameHuffman = new byte[] { (byte)(0x80 | _headerNameHuffmanBytes.Length) } + .Concat(_headerNameHuffmanBytes) + .ToArray(); + + private static readonly byte[] _headerValue = new byte[] { (byte)_headerValueBytes.Length } + .Concat(_headerValueBytes) + .ToArray(); + + private static readonly byte[] _headerValueHuffman = new byte[] { (byte)(0x80 | _headerValueHuffmanBytes.Length) } + .Concat(_headerValueHuffmanBytes) + .ToArray(); + + // & * + // 11111000 11111111 + private static readonly byte[] _huffmanLongPadding = new byte[] { 0x82, 0xf8, 0xff }; + + // EOS * + // 11111111 11111111 11111111 11111111 + private static readonly byte[] _huffmanEos = new byte[] { 0x84, 0xff, 0xff, 0xff, 0xff }; + + private readonly DynamicTable _dynamicTable; + private readonly HPackDecoder _decoder; + + private readonly Dictionary _decodedHeaders = new Dictionary(); + + public HPackDecoderTests() + { + _dynamicTable = new DynamicTable(DynamicTableInitialMaxSize); + _decoder = new HPackDecoder(DynamicTableInitialMaxSize, _dynamicTable); + } + + void IHttpHeadersHandler.OnHeader(Span name, Span value) + { + _decodedHeaders[name.GetAsciiStringNonNullCharacters()] = value.GetAsciiStringNonNullCharacters(); + } + + [Fact] + public void DecodesIndexedHeaderField_StaticTable() + { + _decoder.Decode(_indexedHeaderStatic, endHeaders: true, handler: this); + Assert.Equal("GET", _decodedHeaders[":method"]); + } + + [Fact] + public void DecodesIndexedHeaderField_DynamicTable() + { + // Add the header to the dynamic table + _dynamicTable.Insert(_headerNameBytes, _headerValueBytes); + + // Index it + _decoder.Decode(_indexedHeaderDynamic, endHeaders: true, handler: this); + Assert.Equal(_headerValueString, _decodedHeaders[_headerNameString]); + } + + [Fact] + public void DecodesIndexedHeaderField_OutOfRange_Error() + { + var exception = Assert.Throws(() => _decoder.Decode(_indexedHeaderDynamic, endHeaders: true, handler: this)); + Assert.Equal(CoreStrings.FormatHPackErrorIndexOutOfRange(62), exception.Message); + Assert.Empty(_decodedHeaders); + } + + [Fact] + public void DecodesLiteralHeaderFieldWithIncrementalIndexing_NewName() + { + var encoded = _literalHeaderFieldWithIndexingNewName + .Concat(_headerName) + .Concat(_headerValue) + .ToArray(); + + TestDecodeWithIndexing(encoded, _headerNameString, _headerValueString); + } + + [Fact] + public void DecodesLiteralHeaderFieldWithIncrementalIndexing_NewName_HuffmanEncodedName() + { + var encoded = _literalHeaderFieldWithIndexingNewName + .Concat(_headerNameHuffman) + .Concat(_headerValue) + .ToArray(); + + TestDecodeWithIndexing(encoded, _headerNameString, _headerValueString); + } + + [Fact] + public void DecodesLiteralHeaderFieldWithIncrementalIndexing_NewName_HuffmanEncodedValue() + { + var encoded = _literalHeaderFieldWithIndexingNewName + .Concat(_headerName) + .Concat(_headerValueHuffman) + .ToArray(); + + TestDecodeWithIndexing(encoded, _headerNameString, _headerValueString); + } + + [Fact] + public void DecodesLiteralHeaderFieldWithIncrementalIndexing_NewName_HuffmanEncodedNameAndValue() + { + var encoded = _literalHeaderFieldWithIndexingNewName + .Concat(_headerNameHuffman) + .Concat(_headerValueHuffman) + .ToArray(); + + TestDecodeWithIndexing(encoded, _headerNameString, _headerValueString); + } + + [Fact] + public void DecodesLiteralHeaderFieldWithIncrementalIndexing_IndexedName() + { + var encoded = _literalHeaderFieldWithIndexingIndexedName + .Concat(_headerValue) + .ToArray(); + + TestDecodeWithIndexing(encoded, _userAgentString, _headerValueString); + } + + [Fact] + public void DecodesLiteralHeaderFieldWithIncrementalIndexing_IndexedName_HuffmanEncodedValue() + { + var encoded = _literalHeaderFieldWithIndexingIndexedName + .Concat(_headerValueHuffman) + .ToArray(); + + TestDecodeWithIndexing(encoded, _userAgentString, _headerValueString); + } + + [Fact] + public void DecodesLiteralHeaderFieldWithIncrementalIndexing_IndexedName_OutOfRange_Error() + { + // 01 (Literal Header Field without Indexing Representation) + // 11 1110 (Indexed Name - Index 62 encoded with 6-bit prefix - see http://httpwg.org/specs/rfc7541.html#integer.representation) + // Index 62 is the first entry in the dynamic table. If there's nothing there, the decoder should throw. + + var exception = Assert.Throws(() => _decoder.Decode(new byte[] { 0x7e }, endHeaders: true, handler: this)); + Assert.Equal(CoreStrings.FormatHPackErrorIndexOutOfRange(62), exception.Message); + Assert.Empty(_decodedHeaders); + } + + [Fact] + public void DecodesLiteralHeaderFieldWithoutIndexing_NewName() + { + var encoded = _literalHeaderFieldWithoutIndexingNewName + .Concat(_headerName) + .Concat(_headerValue) + .ToArray(); + + TestDecodeWithoutIndexing(encoded, _headerNameString, _headerValueString); + } + + [Fact] + public void DecodesLiteralHeaderFieldWithoutIndexing_NewName_HuffmanEncodedName() + { + var encoded = _literalHeaderFieldWithoutIndexingNewName + .Concat(_headerNameHuffman) + .Concat(_headerValue) + .ToArray(); + + TestDecodeWithoutIndexing(encoded, _headerNameString, _headerValueString); + } + + [Fact] + public void DecodesLiteralHeaderFieldWithoutIndexing_NewName_HuffmanEncodedValue() + { + var encoded = _literalHeaderFieldWithoutIndexingNewName + .Concat(_headerName) + .Concat(_headerValueHuffman) + .ToArray(); + + TestDecodeWithoutIndexing(encoded, _headerNameString, _headerValueString); + } + + [Fact] + public void DecodesLiteralHeaderFieldWithoutIndexing_NewName_HuffmanEncodedNameAndValue() + { + var encoded = _literalHeaderFieldWithoutIndexingNewName + .Concat(_headerNameHuffman) + .Concat(_headerValueHuffman) + .ToArray(); + + TestDecodeWithoutIndexing(encoded, _headerNameString, _headerValueString); + } + + [Fact] + public void DecodesLiteralHeaderFieldWithoutIndexing_IndexedName() + { + var encoded = _literalHeaderFieldWithoutIndexingIndexedName + .Concat(_headerValue) + .ToArray(); + + TestDecodeWithoutIndexing(encoded, _userAgentString, _headerValueString); + } + + [Fact] + public void DecodesLiteralHeaderFieldWithoutIndexing_IndexedName_HuffmanEncodedValue() + { + var encoded = _literalHeaderFieldWithoutIndexingIndexedName + .Concat(_headerValueHuffman) + .ToArray(); + + TestDecodeWithoutIndexing(encoded, _userAgentString, _headerValueString); + } + + [Fact] + public void DecodesLiteralHeaderFieldWithoutIndexing_IndexedName_OutOfRange_Error() + { + // 0000 (Literal Header Field without Indexing Representation) + // 1111 0010 1111 (Indexed Name - Index 62 encoded with 4-bit prefix - see http://httpwg.org/specs/rfc7541.html#integer.representation) + // Index 62 is the first entry in the dynamic table. If there's nothing there, the decoder should throw. + + var exception = Assert.Throws(() => _decoder.Decode(new byte[] { 0x0f, 0x2f }, endHeaders: true, handler: this)); + Assert.Equal(CoreStrings.FormatHPackErrorIndexOutOfRange(62), exception.Message); + Assert.Empty(_decodedHeaders); + } + + [Fact] + public void DecodesLiteralHeaderFieldNeverIndexed_NewName() + { + var encoded = _literalHeaderFieldNeverIndexedNewName + .Concat(_headerName) + .Concat(_headerValue) + .ToArray(); + + TestDecodeWithoutIndexing(encoded, _headerNameString, _headerValueString); + } + + [Fact] + public void DecodesLiteralHeaderFieldNeverIndexed_NewName_HuffmanEncodedName() + { + var encoded = _literalHeaderFieldNeverIndexedNewName + .Concat(_headerNameHuffman) + .Concat(_headerValue) + .ToArray(); + + TestDecodeWithoutIndexing(encoded, _headerNameString, _headerValueString); + } + + [Fact] + public void DecodesLiteralHeaderFieldNeverIndexed_NewName_HuffmanEncodedValue() + { + var encoded = _literalHeaderFieldNeverIndexedNewName + .Concat(_headerName) + .Concat(_headerValueHuffman) + .ToArray(); + + TestDecodeWithoutIndexing(encoded, _headerNameString, _headerValueString); + } + + [Fact] + public void DecodesLiteralHeaderFieldNeverIndexed_NewName_HuffmanEncodedNameAndValue() + { + var encoded = _literalHeaderFieldNeverIndexedNewName + .Concat(_headerNameHuffman) + .Concat(_headerValueHuffman) + .ToArray(); + + TestDecodeWithoutIndexing(encoded, _headerNameString, _headerValueString); + } + + [Fact] + public void DecodesLiteralHeaderFieldNeverIndexed_IndexedName() + { + // 0001 (Literal Header Field Never Indexed Representation) + // 1111 0010 1011 (Indexed Name - Index 58 encoded with 4-bit prefix - see http://httpwg.org/specs/rfc7541.html#integer.representation) + // Concatenated with value bytes + var encoded = _literalHeaderFieldNeverIndexedIndexedName + .Concat(_headerValue) + .ToArray(); + + TestDecodeWithoutIndexing(encoded, _userAgentString, _headerValueString); + } + + [Fact] + public void DecodesLiteralHeaderFieldNeverIndexed_IndexedName_HuffmanEncodedValue() + { + // 0001 (Literal Header Field Never Indexed Representation) + // 1111 0010 1011 (Indexed Name - Index 58 encoded with 4-bit prefix - see http://httpwg.org/specs/rfc7541.html#integer.representation) + // Concatenated with Huffman encoded value bytes + var encoded = _literalHeaderFieldNeverIndexedIndexedName + .Concat(_headerValueHuffman) + .ToArray(); + + TestDecodeWithoutIndexing(encoded, _userAgentString, _headerValueString); + } + + [Fact] + public void DecodesLiteralHeaderFieldNeverIndexed_IndexedName_OutOfRange_Error() + { + // 0001 (Literal Header Field Never Indexed Representation) + // 1111 0010 1111 (Indexed Name - Index 62 encoded with 4-bit prefix - see http://httpwg.org/specs/rfc7541.html#integer.representation) + // Index 62 is the first entry in the dynamic table. If there's nothing there, the decoder should throw. + + var exception = Assert.Throws(() => _decoder.Decode(new byte[] { 0x1f, 0x2f }, endHeaders: true, handler: this)); + Assert.Equal(CoreStrings.FormatHPackErrorIndexOutOfRange(62), exception.Message); + Assert.Empty(_decodedHeaders); + } + + [Fact] + public void DecodesDynamicTableSizeUpdate() + { + // 001 (Dynamic Table Size Update) + // 11110 (30 encoded with 5-bit prefix - see http://httpwg.org/specs/rfc7541.html#integer.representation) + + Assert.Equal(DynamicTableInitialMaxSize, _dynamicTable.MaxSize); + + _decoder.Decode(new byte[] { 0x3e }, endHeaders: true, handler: this); + + Assert.Equal(30, _dynamicTable.MaxSize); + Assert.Empty(_decodedHeaders); + } + + [Fact] + public void DecodesDynamicTableSizeUpdate_GreaterThanLimit_Error() + { + // 001 (Dynamic Table Size Update) + // 11111 11100010 00011111 (4097 encoded with 5-bit prefix - see http://httpwg.org/specs/rfc7541.html#integer.representation) + + Assert.Equal(DynamicTableInitialMaxSize, _dynamicTable.MaxSize); + + var exception = Assert.Throws(() => _decoder.Decode(new byte[] { 0x3f, 0xe2, 0x1f }, endHeaders: true, handler: this)); + Assert.Equal(CoreStrings.FormatHPackErrorDynamicTableSizeUpdateTooLarge(4097, DynamicTableInitialMaxSize), exception.Message); + Assert.Empty(_decodedHeaders); + } + + [Fact] + public void DecodesStringLength_GreaterThanLimit_Error() + { + var encoded = _literalHeaderFieldWithoutIndexingNewName + .Concat(new byte[] { 0xff, 0x82, 0x1f }) // 4097 encoded with 7-bit prefix + .ToArray(); + + var exception = Assert.Throws(() => _decoder.Decode(encoded, endHeaders: true, handler: this)); + Assert.Equal(CoreStrings.FormatHPackStringLengthTooLarge(4097, HPackDecoder.MaxStringOctets), exception.Message); + Assert.Empty(_decodedHeaders); + } + + public static readonly TheoryData _incompleteHeaderBlockData = new TheoryData + { + // Indexed Header Field Representation - incomplete index encoding + new byte[] { 0xff }, + + // Literal Header Field with Incremental Indexing Representation - New Name - incomplete header name length encoding + new byte[] { 0x40, 0x7f }, + + // Literal Header Field with Incremental Indexing Representation - New Name - incomplete header name + new byte[] { 0x40, 0x01 }, + new byte[] { 0x40, 0x02, 0x61 }, + + // Literal Header Field with Incremental Indexing Representation - New Name - incomplete header value length encoding + new byte[] { 0x40, 0x01, 0x61, 0x7f }, + + // Literal Header Field with Incremental Indexing Representation - New Name - incomplete header value + new byte[] { 0x40, 0x01, 0x61, 0x01 }, + new byte[] { 0x40, 0x01, 0x61, 0x02, 0x61 }, + + // Literal Header Field with Incremental Indexing Representation - Indexed Name - incomplete index encoding + new byte[] { 0x7f }, + + // Literal Header Field with Incremental Indexing Representation - Indexed Name - incomplete header value length encoding + new byte[] { 0x7a, 0xff }, + + // Literal Header Field with Incremental Indexing Representation - Indexed Name - incomplete header value + new byte[] { 0x7a, 0x01 }, + new byte[] { 0x7a, 0x02, 0x61 }, + + // Literal Header Field without Indexing - New Name - incomplete header name length encoding + new byte[] { 0x00, 0xff }, + + // Literal Header Field without Indexing - New Name - incomplete header name + new byte[] { 0x00, 0x01 }, + new byte[] { 0x00, 0x02, 0x61 }, + + // Literal Header Field without Indexing - New Name - incomplete header value length encoding + new byte[] { 0x00, 0x01, 0x61, 0xff }, + + // Literal Header Field without Indexing - New Name - incomplete header value + new byte[] { 0x00, 0x01, 0x61, 0x01 }, + new byte[] { 0x00, 0x01, 0x61, 0x02, 0x61 }, + + // Literal Header Field without Indexing Representation - Indexed Name - incomplete index encoding + new byte[] { 0x0f }, + + // Literal Header Field without Indexing Representation - Indexed Name - incomplete header value length encoding + new byte[] { 0x02, 0xff }, + + // Literal Header Field without Indexing Representation - Indexed Name - incomplete header value + new byte[] { 0x02, 0x01 }, + new byte[] { 0x02, 0x02, 0x61 }, + + // Literal Header Field Never Indexed - New Name - incomplete header name length encoding + new byte[] { 0x10, 0xff }, + + // Literal Header Field Never Indexed - New Name - incomplete header name + new byte[] { 0x10, 0x01 }, + new byte[] { 0x10, 0x02, 0x61 }, + + // Literal Header Field Never Indexed - New Name - incomplete header value length encoding + new byte[] { 0x10, 0x01, 0x61, 0xff }, + + // Literal Header Field Never Indexed - New Name - incomplete header value + new byte[] { 0x10, 0x01, 0x61, 0x01 }, + new byte[] { 0x10, 0x01, 0x61, 0x02, 0x61 }, + + // Literal Header Field Never Indexed Representation - Indexed Name - incomplete index encoding + new byte[] { 0x1f }, + + // Literal Header Field Never Indexed Representation - Indexed Name - incomplete header value length encoding + new byte[] { 0x12, 0xff }, + + // Literal Header Field Never Indexed Representation - Indexed Name - incomplete header value + new byte[] { 0x12, 0x01 }, + new byte[] { 0x12, 0x02, 0x61 }, + + // Dynamic Table Size Update - incomplete max size encoding + new byte[] { 0x3f } + }; + + [Theory] + [MemberData(nameof(_incompleteHeaderBlockData))] + public void DecodesIncompleteHeaderBlock_Error(byte[] encoded) + { + var exception = Assert.Throws(() => _decoder.Decode(encoded, endHeaders: true, handler: this)); + Assert.Equal(CoreStrings.HPackErrorIncompleteHeaderBlock, exception.Message); + Assert.Empty(_decodedHeaders); + } + + public static readonly TheoryData _huffmanDecodingErrorData = new TheoryData + { + // Invalid Huffman encoding in header name + + _literalHeaderFieldWithIndexingNewName.Concat(_huffmanLongPadding).ToArray(), + _literalHeaderFieldWithIndexingNewName.Concat(_huffmanEos).ToArray(), + + _literalHeaderFieldWithoutIndexingNewName.Concat(_huffmanLongPadding).ToArray(), + _literalHeaderFieldWithoutIndexingNewName.Concat(_huffmanEos).ToArray(), + + _literalHeaderFieldNeverIndexedNewName.Concat(_huffmanLongPadding).ToArray(), + _literalHeaderFieldNeverIndexedNewName.Concat(_huffmanEos).ToArray(), + + // Invalid Huffman encoding in header value + + _literalHeaderFieldWithIndexingIndexedName.Concat(_huffmanLongPadding).ToArray(), + _literalHeaderFieldWithIndexingIndexedName.Concat(_huffmanEos).ToArray(), + + _literalHeaderFieldWithoutIndexingIndexedName.Concat(_huffmanLongPadding).ToArray(), + _literalHeaderFieldWithoutIndexingIndexedName.Concat(_huffmanEos).ToArray(), + + _literalHeaderFieldNeverIndexedIndexedName.Concat(_huffmanLongPadding).ToArray(), + _literalHeaderFieldNeverIndexedIndexedName.Concat(_huffmanEos).ToArray() + }; + + [Theory] + [MemberData(nameof(_huffmanDecodingErrorData))] + public void WrapsHuffmanDecodingExceptionInHPackDecodingException(byte[] encoded) + { + var exception = Assert.Throws(() => _decoder.Decode(encoded, endHeaders: true, handler: this)); + Assert.Equal(CoreStrings.HPackHuffmanError, exception.Message); + Assert.IsType(exception.InnerException); + Assert.Empty(_decodedHeaders); + } + + private void TestDecodeWithIndexing(byte[] encoded, string expectedHeaderName, string expectedHeaderValue) + { + TestDecode(encoded, expectedHeaderName, expectedHeaderValue, expectDynamicTableEntry: true); + } + + private void TestDecodeWithoutIndexing(byte[] encoded, string expectedHeaderName, string expectedHeaderValue) + { + TestDecode(encoded, expectedHeaderName, expectedHeaderValue, expectDynamicTableEntry: false); + } + + private void TestDecode(byte[] encoded, string expectedHeaderName, string expectedHeaderValue, bool expectDynamicTableEntry) + { + Assert.Equal(0, _dynamicTable.Count); + Assert.Equal(0, _dynamicTable.Size); + + _decoder.Decode(encoded, endHeaders: true, handler: this); + + Assert.Equal(expectedHeaderValue, _decodedHeaders[expectedHeaderName]); + + if (expectDynamicTableEntry) + { + Assert.Equal(1, _dynamicTable.Count); + Assert.Equal(expectedHeaderName, Encoding.ASCII.GetString(_dynamicTable[0].Name)); + Assert.Equal(expectedHeaderValue, Encoding.ASCII.GetString(_dynamicTable[0].Value)); + Assert.Equal(expectedHeaderName.Length + expectedHeaderValue.Length + 32, _dynamicTable.Size); + } + else + { + Assert.Equal(0, _dynamicTable.Count); + Assert.Equal(0, _dynamicTable.Size); + } + } + } +} diff --git a/test/Kestrel.Core.Tests/Http2ConnectionTests.cs b/test/Kestrel.Core.Tests/Http2ConnectionTests.cs index 873233df34..3851a86dbd 100644 --- a/test/Kestrel.Core.Tests/Http2ConnectionTests.cs +++ b/test/Kestrel.Core.Tests/Http2ConnectionTests.cs @@ -4,7 +4,6 @@ using System; using System.Collections.Concurrent; using System.Collections.Generic; -using System.IO; using System.IO.Pipelines; using System.Linq; using System.Text; @@ -15,19 +14,18 @@ using Microsoft.AspNetCore.Server.Kestrel.Core.Features; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2.HPack; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; using Microsoft.AspNetCore.Testing; using Microsoft.Extensions.Primitives; using Xunit; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests { - public class Http2ConnectionTests : IDisposable + public class Http2ConnectionTests : IDisposable, IHttpHeadersHandler { - private static readonly string _largeHeaderA = new string('a', Http2Frame.MinAllowedMaxFrameSize - Http2Frame.HeaderLength - 8); + private static readonly string _largeHeaderValue = new string('a', HPackDecoder.MaxStringOctets); - private static readonly string _largeHeaderB = new string('b', Http2Frame.MinAllowedMaxFrameSize - Http2Frame.HeaderLength - 8); - - private static readonly IEnumerable> _postRequestHeaders = new [] + private static readonly IEnumerable> _postRequestHeaders = new[] { new KeyValuePair(":method", "POST"), new KeyValuePair(":path", "/"), @@ -35,7 +33,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests new KeyValuePair(":scheme", "https"), }; - private static readonly IEnumerable> _browserRequestHeaders = new [] + private static readonly IEnumerable> _browserRequestHeaders = new[] { new KeyValuePair(":method", "GET"), new KeyValuePair(":path", "/"), @@ -48,23 +46,32 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests new KeyValuePair("upgrade-insecure-requests", "1"), }; - private static readonly IEnumerable> _oneContinuationRequestHeaders = new [] + private static readonly IEnumerable> _oneContinuationRequestHeaders = new[] { new KeyValuePair(":method", "GET"), new KeyValuePair(":path", "/"), new KeyValuePair(":authority", "127.0.0.1"), new KeyValuePair(":scheme", "https"), - new KeyValuePair("a", _largeHeaderA) + new KeyValuePair("a", _largeHeaderValue), + new KeyValuePair("b", _largeHeaderValue), + new KeyValuePair("c", _largeHeaderValue), + new KeyValuePair("d", _largeHeaderValue) }; - private static readonly IEnumerable> _twoContinuationsRequestHeaders = new [] + private static readonly IEnumerable> _twoContinuationsRequestHeaders = new[] { new KeyValuePair(":method", "GET"), new KeyValuePair(":path", "/"), new KeyValuePair(":authority", "127.0.0.1"), new KeyValuePair(":scheme", "https"), - new KeyValuePair("a", _largeHeaderA), - new KeyValuePair("b", _largeHeaderB) + new KeyValuePair("a", _largeHeaderValue), + new KeyValuePair("b", _largeHeaderValue), + new KeyValuePair("c", _largeHeaderValue), + new KeyValuePair("d", _largeHeaderValue), + new KeyValuePair("e", _largeHeaderValue), + new KeyValuePair("f", _largeHeaderValue), + new KeyValuePair("g", _largeHeaderValue), + new KeyValuePair("h", _largeHeaderValue) }; private static readonly byte[] _helloBytes = Encoding.ASCII.GetBytes("hello"); @@ -77,12 +84,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests private readonly (IPipeConnection Transport, IPipeConnection Application) _pair; private readonly Http2ConnectionContext _connectionContext; private readonly Http2Connection _connection; - private readonly HPackEncoder _hpackEncoder = new HPackEncoder(); - private readonly HPackDecoder _hpackDecoder = new HPackDecoder(); private readonly Http2PeerSettings _clientSettings = new Http2PeerSettings(); + private readonly HPackEncoder _hpackEncoder = new HPackEncoder(); + private readonly HPackDecoder _hpackDecoder; private readonly ConcurrentDictionary> _runningStreams = new ConcurrentDictionary>(); private readonly Dictionary _receivedHeaders = new Dictionary(StringComparer.OrdinalIgnoreCase); + private readonly Dictionary _decodedHeaders = new Dictionary(StringComparer.OrdinalIgnoreCase); private readonly HashSet _abortedStreamIds = new HashSet(); private readonly object _abortedStreamIdsLock = new object(); @@ -160,8 +168,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests _largeHeadersApplication = context => { - context.Response.Headers["a"] = _largeHeaderA; - context.Response.Headers["b"] = _largeHeaderB; + foreach (var name in new[] { "a", "b", "c", "d", "e", "f", "g", "h" }) + { + context.Response.Headers[name] = _largeHeaderValue; + } return Task.CompletedTask; }; @@ -208,6 +218,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests _runningStreams[streamIdFeature.StreamId].TrySetResult(null); }; + _hpackDecoder = new HPackDecoder((int)_clientSettings.HeaderTableSize); + _connectionContext = new Http2ConnectionContext { ServiceContext = new TestServiceContext(), @@ -223,6 +235,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests _pipeFactory.Dispose(); } + void IHttpHeadersHandler.OnHeader(Span name, Span value) + { + _decodedHeaders[name.GetAsciiStringNonNullCharacters()] = value.GetAsciiStringNonNullCharacters(); + } + [Fact] public async Task DATA_Received_ReadByStream() { @@ -752,6 +769,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests await WaitForConnectionErrorAsync(expectedLastStreamId: 0, expectedErrorCode: Http2ErrorCode.PROTOCOL_ERROR, ignoreNonGoAwayFrames: false); } + [Fact] + public async Task HEADERS_Received_IncompleteHeaderBlockFragment_ConnectionError() + { + await InitializeConnectionAsync(_noopApplication); + + await SendIncompleteHeadersFrameAsync(streamId: 1); + + await WaitForConnectionErrorAsync(expectedLastStreamId: 0, expectedErrorCode: Http2ErrorCode.COMPRESSION_ERROR, ignoreNonGoAwayFrames: false); + } + [Fact] public async Task PRIORITY_Received_StreamIdZero_ConnectionError() { @@ -1192,6 +1219,17 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests await WaitForConnectionErrorAsync(expectedLastStreamId: 0, expectedErrorCode: Http2ErrorCode.PROTOCOL_ERROR, ignoreNonGoAwayFrames: false); } + [Fact] + public async Task CONTINUATION_Received_IncompleteHeaderBlockFragment_ConnectionError() + { + await InitializeConnectionAsync(_noopApplication); + + await SendHeadersAsync(1, Http2HeadersFrameFlags.NONE, _postRequestHeaders); + await SendIncompleteContinuationFrameAsync(streamId: 1); + + await WaitForConnectionErrorAsync(expectedLastStreamId: 0, expectedErrorCode: Http2ErrorCode.COMPRESSION_ERROR, ignoreNonGoAwayFrames: false); + } + [Fact] public async Task CONTINUATION_Sent_WhenHeadersLargerThanFrameLength() { @@ -1200,15 +1238,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests await StartStreamAsync(1, _browserRequestHeaders, endStream: true); var headersFrame = await ExpectAsync(Http2FrameType.HEADERS, - withLength: 55, + withLength: 12361, withFlags: (byte)Http2HeadersFrameFlags.NONE, withStreamId: 1); var continuationFrame1 = await ExpectAsync(Http2FrameType.CONTINUATION, - withLength: 16373, + withLength: 12306, withFlags: (byte)Http2ContinuationFrameFlags.NONE, withStreamId: 1); var continuationFrame2 = await ExpectAsync(Http2FrameType.CONTINUATION, - withLength: 16373, + withLength: 8204, withFlags: (byte)Http2ContinuationFrameFlags.END_HEADERS, withStreamId: 1); await ExpectAsync(Http2FrameType.DATA, @@ -1218,18 +1256,22 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests await StopConnectionAsync(expectedLastStreamId: 1, ignoreNonGoAwayFrames: false); - var responseHeaders = new HttpResponseHeaders(); - _hpackDecoder.Decode(headersFrame.HeadersPayload, responseHeaders); - _hpackDecoder.Decode(continuationFrame1.HeadersPayload, responseHeaders); - _hpackDecoder.Decode(continuationFrame2.HeadersPayload, responseHeaders); + _hpackDecoder.Decode(headersFrame.HeadersPayload, endHeaders: false, handler: this); + _hpackDecoder.Decode(continuationFrame1.HeadersPayload, endHeaders: false, handler: this); + _hpackDecoder.Decode(continuationFrame2.HeadersPayload, endHeaders: true, handler: this); - var responseHeadersDictionary = (IDictionary)responseHeaders; - Assert.Equal(5, responseHeadersDictionary.Count); - Assert.Contains("date", responseHeadersDictionary.Keys, StringComparer.OrdinalIgnoreCase); - Assert.Equal("200", responseHeadersDictionary[":status"]); - Assert.Equal("0", responseHeadersDictionary["content-length"]); - Assert.Equal(_largeHeaderA, responseHeadersDictionary["a"]); - Assert.Equal(_largeHeaderB, responseHeadersDictionary["b"]); + Assert.Equal(11, _decodedHeaders.Count); + Assert.Contains("date", _decodedHeaders.Keys, StringComparer.OrdinalIgnoreCase); + Assert.Equal("200", _decodedHeaders[":status"]); + Assert.Equal("0", _decodedHeaders["content-length"]); + Assert.Equal(_largeHeaderValue, _decodedHeaders["a"]); + Assert.Equal(_largeHeaderValue, _decodedHeaders["b"]); + Assert.Equal(_largeHeaderValue, _decodedHeaders["c"]); + Assert.Equal(_largeHeaderValue, _decodedHeaders["d"]); + Assert.Equal(_largeHeaderValue, _decodedHeaders["e"]); + Assert.Equal(_largeHeaderValue, _decodedHeaders["f"]); + Assert.Equal(_largeHeaderValue, _decodedHeaders["g"]); + Assert.Equal(_largeHeaderValue, _decodedHeaders["h"]); } [Fact] @@ -1525,12 +1567,28 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests return SendAsync(frame.Raw); } + private Task SendIncompleteHeadersFrameAsync(int streamId) + { + var frame = new Http2Frame(); + + frame.PrepareHeaders(Http2HeadersFrameFlags.END_HEADERS, streamId); + frame.Length = 3; + + // Set up an incomplete Literal Header Field w/ Incremental Indexing frame, + // with an incomplete new name + frame.Payload[0] = 0; + frame.Payload[1] = 2; + frame.Payload[2] = (byte)'a'; + + return SendAsync(frame.Raw); + } + private async Task SendContinuationAsync(int streamId, Http2ContinuationFrameFlags flags) { var frame = new Http2Frame(); frame.PrepareContinuation(flags, streamId); - var done =_hpackEncoder.Encode(frame.Payload, out var length); + var done = _hpackEncoder.Encode(frame.Payload, out var length); frame.Length = length; await SendAsync(frame.Raw); @@ -1538,6 +1596,22 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests return done; } + private Task SendIncompleteContinuationFrameAsync(int streamId) + { + var frame = new Http2Frame(); + + frame.PrepareContinuation(Http2ContinuationFrameFlags.END_HEADERS, streamId); + frame.Length = 3; + + // Set up an incomplete Literal Header Field w/ Incremental Indexing frame, + // with an incomplete new name + frame.Payload[0] = 0; + frame.Payload[1] = 2; + frame.Payload[2] = (byte)'a'; + + return SendAsync(frame.Raw); + } + private Task SendDataAsync(int streamId, Span data, bool endStream) { var frame = new Http2Frame(); diff --git a/test/Kestrel.Core.Tests/HuffmanTests.cs b/test/Kestrel.Core.Tests/HuffmanTests.cs index f075bbc7ba..cbe87cd4d9 100644 --- a/test/Kestrel.Core.Tests/HuffmanTests.cs +++ b/test/Kestrel.Core.Tests/HuffmanTests.cs @@ -1,7 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System; +using System.Text; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2.HPack; using Xunit; @@ -9,28 +9,143 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests { public class HuffmanTests { - [Fact] - public void HuffmanDecodeString() + public static readonly TheoryData _validData = new TheoryData { - // h e.......e l........l l o.......o - var encodedHello = new byte[] { 0b100111_00, 0b101_10100, 0b0_101000_0, 0b0111_1111 }; + // Single 5-bit symbol + { new byte[] { 0x07 }, Encoding.ASCII.GetBytes("0") }, + // Single 6-bit symbol + { new byte[] { 0x57 }, Encoding.ASCII.GetBytes("%") }, + // Single 7-bit symbol + { new byte[] { 0xb9 }, Encoding.ASCII.GetBytes(":") }, + // Single 8-bit symbol + { new byte[] { 0xf8 }, Encoding.ASCII.GetBytes("&") }, + // Single 10-bit symbol + { new byte[] { 0xfe, 0x3f }, Encoding.ASCII.GetBytes("!") }, + // Single 11-bit symbol + { new byte[] { 0xff, 0x7f }, Encoding.ASCII.GetBytes("+") }, + // Single 12-bit symbol + { new byte[] { 0xff, 0xaf }, Encoding.ASCII.GetBytes("#") }, + // Single 13-bit symbol + { new byte[] { 0xff, 0xcf }, Encoding.ASCII.GetBytes("$") }, + // Single 14-bit symbol + { new byte[] { 0xff, 0xf3 }, Encoding.ASCII.GetBytes("^") }, + // Single 15-bit symbol + { new byte[] { 0xff, 0xf9 }, Encoding.ASCII.GetBytes("<") }, + // Single 19-bit symbol + { new byte[] { 0xff, 0xfe, 0x1f }, Encoding.ASCII.GetBytes("\\") }, + // Single 20-bit symbol + { new byte[] { 0xff, 0xfe, 0x6f }, new byte[] { 0x80 } }, + // Single 21-bit symbol + { new byte[] { 0xff, 0xfe, 0xe7 }, new byte[] { 0x99 } }, + // Single 22-bit symbol + { new byte[] { 0xff, 0xff, 0x4b }, new byte[] { 0x81 } }, + // Single 23-bit symbol + { new byte[] { 0xff, 0xff, 0xb1 }, new byte[] { 0x01 } }, + // Single 24-bit symbol + { new byte[] { 0xff, 0xff, 0xea }, new byte[] { 0x09 } }, + // Single 25-bit symbol + { new byte[] { 0xff, 0xff, 0xf6, 0x7f }, new byte[] { 0xc7 } }, + // Single 26-bit symbol + { new byte[] { 0xff, 0xff, 0xf8, 0x3f }, new byte[] { 0xc0 } }, + // Single 27-bit symbol + { new byte[] { 0xff, 0xff, 0xfb, 0xdf }, new byte[] { 0xcb } }, + // Single 28-bit symbol + { new byte[] { 0xff, 0xff, 0xfe, 0x2f }, new byte[] { 0x02 } }, + // Single 30-bit symbol + { new byte[] { 0xff, 0xff, 0xff, 0xf3 }, new byte[] { 0x0a } }, - Assert.Equal("hello", Huffman.Decode(encodedHello, 0, encodedHello.Length)); + // h e l l o * + { new byte[] { 0b100111_00, 0b101_10100, 0b0_101000_0, 0b0111_1111 }, Encoding.ASCII.GetBytes("hello") }, - var encodedHeader = new byte[] - { - 0xb6, 0xb9, 0xac, 0x1c, 0x85, 0x58, 0xd5, 0x20, 0xa4, 0xb6, 0xc2, 0xad, 0x61, 0x7b, 0x5a, 0x54, 0x25, 0x1f - }; + // Sequences that uncovered errors + { new byte[] { 0xb6, 0xb9, 0xac, 0x1c, 0x85, 0x58, 0xd5, 0x20, 0xa4, 0xb6, 0xc2, 0xad, 0x61, 0x7b, 0x5a, 0x54, 0x25, 0x1f }, Encoding.ASCII.GetBytes("upgrade-insecure-requests") }, + { new byte[] { 0xfe, 0x53 }, Encoding.ASCII.GetBytes("\"t") } + }; - Assert.Equal("upgrade-insecure-requests", Huffman.Decode(encodedHeader, 0, encodedHeader.Length)); + [Theory] + [MemberData(nameof(_validData))] + public void HuffmanDecodeArray(byte[] encoded, byte[] expected) + { + var dst = new byte[expected.Length]; + Assert.Equal(expected.Length, Huffman.Decode(encoded, 0, encoded.Length, dst)); + Assert.Equal(expected, dst); + } - encodedHeader = new byte[] - { - // "t - 0xfe, 0x53 - }; + public static readonly TheoryData _longPaddingData = new TheoryData + { + // h e l l o * + new byte[] { 0b100111_00, 0b101_10100, 0b0_101000_0, 0b0111_1111, 0b11111111 }, - Assert.Equal("\"t", Huffman.Decode(encodedHeader, 0, encodedHeader.Length)); + // '&' (8 bits) + 8 bit padding + new byte[] { 0xf8, 0xff }, + + // ':' (7 bits) + 9 bit padding + new byte[] { 0xb9, 0xff } + }; + + [Theory] + [MemberData(nameof(_longPaddingData))] + public void ThrowsOnPaddingLongerThanSevenBits(byte[] encoded) + { + var exception = Assert.Throws(() => Huffman.Decode(encoded, 0, encoded.Length, new byte[encoded.Length * 2])); + Assert.Equal(CoreStrings.HPackHuffmanErrorIncomplete, exception.Message); + } + + public static readonly TheoryData _eosData = new TheoryData + { + // EOS + new byte[] { 0xff, 0xff, 0xff, 0xff }, + // '&' + EOS + '0' + new byte[] { 0xf8, 0xff, 0xff, 0xff, 0xfc, 0x1f } + }; + + [Theory] + [MemberData(nameof(_eosData))] + public void ThrowsOnEOS(byte[] encoded) + { + var exception = Assert.Throws(() => Huffman.Decode(encoded, 0, encoded.Length, new byte[encoded.Length * 2])); + Assert.Equal(CoreStrings.HPackHuffmanErrorEOS, exception.Message); + } + + [Fact] + public void ThrowsOnDestinationBufferTooSmall() + { + // h e l l o * + var encoded = new byte[] { 0b100111_00, 0b101_10100, 0b0_101000_0, 0b0111_1111 }; + var exception = Assert.Throws(() => Huffman.Decode(encoded, 0, encoded.Length, new byte[encoded.Length])); + Assert.Equal(CoreStrings.HPackHuffmanErrorDestinationTooSmall, exception.Message); + } + + public static readonly TheoryData _incompleteSymbolData = new TheoryData + { + // h e l l o (incomplete) + new byte[] { 0b100111_00, 0b101_10100, 0b0_101000_0 }, + + // Non-zero padding will be seen as incomplete symbol + // h e l l o * + new byte[] { 0b100111_00, 0b101_10100, 0b0_101000_0, 0b0111_0000 }, + new byte[] { 0b100111_00, 0b101_10100, 0b0_101000_0, 0b0111_0001 }, + new byte[] { 0b100111_00, 0b101_10100, 0b0_101000_0, 0b0111_0010 }, + new byte[] { 0b100111_00, 0b101_10100, 0b0_101000_0, 0b0111_0011 }, + new byte[] { 0b100111_00, 0b101_10100, 0b0_101000_0, 0b0111_0100 }, + new byte[] { 0b100111_00, 0b101_10100, 0b0_101000_0, 0b0111_0101 }, + new byte[] { 0b100111_00, 0b101_10100, 0b0_101000_0, 0b0111_0110 }, + new byte[] { 0b100111_00, 0b101_10100, 0b0_101000_0, 0b0111_0111 }, + new byte[] { 0b100111_00, 0b101_10100, 0b0_101000_0, 0b0111_1000 }, + new byte[] { 0b100111_00, 0b101_10100, 0b0_101000_0, 0b0111_1001 }, + new byte[] { 0b100111_00, 0b101_10100, 0b0_101000_0, 0b0111_1010 }, + new byte[] { 0b100111_00, 0b101_10100, 0b0_101000_0, 0b0111_1011 }, + new byte[] { 0b100111_00, 0b101_10100, 0b0_101000_0, 0b0111_1100 }, + new byte[] { 0b100111_00, 0b101_10100, 0b0_101000_0, 0b0111_1101 }, + new byte[] { 0b100111_00, 0b101_10100, 0b0_101000_0, 0b0111_1110 } + }; + + [Theory] + [MemberData(nameof(_incompleteSymbolData))] + public void ThrowsOnIncompleteSymbol(byte[] encoded) + { + var exception = Assert.Throws(() => Huffman.Decode(encoded, 0, encoded.Length, new byte[encoded.Length * 2])); + Assert.Equal(CoreStrings.HPackHuffmanErrorIncomplete, exception.Message); } [Theory] @@ -46,7 +161,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests [MemberData(nameof(HuffmanData))] public void HuffmanDecode(int code, uint encoded, int bitLength) { - Assert.Equal(code, Huffman.Decode(encoded, out var decodedBits)); + Assert.Equal(code, Huffman.Decode(encoded, bitLength, out var decodedBits)); Assert.Equal(bitLength, decodedBits); } @@ -61,7 +176,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests #pragma warning restore xUnit1026 int bitLength) { - Assert.Equal(code, Huffman.Decode(Huffman.Encode(code).encoded, out var decodedBits)); + Assert.Equal(code, Huffman.Decode(Huffman.Encode(code).encoded, bitLength, out var decodedBits)); Assert.Equal(bitLength, decodedBits); } From e2c22b91af937c7e43dab5ab6e1dfd8c864b0b94 Mon Sep 17 00:00:00 2001 From: Nate McMaster Date: Fri, 6 Oct 2017 08:50:58 -0700 Subject: [PATCH 1423/1662] Minor test code changes to resolve xUnit2013 build warning --- test/Kestrel.Core.Tests/HttpRequestHeadersTests.cs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/test/Kestrel.Core.Tests/HttpRequestHeadersTests.cs b/test/Kestrel.Core.Tests/HttpRequestHeadersTests.cs index 7104ef8db5..5f1113e9c2 100644 --- a/test/Kestrel.Core.Tests/HttpRequestHeadersTests.cs +++ b/test/Kestrel.Core.Tests/HttpRequestHeadersTests.cs @@ -30,8 +30,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests headers["custom"] = new[] { "value" }; - Assert.Equal(1, headers["custom"].Count); - Assert.Equal("value", headers["custom"][0]); + var header = Assert.Single(headers["custom"]); + Assert.Equal("value", header); } [Fact] @@ -42,10 +42,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests headers["host"] = new[] { "value" }; headers["content-length"] = new[] { "0" }; - Assert.Equal(1, headers["host"].Count); - Assert.Equal(1, headers["content-length"].Count); - Assert.Equal("value", headers["host"][0]); - Assert.Equal("0", headers["content-length"][0]); + var host = Assert.Single(headers["host"]); + var contentLength = Assert.Single(headers["content-length"]); + Assert.Equal("value", host); + Assert.Equal("0", contentLength); } [Fact] From 2ce47196906a39b2821c998c109ce1aec235a806 Mon Sep 17 00:00:00 2001 From: Vladimir Sadov Date: Fri, 6 Oct 2017 11:08:56 -0600 Subject: [PATCH 1424/1662] new toolset compiler - 2.6.0-beta1-62126-01 (#2090) This was a "special" build, so there is no public VSIX for this. The old one should be ok, for most scenarios. When VS 15.5 preview1 is available it will match this compiler feature-wise by default. --- Directory.Build.props | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Directory.Build.props b/Directory.Build.props index 90fa1afb22..ea64574519 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -14,7 +14,7 @@ - + '* ]] && comment=false ; continue; fi - if [[ $ENTITY == '!--'* ]]; then comment=true; continue; fi - if [ -z "$channel" ] && [[ $ENTITY == "KoreBuildChannel" ]]; then channel=$CONTENT; fi - if [ -z "$tools_source" ] && [[ $ENTITY == "KoreBuildToolsSource" ]]; then tools_source=$CONTENT; fi - done < "$config_file" -fi - -[ -z "$channel" ] && channel='dev' -[ -z "$tools_source" ] && tools_source='https://aspnetcore.blob.core.windows.net/buildtools' - -get_korebuild -install_tools "$tools_source" "$DOTNET_HOME" -invoke_repository_build "$repo_path" "$@" +# Call "sync" between "chmod" and execution to prevent "text file busy" error in Docker (aufs) +chmod +x "$DIR/run.sh"; sync +"$DIR/run.sh" default-build "$@" diff --git a/run.cmd b/run.cmd new file mode 100644 index 0000000000..d52d5c7e68 --- /dev/null +++ b/run.cmd @@ -0,0 +1,2 @@ +@ECHO OFF +PowerShell -NoProfile -NoLogo -ExecutionPolicy unrestricted -Command "[System.Threading.Thread]::CurrentThread.CurrentCulture = ''; [System.Threading.Thread]::CurrentThread.CurrentUICulture = '';& '%~dp0run.ps1' %*; exit $LASTEXITCODE" diff --git a/build.ps1 b/run.ps1 similarity index 73% rename from build.ps1 rename to run.ps1 index d5eb4d5cf2..49c2899856 100644 --- a/build.ps1 +++ b/run.ps1 @@ -3,10 +3,13 @@ <# .SYNOPSIS -Build this repository +Executes KoreBuild commands. .DESCRIPTION -Downloads korebuild if required. Then builds the repository. +Downloads korebuild if required. Then executes the KoreBuild command. To see available commands, execute with `-Command help`. + +.PARAMETER Command +The KoreBuild command to run. .PARAMETER Path The folder to build. Defaults to the folder containing this script. @@ -24,31 +27,32 @@ The base url where build tools can be downloaded. Overrides the value from the c Updates KoreBuild to the latest version even if a lock file is present. .PARAMETER ConfigFile -The path to the configuration file that stores values. Defaults to version.xml. +The path to the configuration file that stores values. Defaults to korebuild.json. -.PARAMETER MSBuildArgs -Arguments to be passed to MSBuild +.PARAMETER Arguments +Arguments to be passed to the command .NOTES This function will create a file $PSScriptRoot/korebuild-lock.txt. This lock file can be committed to source, but does not have to be. When the lockfile is not present, KoreBuild will create one using latest available version from $Channel. -The $ConfigFile is expected to be an XML file. It is optional, and the configuration values in it are optional as well. +The $ConfigFile is expected to be an JSON file. It is optional, and the configuration values in it are optional as well. Any options set +in the file are overridden by command line parameters. .EXAMPLE Example config file: -```xml - - - - dev - https://aspnetcore.blob.core.windows.net/buildtools - - +```json +{ + "$schema": "https://raw.githubusercontent.com/aspnet/BuildTools/dev/tools/korebuild.schema.json", + "channel": "dev", + "toolsSource": "https://aspnetcore.blob.core.windows.net/buildtools" +} ``` #> [CmdletBinding(PositionalBinding = $false)] param( + [Parameter(Mandatory=$true, Position = 0)] + [string]$Command, [string]$Path = $PSScriptRoot, [Alias('c')] [string]$Channel, @@ -58,9 +62,9 @@ param( [string]$ToolsSource, [Alias('u')] [switch]$Update, - [string]$ConfigFile = (Join-Path $PSScriptRoot 'version.xml'), + [string]$ConfigFile, [Parameter(ValueFromRemainingArguments = $true)] - [string[]]$MSBuildArgs + [string[]]$Arguments ) Set-StrictMode -Version 2 @@ -147,10 +151,20 @@ function Get-RemoteFile([string]$RemotePath, [string]$LocalPath) { # Load configuration or set defaults +$Path = Resolve-Path $Path +if (!$ConfigFile) { $ConfigFile = Join-Path $Path 'korebuild.json' } + if (Test-Path $ConfigFile) { - [xml] $config = Get-Content $ConfigFile - if (!($Channel)) { [string] $Channel = Select-Xml -Xml $config -XPath '/Project/PropertyGroup/KoreBuildChannel' } - if (!($ToolsSource)) { [string] $ToolsSource = Select-Xml -Xml $config -XPath '/Project/PropertyGroup/KoreBuildToolsSource' } + try { + $config = Get-Content -Raw -Encoding UTF8 -Path $ConfigFile | ConvertFrom-Json + if ($config) { + if (!($Channel) -and (Get-Member -Name 'channel' -InputObject $config)) { [string] $Channel = $config.channel } + if (!($ToolsSource) -and (Get-Member -Name 'toolsSource' -InputObject $config)) { [string] $ToolsSource = $config.toolsSource} + } + } catch { + Write-Warning "$ConfigFile could not be read. Its settings will be ignored." + Write-Warning $Error[0] + } } if (!$DotNetHome) { @@ -169,8 +183,8 @@ $korebuildPath = Get-KoreBuild Import-Module -Force -Scope Local (Join-Path $korebuildPath 'KoreBuild.psd1') try { - Install-Tools $ToolsSource $DotNetHome - Invoke-RepositoryBuild $Path @MSBuildArgs + Set-KoreBuildSettings -ToolsSource $ToolsSource -DotNetHome $DotNetHome -RepoPath $Path -ConfigFile $ConfigFile + Invoke-KoreBuildCommand $Command @Arguments } finally { Remove-Module 'KoreBuild' -ErrorAction Ignore diff --git a/run.sh b/run.sh new file mode 100755 index 0000000000..c278423acc --- /dev/null +++ b/run.sh @@ -0,0 +1,223 @@ +#!/usr/bin/env bash + +set -euo pipefail + +# +# variables +# + +RESET="\033[0m" +RED="\033[0;31m" +YELLOW="\033[0;33m" +MAGENTA="\033[0;95m" +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +[ -z "${DOTNET_HOME:-}" ] && DOTNET_HOME="$HOME/.dotnet" +verbose=false +update=false +repo_path="$DIR" +channel='' +tools_source='' + +# +# Functions +# +__usage() { + echo "Usage: $(basename "${BASH_SOURCE[0]}") command [options] [[--] ...]" + echo "" + echo "Arguments:" + echo " command The command to be run." + echo " ... Arguments passed to the command. Variable number of arguments allowed." + echo "" + echo "Options:" + echo " --verbose Show verbose output." + echo " -c|--channel The channel of KoreBuild to download. Overrides the value from the config file.." + echo " --config-file The path to the configuration file that stores values. Defaults to korebuild.json." + echo " -d|--dotnet-home The directory where .NET Core tools will be stored. Defaults to '\$DOTNET_HOME' or '\$HOME/.dotnet." + echo " --path The directory to build. Defaults to the directory containing the script." + echo " -s|--tools-source|-ToolsSource The base url where build tools can be downloaded. Overrides the value from the config file." + echo " -u|--update Update to the latest KoreBuild even if the lock file is present." + echo "" + echo "Description:" + echo " This function will create a file \$DIR/korebuild-lock.txt. This lock file can be committed to source, but does not have to be." + echo " When the lockfile is not present, KoreBuild will create one using latest available version from \$channel." + + if [[ "${1:-}" != '--no-exit' ]]; then + exit 2 + fi +} + +get_korebuild() { + local version + local lock_file="$repo_path/korebuild-lock.txt" + if [ ! -f "$lock_file" ] || [ "$update" = true ]; then + __get_remote_file "$tools_source/korebuild/channels/$channel/latest.txt" "$lock_file" + fi + version="$(grep 'version:*' -m 1 "$lock_file")" + if [[ "$version" == '' ]]; then + __error "Failed to parse version from $lock_file. Expected a line that begins with 'version:'" + return 1 + fi + version="$(echo "${version#version:}" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')" + local korebuild_path="$DOTNET_HOME/buildtools/korebuild/$version" + + { + if [ ! -d "$korebuild_path" ]; then + mkdir -p "$korebuild_path" + local remote_path="$tools_source/korebuild/artifacts/$version/korebuild.$version.zip" + tmpfile="$(mktemp)" + echo -e "${MAGENTA}Downloading KoreBuild ${version}${RESET}" + if __get_remote_file "$remote_path" "$tmpfile"; then + unzip -q -d "$korebuild_path" "$tmpfile" + fi + rm "$tmpfile" || true + fi + + source "$korebuild_path/KoreBuild.sh" + } || { + if [ -d "$korebuild_path" ]; then + echo "Cleaning up after failed installation" + rm -rf "$korebuild_path" || true + fi + return 1 + } +} + +__error() { + echo -e "${RED}error: $*${RESET}" 1>&2 +} + +__warn() { + echo -e "${YELLOW}warning: $*${RESET}" +} + +__machine_has() { + hash "$1" > /dev/null 2>&1 + return $? +} + +__get_remote_file() { + local remote_path=$1 + local local_path=$2 + + if [[ "$remote_path" != 'http'* ]]; then + cp "$remote_path" "$local_path" + return 0 + fi + + local failed=false + if __machine_has wget; then + wget --tries 10 --quiet -O "$local_path" "$remote_path" || failed=true + else + failed=true + fi + + if [ "$failed" = true ] && __machine_has curl; then + failed=false + curl --retry 10 -sSL -f --create-dirs -o "$local_path" "$remote_path" || failed=true + fi + + if [ "$failed" = true ]; then + __error "Download failed: $remote_path" 1>&2 + return 1 + fi +} + +# +# main +# + +command="${1:-}" +shift + +while [[ $# -gt 0 ]]; do + case $1 in + -\?|-h|--help) + __usage --no-exit + exit 0 + ;; + -c|--channel|-Channel) + shift + channel="${1:-}" + [ -z "$channel" ] && __usage + ;; + --config-file|-ConfigFile) + shift + config_file="${1:-}" + [ -z "$config_file" ] && __usage + if [ ! -f "$config_file" ]; then + __error "Invalid value for --config-file. $config_file does not exist." + exit 1 + fi + ;; + -d|--dotnet-home|-DotNetHome) + shift + DOTNET_HOME="${1:-}" + [ -z "$DOTNET_HOME" ] && __usage + ;; + --path|-Path) + shift + repo_path="${1:-}" + [ -z "$repo_path" ] && __usage + ;; + -s|--tools-source|-ToolsSource) + shift + tools_source="${1:-}" + [ -z "$tools_source" ] && __usage + ;; + -u|--update|-Update) + update=true + ;; + --verbose|-Verbose) + verbose=true + ;; + --) + shift + break + ;; + *) + break + ;; + esac + shift +done + +if ! __machine_has unzip; then + __error 'Missing required command: unzip' + exit 1 +fi + +if ! __machine_has curl && ! __machine_has wget; then + __error 'Missing required command. Either wget or curl is required.' + exit 1 +fi + +[ -z "${config_file:-}" ] && config_file="$repo_path/korebuild.json" +if [ -f "$config_file" ]; then + if __machine_has jq ; then + if jq '.' "$config_file" >/dev/null ; then + config_channel="$(jq -r 'select(.channel!=null) | .channel' "$config_file")" + config_tools_source="$(jq -r 'select(.toolsSource!=null) | .toolsSource' "$config_file")" + else + __warn "$config_file is invalid JSON. Its settings will be ignored." + fi + elif __machine_has python ; then + if python -c "import json,codecs;obj=json.load(codecs.open('$config_file', 'r', 'utf-8-sig'))" >/dev/null ; then + config_channel="$(python -c "import json,codecs;obj=json.load(codecs.open('$config_file', 'r', 'utf-8-sig'));print(obj['channel'] if 'channel' in obj else '')")" + config_tools_source="$(python -c "import json,codecs;obj=json.load(codecs.open('$config_file', 'r', 'utf-8-sig'));print(obj['toolsSource'] if 'toolsSource' in obj else '')")" + else + __warn "$config_file is invalid JSON. Its settings will be ignored." + fi + else + __warn 'Missing required command: jq or pyton. Could not parse the JSON file. Its settings will be ignored.' + fi + + [ ! -z "${config_channel:-}" ] && channel="$config_channel" + [ ! -z "${config_tools_source:-}" ] && tools_source="$config_tools_source" +fi + +[ -z "$channel" ] && channel='dev' +[ -z "$tools_source" ] && tools_source='https://aspnetcore.blob.core.windows.net/buildtools' + +get_korebuild +set_korebuildsettings "$tools_source" "$DOTNET_HOME" "$repo_path" "$config_file" +invoke_korebuild_command "$command" "$@" From d46d2ce193730233f825e7afce21acdc6209ba8c Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Tue, 10 Oct 2017 13:12:34 -0700 Subject: [PATCH 1426/1662] HTTP/2: validate request headers prior to starting new stream. --- .../Internal/Http2/Http2Connection.cs | 219 ++++++++++- .../Http2/Http2StreamErrorException.cs | 21 ++ .../Http2ConnectionTests.cs | 341 +++++++++++++++++- 3 files changed, 551 insertions(+), 30 deletions(-) create mode 100644 src/Kestrel.Core/Internal/Http2/Http2StreamErrorException.cs diff --git a/src/Kestrel.Core/Internal/Http2/Http2Connection.cs b/src/Kestrel.Core/Internal/Http2/Http2Connection.cs index b4e54e7b01..50e023196d 100644 --- a/src/Kestrel.Core/Internal/Http2/Http2Connection.cs +++ b/src/Kestrel.Core/Internal/Http2/Http2Connection.cs @@ -18,8 +18,41 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 { public class Http2Connection : ITimeoutControl, IHttp2StreamLifetimeHandler, IHttpHeadersHandler { + private enum RequestHeaderParsingState + { + Ready, + PseudoHeaderFields, + Headers, + Trailers + } + + [Flags] + private enum PseudoHeaderFields + { + None = 0x0, + Authority = 0x1, + Method = 0x2, + Path = 0x4, + Scheme = 0x8, + Status = 0x10, + Unknown = 0x40000000 + } + public static byte[] ClientPreface { get; } = Encoding.ASCII.GetBytes("PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n"); + private static readonly PseudoHeaderFields _mandatoryRequestPseudoHeaderFields = + PseudoHeaderFields.Method | PseudoHeaderFields.Path | PseudoHeaderFields.Scheme; + + private static readonly byte[] _authorityBytes = Encoding.ASCII.GetBytes("authority"); + private static readonly byte[] _methodBytes = Encoding.ASCII.GetBytes("method"); + private static readonly byte[] _pathBytes = Encoding.ASCII.GetBytes("path"); + private static readonly byte[] _schemeBytes = Encoding.ASCII.GetBytes("scheme"); + private static readonly byte[] _statusBytes = Encoding.ASCII.GetBytes("status"); + private static readonly byte[] _connectionBytes = Encoding.ASCII.GetBytes("connection"); + private static readonly byte[] _teBytes = Encoding.ASCII.GetBytes("te"); + private static readonly byte[] _trailersBytes = Encoding.ASCII.GetBytes("trailers"); + private static readonly byte[] _connectBytes = Encoding.ASCII.GetBytes("CONNECT"); + private readonly Http2ConnectionContext _context; private readonly Http2FrameWriter _frameWriter; private readonly HPackDecoder _hpackDecoder; @@ -30,6 +63,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 private readonly Http2Frame _incomingFrame = new Http2Frame(); private Http2Stream _currentHeadersStream; + private RequestHeaderParsingState _requestHeaderParsingState; + private PseudoHeaderFields _parsedPseudoHeaderFields; + private bool _isMethodConnect; private int _highestOpenedStreamId; private bool _stopping; @@ -318,6 +354,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 { throw new Http2ConnectionErrorException(Http2ErrorCode.STREAM_CLOSED); } + // TODO: trailers } else if (_incomingFrame.StreamId <= _highestOpenedStreamId) @@ -354,17 +391,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 _currentHeadersStream.Reset(); - _streams[_incomingFrame.StreamId] = _currentHeadersStream; - var endHeaders = (_incomingFrame.HeadersFlags & Http2HeadersFrameFlags.END_HEADERS) == Http2HeadersFrameFlags.END_HEADERS; - _hpackDecoder.Decode(_incomingFrame.HeadersPayload, endHeaders, handler: this); - - if (endHeaders) - { - _highestOpenedStreamId = _incomingFrame.StreamId; - _ = _currentHeadersStream.ProcessRequestsAsync(); - _currentHeadersStream = null; - } + await DecodeHeadersAsync(endHeaders, _incomingFrame.HeadersPayload); } } @@ -533,16 +561,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 } var endHeaders = (_incomingFrame.ContinuationFlags & Http2ContinuationFrameFlags.END_HEADERS) == Http2ContinuationFrameFlags.END_HEADERS; - _hpackDecoder.Decode(_incomingFrame.HeadersPayload, endHeaders, handler: this); - if (endHeaders) - { - _highestOpenedStreamId = _currentHeadersStream.StreamId; - _ = _currentHeadersStream.ProcessRequestsAsync(); - _currentHeadersStream = null; - } - - return Task.CompletedTask; + return DecodeHeadersAsync(endHeaders, _incomingFrame.Payload); } private Task ProcessUnknownFrameAsync() @@ -555,6 +575,54 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 return Task.CompletedTask; } + private Task DecodeHeadersAsync(bool endHeaders, Span payload) + { + try + { + _hpackDecoder.Decode(payload, endHeaders, handler: this); + + if (endHeaders) + { + StartStream(); + ResetRequestHeaderParsingState(); + } + } + catch (Http2StreamErrorException ex) + { + ResetRequestHeaderParsingState(); + return _frameWriter.WriteRstStreamAsync(ex.StreamId, ex.ErrorCode); + } + + return Task.CompletedTask; + } + + private void StartStream() + { + if (!_isMethodConnect && (_parsedPseudoHeaderFields & _mandatoryRequestPseudoHeaderFields) != _mandatoryRequestPseudoHeaderFields) + { + // All HTTP/2 requests MUST include exactly one valid value for the :method, :scheme, and :path pseudo-header + // fields, unless it is a CONNECT request (Section 8.3). An HTTP request that omits mandatory pseudo-header + // fields is malformed (Section 8.1.2.6). + throw new Http2StreamErrorException(_currentHeadersStream.StreamId, Http2ErrorCode.PROTOCOL_ERROR); + } + + _streams[_incomingFrame.StreamId] = _currentHeadersStream; + _ = _currentHeadersStream.ProcessRequestsAsync(); + } + + private void ResetRequestHeaderParsingState() + { + if (_requestHeaderParsingState != RequestHeaderParsingState.Trailers) + { + _highestOpenedStreamId = _currentHeadersStream.StreamId; + } + + _currentHeadersStream = null; + _requestHeaderParsingState = RequestHeaderParsingState.Ready; + _parsedPseudoHeaderFields = PseudoHeaderFields.None; + _isMethodConnect = false; + } + private void ThrowIfIncomingFrameSentToIdleStream() { // http://httpwg.org/specs/rfc7540.html#rfc.section.5.1 @@ -581,9 +649,122 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 public void OnHeader(Span name, Span value) { + ValidateHeader(name, value); _currentHeadersStream.OnHeader(name, value); } + private void ValidateHeader(Span name, Span value) + { + // http://httpwg.org/specs/rfc7540.html#rfc.section.8.1.2.1 + if (IsPseudoHeaderField(name, out var headerField)) + { + if (_requestHeaderParsingState == RequestHeaderParsingState.Headers || + _requestHeaderParsingState == RequestHeaderParsingState.Trailers) + { + // Pseudo-header fields MUST NOT appear in trailers. + // ... + // All pseudo-header fields MUST appear in the header block before regular header fields. + // Any request or response that contains a pseudo-header field that appears in a header + // block after a regular header field MUST be treated as malformed (Section 8.1.2.6). + throw new Http2StreamErrorException(_currentHeadersStream.StreamId, Http2ErrorCode.PROTOCOL_ERROR); + } + + _requestHeaderParsingState = RequestHeaderParsingState.PseudoHeaderFields; + + if (headerField == PseudoHeaderFields.Unknown) + { + // Endpoints MUST treat a request or response that contains undefined or invalid pseudo-header + // fields as malformed (Section 8.1.2.6). + throw new Http2StreamErrorException(_currentHeadersStream.StreamId, Http2ErrorCode.PROTOCOL_ERROR); + } + + if (headerField == PseudoHeaderFields.Status) + { + // Pseudo-header fields defined for requests MUST NOT appear in responses; pseudo-header fields + // defined for responses MUST NOT appear in requests. + throw new Http2StreamErrorException(_currentHeadersStream.StreamId, Http2ErrorCode.PROTOCOL_ERROR); + } + + if ((_parsedPseudoHeaderFields & headerField) == headerField) + { + // http://httpwg.org/specs/rfc7540.html#rfc.section.8.1.2.3 + // All HTTP/2 requests MUST include exactly one valid value for the :method, :scheme, and :path pseudo-header fields + throw new Http2StreamErrorException(_currentHeadersStream.StreamId, Http2ErrorCode.PROTOCOL_ERROR); + } + + if (headerField == PseudoHeaderFields.Method) + { + _isMethodConnect = value.SequenceEqual(_connectBytes); + } + + _parsedPseudoHeaderFields |= headerField; + } + else if (_requestHeaderParsingState != RequestHeaderParsingState.Trailers) + { + _requestHeaderParsingState = RequestHeaderParsingState.Headers; + } + + if (IsConnectionSpecificHeaderField(name, value)) + { + throw new Http2StreamErrorException(_currentHeadersStream.StreamId, Http2ErrorCode.PROTOCOL_ERROR); + } + + // http://httpwg.org/specs/rfc7540.html#rfc.section.8.1.2 + // A request or response containing uppercase header field names MUST be treated as malformed (Section 8.1.2.6). + for (var i = 0; i < name.Length; i++) + { + if (name[i] >= 65 && name[i] <= 90) + { + throw new Http2StreamErrorException(_currentHeadersStream.StreamId, Http2ErrorCode.PROTOCOL_ERROR); + } + } + } + + private bool IsPseudoHeaderField(Span name, out PseudoHeaderFields headerField) + { + headerField = PseudoHeaderFields.None; + + if (name.IsEmpty || name[0] != (byte)':') + { + return false; + } + + // Skip ':' + name = name.Slice(1); + + if (name.SequenceEqual(_pathBytes)) + { + headerField = PseudoHeaderFields.Path; + } + else if (name.SequenceEqual(_methodBytes)) + { + headerField = PseudoHeaderFields.Method; + } + else if (name.SequenceEqual(_schemeBytes)) + { + headerField = PseudoHeaderFields.Scheme; + } + else if (name.SequenceEqual(_statusBytes)) + { + headerField = PseudoHeaderFields.Status; + } + else if (name.SequenceEqual(_authorityBytes)) + { + headerField = PseudoHeaderFields.Authority; + } + else + { + headerField = PseudoHeaderFields.Unknown; + } + + return true; + } + + private static bool IsConnectionSpecificHeaderField(Span name, Span value) + { + return name.SequenceEqual(_connectionBytes) || (name.SequenceEqual(_teBytes) && !value.SequenceEqual(_trailersBytes)); + } + void ITimeoutControl.SetTimeout(long ticks, TimeoutAction timeoutAction) { } diff --git a/src/Kestrel.Core/Internal/Http2/Http2StreamErrorException.cs b/src/Kestrel.Core/Internal/Http2/Http2StreamErrorException.cs new file mode 100644 index 0000000000..d2fcdc6bb0 --- /dev/null +++ b/src/Kestrel.Core/Internal/Http2/Http2StreamErrorException.cs @@ -0,0 +1,21 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; + +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 +{ + public class Http2StreamErrorException : Exception + { + public Http2StreamErrorException(int streamId, Http2ErrorCode errorCode) + : base($"HTTP/2 stream ID {streamId} error: {errorCode}") + { + StreamId = streamId; + ErrorCode = errorCode; + } + + public int StreamId { get; } + + public Http2ErrorCode ErrorCode { get; } + } +} diff --git a/test/Kestrel.Core.Tests/Http2ConnectionTests.cs b/test/Kestrel.Core.Tests/Http2ConnectionTests.cs index 3851a86dbd..8e7a80aeb4 100644 --- a/test/Kestrel.Core.Tests/Http2ConnectionTests.cs +++ b/test/Kestrel.Core.Tests/Http2ConnectionTests.cs @@ -16,7 +16,6 @@ using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2.HPack; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; using Microsoft.AspNetCore.Testing; -using Microsoft.Extensions.Primitives; using Xunit; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests @@ -29,16 +28,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests { new KeyValuePair(":method", "POST"), new KeyValuePair(":path", "/"), - new KeyValuePair(":authority", "127.0.0.1"), - new KeyValuePair(":scheme", "https"), + new KeyValuePair(":scheme", "http"), }; private static readonly IEnumerable> _browserRequestHeaders = new[] { new KeyValuePair(":method", "GET"), new KeyValuePair(":path", "/"), - new KeyValuePair(":authority", "127.0.0.1"), - new KeyValuePair(":scheme", "https"), + new KeyValuePair(":scheme", "http"), new KeyValuePair("user-agent", "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:54.0) Gecko/20100101 Firefox/54.0"), new KeyValuePair("accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"), new KeyValuePair("accept-language", "en-US,en;q=0.5"), @@ -50,8 +47,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests { new KeyValuePair(":method", "GET"), new KeyValuePair(":path", "/"), - new KeyValuePair(":authority", "127.0.0.1"), - new KeyValuePair(":scheme", "https"), + new KeyValuePair(":scheme", "http"), new KeyValuePair("a", _largeHeaderValue), new KeyValuePair("b", _largeHeaderValue), new KeyValuePair("c", _largeHeaderValue), @@ -62,8 +58,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests { new KeyValuePair(":method", "GET"), new KeyValuePair(":path", "/"), - new KeyValuePair(":authority", "127.0.0.1"), - new KeyValuePair(":scheme", "https"), + new KeyValuePair(":scheme", "http"), new KeyValuePair("a", _largeHeaderValue), new KeyValuePair("b", _largeHeaderValue), new KeyValuePair("c", _largeHeaderValue), @@ -770,7 +765,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests } [Fact] - public async Task HEADERS_Received_IncompleteHeaderBlockFragment_ConnectionError() + public async Task HEADERS_Received_IncompleteHeaderBlock_ConnectionError() { await InitializeConnectionAsync(_noopApplication); @@ -779,6 +774,143 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests await WaitForConnectionErrorAsync(expectedLastStreamId: 0, expectedErrorCode: Http2ErrorCode.COMPRESSION_ERROR, ignoreNonGoAwayFrames: false); } + [Theory] + [MemberData(nameof(UpperCaseHeaderNameData))] + public async Task HEADERS_Received_HeaderNameContainsUpperCaseCharacter_StreamError(byte[] headerBlock) + { + await InitializeConnectionAsync(_noopApplication); + + await SendHeadersAsync(1, Http2HeadersFrameFlags.END_HEADERS, headerBlock); + await WaitForStreamErrorAsync(1, Http2ErrorCode.PROTOCOL_ERROR, ignoreNonRstStreamFrames: false); + + // Verify that the stream ID can't be re-used + await SendHeadersAsync(1, Http2HeadersFrameFlags.END_HEADERS, _browserRequestHeaders); + await WaitForConnectionErrorAsync(expectedLastStreamId: 1, expectedErrorCode: Http2ErrorCode.STREAM_CLOSED, ignoreNonGoAwayFrames: false); + } + + [Fact] + public Task HEADERS_Received_HeaderBlockContainsUnknownPseudoHeaderField_StreamError() + { + var headers = new[] + { + new KeyValuePair(":method", "GET"), + new KeyValuePair(":path", "/"), + new KeyValuePair(":scheme", "http"), + new KeyValuePair(":unknown", "0"), + }; + + return HEADERS_Received_InvalidHeaderFields_StreamError(headers); + } + + [Fact] + public Task HEADERS_Received_HeaderBlockContainsResponsePseudoHeaderField_StreamError() + { + var headers = new[] + { + new KeyValuePair(":method", "GET"), + new KeyValuePair(":path", "/"), + new KeyValuePair(":scheme", "http"), + new KeyValuePair(":status", "200"), + }; + + return HEADERS_Received_InvalidHeaderFields_StreamError(headers); + } + + [Theory] + [MemberData(nameof(DuplicatePseudoHeaderFieldData))] + public Task HEADERS_Received_HeaderBlockContainsDuplicatePseudoHeaderField_StreamError(IEnumerable> headers) + { + return HEADERS_Received_InvalidHeaderFields_StreamError(headers); + } + + [Theory] + [MemberData(nameof(MissingPseudoHeaderFieldData))] + public Task HEADERS_Received_HeaderBlockDoesNotContainMandatoryPseudoHeaderField_StreamError(IEnumerable> headers) + { + return HEADERS_Received_InvalidHeaderFields_StreamError(headers); + } + + [Theory] + [MemberData(nameof(ConnectMissingPseudoHeaderFieldData))] + public async Task HEADERS_Received_HeaderBlockDoesNotContainMandatoryPseudoHeaderField_MethodIsCONNECT_NoError(IEnumerable> headers) + { + await InitializeConnectionAsync(_noopApplication); + + await SendHeadersAsync(1, Http2HeadersFrameFlags.END_HEADERS | Http2HeadersFrameFlags.END_STREAM, headers); + + await ExpectAsync(Http2FrameType.HEADERS, + withLength: 55, + withFlags: (byte)Http2HeadersFrameFlags.END_HEADERS, + withStreamId: 1); + await ExpectAsync(Http2FrameType.DATA, + withLength: 0, + withFlags: (byte)Http2HeadersFrameFlags.END_STREAM, + withStreamId: 1); + + await StopConnectionAsync(expectedLastStreamId: 1, ignoreNonGoAwayFrames: false); + } + + [Theory] + [MemberData(nameof(PseudoHeaderFieldAfterRegularHeadersData))] + public Task HEADERS_Received_HeaderBlockContainsPseudoHeaderFieldAfterRegularHeaders_StreamError(IEnumerable> headers) + { + return HEADERS_Received_InvalidHeaderFields_StreamError(headers); + } + + private async Task HEADERS_Received_InvalidHeaderFields_StreamError(IEnumerable> headers) + { + await InitializeConnectionAsync(_noopApplication); + + await SendHeadersAsync(1, Http2HeadersFrameFlags.END_HEADERS, headers); + await WaitForStreamErrorAsync(1, Http2ErrorCode.PROTOCOL_ERROR, ignoreNonRstStreamFrames: false); + + // Verify that the stream ID can't be re-used + await SendHeadersAsync(1, Http2HeadersFrameFlags.END_HEADERS, _browserRequestHeaders); + await WaitForConnectionErrorAsync(expectedLastStreamId: 1, expectedErrorCode: Http2ErrorCode.STREAM_CLOSED, ignoreNonGoAwayFrames: false); + } + + [Fact] + public Task HEADERS_Received_HeaderBlockContainsConnectionSpecificHeader_StreamError() + { + var headers = new[] + { + new KeyValuePair(":method", "GET"), + new KeyValuePair(":path", "/"), + new KeyValuePair(":scheme", "http"), + new KeyValuePair("connection", "keep-alive") + }; + + return HEADERS_Received_InvalidHeaderFields_StreamError(headers); + } + + [Fact] + public Task HEADERS_Received_HeaderBlockContainsTEHeader_ValueIsNotTrailers_StreamError() + { + var headers = new[] + { + new KeyValuePair(":method", "GET"), + new KeyValuePair(":path", "/"), + new KeyValuePair(":scheme", "http"), + new KeyValuePair("te", "trailers, deflate") + }; + + return HEADERS_Received_InvalidHeaderFields_StreamError(headers); + } + + [Fact] + public Task HEADERS_Received_HeaderBlockContainsTEHeader_ValueIsTrailers_NoError() + { + var headers = new[] + { + new KeyValuePair(":method", "GET"), + new KeyValuePair(":path", "/"), + new KeyValuePair(":scheme", "http"), + new KeyValuePair("te", "trailers, deflate") + }; + + return HEADERS_Received_InvalidHeaderFields_StreamError(headers); + } + [Fact] public async Task PRIORITY_Received_StreamIdZero_ConnectionError() { @@ -1220,7 +1352,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests } [Fact] - public async Task CONTINUATION_Received_IncompleteHeaderBlockFragment_ConnectionError() + public async Task CONTINUATION_Received_IncompleteHeaderBlock_ConnectionError() { await InitializeConnectionAsync(_noopApplication); @@ -1230,6 +1362,43 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests await WaitForConnectionErrorAsync(expectedLastStreamId: 0, expectedErrorCode: Http2ErrorCode.COMPRESSION_ERROR, ignoreNonGoAwayFrames: false); } + [Theory] + [MemberData(nameof(MissingPseudoHeaderFieldData))] + public async Task CONTINUATION_Received_HeaderBlockDoesNotContainMandatoryPseudoHeaderField_StreamError(IEnumerable> headers) + { + await InitializeConnectionAsync(_noopApplication); + + Assert.True(await SendHeadersAsync(1, Http2HeadersFrameFlags.NONE, headers)); + await SendEmptyContinuationFrameAsync(1, Http2ContinuationFrameFlags.END_HEADERS); + + await WaitForStreamErrorAsync(1, Http2ErrorCode.PROTOCOL_ERROR, ignoreNonRstStreamFrames: false); + + // Verify that the stream ID can't be re-used + await SendHeadersAsync(1, Http2HeadersFrameFlags.END_HEADERS, headers); + await WaitForConnectionErrorAsync(expectedLastStreamId: 1, expectedErrorCode: Http2ErrorCode.STREAM_CLOSED, ignoreNonGoAwayFrames: false); + } + + [Theory] + [MemberData(nameof(ConnectMissingPseudoHeaderFieldData))] + public async Task CONTINUATION_Received_HeaderBlockDoesNotContainMandatoryPseudoHeaderField_MethodIsCONNECT_NoError(IEnumerable> headers) + { + await InitializeConnectionAsync(_noopApplication); + + await SendHeadersAsync(1, Http2HeadersFrameFlags.END_STREAM, headers); + await SendEmptyContinuationFrameAsync(1, Http2ContinuationFrameFlags.END_HEADERS); + + await ExpectAsync(Http2FrameType.HEADERS, + withLength: 55, + withFlags: (byte)Http2HeadersFrameFlags.END_HEADERS, + withStreamId: 1); + await ExpectAsync(Http2FrameType.DATA, + withLength: 0, + withFlags: (byte)Http2HeadersFrameFlags.END_STREAM, + withStreamId: 1); + + await StopConnectionAsync(expectedLastStreamId: 1, ignoreNonGoAwayFrames: false); + } + [Fact] public async Task CONTINUATION_Sent_WhenHeadersLargerThanFrameLength() { @@ -1552,6 +1721,17 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests return done; } + private Task SendHeadersAsync(int streamId, Http2HeadersFrameFlags flags, byte[] headerBlock) + { + var frame = new Http2Frame(); + + frame.PrepareHeaders(flags, streamId); + frame.Length = headerBlock.Length; + headerBlock.CopyTo(frame.HeadersPayload); + + return SendAsync(frame.Raw); + } + private Task SendInvalidHeadersFrameAsync(int streamId, int frameLength, byte padLength) { Assert.True(padLength >= frameLength, $"{nameof(padLength)} must be greater than or equal to {nameof(frameLength)} to create an invalid frame."); @@ -1596,6 +1776,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests return done; } + private Task SendEmptyContinuationFrameAsync(int streamId, Http2ContinuationFrameFlags flags) + { + var frame = new Http2Frame(); + + frame.PrepareContinuation(flags, streamId); + frame.Length = 0; + + return SendAsync(frame.Raw); + } + private Task SendIncompleteContinuationFrameAsync(int streamId) { var frame = new Http2Frame(); @@ -1859,5 +2049,134 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests Assert.Equal(header.Value, value, ignoreCase: true); } } + + public static TheoryData UpperCaseHeaderNameData + { + get + { + // We can't use HPackEncoder here because it will convert header names to lowercase + var headerName = "abcdefghijklmnopqrstuvwxyz"; + + var headerBlockStart = new byte[] + { + 0x82, // Indexed Header Field - :method: GET + 0x84, // Indexed Header Field - :path: / + 0x86, // Indexed Header Field - :scheme: http + 0x00, // Literal Header Field without Indexing - New Name + (byte)headerName.Length, // Header name length + }; + + var headerBlockEnd = new byte[] + { + 0x01, // Header value length + 0x30 // "0" + }; + + var data = new TheoryData(); + + for (var i = 0; i < headerName.Length; i++) + { + var bytes = Encoding.ASCII.GetBytes(headerName); + bytes[i] &= 0xdf; + + var headerBlock = headerBlockStart.Concat(bytes).Concat(headerBlockEnd).ToArray(); + data.Add(headerBlock); + } + + return data; + } + } + + public static TheoryData>> DuplicatePseudoHeaderFieldData + { + get + { + var data = new TheoryData>>(); + var requestHeaders = new[] + { + new KeyValuePair(":method", "GET"), + new KeyValuePair(":path", "/"), + new KeyValuePair(":authority", "127.0.0.1"), + new KeyValuePair(":scheme", "http"), + }; + + foreach (var headerField in requestHeaders) + { + var headers = requestHeaders.Concat(new[] { new KeyValuePair(headerField.Key, headerField.Value) }); + data.Add(headers); + } + + return data; + } + } + + public static TheoryData>> MissingPseudoHeaderFieldData + { + get + { + var data = new TheoryData>>(); + var requestHeaders = new[] + { + new KeyValuePair(":method", "GET"), + new KeyValuePair(":path", "/"), + new KeyValuePair(":scheme", "http"), + }; + + foreach (var headerField in requestHeaders) + { + var headers = requestHeaders.Except(new[] { headerField }); + data.Add(headers); + } + + return data; + } + } + + public static TheoryData>> ConnectMissingPseudoHeaderFieldData + { + get + { + var data = new TheoryData>>(); + var methodHeader = new[] { new KeyValuePair(":method", "CONNECT") }; + var requestHeaders = new[] + { + new KeyValuePair(":path", "/"), + new KeyValuePair(":scheme", "http"), + new KeyValuePair(":authority", "127.0.0.1"), + }; + + foreach (var headerField in requestHeaders) + { + var headers = methodHeader.Concat(requestHeaders.Except(new[] { headerField })); + data.Add(headers); + } + + return data; + } + } + + public static TheoryData>> PseudoHeaderFieldAfterRegularHeadersData + { + get + { + var data = new TheoryData>>(); + var requestHeaders = new[] + { + new KeyValuePair(":method", "GET"), + new KeyValuePair(":path", "/"), + new KeyValuePair(":authority", "127.0.0.1"), + new KeyValuePair(":scheme", "http"), + new KeyValuePair("content-length", "0") + }; + + foreach (var headerField in requestHeaders.Where(h => h.Key.StartsWith(":"))) + { + var headers = requestHeaders.Except(new[] { headerField }).Concat(new[] { headerField }); + data.Add(headers); + } + + return data; + } + } } } From fdb4184dbfdbac6ee8b53a4d8d1fbfaa8f60c0c1 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Wed, 11 Oct 2017 15:14:35 -0700 Subject: [PATCH 1427/1662] Sockets transport (#2100) * Make Sockets the default transport * Create separate Libuv and Sockets functional test projects * Fix functional tests that fail with Sockets * Moved OneToTenThreads test to Kestrel.Transport.Libuv.Tests * Fix systemd activation tests to use libuv transport * Dispose Sockets PipeFactory * Improve Socket's server-side abort handling * Add explicit rebinding test --- .travis.yml | 2 +- KestrelHttpServer.sln | 55 ++++++--- samples/SampleApp/Startup.cs | 23 ++-- src/Kestrel.Core/Properties/AssemblyInfo.cs | 3 +- src/Kestrel.Https/Properties/AssemblyInfo.cs | 4 +- .../Internal/ISocketsTrace.cs | 23 ++++ .../Internal/SocketsTrace.cs | 93 ++++++++++++++ .../SocketConnection.cs | 71 ++++++++--- .../SocketTransport.cs | 19 +-- .../SocketTransportFactory.cs | 24 +++- .../baseline.netcore.json | 4 + src/Kestrel/Kestrel.csproj | 2 + .../WebHostBuilderKestrelExtensions.cs | 8 +- .../AddressRegistrationTests.cs | 114 ++++++++++++++++-- .../HttpProtocolSelectionTests.cs | 4 +- test/Kestrel.FunctionalTests/HttpsTests.cs | 14 +-- .../LoggingConnectionAdapterTests.cs | 2 +- .../MaxRequestBufferSizeTests.cs | 2 +- test/Kestrel.FunctionalTests/RequestTests.cs | 28 +++-- test/Kestrel.FunctionalTests/ResponseTests.cs | 9 +- .../TestHelpers/TestServer.cs | 2 +- .../ThreadCountTests.cs | 72 ----------- ...el.Trasnport.Libuv.FunctionalTests.csproj} | 6 +- .../ListenHandleTests.cs | 0 .../TransportSelector.cs | 15 +++ .../LibuvTransportTests.cs | 50 ++++++++ ...l.Trasnport.Sockets.FunctionalTests.csproj | 36 ++++++ .../TransportSelector.cs | 15 +++ .../SystemdActivation/Dockerfile | 0 .../SystemdActivation/docker-entrypoint.sh | 0 .../SystemdActivation/docker.sh | 0 31 files changed, 527 insertions(+), 173 deletions(-) create mode 100644 src/Kestrel.Transport.Sockets/Internal/ISocketsTrace.cs create mode 100644 src/Kestrel.Transport.Sockets/Internal/SocketsTrace.cs delete mode 100644 test/Kestrel.FunctionalTests/ThreadCountTests.cs rename test/{Kestrel.FunctionalTests/Kestrel.FunctionalTests.csproj => Kestrel.Transport.Libuv.FunctionalTests/Kestrel.Trasnport.Libuv.FunctionalTests.csproj} (76%) rename test/{Kestrel.FunctionalTests => Kestrel.Transport.Libuv.FunctionalTests}/ListenHandleTests.cs (100%) create mode 100644 test/Kestrel.Transport.Libuv.FunctionalTests/TransportSelector.cs create mode 100644 test/Kestrel.Transport.Sockets.FunctionalTests/Kestrel.Trasnport.Sockets.FunctionalTests.csproj create mode 100644 test/Kestrel.Transport.Sockets.FunctionalTests/TransportSelector.cs rename test/{Kestrel.FunctionalTests => }/SystemdActivation/Dockerfile (100%) rename test/{Kestrel.FunctionalTests => }/SystemdActivation/docker-entrypoint.sh (100%) rename test/{Kestrel.FunctionalTests => }/SystemdActivation/docker.sh (100%) mode change 100755 => 100644 diff --git a/.travis.yml b/.travis.yml index 73fb758d81..61ec7b5348 100644 --- a/.travis.yml +++ b/.travis.yml @@ -28,4 +28,4 @@ before_install: - if test "$TRAVIS_OS_NAME" == "osx"; then brew update; brew install openssl; ln -s /usr/local/opt/openssl/lib/libcrypto.1.0.0.dylib /usr/local/lib/; ln -s /usr/local/opt/openssl/lib/libssl.1.0.0.dylib /usr/local/lib/; fi script: - ./build.sh - - if test "$TRAVIS_OS_NAME" != "osx"; then bash test/Kestrel.FunctionalTests/SystemdActivation/docker.sh; fi + - if test "$TRAVIS_OS_NAME" != "osx"; then bash test/SystemdActivation/docker.sh; fi diff --git a/KestrelHttpServer.sln b/KestrelHttpServer.sln index 0baa31521a..2f3786bd6c 100644 --- a/KestrelHttpServer.sln +++ b/KestrelHttpServer.sln @@ -1,6 +1,6 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 15 -VisualStudioVersion = 15.0.26814.0 +VisualStudioVersion = 15.0.26730.16 MinimumVisualStudioVersion = 15.0.26730.03 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{7972A5D6-3385-4127-9277-428506DD44FF}" ProjectSection(SolutionItems) = preProject @@ -68,8 +68,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CodeGenerator", "tools\Code EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Kestrel.Https", "src\Kestrel.Https\Kestrel.Https.csproj", "{5F64B3C3-0C2E-431A-B820-A81BBFC863DA}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Kestrel.FunctionalTests", "test\Kestrel.FunctionalTests\Kestrel.FunctionalTests.csproj", "{9559A5F1-080C-4909-B6CF-7E4B3DC55748}" -EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Kestrel.Performance", "benchmarks\Kestrel.Performance\Kestrel.Performance.csproj", "{EBFE9719-A44B-4978-A71F-D5C254E7F35A}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "TestCertificates", "TestCertificates", "{2822C132-BFFB-4D53-AC5B-E7E47DD81A6E}" @@ -112,6 +110,17 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "build", "build", "{C2910A13 build\repo.targets = build\repo.targets EndProjectSection EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "SystemdActivation", "SystemdActivation", "{B7B0EA74-528F-46B8-9BC4-909D9A67C194}" + ProjectSection(SolutionItems) = preProject + test\SystemdActivation\docker-entrypoint.sh = test\SystemdActivation\docker-entrypoint.sh + test\SystemdActivation\docker.sh = test\SystemdActivation\docker.sh + test\SystemdActivation\Dockerfile = test\SystemdActivation\Dockerfile + EndProjectSection +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Kestrel.Transport.Libuv.FunctionalTests", "test\Kestrel.Transport.Libuv.FunctionalTests\Kestrel.Trasnport.Libuv.FunctionalTests.csproj", "{74032D79-8EA7-4483-BD82-C38370420FFF}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Kestrel.Transport.Sockets.FunctionalTests", "test\Kestrel.Transport.Sockets.FunctionalTests\Kestrel.Trasnport.Sockets.FunctionalTests.csproj", "{9C7B6B5F-088A-436E-834B-6373EA36DEEE}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -194,18 +203,6 @@ Global {5F64B3C3-0C2E-431A-B820-A81BBFC863DA}.Release|x64.Build.0 = Release|Any CPU {5F64B3C3-0C2E-431A-B820-A81BBFC863DA}.Release|x86.ActiveCfg = Release|Any CPU {5F64B3C3-0C2E-431A-B820-A81BBFC863DA}.Release|x86.Build.0 = Release|Any CPU - {9559A5F1-080C-4909-B6CF-7E4B3DC55748}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {9559A5F1-080C-4909-B6CF-7E4B3DC55748}.Debug|Any CPU.Build.0 = Debug|Any CPU - {9559A5F1-080C-4909-B6CF-7E4B3DC55748}.Debug|x64.ActiveCfg = Debug|Any CPU - {9559A5F1-080C-4909-B6CF-7E4B3DC55748}.Debug|x64.Build.0 = Debug|Any CPU - {9559A5F1-080C-4909-B6CF-7E4B3DC55748}.Debug|x86.ActiveCfg = Debug|Any CPU - {9559A5F1-080C-4909-B6CF-7E4B3DC55748}.Debug|x86.Build.0 = Debug|Any CPU - {9559A5F1-080C-4909-B6CF-7E4B3DC55748}.Release|Any CPU.ActiveCfg = Release|Any CPU - {9559A5F1-080C-4909-B6CF-7E4B3DC55748}.Release|Any CPU.Build.0 = Release|Any CPU - {9559A5F1-080C-4909-B6CF-7E4B3DC55748}.Release|x64.ActiveCfg = Release|Any CPU - {9559A5F1-080C-4909-B6CF-7E4B3DC55748}.Release|x64.Build.0 = Release|Any CPU - {9559A5F1-080C-4909-B6CF-7E4B3DC55748}.Release|x86.ActiveCfg = Release|Any CPU - {9559A5F1-080C-4909-B6CF-7E4B3DC55748}.Release|x86.Build.0 = Release|Any CPU {EBFE9719-A44B-4978-A71F-D5C254E7F35A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {EBFE9719-A44B-4978-A71F-D5C254E7F35A}.Debug|Any CPU.Build.0 = Debug|Any CPU {EBFE9719-A44B-4978-A71F-D5C254E7F35A}.Debug|x64.ActiveCfg = Debug|Any CPU @@ -314,6 +311,30 @@ Global {924AE57C-1EBA-4A1D-A039-8C100B7507A5}.Release|x64.Build.0 = Release|Any CPU {924AE57C-1EBA-4A1D-A039-8C100B7507A5}.Release|x86.ActiveCfg = Release|Any CPU {924AE57C-1EBA-4A1D-A039-8C100B7507A5}.Release|x86.Build.0 = Release|Any CPU + {74032D79-8EA7-4483-BD82-C38370420FFF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {74032D79-8EA7-4483-BD82-C38370420FFF}.Debug|Any CPU.Build.0 = Debug|Any CPU + {74032D79-8EA7-4483-BD82-C38370420FFF}.Debug|x64.ActiveCfg = Debug|Any CPU + {74032D79-8EA7-4483-BD82-C38370420FFF}.Debug|x64.Build.0 = Debug|Any CPU + {74032D79-8EA7-4483-BD82-C38370420FFF}.Debug|x86.ActiveCfg = Debug|Any CPU + {74032D79-8EA7-4483-BD82-C38370420FFF}.Debug|x86.Build.0 = Debug|Any CPU + {74032D79-8EA7-4483-BD82-C38370420FFF}.Release|Any CPU.ActiveCfg = Release|Any CPU + {74032D79-8EA7-4483-BD82-C38370420FFF}.Release|Any CPU.Build.0 = Release|Any CPU + {74032D79-8EA7-4483-BD82-C38370420FFF}.Release|x64.ActiveCfg = Release|Any CPU + {74032D79-8EA7-4483-BD82-C38370420FFF}.Release|x64.Build.0 = Release|Any CPU + {74032D79-8EA7-4483-BD82-C38370420FFF}.Release|x86.ActiveCfg = Release|Any CPU + {74032D79-8EA7-4483-BD82-C38370420FFF}.Release|x86.Build.0 = Release|Any CPU + {9C7B6B5F-088A-436E-834B-6373EA36DEEE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {9C7B6B5F-088A-436E-834B-6373EA36DEEE}.Debug|Any CPU.Build.0 = Debug|Any CPU + {9C7B6B5F-088A-436E-834B-6373EA36DEEE}.Debug|x64.ActiveCfg = Debug|Any CPU + {9C7B6B5F-088A-436E-834B-6373EA36DEEE}.Debug|x64.Build.0 = Debug|Any CPU + {9C7B6B5F-088A-436E-834B-6373EA36DEEE}.Debug|x86.ActiveCfg = Debug|Any CPU + {9C7B6B5F-088A-436E-834B-6373EA36DEEE}.Debug|x86.Build.0 = Debug|Any CPU + {9C7B6B5F-088A-436E-834B-6373EA36DEEE}.Release|Any CPU.ActiveCfg = Release|Any CPU + {9C7B6B5F-088A-436E-834B-6373EA36DEEE}.Release|Any CPU.Build.0 = Release|Any CPU + {9C7B6B5F-088A-436E-834B-6373EA36DEEE}.Release|x64.ActiveCfg = Release|Any CPU + {9C7B6B5F-088A-436E-834B-6373EA36DEEE}.Release|x64.Build.0 = Release|Any CPU + {9C7B6B5F-088A-436E-834B-6373EA36DEEE}.Release|x86.ActiveCfg = Release|Any CPU + {9C7B6B5F-088A-436E-834B-6373EA36DEEE}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -325,7 +346,6 @@ Global {B35D4D31-E74C-4646-8A11-7A7A40F0021E} = {8A3D00B8-1CCF-4BE6-A060-11104CE2D9CE} {BD2D4D29-1BD9-40D0-BB31-337D5416B63C} = {327F7880-D9AF-46BD-B45C-3B7E34A01DFD} {5F64B3C3-0C2E-431A-B820-A81BBFC863DA} = {2D5D5227-4DBD-499A-96B1-76A36B03B750} - {9559A5F1-080C-4909-B6CF-7E4B3DC55748} = {D3273454-EA07-41D2-BF0B-FCC3675C2483} {EBFE9719-A44B-4978-A71F-D5C254E7F35A} = {A95C3BE1-B850-4265-97A0-777ADCCD437F} {2822C132-BFFB-4D53-AC5B-E7E47DD81A6E} = {0EF2ACDF-012F-4472-A13A-4272419E2903} {A76B8C8C-0DC5-4DD3-9B1F-02E51A0915F4} = {2D5D5227-4DBD-499A-96B1-76A36B03B750} @@ -336,6 +356,9 @@ Global {4F1C30F8-CCAA-48D7-9DF6-2A84021F5BCC} = {D3273454-EA07-41D2-BF0B-FCC3675C2483} {6956CF5C-3163-4398-8628-4ECA569245B5} = {2D5D5227-4DBD-499A-96B1-76A36B03B750} {924AE57C-1EBA-4A1D-A039-8C100B7507A5} = {2D5D5227-4DBD-499A-96B1-76A36B03B750} + {B7B0EA74-528F-46B8-9BC4-909D9A67C194} = {D3273454-EA07-41D2-BF0B-FCC3675C2483} + {74032D79-8EA7-4483-BD82-C38370420FFF} = {D3273454-EA07-41D2-BF0B-FCC3675C2483} + {9C7B6B5F-088A-436E-834B-6373EA36DEEE} = {D3273454-EA07-41D2-BF0B-FCC3675C2483} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {2D10D020-6770-47CA-BB8D-2C23FE3AE071} diff --git a/samples/SampleApp/Startup.cs b/samples/SampleApp/Startup.cs index e89e97790b..562f3a020d 100644 --- a/samples/SampleApp/Startup.cs +++ b/samples/SampleApp/Startup.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Diagnostics; using System.Globalization; using System.IO; using System.Net; @@ -51,7 +52,7 @@ namespace SampleApp basePort = 5000; } - var host = new WebHostBuilder() + var hostBuilder = new WebHostBuilder() .ConfigureLogging((_, factory) => { factory.AddConsole(); @@ -80,16 +81,20 @@ namespace SampleApp // The following section should be used to demo sockets //options.ListenUnixSocket("/tmp/kestrel-test.sock"); }) - .UseLibuv(options => - { - // Uncomment the following line to change the default number of libuv threads for all endpoints. - // options.ThreadCount = 4; - }) .UseContentRoot(Directory.GetCurrentDirectory()) - .UseStartup() - .Build(); + .UseStartup(); - return host.RunAsync(); + if (string.Equals(Process.GetCurrentProcess().Id.ToString(), Environment.GetEnvironmentVariable("LISTEN_PID"))) + { + // Use libuv if activated by systemd, since that's currently the only transport that supports being passed a socket handle. + hostBuilder.UseLibuv(options => + { + // Uncomment the following line to change the default number of libuv threads for all endpoints. + // options.ThreadCount = 4; + }); + } + + return hostBuilder.Build().RunAsync(); } } } \ No newline at end of file diff --git a/src/Kestrel.Core/Properties/AssemblyInfo.cs b/src/Kestrel.Core/Properties/AssemblyInfo.cs index bd1d32689a..e2d152d0d3 100644 --- a/src/Kestrel.Core/Properties/AssemblyInfo.cs +++ b/src/Kestrel.Core/Properties/AssemblyInfo.cs @@ -3,7 +3,8 @@ using System.Runtime.CompilerServices; -[assembly: InternalsVisibleTo("Microsoft.AspNetCore.Server.Kestrel.FunctionalTests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")] +[assembly: InternalsVisibleTo("Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.FunctionalTests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")] +[assembly: InternalsVisibleTo("Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.FunctionalTests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")] [assembly: InternalsVisibleTo("Microsoft.AspNetCore.Server.Kestrel.Core.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")] [assembly: InternalsVisibleTo("Kestrel.Performance, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")] [assembly: InternalsVisibleTo("Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")] diff --git a/src/Kestrel.Https/Properties/AssemblyInfo.cs b/src/Kestrel.Https/Properties/AssemblyInfo.cs index 3bb5150c92..65c2045e24 100644 --- a/src/Kestrel.Https/Properties/AssemblyInfo.cs +++ b/src/Kestrel.Https/Properties/AssemblyInfo.cs @@ -3,4 +3,6 @@ using System.Runtime.CompilerServices; -[assembly: InternalsVisibleTo("Microsoft.AspNetCore.Server.Kestrel.FunctionalTests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")] +[assembly: InternalsVisibleTo("Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.FunctionalTests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")] +[assembly: InternalsVisibleTo("Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.FunctionalTests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")] + diff --git a/src/Kestrel.Transport.Sockets/Internal/ISocketsTrace.cs b/src/Kestrel.Transport.Sockets/Internal/ISocketsTrace.cs new file mode 100644 index 0000000000..06c2c36f20 --- /dev/null +++ b/src/Kestrel.Transport.Sockets/Internal/ISocketsTrace.cs @@ -0,0 +1,23 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using Microsoft.Extensions.Logging; + +namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal +{ + public interface ISocketsTrace : ILogger + { + void ConnectionReadFin(string connectionId); + + void ConnectionWriteFin(string connectionId); + + void ConnectionError(string connectionId, Exception ex); + + void ConnectionReset(string connectionId); + + void ConnectionPause(string connectionId); + + void ConnectionResume(string connectionId); + } +} diff --git a/src/Kestrel.Transport.Sockets/Internal/SocketsTrace.cs b/src/Kestrel.Transport.Sockets/Internal/SocketsTrace.cs new file mode 100644 index 0000000000..2757bcf4ce --- /dev/null +++ b/src/Kestrel.Transport.Sockets/Internal/SocketsTrace.cs @@ -0,0 +1,93 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using Microsoft.Extensions.Logging; + +namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal +{ + public class SocketsTrace : ISocketsTrace + { + // ConnectionRead: Reserved: 3 + + private static readonly Action _connectionPause = + LoggerMessage.Define(LogLevel.Debug, 4, @"Connection id ""{ConnectionId}"" paused."); + + private static readonly Action _connectionResume = + LoggerMessage.Define(LogLevel.Debug, 5, @"Connection id ""{ConnectionId}"" resumed."); + + private static readonly Action _connectionReadFin = + LoggerMessage.Define(LogLevel.Debug, 6, @"Connection id ""{ConnectionId}"" received FIN."); + + private static readonly Action _connectionWriteFin = + LoggerMessage.Define(LogLevel.Debug, 7, @"Connection id ""{ConnectionId}"" sending FIN."); + + private static readonly Action _connectionError = + LoggerMessage.Define(LogLevel.Information, 14, @"Connection id ""{ConnectionId}"" communication error."); + + private static readonly Action _connectionReset = + LoggerMessage.Define(LogLevel.Debug, 19, @"Connection id ""{ConnectionId}"" reset."); + + private readonly ILogger _logger; + + public SocketsTrace(ILogger logger) + { + _logger = logger; + } + + public void ConnectionRead(string connectionId, int count) + { + // Don't log for now since this could be *too* verbose. + // Reserved: Event ID 3 + } + + public void ConnectionReadFin(string connectionId) + { + _connectionReadFin(_logger, connectionId, null); + } + + public void ConnectionWriteFin(string connectionId) + { + _connectionWriteFin(_logger, connectionId, null); + } + + public void ConnectionWrite(string connectionId, int count) + { + // Don't log for now since this could be *too* verbose. + // Reserved: Event ID 11 + } + + public void ConnectionWriteCallback(string connectionId, int status) + { + // Don't log for now since this could be *too* verbose. + // Reserved: Event ID 12 + } + + public void ConnectionError(string connectionId, Exception ex) + { + _connectionError(_logger, connectionId, ex); + } + + public void ConnectionReset(string connectionId) + { + _connectionReset(_logger, connectionId, null); + } + + public void ConnectionPause(string connectionId) + { + _connectionPause(_logger, connectionId, null); + } + + public void ConnectionResume(string connectionId) + { + _connectionResume(_logger, connectionId, null); + } + + public IDisposable BeginScope(TState state) => _logger.BeginScope(state); + + public bool IsEnabled(LogLevel logLevel) => _logger.IsEnabled(logLevel); + + public void Log(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func formatter) + => _logger.Log(logLevel, eventId, state, exception, formatter); + } +} diff --git a/src/Kestrel.Transport.Sockets/SocketConnection.cs b/src/Kestrel.Transport.Sockets/SocketConnection.cs index 4f11d7cd1f..6a7f765afc 100644 --- a/src/Kestrel.Transport.Sockets/SocketConnection.cs +++ b/src/Kestrel.Transport.Sockets/SocketConnection.cs @@ -5,30 +5,36 @@ using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; +using System.IO.Pipelines; using System.Net; using System.Net.Sockets; using System.Threading.Tasks; -using System.IO.Pipelines; -using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; using Microsoft.AspNetCore.Protocols; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal; +using Microsoft.Extensions.Logging; namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets { internal sealed class SocketConnection : TransportConnection { - private readonly Socket _socket; - private readonly SocketTransport _transport; - - private IList> _sendBufferList; private const int MinAllocBufferSize = 2048; - internal SocketConnection(Socket socket, SocketTransport transport) + private readonly Socket _socket; + private readonly ISocketsTrace _trace; + + private IList> _sendBufferList; + private volatile bool _aborted; + + internal SocketConnection(Socket socket, PipeFactory pipeFactory, ISocketsTrace trace) { Debug.Assert(socket != null); - Debug.Assert(transport != null); + Debug.Assert(pipeFactory != null); + Debug.Assert(trace != null); _socket = socket; - _transport = transport; + PipeFactory = pipeFactory; + _trace = trace; var localEndPoint = (IPEndPoint)_socket.LocalEndPoint; var remoteEndPoint = (IPEndPoint)_socket.RemoteEndPoint; @@ -40,6 +46,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets RemotePort = remoteEndPoint.Port; } + public override PipeFactory PipeFactory { get; } + public override IScheduler InputWriterScheduler => InlineScheduler.Default; + public override IScheduler OutputReaderScheduler => TaskRunScheduler.Default; + public async Task StartAsync(IConnectionHandler connectionHandler) { try @@ -66,9 +76,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets // Dispose the socket(should noop if already called) _socket.Dispose(); } - catch (Exception) + catch (Exception ex) { - // TODO: Log + _trace.LogError(0, ex, $"Unexpected exception in {nameof(SocketConnection)}.{nameof(StartAsync)}."); } } @@ -90,6 +100,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets if (bytesReceived == 0) { // FIN + _trace.ConnectionReadFin(ConnectionId); break; } @@ -100,7 +111,18 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets buffer.Commit(); } - var result = await buffer.FlushAsync(); + var flushTask = buffer.FlushAsync(); + + if (!flushTask.IsCompleted) + { + _trace.ConnectionPause(ConnectionId); + + await flushTask; + + _trace.ConnectionResume(ConnectionId); + } + + var result = flushTask.GetAwaiter().GetResult(); if (result.IsCompleted) { // Pipe consumer is shut down, do we stop writing @@ -111,25 +133,36 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets catch (SocketException ex) when (ex.SocketErrorCode == SocketError.ConnectionReset) { error = new ConnectionResetException(ex.Message, ex); + _trace.ConnectionReset(ConnectionId); } - catch (SocketException ex) when (ex.SocketErrorCode == SocketError.OperationAborted) + catch (SocketException ex) when (ex.SocketErrorCode == SocketError.OperationAborted || + ex.SocketErrorCode == SocketError.Interrupted) { error = new ConnectionAbortedException(); + _trace.ConnectionError(ConnectionId, error); } catch (ObjectDisposedException) { error = new ConnectionAbortedException(); + _trace.ConnectionError(ConnectionId, error); } catch (IOException ex) { error = ex; + _trace.ConnectionError(ConnectionId, error); } catch (Exception ex) { error = new IOException(ex.Message, ex); + _trace.ConnectionError(ConnectionId, error); } finally { + if (_aborted) + { + error = error ?? new ConnectionAbortedException(); + } + Input.Complete(error); } } @@ -202,8 +235,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets Output.Advance(buffer.End); } } - - _socket.Shutdown(SocketShutdown.Send); } catch (SocketException ex) when (ex.SocketErrorCode == SocketError.OperationAborted) { @@ -224,6 +255,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets finally { Output.Complete(error); + + // Make sure to close the connection only after the _aborted flag is set. + // Without this, the RequestsCanBeAbortedMidRead test will sometimes fail when + // a BadHttpRequestException is thrown instead of a TaskCanceledException. + _aborted = true; + _trace.ConnectionWriteFin(ConnectionId); + _socket.Shutdown(SocketShutdown.Both); } } @@ -237,8 +275,5 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets return segment; } - public override PipeFactory PipeFactory => _transport.TransportFactory.PipeFactory; - public override IScheduler InputWriterScheduler => InlineScheduler.Default; - public override IScheduler OutputReaderScheduler => TaskRunScheduler.Default; } } diff --git a/src/Kestrel.Transport.Sockets/SocketTransport.cs b/src/Kestrel.Transport.Sockets/SocketTransport.cs index 83a4cb2909..61ede997e3 100644 --- a/src/Kestrel.Transport.Sockets/SocketTransport.cs +++ b/src/Kestrel.Transport.Sockets/SocketTransport.cs @@ -3,32 +3,38 @@ using System; using System.Diagnostics; +using System.IO.Pipelines; using System.Net; using System.Net.Sockets; using System.Threading.Tasks; using Microsoft.AspNetCore.Protocols; using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal; namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets { internal sealed class SocketTransport : ITransport { - private readonly SocketTransportFactory _transportFactory; + private readonly PipeFactory _pipeFactory = new PipeFactory(); private readonly IEndPointInformation _endPointInformation; private readonly IConnectionHandler _handler; + private readonly ISocketsTrace _trace; private Socket _listenSocket; private Task _listenTask; - internal SocketTransport(SocketTransportFactory transportFactory, IEndPointInformation endPointInformation, IConnectionHandler handler) + internal SocketTransport( + IEndPointInformation endPointInformation, + IConnectionHandler handler, + ISocketsTrace trace) { - Debug.Assert(transportFactory != null); Debug.Assert(endPointInformation != null); Debug.Assert(endPointInformation.Type == ListenType.IPEndPoint); Debug.Assert(handler != null); + Debug.Assert(trace != null); - _transportFactory = transportFactory; _endPointInformation = endPointInformation; _handler = handler; + _trace = trace; _listenSocket = null; _listenTask = null; @@ -92,6 +98,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets public Task StopAsync() { + _pipeFactory.Dispose(); return Task.CompletedTask; } @@ -105,7 +112,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets acceptSocket.NoDelay = _endPointInformation.NoDelay; - var connection = new SocketConnection(acceptSocket, this); + var connection = new SocketConnection(acceptSocket, _pipeFactory, _trace); _ = connection.StartAsync(_handler); } } @@ -121,7 +128,5 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets } } } - - internal SocketTransportFactory TransportFactory => _transportFactory; } } diff --git a/src/Kestrel.Transport.Sockets/SocketTransportFactory.cs b/src/Kestrel.Transport.Sockets/SocketTransportFactory.cs index 849b168342..b8ee977910 100644 --- a/src/Kestrel.Transport.Sockets/SocketTransportFactory.cs +++ b/src/Kestrel.Transport.Sockets/SocketTransportFactory.cs @@ -2,18 +2,32 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.IO.Pipelines; using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal; using Microsoft.Extensions.Options; +using Microsoft.Extensions.Logging; namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets { public sealed class SocketTransportFactory : ITransportFactory { - private readonly PipeFactory _pipeFactory = new PipeFactory(); + private readonly SocketsTrace _trace; - public SocketTransportFactory(IOptions options) + public SocketTransportFactory( + IOptions options, + ILoggerFactory loggerFactory) { + if (options == null) + { + throw new ArgumentNullException(nameof(options)); + } + if (loggerFactory == null) + { + throw new ArgumentNullException(nameof(loggerFactory)); + } + + var logger = loggerFactory.CreateLogger("Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets"); + _trace = new SocketsTrace(logger); } public ITransport Create(IEndPointInformation endPointInformation, IConnectionHandler handler) @@ -33,9 +47,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets throw new ArgumentNullException(nameof(handler)); } - return new SocketTransport(this, endPointInformation, handler); + return new SocketTransport(endPointInformation, handler, _trace); } - - internal PipeFactory PipeFactory => _pipeFactory; } } diff --git a/src/Kestrel.Transport.Sockets/baseline.netcore.json b/src/Kestrel.Transport.Sockets/baseline.netcore.json index e614b8097c..bd469c5786 100644 --- a/src/Kestrel.Transport.Sockets/baseline.netcore.json +++ b/src/Kestrel.Transport.Sockets/baseline.netcore.json @@ -83,6 +83,10 @@ { "Name": "options", "Type": "Microsoft.Extensions.Options.IOptions" + }, + { + "Name": "loggerFactory", + "Type": "Microsoft.Extensions.Logging.ILoggerFactory" } ], "Visibility": "Public", diff --git a/src/Kestrel/Kestrel.csproj b/src/Kestrel/Kestrel.csproj index cdd0e1bc70..1376f1e891 100644 --- a/src/Kestrel/Kestrel.csproj +++ b/src/Kestrel/Kestrel.csproj @@ -16,7 +16,9 @@ + + diff --git a/src/Kestrel/WebHostBuilderKestrelExtensions.cs b/src/Kestrel/WebHostBuilderKestrelExtensions.cs index 3d3dad73cb..5ed947e96a 100644 --- a/src/Kestrel/WebHostBuilderKestrelExtensions.cs +++ b/src/Kestrel/WebHostBuilderKestrelExtensions.cs @@ -5,7 +5,10 @@ using System; using Microsoft.AspNetCore.Hosting.Server; using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets; using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.DependencyInjection.Extensions; using Microsoft.Extensions.Options; namespace Microsoft.AspNetCore.Hosting @@ -23,10 +26,11 @@ namespace Microsoft.AspNetCore.Hosting /// public static IWebHostBuilder UseKestrel(this IWebHostBuilder hostBuilder) { - hostBuilder.UseLibuv(); - return hostBuilder.ConfigureServices(services => { + // Don't override an already-configured transport + services.TryAddSingleton(); + services.AddTransient, KestrelServerOptionsSetup>(); services.AddSingleton(); }); diff --git a/test/Kestrel.FunctionalTests/AddressRegistrationTests.cs b/test/Kestrel.FunctionalTests/AddressRegistrationTests.cs index b9f6e4303a..66f2a62c2d 100644 --- a/test/Kestrel.FunctionalTests/AddressRegistrationTests.cs +++ b/test/Kestrel.FunctionalTests/AddressRegistrationTests.cs @@ -163,7 +163,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests private async Task RegisterAddresses_Success(string addressInput, string[] testUrls, int testPort = 0) { - var hostBuilder = new WebHostBuilder() + var hostBuilder = TransportSelector.GetWebHostBuilder() .UseKestrel() .ConfigureLogging(_configureLoggingDelegate) .UseUrls(addressInput) @@ -223,7 +223,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests private async Task RegisterIPEndPoint_Success(IPEndPoint endPoint, string testUrl, int testPort = 0) { - var hostBuilder = new WebHostBuilder() + var hostBuilder = TransportSelector.GetWebHostBuilder() .ConfigureLogging(_configureLoggingDelegate) .UseKestrel(options => { @@ -304,7 +304,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { var testLogger = new TestApplicationErrorLogger(); - var hostBuilder = new WebHostBuilder() + var hostBuilder = TransportSelector.GetWebHostBuilder() .ConfigureLogging(_configureLoggingDelegate) .UseKestrel() .ConfigureLogging(builder => builder @@ -336,7 +336,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests socket.Bind(new IPEndPoint(IPAddress.Loopback, 0)); var port = ((IPEndPoint)socket.LocalEndPoint).Port; - var hostBuilder = new WebHostBuilder() + var hostBuilder = TransportSelector.GetWebHostBuilder() .ConfigureLogging(_configureLoggingDelegate) .UseKestrel() .UseUrls($"http://127.0.0.1:{port}") @@ -359,7 +359,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests socket.Bind(new IPEndPoint(IPAddress.IPv6Loopback, 0)); var port = ((IPEndPoint)socket.LocalEndPoint).Port; - var hostBuilder = new WebHostBuilder() + var hostBuilder = TransportSelector.GetWebHostBuilder() .ConfigureLogging(_configureLoggingDelegate) .UseKestrel() .UseUrls($"http://[::1]:{port}") @@ -378,7 +378,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { var useUrlsAddress = $"http://127.0.0.1:0"; var testLogger = new TestApplicationErrorLogger(); - var hostBuilder = new WebHostBuilder() + var hostBuilder = TransportSelector.GetWebHostBuilder() .UseKestrel(options => { options.Listen(new IPEndPoint(IPAddress.Loopback, 0), listenOptions => @@ -417,7 +417,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { var useUrlsAddress = $"http://127.0.0.1:0"; var testLogger = new TestApplicationErrorLogger(); - var hostBuilder = new WebHostBuilder() + var hostBuilder = TransportSelector.GetWebHostBuilder() .ConfigureLogging(_configureLoggingDelegate) .UseKestrel(options => { @@ -455,7 +455,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [Fact] public async Task DoesNotOverrideDirectConfigurationWithIServerAddressesFeature_IfAddressesEmpty() { - var hostBuilder = new WebHostBuilder() + var hostBuilder = TransportSelector.GetWebHostBuilder() .ConfigureLogging(_configureLoggingDelegate) .UseKestrel(options => { @@ -499,7 +499,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [Fact] public void ThrowsWhenBindingLocalhostToDynamicPort() { - var hostBuilder = new WebHostBuilder() + var hostBuilder = TransportSelector.GetWebHostBuilder() .UseKestrel() .UseUrls("http://localhost:0") .Configure(ConfigureEchoAddress); @@ -515,7 +515,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [InlineData("ftp://localhost")] public void ThrowsForUnsupportedAddressFromHosting(string addr) { - var hostBuilder = new WebHostBuilder() + var hostBuilder = TransportSelector.GetWebHostBuilder() .UseKestrel() .UseUrls(addr) .Configure(ConfigureEchoAddress); @@ -526,6 +526,91 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } } + // https://github.com/dotnet/corefx/issues/24562 + [ConditionalFact] + [OSSkipCondition(OperatingSystems.MacOSX, SkipReason = "Sockets transport fails to rebind on macOS.")] + [OSSkipCondition(OperatingSystems.Linux, SkipReason = "Sockets transport fails to rebind on Linux.")] + public async Task CanRebindToEndPoint() + { + var port = GetNextPort(); + var endPointAddress = $"http://127.0.0.1:{port}/"; + + var hostBuilder = TransportSelector.GetWebHostBuilder() + .ConfigureLogging(_configureLoggingDelegate) + .UseKestrel(options => + { + options.Listen(IPAddress.Loopback, port); + }) + .Configure(ConfigureEchoAddress); + + using (var host = hostBuilder.Build()) + { + host.Start(); + + Assert.Equal(endPointAddress, await HttpClientSlim.GetStringAsync(endPointAddress)); + } + + hostBuilder = TransportSelector.GetWebHostBuilder() + .ConfigureLogging(_configureLoggingDelegate) + .UseKestrel(options => + { + options.Listen(IPAddress.Loopback, port); + }) + .Configure(ConfigureEchoAddress); + + using (var host = hostBuilder.Build()) + { + host.Start(); + + Assert.Equal(endPointAddress, await HttpClientSlim.GetStringAsync(endPointAddress)); + } + } + + // https://github.com/dotnet/corefx/issues/24562 + [ConditionalFact] + [OSSkipCondition(OperatingSystems.MacOSX, SkipReason = "Sockets transport fails to rebind on macOS.")] + [OSSkipCondition(OperatingSystems.Linux, SkipReason = "Sockets transport fails to rebind on Linux.")] + public async Task CanRebindToMultipleEndPoints() + { + var port = GetNextPort(); + var ipv4endPointAddress = $"http://127.0.0.1:{port}/"; + var ipv6endPointAddress = $"http://[::1]:{port}/"; + + var hostBuilder = TransportSelector.GetWebHostBuilder() + .ConfigureLogging(_configureLoggingDelegate) + .UseKestrel(options => + { + options.Listen(IPAddress.Loopback, port); + options.Listen(IPAddress.IPv6Loopback, port); + }) + .Configure(ConfigureEchoAddress); + + using (var host = hostBuilder.Build()) + { + host.Start(); + + Assert.Equal(ipv4endPointAddress, await HttpClientSlim.GetStringAsync(ipv4endPointAddress)); + Assert.Equal(ipv6endPointAddress, await HttpClientSlim.GetStringAsync(ipv6endPointAddress)); + } + + hostBuilder = TransportSelector.GetWebHostBuilder() + .ConfigureLogging(_configureLoggingDelegate) + .UseKestrel(options => + { + options.Listen(IPAddress.Loopback, port); + options.Listen(IPAddress.IPv6Loopback, port); + }) + .Configure(ConfigureEchoAddress); + + using (var host = hostBuilder.Build()) + { + host.Start(); + + Assert.Equal(ipv4endPointAddress, await HttpClientSlim.GetStringAsync(ipv4endPointAddress)); + Assert.Equal(ipv6endPointAddress, await HttpClientSlim.GetStringAsync(ipv6endPointAddress)); + } + } + private void ThrowsWhenBindingLocalhostToAddressInUse(AddressFamily addressFamily, IPAddress address) { using (var socket = new Socket(addressFamily, SocketType.Stream, ProtocolType.Tcp)) @@ -533,7 +618,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests socket.Bind(new IPEndPoint(address, 0)); var port = ((IPEndPoint)socket.LocalEndPoint).Port; - var hostBuilder = new WebHostBuilder() + var hostBuilder = TransportSelector.GetWebHostBuilder() .ConfigureLogging(_configureLoggingDelegate) .UseKestrel() .UseUrls($"http://localhost:{port}") @@ -807,6 +892,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests private bool CanBindToPort() { +#if MACOS && SOCKETS + // Binding to a port with a Socket, disposing the Socket, and rebinding often fails with + // SocketError.AddressAlreadyInUse on macOS. This isn't an issue if binding with libuv second. + // https://github.com/dotnet/corefx/issues/24562 + return false; +#else try { using (var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)) @@ -819,6 +910,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { return false; } +#endif } } } diff --git a/test/Kestrel.FunctionalTests/HttpProtocolSelectionTests.cs b/test/Kestrel.FunctionalTests/HttpProtocolSelectionTests.cs index 7b665d5ef1..c2dd742c1d 100644 --- a/test/Kestrel.FunctionalTests/HttpProtocolSelectionTests.cs +++ b/test/Kestrel.FunctionalTests/HttpProtocolSelectionTests.cs @@ -45,7 +45,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests private async Task TestSuccess(HttpProtocols serverProtocols, string request, string expectedResponse) { - var builder = new WebHostBuilder() + var builder = TransportSelector.GetWebHostBuilder() .UseKestrel(options => { options.Listen(IPAddress.Loopback, 0, listenOptions => listenOptions.Protocols = serverProtocols); @@ -73,7 +73,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests .Setup(provider => provider.CreateLogger(It.IsAny())) .Returns(logger); - var builder = new WebHostBuilder() + var builder = TransportSelector.GetWebHostBuilder() .ConfigureLogging(loggingBuilder => loggingBuilder.AddProvider(loggerProvider.Object)) .UseKestrel(options => options.Listen(IPAddress.Loopback, 0, listenOptions => listenOptions.Protocols = serverProtocols)) .Configure(app => app.Run(context => Task.CompletedTask)); diff --git a/test/Kestrel.FunctionalTests/HttpsTests.cs b/test/Kestrel.FunctionalTests/HttpsTests.cs index 604df5943c..8bc8fb7f60 100644 --- a/test/Kestrel.FunctionalTests/HttpsTests.cs +++ b/test/Kestrel.FunctionalTests/HttpsTests.cs @@ -31,7 +31,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { var loggerProvider = new HandshakeErrorLoggerProvider(); - var hostBuilder = new WebHostBuilder() + var hostBuilder = TransportSelector.GetWebHostBuilder() .UseKestrel(options => { options.Listen(new IPEndPoint(IPAddress.Loopback, 0), listenOptions => @@ -65,7 +65,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { var loggerProvider = new HandshakeErrorLoggerProvider(); - var hostBuilder = new WebHostBuilder() + var hostBuilder = TransportSelector.GetWebHostBuilder() .UseKestrel(options => { options.Listen(new IPEndPoint(IPAddress.Loopback, 0), listenOptions => @@ -101,7 +101,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests public async Task DoesNotThrowObjectDisposedExceptionOnConnectionAbort() { var loggerProvider = new HandshakeErrorLoggerProvider(); - var hostBuilder = new WebHostBuilder() + var hostBuilder = TransportSelector.GetWebHostBuilder() .UseKestrel(options => { options.Listen(new IPEndPoint(IPAddress.Loopback, 0), listenOptions => @@ -153,7 +153,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { var tcs = new TaskCompletionSource(); var loggerProvider = new HandshakeErrorLoggerProvider(); - var hostBuilder = new WebHostBuilder() + var hostBuilder = TransportSelector.GetWebHostBuilder() .UseKestrel(options => { options.Listen(new IPEndPoint(IPAddress.Loopback, 0), listenOptions => @@ -202,7 +202,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests public async Task DoesNotThrowObjectDisposedExceptionOnEmptyConnection() { var loggerProvider = new HandshakeErrorLoggerProvider(); - var hostBuilder = new WebHostBuilder() + var hostBuilder = TransportSelector.GetWebHostBuilder() .UseKestrel(options => { options.Listen(new IPEndPoint(IPAddress.Loopback, 0), listenOptions => @@ -236,7 +236,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { var loggerProvider = new HandshakeErrorLoggerProvider(); - var hostBuilder = new WebHostBuilder() + var hostBuilder = TransportSelector.GetWebHostBuilder() .UseKestrel(options => { options.Listen(new IPEndPoint(IPAddress.Loopback, 0), listenOptions => @@ -265,7 +265,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests public async Task HandshakeTimesOutAndIsLoggedAsInformation() { var loggerProvider = new HandshakeErrorLoggerProvider(); - var hostBuilder = new WebHostBuilder() + var hostBuilder = TransportSelector.GetWebHostBuilder() .UseKestrel(options => { options.Listen(new IPEndPoint(IPAddress.Loopback, 0), listenOptions => diff --git a/test/Kestrel.FunctionalTests/LoggingConnectionAdapterTests.cs b/test/Kestrel.FunctionalTests/LoggingConnectionAdapterTests.cs index 24e72aa336..12f7e604e3 100644 --- a/test/Kestrel.FunctionalTests/LoggingConnectionAdapterTests.cs +++ b/test/Kestrel.FunctionalTests/LoggingConnectionAdapterTests.cs @@ -26,7 +26,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [Fact] public async Task LoggingConnectionAdapterCanBeAddedBeforeAndAfterHttpsAdapter() { - var host = new WebHostBuilder() + var host = TransportSelector.GetWebHostBuilder() .ConfigureLogging(builder => { builder.SetMinimumLevel(LogLevel.Trace); diff --git a/test/Kestrel.FunctionalTests/MaxRequestBufferSizeTests.cs b/test/Kestrel.FunctionalTests/MaxRequestBufferSizeTests.cs index 9cda0bbde0..79cdee5295 100644 --- a/test/Kestrel.FunctionalTests/MaxRequestBufferSizeTests.cs +++ b/test/Kestrel.FunctionalTests/MaxRequestBufferSizeTests.cs @@ -258,7 +258,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests TaskCompletionSource startReadingRequestBody, TaskCompletionSource clientFinishedSendingRequestBody) { - var host = new WebHostBuilder() + var host = TransportSelector.GetWebHostBuilder() .ConfigureLogging(_configureLoggingDelegate) .UseKestrel(options => { diff --git a/test/Kestrel.FunctionalTests/RequestTests.cs b/test/Kestrel.FunctionalTests/RequestTests.cs index 1362651bde..46933f4275 100644 --- a/test/Kestrel.FunctionalTests/RequestTests.cs +++ b/test/Kestrel.FunctionalTests/RequestTests.cs @@ -69,7 +69,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests Assert.True(contentLength % bufferLength == 0, $"{nameof(contentLength)} sent must be evenly divisible by {bufferLength}."); Assert.True(bufferLength % 256 == 0, $"{nameof(bufferLength)} must be evenly divisible by 256"); - var builder = new WebHostBuilder() + var builder = TransportSelector.GetWebHostBuilder() .UseKestrel(options => { options.Limits.MaxRequestBodySize = contentLength; @@ -155,7 +155,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [Fact] public async Task DoesNotHangOnConnectionCloseRequest() { - var builder = new WebHostBuilder() + var builder = TransportSelector.GetWebHostBuilder() .UseKestrel() .UseUrls("http://127.0.0.1:0") .Configure(app => @@ -185,7 +185,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests var requestBodyPersisted = false; var responseBodyPersisted = false; - var builder = new WebHostBuilder() + var builder = TransportSelector.GetWebHostBuilder() .UseKestrel() .UseUrls("http://127.0.0.1:0") .Configure(app => @@ -228,7 +228,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests public void CanUpgradeRequestWithConnectionKeepAliveUpgradeHeader() { var dataRead = false; - var builder = new WebHostBuilder() + var builder = TransportSelector.GetWebHostBuilder() .UseKestrel() .UseUrls("http://127.0.0.1:0") .Configure(app => @@ -300,7 +300,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests .Setup(factory => factory.CreateLogger(It.IsAny())) .Returns(Mock.Of()); mockLoggerFactory - .Setup(factory => factory.CreateLogger(It.IsIn("Microsoft.AspNetCore.Server.Kestrel", "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv"))) + .Setup(factory => factory.CreateLogger(It.IsIn("Microsoft.AspNetCore.Server.Kestrel", + "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv", + "Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets"))) .Returns(mockLogger.Object); using (var server = new TestServer(context => Task.CompletedTask, new TestServiceContext(mockLoggerFactory.Object))) @@ -354,7 +356,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests .Setup(factory => factory.CreateLogger(It.IsAny())) .Returns(Mock.Of()); mockLoggerFactory - .Setup(factory => factory.CreateLogger(It.IsIn("Microsoft.AspNetCore.Server.Kestrel", "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv"))) + .Setup(factory => factory.CreateLogger(It.IsIn("Microsoft.AspNetCore.Server.Kestrel", + "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv", + "Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets"))) .Returns(mockLogger.Object); using (var server = new TestServer(context => Task.CompletedTask, new TestServiceContext(mockLoggerFactory.Object))) @@ -424,7 +428,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests .Setup(factory => factory.CreateLogger(It.IsAny())) .Returns(Mock.Of()); mockLoggerFactory - .Setup(factory => factory.CreateLogger(It.IsIn("Microsoft.AspNetCore.Server.Kestrel", "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv"))) + .Setup(factory => factory.CreateLogger(It.IsIn("Microsoft.AspNetCore.Server.Kestrel", + "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv", + "Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets"))) .Returns(mockLogger.Object); using (var server = new TestServer(async context => @@ -464,7 +470,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests var appDone = new SemaphoreSlim(0); var expectedExceptionThrown = false; - var builder = new WebHostBuilder() + var builder = TransportSelector.GetWebHostBuilder() .UseKestrel() .UseUrls("http://127.0.0.1:0") .Configure(app => app.Run(async context => @@ -508,7 +514,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { var appStarted = new SemaphoreSlim(0); var requestAborted = new SemaphoreSlim(0); - var builder = new WebHostBuilder() + var builder = TransportSelector.GetWebHostBuilder() .UseKestrel() .UseUrls("http://127.0.0.1:0") .Configure(app => app.Run(async context => @@ -538,7 +544,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [Fact] public void AbortingTheConnectionSendsFIN() { - var builder = new WebHostBuilder() + var builder = TransportSelector.GetWebHostBuilder() .UseKestrel() .UseUrls("http://127.0.0.1:0") .Configure(app => app.Run(context => @@ -1617,7 +1623,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests private async Task TestRemoteIPAddress(string registerAddress, string requestAddress, string expectAddress) { - var builder = new WebHostBuilder() + var builder = TransportSelector.GetWebHostBuilder() .UseKestrel() .UseUrls($"http://{registerAddress}:0") .Configure(app => diff --git a/test/Kestrel.FunctionalTests/ResponseTests.cs b/test/Kestrel.FunctionalTests/ResponseTests.cs index d19ffbfb14..7879e4d727 100644 --- a/test/Kestrel.FunctionalTests/ResponseTests.cs +++ b/test/Kestrel.FunctionalTests/ResponseTests.cs @@ -49,7 +49,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [Fact] public async Task LargeDownload() { - var hostBuilder = new WebHostBuilder() + var hostBuilder = TransportSelector.GetWebHostBuilder() .UseKestrel() .UseUrls("http://127.0.0.1:0/") .Configure(app => @@ -101,7 +101,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [Theory, MemberData(nameof(NullHeaderData))] public async Task IgnoreNullHeaderValues(string headerName, StringValues headerValue, string expectedValue) { - var hostBuilder = new WebHostBuilder() + var hostBuilder = TransportSelector.GetWebHostBuilder() .UseKestrel() .UseUrls("http://127.0.0.1:0/") .Configure(app => @@ -144,7 +144,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests var onStartingCalled = false; var onCompletedCalled = false; - var hostBuilder = new WebHostBuilder() + var hostBuilder = TransportSelector.GetWebHostBuilder() .UseKestrel() .UseUrls("http://127.0.0.1:0/") .Configure(app => @@ -179,7 +179,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { InvalidOperationException ex = null; - var hostBuilder = new WebHostBuilder() + var hostBuilder = TransportSelector.GetWebHostBuilder() .UseKestrel() .UseUrls("http://127.0.0.1:0/") .Configure(app => @@ -2506,6 +2506,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests totalReceived += received; } while (received > 0 && totalReceived < responseSize); } + catch (SocketException) { } catch (IOException) { // Socket.Receive could throw, and that is fine diff --git a/test/Kestrel.FunctionalTests/TestHelpers/TestServer.cs b/test/Kestrel.FunctionalTests/TestHelpers/TestServer.cs index 5e36ddf4af..f0972bb4fd 100644 --- a/test/Kestrel.FunctionalTests/TestHelpers/TestServer.cs +++ b/test/Kestrel.FunctionalTests/TestHelpers/TestServer.cs @@ -48,7 +48,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests _listenOptions = listenOptions; Context = context; - _host = new WebHostBuilder() + _host = TransportSelector.GetWebHostBuilder() .UseKestrel(o => { o.ListenOptions.Add(_listenOptions); diff --git a/test/Kestrel.FunctionalTests/ThreadCountTests.cs b/test/Kestrel.FunctionalTests/ThreadCountTests.cs deleted file mode 100644 index 67f5cbafbb..0000000000 --- a/test/Kestrel.FunctionalTests/ThreadCountTests.cs +++ /dev/null @@ -1,72 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System.Collections.Generic; -using System.Net.Http; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Builder; -using Microsoft.AspNetCore.Hosting; -using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Testing.xunit; -using Xunit; - -namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests -{ - public class ThreadCountTests - { - [ConditionalTheory] - [MemberData(nameof(OneToTen))] - [OSSkipCondition(OperatingSystems.MacOSX, SkipReason = "Tests fail on OS X due to low file descriptor limit.")] - public async Task OneToTenThreads(int threadCount) - { - var hostBuilder = new WebHostBuilder() - .UseKestrel() - .UseLibuv(options => - { - options.ThreadCount = threadCount; - }) - .UseUrls("http://127.0.0.1:0/") - .Configure(app => - { - app.Run(context => - { - return context.Response.WriteAsync("Hello World"); - }); - }); - - using (var host = hostBuilder.Build()) - { - host.Start(); - - using (var client = new HttpClient()) - { - // Send 20 requests just to make sure we don't get any failures - var requestTasks = new List>(); - for (int i = 0; i < 20; i++) - { - var requestTask = client.GetStringAsync($"http://127.0.0.1:{host.GetPort()}/"); - requestTasks.Add(requestTask); - } - - foreach (var result in await Task.WhenAll(requestTasks)) - { - Assert.Equal("Hello World", result); - } - } - } - } - - public static TheoryData OneToTen - { - get - { - var dataset = new TheoryData(); - for (int i = 1; i <= 10; i++) - { - dataset.Add(i); - } - return dataset; - } - } - } -} diff --git a/test/Kestrel.FunctionalTests/Kestrel.FunctionalTests.csproj b/test/Kestrel.Transport.Libuv.FunctionalTests/Kestrel.Trasnport.Libuv.FunctionalTests.csproj similarity index 76% rename from test/Kestrel.FunctionalTests/Kestrel.FunctionalTests.csproj rename to test/Kestrel.Transport.Libuv.FunctionalTests/Kestrel.Trasnport.Libuv.FunctionalTests.csproj index 3ed0a438b9..b4c4d93b69 100644 --- a/test/Kestrel.FunctionalTests/Kestrel.FunctionalTests.csproj +++ b/test/Kestrel.Transport.Libuv.FunctionalTests/Kestrel.Trasnport.Libuv.FunctionalTests.csproj @@ -1,8 +1,8 @@  - Microsoft.AspNetCore.Server.Kestrel.FunctionalTests - Microsoft.AspNetCore.Server.Kestrel.FunctionalTests + Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.FunctionalTests + Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.FunctionalTests netcoreapp2.0;net461 netcoreapp2.0 $(DefineConstants);MACOS @@ -11,6 +11,7 @@ + @@ -20,6 +21,7 @@ + diff --git a/test/Kestrel.FunctionalTests/ListenHandleTests.cs b/test/Kestrel.Transport.Libuv.FunctionalTests/ListenHandleTests.cs similarity index 100% rename from test/Kestrel.FunctionalTests/ListenHandleTests.cs rename to test/Kestrel.Transport.Libuv.FunctionalTests/ListenHandleTests.cs diff --git a/test/Kestrel.Transport.Libuv.FunctionalTests/TransportSelector.cs b/test/Kestrel.Transport.Libuv.FunctionalTests/TransportSelector.cs new file mode 100644 index 0000000000..cba3395d11 --- /dev/null +++ b/test/Kestrel.Transport.Libuv.FunctionalTests/TransportSelector.cs @@ -0,0 +1,15 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using Microsoft.AspNetCore.Hosting; + +namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests +{ + public static class TransportSelector + { + public static IWebHostBuilder GetWebHostBuilder() + { + return new WebHostBuilder().UseLibuv(); + } + } +} diff --git a/test/Kestrel.Transport.Libuv.Tests/LibuvTransportTests.cs b/test/Kestrel.Transport.Libuv.Tests/LibuvTransportTests.cs index d3739ae07f..f62a792b85 100644 --- a/test/Kestrel.Transport.Libuv.Tests/LibuvTransportTests.cs +++ b/test/Kestrel.Transport.Libuv.Tests/LibuvTransportTests.cs @@ -1,7 +1,10 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System.Collections.Generic; +using System.Linq; using System.Net; +using System.Net.Http; using System.Net.Sockets; using System.Text; using System.Threading.Tasks; @@ -10,6 +13,7 @@ using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal; using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests.TestHelpers; using Microsoft.AspNetCore.Testing; +using Microsoft.AspNetCore.Testing.xunit; using Xunit; namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests @@ -25,6 +29,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests } }; + public static IEnumerable OneToTen => Enumerable.Range(1, 10).Select(i => new object[] { i }); + [Fact] public async Task TransportCanBindAndStop() { @@ -80,5 +86,49 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests await transport.UnbindAsync(); await transport.StopAsync(); } + + [ConditionalTheory] + [MemberData(nameof(OneToTen))] + [OSSkipCondition(OperatingSystems.MacOSX, SkipReason = "Tests fail on OS X due to low file descriptor limit.")] + public async Task OneToTenThreads(int threadCount) + { + var listenOptions = new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0)); + var serviceContext = new TestServiceContext(); + var testApplication = new DummyApplication(context => + { + return context.Response.WriteAsync("Hello World"); + }); + + listenOptions.UseHttpServer(listenOptions.ConnectionAdapters, serviceContext, testApplication, HttpProtocols.Http1); + + var transportContext = new TestLibuvTransportContext() + { + ConnectionHandler = new ConnectionHandler(serviceContext, listenOptions.Build()), + Options = new LibuvTransportOptions { ThreadCount = threadCount } + }; + + var transport = new LibuvTransport(transportContext, listenOptions); + + await transport.BindAsync(); + + using (var client = new HttpClient()) + { + // Send 20 requests just to make sure we don't get any failures + var requestTasks = new List>(); + for (int i = 0; i < 20; i++) + { + var requestTask = client.GetStringAsync($"http://127.0.0.1:{listenOptions.IPEndPoint.Port}/"); + requestTasks.Add(requestTask); + } + + foreach (var result in await Task.WhenAll(requestTasks)) + { + Assert.Equal("Hello World", result); + } + } + + await transport.UnbindAsync(); + await transport.StopAsync(); + } } } diff --git a/test/Kestrel.Transport.Sockets.FunctionalTests/Kestrel.Trasnport.Sockets.FunctionalTests.csproj b/test/Kestrel.Transport.Sockets.FunctionalTests/Kestrel.Trasnport.Sockets.FunctionalTests.csproj new file mode 100644 index 0000000000..8030d18468 --- /dev/null +++ b/test/Kestrel.Transport.Sockets.FunctionalTests/Kestrel.Trasnport.Sockets.FunctionalTests.csproj @@ -0,0 +1,36 @@ + + + + Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.FunctionalTests + Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.FunctionalTests + netcoreapp2.0;net461 + netcoreapp2.0 + $(DefineConstants);MACOS + $(DefineConstants);SOCKETS + true + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/Kestrel.Transport.Sockets.FunctionalTests/TransportSelector.cs b/test/Kestrel.Transport.Sockets.FunctionalTests/TransportSelector.cs new file mode 100644 index 0000000000..1a433cc9ec --- /dev/null +++ b/test/Kestrel.Transport.Sockets.FunctionalTests/TransportSelector.cs @@ -0,0 +1,15 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using Microsoft.AspNetCore.Hosting; + +namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests +{ + public static class TransportSelector + { + public static IWebHostBuilder GetWebHostBuilder() + { + return new WebHostBuilder().UseSockets(); + } + } +} diff --git a/test/Kestrel.FunctionalTests/SystemdActivation/Dockerfile b/test/SystemdActivation/Dockerfile similarity index 100% rename from test/Kestrel.FunctionalTests/SystemdActivation/Dockerfile rename to test/SystemdActivation/Dockerfile diff --git a/test/Kestrel.FunctionalTests/SystemdActivation/docker-entrypoint.sh b/test/SystemdActivation/docker-entrypoint.sh similarity index 100% rename from test/Kestrel.FunctionalTests/SystemdActivation/docker-entrypoint.sh rename to test/SystemdActivation/docker-entrypoint.sh diff --git a/test/Kestrel.FunctionalTests/SystemdActivation/docker.sh b/test/SystemdActivation/docker.sh old mode 100755 new mode 100644 similarity index 100% rename from test/Kestrel.FunctionalTests/SystemdActivation/docker.sh rename to test/SystemdActivation/docker.sh From deed6c9780964bf5ec96ed6a77bedd1bd4e6d239 Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Thu, 12 Oct 2017 11:23:57 -0700 Subject: [PATCH 1428/1662] HTTP/2: add exception error messages and log them. --- .../Kestrel.Performance/Mocks/MockTrace.cs | 5 + src/Kestrel.Core/CoreStrings.resx | 134 +++-- .../Internal/Http2/Http2Connection.cs | 152 +++--- .../Http2/Http2ConnectionErrorException.cs | 4 +- .../Http2/Http2StreamErrorException.cs | 4 +- .../Internal/Infrastructure/IKestrelTrace.cs | 10 +- .../Internal/Infrastructure/KestrelTrace.cs | 26 + .../Properties/CoreStrings.Designer.cs | 364 ++++++++++++++ .../Http2ConnectionTests.cs | 469 ++++++++++++++---- 9 files changed, 979 insertions(+), 189 deletions(-) diff --git a/benchmarks/Kestrel.Performance/Mocks/MockTrace.cs b/benchmarks/Kestrel.Performance/Mocks/MockTrace.cs index 77290ee718..fef2b970f1 100644 --- a/benchmarks/Kestrel.Performance/Mocks/MockTrace.cs +++ b/benchmarks/Kestrel.Performance/Mocks/MockTrace.cs @@ -3,6 +3,8 @@ using System; using Microsoft.AspNetCore.Server.Kestrel.Core; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2.HPack; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; using Microsoft.Extensions.Logging; @@ -40,5 +42,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance public void RequestBodyDone(string connectionId, string traceIdentifier) { } public void RequestBodyMininumDataRateNotSatisfied(string connectionId, string traceIdentifier, double rate) { } public void ResponseMininumDataRateNotSatisfied(string connectionId, string traceIdentifier) { } + public void Http2ConnectionError(string connectionId, Http2ConnectionErrorException ex) { } + public void Http2StreamError(string connectionId, Http2StreamErrorException ex) { } + public void HPackDecodingError(string connectionId, int streamId, HPackDecodingException ex) { } } } diff --git a/src/Kestrel.Core/CoreStrings.resx b/src/Kestrel.Core/CoreStrings.resx index 7127c41905..fdbebb8aaf 100644 --- a/src/Kestrel.Core/CoreStrings.resx +++ b/src/Kestrel.Core/CoreStrings.resx @@ -1,17 +1,17 @@  - @@ -384,4 +384,82 @@ The header block was incomplete and could not be fully decoded. - \ No newline at end of file + + The client sent a {frameType} frame with even stream ID {streamId}. + + + The client sent a A PUSH_PROMISE frame. + + + The client sent a {frameType} frame to stream ID {streamId} before signaling of the header block for stream ID {headersStreamId}. + + + The client sent a {frameType} frame with stream ID 0. + + + The client sent a {frameType} frame with stream ID different than 0. + + + The client sent a {frameType} frame with padding longer than or with the same length as the sent data. + + + The client sent a {frameType} frame to closed stream ID {streamId}. + + + The client sent a {frameType} frame to stream ID {streamId} which is in the "half-closed (remote) state". + + + The client sent a {frameType} frame with dependency information that would cause stream ID {streamId} to depend on itself. + + + The client sent a {frameType} frame with length different than {expectedLength}. + + + The client sent a SETTINGS frame with a length that is not a multiple of 6. + + + The client sent a SETTINGS frame with ACK set and length different than 0. + + + The client sent a SETTINGS frame with a value for parameter {parameter} that is out of range. + + + The client sent a WINDOW_UPDATE frame with a window size increment of 0. + + + The client sent a CONTINUATION frame not preceded by a HEADERS frame. + + + The client sent a {frameType} frame to idle stream ID {streamId}. + + + The client sent trailers containing one or more pseudo-header fields. + + + The client sent a header with uppercase characters in its name. + + + The client sent a trailer with uppercase characters in its name. + + + The client sent a HEADERS frame containing trailers without setting the END_STREAM flag. + + + Request headers missing one or more mandatory pseudo-header fields. + + + Pseudo-header field found in request headers after regular header fields. + + + Request headers contain unknown pseudo-header field. + + + Request headers contain response-specific pseudo-header field. + + + Request headers contain duplicate pseudo-header field. + + + Request headers contain connection-specific header field. + + diff --git a/src/Kestrel.Core/Internal/Http2/Http2Connection.cs b/src/Kestrel.Core/Internal/Http2/Http2Connection.cs index 50e023196d..40d35ebee3 100644 --- a/src/Kestrel.Core/Internal/Http2/Http2Connection.cs +++ b/src/Kestrel.Core/Internal/Http2/Http2Connection.cs @@ -166,28 +166,33 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 } } } - catch (ConnectionAbortedException ex) + catch (ConnectionResetException ex) { - // TODO: log + // Don't log ECONNRESET errors when there are no active streams on the connection. Browsers like IE will reset connections regularly. + if (_streams.Count > 0) + { + Log.RequestProcessingError(ConnectionId, ex); + } + error = ex; } catch (Http2ConnectionErrorException ex) { - // TODO: log + Log.Http2ConnectionError(ConnectionId, ex); error = ex; errorCode = ex.ErrorCode; } catch (HPackDecodingException ex) { - // TODO: log + Log.HPackDecodingError(ConnectionId, _currentHeadersStream.StreamId, ex); error = ex; errorCode = Http2ErrorCode.COMPRESSION_ERROR; } catch (Exception ex) { - // TODO: log error = ex; errorCode = Http2ErrorCode.INTERNAL_ERROR; + throw; } finally { @@ -242,7 +247,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 // a connection error (Section 5.4.1) of type PROTOCOL_ERROR. if (_incomingFrame.StreamId != 0 && (_incomingFrame.StreamId & 1) == 0) { - throw new Http2ConnectionErrorException(Http2ErrorCode.PROTOCOL_ERROR); + throw new Http2ConnectionErrorException(CoreStrings.FormatHttp2ErrorStreamIdEven(_incomingFrame.Type, _incomingFrame.StreamId), Http2ErrorCode.PROTOCOL_ERROR); } switch (_incomingFrame.Type) @@ -258,7 +263,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 case Http2FrameType.SETTINGS: return ProcessSettingsFrameAsync(); case Http2FrameType.PUSH_PROMISE: - throw new Http2ConnectionErrorException(Http2ErrorCode.PROTOCOL_ERROR); + throw new Http2ConnectionErrorException(CoreStrings.Http2ErrorPushPromiseReceived, Http2ErrorCode.PROTOCOL_ERROR); case Http2FrameType.PING: return ProcessPingFrameAsync(); case Http2FrameType.GOAWAY: @@ -276,35 +281,39 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 { if (_currentHeadersStream != null) { - throw new Http2ConnectionErrorException(Http2ErrorCode.PROTOCOL_ERROR); + throw new Http2ConnectionErrorException(CoreStrings.FormatHttp2ErrorHeadersInterleaved(_incomingFrame.Type, _incomingFrame.StreamId, _currentHeadersStream.StreamId), Http2ErrorCode.PROTOCOL_ERROR); } if (_incomingFrame.StreamId == 0) { - throw new Http2ConnectionErrorException(Http2ErrorCode.PROTOCOL_ERROR); + throw new Http2ConnectionErrorException(CoreStrings.FormatHttp2ErrorStreamIdZero(_incomingFrame.Type), Http2ErrorCode.PROTOCOL_ERROR); } if (_incomingFrame.DataHasPadding && _incomingFrame.DataPadLength >= _incomingFrame.Length) { - throw new Http2ConnectionErrorException(Http2ErrorCode.PROTOCOL_ERROR); + throw new Http2ConnectionErrorException(CoreStrings.FormatHttp2ErrorPaddingTooLong(_incomingFrame.Type), Http2ErrorCode.PROTOCOL_ERROR); } ThrowIfIncomingFrameSentToIdleStream(); - if (_streams.TryGetValue(_incomingFrame.StreamId, out var stream) && !stream.EndStreamReceived) + if (_streams.TryGetValue(_incomingFrame.StreamId, out var stream)) { + if (stream.EndStreamReceived) + { + // http://httpwg.org/specs/rfc7540.html#rfc.section.5.1 + // + // ...an endpoint that receives any frames after receiving a frame with the + // END_STREAM flag set MUST treat that as a connection error (Section 5.4.1) + // of type STREAM_CLOSED, unless the frame is permitted as described below. + // + // (The allowed frame types for this situation are WINDOW_UPDATE, RST_STREAM and PRIORITY) + throw new Http2ConnectionErrorException(CoreStrings.FormatHttp2ErrorStreamHalfClosedRemote(_incomingFrame.Type, stream.StreamId), Http2ErrorCode.STREAM_CLOSED); + } + return stream.OnDataAsync(_incomingFrame.DataPayload, endStream: (_incomingFrame.DataFlags & Http2DataFrameFlags.END_STREAM) == Http2DataFrameFlags.END_STREAM); } - // http://httpwg.org/specs/rfc7540.html#rfc.section.5.1 - // - // ...an endpoint that receives any frames after receiving a frame with the - // END_STREAM flag set MUST treat that as a connection error (Section 5.4.1) - // of type STREAM_CLOSED, unless the frame is permitted as described below. - // - // (The allowed frame types for this situation are WINDOW_UPDATE, RST_STREAM and PRIORITY) - // // If we couldn't find the stream, it was either alive previously but closed with // END_STREAM or RST_STREAM, or it was implicitly closed when the client opened // a new stream with a higher ID. Per the spec, we should send RST_STREAM if @@ -316,29 +325,29 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 // // We choose to do that here so we don't have to keep state to track implicitly closed // streams vs. streams closed with END_STREAM or RST_STREAM. - throw new Http2ConnectionErrorException(Http2ErrorCode.STREAM_CLOSED); + throw new Http2ConnectionErrorException(CoreStrings.FormatHttp2ErrorStreamClosed(_incomingFrame.Type, _incomingFrame.StreamId), Http2ErrorCode.STREAM_CLOSED); } private async Task ProcessHeadersFrameAsync(IHttpApplication application) { if (_currentHeadersStream != null) { - throw new Http2ConnectionErrorException(Http2ErrorCode.PROTOCOL_ERROR); + throw new Http2ConnectionErrorException(CoreStrings.FormatHttp2ErrorHeadersInterleaved(_incomingFrame.Type, _incomingFrame.StreamId, _currentHeadersStream.StreamId), Http2ErrorCode.PROTOCOL_ERROR); } if (_incomingFrame.StreamId == 0) { - throw new Http2ConnectionErrorException(Http2ErrorCode.PROTOCOL_ERROR); + throw new Http2ConnectionErrorException(CoreStrings.FormatHttp2ErrorStreamIdZero(_incomingFrame.Type), Http2ErrorCode.PROTOCOL_ERROR); } if (_incomingFrame.HeadersHasPadding && _incomingFrame.HeadersPadLength >= _incomingFrame.Length) { - throw new Http2ConnectionErrorException(Http2ErrorCode.PROTOCOL_ERROR); + throw new Http2ConnectionErrorException(CoreStrings.FormatHttp2ErrorPaddingTooLong(_incomingFrame.Type), Http2ErrorCode.PROTOCOL_ERROR); } if (_incomingFrame.HeadersHasPriority && _incomingFrame.HeadersStreamDependency == _incomingFrame.StreamId) { - throw new Http2ConnectionErrorException(Http2ErrorCode.PROTOCOL_ERROR); + throw new Http2ConnectionErrorException(CoreStrings.FormatHttp2ErrorStreamSelfDependency(_incomingFrame.Type, _incomingFrame.StreamId), Http2ErrorCode.PROTOCOL_ERROR); } if (_streams.TryGetValue(_incomingFrame.StreamId, out var stream)) @@ -352,7 +361,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 // (The allowed frame types for this situation are WINDOW_UPDATE, RST_STREAM and PRIORITY) if (stream.EndStreamReceived) { - throw new Http2ConnectionErrorException(Http2ErrorCode.STREAM_CLOSED); + throw new Http2ConnectionErrorException(CoreStrings.FormatHttp2ErrorStreamHalfClosedRemote(_incomingFrame.Type, stream.StreamId), Http2ErrorCode.STREAM_CLOSED); } // TODO: trailers @@ -366,7 +375,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 // // If we couldn't find the stream, it was previously closed (either implicitly or with // END_STREAM or RST_STREAM). - throw new Http2ConnectionErrorException(Http2ErrorCode.STREAM_CLOSED); + throw new Http2ConnectionErrorException(CoreStrings.FormatHttp2ErrorStreamClosed(_incomingFrame.Type, _incomingFrame.StreamId), Http2ErrorCode.STREAM_CLOSED); } else { @@ -400,22 +409,22 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 { if (_currentHeadersStream != null) { - throw new Http2ConnectionErrorException(Http2ErrorCode.PROTOCOL_ERROR); + throw new Http2ConnectionErrorException(CoreStrings.FormatHttp2ErrorHeadersInterleaved(_incomingFrame.Type, _incomingFrame.StreamId, _currentHeadersStream.StreamId), Http2ErrorCode.PROTOCOL_ERROR); } if (_incomingFrame.StreamId == 0) { - throw new Http2ConnectionErrorException(Http2ErrorCode.PROTOCOL_ERROR); + throw new Http2ConnectionErrorException(CoreStrings.FormatHttp2ErrorStreamIdZero(_incomingFrame.Type), Http2ErrorCode.PROTOCOL_ERROR); } if (_incomingFrame.PriorityStreamDependency == _incomingFrame.StreamId) { - throw new Http2ConnectionErrorException(Http2ErrorCode.PROTOCOL_ERROR); + throw new Http2ConnectionErrorException(CoreStrings.FormatHttp2ErrorStreamSelfDependency(_incomingFrame.Type, _incomingFrame.StreamId), Http2ErrorCode.PROTOCOL_ERROR); } if (_incomingFrame.Length != 5) { - throw new Http2ConnectionErrorException(Http2ErrorCode.FRAME_SIZE_ERROR); + throw new Http2ConnectionErrorException(CoreStrings.FormatHttp2ErrorUnexpectedFrameLength(_incomingFrame.Type, 5), Http2ErrorCode.FRAME_SIZE_ERROR); } return Task.CompletedTask; @@ -425,17 +434,17 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 { if (_currentHeadersStream != null) { - throw new Http2ConnectionErrorException(Http2ErrorCode.PROTOCOL_ERROR); + throw new Http2ConnectionErrorException(CoreStrings.FormatHttp2ErrorHeadersInterleaved(_incomingFrame.Type, _incomingFrame.StreamId, _currentHeadersStream.StreamId), Http2ErrorCode.PROTOCOL_ERROR); } if (_incomingFrame.StreamId == 0) { - throw new Http2ConnectionErrorException(Http2ErrorCode.PROTOCOL_ERROR); + throw new Http2ConnectionErrorException(CoreStrings.FormatHttp2ErrorStreamIdZero(_incomingFrame.Type), Http2ErrorCode.PROTOCOL_ERROR); } if (_incomingFrame.Length != 4) { - throw new Http2ConnectionErrorException(Http2ErrorCode.FRAME_SIZE_ERROR); + throw new Http2ConnectionErrorException(CoreStrings.FormatHttp2ErrorUnexpectedFrameLength(_incomingFrame.Type, 4), Http2ErrorCode.FRAME_SIZE_ERROR); } ThrowIfIncomingFrameSentToIdleStream(); @@ -452,22 +461,22 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 { if (_currentHeadersStream != null) { - throw new Http2ConnectionErrorException(Http2ErrorCode.PROTOCOL_ERROR); + throw new Http2ConnectionErrorException(CoreStrings.FormatHttp2ErrorHeadersInterleaved(_incomingFrame.Type, _incomingFrame.StreamId, _currentHeadersStream.StreamId), Http2ErrorCode.PROTOCOL_ERROR); } if (_incomingFrame.StreamId != 0) { - throw new Http2ConnectionErrorException(Http2ErrorCode.PROTOCOL_ERROR); + throw new Http2ConnectionErrorException(CoreStrings.FormatHttp2ErrorStreamIdNotZero(_incomingFrame.Type), Http2ErrorCode.PROTOCOL_ERROR); } if ((_incomingFrame.SettingsFlags & Http2SettingsFrameFlags.ACK) == Http2SettingsFrameFlags.ACK && _incomingFrame.Length != 0) { - throw new Http2ConnectionErrorException(Http2ErrorCode.FRAME_SIZE_ERROR); + throw new Http2ConnectionErrorException(CoreStrings.Http2ErrorSettingsAckLengthNotZero, Http2ErrorCode.FRAME_SIZE_ERROR); } if (_incomingFrame.Length % 6 != 0) { - throw new Http2ConnectionErrorException(Http2ErrorCode.FRAME_SIZE_ERROR); + throw new Http2ConnectionErrorException(CoreStrings.Http2ErrorSettingsLengthNotMultipleOfSix, Http2ErrorCode.FRAME_SIZE_ERROR); } try @@ -477,7 +486,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 } catch (Http2SettingsParameterOutOfRangeException ex) { - throw new Http2ConnectionErrorException(ex.Parameter == Http2SettingsParameter.SETTINGS_INITIAL_WINDOW_SIZE + throw new Http2ConnectionErrorException(CoreStrings.FormatHttp2ErrorSettingsParameterOutOfRange(ex.Parameter), ex.Parameter == Http2SettingsParameter.SETTINGS_INITIAL_WINDOW_SIZE ? Http2ErrorCode.FLOW_CONTROL_ERROR : Http2ErrorCode.PROTOCOL_ERROR); } @@ -487,21 +496,22 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 { if (_currentHeadersStream != null) { - throw new Http2ConnectionErrorException(Http2ErrorCode.PROTOCOL_ERROR); + throw new Http2ConnectionErrorException(CoreStrings.FormatHttp2ErrorHeadersInterleaved(_incomingFrame.Type, _incomingFrame.StreamId, _currentHeadersStream.StreamId), Http2ErrorCode.PROTOCOL_ERROR); } if (_incomingFrame.StreamId != 0) { - throw new Http2ConnectionErrorException(Http2ErrorCode.PROTOCOL_ERROR); + throw new Http2ConnectionErrorException(CoreStrings.FormatHttp2ErrorStreamIdNotZero(_incomingFrame.Type), Http2ErrorCode.PROTOCOL_ERROR); } if (_incomingFrame.Length != 8) { - throw new Http2ConnectionErrorException(Http2ErrorCode.FRAME_SIZE_ERROR); + throw new Http2ConnectionErrorException(CoreStrings.FormatHttp2ErrorUnexpectedFrameLength(_incomingFrame.Type, 8), Http2ErrorCode.FRAME_SIZE_ERROR); } if ((_incomingFrame.PingFlags & Http2PingFrameFlags.ACK) == Http2PingFrameFlags.ACK) { + // TODO: verify that payload is equal to the outgoing PING frame return Task.CompletedTask; } @@ -512,12 +522,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 { if (_currentHeadersStream != null) { - throw new Http2ConnectionErrorException(Http2ErrorCode.PROTOCOL_ERROR); + throw new Http2ConnectionErrorException(CoreStrings.FormatHttp2ErrorHeadersInterleaved(_incomingFrame.Type, _incomingFrame.StreamId, _currentHeadersStream.StreamId), Http2ErrorCode.PROTOCOL_ERROR); } if (_incomingFrame.StreamId != 0) { - throw new Http2ConnectionErrorException(Http2ErrorCode.PROTOCOL_ERROR); + throw new Http2ConnectionErrorException(CoreStrings.FormatHttp2ErrorStreamIdNotZero(_incomingFrame.Type), Http2ErrorCode.PROTOCOL_ERROR); } Stop(); @@ -528,26 +538,34 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 { if (_currentHeadersStream != null) { - throw new Http2ConnectionErrorException(Http2ErrorCode.PROTOCOL_ERROR); + throw new Http2ConnectionErrorException(CoreStrings.FormatHttp2ErrorHeadersInterleaved(_incomingFrame.Type, _incomingFrame.StreamId, _currentHeadersStream.StreamId), Http2ErrorCode.PROTOCOL_ERROR); } if (_incomingFrame.Length != 4) { - throw new Http2ConnectionErrorException(Http2ErrorCode.FRAME_SIZE_ERROR); + throw new Http2ConnectionErrorException(CoreStrings.FormatHttp2ErrorUnexpectedFrameLength(_incomingFrame.Type, 4), Http2ErrorCode.FRAME_SIZE_ERROR); } ThrowIfIncomingFrameSentToIdleStream(); if (_incomingFrame.WindowUpdateSizeIncrement == 0) { - if (_incomingFrame.StreamId == 0) - { - throw new Http2ConnectionErrorException(Http2ErrorCode.PROTOCOL_ERROR); - } - else - { - return _frameWriter.WriteRstStreamAsync(_incomingFrame.StreamId, Http2ErrorCode.PROTOCOL_ERROR); - } + // http://httpwg.org/specs/rfc7540.html#rfc.section.6.9 + // A receiver MUST treat the receipt of a WINDOW_UPDATE + // frame with an flow-control window increment of 0 as a + // stream error (Section 5.4.2) of type PROTOCOL_ERROR; + // errors on the connection flow-control window MUST be + // treated as a connection error (Section 5.4.1). + // + // http://httpwg.org/specs/rfc7540.html#rfc.section.5.4.1 + // An endpoint can end a connection at any time. In + // particular, an endpoint MAY choose to treat a stream + // error as a connection error. + // + // Since server initiated stream resets are not yet properly + // implemented and tested, we treat all zero length window + // increments as connection errors for now. + throw new Http2ConnectionErrorException(CoreStrings.Http2ErrorWindowUpdateIncrementZero, Http2ErrorCode.PROTOCOL_ERROR); } return Task.CompletedTask; @@ -555,9 +573,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 private Task ProcessContinuationFrameAsync(IHttpApplication application) { - if (_currentHeadersStream == null || _incomingFrame.StreamId != _currentHeadersStream.StreamId) + if (_currentHeadersStream == null) { - throw new Http2ConnectionErrorException(Http2ErrorCode.PROTOCOL_ERROR); + throw new Http2ConnectionErrorException(CoreStrings.Http2ErrorContinuationWithNoHeaders, Http2ErrorCode.PROTOCOL_ERROR); + } + + if (_incomingFrame.StreamId != _currentHeadersStream.StreamId) + { + throw new Http2ConnectionErrorException(CoreStrings.FormatHttp2ErrorHeadersInterleaved(_incomingFrame.Type, _incomingFrame.StreamId, _currentHeadersStream.StreamId), Http2ErrorCode.PROTOCOL_ERROR); } var endHeaders = (_incomingFrame.ContinuationFlags & Http2ContinuationFrameFlags.END_HEADERS) == Http2ContinuationFrameFlags.END_HEADERS; @@ -569,7 +592,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 { if (_currentHeadersStream != null) { - throw new Http2ConnectionErrorException(Http2ErrorCode.PROTOCOL_ERROR); + throw new Http2ConnectionErrorException(CoreStrings.FormatHttp2ErrorHeadersInterleaved(_incomingFrame.Type, _incomingFrame.StreamId, _currentHeadersStream.StreamId), Http2ErrorCode.PROTOCOL_ERROR); } return Task.CompletedTask; @@ -589,6 +612,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 } catch (Http2StreamErrorException ex) { + Log.Http2StreamError(ConnectionId, ex); ResetRequestHeaderParsingState(); return _frameWriter.WriteRstStreamAsync(ex.StreamId, ex.ErrorCode); } @@ -603,7 +627,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 // All HTTP/2 requests MUST include exactly one valid value for the :method, :scheme, and :path pseudo-header // fields, unless it is a CONNECT request (Section 8.3). An HTTP request that omits mandatory pseudo-header // fields is malformed (Section 8.1.2.6). - throw new Http2StreamErrorException(_currentHeadersStream.StreamId, Http2ErrorCode.PROTOCOL_ERROR); + throw new Http2StreamErrorException(_currentHeadersStream.StreamId, CoreStrings.Http2ErrorMissingMandatoryPseudoHeaderFields, Http2ErrorCode.PROTOCOL_ERROR); } _streams[_incomingFrame.StreamId] = _currentHeadersStream; @@ -638,7 +662,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 // initial state for all streams. if (_incomingFrame.StreamId > _highestOpenedStreamId) { - throw new Http2ConnectionErrorException(Http2ErrorCode.PROTOCOL_ERROR); + throw new Http2ConnectionErrorException(CoreStrings.FormatHttp2ErrorStreamIdle(_incomingFrame.Type, _incomingFrame.StreamId), Http2ErrorCode.PROTOCOL_ERROR); } } @@ -666,7 +690,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 // All pseudo-header fields MUST appear in the header block before regular header fields. // Any request or response that contains a pseudo-header field that appears in a header // block after a regular header field MUST be treated as malformed (Section 8.1.2.6). - throw new Http2StreamErrorException(_currentHeadersStream.StreamId, Http2ErrorCode.PROTOCOL_ERROR); + throw new Http2StreamErrorException(_currentHeadersStream.StreamId, CoreStrings.Http2ErrorPseudoHeaderFieldAfterRegularHeaders, Http2ErrorCode.PROTOCOL_ERROR); } _requestHeaderParsingState = RequestHeaderParsingState.PseudoHeaderFields; @@ -675,21 +699,21 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 { // Endpoints MUST treat a request or response that contains undefined or invalid pseudo-header // fields as malformed (Section 8.1.2.6). - throw new Http2StreamErrorException(_currentHeadersStream.StreamId, Http2ErrorCode.PROTOCOL_ERROR); + throw new Http2StreamErrorException(_currentHeadersStream.StreamId, CoreStrings.Http2ErrorUnknownPseudoHeaderField, Http2ErrorCode.PROTOCOL_ERROR); } if (headerField == PseudoHeaderFields.Status) { // Pseudo-header fields defined for requests MUST NOT appear in responses; pseudo-header fields // defined for responses MUST NOT appear in requests. - throw new Http2StreamErrorException(_currentHeadersStream.StreamId, Http2ErrorCode.PROTOCOL_ERROR); + throw new Http2StreamErrorException(_currentHeadersStream.StreamId, CoreStrings.Http2ErrorResponsePseudoHeaderField, Http2ErrorCode.PROTOCOL_ERROR); } if ((_parsedPseudoHeaderFields & headerField) == headerField) { // http://httpwg.org/specs/rfc7540.html#rfc.section.8.1.2.3 // All HTTP/2 requests MUST include exactly one valid value for the :method, :scheme, and :path pseudo-header fields - throw new Http2StreamErrorException(_currentHeadersStream.StreamId, Http2ErrorCode.PROTOCOL_ERROR); + throw new Http2StreamErrorException(_currentHeadersStream.StreamId, CoreStrings.Http2ErrorDuplicatePseudoHeaderField, Http2ErrorCode.PROTOCOL_ERROR); } if (headerField == PseudoHeaderFields.Method) @@ -706,7 +730,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 if (IsConnectionSpecificHeaderField(name, value)) { - throw new Http2StreamErrorException(_currentHeadersStream.StreamId, Http2ErrorCode.PROTOCOL_ERROR); + throw new Http2StreamErrorException(_currentHeadersStream.StreamId, CoreStrings.Http2ErrorConnectionSpecificHeaderField, Http2ErrorCode.PROTOCOL_ERROR); } // http://httpwg.org/specs/rfc7540.html#rfc.section.8.1.2 @@ -715,7 +739,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 { if (name[i] >= 65 && name[i] <= 90) { - throw new Http2StreamErrorException(_currentHeadersStream.StreamId, Http2ErrorCode.PROTOCOL_ERROR); + throw new Http2StreamErrorException(_currentHeadersStream.StreamId, CoreStrings.Http2ErrorHeaderNameUppercase, Http2ErrorCode.PROTOCOL_ERROR); } } } diff --git a/src/Kestrel.Core/Internal/Http2/Http2ConnectionErrorException.cs b/src/Kestrel.Core/Internal/Http2/Http2ConnectionErrorException.cs index b1b9136774..dd1314b1a5 100644 --- a/src/Kestrel.Core/Internal/Http2/Http2ConnectionErrorException.cs +++ b/src/Kestrel.Core/Internal/Http2/Http2ConnectionErrorException.cs @@ -7,8 +7,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 { public class Http2ConnectionErrorException : Exception { - public Http2ConnectionErrorException(Http2ErrorCode errorCode) - : base($"HTTP/2 connection error: {errorCode}") + public Http2ConnectionErrorException(string message, Http2ErrorCode errorCode) + : base($"HTTP/2 connection error ({errorCode}): {message}") { ErrorCode = errorCode; } diff --git a/src/Kestrel.Core/Internal/Http2/Http2StreamErrorException.cs b/src/Kestrel.Core/Internal/Http2/Http2StreamErrorException.cs index d2fcdc6bb0..2f63df1412 100644 --- a/src/Kestrel.Core/Internal/Http2/Http2StreamErrorException.cs +++ b/src/Kestrel.Core/Internal/Http2/Http2StreamErrorException.cs @@ -7,8 +7,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 { public class Http2StreamErrorException : Exception { - public Http2StreamErrorException(int streamId, Http2ErrorCode errorCode) - : base($"HTTP/2 stream ID {streamId} error: {errorCode}") + public Http2StreamErrorException(int streamId, string message, Http2ErrorCode errorCode) + : base($"HTTP/2 stream ID {streamId} error ({errorCode}): {message}") { StreamId = streamId; ErrorCode = errorCode; diff --git a/src/Kestrel.Core/Internal/Infrastructure/IKestrelTrace.cs b/src/Kestrel.Core/Internal/Infrastructure/IKestrelTrace.cs index 456e132274..46aed5b8ad 100644 --- a/src/Kestrel.Core/Internal/Infrastructure/IKestrelTrace.cs +++ b/src/Kestrel.Core/Internal/Infrastructure/IKestrelTrace.cs @@ -2,6 +2,8 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2.HPack; using Microsoft.Extensions.Logging; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure @@ -45,5 +47,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure void RequestBodyMininumDataRateNotSatisfied(string connectionId, string traceIdentifier, double rate); void ResponseMininumDataRateNotSatisfied(string connectionId, string traceIdentifier); + + void Http2ConnectionError(string connectionId, Http2ConnectionErrorException ex); + + void Http2StreamError(string connectionId, Http2StreamErrorException ex); + + void HPackDecodingError(string connectionId, int streamId, HPackDecodingException ex); } -} \ No newline at end of file +} diff --git a/src/Kestrel.Core/Internal/Infrastructure/KestrelTrace.cs b/src/Kestrel.Core/Internal/Infrastructure/KestrelTrace.cs index ab6eb51293..1c31f4394c 100644 --- a/src/Kestrel.Core/Internal/Infrastructure/KestrelTrace.cs +++ b/src/Kestrel.Core/Internal/Infrastructure/KestrelTrace.cs @@ -2,6 +2,8 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2.HPack; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; using Microsoft.Extensions.Logging; @@ -66,6 +68,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal private static readonly Action _responseMinimumDataRateNotSatisfied = LoggerMessage.Define(LogLevel.Information, 28, @"Connection id ""{ConnectionId}"", Request id ""{TraceIdentifier}"": the connection was closed becuase the response was not read by the client at the specified minimum data rate."); + private static readonly Action _http2ConnectionError = + LoggerMessage.Define(LogLevel.Information, 29, @"Connection id ""{ConnectionId}"": HTTP/2 connection error."); + + private static readonly Action _http2StreamError = + LoggerMessage.Define(LogLevel.Information, 30, @"Connection id ""{ConnectionId}"": HTTP/2 stream error."); + + private static readonly Action _hpackDecodingError = + LoggerMessage.Define(LogLevel.Information, 31, @"Connection id ""{ConnectionId}"": HPACK decoding error while decoding headers for stream ID {StreamId}."); + protected readonly ILogger _logger; public KestrelTrace(ILogger logger) @@ -168,6 +179,21 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal _responseMinimumDataRateNotSatisfied(_logger, connectionId, traceIdentifier, null); } + public void Http2ConnectionError(string connectionId, Http2ConnectionErrorException ex) + { + _http2ConnectionError(_logger, connectionId, ex); + } + + public void Http2StreamError(string connectionId, Http2StreamErrorException ex) + { + _http2StreamError(_logger, connectionId, ex); + } + + public void HPackDecodingError(string connectionId, int streamId, HPackDecodingException ex) + { + _hpackDecodingError(_logger, connectionId, streamId, ex); + } + public virtual void Log(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func formatter) => _logger.Log(logLevel, eventId, state, exception, formatter); diff --git a/src/Kestrel.Core/Properties/CoreStrings.Designer.cs b/src/Kestrel.Core/Properties/CoreStrings.Designer.cs index 7084b94b0c..346b18a969 100644 --- a/src/Kestrel.Core/Properties/CoreStrings.Designer.cs +++ b/src/Kestrel.Core/Properties/CoreStrings.Designer.cs @@ -1256,6 +1256,370 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core internal static string FormatHPackErrorIncompleteHeaderBlock() => GetString("HPackErrorIncompleteHeaderBlock"); + /// + /// The client sent a {frameType} frame with even stream ID {streamId}. + /// + internal static string Http2ErrorStreamIdEven + { + get => GetString("Http2ErrorStreamIdEven"); + } + + /// + /// The client sent a {frameType} frame with even stream ID {streamId}. + /// + internal static string FormatHttp2ErrorStreamIdEven(object frameType, object streamId) + => string.Format(CultureInfo.CurrentCulture, GetString("Http2ErrorStreamIdEven", "frameType", "streamId"), frameType, streamId); + + /// + /// The client sent a A PUSH_PROMISE frame. + /// + internal static string Http2ErrorPushPromiseReceived + { + get => GetString("Http2ErrorPushPromiseReceived"); + } + + /// + /// The client sent a A PUSH_PROMISE frame. + /// + internal static string FormatHttp2ErrorPushPromiseReceived() + => GetString("Http2ErrorPushPromiseReceived"); + + /// + /// The client sent a {frameType} frame to stream ID {streamId} before signaling of the header block for stream ID {headersStreamId}. + /// + internal static string Http2ErrorHeadersInterleaved + { + get => GetString("Http2ErrorHeadersInterleaved"); + } + + /// + /// The client sent a {frameType} frame to stream ID {streamId} before signaling of the header block for stream ID {headersStreamId}. + /// + internal static string FormatHttp2ErrorHeadersInterleaved(object frameType, object streamId, object headersStreamId) + => string.Format(CultureInfo.CurrentCulture, GetString("Http2ErrorHeadersInterleaved", "frameType", "streamId", "headersStreamId"), frameType, streamId, headersStreamId); + + /// + /// The client sent a {frameType} frame with stream ID 0. + /// + internal static string Http2ErrorStreamIdZero + { + get => GetString("Http2ErrorStreamIdZero"); + } + + /// + /// The client sent a {frameType} frame with stream ID 0. + /// + internal static string FormatHttp2ErrorStreamIdZero(object frameType) + => string.Format(CultureInfo.CurrentCulture, GetString("Http2ErrorStreamIdZero", "frameType"), frameType); + + /// + /// The client sent a {frameType} frame with stream ID different than 0. + /// + internal static string Http2ErrorStreamIdNotZero + { + get => GetString("Http2ErrorStreamIdNotZero"); + } + + /// + /// The client sent a {frameType} frame with stream ID different than 0. + /// + internal static string FormatHttp2ErrorStreamIdNotZero(object frameType) + => string.Format(CultureInfo.CurrentCulture, GetString("Http2ErrorStreamIdNotZero", "frameType"), frameType); + + /// + /// The client sent a {frameType} frame with padding longer than or with the same length as the sent data. + /// + internal static string Http2ErrorPaddingTooLong + { + get => GetString("Http2ErrorPaddingTooLong"); + } + + /// + /// The client sent a {frameType} frame with padding longer than or with the same length as the sent data. + /// + internal static string FormatHttp2ErrorPaddingTooLong(object frameType) + => string.Format(CultureInfo.CurrentCulture, GetString("Http2ErrorPaddingTooLong", "frameType"), frameType); + + /// + /// The client sent a {frameType} frame to closed stream ID {streamId}. + /// + internal static string Http2ErrorStreamClosed + { + get => GetString("Http2ErrorStreamClosed"); + } + + /// + /// The client sent a {frameType} frame to closed stream ID {streamId}. + /// + internal static string FormatHttp2ErrorStreamClosed(object frameType, object streamId) + => string.Format(CultureInfo.CurrentCulture, GetString("Http2ErrorStreamClosed", "frameType", "streamId"), frameType, streamId); + + /// + /// The client sent a {frameType} frame to stream ID {streamId} which is in the "half-closed (remote) state". + /// + internal static string Http2ErrorStreamHalfClosedRemote + { + get => GetString("Http2ErrorStreamHalfClosedRemote"); + } + + /// + /// The client sent a {frameType} frame to stream ID {streamId} which is in the "half-closed (remote) state". + /// + internal static string FormatHttp2ErrorStreamHalfClosedRemote(object frameType, object streamId) + => string.Format(CultureInfo.CurrentCulture, GetString("Http2ErrorStreamHalfClosedRemote", "frameType", "streamId"), frameType, streamId); + + /// + /// The client sent a {frameType} frame with dependency information that would cause stream ID {streamId} to depend on itself. + /// + internal static string Http2ErrorStreamSelfDependency + { + get => GetString("Http2ErrorStreamSelfDependency"); + } + + /// + /// The client sent a {frameType} frame with dependency information that would cause stream ID {streamId} to depend on itself. + /// + internal static string FormatHttp2ErrorStreamSelfDependency(object frameType, object streamId) + => string.Format(CultureInfo.CurrentCulture, GetString("Http2ErrorStreamSelfDependency", "frameType", "streamId"), frameType, streamId); + + /// + /// The client sent a {frameType} frame with length different than {expectedLength}. + /// + internal static string Http2ErrorUnexpectedFrameLength + { + get => GetString("Http2ErrorUnexpectedFrameLength"); + } + + /// + /// The client sent a {frameType} frame with length different than {expectedLength}. + /// + internal static string FormatHttp2ErrorUnexpectedFrameLength(object frameType, object expectedLength) + => string.Format(CultureInfo.CurrentCulture, GetString("Http2ErrorUnexpectedFrameLength", "frameType", "expectedLength"), frameType, expectedLength); + + /// + /// The client sent a SETTINGS frame with a length that is not a multiple of 6. + /// + internal static string Http2ErrorSettingsLengthNotMultipleOfSix + { + get => GetString("Http2ErrorSettingsLengthNotMultipleOfSix"); + } + + /// + /// The client sent a SETTINGS frame with a length that is not a multiple of 6. + /// + internal static string FormatHttp2ErrorSettingsLengthNotMultipleOfSix() + => GetString("Http2ErrorSettingsLengthNotMultipleOfSix"); + + /// + /// The client sent a SETTINGS frame with ACK set and length different than 0. + /// + internal static string Http2ErrorSettingsAckLengthNotZero + { + get => GetString("Http2ErrorSettingsAckLengthNotZero"); + } + + /// + /// The client sent a SETTINGS frame with ACK set and length different than 0. + /// + internal static string FormatHttp2ErrorSettingsAckLengthNotZero() + => GetString("Http2ErrorSettingsAckLengthNotZero"); + + /// + /// The client sent a SETTINGS frame with a value for parameter {parameter} that is out of range. + /// + internal static string Http2ErrorSettingsParameterOutOfRange + { + get => GetString("Http2ErrorSettingsParameterOutOfRange"); + } + + /// + /// The client sent a SETTINGS frame with a value for parameter {parameter} that is out of range. + /// + internal static string FormatHttp2ErrorSettingsParameterOutOfRange(object parameter) + => string.Format(CultureInfo.CurrentCulture, GetString("Http2ErrorSettingsParameterOutOfRange", "parameter"), parameter); + + /// + /// The client sent a WINDOW_UPDATE frame with a window size increment of 0. + /// + internal static string Http2ErrorWindowUpdateIncrementZero + { + get => GetString("Http2ErrorWindowUpdateIncrementZero"); + } + + /// + /// The client sent a WINDOW_UPDATE frame with a window size increment of 0. + /// + internal static string FormatHttp2ErrorWindowUpdateIncrementZero() + => GetString("Http2ErrorWindowUpdateIncrementZero"); + + /// + /// The client sent a CONTINUATION frame not preceded by a HEADERS frame. + /// + internal static string Http2ErrorContinuationWithNoHeaders + { + get => GetString("Http2ErrorContinuationWithNoHeaders"); + } + + /// + /// The client sent a CONTINUATION frame not preceded by a HEADERS frame. + /// + internal static string FormatHttp2ErrorContinuationWithNoHeaders() + => GetString("Http2ErrorContinuationWithNoHeaders"); + + /// + /// The client sent a {frameType} frame to idle stream ID {streamId}. + /// + internal static string Http2ErrorStreamIdle + { + get => GetString("Http2ErrorStreamIdle"); + } + + /// + /// The client sent a {frameType} frame to idle stream ID {streamId}. + /// + internal static string FormatHttp2ErrorStreamIdle(object frameType, object streamId) + => string.Format(CultureInfo.CurrentCulture, GetString("Http2ErrorStreamIdle", "frameType", "streamId"), frameType, streamId); + + /// + /// The client sent trailers containing one or more pseudo-header fields. + /// + internal static string Http2ErrorTrailersContainPseudoHeaderField + { + get => GetString("Http2ErrorTrailersContainPseudoHeaderField"); + } + + /// + /// The client sent trailers containing one or more pseudo-header fields. + /// + internal static string FormatHttp2ErrorTrailersContainPseudoHeaderField() + => GetString("Http2ErrorTrailersContainPseudoHeaderField"); + + /// + /// The client sent a header with uppercase characters in its name. + /// + internal static string Http2ErrorHeaderNameUppercase + { + get => GetString("Http2ErrorHeaderNameUppercase"); + } + + /// + /// The client sent a header with uppercase characters in its name. + /// + internal static string FormatHttp2ErrorHeaderNameUppercase() + => GetString("Http2ErrorHeaderNameUppercase"); + + /// + /// The client sent a trailer with uppercase characters in its name. + /// + internal static string Http2ErrorTrailerNameUppercase + { + get => GetString("Http2ErrorTrailerNameUppercase"); + } + + /// + /// The client sent a trailer with uppercase characters in its name. + /// + internal static string FormatHttp2ErrorTrailerNameUppercase() + => GetString("Http2ErrorTrailerNameUppercase"); + + /// + /// The client sent a HEADERS frame containing trailers without setting the END_STREAM flag. + /// + internal static string Http2ErrorHeadersWithTrailersNoEndStream + { + get => GetString("Http2ErrorHeadersWithTrailersNoEndStream"); + } + + /// + /// The client sent a HEADERS frame containing trailers without setting the END_STREAM flag. + /// + internal static string FormatHttp2ErrorHeadersWithTrailersNoEndStream() + => GetString("Http2ErrorHeadersWithTrailersNoEndStream"); + + /// + /// Request headers missing one or more mandatory pseudo-header fields. + /// + internal static string Http2ErrorMissingMandatoryPseudoHeaderFields + { + get => GetString("Http2ErrorMissingMandatoryPseudoHeaderFields"); + } + + /// + /// Request headers missing one or more mandatory pseudo-header fields. + /// + internal static string FormatHttp2ErrorMissingMandatoryPseudoHeaderFields() + => GetString("Http2ErrorMissingMandatoryPseudoHeaderFields"); + + /// + /// Pseudo-header field found in request headers after regular header fields. + /// + internal static string Http2ErrorPseudoHeaderFieldAfterRegularHeaders + { + get => GetString("Http2ErrorPseudoHeaderFieldAfterRegularHeaders"); + } + + /// + /// Pseudo-header field found in request headers after regular header fields. + /// + internal static string FormatHttp2ErrorPseudoHeaderFieldAfterRegularHeaders() + => GetString("Http2ErrorPseudoHeaderFieldAfterRegularHeaders"); + + /// + /// Request headers contain unknown pseudo-header field. + /// + internal static string Http2ErrorUnknownPseudoHeaderField + { + get => GetString("Http2ErrorUnknownPseudoHeaderField"); + } + + /// + /// Request headers contain unknown pseudo-header field. + /// + internal static string FormatHttp2ErrorUnknownPseudoHeaderField() + => GetString("Http2ErrorUnknownPseudoHeaderField"); + + /// + /// Request headers contain response-specific pseudo-header field. + /// + internal static string Http2ErrorResponsePseudoHeaderField + { + get => GetString("Http2ErrorResponsePseudoHeaderField"); + } + + /// + /// Request headers contain response-specific pseudo-header field. + /// + internal static string FormatHttp2ErrorResponsePseudoHeaderField() + => GetString("Http2ErrorResponsePseudoHeaderField"); + + /// + /// Request headers contain duplicate pseudo-header field. + /// + internal static string Http2ErrorDuplicatePseudoHeaderField + { + get => GetString("Http2ErrorDuplicatePseudoHeaderField"); + } + + /// + /// Request headers contain duplicate pseudo-header field. + /// + internal static string FormatHttp2ErrorDuplicatePseudoHeaderField() + => GetString("Http2ErrorDuplicatePseudoHeaderField"); + + /// + /// Request headers contain connection-specific header field. + /// + internal static string Http2ErrorConnectionSpecificHeaderField + { + get => GetString("Http2ErrorConnectionSpecificHeaderField"); + } + + /// + /// Request headers contain connection-specific header field. + /// + internal static string FormatHttp2ErrorConnectionSpecificHeaderField() + => GetString("Http2ErrorConnectionSpecificHeaderField"); + private static string GetString(string name, params string[] formatterNames) { var value = _resourceManager.GetString(name); diff --git a/test/Kestrel.Core.Tests/Http2ConnectionTests.cs b/test/Kestrel.Core.Tests/Http2ConnectionTests.cs index 8e7a80aeb4..40fdf47094 100644 --- a/test/Kestrel.Core.Tests/Http2ConnectionTests.cs +++ b/test/Kestrel.Core.Tests/Http2ConnectionTests.cs @@ -10,6 +10,7 @@ using System.Text; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Protocols; using Microsoft.AspNetCore.Server.Kestrel.Core.Features; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2; @@ -77,6 +78,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests private readonly PipeFactory _pipeFactory = new PipeFactory(); private readonly (IPipeConnection Transport, IPipeConnection Application) _pair; + private readonly TestApplicationErrorLogger _logger; private readonly Http2ConnectionContext _connectionContext; private readonly Http2Connection _connection; private readonly Http2PeerSettings _clientSettings = new Http2PeerSettings(); @@ -215,9 +217,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests _hpackDecoder = new HPackDecoder((int)_clientSettings.HeaderTableSize); + _logger = new TestApplicationErrorLogger(); + _connectionContext = new Http2ConnectionContext { - ServiceContext = new TestServiceContext(), + ServiceContext = new TestServiceContext() + { + Log = new TestKestrelTrace(_logger) + }, PipeFactory = _pipeFactory, Application = _pair.Application, Transport = _pair.Transport @@ -421,7 +428,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests await SendDataAsync(0, _noData, endStream: false); - await WaitForConnectionErrorAsync(expectedLastStreamId: 0, expectedErrorCode: Http2ErrorCode.PROTOCOL_ERROR, ignoreNonGoAwayFrames: false); + await WaitForConnectionErrorAsync( + ignoreNonGoAwayFrames: false, + expectedLastStreamId: 0, + expectedErrorCode: Http2ErrorCode.PROTOCOL_ERROR, + expectedErrorMessage: CoreStrings.FormatHttp2ErrorStreamIdZero(Http2FrameType.DATA)); } [Fact] @@ -431,7 +442,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests await SendDataAsync(2, _noData, endStream: false); - await WaitForConnectionErrorAsync(expectedLastStreamId: 0, expectedErrorCode: Http2ErrorCode.PROTOCOL_ERROR, ignoreNonGoAwayFrames: false); + await WaitForConnectionErrorAsync( + ignoreNonGoAwayFrames: false, + expectedLastStreamId: 0, + expectedErrorCode: Http2ErrorCode.PROTOCOL_ERROR, + expectedErrorMessage: CoreStrings.FormatHttp2ErrorStreamIdEven(Http2FrameType.DATA, streamId: 2)); } [Fact] @@ -442,7 +457,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests await StartStreamAsync(1, _browserRequestHeaders, endStream: false); await SendInvalidDataFrameAsync(1, frameLength: 5, padLength: 5); - await WaitForConnectionErrorAsync(expectedLastStreamId: 1, expectedErrorCode: Http2ErrorCode.PROTOCOL_ERROR, ignoreNonGoAwayFrames: true); + await WaitForConnectionErrorAsync( + ignoreNonGoAwayFrames: true, + expectedLastStreamId: 1, + expectedErrorCode: Http2ErrorCode.PROTOCOL_ERROR, + expectedErrorMessage: CoreStrings.FormatHttp2ErrorPaddingTooLong(Http2FrameType.DATA)); } [Fact] @@ -453,7 +472,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests await StartStreamAsync(1, _browserRequestHeaders, endStream: false); await SendInvalidDataFrameAsync(1, frameLength: 5, padLength: 6); - await WaitForConnectionErrorAsync(expectedLastStreamId: 1, expectedErrorCode: Http2ErrorCode.PROTOCOL_ERROR, ignoreNonGoAwayFrames: true); + await WaitForConnectionErrorAsync( + ignoreNonGoAwayFrames: true, + expectedLastStreamId: 1, + expectedErrorCode: Http2ErrorCode.PROTOCOL_ERROR, + expectedErrorMessage: CoreStrings.FormatHttp2ErrorPaddingTooLong(Http2FrameType.DATA)); } [Fact] @@ -464,7 +487,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests await StartStreamAsync(1, _browserRequestHeaders, endStream: false); await SendInvalidDataFrameAsync(1, frameLength: 0, padLength: 0); - await WaitForConnectionErrorAsync(expectedLastStreamId: 1, expectedErrorCode: Http2ErrorCode.PROTOCOL_ERROR, ignoreNonGoAwayFrames: true); + await WaitForConnectionErrorAsync( + ignoreNonGoAwayFrames: true, + expectedLastStreamId: 1, + expectedErrorCode: Http2ErrorCode.PROTOCOL_ERROR, + expectedErrorMessage: CoreStrings.FormatHttp2ErrorPaddingTooLong(Http2FrameType.DATA)); } [Fact] @@ -475,7 +502,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests await SendHeadersAsync(1, Http2HeadersFrameFlags.NONE, _browserRequestHeaders); await SendDataAsync(1, _helloWorldBytes, endStream: true); - await WaitForConnectionErrorAsync(expectedLastStreamId: 0, expectedErrorCode: Http2ErrorCode.PROTOCOL_ERROR, ignoreNonGoAwayFrames: false); + await WaitForConnectionErrorAsync( + ignoreNonGoAwayFrames: false, + expectedLastStreamId: 0, + expectedErrorCode: Http2ErrorCode.PROTOCOL_ERROR, + expectedErrorMessage: CoreStrings.FormatHttp2ErrorHeadersInterleaved(Http2FrameType.DATA, streamId: 1, headersStreamId: 1)); } [Fact] @@ -485,7 +516,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests await SendDataAsync(1, _helloWorldBytes, endStream: false); - await WaitForConnectionErrorAsync(expectedLastStreamId: 0, expectedErrorCode: Http2ErrorCode.PROTOCOL_ERROR, ignoreNonGoAwayFrames: false); + await WaitForConnectionErrorAsync( + ignoreNonGoAwayFrames: false, + expectedLastStreamId: 0, + expectedErrorCode: Http2ErrorCode.PROTOCOL_ERROR, + expectedErrorMessage: CoreStrings.FormatHttp2ErrorStreamIdle(Http2FrameType.DATA, streamId: 1)); } [Fact] @@ -498,7 +533,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests await SendDataAsync(1, _helloWorldBytes, endStream: false); - await WaitForConnectionErrorAsync(expectedLastStreamId: 1, expectedErrorCode: Http2ErrorCode.STREAM_CLOSED, ignoreNonGoAwayFrames: false); + await WaitForConnectionErrorAsync( + ignoreNonGoAwayFrames: false, + expectedLastStreamId: 1, + expectedErrorCode: Http2ErrorCode.STREAM_CLOSED, + expectedErrorMessage: CoreStrings.FormatHttp2ErrorStreamHalfClosedRemote(Http2FrameType.DATA, streamId: 1)); } [Fact] @@ -519,7 +558,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests await SendDataAsync(1, _helloWorldBytes, endStream: false); - await WaitForConnectionErrorAsync(expectedLastStreamId: 1, expectedErrorCode: Http2ErrorCode.STREAM_CLOSED, ignoreNonGoAwayFrames: false); + await WaitForConnectionErrorAsync( + ignoreNonGoAwayFrames: false, + expectedLastStreamId: 1, + expectedErrorCode: Http2ErrorCode.STREAM_CLOSED, + expectedErrorMessage: CoreStrings.FormatHttp2ErrorStreamClosed(Http2FrameType.DATA, streamId: 1)); } [Fact] @@ -547,7 +590,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests await SendDataAsync(1, _helloWorldBytes, endStream: true); - await WaitForConnectionErrorAsync(expectedLastStreamId: 3, expectedErrorCode: Http2ErrorCode.STREAM_CLOSED, ignoreNonGoAwayFrames: false); + await WaitForConnectionErrorAsync( + ignoreNonGoAwayFrames: false, + expectedLastStreamId: 3, + expectedErrorCode: Http2ErrorCode.STREAM_CLOSED, + expectedErrorMessage: CoreStrings.FormatHttp2ErrorStreamClosed(Http2FrameType.DATA, streamId: 1)); } [Fact] @@ -647,7 +694,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests await StartStreamAsync(0, _browserRequestHeaders, endStream: true); - await WaitForConnectionErrorAsync(expectedLastStreamId: 0, expectedErrorCode: Http2ErrorCode.PROTOCOL_ERROR, ignoreNonGoAwayFrames: false); + await WaitForConnectionErrorAsync( + ignoreNonGoAwayFrames: false, + expectedLastStreamId: 0, + expectedErrorCode: Http2ErrorCode.PROTOCOL_ERROR, + expectedErrorMessage: CoreStrings.FormatHttp2ErrorStreamIdZero(Http2FrameType.HEADERS)); } [Fact] @@ -657,7 +708,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests await StartStreamAsync(2, _browserRequestHeaders, endStream: true); - await WaitForConnectionErrorAsync(expectedLastStreamId: 0, expectedErrorCode: Http2ErrorCode.PROTOCOL_ERROR, ignoreNonGoAwayFrames: false); + await WaitForConnectionErrorAsync( + ignoreNonGoAwayFrames: false, + expectedLastStreamId: 0, + expectedErrorCode: Http2ErrorCode.PROTOCOL_ERROR, + expectedErrorMessage: CoreStrings.FormatHttp2ErrorStreamIdEven(Http2FrameType.HEADERS, streamId: 2)); } [Fact] @@ -679,7 +734,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests // Try to re-use the stream ID (http://httpwg.org/specs/rfc7540.html#rfc.section.5.1.1) await StartStreamAsync(1, _browserRequestHeaders, endStream: true); - await WaitForConnectionErrorAsync(expectedLastStreamId: 1, expectedErrorCode: Http2ErrorCode.STREAM_CLOSED, ignoreNonGoAwayFrames: false); + await WaitForConnectionErrorAsync( + ignoreNonGoAwayFrames: false, + expectedLastStreamId: 1, + expectedErrorCode: Http2ErrorCode.STREAM_CLOSED, + expectedErrorMessage: CoreStrings.FormatHttp2ErrorStreamClosed(Http2FrameType.HEADERS, streamId: 1)); } [Fact] @@ -692,7 +751,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests await SendHeadersAsync(1, Http2HeadersFrameFlags.NONE, _browserRequestHeaders); - await WaitForConnectionErrorAsync(expectedLastStreamId: 1, expectedErrorCode: Http2ErrorCode.STREAM_CLOSED, ignoreNonGoAwayFrames: false); + await WaitForConnectionErrorAsync( + ignoreNonGoAwayFrames: false, + expectedLastStreamId: 1, + expectedErrorCode: Http2ErrorCode.STREAM_CLOSED, + expectedErrorMessage: CoreStrings.FormatHttp2ErrorStreamHalfClosedRemote(Http2FrameType.HEADERS, streamId: 1)); } [Fact] @@ -714,7 +777,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests // Stream 1 was implicitly closed by opening stream 3 before (http://httpwg.org/specs/rfc7540.html#rfc.section.5.1.1) await StartStreamAsync(1, _browserRequestHeaders, endStream: true); - await WaitForConnectionErrorAsync(expectedLastStreamId: 3, expectedErrorCode: Http2ErrorCode.STREAM_CLOSED, ignoreNonGoAwayFrames: false); + await WaitForConnectionErrorAsync( + ignoreNonGoAwayFrames: false, + expectedLastStreamId: 3, + expectedErrorCode: Http2ErrorCode.STREAM_CLOSED, + expectedErrorMessage: CoreStrings.FormatHttp2ErrorStreamClosed(Http2FrameType.HEADERS, streamId: 1)); } [Theory] @@ -727,7 +794,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests await SendInvalidHeadersFrameAsync(1, frameLength: padLength, padLength: padLength); - await WaitForConnectionErrorAsync(expectedLastStreamId: 0, expectedErrorCode: Http2ErrorCode.PROTOCOL_ERROR, ignoreNonGoAwayFrames: false); + await WaitForConnectionErrorAsync( + ignoreNonGoAwayFrames: true, + expectedLastStreamId: 0, + expectedErrorCode: Http2ErrorCode.PROTOCOL_ERROR, + expectedErrorMessage: CoreStrings.FormatHttp2ErrorPaddingTooLong(Http2FrameType.HEADERS)); } [Theory] @@ -740,7 +811,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests await SendInvalidHeadersFrameAsync(1, frameLength, padLength); - await WaitForConnectionErrorAsync(expectedLastStreamId: 0, expectedErrorCode: Http2ErrorCode.PROTOCOL_ERROR, ignoreNonGoAwayFrames: false); + await WaitForConnectionErrorAsync( + ignoreNonGoAwayFrames: true, + expectedLastStreamId: 0, + expectedErrorCode: Http2ErrorCode.PROTOCOL_ERROR, + expectedErrorMessage: CoreStrings.FormatHttp2ErrorPaddingTooLong(Http2FrameType.HEADERS)); } [Fact] @@ -751,7 +826,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests await SendHeadersAsync(1, Http2HeadersFrameFlags.NONE, _browserRequestHeaders); await SendHeadersAsync(3, Http2HeadersFrameFlags.NONE, _browserRequestHeaders); - await WaitForConnectionErrorAsync(expectedLastStreamId: 0, expectedErrorCode: Http2ErrorCode.PROTOCOL_ERROR, ignoreNonGoAwayFrames: false); + await WaitForConnectionErrorAsync( + ignoreNonGoAwayFrames: false, + expectedLastStreamId: 0, + expectedErrorCode: Http2ErrorCode.PROTOCOL_ERROR, + expectedErrorMessage: CoreStrings.FormatHttp2ErrorHeadersInterleaved(Http2FrameType.HEADERS, streamId: 3, headersStreamId: 1)); } [Fact] @@ -761,7 +840,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests await SendHeadersWithPriorityAsync(1, _browserRequestHeaders, priority: 42, streamDependency: 1, endStream: true); - await WaitForConnectionErrorAsync(expectedLastStreamId: 0, expectedErrorCode: Http2ErrorCode.PROTOCOL_ERROR, ignoreNonGoAwayFrames: false); + await WaitForConnectionErrorAsync( + ignoreNonGoAwayFrames: false, + expectedLastStreamId: 0, + expectedErrorCode: Http2ErrorCode.PROTOCOL_ERROR, + expectedErrorMessage: CoreStrings.FormatHttp2ErrorStreamSelfDependency(Http2FrameType.HEADERS, streamId: 1)); } [Fact] @@ -771,7 +854,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests await SendIncompleteHeadersFrameAsync(streamId: 1); - await WaitForConnectionErrorAsync(expectedLastStreamId: 0, expectedErrorCode: Http2ErrorCode.COMPRESSION_ERROR, ignoreNonGoAwayFrames: false); + await WaitForConnectionErrorAsync( + ignoreNonGoAwayFrames: false, + expectedLastStreamId: 0, + expectedErrorCode: Http2ErrorCode.COMPRESSION_ERROR, + expectedErrorMessage: CoreStrings.HPackErrorIncompleteHeaderBlock); } [Theory] @@ -781,11 +868,19 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests await InitializeConnectionAsync(_noopApplication); await SendHeadersAsync(1, Http2HeadersFrameFlags.END_HEADERS, headerBlock); - await WaitForStreamErrorAsync(1, Http2ErrorCode.PROTOCOL_ERROR, ignoreNonRstStreamFrames: false); + await WaitForStreamErrorAsync( + ignoreNonRstStreamFrames: false, + expectedStreamId: 1, + expectedErrorCode: Http2ErrorCode.PROTOCOL_ERROR, + expectedErrorMessage: CoreStrings.Http2ErrorHeaderNameUppercase); // Verify that the stream ID can't be re-used await SendHeadersAsync(1, Http2HeadersFrameFlags.END_HEADERS, _browserRequestHeaders); - await WaitForConnectionErrorAsync(expectedLastStreamId: 1, expectedErrorCode: Http2ErrorCode.STREAM_CLOSED, ignoreNonGoAwayFrames: false); + await WaitForConnectionErrorAsync( + ignoreNonGoAwayFrames: false, + expectedLastStreamId: 1, + expectedErrorCode: Http2ErrorCode.STREAM_CLOSED, + expectedErrorMessage: CoreStrings.FormatHttp2ErrorStreamClosed(Http2FrameType.HEADERS, streamId: 1)); } [Fact] @@ -799,7 +894,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests new KeyValuePair(":unknown", "0"), }; - return HEADERS_Received_InvalidHeaderFields_StreamError(headers); + return HEADERS_Received_InvalidHeaderFields_StreamError(headers, expectedErrorMessage: CoreStrings.Http2ErrorUnknownPseudoHeaderField); } [Fact] @@ -813,21 +908,21 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests new KeyValuePair(":status", "200"), }; - return HEADERS_Received_InvalidHeaderFields_StreamError(headers); + return HEADERS_Received_InvalidHeaderFields_StreamError(headers, expectedErrorMessage: CoreStrings.Http2ErrorResponsePseudoHeaderField); } [Theory] [MemberData(nameof(DuplicatePseudoHeaderFieldData))] public Task HEADERS_Received_HeaderBlockContainsDuplicatePseudoHeaderField_StreamError(IEnumerable> headers) { - return HEADERS_Received_InvalidHeaderFields_StreamError(headers); + return HEADERS_Received_InvalidHeaderFields_StreamError(headers, expectedErrorMessage: CoreStrings.Http2ErrorDuplicatePseudoHeaderField); } [Theory] [MemberData(nameof(MissingPseudoHeaderFieldData))] public Task HEADERS_Received_HeaderBlockDoesNotContainMandatoryPseudoHeaderField_StreamError(IEnumerable> headers) { - return HEADERS_Received_InvalidHeaderFields_StreamError(headers); + return HEADERS_Received_InvalidHeaderFields_StreamError(headers, expectedErrorMessage: CoreStrings.Http2ErrorMissingMandatoryPseudoHeaderFields); } [Theory] @@ -854,23 +949,31 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests [MemberData(nameof(PseudoHeaderFieldAfterRegularHeadersData))] public Task HEADERS_Received_HeaderBlockContainsPseudoHeaderFieldAfterRegularHeaders_StreamError(IEnumerable> headers) { - return HEADERS_Received_InvalidHeaderFields_StreamError(headers); + return HEADERS_Received_InvalidHeaderFields_StreamError(headers, expectedErrorMessage: CoreStrings.Http2ErrorPseudoHeaderFieldAfterRegularHeaders); } - private async Task HEADERS_Received_InvalidHeaderFields_StreamError(IEnumerable> headers) + private async Task HEADERS_Received_InvalidHeaderFields_StreamError(IEnumerable> headers, string expectedErrorMessage) { await InitializeConnectionAsync(_noopApplication); await SendHeadersAsync(1, Http2HeadersFrameFlags.END_HEADERS, headers); - await WaitForStreamErrorAsync(1, Http2ErrorCode.PROTOCOL_ERROR, ignoreNonRstStreamFrames: false); + await WaitForStreamErrorAsync( + ignoreNonRstStreamFrames: false, + expectedStreamId: 1, + expectedErrorCode: Http2ErrorCode.PROTOCOL_ERROR, + expectedErrorMessage: expectedErrorMessage); // Verify that the stream ID can't be re-used await SendHeadersAsync(1, Http2HeadersFrameFlags.END_HEADERS, _browserRequestHeaders); - await WaitForConnectionErrorAsync(expectedLastStreamId: 1, expectedErrorCode: Http2ErrorCode.STREAM_CLOSED, ignoreNonGoAwayFrames: false); + await WaitForConnectionErrorAsync( + ignoreNonGoAwayFrames: false, + expectedLastStreamId: 1, + expectedErrorCode: Http2ErrorCode.STREAM_CLOSED, + expectedErrorMessage: CoreStrings.FormatHttp2ErrorStreamClosed(Http2FrameType.HEADERS, streamId: 1)); } [Fact] - public Task HEADERS_Received_HeaderBlockContainsConnectionSpecificHeader_StreamError() + public Task HEADERS_Received_HeaderBlockContainsConnectionHeader_StreamError() { var headers = new[] { @@ -880,7 +983,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests new KeyValuePair("connection", "keep-alive") }; - return HEADERS_Received_InvalidHeaderFields_StreamError(headers); + return HEADERS_Received_InvalidHeaderFields_StreamError(headers, CoreStrings.Http2ErrorConnectionSpecificHeaderField); } [Fact] @@ -894,21 +997,34 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests new KeyValuePair("te", "trailers, deflate") }; - return HEADERS_Received_InvalidHeaderFields_StreamError(headers); + return HEADERS_Received_InvalidHeaderFields_StreamError(headers, CoreStrings.Http2ErrorConnectionSpecificHeaderField); } [Fact] - public Task HEADERS_Received_HeaderBlockContainsTEHeader_ValueIsTrailers_NoError() + public async Task HEADERS_Received_HeaderBlockContainsTEHeader_ValueIsTrailers_NoError() { var headers = new[] { new KeyValuePair(":method", "GET"), new KeyValuePair(":path", "/"), new KeyValuePair(":scheme", "http"), - new KeyValuePair("te", "trailers, deflate") + new KeyValuePair("te", "trailers") }; - return HEADERS_Received_InvalidHeaderFields_StreamError(headers); + await InitializeConnectionAsync(_noopApplication); + + await SendHeadersAsync(1, Http2HeadersFrameFlags.END_HEADERS | Http2HeadersFrameFlags.END_STREAM, headers); + + await ExpectAsync(Http2FrameType.HEADERS, + withLength: 55, + withFlags: (byte)Http2HeadersFrameFlags.END_HEADERS, + withStreamId: 1); + await ExpectAsync(Http2FrameType.DATA, + withLength: 0, + withFlags: (byte)Http2HeadersFrameFlags.END_STREAM, + withStreamId: 1); + + await StopConnectionAsync(expectedLastStreamId: 1, ignoreNonGoAwayFrames: false); } [Fact] @@ -918,7 +1034,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests await SendPriorityAsync(0); - await WaitForConnectionErrorAsync(expectedLastStreamId: 0, expectedErrorCode: Http2ErrorCode.PROTOCOL_ERROR, ignoreNonGoAwayFrames: false); + await WaitForConnectionErrorAsync( + ignoreNonGoAwayFrames: false, + expectedLastStreamId: 0, + expectedErrorCode: Http2ErrorCode.PROTOCOL_ERROR, + expectedErrorMessage: CoreStrings.FormatHttp2ErrorStreamIdZero(Http2FrameType.PRIORITY)); } [Fact] @@ -928,7 +1048,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests await SendPriorityAsync(2); - await WaitForConnectionErrorAsync(expectedLastStreamId: 0, expectedErrorCode: Http2ErrorCode.PROTOCOL_ERROR, ignoreNonGoAwayFrames: false); + await WaitForConnectionErrorAsync( + ignoreNonGoAwayFrames: false, + expectedLastStreamId: 0, + expectedErrorCode: Http2ErrorCode.PROTOCOL_ERROR, + expectedErrorMessage: CoreStrings.FormatHttp2ErrorStreamIdEven(Http2FrameType.PRIORITY, streamId: 2)); } [Theory] @@ -940,7 +1064,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests await SendInvalidPriorityFrameAsync(1, length); - await WaitForConnectionErrorAsync(expectedLastStreamId: 0, expectedErrorCode: Http2ErrorCode.FRAME_SIZE_ERROR, ignoreNonGoAwayFrames: false); + await WaitForConnectionErrorAsync( + ignoreNonGoAwayFrames: false, + expectedLastStreamId: 0, + expectedErrorCode: Http2ErrorCode.FRAME_SIZE_ERROR, + expectedErrorMessage: CoreStrings.FormatHttp2ErrorUnexpectedFrameLength(Http2FrameType.PRIORITY, expectedLength: 5)); } [Fact] @@ -951,7 +1079,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests await SendHeadersAsync(1, Http2HeadersFrameFlags.NONE, _browserRequestHeaders); await SendPriorityAsync(1); - await WaitForConnectionErrorAsync(expectedLastStreamId: 0, expectedErrorCode: Http2ErrorCode.PROTOCOL_ERROR, ignoreNonGoAwayFrames: false); + await WaitForConnectionErrorAsync( + ignoreNonGoAwayFrames: false, + expectedLastStreamId: 0, + expectedErrorCode: Http2ErrorCode.PROTOCOL_ERROR, + expectedErrorMessage: CoreStrings.FormatHttp2ErrorHeadersInterleaved(Http2FrameType.PRIORITY, streamId: 1, headersStreamId: 1)); } [Fact] @@ -961,7 +1093,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests await SendPriorityAsync(1, streamDependency: 1); - await WaitForConnectionErrorAsync(expectedLastStreamId: 0, expectedErrorCode: Http2ErrorCode.PROTOCOL_ERROR, ignoreNonGoAwayFrames: false); + await WaitForConnectionErrorAsync( + ignoreNonGoAwayFrames: false, + expectedLastStreamId: 0, + expectedErrorCode: Http2ErrorCode.PROTOCOL_ERROR, + expectedErrorMessage: CoreStrings.FormatHttp2ErrorStreamSelfDependency(Http2FrameType.PRIORITY, 1)); } [Fact] @@ -1007,7 +1143,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests await SendRstStreamAsync(0); - await WaitForConnectionErrorAsync(expectedLastStreamId: 0, expectedErrorCode: Http2ErrorCode.PROTOCOL_ERROR, ignoreNonGoAwayFrames: false); + await WaitForConnectionErrorAsync( + ignoreNonGoAwayFrames: false, + expectedLastStreamId: 0, + expectedErrorCode: Http2ErrorCode.PROTOCOL_ERROR, + expectedErrorMessage: CoreStrings.FormatHttp2ErrorStreamIdZero(Http2FrameType.RST_STREAM)); } [Fact] @@ -1017,7 +1157,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests await SendRstStreamAsync(2); - await WaitForConnectionErrorAsync(expectedLastStreamId: 0, expectedErrorCode: Http2ErrorCode.PROTOCOL_ERROR, ignoreNonGoAwayFrames: false); + await WaitForConnectionErrorAsync( + ignoreNonGoAwayFrames: false, + expectedLastStreamId: 0, + expectedErrorCode: Http2ErrorCode.PROTOCOL_ERROR, + expectedErrorMessage: CoreStrings.FormatHttp2ErrorStreamIdEven(Http2FrameType.RST_STREAM, streamId: 2)); } [Fact] @@ -1027,7 +1171,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests await SendRstStreamAsync(1); - await WaitForConnectionErrorAsync(expectedLastStreamId: 0, expectedErrorCode: Http2ErrorCode.PROTOCOL_ERROR, ignoreNonGoAwayFrames: false); + await WaitForConnectionErrorAsync( + ignoreNonGoAwayFrames: false, + expectedLastStreamId: 0, + expectedErrorCode: Http2ErrorCode.PROTOCOL_ERROR, + expectedErrorMessage: CoreStrings.FormatHttp2ErrorStreamIdle(Http2FrameType.RST_STREAM, streamId: 1)); } [Theory] @@ -1042,7 +1190,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests await SendInvalidRstStreamFrameAsync(1, length); - await WaitForConnectionErrorAsync(expectedLastStreamId: 1, expectedErrorCode: Http2ErrorCode.FRAME_SIZE_ERROR, ignoreNonGoAwayFrames: true); + await WaitForConnectionErrorAsync( + ignoreNonGoAwayFrames: true, + expectedLastStreamId: 1, + expectedErrorCode: Http2ErrorCode.FRAME_SIZE_ERROR, + expectedErrorMessage: CoreStrings.FormatHttp2ErrorUnexpectedFrameLength(Http2FrameType.RST_STREAM, expectedLength: 4)); } [Fact] @@ -1053,7 +1205,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests await SendHeadersAsync(1, Http2HeadersFrameFlags.NONE, _browserRequestHeaders); await SendRstStreamAsync(1); - await WaitForConnectionErrorAsync(expectedLastStreamId: 0, expectedErrorCode: Http2ErrorCode.PROTOCOL_ERROR, ignoreNonGoAwayFrames: false); + await WaitForConnectionErrorAsync( + ignoreNonGoAwayFrames: false, + expectedLastStreamId: 0, + expectedErrorCode: Http2ErrorCode.PROTOCOL_ERROR, + expectedErrorMessage: CoreStrings.FormatHttp2ErrorHeadersInterleaved(Http2FrameType.RST_STREAM, streamId: 1, headersStreamId: 1)); } [Fact] @@ -1065,13 +1221,17 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests } [Fact] - public async Task SETTINGS_Received_StreamIdNonZero_ConnectionError() + public async Task SETTINGS_Received_StreamIdNotZero_ConnectionError() { await InitializeConnectionAsync(_noopApplication); await SendSettingsWithInvalidStreamIdAsync(1); - await WaitForConnectionErrorAsync(expectedLastStreamId: 0, expectedErrorCode: Http2ErrorCode.PROTOCOL_ERROR, ignoreNonGoAwayFrames: false); + await WaitForConnectionErrorAsync( + ignoreNonGoAwayFrames: false, + expectedLastStreamId: 0, + expectedErrorCode: Http2ErrorCode.PROTOCOL_ERROR, + expectedErrorMessage: CoreStrings.FormatHttp2ErrorStreamIdNotZero(Http2FrameType.SETTINGS)); } [Theory] @@ -1090,7 +1250,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests await SendSettingsWithInvalidParameterValueAsync(parameter, value); - await WaitForConnectionErrorAsync(expectedLastStreamId: 0, expectedErrorCode: expectedErrorCode, ignoreNonGoAwayFrames: false); + await WaitForConnectionErrorAsync( + ignoreNonGoAwayFrames: false, + expectedLastStreamId: 0, + expectedErrorCode: expectedErrorCode, + expectedErrorMessage: CoreStrings.FormatHttp2ErrorSettingsParameterOutOfRange(parameter)); } [Fact] @@ -1101,7 +1265,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests await SendHeadersAsync(1, Http2HeadersFrameFlags.NONE, _browserRequestHeaders); await SendSettingsAsync(); - await WaitForConnectionErrorAsync(expectedLastStreamId: 0, expectedErrorCode: Http2ErrorCode.PROTOCOL_ERROR, ignoreNonGoAwayFrames: false); + await WaitForConnectionErrorAsync( + ignoreNonGoAwayFrames: false, + expectedLastStreamId: 0, + expectedErrorCode: Http2ErrorCode.PROTOCOL_ERROR, + expectedErrorMessage: CoreStrings.FormatHttp2ErrorHeadersInterleaved(Http2FrameType.SETTINGS, streamId: 0, headersStreamId: 1)); } [Theory] @@ -1113,7 +1281,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests await SendSettingsAckWithInvalidLengthAsync(length); - await WaitForConnectionErrorAsync(expectedLastStreamId: 0, expectedErrorCode: Http2ErrorCode.FRAME_SIZE_ERROR, ignoreNonGoAwayFrames: false); + await WaitForConnectionErrorAsync( + ignoreNonGoAwayFrames: false, + expectedLastStreamId: 0, + expectedErrorCode: Http2ErrorCode.FRAME_SIZE_ERROR, + expectedErrorMessage: CoreStrings.Http2ErrorSettingsAckLengthNotZero); } [Theory] @@ -1128,7 +1300,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests await SendSettingsWithInvalidLengthAsync(length); - await WaitForConnectionErrorAsync(expectedLastStreamId: 0, expectedErrorCode: Http2ErrorCode.FRAME_SIZE_ERROR, ignoreNonGoAwayFrames: false); + await WaitForConnectionErrorAsync( + ignoreNonGoAwayFrames: false, + expectedLastStreamId: 0, + expectedErrorCode: Http2ErrorCode.FRAME_SIZE_ERROR, + expectedErrorMessage: CoreStrings.Http2ErrorSettingsLengthNotMultipleOfSix); } [Fact] @@ -1138,7 +1314,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests await SendPushPromiseFrameAsync(); - await WaitForConnectionErrorAsync(expectedLastStreamId: 0, expectedErrorCode: Http2ErrorCode.PROTOCOL_ERROR, ignoreNonGoAwayFrames: false); + await WaitForConnectionErrorAsync( + ignoreNonGoAwayFrames: false, + expectedLastStreamId: 0, + expectedErrorCode: Http2ErrorCode.PROTOCOL_ERROR, + expectedErrorMessage: CoreStrings.Http2ErrorPushPromiseReceived); } [Fact] @@ -1173,7 +1353,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests await SendHeadersAsync(1, Http2HeadersFrameFlags.NONE, _browserRequestHeaders); await SendPingAsync(Http2PingFrameFlags.NONE); - await WaitForConnectionErrorAsync(expectedLastStreamId: 0, expectedErrorCode: Http2ErrorCode.PROTOCOL_ERROR, ignoreNonGoAwayFrames: false); + await WaitForConnectionErrorAsync( + ignoreNonGoAwayFrames: false, + expectedLastStreamId: 0, + expectedErrorCode: Http2ErrorCode.PROTOCOL_ERROR, + expectedErrorMessage: CoreStrings.FormatHttp2ErrorHeadersInterleaved(Http2FrameType.PING, streamId: 0, headersStreamId: 1)); } [Fact] @@ -1183,7 +1367,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests await SendPingWithInvalidStreamIdAsync(streamId: 1); - await WaitForConnectionErrorAsync(expectedLastStreamId: 0, expectedErrorCode: Http2ErrorCode.PROTOCOL_ERROR, ignoreNonGoAwayFrames: false); + await WaitForConnectionErrorAsync( + ignoreNonGoAwayFrames: false, + expectedLastStreamId: 0, + expectedErrorCode: Http2ErrorCode.PROTOCOL_ERROR, + expectedErrorMessage: CoreStrings.FormatHttp2ErrorStreamIdNotZero(Http2FrameType.PING)); } [Theory] @@ -1197,7 +1385,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests await SendPingWithInvalidLengthAsync(length); - await WaitForConnectionErrorAsync(expectedLastStreamId: 0, expectedErrorCode: Http2ErrorCode.FRAME_SIZE_ERROR, ignoreNonGoAwayFrames: false); + await WaitForConnectionErrorAsync( + ignoreNonGoAwayFrames: false, + expectedLastStreamId: 0, + expectedErrorCode: Http2ErrorCode.FRAME_SIZE_ERROR, + expectedErrorMessage: CoreStrings.FormatHttp2ErrorUnexpectedFrameLength(Http2FrameType.PING, expectedLength: 8)); } [Fact] @@ -1231,13 +1423,17 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests } [Fact] - public async Task GOAWAY_Received_StreamIdNonZero_ConnectionError() + public async Task GOAWAY_Received_StreamIdNotZero_ConnectionError() { await InitializeConnectionAsync(_noopApplication); await SendInvalidGoAwayFrameAsync(); - await WaitForConnectionErrorAsync(expectedLastStreamId: 0, expectedErrorCode: Http2ErrorCode.PROTOCOL_ERROR, ignoreNonGoAwayFrames: false); + await WaitForConnectionErrorAsync( + ignoreNonGoAwayFrames: false, + expectedLastStreamId: 0, + expectedErrorCode: Http2ErrorCode.PROTOCOL_ERROR, + expectedErrorMessage: CoreStrings.FormatHttp2ErrorStreamIdNotZero(Http2FrameType.GOAWAY)); } [Fact] @@ -1248,7 +1444,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests await SendHeadersAsync(1, Http2HeadersFrameFlags.NONE, _browserRequestHeaders); await SendGoAwayAsync(); - await WaitForConnectionErrorAsync(expectedLastStreamId: 0, expectedErrorCode: Http2ErrorCode.PROTOCOL_ERROR, ignoreNonGoAwayFrames: false); + await WaitForConnectionErrorAsync( + ignoreNonGoAwayFrames: false, + expectedLastStreamId: 0, + expectedErrorCode: Http2ErrorCode.PROTOCOL_ERROR, + expectedErrorMessage: CoreStrings.FormatHttp2ErrorHeadersInterleaved(Http2FrameType.GOAWAY, streamId: 0, headersStreamId: 1)); } [Fact] @@ -1258,7 +1458,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests await SendWindowUpdateAsync(2, sizeIncrement: 42); - await WaitForConnectionErrorAsync(expectedLastStreamId: 0, expectedErrorCode: Http2ErrorCode.PROTOCOL_ERROR, ignoreNonGoAwayFrames: false); + await WaitForConnectionErrorAsync( + ignoreNonGoAwayFrames: false, + expectedLastStreamId: 0, + expectedErrorCode: Http2ErrorCode.PROTOCOL_ERROR, + expectedErrorMessage: CoreStrings.FormatHttp2ErrorStreamIdEven(Http2FrameType.WINDOW_UPDATE, streamId: 2)); } [Fact] @@ -1269,7 +1473,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests await SendHeadersAsync(1, Http2HeadersFrameFlags.NONE, _browserRequestHeaders); await SendWindowUpdateAsync(1, sizeIncrement: 42); - await WaitForConnectionErrorAsync(expectedLastStreamId: 0, expectedErrorCode: Http2ErrorCode.PROTOCOL_ERROR, ignoreNonGoAwayFrames: false); + await WaitForConnectionErrorAsync( + ignoreNonGoAwayFrames: false, + expectedLastStreamId: 0, + expectedErrorCode: Http2ErrorCode.PROTOCOL_ERROR, + expectedErrorMessage: CoreStrings.FormatHttp2ErrorHeadersInterleaved(Http2FrameType.WINDOW_UPDATE, streamId: 1, headersStreamId: 1)); } [Theory] @@ -1283,7 +1491,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests await SendInvalidWindowUpdateAsync(streamId, sizeIncrement: 42, length: length); - await WaitForConnectionErrorAsync(expectedLastStreamId: 0, expectedErrorCode: Http2ErrorCode.FRAME_SIZE_ERROR, ignoreNonGoAwayFrames: false); + await WaitForConnectionErrorAsync( + ignoreNonGoAwayFrames: false, + expectedLastStreamId: 0, + expectedErrorCode: Http2ErrorCode.FRAME_SIZE_ERROR, + expectedErrorMessage: CoreStrings.FormatHttp2ErrorUnexpectedFrameLength(Http2FrameType.WINDOW_UPDATE, expectedLength: 4)); } [Fact] @@ -1293,7 +1505,26 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests await SendWindowUpdateAsync(0, sizeIncrement: 0); - await WaitForConnectionErrorAsync(expectedLastStreamId: 0, expectedErrorCode: Http2ErrorCode.PROTOCOL_ERROR, ignoreNonGoAwayFrames: false); + await WaitForConnectionErrorAsync( + ignoreNonGoAwayFrames: false, + expectedLastStreamId: 0, + expectedErrorCode: Http2ErrorCode.PROTOCOL_ERROR, + expectedErrorMessage: CoreStrings.Http2ErrorWindowUpdateIncrementZero); + } + + [Fact] + public async Task WINDOW_UPDATE_Received_OnStream_SizeIncrementZero_ConnectionError() + { + await InitializeConnectionAsync(_waitForAbortApplication); + + await StartStreamAsync(1, _browserRequestHeaders, endStream: true); + await SendWindowUpdateAsync(1, sizeIncrement: 0); + + await WaitForConnectionErrorAsync( + ignoreNonGoAwayFrames: false, + expectedLastStreamId: 1, + expectedErrorCode: Http2ErrorCode.PROTOCOL_ERROR, + expectedErrorMessage: CoreStrings.Http2ErrorWindowUpdateIncrementZero); } [Fact] @@ -1303,20 +1534,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests await SendWindowUpdateAsync(1, sizeIncrement: 1); - await WaitForConnectionErrorAsync(expectedLastStreamId: 0, expectedErrorCode: Http2ErrorCode.PROTOCOL_ERROR, ignoreNonGoAwayFrames: false); - } - - [Fact] - public async Task WINDOW_UPDATE_Received_OnStream_SizeIncrementZero_StreamError() - { - await InitializeConnectionAsync(_waitForAbortApplication); - - await StartStreamAsync(1, _browserRequestHeaders, endStream: true); - await SendWindowUpdateAsync(1, sizeIncrement: 0); - - await WaitForStreamErrorAsync(expectedStreamId: 1, expectedErrorCode: Http2ErrorCode.PROTOCOL_ERROR, ignoreNonRstStreamFrames: true); - - await StopConnectionAsync(expectedLastStreamId: 1, ignoreNonGoAwayFrames: true); + await WaitForConnectionErrorAsync( + ignoreNonGoAwayFrames: false, + expectedLastStreamId: 0, + expectedErrorCode: Http2ErrorCode.PROTOCOL_ERROR, + expectedErrorMessage: CoreStrings.FormatHttp2ErrorStreamIdle(Http2FrameType.WINDOW_UPDATE, streamId: 1)); } [Fact] @@ -1348,7 +1570,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests await SendHeadersAsync(1, Http2HeadersFrameFlags.NONE, _oneContinuationRequestHeaders); await SendContinuationAsync(3, Http2ContinuationFrameFlags.END_HEADERS); - await WaitForConnectionErrorAsync(expectedLastStreamId: 0, expectedErrorCode: Http2ErrorCode.PROTOCOL_ERROR, ignoreNonGoAwayFrames: false); + await WaitForConnectionErrorAsync( + ignoreNonGoAwayFrames: false, + expectedLastStreamId: 0, + expectedErrorCode: Http2ErrorCode.PROTOCOL_ERROR, + expectedErrorMessage: CoreStrings.FormatHttp2ErrorHeadersInterleaved(Http2FrameType.CONTINUATION, streamId: 3, headersStreamId: 1)); } [Fact] @@ -1359,7 +1585,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests await SendHeadersAsync(1, Http2HeadersFrameFlags.NONE, _postRequestHeaders); await SendIncompleteContinuationFrameAsync(streamId: 1); - await WaitForConnectionErrorAsync(expectedLastStreamId: 0, expectedErrorCode: Http2ErrorCode.COMPRESSION_ERROR, ignoreNonGoAwayFrames: false); + await WaitForConnectionErrorAsync( + ignoreNonGoAwayFrames: false, + expectedLastStreamId: 0, + expectedErrorCode: Http2ErrorCode.COMPRESSION_ERROR, + expectedErrorMessage: CoreStrings.HPackErrorIncompleteHeaderBlock); } [Theory] @@ -1371,11 +1601,19 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests Assert.True(await SendHeadersAsync(1, Http2HeadersFrameFlags.NONE, headers)); await SendEmptyContinuationFrameAsync(1, Http2ContinuationFrameFlags.END_HEADERS); - await WaitForStreamErrorAsync(1, Http2ErrorCode.PROTOCOL_ERROR, ignoreNonRstStreamFrames: false); + await WaitForStreamErrorAsync( + ignoreNonRstStreamFrames: false, + expectedStreamId: 1, + expectedErrorCode: Http2ErrorCode.PROTOCOL_ERROR, + expectedErrorMessage: CoreStrings.Http2ErrorMissingMandatoryPseudoHeaderFields); // Verify that the stream ID can't be re-used await SendHeadersAsync(1, Http2HeadersFrameFlags.END_HEADERS, headers); - await WaitForConnectionErrorAsync(expectedLastStreamId: 1, expectedErrorCode: Http2ErrorCode.STREAM_CLOSED, ignoreNonGoAwayFrames: false); + await WaitForConnectionErrorAsync( + ignoreNonGoAwayFrames: false, + expectedLastStreamId: 1, + expectedErrorCode: Http2ErrorCode.STREAM_CLOSED, + expectedErrorMessage: CoreStrings.FormatHttp2ErrorStreamClosed(Http2FrameType.HEADERS, streamId: 1)); } [Theory] @@ -1448,7 +1686,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests { await InitializeConnectionAsync(_noopApplication); - await SendUnknownFrameTypeAsync(streamId: 1); + await SendUnknownFrameTypeAsync(streamId: 1, frameType: 42); // Check that the connection is still alive await SendPingAsync(Http2PingFrameFlags.NONE); @@ -1466,13 +1704,17 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests await InitializeConnectionAsync(_noopApplication); await SendHeadersAsync(1, Http2HeadersFrameFlags.NONE, _browserRequestHeaders); - await SendUnknownFrameTypeAsync(streamId: 1); + await SendUnknownFrameTypeAsync(streamId: 1, frameType: 42); - await WaitForConnectionErrorAsync(expectedLastStreamId: 0, expectedErrorCode: Http2ErrorCode.PROTOCOL_ERROR, ignoreNonGoAwayFrames: false); + await WaitForConnectionErrorAsync( + ignoreNonGoAwayFrames: false, + expectedLastStreamId: 0, + expectedErrorCode: Http2ErrorCode.PROTOCOL_ERROR, + expectedErrorMessage: CoreStrings.FormatHttp2ErrorHeadersInterleaved(frameType: 42, streamId: 1, headersStreamId: 1)); } [Fact] - public async Task ConnectionError_AbortsAllStreams() + public async Task ConnectionErrorAbortsAllStreams() { await InitializeConnectionAsync(_waitForAbortApplication); @@ -1484,7 +1726,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests // Cause a connection error by sending an invalid frame await SendDataAsync(0, _noData, endStream: false); - await WaitForConnectionErrorAsync(expectedLastStreamId: 5, expectedErrorCode: Http2ErrorCode.PROTOCOL_ERROR, ignoreNonGoAwayFrames: false); + await WaitForConnectionErrorAsync( + ignoreNonGoAwayFrames: false, + expectedLastStreamId: 5, + expectedErrorCode: Http2ErrorCode.PROTOCOL_ERROR, + expectedErrorMessage: CoreStrings.FormatHttp2ErrorStreamIdZero(Http2FrameType.DATA)); await WaitForAllStreamsAsync(); Assert.Contains(1, _abortedStreamIds); @@ -1492,6 +1738,32 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests Assert.Contains(5, _abortedStreamIds); } + [Fact] + public async Task ConnectionResetLoggedWithActiveStreams() + { + await InitializeConnectionAsync(_waitForAbortApplication); + + await SendHeadersAsync(1, Http2HeadersFrameFlags.END_HEADERS | Http2HeadersFrameFlags.END_STREAM, _browserRequestHeaders); + + _pair.Application.Output.Complete(new ConnectionResetException(string.Empty)); + + var result = await _pair.Application.Input.ReadAsync(); + Assert.True(result.IsCompleted); + Assert.Single(_logger.Messages, m => m.Exception is ConnectionResetException); + } + + [Fact] + public async Task ConnectionResetNotLoggedWithNoActiveStreams() + { + await InitializeConnectionAsync(_waitForAbortApplication); + + _pair.Application.Output.Complete(new ConnectionResetException(string.Empty)); + + var result = await _pair.Application.Input.ReadAsync(); + Assert.True(result.IsCompleted); + Assert.DoesNotContain(_logger.Messages, m => m.Exception is ConnectionResetException); + } + private async Task InitializeConnectionAsync(RequestDelegate application) { _connectionTask = _connection.ProcessAsync(new DummyApplication(application)); @@ -1931,11 +2203,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests return SendAsync(frame.Raw); } - private Task SendUnknownFrameTypeAsync(int streamId) + private Task SendUnknownFrameTypeAsync(int streamId, int frameType) { var frame = new Http2Frame(); frame.StreamId = streamId; - frame.Type = (Http2FrameType)42; + frame.Type = (Http2FrameType)frameType; frame.Length = 0; return SendAsync(frame.Raw); } @@ -1996,10 +2268,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests private Task WaitForConnectionStopAsync(int expectedLastStreamId, bool ignoreNonGoAwayFrames) { - return WaitForConnectionErrorAsync(expectedLastStreamId, Http2ErrorCode.NO_ERROR, ignoreNonGoAwayFrames); + return WaitForConnectionErrorAsync(ignoreNonGoAwayFrames, expectedLastStreamId, Http2ErrorCode.NO_ERROR, expectedErrorMessage: null); } - private async Task WaitForConnectionErrorAsync(int expectedLastStreamId, Http2ErrorCode expectedErrorCode, bool ignoreNonGoAwayFrames) + private async Task WaitForConnectionErrorAsync(bool ignoreNonGoAwayFrames, int expectedLastStreamId, Http2ErrorCode expectedErrorCode, string expectedErrorMessage) + where TException : Exception { var frame = await ReceiveFrameAsync(); @@ -2018,11 +2291,17 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests Assert.Equal(expectedLastStreamId, frame.GoAwayLastStreamId); Assert.Equal(expectedErrorCode, frame.GoAwayErrorCode); + if (expectedErrorMessage != null) + { + var message = Assert.Single(_logger.Messages, m => m.Exception is TException); + Assert.Contains(expectedErrorMessage, message.Exception.Message); + } + await _connectionTask; _pair.Application.Output.Complete(); } - private async Task WaitForStreamErrorAsync(int expectedStreamId, Http2ErrorCode expectedErrorCode, bool ignoreNonRstStreamFrames) + private async Task WaitForStreamErrorAsync(bool ignoreNonRstStreamFrames, int expectedStreamId, Http2ErrorCode expectedErrorCode, string expectedErrorMessage) { var frame = await ReceiveFrameAsync(); @@ -2039,6 +2318,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests Assert.Equal(0, frame.Flags); Assert.Equal(expectedStreamId, frame.StreamId); Assert.Equal(expectedErrorCode, frame.RstStreamErrorCode); + + if (expectedErrorMessage != null) + { + var message = Assert.Single(_logger.Messages, m => m.Exception is Http2StreamErrorException); + Assert.Contains(expectedErrorMessage, message.Exception.Message); + } } private void VerifyDecodedRequestHeaders(IEnumerable> expectedHeaders) From 66a3c9496afb9694db13318c4f637ab2dbe1a7d5 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Thu, 12 Oct 2017 12:26:52 -0700 Subject: [PATCH 1429/1662] Set SO_REUSEADDR on managed listen sockets on Unix (#2111) - https://github.com/dotnet/corefx/issues/24562 --- .../SocketTransport.cs | 36 +++++++++++++++++++ .../AddressRegistrationTests.cs | 16 ++------- 2 files changed, 38 insertions(+), 14 deletions(-) diff --git a/src/Kestrel.Transport.Sockets/SocketTransport.cs b/src/Kestrel.Transport.Sockets/SocketTransport.cs index 61ede997e3..99e3bbe3d4 100644 --- a/src/Kestrel.Transport.Sockets/SocketTransport.cs +++ b/src/Kestrel.Transport.Sockets/SocketTransport.cs @@ -6,10 +6,12 @@ using System.Diagnostics; using System.IO.Pipelines; using System.Net; using System.Net.Sockets; +using System.Runtime.InteropServices; using System.Threading.Tasks; using Microsoft.AspNetCore.Protocols; using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; using Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal; +using Microsoft.Extensions.Logging; namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets { @@ -51,6 +53,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets var listenSocket = new Socket(endPoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp); + EnableRebinding(listenSocket); + // Kestrel expects IPv6Any to bind to both IPv6 and IPv4 if (endPoint.Address == IPAddress.IPv6Any) { @@ -128,5 +132,37 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets } } } + + [DllImport("libc", SetLastError = true)] + private static extern int setsockopt(IntPtr socket, int level, int option_name, IntPtr option_value, uint option_len); + + private const int SOL_SOCKET_OSX = 0xffff; + private const int SO_REUSEADDR_OSX = 0x0004; + private const int SOL_SOCKET_LINUX = 0x0001; + private const int SO_REUSEADDR_LINUX = 0x0002; + + // Without setting SO_REUSEADDR on macOS and Linux, binding to a recently used endpoint can fail. + // https://github.com/dotnet/corefx/issues/24562 + private unsafe void EnableRebinding(Socket listenSocket) + { + var optionValue = 1; + var setsockoptStatus = 0; + + if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) + { + setsockoptStatus = setsockopt(listenSocket.Handle, SOL_SOCKET_LINUX, SO_REUSEADDR_LINUX, + (IntPtr)(&optionValue), sizeof(int)); + } + else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) + { + setsockoptStatus = setsockopt(listenSocket.Handle, SOL_SOCKET_OSX, SO_REUSEADDR_OSX, + (IntPtr)(&optionValue), sizeof(int)); + } + + if (setsockoptStatus != 0) + { + _trace.LogInformation("Setting SO_REUSEADDR failed with errno '{errno}'.", Marshal.GetLastWin32Error()); + } + } } } diff --git a/test/Kestrel.FunctionalTests/AddressRegistrationTests.cs b/test/Kestrel.FunctionalTests/AddressRegistrationTests.cs index 66f2a62c2d..7b9c9bdcda 100644 --- a/test/Kestrel.FunctionalTests/AddressRegistrationTests.cs +++ b/test/Kestrel.FunctionalTests/AddressRegistrationTests.cs @@ -526,10 +526,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } } - // https://github.com/dotnet/corefx/issues/24562 - [ConditionalFact] - [OSSkipCondition(OperatingSystems.MacOSX, SkipReason = "Sockets transport fails to rebind on macOS.")] - [OSSkipCondition(OperatingSystems.Linux, SkipReason = "Sockets transport fails to rebind on Linux.")] + [Fact] public async Task CanRebindToEndPoint() { var port = GetNextPort(); @@ -566,10 +563,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } } - // https://github.com/dotnet/corefx/issues/24562 [ConditionalFact] - [OSSkipCondition(OperatingSystems.MacOSX, SkipReason = "Sockets transport fails to rebind on macOS.")] - [OSSkipCondition(OperatingSystems.Linux, SkipReason = "Sockets transport fails to rebind on Linux.")] + [IPv6SupportedCondition] public async Task CanRebindToMultipleEndPoints() { var port = GetNextPort(); @@ -892,12 +887,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests private bool CanBindToPort() { -#if MACOS && SOCKETS - // Binding to a port with a Socket, disposing the Socket, and rebinding often fails with - // SocketError.AddressAlreadyInUse on macOS. This isn't an issue if binding with libuv second. - // https://github.com/dotnet/corefx/issues/24562 - return false; -#else try { using (var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)) @@ -910,7 +899,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { return false; } -#endif } } } From 9dfffd14bb71e4ebef4d0166e0f01006bf58b6cd Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Thu, 12 Oct 2017 17:26:20 -0700 Subject: [PATCH 1430/1662] HTTP/2: support trailers. --- .../Internal/Http2/Http2Connection.cs | 58 ++++- .../Http2ConnectionTests.cs | 219 ++++++++++++++++++ 2 files changed, 269 insertions(+), 8 deletions(-) diff --git a/src/Kestrel.Core/Internal/Http2/Http2Connection.cs b/src/Kestrel.Core/Internal/Http2/Http2Connection.cs index 40d35ebee3..82637d51c1 100644 --- a/src/Kestrel.Core/Internal/Http2/Http2Connection.cs +++ b/src/Kestrel.Core/Internal/Http2/Http2Connection.cs @@ -358,13 +358,24 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 // END_STREAM flag set MUST treat that as a connection error (Section 5.4.1) // of type STREAM_CLOSED, unless the frame is permitted as described below. // - // (The allowed frame types for this situation are WINDOW_UPDATE, RST_STREAM and PRIORITY) + // (The allowed frame types after END_STREAM are WINDOW_UPDATE, RST_STREAM and PRIORITY) if (stream.EndStreamReceived) { throw new Http2ConnectionErrorException(CoreStrings.FormatHttp2ErrorStreamHalfClosedRemote(_incomingFrame.Type, stream.StreamId), Http2ErrorCode.STREAM_CLOSED); } - // TODO: trailers + // This is the last chance for the client to send END_STREAM + if ((_incomingFrame.HeadersFlags & Http2HeadersFrameFlags.END_STREAM) == 0) + { + throw new Http2ConnectionErrorException(CoreStrings.Http2ErrorHeadersWithTrailersNoEndStream, Http2ErrorCode.PROTOCOL_ERROR); + } + + // Since we found an active stream, this HEADERS frame contains trailers + _currentHeadersStream = stream; + _requestHeaderParsingState = RequestHeaderParsingState.Trailers; + + var endHeaders = (_incomingFrame.HeadersFlags & Http2HeadersFrameFlags.END_HEADERS) == Http2HeadersFrameFlags.END_HEADERS; + await DecodeTrailersAsync(endHeaders, _incomingFrame.HeadersPayload); } else if (_incomingFrame.StreamId <= _highestOpenedStreamId) { @@ -585,7 +596,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 var endHeaders = (_incomingFrame.ContinuationFlags & Http2ContinuationFrameFlags.END_HEADERS) == Http2ContinuationFrameFlags.END_HEADERS; - return DecodeHeadersAsync(endHeaders, _incomingFrame.Payload); + if (_requestHeaderParsingState == RequestHeaderParsingState.Trailers) + { + return DecodeTrailersAsync(endHeaders, _incomingFrame.Payload); + } + else + { + return DecodeHeadersAsync(endHeaders, _incomingFrame.Payload); + } } private Task ProcessUnknownFrameAsync() @@ -620,6 +638,20 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 return Task.CompletedTask; } + private Task DecodeTrailersAsync(bool endHeaders, Span payload) + { + _hpackDecoder.Decode(payload, endHeaders, handler: this); + + if (endHeaders) + { + var endStreamTask = _currentHeadersStream.OnDataAsync(Constants.EmptyData, endStream: true); + ResetRequestHeaderParsingState(); + return endStreamTask; + } + + return Task.CompletedTask; + } + private void StartStream() { if (!_isMethodConnect && (_parsedPseudoHeaderFields & _mandatoryRequestPseudoHeaderFields) != _mandatoryRequestPseudoHeaderFields) @@ -682,17 +714,20 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 // http://httpwg.org/specs/rfc7540.html#rfc.section.8.1.2.1 if (IsPseudoHeaderField(name, out var headerField)) { - if (_requestHeaderParsingState == RequestHeaderParsingState.Headers || - _requestHeaderParsingState == RequestHeaderParsingState.Trailers) + if (_requestHeaderParsingState == RequestHeaderParsingState.Headers) { - // Pseudo-header fields MUST NOT appear in trailers. - // ... // All pseudo-header fields MUST appear in the header block before regular header fields. // Any request or response that contains a pseudo-header field that appears in a header // block after a regular header field MUST be treated as malformed (Section 8.1.2.6). throw new Http2StreamErrorException(_currentHeadersStream.StreamId, CoreStrings.Http2ErrorPseudoHeaderFieldAfterRegularHeaders, Http2ErrorCode.PROTOCOL_ERROR); } + if (_requestHeaderParsingState == RequestHeaderParsingState.Trailers) + { + // Pseudo-header fields MUST NOT appear in trailers. + throw new Http2ConnectionErrorException(CoreStrings.Http2ErrorTrailersContainPseudoHeaderField, Http2ErrorCode.PROTOCOL_ERROR); + } + _requestHeaderParsingState = RequestHeaderParsingState.PseudoHeaderFields; if (headerField == PseudoHeaderFields.Unknown) @@ -739,7 +774,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 { if (name[i] >= 65 && name[i] <= 90) { - throw new Http2StreamErrorException(_currentHeadersStream.StreamId, CoreStrings.Http2ErrorHeaderNameUppercase, Http2ErrorCode.PROTOCOL_ERROR); + if (_requestHeaderParsingState == RequestHeaderParsingState.Trailers) + { + throw new Http2ConnectionErrorException(CoreStrings.Http2ErrorTrailerNameUppercase, Http2ErrorCode.PROTOCOL_ERROR); + } + else + { + throw new Http2StreamErrorException(_currentHeadersStream.StreamId, CoreStrings.Http2ErrorHeaderNameUppercase, Http2ErrorCode.PROTOCOL_ERROR); + } } } } diff --git a/test/Kestrel.Core.Tests/Http2ConnectionTests.cs b/test/Kestrel.Core.Tests/Http2ConnectionTests.cs index 40fdf47094..39db80b4a4 100644 --- a/test/Kestrel.Core.Tests/Http2ConnectionTests.cs +++ b/test/Kestrel.Core.Tests/Http2ConnectionTests.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Concurrent; using System.Collections.Generic; +using System.IO; using System.IO.Pipelines; using System.Linq; using System.Text; @@ -44,6 +45,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests new KeyValuePair("upgrade-insecure-requests", "1"), }; + private static readonly IEnumerable> _requestTrailers = new[] + { + new KeyValuePair("trailer-one", "1"), + new KeyValuePair("trailer-two", "2"), + }; + private static readonly IEnumerable> _oneContinuationRequestHeaders = new[] { new KeyValuePair(":method", "GET"), @@ -93,6 +100,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests private readonly RequestDelegate _noopApplication; private readonly RequestDelegate _readHeadersApplication; + private readonly RequestDelegate _readTrailersApplication; private readonly RequestDelegate _bufferingApplication; private readonly RequestDelegate _echoApplication; private readonly RequestDelegate _echoWaitForAbortApplication; @@ -118,6 +126,20 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests return Task.CompletedTask; }; + _readTrailersApplication = async context => + { + using (var ms = new MemoryStream()) + { + // Consuming the entire request body guarantees trailers will be available + await context.Request.Body.CopyToAsync(ms); + } + + foreach (var header in context.Request.Headers) + { + _receivedHeaders[header.Key] = header.Value.ToString(); + } + }; + _bufferingApplication = async context => { var data = new List(); @@ -687,6 +709,52 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests await StopConnectionAsync(expectedLastStreamId: 1, ignoreNonGoAwayFrames: false); } + [Theory] + [InlineData(true)] + [InlineData(false)] + public async Task HEADERS_Received_WithTrailers_Decoded(bool sendData) + { + await InitializeConnectionAsync(_readTrailersApplication); + + await SendHeadersAsync(1, Http2HeadersFrameFlags.END_HEADERS, _browserRequestHeaders); + + // Initialize another stream with a higher stream ID, and verify that after trailers are + // decoded by the other stream, the highest opened stream ID is not reset to the lower ID + // (the highest opened stream ID is sent by the server in the GOAWAY frame when shutting + // down the connection). + await SendHeadersAsync(3, Http2HeadersFrameFlags.END_HEADERS | Http2HeadersFrameFlags.END_STREAM, _browserRequestHeaders); + + // The second stream should end first, since the first one is waiting for the request body. + await ExpectAsync(Http2FrameType.HEADERS, + withLength: 55, + withFlags: (byte)Http2HeadersFrameFlags.END_HEADERS, + withStreamId: 3); + await ExpectAsync(Http2FrameType.DATA, + withLength: 0, + withFlags: (byte)Http2DataFrameFlags.END_STREAM, + withStreamId: 3); + + if (sendData) + { + await SendDataAsync(1, _helloBytes, endStream: false); + } + + await SendHeadersAsync(1, Http2HeadersFrameFlags.END_HEADERS | Http2HeadersFrameFlags.END_STREAM, _requestTrailers); + + await ExpectAsync(Http2FrameType.HEADERS, + withLength: 55, + withFlags: (byte)Http2HeadersFrameFlags.END_HEADERS, + withStreamId: 1); + await ExpectAsync(Http2FrameType.DATA, + withLength: 0, + withFlags: (byte)Http2DataFrameFlags.END_STREAM, + withStreamId: 1); + + VerifyDecodedRequestHeaders(_browserRequestHeaders.Concat(_requestTrailers)); + + await StopConnectionAsync(expectedLastStreamId: 3, ignoreNonGoAwayFrames: false); + } + [Fact] public async Task HEADERS_Received_StreamIdZero_ConnectionError() { @@ -861,6 +929,39 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests expectedErrorMessage: CoreStrings.HPackErrorIncompleteHeaderBlock); } + [Theory] + [MemberData(nameof(IllegalTrailerData))] + public async Task HEADERS_Received_WithTrailers_ContainsIllegalTrailer_ConnectionError(byte[] trailers, string expectedErrorMessage) + { + await InitializeConnectionAsync(_readTrailersApplication); + + await SendHeadersAsync(1, Http2HeadersFrameFlags.END_HEADERS, _browserRequestHeaders); + await SendHeadersAsync(1, Http2HeadersFrameFlags.END_HEADERS | Http2HeadersFrameFlags.END_STREAM, trailers); + + await WaitForConnectionErrorAsync( + ignoreNonGoAwayFrames: false, + expectedLastStreamId: 1, + expectedErrorCode: Http2ErrorCode.PROTOCOL_ERROR, + expectedErrorMessage: expectedErrorMessage); + } + + [Theory] + [InlineData(Http2HeadersFrameFlags.NONE)] + [InlineData(Http2HeadersFrameFlags.END_HEADERS)] + public async Task HEADERS_Received_WithTrailers_EndStreamNotSet_ConnectionError(Http2HeadersFrameFlags flags) + { + await InitializeConnectionAsync(_readTrailersApplication); + + await SendHeadersAsync(1, Http2HeadersFrameFlags.END_HEADERS, _browserRequestHeaders); + await SendHeadersAsync(1, flags, _requestTrailers); + + await WaitForConnectionErrorAsync( + ignoreNonGoAwayFrames: false, + expectedLastStreamId: 1, + expectedErrorCode: Http2ErrorCode.PROTOCOL_ERROR, + expectedErrorMessage: CoreStrings.Http2ErrorHeadersWithTrailersNoEndStream); + } + [Theory] [MemberData(nameof(UpperCaseHeaderNameData))] public async Task HEADERS_Received_HeaderNameContainsUpperCaseCharacter_StreamError(byte[] headerBlock) @@ -1562,6 +1663,67 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests await StopConnectionAsync(expectedLastStreamId: 1, ignoreNonGoAwayFrames: false); } + [Theory] + [InlineData(true)] + [InlineData(false)] + public async Task CONTINUATION_Received_WithTrailers_Decoded(bool sendData) + { + await InitializeConnectionAsync(_readTrailersApplication); + + await SendHeadersAsync(1, Http2HeadersFrameFlags.END_HEADERS, _browserRequestHeaders); + + // Initialize another stream with a higher stream ID, and verify that after trailers are + // decoded by the other stream, the highest opened stream ID is not reset to the lower ID + // (the highest opened stream ID is sent by the server in the GOAWAY frame when shutting + // down the connection). + await SendHeadersAsync(3, Http2HeadersFrameFlags.END_HEADERS | Http2HeadersFrameFlags.END_STREAM, _browserRequestHeaders); + + // The second stream should end first, since the first one is waiting for the request body. + await ExpectAsync(Http2FrameType.HEADERS, + withLength: 55, + withFlags: (byte)Http2HeadersFrameFlags.END_HEADERS, + withStreamId: 3); + await ExpectAsync(Http2FrameType.DATA, + withLength: 0, + withFlags: (byte)Http2DataFrameFlags.END_STREAM, + withStreamId: 3); + + if (sendData) + { + await SendDataAsync(1, _helloBytes, endStream: false); + } + + // Trailers encoded as Literal Header Field without Indexing - New Name + // trailer-1: 1 + // trailer-2: 2 + var trailers = new byte[] { 0x00, 0x09 } + .Concat(Encoding.ASCII.GetBytes("trailer-1")) + .Concat(new byte[] { 0x01, (byte)'1' }) + .Concat(new byte[] { 0x00, 0x09 }) + .Concat(Encoding.ASCII.GetBytes("trailer-2")) + .Concat(new byte[] { 0x01, (byte)'2' }) + .ToArray(); + await SendHeadersAsync(1, Http2HeadersFrameFlags.END_STREAM, new byte[0]); + await SendContinuationAsync(1, Http2ContinuationFrameFlags.END_HEADERS, trailers); + + await ExpectAsync(Http2FrameType.HEADERS, + withLength: 55, + withFlags: (byte)Http2HeadersFrameFlags.END_HEADERS, + withStreamId: 1); + await ExpectAsync(Http2FrameType.DATA, + withLength: 0, + withFlags: (byte)Http2DataFrameFlags.END_STREAM, + withStreamId: 1); + + VerifyDecodedRequestHeaders(_browserRequestHeaders.Concat(new[] + { + new KeyValuePair("trailer-1", "1"), + new KeyValuePair("trailer-2", "2") + })); + + await StopConnectionAsync(expectedLastStreamId: 3, ignoreNonGoAwayFrames: false); + } + [Fact] public async Task CONTINUATION_Received_StreamIdMismatch_ConnectionError() { @@ -1592,6 +1754,23 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests expectedErrorMessage: CoreStrings.HPackErrorIncompleteHeaderBlock); } + [Theory] + [MemberData(nameof(IllegalTrailerData))] + public async Task CONTINUATION_Received_WithTrailers_ContainsIllegalTrailer_ConnectionError(byte[] trailers, string expectedErrorMessage) + { + await InitializeConnectionAsync(_readTrailersApplication); + + await SendHeadersAsync(1, Http2HeadersFrameFlags.END_HEADERS, _browserRequestHeaders); + await SendHeadersAsync(1, Http2HeadersFrameFlags.END_STREAM, new byte[0]); + await SendContinuationAsync(1, Http2ContinuationFrameFlags.END_HEADERS, trailers); + + await WaitForConnectionErrorAsync( + ignoreNonGoAwayFrames: false, + expectedLastStreamId: 1, + expectedErrorCode: Http2ErrorCode.PROTOCOL_ERROR, + expectedErrorMessage: expectedErrorMessage); + } + [Theory] [MemberData(nameof(MissingPseudoHeaderFieldData))] public async Task CONTINUATION_Received_HeaderBlockDoesNotContainMandatoryPseudoHeaderField_StreamError(IEnumerable> headers) @@ -2048,6 +2227,17 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests return done; } + private async Task SendContinuationAsync(int streamId, Http2ContinuationFrameFlags flags, byte[] payload) + { + var frame = new Http2Frame(); + + frame.PrepareContinuation(flags, streamId); + frame.Length = payload.Length; + payload.CopyTo(frame.Payload); + + await SendAsync(frame.Raw); + } + private Task SendEmptyContinuationFrameAsync(int streamId, Http2ContinuationFrameFlags flags) { var frame = new Http2Frame(); @@ -2463,5 +2653,34 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests return data; } } + + public static TheoryData IllegalTrailerData + { + get + { + // We can't use HPackEncoder here because it will convert header names to lowercase + var data = new TheoryData(); + + // Indexed Header Field - :method: GET + data.Add(new byte[] { 0x82 }, CoreStrings.Http2ErrorTrailersContainPseudoHeaderField); + + // Indexed Header Field - :path: / + data.Add(new byte[] { 0x84 }, CoreStrings.Http2ErrorTrailersContainPseudoHeaderField); + + // Indexed Header Field - :scheme: http + data.Add(new byte[] { 0x86 }, CoreStrings.Http2ErrorTrailersContainPseudoHeaderField); + + // Literal Header Field without Indexing - Indexed Name - :authority: 127.0.0.1 + data.Add(new byte[] { 0x01, 0x09 }.Concat(Encoding.ASCII.GetBytes("127.0.0.1")).ToArray(), CoreStrings.Http2ErrorTrailersContainPseudoHeaderField); + + // Literal Header Field without Indexing - New Name - contains-Uppercase: 0 + data.Add(new byte[] { 0x00, 0x12 } + .Concat(Encoding.ASCII.GetBytes("contains-Uppercase")) + .Concat(new byte[] { 0x01, (byte)'0' }) + .ToArray(), CoreStrings.Http2ErrorTrailerNameUppercase); + + return data; + } + } } } From 733ac1efabfc4097d32f77d957b562123ad6164a Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Fri, 13 Oct 2017 15:07:21 -0700 Subject: [PATCH 1431/1662] Handle EPIPE like ECONNRESET on Linux (#2112) --- .../Internal/LibuvConnection.cs | 2 +- .../Internal/LibuvConstants.cs | 18 ++++++++++++++++++ .../Internal/LibuvOutputConsumer.cs | 2 +- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/Kestrel.Transport.Libuv/Internal/LibuvConnection.cs b/src/Kestrel.Transport.Libuv/Internal/LibuvConnection.cs index 26f3ed4ac3..670503dbda 100644 --- a/src/Kestrel.Transport.Libuv/Internal/LibuvConnection.cs +++ b/src/Kestrel.Transport.Libuv/Internal/LibuvConnection.cs @@ -162,7 +162,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal handle.Libuv.Check(status, out var uvError); // Log connection resets at a lower (Debug) level. - if (status == LibuvConstants.ECONNRESET) + if (LibuvConstants.IsConnectionReset(status)) { Log.ConnectionReset(ConnectionId); error = new ConnectionResetException(uvError.Message, uvError); diff --git a/src/Kestrel.Transport.Libuv/Internal/LibuvConstants.cs b/src/Kestrel.Transport.Libuv/Internal/LibuvConstants.cs index 1e7c8f319d..650700ec00 100644 --- a/src/Kestrel.Transport.Libuv/Internal/LibuvConstants.cs +++ b/src/Kestrel.Transport.Libuv/Internal/LibuvConstants.cs @@ -1,6 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System.Runtime.CompilerServices; using System.Runtime.InteropServices; namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal @@ -13,6 +14,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal public static readonly int? ECONNRESET = GetECONNRESET(); public static readonly int? EADDRINUSE = GetEADDRINUSE(); public static readonly int? ENOTSUP = GetENOTSUP(); + public static readonly int? EPIPE = GetEPIPE(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static bool IsConnectionReset(int errno) + { + return errno == ECONNRESET || errno == EPIPE; + } private static int? GetECONNRESET() { @@ -31,6 +39,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal return null; } + private static int? GetEPIPE() + { + if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) + { + return -32; + } + + return null; + } + private static int? GetEADDRINUSE() { if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) diff --git a/src/Kestrel.Transport.Libuv/Internal/LibuvOutputConsumer.cs b/src/Kestrel.Transport.Libuv/Internal/LibuvOutputConsumer.cs index 92b3febcd7..ccf1362b6f 100644 --- a/src/Kestrel.Transport.Libuv/Internal/LibuvOutputConsumer.cs +++ b/src/Kestrel.Transport.Libuv/Internal/LibuvOutputConsumer.cs @@ -118,7 +118,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal else { // Log connection resets at a lower (Debug) level. - if (status == LibuvConstants.ECONNRESET) + if (LibuvConstants.IsConnectionReset(status)) { _log.ConnectionReset(_connectionId); } From d4f263acce8e0d67faffc6184d601c887cb052af Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Mon, 16 Oct 2017 11:55:47 -0700 Subject: [PATCH 1432/1662] Fix typos in project names. --- KestrelHttpServer.sln | 4 ++-- ....csproj => Kestrel.Transport.Libuv.FunctionalTests.csproj} | 0 ...sproj => Kestrel.Transport.Sockets.FunctionalTests.csproj} | 0 3 files changed, 2 insertions(+), 2 deletions(-) rename test/Kestrel.Transport.Libuv.FunctionalTests/{Kestrel.Trasnport.Libuv.FunctionalTests.csproj => Kestrel.Transport.Libuv.FunctionalTests.csproj} (100%) rename test/Kestrel.Transport.Sockets.FunctionalTests/{Kestrel.Trasnport.Sockets.FunctionalTests.csproj => Kestrel.Transport.Sockets.FunctionalTests.csproj} (100%) diff --git a/KestrelHttpServer.sln b/KestrelHttpServer.sln index 2f3786bd6c..8ec3d0f3a6 100644 --- a/KestrelHttpServer.sln +++ b/KestrelHttpServer.sln @@ -117,9 +117,9 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "SystemdActivation", "System test\SystemdActivation\Dockerfile = test\SystemdActivation\Dockerfile EndProjectSection EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Kestrel.Transport.Libuv.FunctionalTests", "test\Kestrel.Transport.Libuv.FunctionalTests\Kestrel.Trasnport.Libuv.FunctionalTests.csproj", "{74032D79-8EA7-4483-BD82-C38370420FFF}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Kestrel.Transport.Libuv.FunctionalTests", "test\Kestrel.Transport.Libuv.FunctionalTests\Kestrel.Transport.Libuv.FunctionalTests.csproj", "{74032D79-8EA7-4483-BD82-C38370420FFF}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Kestrel.Transport.Sockets.FunctionalTests", "test\Kestrel.Transport.Sockets.FunctionalTests\Kestrel.Trasnport.Sockets.FunctionalTests.csproj", "{9C7B6B5F-088A-436E-834B-6373EA36DEEE}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Kestrel.Transport.Sockets.FunctionalTests", "test\Kestrel.Transport.Sockets.FunctionalTests\Kestrel.Transport.Sockets.FunctionalTests.csproj", "{9C7B6B5F-088A-436E-834B-6373EA36DEEE}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/test/Kestrel.Transport.Libuv.FunctionalTests/Kestrel.Trasnport.Libuv.FunctionalTests.csproj b/test/Kestrel.Transport.Libuv.FunctionalTests/Kestrel.Transport.Libuv.FunctionalTests.csproj similarity index 100% rename from test/Kestrel.Transport.Libuv.FunctionalTests/Kestrel.Trasnport.Libuv.FunctionalTests.csproj rename to test/Kestrel.Transport.Libuv.FunctionalTests/Kestrel.Transport.Libuv.FunctionalTests.csproj diff --git a/test/Kestrel.Transport.Sockets.FunctionalTests/Kestrel.Trasnport.Sockets.FunctionalTests.csproj b/test/Kestrel.Transport.Sockets.FunctionalTests/Kestrel.Transport.Sockets.FunctionalTests.csproj similarity index 100% rename from test/Kestrel.Transport.Sockets.FunctionalTests/Kestrel.Trasnport.Sockets.FunctionalTests.csproj rename to test/Kestrel.Transport.Sockets.FunctionalTests/Kestrel.Transport.Sockets.FunctionalTests.csproj From 34c3233db929cfa60ac581138dae7536d1c5065d Mon Sep 17 00:00:00 2001 From: Ryan Brandenburg Date: Mon, 16 Oct 2017 12:50:44 -0700 Subject: [PATCH 1433/1662] Add RepositoryRoot --- Directory.Build.props | 1 + 1 file changed, 1 insertion(+) diff --git a/Directory.Build.props b/Directory.Build.props index ea64574519..e36ea7fde0 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -5,6 +5,7 @@ Microsoft ASP.NET Core https://github.com/aspnet/KestrelHttpServer git + $(MSBuildThisFileDirectory) $(MSBuildThisFileDirectory)build\Key.snk true true From c57aa3b2a83d819d0529fce5018ac073d1bc2526 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Wed, 18 Oct 2017 12:40:37 -0700 Subject: [PATCH 1434/1662] Treat more exceptions from Socket.ReceiveAsync as aborted connections (#2122) --- src/Kestrel.Transport.Sockets/SocketConnection.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Kestrel.Transport.Sockets/SocketConnection.cs b/src/Kestrel.Transport.Sockets/SocketConnection.cs index 6a7f765afc..649db3cd07 100644 --- a/src/Kestrel.Transport.Sockets/SocketConnection.cs +++ b/src/Kestrel.Transport.Sockets/SocketConnection.cs @@ -136,8 +136,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets _trace.ConnectionReset(ConnectionId); } catch (SocketException ex) when (ex.SocketErrorCode == SocketError.OperationAborted || - ex.SocketErrorCode == SocketError.Interrupted) + ex.SocketErrorCode == SocketError.ConnectionAborted || + ex.SocketErrorCode == SocketError.Interrupted || + ex.SocketErrorCode == SocketError.InvalidArgument) { + // Calling Dispose after ReceiveAsync can cause an "InvalidArgument" error on *nix. error = new ConnectionAbortedException(); _trace.ConnectionError(ConnectionId, error); } From 3fbfba63f813de004030615546546360b565b8d5 Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Wed, 18 Oct 2017 16:31:50 -0700 Subject: [PATCH 1435/1662] HTTP/2: implement 100-continue (#2106) --- .../Internal/Http/Http1MessageBody.cs | 10 ----- src/Kestrel.Core/Internal/Http/MessageBody.cs | 12 +++++- .../Internal/Http2/Http2FrameWriter.cs | 12 +++++- .../Internal/Http2/Http2MessageBody.cs | 9 ++++ .../Internal/Http2/Http2Stream.cs | 2 + .../Http2ConnectionTests.cs | 41 +++++++++++++++++++ 6 files changed, 74 insertions(+), 12 deletions(-) diff --git a/src/Kestrel.Core/Internal/Http/Http1MessageBody.cs b/src/Kestrel.Core/Internal/Http/Http1MessageBody.cs index 4f623108d8..9b50aba2e3 100644 --- a/src/Kestrel.Core/Internal/Http/Http1MessageBody.cs +++ b/src/Kestrel.Core/Internal/Http/Http1MessageBody.cs @@ -14,7 +14,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { private readonly Http1Connection _context; - private bool _send100Continue = true; private volatile bool _canceled; private Task _pumpTask; @@ -150,15 +149,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http } } - private void TryProduceContinue() - { - if (_send100Continue) - { - _context.HttpResponseControl.ProduceContinue(); - _send100Continue = false; - } - } - protected void Copy(ReadableBuffer readableBuffer, WritableBuffer writableBuffer) { _context.TimeoutControl.BytesRead(readableBuffer.Length); diff --git a/src/Kestrel.Core/Internal/Http/MessageBody.cs b/src/Kestrel.Core/Internal/Http/MessageBody.cs index 8ae912435a..2fd8c12e60 100644 --- a/src/Kestrel.Core/Internal/Http/MessageBody.cs +++ b/src/Kestrel.Core/Internal/Http/MessageBody.cs @@ -6,7 +6,6 @@ using System.IO; using System.IO.Pipelines; using System.Threading; using System.Threading.Tasks; -using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http @@ -18,6 +17,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http private readonly HttpProtocol _context; + private bool _send100Continue = true; + protected MessageBody(HttpProtocol context) { _context = context; @@ -111,6 +112,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http public abstract Task StopAsync(); + protected void TryProduceContinue() + { + if (_send100Continue) + { + _context.HttpResponseControl.ProduceContinue(); + _send100Continue = false; + } + } + private void TryInit() { if (!_context.HasStartedConsumingRequestBody) diff --git a/src/Kestrel.Core/Internal/Http2/Http2FrameWriter.cs b/src/Kestrel.Core/Internal/Http2/Http2FrameWriter.cs index fb2468d0c4..a34bf0ef53 100644 --- a/src/Kestrel.Core/Internal/Http2/Http2FrameWriter.cs +++ b/src/Kestrel.Core/Internal/Http2/Http2FrameWriter.cs @@ -14,6 +14,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 { public class Http2FrameWriter : IHttp2FrameWriter { + // Literal Header Field without Indexing - Indexed Name (Index 8 - :status) + private static readonly byte[] _continueBytes = new byte[] { 0x08, 0x03, (byte)'1', (byte)'0', (byte)'0' }; + private readonly Http2Frame _outgoingFrame = new Http2Frame(); private readonly object _writeLock = new object(); private readonly HPackEncoder _hpackEncoder = new HPackEncoder(); @@ -50,7 +53,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 public Task Write100ContinueAsync(int streamId) { - return Task.CompletedTask; + lock (_writeLock) + { + _outgoingFrame.PrepareHeaders(Http2HeadersFrameFlags.END_HEADERS, streamId); + _outgoingFrame.Length = _continueBytes.Length; + _continueBytes.CopyTo(_outgoingFrame.HeadersPayload); + + return WriteAsync(_outgoingFrame.Raw); + } } public void WriteResponseHeaders(int streamId, int statusCode, IHeaderDictionary headers) diff --git a/src/Kestrel.Core/Internal/Http2/Http2MessageBody.cs b/src/Kestrel.Core/Internal/Http2/Http2MessageBody.cs index 71a308a8f7..b6ad3af161 100644 --- a/src/Kestrel.Core/Internal/Http2/Http2MessageBody.cs +++ b/src/Kestrel.Core/Internal/Http2/Http2MessageBody.cs @@ -16,6 +16,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 _context = context; } + protected override void OnReadStarted() + { + // Produce 100-continue if no request body data for the stream has arrived yet. + if (!_context.RequestBodyStarted) + { + TryProduceContinue(); + } + } + protected override Task OnConsumeAsync() => Task.CompletedTask; public override Task StopAsync() diff --git a/src/Kestrel.Core/Internal/Http2/Http2Stream.cs b/src/Kestrel.Core/Internal/Http2/Http2Stream.cs index b8f9db04ee..c9832ef03d 100644 --- a/src/Kestrel.Core/Internal/Http2/Http2Stream.cs +++ b/src/Kestrel.Core/Internal/Http2/Http2Stream.cs @@ -24,6 +24,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 public int StreamId => _context.StreamId; + public bool RequestBodyStarted { get; private set; } public bool EndStreamReceived { get; private set; } protected IHttp2StreamLifetimeHandler StreamLifetimeHandler => _context.StreamLifetimeHandler; @@ -84,6 +85,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 writableBuffer.Commit(); } + RequestBodyStarted = true; await writableBuffer.FlushAsync(); } diff --git a/test/Kestrel.Core.Tests/Http2ConnectionTests.cs b/test/Kestrel.Core.Tests/Http2ConnectionTests.cs index 39db80b4a4..e4a875da58 100644 --- a/test/Kestrel.Core.Tests/Http2ConnectionTests.cs +++ b/test/Kestrel.Core.Tests/Http2ConnectionTests.cs @@ -33,6 +33,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests new KeyValuePair(":scheme", "http"), }; + private static readonly IEnumerable> _expectContinueRequestHeaders = new[] + { + new KeyValuePair(":method", "POST"), + new KeyValuePair(":path", "/"), + new KeyValuePair(":authority", "127.0.0.1"), + new KeyValuePair(":scheme", "https"), + new KeyValuePair("expect", "100-continue"), + }; + private static readonly IEnumerable> _browserRequestHeaders = new[] { new KeyValuePair(":method", "GET"), @@ -755,6 +764,38 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests await StopConnectionAsync(expectedLastStreamId: 3, ignoreNonGoAwayFrames: false); } + [Fact] + public async Task HEADERS_Received_ContainsExpect100Continue_100ContinueSent() + { + await InitializeConnectionAsync(_echoApplication); + + await StartStreamAsync(1, _expectContinueRequestHeaders, false); + + var frame = await ExpectAsync(Http2FrameType.HEADERS, + withLength: 5, + withFlags: (byte)Http2HeadersFrameFlags.END_HEADERS, + withStreamId: 1); + + await SendDataAsync(1, _helloBytes, endStream: true); + + await ExpectAsync(Http2FrameType.HEADERS, + withLength: 37, + withFlags: (byte)Http2HeadersFrameFlags.END_HEADERS, + withStreamId: 1); + await ExpectAsync(Http2FrameType.DATA, + withLength: 5, + withFlags: (byte)Http2DataFrameFlags.NONE, + withStreamId: 1); + await ExpectAsync(Http2FrameType.DATA, + withLength: 0, + withFlags: (byte)Http2DataFrameFlags.END_STREAM, + withStreamId: 1); + + Assert.Equal(new byte[] { 0x08, 0x03, (byte)'1', (byte)'0', (byte)'0' }, frame.HeadersPayload.ToArray()); + + await StopConnectionAsync(expectedLastStreamId: 1, ignoreNonGoAwayFrames: false); + } + [Fact] public async Task HEADERS_Received_StreamIdZero_ConnectionError() { From fff3e1ebd0bf063c764eedb641db227a6dde3a5d Mon Sep 17 00:00:00 2001 From: Pavel Krymets Date: Mon, 23 Oct 2017 09:51:00 -0700 Subject: [PATCH 1436/1662] Validate benchmarks (#2126) --- .../DotSegmentRemovalBenchmark.cs | 2 +- ...Http1ConnectionParsingOverheadBenchmark.cs | 24 ++++++++++++------- .../Http1WritingBenchmark.cs | 2 +- .../HttpParserBenchmark.cs | 2 +- .../HttpProtocolFeatureCollection.cs | 24 +++++++++++++------ .../Kestrel.Performance.csproj | 4 ++-- .../KnownStringsBenchmark.cs | 1 + .../PipeThroughputBenchmark.cs | 2 +- benchmarks/Kestrel.Performance/Program.cs | 16 ------------- .../RequestParsingBenchmark.cs | 24 ++++++++++++------- .../ResponseHeaderCollectionBenchmark.cs | 23 +++++++++++------- .../ResponseHeadersWritingBenchmark.cs | 2 +- .../StringUtilitiesBenchmark.cs | 2 +- .../Kestrel.Performance/configs/CoreConfig.cs | 23 +++++++++++------- build/repo.props | 6 ++--- 15 files changed, 90 insertions(+), 67 deletions(-) delete mode 100644 benchmarks/Kestrel.Performance/Program.cs diff --git a/benchmarks/Kestrel.Performance/DotSegmentRemovalBenchmark.cs b/benchmarks/Kestrel.Performance/DotSegmentRemovalBenchmark.cs index 5e65f9aa03..caa43f2b58 100644 --- a/benchmarks/Kestrel.Performance/DotSegmentRemovalBenchmark.cs +++ b/benchmarks/Kestrel.Performance/DotSegmentRemovalBenchmark.cs @@ -8,7 +8,7 @@ using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; namespace Microsoft.AspNetCore.Server.Kestrel.Performance { - [Config(typeof(CoreConfig))] + [ParameterizedJobConfig(typeof(CoreConfig))] public class DotSegmentRemovalBenchmark { // Immutable diff --git a/benchmarks/Kestrel.Performance/Http1ConnectionParsingOverheadBenchmark.cs b/benchmarks/Kestrel.Performance/Http1ConnectionParsingOverheadBenchmark.cs index b582379697..208d9eca15 100644 --- a/benchmarks/Kestrel.Performance/Http1ConnectionParsingOverheadBenchmark.cs +++ b/benchmarks/Kestrel.Performance/Http1ConnectionParsingOverheadBenchmark.cs @@ -11,7 +11,7 @@ using Microsoft.AspNetCore.Server.Kestrel.Performance.Mocks; namespace Microsoft.AspNetCore.Server.Kestrel.Performance { - [Config(typeof(CoreConfig))] + [ParameterizedJobConfig(typeof(CoreConfig))] public class Http1ConnectionParsingOverheadBenchmark { private const int InnerLoopCount = 512; @@ -22,20 +22,28 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance [IterationSetup] public void Setup() { + var pipeFactory = new PipeFactory(); + var pair = pipeFactory.CreateConnectionPair(); + var serviceContext = new ServiceContext { - HttpParserFactory = _ => NullParser.Instance, - ServerOptions = new KestrelServerOptions() + ServerOptions = new KestrelServerOptions(), + HttpParserFactory = f => NullParser.Instance }; - var http1ConnectionContext = new Http1ConnectionContext + + var http1Connection = new Http1Connection(application: null, context: new Http1ConnectionContext { ServiceContext = serviceContext, ConnectionFeatures = new FeatureCollection(), - PipeFactory = new PipeFactory(), - TimeoutControl = new MockTimeoutControl() - }; + PipeFactory = pipeFactory, + TimeoutControl = new MockTimeoutControl(), + Application = pair.Application, + Transport = pair.Transport + }); - _http1Connection = new Http1Connection(application: null, context: http1ConnectionContext); + http1Connection.Reset(); + + _http1Connection = http1Connection; } [Benchmark(Baseline = true, OperationsPerInvoke = InnerLoopCount)] diff --git a/benchmarks/Kestrel.Performance/Http1WritingBenchmark.cs b/benchmarks/Kestrel.Performance/Http1WritingBenchmark.cs index a1a491a7dd..c216433f50 100644 --- a/benchmarks/Kestrel.Performance/Http1WritingBenchmark.cs +++ b/benchmarks/Kestrel.Performance/Http1WritingBenchmark.cs @@ -15,7 +15,7 @@ using Microsoft.AspNetCore.Testing; namespace Microsoft.AspNetCore.Server.Kestrel.Performance { - [Config(typeof(CoreConfig))] + [ParameterizedJobConfig(typeof(CoreConfig))] public class Http1WritingBenchmark { // Standard completed task diff --git a/benchmarks/Kestrel.Performance/HttpParserBenchmark.cs b/benchmarks/Kestrel.Performance/HttpParserBenchmark.cs index 934b543594..0bf1a6fca4 100644 --- a/benchmarks/Kestrel.Performance/HttpParserBenchmark.cs +++ b/benchmarks/Kestrel.Performance/HttpParserBenchmark.cs @@ -8,7 +8,7 @@ using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; namespace Microsoft.AspNetCore.Server.Kestrel.Performance { - [Config(typeof(CoreConfig))] + [ParameterizedJobConfig(typeof(CoreConfig))] public class HttpParserBenchmark : IHttpRequestLineHandler, IHttpHeadersHandler { diff --git a/benchmarks/Kestrel.Performance/HttpProtocolFeatureCollection.cs b/benchmarks/Kestrel.Performance/HttpProtocolFeatureCollection.cs index f637269c3c..f461fe470b 100644 --- a/benchmarks/Kestrel.Performance/HttpProtocolFeatureCollection.cs +++ b/benchmarks/Kestrel.Performance/HttpProtocolFeatureCollection.cs @@ -11,7 +11,7 @@ using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; namespace Microsoft.AspNetCore.Server.Kestrel.Performance { - [Config(typeof(CoreConfig))] + [ParameterizedJobConfig(typeof(CoreConfig))] public class HttpProtocolFeatureCollection { private readonly Http1Connection _http1Connection; @@ -77,19 +77,29 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance public HttpProtocolFeatureCollection() { + var pipeFactory = new PipeFactory(); + var pair = pipeFactory.CreateConnectionPair(); + var serviceContext = new ServiceContext { - HttpParserFactory = _ => NullParser.Instance, - ServerOptions = new KestrelServerOptions() + DateHeaderValueManager = new DateHeaderValueManager(), + ServerOptions = new KestrelServerOptions(), + Log = new MockTrace(), + HttpParserFactory = f => new HttpParser() }; - var http1ConnectionContext = new Http1ConnectionContext + + var http1Connection = new Http1Connection(application: null, context: new Http1ConnectionContext { ServiceContext = serviceContext, ConnectionFeatures = new FeatureCollection(), - PipeFactory = new PipeFactory() - }; + PipeFactory = pipeFactory, + Application = pair.Application, + Transport = pair.Transport + }); - _http1Connection = new Http1Connection(application: null, context: http1ConnectionContext); + http1Connection.Reset(); + + _http1Connection = http1Connection; } [IterationSetup] diff --git a/benchmarks/Kestrel.Performance/Kestrel.Performance.csproj b/benchmarks/Kestrel.Performance/Kestrel.Performance.csproj index 24548de865..4797141dcb 100644 --- a/benchmarks/Kestrel.Performance/Kestrel.Performance.csproj +++ b/benchmarks/Kestrel.Performance/Kestrel.Performance.csproj @@ -4,8 +4,7 @@ Kestrel.Performance Microsoft.AspNetCore.Server.Kestrel.Performance - netcoreapp2.0;net461 - netcoreapp2.0 + netcoreapp2.0 Exe true true @@ -24,6 +23,7 @@ + diff --git a/benchmarks/Kestrel.Performance/KnownStringsBenchmark.cs b/benchmarks/Kestrel.Performance/KnownStringsBenchmark.cs index 69bf2d5adb..095d568360 100644 --- a/benchmarks/Kestrel.Performance/KnownStringsBenchmark.cs +++ b/benchmarks/Kestrel.Performance/KnownStringsBenchmark.cs @@ -9,6 +9,7 @@ using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; namespace Microsoft.AspNetCore.Server.Kestrel.Performance { + [ParameterizedJobConfig(typeof(CoreConfig))] public class KnownStringsBenchmark { static byte[] _methodConnect = Encoding.ASCII.GetBytes("CONNECT "); diff --git a/benchmarks/Kestrel.Performance/PipeThroughputBenchmark.cs b/benchmarks/Kestrel.Performance/PipeThroughputBenchmark.cs index 7af128c11d..15ea0c4cae 100644 --- a/benchmarks/Kestrel.Performance/PipeThroughputBenchmark.cs +++ b/benchmarks/Kestrel.Performance/PipeThroughputBenchmark.cs @@ -7,7 +7,7 @@ using BenchmarkDotNet.Attributes; namespace Microsoft.AspNetCore.Server.Kestrel.Performance { - [Config(typeof(CoreConfig))] + [ParameterizedJobConfig(typeof(CoreConfig))] public class PipeThroughputBenchmark { private const int _writeLenght = 57; diff --git a/benchmarks/Kestrel.Performance/Program.cs b/benchmarks/Kestrel.Performance/Program.cs deleted file mode 100644 index 2c73b19ef8..0000000000 --- a/benchmarks/Kestrel.Performance/Program.cs +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System.Reflection; -using BenchmarkDotNet.Running; - -namespace Microsoft.AspNetCore.Server.Kestrel.Performance -{ - public class Program - { - public static void Main(string[] args) - { - BenchmarkSwitcher.FromAssembly(typeof(Program).GetTypeInfo().Assembly).Run(args); - } - } -} diff --git a/benchmarks/Kestrel.Performance/RequestParsingBenchmark.cs b/benchmarks/Kestrel.Performance/RequestParsingBenchmark.cs index f7355007cc..7f5c44c437 100644 --- a/benchmarks/Kestrel.Performance/RequestParsingBenchmark.cs +++ b/benchmarks/Kestrel.Performance/RequestParsingBenchmark.cs @@ -11,7 +11,7 @@ using Microsoft.AspNetCore.Server.Kestrel.Performance.Mocks; namespace Microsoft.AspNetCore.Server.Kestrel.Performance { - [Config(typeof(CoreConfig))] + [ParameterizedJobConfig(typeof(CoreConfig))] public class RequestParsingBenchmark { public IPipe Pipe { get; set; } @@ -23,23 +23,31 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance [IterationSetup] public void Setup() { - PipeFactory = new PipeFactory(); - Pipe = PipeFactory.Create(); + var pipeFactory = new PipeFactory(); + var pair = pipeFactory.CreateConnectionPair(); var serviceContext = new ServiceContext { - HttpParserFactory = f => new HttpParser(), + DateHeaderValueManager = new DateHeaderValueManager(), ServerOptions = new KestrelServerOptions(), + Log = new MockTrace(), + HttpParserFactory = f => new HttpParser() }; - var http1ConnectionContext = new Http1ConnectionContext + + var http1Connection = new Http1Connection(application: null, context: new Http1ConnectionContext { ServiceContext = serviceContext, ConnectionFeatures = new FeatureCollection(), - PipeFactory = PipeFactory, + PipeFactory = pipeFactory, + Application = pair.Application, + Transport = pair.Transport, TimeoutControl = new MockTimeoutControl() - }; + }); - Http1Connection = new Http1Connection(application: null, context: http1ConnectionContext); + http1Connection.Reset(); + + Http1Connection = http1Connection; + Pipe = pipeFactory.Create(); } [Benchmark(Baseline = true, OperationsPerInvoke = RequestParsingData.InnerLoopCount)] diff --git a/benchmarks/Kestrel.Performance/ResponseHeaderCollectionBenchmark.cs b/benchmarks/Kestrel.Performance/ResponseHeaderCollectionBenchmark.cs index b2ed0ae549..36207e4296 100644 --- a/benchmarks/Kestrel.Performance/ResponseHeaderCollectionBenchmark.cs +++ b/benchmarks/Kestrel.Performance/ResponseHeaderCollectionBenchmark.cs @@ -14,7 +14,7 @@ using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; namespace Microsoft.AspNetCore.Server.Kestrel.Performance { - [Config(typeof(CoreConfig))] + [ParameterizedJobConfig(typeof(CoreConfig))] public class ResponseHeaderCollectionBenchmark { private const int InnerLoopCount = 512; @@ -170,21 +170,28 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance [IterationSetup] public void Setup() { + var pipeFactory = new PipeFactory(); + var pair = pipeFactory.CreateConnectionPair(); + var serviceContext = new ServiceContext { - HttpParserFactory = f => new HttpParser(), - ServerOptions = new KestrelServerOptions() + DateHeaderValueManager = new DateHeaderValueManager(), + ServerOptions = new KestrelServerOptions(), + Log = new MockTrace(), + HttpParserFactory = f => new HttpParser() }; - var http1ConnectionContext = new Http1ConnectionContext + + var http1Connection = new Http1Connection(application: null, context: new Http1ConnectionContext { ServiceContext = serviceContext, ConnectionFeatures = new FeatureCollection(), - PipeFactory = new PipeFactory() - }; - - var http1Connection = new Http1Connection(application: null, context: http1ConnectionContext); + PipeFactory = pipeFactory, + Application = pair.Application, + Transport = pair.Transport + }); http1Connection.Reset(); + _responseHeadersDirect = (HttpResponseHeaders)http1Connection.ResponseHeaders; var context = new DefaultHttpContext(http1Connection); _response = new DefaultHttpResponse(context); diff --git a/benchmarks/Kestrel.Performance/ResponseHeadersWritingBenchmark.cs b/benchmarks/Kestrel.Performance/ResponseHeadersWritingBenchmark.cs index 6604d7afbb..8443e13a5b 100644 --- a/benchmarks/Kestrel.Performance/ResponseHeadersWritingBenchmark.cs +++ b/benchmarks/Kestrel.Performance/ResponseHeadersWritingBenchmark.cs @@ -16,7 +16,7 @@ using Microsoft.AspNetCore.Testing; namespace Microsoft.AspNetCore.Server.Kestrel.Performance { - [Config(typeof(CoreConfig))] + [ParameterizedJobConfig(typeof(CoreConfig))] public class ResponseHeadersWritingBenchmark { private static readonly byte[] _helloWorldPayload = Encoding.ASCII.GetBytes("Hello, World!"); diff --git a/benchmarks/Kestrel.Performance/StringUtilitiesBenchmark.cs b/benchmarks/Kestrel.Performance/StringUtilitiesBenchmark.cs index 8097a8b744..3d1b8aee01 100644 --- a/benchmarks/Kestrel.Performance/StringUtilitiesBenchmark.cs +++ b/benchmarks/Kestrel.Performance/StringUtilitiesBenchmark.cs @@ -6,7 +6,7 @@ using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; namespace Microsoft.AspNetCore.Server.Kestrel.Performance { - [Config(typeof(CoreConfig))] + [ParameterizedJobConfig(typeof(CoreConfig))] public class StringUtilitiesBenchmark { private const int Iterations = 500_000; diff --git a/benchmarks/Kestrel.Performance/configs/CoreConfig.cs b/benchmarks/Kestrel.Performance/configs/CoreConfig.cs index 49897ae207..98f1ab03fd 100644 --- a/benchmarks/Kestrel.Performance/configs/CoreConfig.cs +++ b/benchmarks/Kestrel.Performance/configs/CoreConfig.cs @@ -12,20 +12,25 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance { public class CoreConfig : ManualConfig { - public CoreConfig() - { - Add(JitOptimizationsValidator.FailOnError); - Add(MemoryDiagnoser.Default); - Add(StatisticColumn.OperationsPerSecond); - - Add(Job.Default - .With(BenchmarkDotNet.Environments.Runtime.Core) + public CoreConfig() : this(Job.Core .WithRemoveOutliers(false) .With(new GcMode() { Server = true }) .With(RunStrategy.Throughput) .WithLaunchCount(3) .WithWarmupCount(5) - .WithTargetCount(10)); + .WithTargetCount(10)) + { + Add(JitOptimizationsValidator.FailOnError); + } + + public CoreConfig(Job job) + { + Add(DefaultConfig.Instance); + + Add(MemoryDiagnoser.Default); + Add(StatisticColumn.OperationsPerSecond); + + Add(job); } } } diff --git a/build/repo.props b/build/repo.props index de0440bdd2..eadaa28976 100644 --- a/build/repo.props +++ b/build/repo.props @@ -1,8 +1,8 @@ + + true + - - - From 30010a103bb20f913d00f64d49a9914d37eb8650 Mon Sep 17 00:00:00 2001 From: Andrew Stanton-Nurse Date: Mon, 23 Oct 2017 10:52:02 -0700 Subject: [PATCH 1437/1662] Fix for #2085 - "The Detaskening" (#2123) --- .../Internal/Http/Http1Connection.cs | 116 ++++++++++-------- .../Internal/Http/HttpProtocol.cs | 28 ++++- .../Internal/Http2/Http2Stream.cs | 8 +- 3 files changed, 96 insertions(+), 56 deletions(-) diff --git a/src/Kestrel.Core/Internal/Http/Http1Connection.cs b/src/Kestrel.Core/Internal/Http/Http1Connection.cs index 9357a9d742..b5d9c0235a 100644 --- a/src/Kestrel.Core/Internal/Http/Http1Connection.cs +++ b/src/Kestrel.Core/Internal/Http/Http1Connection.cs @@ -413,67 +413,81 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http protected override MessageBody CreateMessageBody() => Http1MessageBody.For(_httpVersion, HttpRequestHeaders, this); - protected override async Task ParseRequestAsync() + protected override void BeginRequestProcessing() { + // Reset the features and timeout. Reset(); TimeoutControl.SetTimeout(_keepAliveTicks, TimeoutAction.StopProcessingNextRequest); + } - while (_requestProcessingStatus != RequestProcessingStatus.AppStarted) + protected override bool BeginRead(out ReadableBufferAwaitable awaitable) + { + awaitable = Input.ReadAsync(); + return true; + } + + protected override bool TryParseRequest(ReadResult result, out bool endConnection) + { + var examined = result.Buffer.End; + var consumed = result.Buffer.End; + + try { - var result = await Input.ReadAsync(); - - var examined = result.Buffer.End; - var consumed = result.Buffer.End; - - try + ParseRequest(result.Buffer, out consumed, out examined); + } + catch (InvalidOperationException) + { + if (_requestProcessingStatus == RequestProcessingStatus.ParsingHeaders) { - ParseRequest(result.Buffer, out consumed, out examined); - } - catch (InvalidOperationException) - { - if (_requestProcessingStatus == RequestProcessingStatus.ParsingHeaders) - { - throw BadHttpRequestException.GetException(RequestRejectionReason - .MalformedRequestInvalidHeaders); - } - throw; - } - finally - { - Input.Advance(consumed, examined); - } - - if (result.IsCompleted) - { - switch (_requestProcessingStatus) - { - case RequestProcessingStatus.RequestPending: - return false; - case RequestProcessingStatus.ParsingRequestLine: - throw BadHttpRequestException.GetException( - RequestRejectionReason.InvalidRequestLine); - case RequestProcessingStatus.ParsingHeaders: - throw BadHttpRequestException.GetException( - RequestRejectionReason.MalformedRequestInvalidHeaders); - } - } - else if (!_keepAlive && _requestProcessingStatus == RequestProcessingStatus.RequestPending) - { - // Stop the request processing loop if the server is shutting down or there was a keep-alive timeout - // and there is no ongoing request. - return false; - } - else if (RequestTimedOut) - { - // In this case, there is an ongoing request but the start line/header parsing has timed out, so send - // a 408 response. - throw BadHttpRequestException.GetException(RequestRejectionReason.RequestTimeout); + throw BadHttpRequestException.GetException(RequestRejectionReason + .MalformedRequestInvalidHeaders); } + throw; + } + finally + { + Input.Advance(consumed, examined); } - EnsureHostHeaderExists(); + if (result.IsCompleted) + { + switch (_requestProcessingStatus) + { + case RequestProcessingStatus.RequestPending: + endConnection = true; + return true; + case RequestProcessingStatus.ParsingRequestLine: + throw BadHttpRequestException.GetException( + RequestRejectionReason.InvalidRequestLine); + case RequestProcessingStatus.ParsingHeaders: + throw BadHttpRequestException.GetException( + RequestRejectionReason.MalformedRequestInvalidHeaders); + } + } + else if (!_keepAlive && _requestProcessingStatus == RequestProcessingStatus.RequestPending) + { + // Stop the request processing loop if the server is shutting down or there was a keep-alive timeout + // and there is no ongoing request. + endConnection = true; + return true; + } + else if (RequestTimedOut) + { + // In this case, there is an ongoing request but the start line/header parsing has timed out, so send + // a 408 response. + throw BadHttpRequestException.GetException(RequestRejectionReason.RequestTimeout); + } - return true; + endConnection = false; + if (_requestProcessingStatus == RequestProcessingStatus.AppStarted) + { + EnsureHostHeaderExists(); + return true; + } + else + { + return false; + } } } } diff --git a/src/Kestrel.Core/Internal/Http/HttpProtocol.cs b/src/Kestrel.Core/Internal/Http/HttpProtocol.cs index 7ac194dd6e..9f6c11740d 100644 --- a/src/Kestrel.Core/Internal/Http/HttpProtocol.cs +++ b/src/Kestrel.Core/Internal/Http/HttpProtocol.cs @@ -375,11 +375,21 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { } + protected virtual void BeginRequestProcessing() + { + } + + protected virtual bool BeginRead(out ReadableBufferAwaitable awaitable) + { + awaitable = default; + return false; + } + protected abstract string CreateRequestId(); protected abstract MessageBody CreateMessageBody(); - protected abstract Task ParseRequestAsync(); + protected abstract bool TryParseRequest(ReadResult result, out bool endConnection); protected abstract void CreateHttpContext(); @@ -436,7 +446,19 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { while (_keepAlive) { - if (!await ParseRequestAsync()) + BeginRequestProcessing(); + + var result = default(ReadResult); + var endConnection = false; + do + { + if (BeginRead(out var awaitable)) + { + result = await awaitable; + } + } while (!TryParseRequest(result, out endConnection)); + + if (endConnection) { return; } @@ -655,7 +677,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http try { var count = onStarting.Count; - for(var i = 0; i < count; i++) + for (var i = 0; i < count; i++) { var entry = onStarting.Pop(); var task = entry.Key.Invoke(entry.Value); diff --git a/src/Kestrel.Core/Internal/Http2/Http2Stream.cs b/src/Kestrel.Core/Internal/Http2/Http2Stream.cs index c9832ef03d..ea8a564d9f 100644 --- a/src/Kestrel.Core/Internal/Http2/Http2Stream.cs +++ b/src/Kestrel.Core/Internal/Http2/Http2Stream.cs @@ -47,8 +47,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 protected override MessageBody CreateMessageBody() => Http2MessageBody.For(HttpRequestHeaders, this); - protected override Task ParseRequestAsync() + protected override bool TryParseRequest(ReadResult result, out bool endConnection) { + // We don't need any of the parameters because we don't implement BeginRead to actually + // do the reading from a pipeline, nor do we use endConnection to report connection-level errors. + Method = RequestHeaders[":method"]; Scheme = RequestHeaders[":scheme"]; _httpVersion = Http.HttpVersion.Http2; @@ -62,7 +65,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 RequestHeaders["Host"] = RequestHeaders[":authority"]; - return Task.FromResult(true); + endConnection = false; + return true; } public async Task OnDataAsync(ArraySegment data, bool endStream) From 204cf7a1dc9d5f9a999df3f9f288b4b535b3132a Mon Sep 17 00:00:00 2001 From: Vladimir Sadov Date: Mon, 23 Oct 2017 16:18:15 -0700 Subject: [PATCH 1438/1662] This brings support for the final syntax of "ref readonly" and some bug fixes. (#2121) Noticeable changes: - use `in` at declaration of "in" parameters, not `ref readonly` - `ref` comes before `partial` when declaring partial ref structs. - unboxing conversions for ref-like types are statically rejected as impossible to succeed The corresponding VSIX to match these compiler bits with IDE experience is - https://dotnet.myget.org/F/roslyn/vsix/0b48e25b-9903-4d8b-ad39-d4cca196e3c7-2.6.0.6221102.vsix --- Directory.Build.props | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Directory.Build.props b/Directory.Build.props index e36ea7fde0..4f6edcfad9 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -15,7 +15,7 @@ - + @@ -462,4 +462,7 @@ Request headers contain connection-specific header field. - + + Unable to configure default https bindings because no IDefaultHttpsProvider service was provided. + + \ No newline at end of file diff --git a/src/Kestrel.Core/Internal/AddressBinder.cs b/src/Kestrel.Core/Internal/AddressBinder.cs index e4d1d18b93..808675c0fb 100644 --- a/src/Kestrel.Core/Internal/AddressBinder.cs +++ b/src/Kestrel.Core/Internal/AddressBinder.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -18,10 +18,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal internal class AddressBinder { public static async Task BindAsync(IServerAddressesFeature addresses, - List listenOptions, + KestrelServerOptions serverOptions, ILogger logger, + IDefaultHttpsProvider defaultHttpsProvider, Func createBinding) { + var listenOptions = serverOptions.ListenOptions; var strategy = CreateStrategy( listenOptions.ToArray(), addresses.Addresses.ToArray(), @@ -31,7 +33,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal { Addresses = addresses.Addresses, ListenOptions = listenOptions, + ServerOptions = serverOptions, Logger = logger, + DefaultHttpsProvider = defaultHttpsProvider ?? UnconfiguredDefaultHttpsProvider.Instance, CreateBinding = createBinding }; @@ -47,7 +51,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal { public ICollection Addresses { get; set; } public List ListenOptions { get; set; } + public KestrelServerOptions ServerOptions { get; set; } public ILogger Logger { get; set; } + public IDefaultHttpsProvider DefaultHttpsProvider { get; set; } public Func CreateBinding { get; set; } } @@ -120,7 +126,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal context.ListenOptions.Add(endpoint); } - private static async Task BindLocalhostAsync(ServerAddress address, AddressBindContext context) + private static async Task BindLocalhostAsync(ServerAddress address, AddressBindContext context, bool https) { if (address.Port == 0) { @@ -131,7 +137,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal try { - await BindEndpointAsync(new IPEndPoint(IPAddress.Loopback, address.Port), context).ConfigureAwait(false); + var options = new ListenOptions(new IPEndPoint(IPAddress.Loopback, address.Port)); + await BindEndpointAsync(options, context).ConfigureAwait(false); + + if (https) + { + options.KestrelServerOptions = context.ServerOptions; + context.DefaultHttpsProvider.ConfigureHttps(options); + } } catch (Exception ex) when (!(ex is IOException)) { @@ -141,7 +154,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal try { - await BindEndpointAsync(new IPEndPoint(IPAddress.IPv6Loopback, address.Port), context).ConfigureAwait(false); + var options = new ListenOptions(new IPEndPoint(IPAddress.IPv6Loopback, address.Port)); + await BindEndpointAsync(options, context).ConfigureAwait(false); + + if (https) + { + options.KestrelServerOptions = context.ServerOptions; + context.DefaultHttpsProvider.ConfigureHttps(options); + } } catch (Exception ex) when (!(ex is IOException)) { @@ -162,10 +182,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal private static async Task BindAddressAsync(string address, AddressBindContext context) { var parsedAddress = ServerAddress.FromUrl(address); + var https = false; if (parsedAddress.Scheme.Equals("https", StringComparison.OrdinalIgnoreCase)) { - throw new InvalidOperationException(CoreStrings.FormatConfigureHttpsFromMethodCall($"{nameof(KestrelServerOptions)}.{nameof(KestrelServerOptions.Listen)}()")); + https = true; } else if (!parsedAddress.Scheme.Equals("http", StringComparison.OrdinalIgnoreCase)) { @@ -177,20 +198,20 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal throw new InvalidOperationException(CoreStrings.FormatConfigurePathBaseFromMethodCall($"{nameof(IApplicationBuilder)}.UsePathBase()")); } + ListenOptions options = null; if (parsedAddress.IsUnixPipe) { - var endPoint = new ListenOptions(parsedAddress.UnixPipePath); - await BindEndpointAsync(endPoint, context).ConfigureAwait(false); - context.Addresses.Add(endPoint.GetDisplayName()); + options = new ListenOptions(parsedAddress.UnixPipePath); + await BindEndpointAsync(options, context).ConfigureAwait(false); + context.Addresses.Add(options.GetDisplayName()); } else if (string.Equals(parsedAddress.Host, "localhost", StringComparison.OrdinalIgnoreCase)) { // "localhost" for both IPv4 and IPv6 can't be represented as an IPEndPoint. - await BindLocalhostAsync(parsedAddress, context).ConfigureAwait(false); + await BindLocalhostAsync(parsedAddress, context, https).ConfigureAwait(false); } else { - ListenOptions options; if (TryCreateIPEndPoint(parsedAddress, out var endpoint)) { options = new ListenOptions(endpoint); @@ -216,6 +237,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal context.Addresses.Add(options.GetDisplayName()); } + + if (https && options != null) + { + options.KestrelServerOptions = context.ServerOptions; + context.DefaultHttpsProvider.ConfigureHttps(options); + } } private interface IStrategy @@ -229,7 +256,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal { context.Logger.LogDebug(CoreStrings.BindingToDefaultAddress, Constants.DefaultServerAddress); - await BindLocalhostAsync(ServerAddress.FromUrl(Constants.DefaultServerAddress), context).ConfigureAwait(false); + await BindLocalhostAsync(ServerAddress.FromUrl(Constants.DefaultServerAddress), context, https: false).ConfigureAwait(false); } } @@ -305,5 +332,22 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal } } } + + private class UnconfiguredDefaultHttpsProvider : IDefaultHttpsProvider + { + public static readonly UnconfiguredDefaultHttpsProvider Instance = new UnconfiguredDefaultHttpsProvider(); + + private UnconfiguredDefaultHttpsProvider() + { + } + + public void ConfigureHttps(ListenOptions listenOptions) + { + // We have to throw here. If this is called, it's because the user asked for "https" binding but for some + // reason didn't provide a certificate and didn't use the "DefaultHttpsProvider". This means if we no-op, + // we'll silently downgrade to HTTP, which is bad. + throw new InvalidOperationException(CoreStrings.UnableToConfigureHttpsBindings); + } + } } } diff --git a/src/Kestrel.Core/Internal/IDefaultHttpsProvider.cs b/src/Kestrel.Core/Internal/IDefaultHttpsProvider.cs new file mode 100644 index 0000000000..3ed67b0cda --- /dev/null +++ b/src/Kestrel.Core/Internal/IDefaultHttpsProvider.cs @@ -0,0 +1,10 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal +{ + public interface IDefaultHttpsProvider + { + void ConfigureHttps(ListenOptions listenOptions); + } +} diff --git a/src/Kestrel.Core/Internal/KestrelServerOptionsSetup.cs b/src/Kestrel.Core/Internal/KestrelServerOptionsSetup.cs index 18c96e2039..4d7a95ca5b 100644 --- a/src/Kestrel.Core/Internal/KestrelServerOptionsSetup.cs +++ b/src/Kestrel.Core/Internal/KestrelServerOptionsSetup.cs @@ -2,6 +2,8 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using Microsoft.AspNetCore.Hosting.Server.Features; +using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Options; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal diff --git a/src/Kestrel.Core/KestrelServer.cs b/src/Kestrel.Core/KestrelServer.cs index fac999d904..81536a44ab 100644 --- a/src/Kestrel.Core/KestrelServer.cs +++ b/src/Kestrel.Core/KestrelServer.cs @@ -22,6 +22,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core private readonly List _transports = new List(); private readonly Heartbeat _heartbeat; private readonly IServerAddressesFeature _serverAddresses; + private readonly IDefaultHttpsProvider _defaultHttpsProvider; private readonly ITransportFactory _transportFactory; private bool _hasStarted; @@ -33,6 +34,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core { } + public KestrelServer(IOptions options, ITransportFactory transportFactory, ILoggerFactory loggerFactory, IDefaultHttpsProvider defaultHttpsProvider) + : this(transportFactory, CreateServiceContext(options, loggerFactory)) + { + _defaultHttpsProvider = defaultHttpsProvider; + } + // For testing internal KestrelServer(ITransportFactory transportFactory, ServiceContext serviceContext) { @@ -152,7 +159,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core await transport.BindAsync().ConfigureAwait(false); } - await AddressBinder.BindAsync(_serverAddresses, Options.ListenOptions, Trace, OnBind).ConfigureAwait(false); + await AddressBinder.BindAsync(_serverAddresses, Options, Trace, _defaultHttpsProvider, OnBind).ConfigureAwait(false); } catch (Exception ex) { diff --git a/src/Kestrel.Core/Properties/CoreStrings.Designer.cs b/src/Kestrel.Core/Properties/CoreStrings.Designer.cs index 346b18a969..9321f1a2c9 100644 --- a/src/Kestrel.Core/Properties/CoreStrings.Designer.cs +++ b/src/Kestrel.Core/Properties/CoreStrings.Designer.cs @@ -1620,6 +1620,20 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core internal static string FormatHttp2ErrorConnectionSpecificHeaderField() => GetString("Http2ErrorConnectionSpecificHeaderField"); + /// + /// Unable to configure default https bindings because no IDefaultHttpsProvider service was provided. + /// + internal static string UnableToConfigureHttpsBindings + { + get => GetString("UnableToConfigureHttpsBindings"); + } + + /// + /// Unable to configure default https bindings because no IDefaultHttpsProvider service was provided. + /// + internal static string FormatUnableToConfigureHttpsBindings() + => GetString("UnableToConfigureHttpsBindings"); + private static string GetString(string name, params string[] formatterNames) { var value = _resourceManager.GetString(name); diff --git a/src/Kestrel.Https/ListenOptionsHttpsExtensions.cs b/src/Kestrel.Https/ListenOptionsHttpsExtensions.cs index 7cf8ab1b9e..44463ea10e 100644 --- a/src/Kestrel.Https/ListenOptionsHttpsExtensions.cs +++ b/src/Kestrel.Https/ListenOptionsHttpsExtensions.cs @@ -12,7 +12,7 @@ using Microsoft.Extensions.Logging; namespace Microsoft.AspNetCore.Hosting { /// - /// Extension methods fro that configure Kestrel to use HTTPS for a given endpoint. + /// Extension methods for that configure Kestrel to use HTTPS for a given endpoint. /// public static class ListenOptionsHttpsExtensions { diff --git a/src/Kestrel/Internal/DefaultHttpsProvider.cs b/src/Kestrel/Internal/DefaultHttpsProvider.cs new file mode 100644 index 0000000000..efc7d9fb10 --- /dev/null +++ b/src/Kestrel/Internal/DefaultHttpsProvider.cs @@ -0,0 +1,42 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Linq; +using System.Security.Cryptography.X509Certificates; +using Microsoft.AspNetCore.Certificates.Generation; +using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Server.Kestrel.Core; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal; +using Microsoft.Extensions.Logging; + +namespace Microsoft.AspNetCore.Server.Kestrel.Internal +{ + public class DefaultHttpsProvider : IDefaultHttpsProvider + { + private static readonly CertificateManager _certificateManager = new CertificateManager(); + + private readonly ILogger _logger; + + public DefaultHttpsProvider(ILogger logger) + { + _logger = logger; + } + + public void ConfigureHttps(ListenOptions listenOptions) + { + var certificate = _certificateManager.ListCertificates(CertificatePurpose.HTTPS, StoreName.My, StoreLocation.CurrentUser, isValid: true) + .FirstOrDefault(); + if (certificate != null) + { + _logger.LocatedDevelopmentCertificate(certificate); + listenOptions.UseHttps(certificate); + } + else + { + _logger.UnableToLocateDevelopmentCertificate(); + throw new InvalidOperationException(KestrelStrings.HttpsUrlProvidedButNoDevelopmentCertificateFound); + } + } + } +} diff --git a/src/Kestrel/Internal/LoggerExtensions.cs b/src/Kestrel/Internal/LoggerExtensions.cs new file mode 100644 index 0000000000..218f50ca10 --- /dev/null +++ b/src/Kestrel/Internal/LoggerExtensions.cs @@ -0,0 +1,20 @@ +using System; +using System.Security.Cryptography.X509Certificates; +using Microsoft.Extensions.Logging; + +namespace Microsoft.AspNetCore.Server.Kestrel.Internal +{ + internal static class LoggerExtensions + { + // Category: DefaultHttpsProvider + private static readonly Action _locatedDevelopmentCertificate = + LoggerMessage.Define(LogLevel.Debug, new EventId(0, nameof(LocatedDevelopmentCertificate)), "Using development certificate: {certificateSubjectName} (Thumbprint: {certificateThumbprint})"); + + private static readonly Action _unableToLocateDevelopmentCertificate = + LoggerMessage.Define(LogLevel.Error, new EventId(1, nameof(UnableToLocateDevelopmentCertificate)), "Unable to locate an appropriate development https certificate."); + + public static void LocatedDevelopmentCertificate(this ILogger logger, X509Certificate2 certificate) => _locatedDevelopmentCertificate(logger, certificate.Subject, certificate.Thumbprint, null); + + public static void UnableToLocateDevelopmentCertificate(this ILogger logger) => _unableToLocateDevelopmentCertificate(logger, null); + } +} diff --git a/src/Kestrel/Kestrel.csproj b/src/Kestrel/Kestrel.csproj index 1376f1e891..7f7f8de70b 100644 --- a/src/Kestrel/Kestrel.csproj +++ b/src/Kestrel/Kestrel.csproj @@ -12,10 +12,14 @@ + + + + diff --git a/src/Kestrel/KestrelStrings.resx b/src/Kestrel/KestrelStrings.resx new file mode 100644 index 0000000000..d39f8b5166 --- /dev/null +++ b/src/Kestrel/KestrelStrings.resx @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + Unable to configure HTTPS endpoint. Try running 'dotnet developercertificates https -t' to setup a developer certificate for use with localhost. For information on configuring HTTPS see https://go.microsoft.com/fwlink/?linkid=848054 + + \ No newline at end of file diff --git a/src/Kestrel/Properties/KestrelStrings.Designer.cs b/src/Kestrel/Properties/KestrelStrings.Designer.cs new file mode 100644 index 0000000000..ede41f12cf --- /dev/null +++ b/src/Kestrel/Properties/KestrelStrings.Designer.cs @@ -0,0 +1,44 @@ +// +namespace Microsoft.AspNetCore.Server.Kestrel +{ + using System.Globalization; + using System.Reflection; + using System.Resources; + + internal static class KestrelStrings + { + private static readonly ResourceManager _resourceManager + = new ResourceManager("Microsoft.AspNetCore.Server.Kestrel.KestrelStrings", typeof(KestrelStrings).GetTypeInfo().Assembly); + + /// + /// An 'https' URL was provided, but a development certificate could not be found. + /// + internal static string HttpsUrlProvidedButNoDevelopmentCertificateFound + { + get => GetString("HttpsUrlProvidedButNoDevelopmentCertificateFound"); + } + + /// + /// An 'https' URL was provided, but a development certificate could not be found. + /// + internal static string FormatHttpsUrlProvidedButNoDevelopmentCertificateFound() + => GetString("HttpsUrlProvidedButNoDevelopmentCertificateFound"); + + private static string GetString(string name, params string[] formatterNames) + { + var value = _resourceManager.GetString(name); + + System.Diagnostics.Debug.Assert(value != null); + + if (formatterNames != null) + { + for (var i = 0; i < formatterNames.Length; i++) + { + value = value.Replace("{" + formatterNames[i] + "}", "{" + i + "}"); + } + } + + return value; + } + } +} diff --git a/src/Kestrel/WebHostBuilderKestrelExtensions.cs b/src/Kestrel/WebHostBuilderKestrelExtensions.cs index 5ed947e96a..f65a66ac4e 100644 --- a/src/Kestrel/WebHostBuilderKestrelExtensions.cs +++ b/src/Kestrel/WebHostBuilderKestrelExtensions.cs @@ -5,6 +5,7 @@ using System; using Microsoft.AspNetCore.Hosting.Server; using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal; +using Microsoft.AspNetCore.Server.Kestrel.Internal; using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; using Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets; using Microsoft.Extensions.DependencyInjection; @@ -33,6 +34,7 @@ namespace Microsoft.AspNetCore.Hosting services.AddTransient, KestrelServerOptionsSetup>(); services.AddSingleton(); + services.AddSingleton(); }); } diff --git a/test/Kestrel.Core.Tests/AddressBinderTests.cs b/test/Kestrel.Core.Tests/AddressBinderTests.cs index 2c957e6030..d42a598e9c 100644 --- a/test/Kestrel.Core.Tests/AddressBinderTests.cs +++ b/test/Kestrel.Core.Tests/AddressBinderTests.cs @@ -8,9 +8,9 @@ using System.Net; using System.Threading.Tasks; using Microsoft.AspNetCore.Protocols; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal; -using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; using Microsoft.AspNetCore.Testing; using Microsoft.Extensions.Logging.Abstractions; +using Moq; using Xunit; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests @@ -55,12 +55,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests { var addresses = new ServerAddressesFeature(); addresses.Addresses.Add($"http://{host}"); - var options = new List(); + var options = new KestrelServerOptions(); var tcs = new TaskCompletionSource(); await AddressBinder.BindAsync(addresses, options, NullLogger.Instance, + Mock.Of(), endpoint => { tcs.TrySetResult(endpoint); @@ -75,13 +76,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests { var addresses = new ServerAddressesFeature(); addresses.Addresses.Add("http://localhost:5000"); - var options = new List(); + var options = new KestrelServerOptions(); await Assert.ThrowsAsync(() => AddressBinder.BindAsync(addresses, - options, - NullLogger.Instance, - endpoint => throw new AddressInUseException("already in use"))); + options, + NullLogger.Instance, + Mock.Of(), + endpoint => throw new AddressInUseException("already in use"))); } [Theory] @@ -93,7 +95,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests var logger = new MockLogger(); var addresses = new ServerAddressesFeature(); addresses.Addresses.Add(address); - var options = new List(); + var options = new KestrelServerOptions(); var ipV6Attempt = false; var ipV4Attempt = false; @@ -101,6 +103,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests await AddressBinder.BindAsync(addresses, options, logger, + Mock.Of(), endpoint => { if (endpoint.IPEndPoint.Address == IPAddress.IPv6Any) diff --git a/test/Kestrel.Core.Tests/KestrelServerTests.cs b/test/Kestrel.Core.Tests/KestrelServerTests.cs index c6ae3b5a7a..51e9de0221 100644 --- a/test/Kestrel.Core.Tests/KestrelServerTests.cs +++ b/test/Kestrel.Core.Tests/KestrelServerTests.cs @@ -9,6 +9,7 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting.Server; using Microsoft.AspNetCore.Hosting.Server.Features; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal; using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; using Microsoft.AspNetCore.Testing; using Microsoft.Extensions.Logging; @@ -37,20 +38,56 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests } [Fact] - public void StartWithHttpsAddressThrows() + public void StartWithHttpsAddressConfiguresHttpsEndpoints() { - var testLogger = new TestApplicationErrorLogger { ThrowOnCriticalErrors = false }; + var mockDefaultHttpsProvider = new Mock(); - using (var server = CreateServer(new KestrelServerOptions(), testLogger)) + using (var server = CreateServer(new KestrelServerOptions(), mockDefaultHttpsProvider.Object)) { server.Features.Get().Addresses.Add("https://127.0.0.1:0"); - var exception = Assert.Throws(() => StartDummyApplication(server)); + StartDummyApplication(server); - Assert.Equal( - $"HTTPS endpoints can only be configured using {nameof(KestrelServerOptions)}.{nameof(KestrelServerOptions.Listen)}().", - exception.Message); - Assert.Equal(1, testLogger.CriticalErrorsLogged); + mockDefaultHttpsProvider.Verify(provider => provider.ConfigureHttps(It.IsAny()), Times.Once); + } + } + + [Fact] + public void KestrelServerThrowsUsefulExceptionIfDefaultHttpsProviderNotAdded() + { + using (var server = CreateServer(new KestrelServerOptions(), defaultHttpsProvider: null, throwOnCriticalErrors: false)) + { + server.Features.Get().Addresses.Add("https://127.0.0.1:0"); + + var ex = Assert.Throws(() => StartDummyApplication(server)); + Assert.Equal(CoreStrings.UnableToConfigureHttpsBindings, ex.Message); + } + } + + [Fact] + public void KestrelServerDoesNotThrowIfNoDefaultHttpsProviderButNoHttpUrls() + { + using (var server = CreateServer(new KestrelServerOptions(), defaultHttpsProvider: null)) + { + server.Features.Get().Addresses.Add("http://127.0.0.1:0"); + + StartDummyApplication(server); + } + } + + [Fact] + public void KestrelServerDoesNotThrowIfNoDefaultHttpsProviderButManualListenOptions() + { + var mockDefaultHttpsProvider = new Mock(); + + var serverOptions = new KestrelServerOptions(); + serverOptions.Listen(new IPEndPoint(IPAddress.Loopback, 0)); + + using (var server = CreateServer(serverOptions, defaultHttpsProvider: null)) + { + server.Features.Get().Addresses.Add("https://127.0.0.1:0"); + + StartDummyApplication(server); } } @@ -274,6 +311,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests return new KestrelServer(Options.Create(options), new MockTransportFactory(), new LoggerFactory(new[] { new KestrelTestLoggerProvider(testLogger) })); } + private static KestrelServer CreateServer(KestrelServerOptions options, IDefaultHttpsProvider defaultHttpsProvider, bool throwOnCriticalErrors = true) + { + return new KestrelServer(Options.Create(options), new MockTransportFactory(), new LoggerFactory(new[] { new KestrelTestLoggerProvider(throwOnCriticalErrors) }), defaultHttpsProvider); + } + private static void StartDummyApplication(IServer server) { server.StartAsync(new DummyApplication(context => Task.CompletedTask), CancellationToken.None).GetAwaiter().GetResult(); diff --git a/test/Kestrel.FunctionalTests/AddressRegistrationTests.cs b/test/Kestrel.FunctionalTests/AddressRegistrationTests.cs index 7b9c9bdcda..446a201f71 100644 --- a/test/Kestrel.FunctionalTests/AddressRegistrationTests.cs +++ b/test/Kestrel.FunctionalTests/AddressRegistrationTests.cs @@ -511,8 +511,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } [Theory] - [InlineData("https://localhost")] [InlineData("ftp://localhost")] + [InlineData("ssh://localhost")] public void ThrowsForUnsupportedAddressFromHosting(string addr) { var hostBuilder = TransportSelector.GetWebHostBuilder() diff --git a/test/shared/KestrelTestLoggerProvider.cs b/test/shared/KestrelTestLoggerProvider.cs index 45462791d1..48455557fb 100644 --- a/test/shared/KestrelTestLoggerProvider.cs +++ b/test/shared/KestrelTestLoggerProvider.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -10,8 +10,8 @@ namespace Microsoft.AspNetCore.Testing { private readonly ILogger _testLogger; - public KestrelTestLoggerProvider() - : this(new TestApplicationErrorLogger()) + public KestrelTestLoggerProvider(bool throwOnCriticalErrors = true) + : this(new TestApplicationErrorLogger() { ThrowOnCriticalErrors = throwOnCriticalErrors }) { } @@ -30,4 +30,4 @@ namespace Microsoft.AspNetCore.Testing throw new NotImplementedException(); } } -} \ No newline at end of file +} From ab78fb0b8ca4f03eb53795f9a97c8152b045ef6b Mon Sep 17 00:00:00 2001 From: Andrew Stanton-Nurse Date: Wed, 25 Oct 2017 15:22:36 -0700 Subject: [PATCH 1443/1662] fix build break --- src/Kestrel/Kestrel.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Kestrel/Kestrel.csproj b/src/Kestrel/Kestrel.csproj index 7f7f8de70b..fd6008bdec 100644 --- a/src/Kestrel/Kestrel.csproj +++ b/src/Kestrel/Kestrel.csproj @@ -12,7 +12,7 @@ - + From eeb49c2af713a4957195b833eb4fb3286b236ccf Mon Sep 17 00:00:00 2001 From: Tom Deseyn Date: Thu, 26 Oct 2017 20:40:52 +0200 Subject: [PATCH 1444/1662] Pass setsockopt fd as int (#2136) --- src/Kestrel.Transport.Sockets/SocketTransport.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Kestrel.Transport.Sockets/SocketTransport.cs b/src/Kestrel.Transport.Sockets/SocketTransport.cs index b7d01acd0b..cf3cdf84b2 100644 --- a/src/Kestrel.Transport.Sockets/SocketTransport.cs +++ b/src/Kestrel.Transport.Sockets/SocketTransport.cs @@ -154,7 +154,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets { _trace.LogCritical($"Unexpected exeption in {nameof(SocketTransport)}.{nameof(RunAcceptLoopAsync)}."); _listenException = ex; - + // Request shutdown so we can rethrow this exception // in Stop which should be observable. _appLifetime.StopApplication(); @@ -163,7 +163,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets } [DllImport("libc", SetLastError = true)] - private static extern int setsockopt(IntPtr socket, int level, int option_name, IntPtr option_value, uint option_len); + private static extern int setsockopt(int socket, int level, int option_name, IntPtr option_value, uint option_len); private const int SOL_SOCKET_OSX = 0xffff; private const int SO_REUSEADDR_OSX = 0x0004; @@ -179,12 +179,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) { - setsockoptStatus = setsockopt(listenSocket.Handle, SOL_SOCKET_LINUX, SO_REUSEADDR_LINUX, + setsockoptStatus = setsockopt(listenSocket.Handle.ToInt32(), SOL_SOCKET_LINUX, SO_REUSEADDR_LINUX, (IntPtr)(&optionValue), sizeof(int)); } else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) { - setsockoptStatus = setsockopt(listenSocket.Handle, SOL_SOCKET_OSX, SO_REUSEADDR_OSX, + setsockoptStatus = setsockopt(listenSocket.Handle.ToInt32(), SOL_SOCKET_OSX, SO_REUSEADDR_OSX, (IntPtr)(&optionValue), sizeof(int)); } From 0c34523e8b36be0236106aa174ede6aab9acce85 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Tue, 31 Oct 2017 11:09:11 -0700 Subject: [PATCH 1445/1662] Log exception after critical accept loop error (#2140) --- src/Kestrel.Transport.Sockets/SocketTransport.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Kestrel.Transport.Sockets/SocketTransport.cs b/src/Kestrel.Transport.Sockets/SocketTransport.cs index cf3cdf84b2..fe6601253e 100644 --- a/src/Kestrel.Transport.Sockets/SocketTransport.cs +++ b/src/Kestrel.Transport.Sockets/SocketTransport.cs @@ -152,7 +152,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets } else { - _trace.LogCritical($"Unexpected exeption in {nameof(SocketTransport)}.{nameof(RunAcceptLoopAsync)}."); + _trace.LogCritical(ex, $"Unexpected exeption in {nameof(SocketTransport)}.{nameof(RunAcceptLoopAsync)}."); _listenException = ex; // Request shutdown so we can rethrow this exception From 6c82f78c657145404bcdbe403024b2d93ca7699a Mon Sep 17 00:00:00 2001 From: Nate McMaster Date: Thu, 26 Oct 2017 17:36:43 -0700 Subject: [PATCH 1446/1662] Pin tool and package versions to make builds more repeatable Part of aspnet/Universe#575 --- .gitignore | 1 - Directory.Build.props | 15 ++----- Directory.Build.targets | 17 ++------ NuGet.config | 3 +- README.md | 7 +-- .../Kestrel.Performance.csproj | 4 +- build/dependencies.props | 43 +++++++++++++++++++ build/repo.props | 7 ++- korebuild-lock.txt | 2 + korebuild.json | 4 ++ samples/SampleApp/SampleApp.csproj | 2 +- src/Directory.Build.props | 2 +- src/Kestrel.Core/Kestrel.Core.csproj | 20 ++++----- src/Kestrel.Https/Kestrel.Https.csproj | 4 +- src/Kestrel.Tls/Kestrel.Tls.csproj | 2 +- .../Kestrel.Transport.Libuv.csproj | 8 ++-- .../Kestrel.Transport.Sockets.csproj | 6 +-- src/Kestrel/Kestrel.csproj | 6 +-- .../Protocols.Abstractions.csproj | 14 +++--- test/Directory.Build.props | 12 +++--- .../Kestrel.Core.Tests.csproj | 6 +-- ...rel.Transport.Libuv.FunctionalTests.csproj | 8 ++-- .../Kestrel.Transport.Libuv.Tests.csproj | 6 +-- ...l.Transport.Sockets.FunctionalTests.csproj | 8 ++-- tools/CodeGenerator/CodeGenerator.csproj | 4 +- version.props | 10 +++++ version.xml | 8 ---- 27 files changed, 125 insertions(+), 104 deletions(-) create mode 100644 build/dependencies.props create mode 100644 korebuild-lock.txt create mode 100644 korebuild.json create mode 100644 version.props delete mode 100644 version.xml diff --git a/.gitignore b/.gitignore index 8e1cee9e15..708c4155fa 100644 --- a/.gitignore +++ b/.gitignore @@ -35,4 +35,3 @@ BenchmarkDotNet.Artifacts/ BDN.Generated/ binaries/ global.json -korebuild-lock.txt diff --git a/Directory.Build.props b/Directory.Build.props index 4f6edcfad9..396fba05b3 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,5 +1,6 @@ - + + Microsoft ASP.NET Core @@ -9,20 +10,12 @@ $(MSBuildThisFileDirectory)build\Key.snk true true - $(VersionSuffix)-$(BuildNumber) true latest - - - KRB4002 - + + diff --git a/Directory.Build.targets b/Directory.Build.targets index 8296c12835..0ff17438fc 100644 --- a/Directory.Build.targets +++ b/Directory.Build.targets @@ -1,14 +1,5 @@ - - - - <_BootstrapperFile Condition=" $([MSBuild]::IsOSUnixLike()) ">build.sh - <_BootstrapperFile Condition="! $([MSBuild]::IsOSUnixLike()) ">build.cmd - <_BootstrapperError> - Package references have not been pinned. Run './$(_BootstrapperFile) /t:Pin'. - Also, you can run './$(_BootstrapperFile) /t:Restore' which will pin *and* restore packages. '$(_BootstrapperFile)' can be found in '$(MSBuildThisFileDirectory)'. - - - - - + + + $(MicrosoftNETCoreApp20PackageVersion) + diff --git a/NuGet.config b/NuGet.config index c88189696c..9d49a5334e 100644 --- a/NuGet.config +++ b/NuGet.config @@ -3,7 +3,8 @@ - + + diff --git a/README.md b/README.md index 1af1c38364..7f2532761b 100644 --- a/README.md +++ b/README.md @@ -15,12 +15,7 @@ This project is part of ASP.NET Core. You can find samples, documentation and ge ## Building from source -To run a complete build on command line only, execute `build.cmd` or `build.sh` without arguments. - -Before opening this project in Visual Studio or VS Code, execute `build.cmd /t:Restore` (Windows) or `./build.sh /t:Restore` (Linux/macOS). -This will execute only the part of the build script that downloads and initializes a few required build tools and packages. - -See [developer documentation](https://github.com/aspnet/Home/wiki) for more details. +To run a complete build on command line only, execute `build.cmd` or `build.sh` without arguments. See [developer documentation](https://github.com/aspnet/Home/wiki) for more details. ## Packages diff --git a/benchmarks/Kestrel.Performance/Kestrel.Performance.csproj b/benchmarks/Kestrel.Performance/Kestrel.Performance.csproj index 4797141dcb..0fb7d5af0a 100644 --- a/benchmarks/Kestrel.Performance/Kestrel.Performance.csproj +++ b/benchmarks/Kestrel.Performance/Kestrel.Performance.csproj @@ -22,8 +22,8 @@ - - + + diff --git a/build/dependencies.props b/build/dependencies.props new file mode 100644 index 0000000000..b8ba66b1f4 --- /dev/null +++ b/build/dependencies.props @@ -0,0 +1,43 @@ + + + $(MSBuildAllProjects);$(MSBuildThisFileFullPath) + + + + 0.10.9 + 2.1.0-preview1-15549 + 1.10.0 + 2.1.0-preview1-27475 + 2.1.0-preview1-27475 + 2.1.0-preview1-27475 + 2.1.0-preview1-27475 + 2.1.0-preview1-27475 + 2.1.0-preview1-27475 + 2.1.0-preview1-27475 + 2.1.0-preview1-27475 + 2.1.0-preview1-27475 + 2.1.0-preview1-27475 + 2.1.0-preview1-27475 + 2.1.0-preview1-27475 + 2.1.0-preview1-27475 + 2.1.0-preview1-27475 + 2.0.0 + 2.6.0-beta2-62211-02 + 2.1.0-preview1-27475 + 15.3.0 + 4.7.49 + 10.0.1 + 4.4.0 + 0.1.0-e170811-6 + 4.4.0-preview3-25519-03 + 4.4.0 + 4.4.0 + 4.4.0 + 0.1.0-e170811-6 + 4.4.0 + 0.7.0 + 2.3.0 + 2.3.0 + + + diff --git a/build/repo.props b/build/repo.props index eadaa28976..30432c83ee 100644 --- a/build/repo.props +++ b/build/repo.props @@ -1,9 +1,8 @@ true + + Internal.AspNetCore.Universe.Lineup + https://dotnet.myget.org/F/aspnetcore-ci-dev/api/v3/index.json - - - - diff --git a/korebuild-lock.txt b/korebuild-lock.txt new file mode 100644 index 0000000000..45463cc71e --- /dev/null +++ b/korebuild-lock.txt @@ -0,0 +1,2 @@ +version:2.1.0-preview1-15549 +commithash:f570e08585fec510dd60cd4bfe8795388b757a95 diff --git a/korebuild.json b/korebuild.json new file mode 100644 index 0000000000..bd5d51a51b --- /dev/null +++ b/korebuild.json @@ -0,0 +1,4 @@ +{ + "$schema": "https://raw.githubusercontent.com/aspnet/BuildTools/dev/tools/korebuild.schema.json", + "channel": "dev" +} diff --git a/samples/SampleApp/SampleApp.csproj b/samples/SampleApp/SampleApp.csproj index 5dd0ddf608..a2567537c9 100644 --- a/samples/SampleApp/SampleApp.csproj +++ b/samples/SampleApp/SampleApp.csproj @@ -15,7 +15,7 @@ - + diff --git a/src/Directory.Build.props b/src/Directory.Build.props index 5236edee58..4b89a431e7 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -2,6 +2,6 @@ - + diff --git a/src/Kestrel.Core/Kestrel.Core.csproj b/src/Kestrel.Core/Kestrel.Core.csproj index 764b0d5bd8..75793650b5 100644 --- a/src/Kestrel.Core/Kestrel.Core.csproj +++ b/src/Kestrel.Core/Kestrel.Core.csproj @@ -9,21 +9,17 @@ aspnetcore;kestrel true CS1591;$(NoWarn) - - CurrentRuntime - - - - - - - - - - + + + + + + + + diff --git a/src/Kestrel.Https/Kestrel.Https.csproj b/src/Kestrel.Https/Kestrel.Https.csproj index e99a6f7423..de626b50b9 100644 --- a/src/Kestrel.Https/Kestrel.Https.csproj +++ b/src/Kestrel.Https/Kestrel.Https.csproj @@ -8,8 +8,6 @@ true aspnetcore;kestrel CS1591;$(NoWarn) - - CurrentRuntime @@ -17,7 +15,7 @@ - + diff --git a/src/Kestrel.Tls/Kestrel.Tls.csproj b/src/Kestrel.Tls/Kestrel.Tls.csproj index 8ab28b166c..3088fbcc46 100644 --- a/src/Kestrel.Tls/Kestrel.Tls.csproj +++ b/src/Kestrel.Tls/Kestrel.Tls.csproj @@ -17,7 +17,7 @@ - + diff --git a/src/Kestrel.Transport.Libuv/Kestrel.Transport.Libuv.csproj b/src/Kestrel.Transport.Libuv/Kestrel.Transport.Libuv.csproj index 4251d64cea..bef2f77e60 100644 --- a/src/Kestrel.Transport.Libuv/Kestrel.Transport.Libuv.csproj +++ b/src/Kestrel.Transport.Libuv/Kestrel.Transport.Libuv.csproj @@ -12,10 +12,10 @@ - - - - + + + + diff --git a/src/Kestrel.Transport.Sockets/Kestrel.Transport.Sockets.csproj b/src/Kestrel.Transport.Sockets/Kestrel.Transport.Sockets.csproj index af86b481a2..1674a1d65f 100644 --- a/src/Kestrel.Transport.Sockets/Kestrel.Transport.Sockets.csproj +++ b/src/Kestrel.Transport.Sockets/Kestrel.Transport.Sockets.csproj @@ -9,13 +9,11 @@ aspnetcore;kestrel true CS1591;$(NoWarn) - - CurrentRuntime - - + + diff --git a/src/Kestrel/Kestrel.csproj b/src/Kestrel/Kestrel.csproj index fd6008bdec..ac46ce4d3d 100644 --- a/src/Kestrel/Kestrel.csproj +++ b/src/Kestrel/Kestrel.csproj @@ -11,9 +11,9 @@ - - - + + + diff --git a/src/Protocols.Abstractions/Protocols.Abstractions.csproj b/src/Protocols.Abstractions/Protocols.Abstractions.csproj index 32fd561e98..192ee595fa 100644 --- a/src/Protocols.Abstractions/Protocols.Abstractions.csproj +++ b/src/Protocols.Abstractions/Protocols.Abstractions.csproj @@ -13,13 +13,13 @@ - - - - - - - + + + + + + + diff --git a/test/Directory.Build.props b/test/Directory.Build.props index 7039b276a4..5891f8eb0b 100644 --- a/test/Directory.Build.props +++ b/test/Directory.Build.props @@ -10,12 +10,12 @@ - - - - - - + + + + + + diff --git a/test/Kestrel.Core.Tests/Kestrel.Core.Tests.csproj b/test/Kestrel.Core.Tests/Kestrel.Core.Tests.csproj index a23522d606..38f15bc983 100644 --- a/test/Kestrel.Core.Tests/Kestrel.Core.Tests.csproj +++ b/test/Kestrel.Core.Tests/Kestrel.Core.Tests.csproj @@ -18,9 +18,9 @@ - - - + + + diff --git a/test/Kestrel.Transport.Libuv.FunctionalTests/Kestrel.Transport.Libuv.FunctionalTests.csproj b/test/Kestrel.Transport.Libuv.FunctionalTests/Kestrel.Transport.Libuv.FunctionalTests.csproj index b4c4d93b69..43e2b9ff07 100644 --- a/test/Kestrel.Transport.Libuv.FunctionalTests/Kestrel.Transport.Libuv.FunctionalTests.csproj +++ b/test/Kestrel.Transport.Libuv.FunctionalTests/Kestrel.Transport.Libuv.FunctionalTests.csproj @@ -26,10 +26,10 @@ - - - - + + + + diff --git a/test/Kestrel.Transport.Libuv.Tests/Kestrel.Transport.Libuv.Tests.csproj b/test/Kestrel.Transport.Libuv.Tests/Kestrel.Transport.Libuv.Tests.csproj index 4c4aa8b562..ca477f9507 100644 --- a/test/Kestrel.Transport.Libuv.Tests/Kestrel.Transport.Libuv.Tests.csproj +++ b/test/Kestrel.Transport.Libuv.Tests/Kestrel.Transport.Libuv.Tests.csproj @@ -19,9 +19,9 @@ - - - + + + diff --git a/test/Kestrel.Transport.Sockets.FunctionalTests/Kestrel.Transport.Sockets.FunctionalTests.csproj b/test/Kestrel.Transport.Sockets.FunctionalTests/Kestrel.Transport.Sockets.FunctionalTests.csproj index 8030d18468..8bc5d93436 100644 --- a/test/Kestrel.Transport.Sockets.FunctionalTests/Kestrel.Transport.Sockets.FunctionalTests.csproj +++ b/test/Kestrel.Transport.Sockets.FunctionalTests/Kestrel.Transport.Sockets.FunctionalTests.csproj @@ -27,10 +27,10 @@ - - - - + + + + diff --git a/tools/CodeGenerator/CodeGenerator.csproj b/tools/CodeGenerator/CodeGenerator.csproj index fcdc836a7c..e7cf3a993f 100644 --- a/tools/CodeGenerator/CodeGenerator.csproj +++ b/tools/CodeGenerator/CodeGenerator.csproj @@ -12,8 +12,8 @@ - - + + diff --git a/version.props b/version.props new file mode 100644 index 0000000000..5c4a7c32d1 --- /dev/null +++ b/version.props @@ -0,0 +1,10 @@ + + + 2.1.0 + preview1 + $(VersionPrefix) + $(VersionPrefix)-$(VersionSuffix)-final + t000 + $(VersionSuffix)-$(BuildNumber) + + diff --git a/version.xml b/version.xml deleted file mode 100644 index 3c05022b7d..0000000000 --- a/version.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - dev - 2.1.0 - preview1 - - From 238da2742d6cb251240d4fffe1cb3ea148ac6700 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Tue, 7 Nov 2017 14:43:14 -0800 Subject: [PATCH 1447/1662] Use SocketAsyncEventArgs to improve perf (#2147) --- .../Internal/LibuvAwaitable.cs | 2 + .../Internal/BufferExtensions.cs | 20 ++++ .../Internal/SocketAwaitable.cs | 58 +++++++++++ .../{ => Internal}/SocketConnection.cs | 60 ++---------- .../Internal/SocketReceiver.cs | 36 +++++++ .../Internal/SocketSender.cs | 98 +++++++++++++++++++ 6 files changed, 222 insertions(+), 52 deletions(-) create mode 100644 src/Kestrel.Transport.Sockets/Internal/BufferExtensions.cs create mode 100644 src/Kestrel.Transport.Sockets/Internal/SocketAwaitable.cs rename src/Kestrel.Transport.Sockets/{ => Internal}/SocketConnection.cs (80%) create mode 100644 src/Kestrel.Transport.Sockets/Internal/SocketReceiver.cs create mode 100644 src/Kestrel.Transport.Sockets/Internal/SocketSender.cs diff --git a/src/Kestrel.Transport.Libuv/Internal/LibuvAwaitable.cs b/src/Kestrel.Transport.Libuv/Internal/LibuvAwaitable.cs index 8ee11ff42e..49ca4f8e6b 100644 --- a/src/Kestrel.Transport.Libuv/Internal/LibuvAwaitable.cs +++ b/src/Kestrel.Transport.Libuv/Internal/LibuvAwaitable.cs @@ -36,6 +36,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal public UvWriteResult GetResult() { + Debug.Assert(_callback == _callbackCompleted); + var exception = _exception; var status = _status; diff --git a/src/Kestrel.Transport.Sockets/Internal/BufferExtensions.cs b/src/Kestrel.Transport.Sockets/Internal/BufferExtensions.cs new file mode 100644 index 0000000000..cadf97f0d0 --- /dev/null +++ b/src/Kestrel.Transport.Sockets/Internal/BufferExtensions.cs @@ -0,0 +1,20 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; + +namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal +{ + public static class BufferExtensions + { + public static ArraySegment GetArray(this Buffer buffer) + { + ArraySegment result; + if (!buffer.TryGetArray(out result)) + { + throw new InvalidOperationException("Buffer backed by array was expected"); + } + return result; + } + } +} \ No newline at end of file diff --git a/src/Kestrel.Transport.Sockets/Internal/SocketAwaitable.cs b/src/Kestrel.Transport.Sockets/Internal/SocketAwaitable.cs new file mode 100644 index 0000000000..fc68b3c08f --- /dev/null +++ b/src/Kestrel.Transport.Sockets/Internal/SocketAwaitable.cs @@ -0,0 +1,58 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Diagnostics; +using System.Net.Sockets; +using System.Runtime.CompilerServices; +using System.Threading; + +namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal +{ + public class SocketAwaitable : ICriticalNotifyCompletion + { + private static readonly Action _callbackCompleted = () => { }; + + private Action _callback; + private int _bytesTransfered; + private SocketError _error; + + public SocketAwaitable GetAwaiter() => this; + public bool IsCompleted => _callback == _callbackCompleted; + + public int GetResult() + { + Debug.Assert(_callback == _callbackCompleted); + + _callback = null; + + if (_error != SocketError.Success) + { + throw new SocketException((int)_error); + } + + return _bytesTransfered; + } + + public void OnCompleted(Action continuation) + { + if (_callback == _callbackCompleted || + Interlocked.CompareExchange(ref _callback, continuation, null) == _callbackCompleted) + { + continuation(); + } + } + + public void UnsafeOnCompleted(Action continuation) + { + OnCompleted(continuation); + } + + public void Complete(int bytesTransferred, SocketError socketError) + { + _error = socketError; + _bytesTransfered = bytesTransferred; + Interlocked.Exchange(ref _callback, _callbackCompleted)?.Invoke(); + } + } +} \ No newline at end of file diff --git a/src/Kestrel.Transport.Sockets/SocketConnection.cs b/src/Kestrel.Transport.Sockets/Internal/SocketConnection.cs similarity index 80% rename from src/Kestrel.Transport.Sockets/SocketConnection.cs rename to src/Kestrel.Transport.Sockets/Internal/SocketConnection.cs index 6bca6c7731..ac9ef9a8e2 100644 --- a/src/Kestrel.Transport.Sockets/SocketConnection.cs +++ b/src/Kestrel.Transport.Sockets/Internal/SocketConnection.cs @@ -2,7 +2,6 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.IO.Pipelines; @@ -11,10 +10,9 @@ using System.Net.Sockets; using System.Threading.Tasks; using Microsoft.AspNetCore.Protocols; using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; -using Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal; using Microsoft.Extensions.Logging; -namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets +namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal { internal sealed class SocketConnection : TransportConnection { @@ -22,8 +20,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets private readonly Socket _socket; private readonly ISocketsTrace _trace; + private readonly SocketReceiver _receiver; + private readonly SocketSender _sender; - private IList> _sendBufferList; private volatile bool _aborted; internal SocketConnection(Socket socket, PipeFactory pipeFactory, ISocketsTrace trace) @@ -44,6 +43,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets RemoteAddress = remoteEndPoint.Address; RemotePort = remoteEndPoint.Port; + + _receiver = new SocketReceiver(_socket); + _sender = new SocketSender(_socket); } public override PipeFactory PipeFactory { get; } @@ -95,7 +97,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets try { - var bytesReceived = await _socket.ReceiveAsync(GetArraySegment(buffer.Buffer), SocketFlags.None); + var bytesReceived = await _receiver.ReceiveAsync(buffer.Buffer); if (bytesReceived == 0) { @@ -176,25 +178,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets } } - private void SetupSendBuffers(ReadableBuffer buffer) - { - Debug.Assert(!buffer.IsEmpty); - Debug.Assert(!buffer.IsSingleSpan); - - if (_sendBufferList == null) - { - _sendBufferList = new List>(); - } - - // We should always clear the list after the send - Debug.Assert(_sendBufferList.Count == 0); - - foreach (var b in buffer) - { - _sendBufferList.Add(GetArraySegment(b)); - } - } - private async Task DoSend() { Exception error = null; @@ -216,23 +199,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets { if (!buffer.IsEmpty) { - if (buffer.IsSingleSpan) - { - await _socket.SendAsync(GetArraySegment(buffer.First), SocketFlags.None); - } - else - { - SetupSendBuffers(buffer); - - try - { - await _socket.SendAsync(_sendBufferList, SocketFlags.None); - } - finally - { - _sendBufferList.Clear(); - } - } + await _sender.SendAsync(buffer); } else if (result.IsCompleted) { @@ -273,16 +240,5 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets _socket.Shutdown(SocketShutdown.Both); } } - - private static ArraySegment GetArraySegment(Buffer buffer) - { - if (!buffer.TryGetArray(out var segment)) - { - throw new InvalidOperationException(); - } - - return segment; - } - } } diff --git a/src/Kestrel.Transport.Sockets/Internal/SocketReceiver.cs b/src/Kestrel.Transport.Sockets/Internal/SocketReceiver.cs new file mode 100644 index 0000000000..bb9f85a56b --- /dev/null +++ b/src/Kestrel.Transport.Sockets/Internal/SocketReceiver.cs @@ -0,0 +1,36 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Net.Sockets; + +namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal +{ + public class SocketReceiver + { + private readonly Socket _socket; + private readonly SocketAsyncEventArgs _eventArgs = new SocketAsyncEventArgs(); + private readonly SocketAwaitable _awaitable = new SocketAwaitable(); + + public SocketReceiver(Socket socket) + { + _socket = socket; + _eventArgs.UserToken = _awaitable; + _eventArgs.Completed += (_, e) => ((SocketAwaitable)e.UserToken).Complete(e.BytesTransferred, e.SocketError); + } + + public SocketAwaitable ReceiveAsync(Buffer buffer) + { + var segment = buffer.GetArray(); + + _eventArgs.SetBuffer(segment.Array, segment.Offset, segment.Count); + + if (!_socket.ReceiveAsync(_eventArgs)) + { + _awaitable.Complete(_eventArgs.BytesTransferred, _eventArgs.SocketError); + } + + return _awaitable; + } + } +} \ No newline at end of file diff --git a/src/Kestrel.Transport.Sockets/Internal/SocketSender.cs b/src/Kestrel.Transport.Sockets/Internal/SocketSender.cs new file mode 100644 index 0000000000..04f680f42d --- /dev/null +++ b/src/Kestrel.Transport.Sockets/Internal/SocketSender.cs @@ -0,0 +1,98 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.IO.Pipelines; +using System.Net.Sockets; + +namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal +{ + public class SocketSender + { + private readonly Socket _socket; + private readonly SocketAsyncEventArgs _eventArgs = new SocketAsyncEventArgs(); + private readonly SocketAwaitable _awaitable = new SocketAwaitable(); + + private List> _bufferList; + + public SocketSender(Socket socket) + { + _socket = socket; + _eventArgs.UserToken = _awaitable; + _eventArgs.Completed += (_, e) => SendCompleted(e, (SocketAwaitable)e.UserToken); + } + + public SocketAwaitable SendAsync(ReadableBuffer buffers) + { + if (buffers.IsSingleSpan) + { + return SendAsync(buffers.First); + } + + _eventArgs.BufferList = GetBufferList(buffers); + + if (!_socket.SendAsync(_eventArgs)) + { + SendCompleted(_eventArgs, _awaitable); + } + + return _awaitable; + } + + private SocketAwaitable SendAsync(Buffer buffer) + { + var segment = buffer.GetArray(); + + _eventArgs.SetBuffer(segment.Array, segment.Offset, segment.Count); + + if (!_socket.SendAsync(_eventArgs)) + { + SendCompleted(_eventArgs, _awaitable); + } + + return _awaitable; + } + + private List> GetBufferList(ReadableBuffer buffer) + { + Debug.Assert(!buffer.IsEmpty); + Debug.Assert(!buffer.IsSingleSpan); + + if (_bufferList == null) + { + _bufferList = new List>(); + } + + // We should always clear the list after the send + Debug.Assert(_bufferList.Count == 0); + + foreach (var b in buffer) + { + _bufferList.Add(b.GetArray()); + } + + return _bufferList; + } + + private static void SendCompleted(SocketAsyncEventArgs e, SocketAwaitable awaitable) + { + // Clear buffer(s) to prevent the SetBuffer buffer and BufferList from both being + // set for the next write operation. This is unnecessary for reads since they never + // set BufferList. + + if (e.BufferList != null) + { + e.BufferList.Clear(); + e.BufferList = null; + } + else + { + e.SetBuffer(null, 0, 0); + } + + awaitable.Complete(e.BytesTransferred, e.SocketError); + } + } +} \ No newline at end of file From 41abe63c1008a65ec290134f22658438ad77f3a9 Mon Sep 17 00:00:00 2001 From: Tim Seaward Date: Tue, 7 Nov 2017 22:49:02 +0000 Subject: [PATCH 1448/1662] Open ssl pfx (#2150) --- src/Kestrel.Tls/ListenOptionsTlsExtensions.cs | 4 +- src/Kestrel.Tls/OpenSsl.cs | 62 +++++++++++++++++++ src/Kestrel.Tls/TlsConnectionAdapter.cs | 6 +- .../TlsConnectionAdapterOptions.cs | 2 +- src/Kestrel.Tls/TlsStream.cs | 19 +++--- 5 files changed, 75 insertions(+), 18 deletions(-) diff --git a/src/Kestrel.Tls/ListenOptionsTlsExtensions.cs b/src/Kestrel.Tls/ListenOptionsTlsExtensions.cs index cb2c459152..695297eb56 100644 --- a/src/Kestrel.Tls/ListenOptionsTlsExtensions.cs +++ b/src/Kestrel.Tls/ListenOptionsTlsExtensions.cs @@ -10,12 +10,12 @@ namespace Microsoft.AspNetCore.Hosting { public static class ListenOptionsTlsExtensions { - public static ListenOptions UseTls(this ListenOptions listenOptions, string certificatePath, string privateKeyPath) + public static ListenOptions UseTls(this ListenOptions listenOptions, string certificatePath, string password) { return listenOptions.UseTls(new TlsConnectionAdapterOptions { CertificatePath = certificatePath, - PrivateKeyPath = privateKeyPath, + Password = password, Protocols = listenOptions.Protocols }); } diff --git a/src/Kestrel.Tls/OpenSsl.cs b/src/Kestrel.Tls/OpenSsl.cs index 17568e4b9c..7c209a299e 100644 --- a/src/Kestrel.Tls/OpenSsl.cs +++ b/src/Kestrel.Tls/OpenSsl.cs @@ -49,6 +49,41 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Tls NativeMethods.SSL_CTX_free(ctx); } + public unsafe static int SSL_CTX_Set_Pfx(IntPtr ctx, string path, string password) + { + var pass = Marshal.StringToHGlobalAnsi(password); + var key = IntPtr.Zero; + var cert = IntPtr.Zero; + var ca = IntPtr.Zero; + + try + { + var file = System.IO.File.ReadAllBytes(path); + + fixed (void* f = file) + { + var buffer = (IntPtr)f; + var pkcs = NativeMethods.d2i_PKCS12(IntPtr.Zero, ref buffer, file.Length); + var result = NativeMethods.PKCS12_parse(pkcs, pass, ref key, ref cert, ref ca); + if (result != 1) + { + return -1; + } + if (NativeMethods.SSL_CTX_use_certificate(ctx, cert) != 1) return -1; + if (NativeMethods.SSL_CTX_use_PrivateKey(ctx, key) != 1) return -1; + if (NativeMethods.SSL_CTX_set1_chain(ctx, ca) != 1) return -1; + return 1; + } + } + finally + { + Marshal.FreeHGlobal(pass); + if (key != IntPtr.Zero) NativeMethods.EVP_PKEY_free(key); + if (cert != IntPtr.Zero) NativeMethods.X509_free(cert); + if (ca != IntPtr.Zero) NativeMethods.sk_X509_pop_free(ca); + } + } + public static int SSL_CTX_set_ecdh_auto(IntPtr ctx, int onoff) { return (int)NativeMethods.SSL_CTX_ctrl(ctx, SSL_CTRL_SET_ECDH_AUTO, onoff, IntPtr.Zero); @@ -263,6 +298,33 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Tls [DllImport("libssl", CallingConvention = CallingConvention.Cdecl)] public static extern void ERR_load_BIO_strings(); + + [DllImport("libssl", CallingConvention = CallingConvention.Cdecl)] + public static extern IntPtr d2i_PKCS12(IntPtr unsused, ref IntPtr bufferPointer, long length); + + [DllImport("libssl", CallingConvention = CallingConvention.Cdecl)] + public static extern int PKCS12_parse(IntPtr p12, IntPtr pass, ref IntPtr pkey, ref IntPtr cert, ref IntPtr ca); + + [DllImport("libssl", CallingConvention = CallingConvention.Cdecl)] + public static extern void PKCS12_free(IntPtr p12); + + [DllImport("libssl", CallingConvention = CallingConvention.Cdecl)] + public static extern void EVP_PKEY_free(IntPtr pkey); + + [DllImport("libssl", CallingConvention = CallingConvention.Cdecl)] + public static extern void X509_free(IntPtr a); + + [DllImport("libssl", CallingConvention = CallingConvention.Cdecl)] + public static extern void sk_X509_pop_free(IntPtr ca); + + [DllImport("libssl", CallingConvention = CallingConvention.Cdecl)] + public static extern int SSL_CTX_set1_chain(IntPtr ctx, IntPtr sk); + + [DllImport("libssl", CallingConvention = CallingConvention.Cdecl)] + public static extern int SSL_CTX_use_certificate(IntPtr ctx, IntPtr x509); + + [DllImport("libssl", CallingConvention = CallingConvention.Cdecl)] + public static extern int SSL_CTX_use_PrivateKey(IntPtr ctx, IntPtr pkey); } } } diff --git a/src/Kestrel.Tls/TlsConnectionAdapter.cs b/src/Kestrel.Tls/TlsConnectionAdapter.cs index 539c8404f3..8dee80eb68 100644 --- a/src/Kestrel.Tls/TlsConnectionAdapter.cs +++ b/src/Kestrel.Tls/TlsConnectionAdapter.cs @@ -40,9 +40,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Tls throw new ArgumentException("Certificate path must be non-null.", nameof(options)); } - if (options.PrivateKeyPath == null) + if (options.Password == null) { - throw new ArgumentException("Private key path must be non-null.", nameof(options)); + throw new ArgumentException("Password must be non-null.", nameof(options)); } _options = options; @@ -70,7 +70,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Tls private async Task InnerOnConnectionAsync(ConnectionAdapterContext context) { - var tlsStream = new TlsStream(context.ConnectionStream, _options.CertificatePath, _options.PrivateKeyPath, _serverProtocols); + var tlsStream = new TlsStream(context.ConnectionStream, _options.CertificatePath, _options.Password, _serverProtocols); try { diff --git a/src/Kestrel.Tls/TlsConnectionAdapterOptions.cs b/src/Kestrel.Tls/TlsConnectionAdapterOptions.cs index 88d107ffdd..220bd47d9c 100644 --- a/src/Kestrel.Tls/TlsConnectionAdapterOptions.cs +++ b/src/Kestrel.Tls/TlsConnectionAdapterOptions.cs @@ -9,7 +9,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Tls { public string CertificatePath { get; set; } = string.Empty; - public string PrivateKeyPath { get; set; } = string.Empty; + public string Password { get; set; } = string.Empty; public HttpProtocols Protocols { get; set; } } diff --git a/src/Kestrel.Tls/TlsStream.cs b/src/Kestrel.Tls/TlsStream.cs index 0b1b583167..af45dcbe39 100644 --- a/src/Kestrel.Tls/TlsStream.cs +++ b/src/Kestrel.Tls/TlsStream.cs @@ -36,7 +36,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Tls OpenSsl.OpenSSL_add_all_algorithms(); } - public TlsStream(Stream innerStream, string certificatePath, string privateKeyPath, IEnumerable protocols) + public TlsStream(Stream innerStream, string certificatePath, string password, IEnumerable protocols) { _innerStream = innerStream; _protocols = ToWireFormat(protocols); @@ -49,18 +49,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Tls throw new Exception("Unable to create SSL context."); } + if(OpenSsl.SSL_CTX_Set_Pfx(_ctx, certificatePath, password) != 1) + { + throw new InvalidOperationException("Unable to load PFX"); + } + OpenSsl.SSL_CTX_set_ecdh_auto(_ctx, 1); - - if (OpenSsl.SSL_CTX_use_certificate_file(_ctx, certificatePath, 1) != 1) - { - throw new Exception("Unable to load certificate file."); - } - - if (OpenSsl.SSL_CTX_use_PrivateKey_file(_ctx, privateKeyPath, 1) != 1) - { - throw new Exception("Unable to load private key file."); - } - + OpenSsl.SSL_CTX_set_alpn_select_cb(_ctx, _alpnSelectCallback, GCHandle.ToIntPtr(_protocolsHandle)); _ssl = OpenSsl.SSL_new(_ctx); From 89fa8f0fa25a293d426b4baa153a96e0b4f56594 Mon Sep 17 00:00:00 2001 From: Andrew Stanton-Nurse Date: Tue, 7 Nov 2017 15:48:49 -0800 Subject: [PATCH 1449/1662] Revert "Open ssl pfx (#2150)" This reverts commit 41abe63c1008a65ec290134f22658438ad77f3a9. --- src/Kestrel.Tls/ListenOptionsTlsExtensions.cs | 4 +- src/Kestrel.Tls/OpenSsl.cs | 62 ------------------- src/Kestrel.Tls/TlsConnectionAdapter.cs | 6 +- .../TlsConnectionAdapterOptions.cs | 2 +- src/Kestrel.Tls/TlsStream.cs | 15 +++-- 5 files changed, 16 insertions(+), 73 deletions(-) diff --git a/src/Kestrel.Tls/ListenOptionsTlsExtensions.cs b/src/Kestrel.Tls/ListenOptionsTlsExtensions.cs index 695297eb56..cb2c459152 100644 --- a/src/Kestrel.Tls/ListenOptionsTlsExtensions.cs +++ b/src/Kestrel.Tls/ListenOptionsTlsExtensions.cs @@ -10,12 +10,12 @@ namespace Microsoft.AspNetCore.Hosting { public static class ListenOptionsTlsExtensions { - public static ListenOptions UseTls(this ListenOptions listenOptions, string certificatePath, string password) + public static ListenOptions UseTls(this ListenOptions listenOptions, string certificatePath, string privateKeyPath) { return listenOptions.UseTls(new TlsConnectionAdapterOptions { CertificatePath = certificatePath, - Password = password, + PrivateKeyPath = privateKeyPath, Protocols = listenOptions.Protocols }); } diff --git a/src/Kestrel.Tls/OpenSsl.cs b/src/Kestrel.Tls/OpenSsl.cs index 7c209a299e..17568e4b9c 100644 --- a/src/Kestrel.Tls/OpenSsl.cs +++ b/src/Kestrel.Tls/OpenSsl.cs @@ -49,41 +49,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Tls NativeMethods.SSL_CTX_free(ctx); } - public unsafe static int SSL_CTX_Set_Pfx(IntPtr ctx, string path, string password) - { - var pass = Marshal.StringToHGlobalAnsi(password); - var key = IntPtr.Zero; - var cert = IntPtr.Zero; - var ca = IntPtr.Zero; - - try - { - var file = System.IO.File.ReadAllBytes(path); - - fixed (void* f = file) - { - var buffer = (IntPtr)f; - var pkcs = NativeMethods.d2i_PKCS12(IntPtr.Zero, ref buffer, file.Length); - var result = NativeMethods.PKCS12_parse(pkcs, pass, ref key, ref cert, ref ca); - if (result != 1) - { - return -1; - } - if (NativeMethods.SSL_CTX_use_certificate(ctx, cert) != 1) return -1; - if (NativeMethods.SSL_CTX_use_PrivateKey(ctx, key) != 1) return -1; - if (NativeMethods.SSL_CTX_set1_chain(ctx, ca) != 1) return -1; - return 1; - } - } - finally - { - Marshal.FreeHGlobal(pass); - if (key != IntPtr.Zero) NativeMethods.EVP_PKEY_free(key); - if (cert != IntPtr.Zero) NativeMethods.X509_free(cert); - if (ca != IntPtr.Zero) NativeMethods.sk_X509_pop_free(ca); - } - } - public static int SSL_CTX_set_ecdh_auto(IntPtr ctx, int onoff) { return (int)NativeMethods.SSL_CTX_ctrl(ctx, SSL_CTRL_SET_ECDH_AUTO, onoff, IntPtr.Zero); @@ -298,33 +263,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Tls [DllImport("libssl", CallingConvention = CallingConvention.Cdecl)] public static extern void ERR_load_BIO_strings(); - - [DllImport("libssl", CallingConvention = CallingConvention.Cdecl)] - public static extern IntPtr d2i_PKCS12(IntPtr unsused, ref IntPtr bufferPointer, long length); - - [DllImport("libssl", CallingConvention = CallingConvention.Cdecl)] - public static extern int PKCS12_parse(IntPtr p12, IntPtr pass, ref IntPtr pkey, ref IntPtr cert, ref IntPtr ca); - - [DllImport("libssl", CallingConvention = CallingConvention.Cdecl)] - public static extern void PKCS12_free(IntPtr p12); - - [DllImport("libssl", CallingConvention = CallingConvention.Cdecl)] - public static extern void EVP_PKEY_free(IntPtr pkey); - - [DllImport("libssl", CallingConvention = CallingConvention.Cdecl)] - public static extern void X509_free(IntPtr a); - - [DllImport("libssl", CallingConvention = CallingConvention.Cdecl)] - public static extern void sk_X509_pop_free(IntPtr ca); - - [DllImport("libssl", CallingConvention = CallingConvention.Cdecl)] - public static extern int SSL_CTX_set1_chain(IntPtr ctx, IntPtr sk); - - [DllImport("libssl", CallingConvention = CallingConvention.Cdecl)] - public static extern int SSL_CTX_use_certificate(IntPtr ctx, IntPtr x509); - - [DllImport("libssl", CallingConvention = CallingConvention.Cdecl)] - public static extern int SSL_CTX_use_PrivateKey(IntPtr ctx, IntPtr pkey); } } } diff --git a/src/Kestrel.Tls/TlsConnectionAdapter.cs b/src/Kestrel.Tls/TlsConnectionAdapter.cs index 8dee80eb68..539c8404f3 100644 --- a/src/Kestrel.Tls/TlsConnectionAdapter.cs +++ b/src/Kestrel.Tls/TlsConnectionAdapter.cs @@ -40,9 +40,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Tls throw new ArgumentException("Certificate path must be non-null.", nameof(options)); } - if (options.Password == null) + if (options.PrivateKeyPath == null) { - throw new ArgumentException("Password must be non-null.", nameof(options)); + throw new ArgumentException("Private key path must be non-null.", nameof(options)); } _options = options; @@ -70,7 +70,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Tls private async Task InnerOnConnectionAsync(ConnectionAdapterContext context) { - var tlsStream = new TlsStream(context.ConnectionStream, _options.CertificatePath, _options.Password, _serverProtocols); + var tlsStream = new TlsStream(context.ConnectionStream, _options.CertificatePath, _options.PrivateKeyPath, _serverProtocols); try { diff --git a/src/Kestrel.Tls/TlsConnectionAdapterOptions.cs b/src/Kestrel.Tls/TlsConnectionAdapterOptions.cs index 220bd47d9c..88d107ffdd 100644 --- a/src/Kestrel.Tls/TlsConnectionAdapterOptions.cs +++ b/src/Kestrel.Tls/TlsConnectionAdapterOptions.cs @@ -9,7 +9,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Tls { public string CertificatePath { get; set; } = string.Empty; - public string Password { get; set; } = string.Empty; + public string PrivateKeyPath { get; set; } = string.Empty; public HttpProtocols Protocols { get; set; } } diff --git a/src/Kestrel.Tls/TlsStream.cs b/src/Kestrel.Tls/TlsStream.cs index af45dcbe39..0b1b583167 100644 --- a/src/Kestrel.Tls/TlsStream.cs +++ b/src/Kestrel.Tls/TlsStream.cs @@ -36,7 +36,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Tls OpenSsl.OpenSSL_add_all_algorithms(); } - public TlsStream(Stream innerStream, string certificatePath, string password, IEnumerable protocols) + public TlsStream(Stream innerStream, string certificatePath, string privateKeyPath, IEnumerable protocols) { _innerStream = innerStream; _protocols = ToWireFormat(protocols); @@ -49,13 +49,18 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Tls throw new Exception("Unable to create SSL context."); } - if(OpenSsl.SSL_CTX_Set_Pfx(_ctx, certificatePath, password) != 1) + OpenSsl.SSL_CTX_set_ecdh_auto(_ctx, 1); + + if (OpenSsl.SSL_CTX_use_certificate_file(_ctx, certificatePath, 1) != 1) { - throw new InvalidOperationException("Unable to load PFX"); + throw new Exception("Unable to load certificate file."); + } + + if (OpenSsl.SSL_CTX_use_PrivateKey_file(_ctx, privateKeyPath, 1) != 1) + { + throw new Exception("Unable to load private key file."); } - OpenSsl.SSL_CTX_set_ecdh_auto(_ctx, 1); - OpenSsl.SSL_CTX_set_alpn_select_cb(_ctx, _alpnSelectCallback, GCHandle.ToIntPtr(_protocolsHandle)); _ssl = OpenSsl.SSL_new(_ctx); From 64322ae2c5e8749b1976b505f82f01f45d2b0f93 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Tue, 7 Nov 2017 23:31:37 -0800 Subject: [PATCH 1450/1662] Don't let VS add IIS Express settings to the samples --- samples/LargeResponseApp/LargeResponseApp.csproj | 1 + samples/SampleApp/SampleApp.csproj | 1 + 2 files changed, 2 insertions(+) diff --git a/samples/LargeResponseApp/LargeResponseApp.csproj b/samples/LargeResponseApp/LargeResponseApp.csproj index 247595b135..13fab4a63e 100644 --- a/samples/LargeResponseApp/LargeResponseApp.csproj +++ b/samples/LargeResponseApp/LargeResponseApp.csproj @@ -3,6 +3,7 @@ netcoreapp2.0;net461 false + true diff --git a/samples/SampleApp/SampleApp.csproj b/samples/SampleApp/SampleApp.csproj index a2567537c9..7d62f70177 100644 --- a/samples/SampleApp/SampleApp.csproj +++ b/samples/SampleApp/SampleApp.csproj @@ -3,6 +3,7 @@ netcoreapp2.0;net461 false + true From 7d712f58aae2b78305992d45b60d66fee383a2ca Mon Sep 17 00:00:00 2001 From: Nate McMaster Date: Wed, 8 Nov 2017 13:55:00 -0800 Subject: [PATCH 1451/1662] Put Libuv.FunctionalTests into a separate test group --- .../Kestrel.Transport.Libuv.FunctionalTests.csproj | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/Kestrel.Transport.Libuv.FunctionalTests/Kestrel.Transport.Libuv.FunctionalTests.csproj b/test/Kestrel.Transport.Libuv.FunctionalTests/Kestrel.Transport.Libuv.FunctionalTests.csproj index 43e2b9ff07..7d7caae107 100644 --- a/test/Kestrel.Transport.Libuv.FunctionalTests/Kestrel.Transport.Libuv.FunctionalTests.csproj +++ b/test/Kestrel.Transport.Libuv.FunctionalTests/Kestrel.Transport.Libuv.FunctionalTests.csproj @@ -7,6 +7,8 @@ netcoreapp2.0 $(DefineConstants);MACOS true + + Libuv.FunctionalTests From 53b46972691c0aa0edb27e0dbe961e2ea809814e Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Thu, 9 Nov 2017 16:56:08 -0800 Subject: [PATCH 1452/1662] Show cause of connection failure in test (#2155) --- test/Kestrel.FunctionalTests/ConnectionLimitTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Kestrel.FunctionalTests/ConnectionLimitTests.cs b/test/Kestrel.FunctionalTests/ConnectionLimitTests.cs index 0e63b8e88b..49c1e7ab63 100644 --- a/test/Kestrel.FunctionalTests/ConnectionLimitTests.cs +++ b/test/Kestrel.FunctionalTests/ConnectionLimitTests.cs @@ -174,7 +174,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } catch (Exception ex) { - closedTcs.TrySetException(ex); + openedTcs.TrySetException(ex); } }); From 73a37363e1a44e221f070c530a5b987e118cc7a7 Mon Sep 17 00:00:00 2001 From: Pavel Krymets Date: Mon, 13 Nov 2017 15:04:54 -0800 Subject: [PATCH 1453/1662] Migrate to new pipe APIs (#2124) --- ...Http1ConnectionParsingOverheadBenchmark.cs | 7 +- .../Http1WritingBenchmark.cs | 46 ++++--- .../HttpProtocolFeatureCollection.cs | 7 +- .../PipeThroughputBenchmark.cs | 7 +- .../RequestParsingBenchmark.cs | 11 +- .../ResponseHeaderCollectionBenchmark.cs | 7 +- .../ResponseHeadersWritingBenchmark.cs | 24 ++-- build/dependencies.props | 11 +- korebuild-lock.txt | 4 +- .../Internal/ConnectionHandler.cs | 38 +++--- .../Internal/Http/Http1Connection.cs | 3 + .../Internal/Http/Http1ConnectionContext.cs | 3 +- .../Internal/Http/Http1OutputProducer.cs | 9 +- .../Internal/Http/HttpProtocol.cs | 19 +-- .../Internal/Http/IHttpProtocolContext.cs | 3 +- .../Internal/Http/PipelineExtensions.cs | 10 +- .../Internal/Http2/Http2Connection.cs | 2 +- .../Internal/Http2/Http2ConnectionContext.cs | 3 +- .../Internal/Http2/Http2StreamContext.cs | 3 +- src/Kestrel.Core/Internal/HttpConnection.cs | 37 +++--- .../Internal/HttpConnectionContext.cs | 3 +- .../Internal/HttpConnectionMiddleware.cs | 2 +- .../Internal/TransportConnection.Features.cs | 3 +- .../Internal/TransportConnection.cs | 4 +- .../Internal/LibuvConnection.cs | 4 +- .../Internal/LibuvConnectionContext.cs | 6 +- .../Internal/LibuvThread.cs | 7 +- .../Internal/Networking/UvWriteReq.cs | 10 +- .../Internal/BufferExtensions.cs | 4 +- .../Internal/SocketConnection.cs | 11 +- .../Internal/SocketReceiver.cs | 4 +- .../Internal/SocketSender.cs | 4 +- .../SocketTransport.cs | 7 +- .../ConnectionContext.cs | 3 +- .../DefaultConnectionContext.cs | 5 +- .../Features/IConnectionTransportFeature.cs | 6 +- .../PipeFactoryExtensions.cs | 16 ++- .../ConnectionHandlerTests.cs | 4 +- .../Http1ConnectionTests.cs | 9 +- .../Http2ConnectionTests.cs | 9 +- .../Kestrel.Core.Tests/HttpConnectionTests.cs | 11 +- .../HttpResponseHeadersTests.cs | 33 ++--- .../Kestrel.Core.Tests.csproj | 1 + .../Kestrel.Core.Tests/OutputProducerTests.cs | 17 ++- test/Kestrel.Core.Tests/PipeOptionsTests.cs | 6 +- .../PipelineExtensionTests.cs | 19 +-- test/Kestrel.Core.Tests/TestInput.cs | 10 +- .../LibuvConnectionTests.cs | 24 +++- .../LibuvOutputConsumerTests.cs | 121 ++++++++++-------- .../TestHelpers/MockConnectionHandler.cs | 9 +- 50 files changed, 352 insertions(+), 274 deletions(-) diff --git a/benchmarks/Kestrel.Performance/Http1ConnectionParsingOverheadBenchmark.cs b/benchmarks/Kestrel.Performance/Http1ConnectionParsingOverheadBenchmark.cs index 208d9eca15..28413ab08b 100644 --- a/benchmarks/Kestrel.Performance/Http1ConnectionParsingOverheadBenchmark.cs +++ b/benchmarks/Kestrel.Performance/Http1ConnectionParsingOverheadBenchmark.cs @@ -1,6 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System.Buffers; using System.IO.Pipelines; using BenchmarkDotNet.Attributes; using Microsoft.AspNetCore.Http.Features; @@ -22,8 +23,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance [IterationSetup] public void Setup() { - var pipeFactory = new PipeFactory(); - var pair = pipeFactory.CreateConnectionPair(); + var bufferPool = new MemoryPool(); + var pair = PipeFactory.CreateConnectionPair(bufferPool); var serviceContext = new ServiceContext { @@ -35,7 +36,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance { ServiceContext = serviceContext, ConnectionFeatures = new FeatureCollection(), - PipeFactory = pipeFactory, + BufferPool = bufferPool, TimeoutControl = new MockTimeoutControl(), Application = pair.Application, Transport = pair.Transport diff --git a/benchmarks/Kestrel.Performance/Http1WritingBenchmark.cs b/benchmarks/Kestrel.Performance/Http1WritingBenchmark.cs index c216433f50..91f42667ae 100644 --- a/benchmarks/Kestrel.Performance/Http1WritingBenchmark.cs +++ b/benchmarks/Kestrel.Performance/Http1WritingBenchmark.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Buffers; using System.IO.Pipelines; using System.Text; using System.Threading; @@ -93,31 +94,34 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance private TestHttp1Connection MakeHttp1Connection() { - var pipeFactory = new PipeFactory(); - var pair = pipeFactory.CreateConnectionPair(); - _pair = pair; - - var serviceContext = new ServiceContext + using (var memoryPool = new MemoryPool()) { - DateHeaderValueManager = new DateHeaderValueManager(), - ServerOptions = new KestrelServerOptions(), - Log = new MockTrace(), - HttpParserFactory = f => new HttpParser() - }; + var pair = PipeFactory.CreateConnectionPair(memoryPool); + _pair = pair; - var http1Connection = new TestHttp1Connection(application: null, context: new Http1ConnectionContext - { - ServiceContext = serviceContext, - ConnectionFeatures = new FeatureCollection(), - PipeFactory = pipeFactory, - Application = pair.Application, - Transport = pair.Transport - }); + var serviceContext = new ServiceContext + { + DateHeaderValueManager = new DateHeaderValueManager(), + ServerOptions = new KestrelServerOptions(), + Log = new MockTrace(), + HttpParserFactory = f => new HttpParser() + }; - http1Connection.Reset(); - http1Connection.InitializeStreams(MessageBody.ZeroContentLengthKeepAlive); + var http1Connection = new TestHttp1Connection( + application: null, context: new Http1ConnectionContext + { + ServiceContext = serviceContext, + ConnectionFeatures = new FeatureCollection(), + BufferPool = memoryPool, + Application = pair.Application, + Transport = pair.Transport + }); - return http1Connection; + http1Connection.Reset(); + http1Connection.InitializeStreams(MessageBody.ZeroContentLengthKeepAlive); + + return http1Connection; + } } [IterationCleanup] diff --git a/benchmarks/Kestrel.Performance/HttpProtocolFeatureCollection.cs b/benchmarks/Kestrel.Performance/HttpProtocolFeatureCollection.cs index f461fe470b..d55644d976 100644 --- a/benchmarks/Kestrel.Performance/HttpProtocolFeatureCollection.cs +++ b/benchmarks/Kestrel.Performance/HttpProtocolFeatureCollection.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Buffers; using System.IO.Pipelines; using BenchmarkDotNet.Attributes; using Microsoft.AspNetCore.Http.Features; @@ -77,8 +78,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance public HttpProtocolFeatureCollection() { - var pipeFactory = new PipeFactory(); - var pair = pipeFactory.CreateConnectionPair(); + var bufferPool = new MemoryPool(); + var pair = PipeFactory.CreateConnectionPair(bufferPool); var serviceContext = new ServiceContext { @@ -92,7 +93,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance { ServiceContext = serviceContext, ConnectionFeatures = new FeatureCollection(), - PipeFactory = pipeFactory, + BufferPool = bufferPool, Application = pair.Application, Transport = pair.Transport }); diff --git a/benchmarks/Kestrel.Performance/PipeThroughputBenchmark.cs b/benchmarks/Kestrel.Performance/PipeThroughputBenchmark.cs index 15ea0c4cae..973a63708d 100644 --- a/benchmarks/Kestrel.Performance/PipeThroughputBenchmark.cs +++ b/benchmarks/Kestrel.Performance/PipeThroughputBenchmark.cs @@ -1,6 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System.Buffers; using System.IO.Pipelines; using System.Threading.Tasks; using BenchmarkDotNet.Attributes; @@ -14,13 +15,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance private const int InnerLoopCount = 512; private IPipe _pipe; - private PipeFactory _pipelineFactory; + private BufferPool _bufferPool; [IterationSetup] public void Setup() { - _pipelineFactory = new PipeFactory(); - _pipe = _pipelineFactory.Create(); + _bufferPool = new MemoryPool(); + _pipe = new Pipe(new PipeOptions(_bufferPool)); } [Benchmark(OperationsPerInvoke = InnerLoopCount)] diff --git a/benchmarks/Kestrel.Performance/RequestParsingBenchmark.cs b/benchmarks/Kestrel.Performance/RequestParsingBenchmark.cs index 7f5c44c437..5837b5f5a1 100644 --- a/benchmarks/Kestrel.Performance/RequestParsingBenchmark.cs +++ b/benchmarks/Kestrel.Performance/RequestParsingBenchmark.cs @@ -1,6 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System.Buffers; using System.IO.Pipelines; using BenchmarkDotNet.Attributes; using Microsoft.AspNetCore.Http.Features; @@ -18,13 +19,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance public Http1Connection Http1Connection { get; set; } - public PipeFactory PipeFactory { get; set; } - [IterationSetup] public void Setup() { - var pipeFactory = new PipeFactory(); - var pair = pipeFactory.CreateConnectionPair(); + var bufferPool = new MemoryPool(); + var pair = PipeFactory.CreateConnectionPair(bufferPool); var serviceContext = new ServiceContext { @@ -38,7 +37,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance { ServiceContext = serviceContext, ConnectionFeatures = new FeatureCollection(), - PipeFactory = pipeFactory, + BufferPool = bufferPool, Application = pair.Application, Transport = pair.Transport, TimeoutControl = new MockTimeoutControl() @@ -47,7 +46,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance http1Connection.Reset(); Http1Connection = http1Connection; - Pipe = pipeFactory.Create(); + Pipe = new Pipe(new PipeOptions(bufferPool)); } [Benchmark(Baseline = true, OperationsPerInvoke = RequestParsingData.InnerLoopCount)] diff --git a/benchmarks/Kestrel.Performance/ResponseHeaderCollectionBenchmark.cs b/benchmarks/Kestrel.Performance/ResponseHeaderCollectionBenchmark.cs index 36207e4296..cbd2fd5e79 100644 --- a/benchmarks/Kestrel.Performance/ResponseHeaderCollectionBenchmark.cs +++ b/benchmarks/Kestrel.Performance/ResponseHeaderCollectionBenchmark.cs @@ -1,6 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System.Buffers; using System.IO.Pipelines; using System.Runtime.CompilerServices; using System.Text; @@ -170,8 +171,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance [IterationSetup] public void Setup() { - var pipeFactory = new PipeFactory(); - var pair = pipeFactory.CreateConnectionPair(); + var bufferPool = new MemoryPool(); + var pair = PipeFactory.CreateConnectionPair(bufferPool); var serviceContext = new ServiceContext { @@ -185,7 +186,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance { ServiceContext = serviceContext, ConnectionFeatures = new FeatureCollection(), - PipeFactory = pipeFactory, + BufferPool = bufferPool, Application = pair.Application, Transport = pair.Transport }); diff --git a/benchmarks/Kestrel.Performance/ResponseHeadersWritingBenchmark.cs b/benchmarks/Kestrel.Performance/ResponseHeadersWritingBenchmark.cs index 8443e13a5b..4940aa4326 100644 --- a/benchmarks/Kestrel.Performance/ResponseHeadersWritingBenchmark.cs +++ b/benchmarks/Kestrel.Performance/ResponseHeadersWritingBenchmark.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Buffers; using System.IO.Pipelines; using System.Text; using System.Threading; @@ -110,8 +111,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance [IterationSetup] public void Setup() { - var pipeFactory = new PipeFactory(); - var pair = pipeFactory.CreateConnectionPair(); + var bufferPool = new MemoryPool(); + var pair = PipeFactory.CreateConnectionPair(bufferPool); var serviceContext = new ServiceContext { @@ -121,15 +122,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance HttpParserFactory = f => new HttpParser() }; - var http1Connection = new TestHttp1Connection(application: null, context: new Http1ConnectionContext - { - ServiceContext = serviceContext, - ConnectionFeatures = new FeatureCollection(), - PipeFactory = pipeFactory, - TimeoutControl = new MockTimeoutControl(), - Application = pair.Application, - Transport = pair.Transport - }); + var http1Connection = new TestHttp1Connection( + application: null, context: new Http1ConnectionContext + { + ServiceContext = serviceContext, + ConnectionFeatures = new FeatureCollection(), + BufferPool = bufferPool, + TimeoutControl = new MockTimeoutControl(), + Application = pair.Application, + Transport = pair.Transport + }); http1Connection.Reset(); diff --git a/build/dependencies.props b/build/dependencies.props index b8ba66b1f4..243bff93f3 100644 --- a/build/dependencies.props +++ b/build/dependencies.props @@ -28,12 +28,13 @@ 4.7.49 10.0.1 4.4.0 - 0.1.0-e170811-6 - 4.4.0-preview3-25519-03 - 4.4.0 - 4.4.0 + 0.1.0-alpha-002 + 0.1.0-alpha-002 + 4.5.0-preview1-25902-08 + 4.5.0-preview1-25902-08 + 4.5.0-preview1-25902-08 4.4.0 - 0.1.0-e170811-6 + 0.1.0-alpha-002 4.4.0 0.7.0 2.3.0 diff --git a/korebuild-lock.txt b/korebuild-lock.txt index 45463cc71e..86352477bb 100644 --- a/korebuild-lock.txt +++ b/korebuild-lock.txt @@ -1,2 +1,2 @@ -version:2.1.0-preview1-15549 -commithash:f570e08585fec510dd60cd4bfe8795388b757a95 +version:2.1.0-preview1-15551 +commithash:8fad9553b48533fddbb16a423ea55b9710ea2e63 diff --git a/src/Kestrel.Core/Internal/ConnectionHandler.cs b/src/Kestrel.Core/Internal/ConnectionHandler.cs index 5e3513b5ac..fd9dc68746 100644 --- a/src/Kestrel.Core/Internal/ConnectionHandler.cs +++ b/src/Kestrel.Core/Internal/ConnectionHandler.cs @@ -2,7 +2,9 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Buffers; using System.IO.Pipelines; +using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Protocols; @@ -34,10 +36,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal // REVIEW: Unfortunately, we still need to use the service context to create the pipes since the settings // for the scheduler and limits are specified here - var inputOptions = GetInputPipeOptions(_serviceContext, transportFeature.InputWriterScheduler); - var outputOptions = GetOutputPipeOptions(_serviceContext, transportFeature.OutputReaderScheduler); + var inputOptions = GetInputPipeOptions(_serviceContext, connectionContext.BufferPool, transportFeature.InputWriterScheduler); + var outputOptions = GetOutputPipeOptions(_serviceContext, connectionContext.BufferPool, transportFeature.OutputReaderScheduler); - var pair = connectionContext.PipeFactory.CreateConnectionPair(inputOptions, outputOptions); + var pair = PipeFactory.CreateConnectionPair(inputOptions, outputOptions); // Set the transport and connection id connectionContext.ConnectionId = CorrelationIdGenerator.GetNextId(); @@ -81,21 +83,23 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal } // Internal for testing - internal static PipeOptions GetInputPipeOptions(ServiceContext serviceContext, IScheduler writerScheduler) => new PipeOptions - { - ReaderScheduler = serviceContext.ThreadPool, - WriterScheduler = writerScheduler, - MaximumSizeHigh = serviceContext.ServerOptions.Limits.MaxRequestBufferSize ?? 0, - MaximumSizeLow = serviceContext.ServerOptions.Limits.MaxRequestBufferSize ?? 0 - }; + internal static PipeOptions GetInputPipeOptions(ServiceContext serviceContext, BufferPool bufferPool, IScheduler writerScheduler) => new PipeOptions + ( + bufferPool: bufferPool, + readerScheduler: serviceContext.ThreadPool, + writerScheduler: writerScheduler, + maximumSizeHigh: serviceContext.ServerOptions.Limits.MaxRequestBufferSize ?? 0, + maximumSizeLow: serviceContext.ServerOptions.Limits.MaxRequestBufferSize ?? 0 + ); - internal static PipeOptions GetOutputPipeOptions(ServiceContext serviceContext, IScheduler readerScheduler) => new PipeOptions - { - ReaderScheduler = readerScheduler, - WriterScheduler = serviceContext.ThreadPool, - MaximumSizeHigh = GetOutputResponseBufferSize(serviceContext), - MaximumSizeLow = GetOutputResponseBufferSize(serviceContext) - }; + internal static PipeOptions GetOutputPipeOptions(ServiceContext serviceContext, BufferPool bufferPool, IScheduler readerScheduler) => new PipeOptions + ( + bufferPool: bufferPool, + readerScheduler: readerScheduler, + writerScheduler: serviceContext.ThreadPool, + maximumSizeHigh: GetOutputResponseBufferSize(serviceContext), + maximumSizeLow: GetOutputResponseBufferSize(serviceContext) + ); private static long GetOutputResponseBufferSize(ServiceContext serviceContext) { diff --git a/src/Kestrel.Core/Internal/Http/Http1Connection.cs b/src/Kestrel.Core/Internal/Http/Http1Connection.cs index b5d9c0235a..cb073a0724 100644 --- a/src/Kestrel.Core/Internal/Http/Http1Connection.cs +++ b/src/Kestrel.Core/Internal/Http/Http1Connection.cs @@ -209,7 +209,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http if (pathEncoded) { // URI was encoded, unescape and then parse as UTF-8 + // Disabling warning temporary +#pragma warning disable 618 var pathLength = UrlEncoder.Decode(path, path); +#pragma warning restore 618 // Removing dot segments must be done after unescaping. From RFC 3986: // diff --git a/src/Kestrel.Core/Internal/Http/Http1ConnectionContext.cs b/src/Kestrel.Core/Internal/Http/Http1ConnectionContext.cs index 2b15279564..de529ea372 100644 --- a/src/Kestrel.Core/Internal/Http/Http1ConnectionContext.cs +++ b/src/Kestrel.Core/Internal/Http/Http1ConnectionContext.cs @@ -1,6 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System.Buffers; using System.IO.Pipelines; using System.Net; using Microsoft.AspNetCore.Http.Features; @@ -14,7 +15,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http public string ConnectionId { get; set; } public ServiceContext ServiceContext { get; set; } public IFeatureCollection ConnectionFeatures { get; set; } - public PipeFactory PipeFactory { get; set; } + public BufferPool BufferPool { get; set; } public IPEndPoint RemoteEndPoint { get; set; } public IPEndPoint LocalEndPoint { get; set; } public ITimeoutControl TimeoutControl { get; set; } diff --git a/src/Kestrel.Core/Internal/Http/Http1OutputProducer.cs b/src/Kestrel.Core/Internal/Http/Http1OutputProducer.cs index 6ff341bb71..34c74f23d1 100644 --- a/src/Kestrel.Core/Internal/Http/Http1OutputProducer.cs +++ b/src/Kestrel.Core/Internal/Http/Http1OutputProducer.cs @@ -168,7 +168,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http CancellationToken cancellationToken) { var writableBuffer = default(WritableBuffer); - + long bytesWritten = 0; lock (_contextLock) { if (_completed) @@ -181,17 +181,18 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http if (buffer.Count > 0) { writer.Write(buffer.Array, buffer.Offset, buffer.Count); + bytesWritten += buffer.Count; } writableBuffer.Commit(); } - return FlushAsync(writableBuffer, cancellationToken); + return FlushAsync(writableBuffer, bytesWritten, cancellationToken); } // Single caller, at end of method - so inline [MethodImpl(MethodImplOptions.AggressiveInlining)] - private Task FlushAsync(WritableBuffer writableBuffer, CancellationToken cancellationToken) + private Task FlushAsync(WritableBuffer writableBuffer, long bytesWritten, CancellationToken cancellationToken) { var awaitable = writableBuffer.FlushAsync(cancellationToken); if (awaitable.IsCompleted) @@ -199,7 +200,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http // The flush task can't fail today return Task.CompletedTask; } - return FlushAsyncAwaited(awaitable, writableBuffer.BytesWritten, cancellationToken); + return FlushAsyncAwaited(awaitable, bytesWritten, cancellationToken); } private async Task FlushAsyncAwaited(WritableBufferAwaitable awaitable, long count, CancellationToken cancellationToken) diff --git a/src/Kestrel.Core/Internal/Http/HttpProtocol.cs b/src/Kestrel.Core/Internal/Http/HttpProtocol.cs index 9f6c11740d..0cadbce735 100644 --- a/src/Kestrel.Core/Internal/Http/HttpProtocol.cs +++ b/src/Kestrel.Core/Internal/Http/HttpProtocol.cs @@ -73,7 +73,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http public IHttpResponseControl HttpResponseControl { get; set; } - public IPipe RequestBodyPipe { get; } + public Pipe RequestBodyPipe { get; } public ServiceContext ServiceContext => _context.ServiceContext; private IPEndPoint LocalEndPoint => _context.LocalEndPoint; @@ -1301,13 +1301,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http Log.ApplicationError(ConnectionId, TraceIdentifier, ex); } - private IPipe CreateRequestBodyPipe() - => _context.PipeFactory.Create(new PipeOptions - { - ReaderScheduler = ServiceContext.ThreadPool, - WriterScheduler = InlineScheduler.Default, - MaximumSizeHigh = 1, - MaximumSizeLow = 1 - }); + private Pipe CreateRequestBodyPipe() + => new Pipe(new PipeOptions + ( + bufferPool: _context.BufferPool, + readerScheduler: ServiceContext.ThreadPool, + writerScheduler: InlineScheduler.Default, + maximumSizeHigh: 1, + maximumSizeLow: 1 + )); } } diff --git a/src/Kestrel.Core/Internal/Http/IHttpProtocolContext.cs b/src/Kestrel.Core/Internal/Http/IHttpProtocolContext.cs index fe1d5fa363..44abe5160f 100644 --- a/src/Kestrel.Core/Internal/Http/IHttpProtocolContext.cs +++ b/src/Kestrel.Core/Internal/Http/IHttpProtocolContext.cs @@ -1,6 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System.Buffers; using System.IO.Pipelines; using System.Net; using Microsoft.AspNetCore.Http.Features; @@ -12,7 +13,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http string ConnectionId { get; set; } ServiceContext ServiceContext { get; set; } IFeatureCollection ConnectionFeatures { get; set; } - PipeFactory PipeFactory { get; set; } + BufferPool BufferPool { get; set; } IPEndPoint RemoteEndPoint { get; set; } IPEndPoint LocalEndPoint { get; set; } } diff --git a/src/Kestrel.Core/Internal/Http/PipelineExtensions.cs b/src/Kestrel.Core/Internal/Http/PipelineExtensions.cs index 0f53b2783a..e12b588bb4 100644 --- a/src/Kestrel.Core/Internal/Http/PipelineExtensions.cs +++ b/src/Kestrel.Core/Internal/Http/PipelineExtensions.cs @@ -24,7 +24,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http return buffer.ToArray(); } - public static ArraySegment GetArray(this Buffer buffer) + public static ArraySegment GetArray(this Memory buffer) { ArraySegment result; if (!buffer.TryGetArray(out result)) @@ -34,7 +34,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http return result; } - public unsafe static void WriteAsciiNoValidation(ref WritableBufferWriter buffer, string data) + public unsafe static void WriteAsciiNoValidation(ref this WritableBufferWriter buffer, string data) { if (string.IsNullOrEmpty(data)) { @@ -63,7 +63,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public unsafe static void WriteNumeric(ref WritableBufferWriter buffer, ulong number) + public unsafe static void WriteNumeric(ref this WritableBufferWriter buffer, ulong number) { const byte AsciiDigitStart = (byte)'0'; @@ -113,7 +113,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http } [MethodImpl(MethodImplOptions.NoInlining)] - private static void WriteNumericMultiWrite(ref WritableBufferWriter buffer, ulong number) + private static void WriteNumericMultiWrite(ref this WritableBufferWriter buffer, ulong number) { const byte AsciiDigitStart = (byte)'0'; @@ -134,7 +134,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http } [MethodImpl(MethodImplOptions.NoInlining)] - private unsafe static void WriteAsciiMultiWrite(ref WritableBufferWriter buffer, string data) + private unsafe static void WriteAsciiMultiWrite(ref this WritableBufferWriter buffer, string data) { var remaining = data.Length; diff --git a/src/Kestrel.Core/Internal/Http2/Http2Connection.cs b/src/Kestrel.Core/Internal/Http2/Http2Connection.cs index 82637d51c1..83ec0d64f6 100644 --- a/src/Kestrel.Core/Internal/Http2/Http2Connection.cs +++ b/src/Kestrel.Core/Internal/Http2/Http2Connection.cs @@ -397,7 +397,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 StreamId = _incomingFrame.StreamId, ServiceContext = _context.ServiceContext, ConnectionFeatures = _context.ConnectionFeatures, - PipeFactory = _context.PipeFactory, + BufferPool = _context.BufferPool, LocalEndPoint = _context.LocalEndPoint, RemoteEndPoint = _context.RemoteEndPoint, StreamLifetimeHandler = this, diff --git a/src/Kestrel.Core/Internal/Http2/Http2ConnectionContext.cs b/src/Kestrel.Core/Internal/Http2/Http2ConnectionContext.cs index 1c089cc5b0..c4766a7b15 100644 --- a/src/Kestrel.Core/Internal/Http2/Http2ConnectionContext.cs +++ b/src/Kestrel.Core/Internal/Http2/Http2ConnectionContext.cs @@ -1,6 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System.Buffers; using System.IO.Pipelines; using System.Net; using Microsoft.AspNetCore.Http.Features; @@ -12,7 +13,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 public string ConnectionId { get; set; } public ServiceContext ServiceContext { get; set; } public IFeatureCollection ConnectionFeatures { get; set; } - public PipeFactory PipeFactory { get; set; } + public BufferPool BufferPool { get; set; } public IPEndPoint LocalEndPoint { get; set; } public IPEndPoint RemoteEndPoint { get; set; } diff --git a/src/Kestrel.Core/Internal/Http2/Http2StreamContext.cs b/src/Kestrel.Core/Internal/Http2/Http2StreamContext.cs index 68ea22533e..6bc9fc8b82 100644 --- a/src/Kestrel.Core/Internal/Http2/Http2StreamContext.cs +++ b/src/Kestrel.Core/Internal/Http2/Http2StreamContext.cs @@ -1,6 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System.Buffers; using System.IO.Pipelines; using System.Net; using Microsoft.AspNetCore.Http.Features; @@ -14,7 +15,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 public int StreamId { get; set; } public ServiceContext ServiceContext { get; set; } public IFeatureCollection ConnectionFeatures { get; set; } - public PipeFactory PipeFactory { get; set; } + public BufferPool BufferPool { get; set; } public IPEndPoint RemoteEndPoint { get; set; } public IPEndPoint LocalEndPoint { get; set; } public IHttp2StreamLifetimeHandler StreamLifetimeHandler { get; set; } diff --git a/src/Kestrel.Core/Internal/HttpConnection.cs b/src/Kestrel.Core/Internal/HttpConnection.cs index 099446058b..2ecc65d253 100644 --- a/src/Kestrel.Core/Internal/HttpConnection.cs +++ b/src/Kestrel.Core/Internal/HttpConnection.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Buffers; using System.Collections.Generic; using System.Diagnostics; using System.IO; @@ -65,24 +66,26 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal public IPEndPoint LocalEndPoint => _context.LocalEndPoint; public IPEndPoint RemoteEndPoint => _context.RemoteEndPoint; - private PipeFactory PipeFactory => _context.PipeFactory; + private BufferPool BufferPool => _context.BufferPool; // Internal for testing internal PipeOptions AdaptedInputPipeOptions => new PipeOptions - { - ReaderScheduler = _context.ServiceContext.ThreadPool, - WriterScheduler = InlineScheduler.Default, - MaximumSizeHigh = _context.ServiceContext.ServerOptions.Limits.MaxRequestBufferSize ?? 0, - MaximumSizeLow = _context.ServiceContext.ServerOptions.Limits.MaxRequestBufferSize ?? 0 - }; + ( + bufferPool: BufferPool, + readerScheduler: _context.ServiceContext.ThreadPool, + writerScheduler: InlineScheduler.Default, + maximumSizeHigh: _context.ServiceContext.ServerOptions.Limits.MaxRequestBufferSize ?? 0, + maximumSizeLow: _context.ServiceContext.ServerOptions.Limits.MaxRequestBufferSize ?? 0 + ); internal PipeOptions AdaptedOutputPipeOptions => new PipeOptions - { - ReaderScheduler = InlineScheduler.Default, - WriterScheduler = InlineScheduler.Default, - MaximumSizeHigh = _context.ServiceContext.ServerOptions.Limits.MaxResponseBufferSize ?? 0, - MaximumSizeLow = _context.ServiceContext.ServerOptions.Limits.MaxResponseBufferSize ?? 0 - }; + ( + bufferPool: BufferPool, + readerScheduler: InlineScheduler.Default, + writerScheduler: InlineScheduler.Default, + maximumSizeHigh: _context.ServiceContext.ServerOptions.Limits.MaxResponseBufferSize ?? 0, + maximumSizeLow: _context.ServiceContext.ServerOptions.Limits.MaxResponseBufferSize ?? 0 + ); private IKestrelTrace Log => _context.ServiceContext.Log; @@ -107,8 +110,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal { adaptedPipeline = new AdaptedPipeline(transport, application, - PipeFactory.Create(AdaptedInputPipeOptions), - PipeFactory.Create(AdaptedOutputPipeOptions)); + new Pipe(AdaptedInputPipeOptions), + new Pipe(AdaptedOutputPipeOptions)); transport = adaptedPipeline; } @@ -180,7 +183,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal { ConnectionId = _context.ConnectionId, ConnectionFeatures = _context.ConnectionFeatures, - PipeFactory = PipeFactory, + BufferPool = BufferPool, LocalEndPoint = LocalEndPoint, RemoteEndPoint = RemoteEndPoint, ServiceContext = _context.ServiceContext, @@ -197,7 +200,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal ConnectionId = _context.ConnectionId, ServiceContext = _context.ServiceContext, ConnectionFeatures = _context.ConnectionFeatures, - PipeFactory = PipeFactory, + BufferPool = BufferPool, LocalEndPoint = LocalEndPoint, RemoteEndPoint = RemoteEndPoint, Application = application, diff --git a/src/Kestrel.Core/Internal/HttpConnectionContext.cs b/src/Kestrel.Core/Internal/HttpConnectionContext.cs index 67298c0544..c2862b170b 100644 --- a/src/Kestrel.Core/Internal/HttpConnectionContext.cs +++ b/src/Kestrel.Core/Internal/HttpConnectionContext.cs @@ -1,6 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System.Buffers; using System.Collections.Generic; using System.IO.Pipelines; using System.Net; @@ -17,7 +18,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal public ServiceContext ServiceContext { get; set; } public IFeatureCollection ConnectionFeatures { get; set; } public IList ConnectionAdapters { get; set; } - public PipeFactory PipeFactory { get; set; } + public BufferPool BufferPool { get; set; } public IPEndPoint LocalEndPoint { get; set; } public IPEndPoint RemoteEndPoint { get; set; } public IPipeConnection Transport { get; set; } diff --git a/src/Kestrel.Core/Internal/HttpConnectionMiddleware.cs b/src/Kestrel.Core/Internal/HttpConnectionMiddleware.cs index d2b0757fcb..e6686cfd7c 100644 --- a/src/Kestrel.Core/Internal/HttpConnectionMiddleware.cs +++ b/src/Kestrel.Core/Internal/HttpConnectionMiddleware.cs @@ -50,7 +50,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal Protocols = _protocols, ServiceContext = _serviceContext, ConnectionFeatures = connectionContext.Features, - PipeFactory = connectionContext.PipeFactory, + BufferPool = connectionContext.BufferPool, ConnectionAdapters = _connectionAdapters, Transport = connectionContext.Transport, Application = transportFeature.Application diff --git a/src/Kestrel.Transport.Abstractions/Internal/TransportConnection.Features.cs b/src/Kestrel.Transport.Abstractions/Internal/TransportConnection.Features.cs index 2ac096eb24..7da585aeec 100644 --- a/src/Kestrel.Transport.Abstractions/Internal/TransportConnection.Features.cs +++ b/src/Kestrel.Transport.Abstractions/Internal/TransportConnection.Features.cs @@ -1,4 +1,5 @@ using System; +using System.Buffers; using System.Collections; using System.Collections.Generic; using System.IO.Pipelines; @@ -95,7 +96,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal set => LocalPort = value; } - PipeFactory IConnectionTransportFeature.PipeFactory => PipeFactory; + BufferPool IConnectionTransportFeature.BufferPool => BufferPool; IPipeConnection IConnectionTransportFeature.Transport { diff --git a/src/Kestrel.Transport.Abstractions/Internal/TransportConnection.cs b/src/Kestrel.Transport.Abstractions/Internal/TransportConnection.cs index c269a8f928..df8247aa09 100644 --- a/src/Kestrel.Transport.Abstractions/Internal/TransportConnection.cs +++ b/src/Kestrel.Transport.Abstractions/Internal/TransportConnection.cs @@ -1,6 +1,8 @@ using System; +using System.Buffers; using System.IO.Pipelines; using System.Net; +using System.Threading; namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal { @@ -20,7 +22,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal public string ConnectionId { get; set; } - public virtual PipeFactory PipeFactory { get; } + public virtual BufferPool BufferPool { get; } public virtual IScheduler InputWriterScheduler { get; } public virtual IScheduler OutputReaderScheduler { get; } diff --git a/src/Kestrel.Transport.Libuv/Internal/LibuvConnection.cs b/src/Kestrel.Transport.Libuv/Internal/LibuvConnection.cs index 670503dbda..60b7849e26 100644 --- a/src/Kestrel.Transport.Libuv/Internal/LibuvConnection.cs +++ b/src/Kestrel.Transport.Libuv/Internal/LibuvConnection.cs @@ -27,7 +27,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal private readonly UvStreamHandle _socket; private WritableBuffer? _currentWritableBuffer; - private BufferHandle _bufferHandle; + private MemoryHandle _bufferHandle; public LibuvConnection(ListenerContext context, UvStreamHandle socket) : base(context) { @@ -112,7 +112,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal _bufferHandle = currentWritableBuffer.Buffer.Retain(true); - return handle.Libuv.buf_init((IntPtr)_bufferHandle.PinnedPointer, currentWritableBuffer.Buffer.Length); + return handle.Libuv.buf_init((IntPtr)_bufferHandle.Pointer, currentWritableBuffer.Buffer.Length); } private static void ReadCallback(UvStreamHandle handle, int status, object state) diff --git a/src/Kestrel.Transport.Libuv/Internal/LibuvConnectionContext.cs b/src/Kestrel.Transport.Libuv/Internal/LibuvConnectionContext.cs index e1319c8317..2f052becab 100644 --- a/src/Kestrel.Transport.Libuv/Internal/LibuvConnectionContext.cs +++ b/src/Kestrel.Transport.Libuv/Internal/LibuvConnectionContext.cs @@ -1,8 +1,10 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System.Buffers; using System.Net; using System.IO.Pipelines; +using System.Threading; using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal @@ -15,8 +17,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal } public ListenerContext ListenerContext { get; set; } - - public override PipeFactory PipeFactory => ListenerContext.Thread.PipeFactory; + + public override BufferPool BufferPool => ListenerContext.Thread.BufferPool; public override IScheduler InputWriterScheduler => ListenerContext.Thread; public override IScheduler OutputReaderScheduler => ListenerContext.Thread; } diff --git a/src/Kestrel.Transport.Libuv/Internal/LibuvThread.cs b/src/Kestrel.Transport.Libuv/Internal/LibuvThread.cs index 726f3bfb6a..acab590fdc 100644 --- a/src/Kestrel.Transport.Libuv/Internal/LibuvThread.cs +++ b/src/Kestrel.Transport.Libuv/Internal/LibuvThread.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Buffers; using System.Collections.Generic; using System.Diagnostics; using System.IO.Pipelines; @@ -55,7 +56,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal #endif QueueCloseHandle = PostCloseHandle; QueueCloseAsyncHandle = EnqueueCloseHandle; - PipeFactory = new PipeFactory(); + BufferPool = new MemoryPool(); WriteReqPool = new WriteReqPool(this, _log); } @@ -68,7 +69,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal public UvLoopHandle Loop { get { return _loop; } } - public PipeFactory PipeFactory { get; } + public BufferPool BufferPool { get; } public WriteReqPool WriteReqPool { get; } @@ -295,7 +296,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal } finally { - PipeFactory.Dispose(); + BufferPool.Dispose(); WriteReqPool.Dispose(); _threadTcs.SetResult(null); diff --git a/src/Kestrel.Transport.Libuv/Internal/Networking/UvWriteReq.cs b/src/Kestrel.Transport.Libuv/Internal/Networking/UvWriteReq.cs index 857e98ea75..9eac9c1a39 100644 --- a/src/Kestrel.Transport.Libuv/Internal/Networking/UvWriteReq.cs +++ b/src/Kestrel.Transport.Libuv/Internal/Networking/UvWriteReq.cs @@ -25,7 +25,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networkin private LibuvAwaitable _awaitable = new LibuvAwaitable(); private List _pins = new List(BUFFER_COUNT + 1); - private List _handles = new List(BUFFER_COUNT + 1); + private List _handles = new List(BUFFER_COUNT + 1); public UvWriteReq(ILibuvTrace logger) : base(logger) { @@ -100,7 +100,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networkin // Fast path for single buffer pBuffers[0] = Libuv.buf_init( - (IntPtr)memoryHandle.PinnedPointer, + (IntPtr)memoryHandle.Pointer, memory.Length); } else @@ -114,7 +114,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networkin // create and pin each segment being written pBuffers[index] = Libuv.buf_init( - (IntPtr)memoryHandle.PinnedPointer, + (IntPtr)memoryHandle.Pointer, memory.Length); index++; } @@ -206,7 +206,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networkin } // Safe handle has instance method called Unpin - // so using UnpinGcHandles to avoid conflict + // so using UnpinGcHandles to avoid conflict private void UnpinGcHandles() { var pinList = _pins; @@ -254,4 +254,4 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networkin } } } -} \ No newline at end of file +} diff --git a/src/Kestrel.Transport.Sockets/Internal/BufferExtensions.cs b/src/Kestrel.Transport.Sockets/Internal/BufferExtensions.cs index cadf97f0d0..8edfb997b2 100644 --- a/src/Kestrel.Transport.Sockets/Internal/BufferExtensions.cs +++ b/src/Kestrel.Transport.Sockets/Internal/BufferExtensions.cs @@ -7,7 +7,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal { public static class BufferExtensions { - public static ArraySegment GetArray(this Buffer buffer) + public static ArraySegment GetArray(this Memory buffer) { ArraySegment result; if (!buffer.TryGetArray(out result)) @@ -17,4 +17,4 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal return result; } } -} \ No newline at end of file +} diff --git a/src/Kestrel.Transport.Sockets/Internal/SocketConnection.cs b/src/Kestrel.Transport.Sockets/Internal/SocketConnection.cs index ac9ef9a8e2..27f5807a1b 100644 --- a/src/Kestrel.Transport.Sockets/Internal/SocketConnection.cs +++ b/src/Kestrel.Transport.Sockets/Internal/SocketConnection.cs @@ -2,6 +2,8 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Buffers; +using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.IO.Pipelines; @@ -9,6 +11,7 @@ using System.Net; using System.Net.Sockets; using System.Threading.Tasks; using Microsoft.AspNetCore.Protocols; +using System.Threading; using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; using Microsoft.Extensions.Logging; @@ -25,14 +28,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal private volatile bool _aborted; - internal SocketConnection(Socket socket, PipeFactory pipeFactory, ISocketsTrace trace) + internal SocketConnection(Socket socket, BufferPool bufferPool, ISocketsTrace trace) { Debug.Assert(socket != null); - Debug.Assert(pipeFactory != null); + Debug.Assert(bufferPool != null); Debug.Assert(trace != null); _socket = socket; - PipeFactory = pipeFactory; + BufferPool = bufferPool; _trace = trace; var localEndPoint = (IPEndPoint)_socket.LocalEndPoint; @@ -48,7 +51,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal _sender = new SocketSender(_socket); } - public override PipeFactory PipeFactory { get; } + public override BufferPool BufferPool { get; } public override IScheduler InputWriterScheduler => InlineScheduler.Default; public override IScheduler OutputReaderScheduler => TaskRunScheduler.Default; diff --git a/src/Kestrel.Transport.Sockets/Internal/SocketReceiver.cs b/src/Kestrel.Transport.Sockets/Internal/SocketReceiver.cs index bb9f85a56b..ad3a99a0b0 100644 --- a/src/Kestrel.Transport.Sockets/Internal/SocketReceiver.cs +++ b/src/Kestrel.Transport.Sockets/Internal/SocketReceiver.cs @@ -19,7 +19,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal _eventArgs.Completed += (_, e) => ((SocketAwaitable)e.UserToken).Complete(e.BytesTransferred, e.SocketError); } - public SocketAwaitable ReceiveAsync(Buffer buffer) + public SocketAwaitable ReceiveAsync(Memory buffer) { var segment = buffer.GetArray(); @@ -33,4 +33,4 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal return _awaitable; } } -} \ No newline at end of file +} diff --git a/src/Kestrel.Transport.Sockets/Internal/SocketSender.cs b/src/Kestrel.Transport.Sockets/Internal/SocketSender.cs index 04f680f42d..0b3b998c6b 100644 --- a/src/Kestrel.Transport.Sockets/Internal/SocketSender.cs +++ b/src/Kestrel.Transport.Sockets/Internal/SocketSender.cs @@ -41,7 +41,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal return _awaitable; } - private SocketAwaitable SendAsync(Buffer buffer) + private SocketAwaitable SendAsync(Memory buffer) { var segment = buffer.GetArray(); @@ -95,4 +95,4 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal awaitable.Complete(e.BytesTransferred, e.SocketError); } } -} \ No newline at end of file +} diff --git a/src/Kestrel.Transport.Sockets/SocketTransport.cs b/src/Kestrel.Transport.Sockets/SocketTransport.cs index fe6601253e..d4f056829f 100644 --- a/src/Kestrel.Transport.Sockets/SocketTransport.cs +++ b/src/Kestrel.Transport.Sockets/SocketTransport.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Buffers; using System.Diagnostics; using System.IO.Pipelines; using System.Net; @@ -19,7 +20,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets { internal sealed class SocketTransport : ITransport { - private readonly PipeFactory _pipeFactory = new PipeFactory(); + private readonly BufferPool _bufferPool = new MemoryPool(); private readonly IEndPointInformation _endPointInformation; private readonly IConnectionHandler _handler; private readonly IApplicationLifetime _appLifetime; @@ -115,7 +116,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets public Task StopAsync() { - _pipeFactory.Dispose(); + _bufferPool.Dispose(); return Task.CompletedTask; } @@ -130,7 +131,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets var acceptSocket = await _listenSocket.AcceptAsync(); acceptSocket.NoDelay = _endPointInformation.NoDelay; - var connection = new SocketConnection(acceptSocket, _pipeFactory, _trace); + var connection = new SocketConnection(acceptSocket, _bufferPool, _trace); _ = connection.StartAsync(_handler); } catch (SocketException ex) when (ex.SocketErrorCode == SocketError.ConnectionReset) diff --git a/src/Protocols.Abstractions/ConnectionContext.cs b/src/Protocols.Abstractions/ConnectionContext.cs index f2ddc754ae..586a2ae19b 100644 --- a/src/Protocols.Abstractions/ConnectionContext.cs +++ b/src/Protocols.Abstractions/ConnectionContext.cs @@ -1,4 +1,5 @@ using System; +using System.Buffers; using System.IO.Pipelines; using System.Threading; using System.Threading.Tasks; @@ -14,6 +15,6 @@ namespace Microsoft.AspNetCore.Protocols public abstract IPipeConnection Transport { get; set; } - public abstract PipeFactory PipeFactory { get; } + public abstract BufferPool BufferPool { get; } } } diff --git a/src/Protocols.Abstractions/DefaultConnectionContext.cs b/src/Protocols.Abstractions/DefaultConnectionContext.cs index b81fc16f06..0c34637735 100644 --- a/src/Protocols.Abstractions/DefaultConnectionContext.cs +++ b/src/Protocols.Abstractions/DefaultConnectionContext.cs @@ -1,4 +1,5 @@ -using System.IO.Pipelines; +using System.Buffers; +using System.IO.Pipelines; using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Protocols.Features; @@ -27,7 +28,7 @@ namespace Microsoft.AspNetCore.Protocols public override IFeatureCollection Features => _features.Collection; - public override PipeFactory PipeFactory => ConnectionTransportFeature.PipeFactory; + public override BufferPool BufferPool => ConnectionTransportFeature.BufferPool; public override IPipeConnection Transport { diff --git a/src/Protocols.Abstractions/Features/IConnectionTransportFeature.cs b/src/Protocols.Abstractions/Features/IConnectionTransportFeature.cs index 8f27924126..3fc8d86224 100644 --- a/src/Protocols.Abstractions/Features/IConnectionTransportFeature.cs +++ b/src/Protocols.Abstractions/Features/IConnectionTransportFeature.cs @@ -1,10 +1,12 @@ -using System.IO.Pipelines; +using System.Buffers; +using System.IO.Pipelines; +using System.Threading; namespace Microsoft.AspNetCore.Protocols.Features { public interface IConnectionTransportFeature { - PipeFactory PipeFactory { get; } + BufferPool BufferPool { get; } IPipeConnection Transport { get; set; } diff --git a/src/Protocols.Abstractions/PipeFactoryExtensions.cs b/src/Protocols.Abstractions/PipeFactoryExtensions.cs index 9ded8a8f9d..f28207db59 100644 --- a/src/Protocols.Abstractions/PipeFactoryExtensions.cs +++ b/src/Protocols.Abstractions/PipeFactoryExtensions.cs @@ -1,16 +1,18 @@ -namespace System.IO.Pipelines +using System.Buffers; + +namespace System.IO.Pipelines { - public static class PipeFactoryExtensions + public static class PipeFactory { - public static (IPipeConnection Transport, IPipeConnection Application) CreateConnectionPair(this PipeFactory pipeFactory) + public static (IPipeConnection Transport, IPipeConnection Application) CreateConnectionPair(BufferPool memoryPool) { - return pipeFactory.CreateConnectionPair(new PipeOptions(), new PipeOptions()); + return CreateConnectionPair(new PipeOptions(memoryPool), new PipeOptions(memoryPool)); } - public static (IPipeConnection Transport, IPipeConnection Application) CreateConnectionPair(this PipeFactory pipeFactory, PipeOptions inputOptions, PipeOptions outputOptions) + public static (IPipeConnection Transport, IPipeConnection Application) CreateConnectionPair(PipeOptions inputOptions, PipeOptions outputOptions) { - var input = pipeFactory.Create(inputOptions); - var output = pipeFactory.Create(outputOptions); + var input = new Pipe(inputOptions); + var output = new Pipe(outputOptions); var transportToApplication = new PipeConnection(output.Reader, input.Writer); var applicationToTransport = new PipeConnection(input.Reader, output.Writer); diff --git a/test/Kestrel.Core.Tests/ConnectionHandlerTests.cs b/test/Kestrel.Core.Tests/ConnectionHandlerTests.cs index 45450bf9bd..e1ff59b297 100644 --- a/test/Kestrel.Core.Tests/ConnectionHandlerTests.cs +++ b/test/Kestrel.Core.Tests/ConnectionHandlerTests.cs @@ -1,8 +1,10 @@ using System; +using System.Buffers; using System.Collections.Generic; using System.IO.Pipelines; using System.Linq; using System.Text; +using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Protocols.Features; @@ -51,7 +53,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests Set(this); } - public PipeFactory PipeFactory { get; } = new PipeFactory(); + public BufferPool BufferPool { get; } = new MemoryPool(); public IPipeConnection Transport { get; set; } public IPipeConnection Application { get; set; } diff --git a/test/Kestrel.Core.Tests/Http1ConnectionTests.cs b/test/Kestrel.Core.Tests/Http1ConnectionTests.cs index 2cfd2ed2f8..0601a12763 100644 --- a/test/Kestrel.Core.Tests/Http1ConnectionTests.cs +++ b/test/Kestrel.Core.Tests/Http1ConnectionTests.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Buffers; using System.Collections; using System.Collections.Generic; using System.IO; @@ -32,7 +33,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests private readonly TestHttp1Connection _http1Connection; private readonly ServiceContext _serviceContext; private readonly Http1ConnectionContext _http1ConnectionContext; - private readonly PipeFactory _pipelineFactory; + private readonly BufferPool _pipelineFactory; private ReadCursor _consumed; private ReadCursor _examined; private Mock _timeoutControl; @@ -52,8 +53,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests public Http1ConnectionTests() { - _pipelineFactory = new PipeFactory(); - var pair = _pipelineFactory.CreateConnectionPair(); + _pipelineFactory = new MemoryPool(); + var pair = PipeFactory.CreateConnectionPair(_pipelineFactory); _transport = pair.Transport; _application = pair.Application; @@ -64,7 +65,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests { ServiceContext = _serviceContext, ConnectionFeatures = new FeatureCollection(), - PipeFactory = _pipelineFactory, + BufferPool = _pipelineFactory, TimeoutControl = _timeoutControl.Object, Application = pair.Application, Transport = pair.Transport diff --git a/test/Kestrel.Core.Tests/Http2ConnectionTests.cs b/test/Kestrel.Core.Tests/Http2ConnectionTests.cs index e4a875da58..69a7807ab0 100644 --- a/test/Kestrel.Core.Tests/Http2ConnectionTests.cs +++ b/test/Kestrel.Core.Tests/Http2ConnectionTests.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Buffers; using System.Collections.Concurrent; using System.Collections.Generic; using System.IO; @@ -92,7 +93,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests private static readonly byte[] _noData = new byte[0]; private static readonly byte[] _maxData = Encoding.ASCII.GetBytes(new string('a', Http2Frame.MinAllowedMaxFrameSize)); - private readonly PipeFactory _pipeFactory = new PipeFactory(); + private readonly BufferPool _bufferPool = new MemoryPool(); private readonly (IPipeConnection Transport, IPipeConnection Application) _pair; private readonly TestApplicationErrorLogger _logger; private readonly Http2ConnectionContext _connectionContext; @@ -121,7 +122,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests public Http2ConnectionTests() { - _pair = _pipeFactory.CreateConnectionPair(); + _pair = PipeFactory.CreateConnectionPair(_bufferPool); _noopApplication = context => Task.CompletedTask; @@ -256,7 +257,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests { Log = new TestKestrelTrace(_logger) }, - PipeFactory = _pipeFactory, + BufferPool = _bufferPool, Application = _pair.Application, Transport = _pair.Transport }; @@ -265,7 +266,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests public void Dispose() { - _pipeFactory.Dispose(); + _bufferPool.Dispose(); } void IHttpHeadersHandler.OnHeader(Span name, Span value) diff --git a/test/Kestrel.Core.Tests/HttpConnectionTests.cs b/test/Kestrel.Core.Tests/HttpConnectionTests.cs index a5c53eafde..3a4e43cc44 100644 --- a/test/Kestrel.Core.Tests/HttpConnectionTests.cs +++ b/test/Kestrel.Core.Tests/HttpConnectionTests.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Buffers; using System.Collections.Generic; using System.IO.Pipelines; using System.Threading; @@ -17,21 +18,21 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests { public class HttpConnectionTests : IDisposable { - private readonly PipeFactory _pipeFactory; + private readonly BufferPool _bufferPool; private readonly HttpConnectionContext _httpConnectionContext; private readonly HttpConnection _httpConnection; public HttpConnectionTests() { - _pipeFactory = new PipeFactory(); - var pair = _pipeFactory.CreateConnectionPair(); + _bufferPool = new MemoryPool(); + var pair = PipeFactory.CreateConnectionPair(_bufferPool); _httpConnectionContext = new HttpConnectionContext { ConnectionId = "0123456789", ConnectionAdapters = new List(), ConnectionFeatures = new FeatureCollection(), - PipeFactory = _pipeFactory, + BufferPool = _bufferPool, HttpConnectionId = long.MinValue, Application = pair.Application, Transport = pair.Transport, @@ -46,7 +47,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests public void Dispose() { - _pipeFactory.Dispose(); + _bufferPool.Dispose(); } [Fact] diff --git a/test/Kestrel.Core.Tests/HttpResponseHeadersTests.cs b/test/Kestrel.Core.Tests/HttpResponseHeadersTests.cs index 8ed1d70602..46c28a3633 100644 --- a/test/Kestrel.Core.Tests/HttpResponseHeadersTests.cs +++ b/test/Kestrel.Core.Tests/HttpResponseHeadersTests.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Buffers; using System.Collections.Generic; using System.Globalization; using System.IO.Pipelines; @@ -19,26 +20,28 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests [Fact] public void InitialDictionaryIsEmpty() { - var factory = new PipeFactory(); - var pair = factory.CreateConnectionPair(); - var http1ConnectionContext = new Http1ConnectionContext + using (var memoryPool = new MemoryPool()) { - ServiceContext = new TestServiceContext(), - ConnectionFeatures = new FeatureCollection(), - PipeFactory = factory, - Application = pair.Application, - Transport = pair.Transport, - TimeoutControl = null - }; + var pair = PipeFactory.CreateConnectionPair(memoryPool); + var http1ConnectionContext = new Http1ConnectionContext + { + ServiceContext = new TestServiceContext(), + ConnectionFeatures = new FeatureCollection(), + BufferPool = memoryPool, + Application = pair.Application, + Transport = pair.Transport, + TimeoutControl = null + }; - var http1Connection = new Http1Connection(application: null, context: http1ConnectionContext); + var http1Connection = new Http1Connection(application: null, context: http1ConnectionContext); - http1Connection.Reset(); + http1Connection.Reset(); - IDictionary headers = http1Connection.ResponseHeaders; + IDictionary headers = http1Connection.ResponseHeaders; - Assert.Equal(0, headers.Count); - Assert.False(headers.IsReadOnly); + Assert.Equal(0, headers.Count); + Assert.False(headers.IsReadOnly); + } } [Theory] diff --git a/test/Kestrel.Core.Tests/Kestrel.Core.Tests.csproj b/test/Kestrel.Core.Tests/Kestrel.Core.Tests.csproj index 38f15bc983..de9645ced9 100644 --- a/test/Kestrel.Core.Tests/Kestrel.Core.Tests.csproj +++ b/test/Kestrel.Core.Tests/Kestrel.Core.Tests.csproj @@ -21,6 +21,7 @@ + diff --git a/test/Kestrel.Core.Tests/OutputProducerTests.cs b/test/Kestrel.Core.Tests/OutputProducerTests.cs index 2beb0fcda6..ccfb164bad 100644 --- a/test/Kestrel.Core.Tests/OutputProducerTests.cs +++ b/test/Kestrel.Core.Tests/OutputProducerTests.cs @@ -2,7 +2,9 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Buffers; using System.IO.Pipelines; +using System.Threading; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; using Microsoft.AspNetCore.Testing; @@ -13,25 +15,26 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests { public class OutputProducerTests : IDisposable { - private readonly PipeFactory _pipeFactory; + private readonly BufferPool _bufferPool; public OutputProducerTests() { - _pipeFactory = new PipeFactory(); + _bufferPool = new MemoryPool(); } public void Dispose() { - _pipeFactory.Dispose(); + _bufferPool.Dispose(); } [Fact] public void WritesNoopAfterConnectionCloses() { var pipeOptions = new PipeOptions - { - ReaderScheduler = Mock.Of(), - }; + ( + bufferPool:_bufferPool, + readerScheduler: Mock.Of() + ); using (var socketOutput = CreateOutputProducer(pipeOptions)) { @@ -52,7 +55,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests private Http1OutputProducer CreateOutputProducer(PipeOptions pipeOptions) { - var pipe = _pipeFactory.Create(pipeOptions); + var pipe = new Pipe(pipeOptions); var serviceContext = new TestServiceContext(); var socketOutput = new Http1OutputProducer( pipe.Reader, diff --git a/test/Kestrel.Core.Tests/PipeOptionsTests.cs b/test/Kestrel.Core.Tests/PipeOptionsTests.cs index 530d2698d6..19ac6a1592 100644 --- a/test/Kestrel.Core.Tests/PipeOptionsTests.cs +++ b/test/Kestrel.Core.Tests/PipeOptionsTests.cs @@ -1,8 +1,10 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System.Buffers; using System.Collections.Generic; using System.IO.Pipelines; +using System.Threading; using Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; @@ -25,7 +27,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests serviceContext.ThreadPool = new LoggingThreadPool(null); var mockScheduler = Mock.Of(); - var outputPipeOptions = ConnectionHandler.GetOutputPipeOptions(serviceContext, readerScheduler: mockScheduler); + var outputPipeOptions = ConnectionHandler.GetOutputPipeOptions(serviceContext, new MemoryPool(), readerScheduler: mockScheduler); Assert.Equal(expectedMaximumSizeLow, outputPipeOptions.MaximumSizeLow); Assert.Equal(expectedMaximumSizeHigh, outputPipeOptions.MaximumSizeHigh); @@ -43,7 +45,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests serviceContext.ThreadPool = new LoggingThreadPool(null); var mockScheduler = Mock.Of(); - var inputPipeOptions = ConnectionHandler.GetInputPipeOptions(serviceContext, writerScheduler: mockScheduler); + var inputPipeOptions = ConnectionHandler.GetInputPipeOptions(serviceContext, new MemoryPool(), writerScheduler: mockScheduler); Assert.Equal(expectedMaximumSizeLow, inputPipeOptions.MaximumSizeLow); Assert.Equal(expectedMaximumSizeHigh, inputPipeOptions.MaximumSizeHigh); diff --git a/test/Kestrel.Core.Tests/PipelineExtensionTests.cs b/test/Kestrel.Core.Tests/PipelineExtensionTests.cs index b79bb20a75..954122f369 100644 --- a/test/Kestrel.Core.Tests/PipelineExtensionTests.cs +++ b/test/Kestrel.Core.Tests/PipelineExtensionTests.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Buffers; using System.IO.Pipelines; using System.Text; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; @@ -15,16 +16,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests private const int _ulongMaxValueLength = 20; private readonly IPipe _pipe; - private readonly PipeFactory _pipeFactory = new PipeFactory(); + private readonly BufferPool _bufferPool = new MemoryPool(); public PipelineExtensionTests() { - _pipe = _pipeFactory.Create(); + _pipe = new Pipe(new PipeOptions(_bufferPool)); } public void Dispose() { - _pipeFactory.Dispose(); + _bufferPool.Dispose(); } [Theory] @@ -35,7 +36,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests { var writerBuffer = _pipe.Writer.Alloc(); var writer = new WritableBufferWriter(writerBuffer); - PipelineExtensions.WriteNumeric(ref writer, number); + writer.WriteNumeric(number); writerBuffer.FlushAsync().GetAwaiter().GetResult(); var reader = _pipe.Reader.ReadAsync().GetAwaiter().GetResult(); @@ -57,7 +58,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests writer.Write(spacer); var bufferLength = writer.Span.Length; - PipelineExtensions.WriteNumeric(ref writer, ulong.MaxValue); + writer.WriteNumeric(ulong.MaxValue); Assert.NotEqual(bufferLength, writer.Span.Length); writerBuffer.FlushAsync().GetAwaiter().GetResult(); @@ -83,7 +84,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests { var writerBuffer = _pipe.Writer.Alloc(); var writer = new WritableBufferWriter(writerBuffer); - PipelineExtensions.WriteAsciiNoValidation(ref writer, input); + writer.WriteAsciiNoValidation(input); writerBuffer.FlushAsync().GetAwaiter().GetResult(); var reader = _pipe.Reader.ReadAsync().GetAwaiter().GetResult(); @@ -110,7 +111,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests // but it shouldn't produce more than one byte per character var writerBuffer = _pipe.Writer.Alloc(); var writer = new WritableBufferWriter(writerBuffer); - PipelineExtensions.WriteAsciiNoValidation(ref writer, input); + writer.WriteAsciiNoValidation(input); writerBuffer.FlushAsync().GetAwaiter().GetResult(); var reader = _pipe.Reader.ReadAsync().GetAwaiter().GetResult(); @@ -125,7 +126,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests var writer = new WritableBufferWriter(writerBuffer); for (var i = 0; i < maxAscii; i++) { - PipelineExtensions.WriteAsciiNoValidation(ref writer, new string((char)i, 1)); + writer.WriteAsciiNoValidation(new string((char)i, 1)); } writerBuffer.FlushAsync().GetAwaiter().GetResult(); @@ -158,7 +159,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests Assert.Equal(gapSize, writer.Span.Length); var bufferLength = writer.Span.Length; - PipelineExtensions.WriteAsciiNoValidation(ref writer, testString); + writer.WriteAsciiNoValidation(testString); Assert.NotEqual(bufferLength, writer.Span.Length); writerBuffer.FlushAsync().GetAwaiter().GetResult(); diff --git a/test/Kestrel.Core.Tests/TestInput.cs b/test/Kestrel.Core.Tests/TestInput.cs index 9905a4a965..e9c2cdf701 100644 --- a/test/Kestrel.Core.Tests/TestInput.cs +++ b/test/Kestrel.Core.Tests/TestInput.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Buffers; using System.IO.Pipelines; using System.Text; using Microsoft.AspNetCore.Http.Features; @@ -15,13 +16,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests class TestInput : IDisposable { private MemoryPool _memoryPool; - private PipeFactory _pipelineFactory; public TestInput() { _memoryPool = new MemoryPool(); - _pipelineFactory = new PipeFactory(); - var pair = _pipelineFactory.CreateConnectionPair(); + var pair = PipeFactory.CreateConnectionPair(_memoryPool); Transport = pair.Transport; Application = pair.Application; @@ -31,7 +30,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests ConnectionFeatures = new FeatureCollection(), Application = Application, Transport = Transport, - PipeFactory = _pipelineFactory, + BufferPool = _memoryPool, TimeoutControl = Mock.Of() }; @@ -43,8 +42,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests public IPipeConnection Application { get; } - public PipeFactory PipeFactory => _pipelineFactory; - public Http1ConnectionContext Http1ConnectionContext { get; } public Http1Connection Http1Connection { get; set; } @@ -67,7 +64,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests public void Dispose() { - _pipelineFactory.Dispose(); _memoryPool.Dispose(); } } diff --git a/test/Kestrel.Transport.Libuv.Tests/LibuvConnectionTests.cs b/test/Kestrel.Transport.Libuv.Tests/LibuvConnectionTests.cs index 5f6e341d74..061dfcebf7 100644 --- a/test/Kestrel.Transport.Libuv.Tests/LibuvConnectionTests.cs +++ b/test/Kestrel.Transport.Libuv.Tests/LibuvConnectionTests.cs @@ -55,13 +55,20 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests public async Task ConnectionDoesNotResumeAfterSocketCloseIfBackpressureIsApplied() { var mockConnectionHandler = new MockConnectionHandler(); - mockConnectionHandler.InputOptions.MaximumSizeHigh = 3; var mockLibuv = new MockLibuv(); var transportContext = new TestLibuvTransportContext() { ConnectionHandler = mockConnectionHandler }; var transport = new LibuvTransport(mockLibuv, transportContext, null); var thread = new LibuvThread(transport); + mockConnectionHandler.InputOptions = pool => + new PipeOptions( + bufferPool: pool, + maximumSizeHigh: 3); + // We don't set the output writer scheduler here since we want to run the callback inline - mockConnectionHandler.OutputOptions.ReaderScheduler = thread; + + mockConnectionHandler.OutputOptions = pool => new PipeOptions(bufferPool: pool, readerScheduler: thread); + + Task connectionTask = null; try { @@ -106,8 +113,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests public async Task ConnectionDoesNotResumeAfterReadCallbackScheduledAndSocketCloseIfBackpressureIsApplied() { var mockConnectionHandler = new MockConnectionHandler(); - mockConnectionHandler.InputOptions.MaximumSizeHigh = 3; - mockConnectionHandler.InputOptions.MaximumSizeLow = 3; var mockLibuv = new MockLibuv(); var transportContext = new TestLibuvTransportContext() { ConnectionHandler = mockConnectionHandler }; var transport = new LibuvTransport(mockLibuv, transportContext, null); @@ -118,8 +123,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests { backPressure = () => a(o); }); - mockConnectionHandler.InputOptions.WriterScheduler = mockScheduler.Object; - mockConnectionHandler.OutputOptions.ReaderScheduler = thread; + mockConnectionHandler.InputOptions = pool => + new PipeOptions( + bufferPool: pool, + maximumSizeHigh: 3, + maximumSizeLow: 3, + writerScheduler: mockScheduler.Object); + + mockConnectionHandler.OutputOptions = pool => new PipeOptions(bufferPool: pool, readerScheduler:thread ); + Task connectionTask = null; try { diff --git a/test/Kestrel.Transport.Libuv.Tests/LibuvOutputConsumerTests.cs b/test/Kestrel.Transport.Libuv.Tests/LibuvOutputConsumerTests.cs index be256e30d0..2a7b0ee4c1 100644 --- a/test/Kestrel.Transport.Libuv.Tests/LibuvOutputConsumerTests.cs +++ b/test/Kestrel.Transport.Libuv.Tests/LibuvOutputConsumerTests.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Buffers; using System.Collections.Concurrent; using System.IO.Pipelines; using System.Threading; @@ -21,7 +22,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests { public class LibuvOutputConsumerTests : IDisposable { - private readonly PipeFactory _pipeFactory; + private readonly BufferPool _bufferPool; private readonly MockLibuv _mockLibuv; private readonly LibuvThread _libuvThread; @@ -37,7 +38,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests public LibuvOutputConsumerTests() { - _pipeFactory = new PipeFactory(); + _bufferPool = new MemoryPool(); _mockLibuv = new MockLibuv(); var libuvTransport = new LibuvTransport(_mockLibuv, new TestLibuvTransportContext(), new ListenOptions(0)); @@ -48,7 +49,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests public void Dispose() { _libuvThread.StopAsync(TimeSpan.FromSeconds(1)).Wait(); - _pipeFactory.Dispose(); + _bufferPool.Dispose(); } [Theory] @@ -62,11 +63,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests // ConnectionHandler will set MaximumSizeHigh/Low to zero when MaxResponseBufferSize is null. // This is verified in PipeOptionsTests.OutputPipeOptionsConfiguredCorrectly. var pipeOptions = new PipeOptions - { - ReaderScheduler = _libuvThread, - MaximumSizeHigh = maxResponseBufferSize ?? 0, - MaximumSizeLow = maxResponseBufferSize ?? 0, - }; + ( + bufferPool: _bufferPool, + readerScheduler: _libuvThread, + maximumSizeHigh: maxResponseBufferSize ?? 0, + maximumSizeLow: maxResponseBufferSize ?? 0 + ); using (var outputProducer = CreateOutputProducer(pipeOptions)) { @@ -97,11 +99,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests // ConnectionHandler will set MaximumSizeHigh/Low to zero when MaxResponseBufferSize is null. // This is verified in PipeOptionsTests.OutputPipeOptionsConfiguredCorrectly. var pipeOptions = new PipeOptions - { - ReaderScheduler = _libuvThread, - MaximumSizeHigh = 0, - MaximumSizeLow = 0, - }; + ( + bufferPool: _bufferPool, + readerScheduler: _libuvThread, + maximumSizeHigh: 0, + maximumSizeLow: 0 + ); using (var outputProducer = CreateOutputProducer(pipeOptions)) { @@ -144,11 +147,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests // ConnectionHandler will set MaximumSizeHigh/Low to 1 when MaxResponseBufferSize is zero. // This is verified in PipeOptionsTests.OutputPipeOptionsConfiguredCorrectly. var pipeOptions = new PipeOptions - { - ReaderScheduler = _libuvThread, - MaximumSizeHigh = 1, - MaximumSizeLow = 1, - }; + ( + bufferPool: _bufferPool, + readerScheduler: _libuvThread, + maximumSizeHigh: 1, + maximumSizeLow: 1 + ); using (var outputProducer = CreateOutputProducer(pipeOptions)) { @@ -199,11 +203,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests }; var pipeOptions = new PipeOptions - { - ReaderScheduler = _libuvThread, - MaximumSizeHigh = maxResponseBufferSize, - MaximumSizeLow = maxResponseBufferSize, - }; + ( + bufferPool: _bufferPool, + readerScheduler: _libuvThread, + maximumSizeHigh: maxResponseBufferSize, + maximumSizeLow: maxResponseBufferSize + ); using (var outputProducer = CreateOutputProducer(pipeOptions)) { @@ -262,11 +267,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests }; var pipeOptions = new PipeOptions - { - ReaderScheduler = _libuvThread, - MaximumSizeHigh = maxResponseBufferSize, - MaximumSizeLow = maxResponseBufferSize, - }; + ( + bufferPool: _bufferPool, + readerScheduler: _libuvThread, + maximumSizeHigh: maxResponseBufferSize, + maximumSizeLow: maxResponseBufferSize + ); using (var outputProducer = CreateOutputProducer(pipeOptions)) { @@ -331,11 +337,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests var abortedSource = new CancellationTokenSource(); var pipeOptions = new PipeOptions - { - ReaderScheduler = _libuvThread, - MaximumSizeHigh = maxResponseBufferSize, - MaximumSizeLow = maxResponseBufferSize, - }; + ( + bufferPool: _bufferPool, + readerScheduler: _libuvThread, + maximumSizeHigh: maxResponseBufferSize, + maximumSizeLow: maxResponseBufferSize + ); using (var outputProducer = CreateOutputProducer(pipeOptions, abortedSource)) { @@ -423,11 +430,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests var abortedSource = new CancellationTokenSource(); var pipeOptions = new PipeOptions - { - ReaderScheduler = _libuvThread, - MaximumSizeHigh = maxResponseBufferSize, - MaximumSizeLow = maxResponseBufferSize, - }; + ( + bufferPool: _bufferPool, + readerScheduler: _libuvThread, + maximumSizeHigh: maxResponseBufferSize, + maximumSizeLow: maxResponseBufferSize + ); using (var outputProducer = CreateOutputProducer(pipeOptions)) { @@ -506,11 +514,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests var abortedSource = new CancellationTokenSource(); var pipeOptions = new PipeOptions - { - ReaderScheduler = _libuvThread, - MaximumSizeHigh = maxResponseBufferSize, - MaximumSizeLow = maxResponseBufferSize, - }; + ( + bufferPool: _bufferPool, + readerScheduler: _libuvThread, + maximumSizeHigh: maxResponseBufferSize, + maximumSizeLow: maxResponseBufferSize + ); using (var outputProducer = CreateOutputProducer(pipeOptions)) { @@ -587,11 +596,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests }; var pipeOptions = new PipeOptions - { - ReaderScheduler = _libuvThread, - MaximumSizeHigh = maxResponseBufferSize, - MaximumSizeLow = maxResponseBufferSize, - }; + ( + bufferPool: _bufferPool, + readerScheduler: _libuvThread, + maximumSizeHigh: maxResponseBufferSize, + maximumSizeLow: maxResponseBufferSize + ); using (var outputProducer = CreateOutputProducer(pipeOptions)) { @@ -647,11 +657,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests // ConnectionHandler will set MaximumSizeHigh/Low to zero when MaxResponseBufferSize is null. // This is verified in PipeOptionsTests.OutputPipeOptionsConfiguredCorrectly. var pipeOptions = new PipeOptions - { - ReaderScheduler = _libuvThread, - MaximumSizeHigh = maxResponseBufferSize ?? 0, - MaximumSizeLow = maxResponseBufferSize ?? 0, - }; + ( + bufferPool: _bufferPool, + readerScheduler: _libuvThread, + maximumSizeHigh: maxResponseBufferSize ?? 0, + maximumSizeLow: maxResponseBufferSize ?? 0 + ); using (var outputProducer = CreateOutputProducer(pipeOptions)) { @@ -684,7 +695,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests private Http1OutputProducer CreateOutputProducer(PipeOptions pipeOptions, CancellationTokenSource cts = null) { - var pair = _pipeFactory.CreateConnectionPair(pipeOptions, pipeOptions); + var pair = PipeFactory.CreateConnectionPair(pipeOptions, pipeOptions); var logger = new TestApplicationErrorLogger(); var serviceContext = new TestServiceContext @@ -701,7 +712,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests { ServiceContext = serviceContext, ConnectionFeatures = new FeatureCollection(), - PipeFactory = _pipeFactory, + BufferPool = _bufferPool, TimeoutControl = Mock.Of(), Application = pair.Application, Transport = pair.Transport diff --git a/test/Kestrel.Transport.Libuv.Tests/TestHelpers/MockConnectionHandler.cs b/test/Kestrel.Transport.Libuv.Tests/TestHelpers/MockConnectionHandler.cs index f1615378ee..5ae8289792 100644 --- a/test/Kestrel.Transport.Libuv.Tests/TestHelpers/MockConnectionHandler.cs +++ b/test/Kestrel.Transport.Libuv.Tests/TestHelpers/MockConnectionHandler.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Buffers; using System.IO.Pipelines; using System.Threading.Tasks; using Microsoft.AspNetCore.Http.Features; @@ -13,15 +14,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests.TestHelpers { public class MockConnectionHandler : IConnectionHandler { - public PipeOptions InputOptions { get; set; } = new PipeOptions(); - public PipeOptions OutputOptions { get; set; } = new PipeOptions(); + public Func InputOptions { get; set; } = pool => new PipeOptions(pool); + public Func OutputOptions { get; set; } = pool => new PipeOptions(pool); public void OnConnection(IFeatureCollection features) { var connectionContext = new DefaultConnectionContext(features); - Input = connectionContext.PipeFactory.Create(InputOptions ?? new PipeOptions()); - Output = connectionContext.PipeFactory.Create(OutputOptions ?? new PipeOptions()); + Input = new Pipe(InputOptions(connectionContext.BufferPool)); + Output = new Pipe(InputOptions(connectionContext.BufferPool)); var feature = connectionContext.Features.Get(); From 065e9bb57a5f8900dc2fc7cc8d94c71135cde9e5 Mon Sep 17 00:00:00 2001 From: Andrew Stanton-Nurse Date: Mon, 13 Nov 2017 15:54:16 -0800 Subject: [PATCH 1454/1662] Update "temporary" OpenSSL wrapper to support 1.1, and add HTTP/2 sample with docker (#2149) --- KestrelHttpServer.sln | 17 ++- samples/Http2SampleApp/Dockerfile | 14 +++ samples/Http2SampleApp/Http2SampleApp.csproj | 21 ++++ samples/Http2SampleApp/Program.cs | 50 ++++++++ samples/Http2SampleApp/Startup.cs | 29 +++++ .../Http2SampleApp/scripts/build-docker.ps1 | 3 + .../Http2SampleApp/scripts/build-docker.sh | 6 + samples/Http2SampleApp/scripts/run-docker.ps1 | 1 + samples/Http2SampleApp/scripts/run-docker.sh | 2 + samples/SampleApp/SampleApp.csproj | 8 +- samples/SampleApp/testCert.pfx | Bin 2483 -> 0 bytes .../Internal/Http2/Http2Frame.Data.cs | 6 + src/Kestrel.Core/Internal/Http2/Http2Frame.cs | 1 + src/Kestrel.Tls/ListenOptionsTlsExtensions.cs | 4 +- src/Kestrel.Tls/OpenSsl.cs | 115 +++++++++++++++++- src/Kestrel.Tls/TlsConnectionAdapter.cs | 6 +- .../TlsConnectionAdapterOptions.cs | 2 +- src/Kestrel.Tls/TlsStream.cs | 34 +++--- 18 files changed, 290 insertions(+), 29 deletions(-) create mode 100644 samples/Http2SampleApp/Dockerfile create mode 100644 samples/Http2SampleApp/Http2SampleApp.csproj create mode 100644 samples/Http2SampleApp/Program.cs create mode 100644 samples/Http2SampleApp/Startup.cs create mode 100644 samples/Http2SampleApp/scripts/build-docker.ps1 create mode 100755 samples/Http2SampleApp/scripts/build-docker.sh create mode 100644 samples/Http2SampleApp/scripts/run-docker.ps1 create mode 100755 samples/Http2SampleApp/scripts/run-docker.sh delete mode 100644 samples/SampleApp/testCert.pfx diff --git a/KestrelHttpServer.sln b/KestrelHttpServer.sln index 8ec3d0f3a6..6cdeaa1464 100644 --- a/KestrelHttpServer.sln +++ b/KestrelHttpServer.sln @@ -1,6 +1,6 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 15 -VisualStudioVersion = 15.0.26730.16 +VisualStudioVersion = 15.0.27101.0 MinimumVisualStudioVersion = 15.0.26730.03 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{7972A5D6-3385-4127-9277-428506DD44FF}" ProjectSection(SolutionItems) = preProject @@ -121,6 +121,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Kestrel.Transport.Libuv.Fun EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Kestrel.Transport.Sockets.FunctionalTests", "test\Kestrel.Transport.Sockets.FunctionalTests\Kestrel.Transport.Sockets.FunctionalTests.csproj", "{9C7B6B5F-088A-436E-834B-6373EA36DEEE}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Http2SampleApp", "samples\Http2SampleApp\Http2SampleApp.csproj", "{7BC22A4A-15D2-44C2-AB45-049F0FB562FA}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -335,6 +337,18 @@ Global {9C7B6B5F-088A-436E-834B-6373EA36DEEE}.Release|x64.Build.0 = Release|Any CPU {9C7B6B5F-088A-436E-834B-6373EA36DEEE}.Release|x86.ActiveCfg = Release|Any CPU {9C7B6B5F-088A-436E-834B-6373EA36DEEE}.Release|x86.Build.0 = Release|Any CPU + {7BC22A4A-15D2-44C2-AB45-049F0FB562FA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {7BC22A4A-15D2-44C2-AB45-049F0FB562FA}.Debug|Any CPU.Build.0 = Debug|Any CPU + {7BC22A4A-15D2-44C2-AB45-049F0FB562FA}.Debug|x64.ActiveCfg = Debug|Any CPU + {7BC22A4A-15D2-44C2-AB45-049F0FB562FA}.Debug|x64.Build.0 = Debug|Any CPU + {7BC22A4A-15D2-44C2-AB45-049F0FB562FA}.Debug|x86.ActiveCfg = Debug|Any CPU + {7BC22A4A-15D2-44C2-AB45-049F0FB562FA}.Debug|x86.Build.0 = Debug|Any CPU + {7BC22A4A-15D2-44C2-AB45-049F0FB562FA}.Release|Any CPU.ActiveCfg = Release|Any CPU + {7BC22A4A-15D2-44C2-AB45-049F0FB562FA}.Release|Any CPU.Build.0 = Release|Any CPU + {7BC22A4A-15D2-44C2-AB45-049F0FB562FA}.Release|x64.ActiveCfg = Release|Any CPU + {7BC22A4A-15D2-44C2-AB45-049F0FB562FA}.Release|x64.Build.0 = Release|Any CPU + {7BC22A4A-15D2-44C2-AB45-049F0FB562FA}.Release|x86.ActiveCfg = Release|Any CPU + {7BC22A4A-15D2-44C2-AB45-049F0FB562FA}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -359,6 +373,7 @@ Global {B7B0EA74-528F-46B8-9BC4-909D9A67C194} = {D3273454-EA07-41D2-BF0B-FCC3675C2483} {74032D79-8EA7-4483-BD82-C38370420FFF} = {D3273454-EA07-41D2-BF0B-FCC3675C2483} {9C7B6B5F-088A-436E-834B-6373EA36DEEE} = {D3273454-EA07-41D2-BF0B-FCC3675C2483} + {7BC22A4A-15D2-44C2-AB45-049F0FB562FA} = {8A3D00B8-1CCF-4BE6-A060-11104CE2D9CE} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {2D10D020-6770-47CA-BB8D-2C23FE3AE071} diff --git a/samples/Http2SampleApp/Dockerfile b/samples/Http2SampleApp/Dockerfile new file mode 100644 index 0000000000..e93d563bde --- /dev/null +++ b/samples/Http2SampleApp/Dockerfile @@ -0,0 +1,14 @@ +FROM microsoft/aspnetcore:2.0.0-stretch + +RUN apt-get update && \ + apt-get install -y --no-install-recommends \ + libssl-dev && \ + rm -rf /var/lib/apt/lists/* + +ARG CONFIGURATION=Debug + +WORKDIR /app + +COPY ./bin/${CONFIGURATION}/netcoreapp2.0/publish/ /app + +ENTRYPOINT [ "/usr/bin/dotnet", "/app/Http2SampleApp.dll" ] diff --git a/samples/Http2SampleApp/Http2SampleApp.csproj b/samples/Http2SampleApp/Http2SampleApp.csproj new file mode 100644 index 0000000000..0fd184ca8d --- /dev/null +++ b/samples/Http2SampleApp/Http2SampleApp.csproj @@ -0,0 +1,21 @@ + + + + netcoreapp2.0 + false + + + + + + + + + + + + + + + + diff --git a/samples/Http2SampleApp/Program.cs b/samples/Http2SampleApp/Program.cs new file mode 100644 index 0000000000..249c41347c --- /dev/null +++ b/samples/Http2SampleApp/Program.cs @@ -0,0 +1,50 @@ +using System.Globalization; +using System.IO; +using System.Net; +using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Server.Kestrel.Core; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Logging; + +namespace Http2SampleApp +{ + public class Program + { + public static void Main(string[] args) + { + var configuration = new ConfigurationBuilder() + .AddEnvironmentVariables() + .Build(); + + if (!ushort.TryParse(configuration["BASE_PORT"], NumberStyles.None, CultureInfo.InvariantCulture, out var basePort)) + { + basePort = 5000; + } + + var hostBuilder = new WebHostBuilder() + .ConfigureLogging((_, factory) => + { + // Set logging to the MAX. + factory.SetMinimumLevel(LogLevel.Trace); + factory.AddConsole(); + }) + .UseKestrel(options => + { + // Run callbacks on the transport thread + options.ApplicationSchedulingMode = SchedulingMode.Inline; + + options.Listen(IPAddress.Any, basePort, listenOptions => + { + listenOptions.Protocols = HttpProtocols.Http1AndHttp2; + listenOptions.UseTls("testCert.pfx", "testPassword"); + listenOptions.UseConnectionLogging(); + }); + }) + .UseContentRoot(Directory.GetCurrentDirectory()) + .UseStartup(); + + hostBuilder.Build().Run(); + } + } +} diff --git a/samples/Http2SampleApp/Startup.cs b/samples/Http2SampleApp/Startup.cs new file mode 100644 index 0000000000..6dce6b8a19 --- /dev/null +++ b/samples/Http2SampleApp/Startup.cs @@ -0,0 +1,29 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Http; +using Microsoft.Extensions.DependencyInjection; + +namespace Http2SampleApp +{ + public class Startup + { + // This method gets called by the runtime. Use this method to add services to the container. + // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 + public void ConfigureServices(IServiceCollection services) + { + } + + // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. + public void Configure(IApplicationBuilder app, IHostingEnvironment env) + { + app.Run(async (context) => + { + await context.Response.WriteAsync("Hello World!"); + }); + } + } +} diff --git a/samples/Http2SampleApp/scripts/build-docker.ps1 b/samples/Http2SampleApp/scripts/build-docker.ps1 new file mode 100644 index 0000000000..eda82ace6f --- /dev/null +++ b/samples/Http2SampleApp/scripts/build-docker.ps1 @@ -0,0 +1,3 @@ +dotnet publish --framework netcoreapp2.0 "$PSScriptRoot/../Http2SampleApp.csproj" + +docker build -t kestrel-http2-sample (Convert-Path "$PSScriptRoot/..") diff --git a/samples/Http2SampleApp/scripts/build-docker.sh b/samples/Http2SampleApp/scripts/build-docker.sh new file mode 100755 index 0000000000..ca226f0b53 --- /dev/null +++ b/samples/Http2SampleApp/scripts/build-docker.sh @@ -0,0 +1,6 @@ +#!/usr/bin/env bash +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" + +dotnet publish --framework netcoreapp2.0 "$DIR/../Http2SampleApp.csproj" + +docker build -t kestrel-http2-sample "$DIR/.." diff --git a/samples/Http2SampleApp/scripts/run-docker.ps1 b/samples/Http2SampleApp/scripts/run-docker.ps1 new file mode 100644 index 0000000000..7b371b6dde --- /dev/null +++ b/samples/Http2SampleApp/scripts/run-docker.ps1 @@ -0,0 +1 @@ +docker run -p 5000:5000 -it --rm kestrel-http2-sample diff --git a/samples/Http2SampleApp/scripts/run-docker.sh b/samples/Http2SampleApp/scripts/run-docker.sh new file mode 100755 index 0000000000..3039b34a98 --- /dev/null +++ b/samples/Http2SampleApp/scripts/run-docker.sh @@ -0,0 +1,2 @@ +#!/usr/bin/env bash +docker run -it -p 5000:5000 --rm kestrel-http2-sample diff --git a/samples/SampleApp/SampleApp.csproj b/samples/SampleApp/SampleApp.csproj index 7d62f70177..2225608125 100644 --- a/samples/SampleApp/SampleApp.csproj +++ b/samples/SampleApp/SampleApp.csproj @@ -6,10 +6,6 @@ true - - - - @@ -19,4 +15,8 @@ + + + + diff --git a/samples/SampleApp/testCert.pfx b/samples/SampleApp/testCert.pfx deleted file mode 100644 index 7118908c2d730670c16e9f8b2c532a262c951989..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}iX-K^2 w#3o+=C+lQz2J+SOEzVX(eJ)e7=eicC{rr9U2VGDcdH?_b diff --git a/src/Kestrel.Core/Internal/Http2/Http2Frame.Data.cs b/src/Kestrel.Core/Internal/Http2/Http2Frame.Data.cs index 9a0760fe6e..91f0edb72a 100644 --- a/src/Kestrel.Core/Internal/Http2/Http2Frame.Data.cs +++ b/src/Kestrel.Core/Internal/Http2/Http2Frame.Data.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using Microsoft.Extensions.Logging; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 { @@ -40,5 +41,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 Payload.Slice(Length - padLength.Value).Fill(0); } } + + private void DataTraceFrame(ILogger logger) + { + logger.LogTrace("'DATA' Frame. Flags = {DataFlags}, PadLength = {PadLength}, PayloadLength = {PayloadLength}", DataFlags, DataPadLength, DataPayload.Count); + } } } diff --git a/src/Kestrel.Core/Internal/Http2/Http2Frame.cs b/src/Kestrel.Core/Internal/Http2/Http2Frame.cs index e0dbf8bd09..f983b632a3 100644 --- a/src/Kestrel.Core/Internal/Http2/Http2Frame.cs +++ b/src/Kestrel.Core/Internal/Http2/Http2Frame.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using Microsoft.Extensions.Logging; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 { diff --git a/src/Kestrel.Tls/ListenOptionsTlsExtensions.cs b/src/Kestrel.Tls/ListenOptionsTlsExtensions.cs index cb2c459152..695297eb56 100644 --- a/src/Kestrel.Tls/ListenOptionsTlsExtensions.cs +++ b/src/Kestrel.Tls/ListenOptionsTlsExtensions.cs @@ -10,12 +10,12 @@ namespace Microsoft.AspNetCore.Hosting { public static class ListenOptionsTlsExtensions { - public static ListenOptions UseTls(this ListenOptions listenOptions, string certificatePath, string privateKeyPath) + public static ListenOptions UseTls(this ListenOptions listenOptions, string certificatePath, string password) { return listenOptions.UseTls(new TlsConnectionAdapterOptions { CertificatePath = certificatePath, - PrivateKeyPath = privateKeyPath, + Password = password, Protocols = listenOptions.Protocols }); } diff --git a/src/Kestrel.Tls/OpenSsl.cs b/src/Kestrel.Tls/OpenSsl.cs index 17568e4b9c..52af7a8857 100644 --- a/src/Kestrel.Tls/OpenSsl.cs +++ b/src/Kestrel.Tls/OpenSsl.cs @@ -15,23 +15,46 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Tls public const int OPENSSL_NPN_NEGOTIATED = 1; public const int SSL_TLSEXT_ERR_OK = 0; public const int SSL_TLSEXT_ERR_NOACK = 3; + public const int SSL_CTRL_CHAIN = 88; private const int BIO_C_SET_BUF_MEM_EOF_RETURN = 130; private const int SSL_CTRL_SET_ECDH_AUTO = 94; - public static int SSL_library_init() + public static void SSL_library_init() { - return NativeMethods.SSL_library_init(); + try + { + // Try OpenSSL 1.0.2 + NativeMethods.SSL_library_init(); + } + catch (EntryPointNotFoundException) + { + // It's fine, OpenSSL 1.1 doesn't need initialization + } } public static void SSL_load_error_strings() { - NativeMethods.SSL_load_error_strings(); + try + { + NativeMethods.SSL_load_error_strings(); + } + catch (EntryPointNotFoundException) + { + // Also fine, OpenSSL 1.1 doesn't need it. + } } public static void OpenSSL_add_all_algorithms() { - NativeMethods.OPENSSL_add_all_algorithms_noconf(); + try + { + NativeMethods.OPENSSL_add_all_algorithms_noconf(); + } + catch (EntryPointNotFoundException) + { + // Also fine, OpenSSL 1.1 doesn't need it. + } } public static IntPtr TLSv1_2_method() @@ -49,6 +72,41 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Tls NativeMethods.SSL_CTX_free(ctx); } + public unsafe static int SSL_CTX_Set_Pfx(IntPtr ctx, string path, string password) + { + var pass = Marshal.StringToHGlobalAnsi(password); + var key = IntPtr.Zero; + var cert = IntPtr.Zero; + var ca = IntPtr.Zero; + + try + { + var file = System.IO.File.ReadAllBytes(path); + + fixed (void* f = file) + { + var buffer = (IntPtr)f; + var pkcs = NativeMethods.d2i_PKCS12(IntPtr.Zero, ref buffer, file.Length); + var result = NativeMethods.PKCS12_parse(pkcs, pass, ref key, ref cert, ref ca); + if (result != 1) + { + return -1; + } + if (NativeMethods.SSL_CTX_use_certificate(ctx, cert) != 1) return -1; + if (NativeMethods.SSL_CTX_use_PrivateKey(ctx, key) != 1) return -1; + if (NativeMethods.SSL_CTX_ctrl(ctx, SSL_CTRL_CHAIN, 1, ca) != 1) return -1; + return 1; + } + } + finally + { + Marshal.FreeHGlobal(pass); + if (key != IntPtr.Zero) NativeMethods.EVP_PKEY_free(key); + if (cert != IntPtr.Zero) NativeMethods.X509_free(cert); + if (ca != IntPtr.Zero) NativeMethods.sk_X509_pop_free(ca); + } + } + public static int SSL_CTX_set_ecdh_auto(IntPtr ctx, int onoff) { return (int)NativeMethods.SSL_CTX_ctrl(ctx, SSL_CTRL_SET_ECDH_AUTO, onoff, IntPtr.Zero); @@ -109,6 +167,19 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Tls return NativeMethods.SSL_get_error(ssl, ret); } + public static int ERR_get_error() + { + return NativeMethods.ERR_get_error(); + } + + public static string ERR_error_string(int error) + { + var buf = NativeMethods.ERR_error_string(error, IntPtr.Zero); + + // Don't free the buffer! It's a static buffer + return Marshal.PtrToStringAnsi(buf); + } + public static void SSL_set_accept_state(IntPtr ssl) { NativeMethods.SSL_set_accept_state(ssl); @@ -263,6 +334,42 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Tls [DllImport("libssl", CallingConvention = CallingConvention.Cdecl)] public static extern void ERR_load_BIO_strings(); + + [DllImport("libssl", CallingConvention = CallingConvention.Cdecl)] + public static extern int ERR_get_error(); + + [DllImport("libssl", CallingConvention = CallingConvention.Cdecl)] + public static extern IntPtr ERR_error_string(int error, IntPtr buf); + + [DllImport("libssl", CallingConvention = CallingConvention.Cdecl)] + public static extern IntPtr d2i_PKCS12(IntPtr unsused, ref IntPtr bufferPointer, long length); + + [DllImport("libssl", CallingConvention = CallingConvention.Cdecl)] + public static extern int PKCS12_parse(IntPtr p12, IntPtr pass, ref IntPtr pkey, ref IntPtr cert, ref IntPtr ca); + + [DllImport("libssl", CallingConvention = CallingConvention.Cdecl)] + public static extern void PKCS12_free(IntPtr p12); + + [DllImport("libssl", CallingConvention = CallingConvention.Cdecl)] + public static extern void EVP_PKEY_free(IntPtr pkey); + + [DllImport("libssl", CallingConvention = CallingConvention.Cdecl)] + public static extern void X509_free(IntPtr a); + + [DllImport("libssl", CallingConvention = CallingConvention.Cdecl)] + public static extern void sk_X509_pop_free(IntPtr ca); + + [DllImport("libssl", CallingConvention = CallingConvention.Cdecl)] + public static extern int SSL_CTX_ctrl(IntPtr ctx, int cmd, int larg, IntPtr parg); + + [DllImport("libssl", CallingConvention = CallingConvention.Cdecl)] + public static extern int SSL_CTX_set1_chain(IntPtr ctx, IntPtr sk); + + [DllImport("libssl", CallingConvention = CallingConvention.Cdecl)] + public static extern int SSL_CTX_use_certificate(IntPtr ctx, IntPtr x509); + + [DllImport("libssl", CallingConvention = CallingConvention.Cdecl)] + public static extern int SSL_CTX_use_PrivateKey(IntPtr ctx, IntPtr pkey); } } } diff --git a/src/Kestrel.Tls/TlsConnectionAdapter.cs b/src/Kestrel.Tls/TlsConnectionAdapter.cs index 539c8404f3..8dee80eb68 100644 --- a/src/Kestrel.Tls/TlsConnectionAdapter.cs +++ b/src/Kestrel.Tls/TlsConnectionAdapter.cs @@ -40,9 +40,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Tls throw new ArgumentException("Certificate path must be non-null.", nameof(options)); } - if (options.PrivateKeyPath == null) + if (options.Password == null) { - throw new ArgumentException("Private key path must be non-null.", nameof(options)); + throw new ArgumentException("Password must be non-null.", nameof(options)); } _options = options; @@ -70,7 +70,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Tls private async Task InnerOnConnectionAsync(ConnectionAdapterContext context) { - var tlsStream = new TlsStream(context.ConnectionStream, _options.CertificatePath, _options.PrivateKeyPath, _serverProtocols); + var tlsStream = new TlsStream(context.ConnectionStream, _options.CertificatePath, _options.Password, _serverProtocols); try { diff --git a/src/Kestrel.Tls/TlsConnectionAdapterOptions.cs b/src/Kestrel.Tls/TlsConnectionAdapterOptions.cs index 88d107ffdd..220bd47d9c 100644 --- a/src/Kestrel.Tls/TlsConnectionAdapterOptions.cs +++ b/src/Kestrel.Tls/TlsConnectionAdapterOptions.cs @@ -9,7 +9,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Tls { public string CertificatePath { get; set; } = string.Empty; - public string PrivateKeyPath { get; set; } = string.Empty; + public string Password { get; set; } = string.Empty; public HttpProtocols Protocols { get; set; } } diff --git a/src/Kestrel.Tls/TlsStream.cs b/src/Kestrel.Tls/TlsStream.cs index 0b1b583167..497317bab7 100644 --- a/src/Kestrel.Tls/TlsStream.cs +++ b/src/Kestrel.Tls/TlsStream.cs @@ -9,11 +9,15 @@ using System.Runtime.InteropServices; using System.Text; using System.Threading; using System.Threading.Tasks; +using Microsoft.Extensions.Logging; namespace Microsoft.AspNetCore.Server.Kestrel.Tls { public class TlsStream : Stream { + // Error code that indicates that a handshake failed because unencrypted HTTP was sent + private const int SSL_ERROR_HTTP_REQUEST = 336130204; + private static unsafe OpenSsl.alpn_select_cb_t _alpnSelectCallback = AlpnSelectCallback; private readonly Stream _innerStream; @@ -36,7 +40,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Tls OpenSsl.OpenSSL_add_all_algorithms(); } - public TlsStream(Stream innerStream, string certificatePath, string privateKeyPath, IEnumerable protocols) + public TlsStream(Stream innerStream, string certificatePath, string password, IEnumerable protocols) { _innerStream = innerStream; _protocols = ToWireFormat(protocols); @@ -49,18 +53,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Tls throw new Exception("Unable to create SSL context."); } + if(OpenSsl.SSL_CTX_Set_Pfx(_ctx, certificatePath, password) != 1) + { + throw new InvalidOperationException("Unable to load PFX"); + } + OpenSsl.SSL_CTX_set_ecdh_auto(_ctx, 1); - - if (OpenSsl.SSL_CTX_use_certificate_file(_ctx, certificatePath, 1) != 1) - { - throw new Exception("Unable to load certificate file."); - } - - if (OpenSsl.SSL_CTX_use_PrivateKey_file(_ctx, privateKeyPath, 1) != 1) - { - throw new Exception("Unable to load private key file."); - } - + OpenSsl.SSL_CTX_set_alpn_select_cb(_ctx, _alpnSelectCallback, GCHandle.ToIntPtr(_protocolsHandle)); _ssl = OpenSsl.SSL_new(_ctx); @@ -181,9 +180,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Tls { var error = OpenSsl.SSL_get_error(_ssl, ret); - if (error != 2) + if (error == 1) { - throw new IOException($"TLS handshake failed: {nameof(OpenSsl.SSL_do_handshake)} error {error}."); + // SSL error, get it from the OpenSSL error queue + error = OpenSsl.ERR_get_error(); + if (error == SSL_ERROR_HTTP_REQUEST) + { + throw new InvalidOperationException("Unencrypted HTTP traffic was sent to an HTTPS endpoint"); + } + var errorString = OpenSsl.ERR_error_string(error); + throw new IOException($"TLS handshake failed: {nameof(OpenSsl.SSL_do_handshake)} error {error}. {errorString}"); } } From 5b6db93383b674861a73e3f35de9cef1d9caad49 Mon Sep 17 00:00:00 2001 From: JanEggers Date: Wed, 15 Nov 2017 20:30:35 +0100 Subject: [PATCH 1455/1662] fixed minor copy and paste error in mockconnection handler (#2163) --- .../TestHelpers/MockConnectionHandler.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Kestrel.Transport.Libuv.Tests/TestHelpers/MockConnectionHandler.cs b/test/Kestrel.Transport.Libuv.Tests/TestHelpers/MockConnectionHandler.cs index 5ae8289792..273f65f4d4 100644 --- a/test/Kestrel.Transport.Libuv.Tests/TestHelpers/MockConnectionHandler.cs +++ b/test/Kestrel.Transport.Libuv.Tests/TestHelpers/MockConnectionHandler.cs @@ -22,7 +22,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests.TestHelpers var connectionContext = new DefaultConnectionContext(features); Input = new Pipe(InputOptions(connectionContext.BufferPool)); - Output = new Pipe(InputOptions(connectionContext.BufferPool)); + Output = new Pipe(OutputOptions(connectionContext.BufferPool)); var feature = connectionContext.Features.Get(); From 186e9806cd2d276dba5524eda9416388f0d2883b Mon Sep 17 00:00:00 2001 From: Pranav K Date: Thu, 16 Nov 2017 13:59:38 -0800 Subject: [PATCH 1456/1662] Update samples and tests to target netcoreapp2.1 --- Directory.Build.props | 4 ++++ korebuild-lock.txt | 4 ++-- test/Directory.Build.props | 7 +++++++ test/Kestrel.Core.Tests/HttpRequestStreamTests.cs | 2 +- test/Kestrel.Core.Tests/Kestrel.Core.Tests.csproj | 3 +-- test/Kestrel.FunctionalTests/GeneratedCodeTests.cs | 2 +- test/Kestrel.Tests/Kestrel.Tests.csproj | 3 +-- .../Kestrel.Transport.Libuv.FunctionalTests.csproj | 5 ++--- .../Kestrel.Transport.Libuv.Tests.csproj | 3 +-- .../Kestrel.Transport.Sockets.FunctionalTests.csproj | 5 ++--- 10 files changed, 22 insertions(+), 16 deletions(-) diff --git a/Directory.Build.props b/Directory.Build.props index 396fba05b3..ebebe73c9c 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,4 +1,8 @@ + + diff --git a/korebuild-lock.txt b/korebuild-lock.txt index 86352477bb..b2036f3394 100644 --- a/korebuild-lock.txt +++ b/korebuild-lock.txt @@ -1,2 +1,2 @@ -version:2.1.0-preview1-15551 -commithash:8fad9553b48533fddbb16a423ea55b9710ea2e63 +version:2.1.0-preview1-15569 +commithash:47312a6364ad0ee6d7052eada54da940c9b17931 diff --git a/test/Directory.Build.props b/test/Directory.Build.props index 5891f8eb0b..3110e89ce7 100644 --- a/test/Directory.Build.props +++ b/test/Directory.Build.props @@ -1,6 +1,13 @@ + + netcoreapp2.1 + $(DeveloperBuildTestTfms) + netcoreapp2.1;netcoreapp2.0 + $(StandardTestTfms);net461 + + @@ -17,7 +16,7 @@ - + diff --git a/test/Kestrel.Transport.Libuv.Tests/Kestrel.Transport.Libuv.Tests.csproj b/test/Kestrel.Transport.Libuv.Tests/Kestrel.Transport.Libuv.Tests.csproj index ca477f9507..ef4f1d7742 100644 --- a/test/Kestrel.Transport.Libuv.Tests/Kestrel.Transport.Libuv.Tests.csproj +++ b/test/Kestrel.Transport.Libuv.Tests/Kestrel.Transport.Libuv.Tests.csproj @@ -3,8 +3,7 @@ Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests - netcoreapp2.0;net461 - netcoreapp2.0 + $(StandardTestTfms) true true diff --git a/test/Kestrel.Transport.Sockets.FunctionalTests/Kestrel.Transport.Sockets.FunctionalTests.csproj b/test/Kestrel.Transport.Sockets.FunctionalTests/Kestrel.Transport.Sockets.FunctionalTests.csproj index 8bc5d93436..901c8ca106 100644 --- a/test/Kestrel.Transport.Sockets.FunctionalTests/Kestrel.Transport.Sockets.FunctionalTests.csproj +++ b/test/Kestrel.Transport.Sockets.FunctionalTests/Kestrel.Transport.Sockets.FunctionalTests.csproj @@ -3,8 +3,7 @@ Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.FunctionalTests Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.FunctionalTests - netcoreapp2.0;net461 - netcoreapp2.0 + $(StandardTestTfms) $(DefineConstants);MACOS $(DefineConstants);SOCKETS true @@ -16,7 +15,7 @@ - + From 89d1862f211e15d8aae367a6d86de26b173bf6b0 Mon Sep 17 00:00:00 2001 From: "Chris Ross (ASP.NET)" Date: Tue, 14 Nov 2017 15:54:30 -0800 Subject: [PATCH 1457/1662] #2139 Add ListenLocalhost and ListenAnyIP --- samples/SampleApp/Startup.cs | 7 + src/Kestrel.Core/AnyIPListenOptions.cs | 37 ++++++ .../Internal/AddressBindContext.cs | 21 +++ src/Kestrel.Core/Internal/AddressBinder.cs | 123 +++--------------- src/Kestrel.Core/KestrelServerOptions.cs | 34 +++++ src/Kestrel.Core/ListenOptions.cs | 9 +- src/Kestrel.Core/LocalhostListenOptions.cs | 88 +++++++++++++ test/Kestrel.Core.Tests/AddressBinderTests.cs | 57 +++++--- .../AddressRegistrationTests.cs | 108 +++++++++++---- .../LibuvOutputConsumerTests.cs | 2 +- 10 files changed, 341 insertions(+), 145 deletions(-) create mode 100644 src/Kestrel.Core/AnyIPListenOptions.cs create mode 100644 src/Kestrel.Core/Internal/AddressBindContext.cs create mode 100644 src/Kestrel.Core/LocalhostListenOptions.cs diff --git a/samples/SampleApp/Startup.cs b/samples/SampleApp/Startup.cs index 562f3a020d..bf8ce0e1a3 100644 --- a/samples/SampleApp/Startup.cs +++ b/samples/SampleApp/Startup.cs @@ -76,6 +76,13 @@ namespace SampleApp listenOptions.UseConnectionLogging(); }); + options.ListenLocalhost(basePort + 2, listenOptions => + { + listenOptions.UseHttps("testCert.pfx", "testPassword"); + }); + + options.ListenAnyIP(basePort + 3); + options.UseSystemd(); // The following section should be used to demo sockets diff --git a/src/Kestrel.Core/AnyIPListenOptions.cs b/src/Kestrel.Core/AnyIPListenOptions.cs new file mode 100644 index 0000000000..2639337dd7 --- /dev/null +++ b/src/Kestrel.Core/AnyIPListenOptions.cs @@ -0,0 +1,37 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.IO; +using System.Net; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal; +using Microsoft.Extensions.Logging; + +namespace Microsoft.AspNetCore.Server.Kestrel.Core +{ + internal class AnyIPListenOptions : ListenOptions + { + internal AnyIPListenOptions(int port) + : base(new IPEndPoint(IPAddress.IPv6Any, port)) + { + } + + internal override async Task BindAsync(AddressBindContext context) + { + // when address is 'http://hostname:port', 'http://*:port', or 'http://+:port' + try + { + await base.BindAsync(context).ConfigureAwait(false); + } + catch (Exception ex) when (!(ex is IOException)) + { + context.Logger.LogDebug(CoreStrings.FormatFallbackToIPv4Any(IPEndPoint.Port)); + + // for machines that do not support IPv6 + IPEndPoint = new IPEndPoint(IPAddress.Any, IPEndPoint.Port); + await base.BindAsync(context).ConfigureAwait(false); + } + } + } +} diff --git a/src/Kestrel.Core/Internal/AddressBindContext.cs b/src/Kestrel.Core/Internal/AddressBindContext.cs new file mode 100644 index 0000000000..e2f46e6025 --- /dev/null +++ b/src/Kestrel.Core/Internal/AddressBindContext.cs @@ -0,0 +1,21 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Collections.Generic; +using System.Threading.Tasks; +using Microsoft.Extensions.Logging; + +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal +{ + internal class AddressBindContext + { + public ICollection Addresses { get; set; } + public List ListenOptions { get; set; } + public KestrelServerOptions ServerOptions { get; set; } + public ILogger Logger { get; set; } + public IDefaultHttpsProvider DefaultHttpsProvider { get; set; } + + public Func CreateBinding { get; set; } + } +} diff --git a/src/Kestrel.Core/Internal/AddressBinder.cs b/src/Kestrel.Core/Internal/AddressBinder.cs index 808675c0fb..5334308ad8 100644 --- a/src/Kestrel.Core/Internal/AddressBinder.cs +++ b/src/Kestrel.Core/Internal/AddressBinder.cs @@ -47,17 +47,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal await strategy.BindAsync(context).ConfigureAwait(false); } - private class AddressBindContext - { - public ICollection Addresses { get; set; } - public List ListenOptions { get; set; } - public KestrelServerOptions ServerOptions { get; set; } - public ILogger Logger { get; set; } - public IDefaultHttpsProvider DefaultHttpsProvider { get; set; } - - public Func CreateBinding { get; set; } - } - private static IStrategy CreateStrategy(ListenOptions[] listenOptions, string[] addresses, bool preferAddresses) { var hasListenOptions = listenOptions.Length > 0; @@ -109,10 +98,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal return true; } - private static Task BindEndpointAsync(IPEndPoint endpoint, AddressBindContext context) - => BindEndpointAsync(new ListenOptions(endpoint), context); - - private static async Task BindEndpointAsync(ListenOptions endpoint, AddressBindContext context) + internal static async Task BindEndpointAsync(ListenOptions endpoint, AddressBindContext context) { try { @@ -126,60 +112,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal context.ListenOptions.Add(endpoint); } - private static async Task BindLocalhostAsync(ServerAddress address, AddressBindContext context, bool https) - { - if (address.Port == 0) - { - throw new InvalidOperationException(CoreStrings.DynamicPortOnLocalhostNotSupported); - } - - var exceptions = new List(); - - try - { - var options = new ListenOptions(new IPEndPoint(IPAddress.Loopback, address.Port)); - await BindEndpointAsync(options, context).ConfigureAwait(false); - - if (https) - { - options.KestrelServerOptions = context.ServerOptions; - context.DefaultHttpsProvider.ConfigureHttps(options); - } - } - catch (Exception ex) when (!(ex is IOException)) - { - context.Logger.LogWarning(0, CoreStrings.NetworkInterfaceBindingFailed, address, "IPv4 loopback", ex.Message); - exceptions.Add(ex); - } - - try - { - var options = new ListenOptions(new IPEndPoint(IPAddress.IPv6Loopback, address.Port)); - await BindEndpointAsync(options, context).ConfigureAwait(false); - - if (https) - { - options.KestrelServerOptions = context.ServerOptions; - context.DefaultHttpsProvider.ConfigureHttps(options); - } - } - catch (Exception ex) when (!(ex is IOException)) - { - context.Logger.LogWarning(0, CoreStrings.NetworkInterfaceBindingFailed, address, "IPv6 loopback", ex.Message); - exceptions.Add(ex); - } - - if (exceptions.Count == 2) - { - throw new IOException(CoreStrings.FormatAddressBindingFailed(address), new AggregateException(exceptions)); - } - - // If StartLocalhost doesn't throw, there is at least one listener. - // The port cannot change for "localhost". - context.Addresses.Add(address.ToString()); - } - - private static async Task BindAddressAsync(string address, AddressBindContext context) + internal static ListenOptions ParseAddress(string address, KestrelServerOptions serverOptions, IDefaultHttpsProvider defaultHttpsProvider) { var parsedAddress = ServerAddress.FromUrl(address); var https = false; @@ -202,47 +135,29 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal if (parsedAddress.IsUnixPipe) { options = new ListenOptions(parsedAddress.UnixPipePath); - await BindEndpointAsync(options, context).ConfigureAwait(false); - context.Addresses.Add(options.GetDisplayName()); } else if (string.Equals(parsedAddress.Host, "localhost", StringComparison.OrdinalIgnoreCase)) { // "localhost" for both IPv4 and IPv6 can't be represented as an IPEndPoint. - await BindLocalhostAsync(parsedAddress, context, https).ConfigureAwait(false); + options = new LocalhostListenOptions(parsedAddress.Port); + } + else if (TryCreateIPEndPoint(parsedAddress, out var endpoint)) + { + options = new ListenOptions(endpoint); } else { - if (TryCreateIPEndPoint(parsedAddress, out var endpoint)) - { - options = new ListenOptions(endpoint); - await BindEndpointAsync(options, context).ConfigureAwait(false); - } - else - { - // when address is 'http://hostname:port', 'http://*:port', or 'http://+:port' - try - { - options = new ListenOptions(new IPEndPoint(IPAddress.IPv6Any, parsedAddress.Port)); - await BindEndpointAsync(options, context).ConfigureAwait(false); - } - catch (Exception ex) when (!(ex is IOException)) - { - context.Logger.LogDebug(CoreStrings.FormatFallbackToIPv4Any(parsedAddress.Port)); - - // for machines that do not support IPv6 - options = new ListenOptions(new IPEndPoint(IPAddress.Any, parsedAddress.Port)); - await BindEndpointAsync(options, context).ConfigureAwait(false); - } - } - - context.Addresses.Add(options.GetDisplayName()); + // when address is 'http://hostname:port', 'http://*:port', or 'http://+:port' + options = new AnyIPListenOptions(parsedAddress.Port); } - if (https && options != null) + if (https) { - options.KestrelServerOptions = context.ServerOptions; - context.DefaultHttpsProvider.ConfigureHttps(options); + options.KestrelServerOptions = serverOptions; + defaultHttpsProvider.ConfigureHttps(options); } + + return options; } private interface IStrategy @@ -256,7 +171,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal { context.Logger.LogDebug(CoreStrings.BindingToDefaultAddress, Constants.DefaultServerAddress); - await BindLocalhostAsync(ServerAddress.FromUrl(Constants.DefaultServerAddress), context, https: false).ConfigureAwait(false); + await ParseAddress(Constants.DefaultServerAddress, context.ServerOptions, context.DefaultHttpsProvider) + .BindAsync(context).ConfigureAwait(false); } } @@ -308,9 +224,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal { foreach (var endpoint in _endpoints) { - await BindEndpointAsync(endpoint, context).ConfigureAwait(false); - - context.Addresses.Add(endpoint.GetDisplayName()); + await endpoint.BindAsync(context).ConfigureAwait(false); } } } @@ -328,7 +242,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal { foreach (var address in _addresses) { - await BindAddressAsync(address, context).ConfigureAwait(false); + await ParseAddress(address, context.ServerOptions, context.DefaultHttpsProvider) + .BindAsync(context).ConfigureAwait(false); } } } diff --git a/src/Kestrel.Core/KestrelServerOptions.cs b/src/Kestrel.Core/KestrelServerOptions.cs index 136b983533..3d70664cbe 100644 --- a/src/Kestrel.Core/KestrelServerOptions.cs +++ b/src/Kestrel.Core/KestrelServerOptions.cs @@ -105,6 +105,40 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core ListenOptions.Add(listenOptions); } + public void ListenLocalhost(int port) => ListenLocalhost(port, options => { }); + + public void ListenLocalhost(int port, Action configure) + { + if (configure == null) + { + throw new ArgumentNullException(nameof(configure)); + } + + var listenOptions = new LocalhostListenOptions(port) + { + KestrelServerOptions = this, + }; + configure(listenOptions); + ListenOptions.Add(listenOptions); + } + + public void ListenAnyIP(int port) => ListenAnyIP(port, options => { }); + + public void ListenAnyIP(int port, Action configure) + { + if (configure == null) + { + throw new ArgumentNullException(nameof(configure)); + } + + var listenOptions = new AnyIPListenOptions(port) + { + KestrelServerOptions = this, + }; + configure(listenOptions); + ListenOptions.Add(listenOptions); + } + /// /// Bind to given Unix domain socket path. /// diff --git a/src/Kestrel.Core/ListenOptions.cs b/src/Kestrel.Core/ListenOptions.cs index 19e94c43a6..08e728a35c 100644 --- a/src/Kestrel.Core/ListenOptions.cs +++ b/src/Kestrel.Core/ListenOptions.cs @@ -8,6 +8,7 @@ using System.Net; using System.Threading.Tasks; using Microsoft.AspNetCore.Protocols; using Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal; using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; namespace Microsoft.AspNetCore.Server.Kestrel.Core @@ -140,7 +141,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core /// /// Gets the name of this endpoint to display on command-line when the web server starts. /// - internal string GetDisplayName() + internal virtual string GetDisplayName() { var scheme = ConnectionAdapters.Any(f => f.IsHttps) ? "https" @@ -182,5 +183,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core return app; } + + internal virtual async Task BindAsync(AddressBindContext context) + { + await AddressBinder.BindEndpointAsync(this, context).ConfigureAwait(false); + context.Addresses.Add(GetDisplayName()); + } } } diff --git a/src/Kestrel.Core/LocalhostListenOptions.cs b/src/Kestrel.Core/LocalhostListenOptions.cs new file mode 100644 index 0000000000..39c49abbfc --- /dev/null +++ b/src/Kestrel.Core/LocalhostListenOptions.cs @@ -0,0 +1,88 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Net; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal; +using Microsoft.Extensions.Logging; + +namespace Microsoft.AspNetCore.Server.Kestrel.Core +{ + internal class LocalhostListenOptions : ListenOptions + { + internal LocalhostListenOptions(int port) + : base(new IPEndPoint(IPAddress.Loopback, port)) + { + if (port == 0) + { + throw new InvalidOperationException(CoreStrings.DynamicPortOnLocalhostNotSupported); + } + } + + /// + /// Gets the name of this endpoint to display on command-line when the web server starts. + /// + internal override string GetDisplayName() + { + var scheme = ConnectionAdapters.Any(f => f.IsHttps) + ? "https" + : "http"; + + return $"{scheme}://localhost:{IPEndPoint.Port}"; + } + + internal override async Task BindAsync(AddressBindContext context) + { + var exceptions = new List(); + + try + { + var v4Options = Clone(IPAddress.Loopback); + await AddressBinder.BindEndpointAsync(v4Options, context).ConfigureAwait(false); + } + catch (Exception ex) when (!(ex is IOException)) + { + context.Logger.LogWarning(0, CoreStrings.NetworkInterfaceBindingFailed, GetDisplayName(), "IPv4 loopback", ex.Message); + exceptions.Add(ex); + } + + try + { + var v6Options = Clone(IPAddress.IPv6Loopback); + await AddressBinder.BindEndpointAsync(v6Options, context).ConfigureAwait(false); + } + catch (Exception ex) when (!(ex is IOException)) + { + context.Logger.LogWarning(0, CoreStrings.NetworkInterfaceBindingFailed, GetDisplayName(), "IPv6 loopback", ex.Message); + exceptions.Add(ex); + } + + if (exceptions.Count == 2) + { + throw new IOException(CoreStrings.FormatAddressBindingFailed(GetDisplayName()), new AggregateException(exceptions)); + } + + // If StartLocalhost doesn't throw, there is at least one listener. + // The port cannot change for "localhost". + context.Addresses.Add(GetDisplayName()); + } + + // used for cloning to two IPEndpoints + private ListenOptions Clone(IPAddress address) + { + var options = new ListenOptions(new IPEndPoint(address, IPEndPoint.Port)) + { + HandleType = HandleType, + KestrelServerOptions = KestrelServerOptions, + NoDelay = NoDelay, + Protocols = Protocols, + }; + options.ConnectionAdapters.AddRange(ConnectionAdapters); + return options; + } + } +} diff --git a/test/Kestrel.Core.Tests/AddressBinderTests.cs b/test/Kestrel.Core.Tests/AddressBinderTests.cs index d42a598e9c..f2580353db 100644 --- a/test/Kestrel.Core.Tests/AddressBinderTests.cs +++ b/test/Kestrel.Core.Tests/AddressBinderTests.cs @@ -2,12 +2,12 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.Collections.Generic; using System.IO; using System.Net; using System.Threading.Tasks; using Microsoft.AspNetCore.Protocols; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; using Microsoft.AspNetCore.Testing; using Microsoft.Extensions.Logging.Abstractions; using Moq; @@ -51,24 +51,49 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests [InlineData("randomhost")] [InlineData("+")] [InlineData("contoso.com")] - public async Task DefaultsToIPv6AnyOnInvalidIPAddress(string host) + public void ParseAddressDefaultsToAnyIPOnInvalidIPAddress(string host) { - var addresses = new ServerAddressesFeature(); - addresses.Addresses.Add($"http://{host}"); var options = new KestrelServerOptions(); + var listenOptions = AddressBinder.ParseAddress($"http://{host}", options, Mock.Of()); + Assert.IsType(listenOptions); + Assert.Equal(ListenType.IPEndPoint, listenOptions.Type); + Assert.Equal(IPAddress.IPv6Any, listenOptions.IPEndPoint.Address); + Assert.Equal(80, listenOptions.IPEndPoint.Port); + } - var tcs = new TaskCompletionSource(); - await AddressBinder.BindAsync(addresses, - options, - NullLogger.Instance, - Mock.Of(), - endpoint => - { - tcs.TrySetResult(endpoint); - return Task.CompletedTask; - }); - var result = await tcs.Task; - Assert.Equal(IPAddress.IPv6Any, result.IPEndPoint.Address); + [Fact] + public void ParseAddressLocalhost() + { + var options = new KestrelServerOptions(); + var listenOptions = AddressBinder.ParseAddress("http://localhost", options, Mock.Of()); + Assert.IsType(listenOptions); + Assert.Equal(ListenType.IPEndPoint, listenOptions.Type); + Assert.Equal(IPAddress.Loopback, listenOptions.IPEndPoint.Address); + Assert.Equal(80, listenOptions.IPEndPoint.Port); + } + + [Fact] + public void ParseAddressUnixPipe() + { + var options = new KestrelServerOptions(); + var listenOptions = AddressBinder.ParseAddress("http://unix:/tmp/kestrel-test.sock", options, Mock.Of()); + Assert.Equal(ListenType.SocketPath, listenOptions.Type); + Assert.Equal("/tmp/kestrel-test.sock", listenOptions.SocketPath); + } + + [Theory] + [InlineData("http://10.10.10.10:5000/", "10.10.10.10", 5000)] + [InlineData("http://[::1]:5000", "::1", 5000)] + [InlineData("http://[::1]", "::1", 80)] + [InlineData("http://127.0.0.1", "127.0.0.1", 80)] + [InlineData("https://127.0.0.1", "127.0.0.1", 443)] + public void ParseAddressIP(string address, string ip, int port) + { + var options = new KestrelServerOptions(); + var listenOptions = AddressBinder.ParseAddress(address, options, Mock.Of()); + Assert.Equal(ListenType.IPEndPoint, listenOptions.Type); + Assert.Equal(IPAddress.Parse(ip), listenOptions.IPEndPoint.Address); + Assert.Equal(port, listenOptions.IPEndPoint.Port); } [Fact] diff --git a/test/Kestrel.FunctionalTests/AddressRegistrationTests.cs b/test/Kestrel.FunctionalTests/AddressRegistrationTests.cs index 446a201f71..58d7369b50 100644 --- a/test/Kestrel.FunctionalTests/AddressRegistrationTests.cs +++ b/test/Kestrel.FunctionalTests/AddressRegistrationTests.cs @@ -187,7 +187,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests private Task RegisterAddresses_Success(string addressInput, string testUrl, int testPort = 0) => RegisterAddresses_Success(addressInput, new[] { testUrl }, testPort); - private async Task RegisterAddresses_StaticPort_Success(string addressInput, string[] testUrls) + private Task RegisterAddresses_StaticPort_Success(string addressInput, string[] testUrls) => + RunTestWithStaticPort(port => RegisterAddresses_Success($"{addressInput}:{port}", testUrls, port)); + + private async Task RunTestWithStaticPort(Func test) { var retryCount = 0; var errors = new List(); @@ -197,7 +200,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests try { var port = GetNextPort(); - await RegisterAddresses_Success($"{addressInput}:{port}", testUrls, port); + await test(port); return; } catch (XunitException) @@ -254,34 +257,93 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } } - private async Task RegisterIPEndPoint_StaticPort_Success(IPAddress address, string testUrl) + private Task RegisterIPEndPoint_StaticPort_Success(IPAddress address, string testUrl) + => RunTestWithStaticPort(port => RegisterIPEndPoint_Success(new IPEndPoint(address, port), testUrl, port)); + + [ConditionalFact] + public async Task ListenAnyIP_IPv4_Success() { - var retryCount = 0; - var errors = new List(); + await ListenAnyIP_Success(new[] { "http://localhost", "http://127.0.0.1" }); + } - while (retryCount < MaxRetries) + [ConditionalFact] + [IPv6SupportedCondition] + public async Task ListenAnyIP_IPv6_Success() + { + await ListenAnyIP_Success(new[] { "http://[::1]", "http://localhost", "http://127.0.0.1" }); + } + + [ConditionalFact] + [NetworkIsReachable] + public async Task ListenAnyIP_HostName_Success() + { + var hostName = Dns.GetHostName(); + await ListenAnyIP_Success(new[] { $"http://{hostName}" }); + } + + private async Task ListenAnyIP_Success(string[] testUrls, int testPort = 0) + { + var hostBuilder = TransportSelector.GetWebHostBuilder() + .UseKestrel(options => + { + options.ListenAnyIP(testPort); + }) + .ConfigureLogging(_configureLoggingDelegate) + .Configure(ConfigureEchoAddress); + + using (var host = hostBuilder.Build()) { - try - { - var port = GetNextPort(); - await RegisterIPEndPoint_Success(new IPEndPoint(address, port), testUrl, port); - return; - } - catch (XunitException) - { - throw; - } - catch (Exception ex) - { - errors.Add(ex); - } + host.Start(); - retryCount++; + foreach (var testUrl in testUrls.Select(testUrl => $"{testUrl}:{(testPort == 0 ? host.GetPort() : testPort)}")) + { + var response = await HttpClientSlim.GetStringAsync(testUrl, validateCertificate: false); + + // Compare the response with Uri.ToString(), rather than testUrl directly. + // Required to handle IPv6 addresses with zone index, like "fe80::3%1" + Assert.Equal(new Uri(testUrl).ToString(), response); + } } + } - if (errors.Any()) + [ConditionalFact] + public async Task ListenLocalhost_IPv4LocalhostStaticPort_Success() + { + await ListenLocalhost_StaticPort_Success(new[] { "http://localhost", "http://127.0.0.1" }); + } + + [ConditionalFact] + [IPv6SupportedCondition] + public async Task ListenLocalhost_IPv6LocalhostStaticPort_Success() + { + await ListenLocalhost_StaticPort_Success(new[] { "http://localhost", "http://127.0.0.1", "http://[::1]" }); + } + + private Task ListenLocalhost_StaticPort_Success(string[] testUrls) => + RunTestWithStaticPort(port => ListenLocalhost_Success(testUrls, port)); + + private async Task ListenLocalhost_Success(string[] testUrls, int testPort = 0) + { + var hostBuilder = TransportSelector.GetWebHostBuilder() + .UseKestrel(options => + { + options.ListenLocalhost(testPort); + }) + .ConfigureLogging(_configureLoggingDelegate) + .Configure(ConfigureEchoAddress); + + using (var host = hostBuilder.Build()) { - throw new AggregateException(errors); + host.Start(); + + foreach (var testUrl in testUrls.Select(testUrl => $"{testUrl}:{(testPort == 0 ? host.GetPort() : testPort)}")) + { + var response = await HttpClientSlim.GetStringAsync(testUrl, validateCertificate: false); + + // Compare the response with Uri.ToString(), rather than testUrl directly. + // Required to handle IPv6 addresses with zone index, like "fe80::3%1" + Assert.Equal(new Uri(testUrl).ToString(), response); + } } } diff --git a/test/Kestrel.Transport.Libuv.Tests/LibuvOutputConsumerTests.cs b/test/Kestrel.Transport.Libuv.Tests/LibuvOutputConsumerTests.cs index 2a7b0ee4c1..54dd7ed013 100644 --- a/test/Kestrel.Transport.Libuv.Tests/LibuvOutputConsumerTests.cs +++ b/test/Kestrel.Transport.Libuv.Tests/LibuvOutputConsumerTests.cs @@ -41,7 +41,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests _bufferPool = new MemoryPool(); _mockLibuv = new MockLibuv(); - var libuvTransport = new LibuvTransport(_mockLibuv, new TestLibuvTransportContext(), new ListenOptions(0)); + var libuvTransport = new LibuvTransport(_mockLibuv, new TestLibuvTransportContext(), new ListenOptions((ulong)0)); _libuvThread = new LibuvThread(libuvTransport, maxLoops: 1); _libuvThread.StartAsync().Wait(); } From 67fc879c548048aa04288be7c313d0ebb92d6bc4 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Fri, 17 Nov 2017 12:41:35 -0800 Subject: [PATCH 1458/1662] Null out send buffer less (#2164) --- .../Internal/SocketSender.cs | 44 ++++++++----------- 1 file changed, 19 insertions(+), 25 deletions(-) diff --git a/src/Kestrel.Transport.Sockets/Internal/SocketSender.cs b/src/Kestrel.Transport.Sockets/Internal/SocketSender.cs index 0b3b998c6b..365339aa50 100644 --- a/src/Kestrel.Transport.Sockets/Internal/SocketSender.cs +++ b/src/Kestrel.Transport.Sockets/Internal/SocketSender.cs @@ -21,7 +21,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal { _socket = socket; _eventArgs.UserToken = _awaitable; - _eventArgs.Completed += (_, e) => SendCompleted(e, (SocketAwaitable)e.UserToken); + _eventArgs.Completed += (_, e) => ((SocketAwaitable)e.UserToken).Complete(e.BytesTransferred, e.SocketError); } public SocketAwaitable SendAsync(ReadableBuffer buffers) @@ -31,11 +31,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal return SendAsync(buffers.First); } + if (_eventArgs.Buffer != null) + { + _eventArgs.SetBuffer(null, 0, 0); + } + _eventArgs.BufferList = GetBufferList(buffers); if (!_socket.SendAsync(_eventArgs)) { - SendCompleted(_eventArgs, _awaitable); + _awaitable.Complete(_eventArgs.BytesTransferred, _eventArgs.SocketError); } return _awaitable; @@ -45,11 +50,17 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal { var segment = buffer.GetArray(); + // The BufferList getter is much less expensive then the setter. + if (_eventArgs.BufferList != null) + { + _eventArgs.BufferList = null; + } + _eventArgs.SetBuffer(segment.Array, segment.Offset, segment.Count); if (!_socket.SendAsync(_eventArgs)) { - SendCompleted(_eventArgs, _awaitable); + _awaitable.Complete(_eventArgs.BytesTransferred, _eventArgs.SocketError); } return _awaitable; @@ -64,9 +75,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal { _bufferList = new List>(); } - - // We should always clear the list after the send - Debug.Assert(_bufferList.Count == 0); + else + { + // Buffers are pooled, so it's OK to root them until the next multi-buffer write. + _bufferList.Clear(); + } foreach (var b in buffer) { @@ -75,24 +88,5 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal return _bufferList; } - - private static void SendCompleted(SocketAsyncEventArgs e, SocketAwaitable awaitable) - { - // Clear buffer(s) to prevent the SetBuffer buffer and BufferList from both being - // set for the next write operation. This is unnecessary for reads since they never - // set BufferList. - - if (e.BufferList != null) - { - e.BufferList.Clear(); - e.BufferList = null; - } - else - { - e.SetBuffer(null, 0, 0); - } - - awaitable.Complete(e.BytesTransferred, e.SocketError); - } } } From 6a793c252f58e9acb718f3c9c99f97ff447a4507 Mon Sep 17 00:00:00 2001 From: Pranav K Date: Fri, 17 Nov 2017 13:00:25 -0800 Subject: [PATCH 1459/1662] Use MicrosoftNETCoreApp21PackageVersion to determine the runtime framework in netcoreapp2.1 --- Directory.Build.targets | 3 ++- build/dependencies.props | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Directory.Build.targets b/Directory.Build.targets index 0ff17438fc..894b1d0cf8 100644 --- a/Directory.Build.targets +++ b/Directory.Build.targets @@ -1,5 +1,6 @@ - + $(MicrosoftNETCoreApp20PackageVersion) + $(MicrosoftNETCoreApp21PackageVersion) diff --git a/build/dependencies.props b/build/dependencies.props index 243bff93f3..46a0a1cd5d 100644 --- a/build/dependencies.props +++ b/build/dependencies.props @@ -1,4 +1,4 @@ - + $(MSBuildAllProjects);$(MSBuildThisFileFullPath) @@ -22,6 +22,7 @@ 2.1.0-preview1-27475 2.1.0-preview1-27475 2.0.0 + 2.1.0-preview1-25907-02 2.6.0-beta2-62211-02 2.1.0-preview1-27475 15.3.0 From a1d75df47d763afb79906d0a526d9d918d2176d7 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Mon, 20 Nov 2017 11:36:09 -0800 Subject: [PATCH 1460/1662] Use new Memory APIs on SocketAsyncEventArgs (#2173) - This should improve the performance of handling buffers by (eventually) removing GCHandle churn for Kestrel's already pinned buffers. - Made the Sockets transport target both netcoreapp2.1 and netstandard2.0 to use new APIs - Disable API check for the sockets transport --- src/Kestrel.Transport.Sockets/Internal/SocketReceiver.cs | 5 ++++- src/Kestrel.Transport.Sockets/Internal/SocketSender.cs | 9 ++++++--- .../Kestrel.Transport.Sockets.csproj | 3 ++- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/Kestrel.Transport.Sockets/Internal/SocketReceiver.cs b/src/Kestrel.Transport.Sockets/Internal/SocketReceiver.cs index ad3a99a0b0..0aff7d2cfd 100644 --- a/src/Kestrel.Transport.Sockets/Internal/SocketReceiver.cs +++ b/src/Kestrel.Transport.Sockets/Internal/SocketReceiver.cs @@ -21,10 +21,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal public SocketAwaitable ReceiveAsync(Memory buffer) { +#if NETCOREAPP2_1 + _eventArgs.SetBuffer(buffer); +#else var segment = buffer.GetArray(); _eventArgs.SetBuffer(segment.Array, segment.Offset, segment.Count); - +#endif if (!_socket.ReceiveAsync(_eventArgs)) { _awaitable.Complete(_eventArgs.BytesTransferred, _eventArgs.SocketError); diff --git a/src/Kestrel.Transport.Sockets/Internal/SocketSender.cs b/src/Kestrel.Transport.Sockets/Internal/SocketSender.cs index 365339aa50..688704811c 100644 --- a/src/Kestrel.Transport.Sockets/Internal/SocketSender.cs +++ b/src/Kestrel.Transport.Sockets/Internal/SocketSender.cs @@ -48,16 +48,19 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal private SocketAwaitable SendAsync(Memory buffer) { - var segment = buffer.GetArray(); - // The BufferList getter is much less expensive then the setter. if (_eventArgs.BufferList != null) { _eventArgs.BufferList = null; } - _eventArgs.SetBuffer(segment.Array, segment.Offset, segment.Count); +#if NETCOREAPP2_1 + _eventArgs.SetBuffer(buffer); +#else + var segment = buffer.GetArray(); + _eventArgs.SetBuffer(segment.Array, segment.Offset, segment.Count); +#endif if (!_socket.SendAsync(_eventArgs)) { _awaitable.Complete(_eventArgs.BytesTransferred, _eventArgs.SocketError); diff --git a/src/Kestrel.Transport.Sockets/Kestrel.Transport.Sockets.csproj b/src/Kestrel.Transport.Sockets/Kestrel.Transport.Sockets.csproj index 1674a1d65f..8e065c4828 100644 --- a/src/Kestrel.Transport.Sockets/Kestrel.Transport.Sockets.csproj +++ b/src/Kestrel.Transport.Sockets/Kestrel.Transport.Sockets.csproj @@ -4,11 +4,12 @@ Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets Managed socket transport for the ASP.NET Core Kestrel cross-platform web server. - netstandard2.0 + netstandard2.0;netcoreapp2.1 true aspnetcore;kestrel true CS1591;$(NoWarn) + false From 2d69698cfa5b051c5bf0f06ef10645c79214596d Mon Sep 17 00:00:00 2001 From: Nate McMaster Date: Mon, 20 Nov 2017 16:05:56 -0800 Subject: [PATCH 1461/1662] Use MSBuild to set NuGet feeds instead of NuGet.config (#2176) --- Directory.Build.props | 3 ++- NuGet.config | 5 +---- build/sources.props | 17 +++++++++++++++++ 3 files changed, 20 insertions(+), 5 deletions(-) create mode 100644 build/sources.props diff --git a/Directory.Build.props b/Directory.Build.props index ebebe73c9c..877639ff43 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,10 +1,11 @@ - + + Microsoft ASP.NET Core diff --git a/NuGet.config b/NuGet.config index 9d49a5334e..e32bddfd51 100644 --- a/NuGet.config +++ b/NuGet.config @@ -2,9 +2,6 @@ - - - - + diff --git a/build/sources.props b/build/sources.props new file mode 100644 index 0000000000..e6a1c2b358 --- /dev/null +++ b/build/sources.props @@ -0,0 +1,17 @@ + + + + + $(DotNetRestoreSources) + + $(RestoreSources); + https://dotnet.myget.org/F/aspnetcore-ci-dev/api/v3/index.json; + https://dotnet.myget.org/F/aspnetcore-tools/api/v3/index.json; + https://dotnet.myget.org/F/roslyn/api/v3/index.json; + + + $(RestoreSources); + https://api.nuget.org/v3/index.json; + + + From afa48442305e1e74d3cb81ba17a51614e21fd194 Mon Sep 17 00:00:00 2001 From: Pranav K Date: Tue, 21 Nov 2017 15:48:11 -0800 Subject: [PATCH 1462/1662] Replace aspnetcore-ci-dev feed with aspnetcore-dev --- build/dependencies.props | 34 +++++++++++++++++----------------- build/repo.props | 4 ++-- build/sources.props | 2 +- korebuild-lock.txt | 4 ++-- 4 files changed, 22 insertions(+), 22 deletions(-) diff --git a/build/dependencies.props b/build/dependencies.props index 46a0a1cd5d..95d6623260 100644 --- a/build/dependencies.props +++ b/build/dependencies.props @@ -1,30 +1,30 @@ - + $(MSBuildAllProjects);$(MSBuildThisFileFullPath) 0.10.9 - 2.1.0-preview1-15549 + 2.1.0-preview1-15576 1.10.0 - 2.1.0-preview1-27475 - 2.1.0-preview1-27475 - 2.1.0-preview1-27475 - 2.1.0-preview1-27475 - 2.1.0-preview1-27475 - 2.1.0-preview1-27475 - 2.1.0-preview1-27475 - 2.1.0-preview1-27475 - 2.1.0-preview1-27475 - 2.1.0-preview1-27475 - 2.1.0-preview1-27475 - 2.1.0-preview1-27475 - 2.1.0-preview1-27475 - 2.1.0-preview1-27475 + 2.1.0-preview1-27644 + 2.1.0-preview1-27644 + 2.1.0-preview1-27644 + 2.1.0-preview1-27644 + 2.1.0-preview1-27644 + 2.1.0-preview1-27644 + 2.1.0-preview1-27644 + 2.1.0-preview1-27644 + 2.1.0-preview1-27644 + 2.1.0-preview1-27644 + 2.1.0-preview1-27644 + 2.1.0-preview1-27644 + 2.1.0-preview1-27644 + 2.1.0-preview1-27644 2.0.0 2.1.0-preview1-25907-02 2.6.0-beta2-62211-02 - 2.1.0-preview1-27475 + 2.1.0-preview1-27644 15.3.0 4.7.49 10.0.1 diff --git a/build/repo.props b/build/repo.props index 30432c83ee..787d9e7eb8 100644 --- a/build/repo.props +++ b/build/repo.props @@ -1,8 +1,8 @@ - + true Internal.AspNetCore.Universe.Lineup - https://dotnet.myget.org/F/aspnetcore-ci-dev/api/v3/index.json + https://dotnet.myget.org/F/aspnetcore-dev/api/v3/index.json diff --git a/build/sources.props b/build/sources.props index e6a1c2b358..181b021f88 100644 --- a/build/sources.props +++ b/build/sources.props @@ -5,7 +5,7 @@ $(DotNetRestoreSources) $(RestoreSources); - https://dotnet.myget.org/F/aspnetcore-ci-dev/api/v3/index.json; + https://dotnet.myget.org/F/aspnetcore-dev/api/v3/index.json; https://dotnet.myget.org/F/aspnetcore-tools/api/v3/index.json; https://dotnet.myget.org/F/roslyn/api/v3/index.json; diff --git a/korebuild-lock.txt b/korebuild-lock.txt index b2036f3394..1a99066b7c 100644 --- a/korebuild-lock.txt +++ b/korebuild-lock.txt @@ -1,2 +1,2 @@ -version:2.1.0-preview1-15569 -commithash:47312a6364ad0ee6d7052eada54da940c9b17931 +version:2.1.0-preview1-15576 +commithash:2f3856d2ba4f659fcb9253215b83946a06794a27 From 8e1da5d1f627935b235c9dd064311a479250120b Mon Sep 17 00:00:00 2001 From: Chris Ross Date: Wed, 22 Nov 2017 10:19:17 -0800 Subject: [PATCH 1463/1662] Expose WebHostBuilderContext in UseKestrel #1334 (#2177) --- samples/Http2SampleApp/Program.cs | 13 +++------- samples/SampleApp/Startup.cs | 13 +++------- .../WebHostBuilderKestrelExtensions.cs | 26 +++++++++++++++++++ test/SystemdActivation/docker-entrypoint.sh | 4 +-- 4 files changed, 34 insertions(+), 22 deletions(-) diff --git a/samples/Http2SampleApp/Program.cs b/samples/Http2SampleApp/Program.cs index 249c41347c..5ee9cbda2b 100644 --- a/samples/Http2SampleApp/Program.cs +++ b/samples/Http2SampleApp/Program.cs @@ -13,15 +13,6 @@ namespace Http2SampleApp { public static void Main(string[] args) { - var configuration = new ConfigurationBuilder() - .AddEnvironmentVariables() - .Build(); - - if (!ushort.TryParse(configuration["BASE_PORT"], NumberStyles.None, CultureInfo.InvariantCulture, out var basePort)) - { - basePort = 5000; - } - var hostBuilder = new WebHostBuilder() .ConfigureLogging((_, factory) => { @@ -29,8 +20,10 @@ namespace Http2SampleApp factory.SetMinimumLevel(LogLevel.Trace); factory.AddConsole(); }) - .UseKestrel(options => + .UseKestrel((context, options) => { + var basePort = context.Configuration.GetValue("BASE_PORT") ?? 5000; + // Run callbacks on the transport thread options.ApplicationSchedulingMode = SchedulingMode.Inline; diff --git a/samples/SampleApp/Startup.cs b/samples/SampleApp/Startup.cs index bf8ce0e1a3..e0e471b635 100644 --- a/samples/SampleApp/Startup.cs +++ b/samples/SampleApp/Startup.cs @@ -43,22 +43,15 @@ namespace SampleApp Console.WriteLine("Unobserved exception: {0}", e.Exception); }; - var configuration = new ConfigurationBuilder() - .AddEnvironmentVariables() - .Build(); - - if (!ushort.TryParse(configuration["BASE_PORT"], NumberStyles.None, CultureInfo.InvariantCulture, out var basePort)) - { - basePort = 5000; - } - var hostBuilder = new WebHostBuilder() .ConfigureLogging((_, factory) => { factory.AddConsole(); }) - .UseKestrel(options => + .UseKestrel((context, options) => { + var basePort = context.Configuration.GetValue("BASE_PORT") ?? 5000; + // Run callbacks on the transport thread options.ApplicationSchedulingMode = SchedulingMode.Inline; diff --git a/src/Kestrel/WebHostBuilderKestrelExtensions.cs b/src/Kestrel/WebHostBuilderKestrelExtensions.cs index f65a66ac4e..fdc149e2fe 100644 --- a/src/Kestrel/WebHostBuilderKestrelExtensions.cs +++ b/src/Kestrel/WebHostBuilderKestrelExtensions.cs @@ -57,5 +57,31 @@ namespace Microsoft.AspNetCore.Hosting services.Configure(options); }); } + + /// + /// Specify Kestrel as the server to be used by the web host. + /// + /// + /// The Microsoft.AspNetCore.Hosting.IWebHostBuilder to configure. + /// + /// A callback to configure Kestrel options. + /// + /// The Microsoft.AspNetCore.Hosting.IWebHostBuilder. + /// + public static IWebHostBuilder UseKestrel(this IWebHostBuilder hostBuilder, Action configureOptions) + { + if (configureOptions == null) + { + throw new ArgumentNullException(nameof(configureOptions)); + } + + return hostBuilder.UseKestrel().ConfigureServices((context, services) => + { + services.Configure(options => + { + configureOptions(context, options); + }); + }); + } } } diff --git a/test/SystemdActivation/docker-entrypoint.sh b/test/SystemdActivation/docker-entrypoint.sh index c85c5fe0bd..2b501ef6ae 100644 --- a/test/SystemdActivation/docker-entrypoint.sh +++ b/test/SystemdActivation/docker-entrypoint.sh @@ -3,10 +3,10 @@ set -e cd /publish -systemd-socket-activate -l 8080 -E BASE_PORT=7000 dotnet SampleApp.dll & +systemd-socket-activate -l 8080 -E ASPNETCORE_BASE_PORT=7000 dotnet SampleApp.dll & socat TCP-LISTEN:8081,fork TCP-CONNECT:127.0.0.1:7000 & socat TCP-LISTEN:8082,fork TCP-CONNECT:127.0.0.1:7001 & -systemd-socket-activate -l /tmp/activate-kestrel.sock -E BASE_PORT=7100 dotnet SampleApp.dll & +systemd-socket-activate -l /tmp/activate-kestrel.sock -E ASPNETCORE_BASE_PORT=7100 dotnet SampleApp.dll & socat TCP-LISTEN:8083,fork UNIX-CLIENT:/tmp/activate-kestrel.sock & socat TCP-LISTEN:8084,fork TCP-CONNECT:127.0.0.1:7100 & socat TCP-LISTEN:8085,fork TCP-CONNECT:127.0.0.1:7101 & From 76de77746dd900058f7bd49f66debdd245cf9260 Mon Sep 17 00:00:00 2001 From: Pranav K Date: Wed, 22 Nov 2017 19:02:22 -0800 Subject: [PATCH 1464/1662] Eclipse CoreFx package versions to prevent package downgrade warnings --- test/Kestrel.Core.Tests/Kestrel.Core.Tests.csproj | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/Kestrel.Core.Tests/Kestrel.Core.Tests.csproj b/test/Kestrel.Core.Tests/Kestrel.Core.Tests.csproj index 15bac171bb..ede5868b74 100644 --- a/test/Kestrel.Core.Tests/Kestrel.Core.Tests.csproj +++ b/test/Kestrel.Core.Tests/Kestrel.Core.Tests.csproj @@ -21,6 +21,8 @@ + + From ce684270500a12ea25e8f86164fbe082e4eeda13 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Mon, 27 Nov 2017 09:11:39 -0800 Subject: [PATCH 1465/1662] Use ALPN support in SSLStream on .NET Core >= 2.1 (#2179) - Always add the TlsConnectionFeature when the HttpsConnectionAdapter runs - Implemented the ITlsApplicationProtocolsFeature on the existing TlsConnectionFeature - Removed Kestrel.Tls --- KestrelHttpServer.sln | 17 +- samples/Http2SampleApp/Http2SampleApp.csproj | 4 +- samples/Http2SampleApp/Program.cs | 2 +- .../HttpsConnectionAdapterOptions.cs | 7 + .../Internal/HttpsConnectionAdapter.cs | 50 ++- .../Internal/TlsConnectionFeature.cs | 5 +- src/Kestrel.Https/Kestrel.Https.csproj | 2 +- .../ListenOptionsHttpsExtensions.cs | 2 + src/Kestrel.Tls/ClosedStream.cs | 68 ---- src/Kestrel.Tls/Kestrel.Tls.csproj | 23 -- src/Kestrel.Tls/ListenOptionsTlsExtensions.cs | 30 -- src/Kestrel.Tls/OpenSsl.cs | 375 ------------------ src/Kestrel.Tls/Properties/AssemblyInfo.cs | 6 - src/Kestrel.Tls/README.md | 5 - .../TlsApplicationProtocolFeature.cs | 17 - src/Kestrel.Tls/TlsConnectionAdapter.cs | 120 ------ .../TlsConnectionAdapterOptions.cs | 16 - src/Kestrel.Tls/TlsConnectionFeature.cs | 21 - src/Kestrel.Tls/TlsStream.cs | 243 ------------ 19 files changed, 64 insertions(+), 949 deletions(-) delete mode 100644 src/Kestrel.Tls/ClosedStream.cs delete mode 100644 src/Kestrel.Tls/Kestrel.Tls.csproj delete mode 100644 src/Kestrel.Tls/ListenOptionsTlsExtensions.cs delete mode 100644 src/Kestrel.Tls/OpenSsl.cs delete mode 100644 src/Kestrel.Tls/Properties/AssemblyInfo.cs delete mode 100644 src/Kestrel.Tls/README.md delete mode 100644 src/Kestrel.Tls/TlsApplicationProtocolFeature.cs delete mode 100644 src/Kestrel.Tls/TlsConnectionAdapter.cs delete mode 100644 src/Kestrel.Tls/TlsConnectionAdapterOptions.cs delete mode 100644 src/Kestrel.Tls/TlsConnectionFeature.cs delete mode 100644 src/Kestrel.Tls/TlsStream.cs diff --git a/KestrelHttpServer.sln b/KestrelHttpServer.sln index 6cdeaa1464..7718ccf9e7 100644 --- a/KestrelHttpServer.sln +++ b/KestrelHttpServer.sln @@ -1,6 +1,6 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 15 -VisualStudioVersion = 15.0.27101.0 +VisualStudioVersion = 15.0.27110.0 MinimumVisualStudioVersion = 15.0.26730.03 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{7972A5D6-3385-4127-9277-428506DD44FF}" ProjectSection(SolutionItems) = preProject @@ -102,8 +102,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "benchmarks", "benchmarks", EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Protocols.Abstractions", "src\Protocols.Abstractions\Protocols.Abstractions.csproj", "{6956CF5C-3163-4398-8628-4ECA569245B5}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Kestrel.Tls", "src\Kestrel.Tls\Kestrel.Tls.csproj", "{924AE57C-1EBA-4A1D-A039-8C100B7507A5}" -EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "build", "build", "{C2910A13-B2C2-46D8-81D8-7E166F4F5981}" ProjectSection(SolutionItems) = preProject build\repo.props = build\repo.props @@ -301,18 +299,6 @@ Global {6956CF5C-3163-4398-8628-4ECA569245B5}.Release|x64.Build.0 = Release|Any CPU {6956CF5C-3163-4398-8628-4ECA569245B5}.Release|x86.ActiveCfg = Release|Any CPU {6956CF5C-3163-4398-8628-4ECA569245B5}.Release|x86.Build.0 = Release|Any CPU - {924AE57C-1EBA-4A1D-A039-8C100B7507A5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {924AE57C-1EBA-4A1D-A039-8C100B7507A5}.Debug|Any CPU.Build.0 = Debug|Any CPU - {924AE57C-1EBA-4A1D-A039-8C100B7507A5}.Debug|x64.ActiveCfg = Debug|Any CPU - {924AE57C-1EBA-4A1D-A039-8C100B7507A5}.Debug|x64.Build.0 = Debug|Any CPU - {924AE57C-1EBA-4A1D-A039-8C100B7507A5}.Debug|x86.ActiveCfg = Debug|Any CPU - {924AE57C-1EBA-4A1D-A039-8C100B7507A5}.Debug|x86.Build.0 = Debug|Any CPU - {924AE57C-1EBA-4A1D-A039-8C100B7507A5}.Release|Any CPU.ActiveCfg = Release|Any CPU - {924AE57C-1EBA-4A1D-A039-8C100B7507A5}.Release|Any CPU.Build.0 = Release|Any CPU - {924AE57C-1EBA-4A1D-A039-8C100B7507A5}.Release|x64.ActiveCfg = Release|Any CPU - {924AE57C-1EBA-4A1D-A039-8C100B7507A5}.Release|x64.Build.0 = Release|Any CPU - {924AE57C-1EBA-4A1D-A039-8C100B7507A5}.Release|x86.ActiveCfg = Release|Any CPU - {924AE57C-1EBA-4A1D-A039-8C100B7507A5}.Release|x86.Build.0 = Release|Any CPU {74032D79-8EA7-4483-BD82-C38370420FFF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {74032D79-8EA7-4483-BD82-C38370420FFF}.Debug|Any CPU.Build.0 = Debug|Any CPU {74032D79-8EA7-4483-BD82-C38370420FFF}.Debug|x64.ActiveCfg = Debug|Any CPU @@ -369,7 +355,6 @@ Global {D95A7EC3-48AC-4D03-B2E2-0DA3E13BD3A4} = {D3273454-EA07-41D2-BF0B-FCC3675C2483} {4F1C30F8-CCAA-48D7-9DF6-2A84021F5BCC} = {D3273454-EA07-41D2-BF0B-FCC3675C2483} {6956CF5C-3163-4398-8628-4ECA569245B5} = {2D5D5227-4DBD-499A-96B1-76A36B03B750} - {924AE57C-1EBA-4A1D-A039-8C100B7507A5} = {2D5D5227-4DBD-499A-96B1-76A36B03B750} {B7B0EA74-528F-46B8-9BC4-909D9A67C194} = {D3273454-EA07-41D2-BF0B-FCC3675C2483} {74032D79-8EA7-4483-BD82-C38370420FFF} = {D3273454-EA07-41D2-BF0B-FCC3675C2483} {9C7B6B5F-088A-436E-834B-6373EA36DEEE} = {D3273454-EA07-41D2-BF0B-FCC3675C2483} diff --git a/samples/Http2SampleApp/Http2SampleApp.csproj b/samples/Http2SampleApp/Http2SampleApp.csproj index 0fd184ca8d..683e6e4041 100644 --- a/samples/Http2SampleApp/Http2SampleApp.csproj +++ b/samples/Http2SampleApp/Http2SampleApp.csproj @@ -1,13 +1,13 @@ - netcoreapp2.0 + netcoreapp2.1 false + true - diff --git a/samples/Http2SampleApp/Program.cs b/samples/Http2SampleApp/Program.cs index 5ee9cbda2b..bdb49b0a50 100644 --- a/samples/Http2SampleApp/Program.cs +++ b/samples/Http2SampleApp/Program.cs @@ -30,7 +30,7 @@ namespace Http2SampleApp options.Listen(IPAddress.Any, basePort, listenOptions => { listenOptions.Protocols = HttpProtocols.Http1AndHttp2; - listenOptions.UseTls("testCert.pfx", "testPassword"); + listenOptions.UseHttps("testCert.pfx", "testPassword"); listenOptions.UseConnectionLogging(); }); }) diff --git a/src/Kestrel.Https/HttpsConnectionAdapterOptions.cs b/src/Kestrel.Https/HttpsConnectionAdapterOptions.cs index 39b9f9615a..14238658d0 100644 --- a/src/Kestrel.Https/HttpsConnectionAdapterOptions.cs +++ b/src/Kestrel.Https/HttpsConnectionAdapterOptions.cs @@ -6,6 +6,7 @@ using System.Net.Security; using System.Security.Authentication; using System.Security.Cryptography.X509Certificates; using System.Threading; +using Microsoft.AspNetCore.Server.Kestrel.Core; namespace Microsoft.AspNetCore.Server.Kestrel.Https { @@ -51,6 +52,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Https /// public SslProtocols SslProtocols { get; set; } + /// + /// The protocols enabled on this endpoint. + /// + /// Defaults to HTTP/1.x only. + internal HttpProtocols HttpProtocols { get; set; } + /// /// Specifies whether the certificate revocation list is checked during authentication. /// diff --git a/src/Kestrel.Https/Internal/HttpsConnectionAdapter.cs b/src/Kestrel.Https/Internal/HttpsConnectionAdapter.cs index 290bb3beee..853f81966a 100644 --- a/src/Kestrel.Https/Internal/HttpsConnectionAdapter.cs +++ b/src/Kestrel.Https/Internal/HttpsConnectionAdapter.cs @@ -2,12 +2,15 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Collections.Generic; using System.IO; using System.Linq; using System.Net.Security; using System.Security.Cryptography.X509Certificates; +using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Http.Features; +using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal; using Microsoft.AspNetCore.Server.Kestrel.Core.Features; using Microsoft.Extensions.Logging; @@ -64,6 +67,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Https.Internal { SslStream sslStream; bool certificateRequired; + var feature = new TlsConnectionFeature(); + context.Features.Set(feature); if (_options.ClientCertificateMode == ClientCertificateMode.NoCertificate) { @@ -114,8 +119,32 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Https.Internal try { +#if NETCOREAPP2_1 + var sslOptions = new SslServerAuthenticationOptions() + { + ServerCertificate = _serverCertificate, + ClientCertificateRequired = certificateRequired, + EnabledSslProtocols = _options.SslProtocols, + CertificateRevocationCheckMode = _options.CheckCertificateRevocation ? X509RevocationMode.Online : X509RevocationMode.NoCheck, + ApplicationProtocols = new List() + }; + + // This is order sensitive + if ((_options.HttpProtocols & HttpProtocols.Http2) != 0) + { + sslOptions.ApplicationProtocols.Add(SslApplicationProtocol.Http2); + } + + if ((_options.HttpProtocols & HttpProtocols.Http1) != 0) + { + sslOptions.ApplicationProtocols.Add(SslApplicationProtocol.Http11); + } + + await sslStream.AuthenticateAsServerAsync(sslOptions, CancellationToken.None); +#else await sslStream.AuthenticateAsServerAsync(_serverCertificate, certificateRequired, _options.SslProtocols, _options.CheckCertificateRevocation); +#endif } catch (OperationCanceledException) { @@ -134,11 +163,24 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Https.Internal timeoutFeature.CancelTimeout(); } - // Always set the feature even though the cert might be null - context.Features.Set(new TlsConnectionFeature +#if NETCOREAPP2_1 + // Don't allocate in the common case, see https://github.com/dotnet/corefx/issues/25432 + if (sslStream.NegotiatedApplicationProtocol == SslApplicationProtocol.Http11) { - ClientCertificate = ConvertToX509Certificate2(sslStream.RemoteCertificate) - }); + feature.ApplicationProtocol = "http/1.1"; + } + else if (sslStream.NegotiatedApplicationProtocol == SslApplicationProtocol.Http2) + { + feature.ApplicationProtocol = "h2"; + } + else + { + feature.ApplicationProtocol = sslStream.NegotiatedApplicationProtocol.ToString(); + } + + context.Features.Set(feature); +#endif + feature.ClientCertificate = ConvertToX509Certificate2(sslStream.RemoteCertificate); return new HttpsAdaptedConnection(sslStream); } diff --git a/src/Kestrel.Https/Internal/TlsConnectionFeature.cs b/src/Kestrel.Https/Internal/TlsConnectionFeature.cs index 2fb85037b5..d5d7983d8e 100644 --- a/src/Kestrel.Https/Internal/TlsConnectionFeature.cs +++ b/src/Kestrel.Https/Internal/TlsConnectionFeature.cs @@ -6,13 +6,16 @@ using System.Security.Cryptography.X509Certificates; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Http.Features; +using Microsoft.AspNetCore.Server.Kestrel.Core.Features; namespace Microsoft.AspNetCore.Server.Kestrel.Https.Internal { - internal class TlsConnectionFeature : ITlsConnectionFeature + internal class TlsConnectionFeature : ITlsConnectionFeature, ITlsApplicationProtocolFeature { public X509Certificate2 ClientCertificate { get; set; } + public string ApplicationProtocol { get; set; } + public Task GetClientCertificateAsync(CancellationToken cancellationToken) { return Task.FromResult(ClientCertificate); diff --git a/src/Kestrel.Https/Kestrel.Https.csproj b/src/Kestrel.Https/Kestrel.Https.csproj index de626b50b9..d9620b513e 100644 --- a/src/Kestrel.Https/Kestrel.Https.csproj +++ b/src/Kestrel.Https/Kestrel.Https.csproj @@ -4,7 +4,7 @@ Microsoft.AspNetCore.Server.Kestrel.Https Microsoft.AspNetCore.Server.Kestrel.Https HTTPS support for the ASP.NET Core Kestrel cross-platform web server. - netstandard2.0 + netstandard2.0;netcoreapp2.1 true aspnetcore;kestrel CS1591;$(NoWarn) diff --git a/src/Kestrel.Https/ListenOptionsHttpsExtensions.cs b/src/Kestrel.Https/ListenOptionsHttpsExtensions.cs index 44463ea10e..68f2e71ef1 100644 --- a/src/Kestrel.Https/ListenOptionsHttpsExtensions.cs +++ b/src/Kestrel.Https/ListenOptionsHttpsExtensions.cs @@ -87,6 +87,8 @@ namespace Microsoft.AspNetCore.Hosting public static ListenOptions UseHttps(this ListenOptions listenOptions, HttpsConnectionAdapterOptions httpsOptions) { var loggerFactory = listenOptions.KestrelServerOptions.ApplicationServices.GetRequiredService(); + // Set the list of protocols from listen options + httpsOptions.HttpProtocols = listenOptions.Protocols; listenOptions.ConnectionAdapters.Add(new HttpsConnectionAdapter(httpsOptions, loggerFactory)); return listenOptions; } diff --git a/src/Kestrel.Tls/ClosedStream.cs b/src/Kestrel.Tls/ClosedStream.cs deleted file mode 100644 index 511869b29f..0000000000 --- a/src/Kestrel.Tls/ClosedStream.cs +++ /dev/null @@ -1,68 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using System.IO; -using System.Threading; -using System.Threading.Tasks; - -namespace Microsoft.AspNetCore.Server.Kestrel.Tls -{ - internal class ClosedStream : Stream - { - private static readonly Task ZeroResultTask = Task.FromResult(result: 0); - - public override bool CanRead => true; - public override bool CanSeek => false; - public override bool CanWrite => false; - - public override long Length - { - get - { - throw new NotSupportedException(); - } - } - - public override long Position - { - get - { - throw new NotSupportedException(); - } - set - { - throw new NotSupportedException(); - } - } - - public override void Flush() - { - } - - public override long Seek(long offset, SeekOrigin origin) - { - throw new NotSupportedException(); - } - - public override void SetLength(long value) - { - throw new NotSupportedException(); - } - - public override int Read(byte[] buffer, int offset, int count) - { - return 0; - } - - public override Task ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) - { - return ZeroResultTask; - } - - public override void Write(byte[] buffer, int offset, int count) - { - throw new NotSupportedException(); - } - } -} diff --git a/src/Kestrel.Tls/Kestrel.Tls.csproj b/src/Kestrel.Tls/Kestrel.Tls.csproj deleted file mode 100644 index 3088fbcc46..0000000000 --- a/src/Kestrel.Tls/Kestrel.Tls.csproj +++ /dev/null @@ -1,23 +0,0 @@ - - - - Microsoft.AspNetCore.Server.Kestrel.Tls - Microsoft.AspNetCore.Server.Kestrel.Tls - netstandard2.0 - true - aspnetcore;kestrel - CS1591;$(NoWarn) - false - true - false - - - - - - - - - - - diff --git a/src/Kestrel.Tls/ListenOptionsTlsExtensions.cs b/src/Kestrel.Tls/ListenOptionsTlsExtensions.cs deleted file mode 100644 index 695297eb56..0000000000 --- a/src/Kestrel.Tls/ListenOptionsTlsExtensions.cs +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using Microsoft.AspNetCore.Server.Kestrel.Core; -using Microsoft.AspNetCore.Server.Kestrel.Tls; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Logging; - -namespace Microsoft.AspNetCore.Hosting -{ - public static class ListenOptionsTlsExtensions - { - public static ListenOptions UseTls(this ListenOptions listenOptions, string certificatePath, string password) - { - return listenOptions.UseTls(new TlsConnectionAdapterOptions - { - CertificatePath = certificatePath, - Password = password, - Protocols = listenOptions.Protocols - }); - } - - public static ListenOptions UseTls(this ListenOptions listenOptions, TlsConnectionAdapterOptions tlsOptions) - { - var loggerFactory = listenOptions.KestrelServerOptions.ApplicationServices.GetRequiredService(); - listenOptions.ConnectionAdapters.Add(new TlsConnectionAdapter(tlsOptions, loggerFactory)); - return listenOptions; - } - } -} diff --git a/src/Kestrel.Tls/OpenSsl.cs b/src/Kestrel.Tls/OpenSsl.cs deleted file mode 100644 index 52af7a8857..0000000000 --- a/src/Kestrel.Tls/OpenSsl.cs +++ /dev/null @@ -1,375 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Linq; -using System.Runtime.InteropServices; -using System.Text; - -namespace Microsoft.AspNetCore.Server.Kestrel.Tls -{ - public static class OpenSsl - { - public const int OPENSSL_NPN_NEGOTIATED = 1; - public const int SSL_TLSEXT_ERR_OK = 0; - public const int SSL_TLSEXT_ERR_NOACK = 3; - public const int SSL_CTRL_CHAIN = 88; - - private const int BIO_C_SET_BUF_MEM_EOF_RETURN = 130; - private const int SSL_CTRL_SET_ECDH_AUTO = 94; - - public static void SSL_library_init() - { - try - { - // Try OpenSSL 1.0.2 - NativeMethods.SSL_library_init(); - } - catch (EntryPointNotFoundException) - { - // It's fine, OpenSSL 1.1 doesn't need initialization - } - } - - public static void SSL_load_error_strings() - { - try - { - NativeMethods.SSL_load_error_strings(); - } - catch (EntryPointNotFoundException) - { - // Also fine, OpenSSL 1.1 doesn't need it. - } - } - - public static void OpenSSL_add_all_algorithms() - { - try - { - NativeMethods.OPENSSL_add_all_algorithms_noconf(); - } - catch (EntryPointNotFoundException) - { - // Also fine, OpenSSL 1.1 doesn't need it. - } - } - - public static IntPtr TLSv1_2_method() - { - return NativeMethods.TLSv1_2_method(); - } - - public static IntPtr SSL_CTX_new(IntPtr method) - { - return NativeMethods.SSL_CTX_new(method); - } - - public static void SSL_CTX_free(IntPtr ctx) - { - NativeMethods.SSL_CTX_free(ctx); - } - - public unsafe static int SSL_CTX_Set_Pfx(IntPtr ctx, string path, string password) - { - var pass = Marshal.StringToHGlobalAnsi(password); - var key = IntPtr.Zero; - var cert = IntPtr.Zero; - var ca = IntPtr.Zero; - - try - { - var file = System.IO.File.ReadAllBytes(path); - - fixed (void* f = file) - { - var buffer = (IntPtr)f; - var pkcs = NativeMethods.d2i_PKCS12(IntPtr.Zero, ref buffer, file.Length); - var result = NativeMethods.PKCS12_parse(pkcs, pass, ref key, ref cert, ref ca); - if (result != 1) - { - return -1; - } - if (NativeMethods.SSL_CTX_use_certificate(ctx, cert) != 1) return -1; - if (NativeMethods.SSL_CTX_use_PrivateKey(ctx, key) != 1) return -1; - if (NativeMethods.SSL_CTX_ctrl(ctx, SSL_CTRL_CHAIN, 1, ca) != 1) return -1; - return 1; - } - } - finally - { - Marshal.FreeHGlobal(pass); - if (key != IntPtr.Zero) NativeMethods.EVP_PKEY_free(key); - if (cert != IntPtr.Zero) NativeMethods.X509_free(cert); - if (ca != IntPtr.Zero) NativeMethods.sk_X509_pop_free(ca); - } - } - - public static int SSL_CTX_set_ecdh_auto(IntPtr ctx, int onoff) - { - return (int)NativeMethods.SSL_CTX_ctrl(ctx, SSL_CTRL_SET_ECDH_AUTO, onoff, IntPtr.Zero); - } - - public static int SSL_CTX_use_certificate_file(IntPtr ctx, string file, int type) - { - var ptr = Marshal.StringToHGlobalAnsi(file); - var error = NativeMethods.SSL_CTX_use_certificate_file(ctx, ptr, type); - Marshal.FreeHGlobal(ptr); - - return error; - } - - public static int SSL_CTX_use_PrivateKey_file(IntPtr ctx, string file, int type) - { - var ptr = Marshal.StringToHGlobalAnsi(file); - var error = NativeMethods.SSL_CTX_use_PrivateKey_file(ctx, ptr, type); - Marshal.FreeHGlobal(ptr); - - return error; - } - - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - public unsafe delegate int alpn_select_cb_t(IntPtr ssl, out byte* @out, out byte outlen, byte* @in, uint inlen, IntPtr arg); - - public unsafe static void SSL_CTX_set_alpn_select_cb(IntPtr ctx, alpn_select_cb_t cb, IntPtr arg) - { - NativeMethods.SSL_CTX_set_alpn_select_cb(ctx, cb, arg); - } - - public static unsafe int SSL_select_next_proto(out byte* @out, out byte outlen, byte* server, uint server_len, byte* client, uint client_len) - { - return NativeMethods.SSL_select_next_proto(out @out, out outlen, server, server_len, client, client_len); - } - - public static unsafe void SSL_get0_alpn_selected(IntPtr ssl, out string protocol) - { - NativeMethods.SSL_get0_alpn_selected(ssl, out var data, out var length); - - protocol = data != null - ? Marshal.PtrToStringAnsi((IntPtr)data, length) - : null; - } - - public static IntPtr SSL_new(IntPtr ctx) - { - return NativeMethods.SSL_new(ctx); - } - - public static void SSL_free(IntPtr ssl) - { - NativeMethods.SSL_free(ssl); - } - - public static int SSL_get_error(IntPtr ssl, int ret) - { - return NativeMethods.SSL_get_error(ssl, ret); - } - - public static int ERR_get_error() - { - return NativeMethods.ERR_get_error(); - } - - public static string ERR_error_string(int error) - { - var buf = NativeMethods.ERR_error_string(error, IntPtr.Zero); - - // Don't free the buffer! It's a static buffer - return Marshal.PtrToStringAnsi(buf); - } - - public static void SSL_set_accept_state(IntPtr ssl) - { - NativeMethods.SSL_set_accept_state(ssl); - } - - public static int SSL_do_handshake(IntPtr ssl) - { - return NativeMethods.SSL_do_handshake(ssl); - } - - public static unsafe int SSL_read(IntPtr ssl, byte[] buffer, int offset, int count) - { - fixed (byte* ptr = buffer) - { - return NativeMethods.SSL_read(ssl, (IntPtr)(ptr + offset), count); - } - } - - public static unsafe int SSL_write(IntPtr ssl, byte[] buffer, int offset, int count) - { - fixed (byte* ptr = buffer) - { - return NativeMethods.SSL_write(ssl, (IntPtr)(ptr + offset), count); - } - } - - public static void SSL_set_bio(IntPtr ssl, IntPtr rbio, IntPtr wbio) - { - NativeMethods.SSL_set_bio(ssl, rbio, wbio); - } - - public static IntPtr BIO_new(IntPtr type) - { - return NativeMethods.BIO_new(type); - } - - public static unsafe int BIO_read(IntPtr b, byte[] buffer, int offset, int count) - { - fixed (byte* ptr = buffer) - { - return NativeMethods.BIO_read(b, (IntPtr)(ptr + offset), count); - } - } - - public static unsafe int BIO_write(IntPtr b, byte[] buffer, int offset, int count) - { - fixed (byte* ptr = buffer) - { - return NativeMethods.BIO_write(b, (IntPtr)(ptr + offset), count); - } - } - - public static long BIO_ctrl_pending(IntPtr b) - { - return NativeMethods.BIO_ctrl_pending(b); - } - - public static long BIO_set_mem_eof_return(IntPtr b, int v) - { - return NativeMethods.BIO_ctrl(b, BIO_C_SET_BUF_MEM_EOF_RETURN, v, IntPtr.Zero); - } - - public static IntPtr BIO_s_mem() - { - return NativeMethods.BIO_s_mem(); - } - - public static void ERR_load_BIO_strings() - { - NativeMethods.ERR_load_BIO_strings(); - } - - private class NativeMethods - { - [DllImport("libssl", CallingConvention = CallingConvention.Cdecl)] - public static extern int SSL_library_init(); - - [DllImport("libssl", CallingConvention = CallingConvention.Cdecl)] - public static extern void SSL_load_error_strings(); - - [DllImport("libssl", CallingConvention = CallingConvention.Cdecl)] - public static extern void OPENSSL_add_all_algorithms_noconf(); - - [DllImport("libssl", CallingConvention = CallingConvention.Cdecl)] - public static extern IntPtr TLSv1_2_method(); - - [DllImport("libssl", CallingConvention = CallingConvention.Cdecl)] - public static extern IntPtr SSL_CTX_new(IntPtr method); - - [DllImport("libssl", CallingConvention = CallingConvention.Cdecl)] - public static extern IntPtr SSL_CTX_free(IntPtr ctx); - - [DllImport("libssl", CallingConvention = CallingConvention.Cdecl)] - public static extern long SSL_CTX_ctrl(IntPtr ctx, int cmd, long larg, IntPtr parg); - - [DllImport("libssl", CallingConvention = CallingConvention.Cdecl)] - public static extern int SSL_CTX_use_certificate_file(IntPtr ctx, IntPtr file, int type); - - [DllImport("libssl", CallingConvention = CallingConvention.Cdecl)] - public static extern int SSL_CTX_use_PrivateKey_file(IntPtr ctx, IntPtr file, int type); - - [DllImport("libssl", CallingConvention = CallingConvention.Cdecl)] - public static extern void SSL_CTX_set_alpn_select_cb(IntPtr ctx, alpn_select_cb_t cb, IntPtr arg); - - [DllImport("libssl", CallingConvention = CallingConvention.Cdecl)] - public static extern unsafe int SSL_select_next_proto(out byte* @out, out byte outlen, byte* server, uint server_len, byte* client, uint client_len); - - [DllImport("libssl", CallingConvention = CallingConvention.Cdecl)] - public static extern unsafe void SSL_get0_alpn_selected(IntPtr ssl, out byte* data, out int len); - - [DllImport("libssl", CallingConvention = CallingConvention.Cdecl)] - public static extern IntPtr SSL_new(IntPtr ctx); - - [DllImport("libssl", CallingConvention = CallingConvention.Cdecl)] - public static extern IntPtr SSL_free(IntPtr ssl); - - [DllImport("libssl", CallingConvention = CallingConvention.Cdecl)] - public static extern int SSL_get_error(IntPtr ssl, int ret); - - [DllImport("libssl", CallingConvention = CallingConvention.Cdecl)] - public static extern void SSL_set_accept_state(IntPtr ssl); - - [DllImport("libssl", CallingConvention = CallingConvention.Cdecl)] - public static extern int SSL_do_handshake(IntPtr ssl); - - [DllImport("libssl", CallingConvention = CallingConvention.Cdecl)] - public static extern int SSL_read(IntPtr ssl, IntPtr buf, int len); - - [DllImport("libssl", CallingConvention = CallingConvention.Cdecl)] - public static extern int SSL_write(IntPtr ssl, IntPtr buf, int len); - - [DllImport("libssl", CallingConvention = CallingConvention.Cdecl)] - public static extern void SSL_set_bio(IntPtr ssl, IntPtr rbio, IntPtr wbio); - - [DllImport("libssl", CallingConvention = CallingConvention.Cdecl)] - public static extern IntPtr BIO_new(IntPtr type); - - [DllImport("libssl", CallingConvention = CallingConvention.Cdecl)] - public static extern int BIO_read(IntPtr b, IntPtr buf, int len); - - [DllImport("libssl", CallingConvention = CallingConvention.Cdecl)] - public static extern int BIO_write(IntPtr b, IntPtr buf, int len); - - [DllImport("libssl", CallingConvention = CallingConvention.Cdecl)] - public static extern long BIO_ctrl(IntPtr bp, int cmd, long larg, IntPtr parg); - - [DllImport("libssl", CallingConvention = CallingConvention.Cdecl)] - public static extern long BIO_ctrl_pending(IntPtr bp); - - [DllImport("libssl", CallingConvention = CallingConvention.Cdecl)] - public static extern IntPtr BIO_s_mem(); - - [DllImport("libssl", CallingConvention = CallingConvention.Cdecl)] - public static extern void ERR_load_BIO_strings(); - - [DllImport("libssl", CallingConvention = CallingConvention.Cdecl)] - public static extern int ERR_get_error(); - - [DllImport("libssl", CallingConvention = CallingConvention.Cdecl)] - public static extern IntPtr ERR_error_string(int error, IntPtr buf); - - [DllImport("libssl", CallingConvention = CallingConvention.Cdecl)] - public static extern IntPtr d2i_PKCS12(IntPtr unsused, ref IntPtr bufferPointer, long length); - - [DllImport("libssl", CallingConvention = CallingConvention.Cdecl)] - public static extern int PKCS12_parse(IntPtr p12, IntPtr pass, ref IntPtr pkey, ref IntPtr cert, ref IntPtr ca); - - [DllImport("libssl", CallingConvention = CallingConvention.Cdecl)] - public static extern void PKCS12_free(IntPtr p12); - - [DllImport("libssl", CallingConvention = CallingConvention.Cdecl)] - public static extern void EVP_PKEY_free(IntPtr pkey); - - [DllImport("libssl", CallingConvention = CallingConvention.Cdecl)] - public static extern void X509_free(IntPtr a); - - [DllImport("libssl", CallingConvention = CallingConvention.Cdecl)] - public static extern void sk_X509_pop_free(IntPtr ca); - - [DllImport("libssl", CallingConvention = CallingConvention.Cdecl)] - public static extern int SSL_CTX_ctrl(IntPtr ctx, int cmd, int larg, IntPtr parg); - - [DllImport("libssl", CallingConvention = CallingConvention.Cdecl)] - public static extern int SSL_CTX_set1_chain(IntPtr ctx, IntPtr sk); - - [DllImport("libssl", CallingConvention = CallingConvention.Cdecl)] - public static extern int SSL_CTX_use_certificate(IntPtr ctx, IntPtr x509); - - [DllImport("libssl", CallingConvention = CallingConvention.Cdecl)] - public static extern int SSL_CTX_use_PrivateKey(IntPtr ctx, IntPtr pkey); - } - } -} diff --git a/src/Kestrel.Tls/Properties/AssemblyInfo.cs b/src/Kestrel.Tls/Properties/AssemblyInfo.cs deleted file mode 100644 index 3bb5150c92..0000000000 --- a/src/Kestrel.Tls/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,6 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System.Runtime.CompilerServices; - -[assembly: InternalsVisibleTo("Microsoft.AspNetCore.Server.Kestrel.FunctionalTests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")] diff --git a/src/Kestrel.Tls/README.md b/src/Kestrel.Tls/README.md deleted file mode 100644 index 9012206247..0000000000 --- a/src/Kestrel.Tls/README.md +++ /dev/null @@ -1,5 +0,0 @@ -# NOT FOR PRODUCTION USE - -The code in this package contains the bare minimum to make Kestrel work with TLS 1.2 with ALPN support. It has not been audited nor hardened in any way. DO NOT USE THIS IN PRODUCTION. - -This package is temporary and will be removed once `SslStream` supports ALPN. diff --git a/src/Kestrel.Tls/TlsApplicationProtocolFeature.cs b/src/Kestrel.Tls/TlsApplicationProtocolFeature.cs deleted file mode 100644 index b3bcee74cc..0000000000 --- a/src/Kestrel.Tls/TlsApplicationProtocolFeature.cs +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using Microsoft.AspNetCore.Server.Kestrel.Core.Features; - -namespace Microsoft.AspNetCore.Server.Kestrel.Tls -{ - internal class TlsApplicationProtocolFeature : ITlsApplicationProtocolFeature - { - public TlsApplicationProtocolFeature(string applicationProtocol) - { - ApplicationProtocol = applicationProtocol; - } - - public string ApplicationProtocol { get; } - } -} diff --git a/src/Kestrel.Tls/TlsConnectionAdapter.cs b/src/Kestrel.Tls/TlsConnectionAdapter.cs deleted file mode 100644 index 8dee80eb68..0000000000 --- a/src/Kestrel.Tls/TlsConnectionAdapter.cs +++ /dev/null @@ -1,120 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using System.Collections.Generic; -using System.IO; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Http.Features; -using Microsoft.AspNetCore.Server.Kestrel.Core; -using Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal; -using Microsoft.AspNetCore.Server.Kestrel.Core.Features; -using Microsoft.Extensions.Logging; - -namespace Microsoft.AspNetCore.Server.Kestrel.Tls -{ - public class TlsConnectionAdapter : IConnectionAdapter - { - private static readonly ClosedAdaptedConnection _closedAdaptedConnection = new ClosedAdaptedConnection(); - private static readonly List _serverProtocols = new List(); - - private readonly TlsConnectionAdapterOptions _options; - private readonly ILogger _logger; - - private string _applicationProtocol; - - public TlsConnectionAdapter(TlsConnectionAdapterOptions options) - : this(options, loggerFactory: null) - { - } - - public TlsConnectionAdapter(TlsConnectionAdapterOptions options, ILoggerFactory loggerFactory) - { - if (options == null) - { - throw new ArgumentNullException(nameof(options)); - } - - if (options.CertificatePath == null) - { - throw new ArgumentException("Certificate path must be non-null.", nameof(options)); - } - - if (options.Password == null) - { - throw new ArgumentException("Password must be non-null.", nameof(options)); - } - - _options = options; - _logger = loggerFactory?.CreateLogger(nameof(TlsConnectionAdapter)); - - // Order is important. If HTTP/2 is enabled, we prefer it over HTTP/1.1. So add it first. - if ((options.Protocols & HttpProtocols.Http2) == HttpProtocols.Http2) - { - _serverProtocols.Add("h2"); - } - - if ((options.Protocols & HttpProtocols.Http1) == HttpProtocols.Http1) - { - _serverProtocols.Add("http/1.1"); - } - } - - public bool IsHttps => true; - - public Task OnConnectionAsync(ConnectionAdapterContext context) - { - // Don't trust TlsStream not to block. - return Task.Run(() => InnerOnConnectionAsync(context)); - } - - private async Task InnerOnConnectionAsync(ConnectionAdapterContext context) - { - var tlsStream = new TlsStream(context.ConnectionStream, _options.CertificatePath, _options.Password, _serverProtocols); - - try - { - await tlsStream.DoHandshakeAsync(); - _applicationProtocol = tlsStream.GetNegotiatedApplicationProtocol(); - } - catch (IOException ex) - { - _logger?.LogInformation(1, ex, "Authentication failed."); - tlsStream.Dispose(); - return _closedAdaptedConnection; - } - - // Always set the feature even though the cert might be null - context.Features.Set(new TlsConnectionFeature()); - context.Features.Set(new TlsApplicationProtocolFeature(_applicationProtocol)); - - return new TlsAdaptedConnection(tlsStream); - } - - private class TlsAdaptedConnection : IAdaptedConnection - { - private readonly TlsStream _tlsStream; - - public TlsAdaptedConnection(TlsStream tlsStream) - { - _tlsStream = tlsStream; - } - - public Stream ConnectionStream => _tlsStream; - - public void Dispose() - { - _tlsStream.Dispose(); - } - } - - private class ClosedAdaptedConnection : IAdaptedConnection - { - public Stream ConnectionStream { get; } = new ClosedStream(); - - public void Dispose() - { - } - } - } -} diff --git a/src/Kestrel.Tls/TlsConnectionAdapterOptions.cs b/src/Kestrel.Tls/TlsConnectionAdapterOptions.cs deleted file mode 100644 index 220bd47d9c..0000000000 --- a/src/Kestrel.Tls/TlsConnectionAdapterOptions.cs +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using Microsoft.AspNetCore.Server.Kestrel.Core; - -namespace Microsoft.AspNetCore.Server.Kestrel.Tls -{ - public class TlsConnectionAdapterOptions - { - public string CertificatePath { get; set; } = string.Empty; - - public string Password { get; set; } = string.Empty; - - public HttpProtocols Protocols { get; set; } - } -} diff --git a/src/Kestrel.Tls/TlsConnectionFeature.cs b/src/Kestrel.Tls/TlsConnectionFeature.cs deleted file mode 100644 index 007fbd0f8a..0000000000 --- a/src/Kestrel.Tls/TlsConnectionFeature.cs +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using System.Security.Cryptography.X509Certificates; -using System.Threading; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Http.Features; - -namespace Microsoft.AspNetCore.Server.Kestrel.Tls -{ - internal class TlsConnectionFeature : ITlsConnectionFeature - { - public X509Certificate2 ClientCertificate { get; set; } - - public Task GetClientCertificateAsync(CancellationToken cancellationToken) - { - return Task.FromResult(ClientCertificate); - } - } -} diff --git a/src/Kestrel.Tls/TlsStream.cs b/src/Kestrel.Tls/TlsStream.cs deleted file mode 100644 index 497317bab7..0000000000 --- a/src/Kestrel.Tls/TlsStream.cs +++ /dev/null @@ -1,243 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Runtime.InteropServices; -using System.Text; -using System.Threading; -using System.Threading.Tasks; -using Microsoft.Extensions.Logging; - -namespace Microsoft.AspNetCore.Server.Kestrel.Tls -{ - public class TlsStream : Stream - { - // Error code that indicates that a handshake failed because unencrypted HTTP was sent - private const int SSL_ERROR_HTTP_REQUEST = 336130204; - - private static unsafe OpenSsl.alpn_select_cb_t _alpnSelectCallback = AlpnSelectCallback; - - private readonly Stream _innerStream; - private readonly byte[] _protocols; - private readonly GCHandle _protocolsHandle; - - private IntPtr _ctx; - private IntPtr _ssl; - private IntPtr _inputBio; - private IntPtr _outputBio; - - private readonly byte[] _inputBuffer = new byte[1024 * 1024]; - private readonly byte[] _outputBuffer = new byte[1024 * 1024]; - - static TlsStream() - { - OpenSsl.SSL_library_init(); - OpenSsl.SSL_load_error_strings(); - OpenSsl.ERR_load_BIO_strings(); - OpenSsl.OpenSSL_add_all_algorithms(); - } - - public TlsStream(Stream innerStream, string certificatePath, string password, IEnumerable protocols) - { - _innerStream = innerStream; - _protocols = ToWireFormat(protocols); - _protocolsHandle = GCHandle.Alloc(_protocols); - - _ctx = OpenSsl.SSL_CTX_new(OpenSsl.TLSv1_2_method()); - - if (_ctx == IntPtr.Zero) - { - throw new Exception("Unable to create SSL context."); - } - - if(OpenSsl.SSL_CTX_Set_Pfx(_ctx, certificatePath, password) != 1) - { - throw new InvalidOperationException("Unable to load PFX"); - } - - OpenSsl.SSL_CTX_set_ecdh_auto(_ctx, 1); - - OpenSsl.SSL_CTX_set_alpn_select_cb(_ctx, _alpnSelectCallback, GCHandle.ToIntPtr(_protocolsHandle)); - - _ssl = OpenSsl.SSL_new(_ctx); - - _inputBio = OpenSsl.BIO_new(OpenSsl.BIO_s_mem()); - OpenSsl.BIO_set_mem_eof_return(_inputBio, -1); - - _outputBio = OpenSsl.BIO_new(OpenSsl.BIO_s_mem()); - OpenSsl.BIO_set_mem_eof_return(_outputBio, -1); - - OpenSsl.SSL_set_bio(_ssl, _inputBio, _outputBio); - } - - ~TlsStream() - { - if (_ssl != IntPtr.Zero) - { - OpenSsl.SSL_free(_ssl); - } - - if (_ctx != IntPtr.Zero) - { - // This frees the BIOs. - OpenSsl.SSL_CTX_free(_ctx); - } - - if (_protocolsHandle.IsAllocated) - { - _protocolsHandle.Free(); - } - } - - public override bool CanRead => true; - public override bool CanWrite => true; - - public override bool CanSeek => false; - public override long Length => throw new NotSupportedException(); - public override long Position - { - get => throw new NotSupportedException(); - set => throw new NotSupportedException(); - } - public override long Seek(long offset, SeekOrigin origin) => throw new NotSupportedException(); - public override void SetLength(long value) => throw new NotSupportedException(); - - public override void Flush() - { - FlushAsync(default(CancellationToken)).GetAwaiter().GetResult(); - } - - public override int Read(byte[] buffer, int offset, int count) - { - return ReadAsync(buffer, offset, count).GetAwaiter().GetResult(); - } - - public override void Write(byte[] buffer, int offset, int count) - { - WriteAsync(buffer, offset, count).GetAwaiter().GetResult(); - } - - public override async Task FlushAsync(CancellationToken cancellationToken) - { - var pending = OpenSsl.BIO_ctrl_pending(_outputBio); - - while (pending > 0) - { - var count = OpenSsl.BIO_read(_outputBio, _outputBuffer, 0, _outputBuffer.Length); - await _innerStream.WriteAsync(_outputBuffer, 0, count, cancellationToken); - - pending = OpenSsl.BIO_ctrl_pending(_outputBio); - } - } - - public override async Task ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) - { - if (OpenSsl.BIO_ctrl_pending(_inputBio) == 0) - { - var bytesRead = await _innerStream.ReadAsync(_inputBuffer, 0, _inputBuffer.Length, cancellationToken); - - if (bytesRead == 0) - { - return 0; - } - - OpenSsl.BIO_write(_inputBio, _inputBuffer, 0, bytesRead); - } - - return OpenSsl.SSL_read(_ssl, buffer, offset, count); - } - - public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) - { - OpenSsl.SSL_write(_ssl, buffer, offset, count); - - return FlushAsync(cancellationToken); - } - - public async Task DoHandshakeAsync(CancellationToken cancellationToken = default(CancellationToken)) - { - OpenSsl.SSL_set_accept_state(_ssl); - - var count = 0; - - try - { - while ((count = await _innerStream.ReadAsync(_inputBuffer, 0, _inputBuffer.Length, cancellationToken)) > 0) - { - if (count == 0) - { - throw new IOException("TLS handshake failed: the inner stream was closed."); - } - - OpenSsl.BIO_write(_inputBio, _inputBuffer, 0, count); - - var ret = OpenSsl.SSL_do_handshake(_ssl); - - if (ret != 1) - { - var error = OpenSsl.SSL_get_error(_ssl, ret); - - if (error == 1) - { - // SSL error, get it from the OpenSSL error queue - error = OpenSsl.ERR_get_error(); - if (error == SSL_ERROR_HTTP_REQUEST) - { - throw new InvalidOperationException("Unencrypted HTTP traffic was sent to an HTTPS endpoint"); - } - var errorString = OpenSsl.ERR_error_string(error); - throw new IOException($"TLS handshake failed: {nameof(OpenSsl.SSL_do_handshake)} error {error}. {errorString}"); - } - } - - await FlushAsync(cancellationToken); - - if (ret == 1) - { - return; - } - } - } - finally - { - _protocolsHandle.Free(); - } - } - - public string GetNegotiatedApplicationProtocol() - { - OpenSsl.SSL_get0_alpn_selected(_ssl, out var protocol); - return protocol; - } - - private static unsafe int AlpnSelectCallback(IntPtr ssl, out byte* @out, out byte outlen, byte* @in, uint inlen, IntPtr arg) - { - var protocols = GCHandle.FromIntPtr(arg); - var server = (byte[])protocols.Target; - - fixed (byte* serverPtr = server) - { - return OpenSsl.SSL_select_next_proto(out @out, out outlen, serverPtr, (uint)server.Length, @in, (uint)inlen) == OpenSsl.OPENSSL_NPN_NEGOTIATED - ? OpenSsl.SSL_TLSEXT_ERR_OK - : OpenSsl.SSL_TLSEXT_ERR_NOACK; - } - } - - private static byte[] ToWireFormat(IEnumerable protocols) - { - var buffer = new byte[protocols.Count() + protocols.Sum(protocol => protocol.Length)]; - - var offset = 0; - foreach (var protocol in protocols) - { - buffer[offset++] = (byte)protocol.Length; - offset += Encoding.ASCII.GetBytes(protocol, 0, protocol.Length, buffer, offset); - } - - return buffer; - } - } -} From 98de3aa50dc6ae4309d74fbbe8fe95b0f942b6ad Mon Sep 17 00:00:00 2001 From: Nate McMaster Date: Tue, 28 Nov 2017 11:04:08 -0800 Subject: [PATCH 1466/1662] Suppress API check due to reflection load errors (#2185) [ci skip] --- src/Kestrel.Https/Kestrel.Https.csproj | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Kestrel.Https/Kestrel.Https.csproj b/src/Kestrel.Https/Kestrel.Https.csproj index d9620b513e..d7fbda15e4 100644 --- a/src/Kestrel.Https/Kestrel.Https.csproj +++ b/src/Kestrel.Https/Kestrel.Https.csproj @@ -8,6 +8,8 @@ true aspnetcore;kestrel CS1591;$(NoWarn) + + false From 5e9e3a857418cb3cd0c6c18be8c5ed86984cffad Mon Sep 17 00:00:00 2001 From: Tornhoof Date: Wed, 29 Nov 2017 21:30:27 +0100 Subject: [PATCH 1467/1662] Make sure to add whitespace after the status code even if the reasonphrase is empty (#2184) --- .../Internal/Http/ReasonPhrases.cs | 6 +++-- test/Kestrel.Core.Tests/ReasonPhrasesTests.cs | 24 +++++++++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 test/Kestrel.Core.Tests/ReasonPhrasesTests.cs diff --git a/src/Kestrel.Core/Internal/Http/ReasonPhrases.cs b/src/Kestrel.Core/Internal/Http/ReasonPhrases.cs index 36eaaacf87..d372113bda 100644 --- a/src/Kestrel.Core/Internal/Http/ReasonPhrases.cs +++ b/src/Kestrel.Core/Internal/Http/ReasonPhrases.cs @@ -222,9 +222,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http default: var predefinedReasonPhrase = WebUtilities.ReasonPhrases.GetReasonPhrase(statusCode); + // https://tools.ietf.org/html/rfc7230#section-3.1.2 requires trailing whitespace regardless of reason phrase + var formattedStatusCode = statusCode.ToString(CultureInfo.InvariantCulture) + " "; return string.IsNullOrEmpty(predefinedReasonPhrase) - ? Encoding.ASCII.GetBytes(statusCode.ToString(CultureInfo.InvariantCulture)) - : Encoding.ASCII.GetBytes(statusCode.ToString(CultureInfo.InvariantCulture) + " " + predefinedReasonPhrase); + ? Encoding.ASCII.GetBytes(formattedStatusCode) + : Encoding.ASCII.GetBytes(formattedStatusCode + predefinedReasonPhrase); } } diff --git a/test/Kestrel.Core.Tests/ReasonPhrasesTests.cs b/test/Kestrel.Core.Tests/ReasonPhrasesTests.cs new file mode 100644 index 0000000000..9a7957735b --- /dev/null +++ b/test/Kestrel.Core.Tests/ReasonPhrasesTests.cs @@ -0,0 +1,24 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using Xunit; +using Microsoft.AspNetCore.Http; +using System.Text; + +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests +{ + public class ReasonPhraseTests + { + [Theory] + [InlineData(999, "Unknown", "999 Unknown")] + [InlineData(999, null, "999 ")] + [InlineData(StatusCodes.Status200OK, "OK", "200 OK")] + [InlineData(StatusCodes.Status200OK, null, "200 OK")] + public void Formatting(int statusCode, string reasonPhrase, string expectedResult) + { + var bytes = Internal.Http.ReasonPhrases.ToStatusBytes(statusCode, reasonPhrase); + Assert.NotNull(bytes); + Assert.Equal(expectedResult, Encoding.ASCII.GetString(bytes)); + } + } +} \ No newline at end of file From 906dc80fd609a182acd5d4c3afc037710b41ff31 Mon Sep 17 00:00:00 2001 From: Pranav K Date: Wed, 29 Nov 2017 14:09:27 -0800 Subject: [PATCH 1468/1662] Specify runtime versions to install --- build/repo.props | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/build/repo.props b/build/repo.props index 787d9e7eb8..2c858d96cf 100644 --- a/build/repo.props +++ b/build/repo.props @@ -1,8 +1,15 @@  + + true Internal.AspNetCore.Universe.Lineup https://dotnet.myget.org/F/aspnetcore-dev/api/v3/index.json + + + + + From 01e2c881317ef3473b313a01eb194f6f418b11b6 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Thu, 30 Nov 2017 11:20:22 -0800 Subject: [PATCH 1469/1662] Remove the custom C# compiler now that we're using the 2.2 SDK (#2193) - It should speed builds up considerably --- Directory.Build.props | 5 ----- build/dependencies.props | 1 - 2 files changed, 6 deletions(-) diff --git a/Directory.Build.props b/Directory.Build.props index 877639ff43..170752b08d 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -18,9 +18,4 @@ true latest - - - - - diff --git a/build/dependencies.props b/build/dependencies.props index 95d6623260..63cc2e08da 100644 --- a/build/dependencies.props +++ b/build/dependencies.props @@ -23,7 +23,6 @@ 2.1.0-preview1-27644 2.0.0 2.1.0-preview1-25907-02 - 2.6.0-beta2-62211-02 2.1.0-preview1-27644 15.3.0 4.7.49 From 7c2c5f2bef20182dd223665c1a55fb266d8405e1 Mon Sep 17 00:00:00 2001 From: Ryan Brandenburg Date: Thu, 30 Nov 2017 18:36:35 -0800 Subject: [PATCH 1470/1662] EnableApiCheck for Kestrel.Https (#2198) --- src/Kestrel.Https/Kestrel.Https.csproj | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Kestrel.Https/Kestrel.Https.csproj b/src/Kestrel.Https/Kestrel.Https.csproj index d7fbda15e4..d9620b513e 100644 --- a/src/Kestrel.Https/Kestrel.Https.csproj +++ b/src/Kestrel.Https/Kestrel.Https.csproj @@ -8,8 +8,6 @@ true aspnetcore;kestrel CS1591;$(NoWarn) - - false From a08707f133b138181ca0fc4ddd75200dc687858e Mon Sep 17 00:00:00 2001 From: Ryan Brandenburg Date: Fri, 1 Dec 2017 10:24:55 -0800 Subject: [PATCH 1471/1662] Update bootstrappers --- run.ps1 | 17 +++++++++++------ run.sh | 30 +++++++++++++++++++----------- 2 files changed, 30 insertions(+), 17 deletions(-) diff --git a/run.ps1 b/run.ps1 index 49c2899856..27dcf848f8 100644 --- a/run.ps1 +++ b/run.ps1 @@ -29,6 +29,9 @@ Updates KoreBuild to the latest version even if a lock file is present. .PARAMETER ConfigFile The path to the configuration file that stores values. Defaults to korebuild.json. +.PARAMETER ToolsSourceSuffix +The Suffix to append to the end of the ToolsSource. Useful for query strings in blob stores. + .PARAMETER Arguments Arguments to be passed to the command @@ -51,7 +54,7 @@ Example config file: #> [CmdletBinding(PositionalBinding = $false)] param( - [Parameter(Mandatory=$true, Position = 0)] + [Parameter(Mandatory = $true, Position = 0)] [string]$Command, [string]$Path = $PSScriptRoot, [Alias('c')] @@ -63,6 +66,7 @@ param( [Alias('u')] [switch]$Update, [string]$ConfigFile, + [string]$ToolsSourceSuffix, [Parameter(ValueFromRemainingArguments = $true)] [string[]]$Arguments ) @@ -79,7 +83,7 @@ function Get-KoreBuild { $lockFile = Join-Path $Path 'korebuild-lock.txt' if (!(Test-Path $lockFile) -or $Update) { - Get-RemoteFile "$ToolsSource/korebuild/channels/$Channel/latest.txt" $lockFile + Get-RemoteFile "$ToolsSource/korebuild/channels/$Channel/latest.txt" $lockFile $ToolsSourceSuffix } $version = Get-Content $lockFile | Where-Object { $_ -like 'version:*' } | Select-Object -first 1 @@ -96,7 +100,7 @@ function Get-KoreBuild { try { $tmpfile = Join-Path ([IO.Path]::GetTempPath()) "KoreBuild-$([guid]::NewGuid()).zip" - Get-RemoteFile $remotePath $tmpfile + Get-RemoteFile $remotePath $tmpfile $ToolsSourceSuffix if (Get-Command -Name 'Expand-Archive' -ErrorAction Ignore) { # Use built-in commands where possible as they are cross-plat compatible Expand-Archive -Path $tmpfile -DestinationPath $korebuildPath @@ -124,7 +128,7 @@ function Join-Paths([string]$path, [string[]]$childPaths) { return $path } -function Get-RemoteFile([string]$RemotePath, [string]$LocalPath) { +function Get-RemoteFile([string]$RemotePath, [string]$LocalPath, [string]$RemoteSuffix) { if ($RemotePath -notlike 'http*') { Copy-Item $RemotePath $LocalPath return @@ -134,7 +138,7 @@ function Get-RemoteFile([string]$RemotePath, [string]$LocalPath) { while ($retries -gt 0) { $retries -= 1 try { - Invoke-WebRequest -UseBasicParsing -Uri $RemotePath -OutFile $LocalPath + Invoke-WebRequest -UseBasicParsing -Uri $($RemotePath + $RemoteSuffix) -OutFile $LocalPath return } catch { @@ -161,7 +165,8 @@ if (Test-Path $ConfigFile) { if (!($Channel) -and (Get-Member -Name 'channel' -InputObject $config)) { [string] $Channel = $config.channel } if (!($ToolsSource) -and (Get-Member -Name 'toolsSource' -InputObject $config)) { [string] $ToolsSource = $config.toolsSource} } - } catch { + } + catch { Write-Warning "$ConfigFile could not be read. Its settings will be ignored." Write-Warning $Error[0] } diff --git a/run.sh b/run.sh index c278423acc..834961fc3a 100755 --- a/run.sh +++ b/run.sh @@ -17,6 +17,7 @@ update=false repo_path="$DIR" channel='' tools_source='' +tools_source_suffix='' # # Functions @@ -29,13 +30,14 @@ __usage() { echo " ... Arguments passed to the command. Variable number of arguments allowed." echo "" echo "Options:" - echo " --verbose Show verbose output." - echo " -c|--channel The channel of KoreBuild to download. Overrides the value from the config file.." - echo " --config-file The path to the configuration file that stores values. Defaults to korebuild.json." - echo " -d|--dotnet-home The directory where .NET Core tools will be stored. Defaults to '\$DOTNET_HOME' or '\$HOME/.dotnet." - echo " --path The directory to build. Defaults to the directory containing the script." - echo " -s|--tools-source|-ToolsSource The base url where build tools can be downloaded. Overrides the value from the config file." - echo " -u|--update Update to the latest KoreBuild even if the lock file is present." + echo " --verbose Show verbose output." + echo " -c|--channel The channel of KoreBuild to download. Overrides the value from the config file.." + echo " --config-file The path to the configuration file that stores values. Defaults to korebuild.json." + echo " -d|--dotnet-home The directory where .NET Core tools will be stored. Defaults to '\$DOTNET_HOME' or '\$HOME/.dotnet." + echo " --path The directory to build. Defaults to the directory containing the script." + echo " -s|--tools-source|-ToolsSource The base url where build tools can be downloaded. Overrides the value from the config file." + echo " --tools-source-suffix|-ToolsSourceSuffix The suffix to append to tools-source. Useful for query strings." + echo " -u|--update Update to the latest KoreBuild even if the lock file is present." echo "" echo "Description:" echo " This function will create a file \$DIR/korebuild-lock.txt. This lock file can be committed to source, but does not have to be." @@ -50,7 +52,7 @@ get_korebuild() { local version local lock_file="$repo_path/korebuild-lock.txt" if [ ! -f "$lock_file" ] || [ "$update" = true ]; then - __get_remote_file "$tools_source/korebuild/channels/$channel/latest.txt" "$lock_file" + __get_remote_file "$tools_source/korebuild/channels/$channel/latest.txt" "$lock_file" "$tools_source_suffix" fi version="$(grep 'version:*' -m 1 "$lock_file")" if [[ "$version" == '' ]]; then @@ -66,7 +68,7 @@ get_korebuild() { local remote_path="$tools_source/korebuild/artifacts/$version/korebuild.$version.zip" tmpfile="$(mktemp)" echo -e "${MAGENTA}Downloading KoreBuild ${version}${RESET}" - if __get_remote_file "$remote_path" "$tmpfile"; then + if __get_remote_file "$remote_path" "$tmpfile" "$tools_source_suffix"; then unzip -q -d "$korebuild_path" "$tmpfile" fi rm "$tmpfile" || true @@ -98,6 +100,7 @@ __machine_has() { __get_remote_file() { local remote_path=$1 local local_path=$2 + local remote_path_suffix=$3 if [[ "$remote_path" != 'http'* ]]; then cp "$remote_path" "$local_path" @@ -106,14 +109,14 @@ __get_remote_file() { local failed=false if __machine_has wget; then - wget --tries 10 --quiet -O "$local_path" "$remote_path" || failed=true + wget --tries 10 --quiet -O "$local_path" "${remote_path}${remote_path_suffix}" || failed=true else failed=true fi if [ "$failed" = true ] && __machine_has curl; then failed=false - curl --retry 10 -sSL -f --create-dirs -o "$local_path" "$remote_path" || failed=true + curl --retry 10 -sSL -f --create-dirs -o "$local_path" "${remote_path}${remote_path_suffix}" || failed=true fi if [ "$failed" = true ]; then @@ -164,6 +167,11 @@ while [[ $# -gt 0 ]]; do tools_source="${1:-}" [ -z "$tools_source" ] && __usage ;; + --tools-source-suffix|-ToolsSourceSuffix) + shift + tools_source_suffix="${1:-}" + [ -z "$tools_source_suffix" ] && __usage + ;; -u|--update|-Update) update=true ;; From b8a1c04ffbeee6c60a74766142ff3e2e6779d701 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Sun, 3 Dec 2017 13:27:36 -0800 Subject: [PATCH 1472/1662] Make the HttpParser a singleton (#2203) - It's completely stateless so make it a singleton - Fixed tests --- .../Http1ConnectionParsingOverheadBenchmark.cs | 2 +- .../Http1WritingBenchmark.cs | 2 +- .../HttpProtocolFeatureCollection.cs | 2 +- .../RequestParsingBenchmark.cs | 2 +- .../ResponseHeaderCollectionBenchmark.cs | 2 +- .../ResponseHeadersWritingBenchmark.cs | 2 +- .../Internal/Http/Http1Connection.cs | 2 +- src/Kestrel.Core/Internal/ServiceContext.cs | 2 +- src/Kestrel.Core/KestrelServer.cs | 2 +- test/Kestrel.Core.Tests/KestrelServerTests.cs | 17 ++++++++++++++--- .../ListenerPrimaryTests.cs | 4 ++-- test/shared/TestServiceContext.cs | 2 +- 12 files changed, 26 insertions(+), 15 deletions(-) diff --git a/benchmarks/Kestrel.Performance/Http1ConnectionParsingOverheadBenchmark.cs b/benchmarks/Kestrel.Performance/Http1ConnectionParsingOverheadBenchmark.cs index 28413ab08b..35f40de854 100644 --- a/benchmarks/Kestrel.Performance/Http1ConnectionParsingOverheadBenchmark.cs +++ b/benchmarks/Kestrel.Performance/Http1ConnectionParsingOverheadBenchmark.cs @@ -29,7 +29,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance var serviceContext = new ServiceContext { ServerOptions = new KestrelServerOptions(), - HttpParserFactory = f => NullParser.Instance + HttpParser = NullParser.Instance }; var http1Connection = new Http1Connection(application: null, context: new Http1ConnectionContext diff --git a/benchmarks/Kestrel.Performance/Http1WritingBenchmark.cs b/benchmarks/Kestrel.Performance/Http1WritingBenchmark.cs index 91f42667ae..ea5e13646f 100644 --- a/benchmarks/Kestrel.Performance/Http1WritingBenchmark.cs +++ b/benchmarks/Kestrel.Performance/Http1WritingBenchmark.cs @@ -104,7 +104,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance DateHeaderValueManager = new DateHeaderValueManager(), ServerOptions = new KestrelServerOptions(), Log = new MockTrace(), - HttpParserFactory = f => new HttpParser() + HttpParser = new HttpParser() }; var http1Connection = new TestHttp1Connection( diff --git a/benchmarks/Kestrel.Performance/HttpProtocolFeatureCollection.cs b/benchmarks/Kestrel.Performance/HttpProtocolFeatureCollection.cs index d55644d976..1df078f0e5 100644 --- a/benchmarks/Kestrel.Performance/HttpProtocolFeatureCollection.cs +++ b/benchmarks/Kestrel.Performance/HttpProtocolFeatureCollection.cs @@ -86,7 +86,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance DateHeaderValueManager = new DateHeaderValueManager(), ServerOptions = new KestrelServerOptions(), Log = new MockTrace(), - HttpParserFactory = f => new HttpParser() + HttpParser = new HttpParser() }; var http1Connection = new Http1Connection(application: null, context: new Http1ConnectionContext diff --git a/benchmarks/Kestrel.Performance/RequestParsingBenchmark.cs b/benchmarks/Kestrel.Performance/RequestParsingBenchmark.cs index 5837b5f5a1..d8c002c543 100644 --- a/benchmarks/Kestrel.Performance/RequestParsingBenchmark.cs +++ b/benchmarks/Kestrel.Performance/RequestParsingBenchmark.cs @@ -30,7 +30,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance DateHeaderValueManager = new DateHeaderValueManager(), ServerOptions = new KestrelServerOptions(), Log = new MockTrace(), - HttpParserFactory = f => new HttpParser() + HttpParser = new HttpParser() }; var http1Connection = new Http1Connection(application: null, context: new Http1ConnectionContext diff --git a/benchmarks/Kestrel.Performance/ResponseHeaderCollectionBenchmark.cs b/benchmarks/Kestrel.Performance/ResponseHeaderCollectionBenchmark.cs index cbd2fd5e79..6f9ac3b78a 100644 --- a/benchmarks/Kestrel.Performance/ResponseHeaderCollectionBenchmark.cs +++ b/benchmarks/Kestrel.Performance/ResponseHeaderCollectionBenchmark.cs @@ -179,7 +179,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance DateHeaderValueManager = new DateHeaderValueManager(), ServerOptions = new KestrelServerOptions(), Log = new MockTrace(), - HttpParserFactory = f => new HttpParser() + HttpParser = new HttpParser() }; var http1Connection = new Http1Connection(application: null, context: new Http1ConnectionContext diff --git a/benchmarks/Kestrel.Performance/ResponseHeadersWritingBenchmark.cs b/benchmarks/Kestrel.Performance/ResponseHeadersWritingBenchmark.cs index 4940aa4326..c11e5ceff5 100644 --- a/benchmarks/Kestrel.Performance/ResponseHeadersWritingBenchmark.cs +++ b/benchmarks/Kestrel.Performance/ResponseHeadersWritingBenchmark.cs @@ -119,7 +119,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance DateHeaderValueManager = new DateHeaderValueManager(), ServerOptions = new KestrelServerOptions(), Log = new MockTrace(), - HttpParserFactory = f => new HttpParser() + HttpParser = new HttpParser() }; var http1Connection = new TestHttp1Connection( diff --git a/src/Kestrel.Core/Internal/Http/Http1Connection.cs b/src/Kestrel.Core/Internal/Http/Http1Connection.cs index cb073a0724..a9e74a4220 100644 --- a/src/Kestrel.Core/Internal/Http/Http1Connection.cs +++ b/src/Kestrel.Core/Internal/Http/Http1Connection.cs @@ -35,7 +35,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http : base(context) { _context = context; - _parser = ServiceContext.HttpParserFactory(new Http1ParsingHandler(this)); + _parser = ServiceContext.HttpParser; _keepAliveTicks = ServerOptions.Limits.KeepAliveTimeout.Ticks; _requestHeadersTimeoutTicks = ServerOptions.Limits.RequestHeadersTimeout.Ticks; diff --git a/src/Kestrel.Core/Internal/ServiceContext.cs b/src/Kestrel.Core/Internal/ServiceContext.cs index 19d22a1272..30f45b1f37 100644 --- a/src/Kestrel.Core/Internal/ServiceContext.cs +++ b/src/Kestrel.Core/Internal/ServiceContext.cs @@ -13,7 +13,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal public IThreadPool ThreadPool { get; set; } - public Func> HttpParserFactory { get; set; } + public IHttpParser HttpParser { get; set; } public ISystemClock SystemClock { get; set; } diff --git a/src/Kestrel.Core/KestrelServer.cs b/src/Kestrel.Core/KestrelServer.cs index 81536a44ab..1905ab7bc6 100644 --- a/src/Kestrel.Core/KestrelServer.cs +++ b/src/Kestrel.Core/KestrelServer.cs @@ -101,7 +101,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core return new ServiceContext { Log = trace, - HttpParserFactory = handler => new HttpParser(handler.Connection.ServiceContext.Log.IsEnabled(LogLevel.Information)), + HttpParser = new HttpParser(trace.IsEnabled(LogLevel.Information)), ThreadPool = threadPool, SystemClock = systemClock, DateHeaderValueManager = dateHeaderValueManager, diff --git a/test/Kestrel.Core.Tests/KestrelServerTests.cs b/test/Kestrel.Core.Tests/KestrelServerTests.cs index 51e9de0221..da23da4f19 100644 --- a/test/Kestrel.Core.Tests/KestrelServerTests.cs +++ b/test/Kestrel.Core.Tests/KestrelServerTests.cs @@ -188,6 +188,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests public void LoggerCategoryNameIsKestrelServerNamespace() { var mockLoggerFactory = new Mock(); + var mockLogger = new Mock(); + mockLoggerFactory.Setup(m => m.CreateLogger(It.IsAny())).Returns(mockLogger.Object); new KestrelServer(Options.Create(null), Mock.Of(), mockLoggerFactory.Object); mockLoggerFactory.Verify(factory => factory.CreateLogger("Microsoft.AspNetCore.Server.Kestrel")); } @@ -195,8 +197,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests [Fact] public void StartWithNoTransportFactoryThrows() { + var mockLoggerFactory = new Mock(); + var mockLogger = new Mock(); + mockLoggerFactory.Setup(m => m.CreateLogger(It.IsAny())).Returns(mockLogger.Object); var exception = Assert.Throws(() => - new KestrelServer(Options.Create(null), null, Mock.Of())); + new KestrelServer(Options.Create(null), null, mockLoggerFactory.Object)); Assert.Equal("transportFactory", exception.ParamName); } @@ -231,7 +236,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests .Setup(transportFactory => transportFactory.Create(It.IsAny(), It.IsAny())) .Returns(mockTransport.Object); - var server = new KestrelServer(Options.Create(options), mockTransportFactory.Object, Mock.Of()); + var mockLoggerFactory = new Mock(); + var mockLogger = new Mock(); + mockLoggerFactory.Setup(m => m.CreateLogger(It.IsAny())).Returns(mockLogger.Object); + var server = new KestrelServer(Options.Create(options), mockTransportFactory.Object, mockLoggerFactory.Object); await server.StartAsync(new DummyApplication(), CancellationToken.None); var stopTask1 = server.StopAsync(default(CancellationToken)); @@ -285,7 +293,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests .Setup(transportFactory => transportFactory.Create(It.IsAny(), It.IsAny())) .Returns(mockTransport.Object); - var server = new KestrelServer(Options.Create(options), mockTransportFactory.Object, Mock.Of()); + var mockLoggerFactory = new Mock(); + var mockLogger = new Mock(); + mockLoggerFactory.Setup(m => m.CreateLogger(It.IsAny())).Returns(mockLogger.Object); + var server = new KestrelServer(Options.Create(options), mockTransportFactory.Object, mockLoggerFactory.Object); await server.StartAsync(new DummyApplication(), CancellationToken.None); var stopTask1 = server.StopAsync(default(CancellationToken)); diff --git a/test/Kestrel.Transport.Libuv.Tests/ListenerPrimaryTests.cs b/test/Kestrel.Transport.Libuv.Tests/ListenerPrimaryTests.cs index 41ee4a7f19..3defb90297 100644 --- a/test/Kestrel.Transport.Libuv.Tests/ListenerPrimaryTests.cs +++ b/test/Kestrel.Transport.Libuv.Tests/ListenerPrimaryTests.cs @@ -110,7 +110,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests DateHeaderValueManager = serviceContextPrimary.DateHeaderValueManager, ServerOptions = serviceContextPrimary.ServerOptions, ThreadPool = serviceContextPrimary.ThreadPool, - HttpParserFactory = serviceContextPrimary.HttpParserFactory, + HttpParser = serviceContextPrimary.HttpParser, }; var builderSecondary = new ConnectionBuilder(); builderSecondary.UseHttpServer(serviceContextSecondary, new DummyApplication(c => c.Response.WriteAsync("Secondary")), HttpProtocols.Http1); @@ -221,7 +221,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests DateHeaderValueManager = serviceContextPrimary.DateHeaderValueManager, ServerOptions = serviceContextPrimary.ServerOptions, ThreadPool = serviceContextPrimary.ThreadPool, - HttpParserFactory = serviceContextPrimary.HttpParserFactory, + HttpParser = serviceContextPrimary.HttpParser, }; var builderSecondary = new ConnectionBuilder(); builderSecondary.UseHttpServer(serviceContextSecondary, new DummyApplication(c => c.Response.WriteAsync("Secondary")), HttpProtocols.Http1); diff --git a/test/shared/TestServiceContext.cs b/test/shared/TestServiceContext.cs index 556e36be58..1109cf5f05 100644 --- a/test/shared/TestServiceContext.cs +++ b/test/shared/TestServiceContext.cs @@ -39,7 +39,7 @@ namespace Microsoft.AspNetCore.Testing SystemClock = new MockSystemClock(); DateHeaderValueManager = new DateHeaderValueManager(SystemClock); ConnectionManager = new HttpConnectionManager(Log, ResourceCounter.Unlimited); - HttpParserFactory = handler => new HttpParser(handler.Connection.ServiceContext.Log.IsEnabled(LogLevel.Information)); + HttpParser = new HttpParser(Log.IsEnabled(LogLevel.Information)); ServerOptions = new KestrelServerOptions { AddServerHeader = false From 668f8e3b4b4f6e74e7a36433439847575889058e Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Mon, 4 Dec 2017 15:59:12 -0800 Subject: [PATCH 1473/1662] Lazily allocate protocol-specific connection objects (#2190) * Refactor Http[12]?Connection --- ...Http1ConnectionParsingOverheadBenchmark.cs | 4 +- .../Http1WritingBenchmark.cs | 21 +- .../HttpProtocolFeatureCollection.cs | 4 +- .../RequestParsingBenchmark.cs | 4 +- .../ResponseHeaderCollectionBenchmark.cs | 2 +- .../ResponseHeadersWritingBenchmark.cs | 21 +- .../Internal/Http/Http1Connection.cs | 8 +- .../Internal/Http/Http1ConnectionOfT.cs | 27 --- .../Internal/Http/HttpProtocol.cs | 16 +- .../Internal/Http2/Http2Connection.cs | 23 +- .../Internal/Http2/Http2Stream.cs | 2 +- .../Internal/Http2/Http2StreamOfT.cs | 27 --- src/Kestrel.Core/Internal/HttpConnection.cs | 203 ++++++++++-------- .../Internal/IRequestProcessor.cs | 16 ++ .../Http1ConnectionTests.cs | 26 +-- .../Http2ConnectionTests.cs | 2 +- .../Kestrel.Core.Tests/HttpConnectionTests.cs | 30 +-- .../HttpResponseHeadersTests.cs | 2 +- test/Kestrel.Core.Tests/TestInput.cs | 2 +- .../LibuvOutputConsumerTests.cs | 2 +- test/shared/TestHttp1Connection.cs | 8 +- 21 files changed, 206 insertions(+), 244 deletions(-) delete mode 100644 src/Kestrel.Core/Internal/Http/Http1ConnectionOfT.cs delete mode 100644 src/Kestrel.Core/Internal/Http2/Http2StreamOfT.cs create mode 100644 src/Kestrel.Core/Internal/IRequestProcessor.cs diff --git a/benchmarks/Kestrel.Performance/Http1ConnectionParsingOverheadBenchmark.cs b/benchmarks/Kestrel.Performance/Http1ConnectionParsingOverheadBenchmark.cs index 35f40de854..42e4cba170 100644 --- a/benchmarks/Kestrel.Performance/Http1ConnectionParsingOverheadBenchmark.cs +++ b/benchmarks/Kestrel.Performance/Http1ConnectionParsingOverheadBenchmark.cs @@ -18,7 +18,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance private const int InnerLoopCount = 512; public ReadableBuffer _buffer; - public Http1Connection _http1Connection; + public Http1Connection _http1Connection; [IterationSetup] public void Setup() @@ -32,7 +32,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance HttpParser = NullParser.Instance }; - var http1Connection = new Http1Connection(application: null, context: new Http1ConnectionContext + var http1Connection = new Http1Connection(new Http1ConnectionContext { ServiceContext = serviceContext, ConnectionFeatures = new FeatureCollection(), diff --git a/benchmarks/Kestrel.Performance/Http1WritingBenchmark.cs b/benchmarks/Kestrel.Performance/Http1WritingBenchmark.cs index ea5e13646f..717009affa 100644 --- a/benchmarks/Kestrel.Performance/Http1WritingBenchmark.cs +++ b/benchmarks/Kestrel.Performance/Http1WritingBenchmark.cs @@ -25,7 +25,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance private static readonly Task _psuedoAsyncTask = Task.FromResult(27); private static readonly Func _psuedoAsyncTaskFunc = (obj) => _psuedoAsyncTask; - private readonly TestHttp1Connection _http1Connection; + private readonly TestHttp1Connection _http1Connection; private (IPipeConnection Transport, IPipeConnection Application) _pair; private readonly byte[] _writeData; @@ -92,7 +92,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance return _http1Connection.ResponseBody.WriteAsync(_writeData, 0, _writeData.Length, default(CancellationToken)); } - private TestHttp1Connection MakeHttp1Connection() + private TestHttp1Connection MakeHttp1Connection() { using (var memoryPool = new MemoryPool()) { @@ -107,15 +107,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance HttpParser = new HttpParser() }; - var http1Connection = new TestHttp1Connection( - application: null, context: new Http1ConnectionContext - { - ServiceContext = serviceContext, - ConnectionFeatures = new FeatureCollection(), - BufferPool = memoryPool, - Application = pair.Application, - Transport = pair.Transport - }); + var http1Connection = new TestHttp1Connection(new Http1ConnectionContext + { + ServiceContext = serviceContext, + ConnectionFeatures = new FeatureCollection(), + BufferPool = memoryPool, + Application = pair.Application, + Transport = pair.Transport + }); http1Connection.Reset(); http1Connection.InitializeStreams(MessageBody.ZeroContentLengthKeepAlive); diff --git a/benchmarks/Kestrel.Performance/HttpProtocolFeatureCollection.cs b/benchmarks/Kestrel.Performance/HttpProtocolFeatureCollection.cs index 1df078f0e5..b9cc8b27c4 100644 --- a/benchmarks/Kestrel.Performance/HttpProtocolFeatureCollection.cs +++ b/benchmarks/Kestrel.Performance/HttpProtocolFeatureCollection.cs @@ -15,7 +15,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance [ParameterizedJobConfig(typeof(CoreConfig))] public class HttpProtocolFeatureCollection { - private readonly Http1Connection _http1Connection; + private readonly Http1Connection _http1Connection; private IFeatureCollection _collection; [Benchmark(Baseline = true)] @@ -89,7 +89,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance HttpParser = new HttpParser() }; - var http1Connection = new Http1Connection(application: null, context: new Http1ConnectionContext + var http1Connection = new Http1Connection(new Http1ConnectionContext { ServiceContext = serviceContext, ConnectionFeatures = new FeatureCollection(), diff --git a/benchmarks/Kestrel.Performance/RequestParsingBenchmark.cs b/benchmarks/Kestrel.Performance/RequestParsingBenchmark.cs index d8c002c543..52b0bdca68 100644 --- a/benchmarks/Kestrel.Performance/RequestParsingBenchmark.cs +++ b/benchmarks/Kestrel.Performance/RequestParsingBenchmark.cs @@ -17,7 +17,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance { public IPipe Pipe { get; set; } - public Http1Connection Http1Connection { get; set; } + public Http1Connection Http1Connection { get; set; } [IterationSetup] public void Setup() @@ -33,7 +33,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance HttpParser = new HttpParser() }; - var http1Connection = new Http1Connection(application: null, context: new Http1ConnectionContext + var http1Connection = new Http1Connection(new Http1ConnectionContext { ServiceContext = serviceContext, ConnectionFeatures = new FeatureCollection(), diff --git a/benchmarks/Kestrel.Performance/ResponseHeaderCollectionBenchmark.cs b/benchmarks/Kestrel.Performance/ResponseHeaderCollectionBenchmark.cs index 6f9ac3b78a..664567cd88 100644 --- a/benchmarks/Kestrel.Performance/ResponseHeaderCollectionBenchmark.cs +++ b/benchmarks/Kestrel.Performance/ResponseHeaderCollectionBenchmark.cs @@ -182,7 +182,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance HttpParser = new HttpParser() }; - var http1Connection = new Http1Connection(application: null, context: new Http1ConnectionContext + var http1Connection = new Http1Connection(new Http1ConnectionContext { ServiceContext = serviceContext, ConnectionFeatures = new FeatureCollection(), diff --git a/benchmarks/Kestrel.Performance/ResponseHeadersWritingBenchmark.cs b/benchmarks/Kestrel.Performance/ResponseHeadersWritingBenchmark.cs index c11e5ceff5..e56c7112e5 100644 --- a/benchmarks/Kestrel.Performance/ResponseHeadersWritingBenchmark.cs +++ b/benchmarks/Kestrel.Performance/ResponseHeadersWritingBenchmark.cs @@ -22,7 +22,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance { private static readonly byte[] _helloWorldPayload = Encoding.ASCII.GetBytes("Hello, World!"); - private TestHttp1Connection _http1Connection; + private TestHttp1Connection _http1Connection; [Params( BenchmarkTypes.TechEmpowerPlaintext, @@ -122,16 +122,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance HttpParser = new HttpParser() }; - var http1Connection = new TestHttp1Connection( - application: null, context: new Http1ConnectionContext - { - ServiceContext = serviceContext, - ConnectionFeatures = new FeatureCollection(), - BufferPool = bufferPool, - TimeoutControl = new MockTimeoutControl(), - Application = pair.Application, - Transport = pair.Transport - }); + var http1Connection = new TestHttp1Connection(new Http1ConnectionContext + { + ServiceContext = serviceContext, + ConnectionFeatures = new FeatureCollection(), + BufferPool = bufferPool, + TimeoutControl = new MockTimeoutControl(), + Application = pair.Application, + Transport = pair.Transport + }); http1Connection.Reset(); diff --git a/src/Kestrel.Core/Internal/Http/Http1Connection.cs b/src/Kestrel.Core/Internal/Http/Http1Connection.cs index a9e74a4220..29b257208b 100644 --- a/src/Kestrel.Core/Internal/Http/Http1Connection.cs +++ b/src/Kestrel.Core/Internal/Http/Http1Connection.cs @@ -6,13 +6,12 @@ using System.Diagnostics; using System.IO.Pipelines; using System.Text; using System.Text.Encodings.Web.Utf8; -using System.Threading.Tasks; using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { - public abstract partial class Http1Connection : HttpProtocol + public partial class Http1Connection : HttpProtocol, IRequestProcessor { private const byte ByteAsterisk = (byte)'*'; private const byte ByteForwardSlash = (byte)'/'; @@ -146,6 +145,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { TimeoutControl.CancelTimeout(); } + return result; } @@ -337,7 +337,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http QueryString = query.GetAsciiStringNonNullCharacters(); } - private unsafe static string GetUtf8String(Span path) + private static unsafe string GetUtf8String(Span path) { // .NET 451 doesn't have pointer overloads for Encoding.GetString so we // copy to an array @@ -347,7 +347,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http } } - protected void EnsureHostHeaderExists() + private void EnsureHostHeaderExists() { if (_httpVersion == Http.HttpVersion.Http10) { diff --git a/src/Kestrel.Core/Internal/Http/Http1ConnectionOfT.cs b/src/Kestrel.Core/Internal/Http/Http1ConnectionOfT.cs deleted file mode 100644 index 2e0cf25669..0000000000 --- a/src/Kestrel.Core/Internal/Http/Http1ConnectionOfT.cs +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System.Threading.Tasks; -using Microsoft.AspNetCore.Hosting.Server; - -namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http -{ - public class Http1Connection : Http1Connection - { - private readonly IHttpApplication _application; - - private TContext _httpContext; - - public Http1Connection(IHttpApplication application, Http1ConnectionContext context) - : base(context) - { - _application = application; - } - - protected override void CreateHttpContext() => _httpContext = _application.CreateContext(this); - - protected override void DisposeHttpContext() => _application.DisposeContext(_httpContext, _applicationException); - - protected override Task InvokeApplicationAsync() => _application.ProcessRequestAsync(_httpContext); - } -} diff --git a/src/Kestrel.Core/Internal/Http/HttpProtocol.cs b/src/Kestrel.Core/Internal/Http/HttpProtocol.cs index 0cadbce735..dacd5313f4 100644 --- a/src/Kestrel.Core/Internal/Http/HttpProtocol.cs +++ b/src/Kestrel.Core/Internal/Http/HttpProtocol.cs @@ -12,6 +12,7 @@ using System.Runtime.CompilerServices; using System.Text; using System.Threading; using System.Threading.Tasks; +using Microsoft.AspNetCore.Hosting.Server; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Protocols; @@ -391,12 +392,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http protected abstract bool TryParseRequest(ReadResult result, out bool endConnection); - protected abstract void CreateHttpContext(); - - protected abstract void DisposeHttpContext(); - - protected abstract Task InvokeApplicationAsync(); - private void CancelRequestAbortedToken() { try @@ -440,7 +435,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http HttpRequestHeaders.Append(name, valueString); } - public async Task ProcessRequestsAsync() + public async Task ProcessRequestsAsync(IHttpApplication application) { try { @@ -474,14 +469,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http InitializeStreams(messageBody); - CreateHttpContext(); + var httpContext = application.CreateContext(this); + try { try { KestrelEventSource.Log.RequestStart(this); - await InvokeApplicationAsync(); + await application.ProcessRequestAsync(httpContext); if (_requestAborted == 0) { @@ -563,7 +559,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http } finally { - DisposeHttpContext(); + application.DisposeContext(httpContext, _applicationException); // StopStreams should be called before the end of the "if (!_requestProcessingStopping)" block // to ensure InitializeStreams has been called. diff --git a/src/Kestrel.Core/Internal/Http2/Http2Connection.cs b/src/Kestrel.Core/Internal/Http2/Http2Connection.cs index 83ec0d64f6..9d6ac80794 100644 --- a/src/Kestrel.Core/Internal/Http2/Http2Connection.cs +++ b/src/Kestrel.Core/Internal/Http2/Http2Connection.cs @@ -6,6 +6,7 @@ using System.Collections.Concurrent; using System.IO.Pipelines; using System.Text; using System.Threading.Tasks; +using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting.Server; using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Protocols; @@ -16,7 +17,7 @@ using Microsoft.Extensions.Logging; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 { - public class Http2Connection : ITimeoutControl, IHttp2StreamLifetimeHandler, IHttpHeadersHandler + public class Http2Connection : ITimeoutControl, IHttp2StreamLifetimeHandler, IHttpHeadersHandler, IRequestProcessor { private enum RequestHeaderParsingState { @@ -93,13 +94,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 _frameWriter.Abort(ex); } - public void Stop() + public void StopProcessingNextRequest() { _stopping = true; Input.CancelPendingRead(); } - public async Task ProcessAsync(IHttpApplication application) + public async Task ProcessRequestsAsync(IHttpApplication application) { Exception error = null; var errorCode = Http2ErrorCode.NO_ERROR; @@ -391,7 +392,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 else { // Start a new stream - _currentHeadersStream = new Http2Stream(application, new Http2StreamContext + _currentHeadersStream = new Http2Stream(new Http2StreamContext { ConnectionId = ConnectionId, StreamId = _incomingFrame.StreamId, @@ -412,7 +413,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 _currentHeadersStream.Reset(); var endHeaders = (_incomingFrame.HeadersFlags & Http2HeadersFrameFlags.END_HEADERS) == Http2HeadersFrameFlags.END_HEADERS; - await DecodeHeadersAsync(endHeaders, _incomingFrame.HeadersPayload); + await DecodeHeadersAsync(application, endHeaders, _incomingFrame.HeadersPayload); } } @@ -541,7 +542,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 throw new Http2ConnectionErrorException(CoreStrings.FormatHttp2ErrorStreamIdNotZero(_incomingFrame.Type), Http2ErrorCode.PROTOCOL_ERROR); } - Stop(); + StopProcessingNextRequest(); return Task.CompletedTask; } @@ -602,7 +603,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 } else { - return DecodeHeadersAsync(endHeaders, _incomingFrame.Payload); + return DecodeHeadersAsync(application, endHeaders, _incomingFrame.Payload); } } @@ -616,7 +617,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 return Task.CompletedTask; } - private Task DecodeHeadersAsync(bool endHeaders, Span payload) + private Task DecodeHeadersAsync(IHttpApplication application, bool endHeaders, Span payload) { try { @@ -624,7 +625,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 if (endHeaders) { - StartStream(); + StartStream(application); ResetRequestHeaderParsingState(); } } @@ -652,7 +653,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 return Task.CompletedTask; } - private void StartStream() + private void StartStream(IHttpApplication application) { if (!_isMethodConnect && (_parsedPseudoHeaderFields & _mandatoryRequestPseudoHeaderFields) != _mandatoryRequestPseudoHeaderFields) { @@ -663,7 +664,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 } _streams[_incomingFrame.StreamId] = _currentHeadersStream; - _ = _currentHeadersStream.ProcessRequestsAsync(); + _ = _currentHeadersStream.ProcessRequestsAsync(application); } private void ResetRequestHeaderParsingState() diff --git a/src/Kestrel.Core/Internal/Http2/Http2Stream.cs b/src/Kestrel.Core/Internal/Http2/Http2Stream.cs index ea8a564d9f..1d96e3f7be 100644 --- a/src/Kestrel.Core/Internal/Http2/Http2Stream.cs +++ b/src/Kestrel.Core/Internal/Http2/Http2Stream.cs @@ -10,7 +10,7 @@ using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 { - public abstract partial class Http2Stream : HttpProtocol + public partial class Http2Stream : HttpProtocol { private readonly Http2StreamContext _context; diff --git a/src/Kestrel.Core/Internal/Http2/Http2StreamOfT.cs b/src/Kestrel.Core/Internal/Http2/Http2StreamOfT.cs deleted file mode 100644 index 5f6c1e7d95..0000000000 --- a/src/Kestrel.Core/Internal/Http2/Http2StreamOfT.cs +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System.Threading.Tasks; -using Microsoft.AspNetCore.Hosting.Server; - -namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 -{ - public class Http2Stream : Http2Stream - { - private readonly IHttpApplication _application; - - private TContext _httpContext; - - public Http2Stream(IHttpApplication application, Http2StreamContext context) - : base(context) - { - _application = application; - } - - protected override void CreateHttpContext() => _httpContext = _application.CreateContext(this); - - protected override void DisposeHttpContext() => _application.DisposeContext(_httpContext, _applicationException); - - protected override Task InvokeApplicationAsync() => _application.ProcessRequestAsync(_httpContext); - } -} diff --git a/src/Kestrel.Core/Internal/HttpConnection.cs b/src/Kestrel.Core/Internal/HttpConnection.cs index 2ecc65d253..81bf33f2dc 100644 --- a/src/Kestrel.Core/Internal/HttpConnection.cs +++ b/src/Kestrel.Core/Internal/HttpConnection.cs @@ -21,30 +21,29 @@ using Microsoft.Extensions.Logging; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal { - public class HttpConnection : ITimeoutControl, IConnectionTimeoutFeature + public class HttpConnection : ITimeoutControl, IConnectionTimeoutFeature, IRequestProcessor { - private const int Http2ConnectionNotStarted = 0; - private const int Http2ConnectionStarted = 1; - private const int Http2ConnectionClosed = 2; - private readonly HttpConnectionContext _context; - private IList _adaptedConnections; private readonly TaskCompletionSource _socketClosedTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + + private IList _adaptedConnections; + private IPipeConnection _adaptedTransport; + + private readonly object _protocolSelectionLock = new object(); + private IRequestProcessor _requestProcessor; private Http1Connection _http1Connection; - private Http2Connection _http2Connection; - private volatile int _http2ConnectionState; private long _lastTimestamp; private long _timeoutTimestamp = long.MaxValue; private TimeoutAction _timeoutAction; - private object _readTimingLock = new object(); + private readonly object _readTimingLock = new object(); private bool _readTimingEnabled; private bool _readTimingPauseRequested; private long _readTimingElapsedTicks; private long _readTimingBytesRead; - private object _writeTimingLock = new object(); + private readonly object _writeTimingLock = new object(); private int _writeTimingWrites; private long _writeTimingTimeoutTimestamp; @@ -53,6 +52,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal public HttpConnection(HttpConnectionContext context) { _context = context; + _requestProcessor = this; } // For testing @@ -102,35 +102,29 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal AdaptedPipeline adaptedPipeline = null; var adaptedPipelineTask = Task.CompletedTask; - var transport = _context.Transport; + + // _adaptedTransport must be set prior to adding the connection to the manager in order + // to allow the connection to be aported prior to protocol selection. + _adaptedTransport = _context.Transport; var application = _context.Application; if (_context.ConnectionAdapters.Count > 0) { - adaptedPipeline = new AdaptedPipeline(transport, + adaptedPipeline = new AdaptedPipeline(_adaptedTransport, application, new Pipe(AdaptedInputPipeOptions), new Pipe(AdaptedOutputPipeOptions)); - transport = adaptedPipeline; + _adaptedTransport = adaptedPipeline; } - // _http1Connection must be initialized before adding the connection to the connection manager - CreateHttp1Connection(httpApplication, transport, application); - - // _http2Connection must be initialized before yielding control to the transport thread, - // to prevent a race condition where _http2Connection.Abort() is called just as - // _http2Connection is about to be initialized. - CreateHttp2Connection(httpApplication, transport, application); - // Do this before the first await so we don't yield control to the transport until we've // added the connection to the connection manager _context.ServiceContext.ConnectionManager.AddConnection(_context.HttpConnectionId, this); _lastTimestamp = _context.ServiceContext.SystemClock.UtcNow.Ticks; - _http1Connection.ConnectionFeatures.Set(this); - _http2Connection.ConnectionFeatures.Set(this); + _context.ConnectionFeatures.Set(this); if (adaptedPipeline != null) { @@ -139,21 +133,41 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal adaptedPipelineTask = adaptedPipeline.RunAsync(stream); } - var protocol = SelectProtocol(); + IRequestProcessor requestProcessor = null; - if (protocol == HttpProtocols.None) + lock (_protocolSelectionLock) { - Abort(ex: null); + // Ensure that the connection hasn't already been stopped. + if (_requestProcessor == this) + { + switch (SelectProtocol()) + { + case HttpProtocols.Http1: + // _http1Connection must be initialized before adding the connection to the connection manager + requestProcessor = _http1Connection = CreateHttp1Connection(_adaptedTransport, application); + break; + case HttpProtocols.Http2: + // _http2Connection must be initialized before yielding control to the transport thread, + // to prevent a race condition where _http2Connection.Abort() is called just as + // _http2Connection is about to be initialized. + requestProcessor = CreateHttp2Connection(_adaptedTransport, application); + break; + case HttpProtocols.None: + // An error was already logged in SelectProtocol(), but we should close the connection. + Abort(ex: null); + break; + default: + // SelectProtocol() only returns Http1, Http2 or None. + throw new NotSupportedException($"{nameof(SelectProtocol)} returned something other than Http1, Http2 or None."); + } + + _requestProcessor = requestProcessor; + } } - // One of these has to run even if no protocol was selected so the abort propagates and everything completes properly - if (protocol == HttpProtocols.Http2 && Interlocked.CompareExchange(ref _http2ConnectionState, Http2ConnectionStarted, Http2ConnectionNotStarted) == Http2ConnectionNotStarted) + if (requestProcessor != null) { - await _http2Connection.ProcessAsync(httpApplication); - } - else - { - await _http1Connection.ProcessRequestsAsync(); + await requestProcessor.ProcessRequestsAsync(httpApplication); } await adaptedPipelineTask; @@ -161,14 +175,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal } catch (Exception ex) { - Log.LogError(0, ex, $"Unexpected exception in {nameof(HttpConnection)}.{nameof(ProcessRequestsAsync)}."); + Log.LogCritical(0, ex, $"Unexpected exception in {nameof(HttpConnection)}.{nameof(ProcessRequestsAsync)}."); } finally { _context.ServiceContext.ConnectionManager.RemoveConnection(_context.HttpConnectionId); DisposeAdaptedConnections(); - if (_http1Connection.IsUpgraded) + if (_http1Connection?.IsUpgraded == true) { _context.ServiceContext.ConnectionManager.UpgradedConnectionCount.ReleaseOne(); } @@ -177,9 +191,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal } } - internal void CreateHttp1Connection(IHttpApplication httpApplication, IPipeConnection transport, IPipeConnection application) + // For testing only + internal void Initialize(IPipeConnection transport, IPipeConnection application) { - _http1Connection = new Http1Connection(httpApplication, new Http1ConnectionContext + _requestProcessor = _http1Connection = CreateHttp1Connection(transport, application); + } + + private Http1Connection CreateHttp1Connection(IPipeConnection transport, IPipeConnection application) + { + return new Http1Connection(new Http1ConnectionContext { ConnectionId = _context.ConnectionId, ConnectionFeatures = _context.ConnectionFeatures, @@ -193,9 +213,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal }); } - internal void CreateHttp2Connection(IHttpApplication httpApplication, IPipeConnection transport, IPipeConnection application) + private Http2Connection CreateHttp2Connection(IPipeConnection transport, IPipeConnection application) { - _http2Connection = new Http2Connection(new Http2ConnectionContext + return new Http2Connection(new Http2ConnectionContext { ConnectionId = _context.ConnectionId, ServiceContext = _context.ServiceContext, @@ -217,16 +237,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal public Task StopProcessingNextRequestAsync() { - Debug.Assert(_http1Connection != null, $"{nameof(_http1Connection)} is null"); - Debug.Assert(_http2Connection != null, $"{nameof(_http2Connection)} is null"); - - if (Interlocked.Exchange(ref _http2ConnectionState, Http2ConnectionClosed) == Http2ConnectionStarted) + lock (_protocolSelectionLock) { - _http2Connection.Stop(); - } - else - { - _http1Connection.StopProcessingNextRequest(); + _requestProcessor?.StopProcessingNextRequest(); + _requestProcessor = null; } return _lifetimeTask; @@ -234,17 +248,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal public void Abort(Exception ex) { - Debug.Assert(_http1Connection != null, $"{nameof(_http1Connection)} is null"); - Debug.Assert(_http2Connection != null, $"{nameof(_http2Connection)} is null"); - - // Abort the connection (if not already aborted) - if (Interlocked.Exchange(ref _http2ConnectionState, Http2ConnectionClosed) == Http2ConnectionStarted) + lock (_protocolSelectionLock) { - _http2Connection.Abort(ex); - } - else - { - _http1Connection.Abort(ex); + _requestProcessor?.Abort(ex); + _requestProcessor = null; } } @@ -255,28 +262,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal return _lifetimeTask; } - public void SendTimeoutResponse() - { - Debug.Assert(_http1Connection != null, $"{nameof(_http1Connection)} is null"); - Debug.Assert(_http2Connection != null, $"{nameof(_http2Connection)} is null"); - - RequestTimedOut = true; - _http1Connection.SendTimeoutResponse(); - } - - public void StopProcessingNextRequest() - { - Debug.Assert(_http1Connection != null, $"{nameof(_http1Connection)} is null"); - Debug.Assert(_http2Connection != null, $"{nameof(_http2Connection)} is null"); - - _http1Connection.StopProcessingNextRequest(); - } - private async Task ApplyConnectionAdaptersAsync() { - Debug.Assert(_http1Connection != null, $"{nameof(_http1Connection)} is null"); - Debug.Assert(_http2Connection != null, $"{nameof(_http2Connection)} is null"); - var connectionAdapters = _context.ConnectionAdapters; var stream = new RawStream(_context.Transport.Input, _context.Transport.Output); var adapterContext = new ConnectionAdapterContext(_context.ConnectionFeatures, stream); @@ -348,14 +335,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal public void Tick(DateTimeOffset now) { - Debug.Assert(_http1Connection != null, $"{nameof(_http1Connection)} is null"); - Debug.Assert(_http2Connection != null, $"{nameof(_http2Connection)} is null"); - var timestamp = now.Ticks; CheckForTimeout(timestamp); - CheckForReadDataRateTimeout(timestamp); - CheckForWriteDataRateTimeout(timestamp); + + // HTTP/2 rate timeouts are not yet supported. + if (_http1Connection != null) + { + CheckForReadDataRateTimeout(timestamp); + CheckForWriteDataRateTimeout(timestamp); + } Interlocked.Exchange(ref _lastTimestamp, timestamp); } @@ -372,12 +361,19 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal switch (_timeoutAction) { case TimeoutAction.StopProcessingNextRequest: - StopProcessingNextRequest(); + // Http/2 keep-alive timeouts are not yet supported. + _http1Connection?.StopProcessingNextRequest(); break; case TimeoutAction.SendTimeoutResponse: - SendTimeoutResponse(); + // HTTP/2 timeout responses are not yet supported. + if (_http1Connection != null) + { + RequestTimedOut = true; + _http1Connection.SendTimeoutResponse(); + } break; case TimeoutAction.AbortConnection: + // This is actually supported with HTTP/2! Abort(new TimeoutException()); break; } @@ -387,6 +383,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal private void CheckForReadDataRateTimeout(long timestamp) { + Debug.Assert(_http1Connection != null); + // The only time when both a timeout is set and the read data rate could be enforced is // when draining the request body. Since there's already a (short) timeout set for draining, // it's safe to not check the data rate at this point. @@ -412,7 +410,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal if (rate < minRequestBodyDataRate.BytesPerSecond && !Debugger.IsAttached) { Log.RequestBodyMininumDataRateNotSatisfied(_context.ConnectionId, _http1Connection.TraceIdentifier, minRequestBodyDataRate.BytesPerSecond); - SendTimeoutResponse(); + RequestTimedOut = true; + _http1Connection.SendTimeoutResponse(); } } @@ -430,6 +429,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal private void CheckForWriteDataRateTimeout(long timestamp) { + Debug.Assert(_http1Connection != null); + lock (_writeTimingLock) { if (_writeTimingWrites > 0 && timestamp > _writeTimingTimeoutTimestamp && !Debugger.IsAttached) @@ -510,6 +511,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal public void StartTimingWrite(long size) { + Debug.Assert(_http1Connection != null); + lock (_writeTimingLock) { var minResponseDataRate = _http1Connection.MinResponseDataRate; @@ -563,5 +566,33 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal ResetTimeout(timeSpan.Ticks, TimeoutAction.AbortConnection); } + + private void CloseUninitializedConnection() + { + Debug.Assert(_adaptedTransport != null); + + // CancelPendingRead signals the transport directly to close the connection + // without any potential interference from connection adapters. + _context.Application.Input.CancelPendingRead(); + + _adaptedTransport.Input.Complete(); + _adaptedTransport.Output.Complete(); + } + + // These IStoppableConnection methods only get called if the server shuts down during initialization. + Task IRequestProcessor.ProcessRequestsAsync(IHttpApplication application) + { + throw new NotSupportedException(); + } + + void IRequestProcessor.StopProcessingNextRequest() + { + CloseUninitializedConnection(); + } + + void IRequestProcessor.Abort(Exception ex) + { + CloseUninitializedConnection(); + } } } diff --git a/src/Kestrel.Core/Internal/IRequestProcessor.cs b/src/Kestrel.Core/Internal/IRequestProcessor.cs new file mode 100644 index 0000000000..5b40735ac8 --- /dev/null +++ b/src/Kestrel.Core/Internal/IRequestProcessor.cs @@ -0,0 +1,16 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Hosting.Server; + +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal +{ + public interface IRequestProcessor + { + Task ProcessRequestsAsync(IHttpApplication application); + void StopProcessingNextRequest(); + void Abort(Exception ex); + } +} \ No newline at end of file diff --git a/test/Kestrel.Core.Tests/Http1ConnectionTests.cs b/test/Kestrel.Core.Tests/Http1ConnectionTests.cs index 0601a12763..1efca25551 100644 --- a/test/Kestrel.Core.Tests/Http1ConnectionTests.cs +++ b/test/Kestrel.Core.Tests/Http1ConnectionTests.cs @@ -11,7 +11,6 @@ using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; -using Microsoft.AspNetCore.Hosting.Server; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Server.Kestrel.Core.Features; @@ -30,7 +29,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests { private readonly IPipeConnection _transport; private readonly IPipeConnection _application; - private readonly TestHttp1Connection _http1Connection; + private readonly TestHttp1Connection _http1Connection; private readonly ServiceContext _serviceContext; private readonly Http1ConnectionContext _http1ConnectionContext; private readonly BufferPool _pipelineFactory; @@ -38,19 +37,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests private ReadCursor _examined; private Mock _timeoutControl; - private class TestHttp1Connection : Http1Connection - { - public TestHttp1Connection(IHttpApplication application, Http1ConnectionContext context) - : base(application, context) - { - } - - public Task ProduceEndAsync() - { - return ProduceEnd(); - } - } - public Http1ConnectionTests() { _pipelineFactory = new MemoryPool(); @@ -71,7 +57,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests Transport = pair.Transport }; - _http1Connection = new TestHttp1Connection(application: null, context: _http1ConnectionContext); + _http1Connection = new TestHttp1Connection(_http1ConnectionContext); _http1Connection.Reset(); } @@ -509,7 +495,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests [Fact] public void ProcessRequestsAsyncEnablesKeepAliveTimeout() { - var requestProcessingTask = _http1Connection.ProcessRequestsAsync(); + var requestProcessingTask = _http1Connection.ProcessRequestsAsync(null); var expectedKeepAliveTimeout = _serviceContext.ServerOptions.Limits.KeepAliveTimeout.Ticks; _timeoutControl.Verify(cc => cc.SetTimeout(expectedKeepAliveTimeout, TimeoutAction.StopProcessingNextRequest)); @@ -594,7 +580,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests [Fact] public async Task RequestProcessingTaskIsUnwrapped() { - var requestProcessingTask = _http1Connection.ProcessRequestsAsync(); + var requestProcessingTask = _http1Connection.ProcessRequestsAsync(null); var data = Encoding.ASCII.GetBytes("GET / HTTP/1.1\r\nHost:\r\n\r\n"); await _application.Output.WriteAsync(data); @@ -723,7 +709,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests var headers0 = MakeHeaders(header0Count); var headers1 = MakeHeaders(header1Count, header0Count); - var requestProcessingTask = _http1Connection.ProcessRequestsAsync(); + var requestProcessingTask = _http1Connection.ProcessRequestsAsync(null); await _application.Output.WriteAsync(Encoding.ASCII.GetBytes("GET / HTTP/1.0\r\n")); await WaitForCondition(TimeSpan.FromSeconds(1), () => _http1Connection.RequestHeaders != null); @@ -757,7 +743,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests var headers0 = MakeHeaders(header0Count); var headers1 = MakeHeaders(header1Count, header0Count); - var requestProcessingTask = _http1Connection.ProcessRequestsAsync(); + var requestProcessingTask = _http1Connection.ProcessRequestsAsync(null); await _application.Output.WriteAsync(Encoding.ASCII.GetBytes("GET / HTTP/1.0\r\n")); await WaitForCondition(TimeSpan.FromSeconds(1), () => _http1Connection.RequestHeaders != null); diff --git a/test/Kestrel.Core.Tests/Http2ConnectionTests.cs b/test/Kestrel.Core.Tests/Http2ConnectionTests.cs index 69a7807ab0..3f6d9a2a9c 100644 --- a/test/Kestrel.Core.Tests/Http2ConnectionTests.cs +++ b/test/Kestrel.Core.Tests/Http2ConnectionTests.cs @@ -1987,7 +1987,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests private async Task InitializeConnectionAsync(RequestDelegate application) { - _connectionTask = _connection.ProcessAsync(new DummyApplication(application)); + _connectionTask = _connection.ProcessRequestsAsync(new DummyApplication(application)); await SendPreambleAsync().ConfigureAwait(false); await SendSettingsAsync(); diff --git a/test/Kestrel.Core.Tests/HttpConnectionTests.cs b/test/Kestrel.Core.Tests/HttpConnectionTests.cs index 3a4e43cc44..dffd274f75 100644 --- a/test/Kestrel.Core.Tests/HttpConnectionTests.cs +++ b/test/Kestrel.Core.Tests/HttpConnectionTests.cs @@ -56,8 +56,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests var mockDebugger = new Mock(); mockDebugger.SetupGet(g => g.IsAttached).Returns(true); _httpConnection.Debugger = mockDebugger.Object; - _httpConnection.CreateHttp1Connection(new DummyApplication(), _httpConnectionContext.Transport, _httpConnectionContext.Application); - _httpConnection.CreateHttp2Connection(new DummyApplication(), _httpConnectionContext.Transport, _httpConnectionContext.Application); + _httpConnection.Initialize(_httpConnectionContext.Transport, _httpConnectionContext.Application); var now = DateTimeOffset.Now; _httpConnection.Tick(now); @@ -104,8 +103,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests _httpConnectionContext.ServiceContext.Log = logger; - _httpConnection.CreateHttp1Connection(new DummyApplication(), _httpConnectionContext.Transport, _httpConnectionContext.Application); - _httpConnection.CreateHttp2Connection(new DummyApplication(), _httpConnectionContext.Transport, _httpConnectionContext.Application); + _httpConnection.Initialize(_httpConnectionContext.Transport, _httpConnectionContext.Application); _httpConnection.Http1Connection.Reset(); // Initialize timestamp @@ -132,8 +130,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests var mockLogger = new Mock(); _httpConnectionContext.ServiceContext.Log = mockLogger.Object; - _httpConnection.CreateHttp1Connection(new DummyApplication(), _httpConnectionContext.Transport, _httpConnectionContext.Application); - _httpConnection.CreateHttp2Connection(new DummyApplication(), _httpConnectionContext.Transport, _httpConnectionContext.Application); + _httpConnection.Initialize(_httpConnectionContext.Transport, _httpConnectionContext.Application); _httpConnection.Http1Connection.Reset(); // Initialize timestamp @@ -175,8 +172,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests var mockLogger = new Mock(); _httpConnectionContext.ServiceContext.Log = mockLogger.Object; - _httpConnection.CreateHttp1Connection(new DummyApplication(), _httpConnectionContext.Transport, _httpConnectionContext.Application); - _httpConnection.CreateHttp2Connection(new DummyApplication(), _httpConnectionContext.Transport, _httpConnectionContext.Application); + _httpConnection.Initialize(_httpConnectionContext.Transport, _httpConnectionContext.Application); _httpConnection.Http1Connection.Reset(); // Initialize timestamp @@ -253,8 +249,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests var mockLogger = new Mock(); _httpConnectionContext.ServiceContext.Log = mockLogger.Object; - _httpConnection.CreateHttp1Connection(new DummyApplication(), _httpConnectionContext.Transport, _httpConnectionContext.Application); - _httpConnection.CreateHttp2Connection(new DummyApplication(), _httpConnectionContext.Transport, _httpConnectionContext.Application); + _httpConnection.Initialize(_httpConnectionContext.Transport, _httpConnectionContext.Application); _httpConnection.Http1Connection.Reset(); // Initialize timestamp @@ -322,8 +317,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests var mockLogger = new Mock(); _httpConnectionContext.ServiceContext.Log = mockLogger.Object; - _httpConnection.CreateHttp1Connection(new DummyApplication(), _httpConnectionContext.Transport, _httpConnectionContext.Application); - _httpConnection.CreateHttp2Connection(new DummyApplication(), _httpConnectionContext.Transport, _httpConnectionContext.Application); + _httpConnection.Initialize(_httpConnectionContext.Transport, _httpConnectionContext.Application); _httpConnection.Http1Connection.Reset(); // Initialize timestamp @@ -385,8 +379,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests var mockLogger = new Mock(); _httpConnectionContext.ServiceContext.Log = mockLogger.Object; - _httpConnection.CreateHttp1Connection(new DummyApplication(), _httpConnectionContext.Transport, _httpConnectionContext.Application); - _httpConnection.CreateHttp2Connection(new DummyApplication(), _httpConnectionContext.Transport, _httpConnectionContext.Application); + _httpConnection.Initialize(_httpConnectionContext.Transport, _httpConnectionContext.Application); _httpConnection.Http1Connection.Reset(); var startTime = systemClock.UtcNow; @@ -427,8 +420,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests var mockLogger = new Mock(); _httpConnectionContext.ServiceContext.Log = mockLogger.Object; - _httpConnection.CreateHttp1Connection(new DummyApplication(), _httpConnectionContext.Transport, _httpConnectionContext.Application); - _httpConnection.CreateHttp2Connection(new DummyApplication(), _httpConnectionContext.Transport, _httpConnectionContext.Application); + _httpConnection.Initialize(_httpConnectionContext.Transport, _httpConnectionContext.Application); _httpConnection.Http1Connection.Reset(); _httpConnection.Http1Connection.RequestAborted.Register(() => { @@ -462,8 +454,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests var mockLogger = new Mock(); _httpConnectionContext.ServiceContext.Log = mockLogger.Object; - _httpConnection.CreateHttp1Connection(new DummyApplication(), _httpConnectionContext.Transport, _httpConnectionContext.Application); - _httpConnection.CreateHttp2Connection(new DummyApplication(), _httpConnectionContext.Transport, _httpConnectionContext.Application); + _httpConnection.Initialize(_httpConnectionContext.Transport, _httpConnectionContext.Application); _httpConnection.Http1Connection.Reset(); _httpConnection.Http1Connection.RequestAborted.Register(() => { @@ -505,8 +496,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests var mockLogger = new Mock(); _httpConnectionContext.ServiceContext.Log = mockLogger.Object; - _httpConnection.CreateHttp1Connection(new DummyApplication(), _httpConnectionContext.Transport, _httpConnectionContext.Application); - _httpConnection.CreateHttp2Connection(new DummyApplication(), _httpConnectionContext.Transport, _httpConnectionContext.Application); + _httpConnection.Initialize(_httpConnectionContext.Transport, _httpConnectionContext.Application); _httpConnection.Http1Connection.Reset(); _httpConnection.Http1Connection.RequestAborted.Register(() => { diff --git a/test/Kestrel.Core.Tests/HttpResponseHeadersTests.cs b/test/Kestrel.Core.Tests/HttpResponseHeadersTests.cs index 46c28a3633..b98a47c8e5 100644 --- a/test/Kestrel.Core.Tests/HttpResponseHeadersTests.cs +++ b/test/Kestrel.Core.Tests/HttpResponseHeadersTests.cs @@ -33,7 +33,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests TimeoutControl = null }; - var http1Connection = new Http1Connection(application: null, context: http1ConnectionContext); + var http1Connection = new Http1Connection(http1ConnectionContext); http1Connection.Reset(); diff --git a/test/Kestrel.Core.Tests/TestInput.cs b/test/Kestrel.Core.Tests/TestInput.cs index e9c2cdf701..76276f3858 100644 --- a/test/Kestrel.Core.Tests/TestInput.cs +++ b/test/Kestrel.Core.Tests/TestInput.cs @@ -34,7 +34,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests TimeoutControl = Mock.Of() }; - Http1Connection = new Http1Connection(null, Http1ConnectionContext); + Http1Connection = new Http1Connection(Http1ConnectionContext); Http1Connection.HttpResponseControl = Mock.Of(); } diff --git a/test/Kestrel.Transport.Libuv.Tests/LibuvOutputConsumerTests.cs b/test/Kestrel.Transport.Libuv.Tests/LibuvOutputConsumerTests.cs index 54dd7ed013..da69f195ab 100644 --- a/test/Kestrel.Transport.Libuv.Tests/LibuvOutputConsumerTests.cs +++ b/test/Kestrel.Transport.Libuv.Tests/LibuvOutputConsumerTests.cs @@ -708,7 +708,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests var socket = new MockSocket(_mockLibuv, _libuvThread.Loop.ThreadId, transportContext.Log); var consumer = new LibuvOutputConsumer(pair.Application.Input, _libuvThread, socket, "0", transportContext.Log); - var http1Connection = new Http1Connection(null, new Http1ConnectionContext + var http1Connection = new Http1Connection(new Http1ConnectionContext { ServiceContext = serviceContext, ConnectionFeatures = new FeatureCollection(), diff --git a/test/shared/TestHttp1Connection.cs b/test/shared/TestHttp1Connection.cs index 8888a468be..d98f2e91e0 100644 --- a/test/shared/TestHttp1Connection.cs +++ b/test/shared/TestHttp1Connection.cs @@ -2,16 +2,14 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Threading.Tasks; -using Microsoft.AspNetCore.Hosting.Server; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; -using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; namespace Microsoft.AspNetCore.Testing { - public class TestHttp1Connection : Http1Connection + public class TestHttp1Connection : Http1Connection { - public TestHttp1Connection(IHttpApplication application, Http1ConnectionContext context) - : base(application, context) + public TestHttp1Connection(Http1ConnectionContext context) + : base(context) { } From edebfc1bb92fc69621047a3e180274283e825eb2 Mon Sep 17 00:00:00 2001 From: "ASP.NET CI" Date: Sun, 10 Dec 2017 13:01:47 -0800 Subject: [PATCH 1474/1662] Update dependencies.props [auto-updated: dependencies] --- build/dependencies.props | 52 ++++++++++++++++++++-------------------- korebuild-lock.txt | 4 ++-- 2 files changed, 28 insertions(+), 28 deletions(-) diff --git a/build/dependencies.props b/build/dependencies.props index 63cc2e08da..5deb3e804b 100644 --- a/build/dependencies.props +++ b/build/dependencies.props @@ -5,40 +5,40 @@ 0.10.9 - 2.1.0-preview1-15576 + 2.1.0-preview1-15618 1.10.0 - 2.1.0-preview1-27644 - 2.1.0-preview1-27644 - 2.1.0-preview1-27644 - 2.1.0-preview1-27644 - 2.1.0-preview1-27644 - 2.1.0-preview1-27644 - 2.1.0-preview1-27644 - 2.1.0-preview1-27644 - 2.1.0-preview1-27644 - 2.1.0-preview1-27644 - 2.1.0-preview1-27644 - 2.1.0-preview1-27644 - 2.1.0-preview1-27644 - 2.1.0-preview1-27644 + 2.1.0-preview1-27773 + 2.1.0-preview1-27773 + 2.1.0-preview1-27773 + 2.1.0-preview1-27773 + 2.1.0-preview1-27773 + 2.1.0-preview1-27773 + 2.1.0-preview1-27773 + 2.1.0-preview1-27773 + 2.1.0-preview1-27773 + 2.1.0-preview1-27773 + 2.1.0-preview1-27773 + 2.1.0-preview1-27773 + 2.1.0-preview1-27773 + 2.1.0-preview1-27773 2.0.0 - 2.1.0-preview1-25907-02 - 2.1.0-preview1-27644 + 2.1.0-preview1-25915-01 + 2.1.0-preview1-27773 15.3.0 4.7.49 10.0.1 - 4.4.0 + 4.5.0-preview1-25914-04 0.1.0-alpha-002 0.1.0-alpha-002 - 4.5.0-preview1-25902-08 - 4.5.0-preview1-25902-08 - 4.5.0-preview1-25902-08 - 4.4.0 + 4.5.0-preview1-25914-04 + 4.5.0-preview1-25914-04 + 4.5.0-preview1-25914-04 + 4.5.0-preview1-25914-04 0.1.0-alpha-002 - 4.4.0 - 0.7.0 - 2.3.0 - 2.3.0 + 4.5.0-preview2-25707-02 + 0.8.0 + 2.3.1 + 2.3.1 diff --git a/korebuild-lock.txt b/korebuild-lock.txt index 1a99066b7c..e7cce93009 100644 --- a/korebuild-lock.txt +++ b/korebuild-lock.txt @@ -1,2 +1,2 @@ -version:2.1.0-preview1-15576 -commithash:2f3856d2ba4f659fcb9253215b83946a06794a27 +version:2.1.0-preview1-15618 +commithash:00ce1383114015fe89b221146036e59e6bc11219 From 95dc8824c347ea1bc48ba0f582c6ccf83c08c1bc Mon Sep 17 00:00:00 2001 From: BrennanConroy Date: Mon, 11 Dec 2017 09:02:37 -0800 Subject: [PATCH 1475/1662] Upgrade package references and react to corefx API changes (#2212) --- ...Http1ConnectionParsingOverheadBenchmark.cs | 6 ++-- .../Http1WritingBenchmark.cs | 2 +- .../HttpProtocolFeatureCollection.cs | 6 ++-- .../PipeThroughputBenchmark.cs | 6 ++-- .../RequestParsingBenchmark.cs | 8 +++--- .../ResponseHeaderCollectionBenchmark.cs | 6 ++-- .../ResponseHeadersWritingBenchmark.cs | 6 ++-- build/dependencies.props | 22 +++++++-------- korebuild-lock.txt | 4 +-- .../Internal/ConnectionHandler.cs | 12 ++++---- .../Internal/Http/Http1ConnectionContext.cs | 2 +- .../Internal/Http/HttpProtocol.cs | 2 +- .../Internal/Http/IHttpProtocolContext.cs | 2 +- .../Internal/Http2/Http2Connection.cs | 2 +- .../Internal/Http2/Http2ConnectionContext.cs | 2 +- .../Internal/Http2/Http2StreamContext.cs | 2 +- src/Kestrel.Core/Internal/HttpConnection.cs | 10 +++---- .../Internal/HttpConnectionContext.cs | 2 +- .../Internal/HttpConnectionMiddleware.cs | 2 +- .../Internal/TransportConnection.Features.cs | 2 +- .../Internal/TransportConnection.cs | 2 +- .../Internal/LibuvConnectionContext.cs | 2 +- .../Internal/LibuvThread.cs | 6 ++-- .../Internal/SocketConnection.cs | 8 +++--- .../Internal/SocketSender.cs | 4 +++ .../SocketTransport.cs | 6 ++-- .../ConnectionContext.cs | 2 +- .../DefaultConnectionContext.cs | 2 +- .../Features/IConnectionTransportFeature.cs | 2 +- .../PipeFactoryExtensions.cs | 2 +- .../ConnectionHandlerTests.cs | 2 +- .../Http1ConnectionTests.cs | 4 +-- .../Http2ConnectionTests.cs | 8 +++--- .../Kestrel.Core.Tests/HttpConnectionTests.cs | 10 +++---- .../HttpResponseHeadersTests.cs | 2 +- .../Kestrel.Core.Tests/OutputProducerTests.cs | 8 +++--- .../PipelineExtensionTests.cs | 6 ++-- test/Kestrel.Core.Tests/TestInput.cs | 2 +- .../LibuvConnectionTests.cs | 8 +++--- .../LibuvOutputConsumerTests.cs | 28 +++++++++---------- .../TestHelpers/MockConnectionHandler.cs | 9 +++--- 41 files changed, 116 insertions(+), 113 deletions(-) diff --git a/benchmarks/Kestrel.Performance/Http1ConnectionParsingOverheadBenchmark.cs b/benchmarks/Kestrel.Performance/Http1ConnectionParsingOverheadBenchmark.cs index 42e4cba170..5b2af1d52a 100644 --- a/benchmarks/Kestrel.Performance/Http1ConnectionParsingOverheadBenchmark.cs +++ b/benchmarks/Kestrel.Performance/Http1ConnectionParsingOverheadBenchmark.cs @@ -23,8 +23,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance [IterationSetup] public void Setup() { - var bufferPool = new MemoryPool(); - var pair = PipeFactory.CreateConnectionPair(bufferPool); + var memoryPool = new MemoryPool(); + var pair = PipeFactory.CreateConnectionPair(memoryPool); var serviceContext = new ServiceContext { @@ -36,7 +36,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance { ServiceContext = serviceContext, ConnectionFeatures = new FeatureCollection(), - BufferPool = bufferPool, + MemoryPool = memoryPool, TimeoutControl = new MockTimeoutControl(), Application = pair.Application, Transport = pair.Transport diff --git a/benchmarks/Kestrel.Performance/Http1WritingBenchmark.cs b/benchmarks/Kestrel.Performance/Http1WritingBenchmark.cs index 717009affa..fcc3f86bc4 100644 --- a/benchmarks/Kestrel.Performance/Http1WritingBenchmark.cs +++ b/benchmarks/Kestrel.Performance/Http1WritingBenchmark.cs @@ -111,7 +111,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance { ServiceContext = serviceContext, ConnectionFeatures = new FeatureCollection(), - BufferPool = memoryPool, + MemoryPool = memoryPool, Application = pair.Application, Transport = pair.Transport }); diff --git a/benchmarks/Kestrel.Performance/HttpProtocolFeatureCollection.cs b/benchmarks/Kestrel.Performance/HttpProtocolFeatureCollection.cs index b9cc8b27c4..b5ebc8531e 100644 --- a/benchmarks/Kestrel.Performance/HttpProtocolFeatureCollection.cs +++ b/benchmarks/Kestrel.Performance/HttpProtocolFeatureCollection.cs @@ -78,8 +78,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance public HttpProtocolFeatureCollection() { - var bufferPool = new MemoryPool(); - var pair = PipeFactory.CreateConnectionPair(bufferPool); + var memoryPool = new MemoryPool(); + var pair = PipeFactory.CreateConnectionPair(memoryPool); var serviceContext = new ServiceContext { @@ -93,7 +93,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance { ServiceContext = serviceContext, ConnectionFeatures = new FeatureCollection(), - BufferPool = bufferPool, + MemoryPool = memoryPool, Application = pair.Application, Transport = pair.Transport }); diff --git a/benchmarks/Kestrel.Performance/PipeThroughputBenchmark.cs b/benchmarks/Kestrel.Performance/PipeThroughputBenchmark.cs index 973a63708d..92b04887f3 100644 --- a/benchmarks/Kestrel.Performance/PipeThroughputBenchmark.cs +++ b/benchmarks/Kestrel.Performance/PipeThroughputBenchmark.cs @@ -15,13 +15,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance private const int InnerLoopCount = 512; private IPipe _pipe; - private BufferPool _bufferPool; + private MemoryPool _memoryPool; [IterationSetup] public void Setup() { - _bufferPool = new MemoryPool(); - _pipe = new Pipe(new PipeOptions(_bufferPool)); + _memoryPool = new MemoryPool(); + _pipe = new Pipe(new PipeOptions(_memoryPool)); } [Benchmark(OperationsPerInvoke = InnerLoopCount)] diff --git a/benchmarks/Kestrel.Performance/RequestParsingBenchmark.cs b/benchmarks/Kestrel.Performance/RequestParsingBenchmark.cs index 52b0bdca68..c7b74bf7d5 100644 --- a/benchmarks/Kestrel.Performance/RequestParsingBenchmark.cs +++ b/benchmarks/Kestrel.Performance/RequestParsingBenchmark.cs @@ -22,8 +22,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance [IterationSetup] public void Setup() { - var bufferPool = new MemoryPool(); - var pair = PipeFactory.CreateConnectionPair(bufferPool); + var memoryPool = new MemoryPool(); + var pair = PipeFactory.CreateConnectionPair(memoryPool); var serviceContext = new ServiceContext { @@ -37,7 +37,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance { ServiceContext = serviceContext, ConnectionFeatures = new FeatureCollection(), - BufferPool = bufferPool, + MemoryPool = memoryPool, Application = pair.Application, Transport = pair.Transport, TimeoutControl = new MockTimeoutControl() @@ -46,7 +46,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance http1Connection.Reset(); Http1Connection = http1Connection; - Pipe = new Pipe(new PipeOptions(bufferPool)); + Pipe = new Pipe(new PipeOptions(memoryPool)); } [Benchmark(Baseline = true, OperationsPerInvoke = RequestParsingData.InnerLoopCount)] diff --git a/benchmarks/Kestrel.Performance/ResponseHeaderCollectionBenchmark.cs b/benchmarks/Kestrel.Performance/ResponseHeaderCollectionBenchmark.cs index 664567cd88..1e49ec53f2 100644 --- a/benchmarks/Kestrel.Performance/ResponseHeaderCollectionBenchmark.cs +++ b/benchmarks/Kestrel.Performance/ResponseHeaderCollectionBenchmark.cs @@ -171,8 +171,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance [IterationSetup] public void Setup() { - var bufferPool = new MemoryPool(); - var pair = PipeFactory.CreateConnectionPair(bufferPool); + var memoryPool = new MemoryPool(); + var pair = PipeFactory.CreateConnectionPair(memoryPool); var serviceContext = new ServiceContext { @@ -186,7 +186,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance { ServiceContext = serviceContext, ConnectionFeatures = new FeatureCollection(), - BufferPool = bufferPool, + MemoryPool = memoryPool, Application = pair.Application, Transport = pair.Transport }); diff --git a/benchmarks/Kestrel.Performance/ResponseHeadersWritingBenchmark.cs b/benchmarks/Kestrel.Performance/ResponseHeadersWritingBenchmark.cs index e56c7112e5..024fd1ae1c 100644 --- a/benchmarks/Kestrel.Performance/ResponseHeadersWritingBenchmark.cs +++ b/benchmarks/Kestrel.Performance/ResponseHeadersWritingBenchmark.cs @@ -111,8 +111,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance [IterationSetup] public void Setup() { - var bufferPool = new MemoryPool(); - var pair = PipeFactory.CreateConnectionPair(bufferPool); + var memoryPool = new MemoryPool(); + var pair = PipeFactory.CreateConnectionPair(memoryPool); var serviceContext = new ServiceContext { @@ -126,7 +126,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance { ServiceContext = serviceContext, ConnectionFeatures = new FeatureCollection(), - BufferPool = bufferPool, + MemoryPool = memoryPool, TimeoutControl = new MockTimeoutControl(), Application = pair.Application, Transport = pair.Transport diff --git a/build/dependencies.props b/build/dependencies.props index 5deb3e804b..0ed82b9623 100644 --- a/build/dependencies.props +++ b/build/dependencies.props @@ -5,7 +5,7 @@ 0.10.9 - 2.1.0-preview1-15618 + 2.1.0-preview1-15620 1.10.0 2.1.0-preview1-27773 2.1.0-preview1-27773 @@ -22,20 +22,20 @@ 2.1.0-preview1-27773 2.1.0-preview1-27773 2.0.0 - 2.1.0-preview1-25915-01 + 2.1.0-preview1-26008-01 2.1.0-preview1-27773 15.3.0 4.7.49 10.0.1 - 4.5.0-preview1-25914-04 - 0.1.0-alpha-002 - 0.1.0-alpha-002 - 4.5.0-preview1-25914-04 - 4.5.0-preview1-25914-04 - 4.5.0-preview1-25914-04 - 4.5.0-preview1-25914-04 - 0.1.0-alpha-002 - 4.5.0-preview2-25707-02 + 4.5.0-preview1-26006-06 + 0.1.0-e171206-2 + 0.1.0-e171206-2 + 4.5.0-preview1-26006-06 + 4.5.0-preview1-26006-06 + 4.5.0-preview1-26006-06 + 4.5.0-preview1-26006-06 + 0.1.0-e171206-2 + 4.5.0-preview1-26006-06 0.8.0 2.3.1 2.3.1 diff --git a/korebuild-lock.txt b/korebuild-lock.txt index e7cce93009..fe4a961da3 100644 --- a/korebuild-lock.txt +++ b/korebuild-lock.txt @@ -1,2 +1,2 @@ -version:2.1.0-preview1-15618 -commithash:00ce1383114015fe89b221146036e59e6bc11219 +version:2.1.0-preview1-15620 +commithash:6432b49a2c00310416df39b6fe548ef4af9c6011 diff --git a/src/Kestrel.Core/Internal/ConnectionHandler.cs b/src/Kestrel.Core/Internal/ConnectionHandler.cs index fd9dc68746..ee49a5b239 100644 --- a/src/Kestrel.Core/Internal/ConnectionHandler.cs +++ b/src/Kestrel.Core/Internal/ConnectionHandler.cs @@ -36,8 +36,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal // REVIEW: Unfortunately, we still need to use the service context to create the pipes since the settings // for the scheduler and limits are specified here - var inputOptions = GetInputPipeOptions(_serviceContext, connectionContext.BufferPool, transportFeature.InputWriterScheduler); - var outputOptions = GetOutputPipeOptions(_serviceContext, connectionContext.BufferPool, transportFeature.OutputReaderScheduler); + var inputOptions = GetInputPipeOptions(_serviceContext, connectionContext.MemoryPool, transportFeature.InputWriterScheduler); + var outputOptions = GetOutputPipeOptions(_serviceContext, connectionContext.MemoryPool, transportFeature.OutputReaderScheduler); var pair = PipeFactory.CreateConnectionPair(inputOptions, outputOptions); @@ -83,18 +83,18 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal } // Internal for testing - internal static PipeOptions GetInputPipeOptions(ServiceContext serviceContext, BufferPool bufferPool, IScheduler writerScheduler) => new PipeOptions + internal static PipeOptions GetInputPipeOptions(ServiceContext serviceContext, MemoryPool memoryPool, IScheduler writerScheduler) => new PipeOptions ( - bufferPool: bufferPool, + pool: memoryPool, readerScheduler: serviceContext.ThreadPool, writerScheduler: writerScheduler, maximumSizeHigh: serviceContext.ServerOptions.Limits.MaxRequestBufferSize ?? 0, maximumSizeLow: serviceContext.ServerOptions.Limits.MaxRequestBufferSize ?? 0 ); - internal static PipeOptions GetOutputPipeOptions(ServiceContext serviceContext, BufferPool bufferPool, IScheduler readerScheduler) => new PipeOptions + internal static PipeOptions GetOutputPipeOptions(ServiceContext serviceContext, MemoryPool memoryPool, IScheduler readerScheduler) => new PipeOptions ( - bufferPool: bufferPool, + pool: memoryPool, readerScheduler: readerScheduler, writerScheduler: serviceContext.ThreadPool, maximumSizeHigh: GetOutputResponseBufferSize(serviceContext), diff --git a/src/Kestrel.Core/Internal/Http/Http1ConnectionContext.cs b/src/Kestrel.Core/Internal/Http/Http1ConnectionContext.cs index de529ea372..b30be13924 100644 --- a/src/Kestrel.Core/Internal/Http/Http1ConnectionContext.cs +++ b/src/Kestrel.Core/Internal/Http/Http1ConnectionContext.cs @@ -15,7 +15,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http public string ConnectionId { get; set; } public ServiceContext ServiceContext { get; set; } public IFeatureCollection ConnectionFeatures { get; set; } - public BufferPool BufferPool { get; set; } + public MemoryPool MemoryPool { get; set; } public IPEndPoint RemoteEndPoint { get; set; } public IPEndPoint LocalEndPoint { get; set; } public ITimeoutControl TimeoutControl { get; set; } diff --git a/src/Kestrel.Core/Internal/Http/HttpProtocol.cs b/src/Kestrel.Core/Internal/Http/HttpProtocol.cs index dacd5313f4..fca679dd23 100644 --- a/src/Kestrel.Core/Internal/Http/HttpProtocol.cs +++ b/src/Kestrel.Core/Internal/Http/HttpProtocol.cs @@ -1300,7 +1300,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http private Pipe CreateRequestBodyPipe() => new Pipe(new PipeOptions ( - bufferPool: _context.BufferPool, + pool: _context.MemoryPool, readerScheduler: ServiceContext.ThreadPool, writerScheduler: InlineScheduler.Default, maximumSizeHigh: 1, diff --git a/src/Kestrel.Core/Internal/Http/IHttpProtocolContext.cs b/src/Kestrel.Core/Internal/Http/IHttpProtocolContext.cs index 44abe5160f..392dcf1833 100644 --- a/src/Kestrel.Core/Internal/Http/IHttpProtocolContext.cs +++ b/src/Kestrel.Core/Internal/Http/IHttpProtocolContext.cs @@ -13,7 +13,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http string ConnectionId { get; set; } ServiceContext ServiceContext { get; set; } IFeatureCollection ConnectionFeatures { get; set; } - BufferPool BufferPool { get; set; } + MemoryPool MemoryPool { get; set; } IPEndPoint RemoteEndPoint { get; set; } IPEndPoint LocalEndPoint { get; set; } } diff --git a/src/Kestrel.Core/Internal/Http2/Http2Connection.cs b/src/Kestrel.Core/Internal/Http2/Http2Connection.cs index 9d6ac80794..db71ff63c9 100644 --- a/src/Kestrel.Core/Internal/Http2/Http2Connection.cs +++ b/src/Kestrel.Core/Internal/Http2/Http2Connection.cs @@ -398,7 +398,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 StreamId = _incomingFrame.StreamId, ServiceContext = _context.ServiceContext, ConnectionFeatures = _context.ConnectionFeatures, - BufferPool = _context.BufferPool, + MemoryPool = _context.MemoryPool, LocalEndPoint = _context.LocalEndPoint, RemoteEndPoint = _context.RemoteEndPoint, StreamLifetimeHandler = this, diff --git a/src/Kestrel.Core/Internal/Http2/Http2ConnectionContext.cs b/src/Kestrel.Core/Internal/Http2/Http2ConnectionContext.cs index c4766a7b15..929bef9f92 100644 --- a/src/Kestrel.Core/Internal/Http2/Http2ConnectionContext.cs +++ b/src/Kestrel.Core/Internal/Http2/Http2ConnectionContext.cs @@ -13,7 +13,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 public string ConnectionId { get; set; } public ServiceContext ServiceContext { get; set; } public IFeatureCollection ConnectionFeatures { get; set; } - public BufferPool BufferPool { get; set; } + public MemoryPool MemoryPool { get; set; } public IPEndPoint LocalEndPoint { get; set; } public IPEndPoint RemoteEndPoint { get; set; } diff --git a/src/Kestrel.Core/Internal/Http2/Http2StreamContext.cs b/src/Kestrel.Core/Internal/Http2/Http2StreamContext.cs index 6bc9fc8b82..247e1764a7 100644 --- a/src/Kestrel.Core/Internal/Http2/Http2StreamContext.cs +++ b/src/Kestrel.Core/Internal/Http2/Http2StreamContext.cs @@ -15,7 +15,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 public int StreamId { get; set; } public ServiceContext ServiceContext { get; set; } public IFeatureCollection ConnectionFeatures { get; set; } - public BufferPool BufferPool { get; set; } + public MemoryPool MemoryPool { get; set; } public IPEndPoint RemoteEndPoint { get; set; } public IPEndPoint LocalEndPoint { get; set; } public IHttp2StreamLifetimeHandler StreamLifetimeHandler { get; set; } diff --git a/src/Kestrel.Core/Internal/HttpConnection.cs b/src/Kestrel.Core/Internal/HttpConnection.cs index 81bf33f2dc..44f0fcbd1a 100644 --- a/src/Kestrel.Core/Internal/HttpConnection.cs +++ b/src/Kestrel.Core/Internal/HttpConnection.cs @@ -66,12 +66,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal public IPEndPoint LocalEndPoint => _context.LocalEndPoint; public IPEndPoint RemoteEndPoint => _context.RemoteEndPoint; - private BufferPool BufferPool => _context.BufferPool; + private MemoryPool MemoryPool => _context.MemoryPool; // Internal for testing internal PipeOptions AdaptedInputPipeOptions => new PipeOptions ( - bufferPool: BufferPool, + pool: MemoryPool, readerScheduler: _context.ServiceContext.ThreadPool, writerScheduler: InlineScheduler.Default, maximumSizeHigh: _context.ServiceContext.ServerOptions.Limits.MaxRequestBufferSize ?? 0, @@ -80,7 +80,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal internal PipeOptions AdaptedOutputPipeOptions => new PipeOptions ( - bufferPool: BufferPool, + pool: MemoryPool, readerScheduler: InlineScheduler.Default, writerScheduler: InlineScheduler.Default, maximumSizeHigh: _context.ServiceContext.ServerOptions.Limits.MaxResponseBufferSize ?? 0, @@ -203,7 +203,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal { ConnectionId = _context.ConnectionId, ConnectionFeatures = _context.ConnectionFeatures, - BufferPool = BufferPool, + MemoryPool = MemoryPool, LocalEndPoint = LocalEndPoint, RemoteEndPoint = RemoteEndPoint, ServiceContext = _context.ServiceContext, @@ -220,7 +220,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal ConnectionId = _context.ConnectionId, ServiceContext = _context.ServiceContext, ConnectionFeatures = _context.ConnectionFeatures, - BufferPool = BufferPool, + MemoryPool = MemoryPool, LocalEndPoint = LocalEndPoint, RemoteEndPoint = RemoteEndPoint, Application = application, diff --git a/src/Kestrel.Core/Internal/HttpConnectionContext.cs b/src/Kestrel.Core/Internal/HttpConnectionContext.cs index c2862b170b..dcd5563e79 100644 --- a/src/Kestrel.Core/Internal/HttpConnectionContext.cs +++ b/src/Kestrel.Core/Internal/HttpConnectionContext.cs @@ -18,7 +18,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal public ServiceContext ServiceContext { get; set; } public IFeatureCollection ConnectionFeatures { get; set; } public IList ConnectionAdapters { get; set; } - public BufferPool BufferPool { get; set; } + public MemoryPool MemoryPool { get; set; } public IPEndPoint LocalEndPoint { get; set; } public IPEndPoint RemoteEndPoint { get; set; } public IPipeConnection Transport { get; set; } diff --git a/src/Kestrel.Core/Internal/HttpConnectionMiddleware.cs b/src/Kestrel.Core/Internal/HttpConnectionMiddleware.cs index e6686cfd7c..8018438fa4 100644 --- a/src/Kestrel.Core/Internal/HttpConnectionMiddleware.cs +++ b/src/Kestrel.Core/Internal/HttpConnectionMiddleware.cs @@ -50,7 +50,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal Protocols = _protocols, ServiceContext = _serviceContext, ConnectionFeatures = connectionContext.Features, - BufferPool = connectionContext.BufferPool, + MemoryPool = connectionContext.MemoryPool, ConnectionAdapters = _connectionAdapters, Transport = connectionContext.Transport, Application = transportFeature.Application diff --git a/src/Kestrel.Transport.Abstractions/Internal/TransportConnection.Features.cs b/src/Kestrel.Transport.Abstractions/Internal/TransportConnection.Features.cs index 7da585aeec..5af87f3293 100644 --- a/src/Kestrel.Transport.Abstractions/Internal/TransportConnection.Features.cs +++ b/src/Kestrel.Transport.Abstractions/Internal/TransportConnection.Features.cs @@ -96,7 +96,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal set => LocalPort = value; } - BufferPool IConnectionTransportFeature.BufferPool => BufferPool; + MemoryPool IConnectionTransportFeature.MemoryPool => MemoryPool; IPipeConnection IConnectionTransportFeature.Transport { diff --git a/src/Kestrel.Transport.Abstractions/Internal/TransportConnection.cs b/src/Kestrel.Transport.Abstractions/Internal/TransportConnection.cs index df8247aa09..dc1af6ec56 100644 --- a/src/Kestrel.Transport.Abstractions/Internal/TransportConnection.cs +++ b/src/Kestrel.Transport.Abstractions/Internal/TransportConnection.cs @@ -22,7 +22,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal public string ConnectionId { get; set; } - public virtual BufferPool BufferPool { get; } + public virtual MemoryPool MemoryPool { get; } public virtual IScheduler InputWriterScheduler { get; } public virtual IScheduler OutputReaderScheduler { get; } diff --git a/src/Kestrel.Transport.Libuv/Internal/LibuvConnectionContext.cs b/src/Kestrel.Transport.Libuv/Internal/LibuvConnectionContext.cs index 2f052becab..dde6aa5f30 100644 --- a/src/Kestrel.Transport.Libuv/Internal/LibuvConnectionContext.cs +++ b/src/Kestrel.Transport.Libuv/Internal/LibuvConnectionContext.cs @@ -18,7 +18,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal public ListenerContext ListenerContext { get; set; } - public override BufferPool BufferPool => ListenerContext.Thread.BufferPool; + public override MemoryPool MemoryPool => ListenerContext.Thread.MemoryPool; public override IScheduler InputWriterScheduler => ListenerContext.Thread; public override IScheduler OutputReaderScheduler => ListenerContext.Thread; } diff --git a/src/Kestrel.Transport.Libuv/Internal/LibuvThread.cs b/src/Kestrel.Transport.Libuv/Internal/LibuvThread.cs index acab590fdc..ca9edc7445 100644 --- a/src/Kestrel.Transport.Libuv/Internal/LibuvThread.cs +++ b/src/Kestrel.Transport.Libuv/Internal/LibuvThread.cs @@ -56,7 +56,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal #endif QueueCloseHandle = PostCloseHandle; QueueCloseAsyncHandle = EnqueueCloseHandle; - BufferPool = new MemoryPool(); + MemoryPool = new MemoryPool(); WriteReqPool = new WriteReqPool(this, _log); } @@ -69,7 +69,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal public UvLoopHandle Loop { get { return _loop; } } - public BufferPool BufferPool { get; } + public MemoryPool MemoryPool { get; } public WriteReqPool WriteReqPool { get; } @@ -296,7 +296,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal } finally { - BufferPool.Dispose(); + MemoryPool.Dispose(); WriteReqPool.Dispose(); _threadTcs.SetResult(null); diff --git a/src/Kestrel.Transport.Sockets/Internal/SocketConnection.cs b/src/Kestrel.Transport.Sockets/Internal/SocketConnection.cs index 27f5807a1b..d74159792e 100644 --- a/src/Kestrel.Transport.Sockets/Internal/SocketConnection.cs +++ b/src/Kestrel.Transport.Sockets/Internal/SocketConnection.cs @@ -28,14 +28,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal private volatile bool _aborted; - internal SocketConnection(Socket socket, BufferPool bufferPool, ISocketsTrace trace) + internal SocketConnection(Socket socket, MemoryPool memoryPool, ISocketsTrace trace) { Debug.Assert(socket != null); - Debug.Assert(bufferPool != null); + Debug.Assert(memoryPool != null); Debug.Assert(trace != null); _socket = socket; - BufferPool = bufferPool; + MemoryPool = memoryPool; _trace = trace; var localEndPoint = (IPEndPoint)_socket.LocalEndPoint; @@ -51,7 +51,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal _sender = new SocketSender(_socket); } - public override BufferPool BufferPool { get; } + public override MemoryPool MemoryPool { get; } public override IScheduler InputWriterScheduler => InlineScheduler.Default; public override IScheduler OutputReaderScheduler => TaskRunScheduler.Default; diff --git a/src/Kestrel.Transport.Sockets/Internal/SocketSender.cs b/src/Kestrel.Transport.Sockets/Internal/SocketSender.cs index 688704811c..f871dc7021 100644 --- a/src/Kestrel.Transport.Sockets/Internal/SocketSender.cs +++ b/src/Kestrel.Transport.Sockets/Internal/SocketSender.cs @@ -31,7 +31,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal return SendAsync(buffers.First); } +#if NETCOREAPP2_1 + if (!_eventArgs.MemoryBuffer.Equals(Memory.Empty)) +#else if (_eventArgs.Buffer != null) +#endif { _eventArgs.SetBuffer(null, 0, 0); } diff --git a/src/Kestrel.Transport.Sockets/SocketTransport.cs b/src/Kestrel.Transport.Sockets/SocketTransport.cs index d4f056829f..6cec602c36 100644 --- a/src/Kestrel.Transport.Sockets/SocketTransport.cs +++ b/src/Kestrel.Transport.Sockets/SocketTransport.cs @@ -20,7 +20,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets { internal sealed class SocketTransport : ITransport { - private readonly BufferPool _bufferPool = new MemoryPool(); + private readonly MemoryPool _memoryPool = new MemoryPool(); private readonly IEndPointInformation _endPointInformation; private readonly IConnectionHandler _handler; private readonly IApplicationLifetime _appLifetime; @@ -116,7 +116,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets public Task StopAsync() { - _bufferPool.Dispose(); + _memoryPool.Dispose(); return Task.CompletedTask; } @@ -131,7 +131,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets var acceptSocket = await _listenSocket.AcceptAsync(); acceptSocket.NoDelay = _endPointInformation.NoDelay; - var connection = new SocketConnection(acceptSocket, _bufferPool, _trace); + var connection = new SocketConnection(acceptSocket, _memoryPool, _trace); _ = connection.StartAsync(_handler); } catch (SocketException ex) when (ex.SocketErrorCode == SocketError.ConnectionReset) diff --git a/src/Protocols.Abstractions/ConnectionContext.cs b/src/Protocols.Abstractions/ConnectionContext.cs index 586a2ae19b..afe2149576 100644 --- a/src/Protocols.Abstractions/ConnectionContext.cs +++ b/src/Protocols.Abstractions/ConnectionContext.cs @@ -15,6 +15,6 @@ namespace Microsoft.AspNetCore.Protocols public abstract IPipeConnection Transport { get; set; } - public abstract BufferPool BufferPool { get; } + public abstract MemoryPool MemoryPool { get; } } } diff --git a/src/Protocols.Abstractions/DefaultConnectionContext.cs b/src/Protocols.Abstractions/DefaultConnectionContext.cs index 0c34637735..047ed92eab 100644 --- a/src/Protocols.Abstractions/DefaultConnectionContext.cs +++ b/src/Protocols.Abstractions/DefaultConnectionContext.cs @@ -28,7 +28,7 @@ namespace Microsoft.AspNetCore.Protocols public override IFeatureCollection Features => _features.Collection; - public override BufferPool BufferPool => ConnectionTransportFeature.BufferPool; + public override MemoryPool MemoryPool => ConnectionTransportFeature.MemoryPool; public override IPipeConnection Transport { diff --git a/src/Protocols.Abstractions/Features/IConnectionTransportFeature.cs b/src/Protocols.Abstractions/Features/IConnectionTransportFeature.cs index 3fc8d86224..9a090437e8 100644 --- a/src/Protocols.Abstractions/Features/IConnectionTransportFeature.cs +++ b/src/Protocols.Abstractions/Features/IConnectionTransportFeature.cs @@ -6,7 +6,7 @@ namespace Microsoft.AspNetCore.Protocols.Features { public interface IConnectionTransportFeature { - BufferPool BufferPool { get; } + MemoryPool MemoryPool { get; } IPipeConnection Transport { get; set; } diff --git a/src/Protocols.Abstractions/PipeFactoryExtensions.cs b/src/Protocols.Abstractions/PipeFactoryExtensions.cs index f28207db59..e6b11e5654 100644 --- a/src/Protocols.Abstractions/PipeFactoryExtensions.cs +++ b/src/Protocols.Abstractions/PipeFactoryExtensions.cs @@ -4,7 +4,7 @@ namespace System.IO.Pipelines { public static class PipeFactory { - public static (IPipeConnection Transport, IPipeConnection Application) CreateConnectionPair(BufferPool memoryPool) + public static (IPipeConnection Transport, IPipeConnection Application) CreateConnectionPair(MemoryPool memoryPool) { return CreateConnectionPair(new PipeOptions(memoryPool), new PipeOptions(memoryPool)); } diff --git a/test/Kestrel.Core.Tests/ConnectionHandlerTests.cs b/test/Kestrel.Core.Tests/ConnectionHandlerTests.cs index e1ff59b297..5c7afd17f0 100644 --- a/test/Kestrel.Core.Tests/ConnectionHandlerTests.cs +++ b/test/Kestrel.Core.Tests/ConnectionHandlerTests.cs @@ -53,7 +53,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests Set(this); } - public BufferPool BufferPool { get; } = new MemoryPool(); + public MemoryPool MemoryPool { get; } = new MemoryPool(); public IPipeConnection Transport { get; set; } public IPipeConnection Application { get; set; } diff --git a/test/Kestrel.Core.Tests/Http1ConnectionTests.cs b/test/Kestrel.Core.Tests/Http1ConnectionTests.cs index 1efca25551..934bd31257 100644 --- a/test/Kestrel.Core.Tests/Http1ConnectionTests.cs +++ b/test/Kestrel.Core.Tests/Http1ConnectionTests.cs @@ -32,7 +32,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests private readonly TestHttp1Connection _http1Connection; private readonly ServiceContext _serviceContext; private readonly Http1ConnectionContext _http1ConnectionContext; - private readonly BufferPool _pipelineFactory; + private readonly MemoryPool _pipelineFactory; private ReadCursor _consumed; private ReadCursor _examined; private Mock _timeoutControl; @@ -51,7 +51,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests { ServiceContext = _serviceContext, ConnectionFeatures = new FeatureCollection(), - BufferPool = _pipelineFactory, + MemoryPool = _pipelineFactory, TimeoutControl = _timeoutControl.Object, Application = pair.Application, Transport = pair.Transport diff --git a/test/Kestrel.Core.Tests/Http2ConnectionTests.cs b/test/Kestrel.Core.Tests/Http2ConnectionTests.cs index 3f6d9a2a9c..a9976e08fb 100644 --- a/test/Kestrel.Core.Tests/Http2ConnectionTests.cs +++ b/test/Kestrel.Core.Tests/Http2ConnectionTests.cs @@ -93,7 +93,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests private static readonly byte[] _noData = new byte[0]; private static readonly byte[] _maxData = Encoding.ASCII.GetBytes(new string('a', Http2Frame.MinAllowedMaxFrameSize)); - private readonly BufferPool _bufferPool = new MemoryPool(); + private readonly MemoryPool _memoryPool = new MemoryPool(); private readonly (IPipeConnection Transport, IPipeConnection Application) _pair; private readonly TestApplicationErrorLogger _logger; private readonly Http2ConnectionContext _connectionContext; @@ -122,7 +122,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests public Http2ConnectionTests() { - _pair = PipeFactory.CreateConnectionPair(_bufferPool); + _pair = PipeFactory.CreateConnectionPair(_memoryPool); _noopApplication = context => Task.CompletedTask; @@ -257,7 +257,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests { Log = new TestKestrelTrace(_logger) }, - BufferPool = _bufferPool, + MemoryPool = _memoryPool, Application = _pair.Application, Transport = _pair.Transport }; @@ -266,7 +266,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests public void Dispose() { - _bufferPool.Dispose(); + _memoryPool.Dispose(); } void IHttpHeadersHandler.OnHeader(Span name, Span value) diff --git a/test/Kestrel.Core.Tests/HttpConnectionTests.cs b/test/Kestrel.Core.Tests/HttpConnectionTests.cs index dffd274f75..e426c22d21 100644 --- a/test/Kestrel.Core.Tests/HttpConnectionTests.cs +++ b/test/Kestrel.Core.Tests/HttpConnectionTests.cs @@ -18,21 +18,21 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests { public class HttpConnectionTests : IDisposable { - private readonly BufferPool _bufferPool; + private readonly MemoryPool _memoryPool; private readonly HttpConnectionContext _httpConnectionContext; private readonly HttpConnection _httpConnection; public HttpConnectionTests() { - _bufferPool = new MemoryPool(); - var pair = PipeFactory.CreateConnectionPair(_bufferPool); + _memoryPool = new MemoryPool(); + var pair = PipeFactory.CreateConnectionPair(_memoryPool); _httpConnectionContext = new HttpConnectionContext { ConnectionId = "0123456789", ConnectionAdapters = new List(), ConnectionFeatures = new FeatureCollection(), - BufferPool = _bufferPool, + MemoryPool = _memoryPool, HttpConnectionId = long.MinValue, Application = pair.Application, Transport = pair.Transport, @@ -47,7 +47,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests public void Dispose() { - _bufferPool.Dispose(); + _memoryPool.Dispose(); } [Fact] diff --git a/test/Kestrel.Core.Tests/HttpResponseHeadersTests.cs b/test/Kestrel.Core.Tests/HttpResponseHeadersTests.cs index b98a47c8e5..4634b758cf 100644 --- a/test/Kestrel.Core.Tests/HttpResponseHeadersTests.cs +++ b/test/Kestrel.Core.Tests/HttpResponseHeadersTests.cs @@ -27,7 +27,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests { ServiceContext = new TestServiceContext(), ConnectionFeatures = new FeatureCollection(), - BufferPool = memoryPool, + MemoryPool = memoryPool, Application = pair.Application, Transport = pair.Transport, TimeoutControl = null diff --git a/test/Kestrel.Core.Tests/OutputProducerTests.cs b/test/Kestrel.Core.Tests/OutputProducerTests.cs index ccfb164bad..77e21810f3 100644 --- a/test/Kestrel.Core.Tests/OutputProducerTests.cs +++ b/test/Kestrel.Core.Tests/OutputProducerTests.cs @@ -15,16 +15,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests { public class OutputProducerTests : IDisposable { - private readonly BufferPool _bufferPool; + private readonly MemoryPool _memoryPool; public OutputProducerTests() { - _bufferPool = new MemoryPool(); + _memoryPool = new MemoryPool(); } public void Dispose() { - _bufferPool.Dispose(); + _memoryPool.Dispose(); } [Fact] @@ -32,7 +32,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests { var pipeOptions = new PipeOptions ( - bufferPool:_bufferPool, + pool: _memoryPool, readerScheduler: Mock.Of() ); diff --git a/test/Kestrel.Core.Tests/PipelineExtensionTests.cs b/test/Kestrel.Core.Tests/PipelineExtensionTests.cs index 954122f369..00cc9d1c2e 100644 --- a/test/Kestrel.Core.Tests/PipelineExtensionTests.cs +++ b/test/Kestrel.Core.Tests/PipelineExtensionTests.cs @@ -16,16 +16,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests private const int _ulongMaxValueLength = 20; private readonly IPipe _pipe; - private readonly BufferPool _bufferPool = new MemoryPool(); + private readonly MemoryPool _memoryPool = new MemoryPool(); public PipelineExtensionTests() { - _pipe = new Pipe(new PipeOptions(_bufferPool)); + _pipe = new Pipe(new PipeOptions(_memoryPool)); } public void Dispose() { - _bufferPool.Dispose(); + _memoryPool.Dispose(); } [Theory] diff --git a/test/Kestrel.Core.Tests/TestInput.cs b/test/Kestrel.Core.Tests/TestInput.cs index 76276f3858..ba644e4bf8 100644 --- a/test/Kestrel.Core.Tests/TestInput.cs +++ b/test/Kestrel.Core.Tests/TestInput.cs @@ -30,7 +30,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests ConnectionFeatures = new FeatureCollection(), Application = Application, Transport = Transport, - BufferPool = _memoryPool, + MemoryPool = _memoryPool, TimeoutControl = Mock.Of() }; diff --git a/test/Kestrel.Transport.Libuv.Tests/LibuvConnectionTests.cs b/test/Kestrel.Transport.Libuv.Tests/LibuvConnectionTests.cs index 061dfcebf7..f6df1515e3 100644 --- a/test/Kestrel.Transport.Libuv.Tests/LibuvConnectionTests.cs +++ b/test/Kestrel.Transport.Libuv.Tests/LibuvConnectionTests.cs @@ -61,12 +61,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests var thread = new LibuvThread(transport); mockConnectionHandler.InputOptions = pool => new PipeOptions( - bufferPool: pool, + pool: pool, maximumSizeHigh: 3); // We don't set the output writer scheduler here since we want to run the callback inline - mockConnectionHandler.OutputOptions = pool => new PipeOptions(bufferPool: pool, readerScheduler: thread); + mockConnectionHandler.OutputOptions = pool => new PipeOptions(pool: pool, readerScheduler: thread); Task connectionTask = null; @@ -125,12 +125,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests }); mockConnectionHandler.InputOptions = pool => new PipeOptions( - bufferPool: pool, + pool: pool, maximumSizeHigh: 3, maximumSizeLow: 3, writerScheduler: mockScheduler.Object); - mockConnectionHandler.OutputOptions = pool => new PipeOptions(bufferPool: pool, readerScheduler:thread ); + mockConnectionHandler.OutputOptions = pool => new PipeOptions(pool: pool, readerScheduler:thread ); Task connectionTask = null; try diff --git a/test/Kestrel.Transport.Libuv.Tests/LibuvOutputConsumerTests.cs b/test/Kestrel.Transport.Libuv.Tests/LibuvOutputConsumerTests.cs index da69f195ab..06576890d4 100644 --- a/test/Kestrel.Transport.Libuv.Tests/LibuvOutputConsumerTests.cs +++ b/test/Kestrel.Transport.Libuv.Tests/LibuvOutputConsumerTests.cs @@ -22,7 +22,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests { public class LibuvOutputConsumerTests : IDisposable { - private readonly BufferPool _bufferPool; + private readonly MemoryPool _memoryPool; private readonly MockLibuv _mockLibuv; private readonly LibuvThread _libuvThread; @@ -38,7 +38,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests public LibuvOutputConsumerTests() { - _bufferPool = new MemoryPool(); + _memoryPool = new MemoryPool(); _mockLibuv = new MockLibuv(); var libuvTransport = new LibuvTransport(_mockLibuv, new TestLibuvTransportContext(), new ListenOptions((ulong)0)); @@ -49,7 +49,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests public void Dispose() { _libuvThread.StopAsync(TimeSpan.FromSeconds(1)).Wait(); - _bufferPool.Dispose(); + _memoryPool.Dispose(); } [Theory] @@ -64,7 +64,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests // This is verified in PipeOptionsTests.OutputPipeOptionsConfiguredCorrectly. var pipeOptions = new PipeOptions ( - bufferPool: _bufferPool, + pool: _memoryPool, readerScheduler: _libuvThread, maximumSizeHigh: maxResponseBufferSize ?? 0, maximumSizeLow: maxResponseBufferSize ?? 0 @@ -100,7 +100,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests // This is verified in PipeOptionsTests.OutputPipeOptionsConfiguredCorrectly. var pipeOptions = new PipeOptions ( - bufferPool: _bufferPool, + pool: _memoryPool, readerScheduler: _libuvThread, maximumSizeHigh: 0, maximumSizeLow: 0 @@ -148,7 +148,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests // This is verified in PipeOptionsTests.OutputPipeOptionsConfiguredCorrectly. var pipeOptions = new PipeOptions ( - bufferPool: _bufferPool, + pool: _memoryPool, readerScheduler: _libuvThread, maximumSizeHigh: 1, maximumSizeLow: 1 @@ -204,7 +204,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests var pipeOptions = new PipeOptions ( - bufferPool: _bufferPool, + pool: _memoryPool, readerScheduler: _libuvThread, maximumSizeHigh: maxResponseBufferSize, maximumSizeLow: maxResponseBufferSize @@ -268,7 +268,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests var pipeOptions = new PipeOptions ( - bufferPool: _bufferPool, + pool: _memoryPool, readerScheduler: _libuvThread, maximumSizeHigh: maxResponseBufferSize, maximumSizeLow: maxResponseBufferSize @@ -338,7 +338,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests var pipeOptions = new PipeOptions ( - bufferPool: _bufferPool, + pool: _memoryPool, readerScheduler: _libuvThread, maximumSizeHigh: maxResponseBufferSize, maximumSizeLow: maxResponseBufferSize @@ -431,7 +431,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests var pipeOptions = new PipeOptions ( - bufferPool: _bufferPool, + pool: _memoryPool, readerScheduler: _libuvThread, maximumSizeHigh: maxResponseBufferSize, maximumSizeLow: maxResponseBufferSize @@ -515,7 +515,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests var pipeOptions = new PipeOptions ( - bufferPool: _bufferPool, + pool: _memoryPool, readerScheduler: _libuvThread, maximumSizeHigh: maxResponseBufferSize, maximumSizeLow: maxResponseBufferSize @@ -597,7 +597,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests var pipeOptions = new PipeOptions ( - bufferPool: _bufferPool, + pool: _memoryPool, readerScheduler: _libuvThread, maximumSizeHigh: maxResponseBufferSize, maximumSizeLow: maxResponseBufferSize @@ -658,7 +658,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests // This is verified in PipeOptionsTests.OutputPipeOptionsConfiguredCorrectly. var pipeOptions = new PipeOptions ( - bufferPool: _bufferPool, + pool: _memoryPool, readerScheduler: _libuvThread, maximumSizeHigh: maxResponseBufferSize ?? 0, maximumSizeLow: maxResponseBufferSize ?? 0 @@ -712,7 +712,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests { ServiceContext = serviceContext, ConnectionFeatures = new FeatureCollection(), - BufferPool = _bufferPool, + MemoryPool = _memoryPool, TimeoutControl = Mock.Of(), Application = pair.Application, Transport = pair.Transport diff --git a/test/Kestrel.Transport.Libuv.Tests/TestHelpers/MockConnectionHandler.cs b/test/Kestrel.Transport.Libuv.Tests/TestHelpers/MockConnectionHandler.cs index 273f65f4d4..1efb0bedab 100644 --- a/test/Kestrel.Transport.Libuv.Tests/TestHelpers/MockConnectionHandler.cs +++ b/test/Kestrel.Transport.Libuv.Tests/TestHelpers/MockConnectionHandler.cs @@ -4,7 +4,6 @@ using System; using System.Buffers; using System.IO.Pipelines; -using System.Threading.Tasks; using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Protocols; using Microsoft.AspNetCore.Protocols.Features; @@ -14,15 +13,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests.TestHelpers { public class MockConnectionHandler : IConnectionHandler { - public Func InputOptions { get; set; } = pool => new PipeOptions(pool); - public Func OutputOptions { get; set; } = pool => new PipeOptions(pool); + public Func InputOptions { get; set; } = pool => new PipeOptions(pool); + public Func OutputOptions { get; set; } = pool => new PipeOptions(pool); public void OnConnection(IFeatureCollection features) { var connectionContext = new DefaultConnectionContext(features); - Input = new Pipe(InputOptions(connectionContext.BufferPool)); - Output = new Pipe(OutputOptions(connectionContext.BufferPool)); + Input = new Pipe(InputOptions(connectionContext.MemoryPool)); + Output = new Pipe(OutputOptions(connectionContext.MemoryPool)); var feature = connectionContext.Features.Get(); From 2b54b2fc91629a96b57af9dddb18f44dff53a70f Mon Sep 17 00:00:00 2001 From: BrennanConroy Date: Mon, 11 Dec 2017 13:32:08 -0800 Subject: [PATCH 1476/1662] Upgrade deps (#2215) --- build/dependencies.props | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/build/dependencies.props b/build/dependencies.props index 0ed82b9623..4cbd05bfa3 100644 --- a/build/dependencies.props +++ b/build/dependencies.props @@ -7,23 +7,23 @@ 0.10.9 2.1.0-preview1-15620 1.10.0 - 2.1.0-preview1-27773 - 2.1.0-preview1-27773 - 2.1.0-preview1-27773 - 2.1.0-preview1-27773 - 2.1.0-preview1-27773 - 2.1.0-preview1-27773 - 2.1.0-preview1-27773 - 2.1.0-preview1-27773 - 2.1.0-preview1-27773 - 2.1.0-preview1-27773 - 2.1.0-preview1-27773 - 2.1.0-preview1-27773 - 2.1.0-preview1-27773 - 2.1.0-preview1-27773 + 2.1.0-preview1-27776 + 2.1.0-preview1-27776 + 2.1.0-preview1-27776 + 2.1.0-preview1-27776 + 2.1.0-preview1-27776 + 2.1.0-preview1-27776 + 2.1.0-preview1-27776 + 2.1.0-preview1-27776 + 2.1.0-preview1-27776 + 2.1.0-preview1-27776 + 2.1.0-preview1-27776 + 2.1.0-preview1-27776 + 2.1.0-preview1-27776 + 2.1.0-preview1-27776 2.0.0 2.1.0-preview1-26008-01 - 2.1.0-preview1-27773 + 2.1.0-preview1-27776 15.3.0 4.7.49 10.0.1 @@ -35,7 +35,7 @@ 4.5.0-preview1-26006-06 4.5.0-preview1-26006-06 0.1.0-e171206-2 - 4.5.0-preview1-26006-06 + 4.5.0-preview2-25707-02 0.8.0 2.3.1 2.3.1 From 9ece7ee935f7ffa9e71a22acca29bc6ed7a5b700 Mon Sep 17 00:00:00 2001 From: "ASP.NET CI" Date: Wed, 13 Dec 2017 21:01:22 +0000 Subject: [PATCH 1477/1662] Update dependencies.props [auto-updated: dependencies] --- build/dependencies.props | 34 +++++++++++++++++----------------- korebuild-lock.txt | 4 ++-- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/build/dependencies.props b/build/dependencies.props index 4cbd05bfa3..3467fe7edc 100644 --- a/build/dependencies.props +++ b/build/dependencies.props @@ -4,26 +4,26 @@ - 0.10.9 - 2.1.0-preview1-15620 + 0.10.11 + 2.1.0-preview1-15626 1.10.0 - 2.1.0-preview1-27776 - 2.1.0-preview1-27776 - 2.1.0-preview1-27776 - 2.1.0-preview1-27776 - 2.1.0-preview1-27776 - 2.1.0-preview1-27776 - 2.1.0-preview1-27776 - 2.1.0-preview1-27776 - 2.1.0-preview1-27776 - 2.1.0-preview1-27776 - 2.1.0-preview1-27776 - 2.1.0-preview1-27776 - 2.1.0-preview1-27776 - 2.1.0-preview1-27776 + 2.1.0-preview1-27807 + 2.1.0-preview1-27807 + 2.1.0-preview1-27807 + 2.1.0-preview1-27807 + 2.1.0-preview1-27807 + 2.1.0-preview1-27807 + 2.1.0-preview1-27807 + 2.1.0-preview1-27807 + 2.1.0-preview1-27807 + 2.1.0-preview1-27807 + 2.1.0-preview1-27807 + 2.1.0-preview1-27807 + 2.1.0-preview1-27807 + 2.1.0-preview1-27807 2.0.0 2.1.0-preview1-26008-01 - 2.1.0-preview1-27776 + 2.1.0-preview1-27807 15.3.0 4.7.49 10.0.1 diff --git a/korebuild-lock.txt b/korebuild-lock.txt index fe4a961da3..8d52a6128c 100644 --- a/korebuild-lock.txt +++ b/korebuild-lock.txt @@ -1,2 +1,2 @@ -version:2.1.0-preview1-15620 -commithash:6432b49a2c00310416df39b6fe548ef4af9c6011 +version:2.1.0-preview1-15626 +commithash:fd6410e9c90c428bc01238372303ad09cb9ec889 From 9f029350749fbd39534aea084d225a407c9e2eae Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Fri, 15 Dec 2017 12:45:32 -0800 Subject: [PATCH 1478/1662] Call Listen after Bind in tests (#2221) --- test/Kestrel.FunctionalTests/AddressRegistrationTests.cs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/test/Kestrel.FunctionalTests/AddressRegistrationTests.cs b/test/Kestrel.FunctionalTests/AddressRegistrationTests.cs index 58d7369b50..84cdb61396 100644 --- a/test/Kestrel.FunctionalTests/AddressRegistrationTests.cs +++ b/test/Kestrel.FunctionalTests/AddressRegistrationTests.cs @@ -19,7 +19,6 @@ using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; using Microsoft.AspNetCore.Testing; using Microsoft.AspNetCore.Testing.xunit; -using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using Xunit; @@ -396,6 +395,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests using (var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)) { socket.Bind(new IPEndPoint(IPAddress.Loopback, 0)); + socket.Listen(0); var port = ((IPEndPoint)socket.LocalEndPoint).Port; var hostBuilder = TransportSelector.GetWebHostBuilder() @@ -419,6 +419,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests using (var socket = new Socket(AddressFamily.InterNetworkV6, SocketType.Stream, ProtocolType.Tcp)) { socket.Bind(new IPEndPoint(IPAddress.IPv6Loopback, 0)); + socket.Listen(0); var port = ((IPEndPoint)socket.LocalEndPoint).Port; var hostBuilder = TransportSelector.GetWebHostBuilder() @@ -673,6 +674,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests using (var socket = new Socket(addressFamily, SocketType.Stream, ProtocolType.Tcp)) { socket.Bind(new IPEndPoint(address, 0)); + socket.Listen(0); var port = ((IPEndPoint)socket.LocalEndPoint).Port; var hostBuilder = TransportSelector.GetWebHostBuilder() @@ -899,7 +901,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests using (var serverSocket = new Socket(endPoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp)) { serverSocket.Bind(endPoint); - serverSocket.Listen(1); + serverSocket.Listen(0); var socketArgs = new SocketAsyncEventArgs { @@ -954,6 +956,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests using (var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)) { socket.Bind(new IPEndPoint(IPAddress.Loopback, _port)); + socket.Listen(0); return true; } } From d505d20ba7e3440ac26ba93f06d53b56bb3579e5 Mon Sep 17 00:00:00 2001 From: "Chris Ross (ASP.NET)" Date: Mon, 18 Dec 2017 12:47:43 -0800 Subject: [PATCH 1479/1662] Merge Kestrel.Https into Kestrel.Core. Fix sample. --- samples/SampleApp/SampleApp.csproj | 2 +- samples/SampleApp/testCert.pfx | Bin 0 -> 2483 bytes .../ClientCertificateMode.cs | 0 src/Kestrel.Core/CoreStrings.resx | 15 ++ .../HttpsConnectionAdapterOptions.cs | 2 +- .../Internal/ClosedStream.cs | 0 .../Internal/HttpsConnectionAdapter.cs | 8 +- .../Internal/TlsConnectionFeature.cs | 0 .../ListenOptionsHttpsExtensions.cs | 0 .../Properties/CoreStrings.Designer.cs | 70 +++++++++ src/Kestrel.Https/HttpsStrings.resx | 135 ------------------ src/Kestrel.Https/Kestrel.Https.csproj | 6 - src/Kestrel.Https/Properties/AssemblyInfo.cs | 10 +- .../Properties/HttpsStrings.Designer.cs | 100 ------------- .../Properties/KestrelStrings.Designer.cs | 4 +- .../HttpsConnectionAdapterOptionsTest.cs | 3 +- .../HttpsConnectionAdapterTests.cs | 2 +- 17 files changed, 103 insertions(+), 254 deletions(-) create mode 100644 samples/SampleApp/testCert.pfx rename src/{Kestrel.Https => Kestrel.Core}/ClientCertificateMode.cs (100%) rename src/{Kestrel.Https => Kestrel.Core}/HttpsConnectionAdapterOptions.cs (98%) rename src/{Kestrel.Https => Kestrel.Core}/Internal/ClosedStream.cs (100%) rename src/{Kestrel.Https => Kestrel.Core}/Internal/HttpsConnectionAdapter.cs (96%) rename src/{Kestrel.Https => Kestrel.Core}/Internal/TlsConnectionFeature.cs (100%) rename src/{Kestrel.Https => Kestrel.Core}/ListenOptionsHttpsExtensions.cs (100%) delete mode 100644 src/Kestrel.Https/HttpsStrings.resx delete mode 100644 src/Kestrel.Https/Properties/HttpsStrings.Designer.cs diff --git a/samples/SampleApp/SampleApp.csproj b/samples/SampleApp/SampleApp.csproj index 2225608125..a7ba9be9d6 100644 --- a/samples/SampleApp/SampleApp.csproj +++ b/samples/SampleApp/SampleApp.csproj @@ -1,7 +1,7 @@  - netcoreapp2.0;net461 + netcoreapp2.1;netcoreapp2.0;net461 false true diff --git a/samples/SampleApp/testCert.pfx b/samples/SampleApp/testCert.pfx new file mode 100644 index 0000000000000000000000000000000000000000..7118908c2d730670c16e9f8b2c532a262c951989 GIT binary patch literal 2483 zcmaKuc|27A8pqF>IWr86E&Q@(n=B)p$ug!;QVB6xij*z;uPLG!yCz#DQB)+9G$9m9 zQU)=DWXU?*EZIwG!+0d++P@yZ4Xhoagg?p6B~|Ue7tN=Ny=UD?x#1n1MTq z#c9MHh+D#gd|(a(cN}8i91v^=GcdgW3SmA$49p~gM-dys3jVWdg8+!iVL)pz1LDE5 zSb=|GAn(@R=(Ux!MfS9@}sFu-xDd zIt2+mqSq$glwy_6UNs<2?(qERU!gJ;5j}Pp&6trxG=wi)=@k(w2+fJVnc+qvXVzy(>Om4;L|^)R`t*3nTpAmEmTl(#i!RV#a0t#u6>Q9mY`-Nmcs7$XjXT7 zUmCD`O~_j7!%R#I?cG-7C^hcH)@l?WC1vyw$FFu_(r)jhOq6p}W8sG7NO{YTy8tG4 zrb$tTkag*G?(7lfoGx$4YWui>{{@}-FB2ub=}RX{1zx?j)s-##J9|G7E1@-;7Nuln z9MQoX7FJ76+D#XXT@ZZmLZCufIdf3@OigG6m8I7!GT=7VD|>?6e!z9=eT}*E_tSn6 zl+clHCZ-kcIR#gen#LjMJW8>0QtViaQB#FhqsCb0YPYr3;jRITl@V9Aph24D?r2d` zetCyyCg<*O-u+M& zW^ptmT|}p$VAOZpmbQ1{5fK-6ytEvre#Po}6c2URn`viQAF2+e?Z~PK2&pd>7=7)I zTCYm)@3PFRu_6a6Kb)IpCzQ%e3l%O#SDA+$Pq{Dk{HCqi7z>qd{nVpebffL7h{c4( zmhXn~G+C27S3(IfC)q2KON=YwqHXEo%zc40DgWLzF{%RIdr@RcLu90qMSHf!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HLB8S9CgOm*>XA8*y4`JE;^s$=bqD#U4;e5C&x&ggKIAVL zrQ)Yd8|{>7Z(6*B&7&4&9(*vDOfHMuR-Dk1IZia*XM^EZUD^{?cWG>J>KrtElc*{K zaVl(7SN2cH4I6Q$bZOpJ8e5LKaG7p;?tJ~#+9QrTYU@f#5`Vo7cEX!szCT}iX-K^2 w#3o+=C+lQz2J+SOEzVX(eJ)e7=eicC{rr9U2VGDcdH?_b literal 0 HcmV?d00001 diff --git a/src/Kestrel.Https/ClientCertificateMode.cs b/src/Kestrel.Core/ClientCertificateMode.cs similarity index 100% rename from src/Kestrel.Https/ClientCertificateMode.cs rename to src/Kestrel.Core/ClientCertificateMode.cs diff --git a/src/Kestrel.Core/CoreStrings.resx b/src/Kestrel.Core/CoreStrings.resx index 158bc6cc53..49ee7e20b8 100644 --- a/src/Kestrel.Core/CoreStrings.resx +++ b/src/Kestrel.Core/CoreStrings.resx @@ -465,4 +465,19 @@ Unable to configure default https bindings because no IDefaultHttpsProvider service was provided. + + Failed to authenticate HTTPS connection. + + + Authentication of the HTTPS connection timed out. + + + Certificate {thumbprint} cannot be used as an SSL server certificate. It has an Extended Key Usage extension but the usages do not include Server Authentication (OID 1.3.6.1.5.5.7.3.1). + + + Value must be a positive TimeSpan. + + + The server certificate parameter is required. + \ No newline at end of file diff --git a/src/Kestrel.Https/HttpsConnectionAdapterOptions.cs b/src/Kestrel.Core/HttpsConnectionAdapterOptions.cs similarity index 98% rename from src/Kestrel.Https/HttpsConnectionAdapterOptions.cs rename to src/Kestrel.Core/HttpsConnectionAdapterOptions.cs index 14238658d0..6ada701707 100644 --- a/src/Kestrel.Https/HttpsConnectionAdapterOptions.cs +++ b/src/Kestrel.Core/HttpsConnectionAdapterOptions.cs @@ -73,7 +73,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Https { if (value <= TimeSpan.Zero && value != Timeout.InfiniteTimeSpan) { - throw new ArgumentOutOfRangeException(nameof(value), HttpsStrings.PositiveTimeSpanRequired); + throw new ArgumentOutOfRangeException(nameof(value), CoreStrings.PositiveTimeSpanRequired); } _handshakeTimeout = value != Timeout.InfiniteTimeSpan ? value : TimeSpan.MaxValue; } diff --git a/src/Kestrel.Https/Internal/ClosedStream.cs b/src/Kestrel.Core/Internal/ClosedStream.cs similarity index 100% rename from src/Kestrel.Https/Internal/ClosedStream.cs rename to src/Kestrel.Core/Internal/ClosedStream.cs diff --git a/src/Kestrel.Https/Internal/HttpsConnectionAdapter.cs b/src/Kestrel.Core/Internal/HttpsConnectionAdapter.cs similarity index 96% rename from src/Kestrel.Https/Internal/HttpsConnectionAdapter.cs rename to src/Kestrel.Core/Internal/HttpsConnectionAdapter.cs index 853f81966a..68043a0762 100644 --- a/src/Kestrel.Https/Internal/HttpsConnectionAdapter.cs +++ b/src/Kestrel.Core/Internal/HttpsConnectionAdapter.cs @@ -43,7 +43,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Https.Internal if (options.ServerCertificate == null) { - throw new ArgumentException(HttpsStrings.ServiceCertificateRequired, nameof(options)); + throw new ArgumentException(CoreStrings.ServiceCertificateRequired, nameof(options)); } // capture the certificate now so it can be switched after validation @@ -148,13 +148,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Https.Internal } catch (OperationCanceledException) { - _logger?.LogInformation(2, HttpsStrings.AuthenticationTimedOut); + _logger?.LogInformation(2, CoreStrings.AuthenticationTimedOut); sslStream.Dispose(); return _closedAdaptedConnection; } catch (IOException ex) { - _logger?.LogInformation(1, ex, HttpsStrings.AuthenticationFailed); + _logger?.LogInformation(1, ex, CoreStrings.AuthenticationFailed); sslStream.Dispose(); return _closedAdaptedConnection; } @@ -218,7 +218,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Https.Internal if (hasEkuExtension) { - throw new InvalidOperationException(HttpsStrings.FormatInvalidServerCertificateEku(certificate.Thumbprint)); + throw new InvalidOperationException(CoreStrings.FormatInvalidServerCertificateEku(certificate.Thumbprint)); } } diff --git a/src/Kestrel.Https/Internal/TlsConnectionFeature.cs b/src/Kestrel.Core/Internal/TlsConnectionFeature.cs similarity index 100% rename from src/Kestrel.Https/Internal/TlsConnectionFeature.cs rename to src/Kestrel.Core/Internal/TlsConnectionFeature.cs diff --git a/src/Kestrel.Https/ListenOptionsHttpsExtensions.cs b/src/Kestrel.Core/ListenOptionsHttpsExtensions.cs similarity index 100% rename from src/Kestrel.Https/ListenOptionsHttpsExtensions.cs rename to src/Kestrel.Core/ListenOptionsHttpsExtensions.cs diff --git a/src/Kestrel.Core/Properties/CoreStrings.Designer.cs b/src/Kestrel.Core/Properties/CoreStrings.Designer.cs index 9321f1a2c9..4e1d8cf2c7 100644 --- a/src/Kestrel.Core/Properties/CoreStrings.Designer.cs +++ b/src/Kestrel.Core/Properties/CoreStrings.Designer.cs @@ -1634,6 +1634,76 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core internal static string FormatUnableToConfigureHttpsBindings() => GetString("UnableToConfigureHttpsBindings"); + /// + /// Failed to authenticate HTTPS connection. + /// + internal static string AuthenticationFailed + { + get => GetString("AuthenticationFailed"); + } + + /// + /// Failed to authenticate HTTPS connection. + /// + internal static string FormatAuthenticationFailed() + => GetString("AuthenticationFailed"); + + /// + /// Authentication of the HTTPS connection timed out. + /// + internal static string AuthenticationTimedOut + { + get => GetString("AuthenticationTimedOut"); + } + + /// + /// Authentication of the HTTPS connection timed out. + /// + internal static string FormatAuthenticationTimedOut() + => GetString("AuthenticationTimedOut"); + + /// + /// Certificate {thumbprint} cannot be used as an SSL server certificate. It has an Extended Key Usage extension but the usages do not include Server Authentication (OID 1.3.6.1.5.5.7.3.1). + /// + internal static string InvalidServerCertificateEku + { + get => GetString("InvalidServerCertificateEku"); + } + + /// + /// Certificate {thumbprint} cannot be used as an SSL server certificate. It has an Extended Key Usage extension but the usages do not include Server Authentication (OID 1.3.6.1.5.5.7.3.1). + /// + internal static string FormatInvalidServerCertificateEku(object thumbprint) + => string.Format(CultureInfo.CurrentCulture, GetString("InvalidServerCertificateEku", "thumbprint"), thumbprint); + + /// + /// Value must be a positive TimeSpan. + /// + internal static string PositiveTimeSpanRequired1 + { + get => GetString("PositiveTimeSpanRequired1"); + } + + /// + /// Value must be a positive TimeSpan. + /// + internal static string FormatPositiveTimeSpanRequired1() + => GetString("PositiveTimeSpanRequired1"); + + /// + /// The server certificate parameter is required. + /// + internal static string ServiceCertificateRequired + { + get => GetString("ServiceCertificateRequired"); + } + + /// + /// The server certificate parameter is required. + /// + internal static string FormatServiceCertificateRequired() + => GetString("ServiceCertificateRequired"); + private static string GetString(string name, params string[] formatterNames) { var value = _resourceManager.GetString(name); diff --git a/src/Kestrel.Https/HttpsStrings.resx b/src/Kestrel.Https/HttpsStrings.resx deleted file mode 100644 index 689b5c4779..0000000000 --- a/src/Kestrel.Https/HttpsStrings.resx +++ /dev/null @@ -1,135 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 2.0 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - Failed to authenticate HTTPS connection. - - - Authentication of the HTTPS connection timed out. - - - Certificate {thumbprint} cannot be used as an SSL server certificate. It has an Extended Key Usage extension but the usages do not include Server Authentication (OID 1.3.6.1.5.5.7.3.1). - - - Value must be a positive TimeSpan. - - - The server certificate parameter is required. - - \ No newline at end of file diff --git a/src/Kestrel.Https/Kestrel.Https.csproj b/src/Kestrel.Https/Kestrel.Https.csproj index d9620b513e..8b3226529e 100644 --- a/src/Kestrel.Https/Kestrel.Https.csproj +++ b/src/Kestrel.Https/Kestrel.Https.csproj @@ -18,10 +18,4 @@ - - - - - - diff --git a/src/Kestrel.Https/Properties/AssemblyInfo.cs b/src/Kestrel.Https/Properties/AssemblyInfo.cs index 65c2045e24..c99dd8d3e3 100644 --- a/src/Kestrel.Https/Properties/AssemblyInfo.cs +++ b/src/Kestrel.Https/Properties/AssemblyInfo.cs @@ -2,7 +2,11 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Runtime.CompilerServices; +using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Server.Kestrel.Https; +using Microsoft.AspNetCore.Server.Kestrel.Https.Internal; -[assembly: InternalsVisibleTo("Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.FunctionalTests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")] -[assembly: InternalsVisibleTo("Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.FunctionalTests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")] - +[assembly: TypeForwardedTo(typeof(ClientCertificateMode))] +[assembly: TypeForwardedTo(typeof(HttpsConnectionAdapter))] +[assembly: TypeForwardedTo(typeof(HttpsConnectionAdapterOptions))] +[assembly: TypeForwardedTo(typeof(ListenOptionsHttpsExtensions))] \ No newline at end of file diff --git a/src/Kestrel.Https/Properties/HttpsStrings.Designer.cs b/src/Kestrel.Https/Properties/HttpsStrings.Designer.cs deleted file mode 100644 index 417309ee92..0000000000 --- a/src/Kestrel.Https/Properties/HttpsStrings.Designer.cs +++ /dev/null @@ -1,100 +0,0 @@ -// -namespace Microsoft.AspNetCore.Server.Kestrel.Https -{ - using System.Globalization; - using System.Reflection; - using System.Resources; - - internal static class HttpsStrings - { - private static readonly ResourceManager _resourceManager - = new ResourceManager("Microsoft.AspNetCore.Server.Kestrel.Https.HttpsStrings", typeof(HttpsStrings).GetTypeInfo().Assembly); - - /// - /// Failed to authenticate HTTPS connection. - /// - internal static string AuthenticationFailed - { - get => GetString("AuthenticationFailed"); - } - - /// - /// Failed to authenticate HTTPS connection. - /// - internal static string FormatAuthenticationFailed() - => GetString("AuthenticationFailed"); - - /// - /// Authentication of the HTTPS connection timed out. - /// - internal static string AuthenticationTimedOut - { - get => GetString("AuthenticationTimedOut"); - } - - /// - /// Authentication of the HTTPS connection timed out. - /// - internal static string FormatAuthenticationTimedOut() - => GetString("AuthenticationTimedOut"); - - /// - /// Certificate {thumbprint} cannot be used as an SSL server certificate. It has an Extended Key Usage extension but the usages do not include Server Authentication (OID 1.3.6.1.5.5.7.3.1). - /// - internal static string InvalidServerCertificateEku - { - get => GetString("InvalidServerCertificateEku"); - } - - /// - /// Certificate {thumbprint} cannot be used as an SSL server certificate. It has an Extended Key Usage extension but the usages do not include Server Authentication (OID 1.3.6.1.5.5.7.3.1). - /// - internal static string FormatInvalidServerCertificateEku(object thumbprint) - => string.Format(CultureInfo.CurrentCulture, GetString("InvalidServerCertificateEku", "thumbprint"), thumbprint); - - /// - /// Value must be a positive TimeSpan. - /// - internal static string PositiveTimeSpanRequired - { - get => GetString("PositiveTimeSpanRequired"); - } - - /// - /// Value must be a positive TimeSpan. - /// - internal static string FormatPositiveTimeSpanRequired() - => GetString("PositiveTimeSpanRequired"); - - /// - /// The server certificate parameter is required. - /// - internal static string ServiceCertificateRequired - { - get => GetString("ServiceCertificateRequired"); - } - - /// - /// The server certificate parameter is required. - /// - internal static string FormatServiceCertificateRequired() - => GetString("ServiceCertificateRequired"); - - private static string GetString(string name, params string[] formatterNames) - { - var value = _resourceManager.GetString(name); - - System.Diagnostics.Debug.Assert(value != null); - - if (formatterNames != null) - { - for (var i = 0; i < formatterNames.Length; i++) - { - value = value.Replace("{" + formatterNames[i] + "}", "{" + i + "}"); - } - } - - return value; - } - } -} diff --git a/src/Kestrel/Properties/KestrelStrings.Designer.cs b/src/Kestrel/Properties/KestrelStrings.Designer.cs index ede41f12cf..0246bf453a 100644 --- a/src/Kestrel/Properties/KestrelStrings.Designer.cs +++ b/src/Kestrel/Properties/KestrelStrings.Designer.cs @@ -11,7 +11,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel = new ResourceManager("Microsoft.AspNetCore.Server.Kestrel.KestrelStrings", typeof(KestrelStrings).GetTypeInfo().Assembly); /// - /// An 'https' URL was provided, but a development certificate could not be found. + /// Unable to configure HTTPS endpoint. Try running 'dotnet developercertificates https -t' to setup a developer certificate for use with localhost. For information on configuring HTTPS see https://go.microsoft.com/fwlink/?linkid=848054 /// internal static string HttpsUrlProvidedButNoDevelopmentCertificateFound { @@ -19,7 +19,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel } /// - /// An 'https' URL was provided, but a development certificate could not be found. + /// Unable to configure HTTPS endpoint. Try running 'dotnet developercertificates https -t' to setup a developer certificate for use with localhost. For information on configuring HTTPS see https://go.microsoft.com/fwlink/?linkid=848054 /// internal static string FormatHttpsUrlProvidedButNoDevelopmentCertificateFound() => GetString("HttpsUrlProvidedButNoDevelopmentCertificateFound"); diff --git a/test/Kestrel.FunctionalTests/HttpsConnectionAdapterOptionsTest.cs b/test/Kestrel.FunctionalTests/HttpsConnectionAdapterOptionsTest.cs index b626416092..7d32d4be96 100644 --- a/test/Kestrel.FunctionalTests/HttpsConnectionAdapterOptionsTest.cs +++ b/test/Kestrel.FunctionalTests/HttpsConnectionAdapterOptionsTest.cs @@ -3,6 +3,7 @@ using System; using System.Threading; +using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.AspNetCore.Server.Kestrel.Https; using Xunit; @@ -36,7 +37,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests var exception = Assert.Throws(() => new HttpsConnectionAdapterOptions { HandshakeTimeout = value }); Assert.Equal("value", exception.ParamName); - Assert.StartsWith(HttpsStrings.PositiveTimeSpanRequired, exception.Message); + Assert.StartsWith(CoreStrings.PositiveTimeSpanRequired, exception.Message); } public static TheoryData TimeoutValidData => new TheoryData diff --git a/test/Kestrel.FunctionalTests/HttpsConnectionAdapterTests.cs b/test/Kestrel.FunctionalTests/HttpsConnectionAdapterTests.cs index ebf6081761..c08d02fb3e 100644 --- a/test/Kestrel.FunctionalTests/HttpsConnectionAdapterTests.cs +++ b/test/Kestrel.FunctionalTests/HttpsConnectionAdapterTests.cs @@ -427,7 +427,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests ServerCertificate = cert, })); - Assert.Equal(HttpsStrings.FormatInvalidServerCertificateEku(cert.Thumbprint), ex.Message); + Assert.Equal(CoreStrings.FormatInvalidServerCertificateEku(cert.Thumbprint), ex.Message); } private static async Task App(HttpContext httpContext) From 9cb1acdea05091fb1f40aa78179fd22e0248edb7 Mon Sep 17 00:00:00 2001 From: "Chris Ross (ASP.NET)" Date: Mon, 18 Dec 2017 14:45:58 -0800 Subject: [PATCH 1480/1662] Update dependencies --- build/dependencies.props | 48 ++++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/build/dependencies.props b/build/dependencies.props index 3467fe7edc..511e04d92d 100644 --- a/build/dependencies.props +++ b/build/dependencies.props @@ -7,34 +7,34 @@ 0.10.11 2.1.0-preview1-15626 1.10.0 - 2.1.0-preview1-27807 - 2.1.0-preview1-27807 - 2.1.0-preview1-27807 - 2.1.0-preview1-27807 - 2.1.0-preview1-27807 - 2.1.0-preview1-27807 - 2.1.0-preview1-27807 - 2.1.0-preview1-27807 - 2.1.0-preview1-27807 - 2.1.0-preview1-27807 - 2.1.0-preview1-27807 - 2.1.0-preview1-27807 - 2.1.0-preview1-27807 - 2.1.0-preview1-27807 + 2.1.0-preview1-27845 + 2.1.0-preview1-27845 + 2.1.0-preview1-27845 + 2.1.0-preview1-27845 + 2.1.0-preview1-27845 + 2.1.0-preview1-27845 + 2.1.0-preview1-27845 + 2.1.0-preview1-27845 + 2.1.0-preview1-27845 + 2.1.0-preview1-27845 + 2.1.0-preview1-27845 + 2.1.0-preview1-27845 + 2.1.0-preview1-27845 + 2.1.0-preview1-27845 2.0.0 - 2.1.0-preview1-26008-01 - 2.1.0-preview1-27807 + 2.1.0-preview1-26016-05 + 2.1.0-preview1-27845 15.3.0 4.7.49 10.0.1 - 4.5.0-preview1-26006-06 - 0.1.0-e171206-2 - 0.1.0-e171206-2 - 4.5.0-preview1-26006-06 - 4.5.0-preview1-26006-06 - 4.5.0-preview1-26006-06 - 4.5.0-preview1-26006-06 - 0.1.0-e171206-2 + 4.5.0-preview1-26016-05 + 0.1.0-e171215-1 + 0.1.0-e171215-1 + 4.5.0-preview1-26016-05 + 4.5.0-preview1-26016-05 + 4.5.0-preview1-26016-05 + 4.5.0-preview1-26016-05 + 0.1.0-e171215-1 4.5.0-preview2-25707-02 0.8.0 2.3.1 From 3a0a133a02d0981025ba08a92612b4015bf54f47 Mon Sep 17 00:00:00 2001 From: Pavel Krymets Date: Tue, 19 Dec 2017 11:33:39 -0800 Subject: [PATCH 1481/1662] Remove use of Dangerous* Span APIs and use MemoryMarshal instead (#2228) --- src/Kestrel.Core/Internal/Http/Http1Connection.cs | 3 ++- src/Kestrel.Core/Internal/Http/HttpParser.cs | 7 ++++--- src/Kestrel.Core/Internal/Http/HttpRequestHeaders.cs | 3 ++- src/Kestrel.Core/Internal/Http/PathNormalizer.cs | 3 ++- src/Kestrel.Core/Internal/Http/PipelineExtensions.cs | 7 ++++--- .../Internal/Infrastructure/HttpUtilities.cs | 9 +++++---- 6 files changed, 19 insertions(+), 13 deletions(-) diff --git a/src/Kestrel.Core/Internal/Http/Http1Connection.cs b/src/Kestrel.Core/Internal/Http/Http1Connection.cs index 29b257208b..5168bf7d61 100644 --- a/src/Kestrel.Core/Internal/Http/Http1Connection.cs +++ b/src/Kestrel.Core/Internal/Http/Http1Connection.cs @@ -4,6 +4,7 @@ using System; using System.Diagnostics; using System.IO.Pipelines; +using System.Runtime.InteropServices; using System.Text; using System.Text.Encodings.Web.Utf8; using Microsoft.AspNetCore.Http.Features; @@ -341,7 +342,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { // .NET 451 doesn't have pointer overloads for Encoding.GetString so we // copy to an array - fixed (byte* pointer = &path.DangerousGetPinnableReference()) + fixed (byte* pointer = &MemoryMarshal.GetReference(path)) { return Encoding.UTF8.GetString(pointer, path.Length); } diff --git a/src/Kestrel.Core/Internal/Http/HttpParser.cs b/src/Kestrel.Core/Internal/Http/HttpParser.cs index cb2163a493..ab66b2337f 100644 --- a/src/Kestrel.Core/Internal/Http/HttpParser.cs +++ b/src/Kestrel.Core/Internal/Http/HttpParser.cs @@ -4,6 +4,7 @@ using System; using System.IO.Pipelines; using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http @@ -60,7 +61,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http } // Fix and parse the span - fixed (byte* data = &span.DangerousGetPinnableReference()) + fixed (byte* data = &MemoryMarshal.GetReference(span)) { ParseRequestLine(handler, data, span.Length); } @@ -204,7 +205,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http var span = reader.Span; var remaining = span.Length - reader.Index; - fixed (byte* pBuffer = &span.DangerousGetPinnableReference()) + fixed (byte* pBuffer = &MemoryMarshal.GetReference(span)) { while (remaining > 0) { @@ -289,7 +290,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http var headerSpan = buffer.Slice(current, lineEnd).ToSpan(); length = headerSpan.Length; - fixed (byte* pHeader = &headerSpan.DangerousGetPinnableReference()) + fixed (byte* pHeader = &MemoryMarshal.GetReference(headerSpan)) { TakeSingleHeader(pHeader, length, handler); } diff --git a/src/Kestrel.Core/Internal/Http/HttpRequestHeaders.cs b/src/Kestrel.Core/Internal/Http/HttpRequestHeaders.cs index fd0008e52b..f512df8fcf 100644 --- a/src/Kestrel.Core/Internal/Http/HttpRequestHeaders.cs +++ b/src/Kestrel.Core/Internal/Http/HttpRequestHeaders.cs @@ -5,6 +5,7 @@ using System; using System.Collections; using System.Collections.Generic; using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; using Microsoft.Extensions.Primitives; using Microsoft.Net.Http.Headers; @@ -32,7 +33,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http public unsafe void Append(Span name, string value) { - fixed (byte* namePtr = &name.DangerousGetPinnableReference()) + fixed (byte* namePtr = &MemoryMarshal.GetReference(name)) { Append(namePtr, name.Length, value); } diff --git a/src/Kestrel.Core/Internal/Http/PathNormalizer.cs b/src/Kestrel.Core/Internal/Http/PathNormalizer.cs index de076e1849..68cdddf7ce 100644 --- a/src/Kestrel.Core/Internal/Http/PathNormalizer.cs +++ b/src/Kestrel.Core/Internal/Http/PathNormalizer.cs @@ -3,6 +3,7 @@ using System; using System.Diagnostics; +using System.Runtime.InteropServices; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { @@ -14,7 +15,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http // In-place implementation of the algorithm from https://tools.ietf.org/html/rfc3986#section-5.2.4 public static unsafe int RemoveDotSegments(Span input) { - fixed (byte* start = &input.DangerousGetPinnableReference()) + fixed (byte* start = &MemoryMarshal.GetReference(input)) { var end = start + input.Length; return RemoveDotSegments(start, end); diff --git a/src/Kestrel.Core/Internal/Http/PipelineExtensions.cs b/src/Kestrel.Core/Internal/Http/PipelineExtensions.cs index e12b588bb4..6989d80aa3 100644 --- a/src/Kestrel.Core/Internal/Http/PipelineExtensions.cs +++ b/src/Kestrel.Core/Internal/Http/PipelineExtensions.cs @@ -4,6 +4,7 @@ using System; using System.IO.Pipelines; using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { @@ -49,7 +50,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http if (sourceLength <= destLength) { fixed (char* input = data) - fixed (byte* output = &dest.DangerousGetPinnableReference()) + fixed (byte* output = &MemoryMarshal.GetReference(dest)) { EncodeAsciiCharsToBytes(input, output, sourceLength); } @@ -72,7 +73,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http // Fast path, try copying to the available memory directly var simpleWrite = true; - fixed (byte* output = &span.DangerousGetPinnableReference()) + fixed (byte* output = &MemoryMarshal.GetReference(span)) { var start = output; if (number < 10 && bytesLeftInBlock >= 1) @@ -152,7 +153,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http continue; } - fixed (byte* output = &buffer.Span.DangerousGetPinnableReference()) + fixed (byte* output = &MemoryMarshal.GetReference(buffer.Span)) { EncodeAsciiCharsToBytes(inputSlice, output, writable); } diff --git a/src/Kestrel.Core/Internal/Infrastructure/HttpUtilities.cs b/src/Kestrel.Core/Internal/Infrastructure/HttpUtilities.cs index 7b08a068fd..28f73a9031 100644 --- a/src/Kestrel.Core/Internal/Infrastructure/HttpUtilities.cs +++ b/src/Kestrel.Core/Internal/Infrastructure/HttpUtilities.cs @@ -4,6 +4,7 @@ using System; using System.Diagnostics; using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; using System.Text; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; @@ -91,7 +92,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure var asciiString = new string('\0', span.Length); fixed (char* output = asciiString) - fixed (byte* buffer = &span.DangerousGetPinnableReference()) + fixed (byte* buffer = &MemoryMarshal.GetReference(span)) { // This version if AsciiUtilities returns null if there are any null (0 byte) characters // in the string @@ -136,7 +137,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure [MethodImpl(MethodImplOptions.AggressiveInlining)] public static unsafe bool GetKnownMethod(this Span span, out HttpMethod method, out int length) { - fixed (byte* data = &span.DangerousGetPinnableReference()) + fixed (byte* data = &MemoryMarshal.GetReference(span)) { method = GetKnownMethod(data, span.Length, out length); return method != HttpMethod.Custom; @@ -190,7 +191,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure [MethodImpl(MethodImplOptions.AggressiveInlining)] public static unsafe bool GetKnownVersion(this Span span, out HttpVersion knownVersion, out byte length) { - fixed (byte* data = &span.DangerousGetPinnableReference()) + fixed (byte* data = &MemoryMarshal.GetReference(span)) { knownVersion = GetKnownVersion(data, span.Length); if (knownVersion != HttpVersion.Unknown) @@ -249,7 +250,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure [MethodImpl(MethodImplOptions.AggressiveInlining)] public static unsafe bool GetKnownHttpScheme(this Span span, out HttpScheme knownScheme) { - fixed (byte* data = &span.DangerousGetPinnableReference()) + fixed (byte* data = &MemoryMarshal.GetReference(span)) { return GetKnownHttpScheme(data, span.Length, out knownScheme); } From dfaf37cbba684a9913b79ec68fdf5ad18378c170 Mon Sep 17 00:00:00 2001 From: "Chris Ross (ASP.NET)" Date: Tue, 21 Nov 2017 10:59:34 -0800 Subject: [PATCH 1482/1662] Implement config support #1290 #1879 #2016 #2166 #2167 #2188 --- KestrelHttpServer.sln | 20 +- build/dependencies.props | 3 + samples/SampleApp/SampleApp.csproj | 17 +- samples/SampleApp/Startup.cs | 59 +++- .../SampleApp/appsettings.Development.json | 15 + samples/SampleApp/appsettings.Production.json | 14 + samples/SampleApp/appsettings.json | 6 + samples/SystemdTestApp/Startup.cs | 92 ++++++ samples/SystemdTestApp/SystemdTestApp.csproj | 23 ++ samples/SystemdTestApp/testCert.pfx | Bin 0 -> 2483 bytes src/Kestrel.Core/CoreStrings.resx | 15 + src/Kestrel.Core/EndpointConfiguration.cs | 26 ++ .../Internal/AddressBindContext.cs | 1 - src/Kestrel.Core/Internal/AddressBinder.cs | 63 ++-- .../Internal/CertificateLoader.cs | 99 ++++++ .../Internal/ConfigurationReader.cs | 140 +++++++++ .../Internal/HttpsConnectionAdapter.cs | 35 +-- .../Internal/IDefaultHttpsProvider.cs | 10 - .../Internal/Infrastructure/Constants.cs | 7 +- .../Internal/KestrelServerOptionsSetup.cs | 24 +- .../Internal/LoggerExtensions.cs | 2 +- src/Kestrel.Core/Kestrel.Core.csproj | 3 + .../KestrelConfigurationLoader.cs | 297 ++++++++++++++++++ src/Kestrel.Core/KestrelServer.cs | 11 +- src/Kestrel.Core/KestrelServerOptions.cs | 110 ++++++- .../ListenOptionsHttpsExtensions.cs | 205 +++++++++--- src/Kestrel.Core/Properties/AssemblyInfo.cs | 1 + .../Properties/CoreStrings.Designer.cs | 70 +++++ src/Kestrel/Internal/DefaultHttpsProvider.cs | 42 --- src/Kestrel/Kestrel.csproj | 2 - src/Kestrel/KestrelStrings.resx | 123 -------- .../Properties/KestrelStrings.Designer.cs | 44 --- .../WebHostBuilderKestrelExtensions.cs | 1 - test/Kestrel.Core.Tests/AddressBinderTests.cs | 26 +- .../Kestrel.Core.Tests.csproj | 1 + .../KestrelServerOptionsTests.cs | 35 +++ test/Kestrel.Core.Tests/KestrelServerTests.cs | 38 ++- .../AddressRegistrationTests.cs | 81 ++++- .../CertificateLoaderTests.cs | 64 ++++ test/Kestrel.FunctionalTests/HttpsTests.cs | 65 +++- .../Kestrel.Tests/ConfigurationReaderTests.cs | 177 +++++++++++ test/Kestrel.Tests/Kestrel.Tests.csproj | 6 + .../KestrelConfigurationBuilderTests.cs | 213 +++++++++++++ test/SystemdActivation/docker-entrypoint.sh | 4 +- test/SystemdActivation/docker.sh | 6 +- test/shared/TestResources.cs | 6 + 46 files changed, 1903 insertions(+), 399 deletions(-) create mode 100644 samples/SampleApp/appsettings.Development.json create mode 100644 samples/SampleApp/appsettings.Production.json create mode 100644 samples/SampleApp/appsettings.json create mode 100644 samples/SystemdTestApp/Startup.cs create mode 100644 samples/SystemdTestApp/SystemdTestApp.csproj create mode 100644 samples/SystemdTestApp/testCert.pfx create mode 100644 src/Kestrel.Core/EndpointConfiguration.cs create mode 100644 src/Kestrel.Core/Internal/CertificateLoader.cs create mode 100644 src/Kestrel.Core/Internal/ConfigurationReader.cs delete mode 100644 src/Kestrel.Core/Internal/IDefaultHttpsProvider.cs rename src/{Kestrel => Kestrel.Core}/Internal/LoggerExtensions.cs (94%) create mode 100644 src/Kestrel.Core/KestrelConfigurationLoader.cs delete mode 100644 src/Kestrel/Internal/DefaultHttpsProvider.cs delete mode 100644 src/Kestrel/KestrelStrings.resx delete mode 100644 src/Kestrel/Properties/KestrelStrings.Designer.cs create mode 100644 test/Kestrel.FunctionalTests/CertificateLoaderTests.cs create mode 100644 test/Kestrel.Tests/ConfigurationReaderTests.cs create mode 100644 test/Kestrel.Tests/KestrelConfigurationBuilderTests.cs diff --git a/KestrelHttpServer.sln b/KestrelHttpServer.sln index 7718ccf9e7..345cf04f72 100644 --- a/KestrelHttpServer.sln +++ b/KestrelHttpServer.sln @@ -1,6 +1,6 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 15 -VisualStudioVersion = 15.0.27110.0 +VisualStudioVersion = 15.0.27130.2010 MinimumVisualStudioVersion = 15.0.26730.03 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{7972A5D6-3385-4127-9277-428506DD44FF}" ProjectSection(SolutionItems) = preProject @@ -104,6 +104,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Protocols.Abstractions", "s EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "build", "build", "{C2910A13-B2C2-46D8-81D8-7E166F4F5981}" ProjectSection(SolutionItems) = preProject + build\dependencies.props = build\dependencies.props build\repo.props = build\repo.props build\repo.targets = build\repo.targets EndProjectSection @@ -119,7 +120,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Kestrel.Transport.Libuv.Fun EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Kestrel.Transport.Sockets.FunctionalTests", "test\Kestrel.Transport.Sockets.FunctionalTests\Kestrel.Transport.Sockets.FunctionalTests.csproj", "{9C7B6B5F-088A-436E-834B-6373EA36DEEE}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Http2SampleApp", "samples\Http2SampleApp\Http2SampleApp.csproj", "{7BC22A4A-15D2-44C2-AB45-049F0FB562FA}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Http2SampleApp", "samples\Http2SampleApp\Http2SampleApp.csproj", "{7BC22A4A-15D2-44C2-AB45-049F0FB562FA}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SystemdTestApp", "samples\SystemdTestApp\SystemdTestApp.csproj", "{A7994A41-CAF8-47A7-8975-F101F75B5BC1}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -335,6 +338,18 @@ Global {7BC22A4A-15D2-44C2-AB45-049F0FB562FA}.Release|x64.Build.0 = Release|Any CPU {7BC22A4A-15D2-44C2-AB45-049F0FB562FA}.Release|x86.ActiveCfg = Release|Any CPU {7BC22A4A-15D2-44C2-AB45-049F0FB562FA}.Release|x86.Build.0 = Release|Any CPU + {A7994A41-CAF8-47A7-8975-F101F75B5BC1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A7994A41-CAF8-47A7-8975-F101F75B5BC1}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A7994A41-CAF8-47A7-8975-F101F75B5BC1}.Debug|x64.ActiveCfg = Debug|Any CPU + {A7994A41-CAF8-47A7-8975-F101F75B5BC1}.Debug|x64.Build.0 = Debug|Any CPU + {A7994A41-CAF8-47A7-8975-F101F75B5BC1}.Debug|x86.ActiveCfg = Debug|Any CPU + {A7994A41-CAF8-47A7-8975-F101F75B5BC1}.Debug|x86.Build.0 = Debug|Any CPU + {A7994A41-CAF8-47A7-8975-F101F75B5BC1}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A7994A41-CAF8-47A7-8975-F101F75B5BC1}.Release|Any CPU.Build.0 = Release|Any CPU + {A7994A41-CAF8-47A7-8975-F101F75B5BC1}.Release|x64.ActiveCfg = Release|Any CPU + {A7994A41-CAF8-47A7-8975-F101F75B5BC1}.Release|x64.Build.0 = Release|Any CPU + {A7994A41-CAF8-47A7-8975-F101F75B5BC1}.Release|x86.ActiveCfg = Release|Any CPU + {A7994A41-CAF8-47A7-8975-F101F75B5BC1}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -359,6 +374,7 @@ Global {74032D79-8EA7-4483-BD82-C38370420FFF} = {D3273454-EA07-41D2-BF0B-FCC3675C2483} {9C7B6B5F-088A-436E-834B-6373EA36DEEE} = {D3273454-EA07-41D2-BF0B-FCC3675C2483} {7BC22A4A-15D2-44C2-AB45-049F0FB562FA} = {8A3D00B8-1CCF-4BE6-A060-11104CE2D9CE} + {A7994A41-CAF8-47A7-8975-F101F75B5BC1} = {8A3D00B8-1CCF-4BE6-A060-11104CE2D9CE} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {2D10D020-6770-47CA-BB8D-2C23FE3AE071} diff --git a/build/dependencies.props b/build/dependencies.props index 511e04d92d..b6e10ad8cb 100644 --- a/build/dependencies.props +++ b/build/dependencies.props @@ -16,6 +16,9 @@ 2.1.0-preview1-27845 2.1.0-preview1-27845 2.1.0-preview1-27845 + 2.1.0-preview1-27845 + 2.1.0-preview1-27845 + 2.1.0-preview1-27845 2.1.0-preview1-27845 2.1.0-preview1-27845 2.1.0-preview1-27845 diff --git a/samples/SampleApp/SampleApp.csproj b/samples/SampleApp/SampleApp.csproj index a7ba9be9d6..112987f619 100644 --- a/samples/SampleApp/SampleApp.csproj +++ b/samples/SampleApp/SampleApp.csproj @@ -12,11 +12,26 @@ + - + + PreserveNewest + + + + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + diff --git a/samples/SampleApp/Startup.cs b/samples/SampleApp/Startup.cs index e0e471b635..09baead9da 100644 --- a/samples/SampleApp/Startup.cs +++ b/samples/SampleApp/Startup.cs @@ -3,13 +3,15 @@ using System; using System.Diagnostics; -using System.Globalization; using System.IO; using System.Net; +using System.Security.Authentication; +using System.Security.Cryptography.X509Certificates; using System.Threading.Tasks; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Logging; @@ -48,10 +50,31 @@ namespace SampleApp { factory.AddConsole(); }) + .ConfigureAppConfiguration((hostingContext, config) => + { + var env = hostingContext.HostingEnvironment; + config.AddJsonFile("appsettings.json", optional: true) + .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true); + }) .UseKestrel((context, options) => { + if (context.HostingEnvironment.IsDevelopment()) + { + ShowConfig(context.Configuration); + } + var basePort = context.Configuration.GetValue("BASE_PORT") ?? 5000; + options.ConfigureEndpointDefaults(opt => + { + opt.Protocols = HttpProtocols.Http1; + }); + + options.ConfigureHttpsDefaults(httpsOptions => + { + httpsOptions.SslProtocols = SslProtocols.Tls12; + }); + // Run callbacks on the transport thread options.ApplicationSchedulingMode = SchedulingMode.Inline; @@ -71,11 +94,34 @@ namespace SampleApp options.ListenLocalhost(basePort + 2, listenOptions => { - listenOptions.UseHttps("testCert.pfx", "testPassword"); + // Use default dev cert + listenOptions.UseHttps(); }); options.ListenAnyIP(basePort + 3); + options.ListenAnyIP(basePort + 4, listenOptions => + { + listenOptions.UseHttps(StoreName.My, "aspnet.test", allowInvalid: true); + }); + + options + .Configure() + .Endpoint(IPAddress.Loopback, basePort + 5) + .LocalhostEndpoint(basePort + 6) + .Load(); + + options + .Configure(context.Configuration.GetSection("Kestrel")) + .Endpoint("NamedEndpoint", opt => + { + opt.ListenOptions.Protocols = HttpProtocols.Http1; + }) + .Endpoint("NamedHttpsEndpoint", opt => + { + opt.HttpsOptions.SslProtocols = SslProtocols.Tls12; + }); + options.UseSystemd(); // The following section should be used to demo sockets @@ -96,5 +142,14 @@ namespace SampleApp return hostBuilder.Build().RunAsync(); } + + private static void ShowConfig(IConfiguration config) + { + foreach (var pair in config.GetChildren()) + { + Console.WriteLine($"{pair.Path} - {pair.Value}"); + ShowConfig(pair); + } + } } } \ No newline at end of file diff --git a/samples/SampleApp/appsettings.Development.json b/samples/SampleApp/appsettings.Development.json new file mode 100644 index 0000000000..9edfa91a20 --- /dev/null +++ b/samples/SampleApp/appsettings.Development.json @@ -0,0 +1,15 @@ +{ + "Kestrel": { + "Endpoints": { + "NamedEndpoint": { "Url": "http://localhost:6000" }, + "NamedHttpsEndpoint": { + "Url": "https://localhost:6443", + "Certificate": { + "Subject": "aspnet.test", + "Store": "My", + "AllowInvalid": true + } + } + } + } +} diff --git a/samples/SampleApp/appsettings.Production.json b/samples/SampleApp/appsettings.Production.json new file mode 100644 index 0000000000..8719fb89b7 --- /dev/null +++ b/samples/SampleApp/appsettings.Production.json @@ -0,0 +1,14 @@ +{ + "Kestrel": { + "Endpoints": { + "NamedEndpoint": { "Url": "http://*:6000" }, + "NamedHttpsEndpoint": { + "Url": "https://*:6443", + "Certificate": { + "Path": "testCert.pfx", + "Password": "testPassword" + } + } + } + } +} diff --git a/samples/SampleApp/appsettings.json b/samples/SampleApp/appsettings.json new file mode 100644 index 0000000000..cd77ddd218 --- /dev/null +++ b/samples/SampleApp/appsettings.json @@ -0,0 +1,6 @@ +{ + "Kestrel": { + "Endpoints": { + } + } +} diff --git a/samples/SystemdTestApp/Startup.cs b/samples/SystemdTestApp/Startup.cs new file mode 100644 index 0000000000..0b3c5e05de --- /dev/null +++ b/samples/SystemdTestApp/Startup.cs @@ -0,0 +1,92 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Diagnostics; +using System.IO; +using System.Net; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Logging; + +namespace SystemdTestApp +{ + public class Startup + { + public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory) + { + var logger = loggerFactory.CreateLogger("Default"); + + app.Run(async context => + { + var connectionFeature = context.Connection; + logger.LogDebug($"Peer: {connectionFeature.RemoteIpAddress?.ToString()}:{connectionFeature.RemotePort}" + + $"{Environment.NewLine}" + + $"Sock: {connectionFeature.LocalIpAddress?.ToString()}:{connectionFeature.LocalPort}"); + + var response = $"hello, world{Environment.NewLine}"; + context.Response.ContentLength = response.Length; + context.Response.ContentType = "text/plain"; + await context.Response.WriteAsync(response); + }); + } + + public static Task Main(string[] args) + { + TaskScheduler.UnobservedTaskException += (sender, e) => + { + Console.WriteLine("Unobserved exception: {0}", e.Exception); + }; + + var hostBuilder = new WebHostBuilder() + .ConfigureLogging((_, factory) => + { + factory.AddConsole(); + }) + .UseKestrel((context, options) => + { + var basePort = context.Configuration.GetValue("BASE_PORT") ?? 5000; + + // Run callbacks on the transport thread + options.ApplicationSchedulingMode = SchedulingMode.Inline; + + options.Listen(IPAddress.Loopback, basePort, listenOptions => + { + // Uncomment the following to enable Nagle's algorithm for this endpoint. + //listenOptions.NoDelay = false; + + listenOptions.UseConnectionLogging(); + }); + + options.Listen(IPAddress.Loopback, basePort + 1, listenOptions => + { + listenOptions.UseHttps("testCert.pfx", "testPassword"); + listenOptions.UseConnectionLogging(); + }); + + options.UseSystemd(); + + // The following section should be used to demo sockets + //options.ListenUnixSocket("/tmp/kestrel-test.sock"); + }) + .UseContentRoot(Directory.GetCurrentDirectory()) + .UseStartup(); + + if (string.Equals(Process.GetCurrentProcess().Id.ToString(), Environment.GetEnvironmentVariable("LISTEN_PID"))) + { + // Use libuv if activated by systemd, since that's currently the only transport that supports being passed a socket handle. + hostBuilder.UseLibuv(options => + { + // Uncomment the following line to change the default number of libuv threads for all endpoints. + // options.ThreadCount = 4; + }); + } + + return hostBuilder.Build().RunAsync(); + } + } +} \ No newline at end of file diff --git a/samples/SystemdTestApp/SystemdTestApp.csproj b/samples/SystemdTestApp/SystemdTestApp.csproj new file mode 100644 index 0000000000..08a5547858 --- /dev/null +++ b/samples/SystemdTestApp/SystemdTestApp.csproj @@ -0,0 +1,23 @@ + + + + netcoreapp2.1;netcoreapp2.0;net461 + false + true + + + + + + + + + + + + + PreserveNewest + + + + diff --git a/samples/SystemdTestApp/testCert.pfx b/samples/SystemdTestApp/testCert.pfx new file mode 100644 index 0000000000000000000000000000000000000000..7118908c2d730670c16e9f8b2c532a262c951989 GIT binary patch literal 2483 zcmaKuc|27A8pqF>IWr86E&Q@(n=B)p$ug!;QVB6xij*z;uPLG!yCz#DQB)+9G$9m9 zQU)=DWXU?*EZIwG!+0d++P@yZ4Xhoagg?p6B~|Ue7tN=Ny=UD?x#1n1MTq z#c9MHh+D#gd|(a(cN}8i91v^=GcdgW3SmA$49p~gM-dys3jVWdg8+!iVL)pz1LDE5 zSb=|GAn(@R=(Ux!MfS9@}sFu-xDd zIt2+mqSq$glwy_6UNs<2?(qERU!gJ;5j}Pp&6trxG=wi)=@k(w2+fJVnc+qvXVzy(>Om4;L|^)R`t*3nTpAmEmTl(#i!RV#a0t#u6>Q9mY`-Nmcs7$XjXT7 zUmCD`O~_j7!%R#I?cG-7C^hcH)@l?WC1vyw$FFu_(r)jhOq6p}W8sG7NO{YTy8tG4 zrb$tTkag*G?(7lfoGx$4YWui>{{@}-FB2ub=}RX{1zx?j)s-##J9|G7E1@-;7Nuln z9MQoX7FJ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Ira@s&d968y-y}Y|ww(R$GzWS*V&)k@W0>Slem{|HdTCjm;_5 zwY*A8W3nUbemE^_f0ng$tbd<`sr?TO-_&VCw+F#7P@LkIl$1PzTBoPY1b88EIO>UO zP-NK7+g2yD3U6g3i|iA6+su>54sf_Sk0F=)1|9odnCM4u2Rs z=&Y?-V&VquSN%3FJ2~ZGweP~iLs|w=l@9yu$tj@}Dp?e-2JUsqOoswdXb=E%&0te_ zA2M+{5Hf-dqD7=yw*r@A*xkn(1IS~nfP}k}e?4Bt|9g(eph4hFX_|S6nj1&Sz9z^= zRw~<&-9d@FzTn6S*RVE{Wj5lgLJr9HLB8S9CgOm*>XA8*y4`JE;^s$=bqD#U4;e5C&x&ggKIAVL zrQ)Yd8|{>7Z(6*B&7&4&9(*vDOfHMuR-Dk1IZia*XM^EZUD^{?cWG>J>KrtElc*{K zaVl(7SN2cH4I6Q$bZOpJ8e5LKaG7p;?tJ~#+9QrTYU@f#5`Vo7cEX!szCT}iX-K^2 w#3o+=C+lQz2J+SOEzVX(eJ)e7=eicC{rr9U2VGDcdH?_b literal 0 HcmV?d00001 diff --git a/src/Kestrel.Core/CoreStrings.resx b/src/Kestrel.Core/CoreStrings.resx index 49ee7e20b8..2babfee801 100644 --- a/src/Kestrel.Core/CoreStrings.resx +++ b/src/Kestrel.Core/CoreStrings.resx @@ -480,4 +480,19 @@ The server certificate parameter is required. + + No listening endpoints were configured. Binding to {address0} and {address1} by default. + + + The requested certificate {subject} could not be found in {storeLocation}/{storeName} with AllowInvalid setting: {allowInvalid}. + + + The endpoint {endpointName} is missing the required 'Url' parameter. + + + Unable to configure HTTPS endpoint. No server certificate was specified and the default developer certificate could not be found. Try running 'dotnet developercertificates https -t' to setup a developer certificate for use with localhost. For information on configuring HTTPS see https://go.microsoft.com/fwlink/?linkid=848054 + + + The endpoint {endpointName} specified multiple certificate sources. + \ No newline at end of file diff --git a/src/Kestrel.Core/EndpointConfiguration.cs b/src/Kestrel.Core/EndpointConfiguration.cs new file mode 100644 index 0000000000..94848b14bd --- /dev/null +++ b/src/Kestrel.Core/EndpointConfiguration.cs @@ -0,0 +1,26 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using Microsoft.AspNetCore.Server.Kestrel.Core; +using Microsoft.AspNetCore.Server.Kestrel.Https; +using Microsoft.Extensions.Configuration; + +namespace Microsoft.AspNetCore.Server.Kestrel +{ + public class EndpointConfiguration + { + internal EndpointConfiguration(bool isHttps, ListenOptions listenOptions, HttpsConnectionAdapterOptions httpsOptions, IConfigurationSection configSection) + { + IsHttps = isHttps; + ListenOptions = listenOptions ?? throw new ArgumentNullException(nameof(listenOptions)); + HttpsOptions = httpsOptions ?? throw new ArgumentNullException(nameof(httpsOptions)); + ConfigSection = configSection ?? throw new ArgumentNullException(nameof(configSection)); + } + + public bool IsHttps { get; } + public ListenOptions ListenOptions { get; } + public HttpsConnectionAdapterOptions HttpsOptions { get; } + public IConfigurationSection ConfigSection { get; } + } +} diff --git a/src/Kestrel.Core/Internal/AddressBindContext.cs b/src/Kestrel.Core/Internal/AddressBindContext.cs index e2f46e6025..f4c1859b7f 100644 --- a/src/Kestrel.Core/Internal/AddressBindContext.cs +++ b/src/Kestrel.Core/Internal/AddressBindContext.cs @@ -14,7 +14,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal public List ListenOptions { get; set; } public KestrelServerOptions ServerOptions { get; set; } public ILogger Logger { get; set; } - public IDefaultHttpsProvider DefaultHttpsProvider { get; set; } public Func CreateBinding { get; set; } } diff --git a/src/Kestrel.Core/Internal/AddressBinder.cs b/src/Kestrel.Core/Internal/AddressBinder.cs index 5334308ad8..96ec14e51b 100644 --- a/src/Kestrel.Core/Internal/AddressBinder.cs +++ b/src/Kestrel.Core/Internal/AddressBinder.cs @@ -8,6 +8,7 @@ using System.Linq; using System.Net; using System.Threading.Tasks; using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting.Server.Features; using Microsoft.AspNetCore.Protocols; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; @@ -20,7 +21,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal public static async Task BindAsync(IServerAddressesFeature addresses, KestrelServerOptions serverOptions, ILogger logger, - IDefaultHttpsProvider defaultHttpsProvider, Func createBinding) { var listenOptions = serverOptions.ListenOptions; @@ -35,7 +35,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal ListenOptions = listenOptions, ServerOptions = serverOptions, Logger = logger, - DefaultHttpsProvider = defaultHttpsProvider ?? UnconfiguredDefaultHttpsProvider.Instance, CreateBinding = createBinding }; @@ -112,10 +111,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal context.ListenOptions.Add(endpoint); } - internal static ListenOptions ParseAddress(string address, KestrelServerOptions serverOptions, IDefaultHttpsProvider defaultHttpsProvider) + internal static ListenOptions ParseAddress(string address, out bool https) { var parsedAddress = ServerAddress.FromUrl(address); - var https = false; + https = false; if (parsedAddress.Scheme.Equals("https", StringComparison.OrdinalIgnoreCase)) { @@ -151,12 +150,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal options = new AnyIPListenOptions(parsedAddress.Port); } - if (https) - { - options.KestrelServerOptions = serverOptions; - defaultHttpsProvider.ConfigureHttps(options); - } - return options; } @@ -169,10 +162,26 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal { public async Task BindAsync(AddressBindContext context) { - context.Logger.LogDebug(CoreStrings.BindingToDefaultAddress, Constants.DefaultServerAddress); + var httpDefault = ParseAddress(Constants.DefaultServerAddress, out var https); + context.ServerOptions.ApplyEndpointDefaults(httpDefault); + await httpDefault.BindAsync(context).ConfigureAwait(false); - await ParseAddress(Constants.DefaultServerAddress, context.ServerOptions, context.DefaultHttpsProvider) - .BindAsync(context).ConfigureAwait(false); + // Conditional https default, only if a cert is available + var httpsDefault = ParseAddress(Constants.DefaultServerHttpsAddress, out https); + context.ServerOptions.ApplyEndpointDefaults(httpsDefault); + + if (httpsDefault.ConnectionAdapters.Any(f => f.IsHttps) + || httpsDefault.TryUseHttps()) + { + await httpsDefault.BindAsync(context).ConfigureAwait(false); + context.Logger.LogDebug(CoreStrings.BindingToDefaultAddresses, + Constants.DefaultServerAddress, Constants.DefaultServerHttpsAddress); + } + else + { + // No default cert is available, do not bind to the https endpoint. + context.Logger.LogDebug(CoreStrings.BindingToDefaultAddress, Constants.DefaultServerAddress); + } } } @@ -242,27 +251,17 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal { foreach (var address in _addresses) { - await ParseAddress(address, context.ServerOptions, context.DefaultHttpsProvider) - .BindAsync(context).ConfigureAwait(false); + var options = ParseAddress(address, out var https); + context.ServerOptions.ApplyEndpointDefaults(options); + + if (https && !options.ConnectionAdapters.Any(f => f.IsHttps)) + { + options.UseHttps(); + } + + await options.BindAsync(context).ConfigureAwait(false); } } } - - private class UnconfiguredDefaultHttpsProvider : IDefaultHttpsProvider - { - public static readonly UnconfiguredDefaultHttpsProvider Instance = new UnconfiguredDefaultHttpsProvider(); - - private UnconfiguredDefaultHttpsProvider() - { - } - - public void ConfigureHttps(ListenOptions listenOptions) - { - // We have to throw here. If this is called, it's because the user asked for "https" binding but for some - // reason didn't provide a certificate and didn't use the "DefaultHttpsProvider". This means if we no-op, - // we'll silently downgrade to HTTP, which is bad. - throw new InvalidOperationException(CoreStrings.UnableToConfigureHttpsBindings); - } - } } } diff --git a/src/Kestrel.Core/Internal/CertificateLoader.cs b/src/Kestrel.Core/Internal/CertificateLoader.cs new file mode 100644 index 0000000000..087fad7d87 --- /dev/null +++ b/src/Kestrel.Core/Internal/CertificateLoader.cs @@ -0,0 +1,99 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Security.Cryptography.X509Certificates; +using System.Text; +using Microsoft.AspNetCore.Server.Kestrel.Core; + +namespace Microsoft.AspNetCore.Server.Kestrel.Https.Internal +{ + public static class CertificateLoader + { + // See http://oid-info.com/get/1.3.6.1.5.5.7.3.1 + // Indicates that a certificate can be used as a SSL server certificate + private const string ServerAuthenticationOid = "1.3.6.1.5.5.7.3.1"; + + public static X509Certificate2 LoadFromStoreCert(string subject, string storeName, StoreLocation storeLocation, bool allowInvalid) + { + using (var store = new X509Store(storeName, storeLocation)) + { + X509Certificate2Collection storeCertificates = null; + X509Certificate2 foundCertificate = null; + + try + { + store.Open(OpenFlags.ReadOnly); + storeCertificates = store.Certificates; + var foundCertificates = storeCertificates.Find(X509FindType.FindBySubjectName, subject, !allowInvalid); + foundCertificate = foundCertificates + .OfType() + .Where(IsCertificateAllowedForServerAuth) + .OrderByDescending(certificate => certificate.NotAfter) + .FirstOrDefault(); + + if (foundCertificate == null) + { + throw new InvalidOperationException(CoreStrings.FormatCertNotFoundInStore(subject, storeLocation, storeName, allowInvalid)); + } + + return foundCertificate; + } + finally + { + DisposeCertificates(storeCertificates, except: foundCertificate); + } + } + } + + internal static bool IsCertificateAllowedForServerAuth(X509Certificate2 certificate) + { + /* If the Extended Key Usage extension is included, then we check that the serverAuth usage is included. (http://oid-info.com/get/1.3.6.1.5.5.7.3.1) + * If the Extended Key Usage extension is not included, then we assume the certificate is allowed for all usages. + * + * See also https://blogs.msdn.microsoft.com/kaushal/2012/02/17/client-certificates-vs-server-certificates/ + * + * From https://tools.ietf.org/html/rfc3280#section-4.2.1.13 "Certificate Extensions: Extended Key Usage" + * + * If the (Extended Key Usage) extension is present, then the certificate MUST only be used + * for one of the purposes indicated. If multiple purposes are + * indicated the application need not recognize all purposes indicated, + * as long as the intended purpose is present. Certificate using + * applications MAY require that a particular purpose be indicated in + * order for the certificate to be acceptable to that application. + */ + + var hasEkuExtension = false; + + foreach (var extension in certificate.Extensions.OfType()) + { + hasEkuExtension = true; + foreach (var oid in extension.EnhancedKeyUsages) + { + if (oid.Value.Equals(ServerAuthenticationOid, StringComparison.Ordinal)) + { + return true; + } + } + } + + return !hasEkuExtension; + } + + private static void DisposeCertificates(X509Certificate2Collection certificates, X509Certificate2 except) + { + if (certificates != null) + { + foreach (var certificate in certificates) + { + if (!certificate.Equals(except)) + { + certificate.Dispose(); + } + } + } + } + } +} diff --git a/src/Kestrel.Core/Internal/ConfigurationReader.cs b/src/Kestrel.Core/Internal/ConfigurationReader.cs new file mode 100644 index 0000000000..08f347b922 --- /dev/null +++ b/src/Kestrel.Core/Internal/ConfigurationReader.cs @@ -0,0 +1,140 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Collections.Generic; +using System.Linq; +using Microsoft.Extensions.Configuration; + +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal +{ + internal class ConfigurationReader + { + private IConfiguration _configuration; + private IDictionary _certificates; + private IList _endpoints; + + public ConfigurationReader(IConfiguration configuration) + { + _configuration = configuration ?? throw new ArgumentNullException(nameof(configuration)); + } + + public IDictionary Certificates + { + get + { + if (_certificates == null) + { + ReadCertificates(); + } + + return _certificates; + } + } + + public IEnumerable Endpoints + { + get + { + if (_endpoints == null) + { + ReadEndpoints(); + } + + return _endpoints; + } + } + + private void ReadCertificates() + { + _certificates = new Dictionary(0); + + var certificatesConfig = _configuration.GetSection("Certificates").GetChildren(); + foreach (var certificateConfig in certificatesConfig) + { + _certificates.Add(certificateConfig.Key, new CertificateConfig(certificateConfig)); + } + } + + private void ReadEndpoints() + { + _endpoints = new List(); + + var endpointsConfig = _configuration.GetSection("Endpoints").GetChildren(); + foreach (var endpointConfig in endpointsConfig) + { + // "EndpointName": { +        // "Url": "https://*:5463", +        // "Certificate": { +          // "Path": "testCert.pfx", +          // "Password": "testPassword" +       // } + // } + + var url = endpointConfig["Url"]; + if (string.IsNullOrEmpty(url)) + { + throw new InvalidOperationException(CoreStrings.FormatEndpointMissingUrl(endpointConfig.Key)); + } + + var endpoint = new EndpointConfig() + { + Name = endpointConfig.Key, + Url = url, + ConfigSection = endpointConfig, + Certificate = new CertificateConfig(endpointConfig.GetSection("Certificate")), + }; + _endpoints.Add(endpoint); + } + } + } + + // "EndpointName": { + // "Url": "https://*:5463", + // "Certificate": { + // "Path": "testCert.pfx", + // "Password": "testPassword" + // } + // } + internal class EndpointConfig + { + public string Name { get; set; } + public string Url { get; set; } + public IConfigurationSection ConfigSection { get; set; } + public CertificateConfig Certificate { get; set; } + } + + // "CertificateName": { + // "Path": "testCert.pfx", + // "Password": "testPassword" + // } + internal class CertificateConfig + { + public CertificateConfig(IConfigurationSection configSection) + { + ConfigSection = configSection; + ConfigSection.Bind(this); + } + + public IConfigurationSection ConfigSection { get; } + + // File + public bool IsFileCert => !string.IsNullOrEmpty(Path); + + public string Path { get; set; } + + public string Password { get; set; } + + // Cert store + + public bool IsStoreCert => !string.IsNullOrEmpty(Subject); + + public string Subject { get; set; } + + public string Store { get; set; } + + public string Location { get; set; } + + public bool? AllowInvalid { get; set; } + } +} diff --git a/src/Kestrel.Core/Internal/HttpsConnectionAdapter.cs b/src/Kestrel.Core/Internal/HttpsConnectionAdapter.cs index 68043a0762..cae7d60b2f 100644 --- a/src/Kestrel.Core/Internal/HttpsConnectionAdapter.cs +++ b/src/Kestrel.Core/Internal/HttpsConnectionAdapter.cs @@ -19,10 +19,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Https.Internal { public class HttpsConnectionAdapter : IConnectionAdapter { - // See http://oid-info.com/get/1.3.6.1.5.5.7.3.1 - // Indicates that a certificate can be used as a SSL server certificate - private const string ServerAuthenticationOid = "1.3.6.1.5.5.7.3.1"; - private static readonly ClosedAdaptedConnection _closedAdaptedConnection = new ClosedAdaptedConnection(); private readonly HttpsConnectionAdapterOptions _options; @@ -187,36 +183,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Https.Internal private static void EnsureCertificateIsAllowedForServerAuth(X509Certificate2 certificate) { - /* If the Extended Key Usage extension is included, then we check that the serverAuth usage is included. (http://oid-info.com/get/1.3.6.1.5.5.7.3.1) - * If the Extended Key Usage extension is not included, then we assume the certificate is allowed for all usages. - * - * See also https://blogs.msdn.microsoft.com/kaushal/2012/02/17/client-certificates-vs-server-certificates/ - * - * From https://tools.ietf.org/html/rfc3280#section-4.2.1.13 "Certificate Extensions: Extended Key Usage" - * - * If the (Extended Key Usage) extension is present, then the certificate MUST only be used - * for one of the purposes indicated. If multiple purposes are - * indicated the application need not recognize all purposes indicated, - * as long as the intended purpose is present. Certificate using - * applications MAY require that a particular purpose be indicated in - * order for the certificate to be acceptable to that application. - */ - - var hasEkuExtension = false; - - foreach (var extension in certificate.Extensions.OfType()) - { - hasEkuExtension = true; - foreach (var oid in extension.EnhancedKeyUsages) - { - if (oid.Value.Equals(ServerAuthenticationOid, StringComparison.Ordinal)) - { - return; - } - } - } - - if (hasEkuExtension) + if (!CertificateLoader.IsCertificateAllowedForServerAuth(certificate)) { throw new InvalidOperationException(CoreStrings.FormatInvalidServerCertificateEku(certificate.Thumbprint)); } diff --git a/src/Kestrel.Core/Internal/IDefaultHttpsProvider.cs b/src/Kestrel.Core/Internal/IDefaultHttpsProvider.cs deleted file mode 100644 index 3ed67b0cda..0000000000 --- a/src/Kestrel.Core/Internal/IDefaultHttpsProvider.cs +++ /dev/null @@ -1,10 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal -{ - public interface IDefaultHttpsProvider - { - void ConfigureHttps(ListenOptions listenOptions); - } -} diff --git a/src/Kestrel.Core/Internal/Infrastructure/Constants.cs b/src/Kestrel.Core/Internal/Infrastructure/Constants.cs index 6db5d384ee..8aead7103c 100644 --- a/src/Kestrel.Core/Internal/Infrastructure/Constants.cs +++ b/src/Kestrel.Core/Internal/Infrastructure/Constants.cs @@ -10,10 +10,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure public const int MaxExceptionDetailSize = 128; /// - /// The IPEndPoint Kestrel will bind to if nothing else is specified. + /// The endpoint Kestrel will bind to if nothing else is specified. /// public static readonly string DefaultServerAddress = "http://localhost:5000"; + /// + /// The endpoint Kestrel will bind to if nothing else is specified and a default certificate is available. + /// + public static readonly string DefaultServerHttpsAddress = "https://localhost:5001"; + /// /// Prefix of host name used to specify Unix sockets in the configuration. /// diff --git a/src/Kestrel.Core/Internal/KestrelServerOptionsSetup.cs b/src/Kestrel.Core/Internal/KestrelServerOptionsSetup.cs index 4d7a95ca5b..18831f0b49 100644 --- a/src/Kestrel.Core/Internal/KestrelServerOptionsSetup.cs +++ b/src/Kestrel.Core/Internal/KestrelServerOptionsSetup.cs @@ -2,8 +2,12 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using Microsoft.AspNetCore.Hosting.Server.Features; +using System.Linq; +using System.Security.Cryptography.X509Certificates; +using Microsoft.AspNetCore.Certificates.Generation; +using Microsoft.AspNetCore.Server.Kestrel.Internal; using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal @@ -20,6 +24,24 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal public void Configure(KestrelServerOptions options) { options.ApplicationServices = _services; + UseDefaultDeveloperCertificate(options); + } + + private void UseDefaultDeveloperCertificate(KestrelServerOptions options) + { + var certificateManager = new CertificateManager(); + var certificate = certificateManager.ListCertificates(CertificatePurpose.HTTPS, StoreName.My, StoreLocation.CurrentUser, isValid: true) + .FirstOrDefault(); + var logger = options.ApplicationServices.GetRequiredService>(); + if (certificate != null) + { + logger.LocatedDevelopmentCertificate(certificate); + options.DefaultCertificate = certificate; + } + else + { + logger.UnableToLocateDevelopmentCertificate(); + } } } } diff --git a/src/Kestrel/Internal/LoggerExtensions.cs b/src/Kestrel.Core/Internal/LoggerExtensions.cs similarity index 94% rename from src/Kestrel/Internal/LoggerExtensions.cs rename to src/Kestrel.Core/Internal/LoggerExtensions.cs index 218f50ca10..1f3b8d131d 100644 --- a/src/Kestrel/Internal/LoggerExtensions.cs +++ b/src/Kestrel.Core/Internal/LoggerExtensions.cs @@ -11,7 +11,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal LoggerMessage.Define(LogLevel.Debug, new EventId(0, nameof(LocatedDevelopmentCertificate)), "Using development certificate: {certificateSubjectName} (Thumbprint: {certificateThumbprint})"); private static readonly Action _unableToLocateDevelopmentCertificate = - LoggerMessage.Define(LogLevel.Error, new EventId(1, nameof(UnableToLocateDevelopmentCertificate)), "Unable to locate an appropriate development https certificate."); + LoggerMessage.Define(LogLevel.Debug, new EventId(1, nameof(UnableToLocateDevelopmentCertificate)), "Unable to locate an appropriate development https certificate."); public static void LocatedDevelopmentCertificate(this ILogger logger, X509Certificate2 certificate) => _locatedDevelopmentCertificate(logger, certificate.Subject, certificate.Thumbprint, null); diff --git a/src/Kestrel.Core/Kestrel.Core.csproj b/src/Kestrel.Core/Kestrel.Core.csproj index 75793650b5..2f6ea2a3bb 100644 --- a/src/Kestrel.Core/Kestrel.Core.csproj +++ b/src/Kestrel.Core/Kestrel.Core.csproj @@ -12,14 +12,17 @@ + + + diff --git a/src/Kestrel.Core/KestrelConfigurationLoader.cs b/src/Kestrel.Core/KestrelConfigurationLoader.cs new file mode 100644 index 0000000000..1dfb9d262c --- /dev/null +++ b/src/Kestrel.Core/KestrelConfigurationLoader.cs @@ -0,0 +1,297 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Net; +using System.Security.Cryptography.X509Certificates; +using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Server.Kestrel.Core; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal; +using Microsoft.AspNetCore.Server.Kestrel.Https; +using Microsoft.AspNetCore.Server.Kestrel.Https.Internal; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; + +namespace Microsoft.AspNetCore.Server.Kestrel +{ + public class KestrelConfigurationLoader + { + internal KestrelConfigurationLoader(KestrelServerOptions options, IConfiguration configuration) + { + Options = options ?? throw new ArgumentNullException(nameof(options)); + Configuration = configuration ?? throw new ArgumentNullException(nameof(configuration)); + } + + public KestrelServerOptions Options { get; } + public IConfiguration Configuration { get; } + private IDictionary> EndpointConfigurations { get; } + = new Dictionary>(0, StringComparer.OrdinalIgnoreCase); + // Actions that will be delayed until Load so that they aren't applied if the configuration loader is replaced. + private IList EndpointsToAdd { get; } = new List(); + + /// + /// Specifies a configuration Action to run when an endpoint with the given name is loaded from configuration. + /// + public KestrelConfigurationLoader Endpoint(string name, Action configureOptions) + { + if (string.IsNullOrEmpty(name)) + { + throw new ArgumentNullException(nameof(name)); + } + + EndpointConfigurations[name] = configureOptions ?? throw new ArgumentNullException(nameof(configureOptions)); + return this; + } + + /// + /// Bind to given IP address and port. + /// + public KestrelConfigurationLoader Endpoint(IPAddress address, int port) => Endpoint(address, port, _ => { }); + + /// + /// Bind to given IP address and port. + /// + public KestrelConfigurationLoader Endpoint(IPAddress address, int port, Action configure) + { + if (address == null) + { + throw new ArgumentNullException(nameof(address)); + } + + return Endpoint(new IPEndPoint(address, port), configure); + } + + /// + /// Bind to given IP endpoint. + /// + public KestrelConfigurationLoader Endpoint(IPEndPoint endPoint) => Endpoint(endPoint, _ => { }); + + /// + /// Bind to given IP address and port. + /// + public KestrelConfigurationLoader Endpoint(IPEndPoint endPoint, Action configure) + { + if (endPoint == null) + { + throw new ArgumentNullException(nameof(endPoint)); + } + if (configure == null) + { + throw new ArgumentNullException(nameof(configure)); + } + + EndpointsToAdd.Add(() => + { + Options.Listen(endPoint, configure); + }); + + return this; + } + + /// + /// Listens on ::1 and 127.0.0.1 with the given port. Requesting a dynamic port by specifying 0 is not supported + /// for this type of endpoint. + /// + public KestrelConfigurationLoader LocalhostEndpoint(int port) => LocalhostEndpoint(port, options => { }); + + /// + /// Listens on ::1 and 127.0.0.1 with the given port. Requesting a dynamic port by specifying 0 is not supported + /// for this type of endpoint. + /// + public KestrelConfigurationLoader LocalhostEndpoint(int port, Action configure) + { + if (configure == null) + { + throw new ArgumentNullException(nameof(configure)); + } + + EndpointsToAdd.Add(() => + { + Options.ListenLocalhost(port, configure); + }); + + return this; + } + + /// + /// Listens on all IPs using IPv6 [::], or IPv4 0.0.0.0 if IPv6 is not supported. + /// + public KestrelConfigurationLoader AnyIPEndpoint(int port) => AnyIPEndpoint(port, options => { }); + + /// + /// Listens on all IPs using IPv6 [::], or IPv4 0.0.0.0 if IPv6 is not supported. + /// + public KestrelConfigurationLoader AnyIPEndpoint(int port, Action configure) + { + if (configure == null) + { + throw new ArgumentNullException(nameof(configure)); + } + + EndpointsToAdd.Add(() => + { + Options.ListenAnyIP(port, configure); + }); + + return this; + } + + /// + /// Bind to given Unix domain socket path. + /// + public KestrelConfigurationLoader UnixSocketEndpoint(string socketPath) => UnixSocketEndpoint(socketPath, _ => { }); + + /// + /// Bind to given Unix domain socket path. + /// + public KestrelConfigurationLoader UnixSocketEndpoint(string socketPath, Action configure) + { + if (socketPath == null) + { + throw new ArgumentNullException(nameof(socketPath)); + } + if (socketPath.Length == 0 || socketPath[0] != '/') + { + throw new ArgumentException(CoreStrings.UnixSocketPathMustBeAbsolute, nameof(socketPath)); + } + if (configure == null) + { + throw new ArgumentNullException(nameof(configure)); + } + + EndpointsToAdd.Add(() => + { + Options.ListenUnixSocket(socketPath, configure); + }); + + return this; + } + + /// + /// Open a socket file descriptor. + /// + public KestrelConfigurationLoader HandleEndpoint(ulong handle) => HandleEndpoint(handle, _ => { }); + + /// + /// Open a socket file descriptor. + /// + public KestrelConfigurationLoader HandleEndpoint(ulong handle, Action configure) + { + if (configure == null) + { + throw new ArgumentNullException(nameof(configure)); + } + + EndpointsToAdd.Add(() => + { + Options.ListenHandle(handle, configure); + }); + + return this; + } + + public void Load() + { + if (Options.ConfigurationLoader == null) + { + // The loader has already been run. + return; + } + Options.ConfigurationLoader = null; + + var configReader = new ConfigurationReader(Configuration); + + LoadDefaultCert(configReader); + + foreach (var endpoint in configReader.Endpoints) + { + var listenOptions = AddressBinder.ParseAddress(endpoint.Url, out var https); + Options.ApplyEndpointDefaults(listenOptions); + + // Compare to UseHttps(httpsOptions => { }) + var httpsOptions = new HttpsConnectionAdapterOptions(); + if (https) + { + // Defaults + Options.ApplyHttpsDefaults(httpsOptions); + + // Specified + httpsOptions.ServerCertificate = LoadCertificate(endpoint.Certificate, endpoint.Name) + ?? httpsOptions.ServerCertificate; + } + + if (EndpointConfigurations.TryGetValue(endpoint.Name, out var configureEndpoint)) + { + var endpointConfig = new EndpointConfiguration(https, listenOptions, httpsOptions, endpoint.ConfigSection); + configureEndpoint(endpointConfig); + } + + // EndpointDefaults or configureEndpoint may have added an https adapter. + if (https && !listenOptions.ConnectionAdapters.Any(f => f.IsHttps)) + { + if (httpsOptions.ServerCertificate == null) + { + throw new InvalidOperationException(CoreStrings.NoCertSpecifiedNoDevelopmentCertificateFound); + } + + listenOptions.UseHttps(httpsOptions); + } + + Options.ListenOptions.Add(listenOptions); + } + + foreach (var action in EndpointsToAdd) + { + action(); + } + } + + private void LoadDefaultCert(ConfigurationReader configReader) + { + if (configReader.Certificates.TryGetValue("Default", out var defaultCertConfig)) + { + var defaultCert = LoadCertificate(defaultCertConfig, "Default"); + if (defaultCert != null) + { + Options.DefaultCertificate = defaultCert; + } + } + } + + private X509Certificate2 LoadCertificate(CertificateConfig certInfo, string endpointName) + { + if (certInfo.IsFileCert && certInfo.IsStoreCert) + { + throw new InvalidOperationException(CoreStrings.FormatMultipleCertificateSources(endpointName)); + } + else if (certInfo.IsFileCert) + { + var env = Options.ApplicationServices.GetRequiredService(); + return new X509Certificate2(Path.Combine(env.ContentRootPath, certInfo.Path), certInfo.Password); + } + else if (certInfo.IsStoreCert) + { + return LoadFromStoreCert(certInfo); + } + return null; + } + + private static X509Certificate2 LoadFromStoreCert(CertificateConfig certInfo) + { + var subject = certInfo.Subject; + var storeName = certInfo.Store; + var location = certInfo.Location; + var storeLocation = StoreLocation.CurrentUser; + if (!string.IsNullOrEmpty(location)) + { + storeLocation = (StoreLocation)Enum.Parse(typeof(StoreLocation), location, ignoreCase: true); + } + var allowInvalid = certInfo.AllowInvalid ?? false; + + return CertificateLoader.LoadFromStoreCert(subject, storeName, storeLocation, allowInvalid); + } + } +} diff --git a/src/Kestrel.Core/KestrelServer.cs b/src/Kestrel.Core/KestrelServer.cs index 1905ab7bc6..43b7ee3981 100644 --- a/src/Kestrel.Core/KestrelServer.cs +++ b/src/Kestrel.Core/KestrelServer.cs @@ -22,7 +22,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core private readonly List _transports = new List(); private readonly Heartbeat _heartbeat; private readonly IServerAddressesFeature _serverAddresses; - private readonly IDefaultHttpsProvider _defaultHttpsProvider; private readonly ITransportFactory _transportFactory; private bool _hasStarted; @@ -34,12 +33,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core { } - public KestrelServer(IOptions options, ITransportFactory transportFactory, ILoggerFactory loggerFactory, IDefaultHttpsProvider defaultHttpsProvider) - : this(transportFactory, CreateServiceContext(options, loggerFactory)) - { - _defaultHttpsProvider = defaultHttpsProvider; - } - // For testing internal KestrelServer(ITransportFactory transportFactory, ServiceContext serviceContext) { @@ -159,7 +152,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core await transport.BindAsync().ConfigureAwait(false); } - await AddressBinder.BindAsync(_serverAddresses, Options, Trace, _defaultHttpsProvider, OnBind).ConfigureAwait(false); + await AddressBinder.BindAsync(_serverAddresses, Options, Trace, OnBind).ConfigureAwait(false); } catch (Exception ex) { @@ -224,6 +217,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core private void ValidateOptions() { + Options.ConfigurationLoader?.Load(); + if (Options.Limits.MaxRequestBufferSize.HasValue && Options.Limits.MaxRequestBufferSize < Options.Limits.MaxRequestLineSize) { diff --git a/src/Kestrel.Core/KestrelServerOptions.cs b/src/Kestrel.Core/KestrelServerOptions.cs index 3d70664cbe..b4354d4c0a 100644 --- a/src/Kestrel.Core/KestrelServerOptions.cs +++ b/src/Kestrel.Core/KestrelServerOptions.cs @@ -4,8 +4,11 @@ using System; using System.Collections.Generic; using System.Net; +using System.Security.Cryptography.X509Certificates; using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Server.Kestrel.Https; using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; +using Microsoft.Extensions.Configuration; namespace Microsoft.AspNetCore.Server.Kestrel.Core { @@ -55,6 +58,78 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core /// public KestrelServerLimits Limits { get; } = new KestrelServerLimits(); + /// + /// Provides a configuration source where endpoints will be loaded from on server start. + /// The default is null. + /// + public KestrelConfigurationLoader ConfigurationLoader { get; set; } + + /// + /// A default configuration action for all endpoints. Use for Listen, configuration, the default url, and URLs. + /// + private Action EndpointDefaults { get; set; } = _ => { }; + + /// + /// A default configuration action for all https endpoints. + /// + private Action HttpsDefaults { get; set; } = _ => { }; + + /// + /// The default server certificate for https endpoints. This is applied before HttpsDefaults. + /// + internal X509Certificate2 DefaultCertificate { get; set; } + + /// + /// Specifies a configuration Action to run for each newly created endpoint. Calling this again will replace + /// the prior action. + /// + public void ConfigureEndpointDefaults(Action configureOptions) + { + EndpointDefaults = configureOptions ?? throw new ArgumentNullException(nameof(configureOptions)); + } + + internal void ApplyEndpointDefaults(ListenOptions listenOptions) + { + listenOptions.KestrelServerOptions = this; + EndpointDefaults(listenOptions); + } + + /// + /// Specifies a configuration Action to run for each newly created https endpoint. Calling this again will replace + /// the prior action. + /// + public void ConfigureHttpsDefaults(Action configureOptions) + { + HttpsDefaults = configureOptions ?? throw new ArgumentNullException(nameof(configureOptions)); + } + + internal void ApplyHttpsDefaults(HttpsConnectionAdapterOptions httpsOptions) + { + httpsOptions.ServerCertificate = DefaultCertificate; + HttpsDefaults(httpsOptions); + } + + /// + /// Creates a configuration loader for setting up Kestrel. + /// + public KestrelConfigurationLoader Configure() + { + var loader = new KestrelConfigurationLoader(this, new ConfigurationBuilder().Build()); + ConfigurationLoader = loader; + return loader; + } + + /// + /// Creates a configuration loader for setting up Kestrel that takes an IConfiguration as input. + /// This configuration must be scoped to the configuration section for Kestrel. + /// + public KestrelConfigurationLoader Configure(IConfiguration config) + { + var loader = new KestrelConfigurationLoader(this, config); + ConfigurationLoader = loader; + return loader; + } + /// /// Bind to given IP address and port. /// @@ -100,13 +175,22 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core throw new ArgumentNullException(nameof(configure)); } - var listenOptions = new ListenOptions(endPoint) { KestrelServerOptions = this }; + var listenOptions = new ListenOptions(endPoint); + ApplyEndpointDefaults(listenOptions); configure(listenOptions); ListenOptions.Add(listenOptions); } + /// + /// Listens on ::1 and 127.0.0.1 with the given port. Requesting a dynamic port by specifying 0 is not supported + /// for this type of endpoint. + /// public void ListenLocalhost(int port) => ListenLocalhost(port, options => { }); + /// + /// Listens on ::1 and 127.0.0.1 with the given port. Requesting a dynamic port by specifying 0 is not supported + /// for this type of endpoint. + /// public void ListenLocalhost(int port, Action configure) { if (configure == null) @@ -114,16 +198,20 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core throw new ArgumentNullException(nameof(configure)); } - var listenOptions = new LocalhostListenOptions(port) - { - KestrelServerOptions = this, - }; + var listenOptions = new LocalhostListenOptions(port); + ApplyEndpointDefaults(listenOptions); configure(listenOptions); ListenOptions.Add(listenOptions); } + /// + /// Listens on all IPs using IPv6 [::], or IPv4 0.0.0.0 if IPv6 is not supported. + /// public void ListenAnyIP(int port) => ListenAnyIP(port, options => { }); + /// + /// Listens on all IPs using IPv6 [::], or IPv4 0.0.0.0 if IPv6 is not supported. + /// public void ListenAnyIP(int port, Action configure) { if (configure == null) @@ -131,10 +219,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core throw new ArgumentNullException(nameof(configure)); } - var listenOptions = new AnyIPListenOptions(port) - { - KestrelServerOptions = this, - }; + var listenOptions = new AnyIPListenOptions(port); + ApplyEndpointDefaults(listenOptions); configure(listenOptions); ListenOptions.Add(listenOptions); } @@ -166,7 +252,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core throw new ArgumentNullException(nameof(configure)); } - var listenOptions = new ListenOptions(socketPath) { KestrelServerOptions = this }; + var listenOptions = new ListenOptions(socketPath); + ApplyEndpointDefaults(listenOptions); configure(listenOptions); ListenOptions.Add(listenOptions); } @@ -190,7 +277,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core throw new ArgumentNullException(nameof(configure)); } - var listenOptions = new ListenOptions(handle) { KestrelServerOptions = this }; + var listenOptions = new ListenOptions(handle); + ApplyEndpointDefaults(listenOptions); configure(listenOptions); ListenOptions.Add(listenOptions); } diff --git a/src/Kestrel.Core/ListenOptionsHttpsExtensions.cs b/src/Kestrel.Core/ListenOptionsHttpsExtensions.cs index 68f2e71ef1..6a03648746 100644 --- a/src/Kestrel.Core/ListenOptionsHttpsExtensions.cs +++ b/src/Kestrel.Core/ListenOptionsHttpsExtensions.cs @@ -1,9 +1,11 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; using System.IO; using System.Security.Cryptography.X509Certificates; using Microsoft.AspNetCore.Server.Kestrel.Core; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal; using Microsoft.AspNetCore.Server.Kestrel.Https; using Microsoft.AspNetCore.Server.Kestrel.Https.Internal; using Microsoft.Extensions.DependencyInjection; @@ -16,18 +18,21 @@ namespace Microsoft.AspNetCore.Hosting /// public static class ListenOptionsHttpsExtensions { + /// + /// Configure Kestrel to use HTTPS with the default certificate if available. + /// This will throw if no default certificate is configured. + /// + /// The to configure. + /// The . + public static ListenOptions UseHttps(this ListenOptions listenOptions) => listenOptions.UseHttps(_ => { }); + /// /// Configure Kestrel to use HTTPS. /// - /// - /// The to configure. - /// - /// - /// The name of a certificate file, relative to the directory that contains the application content files. - /// - /// - /// The . - /// + /// The to configure. + /// The name of a certificate file, relative to the directory that contains the application + /// content files. + /// The . public static ListenOptions UseHttps(this ListenOptions listenOptions, string fileName) { var env = listenOptions.KestrelServerOptions.ApplicationServices.GetRequiredService(); @@ -37,18 +42,11 @@ namespace Microsoft.AspNetCore.Hosting /// /// Configure Kestrel to use HTTPS. /// - /// - /// The to configure. - /// - /// - /// The name of a certificate file, relative to the directory that contains the application content files. - /// - /// - /// The password required to access the X.509 certificate data. - /// - /// - /// The . - /// + /// The to configure. + /// The name of a certificate file, relative to the directory that contains the application + /// content files. + /// The password required to access the X.509 certificate data. + /// The . public static ListenOptions UseHttps(this ListenOptions listenOptions, string fileName, string password) { var env = listenOptions.KestrelServerOptions.ApplicationServices.GetRequiredService(); @@ -58,32 +56,157 @@ namespace Microsoft.AspNetCore.Hosting /// /// Configure Kestrel to use HTTPS. /// - /// - /// The to configure. - /// - /// - /// The X.509 certificate. - /// - /// - /// The . - /// - public static ListenOptions UseHttps(this ListenOptions listenOptions, X509Certificate2 serverCertificate) + /// The to configure. + /// The name of a certificate file, relative to the directory that contains the application content files. + /// The password required to access the X.509 certificate data. + /// An Action to configure the . + /// The . + public static ListenOptions UseHttps(this ListenOptions listenOptions, string fileName, string password, + Action configureOptions) { - return listenOptions.UseHttps(new HttpsConnectionAdapterOptions { ServerCertificate = serverCertificate }); + var env = listenOptions.KestrelServerOptions.ApplicationServices.GetRequiredService(); + return listenOptions.UseHttps(new X509Certificate2(Path.Combine(env.ContentRootPath, fileName), password), configureOptions); } /// /// Configure Kestrel to use HTTPS. /// - /// - /// The to configure. - /// - /// - /// Options to configure HTTPS. - /// - /// - /// The . - /// + /// The to configure. + /// The certificate store to load the certificate from. + /// The subject name for the certificate to load. + /// The . + public static ListenOptions UseHttps(this ListenOptions listenOptions, StoreName storeName, string subject) + => listenOptions.UseHttps(storeName, subject, allowInvalid: false); + + /// + /// Configure Kestrel to use HTTPS. + /// + /// The to configure. + /// The certificate store to load the certificate from. + /// The subject name for the certificate to load. + /// Indicates if invalid certificates should be considered, such as self-signed certificates. + /// The . + public static ListenOptions UseHttps(this ListenOptions listenOptions, StoreName storeName, string subject, bool allowInvalid) + => listenOptions.UseHttps(storeName, subject, allowInvalid, StoreLocation.CurrentUser); + + /// + /// Configure Kestrel to use HTTPS. + /// + /// The to configure. + /// The certificate store to load the certificate from. + /// The subject name for the certificate to load. + /// Indicates if invalid certificates should be considered, such as self-signed certificates. + /// The store location to load the certificate from. + /// The . + public static ListenOptions UseHttps(this ListenOptions listenOptions, StoreName storeName, string subject, bool allowInvalid, StoreLocation location) + => listenOptions.UseHttps(storeName, subject, allowInvalid, location, configureOptions: _ => { }); + + /// + /// Configure Kestrel to use HTTPS. + /// + /// The to configure. + /// The certificate store to load the certificate from. + /// The subject name for the certificate to load. + /// Indicates if invalid certificates should be considered, such as self-signed certificates. + /// The store location to load the certificate from. + /// An Action to configure the . + /// The . + public static ListenOptions UseHttps(this ListenOptions listenOptions, StoreName storeName, string subject, bool allowInvalid, StoreLocation location, + Action configureOptions) + { + return listenOptions.UseHttps(CertificateLoader.LoadFromStoreCert(subject, storeName.ToString(), location, allowInvalid), configureOptions); + } + + /// + /// Configure Kestrel to use HTTPS. + /// + /// The to configure. + /// The X.509 certificate. + /// The . + public static ListenOptions UseHttps(this ListenOptions listenOptions, X509Certificate2 serverCertificate) + { + if (serverCertificate == null) + { + throw new ArgumentNullException(nameof(serverCertificate)); + } + + return listenOptions.UseHttps(options => + { + options.ServerCertificate = serverCertificate; + }); + } + + /// + /// Configure Kestrel to use HTTPS. + /// + /// The to configure. + /// The X.509 certificate. + /// An Action to configure the . + /// The . + public static ListenOptions UseHttps(this ListenOptions listenOptions, X509Certificate2 serverCertificate, + Action configureOptions) + { + if (serverCertificate == null) + { + throw new ArgumentNullException(nameof(serverCertificate)); + } + + if (configureOptions == null) + { + throw new ArgumentNullException(nameof(configureOptions)); + } + + return listenOptions.UseHttps(options => + { + options.ServerCertificate = serverCertificate; + configureOptions(options); + }); + } + + /// + /// Configure Kestrel to use HTTPS. + /// + /// The to configure. + /// An action to configure options for HTTPS. + /// The . + public static ListenOptions UseHttps(this ListenOptions listenOptions, Action configureOptions) + { + if (configureOptions == null) + { + throw new ArgumentNullException(nameof(configureOptions)); + } + + var options = new HttpsConnectionAdapterOptions(); + listenOptions.KestrelServerOptions.ApplyHttpsDefaults(options); + configureOptions(options); + + if (options.ServerCertificate == null) + { + throw new InvalidOperationException(CoreStrings.NoCertSpecifiedNoDevelopmentCertificateFound); + } + return listenOptions.UseHttps(options); + } + + // Use Https if a default cert is available + internal static bool TryUseHttps(this ListenOptions listenOptions) + { + var options = new HttpsConnectionAdapterOptions(); + listenOptions.KestrelServerOptions.ApplyHttpsDefaults(options); + + if (options.ServerCertificate == null) + { + return false; + } + listenOptions.UseHttps(options); + return true; + } + + /// + /// Configure Kestrel to use HTTPS. + /// + /// The to configure. + /// Options to configure HTTPS. + /// The . public static ListenOptions UseHttps(this ListenOptions listenOptions, HttpsConnectionAdapterOptions httpsOptions) { var loggerFactory = listenOptions.KestrelServerOptions.ApplicationServices.GetRequiredService(); diff --git a/src/Kestrel.Core/Properties/AssemblyInfo.cs b/src/Kestrel.Core/Properties/AssemblyInfo.cs index e2d152d0d3..af17db4f34 100644 --- a/src/Kestrel.Core/Properties/AssemblyInfo.cs +++ b/src/Kestrel.Core/Properties/AssemblyInfo.cs @@ -3,6 +3,7 @@ using System.Runtime.CompilerServices; +[assembly: InternalsVisibleTo("Microsoft.AspNetCore.Server.Kestrel.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")] [assembly: InternalsVisibleTo("Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.FunctionalTests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")] [assembly: InternalsVisibleTo("Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.FunctionalTests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")] [assembly: InternalsVisibleTo("Microsoft.AspNetCore.Server.Kestrel.Core.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")] diff --git a/src/Kestrel.Core/Properties/CoreStrings.Designer.cs b/src/Kestrel.Core/Properties/CoreStrings.Designer.cs index 4e1d8cf2c7..ff2732087f 100644 --- a/src/Kestrel.Core/Properties/CoreStrings.Designer.cs +++ b/src/Kestrel.Core/Properties/CoreStrings.Designer.cs @@ -1704,6 +1704,76 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core internal static string FormatServiceCertificateRequired() => GetString("ServiceCertificateRequired"); + /// + /// No listening endpoints were configured. Binding to {address0} and {address1} by default. + /// + internal static string BindingToDefaultAddresses + { + get => GetString("BindingToDefaultAddresses"); + } + + /// + /// No listening endpoints were configured. Binding to {address0} and {address1} by default. + /// + internal static string FormatBindingToDefaultAddresses(object address0, object address1) + => string.Format(CultureInfo.CurrentCulture, GetString("BindingToDefaultAddresses", "address0", "address1"), address0, address1); + + /// + /// The requested certificate {subject} could not be found in {storeLocation}/{storeName} with AllowInvalid setting: {allowInvalid}. + /// + internal static string CertNotFoundInStore + { + get => GetString("CertNotFoundInStore"); + } + + /// + /// The requested certificate {subject} could not be found in {storeLocation}/{storeName} with AllowInvalid setting: {allowInvalid}. + /// + internal static string FormatCertNotFoundInStore(object subject, object storeLocation, object storeName, object allowInvalid) + => string.Format(CultureInfo.CurrentCulture, GetString("CertNotFoundInStore", "subject", "storeLocation", "storeName", "allowInvalid"), subject, storeLocation, storeName, allowInvalid); + + /// + /// The endpoint {endpointName} is missing the required 'Url' parameter. + /// + internal static string EndpointMissingUrl + { + get => GetString("EndpointMissingUrl"); + } + + /// + /// The endpoint {endpointName} is missing the required 'Url' parameter. + /// + internal static string FormatEndpointMissingUrl(object endpointName) + => string.Format(CultureInfo.CurrentCulture, GetString("EndpointMissingUrl", "endpointName"), endpointName); + + /// + /// Unable to configure HTTPS endpoint. No server certificate was specified and the default developer certificate could not be found. Try running 'dotnet developercertificates https -t' to setup a developer certificate for use with localhost. For information on configuring HTTPS see https://go.microsoft.com/fwlink/?linkid=848054 + /// + internal static string NoCertSpecifiedNoDevelopmentCertificateFound + { + get => GetString("NoCertSpecifiedNoDevelopmentCertificateFound"); + } + + /// + /// Unable to configure HTTPS endpoint. No server certificate was specified and the default developer certificate could not be found. Try running 'dotnet developercertificates https -t' to setup a developer certificate for use with localhost. For information on configuring HTTPS see https://go.microsoft.com/fwlink/?linkid=848054 + /// + internal static string FormatNoCertSpecifiedNoDevelopmentCertificateFound() + => GetString("NoCertSpecifiedNoDevelopmentCertificateFound"); + + /// + /// The endpoint {endpointName} specified multiple certificate sources. + /// + internal static string MultipleCertificateSources + { + get => GetString("MultipleCertificateSources"); + } + + /// + /// The endpoint {endpointName} specified multiple certificate sources. + /// + internal static string FormatMultipleCertificateSources(object endpointName) + => string.Format(CultureInfo.CurrentCulture, GetString("MultipleCertificateSources", "endpointName"), endpointName); + private static string GetString(string name, params string[] formatterNames) { var value = _resourceManager.GetString(name); diff --git a/src/Kestrel/Internal/DefaultHttpsProvider.cs b/src/Kestrel/Internal/DefaultHttpsProvider.cs deleted file mode 100644 index efc7d9fb10..0000000000 --- a/src/Kestrel/Internal/DefaultHttpsProvider.cs +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using System.Linq; -using System.Security.Cryptography.X509Certificates; -using Microsoft.AspNetCore.Certificates.Generation; -using Microsoft.AspNetCore.Hosting; -using Microsoft.AspNetCore.Server.Kestrel.Core; -using Microsoft.AspNetCore.Server.Kestrel.Core.Internal; -using Microsoft.Extensions.Logging; - -namespace Microsoft.AspNetCore.Server.Kestrel.Internal -{ - public class DefaultHttpsProvider : IDefaultHttpsProvider - { - private static readonly CertificateManager _certificateManager = new CertificateManager(); - - private readonly ILogger _logger; - - public DefaultHttpsProvider(ILogger logger) - { - _logger = logger; - } - - public void ConfigureHttps(ListenOptions listenOptions) - { - var certificate = _certificateManager.ListCertificates(CertificatePurpose.HTTPS, StoreName.My, StoreLocation.CurrentUser, isValid: true) - .FirstOrDefault(); - if (certificate != null) - { - _logger.LocatedDevelopmentCertificate(certificate); - listenOptions.UseHttps(certificate); - } - else - { - _logger.UnableToLocateDevelopmentCertificate(); - throw new InvalidOperationException(KestrelStrings.HttpsUrlProvidedButNoDevelopmentCertificateFound); - } - } - } -} diff --git a/src/Kestrel/Kestrel.csproj b/src/Kestrel/Kestrel.csproj index ac46ce4d3d..55f910ddcf 100644 --- a/src/Kestrel/Kestrel.csproj +++ b/src/Kestrel/Kestrel.csproj @@ -12,8 +12,6 @@ - - diff --git a/src/Kestrel/KestrelStrings.resx b/src/Kestrel/KestrelStrings.resx deleted file mode 100644 index d39f8b5166..0000000000 --- a/src/Kestrel/KestrelStrings.resx +++ /dev/null @@ -1,123 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 2.0 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - Unable to configure HTTPS endpoint. Try running 'dotnet developercertificates https -t' to setup a developer certificate for use with localhost. For information on configuring HTTPS see https://go.microsoft.com/fwlink/?linkid=848054 - - \ No newline at end of file diff --git a/src/Kestrel/Properties/KestrelStrings.Designer.cs b/src/Kestrel/Properties/KestrelStrings.Designer.cs deleted file mode 100644 index 0246bf453a..0000000000 --- a/src/Kestrel/Properties/KestrelStrings.Designer.cs +++ /dev/null @@ -1,44 +0,0 @@ -// -namespace Microsoft.AspNetCore.Server.Kestrel -{ - using System.Globalization; - using System.Reflection; - using System.Resources; - - internal static class KestrelStrings - { - private static readonly ResourceManager _resourceManager - = new ResourceManager("Microsoft.AspNetCore.Server.Kestrel.KestrelStrings", typeof(KestrelStrings).GetTypeInfo().Assembly); - - /// - /// Unable to configure HTTPS endpoint. Try running 'dotnet developercertificates https -t' to setup a developer certificate for use with localhost. For information on configuring HTTPS see https://go.microsoft.com/fwlink/?linkid=848054 - /// - internal static string HttpsUrlProvidedButNoDevelopmentCertificateFound - { - get => GetString("HttpsUrlProvidedButNoDevelopmentCertificateFound"); - } - - /// - /// Unable to configure HTTPS endpoint. Try running 'dotnet developercertificates https -t' to setup a developer certificate for use with localhost. For information on configuring HTTPS see https://go.microsoft.com/fwlink/?linkid=848054 - /// - internal static string FormatHttpsUrlProvidedButNoDevelopmentCertificateFound() - => GetString("HttpsUrlProvidedButNoDevelopmentCertificateFound"); - - private static string GetString(string name, params string[] formatterNames) - { - var value = _resourceManager.GetString(name); - - System.Diagnostics.Debug.Assert(value != null); - - if (formatterNames != null) - { - for (var i = 0; i < formatterNames.Length; i++) - { - value = value.Replace("{" + formatterNames[i] + "}", "{" + i + "}"); - } - } - - return value; - } - } -} diff --git a/src/Kestrel/WebHostBuilderKestrelExtensions.cs b/src/Kestrel/WebHostBuilderKestrelExtensions.cs index fdc149e2fe..faac901aff 100644 --- a/src/Kestrel/WebHostBuilderKestrelExtensions.cs +++ b/src/Kestrel/WebHostBuilderKestrelExtensions.cs @@ -34,7 +34,6 @@ namespace Microsoft.AspNetCore.Hosting services.AddTransient, KestrelServerOptionsSetup>(); services.AddSingleton(); - services.AddSingleton(); }); } diff --git a/test/Kestrel.Core.Tests/AddressBinderTests.cs b/test/Kestrel.Core.Tests/AddressBinderTests.cs index f2580353db..d548fa70ba 100644 --- a/test/Kestrel.Core.Tests/AddressBinderTests.cs +++ b/test/Kestrel.Core.Tests/AddressBinderTests.cs @@ -54,46 +54,50 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests public void ParseAddressDefaultsToAnyIPOnInvalidIPAddress(string host) { var options = new KestrelServerOptions(); - var listenOptions = AddressBinder.ParseAddress($"http://{host}", options, Mock.Of()); + var listenOptions = AddressBinder.ParseAddress($"http://{host}", out var https); Assert.IsType(listenOptions); Assert.Equal(ListenType.IPEndPoint, listenOptions.Type); Assert.Equal(IPAddress.IPv6Any, listenOptions.IPEndPoint.Address); Assert.Equal(80, listenOptions.IPEndPoint.Port); + Assert.False(https); } [Fact] public void ParseAddressLocalhost() { var options = new KestrelServerOptions(); - var listenOptions = AddressBinder.ParseAddress("http://localhost", options, Mock.Of()); + var listenOptions = AddressBinder.ParseAddress("http://localhost", out var https); Assert.IsType(listenOptions); Assert.Equal(ListenType.IPEndPoint, listenOptions.Type); Assert.Equal(IPAddress.Loopback, listenOptions.IPEndPoint.Address); Assert.Equal(80, listenOptions.IPEndPoint.Port); + Assert.False(https); } [Fact] public void ParseAddressUnixPipe() { var options = new KestrelServerOptions(); - var listenOptions = AddressBinder.ParseAddress("http://unix:/tmp/kestrel-test.sock", options, Mock.Of()); + var listenOptions = AddressBinder.ParseAddress("http://unix:/tmp/kestrel-test.sock", out var https); Assert.Equal(ListenType.SocketPath, listenOptions.Type); Assert.Equal("/tmp/kestrel-test.sock", listenOptions.SocketPath); + Assert.False(https); } [Theory] - [InlineData("http://10.10.10.10:5000/", "10.10.10.10", 5000)] - [InlineData("http://[::1]:5000", "::1", 5000)] - [InlineData("http://[::1]", "::1", 80)] - [InlineData("http://127.0.0.1", "127.0.0.1", 80)] - [InlineData("https://127.0.0.1", "127.0.0.1", 443)] - public void ParseAddressIP(string address, string ip, int port) + [InlineData("http://10.10.10.10:5000/", "10.10.10.10", 5000, false)] + [InlineData("http://[::1]:5000", "::1", 5000, false)] + [InlineData("http://[::1]", "::1", 80, false)] + [InlineData("http://127.0.0.1", "127.0.0.1", 80, false)] + [InlineData("https://127.0.0.1", "127.0.0.1", 443, true)] + public void ParseAddressIP(string address, string ip, int port, bool isHttps) { var options = new KestrelServerOptions(); - var listenOptions = AddressBinder.ParseAddress(address, options, Mock.Of()); + var listenOptions = AddressBinder.ParseAddress(address, out var https); Assert.Equal(ListenType.IPEndPoint, listenOptions.Type); Assert.Equal(IPAddress.Parse(ip), listenOptions.IPEndPoint.Address); Assert.Equal(port, listenOptions.IPEndPoint.Port); + Assert.Equal(isHttps, https); } [Fact] @@ -107,7 +111,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests AddressBinder.BindAsync(addresses, options, NullLogger.Instance, - Mock.Of(), endpoint => throw new AddressInUseException("already in use"))); } @@ -128,7 +131,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests await AddressBinder.BindAsync(addresses, options, logger, - Mock.Of(), endpoint => { if (endpoint.IPEndPoint.Address == IPAddress.IPv6Any) diff --git a/test/Kestrel.Core.Tests/Kestrel.Core.Tests.csproj b/test/Kestrel.Core.Tests/Kestrel.Core.Tests.csproj index ede5868b74..632a9f5ae7 100644 --- a/test/Kestrel.Core.Tests/Kestrel.Core.Tests.csproj +++ b/test/Kestrel.Core.Tests/Kestrel.Core.Tests.csproj @@ -17,6 +17,7 @@ + diff --git a/test/Kestrel.Core.Tests/KestrelServerOptionsTests.cs b/test/Kestrel.Core.Tests/KestrelServerOptionsTests.cs index 2597862f80..75739a4c7b 100644 --- a/test/Kestrel.Core.Tests/KestrelServerOptionsTests.cs +++ b/test/Kestrel.Core.Tests/KestrelServerOptionsTests.cs @@ -29,5 +29,40 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests Assert.True(options.AllowSynchronousIO); } + + [Fact] + public void ConfigureEndpointDefaultsAppliesToNewEndpoints() + { + var options = new KestrelServerOptions(); + options.ListenLocalhost(5000); + + Assert.True(options.ListenOptions[0].NoDelay); + + options.ConfigureEndpointDefaults(opt => + { + opt.NoDelay = false; + }); + + options.Listen(new IPEndPoint(IPAddress.Loopback, 5000), opt => + { + // ConfigureEndpointDefaults runs before this callback + Assert.False(opt.NoDelay); + }); + Assert.False(options.ListenOptions[1].NoDelay); + + options.ListenLocalhost(5000, opt => + { + Assert.False(opt.NoDelay); + opt.NoDelay = true; // Can be overriden + }); + Assert.True(options.ListenOptions[2].NoDelay); + + + options.ListenAnyIP(5000, opt => + { + Assert.False(opt.NoDelay); + }); + Assert.False(options.ListenOptions[3].NoDelay); + } } } \ No newline at end of file diff --git a/test/Kestrel.Core.Tests/KestrelServerTests.cs b/test/Kestrel.Core.Tests/KestrelServerTests.cs index da23da4f19..ab9015cf5f 100644 --- a/test/Kestrel.Core.Tests/KestrelServerTests.cs +++ b/test/Kestrel.Core.Tests/KestrelServerTests.cs @@ -9,9 +9,9 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting.Server; using Microsoft.AspNetCore.Hosting.Server.Features; -using Microsoft.AspNetCore.Server.Kestrel.Core.Internal; using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; using Microsoft.AspNetCore.Testing; +using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using Moq; @@ -21,12 +21,21 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests { public class KestrelServerTests { + private KestrelServerOptions CreateServerOptions() + { + var serverOptions = new KestrelServerOptions(); + serverOptions.ApplicationServices = new ServiceCollection() + .AddLogging() + .BuildServiceProvider(); + return serverOptions; + } + [Fact] public void StartWithInvalidAddressThrows() { var testLogger = new TestApplicationErrorLogger { ThrowOnCriticalErrors = false }; - using (var server = CreateServer(new KestrelServerOptions(), testLogger)) + using (var server = CreateServer(CreateServerOptions(), testLogger)) { server.Features.Get().Addresses.Add("http:/asdf"); @@ -40,34 +49,35 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests [Fact] public void StartWithHttpsAddressConfiguresHttpsEndpoints() { - var mockDefaultHttpsProvider = new Mock(); - - using (var server = CreateServer(new KestrelServerOptions(), mockDefaultHttpsProvider.Object)) + var options = CreateServerOptions(); + options.DefaultCertificate = TestResources.GetTestCertificate(); + using (var server = CreateServer(options)) { server.Features.Get().Addresses.Add("https://127.0.0.1:0"); StartDummyApplication(server); - mockDefaultHttpsProvider.Verify(provider => provider.ConfigureHttps(It.IsAny()), Times.Once); + Assert.True(server.Options.ListenOptions.Any()); + Assert.Contains(server.Options.ListenOptions[0].ConnectionAdapters, adapter => adapter.IsHttps); } } [Fact] public void KestrelServerThrowsUsefulExceptionIfDefaultHttpsProviderNotAdded() { - using (var server = CreateServer(new KestrelServerOptions(), defaultHttpsProvider: null, throwOnCriticalErrors: false)) + using (var server = CreateServer(CreateServerOptions(), throwOnCriticalErrors: false)) { server.Features.Get().Addresses.Add("https://127.0.0.1:0"); var ex = Assert.Throws(() => StartDummyApplication(server)); - Assert.Equal(CoreStrings.UnableToConfigureHttpsBindings, ex.Message); + Assert.Equal(CoreStrings.NoCertSpecifiedNoDevelopmentCertificateFound, ex.Message); } } [Fact] public void KestrelServerDoesNotThrowIfNoDefaultHttpsProviderButNoHttpUrls() { - using (var server = CreateServer(new KestrelServerOptions(), defaultHttpsProvider: null)) + using (var server = CreateServer(CreateServerOptions())) { server.Features.Get().Addresses.Add("http://127.0.0.1:0"); @@ -78,12 +88,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests [Fact] public void KestrelServerDoesNotThrowIfNoDefaultHttpsProviderButManualListenOptions() { - var mockDefaultHttpsProvider = new Mock(); - - var serverOptions = new KestrelServerOptions(); + var serverOptions = CreateServerOptions(); serverOptions.Listen(new IPEndPoint(IPAddress.Loopback, 0)); - using (var server = CreateServer(serverOptions, defaultHttpsProvider: null)) + using (var server = CreateServer(serverOptions)) { server.Features.Get().Addresses.Add("https://127.0.0.1:0"); @@ -322,9 +330,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests return new KestrelServer(Options.Create(options), new MockTransportFactory(), new LoggerFactory(new[] { new KestrelTestLoggerProvider(testLogger) })); } - private static KestrelServer CreateServer(KestrelServerOptions options, IDefaultHttpsProvider defaultHttpsProvider, bool throwOnCriticalErrors = true) + private static KestrelServer CreateServer(KestrelServerOptions options, bool throwOnCriticalErrors = true) { - return new KestrelServer(Options.Create(options), new MockTransportFactory(), new LoggerFactory(new[] { new KestrelTestLoggerProvider(throwOnCriticalErrors) }), defaultHttpsProvider); + return new KestrelServer(Options.Create(options), new MockTransportFactory(), new LoggerFactory(new[] { new KestrelTestLoggerProvider(throwOnCriticalErrors) })); } private static void StartDummyApplication(IServer server) diff --git a/test/Kestrel.FunctionalTests/AddressRegistrationTests.cs b/test/Kestrel.FunctionalTests/AddressRegistrationTests.cs index 84cdb61396..b5a0859c36 100644 --- a/test/Kestrel.FunctionalTests/AddressRegistrationTests.cs +++ b/test/Kestrel.FunctionalTests/AddressRegistrationTests.cs @@ -8,6 +8,7 @@ using System.Linq; using System.Net; using System.Net.NetworkInformation; using System.Net.Sockets; +using System.Security.Cryptography.X509Certificates; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Builder; @@ -17,6 +18,7 @@ using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http.Extensions; using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Https; using Microsoft.AspNetCore.Testing; using Microsoft.AspNetCore.Testing.xunit; using Microsoft.Extensions.Logging; @@ -189,6 +191,40 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests private Task RegisterAddresses_StaticPort_Success(string addressInput, string[] testUrls) => RunTestWithStaticPort(port => RegisterAddresses_Success($"{addressInput}:{port}", testUrls, port)); + [Fact] + public async Task RegisterHttpAddress_UpradedToHttpsByConfigureEndpointDefaults() + { + var hostBuilder = TransportSelector.GetWebHostBuilder() + .UseKestrel(serverOptions => + { + serverOptions.ConfigureEndpointDefaults(listenOptions => + { + listenOptions.UseHttps(TestResources.GetTestCertificate()); + }); + }) + .ConfigureLogging(_configureLoggingDelegate) + .UseUrls("http://127.0.0.1:0") + .Configure(app => + { + var serverAddresses = app.ServerFeatures.Get(); + app.Run(context => + { + Assert.Single(serverAddresses.Addresses); + return context.Response.WriteAsync(serverAddresses.Addresses.First()); + }); + }); + + using (var host = hostBuilder.Build()) + { + host.Start(); + + var expectedUrl = $"https://127.0.0.1:{host.GetPort()}"; + var response = await HttpClientSlim.GetStringAsync(expectedUrl, validateCertificate: false); + + Assert.Equal(expectedUrl, response); + } + } + private async Task RunTestWithStaticPort(Func test) { var retryCount = 0; @@ -361,13 +397,40 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests return RegisterDefaultServerAddresses_Success(new[] { "http://127.0.0.1:5000", "http://[::1]:5000" }); } - private async Task RegisterDefaultServerAddresses_Success(IEnumerable addresses) + [ConditionalFact] + [PortSupportedCondition(5000)] + [PortSupportedCondition(5001)] + public Task DefaultsServerAddress_BindsToIPv4WithHttps() + { + return RegisterDefaultServerAddresses_Success( + new[] { "http://127.0.0.1:5000", "https://127.0.0.1:5001" }, mockHttps: true); + } + + [ConditionalFact] + [IPv6SupportedCondition] + [PortSupportedCondition(5000)] + [PortSupportedCondition(5001)] + public Task DefaultsServerAddress_BindsToIPv6WithHttps() + { + return RegisterDefaultServerAddresses_Success(new[] { + "http://127.0.0.1:5000", "http://[::1]:5000", + "https://127.0.0.1:5001", "https://[::1]:5001"}, + mockHttps: true); + } + + private async Task RegisterDefaultServerAddresses_Success(IEnumerable addresses, bool mockHttps = false) { var testLogger = new TestApplicationErrorLogger(); var hostBuilder = TransportSelector.GetWebHostBuilder() .ConfigureLogging(_configureLoggingDelegate) - .UseKestrel() + .UseKestrel(options => + { + if (mockHttps) + { + options.DefaultCertificate = new X509Certificate2(TestResources.TestCertificatePath, "testPassword"); + } + }) .ConfigureLogging(builder => builder .AddProvider(new KestrelTestLoggerProvider(testLogger)) .SetMinimumLevel(LogLevel.Debug)) @@ -378,13 +441,19 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests host.Start(); Assert.Equal(5000, host.GetPort()); + + if (mockHttps) + { + Assert.Contains(5001, host.GetPorts()); + } + Assert.Single(testLogger.Messages, log => log.LogLevel == LogLevel.Debug && - string.Equals(CoreStrings.FormatBindingToDefaultAddress(Constants.DefaultServerAddress), - log.Message, StringComparison.Ordinal)); + (string.Equals(CoreStrings.FormatBindingToDefaultAddresses(Constants.DefaultServerAddress, Constants.DefaultServerHttpsAddress), log.Message, StringComparison.Ordinal) + || string.Equals(CoreStrings.FormatBindingToDefaultAddress(Constants.DefaultServerAddress), log.Message, StringComparison.Ordinal))); foreach (var address in addresses) { - Assert.Equal(new Uri(address).ToString(), await HttpClientSlim.GetStringAsync(address)); + Assert.Equal(new Uri(address).ToString(), await HttpClientSlim.GetStringAsync(address, validateCertificate: false)); } } } @@ -933,7 +1002,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } } - [AttributeUsage(AttributeTargets.Method, AllowMultiple = false)] + [AttributeUsage(AttributeTargets.Method, AllowMultiple = true)] private class PortSupportedConditionAttribute : Attribute, ITestCondition { private readonly int _port; diff --git a/test/Kestrel.FunctionalTests/CertificateLoaderTests.cs b/test/Kestrel.FunctionalTests/CertificateLoaderTests.cs new file mode 100644 index 0000000000..21ad9704ed --- /dev/null +++ b/test/Kestrel.FunctionalTests/CertificateLoaderTests.cs @@ -0,0 +1,64 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System.Linq; +using System.Security.Cryptography.X509Certificates; +using Microsoft.AspNetCore.Server.Kestrel.Https.Internal; +using Microsoft.AspNetCore.Testing; +using Xunit; +using Xunit.Abstractions; + +namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests +{ + public class CertificateLoaderTests + { + private readonly ITestOutputHelper _output; + + public CertificateLoaderTests(ITestOutputHelper output) + { + _output = output; + } + + [Theory] + [InlineData("no_extensions.pfx")] + public void IsCertificateAllowedForServerAuth_AllowWithNoExtensions(string testCertName) + { + var certPath = TestResources.GetCertPath(testCertName); + _output.WriteLine("Loading " + certPath); + var cert = new X509Certificate2(certPath, "testPassword"); + Assert.Empty(cert.Extensions.OfType()); + + Assert.True(CertificateLoader.IsCertificateAllowedForServerAuth(cert)); + } + + [Theory] + [InlineData("eku.server.pfx")] + [InlineData("eku.multiple_usages.pfx")] + public void IsCertificateAllowedForServerAuth_ValidatesEnhancedKeyUsageOnCertificate(string testCertName) + { + var certPath = TestResources.GetCertPath(testCertName); + _output.WriteLine("Loading " + certPath); + var cert = new X509Certificate2(certPath, "testPassword"); + Assert.NotEmpty(cert.Extensions); + var eku = Assert.Single(cert.Extensions.OfType()); + Assert.NotEmpty(eku.EnhancedKeyUsages); + + Assert.True(CertificateLoader.IsCertificateAllowedForServerAuth(cert)); + } + + [Theory] + [InlineData("eku.code_signing.pfx")] + [InlineData("eku.client.pfx")] + public void IsCertificateAllowedForServerAuth_RejectsCertificatesMissingServerEku(string testCertName) + { + var certPath = TestResources.GetCertPath(testCertName); + _output.WriteLine("Loading " + certPath); + var cert = new X509Certificate2(certPath, "testPassword"); + Assert.NotEmpty(cert.Extensions); + var eku = Assert.Single(cert.Extensions.OfType()); + Assert.NotEmpty(eku.EnhancedKeyUsages); + + Assert.False(CertificateLoader.IsCertificateAllowedForServerAuth(cert)); + } + } +} diff --git a/test/Kestrel.FunctionalTests/HttpsTests.cs b/test/Kestrel.FunctionalTests/HttpsTests.cs index 8bc8fb7f60..86403b11b5 100644 --- a/test/Kestrel.FunctionalTests/HttpsTests.cs +++ b/test/Kestrel.FunctionalTests/HttpsTests.cs @@ -3,7 +3,6 @@ using System; using System.Collections.Generic; -using System.IO; using System.Net; using System.Net.Security; using System.Net.Sockets; @@ -14,8 +13,11 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Server.Kestrel.Core; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal; using Microsoft.AspNetCore.Server.Kestrel.Https; using Microsoft.AspNetCore.Server.Kestrel.Https.Internal; +using Microsoft.AspNetCore.Server.Kestrel.Internal; using Microsoft.AspNetCore.Testing; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; @@ -26,6 +28,61 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { public class HttpsTests { + private KestrelServerOptions CreateServerOptions() + { + var serverOptions = new KestrelServerOptions(); + serverOptions.ApplicationServices = new ServiceCollection() + .AddLogging() + .BuildServiceProvider(); + return serverOptions; + } + + [Fact] + public void UseHttpsDefaultsToDefaultCert() + { + var serverOptions = CreateServerOptions(); + var defaultCert = new X509Certificate2(TestResources.TestCertificatePath, "testPassword"); + serverOptions.DefaultCertificate = defaultCert; + + serverOptions.ListenLocalhost(5000, options => + { + options.UseHttps(); + }); + + serverOptions.ListenLocalhost(5001, options => + { + options.UseHttps(opt => + { + Assert.Equal(defaultCert, opt.ServerCertificate); + }); + }); + } + + [Fact] + public void ConfigureHttpsDefaultsOverridesDefaultCert() + { + var serverOptions = CreateServerOptions(); + var defaultCert = new X509Certificate2(TestResources.TestCertificatePath, "testPassword"); + serverOptions.DefaultCertificate = defaultCert; + serverOptions.ConfigureHttpsDefaults(options => + { + Assert.Equal(defaultCert, options.ServerCertificate); + options.ServerCertificate = null; + options.ClientCertificateMode = ClientCertificateMode.RequireCertificate; + }); + serverOptions.ListenLocalhost(5000, options => + { + options.UseHttps(opt => + { + Assert.Null(opt.ServerCertificate); + Assert.Equal(ClientCertificateMode.RequireCertificate, opt.ClientCertificateMode); + + // So UseHttps won't throw + opt.ServerCertificate = defaultCert; + }); + }); + } + [Fact] public async Task EmptyRequestLoggedAsInformation() { @@ -270,10 +327,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { options.Listen(new IPEndPoint(IPAddress.Loopback, 0), listenOptions => { - listenOptions.UseHttps(new HttpsConnectionAdapterOptions + listenOptions.UseHttps(o => { - ServerCertificate = new X509Certificate2(TestResources.TestCertificatePath, "testPassword"), - HandshakeTimeout = TimeSpan.FromSeconds(1) + o.ServerCertificate = new X509Certificate2(TestResources.TestCertificatePath, "testPassword"); + o.HandshakeTimeout = TimeSpan.FromSeconds(1); }); }); }) diff --git a/test/Kestrel.Tests/ConfigurationReaderTests.cs b/test/Kestrel.Tests/ConfigurationReaderTests.cs new file mode 100644 index 0000000000..ecc7f5e587 --- /dev/null +++ b/test/Kestrel.Tests/ConfigurationReaderTests.cs @@ -0,0 +1,177 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Collections.Generic; +using System.Linq; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal; +using Microsoft.Extensions.Configuration; +using Xunit; + +namespace Microsoft.AspNetCore.Server.Kestrel.Tests +{ + public class ConfigurationReaderTests + { + [Fact] + public void ReadCertificatesWhenNoCertificatsSection_ReturnsEmptyCollection() + { + var config = new ConfigurationBuilder().AddInMemoryCollection().Build(); + var reader = new ConfigurationReader(config); + var certificates = reader.Certificates; + Assert.NotNull(certificates); + Assert.False(certificates.Any()); + } + + [Fact] + public void ReadCertificatesWhenEmptyCertificatsSection_ReturnsEmptyCollection() + { + var config = new ConfigurationBuilder().AddInMemoryCollection(new[] + { + new KeyValuePair("Certificates", ""), + }).Build(); + var reader = new ConfigurationReader(config); + var certificates = reader.Certificates; + Assert.NotNull(certificates); + Assert.False(certificates.Any()); + } + + [Fact] + public void ReadCertificatsSection_ReturnsCollection() + { + var config = new ConfigurationBuilder().AddInMemoryCollection(new[] + { + new KeyValuePair("Certificates:FileCert:Path", "/path/cert.pfx"), + new KeyValuePair("Certificates:FileCert:Password", "certpassword"), + new KeyValuePair("Certificates:StoreCert:Subject", "certsubject"), + new KeyValuePair("Certificates:StoreCert:Store", "certstore"), + new KeyValuePair("Certificates:StoreCert:Location", "cetlocation"), + new KeyValuePair("Certificates:StoreCert:AllowInvalid", "true"), + }).Build(); + var reader = new ConfigurationReader(config); + var certificates = reader.Certificates; + Assert.NotNull(certificates); + Assert.Equal(2, certificates.Count); + + var fileCert = certificates["FileCert"]; + Assert.True(fileCert.IsFileCert); + Assert.False(fileCert.IsStoreCert); + Assert.Equal("/path/cert.pfx", fileCert.Path); + Assert.Equal("certpassword", fileCert.Password); + + var storeCert = certificates["StoreCert"]; + Assert.False(storeCert.IsFileCert); + Assert.True(storeCert.IsStoreCert); + Assert.Equal("certsubject", storeCert.Subject); + Assert.Equal("certstore", storeCert.Store); + Assert.Equal("cetlocation", storeCert.Location); + Assert.True(storeCert.AllowInvalid); + } + + [Fact] + public void ReadEndpointsWhenNoEndpointsSection_ReturnsEmptyCollection() + { + var config = new ConfigurationBuilder().AddInMemoryCollection().Build(); + var reader = new ConfigurationReader(config); + var endpoints = reader.Endpoints; + Assert.NotNull(endpoints); + Assert.False(endpoints.Any()); + } + + [Fact] + public void ReadEndpointsWhenEmptyEndpointsSection_ReturnsEmptyCollection() + { + var config = new ConfigurationBuilder().AddInMemoryCollection(new[] + { + new KeyValuePair("Endpoints", ""), + }).Build(); + var reader = new ConfigurationReader(config); + var endpoints = reader.Endpoints; + Assert.NotNull(endpoints); + Assert.False(endpoints.Any()); + } + + [Fact] + public void ReadEndpointWithMissingUrl_Throws() + { + var config = new ConfigurationBuilder().AddInMemoryCollection(new[] + { + new KeyValuePair("Endpoints:End1", ""), + }).Build(); + var reader = new ConfigurationReader(config); + Assert.Throws(() => reader.Endpoints); + } + + [Fact] + public void ReadEndpointWithEmptyUrl_Throws() + { + var config = new ConfigurationBuilder().AddInMemoryCollection(new[] + { + new KeyValuePair("Endpoints:End1:Url", ""), + }).Build(); + var reader = new ConfigurationReader(config); + Assert.Throws(() => reader.Endpoints); + } + + [Fact] + public void ReadEndpointsSection_ReturnsCollection() + { + var config = new ConfigurationBuilder().AddInMemoryCollection(new[] + { + new KeyValuePair("Endpoints:End1:Url", "http://*:5001"), + new KeyValuePair("Endpoints:End2:Url", "https://*:5002"), + new KeyValuePair("Endpoints:End3:Url", "https://*:5003"), + new KeyValuePair("Endpoints:End3:Certificate:Path", "/path/cert.pfx"), + new KeyValuePair("Endpoints:End3:Certificate:Password", "certpassword"), + new KeyValuePair("Endpoints:End4:Url", "https://*:5004"), + new KeyValuePair("Endpoints:End4:Certificate:Subject", "certsubject"), + new KeyValuePair("Endpoints:End4:Certificate:Store", "certstore"), + new KeyValuePair("Endpoints:End4:Certificate:Location", "cetlocation"), + new KeyValuePair("Endpoints:End4:Certificate:AllowInvalid", "true"), + }).Build(); + var reader = new ConfigurationReader(config); + var endpoints = reader.Endpoints; + Assert.NotNull(endpoints); + Assert.Equal(4, endpoints.Count()); + + var end1 = endpoints.First(); + Assert.Equal("End1", end1.Name); + Assert.Equal("http://*:5001", end1.Url); + Assert.NotNull(end1.ConfigSection); + Assert.NotNull(end1.Certificate); + Assert.False(end1.Certificate.ConfigSection.Exists()); + + var end2 = endpoints.Skip(1).First(); + Assert.Equal("End2", end2.Name); + Assert.Equal("https://*:5002", end2.Url); + Assert.NotNull(end2.ConfigSection); + Assert.NotNull(end2.Certificate); + Assert.False(end2.Certificate.ConfigSection.Exists()); + + var end3 = endpoints.Skip(2).First(); + Assert.Equal("End3", end3.Name); + Assert.Equal("https://*:5003", end3.Url); + Assert.NotNull(end3.ConfigSection); + Assert.NotNull(end3.Certificate); + Assert.True(end3.Certificate.ConfigSection.Exists()); + var cert3 = end3.Certificate; + Assert.True(cert3.IsFileCert); + Assert.False(cert3.IsStoreCert); + Assert.Equal("/path/cert.pfx", cert3.Path); + Assert.Equal("certpassword", cert3.Password); + + var end4 = endpoints.Skip(3).First(); + Assert.Equal("End4", end4.Name); + Assert.Equal("https://*:5004", end4.Url); + Assert.NotNull(end4.ConfigSection); + Assert.NotNull(end4.Certificate); + Assert.True(end4.Certificate.ConfigSection.Exists()); + var cert4 = end4.Certificate; + Assert.False(cert4.IsFileCert); + Assert.True(cert4.IsStoreCert); + Assert.Equal("certsubject", cert4.Subject); + Assert.Equal("certstore", cert4.Store); + Assert.Equal("cetlocation", cert4.Location); + Assert.True(cert4.AllowInvalid); + } + } +} diff --git a/test/Kestrel.Tests/Kestrel.Tests.csproj b/test/Kestrel.Tests/Kestrel.Tests.csproj index 5137cd136c..c26558bb08 100644 --- a/test/Kestrel.Tests/Kestrel.Tests.csproj +++ b/test/Kestrel.Tests/Kestrel.Tests.csproj @@ -6,8 +6,14 @@ $(StandardTestTfms) + + + + + + diff --git a/test/Kestrel.Tests/KestrelConfigurationBuilderTests.cs b/test/Kestrel.Tests/KestrelConfigurationBuilderTests.cs new file mode 100644 index 0000000000..bdd9bff4c1 --- /dev/null +++ b/test/Kestrel.Tests/KestrelConfigurationBuilderTests.cs @@ -0,0 +1,213 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Security.Cryptography.X509Certificates; +using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Server.Kestrel.Core; +using Microsoft.AspNetCore.Server.Kestrel.Https; +using Microsoft.AspNetCore.Testing; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using Xunit; + +namespace Microsoft.AspNetCore.Server.Kestrel.Tests +{ + public class KestrelConfigurationBuilderTests + { + private KestrelServerOptions CreateServerOptions() + { + var serverOptions = new KestrelServerOptions(); + serverOptions.ApplicationServices = new ServiceCollection() + .AddLogging() + .BuildServiceProvider(); + return serverOptions; + } + + [Fact] + public void ConfigureNamedEndpoint_OnlyRunForMatchingConfig() + { + var found = false; + var serverOptions = CreateServerOptions(); + var config = new ConfigurationBuilder().AddInMemoryCollection(new[] + { + new KeyValuePair("Endpoints:Found:Url", "http://*:5001"), + }).Build(); + serverOptions.Configure(config) + .Endpoint("Found", endpointOptions => found = true) + .Endpoint("NotFound", endpointOptions => throw new NotImplementedException()) + .Load(); + + Assert.Single(serverOptions.ListenOptions); + Assert.Equal(5001, serverOptions.ListenOptions[0].IPEndPoint.Port); + + Assert.True(found); + } + + [Fact] + public void ConfigureEndpoint_OnlyRunWhenBuildIsCalled() + { + var run = false; + var serverOptions = CreateServerOptions(); + serverOptions.Configure() + .LocalhostEndpoint(5001, endpointOptions => run = true); + + Assert.Empty(serverOptions.ListenOptions); + + serverOptions.ConfigurationLoader.Load(); + + Assert.Single(serverOptions.ListenOptions); + Assert.Equal(5001, serverOptions.ListenOptions[0].IPEndPoint.Port); + + Assert.True(run); + } + + [Fact] + public void CallBuildTwice_OnlyRunsOnce() + { + var serverOptions = CreateServerOptions(); + var builder = serverOptions.Configure() + .LocalhostEndpoint(5001); + + Assert.Empty(serverOptions.ListenOptions); + Assert.Equal(builder, serverOptions.ConfigurationLoader); + + builder.Load(); + + Assert.Single(serverOptions.ListenOptions); + Assert.Equal(5001, serverOptions.ListenOptions[0].IPEndPoint.Port); + Assert.Null(serverOptions.ConfigurationLoader); + + builder.Load(); + + Assert.Single(serverOptions.ListenOptions); + Assert.Equal(5001, serverOptions.ListenOptions[0].IPEndPoint.Port); + Assert.Null(serverOptions.ConfigurationLoader); + } + + [Fact] + public void Configure_IsReplacable() + { + var run1 = false; + var serverOptions = CreateServerOptions(); + var config1 = new ConfigurationBuilder().AddInMemoryCollection(new[] + { + new KeyValuePair("Endpoints:End1:Url", "http://*:5001"), + }).Build(); + serverOptions.Configure(config1) + .LocalhostEndpoint(5001, endpointOptions => run1 = true); + + Assert.Empty(serverOptions.ListenOptions); + Assert.False(run1); + + var run2 = false; + var config2 = new ConfigurationBuilder().AddInMemoryCollection(new[] + { + new KeyValuePair("Endpoints:End2:Url", "http://*:5002"), + }).Build(); + serverOptions.Configure(config2) + .LocalhostEndpoint(5003, endpointOptions => run2 = true); + + serverOptions.ConfigurationLoader.Load(); + + Assert.Equal(2, serverOptions.ListenOptions.Count); + Assert.Equal(5002, serverOptions.ListenOptions[0].IPEndPoint.Port); + Assert.Equal(5003, serverOptions.ListenOptions[1].IPEndPoint.Port); + + Assert.False(run1); + Assert.True(run2); + } + + [Fact] + public void ConfigureDefaultsAppliesToNewConfigureEndpoints() + { + var serverOptions = CreateServerOptions(); + + serverOptions.ConfigureEndpointDefaults(opt => + { + opt.NoDelay = false; + }); + + serverOptions.ConfigureHttpsDefaults(opt => + { + opt.ServerCertificate = new X509Certificate2(TestResources.TestCertificatePath, "testPassword"); + opt.ClientCertificateMode = ClientCertificateMode.RequireCertificate; + }); + + var ran1 = false; + var ran2 = false; + var config = new ConfigurationBuilder().AddInMemoryCollection(new[] + { + new KeyValuePair("Endpoints:End1:Url", "https://*:5001"), + }).Build(); + serverOptions.Configure(config) + .Endpoint("End1", opt => + { + ran1 = true; + Assert.True(opt.IsHttps); + Assert.NotNull(opt.HttpsOptions.ServerCertificate); + Assert.Equal(ClientCertificateMode.RequireCertificate, opt.HttpsOptions.ClientCertificateMode); + Assert.False(opt.ListenOptions.NoDelay); + }) + .LocalhostEndpoint(5002, opt => + { + ran2 = true; + Assert.False(opt.NoDelay); + }) + .Load(); + + Assert.True(ran1); + Assert.True(ran2); + + Assert.NotNull(serverOptions.ListenOptions[0].ConnectionAdapters.Where(adapter => adapter.IsHttps).SingleOrDefault()); + Assert.Null(serverOptions.ListenOptions[1].ConnectionAdapters.Where(adapter => adapter.IsHttps).SingleOrDefault()); + } + + [Fact] + public void ConfigureEndpointDefaultCanEnableHttps() + { + var serverOptions = CreateServerOptions(); + + serverOptions.ConfigureEndpointDefaults(opt => + { + opt.NoDelay = false; + opt.UseHttps(new X509Certificate2(TestResources.TestCertificatePath, "testPassword")); + }); + + serverOptions.ConfigureHttpsDefaults(opt => + { + opt.ClientCertificateMode = ClientCertificateMode.RequireCertificate; + }); + + var ran1 = false; + var ran2 = false; + var config = new ConfigurationBuilder().AddInMemoryCollection(new[] + { + new KeyValuePair("Endpoints:End1:Url", "https://*:5001"), + }).Build(); + serverOptions.Configure(config) + .Endpoint("End1", opt => + { + ran1 = true; + Assert.True(opt.IsHttps); + Assert.Equal(ClientCertificateMode.RequireCertificate, opt.HttpsOptions.ClientCertificateMode); + Assert.False(opt.ListenOptions.NoDelay); + }) + .LocalhostEndpoint(5002, opt => + { + ran2 = true; + Assert.False(opt.NoDelay); + }) + .Load(); + + Assert.True(ran1); + Assert.True(ran2); + + // You only get Https once per endpoint. + Assert.NotNull(serverOptions.ListenOptions[0].ConnectionAdapters.Where(adapter => adapter.IsHttps).SingleOrDefault()); + Assert.NotNull(serverOptions.ListenOptions[1].ConnectionAdapters.Where(adapter => adapter.IsHttps).SingleOrDefault()); + } + } +} diff --git a/test/SystemdActivation/docker-entrypoint.sh b/test/SystemdActivation/docker-entrypoint.sh index 2b501ef6ae..cb8d2f2d6f 100644 --- a/test/SystemdActivation/docker-entrypoint.sh +++ b/test/SystemdActivation/docker-entrypoint.sh @@ -3,10 +3,10 @@ set -e cd /publish -systemd-socket-activate -l 8080 -E ASPNETCORE_BASE_PORT=7000 dotnet SampleApp.dll & +systemd-socket-activate -l 8080 -E ASPNETCORE_BASE_PORT=7000 dotnet SystemdTestApp.dll & socat TCP-LISTEN:8081,fork TCP-CONNECT:127.0.0.1:7000 & socat TCP-LISTEN:8082,fork TCP-CONNECT:127.0.0.1:7001 & -systemd-socket-activate -l /tmp/activate-kestrel.sock -E ASPNETCORE_BASE_PORT=7100 dotnet SampleApp.dll & +systemd-socket-activate -l /tmp/activate-kestrel.sock -E ASPNETCORE_BASE_PORT=7100 dotnet SystemdTestApp.dll & socat TCP-LISTEN:8083,fork UNIX-CLIENT:/tmp/activate-kestrel.sock & socat TCP-LISTEN:8084,fork TCP-CONNECT:127.0.0.1:7100 & socat TCP-LISTEN:8085,fork TCP-CONNECT:127.0.0.1:7101 & diff --git a/test/SystemdActivation/docker.sh b/test/SystemdActivation/docker.sh index 1f4a62b3a6..28560cf69f 100644 --- a/test/SystemdActivation/docker.sh +++ b/test/SystemdActivation/docker.sh @@ -4,14 +4,14 @@ set -e scriptDir=$(dirname "${BASH_SOURCE[0]}") PATH="$HOME/.dotnet/:$PATH" -dotnet publish -f netcoreapp2.0 ./samples/SampleApp/ -cp -R ./samples/SampleApp/bin/Debug/netcoreapp2.0/publish/ $scriptDir +dotnet publish -f netcoreapp2.0 ./samples/SystemdTestApp/ +cp -R ./samples/SystemdTestApp/bin/Debug/netcoreapp2.0/publish/ $scriptDir cp -R ~/.dotnet/ $scriptDir image=$(docker build -qf $scriptDir/Dockerfile $scriptDir) container=$(docker run -Pd $image) -# Try to connect to SampleApp once a second up to 10 times via all available ports. +# Try to connect to SystemdTestApp once a second up to 10 times via all available ports. for i in {1..10}; do curl -f http://$(docker port $container 8080/tcp) \ && curl -f http://$(docker port $container 8081/tcp) \ diff --git a/test/shared/TestResources.cs b/test/shared/TestResources.cs index 6b0cf70fec..b8ae46d18f 100644 --- a/test/shared/TestResources.cs +++ b/test/shared/TestResources.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.IO; +using System.Security.Cryptography.X509Certificates; namespace Microsoft.AspNetCore.Testing { @@ -11,5 +12,10 @@ namespace Microsoft.AspNetCore.Testing public static string TestCertificatePath { get; } = Path.Combine(_baseDir, "testCert.pfx"); public static string GetCertPath(string name) => Path.Combine(_baseDir, name); + + public static X509Certificate2 GetTestCertificate() + { + return new X509Certificate2(TestCertificatePath, "testPassword"); + } } } From e7cc0d33af55c60ca386f774ab30dfdab2305c73 Mon Sep 17 00:00:00 2001 From: Pavel Krymets Date: Fri, 22 Dec 2017 09:51:26 -0800 Subject: [PATCH 1483/1662] Use common BDN config (#2233) --- .../Kestrel.Performance/AssemblyInfo.cs | 1 + .../DotSegmentRemovalBenchmark.cs | 1 - ...Http1ConnectionParsingOverheadBenchmark.cs | 1 - .../Http1WritingBenchmark.cs | 1 - .../HttpParserBenchmark.cs | 2 -- .../HttpProtocolFeatureCollection.cs | 1 - .../KnownStringsBenchmark.cs | 1 - .../PipeThroughputBenchmark.cs | 1 - .../RequestParsingBenchmark.cs | 1 - .../ResponseHeaderCollectionBenchmark.cs | 1 - .../ResponseHeadersWritingBenchmark.cs | 1 - .../StringUtilitiesBenchmark.cs | 1 - .../Kestrel.Performance/configs/CoreConfig.cs | 36 ------------------- 13 files changed, 1 insertion(+), 48 deletions(-) create mode 100644 benchmarks/Kestrel.Performance/AssemblyInfo.cs delete mode 100644 benchmarks/Kestrel.Performance/configs/CoreConfig.cs diff --git a/benchmarks/Kestrel.Performance/AssemblyInfo.cs b/benchmarks/Kestrel.Performance/AssemblyInfo.cs new file mode 100644 index 0000000000..32248e0d1b --- /dev/null +++ b/benchmarks/Kestrel.Performance/AssemblyInfo.cs @@ -0,0 +1 @@ +[assembly: BenchmarkDotNet.Attributes.AspNetCoreBenchmark] diff --git a/benchmarks/Kestrel.Performance/DotSegmentRemovalBenchmark.cs b/benchmarks/Kestrel.Performance/DotSegmentRemovalBenchmark.cs index caa43f2b58..79389d4a33 100644 --- a/benchmarks/Kestrel.Performance/DotSegmentRemovalBenchmark.cs +++ b/benchmarks/Kestrel.Performance/DotSegmentRemovalBenchmark.cs @@ -8,7 +8,6 @@ using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; namespace Microsoft.AspNetCore.Server.Kestrel.Performance { - [ParameterizedJobConfig(typeof(CoreConfig))] public class DotSegmentRemovalBenchmark { // Immutable diff --git a/benchmarks/Kestrel.Performance/Http1ConnectionParsingOverheadBenchmark.cs b/benchmarks/Kestrel.Performance/Http1ConnectionParsingOverheadBenchmark.cs index 5b2af1d52a..4747c696ee 100644 --- a/benchmarks/Kestrel.Performance/Http1ConnectionParsingOverheadBenchmark.cs +++ b/benchmarks/Kestrel.Performance/Http1ConnectionParsingOverheadBenchmark.cs @@ -12,7 +12,6 @@ using Microsoft.AspNetCore.Server.Kestrel.Performance.Mocks; namespace Microsoft.AspNetCore.Server.Kestrel.Performance { - [ParameterizedJobConfig(typeof(CoreConfig))] public class Http1ConnectionParsingOverheadBenchmark { private const int InnerLoopCount = 512; diff --git a/benchmarks/Kestrel.Performance/Http1WritingBenchmark.cs b/benchmarks/Kestrel.Performance/Http1WritingBenchmark.cs index fcc3f86bc4..3904523c02 100644 --- a/benchmarks/Kestrel.Performance/Http1WritingBenchmark.cs +++ b/benchmarks/Kestrel.Performance/Http1WritingBenchmark.cs @@ -16,7 +16,6 @@ using Microsoft.AspNetCore.Testing; namespace Microsoft.AspNetCore.Server.Kestrel.Performance { - [ParameterizedJobConfig(typeof(CoreConfig))] public class Http1WritingBenchmark { // Standard completed task diff --git a/benchmarks/Kestrel.Performance/HttpParserBenchmark.cs b/benchmarks/Kestrel.Performance/HttpParserBenchmark.cs index 0bf1a6fca4..429dc358e7 100644 --- a/benchmarks/Kestrel.Performance/HttpParserBenchmark.cs +++ b/benchmarks/Kestrel.Performance/HttpParserBenchmark.cs @@ -8,8 +8,6 @@ using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; namespace Microsoft.AspNetCore.Server.Kestrel.Performance { - [ParameterizedJobConfig(typeof(CoreConfig))] - public class HttpParserBenchmark : IHttpRequestLineHandler, IHttpHeadersHandler { private readonly HttpParser _parser = new HttpParser(); diff --git a/benchmarks/Kestrel.Performance/HttpProtocolFeatureCollection.cs b/benchmarks/Kestrel.Performance/HttpProtocolFeatureCollection.cs index b5ebc8531e..23d9c80d3b 100644 --- a/benchmarks/Kestrel.Performance/HttpProtocolFeatureCollection.cs +++ b/benchmarks/Kestrel.Performance/HttpProtocolFeatureCollection.cs @@ -12,7 +12,6 @@ using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; namespace Microsoft.AspNetCore.Server.Kestrel.Performance { - [ParameterizedJobConfig(typeof(CoreConfig))] public class HttpProtocolFeatureCollection { private readonly Http1Connection _http1Connection; diff --git a/benchmarks/Kestrel.Performance/KnownStringsBenchmark.cs b/benchmarks/Kestrel.Performance/KnownStringsBenchmark.cs index 095d568360..69bf2d5adb 100644 --- a/benchmarks/Kestrel.Performance/KnownStringsBenchmark.cs +++ b/benchmarks/Kestrel.Performance/KnownStringsBenchmark.cs @@ -9,7 +9,6 @@ using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; namespace Microsoft.AspNetCore.Server.Kestrel.Performance { - [ParameterizedJobConfig(typeof(CoreConfig))] public class KnownStringsBenchmark { static byte[] _methodConnect = Encoding.ASCII.GetBytes("CONNECT "); diff --git a/benchmarks/Kestrel.Performance/PipeThroughputBenchmark.cs b/benchmarks/Kestrel.Performance/PipeThroughputBenchmark.cs index 92b04887f3..999fa0a8e1 100644 --- a/benchmarks/Kestrel.Performance/PipeThroughputBenchmark.cs +++ b/benchmarks/Kestrel.Performance/PipeThroughputBenchmark.cs @@ -8,7 +8,6 @@ using BenchmarkDotNet.Attributes; namespace Microsoft.AspNetCore.Server.Kestrel.Performance { - [ParameterizedJobConfig(typeof(CoreConfig))] public class PipeThroughputBenchmark { private const int _writeLenght = 57; diff --git a/benchmarks/Kestrel.Performance/RequestParsingBenchmark.cs b/benchmarks/Kestrel.Performance/RequestParsingBenchmark.cs index c7b74bf7d5..7762902258 100644 --- a/benchmarks/Kestrel.Performance/RequestParsingBenchmark.cs +++ b/benchmarks/Kestrel.Performance/RequestParsingBenchmark.cs @@ -12,7 +12,6 @@ using Microsoft.AspNetCore.Server.Kestrel.Performance.Mocks; namespace Microsoft.AspNetCore.Server.Kestrel.Performance { - [ParameterizedJobConfig(typeof(CoreConfig))] public class RequestParsingBenchmark { public IPipe Pipe { get; set; } diff --git a/benchmarks/Kestrel.Performance/ResponseHeaderCollectionBenchmark.cs b/benchmarks/Kestrel.Performance/ResponseHeaderCollectionBenchmark.cs index 1e49ec53f2..8f722aaba5 100644 --- a/benchmarks/Kestrel.Performance/ResponseHeaderCollectionBenchmark.cs +++ b/benchmarks/Kestrel.Performance/ResponseHeaderCollectionBenchmark.cs @@ -15,7 +15,6 @@ using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; namespace Microsoft.AspNetCore.Server.Kestrel.Performance { - [ParameterizedJobConfig(typeof(CoreConfig))] public class ResponseHeaderCollectionBenchmark { private const int InnerLoopCount = 512; diff --git a/benchmarks/Kestrel.Performance/ResponseHeadersWritingBenchmark.cs b/benchmarks/Kestrel.Performance/ResponseHeadersWritingBenchmark.cs index 024fd1ae1c..9c807620e4 100644 --- a/benchmarks/Kestrel.Performance/ResponseHeadersWritingBenchmark.cs +++ b/benchmarks/Kestrel.Performance/ResponseHeadersWritingBenchmark.cs @@ -17,7 +17,6 @@ using Microsoft.AspNetCore.Testing; namespace Microsoft.AspNetCore.Server.Kestrel.Performance { - [ParameterizedJobConfig(typeof(CoreConfig))] public class ResponseHeadersWritingBenchmark { private static readonly byte[] _helloWorldPayload = Encoding.ASCII.GetBytes("Hello, World!"); diff --git a/benchmarks/Kestrel.Performance/StringUtilitiesBenchmark.cs b/benchmarks/Kestrel.Performance/StringUtilitiesBenchmark.cs index 3d1b8aee01..e2b2e9eab1 100644 --- a/benchmarks/Kestrel.Performance/StringUtilitiesBenchmark.cs +++ b/benchmarks/Kestrel.Performance/StringUtilitiesBenchmark.cs @@ -6,7 +6,6 @@ using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; namespace Microsoft.AspNetCore.Server.Kestrel.Performance { - [ParameterizedJobConfig(typeof(CoreConfig))] public class StringUtilitiesBenchmark { private const int Iterations = 500_000; diff --git a/benchmarks/Kestrel.Performance/configs/CoreConfig.cs b/benchmarks/Kestrel.Performance/configs/CoreConfig.cs deleted file mode 100644 index 98f1ab03fd..0000000000 --- a/benchmarks/Kestrel.Performance/configs/CoreConfig.cs +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using BenchmarkDotNet.Columns; -using BenchmarkDotNet.Configs; -using BenchmarkDotNet.Diagnosers; -using BenchmarkDotNet.Engines; -using BenchmarkDotNet.Jobs; -using BenchmarkDotNet.Validators; - -namespace Microsoft.AspNetCore.Server.Kestrel.Performance -{ - public class CoreConfig : ManualConfig - { - public CoreConfig() : this(Job.Core - .WithRemoveOutliers(false) - .With(new GcMode() { Server = true }) - .With(RunStrategy.Throughput) - .WithLaunchCount(3) - .WithWarmupCount(5) - .WithTargetCount(10)) - { - Add(JitOptimizationsValidator.FailOnError); - } - - public CoreConfig(Job job) - { - Add(DefaultConfig.Instance); - - Add(MemoryDiagnoser.Default); - Add(StatisticColumn.OperationsPerSecond); - - Add(job); - } - } -} From 9b3470dacbe50133d4a8cfd3508ec36ba40d8620 Mon Sep 17 00:00:00 2001 From: Pavel Krymets Date: Tue, 26 Dec 2017 11:15:43 -0800 Subject: [PATCH 1484/1662] Upgrade dependencies to fix benchmark build --- build/dependencies.props | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/build/dependencies.props b/build/dependencies.props index b6e10ad8cb..736bbbba7c 100644 --- a/build/dependencies.props +++ b/build/dependencies.props @@ -7,26 +7,26 @@ 0.10.11 2.1.0-preview1-15626 1.10.0 - 2.1.0-preview1-27845 - 2.1.0-preview1-27845 - 2.1.0-preview1-27845 - 2.1.0-preview1-27845 - 2.1.0-preview1-27845 - 2.1.0-preview1-27845 - 2.1.0-preview1-27845 - 2.1.0-preview1-27845 - 2.1.0-preview1-27845 - 2.1.0-preview1-27845 - 2.1.0-preview1-27845 - 2.1.0-preview1-27845 - 2.1.0-preview1-27845 - 2.1.0-preview1-27845 - 2.1.0-preview1-27845 - 2.1.0-preview1-27845 - 2.1.0-preview1-27845 + 2.1.0-preview1-27907 + 2.1.0-preview1-27907 + 2.1.0-preview1-27907 + 2.1.0-preview1-27907 + 2.1.0-preview1-27907 + 2.1.0-preview1-27907 + 2.1.0-preview1-27907 + 2.1.0-preview1-27907 + 2.1.0-preview1-27907 + 2.1.0-preview1-27907 + 2.1.0-preview1-27907 + 2.1.0-preview1-27907 + 2.1.0-preview1-27907 + 2.1.0-preview1-27907 + 2.1.0-preview1-27907 + 2.1.0-preview1-27907 + 2.1.0-preview1-27907 2.0.0 2.1.0-preview1-26016-05 - 2.1.0-preview1-27845 + 2.1.0-preview1-27907 15.3.0 4.7.49 10.0.1 From c8e93a610879c34681ed722695d4ac453785b81e Mon Sep 17 00:00:00 2001 From: Chris Ross Date: Wed, 27 Dec 2017 10:06:42 -0800 Subject: [PATCH 1485/1662] Use localhost dev cert in sample (#2235) --- samples/SampleApp/Startup.cs | 2 +- samples/SampleApp/appsettings.Development.json | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/samples/SampleApp/Startup.cs b/samples/SampleApp/Startup.cs index 09baead9da..02c66a20be 100644 --- a/samples/SampleApp/Startup.cs +++ b/samples/SampleApp/Startup.cs @@ -102,7 +102,7 @@ namespace SampleApp options.ListenAnyIP(basePort + 4, listenOptions => { - listenOptions.UseHttps(StoreName.My, "aspnet.test", allowInvalid: true); + listenOptions.UseHttps(StoreName.My, "localhost", allowInvalid: true); }); options diff --git a/samples/SampleApp/appsettings.Development.json b/samples/SampleApp/appsettings.Development.json index 9edfa91a20..741bd03aee 100644 --- a/samples/SampleApp/appsettings.Development.json +++ b/samples/SampleApp/appsettings.Development.json @@ -5,9 +5,9 @@ "NamedHttpsEndpoint": { "Url": "https://localhost:6443", "Certificate": { - "Subject": "aspnet.test", + "Subject": "localhost", "Store": "My", - "AllowInvalid": true + "AllowInvalid": true } } } From bf138224d880e34e68a2d3483ecc84830f3c4e92 Mon Sep 17 00:00:00 2001 From: "ASP.NET CI" Date: Sun, 31 Dec 2017 21:18:22 +0000 Subject: [PATCH 1486/1662] Update dependencies.props [auto-updated: dependencies] --- build/dependencies.props | 38 +++++++++++++++++++------------------- korebuild-lock.txt | 4 ++-- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/build/dependencies.props b/build/dependencies.props index 736bbbba7c..5c53fad5d0 100644 --- a/build/dependencies.props +++ b/build/dependencies.props @@ -5,28 +5,28 @@ 0.10.11 - 2.1.0-preview1-15626 + 2.1.0-preview1-15651 1.10.0 - 2.1.0-preview1-27907 - 2.1.0-preview1-27907 - 2.1.0-preview1-27907 - 2.1.0-preview1-27907 - 2.1.0-preview1-27907 - 2.1.0-preview1-27907 - 2.1.0-preview1-27907 - 2.1.0-preview1-27907 - 2.1.0-preview1-27907 - 2.1.0-preview1-27907 - 2.1.0-preview1-27907 - 2.1.0-preview1-27907 - 2.1.0-preview1-27907 - 2.1.0-preview1-27907 - 2.1.0-preview1-27907 - 2.1.0-preview1-27907 - 2.1.0-preview1-27907 + 2.1.0-preview1-27942 + 2.1.0-preview1-27942 + 2.1.0-preview1-27942 + 2.1.0-preview1-27942 + 2.1.0-preview1-27942 + 2.1.0-preview1-27942 + 2.1.0-preview1-27942 + 2.1.0-preview1-27942 + 2.1.0-preview1-27942 + 2.1.0-preview1-27942 + 2.1.0-preview1-27942 + 2.1.0-preview1-27942 + 2.1.0-preview1-27942 + 2.1.0-preview1-27942 + 2.1.0-preview1-27942 + 2.1.0-preview1-27942 + 2.1.0-preview1-27942 2.0.0 2.1.0-preview1-26016-05 - 2.1.0-preview1-27907 + 2.1.0-preview1-27942 15.3.0 4.7.49 10.0.1 diff --git a/korebuild-lock.txt b/korebuild-lock.txt index 8d52a6128c..7c2e97aa79 100644 --- a/korebuild-lock.txt +++ b/korebuild-lock.txt @@ -1,2 +1,2 @@ -version:2.1.0-preview1-15626 -commithash:fd6410e9c90c428bc01238372303ad09cb9ec889 +version:2.1.0-preview1-15651 +commithash:ebf2365121c2c6a6a0fbfa9b0f37bb5effc89323 From b57ac72431a0cd89a710d03d33b8edcb21a94756 Mon Sep 17 00:00:00 2001 From: "ASP.NET CI" Date: Thu, 4 Jan 2018 01:24:48 +0000 Subject: [PATCH 1487/1662] Update dependencies.props [auto-updated: dependencies] --- build/dependencies.props | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/build/dependencies.props b/build/dependencies.props index 5c53fad5d0..8693cc95ac 100644 --- a/build/dependencies.props +++ b/build/dependencies.props @@ -7,26 +7,26 @@ 0.10.11 2.1.0-preview1-15651 1.10.0 - 2.1.0-preview1-27942 - 2.1.0-preview1-27942 - 2.1.0-preview1-27942 - 2.1.0-preview1-27942 - 2.1.0-preview1-27942 - 2.1.0-preview1-27942 - 2.1.0-preview1-27942 - 2.1.0-preview1-27942 - 2.1.0-preview1-27942 - 2.1.0-preview1-27942 - 2.1.0-preview1-27942 - 2.1.0-preview1-27942 - 2.1.0-preview1-27942 - 2.1.0-preview1-27942 - 2.1.0-preview1-27942 - 2.1.0-preview1-27942 - 2.1.0-preview1-27942 + 2.1.0-preview1-27965 + 2.1.0-preview1-27965 + 2.1.0-preview1-27965 + 2.1.0-preview1-27965 + 2.1.0-preview1-27965 + 2.1.0-preview1-27965 + 2.1.0-preview1-27965 + 2.1.0-preview1-27965 + 2.1.0-preview1-27965 + 2.1.0-preview1-27965 + 2.1.0-preview1-27965 + 2.1.0-preview1-27965 + 2.1.0-preview1-27965 + 2.1.0-preview1-27965 + 2.1.0-preview1-27965 + 2.1.0-preview1-27965 + 2.1.0-preview1-27965 2.0.0 2.1.0-preview1-26016-05 - 2.1.0-preview1-27942 + 2.1.0-preview1-27965 15.3.0 4.7.49 10.0.1 From 1fa001e7db3d7eb93d42f7e0ef4c6c114a831d64 Mon Sep 17 00:00:00 2001 From: Pavel Krymets Date: Thu, 4 Jan 2018 09:54:42 -0800 Subject: [PATCH 1488/1662] React to pipeline changes (#2234) React to pipeline changes --- ...Http1ConnectionParsingOverheadBenchmark.cs | 2 +- .../HttpParserBenchmark.cs | 5 +- .../Kestrel.Performance/Mocks/NullParser.cs | 6 ++- build/dependencies.props | 21 ++++---- .../Adapter/Internal/AdaptedPipeline.cs | 1 + .../Internal/ConnectionHandler.cs | 4 +- .../Internal/Http/Http1Connection.cs | 11 +++-- .../Internal/Http/Http1MessageBody.cs | 44 +++++++++-------- .../Internal/Http/Http1OutputProducer.cs | 2 +- src/Kestrel.Core/Internal/Http/HttpParser.cs | 20 ++++---- .../Internal/Http/HttpProtocol.cs | 4 +- src/Kestrel.Core/Internal/Http/IHttpParser.cs | 8 ++-- .../Internal/Http/PipelineExtensions.cs | 12 ++++- .../Internal/Http2/Http2Connection.cs | 4 +- .../Internal/Http2/Http2FrameReader.cs | 4 +- src/Kestrel.Core/Internal/HttpConnection.cs | 6 +-- .../Infrastructure/InlineLoggingThreadPool.cs | 13 +++-- .../{IThreadPool.cs => KestrelThreadPool.cs} | 6 +-- .../Infrastructure/LoggingThreadPool.cs | 13 +++-- src/Kestrel.Core/Internal/ServiceContext.cs | 2 +- src/Kestrel.Core/KestrelServer.cs | 2 +- .../Internal/TransportConnection.cs | 4 +- .../Internal/LibuvConnection.cs | 3 +- .../Internal/LibuvConnectionContext.cs | 4 +- .../Internal/LibuvThread.cs | 9 +++- .../Internal/Networking/UvWriteReq.cs | 4 +- .../Internal/BufferExtensions.cs | 15 ++++-- .../Internal/SocketConnection.cs | 4 +- .../Internal/SocketSender.cs | 12 +++-- .../Features/IConnectionTransportFeature.cs | 4 +- .../ConnectionHandlerTests.cs | 4 +- .../Http1ConnectionTests.cs | 5 +- test/Kestrel.Core.Tests/HttpParserTests.cs | 48 +++++++------------ .../Kestrel.Core.Tests/OutputProducerTests.cs | 2 +- test/Kestrel.Core.Tests/PipeOptionsTests.cs | 10 ++-- .../LibuvConnectionTests.cs | 6 +-- .../MultipleLoopTests.cs | 3 +- .../NetworkingTests.cs | 3 +- 38 files changed, 187 insertions(+), 143 deletions(-) rename src/Kestrel.Core/Internal/Infrastructure/{IThreadPool.cs => KestrelThreadPool.cs} (64%) diff --git a/benchmarks/Kestrel.Performance/Http1ConnectionParsingOverheadBenchmark.cs b/benchmarks/Kestrel.Performance/Http1ConnectionParsingOverheadBenchmark.cs index 4747c696ee..f3ef888b9a 100644 --- a/benchmarks/Kestrel.Performance/Http1ConnectionParsingOverheadBenchmark.cs +++ b/benchmarks/Kestrel.Performance/Http1ConnectionParsingOverheadBenchmark.cs @@ -16,7 +16,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance { private const int InnerLoopCount = 512; - public ReadableBuffer _buffer; + public ReadOnlyBuffer _buffer; public Http1Connection _http1Connection; [IterationSetup] diff --git a/benchmarks/Kestrel.Performance/HttpParserBenchmark.cs b/benchmarks/Kestrel.Performance/HttpParserBenchmark.cs index 429dc358e7..4d63b75b91 100644 --- a/benchmarks/Kestrel.Performance/HttpParserBenchmark.cs +++ b/benchmarks/Kestrel.Performance/HttpParserBenchmark.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Buffers; using System.IO.Pipelines; using BenchmarkDotNet.Attributes; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; @@ -12,7 +13,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance { private readonly HttpParser _parser = new HttpParser(); - private ReadableBuffer _buffer; + private ReadOnlyBuffer _buffer; [Benchmark(Baseline = true, OperationsPerInvoke = RequestParsingData.InnerLoopCount)] public void PlaintextTechEmpower() @@ -46,7 +47,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance private void InsertData(byte[] data) { - _buffer = ReadableBuffer.Create(data); + _buffer = new ReadOnlyBuffer(data); } private void ParseData() diff --git a/benchmarks/Kestrel.Performance/Mocks/NullParser.cs b/benchmarks/Kestrel.Performance/Mocks/NullParser.cs index e9380cda77..f091f67320 100644 --- a/benchmarks/Kestrel.Performance/Mocks/NullParser.cs +++ b/benchmarks/Kestrel.Performance/Mocks/NullParser.cs @@ -2,6 +2,8 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Buffers; +using System.Collections.Sequences; using System.IO.Pipelines; using System.Text; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; @@ -21,7 +23,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance public static readonly NullParser Instance = new NullParser(); - public bool ParseHeaders(TRequestHandler handler, ReadableBuffer buffer, out ReadCursor consumed, out ReadCursor examined, out int consumedBytes) + public bool ParseHeaders(TRequestHandler handler, ReadOnlyBuffer buffer, out Position consumed, out Position examined, out int consumedBytes) { handler.OnHeader(new Span(_hostHeaderName), new Span(_hostHeaderValue)); handler.OnHeader(new Span(_acceptHeaderName), new Span(_acceptHeaderValue)); @@ -34,7 +36,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance return true; } - public bool ParseRequestLine(TRequestHandler handler, ReadableBuffer buffer, out ReadCursor consumed, out ReadCursor examined) + public bool ParseRequestLine(TRequestHandler handler, ReadOnlyBuffer buffer, out Position consumed, out Position examined) { handler.OnStartLine(HttpMethod.Get, HttpVersion.Http11, diff --git a/build/dependencies.props b/build/dependencies.props index 8693cc95ac..e0c9c9a59b 100644 --- a/build/dependencies.props +++ b/build/dependencies.props @@ -25,20 +25,21 @@ 2.1.0-preview1-27965 2.1.0-preview1-27965 2.0.0 - 2.1.0-preview1-26016-05 + 2.1.0-preview1-26102-01 2.1.0-preview1-27965 15.3.0 4.7.49 10.0.1 - 4.5.0-preview1-26016-05 - 0.1.0-e171215-1 - 0.1.0-e171215-1 - 4.5.0-preview1-26016-05 - 4.5.0-preview1-26016-05 - 4.5.0-preview1-26016-05 - 4.5.0-preview1-26016-05 - 0.1.0-e171215-1 - 4.5.0-preview2-25707-02 + 4.5.0-preview1-26102-01 + 0.1.0-e180104-2 + 0.1.0-e180104-2 + 0.1.0-e180104-2 + 4.5.0-preview1-26102-01 + 4.5.0-preview1-26102-01 + 4.5.0-preview1-26102-01 + 4.5.0-preview1-26102-01 + 0.1.0-e180104-2 + 4.5.0-preview1-26102-01 0.8.0 2.3.1 2.3.1 diff --git a/src/Kestrel.Core/Adapter/Internal/AdaptedPipeline.cs b/src/Kestrel.Core/Adapter/Internal/AdaptedPipeline.cs index 72c1780d08..43526c8243 100644 --- a/src/Kestrel.Core/Adapter/Internal/AdaptedPipeline.cs +++ b/src/Kestrel.Core/Adapter/Internal/AdaptedPipeline.cs @@ -6,6 +6,7 @@ using System.IO; using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; using System.IO.Pipelines; +using System.Runtime.InteropServices; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal { diff --git a/src/Kestrel.Core/Internal/ConnectionHandler.cs b/src/Kestrel.Core/Internal/ConnectionHandler.cs index ee49a5b239..d968fce78c 100644 --- a/src/Kestrel.Core/Internal/ConnectionHandler.cs +++ b/src/Kestrel.Core/Internal/ConnectionHandler.cs @@ -83,7 +83,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal } // Internal for testing - internal static PipeOptions GetInputPipeOptions(ServiceContext serviceContext, MemoryPool memoryPool, IScheduler writerScheduler) => new PipeOptions + internal static PipeOptions GetInputPipeOptions(ServiceContext serviceContext, MemoryPool memoryPool, Scheduler writerScheduler) => new PipeOptions ( pool: memoryPool, readerScheduler: serviceContext.ThreadPool, @@ -92,7 +92,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal maximumSizeLow: serviceContext.ServerOptions.Limits.MaxRequestBufferSize ?? 0 ); - internal static PipeOptions GetOutputPipeOptions(ServiceContext serviceContext, MemoryPool memoryPool, IScheduler readerScheduler) => new PipeOptions + internal static PipeOptions GetOutputPipeOptions(ServiceContext serviceContext, MemoryPool memoryPool, Scheduler readerScheduler) => new PipeOptions ( pool: memoryPool, readerScheduler: readerScheduler, diff --git a/src/Kestrel.Core/Internal/Http/Http1Connection.cs b/src/Kestrel.Core/Internal/Http/Http1Connection.cs index 5168bf7d61..84890c4137 100644 --- a/src/Kestrel.Core/Internal/Http/Http1Connection.cs +++ b/src/Kestrel.Core/Internal/Http/Http1Connection.cs @@ -2,11 +2,14 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Buffers; +using System.Collections.Sequences; using System.Diagnostics; using System.IO.Pipelines; using System.Runtime.InteropServices; using System.Text; using System.Text.Encodings.Web.Utf8; +using System.Threading; using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; @@ -66,7 +69,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http Input.CancelPendingRead(); } - public void ParseRequest(ReadableBuffer buffer, out ReadCursor consumed, out ReadCursor examined) + public void ParseRequest(ReadOnlyBuffer buffer, out Position consumed, out Position examined) { consumed = buffer.Start; examined = buffer.End; @@ -104,7 +107,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http } } - public bool TakeStartLine(ReadableBuffer buffer, out ReadCursor consumed, out ReadCursor examined) + public bool TakeStartLine(ReadOnlyBuffer buffer, out Position consumed, out Position examined) { var overLength = false; if (buffer.Length >= ServerOptions.Limits.MaxRequestLineSize) @@ -122,7 +125,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http return result; } - public bool TakeMessageHeaders(ReadableBuffer buffer, out ReadCursor consumed, out ReadCursor examined) + public bool TakeMessageHeaders(ReadOnlyBuffer buffer, out Position consumed, out Position examined) { // Make sure the buffer is limited bool overLength = false; @@ -424,7 +427,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http TimeoutControl.SetTimeout(_keepAliveTicks, TimeoutAction.StopProcessingNextRequest); } - protected override bool BeginRead(out ReadableBufferAwaitable awaitable) + protected override bool BeginRead(out ValueAwaiter awaitable) { awaitable = Input.ReadAsync(); return true; diff --git a/src/Kestrel.Core/Internal/Http/Http1MessageBody.cs b/src/Kestrel.Core/Internal/Http/Http1MessageBody.cs index 9b50aba2e3..e75f7e7255 100644 --- a/src/Kestrel.Core/Internal/Http/Http1MessageBody.cs +++ b/src/Kestrel.Core/Internal/Http/Http1MessageBody.cs @@ -2,6 +2,8 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Buffers; +using System.Collections.Sequences; using System.IO; using System.IO.Pipelines; using System.Threading.Tasks; @@ -149,7 +151,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http } } - protected void Copy(ReadableBuffer readableBuffer, WritableBuffer writableBuffer) + protected void Copy(ReadOnlyBuffer readableBuffer, WritableBuffer writableBuffer) { _context.TimeoutControl.BytesRead(readableBuffer.Length); @@ -171,7 +173,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http _pumpTask = PumpAsync(); } - protected virtual bool Read(ReadableBuffer readableBuffer, WritableBuffer writableBuffer, out ReadCursor consumed, out ReadCursor examined) + protected virtual bool Read(ReadOnlyBuffer readableBuffer, WritableBuffer writableBuffer, out Position consumed, out Position examined) { throw new NotImplementedException(); } @@ -296,7 +298,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http RequestUpgrade = true; } - protected override bool Read(ReadableBuffer readableBuffer, WritableBuffer writableBuffer, out ReadCursor consumed, out ReadCursor examined) + protected override bool Read(ReadOnlyBuffer readableBuffer, WritableBuffer writableBuffer, out Position consumed, out Position examined) { Copy(readableBuffer, writableBuffer); consumed = readableBuffer.End; @@ -318,7 +320,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http _inputLength = _contentLength; } - protected override bool Read(ReadableBuffer readableBuffer, WritableBuffer writableBuffer, out ReadCursor consumed, out ReadCursor examined) + protected override bool Read(ReadOnlyBuffer readableBuffer, WritableBuffer writableBuffer, out Position consumed, out Position examined) { if (_inputLength == 0) { @@ -366,10 +368,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http RequestKeepAlive = keepAlive; } - protected override bool Read(ReadableBuffer readableBuffer, WritableBuffer writableBuffer, out ReadCursor consumed, out ReadCursor examined) + protected override bool Read(ReadOnlyBuffer readableBuffer, WritableBuffer writableBuffer, out Position consumed, out Position examined) { - consumed = default(ReadCursor); - examined = default(ReadCursor); + consumed = default(Position); + examined = default(Position); while (_mode < Mode.Trailer) { @@ -457,17 +459,17 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http } } - private void ParseChunkedPrefix(ReadableBuffer buffer, out ReadCursor consumed, out ReadCursor examined) + private void ParseChunkedPrefix(ReadOnlyBuffer buffer, out Position consumed, out Position examined) { consumed = buffer.Start; examined = buffer.Start; - var reader = new ReadableBufferReader(buffer); + var reader = BufferReader.Create(buffer); var ch1 = reader.Take(); var ch2 = reader.Take(); if (ch1 == -1 || ch2 == -1) { - examined = reader.Cursor; + examined = reader.Position; return; } @@ -478,8 +480,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { if (ch1 == ';') { - consumed = reader.Cursor; - examined = reader.Cursor; + consumed = reader.Position; + examined = reader.Position; AddAndCheckConsumedBytes(reader.ConsumedBytes); _inputLength = chunkSize; @@ -490,14 +492,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http ch2 = reader.Take(); if (ch2 == -1) { - examined = reader.Cursor; + examined = reader.Position; return; } if (ch1 == '\r' && ch2 == '\n') { - consumed = reader.Cursor; - examined = reader.Cursor; + consumed = reader.Position; + examined = reader.Position; AddAndCheckConsumedBytes(reader.ConsumedBytes); _inputLength = chunkSize; @@ -513,7 +515,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http _context.ThrowRequestRejected(RequestRejectionReason.BadChunkSizeData); } - private void ParseExtension(ReadableBuffer buffer, out ReadCursor consumed, out ReadCursor examined) + private void ParseExtension(ReadOnlyBuffer buffer, out Position consumed, out Position examined) { // Chunk-extensions not currently parsed // Just drain the data @@ -522,8 +524,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http do { - ReadCursor extensionCursor; - if (ReadCursorOperations.Seek(buffer.Start, buffer.End, out extensionCursor, ByteCR) == -1) + Position extensionCursor; + if (ReadOnlyBuffer.Seek(buffer.Start, buffer.End, out extensionCursor, ByteCR) == -1) { // End marker not found yet consumed = buffer.End; @@ -565,7 +567,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http } while (_mode == Mode.Extension); } - private void ReadChunkedData(ReadableBuffer buffer, WritableBuffer writableBuffer, out ReadCursor consumed, out ReadCursor examined) + private void ReadChunkedData(ReadOnlyBuffer buffer, WritableBuffer writableBuffer, out Position consumed, out Position examined) { var actual = Math.Min(buffer.Length, _inputLength); consumed = buffer.Move(buffer.Start, actual); @@ -582,7 +584,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http } } - private void ParseChunkedSuffix(ReadableBuffer buffer, out ReadCursor consumed, out ReadCursor examined) + private void ParseChunkedSuffix(ReadOnlyBuffer buffer, out Position consumed, out Position examined) { consumed = buffer.Start; examined = buffer.Start; @@ -608,7 +610,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http } } - private void ParseChunkedTrailer(ReadableBuffer buffer, out ReadCursor consumed, out ReadCursor examined) + private void ParseChunkedTrailer(ReadOnlyBuffer buffer, out Position consumed, out Position examined) { consumed = buffer.Start; examined = buffer.Start; diff --git a/src/Kestrel.Core/Internal/Http/Http1OutputProducer.cs b/src/Kestrel.Core/Internal/Http/Http1OutputProducer.cs index 34c74f23d1..466f17f64e 100644 --- a/src/Kestrel.Core/Internal/Http/Http1OutputProducer.cs +++ b/src/Kestrel.Core/Internal/Http/Http1OutputProducer.cs @@ -203,7 +203,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http return FlushAsyncAwaited(awaitable, bytesWritten, cancellationToken); } - private async Task FlushAsyncAwaited(WritableBufferAwaitable awaitable, long count, CancellationToken cancellationToken) + private async Task FlushAsyncAwaited(ValueAwaiter awaitable, long count, CancellationToken cancellationToken) { // https://github.com/dotnet/corefxlab/issues/1334 // Since the flush awaitable doesn't currently support multiple awaiters diff --git a/src/Kestrel.Core/Internal/Http/HttpParser.cs b/src/Kestrel.Core/Internal/Http/HttpParser.cs index ab66b2337f..13297094f3 100644 --- a/src/Kestrel.Core/Internal/Http/HttpParser.cs +++ b/src/Kestrel.Core/Internal/Http/HttpParser.cs @@ -2,6 +2,8 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Buffers; +using System.Collections.Sequences; using System.IO.Pipelines; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; @@ -31,7 +33,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http private const byte ByteQuestionMark = (byte)'?'; private const byte BytePercentage = (byte)'%'; - public unsafe bool ParseRequestLine(TRequestHandler handler, ReadableBuffer buffer, out ReadCursor consumed, out ReadCursor examined) + public unsafe bool ParseRequestLine(TRequestHandler handler, ReadOnlyBuffer buffer, out Position consumed, out Position examined) { consumed = buffer.Start; examined = buffer.End; @@ -186,7 +188,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http handler.OnStartLine(method, httpVersion, targetBuffer, pathBuffer, query, customMethod, pathEncoded); } - public unsafe bool ParseHeaders(TRequestHandler handler, ReadableBuffer buffer, out ReadCursor consumed, out ReadCursor examined, out int consumedBytes) + public unsafe bool ParseHeaders(TRequestHandler handler, ReadOnlyBuffer buffer, out Position consumed, out Position examined, out int consumedBytes) { consumed = buffer.Start; examined = buffer.End; @@ -194,8 +196,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http var bufferEnd = buffer.End; - var reader = new ReadableBufferReader(buffer); - var start = default(ReadableBufferReader); + var reader = BufferReader.Create(buffer); + var start = default(BufferReader); var done = false; try @@ -276,10 +278,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http } else { - var current = reader.Cursor; + var current = reader.Position; // Split buffers - if (ReadCursorOperations.Seek(current, bufferEnd, out var lineEnd, ByteLF) == -1) + if (ReadOnlyBuffer.Seek(current, bufferEnd, out var lineEnd, ByteLF) == -1) { // Not there return false; @@ -312,7 +314,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http } finally { - consumed = reader.Cursor; + consumed = reader.Position; consumedBytes = reader.ConsumedBytes; if (done) @@ -412,10 +414,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http } [MethodImpl(MethodImplOptions.NoInlining)] - private static bool TryGetNewLine(ref ReadableBuffer buffer, out ReadCursor found) + private static bool TryGetNewLine(ref ReadOnlyBuffer buffer, out Position found) { var start = buffer.Start; - if (ReadCursorOperations.Seek(start, buffer.End, out found, ByteLF) != -1) + if (ReadOnlyBuffer.Seek(start, buffer.End, out found, ByteLF) != -1) { // Move 1 byte past the \n found = buffer.Move(found, 1); diff --git a/src/Kestrel.Core/Internal/Http/HttpProtocol.cs b/src/Kestrel.Core/Internal/Http/HttpProtocol.cs index fca679dd23..2d722efa3e 100644 --- a/src/Kestrel.Core/Internal/Http/HttpProtocol.cs +++ b/src/Kestrel.Core/Internal/Http/HttpProtocol.cs @@ -380,7 +380,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { } - protected virtual bool BeginRead(out ReadableBufferAwaitable awaitable) + protected virtual bool BeginRead(out ValueAwaiter awaitable) { awaitable = default; return false; @@ -1302,7 +1302,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http ( pool: _context.MemoryPool, readerScheduler: ServiceContext.ThreadPool, - writerScheduler: InlineScheduler.Default, + writerScheduler: Scheduler.Inline, maximumSizeHigh: 1, maximumSizeLow: 1 )); diff --git a/src/Kestrel.Core/Internal/Http/IHttpParser.cs b/src/Kestrel.Core/Internal/Http/IHttpParser.cs index a0a477d0f0..07dff45a84 100644 --- a/src/Kestrel.Core/Internal/Http/IHttpParser.cs +++ b/src/Kestrel.Core/Internal/Http/IHttpParser.cs @@ -1,14 +1,16 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System.Buffers; +using System.Collections.Sequences; using System.IO.Pipelines; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { public interface IHttpParser where TRequestHandler : IHttpHeadersHandler, IHttpRequestLineHandler { - bool ParseRequestLine(TRequestHandler handler, ReadableBuffer buffer, out ReadCursor consumed, out ReadCursor examined); + bool ParseRequestLine(TRequestHandler handler, ReadOnlyBuffer buffer, out Position consumed, out Position examined); - bool ParseHeaders(TRequestHandler handler, ReadableBuffer buffer, out ReadCursor consumed, out ReadCursor examined, out int consumedBytes); + bool ParseHeaders(TRequestHandler handler, ReadOnlyBuffer buffer, out Position consumed, out Position examined, out int consumedBytes); } -} \ No newline at end of file +} diff --git a/src/Kestrel.Core/Internal/Http/PipelineExtensions.cs b/src/Kestrel.Core/Internal/Http/PipelineExtensions.cs index 6989d80aa3..e45d8ef5c5 100644 --- a/src/Kestrel.Core/Internal/Http/PipelineExtensions.cs +++ b/src/Kestrel.Core/Internal/Http/PipelineExtensions.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Buffers; using System.IO.Pipelines; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; @@ -16,7 +17,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http private static byte[] _numericBytesScratch; [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Span ToSpan(this ReadableBuffer buffer) + public static ReadOnlySpan ToSpan(this ReadOnlyBuffer buffer) { if (buffer.IsSingleSpan) { @@ -35,6 +36,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http return result; } + public static ArraySegment GetArray(this ReadOnlyMemory memory) + { + if (!MemoryMarshal.TryGetArray(memory, out var result)) + { + throw new InvalidOperationException("Buffer backed by array was expected"); + } + return result; + } + public unsafe static void WriteAsciiNoValidation(ref this WritableBufferWriter buffer, string data) { if (string.IsNullOrEmpty(data)) diff --git a/src/Kestrel.Core/Internal/Http2/Http2Connection.cs b/src/Kestrel.Core/Internal/Http2/Http2Connection.cs index db71ff63c9..c1cb104f50 100644 --- a/src/Kestrel.Core/Internal/Http2/Http2Connection.cs +++ b/src/Kestrel.Core/Internal/Http2/Http2Connection.cs @@ -2,6 +2,8 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Buffers; +using System.Collections.Sequences; using System.Collections.Concurrent; using System.IO.Pipelines; using System.Text; @@ -214,7 +216,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 } } - private bool ParsePreface(ReadableBuffer readableBuffer, out ReadCursor consumed, out ReadCursor examined) + private bool ParsePreface(ReadOnlyBuffer readableBuffer, out Position consumed, out Position examined) { consumed = readableBuffer.Start; examined = readableBuffer.End; diff --git a/src/Kestrel.Core/Internal/Http2/Http2FrameReader.cs b/src/Kestrel.Core/Internal/Http2/Http2FrameReader.cs index 2a45009277..0a2ae72aa0 100644 --- a/src/Kestrel.Core/Internal/Http2/Http2FrameReader.cs +++ b/src/Kestrel.Core/Internal/Http2/Http2FrameReader.cs @@ -1,13 +1,15 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System.Buffers; +using System.Collections.Sequences; using System.IO.Pipelines; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 { public static class Http2FrameReader { - public static bool ReadFrame(ReadableBuffer readableBuffer, Http2Frame frame, out ReadCursor consumed, out ReadCursor examined) + public static bool ReadFrame(ReadOnlyBuffer readableBuffer, Http2Frame frame, out Position consumed, out Position examined) { consumed = readableBuffer.Start; examined = readableBuffer.End; diff --git a/src/Kestrel.Core/Internal/HttpConnection.cs b/src/Kestrel.Core/Internal/HttpConnection.cs index 44f0fcbd1a..1ac4945ae4 100644 --- a/src/Kestrel.Core/Internal/HttpConnection.cs +++ b/src/Kestrel.Core/Internal/HttpConnection.cs @@ -73,7 +73,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal ( pool: MemoryPool, readerScheduler: _context.ServiceContext.ThreadPool, - writerScheduler: InlineScheduler.Default, + writerScheduler: Scheduler.Inline, maximumSizeHigh: _context.ServiceContext.ServerOptions.Limits.MaxRequestBufferSize ?? 0, maximumSizeLow: _context.ServiceContext.ServerOptions.Limits.MaxRequestBufferSize ?? 0 ); @@ -81,8 +81,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal internal PipeOptions AdaptedOutputPipeOptions => new PipeOptions ( pool: MemoryPool, - readerScheduler: InlineScheduler.Default, - writerScheduler: InlineScheduler.Default, + readerScheduler: Scheduler.Inline, + writerScheduler: Scheduler.Inline, maximumSizeHigh: _context.ServiceContext.ServerOptions.Limits.MaxResponseBufferSize ?? 0, maximumSizeLow: _context.ServiceContext.ServerOptions.Limits.MaxResponseBufferSize ?? 0 ); diff --git a/src/Kestrel.Core/Internal/Infrastructure/InlineLoggingThreadPool.cs b/src/Kestrel.Core/Internal/Infrastructure/InlineLoggingThreadPool.cs index f762ff976b..26219bf8b0 100644 --- a/src/Kestrel.Core/Internal/Infrastructure/InlineLoggingThreadPool.cs +++ b/src/Kestrel.Core/Internal/Infrastructure/InlineLoggingThreadPool.cs @@ -7,7 +7,7 @@ using Microsoft.Extensions.Logging; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure { - public class InlineLoggingThreadPool : IThreadPool + public class InlineLoggingThreadPool : KestrelThreadPool { private readonly IKestrelTrace _log; @@ -16,7 +16,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure _log = log; } - public void Run(Action action) + public override void Run(Action action) { try { @@ -28,12 +28,17 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure } } - public void UnsafeRun(WaitCallback action, object state) + public override void UnsafeRun(WaitCallback action, object state) { action(state); } - public void Schedule(Action action, object state) + public override void Schedule(Action action) + { + Run(action); + } + + public override void Schedule(Action action, object state) { try { diff --git a/src/Kestrel.Core/Internal/Infrastructure/IThreadPool.cs b/src/Kestrel.Core/Internal/Infrastructure/KestrelThreadPool.cs similarity index 64% rename from src/Kestrel.Core/Internal/Infrastructure/IThreadPool.cs rename to src/Kestrel.Core/Internal/Infrastructure/KestrelThreadPool.cs index c78a4db61d..54375c3aaa 100644 --- a/src/Kestrel.Core/Internal/Infrastructure/IThreadPool.cs +++ b/src/Kestrel.Core/Internal/Infrastructure/KestrelThreadPool.cs @@ -7,9 +7,9 @@ using System.Threading; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure { - public interface IThreadPool : IScheduler + public abstract class KestrelThreadPool: Scheduler { - void Run(Action action); - void UnsafeRun(WaitCallback action, object state); + public abstract void Run(Action action); + public abstract void UnsafeRun(WaitCallback action, object state); } } \ No newline at end of file diff --git a/src/Kestrel.Core/Internal/Infrastructure/LoggingThreadPool.cs b/src/Kestrel.Core/Internal/Infrastructure/LoggingThreadPool.cs index 184d956b18..1d90a7b681 100644 --- a/src/Kestrel.Core/Internal/Infrastructure/LoggingThreadPool.cs +++ b/src/Kestrel.Core/Internal/Infrastructure/LoggingThreadPool.cs @@ -7,7 +7,7 @@ using Microsoft.Extensions.Logging; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure { - public class LoggingThreadPool : IThreadPool + public class LoggingThreadPool : KestrelThreadPool { private readonly IKestrelTrace _log; @@ -40,17 +40,22 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure }; } - public void Run(Action action) + public override void Run(Action action) { ThreadPool.QueueUserWorkItem(_runAction, action); } - public void UnsafeRun(WaitCallback action, object state) + public override void UnsafeRun(WaitCallback action, object state) { ThreadPool.QueueUserWorkItem(action, state); } - public void Schedule(Action action, object state) + public override void Schedule(Action action) + { + Run(action); + } + + public override void Schedule(Action action, object state) { Run(() => action(state)); } diff --git a/src/Kestrel.Core/Internal/ServiceContext.cs b/src/Kestrel.Core/Internal/ServiceContext.cs index 30f45b1f37..9bad6b576b 100644 --- a/src/Kestrel.Core/Internal/ServiceContext.cs +++ b/src/Kestrel.Core/Internal/ServiceContext.cs @@ -11,7 +11,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal { public IKestrelTrace Log { get; set; } - public IThreadPool ThreadPool { get; set; } + public KestrelThreadPool ThreadPool { get; set; } public IHttpParser HttpParser { get; set; } diff --git a/src/Kestrel.Core/KestrelServer.cs b/src/Kestrel.Core/KestrelServer.cs index 43b7ee3981..6d2c1d059c 100644 --- a/src/Kestrel.Core/KestrelServer.cs +++ b/src/Kestrel.Core/KestrelServer.cs @@ -77,7 +77,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core // TODO: This logic will eventually move into the IConnectionHandler and off // the service context once we get to https://github.com/aspnet/KestrelHttpServer/issues/1662 - IThreadPool threadPool = null; + KestrelThreadPool threadPool = null; switch (serverOptions.ApplicationSchedulingMode) { case SchedulingMode.Default: diff --git a/src/Kestrel.Transport.Abstractions/Internal/TransportConnection.cs b/src/Kestrel.Transport.Abstractions/Internal/TransportConnection.cs index dc1af6ec56..3889bff14f 100644 --- a/src/Kestrel.Transport.Abstractions/Internal/TransportConnection.cs +++ b/src/Kestrel.Transport.Abstractions/Internal/TransportConnection.cs @@ -23,8 +23,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal public string ConnectionId { get; set; } public virtual MemoryPool MemoryPool { get; } - public virtual IScheduler InputWriterScheduler { get; } - public virtual IScheduler OutputReaderScheduler { get; } + public virtual Scheduler InputWriterScheduler { get; } + public virtual Scheduler OutputReaderScheduler { get; } public IPipeConnection Transport { get; set; } public IPipeConnection Application { get; set; } diff --git a/src/Kestrel.Transport.Libuv/Internal/LibuvConnection.cs b/src/Kestrel.Transport.Libuv/Internal/LibuvConnection.cs index 60b7849e26..35cbdf0771 100644 --- a/src/Kestrel.Transport.Libuv/Internal/LibuvConnection.cs +++ b/src/Kestrel.Transport.Libuv/Internal/LibuvConnection.cs @@ -6,6 +6,7 @@ using System.Buffers; using System.Diagnostics; using System.IO; using System.IO.Pipelines; +using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Protocols; using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; @@ -183,7 +184,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal _bufferHandle.Dispose(); } - private async Task ApplyBackpressureAsync(WritableBufferAwaitable flushTask) + private async Task ApplyBackpressureAsync(ValueAwaiter flushTask) { Log.ConnectionPause(ConnectionId); _socket.ReadStop(); diff --git a/src/Kestrel.Transport.Libuv/Internal/LibuvConnectionContext.cs b/src/Kestrel.Transport.Libuv/Internal/LibuvConnectionContext.cs index dde6aa5f30..be2ca1d255 100644 --- a/src/Kestrel.Transport.Libuv/Internal/LibuvConnectionContext.cs +++ b/src/Kestrel.Transport.Libuv/Internal/LibuvConnectionContext.cs @@ -19,7 +19,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal public ListenerContext ListenerContext { get; set; } public override MemoryPool MemoryPool => ListenerContext.Thread.MemoryPool; - public override IScheduler InputWriterScheduler => ListenerContext.Thread; - public override IScheduler OutputReaderScheduler => ListenerContext.Thread; + public override Scheduler InputWriterScheduler => ListenerContext.Thread; + public override Scheduler OutputReaderScheduler => ListenerContext.Thread; } } diff --git a/src/Kestrel.Transport.Libuv/Internal/LibuvThread.cs b/src/Kestrel.Transport.Libuv/Internal/LibuvThread.cs index ca9edc7445..ba4396fe32 100644 --- a/src/Kestrel.Transport.Libuv/Internal/LibuvThread.cs +++ b/src/Kestrel.Transport.Libuv/Internal/LibuvThread.cs @@ -15,7 +15,7 @@ using Microsoft.Extensions.Logging; namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal { - public class LibuvThread : IScheduler + public class LibuvThread : Scheduler { // maximum times the work queues swapped and are processed in a single pass // as completing a task may immediately have write data to put on the network @@ -390,7 +390,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal return await Task.WhenAny(task, Task.Delay(timeout)).ConfigureAwait(false) == task; } - public void Schedule(Action action, object state) + public override void Schedule(Action action) + { + Post(state => state(), action); + } + + public override void Schedule(Action action, object state) { Post(action, state); } diff --git a/src/Kestrel.Transport.Libuv/Internal/Networking/UvWriteReq.cs b/src/Kestrel.Transport.Libuv/Internal/Networking/UvWriteReq.cs index 9eac9c1a39..c25f2aec28 100644 --- a/src/Kestrel.Transport.Libuv/Internal/Networking/UvWriteReq.cs +++ b/src/Kestrel.Transport.Libuv/Internal/Networking/UvWriteReq.cs @@ -49,7 +49,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networkin _bufs = handle + requestSize; } - public LibuvAwaitable WriteAsync(UvStreamHandle handle, ReadableBuffer buffer) + public LibuvAwaitable WriteAsync(UvStreamHandle handle, ReadOnlyBuffer buffer) { Write(handle, buffer, LibuvAwaitable.Callback, _awaitable); return _awaitable; @@ -63,7 +63,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networkin private unsafe void Write( UvStreamHandle handle, - ReadableBuffer buffer, + ReadOnlyBuffer buffer, Action callback, object state) { diff --git a/src/Kestrel.Transport.Sockets/Internal/BufferExtensions.cs b/src/Kestrel.Transport.Sockets/Internal/BufferExtensions.cs index 8edfb997b2..7340736bd8 100644 --- a/src/Kestrel.Transport.Sockets/Internal/BufferExtensions.cs +++ b/src/Kestrel.Transport.Sockets/Internal/BufferExtensions.cs @@ -2,15 +2,24 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Runtime.InteropServices; namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal { public static class BufferExtensions { - public static ArraySegment GetArray(this Memory buffer) + public static ArraySegment GetArray(this Memory memory) { - ArraySegment result; - if (!buffer.TryGetArray(out result)) + if (!memory.TryGetArray(out var result)) + { + throw new InvalidOperationException("Buffer backed by array was expected"); + } + return result; + } + + public static ArraySegment GetArray(this ReadOnlyMemory memory) + { + if (!MemoryMarshal.TryGetArray(memory, out var result)) { throw new InvalidOperationException("Buffer backed by array was expected"); } diff --git a/src/Kestrel.Transport.Sockets/Internal/SocketConnection.cs b/src/Kestrel.Transport.Sockets/Internal/SocketConnection.cs index d74159792e..ff7c678cd7 100644 --- a/src/Kestrel.Transport.Sockets/Internal/SocketConnection.cs +++ b/src/Kestrel.Transport.Sockets/Internal/SocketConnection.cs @@ -52,8 +52,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal } public override MemoryPool MemoryPool { get; } - public override IScheduler InputWriterScheduler => InlineScheduler.Default; - public override IScheduler OutputReaderScheduler => TaskRunScheduler.Default; + public override Scheduler InputWriterScheduler => Scheduler.Inline; + public override Scheduler OutputReaderScheduler => Scheduler.TaskRun; public async Task StartAsync(IConnectionHandler connectionHandler) { diff --git a/src/Kestrel.Transport.Sockets/Internal/SocketSender.cs b/src/Kestrel.Transport.Sockets/Internal/SocketSender.cs index f871dc7021..8f5197f2ad 100644 --- a/src/Kestrel.Transport.Sockets/Internal/SocketSender.cs +++ b/src/Kestrel.Transport.Sockets/Internal/SocketSender.cs @@ -2,10 +2,12 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Buffers; using System.Collections.Generic; using System.Diagnostics; using System.IO.Pipelines; using System.Net.Sockets; +using System.Runtime.InteropServices; namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal { @@ -24,7 +26,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal _eventArgs.Completed += (_, e) => ((SocketAwaitable)e.UserToken).Complete(e.BytesTransferred, e.SocketError); } - public SocketAwaitable SendAsync(ReadableBuffer buffers) + public SocketAwaitable SendAsync(ReadOnlyBuffer buffers) { if (buffers.IsSingleSpan) { @@ -50,7 +52,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal return _awaitable; } - private SocketAwaitable SendAsync(Memory buffer) + private SocketAwaitable SendAsync(ReadOnlyMemory memory) { // The BufferList getter is much less expensive then the setter. if (_eventArgs.BufferList != null) @@ -59,9 +61,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal } #if NETCOREAPP2_1 - _eventArgs.SetBuffer(buffer); + _eventArgs.SetBuffer(MemoryMarshal.AsMemory(memory)); #else - var segment = buffer.GetArray(); + var segment = memory.GetArray(); _eventArgs.SetBuffer(segment.Array, segment.Offset, segment.Count); #endif @@ -73,7 +75,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal return _awaitable; } - private List> GetBufferList(ReadableBuffer buffer) + private List> GetBufferList(ReadOnlyBuffer buffer) { Debug.Assert(!buffer.IsEmpty); Debug.Assert(!buffer.IsSingleSpan); diff --git a/src/Protocols.Abstractions/Features/IConnectionTransportFeature.cs b/src/Protocols.Abstractions/Features/IConnectionTransportFeature.cs index 9a090437e8..2d7f3b5746 100644 --- a/src/Protocols.Abstractions/Features/IConnectionTransportFeature.cs +++ b/src/Protocols.Abstractions/Features/IConnectionTransportFeature.cs @@ -12,8 +12,8 @@ namespace Microsoft.AspNetCore.Protocols.Features IPipeConnection Application { get; set; } - IScheduler InputWriterScheduler { get; } + Scheduler InputWriterScheduler { get; } - IScheduler OutputReaderScheduler { get; } + Scheduler OutputReaderScheduler { get; } } } diff --git a/test/Kestrel.Core.Tests/ConnectionHandlerTests.cs b/test/Kestrel.Core.Tests/ConnectionHandlerTests.cs index 5c7afd17f0..42264410db 100644 --- a/test/Kestrel.Core.Tests/ConnectionHandlerTests.cs +++ b/test/Kestrel.Core.Tests/ConnectionHandlerTests.cs @@ -58,9 +58,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests public IPipeConnection Transport { get; set; } public IPipeConnection Application { get; set; } - public IScheduler InputWriterScheduler => TaskRunScheduler.Default; + public Scheduler InputWriterScheduler => Scheduler.TaskRun; - public IScheduler OutputReaderScheduler => TaskRunScheduler.Default; + public Scheduler OutputReaderScheduler => Scheduler.TaskRun; public string ConnectionId { get; set; } } diff --git a/test/Kestrel.Core.Tests/Http1ConnectionTests.cs b/test/Kestrel.Core.Tests/Http1ConnectionTests.cs index 934bd31257..3c1eba171b 100644 --- a/test/Kestrel.Core.Tests/Http1ConnectionTests.cs +++ b/test/Kestrel.Core.Tests/Http1ConnectionTests.cs @@ -5,6 +5,7 @@ using System; using System.Buffers; using System.Collections; using System.Collections.Generic; +using System.Collections.Sequences; using System.IO; using System.IO.Pipelines; using System.Linq; @@ -33,8 +34,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests private readonly ServiceContext _serviceContext; private readonly Http1ConnectionContext _http1ConnectionContext; private readonly MemoryPool _pipelineFactory; - private ReadCursor _consumed; - private ReadCursor _examined; + private Position _consumed; + private Position _examined; private Mock _timeoutControl; public Http1ConnectionTests() diff --git a/test/Kestrel.Core.Tests/HttpParserTests.cs b/test/Kestrel.Core.Tests/HttpParserTests.cs index 17647743e5..2a1d3dd142 100644 --- a/test/Kestrel.Core.Tests/HttpParserTests.cs +++ b/test/Kestrel.Core.Tests/HttpParserTests.cs @@ -2,8 +2,8 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Buffers; using System.IO.Pipelines; -using System.IO.Pipelines.Testing; using System.Collections.Generic; using System.Linq; using System.Text; @@ -35,7 +35,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests string expectedVersion) { var parser = CreateParser(Mock.Of()); - var buffer = ReadableBuffer.Create(Encoding.ASCII.GetBytes(requestLine)); + var buffer = new ReadOnlyBuffer(Encoding.ASCII.GetBytes(requestLine)); var requestHandler = new RequestHandler(); Assert.True(parser.ParseRequestLine(requestHandler, buffer, out var consumed, out var examined)); @@ -54,7 +54,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests public void ParseRequestLineReturnsFalseWhenGivenIncompleteRequestLines(string requestLine) { var parser = CreateParser(Mock.Of()); - var buffer = ReadableBuffer.Create(Encoding.ASCII.GetBytes(requestLine)); + var buffer = new ReadOnlyBuffer(Encoding.ASCII.GetBytes(requestLine)); var requestHandler = new RequestHandler(); Assert.False(parser.ParseRequestLine(requestHandler, buffer, out var consumed, out var examined)); @@ -65,7 +65,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests public void ParseRequestLineDoesNotConsumeIncompleteRequestLine(string requestLine) { var parser = CreateParser(Mock.Of()); - var buffer = ReadableBuffer.Create(Encoding.ASCII.GetBytes(requestLine)); + var buffer = new ReadOnlyBuffer(Encoding.ASCII.GetBytes(requestLine)); var requestHandler = new RequestHandler(); Assert.False(parser.ParseRequestLine(requestHandler, buffer, out var consumed, out var examined)); @@ -84,7 +84,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests .Returns(true); var parser = CreateParser(mockTrace.Object); - var buffer = ReadableBuffer.Create(Encoding.ASCII.GetBytes(requestLine)); + var buffer = new ReadOnlyBuffer(Encoding.ASCII.GetBytes(requestLine)); var requestHandler = new RequestHandler(); var exception = Assert.Throws(() => @@ -106,7 +106,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests .Returns(true); var parser = CreateParser(mockTrace.Object); - var buffer = ReadableBuffer.Create(Encoding.ASCII.GetBytes(requestLine)); + var buffer = new ReadOnlyBuffer(Encoding.ASCII.GetBytes(requestLine)); var requestHandler = new RequestHandler(); var exception = Assert.Throws(() => @@ -128,7 +128,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests .Returns(true); var parser = CreateParser(mockTrace.Object); - var buffer = ReadableBuffer.Create(Encoding.ASCII.GetBytes(requestLine)); + var buffer = new ReadOnlyBuffer(Encoding.ASCII.GetBytes(requestLine)); var requestHandler = new RequestHandler(); var exception = Assert.Throws(() => @@ -179,7 +179,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests { var parser = CreateParser(Mock.Of()); - var buffer = ReadableBuffer.Create(Encoding.ASCII.GetBytes(rawHeaders)); + var buffer = new ReadOnlyBuffer(Encoding.ASCII.GetBytes(rawHeaders)); var requestHandler = new RequestHandler(); Assert.False(parser.ParseHeaders(requestHandler, buffer, out var consumed, out var examined, out var consumedBytes)); } @@ -204,7 +204,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests { var parser = CreateParser(Mock.Of()); - var buffer = ReadableBuffer.Create(Encoding.ASCII.GetBytes(rawHeaders)); + var buffer = new ReadOnlyBuffer(Encoding.ASCII.GetBytes(rawHeaders)); var requestHandler = new RequestHandler(); parser.ParseHeaders(requestHandler, buffer, out var consumed, out var examined, out var consumedBytes); @@ -294,7 +294,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests var parser = CreateParser(Mock.Of()); const string headerLine = "Header: value\r\n\r"; - var buffer1 = ReadableBuffer.Create(Encoding.ASCII.GetBytes(headerLine)); + var buffer1 = new ReadOnlyBuffer(Encoding.ASCII.GetBytes(headerLine)); var requestHandler = new RequestHandler(); Assert.False(parser.ParseHeaders(requestHandler, buffer1, out var consumed, out var examined, out var consumedBytes)); @@ -302,7 +302,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests Assert.Equal(buffer1.End, examined); Assert.Equal(headerLine.Length - 1, consumedBytes); - var buffer2 = ReadableBuffer.Create(Encoding.ASCII.GetBytes("\r\n")); + var buffer2 = new ReadOnlyBuffer(Encoding.ASCII.GetBytes("\r\n")); Assert.True(parser.ParseHeaders(requestHandler, buffer2, out consumed, out examined, out consumedBytes)); Assert.Equal(buffer2.End, consumed); @@ -320,7 +320,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests .Returns(true); var parser = CreateParser(mockTrace.Object); - var buffer = ReadableBuffer.Create(Encoding.ASCII.GetBytes(rawHeaders)); + var buffer = new ReadOnlyBuffer(Encoding.ASCII.GetBytes(rawHeaders)); var requestHandler = new RequestHandler(); var exception = Assert.Throws(() => @@ -341,7 +341,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests var parser = CreateParser(mockTrace.Object); // Invalid request line - var buffer = ReadableBuffer.Create(Encoding.ASCII.GetBytes("GET % HTTP/1.1\r\n")); + var buffer = new ReadOnlyBuffer(Encoding.ASCII.GetBytes("GET % HTTP/1.1\r\n")); var requestHandler = new RequestHandler(); var exception = Assert.Throws(() => @@ -351,7 +351,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests Assert.Equal(StatusCodes.Status400BadRequest, (exception as BadHttpRequestException).StatusCode); // Unrecognized HTTP version - buffer = ReadableBuffer.Create(Encoding.ASCII.GetBytes("GET / HTTP/1.2\r\n")); + buffer = new ReadOnlyBuffer(Encoding.ASCII.GetBytes("GET / HTTP/1.2\r\n")); exception = Assert.Throws(() => parser.ParseRequestLine(requestHandler, buffer, out var consumed, out var examined)); @@ -360,7 +360,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests Assert.Equal(StatusCodes.Status505HttpVersionNotsupported, (exception as BadHttpRequestException).StatusCode); // Invalid request header - buffer = ReadableBuffer.Create(Encoding.ASCII.GetBytes("Header: value\n\r\n")); + buffer = new ReadOnlyBuffer(Encoding.ASCII.GetBytes("Header: value\n\r\n")); exception = Assert.Throws(() => parser.ParseHeaders(requestHandler, buffer, out var consumed, out var examined, out var consumedBytes)); @@ -369,27 +369,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests Assert.Equal(StatusCodes.Status400BadRequest, exception.StatusCode); } - [Fact] - public void ParseRequestLineSplitBufferWithoutNewLineDoesNotUpdateConsumed() - { - var parser = CreateParser(Mock.Of()); - var buffer = BufferUtilities.CreateBuffer("GET ", "/"); - - var requestHandler = new RequestHandler(); - var result = parser.ParseRequestLine(requestHandler, buffer, out var consumed, out var examined); - - Assert.False(result); - Assert.Equal(buffer.Start, consumed); - Assert.Equal(buffer.End, examined); - } - private void VerifyHeader( string headerName, string rawHeaderValue, string expectedHeaderValue) { var parser = CreateParser(Mock.Of()); - var buffer = ReadableBuffer.Create(Encoding.ASCII.GetBytes($"{headerName}:{rawHeaderValue}\r\n")); + var buffer = new ReadOnlyBuffer(Encoding.ASCII.GetBytes($"{headerName}:{rawHeaderValue}\r\n")); var requestHandler = new RequestHandler(); parser.ParseHeaders(requestHandler, buffer, out var consumed, out var examined, out var consumedBytes); @@ -407,7 +393,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests Assert.True(expectedHeaderNames.Count() == expectedHeaderValues.Count(), $"{nameof(expectedHeaderNames)} and {nameof(expectedHeaderValues)} sizes must match"); var parser = CreateParser(Mock.Of()); - var buffer = ReadableBuffer.Create(Encoding.ASCII.GetBytes(rawHeaders)); + var buffer = new ReadOnlyBuffer(Encoding.ASCII.GetBytes(rawHeaders)); var requestHandler = new RequestHandler(); parser.ParseHeaders(requestHandler, buffer, out var consumed, out var examined, out var consumedBytes); diff --git a/test/Kestrel.Core.Tests/OutputProducerTests.cs b/test/Kestrel.Core.Tests/OutputProducerTests.cs index 77e21810f3..71a4b7712b 100644 --- a/test/Kestrel.Core.Tests/OutputProducerTests.cs +++ b/test/Kestrel.Core.Tests/OutputProducerTests.cs @@ -33,7 +33,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests var pipeOptions = new PipeOptions ( pool: _memoryPool, - readerScheduler: Mock.Of() + readerScheduler: Mock.Of() ); using (var socketOutput = CreateOutputProducer(pipeOptions)) diff --git a/test/Kestrel.Core.Tests/PipeOptionsTests.cs b/test/Kestrel.Core.Tests/PipeOptionsTests.cs index 19ac6a1592..397fbdbbc8 100644 --- a/test/Kestrel.Core.Tests/PipeOptionsTests.cs +++ b/test/Kestrel.Core.Tests/PipeOptionsTests.cs @@ -26,7 +26,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests serviceContext.ServerOptions.Limits.MaxResponseBufferSize = maxResponseBufferSize; serviceContext.ThreadPool = new LoggingThreadPool(null); - var mockScheduler = Mock.Of(); + var mockScheduler = Mock.Of(); var outputPipeOptions = ConnectionHandler.GetOutputPipeOptions(serviceContext, new MemoryPool(), readerScheduler: mockScheduler); Assert.Equal(expectedMaximumSizeLow, outputPipeOptions.MaximumSizeLow); @@ -44,7 +44,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests serviceContext.ServerOptions.Limits.MaxRequestBufferSize = maxRequestBufferSize; serviceContext.ThreadPool = new LoggingThreadPool(null); - var mockScheduler = Mock.Of(); + var mockScheduler = Mock.Of(); var inputPipeOptions = ConnectionHandler.GetInputPipeOptions(serviceContext, new MemoryPool(), writerScheduler: mockScheduler); Assert.Equal(expectedMaximumSizeLow, inputPipeOptions.MaximumSizeLow); @@ -69,7 +69,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests Assert.Equal(expectedMaximumSizeLow, connectionLifetime.AdaptedInputPipeOptions.MaximumSizeLow); Assert.Equal(expectedMaximumSizeHigh, connectionLifetime.AdaptedInputPipeOptions.MaximumSizeHigh); Assert.Same(serviceContext.ThreadPool, connectionLifetime.AdaptedInputPipeOptions.ReaderScheduler); - Assert.Same(InlineScheduler.Default, connectionLifetime.AdaptedInputPipeOptions.WriterScheduler); + Assert.Same(Scheduler.Inline, connectionLifetime.AdaptedInputPipeOptions.WriterScheduler); } [Theory] @@ -87,8 +87,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests Assert.Equal(expectedMaximumSizeLow, connectionLifetime.AdaptedOutputPipeOptions.MaximumSizeLow); Assert.Equal(expectedMaximumSizeHigh, connectionLifetime.AdaptedOutputPipeOptions.MaximumSizeHigh); - Assert.Same(InlineScheduler.Default, connectionLifetime.AdaptedOutputPipeOptions.ReaderScheduler); - Assert.Same(InlineScheduler.Default, connectionLifetime.AdaptedOutputPipeOptions.WriterScheduler); + Assert.Same(Scheduler.Inline, connectionLifetime.AdaptedOutputPipeOptions.ReaderScheduler); + Assert.Same(Scheduler.Inline, connectionLifetime.AdaptedOutputPipeOptions.WriterScheduler); } } } diff --git a/test/Kestrel.Transport.Libuv.Tests/LibuvConnectionTests.cs b/test/Kestrel.Transport.Libuv.Tests/LibuvConnectionTests.cs index f6df1515e3..4c79bddf19 100644 --- a/test/Kestrel.Transport.Libuv.Tests/LibuvConnectionTests.cs +++ b/test/Kestrel.Transport.Libuv.Tests/LibuvConnectionTests.cs @@ -117,11 +117,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests var transportContext = new TestLibuvTransportContext() { ConnectionHandler = mockConnectionHandler }; var transport = new LibuvTransport(mockLibuv, transportContext, null); var thread = new LibuvThread(transport); - var mockScheduler = new Mock(); + var mockScheduler = new Mock(); Action backPressure = null; - mockScheduler.Setup(m => m.Schedule(It.IsAny>(), It.IsAny())).Callback, object>((a, o) => + mockScheduler.Setup(m => m.Schedule(It.IsAny())).Callback(a => { - backPressure = () => a(o); + backPressure = a; }); mockConnectionHandler.InputOptions = pool => new PipeOptions( diff --git a/test/Kestrel.Transport.Libuv.Tests/MultipleLoopTests.cs b/test/Kestrel.Transport.Libuv.Tests/MultipleLoopTests.cs index c079e405cc..001b4343e1 100644 --- a/test/Kestrel.Transport.Libuv.Tests/MultipleLoopTests.cs +++ b/test/Kestrel.Transport.Libuv.Tests/MultipleLoopTests.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Buffers; using System.IO.Pipelines; using System.Net; using System.Net.Sockets; @@ -68,7 +69,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests await writeRequest.WriteAsync( serverConnectionPipe, - ReadableBuffer.Create(new byte[] { 1, 2, 3, 4 })); + new ReadOnlyBuffer(new byte[] { 1, 2, 3, 4 })); writeRequest.Dispose(); serverConnectionPipe.Dispose(); diff --git a/test/Kestrel.Transport.Libuv.Tests/NetworkingTests.cs b/test/Kestrel.Transport.Libuv.Tests/NetworkingTests.cs index 0378022eed..dfe9681a0b 100644 --- a/test/Kestrel.Transport.Libuv.Tests/NetworkingTests.cs +++ b/test/Kestrel.Transport.Libuv.Tests/NetworkingTests.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Buffers; using System.Net; using System.Net.Sockets; using System.Runtime.InteropServices; @@ -161,7 +162,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests { var req = new UvWriteReq(_logger); req.DangerousInit(loop); - var block = ReadableBuffer.Create(new byte[] { 65, 66, 67, 68, 69 }); + var block = new ReadOnlyBuffer(new byte[] { 65, 66, 67, 68, 69 }); await req.WriteAsync( tcp2, From 2d3a01d48d4a1a664c2214f33d2c41f38372eba4 Mon Sep 17 00:00:00 2001 From: "Chris Ross (ASP.NET)" Date: Fri, 29 Dec 2017 12:33:34 -0800 Subject: [PATCH 1489/1662] Change ApplicationProtocol to ReadOnlyMemory #2182 --- samples/Http2SampleApp/Http2SampleApp.csproj | 4 +++- samples/Http2SampleApp/testCert.pfx | Bin 0 -> 2483 bytes .../Features/ITlsApplicationProtocolFeature.cs | 5 +++-- src/Kestrel.Core/Internal/HttpConnection.cs | 9 ++++++--- .../Internal/HttpsConnectionAdapter.cs | 15 +-------------- .../Internal/TlsConnectionFeature.cs | 2 +- src/Kestrel.Core/Kestrel.Core.csproj | 2 +- 7 files changed, 15 insertions(+), 22 deletions(-) create mode 100644 samples/Http2SampleApp/testCert.pfx diff --git a/samples/Http2SampleApp/Http2SampleApp.csproj b/samples/Http2SampleApp/Http2SampleApp.csproj index 683e6e4041..cd660a6c80 100644 --- a/samples/Http2SampleApp/Http2SampleApp.csproj +++ b/samples/Http2SampleApp/Http2SampleApp.csproj @@ -15,7 +15,9 @@ - + + PreserveNewest + diff --git a/samples/Http2SampleApp/testCert.pfx b/samples/Http2SampleApp/testCert.pfx new file mode 100644 index 0000000000000000000000000000000000000000..7118908c2d730670c16e9f8b2c532a262c951989 GIT binary patch literal 2483 zcmaKuc|27A8pqF>IWr86E&Q@(n=B)p$ug!;QVB6xij*z;uPLG!yCz#DQB)+9G$9m9 zQU)=DWXU?*EZIwG!+0d++P@yZ4Xhoagg?p6B~|Ue7tN=Ny=UD?x#1n1MTq z#c9MHh+D#gd|(a(cN}8i91v^=GcdgW3SmA$49p~gM-dys3jVWdg8+!iVL)pz1LDE5 zSb=|GAn(@R=(Ux!MfS9@}sFu-xDd zIt2+mqSq$glwy_6UNs<2?(qERU!gJ;5j}Pp&6trxG=wi)=@k(w2+fJVnc+qvXVzy(>Om4;L|^)R`t*3nTpAmEmTl(#i!RV#a0t#u6>Q9mY`-Nmcs7$XjXT7 zUmCD`O~_j7!%R#I?cG-7C^hcH)@l?WC1vyw$FFu_(r)jhOq6p}W8sG7NO{YTy8tG4 zrb$tTkag*G?(7lfoGx$4YWui>{{@}-FB2ub=}RX{1zx?j)s-##J9|G7E1@-;7Nuln z9MQoX7FJ76+D#XXT@ZZmLZCufIdf3@OigG6m8I7!GT=7VD|>?6e!z9=eT}*E_tSn6 zl+clHCZ-kcIR#gen#LjMJW8>0QtViaQB#FhqsCb0YPYr3;jRITl@V9Aph24D?r2d` zetCyyCg<*O-u+M& zW^ptmT|}p$VAOZpmbQ1{5fK-6ytEvre#Po}6c2URn`viQAF2+e?Z~PK2&pd>7=7)I zTCYm)@3PFRu_6a6Kb)IpCzQ%e3l%O#SDA+$Pq{Dk{HC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A*xkn(1IS~nfP}k}e?4Bt|9g(eph4hFX_|S6nj1&Sz9z^= zRw~<&-9d@FzTn6S*RVE{Wj5lgLJr9HLB8S9CgOm*>XA8*y4`JE;^s$=bqD#U4;e5C&x&ggKIAVL zrQ)Yd8|{>7Z(6*B&7&4&9(*vDOfHMuR-Dk1IZia*XM^EZUD^{?cWG>J>KrtElc*{K zaVl(7SN2cH4I6Q$bZOpJ8e5LKaG7p;?tJ~#+9QrTYU@f#5`Vo7cEX!szCT}iX-K^2 w#3o+=C+lQz2J+SOEzVX(eJ)e7=eicC{rr9U2VGDcdH?_b literal 0 HcmV?d00001 diff --git a/src/Kestrel.Core/Features/ITlsApplicationProtocolFeature.cs b/src/Kestrel.Core/Features/ITlsApplicationProtocolFeature.cs index 7ad37730d5..8adca3f0e8 100644 --- a/src/Kestrel.Core/Features/ITlsApplicationProtocolFeature.cs +++ b/src/Kestrel.Core/Features/ITlsApplicationProtocolFeature.cs @@ -1,11 +1,12 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; + namespace Microsoft.AspNetCore.Server.Kestrel.Core.Features { - // TODO: this should be merged with ITlsConnectionFeature public interface ITlsApplicationProtocolFeature { - string ApplicationProtocol { get; } + ReadOnlyMemory ApplicationProtocol { get; } } } diff --git a/src/Kestrel.Core/Internal/HttpConnection.cs b/src/Kestrel.Core/Internal/HttpConnection.cs index 1ac4945ae4..fcd2c314a8 100644 --- a/src/Kestrel.Core/Internal/HttpConnection.cs +++ b/src/Kestrel.Core/Internal/HttpConnection.cs @@ -23,6 +23,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal { public class HttpConnection : ITimeoutControl, IConnectionTimeoutFeature, IRequestProcessor { + private static readonly ReadOnlyMemory Http2Id = new ReadOnlyMemory(new[] { (byte)'h', (byte)'2' }); + private readonly HttpConnectionContext _context; private readonly TaskCompletionSource _socketClosedTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); @@ -303,7 +305,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal private HttpProtocols SelectProtocol() { var hasTls = _context.ConnectionFeatures.Get() != null; - var applicationProtocol = _context.ConnectionFeatures.Get()?.ApplicationProtocol; + var applicationProtocol = _context.ConnectionFeatures.Get()?.ApplicationProtocol + ?? new ReadOnlyMemory(); var http1Enabled = (_context.Protocols & HttpProtocols.Http1) == HttpProtocols.Http1; var http2Enabled = (_context.Protocols & HttpProtocols.Http2) == HttpProtocols.Http2; @@ -319,7 +322,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal error = CoreStrings.EndPointRequiresTlsForHttp1AndHttp2; } - if (!http1Enabled && http2Enabled && hasTls && applicationProtocol != "h2") + if (!http1Enabled && http2Enabled && hasTls && !Http2Id.SequenceEqual(applicationProtocol)) { error = CoreStrings.EndPointHttp2NotNegotiated; } @@ -330,7 +333,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal return HttpProtocols.None; } - return http2Enabled && (!hasTls || applicationProtocol == "h2") ? HttpProtocols.Http2 : HttpProtocols.Http1; + return http2Enabled && (!hasTls || Http2Id.SequenceEqual(applicationProtocol)) ? HttpProtocols.Http2 : HttpProtocols.Http1; } public void Tick(DateTimeOffset now) diff --git a/src/Kestrel.Core/Internal/HttpsConnectionAdapter.cs b/src/Kestrel.Core/Internal/HttpsConnectionAdapter.cs index cae7d60b2f..5022462886 100644 --- a/src/Kestrel.Core/Internal/HttpsConnectionAdapter.cs +++ b/src/Kestrel.Core/Internal/HttpsConnectionAdapter.cs @@ -160,20 +160,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Https.Internal } #if NETCOREAPP2_1 - // Don't allocate in the common case, see https://github.com/dotnet/corefx/issues/25432 - if (sslStream.NegotiatedApplicationProtocol == SslApplicationProtocol.Http11) - { - feature.ApplicationProtocol = "http/1.1"; - } - else if (sslStream.NegotiatedApplicationProtocol == SslApplicationProtocol.Http2) - { - feature.ApplicationProtocol = "h2"; - } - else - { - feature.ApplicationProtocol = sslStream.NegotiatedApplicationProtocol.ToString(); - } - + feature.ApplicationProtocol = sslStream.NegotiatedApplicationProtocol.Protocol; context.Features.Set(feature); #endif feature.ClientCertificate = ConvertToX509Certificate2(sslStream.RemoteCertificate); diff --git a/src/Kestrel.Core/Internal/TlsConnectionFeature.cs b/src/Kestrel.Core/Internal/TlsConnectionFeature.cs index d5d7983d8e..a914024131 100644 --- a/src/Kestrel.Core/Internal/TlsConnectionFeature.cs +++ b/src/Kestrel.Core/Internal/TlsConnectionFeature.cs @@ -14,7 +14,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Https.Internal { public X509Certificate2 ClientCertificate { get; set; } - public string ApplicationProtocol { get; set; } + public ReadOnlyMemory ApplicationProtocol { get; set; } public Task GetClientCertificateAsync(CancellationToken cancellationToken) { diff --git a/src/Kestrel.Core/Kestrel.Core.csproj b/src/Kestrel.Core/Kestrel.Core.csproj index 2f6ea2a3bb..59b66b7373 100644 --- a/src/Kestrel.Core/Kestrel.Core.csproj +++ b/src/Kestrel.Core/Kestrel.Core.csproj @@ -4,7 +4,7 @@ Microsoft.AspNetCore.Server.Kestrel.Core Microsoft.AspNetCore.Server.Kestrel.Core Core components of ASP.NET Core Kestrel cross-platform web server. - netstandard2.0 + netstandard2.0;netcoreapp2.1 true aspnetcore;kestrel true From bd3195ff43188bab0b91ab590f74d06513036996 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Thu, 4 Jan 2018 15:58:19 -0800 Subject: [PATCH 1490/1662] Fix dependencies.props --- build/dependencies.props | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/dependencies.props b/build/dependencies.props index e0c9c9a59b..6d0c133d98 100644 --- a/build/dependencies.props +++ b/build/dependencies.props @@ -39,7 +39,7 @@ 4.5.0-preview1-26102-01 4.5.0-preview1-26102-01 0.1.0-e180104-2 - 4.5.0-preview1-26102-01 + 4.5.0-preview2-25707-02 0.8.0 2.3.1 2.3.1 From 664055fa4396b72e6914bb1b0f9b98c0030e83ea Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Thu, 4 Jan 2018 16:17:36 -0800 Subject: [PATCH 1491/1662] Revert "Change ApplicationProtocol to ReadOnlyMemory #2182" This reverts commit 2d3a01d48d4a1a664c2214f33d2c41f38372eba4. --- samples/Http2SampleApp/Http2SampleApp.csproj | 4 +--- samples/Http2SampleApp/testCert.pfx | Bin 2483 -> 0 bytes .../Features/ITlsApplicationProtocolFeature.cs | 5 ++--- src/Kestrel.Core/Internal/HttpConnection.cs | 9 +++------ .../Internal/HttpsConnectionAdapter.cs | 15 ++++++++++++++- .../Internal/TlsConnectionFeature.cs | 2 +- src/Kestrel.Core/Kestrel.Core.csproj | 2 +- 7 files changed, 22 insertions(+), 15 deletions(-) delete mode 100644 samples/Http2SampleApp/testCert.pfx diff --git a/samples/Http2SampleApp/Http2SampleApp.csproj b/samples/Http2SampleApp/Http2SampleApp.csproj index cd660a6c80..683e6e4041 100644 --- a/samples/Http2SampleApp/Http2SampleApp.csproj +++ b/samples/Http2SampleApp/Http2SampleApp.csproj @@ -15,9 +15,7 @@ - - PreserveNewest - + diff --git a/samples/Http2SampleApp/testCert.pfx b/samples/Http2SampleApp/testCert.pfx deleted file mode 100644 index 7118908c2d730670c16e9f8b2c532a262c951989..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2483 zcmaKuc|27A8pqF>IWr86E&Q@(n=B)p$ug!;QVB6xij*z;uPLG!yCz#DQB)+9G$9m9 zQU)=DWXU?*EZIwG!+0d++P@yZ4Xhoagg?p6B~|Ue7tN=Ny=UD?x#1n1MTq z#c9MHh+D#gd|(a(cN}8i91v^=GcdgW3SmA$49p~gM-dys3jVWdg8+!iVL)pz1LDE5 zSb=|GAn(@R=(Ux!MfS9@}sFu-xDd zIt2+mqSq$glwy_6UNs<2?(qERU!gJ;5j}Pp&6trxG=wi)=@k(w2+fJVnc+qvXVzy(>Om4;L|^)R`t*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oe1763EQHorRm`C&ktKn(OQ1n)$Q{GZz&jRb`eDEMpl<0O#+)DMV(T7nsIzCG{QuM->B9g7Lrl2SE&gW`M!~(un|y0fIn=b^6_$ z9{zEzgYI~39xn0ZP*9qBL%fg7rg$ttt&TOmvfNNO<6FT0ZavM$Y4CYLQGIcIYv9Y& zBGPUh&QTfW;V2!)oIra@s&d968y-y}Y|ww(R$GzWS*V&)k@W0>Slem{|HdTCjm;_5 zwY*A8W3nUbemE^_f0ng$tbd<`sr?TO-_&VCw+F#7P@LkIl$1PzTBoPY1b88EIO>UO zP-NK7+g2yD3U6g3i|iA6+su>54sf_Sk0F=)1|9odnCM4u2Rs z=&Y?-V&VquSN%3FJ2~ZGweP~iLs|w=l@9yu$tj@}Dp?e-2JUsqOoswdXb=E%&0te_ zA2M+{5Hf-dqD7=yw*r@A*xkn(1IS~nfP}k}e?4Bt|9g(eph4hFX_|S6nj1&Sz9z^= zRw~<&-9d@FzTn6S*RVE{Wj5lgLJr9HLB8S9CgOm*>XA8*y4`JE;^s$=bqD#U4;e5C&x&ggKIAVL zrQ)Yd8|{>7Z(6*B&7&4&9(*vDOfHMuR-Dk1IZia*XM^EZUD^{?cWG>J>KrtElc*{K zaVl(7SN2cH4I6Q$bZOpJ8e5LKaG7p;?tJ~#+9QrTYU@f#5`Vo7cEX!szCT}iX-K^2 w#3o+=C+lQz2J+SOEzVX(eJ)e7=eicC{rr9U2VGDcdH?_b diff --git a/src/Kestrel.Core/Features/ITlsApplicationProtocolFeature.cs b/src/Kestrel.Core/Features/ITlsApplicationProtocolFeature.cs index 8adca3f0e8..7ad37730d5 100644 --- a/src/Kestrel.Core/Features/ITlsApplicationProtocolFeature.cs +++ b/src/Kestrel.Core/Features/ITlsApplicationProtocolFeature.cs @@ -1,12 +1,11 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System; - namespace Microsoft.AspNetCore.Server.Kestrel.Core.Features { + // TODO: this should be merged with ITlsConnectionFeature public interface ITlsApplicationProtocolFeature { - ReadOnlyMemory ApplicationProtocol { get; } + string ApplicationProtocol { get; } } } diff --git a/src/Kestrel.Core/Internal/HttpConnection.cs b/src/Kestrel.Core/Internal/HttpConnection.cs index fcd2c314a8..1ac4945ae4 100644 --- a/src/Kestrel.Core/Internal/HttpConnection.cs +++ b/src/Kestrel.Core/Internal/HttpConnection.cs @@ -23,8 +23,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal { public class HttpConnection : ITimeoutControl, IConnectionTimeoutFeature, IRequestProcessor { - private static readonly ReadOnlyMemory Http2Id = new ReadOnlyMemory(new[] { (byte)'h', (byte)'2' }); - private readonly HttpConnectionContext _context; private readonly TaskCompletionSource _socketClosedTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); @@ -305,8 +303,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal private HttpProtocols SelectProtocol() { var hasTls = _context.ConnectionFeatures.Get() != null; - var applicationProtocol = _context.ConnectionFeatures.Get()?.ApplicationProtocol - ?? new ReadOnlyMemory(); + var applicationProtocol = _context.ConnectionFeatures.Get()?.ApplicationProtocol; var http1Enabled = (_context.Protocols & HttpProtocols.Http1) == HttpProtocols.Http1; var http2Enabled = (_context.Protocols & HttpProtocols.Http2) == HttpProtocols.Http2; @@ -322,7 +319,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal error = CoreStrings.EndPointRequiresTlsForHttp1AndHttp2; } - if (!http1Enabled && http2Enabled && hasTls && !Http2Id.SequenceEqual(applicationProtocol)) + if (!http1Enabled && http2Enabled && hasTls && applicationProtocol != "h2") { error = CoreStrings.EndPointHttp2NotNegotiated; } @@ -333,7 +330,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal return HttpProtocols.None; } - return http2Enabled && (!hasTls || Http2Id.SequenceEqual(applicationProtocol)) ? HttpProtocols.Http2 : HttpProtocols.Http1; + return http2Enabled && (!hasTls || applicationProtocol == "h2") ? HttpProtocols.Http2 : HttpProtocols.Http1; } public void Tick(DateTimeOffset now) diff --git a/src/Kestrel.Core/Internal/HttpsConnectionAdapter.cs b/src/Kestrel.Core/Internal/HttpsConnectionAdapter.cs index 5022462886..cae7d60b2f 100644 --- a/src/Kestrel.Core/Internal/HttpsConnectionAdapter.cs +++ b/src/Kestrel.Core/Internal/HttpsConnectionAdapter.cs @@ -160,7 +160,20 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Https.Internal } #if NETCOREAPP2_1 - feature.ApplicationProtocol = sslStream.NegotiatedApplicationProtocol.Protocol; + // Don't allocate in the common case, see https://github.com/dotnet/corefx/issues/25432 + if (sslStream.NegotiatedApplicationProtocol == SslApplicationProtocol.Http11) + { + feature.ApplicationProtocol = "http/1.1"; + } + else if (sslStream.NegotiatedApplicationProtocol == SslApplicationProtocol.Http2) + { + feature.ApplicationProtocol = "h2"; + } + else + { + feature.ApplicationProtocol = sslStream.NegotiatedApplicationProtocol.ToString(); + } + context.Features.Set(feature); #endif feature.ClientCertificate = ConvertToX509Certificate2(sslStream.RemoteCertificate); diff --git a/src/Kestrel.Core/Internal/TlsConnectionFeature.cs b/src/Kestrel.Core/Internal/TlsConnectionFeature.cs index a914024131..d5d7983d8e 100644 --- a/src/Kestrel.Core/Internal/TlsConnectionFeature.cs +++ b/src/Kestrel.Core/Internal/TlsConnectionFeature.cs @@ -14,7 +14,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Https.Internal { public X509Certificate2 ClientCertificate { get; set; } - public ReadOnlyMemory ApplicationProtocol { get; set; } + public string ApplicationProtocol { get; set; } public Task GetClientCertificateAsync(CancellationToken cancellationToken) { diff --git a/src/Kestrel.Core/Kestrel.Core.csproj b/src/Kestrel.Core/Kestrel.Core.csproj index 59b66b7373..2f6ea2a3bb 100644 --- a/src/Kestrel.Core/Kestrel.Core.csproj +++ b/src/Kestrel.Core/Kestrel.Core.csproj @@ -4,7 +4,7 @@ Microsoft.AspNetCore.Server.Kestrel.Core Microsoft.AspNetCore.Server.Kestrel.Core Core components of ASP.NET Core Kestrel cross-platform web server. - netstandard2.0;netcoreapp2.1 + netstandard2.0 true aspnetcore;kestrel true From ad2149f5f0453ac4a209882afb56fb766ee58d42 Mon Sep 17 00:00:00 2001 From: "Chris Ross (ASP.NET)" Date: Fri, 29 Dec 2017 12:33:34 -0800 Subject: [PATCH 1492/1662] Change ApplicationProtocol to ReadOnlyMemory #2182 --- samples/Http2SampleApp/Http2SampleApp.csproj | 4 +++- samples/Http2SampleApp/testCert.pfx | Bin 0 -> 2483 bytes .../Features/ITlsApplicationProtocolFeature.cs | 5 +++-- src/Kestrel.Core/Internal/HttpConnection.cs | 9 ++++++--- .../Internal/HttpsConnectionAdapter.cs | 15 +-------------- .../Internal/TlsConnectionFeature.cs | 2 +- src/Kestrel.Core/Kestrel.Core.csproj | 2 +- 7 files changed, 15 insertions(+), 22 deletions(-) create mode 100644 samples/Http2SampleApp/testCert.pfx diff --git a/samples/Http2SampleApp/Http2SampleApp.csproj b/samples/Http2SampleApp/Http2SampleApp.csproj index 683e6e4041..cd660a6c80 100644 --- a/samples/Http2SampleApp/Http2SampleApp.csproj +++ b/samples/Http2SampleApp/Http2SampleApp.csproj @@ -15,7 +15,9 @@ - + + PreserveNewest + diff --git a/samples/Http2SampleApp/testCert.pfx b/samples/Http2SampleApp/testCert.pfx new file mode 100644 index 0000000000000000000000000000000000000000..7118908c2d730670c16e9f8b2c532a262c951989 GIT binary patch literal 2483 zcmaKuc|27A8pqF>IWr86E&Q@(n=B)p$ug!;QVB6xij*z;uPLG!yCz#DQB)+9G$9m9 zQU)=DWXU?*EZIwG!+0d++P@yZ4Xhoagg?p6B~|Ue7tN=Ny=UD?x#1n1MTq z#c9MHh+D#gd|(a(cN}8i91v^=GcdgW3SmA$49p~gM-dys3jVWdg8+!iVL)pz1LDE5 zSb=|GAn(@R=(Ux!MfS9@}sFu-xDd zIt2+mqSq$glwy_6UNs<2?(qERU!gJ;5j}Pp&6tr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-86#`mhrgN5p~<$RLY? zq(kynfFA5{v#p+EA1 z5aoe1763EQHorRm`C&ktKn(OQ1n)$Q{GZz&jRb`eDEMpl<0O#+)DMV(T7nsIzCG{QuM->B9g7Lrl2SE&gW`M!~(un|y0fIn=b^6_$ z9{zEzgYI~39xn0ZP*9qBL%fg7rg$ttt&TOmvfNNO<6FT0ZavM$Y4CYLQGIcIYv9Y& zBGPUh&QTfW;V2!)oIra@s&d968y-y}Y|ww(R$GzWS*V&)k@W0>Slem{|HdTCjm;_5 zwY*A8W3nUbemE^_f0ng$tbd<`sr?TO-_&VCw+F#7P@LkIl$1PzTBoPY1b88EIO>UO zP-NK7+g2yD3U6g3i|iA6+su>54sf_Sk0F=)1|9odnCM4u2Rs z=&Y?-V&VquSN%3FJ2~ZGweP~iLs|w=l@9yu$tj@}Dp?e-2JUsqOoswdXb=E%&0te_ zA2M+{5Hf-dqD7=yw*r@A*xkn(1IS~nfP}k}e?4Bt|9g(eph4hFX_|S6nj1&Sz9z^= zRw~<&-9d@FzTn6S*RVE{Wj5lgLJr9HLB8S9CgOm*>XA8*y4`JE;^s$=bqD#U4;e5C&x&ggKIAVL zrQ)Yd8|{>7Z(6*B&7&4&9(*vDOfHMuR-Dk1IZia*XM^EZUD^{?cWG>J>KrtElc*{K zaVl(7SN2cH4I6Q$bZOpJ8e5LKaG7p;?tJ~#+9QrTYU@f#5`Vo7cEX!szCT}iX-K^2 w#3o+=C+lQz2J+SOEzVX(eJ)e7=eicC{rr9U2VGDcdH?_b literal 0 HcmV?d00001 diff --git a/src/Kestrel.Core/Features/ITlsApplicationProtocolFeature.cs b/src/Kestrel.Core/Features/ITlsApplicationProtocolFeature.cs index 7ad37730d5..8adca3f0e8 100644 --- a/src/Kestrel.Core/Features/ITlsApplicationProtocolFeature.cs +++ b/src/Kestrel.Core/Features/ITlsApplicationProtocolFeature.cs @@ -1,11 +1,12 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; + namespace Microsoft.AspNetCore.Server.Kestrel.Core.Features { - // TODO: this should be merged with ITlsConnectionFeature public interface ITlsApplicationProtocolFeature { - string ApplicationProtocol { get; } + ReadOnlyMemory ApplicationProtocol { get; } } } diff --git a/src/Kestrel.Core/Internal/HttpConnection.cs b/src/Kestrel.Core/Internal/HttpConnection.cs index 1ac4945ae4..2288e99413 100644 --- a/src/Kestrel.Core/Internal/HttpConnection.cs +++ b/src/Kestrel.Core/Internal/HttpConnection.cs @@ -23,6 +23,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal { public class HttpConnection : ITimeoutControl, IConnectionTimeoutFeature, IRequestProcessor { + private static readonly ReadOnlyMemory Http2Id = new[] { (byte)'h', (byte)'2' }; + private readonly HttpConnectionContext _context; private readonly TaskCompletionSource _socketClosedTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); @@ -303,7 +305,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal private HttpProtocols SelectProtocol() { var hasTls = _context.ConnectionFeatures.Get() != null; - var applicationProtocol = _context.ConnectionFeatures.Get()?.ApplicationProtocol; + var applicationProtocol = _context.ConnectionFeatures.Get()?.ApplicationProtocol + ?? new ReadOnlyMemory(); var http1Enabled = (_context.Protocols & HttpProtocols.Http1) == HttpProtocols.Http1; var http2Enabled = (_context.Protocols & HttpProtocols.Http2) == HttpProtocols.Http2; @@ -319,7 +322,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal error = CoreStrings.EndPointRequiresTlsForHttp1AndHttp2; } - if (!http1Enabled && http2Enabled && hasTls && applicationProtocol != "h2") + if (!http1Enabled && http2Enabled && hasTls && !Http2Id.Span.SequenceEqual(applicationProtocol.Span)) { error = CoreStrings.EndPointHttp2NotNegotiated; } @@ -330,7 +333,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal return HttpProtocols.None; } - return http2Enabled && (!hasTls || applicationProtocol == "h2") ? HttpProtocols.Http2 : HttpProtocols.Http1; + return http2Enabled && (!hasTls || Http2Id.Span.SequenceEqual(applicationProtocol.Span)) ? HttpProtocols.Http2 : HttpProtocols.Http1; } public void Tick(DateTimeOffset now) diff --git a/src/Kestrel.Core/Internal/HttpsConnectionAdapter.cs b/src/Kestrel.Core/Internal/HttpsConnectionAdapter.cs index cae7d60b2f..5022462886 100644 --- a/src/Kestrel.Core/Internal/HttpsConnectionAdapter.cs +++ b/src/Kestrel.Core/Internal/HttpsConnectionAdapter.cs @@ -160,20 +160,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Https.Internal } #if NETCOREAPP2_1 - // Don't allocate in the common case, see https://github.com/dotnet/corefx/issues/25432 - if (sslStream.NegotiatedApplicationProtocol == SslApplicationProtocol.Http11) - { - feature.ApplicationProtocol = "http/1.1"; - } - else if (sslStream.NegotiatedApplicationProtocol == SslApplicationProtocol.Http2) - { - feature.ApplicationProtocol = "h2"; - } - else - { - feature.ApplicationProtocol = sslStream.NegotiatedApplicationProtocol.ToString(); - } - + feature.ApplicationProtocol = sslStream.NegotiatedApplicationProtocol.Protocol; context.Features.Set(feature); #endif feature.ClientCertificate = ConvertToX509Certificate2(sslStream.RemoteCertificate); diff --git a/src/Kestrel.Core/Internal/TlsConnectionFeature.cs b/src/Kestrel.Core/Internal/TlsConnectionFeature.cs index d5d7983d8e..a914024131 100644 --- a/src/Kestrel.Core/Internal/TlsConnectionFeature.cs +++ b/src/Kestrel.Core/Internal/TlsConnectionFeature.cs @@ -14,7 +14,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Https.Internal { public X509Certificate2 ClientCertificate { get; set; } - public string ApplicationProtocol { get; set; } + public ReadOnlyMemory ApplicationProtocol { get; set; } public Task GetClientCertificateAsync(CancellationToken cancellationToken) { diff --git a/src/Kestrel.Core/Kestrel.Core.csproj b/src/Kestrel.Core/Kestrel.Core.csproj index 2f6ea2a3bb..59b66b7373 100644 --- a/src/Kestrel.Core/Kestrel.Core.csproj +++ b/src/Kestrel.Core/Kestrel.Core.csproj @@ -4,7 +4,7 @@ Microsoft.AspNetCore.Server.Kestrel.Core Microsoft.AspNetCore.Server.Kestrel.Core Core components of ASP.NET Core Kestrel cross-platform web server. - netstandard2.0 + netstandard2.0;netcoreapp2.1 true aspnetcore;kestrel true From 7fde08d6fb28c704d5d9c9241ad041b94670f866 Mon Sep 17 00:00:00 2001 From: "ASP.NET CI" Date: Sat, 6 Jan 2018 14:58:00 -0800 Subject: [PATCH 1493/1662] Update dependencies.props [auto-updated: dependencies] --- korebuild-lock.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/korebuild-lock.txt b/korebuild-lock.txt index 7c2e97aa79..2146d006d7 100644 --- a/korebuild-lock.txt +++ b/korebuild-lock.txt @@ -1,2 +1,2 @@ -version:2.1.0-preview1-15651 -commithash:ebf2365121c2c6a6a0fbfa9b0f37bb5effc89323 +version:2.1.0-preview1-15661 +commithash:c9349d4c8a495d3085d9b879214d80f2f45e2193 From 9a8dd6ef12da395371a4f80cf2ef97f4f13adf48 Mon Sep 17 00:00:00 2001 From: Steffen Forkmann Date: Wed, 10 Jan 2018 00:01:09 +0100 Subject: [PATCH 1494/1662] Allow Content-Length 0 for Websocket-Connection (#2217) --- .../Internal/Http/Http1MessageBody.cs | 24 +++++++---------- test/Kestrel.Core.Tests/MessageBodyTests.cs | 26 +++++++++++++++++++ 2 files changed, 36 insertions(+), 14 deletions(-) diff --git a/src/Kestrel.Core/Internal/Http/Http1MessageBody.cs b/src/Kestrel.Core/Internal/Http/Http1MessageBody.cs index e75f7e7255..3d808838b9 100644 --- a/src/Kestrel.Core/Internal/Http/Http1MessageBody.cs +++ b/src/Kestrel.Core/Internal/Http/Http1MessageBody.cs @@ -230,6 +230,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http keepAlive = (connectionOptions & ConnectionOptions.KeepAlive) == ConnectionOptions.KeepAlive; } + if (upgrade) + { + if (headers.HeaderTransferEncoding.Count > 0 || (headers.ContentLength.HasValue && headers.ContentLength.Value != 0)) + { + context.ThrowRequestRejected(RequestRejectionReason.UpgradeRequestCannotHavePayload); + } + + return new ForUpgrade(context); + } + var transferEncoding = headers.HeaderTransferEncoding; if (transferEncoding.Count > 0) { @@ -246,11 +256,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http context.ThrowRequestRejected(RequestRejectionReason.FinalTransferCodingNotChunked, transferEncoding.ToString()); } - if (upgrade) - { - context.ThrowRequestRejected(RequestRejectionReason.UpgradeRequestCannotHavePayload); - } - return new ForChunkedEncoding(keepAlive, context); } @@ -262,10 +267,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { return keepAlive ? MessageBody.ZeroContentLengthKeepAlive : MessageBody.ZeroContentLengthClose; } - else if (upgrade) - { - context.ThrowRequestRejected(RequestRejectionReason.UpgradeRequestCannotHavePayload); - } return new ForContentLength(keepAlive, contentLength, context); } @@ -282,11 +283,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http } } - if (upgrade) - { - return new ForUpgrade(context); - } - return keepAlive ? MessageBody.ZeroContentLengthKeepAlive : MessageBody.ZeroContentLengthClose; } diff --git a/test/Kestrel.Core.Tests/MessageBodyTests.cs b/test/Kestrel.Core.Tests/MessageBodyTests.cs index 76ecd86f7f..9fa5b6ef1a 100644 --- a/test/Kestrel.Core.Tests/MessageBodyTests.cs +++ b/test/Kestrel.Core.Tests/MessageBodyTests.cs @@ -503,6 +503,32 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests } } + [Fact] + public async Task UpgradeConnectionAcceptsContentLengthZero() + { + // https://tools.ietf.org/html/rfc7230#section-3.3.2 + // "A user agent SHOULD NOT send a Content-Length header field when the request message does not contain + // a payload body and the method semantics do not anticipate such a body." + // ==> it can actually send that header + var headerConnection = "Upgrade, Keep-Alive"; + using (var input = new TestInput()) + { + var body = Http1MessageBody.For(HttpVersion.Http11, new HttpRequestHeaders { HeaderConnection = headerConnection, ContentLength = 0 }, input.Http1Connection); + var stream = new HttpRequestStream(Mock.Of()); + stream.StartAcceptingReads(body); + + input.Add("Hello"); + + var buffer = new byte[1024]; + Assert.Equal(5, await stream.ReadAsync(buffer, 0, buffer.Length)); + AssertASCII("Hello", new ArraySegment(buffer, 0, 5)); + + input.Fin(); + + await body.StopAsync(); + } + } + [Fact] public async Task PumpAsyncDoesNotReturnAfterCancelingInput() { From 420500e2a94e3849db51b161c6507127250a04d0 Mon Sep 17 00:00:00 2001 From: "Chris Ross (ASP.NET)" Date: Tue, 10 Oct 2017 16:26:22 -0700 Subject: [PATCH 1495/1662] #2102 Always start the response before draining the request. --- .../Internal/Http/HttpProtocol.cs | 31 +++-- .../MaxRequestBodySizeTests.cs | 3 +- .../RequestBodyTimeoutTests.cs | 16 ++- test/Kestrel.FunctionalTests/ResponseTests.cs | 108 ++++++++++++------ 4 files changed, 104 insertions(+), 54 deletions(-) diff --git a/src/Kestrel.Core/Internal/Http/HttpProtocol.cs b/src/Kestrel.Core/Internal/Http/HttpProtocol.cs index 2d722efa3e..cc34dfef3c 100644 --- a/src/Kestrel.Core/Internal/Http/HttpProtocol.cs +++ b/src/Kestrel.Core/Internal/Http/HttpProtocol.cs @@ -517,19 +517,19 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http // If _requestAbort is set, the connection has already been closed. if (_requestAborted == 0) { - if (HasResponseStarted) - { - // If the response has already started, call ProduceEnd() before - // consuming the rest of the request body to prevent - // delaying clients waiting for the chunk terminator: - // - // https://github.com/dotnet/corefx/issues/17330#issuecomment-288248663 - // - // ProduceEnd() must be called before _application.DisposeContext(), to ensure - // HttpContext.Response.StatusCode is correctly set when - // IHttpContextFactory.Dispose(HttpContext) is called. - await ProduceEnd(); - } + // Call ProduceEnd() before consuming the rest of the request body to prevent + // delaying clients waiting for the chunk terminator: + // + // https://github.com/dotnet/corefx/issues/17330#issuecomment-288248663 + // + // This also prevents the 100 Continue response from being sent if the app + // never tried to read the body. + // https://github.com/aspnet/KestrelHttpServer/issues/2102 + // + // ProduceEnd() must be called before _application.DisposeContext(), to ensure + // HttpContext.Response.StatusCode is correctly set when + // IHttpContextFactory.Dispose(HttpContext) is called. + await ProduceEnd(); // ForZeroContentLength does not complete the reader nor the writer if (!messageBody.IsEmpty && _keepAlive) @@ -537,11 +537,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http // Finish reading the request body in case the app did not. await messageBody.ConsumeAsync(); } - - if (!HasResponseStarted) - { - await ProduceEnd(); - } } else if (!HasResponseStarted) { diff --git a/test/Kestrel.FunctionalTests/MaxRequestBodySizeTests.cs b/test/Kestrel.FunctionalTests/MaxRequestBodySizeTests.cs index 925fc11f63..8c68fe3c39 100644 --- a/test/Kestrel.FunctionalTests/MaxRequestBodySizeTests.cs +++ b/test/Kestrel.FunctionalTests/MaxRequestBodySizeTests.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.IO; using System.Text; using System.Threading.Tasks; using Microsoft.AspNetCore.Http.Features; @@ -140,7 +141,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [Fact] public async Task DoesNotRejectBodylessGetRequestWithZeroMaxRequestBodySize() { - using (var server = new TestServer(context => Task.CompletedTask, + using (var server = new TestServer(context => context.Request.Body.CopyToAsync(Stream.Null), new TestServiceContext { ServerOptions = { Limits = { MaxRequestBodySize = 0 } } })) { using (var connection = server.CreateConnection()) diff --git a/test/Kestrel.FunctionalTests/RequestBodyTimeoutTests.cs b/test/Kestrel.FunctionalTests/RequestBodyTimeoutTests.cs index 073b646e2d..a9593afe79 100644 --- a/test/Kestrel.FunctionalTests/RequestBodyTimeoutTests.cs +++ b/test/Kestrel.FunctionalTests/RequestBodyTimeoutTests.cs @@ -7,9 +7,12 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.AspNetCore.Server.Kestrel.Core.Features; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; using Microsoft.AspNetCore.Testing; +using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Logging.Testing; using Xunit; namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests @@ -66,12 +69,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [Fact] public async Task RequestTimesOutWhenNotDrainedWithinDrainTimeoutPeriod() { + var sink = new TestSink(); + var logger = new TestLogger("TestLogger", sink, enabled: true); + // This test requires a real clock since we can't control when the drain timeout is set var systemClock = new SystemClock(); var serviceContext = new TestServiceContext { SystemClock = systemClock, - DateHeaderValueManager = new DateHeaderValueManager(systemClock) + DateHeaderValueManager = new DateHeaderValueManager(systemClock), + Log = new KestrelTrace(logger) }; var appRunningEvent = new ManualResetEventSlim(); @@ -96,17 +103,20 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests Assert.True(appRunningEvent.Wait(TimeSpan.FromSeconds(10))); await connection.Receive( - "HTTP/1.1 408 Request Timeout", - "Connection: close", + "HTTP/1.1 200 OK", ""); await connection.ReceiveStartsWith( "Date: "); + // Disconnected due to the timeout await connection.ReceiveForcedEnd( "Content-Length: 0", "", ""); } } + + Assert.Contains(sink.Writes, w => w.EventId.Id == 17 && w.LogLevel == LogLevel.Information && w.Exception is BadHttpRequestException + && ((BadHttpRequestException)w.Exception).StatusCode == StatusCodes.Status408RequestTimeout); } [Fact] diff --git a/test/Kestrel.FunctionalTests/ResponseTests.cs b/test/Kestrel.FunctionalTests/ResponseTests.cs index 8fc7a16052..a43f9cb746 100644 --- a/test/Kestrel.FunctionalTests/ResponseTests.cs +++ b/test/Kestrel.FunctionalTests/ResponseTests.cs @@ -257,8 +257,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { return Task.CompletedTask; }, - expectedClientStatusCode: null, - expectedServerStatusCode: HttpStatusCode.BadRequest, + expectedClientStatusCode: HttpStatusCode.OK, + expectedServerStatusCode: HttpStatusCode.OK, sendMalformedRequest: true); } @@ -289,8 +289,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { } }, - expectedClientStatusCode: null, - expectedServerStatusCode: HttpStatusCode.BadRequest, + expectedClientStatusCode: HttpStatusCode.OK, + expectedServerStatusCode: HttpStatusCode.OK, sendMalformedRequest: true); } @@ -311,8 +311,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests disposedTcs.TrySetResult(c.Response.StatusCode); }); - using (var server = new TestServer(handler, new TestServiceContext(), new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0)), - services => services.AddSingleton(mockHttpContextFactory.Object))) + var sink = new TestSink(); + var logger = new TestLogger("TestLogger", sink, enabled: true); + + using (var server = new TestServer(handler, new TestServiceContext() { Log = new KestrelTrace(logger) }, + new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0)), + services => services.AddSingleton(mockHttpContextFactory.Object))) { if (!sendMalformedRequest) { @@ -342,32 +346,57 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests "Transfer-Encoding: chunked", "", "gg"); - await connection.ReceiveForcedEnd( - "HTTP/1.1 400 Bad Request", - "Connection: close", - $"Date: {server.Context.DateHeaderValue}", - "Content-Length: 0", - "", - ""); + if (expectedClientStatusCode == HttpStatusCode.OK) + { + await connection.ReceiveForcedEnd( + "HTTP/1.1 200 OK", + $"Date: {server.Context.DateHeaderValue}", + "Content-Length: 0", + "", + ""); + } + else + { + await connection.ReceiveForcedEnd( + "HTTP/1.1 400 Bad Request", + "Connection: close", + $"Date: {server.Context.DateHeaderValue}", + "Content-Length: 0", + "", + ""); + } } } var disposedStatusCode = await disposedTcs.Task.TimeoutAfter(TimeSpan.FromSeconds(10)); Assert.Equal(expectedServerStatusCode, (HttpStatusCode)disposedStatusCode); } + + if (sendMalformedRequest) + { + Assert.Contains(sink.Writes, w => w.EventId.Id == 17 && w.LogLevel == LogLevel.Information && w.Exception is BadHttpRequestException + && ((BadHttpRequestException)w.Exception).StatusCode == StatusCodes.Status400BadRequest); + } + else + { + Assert.DoesNotContain(sink.Writes, w => w.EventId.Id == 17 && w.LogLevel == LogLevel.Information && w.Exception is BadHttpRequestException + && ((BadHttpRequestException)w.Exception).StatusCode == StatusCodes.Status400BadRequest); + } } // https://github.com/aspnet/KestrelHttpServer/pull/1111/files#r80584475 explains the reason for this test. [Fact] - public async Task SingleErrorResponseSentWhenAppSwallowsBadRequestException() + public async Task NoErrorResponseSentWhenAppSwallowsBadRequestException() { BadHttpRequestException readException = null; + var sink = new TestSink(); + var logger = new TestLogger("TestLogger", sink, enabled: true); using (var server = new TestServer(async httpContext => { readException = await Assert.ThrowsAsync( async () => await httpContext.Request.Body.ReadAsync(new byte[1], 0, 1)); - })) + }, new TestServiceContext() { Log = new KestrelTrace(logger) })) { using (var connection = server.CreateConnection()) { @@ -378,8 +407,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests "", "gg"); await connection.ReceiveForcedEnd( - "HTTP/1.1 400 Bad Request", - "Connection: close", + "HTTP/1.1 200 OK", $"Date: {server.Context.DateHeaderValue}", "Content-Length: 0", "", @@ -388,6 +416,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } Assert.NotNull(readException); + + Assert.Contains(sink.Writes, w => w.EventId.Id == 17 && w.LogLevel == LogLevel.Information && w.Exception is BadHttpRequestException + && ((BadHttpRequestException)w.Exception).StatusCode == StatusCodes.Status400BadRequest); } [Fact] @@ -1474,9 +1505,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } [Fact] - public async Task WhenResponseNotStartedResponseEndedAfterConsumingRequestBody() + public async Task WhenResponseNotStartedResponseEndedBeforeConsumingRequestBody() { - using (var server = new TestServer(httpContext => Task.CompletedTask)) + var sink = new TestSink(); + var logger = new TestLogger("TestLogger", sink, enabled: true); + + using (var server = new TestServer(httpContext => Task.CompletedTask, + new TestServiceContext() { Log = new KestrelTrace(logger) })) { using (var connection = server.CreateConnection()) { @@ -1487,27 +1522,32 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests "", "gg"); - // If the expected behavior is regressed, this will receive - // a success response because the server flushed the response - // before reading the malformed chunk header in the request. + // This will receive a success response because the server flushed the response + // before reading the malformed chunk header in the request, but then it will close + // the connection. await connection.ReceiveForcedEnd( - "HTTP/1.1 400 Bad Request", - "Connection: close", + "HTTP/1.1 200 OK", $"Date: {server.Context.DateHeaderValue}", "Content-Length: 0", "", ""); } } + + Assert.Contains(sink.Writes, w => w.EventId.Id == 17 && w.LogLevel == LogLevel.Information && w.Exception is BadHttpRequestException + && ((BadHttpRequestException)w.Exception).StatusCode == StatusCodes.Status400BadRequest); } [Fact] public async Task Sending100ContinueDoesNotStartResponse() { + var sink = new TestSink(); + var logger = new TestLogger("TestLogger", sink, enabled: true); + using (var server = new TestServer(httpContext => { return httpContext.Request.Body.ReadAsync(new byte[1], 0, 1); - })) + }, new TestServiceContext() { Log = new KestrelTrace(logger) })) { using (var connection = server.CreateConnection()) { @@ -1530,6 +1570,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests "a", ""); + await connection.Receive( + "HTTP/1.1 200 OK", + $"Date: {server.Context.DateHeaderValue}", + "Content-Length: 0", + "", + ""); + // This will be consumed by Http1Connection when it attempts to // consume the request body and will cause an error. await connection.Send( @@ -1538,15 +1585,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests // If 100 Continue sets HttpProtocol.HasResponseStarted to true, // a success response will be produced before the server sees the // bad chunk header above, making this test fail. - await connection.ReceiveForcedEnd( - "HTTP/1.1 400 Bad Request", - "Connection: close", - $"Date: {server.Context.DateHeaderValue}", - "Content-Length: 0", - "", - ""); + await connection.ReceiveEnd(); } } + + Assert.Contains(sink.Writes, w => w.EventId.Id == 17 && w.LogLevel == LogLevel.Information && w.Exception is BadHttpRequestException + && ((BadHttpRequestException)w.Exception).StatusCode == StatusCodes.Status400BadRequest); } [Fact] From 1bce01cb9c0c6b305068c462a6d5d7dbb98ce0fe Mon Sep 17 00:00:00 2001 From: Nate McMaster Date: Fri, 12 Jan 2018 14:47:52 -0800 Subject: [PATCH 1496/1662] Respect NoBuild from /t:StressTest --- build/repo.targets | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/build/repo.targets b/build/repo.targets index 85c8e8c896..820bc06a7f 100644 --- a/build/repo.targets +++ b/build/repo.targets @@ -2,10 +2,16 @@ - + + + Build + + + + From e6bb55101893142f92912c748e66115bc4aacdb4 Mon Sep 17 00:00:00 2001 From: Javier Calvarro Nelson Date: Mon, 8 Jan 2018 10:28:38 -0800 Subject: [PATCH 1497/1662] Adds support for loading the developer certificate from a pfx file * If we can't find a developer certificate on the certificate store we will look for a developer certificate on the file system if a password has been specified for the Development certificate. * We will look at ${APPDATA}/ASP.NET/https/<>.pfx for windows and fallback to ${HOME}/.aspnet/https/<>.pfx * In case the password wasn't specified through configuration, the file is not found on the file system or can't be loaded, we won't do anything. --- .../Internal/KestrelServerOptionsSetup.cs | 15 ++- src/Kestrel.Core/Internal/LoggerExtensions.cs | 10 ++ .../KestrelConfigurationLoader.cs | 76 +++++++++++- .../KestrelConfigurationBuilderTests.cs | 115 ++++++++++++++++++ .../shared/TestCertificates/aspnetdevcert.pfx | Bin 0 -> 2700 bytes 5 files changed, 212 insertions(+), 4 deletions(-) create mode 100644 test/shared/TestCertificates/aspnetdevcert.pfx diff --git a/src/Kestrel.Core/Internal/KestrelServerOptionsSetup.cs b/src/Kestrel.Core/Internal/KestrelServerOptionsSetup.cs index 18831f0b49..013ce0ac80 100644 --- a/src/Kestrel.Core/Internal/KestrelServerOptionsSetup.cs +++ b/src/Kestrel.Core/Internal/KestrelServerOptionsSetup.cs @@ -29,10 +29,19 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal private void UseDefaultDeveloperCertificate(KestrelServerOptions options) { - var certificateManager = new CertificateManager(); - var certificate = certificateManager.ListCertificates(CertificatePurpose.HTTPS, StoreName.My, StoreLocation.CurrentUser, isValid: true) - .FirstOrDefault(); var logger = options.ApplicationServices.GetRequiredService>(); + X509Certificate2 certificate = null; + try + { + var certificateManager = new CertificateManager(); + certificate = certificateManager.ListCertificates(CertificatePurpose.HTTPS, StoreName.My, StoreLocation.CurrentUser, isValid: true) + .FirstOrDefault(); + } + catch + { + logger.UnableToLocateDevelopmentCertificate(); + } + if (certificate != null) { logger.LocatedDevelopmentCertificate(certificate); diff --git a/src/Kestrel.Core/Internal/LoggerExtensions.cs b/src/Kestrel.Core/Internal/LoggerExtensions.cs index 1f3b8d131d..0a4c6f3a5e 100644 --- a/src/Kestrel.Core/Internal/LoggerExtensions.cs +++ b/src/Kestrel.Core/Internal/LoggerExtensions.cs @@ -13,8 +13,18 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal private static readonly Action _unableToLocateDevelopmentCertificate = LoggerMessage.Define(LogLevel.Debug, new EventId(1, nameof(UnableToLocateDevelopmentCertificate)), "Unable to locate an appropriate development https certificate."); + private static readonly Action _failedToLocateDevelopmentCertificateFile = + LoggerMessage.Define(LogLevel.Debug, new EventId(2, nameof(FailedToLocateDevelopmentCertificateFile)), "Failed to locate the development https certificate at '{certificatePath}'."); + + private static readonly Action _failedToLoadDevelopmentCertificate = + LoggerMessage.Define(LogLevel.Debug, new EventId(3, nameof(FailedToLoadDevelopmentCertificate)), "Failed to load the development https certificate at '{certificatePath}'."); + public static void LocatedDevelopmentCertificate(this ILogger logger, X509Certificate2 certificate) => _locatedDevelopmentCertificate(logger, certificate.Subject, certificate.Thumbprint, null); public static void UnableToLocateDevelopmentCertificate(this ILogger logger) => _unableToLocateDevelopmentCertificate(logger, null); + + public static void FailedToLocateDevelopmentCertificateFile(this ILogger logger, string certificatePath) => _failedToLocateDevelopmentCertificateFile(logger, certificatePath, null); + + public static void FailedToLoadDevelopmentCertificate(this ILogger logger, string certificatePath) => _failedToLoadDevelopmentCertificate(logger, certificatePath, null); } } diff --git a/src/Kestrel.Core/KestrelConfigurationLoader.cs b/src/Kestrel.Core/KestrelConfigurationLoader.cs index 1dfb9d262c..71337a11d2 100644 --- a/src/Kestrel.Core/KestrelConfigurationLoader.cs +++ b/src/Kestrel.Core/KestrelConfigurationLoader.cs @@ -6,14 +6,18 @@ using System.Collections.Generic; using System.IO; using System.Linq; using System.Net; +using System.Security.Cryptography; using System.Security.Cryptography.X509Certificates; +using Microsoft.AspNetCore.Certificates.Generation; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal; using Microsoft.AspNetCore.Server.Kestrel.Https; using Microsoft.AspNetCore.Server.Kestrel.Https.Internal; +using Microsoft.AspNetCore.Server.Kestrel.Internal; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; namespace Microsoft.AspNetCore.Server.Kestrel { @@ -205,7 +209,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel var configReader = new ConfigurationReader(Configuration); LoadDefaultCert(configReader); - + foreach (var endpoint in configReader.Endpoints) { var listenOptions = AddressBinder.ParseAddress(endpoint.Url, out var https); @@ -259,6 +263,76 @@ namespace Microsoft.AspNetCore.Server.Kestrel Options.DefaultCertificate = defaultCert; } } + else + { + var logger = Options.ApplicationServices.GetRequiredService>(); + var certificate = FindDeveloperCertificateFile(configReader, logger); + if (certificate != null) + { + logger.LocatedDevelopmentCertificate(certificate); + Options.DefaultCertificate = certificate; + } + } + } + + private X509Certificate2 FindDeveloperCertificateFile(ConfigurationReader configReader, ILogger logger) + { + string certificatePath = null; + try + { + if (configReader.Certificates.TryGetValue("Development", out var certificateConfig) && + certificateConfig.Path == null && + certificateConfig.Password != null && + TryGetCertificatePath(out certificatePath) && + File.Exists(certificatePath)) + { + var certificate = new X509Certificate2(certificatePath, certificateConfig.Password); + return IsDevelopmentCertificate(certificate) ? certificate : null; + } + else if (!File.Exists(certificatePath)) + { + logger.FailedToLocateDevelopmentCertificateFile(certificatePath); + } + } + catch (CryptographicException) + { + logger.FailedToLoadDevelopmentCertificate(certificatePath); + } + + return null; + } + + private bool IsDevelopmentCertificate(X509Certificate2 certificate) + { + if (!string.Equals(certificate.Subject, "CN=localhost", StringComparison.Ordinal)) + { + return false; + } + + foreach (var ext in certificate.Extensions) + { + if (string.Equals(ext.Oid.Value, CertificateManager.AspNetHttpsOid, StringComparison.Ordinal)) + { + return true; + } + } + + return false; + } + + private bool TryGetCertificatePath(out string path) + { + var hostingEnvironment = Options.ApplicationServices.GetRequiredService(); + var appName = hostingEnvironment.ApplicationName; + + // This will go away when we implement + // https://github.com/aspnet/Hosting/issues/1294 + var appData = Environment.GetEnvironmentVariable("APPDATA"); + var home = Environment.GetEnvironmentVariable("HOME"); + var basePath = appData != null ? Path.Combine(appData, "ASP.NET", "https") : null; + basePath = basePath ?? (home != null ? Path.Combine(home, ".aspnet", "https") : null); + path = basePath != null ? Path.Combine(basePath, $"{appName}.pfx") : null; + return path != null; } private X509Certificate2 LoadCertificate(CertificateConfig certInfo, string endpointName) diff --git a/test/Kestrel.Tests/KestrelConfigurationBuilderTests.cs b/test/Kestrel.Tests/KestrelConfigurationBuilderTests.cs index bdd9bff4c1..33caeb1d34 100644 --- a/test/Kestrel.Tests/KestrelConfigurationBuilderTests.cs +++ b/test/Kestrel.Tests/KestrelConfigurationBuilderTests.cs @@ -3,9 +3,11 @@ using System; using System.Collections.Generic; +using System.IO; using System.Linq; using System.Security.Cryptography.X509Certificates; using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Hosting.Internal; using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.AspNetCore.Server.Kestrel.Https; using Microsoft.AspNetCore.Testing; @@ -22,6 +24,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Tests var serverOptions = new KestrelServerOptions(); serverOptions.ApplicationServices = new ServiceCollection() .AddLogging() + .AddSingleton(new HostingEnvironment() { ApplicationName = "TestApplication" }) .BuildServiceProvider(); return serverOptions; } @@ -209,5 +212,117 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Tests Assert.NotNull(serverOptions.ListenOptions[0].ConnectionAdapters.Where(adapter => adapter.IsHttps).SingleOrDefault()); Assert.NotNull(serverOptions.ListenOptions[1].ConnectionAdapters.Where(adapter => adapter.IsHttps).SingleOrDefault()); } + + [Fact] + public void ConfigureEndpointDevelopmentCertificateGetsLoadedWhenPresent() + { + try + { + var serverOptions = CreateServerOptions(); + var certificate = new X509Certificate2(TestResources.GetCertPath("aspnetdevcert.pfx"), "aspnetdevcert", X509KeyStorageFlags.Exportable); + var bytes = certificate.Export(X509ContentType.Pkcs12, "1234"); + var path = GetCertificatePath(); + Directory.CreateDirectory(Path.GetDirectoryName(path)); + File.WriteAllBytes(path, bytes); + + var ran1 = false; + var config = new ConfigurationBuilder().AddInMemoryCollection(new[] + { + new KeyValuePair("Endpoints:End1:Url", "https://*:5001"), + new KeyValuePair("Certificates:Development:Password", "1234"), + }).Build(); + + serverOptions + .Configure(config) + .Endpoint("End1", opt => + { + ran1 = true; + Assert.True(opt.IsHttps); + Assert.Equal(opt.HttpsOptions.ServerCertificate.SerialNumber, certificate.SerialNumber); + }).Load(); + + Assert.True(ran1); + Assert.NotNull(serverOptions.DefaultCertificate); + } + finally + { + if (File.Exists(GetCertificatePath())) + { + File.Delete(GetCertificatePath()); + } + } + } + + [Fact] + public void ConfigureEndpointDevelopmentCertificateGetsIgnoredIfPasswordIsNotCorrect() + { + try + { + var serverOptions = CreateServerOptions(); + var certificate = new X509Certificate2(TestResources.GetCertPath("aspnetdevcert.pfx"), "aspnetdevcert", X509KeyStorageFlags.Exportable); + var bytes = certificate.Export(X509ContentType.Pkcs12, "1234"); + var path = GetCertificatePath(); + Directory.CreateDirectory(Path.GetDirectoryName(path)); + File.WriteAllBytes(path, bytes); + + var config = new ConfigurationBuilder().AddInMemoryCollection(new[] + { + new KeyValuePair("Certificates:Development:Password", "12341234"), + }).Build(); + + serverOptions + .Configure(config) + .Load(); + + Assert.Null(serverOptions.DefaultCertificate); + } + finally + { + if (File.Exists(GetCertificatePath())) + { + File.Delete(GetCertificatePath()); + } + } + } + + [Fact] + public void ConfigureEndpointDevelopmentCertificateGetsIgnoredIfPfxFileDoesNotExist() + { + try + { + var serverOptions = CreateServerOptions(); + if (File.Exists(GetCertificatePath())) + { + File.Delete(GetCertificatePath()); + } + + var config = new ConfigurationBuilder().AddInMemoryCollection(new[] + { + new KeyValuePair("Certificates:Development:Password", "12341234") + }).Build(); + + serverOptions + .Configure(config) + .Load(); + + Assert.Null(serverOptions.DefaultCertificate); + } + finally + { + if (File.Exists(GetCertificatePath())) + { + File.Delete(GetCertificatePath()); + } + } + } + + private static string GetCertificatePath() + { + var appData = Environment.GetEnvironmentVariable("APPDATA"); + var home = Environment.GetEnvironmentVariable("HOME"); + var basePath = appData != null ? Path.Combine(appData, "ASP.NET", "https") : null; + basePath = basePath ?? (home != null ? Path.Combine(home, ".aspnet", "https") : null); + return Path.Combine(basePath, $"TestApplication.pfx"); + } } } diff --git a/test/shared/TestCertificates/aspnetdevcert.pfx b/test/shared/TestCertificates/aspnetdevcert.pfx new file mode 100644 index 0000000000000000000000000000000000000000..e6eeeaa2e1f2a7cbee60365229c5e40e64c352ff GIT binary patch literal 2700 zcmZXUc{tQ-8^?dM7|Y;9W6N5W>}HN-tXUdcmPVrNgphqH;ba+7osjI=8WJL8UlO6Q z4#rlpWb8Gvj3tc9JE!Zs=Ungg{&7Fg_x^mJ`@WvPzDOL)eJ}`u#Iayt%+m2j@%wBb zMi3syq722cpy*f*iDTIKAB$lQies3j;}7&2gTeovVr2n=@i^!P5(lLq1z;@y#q{Ou zP^Rnlj?U}dIR;=bBMFLw_8ti~)c3}(M>9Ji{b!<-iJ&Wbk-u=;rCR(tp&mERKKqBotKSNj$*Sg!b@UDOMt^l9m>3iv4 zw03P*G$+Po15fE^K(Ec3UugOW(_K@*r>!?pnLe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z)aZQXU{}C7o@3T=Ci}zF*R{D1r8Ds}y?O6yJkh$7$QkFNP3aWqQKZ@Cz4^`rUwtFK zjEYyW_Ppw%nru$5#;MIe3);U#lA4>9dq9*wa;K~YKiyf13jAo`y1>zA*FOn{PwYcx z4#G~sxs}88>hpct)y^XUGI1>jY#zdC~KnQGe`%CbChvP^BJH+tgr5^c@c_vw6Xd>|_m{ zl78y_A?&Vr`Sp}G0%>SSRep4SdB-L-oieSkZK;aFm;*SgA)++_Cv5kA_+C~|#q6HA zdWExH*IgeNqY~8;uOPCR<|iI4oXXD&d2xLqb*w|#F}0TP^GR8^FoEjV(o8e0e0@G8 z#>9M9Ymm__s~KXyEAaG_898yT{=47+Igtq24+#?&=8{s&zOnAi!PzH6adEKCNA#^l zuv}5}6d$boV$*WgntbJ~rfy4}GydiYob;c2KHoMH*3ygQbzOP{CYXTeyJ;`O7u8ji~3aggRfvmjfR?|0wyy3mKSaE6O{qlN;xqP0*K1$^ z)N`XUv}CVq|ADdWVzf;1D4F-MC5qJNn_T+^e~9!ObfX+ Date: Tue, 16 Jan 2018 16:43:45 -0800 Subject: [PATCH 1498/1662] Improve server shutdown logic (#2247) Ensure connections abort when they don't close gracefully. --- src/Kestrel.Core/Internal/HttpConnection.cs | 61 ++++++++++++++------- test/shared/TestApplicationErrorLogger.cs | 14 ++++- 2 files changed, 52 insertions(+), 23 deletions(-) diff --git a/src/Kestrel.Core/Internal/HttpConnection.cs b/src/Kestrel.Core/Internal/HttpConnection.cs index 2288e99413..c927017622 100644 --- a/src/Kestrel.Core/Internal/HttpConnection.cs +++ b/src/Kestrel.Core/Internal/HttpConnection.cs @@ -21,7 +21,7 @@ using Microsoft.Extensions.Logging; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal { - public class HttpConnection : ITimeoutControl, IConnectionTimeoutFeature, IRequestProcessor + public class HttpConnection : ITimeoutControl, IConnectionTimeoutFeature { private static readonly ReadOnlyMemory Http2Id = new[] { (byte)'h', (byte)'2' }; @@ -32,6 +32,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal private IPipeConnection _adaptedTransport; private readonly object _protocolSelectionLock = new object(); + private ProtocolSelectionState _protocolSelectionState = ProtocolSelectionState.Initializing; private IRequestProcessor _requestProcessor; private Http1Connection _http1Connection; @@ -54,7 +55,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal public HttpConnection(HttpConnectionContext context) { _context = context; - _requestProcessor = this; } // For testing @@ -140,19 +140,21 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal lock (_protocolSelectionLock) { // Ensure that the connection hasn't already been stopped. - if (_requestProcessor == this) + if (_protocolSelectionState == ProtocolSelectionState.Initializing) { switch (SelectProtocol()) { case HttpProtocols.Http1: // _http1Connection must be initialized before adding the connection to the connection manager requestProcessor = _http1Connection = CreateHttp1Connection(_adaptedTransport, application); + _protocolSelectionState = ProtocolSelectionState.Selected; break; case HttpProtocols.Http2: // _http2Connection must be initialized before yielding control to the transport thread, // to prevent a race condition where _http2Connection.Abort() is called just as // _http2Connection is about to be initialized. requestProcessor = CreateHttp2Connection(_adaptedTransport, application); + _protocolSelectionState = ProtocolSelectionState.Selected; break; case HttpProtocols.None: // An error was already logged in SelectProtocol(), but we should close the connection. @@ -197,6 +199,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal internal void Initialize(IPipeConnection transport, IPipeConnection application) { _requestProcessor = _http1Connection = CreateHttp1Connection(transport, application); + _protocolSelectionState = ProtocolSelectionState.Selected; } private Http1Connection CreateHttp1Connection(IPipeConnection transport, IPipeConnection application) @@ -241,8 +244,20 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal { lock (_protocolSelectionLock) { - _requestProcessor?.StopProcessingNextRequest(); - _requestProcessor = null; + switch (_protocolSelectionState) + { + case ProtocolSelectionState.Initializing: + CloseUninitializedConnection(); + _protocolSelectionState = ProtocolSelectionState.Stopped; + break; + case ProtocolSelectionState.Selected: + _requestProcessor.StopProcessingNextRequest(); + _protocolSelectionState = ProtocolSelectionState.Stopping; + break; + case ProtocolSelectionState.Stopping: + case ProtocolSelectionState.Stopped: + break; + } } return _lifetimeTask; @@ -252,8 +267,20 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal { lock (_protocolSelectionLock) { - _requestProcessor?.Abort(ex); - _requestProcessor = null; + switch (_protocolSelectionState) + { + case ProtocolSelectionState.Initializing: + CloseUninitializedConnection(); + break; + case ProtocolSelectionState.Selected: + case ProtocolSelectionState.Stopping: + _requestProcessor.Abort(ex); + break; + case ProtocolSelectionState.Stopped: + break; + } + + _protocolSelectionState = ProtocolSelectionState.Stopped; } } @@ -261,7 +288,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal { Abort(ex); - return _lifetimeTask; + return _socketClosedTcs.Task; } private async Task ApplyConnectionAdaptersAsync() @@ -582,20 +609,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal _adaptedTransport.Output.Complete(); } - // These IStoppableConnection methods only get called if the server shuts down during initialization. - Task IRequestProcessor.ProcessRequestsAsync(IHttpApplication application) + private enum ProtocolSelectionState { - throw new NotSupportedException(); - } - - void IRequestProcessor.StopProcessingNextRequest() - { - CloseUninitializedConnection(); - } - - void IRequestProcessor.Abort(Exception ex) - { - CloseUninitializedConnection(); + Initializing, + Selected, + Stopping, + Stopped } } } diff --git a/test/shared/TestApplicationErrorLogger.cs b/test/shared/TestApplicationErrorLogger.cs index 144b251802..480d8d4140 100644 --- a/test/shared/TestApplicationErrorLogger.cs +++ b/test/shared/TestApplicationErrorLogger.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Concurrent; using System.Linq; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; using Microsoft.Extensions.Logging; @@ -44,14 +45,23 @@ namespace Microsoft.AspNetCore.Testing if (logLevel == LogLevel.Critical && ThrowOnCriticalErrors) #endif { - Console.WriteLine($"Log {logLevel}[{eventId}]: {formatter(state, exception)} {exception?.Message}"); + var log = $"Log {logLevel}[{eventId}]: {formatter(state, exception)} {exception?.Message}"; + + Console.WriteLine(log); if (logLevel == LogLevel.Critical && ThrowOnCriticalErrors) { - throw new Exception("Unexpected critical error.", exception); + throw new Exception($"Unexpected critical error. {log}", exception); } } + // Fail tests where not all the connections close during server shutdown. + if (eventId.Id == 21 && eventId.Name == nameof(KestrelTrace.NotAllConnectionsAborted)) + { + var log = $"Log {logLevel}[{eventId}]: {formatter(state, exception)} {exception?.Message}"; + throw new Exception($"Shutdown failure. {log}"); + } + Messages.Enqueue(new LogMessage { LogLevel = logLevel, From cf371a4e740aa8ca76d49027e13d3dfa38ce3bdb Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Tue, 16 Jan 2018 18:11:11 -0800 Subject: [PATCH 1499/1662] Disable heartbeat warning when debugger is attached (#2258) --- .../Internal/Infrastructure/Heartbeat.cs | 9 +++-- src/Kestrel.Core/KestrelServer.cs | 5 ++- .../DateHeaderValueManagerTests.cs | 6 ++-- test/Kestrel.Core.Tests/HeartbeatTests.cs | 33 +++++++++++++++++-- 4 files changed, 45 insertions(+), 8 deletions(-) diff --git a/src/Kestrel.Core/Internal/Infrastructure/Heartbeat.cs b/src/Kestrel.Core/Internal/Infrastructure/Heartbeat.cs index 28a11f5580..f722f60e9d 100644 --- a/src/Kestrel.Core/Internal/Infrastructure/Heartbeat.cs +++ b/src/Kestrel.Core/Internal/Infrastructure/Heartbeat.cs @@ -13,14 +13,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure private readonly IHeartbeatHandler[] _callbacks; private readonly ISystemClock _systemClock; + private readonly IDebugger _debugger; private readonly IKestrelTrace _trace; private Timer _timer; private int _executingOnHeartbeat; - public Heartbeat(IHeartbeatHandler[] callbacks, ISystemClock systemClock, IKestrelTrace trace) + public Heartbeat(IHeartbeatHandler[] callbacks, ISystemClock systemClock, IDebugger debugger, IKestrelTrace trace) { _callbacks = callbacks; _systemClock = systemClock; + _debugger = debugger; _trace = trace; } @@ -59,7 +61,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure } else { - _trace.HeartbeatSlow(Interval, now); + if (!_debugger.IsAttached) + { + _trace.HeartbeatSlow(Interval, now); + } } } diff --git a/src/Kestrel.Core/KestrelServer.cs b/src/Kestrel.Core/KestrelServer.cs index 6d2c1d059c..8f1c62099e 100644 --- a/src/Kestrel.Core/KestrelServer.cs +++ b/src/Kestrel.Core/KestrelServer.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Hosting.Server; @@ -47,7 +48,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core var httpHeartbeatManager = new HttpHeartbeatManager(serviceContext.ConnectionManager); _heartbeat = new Heartbeat( new IHeartbeatHandler[] { serviceContext.DateHeaderValueManager, httpHeartbeatManager }, - serviceContext.SystemClock, Trace); + serviceContext.SystemClock, + DebuggerWrapper.Singleton, + Trace); Features = new FeatureCollection(); _serverAddresses = new ServerAddressesFeature(); diff --git a/test/Kestrel.Core.Tests/DateHeaderValueManagerTests.cs b/test/Kestrel.Core.Tests/DateHeaderValueManagerTests.cs index 8af56589f8..3d1e880765 100644 --- a/test/Kestrel.Core.Tests/DateHeaderValueManagerTests.cs +++ b/test/Kestrel.Core.Tests/DateHeaderValueManagerTests.cs @@ -46,7 +46,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests var dateHeaderValueManager = new DateHeaderValueManager(systemClock); var testKestrelTrace = new TestKestrelTrace(); - using (var heartbeat = new Heartbeat(new IHeartbeatHandler[] { dateHeaderValueManager }, systemClock, testKestrelTrace)) + using (var heartbeat = new Heartbeat(new IHeartbeatHandler[] { dateHeaderValueManager }, systemClock, DebuggerWrapper.Singleton, testKestrelTrace)) { Assert.Equal(now.ToString(Rfc1123DateFormat), dateHeaderValueManager.GetDateHeaderValues().String); systemClock.UtcNow = future; @@ -71,7 +71,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests var mockHeartbeatHandler = new Mock(); - using (var heartbeat = new Heartbeat(new[] { dateHeaderValueManager, mockHeartbeatHandler.Object }, systemClock, testKestrelTrace)) + using (var heartbeat = new Heartbeat(new[] { dateHeaderValueManager, mockHeartbeatHandler.Object }, systemClock, DebuggerWrapper.Singleton, testKestrelTrace)) { heartbeat.OnHeartbeat(); @@ -100,7 +100,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests var dateHeaderValueManager = new DateHeaderValueManager(systemClock); var testKestrelTrace = new TestKestrelTrace(); - using (var heatbeat = new Heartbeat(new IHeartbeatHandler[] { dateHeaderValueManager }, systemClock, testKestrelTrace)) + using (var heatbeat = new Heartbeat(new IHeartbeatHandler[] { dateHeaderValueManager }, systemClock, DebuggerWrapper.Singleton, testKestrelTrace)) { heatbeat.OnHeartbeat(); Assert.Equal(now.ToString(Rfc1123DateFormat), dateHeaderValueManager.GetDateHeaderValues().String); diff --git a/test/Kestrel.Core.Tests/HeartbeatTests.cs b/test/Kestrel.Core.Tests/HeartbeatTests.cs index 6cd3b27000..5b961ce7bf 100644 --- a/test/Kestrel.Core.Tests/HeartbeatTests.cs +++ b/test/Kestrel.Core.Tests/HeartbeatTests.cs @@ -26,14 +26,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests { var systemClock = new MockSystemClock(); var heartbeatHandler = new Mock(); + var debugger = new Mock(); var kestrelTrace = new Mock(); var handlerMre = new ManualResetEventSlim(); var traceMre = new ManualResetEventSlim(); heartbeatHandler.Setup(h => h.OnHeartbeat(systemClock.UtcNow)).Callback(() => handlerMre.Wait()); + debugger.Setup(d => d.IsAttached).Returns(false); kestrelTrace.Setup(t => t.HeartbeatSlow(Heartbeat.Interval, systemClock.UtcNow)).Callback(() => traceMre.Set()); - using (var heartbeat = new Heartbeat(new[] { heartbeatHandler.Object }, systemClock, kestrelTrace.Object)) + using (var heartbeat = new Heartbeat(new[] { heartbeatHandler.Object }, systemClock, debugger.Object, kestrelTrace.Object)) { Task.Run(() => heartbeat.OnHeartbeat()); Task.Run(() => heartbeat.OnHeartbeat()); @@ -46,6 +48,33 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests kestrelTrace.Verify(t => t.HeartbeatSlow(Heartbeat.Interval, systemClock.UtcNow), Times.Once()); } + [Fact] + public void BlockedHeartbeatIsNotLoggedAsErrorIfDebuggerAttached() + { + var systemClock = new MockSystemClock(); + var heartbeatHandler = new Mock(); + var debugger = new Mock(); + var kestrelTrace = new Mock(); + var handlerMre = new ManualResetEventSlim(); + var traceMre = new ManualResetEventSlim(); + + heartbeatHandler.Setup(h => h.OnHeartbeat(systemClock.UtcNow)).Callback(() => handlerMre.Wait()); + debugger.Setup(d => d.IsAttached).Returns(true); + kestrelTrace.Setup(t => t.HeartbeatSlow(Heartbeat.Interval, systemClock.UtcNow)).Callback(() => traceMre.Set()); + + using (var heartbeat = new Heartbeat(new[] { heartbeatHandler.Object }, systemClock, debugger.Object, kestrelTrace.Object)) + { + Task.Run(() => heartbeat.OnHeartbeat()); + Task.Run(() => heartbeat.OnHeartbeat()); + Assert.False(traceMre.Wait(TimeSpan.FromSeconds(10))); + } + + handlerMre.Set(); + + heartbeatHandler.Verify(h => h.OnHeartbeat(systemClock.UtcNow), Times.Once()); + kestrelTrace.Verify(t => t.HeartbeatSlow(Heartbeat.Interval, systemClock.UtcNow), Times.Never()); + } + [Fact] public void ExceptionFromHeartbeatHandlerIsLoggedAsError() { @@ -56,7 +85,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests heartbeatHandler.Setup(h => h.OnHeartbeat(systemClock.UtcNow)).Throws(ex); - using (var heartbeat = new Heartbeat(new[] { heartbeatHandler.Object }, systemClock, kestrelTrace)) + using (var heartbeat = new Heartbeat(new[] { heartbeatHandler.Object }, systemClock, DebuggerWrapper.Singleton, kestrelTrace)) { heartbeat.OnHeartbeat(); } From 040ea2e6b45b5909abe3c3b0e199ff6dd6136026 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Thu, 18 Jan 2018 15:53:46 -0800 Subject: [PATCH 1500/1662] Fix MockLibuv.OnPostTask (#2260) Prevents UvWriteReq leaks in LibuvOutputConsumerTests --- .../TestHelpers/MockLibuv.cs | 52 +++++-------------- 1 file changed, 14 insertions(+), 38 deletions(-) diff --git a/test/Kestrel.Transport.Libuv.Tests/TestHelpers/MockLibuv.cs b/test/Kestrel.Transport.Libuv.Tests/TestHelpers/MockLibuv.cs index 4f334bcfea..6cb3f6917a 100644 --- a/test/Kestrel.Transport.Libuv.Tests/TestHelpers/MockLibuv.cs +++ b/test/Kestrel.Transport.Libuv.Tests/TestHelpers/MockLibuv.cs @@ -16,7 +16,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests.TestHelpers private readonly object _postLock = new object(); private TaskCompletionSource _onPostTcs = new TaskCompletionSource(); private bool _completedOnPostTcs; - private bool _sendCalled; private bool _stopLoop; private readonly ManualResetEventSlim _loopWh = new ManualResetEventSlim(); @@ -38,29 +37,17 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests.TestHelpers _uv_async_send = postHandle => { - // Attempt to run the async send logic inline; this should succeed most of the time. - // In the rare cases where it fails to acquire the lock, use Task.Run() so this call - // never blocks, since the real libuv never blocks. - if (Monitor.TryEnter(_postLock)) + lock (_postLock) { - try + if (_completedOnPostTcs) { - UvAsyncSend(); + _onPostTcs = new TaskCompletionSource(); + _completedOnPostTcs = false; } - finally - { - Monitor.Exit(_postLock); - } - } - else - { - Task.Run(() => - { - lock (_postLock) - { - UvAsyncSend(); - } - }); + + PostCount++; + + _loopWh.Set(); } return 0; @@ -83,13 +70,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests.TestHelpers lock (_postLock) { - _sendCalled = false; _loopWh.Reset(); - _onPost(_postHandle.InternalGetHandle()); + } + _onPost(_postHandle.InternalGetHandle()); + + lock (_postLock) + { // Allow the loop to be run again before completing // _onPostTcs given a nested uv_async_send call. - if (!_sendCalled) + if (!_loopWh.IsSet) { // Ensure any subsequent calls to uv_async_send // create a new _onPostTcs to be completed. @@ -171,19 +161,5 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests.TestHelpers { return OnWrite(handle, nbufs, status => cb(req.InternalGetHandle(), status)); } - - private void UvAsyncSend() - { - if (_completedOnPostTcs) - { - _onPostTcs = new TaskCompletionSource(); - _completedOnPostTcs = false; - } - - PostCount++; - - _sendCalled = true; - _loopWh.Set(); - } } } From 526dfdb332b30fd6042d8ef8d1a2ba99cc654010 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Thu, 18 Jan 2018 17:25:28 -0800 Subject: [PATCH 1501/1662] Switch back to libuv as the default transport (#2257) * Switch back to libuv as the default transport --- .../WebHostBuilderKestrelExtensions.cs | 5 +- .../WebHostBuilderKestrelExtensionsTests.cs | 49 +++++++++++++++++++ 2 files changed, 51 insertions(+), 3 deletions(-) diff --git a/src/Kestrel/WebHostBuilderKestrelExtensions.cs b/src/Kestrel/WebHostBuilderKestrelExtensions.cs index faac901aff..70b1a34d74 100644 --- a/src/Kestrel/WebHostBuilderKestrelExtensions.cs +++ b/src/Kestrel/WebHostBuilderKestrelExtensions.cs @@ -5,9 +5,8 @@ using System; using Microsoft.AspNetCore.Hosting.Server; using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal; -using Microsoft.AspNetCore.Server.Kestrel.Internal; using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; -using Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection.Extensions; using Microsoft.Extensions.Options; @@ -30,7 +29,7 @@ namespace Microsoft.AspNetCore.Hosting return hostBuilder.ConfigureServices(services => { // Don't override an already-configured transport - services.TryAddSingleton(); + services.TryAddSingleton(); services.AddTransient, KestrelServerOptionsSetup>(); services.AddSingleton(); diff --git a/test/Kestrel.Tests/WebHostBuilderKestrelExtensionsTests.cs b/test/Kestrel.Tests/WebHostBuilderKestrelExtensionsTests.cs index fc5d6509ae..3c10c1c0ff 100644 --- a/test/Kestrel.Tests/WebHostBuilderKestrelExtensionsTests.cs +++ b/test/Kestrel.Tests/WebHostBuilderKestrelExtensionsTests.cs @@ -3,6 +3,9 @@ using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Server.Kestrel.Core; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets; using Microsoft.Extensions.DependencyInjection; using Xunit; @@ -46,5 +49,51 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Tests // Act hostBuilder.Build(); } + + [Fact] + public void LibuvIsTheDefaultTransport() + { + var hostBuilder = new WebHostBuilder() + .UseKestrel() + .Configure(app => { }); + + Assert.IsType(hostBuilder.Build().Services.GetService()); + } + + [Fact] + public void LibuvTransportCanBeManuallySelectedIndependentOfOrder() + { + var hostBuilder = new WebHostBuilder() + .UseKestrel() + .UseLibuv() + .Configure(app => { }); + + Assert.IsType(hostBuilder.Build().Services.GetService()); + + var hostBuilderReversed = new WebHostBuilder() + .UseLibuv() + .UseKestrel() + .Configure(app => { }); + + Assert.IsType(hostBuilderReversed.Build().Services.GetService()); + } + + [Fact] + public void SocketsTransportCanBeManuallySelectedIndependentOfOrder() + { + var hostBuilder = new WebHostBuilder() + .UseKestrel() + .UseSockets() + .Configure(app => { }); + + Assert.IsType(hostBuilder.Build().Services.GetService()); + + var hostBuilderReversed = new WebHostBuilder() + .UseSockets() + .UseKestrel() + .Configure(app => { }); + + Assert.IsType(hostBuilderReversed.Build().Services.GetService()); + } } } From ee1c5c440c8d189e66bf215d95564fd26ddd9a9f Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Tue, 23 Jan 2018 10:58:22 -0800 Subject: [PATCH 1502/1662] Fix HeartbeatTests flakiness (#2268) --- test/Kestrel.Core.Tests/HeartbeatTests.cs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/test/Kestrel.Core.Tests/HeartbeatTests.cs b/test/Kestrel.Core.Tests/HeartbeatTests.cs index 5b961ce7bf..bf80664c6d 100644 --- a/test/Kestrel.Core.Tests/HeartbeatTests.cs +++ b/test/Kestrel.Core.Tests/HeartbeatTests.cs @@ -30,6 +30,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests var kestrelTrace = new Mock(); var handlerMre = new ManualResetEventSlim(); var traceMre = new ManualResetEventSlim(); + var onHeartbeatTasks = new Task[2]; heartbeatHandler.Setup(h => h.OnHeartbeat(systemClock.UtcNow)).Callback(() => handlerMre.Wait()); debugger.Setup(d => d.IsAttached).Returns(false); @@ -37,12 +38,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests using (var heartbeat = new Heartbeat(new[] { heartbeatHandler.Object }, systemClock, debugger.Object, kestrelTrace.Object)) { - Task.Run(() => heartbeat.OnHeartbeat()); - Task.Run(() => heartbeat.OnHeartbeat()); + onHeartbeatTasks[0] = Task.Run(() => heartbeat.OnHeartbeat()); + onHeartbeatTasks[1] = Task.Run(() => heartbeat.OnHeartbeat()); Assert.True(traceMre.Wait(TimeSpan.FromSeconds(10))); } handlerMre.Set(); + Task.WaitAll(onHeartbeatTasks); heartbeatHandler.Verify(h => h.OnHeartbeat(systemClock.UtcNow), Times.Once()); kestrelTrace.Verify(t => t.HeartbeatSlow(Heartbeat.Interval, systemClock.UtcNow), Times.Once()); @@ -57,6 +59,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests var kestrelTrace = new Mock(); var handlerMre = new ManualResetEventSlim(); var traceMre = new ManualResetEventSlim(); + var onHeartbeatTasks = new Task[2]; heartbeatHandler.Setup(h => h.OnHeartbeat(systemClock.UtcNow)).Callback(() => handlerMre.Wait()); debugger.Setup(d => d.IsAttached).Returns(true); @@ -64,12 +67,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests using (var heartbeat = new Heartbeat(new[] { heartbeatHandler.Object }, systemClock, debugger.Object, kestrelTrace.Object)) { - Task.Run(() => heartbeat.OnHeartbeat()); - Task.Run(() => heartbeat.OnHeartbeat()); + onHeartbeatTasks[0] = Task.Run(() => heartbeat.OnHeartbeat()); + onHeartbeatTasks[1] = Task.Run(() => heartbeat.OnHeartbeat()); Assert.False(traceMre.Wait(TimeSpan.FromSeconds(10))); } handlerMre.Set(); + Task.WaitAll(onHeartbeatTasks); heartbeatHandler.Verify(h => h.OnHeartbeat(systemClock.UtcNow), Times.Once()); kestrelTrace.Verify(t => t.HeartbeatSlow(Heartbeat.Interval, systemClock.UtcNow), Times.Never()); From 38bcbb588a79e298797a7d88afcc1d3de7d68a90 Mon Sep 17 00:00:00 2001 From: Pranav K Date: Tue, 23 Jan 2018 15:31:45 -0800 Subject: [PATCH 1503/1662] Branching for 2.1.0-preview1 --- build/dependencies.props | 52 ++++++++++++++++++++-------------------- build/repo.props | 4 ++-- build/sources.props | 4 ++-- korebuild-lock.txt | 4 ++-- 4 files changed, 32 insertions(+), 32 deletions(-) diff --git a/build/dependencies.props b/build/dependencies.props index 6d0c133d98..bf97f3a333 100644 --- a/build/dependencies.props +++ b/build/dependencies.props @@ -5,41 +5,41 @@ 0.10.11 - 2.1.0-preview1-15651 + 2.1.0-preview1-15679 1.10.0 - 2.1.0-preview1-27965 - 2.1.0-preview1-27965 - 2.1.0-preview1-27965 - 2.1.0-preview1-27965 - 2.1.0-preview1-27965 - 2.1.0-preview1-27965 - 2.1.0-preview1-27965 - 2.1.0-preview1-27965 - 2.1.0-preview1-27965 - 2.1.0-preview1-27965 - 2.1.0-preview1-27965 - 2.1.0-preview1-27965 - 2.1.0-preview1-27965 - 2.1.0-preview1-27965 - 2.1.0-preview1-27965 - 2.1.0-preview1-27965 - 2.1.0-preview1-27965 + 2.1.0-preview1-28153 + 2.1.0-preview1-28153 + 2.1.0-preview1-28153 + 2.1.0-preview1-28153 + 2.1.0-preview1-28153 + 2.1.0-preview1-28153 + 2.1.0-preview1-28153 + 2.1.0-preview1-28153 + 2.1.0-preview1-28153 + 2.1.0-preview1-28153 + 2.1.0-preview1-28153 + 2.1.0-preview1-28153 + 2.1.0-preview1-28153 + 2.1.0-preview1-28153 + 2.1.0-preview1-28153 + 2.1.0-preview1-28153 + 2.1.0-preview1-28153 2.0.0 - 2.1.0-preview1-26102-01 - 2.1.0-preview1-27965 + 2.1.0-preview1-26115-03 + 2.1.0-preview1-28153 15.3.0 4.7.49 10.0.1 - 4.5.0-preview1-26102-01 + 4.5.0-preview1-26112-01 0.1.0-e180104-2 0.1.0-e180104-2 0.1.0-e180104-2 - 4.5.0-preview1-26102-01 - 4.5.0-preview1-26102-01 - 4.5.0-preview1-26102-01 - 4.5.0-preview1-26102-01 + 4.5.0-preview1-26112-01 + 4.5.0-preview1-26112-01 + 4.5.0-preview1-26112-01 + 4.5.0-preview1-26112-01 0.1.0-e180104-2 - 4.5.0-preview2-25707-02 + 4.5.0-preview1-26112-01 0.8.0 2.3.1 2.3.1 diff --git a/build/repo.props b/build/repo.props index 2c858d96cf..551c916879 100644 --- a/build/repo.props +++ b/build/repo.props @@ -1,11 +1,11 @@ - + true Internal.AspNetCore.Universe.Lineup - https://dotnet.myget.org/F/aspnetcore-dev/api/v3/index.json + https://dotnet.myget.org/F/aspnetcore-release/api/v3/index.json diff --git a/build/sources.props b/build/sources.props index 181b021f88..4cb921ab02 100644 --- a/build/sources.props +++ b/build/sources.props @@ -1,11 +1,11 @@ - + $(DotNetRestoreSources) $(RestoreSources); - https://dotnet.myget.org/F/aspnetcore-dev/api/v3/index.json; + https://dotnet.myget.org/F/aspnetcore-release/api/v3/index.json; https://dotnet.myget.org/F/aspnetcore-tools/api/v3/index.json; https://dotnet.myget.org/F/roslyn/api/v3/index.json; diff --git a/korebuild-lock.txt b/korebuild-lock.txt index 2146d006d7..a474bc0e35 100644 --- a/korebuild-lock.txt +++ b/korebuild-lock.txt @@ -1,2 +1,2 @@ -version:2.1.0-preview1-15661 -commithash:c9349d4c8a495d3085d9b879214d80f2f45e2193 +version:2.1.0-preview1-15679 +commithash:5347461137cb45a77ddcc0b55b2478092de43338 From 1c0cf15b119c053d8db754fd8688c50655de8ce8 Mon Sep 17 00:00:00 2001 From: Ryan Brandenburg Date: Tue, 23 Jan 2018 16:25:03 -0800 Subject: [PATCH 1504/1662] Add messages to Asserts (#2259) --- test/Kestrel.FunctionalTests/RequestBodyTimeoutTests.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/Kestrel.FunctionalTests/RequestBodyTimeoutTests.cs b/test/Kestrel.FunctionalTests/RequestBodyTimeoutTests.cs index a9593afe79..44c7366067 100644 --- a/test/Kestrel.FunctionalTests/RequestBodyTimeoutTests.cs +++ b/test/Kestrel.FunctionalTests/RequestBodyTimeoutTests.cs @@ -163,9 +163,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests "", ""); - Assert.True(appRunningEvent.Wait(TimeSpan.FromSeconds(10))); + Assert.True(appRunningEvent.Wait(TimeSpan.FromSeconds(10)), "AppRunningEvent timed out."); systemClock.UtcNow += gracePeriod + TimeSpan.FromSeconds(1); - Assert.True(exceptionSwallowedEvent.Wait(TimeSpan.FromSeconds(10))); + Assert.True(exceptionSwallowedEvent.Wait(TimeSpan.FromSeconds(10)), "ExceptionSwallowedEvent timed out."); await connection.Receive( "HTTP/1.1 200 OK", From 4fd4fd9f4140b90734b179ea2fa9ddc9e89b0f69 Mon Sep 17 00:00:00 2001 From: "Chris Ross (ASP.NET)" Date: Mon, 22 Jan 2018 09:22:48 -0800 Subject: [PATCH 1505/1662] Mark HTTP/2 as not supported with an AppContext switch override. --- samples/Http2SampleApp/Program.cs | 4 +++- samples/Http2SampleApp/Startup.cs | 12 +++-------- src/Kestrel.Core/CoreStrings.resx | 3 +++ src/Kestrel.Core/ListenOptions.cs | 21 +++++++++++++++++-- .../Properties/CoreStrings.Designer.cs | 14 +++++++++++++ test/Kestrel.Core.Tests/ListenOptionsTests.cs | 11 ++++++++++ .../HttpProtocolSelectionTests.cs | 12 +++++++++-- 7 files changed, 63 insertions(+), 14 deletions(-) diff --git a/samples/Http2SampleApp/Program.cs b/samples/Http2SampleApp/Program.cs index bdb49b0a50..e95177afe5 100644 --- a/samples/Http2SampleApp/Program.cs +++ b/samples/Http2SampleApp/Program.cs @@ -1,4 +1,4 @@ -using System.Globalization; +using System; using System.IO; using System.Net; using Microsoft.AspNetCore.Hosting; @@ -13,6 +13,8 @@ namespace Http2SampleApp { public static void Main(string[] args) { + AppContext.SetSwitch("Switch.Microsoft.AspNetCore.Server.Kestrel.Experimental.Http2", isEnabled: true); + var hostBuilder = new WebHostBuilder() .ConfigureLogging((_, factory) => { diff --git a/samples/Http2SampleApp/Startup.cs b/samples/Http2SampleApp/Startup.cs index 6dce6b8a19..904e07cbb8 100644 --- a/samples/Http2SampleApp/Startup.cs +++ b/samples/Http2SampleApp/Startup.cs @@ -1,7 +1,3 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; @@ -11,18 +7,16 @@ namespace Http2SampleApp { public class Startup { - // This method gets called by the runtime. Use this method to add services to the container. - // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 + public void ConfigureServices(IServiceCollection services) { } - // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env) { - app.Run(async (context) => + app.Run(context => { - await context.Response.WriteAsync("Hello World!"); + return context.Response.WriteAsync("Hello World! " + context.Request.Protocol); }); } } diff --git a/src/Kestrel.Core/CoreStrings.resx b/src/Kestrel.Core/CoreStrings.resx index 2babfee801..e369a2d122 100644 --- a/src/Kestrel.Core/CoreStrings.resx +++ b/src/Kestrel.Core/CoreStrings.resx @@ -495,4 +495,7 @@ The endpoint {endpointName} specified multiple certificate sources. + + HTTP/2 support is experimental, see https://go.microsoft.com/fwlink/?linkid=866785 to enable it. + \ No newline at end of file diff --git a/src/Kestrel.Core/ListenOptions.cs b/src/Kestrel.Core/ListenOptions.cs index 08e728a35c..0ed675aac8 100644 --- a/src/Kestrel.Core/ListenOptions.cs +++ b/src/Kestrel.Core/ListenOptions.cs @@ -19,13 +19,18 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core /// public class ListenOptions : IEndPointInformation, IConnectionBuilder { + internal const string Http2ExperimentSwitch = "Switch.Microsoft.AspNetCore.Server.Kestrel.Experimental.Http2"; + private FileHandleType _handleType; + private HttpProtocols _protocols = HttpProtocols.Http1; + internal bool _isHttp2Supported; private readonly List> _components = new List>(); internal ListenOptions(IPEndPoint endPoint) { Type = ListenType.IPEndPoint; IPEndPoint = endPoint; + AppContext.TryGetSwitch(Http2ExperimentSwitch, out _isHttp2Supported); } internal ListenOptions(string socketPath) @@ -122,8 +127,20 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core /// /// The protocols enabled on this endpoint. /// - /// Defaults to HTTP/1.x only. - public HttpProtocols Protocols { get; set; } = HttpProtocols.Http1; + /// Defaults to HTTP/1.x only. HTTP/2 support is experimental, see + /// https://go.microsoft.com/fwlink/?linkid=866785 to enable it. + public HttpProtocols Protocols + { + get => _protocols; + set + { + if (!_isHttp2Supported && (value == HttpProtocols.Http1AndHttp2 || value == HttpProtocols.Http2)) + { + throw new NotSupportedException(CoreStrings.Http2NotSupported); + } + _protocols = value; + } + } /// /// Gets the that allows each connection diff --git a/src/Kestrel.Core/Properties/CoreStrings.Designer.cs b/src/Kestrel.Core/Properties/CoreStrings.Designer.cs index ff2732087f..1df67ddf4f 100644 --- a/src/Kestrel.Core/Properties/CoreStrings.Designer.cs +++ b/src/Kestrel.Core/Properties/CoreStrings.Designer.cs @@ -1774,6 +1774,20 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core internal static string FormatMultipleCertificateSources(object endpointName) => string.Format(CultureInfo.CurrentCulture, GetString("MultipleCertificateSources", "endpointName"), endpointName); + /// + /// HTTP/2 support is experimental, see https://go.microsoft.com/fwlink/?linkid=866785 to enable it. + /// + internal static string Http2NotSupported + { + get => GetString("Http2NotSupported"); + } + + /// + /// HTTP/2 support is experimental, see https://go.microsoft.com/fwlink/?linkid=866785 to enable it. + /// + internal static string FormatHttp2NotSupported() + => GetString("Http2NotSupported"); + private static string GetString(string name, params string[] formatterNames) { var value = _resourceManager.GetString(name); diff --git a/test/Kestrel.Core.Tests/ListenOptionsTests.cs b/test/Kestrel.Core.Tests/ListenOptionsTests.cs index 89d495876f..808d4e6cdd 100644 --- a/test/Kestrel.Core.Tests/ListenOptionsTests.cs +++ b/test/Kestrel.Core.Tests/ListenOptionsTests.cs @@ -1,6 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; using System.Net; using Xunit; @@ -14,5 +15,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests var listenOptions = new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0)); Assert.Equal(HttpProtocols.Http1, listenOptions.Protocols); } + + [Fact] + public void Http2DisabledByDefault() + { + var listenOptions = new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0)); + var ex = Assert.Throws(() => listenOptions.Protocols = HttpProtocols.Http1AndHttp2); + Assert.Equal(CoreStrings.Http2NotSupported, ex.Message); + ex = Assert.Throws(() => listenOptions.Protocols = HttpProtocols.Http2); + Assert.Equal(CoreStrings.Http2NotSupported, ex.Message); + } } } diff --git a/test/Kestrel.FunctionalTests/HttpProtocolSelectionTests.cs b/test/Kestrel.FunctionalTests/HttpProtocolSelectionTests.cs index c2dd742c1d..198ba040f3 100644 --- a/test/Kestrel.FunctionalTests/HttpProtocolSelectionTests.cs +++ b/test/Kestrel.FunctionalTests/HttpProtocolSelectionTests.cs @@ -48,7 +48,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests var builder = TransportSelector.GetWebHostBuilder() .UseKestrel(options => { - options.Listen(IPAddress.Loopback, 0, listenOptions => listenOptions.Protocols = serverProtocols); + options.Listen(IPAddress.Loopback, 0, listenOptions => + { + listenOptions._isHttp2Supported = true; + listenOptions.Protocols = serverProtocols; + }); }) .Configure(app => app.Run(context => Task.CompletedTask)); @@ -75,7 +79,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests var builder = TransportSelector.GetWebHostBuilder() .ConfigureLogging(loggingBuilder => loggingBuilder.AddProvider(loggerProvider.Object)) - .UseKestrel(options => options.Listen(IPAddress.Loopback, 0, listenOptions => listenOptions.Protocols = serverProtocols)) + .UseKestrel(options => options.Listen(IPAddress.Loopback, 0, listenOptions => + { + listenOptions._isHttp2Supported = true; + listenOptions.Protocols = serverProtocols; + })) .Configure(app => app.Run(context => Task.CompletedTask)); using (var host = builder.Build()) From 30a68dec4965571a6fc94c425e0b90ba71ff7c9a Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Wed, 24 Jan 2018 17:42:49 -0800 Subject: [PATCH 1506/1662] Fix flakiness in address-in-use test (#2267) * Increase test timeouts * Use constant for default test timeout. --- .../Http1ConnectionTests.cs | 16 ++-- .../Http2ConnectionTests.cs | 8 +- test/Kestrel.Core.Tests/KestrelServerTests.cs | 4 +- test/Kestrel.Core.Tests/MessageBodyTests.cs | 4 +- .../AddressRegistrationTests.cs | 83 +++++++++++++++---- .../ConnectionLimitTests.cs | 8 +- .../EventSourceTests.cs | 2 +- .../HttpConnectionManagerTests.cs | 4 +- .../HttpProtocolSelectionTests.cs | 2 +- test/Kestrel.FunctionalTests/HttpsTests.cs | 10 +-- .../RequestBodyTimeoutTests.cs | 8 +- test/Kestrel.FunctionalTests/RequestTests.cs | 28 +++---- test/Kestrel.FunctionalTests/ResponseTests.cs | 38 ++++----- test/Kestrel.FunctionalTests/UpgradeTests.cs | 12 +-- .../LibuvConnectionTests.cs | 12 +-- .../LibuvOutputConsumerTests.cs | 14 ++-- .../ListenerPrimaryTests.cs | 14 ++-- .../TestHelpers => shared}/TestConstants.cs | 5 +- 18 files changed, 161 insertions(+), 111 deletions(-) rename test/{Kestrel.Transport.Libuv.Tests/TestHelpers => shared}/TestConstants.cs (66%) diff --git a/test/Kestrel.Core.Tests/Http1ConnectionTests.cs b/test/Kestrel.Core.Tests/Http1ConnectionTests.cs index 3c1eba171b..ce197bc7ac 100644 --- a/test/Kestrel.Core.Tests/Http1ConnectionTests.cs +++ b/test/Kestrel.Core.Tests/Http1ConnectionTests.cs @@ -589,7 +589,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests _http1Connection.StopProcessingNextRequest(); Assert.IsNotType>(requestProcessingTask); - await requestProcessingTask.TimeoutAfter(TimeSpan.FromSeconds(10)); + await requestProcessingTask.TimeoutAfter(TestConstants.DefaultTimeout); _application.Output.Complete(); } @@ -713,21 +713,21 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests var requestProcessingTask = _http1Connection.ProcessRequestsAsync(null); await _application.Output.WriteAsync(Encoding.ASCII.GetBytes("GET / HTTP/1.0\r\n")); - await WaitForCondition(TimeSpan.FromSeconds(1), () => _http1Connection.RequestHeaders != null); + await WaitForCondition(TestConstants.DefaultTimeout, () => _http1Connection.RequestHeaders != null); Assert.Equal(0, _http1Connection.RequestHeaders.Count); await _application.Output.WriteAsync(Encoding.ASCII.GetBytes(headers0)); - await WaitForCondition(TimeSpan.FromSeconds(1), () => _http1Connection.RequestHeaders.Count >= header0Count); + await WaitForCondition(TestConstants.DefaultTimeout, () => _http1Connection.RequestHeaders.Count >= header0Count); Assert.Equal(header0Count, _http1Connection.RequestHeaders.Count); await _application.Output.WriteAsync(Encoding.ASCII.GetBytes(headers1)); - await WaitForCondition(TimeSpan.FromSeconds(1), () => _http1Connection.RequestHeaders.Count >= header0Count + header1Count); + await WaitForCondition(TestConstants.DefaultTimeout, () => _http1Connection.RequestHeaders.Count >= header0Count + header1Count); Assert.Equal(header0Count + header1Count, _http1Connection.RequestHeaders.Count); await _application.Output.WriteAsync(Encoding.ASCII.GetBytes("\r\n")); Assert.Equal(header0Count + header1Count, _http1Connection.RequestHeaders.Count); - await requestProcessingTask.TimeoutAfter(TimeSpan.FromSeconds(10)); + await requestProcessingTask.TimeoutAfter(TestConstants.DefaultTimeout); } [Theory] @@ -747,7 +747,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests var requestProcessingTask = _http1Connection.ProcessRequestsAsync(null); await _application.Output.WriteAsync(Encoding.ASCII.GetBytes("GET / HTTP/1.0\r\n")); - await WaitForCondition(TimeSpan.FromSeconds(1), () => _http1Connection.RequestHeaders != null); + await WaitForCondition(TestConstants.DefaultTimeout, () => _http1Connection.RequestHeaders != null); Assert.Equal(0, _http1Connection.RequestHeaders.Count); var newRequestHeaders = new RequestHeadersWrapper(_http1Connection.RequestHeaders); @@ -755,12 +755,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests Assert.Same(newRequestHeaders, _http1Connection.RequestHeaders); await _application.Output.WriteAsync(Encoding.ASCII.GetBytes(headers0)); - await WaitForCondition(TimeSpan.FromSeconds(1), () => _http1Connection.RequestHeaders.Count >= header0Count); + await WaitForCondition(TestConstants.DefaultTimeout, () => _http1Connection.RequestHeaders.Count >= header0Count); Assert.Same(newRequestHeaders, _http1Connection.RequestHeaders); Assert.Equal(header0Count, _http1Connection.RequestHeaders.Count); await _application.Output.WriteAsync(Encoding.ASCII.GetBytes(headers1)); - await WaitForCondition(TimeSpan.FromSeconds(1), () => _http1Connection.RequestHeaders.Count >= header0Count + header1Count); + await WaitForCondition(TestConstants.DefaultTimeout, () => _http1Connection.RequestHeaders.Count >= header0Count + header1Count); Assert.Same(newRequestHeaders, _http1Connection.RequestHeaders); Assert.Equal(header0Count + header1Count, _http1Connection.RequestHeaders.Count); diff --git a/test/Kestrel.Core.Tests/Http2ConnectionTests.cs b/test/Kestrel.Core.Tests/Http2ConnectionTests.cs index a9976e08fb..24e08b3b7c 100644 --- a/test/Kestrel.Core.Tests/Http2ConnectionTests.cs +++ b/test/Kestrel.Core.Tests/Http2ConnectionTests.cs @@ -192,7 +192,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests sem.Release(); }); - await sem.WaitAsync().TimeoutAfter(TimeSpan.FromSeconds(10)); + await sem.WaitAsync().TimeoutAfter(TestConstants.DefaultTimeout); }; _largeHeadersApplication = context => @@ -220,7 +220,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests sem.Release(); }); - await sem.WaitAsync().TimeoutAfter(TimeSpan.FromSeconds(10)); + await sem.WaitAsync().TimeoutAfter(TestConstants.DefaultTimeout); _runningStreams[streamIdFeature.StreamId].TrySetResult(null); }; @@ -240,7 +240,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests sem.Release(); }); - await sem.WaitAsync().TimeoutAfter(TimeSpan.FromSeconds(10)); + await sem.WaitAsync().TimeoutAfter(TestConstants.DefaultTimeout); await context.Response.Body.FlushAsync(); @@ -2133,7 +2133,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests private Task WaitForAllStreamsAsync() { - return Task.WhenAll(_runningStreams.Values.Select(tcs => tcs.Task)).TimeoutAfter(TimeSpan.FromSeconds(30)); + return Task.WhenAll(_runningStreams.Values.Select(tcs => tcs.Task)).TimeoutAfter(TestConstants.DefaultTimeout); } private async Task SendAsync(ArraySegment span) diff --git a/test/Kestrel.Core.Tests/KestrelServerTests.cs b/test/Kestrel.Core.Tests/KestrelServerTests.cs index ab9015cf5f..fefd6bce51 100644 --- a/test/Kestrel.Core.Tests/KestrelServerTests.cs +++ b/test/Kestrel.Core.Tests/KestrelServerTests.cs @@ -261,7 +261,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests unbind.Release(); stop.Release(); - await Task.WhenAll(new[] { stopTask1, stopTask2, stopTask3 }).TimeoutAfter(TimeSpan.FromSeconds(10)); + await Task.WhenAll(new[] { stopTask1, stopTask2, stopTask3 }).TimeoutAfter(TestConstants.DefaultTimeout); mockTransport.Verify(transport => transport.UnbindAsync(), Times.Once); mockTransport.Verify(transport => transport.StopAsync(), Times.Once); @@ -317,7 +317,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests unbind.Release(); - var timeout = TimeSpan.FromSeconds(10); + var timeout = TestConstants.DefaultTimeout; Assert.Same(unbindException, await Assert.ThrowsAsync(() => stopTask1.TimeoutAfter(timeout))); Assert.Same(unbindException, await Assert.ThrowsAsync(() => stopTask2.TimeoutAfter(timeout))); Assert.Same(unbindException, await Assert.ThrowsAsync(() => stopTask3.TimeoutAfter(timeout))); diff --git a/test/Kestrel.Core.Tests/MessageBodyTests.cs b/test/Kestrel.Core.Tests/MessageBodyTests.cs index 9fa5b6ef1a..3895a46fd4 100644 --- a/test/Kestrel.Core.Tests/MessageBodyTests.cs +++ b/test/Kestrel.Core.Tests/MessageBodyTests.cs @@ -147,7 +147,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests input.Add("\r\r\r\nHello\r\n0\r\n\r\n"); - Assert.Equal(5, await readTask.TimeoutAfter(TimeSpan.FromSeconds(10))); + Assert.Equal(5, await readTask.TimeoutAfter(TestConstants.DefaultTimeout)); Assert.Equal(0, await stream.ReadAsync(buffer, 0, buffer.Length)); await body.StopAsync(); @@ -704,7 +704,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests input.Fin(); - Assert.True(logEvent.Wait(TimeSpan.FromSeconds(10))); + Assert.True(logEvent.Wait(TestConstants.DefaultTimeout)); await body.StopAsync(); } diff --git a/test/Kestrel.FunctionalTests/AddressRegistrationTests.cs b/test/Kestrel.FunctionalTests/AddressRegistrationTests.cs index b5a0859c36..9e83cde243 100644 --- a/test/Kestrel.FunctionalTests/AddressRegistrationTests.cs +++ b/test/Kestrel.FunctionalTests/AddressRegistrationTests.cs @@ -618,14 +618,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [Fact] public void ThrowsWhenBindingLocalhostToIPv4AddressInUse() { - ThrowsWhenBindingLocalhostToAddressInUse(AddressFamily.InterNetwork, IPAddress.Loopback); + ThrowsWhenBindingLocalhostToAddressInUse(AddressFamily.InterNetwork); } [ConditionalFact] [IPv6SupportedCondition] public void ThrowsWhenBindingLocalhostToIPv6AddressInUse() { - ThrowsWhenBindingLocalhostToAddressInUse(AddressFamily.InterNetworkV6, IPAddress.IPv6Loopback); + ThrowsWhenBindingLocalhostToAddressInUse(AddressFamily.InterNetworkV6); } [Fact] @@ -738,27 +738,74 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } } - private void ThrowsWhenBindingLocalhostToAddressInUse(AddressFamily addressFamily, IPAddress address) + private void ThrowsWhenBindingLocalhostToAddressInUse(AddressFamily addressFamily) { - using (var socket = new Socket(addressFamily, SocketType.Stream, ProtocolType.Tcp)) + var addressInUseCount = 0; + var wrongMessageCount = 0; + + var address = addressFamily == AddressFamily.InterNetwork ? IPAddress.Loopback : IPAddress.IPv6Loopback; + var otherAddressFamily = addressFamily == AddressFamily.InterNetwork ? AddressFamily.InterNetworkV6 : AddressFamily.InterNetwork; + + while (addressInUseCount < 10 && wrongMessageCount < 10) { - socket.Bind(new IPEndPoint(address, 0)); - socket.Listen(0); - var port = ((IPEndPoint)socket.LocalEndPoint).Port; + int port; - var hostBuilder = TransportSelector.GetWebHostBuilder() - .ConfigureLogging(_configureLoggingDelegate) - .UseKestrel() - .UseUrls($"http://localhost:{port}") - .Configure(ConfigureEchoAddress); - - using (var host = hostBuilder.Build()) + using (var socket = new Socket(AddressFamily.InterNetworkV6, SocketType.Stream, ProtocolType.Tcp)) { - var exception = Assert.Throws(() => host.Start()); - Assert.Equal( - CoreStrings.FormatEndpointAlreadyInUse($"http://{(addressFamily == AddressFamily.InterNetwork ? "127.0.0.1" : "[::1]")}:{port}"), - exception.Message); + // Bind first to IPv6Any to ensure both the IPv4 and IPv6 ports are avaiable. + socket.Bind(new IPEndPoint(IPAddress.IPv6Any, 0)); + socket.Listen(0); + port = ((IPEndPoint)socket.LocalEndPoint).Port; } + + using (var socket = new Socket(addressFamily, SocketType.Stream, ProtocolType.Tcp)) + { + try + { + socket.Bind(new IPEndPoint(address, port)); + socket.Listen(0); + } + catch (SocketException) + { + addressInUseCount++; + continue; + } + + var hostBuilder = TransportSelector.GetWebHostBuilder() + .ConfigureLogging(_configureLoggingDelegate) + .UseKestrel() + .UseUrls($"http://localhost:{port}") + .Configure(ConfigureEchoAddress); + + using (var host = hostBuilder.Build()) + { + var exception = Assert.Throws(() => host.Start()); + + var thisAddressString = $"http://{(addressFamily == AddressFamily.InterNetwork ? "127.0.0.1" : "[::1]")}:{port}"; + var otherAddressString = $"http://{(addressFamily == AddressFamily.InterNetworkV6? "127.0.0.1" : "[::1]")}:{port}"; + + if (exception.Message == CoreStrings.FormatEndpointAlreadyInUse(otherAddressString)) + { + // Don't fail immediately, because it's possible that something else really did bind to the + // same port for the other address family between the IPv6Any bind above and now. + wrongMessageCount++; + continue; + } + + Assert.Equal(CoreStrings.FormatEndpointAlreadyInUse(thisAddressString), exception.Message); + break; + } + } + } + + if (addressInUseCount >= 10) + { + Assert.True(false, $"The corresponding {otherAddressFamily} address was already in use 10 times."); + } + + if (wrongMessageCount >= 10) + { + Assert.True(false, $"An error for a conflict with {otherAddressFamily} was thrown 10 times."); } } diff --git a/test/Kestrel.FunctionalTests/ConnectionLimitTests.cs b/test/Kestrel.FunctionalTests/ConnectionLimitTests.cs index 49c1e7ab63..5ed40564ab 100644 --- a/test/Kestrel.FunctionalTests/ConnectionLimitTests.cs +++ b/test/Kestrel.FunctionalTests/ConnectionLimitTests.cs @@ -37,11 +37,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { await connection.SendEmptyGetAsKeepAlive(); ; await connection.Receive("HTTP/1.1 200 OK"); - Assert.True(await lockedTcs.Task.TimeoutAfter(TimeSpan.FromSeconds(10))); + Assert.True(await lockedTcs.Task.TimeoutAfter(TestConstants.DefaultTimeout)); requestTcs.TrySetResult(null); } - await releasedTcs.Task.TimeoutAfter(TimeSpan.FromSeconds(10)); + await releasedTcs.Task.TimeoutAfter(TestConstants.DefaultTimeout); } [Fact] @@ -85,7 +85,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests catch { } // connection should close without sending any data - await rejected.WaitForConnectionClose().TimeoutAfter(TimeSpan.FromSeconds(15)); + await rejected.WaitForConnectionClose().TimeoutAfter(TestConstants.DefaultTimeout); } } } @@ -124,7 +124,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } catch { } // connection should close without sending any data - await connection.WaitForConnectionClose().TimeoutAfter(TimeSpan.FromSeconds(15)); + await connection.WaitForConnectionClose().TimeoutAfter(TestConstants.DefaultTimeout); } } diff --git a/test/Kestrel.FunctionalTests/EventSourceTests.cs b/test/Kestrel.FunctionalTests/EventSourceTests.cs index 639e8d5153..1d99ade358 100644 --- a/test/Kestrel.FunctionalTests/EventSourceTests.cs +++ b/test/Kestrel.FunctionalTests/EventSourceTests.cs @@ -43,7 +43,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests "Host:", "", "") - .TimeoutAfter(TimeSpan.FromSeconds(10)); + .TimeoutAfter(TestConstants.DefaultTimeout); await connection.Receive("HTTP/1.1 200"); } } diff --git a/test/Kestrel.FunctionalTests/HttpConnectionManagerTests.cs b/test/Kestrel.FunctionalTests/HttpConnectionManagerTests.cs index 50c5181b4e..f0df336587 100644 --- a/test/Kestrel.FunctionalTests/HttpConnectionManagerTests.cs +++ b/test/Kestrel.FunctionalTests/HttpConnectionManagerTests.cs @@ -50,14 +50,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { await connection.SendEmptyGet(); - Assert.True(await appStartedWh.WaitAsync(TimeSpan.FromSeconds(10))); + Assert.True(await appStartedWh.WaitAsync(TestConstants.DefaultTimeout)); // Close connection without waiting for a response } var logWaitAttempts = 0; - for (; !await logWh.WaitAsync(TimeSpan.FromSeconds(1)) && logWaitAttempts < 10; logWaitAttempts++) + for (; !await logWh.WaitAsync(TimeSpan.FromSeconds(1)) && logWaitAttempts < 30; logWaitAttempts++) { GC.Collect(); GC.WaitForPendingFinalizers(); diff --git a/test/Kestrel.FunctionalTests/HttpProtocolSelectionTests.cs b/test/Kestrel.FunctionalTests/HttpProtocolSelectionTests.cs index 198ba040f3..e74c148218 100644 --- a/test/Kestrel.FunctionalTests/HttpProtocolSelectionTests.cs +++ b/test/Kestrel.FunctionalTests/HttpProtocolSelectionTests.cs @@ -92,7 +92,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests using (var connection = new TestConnection(host.GetPort())) { - await connection.WaitForConnectionClose().TimeoutAfter(TimeSpan.FromSeconds(30)); + await connection.WaitForConnectionClose().TimeoutAfter(TestConstants.DefaultTimeout); } } diff --git a/test/Kestrel.FunctionalTests/HttpsTests.cs b/test/Kestrel.FunctionalTests/HttpsTests.cs index 86403b11b5..24959f9c7f 100644 --- a/test/Kestrel.FunctionalTests/HttpsTests.cs +++ b/test/Kestrel.FunctionalTests/HttpsTests.cs @@ -108,7 +108,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests // Close socket immediately } - await loggerProvider.FilterLogger.LogTcs.Task.TimeoutAfter(TimeSpan.FromSeconds(10)); + await loggerProvider.FilterLogger.LogTcs.Task.TimeoutAfter(TestConstants.DefaultTimeout); } Assert.Equal(1, loggerProvider.FilterLogger.LastEventId.Id); @@ -144,7 +144,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests await stream.WriteAsync(new byte[10], 0, 10); } - await loggerProvider.FilterLogger.LogTcs.Task.TimeoutAfter(TimeSpan.FromSeconds(10)); + await loggerProvider.FilterLogger.LogTcs.Task.TimeoutAfter(TestConstants.DefaultTimeout); } Assert.Equal(1, loggerProvider.FilterLogger.LastEventId.Id); @@ -251,7 +251,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } } - await tcs.Task.TimeoutAfter(TimeSpan.FromSeconds(10)); + await tcs.Task.TimeoutAfter(TestConstants.DefaultTimeout); } // Regression test for https://github.com/aspnet/KestrelHttpServer/issues/1693 @@ -345,11 +345,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests using (var stream = new NetworkStream(socket, ownsSocket: false)) { // No data should be sent and the connection should be closed in well under 30 seconds. - Assert.Equal(0, await stream.ReadAsync(new byte[1], 0, 1).TimeoutAfter(TimeSpan.FromSeconds(30))); + Assert.Equal(0, await stream.ReadAsync(new byte[1], 0, 1).TimeoutAfter(TestConstants.DefaultTimeout)); } } - await loggerProvider.FilterLogger.LogTcs.Task.TimeoutAfter(TimeSpan.FromSeconds(10)); + await loggerProvider.FilterLogger.LogTcs.Task.TimeoutAfter(TestConstants.DefaultTimeout); Assert.Equal(2, loggerProvider.FilterLogger.LastEventId); Assert.Equal(LogLevel.Information, loggerProvider.FilterLogger.LastLogLevel); } diff --git a/test/Kestrel.FunctionalTests/RequestBodyTimeoutTests.cs b/test/Kestrel.FunctionalTests/RequestBodyTimeoutTests.cs index 44c7366067..2e162bd7a0 100644 --- a/test/Kestrel.FunctionalTests/RequestBodyTimeoutTests.cs +++ b/test/Kestrel.FunctionalTests/RequestBodyTimeoutTests.cs @@ -50,7 +50,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests "", ""); - Assert.True(appRunningEvent.Wait(TimeSpan.FromSeconds(10))); + Assert.True(appRunningEvent.Wait(TestConstants.DefaultTimeout)); systemClock.UtcNow += gracePeriod + TimeSpan.FromSeconds(1); await connection.Receive( @@ -100,7 +100,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests "", ""); - Assert.True(appRunningEvent.Wait(TimeSpan.FromSeconds(10))); + Assert.True(appRunningEvent.Wait(TestConstants.DefaultTimeout)); await connection.Receive( "HTTP/1.1 200 OK", @@ -163,9 +163,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests "", ""); - Assert.True(appRunningEvent.Wait(TimeSpan.FromSeconds(10)), "AppRunningEvent timed out."); + Assert.True(appRunningEvent.Wait(TestConstants.DefaultTimeout), "AppRunningEvent timed out."); systemClock.UtcNow += gracePeriod + TimeSpan.FromSeconds(1); - Assert.True(exceptionSwallowedEvent.Wait(TimeSpan.FromSeconds(10)), "ExceptionSwallowedEvent timed out."); + Assert.True(exceptionSwallowedEvent.Wait(TestConstants.DefaultTimeout), "ExceptionSwallowedEvent timed out."); await connection.Receive( "HTTP/1.1 200 OK", diff --git a/test/Kestrel.FunctionalTests/RequestTests.cs b/test/Kestrel.FunctionalTests/RequestTests.cs index 46933f4275..504a93104d 100644 --- a/test/Kestrel.FunctionalTests/RequestTests.cs +++ b/test/Kestrel.FunctionalTests/RequestTests.cs @@ -310,7 +310,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests using (var connection = server.CreateConnection()) { // Wait until connection is established - Assert.True(await connectionStarted.WaitAsync(TimeSpan.FromSeconds(10))); + Assert.True(await connectionStarted.WaitAsync(TestConstants.DefaultTimeout)); // Force a reset connection.Socket.LingerState = new LingerOption(true, 0); @@ -320,7 +320,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests // This check MUST come before disposing the server, otherwise there's a race where the RST // is still in flight when the connection is aborted, leading to the reset never being received // and therefore not logged. - Assert.True(await connectionReset.WaitAsync(TimeSpan.FromSeconds(10))); + Assert.True(await connectionReset.WaitAsync(TestConstants.DefaultTimeout)); } Assert.False(loggedHigherThanDebug); @@ -388,7 +388,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests // This check MUST come before disposing the server, otherwise there's a race where the RST // is still in flight when the connection is aborted, leading to the reset never being received // and therefore not logged. - Assert.True(await connectionReset.WaitAsync(TimeSpan.FromSeconds(10))); + Assert.True(await connectionReset.WaitAsync(TestConstants.DefaultTimeout)); } Assert.False(loggedHigherThanDebug); @@ -445,7 +445,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests await connection.SendEmptyGet(); // Wait until connection is established - Assert.True(await requestStarted.WaitAsync(TimeSpan.FromSeconds(30)), "request should have started"); + Assert.True(await requestStarted.WaitAsync(TestConstants.DefaultTimeout), "request should have started"); // Force a reset connection.Socket.LingerState = new LingerOption(true, 0); @@ -455,7 +455,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests // This check MUST come before disposing the server, otherwise there's a race where the RST // is still in flight when the connection is aborted, leading to the reset never being received // and therefore not logged. - Assert.True(await connectionReset.WaitAsync(TimeSpan.FromSeconds(30)), "Connection reset event should have been logged"); + Assert.True(await connectionReset.WaitAsync(TestConstants.DefaultTimeout), "Connection reset event should have been logged"); connectionClosing.Release(); } @@ -523,7 +523,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests var token = context.RequestAborted; token.Register(() => requestAborted.Release(2)); - await requestAborted.WaitAsync().TimeoutAfter(TimeSpan.FromSeconds(10)); + await requestAborted.WaitAsync().TimeoutAfter(TestConstants.DefaultTimeout); })); using (var host = builder.Build()) @@ -536,7 +536,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests socket.Send(Encoding.ASCII.GetBytes("GET / HTTP/1.1\r\nHost:\r\n\r\n")); await appStarted.WaitAsync(); socket.Shutdown(SocketShutdown.Send); - await requestAborted.WaitAsync().TimeoutAfter(TimeSpan.FromSeconds(10)); + await requestAborted.WaitAsync().TimeoutAfter(TestConstants.DefaultTimeout); } } } @@ -620,9 +620,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests "", "4", "Done") - .TimeoutAfter(TimeSpan.FromSeconds(10)); + .TimeoutAfter(TestConstants.DefaultTimeout); - await Task.WhenAll(pathTcs.Task, rawTargetTcs.Task, queryTcs.Task).TimeoutAfter(TimeSpan.FromSeconds(30)); + await Task.WhenAll(pathTcs.Task, rawTargetTcs.Task, queryTcs.Task).TimeoutAfter(TestConstants.DefaultTimeout); Assert.Equal(new PathString(expectedPath), pathTcs.Task.Result); Assert.Equal(requestUrl, rawTargetTcs.Task.Result); if (queryValue == null) @@ -648,7 +648,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests })) { var requestId = await HttpClientSlim.GetStringAsync($"http://{server.EndPoint}") - .TimeoutAfter(TimeSpan.FromSeconds(10)); + .TimeoutAfter(TestConstants.DefaultTimeout); Assert.Equal(knownId, requestId); } } @@ -689,7 +689,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests $"Date: {server.Context.DateHeaderValue}", $"Content-Length: {identifierLength}", "", - "").TimeoutAfter(TimeSpan.FromSeconds(10)); + "").TimeoutAfter(TestConstants.DefaultTimeout); var read = await connection.Reader.ReadAsync(buffer, 0, identifierLength); Assert.Equal(identifierLength, read); @@ -950,7 +950,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests using (var server = new TestServer(async httpContext => { // This will hang if 0 content length is not assumed by the server - Assert.Equal(0, await httpContext.Request.Body.ReadAsync(new byte[1], 0, 1).TimeoutAfter(TimeSpan.FromSeconds(10))); + Assert.Equal(0, await httpContext.Request.Body.ReadAsync(new byte[1], 0, 1).TimeoutAfter(TestConstants.DefaultTimeout)); }, testContext, listenOptions)) { using (var connection = server.CreateConnection()) @@ -1169,7 +1169,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests var read = 0; while (read < message.Length) { - read += await duplexStream.ReadAsync(buffer, read, buffer.Length - read).TimeoutAfter(TimeSpan.FromSeconds(10)); + read += await duplexStream.ReadAsync(buffer, read, buffer.Length - read).TimeoutAfter(TestConstants.DefaultTimeout); } await duplexStream.WriteAsync(buffer, 0, read); @@ -1476,7 +1476,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests "", "a"); - Assert.True(appEvent.Wait(TimeSpan.FromSeconds(10))); + Assert.True(appEvent.Wait(TestConstants.DefaultTimeout)); await Task.Delay(TimeSpan.FromSeconds(5)); diff --git a/test/Kestrel.FunctionalTests/ResponseTests.cs b/test/Kestrel.FunctionalTests/ResponseTests.cs index a43f9cb746..40dad103ba 100644 --- a/test/Kestrel.FunctionalTests/ResponseTests.cs +++ b/test/Kestrel.FunctionalTests/ResponseTests.cs @@ -368,7 +368,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } } - var disposedStatusCode = await disposedTcs.Task.TimeoutAfter(TimeSpan.FromSeconds(10)); + var disposedStatusCode = await disposedTcs.Task.TimeoutAfter(TestConstants.DefaultTimeout); Assert.Equal(expectedServerStatusCode, (HttpStatusCode)disposedStatusCode); } @@ -538,7 +538,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests // Wait for message to be logged before disposing the socket. // Disposing the socket will abort the connection and HttpProtocol._requestAborted // might be 1 by the time ProduceEnd() gets called and the message is logged. - await logTcs.Task.TimeoutAfter(TimeSpan.FromSeconds(10)); + await logTcs.Task.TimeoutAfter(TestConstants.DefaultTimeout); } } @@ -578,7 +578,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests "", "hello,"); - await connection.WaitForConnectionClose().TimeoutAfter(TimeSpan.FromSeconds(30)); + await connection.WaitForConnectionClose().TimeoutAfter(TestConstants.DefaultTimeout); } } @@ -740,10 +740,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests "hello, world"); // Wait for error message to be logged. - await logTcs.Task.TimeoutAfter(TimeSpan.FromSeconds(10)); + await logTcs.Task.TimeoutAfter(TestConstants.DefaultTimeout); // The server should close the connection in this situation. - await connection.WaitForConnectionClose().TimeoutAfter(TimeSpan.FromSeconds(10)); + await connection.WaitForConnectionClose().TimeoutAfter(TestConstants.DefaultTimeout); } } @@ -772,7 +772,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests await httpContext.Response.WriteAsync("hello,"); // Wait until the request is aborted so we know HttpProtocol will skip the response content length check. - Assert.True(await requestAborted.WaitAsync(TimeSpan.FromSeconds(10))); + Assert.True(await requestAborted.WaitAsync(TestConstants.DefaultTimeout)); }, new TestServiceContext { Log = mockTrace.Object })) { using (var connection = server.CreateConnection()) @@ -796,7 +796,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests // Await before disposing the server to prevent races between the // abort triggered by the connection RST and the abort called when // disposing the server. - Assert.True(await requestAborted.WaitAsync(TimeSpan.FromSeconds(10))); + Assert.True(await requestAborted.WaitAsync(TestConstants.DefaultTimeout)); } // With the server disposed we know all connections were drained and all messages were logged. @@ -1111,12 +1111,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests requestStarted.Wait(); connection.Shutdown(SocketShutdown.Send); - await connection.WaitForConnectionClose().TimeoutAfter(TimeSpan.FromSeconds(30)); + await connection.WaitForConnectionClose().TimeoutAfter(TestConstants.DefaultTimeout); } connectionClosed.Set(); - await tcs.Task.TimeoutAfter(TimeSpan.FromSeconds(30)); + await tcs.Task.TimeoutAfter(TestConstants.DefaultTimeout); } } @@ -1150,7 +1150,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests "Transfer-Encoding: chunked", "", "gg"); - await responseWritten.WaitAsync().TimeoutAfter(TimeSpan.FromSeconds(30)); + await responseWritten.WaitAsync().TimeoutAfter(TestConstants.DefaultTimeout); await connection.ReceiveEnd( "HTTP/1.1 400 Bad Request", $"Date: {server.Context.DateHeaderValue}", @@ -1706,7 +1706,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests using (var server = new TestServer(async httpContext => { - Assert.Equal(0, await httpContext.Request.Body.ReadAsync(new byte[1], 0, 1).TimeoutAfter(TimeSpan.FromSeconds(10))); + Assert.Equal(0, await httpContext.Request.Body.ReadAsync(new byte[1], 0, 1).TimeoutAfter(TestConstants.DefaultTimeout)); }, testContext, listenOptions)) { using (var connection = server.CreateConnection()) @@ -2152,7 +2152,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests var lifetime = httpContext.Features.Get(); lifetime.RequestAborted.Register(() => requestAbortedWh.Set()); - Assert.True(requestAbortedWh.Wait(TimeSpan.FromSeconds(10))); + Assert.True(requestAbortedWh.Wait(TestConstants.DefaultTimeout)); try { @@ -2176,15 +2176,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests "", ""); - Assert.True(requestStartWh.Wait(TimeSpan.FromSeconds(10))); + Assert.True(requestStartWh.Wait(TestConstants.DefaultTimeout)); } // Write failed - can throw TaskCanceledException or OperationCanceledException, // dependending on how far the canceled write goes. - await Assert.ThrowsAnyAsync(async () => await writeTcs.Task).TimeoutAfter(TimeSpan.FromSeconds(15)); + await Assert.ThrowsAnyAsync(async () => await writeTcs.Task).TimeoutAfter(TestConstants.DefaultTimeout); // RequestAborted tripped - Assert.True(requestAbortedWh.Wait(TimeSpan.FromSeconds(1))); + Assert.True(requestAbortedWh.Wait(TestConstants.DefaultTimeout)); } } @@ -2342,7 +2342,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests "hello, world"); // Wait for all callbacks to be called. - await onStartingTcs.Task.TimeoutAfter(TimeSpan.FromSeconds(10)); + await onStartingTcs.Task.TimeoutAfter(TestConstants.DefaultTimeout); } } @@ -2394,7 +2394,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests "hello, world"); // Wait for all callbacks to be called. - await onCompletedTcs.Task.TimeoutAfter(TimeSpan.FromSeconds(10)); + await onCompletedTcs.Task.TimeoutAfter(TestConstants.DefaultTimeout); } } @@ -2654,10 +2654,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests using (var reader = new StreamReader(sslStream, encoding: Encoding.ASCII, detectEncodingFromByteOrderMarks: false, bufferSize: 1024, leaveOpen: false)) { - await reader.ReadToEndAsync().TimeoutAfter(TimeSpan.FromSeconds(30)); + await reader.ReadToEndAsync().TimeoutAfter(TestConstants.DefaultTimeout); } - Assert.True(messageLogged.Wait(TimeSpan.FromSeconds(10))); + Assert.True(messageLogged.Wait(TestConstants.DefaultTimeout)); } } } diff --git a/test/Kestrel.FunctionalTests/UpgradeTests.cs b/test/Kestrel.FunctionalTests/UpgradeTests.cs index 6d77b7758b..8b37add35f 100644 --- a/test/Kestrel.FunctionalTests/UpgradeTests.cs +++ b/test/Kestrel.FunctionalTests/UpgradeTests.cs @@ -54,7 +54,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests ""); await connection.Receive("New protocol data"); - await upgrade.Task.TimeoutAfter(TimeSpan.FromSeconds(30)); + await upgrade.Task.TimeoutAfter(TestConstants.DefaultTimeout); } } } @@ -74,7 +74,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests var stream = await feature.UpgradeAsync(); var buffer = new byte[128]; - var read = await context.Request.Body.ReadAsync(buffer, 0, 128).TimeoutAfter(TimeSpan.FromSeconds(10)); + var read = await context.Request.Body.ReadAsync(buffer, 0, 128).TimeoutAfter(TestConstants.DefaultTimeout); Assert.Equal(0, read); using (var reader = new StreamReader(stream)) @@ -108,7 +108,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests await connection.Send(send + "\r\n"); await connection.Receive(recv); - await upgrade.Task.TimeoutAfter(TimeSpan.FromSeconds(30)); + await upgrade.Task.TimeoutAfter(TestConstants.DefaultTimeout); } } } @@ -145,10 +145,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests $"Date: {server.Context.DateHeaderValue}", "", ""); - await connection.WaitForConnectionClose().TimeoutAfter(TimeSpan.FromSeconds(15)); + await connection.WaitForConnectionClose().TimeoutAfter(TestConstants.DefaultTimeout); } - var ex = await Assert.ThrowsAsync(async () => await upgradeTcs.Task.TimeoutAfter(TimeSpan.FromSeconds(15))); + var ex = await Assert.ThrowsAsync(async () => await upgradeTcs.Task.TimeoutAfter(TestConstants.DefaultTimeout)); Assert.Equal(CoreStrings.UpgradeCannotBeCalledMultipleTimes, ex.Message); } @@ -250,7 +250,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } } - var ex = await Assert.ThrowsAsync(async () => await upgradeTcs.Task).TimeoutAfter(TimeSpan.FromSeconds(15)); + var ex = await Assert.ThrowsAsync(async () => await upgradeTcs.Task).TimeoutAfter(TestConstants.DefaultTimeout); Assert.Equal(CoreStrings.CannotUpgradeNonUpgradableRequest, ex.Message); } diff --git a/test/Kestrel.Transport.Libuv.Tests/LibuvConnectionTests.cs b/test/Kestrel.Transport.Libuv.Tests/LibuvConnectionTests.cs index 4c79bddf19..a68039898a 100644 --- a/test/Kestrel.Transport.Libuv.Tests/LibuvConnectionTests.cs +++ b/test/Kestrel.Transport.Libuv.Tests/LibuvConnectionTests.cs @@ -47,7 +47,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests } finally { - await thread.StopAsync(TimeSpan.FromSeconds(1)); + await thread.StopAsync(TimeSpan.FromSeconds(5)); } } @@ -97,7 +97,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests // Now complete the output writer so that the connection closes mockConnectionHandler.Output.Writer.Complete(); - await connectionTask.TimeoutAfter(TimeSpan.FromSeconds(10)); + await connectionTask.TimeoutAfter(TestConstants.DefaultTimeout); // Assert that we don't try to start reading Assert.Null(mockLibuv.AllocCallback); @@ -105,7 +105,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests } finally { - await thread.StopAsync(TimeSpan.FromSeconds(1)); + await thread.StopAsync(TimeSpan.FromSeconds(5)); } } @@ -176,7 +176,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests // Now complete the output writer and wait for the connection to close mockConnectionHandler.Output.Writer.Complete(); - await connectionTask.TimeoutAfter(TimeSpan.FromSeconds(10)); + await connectionTask.TimeoutAfter(TestConstants.DefaultTimeout); // Assert that we don't try to start reading Assert.Null(mockLibuv.AllocCallback); @@ -184,7 +184,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests } finally { - await thread.StopAsync(TimeSpan.FromSeconds(1)); + await thread.StopAsync(TimeSpan.FromSeconds(5)); } } @@ -219,7 +219,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests } finally { - await thread.StopAsync(TimeSpan.FromSeconds(1)); + await thread.StopAsync(TimeSpan.FromSeconds(5)); } } } diff --git a/test/Kestrel.Transport.Libuv.Tests/LibuvOutputConsumerTests.cs b/test/Kestrel.Transport.Libuv.Tests/LibuvOutputConsumerTests.cs index 06576890d4..c0d0e6a7d5 100644 --- a/test/Kestrel.Transport.Libuv.Tests/LibuvOutputConsumerTests.cs +++ b/test/Kestrel.Transport.Libuv.Tests/LibuvOutputConsumerTests.cs @@ -48,7 +48,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests public void Dispose() { - _libuvThread.StopAsync(TimeSpan.FromSeconds(1)).Wait(); + _libuvThread.StopAsync(TimeSpan.FromSeconds(5)).Wait(); _memoryPool.Dispose(); } @@ -80,7 +80,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests var writeTask = outputProducer.WriteDataAsync(buffer); // Assert - await writeTask.TimeoutAfter(TimeSpan.FromSeconds(5)); + await writeTask.TimeoutAfter(TestConstants.DefaultTimeout); } } @@ -116,7 +116,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests var writeTask = outputProducer.WriteDataAsync(buffer); // Assert - await writeTask.TimeoutAfter(TimeSpan.FromSeconds(5)); + await writeTask.TimeoutAfter(TestConstants.DefaultTimeout); // Cleanup outputProducer.Dispose(); @@ -173,7 +173,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests await _libuvThread.PostAsync(cb => cb(0), triggerNextCompleted); // Assert - await writeTask.TimeoutAfter(TimeSpan.FromSeconds(5)); + await writeTask.TimeoutAfter(TestConstants.DefaultTimeout); // Cleanup outputProducer.Dispose(); @@ -235,7 +235,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests await _libuvThread.PostAsync(cb => cb(0), triggerNextCompleted); // Finishing the first write should allow the second write to pre-complete. - await writeTask2.TimeoutAfter(TimeSpan.FromSeconds(5)); + await writeTask2.TimeoutAfter(TestConstants.DefaultTimeout); // Cleanup outputProducer.Dispose(); @@ -309,7 +309,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests await _libuvThread.PostAsync(cb => cb(0), triggerNextCompleted); } - var timeout = TimeSpan.FromSeconds(5); + var timeout = TestConstants.DefaultTimeout; await writeTask2.TimeoutAfter(timeout); await writeTask3.TimeoutAfter(timeout); @@ -629,7 +629,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests await _libuvThread.PostAsync(cb => cb(0), triggerNextCompleted); } - var timeout = TimeSpan.FromSeconds(5); + var timeout = TestConstants.DefaultTimeout; // Assert // Too many bytes are already pre-completed for the third but not the second write to pre-complete. diff --git a/test/Kestrel.Transport.Libuv.Tests/ListenerPrimaryTests.cs b/test/Kestrel.Transport.Libuv.Tests/ListenerPrimaryTests.cs index 3defb90297..0438398b7d 100644 --- a/test/Kestrel.Transport.Libuv.Tests/ListenerPrimaryTests.cs +++ b/test/Kestrel.Transport.Libuv.Tests/ListenerPrimaryTests.cs @@ -65,7 +65,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests var listenerSecondary = new ListenerSecondary(transportContextSecondary); await listenerSecondary.StartAsync(pipeName, pipeMessage, listenOptions, libuvThreadSecondary); - var maxWait = Task.Delay(TimeSpan.FromSeconds(30)); + var maxWait = Task.Delay(TestConstants.DefaultTimeout); // wait for ListenerPrimary.ReadCallback to add the secondary pipe while (listenerPrimary.UvPipeCount == listenerCount) { @@ -85,10 +85,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests Assert.Equal("Primary", await HttpClientSlim.GetStringAsync(address)); await listenerSecondary.DisposeAsync(); - await libuvThreadSecondary.StopAsync(TimeSpan.FromSeconds(1)); + await libuvThreadSecondary.StopAsync(TimeSpan.FromSeconds(5)); await listenerPrimary.DisposeAsync(); - await libuvThreadPrimary.StopAsync(TimeSpan.FromSeconds(1)); + await libuvThreadPrimary.StopAsync(TimeSpan.FromSeconds(5)); } // https://github.com/aspnet/KestrelHttpServer/issues/1182 @@ -191,10 +191,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests Assert.Equal("Primary", await HttpClientSlim.GetStringAsync(address)); await listenerSecondary.DisposeAsync(); - await libuvThreadSecondary.StopAsync(TimeSpan.FromSeconds(1)); + await libuvThreadSecondary.StopAsync(TimeSpan.FromSeconds(5)); await listenerPrimary.DisposeAsync(); - await libuvThreadPrimary.StopAsync(TimeSpan.FromSeconds(1)); + await libuvThreadPrimary.StopAsync(TimeSpan.FromSeconds(5)); Assert.Equal(1, logger.TotalErrorsLogged); var errorMessage = logger.Messages.First(m => m.LogLevel == LogLevel.Error); @@ -258,10 +258,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests Assert.Equal("Primary", await HttpClientSlim.GetStringAsync(address)); await listenerSecondary.DisposeAsync(); - await libuvThreadSecondary.StopAsync(TimeSpan.FromSeconds(1)); + await libuvThreadSecondary.StopAsync(TimeSpan.FromSeconds(5)); await listenerPrimary.DisposeAsync(); - await libuvThreadPrimary.StopAsync(TimeSpan.FromSeconds(1)); + await libuvThreadPrimary.StopAsync(TimeSpan.FromSeconds(5)); Assert.Equal(1, logger.TotalErrorsLogged); var errorMessage = logger.Messages.First(m => m.LogLevel == LogLevel.Error); diff --git a/test/Kestrel.Transport.Libuv.Tests/TestHelpers/TestConstants.cs b/test/shared/TestConstants.cs similarity index 66% rename from test/Kestrel.Transport.Libuv.Tests/TestHelpers/TestConstants.cs rename to test/shared/TestConstants.cs index e9843bda85..9615b4c5ef 100644 --- a/test/Kestrel.Transport.Libuv.Tests/TestHelpers/TestConstants.cs +++ b/test/shared/TestConstants.cs @@ -1,10 +1,13 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests.TestHelpers +using System; + +namespace Microsoft.AspNetCore.Testing { public class TestConstants { public const int EOF = -4095; + public static TimeSpan DefaultTimeout = TimeSpan.FromSeconds(30); } } From e3b70db2785ef334805ed5d4a527256d3affb272 Mon Sep 17 00:00:00 2001 From: Ryan Brandenburg Date: Wed, 24 Jan 2018 15:49:25 -0800 Subject: [PATCH 1507/1662] Preview2 --- version.props | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version.props b/version.props index 5c4a7c32d1..370d5ababd 100644 --- a/version.props +++ b/version.props @@ -1,7 +1,7 @@ 2.1.0 - preview1 + preview2 $(VersionPrefix) $(VersionPrefix)-$(VersionSuffix)-final t000 From 8280c1b73ffe25e3c4492cf7f7aeeaca7098953a Mon Sep 17 00:00:00 2001 From: Javier Calvarro Nelson Date: Thu, 25 Jan 2018 17:56:16 -0800 Subject: [PATCH 1508/1662] Update Kestrel HTTPS developer certificate error message --- src/Kestrel.Core/CoreStrings.resx | 4 +++- src/Kestrel.Core/Properties/CoreStrings.Designer.cs | 8 ++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/Kestrel.Core/CoreStrings.resx b/src/Kestrel.Core/CoreStrings.resx index e369a2d122..a8a2db7f84 100644 --- a/src/Kestrel.Core/CoreStrings.resx +++ b/src/Kestrel.Core/CoreStrings.resx @@ -490,7 +490,9 @@ The endpoint {endpointName} is missing the required 'Url' parameter. - Unable to configure HTTPS endpoint. No server certificate was specified and the default developer certificate could not be found. Try running 'dotnet developercertificates https -t' to setup a developer certificate for use with localhost. For information on configuring HTTPS see https://go.microsoft.com/fwlink/?linkid=848054 + Unable to configure HTTPS endpoint. No server certificate was specified, and the default developer certificate could not be found. +To install the developer certificate first install the dev-certs tool by running 'dotnet install tool dotnet-dev-certs -g --version 2.1.0-preview1-final' and then run 'dotnet-dev-certs https'. To trust the certificate (Windows and macOS only) run 'dotnet-dev-certs https --trust'. +For more information on configuring HTTPS see https://go.microsoft.com/fwlink/?linkid=848054. The endpoint {endpointName} specified multiple certificate sources. diff --git a/src/Kestrel.Core/Properties/CoreStrings.Designer.cs b/src/Kestrel.Core/Properties/CoreStrings.Designer.cs index 1df67ddf4f..7e12e1c524 100644 --- a/src/Kestrel.Core/Properties/CoreStrings.Designer.cs +++ b/src/Kestrel.Core/Properties/CoreStrings.Designer.cs @@ -1747,7 +1747,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core => string.Format(CultureInfo.CurrentCulture, GetString("EndpointMissingUrl", "endpointName"), endpointName); /// - /// Unable to configure HTTPS endpoint. No server certificate was specified and the default developer certificate could not be found. Try running 'dotnet developercertificates https -t' to setup a developer certificate for use with localhost. For information on configuring HTTPS see https://go.microsoft.com/fwlink/?linkid=848054 + /// Unable to configure HTTPS endpoint. No server certificate was specified, and the default developer certificate could not be found. + /// To install the developer certificate first install the dev-certs tool by running 'dotnet install tool dotnet-dev-certs -g --version 2.1.0-preview1-final' and then run 'dotnet-dev-certs https'. To trust the certificate (Windows and macOS only) run 'dotnet-dev-certs https --trust'. + /// For more information on configuring HTTPS see https://go.microsoft.com/fwlink/?linkid=848054. /// internal static string NoCertSpecifiedNoDevelopmentCertificateFound { @@ -1755,7 +1757,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core } /// - /// Unable to configure HTTPS endpoint. No server certificate was specified and the default developer certificate could not be found. Try running 'dotnet developercertificates https -t' to setup a developer certificate for use with localhost. For information on configuring HTTPS see https://go.microsoft.com/fwlink/?linkid=848054 + /// Unable to configure HTTPS endpoint. No server certificate was specified, and the default developer certificate could not be found. + /// To install the developer certificate first install the dev-certs tool by running 'dotnet install tool dotnet-dev-certs -g --version 2.1.0-preview1-final' and then run 'dotnet-dev-certs https'. To trust the certificate (Windows and macOS only) run 'dotnet-dev-certs https --trust'. + /// For more information on configuring HTTPS see https://go.microsoft.com/fwlink/?linkid=848054. /// internal static string FormatNoCertSpecifiedNoDevelopmentCertificateFound() => GetString("NoCertSpecifiedNoDevelopmentCertificateFound"); From 50b396cec6337956098725f7324711d1b9994370 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Mon, 29 Jan 2018 12:41:45 -0800 Subject: [PATCH 1509/1662] Fixed race in sockets transport (#2279) - Based on the changes you made earlier (f4d27e6), we trigger OnConnectionClosed before the socket is disposed in the SocketTransport. This moves the call to Output.Complete to happen after and thus fixes the race. --- .../Internal/SocketConnection.cs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/Kestrel.Transport.Sockets/Internal/SocketConnection.cs b/src/Kestrel.Transport.Sockets/Internal/SocketConnection.cs index ff7c678cd7..320c4739f9 100644 --- a/src/Kestrel.Transport.Sockets/Internal/SocketConnection.cs +++ b/src/Kestrel.Transport.Sockets/Internal/SocketConnection.cs @@ -57,13 +57,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal public async Task StartAsync(IConnectionHandler connectionHandler) { + Exception sendError = null; try { connectionHandler.OnConnection(this); // Spawn send and receive logic Task receiveTask = DoReceive(); - Task sendTask = DoSend(); + Task sendTask = DoSend(); // If the sending task completes then close the receive // We don't need to do this in the other direction because the kestrel @@ -76,7 +77,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal // Now wait for both to complete await receiveTask; - await sendTask; + sendError = await sendTask; // Dispose the socket(should noop if already called) _socket.Dispose(); @@ -85,6 +86,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal { _trace.LogError(0, ex, $"Unexpected exception in {nameof(SocketConnection)}.{nameof(StartAsync)}."); } + finally + { + // Complete the output after disposing the socket + Output.Complete(sendError); + } } private async Task DoReceive() @@ -181,7 +187,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal } } - private async Task DoSend() + private async Task DoSend() { Exception error = null; @@ -233,8 +239,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal } finally { - Output.Complete(error); - // Make sure to close the connection only after the _aborted flag is set. // Without this, the RequestsCanBeAbortedMidRead test will sometimes fail when // a BadHttpRequestException is thrown instead of a TaskCanceledException. @@ -242,6 +246,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal _trace.ConnectionWriteFin(ConnectionId); _socket.Shutdown(SocketShutdown.Both); } + + return error; } } } From 8ea181f088f9022338b258e8f1f7ca70b2851fdb Mon Sep 17 00:00:00 2001 From: David Fowler Date: Mon, 29 Jan 2018 14:27:47 -0800 Subject: [PATCH 1510/1662] Use the OnWriterCompleted and OnReaderCompleted events directly. (#2280) --- .../Internal/HttpConnectionMiddleware.cs | 44 ++++--------------- 1 file changed, 8 insertions(+), 36 deletions(-) diff --git a/src/Kestrel.Core/Internal/HttpConnectionMiddleware.cs b/src/Kestrel.Core/Internal/HttpConnectionMiddleware.cs index 8018438fa4..6514768ab5 100644 --- a/src/Kestrel.Core/Internal/HttpConnectionMiddleware.cs +++ b/src/Kestrel.Core/Internal/HttpConnectionMiddleware.cs @@ -1,6 +1,4 @@ -using System; -using System.Collections.Generic; -using System.IO.Pipelines; +using System.Collections.Generic; using System.Net; using System.Threading; using System.Threading.Tasks; @@ -9,15 +7,11 @@ using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Protocols; using Microsoft.AspNetCore.Protocols.Features; using Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal; -using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; -using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal { public class HttpConnectionMiddleware { - private static Action _completeTcs = CompleteTcs; - private static long _lastHttpConnectionId = long.MinValue; private readonly IList _connectionAdapters; @@ -74,42 +68,20 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal var connection = new HttpConnection(httpConnectionContext); var processingTask = connection.StartRequestProcessing(_application); - - var inputTcs = new TaskCompletionSource(); - var outputTcs = new TaskCompletionSource(); - - // The reason we don't fire events directly from these callbacks is because it seems - // like the transport callbacks root the state object (even after it fires) - connectionContext.Transport.Input.OnWriterCompleted(_completeTcs, inputTcs); - connectionContext.Transport.Output.OnReaderCompleted(_completeTcs, outputTcs); - - inputTcs.Task.ContinueWith((task, state) => + + connectionContext.Transport.Input.OnWriterCompleted((error, state) => { - ((HttpConnection)state).Abort(task.Exception?.InnerException); + ((HttpConnection)state).Abort(error); }, - connection, TaskContinuationOptions.ExecuteSynchronously); + connection); - outputTcs.Task.ContinueWith((task, state) => + connectionContext.Transport.Output.OnReaderCompleted((error, state) => { - ((HttpConnection)state).OnConnectionClosed(task.Exception?.InnerException); + ((HttpConnection)state).OnConnectionClosed(error); }, - connection, TaskContinuationOptions.ExecuteSynchronously); + connection); return processingTask; } - - private static void CompleteTcs(Exception error, object state) - { - var tcs = (TaskCompletionSource)state; - - if (error != null) - { - tcs.TrySetException(error); - } - else - { - tcs.TrySetResult(null); - } - } } } From a84095e5c3a61a329bca5819183de608067d0394 Mon Sep 17 00:00:00 2001 From: Pavel Krymets Date: Mon, 29 Jan 2018 14:34:48 -0800 Subject: [PATCH 1511/1662] React to pipelines changes (#2275) --- ...Http1ConnectionParsingOverheadBenchmark.cs | 2 +- .../Http1WritingBenchmark.cs | 4 +- .../HttpParserBenchmark.cs | 4 +- .../Kestrel.Performance/Mocks/NullParser.cs | 5 +- .../PipeThroughputBenchmark.cs | 18 ++-- .../RequestParsingBenchmark.cs | 13 ++- build/dependencies.props | 22 ++--- .../Adapter/Internal/AdaptedPipeline.cs | 36 ++++---- .../Adapter/Internal/RawStream.cs | 15 ++-- .../Internal/ConnectionHandler.cs | 12 +-- src/Kestrel.Core/Internal/Http/ChunkWriter.cs | 9 +- .../Internal/Http/Http1Connection.cs | 11 +-- .../Internal/Http/Http1ConnectionContext.cs | 4 +- .../Internal/Http/Http1MessageBody.cs | 53 +++++------ .../Internal/Http/Http1OutputProducer.cs | 31 +++---- .../Internal/Http/HttpHeaders.Generated.cs | 75 ++++++++-------- src/Kestrel.Core/Internal/Http/HttpParser.cs | 49 ++++++----- .../Internal/Http/HttpProtocol.Generated.cs | 88 ++++++++++--------- .../Internal/Http/HttpProtocol.cs | 15 ++-- .../Internal/Http/HttpResponseHeaders.cs | 3 +- .../Internal/Http/IHttpOutputProducer.cs | 2 +- src/Kestrel.Core/Internal/Http/IHttpParser.cs | 5 +- src/Kestrel.Core/Internal/Http/MessageBody.cs | 6 +- .../Internal/Http/PipelineExtensions.cs | 14 +-- .../Internal/Http2/Http2Connection.cs | 13 +-- .../Internal/Http2/Http2ConnectionContext.cs | 4 +- .../Internal/Http2/Http2FrameReader.cs | 5 +- .../Internal/Http2/Http2FrameWriter.cs | 22 ++--- .../Internal/Http2/Http2OutputProducer.cs | 2 +- .../Internal/Http2/Http2Stream.cs | 9 +- src/Kestrel.Core/Internal/HttpConnection.cs | 22 ++--- .../Internal/HttpConnectionContext.cs | 4 +- .../Infrastructure/KestrelThreadPool.cs | 3 +- .../Infrastructure/LoggingThreadPool.cs | 4 +- .../Internal/TransportConnection.Features.cs | 4 +- .../Internal/TransportConnection.cs | 12 +-- .../Internal/LibuvConnection.cs | 22 ++--- .../Internal/LibuvConnectionContext.cs | 4 +- .../Internal/LibuvOutputConsumer.cs | 6 +- .../Internal/LibuvThread.cs | 2 +- .../Internal/Networking/UvWriteReq.cs | 6 +- .../Internal/SocketConnection.cs | 16 ++-- .../Internal/SocketSender.cs | 8 +- .../ConnectionContext.cs | 2 +- .../DefaultConnectionContext.cs | 2 +- .../Features/IConnectionTransportFeature.cs | 8 +- src/Protocols.Abstractions/PipeConnection.cs | 8 +- .../PipeFactoryExtensions.cs | 4 +- .../ConnectionHandlerTests.cs | 12 ++- .../Http1ConnectionTests.cs | 38 ++++---- .../Http2ConnectionTests.cs | 6 +- test/Kestrel.Core.Tests/HttpParserTests.cs | 56 ++++++------ test/Kestrel.Core.Tests/MessageBodyTests.cs | 17 ++-- .../Kestrel.Core.Tests/OutputProducerTests.cs | 2 +- test/Kestrel.Core.Tests/PipeOptionsTests.cs | 26 +++--- .../PipelineExtensionTests.cs | 30 +++---- test/Kestrel.Core.Tests/TestInput.cs | 4 +- .../LibuvConnectionTests.cs | 10 +-- .../LibuvOutputConsumerTests.cs | 50 +++++------ .../MultipleLoopTests.cs | 2 +- .../NetworkingTests.cs | 2 +- .../TestHelpers/MockConnectionHandler.cs | 4 +- tools/CodeGenerator/CodeGenerator.csproj | 3 - .../HttpProtocolFeatureCollection.cs | 86 +++++++++--------- .../HttpUtilities/HttpUtilities.cs | 29 +++--- tools/CodeGenerator/KnownHeaders.cs | 22 ++--- tools/CodeGenerator/Program.cs | 4 +- 67 files changed, 550 insertions(+), 541 deletions(-) diff --git a/benchmarks/Kestrel.Performance/Http1ConnectionParsingOverheadBenchmark.cs b/benchmarks/Kestrel.Performance/Http1ConnectionParsingOverheadBenchmark.cs index f3ef888b9a..b4979f4a3b 100644 --- a/benchmarks/Kestrel.Performance/Http1ConnectionParsingOverheadBenchmark.cs +++ b/benchmarks/Kestrel.Performance/Http1ConnectionParsingOverheadBenchmark.cs @@ -16,7 +16,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance { private const int InnerLoopCount = 512; - public ReadOnlyBuffer _buffer; + public ReadOnlyBuffer _buffer; public Http1Connection _http1Connection; [IterationSetup] diff --git a/benchmarks/Kestrel.Performance/Http1WritingBenchmark.cs b/benchmarks/Kestrel.Performance/Http1WritingBenchmark.cs index 3904523c02..325b27c0e7 100644 --- a/benchmarks/Kestrel.Performance/Http1WritingBenchmark.cs +++ b/benchmarks/Kestrel.Performance/Http1WritingBenchmark.cs @@ -25,7 +25,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance private static readonly Func _psuedoAsyncTaskFunc = (obj) => _psuedoAsyncTask; private readonly TestHttp1Connection _http1Connection; - private (IPipeConnection Transport, IPipeConnection Application) _pair; + private (IDuplexPipe Transport, IDuplexPipe Application) _pair; private readonly byte[] _writeData; @@ -128,7 +128,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance var reader = _pair.Application.Input; if (reader.TryRead(out var readResult)) { - reader.Advance(readResult.Buffer.End); + reader.AdvanceTo(readResult.Buffer.End); } } diff --git a/benchmarks/Kestrel.Performance/HttpParserBenchmark.cs b/benchmarks/Kestrel.Performance/HttpParserBenchmark.cs index 4d63b75b91..2c42151f34 100644 --- a/benchmarks/Kestrel.Performance/HttpParserBenchmark.cs +++ b/benchmarks/Kestrel.Performance/HttpParserBenchmark.cs @@ -13,7 +13,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance { private readonly HttpParser _parser = new HttpParser(); - private ReadOnlyBuffer _buffer; + private ReadOnlyBuffer _buffer; [Benchmark(Baseline = true, OperationsPerInvoke = RequestParsingData.InnerLoopCount)] public void PlaintextTechEmpower() @@ -47,7 +47,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance private void InsertData(byte[] data) { - _buffer = new ReadOnlyBuffer(data); + _buffer = new ReadOnlyBuffer(data); } private void ParseData() diff --git a/benchmarks/Kestrel.Performance/Mocks/NullParser.cs b/benchmarks/Kestrel.Performance/Mocks/NullParser.cs index f091f67320..3f83491dd8 100644 --- a/benchmarks/Kestrel.Performance/Mocks/NullParser.cs +++ b/benchmarks/Kestrel.Performance/Mocks/NullParser.cs @@ -3,6 +3,7 @@ using System; using System.Buffers; +using System.Collections; using System.Collections.Sequences; using System.IO.Pipelines; using System.Text; @@ -23,7 +24,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance public static readonly NullParser Instance = new NullParser(); - public bool ParseHeaders(TRequestHandler handler, ReadOnlyBuffer buffer, out Position consumed, out Position examined, out int consumedBytes) + public bool ParseHeaders(TRequestHandler handler, ReadOnlyBuffer buffer, out SequencePosition consumed, out SequencePosition examined, out int consumedBytes) { handler.OnHeader(new Span(_hostHeaderName), new Span(_hostHeaderValue)); handler.OnHeader(new Span(_acceptHeaderName), new Span(_acceptHeaderValue)); @@ -36,7 +37,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance return true; } - public bool ParseRequestLine(TRequestHandler handler, ReadOnlyBuffer buffer, out Position consumed, out Position examined) + public bool ParseRequestLine(TRequestHandler handler, ReadOnlyBuffer buffer, out SequencePosition consumed, out SequencePosition examined) { handler.OnStartLine(HttpMethod.Get, HttpVersion.Http11, diff --git a/benchmarks/Kestrel.Performance/PipeThroughputBenchmark.cs b/benchmarks/Kestrel.Performance/PipeThroughputBenchmark.cs index 999fa0a8e1..80e331ea5a 100644 --- a/benchmarks/Kestrel.Performance/PipeThroughputBenchmark.cs +++ b/benchmarks/Kestrel.Performance/PipeThroughputBenchmark.cs @@ -13,7 +13,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance private const int _writeLenght = 57; private const int InnerLoopCount = 512; - private IPipe _pipe; + private Pipe _pipe; private MemoryPool _memoryPool; [IterationSetup] @@ -30,9 +30,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance { for (int i = 0; i < InnerLoopCount; i++) { - var writableBuffer = _pipe.Writer.Alloc(_writeLenght); - writableBuffer.Advance(_writeLenght); - await writableBuffer.FlushAsync(); + _pipe.Writer.GetMemory(_writeLenght); + _pipe.Writer.Advance(_writeLenght); + await _pipe.Writer.FlushAsync(); } }); @@ -43,7 +43,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance { var result = await _pipe.Reader.ReadAsync(); remaining -= result.Buffer.Length; - _pipe.Reader.Advance(result.Buffer.End, result.Buffer.End); + _pipe.Reader.AdvanceTo(result.Buffer.End, result.Buffer.End); } }); @@ -55,11 +55,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance { for (int i = 0; i < InnerLoopCount; i++) { - var writableBuffer = _pipe.Writer.Alloc(_writeLenght); - writableBuffer.Advance(_writeLenght); - writableBuffer.FlushAsync().GetAwaiter().GetResult(); + _pipe.Writer.GetMemory(_writeLenght); + _pipe.Writer.Advance(_writeLenght); + _pipe.Writer.FlushAsync().GetAwaiter().GetResult(); var result = _pipe.Reader.ReadAsync().GetAwaiter().GetResult(); - _pipe.Reader.Advance(result.Buffer.End, result.Buffer.End); + _pipe.Reader.AdvanceTo(result.Buffer.End, result.Buffer.End); } } } diff --git a/benchmarks/Kestrel.Performance/RequestParsingBenchmark.cs b/benchmarks/Kestrel.Performance/RequestParsingBenchmark.cs index 7762902258..3c7d4caaf7 100644 --- a/benchmarks/Kestrel.Performance/RequestParsingBenchmark.cs +++ b/benchmarks/Kestrel.Performance/RequestParsingBenchmark.cs @@ -14,7 +14,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance { public class RequestParsingBenchmark { - public IPipe Pipe { get; set; } + public Pipe Pipe { get; set; } public Http1Connection Http1Connection { get; set; } @@ -130,10 +130,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance private void InsertData(byte[] bytes) { - var buffer = Pipe.Writer.Alloc(2048); - buffer.Write(bytes); + Pipe.Writer.Write(bytes); // There should not be any backpressure and task completes immediately - buffer.FlushAsync().GetAwaiter().GetResult(); + Pipe.Writer.FlushAsync().GetAwaiter().GetResult(); } private void ParseDataDrainBuffer() @@ -166,7 +165,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance } while (readableBuffer.Length > 0); - Pipe.Reader.Advance(readableBuffer.End); + Pipe.Reader.AdvanceTo(readableBuffer.End); } private void ParseData() @@ -189,7 +188,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance { ErrorUtilities.ThrowInvalidRequestLine(); } - Pipe.Reader.Advance(consumed, examined); + Pipe.Reader.AdvanceTo(consumed, examined); result = Pipe.Reader.ReadAsync().GetAwaiter().GetResult(); readableBuffer = result.Buffer; @@ -198,7 +197,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance { ErrorUtilities.ThrowInvalidRequestHeaders(); } - Pipe.Reader.Advance(consumed, examined); + Pipe.Reader.AdvanceTo(consumed, examined); } while (true); } diff --git a/build/dependencies.props b/build/dependencies.props index bf97f3a333..67964d04ce 100644 --- a/build/dependencies.props +++ b/build/dependencies.props @@ -25,21 +25,21 @@ 2.1.0-preview1-28153 2.1.0-preview1-28153 2.0.0 - 2.1.0-preview1-26115-03 + 2.1.0-preview1-26126-02 2.1.0-preview1-28153 15.3.0 4.7.49 10.0.1 - 4.5.0-preview1-26112-01 - 0.1.0-e180104-2 - 0.1.0-e180104-2 - 0.1.0-e180104-2 - 4.5.0-preview1-26112-01 - 4.5.0-preview1-26112-01 - 4.5.0-preview1-26112-01 - 4.5.0-preview1-26112-01 - 0.1.0-e180104-2 - 4.5.0-preview1-26112-01 + 4.5.0-preview1-26126-05 + 0.1.0-preview1-180129-1 + 0.1.0-preview1-180129-1 + 0.1.0-preview1-180129-1 + 4.5.0-preview1-26126-05 + 4.5.0-preview1-26126-05 + 4.5.0-preview1-26126-05 + 4.5.0-preview1-26126-05 + 0.1.0-preview1-180129-1 + 4.5.0-preview1-26126-05 0.8.0 2.3.1 2.3.1 diff --git a/src/Kestrel.Core/Adapter/Internal/AdaptedPipeline.cs b/src/Kestrel.Core/Adapter/Internal/AdaptedPipeline.cs index 43526c8243..2cebf61741 100644 --- a/src/Kestrel.Core/Adapter/Internal/AdaptedPipeline.cs +++ b/src/Kestrel.Core/Adapter/Internal/AdaptedPipeline.cs @@ -10,17 +10,17 @@ using System.Runtime.InteropServices; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal { - public class AdaptedPipeline : IPipeConnection + public class AdaptedPipeline : IDuplexPipe { private const int MinAllocBufferSize = 2048; - private readonly IPipeConnection _transport; - private readonly IPipeConnection _application; + private readonly IDuplexPipe _transport; + private readonly IDuplexPipe _application; - public AdaptedPipeline(IPipeConnection transport, - IPipeConnection application, - IPipe inputPipe, - IPipe outputPipe) + public AdaptedPipeline(IDuplexPipe transport, + IDuplexPipe application, + Pipe inputPipe, + Pipe outputPipe) { _transport = transport; _application = application; @@ -28,13 +28,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal Output = outputPipe; } - public IPipe Input { get; } + public Pipe Input { get; } - public IPipe Output { get; } + public Pipe Output { get; } - IPipeReader IPipeConnection.Input => Input.Reader; + PipeReader IDuplexPipe.Input => Input.Reader; - IPipeWriter IPipeConnection.Output => Output.Writer; + PipeWriter IDuplexPipe.Output => Output.Writer; public async Task RunAsync(Stream stream) { @@ -78,7 +78,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal } await stream.FlushAsync(); } - else if (buffer.IsSingleSpan) + else if (buffer.IsSingleSegment) { var array = buffer.First.GetArray(); await stream.WriteAsync(array.Array, array.Offset, array.Count); @@ -94,7 +94,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal } finally { - Output.Reader.Advance(buffer.End); + Output.Reader.AdvanceTo(buffer.End); } } } @@ -124,13 +124,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal while (true) { - var outputBuffer = Input.Writer.Alloc(MinAllocBufferSize); + var outputBuffer = Input.Writer.GetMemory(MinAllocBufferSize); - var array = outputBuffer.Buffer.GetArray(); + var array = outputBuffer.GetArray(); try { var bytesRead = await stream.ReadAsync(array.Array, array.Offset, array.Count); - outputBuffer.Advance(bytesRead); + Input.Writer.Advance(bytesRead); if (bytesRead == 0) { @@ -140,10 +140,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal } finally { - outputBuffer.Commit(); + Input.Writer.Commit(); } - var result = await outputBuffer.FlushAsync(); + var result = await Input.Writer.FlushAsync(); if (result.IsCompleted) { diff --git a/src/Kestrel.Core/Adapter/Internal/RawStream.cs b/src/Kestrel.Core/Adapter/Internal/RawStream.cs index fdd4470637..87a0932c32 100644 --- a/src/Kestrel.Core/Adapter/Internal/RawStream.cs +++ b/src/Kestrel.Core/Adapter/Internal/RawStream.cs @@ -6,15 +6,16 @@ using System.IO.Pipelines; using System.IO; using System.Threading; using System.Threading.Tasks; +using System.Buffers; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal { public class RawStream : Stream { - private readonly IPipeReader _input; - private readonly IPipeWriter _output; + private readonly PipeReader _input; + private readonly PipeWriter _output; - public RawStream(IPipeReader input, IPipeWriter output) + public RawStream(PipeReader input, PipeWriter output) { _input = input; _output = output; @@ -75,14 +76,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal public override async Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken token) { - var output = _output.Alloc(); - if (buffer != null) { - output.Write(new ArraySegment(buffer, offset, count)); + _output.Write(new ReadOnlySpan(buffer, offset, count)); } - await output.FlushAsync(token); + await _output.FlushAsync(token); } public override void Flush() @@ -118,7 +117,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal } finally { - _input.Advance(readableBuffer.End, readableBuffer.End); + _input.AdvanceTo(readableBuffer.End, readableBuffer.End); } } } diff --git a/src/Kestrel.Core/Internal/ConnectionHandler.cs b/src/Kestrel.Core/Internal/ConnectionHandler.cs index d968fce78c..bf8b598866 100644 --- a/src/Kestrel.Core/Internal/ConnectionHandler.cs +++ b/src/Kestrel.Core/Internal/ConnectionHandler.cs @@ -83,22 +83,22 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal } // Internal for testing - internal static PipeOptions GetInputPipeOptions(ServiceContext serviceContext, MemoryPool memoryPool, Scheduler writerScheduler) => new PipeOptions + internal static PipeOptions GetInputPipeOptions(ServiceContext serviceContext, MemoryPool memoryPool, PipeScheduler writerScheduler) => new PipeOptions ( pool: memoryPool, readerScheduler: serviceContext.ThreadPool, writerScheduler: writerScheduler, - maximumSizeHigh: serviceContext.ServerOptions.Limits.MaxRequestBufferSize ?? 0, - maximumSizeLow: serviceContext.ServerOptions.Limits.MaxRequestBufferSize ?? 0 + pauseWriterThreshold: serviceContext.ServerOptions.Limits.MaxRequestBufferSize ?? 0, + resumeWriterThreshold: serviceContext.ServerOptions.Limits.MaxRequestBufferSize ?? 0 ); - internal static PipeOptions GetOutputPipeOptions(ServiceContext serviceContext, MemoryPool memoryPool, Scheduler readerScheduler) => new PipeOptions + internal static PipeOptions GetOutputPipeOptions(ServiceContext serviceContext, MemoryPool memoryPool, PipeScheduler readerScheduler) => new PipeOptions ( pool: memoryPool, readerScheduler: readerScheduler, writerScheduler: serviceContext.ThreadPool, - maximumSizeHigh: GetOutputResponseBufferSize(serviceContext), - maximumSizeLow: GetOutputResponseBufferSize(serviceContext) + pauseWriterThreshold: GetOutputResponseBufferSize(serviceContext), + resumeWriterThreshold: GetOutputResponseBufferSize(serviceContext) ); private static long GetOutputResponseBufferSize(ServiceContext serviceContext) diff --git a/src/Kestrel.Core/Internal/Http/ChunkWriter.cs b/src/Kestrel.Core/Internal/Http/ChunkWriter.cs index a394fb414e..d37f6d48df 100644 --- a/src/Kestrel.Core/Internal/Http/ChunkWriter.cs +++ b/src/Kestrel.Core/Internal/Http/ChunkWriter.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Buffers; using System.IO.Pipelines; using System.Text; @@ -47,16 +48,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http return new ArraySegment(bytes, offset, 10 - offset); } - public static int WriteBeginChunkBytes(ref WritableBufferWriter start, int dataCount) + public static int WriteBeginChunkBytes(ref OutputWriter start, int dataCount) { var chunkSegment = BeginChunkBytes(dataCount); - start.Write(chunkSegment.Array, chunkSegment.Offset, chunkSegment.Count); + start.Write(new ReadOnlySpan(chunkSegment.Array, chunkSegment.Offset, chunkSegment.Count)); return chunkSegment.Count; } - public static void WriteEndChunkBytes(ref WritableBufferWriter start) + public static void WriteEndChunkBytes(ref OutputWriter start) { - start.Write(_endChunkBytes.Array, _endChunkBytes.Offset, _endChunkBytes.Count); + start.Write(new ReadOnlySpan(_endChunkBytes.Array, _endChunkBytes.Offset, _endChunkBytes.Count)); } } } diff --git a/src/Kestrel.Core/Internal/Http/Http1Connection.cs b/src/Kestrel.Core/Internal/Http/Http1Connection.cs index 84890c4137..e0e5c7d438 100644 --- a/src/Kestrel.Core/Internal/Http/Http1Connection.cs +++ b/src/Kestrel.Core/Internal/Http/Http1Connection.cs @@ -3,6 +3,7 @@ using System; using System.Buffers; +using System.Collections; using System.Collections.Sequences; using System.Diagnostics; using System.IO.Pipelines; @@ -45,7 +46,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http Output = new Http1OutputProducer(_context.Application.Input, _context.Transport.Output, _context.ConnectionId, _context.ServiceContext.Log, _context.TimeoutControl); } - public IPipeReader Input => _context.Transport.Input; + public PipeReader Input => _context.Transport.Input; public ITimeoutControl TimeoutControl => _context.TimeoutControl; public bool RequestTimedOut => _requestTimedOut; @@ -69,7 +70,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http Input.CancelPendingRead(); } - public void ParseRequest(ReadOnlyBuffer buffer, out Position consumed, out Position examined) + public void ParseRequest(ReadOnlyBuffer buffer, out SequencePosition consumed, out SequencePosition examined) { consumed = buffer.Start; examined = buffer.End; @@ -107,7 +108,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http } } - public bool TakeStartLine(ReadOnlyBuffer buffer, out Position consumed, out Position examined) + public bool TakeStartLine(ReadOnlyBuffer buffer, out SequencePosition consumed, out SequencePosition examined) { var overLength = false; if (buffer.Length >= ServerOptions.Limits.MaxRequestLineSize) @@ -125,7 +126,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http return result; } - public bool TakeMessageHeaders(ReadOnlyBuffer buffer, out Position consumed, out Position examined) + public bool TakeMessageHeaders(ReadOnlyBuffer buffer, out SequencePosition consumed, out SequencePosition examined) { // Make sure the buffer is limited bool overLength = false; @@ -453,7 +454,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http } finally { - Input.Advance(consumed, examined); + Input.AdvanceTo(consumed, examined); } if (result.IsCompleted) diff --git a/src/Kestrel.Core/Internal/Http/Http1ConnectionContext.cs b/src/Kestrel.Core/Internal/Http/Http1ConnectionContext.cs index b30be13924..cb3d9a2cef 100644 --- a/src/Kestrel.Core/Internal/Http/Http1ConnectionContext.cs +++ b/src/Kestrel.Core/Internal/Http/Http1ConnectionContext.cs @@ -19,7 +19,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http public IPEndPoint RemoteEndPoint { get; set; } public IPEndPoint LocalEndPoint { get; set; } public ITimeoutControl TimeoutControl { get; set; } - public IPipeConnection Transport { get; set; } - public IPipeConnection Application { get; set; } + public IDuplexPipe Transport { get; set; } + public IDuplexPipe Application { get; set; } } } diff --git a/src/Kestrel.Core/Internal/Http/Http1MessageBody.cs b/src/Kestrel.Core/Internal/Http/Http1MessageBody.cs index 3d808838b9..521a9c58f8 100644 --- a/src/Kestrel.Core/Internal/Http/Http1MessageBody.cs +++ b/src/Kestrel.Core/Internal/Http/Http1MessageBody.cs @@ -3,6 +3,7 @@ using System; using System.Buffers; +using System.Collections; using System.Collections.Sequences; using System.IO; using System.IO.Pipelines; @@ -62,19 +63,18 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http if (!readableBuffer.IsEmpty) { - var writableBuffer = _context.RequestBodyPipe.Writer.Alloc(1); bool done; try { - done = Read(readableBuffer, writableBuffer, out consumed, out examined); + done = Read(readableBuffer, _context.RequestBodyPipe.Writer, out consumed, out examined); } finally { - writableBuffer.Commit(); + _context.RequestBodyPipe.Writer.Commit(); } - var writeAwaitable = writableBuffer.FlushAsync(); + var writeAwaitable = _context.RequestBodyPipe.Writer.FlushAsync(); var backpressure = false; if (!writeAwaitable.IsCompleted) @@ -105,7 +105,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http } finally { - _context.Input.Advance(consumed, examined); + _context.Input.AdvanceTo(consumed, examined); } } } @@ -142,7 +142,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http do { result = await _context.RequestBodyPipe.Reader.ReadAsync(); - _context.RequestBodyPipe.Reader.Advance(result.Buffer.End); + _context.RequestBodyPipe.Reader.AdvanceTo(result.Buffer.End); } while (!result.IsCompleted); } finally @@ -151,11 +151,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http } } - protected void Copy(ReadOnlyBuffer readableBuffer, WritableBuffer writableBuffer) + protected void Copy(ReadOnlyBuffer readableBuffer, PipeWriter writableBuffer) { _context.TimeoutControl.BytesRead(readableBuffer.Length); - if (readableBuffer.IsSingleSpan) + if (readableBuffer.IsSingleSegment) { writableBuffer.Write(readableBuffer.First.Span); } @@ -173,7 +173,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http _pumpTask = PumpAsync(); } - protected virtual bool Read(ReadOnlyBuffer readableBuffer, WritableBuffer writableBuffer, out Position consumed, out Position examined) + protected virtual bool Read(ReadOnlyBuffer readableBuffer, PipeWriter writableBuffer, out SequencePosition consumed, out SequencePosition examined) { throw new NotImplementedException(); } @@ -294,7 +294,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http RequestUpgrade = true; } - protected override bool Read(ReadOnlyBuffer readableBuffer, WritableBuffer writableBuffer, out Position consumed, out Position examined) + protected override bool Read(ReadOnlyBuffer readableBuffer, PipeWriter writableBuffer, out SequencePosition consumed, out SequencePosition examined) { Copy(readableBuffer, writableBuffer); consumed = readableBuffer.End; @@ -316,7 +316,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http _inputLength = _contentLength; } - protected override bool Read(ReadOnlyBuffer readableBuffer, WritableBuffer writableBuffer, out Position consumed, out Position examined) + protected override bool Read(ReadOnlyBuffer readableBuffer, PipeWriter writableBuffer, out SequencePosition consumed, out SequencePosition examined) { if (_inputLength == 0) { @@ -326,7 +326,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http var actual = (int)Math.Min(readableBuffer.Length, _inputLength); _inputLength -= actual; - consumed = readableBuffer.Move(readableBuffer.Start, actual); + consumed = readableBuffer.GetPosition(readableBuffer.Start, actual); examined = consumed; Copy(readableBuffer.Slice(0, actual), writableBuffer); @@ -364,10 +364,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http RequestKeepAlive = keepAlive; } - protected override bool Read(ReadOnlyBuffer readableBuffer, WritableBuffer writableBuffer, out Position consumed, out Position examined) + protected override bool Read(ReadOnlyBuffer readableBuffer, PipeWriter writableBuffer, out SequencePosition consumed, out SequencePosition examined) { - consumed = default(Position); - examined = default(Position); + consumed = default(SequencePosition); + examined = default(SequencePosition); while (_mode < Mode.Trailer) { @@ -455,13 +455,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http } } - private void ParseChunkedPrefix(ReadOnlyBuffer buffer, out Position consumed, out Position examined) + private void ParseChunkedPrefix(ReadOnlyBuffer buffer, out SequencePosition consumed, out SequencePosition examined) { consumed = buffer.Start; examined = buffer.Start; var reader = BufferReader.Create(buffer); - var ch1 = reader.Take(); - var ch2 = reader.Take(); + var ch1 = reader.Read(); + var ch2 = reader.Read(); if (ch1 == -1 || ch2 == -1) { @@ -485,7 +485,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http return; } - ch2 = reader.Take(); + ch2 = reader.Read(); if (ch2 == -1) { examined = reader.Position; @@ -511,7 +511,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http _context.ThrowRequestRejected(RequestRejectionReason.BadChunkSizeData); } - private void ParseExtension(ReadOnlyBuffer buffer, out Position consumed, out Position examined) + private void ParseExtension(ReadOnlyBuffer buffer, out SequencePosition consumed, out SequencePosition examined) { // Chunk-extensions not currently parsed // Just drain the data @@ -520,8 +520,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http do { - Position extensionCursor; - if (ReadOnlyBuffer.Seek(buffer.Start, buffer.End, out extensionCursor, ByteCR) == -1) + SequencePosition? extensionCursorPosition = buffer.PositionOf(ByteCR); + if (extensionCursorPosition == null) { // End marker not found yet consumed = buffer.End; @@ -530,6 +530,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http return; }; + var extensionCursor = extensionCursorPosition.Value; var charsToByteCRExclusive = buffer.Slice(0, extensionCursor).Length; var sufixBuffer = buffer.Slice(extensionCursor); @@ -563,10 +564,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http } while (_mode == Mode.Extension); } - private void ReadChunkedData(ReadOnlyBuffer buffer, WritableBuffer writableBuffer, out Position consumed, out Position examined) + private void ReadChunkedData(ReadOnlyBuffer buffer, PipeWriter writableBuffer, out SequencePosition consumed, out SequencePosition examined) { var actual = Math.Min(buffer.Length, _inputLength); - consumed = buffer.Move(buffer.Start, actual); + consumed = buffer.GetPosition(buffer.Start, actual); examined = consumed; Copy(buffer.Slice(0, actual), writableBuffer); @@ -580,7 +581,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http } } - private void ParseChunkedSuffix(ReadOnlyBuffer buffer, out Position consumed, out Position examined) + private void ParseChunkedSuffix(ReadOnlyBuffer buffer, out SequencePosition consumed, out SequencePosition examined) { consumed = buffer.Start; examined = buffer.Start; @@ -606,7 +607,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http } } - private void ParseChunkedTrailer(ReadOnlyBuffer buffer, out Position consumed, out Position examined) + private void ParseChunkedTrailer(ReadOnlyBuffer buffer, out SequencePosition consumed, out SequencePosition examined) { consumed = buffer.Start; examined = buffer.Start; diff --git a/src/Kestrel.Core/Internal/Http/Http1OutputProducer.cs b/src/Kestrel.Core/Internal/Http/Http1OutputProducer.cs index 466f17f64e..a3781075c5 100644 --- a/src/Kestrel.Core/Internal/Http/Http1OutputProducer.cs +++ b/src/Kestrel.Core/Internal/Http/Http1OutputProducer.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Buffers; using System.Diagnostics; using System.IO.Pipelines; using System.Runtime.CompilerServices; @@ -28,8 +29,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http private bool _completed = false; - private readonly IPipeWriter _pipeWriter; - private readonly IPipeReader _outputPipeReader; + private readonly PipeWriter _pipeWriter; + private readonly PipeReader _outputPipeReader; // https://github.com/dotnet/corefxlab/issues/1334 // Pipelines don't support multiple awaiters on flush @@ -39,8 +40,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http private Action _flushCompleted; public Http1OutputProducer( - IPipeReader outputPipeReader, - IPipeWriter pipeWriter, + PipeReader outputPipeReader, + PipeWriter pipeWriter, string connectionId, IKestrelTrace log, ITimeoutControl timeoutControl) @@ -73,7 +74,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http return WriteAsync(Constants.EmptyData, cancellationToken); } - public void Write(Action callback, T state) + public void Write(Action callback, T state) { lock (_contextLock) { @@ -82,13 +83,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http return; } - var buffer = _pipeWriter.Alloc(1); + var buffer = _pipeWriter; callback(buffer, state); buffer.Commit(); } } - public Task WriteAsync(Action callback, T state) + public Task WriteAsync(Action callback, T state) { lock (_contextLock) { @@ -97,7 +98,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http return Task.CompletedTask; } - var buffer = _pipeWriter.Alloc(1); + var buffer = _pipeWriter; callback(buffer, state); buffer.Commit(); } @@ -114,8 +115,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http return; } - var buffer = _pipeWriter.Alloc(1); - var writer = new WritableBufferWriter(buffer); + var buffer = _pipeWriter; + var writer = OutputWriter.Create(buffer); writer.Write(_bytesHttpVersion11); var statusBytes = ReasonPhrases.ToStatusBytes(statusCode, reasonPhrase); @@ -167,7 +168,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http ArraySegment buffer, CancellationToken cancellationToken) { - var writableBuffer = default(WritableBuffer); + var writableBuffer = default(PipeWriter); long bytesWritten = 0; lock (_contextLock) { @@ -176,11 +177,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http return Task.CompletedTask; } - writableBuffer = _pipeWriter.Alloc(1); - var writer = new WritableBufferWriter(writableBuffer); + writableBuffer = _pipeWriter; + var writer = OutputWriter.Create(writableBuffer); if (buffer.Count > 0) { - writer.Write(buffer.Array, buffer.Offset, buffer.Count); + writer.Write(new ReadOnlySpan(buffer.Array, buffer.Offset, buffer.Count)); bytesWritten += buffer.Count; } @@ -192,7 +193,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http // Single caller, at end of method - so inline [MethodImpl(MethodImplOptions.AggressiveInlining)] - private Task FlushAsync(WritableBuffer writableBuffer, long bytesWritten, CancellationToken cancellationToken) + private Task FlushAsync(PipeWriter writableBuffer, long bytesWritten, CancellationToken cancellationToken) { var awaitable = writableBuffer.FlushAsync(cancellationToken); if (awaitable.IsCompleted) diff --git a/src/Kestrel.Core/Internal/Http/HttpHeaders.Generated.cs b/src/Kestrel.Core/Internal/Http/HttpHeaders.Generated.cs index 0da75ae65f..80bf03c4fd 100644 --- a/src/Kestrel.Core/Internal/Http/HttpHeaders.Generated.cs +++ b/src/Kestrel.Core/Internal/Http/HttpHeaders.Generated.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; +using System.Buffers; using System.IO.Pipelines; using Microsoft.Extensions.Primitives; using Microsoft.Net.Http.Headers; @@ -7753,7 +7754,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http return true; } - protected void CopyToFast(ref WritableBufferWriter output) + protected void CopyToFast(ref OutputWriter output) { var tempBits = _bits | (_contentLength.HasValue ? -9223372036854775808L : 0); @@ -7771,7 +7772,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http var value = _headers._Connection[i]; if (value != null) { - output.Write(_headerBytes, 17, 14); + output.Write(new ReadOnlySpan(_headerBytes, 17, 14)); PipelineExtensions.WriteAsciiNoValidation(ref output, value); } } @@ -7797,7 +7798,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http var value = _headers._Date[i]; if (value != null) { - output.Write(_headerBytes, 31, 8); + output.Write(new ReadOnlySpan(_headerBytes, 31, 8)); PipelineExtensions.WriteAsciiNoValidation(ref output, value); } } @@ -7818,7 +7819,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http var value = _headers._ContentType[i]; if (value != null) { - output.Write(_headerBytes, 133, 16); + output.Write(new ReadOnlySpan(_headerBytes, 133, 16)); PipelineExtensions.WriteAsciiNoValidation(ref output, value); } } @@ -7844,7 +7845,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http var value = _headers._Server[i]; if (value != null) { - output.Write(_headerBytes, 350, 10); + output.Write(new ReadOnlySpan(_headerBytes, 350, 10)); PipelineExtensions.WriteAsciiNoValidation(ref output, value); } } @@ -7858,7 +7859,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http } if ((tempBits & -9223372036854775808L) != 0) { - output.Write(_headerBytes, 592, 18); + output.Write(new ReadOnlySpan(_headerBytes, 592, 18)); PipelineExtensions.WriteNumeric(ref output, (ulong)ContentLength.Value); if((tempBits & ~-9223372036854775808L) == 0) @@ -7876,7 +7877,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http var value = _headers._CacheControl[i]; if (value != null) { - output.Write(_headerBytes, 0, 17); + output.Write(new ReadOnlySpan(_headerBytes, 0, 17)); PipelineExtensions.WriteAsciiNoValidation(ref output, value); } } @@ -7897,7 +7898,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http var value = _headers._KeepAlive[i]; if (value != null) { - output.Write(_headerBytes, 39, 14); + output.Write(new ReadOnlySpan(_headerBytes, 39, 14)); PipelineExtensions.WriteAsciiNoValidation(ref output, value); } } @@ -7918,7 +7919,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http var value = _headers._Pragma[i]; if (value != null) { - output.Write(_headerBytes, 53, 10); + output.Write(new ReadOnlySpan(_headerBytes, 53, 10)); PipelineExtensions.WriteAsciiNoValidation(ref output, value); } } @@ -7939,7 +7940,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http var value = _headers._Trailer[i]; if (value != null) { - output.Write(_headerBytes, 63, 11); + output.Write(new ReadOnlySpan(_headerBytes, 63, 11)); PipelineExtensions.WriteAsciiNoValidation(ref output, value); } } @@ -7965,7 +7966,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http var value = _headers._TransferEncoding[i]; if (value != null) { - output.Write(_headerBytes, 74, 21); + output.Write(new ReadOnlySpan(_headerBytes, 74, 21)); PipelineExtensions.WriteAsciiNoValidation(ref output, value); } } @@ -7986,7 +7987,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http var value = _headers._Upgrade[i]; if (value != null) { - output.Write(_headerBytes, 95, 11); + output.Write(new ReadOnlySpan(_headerBytes, 95, 11)); PipelineExtensions.WriteAsciiNoValidation(ref output, value); } } @@ -8007,7 +8008,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http var value = _headers._Via[i]; if (value != null) { - output.Write(_headerBytes, 106, 7); + output.Write(new ReadOnlySpan(_headerBytes, 106, 7)); PipelineExtensions.WriteAsciiNoValidation(ref output, value); } } @@ -8028,7 +8029,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http var value = _headers._Warning[i]; if (value != null) { - output.Write(_headerBytes, 113, 11); + output.Write(new ReadOnlySpan(_headerBytes, 113, 11)); PipelineExtensions.WriteAsciiNoValidation(ref output, value); } } @@ -8049,7 +8050,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http var value = _headers._Allow[i]; if (value != null) { - output.Write(_headerBytes, 124, 9); + output.Write(new ReadOnlySpan(_headerBytes, 124, 9)); PipelineExtensions.WriteAsciiNoValidation(ref output, value); } } @@ -8070,7 +8071,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http var value = _headers._ContentEncoding[i]; if (value != null) { - output.Write(_headerBytes, 149, 20); + output.Write(new ReadOnlySpan(_headerBytes, 149, 20)); PipelineExtensions.WriteAsciiNoValidation(ref output, value); } } @@ -8091,7 +8092,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http var value = _headers._ContentLanguage[i]; if (value != null) { - output.Write(_headerBytes, 169, 20); + output.Write(new ReadOnlySpan(_headerBytes, 169, 20)); PipelineExtensions.WriteAsciiNoValidation(ref output, value); } } @@ -8112,7 +8113,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http var value = _headers._ContentLocation[i]; if (value != null) { - output.Write(_headerBytes, 189, 20); + output.Write(new ReadOnlySpan(_headerBytes, 189, 20)); PipelineExtensions.WriteAsciiNoValidation(ref output, value); } } @@ -8133,7 +8134,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http var value = _headers._ContentMD5[i]; if (value != null) { - output.Write(_headerBytes, 209, 15); + output.Write(new ReadOnlySpan(_headerBytes, 209, 15)); PipelineExtensions.WriteAsciiNoValidation(ref output, value); } } @@ -8154,7 +8155,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http var value = _headers._ContentRange[i]; if (value != null) { - output.Write(_headerBytes, 224, 17); + output.Write(new ReadOnlySpan(_headerBytes, 224, 17)); PipelineExtensions.WriteAsciiNoValidation(ref output, value); } } @@ -8175,7 +8176,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http var value = _headers._Expires[i]; if (value != null) { - output.Write(_headerBytes, 241, 11); + output.Write(new ReadOnlySpan(_headerBytes, 241, 11)); PipelineExtensions.WriteAsciiNoValidation(ref output, value); } } @@ -8196,7 +8197,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http var value = _headers._LastModified[i]; if (value != null) { - output.Write(_headerBytes, 252, 17); + output.Write(new ReadOnlySpan(_headerBytes, 252, 17)); PipelineExtensions.WriteAsciiNoValidation(ref output, value); } } @@ -8217,7 +8218,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http var value = _headers._AcceptRanges[i]; if (value != null) { - output.Write(_headerBytes, 269, 17); + output.Write(new ReadOnlySpan(_headerBytes, 269, 17)); PipelineExtensions.WriteAsciiNoValidation(ref output, value); } } @@ -8238,7 +8239,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http var value = _headers._Age[i]; if (value != null) { - output.Write(_headerBytes, 286, 7); + output.Write(new ReadOnlySpan(_headerBytes, 286, 7)); PipelineExtensions.WriteAsciiNoValidation(ref output, value); } } @@ -8259,7 +8260,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http var value = _headers._ETag[i]; if (value != null) { - output.Write(_headerBytes, 293, 8); + output.Write(new ReadOnlySpan(_headerBytes, 293, 8)); PipelineExtensions.WriteAsciiNoValidation(ref output, value); } } @@ -8280,7 +8281,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http var value = _headers._Location[i]; if (value != null) { - output.Write(_headerBytes, 301, 12); + output.Write(new ReadOnlySpan(_headerBytes, 301, 12)); PipelineExtensions.WriteAsciiNoValidation(ref output, value); } } @@ -8301,7 +8302,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http var value = _headers._ProxyAuthenticate[i]; if (value != null) { - output.Write(_headerBytes, 313, 22); + output.Write(new ReadOnlySpan(_headerBytes, 313, 22)); PipelineExtensions.WriteAsciiNoValidation(ref output, value); } } @@ -8322,7 +8323,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http var value = _headers._RetryAfter[i]; if (value != null) { - output.Write(_headerBytes, 335, 15); + output.Write(new ReadOnlySpan(_headerBytes, 335, 15)); PipelineExtensions.WriteAsciiNoValidation(ref output, value); } } @@ -8343,7 +8344,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http var value = _headers._SetCookie[i]; if (value != null) { - output.Write(_headerBytes, 360, 14); + output.Write(new ReadOnlySpan(_headerBytes, 360, 14)); PipelineExtensions.WriteAsciiNoValidation(ref output, value); } } @@ -8364,7 +8365,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http var value = _headers._Vary[i]; if (value != null) { - output.Write(_headerBytes, 374, 8); + output.Write(new ReadOnlySpan(_headerBytes, 374, 8)); PipelineExtensions.WriteAsciiNoValidation(ref output, value); } } @@ -8385,7 +8386,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http var value = _headers._WWWAuthenticate[i]; if (value != null) { - output.Write(_headerBytes, 382, 20); + output.Write(new ReadOnlySpan(_headerBytes, 382, 20)); PipelineExtensions.WriteAsciiNoValidation(ref output, value); } } @@ -8406,7 +8407,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http var value = _headers._AccessControlAllowCredentials[i]; if (value != null) { - output.Write(_headerBytes, 402, 36); + output.Write(new ReadOnlySpan(_headerBytes, 402, 36)); PipelineExtensions.WriteAsciiNoValidation(ref output, value); } } @@ -8427,7 +8428,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http var value = _headers._AccessControlAllowHeaders[i]; if (value != null) { - output.Write(_headerBytes, 438, 32); + output.Write(new ReadOnlySpan(_headerBytes, 438, 32)); PipelineExtensions.WriteAsciiNoValidation(ref output, value); } } @@ -8448,7 +8449,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http var value = _headers._AccessControlAllowMethods[i]; if (value != null) { - output.Write(_headerBytes, 470, 32); + output.Write(new ReadOnlySpan(_headerBytes, 470, 32)); PipelineExtensions.WriteAsciiNoValidation(ref output, value); } } @@ -8469,7 +8470,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http var value = _headers._AccessControlAllowOrigin[i]; if (value != null) { - output.Write(_headerBytes, 502, 31); + output.Write(new ReadOnlySpan(_headerBytes, 502, 31)); PipelineExtensions.WriteAsciiNoValidation(ref output, value); } } @@ -8490,7 +8491,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http var value = _headers._AccessControlExposeHeaders[i]; if (value != null) { - output.Write(_headerBytes, 533, 33); + output.Write(new ReadOnlySpan(_headerBytes, 533, 33)); PipelineExtensions.WriteAsciiNoValidation(ref output, value); } } @@ -8511,7 +8512,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http var value = _headers._AccessControlMaxAge[i]; if (value != null) { - output.Write(_headerBytes, 566, 26); + output.Write(new ReadOnlySpan(_headerBytes, 566, 26)); PipelineExtensions.WriteAsciiNoValidation(ref output, value); } } diff --git a/src/Kestrel.Core/Internal/Http/HttpParser.cs b/src/Kestrel.Core/Internal/Http/HttpParser.cs index 13297094f3..ece56ac7ed 100644 --- a/src/Kestrel.Core/Internal/Http/HttpParser.cs +++ b/src/Kestrel.Core/Internal/Http/HttpParser.cs @@ -3,6 +3,7 @@ using System; using System.Buffers; +using System.Collections; using System.Collections.Sequences; using System.IO.Pipelines; using System.Runtime.CompilerServices; @@ -33,7 +34,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http private const byte ByteQuestionMark = (byte)'?'; private const byte BytePercentage = (byte)'%'; - public unsafe bool ParseRequestLine(TRequestHandler handler, ReadOnlyBuffer buffer, out Position consumed, out Position examined) + public unsafe bool ParseRequestLine(TRequestHandler handler, ReadOnlyBuffer buffer, out SequencePosition consumed, out SequencePosition examined) { consumed = buffer.Start; examined = buffer.End; @@ -43,10 +44,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http var lineIndex = span.IndexOf(ByteLF); if (lineIndex >= 0) { - consumed = buffer.Move(consumed, lineIndex + 1); + consumed = buffer.GetPosition(consumed, lineIndex + 1); span = span.Slice(0, lineIndex + 1); } - else if (buffer.IsSingleSpan) + else if (buffer.IsSingleSegment) { // No request line end return false; @@ -188,7 +189,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http handler.OnStartLine(method, httpVersion, targetBuffer, pathBuffer, query, customMethod, pathEncoded); } - public unsafe bool ParseHeaders(TRequestHandler handler, ReadOnlyBuffer buffer, out Position consumed, out Position examined, out int consumedBytes) + public unsafe bool ParseHeaders(TRequestHandler handler, ReadOnlyBuffer buffer, out SequencePosition consumed, out SequencePosition examined, out int consumedBytes) { consumed = buffer.Start; examined = buffer.End; @@ -197,21 +198,21 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http var bufferEnd = buffer.End; var reader = BufferReader.Create(buffer); - var start = default(BufferReader); + var start = default(BufferReader>); var done = false; try { while (!reader.End) { - var span = reader.Span; - var remaining = span.Length - reader.Index; + var span = reader.CurrentSegment; + var remaining = span.Length - reader.CurrentSegmentIndex; fixed (byte* pBuffer = &MemoryMarshal.GetReference(span)) { while (remaining > 0) { - var index = reader.Index; + var index = reader.CurrentSegmentIndex; int ch1; int ch2; @@ -228,8 +229,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http start = reader; // Possibly split across spans - ch1 = reader.Take(); - ch2 = reader.Take(); + ch1 = reader.Read(); + ch2 = reader.Read(); } if (ch1 == ByteCR) @@ -245,9 +246,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { // If we got 2 bytes from the span directly so skip ahead 2 so that // the reader's state matches what we expect - if (index == reader.Index) + if (index == reader.CurrentSegmentIndex) { - reader.Skip(2); + reader.Advance(2); } done = true; @@ -260,10 +261,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http // We moved the reader so look ahead 2 bytes so reset both the reader // and the index - if (index != reader.Index) + if (index != reader.CurrentSegmentIndex) { reader = start; - index = reader.Index; + index = reader.CurrentSegmentIndex; } var endIndex = new Span(pBuffer + index, remaining).IndexOf(ByteLF); @@ -279,16 +280,20 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http else { var current = reader.Position; + var currentSlice = buffer.Slice(current, bufferEnd); + var lineEndPosition = currentSlice.PositionOf(ByteLF); // Split buffers - if (ReadOnlyBuffer.Seek(current, bufferEnd, out var lineEnd, ByteLF) == -1) + if (lineEndPosition == null) { // Not there return false; } + var lineEnd = lineEndPosition.Value; + // Make sure LF is included in lineEnd - lineEnd = buffer.Move(lineEnd, 1); + lineEnd = buffer.GetPosition(lineEnd, 1); var headerSpan = buffer.Slice(current, lineEnd).ToSpan(); length = headerSpan.Length; @@ -304,7 +309,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http } // Skip the reader forward past the header line - reader.Skip(length); + reader.Advance(length); remaining -= length; } } @@ -414,15 +419,17 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http } [MethodImpl(MethodImplOptions.NoInlining)] - private static bool TryGetNewLine(ref ReadOnlyBuffer buffer, out Position found) + private static bool TryGetNewLine(ref ReadOnlyBuffer buffer, out SequencePosition found) { - var start = buffer.Start; - if (ReadOnlyBuffer.Seek(start, buffer.End, out found, ByteLF) != -1) + var byteLfPosition = buffer.PositionOf(ByteLF); + if (byteLfPosition != null) { // Move 1 byte past the \n - found = buffer.Move(found, 1); + found = buffer.GetPosition(byteLfPosition.Value, 1); return true; } + + found = default; return false; } diff --git a/src/Kestrel.Core/Internal/Http/HttpProtocol.Generated.cs b/src/Kestrel.Core/Internal/Http/HttpProtocol.Generated.cs index 5c57080c1f..319d36865b 100644 --- a/src/Kestrel.Core/Internal/Http/HttpProtocol.Generated.cs +++ b/src/Kestrel.Core/Internal/Http/HttpProtocol.Generated.cs @@ -4,31 +4,35 @@ using System; using System.Collections.Generic; +using Microsoft.AspNetCore.Http.Features; +using Microsoft.AspNetCore.Http.Features.Authentication; +using Microsoft.AspNetCore.Server.Kestrel.Core.Features; + namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { public partial class HttpProtocol { - private static readonly Type IHttpRequestFeatureType = typeof(global::Microsoft.AspNetCore.Http.Features.IHttpRequestFeature); - private static readonly Type IHttpResponseFeatureType = typeof(global::Microsoft.AspNetCore.Http.Features.IHttpResponseFeature); - private static readonly Type IHttpRequestIdentifierFeatureType = typeof(global::Microsoft.AspNetCore.Http.Features.IHttpRequestIdentifierFeature); - private static readonly Type IServiceProvidersFeatureType = typeof(global::Microsoft.AspNetCore.Http.Features.IServiceProvidersFeature); - private static readonly Type IHttpRequestLifetimeFeatureType = typeof(global::Microsoft.AspNetCore.Http.Features.IHttpRequestLifetimeFeature); - private static readonly Type IHttpConnectionFeatureType = typeof(global::Microsoft.AspNetCore.Http.Features.IHttpConnectionFeature); - private static readonly Type IHttpAuthenticationFeatureType = typeof(global::Microsoft.AspNetCore.Http.Features.Authentication.IHttpAuthenticationFeature); - private static readonly Type IQueryFeatureType = typeof(global::Microsoft.AspNetCore.Http.Features.IQueryFeature); - private static readonly Type IFormFeatureType = typeof(global::Microsoft.AspNetCore.Http.Features.IFormFeature); - private static readonly Type IHttpUpgradeFeatureType = typeof(global::Microsoft.AspNetCore.Http.Features.IHttpUpgradeFeature); - private static readonly Type IHttp2StreamIdFeatureType = typeof(global::Microsoft.AspNetCore.Server.Kestrel.Core.Features.IHttp2StreamIdFeature); - private static readonly Type IResponseCookiesFeatureType = typeof(global::Microsoft.AspNetCore.Http.Features.IResponseCookiesFeature); - private static readonly Type IItemsFeatureType = typeof(global::Microsoft.AspNetCore.Http.Features.IItemsFeature); - private static readonly Type ITlsConnectionFeatureType = typeof(global::Microsoft.AspNetCore.Http.Features.ITlsConnectionFeature); - private static readonly Type IHttpWebSocketFeatureType = typeof(global::Microsoft.AspNetCore.Http.Features.IHttpWebSocketFeature); - private static readonly Type ISessionFeatureType = typeof(global::Microsoft.AspNetCore.Http.Features.ISessionFeature); - private static readonly Type IHttpMaxRequestBodySizeFeatureType = typeof(global::Microsoft.AspNetCore.Http.Features.IHttpMaxRequestBodySizeFeature); - private static readonly Type IHttpMinRequestBodyDataRateFeatureType = typeof(global::Microsoft.AspNetCore.Server.Kestrel.Core.Features.IHttpMinRequestBodyDataRateFeature); - private static readonly Type IHttpMinResponseDataRateFeatureType = typeof(global::Microsoft.AspNetCore.Server.Kestrel.Core.Features.IHttpMinResponseDataRateFeature); - private static readonly Type IHttpBodyControlFeatureType = typeof(global::Microsoft.AspNetCore.Http.Features.IHttpBodyControlFeature); - private static readonly Type IHttpSendFileFeatureType = typeof(global::Microsoft.AspNetCore.Http.Features.IHttpSendFileFeature); + private static readonly Type IHttpRequestFeatureType = typeof(IHttpRequestFeature); + private static readonly Type IHttpResponseFeatureType = typeof(IHttpResponseFeature); + private static readonly Type IHttpRequestIdentifierFeatureType = typeof(IHttpRequestIdentifierFeature); + private static readonly Type IServiceProvidersFeatureType = typeof(IServiceProvidersFeature); + private static readonly Type IHttpRequestLifetimeFeatureType = typeof(IHttpRequestLifetimeFeature); + private static readonly Type IHttpConnectionFeatureType = typeof(IHttpConnectionFeature); + private static readonly Type IHttpAuthenticationFeatureType = typeof(IHttpAuthenticationFeature); + private static readonly Type IQueryFeatureType = typeof(IQueryFeature); + private static readonly Type IFormFeatureType = typeof(IFormFeature); + private static readonly Type IHttpUpgradeFeatureType = typeof(IHttpUpgradeFeature); + private static readonly Type IHttp2StreamIdFeatureType = typeof(IHttp2StreamIdFeature); + private static readonly Type IResponseCookiesFeatureType = typeof(IResponseCookiesFeature); + private static readonly Type IItemsFeatureType = typeof(IItemsFeature); + private static readonly Type ITlsConnectionFeatureType = typeof(ITlsConnectionFeature); + private static readonly Type IHttpWebSocketFeatureType = typeof(IHttpWebSocketFeature); + private static readonly Type ISessionFeatureType = typeof(ISessionFeature); + private static readonly Type IHttpMaxRequestBodySizeFeatureType = typeof(IHttpMaxRequestBodySizeFeature); + private static readonly Type IHttpMinRequestBodyDataRateFeatureType = typeof(IHttpMinRequestBodyDataRateFeature); + private static readonly Type IHttpMinResponseDataRateFeatureType = typeof(IHttpMinResponseDataRateFeature); + private static readonly Type IHttpBodyControlFeatureType = typeof(IHttpBodyControlFeature); + private static readonly Type IHttpSendFileFeatureType = typeof(IHttpSendFileFeature); private object _currentIHttpRequestFeature; private object _currentIHttpResponseFeature; @@ -283,87 +287,87 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { if (_currentIHttpRequestFeature != null) { - yield return new KeyValuePair(IHttpRequestFeatureType, _currentIHttpRequestFeature as global::Microsoft.AspNetCore.Http.Features.IHttpRequestFeature); + yield return new KeyValuePair(IHttpRequestFeatureType, _currentIHttpRequestFeature as IHttpRequestFeature); } if (_currentIHttpResponseFeature != null) { - yield return new KeyValuePair(IHttpResponseFeatureType, _currentIHttpResponseFeature as global::Microsoft.AspNetCore.Http.Features.IHttpResponseFeature); + yield return new KeyValuePair(IHttpResponseFeatureType, _currentIHttpResponseFeature as IHttpResponseFeature); } if (_currentIHttpRequestIdentifierFeature != null) { - yield return new KeyValuePair(IHttpRequestIdentifierFeatureType, _currentIHttpRequestIdentifierFeature as global::Microsoft.AspNetCore.Http.Features.IHttpRequestIdentifierFeature); + yield return new KeyValuePair(IHttpRequestIdentifierFeatureType, _currentIHttpRequestIdentifierFeature as IHttpRequestIdentifierFeature); } if (_currentIServiceProvidersFeature != null) { - yield return new KeyValuePair(IServiceProvidersFeatureType, _currentIServiceProvidersFeature as global::Microsoft.AspNetCore.Http.Features.IServiceProvidersFeature); + yield return new KeyValuePair(IServiceProvidersFeatureType, _currentIServiceProvidersFeature as IServiceProvidersFeature); } if (_currentIHttpRequestLifetimeFeature != null) { - yield return new KeyValuePair(IHttpRequestLifetimeFeatureType, _currentIHttpRequestLifetimeFeature as global::Microsoft.AspNetCore.Http.Features.IHttpRequestLifetimeFeature); + yield return new KeyValuePair(IHttpRequestLifetimeFeatureType, _currentIHttpRequestLifetimeFeature as IHttpRequestLifetimeFeature); } if (_currentIHttpConnectionFeature != null) { - yield return new KeyValuePair(IHttpConnectionFeatureType, _currentIHttpConnectionFeature as global::Microsoft.AspNetCore.Http.Features.IHttpConnectionFeature); + yield return new KeyValuePair(IHttpConnectionFeatureType, _currentIHttpConnectionFeature as IHttpConnectionFeature); } if (_currentIHttpAuthenticationFeature != null) { - yield return new KeyValuePair(IHttpAuthenticationFeatureType, _currentIHttpAuthenticationFeature as global::Microsoft.AspNetCore.Http.Features.Authentication.IHttpAuthenticationFeature); + yield return new KeyValuePair(IHttpAuthenticationFeatureType, _currentIHttpAuthenticationFeature as IHttpAuthenticationFeature); } if (_currentIQueryFeature != null) { - yield return new KeyValuePair(IQueryFeatureType, _currentIQueryFeature as global::Microsoft.AspNetCore.Http.Features.IQueryFeature); + yield return new KeyValuePair(IQueryFeatureType, _currentIQueryFeature as IQueryFeature); } if (_currentIFormFeature != null) { - yield return new KeyValuePair(IFormFeatureType, _currentIFormFeature as global::Microsoft.AspNetCore.Http.Features.IFormFeature); + yield return new KeyValuePair(IFormFeatureType, _currentIFormFeature as IFormFeature); } if (_currentIHttpUpgradeFeature != null) { - yield return new KeyValuePair(IHttpUpgradeFeatureType, _currentIHttpUpgradeFeature as global::Microsoft.AspNetCore.Http.Features.IHttpUpgradeFeature); + yield return new KeyValuePair(IHttpUpgradeFeatureType, _currentIHttpUpgradeFeature as IHttpUpgradeFeature); } if (_currentIHttp2StreamIdFeature != null) { - yield return new KeyValuePair(IHttp2StreamIdFeatureType, _currentIHttp2StreamIdFeature as global::Microsoft.AspNetCore.Server.Kestrel.Core.Features.IHttp2StreamIdFeature); + yield return new KeyValuePair(IHttp2StreamIdFeatureType, _currentIHttp2StreamIdFeature as IHttp2StreamIdFeature); } if (_currentIResponseCookiesFeature != null) { - yield return new KeyValuePair(IResponseCookiesFeatureType, _currentIResponseCookiesFeature as global::Microsoft.AspNetCore.Http.Features.IResponseCookiesFeature); + yield return new KeyValuePair(IResponseCookiesFeatureType, _currentIResponseCookiesFeature as IResponseCookiesFeature); } if (_currentIItemsFeature != null) { - yield return new KeyValuePair(IItemsFeatureType, _currentIItemsFeature as global::Microsoft.AspNetCore.Http.Features.IItemsFeature); + yield return new KeyValuePair(IItemsFeatureType, _currentIItemsFeature as IItemsFeature); } if (_currentITlsConnectionFeature != null) { - yield return new KeyValuePair(ITlsConnectionFeatureType, _currentITlsConnectionFeature as global::Microsoft.AspNetCore.Http.Features.ITlsConnectionFeature); + yield return new KeyValuePair(ITlsConnectionFeatureType, _currentITlsConnectionFeature as ITlsConnectionFeature); } if (_currentIHttpWebSocketFeature != null) { - yield return new KeyValuePair(IHttpWebSocketFeatureType, _currentIHttpWebSocketFeature as global::Microsoft.AspNetCore.Http.Features.IHttpWebSocketFeature); + yield return new KeyValuePair(IHttpWebSocketFeatureType, _currentIHttpWebSocketFeature as IHttpWebSocketFeature); } if (_currentISessionFeature != null) { - yield return new KeyValuePair(ISessionFeatureType, _currentISessionFeature as global::Microsoft.AspNetCore.Http.Features.ISessionFeature); + yield return new KeyValuePair(ISessionFeatureType, _currentISessionFeature as ISessionFeature); } if (_currentIHttpMaxRequestBodySizeFeature != null) { - yield return new KeyValuePair(IHttpMaxRequestBodySizeFeatureType, _currentIHttpMaxRequestBodySizeFeature as global::Microsoft.AspNetCore.Http.Features.IHttpMaxRequestBodySizeFeature); + yield return new KeyValuePair(IHttpMaxRequestBodySizeFeatureType, _currentIHttpMaxRequestBodySizeFeature as IHttpMaxRequestBodySizeFeature); } if (_currentIHttpMinRequestBodyDataRateFeature != null) { - yield return new KeyValuePair(IHttpMinRequestBodyDataRateFeatureType, _currentIHttpMinRequestBodyDataRateFeature as global::Microsoft.AspNetCore.Server.Kestrel.Core.Features.IHttpMinRequestBodyDataRateFeature); + yield return new KeyValuePair(IHttpMinRequestBodyDataRateFeatureType, _currentIHttpMinRequestBodyDataRateFeature as IHttpMinRequestBodyDataRateFeature); } if (_currentIHttpMinResponseDataRateFeature != null) { - yield return new KeyValuePair(IHttpMinResponseDataRateFeatureType, _currentIHttpMinResponseDataRateFeature as global::Microsoft.AspNetCore.Server.Kestrel.Core.Features.IHttpMinResponseDataRateFeature); + yield return new KeyValuePair(IHttpMinResponseDataRateFeatureType, _currentIHttpMinResponseDataRateFeature as IHttpMinResponseDataRateFeature); } if (_currentIHttpBodyControlFeature != null) { - yield return new KeyValuePair(IHttpBodyControlFeatureType, _currentIHttpBodyControlFeature as global::Microsoft.AspNetCore.Http.Features.IHttpBodyControlFeature); + yield return new KeyValuePair(IHttpBodyControlFeatureType, _currentIHttpBodyControlFeature as IHttpBodyControlFeature); } if (_currentIHttpSendFileFeature != null) { - yield return new KeyValuePair(IHttpSendFileFeatureType, _currentIHttpSendFileFeature as global::Microsoft.AspNetCore.Http.Features.IHttpSendFileFeature); + yield return new KeyValuePair(IHttpSendFileFeatureType, _currentIHttpSendFileFeature as IHttpSendFileFeature); } if (MaybeExtra != null) diff --git a/src/Kestrel.Core/Internal/Http/HttpProtocol.cs b/src/Kestrel.Core/Internal/Http/HttpProtocol.cs index cc34dfef3c..f8ada6f76e 100644 --- a/src/Kestrel.Core/Internal/Http/HttpProtocol.cs +++ b/src/Kestrel.Core/Internal/Http/HttpProtocol.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Buffers; using System.Collections.Generic; using System.Diagnostics; using System.IO; @@ -30,7 +31,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http private static readonly byte[] _bytesConnectionKeepAlive = Encoding.ASCII.GetBytes("\r\nConnection: keep-alive"); private static readonly byte[] _bytesTransferEncodingChunked = Encoding.ASCII.GetBytes("\r\nTransfer-Encoding: chunked"); private static readonly byte[] _bytesServer = Encoding.ASCII.GetBytes("\r\nServer: " + Constants.ServerName); - private static readonly Action> _writeChunk = WriteChunk; + private static readonly Action> _writeChunk = WriteChunk; private readonly object _onStartingSync = new Object(); private readonly object _onCompletedSync = new Object(); @@ -895,13 +896,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http return Output.WriteAsync(_writeChunk, data); } - private static void WriteChunk(WritableBuffer writableBuffer, ArraySegment buffer) + private static void WriteChunk(PipeWriter writableBuffer, ArraySegment buffer) { - var writer = new WritableBufferWriter(writableBuffer); + var writer = OutputWriter.Create(writableBuffer); if (buffer.Count > 0) { ChunkWriter.WriteBeginChunkBytes(ref writer, buffer.Count); - writer.Write(buffer.Array, buffer.Offset, buffer.Count); + writer.Write(new ReadOnlySpan(buffer.Array, buffer.Offset, buffer.Count)); ChunkWriter.WriteEndChunkBytes(ref writer); } } @@ -1297,9 +1298,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http ( pool: _context.MemoryPool, readerScheduler: ServiceContext.ThreadPool, - writerScheduler: Scheduler.Inline, - maximumSizeHigh: 1, - maximumSizeLow: 1 + writerScheduler: PipeScheduler.Inline, + pauseWriterThreshold: 1, + resumeWriterThreshold: 1 )); } } diff --git a/src/Kestrel.Core/Internal/Http/HttpResponseHeaders.cs b/src/Kestrel.Core/Internal/Http/HttpResponseHeaders.cs index 41bc6ea29b..9a75ff780a 100644 --- a/src/Kestrel.Core/Internal/Http/HttpResponseHeaders.cs +++ b/src/Kestrel.Core/Internal/Http/HttpResponseHeaders.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Buffers; using System.IO.Pipelines; using System.Collections; using System.Collections.Generic; @@ -34,7 +35,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http return GetEnumerator(); } - public void CopyTo(ref WritableBufferWriter output) + public void CopyTo(ref OutputWriter output) { CopyToFast(ref output); if (MaybeUnknown != null) diff --git a/src/Kestrel.Core/Internal/Http/IHttpOutputProducer.cs b/src/Kestrel.Core/Internal/Http/IHttpOutputProducer.cs index adab288186..019fa9fe77 100644 --- a/src/Kestrel.Core/Internal/Http/IHttpOutputProducer.cs +++ b/src/Kestrel.Core/Internal/Http/IHttpOutputProducer.cs @@ -11,7 +11,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http public interface IHttpOutputProducer : IDisposable { void Abort(Exception error); - Task WriteAsync(Action callback, T state); + Task WriteAsync(Action callback, T state); Task FlushAsync(CancellationToken cancellationToken); Task Write100ContinueAsync(CancellationToken cancellationToken); void WriteResponseHeaders(int statusCode, string ReasonPhrase, HttpResponseHeaders responseHeaders); diff --git a/src/Kestrel.Core/Internal/Http/IHttpParser.cs b/src/Kestrel.Core/Internal/Http/IHttpParser.cs index 07dff45a84..62c2c131b3 100644 --- a/src/Kestrel.Core/Internal/Http/IHttpParser.cs +++ b/src/Kestrel.Core/Internal/Http/IHttpParser.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Buffers; +using System.Collections; using System.Collections.Sequences; using System.IO.Pipelines; @@ -9,8 +10,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { public interface IHttpParser where TRequestHandler : IHttpHeadersHandler, IHttpRequestLineHandler { - bool ParseRequestLine(TRequestHandler handler, ReadOnlyBuffer buffer, out Position consumed, out Position examined); + bool ParseRequestLine(TRequestHandler handler, ReadOnlyBuffer buffer, out SequencePosition consumed, out SequencePosition examined); - bool ParseHeaders(TRequestHandler handler, ReadOnlyBuffer buffer, out Position consumed, out Position examined, out int consumedBytes); + bool ParseHeaders(TRequestHandler handler, ReadOnlyBuffer buffer, out SequencePosition consumed, out SequencePosition examined, out int consumedBytes); } } diff --git a/src/Kestrel.Core/Internal/Http/MessageBody.cs b/src/Kestrel.Core/Internal/Http/MessageBody.cs index 2fd8c12e60..08054b35aa 100644 --- a/src/Kestrel.Core/Internal/Http/MessageBody.cs +++ b/src/Kestrel.Core/Internal/Http/MessageBody.cs @@ -53,7 +53,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http // buffer.Count is int var actual = (int) Math.Min(readableBuffer.Length, buffer.Count); var slice = readableBuffer.Slice(0, actual); - consumed = readableBuffer.Move(readableBuffer.Start, actual); + consumed = readableBuffer.GetPosition(readableBuffer.Start, actual); slice.CopyTo(buffer); return actual; } @@ -64,7 +64,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http } finally { - _context.RequestBodyPipe.Reader.Advance(consumed); + _context.RequestBodyPipe.Reader.AdvanceTo(consumed); } } } @@ -96,7 +96,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http } finally { - _context.RequestBodyPipe.Reader.Advance(consumed); + _context.RequestBodyPipe.Reader.AdvanceTo(consumed); } } } diff --git a/src/Kestrel.Core/Internal/Http/PipelineExtensions.cs b/src/Kestrel.Core/Internal/Http/PipelineExtensions.cs index e45d8ef5c5..4caefd3a95 100644 --- a/src/Kestrel.Core/Internal/Http/PipelineExtensions.cs +++ b/src/Kestrel.Core/Internal/Http/PipelineExtensions.cs @@ -17,9 +17,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http private static byte[] _numericBytesScratch; [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static ReadOnlySpan ToSpan(this ReadOnlyBuffer buffer) + public static ReadOnlySpan ToSpan(this ReadOnlyBuffer buffer) { - if (buffer.IsSingleSpan) + if (buffer.IsSingleSegment) { return buffer.First.Span; } @@ -45,7 +45,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http return result; } - public unsafe static void WriteAsciiNoValidation(ref this WritableBufferWriter buffer, string data) + public unsafe static void WriteAsciiNoValidation(ref this OutputWriter buffer, string data) { if (string.IsNullOrEmpty(data)) { @@ -74,7 +74,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public unsafe static void WriteNumeric(ref this WritableBufferWriter buffer, ulong number) + public unsafe static void WriteNumeric(ref this OutputWriter buffer, ulong number) { const byte AsciiDigitStart = (byte)'0'; @@ -124,7 +124,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http } [MethodImpl(MethodImplOptions.NoInlining)] - private static void WriteNumericMultiWrite(ref this WritableBufferWriter buffer, ulong number) + private static void WriteNumericMultiWrite(ref this OutputWriter buffer, ulong number) { const byte AsciiDigitStart = (byte)'0'; @@ -141,11 +141,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http while (value != 0); var length = _maxULongByteLength - position; - buffer.Write(byteBuffer, position, length); + buffer.Write(new ReadOnlySpan(byteBuffer, position, length)); } [MethodImpl(MethodImplOptions.NoInlining)] - private unsafe static void WriteAsciiMultiWrite(ref this WritableBufferWriter buffer, string data) + private unsafe static void WriteAsciiMultiWrite(ref this OutputWriter buffer, string data) { var remaining = data.Length; diff --git a/src/Kestrel.Core/Internal/Http2/Http2Connection.cs b/src/Kestrel.Core/Internal/Http2/Http2Connection.cs index c1cb104f50..ca788861ed 100644 --- a/src/Kestrel.Core/Internal/Http2/Http2Connection.cs +++ b/src/Kestrel.Core/Internal/Http2/Http2Connection.cs @@ -3,6 +3,7 @@ using System; using System.Buffers; +using System.Collections; using System.Collections.Sequences; using System.Collections.Concurrent; using System.IO.Pipelines; @@ -84,7 +85,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 public string ConnectionId => _context.ConnectionId; - public IPipeReader Input => _context.Transport.Input; + public PipeReader Input => _context.Transport.Input; public IKestrelTrace Log => _context.ServiceContext.Log; @@ -132,7 +133,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 } finally { - Input.Advance(consumed, examined); + Input.AdvanceTo(consumed, examined); } } @@ -165,7 +166,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 } finally { - Input.Advance(consumed, examined); + Input.AdvanceTo(consumed, examined); } } } @@ -216,7 +217,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 } } - private bool ParsePreface(ReadOnlyBuffer readableBuffer, out Position consumed, out Position examined) + private bool ParsePreface(ReadOnlyBuffer readableBuffer, out SequencePosition consumed, out SequencePosition examined) { consumed = readableBuffer.Start; examined = readableBuffer.End; @@ -226,7 +227,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 return false; } - var span = readableBuffer.IsSingleSpan + var span = readableBuffer.IsSingleSegment ? readableBuffer.First.Span : readableBuffer.ToSpan(); @@ -238,7 +239,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 } } - consumed = examined = readableBuffer.Move(readableBuffer.Start, ClientPreface.Length); + consumed = examined = readableBuffer.GetPosition(readableBuffer.Start, ClientPreface.Length); return true; } diff --git a/src/Kestrel.Core/Internal/Http2/Http2ConnectionContext.cs b/src/Kestrel.Core/Internal/Http2/Http2ConnectionContext.cs index 929bef9f92..73e4217a5c 100644 --- a/src/Kestrel.Core/Internal/Http2/Http2ConnectionContext.cs +++ b/src/Kestrel.Core/Internal/Http2/Http2ConnectionContext.cs @@ -17,7 +17,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 public IPEndPoint LocalEndPoint { get; set; } public IPEndPoint RemoteEndPoint { get; set; } - public IPipeConnection Transport { get; set; } - public IPipeConnection Application { get; set; } + public IDuplexPipe Transport { get; set; } + public IDuplexPipe Application { get; set; } } } diff --git a/src/Kestrel.Core/Internal/Http2/Http2FrameReader.cs b/src/Kestrel.Core/Internal/Http2/Http2FrameReader.cs index 0a2ae72aa0..9673ad57d5 100644 --- a/src/Kestrel.Core/Internal/Http2/Http2FrameReader.cs +++ b/src/Kestrel.Core/Internal/Http2/Http2FrameReader.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Buffers; +using System.Collections; using System.Collections.Sequences; using System.IO.Pipelines; @@ -9,7 +10,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 { public static class Http2FrameReader { - public static bool ReadFrame(ReadOnlyBuffer readableBuffer, Http2Frame frame, out Position consumed, out Position examined) + public static bool ReadFrame(ReadOnlyBuffer readableBuffer, Http2Frame frame, out SequencePosition consumed, out SequencePosition examined) { consumed = readableBuffer.Start; examined = readableBuffer.End; @@ -28,7 +29,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 } readableBuffer.Slice(Http2Frame.HeaderLength, frame.Length).CopyTo(frame.Payload); - consumed = examined = readableBuffer.Move(readableBuffer.Start, Http2Frame.HeaderLength + frame.Length); + consumed = examined = readableBuffer.GetPosition(readableBuffer.Start, Http2Frame.HeaderLength + frame.Length); return true; } diff --git a/src/Kestrel.Core/Internal/Http2/Http2FrameWriter.cs b/src/Kestrel.Core/Internal/Http2/Http2FrameWriter.cs index a34bf0ef53..0540beb0fa 100644 --- a/src/Kestrel.Core/Internal/Http2/Http2FrameWriter.cs +++ b/src/Kestrel.Core/Internal/Http2/Http2FrameWriter.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Buffers; using System.Collections.Generic; using System.IO.Pipelines; using System.Threading; @@ -20,12 +21,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 private readonly Http2Frame _outgoingFrame = new Http2Frame(); private readonly object _writeLock = new object(); private readonly HPackEncoder _hpackEncoder = new HPackEncoder(); - private readonly IPipeWriter _outputWriter; - private readonly IPipeReader _outputReader; + private readonly PipeWriter _outputWriter; + private readonly PipeReader _outputReader; private bool _completed; - public Http2FrameWriter(IPipeWriter outputPipeWriter, IPipeReader outputPipeReader) + public Http2FrameWriter(PipeWriter outputPipeWriter, PipeReader outputPipeReader) { _outputWriter = outputPipeWriter; _outputReader = outputPipeReader; @@ -48,7 +49,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 public Task FlushAsync(CancellationToken cancellationToken) { - return WriteAsync(Constants.EmptyData); + lock (_writeLock) + { + return WriteAsync(Constants.EmptyData); + } } public Task Write100ContinueAsync(int streamId) @@ -185,9 +189,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 return; } - var writeableBuffer = _outputWriter.Alloc(1); - writeableBuffer.Write(data); - writeableBuffer.Commit(); + _outputWriter.Write(data); + _outputWriter.Commit(); } // Must be called with _writeLock @@ -198,9 +201,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 return; } - var writeableBuffer = _outputWriter.Alloc(1); - writeableBuffer.Write(data); - await writeableBuffer.FlushAsync(cancellationToken); + _outputWriter.Write(data); + await _outputWriter.FlushAsync(cancellationToken); } private static IEnumerable> EnumerateHeaders(IHeaderDictionary headers) diff --git a/src/Kestrel.Core/Internal/Http2/Http2OutputProducer.cs b/src/Kestrel.Core/Internal/Http2/Http2OutputProducer.cs index 93f549b5ce..d1aa31df72 100644 --- a/src/Kestrel.Core/Internal/Http2/Http2OutputProducer.cs +++ b/src/Kestrel.Core/Internal/Http2/Http2OutputProducer.cs @@ -30,7 +30,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 // TODO: RST_STREAM? } - public Task WriteAsync(Action callback, T state) + public Task WriteAsync(Action callback, T state) { throw new NotImplementedException(); } diff --git a/src/Kestrel.Core/Internal/Http2/Http2Stream.cs b/src/Kestrel.Core/Internal/Http2/Http2Stream.cs index 1d96e3f7be..6d8fc9136f 100644 --- a/src/Kestrel.Core/Internal/Http2/Http2Stream.cs +++ b/src/Kestrel.Core/Internal/Http2/Http2Stream.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Buffers; using System.IO.Pipelines; using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Core.Features; @@ -78,19 +79,17 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 { if (data.Count > 0) { - var writableBuffer = RequestBodyPipe.Writer.Alloc(1); - try { - writableBuffer.Write(data); + RequestBodyPipe.Writer.Write(data); } finally { - writableBuffer.Commit(); + RequestBodyPipe.Writer.Commit(); } RequestBodyStarted = true; - await writableBuffer.FlushAsync(); + await RequestBodyPipe.Writer.FlushAsync(); } if (endStream) diff --git a/src/Kestrel.Core/Internal/HttpConnection.cs b/src/Kestrel.Core/Internal/HttpConnection.cs index c927017622..471d8194a2 100644 --- a/src/Kestrel.Core/Internal/HttpConnection.cs +++ b/src/Kestrel.Core/Internal/HttpConnection.cs @@ -29,7 +29,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal private readonly TaskCompletionSource _socketClosedTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); private IList _adaptedConnections; - private IPipeConnection _adaptedTransport; + private IDuplexPipe _adaptedTransport; private readonly object _protocolSelectionLock = new object(); private ProtocolSelectionState _protocolSelectionState = ProtocolSelectionState.Initializing; @@ -75,18 +75,18 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal ( pool: MemoryPool, readerScheduler: _context.ServiceContext.ThreadPool, - writerScheduler: Scheduler.Inline, - maximumSizeHigh: _context.ServiceContext.ServerOptions.Limits.MaxRequestBufferSize ?? 0, - maximumSizeLow: _context.ServiceContext.ServerOptions.Limits.MaxRequestBufferSize ?? 0 + writerScheduler: PipeScheduler.Inline, + pauseWriterThreshold: _context.ServiceContext.ServerOptions.Limits.MaxRequestBufferSize ?? 0, + resumeWriterThreshold: _context.ServiceContext.ServerOptions.Limits.MaxRequestBufferSize ?? 0 ); internal PipeOptions AdaptedOutputPipeOptions => new PipeOptions ( pool: MemoryPool, - readerScheduler: Scheduler.Inline, - writerScheduler: Scheduler.Inline, - maximumSizeHigh: _context.ServiceContext.ServerOptions.Limits.MaxResponseBufferSize ?? 0, - maximumSizeLow: _context.ServiceContext.ServerOptions.Limits.MaxResponseBufferSize ?? 0 + readerScheduler: PipeScheduler.Inline, + writerScheduler: PipeScheduler.Inline, + pauseWriterThreshold: _context.ServiceContext.ServerOptions.Limits.MaxResponseBufferSize ?? 0, + resumeWriterThreshold: _context.ServiceContext.ServerOptions.Limits.MaxResponseBufferSize ?? 0 ); private IKestrelTrace Log => _context.ServiceContext.Log; @@ -196,13 +196,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal } // For testing only - internal void Initialize(IPipeConnection transport, IPipeConnection application) + internal void Initialize(IDuplexPipe transport, IDuplexPipe application) { _requestProcessor = _http1Connection = CreateHttp1Connection(transport, application); _protocolSelectionState = ProtocolSelectionState.Selected; } - private Http1Connection CreateHttp1Connection(IPipeConnection transport, IPipeConnection application) + private Http1Connection CreateHttp1Connection(IDuplexPipe transport, IDuplexPipe application) { return new Http1Connection(new Http1ConnectionContext { @@ -218,7 +218,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal }); } - private Http2Connection CreateHttp2Connection(IPipeConnection transport, IPipeConnection application) + private Http2Connection CreateHttp2Connection(IDuplexPipe transport, IDuplexPipe application) { return new Http2Connection(new Http2ConnectionContext { diff --git a/src/Kestrel.Core/Internal/HttpConnectionContext.cs b/src/Kestrel.Core/Internal/HttpConnectionContext.cs index dcd5563e79..445d07a644 100644 --- a/src/Kestrel.Core/Internal/HttpConnectionContext.cs +++ b/src/Kestrel.Core/Internal/HttpConnectionContext.cs @@ -21,7 +21,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal public MemoryPool MemoryPool { get; set; } public IPEndPoint LocalEndPoint { get; set; } public IPEndPoint RemoteEndPoint { get; set; } - public IPipeConnection Transport { get; set; } - public IPipeConnection Application { get; set; } + public IDuplexPipe Transport { get; set; } + public IDuplexPipe Application { get; set; } } } diff --git a/src/Kestrel.Core/Internal/Infrastructure/KestrelThreadPool.cs b/src/Kestrel.Core/Internal/Infrastructure/KestrelThreadPool.cs index 54375c3aaa..6fe8810a3f 100644 --- a/src/Kestrel.Core/Internal/Infrastructure/KestrelThreadPool.cs +++ b/src/Kestrel.Core/Internal/Infrastructure/KestrelThreadPool.cs @@ -2,12 +2,11 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.IO.Pipelines; using System.Threading; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure { - public abstract class KestrelThreadPool: Scheduler + public abstract class KestrelThreadPool : PipeScheduler { public abstract void Run(Action action); public abstract void UnsafeRun(WaitCallback action, object state); diff --git a/src/Kestrel.Core/Internal/Infrastructure/LoggingThreadPool.cs b/src/Kestrel.Core/Internal/Infrastructure/LoggingThreadPool.cs index 1d90a7b681..70c90bd1ea 100644 --- a/src/Kestrel.Core/Internal/Infrastructure/LoggingThreadPool.cs +++ b/src/Kestrel.Core/Internal/Infrastructure/LoggingThreadPool.cs @@ -42,12 +42,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure public override void Run(Action action) { - ThreadPool.QueueUserWorkItem(_runAction, action); + System.Threading.ThreadPool.QueueUserWorkItem(_runAction, action); } public override void UnsafeRun(WaitCallback action, object state) { - ThreadPool.QueueUserWorkItem(action, state); + System.Threading.ThreadPool.QueueUserWorkItem(action, state); } public override void Schedule(Action action) diff --git a/src/Kestrel.Transport.Abstractions/Internal/TransportConnection.Features.cs b/src/Kestrel.Transport.Abstractions/Internal/TransportConnection.Features.cs index 5af87f3293..98308725e6 100644 --- a/src/Kestrel.Transport.Abstractions/Internal/TransportConnection.Features.cs +++ b/src/Kestrel.Transport.Abstractions/Internal/TransportConnection.Features.cs @@ -98,13 +98,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal MemoryPool IConnectionTransportFeature.MemoryPool => MemoryPool; - IPipeConnection IConnectionTransportFeature.Transport + IDuplexPipe IConnectionTransportFeature.Transport { get => Transport; set => Transport = value; } - IPipeConnection IConnectionTransportFeature.Application + IDuplexPipe IConnectionTransportFeature.Application { get => Application; set => Application = value; diff --git a/src/Kestrel.Transport.Abstractions/Internal/TransportConnection.cs b/src/Kestrel.Transport.Abstractions/Internal/TransportConnection.cs index 3889bff14f..bd5193738f 100644 --- a/src/Kestrel.Transport.Abstractions/Internal/TransportConnection.cs +++ b/src/Kestrel.Transport.Abstractions/Internal/TransportConnection.cs @@ -23,13 +23,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal public string ConnectionId { get; set; } public virtual MemoryPool MemoryPool { get; } - public virtual Scheduler InputWriterScheduler { get; } - public virtual Scheduler OutputReaderScheduler { get; } + public virtual PipeScheduler InputWriterScheduler { get; } + public virtual PipeScheduler OutputReaderScheduler { get; } - public IPipeConnection Transport { get; set; } - public IPipeConnection Application { get; set; } + public IDuplexPipe Transport { get; set; } + public IDuplexPipe Application { get; set; } - public IPipeWriter Input => Application.Output; - public IPipeReader Output => Application.Input; + public PipeWriter Input => Application.Output; + public PipeReader Output => Application.Input; } } diff --git a/src/Kestrel.Transport.Libuv/Internal/LibuvConnection.cs b/src/Kestrel.Transport.Libuv/Internal/LibuvConnection.cs index 35cbdf0771..a606d32f07 100644 --- a/src/Kestrel.Transport.Libuv/Internal/LibuvConnection.cs +++ b/src/Kestrel.Transport.Libuv/Internal/LibuvConnection.cs @@ -27,7 +27,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal private readonly UvStreamHandle _socket; - private WritableBuffer? _currentWritableBuffer; private MemoryHandle _bufferHandle; public LibuvConnection(ListenerContext context, UvStreamHandle socket) : base(context) @@ -107,13 +106,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal private unsafe LibuvFunctions.uv_buf_t OnAlloc(UvStreamHandle handle, int suggestedSize) { - Debug.Assert(_currentWritableBuffer == null); - var currentWritableBuffer = Input.Alloc(MinAllocBufferSize); - _currentWritableBuffer = currentWritableBuffer; + var currentWritableBuffer = Input.GetMemory(MinAllocBufferSize); + _bufferHandle = currentWritableBuffer.Retain(true); - _bufferHandle = currentWritableBuffer.Buffer.Retain(true); - - return handle.Libuv.buf_init((IntPtr)_bufferHandle.Pointer, currentWritableBuffer.Buffer.Length); + return handle.Libuv.buf_init((IntPtr)_bufferHandle.Pointer, currentWritableBuffer.Length); } private static void ReadCallback(UvStreamHandle handle, int status, object state) @@ -127,17 +123,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal { // EAGAIN/EWOULDBLOCK so just return the buffer. // http://docs.libuv.org/en/v1.x/stream.html#c.uv_read_cb - Debug.Assert(_currentWritableBuffer != null); - _currentWritableBuffer.Value.Commit(); + Input.Commit(); } else if (status > 0) { Log.ConnectionRead(ConnectionId, status); - Debug.Assert(_currentWritableBuffer != null); - var currentWritableBuffer = _currentWritableBuffer.Value; - currentWritableBuffer.Advance(status); - var flushTask = currentWritableBuffer.FlushAsync(); + Input.Advance(status); + var flushTask = Input.FlushAsync(); if (!flushTask.IsCompleted) { @@ -149,7 +142,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal else { // Given a negative status, it's possible that OnAlloc wasn't called. - _currentWritableBuffer?.Commit(); + Input.Commit(); _socket.ReadStop(); IOException error = null; @@ -180,7 +173,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal } // Cleanup state from last OnAlloc. This is safe even if OnAlloc wasn't called. - _currentWritableBuffer = null; _bufferHandle.Dispose(); } diff --git a/src/Kestrel.Transport.Libuv/Internal/LibuvConnectionContext.cs b/src/Kestrel.Transport.Libuv/Internal/LibuvConnectionContext.cs index be2ca1d255..075a57752c 100644 --- a/src/Kestrel.Transport.Libuv/Internal/LibuvConnectionContext.cs +++ b/src/Kestrel.Transport.Libuv/Internal/LibuvConnectionContext.cs @@ -19,7 +19,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal public ListenerContext ListenerContext { get; set; } public override MemoryPool MemoryPool => ListenerContext.Thread.MemoryPool; - public override Scheduler InputWriterScheduler => ListenerContext.Thread; - public override Scheduler OutputReaderScheduler => ListenerContext.Thread; + public override PipeScheduler InputWriterScheduler => ListenerContext.Thread; + public override PipeScheduler OutputReaderScheduler => ListenerContext.Thread; } } diff --git a/src/Kestrel.Transport.Libuv/Internal/LibuvOutputConsumer.cs b/src/Kestrel.Transport.Libuv/Internal/LibuvOutputConsumer.cs index ccf1362b6f..298c333d05 100644 --- a/src/Kestrel.Transport.Libuv/Internal/LibuvOutputConsumer.cs +++ b/src/Kestrel.Transport.Libuv/Internal/LibuvOutputConsumer.cs @@ -14,10 +14,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal private readonly UvStreamHandle _socket; private readonly string _connectionId; private readonly ILibuvTrace _log; - private readonly IPipeReader _pipe; + private readonly PipeReader _pipe; public LibuvOutputConsumer( - IPipeReader pipe, + PipeReader pipe, LibuvThread thread, UvStreamHandle socket, string connectionId, @@ -94,7 +94,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal } finally { - _pipe.Advance(consumed); + _pipe.AdvanceTo(consumed); } } } diff --git a/src/Kestrel.Transport.Libuv/Internal/LibuvThread.cs b/src/Kestrel.Transport.Libuv/Internal/LibuvThread.cs index ba4396fe32..db3682fe32 100644 --- a/src/Kestrel.Transport.Libuv/Internal/LibuvThread.cs +++ b/src/Kestrel.Transport.Libuv/Internal/LibuvThread.cs @@ -15,7 +15,7 @@ using Microsoft.Extensions.Logging; namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal { - public class LibuvThread : Scheduler + public class LibuvThread : PipeScheduler { // maximum times the work queues swapped and are processed in a single pass // as completing a task may immediately have write data to put on the network diff --git a/src/Kestrel.Transport.Libuv/Internal/Networking/UvWriteReq.cs b/src/Kestrel.Transport.Libuv/Internal/Networking/UvWriteReq.cs index c25f2aec28..e720f2700c 100644 --- a/src/Kestrel.Transport.Libuv/Internal/Networking/UvWriteReq.cs +++ b/src/Kestrel.Transport.Libuv/Internal/Networking/UvWriteReq.cs @@ -49,7 +49,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networkin _bufs = handle + requestSize; } - public LibuvAwaitable WriteAsync(UvStreamHandle handle, ReadOnlyBuffer buffer) + public LibuvAwaitable WriteAsync(UvStreamHandle handle, ReadOnlyBuffer buffer) { Write(handle, buffer, LibuvAwaitable.Callback, _awaitable); return _awaitable; @@ -63,14 +63,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networkin private unsafe void Write( UvStreamHandle handle, - ReadOnlyBuffer buffer, + ReadOnlyBuffer buffer, Action callback, object state) { try { var nBuffers = 0; - if (buffer.IsSingleSpan) + if (buffer.IsSingleSegment) { nBuffers = 1; } diff --git a/src/Kestrel.Transport.Sockets/Internal/SocketConnection.cs b/src/Kestrel.Transport.Sockets/Internal/SocketConnection.cs index ff7c678cd7..cf128c05f3 100644 --- a/src/Kestrel.Transport.Sockets/Internal/SocketConnection.cs +++ b/src/Kestrel.Transport.Sockets/Internal/SocketConnection.cs @@ -52,8 +52,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal } public override MemoryPool MemoryPool { get; } - public override Scheduler InputWriterScheduler => Scheduler.Inline; - public override Scheduler OutputReaderScheduler => Scheduler.TaskRun; + public override PipeScheduler InputWriterScheduler => PipeScheduler.Inline; + public override PipeScheduler OutputReaderScheduler => PipeScheduler.ThreadPool; public async Task StartAsync(IConnectionHandler connectionHandler) { @@ -96,11 +96,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal while (true) { // Ensure we have some reasonable amount of buffer space - var buffer = Input.Alloc(MinAllocBufferSize); + var buffer = Input.GetMemory(MinAllocBufferSize); try { - var bytesReceived = await _receiver.ReceiveAsync(buffer.Buffer); + var bytesReceived = await _receiver.ReceiveAsync(buffer); if (bytesReceived == 0) { @@ -109,14 +109,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal break; } - buffer.Advance(bytesReceived); + Input.Advance(bytesReceived); } finally { - buffer.Commit(); + Input.Commit(); } - var flushTask = buffer.FlushAsync(); + var flushTask = Input.FlushAsync(); if (!flushTask.IsCompleted) { @@ -211,7 +211,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal } finally { - Output.Advance(buffer.End); + Output.AdvanceTo(buffer.End); } } } diff --git a/src/Kestrel.Transport.Sockets/Internal/SocketSender.cs b/src/Kestrel.Transport.Sockets/Internal/SocketSender.cs index 8f5197f2ad..be71f3f9df 100644 --- a/src/Kestrel.Transport.Sockets/Internal/SocketSender.cs +++ b/src/Kestrel.Transport.Sockets/Internal/SocketSender.cs @@ -26,9 +26,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal _eventArgs.Completed += (_, e) => ((SocketAwaitable)e.UserToken).Complete(e.BytesTransferred, e.SocketError); } - public SocketAwaitable SendAsync(ReadOnlyBuffer buffers) + public SocketAwaitable SendAsync(ReadOnlyBuffer buffers) { - if (buffers.IsSingleSpan) + if (buffers.IsSingleSegment) { return SendAsync(buffers.First); } @@ -75,10 +75,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal return _awaitable; } - private List> GetBufferList(ReadOnlyBuffer buffer) + private List> GetBufferList(ReadOnlyBuffer buffer) { Debug.Assert(!buffer.IsEmpty); - Debug.Assert(!buffer.IsSingleSpan); + Debug.Assert(!buffer.IsSingleSegment); if (_bufferList == null) { diff --git a/src/Protocols.Abstractions/ConnectionContext.cs b/src/Protocols.Abstractions/ConnectionContext.cs index afe2149576..f4fb2dbae9 100644 --- a/src/Protocols.Abstractions/ConnectionContext.cs +++ b/src/Protocols.Abstractions/ConnectionContext.cs @@ -13,7 +13,7 @@ namespace Microsoft.AspNetCore.Protocols public abstract IFeatureCollection Features { get; } - public abstract IPipeConnection Transport { get; set; } + public abstract IDuplexPipe Transport { get; set; } public abstract MemoryPool MemoryPool { get; } } diff --git a/src/Protocols.Abstractions/DefaultConnectionContext.cs b/src/Protocols.Abstractions/DefaultConnectionContext.cs index 047ed92eab..18ac26c673 100644 --- a/src/Protocols.Abstractions/DefaultConnectionContext.cs +++ b/src/Protocols.Abstractions/DefaultConnectionContext.cs @@ -30,7 +30,7 @@ namespace Microsoft.AspNetCore.Protocols public override MemoryPool MemoryPool => ConnectionTransportFeature.MemoryPool; - public override IPipeConnection Transport + public override IDuplexPipe Transport { get => ConnectionTransportFeature.Transport; set => ConnectionTransportFeature.Transport = value; diff --git a/src/Protocols.Abstractions/Features/IConnectionTransportFeature.cs b/src/Protocols.Abstractions/Features/IConnectionTransportFeature.cs index 2d7f3b5746..54e21226e4 100644 --- a/src/Protocols.Abstractions/Features/IConnectionTransportFeature.cs +++ b/src/Protocols.Abstractions/Features/IConnectionTransportFeature.cs @@ -8,12 +8,12 @@ namespace Microsoft.AspNetCore.Protocols.Features { MemoryPool MemoryPool { get; } - IPipeConnection Transport { get; set; } + IDuplexPipe Transport { get; set; } - IPipeConnection Application { get; set; } + IDuplexPipe Application { get; set; } - Scheduler InputWriterScheduler { get; } + PipeScheduler InputWriterScheduler { get; } - Scheduler OutputReaderScheduler { get; } + PipeScheduler OutputReaderScheduler { get; } } } diff --git a/src/Protocols.Abstractions/PipeConnection.cs b/src/Protocols.Abstractions/PipeConnection.cs index 31b3a7a74c..5b3ab2a50b 100644 --- a/src/Protocols.Abstractions/PipeConnection.cs +++ b/src/Protocols.Abstractions/PipeConnection.cs @@ -4,17 +4,17 @@ using System.Text; namespace System.IO.Pipelines { - public class PipeConnection : IPipeConnection + public class PipeConnection : IDuplexPipe { - public PipeConnection(IPipeReader reader, IPipeWriter writer) + public PipeConnection(PipeReader reader, PipeWriter writer) { Input = reader; Output = writer; } - public IPipeReader Input { get; } + public PipeReader Input { get; } - public IPipeWriter Output { get; } + public PipeWriter Output { get; } public void Dispose() { diff --git a/src/Protocols.Abstractions/PipeFactoryExtensions.cs b/src/Protocols.Abstractions/PipeFactoryExtensions.cs index e6b11e5654..01abf37428 100644 --- a/src/Protocols.Abstractions/PipeFactoryExtensions.cs +++ b/src/Protocols.Abstractions/PipeFactoryExtensions.cs @@ -4,12 +4,12 @@ namespace System.IO.Pipelines { public static class PipeFactory { - public static (IPipeConnection Transport, IPipeConnection Application) CreateConnectionPair(MemoryPool memoryPool) + public static (IDuplexPipe Transport, IDuplexPipe Application) CreateConnectionPair(MemoryPool memoryPool) { return CreateConnectionPair(new PipeOptions(memoryPool), new PipeOptions(memoryPool)); } - public static (IPipeConnection Transport, IPipeConnection Application) CreateConnectionPair(PipeOptions inputOptions, PipeOptions outputOptions) + public static (IDuplexPipe Transport, IDuplexPipe Application) CreateConnectionPair(PipeOptions inputOptions, PipeOptions outputOptions) { var input = new Pipe(inputOptions); var output = new Pipe(outputOptions); diff --git a/test/Kestrel.Core.Tests/ConnectionHandlerTests.cs b/test/Kestrel.Core.Tests/ConnectionHandlerTests.cs index 42264410db..13aabd72ad 100644 --- a/test/Kestrel.Core.Tests/ConnectionHandlerTests.cs +++ b/test/Kestrel.Core.Tests/ConnectionHandlerTests.cs @@ -1,9 +1,7 @@ -using System; -using System.Buffers; +using System.Buffers; using System.Collections.Generic; using System.IO.Pipelines; using System.Linq; -using System.Text; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Http.Features; @@ -55,12 +53,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests public MemoryPool MemoryPool { get; } = new MemoryPool(); - public IPipeConnection Transport { get; set; } - public IPipeConnection Application { get; set; } + public IDuplexPipe Transport { get; set; } + public IDuplexPipe Application { get; set; } - public Scheduler InputWriterScheduler => Scheduler.TaskRun; + public PipeScheduler InputWriterScheduler => PipeScheduler.ThreadPool; - public Scheduler OutputReaderScheduler => Scheduler.TaskRun; + public PipeScheduler OutputReaderScheduler => PipeScheduler.ThreadPool; public string ConnectionId { get; set; } } diff --git a/test/Kestrel.Core.Tests/Http1ConnectionTests.cs b/test/Kestrel.Core.Tests/Http1ConnectionTests.cs index 3c1eba171b..53f54e3a5e 100644 --- a/test/Kestrel.Core.Tests/Http1ConnectionTests.cs +++ b/test/Kestrel.Core.Tests/Http1ConnectionTests.cs @@ -28,14 +28,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests { public class Http1ConnectionTests : IDisposable { - private readonly IPipeConnection _transport; - private readonly IPipeConnection _application; + private readonly IDuplexPipe _transport; + private readonly IDuplexPipe _application; private readonly TestHttp1Connection _http1Connection; private readonly ServiceContext _serviceContext; private readonly Http1ConnectionContext _http1ConnectionContext; private readonly MemoryPool _pipelineFactory; - private Position _consumed; - private Position _examined; + private SequencePosition _consumed; + private SequencePosition _examined; private Mock _timeoutControl; public Http1ConnectionTests() @@ -84,7 +84,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests var readableBuffer = (await _transport.Input.ReadAsync()).Buffer; var exception = Assert.Throws(() => _http1Connection.TakeMessageHeaders(readableBuffer, out _consumed, out _examined)); - _transport.Input.Advance(_consumed, _examined); + _transport.Input.AdvanceTo(_consumed, _examined); Assert.Equal(CoreStrings.BadRequest_HeadersExceedMaxTotalSize, exception.Message); Assert.Equal(StatusCodes.Status431RequestHeaderFieldsTooLarge, exception.StatusCode); @@ -100,7 +100,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests var readableBuffer = (await _transport.Input.ReadAsync()).Buffer; var exception = Assert.Throws(() => _http1Connection.TakeMessageHeaders(readableBuffer, out _consumed, out _examined)); - _transport.Input.Advance(_consumed, _examined); + _transport.Input.AdvanceTo(_consumed, _examined); Assert.Equal(CoreStrings.BadRequest_TooManyHeaders, exception.Message); Assert.Equal(StatusCodes.Status431RequestHeaderFieldsTooLarge, exception.StatusCode); @@ -205,7 +205,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests var readableBuffer = (await _transport.Input.ReadAsync()).Buffer; var takeMessageHeaders = _http1Connection.TakeMessageHeaders(readableBuffer, out _consumed, out _examined); - _transport.Input.Advance(_consumed, _examined); + _transport.Input.AdvanceTo(_consumed, _examined); Assert.True(takeMessageHeaders); Assert.Equal(1, _http1Connection.RequestHeaders.Count); @@ -217,7 +217,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests readableBuffer = (await _transport.Input.ReadAsync()).Buffer; takeMessageHeaders = _http1Connection.TakeMessageHeaders(readableBuffer, out _consumed, out _examined); - _transport.Input.Advance(_consumed, _examined); + _transport.Input.AdvanceTo(_consumed, _examined); Assert.True(takeMessageHeaders); Assert.Equal(1, _http1Connection.RequestHeaders.Count); @@ -342,7 +342,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests var readableBuffer = (await _transport.Input.ReadAsync()).Buffer; var returnValue = _http1Connection.TakeStartLine(readableBuffer, out _consumed, out _examined); - _transport.Input.Advance(_consumed, _examined); + _transport.Input.AdvanceTo(_consumed, _examined); Assert.True(returnValue); Assert.Equal(expectedMethod, _http1Connection.Method); @@ -365,7 +365,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests var readableBuffer = (await _transport.Input.ReadAsync()).Buffer; var returnValue = _http1Connection.TakeStartLine(readableBuffer, out _consumed, out _examined); - _transport.Input.Advance(_consumed, _examined); + _transport.Input.AdvanceTo(_consumed, _examined); Assert.True(returnValue); Assert.Equal(expectedRawTarget, _http1Connection.RawTarget); @@ -379,7 +379,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests await _application.Output.WriteAsync(Encoding.ASCII.GetBytes("G")); _http1Connection.ParseRequest((await _transport.Input.ReadAsync()).Buffer, out _consumed, out _examined); - _transport.Input.Advance(_consumed, _examined); + _transport.Input.AdvanceTo(_consumed, _examined); var expectedRequestHeadersTimeout = _serviceContext.ServerOptions.Limits.RequestHeadersTimeout.Ticks; _timeoutControl.Verify(cc => cc.ResetTimeout(expectedRequestHeadersTimeout, TimeoutAction.SendTimeoutResponse)); @@ -395,7 +395,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests var readableBuffer = (await _transport.Input.ReadAsync()).Buffer; var exception = Assert.Throws(() => _http1Connection.TakeStartLine(readableBuffer, out _consumed, out _examined)); - _transport.Input.Advance(_consumed, _examined); + _transport.Input.AdvanceTo(_consumed, _examined); Assert.Equal(CoreStrings.BadRequest_RequestLineTooLong, exception.Message); Assert.Equal(StatusCodes.Status414UriTooLong, exception.StatusCode); @@ -410,7 +410,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests var exception = Assert.Throws(() => _http1Connection.TakeStartLine(readableBuffer, out _consumed, out _examined)); - _transport.Input.Advance(_consumed, _examined); + _transport.Input.AdvanceTo(_consumed, _examined); Assert.Equal(CoreStrings.FormatBadRequest_InvalidRequestTarget_Detail(target), exception.Message); } @@ -424,7 +424,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests var exception = Assert.Throws(() => _http1Connection.TakeStartLine(readableBuffer, out _consumed, out _examined)); - _transport.Input.Advance(_consumed, _examined); + _transport.Input.AdvanceTo(_consumed, _examined); Assert.Equal(CoreStrings.FormatBadRequest_InvalidRequestTarget_Detail(target.EscapeNonPrintable()), exception.Message); } @@ -440,7 +440,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests var exception = Assert.Throws(() => _http1Connection.TakeStartLine(readableBuffer, out _consumed, out _examined)); - _transport.Input.Advance(_consumed, _examined); + _transport.Input.AdvanceTo(_consumed, _examined); Assert.Equal(CoreStrings.FormatBadRequest_InvalidRequestLine_Detail(requestLine.EscapeNonPrintable()), exception.Message); } @@ -456,7 +456,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests var exception = Assert.Throws(() => _http1Connection.TakeStartLine(readableBuffer, out _consumed, out _examined)); - _transport.Input.Advance(_consumed, _examined); + _transport.Input.AdvanceTo(_consumed, _examined); Assert.Equal(CoreStrings.FormatBadRequest_InvalidRequestTarget_Detail(target.EscapeNonPrintable()), exception.Message); } @@ -472,7 +472,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests var exception = Assert.Throws(() => _http1Connection.TakeStartLine(readableBuffer, out _consumed, out _examined)); - _transport.Input.Advance(_consumed, _examined); + _transport.Input.AdvanceTo(_consumed, _examined); Assert.Equal(CoreStrings.FormatBadRequest_InvalidRequestTarget_Detail(target.EscapeNonPrintable()), exception.Message); } @@ -486,7 +486,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests var exception = Assert.Throws(() => _http1Connection.TakeStartLine(readableBuffer, out _consumed, out _examined)); - _transport.Input.Advance(_consumed, _examined); + _transport.Input.AdvanceTo(_consumed, _examined); Assert.Equal(405, exception.StatusCode); Assert.Equal(CoreStrings.BadRequest_MethodNotAllowed, exception.Message); @@ -685,7 +685,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests var exception = Assert.Throws(() => _http1Connection.TakeStartLine(readableBuffer, out _consumed, out _examined)); - _transport.Input.Advance(_consumed, _examined); + _transport.Input.AdvanceTo(_consumed, _examined); Assert.Equal(CoreStrings.FormatBadRequest_InvalidRequestTarget_Detail(string.Empty), exception.Message); Assert.Equal(StatusCodes.Status400BadRequest, exception.StatusCode); diff --git a/test/Kestrel.Core.Tests/Http2ConnectionTests.cs b/test/Kestrel.Core.Tests/Http2ConnectionTests.cs index a9976e08fb..462e7160e2 100644 --- a/test/Kestrel.Core.Tests/Http2ConnectionTests.cs +++ b/test/Kestrel.Core.Tests/Http2ConnectionTests.cs @@ -94,7 +94,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests private static readonly byte[] _maxData = Encoding.ASCII.GetBytes(new string('a', Http2Frame.MinAllowedMaxFrameSize)); private readonly MemoryPool _memoryPool = new MemoryPool(); - private readonly (IPipeConnection Transport, IPipeConnection Application) _pair; + private readonly (IDuplexPipe Transport, IDuplexPipe Application) _pair; private readonly TestApplicationErrorLogger _logger; private readonly Http2ConnectionContext _connectionContext; private readonly Http2Connection _connection; @@ -2138,7 +2138,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests private async Task SendAsync(ArraySegment span) { - var writableBuffer = _pair.Application.Output.Alloc(1); + var writableBuffer = _pair.Application.Output; writableBuffer.Write(span); await writableBuffer.FlushAsync(); } @@ -2466,7 +2466,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests } finally { - _pair.Application.Input.Advance(consumed, examined); + _pair.Application.Input.AdvanceTo(consumed, examined); } } } diff --git a/test/Kestrel.Core.Tests/HttpParserTests.cs b/test/Kestrel.Core.Tests/HttpParserTests.cs index 2a1d3dd142..48f3406533 100644 --- a/test/Kestrel.Core.Tests/HttpParserTests.cs +++ b/test/Kestrel.Core.Tests/HttpParserTests.cs @@ -35,7 +35,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests string expectedVersion) { var parser = CreateParser(Mock.Of()); - var buffer = new ReadOnlyBuffer(Encoding.ASCII.GetBytes(requestLine)); + var buffer = new ReadOnlyBuffer(Encoding.ASCII.GetBytes(requestLine)); var requestHandler = new RequestHandler(); Assert.True(parser.ParseRequestLine(requestHandler, buffer, out var consumed, out var examined)); @@ -45,8 +45,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests Assert.Equal(requestHandler.RawTarget, expectedRawTarget); Assert.Equal(requestHandler.RawPath, expectedRawPath); Assert.Equal(requestHandler.Version, expectedVersion); - Assert.Equal(buffer.End, consumed); - Assert.Equal(buffer.End, examined); + Assert.True(buffer.Slice(consumed).IsEmpty); + Assert.True(buffer.Slice(examined).IsEmpty); } [Theory] @@ -54,7 +54,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests public void ParseRequestLineReturnsFalseWhenGivenIncompleteRequestLines(string requestLine) { var parser = CreateParser(Mock.Of()); - var buffer = new ReadOnlyBuffer(Encoding.ASCII.GetBytes(requestLine)); + var buffer = new ReadOnlyBuffer(Encoding.ASCII.GetBytes(requestLine)); var requestHandler = new RequestHandler(); Assert.False(parser.ParseRequestLine(requestHandler, buffer, out var consumed, out var examined)); @@ -65,13 +65,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests public void ParseRequestLineDoesNotConsumeIncompleteRequestLine(string requestLine) { var parser = CreateParser(Mock.Of()); - var buffer = new ReadOnlyBuffer(Encoding.ASCII.GetBytes(requestLine)); + var buffer = new ReadOnlyBuffer(Encoding.ASCII.GetBytes(requestLine)); var requestHandler = new RequestHandler(); Assert.False(parser.ParseRequestLine(requestHandler, buffer, out var consumed, out var examined)); Assert.Equal(buffer.Start, consumed); - Assert.Equal(buffer.End, examined); + Assert.True(buffer.Slice(examined).IsEmpty); } [Theory] @@ -84,7 +84,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests .Returns(true); var parser = CreateParser(mockTrace.Object); - var buffer = new ReadOnlyBuffer(Encoding.ASCII.GetBytes(requestLine)); + var buffer = new ReadOnlyBuffer(Encoding.ASCII.GetBytes(requestLine)); var requestHandler = new RequestHandler(); var exception = Assert.Throws(() => @@ -106,7 +106,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests .Returns(true); var parser = CreateParser(mockTrace.Object); - var buffer = new ReadOnlyBuffer(Encoding.ASCII.GetBytes(requestLine)); + var buffer = new ReadOnlyBuffer(Encoding.ASCII.GetBytes(requestLine)); var requestHandler = new RequestHandler(); var exception = Assert.Throws(() => @@ -128,7 +128,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests .Returns(true); var parser = CreateParser(mockTrace.Object); - var buffer = new ReadOnlyBuffer(Encoding.ASCII.GetBytes(requestLine)); + var buffer = new ReadOnlyBuffer(Encoding.ASCII.GetBytes(requestLine)); var requestHandler = new RequestHandler(); var exception = Assert.Throws(() => @@ -179,7 +179,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests { var parser = CreateParser(Mock.Of()); - var buffer = new ReadOnlyBuffer(Encoding.ASCII.GetBytes(rawHeaders)); + var buffer = new ReadOnlyBuffer(Encoding.ASCII.GetBytes(rawHeaders)); var requestHandler = new RequestHandler(); Assert.False(parser.ParseHeaders(requestHandler, buffer, out var consumed, out var examined, out var consumedBytes)); } @@ -204,12 +204,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests { var parser = CreateParser(Mock.Of()); - var buffer = new ReadOnlyBuffer(Encoding.ASCII.GetBytes(rawHeaders)); + var buffer = new ReadOnlyBuffer(Encoding.ASCII.GetBytes(rawHeaders)); var requestHandler = new RequestHandler(); parser.ParseHeaders(requestHandler, buffer, out var consumed, out var examined, out var consumedBytes); - Assert.Equal(buffer.Start, consumed); - Assert.Equal(buffer.End, examined); + Assert.Equal(buffer.Length, buffer.Slice(consumed).Length); + Assert.True(buffer.Slice(examined).IsEmpty); Assert.Equal(0, consumedBytes); } @@ -294,19 +294,19 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests var parser = CreateParser(Mock.Of()); const string headerLine = "Header: value\r\n\r"; - var buffer1 = new ReadOnlyBuffer(Encoding.ASCII.GetBytes(headerLine)); + var buffer1 = new ReadOnlyBuffer(Encoding.ASCII.GetBytes(headerLine)); var requestHandler = new RequestHandler(); Assert.False(parser.ParseHeaders(requestHandler, buffer1, out var consumed, out var examined, out var consumedBytes)); - Assert.Equal(buffer1.Move(buffer1.Start, headerLine.Length - 1), consumed); + Assert.Equal(buffer1.GetPosition(buffer1.Start, headerLine.Length - 1), consumed); Assert.Equal(buffer1.End, examined); Assert.Equal(headerLine.Length - 1, consumedBytes); - var buffer2 = new ReadOnlyBuffer(Encoding.ASCII.GetBytes("\r\n")); + var buffer2 = new ReadOnlyBuffer(Encoding.ASCII.GetBytes("\r\n")); Assert.True(parser.ParseHeaders(requestHandler, buffer2, out consumed, out examined, out consumedBytes)); - Assert.Equal(buffer2.End, consumed); - Assert.Equal(buffer2.End, examined); + Assert.True(buffer2.Slice(consumed).IsEmpty); + Assert.True(buffer2.Slice(examined).IsEmpty); Assert.Equal(2, consumedBytes); } @@ -320,7 +320,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests .Returns(true); var parser = CreateParser(mockTrace.Object); - var buffer = new ReadOnlyBuffer(Encoding.ASCII.GetBytes(rawHeaders)); + var buffer = new ReadOnlyBuffer(Encoding.ASCII.GetBytes(rawHeaders)); var requestHandler = new RequestHandler(); var exception = Assert.Throws(() => @@ -341,7 +341,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests var parser = CreateParser(mockTrace.Object); // Invalid request line - var buffer = new ReadOnlyBuffer(Encoding.ASCII.GetBytes("GET % HTTP/1.1\r\n")); + var buffer = new ReadOnlyBuffer(Encoding.ASCII.GetBytes("GET % HTTP/1.1\r\n")); var requestHandler = new RequestHandler(); var exception = Assert.Throws(() => @@ -351,7 +351,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests Assert.Equal(StatusCodes.Status400BadRequest, (exception as BadHttpRequestException).StatusCode); // Unrecognized HTTP version - buffer = new ReadOnlyBuffer(Encoding.ASCII.GetBytes("GET / HTTP/1.2\r\n")); + buffer = new ReadOnlyBuffer(Encoding.ASCII.GetBytes("GET / HTTP/1.2\r\n")); exception = Assert.Throws(() => parser.ParseRequestLine(requestHandler, buffer, out var consumed, out var examined)); @@ -360,7 +360,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests Assert.Equal(StatusCodes.Status505HttpVersionNotsupported, (exception as BadHttpRequestException).StatusCode); // Invalid request header - buffer = new ReadOnlyBuffer(Encoding.ASCII.GetBytes("Header: value\n\r\n")); + buffer = new ReadOnlyBuffer(Encoding.ASCII.GetBytes("Header: value\n\r\n")); exception = Assert.Throws(() => parser.ParseHeaders(requestHandler, buffer, out var consumed, out var examined, out var consumedBytes)); @@ -375,7 +375,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests string expectedHeaderValue) { var parser = CreateParser(Mock.Of()); - var buffer = new ReadOnlyBuffer(Encoding.ASCII.GetBytes($"{headerName}:{rawHeaderValue}\r\n")); + var buffer = new ReadOnlyBuffer(Encoding.ASCII.GetBytes($"{headerName}:{rawHeaderValue}\r\n")); var requestHandler = new RequestHandler(); parser.ParseHeaders(requestHandler, buffer, out var consumed, out var examined, out var consumedBytes); @@ -384,8 +384,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests Assert.Single(pairs); Assert.Equal(headerName, pairs[0].Key); Assert.Equal(expectedHeaderValue, pairs[0].Value); - Assert.Equal(buffer.End, consumed); - Assert.Equal(buffer.End, examined); + Assert.True(buffer.Slice(consumed).IsEmpty); + Assert.True(buffer.Slice(examined).IsEmpty); } private void VerifyRawHeaders(string rawHeaders, IEnumerable expectedHeaderNames, IEnumerable expectedHeaderValues) @@ -393,7 +393,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests Assert.True(expectedHeaderNames.Count() == expectedHeaderValues.Count(), $"{nameof(expectedHeaderNames)} and {nameof(expectedHeaderValues)} sizes must match"); var parser = CreateParser(Mock.Of()); - var buffer = new ReadOnlyBuffer(Encoding.ASCII.GetBytes(rawHeaders)); + var buffer = new ReadOnlyBuffer(Encoding.ASCII.GetBytes(rawHeaders)); var requestHandler = new RequestHandler(); parser.ParseHeaders(requestHandler, buffer, out var consumed, out var examined, out var consumedBytes); @@ -403,8 +403,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests Assert.Equal(expectedHeaderNames.Count(), parsedHeaders.Length); Assert.Equal(expectedHeaderNames, parsedHeaders.Select(t => t.Key)); Assert.Equal(expectedHeaderValues, parsedHeaders.Select(t => t.Value)); - Assert.Equal(buffer.End, consumed); - Assert.Equal(buffer.End, examined); + Assert.True(buffer.Slice(consumed).IsEmpty); + Assert.True(buffer.Slice(examined).IsEmpty); } private IHttpParser CreateParser(IKestrelTrace log) => new HttpParser(log.IsEnabled(LogLevel.Information)); diff --git a/test/Kestrel.Core.Tests/MessageBodyTests.cs b/test/Kestrel.Core.Tests/MessageBodyTests.cs index 9fa5b6ef1a..148fb56630 100644 --- a/test/Kestrel.Core.Tests/MessageBodyTests.cs +++ b/test/Kestrel.Core.Tests/MessageBodyTests.cs @@ -5,6 +5,7 @@ using System; using System.Collections.Generic; using System.IO; using System.Linq; +using System.Runtime.InteropServices; using System.Text; using System.Threading; using System.Threading.Tasks; @@ -445,23 +446,23 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests // The block returned by IncomingStart always has at least 2048 available bytes, // so no need to bounds check in this test. var bytes = Encoding.ASCII.GetBytes(data[0]); - var buffer = input.Application.Output.Alloc(2048); + var buffer = input.Application.Output.GetMemory(2028); ArraySegment block; - Assert.True(buffer.Buffer.TryGetArray(out block)); + Assert.True(MemoryMarshal.TryGetArray(buffer, out block)); Buffer.BlockCopy(bytes, 0, block.Array, block.Offset, bytes.Length); - buffer.Advance(bytes.Length); - await buffer.FlushAsync(); + input.Application.Output.Advance(bytes.Length); + await input.Application.Output.FlushAsync(); // Verify the block passed to WriteAsync is the same one incoming data was written into. Assert.Same(block.Array, await writeTcs.Task); writeTcs = new TaskCompletionSource(); bytes = Encoding.ASCII.GetBytes(data[1]); - buffer = input.Application.Output.Alloc(2048); - Assert.True(buffer.Buffer.TryGetArray(out block)); + buffer = input.Application.Output.GetMemory(2048); + Assert.True(MemoryMarshal.TryGetArray(buffer, out block)); Buffer.BlockCopy(bytes, 0, block.Array, block.Offset, bytes.Length); - buffer.Advance(bytes.Length); - await buffer.FlushAsync(); + input.Application.Output.Advance(bytes.Length); + await input.Application.Output.FlushAsync(); Assert.Same(block.Array, await writeTcs.Task); diff --git a/test/Kestrel.Core.Tests/OutputProducerTests.cs b/test/Kestrel.Core.Tests/OutputProducerTests.cs index 71a4b7712b..8c489537ec 100644 --- a/test/Kestrel.Core.Tests/OutputProducerTests.cs +++ b/test/Kestrel.Core.Tests/OutputProducerTests.cs @@ -33,7 +33,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests var pipeOptions = new PipeOptions ( pool: _memoryPool, - readerScheduler: Mock.Of() + readerScheduler: Mock.Of() ); using (var socketOutput = CreateOutputProducer(pipeOptions)) diff --git a/test/Kestrel.Core.Tests/PipeOptionsTests.cs b/test/Kestrel.Core.Tests/PipeOptionsTests.cs index 397fbdbbc8..519c266d5b 100644 --- a/test/Kestrel.Core.Tests/PipeOptionsTests.cs +++ b/test/Kestrel.Core.Tests/PipeOptionsTests.cs @@ -26,11 +26,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests serviceContext.ServerOptions.Limits.MaxResponseBufferSize = maxResponseBufferSize; serviceContext.ThreadPool = new LoggingThreadPool(null); - var mockScheduler = Mock.Of(); + var mockScheduler = Mock.Of(); var outputPipeOptions = ConnectionHandler.GetOutputPipeOptions(serviceContext, new MemoryPool(), readerScheduler: mockScheduler); - Assert.Equal(expectedMaximumSizeLow, outputPipeOptions.MaximumSizeLow); - Assert.Equal(expectedMaximumSizeHigh, outputPipeOptions.MaximumSizeHigh); + Assert.Equal(expectedMaximumSizeLow, outputPipeOptions.ResumeWriterThreshold); + Assert.Equal(expectedMaximumSizeHigh, outputPipeOptions.PauseWriterThreshold); Assert.Same(mockScheduler, outputPipeOptions.ReaderScheduler); Assert.Same(serviceContext.ThreadPool, outputPipeOptions.WriterScheduler); } @@ -44,11 +44,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests serviceContext.ServerOptions.Limits.MaxRequestBufferSize = maxRequestBufferSize; serviceContext.ThreadPool = new LoggingThreadPool(null); - var mockScheduler = Mock.Of(); + var mockScheduler = Mock.Of(); var inputPipeOptions = ConnectionHandler.GetInputPipeOptions(serviceContext, new MemoryPool(), writerScheduler: mockScheduler); - Assert.Equal(expectedMaximumSizeLow, inputPipeOptions.MaximumSizeLow); - Assert.Equal(expectedMaximumSizeHigh, inputPipeOptions.MaximumSizeHigh); + Assert.Equal(expectedMaximumSizeLow, inputPipeOptions.ResumeWriterThreshold); + Assert.Equal(expectedMaximumSizeHigh, inputPipeOptions.PauseWriterThreshold); Assert.Same(serviceContext.ThreadPool, inputPipeOptions.ReaderScheduler); Assert.Same(mockScheduler, inputPipeOptions.WriterScheduler); } @@ -66,10 +66,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests ServiceContext = serviceContext }); - Assert.Equal(expectedMaximumSizeLow, connectionLifetime.AdaptedInputPipeOptions.MaximumSizeLow); - Assert.Equal(expectedMaximumSizeHigh, connectionLifetime.AdaptedInputPipeOptions.MaximumSizeHigh); + Assert.Equal(expectedMaximumSizeLow, connectionLifetime.AdaptedInputPipeOptions.ResumeWriterThreshold); + Assert.Equal(expectedMaximumSizeHigh, connectionLifetime.AdaptedInputPipeOptions.PauseWriterThreshold); Assert.Same(serviceContext.ThreadPool, connectionLifetime.AdaptedInputPipeOptions.ReaderScheduler); - Assert.Same(Scheduler.Inline, connectionLifetime.AdaptedInputPipeOptions.WriterScheduler); + Assert.Same(PipeScheduler.Inline, connectionLifetime.AdaptedInputPipeOptions.WriterScheduler); } [Theory] @@ -85,10 +85,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests ServiceContext = serviceContext }); - Assert.Equal(expectedMaximumSizeLow, connectionLifetime.AdaptedOutputPipeOptions.MaximumSizeLow); - Assert.Equal(expectedMaximumSizeHigh, connectionLifetime.AdaptedOutputPipeOptions.MaximumSizeHigh); - Assert.Same(Scheduler.Inline, connectionLifetime.AdaptedOutputPipeOptions.ReaderScheduler); - Assert.Same(Scheduler.Inline, connectionLifetime.AdaptedOutputPipeOptions.WriterScheduler); + Assert.Equal(expectedMaximumSizeLow, connectionLifetime.AdaptedOutputPipeOptions.ResumeWriterThreshold); + Assert.Equal(expectedMaximumSizeHigh, connectionLifetime.AdaptedOutputPipeOptions.PauseWriterThreshold); + Assert.Same(PipeScheduler.Inline, connectionLifetime.AdaptedOutputPipeOptions.ReaderScheduler); + Assert.Same(PipeScheduler.Inline, connectionLifetime.AdaptedOutputPipeOptions.WriterScheduler); } } } diff --git a/test/Kestrel.Core.Tests/PipelineExtensionTests.cs b/test/Kestrel.Core.Tests/PipelineExtensionTests.cs index 00cc9d1c2e..286dff7cbe 100644 --- a/test/Kestrel.Core.Tests/PipelineExtensionTests.cs +++ b/test/Kestrel.Core.Tests/PipelineExtensionTests.cs @@ -15,7 +15,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests // ulong.MaxValue.ToString().Length private const int _ulongMaxValueLength = 20; - private readonly IPipe _pipe; + private readonly Pipe _pipe; private readonly MemoryPool _memoryPool = new MemoryPool(); public PipelineExtensionTests() @@ -34,8 +34,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests [InlineData(4_8_15_16_23_42)] public void WritesNumericToAscii(ulong number) { - var writerBuffer = _pipe.Writer.Alloc(); - var writer = new WritableBufferWriter(writerBuffer); + var writerBuffer = _pipe.Writer; + var writer = OutputWriter.Create(writerBuffer); writer.WriteNumeric(number); writerBuffer.FlushAsync().GetAwaiter().GetResult(); @@ -51,8 +51,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests [InlineData(_ulongMaxValueLength - 1)] public void WritesNumericAcrossSpanBoundaries(int gapSize) { - var writerBuffer = _pipe.Writer.Alloc(100); - var writer = new WritableBufferWriter(writerBuffer); + var writerBuffer = _pipe.Writer; + var writer = OutputWriter.Create(writerBuffer); // almost fill up the first block var spacer = new byte[writer.Span.Length - gapSize]; writer.Write(spacer); @@ -66,7 +66,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests var reader = _pipe.Reader.ReadAsync().GetAwaiter().GetResult(); var numAsString = ulong.MaxValue.ToString(); var written = reader.Buffer.Slice(spacer.Length, numAsString.Length); - Assert.False(written.IsSingleSpan, "The buffer should cross spans"); + Assert.False(written.IsSingleSegment, "The buffer should cross spans"); AssertExtensions.Equal(Encoding.ASCII.GetBytes(numAsString), written.ToArray()); } @@ -82,8 +82,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests [InlineData(null, new byte[0])] public void EncodesAsAscii(string input, byte[] expected) { - var writerBuffer = _pipe.Writer.Alloc(); - var writer = new WritableBufferWriter(writerBuffer); + var writerBuffer = _pipe.Writer; + var writer = OutputWriter.Create(writerBuffer); writer.WriteAsciiNoValidation(input); writerBuffer.FlushAsync().GetAwaiter().GetResult(); var reader = _pipe.Reader.ReadAsync().GetAwaiter().GetResult(); @@ -109,8 +109,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests { // WriteAscii doesn't validate if characters are in the ASCII range // but it shouldn't produce more than one byte per character - var writerBuffer = _pipe.Writer.Alloc(); - var writer = new WritableBufferWriter(writerBuffer); + var writerBuffer = _pipe.Writer; + var writer = OutputWriter.Create(writerBuffer); writer.WriteAsciiNoValidation(input); writerBuffer.FlushAsync().GetAwaiter().GetResult(); var reader = _pipe.Reader.ReadAsync().GetAwaiter().GetResult(); @@ -122,8 +122,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests public void WriteAsciiNoValidation() { const byte maxAscii = 0x7f; - var writerBuffer = _pipe.Writer.Alloc(); - var writer = new WritableBufferWriter(writerBuffer); + var writerBuffer = _pipe.Writer; + var writer = OutputWriter.Create(writerBuffer); for (var i = 0; i < maxAscii; i++) { writer.WriteAsciiNoValidation(new string((char)i, 1)); @@ -151,8 +151,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests public void WritesAsciiAcrossBlockBoundaries(int stringLength, int gapSize) { var testString = new string(' ', stringLength); - var writerBuffer = _pipe.Writer.Alloc(100); - var writer = new WritableBufferWriter(writerBuffer); + var writerBuffer = _pipe.Writer; + var writer = OutputWriter.Create(writerBuffer); // almost fill up the first block var spacer = new byte[writer.Span.Length - gapSize]; writer.Write(spacer); @@ -166,7 +166,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests var reader = _pipe.Reader.ReadAsync().GetAwaiter().GetResult(); var written = reader.Buffer.Slice(spacer.Length, stringLength); - Assert.False(written.IsSingleSpan, "The buffer should cross spans"); + Assert.False(written.IsSingleSegment, "The buffer should cross spans"); AssertExtensions.Equal(Encoding.ASCII.GetBytes(testString), written.ToArray()); } } diff --git a/test/Kestrel.Core.Tests/TestInput.cs b/test/Kestrel.Core.Tests/TestInput.cs index ba644e4bf8..6153e8d2a5 100644 --- a/test/Kestrel.Core.Tests/TestInput.cs +++ b/test/Kestrel.Core.Tests/TestInput.cs @@ -38,9 +38,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests Http1Connection.HttpResponseControl = Mock.Of(); } - public IPipeConnection Transport { get; } + public IDuplexPipe Transport { get; } - public IPipeConnection Application { get; } + public IDuplexPipe Application { get; } public Http1ConnectionContext Http1ConnectionContext { get; } diff --git a/test/Kestrel.Transport.Libuv.Tests/LibuvConnectionTests.cs b/test/Kestrel.Transport.Libuv.Tests/LibuvConnectionTests.cs index 4c79bddf19..2dfc7a1ad4 100644 --- a/test/Kestrel.Transport.Libuv.Tests/LibuvConnectionTests.cs +++ b/test/Kestrel.Transport.Libuv.Tests/LibuvConnectionTests.cs @@ -62,7 +62,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests mockConnectionHandler.InputOptions = pool => new PipeOptions( pool: pool, - maximumSizeHigh: 3); + pauseWriterThreshold: 3); // We don't set the output writer scheduler here since we want to run the callback inline @@ -117,7 +117,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests var transportContext = new TestLibuvTransportContext() { ConnectionHandler = mockConnectionHandler }; var transport = new LibuvTransport(mockLibuv, transportContext, null); var thread = new LibuvThread(transport); - var mockScheduler = new Mock(); + var mockScheduler = new Mock(); Action backPressure = null; mockScheduler.Setup(m => m.Schedule(It.IsAny())).Callback(a => { @@ -126,8 +126,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests mockConnectionHandler.InputOptions = pool => new PipeOptions( pool: pool, - maximumSizeHigh: 3, - maximumSizeLow: 3, + pauseWriterThreshold: 3, + resumeWriterThreshold: 3, writerScheduler: mockScheduler.Object); mockConnectionHandler.OutputOptions = pool => new PipeOptions(pool: pool, readerScheduler:thread ); @@ -161,7 +161,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests var result = await mockConnectionHandler.Input.Reader.ReadAsync(); // Calling advance will call into our custom scheduler that captures the back pressure // callback - mockConnectionHandler.Input.Reader.Advance(result.Buffer.End); + mockConnectionHandler.Input.Reader.AdvanceTo(result.Buffer.End); // Cancel the current pending flush mockConnectionHandler.Input.Writer.CancelPendingFlush(); diff --git a/test/Kestrel.Transport.Libuv.Tests/LibuvOutputConsumerTests.cs b/test/Kestrel.Transport.Libuv.Tests/LibuvOutputConsumerTests.cs index 06576890d4..36554bb133 100644 --- a/test/Kestrel.Transport.Libuv.Tests/LibuvOutputConsumerTests.cs +++ b/test/Kestrel.Transport.Libuv.Tests/LibuvOutputConsumerTests.cs @@ -60,14 +60,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests // SocketOutput, the write callback would never be invoked for writes larger than // maxResponseBufferSize even after the write actually completed. - // ConnectionHandler will set MaximumSizeHigh/Low to zero when MaxResponseBufferSize is null. + // ConnectionHandler will set Pause/ResumeWriterThreshold to zero when MaxResponseBufferSize is null. // This is verified in PipeOptionsTests.OutputPipeOptionsConfiguredCorrectly. var pipeOptions = new PipeOptions ( pool: _memoryPool, readerScheduler: _libuvThread, - maximumSizeHigh: maxResponseBufferSize ?? 0, - maximumSizeLow: maxResponseBufferSize ?? 0 + pauseWriterThreshold: maxResponseBufferSize ?? 0, + resumeWriterThreshold: maxResponseBufferSize ?? 0 ); using (var outputProducer = CreateOutputProducer(pipeOptions)) @@ -96,14 +96,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests return 0; }; - // ConnectionHandler will set MaximumSizeHigh/Low to zero when MaxResponseBufferSize is null. + // ConnectionHandler will set Pause/ResumeWriterThreshold to zero when MaxResponseBufferSize is null. // This is verified in PipeOptionsTests.OutputPipeOptionsConfiguredCorrectly. var pipeOptions = new PipeOptions ( pool: _memoryPool, readerScheduler: _libuvThread, - maximumSizeHigh: 0, - maximumSizeLow: 0 + pauseWriterThreshold: 0, + resumeWriterThreshold: 0 ); using (var outputProducer = CreateOutputProducer(pipeOptions)) @@ -144,14 +144,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests return 0; }; - // ConnectionHandler will set MaximumSizeHigh/Low to 1 when MaxResponseBufferSize is zero. + // ConnectionHandler will set Pause/ResumeWriterThreshold to 1 when MaxResponseBufferSize is zero. // This is verified in PipeOptionsTests.OutputPipeOptionsConfiguredCorrectly. var pipeOptions = new PipeOptions ( pool: _memoryPool, readerScheduler: _libuvThread, - maximumSizeHigh: 1, - maximumSizeLow: 1 + pauseWriterThreshold: 1, + resumeWriterThreshold: 1 ); using (var outputProducer = CreateOutputProducer(pipeOptions)) @@ -206,8 +206,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests ( pool: _memoryPool, readerScheduler: _libuvThread, - maximumSizeHigh: maxResponseBufferSize, - maximumSizeLow: maxResponseBufferSize + pauseWriterThreshold: maxResponseBufferSize, + resumeWriterThreshold: maxResponseBufferSize ); using (var outputProducer = CreateOutputProducer(pipeOptions)) @@ -270,8 +270,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests ( pool: _memoryPool, readerScheduler: _libuvThread, - maximumSizeHigh: maxResponseBufferSize, - maximumSizeLow: maxResponseBufferSize + pauseWriterThreshold: maxResponseBufferSize, + resumeWriterThreshold: maxResponseBufferSize ); using (var outputProducer = CreateOutputProducer(pipeOptions)) @@ -340,8 +340,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests ( pool: _memoryPool, readerScheduler: _libuvThread, - maximumSizeHigh: maxResponseBufferSize, - maximumSizeLow: maxResponseBufferSize + pauseWriterThreshold: maxResponseBufferSize, + resumeWriterThreshold: maxResponseBufferSize ); using (var outputProducer = CreateOutputProducer(pipeOptions, abortedSource)) @@ -433,8 +433,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests ( pool: _memoryPool, readerScheduler: _libuvThread, - maximumSizeHigh: maxResponseBufferSize, - maximumSizeLow: maxResponseBufferSize + pauseWriterThreshold: maxResponseBufferSize, + resumeWriterThreshold: maxResponseBufferSize ); using (var outputProducer = CreateOutputProducer(pipeOptions)) @@ -517,8 +517,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests ( pool: _memoryPool, readerScheduler: _libuvThread, - maximumSizeHigh: maxResponseBufferSize, - maximumSizeLow: maxResponseBufferSize + pauseWriterThreshold: maxResponseBufferSize, + resumeWriterThreshold: maxResponseBufferSize ); using (var outputProducer = CreateOutputProducer(pipeOptions)) @@ -599,8 +599,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests ( pool: _memoryPool, readerScheduler: _libuvThread, - maximumSizeHigh: maxResponseBufferSize, - maximumSizeLow: maxResponseBufferSize + pauseWriterThreshold: maxResponseBufferSize, + resumeWriterThreshold: maxResponseBufferSize ); using (var outputProducer = CreateOutputProducer(pipeOptions)) @@ -654,14 +654,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests return 0; }; - // ConnectionHandler will set MaximumSizeHigh/Low to zero when MaxResponseBufferSize is null. + // ConnectionHandler will set Pause/ResumeWriterThreshold to zero when MaxResponseBufferSize is null. // This is verified in PipeOptionsTests.OutputPipeOptionsConfiguredCorrectly. var pipeOptions = new PipeOptions ( pool: _memoryPool, readerScheduler: _libuvThread, - maximumSizeHigh: maxResponseBufferSize ?? 0, - maximumSizeLow: maxResponseBufferSize ?? 0 + pauseWriterThreshold: maxResponseBufferSize ?? 0, + resumeWriterThreshold: maxResponseBufferSize ?? 0 ); using (var outputProducer = CreateOutputProducer(pipeOptions)) @@ -728,7 +728,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests return (Http1OutputProducer)http1Connection.Output; } - private async Task WriteOutputAsync(LibuvOutputConsumer consumer, IPipeReader outputReader, Http1Connection http1Connection) + private async Task WriteOutputAsync(LibuvOutputConsumer consumer, PipeReader outputReader, Http1Connection http1Connection) { // This WriteOutputAsync() calling code is equivalent to that in LibuvConnection. try diff --git a/test/Kestrel.Transport.Libuv.Tests/MultipleLoopTests.cs b/test/Kestrel.Transport.Libuv.Tests/MultipleLoopTests.cs index 001b4343e1..e5972077c9 100644 --- a/test/Kestrel.Transport.Libuv.Tests/MultipleLoopTests.cs +++ b/test/Kestrel.Transport.Libuv.Tests/MultipleLoopTests.cs @@ -69,7 +69,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests await writeRequest.WriteAsync( serverConnectionPipe, - new ReadOnlyBuffer(new byte[] { 1, 2, 3, 4 })); + new ReadOnlyBuffer(new byte[] { 1, 2, 3, 4 })); writeRequest.Dispose(); serverConnectionPipe.Dispose(); diff --git a/test/Kestrel.Transport.Libuv.Tests/NetworkingTests.cs b/test/Kestrel.Transport.Libuv.Tests/NetworkingTests.cs index dfe9681a0b..bf25af4392 100644 --- a/test/Kestrel.Transport.Libuv.Tests/NetworkingTests.cs +++ b/test/Kestrel.Transport.Libuv.Tests/NetworkingTests.cs @@ -162,7 +162,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests { var req = new UvWriteReq(_logger); req.DangerousInit(loop); - var block = new ReadOnlyBuffer(new byte[] { 65, 66, 67, 68, 69 }); + var block = new ReadOnlyBuffer(new byte[] { 65, 66, 67, 68, 69 }); await req.WriteAsync( tcp2, diff --git a/test/Kestrel.Transport.Libuv.Tests/TestHelpers/MockConnectionHandler.cs b/test/Kestrel.Transport.Libuv.Tests/TestHelpers/MockConnectionHandler.cs index 1efb0bedab..d52a868b67 100644 --- a/test/Kestrel.Transport.Libuv.Tests/TestHelpers/MockConnectionHandler.cs +++ b/test/Kestrel.Transport.Libuv.Tests/TestHelpers/MockConnectionHandler.cs @@ -29,7 +29,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests.TestHelpers feature.Application = new PipeConnection(Output.Reader, Input.Writer); } - public IPipe Input { get; private set; } - public IPipe Output { get; private set; } + public Pipe Input { get; private set; } + public Pipe Output { get; private set; } } } diff --git a/tools/CodeGenerator/CodeGenerator.csproj b/tools/CodeGenerator/CodeGenerator.csproj index e7cf3a993f..c85676e21d 100644 --- a/tools/CodeGenerator/CodeGenerator.csproj +++ b/tools/CodeGenerator/CodeGenerator.csproj @@ -7,9 +7,6 @@ true - - - diff --git a/tools/CodeGenerator/HttpProtocolFeatureCollection.cs b/tools/CodeGenerator/HttpProtocolFeatureCollection.cs index 6582f445e9..b960180f26 100644 --- a/tools/CodeGenerator/HttpProtocolFeatureCollection.cs +++ b/tools/CodeGenerator/HttpProtocolFeatureCollection.cs @@ -6,7 +6,7 @@ using System.Collections.Generic; using System.Linq; using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Http.Features.Authentication; -using Microsoft.AspNetCore.Server.Kestrel.Core.Features; +//using Microsoft.AspNetCore.Server.Kestrel.Core.Features; namespace CodeGenerator { @@ -23,39 +23,39 @@ namespace CodeGenerator { var alwaysFeatures = new[] { - typeof(IHttpRequestFeature), - typeof(IHttpResponseFeature), - typeof(IHttpRequestIdentifierFeature), - typeof(IServiceProvidersFeature), - typeof(IHttpRequestLifetimeFeature), - typeof(IHttpConnectionFeature), + "IHttpRequestFeature", + "IHttpResponseFeature", + "IHttpRequestIdentifierFeature", + "IServiceProvidersFeature", + "IHttpRequestLifetimeFeature", + "IHttpConnectionFeature", }; var commonFeatures = new[] { - typeof(IHttpAuthenticationFeature), - typeof(IQueryFeature), - typeof(IFormFeature), + "IHttpAuthenticationFeature", + "IQueryFeature", + "IFormFeature", }; var sometimesFeatures = new[] { - typeof(IHttpUpgradeFeature), - typeof(IHttp2StreamIdFeature), - typeof(IResponseCookiesFeature), - typeof(IItemsFeature), - typeof(ITlsConnectionFeature), - typeof(IHttpWebSocketFeature), - typeof(ISessionFeature), - typeof(IHttpMaxRequestBodySizeFeature), - typeof(IHttpMinRequestBodyDataRateFeature), - typeof(IHttpMinResponseDataRateFeature), - typeof(IHttpBodyControlFeature), + "IHttpUpgradeFeature", + "IHttp2StreamIdFeature", + "IResponseCookiesFeature", + "IItemsFeature", + "ITlsConnectionFeature", + "IHttpWebSocketFeature", + "ISessionFeature", + "IHttpMaxRequestBodySizeFeature", + "IHttpMinRequestBodyDataRateFeature", + "IHttpMinResponseDataRateFeature", + "IHttpBodyControlFeature", }; var rareFeatures = new[] { - typeof(IHttpSendFileFeature), + "IHttpSendFileFeature", }; var allFeatures = alwaysFeatures.Concat(commonFeatures).Concat(sometimesFeatures).Concat(rareFeatures); @@ -64,15 +64,15 @@ namespace CodeGenerator // See also: src/Kestrel/Http/HttpProtocol.FeatureCollection.cs var implementedFeatures = new[] { - typeof(IHttpRequestFeature), - typeof(IHttpResponseFeature), - typeof(IHttpRequestIdentifierFeature), - typeof(IHttpRequestLifetimeFeature), - typeof(IHttpConnectionFeature), - typeof(IHttpMaxRequestBodySizeFeature), - typeof(IHttpMinRequestBodyDataRateFeature), - typeof(IHttpMinResponseDataRateFeature), - typeof(IHttpBodyControlFeature), + "IHttpRequestFeature", + "IHttpResponseFeature", + "IHttpRequestIdentifierFeature", + "IHttpRequestLifetimeFeature", + "IHttpConnectionFeature", + "IHttpMaxRequestBodySizeFeature", + "IHttpMinRequestBodyDataRateFeature", + "IHttpMinResponseDataRateFeature", + "IHttpBodyControlFeature", }; return $@"// Copyright (c) .NET Foundation. All rights reserved. @@ -81,26 +81,30 @@ namespace CodeGenerator using System; using System.Collections.Generic; +using Microsoft.AspNetCore.Http.Features; +using Microsoft.AspNetCore.Http.Features.Authentication; +using Microsoft.AspNetCore.Server.Kestrel.Core.Features; + namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http {{ public partial class {className} {{{Each(allFeatures, feature => $@" - private static readonly Type {feature.Name}Type = typeof(global::{feature.FullName});")} + private static readonly Type {feature}Type = typeof({feature});")} {Each(allFeatures, feature => $@" - private object _current{feature.Name};")} + private object _current{feature};")} private void FastReset() {{{Each(implementedFeatures, feature => $@" - _current{feature.Name} = this;")} + _current{feature} = this;")} {Each(allFeatures.Where(f => !implementedFeatures.Contains(f)), feature => $@" - _current{feature.Name} = null;")} + _current{feature} = null;")} }} internal object FastFeatureGet(Type key) {{{Each(allFeatures, feature => $@" - if (key == {feature.Name}Type) + if (key == {feature}Type) {{ - return _current{feature.Name}; + return _current{feature}; }}")} return ExtraFeatureGet(key); }} @@ -109,9 +113,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http {{ _featureRevision++; {Each(allFeatures, feature => $@" - if (key == {feature.Name}Type) + if (key == {feature}Type) {{ - _current{feature.Name} = feature; + _current{feature} = feature; return; }}")}; ExtraFeatureSet(key, feature); @@ -119,9 +123,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http private IEnumerable> FastEnumerable() {{{Each(allFeatures, feature => $@" - if (_current{feature.Name} != null) + if (_current{feature} != null) {{ - yield return new KeyValuePair({feature.Name}Type, _current{feature.Name} as global::{feature.FullName}); + yield return new KeyValuePair({feature}Type, _current{feature} as {feature}); }}")} if (MaybeExtra != null) diff --git a/tools/CodeGenerator/HttpUtilities/HttpUtilities.cs b/tools/CodeGenerator/HttpUtilities/HttpUtilities.cs index 4d8c2ca922..7263d1fd16 100644 --- a/tools/CodeGenerator/HttpUtilities/HttpUtilities.cs +++ b/tools/CodeGenerator/HttpUtilities/HttpUtilities.cs @@ -7,7 +7,6 @@ using System.Diagnostics; using System.Linq; using System.Text; using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; namespace CodeGenerator.HttpUtilities { @@ -17,27 +16,27 @@ namespace CodeGenerator.HttpUtilities { var httpMethods = new [] { - new Tuple("CONNECT ", HttpMethod.Connect), - new Tuple("DELETE ", HttpMethod.Delete), - new Tuple("HEAD ", HttpMethod.Head), - new Tuple("PATCH ", HttpMethod.Patch), - new Tuple("POST ", HttpMethod.Post), - new Tuple("PUT ", HttpMethod.Put), - new Tuple("OPTIONS ", HttpMethod.Options), - new Tuple("TRACE ", HttpMethod.Trace), - new Tuple("GET ", HttpMethod.Get) + new Tuple("CONNECT ", "Connect"), + new Tuple("DELETE ", "Delete"), + new Tuple("HEAD ", "Head"), + new Tuple("PATCH ", "Patch"), + new Tuple("POST ", "Post"), + new Tuple("PUT ", "Put"), + new Tuple("OPTIONS ", "Options"), + new Tuple("TRACE ", "Trace"), + new Tuple("GET ", "Get") }; return GenerateFile(httpMethods); } - private static string GenerateFile(Tuple[] httpMethods) + private static string GenerateFile(Tuple[] httpMethods) { var maskLength = (byte)Math.Ceiling(Math.Log(httpMethods.Length, 2)); var methodsInfo = httpMethods.Select(GetMethodStringAndUlongAndMaskLength).ToList(); - var methodsInfoWithoutGet = methodsInfo.Where(m => m.HttpMethod != HttpMethod.Get.ToString()).ToList(); + var methodsInfoWithoutGet = methodsInfo.Where(m => m.HttpMethod != "Get".ToString()).ToList(); var methodsAsciiStringAsLong = methodsInfo.Select(m => m.AsciiStringAsLong).ToArray(); @@ -158,7 +157,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure var maskFieldName = GetMaskFieldName(methodInfo.MaskLength); var httpMethodFieldName = GetHttpMethodFieldName(methodInfo); - result.AppendFormat(" SetKnownMethod({0}, {1}, {2}.{3}, {4});", maskFieldName, httpMethodFieldName, typeof(HttpMethod).Name, methodInfo.HttpMethod, methodInfo.MaskLength - 1); + result.AppendFormat(" SetKnownMethod({0}, {1}, HttpMethod.{3}, {4});", maskFieldName, httpMethodFieldName, typeof(String).Name, methodInfo.HttpMethod, methodInfo.MaskLength - 1); if (index < methodsInfo.Count - 1) { @@ -181,7 +180,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure { var methodInfo = methodsInfo[index]; - result.AppendFormat(" _methodNames[(byte){0}.{1}] = {2}.{3};", typeof(HttpMethod).Name, methodInfo.HttpMethod, typeof(HttpMethods).Name, methodInfo.HttpMethod); + result.AppendFormat(" _methodNames[(byte)HttpMethod.{1}] = {2}.{3};", typeof(String).Name, methodInfo.HttpMethod, typeof(HttpMethods).Name, methodInfo.HttpMethod); if (index < methodsInfo.Count - 1) { @@ -281,7 +280,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure public int MaskLength; } - private static MethodInfo GetMethodStringAndUlongAndMaskLength(Tuple method) + private static MethodInfo GetMethodStringAndUlongAndMaskLength(Tuple method) { var methodString = GetMethodString(method.Item1); diff --git a/tools/CodeGenerator/KnownHeaders.cs b/tools/CodeGenerator/KnownHeaders.cs index 89a66fc2ac..8571143b3f 100644 --- a/tools/CodeGenerator/KnownHeaders.cs +++ b/tools/CodeGenerator/KnownHeaders.cs @@ -6,7 +6,6 @@ using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Text; -using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; namespace CodeGenerator { @@ -266,14 +265,14 @@ namespace CodeGenerator { Headers = requestHeaders, HeadersByLength = requestHeaders.GroupBy(x => x.Name.Length), - ClassName = nameof(HttpRequestHeaders), + ClassName = "HttpRequestHeaders", Bytes = default(byte[]) }, new { Headers = responseHeaders, HeadersByLength = responseHeaders.GroupBy(x => x.Name.Length), - ClassName = nameof(HttpResponseHeaders), + ClassName = "HttpResponseHeaders", Bytes = responseHeaders.SelectMany(header => header.Bytes).ToArray() } }; @@ -293,6 +292,7 @@ namespace CodeGenerator using System; using System.Collections.Generic; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; +using System.Buffers; using System.IO.Pipelines; using Microsoft.Extensions.Primitives; using Microsoft.Net.Http.Headers; @@ -384,7 +384,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http }} protected override void SetValueFast(string key, StringValues value) - {{{(loop.ClassName == nameof(HttpResponseHeaders) ? @" + {{{(loop.ClassName == "HttpResponseHeaders" ? @" ValidateHeaderCharacters(value);" : "")} switch (key.Length) {{{Each(loop.HeadersByLength, byLength => $@" @@ -406,7 +406,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http }} protected override bool AddValueFast(string key, StringValues value) - {{{(loop.ClassName == nameof(HttpResponseHeaders) ? @" + {{{(loop.ClassName == "HttpResponseHeaders" ? @" ValidateHeaderCharacters(value);" : "")} switch (key.Length) {{{Each(loop.HeadersByLength, byLength => $@" @@ -432,7 +432,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http }} break;")} }} -{(loop.ClassName == nameof(HttpResponseHeaders) ? @" +{(loop.ClassName == "HttpResponseHeaders" ? @" ValidateHeaderCharacters(key);" : "")} Unknown.Add(key, value); // Return true, above will throw and exit for false @@ -522,8 +522,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http return true; }} - {(loop.ClassName == nameof(HttpResponseHeaders) ? $@" - protected void CopyToFast(ref WritableBufferWriter output) + {(loop.ClassName == "HttpResponseHeaders" ? $@" + protected void CopyToFast(ref OutputWriter output) {{ var tempBits = _bits | (_contentLength.HasValue ? {1L << 63}L : 0); {Each(loop.Headers.Where(header => header.Identifier != "ContentLength").OrderBy(h => !h.PrimaryHeader), header => $@" @@ -541,7 +541,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http var value = _headers._{header.Identifier}[i]; if (value != null) {{ - output.Write(_headerBytes, {header.BytesOffset}, {header.BytesCount}); + output.Write(new ReadOnlySpan(_headerBytes, {header.BytesOffset}, {header.BytesCount})); PipelineExtensions.WriteAsciiNoValidation(ref output, value); }} }} @@ -555,7 +555,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http }}{(header.Identifier == "Server" ? $@" if ((tempBits & {1L << 63}L) != 0) {{ - output.Write(_headerBytes, {loop.Headers.First(x => x.Identifier == "ContentLength").BytesOffset}, {loop.Headers.First(x => x.Identifier == "ContentLength").BytesCount}); + output.Write(new ReadOnlySpan(_headerBytes, {loop.Headers.First(x => x.Identifier == "ContentLength").BytesOffset}, {loop.Headers.First(x => x.Identifier == "ContentLength").BytesCount})); PipelineExtensions.WriteNumeric(ref output, (ulong)ContentLength.Value); if((tempBits & ~{1L << 63}L) == 0) @@ -565,7 +565,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http tempBits &= ~{1L << 63}L; }}" : "")}")} }}" : "")} - {(loop.ClassName == nameof(HttpRequestHeaders) ? $@" + {(loop.ClassName == "HttpRequestHeaders" ? $@" public unsafe void Append(byte* pKeyBytes, int keyLength, string value) {{ var pUB = pKeyBytes; diff --git a/tools/CodeGenerator/Program.cs b/tools/CodeGenerator/Program.cs index 1d8596890e..a7870adec4 100644 --- a/tools/CodeGenerator/Program.cs +++ b/tools/CodeGenerator/Program.cs @@ -3,8 +3,6 @@ using System; using System.IO; -using Microsoft.AspNetCore.Server.Kestrel.Core.Features; -using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; namespace CodeGenerator { @@ -36,7 +34,7 @@ namespace CodeGenerator public static void Run(string knownHeadersPath, string httpProtocolFeatureCollectionPath, string httpUtilitiesPath) { var knownHeadersContent = KnownHeaders.GeneratedFile(); - var httpProtocolFeatureCollectionContent = HttpProtocolFeatureCollection.GeneratedFile(nameof(HttpProtocol)); + var httpProtocolFeatureCollectionContent = HttpProtocolFeatureCollection.GeneratedFile("HttpProtocol"); var httpUtilitiesContent = HttpUtilities.HttpUtilities.GeneratedFile(); var existingKnownHeaders = File.Exists(knownHeadersPath) ? File.ReadAllText(knownHeadersPath) : ""; From 5e6b901a12697945974001c3f1bc69af3ed60273 Mon Sep 17 00:00:00 2001 From: Pavel Krymets Date: Wed, 31 Jan 2018 12:41:42 -0800 Subject: [PATCH 1512/1662] Update dependencies --- build/dependencies.props | 54 ++++++++++++++++++++-------------------- korebuild-lock.txt | 4 +-- 2 files changed, 29 insertions(+), 29 deletions(-) diff --git a/build/dependencies.props b/build/dependencies.props index bc2f57093b..d8493c087d 100644 --- a/build/dependencies.props +++ b/build/dependencies.props @@ -1,45 +1,45 @@ - + $(MSBuildAllProjects);$(MSBuildThisFileFullPath) 0.10.11 - 2.1.0-preview1-15651 + 2.1.0-preview2-15692 1.10.0 - 2.1.0-preview1-27965 - 2.1.0-preview1-27965 - 2.1.0-preview1-27965 - 2.1.0-preview1-27965 - 2.1.0-preview1-27965 - 2.1.0-preview1-27965 - 2.1.0-preview1-27965 - 2.1.0-preview1-27965 - 2.1.0-preview1-27965 - 2.1.0-preview1-27965 - 2.1.0-preview1-27965 - 2.1.0-preview1-27965 - 2.1.0-preview1-27965 - 2.1.0-preview1-27965 - 2.1.0-preview1-27965 - 2.1.0-preview1-27965 - 2.1.0-preview1-27965 + 2.1.0-preview2-28212 + 2.1.0-preview2-28212 + 2.1.0-preview2-28212 + 2.1.0-preview2-28212 + 2.1.0-preview2-28212 + 2.1.0-preview2-28212 + 2.1.0-preview2-28212 + 2.1.0-preview2-28212 + 2.1.0-preview2-28212 + 2.1.0-preview2-28212 + 2.1.0-preview2-28212 + 2.1.0-preview2-28212 + 2.1.0-preview2-28212 + 2.1.0-preview2-28212 + 2.1.0-preview2-28212 + 2.1.0-preview2-28212 + 2.1.0-preview2-28212 2.0.0 - 2.1.0-preview2-26124-07 - 2.1.0-preview1-27965 + 2.1.0-preview2-26130-04 + 2.1.0-preview2-28212 15.3.0 4.7.49 10.0.1 - 4.5.0-preview2-26125-06 + 4.5.0-preview2-26130-01 0.1.0-preview2-180130-1 0.1.0-preview2-180130-1 0.1.0-preview2-180130-1 - 4.5.0-preview2-26125-06 - 4.5.0-preview2-26125-06 - 4.5.0-preview2-26125-06 - 4.5.0-preview2-26125-06 + 4.5.0-preview2-26130-01 + 4.5.0-preview2-26130-01 + 4.5.0-preview2-26130-01 + 4.5.0-preview2-26130-01 0.1.0-preview2-180130-1 - 4.5.0-preview2-25707-02 + 4.5.0-preview2-26130-01 0.8.0 2.3.1 2.3.1 diff --git a/korebuild-lock.txt b/korebuild-lock.txt index 2146d006d7..232cb858c2 100644 --- a/korebuild-lock.txt +++ b/korebuild-lock.txt @@ -1,2 +1,2 @@ -version:2.1.0-preview1-15661 -commithash:c9349d4c8a495d3085d9b879214d80f2f45e2193 +version:2.1.0-preview2-15692 +commithash:5d9f445ce3f8492451a6f461df7e739bbed6a7f8 From 9c2158fd379c9c55174fff4751065434105483ae Mon Sep 17 00:00:00 2001 From: Ryan Brandenburg Date: Wed, 31 Jan 2018 11:49:18 -0800 Subject: [PATCH 1513/1662] Skip flaky test --- test/Kestrel.FunctionalTests/ConnectionLimitTests.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/test/Kestrel.FunctionalTests/ConnectionLimitTests.cs b/test/Kestrel.FunctionalTests/ConnectionLimitTests.cs index 5ed40564ab..db967776ed 100644 --- a/test/Kestrel.FunctionalTests/ConnectionLimitTests.cs +++ b/test/Kestrel.FunctionalTests/ConnectionLimitTests.cs @@ -121,7 +121,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { // this may throw IOException, depending on how fast Kestrel closes the socket await connection.SendEmptyGetAsKeepAlive(); - } catch { } + } + catch { } // connection should close without sending any data await connection.WaitForConnectionClose().TimeoutAfter(TestConstants.DefaultTimeout); @@ -132,7 +133,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } } - [Fact] + [Fact(Skip = "https://github.com/aspnet/KestrelHttpServer/issues/2282")] public async Task ConnectionCountingReturnsToZero() { const int count = 100; From a5f78264f4368afed3ead6d97cf8fb1bb33eb493 Mon Sep 17 00:00:00 2001 From: Nate McMaster Date: Wed, 31 Jan 2018 15:01:12 -0800 Subject: [PATCH 1514/1662] Update dependencies.props to 2.1.0-preview-28193, build tools to 2.1.0-preview1-1010 [ci skip] Scripted changes: - updated travis and appveyor.yml files to only build dev, ci, and release branches - updated dependencies.props - updated korebuild-lock.txt - updated korebuild.json to release/2.1 channel --- .appveyor.yml | 17 +++++------- .travis.yml | 28 +++++++++---------- build/dependencies.props | 60 ++++++++++++++++++++-------------------- korebuild-lock.txt | 4 +-- korebuild.json | 4 +-- 5 files changed, 55 insertions(+), 58 deletions(-) diff --git a/.appveyor.yml b/.appveyor.yml index 296a790bc1..4eea96ab69 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -1,20 +1,17 @@ init: - - git config --global core.autocrlf true +- git config --global core.autocrlf true branches: only: - - master - - release - - dev - - feature/dev-si - - /^(.*\/)?ci-.*$/ - - /^rel\/.*/ + - dev + - /^release\/.*$/ + - /^(.*\/)?ci-.*$/ build_script: - - ps: .\run.ps1 default-build +- ps: .\run.ps1 default-build clone_depth: 1 environment: global: DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true DOTNET_CLI_TELEMETRY_OPTOUT: 1 -test: off -deploy: off +test: 'off' +deploy: 'off' os: Visual Studio 2017 diff --git a/.travis.yml b/.travis.yml index 61ec7b5348..ccbc068a62 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,30 +2,30 @@ language: csharp sudo: required dist: trusty services: - - docker +- docker addons: apt: packages: - libunwind8 env: global: - - DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true - - DOTNET_CLI_TELEMETRY_OPTOUT: 1 + - DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true + - DOTNET_CLI_TELEMETRY_OPTOUT: 1 mono: none os: - - linux - - osx +- linux +- osx osx_image: xcode8.2 branches: only: - - master - - release - - dev - - feature/dev-si - - /^(.*\/)?ci-.*$/ - - /^rel\/.*/ + - dev + - /^release\/.*$/ + - /^(.*\/)?ci-.*$/ before_install: - - if test "$TRAVIS_OS_NAME" == "osx"; then brew update; brew install openssl; ln -s /usr/local/opt/openssl/lib/libcrypto.1.0.0.dylib /usr/local/lib/; ln -s /usr/local/opt/openssl/lib/libssl.1.0.0.dylib /usr/local/lib/; fi +- if test "$TRAVIS_OS_NAME" == "osx"; then brew update; brew install openssl; ln -s + /usr/local/opt/openssl/lib/libcrypto.1.0.0.dylib /usr/local/lib/; ln -s /usr/local/opt/openssl/lib/libssl.1.0.0.dylib + /usr/local/lib/; fi script: - - ./build.sh - - if test "$TRAVIS_OS_NAME" != "osx"; then bash test/SystemdActivation/docker.sh; fi +- ./build.sh +- if test "$TRAVIS_OS_NAME" != "osx"; then bash test/SystemdActivation/docker.sh; + fi diff --git a/build/dependencies.props b/build/dependencies.props index 67964d04ce..3b353f4110 100644 --- a/build/dependencies.props +++ b/build/dependencies.props @@ -5,41 +5,41 @@ 0.10.11 - 2.1.0-preview1-15679 + 2.1.0-preview1-1010 1.10.0 - 2.1.0-preview1-28153 - 2.1.0-preview1-28153 - 2.1.0-preview1-28153 - 2.1.0-preview1-28153 - 2.1.0-preview1-28153 - 2.1.0-preview1-28153 - 2.1.0-preview1-28153 - 2.1.0-preview1-28153 - 2.1.0-preview1-28153 - 2.1.0-preview1-28153 - 2.1.0-preview1-28153 - 2.1.0-preview1-28153 - 2.1.0-preview1-28153 - 2.1.0-preview1-28153 - 2.1.0-preview1-28153 - 2.1.0-preview1-28153 - 2.1.0-preview1-28153 + 2.1.0-preview1-28193 + 2.1.0-preview1-28193 + 2.1.0-preview1-28193 + 2.1.0-preview1-28193 + 2.1.0-preview1-28193 + 2.1.0-preview1-28193 + 2.1.0-preview1-28193 + 2.1.0-preview1-28193 + 2.1.0-preview1-28193 + 2.1.0-preview1-28193 + 2.1.0-preview1-28193 + 2.1.0-preview1-28193 + 2.1.0-preview1-28193 + 2.1.0-preview1-28193 + 2.1.0-preview1-28193 + 2.1.0-preview1-28193 + 2.1.0-preview1-28193 2.0.0 - 2.1.0-preview1-26126-02 - 2.1.0-preview1-28153 + 2.1.0-preview1-26122-01 + 2.1.0-preview1-28193 15.3.0 4.7.49 10.0.1 - 4.5.0-preview1-26126-05 - 0.1.0-preview1-180129-1 - 0.1.0-preview1-180129-1 - 0.1.0-preview1-180129-1 - 4.5.0-preview1-26126-05 - 4.5.0-preview1-26126-05 - 4.5.0-preview1-26126-05 - 4.5.0-preview1-26126-05 - 0.1.0-preview1-180129-1 - 4.5.0-preview1-26126-05 + 4.5.0-preview1-26119-06 + 0.1.0-e180104-2 + 0.1.0-e180104-2 + 0.1.0-e180104-2 + 4.5.0-preview1-26119-06 + 4.5.0-preview1-26119-06 + 4.5.0-preview1-26119-06 + 4.5.0-preview1-26119-06 + 0.1.0-e180104-2 + 4.5.0-preview1-26119-06 0.8.0 2.3.1 2.3.1 diff --git a/korebuild-lock.txt b/korebuild-lock.txt index a474bc0e35..851bfbf203 100644 --- a/korebuild-lock.txt +++ b/korebuild-lock.txt @@ -1,2 +1,2 @@ -version:2.1.0-preview1-15679 -commithash:5347461137cb45a77ddcc0b55b2478092de43338 +version:2.1.0-preview1-1010 +commithash:75ca924dfbd673c38841025b04c4dcd93b84f56d diff --git a/korebuild.json b/korebuild.json index bd5d51a51b..678d8bb948 100644 --- a/korebuild.json +++ b/korebuild.json @@ -1,4 +1,4 @@ { - "$schema": "https://raw.githubusercontent.com/aspnet/BuildTools/dev/tools/korebuild.schema.json", - "channel": "dev" + "$schema": "https://raw.githubusercontent.com/aspnet/BuildTools/release/2.1/tools/korebuild.schema.json", + "channel": "release/2.1" } From 93b10d9060090a2080cb94731e0228427ba4a0ee Mon Sep 17 00:00:00 2001 From: Ryan Brandenburg Date: Fri, 2 Feb 2018 10:45:54 -0800 Subject: [PATCH 1515/1662] Shorten logger to prevent longpath --- test/Kestrel.FunctionalTests/ResponseTests.cs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/test/Kestrel.FunctionalTests/ResponseTests.cs b/test/Kestrel.FunctionalTests/ResponseTests.cs index 40dad103ba..aa4d0fe84b 100644 --- a/test/Kestrel.FunctionalTests/ResponseTests.cs +++ b/test/Kestrel.FunctionalTests/ResponseTests.cs @@ -2495,10 +2495,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [Fact] public void ConnectionClosedWhenResponseDoesNotSatisfyMinimumDataRate() { - using (StartLog(out var loggerFactory)) + using (StartLog(out var loggerFactory, "ConnClosedWhenRespDoesNotSatisfyMin")) { - var logger = loggerFactory.CreateLogger($"{typeof(ResponseTests).FullName}.{nameof(ConnectionClosedWhenResponseDoesNotSatisfyMinimumDataRate)}"); - + var logger = loggerFactory.CreateLogger($"{ typeof(ResponseTests).FullName}.{ nameof(ConnectionClosedWhenResponseDoesNotSatisfyMinimumDataRate)}"); var chunkSize = 64 * 1024; var chunks = 128; var responseSize = chunks * chunkSize; From 8f25c4e8ca11871eac728f69c2bb256501a1838e Mon Sep 17 00:00:00 2001 From: Redouane Sobaihi Date: Thu, 8 Feb 2018 20:37:01 +0100 Subject: [PATCH 1516/1662] Include limits default values in intellisense comments. (#2304) --- src/Kestrel.Core/KestrelServerLimits.cs | 30 ++++++++++++------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/Kestrel.Core/KestrelServerLimits.cs b/src/Kestrel.Core/KestrelServerLimits.cs index 6cd16e9a6b..f2f8e773ac 100644 --- a/src/Kestrel.Core/KestrelServerLimits.cs +++ b/src/Kestrel.Core/KestrelServerLimits.cs @@ -43,12 +43,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core /// Gets or sets the maximum size of the response buffer before write /// calls begin to block or return tasks that don't complete until the /// buffer size drops below the configured limit. + /// Defaults to 65,536 bytes (64 KB). /// /// /// When set to null, the size of the response buffer is unlimited. /// When set to zero, all write calls will block or return tasks that /// don't complete until the entire response buffer is flushed. - /// Defaults to 65,536 bytes (64 KB). /// public long? MaxResponseBufferSize { @@ -65,10 +65,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core /// /// Gets or sets the maximum size of the request buffer. + /// Defaults to 1,048,576 bytes (1 MB). /// /// /// When set to null, the size of the request buffer is unlimited. - /// Defaults to 1,048,576 bytes (1 MB). /// public long? MaxRequestBufferSize { @@ -85,9 +85,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core /// /// Gets or sets the maximum allowed size for the HTTP request line. + /// Defaults to 8,192 bytes (8 KB). /// /// - /// Defaults to 8,192 bytes (8 KB). /// public int MaxRequestLineSize { @@ -104,9 +104,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core /// /// Gets or sets the maximum allowed size for the HTTP request headers. + /// Defaults to 32,768 bytes (32 KB). /// /// - /// Defaults to 32,768 bytes (32 KB). /// public int MaxRequestHeadersTotalSize { @@ -123,9 +123,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core /// /// Gets or sets the maximum allowed number of headers per HTTP request. + /// Defaults to 100. /// /// - /// Defaults to 100. /// public int MaxRequestHeaderCount { @@ -145,9 +145,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core /// When set to null, the maximum request body size is unlimited. /// This limit has no effect on upgraded connections which are always unlimited. /// This can be overridden per-request via . + /// Defaults to 30,000,000 bytes, which is approximately 28.6MB. /// /// - /// Defaults to 30,000,000 bytes, which is approximately 28.6MB. /// public long? MaxRequestBodySize { @@ -164,9 +164,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core /// /// Gets or sets the keep-alive timeout. + /// Defaults to 2 minutes. /// /// - /// Defaults to 2 minutes. /// public TimeSpan KeepAliveTimeout { @@ -183,9 +183,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core /// /// Gets or sets the maximum amount of time the server will spend receiving request headers. + /// Defaults to 30 seconds. /// /// - /// Defaults to 30 seconds. /// public TimeSpan RequestHeadersTimeout { @@ -202,11 +202,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core /// /// Gets or sets the maximum number of open connections. When set to null, the number of connections is unlimited. - /// - /// /// /// Defaults to null. /// + /// + /// /// /// When a connection is upgraded to another protocol, such as WebSockets, its connection is counted against the /// limit instead of . @@ -228,11 +228,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core /// /// Gets or sets the maximum number of open, upgraded connections. When set to null, the number of upgraded connections is unlimited. /// An upgraded connection is one that has been switched from HTTP to another protocol, such as WebSockets. - /// - /// /// /// Defaults to null. /// + /// + /// /// /// When a connection is upgraded to another protocol, such as WebSockets, its connection is counted against the /// limit instead of . @@ -256,9 +256,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core /// Setting this property to null indicates no minimum data rate should be enforced. /// This limit has no effect on upgraded connections which are always unlimited. /// This can be overridden per-request via . + /// Defaults to 240 bytes/second with a 5 second grace period. /// /// - /// Defaults to 240 bytes/second with a 5 second grace period. /// public MinDataRate MinRequestBodyDataRate { get; set; } = // Matches the default IIS minBytesPerSecond @@ -269,11 +269,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core /// Setting this property to null indicates no minimum data rate should be enforced. /// This limit has no effect on upgraded connections which are always unlimited. /// This can be overridden per-request via . - /// - /// /// /// Defaults to 240 bytes/second with a 5 second grace period. /// + /// + /// /// /// Contrary to the request body minimum data rate, this rate applies to the response status line and headers as well. /// From 5dd590e75ec4b95b03971430696545708e292b35 Mon Sep 17 00:00:00 2001 From: Joshua Clark Date: Thu, 8 Feb 2018 20:28:00 -0500 Subject: [PATCH 1517/1662] Add clearer exception message to HttpResponseStream ODE (#2305) --- src/Kestrel.Core/CoreStrings.resx | 3 +++ src/Kestrel.Core/Internal/Http/HttpResponseStream.cs | 2 +- src/Kestrel.Core/Properties/CoreStrings.Designer.cs | 8 ++++++++ test/Kestrel.Core.Tests/HttpResponseStreamTests.cs | 3 ++- 4 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/Kestrel.Core/CoreStrings.resx b/src/Kestrel.Core/CoreStrings.resx index a8a2db7f84..966dbfd1bb 100644 --- a/src/Kestrel.Core/CoreStrings.resx +++ b/src/Kestrel.Core/CoreStrings.resx @@ -500,4 +500,7 @@ For more information on configuring HTTPS see https://go.microsoft.com/fwlink/?l HTTP/2 support is experimental, see https://go.microsoft.com/fwlink/?linkid=866785 to enable it. + + Cannot write to the response body, the response has completed. + \ No newline at end of file diff --git a/src/Kestrel.Core/Internal/Http/HttpResponseStream.cs b/src/Kestrel.Core/Internal/Http/HttpResponseStream.cs index 90c8cae840..e1c44d645f 100644 --- a/src/Kestrel.Core/Internal/Http/HttpResponseStream.cs +++ b/src/Kestrel.Core/Internal/Http/HttpResponseStream.cs @@ -158,7 +158,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http } break; case HttpStreamState.Closed: - throw new ObjectDisposedException(nameof(HttpResponseStream)); + throw new ObjectDisposedException(nameof(HttpResponseStream), CoreStrings.WritingToResponseBodyAfterResponseCompleted); case HttpStreamState.Aborted: if (cancellationToken.IsCancellationRequested) { diff --git a/src/Kestrel.Core/Properties/CoreStrings.Designer.cs b/src/Kestrel.Core/Properties/CoreStrings.Designer.cs index 7e12e1c524..c915e95dff 100644 --- a/src/Kestrel.Core/Properties/CoreStrings.Designer.cs +++ b/src/Kestrel.Core/Properties/CoreStrings.Designer.cs @@ -878,6 +878,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core internal static string FormatWritingToResponseBodyNotSupported(object statusCode) => string.Format(CultureInfo.CurrentCulture, GetString("WritingToResponseBodyNotSupported", "statusCode"), statusCode); + /// + /// Cannot write to the response body, the response has completed. + /// + internal static string WritingToResponseBodyAfterResponseCompleted + { + get => GetString("WritingToResponseBodyAfterResponseCompleted"); + } + /// /// Connection shutdown abnormally. /// diff --git a/test/Kestrel.Core.Tests/HttpResponseStreamTests.cs b/test/Kestrel.Core.Tests/HttpResponseStreamTests.cs index cac27c5f52..06bd3436cd 100644 --- a/test/Kestrel.Core.Tests/HttpResponseStreamTests.cs +++ b/test/Kestrel.Core.Tests/HttpResponseStreamTests.cs @@ -99,7 +99,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests var stream = new HttpResponseStream(Mock.Of(), Mock.Of()); stream.StartAcceptingWrites(); stream.StopAcceptingWrites(); - Assert.Throws(() => { stream.WriteAsync(new byte[1], 0, 1); }); + var ex = Assert.Throws(() => { stream.WriteAsync(new byte[1], 0, 1); }); + Assert.Contains(CoreStrings.WritingToResponseBodyAfterResponseCompleted, ex.Message); } [Fact] From 0608de37dcda40641d92ba3f52fe27e2d0acd4f3 Mon Sep 17 00:00:00 2001 From: Nate McMaster Date: Fri, 9 Feb 2018 08:35:12 -0800 Subject: [PATCH 1518/1662] Upgrade dependencies to 2.1.0-preview1-28258 [auto-updated: dependencies] --- build/dependencies.props | 58 ++++++++++++++++++++-------------------- 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/build/dependencies.props b/build/dependencies.props index 3b353f4110..0cc201a2bd 100644 --- a/build/dependencies.props +++ b/build/dependencies.props @@ -7,39 +7,39 @@ 0.10.11 2.1.0-preview1-1010 1.10.0 - 2.1.0-preview1-28193 - 2.1.0-preview1-28193 - 2.1.0-preview1-28193 - 2.1.0-preview1-28193 - 2.1.0-preview1-28193 - 2.1.0-preview1-28193 - 2.1.0-preview1-28193 - 2.1.0-preview1-28193 - 2.1.0-preview1-28193 - 2.1.0-preview1-28193 - 2.1.0-preview1-28193 - 2.1.0-preview1-28193 - 2.1.0-preview1-28193 - 2.1.0-preview1-28193 - 2.1.0-preview1-28193 - 2.1.0-preview1-28193 - 2.1.0-preview1-28193 + 2.1.0-preview1-28258 + 2.1.0-preview1-28258 + 2.1.0-preview1-28258 + 2.1.0-preview1-28258 + 2.1.0-preview1-28258 + 2.1.0-preview1-28258 + 2.1.0-preview1-28258 + 2.1.0-preview1-28258 + 2.1.0-preview1-28258 + 2.1.0-preview1-28258 + 2.1.0-preview1-28258 + 2.1.0-preview1-28258 + 2.1.0-preview1-28258 + 2.1.0-preview1-28258 + 2.1.0-preview1-28258 + 2.1.0-preview1-28258 + 2.1.0-preview1-28258 2.0.0 - 2.1.0-preview1-26122-01 - 2.1.0-preview1-28193 + 2.1.0-preview1-26126-02 + 2.1.0-preview1-28258 15.3.0 4.7.49 10.0.1 - 4.5.0-preview1-26119-06 - 0.1.0-e180104-2 - 0.1.0-e180104-2 - 0.1.0-e180104-2 - 4.5.0-preview1-26119-06 - 4.5.0-preview1-26119-06 - 4.5.0-preview1-26119-06 - 4.5.0-preview1-26119-06 - 0.1.0-e180104-2 - 4.5.0-preview1-26119-06 + 4.5.0-preview1-26126-05 + 0.1.0-preview1-180129-1 + 0.1.0-preview1-180129-1 + 0.1.0-preview1-180129-1 + 4.5.0-preview1-26126-05 + 4.5.0-preview1-26126-05 + 4.5.0-preview1-26126-05 + 4.5.0-preview1-26126-05 + 0.1.0-preview1-180129-1 + 4.5.0-preview1-26126-05 0.8.0 2.3.1 2.3.1 From 7098c8d07db140b83dc269383fe209ec35a2f047 Mon Sep 17 00:00:00 2001 From: "ASP.NET CI" Date: Fri, 9 Feb 2018 11:48:37 -0800 Subject: [PATCH 1519/1662] Update dependencies.props [auto-updated: dependencies] --- build/dependencies.props | 38 +++++++++++++++++++------------------- korebuild-lock.txt | 4 ++-- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/build/dependencies.props b/build/dependencies.props index d8493c087d..666de45d2c 100644 --- a/build/dependencies.props +++ b/build/dependencies.props @@ -5,28 +5,28 @@ 0.10.11 - 2.1.0-preview2-15692 + 2.1.0-preview2-15698 1.10.0 - 2.1.0-preview2-28212 - 2.1.0-preview2-28212 - 2.1.0-preview2-28212 - 2.1.0-preview2-28212 - 2.1.0-preview2-28212 - 2.1.0-preview2-28212 - 2.1.0-preview2-28212 - 2.1.0-preview2-28212 - 2.1.0-preview2-28212 - 2.1.0-preview2-28212 - 2.1.0-preview2-28212 - 2.1.0-preview2-28212 - 2.1.0-preview2-28212 - 2.1.0-preview2-28212 - 2.1.0-preview2-28212 - 2.1.0-preview2-28212 - 2.1.0-preview2-28212 + 2.1.0-preview2-30066 + 2.1.0-preview2-30066 + 2.1.0-preview2-30066 + 2.1.0-preview2-30066 + 2.1.0-preview2-30066 + 2.1.0-preview2-30066 + 2.1.0-preview2-30066 + 2.1.0-preview2-30066 + 2.1.0-preview2-30066 + 2.1.0-preview2-30066 + 2.1.0-preview2-30066 + 2.1.0-preview2-30066 + 2.1.0-preview2-30066 + 2.1.0-preview2-30066 + 2.1.0-preview2-30066 + 2.1.0-preview2-30066 + 2.1.0-preview2-30066 2.0.0 2.1.0-preview2-26130-04 - 2.1.0-preview2-28212 + 2.1.0-preview2-30066 15.3.0 4.7.49 10.0.1 diff --git a/korebuild-lock.txt b/korebuild-lock.txt index 232cb858c2..3e2b56b91b 100644 --- a/korebuild-lock.txt +++ b/korebuild-lock.txt @@ -1,2 +1,2 @@ -version:2.1.0-preview2-15692 -commithash:5d9f445ce3f8492451a6f461df7e739bbed6a7f8 +version:2.1.0-preview2-15698 +commithash:7216e5068cb1957e09d45fcbe58a744dd5c2de73 From 2156030460b0d2cc37022dba86aa9f8b5a6050e5 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Sat, 10 Feb 2018 10:39:21 -0800 Subject: [PATCH 1520/1662] Clean up some of protocol abstractions (#2311) * Clean up some of protocol abstractions - Renamed PipeConnection to DuplexPipe - Removed MemoryPool from ConnectionContext - Work around value tuple issue on net471 --- ...Http1ConnectionParsingOverheadBenchmark.cs | 2 +- .../Http1WritingBenchmark.cs | 4 +- .../HttpProtocolFeatureCollection.cs | 2 +- .../RequestParsingBenchmark.cs | 2 +- .../ResponseHeaderCollectionBenchmark.cs | 2 +- .../ResponseHeadersWritingBenchmark.cs | 2 +- .../Internal/ConnectionHandler.cs | 6 +-- .../Internal/HttpConnectionMiddleware.cs | 2 +- .../ConnectionContext.cs | 8 +-- .../DefaultConnectionContext.cs | 2 - src/Protocols.Abstractions/DuplexPipe.cs | 53 +++++++++++++++++++ src/Protocols.Abstractions/PipeConnection.cs | 23 -------- .../PipeFactoryExtensions.cs | 23 -------- .../Http1ConnectionTests.cs | 2 +- .../Http2ConnectionTests.cs | 4 +- .../Kestrel.Core.Tests/HttpConnectionTests.cs | 2 +- .../HttpResponseHeadersTests.cs | 2 +- test/Kestrel.Core.Tests/TestInput.cs | 2 +- .../LibuvOutputConsumerTests.cs | 2 +- .../TestHelpers/MockConnectionHandler.cs | 10 ++-- 20 files changed, 77 insertions(+), 78 deletions(-) create mode 100644 src/Protocols.Abstractions/DuplexPipe.cs delete mode 100644 src/Protocols.Abstractions/PipeConnection.cs delete mode 100644 src/Protocols.Abstractions/PipeFactoryExtensions.cs diff --git a/benchmarks/Kestrel.Performance/Http1ConnectionParsingOverheadBenchmark.cs b/benchmarks/Kestrel.Performance/Http1ConnectionParsingOverheadBenchmark.cs index b4979f4a3b..ff3fa369bf 100644 --- a/benchmarks/Kestrel.Performance/Http1ConnectionParsingOverheadBenchmark.cs +++ b/benchmarks/Kestrel.Performance/Http1ConnectionParsingOverheadBenchmark.cs @@ -23,7 +23,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance public void Setup() { var memoryPool = new MemoryPool(); - var pair = PipeFactory.CreateConnectionPair(memoryPool); + var pair = DuplexPipe.CreateConnectionPair(memoryPool); var serviceContext = new ServiceContext { diff --git a/benchmarks/Kestrel.Performance/Http1WritingBenchmark.cs b/benchmarks/Kestrel.Performance/Http1WritingBenchmark.cs index 325b27c0e7..1f00d1e6cf 100644 --- a/benchmarks/Kestrel.Performance/Http1WritingBenchmark.cs +++ b/benchmarks/Kestrel.Performance/Http1WritingBenchmark.cs @@ -25,7 +25,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance private static readonly Func _psuedoAsyncTaskFunc = (obj) => _psuedoAsyncTask; private readonly TestHttp1Connection _http1Connection; - private (IDuplexPipe Transport, IDuplexPipe Application) _pair; + private DuplexPipe.DuplexPipePair _pair; private readonly byte[] _writeData; @@ -95,7 +95,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance { using (var memoryPool = new MemoryPool()) { - var pair = PipeFactory.CreateConnectionPair(memoryPool); + var pair = DuplexPipe.CreateConnectionPair(memoryPool); _pair = pair; var serviceContext = new ServiceContext diff --git a/benchmarks/Kestrel.Performance/HttpProtocolFeatureCollection.cs b/benchmarks/Kestrel.Performance/HttpProtocolFeatureCollection.cs index 23d9c80d3b..ddf7fa0554 100644 --- a/benchmarks/Kestrel.Performance/HttpProtocolFeatureCollection.cs +++ b/benchmarks/Kestrel.Performance/HttpProtocolFeatureCollection.cs @@ -78,7 +78,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance public HttpProtocolFeatureCollection() { var memoryPool = new MemoryPool(); - var pair = PipeFactory.CreateConnectionPair(memoryPool); + var pair = DuplexPipe.CreateConnectionPair(memoryPool); var serviceContext = new ServiceContext { diff --git a/benchmarks/Kestrel.Performance/RequestParsingBenchmark.cs b/benchmarks/Kestrel.Performance/RequestParsingBenchmark.cs index 3c7d4caaf7..c682553483 100644 --- a/benchmarks/Kestrel.Performance/RequestParsingBenchmark.cs +++ b/benchmarks/Kestrel.Performance/RequestParsingBenchmark.cs @@ -22,7 +22,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance public void Setup() { var memoryPool = new MemoryPool(); - var pair = PipeFactory.CreateConnectionPair(memoryPool); + var pair = DuplexPipe.CreateConnectionPair(memoryPool); var serviceContext = new ServiceContext { diff --git a/benchmarks/Kestrel.Performance/ResponseHeaderCollectionBenchmark.cs b/benchmarks/Kestrel.Performance/ResponseHeaderCollectionBenchmark.cs index 8f722aaba5..dd6cd25cf4 100644 --- a/benchmarks/Kestrel.Performance/ResponseHeaderCollectionBenchmark.cs +++ b/benchmarks/Kestrel.Performance/ResponseHeaderCollectionBenchmark.cs @@ -171,7 +171,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance public void Setup() { var memoryPool = new MemoryPool(); - var pair = PipeFactory.CreateConnectionPair(memoryPool); + var pair = DuplexPipe.CreateConnectionPair(memoryPool); var serviceContext = new ServiceContext { diff --git a/benchmarks/Kestrel.Performance/ResponseHeadersWritingBenchmark.cs b/benchmarks/Kestrel.Performance/ResponseHeadersWritingBenchmark.cs index 9c807620e4..8c7c3b46be 100644 --- a/benchmarks/Kestrel.Performance/ResponseHeadersWritingBenchmark.cs +++ b/benchmarks/Kestrel.Performance/ResponseHeadersWritingBenchmark.cs @@ -111,7 +111,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance public void Setup() { var memoryPool = new MemoryPool(); - var pair = PipeFactory.CreateConnectionPair(memoryPool); + var pair = DuplexPipe.CreateConnectionPair(memoryPool); var serviceContext = new ServiceContext { diff --git a/src/Kestrel.Core/Internal/ConnectionHandler.cs b/src/Kestrel.Core/Internal/ConnectionHandler.cs index bf8b598866..41607602d4 100644 --- a/src/Kestrel.Core/Internal/ConnectionHandler.cs +++ b/src/Kestrel.Core/Internal/ConnectionHandler.cs @@ -36,10 +36,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal // REVIEW: Unfortunately, we still need to use the service context to create the pipes since the settings // for the scheduler and limits are specified here - var inputOptions = GetInputPipeOptions(_serviceContext, connectionContext.MemoryPool, transportFeature.InputWriterScheduler); - var outputOptions = GetOutputPipeOptions(_serviceContext, connectionContext.MemoryPool, transportFeature.OutputReaderScheduler); + var inputOptions = GetInputPipeOptions(_serviceContext, transportFeature.MemoryPool, transportFeature.InputWriterScheduler); + var outputOptions = GetOutputPipeOptions(_serviceContext, transportFeature.MemoryPool, transportFeature.OutputReaderScheduler); - var pair = PipeFactory.CreateConnectionPair(inputOptions, outputOptions); + var pair = DuplexPipe.CreateConnectionPair(inputOptions, outputOptions); // Set the transport and connection id connectionContext.ConnectionId = CorrelationIdGenerator.GetNextId(); diff --git a/src/Kestrel.Core/Internal/HttpConnectionMiddleware.cs b/src/Kestrel.Core/Internal/HttpConnectionMiddleware.cs index 6514768ab5..3e25712899 100644 --- a/src/Kestrel.Core/Internal/HttpConnectionMiddleware.cs +++ b/src/Kestrel.Core/Internal/HttpConnectionMiddleware.cs @@ -44,7 +44,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal Protocols = _protocols, ServiceContext = _serviceContext, ConnectionFeatures = connectionContext.Features, - MemoryPool = connectionContext.MemoryPool, + MemoryPool = transportFeature.MemoryPool, ConnectionAdapters = _connectionAdapters, Transport = connectionContext.Transport, Application = transportFeature.Application diff --git a/src/Protocols.Abstractions/ConnectionContext.cs b/src/Protocols.Abstractions/ConnectionContext.cs index f4fb2dbae9..329afa4b11 100644 --- a/src/Protocols.Abstractions/ConnectionContext.cs +++ b/src/Protocols.Abstractions/ConnectionContext.cs @@ -1,8 +1,4 @@ -using System; -using System.Buffers; -using System.IO.Pipelines; -using System.Threading; -using System.Threading.Tasks; +using System.IO.Pipelines; using Microsoft.AspNetCore.Http.Features; namespace Microsoft.AspNetCore.Protocols @@ -14,7 +10,5 @@ namespace Microsoft.AspNetCore.Protocols public abstract IFeatureCollection Features { get; } public abstract IDuplexPipe Transport { get; set; } - - public abstract MemoryPool MemoryPool { get; } } } diff --git a/src/Protocols.Abstractions/DefaultConnectionContext.cs b/src/Protocols.Abstractions/DefaultConnectionContext.cs index 18ac26c673..cc75702caf 100644 --- a/src/Protocols.Abstractions/DefaultConnectionContext.cs +++ b/src/Protocols.Abstractions/DefaultConnectionContext.cs @@ -28,8 +28,6 @@ namespace Microsoft.AspNetCore.Protocols public override IFeatureCollection Features => _features.Collection; - public override MemoryPool MemoryPool => ConnectionTransportFeature.MemoryPool; - public override IDuplexPipe Transport { get => ConnectionTransportFeature.Transport; diff --git a/src/Protocols.Abstractions/DuplexPipe.cs b/src/Protocols.Abstractions/DuplexPipe.cs new file mode 100644 index 0000000000..a354af53e9 --- /dev/null +++ b/src/Protocols.Abstractions/DuplexPipe.cs @@ -0,0 +1,53 @@ +using System; +using System.Buffers; +using System.Collections.Generic; +using System.Text; + +namespace System.IO.Pipelines +{ + public class DuplexPipe : IDuplexPipe + { + public DuplexPipe(PipeReader reader, PipeWriter writer) + { + Input = reader; + Output = writer; + } + + public PipeReader Input { get; } + + public PipeWriter Output { get; } + + public void Dispose() + { + } + + public static DuplexPipePair CreateConnectionPair(MemoryPool memoryPool) + { + return CreateConnectionPair(new PipeOptions(memoryPool), new PipeOptions(memoryPool)); + } + + public static DuplexPipePair CreateConnectionPair(PipeOptions inputOptions, PipeOptions outputOptions) + { + var input = new Pipe(inputOptions); + var output = new Pipe(outputOptions); + + var transportToApplication = new DuplexPipe(output.Reader, input.Writer); + var applicationToTransport = new DuplexPipe(input.Reader, output.Writer); + + return new DuplexPipePair(applicationToTransport, transportToApplication); + } + + // This class exists to work around issues with value tuple on .NET Framework + public readonly struct DuplexPipePair + { + public IDuplexPipe Transport { get; } + public IDuplexPipe Application { get; } + + public DuplexPipePair(IDuplexPipe transport, IDuplexPipe application) + { + Transport = transport; + Application = application; + } + } + } +} diff --git a/src/Protocols.Abstractions/PipeConnection.cs b/src/Protocols.Abstractions/PipeConnection.cs deleted file mode 100644 index 5b3ab2a50b..0000000000 --- a/src/Protocols.Abstractions/PipeConnection.cs +++ /dev/null @@ -1,23 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace System.IO.Pipelines -{ - public class PipeConnection : IDuplexPipe - { - public PipeConnection(PipeReader reader, PipeWriter writer) - { - Input = reader; - Output = writer; - } - - public PipeReader Input { get; } - - public PipeWriter Output { get; } - - public void Dispose() - { - } - } -} diff --git a/src/Protocols.Abstractions/PipeFactoryExtensions.cs b/src/Protocols.Abstractions/PipeFactoryExtensions.cs deleted file mode 100644 index 01abf37428..0000000000 --- a/src/Protocols.Abstractions/PipeFactoryExtensions.cs +++ /dev/null @@ -1,23 +0,0 @@ -using System.Buffers; - -namespace System.IO.Pipelines -{ - public static class PipeFactory - { - public static (IDuplexPipe Transport, IDuplexPipe Application) CreateConnectionPair(MemoryPool memoryPool) - { - return CreateConnectionPair(new PipeOptions(memoryPool), new PipeOptions(memoryPool)); - } - - public static (IDuplexPipe Transport, IDuplexPipe Application) CreateConnectionPair(PipeOptions inputOptions, PipeOptions outputOptions) - { - var input = new Pipe(inputOptions); - var output = new Pipe(outputOptions); - - var transportToApplication = new PipeConnection(output.Reader, input.Writer); - var applicationToTransport = new PipeConnection(input.Reader, output.Writer); - - return (applicationToTransport, transportToApplication); - } - } -} diff --git a/test/Kestrel.Core.Tests/Http1ConnectionTests.cs b/test/Kestrel.Core.Tests/Http1ConnectionTests.cs index de20cc3f1e..7e286aad82 100644 --- a/test/Kestrel.Core.Tests/Http1ConnectionTests.cs +++ b/test/Kestrel.Core.Tests/Http1ConnectionTests.cs @@ -41,7 +41,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests public Http1ConnectionTests() { _pipelineFactory = new MemoryPool(); - var pair = PipeFactory.CreateConnectionPair(_pipelineFactory); + var pair = DuplexPipe.CreateConnectionPair(_pipelineFactory); _transport = pair.Transport; _application = pair.Application; diff --git a/test/Kestrel.Core.Tests/Http2ConnectionTests.cs b/test/Kestrel.Core.Tests/Http2ConnectionTests.cs index 9ab55bc8d5..e88add0081 100644 --- a/test/Kestrel.Core.Tests/Http2ConnectionTests.cs +++ b/test/Kestrel.Core.Tests/Http2ConnectionTests.cs @@ -94,7 +94,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests private static readonly byte[] _maxData = Encoding.ASCII.GetBytes(new string('a', Http2Frame.MinAllowedMaxFrameSize)); private readonly MemoryPool _memoryPool = new MemoryPool(); - private readonly (IDuplexPipe Transport, IDuplexPipe Application) _pair; + private readonly DuplexPipe.DuplexPipePair _pair; private readonly TestApplicationErrorLogger _logger; private readonly Http2ConnectionContext _connectionContext; private readonly Http2Connection _connection; @@ -122,7 +122,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests public Http2ConnectionTests() { - _pair = PipeFactory.CreateConnectionPair(_memoryPool); + _pair = DuplexPipe.CreateConnectionPair(_memoryPool); _noopApplication = context => Task.CompletedTask; diff --git a/test/Kestrel.Core.Tests/HttpConnectionTests.cs b/test/Kestrel.Core.Tests/HttpConnectionTests.cs index e426c22d21..4e2829e863 100644 --- a/test/Kestrel.Core.Tests/HttpConnectionTests.cs +++ b/test/Kestrel.Core.Tests/HttpConnectionTests.cs @@ -25,7 +25,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests public HttpConnectionTests() { _memoryPool = new MemoryPool(); - var pair = PipeFactory.CreateConnectionPair(_memoryPool); + var pair = DuplexPipe.CreateConnectionPair(_memoryPool); _httpConnectionContext = new HttpConnectionContext { diff --git a/test/Kestrel.Core.Tests/HttpResponseHeadersTests.cs b/test/Kestrel.Core.Tests/HttpResponseHeadersTests.cs index 4634b758cf..0df993ab89 100644 --- a/test/Kestrel.Core.Tests/HttpResponseHeadersTests.cs +++ b/test/Kestrel.Core.Tests/HttpResponseHeadersTests.cs @@ -22,7 +22,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests { using (var memoryPool = new MemoryPool()) { - var pair = PipeFactory.CreateConnectionPair(memoryPool); + var pair = DuplexPipe.CreateConnectionPair(memoryPool); var http1ConnectionContext = new Http1ConnectionContext { ServiceContext = new TestServiceContext(), diff --git a/test/Kestrel.Core.Tests/TestInput.cs b/test/Kestrel.Core.Tests/TestInput.cs index 6153e8d2a5..601fcd133e 100644 --- a/test/Kestrel.Core.Tests/TestInput.cs +++ b/test/Kestrel.Core.Tests/TestInput.cs @@ -20,7 +20,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests public TestInput() { _memoryPool = new MemoryPool(); - var pair = PipeFactory.CreateConnectionPair(_memoryPool); + var pair = DuplexPipe.CreateConnectionPair(_memoryPool); Transport = pair.Transport; Application = pair.Application; diff --git a/test/Kestrel.Transport.Libuv.Tests/LibuvOutputConsumerTests.cs b/test/Kestrel.Transport.Libuv.Tests/LibuvOutputConsumerTests.cs index a63ab1bec8..d674ae6e96 100644 --- a/test/Kestrel.Transport.Libuv.Tests/LibuvOutputConsumerTests.cs +++ b/test/Kestrel.Transport.Libuv.Tests/LibuvOutputConsumerTests.cs @@ -695,7 +695,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests private Http1OutputProducer CreateOutputProducer(PipeOptions pipeOptions, CancellationTokenSource cts = null) { - var pair = PipeFactory.CreateConnectionPair(pipeOptions, pipeOptions); + var pair = DuplexPipe.CreateConnectionPair(pipeOptions, pipeOptions); var logger = new TestApplicationErrorLogger(); var serviceContext = new TestServiceContext diff --git a/test/Kestrel.Transport.Libuv.Tests/TestHelpers/MockConnectionHandler.cs b/test/Kestrel.Transport.Libuv.Tests/TestHelpers/MockConnectionHandler.cs index d52a868b67..2b2b380755 100644 --- a/test/Kestrel.Transport.Libuv.Tests/TestHelpers/MockConnectionHandler.cs +++ b/test/Kestrel.Transport.Libuv.Tests/TestHelpers/MockConnectionHandler.cs @@ -20,13 +20,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests.TestHelpers { var connectionContext = new DefaultConnectionContext(features); - Input = new Pipe(InputOptions(connectionContext.MemoryPool)); - Output = new Pipe(OutputOptions(connectionContext.MemoryPool)); - var feature = connectionContext.Features.Get(); - connectionContext.Transport = new PipeConnection(Input.Reader, Output.Writer); - feature.Application = new PipeConnection(Output.Reader, Input.Writer); + Input = new Pipe(InputOptions(feature.MemoryPool)); + Output = new Pipe(OutputOptions(feature.MemoryPool)); + + connectionContext.Transport = new DuplexPipe(Input.Reader, Output.Writer); + feature.Application = new DuplexPipe(Output.Reader, Input.Writer); } public Pipe Input { get; private set; } From f65e89294dfb99eaf5b0c0cc9c817d699128cdaf Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Sat, 10 Feb 2018 21:18:21 +0000 Subject: [PATCH 1521/1662] Add Plaintext sample (#2312) --- KestrelHttpServer.sln | 15 ++++++++ samples/PlaintextApp/PlaintextApp.csproj | 13 +++++++ samples/PlaintextApp/Startup.cs | 45 ++++++++++++++++++++++++ 3 files changed, 73 insertions(+) create mode 100644 samples/PlaintextApp/PlaintextApp.csproj create mode 100644 samples/PlaintextApp/Startup.cs diff --git a/KestrelHttpServer.sln b/KestrelHttpServer.sln index 345cf04f72..0440b242cf 100644 --- a/KestrelHttpServer.sln +++ b/KestrelHttpServer.sln @@ -124,6 +124,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Http2SampleApp", "samples\H EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SystemdTestApp", "samples\SystemdTestApp\SystemdTestApp.csproj", "{A7994A41-CAF8-47A7-8975-F101F75B5BC1}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PlaintextApp", "samples\PlaintextApp\PlaintextApp.csproj", "{CE5523AE-6E38-4E20-998F-C64E02C5CC51}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -350,6 +352,18 @@ Global {A7994A41-CAF8-47A7-8975-F101F75B5BC1}.Release|x64.Build.0 = Release|Any CPU {A7994A41-CAF8-47A7-8975-F101F75B5BC1}.Release|x86.ActiveCfg = Release|Any CPU {A7994A41-CAF8-47A7-8975-F101F75B5BC1}.Release|x86.Build.0 = Release|Any CPU + {CE5523AE-6E38-4E20-998F-C64E02C5CC51}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {CE5523AE-6E38-4E20-998F-C64E02C5CC51}.Debug|Any CPU.Build.0 = Debug|Any CPU + {CE5523AE-6E38-4E20-998F-C64E02C5CC51}.Debug|x64.ActiveCfg = Debug|Any CPU + {CE5523AE-6E38-4E20-998F-C64E02C5CC51}.Debug|x64.Build.0 = Debug|Any CPU + {CE5523AE-6E38-4E20-998F-C64E02C5CC51}.Debug|x86.ActiveCfg = Debug|Any CPU + {CE5523AE-6E38-4E20-998F-C64E02C5CC51}.Debug|x86.Build.0 = Debug|Any CPU + {CE5523AE-6E38-4E20-998F-C64E02C5CC51}.Release|Any CPU.ActiveCfg = Release|Any CPU + {CE5523AE-6E38-4E20-998F-C64E02C5CC51}.Release|Any CPU.Build.0 = Release|Any CPU + {CE5523AE-6E38-4E20-998F-C64E02C5CC51}.Release|x64.ActiveCfg = Release|Any CPU + {CE5523AE-6E38-4E20-998F-C64E02C5CC51}.Release|x64.Build.0 = Release|Any CPU + {CE5523AE-6E38-4E20-998F-C64E02C5CC51}.Release|x86.ActiveCfg = Release|Any CPU + {CE5523AE-6E38-4E20-998F-C64E02C5CC51}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -375,6 +389,7 @@ Global {9C7B6B5F-088A-436E-834B-6373EA36DEEE} = {D3273454-EA07-41D2-BF0B-FCC3675C2483} {7BC22A4A-15D2-44C2-AB45-049F0FB562FA} = {8A3D00B8-1CCF-4BE6-A060-11104CE2D9CE} {A7994A41-CAF8-47A7-8975-F101F75B5BC1} = {8A3D00B8-1CCF-4BE6-A060-11104CE2D9CE} + {CE5523AE-6E38-4E20-998F-C64E02C5CC51} = {8A3D00B8-1CCF-4BE6-A060-11104CE2D9CE} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {2D10D020-6770-47CA-BB8D-2C23FE3AE071} diff --git a/samples/PlaintextApp/PlaintextApp.csproj b/samples/PlaintextApp/PlaintextApp.csproj new file mode 100644 index 0000000000..238983e4f8 --- /dev/null +++ b/samples/PlaintextApp/PlaintextApp.csproj @@ -0,0 +1,13 @@ + + + + netcoreapp2.1;net461 + false + true + + + + + + + diff --git a/samples/PlaintextApp/Startup.cs b/samples/PlaintextApp/Startup.cs new file mode 100644 index 0000000000..28da0a6f2c --- /dev/null +++ b/samples/PlaintextApp/Startup.cs @@ -0,0 +1,45 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System.IO; +using System.Net; +using System.Text; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Hosting; + +namespace PlaintextApp +{ + public class Startup + { + private static readonly byte[] _helloWorldBytes = Encoding.UTF8.GetBytes("Hello, World!"); + + public void Configure(IApplicationBuilder app) + { + app.Run((httpContext) => + { + var response = httpContext.Response; + response.StatusCode = 200; + response.ContentType = "text/plain"; + + var helloWorld = _helloWorldBytes; + response.ContentLength = helloWorld.Length; + return response.Body.WriteAsync(helloWorld, 0, helloWorld.Length); + }); + } + + public static Task Main(string[] args) + { + var host = new WebHostBuilder() + .UseKestrel(options => + { + options.Listen(IPAddress.Loopback, 5001); + }) + .UseContentRoot(Directory.GetCurrentDirectory()) + .UseStartup() + .Build(); + + return host.RunAsync(); + } + } +} From b0673337e9303ad97ce74745a19c291e81ab45c7 Mon Sep 17 00:00:00 2001 From: "ASP.NET CI" Date: Sun, 11 Feb 2018 12:29:52 -0800 Subject: [PATCH 1522/1662] Update dependencies.props [auto-updated: dependencies] --- build/dependencies.props | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/build/dependencies.props b/build/dependencies.props index 666de45d2c..8952a0dd69 100644 --- a/build/dependencies.props +++ b/build/dependencies.props @@ -7,26 +7,26 @@ 0.10.11 2.1.0-preview2-15698 1.10.0 - 2.1.0-preview2-30066 - 2.1.0-preview2-30066 - 2.1.0-preview2-30066 - 2.1.0-preview2-30066 - 2.1.0-preview2-30066 - 2.1.0-preview2-30066 - 2.1.0-preview2-30066 - 2.1.0-preview2-30066 - 2.1.0-preview2-30066 - 2.1.0-preview2-30066 - 2.1.0-preview2-30066 - 2.1.0-preview2-30066 - 2.1.0-preview2-30066 - 2.1.0-preview2-30066 - 2.1.0-preview2-30066 - 2.1.0-preview2-30066 - 2.1.0-preview2-30066 + 2.1.0-preview2-30077 + 2.1.0-preview2-30077 + 2.1.0-preview2-30077 + 2.1.0-preview2-30077 + 2.1.0-preview2-30077 + 2.1.0-preview2-30077 + 2.1.0-preview2-30077 + 2.1.0-preview2-30077 + 2.1.0-preview2-30077 + 2.1.0-preview2-30077 + 2.1.0-preview2-30077 + 2.1.0-preview2-30077 + 2.1.0-preview2-30077 + 2.1.0-preview2-30077 + 2.1.0-preview2-30077 + 2.1.0-preview2-30077 + 2.1.0-preview2-30077 2.0.0 2.1.0-preview2-26130-04 - 2.1.0-preview2-30066 + 2.1.0-preview2-30077 15.3.0 4.7.49 10.0.1 @@ -42,7 +42,7 @@ 4.5.0-preview2-26130-01 0.8.0 2.3.1 - 2.3.1 + 2.4.0-beta.1.build3945 \ No newline at end of file From 9341f72b8d489b6c3b6f6f367bc557f8cb3af997 Mon Sep 17 00:00:00 2001 From: Alessio Franceschelli Date: Wed, 14 Feb 2018 19:46:13 +0000 Subject: [PATCH 1523/1662] Consumes request before closing connection (#2314) --- .../Internal/Http/Http1MessageBody.cs | 2 ++ .../Internal/Http/HttpProtocol.cs | 2 +- .../Http1ConnectionTests.cs | 21 +++++++++++++++++++ test/shared/TestHttp1Connection.cs | 7 +++++++ 4 files changed, 31 insertions(+), 1 deletion(-) diff --git a/src/Kestrel.Core/Internal/Http/Http1MessageBody.cs b/src/Kestrel.Core/Internal/Http/Http1MessageBody.cs index 521a9c58f8..4910ae18be 100644 --- a/src/Kestrel.Core/Internal/Http/Http1MessageBody.cs +++ b/src/Kestrel.Core/Internal/Http/Http1MessageBody.cs @@ -294,6 +294,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http RequestUpgrade = true; } + public override bool IsEmpty => true; + protected override bool Read(ReadOnlyBuffer readableBuffer, PipeWriter writableBuffer, out SequencePosition consumed, out SequencePosition examined) { Copy(readableBuffer, writableBuffer); diff --git a/src/Kestrel.Core/Internal/Http/HttpProtocol.cs b/src/Kestrel.Core/Internal/Http/HttpProtocol.cs index f8ada6f76e..09f6b54af5 100644 --- a/src/Kestrel.Core/Internal/Http/HttpProtocol.cs +++ b/src/Kestrel.Core/Internal/Http/HttpProtocol.cs @@ -533,7 +533,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http await ProduceEnd(); // ForZeroContentLength does not complete the reader nor the writer - if (!messageBody.IsEmpty && _keepAlive) + if (!messageBody.IsEmpty) { // Finish reading the request body in case the app did not. await messageBody.ConsumeAsync(); diff --git a/test/Kestrel.Core.Tests/Http1ConnectionTests.cs b/test/Kestrel.Core.Tests/Http1ConnectionTests.cs index 7e286aad82..75c7f4f560 100644 --- a/test/Kestrel.Core.Tests/Http1ConnectionTests.cs +++ b/test/Kestrel.Core.Tests/Http1ConnectionTests.cs @@ -12,6 +12,7 @@ using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; +using Microsoft.AspNetCore.Hosting.Server; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Server.Kestrel.Core.Features; @@ -792,6 +793,26 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests Assert.StartsWith(CoreStrings.NonNegativeNumberOrNullRequired, ex.Message); } + [Fact] + public async Task ConsumesRequestWhenApplicationDoesNotConsumeIt() + { + var httpApplication = new DummyApplication(async context => + { + var buffer = new byte[10]; + await context.Response.Body.WriteAsync(buffer, 0, 10); + }); + var mockMessageBody = new Mock(null); + _http1Connection.NextMessageBody = mockMessageBody.Object; + + var requestProcessingTask = _http1Connection.ProcessRequestsAsync(httpApplication); + + var data = Encoding.ASCII.GetBytes("POST / HTTP/1.1\r\nHost:\r\nConnection: close\r\ncontent-length: 1\r\n\r\n"); + await _application.Output.WriteAsync(data); + await requestProcessingTask.TimeoutAfter(TestConstants.DefaultTimeout); + + mockMessageBody.Verify(body => body.ConsumeAsync(), Times.Once); + } + private static async Task WaitForCondition(TimeSpan timeout, Func condition) { const int MaxWaitLoop = 150; diff --git a/test/shared/TestHttp1Connection.cs b/test/shared/TestHttp1Connection.cs index d98f2e91e0..f53a2a52db 100644 --- a/test/shared/TestHttp1Connection.cs +++ b/test/shared/TestHttp1Connection.cs @@ -25,9 +25,16 @@ namespace Microsoft.AspNetCore.Testing set => _keepAlive = value; } + public MessageBody NextMessageBody { private get; set; } + public Task ProduceEndAsync() { return ProduceEnd(); } + + protected override MessageBody CreateMessageBody() + { + return NextMessageBody ?? base.CreateMessageBody(); + } } } From 14332c5daf94a7b2d771dc5ba8a03e4b2f63a604 Mon Sep 17 00:00:00 2001 From: Alessio Franceschelli Date: Thu, 15 Feb 2018 00:01:07 +0000 Subject: [PATCH 1524/1662] Allows Content-Length for 304 Not Modified response (#2321) --- .../Internal/Http/HttpProtocol.cs | 1 + test/Kestrel.FunctionalTests/ResponseTests.cs | 29 +++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/src/Kestrel.Core/Internal/Http/HttpProtocol.cs b/src/Kestrel.Core/Internal/Http/HttpProtocol.cs index 09f6b54af5..d0e90e1054 100644 --- a/src/Kestrel.Core/Internal/Http/HttpProtocol.cs +++ b/src/Kestrel.Core/Internal/Http/HttpProtocol.cs @@ -875,6 +875,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http var responseHeaders = HttpResponseHeaders; if (!HttpMethods.IsHead(Method) && + StatusCode != StatusCodes.Status304NotModified && !responseHeaders.HasTransferEncoding && responseHeaders.ContentLength.HasValue && _responseBytesWritten < responseHeaders.ContentLength.Value) diff --git a/test/Kestrel.FunctionalTests/ResponseTests.cs b/test/Kestrel.FunctionalTests/ResponseTests.cs index aa4d0fe84b..4f5513ec98 100644 --- a/test/Kestrel.FunctionalTests/ResponseTests.cs +++ b/test/Kestrel.FunctionalTests/ResponseTests.cs @@ -2662,6 +2662,35 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } } + [Fact] + public async Task NonZeroContentLengthFor304StatusCodeIsAllowed() + { + using (var server = new TestServer(httpContext => + { + var response = httpContext.Response; + response.StatusCode = StatusCodes.Status304NotModified; + response.ContentLength = 42; + + return Task.CompletedTask; + })) + { + using (var connection = server.CreateConnection()) + { + await connection.Send( + "GET / HTTP/1.1", + "Host:", + "", + ""); + await connection.Receive( + "HTTP/1.1 304 Not Modified", + $"Date: {server.Context.DateHeaderValue}", + "Content-Length: 42", + "", + ""); + } + } + } + public static TheoryData NullHeaderData { get From d78e7ea80d734b6d0b094245e8c7727d670e13da Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Thu, 15 Feb 2018 14:05:45 -0800 Subject: [PATCH 1525/1662] Fixed race in sockets transport (#2279) (#2322) --- .../Internal/SocketConnection.cs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/Kestrel.Transport.Sockets/Internal/SocketConnection.cs b/src/Kestrel.Transport.Sockets/Internal/SocketConnection.cs index cf128c05f3..2ab964e894 100644 --- a/src/Kestrel.Transport.Sockets/Internal/SocketConnection.cs +++ b/src/Kestrel.Transport.Sockets/Internal/SocketConnection.cs @@ -57,13 +57,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal public async Task StartAsync(IConnectionHandler connectionHandler) { + Exception sendError = null; try { connectionHandler.OnConnection(this); // Spawn send and receive logic Task receiveTask = DoReceive(); - Task sendTask = DoSend(); + Task sendTask = DoSend(); // If the sending task completes then close the receive // We don't need to do this in the other direction because the kestrel @@ -76,7 +77,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal // Now wait for both to complete await receiveTask; - await sendTask; + sendError = await sendTask; // Dispose the socket(should noop if already called) _socket.Dispose(); @@ -85,6 +86,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal { _trace.LogError(0, ex, $"Unexpected exception in {nameof(SocketConnection)}.{nameof(StartAsync)}."); } + finally + { + // Complete the output after disposing the socket + Output.Complete(sendError); + } } private async Task DoReceive() @@ -181,7 +187,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal } } - private async Task DoSend() + private async Task DoSend() { Exception error = null; @@ -233,8 +239,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal } finally { - Output.Complete(error); - // Make sure to close the connection only after the _aborted flag is set. // Without this, the RequestsCanBeAbortedMidRead test will sometimes fail when // a BadHttpRequestException is thrown instead of a TaskCanceledException. @@ -242,6 +246,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal _trace.ConnectionWriteFin(ConnectionId); _socket.Shutdown(SocketShutdown.Both); } + + return error; } } } From 4afaa386db527e1ff168389bb189ddbecd8deaff Mon Sep 17 00:00:00 2001 From: Mike Harder Date: Fri, 16 Feb 2018 14:04:16 -0800 Subject: [PATCH 1526/1662] Remove unnecessary usings (#2326) --- .../Kestrel.Performance/DotSegmentRemovalBenchmark.cs | 1 - benchmarks/Kestrel.Performance/HttpParserBenchmark.cs | 1 - benchmarks/Kestrel.Performance/Mocks/NullParser.cs | 2 -- src/Kestrel.Core/Adapter/Internal/AdaptedPipeline.cs | 1 - .../Adapter/Internal/LoggingConnectionAdapter.cs | 1 - src/Kestrel.Core/Internal/CertificateLoader.cs | 2 -- src/Kestrel.Core/Internal/ConfigurationReader.cs | 1 - src/Kestrel.Core/Internal/Http/Http1Connection.cs | 1 - src/Kestrel.Core/Internal/Http/Http1ConnectionContext.cs | 1 - src/Kestrel.Core/Internal/Http/Http1MessageBody.cs | 1 - src/Kestrel.Core/Internal/Http/Http1OutputProducer.cs | 1 - src/Kestrel.Core/Internal/Http/HttpParser.cs | 2 -- .../Internal/Http/HttpProtocol.FeatureCollection.cs | 1 - src/Kestrel.Core/Internal/Http/HttpRequestStream.cs | 1 - src/Kestrel.Core/Internal/Http/IHttpParser.cs | 2 -- src/Kestrel.Core/Internal/Http/IHttpProtocolContext.cs | 1 - src/Kestrel.Core/Internal/Http/MessageBody.cs | 1 - src/Kestrel.Core/Internal/Http2/HPack/HPackEncoder.cs | 3 --- src/Kestrel.Core/Internal/Http2/Http2Connection.cs | 2 -- src/Kestrel.Core/Internal/Http2/Http2ErrorCode.cs | 1 - src/Kestrel.Core/Internal/Http2/Http2Frame.Continuation.cs | 1 - src/Kestrel.Core/Internal/Http2/Http2Frame.Ping.cs | 1 - src/Kestrel.Core/Internal/Http2/Http2Frame.cs | 1 - src/Kestrel.Core/Internal/Http2/Http2FrameReader.cs | 2 -- src/Kestrel.Core/Internal/Http2/Http2PeerSettings.cs | 1 - src/Kestrel.Core/Internal/Http2/Http2StreamContext.cs | 1 - src/Kestrel.Core/Internal/HttpsConnectionAdapter.cs | 1 - .../HttpConnectionManagerShutdownExtensions.cs | 1 - .../Internal/Infrastructure/KestrelEventSource.cs | 4 ---- src/Kestrel.Core/Internal/ServerAddressesFeature.cs | 2 -- src/Kestrel.Core/Internal/ServiceContext.cs | 1 - src/Kestrel.Core/KestrelServer.cs | 1 - src/Kestrel.Core/ListenOptionsHttpsExtensions.cs | 1 - .../Internal/IConnectionHandler.cs | 1 - .../Internal/TransportConnection.Features.cs | 1 - .../Internal/TransportConnection.cs | 3 +-- src/Kestrel.Transport.Libuv/Internal/LibuvConnection.cs | 1 - .../Internal/LibuvConnectionContext.cs | 2 -- src/Kestrel.Transport.Libuv/Internal/LibuvThread.cs | 1 - .../Internal/Networking/UvWriteReq.cs | 1 - src/Kestrel.Transport.Sockets/Internal/SocketConnection.cs | 2 -- src/Kestrel.Transport.Sockets/Internal/SocketSender.cs | 1 - src/Kestrel.Transport.Sockets/SocketTransport.cs | 1 - src/Kestrel.Transport.Sockets/SocketTransportOptions.cs | 3 --- src/Protocols.Abstractions/ConnectionDelegate.cs | 5 +---- src/Protocols.Abstractions/DefaultConnectionContext.cs | 3 +-- src/Protocols.Abstractions/DuplexPipe.cs | 5 +---- src/Protocols.Abstractions/Features/IConnectionIdFeature.cs | 6 +----- src/Protocols.Abstractions/IConnectionBuilder.cs | 2 -- test/Kestrel.Core.Tests/AddressBinderTests.cs | 1 - test/Kestrel.Core.Tests/HPackEncoderTests.cs | 1 - test/Kestrel.Core.Tests/Http1ConnectionTests.cs | 2 -- test/Kestrel.Core.Tests/HttpParserTests.cs | 1 - test/Kestrel.Core.Tests/HttpRequestHeadersTests.cs | 1 - test/Kestrel.Core.Tests/IntegerDecoderTests.cs | 1 - test/Kestrel.Core.Tests/IntegerEncoderTests.cs | 1 - test/Kestrel.Core.Tests/KestrelEventSourceTests.cs | 1 - test/Kestrel.Core.Tests/PipeOptionsTests.cs | 3 --- test/Kestrel.Core.Tests/ServerAddressTests.cs | 1 - test/Kestrel.FunctionalTests/AddressRegistrationTests.cs | 1 - test/Kestrel.FunctionalTests/BadHttpRequestTests.cs | 1 - test/Kestrel.FunctionalTests/HttpsTests.cs | 2 -- test/Kestrel.FunctionalTests/KeepAliveTimeoutTests.cs | 1 - test/Kestrel.FunctionalTests/RequestTests.cs | 1 - .../TestHelpers/NetworkIsReachableAttribute.cs | 1 - test/Kestrel.Transport.Libuv.Tests/MultipleLoopTests.cs | 2 -- test/Kestrel.Transport.Libuv.Tests/NetworkingTests.cs | 1 - .../TestHelpers/TestLibuvTransportContext.cs | 1 - test/shared/PassThroughConnectionAdapter.cs | 1 - test/shared/TestServiceContext.cs | 1 - tools/CodeGenerator/HttpProtocolFeatureCollection.cs | 3 --- 71 files changed, 5 insertions(+), 107 deletions(-) diff --git a/benchmarks/Kestrel.Performance/DotSegmentRemovalBenchmark.cs b/benchmarks/Kestrel.Performance/DotSegmentRemovalBenchmark.cs index 79389d4a33..5f943d97de 100644 --- a/benchmarks/Kestrel.Performance/DotSegmentRemovalBenchmark.cs +++ b/benchmarks/Kestrel.Performance/DotSegmentRemovalBenchmark.cs @@ -1,7 +1,6 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System; using System.Text; using BenchmarkDotNet.Attributes; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; diff --git a/benchmarks/Kestrel.Performance/HttpParserBenchmark.cs b/benchmarks/Kestrel.Performance/HttpParserBenchmark.cs index 2c42151f34..5b02d38a93 100644 --- a/benchmarks/Kestrel.Performance/HttpParserBenchmark.cs +++ b/benchmarks/Kestrel.Performance/HttpParserBenchmark.cs @@ -3,7 +3,6 @@ using System; using System.Buffers; -using System.IO.Pipelines; using BenchmarkDotNet.Attributes; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; diff --git a/benchmarks/Kestrel.Performance/Mocks/NullParser.cs b/benchmarks/Kestrel.Performance/Mocks/NullParser.cs index 3f83491dd8..60bab155a0 100644 --- a/benchmarks/Kestrel.Performance/Mocks/NullParser.cs +++ b/benchmarks/Kestrel.Performance/Mocks/NullParser.cs @@ -4,8 +4,6 @@ using System; using System.Buffers; using System.Collections; -using System.Collections.Sequences; -using System.IO.Pipelines; using System.Text; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; diff --git a/src/Kestrel.Core/Adapter/Internal/AdaptedPipeline.cs b/src/Kestrel.Core/Adapter/Internal/AdaptedPipeline.cs index 2cebf61741..fd8c35f037 100644 --- a/src/Kestrel.Core/Adapter/Internal/AdaptedPipeline.cs +++ b/src/Kestrel.Core/Adapter/Internal/AdaptedPipeline.cs @@ -6,7 +6,6 @@ using System.IO; using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; using System.IO.Pipelines; -using System.Runtime.InteropServices; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal { diff --git a/src/Kestrel.Core/Adapter/Internal/LoggingConnectionAdapter.cs b/src/Kestrel.Core/Adapter/Internal/LoggingConnectionAdapter.cs index 10d370df56..1afd32d1d6 100644 --- a/src/Kestrel.Core/Adapter/Internal/LoggingConnectionAdapter.cs +++ b/src/Kestrel.Core/Adapter/Internal/LoggingConnectionAdapter.cs @@ -4,7 +4,6 @@ using System; using System.IO; using System.Threading.Tasks; -using Microsoft.AspNetCore.Http.Features; using Microsoft.Extensions.Logging; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal diff --git a/src/Kestrel.Core/Internal/CertificateLoader.cs b/src/Kestrel.Core/Internal/CertificateLoader.cs index 087fad7d87..ce9c17e340 100644 --- a/src/Kestrel.Core/Internal/CertificateLoader.cs +++ b/src/Kestrel.Core/Internal/CertificateLoader.cs @@ -2,10 +2,8 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.Collections.Generic; using System.Linq; using System.Security.Cryptography.X509Certificates; -using System.Text; using Microsoft.AspNetCore.Server.Kestrel.Core; namespace Microsoft.AspNetCore.Server.Kestrel.Https.Internal diff --git a/src/Kestrel.Core/Internal/ConfigurationReader.cs b/src/Kestrel.Core/Internal/ConfigurationReader.cs index 08f347b922..b36a9af94e 100644 --- a/src/Kestrel.Core/Internal/ConfigurationReader.cs +++ b/src/Kestrel.Core/Internal/ConfigurationReader.cs @@ -3,7 +3,6 @@ using System; using System.Collections.Generic; -using System.Linq; using Microsoft.Extensions.Configuration; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal diff --git a/src/Kestrel.Core/Internal/Http/Http1Connection.cs b/src/Kestrel.Core/Internal/Http/Http1Connection.cs index e0e5c7d438..a09b17e139 100644 --- a/src/Kestrel.Core/Internal/Http/Http1Connection.cs +++ b/src/Kestrel.Core/Internal/Http/Http1Connection.cs @@ -4,7 +4,6 @@ using System; using System.Buffers; using System.Collections; -using System.Collections.Sequences; using System.Diagnostics; using System.IO.Pipelines; using System.Runtime.InteropServices; diff --git a/src/Kestrel.Core/Internal/Http/Http1ConnectionContext.cs b/src/Kestrel.Core/Internal/Http/Http1ConnectionContext.cs index cb3d9a2cef..b88bb4bedb 100644 --- a/src/Kestrel.Core/Internal/Http/Http1ConnectionContext.cs +++ b/src/Kestrel.Core/Internal/Http/Http1ConnectionContext.cs @@ -5,7 +5,6 @@ using System.Buffers; using System.IO.Pipelines; using System.Net; using Microsoft.AspNetCore.Http.Features; -using Microsoft.AspNetCore.Protocols; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http diff --git a/src/Kestrel.Core/Internal/Http/Http1MessageBody.cs b/src/Kestrel.Core/Internal/Http/Http1MessageBody.cs index 4910ae18be..4e08e419fb 100644 --- a/src/Kestrel.Core/Internal/Http/Http1MessageBody.cs +++ b/src/Kestrel.Core/Internal/Http/Http1MessageBody.cs @@ -4,7 +4,6 @@ using System; using System.Buffers; using System.Collections; -using System.Collections.Sequences; using System.IO; using System.IO.Pipelines; using System.Threading.Tasks; diff --git a/src/Kestrel.Core/Internal/Http/Http1OutputProducer.cs b/src/Kestrel.Core/Internal/Http/Http1OutputProducer.cs index a3781075c5..f220e7c70f 100644 --- a/src/Kestrel.Core/Internal/Http/Http1OutputProducer.cs +++ b/src/Kestrel.Core/Internal/Http/Http1OutputProducer.cs @@ -3,7 +3,6 @@ using System; using System.Buffers; -using System.Diagnostics; using System.IO.Pipelines; using System.Runtime.CompilerServices; using System.Text; diff --git a/src/Kestrel.Core/Internal/Http/HttpParser.cs b/src/Kestrel.Core/Internal/Http/HttpParser.cs index ece56ac7ed..36c4ffecfb 100644 --- a/src/Kestrel.Core/Internal/Http/HttpParser.cs +++ b/src/Kestrel.Core/Internal/Http/HttpParser.cs @@ -4,8 +4,6 @@ using System; using System.Buffers; using System.Collections; -using System.Collections.Sequences; -using System.IO.Pipelines; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; diff --git a/src/Kestrel.Core/Internal/Http/HttpProtocol.FeatureCollection.cs b/src/Kestrel.Core/Internal/Http/HttpProtocol.FeatureCollection.cs index 230ba868ac..e4fe29168f 100644 --- a/src/Kestrel.Core/Internal/Http/HttpProtocol.FeatureCollection.cs +++ b/src/Kestrel.Core/Internal/Http/HttpProtocol.FeatureCollection.cs @@ -11,7 +11,6 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Server.Kestrel.Core.Features; -using Microsoft.Extensions.Primitives; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { diff --git a/src/Kestrel.Core/Internal/Http/HttpRequestStream.cs b/src/Kestrel.Core/Internal/Http/HttpRequestStream.cs index ca81b5ae56..2f677704c3 100644 --- a/src/Kestrel.Core/Internal/Http/HttpRequestStream.cs +++ b/src/Kestrel.Core/Internal/Http/HttpRequestStream.cs @@ -6,7 +6,6 @@ using System.IO; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; -using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Protocols; diff --git a/src/Kestrel.Core/Internal/Http/IHttpParser.cs b/src/Kestrel.Core/Internal/Http/IHttpParser.cs index 62c2c131b3..e1978ffb01 100644 --- a/src/Kestrel.Core/Internal/Http/IHttpParser.cs +++ b/src/Kestrel.Core/Internal/Http/IHttpParser.cs @@ -3,8 +3,6 @@ using System.Buffers; using System.Collections; -using System.Collections.Sequences; -using System.IO.Pipelines; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { diff --git a/src/Kestrel.Core/Internal/Http/IHttpProtocolContext.cs b/src/Kestrel.Core/Internal/Http/IHttpProtocolContext.cs index 392dcf1833..c58d97196d 100644 --- a/src/Kestrel.Core/Internal/Http/IHttpProtocolContext.cs +++ b/src/Kestrel.Core/Internal/Http/IHttpProtocolContext.cs @@ -2,7 +2,6 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Buffers; -using System.IO.Pipelines; using System.Net; using Microsoft.AspNetCore.Http.Features; diff --git a/src/Kestrel.Core/Internal/Http/MessageBody.cs b/src/Kestrel.Core/Internal/Http/MessageBody.cs index 08054b35aa..5d05eacf43 100644 --- a/src/Kestrel.Core/Internal/Http/MessageBody.cs +++ b/src/Kestrel.Core/Internal/Http/MessageBody.cs @@ -3,7 +3,6 @@ using System; using System.IO; -using System.IO.Pipelines; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; diff --git a/src/Kestrel.Core/Internal/Http2/HPack/HPackEncoder.cs b/src/Kestrel.Core/Internal/Http2/HPack/HPackEncoder.cs index 25206fed5b..0c92961acf 100644 --- a/src/Kestrel.Core/Internal/Http2/HPack/HPackEncoder.cs +++ b/src/Kestrel.Core/Internal/Http2/HPack/HPackEncoder.cs @@ -2,10 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.Collections; using System.Collections.Generic; -using Microsoft.AspNetCore.Http; -using Microsoft.Extensions.Primitives; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2.HPack { diff --git a/src/Kestrel.Core/Internal/Http2/Http2Connection.cs b/src/Kestrel.Core/Internal/Http2/Http2Connection.cs index ca788861ed..2d8fcd9b95 100644 --- a/src/Kestrel.Core/Internal/Http2/Http2Connection.cs +++ b/src/Kestrel.Core/Internal/Http2/Http2Connection.cs @@ -4,12 +4,10 @@ using System; using System.Buffers; using System.Collections; -using System.Collections.Sequences; using System.Collections.Concurrent; using System.IO.Pipelines; using System.Text; using System.Threading.Tasks; -using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting.Server; using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Protocols; diff --git a/src/Kestrel.Core/Internal/Http2/Http2ErrorCode.cs b/src/Kestrel.Core/Internal/Http2/Http2ErrorCode.cs index 2f14f191ba..401350fb39 100644 --- a/src/Kestrel.Core/Internal/Http2/Http2ErrorCode.cs +++ b/src/Kestrel.Core/Internal/Http2/Http2ErrorCode.cs @@ -1,7 +1,6 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 { diff --git a/src/Kestrel.Core/Internal/Http2/Http2Frame.Continuation.cs b/src/Kestrel.Core/Internal/Http2/Http2Frame.Continuation.cs index e184ff64db..d599864b7b 100644 --- a/src/Kestrel.Core/Internal/Http2/Http2Frame.Continuation.cs +++ b/src/Kestrel.Core/Internal/Http2/Http2Frame.Continuation.cs @@ -1,7 +1,6 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 { diff --git a/src/Kestrel.Core/Internal/Http2/Http2Frame.Ping.cs b/src/Kestrel.Core/Internal/Http2/Http2Frame.Ping.cs index 932d717ac1..cbbdc88d41 100644 --- a/src/Kestrel.Core/Internal/Http2/Http2Frame.Ping.cs +++ b/src/Kestrel.Core/Internal/Http2/Http2Frame.Ping.cs @@ -1,7 +1,6 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 { diff --git a/src/Kestrel.Core/Internal/Http2/Http2Frame.cs b/src/Kestrel.Core/Internal/Http2/Http2Frame.cs index f983b632a3..e0dbf8bd09 100644 --- a/src/Kestrel.Core/Internal/Http2/Http2Frame.cs +++ b/src/Kestrel.Core/Internal/Http2/Http2Frame.cs @@ -2,7 +2,6 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using Microsoft.Extensions.Logging; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 { diff --git a/src/Kestrel.Core/Internal/Http2/Http2FrameReader.cs b/src/Kestrel.Core/Internal/Http2/Http2FrameReader.cs index 9673ad57d5..68bf0e07e2 100644 --- a/src/Kestrel.Core/Internal/Http2/Http2FrameReader.cs +++ b/src/Kestrel.Core/Internal/Http2/Http2FrameReader.cs @@ -3,8 +3,6 @@ using System.Buffers; using System.Collections; -using System.Collections.Sequences; -using System.IO.Pipelines; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 { diff --git a/src/Kestrel.Core/Internal/Http2/Http2PeerSettings.cs b/src/Kestrel.Core/Internal/Http2/Http2PeerSettings.cs index af94d593df..4bf4787435 100644 --- a/src/Kestrel.Core/Internal/Http2/Http2PeerSettings.cs +++ b/src/Kestrel.Core/Internal/Http2/Http2PeerSettings.cs @@ -1,7 +1,6 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System; using System.Collections; using System.Collections.Generic; diff --git a/src/Kestrel.Core/Internal/Http2/Http2StreamContext.cs b/src/Kestrel.Core/Internal/Http2/Http2StreamContext.cs index 247e1764a7..72ccd8d7c0 100644 --- a/src/Kestrel.Core/Internal/Http2/Http2StreamContext.cs +++ b/src/Kestrel.Core/Internal/Http2/Http2StreamContext.cs @@ -2,7 +2,6 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Buffers; -using System.IO.Pipelines; using System.Net; using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; diff --git a/src/Kestrel.Core/Internal/HttpsConnectionAdapter.cs b/src/Kestrel.Core/Internal/HttpsConnectionAdapter.cs index 5022462886..c71aedfedb 100644 --- a/src/Kestrel.Core/Internal/HttpsConnectionAdapter.cs +++ b/src/Kestrel.Core/Internal/HttpsConnectionAdapter.cs @@ -4,7 +4,6 @@ using System; using System.Collections.Generic; using System.IO; -using System.Linq; using System.Net.Security; using System.Security.Cryptography.X509Certificates; using System.Threading; diff --git a/src/Kestrel.Core/Internal/Infrastructure/HttpConnectionManagerShutdownExtensions.cs b/src/Kestrel.Core/Internal/Infrastructure/HttpConnectionManagerShutdownExtensions.cs index d8f6320ff9..40e41874c4 100644 --- a/src/Kestrel.Core/Internal/Infrastructure/HttpConnectionManagerShutdownExtensions.cs +++ b/src/Kestrel.Core/Internal/Infrastructure/HttpConnectionManagerShutdownExtensions.cs @@ -5,7 +5,6 @@ using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Protocols; -using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure { diff --git a/src/Kestrel.Core/Internal/Infrastructure/KestrelEventSource.cs b/src/Kestrel.Core/Internal/Infrastructure/KestrelEventSource.cs index 708dedaa89..ed70a3797a 100644 --- a/src/Kestrel.Core/Internal/Infrastructure/KestrelEventSource.cs +++ b/src/Kestrel.Core/Internal/Infrastructure/KestrelEventSource.cs @@ -2,12 +2,8 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Diagnostics.Tracing; -using System.Net; using System.Runtime.CompilerServices; -using Microsoft.AspNetCore.Http.Features; -using Microsoft.AspNetCore.Protocols; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; -using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure { diff --git a/src/Kestrel.Core/Internal/ServerAddressesFeature.cs b/src/Kestrel.Core/Internal/ServerAddressesFeature.cs index 76a9d960b5..f8bcd13cde 100644 --- a/src/Kestrel.Core/Internal/ServerAddressesFeature.cs +++ b/src/Kestrel.Core/Internal/ServerAddressesFeature.cs @@ -1,9 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System; using System.Collections.Generic; -using System.Text; using Microsoft.AspNetCore.Hosting.Server.Features; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal diff --git a/src/Kestrel.Core/Internal/ServiceContext.cs b/src/Kestrel.Core/Internal/ServiceContext.cs index 9bad6b576b..9ca494fa54 100644 --- a/src/Kestrel.Core/Internal/ServiceContext.cs +++ b/src/Kestrel.Core/Internal/ServiceContext.cs @@ -1,7 +1,6 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; diff --git a/src/Kestrel.Core/KestrelServer.cs b/src/Kestrel.Core/KestrelServer.cs index 8f1c62099e..fcf6aedca9 100644 --- a/src/Kestrel.Core/KestrelServer.cs +++ b/src/Kestrel.Core/KestrelServer.cs @@ -3,7 +3,6 @@ using System; using System.Collections.Generic; -using System.Diagnostics; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Hosting.Server; diff --git a/src/Kestrel.Core/ListenOptionsHttpsExtensions.cs b/src/Kestrel.Core/ListenOptionsHttpsExtensions.cs index 6a03648746..7cc267c5de 100644 --- a/src/Kestrel.Core/ListenOptionsHttpsExtensions.cs +++ b/src/Kestrel.Core/ListenOptionsHttpsExtensions.cs @@ -5,7 +5,6 @@ using System; using System.IO; using System.Security.Cryptography.X509Certificates; using Microsoft.AspNetCore.Server.Kestrel.Core; -using Microsoft.AspNetCore.Server.Kestrel.Core.Internal; using Microsoft.AspNetCore.Server.Kestrel.Https; using Microsoft.AspNetCore.Server.Kestrel.Https.Internal; using Microsoft.Extensions.DependencyInjection; diff --git a/src/Kestrel.Transport.Abstractions/Internal/IConnectionHandler.cs b/src/Kestrel.Transport.Abstractions/Internal/IConnectionHandler.cs index 41b5c57839..9ae3f89c3f 100644 --- a/src/Kestrel.Transport.Abstractions/Internal/IConnectionHandler.cs +++ b/src/Kestrel.Transport.Abstractions/Internal/IConnectionHandler.cs @@ -1,7 +1,6 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System.Threading.Tasks; using Microsoft.AspNetCore.Http.Features; namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal diff --git a/src/Kestrel.Transport.Abstractions/Internal/TransportConnection.Features.cs b/src/Kestrel.Transport.Abstractions/Internal/TransportConnection.Features.cs index 98308725e6..ad794fa879 100644 --- a/src/Kestrel.Transport.Abstractions/Internal/TransportConnection.Features.cs +++ b/src/Kestrel.Transport.Abstractions/Internal/TransportConnection.Features.cs @@ -4,7 +4,6 @@ using System.Collections; using System.Collections.Generic; using System.IO.Pipelines; using System.Net; -using System.Threading.Tasks; using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Protocols.Features; diff --git a/src/Kestrel.Transport.Abstractions/Internal/TransportConnection.cs b/src/Kestrel.Transport.Abstractions/Internal/TransportConnection.cs index bd5193738f..34cb670e48 100644 --- a/src/Kestrel.Transport.Abstractions/Internal/TransportConnection.cs +++ b/src/Kestrel.Transport.Abstractions/Internal/TransportConnection.cs @@ -1,5 +1,4 @@ -using System; -using System.Buffers; +using System.Buffers; using System.IO.Pipelines; using System.Net; using System.Threading; diff --git a/src/Kestrel.Transport.Libuv/Internal/LibuvConnection.cs b/src/Kestrel.Transport.Libuv/Internal/LibuvConnection.cs index a606d32f07..8471d89d61 100644 --- a/src/Kestrel.Transport.Libuv/Internal/LibuvConnection.cs +++ b/src/Kestrel.Transport.Libuv/Internal/LibuvConnection.cs @@ -3,7 +3,6 @@ using System; using System.Buffers; -using System.Diagnostics; using System.IO; using System.IO.Pipelines; using System.Threading; diff --git a/src/Kestrel.Transport.Libuv/Internal/LibuvConnectionContext.cs b/src/Kestrel.Transport.Libuv/Internal/LibuvConnectionContext.cs index 075a57752c..39f68be604 100644 --- a/src/Kestrel.Transport.Libuv/Internal/LibuvConnectionContext.cs +++ b/src/Kestrel.Transport.Libuv/Internal/LibuvConnectionContext.cs @@ -2,8 +2,6 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Buffers; -using System.Net; -using System.IO.Pipelines; using System.Threading; using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; diff --git a/src/Kestrel.Transport.Libuv/Internal/LibuvThread.cs b/src/Kestrel.Transport.Libuv/Internal/LibuvThread.cs index db3682fe32..87774d835a 100644 --- a/src/Kestrel.Transport.Libuv/Internal/LibuvThread.cs +++ b/src/Kestrel.Transport.Libuv/Internal/LibuvThread.cs @@ -5,7 +5,6 @@ using System; using System.Buffers; using System.Collections.Generic; using System.Diagnostics; -using System.IO.Pipelines; using System.Runtime.ExceptionServices; using System.Threading; using System.Threading.Tasks; diff --git a/src/Kestrel.Transport.Libuv/Internal/Networking/UvWriteReq.cs b/src/Kestrel.Transport.Libuv/Internal/Networking/UvWriteReq.cs index e720f2700c..27d78bae3d 100644 --- a/src/Kestrel.Transport.Libuv/Internal/Networking/UvWriteReq.cs +++ b/src/Kestrel.Transport.Libuv/Internal/Networking/UvWriteReq.cs @@ -5,7 +5,6 @@ using System; using System.Buffers; using System.Collections.Generic; using System.Runtime.InteropServices; -using System.IO.Pipelines; using Microsoft.Extensions.Logging; namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking diff --git a/src/Kestrel.Transport.Sockets/Internal/SocketConnection.cs b/src/Kestrel.Transport.Sockets/Internal/SocketConnection.cs index 2ab964e894..227101d1f9 100644 --- a/src/Kestrel.Transport.Sockets/Internal/SocketConnection.cs +++ b/src/Kestrel.Transport.Sockets/Internal/SocketConnection.cs @@ -3,10 +3,8 @@ using System; using System.Buffers; -using System.Collections.Generic; using System.Diagnostics; using System.IO; -using System.IO.Pipelines; using System.Net; using System.Net.Sockets; using System.Threading.Tasks; diff --git a/src/Kestrel.Transport.Sockets/Internal/SocketSender.cs b/src/Kestrel.Transport.Sockets/Internal/SocketSender.cs index be71f3f9df..ef88ce8731 100644 --- a/src/Kestrel.Transport.Sockets/Internal/SocketSender.cs +++ b/src/Kestrel.Transport.Sockets/Internal/SocketSender.cs @@ -5,7 +5,6 @@ using System; using System.Buffers; using System.Collections.Generic; using System.Diagnostics; -using System.IO.Pipelines; using System.Net.Sockets; using System.Runtime.InteropServices; diff --git a/src/Kestrel.Transport.Sockets/SocketTransport.cs b/src/Kestrel.Transport.Sockets/SocketTransport.cs index 6cec602c36..cd729a5eb1 100644 --- a/src/Kestrel.Transport.Sockets/SocketTransport.cs +++ b/src/Kestrel.Transport.Sockets/SocketTransport.cs @@ -4,7 +4,6 @@ using System; using System.Buffers; using System.Diagnostics; -using System.IO.Pipelines; using System.Net; using System.Net.Sockets; using System.Runtime.ExceptionServices; diff --git a/src/Kestrel.Transport.Sockets/SocketTransportOptions.cs b/src/Kestrel.Transport.Sockets/SocketTransportOptions.cs index be34d292d8..05bae64609 100644 --- a/src/Kestrel.Transport.Sockets/SocketTransportOptions.cs +++ b/src/Kestrel.Transport.Sockets/SocketTransportOptions.cs @@ -1,9 +1,6 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System; -using System.Collections.Generic; -using System.Text; namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets { diff --git a/src/Protocols.Abstractions/ConnectionDelegate.cs b/src/Protocols.Abstractions/ConnectionDelegate.cs index a0656c0496..ff0e4d75af 100644 --- a/src/Protocols.Abstractions/ConnectionDelegate.cs +++ b/src/Protocols.Abstractions/ConnectionDelegate.cs @@ -1,7 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Text; -using System.Threading.Tasks; +using System.Threading.Tasks; namespace Microsoft.AspNetCore.Protocols { diff --git a/src/Protocols.Abstractions/DefaultConnectionContext.cs b/src/Protocols.Abstractions/DefaultConnectionContext.cs index cc75702caf..d38657061c 100644 --- a/src/Protocols.Abstractions/DefaultConnectionContext.cs +++ b/src/Protocols.Abstractions/DefaultConnectionContext.cs @@ -1,5 +1,4 @@ -using System.Buffers; -using System.IO.Pipelines; +using System.IO.Pipelines; using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Protocols.Features; diff --git a/src/Protocols.Abstractions/DuplexPipe.cs b/src/Protocols.Abstractions/DuplexPipe.cs index a354af53e9..4e26d458ec 100644 --- a/src/Protocols.Abstractions/DuplexPipe.cs +++ b/src/Protocols.Abstractions/DuplexPipe.cs @@ -1,7 +1,4 @@ -using System; -using System.Buffers; -using System.Collections.Generic; -using System.Text; +using System.Buffers; namespace System.IO.Pipelines { diff --git a/src/Protocols.Abstractions/Features/IConnectionIdFeature.cs b/src/Protocols.Abstractions/Features/IConnectionIdFeature.cs index 1b94c5b4cc..ab1c09e3db 100644 --- a/src/Protocols.Abstractions/Features/IConnectionIdFeature.cs +++ b/src/Protocols.Abstractions/Features/IConnectionIdFeature.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace Microsoft.AspNetCore.Protocols.Features +namespace Microsoft.AspNetCore.Protocols.Features { public interface IConnectionIdFeature { diff --git a/src/Protocols.Abstractions/IConnectionBuilder.cs b/src/Protocols.Abstractions/IConnectionBuilder.cs index 7f75d27643..15a028c5db 100644 --- a/src/Protocols.Abstractions/IConnectionBuilder.cs +++ b/src/Protocols.Abstractions/IConnectionBuilder.cs @@ -1,6 +1,4 @@ using System; -using System.Collections.Generic; -using System.Text; namespace Microsoft.AspNetCore.Protocols { diff --git a/test/Kestrel.Core.Tests/AddressBinderTests.cs b/test/Kestrel.Core.Tests/AddressBinderTests.cs index d548fa70ba..9308c8c14b 100644 --- a/test/Kestrel.Core.Tests/AddressBinderTests.cs +++ b/test/Kestrel.Core.Tests/AddressBinderTests.cs @@ -10,7 +10,6 @@ using Microsoft.AspNetCore.Server.Kestrel.Core.Internal; using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; using Microsoft.AspNetCore.Testing; using Microsoft.Extensions.Logging.Abstractions; -using Moq; using Xunit; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests diff --git a/test/Kestrel.Core.Tests/HPackEncoderTests.cs b/test/Kestrel.Core.Tests/HPackEncoderTests.cs index de07eeec72..20313c6a90 100644 --- a/test/Kestrel.Core.Tests/HPackEncoderTests.cs +++ b/test/Kestrel.Core.Tests/HPackEncoderTests.cs @@ -3,7 +3,6 @@ using System; using System.Collections.Generic; -using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2.HPack; using Xunit; diff --git a/test/Kestrel.Core.Tests/Http1ConnectionTests.cs b/test/Kestrel.Core.Tests/Http1ConnectionTests.cs index 75c7f4f560..56711ed1b3 100644 --- a/test/Kestrel.Core.Tests/Http1ConnectionTests.cs +++ b/test/Kestrel.Core.Tests/Http1ConnectionTests.cs @@ -5,14 +5,12 @@ using System; using System.Buffers; using System.Collections; using System.Collections.Generic; -using System.Collections.Sequences; using System.IO; using System.IO.Pipelines; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; -using Microsoft.AspNetCore.Hosting.Server; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Server.Kestrel.Core.Features; diff --git a/test/Kestrel.Core.Tests/HttpParserTests.cs b/test/Kestrel.Core.Tests/HttpParserTests.cs index 48f3406533..e9c8e07500 100644 --- a/test/Kestrel.Core.Tests/HttpParserTests.cs +++ b/test/Kestrel.Core.Tests/HttpParserTests.cs @@ -3,7 +3,6 @@ using System; using System.Buffers; -using System.IO.Pipelines; using System.Collections.Generic; using System.Linq; using System.Text; diff --git a/test/Kestrel.Core.Tests/HttpRequestHeadersTests.cs b/test/Kestrel.Core.Tests/HttpRequestHeadersTests.cs index 5f1113e9c2..1eef7c792c 100644 --- a/test/Kestrel.Core.Tests/HttpRequestHeadersTests.cs +++ b/test/Kestrel.Core.Tests/HttpRequestHeadersTests.cs @@ -5,7 +5,6 @@ using System; using System.Collections.Generic; using System.Text; using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; using Microsoft.Extensions.Primitives; using Xunit; diff --git a/test/Kestrel.Core.Tests/IntegerDecoderTests.cs b/test/Kestrel.Core.Tests/IntegerDecoderTests.cs index c9e259b0ff..b89b0f84a3 100644 --- a/test/Kestrel.Core.Tests/IntegerDecoderTests.cs +++ b/test/Kestrel.Core.Tests/IntegerDecoderTests.cs @@ -1,7 +1,6 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2.HPack; using Xunit; diff --git a/test/Kestrel.Core.Tests/IntegerEncoderTests.cs b/test/Kestrel.Core.Tests/IntegerEncoderTests.cs index 2c4811c81c..c667cc6cee 100644 --- a/test/Kestrel.Core.Tests/IntegerEncoderTests.cs +++ b/test/Kestrel.Core.Tests/IntegerEncoderTests.cs @@ -1,7 +1,6 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2.HPack; using Xunit; diff --git a/test/Kestrel.Core.Tests/KestrelEventSourceTests.cs b/test/Kestrel.Core.Tests/KestrelEventSourceTests.cs index 4f1944387b..7f407c92fb 100644 --- a/test/Kestrel.Core.Tests/KestrelEventSourceTests.cs +++ b/test/Kestrel.Core.Tests/KestrelEventSourceTests.cs @@ -4,7 +4,6 @@ using System; using System.Diagnostics.Tracing; using System.Reflection; -using Microsoft.AspNetCore.Server.Kestrel.Core; using Xunit; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests diff --git a/test/Kestrel.Core.Tests/PipeOptionsTests.cs b/test/Kestrel.Core.Tests/PipeOptionsTests.cs index 519c266d5b..ff3ab4ce27 100644 --- a/test/Kestrel.Core.Tests/PipeOptionsTests.cs +++ b/test/Kestrel.Core.Tests/PipeOptionsTests.cs @@ -2,10 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Buffers; -using System.Collections.Generic; -using System.IO.Pipelines; using System.Threading; -using Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; using Microsoft.AspNetCore.Testing; diff --git a/test/Kestrel.Core.Tests/ServerAddressTests.cs b/test/Kestrel.Core.Tests/ServerAddressTests.cs index 9c9c7a654b..94dc2ee3ab 100644 --- a/test/Kestrel.Core.Tests/ServerAddressTests.cs +++ b/test/Kestrel.Core.Tests/ServerAddressTests.cs @@ -2,7 +2,6 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using Microsoft.AspNetCore.Server.Kestrel.Core; using Xunit; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests diff --git a/test/Kestrel.FunctionalTests/AddressRegistrationTests.cs b/test/Kestrel.FunctionalTests/AddressRegistrationTests.cs index 9e83cde243..6e66f401bc 100644 --- a/test/Kestrel.FunctionalTests/AddressRegistrationTests.cs +++ b/test/Kestrel.FunctionalTests/AddressRegistrationTests.cs @@ -18,7 +18,6 @@ using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http.Extensions; using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; -using Microsoft.AspNetCore.Server.Kestrel.Https; using Microsoft.AspNetCore.Testing; using Microsoft.AspNetCore.Testing.xunit; using Microsoft.Extensions.Logging; diff --git a/test/Kestrel.FunctionalTests/BadHttpRequestTests.cs b/test/Kestrel.FunctionalTests/BadHttpRequestTests.cs index be64faeaf4..29b8164fc2 100644 --- a/test/Kestrel.FunctionalTests/BadHttpRequestTests.cs +++ b/test/Kestrel.FunctionalTests/BadHttpRequestTests.cs @@ -1,7 +1,6 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; diff --git a/test/Kestrel.FunctionalTests/HttpsTests.cs b/test/Kestrel.FunctionalTests/HttpsTests.cs index 24959f9c7f..152823f6a9 100644 --- a/test/Kestrel.FunctionalTests/HttpsTests.cs +++ b/test/Kestrel.FunctionalTests/HttpsTests.cs @@ -14,10 +14,8 @@ using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Server.Kestrel.Core; -using Microsoft.AspNetCore.Server.Kestrel.Core.Internal; using Microsoft.AspNetCore.Server.Kestrel.Https; using Microsoft.AspNetCore.Server.Kestrel.Https.Internal; -using Microsoft.AspNetCore.Server.Kestrel.Internal; using Microsoft.AspNetCore.Testing; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; diff --git a/test/Kestrel.FunctionalTests/KeepAliveTimeoutTests.cs b/test/Kestrel.FunctionalTests/KeepAliveTimeoutTests.cs index 5090147065..5d4a3c553f 100644 --- a/test/Kestrel.FunctionalTests/KeepAliveTimeoutTests.cs +++ b/test/Kestrel.FunctionalTests/KeepAliveTimeoutTests.cs @@ -2,7 +2,6 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.Diagnostics; using System.Text; using System.Threading; using System.Threading.Tasks; diff --git a/test/Kestrel.FunctionalTests/RequestTests.cs b/test/Kestrel.FunctionalTests/RequestTests.cs index 504a93104d..ff063b35bf 100644 --- a/test/Kestrel.FunctionalTests/RequestTests.cs +++ b/test/Kestrel.FunctionalTests/RequestTests.cs @@ -22,7 +22,6 @@ using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.AspNetCore.Server.Kestrel.Core.Features; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; -using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; using Microsoft.AspNetCore.Testing; using Microsoft.AspNetCore.Testing.xunit; using Microsoft.Extensions.Logging; diff --git a/test/Kestrel.FunctionalTests/TestHelpers/NetworkIsReachableAttribute.cs b/test/Kestrel.FunctionalTests/TestHelpers/NetworkIsReachableAttribute.cs index a17a321cba..9b62c0689b 100644 --- a/test/Kestrel.FunctionalTests/TestHelpers/NetworkIsReachableAttribute.cs +++ b/test/Kestrel.FunctionalTests/TestHelpers/NetworkIsReachableAttribute.cs @@ -2,7 +2,6 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.Linq; using System.Net; using System.Net.Sockets; using Microsoft.AspNetCore.Testing; diff --git a/test/Kestrel.Transport.Libuv.Tests/MultipleLoopTests.cs b/test/Kestrel.Transport.Libuv.Tests/MultipleLoopTests.cs index e5972077c9..b4dd9c64ae 100644 --- a/test/Kestrel.Transport.Libuv.Tests/MultipleLoopTests.cs +++ b/test/Kestrel.Transport.Libuv.Tests/MultipleLoopTests.cs @@ -3,14 +3,12 @@ using System; using System.Buffers; -using System.IO.Pipelines; using System.Net; using System.Net.Sockets; using System.Runtime.InteropServices; using System.Threading; using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal; using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking; -using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests.TestHelpers; using Microsoft.AspNetCore.Testing; using Xunit; diff --git a/test/Kestrel.Transport.Libuv.Tests/NetworkingTests.cs b/test/Kestrel.Transport.Libuv.Tests/NetworkingTests.cs index bf25af4392..24a1bf36a7 100644 --- a/test/Kestrel.Transport.Libuv.Tests/NetworkingTests.cs +++ b/test/Kestrel.Transport.Libuv.Tests/NetworkingTests.cs @@ -9,7 +9,6 @@ using System.Runtime.InteropServices; using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal; using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking; -using System.IO.Pipelines; using Microsoft.AspNetCore.Testing; using Xunit; diff --git a/test/Kestrel.Transport.Libuv.Tests/TestHelpers/TestLibuvTransportContext.cs b/test/Kestrel.Transport.Libuv.Tests/TestHelpers/TestLibuvTransportContext.cs index 9f608c64b9..d764eaf940 100644 --- a/test/Kestrel.Transport.Libuv.Tests/TestHelpers/TestLibuvTransportContext.cs +++ b/test/Kestrel.Transport.Libuv.Tests/TestHelpers/TestLibuvTransportContext.cs @@ -1,7 +1,6 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System; using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal; using Microsoft.AspNetCore.Testing; diff --git a/test/shared/PassThroughConnectionAdapter.cs b/test/shared/PassThroughConnectionAdapter.cs index c018e49ad7..5f10736595 100644 --- a/test/shared/PassThroughConnectionAdapter.cs +++ b/test/shared/PassThroughConnectionAdapter.cs @@ -3,7 +3,6 @@ using System.IO; using System.Threading.Tasks; -using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal; namespace Microsoft.AspNetCore.Testing diff --git a/test/shared/TestServiceContext.cs b/test/shared/TestServiceContext.cs index 1109cf5f05..9739022477 100644 --- a/test/shared/TestServiceContext.cs +++ b/test/shared/TestServiceContext.cs @@ -1,7 +1,6 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System; using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; diff --git a/tools/CodeGenerator/HttpProtocolFeatureCollection.cs b/tools/CodeGenerator/HttpProtocolFeatureCollection.cs index b960180f26..3865658e70 100644 --- a/tools/CodeGenerator/HttpProtocolFeatureCollection.cs +++ b/tools/CodeGenerator/HttpProtocolFeatureCollection.cs @@ -4,9 +4,6 @@ using System; using System.Collections.Generic; using System.Linq; -using Microsoft.AspNetCore.Http.Features; -using Microsoft.AspNetCore.Http.Features.Authentication; -//using Microsoft.AspNetCore.Server.Kestrel.Core.Features; namespace CodeGenerator { From 07026cf6db2bb142bea7fe4f3091d260f3d90de0 Mon Sep 17 00:00:00 2001 From: Mike Harder Date: Fri, 16 Feb 2018 17:11:27 -0800 Subject: [PATCH 1527/1662] Re-enable test ParseRequestLineSplitBufferWithoutNewLineDoesNotUpdateConsumed (#2328) - Addresses #2243 --- test/Kestrel.Core.Tests/HttpParserTests.cs | 95 ++++++++++++++++++++++ 1 file changed, 95 insertions(+) diff --git a/test/Kestrel.Core.Tests/HttpParserTests.cs b/test/Kestrel.Core.Tests/HttpParserTests.cs index e9c8e07500..b436c16211 100644 --- a/test/Kestrel.Core.Tests/HttpParserTests.cs +++ b/test/Kestrel.Core.Tests/HttpParserTests.cs @@ -368,6 +368,20 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests Assert.Equal(StatusCodes.Status400BadRequest, exception.StatusCode); } + [Fact] + public void ParseRequestLineSplitBufferWithoutNewLineDoesNotUpdateConsumed() + { + var parser = CreateParser(Mock.Of()); + var buffer = CreateBuffer("GET ", "/"); + + var requestHandler = new RequestHandler(); + var result = parser.ParseRequestLine(requestHandler, buffer, out var consumed, out var examined); + + Assert.False(result); + Assert.Equal(buffer.Start, consumed); + Assert.Equal(buffer.End, examined); + } + private void VerifyHeader( string headerName, string rawHeaderValue, @@ -451,5 +465,86 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests PathEncoded = pathEncoded; } } + + private static ReadOnlyBuffer CreateBuffer(params string[] inputs) + { + var buffers = new byte[inputs.Length][]; + for (int i = 0; i < inputs.Length; i++) + { + buffers[i] = Encoding.UTF8.GetBytes(inputs[i]); + } + return CreateBuffer(buffers); + } + + // Copied from https://github.com/dotnet/corefx/blob/master/src/System.Memory/tests/ReadOnlyBuffer/ReadOnlySequenceFactory.cs + private static ReadOnlyBuffer CreateBuffer(params byte[][] inputs) + { + if (inputs == null || inputs.Length == 0) + { + throw new InvalidOperationException(); + } + + int i = 0; + + BufferSegment last = null; + BufferSegment first = null; + + do + { + byte[] s = inputs[i]; + int length = s.Length; + int dataOffset = length; + var chars = new byte[length * 2]; + + for (int j = 0; j < length; j++) + { + chars[dataOffset + j] = s[j]; + } + + // Create a segment that has offset relative to the OwnedMemory and OwnedMemory itself has offset relative to array + var memory = new Memory(chars).Slice(length, length); + + if (first == null) + { + first = new BufferSegment(memory); + last = first; + } + else + { + last = last.Append(memory); + } + i++; + } while (i < inputs.Length); + + return new ReadOnlyBuffer(first, 0, last, last.Memory.Length); + } + + // Copied from https://github.com/dotnet/corefx/blob/master/src/System.Memory/tests/ReadOnlyBuffer/BufferSegment.cs + private class BufferSegment : IMemoryList + { + public BufferSegment(Memory memory) + { + Memory = memory; + } + + /// + /// Combined length of all segments before this + /// + public long RunningIndex { get; private set; } + + public Memory Memory { get; set; } + + public IMemoryList Next { get; private set; } + + public BufferSegment Append(Memory memory) + { + var segment = new BufferSegment(memory) + { + RunningIndex = RunningIndex + Memory.Length + }; + Next = segment; + return segment; + } + } } } From 1f8591184e63467dc56b7252d3a340be8fee42b2 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Sat, 17 Feb 2018 16:13:15 +0000 Subject: [PATCH 1528/1662] Use ReferenceEquals not MulticastDelegate.equals (#2330) It never inlines because its such a chunky method --- src/Kestrel.Transport.Libuv/Internal/LibuvAwaitable.cs | 6 +++--- src/Kestrel.Transport.Sockets/Internal/SocketAwaitable.cs | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Kestrel.Transport.Libuv/Internal/LibuvAwaitable.cs b/src/Kestrel.Transport.Libuv/Internal/LibuvAwaitable.cs index 49ca4f8e6b..b4d40dea29 100644 --- a/src/Kestrel.Transport.Libuv/Internal/LibuvAwaitable.cs +++ b/src/Kestrel.Transport.Libuv/Internal/LibuvAwaitable.cs @@ -32,7 +32,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal }; public LibuvAwaitable GetAwaiter() => this; - public bool IsCompleted => _callback == _callbackCompleted; + public bool IsCompleted => ReferenceEquals(_callback, _callbackCompleted); public UvWriteResult GetResult() { @@ -54,8 +54,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal // There should never be a race between IsCompleted and OnCompleted since both operations // should always be on the libuv thread - if (_callback == _callbackCompleted || - Interlocked.CompareExchange(ref _callback, continuation, null) == _callbackCompleted) + if (ReferenceEquals(_callback, _callbackCompleted) || + ReferenceEquals(Interlocked.CompareExchange(ref _callback, continuation, null), _callbackCompleted)) { Debug.Fail($"{typeof(LibuvAwaitable)}.{nameof(OnCompleted)} raced with {nameof(IsCompleted)}, running callback inline."); diff --git a/src/Kestrel.Transport.Sockets/Internal/SocketAwaitable.cs b/src/Kestrel.Transport.Sockets/Internal/SocketAwaitable.cs index fc68b3c08f..0ed4ac89bc 100644 --- a/src/Kestrel.Transport.Sockets/Internal/SocketAwaitable.cs +++ b/src/Kestrel.Transport.Sockets/Internal/SocketAwaitable.cs @@ -18,11 +18,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal private SocketError _error; public SocketAwaitable GetAwaiter() => this; - public bool IsCompleted => _callback == _callbackCompleted; + public bool IsCompleted => ReferenceEquals(_callback, _callbackCompleted); public int GetResult() { - Debug.Assert(_callback == _callbackCompleted); + Debug.Assert(ReferenceEquals(_callback, _callbackCompleted)); _callback = null; @@ -36,8 +36,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal public void OnCompleted(Action continuation) { - if (_callback == _callbackCompleted || - Interlocked.CompareExchange(ref _callback, continuation, null) == _callbackCompleted) + if (ReferenceEquals(_callback, _callbackCompleted) || + ReferenceEquals(Interlocked.CompareExchange(ref _callback, continuation, null), _callbackCompleted)) { continuation(); } From 38a4560e1c9a4c1eb1583ff0bf36b8a2cde284aa Mon Sep 17 00:00:00 2001 From: David Fowler Date: Sat, 17 Feb 2018 09:39:59 -0800 Subject: [PATCH 1529/1662] Remove check for above debug logs --- test/Kestrel.FunctionalTests/RequestTests.cs | 24 -------------------- 1 file changed, 24 deletions(-) diff --git a/test/Kestrel.FunctionalTests/RequestTests.cs b/test/Kestrel.FunctionalTests/RequestTests.cs index ff063b35bf..bef16a7333 100644 --- a/test/Kestrel.FunctionalTests/RequestTests.cs +++ b/test/Kestrel.FunctionalTests/RequestTests.cs @@ -269,7 +269,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { var connectionStarted = new SemaphoreSlim(0); var connectionReset = new SemaphoreSlim(0); - var loggedHigherThanDebug = false; var mockLogger = new Mock(); mockLogger @@ -287,11 +286,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { connectionReset.Release(); } - - if (logLevel > LogLevel.Debug) - { - loggedHigherThanDebug = true; - } }); var mockLoggerFactory = new Mock(); @@ -321,15 +315,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests // and therefore not logged. Assert.True(await connectionReset.WaitAsync(TestConstants.DefaultTimeout)); } - - Assert.False(loggedHigherThanDebug); } [Fact] public async Task ConnectionResetBetweenRequestsIsLoggedAsDebug() { var connectionReset = new SemaphoreSlim(0); - var loggedHigherThanDebug = false; var mockLogger = new Mock(); mockLogger @@ -343,11 +334,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { connectionReset.Release(); } - - if (logLevel > LogLevel.Debug) - { - loggedHigherThanDebug = true; - } }); var mockLoggerFactory = new Mock(); @@ -389,8 +375,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests // and therefore not logged. Assert.True(await connectionReset.WaitAsync(TestConstants.DefaultTimeout)); } - - Assert.False(loggedHigherThanDebug); } [Fact] @@ -399,7 +383,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests var requestStarted = new SemaphoreSlim(0); var connectionReset = new SemaphoreSlim(0); var connectionClosing = new SemaphoreSlim(0); - var loggedHigherThanDebug = false; var mockLogger = new Mock(); mockLogger @@ -415,11 +398,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { connectionReset.Release(); } - - if (logLevel > LogLevel.Debug) - { - loggedHigherThanDebug = true; - } }); var mockLoggerFactory = new Mock(); @@ -457,8 +435,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests Assert.True(await connectionReset.WaitAsync(TestConstants.DefaultTimeout), "Connection reset event should have been logged"); connectionClosing.Release(); } - - Assert.False(loggedHigherThanDebug, "Logged event should not have been higher than debug."); } [Fact] From da6325251e5f6a034c505cae6fb2eae964d0d0c4 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Sat, 17 Feb 2018 09:40:42 -0800 Subject: [PATCH 1530/1662] Revert "Remove check for above debug logs" This reverts commit 38a4560e1c9a4c1eb1583ff0bf36b8a2cde284aa. --- test/Kestrel.FunctionalTests/RequestTests.cs | 24 ++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/test/Kestrel.FunctionalTests/RequestTests.cs b/test/Kestrel.FunctionalTests/RequestTests.cs index bef16a7333..ff063b35bf 100644 --- a/test/Kestrel.FunctionalTests/RequestTests.cs +++ b/test/Kestrel.FunctionalTests/RequestTests.cs @@ -269,6 +269,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { var connectionStarted = new SemaphoreSlim(0); var connectionReset = new SemaphoreSlim(0); + var loggedHigherThanDebug = false; var mockLogger = new Mock(); mockLogger @@ -286,6 +287,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { connectionReset.Release(); } + + if (logLevel > LogLevel.Debug) + { + loggedHigherThanDebug = true; + } }); var mockLoggerFactory = new Mock(); @@ -315,12 +321,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests // and therefore not logged. Assert.True(await connectionReset.WaitAsync(TestConstants.DefaultTimeout)); } + + Assert.False(loggedHigherThanDebug); } [Fact] public async Task ConnectionResetBetweenRequestsIsLoggedAsDebug() { var connectionReset = new SemaphoreSlim(0); + var loggedHigherThanDebug = false; var mockLogger = new Mock(); mockLogger @@ -334,6 +343,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { connectionReset.Release(); } + + if (logLevel > LogLevel.Debug) + { + loggedHigherThanDebug = true; + } }); var mockLoggerFactory = new Mock(); @@ -375,6 +389,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests // and therefore not logged. Assert.True(await connectionReset.WaitAsync(TestConstants.DefaultTimeout)); } + + Assert.False(loggedHigherThanDebug); } [Fact] @@ -383,6 +399,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests var requestStarted = new SemaphoreSlim(0); var connectionReset = new SemaphoreSlim(0); var connectionClosing = new SemaphoreSlim(0); + var loggedHigherThanDebug = false; var mockLogger = new Mock(); mockLogger @@ -398,6 +415,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { connectionReset.Release(); } + + if (logLevel > LogLevel.Debug) + { + loggedHigherThanDebug = true; + } }); var mockLoggerFactory = new Mock(); @@ -435,6 +457,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests Assert.True(await connectionReset.WaitAsync(TestConstants.DefaultTimeout), "Connection reset event should have been logged"); connectionClosing.Release(); } + + Assert.False(loggedHigherThanDebug, "Logged event should not have been higher than debug."); } [Fact] From 47109ebcce20d196e6c223341ed39c15b3594391 Mon Sep 17 00:00:00 2001 From: "ASP.NET CI" Date: Sun, 18 Feb 2018 12:22:55 -0800 Subject: [PATCH 1531/1662] Update dependencies.props [auto-updated: dependencies] --- build/dependencies.props | 38 +++++++++++++++++++------------------- korebuild-lock.txt | 4 ++-- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/build/dependencies.props b/build/dependencies.props index 8952a0dd69..302297c7ec 100644 --- a/build/dependencies.props +++ b/build/dependencies.props @@ -5,28 +5,28 @@ 0.10.11 - 2.1.0-preview2-15698 + 2.1.0-preview2-15707 1.10.0 - 2.1.0-preview2-30077 - 2.1.0-preview2-30077 - 2.1.0-preview2-30077 - 2.1.0-preview2-30077 - 2.1.0-preview2-30077 - 2.1.0-preview2-30077 - 2.1.0-preview2-30077 - 2.1.0-preview2-30077 - 2.1.0-preview2-30077 - 2.1.0-preview2-30077 - 2.1.0-preview2-30077 - 2.1.0-preview2-30077 - 2.1.0-preview2-30077 - 2.1.0-preview2-30077 - 2.1.0-preview2-30077 - 2.1.0-preview2-30077 - 2.1.0-preview2-30077 + 2.1.0-preview2-30131 + 2.1.0-preview2-30131 + 2.1.0-preview2-30131 + 2.1.0-preview2-30131 + 2.1.0-preview2-30131 + 2.1.0-preview2-30131 + 2.1.0-preview2-30131 + 2.1.0-preview2-30131 + 2.1.0-preview2-30131 + 2.1.0-preview2-30131 + 2.1.0-preview2-30131 + 2.1.0-preview2-30131 + 2.1.0-preview2-30131 + 2.1.0-preview2-30131 + 2.1.0-preview2-30131 + 2.1.0-preview2-30131 + 2.1.0-preview2-30131 2.0.0 2.1.0-preview2-26130-04 - 2.1.0-preview2-30077 + 2.1.0-preview2-30131 15.3.0 4.7.49 10.0.1 diff --git a/korebuild-lock.txt b/korebuild-lock.txt index 3e2b56b91b..89d0ad3d15 100644 --- a/korebuild-lock.txt +++ b/korebuild-lock.txt @@ -1,2 +1,2 @@ -version:2.1.0-preview2-15698 -commithash:7216e5068cb1957e09d45fcbe58a744dd5c2de73 +version:2.1.0-preview2-15707 +commithash:e74e53f129ab34332947fea7ac7b7591b027cb22 From a72e5db79791030284fd4cb93e403bb55b21d815 Mon Sep 17 00:00:00 2001 From: brightcr Date: Mon, 19 Feb 2018 22:06:28 +0530 Subject: [PATCH 1532/1662] Removed code to set response headers - connection and upgrade as it should be set by caller e.g. WebSockets Middleware (#2329) --- .../Internal/Http/Http1Connection.FeatureCollection.cs | 9 --------- 1 file changed, 9 deletions(-) diff --git a/src/Kestrel.Core/Internal/Http/Http1Connection.FeatureCollection.cs b/src/Kestrel.Core/Internal/Http/Http1Connection.FeatureCollection.cs index bcb7e60ebb..9264a75df7 100644 --- a/src/Kestrel.Core/Internal/Http/Http1Connection.FeatureCollection.cs +++ b/src/Kestrel.Core/Internal/Http/Http1Connection.FeatureCollection.cs @@ -8,7 +8,6 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Server.Kestrel.Core.Features; -using Microsoft.Extensions.Primitives; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { @@ -40,14 +39,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http StatusCode = StatusCodes.Status101SwitchingProtocols; ReasonPhrase = "Switching Protocols"; ResponseHeaders["Connection"] = "Upgrade"; - if (!ResponseHeaders.ContainsKey("Upgrade")) - { - StringValues values; - if (RequestHeaders.TryGetValue("Upgrade", out values)) - { - ResponseHeaders["Upgrade"] = values; - } - } await FlushAsync(default(CancellationToken)); From 3fc69dc71f309fe59be48e0d5cf8592c10bfd120 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Wed, 21 Feb 2018 00:00:46 -0800 Subject: [PATCH 1533/1662] Updated Streams to override Memory and Span overloads (#2333) - Also plumbed Memory/Span through Kestrel over ArraySegment. - Throw synchronously from the HttpRequestStream instead of async in some cases. --- .../Adapter/Internal/AdaptedPipeline.cs | 14 +++++- .../Adapter/Internal/LoggingStream.cs | 50 ++++++++++++++++--- .../Adapter/Internal/RawStream.cs | 29 ++++++++--- .../Internal/Http/Http1OutputProducer.cs | 18 +++---- .../Internal/Http/HttpProtocol.cs | 28 +++++------ .../Internal/Http/HttpRequestStream.cs | 47 +++++++++-------- .../Internal/Http/HttpResponseStream.cs | 34 +++++++------ .../Internal/Http/IHttpOutputProducer.cs | 5 +- .../Internal/Http/IHttpResponseControl.cs | 2 +- src/Kestrel.Core/Internal/Http/MessageBody.cs | 15 ++++-- src/Kestrel.Core/Internal/Http2/Http2Frame.cs | 2 +- .../Internal/Http2/Http2FrameWriter.cs | 19 ++++--- .../Internal/Http2/Http2OutputProducer.cs | 2 +- .../Internal/Http2/IHttp2FrameWriter.cs | 6 +-- .../Http2ConnectionTests.cs | 7 ++- .../HttpRequestStreamTests.cs | 26 ++++------ .../HttpResponseStreamTests.cs | 2 +- test/Kestrel.Core.Tests/MessageBodyTests.cs | 4 +- .../TestHelpers/MockHttpResponseControl.cs | 2 +- 19 files changed, 199 insertions(+), 113 deletions(-) diff --git a/src/Kestrel.Core/Adapter/Internal/AdaptedPipeline.cs b/src/Kestrel.Core/Adapter/Internal/AdaptedPipeline.cs index fd8c35f037..4204469241 100644 --- a/src/Kestrel.Core/Adapter/Internal/AdaptedPipeline.cs +++ b/src/Kestrel.Core/Adapter/Internal/AdaptedPipeline.cs @@ -79,15 +79,23 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal } else if (buffer.IsSingleSegment) { +#if NETCOREAPP2_1 + await stream.WriteAsync(buffer.First); +#else var array = buffer.First.GetArray(); await stream.WriteAsync(array.Array, array.Offset, array.Count); +#endif } else { foreach (var memory in buffer) { +#if NETCOREAPP2_1 + await stream.WriteAsync(memory); +#else var array = memory.GetArray(); await stream.WriteAsync(array.Array, array.Offset, array.Count); +#endif } } } @@ -125,10 +133,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal var outputBuffer = Input.Writer.GetMemory(MinAllocBufferSize); - var array = outputBuffer.GetArray(); try { +#if NETCOREAPP2_1 + var bytesRead = await stream.ReadAsync(outputBuffer); +#else + var array = outputBuffer.GetArray(); var bytesRead = await stream.ReadAsync(array.Array, array.Offset, array.Count); +#endif Input.Writer.Advance(bytesRead); if (bytesRead == 0) diff --git a/src/Kestrel.Core/Adapter/Internal/LoggingStream.cs b/src/Kestrel.Core/Adapter/Internal/LoggingStream.cs index 584bf6301d..62f62a5d4c 100644 --- a/src/Kestrel.Core/Adapter/Internal/LoggingStream.cs +++ b/src/Kestrel.Core/Adapter/Internal/LoggingStream.cs @@ -79,17 +79,35 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal public override int Read(byte[] buffer, int offset, int count) { int read = _inner.Read(buffer, offset, count); - Log("Read", read, buffer, offset); + Log("Read", new ReadOnlySpan(buffer, offset, read)); return read; } +#if NETCOREAPP2_1 + public override int Read(Span destination) + { + int read = _inner.Read(destination); + Log("Read", destination.Slice(0, read)); + return read; + } +#endif + public async override Task ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) { int read = await _inner.ReadAsync(buffer, offset, count, cancellationToken); - Log("ReadAsync", read, buffer, offset); + Log("ReadAsync", new ReadOnlySpan(buffer, offset, read)); return read; } +#if NETCOREAPP2_1 + public override async ValueTask ReadAsync(Memory destination, CancellationToken cancellationToken = default) + { + int read = await _inner.ReadAsync(destination, cancellationToken); + Log("ReadAsync", destination.Span.Slice(0, read)); + return read; + } +#endif + public override long Seek(long offset, SeekOrigin origin) { return _inner.Seek(offset, origin); @@ -102,29 +120,45 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal public override void Write(byte[] buffer, int offset, int count) { - Log("Write", count, buffer, offset); + Log("Write", new ReadOnlySpan(buffer, offset, count)); _inner.Write(buffer, offset, count); } +#if NETCOREAPP2_1 + public override void Write(ReadOnlySpan source) + { + Log("Write", source); + _inner.Write(source); + } +#endif + public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) { - Log("WriteAsync", count, buffer, offset); + Log("WriteAsync", new ReadOnlySpan(buffer, offset, count)); return _inner.WriteAsync(buffer, offset, count, cancellationToken); } - private void Log(string method, int count, byte[] buffer, int offset) +#if NETCOREAPP2_1 + public override Task WriteAsync(ReadOnlyMemory source, CancellationToken cancellationToken = default) { - var builder = new StringBuilder($"{method}[{count}] "); + Log("WriteAsync", source.Span); + return _inner.WriteAsync(source, cancellationToken); + } +#endif + + private void Log(string method, ReadOnlySpan buffer) + { + var builder = new StringBuilder($"{method}[{buffer.Length}] "); // Write the hex - for (int i = offset; i < offset + count; i++) + for (int i = 0; i < buffer.Length; i++) { builder.Append(buffer[i].ToString("X2")); builder.Append(" "); } builder.AppendLine(); // Write the bytes as if they were ASCII - for (int i = offset; i < offset + count; i++) + for (int i = 0; i < buffer.Length; i++) { builder.Append((char)buffer[i]); } diff --git a/src/Kestrel.Core/Adapter/Internal/RawStream.cs b/src/Kestrel.Core/Adapter/Internal/RawStream.cs index 87a0932c32..32fb757db2 100644 --- a/src/Kestrel.Core/Adapter/Internal/RawStream.cs +++ b/src/Kestrel.Core/Adapter/Internal/RawStream.cs @@ -61,29 +61,44 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal { // ValueTask uses .GetAwaiter().GetResult() if necessary // https://github.com/dotnet/corefx/blob/f9da3b4af08214764a51b2331f3595ffaf162abe/src/System.Threading.Tasks.Extensions/src/System/Threading/Tasks/ValueTask.cs#L156 - return ReadAsync(new ArraySegment(buffer, offset, count)).Result; + return ReadAsyncInternal(new Memory(buffer, offset, count)).Result; } public override Task ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) { - return ReadAsync(new ArraySegment(buffer, offset, count)); + return ReadAsyncInternal(new Memory(buffer, offset, count)).AsTask(); } +#if NETCOREAPP2_1 + public override ValueTask ReadAsync(Memory destination, CancellationToken cancellationToken = default) + { + return ReadAsyncInternal(destination); + } +#endif + public override void Write(byte[] buffer, int offset, int count) { WriteAsync(buffer, offset, count).GetAwaiter().GetResult(); } - public override async Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken token) + public override async Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) { if (buffer != null) { _output.Write(new ReadOnlySpan(buffer, offset, count)); } - await _output.FlushAsync(token); + await _output.FlushAsync(cancellationToken); } +#if NETCOREAPP2_1 + public override async Task WriteAsync(ReadOnlyMemory source, CancellationToken cancellationToken = default) + { + _output.Write(source.Span); + await _output.FlushAsync(cancellationToken); + } +#endif + public override void Flush() { FlushAsync(CancellationToken.None).GetAwaiter().GetResult(); @@ -94,7 +109,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal return WriteAsync(null, 0, 0, cancellationToken); } - private async Task ReadAsync(ArraySegment buffer) + private async ValueTask ReadAsyncInternal(Memory destination) { while (true) { @@ -105,9 +120,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal if (!readableBuffer.IsEmpty) { // buffer.Count is int - var count = (int) Math.Min(readableBuffer.Length, buffer.Count); + var count = (int) Math.Min(readableBuffer.Length, destination.Length); readableBuffer = readableBuffer.Slice(0, count); - readableBuffer.CopyTo(buffer); + readableBuffer.CopyTo(destination.Span); return count; } else if (result.IsCompleted) diff --git a/src/Kestrel.Core/Internal/Http/Http1OutputProducer.cs b/src/Kestrel.Core/Internal/Http/Http1OutputProducer.cs index f220e7c70f..dbc8cf0f52 100644 --- a/src/Kestrel.Core/Internal/Http/Http1OutputProducer.cs +++ b/src/Kestrel.Core/Internal/Http/Http1OutputProducer.cs @@ -14,10 +14,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { public class Http1OutputProducer : IHttpOutputProducer { - private static readonly ArraySegment _continueBytes = new ArraySegment(Encoding.ASCII.GetBytes("HTTP/1.1 100 Continue\r\n\r\n")); + private static readonly ReadOnlyMemory _continueBytes = new ReadOnlyMemory(Encoding.ASCII.GetBytes("HTTP/1.1 100 Continue\r\n\r\n")); private static readonly byte[] _bytesHttpVersion11 = Encoding.ASCII.GetBytes("HTTP/1.1 "); private static readonly byte[] _bytesEndHeaders = Encoding.ASCII.GetBytes("\r\n\r\n"); - private static readonly ArraySegment _endChunkedResponseBytes = new ArraySegment(Encoding.ASCII.GetBytes("0\r\n\r\n")); + private static readonly ReadOnlyMemory _endChunkedResponseBytes = new ReadOnlyMemory(Encoding.ASCII.GetBytes("0\r\n\r\n")); private readonly string _connectionId; private readonly ITimeoutControl _timeoutControl; @@ -53,7 +53,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http _flushCompleted = OnFlushCompleted; } - public Task WriteDataAsync(ArraySegment buffer, CancellationToken cancellationToken = default(CancellationToken)) + public Task WriteDataAsync(ReadOnlySpan buffer, CancellationToken cancellationToken = default(CancellationToken)) { if (cancellationToken.IsCancellationRequested) { @@ -65,7 +65,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http public Task WriteStreamSuffixAsync(CancellationToken cancellationToken) { - return WriteAsync(_endChunkedResponseBytes, cancellationToken); + return WriteAsync(_endChunkedResponseBytes.Span, cancellationToken); } public Task FlushAsync(CancellationToken cancellationToken = default(CancellationToken)) @@ -160,11 +160,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http public Task Write100ContinueAsync(CancellationToken cancellationToken) { - return WriteAsync(_continueBytes, default(CancellationToken)); + return WriteAsync(_continueBytes.Span, default(CancellationToken)); } private Task WriteAsync( - ArraySegment buffer, + ReadOnlySpan buffer, CancellationToken cancellationToken) { var writableBuffer = default(PipeWriter); @@ -178,10 +178,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http writableBuffer = _pipeWriter; var writer = OutputWriter.Create(writableBuffer); - if (buffer.Count > 0) + if (buffer.Length > 0) { - writer.Write(new ReadOnlySpan(buffer.Array, buffer.Offset, buffer.Count)); - bytesWritten += buffer.Count; + writer.Write(buffer); + bytesWritten += buffer.Length; } writableBuffer.Commit(); diff --git a/src/Kestrel.Core/Internal/Http/HttpProtocol.cs b/src/Kestrel.Core/Internal/Http/HttpProtocol.cs index d0e90e1054..45bfa675ca 100644 --- a/src/Kestrel.Core/Internal/Http/HttpProtocol.cs +++ b/src/Kestrel.Core/Internal/Http/HttpProtocol.cs @@ -31,7 +31,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http private static readonly byte[] _bytesConnectionKeepAlive = Encoding.ASCII.GetBytes("\r\nConnection: keep-alive"); private static readonly byte[] _bytesTransferEncodingChunked = Encoding.ASCII.GetBytes("\r\nTransfer-Encoding: chunked"); private static readonly byte[] _bytesServer = Encoding.ASCII.GetBytes("\r\nServer: " + Constants.ServerName); - private static readonly Action> _writeChunk = WriteChunk; + private static readonly Action> _writeChunk = WriteChunk; private readonly object _onStartingSync = new Object(); private readonly object _onCompletedSync = new Object(); @@ -762,14 +762,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http await Output.FlushAsync(cancellationToken); } - public Task WriteAsync(ArraySegment data, CancellationToken cancellationToken = default(CancellationToken)) + public Task WriteAsync(ReadOnlyMemory data, CancellationToken cancellationToken = default(CancellationToken)) { // For the first write, ensure headers are flushed if WriteDataAsync isn't called. var firstWrite = !HasResponseStarted; if (firstWrite) { - var initializeTask = InitializeResponseAsync(data.Count); + var initializeTask = InitializeResponseAsync(data.Length); // If return is Task.CompletedTask no awaiting is required if (!ReferenceEquals(initializeTask, Task.CompletedTask)) { @@ -778,14 +778,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http } else { - VerifyAndUpdateWrite(data.Count); + VerifyAndUpdateWrite(data.Length); } if (_canHaveBody) { if (_autoChunk) { - if (data.Count == 0) + if (data.Length == 0) { return !firstWrite ? Task.CompletedTask : FlushAsync(cancellationToken); } @@ -794,7 +794,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http else { CheckLastWrite(); - return Output.WriteDataAsync(data, cancellationToken: cancellationToken); + return Output.WriteDataAsync(data.Span, cancellationToken: cancellationToken); } } else @@ -804,7 +804,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http } } - public async Task WriteAsyncAwaited(Task initializeTask, ArraySegment data, CancellationToken cancellationToken) + public async Task WriteAsyncAwaited(Task initializeTask, ReadOnlyMemory data, CancellationToken cancellationToken) { await initializeTask; @@ -814,7 +814,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { if (_autoChunk) { - if (data.Count == 0) + if (data.Length == 0) { await FlushAsync(cancellationToken); return; @@ -825,7 +825,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http else { CheckLastWrite(); - await Output.WriteDataAsync(data, cancellationToken: cancellationToken); + await Output.WriteDataAsync(data.Span, cancellationToken: cancellationToken); } } else @@ -892,18 +892,18 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http } } - private Task WriteChunkedAsync(ArraySegment data, CancellationToken cancellationToken) + private Task WriteChunkedAsync(ReadOnlyMemory data, CancellationToken cancellationToken) { return Output.WriteAsync(_writeChunk, data); } - private static void WriteChunk(PipeWriter writableBuffer, ArraySegment buffer) + private static void WriteChunk(PipeWriter writableBuffer, ReadOnlyMemory buffer) { var writer = OutputWriter.Create(writableBuffer); - if (buffer.Count > 0) + if (buffer.Length > 0) { - ChunkWriter.WriteBeginChunkBytes(ref writer, buffer.Count); - writer.Write(new ReadOnlySpan(buffer.Array, buffer.Offset, buffer.Count)); + ChunkWriter.WriteBeginChunkBytes(ref writer, buffer.Length); + writer.Write(buffer.Span); ChunkWriter.WriteEndChunkBytes(ref writer); } } diff --git a/src/Kestrel.Core/Internal/Http/HttpRequestStream.cs b/src/Kestrel.Core/Internal/Http/HttpRequestStream.cs index 2f677704c3..4f325f4d38 100644 --- a/src/Kestrel.Core/Internal/Http/HttpRequestStream.cs +++ b/src/Kestrel.Core/Internal/Http/HttpRequestStream.cs @@ -3,11 +3,12 @@ using System; using System.IO; +using System.Runtime.ExceptionServices; using System.Threading; using System.Threading.Tasks; -using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Protocols; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { @@ -105,20 +106,25 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http public override Task ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) { - var task = ValidateState(cancellationToken); - if (task != null) - { - return task; - } + ValidateState(cancellationToken); - return ReadAsyncInternal(buffer, offset, count, cancellationToken); + return ReadAsyncInternal(new Memory(buffer, offset, count), cancellationToken).AsTask(); } - private async Task ReadAsyncInternal(byte[] buffer, int offset, int count, CancellationToken cancellationToken) +#if NETCOREAPP2_1 + public override ValueTask ReadAsync(Memory destination, CancellationToken cancellationToken = default) + { + ValidateState(cancellationToken); + + return ReadAsyncInternal(destination, cancellationToken); + } +#endif + + private async ValueTask ReadAsyncInternal(Memory buffer, CancellationToken cancellationToken) { try { - return await _body.ReadAsync(new ArraySegment(buffer, offset, count), cancellationToken); + return await _body.ReadAsync(buffer, cancellationToken); } catch (ConnectionAbortedException ex) { @@ -137,11 +143,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http throw new ArgumentException(CoreStrings.PositiveNumberRequired, nameof(bufferSize)); } - var task = ValidateState(cancellationToken); - if (task != null) - { - return task; - } + ValidateState(cancellationToken); return CopyToAsyncInternal(destination, cancellationToken); } @@ -193,24 +195,29 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http } } - private Task ValidateState(CancellationToken cancellationToken) + private void ValidateState(CancellationToken cancellationToken) { switch (_state) { case HttpStreamState.Open: if (cancellationToken.IsCancellationRequested) { - return Task.FromCanceled(cancellationToken); + cancellationToken.ThrowIfCancellationRequested(); } break; case HttpStreamState.Closed: throw new ObjectDisposedException(nameof(HttpRequestStream)); case HttpStreamState.Aborted: - return _error != null ? - Task.FromException(_error) : - Task.FromCanceled(new CancellationToken(true)); + if (_error != null) + { + ExceptionDispatchInfo.Capture(_error).Throw(); + } + else + { + throw new TaskCanceledException(); + } + break; } - return null; } } } diff --git a/src/Kestrel.Core/Internal/Http/HttpResponseStream.cs b/src/Kestrel.Core/Internal/Http/HttpResponseStream.cs index e1c44d645f..93cea42956 100644 --- a/src/Kestrel.Core/Internal/Http/HttpResponseStream.cs +++ b/src/Kestrel.Core/Internal/Http/HttpResponseStream.cs @@ -41,12 +41,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http public override Task FlushAsync(CancellationToken cancellationToken) { - var task = ValidateState(cancellationToken); - if (task == null) - { - return _httpResponseControl.FlushAsync(cancellationToken); - } - return task; + ValidateState(cancellationToken); + + return _httpResponseControl.FlushAsync(cancellationToken); } public override long Seek(long offset, SeekOrigin origin) @@ -109,14 +106,20 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) { - var task = ValidateState(cancellationToken); - if (task == null) - { - return _httpResponseControl.WriteAsync(new ArraySegment(buffer, offset, count), cancellationToken); - } - return task; + ValidateState(cancellationToken); + + return _httpResponseControl.WriteAsync(new ReadOnlyMemory(buffer, offset, count), cancellationToken); } +#if NETCOREAPP2_1 + public override Task WriteAsync(ReadOnlyMemory source, CancellationToken cancellationToken = default) + { + ValidateState(cancellationToken); + + return _httpResponseControl.WriteAsync(source, cancellationToken); + } +#endif + public void StartAcceptingWrites() { // Only start if not aborted @@ -147,14 +150,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http } } - private Task ValidateState(CancellationToken cancellationToken) + private void ValidateState(CancellationToken cancellationToken) { switch (_state) { case HttpStreamState.Open: if (cancellationToken.IsCancellationRequested) { - return Task.FromCanceled(cancellationToken); + cancellationToken.ThrowIfCancellationRequested(); } break; case HttpStreamState.Closed: @@ -163,11 +166,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http if (cancellationToken.IsCancellationRequested) { // Aborted state only throws on write if cancellationToken requests it - return Task.FromCanceled(cancellationToken); + cancellationToken.ThrowIfCancellationRequested(); } break; } - return null; } } } diff --git a/src/Kestrel.Core/Internal/Http/IHttpOutputProducer.cs b/src/Kestrel.Core/Internal/Http/IHttpOutputProducer.cs index 019fa9fe77..abc2b4454a 100644 --- a/src/Kestrel.Core/Internal/Http/IHttpOutputProducer.cs +++ b/src/Kestrel.Core/Internal/Http/IHttpOutputProducer.cs @@ -15,7 +15,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http Task FlushAsync(CancellationToken cancellationToken); Task Write100ContinueAsync(CancellationToken cancellationToken); void WriteResponseHeaders(int statusCode, string ReasonPhrase, HttpResponseHeaders responseHeaders); - Task WriteDataAsync(ArraySegment data, CancellationToken cancellationToken); + // The reason this is ReadOnlySpan and not ReadOnlyMemory is because writes are always + // synchronous. Flushing to get back pressure is the only time we truly go async but + // that's after the buffer is copied + Task WriteDataAsync(ReadOnlySpan data, CancellationToken cancellationToken); Task WriteStreamSuffixAsync(CancellationToken cancellationToken); } } diff --git a/src/Kestrel.Core/Internal/Http/IHttpResponseControl.cs b/src/Kestrel.Core/Internal/Http/IHttpResponseControl.cs index fac6b11c0b..9a42aa6116 100644 --- a/src/Kestrel.Core/Internal/Http/IHttpResponseControl.cs +++ b/src/Kestrel.Core/Internal/Http/IHttpResponseControl.cs @@ -10,7 +10,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http public interface IHttpResponseControl { void ProduceContinue(); - Task WriteAsync(ArraySegment data, CancellationToken cancellationToken); + Task WriteAsync(ReadOnlyMemory data, CancellationToken cancellationToken); Task FlushAsync(CancellationToken cancellationToken); } } diff --git a/src/Kestrel.Core/Internal/Http/MessageBody.cs b/src/Kestrel.Core/Internal/Http/MessageBody.cs index 5d05eacf43..ad330f2c92 100644 --- a/src/Kestrel.Core/Internal/Http/MessageBody.cs +++ b/src/Kestrel.Core/Internal/Http/MessageBody.cs @@ -35,7 +35,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http protected IKestrelTrace Log => _context.ServiceContext.Log; - public virtual async Task ReadAsync(ArraySegment buffer, CancellationToken cancellationToken = default(CancellationToken)) + public virtual async ValueTask ReadAsync(Memory buffer, CancellationToken cancellationToken = default(CancellationToken)) { TryInit(); @@ -50,10 +50,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http if (!readableBuffer.IsEmpty) { // buffer.Count is int - var actual = (int) Math.Min(readableBuffer.Length, buffer.Count); + var actual = (int) Math.Min(readableBuffer.Length, buffer.Length); var slice = readableBuffer.Slice(0, actual); consumed = readableBuffer.GetPosition(readableBuffer.Start, actual); - slice.CopyTo(buffer); + slice.CopyTo(buffer.Span); return actual; } else if (result.IsCompleted) @@ -84,8 +84,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { foreach (var memory in readableBuffer) { + // REVIEW: This *could* be slower if 2 things are true + // - The WriteAsync(ReadOnlyMemory) isn't overridden on the destination + // - We change the Kestrel Memory Pool to not use pinned arrays but instead use native memory +#if NETCOREAPP2_1 + await destination.WriteAsync(memory); +#else var array = memory.GetArray(); await destination.WriteAsync(array.Array, array.Offset, array.Count, cancellationToken); +#endif } } else if (result.IsCompleted) @@ -148,7 +155,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http public override bool IsEmpty => true; - public override Task ReadAsync(ArraySegment buffer, CancellationToken cancellationToken = default(CancellationToken)) => Task.FromResult(0); + public override ValueTask ReadAsync(Memory buffer, CancellationToken cancellationToken = default(CancellationToken)) => new ValueTask(0); public override Task CopyToAsync(Stream destination, CancellationToken cancellationToken = default(CancellationToken)) => Task.CompletedTask; diff --git a/src/Kestrel.Core/Internal/Http2/Http2Frame.cs b/src/Kestrel.Core/Internal/Http2/Http2Frame.cs index e0dbf8bd09..0d693c0ced 100644 --- a/src/Kestrel.Core/Internal/Http2/Http2Frame.cs +++ b/src/Kestrel.Core/Internal/Http2/Http2Frame.cs @@ -19,7 +19,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 private readonly byte[] _data = new byte[HeaderLength + MinAllowedMaxFrameSize]; - public ArraySegment Raw => new ArraySegment(_data, 0, HeaderLength + Length); + public Span Raw => new Span(_data, 0, HeaderLength + Length); public int Length { diff --git a/src/Kestrel.Core/Internal/Http2/Http2FrameWriter.cs b/src/Kestrel.Core/Internal/Http2/Http2FrameWriter.cs index 0540beb0fa..362bdc9759 100644 --- a/src/Kestrel.Core/Internal/Http2/Http2FrameWriter.cs +++ b/src/Kestrel.Core/Internal/Http2/Http2FrameWriter.cs @@ -100,10 +100,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 } } - public Task WriteDataAsync(int streamId, Span data, CancellationToken cancellationToken) + public Task WriteDataAsync(int streamId, ReadOnlySpan data, CancellationToken cancellationToken) => WriteDataAsync(streamId, data, endStream: false, cancellationToken: cancellationToken); - public Task WriteDataAsync(int streamId, Span data, bool endStream, CancellationToken cancellationToken) + public Task WriteDataAsync(int streamId, ReadOnlySpan data, bool endStream, CancellationToken cancellationToken) { var tasks = new List(); @@ -162,7 +162,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 } } - public Task WritePingAsync(Http2PingFrameFlags flags, Span payload) + public Task WritePingAsync(Http2PingFrameFlags flags, ReadOnlySpan payload) { lock (_writeLock) { @@ -182,7 +182,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 } // Must be called with _writeLock - private void Append(ArraySegment data) + private void Append(ReadOnlySpan data) { if (_completed) { @@ -194,15 +194,20 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 } // Must be called with _writeLock - private async Task WriteAsync(ArraySegment data, CancellationToken cancellationToken = default(CancellationToken)) + private Task WriteAsync(ReadOnlySpan data, CancellationToken cancellationToken = default(CancellationToken)) { if (_completed) { - return; + return Task.CompletedTask; } _outputWriter.Write(data); - await _outputWriter.FlushAsync(cancellationToken); + return FlushAsync(_outputWriter, cancellationToken); + } + + private async Task FlushAsync(PipeWriter outputWriter, CancellationToken cancellationToken) + { + await outputWriter.FlushAsync(cancellationToken); } private static IEnumerable> EnumerateHeaders(IHeaderDictionary headers) diff --git a/src/Kestrel.Core/Internal/Http2/Http2OutputProducer.cs b/src/Kestrel.Core/Internal/Http2/Http2OutputProducer.cs index d1aa31df72..571f5a32d2 100644 --- a/src/Kestrel.Core/Internal/Http2/Http2OutputProducer.cs +++ b/src/Kestrel.Core/Internal/Http2/Http2OutputProducer.cs @@ -39,7 +39,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 public Task Write100ContinueAsync(CancellationToken cancellationToken) => _frameWriter.Write100ContinueAsync(_streamId); - public Task WriteDataAsync(ArraySegment data, CancellationToken cancellationToken) + public Task WriteDataAsync(ReadOnlySpan data, CancellationToken cancellationToken) { return _frameWriter.WriteDataAsync(_streamId, data, cancellationToken); } diff --git a/src/Kestrel.Core/Internal/Http2/IHttp2FrameWriter.cs b/src/Kestrel.Core/Internal/Http2/IHttp2FrameWriter.cs index 21a8192a44..aa7b23330b 100644 --- a/src/Kestrel.Core/Internal/Http2/IHttp2FrameWriter.cs +++ b/src/Kestrel.Core/Internal/Http2/IHttp2FrameWriter.cs @@ -14,11 +14,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 Task FlushAsync(CancellationToken cancellationToken = default(CancellationToken)); Task Write100ContinueAsync(int streamId); void WriteResponseHeaders(int streamId, int statusCode, IHeaderDictionary headers); - Task WriteDataAsync(int streamId, Span data, CancellationToken cancellationToken); - Task WriteDataAsync(int streamId, Span data, bool endStream, CancellationToken cancellationToken); + Task WriteDataAsync(int streamId, ReadOnlySpan data, CancellationToken cancellationToken); + Task WriteDataAsync(int streamId, ReadOnlySpan data, bool endStream, CancellationToken cancellationToken); Task WriteRstStreamAsync(int streamId, Http2ErrorCode errorCode); Task WriteSettingsAckAsync(); - Task WritePingAsync(Http2PingFrameFlags flags, Span payload); + Task WritePingAsync(Http2PingFrameFlags flags, ReadOnlySpan payload); Task WriteGoAwayAsync(int lastStreamId, Http2ErrorCode errorCode); } } diff --git a/test/Kestrel.Core.Tests/Http2ConnectionTests.cs b/test/Kestrel.Core.Tests/Http2ConnectionTests.cs index e88add0081..5c5a0c2925 100644 --- a/test/Kestrel.Core.Tests/Http2ConnectionTests.cs +++ b/test/Kestrel.Core.Tests/Http2ConnectionTests.cs @@ -2136,10 +2136,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests return Task.WhenAll(_runningStreams.Values.Select(tcs => tcs.Task)).TimeoutAfter(TestConstants.DefaultTimeout); } - private async Task SendAsync(ArraySegment span) + private Task SendAsync(ReadOnlySpan span) { var writableBuffer = _pair.Application.Output; writableBuffer.Write(span); + return FlushAsync(writableBuffer); + } + + private static async Task FlushAsync(PipeWriter writableBuffer) + { await writableBuffer.FlushAsync(); } diff --git a/test/Kestrel.Core.Tests/HttpRequestStreamTests.cs b/test/Kestrel.Core.Tests/HttpRequestStreamTests.cs index a4baec6303..98c3d7ef68 100644 --- a/test/Kestrel.Core.Tests/HttpRequestStreamTests.cs +++ b/test/Kestrel.Core.Tests/HttpRequestStreamTests.cs @@ -118,7 +118,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests var mockBodyControl = new Mock(); mockBodyControl.Setup(m => m.AllowSynchronousIO).Returns(() => allowSynchronousIO); var mockMessageBody = new Mock((HttpProtocol)null); - mockMessageBody.Setup(m => m.ReadAsync(It.IsAny>(), CancellationToken.None)).ReturnsAsync(0); + mockMessageBody.Setup(m => m.ReadAsync(It.IsAny>(), CancellationToken.None)).Returns(new ValueTask(0)); var stream = new HttpRequestStream(mockBodyControl.Object); stream.StartAcceptingReads(mockMessageBody.Object); @@ -136,25 +136,23 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests } [Fact] - public void AbortCausesReadToCancel() + public async Task AbortCausesReadToCancel() { var stream = new HttpRequestStream(Mock.Of()); stream.StartAcceptingReads(null); stream.Abort(); - var task = stream.ReadAsync(new byte[1], 0, 1); - Assert.True(task.IsCanceled); + await Assert.ThrowsAsync(() => stream.ReadAsync(new byte[1], 0, 1)); } [Fact] - public void AbortWithErrorCausesReadToCancel() + public async Task AbortWithErrorCausesReadToCancel() { var stream = new HttpRequestStream(Mock.Of()); stream.StartAcceptingReads(null); var error = new Exception(); stream.Abort(error); - var task = stream.ReadAsync(new byte[1], 0, 1); - Assert.True(task.IsFaulted); - Assert.Same(error, task.Exception.InnerException); + var exception = await Assert.ThrowsAsync(() => stream.ReadAsync(new byte[1], 0, 1)); + Assert.Same(error, exception); } [Fact] @@ -167,25 +165,23 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests } [Fact] - public void AbortCausesCopyToAsyncToCancel() + public async Task AbortCausesCopyToAsyncToCancel() { var stream = new HttpRequestStream(Mock.Of()); stream.StartAcceptingReads(null); stream.Abort(); - var task = stream.CopyToAsync(Mock.Of()); - Assert.True(task.IsCanceled); + await Assert.ThrowsAsync(() => stream.CopyToAsync(Mock.Of())); } [Fact] - public void AbortWithErrorCausesCopyToAsyncToCancel() + public async Task AbortWithErrorCausesCopyToAsyncToCancel() { var stream = new HttpRequestStream(Mock.Of()); stream.StartAcceptingReads(null); var error = new Exception(); stream.Abort(error); - var task = stream.CopyToAsync(Mock.Of()); - Assert.True(task.IsFaulted); - Assert.Same(error, task.Exception.InnerException); + var exception = await Assert.ThrowsAsync(() => stream.CopyToAsync(Mock.Of())); + Assert.Same(error, exception); } [Fact] diff --git a/test/Kestrel.Core.Tests/HttpResponseStreamTests.cs b/test/Kestrel.Core.Tests/HttpResponseStreamTests.cs index 06bd3436cd..5e49e8a5a2 100644 --- a/test/Kestrel.Core.Tests/HttpResponseStreamTests.cs +++ b/test/Kestrel.Core.Tests/HttpResponseStreamTests.cs @@ -110,7 +110,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests var mockBodyControl = new Mock(); mockBodyControl.Setup(m => m.AllowSynchronousIO).Returns(() => allowSynchronousIO); var mockHttpResponseControl = new Mock(); - mockHttpResponseControl.Setup(m => m.WriteAsync(It.IsAny>(), CancellationToken.None)).Returns(Task.CompletedTask); + mockHttpResponseControl.Setup(m => m.WriteAsync(It.IsAny>(), CancellationToken.None)).Returns(Task.CompletedTask); var stream = new HttpResponseStream(mockBodyControl.Object, mockHttpResponseControl.Object); stream.StartAcceptingWrites(); diff --git a/test/Kestrel.Core.Tests/MessageBodyTests.cs b/test/Kestrel.Core.Tests/MessageBodyTests.cs index ad6ac1237e..41d0724bd0 100644 --- a/test/Kestrel.Core.Tests/MessageBodyTests.cs +++ b/test/Kestrel.Core.Tests/MessageBodyTests.cs @@ -426,7 +426,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests { var writeCount = 0; var writeTcs = new TaskCompletionSource(); - var mockDestination = new Mock(); + var mockDestination = new Mock() { CallBase = true }; mockDestination .Setup(m => m.WriteAsync(It.IsAny(), It.IsAny(), It.IsAny(), CancellationToken.None)) @@ -595,7 +595,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests // Time out on the next read input.Http1Connection.SendTimeoutResponse(); - var exception = await Assert.ThrowsAsync(() => body.ReadAsync(new ArraySegment(new byte[1]))); + var exception = await Assert.ThrowsAsync(async () => await body.ReadAsync(new Memory(new byte[1]))); Assert.Equal(StatusCodes.Status408RequestTimeout, exception.StatusCode); await body.StopAsync(); diff --git a/test/Kestrel.Core.Tests/TestHelpers/MockHttpResponseControl.cs b/test/Kestrel.Core.Tests/TestHelpers/MockHttpResponseControl.cs index 2ff611f49e..738a070635 100644 --- a/test/Kestrel.Core.Tests/TestHelpers/MockHttpResponseControl.cs +++ b/test/Kestrel.Core.Tests/TestHelpers/MockHttpResponseControl.cs @@ -19,7 +19,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests.TestHelpers { } - public Task WriteAsync(ArraySegment data, CancellationToken cancellationToken) + public Task WriteAsync(ReadOnlyMemory data, CancellationToken cancellationToken) { return Task.CompletedTask; } From dbbbaf8e4b5f5235a1fcf62bceac7cb7c24f8d0d Mon Sep 17 00:00:00 2001 From: Pranav K Date: Wed, 21 Feb 2018 18:27:01 -0800 Subject: [PATCH 1534/1662] Use FeatureBranchVersionSuffix when generating VersionSuffix --- version.props | 1 + 1 file changed, 1 insertion(+) diff --git a/version.props b/version.props index 370d5ababd..65c8a07e37 100644 --- a/version.props +++ b/version.props @@ -5,6 +5,7 @@ $(VersionPrefix) $(VersionPrefix)-$(VersionSuffix)-final t000 + $(VersionSuffix)-$([System.Text.RegularExpressions.Regex]::Replace('$(FeatureBranchVersionSuffix)', '[^\w-]', '-')) $(VersionSuffix)-$(BuildNumber) From d996f6b7fcc805b749a6dfaf3c3dd88dff691f85 Mon Sep 17 00:00:00 2001 From: Pavel Krymets Date: Thu, 22 Feb 2018 10:27:47 -0800 Subject: [PATCH 1535/1662] Drop Pipelines.Testing dependency that we don't use (#2343) --- build/dependencies.props | 3 +-- test/Kestrel.Core.Tests/Kestrel.Core.Tests.csproj | 1 - 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/build/dependencies.props b/build/dependencies.props index 302297c7ec..4ed572c52e 100644 --- a/build/dependencies.props +++ b/build/dependencies.props @@ -33,7 +33,6 @@ 4.5.0-preview2-26130-01 0.1.0-preview2-180130-1 0.1.0-preview2-180130-1 - 0.1.0-preview2-180130-1 4.5.0-preview2-26130-01 4.5.0-preview2-26130-01 4.5.0-preview2-26130-01 @@ -45,4 +44,4 @@ 2.4.0-beta.1.build3945 - \ No newline at end of file + diff --git a/test/Kestrel.Core.Tests/Kestrel.Core.Tests.csproj b/test/Kestrel.Core.Tests/Kestrel.Core.Tests.csproj index 632a9f5ae7..fdbbd000ef 100644 --- a/test/Kestrel.Core.Tests/Kestrel.Core.Tests.csproj +++ b/test/Kestrel.Core.Tests/Kestrel.Core.Tests.csproj @@ -21,7 +21,6 @@ - From c0f88ebdc1fa5f42043d38152f5a0992afad842a Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Fri, 23 Feb 2018 00:44:38 +0000 Subject: [PATCH 1536/1662] Faster IFeatureCollection.Get (#2290) --- .../HttpProtocolFeatureCollection.cs | 96 ++-- .../Internal/Http/Http1Connection.cs | 2 +- .../Http/HttpProtocol.FeatureCollection.cs | 14 +- .../Internal/Http/HttpProtocol.Generated.cs | 440 +++++++++++++----- .../Internal/Http2/Http2Stream.cs | 2 +- .../Internal/TransportConnection.Features.cs | 130 ++++-- .../HttpProtocolFeatureCollectionTests.cs | 224 +++++++++ .../HttpProtocolFeatureCollection.cs | 106 ++++- 8 files changed, 755 insertions(+), 259 deletions(-) create mode 100644 test/Kestrel.Core.Tests/HttpProtocolFeatureCollectionTests.cs diff --git a/benchmarks/Kestrel.Performance/HttpProtocolFeatureCollection.cs b/benchmarks/Kestrel.Performance/HttpProtocolFeatureCollection.cs index ddf7fa0554..69f07faf3e 100644 --- a/benchmarks/Kestrel.Performance/HttpProtocolFeatureCollection.cs +++ b/benchmarks/Kestrel.Performance/HttpProtocolFeatureCollection.cs @@ -4,6 +4,9 @@ using System; using System.Buffers; using System.IO.Pipelines; +using System.Runtime.CompilerServices; +using System.Threading; +using System.Threading.Tasks; using BenchmarkDotNet.Attributes; using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Server.Kestrel.Core; @@ -14,65 +17,63 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance { public class HttpProtocolFeatureCollection { - private readonly Http1Connection _http1Connection; - private IFeatureCollection _collection; + private readonly IFeatureCollection _collection; - [Benchmark(Baseline = true)] - public IHttpRequestFeature GetFirstViaFastFeature() + [Benchmark] + [MethodImpl(MethodImplOptions.NoInlining)] + public IHttpRequestFeature GetViaTypeOf_First() { - return (IHttpRequestFeature)GetFastFeature(typeof(IHttpRequestFeature)); + return (IHttpRequestFeature)_collection[typeof(IHttpRequestFeature)]; } [Benchmark] - public IHttpRequestFeature GetFirstViaType() - { - return (IHttpRequestFeature)Get(typeof(IHttpRequestFeature)); - } - - [Benchmark] - public IHttpRequestFeature GetFirstViaExtension() - { - return _collection.GetType(); - } - - [Benchmark] - public IHttpRequestFeature GetFirstViaGeneric() + [MethodImpl(MethodImplOptions.NoInlining)] + public IHttpRequestFeature GetViaGeneric_First() { return _collection.Get(); } [Benchmark] - public IHttpSendFileFeature GetLastViaFastFeature() + [MethodImpl(MethodImplOptions.NoInlining)] + public IHttpSendFileFeature GetViaTypeOf_Last() { - return (IHttpSendFileFeature)GetFastFeature(typeof(IHttpSendFileFeature)); + return (IHttpSendFileFeature)_collection[typeof(IHttpSendFileFeature)]; } [Benchmark] - public IHttpSendFileFeature GetLastViaType() - { - return (IHttpSendFileFeature)Get(typeof(IHttpSendFileFeature)); - } - - [Benchmark] - public IHttpSendFileFeature GetLastViaExtension() - { - return _collection.GetType(); - } - - [Benchmark] - public IHttpSendFileFeature GetLastViaGeneric() + [MethodImpl(MethodImplOptions.NoInlining)] + public IHttpSendFileFeature GetViaGeneric_Last() { return _collection.Get(); } - private object Get(Type type) + [Benchmark] + [MethodImpl(MethodImplOptions.NoInlining)] + public object GetViaTypeOf_Custom() { - return _collection[type]; + return (IHttpCustomFeature)_collection[typeof(IHttpCustomFeature)]; } - private object GetFastFeature(Type type) + [Benchmark] + [MethodImpl(MethodImplOptions.NoInlining)] + public object GetViaGeneric_Custom() { - return _http1Connection.FastFeatureGet(type); + return _collection.Get(); + } + + + [Benchmark] + [MethodImpl(MethodImplOptions.NoInlining)] + public object GetViaTypeOf_NotFound() + { + return (IHttpNotFoundFeature)_collection[typeof(IHttpNotFoundFeature)]; + } + + [Benchmark] + [MethodImpl(MethodImplOptions.NoInlining)] + public object GetViaGeneric_NotFound() + { + return _collection.Get(); } public HttpProtocolFeatureCollection() @@ -99,21 +100,24 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance http1Connection.Reset(); - _http1Connection = http1Connection; + _collection = http1Connection; } - [IterationSetup] - public void Setup() + private class SendFileFeature : IHttpSendFileFeature { - _collection = _http1Connection; + public Task SendFileAsync(string path, long offset, long? count, CancellationToken cancellation) + { + throw new NotImplementedException(); + } } - } - public static class IFeatureCollectionExtensions - { - public static T GetType(this IFeatureCollection collection) + private interface IHttpCustomFeature + { + } + + private interface IHttpNotFoundFeature { - return (T)collection[typeof(T)]; } } + } diff --git a/src/Kestrel.Core/Internal/Http/Http1Connection.cs b/src/Kestrel.Core/Internal/Http/Http1Connection.cs index a09b17e139..a66179fa4a 100644 --- a/src/Kestrel.Core/Internal/Http/Http1Connection.cs +++ b/src/Kestrel.Core/Internal/Http/Http1Connection.cs @@ -400,7 +400,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http protected override void OnReset() { - FastFeatureSet(typeof(IHttpUpgradeFeature), this); + ResetIHttpUpgradeFeature(); _requestTimedOut = false; _requestTargetForm = HttpRequestTarget.Unknown; diff --git a/src/Kestrel.Core/Internal/Http/HttpProtocol.FeatureCollection.cs b/src/Kestrel.Core/Internal/Http/HttpProtocol.FeatureCollection.cs index e4fe29168f..cc0337a833 100644 --- a/src/Kestrel.Core/Internal/Http/HttpProtocol.FeatureCollection.cs +++ b/src/Kestrel.Core/Internal/Http/HttpProtocol.FeatureCollection.cs @@ -243,20 +243,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http set => MinResponseDataRate = value; } - object IFeatureCollection.this[Type key] + protected void ResetIHttpUpgradeFeature() { - get => FastFeatureGet(key) ?? ConnectionFeatures[key]; - set => FastFeatureSet(key, value); + _currentIHttpUpgradeFeature = this; } - TFeature IFeatureCollection.Get() + protected void ResetIHttp2StreamIdFeature() { - return (TFeature)(FastFeatureGet(typeof(TFeature)) ?? ConnectionFeatures[typeof(TFeature)]); - } - - void IFeatureCollection.Set(TFeature instance) - { - FastFeatureSet(typeof(TFeature), instance); + _currentIHttp2StreamIdFeature = this; } void IHttpResponseFeature.OnStarting(Func callback, object state) diff --git a/src/Kestrel.Core/Internal/Http/HttpProtocol.Generated.cs b/src/Kestrel.Core/Internal/Http/HttpProtocol.Generated.cs index 319d36865b..3bac0a0778 100644 --- a/src/Kestrel.Core/Internal/Http/HttpProtocol.Generated.cs +++ b/src/Kestrel.Core/Internal/Http/HttpProtocol.Generated.cs @@ -82,205 +82,389 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http _currentIHttpSendFileFeature = null; } - internal object FastFeatureGet(Type key) + object IFeatureCollection.this[Type key] { - if (key == IHttpRequestFeatureType) + get { - return _currentIHttpRequestFeature; + object feature = null; + if (key == IHttpRequestFeatureType) + { + feature = _currentIHttpRequestFeature; + } + else if (key == IHttpResponseFeatureType) + { + feature = _currentIHttpResponseFeature; + } + else if (key == IHttpRequestIdentifierFeatureType) + { + feature = _currentIHttpRequestIdentifierFeature; + } + else if (key == IServiceProvidersFeatureType) + { + feature = _currentIServiceProvidersFeature; + } + else if (key == IHttpRequestLifetimeFeatureType) + { + feature = _currentIHttpRequestLifetimeFeature; + } + else if (key == IHttpConnectionFeatureType) + { + feature = _currentIHttpConnectionFeature; + } + else if (key == IHttpAuthenticationFeatureType) + { + feature = _currentIHttpAuthenticationFeature; + } + else if (key == IQueryFeatureType) + { + feature = _currentIQueryFeature; + } + else if (key == IFormFeatureType) + { + feature = _currentIFormFeature; + } + else if (key == IHttpUpgradeFeatureType) + { + feature = _currentIHttpUpgradeFeature; + } + else if (key == IHttp2StreamIdFeatureType) + { + feature = _currentIHttp2StreamIdFeature; + } + else if (key == IResponseCookiesFeatureType) + { + feature = _currentIResponseCookiesFeature; + } + else if (key == IItemsFeatureType) + { + feature = _currentIItemsFeature; + } + else if (key == ITlsConnectionFeatureType) + { + feature = _currentITlsConnectionFeature; + } + else if (key == IHttpWebSocketFeatureType) + { + feature = _currentIHttpWebSocketFeature; + } + else if (key == ISessionFeatureType) + { + feature = _currentISessionFeature; + } + else if (key == IHttpMaxRequestBodySizeFeatureType) + { + feature = _currentIHttpMaxRequestBodySizeFeature; + } + else if (key == IHttpMinRequestBodyDataRateFeatureType) + { + feature = _currentIHttpMinRequestBodyDataRateFeature; + } + else if (key == IHttpMinResponseDataRateFeatureType) + { + feature = _currentIHttpMinResponseDataRateFeature; + } + else if (key == IHttpBodyControlFeatureType) + { + feature = _currentIHttpBodyControlFeature; + } + else if (key == IHttpSendFileFeatureType) + { + feature = _currentIHttpSendFileFeature; + } + else if (MaybeExtra != null) + { + feature = ExtraFeatureGet(key); + } + + return feature ?? ConnectionFeatures[key]; } - if (key == IHttpResponseFeatureType) + + set { - return _currentIHttpResponseFeature; + _featureRevision++; + + if (key == IHttpRequestFeatureType) + { + _currentIHttpRequestFeature = value; + } + else if (key == IHttpResponseFeatureType) + { + _currentIHttpResponseFeature = value; + } + else if (key == IHttpRequestIdentifierFeatureType) + { + _currentIHttpRequestIdentifierFeature = value; + } + else if (key == IServiceProvidersFeatureType) + { + _currentIServiceProvidersFeature = value; + } + else if (key == IHttpRequestLifetimeFeatureType) + { + _currentIHttpRequestLifetimeFeature = value; + } + else if (key == IHttpConnectionFeatureType) + { + _currentIHttpConnectionFeature = value; + } + else if (key == IHttpAuthenticationFeatureType) + { + _currentIHttpAuthenticationFeature = value; + } + else if (key == IQueryFeatureType) + { + _currentIQueryFeature = value; + } + else if (key == IFormFeatureType) + { + _currentIFormFeature = value; + } + else if (key == IHttpUpgradeFeatureType) + { + _currentIHttpUpgradeFeature = value; + } + else if (key == IHttp2StreamIdFeatureType) + { + _currentIHttp2StreamIdFeature = value; + } + else if (key == IResponseCookiesFeatureType) + { + _currentIResponseCookiesFeature = value; + } + else if (key == IItemsFeatureType) + { + _currentIItemsFeature = value; + } + else if (key == ITlsConnectionFeatureType) + { + _currentITlsConnectionFeature = value; + } + else if (key == IHttpWebSocketFeatureType) + { + _currentIHttpWebSocketFeature = value; + } + else if (key == ISessionFeatureType) + { + _currentISessionFeature = value; + } + else if (key == IHttpMaxRequestBodySizeFeatureType) + { + _currentIHttpMaxRequestBodySizeFeature = value; + } + else if (key == IHttpMinRequestBodyDataRateFeatureType) + { + _currentIHttpMinRequestBodyDataRateFeature = value; + } + else if (key == IHttpMinResponseDataRateFeatureType) + { + _currentIHttpMinResponseDataRateFeature = value; + } + else if (key == IHttpBodyControlFeatureType) + { + _currentIHttpBodyControlFeature = value; + } + else if (key == IHttpSendFileFeatureType) + { + _currentIHttpSendFileFeature = value; + } + else + { + ExtraFeatureSet(key, value); + } } - if (key == IHttpRequestIdentifierFeatureType) - { - return _currentIHttpRequestIdentifierFeature; - } - if (key == IServiceProvidersFeatureType) - { - return _currentIServiceProvidersFeature; - } - if (key == IHttpRequestLifetimeFeatureType) - { - return _currentIHttpRequestLifetimeFeature; - } - if (key == IHttpConnectionFeatureType) - { - return _currentIHttpConnectionFeature; - } - if (key == IHttpAuthenticationFeatureType) - { - return _currentIHttpAuthenticationFeature; - } - if (key == IQueryFeatureType) - { - return _currentIQueryFeature; - } - if (key == IFormFeatureType) - { - return _currentIFormFeature; - } - if (key == IHttpUpgradeFeatureType) - { - return _currentIHttpUpgradeFeature; - } - if (key == IHttp2StreamIdFeatureType) - { - return _currentIHttp2StreamIdFeature; - } - if (key == IResponseCookiesFeatureType) - { - return _currentIResponseCookiesFeature; - } - if (key == IItemsFeatureType) - { - return _currentIItemsFeature; - } - if (key == ITlsConnectionFeatureType) - { - return _currentITlsConnectionFeature; - } - if (key == IHttpWebSocketFeatureType) - { - return _currentIHttpWebSocketFeature; - } - if (key == ISessionFeatureType) - { - return _currentISessionFeature; - } - if (key == IHttpMaxRequestBodySizeFeatureType) - { - return _currentIHttpMaxRequestBodySizeFeature; - } - if (key == IHttpMinRequestBodyDataRateFeatureType) - { - return _currentIHttpMinRequestBodyDataRateFeature; - } - if (key == IHttpMinResponseDataRateFeatureType) - { - return _currentIHttpMinResponseDataRateFeature; - } - if (key == IHttpBodyControlFeatureType) - { - return _currentIHttpBodyControlFeature; - } - if (key == IHttpSendFileFeatureType) - { - return _currentIHttpSendFileFeature; - } - return ExtraFeatureGet(key); } - protected void FastFeatureSet(Type key, object feature) + void IFeatureCollection.Set(TFeature feature) { _featureRevision++; - - if (key == IHttpRequestFeatureType) + if (typeof(TFeature) == typeof(IHttpRequestFeature)) { _currentIHttpRequestFeature = feature; - return; } - if (key == IHttpResponseFeatureType) + else if (typeof(TFeature) == typeof(IHttpResponseFeature)) { _currentIHttpResponseFeature = feature; - return; } - if (key == IHttpRequestIdentifierFeatureType) + else if (typeof(TFeature) == typeof(IHttpRequestIdentifierFeature)) { _currentIHttpRequestIdentifierFeature = feature; - return; } - if (key == IServiceProvidersFeatureType) + else if (typeof(TFeature) == typeof(IServiceProvidersFeature)) { _currentIServiceProvidersFeature = feature; - return; } - if (key == IHttpRequestLifetimeFeatureType) + else if (typeof(TFeature) == typeof(IHttpRequestLifetimeFeature)) { _currentIHttpRequestLifetimeFeature = feature; - return; } - if (key == IHttpConnectionFeatureType) + else if (typeof(TFeature) == typeof(IHttpConnectionFeature)) { _currentIHttpConnectionFeature = feature; - return; } - if (key == IHttpAuthenticationFeatureType) + else if (typeof(TFeature) == typeof(IHttpAuthenticationFeature)) { _currentIHttpAuthenticationFeature = feature; - return; } - if (key == IQueryFeatureType) + else if (typeof(TFeature) == typeof(IQueryFeature)) { _currentIQueryFeature = feature; - return; } - if (key == IFormFeatureType) + else if (typeof(TFeature) == typeof(IFormFeature)) { _currentIFormFeature = feature; - return; } - if (key == IHttpUpgradeFeatureType) + else if (typeof(TFeature) == typeof(IHttpUpgradeFeature)) { _currentIHttpUpgradeFeature = feature; - return; } - if (key == IHttp2StreamIdFeatureType) + else if (typeof(TFeature) == typeof(IHttp2StreamIdFeature)) { _currentIHttp2StreamIdFeature = feature; - return; } - if (key == IResponseCookiesFeatureType) + else if (typeof(TFeature) == typeof(IResponseCookiesFeature)) { _currentIResponseCookiesFeature = feature; - return; } - if (key == IItemsFeatureType) + else if (typeof(TFeature) == typeof(IItemsFeature)) { _currentIItemsFeature = feature; - return; } - if (key == ITlsConnectionFeatureType) + else if (typeof(TFeature) == typeof(ITlsConnectionFeature)) { _currentITlsConnectionFeature = feature; - return; } - if (key == IHttpWebSocketFeatureType) + else if (typeof(TFeature) == typeof(IHttpWebSocketFeature)) { _currentIHttpWebSocketFeature = feature; - return; } - if (key == ISessionFeatureType) + else if (typeof(TFeature) == typeof(ISessionFeature)) { _currentISessionFeature = feature; - return; } - if (key == IHttpMaxRequestBodySizeFeatureType) + else if (typeof(TFeature) == typeof(IHttpMaxRequestBodySizeFeature)) { _currentIHttpMaxRequestBodySizeFeature = feature; - return; } - if (key == IHttpMinRequestBodyDataRateFeatureType) + else if (typeof(TFeature) == typeof(IHttpMinRequestBodyDataRateFeature)) { _currentIHttpMinRequestBodyDataRateFeature = feature; - return; } - if (key == IHttpMinResponseDataRateFeatureType) + else if (typeof(TFeature) == typeof(IHttpMinResponseDataRateFeature)) { _currentIHttpMinResponseDataRateFeature = feature; - return; } - if (key == IHttpBodyControlFeatureType) + else if (typeof(TFeature) == typeof(IHttpBodyControlFeature)) { _currentIHttpBodyControlFeature = feature; - return; } - if (key == IHttpSendFileFeatureType) + else if (typeof(TFeature) == typeof(IHttpSendFileFeature)) { _currentIHttpSendFileFeature = feature; - return; - }; - ExtraFeatureSet(key, feature); + } + else + { + ExtraFeatureSet(typeof(TFeature), feature); + } + } + + TFeature IFeatureCollection.Get() + { + TFeature feature = default; + if (typeof(TFeature) == typeof(IHttpRequestFeature)) + { + feature = (TFeature)_currentIHttpRequestFeature; + } + else if (typeof(TFeature) == typeof(IHttpResponseFeature)) + { + feature = (TFeature)_currentIHttpResponseFeature; + } + else if (typeof(TFeature) == typeof(IHttpRequestIdentifierFeature)) + { + feature = (TFeature)_currentIHttpRequestIdentifierFeature; + } + else if (typeof(TFeature) == typeof(IServiceProvidersFeature)) + { + feature = (TFeature)_currentIServiceProvidersFeature; + } + else if (typeof(TFeature) == typeof(IHttpRequestLifetimeFeature)) + { + feature = (TFeature)_currentIHttpRequestLifetimeFeature; + } + else if (typeof(TFeature) == typeof(IHttpConnectionFeature)) + { + feature = (TFeature)_currentIHttpConnectionFeature; + } + else if (typeof(TFeature) == typeof(IHttpAuthenticationFeature)) + { + feature = (TFeature)_currentIHttpAuthenticationFeature; + } + else if (typeof(TFeature) == typeof(IQueryFeature)) + { + feature = (TFeature)_currentIQueryFeature; + } + else if (typeof(TFeature) == typeof(IFormFeature)) + { + feature = (TFeature)_currentIFormFeature; + } + else if (typeof(TFeature) == typeof(IHttpUpgradeFeature)) + { + feature = (TFeature)_currentIHttpUpgradeFeature; + } + else if (typeof(TFeature) == typeof(IHttp2StreamIdFeature)) + { + feature = (TFeature)_currentIHttp2StreamIdFeature; + } + else if (typeof(TFeature) == typeof(IResponseCookiesFeature)) + { + feature = (TFeature)_currentIResponseCookiesFeature; + } + else if (typeof(TFeature) == typeof(IItemsFeature)) + { + feature = (TFeature)_currentIItemsFeature; + } + else if (typeof(TFeature) == typeof(ITlsConnectionFeature)) + { + feature = (TFeature)_currentITlsConnectionFeature; + } + else if (typeof(TFeature) == typeof(IHttpWebSocketFeature)) + { + feature = (TFeature)_currentIHttpWebSocketFeature; + } + else if (typeof(TFeature) == typeof(ISessionFeature)) + { + feature = (TFeature)_currentISessionFeature; + } + else if (typeof(TFeature) == typeof(IHttpMaxRequestBodySizeFeature)) + { + feature = (TFeature)_currentIHttpMaxRequestBodySizeFeature; + } + else if (typeof(TFeature) == typeof(IHttpMinRequestBodyDataRateFeature)) + { + feature = (TFeature)_currentIHttpMinRequestBodyDataRateFeature; + } + else if (typeof(TFeature) == typeof(IHttpMinResponseDataRateFeature)) + { + feature = (TFeature)_currentIHttpMinResponseDataRateFeature; + } + else if (typeof(TFeature) == typeof(IHttpBodyControlFeature)) + { + feature = (TFeature)_currentIHttpBodyControlFeature; + } + else if (typeof(TFeature) == typeof(IHttpSendFileFeature)) + { + feature = (TFeature)_currentIHttpSendFileFeature; + } + else if (MaybeExtra != null) + { + feature = (TFeature)(ExtraFeatureGet(typeof(TFeature))); + } + + if (feature == null) + { + feature = ConnectionFeatures.Get(); + } + + return feature; } private IEnumerable> FastEnumerable() diff --git a/src/Kestrel.Core/Internal/Http2/Http2Stream.cs b/src/Kestrel.Core/Internal/Http2/Http2Stream.cs index 6d8fc9136f..873cb1fbea 100644 --- a/src/Kestrel.Core/Internal/Http2/Http2Stream.cs +++ b/src/Kestrel.Core/Internal/Http2/Http2Stream.cs @@ -34,7 +34,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 protected override void OnReset() { - FastFeatureSet(typeof(IHttp2StreamIdFeature), this); + ResetIHttp2StreamIdFeature(); } protected override void OnRequestProcessingEnded() diff --git a/src/Kestrel.Transport.Abstractions/Internal/TransportConnection.Features.cs b/src/Kestrel.Transport.Abstractions/Internal/TransportConnection.Features.cs index ad794fa879..acd9e0dab1 100644 --- a/src/Kestrel.Transport.Abstractions/Internal/TransportConnection.Features.cs +++ b/src/Kestrel.Transport.Abstractions/Internal/TransportConnection.Features.cs @@ -111,69 +111,101 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal object IFeatureCollection.this[Type key] { - get => FastFeatureGet(key); - set => FastFeatureSet(key, value); + get + { + if (key == IHttpConnectionFeatureType) + { + return _currentIHttpConnectionFeature; + } + + if (key == IConnectionIdFeatureType) + { + return _currentIConnectionIdFeature; + } + + if (key == IConnectionTransportFeatureType) + { + return _currentIConnectionTransportFeature; + } + + if (MaybeExtra != null) + { + return ExtraFeatureGet(key); + } + + return null; + } + set + { + _featureRevision++; + + if (key == IHttpConnectionFeatureType) + { + _currentIHttpConnectionFeature = value; + } + else if (key == IConnectionIdFeatureType) + { + _currentIConnectionIdFeature = value; + } + else if (key == IConnectionTransportFeatureType) + { + _currentIConnectionTransportFeature = value; + } + else + { + ExtraFeatureSet(key, value); + } + } } TFeature IFeatureCollection.Get() { - return (TFeature)FastFeatureGet(typeof(TFeature)); + if (typeof(TFeature) == typeof(IHttpConnectionFeature)) + { + return (TFeature)_currentIHttpConnectionFeature; + } + else if (typeof(TFeature) == typeof(IConnectionIdFeature)) + { + return (TFeature)_currentIConnectionIdFeature; + } + else if (typeof(TFeature) == typeof(IConnectionTransportFeature)) + { + return (TFeature)_currentIConnectionTransportFeature; + } + else if (MaybeExtra != null) + { + return (TFeature)ExtraFeatureGet(typeof(TFeature)); + } + + return default; } void IFeatureCollection.Set(TFeature instance) { - FastFeatureSet(typeof(TFeature), instance); + _featureRevision++; + + if (typeof(TFeature) == typeof(IHttpConnectionFeature)) + { + _currentIHttpConnectionFeature = instance; + } + else if (typeof(TFeature) == typeof(IConnectionIdFeature)) + { + _currentIConnectionIdFeature = instance; + } + else if (typeof(TFeature) == typeof(IConnectionTransportFeature)) + { + _currentIConnectionTransportFeature = instance; + } + else + { + ExtraFeatureSet(typeof(TFeature), instance); + } } IEnumerator> IEnumerable>.GetEnumerator() => FastEnumerable().GetEnumerator(); IEnumerator IEnumerable.GetEnumerator() => FastEnumerable().GetEnumerator(); - private object FastFeatureGet(Type key) - { - if (key == IHttpConnectionFeatureType) - { - return _currentIHttpConnectionFeature; - } - - if (key == IConnectionIdFeatureType) - { - return _currentIConnectionIdFeature; - } - - if (key == IConnectionTransportFeatureType) - { - return _currentIConnectionTransportFeature; - } - - return ExtraFeatureGet(key); - } - - private void FastFeatureSet(Type key, object feature) - { - _featureRevision++; - - if (key == IHttpConnectionFeatureType) - { - _currentIHttpConnectionFeature = feature; - return; - } - - if (key == IConnectionIdFeatureType) - { - _currentIConnectionIdFeature = feature; - return; - } - - if (key == IConnectionTransportFeatureType) - { - _currentIConnectionTransportFeature = feature; - return; - } - - ExtraFeatureSet(key, feature); - } - private IEnumerable> FastEnumerable() { if (_currentIHttpConnectionFeature != null) diff --git a/test/Kestrel.Core.Tests/HttpProtocolFeatureCollectionTests.cs b/test/Kestrel.Core.Tests/HttpProtocolFeatureCollectionTests.cs new file mode 100644 index 0000000000..4167386340 --- /dev/null +++ b/test/Kestrel.Core.Tests/HttpProtocolFeatureCollectionTests.cs @@ -0,0 +1,224 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Buffers; +using System.IO.Pipelines; +using System.Linq; +using Microsoft.AspNetCore.Http.Features; +using Microsoft.AspNetCore.Server.Kestrel.Core.Features; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; +using Microsoft.AspNetCore.Testing; +using Moq; +using Xunit; + +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests +{ + public class HttpProtocolFeatureCollectionTests : IDisposable + { + private readonly IDuplexPipe _transport; + private readonly IDuplexPipe _application; + private readonly TestHttp1Connection _http1Connection; + private readonly ServiceContext _serviceContext; + private readonly Http1ConnectionContext _http1ConnectionContext; + private readonly MemoryPool _pipelineFactory; + private Mock _timeoutControl; + + private readonly IFeatureCollection _collection; + + public HttpProtocolFeatureCollectionTests() + { + _pipelineFactory = new MemoryPool(); + var pair = DuplexPipe.CreateConnectionPair(_pipelineFactory); + + _transport = pair.Transport; + _application = pair.Application; + + _serviceContext = new TestServiceContext(); + _timeoutControl = new Mock(); + _http1ConnectionContext = new Http1ConnectionContext + { + ServiceContext = _serviceContext, + ConnectionFeatures = new FeatureCollection(), + MemoryPool = _pipelineFactory, + TimeoutControl = _timeoutControl.Object, + Application = pair.Application, + Transport = pair.Transport + }; + + _http1Connection = new TestHttp1Connection(_http1ConnectionContext); + _http1Connection.Reset(); + _collection = _http1Connection; + } + + public void Dispose() + { + _transport.Input.Complete(); + _transport.Output.Complete(); + + _application.Input.Complete(); + _application.Output.Complete(); + + _pipelineFactory.Dispose(); + } + + [Fact] + public int FeaturesStartAsSelf() + { + var featureCount = 0; + foreach (var featureIter in _collection) + { + Type type = featureIter.Key; + if (type.IsAssignableFrom(typeof(HttpProtocol))) + { + var featureLookup = _collection[type]; + Assert.Same(featureLookup, featureIter.Value); + Assert.Same(featureLookup, _collection); + featureCount++; + } + } + + Assert.NotEqual(0, featureCount); + + return featureCount; + } + + [Fact] + public int FeaturesCanBeAssignedTo() + { + var featureCount = SetFeaturesToNonDefault(); + Assert.NotEqual(0, featureCount); + + featureCount = 0; + foreach (var feature in _collection) + { + Type type = feature.Key; + if (type.IsAssignableFrom(typeof(HttpProtocol))) + { + Assert.Same(_collection[type], feature.Value); + Assert.NotSame(_collection[type], _collection); + featureCount++; + } + } + + Assert.NotEqual(0, featureCount); + + return featureCount; + } + + [Fact] + public void FeaturesResetToSelf() + { + var featuresAssigned = SetFeaturesToNonDefault(); + _http1Connection.ResetFeatureCollection(); + var featuresReset = FeaturesStartAsSelf(); + + Assert.Equal(featuresAssigned, featuresReset); + } + + [Fact] + public void FeaturesByGenericSameAsByType() + { + var featuresAssigned = SetFeaturesToNonDefault(); + + CompareGenericGetterToIndexer(); + + _http1Connection.ResetFeatureCollection(); + var featuresReset = FeaturesStartAsSelf(); + + Assert.Equal(featuresAssigned, featuresReset); + } + + [Fact] + public void FeaturesSetByTypeSameAsGeneric() + { + _collection[typeof(IHttpRequestFeature)] = CreateHttp1Connection(); + _collection[typeof(IHttpResponseFeature)] = CreateHttp1Connection(); + _collection[typeof(IHttpRequestIdentifierFeature)] = CreateHttp1Connection(); + _collection[typeof(IHttpRequestLifetimeFeature)] = CreateHttp1Connection(); + _collection[typeof(IHttpConnectionFeature)] = CreateHttp1Connection(); + _collection[typeof(IHttpMaxRequestBodySizeFeature)] = CreateHttp1Connection(); + _collection[typeof(IHttpMinRequestBodyDataRateFeature)] = CreateHttp1Connection(); + _collection[typeof(IHttpMinResponseDataRateFeature)] = CreateHttp1Connection(); + _collection[typeof(IHttpBodyControlFeature)] = CreateHttp1Connection(); + + CompareGenericGetterToIndexer(); + + EachHttpProtocolFeatureSetAndUnique(); + } + + [Fact] + public void FeaturesSetByGenericSameAsByType() + { + _collection.Set(CreateHttp1Connection()); + _collection.Set(CreateHttp1Connection()); + _collection.Set(CreateHttp1Connection()); + _collection.Set(CreateHttp1Connection()); + _collection.Set(CreateHttp1Connection()); + _collection.Set(CreateHttp1Connection()); + _collection.Set(CreateHttp1Connection()); + _collection.Set(CreateHttp1Connection()); + _collection.Set(CreateHttp1Connection()); + + CompareGenericGetterToIndexer(); + + EachHttpProtocolFeatureSetAndUnique(); + } + + private void CompareGenericGetterToIndexer() + { + Assert.Same(_collection.Get(), _collection[typeof(IHttpRequestFeature)]); + Assert.Same(_collection.Get(), _collection[typeof(IHttpResponseFeature)]); + Assert.Same(_collection.Get(), _collection[typeof(IHttpRequestIdentifierFeature)]); + Assert.Same(_collection.Get(), _collection[typeof(IHttpRequestLifetimeFeature)]); + Assert.Same(_collection.Get(), _collection[typeof(IHttpConnectionFeature)]); + Assert.Same(_collection.Get(), _collection[typeof(IHttpMaxRequestBodySizeFeature)]); + Assert.Same(_collection.Get(), _collection[typeof(IHttpMinRequestBodyDataRateFeature)]); + Assert.Same(_collection.Get(), _collection[typeof(IHttpMinResponseDataRateFeature)]); + Assert.Same(_collection.Get(), _collection[typeof(IHttpBodyControlFeature)]); + } + + private int EachHttpProtocolFeatureSetAndUnique() + { + int featureCount = 0; + foreach (var item in _collection) + { + Type type = item.Key; + if (type.IsAssignableFrom(typeof(HttpProtocol))) + { + Assert.Equal(1, _collection.Count(kv => ReferenceEquals(kv.Value, item.Value))); + + featureCount++; + } + } + + Assert.NotEqual(0, featureCount); + + return featureCount; + } + + private int SetFeaturesToNonDefault() + { + int featureCount = 0; + foreach (var feature in _collection) + { + Type type = feature.Key; + if (type.IsAssignableFrom(typeof(HttpProtocol))) + { + _collection[type] = CreateHttp1Connection(); + featureCount++; + } + } + + var protocolFeaturesCount = EachHttpProtocolFeatureSetAndUnique(); + + Assert.Equal(protocolFeaturesCount, featureCount); + + return featureCount; + } + + private HttpProtocol CreateHttp1Connection() => new TestHttp1Connection(_http1ConnectionContext); + } +} diff --git a/tools/CodeGenerator/HttpProtocolFeatureCollection.cs b/tools/CodeGenerator/HttpProtocolFeatureCollection.cs index 3865658e70..db6508080e 100644 --- a/tools/CodeGenerator/HttpProtocolFeatureCollection.cs +++ b/tools/CodeGenerator/HttpProtocolFeatureCollection.cs @@ -16,6 +16,12 @@ namespace CodeGenerator return values.Select(formatter).Aggregate((a, b) => a + b); } + public class KnownFeature + { + public string Name; + public int Index; + } + public static string GeneratedFile(string className) { var alwaysFeatures = new[] @@ -55,7 +61,15 @@ namespace CodeGenerator "IHttpSendFileFeature", }; - var allFeatures = alwaysFeatures.Concat(commonFeatures).Concat(sometimesFeatures).Concat(rareFeatures); + var allFeatures = alwaysFeatures + .Concat(commonFeatures) + .Concat(sometimesFeatures) + .Concat(rareFeatures) + .Select((type, index) => new KnownFeature + { + Name = type, + Index = index + }); // NOTE: This list MUST always match the set of feature interfaces implemented by HttpProtocol. // See also: src/Kestrel/Http/HttpProtocol.FeatureCollection.cs @@ -86,43 +100,87 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http {{ public partial class {className} {{{Each(allFeatures, feature => $@" - private static readonly Type {feature}Type = typeof({feature});")} + private static readonly Type {feature.Name}Type = typeof({feature.Name});")} {Each(allFeatures, feature => $@" - private object _current{feature};")} + private object _current{feature.Name};")} private void FastReset() {{{Each(implementedFeatures, feature => $@" _current{feature} = this;")} - {Each(allFeatures.Where(f => !implementedFeatures.Contains(f)), feature => $@" - _current{feature} = null;")} + {Each(allFeatures.Where(f => !implementedFeatures.Contains(f.Name)), feature => $@" + _current{feature.Name} = null;")} }} - internal object FastFeatureGet(Type key) - {{{Each(allFeatures, feature => $@" - if (key == {feature}Type) - {{ - return _current{feature}; - }}")} - return ExtraFeatureGet(key); - }} - - protected void FastFeatureSet(Type key, object feature) + object IFeatureCollection.this[Type key] {{ - _featureRevision++; - {Each(allFeatures, feature => $@" - if (key == {feature}Type) + get {{ - _current{feature} = feature; - return; - }}")}; - ExtraFeatureSet(key, feature); + object feature = null;{Each(allFeatures, feature => $@" + {(feature.Index != 0 ? "else " : "")}if (key == {feature.Name}Type) + {{ + feature = _current{feature.Name}; + }}")} + else if (MaybeExtra != null) + {{ + feature = ExtraFeatureGet(key); + }} + + return feature ?? ConnectionFeatures[key]; + }} + + set + {{ + _featureRevision++; + {Each(allFeatures, feature => $@" + {(feature.Index != 0 ? "else " : "")}if (key == {feature.Name}Type) + {{ + _current{feature.Name} = value; + }}")} + else + {{ + ExtraFeatureSet(key, value); + }} + }} + }} + + void IFeatureCollection.Set(TFeature feature) + {{ + _featureRevision++;{Each(allFeatures, feature => $@" + {(feature.Index != 0 ? "else " : "")}if (typeof(TFeature) == typeof({feature.Name})) + {{ + _current{feature.Name} = feature; + }}")} + else + {{ + ExtraFeatureSet(typeof(TFeature), feature); + }} + }} + + TFeature IFeatureCollection.Get() + {{ + TFeature feature = default;{Each(allFeatures, feature => $@" + {(feature.Index != 0 ? "else " : "")}if (typeof(TFeature) == typeof({feature.Name})) + {{ + feature = (TFeature)_current{feature.Name}; + }}")} + else if (MaybeExtra != null) + {{ + feature = (TFeature)(ExtraFeatureGet(typeof(TFeature))); + }} + + if (feature == null) + {{ + feature = ConnectionFeatures.Get(); + }} + + return feature; }} private IEnumerable> FastEnumerable() {{{Each(allFeatures, feature => $@" - if (_current{feature} != null) + if (_current{feature.Name} != null) {{ - yield return new KeyValuePair({feature}Type, _current{feature} as {feature}); + yield return new KeyValuePair({feature.Name}Type, _current{feature.Name} as {feature.Name}); }}")} if (MaybeExtra != null) From c57784447edcf0f9de2c1d88d4cc0d6bc863c45d Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Fri, 23 Feb 2018 00:45:31 +0000 Subject: [PATCH 1537/1662] Speed up TryGetAsciiString (#1973) * Widen * Remove TryGetAsciiStringVectorCheckShifts * Add Span version to benchmarks --- .../AsciiBytesToStringBenchmark.cs | 623 ++++++++++++++++++ .../Infrastructure/StringUtilities.cs | 183 +++-- test/Kestrel.Core.Tests/AsciiDecoding.cs | 21 +- 3 files changed, 763 insertions(+), 64 deletions(-) create mode 100644 benchmarks/Kestrel.Performance/AsciiBytesToStringBenchmark.cs diff --git a/benchmarks/Kestrel.Performance/AsciiBytesToStringBenchmark.cs b/benchmarks/Kestrel.Performance/AsciiBytesToStringBenchmark.cs new file mode 100644 index 0000000000..173b7260e5 --- /dev/null +++ b/benchmarks/Kestrel.Performance/AsciiBytesToStringBenchmark.cs @@ -0,0 +1,623 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using BenchmarkDotNet.Attributes; +using System; +using System.Collections.Generic; +using System.Numerics; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using System.Text; + +namespace Microsoft.AspNetCore.Server.Kestrel.Performance +{ + public class AsciiBytesToStringBenchmark + { + private const int Iterations = 100; + + private byte[] _asciiBytes; + private string _asciiString = new string('\0', 1024); + + [Params( + BenchmarkTypes.KeepAlive, + BenchmarkTypes.Accept, + BenchmarkTypes.UserAgent, + BenchmarkTypes.Cookie + )] + public BenchmarkTypes Type { get; set; } + + [GlobalSetup] + public void Setup() + { + switch (Type) + { + case BenchmarkTypes.KeepAlive: + _asciiBytes = Encoding.ASCII.GetBytes("keep-alive"); + break; + case BenchmarkTypes.Accept: + _asciiBytes = Encoding.ASCII.GetBytes("text/plain,text/html;q=0.9,application/xhtml+xml;q=0.9,application/xml;q=0.8,*/*;q=0.7"); + break; + case BenchmarkTypes.UserAgent: + _asciiBytes = Encoding.ASCII.GetBytes("Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.99 Safari/537.36"); + break; + case BenchmarkTypes.Cookie: + _asciiBytes = Encoding.ASCII.GetBytes("prov=20629ccd-8b0f-e8ef-2935-cd26609fc0bc; __qca=P0-1591065732-1479167353442; _ga=GA1.2.1298898376.1479167354; _gat=1; sgt=id=9519gfde_3347_4762_8762_df51458c8ec2; acct=t=why-is-%e0%a5%a7%e0%a5%a8%e0%a5%a9-numeric&s=why-is-%e0%a5%a7%e0%a5%a8%e0%a5%a9-numeric"); + break; + } + + Verify(); + } + + [Benchmark(OperationsPerInvoke = Iterations)] + public unsafe string EncodingAsciiGetChars() + { + for (uint i = 0; i < Iterations; i++) + { + fixed (byte* pBytes = &_asciiBytes[0]) + fixed (char* pString = _asciiString) + { + Encoding.ASCII.GetChars(pBytes, _asciiBytes.Length, pString, _asciiBytes.Length); + } + } + + return _asciiString; + } + + [Benchmark(Baseline = true, OperationsPerInvoke = Iterations)] + public unsafe byte[] KestrelBytesToString() + { + for (uint i = 0; i < Iterations; i++) + { + fixed (byte* pBytes = &_asciiBytes[0]) + fixed (char* pString = _asciiString) + { + TryGetAsciiString(pBytes, pString, _asciiBytes.Length); + } + } + + return _asciiBytes; + } + + [Benchmark(OperationsPerInvoke = Iterations)] + public unsafe byte[] AsciiBytesToStringVectorCheck() + { + for (uint i = 0; i < Iterations; i++) + { + fixed (byte* pBytes = &_asciiBytes[0]) + fixed (char* pString = _asciiString) + { + TryGetAsciiStringVectorCheck(pBytes, pString, _asciiBytes.Length); + } + } + + return _asciiBytes; + } + + [Benchmark(OperationsPerInvoke = Iterations)] + public unsafe byte[] AsciiBytesToStringVectorWiden() + { + // Widen Acceleration is post netcoreapp2.0 + for (uint i = 0; i < Iterations; i++) + { + fixed (byte* pBytes = &_asciiBytes[0]) + fixed (char* pString = _asciiString) + { + TryGetAsciiStringVectorWiden(pBytes, pString, _asciiBytes.Length); + } + } + + return _asciiBytes; + } + + [Benchmark(OperationsPerInvoke = Iterations)] + public unsafe byte[] AsciiBytesToStringSpanWiden() + { + // Widen Acceleration is post netcoreapp2.0 + for (uint i = 0; i < Iterations; i++) + { + fixed (char* pString = _asciiString) + { + TryGetAsciiStringWidenSpan(_asciiBytes, new Span(pString, _asciiString.Length)); + } + } + + return _asciiBytes; + } + + public static bool TryGetAsciiStringWidenSpan(ReadOnlySpan input, Span output) + { + // Start as valid + var isValid = true; + + do + { + // If Vector not-accelerated or remaining less than vector size + if (!Vector.IsHardwareAccelerated || input.Length < Vector.Count) + { + if (IntPtr.Size == 8) // Use Intrinsic switch for branch elimination + { + // 64-bit: Loop longs by default + while ((uint)sizeof(long) <= (uint)input.Length) + { + isValid &= CheckBytesInAsciiRange(MemoryMarshal.Cast(input)[0]); + + output[0] = (char)input[0]; + output[1] = (char)input[1]; + output[2] = (char)input[2]; + output[3] = (char)input[3]; + output[4] = (char)input[4]; + output[5] = (char)input[5]; + output[6] = (char)input[6]; + output[7] = (char)input[7]; + + input = input.Slice(sizeof(long)); + output = output.Slice(sizeof(long)); + } + if ((uint)sizeof(int) <= (uint)input.Length) + { + isValid &= CheckBytesInAsciiRange(MemoryMarshal.Cast(input)[0]); + + output[0] = (char)input[0]; + output[1] = (char)input[1]; + output[2] = (char)input[2]; + output[3] = (char)input[3]; + + input = input.Slice(sizeof(int)); + output = output.Slice(sizeof(int)); + } + } + else + { + // 32-bit: Loop ints by default + while ((uint)sizeof(int) <= (uint)input.Length) + { + isValid &= CheckBytesInAsciiRange(MemoryMarshal.Cast(input)[0]); + + output[0] = (char)input[0]; + output[1] = (char)input[1]; + output[2] = (char)input[2]; + output[3] = (char)input[3]; + + input = input.Slice(sizeof(int)); + output = output.Slice(sizeof(int)); + } + } + if ((uint)sizeof(short) <= (uint)input.Length) + { + isValid &= CheckBytesInAsciiRange(MemoryMarshal.Cast(input)[0]); + + output[0] = (char)input[0]; + output[1] = (char)input[1]; + + input = input.Slice(sizeof(short)); + output = output.Slice(sizeof(short)); + } + if ((uint)sizeof(byte) <= (uint)input.Length) + { + isValid &= CheckBytesInAsciiRange((sbyte)input[0]); + output[0] = (char)input[0]; + } + + return isValid; + } + + // do/while as entry condition already checked + do + { + var vector = MemoryMarshal.Cast>(input)[0]; + isValid &= CheckBytesInAsciiRange(vector); + Vector.Widen( + vector, + out MemoryMarshal.Cast>(output)[0], + out MemoryMarshal.Cast>(output)[1]); + + input = input.Slice(Vector.Count); + output = output.Slice(Vector.Count); + } while (input.Length >= Vector.Count); + + // Vector path done, loop back to do non-Vector + // If is a exact multiple of vector size, bail now + } while (input.Length > 0); + + return isValid; + } + + public static unsafe bool TryGetAsciiStringVectorWiden(byte* input, char* output, int count) + { + // Calcuate end position + var end = input + count; + // Start as valid + var isValid = true; + + do + { + // If Vector not-accelerated or remaining less than vector size + if (!Vector.IsHardwareAccelerated || input > end - Vector.Count) + { + if (IntPtr.Size == 8) // Use Intrinsic switch for branch elimination + { + // 64-bit: Loop longs by default + while (input <= end - sizeof(long)) + { + isValid &= CheckBytesInAsciiRange(((long*)input)[0]); + + output[0] = (char)input[0]; + output[1] = (char)input[1]; + output[2] = (char)input[2]; + output[3] = (char)input[3]; + output[4] = (char)input[4]; + output[5] = (char)input[5]; + output[6] = (char)input[6]; + output[7] = (char)input[7]; + + input += sizeof(long); + output += sizeof(long); + } + if (input <= end - sizeof(int)) + { + isValid &= CheckBytesInAsciiRange(((int*)input)[0]); + + output[0] = (char)input[0]; + output[1] = (char)input[1]; + output[2] = (char)input[2]; + output[3] = (char)input[3]; + + input += sizeof(int); + output += sizeof(int); + } + } + else + { + // 32-bit: Loop ints by default + while (input <= end - sizeof(int)) + { + isValid &= CheckBytesInAsciiRange(((int*)input)[0]); + + output[0] = (char)input[0]; + output[1] = (char)input[1]; + output[2] = (char)input[2]; + output[3] = (char)input[3]; + + input += sizeof(int); + output += sizeof(int); + } + } + if (input <= end - sizeof(short)) + { + isValid &= CheckBytesInAsciiRange(((short*)input)[0]); + + output[0] = (char)input[0]; + output[1] = (char)input[1]; + + input += sizeof(short); + output += sizeof(short); + } + if (input < end) + { + isValid &= CheckBytesInAsciiRange(((sbyte*)input)[0]); + output[0] = (char)input[0]; + } + + return isValid; + } + + // do/while as entry condition already checked + do + { + var vector = Unsafe.AsRef>(input); + isValid &= CheckBytesInAsciiRange(vector); + Vector.Widen( + vector, + out Unsafe.AsRef>(output), + out Unsafe.AsRef>(output + Vector.Count)); + + input += Vector.Count; + output += Vector.Count; + } while (input <= end - Vector.Count); + + // Vector path done, loop back to do non-Vector + // If is a exact multiple of vector size, bail now + } while (input < end); + + return isValid; + } + + public static unsafe bool TryGetAsciiStringVectorCheck(byte* input, char* output, int count) + { + // Calcuate end position + var end = input + count; + // Start as valid + var isValid = true; + do + { + // If Vector not-accelerated or remaining less than vector size + if (!Vector.IsHardwareAccelerated || input > end - Vector.Count) + { + if (IntPtr.Size == 8) // Use Intrinsic switch for branch elimination + { + // 64-bit: Loop longs by default + while (input <= end - sizeof(long)) + { + isValid &= CheckBytesInAsciiRange(((long*)input)[0]); + + output[0] = (char)input[0]; + output[1] = (char)input[1]; + output[2] = (char)input[2]; + output[3] = (char)input[3]; + output[4] = (char)input[4]; + output[5] = (char)input[5]; + output[6] = (char)input[6]; + output[7] = (char)input[7]; + + input += sizeof(long); + output += sizeof(long); + } + if (input <= end - sizeof(int)) + { + isValid &= CheckBytesInAsciiRange(((int*)input)[0]); + + output[0] = (char)input[0]; + output[1] = (char)input[1]; + output[2] = (char)input[2]; + output[3] = (char)input[3]; + + input += sizeof(int); + output += sizeof(int); + } + } + else + { + // 32-bit: Loop ints by default + while (input <= end - sizeof(int)) + { + isValid &= CheckBytesInAsciiRange(((int*)input)[0]); + + output[0] = (char)input[0]; + output[1] = (char)input[1]; + output[2] = (char)input[2]; + output[3] = (char)input[3]; + + input += sizeof(int); + output += sizeof(int); + } + } + if (input <= end - sizeof(short)) + { + isValid &= CheckBytesInAsciiRange(((short*)input)[0]); + + output[0] = (char)input[0]; + output[1] = (char)input[1]; + + input += sizeof(short); + output += sizeof(short); + } + if (input < end) + { + isValid &= CheckBytesInAsciiRange(((sbyte*)input)[0]); + output[0] = (char)input[0]; + } + + return isValid; + } + + // do/while as entry condition already checked + do + { + isValid &= CheckBytesInAsciiRange(Unsafe.AsRef>(input)); + + // Vector.Widen is only netcoreapp2.1+ so let's do this manually + var i = 0; + do + { + // Vectors are min 16 byte, so lets do 16 byte loops + i += 16; + // Unrolled byte-wise widen + output[0] = (char)input[0]; + output[1] = (char)input[1]; + output[2] = (char)input[2]; + output[3] = (char)input[3]; + output[4] = (char)input[4]; + output[5] = (char)input[5]; + output[6] = (char)input[6]; + output[7] = (char)input[7]; + output[8] = (char)input[8]; + output[9] = (char)input[9]; + output[10] = (char)input[10]; + output[11] = (char)input[11]; + output[12] = (char)input[12]; + output[13] = (char)input[13]; + output[14] = (char)input[14]; + output[15] = (char)input[15]; + + input += 16; + output += 16; + } while (i < Vector.Count); + } while (input <= end - Vector.Count); + + // Vector path done, loop back to do non-Vector + // If is a exact multiple of vector size, bail now + } while (input < end); + + return isValid; + } + + public static unsafe bool TryGetAsciiString(byte* input, char* output, int count) + { + var i = 0; + sbyte* signedInput = (sbyte*)input; + + bool isValid = true; + while (i < count - 11) + { + isValid = isValid && *signedInput > 0 && *(signedInput + 1) > 0 && *(signedInput + 2) > 0 && + *(signedInput + 3) > 0 && *(signedInput + 4) > 0 && *(signedInput + 5) > 0 && *(signedInput + 6) > 0 && + *(signedInput + 7) > 0 && *(signedInput + 8) > 0 && *(signedInput + 9) > 0 && *(signedInput + 10) > 0 && + *(signedInput + 11) > 0; + + i += 12; + *(output) = (char)*(signedInput); + *(output + 1) = (char)*(signedInput + 1); + *(output + 2) = (char)*(signedInput + 2); + *(output + 3) = (char)*(signedInput + 3); + *(output + 4) = (char)*(signedInput + 4); + *(output + 5) = (char)*(signedInput + 5); + *(output + 6) = (char)*(signedInput + 6); + *(output + 7) = (char)*(signedInput + 7); + *(output + 8) = (char)*(signedInput + 8); + *(output + 9) = (char)*(signedInput + 9); + *(output + 10) = (char)*(signedInput + 10); + *(output + 11) = (char)*(signedInput + 11); + output += 12; + signedInput += 12; + } + if (i < count - 5) + { + isValid = isValid && *signedInput > 0 && *(signedInput + 1) > 0 && *(signedInput + 2) > 0 && + *(signedInput + 3) > 0 && *(signedInput + 4) > 0 && *(signedInput + 5) > 0; + + i += 6; + *(output) = (char)*(signedInput); + *(output + 1) = (char)*(signedInput + 1); + *(output + 2) = (char)*(signedInput + 2); + *(output + 3) = (char)*(signedInput + 3); + *(output + 4) = (char)*(signedInput + 4); + *(output + 5) = (char)*(signedInput + 5); + output += 6; + signedInput += 6; + } + if (i < count - 3) + { + isValid = isValid && *signedInput > 0 && *(signedInput + 1) > 0 && *(signedInput + 2) > 0 && + *(signedInput + 3) > 0; + + i += 4; + *(output) = (char)*(signedInput); + *(output + 1) = (char)*(signedInput + 1); + *(output + 2) = (char)*(signedInput + 2); + *(output + 3) = (char)*(signedInput + 3); + output += 4; + signedInput += 4; + } + + while (i < count) + { + isValid = isValid && *signedInput > 0; + + i++; + *output = (char)*signedInput; + output++; + signedInput++; + } + + return isValid; + } + + private static bool CheckBytesInAsciiRange(Vector check) + { + // Vectorized byte range check, signed byte > 0 for 1-127 + return Vector.GreaterThanAll(check, Vector.Zero); + } + + // Validate: bytes != 0 && bytes <= 127 + // Subtract 1 from all bytes to move 0 to high bits + // bitwise or with self to catch all > 127 bytes + // mask off high bits and check if 0 + + [MethodImpl(MethodImplOptions.AggressiveInlining)] // Needs a push + private static bool CheckBytesInAsciiRange(long check) + { + const long HighBits = unchecked((long)0x8080808080808080L); + return (((check - 0x0101010101010101L) | check) & HighBits) == 0; + } + + private static bool CheckBytesInAsciiRange(int check) + { + const int HighBits = unchecked((int)0x80808080); + return (((check - 0x01010101) | check) & HighBits) == 0; + } + + private static bool CheckBytesInAsciiRange(short check) + { + const short HighBits = unchecked((short)0x8080); + return (((short)(check - 0x0101) | check) & HighBits) == 0; + } + + private static bool CheckBytesInAsciiRange(sbyte check) + => check > 0; + + private void Verify() + { + var verification = EncodingAsciiGetChars().Substring(0, _asciiBytes.Length); + + BlankString('\0'); + EncodingAsciiGetChars(); + VerifyString(verification, '\0'); + BlankString(' '); + EncodingAsciiGetChars(); + VerifyString(verification, ' '); + + BlankString('\0'); + KestrelBytesToString(); + VerifyString(verification, '\0'); + BlankString(' '); + KestrelBytesToString(); + VerifyString(verification, ' '); + + BlankString('\0'); + AsciiBytesToStringVectorCheck(); + VerifyString(verification, '\0'); + BlankString(' '); + AsciiBytesToStringVectorCheck(); + VerifyString(verification, ' '); + + BlankString('\0'); + AsciiBytesToStringVectorWiden(); + VerifyString(verification, '\0'); + BlankString(' '); + AsciiBytesToStringVectorWiden(); + VerifyString(verification, ' '); + + BlankString('\0'); + AsciiBytesToStringSpanWiden(); + VerifyString(verification, '\0'); + BlankString(' '); + AsciiBytesToStringSpanWiden(); + VerifyString(verification, ' '); + } + + private unsafe void BlankString(char ch) + { + fixed (char* pString = _asciiString) + { + for (var i = 0; i < _asciiString.Length; i++) + { + *(pString + i) = ch; + } + } + } + + private unsafe void VerifyString(string verification, char ch) + { + fixed (char* pString = _asciiString) + { + var i = 0; + for (; i < verification.Length; i++) + { + if (*(pString + i) != verification[i]) throw new Exception($"Verify failed, saw {(int)*(pString + i)} expected {(int)verification[i]} at position {i}"); + } + for (; i < _asciiString.Length; i++) + { + if (*(pString + i) != ch) throw new Exception($"Verify failed, saw {(int)*(pString + i)} expected {(int)ch} at position {i}"); ; + } + } + } + + public enum BenchmarkTypes + { + KeepAlive, + Accept, + UserAgent, + Cookie, + } + } +} diff --git a/src/Kestrel.Core/Internal/Infrastructure/StringUtilities.cs b/src/Kestrel.Core/Internal/Infrastructure/StringUtilities.cs index ab9ce0683c..76c4a8576e 100644 --- a/src/Kestrel.Core/Internal/Infrastructure/StringUtilities.cs +++ b/src/Kestrel.Core/Internal/Infrastructure/StringUtilities.cs @@ -1,77 +1,110 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; +using System.Numerics; +using System.Runtime.CompilerServices; + namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure { internal class StringUtilities { public static unsafe bool TryGetAsciiString(byte* input, char* output, int count) { - var i = 0; - sbyte* signedInput = (sbyte*)input; + // Calcuate end position + var end = input + count; + // Start as valid + var isValid = true; - bool isValid = true; - while (i < count - 11) + do { - isValid = isValid && *signedInput > 0 && *(signedInput + 1) > 0 && *(signedInput + 2) > 0 && - *(signedInput + 3) > 0 && *(signedInput + 4) > 0 && *(signedInput + 5) > 0 && *(signedInput + 6) > 0 && - *(signedInput + 7) > 0 && *(signedInput + 8) > 0 && *(signedInput + 9) > 0 && *(signedInput + 10) > 0 && - *(signedInput + 11) > 0; + // If Vector not-accelerated or remaining less than vector size + if (!Vector.IsHardwareAccelerated || input > end - Vector.Count) + { + if (IntPtr.Size == 8) // Use Intrinsic switch for branch elimination + { + // 64-bit: Loop longs by default + while (input <= end - sizeof(long)) + { + isValid &= CheckBytesInAsciiRange(((long*)input)[0]); - i += 12; - *(output) = (char)*(signedInput); - *(output + 1) = (char)*(signedInput + 1); - *(output + 2) = (char)*(signedInput + 2); - *(output + 3) = (char)*(signedInput + 3); - *(output + 4) = (char)*(signedInput + 4); - *(output + 5) = (char)*(signedInput + 5); - *(output + 6) = (char)*(signedInput + 6); - *(output + 7) = (char)*(signedInput + 7); - *(output + 8) = (char)*(signedInput + 8); - *(output + 9) = (char)*(signedInput + 9); - *(output + 10) = (char)*(signedInput + 10); - *(output + 11) = (char)*(signedInput + 11); - output += 12; - signedInput += 12; - } - if (i < count - 5) - { - isValid = isValid && *signedInput > 0 && *(signedInput + 1) > 0 && *(signedInput + 2) > 0 && - *(signedInput + 3) > 0 && *(signedInput + 4) > 0 && *(signedInput + 5) > 0; + output[0] = (char)input[0]; + output[1] = (char)input[1]; + output[2] = (char)input[2]; + output[3] = (char)input[3]; + output[4] = (char)input[4]; + output[5] = (char)input[5]; + output[6] = (char)input[6]; + output[7] = (char)input[7]; - i += 6; - *(output) = (char)*(signedInput); - *(output + 1) = (char)*(signedInput + 1); - *(output + 2) = (char)*(signedInput + 2); - *(output + 3) = (char)*(signedInput + 3); - *(output + 4) = (char)*(signedInput + 4); - *(output + 5) = (char)*(signedInput + 5); - output += 6; - signedInput += 6; - } - if (i < count - 3) - { - isValid = isValid && *signedInput > 0 && *(signedInput + 1) > 0 && *(signedInput + 2) > 0 && - *(signedInput + 3) > 0; + input += sizeof(long); + output += sizeof(long); + } + if (input <= end - sizeof(int)) + { + isValid &= CheckBytesInAsciiRange(((int*)input)[0]); - i += 4; - *(output) = (char)*(signedInput); - *(output + 1) = (char)*(signedInput + 1); - *(output + 2) = (char)*(signedInput + 2); - *(output + 3) = (char)*(signedInput + 3); - output += 4; - signedInput += 4; - } + output[0] = (char)input[0]; + output[1] = (char)input[1]; + output[2] = (char)input[2]; + output[3] = (char)input[3]; - while (i < count) - { - isValid = isValid && *signedInput > 0; + input += sizeof(int); + output += sizeof(int); + } + } + else + { + // 32-bit: Loop ints by default + while (input <= end - sizeof(int)) + { + isValid &= CheckBytesInAsciiRange(((int*)input)[0]); - i++; - *output = (char)*signedInput; - output++; - signedInput++; - } + output[0] = (char)input[0]; + output[1] = (char)input[1]; + output[2] = (char)input[2]; + output[3] = (char)input[3]; + + input += sizeof(int); + output += sizeof(int); + } + } + if (input <= end - sizeof(short)) + { + isValid &= CheckBytesInAsciiRange(((short*)input)[0]); + + output[0] = (char)input[0]; + output[1] = (char)input[1]; + + input += sizeof(short); + output += sizeof(short); + } + if (input < end) + { + isValid &= CheckBytesInAsciiRange(((sbyte*)input)[0]); + output[0] = (char)input[0]; + } + + return isValid; + } + + // do/while as entry condition already checked + do + { + var vector = Unsafe.AsRef>(input); + isValid &= CheckBytesInAsciiRange(vector); + Vector.Widen( + vector, + out Unsafe.AsRef>(output), + out Unsafe.AsRef>(output + Vector.Count)); + + input += Vector.Count; + output += Vector.Count; + } while (input <= end - Vector.Count); + + // Vector path done, loop back to do non-Vector + // If is a exact multiple of vector size, bail now + } while (input < end); return isValid; } @@ -119,5 +152,39 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure // string ctor overload that takes char* return new string(charBuffer, 0, length); } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] // Needs a push + private static bool CheckBytesInAsciiRange(Vector check) + { + // Vectorized byte range check, signed byte > 0 for 1-127 + return Vector.GreaterThanAll(check, Vector.Zero); + } + + // Validate: bytes != 0 && bytes <= 127 + // Subtract 1 from all bytes to move 0 to high bits + // bitwise or with self to catch all > 127 bytes + // mask off high bits and check if 0 + + [MethodImpl(MethodImplOptions.AggressiveInlining)] // Needs a push + private static bool CheckBytesInAsciiRange(long check) + { + const long HighBits = unchecked((long)0x8080808080808080L); + return (((check - 0x0101010101010101L) | check) & HighBits) == 0; + } + + private static bool CheckBytesInAsciiRange(int check) + { + const int HighBits = unchecked((int)0x80808080); + return (((check - 0x01010101) | check) & HighBits) == 0; + } + + private static bool CheckBytesInAsciiRange(short check) + { + const short HighBits = unchecked((short)0x8080); + return (((short)(check - 0x0101) | check) & HighBits) == 0; + } + + private static bool CheckBytesInAsciiRange(sbyte check) + => check > 0; } } diff --git a/test/Kestrel.Core.Tests/AsciiDecoding.cs b/test/Kestrel.Core.Tests/AsciiDecoding.cs index ba61f1bad2..8f593f9671 100644 --- a/test/Kestrel.Core.Tests/AsciiDecoding.cs +++ b/test/Kestrel.Core.Tests/AsciiDecoding.cs @@ -13,15 +13,24 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests [Fact] private void FullAsciiRangeSupported() { - var byteRange = Enumerable.Range(1, 127).Select(x => (byte)x).ToArray(); - var s = new Span(byteRange).GetAsciiStringNonNullCharacters(); + var byteRange = Enumerable.Range(1, 127).Select(x => (byte)x); - Assert.Equal(s.Length, byteRange.Length); + var byteArray = byteRange + .Concat(byteRange) + .Concat(byteRange) + .Concat(byteRange) + .Concat(byteRange) + .Concat(byteRange) + .ToArray(); - for (var i = 1; i < byteRange.Length; i++) + var s = new Span(byteArray).GetAsciiStringNonNullCharacters(); + + Assert.Equal(s.Length, byteArray.Length); + + for (var i = 1; i < byteArray.Length; i++) { var sb = (byte)s[i]; - var b = byteRange[i]; + var b = byteArray[i]; Assert.Equal(sb, b); } @@ -32,7 +41,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests [InlineData(0x80)] private void ExceptionThrownForZeroOrNonAscii(byte b) { - for (var length = 1; length < 16; length++) + for (var length = 1; length < 1024; length++) { for (var position = 0; position < length; position++) { From 6252ffd86a7e289104d08965670785a57ac46fb6 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Fri, 23 Feb 2018 00:46:18 +0000 Subject: [PATCH 1538/1662] Flatten exception handling (#2313) 3 nested try blocks with 3 finallies in same function O_o --- .../Internal/Http/HttpProtocol.cs | 286 ++++++++++-------- 1 file changed, 152 insertions(+), 134 deletions(-) diff --git a/src/Kestrel.Core/Internal/Http/HttpProtocol.cs b/src/Kestrel.Core/Internal/Http/HttpProtocol.cs index 45bfa675ca..c5cef990ee 100644 --- a/src/Kestrel.Core/Internal/Http/HttpProtocol.cs +++ b/src/Kestrel.Core/Internal/Http/HttpProtocol.cs @@ -46,7 +46,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http private CancellationToken? _manuallySetRequestAbortToken; protected RequestProcessingStatus _requestProcessingStatus; - protected volatile bool _keepAlive = true; // volatile, see: https://msdn.microsoft.com/en-us/library/x13ttww7.aspx + protected volatile bool _keepAlive; // volatile, see: https://msdn.microsoft.com/en-us/library/x13ttww7.aspx protected bool _upgradeAvailable; private bool _canHaveBody; private bool _autoChunk; @@ -440,139 +440,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { try { - while (_keepAlive) - { - BeginRequestProcessing(); - - var result = default(ReadResult); - var endConnection = false; - do - { - if (BeginRead(out var awaitable)) - { - result = await awaitable; - } - } while (!TryParseRequest(result, out endConnection)); - - if (endConnection) - { - return; - } - - var messageBody = CreateMessageBody(); - - if (!messageBody.RequestKeepAlive) - { - _keepAlive = false; - } - - _upgradeAvailable = messageBody.RequestUpgrade; - - InitializeStreams(messageBody); - - var httpContext = application.CreateContext(this); - - try - { - try - { - KestrelEventSource.Log.RequestStart(this); - - await application.ProcessRequestAsync(httpContext); - - if (_requestAborted == 0) - { - VerifyResponseContentLength(); - } - } - catch (Exception ex) - { - ReportApplicationError(ex); - - if (ex is BadHttpRequestException) - { - throw; - } - } - finally - { - KestrelEventSource.Log.RequestStop(this); - - // Trigger OnStarting if it hasn't been called yet and the app hasn't - // already failed. If an OnStarting callback throws we can go through - // our normal error handling in ProduceEnd. - // https://github.com/aspnet/KestrelHttpServer/issues/43 - if (!HasResponseStarted && _applicationException == null && _onStarting != null) - { - await FireOnStarting(); - } - - PauseStreams(); - - if (_onCompleted != null) - { - await FireOnCompleted(); - } - } - - // If _requestAbort is set, the connection has already been closed. - if (_requestAborted == 0) - { - // Call ProduceEnd() before consuming the rest of the request body to prevent - // delaying clients waiting for the chunk terminator: - // - // https://github.com/dotnet/corefx/issues/17330#issuecomment-288248663 - // - // This also prevents the 100 Continue response from being sent if the app - // never tried to read the body. - // https://github.com/aspnet/KestrelHttpServer/issues/2102 - // - // ProduceEnd() must be called before _application.DisposeContext(), to ensure - // HttpContext.Response.StatusCode is correctly set when - // IHttpContextFactory.Dispose(HttpContext) is called. - await ProduceEnd(); - - // ForZeroContentLength does not complete the reader nor the writer - if (!messageBody.IsEmpty) - { - // Finish reading the request body in case the app did not. - await messageBody.ConsumeAsync(); - } - } - else if (!HasResponseStarted) - { - // If the request was aborted and no response was sent, there's no - // meaningful status code to log. - StatusCode = 0; - } - } - catch (BadHttpRequestException ex) - { - // Handle BadHttpRequestException thrown during app execution or remaining message body consumption. - // This has to be caught here so StatusCode is set properly before disposing the HttpContext - // (DisposeContext logs StatusCode). - SetBadRequestState(ex); - } - finally - { - application.DisposeContext(httpContext, _applicationException); - - // StopStreams should be called before the end of the "if (!_requestProcessingStopping)" block - // to ensure InitializeStreams has been called. - StopStreams(); - - if (HasStartedConsumingRequestBody) - { - RequestBodyPipe.Reader.Complete(); - - // Wait for MessageBody.PumpAsync() to call RequestBodyPipe.Writer.Complete(). - await messageBody.StopAsync(); - - // At this point both the request body pipe reader and writer should be completed. - RequestBodyPipe.Reset(); - } - } - } + await ProcessRequests(application); } catch (BadHttpRequestException ex) { @@ -615,6 +483,156 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http } } + private async Task ProcessRequests(IHttpApplication application) + { + // Keep-alive is default for HTTP/1.1 and HTTP/2; parsing and errors will change its value + _keepAlive = true; + do + { + BeginRequestProcessing(); + + var result = default(ReadResult); + var endConnection = false; + do + { + if (BeginRead(out var awaitable)) + { + result = await awaitable; + } + } while (!TryParseRequest(result, out endConnection)); + + if (endConnection) + { + // Connection finished, stop processing requests + return; + } + + var messageBody = CreateMessageBody(); + if (!messageBody.RequestKeepAlive) + { + _keepAlive = false; + } + + _upgradeAvailable = messageBody.RequestUpgrade; + + InitializeStreams(messageBody); + + var httpContext = application.CreateContext(this); + + BadHttpRequestException badRequestException = null; + try + { + KestrelEventSource.Log.RequestStart(this); + + // Run the application code for this request + await application.ProcessRequestAsync(httpContext); + + if (_requestAborted == 0) + { + VerifyResponseContentLength(); + } + } + catch (Exception ex) + { + ReportApplicationError(ex); + // Capture BadHttpRequestException for further processing + badRequestException = ex as BadHttpRequestException; + } + + KestrelEventSource.Log.RequestStop(this); + + // Trigger OnStarting if it hasn't been called yet and the app hasn't + // already failed. If an OnStarting callback throws we can go through + // our normal error handling in ProduceEnd. + // https://github.com/aspnet/KestrelHttpServer/issues/43 + if (!HasResponseStarted && _applicationException == null && _onStarting != null) + { + await FireOnStarting(); + } + + PauseStreams(); + + if (_onCompleted != null) + { + await FireOnCompleted(); + } + + if (badRequestException == null) + { + // If _requestAbort is set, the connection has already been closed. + if (_requestAborted == 0) + { + // Call ProduceEnd() before consuming the rest of the request body to prevent + // delaying clients waiting for the chunk terminator: + // + // https://github.com/dotnet/corefx/issues/17330#issuecomment-288248663 + // + // This also prevents the 100 Continue response from being sent if the app + // never tried to read the body. + // https://github.com/aspnet/KestrelHttpServer/issues/2102 + // + // ProduceEnd() must be called before _application.DisposeContext(), to ensure + // HttpContext.Response.StatusCode is correctly set when + // IHttpContextFactory.Dispose(HttpContext) is called. + await ProduceEnd(); + + // ForZeroContentLength does not complete the reader nor the writer + if (!messageBody.IsEmpty) + { + try + { + // Finish reading the request body in case the app did not. + await messageBody.ConsumeAsync(); + } + catch (BadHttpRequestException ex) + { + // Capture BadHttpRequestException for further processing + badRequestException = ex; + } + } + } + else if (!HasResponseStarted) + { + // If the request was aborted and no response was sent, there's no + // meaningful status code to log. + StatusCode = 0; + } + } + + if (badRequestException != null) + { + // Handle BadHttpRequestException thrown during app execution or remaining message body consumption. + // This has to be caught here so StatusCode is set properly before disposing the HttpContext + // (DisposeContext logs StatusCode). + SetBadRequestState(badRequestException); + } + + application.DisposeContext(httpContext, _applicationException); + + // StopStreams should be called before the end of the "if (!_requestProcessingStopping)" block + // to ensure InitializeStreams has been called. + StopStreams(); + + if (HasStartedConsumingRequestBody) + { + RequestBodyPipe.Reader.Complete(); + + // Wait for MessageBody.PumpAsync() to call RequestBodyPipe.Writer.Complete(). + await messageBody.StopAsync(); + + // At this point both the request body pipe reader and writer should be completed. + RequestBodyPipe.Reset(); + } + + if (badRequestException != null) + { + // Bad request reported, stop processing requests + return; + } + + } while (_keepAlive); + } + public void OnStarting(Func callback, object state) { lock (_onStartingSync) From 6728e756b77afb54a29e06cdba3e6f194984ec40 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Fri, 23 Feb 2018 17:24:20 +0000 Subject: [PATCH 1539/1662] Sanitize and centralize exception throws (#2293) * Sanitize and centralize exception throws --- src/Kestrel.Core/BadHttpRequestException.cs | 24 +++++++++++- .../Internal/Http/Http1Connection.cs | 28 +++++++------- .../Internal/Http/Http1MessageBody.cs | 20 +++++----- .../Internal/Http/HttpHeaders.Generated.cs | 2 +- src/Kestrel.Core/Internal/Http/HttpParser.cs | 10 +++-- .../Internal/Http/HttpProtocol.cs | 38 +++++++++++++------ .../Internal/Http/HttpRequestHeaders.cs | 14 +------ .../StackTraceHiddenAttribute.cs | 17 +++++++++ tools/CodeGenerator/KnownHeaders.cs | 2 +- 9 files changed, 101 insertions(+), 54 deletions(-) create mode 100644 src/Kestrel.Core/Internal/Infrastructure/StackTraceHiddenAttribute.cs diff --git a/src/Kestrel.Core/BadHttpRequestException.cs b/src/Kestrel.Core/BadHttpRequestException.cs index e778f76641..1414753d9f 100644 --- a/src/Kestrel.Core/BadHttpRequestException.cs +++ b/src/Kestrel.Core/BadHttpRequestException.cs @@ -1,7 +1,9 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System.Diagnostics; using System.IO; +using System.Runtime.CompilerServices; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; @@ -30,6 +32,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core internal StringValues AllowedHeader { get; } + [StackTraceHidden] + internal static void Throw(RequestRejectionReason reason) + { + throw GetException(reason); + } + + [MethodImpl(MethodImplOptions.NoInlining)] internal static BadHttpRequestException GetException(RequestRejectionReason reason) { BadHttpRequestException ex; @@ -102,6 +111,19 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core return ex; } + [StackTraceHidden] + internal static void Throw(RequestRejectionReason reason, string detail) + { + throw GetException(reason, detail); + } + + [StackTraceHidden] + internal static void Throw(RequestRejectionReason reason, in StringValues detail) + { + throw GetException(reason, detail.ToString()); + } + + [MethodImpl(MethodImplOptions.NoInlining)] internal static BadHttpRequestException GetException(RequestRejectionReason reason, string detail) { BadHttpRequestException ex; @@ -141,4 +163,4 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core return ex; } } -} +} \ No newline at end of file diff --git a/src/Kestrel.Core/Internal/Http/Http1Connection.cs b/src/Kestrel.Core/Internal/Http/Http1Connection.cs index a66179fa4a..4b24908f53 100644 --- a/src/Kestrel.Core/Internal/Http/Http1Connection.cs +++ b/src/Kestrel.Core/Internal/Http/Http1Connection.cs @@ -119,7 +119,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http var result = _parser.ParseRequestLine(new Http1ParsingHandler(this), buffer, out consumed, out examined); if (!result && overLength) { - ThrowRequestRejected(RequestRejectionReason.RequestLineTooLong); + BadHttpRequestException.Throw(RequestRejectionReason.RequestLineTooLong); } return result; @@ -143,7 +143,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http if (!result && overLength) { - ThrowRequestRejected(RequestRejectionReason.HeadersExceedMaxTotalSize); + BadHttpRequestException.Throw(RequestRejectionReason.HeadersExceedMaxTotalSize); } if (result) { @@ -278,7 +278,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http // requests (https://tools.ietf.org/html/rfc7231#section-4.3.6). if (method != HttpMethod.Connect) { - ThrowRequestRejected(RequestRejectionReason.ConnectMethodRequired); + BadHttpRequestException.Throw(RequestRejectionReason.ConnectMethodRequired); } // When making a CONNECT request to establish a tunnel through one or @@ -303,7 +303,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http // OPTIONS request (https://tools.ietf.org/html/rfc7231#section-4.3.7). if (method != HttpMethod.Options) { - ThrowRequestRejected(RequestRejectionReason.OptionsMethodRequired); + BadHttpRequestException.Throw(RequestRejectionReason.OptionsMethodRequired); } RawTarget = Asterisk; @@ -367,17 +367,17 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http var host = HttpRequestHeaders.HeaderHost; if (host.Count <= 0) { - ThrowRequestRejected(RequestRejectionReason.MissingHostHeader); + BadHttpRequestException.Throw(RequestRejectionReason.MissingHostHeader); } else if (host.Count > 1) { - ThrowRequestRejected(RequestRejectionReason.MultipleHostHeaders); + BadHttpRequestException.Throw(RequestRejectionReason.MultipleHostHeaders); } else if (_requestTargetForm == HttpRequestTarget.AuthorityForm) { if (!host.Equals(RawTarget)) { - ThrowRequestRejected(RequestRejectionReason.InvalidHostHeader, host.ToString()); + BadHttpRequestException.Throw(RequestRejectionReason.InvalidHostHeader, in host); } } else if (_requestTargetForm == HttpRequestTarget.AbsoluteForm) @@ -393,7 +393,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http if ((host != _absoluteRequestTarget.Authority || !_absoluteRequestTarget.IsDefaultPort) && host != authorityAndPort) { - ThrowRequestRejected(RequestRejectionReason.InvalidHostHeader, host.ToString()); + BadHttpRequestException.Throw(RequestRejectionReason.InvalidHostHeader, in host); } } } @@ -446,7 +446,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { if (_requestProcessingStatus == RequestProcessingStatus.ParsingHeaders) { - throw BadHttpRequestException.GetException(RequestRejectionReason + BadHttpRequestException.Throw(RequestRejectionReason .MalformedRequestInvalidHeaders); } throw; @@ -464,11 +464,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http endConnection = true; return true; case RequestProcessingStatus.ParsingRequestLine: - throw BadHttpRequestException.GetException( - RequestRejectionReason.InvalidRequestLine); + BadHttpRequestException.Throw(RequestRejectionReason.InvalidRequestLine); + break; case RequestProcessingStatus.ParsingHeaders: - throw BadHttpRequestException.GetException( - RequestRejectionReason.MalformedRequestInvalidHeaders); + BadHttpRequestException.Throw(RequestRejectionReason.MalformedRequestInvalidHeaders); + break; } } else if (!_keepAlive && _requestProcessingStatus == RequestProcessingStatus.RequestPending) @@ -482,7 +482,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { // In this case, there is an ongoing request but the start line/header parsing has timed out, so send // a 408 response. - throw BadHttpRequestException.GetException(RequestRejectionReason.RequestTimeout); + BadHttpRequestException.Throw(RequestRejectionReason.RequestTimeout); } endConnection = false; diff --git a/src/Kestrel.Core/Internal/Http/Http1MessageBody.cs b/src/Kestrel.Core/Internal/Http/Http1MessageBody.cs index 4e08e419fb..427bbacfcf 100644 --- a/src/Kestrel.Core/Internal/Http/Http1MessageBody.cs +++ b/src/Kestrel.Core/Internal/Http/Http1MessageBody.cs @@ -46,7 +46,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http if (_context.RequestTimedOut) { - _context.ThrowRequestRejected(RequestRejectionReason.RequestTimeout); + BadHttpRequestException.Throw(RequestRejectionReason.RequestTimeout); } var readableBuffer = result.Buffer; @@ -97,7 +97,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http } else if (result.IsCompleted) { - _context.ThrowRequestRejected(RequestRejectionReason.UnexpectedEndOfRequestContent); + BadHttpRequestException.Throw(RequestRejectionReason.UnexpectedEndOfRequestContent); } awaitable = _context.Input.ReadAsync(); @@ -233,7 +233,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { if (headers.HeaderTransferEncoding.Count > 0 || (headers.ContentLength.HasValue && headers.ContentLength.Value != 0)) { - context.ThrowRequestRejected(RequestRejectionReason.UpgradeRequestCannotHavePayload); + BadHttpRequestException.Throw(RequestRejectionReason.UpgradeRequestCannotHavePayload); } return new ForUpgrade(context); @@ -252,7 +252,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http // status code and then close the connection. if (transferCoding != TransferCoding.Chunked) { - context.ThrowRequestRejected(RequestRejectionReason.FinalTransferCodingNotChunked, transferEncoding.ToString()); + BadHttpRequestException.Throw(RequestRejectionReason.FinalTransferCodingNotChunked, in transferEncoding); } return new ForChunkedEncoding(keepAlive, context); @@ -278,7 +278,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http if (HttpMethods.IsPost(context.Method) || HttpMethods.IsPut(context.Method)) { var requestRejectionReason = httpVersion == HttpVersion.Http11 ? RequestRejectionReason.LengthRequired : RequestRejectionReason.LengthRequiredHttp10; - context.ThrowRequestRejected(requestRejectionReason, context.Method); + BadHttpRequestException.Throw(requestRejectionReason, context.Method); } } @@ -339,7 +339,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { if (_contentLength > _context.MaxRequestBodySize) { - _context.ThrowRequestRejected(RequestRejectionReason.RequestBodyTooLarge); + BadHttpRequestException.Throw(RequestRejectionReason.RequestBodyTooLarge); } } } @@ -452,7 +452,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http if (_consumedBytes > _context.MaxRequestBodySize) { - _context.ThrowRequestRejected(RequestRejectionReason.RequestBodyTooLarge); + BadHttpRequestException.Throw(RequestRejectionReason.RequestBodyTooLarge); } } @@ -509,7 +509,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http } // At this point, 10 bytes have been consumed which is enough to parse the max value "7FFFFFFF\r\n". - _context.ThrowRequestRejected(RequestRejectionReason.BadChunkSizeData); + BadHttpRequestException.Throw(RequestRejectionReason.BadChunkSizeData); } private void ParseExtension(ReadOnlyBuffer buffer, out SequencePosition consumed, out SequencePosition examined) @@ -604,7 +604,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http } else { - _context.ThrowRequestRejected(RequestRejectionReason.BadChunkSuffix); + BadHttpRequestException.Throw(RequestRejectionReason.BadChunkSuffix); } } @@ -660,7 +660,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http throw new IOException(CoreStrings.BadRequest_BadChunkSizeData, ex); } - _context.ThrowRequestRejected(RequestRejectionReason.BadChunkSizeData); + BadHttpRequestException.Throw(RequestRejectionReason.BadChunkSizeData); return -1; // can't happen, but compiler complains } diff --git a/src/Kestrel.Core/Internal/Http/HttpHeaders.Generated.cs b/src/Kestrel.Core/Internal/Http/HttpHeaders.Generated.cs index 80bf03c4fd..704d2216a8 100644 --- a/src/Kestrel.Core/Internal/Http/HttpHeaders.Generated.cs +++ b/src/Kestrel.Core/Internal/Http/HttpHeaders.Generated.cs @@ -4049,7 +4049,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { if (_contentLength.HasValue) { - ThrowMultipleContentLengthsException(); + BadHttpRequestException.Throw(RequestRejectionReason.MultipleContentLengths); } else { diff --git a/src/Kestrel.Core/Internal/Http/HttpParser.cs b/src/Kestrel.Core/Internal/Http/HttpParser.cs index 36c4ffecfb..2ca5cdddbf 100644 --- a/src/Kestrel.Core/Internal/Http/HttpParser.cs +++ b/src/Kestrel.Core/Internal/Http/HttpParser.cs @@ -4,6 +4,7 @@ using System; using System.Buffers; using System.Collections; +using System.Diagnostics; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; @@ -254,7 +255,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http } // Headers don't end in CRLF line. - RejectRequest(RequestRejectionReason.InvalidRequestHeadersNoCRLF); + BadHttpRequestException.Throw(RequestRejectionReason.InvalidRequestHeadersNoCRLF); } // We moved the reader so look ahead 2 bytes so reset both the reader @@ -483,18 +484,19 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http c == '~'; } - private void RejectRequest(RequestRejectionReason reason) - => throw BadHttpRequestException.GetException(reason); - + [StackTraceHidden] private unsafe void RejectRequestLine(byte* requestLine, int length) => throw GetInvalidRequestException(RequestRejectionReason.InvalidRequestLine, requestLine, length); + [StackTraceHidden] private unsafe void RejectRequestHeader(byte* headerLine, int length) => throw GetInvalidRequestException(RequestRejectionReason.InvalidRequestHeader, headerLine, length); + [StackTraceHidden] private unsafe void RejectUnknownVersion(byte* version, int length) => throw GetInvalidRequestException(RequestRejectionReason.UnrecognizedHTTPVersion, version, length); + [MethodImpl(MethodImplOptions.NoInlining)] private unsafe BadHttpRequestException GetInvalidRequestException(RequestRejectionReason reason, byte* detail, int length) => BadHttpRequestException.GetException( reason, diff --git a/src/Kestrel.Core/Internal/Http/HttpProtocol.cs b/src/Kestrel.Core/Internal/Http/HttpProtocol.cs index c5cef990ee..80d073f23e 100644 --- a/src/Kestrel.Core/Internal/Http/HttpProtocol.cs +++ b/src/Kestrel.Core/Internal/Http/HttpProtocol.cs @@ -429,7 +429,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http _requestHeadersParsed++; if (_requestHeadersParsed > ServerOptions.Limits.MaxRequestHeaderCount) { - ThrowRequestRejected(RequestRejectionReason.TooManyHeaders); + BadHttpRequestException.Throw(RequestRejectionReason.TooManyHeaders); } var valueString = value.GetAsciiStringNonNullCharacters(); @@ -863,13 +863,26 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http _responseBytesWritten + count > responseHeaders.ContentLength.Value) { _keepAlive = false; - throw new InvalidOperationException( - CoreStrings.FormatTooManyBytesWritten(_responseBytesWritten + count, responseHeaders.ContentLength.Value)); + ThrowTooManyBytesWritten(count); } _responseBytesWritten += count; } + [StackTraceHidden] + private void ThrowTooManyBytesWritten(int count) + { + throw GetTooManyBytesWrittenException(count); + } + + [MethodImpl(MethodImplOptions.NoInlining)] + private InvalidOperationException GetTooManyBytesWrittenException(int count) + { + var responseHeaders = HttpResponseHeaders; + return new InvalidOperationException( + CoreStrings.FormatTooManyBytesWritten(_responseBytesWritten + count, responseHeaders.ContentLength.Value)); + } + private void CheckLastWrite() { var responseHeaders = HttpResponseHeaders; @@ -1250,25 +1263,28 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http // Writes to HEAD response are ignored and logged at the end of the request if (Method != "HEAD") { - // Throw Exception for 204, 205, 304 responses. - throw new InvalidOperationException(CoreStrings.FormatWritingToResponseBodyNotSupported(StatusCode)); + ThrowWritingToResponseBodyNotSupported(); } } + [StackTraceHidden] + private void ThrowWritingToResponseBodyNotSupported() + { + // Throw Exception for 204, 205, 304 responses. + throw new InvalidOperationException(CoreStrings.FormatWritingToResponseBodyNotSupported(StatusCode)); + } + + [StackTraceHidden] private void ThrowResponseAbortedException() { throw new ObjectDisposedException(CoreStrings.UnhandledApplicationException, _applicationException); } - public void ThrowRequestRejected(RequestRejectionReason reason) - => throw BadHttpRequestException.GetException(reason); - - public void ThrowRequestRejected(RequestRejectionReason reason, string detail) - => throw BadHttpRequestException.GetException(reason, detail); - + [StackTraceHidden] public void ThrowRequestTargetRejected(Span target) => throw GetInvalidRequestTargetException(target); + [MethodImpl(MethodImplOptions.NoInlining)] private BadHttpRequestException GetInvalidRequestTargetException(Span target) => BadHttpRequestException.GetException( RequestRejectionReason.InvalidRequestTarget, diff --git a/src/Kestrel.Core/Internal/Http/HttpRequestHeaders.cs b/src/Kestrel.Core/Internal/Http/HttpRequestHeaders.cs index f512df8fcf..c441ae5ed6 100644 --- a/src/Kestrel.Core/Internal/Http/HttpRequestHeaders.cs +++ b/src/Kestrel.Core/Internal/Http/HttpRequestHeaders.cs @@ -19,7 +19,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http long parsed; if (!HeaderUtilities.TryParseNonNegativeInt64(value, out parsed)) { - ThrowInvalidContentLengthException(value); + BadHttpRequestException.Throw(RequestRejectionReason.InvalidContentLength, value); } return parsed; @@ -47,7 +47,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { if (!StringUtilities.TryGetAsciiString(pKeyBytes, keyBuffer, keyLength)) { - throw BadHttpRequestException.GetException(RequestRejectionReason.InvalidCharactersInHeaderName); + BadHttpRequestException.Throw(RequestRejectionReason.InvalidCharactersInHeaderName); } } @@ -56,16 +56,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http Unknown[key] = AppendValue(existing, value); } - private static void ThrowInvalidContentLengthException(string value) - { - throw BadHttpRequestException.GetException(RequestRejectionReason.InvalidContentLength, value); - } - - private static void ThrowMultipleContentLengthsException() - { - throw BadHttpRequestException.GetException(RequestRejectionReason.MultipleContentLengths); - } - public Enumerator GetEnumerator() { return new Enumerator(this); diff --git a/src/Kestrel.Core/Internal/Infrastructure/StackTraceHiddenAttribute.cs b/src/Kestrel.Core/Internal/Infrastructure/StackTraceHiddenAttribute.cs new file mode 100644 index 0000000000..cf6e608d7b --- /dev/null +++ b/src/Kestrel.Core/Internal/Infrastructure/StackTraceHiddenAttribute.cs @@ -0,0 +1,17 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +namespace System.Diagnostics +{ + /// + /// Attribute to add to non-returning throw only methods, + /// to restore the stack trace back to what it would be if the throw was in-place + /// + [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method | AttributeTargets.Constructor | AttributeTargets.Struct, Inherited = false)] + internal sealed class StackTraceHiddenAttribute : Attribute + { + // https://github.com/dotnet/coreclr/blob/eb54e48b13fdfb7233b7bcd32b93792ba3e89f0c/src/mscorlib/shared/System/Diagnostics/StackTraceHiddenAttribute.cs + public StackTraceHiddenAttribute() { } + } +} \ No newline at end of file diff --git a/tools/CodeGenerator/KnownHeaders.cs b/tools/CodeGenerator/KnownHeaders.cs index 8571143b3f..7578113ba3 100644 --- a/tools/CodeGenerator/KnownHeaders.cs +++ b/tools/CodeGenerator/KnownHeaders.cs @@ -36,7 +36,7 @@ namespace CodeGenerator {{{(header.Identifier == "ContentLength" ? $@" if (_contentLength.HasValue) {{ - ThrowMultipleContentLengthsException(); + BadHttpRequestException.Throw(RequestRejectionReason.MultipleContentLengths); }} else {{ From 39951e892eab3e167055fce51c514b44db74b38d Mon Sep 17 00:00:00 2001 From: Nikita Tsukanov Date: Fri, 23 Feb 2018 20:51:09 +0300 Subject: [PATCH 1540/1662] Don't throw in HttpRequestStream.Flush (#2342) Because read-only streams apparently can have Flush semantics and this behavior is expected by some of built-in stream wrappers (e. g. CryptoStream) https://github.com/dotnet/corefx/pull/27327#pullrequestreview-98384813 https://github.com/aspnet/KestrelHttpServer/issues/2341 --- src/Kestrel.Core/Internal/Http/HttpRequestStream.cs | 3 +-- test/Kestrel.Core.Tests/HttpRequestStreamTests.cs | 9 +++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Kestrel.Core/Internal/Http/HttpRequestStream.cs b/src/Kestrel.Core/Internal/Http/HttpRequestStream.cs index 4f325f4d38..2c47fad114 100644 --- a/src/Kestrel.Core/Internal/Http/HttpRequestStream.cs +++ b/src/Kestrel.Core/Internal/Http/HttpRequestStream.cs @@ -38,12 +38,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http public override void Flush() { - throw new NotSupportedException(); } public override Task FlushAsync(CancellationToken cancellationToken) { - throw new NotSupportedException(); + return Task.CompletedTask; } public override long Seek(long offset, SeekOrigin origin) diff --git a/test/Kestrel.Core.Tests/HttpRequestStreamTests.cs b/test/Kestrel.Core.Tests/HttpRequestStreamTests.cs index 98c3d7ef68..8bff09b8a7 100644 --- a/test/Kestrel.Core.Tests/HttpRequestStreamTests.cs +++ b/test/Kestrel.Core.Tests/HttpRequestStreamTests.cs @@ -98,17 +98,18 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests #endif [Fact] - public void FlushThrows() + // Read-only streams should support Flush according to https://github.com/dotnet/corefx/pull/27327#pullrequestreview-98384813 + public void FlushDoesNotThrow() { var stream = new HttpRequestStream(Mock.Of()); - Assert.Throws(() => stream.Flush()); + stream.Flush(); } [Fact] - public async Task FlushAsyncThrows() + public async Task FlushAsyncDoesNotThrow() { var stream = new HttpRequestStream(Mock.Of()); - await Assert.ThrowsAsync(() => stream.FlushAsync()); + await stream.FlushAsync(); } [Fact] From de7e2a2573e26c91490a094f65d7dad9479f9bb8 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Fri, 23 Feb 2018 22:29:42 +0000 Subject: [PATCH 1541/1662] Use enum for method rather than string compares (#2294) --- src/Kestrel.Core/BadHttpRequestException.cs | 4 + .../Internal/Http/Http1Connection.cs | 11 ++- .../Internal/Http/Http1MessageBody.cs | 2 +- src/Kestrel.Core/Internal/Http/HttpMethod.cs | 2 + .../Http/HttpProtocol.FeatureCollection.cs | 17 +++- .../Internal/Http/HttpProtocol.cs | 16 ++-- .../Internal/Http2/Http2Stream.cs | 6 +- .../Internal/Infrastructure/HttpUtilities.cs | 82 +++++++++++++++++++ .../Http1ConnectionTests.cs | 8 +- test/Kestrel.Core.Tests/MessageBodyTests.cs | 16 ++-- 10 files changed, 137 insertions(+), 27 deletions(-) diff --git a/src/Kestrel.Core/BadHttpRequestException.cs b/src/Kestrel.Core/BadHttpRequestException.cs index 1414753d9f..4fc2bb1521 100644 --- a/src/Kestrel.Core/BadHttpRequestException.cs +++ b/src/Kestrel.Core/BadHttpRequestException.cs @@ -38,6 +38,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core throw GetException(reason); } + [StackTraceHidden] + public static void Throw(RequestRejectionReason reason, HttpMethod method) + => throw GetException(reason, method.ToString().ToUpperInvariant()); + [MethodImpl(MethodImplOptions.NoInlining)] internal static BadHttpRequestException GetException(RequestRejectionReason reason) { diff --git a/src/Kestrel.Core/Internal/Http/Http1Connection.cs b/src/Kestrel.Core/Internal/Http/Http1Connection.cs index 4b24908f53..142902a8de 100644 --- a/src/Kestrel.Core/Internal/Http/Http1Connection.cs +++ b/src/Kestrel.Core/Internal/Http/Http1Connection.cs @@ -181,13 +181,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http OnAuthorityFormTarget(method, target); } - Method = method != HttpMethod.Custom - ? HttpUtilities.MethodToString(method) ?? string.Empty - : customMethod.GetAsciiStringNonNullCharacters(); + Method = method; + if (method == HttpMethod.Custom) + { + _methodText = customMethod.GetAsciiStringNonNullCharacters(); + } + _httpVersion = version; Debug.Assert(RawTarget != null, "RawTarget was not set"); - Debug.Assert(Method != null, "Method was not set"); + Debug.Assert(((IHttpRequestFeature)this).Method != null, "Method was not set"); Debug.Assert(Path != null, "Path was not set"); Debug.Assert(QueryString != null, "QueryString was not set"); Debug.Assert(HttpVersion != null, "HttpVersion was not set"); diff --git a/src/Kestrel.Core/Internal/Http/Http1MessageBody.cs b/src/Kestrel.Core/Internal/Http/Http1MessageBody.cs index 427bbacfcf..4eb3f8928d 100644 --- a/src/Kestrel.Core/Internal/Http/Http1MessageBody.cs +++ b/src/Kestrel.Core/Internal/Http/Http1MessageBody.cs @@ -275,7 +275,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { // If we got here, request contains no Content-Length or Transfer-Encoding header. // Reject with 411 Length Required. - if (HttpMethods.IsPost(context.Method) || HttpMethods.IsPut(context.Method)) + if (context.Method == HttpMethod.Post || context.Method == HttpMethod.Put) { var requestRejectionReason = httpVersion == HttpVersion.Http11 ? RequestRejectionReason.LengthRequired : RequestRejectionReason.LengthRequiredHttp10; BadHttpRequestException.Throw(requestRejectionReason, context.Method); diff --git a/src/Kestrel.Core/Internal/Http/HttpMethod.cs b/src/Kestrel.Core/Internal/Http/HttpMethod.cs index 0aa230cf50..3e6ff0667e 100644 --- a/src/Kestrel.Core/Internal/Http/HttpMethod.cs +++ b/src/Kestrel.Core/Internal/Http/HttpMethod.cs @@ -16,5 +16,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http Options, Custom, + + None = byte.MaxValue, } } \ No newline at end of file diff --git a/src/Kestrel.Core/Internal/Http/HttpProtocol.FeatureCollection.cs b/src/Kestrel.Core/Internal/Http/HttpProtocol.FeatureCollection.cs index cc0337a833..055e8a1e76 100644 --- a/src/Kestrel.Core/Internal/Http/HttpProtocol.FeatureCollection.cs +++ b/src/Kestrel.Core/Internal/Http/HttpProtocol.FeatureCollection.cs @@ -11,6 +11,7 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Server.Kestrel.Core.Features; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { @@ -89,8 +90,20 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http string IHttpRequestFeature.Method { - get => Method; - set => Method = value; + get + { + if (_methodText != null) + { + return _methodText; + } + + _methodText = HttpUtilities.MethodToString(Method) ?? string.Empty; + return _methodText; + } + set + { + _methodText = value; + } } string IHttpRequestFeature.PathBase diff --git a/src/Kestrel.Core/Internal/Http/HttpProtocol.cs b/src/Kestrel.Core/Internal/Http/HttpProtocol.cs index 80d073f23e..274376c31b 100644 --- a/src/Kestrel.Core/Internal/Http/HttpProtocol.cs +++ b/src/Kestrel.Core/Internal/Http/HttpProtocol.cs @@ -62,6 +62,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http private readonly IHttpProtocolContext _context; + protected string _methodText = null; private string _scheme = null; public HttpProtocol(IHttpProtocolContext context) @@ -119,7 +120,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http public IPAddress LocalIpAddress { get; set; } public int LocalPort { get; set; } public string Scheme { get; set; } - public string Method { get; set; } + public HttpMethod Method { get; set; } public string PathBase { get; set; } public string Path { get; set; } public string QueryString { get; set; } @@ -324,7 +325,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http MaxRequestBodySize = ServerOptions.Limits.MaxRequestBodySize; AllowSynchronousIO = ServerOptions.AllowSynchronousIO; TraceIdentifier = null; - Method = null; + Method = HttpMethod.None; + _methodText = null; PathBase = null; Path = null; RawTarget = null; @@ -905,7 +907,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { var responseHeaders = HttpResponseHeaders; - if (!HttpMethods.IsHead(Method) && + if (Method != HttpMethod.Head && StatusCode != StatusCodes.Status304NotModified && !responseHeaders.HasTransferEncoding && responseHeaders.ContentLength.HasValue && @@ -1074,7 +1076,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http Log.ConnectionKeepAlive(ConnectionId); } - if (HttpMethods.IsHead(Method) && _responseBytesWritten > 0) + if (Method == HttpMethod.Head && _responseBytesWritten > 0) { Log.ConnectionHeadResponseBodyWrite(ConnectionId, _responseBytesWritten); } @@ -1094,7 +1096,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http Log.ConnectionKeepAlive(ConnectionId); } - if (HttpMethods.IsHead(Method) && _responseBytesWritten > 0) + if (Method == HttpMethod.Head && _responseBytesWritten > 0) { Log.ConnectionHeadResponseBodyWrite(ConnectionId, _responseBytesWritten); } @@ -1124,7 +1126,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http } // Set whether response can have body - _canHaveBody = StatusCanHaveBody(StatusCode) && Method != "HEAD"; + _canHaveBody = StatusCanHaveBody(StatusCode) && Method != HttpMethod.Head; // Don't set the Content-Length or Transfer-Encoding headers // automatically for HEAD requests or 204, 205, 304 responses. @@ -1261,7 +1263,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http public void HandleNonBodyResponseWrite() { // Writes to HEAD response are ignored and logged at the end of the request - if (Method != "HEAD") + if (Method != HttpMethod.Head) { ThrowWritingToResponseBodyNotSupported(); } diff --git a/src/Kestrel.Core/Internal/Http2/Http2Stream.cs b/src/Kestrel.Core/Internal/Http2/Http2Stream.cs index 873cb1fbea..de212d1933 100644 --- a/src/Kestrel.Core/Internal/Http2/Http2Stream.cs +++ b/src/Kestrel.Core/Internal/Http2/Http2Stream.cs @@ -5,6 +5,7 @@ using System; using System.Buffers; using System.IO.Pipelines; using System.Threading.Tasks; +using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Server.Kestrel.Core.Features; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; @@ -53,7 +54,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 // We don't need any of the parameters because we don't implement BeginRead to actually // do the reading from a pipeline, nor do we use endConnection to report connection-level errors. - Method = RequestHeaders[":method"]; + var methodText = RequestHeaders[":method"]; + Method = HttpUtilities.GetKnownMethod(methodText); + _methodText = methodText; + Scheme = RequestHeaders[":scheme"]; _httpVersion = Http.HttpVersion.Http2; diff --git a/src/Kestrel.Core/Internal/Infrastructure/HttpUtilities.cs b/src/Kestrel.Core/Internal/Infrastructure/HttpUtilities.cs index 28f73a9031..457b7afe5f 100644 --- a/src/Kestrel.Core/Internal/Infrastructure/HttpUtilities.cs +++ b/src/Kestrel.Core/Internal/Infrastructure/HttpUtilities.cs @@ -6,6 +6,7 @@ using System.Diagnostics; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Text; +using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure @@ -177,6 +178,87 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure return HttpMethod.Custom; } + /// + /// Parses string for a known HTTP method. + /// + /// + /// A "known HTTP method" can be an HTTP method name defined in the HTTP/1.1 RFC. + /// The Known Methods (CONNECT, DELETE, GET, HEAD, PATCH, POST, PUT, OPTIONS, TRACE) + /// + /// + public static HttpMethod GetKnownMethod(string value) + { + // Called by http/2 + if (value == null) + { + throw new ArgumentNullException(nameof(value)); + } + + var length = value.Length; + if (length == 0) + { + throw new ArgumentException(nameof(value)); + } + + // Start with custom and assign if known method is found + var method = HttpMethod.Custom; + + var firstChar = value[0]; + if (length == 3) + { + if (firstChar == 'G' && string.Equals(value, HttpMethods.Get, StringComparison.Ordinal)) + { + method = HttpMethod.Get; + } + else if (firstChar == 'P' && string.Equals(value, HttpMethods.Put, StringComparison.Ordinal)) + { + method = HttpMethod.Put; + } + } + else if (length == 4) + { + if (firstChar == 'H' && string.Equals(value, HttpMethods.Head, StringComparison.Ordinal)) + { + method = HttpMethod.Head; + } + else if(firstChar == 'P' && string.Equals(value, HttpMethods.Post, StringComparison.Ordinal)) + { + method = HttpMethod.Post; + } + } + else if (length == 5) + { + if (firstChar == 'T' && string.Equals(value, HttpMethods.Trace, StringComparison.Ordinal)) + { + method = HttpMethod.Trace; + } + else if(firstChar == 'P' && string.Equals(value, HttpMethods.Patch, StringComparison.Ordinal)) + { + method = HttpMethod.Patch; + } + } + else if (length == 6) + { + if (firstChar == 'D' && string.Equals(value, HttpMethods.Delete, StringComparison.Ordinal)) + { + method = HttpMethod.Delete; + } + } + else if (length == 7) + { + if (firstChar == 'C' && string.Equals(value, HttpMethods.Connect, StringComparison.Ordinal)) + { + method = HttpMethod.Connect; + } + else if (firstChar == 'O' && string.Equals(value, HttpMethods.Options, StringComparison.Ordinal)) + { + method = HttpMethod.Options; + } + } + + return method; + } + /// /// Checks 9 bytes from correspond to a known HTTP version. /// diff --git a/test/Kestrel.Core.Tests/Http1ConnectionTests.cs b/test/Kestrel.Core.Tests/Http1ConnectionTests.cs index 56711ed1b3..41c933a429 100644 --- a/test/Kestrel.Core.Tests/Http1ConnectionTests.cs +++ b/test/Kestrel.Core.Tests/Http1ConnectionTests.cs @@ -344,7 +344,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests _transport.Input.AdvanceTo(_consumed, _examined); Assert.True(returnValue); - Assert.Equal(expectedMethod, _http1Connection.Method); + Assert.Equal(expectedMethod, ((IHttpRequestFeature)_http1Connection).Method); Assert.Equal(expectedRawTarget, _http1Connection.RawTarget); Assert.Equal(expectedDecodedPath, _http1Connection.Path); Assert.Equal(expectedQueryString, _http1Connection.QueryString); @@ -532,7 +532,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests { // Arrange _http1Connection.HttpVersion = "HTTP/1.1"; - ((IHttpRequestFeature)_http1Connection).Method = "HEAD"; + _http1Connection.Method = HttpMethod.Head; // Act/Assert await _http1Connection.WriteAsync(new ArraySegment(new byte[1])); @@ -543,7 +543,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests { // Arrange _http1Connection.HttpVersion = "HTTP/1.1"; - ((IHttpRequestFeature)_http1Connection).Method = "HEAD"; + _http1Connection.Method = HttpMethod.Head; // Act/Assert await _http1Connection.WriteAsync(new ArraySegment(new byte[1]), default(CancellationToken)); @@ -554,7 +554,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests { // Arrange _http1Connection.HttpVersion = "HTTP/1.1"; - ((IHttpRequestFeature)_http1Connection).Method = "HEAD"; + _http1Connection.Method = HttpMethod.Head; // Act _http1Connection.ResponseHeaders.Add("Transfer-Encoding", "chunked"); diff --git a/test/Kestrel.Core.Tests/MessageBodyTests.cs b/test/Kestrel.Core.Tests/MessageBodyTests.cs index 41d0724bd0..8a563474fe 100644 --- a/test/Kestrel.Core.Tests/MessageBodyTests.cs +++ b/test/Kestrel.Core.Tests/MessageBodyTests.cs @@ -333,9 +333,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests } [Theory] - [InlineData("POST")] - [InlineData("PUT")] - public void ForThrowsWhenMethodRequiresLengthButNoContentLengthOrTransferEncodingIsSet(string method) + [InlineData(HttpMethod.Post)] + [InlineData(HttpMethod.Put)] + public void ForThrowsWhenMethodRequiresLengthButNoContentLengthOrTransferEncodingIsSet(HttpMethod method) { using (var input = new TestInput()) { @@ -344,14 +344,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests Http1MessageBody.For(HttpVersion.Http11, new HttpRequestHeaders(), input.Http1Connection)); Assert.Equal(StatusCodes.Status411LengthRequired, ex.StatusCode); - Assert.Equal(CoreStrings.FormatBadRequest_LengthRequired(method), ex.Message); + Assert.Equal(CoreStrings.FormatBadRequest_LengthRequired(((IHttpRequestFeature)input.Http1Connection).Method), ex.Message); } } [Theory] - [InlineData("POST")] - [InlineData("PUT")] - public void ForThrowsWhenMethodRequiresLengthButNoContentLengthSetHttp10(string method) + [InlineData(HttpMethod.Post)] + [InlineData(HttpMethod.Put)] + public void ForThrowsWhenMethodRequiresLengthButNoContentLengthSetHttp10(HttpMethod method) { using (var input = new TestInput()) { @@ -360,7 +360,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests Http1MessageBody.For(HttpVersion.Http10, new HttpRequestHeaders(), input.Http1Connection)); Assert.Equal(StatusCodes.Status400BadRequest, ex.StatusCode); - Assert.Equal(CoreStrings.FormatBadRequest_LengthRequiredHttp10(method), ex.Message); + Assert.Equal(CoreStrings.FormatBadRequest_LengthRequiredHttp10(((IHttpRequestFeature)input.Http1Connection).Method), ex.Message); } } From 0134e56909cc06946f85ce4a3b45f1cdc86d26cf Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Fri, 23 Feb 2018 22:22:00 -0800 Subject: [PATCH 1542/1662] Include exceptions when displaying test logs (#2344) --- test/Kestrel.FunctionalTests/HttpsTests.cs | 3 ++- test/Kestrel.FunctionalTests/RequestTests.cs | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/test/Kestrel.FunctionalTests/HttpsTests.cs b/test/Kestrel.FunctionalTests/HttpsTests.cs index 152823f6a9..9190597c3b 100644 --- a/test/Kestrel.FunctionalTests/HttpsTests.cs +++ b/test/Kestrel.FunctionalTests/HttpsTests.cs @@ -412,7 +412,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { if (logLevel == LogLevel.Error) { - _errorMessages.Add(formatter(state, exception)); + var log = $"Log {logLevel}[{eventId}]: {formatter(state, exception)} {exception?.Message}"; + _errorMessages.Add(log); } if (exception is ObjectDisposedException) diff --git a/test/Kestrel.FunctionalTests/RequestTests.cs b/test/Kestrel.FunctionalTests/RequestTests.cs index ff063b35bf..a6ce1b5db9 100644 --- a/test/Kestrel.FunctionalTests/RequestTests.cs +++ b/test/Kestrel.FunctionalTests/RequestTests.cs @@ -409,7 +409,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests .Setup(logger => logger.Log(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny>())) .Callback>((logLevel, eventId, state, exception, formatter) => { - _output.WriteLine(logLevel + ": " + formatter(state, exception)); + var log = $"Log {logLevel}[{eventId}]: {formatter(state, exception)} {exception?.Message}"; + _output.WriteLine(log); if (eventId.Id == _connectionResetEventId) { From 06945ba81ebe55e17e32b8d7ff25fb3075895cc3 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Sat, 24 Feb 2018 16:51:57 -0800 Subject: [PATCH 1543/1662] Include exceptions when displaying test logs (#2346) --- test/Kestrel.FunctionalTests/HttpsTests.cs | 2 +- test/Kestrel.FunctionalTests/RequestTests.cs | 2 +- test/shared/TestApplicationErrorLogger.cs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/test/Kestrel.FunctionalTests/HttpsTests.cs b/test/Kestrel.FunctionalTests/HttpsTests.cs index 9190597c3b..481f3ef2bd 100644 --- a/test/Kestrel.FunctionalTests/HttpsTests.cs +++ b/test/Kestrel.FunctionalTests/HttpsTests.cs @@ -412,7 +412,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { if (logLevel == LogLevel.Error) { - var log = $"Log {logLevel}[{eventId}]: {formatter(state, exception)} {exception?.Message}"; + var log = $"Log {logLevel}[{eventId}]: {formatter(state, exception)} {exception}"; _errorMessages.Add(log); } diff --git a/test/Kestrel.FunctionalTests/RequestTests.cs b/test/Kestrel.FunctionalTests/RequestTests.cs index a6ce1b5db9..d1fdfd5dc8 100644 --- a/test/Kestrel.FunctionalTests/RequestTests.cs +++ b/test/Kestrel.FunctionalTests/RequestTests.cs @@ -409,7 +409,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests .Setup(logger => logger.Log(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny>())) .Callback>((logLevel, eventId, state, exception, formatter) => { - var log = $"Log {logLevel}[{eventId}]: {formatter(state, exception)} {exception?.Message}"; + var log = $"Log {logLevel}[{eventId}]: {formatter(state, exception)} {exception}"; _output.WriteLine(log); if (eventId.Id == _connectionResetEventId) diff --git a/test/shared/TestApplicationErrorLogger.cs b/test/shared/TestApplicationErrorLogger.cs index 480d8d4140..91a61f08f7 100644 --- a/test/shared/TestApplicationErrorLogger.cs +++ b/test/shared/TestApplicationErrorLogger.cs @@ -45,7 +45,7 @@ namespace Microsoft.AspNetCore.Testing if (logLevel == LogLevel.Critical && ThrowOnCriticalErrors) #endif { - var log = $"Log {logLevel}[{eventId}]: {formatter(state, exception)} {exception?.Message}"; + var log = $"Log {logLevel}[{eventId}]: {formatter(state, exception)} {exception}"; Console.WriteLine(log); From 83bf2375b39d2f8f28c1314d1ae0a64e22f025e8 Mon Sep 17 00:00:00 2001 From: Justin Wyer Date: Mon, 26 Feb 2018 03:10:04 +0200 Subject: [PATCH 1544/1662] #2035 Do not await OnCompleted handlers before sending the Response (#2324) --- .../Internal/Http/HttpProtocol.cs | 18 ++- test/Kestrel.FunctionalTests/ResponseTests.cs | 106 +++++++++++++++++- 2 files changed, 109 insertions(+), 15 deletions(-) diff --git a/src/Kestrel.Core/Internal/Http/HttpProtocol.cs b/src/Kestrel.Core/Internal/Http/HttpProtocol.cs index 274376c31b..7839a33cbd 100644 --- a/src/Kestrel.Core/Internal/Http/HttpProtocol.cs +++ b/src/Kestrel.Core/Internal/Http/HttpProtocol.cs @@ -554,11 +554,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http PauseStreams(); - if (_onCompleted != null) - { - await FireOnCompleted(); - } - if (badRequestException == null) { // If _requestAbort is set, the connection has already been closed. @@ -601,6 +596,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http } } + if (_onCompleted != null) + { + await FireOnCompleted(); + } + if (badRequestException != null) { // Handle BadHttpRequestException thrown during app execution or remaining message body consumption. @@ -739,10 +739,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { return Task.CompletedTask; } - else - { - return FireOnCompletedAwaited(onCompleted); - } + + return FireOnCompletedAwaited(onCompleted); } private async Task FireOnCompletedAwaited(Stack, object>> onCompleted) @@ -755,7 +753,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http } catch (Exception ex) { - ReportApplicationError(ex); + Log.ApplicationError(ConnectionId, TraceIdentifier, ex); } } } diff --git a/test/Kestrel.FunctionalTests/ResponseTests.cs b/test/Kestrel.FunctionalTests/ResponseTests.cs index 4f5513ec98..ca9616dfcf 100644 --- a/test/Kestrel.FunctionalTests/ResponseTests.cs +++ b/test/Kestrel.FunctionalTests/ResponseTests.cs @@ -146,7 +146,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests public async Task OnCompleteCalledEvenWhenOnStartingNotCalled() { var onStartingCalled = false; - var onCompletedCalled = false; + var onCompletedTcs = new TaskCompletionSource(); var hostBuilder = TransportSelector.GetWebHostBuilder() .UseKestrel() @@ -156,7 +156,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests app.Run(context => { context.Response.OnStarting(() => Task.Run(() => onStartingCalled = true)); - context.Response.OnCompleted(() => Task.Run(() => onCompletedCalled = true)); + context.Response.OnCompleted(() => Task.Run(() => + { + onCompletedTcs.SetResult(null); + })); // Prevent OnStarting call (see HttpProtocol.ProcessRequestsAsync()). throw new Exception(); @@ -173,7 +176,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests Assert.Equal(HttpStatusCode.InternalServerError, response.StatusCode); Assert.False(onStartingCalled); - Assert.True(onCompletedCalled); + await onCompletedTcs.Task.TimeoutAfter(TestConstants.DefaultTimeout); } } } @@ -294,6 +297,99 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests sendMalformedRequest: true); } + [Fact] + public async Task OnCompletedExceptionShouldNotPreventAResponse() + { + var hostBuilder = TransportSelector.GetWebHostBuilder() + .UseKestrel() + .UseUrls("http://127.0.0.1:0/") + .Configure(app => + { + app.Run(async context => + { + context.Response.OnCompleted(_ => throw new Exception(), null); + await context.Response.WriteAsync("hello, world"); + }); + }); + + using (var host = hostBuilder.Build()) + { + host.Start(); + + using (var client = new HttpClient()) + { + var response = await client.GetAsync($"http://127.0.0.1:{host.GetPort()}/"); + Assert.Equal(HttpStatusCode.OK, response.StatusCode); + } + } + } + + [Fact] + public async Task OnCompletedShouldNotBlockAResponse() + { + var delay = Task.Delay(TestConstants.DefaultTimeout); + var hostBuilder = TransportSelector.GetWebHostBuilder() + .UseKestrel() + .UseUrls("http://127.0.0.1:0/") + .Configure(app => + { + app.Run(async context => + { + context.Response.OnCompleted(async () => + { + await delay; + }); + await context.Response.WriteAsync("hello, world"); + }); + }); + + using (var host = hostBuilder.Build()) + { + host.Start(); + + using (var client = new HttpClient()) + { + var response = await client.GetAsync($"http://127.0.0.1:{host.GetPort()}/"); + Assert.Equal(HttpStatusCode.OK, response.StatusCode); + Assert.False(delay.IsCompleted); + } + } + } + + [Fact] + public async Task InvalidChunkedEncodingInRequestShouldNotBlockOnCompleted() + { + var onCompletedTcs = new TaskCompletionSource(); + + using (var server = new TestServer(httpContext => + { + httpContext.Response.OnCompleted(() => Task.Run(() => + { + onCompletedTcs.SetResult(null); + })); + return Task.CompletedTask; + })) + { + using (var connection = server.CreateConnection()) + { + await connection.Send( + "GET / HTTP/1.1", + "Host:", + "Transfer-Encoding: chunked", + "", + "gg"); + await connection.ReceiveForcedEnd( + "HTTP/1.1 200 OK", + $"Date: {server.Context.DateHeaderValue}", + "Content-Length: 0", + "", + ""); + } + } + + await onCompletedTcs.Task.TimeoutAfter(TestConstants.DefaultTimeout); + } + private static async Task ResponseStatusCodeSetBeforeHttpContextDispose( RequestDelegate handler, HttpStatusCode? expectedClientStatusCode, @@ -1988,7 +2084,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [Theory] [MemberData(nameof(ConnectionAdapterData))] - public async Task ThrowingInOnCompletedIsLoggedAndClosesConnection(ListenOptions listenOptions) + public async Task ThrowingInOnCompletedIsLogged(ListenOptions listenOptions) { var testContext = new TestServiceContext(); @@ -2024,7 +2120,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests "Host:", "", ""); - await connection.ReceiveForcedEnd( + await connection.ReceiveEnd( "HTTP/1.1 200 OK", $"Date: {testContext.DateHeaderValue}", "Content-Length: 11", From a3911269c577dd73061f9e3a1860851aeb8cea75 Mon Sep 17 00:00:00 2001 From: "ASP.NET CI" Date: Mon, 26 Feb 2018 11:06:51 -0800 Subject: [PATCH 1545/1662] Update dependencies.props [auto-updated: dependencies] --- build/dependencies.props | 40 ++++++++++++++++++++-------------------- korebuild-lock.txt | 4 ++-- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/build/dependencies.props b/build/dependencies.props index 4ed572c52e..b58d70b16c 100644 --- a/build/dependencies.props +++ b/build/dependencies.props @@ -5,29 +5,29 @@ 0.10.11 - 2.1.0-preview2-15707 + 2.1.0-preview2-15721 1.10.0 - 2.1.0-preview2-30131 - 2.1.0-preview2-30131 - 2.1.0-preview2-30131 - 2.1.0-preview2-30131 - 2.1.0-preview2-30131 - 2.1.0-preview2-30131 - 2.1.0-preview2-30131 - 2.1.0-preview2-30131 - 2.1.0-preview2-30131 - 2.1.0-preview2-30131 - 2.1.0-preview2-30131 - 2.1.0-preview2-30131 - 2.1.0-preview2-30131 - 2.1.0-preview2-30131 - 2.1.0-preview2-30131 - 2.1.0-preview2-30131 - 2.1.0-preview2-30131 + 2.1.0-preview2-30187 + 2.1.0-preview2-30187 + 2.1.0-preview2-30187 + 2.1.0-preview2-30187 + 2.1.0-preview2-30187 + 2.1.0-preview2-30187 + 2.1.0-preview2-30187 + 2.1.0-preview2-30187 + 2.1.0-preview2-30187 + 2.1.0-preview2-30187 + 2.1.0-preview2-30187 + 2.1.0-preview2-30187 + 2.1.0-preview2-30187 + 2.1.0-preview2-30187 + 2.1.0-preview2-30187 + 2.1.0-preview2-30187 + 2.1.0-preview2-30187 2.0.0 2.1.0-preview2-26130-04 - 2.1.0-preview2-30131 - 15.3.0 + 2.1.0-preview2-30187 + 15.6.0 4.7.49 10.0.1 4.5.0-preview2-26130-01 diff --git a/korebuild-lock.txt b/korebuild-lock.txt index 89d0ad3d15..e6c7fddffa 100644 --- a/korebuild-lock.txt +++ b/korebuild-lock.txt @@ -1,2 +1,2 @@ -version:2.1.0-preview2-15707 -commithash:e74e53f129ab34332947fea7ac7b7591b027cb22 +version:2.1.0-preview2-15721 +commithash:f9bb4be59e39938ec59a6975257e26099b0d03c1 From 2c108d9ba1986748ac3bc512c69a43319de85ddc Mon Sep 17 00:00:00 2001 From: Pavel Krymets Date: Wed, 28 Feb 2018 12:41:51 -0800 Subject: [PATCH 1546/1662] React to pipes in corefx (#2337) --- Directory.Build.props | 2 + ...Http1ConnectionParsingOverheadBenchmark.cs | 5 +- .../Http1WritingBenchmark.cs | 60 +-- .../HttpParserBenchmark.cs | 4 +- .../HttpProtocolFeatureCollection.cs | 3 +- .../Kestrel.Performance/Mocks/NullParser.cs | 4 +- .../PipeThroughputBenchmark.cs | 12 +- .../RequestParsingBenchmark.cs | 18 +- .../ResponseHeaderCollectionBenchmark.cs | 3 +- .../ResponseHeadersWritingBenchmark.cs | 15 +- build/dependencies.props | 59 ++- .../Adapter/Internal/AdaptedPipeline.cs | 25 +- .../Internal/ConnectionHandler.cs | 4 +- src/Kestrel.Core/Internal/Http/ChunkWriter.cs | 6 +- .../Internal/Http/Http1Connection.cs | 15 +- .../Internal/Http/Http1ConnectionContext.cs | 2 +- .../Internal/Http/Http1MessageBody.cs | 33 +- .../Internal/Http/Http1OutputProducer.cs | 13 +- .../Internal/Http/HttpHeaders.Generated.cs | 2 +- src/Kestrel.Core/Internal/Http/HttpParser.cs | 11 +- .../Internal/Http/HttpProtocol.cs | 5 +- .../Internal/Http/HttpResponseHeaders.cs | 12 +- src/Kestrel.Core/Internal/Http/IHttpParser.cs | 5 +- .../Internal/Http/IHttpProtocolContext.cs | 2 +- src/Kestrel.Core/Internal/Http/MessageBody.cs | 1 + .../Internal/Http/PipelineExtensions.cs | 12 +- src/Kestrel.Core/Internal/Http/UrlDecoder.cs | 411 ++++++++++++++++++ .../Internal/Http2/Http2Connection.cs | 2 +- .../Internal/Http2/Http2ConnectionContext.cs | 2 +- .../Internal/Http2/Http2FrameReader.cs | 3 +- .../Internal/Http2/Http2FrameWriter.cs | 1 - .../Internal/Http2/Http2Stream.cs | 9 +- .../Internal/Http2/Http2StreamContext.cs | 2 +- src/Kestrel.Core/Internal/HttpConnection.cs | 2 +- .../Internal/HttpConnectionContext.cs | 2 +- .../Infrastructure/KestrelThreadPool.cs | 1 + src/Kestrel.Core/Kestrel.Core.csproj | 1 + .../Internal/KestrelMemoryPool.cs | 12 + .../Internal/TransportConnection.Features.cs | 2 +- .../Internal/TransportConnection.cs | 2 +- .../Kestrel.Transport.Abstractions.csproj | 3 + .../Internal/LibuvConnection.cs | 6 +- .../Internal/LibuvConnectionContext.cs | 3 +- .../Internal/LibuvOutputConsumer.cs | 2 +- .../Internal/LibuvThread.cs | 6 +- .../Internal/Networking/UvWriteReq.cs | 4 +- .../Internal/SocketConnection.cs | 29 +- .../Internal/SocketSender.cs | 4 +- .../SocketTransport.cs | 2 +- src/Protocols.Abstractions/DuplexPipe.cs | 2 +- .../Features/IConnectionTransportFeature.cs | 2 +- .../Protocols.Abstractions.csproj | 1 - .../ConnectionHandlerTests.cs | 4 +- .../Http1ConnectionTests.cs | 7 +- .../Http2ConnectionTests.cs | 3 +- .../Kestrel.Core.Tests/HttpConnectionTests.cs | 5 +- test/Kestrel.Core.Tests/HttpParserTests.cs | 38 +- .../HttpProtocolFeatureCollectionTests.cs | 5 +- .../HttpResponseHeadersTests.cs | 3 +- .../Kestrel.Core.Tests/OutputProducerTests.cs | 5 +- test/Kestrel.Core.Tests/PipeOptionsTests.cs | 6 +- .../PipelineExtensionTests.cs | 23 +- test/Kestrel.Core.Tests/TestInput.cs | 9 +- .../LibuvOutputConsumerTests.cs | 6 +- .../MultipleLoopTests.cs | 2 +- .../NetworkingTests.cs | 2 +- .../TestHelpers/MockConnectionHandler.cs | 4 +- tools/CodeGenerator/KnownHeaders.cs | 2 +- 68 files changed, 715 insertions(+), 258 deletions(-) create mode 100644 src/Kestrel.Core/Internal/Http/UrlDecoder.cs create mode 100644 src/Kestrel.Transport.Abstractions/Internal/KestrelMemoryPool.cs diff --git a/Directory.Build.props b/Directory.Build.props index 170752b08d..ca80f126d5 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -17,5 +17,7 @@ true true latest + + false diff --git a/benchmarks/Kestrel.Performance/Http1ConnectionParsingOverheadBenchmark.cs b/benchmarks/Kestrel.Performance/Http1ConnectionParsingOverheadBenchmark.cs index ff3fa369bf..4d3f9ec311 100644 --- a/benchmarks/Kestrel.Performance/Http1ConnectionParsingOverheadBenchmark.cs +++ b/benchmarks/Kestrel.Performance/Http1ConnectionParsingOverheadBenchmark.cs @@ -9,6 +9,7 @@ using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Performance.Mocks; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; namespace Microsoft.AspNetCore.Server.Kestrel.Performance { @@ -16,13 +17,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance { private const int InnerLoopCount = 512; - public ReadOnlyBuffer _buffer; + public ReadOnlySequence _buffer; public Http1Connection _http1Connection; [IterationSetup] public void Setup() { - var memoryPool = new MemoryPool(); + var memoryPool = KestrelMemoryPool.Create(); var pair = DuplexPipe.CreateConnectionPair(memoryPool); var serviceContext = new ServiceContext diff --git a/benchmarks/Kestrel.Performance/Http1WritingBenchmark.cs b/benchmarks/Kestrel.Performance/Http1WritingBenchmark.cs index 1f00d1e6cf..d3137dac17 100644 --- a/benchmarks/Kestrel.Performance/Http1WritingBenchmark.cs +++ b/benchmarks/Kestrel.Performance/Http1WritingBenchmark.cs @@ -12,6 +12,7 @@ using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; using Microsoft.AspNetCore.Testing; namespace Microsoft.AspNetCore.Server.Kestrel.Performance @@ -24,15 +25,17 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance private static readonly Task _psuedoAsyncTask = Task.FromResult(27); private static readonly Func _psuedoAsyncTaskFunc = (obj) => _psuedoAsyncTask; - private readonly TestHttp1Connection _http1Connection; + private TestHttp1Connection _http1Connection; private DuplexPipe.DuplexPipePair _pair; + private MemoryPool _memoryPool; - private readonly byte[] _writeData; + private readonly byte[] _writeData = Encoding.ASCII.GetBytes("Hello, World!"); - public Http1WritingBenchmark() + [GlobalSetup] + public void GlobalSetup() { + _memoryPool = KestrelMemoryPool.Create(); _http1Connection = MakeHttp1Connection(); - _writeData = Encoding.ASCII.GetBytes("Hello, World!"); } [Params(true, false)] @@ -93,33 +96,30 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance private TestHttp1Connection MakeHttp1Connection() { - using (var memoryPool = new MemoryPool()) + var pair = DuplexPipe.CreateConnectionPair(_memoryPool); + _pair = pair; + + var serviceContext = new ServiceContext { - var pair = DuplexPipe.CreateConnectionPair(memoryPool); - _pair = pair; + DateHeaderValueManager = new DateHeaderValueManager(), + ServerOptions = new KestrelServerOptions(), + Log = new MockTrace(), + HttpParser = new HttpParser() + }; - var serviceContext = new ServiceContext - { - DateHeaderValueManager = new DateHeaderValueManager(), - ServerOptions = new KestrelServerOptions(), - Log = new MockTrace(), - HttpParser = new HttpParser() - }; + var http1Connection = new TestHttp1Connection(new Http1ConnectionContext + { + ServiceContext = serviceContext, + ConnectionFeatures = new FeatureCollection(), + MemoryPool = _memoryPool, + Application = pair.Application, + Transport = pair.Transport + }); - var http1Connection = new TestHttp1Connection(new Http1ConnectionContext - { - ServiceContext = serviceContext, - ConnectionFeatures = new FeatureCollection(), - MemoryPool = memoryPool, - Application = pair.Application, - Transport = pair.Transport - }); + http1Connection.Reset(); + http1Connection.InitializeStreams(MessageBody.ZeroContentLengthKeepAlive); - http1Connection.Reset(); - http1Connection.InitializeStreams(MessageBody.ZeroContentLengthKeepAlive); - - return http1Connection; - } + return http1Connection; } [IterationCleanup] @@ -138,5 +138,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance Sync, Async } + + [GlobalCleanup] + public void Dispose() + { + _memoryPool?.Dispose(); + } } } diff --git a/benchmarks/Kestrel.Performance/HttpParserBenchmark.cs b/benchmarks/Kestrel.Performance/HttpParserBenchmark.cs index 5b02d38a93..bb14ffb537 100644 --- a/benchmarks/Kestrel.Performance/HttpParserBenchmark.cs +++ b/benchmarks/Kestrel.Performance/HttpParserBenchmark.cs @@ -12,7 +12,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance { private readonly HttpParser _parser = new HttpParser(); - private ReadOnlyBuffer _buffer; + private ReadOnlySequence _buffer; [Benchmark(Baseline = true, OperationsPerInvoke = RequestParsingData.InnerLoopCount)] public void PlaintextTechEmpower() @@ -46,7 +46,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance private void InsertData(byte[] data) { - _buffer = new ReadOnlyBuffer(data); + _buffer = new ReadOnlySequence(data); } private void ParseData() diff --git a/benchmarks/Kestrel.Performance/HttpProtocolFeatureCollection.cs b/benchmarks/Kestrel.Performance/HttpProtocolFeatureCollection.cs index 69f07faf3e..081d17dc79 100644 --- a/benchmarks/Kestrel.Performance/HttpProtocolFeatureCollection.cs +++ b/benchmarks/Kestrel.Performance/HttpProtocolFeatureCollection.cs @@ -12,6 +12,7 @@ using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; namespace Microsoft.AspNetCore.Server.Kestrel.Performance { @@ -78,7 +79,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance public HttpProtocolFeatureCollection() { - var memoryPool = new MemoryPool(); + var memoryPool = KestrelMemoryPool.Create(); var pair = DuplexPipe.CreateConnectionPair(memoryPool); var serviceContext = new ServiceContext diff --git a/benchmarks/Kestrel.Performance/Mocks/NullParser.cs b/benchmarks/Kestrel.Performance/Mocks/NullParser.cs index 60bab155a0..99564a460b 100644 --- a/benchmarks/Kestrel.Performance/Mocks/NullParser.cs +++ b/benchmarks/Kestrel.Performance/Mocks/NullParser.cs @@ -22,7 +22,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance public static readonly NullParser Instance = new NullParser(); - public bool ParseHeaders(TRequestHandler handler, ReadOnlyBuffer buffer, out SequencePosition consumed, out SequencePosition examined, out int consumedBytes) + public bool ParseHeaders(TRequestHandler handler, ReadOnlySequence buffer, out SequencePosition consumed, out SequencePosition examined, out int consumedBytes) { handler.OnHeader(new Span(_hostHeaderName), new Span(_hostHeaderValue)); handler.OnHeader(new Span(_acceptHeaderName), new Span(_acceptHeaderValue)); @@ -35,7 +35,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance return true; } - public bool ParseRequestLine(TRequestHandler handler, ReadOnlyBuffer buffer, out SequencePosition consumed, out SequencePosition examined) + public bool ParseRequestLine(TRequestHandler handler, ReadOnlySequence buffer, out SequencePosition consumed, out SequencePosition examined) { handler.OnStartLine(HttpMethod.Get, HttpVersion.Http11, diff --git a/benchmarks/Kestrel.Performance/PipeThroughputBenchmark.cs b/benchmarks/Kestrel.Performance/PipeThroughputBenchmark.cs index 80e331ea5a..b647567715 100644 --- a/benchmarks/Kestrel.Performance/PipeThroughputBenchmark.cs +++ b/benchmarks/Kestrel.Performance/PipeThroughputBenchmark.cs @@ -1,10 +1,12 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; using System.Buffers; using System.IO.Pipelines; using System.Threading.Tasks; using BenchmarkDotNet.Attributes; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; namespace Microsoft.AspNetCore.Server.Kestrel.Performance { @@ -14,12 +16,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance private const int InnerLoopCount = 512; private Pipe _pipe; - private MemoryPool _memoryPool; + private MemoryPool _memoryPool; [IterationSetup] public void Setup() { - _memoryPool = new MemoryPool(); + _memoryPool = KestrelMemoryPool.Create(); _pipe = new Pipe(new PipeOptions(_memoryPool)); } @@ -62,5 +64,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance _pipe.Reader.AdvanceTo(result.Buffer.End, result.Buffer.End); } } + + [IterationCleanup] + public void Cleanup() + { + _memoryPool.Dispose(); + } } } diff --git a/benchmarks/Kestrel.Performance/RequestParsingBenchmark.cs b/benchmarks/Kestrel.Performance/RequestParsingBenchmark.cs index c682553483..e6ea256d01 100644 --- a/benchmarks/Kestrel.Performance/RequestParsingBenchmark.cs +++ b/benchmarks/Kestrel.Performance/RequestParsingBenchmark.cs @@ -9,11 +9,14 @@ using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Performance.Mocks; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; namespace Microsoft.AspNetCore.Server.Kestrel.Performance { public class RequestParsingBenchmark { + private MemoryPool _memoryPool; + public Pipe Pipe { get; set; } public Http1Connection Http1Connection { get; set; } @@ -21,8 +24,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance [IterationSetup] public void Setup() { - var memoryPool = new MemoryPool(); - var pair = DuplexPipe.CreateConnectionPair(memoryPool); + _memoryPool = KestrelMemoryPool.Create(); + var pair = DuplexPipe.CreateConnectionPair(_memoryPool); var serviceContext = new ServiceContext { @@ -36,7 +39,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance { ServiceContext = serviceContext, ConnectionFeatures = new FeatureCollection(), - MemoryPool = memoryPool, + MemoryPool = _memoryPool, Application = pair.Application, Transport = pair.Transport, TimeoutControl = new MockTimeoutControl() @@ -45,7 +48,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance http1Connection.Reset(); Http1Connection = http1Connection; - Pipe = new Pipe(new PipeOptions(memoryPool)); + Pipe = new Pipe(new PipeOptions(_memoryPool)); } [Benchmark(Baseline = true, OperationsPerInvoke = RequestParsingData.InnerLoopCount)] @@ -201,5 +204,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance } while (true); } + + + [IterationCleanup] + public void Cleanup() + { + _memoryPool.Dispose(); + } } } diff --git a/benchmarks/Kestrel.Performance/ResponseHeaderCollectionBenchmark.cs b/benchmarks/Kestrel.Performance/ResponseHeaderCollectionBenchmark.cs index dd6cd25cf4..b36f674ba4 100644 --- a/benchmarks/Kestrel.Performance/ResponseHeaderCollectionBenchmark.cs +++ b/benchmarks/Kestrel.Performance/ResponseHeaderCollectionBenchmark.cs @@ -12,6 +12,7 @@ using Microsoft.AspNetCore.Http.Internal; using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; namespace Microsoft.AspNetCore.Server.Kestrel.Performance { @@ -170,7 +171,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance [IterationSetup] public void Setup() { - var memoryPool = new MemoryPool(); + var memoryPool = KestrelMemoryPool.Create(); var pair = DuplexPipe.CreateConnectionPair(memoryPool); var serviceContext = new ServiceContext diff --git a/benchmarks/Kestrel.Performance/ResponseHeadersWritingBenchmark.cs b/benchmarks/Kestrel.Performance/ResponseHeadersWritingBenchmark.cs index 8c7c3b46be..67b3705238 100644 --- a/benchmarks/Kestrel.Performance/ResponseHeadersWritingBenchmark.cs +++ b/benchmarks/Kestrel.Performance/ResponseHeadersWritingBenchmark.cs @@ -13,6 +13,7 @@ using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Performance.Mocks; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; using Microsoft.AspNetCore.Testing; namespace Microsoft.AspNetCore.Server.Kestrel.Performance @@ -23,6 +24,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance private TestHttp1Connection _http1Connection; + private MemoryPool _memoryPool; + [Params( BenchmarkTypes.TechEmpowerPlaintext, BenchmarkTypes.PlaintextChunked, @@ -110,8 +113,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance [IterationSetup] public void Setup() { - var memoryPool = new MemoryPool(); - var pair = DuplexPipe.CreateConnectionPair(memoryPool); + _memoryPool = KestrelMemoryPool.Create(); + var pair = DuplexPipe.CreateConnectionPair(_memoryPool); var serviceContext = new ServiceContext { @@ -125,7 +128,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance { ServiceContext = serviceContext, ConnectionFeatures = new FeatureCollection(), - MemoryPool = memoryPool, + MemoryPool = _memoryPool, TimeoutControl = new MockTimeoutControl(), Application = pair.Application, Transport = pair.Transport @@ -136,6 +139,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance _http1Connection = http1Connection; } + [IterationCleanup] + public void Cleanup() + { + _memoryPool.Dispose(); + } + public enum BenchmarkTypes { TechEmpowerPlaintext, diff --git a/build/dependencies.props b/build/dependencies.props index b58d70b16c..f05fd787d5 100644 --- a/build/dependencies.props +++ b/build/dependencies.props @@ -5,40 +5,39 @@ 0.10.11 - 2.1.0-preview2-15721 + 2.1.0-preview2-15707 1.10.0 - 2.1.0-preview2-30187 - 2.1.0-preview2-30187 - 2.1.0-preview2-30187 - 2.1.0-preview2-30187 - 2.1.0-preview2-30187 - 2.1.0-preview2-30187 - 2.1.0-preview2-30187 - 2.1.0-preview2-30187 - 2.1.0-preview2-30187 - 2.1.0-preview2-30187 - 2.1.0-preview2-30187 - 2.1.0-preview2-30187 - 2.1.0-preview2-30187 - 2.1.0-preview2-30187 - 2.1.0-preview2-30187 - 2.1.0-preview2-30187 - 2.1.0-preview2-30187 + 2.1.0-preview2-30131 + 2.1.0-preview2-30131 + 2.1.0-preview2-30131 + 2.1.0-preview2-30131 + 2.1.0-preview2-30131 + 2.1.0-preview2-30131 + 2.1.0-preview2-30131 + 2.1.0-preview2-30131 + 2.1.0-preview2-30131 + 2.1.0-preview2-t000 + 2.1.0-preview2-30131 + 2.1.0-preview2-30131 + 2.1.0-preview2-30131 + 2.1.0-preview2-30131 + 2.1.0-preview2-30131 + 2.1.0-preview2-30131 + 2.1.0-preview2-30131 + 2.1.0-preview2-30131 2.0.0 - 2.1.0-preview2-26130-04 - 2.1.0-preview2-30187 - 15.6.0 + 2.1.0-preview2-26225-03 + 2.1.0-preview2-30131 + 15.3.0 4.7.49 10.0.1 - 4.5.0-preview2-26130-01 - 0.1.0-preview2-180130-1 - 0.1.0-preview2-180130-1 - 4.5.0-preview2-26130-01 - 4.5.0-preview2-26130-01 - 4.5.0-preview2-26130-01 - 4.5.0-preview2-26130-01 - 0.1.0-preview2-180130-1 - 4.5.0-preview2-26130-01 + 4.5.0-preview2-26224-02 + 4.5.0-preview2-26224-02 + 4.5.0-preview2-26224-02 + 4.5.0-preview2-26224-02 + 4.5.0-preview2-26224-02 + 4.5.0-preview2-26224-02 + 4.5.0-preview2-26224-02 0.8.0 2.3.1 2.4.0-beta.1.build3945 diff --git a/src/Kestrel.Core/Adapter/Internal/AdaptedPipeline.cs b/src/Kestrel.Core/Adapter/Internal/AdaptedPipeline.cs index 4204469241..522768e270 100644 --- a/src/Kestrel.Core/Adapter/Internal/AdaptedPipeline.cs +++ b/src/Kestrel.Core/Adapter/Internal/AdaptedPipeline.cs @@ -62,7 +62,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal try { - if (result.IsCancelled) + if (result.IsCanceled) { // Forward the cancellation to the transport pipe _application.Input.CancelPendingRead(); @@ -132,26 +132,18 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal { var outputBuffer = Input.Writer.GetMemory(MinAllocBufferSize); - - try - { #if NETCOREAPP2_1 - var bytesRead = await stream.ReadAsync(outputBuffer); + var bytesRead = await stream.ReadAsync(outputBuffer); #else - var array = outputBuffer.GetArray(); - var bytesRead = await stream.ReadAsync(array.Array, array.Offset, array.Count); + var array = outputBuffer.GetArray(); + var bytesRead = await stream.ReadAsync(array.Array, array.Offset, array.Count); #endif - Input.Writer.Advance(bytesRead); + Input.Writer.Advance(bytesRead); - if (bytesRead == 0) - { - // FIN - break; - } - } - finally + if (bytesRead == 0) { - Input.Writer.Commit(); + // FIN + break; } var result = await Input.Writer.FlushAsync(); @@ -160,7 +152,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal { break; } - } } catch (Exception ex) diff --git a/src/Kestrel.Core/Internal/ConnectionHandler.cs b/src/Kestrel.Core/Internal/ConnectionHandler.cs index 41607602d4..8cd9552522 100644 --- a/src/Kestrel.Core/Internal/ConnectionHandler.cs +++ b/src/Kestrel.Core/Internal/ConnectionHandler.cs @@ -83,7 +83,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal } // Internal for testing - internal static PipeOptions GetInputPipeOptions(ServiceContext serviceContext, MemoryPool memoryPool, PipeScheduler writerScheduler) => new PipeOptions + internal static PipeOptions GetInputPipeOptions(ServiceContext serviceContext, MemoryPool memoryPool, PipeScheduler writerScheduler) => new PipeOptions ( pool: memoryPool, readerScheduler: serviceContext.ThreadPool, @@ -92,7 +92,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal resumeWriterThreshold: serviceContext.ServerOptions.Limits.MaxRequestBufferSize ?? 0 ); - internal static PipeOptions GetOutputPipeOptions(ServiceContext serviceContext, MemoryPool memoryPool, PipeScheduler readerScheduler) => new PipeOptions + internal static PipeOptions GetOutputPipeOptions(ServiceContext serviceContext, MemoryPool memoryPool, PipeScheduler readerScheduler) => new PipeOptions ( pool: memoryPool, readerScheduler: readerScheduler, diff --git a/src/Kestrel.Core/Internal/Http/ChunkWriter.cs b/src/Kestrel.Core/Internal/Http/ChunkWriter.cs index d37f6d48df..3d8cc4566b 100644 --- a/src/Kestrel.Core/Internal/Http/ChunkWriter.cs +++ b/src/Kestrel.Core/Internal/Http/ChunkWriter.cs @@ -8,7 +8,7 @@ using System.Text; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { - public static class ChunkWriter + internal static class ChunkWriter { private static readonly ArraySegment _endChunkBytes = CreateAsciiByteArraySegment("\r\n"); private static readonly byte[] _hex = Encoding.ASCII.GetBytes("0123456789abcdef"); @@ -48,14 +48,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http return new ArraySegment(bytes, offset, 10 - offset); } - public static int WriteBeginChunkBytes(ref OutputWriter start, int dataCount) + internal static int WriteBeginChunkBytes(ref BufferWriter start, int dataCount) { var chunkSegment = BeginChunkBytes(dataCount); start.Write(new ReadOnlySpan(chunkSegment.Array, chunkSegment.Offset, chunkSegment.Count)); return chunkSegment.Count; } - public static void WriteEndChunkBytes(ref OutputWriter start) + internal static void WriteEndChunkBytes(ref BufferWriter start) { start.Write(new ReadOnlySpan(_endChunkBytes.Array, _endChunkBytes.Offset, _endChunkBytes.Count)); } diff --git a/src/Kestrel.Core/Internal/Http/Http1Connection.cs b/src/Kestrel.Core/Internal/Http/Http1Connection.cs index 142902a8de..c8bab28d31 100644 --- a/src/Kestrel.Core/Internal/Http/Http1Connection.cs +++ b/src/Kestrel.Core/Internal/Http/Http1Connection.cs @@ -8,9 +8,10 @@ using System.Diagnostics; using System.IO.Pipelines; using System.Runtime.InteropServices; using System.Text; -using System.Text.Encodings.Web.Utf8; +using System.Text.Encodings.Web; using System.Threading; using Microsoft.AspNetCore.Http.Features; +using Microsoft.AspNetCore.Protocols.Abstractions; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http @@ -69,7 +70,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http Input.CancelPendingRead(); } - public void ParseRequest(ReadOnlyBuffer buffer, out SequencePosition consumed, out SequencePosition examined) + public void ParseRequest(ReadOnlySequence buffer, out SequencePosition consumed, out SequencePosition examined) { consumed = buffer.Start; examined = buffer.End; @@ -107,7 +108,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http } } - public bool TakeStartLine(ReadOnlyBuffer buffer, out SequencePosition consumed, out SequencePosition examined) + public bool TakeStartLine(ReadOnlySequence buffer, out SequencePosition consumed, out SequencePosition examined) { var overLength = false; if (buffer.Length >= ServerOptions.Limits.MaxRequestLineSize) @@ -125,7 +126,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http return result; } - public bool TakeMessageHeaders(ReadOnlyBuffer buffer, out SequencePosition consumed, out SequencePosition examined) + public bool TakeMessageHeaders(ReadOnlySequence buffer, out SequencePosition consumed, out SequencePosition examined) { // Make sure the buffer is limited bool overLength = false; @@ -217,9 +218,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { // URI was encoded, unescape and then parse as UTF-8 // Disabling warning temporary -#pragma warning disable 618 - var pathLength = UrlEncoder.Decode(path, path); -#pragma warning restore 618 + var pathLength = UrlDecoder.Decode(path, path); // Removing dot segments must be done after unescaping. From RFC 3986: // @@ -430,7 +429,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http TimeoutControl.SetTimeout(_keepAliveTicks, TimeoutAction.StopProcessingNextRequest); } - protected override bool BeginRead(out ValueAwaiter awaitable) + protected override bool BeginRead(out PipeAwaiter awaitable) { awaitable = Input.ReadAsync(); return true; diff --git a/src/Kestrel.Core/Internal/Http/Http1ConnectionContext.cs b/src/Kestrel.Core/Internal/Http/Http1ConnectionContext.cs index b88bb4bedb..9dbcee29e7 100644 --- a/src/Kestrel.Core/Internal/Http/Http1ConnectionContext.cs +++ b/src/Kestrel.Core/Internal/Http/Http1ConnectionContext.cs @@ -14,7 +14,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http public string ConnectionId { get; set; } public ServiceContext ServiceContext { get; set; } public IFeatureCollection ConnectionFeatures { get; set; } - public MemoryPool MemoryPool { get; set; } + public MemoryPool MemoryPool { get; set; } public IPEndPoint RemoteEndPoint { get; set; } public IPEndPoint LocalEndPoint { get; set; } public ITimeoutControl TimeoutControl { get; set; } diff --git a/src/Kestrel.Core/Internal/Http/Http1MessageBody.cs b/src/Kestrel.Core/Internal/Http/Http1MessageBody.cs index 4eb3f8928d..1e7f3caf2d 100644 --- a/src/Kestrel.Core/Internal/Http/Http1MessageBody.cs +++ b/src/Kestrel.Core/Internal/Http/Http1MessageBody.cs @@ -8,6 +8,7 @@ using System.IO; using System.IO.Pipelines; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Protocols.Abstractions; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http @@ -63,15 +64,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http if (!readableBuffer.IsEmpty) { bool done; - - try - { - done = Read(readableBuffer, _context.RequestBodyPipe.Writer, out consumed, out examined); - } - finally - { - _context.RequestBodyPipe.Writer.Commit(); - } + done = Read(readableBuffer, _context.RequestBodyPipe.Writer, out consumed, out examined); var writeAwaitable = _context.RequestBodyPipe.Writer.FlushAsync(); var backpressure = false; @@ -150,7 +143,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http } } - protected void Copy(ReadOnlyBuffer readableBuffer, PipeWriter writableBuffer) + protected void Copy(ReadOnlySequence readableBuffer, PipeWriter writableBuffer) { _context.TimeoutControl.BytesRead(readableBuffer.Length); @@ -172,7 +165,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http _pumpTask = PumpAsync(); } - protected virtual bool Read(ReadOnlyBuffer readableBuffer, PipeWriter writableBuffer, out SequencePosition consumed, out SequencePosition examined) + protected virtual bool Read(ReadOnlySequence readableBuffer, PipeWriter writableBuffer, out SequencePosition consumed, out SequencePosition examined) { throw new NotImplementedException(); } @@ -295,7 +288,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http public override bool IsEmpty => true; - protected override bool Read(ReadOnlyBuffer readableBuffer, PipeWriter writableBuffer, out SequencePosition consumed, out SequencePosition examined) + protected override bool Read(ReadOnlySequence readableBuffer, PipeWriter writableBuffer, out SequencePosition consumed, out SequencePosition examined) { Copy(readableBuffer, writableBuffer); consumed = readableBuffer.End; @@ -317,7 +310,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http _inputLength = _contentLength; } - protected override bool Read(ReadOnlyBuffer readableBuffer, PipeWriter writableBuffer, out SequencePosition consumed, out SequencePosition examined) + protected override bool Read(ReadOnlySequence readableBuffer, PipeWriter writableBuffer, out SequencePosition consumed, out SequencePosition examined) { if (_inputLength == 0) { @@ -365,7 +358,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http RequestKeepAlive = keepAlive; } - protected override bool Read(ReadOnlyBuffer readableBuffer, PipeWriter writableBuffer, out SequencePosition consumed, out SequencePosition examined) + protected override bool Read(ReadOnlySequence readableBuffer, PipeWriter writableBuffer, out SequencePosition consumed, out SequencePosition examined) { consumed = default(SequencePosition); examined = default(SequencePosition); @@ -456,11 +449,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http } } - private void ParseChunkedPrefix(ReadOnlyBuffer buffer, out SequencePosition consumed, out SequencePosition examined) + private void ParseChunkedPrefix(ReadOnlySequence buffer, out SequencePosition consumed, out SequencePosition examined) { consumed = buffer.Start; examined = buffer.Start; - var reader = BufferReader.Create(buffer); + var reader = new BufferReader(buffer); var ch1 = reader.Read(); var ch2 = reader.Read(); @@ -512,7 +505,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http BadHttpRequestException.Throw(RequestRejectionReason.BadChunkSizeData); } - private void ParseExtension(ReadOnlyBuffer buffer, out SequencePosition consumed, out SequencePosition examined) + private void ParseExtension(ReadOnlySequence buffer, out SequencePosition consumed, out SequencePosition examined) { // Chunk-extensions not currently parsed // Just drain the data @@ -565,7 +558,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http } while (_mode == Mode.Extension); } - private void ReadChunkedData(ReadOnlyBuffer buffer, PipeWriter writableBuffer, out SequencePosition consumed, out SequencePosition examined) + private void ReadChunkedData(ReadOnlySequence buffer, PipeWriter writableBuffer, out SequencePosition consumed, out SequencePosition examined) { var actual = Math.Min(buffer.Length, _inputLength); consumed = buffer.GetPosition(buffer.Start, actual); @@ -582,7 +575,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http } } - private void ParseChunkedSuffix(ReadOnlyBuffer buffer, out SequencePosition consumed, out SequencePosition examined) + private void ParseChunkedSuffix(ReadOnlySequence buffer, out SequencePosition consumed, out SequencePosition examined) { consumed = buffer.Start; examined = buffer.Start; @@ -608,7 +601,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http } } - private void ParseChunkedTrailer(ReadOnlyBuffer buffer, out SequencePosition consumed, out SequencePosition examined) + private void ParseChunkedTrailer(ReadOnlySequence buffer, out SequencePosition consumed, out SequencePosition examined) { consumed = buffer.Start; examined = buffer.Start; diff --git a/src/Kestrel.Core/Internal/Http/Http1OutputProducer.cs b/src/Kestrel.Core/Internal/Http/Http1OutputProducer.cs index dbc8cf0f52..3ecbf9298f 100644 --- a/src/Kestrel.Core/Internal/Http/Http1OutputProducer.cs +++ b/src/Kestrel.Core/Internal/Http/Http1OutputProducer.cs @@ -84,7 +84,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http var buffer = _pipeWriter; callback(buffer, state); - buffer.Commit(); } } @@ -99,7 +98,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http var buffer = _pipeWriter; callback(buffer, state); - buffer.Commit(); } return FlushAsync(); @@ -115,14 +113,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http } var buffer = _pipeWriter; - var writer = OutputWriter.Create(buffer); + var writer = new BufferWriter(buffer); writer.Write(_bytesHttpVersion11); var statusBytes = ReasonPhrases.ToStatusBytes(statusCode, reasonPhrase); writer.Write(statusBytes); responseHeaders.CopyTo(ref writer); writer.Write(_bytesEndHeaders); - buffer.Commit(); + writer.Commit(); } } @@ -177,14 +175,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http } writableBuffer = _pipeWriter; - var writer = OutputWriter.Create(writableBuffer); + var writer = new BufferWriter(writableBuffer); if (buffer.Length > 0) { writer.Write(buffer); bytesWritten += buffer.Length; } - - writableBuffer.Commit(); + writer.Commit(); } return FlushAsync(writableBuffer, bytesWritten, cancellationToken); @@ -203,7 +200,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http return FlushAsyncAwaited(awaitable, bytesWritten, cancellationToken); } - private async Task FlushAsyncAwaited(ValueAwaiter awaitable, long count, CancellationToken cancellationToken) + private async Task FlushAsyncAwaited(PipeAwaiter awaitable, long count, CancellationToken cancellationToken) { // https://github.com/dotnet/corefxlab/issues/1334 // Since the flush awaitable doesn't currently support multiple awaiters diff --git a/src/Kestrel.Core/Internal/Http/HttpHeaders.Generated.cs b/src/Kestrel.Core/Internal/Http/HttpHeaders.Generated.cs index 704d2216a8..84dc60f624 100644 --- a/src/Kestrel.Core/Internal/Http/HttpHeaders.Generated.cs +++ b/src/Kestrel.Core/Internal/Http/HttpHeaders.Generated.cs @@ -7754,7 +7754,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http return true; } - protected void CopyToFast(ref OutputWriter output) + internal void CopyToFast(ref BufferWriter output) { var tempBits = _bits | (_contentLength.HasValue ? -9223372036854775808L : 0); diff --git a/src/Kestrel.Core/Internal/Http/HttpParser.cs b/src/Kestrel.Core/Internal/Http/HttpParser.cs index 2ca5cdddbf..976841466a 100644 --- a/src/Kestrel.Core/Internal/Http/HttpParser.cs +++ b/src/Kestrel.Core/Internal/Http/HttpParser.cs @@ -7,6 +7,7 @@ using System.Collections; using System.Diagnostics; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; +using Microsoft.AspNetCore.Protocols.Abstractions; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http @@ -33,7 +34,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http private const byte ByteQuestionMark = (byte)'?'; private const byte BytePercentage = (byte)'%'; - public unsafe bool ParseRequestLine(TRequestHandler handler, ReadOnlyBuffer buffer, out SequencePosition consumed, out SequencePosition examined) + public unsafe bool ParseRequestLine(TRequestHandler handler, ReadOnlySequence buffer, out SequencePosition consumed, out SequencePosition examined) { consumed = buffer.Start; examined = buffer.End; @@ -188,7 +189,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http handler.OnStartLine(method, httpVersion, targetBuffer, pathBuffer, query, customMethod, pathEncoded); } - public unsafe bool ParseHeaders(TRequestHandler handler, ReadOnlyBuffer buffer, out SequencePosition consumed, out SequencePosition examined, out int consumedBytes) + public unsafe bool ParseHeaders(TRequestHandler handler, ReadOnlySequence buffer, out SequencePosition consumed, out SequencePosition examined, out int consumedBytes) { consumed = buffer.Start; examined = buffer.End; @@ -196,8 +197,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http var bufferEnd = buffer.End; - var reader = BufferReader.Create(buffer); - var start = default(BufferReader>); + var reader = new BufferReader(buffer); + var start = default(BufferReader); var done = false; try @@ -418,7 +419,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http } [MethodImpl(MethodImplOptions.NoInlining)] - private static bool TryGetNewLine(ref ReadOnlyBuffer buffer, out SequencePosition found) + private static bool TryGetNewLine(ref ReadOnlySequence buffer, out SequencePosition found) { var byteLfPosition = buffer.PositionOf(ByteLF); if (byteLfPosition != null) diff --git a/src/Kestrel.Core/Internal/Http/HttpProtocol.cs b/src/Kestrel.Core/Internal/Http/HttpProtocol.cs index 7839a33cbd..ad90b76a1e 100644 --- a/src/Kestrel.Core/Internal/Http/HttpProtocol.cs +++ b/src/Kestrel.Core/Internal/Http/HttpProtocol.cs @@ -383,7 +383,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { } - protected virtual bool BeginRead(out ValueAwaiter awaitable) + protected virtual bool BeginRead(out PipeAwaiter awaitable) { awaitable = default; return false; @@ -930,12 +930,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http private static void WriteChunk(PipeWriter writableBuffer, ReadOnlyMemory buffer) { - var writer = OutputWriter.Create(writableBuffer); + var writer = new BufferWriter(writableBuffer); if (buffer.Length > 0) { ChunkWriter.WriteBeginChunkBytes(ref writer, buffer.Length); writer.Write(buffer.Span); ChunkWriter.WriteEndChunkBytes(ref writer); + writer.Commit(); } } diff --git a/src/Kestrel.Core/Internal/Http/HttpResponseHeaders.cs b/src/Kestrel.Core/Internal/Http/HttpResponseHeaders.cs index 9a75ff780a..badb63449c 100644 --- a/src/Kestrel.Core/Internal/Http/HttpResponseHeaders.cs +++ b/src/Kestrel.Core/Internal/Http/HttpResponseHeaders.cs @@ -35,9 +35,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http return GetEnumerator(); } - public void CopyTo(ref OutputWriter output) + internal void CopyTo(ref BufferWriter buffer) { - CopyToFast(ref output); + CopyToFast(ref buffer); if (MaybeUnknown != null) { foreach (var kv in MaybeUnknown) @@ -46,10 +46,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { if (value != null) { - output.Write(_CrLf); - PipelineExtensions.WriteAsciiNoValidation(ref output, kv.Key); - output.Write(_colonSpace); - PipelineExtensions.WriteAsciiNoValidation(ref output, value); + buffer.Write(_CrLf); + PipelineExtensions.WriteAsciiNoValidation(ref buffer, kv.Key); + buffer.Write(_colonSpace); + PipelineExtensions.WriteAsciiNoValidation(ref buffer, value); } } } diff --git a/src/Kestrel.Core/Internal/Http/IHttpParser.cs b/src/Kestrel.Core/Internal/Http/IHttpParser.cs index e1978ffb01..2cd77a3cd1 100644 --- a/src/Kestrel.Core/Internal/Http/IHttpParser.cs +++ b/src/Kestrel.Core/Internal/Http/IHttpParser.cs @@ -1,6 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; using System.Buffers; using System.Collections; @@ -8,8 +9,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { public interface IHttpParser where TRequestHandler : IHttpHeadersHandler, IHttpRequestLineHandler { - bool ParseRequestLine(TRequestHandler handler, ReadOnlyBuffer buffer, out SequencePosition consumed, out SequencePosition examined); + bool ParseRequestLine(TRequestHandler handler, ReadOnlySequence buffer, out SequencePosition consumed, out SequencePosition examined); - bool ParseHeaders(TRequestHandler handler, ReadOnlyBuffer buffer, out SequencePosition consumed, out SequencePosition examined, out int consumedBytes); + bool ParseHeaders(TRequestHandler handler, ReadOnlySequence buffer, out SequencePosition consumed, out SequencePosition examined, out int consumedBytes); } } diff --git a/src/Kestrel.Core/Internal/Http/IHttpProtocolContext.cs b/src/Kestrel.Core/Internal/Http/IHttpProtocolContext.cs index c58d97196d..2aa526b867 100644 --- a/src/Kestrel.Core/Internal/Http/IHttpProtocolContext.cs +++ b/src/Kestrel.Core/Internal/Http/IHttpProtocolContext.cs @@ -12,7 +12,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http string ConnectionId { get; set; } ServiceContext ServiceContext { get; set; } IFeatureCollection ConnectionFeatures { get; set; } - MemoryPool MemoryPool { get; set; } + MemoryPool MemoryPool { get; set; } IPEndPoint RemoteEndPoint { get; set; } IPEndPoint LocalEndPoint { get; set; } } diff --git a/src/Kestrel.Core/Internal/Http/MessageBody.cs b/src/Kestrel.Core/Internal/Http/MessageBody.cs index ad330f2c92..2ebf6f1212 100644 --- a/src/Kestrel.Core/Internal/Http/MessageBody.cs +++ b/src/Kestrel.Core/Internal/Http/MessageBody.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Buffers; using System.IO; using System.Threading; using System.Threading.Tasks; diff --git a/src/Kestrel.Core/Internal/Http/PipelineExtensions.cs b/src/Kestrel.Core/Internal/Http/PipelineExtensions.cs index 4caefd3a95..b5a2664bda 100644 --- a/src/Kestrel.Core/Internal/Http/PipelineExtensions.cs +++ b/src/Kestrel.Core/Internal/Http/PipelineExtensions.cs @@ -17,7 +17,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http private static byte[] _numericBytesScratch; [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static ReadOnlySpan ToSpan(this ReadOnlyBuffer buffer) + public static ReadOnlySpan ToSpan(this ReadOnlySequence buffer) { if (buffer.IsSingleSegment) { @@ -45,7 +45,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http return result; } - public unsafe static void WriteAsciiNoValidation(ref this OutputWriter buffer, string data) + internal static unsafe void WriteAsciiNoValidation(ref this BufferWriter buffer, string data) { if (string.IsNullOrEmpty(data)) { @@ -74,7 +74,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public unsafe static void WriteNumeric(ref this OutputWriter buffer, ulong number) + internal static unsafe void WriteNumeric(ref this BufferWriter buffer, ulong number) { const byte AsciiDigitStart = (byte)'0'; @@ -124,7 +124,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http } [MethodImpl(MethodImplOptions.NoInlining)] - private static void WriteNumericMultiWrite(ref this OutputWriter buffer, ulong number) + private static void WriteNumericMultiWrite(ref this BufferWriter buffer, ulong number) { const byte AsciiDigitStart = (byte)'0'; @@ -145,7 +145,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http } [MethodImpl(MethodImplOptions.NoInlining)] - private unsafe static void WriteAsciiMultiWrite(ref this OutputWriter buffer, string data) + private unsafe static void WriteAsciiMultiWrite(ref this BufferWriter buffer, string data) { var remaining = data.Length; @@ -176,7 +176,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http } } - private unsafe static void EncodeAsciiCharsToBytes(char* input, byte* output, int length) + private static unsafe void EncodeAsciiCharsToBytes(char* input, byte* output, int length) { // Note: Not BIGENDIAN or check for non-ascii const int Shift16Shift24 = (1 << 16) | (1 << 24); diff --git a/src/Kestrel.Core/Internal/Http/UrlDecoder.cs b/src/Kestrel.Core/Internal/Http/UrlDecoder.cs new file mode 100644 index 0000000000..fcdb3cfef6 --- /dev/null +++ b/src/Kestrel.Core/Internal/Http/UrlDecoder.cs @@ -0,0 +1,411 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; + +namespace Microsoft.AspNetCore.Protocols.Abstractions +{ + internal class UrlDecoder + { + static bool[] IsAllowed = new bool[0x7F + 1]; + + /// + /// Unescape a URL path + /// + /// The byte span represents a UTF8 encoding url path. + /// The byte span where unescaped url path is copied to. + /// The length of the byte sequence of the unescaped url path. + public static int Decode(ReadOnlySpan source, Span destination) + { + if (destination.Length < source.Length) + { + throw new ArgumentException( + "Lenghth of the destination byte span is less then the source.", + nameof(destination)); + } + + // This requires the destination span to be larger or equal to source span + source.CopyTo(destination); + return DecodeInPlace(destination); + } + + /// + /// Unescape a URL path in place. + /// + /// The byte span represents a UTF8 encoding url path. + /// The number of the bytes representing the result. + /// + /// The unescape is done in place, which means after decoding the result is the subset of + /// the input span. + /// + public static int DecodeInPlace(Span buffer) + { + // the slot to read the input + var sourceIndex = 0; + + // the slot to write the unescaped byte + var destinationIndex = 0; + + while (true) + { + if (sourceIndex == buffer.Length) + { + break; + } + + if (buffer[sourceIndex] == '%') + { + var decodeIndex = sourceIndex; + + // If decoding process succeeds, the writer iterator will be moved + // to the next write-ready location. On the other hand if the scanned + // percent-encodings cannot be interpreted as sequence of UTF-8 octets, + // these bytes should be copied to output as is. + // The decodeReader iterator is always moved to the first byte not yet + // be scanned after the process. A failed decoding means the chars + // between the reader and decodeReader can be copied to output untouched. + if (!DecodeCore(ref decodeIndex, ref destinationIndex, buffer)) + { + Copy(sourceIndex, decodeIndex, ref destinationIndex, buffer); + } + + sourceIndex = decodeIndex; + } + else + { + buffer[destinationIndex++] = buffer[sourceIndex++]; + } + } + + return destinationIndex; + } + + /// + /// Unescape the percent-encodings + /// + /// The iterator point to the first % char + /// The place to write to + /// The byte array + private static bool DecodeCore(ref int sourceIndex, ref int destinationIndex, Span buffer) + { + // preserves the original head. if the percent-encodings cannot be interpreted as sequence of UTF-8 octets, + // bytes from this till the last scanned one will be copied to the memory pointed by writer. + var byte1 = UnescapePercentEncoding(ref sourceIndex, buffer); + if (byte1 == -1) + { + return false; + } + + if (byte1 == 0) + { + throw new InvalidOperationException("The path contains null characters."); + } + + if (byte1 <= 0x7F) + { + // first byte < U+007f, it is a single byte ASCII + buffer[destinationIndex++] = (byte)byte1; + return true; + } + + int byte2 = 0, byte3 = 0, byte4 = 0; + + // anticipate more bytes + var currentDecodeBits = 0; + var byteCount = 1; + var expectValueMin = 0; + if ((byte1 & 0xE0) == 0xC0) + { + // 110x xxxx, expect one more byte + currentDecodeBits = byte1 & 0x1F; + byteCount = 2; + expectValueMin = 0x80; + } + else if ((byte1 & 0xF0) == 0xE0) + { + // 1110 xxxx, expect two more bytes + currentDecodeBits = byte1 & 0x0F; + byteCount = 3; + expectValueMin = 0x800; + } + else if ((byte1 & 0xF8) == 0xF0) + { + // 1111 0xxx, expect three more bytes + currentDecodeBits = byte1 & 0x07; + byteCount = 4; + expectValueMin = 0x10000; + } + else + { + // invalid first byte + return false; + } + + var remainingBytes = byteCount - 1; + while (remainingBytes > 0) + { + // read following three chars + if (sourceIndex == buffer.Length) + { + return false; + } + + var nextSourceIndex = sourceIndex; + var nextByte = UnescapePercentEncoding(ref nextSourceIndex, buffer); + if (nextByte == -1) + { + return false; + } + + if ((nextByte & 0xC0) != 0x80) + { + // the follow up byte is not in form of 10xx xxxx + return false; + } + + currentDecodeBits = (currentDecodeBits << 6) | (nextByte & 0x3F); + remainingBytes--; + + if (remainingBytes == 1 && currentDecodeBits >= 0x360 && currentDecodeBits <= 0x37F) + { + // this is going to end up in the range of 0xD800-0xDFFF UTF-16 surrogates that + // are not allowed in UTF-8; + return false; + } + + if (remainingBytes == 2 && currentDecodeBits >= 0x110) + { + // this is going to be out of the upper Unicode bound 0x10FFFF. + return false; + } + + sourceIndex = nextSourceIndex; + if (byteCount - remainingBytes == 2) + { + byte2 = nextByte; + } + else if (byteCount - remainingBytes == 3) + { + byte3 = nextByte; + } + else if (byteCount - remainingBytes == 4) + { + byte4 = nextByte; + } + } + + if (currentDecodeBits < expectValueMin) + { + // overlong encoding (e.g. using 2 bytes to encode something that only needed 1). + return false; + } + + // all bytes are verified, write to the output + // TODO: measure later to determine if the performance of following logic can be improved + // the idea is to combine the bytes into short/int and write to span directly to avoid + // range check cost + if (byteCount > 0) + { + buffer[destinationIndex++] = (byte)byte1; + } + if (byteCount > 1) + { + buffer[destinationIndex++] = (byte)byte2; + } + if (byteCount > 2) + { + buffer[destinationIndex++] = (byte)byte3; + } + if (byteCount > 3) + { + buffer[destinationIndex++] = (byte)byte4; + } + + return true; + } + + private static void Copy(int begin, int end, ref int writer, Span buffer) + { + while (begin != end) + { + buffer[writer++] = buffer[begin++]; + } + } + + /// + /// Read the percent-encoding and try unescape it. + /// + /// The operation first peek at the character the + /// iterator points at. If it is % the is then + /// moved on to scan the following to characters. If the two following + /// characters are hexadecimal literals they will be unescaped and the + /// value will be returned. + /// + /// If the first character is not % the iterator + /// will be removed beyond the location of % and -1 will be returned. + /// + /// If the following two characters can't be successfully unescaped the + /// iterator will be move behind the % and -1 + /// will be returned. + /// + /// The value to read + /// The byte array + /// The unescaped byte if success. Otherwise return -1. + private static int UnescapePercentEncoding(ref int scan, Span buffer) + { + if (buffer[scan++] != '%') + { + return -1; + } + + var probe = scan; + + var value1 = ReadHex(ref probe, buffer); + if (value1 == -1) + { + return -1; + } + + var value2 = ReadHex(ref probe, buffer); + if (value2 == -1) + { + return -1; + } + + if (SkipUnescape(value1, value2)) + { + return -1; + } + + scan = probe; + return (value1 << 4) + value2; + } + + + /// + /// Read the next char and convert it into hexadecimal value. + /// + /// The index will be moved to the next + /// byte no matter no matter whether the operation successes. + /// + /// The index of the byte in the buffer to read + /// The byte span from which the hex to be read + /// The hexadecimal value if successes, otherwise -1. + private static int ReadHex(ref int scan, Span buffer) + { + if (scan == buffer.Length) + { + return -1; + } + + var value = buffer[scan++]; + var isHead = ((value >= '0') && (value <= '9')) || + ((value >= 'A') && (value <= 'F')) || + ((value >= 'a') && (value <= 'f')); + + if (!isHead) + { + return -1; + } + + if (value <= '9') + { + return value - '0'; + } + else if (value <= 'F') + { + return (value - 'A') + 10; + } + else // a - f + { + return (value - 'a') + 10; + } + } + + private static bool SkipUnescape(int value1, int value2) + { + // skip %2F - '/' + if (value1 == 2 && value2 == 15) + { + return true; + } + + return false; + } + + static UrlDecoder() + { + // Unreserved + IsAllowed['A'] = true; + IsAllowed['B'] = true; + IsAllowed['C'] = true; + IsAllowed['D'] = true; + IsAllowed['E'] = true; + IsAllowed['F'] = true; + IsAllowed['G'] = true; + IsAllowed['H'] = true; + IsAllowed['I'] = true; + IsAllowed['J'] = true; + IsAllowed['K'] = true; + IsAllowed['L'] = true; + IsAllowed['M'] = true; + IsAllowed['N'] = true; + IsAllowed['O'] = true; + IsAllowed['P'] = true; + IsAllowed['Q'] = true; + IsAllowed['R'] = true; + IsAllowed['S'] = true; + IsAllowed['T'] = true; + IsAllowed['U'] = true; + IsAllowed['V'] = true; + IsAllowed['W'] = true; + IsAllowed['X'] = true; + IsAllowed['Y'] = true; + IsAllowed['Z'] = true; + + IsAllowed['a'] = true; + IsAllowed['b'] = true; + IsAllowed['c'] = true; + IsAllowed['d'] = true; + IsAllowed['e'] = true; + IsAllowed['f'] = true; + IsAllowed['g'] = true; + IsAllowed['h'] = true; + IsAllowed['i'] = true; + IsAllowed['j'] = true; + IsAllowed['k'] = true; + IsAllowed['l'] = true; + IsAllowed['m'] = true; + IsAllowed['n'] = true; + IsAllowed['o'] = true; + IsAllowed['p'] = true; + IsAllowed['q'] = true; + IsAllowed['r'] = true; + IsAllowed['s'] = true; + IsAllowed['t'] = true; + IsAllowed['u'] = true; + IsAllowed['v'] = true; + IsAllowed['w'] = true; + IsAllowed['x'] = true; + IsAllowed['y'] = true; + IsAllowed['z'] = true; + + IsAllowed['0'] = true; + IsAllowed['1'] = true; + IsAllowed['2'] = true; + IsAllowed['3'] = true; + IsAllowed['4'] = true; + IsAllowed['5'] = true; + IsAllowed['6'] = true; + IsAllowed['7'] = true; + IsAllowed['8'] = true; + IsAllowed['9'] = true; + + IsAllowed['-'] = true; + IsAllowed['_'] = true; + IsAllowed['.'] = true; + IsAllowed['~'] = true; + } + } +} diff --git a/src/Kestrel.Core/Internal/Http2/Http2Connection.cs b/src/Kestrel.Core/Internal/Http2/Http2Connection.cs index 2d8fcd9b95..d0b46039db 100644 --- a/src/Kestrel.Core/Internal/Http2/Http2Connection.cs +++ b/src/Kestrel.Core/Internal/Http2/Http2Connection.cs @@ -215,7 +215,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 } } - private bool ParsePreface(ReadOnlyBuffer readableBuffer, out SequencePosition consumed, out SequencePosition examined) + private bool ParsePreface(ReadOnlySequence readableBuffer, out SequencePosition consumed, out SequencePosition examined) { consumed = readableBuffer.Start; examined = readableBuffer.End; diff --git a/src/Kestrel.Core/Internal/Http2/Http2ConnectionContext.cs b/src/Kestrel.Core/Internal/Http2/Http2ConnectionContext.cs index 73e4217a5c..ae9ceb3b70 100644 --- a/src/Kestrel.Core/Internal/Http2/Http2ConnectionContext.cs +++ b/src/Kestrel.Core/Internal/Http2/Http2ConnectionContext.cs @@ -13,7 +13,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 public string ConnectionId { get; set; } public ServiceContext ServiceContext { get; set; } public IFeatureCollection ConnectionFeatures { get; set; } - public MemoryPool MemoryPool { get; set; } + public MemoryPool MemoryPool { get; set; } public IPEndPoint LocalEndPoint { get; set; } public IPEndPoint RemoteEndPoint { get; set; } diff --git a/src/Kestrel.Core/Internal/Http2/Http2FrameReader.cs b/src/Kestrel.Core/Internal/Http2/Http2FrameReader.cs index 68bf0e07e2..b9d84fc896 100644 --- a/src/Kestrel.Core/Internal/Http2/Http2FrameReader.cs +++ b/src/Kestrel.Core/Internal/Http2/Http2FrameReader.cs @@ -1,6 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; using System.Buffers; using System.Collections; @@ -8,7 +9,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 { public static class Http2FrameReader { - public static bool ReadFrame(ReadOnlyBuffer readableBuffer, Http2Frame frame, out SequencePosition consumed, out SequencePosition examined) + public static bool ReadFrame(ReadOnlySequence readableBuffer, Http2Frame frame, out SequencePosition consumed, out SequencePosition examined) { consumed = readableBuffer.Start; examined = readableBuffer.End; diff --git a/src/Kestrel.Core/Internal/Http2/Http2FrameWriter.cs b/src/Kestrel.Core/Internal/Http2/Http2FrameWriter.cs index 362bdc9759..e31d4b7f4f 100644 --- a/src/Kestrel.Core/Internal/Http2/Http2FrameWriter.cs +++ b/src/Kestrel.Core/Internal/Http2/Http2FrameWriter.cs @@ -190,7 +190,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 } _outputWriter.Write(data); - _outputWriter.Commit(); } // Must be called with _writeLock diff --git a/src/Kestrel.Core/Internal/Http2/Http2Stream.cs b/src/Kestrel.Core/Internal/Http2/Http2Stream.cs index de212d1933..41e84805d9 100644 --- a/src/Kestrel.Core/Internal/Http2/Http2Stream.cs +++ b/src/Kestrel.Core/Internal/Http2/Http2Stream.cs @@ -83,14 +83,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 { if (data.Count > 0) { - try - { - RequestBodyPipe.Writer.Write(data); - } - finally - { - RequestBodyPipe.Writer.Commit(); - } + RequestBodyPipe.Writer.Write(data); RequestBodyStarted = true; await RequestBodyPipe.Writer.FlushAsync(); diff --git a/src/Kestrel.Core/Internal/Http2/Http2StreamContext.cs b/src/Kestrel.Core/Internal/Http2/Http2StreamContext.cs index 72ccd8d7c0..eea80103a7 100644 --- a/src/Kestrel.Core/Internal/Http2/Http2StreamContext.cs +++ b/src/Kestrel.Core/Internal/Http2/Http2StreamContext.cs @@ -14,7 +14,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 public int StreamId { get; set; } public ServiceContext ServiceContext { get; set; } public IFeatureCollection ConnectionFeatures { get; set; } - public MemoryPool MemoryPool { get; set; } + public MemoryPool MemoryPool { get; set; } public IPEndPoint RemoteEndPoint { get; set; } public IPEndPoint LocalEndPoint { get; set; } public IHttp2StreamLifetimeHandler StreamLifetimeHandler { get; set; } diff --git a/src/Kestrel.Core/Internal/HttpConnection.cs b/src/Kestrel.Core/Internal/HttpConnection.cs index 471d8194a2..b3895a72c9 100644 --- a/src/Kestrel.Core/Internal/HttpConnection.cs +++ b/src/Kestrel.Core/Internal/HttpConnection.cs @@ -68,7 +68,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal public IPEndPoint LocalEndPoint => _context.LocalEndPoint; public IPEndPoint RemoteEndPoint => _context.RemoteEndPoint; - private MemoryPool MemoryPool => _context.MemoryPool; + private MemoryPool MemoryPool => _context.MemoryPool; // Internal for testing internal PipeOptions AdaptedInputPipeOptions => new PipeOptions diff --git a/src/Kestrel.Core/Internal/HttpConnectionContext.cs b/src/Kestrel.Core/Internal/HttpConnectionContext.cs index 445d07a644..b60d5702ac 100644 --- a/src/Kestrel.Core/Internal/HttpConnectionContext.cs +++ b/src/Kestrel.Core/Internal/HttpConnectionContext.cs @@ -18,7 +18,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal public ServiceContext ServiceContext { get; set; } public IFeatureCollection ConnectionFeatures { get; set; } public IList ConnectionAdapters { get; set; } - public MemoryPool MemoryPool { get; set; } + public MemoryPool MemoryPool { get; set; } public IPEndPoint LocalEndPoint { get; set; } public IPEndPoint RemoteEndPoint { get; set; } public IDuplexPipe Transport { get; set; } diff --git a/src/Kestrel.Core/Internal/Infrastructure/KestrelThreadPool.cs b/src/Kestrel.Core/Internal/Infrastructure/KestrelThreadPool.cs index 6fe8810a3f..b160a1df5b 100644 --- a/src/Kestrel.Core/Internal/Infrastructure/KestrelThreadPool.cs +++ b/src/Kestrel.Core/Internal/Infrastructure/KestrelThreadPool.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.IO.Pipelines; using System.Threading; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure diff --git a/src/Kestrel.Core/Kestrel.Core.csproj b/src/Kestrel.Core/Kestrel.Core.csproj index 59b66b7373..68a0b5aaf5 100644 --- a/src/Kestrel.Core/Kestrel.Core.csproj +++ b/src/Kestrel.Core/Kestrel.Core.csproj @@ -21,6 +21,7 @@ + diff --git a/src/Kestrel.Transport.Abstractions/Internal/KestrelMemoryPool.cs b/src/Kestrel.Transport.Abstractions/Internal/KestrelMemoryPool.cs new file mode 100644 index 0000000000..61a065c6eb --- /dev/null +++ b/src/Kestrel.Transport.Abstractions/Internal/KestrelMemoryPool.cs @@ -0,0 +1,12 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System.Buffers; + +namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal +{ + public static class KestrelMemoryPool + { + public static MemoryPool Create() => new SlabMemoryPool(); + } +} diff --git a/src/Kestrel.Transport.Abstractions/Internal/TransportConnection.Features.cs b/src/Kestrel.Transport.Abstractions/Internal/TransportConnection.Features.cs index acd9e0dab1..4259da0128 100644 --- a/src/Kestrel.Transport.Abstractions/Internal/TransportConnection.Features.cs +++ b/src/Kestrel.Transport.Abstractions/Internal/TransportConnection.Features.cs @@ -95,7 +95,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal set => LocalPort = value; } - MemoryPool IConnectionTransportFeature.MemoryPool => MemoryPool; + MemoryPool IConnectionTransportFeature.MemoryPool => MemoryPool; IDuplexPipe IConnectionTransportFeature.Transport { diff --git a/src/Kestrel.Transport.Abstractions/Internal/TransportConnection.cs b/src/Kestrel.Transport.Abstractions/Internal/TransportConnection.cs index 34cb670e48..3aae48b16c 100644 --- a/src/Kestrel.Transport.Abstractions/Internal/TransportConnection.cs +++ b/src/Kestrel.Transport.Abstractions/Internal/TransportConnection.cs @@ -21,7 +21,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal public string ConnectionId { get; set; } - public virtual MemoryPool MemoryPool { get; } + public virtual MemoryPool MemoryPool { get; } public virtual PipeScheduler InputWriterScheduler { get; } public virtual PipeScheduler OutputReaderScheduler { get; } diff --git a/src/Kestrel.Transport.Abstractions/Kestrel.Transport.Abstractions.csproj b/src/Kestrel.Transport.Abstractions/Kestrel.Transport.Abstractions.csproj index cfbd7353cf..b8877c964a 100644 --- a/src/Kestrel.Transport.Abstractions/Kestrel.Transport.Abstractions.csproj +++ b/src/Kestrel.Transport.Abstractions/Kestrel.Transport.Abstractions.csproj @@ -15,5 +15,8 @@ + + + diff --git a/src/Kestrel.Transport.Libuv/Internal/LibuvConnection.cs b/src/Kestrel.Transport.Libuv/Internal/LibuvConnection.cs index 8471d89d61..bb98d1c8c1 100644 --- a/src/Kestrel.Transport.Libuv/Internal/LibuvConnection.cs +++ b/src/Kestrel.Transport.Libuv/Internal/LibuvConnection.cs @@ -122,7 +122,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal { // EAGAIN/EWOULDBLOCK so just return the buffer. // http://docs.libuv.org/en/v1.x/stream.html#c.uv_read_cb - Input.Commit(); } else if (status > 0) { @@ -141,7 +140,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal else { // Given a negative status, it's possible that OnAlloc wasn't called. - Input.Commit(); _socket.ReadStop(); IOException error = null; @@ -175,7 +173,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal _bufferHandle.Dispose(); } - private async Task ApplyBackpressureAsync(ValueAwaiter flushTask) + private async Task ApplyBackpressureAsync(PipeAwaiter flushTask) { Log.ConnectionPause(ConnectionId); _socket.ReadStop(); @@ -183,7 +181,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal var result = await flushTask; // If the reader isn't complete or cancelled then resume reading - if (!result.IsCompleted && !result.IsCancelled) + if (!result.IsCompleted && !result.IsCanceled) { Log.ConnectionResume(ConnectionId); StartReading(); diff --git a/src/Kestrel.Transport.Libuv/Internal/LibuvConnectionContext.cs b/src/Kestrel.Transport.Libuv/Internal/LibuvConnectionContext.cs index 39f68be604..1f2abb9f37 100644 --- a/src/Kestrel.Transport.Libuv/Internal/LibuvConnectionContext.cs +++ b/src/Kestrel.Transport.Libuv/Internal/LibuvConnectionContext.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Buffers; +using System.IO.Pipelines; using System.Threading; using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; @@ -16,7 +17,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal public ListenerContext ListenerContext { get; set; } - public override MemoryPool MemoryPool => ListenerContext.Thread.MemoryPool; + public override MemoryPool MemoryPool => ListenerContext.Thread.MemoryPool; public override PipeScheduler InputWriterScheduler => ListenerContext.Thread; public override PipeScheduler OutputReaderScheduler => ListenerContext.Thread; } diff --git a/src/Kestrel.Transport.Libuv/Internal/LibuvOutputConsumer.cs b/src/Kestrel.Transport.Libuv/Internal/LibuvOutputConsumer.cs index 298c333d05..cb60e9a2e0 100644 --- a/src/Kestrel.Transport.Libuv/Internal/LibuvOutputConsumer.cs +++ b/src/Kestrel.Transport.Libuv/Internal/LibuvOutputConsumer.cs @@ -55,7 +55,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal try { - if (result.IsCancelled) + if (result.IsCanceled) { break; } diff --git a/src/Kestrel.Transport.Libuv/Internal/LibuvThread.cs b/src/Kestrel.Transport.Libuv/Internal/LibuvThread.cs index 87774d835a..0d6530303f 100644 --- a/src/Kestrel.Transport.Libuv/Internal/LibuvThread.cs +++ b/src/Kestrel.Transport.Libuv/Internal/LibuvThread.cs @@ -5,10 +5,12 @@ using System; using System.Buffers; using System.Collections.Generic; using System.Diagnostics; +using System.IO.Pipelines; using System.Runtime.ExceptionServices; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking; using Microsoft.Extensions.Logging; @@ -55,7 +57,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal #endif QueueCloseHandle = PostCloseHandle; QueueCloseAsyncHandle = EnqueueCloseHandle; - MemoryPool = new MemoryPool(); + MemoryPool = KestrelMemoryPool.Create(); WriteReqPool = new WriteReqPool(this, _log); } @@ -68,7 +70,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal public UvLoopHandle Loop { get { return _loop; } } - public MemoryPool MemoryPool { get; } + public MemoryPool MemoryPool { get; } public WriteReqPool WriteReqPool { get; } diff --git a/src/Kestrel.Transport.Libuv/Internal/Networking/UvWriteReq.cs b/src/Kestrel.Transport.Libuv/Internal/Networking/UvWriteReq.cs index 27d78bae3d..9a635ba5cc 100644 --- a/src/Kestrel.Transport.Libuv/Internal/Networking/UvWriteReq.cs +++ b/src/Kestrel.Transport.Libuv/Internal/Networking/UvWriteReq.cs @@ -48,7 +48,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networkin _bufs = handle + requestSize; } - public LibuvAwaitable WriteAsync(UvStreamHandle handle, ReadOnlyBuffer buffer) + public LibuvAwaitable WriteAsync(UvStreamHandle handle, ReadOnlySequence buffer) { Write(handle, buffer, LibuvAwaitable.Callback, _awaitable); return _awaitable; @@ -62,7 +62,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networkin private unsafe void Write( UvStreamHandle handle, - ReadOnlyBuffer buffer, + ReadOnlySequence buffer, Action callback, object state) { diff --git a/src/Kestrel.Transport.Sockets/Internal/SocketConnection.cs b/src/Kestrel.Transport.Sockets/Internal/SocketConnection.cs index 227101d1f9..87fee3379a 100644 --- a/src/Kestrel.Transport.Sockets/Internal/SocketConnection.cs +++ b/src/Kestrel.Transport.Sockets/Internal/SocketConnection.cs @@ -5,6 +5,7 @@ using System; using System.Buffers; using System.Diagnostics; using System.IO; +using System.IO.Pipelines; using System.Net; using System.Net.Sockets; using System.Threading.Tasks; @@ -26,7 +27,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal private volatile bool _aborted; - internal SocketConnection(Socket socket, MemoryPool memoryPool, ISocketsTrace trace) + internal SocketConnection(Socket socket, MemoryPool memoryPool, ISocketsTrace trace) { Debug.Assert(socket != null); Debug.Assert(memoryPool != null); @@ -49,7 +50,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal _sender = new SocketSender(_socket); } - public override MemoryPool MemoryPool { get; } + public override MemoryPool MemoryPool { get; } public override PipeScheduler InputWriterScheduler => PipeScheduler.Inline; public override PipeScheduler OutputReaderScheduler => PipeScheduler.ThreadPool; @@ -102,24 +103,18 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal // Ensure we have some reasonable amount of buffer space var buffer = Input.GetMemory(MinAllocBufferSize); - try - { - var bytesReceived = await _receiver.ReceiveAsync(buffer); + var bytesReceived = await _receiver.ReceiveAsync(buffer); - if (bytesReceived == 0) - { - // FIN - _trace.ConnectionReadFin(ConnectionId); - break; - } - - Input.Advance(bytesReceived); - } - finally + if (bytesReceived == 0) { - Input.Commit(); + // FIN + _trace.ConnectionReadFin(ConnectionId); + break; } + Input.Advance(bytesReceived); + + var flushTask = Input.FlushAsync(); if (!flushTask.IsCompleted) @@ -197,7 +192,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal var result = await Output.ReadAsync(); var buffer = result.Buffer; - if (result.IsCancelled) + if (result.IsCanceled) { break; } diff --git a/src/Kestrel.Transport.Sockets/Internal/SocketSender.cs b/src/Kestrel.Transport.Sockets/Internal/SocketSender.cs index ef88ce8731..2199c60ef5 100644 --- a/src/Kestrel.Transport.Sockets/Internal/SocketSender.cs +++ b/src/Kestrel.Transport.Sockets/Internal/SocketSender.cs @@ -25,7 +25,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal _eventArgs.Completed += (_, e) => ((SocketAwaitable)e.UserToken).Complete(e.BytesTransferred, e.SocketError); } - public SocketAwaitable SendAsync(ReadOnlyBuffer buffers) + public SocketAwaitable SendAsync(ReadOnlySequence buffers) { if (buffers.IsSingleSegment) { @@ -74,7 +74,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal return _awaitable; } - private List> GetBufferList(ReadOnlyBuffer buffer) + private List> GetBufferList(ReadOnlySequence buffer) { Debug.Assert(!buffer.IsEmpty); Debug.Assert(!buffer.IsSingleSegment); diff --git a/src/Kestrel.Transport.Sockets/SocketTransport.cs b/src/Kestrel.Transport.Sockets/SocketTransport.cs index cd729a5eb1..c27f24767a 100644 --- a/src/Kestrel.Transport.Sockets/SocketTransport.cs +++ b/src/Kestrel.Transport.Sockets/SocketTransport.cs @@ -19,7 +19,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets { internal sealed class SocketTransport : ITransport { - private readonly MemoryPool _memoryPool = new MemoryPool(); + private readonly MemoryPool _memoryPool = KestrelMemoryPool.Create(); private readonly IEndPointInformation _endPointInformation; private readonly IConnectionHandler _handler; private readonly IApplicationLifetime _appLifetime; diff --git a/src/Protocols.Abstractions/DuplexPipe.cs b/src/Protocols.Abstractions/DuplexPipe.cs index 4e26d458ec..60fc029aec 100644 --- a/src/Protocols.Abstractions/DuplexPipe.cs +++ b/src/Protocols.Abstractions/DuplexPipe.cs @@ -18,7 +18,7 @@ namespace System.IO.Pipelines { } - public static DuplexPipePair CreateConnectionPair(MemoryPool memoryPool) + public static DuplexPipePair CreateConnectionPair(MemoryPool memoryPool) { return CreateConnectionPair(new PipeOptions(memoryPool), new PipeOptions(memoryPool)); } diff --git a/src/Protocols.Abstractions/Features/IConnectionTransportFeature.cs b/src/Protocols.Abstractions/Features/IConnectionTransportFeature.cs index 54e21226e4..1a5500b692 100644 --- a/src/Protocols.Abstractions/Features/IConnectionTransportFeature.cs +++ b/src/Protocols.Abstractions/Features/IConnectionTransportFeature.cs @@ -6,7 +6,7 @@ namespace Microsoft.AspNetCore.Protocols.Features { public interface IConnectionTransportFeature { - MemoryPool MemoryPool { get; } + MemoryPool MemoryPool { get; } IDuplexPipe Transport { get; set; } diff --git a/src/Protocols.Abstractions/Protocols.Abstractions.csproj b/src/Protocols.Abstractions/Protocols.Abstractions.csproj index 192ee595fa..ac03b392b4 100644 --- a/src/Protocols.Abstractions/Protocols.Abstractions.csproj +++ b/src/Protocols.Abstractions/Protocols.Abstractions.csproj @@ -17,7 +17,6 @@ - diff --git a/test/Kestrel.Core.Tests/ConnectionHandlerTests.cs b/test/Kestrel.Core.Tests/ConnectionHandlerTests.cs index 13aabd72ad..ee1cffefdc 100644 --- a/test/Kestrel.Core.Tests/ConnectionHandlerTests.cs +++ b/test/Kestrel.Core.Tests/ConnectionHandlerTests.cs @@ -7,6 +7,8 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Protocols.Features; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; using Microsoft.AspNetCore.Testing; using Xunit; @@ -51,7 +53,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests Set(this); } - public MemoryPool MemoryPool { get; } = new MemoryPool(); + public MemoryPool MemoryPool { get; } = KestrelMemoryPool.Create(); public IDuplexPipe Transport { get; set; } public IDuplexPipe Application { get; set; } diff --git a/test/Kestrel.Core.Tests/Http1ConnectionTests.cs b/test/Kestrel.Core.Tests/Http1ConnectionTests.cs index 41c933a429..7428e20ec2 100644 --- a/test/Kestrel.Core.Tests/Http1ConnectionTests.cs +++ b/test/Kestrel.Core.Tests/Http1ConnectionTests.cs @@ -17,6 +17,7 @@ using Microsoft.AspNetCore.Server.Kestrel.Core.Features; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; using Microsoft.AspNetCore.Testing; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Primitives; @@ -32,14 +33,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests private readonly TestHttp1Connection _http1Connection; private readonly ServiceContext _serviceContext; private readonly Http1ConnectionContext _http1ConnectionContext; - private readonly MemoryPool _pipelineFactory; + private readonly MemoryPool _pipelineFactory; private SequencePosition _consumed; private SequencePosition _examined; private Mock _timeoutControl; public Http1ConnectionTests() { - _pipelineFactory = new MemoryPool(); + _pipelineFactory = KestrelMemoryPool.Create(); var pair = DuplexPipe.CreateConnectionPair(_pipelineFactory); _transport = pair.Transport; @@ -803,7 +804,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests _http1Connection.NextMessageBody = mockMessageBody.Object; var requestProcessingTask = _http1Connection.ProcessRequestsAsync(httpApplication); - + var data = Encoding.ASCII.GetBytes("POST / HTTP/1.1\r\nHost:\r\nConnection: close\r\ncontent-length: 1\r\n\r\n"); await _application.Output.WriteAsync(data); await requestProcessingTask.TimeoutAfter(TestConstants.DefaultTimeout); diff --git a/test/Kestrel.Core.Tests/Http2ConnectionTests.cs b/test/Kestrel.Core.Tests/Http2ConnectionTests.cs index 5c5a0c2925..b8f47eebee 100644 --- a/test/Kestrel.Core.Tests/Http2ConnectionTests.cs +++ b/test/Kestrel.Core.Tests/Http2ConnectionTests.cs @@ -18,6 +18,7 @@ using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2.HPack; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; using Microsoft.AspNetCore.Testing; using Xunit; @@ -93,7 +94,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests private static readonly byte[] _noData = new byte[0]; private static readonly byte[] _maxData = Encoding.ASCII.GetBytes(new string('a', Http2Frame.MinAllowedMaxFrameSize)); - private readonly MemoryPool _memoryPool = new MemoryPool(); + private readonly MemoryPool _memoryPool = KestrelMemoryPool.Create(); private readonly DuplexPipe.DuplexPipePair _pair; private readonly TestApplicationErrorLogger _logger; private readonly Http2ConnectionContext _connectionContext; diff --git a/test/Kestrel.Core.Tests/HttpConnectionTests.cs b/test/Kestrel.Core.Tests/HttpConnectionTests.cs index 4e2829e863..27b1c3c5b3 100644 --- a/test/Kestrel.Core.Tests/HttpConnectionTests.cs +++ b/test/Kestrel.Core.Tests/HttpConnectionTests.cs @@ -10,6 +10,7 @@ using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; using Microsoft.AspNetCore.Testing; using Moq; using Xunit; @@ -18,13 +19,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests { public class HttpConnectionTests : IDisposable { - private readonly MemoryPool _memoryPool; + private readonly MemoryPool _memoryPool; private readonly HttpConnectionContext _httpConnectionContext; private readonly HttpConnection _httpConnection; public HttpConnectionTests() { - _memoryPool = new MemoryPool(); + _memoryPool = KestrelMemoryPool.Create(); var pair = DuplexPipe.CreateConnectionPair(_memoryPool); _httpConnectionContext = new HttpConnectionContext diff --git a/test/Kestrel.Core.Tests/HttpParserTests.cs b/test/Kestrel.Core.Tests/HttpParserTests.cs index b436c16211..8baa695f96 100644 --- a/test/Kestrel.Core.Tests/HttpParserTests.cs +++ b/test/Kestrel.Core.Tests/HttpParserTests.cs @@ -34,7 +34,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests string expectedVersion) { var parser = CreateParser(Mock.Of()); - var buffer = new ReadOnlyBuffer(Encoding.ASCII.GetBytes(requestLine)); + var buffer = new ReadOnlySequence(Encoding.ASCII.GetBytes(requestLine)); var requestHandler = new RequestHandler(); Assert.True(parser.ParseRequestLine(requestHandler, buffer, out var consumed, out var examined)); @@ -53,7 +53,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests public void ParseRequestLineReturnsFalseWhenGivenIncompleteRequestLines(string requestLine) { var parser = CreateParser(Mock.Of()); - var buffer = new ReadOnlyBuffer(Encoding.ASCII.GetBytes(requestLine)); + var buffer = new ReadOnlySequence(Encoding.ASCII.GetBytes(requestLine)); var requestHandler = new RequestHandler(); Assert.False(parser.ParseRequestLine(requestHandler, buffer, out var consumed, out var examined)); @@ -64,7 +64,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests public void ParseRequestLineDoesNotConsumeIncompleteRequestLine(string requestLine) { var parser = CreateParser(Mock.Of()); - var buffer = new ReadOnlyBuffer(Encoding.ASCII.GetBytes(requestLine)); + var buffer = new ReadOnlySequence(Encoding.ASCII.GetBytes(requestLine)); var requestHandler = new RequestHandler(); Assert.False(parser.ParseRequestLine(requestHandler, buffer, out var consumed, out var examined)); @@ -83,7 +83,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests .Returns(true); var parser = CreateParser(mockTrace.Object); - var buffer = new ReadOnlyBuffer(Encoding.ASCII.GetBytes(requestLine)); + var buffer = new ReadOnlySequence(Encoding.ASCII.GetBytes(requestLine)); var requestHandler = new RequestHandler(); var exception = Assert.Throws(() => @@ -105,7 +105,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests .Returns(true); var parser = CreateParser(mockTrace.Object); - var buffer = new ReadOnlyBuffer(Encoding.ASCII.GetBytes(requestLine)); + var buffer = new ReadOnlySequence(Encoding.ASCII.GetBytes(requestLine)); var requestHandler = new RequestHandler(); var exception = Assert.Throws(() => @@ -127,7 +127,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests .Returns(true); var parser = CreateParser(mockTrace.Object); - var buffer = new ReadOnlyBuffer(Encoding.ASCII.GetBytes(requestLine)); + var buffer = new ReadOnlySequence(Encoding.ASCII.GetBytes(requestLine)); var requestHandler = new RequestHandler(); var exception = Assert.Throws(() => @@ -178,7 +178,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests { var parser = CreateParser(Mock.Of()); - var buffer = new ReadOnlyBuffer(Encoding.ASCII.GetBytes(rawHeaders)); + var buffer = new ReadOnlySequence(Encoding.ASCII.GetBytes(rawHeaders)); var requestHandler = new RequestHandler(); Assert.False(parser.ParseHeaders(requestHandler, buffer, out var consumed, out var examined, out var consumedBytes)); } @@ -203,7 +203,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests { var parser = CreateParser(Mock.Of()); - var buffer = new ReadOnlyBuffer(Encoding.ASCII.GetBytes(rawHeaders)); + var buffer = new ReadOnlySequence(Encoding.ASCII.GetBytes(rawHeaders)); var requestHandler = new RequestHandler(); parser.ParseHeaders(requestHandler, buffer, out var consumed, out var examined, out var consumedBytes); @@ -293,7 +293,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests var parser = CreateParser(Mock.Of()); const string headerLine = "Header: value\r\n\r"; - var buffer1 = new ReadOnlyBuffer(Encoding.ASCII.GetBytes(headerLine)); + var buffer1 = new ReadOnlySequence(Encoding.ASCII.GetBytes(headerLine)); var requestHandler = new RequestHandler(); Assert.False(parser.ParseHeaders(requestHandler, buffer1, out var consumed, out var examined, out var consumedBytes)); @@ -301,7 +301,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests Assert.Equal(buffer1.End, examined); Assert.Equal(headerLine.Length - 1, consumedBytes); - var buffer2 = new ReadOnlyBuffer(Encoding.ASCII.GetBytes("\r\n")); + var buffer2 = new ReadOnlySequence(Encoding.ASCII.GetBytes("\r\n")); Assert.True(parser.ParseHeaders(requestHandler, buffer2, out consumed, out examined, out consumedBytes)); Assert.True(buffer2.Slice(consumed).IsEmpty); @@ -319,7 +319,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests .Returns(true); var parser = CreateParser(mockTrace.Object); - var buffer = new ReadOnlyBuffer(Encoding.ASCII.GetBytes(rawHeaders)); + var buffer = new ReadOnlySequence(Encoding.ASCII.GetBytes(rawHeaders)); var requestHandler = new RequestHandler(); var exception = Assert.Throws(() => @@ -340,7 +340,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests var parser = CreateParser(mockTrace.Object); // Invalid request line - var buffer = new ReadOnlyBuffer(Encoding.ASCII.GetBytes("GET % HTTP/1.1\r\n")); + var buffer = new ReadOnlySequence(Encoding.ASCII.GetBytes("GET % HTTP/1.1\r\n")); var requestHandler = new RequestHandler(); var exception = Assert.Throws(() => @@ -350,7 +350,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests Assert.Equal(StatusCodes.Status400BadRequest, (exception as BadHttpRequestException).StatusCode); // Unrecognized HTTP version - buffer = new ReadOnlyBuffer(Encoding.ASCII.GetBytes("GET / HTTP/1.2\r\n")); + buffer = new ReadOnlySequence(Encoding.ASCII.GetBytes("GET / HTTP/1.2\r\n")); exception = Assert.Throws(() => parser.ParseRequestLine(requestHandler, buffer, out var consumed, out var examined)); @@ -359,7 +359,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests Assert.Equal(StatusCodes.Status505HttpVersionNotsupported, (exception as BadHttpRequestException).StatusCode); // Invalid request header - buffer = new ReadOnlyBuffer(Encoding.ASCII.GetBytes("Header: value\n\r\n")); + buffer = new ReadOnlySequence(Encoding.ASCII.GetBytes("Header: value\n\r\n")); exception = Assert.Throws(() => parser.ParseHeaders(requestHandler, buffer, out var consumed, out var examined, out var consumedBytes)); @@ -388,7 +388,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests string expectedHeaderValue) { var parser = CreateParser(Mock.Of()); - var buffer = new ReadOnlyBuffer(Encoding.ASCII.GetBytes($"{headerName}:{rawHeaderValue}\r\n")); + var buffer = new ReadOnlySequence(Encoding.ASCII.GetBytes($"{headerName}:{rawHeaderValue}\r\n")); var requestHandler = new RequestHandler(); parser.ParseHeaders(requestHandler, buffer, out var consumed, out var examined, out var consumedBytes); @@ -406,7 +406,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests Assert.True(expectedHeaderNames.Count() == expectedHeaderValues.Count(), $"{nameof(expectedHeaderNames)} and {nameof(expectedHeaderValues)} sizes must match"); var parser = CreateParser(Mock.Of()); - var buffer = new ReadOnlyBuffer(Encoding.ASCII.GetBytes(rawHeaders)); + var buffer = new ReadOnlySequence(Encoding.ASCII.GetBytes(rawHeaders)); var requestHandler = new RequestHandler(); parser.ParseHeaders(requestHandler, buffer, out var consumed, out var examined, out var consumedBytes); @@ -466,7 +466,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests } } - private static ReadOnlyBuffer CreateBuffer(params string[] inputs) + private static ReadOnlySequence CreateBuffer(params string[] inputs) { var buffers = new byte[inputs.Length][]; for (int i = 0; i < inputs.Length; i++) @@ -477,7 +477,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests } // Copied from https://github.com/dotnet/corefx/blob/master/src/System.Memory/tests/ReadOnlyBuffer/ReadOnlySequenceFactory.cs - private static ReadOnlyBuffer CreateBuffer(params byte[][] inputs) + private static ReadOnlySequence CreateBuffer(params byte[][] inputs) { if (inputs == null || inputs.Length == 0) { @@ -516,7 +516,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests i++; } while (i < inputs.Length); - return new ReadOnlyBuffer(first, 0, last, last.Memory.Length); + return new ReadOnlySequence(first, 0, last, last.Memory.Length); } // Copied from https://github.com/dotnet/corefx/blob/master/src/System.Memory/tests/ReadOnlyBuffer/BufferSegment.cs diff --git a/test/Kestrel.Core.Tests/HttpProtocolFeatureCollectionTests.cs b/test/Kestrel.Core.Tests/HttpProtocolFeatureCollectionTests.cs index 4167386340..846b441862 100644 --- a/test/Kestrel.Core.Tests/HttpProtocolFeatureCollectionTests.cs +++ b/test/Kestrel.Core.Tests/HttpProtocolFeatureCollectionTests.cs @@ -10,6 +10,7 @@ using Microsoft.AspNetCore.Server.Kestrel.Core.Features; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; using Microsoft.AspNetCore.Testing; using Moq; using Xunit; @@ -23,14 +24,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests private readonly TestHttp1Connection _http1Connection; private readonly ServiceContext _serviceContext; private readonly Http1ConnectionContext _http1ConnectionContext; - private readonly MemoryPool _pipelineFactory; + private readonly MemoryPool _pipelineFactory; private Mock _timeoutControl; private readonly IFeatureCollection _collection; public HttpProtocolFeatureCollectionTests() { - _pipelineFactory = new MemoryPool(); + _pipelineFactory = KestrelMemoryPool.Create(); var pair = DuplexPipe.CreateConnectionPair(_pipelineFactory); _transport = pair.Transport; diff --git a/test/Kestrel.Core.Tests/HttpResponseHeadersTests.cs b/test/Kestrel.Core.Tests/HttpResponseHeadersTests.cs index 0df993ab89..8a602351ad 100644 --- a/test/Kestrel.Core.Tests/HttpResponseHeadersTests.cs +++ b/test/Kestrel.Core.Tests/HttpResponseHeadersTests.cs @@ -9,6 +9,7 @@ using System.IO.Pipelines; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; using Microsoft.AspNetCore.Testing; using Microsoft.Extensions.Primitives; using Xunit; @@ -20,7 +21,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests [Fact] public void InitialDictionaryIsEmpty() { - using (var memoryPool = new MemoryPool()) + using (var memoryPool = KestrelMemoryPool.Create()) { var pair = DuplexPipe.CreateConnectionPair(memoryPool); var http1ConnectionContext = new Http1ConnectionContext diff --git a/test/Kestrel.Core.Tests/OutputProducerTests.cs b/test/Kestrel.Core.Tests/OutputProducerTests.cs index 8c489537ec..b9e334b527 100644 --- a/test/Kestrel.Core.Tests/OutputProducerTests.cs +++ b/test/Kestrel.Core.Tests/OutputProducerTests.cs @@ -7,6 +7,7 @@ using System.IO.Pipelines; using System.Threading; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; using Microsoft.AspNetCore.Testing; using Moq; using Xunit; @@ -15,11 +16,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests { public class OutputProducerTests : IDisposable { - private readonly MemoryPool _memoryPool; + private readonly MemoryPool _memoryPool; public OutputProducerTests() { - _memoryPool = new MemoryPool(); + _memoryPool = KestrelMemoryPool.Create(); } public void Dispose() diff --git a/test/Kestrel.Core.Tests/PipeOptionsTests.cs b/test/Kestrel.Core.Tests/PipeOptionsTests.cs index ff3ab4ce27..71a4df8d05 100644 --- a/test/Kestrel.Core.Tests/PipeOptionsTests.cs +++ b/test/Kestrel.Core.Tests/PipeOptionsTests.cs @@ -2,9 +2,11 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Buffers; +using System.IO.Pipelines; using System.Threading; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; using Microsoft.AspNetCore.Testing; using Moq; using Xunit; @@ -24,7 +26,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests serviceContext.ThreadPool = new LoggingThreadPool(null); var mockScheduler = Mock.Of(); - var outputPipeOptions = ConnectionHandler.GetOutputPipeOptions(serviceContext, new MemoryPool(), readerScheduler: mockScheduler); + var outputPipeOptions = ConnectionHandler.GetOutputPipeOptions(serviceContext, KestrelMemoryPool.Create(), readerScheduler: mockScheduler); Assert.Equal(expectedMaximumSizeLow, outputPipeOptions.ResumeWriterThreshold); Assert.Equal(expectedMaximumSizeHigh, outputPipeOptions.PauseWriterThreshold); @@ -42,7 +44,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests serviceContext.ThreadPool = new LoggingThreadPool(null); var mockScheduler = Mock.Of(); - var inputPipeOptions = ConnectionHandler.GetInputPipeOptions(serviceContext, new MemoryPool(), writerScheduler: mockScheduler); + var inputPipeOptions = ConnectionHandler.GetInputPipeOptions(serviceContext, KestrelMemoryPool.Create(), writerScheduler: mockScheduler); Assert.Equal(expectedMaximumSizeLow, inputPipeOptions.ResumeWriterThreshold); Assert.Equal(expectedMaximumSizeHigh, inputPipeOptions.PauseWriterThreshold); diff --git a/test/Kestrel.Core.Tests/PipelineExtensionTests.cs b/test/Kestrel.Core.Tests/PipelineExtensionTests.cs index 286dff7cbe..ed534a564f 100644 --- a/test/Kestrel.Core.Tests/PipelineExtensionTests.cs +++ b/test/Kestrel.Core.Tests/PipelineExtensionTests.cs @@ -6,6 +6,7 @@ using System.Buffers; using System.IO.Pipelines; using System.Text; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; using Xunit; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests @@ -16,7 +17,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests private const int _ulongMaxValueLength = 20; private readonly Pipe _pipe; - private readonly MemoryPool _memoryPool = new MemoryPool(); + private readonly MemoryPool _memoryPool = KestrelMemoryPool.Create(); public PipelineExtensionTests() { @@ -35,8 +36,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests public void WritesNumericToAscii(ulong number) { var writerBuffer = _pipe.Writer; - var writer = OutputWriter.Create(writerBuffer); + var writer = new BufferWriter(writerBuffer); writer.WriteNumeric(number); + writer.Commit(); writerBuffer.FlushAsync().GetAwaiter().GetResult(); var reader = _pipe.Reader.ReadAsync().GetAwaiter().GetResult(); @@ -52,7 +54,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests public void WritesNumericAcrossSpanBoundaries(int gapSize) { var writerBuffer = _pipe.Writer; - var writer = OutputWriter.Create(writerBuffer); + var writer = new BufferWriter(writerBuffer); // almost fill up the first block var spacer = new byte[writer.Span.Length - gapSize]; writer.Write(spacer); @@ -60,7 +62,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests var bufferLength = writer.Span.Length; writer.WriteNumeric(ulong.MaxValue); Assert.NotEqual(bufferLength, writer.Span.Length); - + writer.Commit(); writerBuffer.FlushAsync().GetAwaiter().GetResult(); var reader = _pipe.Reader.ReadAsync().GetAwaiter().GetResult(); @@ -83,8 +85,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests public void EncodesAsAscii(string input, byte[] expected) { var writerBuffer = _pipe.Writer; - var writer = OutputWriter.Create(writerBuffer); + var writer = new BufferWriter(writerBuffer); writer.WriteAsciiNoValidation(input); + writer.Commit(); writerBuffer.FlushAsync().GetAwaiter().GetResult(); var reader = _pipe.Reader.ReadAsync().GetAwaiter().GetResult(); @@ -110,8 +113,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests // WriteAscii doesn't validate if characters are in the ASCII range // but it shouldn't produce more than one byte per character var writerBuffer = _pipe.Writer; - var writer = OutputWriter.Create(writerBuffer); + var writer = new BufferWriter(writerBuffer); writer.WriteAsciiNoValidation(input); + writer.Commit(); writerBuffer.FlushAsync().GetAwaiter().GetResult(); var reader = _pipe.Reader.ReadAsync().GetAwaiter().GetResult(); @@ -123,11 +127,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests { const byte maxAscii = 0x7f; var writerBuffer = _pipe.Writer; - var writer = OutputWriter.Create(writerBuffer); + var writer = new BufferWriter(writerBuffer); for (var i = 0; i < maxAscii; i++) { writer.WriteAsciiNoValidation(new string((char)i, 1)); } + writer.Commit(); writerBuffer.FlushAsync().GetAwaiter().GetResult(); var reader = _pipe.Reader.ReadAsync().GetAwaiter().GetResult(); @@ -152,7 +157,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests { var testString = new string(' ', stringLength); var writerBuffer = _pipe.Writer; - var writer = OutputWriter.Create(writerBuffer); + var writer = new BufferWriter(writerBuffer); // almost fill up the first block var spacer = new byte[writer.Span.Length - gapSize]; writer.Write(spacer); @@ -161,7 +166,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests var bufferLength = writer.Span.Length; writer.WriteAsciiNoValidation(testString); Assert.NotEqual(bufferLength, writer.Span.Length); - + writer.Commit(); writerBuffer.FlushAsync().GetAwaiter().GetResult(); var reader = _pipe.Reader.ReadAsync().GetAwaiter().GetResult(); diff --git a/test/Kestrel.Core.Tests/TestInput.cs b/test/Kestrel.Core.Tests/TestInput.cs index 601fcd133e..d042e5c5bc 100644 --- a/test/Kestrel.Core.Tests/TestInput.cs +++ b/test/Kestrel.Core.Tests/TestInput.cs @@ -5,9 +5,11 @@ using System; using System.Buffers; using System.IO.Pipelines; using System.Text; +using System.Threading.Tasks; using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; using Microsoft.AspNetCore.Testing; using Moq; @@ -15,11 +17,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests { class TestInput : IDisposable { - private MemoryPool _memoryPool; + private MemoryPool _memoryPool; public TestInput() { - _memoryPool = new MemoryPool(); + _memoryPool = KestrelMemoryPool.Create(); var pair = DuplexPipe.CreateConnectionPair(_memoryPool); Transport = pair.Transport; Application = pair.Application; @@ -49,7 +51,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests public void Add(string text) { var data = Encoding.ASCII.GetBytes(text); - Application.Output.WriteAsync(data).Wait(); + async Task Write() => await Application.Output.WriteAsync(data); + Write().Wait(); } public void Fin() diff --git a/test/Kestrel.Transport.Libuv.Tests/LibuvOutputConsumerTests.cs b/test/Kestrel.Transport.Libuv.Tests/LibuvOutputConsumerTests.cs index d674ae6e96..1e9fb7f361 100644 --- a/test/Kestrel.Transport.Libuv.Tests/LibuvOutputConsumerTests.cs +++ b/test/Kestrel.Transport.Libuv.Tests/LibuvOutputConsumerTests.cs @@ -11,6 +11,7 @@ using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal; using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking; using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests.TestHelpers; @@ -22,7 +23,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests { public class LibuvOutputConsumerTests : IDisposable { - private readonly MemoryPool _memoryPool; + private readonly MemoryPool _memoryPool; private readonly MockLibuv _mockLibuv; private readonly LibuvThread _libuvThread; @@ -38,7 +39,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests public LibuvOutputConsumerTests() { - _memoryPool = new MemoryPool(); + _memoryPool = KestrelMemoryPool.Create(); _mockLibuv = new MockLibuv(); var libuvTransport = new LibuvTransport(_mockLibuv, new TestLibuvTransportContext(), new ListenOptions((ulong)0)); @@ -340,6 +341,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests ( pool: _memoryPool, readerScheduler: _libuvThread, + writerScheduler: PipeScheduler.Inline, pauseWriterThreshold: maxResponseBufferSize, resumeWriterThreshold: maxResponseBufferSize ); diff --git a/test/Kestrel.Transport.Libuv.Tests/MultipleLoopTests.cs b/test/Kestrel.Transport.Libuv.Tests/MultipleLoopTests.cs index b4dd9c64ae..463165ef88 100644 --- a/test/Kestrel.Transport.Libuv.Tests/MultipleLoopTests.cs +++ b/test/Kestrel.Transport.Libuv.Tests/MultipleLoopTests.cs @@ -67,7 +67,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests await writeRequest.WriteAsync( serverConnectionPipe, - new ReadOnlyBuffer(new byte[] { 1, 2, 3, 4 })); + new ReadOnlySequence(new byte[] { 1, 2, 3, 4 })); writeRequest.Dispose(); serverConnectionPipe.Dispose(); diff --git a/test/Kestrel.Transport.Libuv.Tests/NetworkingTests.cs b/test/Kestrel.Transport.Libuv.Tests/NetworkingTests.cs index 24a1bf36a7..0e698d5477 100644 --- a/test/Kestrel.Transport.Libuv.Tests/NetworkingTests.cs +++ b/test/Kestrel.Transport.Libuv.Tests/NetworkingTests.cs @@ -161,7 +161,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests { var req = new UvWriteReq(_logger); req.DangerousInit(loop); - var block = new ReadOnlyBuffer(new byte[] { 65, 66, 67, 68, 69 }); + var block = new ReadOnlySequence(new byte[] { 65, 66, 67, 68, 69 }); await req.WriteAsync( tcp2, diff --git a/test/Kestrel.Transport.Libuv.Tests/TestHelpers/MockConnectionHandler.cs b/test/Kestrel.Transport.Libuv.Tests/TestHelpers/MockConnectionHandler.cs index 2b2b380755..d248b4cfc2 100644 --- a/test/Kestrel.Transport.Libuv.Tests/TestHelpers/MockConnectionHandler.cs +++ b/test/Kestrel.Transport.Libuv.Tests/TestHelpers/MockConnectionHandler.cs @@ -13,8 +13,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests.TestHelpers { public class MockConnectionHandler : IConnectionHandler { - public Func InputOptions { get; set; } = pool => new PipeOptions(pool); - public Func OutputOptions { get; set; } = pool => new PipeOptions(pool); + public Func, PipeOptions> InputOptions { get; set; } = pool => new PipeOptions(pool); + public Func, PipeOptions> OutputOptions { get; set; } = pool => new PipeOptions(pool); public void OnConnection(IFeatureCollection features) { diff --git a/tools/CodeGenerator/KnownHeaders.cs b/tools/CodeGenerator/KnownHeaders.cs index 7578113ba3..18a0613469 100644 --- a/tools/CodeGenerator/KnownHeaders.cs +++ b/tools/CodeGenerator/KnownHeaders.cs @@ -523,7 +523,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http return true; }} {(loop.ClassName == "HttpResponseHeaders" ? $@" - protected void CopyToFast(ref OutputWriter output) + internal void CopyToFast(ref BufferWriter output) {{ var tempBits = _bits | (_contentLength.HasValue ? {1L << 63}L : 0); {Each(loop.Headers.Where(header => header.Identifier != "ContentLength").OrderBy(h => !h.PrimaryHeader), header => $@" From 300453396a57cd14bcb297627b1507de83dc88ab Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Thu, 1 Mar 2018 03:54:44 +0000 Subject: [PATCH 1547/1662] Pass StringValues via in (#2295) --- .../Internal/Http/HttpHeaders.Generated.cs | 16 ++++++++-------- src/Kestrel.Core/Internal/Http/HttpHeaders.cs | 12 ++++++------ .../Internal/Http/HttpRequestHeaders.cs | 2 +- .../Internal/Http/HttpResponseHeaders.cs | 6 +++--- tools/CodeGenerator/KnownHeaders.cs | 6 +++--- 5 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/Kestrel.Core/Internal/Http/HttpHeaders.Generated.cs b/src/Kestrel.Core/Internal/Http/HttpHeaders.Generated.cs index 84dc60f624..27473181b7 100644 --- a/src/Kestrel.Core/Internal/Http/HttpHeaders.Generated.cs +++ b/src/Kestrel.Core/Internal/Http/HttpHeaders.Generated.cs @@ -1252,7 +1252,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http return MaybeUnknown?.TryGetValue(key, out value) ?? false; } - protected override void SetValueFast(string key, StringValues value) + protected override void SetValueFast(string key, in StringValues value) { switch (key.Length) { @@ -1600,7 +1600,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http SetValueUnknown(key, value); } - protected override bool AddValueFast(string key, StringValues value) + protected override bool AddValueFast(string key, in StringValues value) { switch (key.Length) { @@ -5411,25 +5411,25 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http } } - public void SetRawConnection(StringValues value, byte[] raw) + public void SetRawConnection(in StringValues value, byte[] raw) { _bits |= 2L; _headers._Connection = value; _headers._rawConnection = raw; } - public void SetRawDate(StringValues value, byte[] raw) + public void SetRawDate(in StringValues value, byte[] raw) { _bits |= 4L; _headers._Date = value; _headers._rawDate = raw; } - public void SetRawTransferEncoding(StringValues value, byte[] raw) + public void SetRawTransferEncoding(in StringValues value, byte[] raw) { _bits |= 64L; _headers._TransferEncoding = value; _headers._rawTransferEncoding = raw; } - public void SetRawServer(StringValues value, byte[] raw) + public void SetRawServer(in StringValues value, byte[] raw) { _bits |= 33554432L; _headers._Server = value; @@ -5849,7 +5849,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http return MaybeUnknown?.TryGetValue(key, out value) ?? false; } - protected override void SetValueFast(string key, StringValues value) + protected override void SetValueFast(string key, in StringValues value) { ValidateHeaderCharacters(value); switch (key.Length) @@ -6154,7 +6154,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http SetValueUnknown(key, value); } - protected override bool AddValueFast(string key, StringValues value) + protected override bool AddValueFast(string key, in StringValues value) { ValidateHeaderCharacters(value); switch (key.Length) diff --git a/src/Kestrel.Core/Internal/Http/HttpHeaders.cs b/src/Kestrel.Core/Internal/Http/HttpHeaders.cs index f0aa6218df..92061b5d87 100644 --- a/src/Kestrel.Core/Internal/Http/HttpHeaders.cs +++ b/src/Kestrel.Core/Internal/Http/HttpHeaders.cs @@ -107,7 +107,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http } [MethodImpl(MethodImplOptions.NoInlining)] - protected static StringValues AppendValue(StringValues existing, string append) + protected static StringValues AppendValue(in StringValues existing, string append) { return StringValues.Concat(existing, append); } @@ -134,10 +134,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http protected virtual bool TryGetValueFast(string key, out StringValues value) { throw new NotImplementedException(); } - protected virtual void SetValueFast(string key, StringValues value) + protected virtual void SetValueFast(string key, in StringValues value) { throw new NotImplementedException(); } - protected virtual bool AddValueFast(string key, StringValues value) + protected virtual bool AddValueFast(string key, in StringValues value) { throw new NotImplementedException(); } protected virtual bool RemoveFast(string key) @@ -234,7 +234,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http return TryGetValueFast(key, out value); } - public static void ValidateHeaderCharacters(StringValues headerValues) + public static void ValidateHeaderCharacters(in StringValues headerValues) { var count = headerValues.Count; for (var i = 0; i < count; i++) @@ -258,7 +258,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http } } - public static unsafe ConnectionOptions ParseConnection(StringValues connection) + public static unsafe ConnectionOptions ParseConnection(in StringValues connection) { var connectionOptions = ConnectionOptions.None; @@ -360,7 +360,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http return connectionOptions; } - public static unsafe TransferCoding GetFinalTransferCoding(StringValues transferEncoding) + public static unsafe TransferCoding GetFinalTransferCoding(in StringValues transferEncoding) { var transferEncodingOptions = TransferCoding.None; diff --git a/src/Kestrel.Core/Internal/Http/HttpRequestHeaders.cs b/src/Kestrel.Core/Internal/Http/HttpRequestHeaders.cs index c441ae5ed6..9ee5a2a27e 100644 --- a/src/Kestrel.Core/Internal/Http/HttpRequestHeaders.cs +++ b/src/Kestrel.Core/Internal/Http/HttpRequestHeaders.cs @@ -26,7 +26,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http } [MethodImpl(MethodImplOptions.NoInlining)] - private void SetValueUnknown(string key, StringValues value) + private void SetValueUnknown(string key, in StringValues value) { Unknown[key] = value; } diff --git a/src/Kestrel.Core/Internal/Http/HttpResponseHeaders.cs b/src/Kestrel.Core/Internal/Http/HttpResponseHeaders.cs index badb63449c..f559102c6a 100644 --- a/src/Kestrel.Core/Internal/Http/HttpResponseHeaders.cs +++ b/src/Kestrel.Core/Internal/Http/HttpResponseHeaders.cs @@ -68,7 +68,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http } [MethodImpl(MethodImplOptions.NoInlining)] - private void SetValueUnknown(string key, StringValues value) + private void SetValueUnknown(string key, in StringValues value) { ValidateHeaderCharacters(key); Unknown[key] = value; @@ -93,11 +93,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http _collection = collection; _bits = collection._bits; _state = 0; - _current = default(KeyValuePair); + _current = default; _hasUnknown = collection.MaybeUnknown != null; _unknownEnumerator = _hasUnknown ? collection.MaybeUnknown.GetEnumerator() - : default(Dictionary.Enumerator); + : default; } public KeyValuePair Current => _current; diff --git a/tools/CodeGenerator/KnownHeaders.cs b/tools/CodeGenerator/KnownHeaders.cs index 18a0613469..6aa1654681 100644 --- a/tools/CodeGenerator/KnownHeaders.cs +++ b/tools/CodeGenerator/KnownHeaders.cs @@ -344,7 +344,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http }}")} }}")} {Each(loop.Headers.Where(header => header.EnhancedSetter), header => $@" - public void SetRaw{header.Identifier}(StringValues value, byte[] raw) + public void SetRaw{header.Identifier}(in StringValues value, byte[] raw) {{ {header.SetBit()}; _headers._{header.Identifier} = value; @@ -383,7 +383,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http return MaybeUnknown?.TryGetValue(key, out value) ?? false; }} - protected override void SetValueFast(string key, StringValues value) + protected override void SetValueFast(string key, in StringValues value) {{{(loop.ClassName == "HttpResponseHeaders" ? @" ValidateHeaderCharacters(value);" : "")} switch (key.Length) @@ -405,7 +405,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http SetValueUnknown(key, value); }} - protected override bool AddValueFast(string key, StringValues value) + protected override bool AddValueFast(string key, in StringValues value) {{{(loop.ClassName == "HttpResponseHeaders" ? @" ValidateHeaderCharacters(value);" : "")} switch (key.Length) From d47688680361c75457f265ca4975670aedc154a2 Mon Sep 17 00:00:00 2001 From: Pavel Krymets Date: Fri, 2 Mar 2018 09:51:29 -0800 Subject: [PATCH 1548/1662] Upgrade dependency versions --- build/dependencies.props | 42 ++++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/build/dependencies.props b/build/dependencies.props index f05fd787d5..96de726343 100644 --- a/build/dependencies.props +++ b/build/dependencies.props @@ -5,30 +5,30 @@ 0.10.11 - 2.1.0-preview2-15707 + 2.1.0-preview2-15721 1.10.0 - 2.1.0-preview2-30131 - 2.1.0-preview2-30131 - 2.1.0-preview2-30131 - 2.1.0-preview2-30131 - 2.1.0-preview2-30131 - 2.1.0-preview2-30131 - 2.1.0-preview2-30131 - 2.1.0-preview2-30131 - 2.1.0-preview2-30131 - 2.1.0-preview2-t000 - 2.1.0-preview2-30131 - 2.1.0-preview2-30131 - 2.1.0-preview2-30131 - 2.1.0-preview2-30131 - 2.1.0-preview2-30131 - 2.1.0-preview2-30131 - 2.1.0-preview2-30131 - 2.1.0-preview2-30131 + 2.1.0-preview2-30220 + 2.1.0-preview2-30220 + 2.1.0-preview2-30220 + 2.1.0-preview2-30220 + 2.1.0-preview2-30220 + 2.1.0-preview2-30220 + 2.1.0-preview2-30220 + 2.1.0-preview2-30220 + 2.1.0-preview2-30220 + 2.1.0-preview2-30220 + 2.1.0-preview2-30220 + 2.1.0-preview2-30220 + 2.1.0-preview2-30220 + 2.1.0-preview2-30220 + 2.1.0-preview2-30220 + 2.1.0-preview2-30220 + 2.1.0-preview2-30220 + 2.1.0-preview2-30220 2.0.0 2.1.0-preview2-26225-03 - 2.1.0-preview2-30131 - 15.3.0 + 2.1.0-preview2-30220 + 15.6.0 4.7.49 10.0.1 4.5.0-preview2-26224-02 From 0f6ba66e465bf092df20dd0cdeee6e90b6907fab Mon Sep 17 00:00:00 2001 From: Mike Harder Date: Fri, 2 Mar 2018 12:38:32 -0800 Subject: [PATCH 1549/1662] Add InMemoryTransportBenchmark (#2354) --- .../InMemoryTransportBenchmark.cs | 242 ++++++++++++++++++ korebuild-lock.txt | 4 +- 2 files changed, 244 insertions(+), 2 deletions(-) create mode 100644 benchmarks/Kestrel.Performance/InMemoryTransportBenchmark.cs diff --git a/benchmarks/Kestrel.Performance/InMemoryTransportBenchmark.cs b/benchmarks/Kestrel.Performance/InMemoryTransportBenchmark.cs new file mode 100644 index 0000000000..73b94be6e1 --- /dev/null +++ b/benchmarks/Kestrel.Performance/InMemoryTransportBenchmark.cs @@ -0,0 +1,242 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using BenchmarkDotNet.Attributes; +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; +using Microsoft.Extensions.DependencyInjection; +using System; +using System.Buffers; +using System.Collections.Generic; +using System.IO.Pipelines; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Microsoft.AspNetCore.Server.Kestrel.Performance +{ + public class InMemoryTransportBenchmark + { + private const string _plaintextExpectedResponse = + "HTTP/1.1 200 OK\r\n" + + "Date: Fri, 02 Mar 2018 18:37:05 GMT\r\n" + + "Content-Type: text/plain\r\n" + + "Server: Kestrel\r\n" + + "Content-Length: 13\r\n" + + "\r\n" + + "Hello, World!"; + + private static readonly string _plaintextPipelinedExpectedResponse = + string.Concat(Enumerable.Repeat(_plaintextExpectedResponse, RequestParsingData.Pipelining)); + + private IWebHost _host; + private InMemoryConnection _connection; + + [GlobalSetup(Target = nameof(Plaintext) + "," + nameof(PlaintextPipelined))] + public void GlobalSetupPlaintext() + { + var transportFactory = new InMemoryTransportFactory(connectionsPerEndPoint: 1); + + _host = new WebHostBuilder() + // Prevent VS from attaching to hosting startup which could impact results + .UseSetting("preventHostingStartup", "true") + .UseKestrel() + // Bind to a single non-HTTPS endpoint + .UseUrls("http://127.0.0.1:5000") + .ConfigureServices(services => services.AddSingleton(transportFactory)) + .Configure(app => app.UseMiddleware()) + .Build(); + + _host.Start(); + + // Ensure there is a single endpoint and single connection + _connection = transportFactory.Connections.Values.Single().Single(); + + ValidateResponseAsync(RequestParsingData.PlaintextTechEmpowerRequest, _plaintextExpectedResponse).Wait(); + ValidateResponseAsync(RequestParsingData.PlaintextTechEmpowerPipelinedRequests, _plaintextPipelinedExpectedResponse).Wait(); + } + + private async Task ValidateResponseAsync(byte[] request, string expectedResponse) + { + await _connection.SendRequestAsync(request); + var response = Encoding.ASCII.GetString(await _connection.GetResponseAsync(expectedResponse.Length)); + + // Exclude date header since the value changes on every request + var expectedResponseLines = expectedResponse.Split("\r\n").Where(s => !s.StartsWith("Date:")); + var responseLines = response.Split("\r\n").Where(s => !s.StartsWith("Date:")); + + if (!Enumerable.SequenceEqual(expectedResponseLines, responseLines)) + { + throw new InvalidOperationException(string.Join(Environment.NewLine, + "Invalid response", "Expected:", expectedResponse, "Actual:", response)); + } + } + + [GlobalCleanup] + public void GlobalCleanup() + { + _host.Dispose(); + } + + [Benchmark] + public async Task Plaintext() + { + await _connection.SendRequestAsync(RequestParsingData.PlaintextTechEmpowerRequest); + await _connection.ReadResponseAsync(_plaintextExpectedResponse.Length); + } + + [Benchmark(OperationsPerInvoke = RequestParsingData.Pipelining)] + public async Task PlaintextPipelined() + { + await _connection.SendRequestAsync(RequestParsingData.PlaintextTechEmpowerPipelinedRequests); + await _connection.ReadResponseAsync(_plaintextPipelinedExpectedResponse.Length); + } + + public class InMemoryTransportFactory : ITransportFactory + { + private readonly int _connectionsPerEndPoint; + + private readonly Dictionary> _connections = + new Dictionary>(); + + public IReadOnlyDictionary> Connections => _connections; + + public InMemoryTransportFactory(int connectionsPerEndPoint) + { + _connectionsPerEndPoint = connectionsPerEndPoint; + } + + public ITransport Create(IEndPointInformation endPointInformation, IConnectionHandler handler) + { + var connections = new InMemoryConnection[_connectionsPerEndPoint]; + for (var i = 0; i < _connectionsPerEndPoint; i++) + { + connections[i] = new InMemoryConnection(); + } + + _connections.Add(endPointInformation, connections); + + return new InMemoryTransport(handler, connections); + } + } + + public class InMemoryTransport : ITransport + { + private readonly IConnectionHandler _handler; + private readonly IReadOnlyList _connections; + + public InMemoryTransport(IConnectionHandler handler, IReadOnlyList connections) + { + _handler = handler; + _connections = connections; + } + + public Task BindAsync() + { + foreach (var connection in _connections) + { + _handler.OnConnection(connection); + } + + return Task.CompletedTask; + } + + public Task StopAsync() + { + return Task.CompletedTask; + } + + public Task UnbindAsync() + { + return Task.CompletedTask; + } + } + + public class InMemoryConnection : TransportConnection + { + public PipeAwaiter SendRequestAsync(byte[] request) + { + return Input.WriteAsync(request); + } + + // Reads response as efficiently as possible (similar to LibuvTransport), but doesn't return anything + public async Task ReadResponseAsync(int length) + { + while (length > 0) + { + var result = await Output.ReadAsync(); + var buffer = result.Buffer; + length -= (int)buffer.Length; + Output.AdvanceTo(buffer.End); + } + + if (length < 0) + { + throw new InvalidOperationException($"Invalid response, length={length}"); + } + } + + // Returns response so it can be validated, but is slower and allocates more than ReadResponseAsync() + public async Task GetResponseAsync(int length) + { + while (true) + { + var result = await Output.ReadAsync(); + var buffer = result.Buffer; + var consumed = buffer.Start; + var examined = buffer.End; + + try + { + if (buffer.Length >= length) + { + var response = buffer.Slice(0, length); + consumed = response.End; + examined = response.End; + return response.ToArray(); + } + } + finally + { + Output.AdvanceTo(consumed, examined); + } + } + } + } + + // Copied from https://github.com/aspnet/benchmarks/blob/dev/src/Benchmarks/Middleware/PlaintextMiddleware.cs + public class PlaintextMiddleware + { + private static readonly PathString _path = new PathString("/plaintext"); + private static readonly byte[] _helloWorldPayload = Encoding.UTF8.GetBytes("Hello, World!"); + + private readonly RequestDelegate _next; + + public PlaintextMiddleware(RequestDelegate next) + { + _next = next; + } + + public Task Invoke(HttpContext httpContext) + { + if (httpContext.Request.Path.StartsWithSegments(_path, StringComparison.Ordinal)) + { + return WriteResponse(httpContext.Response); + } + + return _next(httpContext); + } + + public static Task WriteResponse(HttpResponse response) + { + var payloadLength = _helloWorldPayload.Length; + response.StatusCode = 200; + response.ContentType = "text/plain"; + response.ContentLength = payloadLength; + return response.Body.WriteAsync(_helloWorldPayload, 0, payloadLength); + } + } + } +} diff --git a/korebuild-lock.txt b/korebuild-lock.txt index e6c7fddffa..bdaa7048b3 100644 --- a/korebuild-lock.txt +++ b/korebuild-lock.txt @@ -1,2 +1,2 @@ -version:2.1.0-preview2-15721 -commithash:f9bb4be59e39938ec59a6975257e26099b0d03c1 +version:2.1.0-preview2-15726 +commithash:599e691c41f502ed9e062b1822ce13b673fc916e From b86df651afe9af28d4fb0e8fd7b79dd8dce68817 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Mon, 5 Mar 2018 16:28:35 -0800 Subject: [PATCH 1550/1662] Fix Http2ConnectionTests flakiness (#2364) - The default PipeScheduler got switched from Inline to ThreadPool. - This switches the Http2ConnectionTests PipeSchedulers back to ThreadPool. --- test/Kestrel.Core.Tests/Http2ConnectionTests.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/test/Kestrel.Core.Tests/Http2ConnectionTests.cs b/test/Kestrel.Core.Tests/Http2ConnectionTests.cs index b8f47eebee..ca49803ee4 100644 --- a/test/Kestrel.Core.Tests/Http2ConnectionTests.cs +++ b/test/Kestrel.Core.Tests/Http2ConnectionTests.cs @@ -123,7 +123,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests public Http2ConnectionTests() { - _pair = DuplexPipe.CreateConnectionPair(_memoryPool); + var inlineSchedulingPipeOptions = new PipeOptions( + pool: _memoryPool, + readerScheduler: PipeScheduler.Inline, + writerScheduler: PipeScheduler.Inline + ); + + _pair = DuplexPipe.CreateConnectionPair(inlineSchedulingPipeOptions, inlineSchedulingPipeOptions); _noopApplication = context => Task.CompletedTask; From c88f949c39201feefda068ea42437fe3ec1af779 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Tue, 6 Mar 2018 09:58:14 -0800 Subject: [PATCH 1551/1662] Be explicit about PipeScheduler.Inline (#2367) --- test/Kestrel.Core.Tests/OutputProducerTests.cs | 3 ++- test/Kestrel.Core.Tests/PipelineExtensionTests.cs | 2 +- test/Kestrel.Core.Tests/TestInput.cs | 3 ++- .../LibuvConnectionTests.cs | 11 +++++++---- .../LibuvOutputConsumerTests.cs | 9 +++++++++ .../TestHelpers/MockConnectionHandler.cs | 4 ++-- 6 files changed, 23 insertions(+), 9 deletions(-) diff --git a/test/Kestrel.Core.Tests/OutputProducerTests.cs b/test/Kestrel.Core.Tests/OutputProducerTests.cs index b9e334b527..8cd730fca0 100644 --- a/test/Kestrel.Core.Tests/OutputProducerTests.cs +++ b/test/Kestrel.Core.Tests/OutputProducerTests.cs @@ -34,7 +34,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests var pipeOptions = new PipeOptions ( pool: _memoryPool, - readerScheduler: Mock.Of() + readerScheduler: Mock.Of(), + writerScheduler: PipeScheduler.Inline ); using (var socketOutput = CreateOutputProducer(pipeOptions)) diff --git a/test/Kestrel.Core.Tests/PipelineExtensionTests.cs b/test/Kestrel.Core.Tests/PipelineExtensionTests.cs index ed534a564f..35e4f02e05 100644 --- a/test/Kestrel.Core.Tests/PipelineExtensionTests.cs +++ b/test/Kestrel.Core.Tests/PipelineExtensionTests.cs @@ -21,7 +21,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests public PipelineExtensionTests() { - _pipe = new Pipe(new PipeOptions(_memoryPool)); + _pipe = new Pipe(new PipeOptions(_memoryPool, readerScheduler: PipeScheduler.Inline, writerScheduler: PipeScheduler.Inline)); } public void Dispose() diff --git a/test/Kestrel.Core.Tests/TestInput.cs b/test/Kestrel.Core.Tests/TestInput.cs index d042e5c5bc..f91def83ec 100644 --- a/test/Kestrel.Core.Tests/TestInput.cs +++ b/test/Kestrel.Core.Tests/TestInput.cs @@ -22,7 +22,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests public TestInput() { _memoryPool = KestrelMemoryPool.Create(); - var pair = DuplexPipe.CreateConnectionPair(_memoryPool); + var options = new PipeOptions(pool: _memoryPool, readerScheduler: PipeScheduler.Inline, writerScheduler: PipeScheduler.Inline); + var pair = DuplexPipe.CreateConnectionPair(options, options); Transport = pair.Transport; Application = pair.Application; diff --git a/test/Kestrel.Transport.Libuv.Tests/LibuvConnectionTests.cs b/test/Kestrel.Transport.Libuv.Tests/LibuvConnectionTests.cs index afbaf577f0..5071a3cbad 100644 --- a/test/Kestrel.Transport.Libuv.Tests/LibuvConnectionTests.cs +++ b/test/Kestrel.Transport.Libuv.Tests/LibuvConnectionTests.cs @@ -62,11 +62,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests mockConnectionHandler.InputOptions = pool => new PipeOptions( pool: pool, - pauseWriterThreshold: 3); + pauseWriterThreshold: 3, + readerScheduler: PipeScheduler.Inline, + writerScheduler: PipeScheduler.Inline); // We don't set the output writer scheduler here since we want to run the callback inline - mockConnectionHandler.OutputOptions = pool => new PipeOptions(pool: pool, readerScheduler: thread); + mockConnectionHandler.OutputOptions = pool => new PipeOptions(pool: pool, readerScheduler: thread, writerScheduler: PipeScheduler.Inline); Task connectionTask = null; @@ -128,9 +130,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests pool: pool, pauseWriterThreshold: 3, resumeWriterThreshold: 3, - writerScheduler: mockScheduler.Object); + writerScheduler: mockScheduler.Object, + readerScheduler: PipeScheduler.Inline); - mockConnectionHandler.OutputOptions = pool => new PipeOptions(pool: pool, readerScheduler:thread ); + mockConnectionHandler.OutputOptions = pool => new PipeOptions(pool: pool, readerScheduler: thread, writerScheduler: PipeScheduler.Inline); Task connectionTask = null; try diff --git a/test/Kestrel.Transport.Libuv.Tests/LibuvOutputConsumerTests.cs b/test/Kestrel.Transport.Libuv.Tests/LibuvOutputConsumerTests.cs index 1e9fb7f361..adc58f5794 100644 --- a/test/Kestrel.Transport.Libuv.Tests/LibuvOutputConsumerTests.cs +++ b/test/Kestrel.Transport.Libuv.Tests/LibuvOutputConsumerTests.cs @@ -67,6 +67,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests ( pool: _memoryPool, readerScheduler: _libuvThread, + writerScheduler: PipeScheduler.Inline, pauseWriterThreshold: maxResponseBufferSize ?? 0, resumeWriterThreshold: maxResponseBufferSize ?? 0 ); @@ -103,6 +104,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests ( pool: _memoryPool, readerScheduler: _libuvThread, + writerScheduler: PipeScheduler.Inline, pauseWriterThreshold: 0, resumeWriterThreshold: 0 ); @@ -151,6 +153,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests ( pool: _memoryPool, readerScheduler: _libuvThread, + writerScheduler: PipeScheduler.Inline, pauseWriterThreshold: 1, resumeWriterThreshold: 1 ); @@ -207,6 +210,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests ( pool: _memoryPool, readerScheduler: _libuvThread, + writerScheduler: PipeScheduler.Inline, pauseWriterThreshold: maxResponseBufferSize, resumeWriterThreshold: maxResponseBufferSize ); @@ -271,6 +275,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests ( pool: _memoryPool, readerScheduler: _libuvThread, + writerScheduler: PipeScheduler.Inline, pauseWriterThreshold: maxResponseBufferSize, resumeWriterThreshold: maxResponseBufferSize ); @@ -435,6 +440,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests ( pool: _memoryPool, readerScheduler: _libuvThread, + writerScheduler: PipeScheduler.Inline, pauseWriterThreshold: maxResponseBufferSize, resumeWriterThreshold: maxResponseBufferSize ); @@ -519,6 +525,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests ( pool: _memoryPool, readerScheduler: _libuvThread, + writerScheduler: PipeScheduler.Inline, pauseWriterThreshold: maxResponseBufferSize, resumeWriterThreshold: maxResponseBufferSize ); @@ -601,6 +608,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests ( pool: _memoryPool, readerScheduler: _libuvThread, + writerScheduler: PipeScheduler.Inline, pauseWriterThreshold: maxResponseBufferSize, resumeWriterThreshold: maxResponseBufferSize ); @@ -662,6 +670,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests ( pool: _memoryPool, readerScheduler: _libuvThread, + writerScheduler: PipeScheduler.Inline, pauseWriterThreshold: maxResponseBufferSize ?? 0, resumeWriterThreshold: maxResponseBufferSize ?? 0 ); diff --git a/test/Kestrel.Transport.Libuv.Tests/TestHelpers/MockConnectionHandler.cs b/test/Kestrel.Transport.Libuv.Tests/TestHelpers/MockConnectionHandler.cs index d248b4cfc2..e6e8ec3738 100644 --- a/test/Kestrel.Transport.Libuv.Tests/TestHelpers/MockConnectionHandler.cs +++ b/test/Kestrel.Transport.Libuv.Tests/TestHelpers/MockConnectionHandler.cs @@ -13,8 +13,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests.TestHelpers { public class MockConnectionHandler : IConnectionHandler { - public Func, PipeOptions> InputOptions { get; set; } = pool => new PipeOptions(pool); - public Func, PipeOptions> OutputOptions { get; set; } = pool => new PipeOptions(pool); + public Func, PipeOptions> InputOptions { get; set; } = pool => new PipeOptions(pool, readerScheduler: PipeScheduler.Inline, writerScheduler: PipeScheduler.Inline); + public Func, PipeOptions> OutputOptions { get; set; } = pool => new PipeOptions(pool, readerScheduler: PipeScheduler.Inline, writerScheduler: PipeScheduler.Inline); public void OnConnection(IFeatureCollection features) { From 9abdd3883d5582d8c141cf2dcca6f03c4300cb41 Mon Sep 17 00:00:00 2001 From: Pranav K Date: Tue, 6 Mar 2018 10:04:38 -0800 Subject: [PATCH 1552/1662] Use dotnet-core feed in repos --- build/sources.props | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/build/sources.props b/build/sources.props index 181b021f88..fe324c40e3 100644 --- a/build/sources.props +++ b/build/sources.props @@ -1,10 +1,11 @@ - + $(DotNetRestoreSources) $(RestoreSources); + https://dotnet.myget.org/F/dotnet-core/api/v3/index.json; https://dotnet.myget.org/F/aspnetcore-dev/api/v3/index.json; https://dotnet.myget.org/F/aspnetcore-tools/api/v3/index.json; https://dotnet.myget.org/F/roslyn/api/v3/index.json; From 49cd0ef97fed1c64514b729c20598b6128567a95 Mon Sep 17 00:00:00 2001 From: Pranav K Date: Tue, 6 Mar 2018 10:04:38 -0800 Subject: [PATCH 1553/1662] Prepend FeatureBranchVersionPrefix if FeatureBranchVersionSuffix is specified --- version.props | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/version.props b/version.props index 65c8a07e37..a11ea1ed52 100644 --- a/version.props +++ b/version.props @@ -5,7 +5,8 @@ $(VersionPrefix) $(VersionPrefix)-$(VersionSuffix)-final t000 - $(VersionSuffix)-$([System.Text.RegularExpressions.Regex]::Replace('$(FeatureBranchVersionSuffix)', '[^\w-]', '-')) + a- + $(FeatureBranchVersionPrefix)$(VersionSuffix)-$([System.Text.RegularExpressions.Regex]::Replace('$(FeatureBranchVersionSuffix)', '[^\w-]', '-')) $(VersionSuffix)-$(BuildNumber) From 42fbba3520fe188f35a83e5f9542893b64c5284f Mon Sep 17 00:00:00 2001 From: "Chris Ross (ASP.NET)" Date: Fri, 2 Mar 2018 10:51:48 -0800 Subject: [PATCH 1554/1662] More detailed request timeout exceptions #2245 --- src/Kestrel.Core/BadHttpRequestException.cs | 7 ++- src/Kestrel.Core/CoreStrings.resx | 7 ++- .../Internal/Http/Http1Connection.cs | 2 +- .../Internal/Http/Http1MessageBody.cs | 2 +- .../Internal/Http/RequestRejectionReason.cs | 3 +- .../Properties/CoreStrings.Designer.cs | 48 +++++++++++++------ 6 files changed, 48 insertions(+), 21 deletions(-) diff --git a/src/Kestrel.Core/BadHttpRequestException.cs b/src/Kestrel.Core/BadHttpRequestException.cs index 4fc2bb1521..0530f53854 100644 --- a/src/Kestrel.Core/BadHttpRequestException.cs +++ b/src/Kestrel.Core/BadHttpRequestException.cs @@ -87,8 +87,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core case RequestRejectionReason.RequestBodyTooLarge: ex = new BadHttpRequestException(CoreStrings.BadRequest_RequestBodyTooLarge, StatusCodes.Status413PayloadTooLarge); break; - case RequestRejectionReason.RequestTimeout: - ex = new BadHttpRequestException(CoreStrings.BadRequest_RequestTimeout, StatusCodes.Status408RequestTimeout); + case RequestRejectionReason.RequestHeadersTimeout: + ex = new BadHttpRequestException(CoreStrings.BadRequest_RequestHeadersTimeout, StatusCodes.Status408RequestTimeout); + break; + case RequestRejectionReason.RequestBodyTimeout: + ex = new BadHttpRequestException(CoreStrings.BadRequest_RequestBodyTimeout, StatusCodes.Status408RequestTimeout); break; case RequestRejectionReason.OptionsMethodRequired: ex = new BadHttpRequestException(CoreStrings.BadRequest_MethodNotAllowed, StatusCodes.Status405MethodNotAllowed, HttpMethod.Options); diff --git a/src/Kestrel.Core/CoreStrings.resx b/src/Kestrel.Core/CoreStrings.resx index 966dbfd1bb..286f64efc9 100644 --- a/src/Kestrel.Core/CoreStrings.resx +++ b/src/Kestrel.Core/CoreStrings.resx @@ -186,8 +186,8 @@ Request line too long. - - Request timed out. + + Reading the request headers timed out. Request contains too many headers. @@ -503,4 +503,7 @@ For more information on configuring HTTPS see https://go.microsoft.com/fwlink/?l Cannot write to the response body, the response has completed. + + Reading the request body timed out due to data arriving too slowly. See MinRequestBodyDataRate. + \ No newline at end of file diff --git a/src/Kestrel.Core/Internal/Http/Http1Connection.cs b/src/Kestrel.Core/Internal/Http/Http1Connection.cs index c8bab28d31..3876e63194 100644 --- a/src/Kestrel.Core/Internal/Http/Http1Connection.cs +++ b/src/Kestrel.Core/Internal/Http/Http1Connection.cs @@ -484,7 +484,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { // In this case, there is an ongoing request but the start line/header parsing has timed out, so send // a 408 response. - BadHttpRequestException.Throw(RequestRejectionReason.RequestTimeout); + BadHttpRequestException.Throw(RequestRejectionReason.RequestHeadersTimeout); } endConnection = false; diff --git a/src/Kestrel.Core/Internal/Http/Http1MessageBody.cs b/src/Kestrel.Core/Internal/Http/Http1MessageBody.cs index 1e7f3caf2d..503e21e5bd 100644 --- a/src/Kestrel.Core/Internal/Http/Http1MessageBody.cs +++ b/src/Kestrel.Core/Internal/Http/Http1MessageBody.cs @@ -47,7 +47,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http if (_context.RequestTimedOut) { - BadHttpRequestException.Throw(RequestRejectionReason.RequestTimeout); + BadHttpRequestException.Throw(RequestRejectionReason.RequestBodyTimeout); } var readableBuffer = result.Buffer; diff --git a/src/Kestrel.Core/Internal/Http/RequestRejectionReason.cs b/src/Kestrel.Core/Internal/Http/RequestRejectionReason.cs index 0a7cb1eeb1..ee27b5cb96 100644 --- a/src/Kestrel.Core/Internal/Http/RequestRejectionReason.cs +++ b/src/Kestrel.Core/Internal/Http/RequestRejectionReason.cs @@ -22,7 +22,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http HeadersExceedMaxTotalSize, TooManyHeaders, RequestBodyTooLarge, - RequestTimeout, + RequestHeadersTimeout, + RequestBodyTimeout, FinalTransferCodingNotChunked, LengthRequired, LengthRequiredHttp10, diff --git a/src/Kestrel.Core/Properties/CoreStrings.Designer.cs b/src/Kestrel.Core/Properties/CoreStrings.Designer.cs index c915e95dff..a8a1937505 100644 --- a/src/Kestrel.Core/Properties/CoreStrings.Designer.cs +++ b/src/Kestrel.Core/Properties/CoreStrings.Designer.cs @@ -333,18 +333,18 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core => GetString("BadRequest_RequestLineTooLong"); /// - /// Request timed out. + /// Reading the request headers timed out. /// - internal static string BadRequest_RequestTimeout + internal static string BadRequest_RequestHeadersTimeout { - get => GetString("BadRequest_RequestTimeout"); + get => GetString("BadRequest_RequestHeadersTimeout"); } /// - /// Request timed out. + /// Reading the request headers timed out. /// - internal static string FormatBadRequest_RequestTimeout() - => GetString("BadRequest_RequestTimeout"); + internal static string FormatBadRequest_RequestHeadersTimeout() + => GetString("BadRequest_RequestHeadersTimeout"); /// /// Request contains too many headers. @@ -878,14 +878,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core internal static string FormatWritingToResponseBodyNotSupported(object statusCode) => string.Format(CultureInfo.CurrentCulture, GetString("WritingToResponseBodyNotSupported", "statusCode"), statusCode); - /// - /// Cannot write to the response body, the response has completed. - /// - internal static string WritingToResponseBodyAfterResponseCompleted - { - get => GetString("WritingToResponseBodyAfterResponseCompleted"); - } - /// /// Connection shutdown abnormally. /// @@ -1800,6 +1792,34 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core internal static string FormatHttp2NotSupported() => GetString("Http2NotSupported"); + /// + /// Cannot write to the response body, the response has completed. + /// + internal static string WritingToResponseBodyAfterResponseCompleted + { + get => GetString("WritingToResponseBodyAfterResponseCompleted"); + } + + /// + /// Cannot write to the response body, the response has completed. + /// + internal static string FormatWritingToResponseBodyAfterResponseCompleted() + => GetString("WritingToResponseBodyAfterResponseCompleted"); + + /// + /// Reading the request body timed out due to data arriving too slowly. See MinRequestBodyDataRate. + /// + internal static string BadRequest_RequestBodyTimeout + { + get => GetString("BadRequest_RequestBodyTimeout"); + } + + /// + /// Reading the request body timed out due to data arriving too slowly. See MinRequestBodyDataRate. + /// + internal static string FormatBadRequest_RequestBodyTimeout() + => GetString("BadRequest_RequestBodyTimeout"); + private static string GetString(string name, params string[] formatterNames) { var value = _resourceManager.GetString(name); From 592ae79cf5840b0fb3321031b7f45ae9f8d483b0 Mon Sep 17 00:00:00 2001 From: "ASP.NET CI" Date: Thu, 8 Mar 2018 13:05:15 -0800 Subject: [PATCH 1555/1662] Update dependencies.props [auto-updated: dependencies] --- build/dependencies.props | 40 ++++++++++++++++++++-------------------- korebuild-lock.txt | 4 ++-- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/build/dependencies.props b/build/dependencies.props index 96de726343..dd30197b3e 100644 --- a/build/dependencies.props +++ b/build/dependencies.props @@ -5,29 +5,29 @@ 0.10.11 - 2.1.0-preview2-15721 + 2.1.0-preview2-15728 1.10.0 - 2.1.0-preview2-30220 - 2.1.0-preview2-30220 - 2.1.0-preview2-30220 - 2.1.0-preview2-30220 - 2.1.0-preview2-30220 - 2.1.0-preview2-30220 - 2.1.0-preview2-30220 - 2.1.0-preview2-30220 - 2.1.0-preview2-30220 - 2.1.0-preview2-30220 - 2.1.0-preview2-30220 - 2.1.0-preview2-30220 - 2.1.0-preview2-30220 - 2.1.0-preview2-30220 - 2.1.0-preview2-30220 - 2.1.0-preview2-30220 - 2.1.0-preview2-30220 - 2.1.0-preview2-30220 + 2.1.0-preview2-30272 + 2.1.0-preview2-30272 + 2.1.0-preview2-30272 + 2.1.0-preview2-30272 + 2.1.0-preview2-30272 + 2.1.0-preview2-30272 + 2.1.0-preview2-30272 + 2.1.0-preview2-30272 + 2.1.0-preview2-30272 + 2.1.0-preview2-30272 + 2.1.0-preview2-30272 + 2.1.0-preview2-30272 + 2.1.0-preview2-30272 + 2.1.0-preview2-30272 + 2.1.0-preview2-30272 + 2.1.0-preview2-30272 + 2.1.0-preview2-30272 + 2.1.0-preview2-30272 2.0.0 2.1.0-preview2-26225-03 - 2.1.0-preview2-30220 + 2.1.0-preview2-30272 15.6.0 4.7.49 10.0.1 diff --git a/korebuild-lock.txt b/korebuild-lock.txt index bdaa7048b3..138d848db1 100644 --- a/korebuild-lock.txt +++ b/korebuild-lock.txt @@ -1,2 +1,2 @@ -version:2.1.0-preview2-15726 -commithash:599e691c41f502ed9e062b1822ce13b673fc916e +version:2.1.0-preview2-15728 +commithash:393377068ddcf51dfee0536536d455f57a828b06 From fc80c15a65d45b8c7a0251c32a086af149761007 Mon Sep 17 00:00:00 2001 From: Pavel Krymets Date: Thu, 8 Mar 2018 14:23:07 -0800 Subject: [PATCH 1556/1662] Update to new corefx (#2369) --- ...Http1ConnectionParsingOverheadBenchmark.cs | 3 +- .../Http1WritingBenchmark.cs | 3 +- .../HttpProtocolFeatureCollection.cs | 3 +- .../InMemoryTransportBenchmark.cs | 2 +- .../RequestParsingBenchmark.cs | 5 +- .../ResponseHeaderCollectionBenchmark.cs | 3 +- .../ResponseHeadersWritingBenchmark.cs | 3 +- build/dependencies.props | 19 ++-- src/Directory.Build.props | 4 +- .../Adapter/Internal/LoggingStream.cs | 2 +- .../Adapter/Internal/RawStream.cs | 2 +- .../Internal/ConnectionHandler.cs | 6 +- .../Internal/Http/Http1Connection.cs | 3 +- .../Internal/Http/Http1MessageBody.cs | 7 +- .../Internal/Http/Http1OutputProducer.cs | 39 +++++-- src/Kestrel.Core/Internal/Http/HttpParser.cs | 6 +- .../Internal/Http/HttpProtocol.cs | 5 +- .../Internal/Http/HttpResponseStream.cs | 4 +- src/Kestrel.Core/Internal/Http/MessageBody.cs | 2 +- .../Internal/Http/PipelineExtensions.cs | 7 +- .../Internal/Http2/Http2Connection.cs | 2 +- .../Internal/Http2/Http2FrameReader.cs | 2 +- src/Kestrel.Core/Internal/HttpConnection.cs | 6 +- .../Internal/Infrastructure/Heartbeat.cs | 13 ++- .../Infrastructure/InlineLoggingThreadPool.cs | 7 +- .../Infrastructure/LoggingThreadPool.cs | 7 +- .../Internal/LibuvConnection.cs | 2 +- .../Internal/LibuvThread.cs | 16 +-- .../Internal/Networking/UvMemory.cs | 2 +- src/Kestrel.Transport.Libuv/LibuvTransport.cs | 2 +- .../Internal/BufferExtensions.cs | 6 +- src/Protocols.Abstractions/DuplexPipe.cs | 5 - test/Kestrel.Core.Tests/AsciiDecoding.cs | 3 +- test/Kestrel.Core.Tests/HeartbeatTests.cs | 4 +- .../Http1ConnectionTests.cs | 3 +- .../Http2ConnectionTests.cs | 3 +- .../Kestrel.Core.Tests/HttpConnectionTests.cs | 3 +- test/Kestrel.Core.Tests/HttpParserTests.cs | 107 +++--------------- .../HttpProtocolFeatureCollectionTests.cs | 11 +- .../HttpResponseHeadersTests.cs | 3 +- .../Kestrel.Core.Tests.csproj | 1 + .../Kestrel.Core.Tests/OutputProducerTests.cs | 3 +- .../PipelineExtensionTests.cs | 2 +- test/Kestrel.Core.Tests/TestInput.cs | 2 +- .../KeepAliveTimeoutTests.cs | 3 +- .../TestHelpers/TestServer.cs | 18 ++- .../TransportSelector.cs | 2 +- .../LibuvConnectionTests.cs | 14 ++- .../LibuvOutputConsumerTests.cs | 30 +++-- .../TestHelpers/MockConnectionHandler.cs | 4 +- .../TransportSelector.cs | 2 +- 51 files changed, 200 insertions(+), 216 deletions(-) diff --git a/benchmarks/Kestrel.Performance/Http1ConnectionParsingOverheadBenchmark.cs b/benchmarks/Kestrel.Performance/Http1ConnectionParsingOverheadBenchmark.cs index 4d3f9ec311..3046c5f1e9 100644 --- a/benchmarks/Kestrel.Performance/Http1ConnectionParsingOverheadBenchmark.cs +++ b/benchmarks/Kestrel.Performance/Http1ConnectionParsingOverheadBenchmark.cs @@ -24,7 +24,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance public void Setup() { var memoryPool = KestrelMemoryPool.Create(); - var pair = DuplexPipe.CreateConnectionPair(memoryPool); + var options = new PipeOptions(memoryPool, readerScheduler: PipeScheduler.Inline, writerScheduler: PipeScheduler.Inline, useSynchronizationContext: false); + var pair = DuplexPipe.CreateConnectionPair(options, options); var serviceContext = new ServiceContext { diff --git a/benchmarks/Kestrel.Performance/Http1WritingBenchmark.cs b/benchmarks/Kestrel.Performance/Http1WritingBenchmark.cs index d3137dac17..891d94ab0a 100644 --- a/benchmarks/Kestrel.Performance/Http1WritingBenchmark.cs +++ b/benchmarks/Kestrel.Performance/Http1WritingBenchmark.cs @@ -96,7 +96,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance private TestHttp1Connection MakeHttp1Connection() { - var pair = DuplexPipe.CreateConnectionPair(_memoryPool); + var options = new PipeOptions(_memoryPool, readerScheduler: PipeScheduler.Inline, writerScheduler: PipeScheduler.Inline, useSynchronizationContext: false); + var pair = DuplexPipe.CreateConnectionPair(options, options); _pair = pair; var serviceContext = new ServiceContext diff --git a/benchmarks/Kestrel.Performance/HttpProtocolFeatureCollection.cs b/benchmarks/Kestrel.Performance/HttpProtocolFeatureCollection.cs index 081d17dc79..24b2c6c4b6 100644 --- a/benchmarks/Kestrel.Performance/HttpProtocolFeatureCollection.cs +++ b/benchmarks/Kestrel.Performance/HttpProtocolFeatureCollection.cs @@ -80,7 +80,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance public HttpProtocolFeatureCollection() { var memoryPool = KestrelMemoryPool.Create(); - var pair = DuplexPipe.CreateConnectionPair(memoryPool); + var options = new PipeOptions(memoryPool, readerScheduler: PipeScheduler.Inline, writerScheduler: PipeScheduler.Inline, useSynchronizationContext: false); + var pair = DuplexPipe.CreateConnectionPair(options, options); var serviceContext = new ServiceContext { diff --git a/benchmarks/Kestrel.Performance/InMemoryTransportBenchmark.cs b/benchmarks/Kestrel.Performance/InMemoryTransportBenchmark.cs index 73b94be6e1..0cf3e137a3 100644 --- a/benchmarks/Kestrel.Performance/InMemoryTransportBenchmark.cs +++ b/benchmarks/Kestrel.Performance/InMemoryTransportBenchmark.cs @@ -156,7 +156,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance public class InMemoryConnection : TransportConnection { - public PipeAwaiter SendRequestAsync(byte[] request) + public ValueTask SendRequestAsync(byte[] request) { return Input.WriteAsync(request); } diff --git a/benchmarks/Kestrel.Performance/RequestParsingBenchmark.cs b/benchmarks/Kestrel.Performance/RequestParsingBenchmark.cs index e6ea256d01..2d881588d2 100644 --- a/benchmarks/Kestrel.Performance/RequestParsingBenchmark.cs +++ b/benchmarks/Kestrel.Performance/RequestParsingBenchmark.cs @@ -25,7 +25,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance public void Setup() { _memoryPool = KestrelMemoryPool.Create(); - var pair = DuplexPipe.CreateConnectionPair(_memoryPool); + var options = new PipeOptions(_memoryPool, readerScheduler: PipeScheduler.Inline, writerScheduler: PipeScheduler.Inline, useSynchronizationContext: false); + var pair = DuplexPipe.CreateConnectionPair(options, options); var serviceContext = new ServiceContext { @@ -147,7 +148,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance return; } - var readableBuffer = awaitable.GetResult().Buffer; + var readableBuffer = awaitable.GetAwaiter().GetResult().Buffer; do { Http1Connection.Reset(); diff --git a/benchmarks/Kestrel.Performance/ResponseHeaderCollectionBenchmark.cs b/benchmarks/Kestrel.Performance/ResponseHeaderCollectionBenchmark.cs index b36f674ba4..e04f007222 100644 --- a/benchmarks/Kestrel.Performance/ResponseHeaderCollectionBenchmark.cs +++ b/benchmarks/Kestrel.Performance/ResponseHeaderCollectionBenchmark.cs @@ -172,7 +172,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance public void Setup() { var memoryPool = KestrelMemoryPool.Create(); - var pair = DuplexPipe.CreateConnectionPair(memoryPool); + var options = new PipeOptions(memoryPool, readerScheduler: PipeScheduler.Inline, writerScheduler: PipeScheduler.Inline, useSynchronizationContext: false); + var pair = DuplexPipe.CreateConnectionPair(options, options); var serviceContext = new ServiceContext { diff --git a/benchmarks/Kestrel.Performance/ResponseHeadersWritingBenchmark.cs b/benchmarks/Kestrel.Performance/ResponseHeadersWritingBenchmark.cs index 67b3705238..69df7fdb88 100644 --- a/benchmarks/Kestrel.Performance/ResponseHeadersWritingBenchmark.cs +++ b/benchmarks/Kestrel.Performance/ResponseHeadersWritingBenchmark.cs @@ -114,7 +114,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance public void Setup() { _memoryPool = KestrelMemoryPool.Create(); - var pair = DuplexPipe.CreateConnectionPair(_memoryPool); + var options = new PipeOptions(_memoryPool, readerScheduler: PipeScheduler.Inline, writerScheduler: PipeScheduler.Inline, useSynchronizationContext: false); + var pair = DuplexPipe.CreateConnectionPair(options, options); var serviceContext = new ServiceContext { diff --git a/build/dependencies.props b/build/dependencies.props index dd30197b3e..b83388dd08 100644 --- a/build/dependencies.props +++ b/build/dependencies.props @@ -16,7 +16,8 @@ 2.1.0-preview2-30272 2.1.0-preview2-30272 2.1.0-preview2-30272 - 2.1.0-preview2-30272 + 2.1.0-preview2-pk-corefx0-16426 + 2.1.0-preview2-pk-corefx0-16426 2.1.0-preview2-30272 2.1.0-preview2-30272 2.1.0-preview2-30272 @@ -26,18 +27,18 @@ 2.1.0-preview2-30272 2.1.0-preview2-30272 2.0.0 - 2.1.0-preview2-26225-03 + 2.1.0-preview2-26308-01 2.1.0-preview2-30272 15.6.0 4.7.49 10.0.1 - 4.5.0-preview2-26224-02 - 4.5.0-preview2-26224-02 - 4.5.0-preview2-26224-02 - 4.5.0-preview2-26224-02 - 4.5.0-preview2-26224-02 - 4.5.0-preview2-26224-02 - 4.5.0-preview2-26224-02 + 4.5.0-preview2-26308-02 + 4.5.0-preview2-26308-02 + 4.5.0-preview2-26308-02 + 4.5.0-preview2-26308-02 + 4.5.0-preview2-26308-02 + 4.5.0-preview2-26308-02 + 4.5.0-preview2-26308-02 0.8.0 2.3.1 2.4.0-beta.1.build3945 diff --git a/src/Directory.Build.props b/src/Directory.Build.props index 4b89a431e7..a1676ede80 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -1,6 +1,8 @@ - + + $(DefineConstants);INNER_LOOP + diff --git a/src/Kestrel.Core/Adapter/Internal/LoggingStream.cs b/src/Kestrel.Core/Adapter/Internal/LoggingStream.cs index 62f62a5d4c..0b5fdf3975 100644 --- a/src/Kestrel.Core/Adapter/Internal/LoggingStream.cs +++ b/src/Kestrel.Core/Adapter/Internal/LoggingStream.cs @@ -139,7 +139,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal } #if NETCOREAPP2_1 - public override Task WriteAsync(ReadOnlyMemory source, CancellationToken cancellationToken = default) + public override ValueTask WriteAsync(ReadOnlyMemory source, CancellationToken cancellationToken = default) { Log("WriteAsync", source.Span); return _inner.WriteAsync(source, cancellationToken); diff --git a/src/Kestrel.Core/Adapter/Internal/RawStream.cs b/src/Kestrel.Core/Adapter/Internal/RawStream.cs index 32fb757db2..ea381c22b2 100644 --- a/src/Kestrel.Core/Adapter/Internal/RawStream.cs +++ b/src/Kestrel.Core/Adapter/Internal/RawStream.cs @@ -92,7 +92,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal } #if NETCOREAPP2_1 - public override async Task WriteAsync(ReadOnlyMemory source, CancellationToken cancellationToken = default) + public override async ValueTask WriteAsync(ReadOnlyMemory source, CancellationToken cancellationToken = default) { _output.Write(source.Span); await _output.FlushAsync(cancellationToken); diff --git a/src/Kestrel.Core/Internal/ConnectionHandler.cs b/src/Kestrel.Core/Internal/ConnectionHandler.cs index 8cd9552522..12ea3d189c 100644 --- a/src/Kestrel.Core/Internal/ConnectionHandler.cs +++ b/src/Kestrel.Core/Internal/ConnectionHandler.cs @@ -89,7 +89,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal readerScheduler: serviceContext.ThreadPool, writerScheduler: writerScheduler, pauseWriterThreshold: serviceContext.ServerOptions.Limits.MaxRequestBufferSize ?? 0, - resumeWriterThreshold: serviceContext.ServerOptions.Limits.MaxRequestBufferSize ?? 0 + resumeWriterThreshold: serviceContext.ServerOptions.Limits.MaxRequestBufferSize ?? 0, + useSynchronizationContext: false ); internal static PipeOptions GetOutputPipeOptions(ServiceContext serviceContext, MemoryPool memoryPool, PipeScheduler readerScheduler) => new PipeOptions @@ -98,7 +99,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal readerScheduler: readerScheduler, writerScheduler: serviceContext.ThreadPool, pauseWriterThreshold: GetOutputResponseBufferSize(serviceContext), - resumeWriterThreshold: GetOutputResponseBufferSize(serviceContext) + resumeWriterThreshold: GetOutputResponseBufferSize(serviceContext), + useSynchronizationContext: false ); private static long GetOutputResponseBufferSize(ServiceContext serviceContext) diff --git a/src/Kestrel.Core/Internal/Http/Http1Connection.cs b/src/Kestrel.Core/Internal/Http/Http1Connection.cs index 3876e63194..1251ac3518 100644 --- a/src/Kestrel.Core/Internal/Http/Http1Connection.cs +++ b/src/Kestrel.Core/Internal/Http/Http1Connection.cs @@ -10,6 +10,7 @@ using System.Runtime.InteropServices; using System.Text; using System.Text.Encodings.Web; using System.Threading; +using System.Threading.Tasks; using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Protocols.Abstractions; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; @@ -429,7 +430,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http TimeoutControl.SetTimeout(_keepAliveTicks, TimeoutAction.StopProcessingNextRequest); } - protected override bool BeginRead(out PipeAwaiter awaitable) + protected override bool BeginRead(out ValueTask awaitable) { awaitable = Input.ReadAsync(); return true; diff --git a/src/Kestrel.Core/Internal/Http/Http1MessageBody.cs b/src/Kestrel.Core/Internal/Http/Http1MessageBody.cs index 503e21e5bd..5ac13c69a4 100644 --- a/src/Kestrel.Core/Internal/Http/Http1MessageBody.cs +++ b/src/Kestrel.Core/Internal/Http/Http1MessageBody.cs @@ -93,12 +93,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http BadHttpRequestException.Throw(RequestRejectionReason.UnexpectedEndOfRequestContent); } - awaitable = _context.Input.ReadAsync(); } finally { _context.Input.AdvanceTo(consumed, examined); } + + awaitable = _context.Input.ReadAsync(); } } catch (Exception ex) @@ -320,7 +321,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http var actual = (int)Math.Min(readableBuffer.Length, _inputLength); _inputLength -= actual; - consumed = readableBuffer.GetPosition(readableBuffer.Start, actual); + consumed = readableBuffer.GetPosition(actual); examined = consumed; Copy(readableBuffer.Slice(0, actual), writableBuffer); @@ -561,7 +562,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http private void ReadChunkedData(ReadOnlySequence buffer, PipeWriter writableBuffer, out SequencePosition consumed, out SequencePosition examined) { var actual = Math.Min(buffer.Length, _inputLength); - consumed = buffer.GetPosition(buffer.Start, actual); + consumed = buffer.GetPosition(actual); examined = consumed; Copy(buffer.Slice(0, actual), writableBuffer); diff --git a/src/Kestrel.Core/Internal/Http/Http1OutputProducer.cs b/src/Kestrel.Core/Internal/Http/Http1OutputProducer.cs index 3ecbf9298f..d767539185 100644 --- a/src/Kestrel.Core/Internal/Http/Http1OutputProducer.cs +++ b/src/Kestrel.Core/Internal/Http/Http1OutputProducer.cs @@ -38,6 +38,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http private readonly object _flushLock = new object(); private Action _flushCompleted; + private ValueTask _flushTask; + public Http1OutputProducer( PipeReader outputPipeReader, PipeWriter pipeWriter, @@ -200,7 +202,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http return FlushAsyncAwaited(awaitable, bytesWritten, cancellationToken); } - private async Task FlushAsyncAwaited(PipeAwaiter awaitable, long count, CancellationToken cancellationToken) + private async Task FlushAsyncAwaited(ValueTask awaitable, long count, CancellationToken cancellationToken) { // https://github.com/dotnet/corefxlab/issues/1334 // Since the flush awaitable doesn't currently support multiple awaiters @@ -208,24 +210,47 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http // All awaiters get the same task lock (_flushLock) { + _flushTask = awaitable; if (_flushTcs == null || _flushTcs.Task.IsCompleted) { _flushTcs = new TaskCompletionSource(); - awaitable.OnCompleted(_flushCompleted); + _flushTask.GetAwaiter().OnCompleted(_flushCompleted); } } _timeoutControl.StartTimingWrite(count); - await _flushTcs.Task; - _timeoutControl.StopTimingWrite(); - - cancellationToken.ThrowIfCancellationRequested(); + try + { + await _flushTcs.Task; + cancellationToken.ThrowIfCancellationRequested(); + } + catch (OperationCanceledException) + { + _completed = true; + throw; + } + finally + { + _timeoutControl.StopTimingWrite(); + } } private void OnFlushCompleted() { - _flushTcs.TrySetResult(null); + try + { + _flushTask.GetAwaiter().GetResult(); + _flushTcs.TrySetResult(null); + } + catch (Exception exception) + { + _flushTcs.TrySetResult(exception); + } + finally + { + _flushTask = default; + } } } } diff --git a/src/Kestrel.Core/Internal/Http/HttpParser.cs b/src/Kestrel.Core/Internal/Http/HttpParser.cs index 976841466a..416976b8ac 100644 --- a/src/Kestrel.Core/Internal/Http/HttpParser.cs +++ b/src/Kestrel.Core/Internal/Http/HttpParser.cs @@ -44,7 +44,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http var lineIndex = span.IndexOf(ByteLF); if (lineIndex >= 0) { - consumed = buffer.GetPosition(consumed, lineIndex + 1); + consumed = buffer.GetPosition(lineIndex + 1, consumed); span = span.Slice(0, lineIndex + 1); } else if (buffer.IsSingleSegment) @@ -293,7 +293,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http var lineEnd = lineEndPosition.Value; // Make sure LF is included in lineEnd - lineEnd = buffer.GetPosition(lineEnd, 1); + lineEnd = buffer.GetPosition(1, lineEnd); var headerSpan = buffer.Slice(current, lineEnd).ToSpan(); length = headerSpan.Length; @@ -425,7 +425,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http if (byteLfPosition != null) { // Move 1 byte past the \n - found = buffer.GetPosition(byteLfPosition.Value, 1); + found = buffer.GetPosition(1, byteLfPosition.Value); return true; } diff --git a/src/Kestrel.Core/Internal/Http/HttpProtocol.cs b/src/Kestrel.Core/Internal/Http/HttpProtocol.cs index ad90b76a1e..2954368f4c 100644 --- a/src/Kestrel.Core/Internal/Http/HttpProtocol.cs +++ b/src/Kestrel.Core/Internal/Http/HttpProtocol.cs @@ -383,7 +383,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { } - protected virtual bool BeginRead(out PipeAwaiter awaitable) + protected virtual bool BeginRead(out ValueTask awaitable) { awaitable = default; return false; @@ -1336,7 +1336,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http readerScheduler: ServiceContext.ThreadPool, writerScheduler: PipeScheduler.Inline, pauseWriterThreshold: 1, - resumeWriterThreshold: 1 + resumeWriterThreshold: 1, + useSynchronizationContext: false )); } } diff --git a/src/Kestrel.Core/Internal/Http/HttpResponseStream.cs b/src/Kestrel.Core/Internal/Http/HttpResponseStream.cs index 93cea42956..fb2cc91a9d 100644 --- a/src/Kestrel.Core/Internal/Http/HttpResponseStream.cs +++ b/src/Kestrel.Core/Internal/Http/HttpResponseStream.cs @@ -112,11 +112,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http } #if NETCOREAPP2_1 - public override Task WriteAsync(ReadOnlyMemory source, CancellationToken cancellationToken = default) + public override ValueTask WriteAsync(ReadOnlyMemory source, CancellationToken cancellationToken = default) { ValidateState(cancellationToken); - return _httpResponseControl.WriteAsync(source, cancellationToken); + return new ValueTask(_httpResponseControl.WriteAsync(source, cancellationToken)); } #endif diff --git a/src/Kestrel.Core/Internal/Http/MessageBody.cs b/src/Kestrel.Core/Internal/Http/MessageBody.cs index 2ebf6f1212..a406e64ffa 100644 --- a/src/Kestrel.Core/Internal/Http/MessageBody.cs +++ b/src/Kestrel.Core/Internal/Http/MessageBody.cs @@ -53,7 +53,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http // buffer.Count is int var actual = (int) Math.Min(readableBuffer.Length, buffer.Length); var slice = readableBuffer.Slice(0, actual); - consumed = readableBuffer.GetPosition(readableBuffer.Start, actual); + consumed = readableBuffer.GetPosition(actual); slice.CopyTo(buffer.Span); return actual; } diff --git a/src/Kestrel.Core/Internal/Http/PipelineExtensions.cs b/src/Kestrel.Core/Internal/Http/PipelineExtensions.cs index b5a2664bda..e56c43b23c 100644 --- a/src/Kestrel.Core/Internal/Http/PipelineExtensions.cs +++ b/src/Kestrel.Core/Internal/Http/PipelineExtensions.cs @@ -28,12 +28,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http public static ArraySegment GetArray(this Memory buffer) { - ArraySegment result; - if (!buffer.TryGetArray(out result)) - { - throw new InvalidOperationException("Buffer backed by array was expected"); - } - return result; + return ((ReadOnlyMemory)buffer).GetArray(); } public static ArraySegment GetArray(this ReadOnlyMemory memory) diff --git a/src/Kestrel.Core/Internal/Http2/Http2Connection.cs b/src/Kestrel.Core/Internal/Http2/Http2Connection.cs index d0b46039db..0e1928720f 100644 --- a/src/Kestrel.Core/Internal/Http2/Http2Connection.cs +++ b/src/Kestrel.Core/Internal/Http2/Http2Connection.cs @@ -237,7 +237,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 } } - consumed = examined = readableBuffer.GetPosition(readableBuffer.Start, ClientPreface.Length); + consumed = examined = readableBuffer.GetPosition(ClientPreface.Length); return true; } diff --git a/src/Kestrel.Core/Internal/Http2/Http2FrameReader.cs b/src/Kestrel.Core/Internal/Http2/Http2FrameReader.cs index b9d84fc896..6b2ab584db 100644 --- a/src/Kestrel.Core/Internal/Http2/Http2FrameReader.cs +++ b/src/Kestrel.Core/Internal/Http2/Http2FrameReader.cs @@ -28,7 +28,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 } readableBuffer.Slice(Http2Frame.HeaderLength, frame.Length).CopyTo(frame.Payload); - consumed = examined = readableBuffer.GetPosition(readableBuffer.Start, Http2Frame.HeaderLength + frame.Length); + consumed = examined = readableBuffer.GetPosition(Http2Frame.HeaderLength + frame.Length); return true; } diff --git a/src/Kestrel.Core/Internal/HttpConnection.cs b/src/Kestrel.Core/Internal/HttpConnection.cs index b3895a72c9..aff705e7ee 100644 --- a/src/Kestrel.Core/Internal/HttpConnection.cs +++ b/src/Kestrel.Core/Internal/HttpConnection.cs @@ -77,7 +77,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal readerScheduler: _context.ServiceContext.ThreadPool, writerScheduler: PipeScheduler.Inline, pauseWriterThreshold: _context.ServiceContext.ServerOptions.Limits.MaxRequestBufferSize ?? 0, - resumeWriterThreshold: _context.ServiceContext.ServerOptions.Limits.MaxRequestBufferSize ?? 0 + resumeWriterThreshold: _context.ServiceContext.ServerOptions.Limits.MaxRequestBufferSize ?? 0, + useSynchronizationContext: false ); internal PipeOptions AdaptedOutputPipeOptions => new PipeOptions @@ -86,7 +87,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal readerScheduler: PipeScheduler.Inline, writerScheduler: PipeScheduler.Inline, pauseWriterThreshold: _context.ServiceContext.ServerOptions.Limits.MaxResponseBufferSize ?? 0, - resumeWriterThreshold: _context.ServiceContext.ServerOptions.Limits.MaxResponseBufferSize ?? 0 + resumeWriterThreshold: _context.ServiceContext.ServerOptions.Limits.MaxResponseBufferSize ?? 0, + useSynchronizationContext: false ); private IKestrelTrace Log => _context.ServiceContext.Log; diff --git a/src/Kestrel.Core/Internal/Infrastructure/Heartbeat.cs b/src/Kestrel.Core/Internal/Infrastructure/Heartbeat.cs index f722f60e9d..fb0f17d83b 100644 --- a/src/Kestrel.Core/Internal/Infrastructure/Heartbeat.cs +++ b/src/Kestrel.Core/Internal/Infrastructure/Heartbeat.cs @@ -15,20 +15,27 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure private readonly ISystemClock _systemClock; private readonly IDebugger _debugger; private readonly IKestrelTrace _trace; + private readonly TimeSpan _interval; private Timer _timer; private int _executingOnHeartbeat; - public Heartbeat(IHeartbeatHandler[] callbacks, ISystemClock systemClock, IDebugger debugger, IKestrelTrace trace) + public Heartbeat(IHeartbeatHandler[] callbacks, ISystemClock systemClock, IDebugger debugger, IKestrelTrace trace): this(callbacks, systemClock, debugger, trace, Interval) + { + + } + + internal Heartbeat(IHeartbeatHandler[] callbacks, ISystemClock systemClock, IDebugger debugger, IKestrelTrace trace, TimeSpan interval) { _callbacks = callbacks; _systemClock = systemClock; _debugger = debugger; _trace = trace; + _interval = interval; } public void Start() { - _timer = new Timer(OnHeartbeat, state: this, dueTime: Interval, period: Interval); + _timer = new Timer(OnHeartbeat, state: this, dueTime: _interval, period: _interval); } private static void OnHeartbeat(object state) @@ -63,7 +70,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure { if (!_debugger.IsAttached) { - _trace.HeartbeatSlow(Interval, now); + _trace.HeartbeatSlow(_interval, now); } } } diff --git a/src/Kestrel.Core/Internal/Infrastructure/InlineLoggingThreadPool.cs b/src/Kestrel.Core/Internal/Infrastructure/InlineLoggingThreadPool.cs index 26219bf8b0..b3ab4c905b 100644 --- a/src/Kestrel.Core/Internal/Infrastructure/InlineLoggingThreadPool.cs +++ b/src/Kestrel.Core/Internal/Infrastructure/InlineLoggingThreadPool.cs @@ -33,12 +33,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure action(state); } - public override void Schedule(Action action) - { - Run(action); - } - - public override void Schedule(Action action, object state) + public override void Schedule(Action action, T state) { try { diff --git a/src/Kestrel.Core/Internal/Infrastructure/LoggingThreadPool.cs b/src/Kestrel.Core/Internal/Infrastructure/LoggingThreadPool.cs index 70c90bd1ea..da0ae6ac39 100644 --- a/src/Kestrel.Core/Internal/Infrastructure/LoggingThreadPool.cs +++ b/src/Kestrel.Core/Internal/Infrastructure/LoggingThreadPool.cs @@ -50,12 +50,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure System.Threading.ThreadPool.QueueUserWorkItem(action, state); } - public override void Schedule(Action action) - { - Run(action); - } - - public override void Schedule(Action action, object state) + public override void Schedule(Action action, T state) { Run(() => action(state)); } diff --git a/src/Kestrel.Transport.Libuv/Internal/LibuvConnection.cs b/src/Kestrel.Transport.Libuv/Internal/LibuvConnection.cs index bb98d1c8c1..b5df138e61 100644 --- a/src/Kestrel.Transport.Libuv/Internal/LibuvConnection.cs +++ b/src/Kestrel.Transport.Libuv/Internal/LibuvConnection.cs @@ -173,7 +173,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal _bufferHandle.Dispose(); } - private async Task ApplyBackpressureAsync(PipeAwaiter flushTask) + private async Task ApplyBackpressureAsync(ValueTask flushTask) { Log.ConnectionPause(ConnectionId); _socket.ReadStop(); diff --git a/src/Kestrel.Transport.Libuv/Internal/LibuvThread.cs b/src/Kestrel.Transport.Libuv/Internal/LibuvThread.cs index 0d6530303f..f26f656528 100644 --- a/src/Kestrel.Transport.Libuv/Internal/LibuvThread.cs +++ b/src/Kestrel.Transport.Libuv/Internal/LibuvThread.cs @@ -48,8 +48,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal _log = transport.Log; _loop = new UvLoopHandle(_log); _post = new UvAsyncHandle(_log); + _thread = new Thread(ThreadStart); +#if !INNER_LOOP _thread.Name = nameof(LibuvThread); +#endif + #if !DEBUG // Mark the thread as being as unimportant to keeping the process alive. // Don't do this for debug builds, so we know if the thread isn't terminating. @@ -132,7 +136,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal _closeError?.Throw(); } -#if DEBUG +#if DEBUG && !INNER_LOOP private void CheckUvReqLeaks() { GC.Collect(); @@ -177,6 +181,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal { CallbackAdapter = CallbackAdapter.PostCallbackAdapter, Callback = callback, + //TODO: This boxes State = state }; @@ -301,7 +306,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal WriteReqPool.Dispose(); _threadTcs.SetResult(null); -#if DEBUG +#if DEBUG && !INNER_LOOP // Check for handle leaks after disposing everything CheckUvReqLeaks(); #endif @@ -391,12 +396,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal return await Task.WhenAny(task, Task.Delay(timeout)).ConfigureAwait(false) == task; } - public override void Schedule(Action action) - { - Post(state => state(), action); - } - - public override void Schedule(Action action, object state) + public override void Schedule(Action action, T state) { Post(action, state); } diff --git a/src/Kestrel.Transport.Libuv/Internal/Networking/UvMemory.cs b/src/Kestrel.Transport.Libuv/Internal/Networking/UvMemory.cs index 1285777910..9454e6fc23 100644 --- a/src/Kestrel.Transport.Libuv/Internal/Networking/UvMemory.cs +++ b/src/Kestrel.Transport.Libuv/Internal/Networking/UvMemory.cs @@ -51,7 +51,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networkin { _uv = uv; ThreadId = threadId; - + handle = Marshal.AllocCoTaskMem(size); *(IntPtr*)handle = GCHandle.ToIntPtr(GCHandle.Alloc(this, _handleType)); } diff --git a/src/Kestrel.Transport.Libuv/LibuvTransport.cs b/src/Kestrel.Transport.Libuv/LibuvTransport.cs index f3d376c3f3..19eb6cf72e 100644 --- a/src/Kestrel.Transport.Libuv/LibuvTransport.cs +++ b/src/Kestrel.Transport.Libuv/LibuvTransport.cs @@ -62,7 +62,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv } Threads.Clear(); -#if DEBUG +#if DEBUG && !INNER_LOOP GC.Collect(); GC.WaitForPendingFinalizers(); GC.Collect(); diff --git a/src/Kestrel.Transport.Sockets/Internal/BufferExtensions.cs b/src/Kestrel.Transport.Sockets/Internal/BufferExtensions.cs index 7340736bd8..9985dfbc5b 100644 --- a/src/Kestrel.Transport.Sockets/Internal/BufferExtensions.cs +++ b/src/Kestrel.Transport.Sockets/Internal/BufferExtensions.cs @@ -10,11 +10,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal { public static ArraySegment GetArray(this Memory memory) { - if (!memory.TryGetArray(out var result)) - { - throw new InvalidOperationException("Buffer backed by array was expected"); - } - return result; + return ((ReadOnlyMemory)memory).GetArray(); } public static ArraySegment GetArray(this ReadOnlyMemory memory) diff --git a/src/Protocols.Abstractions/DuplexPipe.cs b/src/Protocols.Abstractions/DuplexPipe.cs index 60fc029aec..adf8b497c6 100644 --- a/src/Protocols.Abstractions/DuplexPipe.cs +++ b/src/Protocols.Abstractions/DuplexPipe.cs @@ -18,11 +18,6 @@ namespace System.IO.Pipelines { } - public static DuplexPipePair CreateConnectionPair(MemoryPool memoryPool) - { - return CreateConnectionPair(new PipeOptions(memoryPool), new PipeOptions(memoryPool)); - } - public static DuplexPipePair CreateConnectionPair(PipeOptions inputOptions, PipeOptions outputOptions) { var input = new Pipe(inputOptions); diff --git a/test/Kestrel.Core.Tests/AsciiDecoding.cs b/test/Kestrel.Core.Tests/AsciiDecoding.cs index 8f593f9671..7fa45513d2 100644 --- a/test/Kestrel.Core.Tests/AsciiDecoding.cs +++ b/test/Kestrel.Core.Tests/AsciiDecoding.cs @@ -3,6 +3,7 @@ using System; using System.Linq; +using System.Numerics; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; using Xunit; @@ -41,7 +42,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests [InlineData(0x80)] private void ExceptionThrownForZeroOrNonAscii(byte b) { - for (var length = 1; length < 1024; length++) + for (var length = 1; length < Vector.Count * 4; length++) { for (var position = 0; position < length; position++) { diff --git a/test/Kestrel.Core.Tests/HeartbeatTests.cs b/test/Kestrel.Core.Tests/HeartbeatTests.cs index bf80664c6d..86fc9093f3 100644 --- a/test/Kestrel.Core.Tests/HeartbeatTests.cs +++ b/test/Kestrel.Core.Tests/HeartbeatTests.cs @@ -65,11 +65,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests debugger.Setup(d => d.IsAttached).Returns(true); kestrelTrace.Setup(t => t.HeartbeatSlow(Heartbeat.Interval, systemClock.UtcNow)).Callback(() => traceMre.Set()); - using (var heartbeat = new Heartbeat(new[] { heartbeatHandler.Object }, systemClock, debugger.Object, kestrelTrace.Object)) + using (var heartbeat = new Heartbeat(new[] { heartbeatHandler.Object }, systemClock, debugger.Object, kestrelTrace.Object, TimeSpan.FromSeconds(0.01))) { onHeartbeatTasks[0] = Task.Run(() => heartbeat.OnHeartbeat()); onHeartbeatTasks[1] = Task.Run(() => heartbeat.OnHeartbeat()); - Assert.False(traceMre.Wait(TimeSpan.FromSeconds(10))); + Assert.False(traceMre.Wait(TimeSpan.FromSeconds(2))); } handlerMre.Set(); diff --git a/test/Kestrel.Core.Tests/Http1ConnectionTests.cs b/test/Kestrel.Core.Tests/Http1ConnectionTests.cs index 7428e20ec2..c4cac14b78 100644 --- a/test/Kestrel.Core.Tests/Http1ConnectionTests.cs +++ b/test/Kestrel.Core.Tests/Http1ConnectionTests.cs @@ -41,7 +41,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests public Http1ConnectionTests() { _pipelineFactory = KestrelMemoryPool.Create(); - var pair = DuplexPipe.CreateConnectionPair(_pipelineFactory); + var options = new PipeOptions(_pipelineFactory, readerScheduler: PipeScheduler.Inline, writerScheduler: PipeScheduler.Inline, useSynchronizationContext: false); + var pair = DuplexPipe.CreateConnectionPair(options, options); _transport = pair.Transport; _application = pair.Application; diff --git a/test/Kestrel.Core.Tests/Http2ConnectionTests.cs b/test/Kestrel.Core.Tests/Http2ConnectionTests.cs index ca49803ee4..7766a9179b 100644 --- a/test/Kestrel.Core.Tests/Http2ConnectionTests.cs +++ b/test/Kestrel.Core.Tests/Http2ConnectionTests.cs @@ -126,7 +126,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests var inlineSchedulingPipeOptions = new PipeOptions( pool: _memoryPool, readerScheduler: PipeScheduler.Inline, - writerScheduler: PipeScheduler.Inline + writerScheduler: PipeScheduler.Inline, + useSynchronizationContext: false ); _pair = DuplexPipe.CreateConnectionPair(inlineSchedulingPipeOptions, inlineSchedulingPipeOptions); diff --git a/test/Kestrel.Core.Tests/HttpConnectionTests.cs b/test/Kestrel.Core.Tests/HttpConnectionTests.cs index 27b1c3c5b3..8710055844 100644 --- a/test/Kestrel.Core.Tests/HttpConnectionTests.cs +++ b/test/Kestrel.Core.Tests/HttpConnectionTests.cs @@ -26,7 +26,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests public HttpConnectionTests() { _memoryPool = KestrelMemoryPool.Create(); - var pair = DuplexPipe.CreateConnectionPair(_memoryPool); + var options = new PipeOptions(_memoryPool, readerScheduler: PipeScheduler.Inline, writerScheduler: PipeScheduler.Inline, useSynchronizationContext: false); + var pair = DuplexPipe.CreateConnectionPair(options, options); _httpConnectionContext = new HttpConnectionContext { diff --git a/test/Kestrel.Core.Tests/HttpParserTests.cs b/test/Kestrel.Core.Tests/HttpParserTests.cs index 8baa695f96..dec3c68681 100644 --- a/test/Kestrel.Core.Tests/HttpParserTests.cs +++ b/test/Kestrel.Core.Tests/HttpParserTests.cs @@ -18,6 +18,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests { public class HttpParserTests { + private static IKestrelTrace _nullTrace = Mock.Of(); + [Theory] [MemberData(nameof(RequestLineValidData))] public void ParsesRequestLine( @@ -33,7 +35,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests #pragma warning restore xUnit1026 string expectedVersion) { - var parser = CreateParser(Mock.Of()); + var parser = CreateParser(_nullTrace); var buffer = new ReadOnlySequence(Encoding.ASCII.GetBytes(requestLine)); var requestHandler = new RequestHandler(); @@ -52,7 +54,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests [MemberData(nameof(RequestLineIncompleteData))] public void ParseRequestLineReturnsFalseWhenGivenIncompleteRequestLines(string requestLine) { - var parser = CreateParser(Mock.Of()); + var parser = CreateParser(_nullTrace); var buffer = new ReadOnlySequence(Encoding.ASCII.GetBytes(requestLine)); var requestHandler = new RequestHandler(); @@ -63,7 +65,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests [MemberData(nameof(RequestLineIncompleteData))] public void ParseRequestLineDoesNotConsumeIncompleteRequestLine(string requestLine) { - var parser = CreateParser(Mock.Of()); + var parser = CreateParser(_nullTrace); var buffer = new ReadOnlySequence(Encoding.ASCII.GetBytes(requestLine)); var requestHandler = new RequestHandler(); @@ -176,7 +178,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests [InlineData("Header-1: value1\r\nHeader-2: value2\r\n\r")] public void ParseHeadersReturnsFalseWhenGivenIncompleteHeaders(string rawHeaders) { - var parser = CreateParser(Mock.Of()); + var parser = CreateParser(_nullTrace); var buffer = new ReadOnlySequence(Encoding.ASCII.GetBytes(rawHeaders)); var requestHandler = new RequestHandler(); @@ -201,7 +203,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests [InlineData("Header: value\r")] public void ParseHeadersDoesNotConsumeIncompleteHeader(string rawHeaders) { - var parser = CreateParser(Mock.Of()); + var parser = CreateParser(_nullTrace); var buffer = new ReadOnlySequence(Encoding.ASCII.GetBytes(rawHeaders)); var requestHandler = new RequestHandler(); @@ -290,14 +292,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests [Fact] public void ParseHeadersConsumesBytesCorrectlyAtEnd() { - var parser = CreateParser(Mock.Of()); + var parser = CreateParser(_nullTrace); const string headerLine = "Header: value\r\n\r"; var buffer1 = new ReadOnlySequence(Encoding.ASCII.GetBytes(headerLine)); var requestHandler = new RequestHandler(); Assert.False(parser.ParseHeaders(requestHandler, buffer1, out var consumed, out var examined, out var consumedBytes)); - Assert.Equal(buffer1.GetPosition(buffer1.Start, headerLine.Length - 1), consumed); + Assert.Equal(buffer1.GetPosition(headerLine.Length - 1), consumed); Assert.Equal(buffer1.End, examined); Assert.Equal(headerLine.Length - 1, consumedBytes); @@ -371,8 +373,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests [Fact] public void ParseRequestLineSplitBufferWithoutNewLineDoesNotUpdateConsumed() { - var parser = CreateParser(Mock.Of()); - var buffer = CreateBuffer("GET ", "/"); + var parser = CreateParser(_nullTrace); + var buffer = ReadOnlySequenceFactory.CreateSegments( + Encoding.ASCII.GetBytes("GET "), + Encoding.ASCII.GetBytes("/")); var requestHandler = new RequestHandler(); var result = parser.ParseRequestLine(requestHandler, buffer, out var consumed, out var examined); @@ -387,7 +391,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests string rawHeaderValue, string expectedHeaderValue) { - var parser = CreateParser(Mock.Of()); + var parser = CreateParser(_nullTrace); var buffer = new ReadOnlySequence(Encoding.ASCII.GetBytes($"{headerName}:{rawHeaderValue}\r\n")); var requestHandler = new RequestHandler(); @@ -405,7 +409,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests { Assert.True(expectedHeaderNames.Count() == expectedHeaderValues.Count(), $"{nameof(expectedHeaderNames)} and {nameof(expectedHeaderValues)} sizes must match"); - var parser = CreateParser(Mock.Of()); + var parser = CreateParser(_nullTrace); var buffer = new ReadOnlySequence(Encoding.ASCII.GetBytes(rawHeaders)); var requestHandler = new RequestHandler(); @@ -465,86 +469,5 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests PathEncoded = pathEncoded; } } - - private static ReadOnlySequence CreateBuffer(params string[] inputs) - { - var buffers = new byte[inputs.Length][]; - for (int i = 0; i < inputs.Length; i++) - { - buffers[i] = Encoding.UTF8.GetBytes(inputs[i]); - } - return CreateBuffer(buffers); - } - - // Copied from https://github.com/dotnet/corefx/blob/master/src/System.Memory/tests/ReadOnlyBuffer/ReadOnlySequenceFactory.cs - private static ReadOnlySequence CreateBuffer(params byte[][] inputs) - { - if (inputs == null || inputs.Length == 0) - { - throw new InvalidOperationException(); - } - - int i = 0; - - BufferSegment last = null; - BufferSegment first = null; - - do - { - byte[] s = inputs[i]; - int length = s.Length; - int dataOffset = length; - var chars = new byte[length * 2]; - - for (int j = 0; j < length; j++) - { - chars[dataOffset + j] = s[j]; - } - - // Create a segment that has offset relative to the OwnedMemory and OwnedMemory itself has offset relative to array - var memory = new Memory(chars).Slice(length, length); - - if (first == null) - { - first = new BufferSegment(memory); - last = first; - } - else - { - last = last.Append(memory); - } - i++; - } while (i < inputs.Length); - - return new ReadOnlySequence(first, 0, last, last.Memory.Length); - } - - // Copied from https://github.com/dotnet/corefx/blob/master/src/System.Memory/tests/ReadOnlyBuffer/BufferSegment.cs - private class BufferSegment : IMemoryList - { - public BufferSegment(Memory memory) - { - Memory = memory; - } - - /// - /// Combined length of all segments before this - /// - public long RunningIndex { get; private set; } - - public Memory Memory { get; set; } - - public IMemoryList Next { get; private set; } - - public BufferSegment Append(Memory memory) - { - var segment = new BufferSegment(memory) - { - RunningIndex = RunningIndex + Memory.Length - }; - Next = segment; - return segment; - } - } } } diff --git a/test/Kestrel.Core.Tests/HttpProtocolFeatureCollectionTests.cs b/test/Kestrel.Core.Tests/HttpProtocolFeatureCollectionTests.cs index 846b441862..84d08ff3d7 100644 --- a/test/Kestrel.Core.Tests/HttpProtocolFeatureCollectionTests.cs +++ b/test/Kestrel.Core.Tests/HttpProtocolFeatureCollectionTests.cs @@ -24,15 +24,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests private readonly TestHttp1Connection _http1Connection; private readonly ServiceContext _serviceContext; private readonly Http1ConnectionContext _http1ConnectionContext; - private readonly MemoryPool _pipelineFactory; + private readonly MemoryPool _memoryPool; private Mock _timeoutControl; private readonly IFeatureCollection _collection; public HttpProtocolFeatureCollectionTests() { - _pipelineFactory = KestrelMemoryPool.Create(); - var pair = DuplexPipe.CreateConnectionPair(_pipelineFactory); + _memoryPool = KestrelMemoryPool.Create(); + var options = new PipeOptions(_memoryPool, readerScheduler: PipeScheduler.Inline, writerScheduler: PipeScheduler.Inline, useSynchronizationContext: false); + var pair = DuplexPipe.CreateConnectionPair(options, options); _transport = pair.Transport; _application = pair.Application; @@ -43,7 +44,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests { ServiceContext = _serviceContext, ConnectionFeatures = new FeatureCollection(), - MemoryPool = _pipelineFactory, + MemoryPool = _memoryPool, TimeoutControl = _timeoutControl.Object, Application = pair.Application, Transport = pair.Transport @@ -62,7 +63,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests _application.Input.Complete(); _application.Output.Complete(); - _pipelineFactory.Dispose(); + _memoryPool.Dispose(); } [Fact] diff --git a/test/Kestrel.Core.Tests/HttpResponseHeadersTests.cs b/test/Kestrel.Core.Tests/HttpResponseHeadersTests.cs index 8a602351ad..a8e2e7f441 100644 --- a/test/Kestrel.Core.Tests/HttpResponseHeadersTests.cs +++ b/test/Kestrel.Core.Tests/HttpResponseHeadersTests.cs @@ -23,7 +23,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests { using (var memoryPool = KestrelMemoryPool.Create()) { - var pair = DuplexPipe.CreateConnectionPair(memoryPool); + var options = new PipeOptions(memoryPool, readerScheduler: PipeScheduler.Inline, writerScheduler: PipeScheduler.Inline, useSynchronizationContext: false); + var pair = DuplexPipe.CreateConnectionPair(options, options); var http1ConnectionContext = new Http1ConnectionContext { ServiceContext = new TestServiceContext(), diff --git a/test/Kestrel.Core.Tests/Kestrel.Core.Tests.csproj b/test/Kestrel.Core.Tests/Kestrel.Core.Tests.csproj index fdbbd000ef..2d65668838 100644 --- a/test/Kestrel.Core.Tests/Kestrel.Core.Tests.csproj +++ b/test/Kestrel.Core.Tests/Kestrel.Core.Tests.csproj @@ -23,6 +23,7 @@ + diff --git a/test/Kestrel.Core.Tests/OutputProducerTests.cs b/test/Kestrel.Core.Tests/OutputProducerTests.cs index 8cd730fca0..dc063922ff 100644 --- a/test/Kestrel.Core.Tests/OutputProducerTests.cs +++ b/test/Kestrel.Core.Tests/OutputProducerTests.cs @@ -35,7 +35,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests ( pool: _memoryPool, readerScheduler: Mock.Of(), - writerScheduler: PipeScheduler.Inline + writerScheduler: PipeScheduler.Inline, + useSynchronizationContext: false ); using (var socketOutput = CreateOutputProducer(pipeOptions)) diff --git a/test/Kestrel.Core.Tests/PipelineExtensionTests.cs b/test/Kestrel.Core.Tests/PipelineExtensionTests.cs index 35e4f02e05..485183ff85 100644 --- a/test/Kestrel.Core.Tests/PipelineExtensionTests.cs +++ b/test/Kestrel.Core.Tests/PipelineExtensionTests.cs @@ -21,7 +21,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests public PipelineExtensionTests() { - _pipe = new Pipe(new PipeOptions(_memoryPool, readerScheduler: PipeScheduler.Inline, writerScheduler: PipeScheduler.Inline)); + _pipe = new Pipe(new PipeOptions(_memoryPool, readerScheduler: PipeScheduler.Inline, writerScheduler: PipeScheduler.Inline, useSynchronizationContext: false)); } public void Dispose() diff --git a/test/Kestrel.Core.Tests/TestInput.cs b/test/Kestrel.Core.Tests/TestInput.cs index f91def83ec..1295121548 100644 --- a/test/Kestrel.Core.Tests/TestInput.cs +++ b/test/Kestrel.Core.Tests/TestInput.cs @@ -22,7 +22,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests public TestInput() { _memoryPool = KestrelMemoryPool.Create(); - var options = new PipeOptions(pool: _memoryPool, readerScheduler: PipeScheduler.Inline, writerScheduler: PipeScheduler.Inline); + var options = new PipeOptions(pool: _memoryPool, readerScheduler: PipeScheduler.Inline, writerScheduler: PipeScheduler.Inline, useSynchronizationContext: false); var pair = DuplexPipe.CreateConnectionPair(options, options); Transport = pair.Transport; Application = pair.Application; diff --git a/test/Kestrel.FunctionalTests/KeepAliveTimeoutTests.cs b/test/Kestrel.FunctionalTests/KeepAliveTimeoutTests.cs index 5d4a3c553f..32278e4159 100644 --- a/test/Kestrel.FunctionalTests/KeepAliveTimeoutTests.cs +++ b/test/Kestrel.FunctionalTests/KeepAliveTimeoutTests.cs @@ -1,6 +1,6 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - +#if !INNER_LOOP using System; using System.Text; using System.Threading; @@ -252,3 +252,4 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } } } +#endif \ No newline at end of file diff --git a/test/Kestrel.FunctionalTests/TestHelpers/TestServer.cs b/test/Kestrel.FunctionalTests/TestHelpers/TestServer.cs index 0aff951af4..7cf3399dd5 100644 --- a/test/Kestrel.FunctionalTests/TestHelpers/TestServer.cs +++ b/test/Kestrel.FunctionalTests/TestHelpers/TestServer.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Linq; using System.Net; using System.Net.Sockets; using System.Reflection; @@ -11,9 +12,11 @@ using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting.Server; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Server.Kestrel.Core; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal; using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; using Microsoft.AspNetCore.Testing; using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.DependencyInjection.Extensions; using Microsoft.Extensions.Options; namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests @@ -68,7 +71,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } return new KestrelServer(sp.GetRequiredService(), context); }); - + RemoveDevCert(services); configureServices(services); }) .UseSetting(WebHostDefaults.ApplicationKey, typeof(TestServer).GetTypeInfo().Assembly.FullName) @@ -77,6 +80,19 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests _host.Start(); } + public static void RemoveDevCert(IServiceCollection services) + { + // KestrelServerOptionsSetup would scan all system certificates on every test server creation + // making test runs very slow + foreach (var descriptor in services.ToArray()) + { + if (descriptor.ImplementationType == typeof(KestrelServerOptionsSetup)) + { + services.Remove(descriptor); + } + } + } + public IPEndPoint EndPoint => _listenOptions.IPEndPoint; public int Port => _listenOptions.IPEndPoint.Port; public AddressFamily AddressFamily => _listenOptions.IPEndPoint.AddressFamily; diff --git a/test/Kestrel.Transport.Libuv.FunctionalTests/TransportSelector.cs b/test/Kestrel.Transport.Libuv.FunctionalTests/TransportSelector.cs index cba3395d11..db778d603b 100644 --- a/test/Kestrel.Transport.Libuv.FunctionalTests/TransportSelector.cs +++ b/test/Kestrel.Transport.Libuv.FunctionalTests/TransportSelector.cs @@ -9,7 +9,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { public static IWebHostBuilder GetWebHostBuilder() { - return new WebHostBuilder().UseLibuv(); + return new WebHostBuilder().UseLibuv().ConfigureServices(TestServer.RemoveDevCert); } } } diff --git a/test/Kestrel.Transport.Libuv.Tests/LibuvConnectionTests.cs b/test/Kestrel.Transport.Libuv.Tests/LibuvConnectionTests.cs index 5071a3cbad..2eeec77ab7 100644 --- a/test/Kestrel.Transport.Libuv.Tests/LibuvConnectionTests.cs +++ b/test/Kestrel.Transport.Libuv.Tests/LibuvConnectionTests.cs @@ -64,11 +64,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests pool: pool, pauseWriterThreshold: 3, readerScheduler: PipeScheduler.Inline, - writerScheduler: PipeScheduler.Inline); + writerScheduler: PipeScheduler.Inline, + useSynchronizationContext: false); // We don't set the output writer scheduler here since we want to run the callback inline - mockConnectionHandler.OutputOptions = pool => new PipeOptions(pool: pool, readerScheduler: thread, writerScheduler: PipeScheduler.Inline); + mockConnectionHandler.OutputOptions = pool => new PipeOptions(pool: pool, readerScheduler: thread, writerScheduler: PipeScheduler.Inline, useSynchronizationContext: false); Task connectionTask = null; @@ -121,9 +122,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests var thread = new LibuvThread(transport); var mockScheduler = new Mock(); Action backPressure = null; - mockScheduler.Setup(m => m.Schedule(It.IsAny())).Callback(a => + mockScheduler.Setup(m => m.Schedule(It.IsAny>(), It.IsAny())).Callback, object>((a, o) => { - backPressure = a; + backPressure = () => a(o); }); mockConnectionHandler.InputOptions = pool => new PipeOptions( @@ -131,9 +132,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests pauseWriterThreshold: 3, resumeWriterThreshold: 3, writerScheduler: mockScheduler.Object, - readerScheduler: PipeScheduler.Inline); + readerScheduler: PipeScheduler.Inline, + useSynchronizationContext: false); - mockConnectionHandler.OutputOptions = pool => new PipeOptions(pool: pool, readerScheduler: thread, writerScheduler: PipeScheduler.Inline); + mockConnectionHandler.OutputOptions = pool => new PipeOptions(pool: pool, readerScheduler: thread, writerScheduler: PipeScheduler.Inline, useSynchronizationContext: false); Task connectionTask = null; try diff --git a/test/Kestrel.Transport.Libuv.Tests/LibuvOutputConsumerTests.cs b/test/Kestrel.Transport.Libuv.Tests/LibuvOutputConsumerTests.cs index adc58f5794..3b6d6abf7c 100644 --- a/test/Kestrel.Transport.Libuv.Tests/LibuvOutputConsumerTests.cs +++ b/test/Kestrel.Transport.Libuv.Tests/LibuvOutputConsumerTests.cs @@ -69,7 +69,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests readerScheduler: _libuvThread, writerScheduler: PipeScheduler.Inline, pauseWriterThreshold: maxResponseBufferSize ?? 0, - resumeWriterThreshold: maxResponseBufferSize ?? 0 + resumeWriterThreshold: maxResponseBufferSize ?? 0, + useSynchronizationContext: false ); using (var outputProducer = CreateOutputProducer(pipeOptions)) @@ -106,7 +107,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests readerScheduler: _libuvThread, writerScheduler: PipeScheduler.Inline, pauseWriterThreshold: 0, - resumeWriterThreshold: 0 + resumeWriterThreshold: 0, + useSynchronizationContext: false ); using (var outputProducer = CreateOutputProducer(pipeOptions)) @@ -155,7 +157,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests readerScheduler: _libuvThread, writerScheduler: PipeScheduler.Inline, pauseWriterThreshold: 1, - resumeWriterThreshold: 1 + resumeWriterThreshold: 1, + useSynchronizationContext: false ); using (var outputProducer = CreateOutputProducer(pipeOptions)) @@ -212,7 +215,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests readerScheduler: _libuvThread, writerScheduler: PipeScheduler.Inline, pauseWriterThreshold: maxResponseBufferSize, - resumeWriterThreshold: maxResponseBufferSize + resumeWriterThreshold: maxResponseBufferSize, + useSynchronizationContext: false ); using (var outputProducer = CreateOutputProducer(pipeOptions)) @@ -277,7 +281,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests readerScheduler: _libuvThread, writerScheduler: PipeScheduler.Inline, pauseWriterThreshold: maxResponseBufferSize, - resumeWriterThreshold: maxResponseBufferSize + resumeWriterThreshold: maxResponseBufferSize, + useSynchronizationContext: false ); using (var outputProducer = CreateOutputProducer(pipeOptions)) @@ -348,7 +353,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests readerScheduler: _libuvThread, writerScheduler: PipeScheduler.Inline, pauseWriterThreshold: maxResponseBufferSize, - resumeWriterThreshold: maxResponseBufferSize + resumeWriterThreshold: maxResponseBufferSize, + useSynchronizationContext: false ); using (var outputProducer = CreateOutputProducer(pipeOptions, abortedSource)) @@ -442,7 +448,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests readerScheduler: _libuvThread, writerScheduler: PipeScheduler.Inline, pauseWriterThreshold: maxResponseBufferSize, - resumeWriterThreshold: maxResponseBufferSize + resumeWriterThreshold: maxResponseBufferSize, + useSynchronizationContext: false ); using (var outputProducer = CreateOutputProducer(pipeOptions)) @@ -527,7 +534,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests readerScheduler: _libuvThread, writerScheduler: PipeScheduler.Inline, pauseWriterThreshold: maxResponseBufferSize, - resumeWriterThreshold: maxResponseBufferSize + resumeWriterThreshold: maxResponseBufferSize, + useSynchronizationContext: false ); using (var outputProducer = CreateOutputProducer(pipeOptions)) @@ -610,7 +618,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests readerScheduler: _libuvThread, writerScheduler: PipeScheduler.Inline, pauseWriterThreshold: maxResponseBufferSize, - resumeWriterThreshold: maxResponseBufferSize + resumeWriterThreshold: maxResponseBufferSize, + useSynchronizationContext: false ); using (var outputProducer = CreateOutputProducer(pipeOptions)) @@ -672,7 +681,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests readerScheduler: _libuvThread, writerScheduler: PipeScheduler.Inline, pauseWriterThreshold: maxResponseBufferSize ?? 0, - resumeWriterThreshold: maxResponseBufferSize ?? 0 + resumeWriterThreshold: maxResponseBufferSize ?? 0, + useSynchronizationContext: false ); using (var outputProducer = CreateOutputProducer(pipeOptions)) diff --git a/test/Kestrel.Transport.Libuv.Tests/TestHelpers/MockConnectionHandler.cs b/test/Kestrel.Transport.Libuv.Tests/TestHelpers/MockConnectionHandler.cs index e6e8ec3738..daf6cdd27c 100644 --- a/test/Kestrel.Transport.Libuv.Tests/TestHelpers/MockConnectionHandler.cs +++ b/test/Kestrel.Transport.Libuv.Tests/TestHelpers/MockConnectionHandler.cs @@ -13,8 +13,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests.TestHelpers { public class MockConnectionHandler : IConnectionHandler { - public Func, PipeOptions> InputOptions { get; set; } = pool => new PipeOptions(pool, readerScheduler: PipeScheduler.Inline, writerScheduler: PipeScheduler.Inline); - public Func, PipeOptions> OutputOptions { get; set; } = pool => new PipeOptions(pool, readerScheduler: PipeScheduler.Inline, writerScheduler: PipeScheduler.Inline); + public Func, PipeOptions> InputOptions { get; set; } = pool => new PipeOptions(pool, readerScheduler: PipeScheduler.Inline, writerScheduler: PipeScheduler.Inline, useSynchronizationContext: false); + public Func, PipeOptions> OutputOptions { get; set; } = pool => new PipeOptions(pool, readerScheduler: PipeScheduler.Inline, writerScheduler: PipeScheduler.Inline, useSynchronizationContext: false); public void OnConnection(IFeatureCollection features) { diff --git a/test/Kestrel.Transport.Sockets.FunctionalTests/TransportSelector.cs b/test/Kestrel.Transport.Sockets.FunctionalTests/TransportSelector.cs index 1a433cc9ec..52d2b0a4a8 100644 --- a/test/Kestrel.Transport.Sockets.FunctionalTests/TransportSelector.cs +++ b/test/Kestrel.Transport.Sockets.FunctionalTests/TransportSelector.cs @@ -9,7 +9,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { public static IWebHostBuilder GetWebHostBuilder() { - return new WebHostBuilder().UseSockets(); + return new WebHostBuilder().UseSockets().ConfigureServices(TestServer.RemoveDevCert); } } } From f52771d0e9681798d8fbd71866a113d1053fb31d Mon Sep 17 00:00:00 2001 From: Pavel Krymets Date: Thu, 8 Mar 2018 15:24:20 -0800 Subject: [PATCH 1557/1662] Fix MicrosoftExtensionsBuffersTestingSources package version variable --- build/dependencies.props | 2 +- test/Kestrel.Core.Tests/Kestrel.Core.Tests.csproj | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/build/dependencies.props b/build/dependencies.props index b83388dd08..ad5d09463e 100644 --- a/build/dependencies.props +++ b/build/dependencies.props @@ -17,7 +17,7 @@ 2.1.0-preview2-30272 2.1.0-preview2-30272 2.1.0-preview2-pk-corefx0-16426 - 2.1.0-preview2-pk-corefx0-16426 + 2.1.0-preview2-pk-corefx0-16426 2.1.0-preview2-30272 2.1.0-preview2-30272 2.1.0-preview2-30272 diff --git a/test/Kestrel.Core.Tests/Kestrel.Core.Tests.csproj b/test/Kestrel.Core.Tests/Kestrel.Core.Tests.csproj index 2d65668838..3229fd0fa7 100644 --- a/test/Kestrel.Core.Tests/Kestrel.Core.Tests.csproj +++ b/test/Kestrel.Core.Tests/Kestrel.Core.Tests.csproj @@ -23,7 +23,7 @@ - + From 71bff00c0d5a9ac6eb650044cd702dd1cc5fca0f Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Fri, 9 Mar 2018 15:04:20 -0800 Subject: [PATCH 1558/1662] Use LibuvThread inspired IO Queue in Socket transport (#2368) --- .vscode/settings.json | 1 - .../Internal/IOQueue.cs | 67 +++++++++++++++++++ .../Internal/SocketAwaitable.cs | 23 +++++-- .../Internal/SocketConnection.cs | 18 +++-- .../Internal/SocketReceiver.cs | 6 +- .../Internal/SocketSender.cs | 6 +- .../SocketTransport.cs | 53 +++++++++++---- .../SocketTransportFactory.cs | 6 +- .../SocketTransportOptions.cs | 10 ++- 9 files changed, 156 insertions(+), 34 deletions(-) create mode 100644 src/Kestrel.Transport.Sockets/Internal/IOQueue.cs diff --git a/.vscode/settings.json b/.vscode/settings.json index 2c3c5e92d1..0c60b84e84 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -3,7 +3,6 @@ "editor.tabSize": 2 }, "files.trimTrailingWhitespace": true, - "files.insertFinalNewline": true, "files.associations": { "*.props": "xml", "*.targets": "xml" diff --git a/src/Kestrel.Transport.Sockets/Internal/IOQueue.cs b/src/Kestrel.Transport.Sockets/Internal/IOQueue.cs new file mode 100644 index 0000000000..49b6b3e668 --- /dev/null +++ b/src/Kestrel.Transport.Sockets/Internal/IOQueue.cs @@ -0,0 +1,67 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Collections.Concurrent; +using System.IO.Pipelines; +using System.Threading; + +namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal +{ + public class IOQueue : PipeScheduler + { + private static readonly WaitCallback _doWorkCallback = s => ((IOQueue)s).DoWork(); + + private readonly object _workSync = new object(); + private readonly ConcurrentQueue _workItems = new ConcurrentQueue(); + private bool _doingWork; + + public override void Schedule(Action action, T state) + { + var work = new Work + { + CallbackAdapter = (c, s) => ((Action)c)((T)s), + Callback = action, + State = state + }; + + _workItems.Enqueue(work); + + lock (_workSync) + { + if (!_doingWork) + { + System.Threading.ThreadPool.QueueUserWorkItem(_doWorkCallback, this); + _doingWork = true; + } + } + } + + private void DoWork() + { + while (true) + { + while (_workItems.TryDequeue(out Work item)) + { + item.CallbackAdapter(item.Callback, item.State); + } + + lock (_workSync) + { + if (_workItems.IsEmpty) + { + _doingWork = false; + return; + } + } + } + } + + private struct Work + { + public Action CallbackAdapter; + public object Callback; + public object State; + } + } +} diff --git a/src/Kestrel.Transport.Sockets/Internal/SocketAwaitable.cs b/src/Kestrel.Transport.Sockets/Internal/SocketAwaitable.cs index 0ed4ac89bc..f266033a36 100644 --- a/src/Kestrel.Transport.Sockets/Internal/SocketAwaitable.cs +++ b/src/Kestrel.Transport.Sockets/Internal/SocketAwaitable.cs @@ -3,6 +3,7 @@ using System; using System.Diagnostics; +using System.IO.Pipelines; using System.Net.Sockets; using System.Runtime.CompilerServices; using System.Threading; @@ -13,10 +14,17 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal { private static readonly Action _callbackCompleted = () => { }; + private readonly PipeScheduler _ioScheduler; + private Action _callback; - private int _bytesTransfered; + private int _bytesTransferred; private SocketError _error; + public SocketAwaitable(PipeScheduler ioScheduler) + { + _ioScheduler = ioScheduler; + } + public SocketAwaitable GetAwaiter() => this; public bool IsCompleted => ReferenceEquals(_callback, _callbackCompleted); @@ -31,7 +39,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal throw new SocketException((int)_error); } - return _bytesTransfered; + return _bytesTransferred; } public void OnCompleted(Action continuation) @@ -51,8 +59,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal public void Complete(int bytesTransferred, SocketError socketError) { _error = socketError; - _bytesTransfered = bytesTransferred; - Interlocked.Exchange(ref _callback, _callbackCompleted)?.Invoke(); + _bytesTransferred = bytesTransferred; + var continuation = Interlocked.Exchange(ref _callback, _callbackCompleted); + + if (continuation != null) + { + _ioScheduler.Schedule(c => c(), continuation); + } } } -} \ No newline at end of file +} diff --git a/src/Kestrel.Transport.Sockets/Internal/SocketConnection.cs b/src/Kestrel.Transport.Sockets/Internal/SocketConnection.cs index 87fee3379a..d932192165 100644 --- a/src/Kestrel.Transport.Sockets/Internal/SocketConnection.cs +++ b/src/Kestrel.Transport.Sockets/Internal/SocketConnection.cs @@ -8,9 +8,9 @@ using System.IO; using System.IO.Pipelines; using System.Net; using System.Net.Sockets; +using System.Runtime.InteropServices; using System.Threading.Tasks; using Microsoft.AspNetCore.Protocols; -using System.Threading; using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; using Microsoft.Extensions.Logging; @@ -19,15 +19,17 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal internal sealed class SocketConnection : TransportConnection { private const int MinAllocBufferSize = 2048; + public static bool IsWindows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows); private readonly Socket _socket; + private readonly PipeScheduler _scheduler; private readonly ISocketsTrace _trace; private readonly SocketReceiver _receiver; private readonly SocketSender _sender; private volatile bool _aborted; - internal SocketConnection(Socket socket, MemoryPool memoryPool, ISocketsTrace trace) + internal SocketConnection(Socket socket, MemoryPool memoryPool, PipeScheduler scheduler, ISocketsTrace trace) { Debug.Assert(socket != null); Debug.Assert(memoryPool != null); @@ -35,6 +37,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal _socket = socket; MemoryPool = memoryPool; + _scheduler = scheduler; _trace = trace; var localEndPoint = (IPEndPoint)_socket.LocalEndPoint; @@ -46,13 +49,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal RemoteAddress = remoteEndPoint.Address; RemotePort = remoteEndPoint.Port; - _receiver = new SocketReceiver(_socket); - _sender = new SocketSender(_socket); + // On *nix platforms, Sockets already dispatches to the ThreadPool. + var awaiterScheduler = IsWindows ? _scheduler : PipeScheduler.Inline; + + _receiver = new SocketReceiver(_socket, awaiterScheduler); + _sender = new SocketSender(_socket, awaiterScheduler); } public override MemoryPool MemoryPool { get; } - public override PipeScheduler InputWriterScheduler => PipeScheduler.Inline; - public override PipeScheduler OutputReaderScheduler => PipeScheduler.ThreadPool; + public override PipeScheduler InputWriterScheduler => _scheduler; + public override PipeScheduler OutputReaderScheduler => _scheduler; public async Task StartAsync(IConnectionHandler connectionHandler) { diff --git a/src/Kestrel.Transport.Sockets/Internal/SocketReceiver.cs b/src/Kestrel.Transport.Sockets/Internal/SocketReceiver.cs index 0aff7d2cfd..150978e473 100644 --- a/src/Kestrel.Transport.Sockets/Internal/SocketReceiver.cs +++ b/src/Kestrel.Transport.Sockets/Internal/SocketReceiver.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.IO.Pipelines; using System.Net.Sockets; namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal @@ -10,11 +11,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal { private readonly Socket _socket; private readonly SocketAsyncEventArgs _eventArgs = new SocketAsyncEventArgs(); - private readonly SocketAwaitable _awaitable = new SocketAwaitable(); + private readonly SocketAwaitable _awaitable; - public SocketReceiver(Socket socket) + public SocketReceiver(Socket socket, PipeScheduler scheduler) { _socket = socket; + _awaitable = new SocketAwaitable(scheduler); _eventArgs.UserToken = _awaitable; _eventArgs.Completed += (_, e) => ((SocketAwaitable)e.UserToken).Complete(e.BytesTransferred, e.SocketError); } diff --git a/src/Kestrel.Transport.Sockets/Internal/SocketSender.cs b/src/Kestrel.Transport.Sockets/Internal/SocketSender.cs index 2199c60ef5..a8b0727c0a 100644 --- a/src/Kestrel.Transport.Sockets/Internal/SocketSender.cs +++ b/src/Kestrel.Transport.Sockets/Internal/SocketSender.cs @@ -5,6 +5,7 @@ using System; using System.Buffers; using System.Collections.Generic; using System.Diagnostics; +using System.IO.Pipelines; using System.Net.Sockets; using System.Runtime.InteropServices; @@ -14,13 +15,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal { private readonly Socket _socket; private readonly SocketAsyncEventArgs _eventArgs = new SocketAsyncEventArgs(); - private readonly SocketAwaitable _awaitable = new SocketAwaitable(); + private readonly SocketAwaitable _awaitable; private List> _bufferList; - public SocketSender(Socket socket) + public SocketSender(Socket socket, PipeScheduler scheduler) { _socket = socket; + _awaitable = new SocketAwaitable(scheduler); _eventArgs.UserToken = _awaitable; _eventArgs.Completed += (_, e) => ((SocketAwaitable)e.UserToken).Complete(e.BytesTransferred, e.SocketError); } diff --git a/src/Kestrel.Transport.Sockets/SocketTransport.cs b/src/Kestrel.Transport.Sockets/SocketTransport.cs index c27f24767a..9a11e03a0f 100644 --- a/src/Kestrel.Transport.Sockets/SocketTransport.cs +++ b/src/Kestrel.Transport.Sockets/SocketTransport.cs @@ -4,6 +4,7 @@ using System; using System.Buffers; using System.Diagnostics; +using System.IO.Pipelines; using System.Net; using System.Net.Sockets; using System.Runtime.ExceptionServices; @@ -19,10 +20,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets { internal sealed class SocketTransport : ITransport { + private static readonly PipeScheduler[] ThreadPoolSchedulerArray = new PipeScheduler[] { PipeScheduler.ThreadPool }; + private readonly MemoryPool _memoryPool = KestrelMemoryPool.Create(); private readonly IEndPointInformation _endPointInformation; private readonly IConnectionHandler _handler; private readonly IApplicationLifetime _appLifetime; + private readonly int _numSchedulers; + private readonly PipeScheduler[] _schedulers; private readonly ISocketsTrace _trace; private Socket _listenSocket; private Task _listenTask; @@ -33,6 +38,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets IEndPointInformation endPointInformation, IConnectionHandler handler, IApplicationLifetime applicationLifetime, + int ioQueueCount, ISocketsTrace trace) { Debug.Assert(endPointInformation != null); @@ -45,6 +51,22 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets _handler = handler; _appLifetime = applicationLifetime; _trace = trace; + + if (ioQueueCount > 0) + { + _numSchedulers = ioQueueCount; + _schedulers = new IOQueue[_numSchedulers]; + + for (var i = 0; i < _numSchedulers; i++) + { + _schedulers[i] = new IOQueue(); + } + } + else + { + _numSchedulers = ThreadPoolSchedulerArray.Length; + _schedulers = ThreadPoolSchedulerArray; + } } public Task BindAsync() @@ -125,22 +147,25 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets { while (true) { - try + for (var schedulerIndex = 0; schedulerIndex < _numSchedulers; schedulerIndex++) { - var acceptSocket = await _listenSocket.AcceptAsync(); - acceptSocket.NoDelay = _endPointInformation.NoDelay; + try + { + var acceptSocket = await _listenSocket.AcceptAsync(); + acceptSocket.NoDelay = _endPointInformation.NoDelay; - var connection = new SocketConnection(acceptSocket, _memoryPool, _trace); - _ = connection.StartAsync(_handler); - } - catch (SocketException ex) when (ex.SocketErrorCode == SocketError.ConnectionReset) - { - // REVIEW: Should there be a seperate log message for a connection reset this early? - _trace.ConnectionReset(connectionId: "(null)"); - } - catch (SocketException ex) when (!_unbinding) - { - _trace.ConnectionError(connectionId: "(null)", ex); + var connection = new SocketConnection(acceptSocket, _memoryPool, _schedulers[schedulerIndex], _trace); + _ = connection.StartAsync(_handler); + } + catch (SocketException ex) when (ex.SocketErrorCode == SocketError.ConnectionReset) + { + // REVIEW: Should there be a seperate log message for a connection reset this early? + _trace.ConnectionReset(connectionId: "(null)"); + } + catch (SocketException ex) when (!_unbinding) + { + _trace.ConnectionError(connectionId: "(null)", ex); + } } } } diff --git a/src/Kestrel.Transport.Sockets/SocketTransportFactory.cs b/src/Kestrel.Transport.Sockets/SocketTransportFactory.cs index 80320da6f2..473a1519cc 100644 --- a/src/Kestrel.Transport.Sockets/SocketTransportFactory.cs +++ b/src/Kestrel.Transport.Sockets/SocketTransportFactory.cs @@ -12,8 +12,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets { public sealed class SocketTransportFactory : ITransportFactory { - private readonly SocketsTrace _trace; + private readonly SocketTransportOptions _options; private readonly IApplicationLifetime _appLifetime; + private readonly SocketsTrace _trace; public SocketTransportFactory( IOptions options, @@ -33,6 +34,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets throw new ArgumentNullException(nameof(loggerFactory)); } + _options = options.Value; _appLifetime = applicationLifetime; var logger = loggerFactory.CreateLogger("Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets"); _trace = new SocketsTrace(logger); @@ -55,7 +57,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets throw new ArgumentNullException(nameof(handler)); } - return new SocketTransport(endPointInformation, handler, _appLifetime, _trace); + return new SocketTransport(endPointInformation, handler, _appLifetime, _options.IOQueueCount, _trace); } } } diff --git a/src/Kestrel.Transport.Sockets/SocketTransportOptions.cs b/src/Kestrel.Transport.Sockets/SocketTransportOptions.cs index 05bae64609..b6cec0a6d7 100644 --- a/src/Kestrel.Transport.Sockets/SocketTransportOptions.cs +++ b/src/Kestrel.Transport.Sockets/SocketTransportOptions.cs @@ -1,12 +1,18 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets { - // TODO: Come up with some options public class SocketTransportOptions { - + /// + /// The number of I/O queues used to process requests. Set to 0 to directly schedule I/O to the ThreadPool. + /// + /// + /// Defaults to rounded down and clamped between 1 and 16. + /// + public int IOQueueCount { get; set; } = Math.Min(Environment.ProcessorCount, 16); } } From e7d3b0c5f971d6367ccec438407e91807a31447c Mon Sep 17 00:00:00 2001 From: David Fowler Date: Mon, 12 Mar 2018 14:49:19 -0700 Subject: [PATCH 1559/1662] Remove KestrelThreadPool abstraction and replaced it with PipeScheduler (#2371) --- .../Internal/ConnectionHandler.cs | 4 +- .../Internal/Http/HttpProtocol.cs | 4 +- src/Kestrel.Core/Internal/HttpConnection.cs | 2 +- .../Infrastructure/InlineLoggingThreadPool.cs | 48 --------------- .../Infrastructure/KestrelThreadPool.cs | 15 ----- .../Infrastructure/LoggingThreadPool.cs | 58 ------------------- src/Kestrel.Core/Internal/ServiceContext.cs | 3 +- src/Kestrel.Core/KestrelServer.cs | 9 +-- test/Kestrel.Core.Tests/PipeOptionsTests.cs | 10 ++-- test/Kestrel.FunctionalTests/RequestTests.cs | 3 +- .../LibuvOutputConsumerTests.cs | 2 +- .../LibuvTransportTests.cs | 9 +++ .../ListenerPrimaryTests.cs | 4 +- test/shared/TestServiceContext.cs | 3 +- 14 files changed, 33 insertions(+), 141 deletions(-) delete mode 100644 src/Kestrel.Core/Internal/Infrastructure/InlineLoggingThreadPool.cs delete mode 100644 src/Kestrel.Core/Internal/Infrastructure/KestrelThreadPool.cs delete mode 100644 src/Kestrel.Core/Internal/Infrastructure/LoggingThreadPool.cs diff --git a/src/Kestrel.Core/Internal/ConnectionHandler.cs b/src/Kestrel.Core/Internal/ConnectionHandler.cs index 12ea3d189c..f989a61c18 100644 --- a/src/Kestrel.Core/Internal/ConnectionHandler.cs +++ b/src/Kestrel.Core/Internal/ConnectionHandler.cs @@ -86,7 +86,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal internal static PipeOptions GetInputPipeOptions(ServiceContext serviceContext, MemoryPool memoryPool, PipeScheduler writerScheduler) => new PipeOptions ( pool: memoryPool, - readerScheduler: serviceContext.ThreadPool, + readerScheduler: serviceContext.Scheduler, writerScheduler: writerScheduler, pauseWriterThreshold: serviceContext.ServerOptions.Limits.MaxRequestBufferSize ?? 0, resumeWriterThreshold: serviceContext.ServerOptions.Limits.MaxRequestBufferSize ?? 0, @@ -97,7 +97,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal ( pool: memoryPool, readerScheduler: readerScheduler, - writerScheduler: serviceContext.ThreadPool, + writerScheduler: serviceContext.Scheduler, pauseWriterThreshold: GetOutputResponseBufferSize(serviceContext), resumeWriterThreshold: GetOutputResponseBufferSize(serviceContext), useSynchronizationContext: false diff --git a/src/Kestrel.Core/Internal/Http/HttpProtocol.cs b/src/Kestrel.Core/Internal/Http/HttpProtocol.cs index 2954368f4c..30679f525b 100644 --- a/src/Kestrel.Core/Internal/Http/HttpProtocol.cs +++ b/src/Kestrel.Core/Internal/Http/HttpProtocol.cs @@ -422,7 +422,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http Output.Abort(error); // Potentially calling user code. CancelRequestAbortedToken logs any exceptions. - ServiceContext.ThreadPool.UnsafeRun(state => ((HttpProtocol)state).CancelRequestAbortedToken(), this); + ServiceContext.Scheduler.Schedule(state => ((HttpProtocol)state).CancelRequestAbortedToken(), this); } } @@ -1333,7 +1333,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http => new Pipe(new PipeOptions ( pool: _context.MemoryPool, - readerScheduler: ServiceContext.ThreadPool, + readerScheduler: ServiceContext.Scheduler, writerScheduler: PipeScheduler.Inline, pauseWriterThreshold: 1, resumeWriterThreshold: 1, diff --git a/src/Kestrel.Core/Internal/HttpConnection.cs b/src/Kestrel.Core/Internal/HttpConnection.cs index aff705e7ee..fce572a414 100644 --- a/src/Kestrel.Core/Internal/HttpConnection.cs +++ b/src/Kestrel.Core/Internal/HttpConnection.cs @@ -74,7 +74,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal internal PipeOptions AdaptedInputPipeOptions => new PipeOptions ( pool: MemoryPool, - readerScheduler: _context.ServiceContext.ThreadPool, + readerScheduler: _context.ServiceContext.Scheduler, writerScheduler: PipeScheduler.Inline, pauseWriterThreshold: _context.ServiceContext.ServerOptions.Limits.MaxRequestBufferSize ?? 0, resumeWriterThreshold: _context.ServiceContext.ServerOptions.Limits.MaxRequestBufferSize ?? 0, diff --git a/src/Kestrel.Core/Internal/Infrastructure/InlineLoggingThreadPool.cs b/src/Kestrel.Core/Internal/Infrastructure/InlineLoggingThreadPool.cs deleted file mode 100644 index b3ab4c905b..0000000000 --- a/src/Kestrel.Core/Internal/Infrastructure/InlineLoggingThreadPool.cs +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using System.Threading; -using Microsoft.Extensions.Logging; - -namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure -{ - public class InlineLoggingThreadPool : KestrelThreadPool - { - private readonly IKestrelTrace _log; - - public InlineLoggingThreadPool(IKestrelTrace log) - { - _log = log; - } - - public override void Run(Action action) - { - try - { - action(); - } - catch (Exception e) - { - _log.LogError(0, e, "InlineLoggingThreadPool.Run"); - } - } - - public override void UnsafeRun(WaitCallback action, object state) - { - action(state); - } - - public override void Schedule(Action action, T state) - { - try - { - action(state); - } - catch (Exception e) - { - _log.LogError(0, e, "InlineLoggingThreadPool.Schedule"); - } - } - } -} diff --git a/src/Kestrel.Core/Internal/Infrastructure/KestrelThreadPool.cs b/src/Kestrel.Core/Internal/Infrastructure/KestrelThreadPool.cs deleted file mode 100644 index b160a1df5b..0000000000 --- a/src/Kestrel.Core/Internal/Infrastructure/KestrelThreadPool.cs +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using System.IO.Pipelines; -using System.Threading; - -namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure -{ - public abstract class KestrelThreadPool : PipeScheduler - { - public abstract void Run(Action action); - public abstract void UnsafeRun(WaitCallback action, object state); - } -} \ No newline at end of file diff --git a/src/Kestrel.Core/Internal/Infrastructure/LoggingThreadPool.cs b/src/Kestrel.Core/Internal/Infrastructure/LoggingThreadPool.cs deleted file mode 100644 index da0ae6ac39..0000000000 --- a/src/Kestrel.Core/Internal/Infrastructure/LoggingThreadPool.cs +++ /dev/null @@ -1,58 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using System.Threading; -using Microsoft.Extensions.Logging; - -namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure -{ - public class LoggingThreadPool : KestrelThreadPool - { - private readonly IKestrelTrace _log; - - private WaitCallback _runAction; - - public LoggingThreadPool(IKestrelTrace log) - { - _log = log; - - // Curry and capture log in closures once - // The currying is done in functions of the same name to improve the - // call stack for exceptions and profiling else it shows up as LoggingThreadPool.ctor>b__4_0 - // and you aren't sure which of the 3 functions was called. - RunAction(); - } - - private void RunAction() - { - // Capture _log in a singleton closure - _runAction = (o) => - { - try - { - ((Action)o)(); - } - catch (Exception e) - { - _log.LogError(0, e, "LoggingThreadPool.Run"); - } - }; - } - - public override void Run(Action action) - { - System.Threading.ThreadPool.QueueUserWorkItem(_runAction, action); - } - - public override void UnsafeRun(WaitCallback action, object state) - { - System.Threading.ThreadPool.QueueUserWorkItem(action, state); - } - - public override void Schedule(Action action, T state) - { - Run(() => action(state)); - } - } -} \ No newline at end of file diff --git a/src/Kestrel.Core/Internal/ServiceContext.cs b/src/Kestrel.Core/Internal/ServiceContext.cs index 9ca494fa54..1020a6fdbd 100644 --- a/src/Kestrel.Core/Internal/ServiceContext.cs +++ b/src/Kestrel.Core/Internal/ServiceContext.cs @@ -1,6 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System.IO.Pipelines; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; @@ -10,7 +11,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal { public IKestrelTrace Log { get; set; } - public KestrelThreadPool ThreadPool { get; set; } + public PipeScheduler Scheduler { get; set; } public IHttpParser HttpParser { get; set; } diff --git a/src/Kestrel.Core/KestrelServer.cs b/src/Kestrel.Core/KestrelServer.cs index fcf6aedca9..2ab8472cc3 100644 --- a/src/Kestrel.Core/KestrelServer.cs +++ b/src/Kestrel.Core/KestrelServer.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; +using System.IO.Pipelines; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Hosting.Server; @@ -79,15 +80,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core // TODO: This logic will eventually move into the IConnectionHandler and off // the service context once we get to https://github.com/aspnet/KestrelHttpServer/issues/1662 - KestrelThreadPool threadPool = null; + PipeScheduler scheduler = null; switch (serverOptions.ApplicationSchedulingMode) { case SchedulingMode.Default: case SchedulingMode.ThreadPool: - threadPool = new LoggingThreadPool(trace); + scheduler = PipeScheduler.ThreadPool; break; case SchedulingMode.Inline: - threadPool = new InlineLoggingThreadPool(trace); + scheduler = PipeScheduler.Inline; break; default: throw new NotSupportedException(CoreStrings.FormatUnknownTransportMode(serverOptions.ApplicationSchedulingMode)); @@ -97,7 +98,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core { Log = trace, HttpParser = new HttpParser(trace.IsEnabled(LogLevel.Information)), - ThreadPool = threadPool, + Scheduler = scheduler, SystemClock = systemClock, DateHeaderValueManager = dateHeaderValueManager, ConnectionManager = connectionManager, diff --git a/test/Kestrel.Core.Tests/PipeOptionsTests.cs b/test/Kestrel.Core.Tests/PipeOptionsTests.cs index 71a4df8d05..0a15d06491 100644 --- a/test/Kestrel.Core.Tests/PipeOptionsTests.cs +++ b/test/Kestrel.Core.Tests/PipeOptionsTests.cs @@ -23,7 +23,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests { var serviceContext = new TestServiceContext(); serviceContext.ServerOptions.Limits.MaxResponseBufferSize = maxResponseBufferSize; - serviceContext.ThreadPool = new LoggingThreadPool(null); + serviceContext.Scheduler = PipeScheduler.ThreadPool; var mockScheduler = Mock.Of(); var outputPipeOptions = ConnectionHandler.GetOutputPipeOptions(serviceContext, KestrelMemoryPool.Create(), readerScheduler: mockScheduler); @@ -31,7 +31,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests Assert.Equal(expectedMaximumSizeLow, outputPipeOptions.ResumeWriterThreshold); Assert.Equal(expectedMaximumSizeHigh, outputPipeOptions.PauseWriterThreshold); Assert.Same(mockScheduler, outputPipeOptions.ReaderScheduler); - Assert.Same(serviceContext.ThreadPool, outputPipeOptions.WriterScheduler); + Assert.Same(serviceContext.Scheduler, outputPipeOptions.WriterScheduler); } [Theory] @@ -41,14 +41,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests { var serviceContext = new TestServiceContext(); serviceContext.ServerOptions.Limits.MaxRequestBufferSize = maxRequestBufferSize; - serviceContext.ThreadPool = new LoggingThreadPool(null); + serviceContext.Scheduler = PipeScheduler.ThreadPool; var mockScheduler = Mock.Of(); var inputPipeOptions = ConnectionHandler.GetInputPipeOptions(serviceContext, KestrelMemoryPool.Create(), writerScheduler: mockScheduler); Assert.Equal(expectedMaximumSizeLow, inputPipeOptions.ResumeWriterThreshold); Assert.Equal(expectedMaximumSizeHigh, inputPipeOptions.PauseWriterThreshold); - Assert.Same(serviceContext.ThreadPool, inputPipeOptions.ReaderScheduler); + Assert.Same(serviceContext.Scheduler, inputPipeOptions.ReaderScheduler); Assert.Same(mockScheduler, inputPipeOptions.WriterScheduler); } @@ -67,7 +67,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests Assert.Equal(expectedMaximumSizeLow, connectionLifetime.AdaptedInputPipeOptions.ResumeWriterThreshold); Assert.Equal(expectedMaximumSizeHigh, connectionLifetime.AdaptedInputPipeOptions.PauseWriterThreshold); - Assert.Same(serviceContext.ThreadPool, connectionLifetime.AdaptedInputPipeOptions.ReaderScheduler); + Assert.Same(serviceContext.Scheduler, connectionLifetime.AdaptedInputPipeOptions.ReaderScheduler); Assert.Same(PipeScheduler.Inline, connectionLifetime.AdaptedInputPipeOptions.WriterScheduler); } diff --git a/test/Kestrel.FunctionalTests/RequestTests.cs b/test/Kestrel.FunctionalTests/RequestTests.cs index d1fdfd5dc8..8b712af1a2 100644 --- a/test/Kestrel.FunctionalTests/RequestTests.cs +++ b/test/Kestrel.FunctionalTests/RequestTests.cs @@ -6,6 +6,7 @@ using System.Collections.Concurrent; using System.Diagnostics; using System.Globalization; using System.IO; +using System.IO.Pipelines; using System.Linq; using System.Net; using System.Net.Http; @@ -997,7 +998,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { var testContext = new TestServiceContext(); // FIN callbacks are scheduled so run inline to make this test more reliable - testContext.ThreadPool = new InlineLoggingThreadPool(testContext.Log); + testContext.Scheduler = PipeScheduler.Inline; using (var server = new TestServer(TestApp.EchoAppChunked, testContext, listenOptions)) { diff --git a/test/Kestrel.Transport.Libuv.Tests/LibuvOutputConsumerTests.cs b/test/Kestrel.Transport.Libuv.Tests/LibuvOutputConsumerTests.cs index 3b6d6abf7c..ef024facfb 100644 --- a/test/Kestrel.Transport.Libuv.Tests/LibuvOutputConsumerTests.cs +++ b/test/Kestrel.Transport.Libuv.Tests/LibuvOutputConsumerTests.cs @@ -722,7 +722,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests var serviceContext = new TestServiceContext { Log = new TestKestrelTrace(logger), - ThreadPool = new InlineLoggingThreadPool(new TestKestrelTrace(logger)) + Scheduler = PipeScheduler.Inline }; var transportContext = new TestLibuvTransportContext { Log = new LibuvTrace(logger) }; diff --git a/test/Kestrel.Transport.Libuv.Tests/LibuvTransportTests.cs b/test/Kestrel.Transport.Libuv.Tests/LibuvTransportTests.cs index f62a792b85..3f478546da 100644 --- a/test/Kestrel.Transport.Libuv.Tests/LibuvTransportTests.cs +++ b/test/Kestrel.Transport.Libuv.Tests/LibuvTransportTests.cs @@ -1,16 +1,19 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; using System.Collections.Generic; using System.Linq; using System.Net; using System.Net.Http; using System.Net.Sockets; using System.Text; +using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests.TestHelpers; using Microsoft.AspNetCore.Testing; using Microsoft.AspNetCore.Testing.xunit; @@ -128,6 +131,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests } await transport.UnbindAsync(); + + if (!await serviceContext.ConnectionManager.CloseAllConnectionsAsync(default).ConfigureAwait(false)) + { + await serviceContext.ConnectionManager.AbortAllConnectionsAsync().ConfigureAwait(false); + } + await transport.StopAsync(); } } diff --git a/test/Kestrel.Transport.Libuv.Tests/ListenerPrimaryTests.cs b/test/Kestrel.Transport.Libuv.Tests/ListenerPrimaryTests.cs index 0438398b7d..cd243e815b 100644 --- a/test/Kestrel.Transport.Libuv.Tests/ListenerPrimaryTests.cs +++ b/test/Kestrel.Transport.Libuv.Tests/ListenerPrimaryTests.cs @@ -109,7 +109,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests { DateHeaderValueManager = serviceContextPrimary.DateHeaderValueManager, ServerOptions = serviceContextPrimary.ServerOptions, - ThreadPool = serviceContextPrimary.ThreadPool, + Scheduler = serviceContextPrimary.Scheduler, HttpParser = serviceContextPrimary.HttpParser, }; var builderSecondary = new ConnectionBuilder(); @@ -220,7 +220,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests { DateHeaderValueManager = serviceContextPrimary.DateHeaderValueManager, ServerOptions = serviceContextPrimary.ServerOptions, - ThreadPool = serviceContextPrimary.ThreadPool, + Scheduler = serviceContextPrimary.Scheduler, HttpParser = serviceContextPrimary.HttpParser, }; var builderSecondary = new ConnectionBuilder(); diff --git a/test/shared/TestServiceContext.cs b/test/shared/TestServiceContext.cs index 9739022477..d662ee9686 100644 --- a/test/shared/TestServiceContext.cs +++ b/test/shared/TestServiceContext.cs @@ -1,6 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System.IO.Pipelines; using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; @@ -34,7 +35,7 @@ namespace Microsoft.AspNetCore.Testing { LoggerFactory = loggerFactory; Log = kestrelTrace; - ThreadPool = new LoggingThreadPool(Log); + Scheduler = PipeScheduler.ThreadPool; SystemClock = new MockSystemClock(); DateHeaderValueManager = new DateHeaderValueManager(SystemClock); ConnectionManager = new HttpConnectionManager(Log, ResourceCounter.Unlimited); From 2421df85d6a97aa15ffa3148b3d08ff510441c65 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Mon, 12 Mar 2018 23:59:04 -0700 Subject: [PATCH 1560/1662] React to pipelines changes (#2378) --- build/dependencies.props | 54 +++++++++---------- .../Internal/LibuvThread.cs | 2 +- .../Internal/IOQueue.cs | 8 ++- .../Internal/SocketAwaitable.cs | 2 +- 4 files changed, 32 insertions(+), 34 deletions(-) diff --git a/build/dependencies.props b/build/dependencies.props index ad5d09463e..6916e0189a 100644 --- a/build/dependencies.props +++ b/build/dependencies.props @@ -7,38 +7,38 @@ 0.10.11 2.1.0-preview2-15728 1.10.0 - 2.1.0-preview2-30272 - 2.1.0-preview2-30272 - 2.1.0-preview2-30272 - 2.1.0-preview2-30272 - 2.1.0-preview2-30272 - 2.1.0-preview2-30272 - 2.1.0-preview2-30272 - 2.1.0-preview2-30272 - 2.1.0-preview2-30272 - 2.1.0-preview2-pk-corefx0-16426 - 2.1.0-preview2-pk-corefx0-16426 - 2.1.0-preview2-30272 - 2.1.0-preview2-30272 - 2.1.0-preview2-30272 - 2.1.0-preview2-30272 - 2.1.0-preview2-30272 - 2.1.0-preview2-30272 - 2.1.0-preview2-30272 - 2.1.0-preview2-30272 + 2.1.0-preview2-30301 + 2.1.0-preview2-30301 + 2.1.0-preview2-30301 + 2.1.0-preview2-30301 + 2.1.0-preview2-30301 + 2.1.0-preview2-30301 + 2.1.0-preview2-30301 + 2.1.0-preview2-30301 + 2.1.0-preview2-30301 + 2.1.0-preview2-30301 + 2.1.0-preview2-30301 + 2.1.0-preview2-30301 + 2.1.0-preview2-30301 + 2.1.0-preview2-30301 + 2.1.0-preview2-30301 + 2.1.0-preview2-30301 + 2.1.0-preview2-30301 + 2.1.0-preview2-30301 + 2.1.0-preview2-30301 2.0.0 2.1.0-preview2-26308-01 - 2.1.0-preview2-30272 + 2.1.0-preview2-30301 15.6.0 4.7.49 10.0.1 - 4.5.0-preview2-26308-02 - 4.5.0-preview2-26308-02 - 4.5.0-preview2-26308-02 - 4.5.0-preview2-26308-02 - 4.5.0-preview2-26308-02 - 4.5.0-preview2-26308-02 - 4.5.0-preview2-26308-02 + 4.5.0-preview2-26313-02 + 4.5.0-preview2-26313-02 + 4.5.0-preview2-26313-02 + 4.5.0-preview2-26313-02 + 4.5.0-preview2-26313-02 + 4.5.0-preview2-26313-02 + 4.5.0-preview2-26313-02 0.8.0 2.3.1 2.4.0-beta.1.build3945 diff --git a/src/Kestrel.Transport.Libuv/Internal/LibuvThread.cs b/src/Kestrel.Transport.Libuv/Internal/LibuvThread.cs index f26f656528..42b2886c3d 100644 --- a/src/Kestrel.Transport.Libuv/Internal/LibuvThread.cs +++ b/src/Kestrel.Transport.Libuv/Internal/LibuvThread.cs @@ -396,7 +396,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal return await Task.WhenAny(task, Task.Delay(timeout)).ConfigureAwait(false) == task; } - public override void Schedule(Action action, T state) + public override void Schedule(Action action, object state) { Post(action, state); } diff --git a/src/Kestrel.Transport.Sockets/Internal/IOQueue.cs b/src/Kestrel.Transport.Sockets/Internal/IOQueue.cs index 49b6b3e668..6a3e60d1ac 100644 --- a/src/Kestrel.Transport.Sockets/Internal/IOQueue.cs +++ b/src/Kestrel.Transport.Sockets/Internal/IOQueue.cs @@ -16,11 +16,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal private readonly ConcurrentQueue _workItems = new ConcurrentQueue(); private bool _doingWork; - public override void Schedule(Action action, T state) + public override void Schedule(Action action, object state) { var work = new Work { - CallbackAdapter = (c, s) => ((Action)c)((T)s), Callback = action, State = state }; @@ -43,7 +42,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal { while (_workItems.TryDequeue(out Work item)) { - item.CallbackAdapter(item.Callback, item.State); + item.Callback(item.State); } lock (_workSync) @@ -59,8 +58,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal private struct Work { - public Action CallbackAdapter; - public object Callback; + public Action Callback; public object State; } } diff --git a/src/Kestrel.Transport.Sockets/Internal/SocketAwaitable.cs b/src/Kestrel.Transport.Sockets/Internal/SocketAwaitable.cs index f266033a36..1da07c9375 100644 --- a/src/Kestrel.Transport.Sockets/Internal/SocketAwaitable.cs +++ b/src/Kestrel.Transport.Sockets/Internal/SocketAwaitable.cs @@ -64,7 +64,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal if (continuation != null) { - _ioScheduler.Schedule(c => c(), continuation); + _ioScheduler.Schedule(state => ((Action)state)(), continuation); } } } From 2a7bbeb8d792411c0b5e6fd82e44c4bf99b967ee Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Tue, 13 Mar 2018 00:32:52 -0700 Subject: [PATCH 1561/1662] Revert "React to pipelines changes (#2378)" This reverts commit 2421df85d6a97aa15ffa3148b3d08ff510441c65. --- build/dependencies.props | 54 +++++++++---------- .../Internal/LibuvThread.cs | 2 +- .../Internal/IOQueue.cs | 8 +-- .../Internal/SocketAwaitable.cs | 2 +- 4 files changed, 34 insertions(+), 32 deletions(-) diff --git a/build/dependencies.props b/build/dependencies.props index 6916e0189a..ad5d09463e 100644 --- a/build/dependencies.props +++ b/build/dependencies.props @@ -7,38 +7,38 @@ 0.10.11 2.1.0-preview2-15728 1.10.0 - 2.1.0-preview2-30301 - 2.1.0-preview2-30301 - 2.1.0-preview2-30301 - 2.1.0-preview2-30301 - 2.1.0-preview2-30301 - 2.1.0-preview2-30301 - 2.1.0-preview2-30301 - 2.1.0-preview2-30301 - 2.1.0-preview2-30301 - 2.1.0-preview2-30301 - 2.1.0-preview2-30301 - 2.1.0-preview2-30301 - 2.1.0-preview2-30301 - 2.1.0-preview2-30301 - 2.1.0-preview2-30301 - 2.1.0-preview2-30301 - 2.1.0-preview2-30301 - 2.1.0-preview2-30301 - 2.1.0-preview2-30301 + 2.1.0-preview2-30272 + 2.1.0-preview2-30272 + 2.1.0-preview2-30272 + 2.1.0-preview2-30272 + 2.1.0-preview2-30272 + 2.1.0-preview2-30272 + 2.1.0-preview2-30272 + 2.1.0-preview2-30272 + 2.1.0-preview2-30272 + 2.1.0-preview2-pk-corefx0-16426 + 2.1.0-preview2-pk-corefx0-16426 + 2.1.0-preview2-30272 + 2.1.0-preview2-30272 + 2.1.0-preview2-30272 + 2.1.0-preview2-30272 + 2.1.0-preview2-30272 + 2.1.0-preview2-30272 + 2.1.0-preview2-30272 + 2.1.0-preview2-30272 2.0.0 2.1.0-preview2-26308-01 - 2.1.0-preview2-30301 + 2.1.0-preview2-30272 15.6.0 4.7.49 10.0.1 - 4.5.0-preview2-26313-02 - 4.5.0-preview2-26313-02 - 4.5.0-preview2-26313-02 - 4.5.0-preview2-26313-02 - 4.5.0-preview2-26313-02 - 4.5.0-preview2-26313-02 - 4.5.0-preview2-26313-02 + 4.5.0-preview2-26308-02 + 4.5.0-preview2-26308-02 + 4.5.0-preview2-26308-02 + 4.5.0-preview2-26308-02 + 4.5.0-preview2-26308-02 + 4.5.0-preview2-26308-02 + 4.5.0-preview2-26308-02 0.8.0 2.3.1 2.4.0-beta.1.build3945 diff --git a/src/Kestrel.Transport.Libuv/Internal/LibuvThread.cs b/src/Kestrel.Transport.Libuv/Internal/LibuvThread.cs index 42b2886c3d..f26f656528 100644 --- a/src/Kestrel.Transport.Libuv/Internal/LibuvThread.cs +++ b/src/Kestrel.Transport.Libuv/Internal/LibuvThread.cs @@ -396,7 +396,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal return await Task.WhenAny(task, Task.Delay(timeout)).ConfigureAwait(false) == task; } - public override void Schedule(Action action, object state) + public override void Schedule(Action action, T state) { Post(action, state); } diff --git a/src/Kestrel.Transport.Sockets/Internal/IOQueue.cs b/src/Kestrel.Transport.Sockets/Internal/IOQueue.cs index 6a3e60d1ac..49b6b3e668 100644 --- a/src/Kestrel.Transport.Sockets/Internal/IOQueue.cs +++ b/src/Kestrel.Transport.Sockets/Internal/IOQueue.cs @@ -16,10 +16,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal private readonly ConcurrentQueue _workItems = new ConcurrentQueue(); private bool _doingWork; - public override void Schedule(Action action, object state) + public override void Schedule(Action action, T state) { var work = new Work { + CallbackAdapter = (c, s) => ((Action)c)((T)s), Callback = action, State = state }; @@ -42,7 +43,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal { while (_workItems.TryDequeue(out Work item)) { - item.Callback(item.State); + item.CallbackAdapter(item.Callback, item.State); } lock (_workSync) @@ -58,7 +59,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal private struct Work { - public Action Callback; + public Action CallbackAdapter; + public object Callback; public object State; } } diff --git a/src/Kestrel.Transport.Sockets/Internal/SocketAwaitable.cs b/src/Kestrel.Transport.Sockets/Internal/SocketAwaitable.cs index 1da07c9375..f266033a36 100644 --- a/src/Kestrel.Transport.Sockets/Internal/SocketAwaitable.cs +++ b/src/Kestrel.Transport.Sockets/Internal/SocketAwaitable.cs @@ -64,7 +64,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal if (continuation != null) { - _ioScheduler.Schedule(state => ((Action)state)(), continuation); + _ioScheduler.Schedule(c => c(), continuation); } } } From ddd0b4c260f1152c663103ada4a11db22f1cdbad Mon Sep 17 00:00:00 2001 From: David Fowler Date: Tue, 13 Mar 2018 01:43:49 -0700 Subject: [PATCH 1562/1662] Clean up protocol abstractions (#2381) - This change aims to clean up the feature interfaces used by kestrel and exposed by protocol absractions. It splits out the IConnectionTransportFeature into smaller features that may or may not be implemented on the connection. - Added all of the features from Socket.Abstractions in an attempt to make it go away completely. As a result the helper methods and extensions have all been added here. - Change IConnectionHandler to take TransportConnection. This cleans up the interface and makes it more explicit what features are required by Kestrel --- .../Internal/ConnectionHandler.cs | 18 ++-- .../Internal/HttpConnectionMiddleware.cs | 7 +- .../Internal/IConnectionHandler.cs | 2 +- .../Internal/TransportConnection.Features.cs | 96 +++++++++++++++++-- .../Internal/TransportConnection.cs | 3 + .../ConnectionBuilderExtensions.cs | 34 +++++++ src/Protocols.Abstractions/DuplexPipe.cs | 4 - .../Features/ConnectionBuilder.cs | 44 +++++++++ .../Features/IApplicationTransportFeature.cs | 14 +++ .../Features/IConnectionHeartbeatFeature.cs | 12 +++ .../Features/IConnectionIdFeature.cs | 5 +- .../IConnectionInherentKeepAliveFeature.cs | 24 +++++ .../Features/IConnectionMetadataFeature.cs | 13 +++ .../Features/IConnectionTransportFeature.cs | 13 +-- .../Features/IConnectionUserFeature.cs | 9 ++ .../Features/IMemoryPoolFeature.cs | 14 +++ .../Features/ITransportSchedulerFeature.cs | 16 ++++ .../ConnectionHandlerTests.cs | 19 +--- .../TestHelpers/MockConnectionHandler.cs | 14 +-- 19 files changed, 299 insertions(+), 62 deletions(-) create mode 100644 src/Protocols.Abstractions/ConnectionBuilderExtensions.cs create mode 100644 src/Protocols.Abstractions/Features/ConnectionBuilder.cs create mode 100644 src/Protocols.Abstractions/Features/IApplicationTransportFeature.cs create mode 100644 src/Protocols.Abstractions/Features/IConnectionHeartbeatFeature.cs create mode 100644 src/Protocols.Abstractions/Features/IConnectionInherentKeepAliveFeature.cs create mode 100644 src/Protocols.Abstractions/Features/IConnectionMetadataFeature.cs create mode 100644 src/Protocols.Abstractions/Features/IConnectionUserFeature.cs create mode 100644 src/Protocols.Abstractions/Features/IMemoryPoolFeature.cs create mode 100644 src/Protocols.Abstractions/Features/ITransportSchedulerFeature.cs diff --git a/src/Kestrel.Core/Internal/ConnectionHandler.cs b/src/Kestrel.Core/Internal/ConnectionHandler.cs index f989a61c18..db02fcd6ff 100644 --- a/src/Kestrel.Core/Internal/ConnectionHandler.cs +++ b/src/Kestrel.Core/Internal/ConnectionHandler.cs @@ -28,29 +28,25 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal private IKestrelTrace Log => _serviceContext.Log; - public void OnConnection(IFeatureCollection features) + public void OnConnection(TransportConnection connection) { - var connectionContext = new DefaultConnectionContext(features); - - var transportFeature = connectionContext.Features.Get(); - // REVIEW: Unfortunately, we still need to use the service context to create the pipes since the settings // for the scheduler and limits are specified here - var inputOptions = GetInputPipeOptions(_serviceContext, transportFeature.MemoryPool, transportFeature.InputWriterScheduler); - var outputOptions = GetOutputPipeOptions(_serviceContext, transportFeature.MemoryPool, transportFeature.OutputReaderScheduler); + var inputOptions = GetInputPipeOptions(_serviceContext, connection.MemoryPool, connection.InputWriterScheduler); + var outputOptions = GetOutputPipeOptions(_serviceContext, connection.MemoryPool, connection.OutputReaderScheduler); var pair = DuplexPipe.CreateConnectionPair(inputOptions, outputOptions); // Set the transport and connection id - connectionContext.ConnectionId = CorrelationIdGenerator.GetNextId(); - connectionContext.Transport = pair.Transport; + connection.ConnectionId = CorrelationIdGenerator.GetNextId(); + connection.Transport = pair.Transport; // This *must* be set before returning from OnConnection - transportFeature.Application = pair.Application; + connection.Application = pair.Application; // REVIEW: This task should be tracked by the server for graceful shutdown // Today it's handled specifically for http but not for aribitrary middleware - _ = Execute(connectionContext); + _ = Execute(new DefaultConnectionContext(connection)); } private async Task Execute(ConnectionContext connectionContext) diff --git a/src/Kestrel.Core/Internal/HttpConnectionMiddleware.cs b/src/Kestrel.Core/Internal/HttpConnectionMiddleware.cs index 3e25712899..3be295627d 100644 --- a/src/Kestrel.Core/Internal/HttpConnectionMiddleware.cs +++ b/src/Kestrel.Core/Internal/HttpConnectionMiddleware.cs @@ -33,7 +33,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal { // We need the transport feature so that we can cancel the output reader that the transport is using // This is a bit of a hack but it preserves the existing semantics - var transportFeature = connectionContext.Features.Get(); + var applicationFeature = connectionContext.Features.Get(); + var memoryPoolFeature = connectionContext.Features.Get(); var httpConnectionId = Interlocked.Increment(ref _lastHttpConnectionId); @@ -44,10 +45,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal Protocols = _protocols, ServiceContext = _serviceContext, ConnectionFeatures = connectionContext.Features, - MemoryPool = transportFeature.MemoryPool, + MemoryPool = memoryPoolFeature.MemoryPool, ConnectionAdapters = _connectionAdapters, Transport = connectionContext.Transport, - Application = transportFeature.Application + Application = applicationFeature.Application }; var connectionFeature = connectionContext.Features.Get(); diff --git a/src/Kestrel.Transport.Abstractions/Internal/IConnectionHandler.cs b/src/Kestrel.Transport.Abstractions/Internal/IConnectionHandler.cs index 9ae3f89c3f..eec71ff61c 100644 --- a/src/Kestrel.Transport.Abstractions/Internal/IConnectionHandler.cs +++ b/src/Kestrel.Transport.Abstractions/Internal/IConnectionHandler.cs @@ -7,6 +7,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal { public interface IConnectionHandler { - void OnConnection(IFeatureCollection features); + void OnConnection(TransportConnection connection); } } diff --git a/src/Kestrel.Transport.Abstractions/Internal/TransportConnection.Features.cs b/src/Kestrel.Transport.Abstractions/Internal/TransportConnection.Features.cs index 4259da0128..275c80ba95 100644 --- a/src/Kestrel.Transport.Abstractions/Internal/TransportConnection.Features.cs +++ b/src/Kestrel.Transport.Abstractions/Internal/TransportConnection.Features.cs @@ -12,15 +12,24 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal public partial class TransportConnection : IFeatureCollection, IHttpConnectionFeature, IConnectionIdFeature, - IConnectionTransportFeature + IConnectionTransportFeature, + IMemoryPoolFeature, + IApplicationTransportFeature, + ITransportSchedulerFeature { private static readonly Type IHttpConnectionFeatureType = typeof(IHttpConnectionFeature); private static readonly Type IConnectionIdFeatureType = typeof(IConnectionIdFeature); private static readonly Type IConnectionTransportFeatureType = typeof(IConnectionTransportFeature); + private static readonly Type IMemoryPoolFeatureType = typeof(IMemoryPoolFeature); + private static readonly Type IApplicationTransportFeatureType = typeof(IApplicationTransportFeature); + private static readonly Type ITransportSchedulerFeatureType = typeof(ITransportSchedulerFeature); private object _currentIHttpConnectionFeature; private object _currentIConnectionIdFeature; private object _currentIConnectionTransportFeature; + private object _currentIMemoryPoolFeature; + private object _currentIApplicationTransportFeature; + private object _currentITransportSchedulerFeature; private int _featureRevision; @@ -95,7 +104,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal set => LocalPort = value; } - MemoryPool IConnectionTransportFeature.MemoryPool => MemoryPool; + MemoryPool IMemoryPoolFeature.MemoryPool => MemoryPool; IDuplexPipe IConnectionTransportFeature.Transport { @@ -103,12 +112,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal set => Transport = value; } - IDuplexPipe IConnectionTransportFeature.Application + IDuplexPipe IApplicationTransportFeature.Application { get => Application; set => Application = value; } + PipeScheduler ITransportSchedulerFeature.InputWriterScheduler => InputWriterScheduler; + PipeScheduler ITransportSchedulerFeature.OutputReaderScheduler => OutputReaderScheduler; + object IFeatureCollection.this[Type key] { get @@ -128,6 +140,21 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal return _currentIConnectionTransportFeature; } + if (key == IMemoryPoolFeatureType) + { + return _currentIMemoryPoolFeature; + } + + if (key == IApplicationTransportFeatureType) + { + return _currentIApplicationTransportFeature; + } + + if (key == ITransportSchedulerFeatureType) + { + return _currentITransportSchedulerFeature; + } + if (MaybeExtra != null) { return ExtraFeatureGet(key); @@ -151,6 +178,18 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal { _currentIConnectionTransportFeature = value; } + else if (key == IMemoryPoolFeatureType) + { + _currentIMemoryPoolFeature = value; + } + else if (key == IApplicationTransportFeatureType) + { + _currentIApplicationTransportFeature = value; + } + else if (key == ITransportSchedulerFeatureType) + { + _currentITransportSchedulerFeature = value; + } else { ExtraFeatureSet(key, value); @@ -160,18 +199,30 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal TFeature IFeatureCollection.Get() { - if (typeof(TFeature) == typeof(IHttpConnectionFeature)) + if (typeof(TFeature) == IHttpConnectionFeatureType) { return (TFeature)_currentIHttpConnectionFeature; } - else if (typeof(TFeature) == typeof(IConnectionIdFeature)) + else if (typeof(TFeature) == IConnectionIdFeatureType) { return (TFeature)_currentIConnectionIdFeature; } - else if (typeof(TFeature) == typeof(IConnectionTransportFeature)) + else if (typeof(TFeature) == IConnectionTransportFeatureType) { return (TFeature)_currentIConnectionTransportFeature; } + else if (typeof(TFeature) == IMemoryPoolFeatureType) + { + return (TFeature)_currentIMemoryPoolFeature; + } + else if (typeof(TFeature) == IApplicationTransportFeatureType) + { + return (TFeature)_currentIApplicationTransportFeature; + } + else if (typeof(TFeature) == ITransportSchedulerFeatureType) + { + return (TFeature)_currentITransportSchedulerFeature; + } else if (MaybeExtra != null) { return (TFeature)ExtraFeatureGet(typeof(TFeature)); @@ -184,18 +235,30 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal { _featureRevision++; - if (typeof(TFeature) == typeof(IHttpConnectionFeature)) + if (typeof(TFeature) == IHttpConnectionFeatureType) { _currentIHttpConnectionFeature = instance; } - else if (typeof(TFeature) == typeof(IConnectionIdFeature)) + else if (typeof(TFeature) == IConnectionIdFeatureType) { _currentIConnectionIdFeature = instance; } - else if (typeof(TFeature) == typeof(IConnectionTransportFeature)) + else if (typeof(TFeature) == IConnectionTransportFeatureType) { _currentIConnectionTransportFeature = instance; } + else if (typeof(TFeature) == IMemoryPoolFeatureType) + { + _currentIMemoryPoolFeature = instance; + } + else if (typeof(TFeature) == IApplicationTransportFeatureType) + { + _currentIApplicationTransportFeature = instance; + } + else if (typeof(TFeature) == ITransportSchedulerFeatureType) + { + _currentITransportSchedulerFeature = instance; + } else { ExtraFeatureSet(typeof(TFeature), instance); @@ -223,6 +286,21 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal yield return new KeyValuePair(IConnectionTransportFeatureType, _currentIConnectionTransportFeature); } + if (_currentIMemoryPoolFeature != null) + { + yield return new KeyValuePair(IMemoryPoolFeatureType, _currentIMemoryPoolFeature); + } + + if (_currentIApplicationTransportFeature != null) + { + yield return new KeyValuePair(IApplicationTransportFeatureType, _currentIApplicationTransportFeature); + } + + if (_currentITransportSchedulerFeature != null) + { + yield return new KeyValuePair(ITransportSchedulerFeatureType, _currentITransportSchedulerFeature); + } + if (MaybeExtra != null) { foreach (var item in MaybeExtra) diff --git a/src/Kestrel.Transport.Abstractions/Internal/TransportConnection.cs b/src/Kestrel.Transport.Abstractions/Internal/TransportConnection.cs index 3aae48b16c..bfe7e53458 100644 --- a/src/Kestrel.Transport.Abstractions/Internal/TransportConnection.cs +++ b/src/Kestrel.Transport.Abstractions/Internal/TransportConnection.cs @@ -12,6 +12,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal _currentIConnectionIdFeature = this; _currentIConnectionTransportFeature = this; _currentIHttpConnectionFeature = this; + _currentIApplicationTransportFeature = this; + _currentIMemoryPoolFeature = this; + _currentITransportSchedulerFeature = this; } public IPAddress RemoteAddress { get; set; } diff --git a/src/Protocols.Abstractions/ConnectionBuilderExtensions.cs b/src/Protocols.Abstractions/ConnectionBuilderExtensions.cs new file mode 100644 index 0000000000..9db3e4c468 --- /dev/null +++ b/src/Protocols.Abstractions/ConnectionBuilderExtensions.cs @@ -0,0 +1,34 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Threading.Tasks; + +namespace Microsoft.AspNetCore.Protocols +{ + public static class ConnectionBuilderExtensions + { + public static IConnectionBuilder Use(this IConnectionBuilder connectionBuilder, Func, Task> middleware) + { + return connectionBuilder.Use(next => + { + return context => + { + Func simpleNext = () => next(context); + return middleware(context, simpleNext); + }; + }); + } + + public static IConnectionBuilder Run(this IConnectionBuilder connectionBuilder, Func middleware) + { + return connectionBuilder.Use(next => + { + return context => + { + return middleware(context); + }; + }); + } + } +} \ No newline at end of file diff --git a/src/Protocols.Abstractions/DuplexPipe.cs b/src/Protocols.Abstractions/DuplexPipe.cs index adf8b497c6..e7a6ad1710 100644 --- a/src/Protocols.Abstractions/DuplexPipe.cs +++ b/src/Protocols.Abstractions/DuplexPipe.cs @@ -14,10 +14,6 @@ namespace System.IO.Pipelines public PipeWriter Output { get; } - public void Dispose() - { - } - public static DuplexPipePair CreateConnectionPair(PipeOptions inputOptions, PipeOptions outputOptions) { var input = new Pipe(inputOptions); diff --git a/src/Protocols.Abstractions/Features/ConnectionBuilder.cs b/src/Protocols.Abstractions/Features/ConnectionBuilder.cs new file mode 100644 index 0000000000..68efce703f --- /dev/null +++ b/src/Protocols.Abstractions/Features/ConnectionBuilder.cs @@ -0,0 +1,44 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Microsoft.AspNetCore.Protocols +{ + public class ConnectionBuilder : IConnectionBuilder + { + private readonly IList> _components = new List>(); + + public IServiceProvider ApplicationServices { get; } + + public ConnectionBuilder(IServiceProvider applicationServices) + { + ApplicationServices = applicationServices; + } + + public IConnectionBuilder Use(Func middleware) + { + _components.Add(middleware); + return this; + } + + public ConnectionDelegate Build() + { + ConnectionDelegate app = features => + { + return Task.CompletedTask; + }; + + foreach (var component in _components.Reverse()) + { + app = component(app); + } + + return app; + } + } +} \ No newline at end of file diff --git a/src/Protocols.Abstractions/Features/IApplicationTransportFeature.cs b/src/Protocols.Abstractions/Features/IApplicationTransportFeature.cs new file mode 100644 index 0000000000..10f22d135e --- /dev/null +++ b/src/Protocols.Abstractions/Features/IApplicationTransportFeature.cs @@ -0,0 +1,14 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System.Buffers; +using System.IO.Pipelines; +using System.Threading; + +namespace Microsoft.AspNetCore.Protocols.Features +{ + public interface IApplicationTransportFeature + { + IDuplexPipe Application { get; set; } + } +} diff --git a/src/Protocols.Abstractions/Features/IConnectionHeartbeatFeature.cs b/src/Protocols.Abstractions/Features/IConnectionHeartbeatFeature.cs new file mode 100644 index 0000000000..9770143a34 --- /dev/null +++ b/src/Protocols.Abstractions/Features/IConnectionHeartbeatFeature.cs @@ -0,0 +1,12 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; + +namespace Microsoft.AspNetCore.Protocols.Features +{ + public interface IConnectionHeartbeatFeature + { + void OnHeartbeat(Action action, object state); + } +} \ No newline at end of file diff --git a/src/Protocols.Abstractions/Features/IConnectionIdFeature.cs b/src/Protocols.Abstractions/Features/IConnectionIdFeature.cs index ab1c09e3db..4c6cd81e77 100644 --- a/src/Protocols.Abstractions/Features/IConnectionIdFeature.cs +++ b/src/Protocols.Abstractions/Features/IConnectionIdFeature.cs @@ -1,4 +1,7 @@ -namespace Microsoft.AspNetCore.Protocols.Features +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +namespace Microsoft.AspNetCore.Protocols.Features { public interface IConnectionIdFeature { diff --git a/src/Protocols.Abstractions/Features/IConnectionInherentKeepAliveFeature.cs b/src/Protocols.Abstractions/Features/IConnectionInherentKeepAliveFeature.cs new file mode 100644 index 0000000000..cc3a211e46 --- /dev/null +++ b/src/Protocols.Abstractions/Features/IConnectionInherentKeepAliveFeature.cs @@ -0,0 +1,24 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Collections.Generic; +using System.Text; + +namespace Microsoft.AspNetCore.Protocols.Features +{ + /// + /// Indicates if the connection transport has an "inherent keep-alive", which means that the transport will automatically + /// inform the client that it is still present. + /// + /// + /// The most common example of this feature is the Long Polling HTTP transport, which must (due to HTTP limitations) terminate + /// each poll within a particular interval and return a signal indicating "the server is still here, but there is no data yet". + /// This feature allows applications to add keep-alive functionality, but limit it only to transports that don't have some kind + /// of inherent keep-alive. + /// + public interface IConnectionInherentKeepAliveFeature + { + TimeSpan KeepAliveInterval { get; } + } +} \ No newline at end of file diff --git a/src/Protocols.Abstractions/Features/IConnectionMetadataFeature.cs b/src/Protocols.Abstractions/Features/IConnectionMetadataFeature.cs new file mode 100644 index 0000000000..b2e0f67789 --- /dev/null +++ b/src/Protocols.Abstractions/Features/IConnectionMetadataFeature.cs @@ -0,0 +1,13 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Collections.Generic; + +namespace Microsoft.AspNetCore.Protocols.Features +{ + public interface IConnectionMetadataFeature + { + IDictionary Metadata { get; set; } + } +} \ No newline at end of file diff --git a/src/Protocols.Abstractions/Features/IConnectionTransportFeature.cs b/src/Protocols.Abstractions/Features/IConnectionTransportFeature.cs index 1a5500b692..bf7067be23 100644 --- a/src/Protocols.Abstractions/Features/IConnectionTransportFeature.cs +++ b/src/Protocols.Abstractions/Features/IConnectionTransportFeature.cs @@ -1,4 +1,7 @@ -using System.Buffers; +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System.Buffers; using System.IO.Pipelines; using System.Threading; @@ -6,14 +9,6 @@ namespace Microsoft.AspNetCore.Protocols.Features { public interface IConnectionTransportFeature { - MemoryPool MemoryPool { get; } - IDuplexPipe Transport { get; set; } - - IDuplexPipe Application { get; set; } - - PipeScheduler InputWriterScheduler { get; } - - PipeScheduler OutputReaderScheduler { get; } } } diff --git a/src/Protocols.Abstractions/Features/IConnectionUserFeature.cs b/src/Protocols.Abstractions/Features/IConnectionUserFeature.cs new file mode 100644 index 0000000000..5daf9fd232 --- /dev/null +++ b/src/Protocols.Abstractions/Features/IConnectionUserFeature.cs @@ -0,0 +1,9 @@ +using System.Security.Claims; + +namespace Microsoft.AspNetCore.Protocols.Features +{ + public interface IConnectionUserFeature + { + ClaimsPrincipal User { get; set; } + } +} \ No newline at end of file diff --git a/src/Protocols.Abstractions/Features/IMemoryPoolFeature.cs b/src/Protocols.Abstractions/Features/IMemoryPoolFeature.cs new file mode 100644 index 0000000000..128b9ae3c9 --- /dev/null +++ b/src/Protocols.Abstractions/Features/IMemoryPoolFeature.cs @@ -0,0 +1,14 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System.Buffers; +using System.IO.Pipelines; +using System.Threading; + +namespace Microsoft.AspNetCore.Protocols.Features +{ + public interface IMemoryPoolFeature + { + MemoryPool MemoryPool { get; } + } +} diff --git a/src/Protocols.Abstractions/Features/ITransportSchedulerFeature.cs b/src/Protocols.Abstractions/Features/ITransportSchedulerFeature.cs new file mode 100644 index 0000000000..05c8b8d605 --- /dev/null +++ b/src/Protocols.Abstractions/Features/ITransportSchedulerFeature.cs @@ -0,0 +1,16 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System.Buffers; +using System.IO.Pipelines; +using System.Threading; + +namespace Microsoft.AspNetCore.Protocols.Features +{ + public interface ITransportSchedulerFeature + { + PipeScheduler InputWriterScheduler { get; } + + PipeScheduler OutputReaderScheduler { get; } + } +} diff --git a/test/Kestrel.Core.Tests/ConnectionHandlerTests.cs b/test/Kestrel.Core.Tests/ConnectionHandlerTests.cs index ee1cffefdc..27128fe558 100644 --- a/test/Kestrel.Core.Tests/ConnectionHandlerTests.cs +++ b/test/Kestrel.Core.Tests/ConnectionHandlerTests.cs @@ -45,24 +45,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests Assert.True(((TestKestrelTrace)serviceContext.Log).Logger.Scopes.IsEmpty); } - private class TestConnection : FeatureCollection, IConnectionIdFeature, IConnectionTransportFeature + private class TestConnection : TransportConnection { - public TestConnection() - { - Set(this); - Set(this); - } + public override MemoryPool MemoryPool { get; } = KestrelMemoryPool.Create(); - public MemoryPool MemoryPool { get; } = KestrelMemoryPool.Create(); + public override PipeScheduler InputWriterScheduler => PipeScheduler.ThreadPool; - public IDuplexPipe Transport { get; set; } - public IDuplexPipe Application { get; set; } - - public PipeScheduler InputWriterScheduler => PipeScheduler.ThreadPool; - - public PipeScheduler OutputReaderScheduler => PipeScheduler.ThreadPool; - - public string ConnectionId { get; set; } + public override PipeScheduler OutputReaderScheduler => PipeScheduler.ThreadPool; } } } diff --git a/test/Kestrel.Transport.Libuv.Tests/TestHelpers/MockConnectionHandler.cs b/test/Kestrel.Transport.Libuv.Tests/TestHelpers/MockConnectionHandler.cs index daf6cdd27c..edae9162f5 100644 --- a/test/Kestrel.Transport.Libuv.Tests/TestHelpers/MockConnectionHandler.cs +++ b/test/Kestrel.Transport.Libuv.Tests/TestHelpers/MockConnectionHandler.cs @@ -16,17 +16,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests.TestHelpers public Func, PipeOptions> InputOptions { get; set; } = pool => new PipeOptions(pool, readerScheduler: PipeScheduler.Inline, writerScheduler: PipeScheduler.Inline, useSynchronizationContext: false); public Func, PipeOptions> OutputOptions { get; set; } = pool => new PipeOptions(pool, readerScheduler: PipeScheduler.Inline, writerScheduler: PipeScheduler.Inline, useSynchronizationContext: false); - public void OnConnection(IFeatureCollection features) + public void OnConnection(TransportConnection connection) { - var connectionContext = new DefaultConnectionContext(features); + Input = new Pipe(InputOptions(connection.MemoryPool)); + Output = new Pipe(OutputOptions(connection.MemoryPool)); - var feature = connectionContext.Features.Get(); - - Input = new Pipe(InputOptions(feature.MemoryPool)); - Output = new Pipe(OutputOptions(feature.MemoryPool)); - - connectionContext.Transport = new DuplexPipe(Input.Reader, Output.Writer); - feature.Application = new DuplexPipe(Output.Reader, Input.Writer); + connection.Transport = new DuplexPipe(Input.Reader, Output.Writer); + connection.Application = new DuplexPipe(Output.Reader, Input.Writer); } public Pipe Input { get; private set; } From fa3229b48940160532fbd9153631b4ca0ba9613d Mon Sep 17 00:00:00 2001 From: David Fowler Date: Tue, 13 Mar 2018 02:04:42 -0700 Subject: [PATCH 1563/1662] Revert "Clean up protocol abstractions (#2381)" (#2382) This reverts commit ddd0b4c260f1152c663103ada4a11db22f1cdbad. --- .../Internal/ConnectionHandler.cs | 18 ++-- .../Internal/HttpConnectionMiddleware.cs | 7 +- .../Internal/IConnectionHandler.cs | 2 +- .../Internal/TransportConnection.Features.cs | 96 ++----------------- .../Internal/TransportConnection.cs | 3 - .../ConnectionBuilderExtensions.cs | 34 ------- src/Protocols.Abstractions/DuplexPipe.cs | 4 + .../Features/ConnectionBuilder.cs | 44 --------- .../Features/IApplicationTransportFeature.cs | 14 --- .../Features/IConnectionHeartbeatFeature.cs | 12 --- .../Features/IConnectionIdFeature.cs | 5 +- .../IConnectionInherentKeepAliveFeature.cs | 24 ----- .../Features/IConnectionMetadataFeature.cs | 13 --- .../Features/IConnectionTransportFeature.cs | 13 ++- .../Features/IConnectionUserFeature.cs | 9 -- .../Features/IMemoryPoolFeature.cs | 14 --- .../Features/ITransportSchedulerFeature.cs | 16 ---- .../ConnectionHandlerTests.cs | 19 +++- .../TestHelpers/MockConnectionHandler.cs | 14 ++- 19 files changed, 62 insertions(+), 299 deletions(-) delete mode 100644 src/Protocols.Abstractions/ConnectionBuilderExtensions.cs delete mode 100644 src/Protocols.Abstractions/Features/ConnectionBuilder.cs delete mode 100644 src/Protocols.Abstractions/Features/IApplicationTransportFeature.cs delete mode 100644 src/Protocols.Abstractions/Features/IConnectionHeartbeatFeature.cs delete mode 100644 src/Protocols.Abstractions/Features/IConnectionInherentKeepAliveFeature.cs delete mode 100644 src/Protocols.Abstractions/Features/IConnectionMetadataFeature.cs delete mode 100644 src/Protocols.Abstractions/Features/IConnectionUserFeature.cs delete mode 100644 src/Protocols.Abstractions/Features/IMemoryPoolFeature.cs delete mode 100644 src/Protocols.Abstractions/Features/ITransportSchedulerFeature.cs diff --git a/src/Kestrel.Core/Internal/ConnectionHandler.cs b/src/Kestrel.Core/Internal/ConnectionHandler.cs index db02fcd6ff..f989a61c18 100644 --- a/src/Kestrel.Core/Internal/ConnectionHandler.cs +++ b/src/Kestrel.Core/Internal/ConnectionHandler.cs @@ -28,25 +28,29 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal private IKestrelTrace Log => _serviceContext.Log; - public void OnConnection(TransportConnection connection) + public void OnConnection(IFeatureCollection features) { + var connectionContext = new DefaultConnectionContext(features); + + var transportFeature = connectionContext.Features.Get(); + // REVIEW: Unfortunately, we still need to use the service context to create the pipes since the settings // for the scheduler and limits are specified here - var inputOptions = GetInputPipeOptions(_serviceContext, connection.MemoryPool, connection.InputWriterScheduler); - var outputOptions = GetOutputPipeOptions(_serviceContext, connection.MemoryPool, connection.OutputReaderScheduler); + var inputOptions = GetInputPipeOptions(_serviceContext, transportFeature.MemoryPool, transportFeature.InputWriterScheduler); + var outputOptions = GetOutputPipeOptions(_serviceContext, transportFeature.MemoryPool, transportFeature.OutputReaderScheduler); var pair = DuplexPipe.CreateConnectionPair(inputOptions, outputOptions); // Set the transport and connection id - connection.ConnectionId = CorrelationIdGenerator.GetNextId(); - connection.Transport = pair.Transport; + connectionContext.ConnectionId = CorrelationIdGenerator.GetNextId(); + connectionContext.Transport = pair.Transport; // This *must* be set before returning from OnConnection - connection.Application = pair.Application; + transportFeature.Application = pair.Application; // REVIEW: This task should be tracked by the server for graceful shutdown // Today it's handled specifically for http but not for aribitrary middleware - _ = Execute(new DefaultConnectionContext(connection)); + _ = Execute(connectionContext); } private async Task Execute(ConnectionContext connectionContext) diff --git a/src/Kestrel.Core/Internal/HttpConnectionMiddleware.cs b/src/Kestrel.Core/Internal/HttpConnectionMiddleware.cs index 3be295627d..3e25712899 100644 --- a/src/Kestrel.Core/Internal/HttpConnectionMiddleware.cs +++ b/src/Kestrel.Core/Internal/HttpConnectionMiddleware.cs @@ -33,8 +33,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal { // We need the transport feature so that we can cancel the output reader that the transport is using // This is a bit of a hack but it preserves the existing semantics - var applicationFeature = connectionContext.Features.Get(); - var memoryPoolFeature = connectionContext.Features.Get(); + var transportFeature = connectionContext.Features.Get(); var httpConnectionId = Interlocked.Increment(ref _lastHttpConnectionId); @@ -45,10 +44,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal Protocols = _protocols, ServiceContext = _serviceContext, ConnectionFeatures = connectionContext.Features, - MemoryPool = memoryPoolFeature.MemoryPool, + MemoryPool = transportFeature.MemoryPool, ConnectionAdapters = _connectionAdapters, Transport = connectionContext.Transport, - Application = applicationFeature.Application + Application = transportFeature.Application }; var connectionFeature = connectionContext.Features.Get(); diff --git a/src/Kestrel.Transport.Abstractions/Internal/IConnectionHandler.cs b/src/Kestrel.Transport.Abstractions/Internal/IConnectionHandler.cs index eec71ff61c..9ae3f89c3f 100644 --- a/src/Kestrel.Transport.Abstractions/Internal/IConnectionHandler.cs +++ b/src/Kestrel.Transport.Abstractions/Internal/IConnectionHandler.cs @@ -7,6 +7,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal { public interface IConnectionHandler { - void OnConnection(TransportConnection connection); + void OnConnection(IFeatureCollection features); } } diff --git a/src/Kestrel.Transport.Abstractions/Internal/TransportConnection.Features.cs b/src/Kestrel.Transport.Abstractions/Internal/TransportConnection.Features.cs index 275c80ba95..4259da0128 100644 --- a/src/Kestrel.Transport.Abstractions/Internal/TransportConnection.Features.cs +++ b/src/Kestrel.Transport.Abstractions/Internal/TransportConnection.Features.cs @@ -12,24 +12,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal public partial class TransportConnection : IFeatureCollection, IHttpConnectionFeature, IConnectionIdFeature, - IConnectionTransportFeature, - IMemoryPoolFeature, - IApplicationTransportFeature, - ITransportSchedulerFeature + IConnectionTransportFeature { private static readonly Type IHttpConnectionFeatureType = typeof(IHttpConnectionFeature); private static readonly Type IConnectionIdFeatureType = typeof(IConnectionIdFeature); private static readonly Type IConnectionTransportFeatureType = typeof(IConnectionTransportFeature); - private static readonly Type IMemoryPoolFeatureType = typeof(IMemoryPoolFeature); - private static readonly Type IApplicationTransportFeatureType = typeof(IApplicationTransportFeature); - private static readonly Type ITransportSchedulerFeatureType = typeof(ITransportSchedulerFeature); private object _currentIHttpConnectionFeature; private object _currentIConnectionIdFeature; private object _currentIConnectionTransportFeature; - private object _currentIMemoryPoolFeature; - private object _currentIApplicationTransportFeature; - private object _currentITransportSchedulerFeature; private int _featureRevision; @@ -104,7 +95,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal set => LocalPort = value; } - MemoryPool IMemoryPoolFeature.MemoryPool => MemoryPool; + MemoryPool IConnectionTransportFeature.MemoryPool => MemoryPool; IDuplexPipe IConnectionTransportFeature.Transport { @@ -112,15 +103,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal set => Transport = value; } - IDuplexPipe IApplicationTransportFeature.Application + IDuplexPipe IConnectionTransportFeature.Application { get => Application; set => Application = value; } - PipeScheduler ITransportSchedulerFeature.InputWriterScheduler => InputWriterScheduler; - PipeScheduler ITransportSchedulerFeature.OutputReaderScheduler => OutputReaderScheduler; - object IFeatureCollection.this[Type key] { get @@ -140,21 +128,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal return _currentIConnectionTransportFeature; } - if (key == IMemoryPoolFeatureType) - { - return _currentIMemoryPoolFeature; - } - - if (key == IApplicationTransportFeatureType) - { - return _currentIApplicationTransportFeature; - } - - if (key == ITransportSchedulerFeatureType) - { - return _currentITransportSchedulerFeature; - } - if (MaybeExtra != null) { return ExtraFeatureGet(key); @@ -178,18 +151,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal { _currentIConnectionTransportFeature = value; } - else if (key == IMemoryPoolFeatureType) - { - _currentIMemoryPoolFeature = value; - } - else if (key == IApplicationTransportFeatureType) - { - _currentIApplicationTransportFeature = value; - } - else if (key == ITransportSchedulerFeatureType) - { - _currentITransportSchedulerFeature = value; - } else { ExtraFeatureSet(key, value); @@ -199,30 +160,18 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal TFeature IFeatureCollection.Get() { - if (typeof(TFeature) == IHttpConnectionFeatureType) + if (typeof(TFeature) == typeof(IHttpConnectionFeature)) { return (TFeature)_currentIHttpConnectionFeature; } - else if (typeof(TFeature) == IConnectionIdFeatureType) + else if (typeof(TFeature) == typeof(IConnectionIdFeature)) { return (TFeature)_currentIConnectionIdFeature; } - else if (typeof(TFeature) == IConnectionTransportFeatureType) + else if (typeof(TFeature) == typeof(IConnectionTransportFeature)) { return (TFeature)_currentIConnectionTransportFeature; } - else if (typeof(TFeature) == IMemoryPoolFeatureType) - { - return (TFeature)_currentIMemoryPoolFeature; - } - else if (typeof(TFeature) == IApplicationTransportFeatureType) - { - return (TFeature)_currentIApplicationTransportFeature; - } - else if (typeof(TFeature) == ITransportSchedulerFeatureType) - { - return (TFeature)_currentITransportSchedulerFeature; - } else if (MaybeExtra != null) { return (TFeature)ExtraFeatureGet(typeof(TFeature)); @@ -235,30 +184,18 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal { _featureRevision++; - if (typeof(TFeature) == IHttpConnectionFeatureType) + if (typeof(TFeature) == typeof(IHttpConnectionFeature)) { _currentIHttpConnectionFeature = instance; } - else if (typeof(TFeature) == IConnectionIdFeatureType) + else if (typeof(TFeature) == typeof(IConnectionIdFeature)) { _currentIConnectionIdFeature = instance; } - else if (typeof(TFeature) == IConnectionTransportFeatureType) + else if (typeof(TFeature) == typeof(IConnectionTransportFeature)) { _currentIConnectionTransportFeature = instance; } - else if (typeof(TFeature) == IMemoryPoolFeatureType) - { - _currentIMemoryPoolFeature = instance; - } - else if (typeof(TFeature) == IApplicationTransportFeatureType) - { - _currentIApplicationTransportFeature = instance; - } - else if (typeof(TFeature) == ITransportSchedulerFeatureType) - { - _currentITransportSchedulerFeature = instance; - } else { ExtraFeatureSet(typeof(TFeature), instance); @@ -286,21 +223,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal yield return new KeyValuePair(IConnectionTransportFeatureType, _currentIConnectionTransportFeature); } - if (_currentIMemoryPoolFeature != null) - { - yield return new KeyValuePair(IMemoryPoolFeatureType, _currentIMemoryPoolFeature); - } - - if (_currentIApplicationTransportFeature != null) - { - yield return new KeyValuePair(IApplicationTransportFeatureType, _currentIApplicationTransportFeature); - } - - if (_currentITransportSchedulerFeature != null) - { - yield return new KeyValuePair(ITransportSchedulerFeatureType, _currentITransportSchedulerFeature); - } - if (MaybeExtra != null) { foreach (var item in MaybeExtra) diff --git a/src/Kestrel.Transport.Abstractions/Internal/TransportConnection.cs b/src/Kestrel.Transport.Abstractions/Internal/TransportConnection.cs index bfe7e53458..3aae48b16c 100644 --- a/src/Kestrel.Transport.Abstractions/Internal/TransportConnection.cs +++ b/src/Kestrel.Transport.Abstractions/Internal/TransportConnection.cs @@ -12,9 +12,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal _currentIConnectionIdFeature = this; _currentIConnectionTransportFeature = this; _currentIHttpConnectionFeature = this; - _currentIApplicationTransportFeature = this; - _currentIMemoryPoolFeature = this; - _currentITransportSchedulerFeature = this; } public IPAddress RemoteAddress { get; set; } diff --git a/src/Protocols.Abstractions/ConnectionBuilderExtensions.cs b/src/Protocols.Abstractions/ConnectionBuilderExtensions.cs deleted file mode 100644 index 9db3e4c468..0000000000 --- a/src/Protocols.Abstractions/ConnectionBuilderExtensions.cs +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using System.Threading.Tasks; - -namespace Microsoft.AspNetCore.Protocols -{ - public static class ConnectionBuilderExtensions - { - public static IConnectionBuilder Use(this IConnectionBuilder connectionBuilder, Func, Task> middleware) - { - return connectionBuilder.Use(next => - { - return context => - { - Func simpleNext = () => next(context); - return middleware(context, simpleNext); - }; - }); - } - - public static IConnectionBuilder Run(this IConnectionBuilder connectionBuilder, Func middleware) - { - return connectionBuilder.Use(next => - { - return context => - { - return middleware(context); - }; - }); - } - } -} \ No newline at end of file diff --git a/src/Protocols.Abstractions/DuplexPipe.cs b/src/Protocols.Abstractions/DuplexPipe.cs index e7a6ad1710..adf8b497c6 100644 --- a/src/Protocols.Abstractions/DuplexPipe.cs +++ b/src/Protocols.Abstractions/DuplexPipe.cs @@ -14,6 +14,10 @@ namespace System.IO.Pipelines public PipeWriter Output { get; } + public void Dispose() + { + } + public static DuplexPipePair CreateConnectionPair(PipeOptions inputOptions, PipeOptions outputOptions) { var input = new Pipe(inputOptions); diff --git a/src/Protocols.Abstractions/Features/ConnectionBuilder.cs b/src/Protocols.Abstractions/Features/ConnectionBuilder.cs deleted file mode 100644 index 68efce703f..0000000000 --- a/src/Protocols.Abstractions/Features/ConnectionBuilder.cs +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Microsoft.AspNetCore.Protocols -{ - public class ConnectionBuilder : IConnectionBuilder - { - private readonly IList> _components = new List>(); - - public IServiceProvider ApplicationServices { get; } - - public ConnectionBuilder(IServiceProvider applicationServices) - { - ApplicationServices = applicationServices; - } - - public IConnectionBuilder Use(Func middleware) - { - _components.Add(middleware); - return this; - } - - public ConnectionDelegate Build() - { - ConnectionDelegate app = features => - { - return Task.CompletedTask; - }; - - foreach (var component in _components.Reverse()) - { - app = component(app); - } - - return app; - } - } -} \ No newline at end of file diff --git a/src/Protocols.Abstractions/Features/IApplicationTransportFeature.cs b/src/Protocols.Abstractions/Features/IApplicationTransportFeature.cs deleted file mode 100644 index 10f22d135e..0000000000 --- a/src/Protocols.Abstractions/Features/IApplicationTransportFeature.cs +++ /dev/null @@ -1,14 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System.Buffers; -using System.IO.Pipelines; -using System.Threading; - -namespace Microsoft.AspNetCore.Protocols.Features -{ - public interface IApplicationTransportFeature - { - IDuplexPipe Application { get; set; } - } -} diff --git a/src/Protocols.Abstractions/Features/IConnectionHeartbeatFeature.cs b/src/Protocols.Abstractions/Features/IConnectionHeartbeatFeature.cs deleted file mode 100644 index 9770143a34..0000000000 --- a/src/Protocols.Abstractions/Features/IConnectionHeartbeatFeature.cs +++ /dev/null @@ -1,12 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; - -namespace Microsoft.AspNetCore.Protocols.Features -{ - public interface IConnectionHeartbeatFeature - { - void OnHeartbeat(Action action, object state); - } -} \ No newline at end of file diff --git a/src/Protocols.Abstractions/Features/IConnectionIdFeature.cs b/src/Protocols.Abstractions/Features/IConnectionIdFeature.cs index 4c6cd81e77..ab1c09e3db 100644 --- a/src/Protocols.Abstractions/Features/IConnectionIdFeature.cs +++ b/src/Protocols.Abstractions/Features/IConnectionIdFeature.cs @@ -1,7 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -namespace Microsoft.AspNetCore.Protocols.Features +namespace Microsoft.AspNetCore.Protocols.Features { public interface IConnectionIdFeature { diff --git a/src/Protocols.Abstractions/Features/IConnectionInherentKeepAliveFeature.cs b/src/Protocols.Abstractions/Features/IConnectionInherentKeepAliveFeature.cs deleted file mode 100644 index cc3a211e46..0000000000 --- a/src/Protocols.Abstractions/Features/IConnectionInherentKeepAliveFeature.cs +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using System.Collections.Generic; -using System.Text; - -namespace Microsoft.AspNetCore.Protocols.Features -{ - /// - /// Indicates if the connection transport has an "inherent keep-alive", which means that the transport will automatically - /// inform the client that it is still present. - /// - /// - /// The most common example of this feature is the Long Polling HTTP transport, which must (due to HTTP limitations) terminate - /// each poll within a particular interval and return a signal indicating "the server is still here, but there is no data yet". - /// This feature allows applications to add keep-alive functionality, but limit it only to transports that don't have some kind - /// of inherent keep-alive. - /// - public interface IConnectionInherentKeepAliveFeature - { - TimeSpan KeepAliveInterval { get; } - } -} \ No newline at end of file diff --git a/src/Protocols.Abstractions/Features/IConnectionMetadataFeature.cs b/src/Protocols.Abstractions/Features/IConnectionMetadataFeature.cs deleted file mode 100644 index b2e0f67789..0000000000 --- a/src/Protocols.Abstractions/Features/IConnectionMetadataFeature.cs +++ /dev/null @@ -1,13 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using System.Collections.Generic; - -namespace Microsoft.AspNetCore.Protocols.Features -{ - public interface IConnectionMetadataFeature - { - IDictionary Metadata { get; set; } - } -} \ No newline at end of file diff --git a/src/Protocols.Abstractions/Features/IConnectionTransportFeature.cs b/src/Protocols.Abstractions/Features/IConnectionTransportFeature.cs index bf7067be23..1a5500b692 100644 --- a/src/Protocols.Abstractions/Features/IConnectionTransportFeature.cs +++ b/src/Protocols.Abstractions/Features/IConnectionTransportFeature.cs @@ -1,7 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System.Buffers; +using System.Buffers; using System.IO.Pipelines; using System.Threading; @@ -9,6 +6,14 @@ namespace Microsoft.AspNetCore.Protocols.Features { public interface IConnectionTransportFeature { + MemoryPool MemoryPool { get; } + IDuplexPipe Transport { get; set; } + + IDuplexPipe Application { get; set; } + + PipeScheduler InputWriterScheduler { get; } + + PipeScheduler OutputReaderScheduler { get; } } } diff --git a/src/Protocols.Abstractions/Features/IConnectionUserFeature.cs b/src/Protocols.Abstractions/Features/IConnectionUserFeature.cs deleted file mode 100644 index 5daf9fd232..0000000000 --- a/src/Protocols.Abstractions/Features/IConnectionUserFeature.cs +++ /dev/null @@ -1,9 +0,0 @@ -using System.Security.Claims; - -namespace Microsoft.AspNetCore.Protocols.Features -{ - public interface IConnectionUserFeature - { - ClaimsPrincipal User { get; set; } - } -} \ No newline at end of file diff --git a/src/Protocols.Abstractions/Features/IMemoryPoolFeature.cs b/src/Protocols.Abstractions/Features/IMemoryPoolFeature.cs deleted file mode 100644 index 128b9ae3c9..0000000000 --- a/src/Protocols.Abstractions/Features/IMemoryPoolFeature.cs +++ /dev/null @@ -1,14 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System.Buffers; -using System.IO.Pipelines; -using System.Threading; - -namespace Microsoft.AspNetCore.Protocols.Features -{ - public interface IMemoryPoolFeature - { - MemoryPool MemoryPool { get; } - } -} diff --git a/src/Protocols.Abstractions/Features/ITransportSchedulerFeature.cs b/src/Protocols.Abstractions/Features/ITransportSchedulerFeature.cs deleted file mode 100644 index 05c8b8d605..0000000000 --- a/src/Protocols.Abstractions/Features/ITransportSchedulerFeature.cs +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System.Buffers; -using System.IO.Pipelines; -using System.Threading; - -namespace Microsoft.AspNetCore.Protocols.Features -{ - public interface ITransportSchedulerFeature - { - PipeScheduler InputWriterScheduler { get; } - - PipeScheduler OutputReaderScheduler { get; } - } -} diff --git a/test/Kestrel.Core.Tests/ConnectionHandlerTests.cs b/test/Kestrel.Core.Tests/ConnectionHandlerTests.cs index 27128fe558..ee1cffefdc 100644 --- a/test/Kestrel.Core.Tests/ConnectionHandlerTests.cs +++ b/test/Kestrel.Core.Tests/ConnectionHandlerTests.cs @@ -45,13 +45,24 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests Assert.True(((TestKestrelTrace)serviceContext.Log).Logger.Scopes.IsEmpty); } - private class TestConnection : TransportConnection + private class TestConnection : FeatureCollection, IConnectionIdFeature, IConnectionTransportFeature { - public override MemoryPool MemoryPool { get; } = KestrelMemoryPool.Create(); + public TestConnection() + { + Set(this); + Set(this); + } - public override PipeScheduler InputWriterScheduler => PipeScheduler.ThreadPool; + public MemoryPool MemoryPool { get; } = KestrelMemoryPool.Create(); - public override PipeScheduler OutputReaderScheduler => PipeScheduler.ThreadPool; + public IDuplexPipe Transport { get; set; } + public IDuplexPipe Application { get; set; } + + public PipeScheduler InputWriterScheduler => PipeScheduler.ThreadPool; + + public PipeScheduler OutputReaderScheduler => PipeScheduler.ThreadPool; + + public string ConnectionId { get; set; } } } } diff --git a/test/Kestrel.Transport.Libuv.Tests/TestHelpers/MockConnectionHandler.cs b/test/Kestrel.Transport.Libuv.Tests/TestHelpers/MockConnectionHandler.cs index edae9162f5..daf6cdd27c 100644 --- a/test/Kestrel.Transport.Libuv.Tests/TestHelpers/MockConnectionHandler.cs +++ b/test/Kestrel.Transport.Libuv.Tests/TestHelpers/MockConnectionHandler.cs @@ -16,13 +16,17 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests.TestHelpers public Func, PipeOptions> InputOptions { get; set; } = pool => new PipeOptions(pool, readerScheduler: PipeScheduler.Inline, writerScheduler: PipeScheduler.Inline, useSynchronizationContext: false); public Func, PipeOptions> OutputOptions { get; set; } = pool => new PipeOptions(pool, readerScheduler: PipeScheduler.Inline, writerScheduler: PipeScheduler.Inline, useSynchronizationContext: false); - public void OnConnection(TransportConnection connection) + public void OnConnection(IFeatureCollection features) { - Input = new Pipe(InputOptions(connection.MemoryPool)); - Output = new Pipe(OutputOptions(connection.MemoryPool)); + var connectionContext = new DefaultConnectionContext(features); - connection.Transport = new DuplexPipe(Input.Reader, Output.Writer); - connection.Application = new DuplexPipe(Output.Reader, Input.Writer); + var feature = connectionContext.Features.Get(); + + Input = new Pipe(InputOptions(feature.MemoryPool)); + Output = new Pipe(OutputOptions(feature.MemoryPool)); + + connectionContext.Transport = new DuplexPipe(Input.Reader, Output.Writer); + feature.Application = new DuplexPipe(Output.Reader, Input.Writer); } public Pipe Input { get; private set; } From 2d8f3d95fea21a68a673cc060e3178c9f1170fb1 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Tue, 13 Mar 2018 10:27:04 -0700 Subject: [PATCH 1564/1662] Feature/clean up proto abstractions (#2383) - This change aims to clean up the feature interfaces used by kestrel and exposed by protocol absractions. It splits out the IConnectionTransportFeature into smaller features that may or may not be implemented on the connection. - Added all of the features from Socket.Abstractions in an attempt to make it go away completely. As a result the helper methods and extensions have all been added here. - Change IConnectionHandler to take TransportConnection. This cleans up the interface and makes it more explicit what features are required by Kestrel --- .../Internal/ConnectionHandler.cs | 18 ++-- .../Internal/HttpConnectionMiddleware.cs | 7 +- .../Internal/IConnectionHandler.cs | 2 +- .../Internal/TransportConnection.Features.cs | 96 +++++++++++++++++-- .../Internal/TransportConnection.cs | 3 + .../ConnectionBuilderExtensions.cs | 34 +++++++ src/Protocols.Abstractions/DuplexPipe.cs | 4 - .../Features/ConnectionBuilder.cs | 44 +++++++++ .../Features/IApplicationTransportFeature.cs | 14 +++ .../Features/IConnectionHeartbeatFeature.cs | 12 +++ .../Features/IConnectionIdFeature.cs | 5 +- .../IConnectionInherentKeepAliveFeature.cs | 24 +++++ .../Features/IConnectionMetadataFeature.cs | 13 +++ .../Features/IConnectionTransportFeature.cs | 13 +-- .../Features/IConnectionUserFeature.cs | 9 ++ .../Features/IMemoryPoolFeature.cs | 14 +++ .../Features/ITransportSchedulerFeature.cs | 16 ++++ .../ConnectionHandlerTests.cs | 19 +--- .../TestHelpers/MockConnectionHandler.cs | 14 +-- 19 files changed, 299 insertions(+), 62 deletions(-) create mode 100644 src/Protocols.Abstractions/ConnectionBuilderExtensions.cs create mode 100644 src/Protocols.Abstractions/Features/ConnectionBuilder.cs create mode 100644 src/Protocols.Abstractions/Features/IApplicationTransportFeature.cs create mode 100644 src/Protocols.Abstractions/Features/IConnectionHeartbeatFeature.cs create mode 100644 src/Protocols.Abstractions/Features/IConnectionInherentKeepAliveFeature.cs create mode 100644 src/Protocols.Abstractions/Features/IConnectionMetadataFeature.cs create mode 100644 src/Protocols.Abstractions/Features/IConnectionUserFeature.cs create mode 100644 src/Protocols.Abstractions/Features/IMemoryPoolFeature.cs create mode 100644 src/Protocols.Abstractions/Features/ITransportSchedulerFeature.cs diff --git a/src/Kestrel.Core/Internal/ConnectionHandler.cs b/src/Kestrel.Core/Internal/ConnectionHandler.cs index f989a61c18..db02fcd6ff 100644 --- a/src/Kestrel.Core/Internal/ConnectionHandler.cs +++ b/src/Kestrel.Core/Internal/ConnectionHandler.cs @@ -28,29 +28,25 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal private IKestrelTrace Log => _serviceContext.Log; - public void OnConnection(IFeatureCollection features) + public void OnConnection(TransportConnection connection) { - var connectionContext = new DefaultConnectionContext(features); - - var transportFeature = connectionContext.Features.Get(); - // REVIEW: Unfortunately, we still need to use the service context to create the pipes since the settings // for the scheduler and limits are specified here - var inputOptions = GetInputPipeOptions(_serviceContext, transportFeature.MemoryPool, transportFeature.InputWriterScheduler); - var outputOptions = GetOutputPipeOptions(_serviceContext, transportFeature.MemoryPool, transportFeature.OutputReaderScheduler); + var inputOptions = GetInputPipeOptions(_serviceContext, connection.MemoryPool, connection.InputWriterScheduler); + var outputOptions = GetOutputPipeOptions(_serviceContext, connection.MemoryPool, connection.OutputReaderScheduler); var pair = DuplexPipe.CreateConnectionPair(inputOptions, outputOptions); // Set the transport and connection id - connectionContext.ConnectionId = CorrelationIdGenerator.GetNextId(); - connectionContext.Transport = pair.Transport; + connection.ConnectionId = CorrelationIdGenerator.GetNextId(); + connection.Transport = pair.Transport; // This *must* be set before returning from OnConnection - transportFeature.Application = pair.Application; + connection.Application = pair.Application; // REVIEW: This task should be tracked by the server for graceful shutdown // Today it's handled specifically for http but not for aribitrary middleware - _ = Execute(connectionContext); + _ = Execute(new DefaultConnectionContext(connection)); } private async Task Execute(ConnectionContext connectionContext) diff --git a/src/Kestrel.Core/Internal/HttpConnectionMiddleware.cs b/src/Kestrel.Core/Internal/HttpConnectionMiddleware.cs index 3e25712899..3be295627d 100644 --- a/src/Kestrel.Core/Internal/HttpConnectionMiddleware.cs +++ b/src/Kestrel.Core/Internal/HttpConnectionMiddleware.cs @@ -33,7 +33,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal { // We need the transport feature so that we can cancel the output reader that the transport is using // This is a bit of a hack but it preserves the existing semantics - var transportFeature = connectionContext.Features.Get(); + var applicationFeature = connectionContext.Features.Get(); + var memoryPoolFeature = connectionContext.Features.Get(); var httpConnectionId = Interlocked.Increment(ref _lastHttpConnectionId); @@ -44,10 +45,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal Protocols = _protocols, ServiceContext = _serviceContext, ConnectionFeatures = connectionContext.Features, - MemoryPool = transportFeature.MemoryPool, + MemoryPool = memoryPoolFeature.MemoryPool, ConnectionAdapters = _connectionAdapters, Transport = connectionContext.Transport, - Application = transportFeature.Application + Application = applicationFeature.Application }; var connectionFeature = connectionContext.Features.Get(); diff --git a/src/Kestrel.Transport.Abstractions/Internal/IConnectionHandler.cs b/src/Kestrel.Transport.Abstractions/Internal/IConnectionHandler.cs index 9ae3f89c3f..eec71ff61c 100644 --- a/src/Kestrel.Transport.Abstractions/Internal/IConnectionHandler.cs +++ b/src/Kestrel.Transport.Abstractions/Internal/IConnectionHandler.cs @@ -7,6 +7,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal { public interface IConnectionHandler { - void OnConnection(IFeatureCollection features); + void OnConnection(TransportConnection connection); } } diff --git a/src/Kestrel.Transport.Abstractions/Internal/TransportConnection.Features.cs b/src/Kestrel.Transport.Abstractions/Internal/TransportConnection.Features.cs index 4259da0128..275c80ba95 100644 --- a/src/Kestrel.Transport.Abstractions/Internal/TransportConnection.Features.cs +++ b/src/Kestrel.Transport.Abstractions/Internal/TransportConnection.Features.cs @@ -12,15 +12,24 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal public partial class TransportConnection : IFeatureCollection, IHttpConnectionFeature, IConnectionIdFeature, - IConnectionTransportFeature + IConnectionTransportFeature, + IMemoryPoolFeature, + IApplicationTransportFeature, + ITransportSchedulerFeature { private static readonly Type IHttpConnectionFeatureType = typeof(IHttpConnectionFeature); private static readonly Type IConnectionIdFeatureType = typeof(IConnectionIdFeature); private static readonly Type IConnectionTransportFeatureType = typeof(IConnectionTransportFeature); + private static readonly Type IMemoryPoolFeatureType = typeof(IMemoryPoolFeature); + private static readonly Type IApplicationTransportFeatureType = typeof(IApplicationTransportFeature); + private static readonly Type ITransportSchedulerFeatureType = typeof(ITransportSchedulerFeature); private object _currentIHttpConnectionFeature; private object _currentIConnectionIdFeature; private object _currentIConnectionTransportFeature; + private object _currentIMemoryPoolFeature; + private object _currentIApplicationTransportFeature; + private object _currentITransportSchedulerFeature; private int _featureRevision; @@ -95,7 +104,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal set => LocalPort = value; } - MemoryPool IConnectionTransportFeature.MemoryPool => MemoryPool; + MemoryPool IMemoryPoolFeature.MemoryPool => MemoryPool; IDuplexPipe IConnectionTransportFeature.Transport { @@ -103,12 +112,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal set => Transport = value; } - IDuplexPipe IConnectionTransportFeature.Application + IDuplexPipe IApplicationTransportFeature.Application { get => Application; set => Application = value; } + PipeScheduler ITransportSchedulerFeature.InputWriterScheduler => InputWriterScheduler; + PipeScheduler ITransportSchedulerFeature.OutputReaderScheduler => OutputReaderScheduler; + object IFeatureCollection.this[Type key] { get @@ -128,6 +140,21 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal return _currentIConnectionTransportFeature; } + if (key == IMemoryPoolFeatureType) + { + return _currentIMemoryPoolFeature; + } + + if (key == IApplicationTransportFeatureType) + { + return _currentIApplicationTransportFeature; + } + + if (key == ITransportSchedulerFeatureType) + { + return _currentITransportSchedulerFeature; + } + if (MaybeExtra != null) { return ExtraFeatureGet(key); @@ -151,6 +178,18 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal { _currentIConnectionTransportFeature = value; } + else if (key == IMemoryPoolFeatureType) + { + _currentIMemoryPoolFeature = value; + } + else if (key == IApplicationTransportFeatureType) + { + _currentIApplicationTransportFeature = value; + } + else if (key == ITransportSchedulerFeatureType) + { + _currentITransportSchedulerFeature = value; + } else { ExtraFeatureSet(key, value); @@ -160,18 +199,30 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal TFeature IFeatureCollection.Get() { - if (typeof(TFeature) == typeof(IHttpConnectionFeature)) + if (typeof(TFeature) == IHttpConnectionFeatureType) { return (TFeature)_currentIHttpConnectionFeature; } - else if (typeof(TFeature) == typeof(IConnectionIdFeature)) + else if (typeof(TFeature) == IConnectionIdFeatureType) { return (TFeature)_currentIConnectionIdFeature; } - else if (typeof(TFeature) == typeof(IConnectionTransportFeature)) + else if (typeof(TFeature) == IConnectionTransportFeatureType) { return (TFeature)_currentIConnectionTransportFeature; } + else if (typeof(TFeature) == IMemoryPoolFeatureType) + { + return (TFeature)_currentIMemoryPoolFeature; + } + else if (typeof(TFeature) == IApplicationTransportFeatureType) + { + return (TFeature)_currentIApplicationTransportFeature; + } + else if (typeof(TFeature) == ITransportSchedulerFeatureType) + { + return (TFeature)_currentITransportSchedulerFeature; + } else if (MaybeExtra != null) { return (TFeature)ExtraFeatureGet(typeof(TFeature)); @@ -184,18 +235,30 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal { _featureRevision++; - if (typeof(TFeature) == typeof(IHttpConnectionFeature)) + if (typeof(TFeature) == IHttpConnectionFeatureType) { _currentIHttpConnectionFeature = instance; } - else if (typeof(TFeature) == typeof(IConnectionIdFeature)) + else if (typeof(TFeature) == IConnectionIdFeatureType) { _currentIConnectionIdFeature = instance; } - else if (typeof(TFeature) == typeof(IConnectionTransportFeature)) + else if (typeof(TFeature) == IConnectionTransportFeatureType) { _currentIConnectionTransportFeature = instance; } + else if (typeof(TFeature) == IMemoryPoolFeatureType) + { + _currentIMemoryPoolFeature = instance; + } + else if (typeof(TFeature) == IApplicationTransportFeatureType) + { + _currentIApplicationTransportFeature = instance; + } + else if (typeof(TFeature) == ITransportSchedulerFeatureType) + { + _currentITransportSchedulerFeature = instance; + } else { ExtraFeatureSet(typeof(TFeature), instance); @@ -223,6 +286,21 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal yield return new KeyValuePair(IConnectionTransportFeatureType, _currentIConnectionTransportFeature); } + if (_currentIMemoryPoolFeature != null) + { + yield return new KeyValuePair(IMemoryPoolFeatureType, _currentIMemoryPoolFeature); + } + + if (_currentIApplicationTransportFeature != null) + { + yield return new KeyValuePair(IApplicationTransportFeatureType, _currentIApplicationTransportFeature); + } + + if (_currentITransportSchedulerFeature != null) + { + yield return new KeyValuePair(ITransportSchedulerFeatureType, _currentITransportSchedulerFeature); + } + if (MaybeExtra != null) { foreach (var item in MaybeExtra) diff --git a/src/Kestrel.Transport.Abstractions/Internal/TransportConnection.cs b/src/Kestrel.Transport.Abstractions/Internal/TransportConnection.cs index 3aae48b16c..bfe7e53458 100644 --- a/src/Kestrel.Transport.Abstractions/Internal/TransportConnection.cs +++ b/src/Kestrel.Transport.Abstractions/Internal/TransportConnection.cs @@ -12,6 +12,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal _currentIConnectionIdFeature = this; _currentIConnectionTransportFeature = this; _currentIHttpConnectionFeature = this; + _currentIApplicationTransportFeature = this; + _currentIMemoryPoolFeature = this; + _currentITransportSchedulerFeature = this; } public IPAddress RemoteAddress { get; set; } diff --git a/src/Protocols.Abstractions/ConnectionBuilderExtensions.cs b/src/Protocols.Abstractions/ConnectionBuilderExtensions.cs new file mode 100644 index 0000000000..9db3e4c468 --- /dev/null +++ b/src/Protocols.Abstractions/ConnectionBuilderExtensions.cs @@ -0,0 +1,34 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Threading.Tasks; + +namespace Microsoft.AspNetCore.Protocols +{ + public static class ConnectionBuilderExtensions + { + public static IConnectionBuilder Use(this IConnectionBuilder connectionBuilder, Func, Task> middleware) + { + return connectionBuilder.Use(next => + { + return context => + { + Func simpleNext = () => next(context); + return middleware(context, simpleNext); + }; + }); + } + + public static IConnectionBuilder Run(this IConnectionBuilder connectionBuilder, Func middleware) + { + return connectionBuilder.Use(next => + { + return context => + { + return middleware(context); + }; + }); + } + } +} \ No newline at end of file diff --git a/src/Protocols.Abstractions/DuplexPipe.cs b/src/Protocols.Abstractions/DuplexPipe.cs index adf8b497c6..e7a6ad1710 100644 --- a/src/Protocols.Abstractions/DuplexPipe.cs +++ b/src/Protocols.Abstractions/DuplexPipe.cs @@ -14,10 +14,6 @@ namespace System.IO.Pipelines public PipeWriter Output { get; } - public void Dispose() - { - } - public static DuplexPipePair CreateConnectionPair(PipeOptions inputOptions, PipeOptions outputOptions) { var input = new Pipe(inputOptions); diff --git a/src/Protocols.Abstractions/Features/ConnectionBuilder.cs b/src/Protocols.Abstractions/Features/ConnectionBuilder.cs new file mode 100644 index 0000000000..68efce703f --- /dev/null +++ b/src/Protocols.Abstractions/Features/ConnectionBuilder.cs @@ -0,0 +1,44 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Microsoft.AspNetCore.Protocols +{ + public class ConnectionBuilder : IConnectionBuilder + { + private readonly IList> _components = new List>(); + + public IServiceProvider ApplicationServices { get; } + + public ConnectionBuilder(IServiceProvider applicationServices) + { + ApplicationServices = applicationServices; + } + + public IConnectionBuilder Use(Func middleware) + { + _components.Add(middleware); + return this; + } + + public ConnectionDelegate Build() + { + ConnectionDelegate app = features => + { + return Task.CompletedTask; + }; + + foreach (var component in _components.Reverse()) + { + app = component(app); + } + + return app; + } + } +} \ No newline at end of file diff --git a/src/Protocols.Abstractions/Features/IApplicationTransportFeature.cs b/src/Protocols.Abstractions/Features/IApplicationTransportFeature.cs new file mode 100644 index 0000000000..10f22d135e --- /dev/null +++ b/src/Protocols.Abstractions/Features/IApplicationTransportFeature.cs @@ -0,0 +1,14 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System.Buffers; +using System.IO.Pipelines; +using System.Threading; + +namespace Microsoft.AspNetCore.Protocols.Features +{ + public interface IApplicationTransportFeature + { + IDuplexPipe Application { get; set; } + } +} diff --git a/src/Protocols.Abstractions/Features/IConnectionHeartbeatFeature.cs b/src/Protocols.Abstractions/Features/IConnectionHeartbeatFeature.cs new file mode 100644 index 0000000000..9770143a34 --- /dev/null +++ b/src/Protocols.Abstractions/Features/IConnectionHeartbeatFeature.cs @@ -0,0 +1,12 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; + +namespace Microsoft.AspNetCore.Protocols.Features +{ + public interface IConnectionHeartbeatFeature + { + void OnHeartbeat(Action action, object state); + } +} \ No newline at end of file diff --git a/src/Protocols.Abstractions/Features/IConnectionIdFeature.cs b/src/Protocols.Abstractions/Features/IConnectionIdFeature.cs index ab1c09e3db..4c6cd81e77 100644 --- a/src/Protocols.Abstractions/Features/IConnectionIdFeature.cs +++ b/src/Protocols.Abstractions/Features/IConnectionIdFeature.cs @@ -1,4 +1,7 @@ -namespace Microsoft.AspNetCore.Protocols.Features +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +namespace Microsoft.AspNetCore.Protocols.Features { public interface IConnectionIdFeature { diff --git a/src/Protocols.Abstractions/Features/IConnectionInherentKeepAliveFeature.cs b/src/Protocols.Abstractions/Features/IConnectionInherentKeepAliveFeature.cs new file mode 100644 index 0000000000..cc3a211e46 --- /dev/null +++ b/src/Protocols.Abstractions/Features/IConnectionInherentKeepAliveFeature.cs @@ -0,0 +1,24 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Collections.Generic; +using System.Text; + +namespace Microsoft.AspNetCore.Protocols.Features +{ + /// + /// Indicates if the connection transport has an "inherent keep-alive", which means that the transport will automatically + /// inform the client that it is still present. + /// + /// + /// The most common example of this feature is the Long Polling HTTP transport, which must (due to HTTP limitations) terminate + /// each poll within a particular interval and return a signal indicating "the server is still here, but there is no data yet". + /// This feature allows applications to add keep-alive functionality, but limit it only to transports that don't have some kind + /// of inherent keep-alive. + /// + public interface IConnectionInherentKeepAliveFeature + { + TimeSpan KeepAliveInterval { get; } + } +} \ No newline at end of file diff --git a/src/Protocols.Abstractions/Features/IConnectionMetadataFeature.cs b/src/Protocols.Abstractions/Features/IConnectionMetadataFeature.cs new file mode 100644 index 0000000000..b2e0f67789 --- /dev/null +++ b/src/Protocols.Abstractions/Features/IConnectionMetadataFeature.cs @@ -0,0 +1,13 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Collections.Generic; + +namespace Microsoft.AspNetCore.Protocols.Features +{ + public interface IConnectionMetadataFeature + { + IDictionary Metadata { get; set; } + } +} \ No newline at end of file diff --git a/src/Protocols.Abstractions/Features/IConnectionTransportFeature.cs b/src/Protocols.Abstractions/Features/IConnectionTransportFeature.cs index 1a5500b692..bf7067be23 100644 --- a/src/Protocols.Abstractions/Features/IConnectionTransportFeature.cs +++ b/src/Protocols.Abstractions/Features/IConnectionTransportFeature.cs @@ -1,4 +1,7 @@ -using System.Buffers; +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System.Buffers; using System.IO.Pipelines; using System.Threading; @@ -6,14 +9,6 @@ namespace Microsoft.AspNetCore.Protocols.Features { public interface IConnectionTransportFeature { - MemoryPool MemoryPool { get; } - IDuplexPipe Transport { get; set; } - - IDuplexPipe Application { get; set; } - - PipeScheduler InputWriterScheduler { get; } - - PipeScheduler OutputReaderScheduler { get; } } } diff --git a/src/Protocols.Abstractions/Features/IConnectionUserFeature.cs b/src/Protocols.Abstractions/Features/IConnectionUserFeature.cs new file mode 100644 index 0000000000..5daf9fd232 --- /dev/null +++ b/src/Protocols.Abstractions/Features/IConnectionUserFeature.cs @@ -0,0 +1,9 @@ +using System.Security.Claims; + +namespace Microsoft.AspNetCore.Protocols.Features +{ + public interface IConnectionUserFeature + { + ClaimsPrincipal User { get; set; } + } +} \ No newline at end of file diff --git a/src/Protocols.Abstractions/Features/IMemoryPoolFeature.cs b/src/Protocols.Abstractions/Features/IMemoryPoolFeature.cs new file mode 100644 index 0000000000..128b9ae3c9 --- /dev/null +++ b/src/Protocols.Abstractions/Features/IMemoryPoolFeature.cs @@ -0,0 +1,14 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System.Buffers; +using System.IO.Pipelines; +using System.Threading; + +namespace Microsoft.AspNetCore.Protocols.Features +{ + public interface IMemoryPoolFeature + { + MemoryPool MemoryPool { get; } + } +} diff --git a/src/Protocols.Abstractions/Features/ITransportSchedulerFeature.cs b/src/Protocols.Abstractions/Features/ITransportSchedulerFeature.cs new file mode 100644 index 0000000000..05c8b8d605 --- /dev/null +++ b/src/Protocols.Abstractions/Features/ITransportSchedulerFeature.cs @@ -0,0 +1,16 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System.Buffers; +using System.IO.Pipelines; +using System.Threading; + +namespace Microsoft.AspNetCore.Protocols.Features +{ + public interface ITransportSchedulerFeature + { + PipeScheduler InputWriterScheduler { get; } + + PipeScheduler OutputReaderScheduler { get; } + } +} diff --git a/test/Kestrel.Core.Tests/ConnectionHandlerTests.cs b/test/Kestrel.Core.Tests/ConnectionHandlerTests.cs index ee1cffefdc..27128fe558 100644 --- a/test/Kestrel.Core.Tests/ConnectionHandlerTests.cs +++ b/test/Kestrel.Core.Tests/ConnectionHandlerTests.cs @@ -45,24 +45,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests Assert.True(((TestKestrelTrace)serviceContext.Log).Logger.Scopes.IsEmpty); } - private class TestConnection : FeatureCollection, IConnectionIdFeature, IConnectionTransportFeature + private class TestConnection : TransportConnection { - public TestConnection() - { - Set(this); - Set(this); - } + public override MemoryPool MemoryPool { get; } = KestrelMemoryPool.Create(); - public MemoryPool MemoryPool { get; } = KestrelMemoryPool.Create(); + public override PipeScheduler InputWriterScheduler => PipeScheduler.ThreadPool; - public IDuplexPipe Transport { get; set; } - public IDuplexPipe Application { get; set; } - - public PipeScheduler InputWriterScheduler => PipeScheduler.ThreadPool; - - public PipeScheduler OutputReaderScheduler => PipeScheduler.ThreadPool; - - public string ConnectionId { get; set; } + public override PipeScheduler OutputReaderScheduler => PipeScheduler.ThreadPool; } } } diff --git a/test/Kestrel.Transport.Libuv.Tests/TestHelpers/MockConnectionHandler.cs b/test/Kestrel.Transport.Libuv.Tests/TestHelpers/MockConnectionHandler.cs index daf6cdd27c..edae9162f5 100644 --- a/test/Kestrel.Transport.Libuv.Tests/TestHelpers/MockConnectionHandler.cs +++ b/test/Kestrel.Transport.Libuv.Tests/TestHelpers/MockConnectionHandler.cs @@ -16,17 +16,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests.TestHelpers public Func, PipeOptions> InputOptions { get; set; } = pool => new PipeOptions(pool, readerScheduler: PipeScheduler.Inline, writerScheduler: PipeScheduler.Inline, useSynchronizationContext: false); public Func, PipeOptions> OutputOptions { get; set; } = pool => new PipeOptions(pool, readerScheduler: PipeScheduler.Inline, writerScheduler: PipeScheduler.Inline, useSynchronizationContext: false); - public void OnConnection(IFeatureCollection features) + public void OnConnection(TransportConnection connection) { - var connectionContext = new DefaultConnectionContext(features); + Input = new Pipe(InputOptions(connection.MemoryPool)); + Output = new Pipe(OutputOptions(connection.MemoryPool)); - var feature = connectionContext.Features.Get(); - - Input = new Pipe(InputOptions(feature.MemoryPool)); - Output = new Pipe(OutputOptions(feature.MemoryPool)); - - connectionContext.Transport = new DuplexPipe(Input.Reader, Output.Writer); - feature.Application = new DuplexPipe(Output.Reader, Input.Writer); + connection.Transport = new DuplexPipe(Input.Reader, Output.Writer); + connection.Application = new DuplexPipe(Output.Reader, Input.Writer); } public Pipe Input { get; private set; } From bcea8330c43188323bec1b83adba58766cf1c147 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Tue, 13 Mar 2018 14:10:06 -0700 Subject: [PATCH 1565/1662] Clean up some left overs (#2385) --- .../Internal/TransportConnection.Features.cs | 24 +++++++++---------- .../{Features => }/ConnectionBuilder.cs | 0 2 files changed, 12 insertions(+), 12 deletions(-) rename src/Protocols.Abstractions/{Features => }/ConnectionBuilder.cs (100%) diff --git a/src/Kestrel.Transport.Abstractions/Internal/TransportConnection.Features.cs b/src/Kestrel.Transport.Abstractions/Internal/TransportConnection.Features.cs index 275c80ba95..9e91865b86 100644 --- a/src/Kestrel.Transport.Abstractions/Internal/TransportConnection.Features.cs +++ b/src/Kestrel.Transport.Abstractions/Internal/TransportConnection.Features.cs @@ -199,27 +199,27 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal TFeature IFeatureCollection.Get() { - if (typeof(TFeature) == IHttpConnectionFeatureType) + if (typeof(TFeature) == typeof(IHttpConnectionFeature)) { return (TFeature)_currentIHttpConnectionFeature; } - else if (typeof(TFeature) == IConnectionIdFeatureType) + else if (typeof(TFeature) == typeof(IConnectionIdFeature)) { return (TFeature)_currentIConnectionIdFeature; } - else if (typeof(TFeature) == IConnectionTransportFeatureType) + else if (typeof(TFeature) == typeof(IConnectionTransportFeature)) { return (TFeature)_currentIConnectionTransportFeature; } - else if (typeof(TFeature) == IMemoryPoolFeatureType) + else if (typeof(TFeature) == typeof(IMemoryPoolFeature)) { return (TFeature)_currentIMemoryPoolFeature; } - else if (typeof(TFeature) == IApplicationTransportFeatureType) + else if (typeof(TFeature) == typeof(IApplicationTransportFeature)) { return (TFeature)_currentIApplicationTransportFeature; } - else if (typeof(TFeature) == ITransportSchedulerFeatureType) + else if (typeof(TFeature) == typeof(ITransportSchedulerFeature)) { return (TFeature)_currentITransportSchedulerFeature; } @@ -235,27 +235,27 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal { _featureRevision++; - if (typeof(TFeature) == IHttpConnectionFeatureType) + if (typeof(TFeature) == typeof(IHttpConnectionFeature)) { _currentIHttpConnectionFeature = instance; } - else if (typeof(TFeature) == IConnectionIdFeatureType) + else if (typeof(TFeature) == typeof(IConnectionIdFeature)) { _currentIConnectionIdFeature = instance; } - else if (typeof(TFeature) == IConnectionTransportFeatureType) + else if (typeof(TFeature) == typeof(IConnectionTransportFeature)) { _currentIConnectionTransportFeature = instance; } - else if (typeof(TFeature) == IMemoryPoolFeatureType) + else if (typeof(TFeature) == typeof(IMemoryPoolFeature)) { _currentIMemoryPoolFeature = instance; } - else if (typeof(TFeature) == IApplicationTransportFeatureType) + else if (typeof(TFeature) == typeof(IApplicationTransportFeature)) { _currentIApplicationTransportFeature = instance; } - else if (typeof(TFeature) == ITransportSchedulerFeatureType) + else if (typeof(TFeature) == typeof(ITransportSchedulerFeature)) { _currentITransportSchedulerFeature = instance; } diff --git a/src/Protocols.Abstractions/Features/ConnectionBuilder.cs b/src/Protocols.Abstractions/ConnectionBuilder.cs similarity index 100% rename from src/Protocols.Abstractions/Features/ConnectionBuilder.cs rename to src/Protocols.Abstractions/ConnectionBuilder.cs From bfdb48717f8553673d8b071d08e5375f9e4d0132 Mon Sep 17 00:00:00 2001 From: "Chris Ross (ASP.NET)" Date: Fri, 19 Jan 2018 09:28:04 -0800 Subject: [PATCH 1566/1662] Host header format validation --- .../Http1ConnectionBenchmark.cs | 115 +++++++ .../Internal/Http/Http1Connection.cs | 33 +- .../Internal/Http2/HPack/HPackDecoder.cs | 35 +- .../Internal/Http2/Http2Stream.cs | 53 ++- .../Infrastructure/HttpUtilities.Generated.cs | 1 + .../Internal/Infrastructure/HttpUtilities.cs | 133 ++++++++ .../Http1ConnectionTests.cs | 50 +++ .../Http2ConnectionTests.cs | 320 +++++++++++++++++- test/Kestrel.Core.Tests/HttpUtilitiesTest.cs | 95 ++++++ .../BadHttpRequestTests.cs | 18 + test/Kestrel.FunctionalTests/RequestTests.cs | 2 +- .../HttpUtilities/HttpUtilities.cs | 1 + 12 files changed, 825 insertions(+), 31 deletions(-) create mode 100644 benchmarks/Kestrel.Performance/Http1ConnectionBenchmark.cs diff --git a/benchmarks/Kestrel.Performance/Http1ConnectionBenchmark.cs b/benchmarks/Kestrel.Performance/Http1ConnectionBenchmark.cs new file mode 100644 index 0000000000..b90221b4a7 --- /dev/null +++ b/benchmarks/Kestrel.Performance/Http1ConnectionBenchmark.cs @@ -0,0 +1,115 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Buffers; +using System.IO.Pipelines; +using BenchmarkDotNet.Attributes; +using Microsoft.AspNetCore.Http.Features; +using Microsoft.AspNetCore.Server.Kestrel.Core; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Performance.Mocks; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; + +namespace Microsoft.AspNetCore.Server.Kestrel.Performance +{ + public class Http1ConnectionBenchmark + { + private const int InnerLoopCount = 512; + + private readonly HttpParser _parser = new HttpParser(); + + private ReadOnlySequence _buffer; + + public Http1Connection Connection { get; set; } + + [GlobalSetup] + public void Setup() + { + var memoryPool = KestrelMemoryPool.Create(); + var options = new PipeOptions(memoryPool, readerScheduler: PipeScheduler.Inline, writerScheduler: PipeScheduler.Inline, useSynchronizationContext: false); + var pair = DuplexPipe.CreateConnectionPair(options, options); + + var serviceContext = new ServiceContext + { + ServerOptions = new KestrelServerOptions(), + HttpParser = NullParser.Instance + }; + + var http1Connection = new Http1Connection(context: new Http1ConnectionContext + { + ServiceContext = serviceContext, + ConnectionFeatures = new FeatureCollection(), + MemoryPool = memoryPool, + TimeoutControl = new MockTimeoutControl(), + Application = pair.Application, + Transport = pair.Transport + }); + + http1Connection.Reset(); + + Connection = http1Connection; + } + + [Benchmark(Baseline = true, OperationsPerInvoke = RequestParsingData.InnerLoopCount)] + public void PlaintextTechEmpower() + { + for (var i = 0; i < RequestParsingData.InnerLoopCount; i++) + { + InsertData(RequestParsingData.PlaintextTechEmpowerRequest); + ParseData(); + } + } + + [Benchmark(OperationsPerInvoke = RequestParsingData.InnerLoopCount)] + public void LiveAspNet() + { + for (var i = 0; i < RequestParsingData.InnerLoopCount; i++) + { + InsertData(RequestParsingData.LiveaspnetRequest); + ParseData(); + } + } + + private void InsertData(byte[] data) + { + _buffer = new ReadOnlySequence(data); + } + + private void ParseData() + { + if (!_parser.ParseRequestLine(new Adapter(this), _buffer, out var consumed, out var examined)) + { + ErrorUtilities.ThrowInvalidRequestHeaders(); + } + + _buffer = _buffer.Slice(consumed, _buffer.End); + + if (!_parser.ParseHeaders(new Adapter(this), _buffer, out consumed, out examined, out var consumedBytes)) + { + ErrorUtilities.ThrowInvalidRequestHeaders(); + } + + Connection.EnsureHostHeaderExists(); + + Connection.Reset(); + } + + private struct Adapter : IHttpRequestLineHandler, IHttpHeadersHandler + { + public Http1ConnectionBenchmark RequestHandler; + + public Adapter(Http1ConnectionBenchmark requestHandler) + { + RequestHandler = requestHandler; + } + + public void OnHeader(Span name, Span value) + => RequestHandler.Connection.OnHeader(name, value); + + public void OnStartLine(HttpMethod method, HttpVersion version, Span target, Span path, Span query, Span customMethod, bool pathEncoded) + => RequestHandler.Connection.OnStartLine(method, version, target, path, query, customMethod, pathEncoded); + } + } +} \ No newline at end of file diff --git a/src/Kestrel.Core/Internal/Http/Http1Connection.cs b/src/Kestrel.Core/Internal/Http/Http1Connection.cs index 1251ac3518..d0105f9bfe 100644 --- a/src/Kestrel.Core/Internal/Http/Http1Connection.cs +++ b/src/Kestrel.Core/Internal/Http/Http1Connection.cs @@ -3,13 +3,11 @@ using System; using System.Buffers; -using System.Collections; using System.Diagnostics; +using System.Globalization; using System.IO.Pipelines; using System.Runtime.InteropServices; using System.Text; -using System.Text.Encodings.Web; -using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Protocols.Abstractions; @@ -354,13 +352,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http } } - private void EnsureHostHeaderExists() + internal void EnsureHostHeaderExists() { - if (_httpVersion == Http.HttpVersion.Http10) - { - return; - } - // https://tools.ietf.org/html/rfc7230#section-5.4 // A server MUST respond with a 400 (Bad Request) status code to any // HTTP/1.1 request message that lacks a Host header field and to any @@ -368,8 +361,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http // Host header field with an invalid field-value. var host = HttpRequestHeaders.HeaderHost; + var hostText = host.ToString(); if (host.Count <= 0) { + if (_httpVersion == Http.HttpVersion.Http10) + { + return; + } BadHttpRequestException.Throw(RequestRejectionReason.MissingHostHeader); } else if (host.Count > 1) @@ -380,7 +378,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { if (!host.Equals(RawTarget)) { - BadHttpRequestException.Throw(RequestRejectionReason.InvalidHostHeader, in host); + BadHttpRequestException.Throw(RequestRejectionReason.InvalidHostHeader, hostText); } } else if (_requestTargetForm == HttpRequestTarget.AbsoluteForm) @@ -392,13 +390,20 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http // System.Uri doesn't not tell us if the port was in the original string or not. // When IsDefaultPort = true, we will allow Host: with or without the default port - var authorityAndPort = _absoluteRequestTarget.Authority + ":" + _absoluteRequestTarget.Port; - if ((host != _absoluteRequestTarget.Authority || !_absoluteRequestTarget.IsDefaultPort) - && host != authorityAndPort) + if (host != _absoluteRequestTarget.Authority) { - BadHttpRequestException.Throw(RequestRejectionReason.InvalidHostHeader, in host); + if (!_absoluteRequestTarget.IsDefaultPort + || host != _absoluteRequestTarget.Authority + ":" + _absoluteRequestTarget.Port.ToString(CultureInfo.InvariantCulture)) + { + BadHttpRequestException.Throw(RequestRejectionReason.InvalidHostHeader, hostText); + } } } + + if (!HttpUtilities.IsValidHostHeader(hostText)) + { + BadHttpRequestException.Throw(RequestRejectionReason.InvalidHostHeader, hostText); + } } protected override void OnReset() diff --git a/src/Kestrel.Core/Internal/Http2/HPack/HPackDecoder.cs b/src/Kestrel.Core/Internal/Http2/HPack/HPackDecoder.cs index 3df0d7af86..84f91ca896 100644 --- a/src/Kestrel.Core/Internal/Http2/HPack/HPackDecoder.cs +++ b/src/Kestrel.Core/Internal/Http2/HPack/HPackDecoder.cs @@ -261,6 +261,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2.HPack if (_integerDecoder.BeginDecode((byte)(b & ~HuffmanMask), StringLengthPrefix)) { OnStringLength(_integerDecoder.Value, nextState: State.HeaderValue); + if (_integerDecoder.Value == 0) + { + ProcessHeaderValue(handler); + } } else { @@ -272,6 +276,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2.HPack if (_integerDecoder.Decode(b)) { OnStringLength(_integerDecoder.Value, nextState: State.HeaderValue); + if (_integerDecoder.Value == 0) + { + ProcessHeaderValue(handler); + } } break; @@ -280,17 +288,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2.HPack if (_stringIndex == _stringLength) { - OnString(nextState: State.Ready); - - var headerNameSpan = new Span(_headerName, 0, _headerNameLength); - var headerValueSpan = new Span(_headerValueOctets, 0, _headerValueLength); - - handler.OnHeader(headerNameSpan, headerValueSpan); - - if (_index) - { - _dynamicTable.Insert(headerNameSpan, headerValueSpan); - } + ProcessHeaderValue(handler); } break; @@ -314,6 +312,21 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2.HPack } } + private void ProcessHeaderValue(IHttpHeadersHandler handler) + { + OnString(nextState: State.Ready); + + var headerNameSpan = new Span(_headerName, 0, _headerNameLength); + var headerValueSpan = new Span(_headerValueOctets, 0, _headerValueLength); + + handler.OnHeader(headerNameSpan, headerValueSpan); + + if (_index) + { + _dynamicTable.Insert(headerNameSpan, headerValueSpan); + } + } + private void OnIndexedHeaderField(int index, IHttpHeadersHandler handler) { var header = GetHeader(index); diff --git a/src/Kestrel.Core/Internal/Http2/Http2Stream.cs b/src/Kestrel.Core/Internal/Http2/Http2Stream.cs index 41e84805d9..fd73b5ac98 100644 --- a/src/Kestrel.Core/Internal/Http2/Http2Stream.cs +++ b/src/Kestrel.Core/Internal/Http2/Http2Stream.cs @@ -9,6 +9,8 @@ using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Server.Kestrel.Core.Features; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; +using Microsoft.Extensions.Primitives; +using Microsoft.Net.Http.Headers; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 { @@ -54,12 +56,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 // We don't need any of the parameters because we don't implement BeginRead to actually // do the reading from a pipeline, nor do we use endConnection to report connection-level errors. + _httpVersion = Http.HttpVersion.Http2; var methodText = RequestHeaders[":method"]; Method = HttpUtilities.GetKnownMethod(methodText); _methodText = methodText; - - Scheme = RequestHeaders[":scheme"]; - _httpVersion = Http.HttpVersion.Http2; + if (!string.Equals(RequestHeaders[":scheme"], Scheme, StringComparison.OrdinalIgnoreCase)) + { + BadHttpRequestException.Throw(RequestRejectionReason.InvalidRequestLine); + } var path = RequestHeaders[":path"].ToString(); var queryIndex = path.IndexOf('?'); @@ -68,7 +72,48 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 QueryString = queryIndex == -1 ? string.Empty : path.Substring(queryIndex); RawTarget = path; - RequestHeaders["Host"] = RequestHeaders[":authority"]; + // https://tools.ietf.org/html/rfc7230#section-5.4 + // A server MUST respond with a 400 (Bad Request) status code to any + // HTTP/1.1 request message that lacks a Host header field and to any + // request message that contains more than one Host header field or a + // Host header field with an invalid field-value. + + var authority = RequestHeaders[":authority"]; + var host = HttpRequestHeaders.HeaderHost; + if (authority.Count > 0) + { + // https://tools.ietf.org/html/rfc7540#section-8.1.2.3 + // An intermediary that converts an HTTP/2 request to HTTP/1.1 MUST + // create a Host header field if one is not present in a request by + // copying the value of the ":authority" pseudo - header field. + // + // We take this one step further, we don't want mismatched :authority + // and Host headers, replace Host if :authority is defined. + HttpRequestHeaders.HeaderHost = authority; + host = authority; + } + + // TODO: OPTIONS * requests? + // To ensure that the HTTP / 1.1 request line can be reproduced + // accurately, this pseudo - header field MUST be omitted when + // translating from an HTTP/ 1.1 request that has a request target in + // origin or asterisk form(see[RFC7230], Section 5.3). + // https://tools.ietf.org/html/rfc7230#section-5.3 + + if (host.Count <= 0) + { + BadHttpRequestException.Throw(RequestRejectionReason.MissingHostHeader); + } + else if (host.Count > 1) + { + BadHttpRequestException.Throw(RequestRejectionReason.MultipleHostHeaders); + } + + var hostText = host.ToString(); + if (!HttpUtilities.IsValidHostHeader(hostText)) + { + BadHttpRequestException.Throw(RequestRejectionReason.InvalidHostHeader, hostText); + } endConnection = false; return true; diff --git a/src/Kestrel.Core/Internal/Infrastructure/HttpUtilities.Generated.cs b/src/Kestrel.Core/Internal/Infrastructure/HttpUtilities.Generated.cs index 1dd2e252c2..15e3e1cd7b 100644 --- a/src/Kestrel.Core/Internal/Infrastructure/HttpUtilities.Generated.cs +++ b/src/Kestrel.Core/Internal/Infrastructure/HttpUtilities.Generated.cs @@ -51,6 +51,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure SetKnownMethod(_mask8Chars, _httpConnectMethodLong, HttpMethod.Connect, 7); SetKnownMethod(_mask8Chars, _httpOptionsMethodLong, HttpMethod.Options, 7); FillKnownMethodsGaps(); + InitializeHostCharValidity(); _methodNames[(byte)HttpMethod.Connect] = HttpMethods.Connect; _methodNames[(byte)HttpMethod.Delete] = HttpMethods.Delete; _methodNames[(byte)HttpMethod.Get] = HttpMethods.Get; diff --git a/src/Kestrel.Core/Internal/Infrastructure/HttpUtilities.cs b/src/Kestrel.Core/Internal/Infrastructure/HttpUtilities.cs index 457b7afe5f..bfc3baa89b 100644 --- a/src/Kestrel.Core/Internal/Infrastructure/HttpUtilities.cs +++ b/src/Kestrel.Core/Internal/Infrastructure/HttpUtilities.cs @@ -13,6 +13,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure { public static partial class HttpUtilities { + private static readonly bool[] HostCharValidity = new bool[127]; + public const string Http10Version = "HTTP/1.0"; public const string Http11Version = "HTTP/1.1"; public const string Http2Version = "HTTP/2"; @@ -29,6 +31,35 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure private const ulong _http10VersionLong = 3471766442030158920; // GetAsciiStringAsLong("HTTP/1.0"); const results in better codegen private const ulong _http11VersionLong = 3543824036068086856; // GetAsciiStringAsLong("HTTP/1.1"); const results in better codegen + // Only called from the static constructor + private static void InitializeHostCharValidity() + { + // Matches Http.Sys + // Matches RFC 3986 except "*" / "+" / "," / ";" / "=" and "%" HEXDIG HEXDIG which are not allowed by Http.Sys + HostCharValidity['!'] = true; + HostCharValidity['$'] = true; + HostCharValidity['&'] = true; + HostCharValidity['\''] = true; + HostCharValidity['('] = true; + HostCharValidity[')'] = true; + HostCharValidity['-'] = true; + HostCharValidity['.'] = true; + HostCharValidity['_'] = true; + HostCharValidity['~'] = true; + for (var ch = '0'; ch <= '9'; ch++) + { + HostCharValidity[ch] = true; + } + for (var ch = 'A'; ch <= 'Z'; ch++) + { + HostCharValidity[ch] = true; + } + for (var ch = 'a'; ch <= 'z'; ch++) + { + HostCharValidity[ch] = true; + } + } + [MethodImpl(MethodImplOptions.AggressiveInlining)] private static void SetKnownMethod(ulong mask, ulong knownMethodUlong, HttpMethod knownMethod, int length) { @@ -394,5 +425,107 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure return null; } } + + public static bool IsValidHostHeader(string hostText) + { + // The spec allows empty values + if (string.IsNullOrEmpty(hostText)) + { + return true; + } + + if (hostText[0] == '[') + { + return IsValidIPv6Host(hostText); + } + + if (hostText[0] == ':') + { + // Only a port + return false; + } + + var i = 0; + for (; i < hostText.Length; i++) + { + if (!IsValidHostChar(hostText[i])) + { + break; + } + } + return IsValidHostPort(hostText, i); + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static bool IsValidHostChar(char ch) + { + return ch < HostCharValidity.Length && HostCharValidity[ch]; + } + + // The lead '[' was already checked + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static bool IsValidIPv6Host(string hostText) + { + for (var i = 1; i < hostText.Length; i++) + { + var ch = hostText[i]; + if (ch == ']') + { + // [::1] is the shortest valid IPv6 host + if (i < 4) + { + return false; + } + return IsValidHostPort(hostText, i + 1); + } + + if (!IsHex(ch) && ch != ':' && ch != '.') + { + return false; + } + } + + // Must contain a ']' + return false; + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static bool IsValidHostPort(string hostText, int offset) + { + if (offset == hostText.Length) + { + return true; + } + + if (hostText[offset] != ':' || hostText.Length == offset + 1) + { + // Must have at least one number after the colon if present. + return false; + } + + for (var i = offset + 1; i < hostText.Length; i++) + { + if (!IsNumeric(hostText[i])) + { + return false; + } + } + + return true; + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static bool IsNumeric(char ch) + { + return '0' <= ch && ch <= '9'; + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static bool IsHex(char ch) + { + return IsNumeric(ch) + || ('a' <= ch && ch <= 'f') + || ('A' <= ch && ch <= 'F'); + } } } diff --git a/test/Kestrel.Core.Tests/Http1ConnectionTests.cs b/test/Kestrel.Core.Tests/Http1ConnectionTests.cs index c4cac14b78..9d69dc79df 100644 --- a/test/Kestrel.Core.Tests/Http1ConnectionTests.cs +++ b/test/Kestrel.Core.Tests/Http1ConnectionTests.cs @@ -21,6 +21,7 @@ using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; using Microsoft.AspNetCore.Testing; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Primitives; +using Microsoft.Net.Http.Headers; using Moq; using Xunit; @@ -813,6 +814,55 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests mockMessageBody.Verify(body => body.ConsumeAsync(), Times.Once); } + [Fact] + public void Http10HostHeaderNotRequired() + { + _http1Connection.HttpVersion = "HTTP/1.0"; + _http1Connection.EnsureHostHeaderExists(); + } + + [Fact] + public void Http10HostHeaderAllowed() + { + _http1Connection.HttpVersion = "HTTP/1.0"; + _http1Connection.RequestHeaders[HeaderNames.Host] = "localhost:5000"; + _http1Connection.EnsureHostHeaderExists(); + } + + [Fact] + public void Http11EmptyHostHeaderAccepted() + { + _http1Connection.HttpVersion = "HTTP/1.1"; + _http1Connection.RequestHeaders[HeaderNames.Host] = ""; + _http1Connection.EnsureHostHeaderExists(); + } + + [Fact] + public void Http11ValidHostHeadersAccepted() + { + _http1Connection.HttpVersion = "HTTP/1.1"; + _http1Connection.RequestHeaders[HeaderNames.Host] = "localhost:5000"; + _http1Connection.EnsureHostHeaderExists(); + } + + [Fact] + public void BadRequestFor10BadHostHeaderFormat() + { + _http1Connection.HttpVersion = "HTTP/1.0"; + _http1Connection.RequestHeaders[HeaderNames.Host] = "a=b"; + var ex = Assert.Throws(() => _http1Connection.EnsureHostHeaderExists()); + Assert.Equal(CoreStrings.FormatBadRequest_InvalidHostHeader_Detail("a=b"), ex.Message); + } + + [Fact] + public void BadRequestFor11BadHostHeaderFormat() + { + _http1Connection.HttpVersion = "HTTP/1.1"; + _http1Connection.RequestHeaders[HeaderNames.Host] = "a=b"; + var ex = Assert.Throws(() => _http1Connection.EnsureHostHeaderExists()); + Assert.Equal(CoreStrings.FormatBadRequest_InvalidHostHeader_Detail("a=b"), ex.Message); + } + private static async Task WaitForCondition(TimeSpan timeout, Func condition) { const int MaxWaitLoop = 150; diff --git a/test/Kestrel.Core.Tests/Http2ConnectionTests.cs b/test/Kestrel.Core.Tests/Http2ConnectionTests.cs index 7766a9179b..46af33c2dc 100644 --- a/test/Kestrel.Core.Tests/Http2ConnectionTests.cs +++ b/test/Kestrel.Core.Tests/Http2ConnectionTests.cs @@ -20,6 +20,7 @@ using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2.HPack; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; using Microsoft.AspNetCore.Testing; +using Microsoft.Net.Http.Headers; using Xunit; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests @@ -33,6 +34,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests new KeyValuePair(":method", "POST"), new KeyValuePair(":path", "/"), new KeyValuePair(":scheme", "http"), + new KeyValuePair(":authority", "localhost:80"), }; private static readonly IEnumerable> _expectContinueRequestHeaders = new[] @@ -40,7 +42,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests new KeyValuePair(":method", "POST"), new KeyValuePair(":path", "/"), new KeyValuePair(":authority", "127.0.0.1"), - new KeyValuePair(":scheme", "https"), + new KeyValuePair(":scheme", "http"), new KeyValuePair("expect", "100-continue"), }; @@ -49,6 +51,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests new KeyValuePair(":method", "GET"), new KeyValuePair(":path", "/"), new KeyValuePair(":scheme", "http"), + new KeyValuePair(":authority", "localhost:80"), new KeyValuePair("user-agent", "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:54.0) Gecko/20100101 Firefox/54.0"), new KeyValuePair("accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"), new KeyValuePair("accept-language", "en-US,en;q=0.5"), @@ -67,6 +70,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests new KeyValuePair(":method", "GET"), new KeyValuePair(":path", "/"), new KeyValuePair(":scheme", "http"), + new KeyValuePair(":authority", "localhost:80"), new KeyValuePair("a", _largeHeaderValue), new KeyValuePair("b", _largeHeaderValue), new KeyValuePair("c", _largeHeaderValue), @@ -78,6 +82,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests new KeyValuePair(":method", "GET"), new KeyValuePair(":path", "/"), new KeyValuePair(":scheme", "http"), + new KeyValuePair(":authority", "localhost:80"), new KeyValuePair("a", _largeHeaderValue), new KeyValuePair("b", _largeHeaderValue), new KeyValuePair("c", _largeHeaderValue), @@ -110,6 +115,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests private readonly object _abortedStreamIdsLock = new object(); private readonly RequestDelegate _noopApplication; + private readonly RequestDelegate _echoHost; private readonly RequestDelegate _readHeadersApplication; private readonly RequestDelegate _readTrailersApplication; private readonly RequestDelegate _bufferingApplication; @@ -134,6 +140,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests _noopApplication = context => Task.CompletedTask; + _echoHost = context => + { + context.Response.Headers[HeaderNames.Host] = context.Request.Headers[HeaderNames.Host]; + + return Task.CompletedTask; + }; + _readHeadersApplication = context => { foreach (var header in context.Request.Headers) @@ -1178,6 +1191,311 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests await StopConnectionAsync(expectedLastStreamId: 1, ignoreNonGoAwayFrames: false); } + [Fact] + public async Task HEADERS_Received_InvalidAuthority_400Status() + { + var headers = new[] + { + new KeyValuePair(":method", "GET"), + new KeyValuePair(":path", "/"), + new KeyValuePair(":scheme", "http"), + new KeyValuePair(":authority", "local=host:80"), + }; + await InitializeConnectionAsync(_noopApplication); + + await StartStreamAsync(1, headers, endStream: true); + + var headersFrame = await ExpectAsync(Http2FrameType.HEADERS, + withLength: 55, + withFlags: (byte)Http2HeadersFrameFlags.END_HEADERS, + withStreamId: 1); + await ExpectAsync(Http2FrameType.DATA, + withLength: 0, + withFlags: (byte)Http2DataFrameFlags.END_STREAM, + withStreamId: 1); + + await StopConnectionAsync(expectedLastStreamId: 1, ignoreNonGoAwayFrames: false); + + _hpackDecoder.Decode(headersFrame.HeadersPayload, endHeaders: false, handler: this); + + Assert.Equal(3, _decodedHeaders.Count); + Assert.Contains("date", _decodedHeaders.Keys, StringComparer.OrdinalIgnoreCase); + Assert.Equal("400", _decodedHeaders[":status"]); + Assert.Equal("0", _decodedHeaders["content-length"]); + } + + [Fact] + public async Task HEADERS_Received_MissingAuthority_400Status() + { + var headers = new[] + { + new KeyValuePair(":method", "GET"), + new KeyValuePair(":path", "/"), + new KeyValuePair(":scheme", "http"), + }; + await InitializeConnectionAsync(_noopApplication); + + await StartStreamAsync(1, headers, endStream: true); + + var headersFrame = await ExpectAsync(Http2FrameType.HEADERS, + withLength: 55, + withFlags: (byte)Http2HeadersFrameFlags.END_HEADERS, + withStreamId: 1); + await ExpectAsync(Http2FrameType.DATA, + withLength: 0, + withFlags: (byte)Http2DataFrameFlags.END_STREAM, + withStreamId: 1); + + await StopConnectionAsync(expectedLastStreamId: 1, ignoreNonGoAwayFrames: false); + + _hpackDecoder.Decode(headersFrame.HeadersPayload, endHeaders: false, handler: this); + + Assert.Equal(3, _decodedHeaders.Count); + Assert.Contains("date", _decodedHeaders.Keys, StringComparer.OrdinalIgnoreCase); + Assert.Equal("400", _decodedHeaders[":status"]); + Assert.Equal("0", _decodedHeaders["content-length"]); + } + + [Fact] + public async Task HEADERS_Received_TwoHosts_400Status() + { + var headers = new[] + { + new KeyValuePair(":method", "GET"), + new KeyValuePair(":path", "/"), + new KeyValuePair(":scheme", "http"), + new KeyValuePair("Host", "host1"), + new KeyValuePair("Host", "host2"), + }; + await InitializeConnectionAsync(_noopApplication); + + await StartStreamAsync(1, headers, endStream: true); + + var headersFrame = await ExpectAsync(Http2FrameType.HEADERS, + withLength: 55, + withFlags: (byte)Http2HeadersFrameFlags.END_HEADERS, + withStreamId: 1); + await ExpectAsync(Http2FrameType.DATA, + withLength: 0, + withFlags: (byte)Http2DataFrameFlags.END_STREAM, + withStreamId: 1); + + await StopConnectionAsync(expectedLastStreamId: 1, ignoreNonGoAwayFrames: false); + + _hpackDecoder.Decode(headersFrame.HeadersPayload, endHeaders: false, handler: this); + + Assert.Equal(3, _decodedHeaders.Count); + Assert.Contains("date", _decodedHeaders.Keys, StringComparer.OrdinalIgnoreCase); + Assert.Equal("400", _decodedHeaders[":status"]); + Assert.Equal("0", _decodedHeaders["content-length"]); + } + + [Fact] + public async Task HEADERS_Received_EmptyAuthority_200Status() + { + var headers = new[] + { + new KeyValuePair(":method", "GET"), + new KeyValuePair(":path", "/"), + new KeyValuePair(":scheme", "http"), + new KeyValuePair(":authority", ""), + }; + await InitializeConnectionAsync(_noopApplication); + + await StartStreamAsync(1, headers, endStream: true); + + var headersFrame = await ExpectAsync(Http2FrameType.HEADERS, + withLength: 55, + withFlags: (byte)Http2HeadersFrameFlags.END_HEADERS, + withStreamId: 1); + await ExpectAsync(Http2FrameType.DATA, + withLength: 0, + withFlags: (byte)Http2DataFrameFlags.END_STREAM, + withStreamId: 1); + + await StopConnectionAsync(expectedLastStreamId: 1, ignoreNonGoAwayFrames: false); + + _hpackDecoder.Decode(headersFrame.HeadersPayload, endHeaders: false, handler: this); + + Assert.Equal(3, _decodedHeaders.Count); + Assert.Contains("date", _decodedHeaders.Keys, StringComparer.OrdinalIgnoreCase); + Assert.Equal("200", _decodedHeaders[":status"]); + Assert.Equal("0", _decodedHeaders["content-length"]); + } + + [Fact] + public async Task HEADERS_Received_EmptyAuthorityOverridesHost_200Status() + { + var headers = new[] + { + new KeyValuePair(":method", "GET"), + new KeyValuePair(":path", "/"), + new KeyValuePair(":scheme", "http"), + new KeyValuePair(":authority", ""), + new KeyValuePair("Host", "abc"), + }; + await InitializeConnectionAsync(_echoHost); + + await StartStreamAsync(1, headers, endStream: true); + + var headersFrame = await ExpectAsync(Http2FrameType.HEADERS, + withLength: 62, + withFlags: (byte)Http2HeadersFrameFlags.END_HEADERS, + withStreamId: 1); + await ExpectAsync(Http2FrameType.DATA, + withLength: 0, + withFlags: (byte)Http2DataFrameFlags.END_STREAM, + withStreamId: 1); + + await StopConnectionAsync(expectedLastStreamId: 1, ignoreNonGoAwayFrames: false); + + _hpackDecoder.Decode(headersFrame.HeadersPayload, endHeaders: false, handler: this); + + Assert.Equal(4, _decodedHeaders.Count); + Assert.Contains("date", _decodedHeaders.Keys, StringComparer.OrdinalIgnoreCase); + Assert.Equal("200", _decodedHeaders[":status"]); + Assert.Equal("0", _decodedHeaders[HeaderNames.ContentLength]); + Assert.Equal("", _decodedHeaders[HeaderNames.Host]); + } + + [Fact] + public async Task HEADERS_Received_AuthorityOverridesHost_200Status() + { + var headers = new[] + { + new KeyValuePair(":method", "GET"), + new KeyValuePair(":path", "/"), + new KeyValuePair(":scheme", "http"), + new KeyValuePair(":authority", "def"), + new KeyValuePair("Host", "abc"), + }; + await InitializeConnectionAsync(_echoHost); + + await StartStreamAsync(1, headers, endStream: true); + + var headersFrame = await ExpectAsync(Http2FrameType.HEADERS, + withLength: 65, + withFlags: (byte)Http2HeadersFrameFlags.END_HEADERS, + withStreamId: 1); + await ExpectAsync(Http2FrameType.DATA, + withLength: 0, + withFlags: (byte)Http2DataFrameFlags.END_STREAM, + withStreamId: 1); + + await StopConnectionAsync(expectedLastStreamId: 1, ignoreNonGoAwayFrames: false); + + _hpackDecoder.Decode(headersFrame.HeadersPayload, endHeaders: false, handler: this); + + Assert.Equal(4, _decodedHeaders.Count); + Assert.Contains("date", _decodedHeaders.Keys, StringComparer.OrdinalIgnoreCase); + Assert.Equal("200", _decodedHeaders[":status"]); + Assert.Equal("0", _decodedHeaders[HeaderNames.ContentLength]); + Assert.Equal("def", _decodedHeaders[HeaderNames.Host]); + } + + [Fact] + public async Task HEADERS_Received_MissingAuthorityFallsBackToHost_200Status() + { + var headers = new[] + { + new KeyValuePair(":method", "GET"), + new KeyValuePair(":path", "/"), + new KeyValuePair(":scheme", "http"), + new KeyValuePair("Host", "abc"), + }; + await InitializeConnectionAsync(_echoHost); + + await StartStreamAsync(1, headers, endStream: true); + + var headersFrame = await ExpectAsync(Http2FrameType.HEADERS, + withLength: 65, + withFlags: (byte)Http2HeadersFrameFlags.END_HEADERS, + withStreamId: 1); + await ExpectAsync(Http2FrameType.DATA, + withLength: 0, + withFlags: (byte)Http2DataFrameFlags.END_STREAM, + withStreamId: 1); + + await StopConnectionAsync(expectedLastStreamId: 1, ignoreNonGoAwayFrames: false); + + _hpackDecoder.Decode(headersFrame.HeadersPayload, endHeaders: false, handler: this); + + Assert.Equal(4, _decodedHeaders.Count); + Assert.Contains("date", _decodedHeaders.Keys, StringComparer.OrdinalIgnoreCase); + Assert.Equal("200", _decodedHeaders[":status"]); + Assert.Equal("0", _decodedHeaders[HeaderNames.ContentLength]); + Assert.Equal("abc", _decodedHeaders[HeaderNames.Host]); + } + + [Fact] + public async Task HEADERS_Received_AuthorityOverridesInvalidHost_200Status() + { + var headers = new[] + { + new KeyValuePair(":method", "GET"), + new KeyValuePair(":path", "/"), + new KeyValuePair(":scheme", "http"), + new KeyValuePair(":authority", "def"), + new KeyValuePair("Host", "a=bc"), + }; + await InitializeConnectionAsync(_echoHost); + + await StartStreamAsync(1, headers, endStream: true); + + var headersFrame = await ExpectAsync(Http2FrameType.HEADERS, + withLength: 65, + withFlags: (byte)Http2HeadersFrameFlags.END_HEADERS, + withStreamId: 1); + await ExpectAsync(Http2FrameType.DATA, + withLength: 0, + withFlags: (byte)Http2DataFrameFlags.END_STREAM, + withStreamId: 1); + + await StopConnectionAsync(expectedLastStreamId: 1, ignoreNonGoAwayFrames: false); + + _hpackDecoder.Decode(headersFrame.HeadersPayload, endHeaders: false, handler: this); + + Assert.Equal(4, _decodedHeaders.Count); + Assert.Contains("date", _decodedHeaders.Keys, StringComparer.OrdinalIgnoreCase); + Assert.Equal("200", _decodedHeaders[":status"]); + Assert.Equal("0", _decodedHeaders[HeaderNames.ContentLength]); + Assert.Equal("def", _decodedHeaders[HeaderNames.Host]); + } + + [Fact] + public async Task HEADERS_Received_InvalidAuthorityWithValidHost_400Status() + { + var headers = new[] + { + new KeyValuePair(":method", "GET"), + new KeyValuePair(":path", "/"), + new KeyValuePair(":scheme", "http"), + new KeyValuePair(":authority", "d=ef"), + new KeyValuePair("Host", "abc"), + }; + await InitializeConnectionAsync(_echoHost); + + await StartStreamAsync(1, headers, endStream: true); + + var headersFrame = await ExpectAsync(Http2FrameType.HEADERS, + withLength: 55, + withFlags: (byte)Http2HeadersFrameFlags.END_HEADERS, + withStreamId: 1); + await ExpectAsync(Http2FrameType.DATA, + withLength: 0, + withFlags: (byte)Http2DataFrameFlags.END_STREAM, + withStreamId: 1); + + await StopConnectionAsync(expectedLastStreamId: 1, ignoreNonGoAwayFrames: false); + + _hpackDecoder.Decode(headersFrame.HeadersPayload, endHeaders: false, handler: this); + + Assert.Equal(3, _decodedHeaders.Count); + Assert.Contains("date", _decodedHeaders.Keys, StringComparer.OrdinalIgnoreCase); + Assert.Equal("400", _decodedHeaders[":status"]); + Assert.Equal("0", _decodedHeaders[HeaderNames.ContentLength]); + } + [Fact] public async Task PRIORITY_Received_StreamIdZero_ConnectionError() { diff --git a/test/Kestrel.Core.Tests/HttpUtilitiesTest.cs b/test/Kestrel.Core.Tests/HttpUtilitiesTest.cs index 8966c181b0..d2c1233cee 100644 --- a/test/Kestrel.Core.Tests/HttpUtilitiesTest.cs +++ b/test/Kestrel.Core.Tests/HttpUtilitiesTest.cs @@ -131,5 +131,100 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests Assert.Equal(knownString1, expected); Assert.Same(knownString1, knownString2); } + + public static TheoryData HostHeaderData + { + get + { + return new TheoryData() { + "z", + "1", + "y:1", + "1:1", + "[ABCdef]", + "[abcDEF]:0", + "[abcdef:127.2355.1246.114]:0", + "[::1]:80", + "127.0.0.1:80", + "900.900.900.900:9523547852", + "foo", + "foo:234", + "foo.bar.baz", + "foo.BAR.baz:46245", + "foo.ba-ar.baz:46245", + "-foo:1234", + "xn--asdfaf:134", + "-", + "_", + "~", + "!", + "$", + "'", + "(", + ")", + }; + } + } + + [Theory] + [MemberData(nameof(HostHeaderData))] + public void ValidHostHeadersParsed(string host) + { + Assert.True(HttpUtilities.IsValidHostHeader(host)); + } + + public static TheoryData HostHeaderInvalidData + { + get + { + // see https://tools.ietf.org/html/rfc7230#section-5.4 + var data = new TheoryData() { + "[]", // Too short + "[::]", // Too short + "[ghijkl]", // Non-hex + "[afd:adf:123", // Incomplete + "[afd:adf]123", // Missing : + "[afd:adf]:", // Missing port digits + "[afd adf]", // Space + "[ad-314]", // dash + ":1234", // Missing host + "a:b:c", // Missing [] + "::1", // Missing [] + "::", // Missing everything + "abcd:1abcd", // Letters in port + "abcd:1.2", // Dot in port + "1.2.3.4:", // Missing port digits + "1.2 .4", // Space + }; + + // These aren't allowed anywhere in the host header + var invalid = "\"#%*+,/;<=>?@[]\\^`{}|"; + foreach (var ch in invalid) + { + data.Add(ch.ToString()); + } + + invalid = "!\"#$%&'()*+,/;<=>?@[]\\^_`{}|~-"; + foreach (var ch in invalid) + { + data.Add("[abd" + ch + "]:1234"); + } + + invalid = "!\"#$%&'()*+,/;<=>?@[]\\^_`{}|~:abcABC-."; + foreach (var ch in invalid) + { + data.Add("a.b.c:" + ch); + } + + return data; + } + } + + [Theory] + [MemberData(nameof(HostHeaderInvalidData))] + public void InvalidHostHeadersRejected(string host) + { + Assert.False(HttpUtilities.IsValidHostHeader(host)); + } } } \ No newline at end of file diff --git a/test/Kestrel.FunctionalTests/BadHttpRequestTests.cs b/test/Kestrel.FunctionalTests/BadHttpRequestTests.cs index 29b8164fc2..d01f81b347 100644 --- a/test/Kestrel.FunctionalTests/BadHttpRequestTests.cs +++ b/test/Kestrel.FunctionalTests/BadHttpRequestTests.cs @@ -132,6 +132,24 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests CoreStrings.FormatBadRequest_InvalidHostHeader_Detail(host.Trim())); } + [Fact] + public Task BadRequestFor10BadHostHeaderFormat() + { + return TestBadRequest( + $"GET / HTTP/1.0\r\nHost: a=b\r\n\r\n", + "400 Bad Request", + CoreStrings.FormatBadRequest_InvalidHostHeader_Detail("a=b")); + } + + [Fact] + public Task BadRequestFor11BadHostHeaderFormat() + { + return TestBadRequest( + $"GET / HTTP/1.1\r\nHost: a=b\r\n\r\n", + "400 Bad Request", + CoreStrings.FormatBadRequest_InvalidHostHeader_Detail("a=b")); + } + [Fact] public async Task BadRequestLogsAreNotHigherThanInformation() { diff --git a/test/Kestrel.FunctionalTests/RequestTests.cs b/test/Kestrel.FunctionalTests/RequestTests.cs index 8b712af1a2..673cf42ff8 100644 --- a/test/Kestrel.FunctionalTests/RequestTests.cs +++ b/test/Kestrel.FunctionalTests/RequestTests.cs @@ -603,7 +603,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { var requestTarget = new Uri(requestUrl, UriKind.Absolute); var host = requestTarget.Authority; - if (!requestTarget.IsDefaultPort) + if (requestTarget.IsDefaultPort) { host += ":" + requestTarget.Port; } diff --git a/tools/CodeGenerator/HttpUtilities/HttpUtilities.cs b/tools/CodeGenerator/HttpUtilities/HttpUtilities.cs index 7263d1fd16..0c70c0c188 100644 --- a/tools/CodeGenerator/HttpUtilities/HttpUtilities.cs +++ b/tools/CodeGenerator/HttpUtilities/HttpUtilities.cs @@ -84,6 +84,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure {{ {4} FillKnownMethodsGaps(); + InitializeHostCharValidity(); {5} }} From f6108928d829e414df01d10ed1c47edf35dc150b Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Tue, 13 Mar 2018 20:54:01 -0400 Subject: [PATCH 1567/1662] Pass ReadOnlySequence via in (#2389) * Pass ReadOnlySequence via in --- benchmarks/Kestrel.Performance/Mocks/NullParser.cs | 5 ++--- src/Kestrel.Core/Internal/Http/HttpParser.cs | 10 ++++------ src/Kestrel.Core/Internal/Http/IHttpParser.cs | 5 ++--- 3 files changed, 8 insertions(+), 12 deletions(-) diff --git a/benchmarks/Kestrel.Performance/Mocks/NullParser.cs b/benchmarks/Kestrel.Performance/Mocks/NullParser.cs index 99564a460b..556eaa7dbb 100644 --- a/benchmarks/Kestrel.Performance/Mocks/NullParser.cs +++ b/benchmarks/Kestrel.Performance/Mocks/NullParser.cs @@ -3,7 +3,6 @@ using System; using System.Buffers; -using System.Collections; using System.Text; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; @@ -22,7 +21,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance public static readonly NullParser Instance = new NullParser(); - public bool ParseHeaders(TRequestHandler handler, ReadOnlySequence buffer, out SequencePosition consumed, out SequencePosition examined, out int consumedBytes) + public bool ParseHeaders(TRequestHandler handler, in ReadOnlySequence buffer, out SequencePosition consumed, out SequencePosition examined, out int consumedBytes) { handler.OnHeader(new Span(_hostHeaderName), new Span(_hostHeaderValue)); handler.OnHeader(new Span(_acceptHeaderName), new Span(_acceptHeaderValue)); @@ -35,7 +34,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance return true; } - public bool ParseRequestLine(TRequestHandler handler, ReadOnlySequence buffer, out SequencePosition consumed, out SequencePosition examined) + public bool ParseRequestLine(TRequestHandler handler, in ReadOnlySequence buffer, out SequencePosition consumed, out SequencePosition examined) { handler.OnStartLine(HttpMethod.Get, HttpVersion.Http11, diff --git a/src/Kestrel.Core/Internal/Http/HttpParser.cs b/src/Kestrel.Core/Internal/Http/HttpParser.cs index 416976b8ac..594757eb4c 100644 --- a/src/Kestrel.Core/Internal/Http/HttpParser.cs +++ b/src/Kestrel.Core/Internal/Http/HttpParser.cs @@ -3,11 +3,9 @@ using System; using System.Buffers; -using System.Collections; using System.Diagnostics; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; -using Microsoft.AspNetCore.Protocols.Abstractions; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http @@ -34,7 +32,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http private const byte ByteQuestionMark = (byte)'?'; private const byte BytePercentage = (byte)'%'; - public unsafe bool ParseRequestLine(TRequestHandler handler, ReadOnlySequence buffer, out SequencePosition consumed, out SequencePosition examined) + public unsafe bool ParseRequestLine(TRequestHandler handler, in ReadOnlySequence buffer, out SequencePosition consumed, out SequencePosition examined) { consumed = buffer.Start; examined = buffer.End; @@ -52,7 +50,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http // No request line end return false; } - else if (TryGetNewLine(ref buffer, out var found)) + else if (TryGetNewLine(buffer, out var found)) { span = buffer.Slice(consumed, found).ToSpan(); consumed = found; @@ -189,7 +187,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http handler.OnStartLine(method, httpVersion, targetBuffer, pathBuffer, query, customMethod, pathEncoded); } - public unsafe bool ParseHeaders(TRequestHandler handler, ReadOnlySequence buffer, out SequencePosition consumed, out SequencePosition examined, out int consumedBytes) + public unsafe bool ParseHeaders(TRequestHandler handler, in ReadOnlySequence buffer, out SequencePosition consumed, out SequencePosition examined, out int consumedBytes) { consumed = buffer.Start; examined = buffer.End; @@ -419,7 +417,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http } [MethodImpl(MethodImplOptions.NoInlining)] - private static bool TryGetNewLine(ref ReadOnlySequence buffer, out SequencePosition found) + private static bool TryGetNewLine(in ReadOnlySequence buffer, out SequencePosition found) { var byteLfPosition = buffer.PositionOf(ByteLF); if (byteLfPosition != null) diff --git a/src/Kestrel.Core/Internal/Http/IHttpParser.cs b/src/Kestrel.Core/Internal/Http/IHttpParser.cs index 2cd77a3cd1..efd8e9445b 100644 --- a/src/Kestrel.Core/Internal/Http/IHttpParser.cs +++ b/src/Kestrel.Core/Internal/Http/IHttpParser.cs @@ -3,14 +3,13 @@ using System; using System.Buffers; -using System.Collections; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { public interface IHttpParser where TRequestHandler : IHttpHeadersHandler, IHttpRequestLineHandler { - bool ParseRequestLine(TRequestHandler handler, ReadOnlySequence buffer, out SequencePosition consumed, out SequencePosition examined); + bool ParseRequestLine(TRequestHandler handler, in ReadOnlySequence buffer, out SequencePosition consumed, out SequencePosition examined); - bool ParseHeaders(TRequestHandler handler, ReadOnlySequence buffer, out SequencePosition consumed, out SequencePosition examined, out int consumedBytes); + bool ParseHeaders(TRequestHandler handler, in ReadOnlySequence buffer, out SequencePosition consumed, out SequencePosition examined, out int consumedBytes); } } From 572627e88ce4db2ca2b3f18a200d5ff2a73fdead Mon Sep 17 00:00:00 2001 From: David Fowler Date: Tue, 13 Mar 2018 19:37:39 -0700 Subject: [PATCH 1568/1662] Handle posting to the libuv thread after StopAsync (#2388) - Check if the post handle is disposed and noop if it is. We also catch an ObjectDisposedException because it's an inherent race condition. --- .../Internal/LibuvThread.cs | 34 +++++++- .../LibuvThreadTests.cs | 77 +++++++++++++++++++ 2 files changed, 108 insertions(+), 3 deletions(-) create mode 100644 test/Kestrel.Transport.Libuv.Tests/LibuvThreadTests.cs diff --git a/src/Kestrel.Transport.Libuv/Internal/LibuvThread.cs b/src/Kestrel.Transport.Libuv/Internal/LibuvThread.cs index f26f656528..bb0f77ee95 100644 --- a/src/Kestrel.Transport.Libuv/Internal/LibuvThread.cs +++ b/src/Kestrel.Transport.Libuv/Internal/LibuvThread.cs @@ -177,11 +177,17 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal public void Post(Action callback, T state) { + // Handle is closed to don't bother scheduling anything + if (_post.IsClosed) + { + return; + } + var work = new Work { CallbackAdapter = CallbackAdapter.PostCallbackAdapter, Callback = callback, - //TODO: This boxes + // TODO: This boxes State = state }; @@ -189,7 +195,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal { _workAdding.Enqueue(work); } - _post.Send(); + + try + { + _post.Send(); + } + catch (ObjectDisposedException) + { + // There's an inherent race here where we're in the middle of shutdown + } } private void Post(Action callback) @@ -199,6 +213,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal public Task PostAsync(Action callback, T state) { + // Handle is closed to don't bother scheduling anything + if (_post.IsClosed) + { + return Task.CompletedTask; + } + var tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); var work = new Work { @@ -212,7 +232,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal { _workAdding.Enqueue(work); } - _post.Send(); + + try + { + _post.Send(); + } + catch (ObjectDisposedException) + { + // There's an inherent race here where we're in the middle of shutdown + } return tcs.Task; } diff --git a/test/Kestrel.Transport.Libuv.Tests/LibuvThreadTests.cs b/test/Kestrel.Transport.Libuv.Tests/LibuvThreadTests.cs new file mode 100644 index 0000000000..db3b3ebd8f --- /dev/null +++ b/test/Kestrel.Transport.Libuv.Tests/LibuvThreadTests.cs @@ -0,0 +1,77 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests.TestHelpers; +using Microsoft.AspNetCore.Testing; +using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Options; +using Moq; +using Xunit; + +namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests +{ + public class LibuvThreadTests + { + [Fact] + public async Task LibuvThreadDoesNotThrowIfPostingWorkAfterDispose() + { + var mockConnectionHandler = new MockConnectionHandler(); + var mockLibuv = new MockLibuv(); + var transportContext = new TestLibuvTransportContext() { ConnectionHandler = mockConnectionHandler }; + var transport = new LibuvTransport(mockLibuv, transportContext, null); + var thread = new LibuvThread(transport); + var ranOne = false; + var ranTwo = false; + var ranThree = false; + var ranFour = false; + + await thread.StartAsync(); + + await thread.PostAsync(_ => + { + ranOne = true; + }, + null); + + Assert.Equal(1, mockLibuv.PostCount); + + // Shutdown the libuv thread + await thread.StopAsync(TimeSpan.FromSeconds(5)); + + Assert.Equal(2, mockLibuv.PostCount); + + var task = thread.PostAsync(_ => + { + ranTwo = true; + }, + null); + + Assert.Equal(2, mockLibuv.PostCount); + + thread.Post(_ => + { + ranThree = true; + }, + null); + + Assert.Equal(2, mockLibuv.PostCount); + + thread.Schedule(_ => + { + ranFour = true; + }, + (object)null); + + Assert.Equal(2, mockLibuv.PostCount); + + Assert.True(task.IsCompleted); + Assert.True(ranOne); + Assert.False(ranTwo); + Assert.False(ranThree); + Assert.False(ranFour); + } + } +} From e65e58daf388e19398ab770a0e60b2a2ec58773e Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Wed, 14 Mar 2018 02:04:12 -0400 Subject: [PATCH 1569/1662] Reduce Sockets mainloop Send/Receive statemachine size (#2376) * Use Completion to Advance in Error * Drop ReadResult from statemachine --- .../Internal/SocketConnection.cs | 133 +++++++++--------- 1 file changed, 70 insertions(+), 63 deletions(-) diff --git a/src/Kestrel.Transport.Sockets/Internal/SocketConnection.cs b/src/Kestrel.Transport.Sockets/Internal/SocketConnection.cs index d932192165..a70ec03f46 100644 --- a/src/Kestrel.Transport.Sockets/Internal/SocketConnection.cs +++ b/src/Kestrel.Transport.Sockets/Internal/SocketConnection.cs @@ -19,7 +19,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal internal sealed class SocketConnection : TransportConnection { private const int MinAllocBufferSize = 2048; - public static bool IsWindows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows); + public readonly static bool IsWindows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows); private readonly Socket _socket; private readonly PipeScheduler _scheduler; @@ -104,41 +104,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal try { - while (true) - { - // Ensure we have some reasonable amount of buffer space - var buffer = Input.GetMemory(MinAllocBufferSize); - - var bytesReceived = await _receiver.ReceiveAsync(buffer); - - if (bytesReceived == 0) - { - // FIN - _trace.ConnectionReadFin(ConnectionId); - break; - } - - Input.Advance(bytesReceived); - - - var flushTask = Input.FlushAsync(); - - if (!flushTask.IsCompleted) - { - _trace.ConnectionPause(ConnectionId); - - await flushTask; - - _trace.ConnectionResume(ConnectionId); - } - - var result = flushTask.GetAwaiter().GetResult(); - if (result.IsCompleted) - { - // Pipe consumer is shut down, do we stop writing - break; - } - } + await ProcessReceives(); } catch (SocketException ex) when (ex.SocketErrorCode == SocketError.ConnectionReset) { @@ -186,39 +152,51 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal } } + private async Task ProcessReceives() + { + while (true) + { + // Ensure we have some reasonable amount of buffer space + var buffer = Input.GetMemory(MinAllocBufferSize); + + var bytesReceived = await _receiver.ReceiveAsync(buffer); + + if (bytesReceived == 0) + { + // FIN + _trace.ConnectionReadFin(ConnectionId); + break; + } + + Input.Advance(bytesReceived); + + var flushTask = Input.FlushAsync(); + + if (!flushTask.IsCompleted) + { + _trace.ConnectionPause(ConnectionId); + + await flushTask; + + _trace.ConnectionResume(ConnectionId); + } + + var result = flushTask.GetAwaiter().GetResult(); + if (result.IsCompleted) + { + // Pipe consumer is shut down, do we stop writing + break; + } + } + } + private async Task DoSend() { Exception error = null; try { - while (true) - { - // Wait for data to write from the pipe producer - var result = await Output.ReadAsync(); - var buffer = result.Buffer; - - if (result.IsCanceled) - { - break; - } - - try - { - if (!buffer.IsEmpty) - { - await _sender.SendAsync(buffer); - } - else if (result.IsCompleted) - { - break; - } - } - finally - { - Output.AdvanceTo(buffer.End); - } - } + await ProcessSends(); } catch (SocketException ex) when (ex.SocketErrorCode == SocketError.OperationAborted) { @@ -248,5 +226,34 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal return error; } + + private async Task ProcessSends() + { + while (true) + { + // Wait for data to write from the pipe producer + var result = await Output.ReadAsync(); + var buffer = result.Buffer; + + if (result.IsCanceled) + { + break; + } + + var end = buffer.End; + var isCompleted = result.IsCompleted; + if (!buffer.IsEmpty) + { + await _sender.SendAsync(buffer); + } + + Output.AdvanceTo(end); + + if (isCompleted) + { + break; + } + } + } } } From 04eef791bcbb30b2828f551e18671f035594e5ef Mon Sep 17 00:00:00 2001 From: David Fowler Date: Wed, 14 Mar 2018 08:16:38 -0700 Subject: [PATCH 1570/1662] Added transfer format to Protocol.Abstractions (#2391) --- .../Features/ITransferFormatFeature.cs | 11 +++++++++++ src/Protocols.Abstractions/TransferFormat.cs | 14 ++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 src/Protocols.Abstractions/Features/ITransferFormatFeature.cs create mode 100644 src/Protocols.Abstractions/TransferFormat.cs diff --git a/src/Protocols.Abstractions/Features/ITransferFormatFeature.cs b/src/Protocols.Abstractions/Features/ITransferFormatFeature.cs new file mode 100644 index 0000000000..72c262673f --- /dev/null +++ b/src/Protocols.Abstractions/Features/ITransferFormatFeature.cs @@ -0,0 +1,11 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +namespace Microsoft.AspNetCore.Protocols.Features +{ + public interface ITransferFormatFeature + { + TransferFormat SupportedFormats { get; } + TransferFormat ActiveFormat { get; set; } + } +} \ No newline at end of file diff --git a/src/Protocols.Abstractions/TransferFormat.cs b/src/Protocols.Abstractions/TransferFormat.cs new file mode 100644 index 0000000000..dd7cb28f64 --- /dev/null +++ b/src/Protocols.Abstractions/TransferFormat.cs @@ -0,0 +1,14 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; + +namespace Microsoft.AspNetCore.Protocols +{ + [Flags] + public enum TransferFormat + { + Binary = 0x01, + Text = 0x02 + } +} \ No newline at end of file From 9901f0f3e4f9bf7053fa7f4b072cb72d67bedb43 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Wed, 14 Mar 2018 11:50:10 -0700 Subject: [PATCH 1571/1662] Default to the managed socket transport (#2392) --- samples/SampleApp/SampleApp.csproj | 1 + samples/SystemdTestApp/SystemdTestApp.csproj | 1 + src/Kestrel/Kestrel.csproj | 3 --- src/Kestrel/WebHostBuilderKestrelExtensions.cs | 4 ++-- test/Kestrel.Tests/Kestrel.Tests.csproj | 1 + test/Kestrel.Tests/WebHostBuilderKestrelExtensionsTests.cs | 4 ++-- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/samples/SampleApp/SampleApp.csproj b/samples/SampleApp/SampleApp.csproj index 112987f619..036867ebc1 100644 --- a/samples/SampleApp/SampleApp.csproj +++ b/samples/SampleApp/SampleApp.csproj @@ -9,6 +9,7 @@ + diff --git a/samples/SystemdTestApp/SystemdTestApp.csproj b/samples/SystemdTestApp/SystemdTestApp.csproj index 08a5547858..28c159a38e 100644 --- a/samples/SystemdTestApp/SystemdTestApp.csproj +++ b/samples/SystemdTestApp/SystemdTestApp.csproj @@ -8,6 +8,7 @@ + diff --git a/src/Kestrel/Kestrel.csproj b/src/Kestrel/Kestrel.csproj index 55f910ddcf..f097863086 100644 --- a/src/Kestrel/Kestrel.csproj +++ b/src/Kestrel/Kestrel.csproj @@ -17,9 +17,6 @@ - - - diff --git a/src/Kestrel/WebHostBuilderKestrelExtensions.cs b/src/Kestrel/WebHostBuilderKestrelExtensions.cs index 70b1a34d74..6552da10f2 100644 --- a/src/Kestrel/WebHostBuilderKestrelExtensions.cs +++ b/src/Kestrel/WebHostBuilderKestrelExtensions.cs @@ -6,7 +6,7 @@ using Microsoft.AspNetCore.Hosting.Server; using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal; using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; -using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection.Extensions; using Microsoft.Extensions.Options; @@ -29,7 +29,7 @@ namespace Microsoft.AspNetCore.Hosting return hostBuilder.ConfigureServices(services => { // Don't override an already-configured transport - services.TryAddSingleton(); + services.TryAddSingleton(); services.AddTransient, KestrelServerOptionsSetup>(); services.AddSingleton(); diff --git a/test/Kestrel.Tests/Kestrel.Tests.csproj b/test/Kestrel.Tests/Kestrel.Tests.csproj index c26558bb08..d383f39603 100644 --- a/test/Kestrel.Tests/Kestrel.Tests.csproj +++ b/test/Kestrel.Tests/Kestrel.Tests.csproj @@ -13,6 +13,7 @@ + diff --git a/test/Kestrel.Tests/WebHostBuilderKestrelExtensionsTests.cs b/test/Kestrel.Tests/WebHostBuilderKestrelExtensionsTests.cs index 3c10c1c0ff..bc0eff8af8 100644 --- a/test/Kestrel.Tests/WebHostBuilderKestrelExtensionsTests.cs +++ b/test/Kestrel.Tests/WebHostBuilderKestrelExtensionsTests.cs @@ -51,13 +51,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Tests } [Fact] - public void LibuvIsTheDefaultTransport() + public void SocketTransportIsTheDefault() { var hostBuilder = new WebHostBuilder() .UseKestrel() .Configure(app => { }); - Assert.IsType(hostBuilder.Build().Services.GetService()); + Assert.IsType(hostBuilder.Build().Services.GetService()); } [Fact] From d31512528dd1d945b0eb7d6eefccb49647c4686f Mon Sep 17 00:00:00 2001 From: David Fowler Date: Wed, 14 Mar 2018 20:56:30 -0700 Subject: [PATCH 1572/1662] Items is now a first class property on ConnectionContext (#2395) * Metadata is now a first class property on ConnectionContext - Make IConnectionMetadata a manatory top level feature on ConnectionContext - TransportConnection will lazily manifest ConnectionMetadata on first access. This should avoid allocations since Kestrel isn't using this today. --- .../Internal/ConnectionItems.cs | 118 ++++++++++++++++++ .../Internal/TransportConnection.Features.cs | 31 +++++ .../Internal/TransportConnection.cs | 17 +++ .../ConnectionContext.cs | 5 +- .../DefaultConnectionContext.cs | 14 ++- ...aFeature.cs => IConnectionItemsFeature.cs} | 4 +- 6 files changed, 185 insertions(+), 4 deletions(-) create mode 100644 src/Kestrel.Transport.Abstractions/Internal/ConnectionItems.cs rename src/Protocols.Abstractions/Features/{IConnectionMetadataFeature.cs => IConnectionItemsFeature.cs} (72%) diff --git a/src/Kestrel.Transport.Abstractions/Internal/ConnectionItems.cs b/src/Kestrel.Transport.Abstractions/Internal/ConnectionItems.cs new file mode 100644 index 0000000000..adb346df81 --- /dev/null +++ b/src/Kestrel.Transport.Abstractions/Internal/ConnectionItems.cs @@ -0,0 +1,118 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Collections; +using System.Collections.Generic; + +namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal +{ + internal class ConnectionItems : IDictionary + { + public ConnectionItems() + : this(new Dictionary()) + { + } + + public ConnectionItems(IDictionary items) + { + Items = items; + } + + public IDictionary Items { get; } + + // Replace the indexer with one that returns null for missing values + object IDictionary.this[object key] + { + get + { + if (Items.TryGetValue(key, out var value)) + { + return value; + } + return null; + } + set { Items[key] = value; } + } + + void IDictionary.Add(object key, object value) + { + Items.Add(key, value); + } + + bool IDictionary.ContainsKey(object key) + { + return Items.ContainsKey(key); + } + + ICollection IDictionary.Keys + { + get { return Items.Keys; } + } + + bool IDictionary.Remove(object key) + { + return Items.Remove(key); + } + + bool IDictionary.TryGetValue(object key, out object value) + { + return Items.TryGetValue(key, out value); + } + + ICollection IDictionary.Values + { + get { return Items.Values; } + } + + void ICollection>.Add(KeyValuePair item) + { + Items.Add(item); + } + + void ICollection>.Clear() + { + Items.Clear(); + } + + bool ICollection>.Contains(KeyValuePair item) + { + return Items.Contains(item); + } + + void ICollection>.CopyTo(KeyValuePair[] array, int arrayIndex) + { + Items.CopyTo(array, arrayIndex); + } + + int ICollection>.Count + { + get { return Items.Count; } + } + + bool ICollection>.IsReadOnly + { + get { return Items.IsReadOnly; } + } + + bool ICollection>.Remove(KeyValuePair item) + { + object value; + if (Items.TryGetValue(item.Key, out value) && Equals(item.Value, value)) + { + return Items.Remove(item.Key); + } + return false; + } + + IEnumerator> IEnumerable>.GetEnumerator() + { + return Items.GetEnumerator(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return Items.GetEnumerator(); + } + } +} \ No newline at end of file diff --git a/src/Kestrel.Transport.Abstractions/Internal/TransportConnection.Features.cs b/src/Kestrel.Transport.Abstractions/Internal/TransportConnection.Features.cs index 9e91865b86..c9e316557f 100644 --- a/src/Kestrel.Transport.Abstractions/Internal/TransportConnection.Features.cs +++ b/src/Kestrel.Transport.Abstractions/Internal/TransportConnection.Features.cs @@ -13,6 +13,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal IHttpConnectionFeature, IConnectionIdFeature, IConnectionTransportFeature, + IConnectionItemsFeature, IMemoryPoolFeature, IApplicationTransportFeature, ITransportSchedulerFeature @@ -20,6 +21,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal private static readonly Type IHttpConnectionFeatureType = typeof(IHttpConnectionFeature); private static readonly Type IConnectionIdFeatureType = typeof(IConnectionIdFeature); private static readonly Type IConnectionTransportFeatureType = typeof(IConnectionTransportFeature); + private static readonly Type IConnectionItemsFeatureType = typeof(IConnectionItemsFeature); private static readonly Type IMemoryPoolFeatureType = typeof(IMemoryPoolFeature); private static readonly Type IApplicationTransportFeatureType = typeof(IApplicationTransportFeature); private static readonly Type ITransportSchedulerFeatureType = typeof(ITransportSchedulerFeature); @@ -27,6 +29,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal private object _currentIHttpConnectionFeature; private object _currentIConnectionIdFeature; private object _currentIConnectionTransportFeature; + private object _currentIConnectionItemsFeature; private object _currentIMemoryPoolFeature; private object _currentIApplicationTransportFeature; private object _currentITransportSchedulerFeature; @@ -118,6 +121,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal set => Application = value; } + IDictionary IConnectionItemsFeature.Items + { + get => Items; + set => Items = value; + } + PipeScheduler ITransportSchedulerFeature.InputWriterScheduler => InputWriterScheduler; PipeScheduler ITransportSchedulerFeature.OutputReaderScheduler => OutputReaderScheduler; @@ -140,6 +149,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal return _currentIConnectionTransportFeature; } + if (key == IConnectionItemsFeatureType) + { + return _currentIConnectionItemsFeature; + } + if (key == IMemoryPoolFeatureType) { return _currentIMemoryPoolFeature; @@ -178,6 +192,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal { _currentIConnectionTransportFeature = value; } + else if (key == IConnectionItemsFeatureType) + { + _currentIConnectionItemsFeature = value; + } else if (key == IMemoryPoolFeatureType) { _currentIMemoryPoolFeature = value; @@ -211,6 +229,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal { return (TFeature)_currentIConnectionTransportFeature; } + else if (typeof(TFeature) == typeof(IConnectionItemsFeature)) + { + return (TFeature)_currentIConnectionItemsFeature; + } else if (typeof(TFeature) == typeof(IMemoryPoolFeature)) { return (TFeature)_currentIMemoryPoolFeature; @@ -247,6 +269,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal { _currentIConnectionTransportFeature = instance; } + else if (typeof(TFeature) == typeof(IConnectionItemsFeature)) + { + _currentIConnectionItemsFeature = instance; + } else if (typeof(TFeature) == typeof(IMemoryPoolFeature)) { _currentIMemoryPoolFeature = instance; @@ -286,6 +312,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal yield return new KeyValuePair(IConnectionTransportFeatureType, _currentIConnectionTransportFeature); } + if (_currentIConnectionItemsFeature != null) + { + yield return new KeyValuePair(IConnectionItemsFeatureType, _currentIConnectionItemsFeature); + } + if (_currentIMemoryPoolFeature != null) { yield return new KeyValuePair(IMemoryPoolFeatureType, _currentIMemoryPoolFeature); diff --git a/src/Kestrel.Transport.Abstractions/Internal/TransportConnection.cs b/src/Kestrel.Transport.Abstractions/Internal/TransportConnection.cs index bfe7e53458..b753dae64a 100644 --- a/src/Kestrel.Transport.Abstractions/Internal/TransportConnection.cs +++ b/src/Kestrel.Transport.Abstractions/Internal/TransportConnection.cs @@ -1,4 +1,5 @@ using System.Buffers; +using System.Collections.Generic; using System.IO.Pipelines; using System.Net; using System.Threading; @@ -7,11 +8,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal { public abstract partial class TransportConnection { + private IDictionary _items; + public TransportConnection() { _currentIConnectionIdFeature = this; _currentIConnectionTransportFeature = this; _currentIHttpConnectionFeature = this; + _currentIConnectionItemsFeature = this; _currentIApplicationTransportFeature = this; _currentIMemoryPoolFeature = this; _currentITransportSchedulerFeature = this; @@ -31,6 +35,19 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal public IDuplexPipe Transport { get; set; } public IDuplexPipe Application { get; set; } + public IDictionary Items + { + get + { + // Lazily allocate connection metadata + return _items ?? (_items = new ConnectionItems()); + } + set + { + _items = value; + } + } + public PipeWriter Input => Application.Output; public PipeReader Output => Application.Input; } diff --git a/src/Protocols.Abstractions/ConnectionContext.cs b/src/Protocols.Abstractions/ConnectionContext.cs index 329afa4b11..f8175d3897 100644 --- a/src/Protocols.Abstractions/ConnectionContext.cs +++ b/src/Protocols.Abstractions/ConnectionContext.cs @@ -1,4 +1,5 @@ -using System.IO.Pipelines; +using System.Collections.Generic; +using System.IO.Pipelines; using Microsoft.AspNetCore.Http.Features; namespace Microsoft.AspNetCore.Protocols @@ -9,6 +10,8 @@ namespace Microsoft.AspNetCore.Protocols public abstract IFeatureCollection Features { get; } + public abstract IDictionary Items { get; set; } + public abstract IDuplexPipe Transport { get; set; } } } diff --git a/src/Protocols.Abstractions/DefaultConnectionContext.cs b/src/Protocols.Abstractions/DefaultConnectionContext.cs index d38657061c..6959062e69 100644 --- a/src/Protocols.Abstractions/DefaultConnectionContext.cs +++ b/src/Protocols.Abstractions/DefaultConnectionContext.cs @@ -1,4 +1,5 @@ -using System.IO.Pipelines; +using System.Collections.Generic; +using System.IO.Pipelines; using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Protocols.Features; @@ -19,6 +20,9 @@ namespace Microsoft.AspNetCore.Protocols private IConnectionTransportFeature ConnectionTransportFeature => _features.Fetch(ref _features.Cache.ConnectionTransport, _ => null); + private IConnectionItemsFeature ConnectionItemsFeature => + _features.Fetch(ref _features.Cache.ConnectionItems, _ => null); + public override string ConnectionId { get => ConnectionIdFeature.ConnectionId; @@ -33,11 +37,19 @@ namespace Microsoft.AspNetCore.Protocols set => ConnectionTransportFeature.Transport = value; } + public override IDictionary Items + { + get => ConnectionItemsFeature.Items; + set => ConnectionItemsFeature.Items = value; + } + struct FeatureInterfaces { public IConnectionIdFeature ConnectionId; public IConnectionTransportFeature ConnectionTransport; + + public IConnectionItemsFeature ConnectionItems; } } } diff --git a/src/Protocols.Abstractions/Features/IConnectionMetadataFeature.cs b/src/Protocols.Abstractions/Features/IConnectionItemsFeature.cs similarity index 72% rename from src/Protocols.Abstractions/Features/IConnectionMetadataFeature.cs rename to src/Protocols.Abstractions/Features/IConnectionItemsFeature.cs index b2e0f67789..136006b5a3 100644 --- a/src/Protocols.Abstractions/Features/IConnectionMetadataFeature.cs +++ b/src/Protocols.Abstractions/Features/IConnectionItemsFeature.cs @@ -6,8 +6,8 @@ using System.Collections.Generic; namespace Microsoft.AspNetCore.Protocols.Features { - public interface IConnectionMetadataFeature + public interface IConnectionItemsFeature { - IDictionary Metadata { get; set; } + IDictionary Items { get; set; } } } \ No newline at end of file From 181dc0de24e246dd0dd41621ea4b9a16fc81f437 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Mon, 12 Mar 2018 23:03:17 -0700 Subject: [PATCH 1573/1662] React to pipelines changes --- build/dependencies.props | 54 +++++++++---------- .../Internal/LibuvThread.cs | 2 +- .../Internal/IOQueue.cs | 8 ++- .../Internal/SocketAwaitable.cs | 2 +- 4 files changed, 32 insertions(+), 34 deletions(-) diff --git a/build/dependencies.props b/build/dependencies.props index ad5d09463e..6916e0189a 100644 --- a/build/dependencies.props +++ b/build/dependencies.props @@ -7,38 +7,38 @@ 0.10.11 2.1.0-preview2-15728 1.10.0 - 2.1.0-preview2-30272 - 2.1.0-preview2-30272 - 2.1.0-preview2-30272 - 2.1.0-preview2-30272 - 2.1.0-preview2-30272 - 2.1.0-preview2-30272 - 2.1.0-preview2-30272 - 2.1.0-preview2-30272 - 2.1.0-preview2-30272 - 2.1.0-preview2-pk-corefx0-16426 - 2.1.0-preview2-pk-corefx0-16426 - 2.1.0-preview2-30272 - 2.1.0-preview2-30272 - 2.1.0-preview2-30272 - 2.1.0-preview2-30272 - 2.1.0-preview2-30272 - 2.1.0-preview2-30272 - 2.1.0-preview2-30272 - 2.1.0-preview2-30272 + 2.1.0-preview2-30301 + 2.1.0-preview2-30301 + 2.1.0-preview2-30301 + 2.1.0-preview2-30301 + 2.1.0-preview2-30301 + 2.1.0-preview2-30301 + 2.1.0-preview2-30301 + 2.1.0-preview2-30301 + 2.1.0-preview2-30301 + 2.1.0-preview2-30301 + 2.1.0-preview2-30301 + 2.1.0-preview2-30301 + 2.1.0-preview2-30301 + 2.1.0-preview2-30301 + 2.1.0-preview2-30301 + 2.1.0-preview2-30301 + 2.1.0-preview2-30301 + 2.1.0-preview2-30301 + 2.1.0-preview2-30301 2.0.0 2.1.0-preview2-26308-01 - 2.1.0-preview2-30272 + 2.1.0-preview2-30301 15.6.0 4.7.49 10.0.1 - 4.5.0-preview2-26308-02 - 4.5.0-preview2-26308-02 - 4.5.0-preview2-26308-02 - 4.5.0-preview2-26308-02 - 4.5.0-preview2-26308-02 - 4.5.0-preview2-26308-02 - 4.5.0-preview2-26308-02 + 4.5.0-preview2-26313-02 + 4.5.0-preview2-26313-02 + 4.5.0-preview2-26313-02 + 4.5.0-preview2-26313-02 + 4.5.0-preview2-26313-02 + 4.5.0-preview2-26313-02 + 4.5.0-preview2-26313-02 0.8.0 2.3.1 2.4.0-beta.1.build3945 diff --git a/src/Kestrel.Transport.Libuv/Internal/LibuvThread.cs b/src/Kestrel.Transport.Libuv/Internal/LibuvThread.cs index bb0f77ee95..1e621f401b 100644 --- a/src/Kestrel.Transport.Libuv/Internal/LibuvThread.cs +++ b/src/Kestrel.Transport.Libuv/Internal/LibuvThread.cs @@ -424,7 +424,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal return await Task.WhenAny(task, Task.Delay(timeout)).ConfigureAwait(false) == task; } - public override void Schedule(Action action, T state) + public override void Schedule(Action action, object state) { Post(action, state); } diff --git a/src/Kestrel.Transport.Sockets/Internal/IOQueue.cs b/src/Kestrel.Transport.Sockets/Internal/IOQueue.cs index 49b6b3e668..6a3e60d1ac 100644 --- a/src/Kestrel.Transport.Sockets/Internal/IOQueue.cs +++ b/src/Kestrel.Transport.Sockets/Internal/IOQueue.cs @@ -16,11 +16,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal private readonly ConcurrentQueue _workItems = new ConcurrentQueue(); private bool _doingWork; - public override void Schedule(Action action, T state) + public override void Schedule(Action action, object state) { var work = new Work { - CallbackAdapter = (c, s) => ((Action)c)((T)s), Callback = action, State = state }; @@ -43,7 +42,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal { while (_workItems.TryDequeue(out Work item)) { - item.CallbackAdapter(item.Callback, item.State); + item.Callback(item.State); } lock (_workSync) @@ -59,8 +58,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal private struct Work { - public Action CallbackAdapter; - public object Callback; + public Action Callback; public object State; } } diff --git a/src/Kestrel.Transport.Sockets/Internal/SocketAwaitable.cs b/src/Kestrel.Transport.Sockets/Internal/SocketAwaitable.cs index f266033a36..1da07c9375 100644 --- a/src/Kestrel.Transport.Sockets/Internal/SocketAwaitable.cs +++ b/src/Kestrel.Transport.Sockets/Internal/SocketAwaitable.cs @@ -64,7 +64,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal if (continuation != null) { - _ioScheduler.Schedule(c => c(), continuation); + _ioScheduler.Schedule(state => ((Action)state)(), continuation); } } } From acf7584d136b0296544d69a0607af8cffa370a1f Mon Sep 17 00:00:00 2001 From: Javier Calvarro Nelson Date: Thu, 15 Mar 2018 16:55:43 -0700 Subject: [PATCH 1574/1662] Reenable API Check --- src/Kestrel.Transport.Sockets/Kestrel.Transport.Sockets.csproj | 1 - src/Protocols.Abstractions/Protocols.Abstractions.csproj | 1 - 2 files changed, 2 deletions(-) diff --git a/src/Kestrel.Transport.Sockets/Kestrel.Transport.Sockets.csproj b/src/Kestrel.Transport.Sockets/Kestrel.Transport.Sockets.csproj index 8e065c4828..8af8305852 100644 --- a/src/Kestrel.Transport.Sockets/Kestrel.Transport.Sockets.csproj +++ b/src/Kestrel.Transport.Sockets/Kestrel.Transport.Sockets.csproj @@ -9,7 +9,6 @@ aspnetcore;kestrel true CS1591;$(NoWarn) - false diff --git a/src/Protocols.Abstractions/Protocols.Abstractions.csproj b/src/Protocols.Abstractions/Protocols.Abstractions.csproj index ac03b392b4..cd52227801 100644 --- a/src/Protocols.Abstractions/Protocols.Abstractions.csproj +++ b/src/Protocols.Abstractions/Protocols.Abstractions.csproj @@ -9,7 +9,6 @@ aspnetcore true CS1591;$(NoWarn) - false From 2527face168cd24d5a9d685bbbbfdd9b26898ada Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Fri, 16 Mar 2018 02:55:51 -0400 Subject: [PATCH 1575/1662] Query EndPoints once during reset (#2398) --- src/Kestrel.Core/Internal/Http/HttpProtocol.cs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/Kestrel.Core/Internal/Http/HttpProtocol.cs b/src/Kestrel.Core/Internal/Http/HttpProtocol.cs index 30679f525b..01bde85605 100644 --- a/src/Kestrel.Core/Internal/Http/HttpProtocol.cs +++ b/src/Kestrel.Core/Internal/Http/HttpProtocol.cs @@ -335,11 +335,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http _statusCode = StatusCodes.Status200OK; _reasonPhrase = null; - RemoteIpAddress = RemoteEndPoint?.Address; - RemotePort = RemoteEndPoint?.Port ?? 0; + var remoteEndPoint = RemoteEndPoint; + RemoteIpAddress = remoteEndPoint?.Address; + RemotePort = remoteEndPoint?.Port ?? 0; + + var localEndPoint = LocalEndPoint; + LocalIpAddress = localEndPoint?.Address; + LocalPort = localEndPoint?.Port ?? 0; - LocalIpAddress = LocalEndPoint?.Address; - LocalPort = LocalEndPoint?.Port ?? 0; ConnectionIdFeature = ConnectionId; HttpRequestHeaders.Reset(); From e3abaa558c4fc4a47f0413f0e32110cd35278e27 Mon Sep 17 00:00:00 2001 From: Pranav K Date: Fri, 16 Mar 2018 09:41:41 -0700 Subject: [PATCH 1576/1662] Enable dotnet-build bot --- build/buildpipeline/linux.groovy | 10 ++++++++++ build/buildpipeline/osx.groovy | 10 ++++++++++ build/buildpipeline/pipeline.groovy | 18 ++++++++++++++++++ build/buildpipeline/windows.groovy | 12 ++++++++++++ korebuild-lock.txt | 4 ++-- run.ps1 | 16 ++++++++++++++-- run.sh | 16 +++++++++++++++- 7 files changed, 81 insertions(+), 5 deletions(-) create mode 100644 build/buildpipeline/linux.groovy create mode 100644 build/buildpipeline/osx.groovy create mode 100644 build/buildpipeline/pipeline.groovy create mode 100644 build/buildpipeline/windows.groovy diff --git a/build/buildpipeline/linux.groovy b/build/buildpipeline/linux.groovy new file mode 100644 index 0000000000..903f218bb8 --- /dev/null +++ b/build/buildpipeline/linux.groovy @@ -0,0 +1,10 @@ +@Library('dotnet-ci') _ + +simpleNode('Ubuntu16.04', 'latest-or-auto-docker') { + stage ('Checking out source') { + checkout scm + } + stage ('Build') { + sh './build.sh --ci' + } +} diff --git a/build/buildpipeline/osx.groovy b/build/buildpipeline/osx.groovy new file mode 100644 index 0000000000..aaac63686b --- /dev/null +++ b/build/buildpipeline/osx.groovy @@ -0,0 +1,10 @@ +@Library('dotnet-ci') _ + +simpleNode('OSX10.12','latest') { + stage ('Checking out source') { + checkout scm + } + stage ('Build') { + sh './build.sh --ci' + } +} diff --git a/build/buildpipeline/pipeline.groovy b/build/buildpipeline/pipeline.groovy new file mode 100644 index 0000000000..e915cadae1 --- /dev/null +++ b/build/buildpipeline/pipeline.groovy @@ -0,0 +1,18 @@ +import org.dotnet.ci.pipelines.Pipeline + +def windowsPipeline = Pipeline.createPipeline(this, 'build/buildpipeline/windows.groovy') +def linuxPipeline = Pipeline.createPipeline(this, 'build/buildpipeline/linux.groovy') +def osxPipeline = Pipeline.createPipeline(this, 'build/buildpipeline/osx.groovy') +String configuration = 'Release' +def parameters = [ + 'Configuration': configuration +] + +windowsPipeline.triggerPipelineOnEveryGithubPR("Windows ${configuration} x64 Build", parameters) +windowsPipeline.triggerPipelineOnGithubPush(parameters) + +linuxPipeline.triggerPipelineOnEveryGithubPR("Ubuntu 16.04 ${configuration} Build", parameters) +linuxPipeline.triggerPipelineOnGithubPush(parameters) + +osxPipeline.triggerPipelineOnEveryGithubPR("OSX 10.12 ${configuration} Build", parameters) +osxPipeline.triggerPipelineOnGithubPush(parameters) diff --git a/build/buildpipeline/windows.groovy b/build/buildpipeline/windows.groovy new file mode 100644 index 0000000000..8d26f313d4 --- /dev/null +++ b/build/buildpipeline/windows.groovy @@ -0,0 +1,12 @@ +@Library('dotnet-ci') _ + +// 'node' indicates to Jenkins that the enclosed block runs on a node that matches +// the label 'windows-with-vs' +simpleNode('Windows_NT','latest') { + stage ('Checking out source') { + checkout scm + } + stage ('Build') { + bat '.\\run.cmd -CI default-build' + } +} diff --git a/korebuild-lock.txt b/korebuild-lock.txt index 138d848db1..e40ef6651b 100644 --- a/korebuild-lock.txt +++ b/korebuild-lock.txt @@ -1,2 +1,2 @@ -version:2.1.0-preview2-15728 -commithash:393377068ddcf51dfee0536536d455f57a828b06 +version:2.1.0-preview2-15742 +commithash:21fbb0f2c3fe4a9216e2d59632b98cfd7d685962 diff --git a/run.ps1 b/run.ps1 index 27dcf848f8..96c6c54c69 100644 --- a/run.ps1 +++ b/run.ps1 @@ -26,12 +26,18 @@ The base url where build tools can be downloaded. Overrides the value from the c .PARAMETER Update Updates KoreBuild to the latest version even if a lock file is present. +.PARAMETER Reinstall +Re-installs KoreBuild + .PARAMETER ConfigFile The path to the configuration file that stores values. Defaults to korebuild.json. .PARAMETER ToolsSourceSuffix The Suffix to append to the end of the ToolsSource. Useful for query strings in blob stores. +.PARAMETER CI +Sets up CI specific settings and variables. + .PARAMETER Arguments Arguments to be passed to the command @@ -65,8 +71,10 @@ param( [string]$ToolsSource, [Alias('u')] [switch]$Update, - [string]$ConfigFile, + [switch]$Reinstall, [string]$ToolsSourceSuffix, + [string]$ConfigFile = $null, + [switch]$CI, [Parameter(ValueFromRemainingArguments = $true)] [string[]]$Arguments ) @@ -93,6 +101,10 @@ function Get-KoreBuild { $version = $version.TrimStart('version:').Trim() $korebuildPath = Join-Paths $DotNetHome ('buildtools', 'korebuild', $version) + if ($Reinstall -and (Test-Path $korebuildPath)) { + Remove-Item -Force -Recurse $korebuildPath + } + if (!(Test-Path $korebuildPath)) { Write-Host -ForegroundColor Magenta "Downloading KoreBuild $version" New-Item -ItemType Directory -Path $korebuildPath | Out-Null @@ -188,7 +200,7 @@ $korebuildPath = Get-KoreBuild Import-Module -Force -Scope Local (Join-Path $korebuildPath 'KoreBuild.psd1') try { - Set-KoreBuildSettings -ToolsSource $ToolsSource -DotNetHome $DotNetHome -RepoPath $Path -ConfigFile $ConfigFile + Set-KoreBuildSettings -ToolsSource $ToolsSource -DotNetHome $DotNetHome -RepoPath $Path -ConfigFile $ConfigFile -CI:$CI Invoke-KoreBuildCommand $Command @Arguments } finally { diff --git a/run.sh b/run.sh index 834961fc3a..4606a42e78 100755 --- a/run.sh +++ b/run.sh @@ -14,10 +14,12 @@ DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" [ -z "${DOTNET_HOME:-}" ] && DOTNET_HOME="$HOME/.dotnet" verbose=false update=false +reinstall=false repo_path="$DIR" channel='' tools_source='' tools_source_suffix='' +ci=false # # Functions @@ -38,6 +40,8 @@ __usage() { echo " -s|--tools-source|-ToolsSource The base url where build tools can be downloaded. Overrides the value from the config file." echo " --tools-source-suffix|-ToolsSourceSuffix The suffix to append to tools-source. Useful for query strings." echo " -u|--update Update to the latest KoreBuild even if the lock file is present." + echo " --reinstall Reinstall KoreBuild." + echo " --ci Apply CI specific settings and environment variables." echo "" echo "Description:" echo " This function will create a file \$DIR/korebuild-lock.txt. This lock file can be committed to source, but does not have to be." @@ -62,6 +66,10 @@ get_korebuild() { version="$(echo "${version#version:}" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')" local korebuild_path="$DOTNET_HOME/buildtools/korebuild/$version" + if [ "$reinstall" = true ] && [ -d "$korebuild_path" ]; then + rm -rf "$korebuild_path" + fi + { if [ ! -d "$korebuild_path" ]; then mkdir -p "$korebuild_path" @@ -175,6 +183,12 @@ while [[ $# -gt 0 ]]; do -u|--update|-Update) update=true ;; + --reinstall|-[Rr]einstall) + reinstall=true + ;; + --ci) + ci=true + ;; --verbose|-Verbose) verbose=true ;; @@ -227,5 +241,5 @@ fi [ -z "$tools_source" ] && tools_source='https://aspnetcore.blob.core.windows.net/buildtools' get_korebuild -set_korebuildsettings "$tools_source" "$DOTNET_HOME" "$repo_path" "$config_file" +set_korebuildsettings "$tools_source" "$DOTNET_HOME" "$repo_path" "$config_file" "$ci" invoke_korebuild_command "$command" "$@" From c4f02a0390a2d782e428f350daf0ee13748f5c7c Mon Sep 17 00:00:00 2001 From: Pranav K Date: Fri, 16 Mar 2018 10:02:25 -0700 Subject: [PATCH 1577/1662] Update Travis and AppVeyor to use CI flag --- .appveyor.yml | 6 +----- .travis.yml | 6 +----- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/.appveyor.yml b/.appveyor.yml index 4eea96ab69..1f412bf6b5 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -6,12 +6,8 @@ branches: - /^release\/.*$/ - /^(.*\/)?ci-.*$/ build_script: -- ps: .\run.ps1 default-build +- ps: .\run.ps1 -ci default-build clone_depth: 1 -environment: - global: - DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true - DOTNET_CLI_TELEMETRY_OPTOUT: 1 test: 'off' deploy: 'off' os: Visual Studio 2017 diff --git a/.travis.yml b/.travis.yml index ccbc068a62..3b3d7d726b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,10 +7,6 @@ addons: apt: packages: - libunwind8 -env: - global: - - DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true - - DOTNET_CLI_TELEMETRY_OPTOUT: 1 mono: none os: - linux @@ -26,6 +22,6 @@ before_install: /usr/local/opt/openssl/lib/libcrypto.1.0.0.dylib /usr/local/lib/; ln -s /usr/local/opt/openssl/lib/libssl.1.0.0.dylib /usr/local/lib/; fi script: -- ./build.sh +- ./build.sh --ci - if test "$TRAVIS_OS_NAME" != "osx"; then bash test/SystemdActivation/docker.sh; fi From 3584e5f2ab226bd9f6a51c0ef507ea3f1daf3c3a Mon Sep 17 00:00:00 2001 From: Ryan Brandenburg Date: Wed, 14 Mar 2018 15:34:26 -0700 Subject: [PATCH 1578/1662] Set 2.0 baselines --- src/Kestrel.Core/baseline.netcore.json | 9068 +---------------- src/Kestrel.Https/baseline.netcore.json | 68 +- .../baseline.netcore.json | 6444 +----------- .../baseline.netcore.json | 5607 +--------- .../baseline.netcore.json | 10 +- src/Kestrel/baseline.netcore.json | 2 +- 6 files changed, 7 insertions(+), 21192 deletions(-) diff --git a/src/Kestrel.Core/baseline.netcore.json b/src/Kestrel.Core/baseline.netcore.json index d838507d33..7a583ce888 100644 --- a/src/Kestrel.Core/baseline.netcore.json +++ b/src/Kestrel.Core/baseline.netcore.json @@ -1,5 +1,5 @@ { - "AssemblyIdentity": "Microsoft.AspNetCore.Server.Kestrel.Core, Version=2.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60", + "AssemblyIdentity": "Microsoft.AspNetCore.Server.Kestrel.Core, Version=2.0.2.0, Culture=neutral, PublicKeyToken=adb9793829ddae60", "Types": [ { "Name": "Microsoft.AspNetCore.Hosting.ListenOptionsConnectionLoggingExtensions", @@ -1012,8397 +1012,6 @@ ], "GenericParameters": [] }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.ConnectionHandler", - "Visibility": "Public", - "Kind": "Class", - "ImplementedInterfaces": [ - "Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal.IConnectionHandler" - ], - "Members": [ - { - "Kind": "Method", - "Name": "OnConnection", - "Parameters": [ - { - "Name": "connectionInfo", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal.IConnectionInformation" - } - ], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal.IConnectionContext", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal.IConnectionHandler", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "listenOptions", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Core.ListenOptions" - }, - { - "Name": "serviceContext", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.ServiceContext" - }, - { - "Name": "application", - "Type": "Microsoft.AspNetCore.Hosting.Server.IHttpApplication" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [ - { - "ParameterName": "TContext", - "ParameterPosition": 0, - "BaseTypeOrInterfaces": [] - } - ] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.FrameConnection", - "Visibility": "Public", - "Kind": "Class", - "ImplementedInterfaces": [ - "Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal.IConnectionContext", - "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure.ITimeoutControl" - ], - "Members": [ - { - "Kind": "Method", - "Name": "get_TimedOut", - "Parameters": [], - "ReturnType": "System.Boolean", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure.ITimeoutControl", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_ConnectionId", - "Parameters": [], - "ReturnType": "System.String", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal.IConnectionContext", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_Input", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.IPipeWriter", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal.IConnectionContext", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_Output", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.IPipeReader", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal.IConnectionContext", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "StartRequestProcessing", - "Parameters": [ - { - "Name": "application", - "Type": "Microsoft.AspNetCore.Hosting.Server.IHttpApplication" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [ - { - "ParameterName": "TContext", - "ParameterPosition": 0, - "BaseTypeOrInterfaces": [] - } - ] - }, - { - "Kind": "Method", - "Name": "OnConnectionClosed", - "Parameters": [ - { - "Name": "ex", - "Type": "System.Exception" - } - ], - "ReturnType": "System.Void", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal.IConnectionContext", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "StopAsync", - "Parameters": [], - "ReturnType": "System.Threading.Tasks.Task", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Abort", - "Parameters": [ - { - "Name": "ex", - "Type": "System.Exception" - } - ], - "ReturnType": "System.Void", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal.IConnectionContext", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "AbortAsync", - "Parameters": [ - { - "Name": "ex", - "Type": "System.Exception" - } - ], - "ReturnType": "System.Threading.Tasks.Task", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "SetTimeoutResponse", - "Parameters": [], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Timeout", - "Parameters": [], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Tick", - "Parameters": [ - { - "Name": "now", - "Type": "System.DateTimeOffset" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "SetTimeout", - "Parameters": [ - { - "Name": "ticks", - "Type": "System.Int64" - }, - { - "Name": "timeoutAction", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure.TimeoutAction" - } - ], - "ReturnType": "System.Void", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure.ITimeoutControl", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ResetTimeout", - "Parameters": [ - { - "Name": "ticks", - "Type": "System.Int64" - }, - { - "Name": "timeoutAction", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure.TimeoutAction" - } - ], - "ReturnType": "System.Void", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure.ITimeoutControl", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "CancelTimeout", - "Parameters": [], - "ReturnType": "System.Void", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure.ITimeoutControl", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "StartTimingReads", - "Parameters": [], - "ReturnType": "System.Void", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure.ITimeoutControl", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "StopTimingReads", - "Parameters": [], - "ReturnType": "System.Void", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure.ITimeoutControl", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "PauseTimingReads", - "Parameters": [], - "ReturnType": "System.Void", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure.ITimeoutControl", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ResumeTimingReads", - "Parameters": [], - "ReturnType": "System.Void", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure.ITimeoutControl", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "BytesRead", - "Parameters": [ - { - "Name": "count", - "Type": "System.Int32" - } - ], - "ReturnType": "System.Void", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure.ITimeoutControl", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "StartTimingWrite", - "Parameters": [ - { - "Name": "size", - "Type": "System.Int32" - } - ], - "ReturnType": "System.Void", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure.ITimeoutControl", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "StopTimingWrite", - "Parameters": [], - "ReturnType": "System.Void", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure.ITimeoutControl", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "context", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.FrameConnectionContext" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.FrameConnectionContext", - "Visibility": "Public", - "Kind": "Class", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "get_ConnectionId", - "Parameters": [], - "ReturnType": "System.String", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_ConnectionId", - "Parameters": [ - { - "Name": "value", - "Type": "System.String" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_FrameConnectionId", - "Parameters": [], - "ReturnType": "System.Int64", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_FrameConnectionId", - "Parameters": [ - { - "Name": "value", - "Type": "System.Int64" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_ServiceContext", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.ServiceContext", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_ServiceContext", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.ServiceContext" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_ConnectionAdapters", - "Parameters": [], - "ReturnType": "System.Collections.Generic.List", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_ConnectionAdapters", - "Parameters": [ - { - "Name": "value", - "Type": "System.Collections.Generic.List" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_ConnectionInformation", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal.IConnectionInformation", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_ConnectionInformation", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal.IConnectionInformation" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_Input", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.IPipe", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_Input", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.IPipe" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_Output", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.IPipe", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_Output", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.IPipe" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.KestrelTrace", - "Visibility": "Public", - "Kind": "Class", - "ImplementedInterfaces": [ - "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure.IKestrelTrace" - ], - "Members": [ - { - "Kind": "Method", - "Name": "ConnectionStart", - "Parameters": [ - { - "Name": "connectionId", - "Type": "System.String" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure.IKestrelTrace", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ConnectionStop", - "Parameters": [ - { - "Name": "connectionId", - "Type": "System.String" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure.IKestrelTrace", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ConnectionPause", - "Parameters": [ - { - "Name": "connectionId", - "Type": "System.String" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure.IKestrelTrace", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ConnectionResume", - "Parameters": [ - { - "Name": "connectionId", - "Type": "System.String" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure.IKestrelTrace", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ConnectionKeepAlive", - "Parameters": [ - { - "Name": "connectionId", - "Type": "System.String" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure.IKestrelTrace", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ConnectionRejected", - "Parameters": [ - { - "Name": "connectionId", - "Type": "System.String" - } - ], - "ReturnType": "System.Void", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure.IKestrelTrace", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ConnectionDisconnect", - "Parameters": [ - { - "Name": "connectionId", - "Type": "System.String" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure.IKestrelTrace", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ApplicationError", - "Parameters": [ - { - "Name": "connectionId", - "Type": "System.String" - }, - { - "Name": "traceIdentifier", - "Type": "System.String" - }, - { - "Name": "ex", - "Type": "System.Exception" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure.IKestrelTrace", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ConnectionHeadResponseBodyWrite", - "Parameters": [ - { - "Name": "connectionId", - "Type": "System.String" - }, - { - "Name": "count", - "Type": "System.Int64" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure.IKestrelTrace", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "NotAllConnectionsClosedGracefully", - "Parameters": [], - "ReturnType": "System.Void", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure.IKestrelTrace", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ConnectionBadRequest", - "Parameters": [ - { - "Name": "connectionId", - "Type": "System.String" - }, - { - "Name": "ex", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Core.BadHttpRequestException" - } - ], - "ReturnType": "System.Void", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure.IKestrelTrace", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "RequestProcessingError", - "Parameters": [ - { - "Name": "connectionId", - "Type": "System.String" - }, - { - "Name": "ex", - "Type": "System.Exception" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure.IKestrelTrace", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "NotAllConnectionsAborted", - "Parameters": [], - "ReturnType": "System.Void", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure.IKestrelTrace", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "HeartbeatSlow", - "Parameters": [ - { - "Name": "interval", - "Type": "System.TimeSpan" - }, - { - "Name": "now", - "Type": "System.DateTimeOffset" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure.IKestrelTrace", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ApplicationNeverCompleted", - "Parameters": [ - { - "Name": "connectionId", - "Type": "System.String" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure.IKestrelTrace", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "RequestBodyStart", - "Parameters": [ - { - "Name": "connectionId", - "Type": "System.String" - }, - { - "Name": "traceIdentifier", - "Type": "System.String" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure.IKestrelTrace", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "RequestBodyDone", - "Parameters": [ - { - "Name": "connectionId", - "Type": "System.String" - }, - { - "Name": "traceIdentifier", - "Type": "System.String" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure.IKestrelTrace", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "RequestBodyMininumDataRateNotSatisfied", - "Parameters": [ - { - "Name": "connectionId", - "Type": "System.String" - }, - { - "Name": "traceIdentifier", - "Type": "System.String" - }, - { - "Name": "rate", - "Type": "System.Double" - } - ], - "ReturnType": "System.Void", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure.IKestrelTrace", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ResponseMininumDataRateNotSatisfied", - "Parameters": [ - { - "Name": "connectionId", - "Type": "System.String" - }, - { - "Name": "traceIdentifier", - "Type": "System.String" - } - ], - "ReturnType": "System.Void", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure.IKestrelTrace", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Log", - "Parameters": [ - { - "Name": "logLevel", - "Type": "Microsoft.Extensions.Logging.LogLevel" - }, - { - "Name": "eventId", - "Type": "Microsoft.Extensions.Logging.EventId" - }, - { - "Name": "state", - "Type": "T0" - }, - { - "Name": "exception", - "Type": "System.Exception" - }, - { - "Name": "formatter", - "Type": "System.Func" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "ImplementedInterface": "Microsoft.Extensions.Logging.ILogger", - "Visibility": "Public", - "GenericParameter": [ - { - "ParameterName": "TState", - "ParameterPosition": 0, - "BaseTypeOrInterfaces": [] - } - ] - }, - { - "Kind": "Method", - "Name": "IsEnabled", - "Parameters": [ - { - "Name": "logLevel", - "Type": "Microsoft.Extensions.Logging.LogLevel" - } - ], - "ReturnType": "System.Boolean", - "Virtual": true, - "ImplementedInterface": "Microsoft.Extensions.Logging.ILogger", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "BeginScope", - "Parameters": [ - { - "Name": "state", - "Type": "T0" - } - ], - "ReturnType": "System.IDisposable", - "Virtual": true, - "ImplementedInterface": "Microsoft.Extensions.Logging.ILogger", - "Visibility": "Public", - "GenericParameter": [ - { - "ParameterName": "TState", - "ParameterPosition": 0, - "BaseTypeOrInterfaces": [] - } - ] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "logger", - "Type": "Microsoft.Extensions.Logging.ILogger" - } - ], - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "_logger", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Logging.ILogger", - "ReadOnly": true, - "Visibility": "Protected", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.KestrelServerOptionsSetup", - "Visibility": "Public", - "Kind": "Class", - "ImplementedInterfaces": [ - "Microsoft.Extensions.Options.IConfigureOptions" - ], - "Members": [ - { - "Kind": "Method", - "Name": "Configure", - "Parameters": [ - { - "Name": "options", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServerOptions" - } - ], - "ReturnType": "System.Void", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "Microsoft.Extensions.Options.IConfigureOptions", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "services", - "Type": "System.IServiceProvider" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.RejectionConnection", - "Visibility": "Public", - "Kind": "Class", - "ImplementedInterfaces": [ - "Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal.IConnectionContext" - ], - "Members": [ - { - "Kind": "Method", - "Name": "get_ConnectionId", - "Parameters": [], - "ReturnType": "System.String", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal.IConnectionContext", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_Input", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.IPipeWriter", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal.IConnectionContext", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_Output", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.IPipeReader", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal.IConnectionContext", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Reject", - "Parameters": [], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "input", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.IPipe" - }, - { - "Name": "output", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.IPipe" - }, - { - "Name": "connectionId", - "Type": "System.String" - }, - { - "Name": "serviceContext", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.ServiceContext" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.ServiceContext", - "Visibility": "Public", - "Kind": "Class", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "get_Log", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure.IKestrelTrace", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_Log", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure.IKestrelTrace" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_ThreadPool", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure.IThreadPool", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_ThreadPool", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure.IThreadPool" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HttpParserFactory", - "Parameters": [], - "ReturnType": "System.Func>", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HttpParserFactory", - "Parameters": [ - { - "Name": "value", - "Type": "System.Func>" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_SystemClock", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure.ISystemClock", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_SystemClock", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure.ISystemClock" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_DateHeaderValueManager", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.DateHeaderValueManager", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_DateHeaderValueManager", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.DateHeaderValueManager" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_ConnectionManager", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure.FrameConnectionManager", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_ConnectionManager", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure.FrameConnectionManager" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_ServerOptions", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServerOptions", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_ServerOptions", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServerOptions" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure.Disposable", - "Visibility": "Public", - "Kind": "Class", - "ImplementedInterfaces": [ - "System.IDisposable" - ], - "Members": [ - { - "Kind": "Method", - "Name": "Dispose", - "Parameters": [ - { - "Name": "disposing", - "Type": "System.Boolean" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Dispose", - "Parameters": [], - "ReturnType": "System.Void", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "System.IDisposable", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "dispose", - "Type": "System.Action" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure.FrameConnectionManager", - "Visibility": "Public", - "Kind": "Class", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "get_NormalConnectionCount", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure.ResourceCounter", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_UpgradedConnectionCount", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure.ResourceCounter", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "AddConnection", - "Parameters": [ - { - "Name": "id", - "Type": "System.Int64" - }, - { - "Name": "connection", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.FrameConnection" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "RemoveConnection", - "Parameters": [ - { - "Name": "id", - "Type": "System.Int64" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Walk", - "Parameters": [ - { - "Name": "callback", - "Type": "System.Action" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "trace", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure.IKestrelTrace" - }, - { - "Name": "normalConnectionLimit", - "Type": "System.Nullable" - }, - { - "Name": "upgradedConnectionLimit", - "Type": "System.Nullable" - } - ], - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "trace", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure.IKestrelTrace" - }, - { - "Name": "normalConnections", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure.ResourceCounter" - }, - { - "Name": "upgradedConnections", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure.ResourceCounter" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure.FrameConnectionManagerShutdownExtensions", - "Visibility": "Public", - "Kind": "Class", - "Abstract": true, - "Static": true, - "Sealed": true, - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "CloseAllConnectionsAsync", - "Parameters": [ - { - "Name": "connectionManager", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure.FrameConnectionManager" - }, - { - "Name": "token", - "Type": "System.Threading.CancellationToken" - } - ], - "ReturnType": "System.Threading.Tasks.Task", - "Static": true, - "Extension": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "AbortAllConnectionsAsync", - "Parameters": [ - { - "Name": "connectionManager", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure.FrameConnectionManager" - } - ], - "ReturnType": "System.Threading.Tasks.Task", - "Static": true, - "Extension": true, - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure.FrameConnectionReference", - "Visibility": "Public", - "Kind": "Class", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "get_ConnectionId", - "Parameters": [], - "ReturnType": "System.String", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "TryGetConnection", - "Parameters": [ - { - "Name": "connection", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.FrameConnection", - "Direction": "Out" - } - ], - "ReturnType": "System.Boolean", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "connection", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.FrameConnection" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure.FrameHeartbeatManager", - "Visibility": "Public", - "Kind": "Class", - "ImplementedInterfaces": [ - "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure.IHeartbeatHandler" - ], - "Members": [ - { - "Kind": "Method", - "Name": "OnHeartbeat", - "Parameters": [ - { - "Name": "now", - "Type": "System.DateTimeOffset" - } - ], - "ReturnType": "System.Void", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure.IHeartbeatHandler", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "connectionManager", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure.FrameConnectionManager" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure.Heartbeat", - "Visibility": "Public", - "Kind": "Class", - "ImplementedInterfaces": [ - "System.IDisposable" - ], - "Members": [ - { - "Kind": "Method", - "Name": "Start", - "Parameters": [], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Dispose", - "Parameters": [], - "ReturnType": "System.Void", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "System.IDisposable", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "callbacks", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure.IHeartbeatHandler[]" - }, - { - "Name": "systemClock", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure.ISystemClock" - }, - { - "Name": "trace", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure.IKestrelTrace" - } - ], - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "Interval", - "Parameters": [], - "ReturnType": "System.TimeSpan", - "Static": true, - "ReadOnly": true, - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure.HttpUtilities", - "Visibility": "Public", - "Kind": "Class", - "Abstract": true, - "Static": true, - "Sealed": true, - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "GetAsciiStringNonNullCharacters", - "Parameters": [ - { - "Name": "span", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Span" - } - ], - "ReturnType": "System.String", - "Static": true, - "Extension": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "GetAsciiStringEscaped", - "Parameters": [ - { - "Name": "span", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Span" - }, - { - "Name": "maxChars", - "Type": "System.Int32" - } - ], - "ReturnType": "System.String", - "Static": true, - "Extension": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "GetKnownMethod", - "Parameters": [ - { - "Name": "span", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Span" - }, - { - "Name": "method", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpMethod", - "Direction": "Out" - }, - { - "Name": "length", - "Type": "System.Int32", - "Direction": "Out" - } - ], - "ReturnType": "System.Boolean", - "Static": true, - "Extension": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "GetKnownVersion", - "Parameters": [ - { - "Name": "span", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Span" - }, - { - "Name": "knownVersion", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpVersion", - "Direction": "Out" - }, - { - "Name": "length", - "Type": "System.Byte", - "Direction": "Out" - } - ], - "ReturnType": "System.Boolean", - "Static": true, - "Extension": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "GetKnownHttpScheme", - "Parameters": [ - { - "Name": "span", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Span" - }, - { - "Name": "knownScheme", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpScheme", - "Direction": "Out" - } - ], - "ReturnType": "System.Boolean", - "Static": true, - "Extension": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "VersionToString", - "Parameters": [ - { - "Name": "httpVersion", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpVersion" - } - ], - "ReturnType": "System.String", - "Static": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "MethodToString", - "Parameters": [ - { - "Name": "method", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpMethod" - } - ], - "ReturnType": "System.String", - "Static": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "SchemeToString", - "Parameters": [ - { - "Name": "scheme", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpScheme" - } - ], - "ReturnType": "System.String", - "Static": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "Http10Version", - "Parameters": [], - "ReturnType": "System.String", - "Static": true, - "Visibility": "Public", - "GenericParameter": [], - "Constant": true, - "Literal": "\"HTTP/1.0\"" - }, - { - "Kind": "Field", - "Name": "Http11Version", - "Parameters": [], - "ReturnType": "System.String", - "Static": true, - "Visibility": "Public", - "GenericParameter": [], - "Constant": true, - "Literal": "\"HTTP/1.1\"" - }, - { - "Kind": "Field", - "Name": "HttpUriScheme", - "Parameters": [], - "ReturnType": "System.String", - "Static": true, - "Visibility": "Public", - "GenericParameter": [], - "Constant": true, - "Literal": "\"http://\"" - }, - { - "Kind": "Field", - "Name": "HttpsUriScheme", - "Parameters": [], - "ReturnType": "System.String", - "Static": true, - "Visibility": "Public", - "GenericParameter": [], - "Constant": true, - "Literal": "\"https://\"" - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure.IDebugger", - "Visibility": "Public", - "Kind": "Interface", - "Abstract": true, - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "get_IsAttached", - "Parameters": [], - "ReturnType": "System.Boolean", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure.IHeartbeatHandler", - "Visibility": "Public", - "Kind": "Interface", - "Abstract": true, - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "OnHeartbeat", - "Parameters": [ - { - "Name": "now", - "Type": "System.DateTimeOffset" - } - ], - "ReturnType": "System.Void", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure.IKestrelTrace", - "Visibility": "Public", - "Kind": "Interface", - "Abstract": true, - "ImplementedInterfaces": [ - "Microsoft.Extensions.Logging.ILogger" - ], - "Members": [ - { - "Kind": "Method", - "Name": "ConnectionStart", - "Parameters": [ - { - "Name": "connectionId", - "Type": "System.String" - } - ], - "ReturnType": "System.Void", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ConnectionStop", - "Parameters": [ - { - "Name": "connectionId", - "Type": "System.String" - } - ], - "ReturnType": "System.Void", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ConnectionPause", - "Parameters": [ - { - "Name": "connectionId", - "Type": "System.String" - } - ], - "ReturnType": "System.Void", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ConnectionResume", - "Parameters": [ - { - "Name": "connectionId", - "Type": "System.String" - } - ], - "ReturnType": "System.Void", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ConnectionRejected", - "Parameters": [ - { - "Name": "connectionId", - "Type": "System.String" - } - ], - "ReturnType": "System.Void", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ConnectionKeepAlive", - "Parameters": [ - { - "Name": "connectionId", - "Type": "System.String" - } - ], - "ReturnType": "System.Void", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ConnectionDisconnect", - "Parameters": [ - { - "Name": "connectionId", - "Type": "System.String" - } - ], - "ReturnType": "System.Void", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "RequestProcessingError", - "Parameters": [ - { - "Name": "connectionId", - "Type": "System.String" - }, - { - "Name": "ex", - "Type": "System.Exception" - } - ], - "ReturnType": "System.Void", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ConnectionHeadResponseBodyWrite", - "Parameters": [ - { - "Name": "connectionId", - "Type": "System.String" - }, - { - "Name": "count", - "Type": "System.Int64" - } - ], - "ReturnType": "System.Void", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "NotAllConnectionsClosedGracefully", - "Parameters": [], - "ReturnType": "System.Void", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ConnectionBadRequest", - "Parameters": [ - { - "Name": "connectionId", - "Type": "System.String" - }, - { - "Name": "ex", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Core.BadHttpRequestException" - } - ], - "ReturnType": "System.Void", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ApplicationError", - "Parameters": [ - { - "Name": "connectionId", - "Type": "System.String" - }, - { - "Name": "traceIdentifier", - "Type": "System.String" - }, - { - "Name": "ex", - "Type": "System.Exception" - } - ], - "ReturnType": "System.Void", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "NotAllConnectionsAborted", - "Parameters": [], - "ReturnType": "System.Void", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "HeartbeatSlow", - "Parameters": [ - { - "Name": "interval", - "Type": "System.TimeSpan" - }, - { - "Name": "now", - "Type": "System.DateTimeOffset" - } - ], - "ReturnType": "System.Void", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ApplicationNeverCompleted", - "Parameters": [ - { - "Name": "connectionId", - "Type": "System.String" - } - ], - "ReturnType": "System.Void", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "RequestBodyStart", - "Parameters": [ - { - "Name": "connectionId", - "Type": "System.String" - }, - { - "Name": "traceIdentifier", - "Type": "System.String" - } - ], - "ReturnType": "System.Void", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "RequestBodyDone", - "Parameters": [ - { - "Name": "connectionId", - "Type": "System.String" - }, - { - "Name": "traceIdentifier", - "Type": "System.String" - } - ], - "ReturnType": "System.Void", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "RequestBodyMininumDataRateNotSatisfied", - "Parameters": [ - { - "Name": "connectionId", - "Type": "System.String" - }, - { - "Name": "traceIdentifier", - "Type": "System.String" - }, - { - "Name": "rate", - "Type": "System.Double" - } - ], - "ReturnType": "System.Void", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ResponseMininumDataRateNotSatisfied", - "Parameters": [ - { - "Name": "connectionId", - "Type": "System.String" - }, - { - "Name": "traceIdentifier", - "Type": "System.String" - } - ], - "ReturnType": "System.Void", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure.InlineLoggingThreadPool", - "Visibility": "Public", - "Kind": "Class", - "ImplementedInterfaces": [ - "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure.IThreadPool" - ], - "Members": [ - { - "Kind": "Method", - "Name": "Run", - "Parameters": [ - { - "Name": "action", - "Type": "System.Action" - } - ], - "ReturnType": "System.Void", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure.IThreadPool", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "UnsafeRun", - "Parameters": [ - { - "Name": "action", - "Type": "System.Threading.WaitCallback" - }, - { - "Name": "state", - "Type": "System.Object" - } - ], - "ReturnType": "System.Void", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure.IThreadPool", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Schedule", - "Parameters": [ - { - "Name": "action", - "Type": "System.Action" - }, - { - "Name": "state", - "Type": "System.Object" - } - ], - "ReturnType": "System.Void", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.IScheduler", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "log", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure.IKestrelTrace" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure.ISystemClock", - "Visibility": "Public", - "Kind": "Interface", - "Abstract": true, - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "get_UtcNow", - "Parameters": [], - "ReturnType": "System.DateTimeOffset", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure.IThreadPool", - "Visibility": "Public", - "Kind": "Interface", - "Abstract": true, - "ImplementedInterfaces": [ - "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.IScheduler" - ], - "Members": [ - { - "Kind": "Method", - "Name": "Run", - "Parameters": [ - { - "Name": "action", - "Type": "System.Action" - } - ], - "ReturnType": "System.Void", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "UnsafeRun", - "Parameters": [ - { - "Name": "action", - "Type": "System.Threading.WaitCallback" - }, - { - "Name": "state", - "Type": "System.Object" - } - ], - "ReturnType": "System.Void", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure.ITimeoutControl", - "Visibility": "Public", - "Kind": "Interface", - "Abstract": true, - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "get_TimedOut", - "Parameters": [], - "ReturnType": "System.Boolean", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "SetTimeout", - "Parameters": [ - { - "Name": "ticks", - "Type": "System.Int64" - }, - { - "Name": "timeoutAction", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure.TimeoutAction" - } - ], - "ReturnType": "System.Void", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ResetTimeout", - "Parameters": [ - { - "Name": "ticks", - "Type": "System.Int64" - }, - { - "Name": "timeoutAction", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure.TimeoutAction" - } - ], - "ReturnType": "System.Void", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "CancelTimeout", - "Parameters": [], - "ReturnType": "System.Void", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "StartTimingReads", - "Parameters": [], - "ReturnType": "System.Void", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "PauseTimingReads", - "Parameters": [], - "ReturnType": "System.Void", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ResumeTimingReads", - "Parameters": [], - "ReturnType": "System.Void", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "StopTimingReads", - "Parameters": [], - "ReturnType": "System.Void", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "BytesRead", - "Parameters": [ - { - "Name": "count", - "Type": "System.Int32" - } - ], - "ReturnType": "System.Void", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "StartTimingWrite", - "Parameters": [ - { - "Name": "size", - "Type": "System.Int32" - } - ], - "ReturnType": "System.Void", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "StopTimingWrite", - "Parameters": [], - "ReturnType": "System.Void", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure.KestrelEventSource", - "Visibility": "Public", - "Kind": "Class", - "Sealed": true, - "BaseType": "System.Diagnostics.Tracing.EventSource", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "ConnectionStart", - "Parameters": [ - { - "Name": "context", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal.IConnectionContext" - }, - { - "Name": "information", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal.IConnectionInformation" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ConnectionStop", - "Parameters": [ - { - "Name": "connection", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal.IConnectionContext" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ConnectionRejected", - "Parameters": [ - { - "Name": "connectionId", - "Type": "System.String" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "RequestStart", - "Parameters": [ - { - "Name": "frame", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.Frame" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "RequestStop", - "Parameters": [ - { - "Name": "frame", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.Frame" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "Log", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure.KestrelEventSource", - "Static": true, - "ReadOnly": true, - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure.LoggingThreadPool", - "Visibility": "Public", - "Kind": "Class", - "ImplementedInterfaces": [ - "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure.IThreadPool" - ], - "Members": [ - { - "Kind": "Method", - "Name": "Run", - "Parameters": [ - { - "Name": "action", - "Type": "System.Action" - } - ], - "ReturnType": "System.Void", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure.IThreadPool", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "UnsafeRun", - "Parameters": [ - { - "Name": "action", - "Type": "System.Threading.WaitCallback" - }, - { - "Name": "state", - "Type": "System.Object" - } - ], - "ReturnType": "System.Void", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure.IThreadPool", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Schedule", - "Parameters": [ - { - "Name": "action", - "Type": "System.Action" - }, - { - "Name": "state", - "Type": "System.Object" - } - ], - "ReturnType": "System.Void", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.IScheduler", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "log", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure.IKestrelTrace" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure.ReadOnlyStream", - "Visibility": "Public", - "Kind": "Class", - "Abstract": true, - "BaseType": "System.IO.Stream", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "get_CanRead", - "Parameters": [], - "ReturnType": "System.Boolean", - "Virtual": true, - "Override": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_CanWrite", - "Parameters": [], - "ReturnType": "System.Boolean", - "Virtual": true, - "Override": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_WriteTimeout", - "Parameters": [], - "ReturnType": "System.Int32", - "Virtual": true, - "Override": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_WriteTimeout", - "Parameters": [ - { - "Name": "value", - "Type": "System.Int32" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "Override": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Write", - "Parameters": [ - { - "Name": "buffer", - "Type": "System.Byte[]" - }, - { - "Name": "offset", - "Type": "System.Int32" - }, - { - "Name": "count", - "Type": "System.Int32" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "Override": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "WriteAsync", - "Parameters": [ - { - "Name": "buffer", - "Type": "System.Byte[]" - }, - { - "Name": "offset", - "Type": "System.Int32" - }, - { - "Name": "count", - "Type": "System.Int32" - }, - { - "Name": "cancellationToken", - "Type": "System.Threading.CancellationToken" - } - ], - "ReturnType": "System.Threading.Tasks.Task", - "Virtual": true, - "Override": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [], - "Visibility": "Protected", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure.ResourceCounter", - "Visibility": "Public", - "Kind": "Class", - "Abstract": true, - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "TryLockOne", - "Parameters": [], - "ReturnType": "System.Boolean", - "Virtual": true, - "Abstract": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ReleaseOne", - "Parameters": [], - "ReturnType": "System.Void", - "Virtual": true, - "Abstract": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_Unlimited", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure.ResourceCounter", - "Static": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Quota", - "Parameters": [ - { - "Name": "amount", - "Type": "System.Int64" - } - ], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure.ResourceCounter", - "Static": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [], - "Visibility": "Protected", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure.ThrowingWriteOnlyStream", - "Visibility": "Public", - "Kind": "Class", - "BaseType": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure.WriteOnlyStream", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "get_CanSeek", - "Parameters": [], - "ReturnType": "System.Boolean", - "Virtual": true, - "Override": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_Length", - "Parameters": [], - "ReturnType": "System.Int64", - "Virtual": true, - "Override": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_Position", - "Parameters": [], - "ReturnType": "System.Int64", - "Virtual": true, - "Override": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_Position", - "Parameters": [ - { - "Name": "value", - "Type": "System.Int64" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "Override": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Write", - "Parameters": [ - { - "Name": "buffer", - "Type": "System.Byte[]" - }, - { - "Name": "offset", - "Type": "System.Int32" - }, - { - "Name": "count", - "Type": "System.Int32" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "Override": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "WriteAsync", - "Parameters": [ - { - "Name": "buffer", - "Type": "System.Byte[]" - }, - { - "Name": "offset", - "Type": "System.Int32" - }, - { - "Name": "count", - "Type": "System.Int32" - }, - { - "Name": "cancellationToken", - "Type": "System.Threading.CancellationToken" - } - ], - "ReturnType": "System.Threading.Tasks.Task", - "Virtual": true, - "Override": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Flush", - "Parameters": [], - "ReturnType": "System.Void", - "Virtual": true, - "Override": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Seek", - "Parameters": [ - { - "Name": "offset", - "Type": "System.Int64" - }, - { - "Name": "origin", - "Type": "System.IO.SeekOrigin" - } - ], - "ReturnType": "System.Int64", - "Virtual": true, - "Override": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "SetLength", - "Parameters": [ - { - "Name": "value", - "Type": "System.Int64" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "Override": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "exception", - "Type": "System.Exception" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure.TimeoutAction", - "Visibility": "Public", - "Kind": "Enumeration", - "Sealed": true, - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Field", - "Name": "CloseConnection", - "Parameters": [], - "GenericParameter": [], - "Literal": "0" - }, - { - "Kind": "Field", - "Name": "SendTimeoutResponse", - "Parameters": [], - "GenericParameter": [], - "Literal": "1" - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure.UriUtilities", - "Visibility": "Public", - "Kind": "Class", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "IsValidAuthorityCharacter", - "Parameters": [ - { - "Name": "ch", - "Type": "System.Byte" - } - ], - "ReturnType": "System.Boolean", - "Static": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure.WriteOnlyStream", - "Visibility": "Public", - "Kind": "Class", - "Abstract": true, - "BaseType": "System.IO.Stream", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "get_CanRead", - "Parameters": [], - "ReturnType": "System.Boolean", - "Virtual": true, - "Override": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_CanWrite", - "Parameters": [], - "ReturnType": "System.Boolean", - "Virtual": true, - "Override": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_ReadTimeout", - "Parameters": [], - "ReturnType": "System.Int32", - "Virtual": true, - "Override": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_ReadTimeout", - "Parameters": [ - { - "Name": "value", - "Type": "System.Int32" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "Override": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Read", - "Parameters": [ - { - "Name": "buffer", - "Type": "System.Byte[]" - }, - { - "Name": "offset", - "Type": "System.Int32" - }, - { - "Name": "count", - "Type": "System.Int32" - } - ], - "ReturnType": "System.Int32", - "Virtual": true, - "Override": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ReadAsync", - "Parameters": [ - { - "Name": "buffer", - "Type": "System.Byte[]" - }, - { - "Name": "offset", - "Type": "System.Int32" - }, - { - "Name": "count", - "Type": "System.Int32" - }, - { - "Name": "cancellationToken", - "Type": "System.Threading.CancellationToken" - } - ], - "ReturnType": "System.Threading.Tasks.Task", - "Virtual": true, - "Override": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [], - "Visibility": "Protected", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.ChunkWriter", - "Visibility": "Public", - "Kind": "Class", - "Abstract": true, - "Static": true, - "Sealed": true, - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "BeginChunkBytes", - "Parameters": [ - { - "Name": "dataCount", - "Type": "System.Int32" - } - ], - "ReturnType": "System.ArraySegment", - "Static": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "WriteBeginChunkBytes", - "Parameters": [ - { - "Name": "start", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.WritableBufferWriter", - "Direction": "Ref" - }, - { - "Name": "dataCount", - "Type": "System.Int32" - } - ], - "ReturnType": "System.Int32", - "Static": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "WriteEndChunkBytes", - "Parameters": [ - { - "Name": "start", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.WritableBufferWriter", - "Direction": "Ref" - } - ], - "ReturnType": "System.Void", - "Static": true, - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.ConnectionOptions", - "Visibility": "Public", - "Kind": "Enumeration", - "Sealed": true, - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Field", - "Name": "None", - "Parameters": [], - "GenericParameter": [], - "Literal": "0" - }, - { - "Kind": "Field", - "Name": "Close", - "Parameters": [], - "GenericParameter": [], - "Literal": "1" - }, - { - "Kind": "Field", - "Name": "KeepAlive", - "Parameters": [], - "GenericParameter": [], - "Literal": "2" - }, - { - "Kind": "Field", - "Name": "Upgrade", - "Parameters": [], - "GenericParameter": [], - "Literal": "4" - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.DateHeaderValueManager", - "Visibility": "Public", - "Kind": "Class", - "ImplementedInterfaces": [ - "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure.IHeartbeatHandler" - ], - "Members": [ - { - "Kind": "Method", - "Name": "GetDateHeaderValues", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.DateHeaderValueManager+DateHeaderValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "OnHeartbeat", - "Parameters": [ - { - "Name": "now", - "Type": "System.DateTimeOffset" - } - ], - "ReturnType": "System.Void", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure.IHeartbeatHandler", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.Frame", - "Visibility": "Public", - "Kind": "Class", - "Abstract": true, - "ImplementedInterfaces": [ - "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.IFrameControl", - "Microsoft.AspNetCore.Http.Features.IFeatureCollection", - "Microsoft.AspNetCore.Http.Features.IHttpRequestFeature", - "Microsoft.AspNetCore.Http.Features.IHttpResponseFeature", - "Microsoft.AspNetCore.Http.Features.IHttpUpgradeFeature", - "Microsoft.AspNetCore.Http.Features.IHttpConnectionFeature", - "Microsoft.AspNetCore.Http.Features.IHttpRequestLifetimeFeature", - "Microsoft.AspNetCore.Http.Features.IHttpRequestIdentifierFeature", - "Microsoft.AspNetCore.Http.Features.IHttpBodyControlFeature", - "Microsoft.AspNetCore.Http.Features.IHttpMaxRequestBodySizeFeature", - "Microsoft.AspNetCore.Server.Kestrel.Core.Features.IHttpMinRequestBodyDataRateFeature", - "Microsoft.AspNetCore.Server.Kestrel.Core.Features.IHttpMinResponseDataRateFeature" - ], - "Members": [ - { - "Kind": "Method", - "Name": "get_FrameControl", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.IFrameControl", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_FrameControl", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.IFrameControl" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_RequestBodyPipe", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.IPipe", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_ServiceContext", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.ServiceContext", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_ConnectionInformation", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal.IConnectionInformation", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_ConnectionFeatures", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Http.Features.IFeatureCollection", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_ConnectionFeatures", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.AspNetCore.Http.Features.IFeatureCollection" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_Input", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.IPipeReader", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_Output", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.OutputProducer", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_TimeoutControl", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure.ITimeoutControl", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_Log", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure.IKestrelTrace", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_ConnectionId", - "Parameters": [], - "ReturnType": "System.String", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_ConnectionIdFeature", - "Parameters": [], - "ReturnType": "System.String", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_ConnectionIdFeature", - "Parameters": [ - { - "Name": "value", - "Type": "System.String" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HasStartedConsumingRequestBody", - "Parameters": [], - "ReturnType": "System.Boolean", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HasStartedConsumingRequestBody", - "Parameters": [ - { - "Name": "value", - "Type": "System.Boolean" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_MaxRequestBodySize", - "Parameters": [], - "ReturnType": "System.Nullable", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_MaxRequestBodySize", - "Parameters": [ - { - "Name": "value", - "Type": "System.Nullable" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_AllowSynchronousIO", - "Parameters": [], - "ReturnType": "System.Boolean", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_AllowSynchronousIO", - "Parameters": [ - { - "Name": "value", - "Type": "System.Boolean" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_TraceIdentifier", - "Parameters": [ - { - "Name": "value", - "Type": "System.String" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_TraceIdentifier", - "Parameters": [], - "ReturnType": "System.String", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_WasUpgraded", - "Parameters": [], - "ReturnType": "System.Boolean", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_RemoteIpAddress", - "Parameters": [], - "ReturnType": "System.Net.IPAddress", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_RemoteIpAddress", - "Parameters": [ - { - "Name": "value", - "Type": "System.Net.IPAddress" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_RemotePort", - "Parameters": [], - "ReturnType": "System.Int32", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_RemotePort", - "Parameters": [ - { - "Name": "value", - "Type": "System.Int32" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_LocalIpAddress", - "Parameters": [], - "ReturnType": "System.Net.IPAddress", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_LocalIpAddress", - "Parameters": [ - { - "Name": "value", - "Type": "System.Net.IPAddress" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_LocalPort", - "Parameters": [], - "ReturnType": "System.Int32", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_LocalPort", - "Parameters": [ - { - "Name": "value", - "Type": "System.Int32" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_Scheme", - "Parameters": [], - "ReturnType": "System.String", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_Scheme", - "Parameters": [ - { - "Name": "value", - "Type": "System.String" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_Method", - "Parameters": [], - "ReturnType": "System.String", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_Method", - "Parameters": [ - { - "Name": "value", - "Type": "System.String" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_PathBase", - "Parameters": [], - "ReturnType": "System.String", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_PathBase", - "Parameters": [ - { - "Name": "value", - "Type": "System.String" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_Path", - "Parameters": [], - "ReturnType": "System.String", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_Path", - "Parameters": [ - { - "Name": "value", - "Type": "System.String" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_QueryString", - "Parameters": [], - "ReturnType": "System.String", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_QueryString", - "Parameters": [ - { - "Name": "value", - "Type": "System.String" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_RawTarget", - "Parameters": [], - "ReturnType": "System.String", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_RawTarget", - "Parameters": [ - { - "Name": "value", - "Type": "System.String" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HttpVersion", - "Parameters": [], - "ReturnType": "System.String", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HttpVersion", - "Parameters": [ - { - "Name": "value", - "Type": "System.String" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_RequestHeaders", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Http.IHeaderDictionary", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_RequestHeaders", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.AspNetCore.Http.IHeaderDictionary" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_RequestBody", - "Parameters": [], - "ReturnType": "System.IO.Stream", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_RequestBody", - "Parameters": [ - { - "Name": "value", - "Type": "System.IO.Stream" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_StatusCode", - "Parameters": [], - "ReturnType": "System.Int32", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_StatusCode", - "Parameters": [ - { - "Name": "value", - "Type": "System.Int32" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_ReasonPhrase", - "Parameters": [], - "ReturnType": "System.String", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_ReasonPhrase", - "Parameters": [ - { - "Name": "value", - "Type": "System.String" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_ResponseHeaders", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Http.IHeaderDictionary", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_ResponseHeaders", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.AspNetCore.Http.IHeaderDictionary" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_ResponseBody", - "Parameters": [], - "ReturnType": "System.IO.Stream", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_ResponseBody", - "Parameters": [ - { - "Name": "value", - "Type": "System.IO.Stream" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_RequestAborted", - "Parameters": [], - "ReturnType": "System.Threading.CancellationToken", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_RequestAborted", - "Parameters": [ - { - "Name": "value", - "Type": "System.Threading.CancellationToken" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HasResponseStarted", - "Parameters": [], - "ReturnType": "System.Boolean", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_FrameRequestHeaders", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.FrameRequestHeaders", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_FrameResponseHeaders", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.FrameResponseHeaders", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_MinRequestBodyDataRate", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Core.MinDataRate", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_MinRequestBodyDataRate", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Core.MinDataRate" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_MinResponseDataRate", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Core.MinDataRate", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_MinResponseDataRate", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Core.MinDataRate" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "InitializeStreams", - "Parameters": [ - { - "Name": "messageBody", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.MessageBody" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "PauseStreams", - "Parameters": [], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "StopStreams", - "Parameters": [], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Reset", - "Parameters": [], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Stop", - "Parameters": [], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Abort", - "Parameters": [ - { - "Name": "error", - "Type": "System.Exception" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ProcessRequestsAsync", - "Parameters": [], - "ReturnType": "System.Threading.Tasks.Task", - "Virtual": true, - "Abstract": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "OnStarting", - "Parameters": [ - { - "Name": "callback", - "Type": "System.Func" - }, - { - "Name": "state", - "Type": "System.Object" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "OnCompleted", - "Parameters": [ - { - "Name": "callback", - "Type": "System.Func" - }, - { - "Name": "state", - "Type": "System.Object" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "FireOnStarting", - "Parameters": [], - "ReturnType": "System.Threading.Tasks.Task", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "FireOnCompleted", - "Parameters": [], - "ReturnType": "System.Threading.Tasks.Task", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "FlushAsync", - "Parameters": [ - { - "Name": "cancellationToken", - "Type": "System.Threading.CancellationToken", - "DefaultValue": "default(System.Threading.CancellationToken)" - } - ], - "ReturnType": "System.Threading.Tasks.Task", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.IFrameControl", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "WriteAsync", - "Parameters": [ - { - "Name": "data", - "Type": "System.ArraySegment" - }, - { - "Name": "cancellationToken", - "Type": "System.Threading.CancellationToken", - "DefaultValue": "default(System.Threading.CancellationToken)" - } - ], - "ReturnType": "System.Threading.Tasks.Task", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.IFrameControl", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "WriteAsyncAwaited", - "Parameters": [ - { - "Name": "data", - "Type": "System.ArraySegment" - }, - { - "Name": "cancellationToken", - "Type": "System.Threading.CancellationToken" - } - ], - "ReturnType": "System.Threading.Tasks.Task", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "VerifyResponseContentLength", - "Parameters": [], - "ReturnType": "System.Void", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ProduceContinue", - "Parameters": [], - "ReturnType": "System.Void", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.IFrameControl", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "InitializeResponse", - "Parameters": [ - { - "Name": "firstWriteByteCount", - "Type": "System.Int32" - } - ], - "ReturnType": "System.Threading.Tasks.Task", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "TryProduceInvalidRequestResponse", - "Parameters": [], - "ReturnType": "System.Threading.Tasks.Task", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ProduceEnd", - "Parameters": [], - "ReturnType": "System.Threading.Tasks.Task", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ParseRequest", - "Parameters": [ - { - "Name": "buffer", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.ReadableBuffer" - }, - { - "Name": "consumed", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.ReadCursor", - "Direction": "Out" - }, - { - "Name": "examined", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.ReadCursor", - "Direction": "Out" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "TakeStartLine", - "Parameters": [ - { - "Name": "buffer", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.ReadableBuffer" - }, - { - "Name": "consumed", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.ReadCursor", - "Direction": "Out" - }, - { - "Name": "examined", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.ReadCursor", - "Direction": "Out" - } - ], - "ReturnType": "System.Boolean", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "TakeMessageHeaders", - "Parameters": [ - { - "Name": "buffer", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.ReadableBuffer" - }, - { - "Name": "consumed", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.ReadCursor", - "Direction": "Out" - }, - { - "Name": "examined", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.ReadCursor", - "Direction": "Out" - } - ], - "ReturnType": "System.Boolean", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "StatusCanHaveBody", - "Parameters": [ - { - "Name": "statusCode", - "Type": "System.Int32" - } - ], - "ReturnType": "System.Boolean", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "HandleNonBodyResponseWrite", - "Parameters": [], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ThrowRequestRejected", - "Parameters": [ - { - "Name": "reason", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.RequestRejectionReason" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ThrowRequestRejected", - "Parameters": [ - { - "Name": "reason", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.RequestRejectionReason" - }, - { - "Name": "detail", - "Type": "System.String" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "SetBadRequestState", - "Parameters": [ - { - "Name": "reason", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.RequestRejectionReason" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "SetBadRequestState", - "Parameters": [ - { - "Name": "ex", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Core.BadHttpRequestException" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ReportApplicationError", - "Parameters": [ - { - "Name": "ex", - "Type": "System.Exception" - } - ], - "ReturnType": "System.Void", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "OnStartLine", - "Parameters": [ - { - "Name": "method", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpMethod" - }, - { - "Name": "version", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpVersion" - }, - { - "Name": "target", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Span" - }, - { - "Name": "path", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Span" - }, - { - "Name": "query", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Span" - }, - { - "Name": "customMethod", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Span" - }, - { - "Name": "pathEncoded", - "Type": "System.Boolean" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "OnHeader", - "Parameters": [ - { - "Name": "name", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Span" - }, - { - "Name": "value", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Span" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "EnsureHostHeaderExists", - "Parameters": [], - "ReturnType": "System.Void", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ResetFeatureCollection", - "Parameters": [], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "frameContext", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.FrameContext" - } - ], - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "_onStarting", - "Parameters": [], - "ReturnType": "System.Collections.Generic.Stack, System.Object>>", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "_onCompleted", - "Parameters": [], - "ReturnType": "System.Collections.Generic.Stack, System.Object>>", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "_requestProcessingStopping", - "Parameters": [], - "ReturnType": "System.Boolean", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "_requestAborted", - "Parameters": [], - "ReturnType": "System.Int32", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "_requestProcessingStatus", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.RequestProcessingStatus", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "_keepAlive", - "Parameters": [], - "ReturnType": "System.Boolean", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "_upgradeAvailable", - "Parameters": [], - "ReturnType": "System.Boolean", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "_applicationException", - "Parameters": [], - "ReturnType": "System.Exception", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "_httpVersion", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpVersion", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "_keepAliveTicks", - "Parameters": [], - "ReturnType": "System.Int64", - "ReadOnly": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "_responseBytesWritten", - "Parameters": [], - "ReturnType": "System.Int64", - "Visibility": "Protected", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.FrameAdapter", - "Visibility": "Public", - "Kind": "Struct", - "Sealed": true, - "ImplementedInterfaces": [ - "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.IHttpRequestLineHandler", - "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.IHttpHeadersHandler" - ], - "Members": [ - { - "Kind": "Method", - "Name": "OnHeader", - "Parameters": [ - { - "Name": "name", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Span" - }, - { - "Name": "value", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Span" - } - ], - "ReturnType": "System.Void", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.IHttpHeadersHandler", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "OnStartLine", - "Parameters": [ - { - "Name": "method", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpMethod" - }, - { - "Name": "version", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpVersion" - }, - { - "Name": "target", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Span" - }, - { - "Name": "path", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Span" - }, - { - "Name": "query", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Span" - }, - { - "Name": "customMethod", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Span" - }, - { - "Name": "pathEncoded", - "Type": "System.Boolean" - } - ], - "ReturnType": "System.Void", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.IHttpRequestLineHandler", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "frame", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.Frame" - } - ], - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "Frame", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.Frame", - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.FrameContext", - "Visibility": "Public", - "Kind": "Class", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "get_ConnectionId", - "Parameters": [], - "ReturnType": "System.String", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_ConnectionId", - "Parameters": [ - { - "Name": "value", - "Type": "System.String" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_ServiceContext", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.ServiceContext", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_ServiceContext", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.ServiceContext" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_ConnectionInformation", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal.IConnectionInformation", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_ConnectionInformation", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal.IConnectionInformation" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_TimeoutControl", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure.ITimeoutControl", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_TimeoutControl", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure.ITimeoutControl" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_Input", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.IPipeReader", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_Input", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.IPipeReader" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_Output", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.IPipe", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_Output", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.IPipe" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.FrameHeaders", - "Visibility": "Public", - "Kind": "Class", - "Abstract": true, - "ImplementedInterfaces": [ - "Microsoft.AspNetCore.Http.IHeaderDictionary" - ], - "Members": [ - { - "Kind": "Method", - "Name": "get_Unknown", - "Parameters": [], - "ReturnType": "System.Collections.Generic.Dictionary", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_ContentLength", - "Parameters": [], - "ReturnType": "System.Nullable", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Http.IHeaderDictionary", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_ContentLength", - "Parameters": [ - { - "Name": "value", - "Type": "System.Nullable" - } - ], - "ReturnType": "System.Void", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Http.IHeaderDictionary", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ThrowHeadersReadOnlyException", - "Parameters": [], - "ReturnType": "System.Void", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ThrowArgumentException", - "Parameters": [], - "ReturnType": "System.Void", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ThrowKeyNotFoundException", - "Parameters": [], - "ReturnType": "System.Void", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ThrowDuplicateKeyException", - "Parameters": [], - "ReturnType": "System.Void", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "SetReadOnly", - "Parameters": [], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Reset", - "Parameters": [], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "AppendValue", - "Parameters": [ - { - "Name": "existing", - "Type": "Microsoft.Extensions.Primitives.StringValues" - }, - { - "Name": "append", - "Type": "System.String" - } - ], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Static": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "BitCount", - "Parameters": [ - { - "Name": "value", - "Type": "System.Int64" - } - ], - "ReturnType": "System.Int32", - "Static": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "GetCountFast", - "Parameters": [], - "ReturnType": "System.Int32", - "Virtual": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "TryGetValueFast", - "Parameters": [ - { - "Name": "key", - "Type": "System.String" - }, - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues", - "Direction": "Out" - } - ], - "ReturnType": "System.Boolean", - "Virtual": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "SetValueFast", - "Parameters": [ - { - "Name": "key", - "Type": "System.String" - }, - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "AddValueFast", - "Parameters": [ - { - "Name": "key", - "Type": "System.String" - }, - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Boolean", - "Virtual": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "RemoveFast", - "Parameters": [ - { - "Name": "key", - "Type": "System.String" - } - ], - "ReturnType": "System.Boolean", - "Virtual": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ClearFast", - "Parameters": [], - "ReturnType": "System.Void", - "Virtual": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "CopyToFast", - "Parameters": [ - { - "Name": "array", - "Type": "System.Collections.Generic.KeyValuePair[]" - }, - { - "Name": "arrayIndex", - "Type": "System.Int32" - } - ], - "ReturnType": "System.Boolean", - "Virtual": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "GetEnumeratorFast", - "Parameters": [], - "ReturnType": "System.Collections.Generic.IEnumerator>", - "Virtual": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ValidateHeaderCharacters", - "Parameters": [ - { - "Name": "headerValues", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Static": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ValidateHeaderCharacters", - "Parameters": [ - { - "Name": "headerCharacters", - "Type": "System.String" - } - ], - "ReturnType": "System.Void", - "Static": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ParseConnection", - "Parameters": [ - { - "Name": "connection", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.ConnectionOptions", - "Static": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "GetFinalTransferCoding", - "Parameters": [ - { - "Name": "transferEncoding", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.TransferCoding", - "Static": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [], - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "_contentLength", - "Parameters": [], - "ReturnType": "System.Nullable", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "_isReadOnly", - "Parameters": [], - "ReturnType": "System.Boolean", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "MaybeUnknown", - "Parameters": [], - "ReturnType": "System.Collections.Generic.Dictionary", - "Visibility": "Protected", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.FrameRequestHeaders", - "Visibility": "Public", - "Kind": "Class", - "BaseType": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.FrameHeaders", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "get_HeaderCacheControl", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderCacheControl", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderConnection", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderConnection", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderDate", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderDate", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderKeepAlive", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderKeepAlive", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderPragma", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderPragma", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderTrailer", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderTrailer", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderTransferEncoding", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderTransferEncoding", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderUpgrade", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderUpgrade", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderVia", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderVia", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderWarning", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderWarning", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderAllow", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderAllow", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderContentType", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderContentType", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderContentEncoding", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderContentEncoding", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderContentLanguage", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderContentLanguage", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderContentLocation", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderContentLocation", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderContentMD5", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderContentMD5", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderContentRange", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderContentRange", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderExpires", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderExpires", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderLastModified", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderLastModified", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderAccept", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderAccept", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderAcceptCharset", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderAcceptCharset", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderAcceptEncoding", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderAcceptEncoding", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderAcceptLanguage", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderAcceptLanguage", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderAuthorization", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderAuthorization", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderCookie", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderCookie", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderExpect", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderExpect", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderFrom", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderFrom", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderHost", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderHost", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderIfMatch", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderIfMatch", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderIfModifiedSince", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderIfModifiedSince", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderIfNoneMatch", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderIfNoneMatch", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderIfRange", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderIfRange", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderIfUnmodifiedSince", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderIfUnmodifiedSince", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderMaxForwards", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderMaxForwards", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderProxyAuthorization", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderProxyAuthorization", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderReferer", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderReferer", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderRange", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderRange", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderTE", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderTE", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderTranslate", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderTranslate", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderUserAgent", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderUserAgent", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderOrigin", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderOrigin", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderAccessControlRequestMethod", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderAccessControlRequestMethod", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderAccessControlRequestHeaders", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderAccessControlRequestHeaders", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderContentLength", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderContentLength", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "GetCountFast", - "Parameters": [], - "ReturnType": "System.Int32", - "Virtual": true, - "Override": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "TryGetValueFast", - "Parameters": [ - { - "Name": "key", - "Type": "System.String" - }, - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues", - "Direction": "Out" - } - ], - "ReturnType": "System.Boolean", - "Virtual": true, - "Override": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "SetValueFast", - "Parameters": [ - { - "Name": "key", - "Type": "System.String" - }, - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "Override": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "AddValueFast", - "Parameters": [ - { - "Name": "key", - "Type": "System.String" - }, - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Boolean", - "Virtual": true, - "Override": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "RemoveFast", - "Parameters": [ - { - "Name": "key", - "Type": "System.String" - } - ], - "ReturnType": "System.Boolean", - "Virtual": true, - "Override": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ClearFast", - "Parameters": [], - "ReturnType": "System.Void", - "Virtual": true, - "Override": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "CopyToFast", - "Parameters": [ - { - "Name": "array", - "Type": "System.Collections.Generic.KeyValuePair[]" - }, - { - "Name": "arrayIndex", - "Type": "System.Int32" - } - ], - "ReturnType": "System.Boolean", - "Virtual": true, - "Override": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Append", - "Parameters": [ - { - "Name": "pKeyBytes", - "Type": "System.Byte*" - }, - { - "Name": "keyLength", - "Type": "System.Int32" - }, - { - "Name": "value", - "Type": "System.String" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Append", - "Parameters": [ - { - "Name": "name", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Span" - }, - { - "Name": "value", - "Type": "System.String" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "GetEnumerator", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.FrameRequestHeaders+Enumerator", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "GetEnumeratorFast", - "Parameters": [], - "ReturnType": "System.Collections.Generic.IEnumerator>", - "Virtual": true, - "Override": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.FrameResponseHeaders", - "Visibility": "Public", - "Kind": "Class", - "BaseType": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.FrameHeaders", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "get_HeaderCacheControl", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderCacheControl", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderConnection", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderConnection", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderDate", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderDate", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderKeepAlive", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderKeepAlive", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderPragma", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderPragma", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderTrailer", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderTrailer", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderTransferEncoding", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderTransferEncoding", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderUpgrade", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderUpgrade", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderVia", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderVia", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderWarning", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderWarning", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderAllow", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderAllow", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderContentType", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderContentType", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderContentEncoding", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderContentEncoding", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderContentLanguage", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderContentLanguage", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderContentLocation", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderContentLocation", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderContentMD5", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderContentMD5", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderContentRange", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderContentRange", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderExpires", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderExpires", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderLastModified", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderLastModified", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderAcceptRanges", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderAcceptRanges", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderAge", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderAge", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderETag", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderETag", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderLocation", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderLocation", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderProxyAuthenticate", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderProxyAuthenticate", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderRetryAfter", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderRetryAfter", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderServer", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderServer", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderSetCookie", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderSetCookie", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderVary", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderVary", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderWWWAuthenticate", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderWWWAuthenticate", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderAccessControlAllowCredentials", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderAccessControlAllowCredentials", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderAccessControlAllowHeaders", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderAccessControlAllowHeaders", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderAccessControlAllowMethods", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderAccessControlAllowMethods", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderAccessControlAllowOrigin", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderAccessControlAllowOrigin", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderAccessControlExposeHeaders", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderAccessControlExposeHeaders", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderAccessControlMaxAge", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderAccessControlMaxAge", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HeaderContentLength", - "Parameters": [], - "ReturnType": "Microsoft.Extensions.Primitives.StringValues", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HeaderContentLength", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "SetRawConnection", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - }, - { - "Name": "raw", - "Type": "System.Byte[]" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "SetRawDate", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - }, - { - "Name": "raw", - "Type": "System.Byte[]" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "SetRawTransferEncoding", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - }, - { - "Name": "raw", - "Type": "System.Byte[]" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "SetRawServer", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - }, - { - "Name": "raw", - "Type": "System.Byte[]" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "GetCountFast", - "Parameters": [], - "ReturnType": "System.Int32", - "Virtual": true, - "Override": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "TryGetValueFast", - "Parameters": [ - { - "Name": "key", - "Type": "System.String" - }, - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues", - "Direction": "Out" - } - ], - "ReturnType": "System.Boolean", - "Virtual": true, - "Override": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "SetValueFast", - "Parameters": [ - { - "Name": "key", - "Type": "System.String" - }, - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "Override": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "AddValueFast", - "Parameters": [ - { - "Name": "key", - "Type": "System.String" - }, - { - "Name": "value", - "Type": "Microsoft.Extensions.Primitives.StringValues" - } - ], - "ReturnType": "System.Boolean", - "Virtual": true, - "Override": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "RemoveFast", - "Parameters": [ - { - "Name": "key", - "Type": "System.String" - } - ], - "ReturnType": "System.Boolean", - "Virtual": true, - "Override": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ClearFast", - "Parameters": [], - "ReturnType": "System.Void", - "Virtual": true, - "Override": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "CopyToFast", - "Parameters": [ - { - "Name": "array", - "Type": "System.Collections.Generic.KeyValuePair[]" - }, - { - "Name": "arrayIndex", - "Type": "System.Int32" - } - ], - "ReturnType": "System.Boolean", - "Virtual": true, - "Override": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "CopyToFast", - "Parameters": [ - { - "Name": "output", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.WritableBufferWriter", - "Direction": "Ref" - } - ], - "ReturnType": "System.Void", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HasConnection", - "Parameters": [], - "ReturnType": "System.Boolean", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HasTransferEncoding", - "Parameters": [], - "ReturnType": "System.Boolean", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HasServer", - "Parameters": [], - "ReturnType": "System.Boolean", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HasDate", - "Parameters": [], - "ReturnType": "System.Boolean", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "GetEnumerator", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.FrameResponseHeaders+Enumerator", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "GetEnumeratorFast", - "Parameters": [], - "ReturnType": "System.Collections.Generic.IEnumerator>", - "Virtual": true, - "Override": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "CopyTo", - "Parameters": [ - { - "Name": "output", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.WritableBufferWriter", - "Direction": "Ref" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.Frame", - "Visibility": "Public", - "Kind": "Class", - "BaseType": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.Frame", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "ProcessRequestsAsync", - "Parameters": [], - "ReturnType": "System.Threading.Tasks.Task", - "Virtual": true, - "Override": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "application", - "Type": "Microsoft.AspNetCore.Hosting.Server.IHttpApplication" - }, - { - "Name": "frameContext", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.FrameContext" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [ - { - "ParameterName": "TContext", - "ParameterPosition": 0, - "BaseTypeOrInterfaces": [] - } - ] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpMethod", - "Visibility": "Public", - "Kind": "Enumeration", - "Sealed": true, - "BaseType": "System.Byte", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Field", - "Name": "Get", - "Parameters": [], - "GenericParameter": [], - "Literal": "0" - }, - { - "Kind": "Field", - "Name": "Put", - "Parameters": [], - "GenericParameter": [], - "Literal": "1" - }, - { - "Kind": "Field", - "Name": "Delete", - "Parameters": [], - "GenericParameter": [], - "Literal": "2" - }, - { - "Kind": "Field", - "Name": "Post", - "Parameters": [], - "GenericParameter": [], - "Literal": "3" - }, - { - "Kind": "Field", - "Name": "Head", - "Parameters": [], - "GenericParameter": [], - "Literal": "4" - }, - { - "Kind": "Field", - "Name": "Trace", - "Parameters": [], - "GenericParameter": [], - "Literal": "5" - }, - { - "Kind": "Field", - "Name": "Patch", - "Parameters": [], - "GenericParameter": [], - "Literal": "6" - }, - { - "Kind": "Field", - "Name": "Connect", - "Parameters": [], - "GenericParameter": [], - "Literal": "7" - }, - { - "Kind": "Field", - "Name": "Options", - "Parameters": [], - "GenericParameter": [], - "Literal": "8" - }, - { - "Kind": "Field", - "Name": "Custom", - "Parameters": [], - "GenericParameter": [], - "Literal": "9" - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpParser", - "Visibility": "Public", - "Kind": "Class", - "ImplementedInterfaces": [ - "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.IHttpParser" - ], - "Members": [ - { - "Kind": "Method", - "Name": "ParseRequestLine", - "Parameters": [ - { - "Name": "handler", - "Type": "T0" - }, - { - "Name": "buffer", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.ReadableBuffer" - }, - { - "Name": "consumed", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.ReadCursor", - "Direction": "Out" - }, - { - "Name": "examined", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.ReadCursor", - "Direction": "Out" - } - ], - "ReturnType": "System.Boolean", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.IHttpParser", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ParseHeaders", - "Parameters": [ - { - "Name": "handler", - "Type": "T0" - }, - { - "Name": "buffer", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.ReadableBuffer" - }, - { - "Name": "consumed", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.ReadCursor", - "Direction": "Out" - }, - { - "Name": "examined", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.ReadCursor", - "Direction": "Out" - }, - { - "Name": "consumedBytes", - "Type": "System.Int32", - "Direction": "Out" - } - ], - "ReturnType": "System.Boolean", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.IHttpParser", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [], - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "showErrorDetails", - "Type": "System.Boolean" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [ - { - "ParameterName": "TRequestHandler", - "ParameterPosition": 0, - "BaseTypeOrInterfaces": [ - "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.IHttpHeadersHandler", - "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.IHttpRequestLineHandler" - ] - } - ] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpScheme", - "Visibility": "Public", - "Kind": "Enumeration", - "Sealed": true, - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Field", - "Name": "Unknown", - "Parameters": [], - "GenericParameter": [], - "Literal": "-1" - }, - { - "Kind": "Field", - "Name": "Http", - "Parameters": [], - "GenericParameter": [], - "Literal": "0" - }, - { - "Kind": "Field", - "Name": "Https", - "Parameters": [], - "GenericParameter": [], - "Literal": "1" - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpVersion", - "Visibility": "Public", - "Kind": "Enumeration", - "Sealed": true, - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Field", - "Name": "Unknown", - "Parameters": [], - "GenericParameter": [], - "Literal": "-1" - }, - { - "Kind": "Field", - "Name": "Http10", - "Parameters": [], - "GenericParameter": [], - "Literal": "0" - }, - { - "Kind": "Field", - "Name": "Http11", - "Parameters": [], - "GenericParameter": [], - "Literal": "1" - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.IFrameControl", - "Visibility": "Public", - "Kind": "Interface", - "Abstract": true, - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "ProduceContinue", - "Parameters": [], - "ReturnType": "System.Void", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "WriteAsync", - "Parameters": [ - { - "Name": "data", - "Type": "System.ArraySegment" - }, - { - "Name": "cancellationToken", - "Type": "System.Threading.CancellationToken" - } - ], - "ReturnType": "System.Threading.Tasks.Task", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "FlushAsync", - "Parameters": [ - { - "Name": "cancellationToken", - "Type": "System.Threading.CancellationToken" - } - ], - "ReturnType": "System.Threading.Tasks.Task", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.IHttpHeadersHandler", - "Visibility": "Public", - "Kind": "Interface", - "Abstract": true, - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "OnHeader", - "Parameters": [ - { - "Name": "name", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Span" - }, - { - "Name": "value", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Span" - } - ], - "ReturnType": "System.Void", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.IHttpParser", - "Visibility": "Public", - "Kind": "Interface", - "Abstract": true, - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "ParseRequestLine", - "Parameters": [ - { - "Name": "handler", - "Type": "T0" - }, - { - "Name": "buffer", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.ReadableBuffer" - }, - { - "Name": "consumed", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.ReadCursor", - "Direction": "Out" - }, - { - "Name": "examined", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.ReadCursor", - "Direction": "Out" - } - ], - "ReturnType": "System.Boolean", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ParseHeaders", - "Parameters": [ - { - "Name": "handler", - "Type": "T0" - }, - { - "Name": "buffer", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.ReadableBuffer" - }, - { - "Name": "consumed", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.ReadCursor", - "Direction": "Out" - }, - { - "Name": "examined", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.ReadCursor", - "Direction": "Out" - }, - { - "Name": "consumedBytes", - "Type": "System.Int32", - "Direction": "Out" - } - ], - "ReturnType": "System.Boolean", - "GenericParameter": [] - } - ], - "GenericParameters": [ - { - "ParameterName": "TRequestHandler", - "ParameterPosition": 0, - "BaseTypeOrInterfaces": [ - "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.IHttpHeadersHandler", - "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.IHttpRequestLineHandler" - ] - } - ] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.IHttpRequestLineHandler", - "Visibility": "Public", - "Kind": "Interface", - "Abstract": true, - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "OnStartLine", - "Parameters": [ - { - "Name": "method", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpMethod" - }, - { - "Name": "version", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpVersion" - }, - { - "Name": "target", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Span" - }, - { - "Name": "path", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Span" - }, - { - "Name": "query", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Span" - }, - { - "Name": "customMethod", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Span" - }, - { - "Name": "pathEncoded", - "Type": "System.Boolean" - } - ], - "ReturnType": "System.Void", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.MessageBody", - "Visibility": "Public", - "Kind": "Class", - "Abstract": true, - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "get_ZeroContentLengthClose", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.MessageBody", - "Static": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_RequestKeepAlive", - "Parameters": [], - "ReturnType": "System.Boolean", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_RequestKeepAlive", - "Parameters": [ - { - "Name": "value", - "Type": "System.Boolean" - } - ], - "ReturnType": "System.Void", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_RequestUpgrade", - "Parameters": [], - "ReturnType": "System.Boolean", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_RequestUpgrade", - "Parameters": [ - { - "Name": "value", - "Type": "System.Boolean" - } - ], - "ReturnType": "System.Void", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_IsEmpty", - "Parameters": [], - "ReturnType": "System.Boolean", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ReadAsync", - "Parameters": [ - { - "Name": "buffer", - "Type": "System.ArraySegment" - }, - { - "Name": "cancellationToken", - "Type": "System.Threading.CancellationToken", - "DefaultValue": "default(System.Threading.CancellationToken)" - } - ], - "ReturnType": "System.Threading.Tasks.Task", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "CopyToAsync", - "Parameters": [ - { - "Name": "destination", - "Type": "System.IO.Stream" - }, - { - "Name": "cancellationToken", - "Type": "System.Threading.CancellationToken", - "DefaultValue": "default(System.Threading.CancellationToken)" - } - ], - "ReturnType": "System.Threading.Tasks.Task", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ConsumeAsync", - "Parameters": [ - { - "Name": "cancellationToken", - "Type": "System.Threading.CancellationToken", - "DefaultValue": "default(System.Threading.CancellationToken)" - } - ], - "ReturnType": "System.Threading.Tasks.Task", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "StopAsync", - "Parameters": [], - "ReturnType": "System.Threading.Tasks.Task", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Copy", - "Parameters": [ - { - "Name": "readableBuffer", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.ReadableBuffer" - }, - { - "Name": "writableBuffer", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.WritableBuffer" - } - ], - "ReturnType": "System.Void", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Read", - "Parameters": [ - { - "Name": "readableBuffer", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.ReadableBuffer" - }, - { - "Name": "writableBuffer", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.WritableBuffer" - }, - { - "Name": "consumed", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.ReadCursor", - "Direction": "Out" - }, - { - "Name": "examined", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.ReadCursor", - "Direction": "Out" - } - ], - "ReturnType": "System.Boolean", - "Virtual": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "OnReadStart", - "Parameters": [], - "ReturnType": "System.Void", - "Virtual": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "For", - "Parameters": [ - { - "Name": "httpVersion", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpVersion" - }, - { - "Name": "headers", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.FrameRequestHeaders" - }, - { - "Name": "context", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.Frame" - } - ], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.MessageBody", - "Static": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "context", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.Frame" - } - ], - "Visibility": "Protected", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.OutputProducer", - "Visibility": "Public", - "Kind": "Class", - "ImplementedInterfaces": [ - "System.IDisposable" - ], - "Members": [ - { - "Kind": "Method", - "Name": "WriteAsync", - "Parameters": [ - { - "Name": "buffer", - "Type": "System.ArraySegment" - }, - { - "Name": "chunk", - "Type": "System.Boolean", - "DefaultValue": "False" - }, - { - "Name": "cancellationToken", - "Type": "System.Threading.CancellationToken", - "DefaultValue": "default(System.Threading.CancellationToken)" - } - ], - "ReturnType": "System.Threading.Tasks.Task", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "FlushAsync", - "Parameters": [ - { - "Name": "cancellationToken", - "Type": "System.Threading.CancellationToken", - "DefaultValue": "default(System.Threading.CancellationToken)" - } - ], - "ReturnType": "System.Threading.Tasks.Task", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Write", - "Parameters": [ - { - "Name": "callback", - "Type": "System.Action" - }, - { - "Name": "state", - "Type": "T0" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [ - { - "ParameterName": "T", - "ParameterPosition": 0, - "BaseTypeOrInterfaces": [] - } - ] - }, - { - "Kind": "Method", - "Name": "Dispose", - "Parameters": [], - "ReturnType": "System.Void", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "System.IDisposable", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Abort", - "Parameters": [ - { - "Name": "error", - "Type": "System.Exception" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "pipe", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.IPipe" - }, - { - "Name": "connectionId", - "Type": "System.String" - }, - { - "Name": "log", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure.IKestrelTrace" - }, - { - "Name": "timeoutControl", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure.ITimeoutControl" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.PathNormalizer", - "Visibility": "Public", - "Kind": "Class", - "Abstract": true, - "Static": true, - "Sealed": true, - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "RemoveDotSegments", - "Parameters": [ - { - "Name": "input", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Span" - } - ], - "ReturnType": "System.Int32", - "Static": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "RemoveDotSegments", - "Parameters": [ - { - "Name": "start", - "Type": "System.Byte*" - }, - { - "Name": "end", - "Type": "System.Byte*" - } - ], - "ReturnType": "System.Int32", - "Static": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ContainsDotSegments", - "Parameters": [ - { - "Name": "start", - "Type": "System.Byte*" - }, - { - "Name": "end", - "Type": "System.Byte*" - } - ], - "ReturnType": "System.Boolean", - "Static": true, - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.PipelineExtensions", - "Visibility": "Public", - "Kind": "Class", - "Abstract": true, - "Static": true, - "Sealed": true, - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "ToSpan", - "Parameters": [ - { - "Name": "buffer", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.ReadableBuffer" - } - ], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Span", - "Static": true, - "Extension": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "GetArray", - "Parameters": [ - { - "Name": "buffer", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Buffers.Buffer" - } - ], - "ReturnType": "System.ArraySegment", - "Static": true, - "Extension": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "WriteAsciiNoValidation", - "Parameters": [ - { - "Name": "buffer", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.WritableBufferWriter", - "Direction": "Ref" - }, - { - "Name": "data", - "Type": "System.String" - } - ], - "ReturnType": "System.Void", - "Static": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "WriteNumeric", - "Parameters": [ - { - "Name": "buffer", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.WritableBufferWriter", - "Direction": "Ref" - }, - { - "Name": "number", - "Type": "System.UInt64" - } - ], - "ReturnType": "System.Void", - "Static": true, - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.ProduceEndType", - "Visibility": "Public", - "Kind": "Enumeration", - "Sealed": true, - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Field", - "Name": "SocketShutdown", - "Parameters": [], - "GenericParameter": [], - "Literal": "0" - }, - { - "Kind": "Field", - "Name": "SocketDisconnect", - "Parameters": [], - "GenericParameter": [], - "Literal": "1" - }, - { - "Kind": "Field", - "Name": "ConnectionKeepAlive", - "Parameters": [], - "GenericParameter": [], - "Literal": "2" - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.ReasonPhrases", - "Visibility": "Public", - "Kind": "Class", - "Abstract": true, - "Static": true, - "Sealed": true, - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "ToStatusBytes", - "Parameters": [ - { - "Name": "statusCode", - "Type": "System.Int32" - }, - { - "Name": "reasonPhrase", - "Type": "System.String", - "DefaultValue": "null" - } - ], - "ReturnType": "System.Byte[]", - "Static": true, - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.RequestProcessingStatus", - "Visibility": "Public", - "Kind": "Enumeration", - "Sealed": true, - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Field", - "Name": "RequestPending", - "Parameters": [], - "GenericParameter": [], - "Literal": "0" - }, - { - "Kind": "Field", - "Name": "ParsingRequestLine", - "Parameters": [], - "GenericParameter": [], - "Literal": "1" - }, - { - "Kind": "Field", - "Name": "ParsingHeaders", - "Parameters": [], - "GenericParameter": [], - "Literal": "2" - }, - { - "Kind": "Field", - "Name": "AppStarted", - "Parameters": [], - "GenericParameter": [], - "Literal": "3" - }, - { - "Kind": "Field", - "Name": "ResponseStarted", - "Parameters": [], - "GenericParameter": [], - "Literal": "4" - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.RequestRejectionReason", - "Visibility": "Public", - "Kind": "Enumeration", - "Sealed": true, - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Field", - "Name": "UnrecognizedHTTPVersion", - "Parameters": [], - "GenericParameter": [], - "Literal": "0" - }, - { - "Kind": "Field", - "Name": "InvalidRequestLine", - "Parameters": [], - "GenericParameter": [], - "Literal": "1" - }, - { - "Kind": "Field", - "Name": "InvalidRequestHeader", - "Parameters": [], - "GenericParameter": [], - "Literal": "2" - }, - { - "Kind": "Field", - "Name": "InvalidRequestHeadersNoCRLF", - "Parameters": [], - "GenericParameter": [], - "Literal": "3" - }, - { - "Kind": "Field", - "Name": "MalformedRequestInvalidHeaders", - "Parameters": [], - "GenericParameter": [], - "Literal": "4" - }, - { - "Kind": "Field", - "Name": "InvalidContentLength", - "Parameters": [], - "GenericParameter": [], - "Literal": "5" - }, - { - "Kind": "Field", - "Name": "MultipleContentLengths", - "Parameters": [], - "GenericParameter": [], - "Literal": "6" - }, - { - "Kind": "Field", - "Name": "UnexpectedEndOfRequestContent", - "Parameters": [], - "GenericParameter": [], - "Literal": "7" - }, - { - "Kind": "Field", - "Name": "BadChunkSuffix", - "Parameters": [], - "GenericParameter": [], - "Literal": "8" - }, - { - "Kind": "Field", - "Name": "BadChunkSizeData", - "Parameters": [], - "GenericParameter": [], - "Literal": "9" - }, - { - "Kind": "Field", - "Name": "ChunkedRequestIncomplete", - "Parameters": [], - "GenericParameter": [], - "Literal": "10" - }, - { - "Kind": "Field", - "Name": "InvalidRequestTarget", - "Parameters": [], - "GenericParameter": [], - "Literal": "11" - }, - { - "Kind": "Field", - "Name": "InvalidCharactersInHeaderName", - "Parameters": [], - "GenericParameter": [], - "Literal": "12" - }, - { - "Kind": "Field", - "Name": "RequestLineTooLong", - "Parameters": [], - "GenericParameter": [], - "Literal": "13" - }, - { - "Kind": "Field", - "Name": "HeadersExceedMaxTotalSize", - "Parameters": [], - "GenericParameter": [], - "Literal": "14" - }, - { - "Kind": "Field", - "Name": "TooManyHeaders", - "Parameters": [], - "GenericParameter": [], - "Literal": "15" - }, - { - "Kind": "Field", - "Name": "RequestBodyTooLarge", - "Parameters": [], - "GenericParameter": [], - "Literal": "16" - }, - { - "Kind": "Field", - "Name": "RequestTimeout", - "Parameters": [], - "GenericParameter": [], - "Literal": "17" - }, - { - "Kind": "Field", - "Name": "FinalTransferCodingNotChunked", - "Parameters": [], - "GenericParameter": [], - "Literal": "18" - }, - { - "Kind": "Field", - "Name": "LengthRequired", - "Parameters": [], - "GenericParameter": [], - "Literal": "19" - }, - { - "Kind": "Field", - "Name": "LengthRequiredHttp10", - "Parameters": [], - "GenericParameter": [], - "Literal": "20" - }, - { - "Kind": "Field", - "Name": "OptionsMethodRequired", - "Parameters": [], - "GenericParameter": [], - "Literal": "21" - }, - { - "Kind": "Field", - "Name": "ConnectMethodRequired", - "Parameters": [], - "GenericParameter": [], - "Literal": "22" - }, - { - "Kind": "Field", - "Name": "MissingHostHeader", - "Parameters": [], - "GenericParameter": [], - "Literal": "23" - }, - { - "Kind": "Field", - "Name": "MultipleHostHeaders", - "Parameters": [], - "GenericParameter": [], - "Literal": "24" - }, - { - "Kind": "Field", - "Name": "InvalidHostHeader", - "Parameters": [], - "GenericParameter": [], - "Literal": "25" - }, - { - "Kind": "Field", - "Name": "UpgradeRequestCannotHavePayload", - "Parameters": [], - "GenericParameter": [], - "Literal": "26" - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.TransferCoding", - "Visibility": "Public", - "Kind": "Enumeration", - "Sealed": true, - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Field", - "Name": "None", - "Parameters": [], - "GenericParameter": [], - "Literal": "0" - }, - { - "Kind": "Field", - "Name": "Chunked", - "Parameters": [], - "GenericParameter": [], - "Literal": "1" - }, - { - "Kind": "Field", - "Name": "Other", - "Parameters": [], - "GenericParameter": [], - "Literal": "2" - } - ], - "GenericParameters": [] - }, { "Name": "Microsoft.AspNetCore.Server.Kestrel.Core.Features.IHttpMinRequestBodyDataRateFeature", "Visibility": "Public", @@ -9460,681 +1069,6 @@ } ], "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal.AdaptedPipeline", - "Visibility": "Public", - "Kind": "Class", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "get_Input", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.IPipe", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_Output", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.IPipe", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "RunAsync", - "Parameters": [ - { - "Name": "stream", - "Type": "System.IO.Stream" - } - ], - "ReturnType": "System.Threading.Tasks.Task", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "transportInputPipeReader", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.IPipeReader" - }, - { - "Name": "transportOutputPipe", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.IPipe" - }, - { - "Name": "inputPipe", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.IPipe" - }, - { - "Name": "outputPipe", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.IPipe" - }, - { - "Name": "trace", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure.IKestrelTrace" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal.ConnectionAdapterContext", - "Visibility": "Public", - "Kind": "Class", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "get_Features", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Http.Features.IFeatureCollection", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_ConnectionStream", - "Parameters": [], - "ReturnType": "System.IO.Stream", - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal.IAdaptedConnection", - "Visibility": "Public", - "Kind": "Interface", - "Abstract": true, - "ImplementedInterfaces": [ - "System.IDisposable" - ], - "Members": [ - { - "Kind": "Method", - "Name": "get_ConnectionStream", - "Parameters": [], - "ReturnType": "System.IO.Stream", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal.IConnectionAdapter", - "Visibility": "Public", - "Kind": "Interface", - "Abstract": true, - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "get_IsHttps", - "Parameters": [], - "ReturnType": "System.Boolean", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "OnConnectionAsync", - "Parameters": [ - { - "Name": "context", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal.ConnectionAdapterContext" - } - ], - "ReturnType": "System.Threading.Tasks.Task", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal.LoggingConnectionAdapter", - "Visibility": "Public", - "Kind": "Class", - "ImplementedInterfaces": [ - "Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal.IConnectionAdapter" - ], - "Members": [ - { - "Kind": "Method", - "Name": "get_IsHttps", - "Parameters": [], - "ReturnType": "System.Boolean", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal.IConnectionAdapter", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "OnConnectionAsync", - "Parameters": [ - { - "Name": "context", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal.ConnectionAdapterContext" - } - ], - "ReturnType": "System.Threading.Tasks.Task", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal.IConnectionAdapter", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "logger", - "Type": "Microsoft.Extensions.Logging.ILogger" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal.RawStream", - "Visibility": "Public", - "Kind": "Class", - "BaseType": "System.IO.Stream", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "get_CanRead", - "Parameters": [], - "ReturnType": "System.Boolean", - "Virtual": true, - "Override": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_CanSeek", - "Parameters": [], - "ReturnType": "System.Boolean", - "Virtual": true, - "Override": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_CanWrite", - "Parameters": [], - "ReturnType": "System.Boolean", - "Virtual": true, - "Override": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_Length", - "Parameters": [], - "ReturnType": "System.Int64", - "Virtual": true, - "Override": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_Position", - "Parameters": [], - "ReturnType": "System.Int64", - "Virtual": true, - "Override": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_Position", - "Parameters": [ - { - "Name": "value", - "Type": "System.Int64" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "Override": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Seek", - "Parameters": [ - { - "Name": "offset", - "Type": "System.Int64" - }, - { - "Name": "origin", - "Type": "System.IO.SeekOrigin" - } - ], - "ReturnType": "System.Int64", - "Virtual": true, - "Override": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "SetLength", - "Parameters": [ - { - "Name": "value", - "Type": "System.Int64" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "Override": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Read", - "Parameters": [ - { - "Name": "buffer", - "Type": "System.Byte[]" - }, - { - "Name": "offset", - "Type": "System.Int32" - }, - { - "Name": "count", - "Type": "System.Int32" - } - ], - "ReturnType": "System.Int32", - "Virtual": true, - "Override": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ReadAsync", - "Parameters": [ - { - "Name": "buffer", - "Type": "System.Byte[]" - }, - { - "Name": "offset", - "Type": "System.Int32" - }, - { - "Name": "count", - "Type": "System.Int32" - }, - { - "Name": "cancellationToken", - "Type": "System.Threading.CancellationToken" - } - ], - "ReturnType": "System.Threading.Tasks.Task", - "Virtual": true, - "Override": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Write", - "Parameters": [ - { - "Name": "buffer", - "Type": "System.Byte[]" - }, - { - "Name": "offset", - "Type": "System.Int32" - }, - { - "Name": "count", - "Type": "System.Int32" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "Override": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "WriteAsync", - "Parameters": [ - { - "Name": "buffer", - "Type": "System.Byte[]" - }, - { - "Name": "offset", - "Type": "System.Int32" - }, - { - "Name": "count", - "Type": "System.Int32" - }, - { - "Name": "token", - "Type": "System.Threading.CancellationToken" - } - ], - "ReturnType": "System.Threading.Tasks.Task", - "Virtual": true, - "Override": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Flush", - "Parameters": [], - "ReturnType": "System.Void", - "Virtual": true, - "Override": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "FlushAsync", - "Parameters": [ - { - "Name": "cancellationToken", - "Type": "System.Threading.CancellationToken" - } - ], - "ReturnType": "System.Threading.Tasks.Task", - "Virtual": true, - "Override": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "BeginRead", - "Parameters": [ - { - "Name": "buffer", - "Type": "System.Byte[]" - }, - { - "Name": "offset", - "Type": "System.Int32" - }, - { - "Name": "count", - "Type": "System.Int32" - }, - { - "Name": "callback", - "Type": "System.AsyncCallback" - }, - { - "Name": "state", - "Type": "System.Object" - } - ], - "ReturnType": "System.IAsyncResult", - "Virtual": true, - "Override": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "EndRead", - "Parameters": [ - { - "Name": "asyncResult", - "Type": "System.IAsyncResult" - } - ], - "ReturnType": "System.Int32", - "Virtual": true, - "Override": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "BeginWrite", - "Parameters": [ - { - "Name": "buffer", - "Type": "System.Byte[]" - }, - { - "Name": "offset", - "Type": "System.Int32" - }, - { - "Name": "count", - "Type": "System.Int32" - }, - { - "Name": "callback", - "Type": "System.AsyncCallback" - }, - { - "Name": "state", - "Type": "System.Object" - } - ], - "ReturnType": "System.IAsyncResult", - "Virtual": true, - "Override": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "EndWrite", - "Parameters": [ - { - "Name": "asyncResult", - "Type": "System.IAsyncResult" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "Override": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "input", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.IPipeReader" - }, - { - "Name": "output", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.IPipeWriter" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.DateHeaderValueManager+DateHeaderValues", - "Visibility": "Public", - "Kind": "Class", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [], - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "Bytes", - "Parameters": [], - "ReturnType": "System.Byte[]", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "String", - "Parameters": [], - "ReturnType": "System.String", - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.FrameRequestHeaders+Enumerator", - "Visibility": "Public", - "Kind": "Struct", - "Sealed": true, - "ImplementedInterfaces": [ - "System.Collections.Generic.IEnumerator>" - ], - "Members": [ - { - "Kind": "Method", - "Name": "MoveNext", - "Parameters": [], - "ReturnType": "System.Boolean", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "System.Collections.IEnumerator", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_Current", - "Parameters": [], - "ReturnType": "System.Collections.Generic.KeyValuePair", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "System.Collections.Generic.IEnumerator>", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Dispose", - "Parameters": [], - "ReturnType": "System.Void", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "System.IDisposable", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Reset", - "Parameters": [], - "ReturnType": "System.Void", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "System.Collections.IEnumerator", - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.FrameResponseHeaders+Enumerator", - "Visibility": "Public", - "Kind": "Struct", - "Sealed": true, - "ImplementedInterfaces": [ - "System.Collections.Generic.IEnumerator>" - ], - "Members": [ - { - "Kind": "Method", - "Name": "MoveNext", - "Parameters": [], - "ReturnType": "System.Boolean", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "System.Collections.IEnumerator", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_Current", - "Parameters": [], - "ReturnType": "System.Collections.Generic.KeyValuePair", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "System.Collections.Generic.IEnumerator>", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Dispose", - "Parameters": [], - "ReturnType": "System.Void", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "System.IDisposable", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Reset", - "Parameters": [], - "ReturnType": "System.Void", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "System.Collections.IEnumerator", - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] } ] } \ No newline at end of file diff --git a/src/Kestrel.Https/baseline.netcore.json b/src/Kestrel.Https/baseline.netcore.json index 993f1a1008..4919ecc705 100644 --- a/src/Kestrel.Https/baseline.netcore.json +++ b/src/Kestrel.Https/baseline.netcore.json @@ -1,5 +1,5 @@ { - "AssemblyIdentity": "Microsoft.AspNetCore.Server.Kestrel.Https, Version=2.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60", + "AssemblyIdentity": "Microsoft.AspNetCore.Server.Kestrel.Https, Version=2.0.2.0, Culture=neutral, PublicKeyToken=adb9793829ddae60", "Types": [ { "Name": "Microsoft.AspNetCore.Hosting.ListenOptionsHttpsExtensions", @@ -244,72 +244,6 @@ } ], "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Https.Internal.HttpsConnectionAdapter", - "Visibility": "Public", - "Kind": "Class", - "ImplementedInterfaces": [ - "Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal.IConnectionAdapter" - ], - "Members": [ - { - "Kind": "Method", - "Name": "get_IsHttps", - "Parameters": [], - "ReturnType": "System.Boolean", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal.IConnectionAdapter", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "OnConnectionAsync", - "Parameters": [ - { - "Name": "context", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal.ConnectionAdapterContext" - } - ], - "ReturnType": "System.Threading.Tasks.Task", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal.IConnectionAdapter", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "options", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Https.HttpsConnectionAdapterOptions" - } - ], - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "options", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Https.HttpsConnectionAdapterOptions" - }, - { - "Name": "loggerFactory", - "Type": "Microsoft.Extensions.Logging.ILoggerFactory" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] } ] } \ No newline at end of file diff --git a/src/Kestrel.Transport.Abstractions/baseline.netcore.json b/src/Kestrel.Transport.Abstractions/baseline.netcore.json index 5a9e781d56..15710d1a41 100644 --- a/src/Kestrel.Transport.Abstractions/baseline.netcore.json +++ b/src/Kestrel.Transport.Abstractions/baseline.netcore.json @@ -1,6444 +1,4 @@ { - "AssemblyIdentity": "Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions, Version=2.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60", - "Types": [ - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal.AddressInUseException", - "Visibility": "Public", - "Kind": "Class", - "BaseType": "System.InvalidOperationException", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "message", - "Type": "System.String" - } - ], - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "message", - "Type": "System.String" - }, - { - "Name": "inner", - "Type": "System.Exception" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal.ConnectionAbortedException", - "Visibility": "Public", - "Kind": "Class", - "BaseType": "System.OperationCanceledException", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [], - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "message", - "Type": "System.String" - } - ], - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "message", - "Type": "System.String" - }, - { - "Name": "inner", - "Type": "System.Exception" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal.ConnectionResetException", - "Visibility": "Public", - "Kind": "Class", - "BaseType": "System.IO.IOException", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "message", - "Type": "System.String" - } - ], - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "message", - "Type": "System.String" - }, - { - "Name": "inner", - "Type": "System.Exception" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal.FileHandleType", - "Visibility": "Public", - "Kind": "Enumeration", - "Sealed": true, - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Field", - "Name": "Auto", - "Parameters": [], - "GenericParameter": [], - "Literal": "0" - }, - { - "Kind": "Field", - "Name": "Tcp", - "Parameters": [], - "GenericParameter": [], - "Literal": "1" - }, - { - "Kind": "Field", - "Name": "Pipe", - "Parameters": [], - "GenericParameter": [], - "Literal": "2" - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal.IConnectionContext", - "Visibility": "Public", - "Kind": "Interface", - "Abstract": true, - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "get_ConnectionId", - "Parameters": [], - "ReturnType": "System.String", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_Input", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.IPipeWriter", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_Output", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.IPipeReader", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "OnConnectionClosed", - "Parameters": [ - { - "Name": "ex", - "Type": "System.Exception" - } - ], - "ReturnType": "System.Void", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Abort", - "Parameters": [ - { - "Name": "ex", - "Type": "System.Exception" - } - ], - "ReturnType": "System.Void", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal.IConnectionHandler", - "Visibility": "Public", - "Kind": "Interface", - "Abstract": true, - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "OnConnection", - "Parameters": [ - { - "Name": "connectionInfo", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal.IConnectionInformation" - } - ], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal.IConnectionContext", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal.IConnectionInformation", - "Visibility": "Public", - "Kind": "Interface", - "Abstract": true, - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "get_RemoteEndPoint", - "Parameters": [], - "ReturnType": "System.Net.IPEndPoint", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_LocalEndPoint", - "Parameters": [], - "ReturnType": "System.Net.IPEndPoint", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_PipeFactory", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.PipeFactory", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_InputWriterScheduler", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.IScheduler", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_OutputReaderScheduler", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.IScheduler", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal.IEndPointInformation", - "Visibility": "Public", - "Kind": "Interface", - "Abstract": true, - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "get_Type", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal.ListenType", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_IPEndPoint", - "Parameters": [], - "ReturnType": "System.Net.IPEndPoint", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_IPEndPoint", - "Parameters": [ - { - "Name": "value", - "Type": "System.Net.IPEndPoint" - } - ], - "ReturnType": "System.Void", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_SocketPath", - "Parameters": [], - "ReturnType": "System.String", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_FileHandle", - "Parameters": [], - "ReturnType": "System.UInt64", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HandleType", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal.FileHandleType", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_HandleType", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal.FileHandleType" - } - ], - "ReturnType": "System.Void", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_NoDelay", - "Parameters": [], - "ReturnType": "System.Boolean", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal.ITransport", - "Visibility": "Public", - "Kind": "Interface", - "Abstract": true, - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "BindAsync", - "Parameters": [], - "ReturnType": "System.Threading.Tasks.Task", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "UnbindAsync", - "Parameters": [], - "ReturnType": "System.Threading.Tasks.Task", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "StopAsync", - "Parameters": [], - "ReturnType": "System.Threading.Tasks.Task", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal.ITransportFactory", - "Visibility": "Public", - "Kind": "Interface", - "Abstract": true, - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "Create", - "Parameters": [ - { - "Name": "endPointInformation", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal.IEndPointInformation" - }, - { - "Name": "handler", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal.IConnectionHandler" - } - ], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal.ITransport", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal.ListenType", - "Visibility": "Public", - "Kind": "Enumeration", - "Sealed": true, - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Field", - "Name": "IPEndPoint", - "Parameters": [], - "GenericParameter": [], - "Literal": "0" - }, - { - "Kind": "Field", - "Name": "SocketPath", - "Parameters": [], - "GenericParameter": [], - "Literal": "1" - }, - { - "Kind": "Field", - "Name": "FileHandle", - "Parameters": [], - "GenericParameter": [], - "Literal": "2" - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal.SchedulingMode", - "Visibility": "Public", - "Kind": "Enumeration", - "Sealed": true, - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Field", - "Name": "Default", - "Parameters": [], - "GenericParameter": [], - "Literal": "0" - }, - { - "Kind": "Field", - "Name": "ThreadPool", - "Parameters": [], - "GenericParameter": [], - "Literal": "1" - }, - { - "Kind": "Field", - "Name": "Inline", - "Parameters": [], - "GenericParameter": [], - "Literal": "2" - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.ReadOnlySpan", - "Visibility": "Public", - "Kind": "Struct", - "Sealed": true, - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "DangerousCreate", - "Parameters": [ - { - "Name": "obj", - "Type": "System.Object" - }, - { - "Name": "objectData", - "Type": "T0", - "Direction": "Ref" - }, - { - "Name": "length", - "Type": "System.Int32" - } - ], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.ReadOnlySpan", - "Static": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_Length", - "Parameters": [], - "ReturnType": "System.Int32", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_IsEmpty", - "Parameters": [], - "ReturnType": "System.Boolean", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_Item", - "Parameters": [ - { - "Name": "index", - "Type": "System.Int32" - } - ], - "ReturnType": "T0", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "CopyTo", - "Parameters": [ - { - "Name": "destination", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Span" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "TryCopyTo", - "Parameters": [ - { - "Name": "destination", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Span" - } - ], - "ReturnType": "System.Boolean", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "op_Equality", - "Parameters": [ - { - "Name": "left", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.ReadOnlySpan" - }, - { - "Name": "right", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.ReadOnlySpan" - } - ], - "ReturnType": "System.Boolean", - "Static": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "op_Inequality", - "Parameters": [ - { - "Name": "left", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.ReadOnlySpan" - }, - { - "Name": "right", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.ReadOnlySpan" - } - ], - "ReturnType": "System.Boolean", - "Static": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Equals", - "Parameters": [ - { - "Name": "obj", - "Type": "System.Object" - } - ], - "ReturnType": "System.Boolean", - "Virtual": true, - "Override": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "GetHashCode", - "Parameters": [], - "ReturnType": "System.Int32", - "Virtual": true, - "Override": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "op_Implicit", - "Parameters": [ - { - "Name": "array", - "Type": "T0[]" - } - ], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.ReadOnlySpan", - "Static": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "op_Implicit", - "Parameters": [ - { - "Name": "arraySegment", - "Type": "System.ArraySegment" - } - ], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.ReadOnlySpan", - "Static": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Slice", - "Parameters": [ - { - "Name": "start", - "Type": "System.Int32" - } - ], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.ReadOnlySpan", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Slice", - "Parameters": [ - { - "Name": "start", - "Type": "System.Int32" - }, - { - "Name": "length", - "Type": "System.Int32" - } - ], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.ReadOnlySpan", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ToArray", - "Parameters": [], - "ReturnType": "T0[]", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_Empty", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.ReadOnlySpan", - "Static": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "DangerousGetPinnableReference", - "Parameters": [], - "ReturnType": "T0", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "array", - "Type": "T0[]" - } - ], - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "array", - "Type": "T0[]" - }, - { - "Name": "start", - "Type": "System.Int32" - } - ], - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "array", - "Type": "T0[]" - }, - { - "Name": "start", - "Type": "System.Int32" - }, - { - "Name": "length", - "Type": "System.Int32" - } - ], - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "pointer", - "Type": "System.Void*" - }, - { - "Name": "length", - "Type": "System.Int32" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [ - { - "ParameterName": "T", - "ParameterPosition": 0, - "BaseTypeOrInterfaces": [] - } - ] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Span", - "Visibility": "Public", - "Kind": "Struct", - "Sealed": true, - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "DangerousCreate", - "Parameters": [ - { - "Name": "obj", - "Type": "System.Object" - }, - { - "Name": "objectData", - "Type": "T0", - "Direction": "Ref" - }, - { - "Name": "length", - "Type": "System.Int32" - } - ], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Span", - "Static": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_Length", - "Parameters": [], - "ReturnType": "System.Int32", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_IsEmpty", - "Parameters": [], - "ReturnType": "System.Boolean", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_Item", - "Parameters": [ - { - "Name": "index", - "Type": "System.Int32" - } - ], - "ReturnType": "T0", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Clear", - "Parameters": [], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Fill", - "Parameters": [ - { - "Name": "value", - "Type": "T0" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "CopyTo", - "Parameters": [ - { - "Name": "destination", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Span" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "TryCopyTo", - "Parameters": [ - { - "Name": "destination", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Span" - } - ], - "ReturnType": "System.Boolean", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "op_Equality", - "Parameters": [ - { - "Name": "left", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Span" - }, - { - "Name": "right", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Span" - } - ], - "ReturnType": "System.Boolean", - "Static": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "op_Inequality", - "Parameters": [ - { - "Name": "left", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Span" - }, - { - "Name": "right", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Span" - } - ], - "ReturnType": "System.Boolean", - "Static": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Equals", - "Parameters": [ - { - "Name": "obj", - "Type": "System.Object" - } - ], - "ReturnType": "System.Boolean", - "Virtual": true, - "Override": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "GetHashCode", - "Parameters": [], - "ReturnType": "System.Int32", - "Virtual": true, - "Override": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "op_Implicit", - "Parameters": [ - { - "Name": "array", - "Type": "T0[]" - } - ], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Span", - "Static": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "op_Implicit", - "Parameters": [ - { - "Name": "arraySegment", - "Type": "System.ArraySegment" - } - ], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Span", - "Static": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "op_Implicit", - "Parameters": [ - { - "Name": "span", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Span" - } - ], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.ReadOnlySpan", - "Static": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Slice", - "Parameters": [ - { - "Name": "start", - "Type": "System.Int32" - } - ], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Span", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Slice", - "Parameters": [ - { - "Name": "start", - "Type": "System.Int32" - }, - { - "Name": "length", - "Type": "System.Int32" - } - ], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Span", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ToArray", - "Parameters": [], - "ReturnType": "T0[]", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_Empty", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Span", - "Static": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "DangerousGetPinnableReference", - "Parameters": [], - "ReturnType": "T0", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "array", - "Type": "T0[]" - } - ], - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "array", - "Type": "T0[]" - }, - { - "Name": "start", - "Type": "System.Int32" - } - ], - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "array", - "Type": "T0[]" - }, - { - "Name": "start", - "Type": "System.Int32" - }, - { - "Name": "length", - "Type": "System.Int32" - } - ], - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "pointer", - "Type": "System.Void*" - }, - { - "Name": "length", - "Type": "System.Int32" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [ - { - "ParameterName": "T", - "ParameterPosition": 0, - "BaseTypeOrInterfaces": [] - } - ] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.SpanExtensions", - "Visibility": "Public", - "Kind": "Class", - "Abstract": true, - "Static": true, - "Sealed": true, - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "AsBytes", - "Parameters": [ - { - "Name": "source", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Span" - } - ], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Span", - "Static": true, - "Extension": true, - "Visibility": "Public", - "GenericParameter": [ - { - "ParameterName": "T", - "ParameterPosition": 0, - "New": true, - "Struct": true, - "BaseTypeOrInterfaces": [] - } - ] - }, - { - "Kind": "Method", - "Name": "AsBytes", - "Parameters": [ - { - "Name": "source", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.ReadOnlySpan" - } - ], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.ReadOnlySpan", - "Static": true, - "Extension": true, - "Visibility": "Public", - "GenericParameter": [ - { - "ParameterName": "T", - "ParameterPosition": 0, - "New": true, - "Struct": true, - "BaseTypeOrInterfaces": [] - } - ] - }, - { - "Kind": "Method", - "Name": "AsSpan", - "Parameters": [ - { - "Name": "text", - "Type": "System.String" - } - ], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.ReadOnlySpan", - "Static": true, - "Extension": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "NonPortableCast", - "Parameters": [ - { - "Name": "source", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Span" - } - ], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Span", - "Static": true, - "Extension": true, - "Visibility": "Public", - "GenericParameter": [ - { - "ParameterName": "TFrom", - "ParameterPosition": 0, - "New": true, - "Struct": true, - "BaseTypeOrInterfaces": [] - }, - { - "ParameterName": "TTo", - "ParameterPosition": 1, - "New": true, - "Struct": true, - "BaseTypeOrInterfaces": [] - } - ] - }, - { - "Kind": "Method", - "Name": "NonPortableCast", - "Parameters": [ - { - "Name": "source", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.ReadOnlySpan" - } - ], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.ReadOnlySpan", - "Static": true, - "Extension": true, - "Visibility": "Public", - "GenericParameter": [ - { - "ParameterName": "TFrom", - "ParameterPosition": 0, - "New": true, - "Struct": true, - "BaseTypeOrInterfaces": [] - }, - { - "ParameterName": "TTo", - "ParameterPosition": 1, - "New": true, - "Struct": true, - "BaseTypeOrInterfaces": [] - } - ] - }, - { - "Kind": "Method", - "Name": "IndexOf", - "Parameters": [ - { - "Name": "span", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Span" - }, - { - "Name": "value", - "Type": "T0" - } - ], - "ReturnType": "System.Int32", - "Static": true, - "Extension": true, - "Visibility": "Public", - "GenericParameter": [ - { - "ParameterName": "T", - "ParameterPosition": 0, - "New": true, - "Struct": true, - "BaseTypeOrInterfaces": [ - "System.IEquatable" - ] - } - ] - }, - { - "Kind": "Method", - "Name": "IndexOf", - "Parameters": [ - { - "Name": "span", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Span" - }, - { - "Name": "value", - "Type": "System.Byte" - } - ], - "ReturnType": "System.Int32", - "Static": true, - "Extension": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "IndexOf", - "Parameters": [ - { - "Name": "span", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Span" - }, - { - "Name": "value", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.ReadOnlySpan" - } - ], - "ReturnType": "System.Int32", - "Static": true, - "Extension": true, - "Visibility": "Public", - "GenericParameter": [ - { - "ParameterName": "T", - "ParameterPosition": 0, - "New": true, - "Struct": true, - "BaseTypeOrInterfaces": [ - "System.IEquatable" - ] - } - ] - }, - { - "Kind": "Method", - "Name": "IndexOf", - "Parameters": [ - { - "Name": "span", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Span" - }, - { - "Name": "value", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.ReadOnlySpan" - } - ], - "ReturnType": "System.Int32", - "Static": true, - "Extension": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "SequenceEqual", - "Parameters": [ - { - "Name": "first", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Span" - }, - { - "Name": "second", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.ReadOnlySpan" - } - ], - "ReturnType": "System.Boolean", - "Static": true, - "Extension": true, - "Visibility": "Public", - "GenericParameter": [ - { - "ParameterName": "T", - "ParameterPosition": 0, - "New": true, - "Struct": true, - "BaseTypeOrInterfaces": [ - "System.IEquatable" - ] - } - ] - }, - { - "Kind": "Method", - "Name": "SequenceEqual", - "Parameters": [ - { - "Name": "first", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Span" - }, - { - "Name": "second", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.ReadOnlySpan" - } - ], - "ReturnType": "System.Boolean", - "Static": true, - "Extension": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "IndexOf", - "Parameters": [ - { - "Name": "span", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.ReadOnlySpan" - }, - { - "Name": "value", - "Type": "T0" - } - ], - "ReturnType": "System.Int32", - "Static": true, - "Extension": true, - "Visibility": "Public", - "GenericParameter": [ - { - "ParameterName": "T", - "ParameterPosition": 0, - "New": true, - "Struct": true, - "BaseTypeOrInterfaces": [ - "System.IEquatable" - ] - } - ] - }, - { - "Kind": "Method", - "Name": "IndexOf", - "Parameters": [ - { - "Name": "span", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.ReadOnlySpan" - }, - { - "Name": "value", - "Type": "System.Byte" - } - ], - "ReturnType": "System.Int32", - "Static": true, - "Extension": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "IndexOf", - "Parameters": [ - { - "Name": "span", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.ReadOnlySpan" - }, - { - "Name": "value", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.ReadOnlySpan" - } - ], - "ReturnType": "System.Int32", - "Static": true, - "Extension": true, - "Visibility": "Public", - "GenericParameter": [ - { - "ParameterName": "T", - "ParameterPosition": 0, - "New": true, - "Struct": true, - "BaseTypeOrInterfaces": [ - "System.IEquatable" - ] - } - ] - }, - { - "Kind": "Method", - "Name": "IndexOf", - "Parameters": [ - { - "Name": "span", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.ReadOnlySpan" - }, - { - "Name": "value", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.ReadOnlySpan" - } - ], - "ReturnType": "System.Int32", - "Static": true, - "Extension": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "IndexOfAny", - "Parameters": [ - { - "Name": "span", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Span" - }, - { - "Name": "value0", - "Type": "System.Byte" - }, - { - "Name": "value1", - "Type": "System.Byte" - } - ], - "ReturnType": "System.Int32", - "Static": true, - "Extension": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "IndexOfAny", - "Parameters": [ - { - "Name": "span", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Span" - }, - { - "Name": "value0", - "Type": "System.Byte" - }, - { - "Name": "value1", - "Type": "System.Byte" - }, - { - "Name": "value2", - "Type": "System.Byte" - } - ], - "ReturnType": "System.Int32", - "Static": true, - "Extension": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "IndexOfAny", - "Parameters": [ - { - "Name": "span", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Span" - }, - { - "Name": "values", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.ReadOnlySpan" - } - ], - "ReturnType": "System.Int32", - "Static": true, - "Extension": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "IndexOfAny", - "Parameters": [ - { - "Name": "span", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.ReadOnlySpan" - }, - { - "Name": "value0", - "Type": "System.Byte" - }, - { - "Name": "value1", - "Type": "System.Byte" - } - ], - "ReturnType": "System.Int32", - "Static": true, - "Extension": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "IndexOfAny", - "Parameters": [ - { - "Name": "span", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.ReadOnlySpan" - }, - { - "Name": "value0", - "Type": "System.Byte" - }, - { - "Name": "value1", - "Type": "System.Byte" - }, - { - "Name": "value2", - "Type": "System.Byte" - } - ], - "ReturnType": "System.Int32", - "Static": true, - "Extension": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "IndexOfAny", - "Parameters": [ - { - "Name": "span", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.ReadOnlySpan" - }, - { - "Name": "values", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.ReadOnlySpan" - } - ], - "ReturnType": "System.Int32", - "Static": true, - "Extension": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "SequenceEqual", - "Parameters": [ - { - "Name": "first", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.ReadOnlySpan" - }, - { - "Name": "second", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.ReadOnlySpan" - } - ], - "ReturnType": "System.Boolean", - "Static": true, - "Extension": true, - "Visibility": "Public", - "GenericParameter": [ - { - "ParameterName": "T", - "ParameterPosition": 0, - "New": true, - "Struct": true, - "BaseTypeOrInterfaces": [ - "System.IEquatable" - ] - } - ] - }, - { - "Kind": "Method", - "Name": "SequenceEqual", - "Parameters": [ - { - "Name": "first", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.ReadOnlySpan" - }, - { - "Name": "second", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.ReadOnlySpan" - } - ], - "ReturnType": "System.Boolean", - "Static": true, - "Extension": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "StartsWith", - "Parameters": [ - { - "Name": "span", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Span" - }, - { - "Name": "value", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.ReadOnlySpan" - } - ], - "ReturnType": "System.Boolean", - "Static": true, - "Extension": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "StartsWith", - "Parameters": [ - { - "Name": "span", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Span" - }, - { - "Name": "value", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.ReadOnlySpan" - } - ], - "ReturnType": "System.Boolean", - "Static": true, - "Extension": true, - "Visibility": "Public", - "GenericParameter": [ - { - "ParameterName": "T", - "ParameterPosition": 0, - "New": true, - "Struct": true, - "BaseTypeOrInterfaces": [ - "System.IEquatable" - ] - } - ] - }, - { - "Kind": "Method", - "Name": "StartsWith", - "Parameters": [ - { - "Name": "span", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.ReadOnlySpan" - }, - { - "Name": "value", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.ReadOnlySpan" - } - ], - "ReturnType": "System.Boolean", - "Static": true, - "Extension": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "StartsWith", - "Parameters": [ - { - "Name": "span", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.ReadOnlySpan" - }, - { - "Name": "value", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.ReadOnlySpan" - } - ], - "ReturnType": "System.Boolean", - "Static": true, - "Extension": true, - "Visibility": "Public", - "GenericParameter": [ - { - "ParameterName": "T", - "ParameterPosition": 0, - "New": true, - "Struct": true, - "BaseTypeOrInterfaces": [ - "System.IEquatable" - ] - } - ] - }, - { - "Kind": "Method", - "Name": "AsSpan", - "Parameters": [ - { - "Name": "array", - "Type": "T0[]" - } - ], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Span", - "Static": true, - "Extension": true, - "Visibility": "Public", - "GenericParameter": [ - { - "ParameterName": "T", - "ParameterPosition": 0, - "BaseTypeOrInterfaces": [] - } - ] - }, - { - "Kind": "Method", - "Name": "AsSpan", - "Parameters": [ - { - "Name": "arraySegment", - "Type": "System.ArraySegment" - } - ], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Span", - "Static": true, - "Extension": true, - "Visibility": "Public", - "GenericParameter": [ - { - "ParameterName": "T", - "ParameterPosition": 0, - "BaseTypeOrInterfaces": [] - } - ] - }, - { - "Kind": "Method", - "Name": "CopyTo", - "Parameters": [ - { - "Name": "array", - "Type": "T0[]" - }, - { - "Name": "destination", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Span" - } - ], - "ReturnType": "System.Void", - "Static": true, - "Extension": true, - "Visibility": "Public", - "GenericParameter": [ - { - "ParameterName": "T", - "ParameterPosition": 0, - "BaseTypeOrInterfaces": [] - } - ] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Text.Encodings.Web.Utf8.UrlEncoder", - "Visibility": "Public", - "Kind": "Class", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "Decode", - "Parameters": [ - { - "Name": "source", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.ReadOnlySpan" - }, - { - "Name": "destination", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Span" - } - ], - "ReturnType": "System.Int32", - "Static": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "DecodeInPlace", - "Parameters": [ - { - "Name": "buffer", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Span" - } - ], - "ReturnType": "System.Int32", - "Static": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.FlushResult", - "Visibility": "Public", - "Kind": "Struct", - "Sealed": true, - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "get_IsCancelled", - "Parameters": [], - "ReturnType": "System.Boolean", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_IsCompleted", - "Parameters": [], - "ReturnType": "System.Boolean", - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.IPipe", - "Visibility": "Public", - "Kind": "Interface", - "Abstract": true, - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "get_Reader", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.IPipeReader", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_Writer", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.IPipeWriter", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Reset", - "Parameters": [], - "ReturnType": "System.Void", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.IPipeConnection", - "Visibility": "Public", - "Kind": "Interface", - "Abstract": true, - "ImplementedInterfaces": [ - "System.IDisposable" - ], - "Members": [ - { - "Kind": "Method", - "Name": "get_Input", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.IPipeReader", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_Output", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.IPipeWriter", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.IPipeReader", - "Visibility": "Public", - "Kind": "Interface", - "Abstract": true, - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "TryRead", - "Parameters": [ - { - "Name": "result", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.ReadResult", - "Direction": "Out" - } - ], - "ReturnType": "System.Boolean", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ReadAsync", - "Parameters": [ - { - "Name": "cancellationToken", - "Type": "System.Threading.CancellationToken", - "DefaultValue": "default(System.Threading.CancellationToken)" - } - ], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.ReadableBufferAwaitable", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Advance", - "Parameters": [ - { - "Name": "consumed", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.ReadCursor" - }, - { - "Name": "examined", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.ReadCursor" - } - ], - "ReturnType": "System.Void", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "CancelPendingRead", - "Parameters": [], - "ReturnType": "System.Void", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Complete", - "Parameters": [ - { - "Name": "exception", - "Type": "System.Exception", - "DefaultValue": "null" - } - ], - "ReturnType": "System.Void", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "OnWriterCompleted", - "Parameters": [ - { - "Name": "callback", - "Type": "System.Action" - }, - { - "Name": "state", - "Type": "System.Object" - } - ], - "ReturnType": "System.Void", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.IPipeWriter", - "Visibility": "Public", - "Kind": "Interface", - "Abstract": true, - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "Alloc", - "Parameters": [ - { - "Name": "minimumSize", - "Type": "System.Int32", - "DefaultValue": "0" - } - ], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.WritableBuffer", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Complete", - "Parameters": [ - { - "Name": "exception", - "Type": "System.Exception", - "DefaultValue": "null" - } - ], - "ReturnType": "System.Void", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "CancelPendingFlush", - "Parameters": [], - "ReturnType": "System.Void", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "OnReaderCompleted", - "Parameters": [ - { - "Name": "callback", - "Type": "System.Action" - }, - { - "Name": "state", - "Type": "System.Object" - } - ], - "ReturnType": "System.Void", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.IReadableBufferAwaiter", - "Visibility": "Public", - "Kind": "Interface", - "Abstract": true, - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "get_IsCompleted", - "Parameters": [], - "ReturnType": "System.Boolean", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "GetResult", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.ReadResult", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "OnCompleted", - "Parameters": [ - { - "Name": "continuation", - "Type": "System.Action" - } - ], - "ReturnType": "System.Void", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.IScheduler", - "Visibility": "Public", - "Kind": "Interface", - "Abstract": true, - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "Schedule", - "Parameters": [ - { - "Name": "action", - "Type": "System.Action" - }, - { - "Name": "state", - "Type": "System.Object" - } - ], - "ReturnType": "System.Void", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.IWritableBufferAwaiter", - "Visibility": "Public", - "Kind": "Interface", - "Abstract": true, - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "get_IsCompleted", - "Parameters": [], - "ReturnType": "System.Boolean", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "GetResult", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.FlushResult", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "OnCompleted", - "Parameters": [ - { - "Name": "continuation", - "Type": "System.Action" - } - ], - "ReturnType": "System.Void", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.InlineScheduler", - "Visibility": "Public", - "Kind": "Class", - "ImplementedInterfaces": [ - "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.IScheduler" - ], - "Members": [ - { - "Kind": "Method", - "Name": "Schedule", - "Parameters": [ - { - "Name": "action", - "Type": "System.Action" - }, - { - "Name": "state", - "Type": "System.Object" - } - ], - "ReturnType": "System.Void", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.IScheduler", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [], - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "Default", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.InlineScheduler", - "Static": true, - "ReadOnly": true, - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.BufferEnumerator", - "Visibility": "Public", - "Kind": "Struct", - "Sealed": true, - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "get_Current", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Buffers.Buffer", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "MoveNext", - "Parameters": [], - "ReturnType": "System.Boolean", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Reset", - "Parameters": [], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "start", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.ReadCursor" - }, - { - "Name": "end", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.ReadCursor" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.MemoryPool", - "Visibility": "Public", - "Kind": "Class", - "BaseType": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Buffers.BufferPool", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "Rent", - "Parameters": [ - { - "Name": "size", - "Type": "System.Int32" - } - ], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Buffers.OwnedBuffer", - "Virtual": true, - "Override": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "RegisterSlabAllocationCallback", - "Parameters": [ - { - "Name": "callback", - "Type": "System.Action" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "RegisterSlabDeallocationCallback", - "Parameters": [ - { - "Name": "callback", - "Type": "System.Action" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Return", - "Parameters": [ - { - "Name": "block", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.MemoryPoolBlock" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Dispose", - "Parameters": [ - { - "Name": "disposing", - "Type": "System.Boolean" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "Override": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [], - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "MaxPooledBlockLength", - "Parameters": [], - "ReturnType": "System.Int32", - "Static": true, - "Visibility": "Public", - "GenericParameter": [], - "Constant": true, - "Literal": "4032" - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.MemoryPoolBlock", - "Visibility": "Public", - "Kind": "Class", - "BaseType": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Buffers.OwnedBuffer", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "get_Pool", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.MemoryPool", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_Slab", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.MemoryPoolSlab", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_Length", - "Parameters": [], - "ReturnType": "System.Int32", - "Virtual": true, - "Override": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_Span", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Span", - "Virtual": true, - "Override": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Finalize", - "Parameters": [], - "ReturnType": "System.Void", - "Virtual": true, - "Override": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ToString", - "Parameters": [], - "ReturnType": "System.String", - "Virtual": true, - "Override": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "OnZeroReferences", - "Parameters": [], - "ReturnType": "System.Void", - "Virtual": true, - "Override": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "TryGetArrayInternal", - "Parameters": [ - { - "Name": "buffer", - "Type": "System.ArraySegment", - "Direction": "Out" - } - ], - "ReturnType": "System.Boolean", - "Virtual": true, - "Override": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "TryGetPointerInternal", - "Parameters": [ - { - "Name": "pointer", - "Type": "System.Void*", - "Direction": "Out" - } - ], - "ReturnType": "System.Boolean", - "Virtual": true, - "Override": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "pool", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.MemoryPool" - }, - { - "Name": "slab", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.MemoryPoolSlab" - }, - { - "Name": "offset", - "Type": "System.Int32" - }, - { - "Name": "length", - "Type": "System.Int32" - } - ], - "Visibility": "Protected", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.MemoryPoolSlab", - "Visibility": "Public", - "Kind": "Class", - "ImplementedInterfaces": [ - "System.IDisposable" - ], - "Members": [ - { - "Kind": "Method", - "Name": "get_IsActive", - "Parameters": [], - "ReturnType": "System.Boolean", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_NativePointer", - "Parameters": [], - "ReturnType": "System.IntPtr", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_Array", - "Parameters": [], - "ReturnType": "System.Byte[]", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_Length", - "Parameters": [], - "ReturnType": "System.Int32", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Create", - "Parameters": [ - { - "Name": "length", - "Type": "System.Int32" - } - ], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.MemoryPoolSlab", - "Static": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Dispose", - "Parameters": [ - { - "Name": "disposing", - "Type": "System.Boolean" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Finalize", - "Parameters": [], - "ReturnType": "System.Void", - "Virtual": true, - "Override": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Dispose", - "Parameters": [], - "ReturnType": "System.Void", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "System.IDisposable", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "data", - "Type": "System.Byte[]" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.PipeFactory", - "Visibility": "Public", - "Kind": "Class", - "ImplementedInterfaces": [ - "System.IDisposable" - ], - "Members": [ - { - "Kind": "Method", - "Name": "Create", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.IPipe", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Create", - "Parameters": [ - { - "Name": "options", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.PipeOptions" - } - ], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.IPipe", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Dispose", - "Parameters": [], - "ReturnType": "System.Void", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "System.IDisposable", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [], - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "pool", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Buffers.BufferPool" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.PipeOptions", - "Visibility": "Public", - "Kind": "Class", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "get_MaximumSizeHigh", - "Parameters": [], - "ReturnType": "System.Int64", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_MaximumSizeHigh", - "Parameters": [ - { - "Name": "value", - "Type": "System.Int64" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_MaximumSizeLow", - "Parameters": [], - "ReturnType": "System.Int64", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_MaximumSizeLow", - "Parameters": [ - { - "Name": "value", - "Type": "System.Int64" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_WriterScheduler", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.IScheduler", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_WriterScheduler", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.IScheduler" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_ReaderScheduler", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.IScheduler", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_ReaderScheduler", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.IScheduler" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.PipelineReaderExtensions", - "Visibility": "Public", - "Kind": "Class", - "Abstract": true, - "Static": true, - "Sealed": true, - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "Advance", - "Parameters": [ - { - "Name": "input", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.IPipeReader" - }, - { - "Name": "cursor", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.ReadCursor" - } - ], - "ReturnType": "System.Void", - "Static": true, - "Extension": true, - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.PipelineWriterExtensions", - "Visibility": "Public", - "Kind": "Class", - "Abstract": true, - "Static": true, - "Sealed": true, - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "WriteAsync", - "Parameters": [ - { - "Name": "output", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.IPipeWriter" - }, - { - "Name": "source", - "Type": "System.Byte[]" - } - ], - "ReturnType": "System.Threading.Tasks.Task", - "Static": true, - "Extension": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "WriteAsync", - "Parameters": [ - { - "Name": "output", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.IPipeWriter" - }, - { - "Name": "source", - "Type": "System.ArraySegment" - } - ], - "ReturnType": "System.Threading.Tasks.Task", - "Static": true, - "Extension": true, - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.PreservedBuffer", - "Visibility": "Public", - "Kind": "Struct", - "Sealed": true, - "ImplementedInterfaces": [ - "System.IDisposable" - ], - "Members": [ - { - "Kind": "Method", - "Name": "get_Buffer", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.ReadableBuffer", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Dispose", - "Parameters": [], - "ReturnType": "System.Void", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "System.IDisposable", - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.ReadCursor", - "Visibility": "Public", - "Kind": "Struct", - "Sealed": true, - "ImplementedInterfaces": [ - "System.IEquatable" - ], - "Members": [ - { - "Kind": "Method", - "Name": "ToString", - "Parameters": [], - "ReturnType": "System.String", - "Virtual": true, - "Override": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "op_Equality", - "Parameters": [ - { - "Name": "c1", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.ReadCursor" - }, - { - "Name": "c2", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.ReadCursor" - } - ], - "ReturnType": "System.Boolean", - "Static": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "op_Inequality", - "Parameters": [ - { - "Name": "c1", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.ReadCursor" - }, - { - "Name": "c2", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.ReadCursor" - } - ], - "ReturnType": "System.Boolean", - "Static": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Equals", - "Parameters": [ - { - "Name": "other", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.ReadCursor" - } - ], - "ReturnType": "System.Boolean", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "System.IEquatable", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Equals", - "Parameters": [ - { - "Name": "obj", - "Type": "System.Object" - } - ], - "ReturnType": "System.Boolean", - "Virtual": true, - "Override": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "GetHashCode", - "Parameters": [], - "ReturnType": "System.Int32", - "Virtual": true, - "Override": true, - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.ReadCursorOperations", - "Visibility": "Public", - "Kind": "Class", - "Abstract": true, - "Static": true, - "Sealed": true, - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "Seek", - "Parameters": [ - { - "Name": "begin", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.ReadCursor" - }, - { - "Name": "end", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.ReadCursor" - }, - { - "Name": "result", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.ReadCursor", - "Direction": "Out" - }, - { - "Name": "byte0", - "Type": "System.Byte" - } - ], - "ReturnType": "System.Int32", - "Static": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Seek", - "Parameters": [ - { - "Name": "begin", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.ReadCursor" - }, - { - "Name": "end", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.ReadCursor" - }, - { - "Name": "result", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.ReadCursor", - "Direction": "Out" - }, - { - "Name": "byte0", - "Type": "System.Byte" - }, - { - "Name": "byte1", - "Type": "System.Byte" - } - ], - "ReturnType": "System.Int32", - "Static": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Seek", - "Parameters": [ - { - "Name": "begin", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.ReadCursor" - }, - { - "Name": "end", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.ReadCursor" - }, - { - "Name": "result", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.ReadCursor", - "Direction": "Out" - }, - { - "Name": "byte0", - "Type": "System.Byte" - }, - { - "Name": "byte1", - "Type": "System.Byte" - }, - { - "Name": "byte2", - "Type": "System.Byte" - } - ], - "ReturnType": "System.Int32", - "Static": true, - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.ReadResult", - "Visibility": "Public", - "Kind": "Struct", - "Sealed": true, - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "get_Buffer", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.ReadableBuffer", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_IsCancelled", - "Parameters": [], - "ReturnType": "System.Boolean", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_IsCompleted", - "Parameters": [], - "ReturnType": "System.Boolean", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "buffer", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.ReadableBuffer" - }, - { - "Name": "isCancelled", - "Type": "System.Boolean" - }, - { - "Name": "isCompleted", - "Type": "System.Boolean" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.ReadableBuffer", - "Visibility": "Public", - "Kind": "Struct", - "Sealed": true, - "ImplementedInterfaces": [ - "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Collections.Sequences.ISequence>" - ], - "Members": [ - { - "Kind": "Method", - "Name": "get_Length", - "Parameters": [], - "ReturnType": "System.Int32", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_IsEmpty", - "Parameters": [], - "ReturnType": "System.Boolean", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_IsSingleSpan", - "Parameters": [], - "ReturnType": "System.Boolean", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_First", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Buffers.Buffer", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_Start", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.ReadCursor", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_End", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.ReadCursor", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Slice", - "Parameters": [ - { - "Name": "start", - "Type": "System.Int32" - }, - { - "Name": "length", - "Type": "System.Int32" - } - ], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.ReadableBuffer", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Slice", - "Parameters": [ - { - "Name": "start", - "Type": "System.Int32" - }, - { - "Name": "end", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.ReadCursor" - } - ], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.ReadableBuffer", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Slice", - "Parameters": [ - { - "Name": "start", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.ReadCursor" - }, - { - "Name": "end", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.ReadCursor" - } - ], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.ReadableBuffer", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Slice", - "Parameters": [ - { - "Name": "start", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.ReadCursor" - }, - { - "Name": "length", - "Type": "System.Int32" - } - ], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.ReadableBuffer", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Slice", - "Parameters": [ - { - "Name": "start", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.ReadCursor" - } - ], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.ReadableBuffer", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Slice", - "Parameters": [ - { - "Name": "start", - "Type": "System.Int32" - } - ], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.ReadableBuffer", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Preserve", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.PreservedBuffer", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "CopyTo", - "Parameters": [ - { - "Name": "destination", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Span" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ToArray", - "Parameters": [], - "ReturnType": "System.Byte[]", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ToString", - "Parameters": [], - "ReturnType": "System.String", - "Virtual": true, - "Override": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "GetEnumerator", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.BufferEnumerator", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Create", - "Parameters": [ - { - "Name": "data", - "Type": "System.Byte[]" - } - ], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.ReadableBuffer", - "Static": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Create", - "Parameters": [ - { - "Name": "data", - "Type": "System.Byte[]" - }, - { - "Name": "offset", - "Type": "System.Int32" - }, - { - "Name": "length", - "Type": "System.Int32" - } - ], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.ReadableBuffer", - "Static": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Create", - "Parameters": [ - { - "Name": "data", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Buffers.OwnedBuffer" - }, - { - "Name": "offset", - "Type": "System.Int32" - }, - { - "Name": "length", - "Type": "System.Int32" - } - ], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.ReadableBuffer", - "Static": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Move", - "Parameters": [ - { - "Name": "cursor", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.ReadCursor" - }, - { - "Name": "count", - "Type": "System.Int32" - } - ], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.ReadCursor", - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.ReadableBufferAwaitable", - "Visibility": "Public", - "Kind": "Struct", - "Sealed": true, - "ImplementedInterfaces": [ - "System.Runtime.CompilerServices.ICriticalNotifyCompletion" - ], - "Members": [ - { - "Kind": "Method", - "Name": "get_IsCompleted", - "Parameters": [], - "ReturnType": "System.Boolean", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "GetResult", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.ReadResult", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "GetAwaiter", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.ReadableBufferAwaitable", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "UnsafeOnCompleted", - "Parameters": [ - { - "Name": "continuation", - "Type": "System.Action" - } - ], - "ReturnType": "System.Void", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "System.Runtime.CompilerServices.ICriticalNotifyCompletion", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "OnCompleted", - "Parameters": [ - { - "Name": "continuation", - "Type": "System.Action" - } - ], - "ReturnType": "System.Void", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "System.Runtime.CompilerServices.INotifyCompletion", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "awaiter", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.IReadableBufferAwaiter" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.ReadableBufferReader", - "Visibility": "Public", - "Kind": "Struct", - "Sealed": true, - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "get_End", - "Parameters": [], - "ReturnType": "System.Boolean", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_Index", - "Parameters": [], - "ReturnType": "System.Int32", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_Cursor", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.ReadCursor", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_Span", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Span", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_ConsumedBytes", - "Parameters": [], - "ReturnType": "System.Int32", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Peek", - "Parameters": [], - "ReturnType": "System.Int32", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Take", - "Parameters": [], - "ReturnType": "System.Int32", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Skip", - "Parameters": [ - { - "Name": "length", - "Type": "System.Int32" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "buffer", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.ReadableBuffer" - } - ], - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "start", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.ReadCursor" - }, - { - "Name": "end", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.ReadCursor" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.TaskRunScheduler", - "Visibility": "Public", - "Kind": "Class", - "ImplementedInterfaces": [ - "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.IScheduler" - ], - "Members": [ - { - "Kind": "Method", - "Name": "Schedule", - "Parameters": [ - { - "Name": "action", - "Type": "System.Action" - }, - { - "Name": "state", - "Type": "System.Object" - } - ], - "ReturnType": "System.Void", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.IScheduler", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [], - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "Default", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.TaskRunScheduler", - "Static": true, - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.UnownedBuffer", - "Visibility": "Public", - "Kind": "Class", - "BaseType": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Buffers.OwnedBuffer", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "get_Length", - "Parameters": [], - "ReturnType": "System.Int32", - "Virtual": true, - "Override": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_Span", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Span", - "Virtual": true, - "Override": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "MakeCopy", - "Parameters": [ - { - "Name": "offset", - "Type": "System.Int32" - }, - { - "Name": "length", - "Type": "System.Int32" - }, - { - "Name": "newStart", - "Type": "System.Int32", - "Direction": "Out" - }, - { - "Name": "newEnd", - "Type": "System.Int32", - "Direction": "Out" - } - ], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Buffers.OwnedBuffer", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "TryGetArrayInternal", - "Parameters": [ - { - "Name": "buffer", - "Type": "System.ArraySegment", - "Direction": "Out" - } - ], - "ReturnType": "System.Boolean", - "Virtual": true, - "Override": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "TryGetPointerInternal", - "Parameters": [ - { - "Name": "pointer", - "Type": "System.Void*", - "Direction": "Out" - } - ], - "ReturnType": "System.Boolean", - "Virtual": true, - "Override": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "buffer", - "Type": "System.ArraySegment" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.WritableBuffer", - "Visibility": "Public", - "Kind": "Struct", - "Sealed": true, - "ImplementedInterfaces": [ - "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Buffers.IOutput" - ], - "Members": [ - { - "Kind": "Method", - "Name": "get_Buffer", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Buffers.Buffer", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_BytesWritten", - "Parameters": [], - "ReturnType": "System.Int32", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "AsReadableBuffer", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.ReadableBuffer", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Ensure", - "Parameters": [ - { - "Name": "count", - "Type": "System.Int32", - "DefaultValue": "1" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Append", - "Parameters": [ - { - "Name": "buffer", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.ReadableBuffer" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Advance", - "Parameters": [ - { - "Name": "bytesWritten", - "Type": "System.Int32" - } - ], - "ReturnType": "System.Void", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Buffers.IOutput", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Commit", - "Parameters": [], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "FlushAsync", - "Parameters": [ - { - "Name": "cancellationToken", - "Type": "System.Threading.CancellationToken", - "DefaultValue": "default(System.Threading.CancellationToken)" - } - ], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.WritableBufferAwaitable", - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.WritableBufferAwaitable", - "Visibility": "Public", - "Kind": "Struct", - "Sealed": true, - "ImplementedInterfaces": [ - "System.Runtime.CompilerServices.ICriticalNotifyCompletion" - ], - "Members": [ - { - "Kind": "Method", - "Name": "get_IsCompleted", - "Parameters": [], - "ReturnType": "System.Boolean", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "GetResult", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.FlushResult", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "GetAwaiter", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.WritableBufferAwaitable", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "UnsafeOnCompleted", - "Parameters": [ - { - "Name": "continuation", - "Type": "System.Action" - } - ], - "ReturnType": "System.Void", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "System.Runtime.CompilerServices.ICriticalNotifyCompletion", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "OnCompleted", - "Parameters": [ - { - "Name": "continuation", - "Type": "System.Action" - } - ], - "ReturnType": "System.Void", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "System.Runtime.CompilerServices.INotifyCompletion", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "awaiter", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.IWritableBufferAwaiter" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.WritableBufferExtensions", - "Visibility": "Public", - "Kind": "Class", - "Abstract": true, - "Static": true, - "Sealed": true, - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "Write", - "Parameters": [ - { - "Name": "buffer", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.WritableBuffer" - }, - { - "Name": "source", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.ReadOnlySpan" - } - ], - "ReturnType": "System.Void", - "Static": true, - "Extension": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Write", - "Parameters": [ - { - "Name": "buffer", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.WritableBuffer" - }, - { - "Name": "source", - "Type": "System.Byte[]" - } - ], - "ReturnType": "System.Void", - "Static": true, - "Extension": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Write", - "Parameters": [ - { - "Name": "buffer", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.WritableBuffer" - }, - { - "Name": "source", - "Type": "System.Byte[]" - }, - { - "Name": "offset", - "Type": "System.Int32" - }, - { - "Name": "length", - "Type": "System.Int32" - } - ], - "ReturnType": "System.Void", - "Static": true, - "Extension": true, - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.WritableBufferWriter", - "Visibility": "Public", - "Kind": "Struct", - "Sealed": true, - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "get_Span", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Span", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Advance", - "Parameters": [ - { - "Name": "count", - "Type": "System.Int32" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Write", - "Parameters": [ - { - "Name": "source", - "Type": "System.Byte[]" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Write", - "Parameters": [ - { - "Name": "source", - "Type": "System.Byte[]" - }, - { - "Name": "offset", - "Type": "System.Int32" - }, - { - "Name": "length", - "Type": "System.Int32" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Ensure", - "Parameters": [ - { - "Name": "count", - "Type": "System.Int32", - "DefaultValue": "1" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "writableBuffer", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.WritableBuffer" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.Testing.BufferUtilities", - "Visibility": "Public", - "Kind": "Class", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "CreateBuffer", - "Parameters": [ - { - "Name": "inputs", - "Type": "System.Byte[][]", - "IsParams": true - } - ], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.ReadableBuffer", - "Static": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "CreateBuffer", - "Parameters": [ - { - "Name": "inputs", - "Type": "System.String[]", - "IsParams": true - } - ], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.ReadableBuffer", - "Static": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "CreateBuffer", - "Parameters": [ - { - "Name": "inputs", - "Type": "System.Int32[]", - "IsParams": true - } - ], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.ReadableBuffer", - "Static": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Collections.Sequences.ArrayList", - "Visibility": "Public", - "Kind": "Class", - "Sealed": true, - "ImplementedInterfaces": [ - "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Collections.Sequences.ISequence" - ], - "Members": [ - { - "Kind": "Method", - "Name": "get_Length", - "Parameters": [], - "ReturnType": "System.Int32", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_Item", - "Parameters": [ - { - "Name": "index", - "Type": "System.Int32" - } - ], - "ReturnType": "T0", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Add", - "Parameters": [ - { - "Name": "item", - "Type": "T0" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "GetEnumerator", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Collections.Sequences.SequenceEnumerator", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "TryGet", - "Parameters": [ - { - "Name": "position", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Collections.Sequences.Position", - "Direction": "Ref" - }, - { - "Name": "item", - "Type": "T0", - "Direction": "Out" - }, - { - "Name": "advance", - "Type": "System.Boolean", - "DefaultValue": "True" - } - ], - "ReturnType": "System.Boolean", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Collections.Sequences.ISequence", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [], - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "capacity", - "Type": "System.Int32" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [ - { - "ParameterName": "T", - "ParameterPosition": 0, - "BaseTypeOrInterfaces": [] - } - ] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Collections.Sequences.ISequence", - "Visibility": "Public", - "Kind": "Interface", - "Abstract": true, - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "TryGet", - "Parameters": [ - { - "Name": "position", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Collections.Sequences.Position", - "Direction": "Ref" - }, - { - "Name": "item", - "Type": "T0", - "Direction": "Out" - }, - { - "Name": "advance", - "Type": "System.Boolean", - "DefaultValue": "True" - } - ], - "ReturnType": "System.Boolean", - "GenericParameter": [] - } - ], - "GenericParameters": [ - { - "ParameterName": "T", - "ParameterPosition": 0, - "BaseTypeOrInterfaces": [] - } - ] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Collections.Sequences.Position", - "Visibility": "Public", - "Kind": "Struct", - "Sealed": true, - "ImplementedInterfaces": [ - "System.IEquatable" - ], - "Members": [ - { - "Kind": "Method", - "Name": "op_Equality", - "Parameters": [ - { - "Name": "left", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Collections.Sequences.Position" - }, - { - "Name": "right", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Collections.Sequences.Position" - } - ], - "ReturnType": "System.Boolean", - "Static": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "op_Inequality", - "Parameters": [ - { - "Name": "left", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Collections.Sequences.Position" - }, - { - "Name": "right", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Collections.Sequences.Position" - } - ], - "ReturnType": "System.Boolean", - "Static": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Equals", - "Parameters": [ - { - "Name": "other", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Collections.Sequences.Position" - } - ], - "ReturnType": "System.Boolean", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "System.IEquatable", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "GetHashCode", - "Parameters": [], - "ReturnType": "System.Int32", - "Virtual": true, - "Override": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Equals", - "Parameters": [ - { - "Name": "obj", - "Type": "System.Object" - } - ], - "ReturnType": "System.Boolean", - "Virtual": true, - "Override": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "ObjectPosition", - "Parameters": [], - "ReturnType": "System.Object", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "IntegerPosition", - "Parameters": [], - "ReturnType": "System.Int32", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "Tag", - "Parameters": [], - "ReturnType": "System.Int32", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "First", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Collections.Sequences.Position", - "Static": true, - "ReadOnly": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "AfterLast", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Collections.Sequences.Position", - "Static": true, - "ReadOnly": true, - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Collections.Sequences.ResizableArray", - "Visibility": "Public", - "Kind": "Struct", - "Sealed": true, - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "get_Items", - "Parameters": [], - "ReturnType": "T0[]", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_Items", - "Parameters": [ - { - "Name": "value", - "Type": "T0[]" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_Count", - "Parameters": [], - "ReturnType": "System.Int32", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_Count", - "Parameters": [ - { - "Name": "value", - "Type": "System.Int32" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_Capacity", - "Parameters": [], - "ReturnType": "System.Int32", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_Item", - "Parameters": [ - { - "Name": "index", - "Type": "System.Int32" - } - ], - "ReturnType": "T0", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_Item", - "Parameters": [ - { - "Name": "index", - "Type": "System.Int32" - }, - { - "Name": "value", - "Type": "T0" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Add", - "Parameters": [ - { - "Name": "item", - "Type": "T0" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "AddAll", - "Parameters": [ - { - "Name": "items", - "Type": "T0[]" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "AddAll", - "Parameters": [ - { - "Name": "items", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.ReadOnlySpan" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Clear", - "Parameters": [], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Resize", - "Parameters": [ - { - "Name": "newSize", - "Type": "System.Int32", - "DefaultValue": "-1" - } - ], - "ReturnType": "T0[]", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Resize", - "Parameters": [ - { - "Name": "newArray", - "Type": "T0[]" - } - ], - "ReturnType": "T0[]", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "TryGet", - "Parameters": [ - { - "Name": "position", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Collections.Sequences.Position", - "Direction": "Ref" - }, - { - "Name": "item", - "Type": "T0", - "Direction": "Out" - }, - { - "Name": "advance", - "Type": "System.Boolean", - "DefaultValue": "True" - } - ], - "ReturnType": "System.Boolean", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_Full", - "Parameters": [], - "ReturnType": "System.ArraySegment", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_Free", - "Parameters": [], - "ReturnType": "System.ArraySegment", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "capacity", - "Type": "System.Int32" - } - ], - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "array", - "Type": "T0[]" - }, - { - "Name": "count", - "Type": "System.Int32", - "DefaultValue": "0" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [ - { - "ParameterName": "T", - "ParameterPosition": 0, - "BaseTypeOrInterfaces": [] - } - ] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Collections.Sequences.SequenceEnumerator", - "Visibility": "Public", - "Kind": "Struct", - "Sealed": true, - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "MoveNext", - "Parameters": [], - "ReturnType": "System.Boolean", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_Current", - "Parameters": [], - "ReturnType": "T0", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "sequence", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Collections.Sequences.ISequence" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [ - { - "ParameterName": "T", - "ParameterPosition": 0, - "BaseTypeOrInterfaces": [] - } - ] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Runtime.BufferPrimitivesThrowHelper", - "Visibility": "Public", - "Kind": "Class", - "Abstract": true, - "Static": true, - "Sealed": true, - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "ThrowArgumentNullException", - "Parameters": [ - { - "Name": "argument", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Runtime.ExceptionArgument" - } - ], - "ReturnType": "System.Void", - "Static": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ThrowArgumentException", - "Parameters": [], - "ReturnType": "System.Void", - "Static": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ThrowArgumentException", - "Parameters": [ - { - "Name": "argument", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Runtime.ExceptionArgument" - } - ], - "ReturnType": "System.Void", - "Static": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ThrowArgumentOutOfRangeException", - "Parameters": [], - "ReturnType": "System.Void", - "Static": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ThrowArgumentOutOfRangeException", - "Parameters": [ - { - "Name": "argument", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Runtime.ExceptionArgument" - } - ], - "ReturnType": "System.Void", - "Static": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ThrowInvalidOperationException", - "Parameters": [], - "ReturnType": "System.Void", - "Static": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ThrowInvalidOperationException_ForBoxingSpans", - "Parameters": [], - "ReturnType": "System.Void", - "Static": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ThrowObjectDisposedException", - "Parameters": [ - { - "Name": "objectName", - "Type": "System.String" - } - ], - "ReturnType": "System.Void", - "Static": true, - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Runtime.ExceptionArgument", - "Visibility": "Public", - "Kind": "Enumeration", - "Sealed": true, - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Field", - "Name": "pointer", - "Parameters": [], - "GenericParameter": [], - "Literal": "0" - }, - { - "Kind": "Field", - "Name": "array", - "Parameters": [], - "GenericParameter": [], - "Literal": "1" - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Runtime.PrimitiveAttribute", - "Visibility": "Public", - "Kind": "Class", - "Sealed": true, - "BaseType": "System.Attribute", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Runtime.ReferenceCounter", - "Visibility": "Public", - "Kind": "Struct", - "Sealed": true, - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "AddReference", - "Parameters": [ - { - "Name": "obj", - "Type": "System.Object" - } - ], - "ReturnType": "System.Void", - "Static": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Release", - "Parameters": [ - { - "Name": "obj", - "Type": "System.Object" - } - ], - "ReturnType": "System.Void", - "Static": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "HasReference", - "Parameters": [ - { - "Name": "obj", - "Type": "System.Object" - } - ], - "ReturnType": "System.Boolean", - "Static": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "HasThreadLocalReference", - "Parameters": [ - { - "Name": "obj", - "Type": "System.Object" - } - ], - "ReturnType": "System.Boolean", - "Static": true, - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Runtime.ReferenceCountingMethod", - "Visibility": "Public", - "Kind": "Enumeration", - "Sealed": true, - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Field", - "Name": "Interlocked", - "Parameters": [], - "GenericParameter": [], - "Literal": "0" - }, - { - "Kind": "Field", - "Name": "ReferenceCounter", - "Parameters": [], - "GenericParameter": [], - "Literal": "1" - }, - { - "Kind": "Field", - "Name": "None", - "Parameters": [], - "GenericParameter": [], - "Literal": "2" - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Runtime.ReferenceCountingSettings", - "Visibility": "Public", - "Kind": "Class", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [], - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "OwnedMemory", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Runtime.ReferenceCountingMethod", - "Static": true, - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Binary.BufferReader", - "Visibility": "Public", - "Kind": "Class", - "Abstract": true, - "Static": true, - "Sealed": true, - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "ReadBigEndian", - "Parameters": [ - { - "Name": "span", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.ReadOnlySpan" - } - ], - "ReturnType": "T0", - "Static": true, - "Extension": true, - "Visibility": "Public", - "GenericParameter": [ - { - "ParameterName": "T", - "ParameterPosition": 0, - "New": true, - "Struct": true, - "BaseTypeOrInterfaces": [] - } - ] - }, - { - "Kind": "Method", - "Name": "ReadLittleEndian", - "Parameters": [ - { - "Name": "span", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.ReadOnlySpan" - } - ], - "ReturnType": "T0", - "Static": true, - "Extension": true, - "Visibility": "Public", - "GenericParameter": [ - { - "ParameterName": "T", - "ParameterPosition": 0, - "New": true, - "Struct": true, - "BaseTypeOrInterfaces": [] - } - ] - }, - { - "Kind": "Method", - "Name": "ReadBigEndian", - "Parameters": [ - { - "Name": "span", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Span" - } - ], - "ReturnType": "T0", - "Static": true, - "Extension": true, - "Visibility": "Public", - "GenericParameter": [ - { - "ParameterName": "T", - "ParameterPosition": 0, - "New": true, - "Struct": true, - "BaseTypeOrInterfaces": [] - } - ] - }, - { - "Kind": "Method", - "Name": "ReadLittleEndian", - "Parameters": [ - { - "Name": "span", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Span" - } - ], - "ReturnType": "T0", - "Static": true, - "Extension": true, - "Visibility": "Public", - "GenericParameter": [ - { - "ParameterName": "T", - "ParameterPosition": 0, - "New": true, - "Struct": true, - "BaseTypeOrInterfaces": [] - } - ] - }, - { - "Kind": "Method", - "Name": "Read", - "Parameters": [ - { - "Name": "slice", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Span" - } - ], - "ReturnType": "T0", - "Static": true, - "Extension": true, - "Visibility": "Public", - "GenericParameter": [ - { - "ParameterName": "T", - "ParameterPosition": 0, - "New": true, - "Struct": true, - "BaseTypeOrInterfaces": [] - } - ] - }, - { - "Kind": "Method", - "Name": "Read", - "Parameters": [ - { - "Name": "slice", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.ReadOnlySpan" - } - ], - "ReturnType": "T0", - "Static": true, - "Extension": true, - "Visibility": "Public", - "GenericParameter": [ - { - "ParameterName": "T", - "ParameterPosition": 0, - "New": true, - "Struct": true, - "BaseTypeOrInterfaces": [] - } - ] - }, - { - "Kind": "Method", - "Name": "TryRead", - "Parameters": [ - { - "Name": "slice", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.ReadOnlySpan" - }, - { - "Name": "value", - "Type": "T0", - "Direction": "Out" - } - ], - "ReturnType": "System.Boolean", - "Static": true, - "Extension": true, - "Visibility": "Public", - "GenericParameter": [ - { - "ParameterName": "T", - "ParameterPosition": 0, - "New": true, - "Struct": true, - "BaseTypeOrInterfaces": [] - } - ] - }, - { - "Kind": "Method", - "Name": "TryRead", - "Parameters": [ - { - "Name": "slice", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Span" - }, - { - "Name": "value", - "Type": "T0", - "Direction": "Out" - } - ], - "ReturnType": "System.Boolean", - "Static": true, - "Extension": true, - "Visibility": "Public", - "GenericParameter": [ - { - "ParameterName": "T", - "ParameterPosition": 0, - "New": true, - "Struct": true, - "BaseTypeOrInterfaces": [] - } - ] - }, - { - "Kind": "Method", - "Name": "RequiresInInclusiveRange", - "Parameters": [ - { - "Name": "start", - "Type": "System.Int32" - }, - { - "Name": "length", - "Type": "System.UInt32" - } - ], - "ReturnType": "System.Void", - "Static": true, - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Binary.BufferWriter", - "Visibility": "Public", - "Kind": "Class", - "Abstract": true, - "Static": true, - "Sealed": true, - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "WriteBigEndian", - "Parameters": [ - { - "Name": "span", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Span" - }, - { - "Name": "value", - "Type": "T0" - } - ], - "ReturnType": "System.Void", - "Static": true, - "Extension": true, - "Visibility": "Public", - "GenericParameter": [ - { - "ParameterName": "T", - "ParameterPosition": 0, - "New": true, - "Struct": true, - "BaseTypeOrInterfaces": [] - } - ] - }, - { - "Kind": "Method", - "Name": "WriteLittleEndian", - "Parameters": [ - { - "Name": "span", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Span" - }, - { - "Name": "value", - "Type": "T0" - } - ], - "ReturnType": "System.Void", - "Static": true, - "Extension": true, - "Visibility": "Public", - "GenericParameter": [ - { - "ParameterName": "T", - "ParameterPosition": 0, - "New": true, - "Struct": true, - "BaseTypeOrInterfaces": [] - } - ] - }, - { - "Kind": "Method", - "Name": "Write", - "Parameters": [ - { - "Name": "slice", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Span" - }, - { - "Name": "value", - "Type": "T0" - } - ], - "ReturnType": "System.Void", - "Static": true, - "Extension": true, - "Visibility": "Public", - "GenericParameter": [ - { - "ParameterName": "T", - "ParameterPosition": 0, - "New": true, - "Struct": true, - "BaseTypeOrInterfaces": [] - } - ] - }, - { - "Kind": "Method", - "Name": "TryWrite", - "Parameters": [ - { - "Name": "slice", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Span" - }, - { - "Name": "value", - "Type": "T0" - } - ], - "ReturnType": "System.Boolean", - "Static": true, - "Extension": true, - "Visibility": "Public", - "GenericParameter": [ - { - "ParameterName": "T", - "ParameterPosition": 0, - "New": true, - "Struct": true, - "BaseTypeOrInterfaces": [] - } - ] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Buffers.Buffer", - "Visibility": "Public", - "Kind": "Struct", - "Sealed": true, - "ImplementedInterfaces": [ - "System.IEquatable>", - "System.IEquatable>" - ], - "Members": [ - { - "Kind": "Method", - "Name": "op_Implicit", - "Parameters": [ - { - "Name": "buffer", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Buffers.Buffer" - } - ], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Buffers.ReadOnlyBuffer", - "Static": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "op_Implicit", - "Parameters": [ - { - "Name": "array", - "Type": "T0[]" - } - ], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Buffers.Buffer", - "Static": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_Empty", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Buffers.Buffer", - "Static": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_Length", - "Parameters": [], - "ReturnType": "System.Int32", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_IsEmpty", - "Parameters": [], - "ReturnType": "System.Boolean", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Slice", - "Parameters": [ - { - "Name": "index", - "Type": "System.Int32" - } - ], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Buffers.Buffer", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Slice", - "Parameters": [ - { - "Name": "index", - "Type": "System.Int32" - }, - { - "Name": "length", - "Type": "System.Int32" - } - ], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Buffers.Buffer", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_Span", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Span", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Reserve", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Buffers.DisposableReservation", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Pin", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Buffers.BufferHandle", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "TryGetArray", - "Parameters": [ - { - "Name": "buffer", - "Type": "System.ArraySegment", - "Direction": "Out" - } - ], - "ReturnType": "System.Boolean", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "TryGetPointer", - "Parameters": [ - { - "Name": "pointer", - "Type": "System.Void*", - "Direction": "Out" - } - ], - "ReturnType": "System.Boolean", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ToArray", - "Parameters": [], - "ReturnType": "T0[]", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "CopyTo", - "Parameters": [ - { - "Name": "span", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Span" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "CopyTo", - "Parameters": [ - { - "Name": "buffer", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Buffers.Buffer" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Equals", - "Parameters": [ - { - "Name": "obj", - "Type": "System.Object" - } - ], - "ReturnType": "System.Boolean", - "Virtual": true, - "Override": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Equals", - "Parameters": [ - { - "Name": "other", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Buffers.Buffer" - } - ], - "ReturnType": "System.Boolean", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "System.IEquatable>", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Equals", - "Parameters": [ - { - "Name": "other", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Buffers.ReadOnlyBuffer" - } - ], - "ReturnType": "System.Boolean", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "System.IEquatable>", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "op_Equality", - "Parameters": [ - { - "Name": "left", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Buffers.Buffer" - }, - { - "Name": "right", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Buffers.Buffer" - } - ], - "ReturnType": "System.Boolean", - "Static": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "op_Inequality", - "Parameters": [ - { - "Name": "left", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Buffers.Buffer" - }, - { - "Name": "right", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Buffers.Buffer" - } - ], - "ReturnType": "System.Boolean", - "Static": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "op_Equality", - "Parameters": [ - { - "Name": "left", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Buffers.Buffer" - }, - { - "Name": "right", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Buffers.ReadOnlyBuffer" - } - ], - "ReturnType": "System.Boolean", - "Static": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "op_Inequality", - "Parameters": [ - { - "Name": "left", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Buffers.Buffer" - }, - { - "Name": "right", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Buffers.ReadOnlyBuffer" - } - ], - "ReturnType": "System.Boolean", - "Static": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "GetHashCode", - "Parameters": [], - "ReturnType": "System.Int32", - "Virtual": true, - "Override": true, - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [ - { - "ParameterName": "T", - "ParameterPosition": 0, - "BaseTypeOrInterfaces": [] - } - ] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Buffers.BufferHandle", - "Visibility": "Public", - "Kind": "Struct", - "Sealed": true, - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "Create", - "Parameters": [ - { - "Name": "owner", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Buffers.OwnedBuffer" - }, - { - "Name": "index", - "Type": "System.Int32" - }, - { - "Name": "handle", - "Type": "System.Runtime.InteropServices.GCHandle", - "DefaultValue": "default(System.Runtime.InteropServices.GCHandle)" - } - ], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Buffers.BufferHandle", - "Static": true, - "Visibility": "Public", - "GenericParameter": [ - { - "ParameterName": "T", - "ParameterPosition": 0, - "BaseTypeOrInterfaces": [] - } - ] - }, - { - "Kind": "Method", - "Name": "get_PinnedPointer", - "Parameters": [], - "ReturnType": "System.Void*", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Free", - "Parameters": [], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Buffers.BufferPool", - "Visibility": "Public", - "Kind": "Class", - "Abstract": true, - "ImplementedInterfaces": [ - "System.IDisposable" - ], - "Members": [ - { - "Kind": "Method", - "Name": "get_Default", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Buffers.BufferPool", - "Static": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Rent", - "Parameters": [ - { - "Name": "minimumBufferSize", - "Type": "System.Int32" - } - ], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Buffers.OwnedBuffer", - "Virtual": true, - "Abstract": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Dispose", - "Parameters": [], - "ReturnType": "System.Void", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "System.IDisposable", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Finalize", - "Parameters": [], - "ReturnType": "System.Void", - "Virtual": true, - "Override": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Dispose", - "Parameters": [ - { - "Name": "disposing", - "Type": "System.Boolean" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "Abstract": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [], - "Visibility": "Protected", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Buffers.DisposableReservation", - "Visibility": "Public", - "Kind": "Struct", - "Sealed": true, - "ImplementedInterfaces": [ - "System.IDisposable" - ], - "Members": [ - { - "Kind": "Method", - "Name": "get_Span", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Span", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Dispose", - "Parameters": [], - "ReturnType": "System.Void", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "System.IDisposable", - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [ - { - "ParameterName": "T", - "ParameterPosition": 0, - "BaseTypeOrInterfaces": [] - } - ] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Buffers.IOutput", - "Visibility": "Public", - "Kind": "Interface", - "Abstract": true, - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "get_Buffer", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Span", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Advance", - "Parameters": [ - { - "Name": "bytes", - "Type": "System.Int32" - } - ], - "ReturnType": "System.Void", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Enlarge", - "Parameters": [ - { - "Name": "desiredBufferLength", - "Type": "System.Int32", - "DefaultValue": "0" - } - ], - "ReturnType": "System.Void", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Buffers.OwnedBuffer", - "Visibility": "Public", - "Kind": "Class", - "Abstract": true, - "ImplementedInterfaces": [ - "System.IDisposable", - "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Buffers.IKnown" - ], - "Members": [ - { - "Kind": "Method", - "Name": "get_Length", - "Parameters": [], - "ReturnType": "System.Int32", - "Virtual": true, - "Abstract": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_Span", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Span", - "Virtual": true, - "Abstract": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_Buffer", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Buffers.Buffer", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_ReadOnlyBuffer", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Buffers.ReadOnlyBuffer", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "op_Implicit", - "Parameters": [ - { - "Name": "array", - "Type": "T0[]" - } - ], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Buffers.OwnedBuffer", - "Static": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_IsDisposed", - "Parameters": [], - "ReturnType": "System.Boolean", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Dispose", - "Parameters": [], - "ReturnType": "System.Void", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "System.IDisposable", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Dispose", - "Parameters": [ - { - "Name": "disposing", - "Type": "System.Boolean" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_HasOutstandingReferences", - "Parameters": [], - "ReturnType": "System.Boolean", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "AddReference", - "Parameters": [], - "ReturnType": "System.Void", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Buffers.IKnown", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Release", - "Parameters": [], - "ReturnType": "System.Void", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Buffers.IKnown", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "OnZeroReferences", - "Parameters": [], - "ReturnType": "System.Void", - "Virtual": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Pin", - "Parameters": [ - { - "Name": "index", - "Type": "System.Int32", - "DefaultValue": "0" - } - ], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Buffers.BufferHandle", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "TryGetArrayInternal", - "Parameters": [ - { - "Name": "buffer", - "Type": "System.ArraySegment", - "Direction": "Out" - } - ], - "ReturnType": "System.Boolean", - "Virtual": true, - "Abstract": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "TryGetPointerInternal", - "Parameters": [ - { - "Name": "pointer", - "Type": "System.Void*", - "Direction": "Out" - } - ], - "ReturnType": "System.Boolean", - "Virtual": true, - "Abstract": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [], - "Visibility": "Protected", - "GenericParameter": [] - } - ], - "GenericParameters": [ - { - "ParameterName": "T", - "ParameterPosition": 0, - "BaseTypeOrInterfaces": [] - } - ] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Buffers.ReadOnlyBuffer", - "Visibility": "Public", - "Kind": "Struct", - "Sealed": true, - "ImplementedInterfaces": [ - "System.IEquatable>", - "System.IEquatable>" - ], - "Members": [ - { - "Kind": "Method", - "Name": "op_Implicit", - "Parameters": [ - { - "Name": "array", - "Type": "T0[]" - } - ], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Buffers.ReadOnlyBuffer", - "Static": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_Empty", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Buffers.ReadOnlyBuffer", - "Static": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_Length", - "Parameters": [], - "ReturnType": "System.Int32", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_IsEmpty", - "Parameters": [], - "ReturnType": "System.Boolean", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Slice", - "Parameters": [ - { - "Name": "index", - "Type": "System.Int32" - } - ], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Buffers.ReadOnlyBuffer", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Slice", - "Parameters": [ - { - "Name": "index", - "Type": "System.Int32" - }, - { - "Name": "length", - "Type": "System.Int32" - } - ], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Buffers.ReadOnlyBuffer", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_Span", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.ReadOnlySpan", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Reserve", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Buffers.DisposableReservation", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Pin", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Buffers.BufferHandle", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "TryGetPointer", - "Parameters": [ - { - "Name": "pointer", - "Type": "System.Void*", - "Direction": "Out" - } - ], - "ReturnType": "System.Boolean", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "TryGetArray", - "Parameters": [ - { - "Name": "buffer", - "Type": "System.ArraySegment", - "Direction": "Out" - } - ], - "ReturnType": "System.Boolean", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ToArray", - "Parameters": [], - "ReturnType": "T0[]", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "CopyTo", - "Parameters": [ - { - "Name": "span", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Span" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "CopyTo", - "Parameters": [ - { - "Name": "buffer", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Buffers.Buffer" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Equals", - "Parameters": [ - { - "Name": "obj", - "Type": "System.Object" - } - ], - "ReturnType": "System.Boolean", - "Virtual": true, - "Override": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Equals", - "Parameters": [ - { - "Name": "other", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Buffers.Buffer" - } - ], - "ReturnType": "System.Boolean", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "System.IEquatable>", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Equals", - "Parameters": [ - { - "Name": "other", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Buffers.ReadOnlyBuffer" - } - ], - "ReturnType": "System.Boolean", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "System.IEquatable>", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "op_Equality", - "Parameters": [ - { - "Name": "left", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Buffers.ReadOnlyBuffer" - }, - { - "Name": "right", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Buffers.Buffer" - } - ], - "ReturnType": "System.Boolean", - "Static": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "op_Inequality", - "Parameters": [ - { - "Name": "left", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Buffers.ReadOnlyBuffer" - }, - { - "Name": "right", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Buffers.Buffer" - } - ], - "ReturnType": "System.Boolean", - "Static": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "op_Equality", - "Parameters": [ - { - "Name": "left", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Buffers.ReadOnlyBuffer" - }, - { - "Name": "right", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Buffers.ReadOnlyBuffer" - } - ], - "ReturnType": "System.Boolean", - "Static": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "op_Inequality", - "Parameters": [ - { - "Name": "left", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Buffers.ReadOnlyBuffer" - }, - { - "Name": "right", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.Buffers.ReadOnlyBuffer" - } - ], - "ReturnType": "System.Boolean", - "Static": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "GetHashCode", - "Parameters": [], - "ReturnType": "System.Int32", - "Virtual": true, - "Override": true, - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [ - { - "ParameterName": "T", - "ParameterPosition": 0, - "BaseTypeOrInterfaces": [] - } - ] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.SpanHelpers+PerTypeValues", - "Visibility": "Public", - "Kind": "Class", - "Abstract": true, - "Static": true, - "Sealed": true, - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Field", - "Name": "IsReferenceOrContainsReferences", - "Parameters": [], - "ReturnType": "System.Boolean", - "Static": true, - "ReadOnly": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "EmptyArray", - "Parameters": [], - "ReturnType": "T0[]", - "Static": true, - "ReadOnly": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "ArrayAdjustment", - "Parameters": [], - "ReturnType": "System.IntPtr", - "Static": true, - "ReadOnly": true, - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [ - { - "ParameterName": "T", - "ParameterPosition": 0, - "BaseTypeOrInterfaces": [] - } - ] - } - ] + "AssemblyIdentity": "Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions, Version=2.0.2.0, Culture=neutral, PublicKeyToken=adb9793829ddae60", + "Types": [] } \ No newline at end of file diff --git a/src/Kestrel.Transport.Libuv/baseline.netcore.json b/src/Kestrel.Transport.Libuv/baseline.netcore.json index 9dce3fe708..b7c1b7e61b 100644 --- a/src/Kestrel.Transport.Libuv/baseline.netcore.json +++ b/src/Kestrel.Transport.Libuv/baseline.netcore.json @@ -1,5 +1,5 @@ { - "AssemblyIdentity": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv, Version=2.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60", + "AssemblyIdentity": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv, Version=2.0.2.0, Culture=neutral, PublicKeyToken=adb9793829ddae60", "Types": [ { "Name": "Microsoft.AspNetCore.Hosting.WebHostBuilderLibuvExtensions", @@ -262,5611 +262,6 @@ } ], "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.ILibuvTrace", - "Visibility": "Public", - "Kind": "Interface", - "Abstract": true, - "ImplementedInterfaces": [ - "Microsoft.Extensions.Logging.ILogger" - ], - "Members": [ - { - "Kind": "Method", - "Name": "ConnectionRead", - "Parameters": [ - { - "Name": "connectionId", - "Type": "System.String" - }, - { - "Name": "count", - "Type": "System.Int32" - } - ], - "ReturnType": "System.Void", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ConnectionReadFin", - "Parameters": [ - { - "Name": "connectionId", - "Type": "System.String" - } - ], - "ReturnType": "System.Void", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ConnectionWriteFin", - "Parameters": [ - { - "Name": "connectionId", - "Type": "System.String" - } - ], - "ReturnType": "System.Void", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ConnectionWroteFin", - "Parameters": [ - { - "Name": "connectionId", - "Type": "System.String" - }, - { - "Name": "status", - "Type": "System.Int32" - } - ], - "ReturnType": "System.Void", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ConnectionWrite", - "Parameters": [ - { - "Name": "connectionId", - "Type": "System.String" - }, - { - "Name": "count", - "Type": "System.Int32" - } - ], - "ReturnType": "System.Void", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ConnectionWriteCallback", - "Parameters": [ - { - "Name": "connectionId", - "Type": "System.String" - }, - { - "Name": "status", - "Type": "System.Int32" - } - ], - "ReturnType": "System.Void", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ConnectionError", - "Parameters": [ - { - "Name": "connectionId", - "Type": "System.String" - }, - { - "Name": "ex", - "Type": "System.Exception" - } - ], - "ReturnType": "System.Void", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ConnectionReset", - "Parameters": [ - { - "Name": "connectionId", - "Type": "System.String" - } - ], - "ReturnType": "System.Void", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ConnectionPause", - "Parameters": [ - { - "Name": "connectionId", - "Type": "System.String" - } - ], - "ReturnType": "System.Void", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ConnectionResume", - "Parameters": [ - { - "Name": "connectionId", - "Type": "System.String" - } - ], - "ReturnType": "System.Void", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.LibuvAwaitable", - "Visibility": "Public", - "Kind": "Class", - "ImplementedInterfaces": [ - "System.Runtime.CompilerServices.ICriticalNotifyCompletion" - ], - "Members": [ - { - "Kind": "Method", - "Name": "GetAwaiter", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.LibuvAwaitable", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_IsCompleted", - "Parameters": [], - "ReturnType": "System.Boolean", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "GetResult", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.UvWriteResult", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "OnCompleted", - "Parameters": [ - { - "Name": "continuation", - "Type": "System.Action" - } - ], - "ReturnType": "System.Void", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "System.Runtime.CompilerServices.INotifyCompletion", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "UnsafeOnCompleted", - "Parameters": [ - { - "Name": "continuation", - "Type": "System.Action" - } - ], - "ReturnType": "System.Void", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "System.Runtime.CompilerServices.ICriticalNotifyCompletion", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [], - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "Callback", - "Parameters": [], - "ReturnType": "System.Action", - "Static": true, - "ReadOnly": true, - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [ - { - "ParameterName": "TRequest", - "ParameterPosition": 0, - "BaseTypeOrInterfaces": [ - "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.UvRequest" - ] - } - ] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.UvWriteResult", - "Visibility": "Public", - "Kind": "Struct", - "Sealed": true, - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "get_Status", - "Parameters": [], - "ReturnType": "System.Int32", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_Error", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.UvException", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "status", - "Type": "System.Int32" - }, - { - "Name": "error", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.UvException" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.LibuvConnection", - "Visibility": "Public", - "Kind": "Class", - "BaseType": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.LibuvConnectionContext", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "get_ConnectionId", - "Parameters": [], - "ReturnType": "System.String", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_ConnectionId", - "Parameters": [ - { - "Name": "value", - "Type": "System.String" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_Input", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.IPipeWriter", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_Input", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.IPipeWriter" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_Output", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.LibuvOutputConsumer", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_Output", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.LibuvOutputConsumer" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Start", - "Parameters": [], - "ReturnType": "System.Threading.Tasks.Task", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "context", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.ListenerContext" - }, - { - "Name": "socket", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.UvStreamHandle" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.LibuvConnectionContext", - "Visibility": "Public", - "Kind": "Class", - "ImplementedInterfaces": [ - "Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal.IConnectionInformation" - ], - "Members": [ - { - "Kind": "Method", - "Name": "get_ListenerContext", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.ListenerContext", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_ListenerContext", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.ListenerContext" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_RemoteEndPoint", - "Parameters": [], - "ReturnType": "System.Net.IPEndPoint", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal.IConnectionInformation", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_RemoteEndPoint", - "Parameters": [ - { - "Name": "value", - "Type": "System.Net.IPEndPoint" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_LocalEndPoint", - "Parameters": [], - "ReturnType": "System.Net.IPEndPoint", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal.IConnectionInformation", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_LocalEndPoint", - "Parameters": [ - { - "Name": "value", - "Type": "System.Net.IPEndPoint" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_PipeFactory", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.PipeFactory", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal.IConnectionInformation", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_InputWriterScheduler", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.IScheduler", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal.IConnectionInformation", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_OutputReaderScheduler", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.IScheduler", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal.IConnectionInformation", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [], - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "context", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.ListenerContext" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.LibuvOutputConsumer", - "Visibility": "Public", - "Kind": "Class", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "WriteOutputAsync", - "Parameters": [], - "ReturnType": "System.Threading.Tasks.Task", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "pipe", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.IPipeReader" - }, - { - "Name": "thread", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.LibuvThread" - }, - { - "Name": "socket", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.UvStreamHandle" - }, - { - "Name": "connectionId", - "Type": "System.String" - }, - { - "Name": "log", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.ILibuvTrace" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.LibuvThread", - "Visibility": "Public", - "Kind": "Class", - "ImplementedInterfaces": [ - "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.IScheduler" - ], - "Members": [ - { - "Kind": "Method", - "Name": "get_Loop", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.UvLoopHandle", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_PipeFactory", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.PipeFactory", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_WriteReqPool", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.WriteReqPool", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_Requests", - "Parameters": [], - "ReturnType": "System.Collections.Generic.List", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_FatalError", - "Parameters": [], - "ReturnType": "System.Runtime.ExceptionServices.ExceptionDispatchInfo", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_QueueCloseHandle", - "Parameters": [], - "ReturnType": "System.Action, System.IntPtr>", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "StartAsync", - "Parameters": [], - "ReturnType": "System.Threading.Tasks.Task", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "StopAsync", - "Parameters": [ - { - "Name": "timeout", - "Type": "System.TimeSpan" - } - ], - "ReturnType": "System.Threading.Tasks.Task", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Post", - "Parameters": [ - { - "Name": "callback", - "Type": "System.Action" - }, - { - "Name": "state", - "Type": "T0" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [ - { - "ParameterName": "T", - "ParameterPosition": 0, - "BaseTypeOrInterfaces": [] - } - ] - }, - { - "Kind": "Method", - "Name": "PostAsync", - "Parameters": [ - { - "Name": "callback", - "Type": "System.Action" - }, - { - "Name": "state", - "Type": "T0" - } - ], - "ReturnType": "System.Threading.Tasks.Task", - "Visibility": "Public", - "GenericParameter": [ - { - "ParameterName": "T", - "ParameterPosition": 0, - "BaseTypeOrInterfaces": [] - } - ] - }, - { - "Kind": "Method", - "Name": "Walk", - "Parameters": [ - { - "Name": "callback", - "Type": "System.Action" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Schedule", - "Parameters": [ - { - "Name": "action", - "Type": "System.Action" - }, - { - "Name": "state", - "Type": "System.Object" - } - ], - "ReturnType": "System.Void", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.IScheduler", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "transport", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.LibuvTransport" - } - ], - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "transport", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.LibuvTransport" - }, - { - "Name": "maxLoops", - "Type": "System.Int32" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.LibuvTrace", - "Visibility": "Public", - "Kind": "Class", - "ImplementedInterfaces": [ - "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.ILibuvTrace" - ], - "Members": [ - { - "Kind": "Method", - "Name": "ConnectionRead", - "Parameters": [ - { - "Name": "connectionId", - "Type": "System.String" - }, - { - "Name": "count", - "Type": "System.Int32" - } - ], - "ReturnType": "System.Void", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.ILibuvTrace", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ConnectionReadFin", - "Parameters": [ - { - "Name": "connectionId", - "Type": "System.String" - } - ], - "ReturnType": "System.Void", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.ILibuvTrace", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ConnectionWriteFin", - "Parameters": [ - { - "Name": "connectionId", - "Type": "System.String" - } - ], - "ReturnType": "System.Void", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.ILibuvTrace", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ConnectionWroteFin", - "Parameters": [ - { - "Name": "connectionId", - "Type": "System.String" - }, - { - "Name": "status", - "Type": "System.Int32" - } - ], - "ReturnType": "System.Void", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.ILibuvTrace", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ConnectionWrite", - "Parameters": [ - { - "Name": "connectionId", - "Type": "System.String" - }, - { - "Name": "count", - "Type": "System.Int32" - } - ], - "ReturnType": "System.Void", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.ILibuvTrace", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ConnectionWriteCallback", - "Parameters": [ - { - "Name": "connectionId", - "Type": "System.String" - }, - { - "Name": "status", - "Type": "System.Int32" - } - ], - "ReturnType": "System.Void", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.ILibuvTrace", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ConnectionError", - "Parameters": [ - { - "Name": "connectionId", - "Type": "System.String" - }, - { - "Name": "ex", - "Type": "System.Exception" - } - ], - "ReturnType": "System.Void", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.ILibuvTrace", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ConnectionReset", - "Parameters": [ - { - "Name": "connectionId", - "Type": "System.String" - } - ], - "ReturnType": "System.Void", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.ILibuvTrace", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ConnectionPause", - "Parameters": [ - { - "Name": "connectionId", - "Type": "System.String" - } - ], - "ReturnType": "System.Void", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.ILibuvTrace", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ConnectionResume", - "Parameters": [ - { - "Name": "connectionId", - "Type": "System.String" - } - ], - "ReturnType": "System.Void", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.ILibuvTrace", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "BeginScope", - "Parameters": [ - { - "Name": "state", - "Type": "T0" - } - ], - "ReturnType": "System.IDisposable", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "Microsoft.Extensions.Logging.ILogger", - "Visibility": "Public", - "GenericParameter": [ - { - "ParameterName": "TState", - "ParameterPosition": 0, - "BaseTypeOrInterfaces": [] - } - ] - }, - { - "Kind": "Method", - "Name": "IsEnabled", - "Parameters": [ - { - "Name": "logLevel", - "Type": "Microsoft.Extensions.Logging.LogLevel" - } - ], - "ReturnType": "System.Boolean", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "Microsoft.Extensions.Logging.ILogger", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Log", - "Parameters": [ - { - "Name": "logLevel", - "Type": "Microsoft.Extensions.Logging.LogLevel" - }, - { - "Name": "eventId", - "Type": "Microsoft.Extensions.Logging.EventId" - }, - { - "Name": "state", - "Type": "T0" - }, - { - "Name": "exception", - "Type": "System.Exception" - }, - { - "Name": "formatter", - "Type": "System.Func" - } - ], - "ReturnType": "System.Void", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "Microsoft.Extensions.Logging.ILogger", - "Visibility": "Public", - "GenericParameter": [ - { - "ParameterName": "TState", - "ParameterPosition": 0, - "BaseTypeOrInterfaces": [] - } - ] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "logger", - "Type": "Microsoft.Extensions.Logging.ILogger" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.LibuvTransportContext", - "Visibility": "Public", - "Kind": "Class", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "get_Options", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.LibuvTransportOptions", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_Options", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.LibuvTransportOptions" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_AppLifetime", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Hosting.IApplicationLifetime", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_AppLifetime", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.AspNetCore.Hosting.IApplicationLifetime" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_Log", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.ILibuvTrace", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_Log", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.ILibuvTrace" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_ConnectionHandler", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal.IConnectionHandler", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_ConnectionHandler", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal.IConnectionHandler" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Listener", - "Visibility": "Public", - "Kind": "Class", - "BaseType": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.ListenerContext", - "ImplementedInterfaces": [ - "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.IAsyncDisposable" - ], - "Members": [ - { - "Kind": "Method", - "Name": "get_ListenSocket", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.UvStreamHandle", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_Log", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.ILibuvTrace", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "StartAsync", - "Parameters": [ - { - "Name": "endPointInformation", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal.IEndPointInformation" - }, - { - "Name": "thread", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.LibuvThread" - } - ], - "ReturnType": "System.Threading.Tasks.Task", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "DispatchConnection", - "Parameters": [ - { - "Name": "socket", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.UvStreamHandle" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "DisposeAsync", - "Parameters": [], - "ReturnType": "System.Threading.Tasks.Task", - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.IAsyncDisposable", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "transportContext", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.LibuvTransportContext" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.ListenerContext", - "Visibility": "Public", - "Kind": "Class", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "get_TransportContext", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.LibuvTransportContext", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_TransportContext", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.LibuvTransportContext" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_EndPointInformation", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal.IEndPointInformation", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_EndPointInformation", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal.IEndPointInformation" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_Thread", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.LibuvThread", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_Thread", - "Parameters": [ - { - "Name": "value", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.LibuvThread" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "CreateAcceptSocket", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.UvStreamHandle", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "transportContext", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.LibuvTransportContext" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.ListenerPrimary", - "Visibility": "Public", - "Kind": "Class", - "BaseType": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Listener", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "get_UvPipeCount", - "Parameters": [], - "ReturnType": "System.Int32", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "StartAsync", - "Parameters": [ - { - "Name": "pipeName", - "Type": "System.String" - }, - { - "Name": "pipeMessage", - "Type": "System.Byte[]" - }, - { - "Name": "endPointInformation", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal.IEndPointInformation" - }, - { - "Name": "thread", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.LibuvThread" - } - ], - "ReturnType": "System.Threading.Tasks.Task", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "DispatchConnection", - "Parameters": [ - { - "Name": "socket", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.UvStreamHandle" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "Override": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "DisposeAsync", - "Parameters": [], - "ReturnType": "System.Threading.Tasks.Task", - "Virtual": true, - "Override": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.IAsyncDisposable", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "transportContext", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.LibuvTransportContext" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.ListenerSecondary", - "Visibility": "Public", - "Kind": "Class", - "BaseType": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.ListenerContext", - "ImplementedInterfaces": [ - "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.IAsyncDisposable" - ], - "Members": [ - { - "Kind": "Method", - "Name": "get_Log", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.ILibuvTrace", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "StartAsync", - "Parameters": [ - { - "Name": "pipeName", - "Type": "System.String" - }, - { - "Name": "pipeMessage", - "Type": "System.Byte[]" - }, - { - "Name": "endPointInformation", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal.IEndPointInformation" - }, - { - "Name": "thread", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.LibuvThread" - } - ], - "ReturnType": "System.Threading.Tasks.Task", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "DisposeAsync", - "Parameters": [], - "ReturnType": "System.Threading.Tasks.Task", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.IAsyncDisposable", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "transportContext", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.LibuvTransportContext" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.WriteReqPool", - "Visibility": "Public", - "Kind": "Class", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "Allocate", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.UvWriteReq", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Return", - "Parameters": [ - { - "Name": "req", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.UvWriteReq" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Dispose", - "Parameters": [], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "thread", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.LibuvThread" - }, - { - "Name": "log", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.ILibuvTrace" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.LibuvFunctions", - "Visibility": "Public", - "Kind": "Class", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "ThrowIfErrored", - "Parameters": [ - { - "Name": "statusCode", - "Type": "System.Int32" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Check", - "Parameters": [ - { - "Name": "statusCode", - "Type": "System.Int32" - }, - { - "Name": "error", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.UvException", - "Direction": "Out" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "loop_init", - "Parameters": [ - { - "Name": "handle", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.UvLoopHandle" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "loop_close", - "Parameters": [ - { - "Name": "handle", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.UvLoopHandle" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "run", - "Parameters": [ - { - "Name": "handle", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.UvLoopHandle" - }, - { - "Name": "mode", - "Type": "System.Int32" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "stop", - "Parameters": [ - { - "Name": "handle", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.UvLoopHandle" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ref", - "Parameters": [ - { - "Name": "handle", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.UvHandle" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "unref", - "Parameters": [ - { - "Name": "handle", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.UvHandle" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "uv_fileno", - "Parameters": [ - { - "Name": "handle", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.UvHandle" - }, - { - "Name": "socket", - "Type": "System.IntPtr", - "Direction": "Ref" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "close", - "Parameters": [ - { - "Name": "handle", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.UvHandle" - }, - { - "Name": "close_cb", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.LibuvFunctions+uv_close_cb" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "close", - "Parameters": [ - { - "Name": "handle", - "Type": "System.IntPtr" - }, - { - "Name": "close_cb", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.LibuvFunctions+uv_close_cb" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "async_init", - "Parameters": [ - { - "Name": "loop", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.UvLoopHandle" - }, - { - "Name": "handle", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.UvAsyncHandle" - }, - { - "Name": "cb", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.LibuvFunctions+uv_async_cb" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "async_send", - "Parameters": [ - { - "Name": "handle", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.UvAsyncHandle" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "unsafe_async_send", - "Parameters": [ - { - "Name": "handle", - "Type": "System.IntPtr" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "tcp_init", - "Parameters": [ - { - "Name": "loop", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.UvLoopHandle" - }, - { - "Name": "handle", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.UvTcpHandle" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "tcp_bind", - "Parameters": [ - { - "Name": "handle", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.UvTcpHandle" - }, - { - "Name": "addr", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.SockAddr", - "Direction": "Ref" - }, - { - "Name": "flags", - "Type": "System.Int32" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "tcp_open", - "Parameters": [ - { - "Name": "handle", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.UvTcpHandle" - }, - { - "Name": "hSocket", - "Type": "System.IntPtr" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "tcp_nodelay", - "Parameters": [ - { - "Name": "handle", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.UvTcpHandle" - }, - { - "Name": "enable", - "Type": "System.Boolean" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "pipe_init", - "Parameters": [ - { - "Name": "loop", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.UvLoopHandle" - }, - { - "Name": "handle", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.UvPipeHandle" - }, - { - "Name": "ipc", - "Type": "System.Boolean" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "pipe_bind", - "Parameters": [ - { - "Name": "handle", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.UvPipeHandle" - }, - { - "Name": "name", - "Type": "System.String" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "pipe_open", - "Parameters": [ - { - "Name": "handle", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.UvPipeHandle" - }, - { - "Name": "hSocket", - "Type": "System.IntPtr" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "listen", - "Parameters": [ - { - "Name": "handle", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.UvStreamHandle" - }, - { - "Name": "backlog", - "Type": "System.Int32" - }, - { - "Name": "cb", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.LibuvFunctions+uv_connection_cb" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "accept", - "Parameters": [ - { - "Name": "server", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.UvStreamHandle" - }, - { - "Name": "client", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.UvStreamHandle" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "pipe_connect", - "Parameters": [ - { - "Name": "req", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.UvConnectRequest" - }, - { - "Name": "handle", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.UvPipeHandle" - }, - { - "Name": "name", - "Type": "System.String" - }, - { - "Name": "cb", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.LibuvFunctions+uv_connect_cb" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "pipe_pending_count", - "Parameters": [ - { - "Name": "handle", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.UvPipeHandle" - } - ], - "ReturnType": "System.Int32", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "read_start", - "Parameters": [ - { - "Name": "handle", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.UvStreamHandle" - }, - { - "Name": "alloc_cb", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.LibuvFunctions+uv_alloc_cb" - }, - { - "Name": "read_cb", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.LibuvFunctions+uv_read_cb" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "read_stop", - "Parameters": [ - { - "Name": "handle", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.UvStreamHandle" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "try_write", - "Parameters": [ - { - "Name": "handle", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.UvStreamHandle" - }, - { - "Name": "bufs", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.LibuvFunctions+uv_buf_t[]" - }, - { - "Name": "nbufs", - "Type": "System.Int32" - } - ], - "ReturnType": "System.Int32", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "write", - "Parameters": [ - { - "Name": "req", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.UvRequest" - }, - { - "Name": "handle", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.UvStreamHandle" - }, - { - "Name": "bufs", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.LibuvFunctions+uv_buf_t*" - }, - { - "Name": "nbufs", - "Type": "System.Int32" - }, - { - "Name": "cb", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.LibuvFunctions+uv_write_cb" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "write2", - "Parameters": [ - { - "Name": "req", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.UvRequest" - }, - { - "Name": "handle", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.UvStreamHandle" - }, - { - "Name": "bufs", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.LibuvFunctions+uv_buf_t*" - }, - { - "Name": "nbufs", - "Type": "System.Int32" - }, - { - "Name": "sendHandle", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.UvStreamHandle" - }, - { - "Name": "cb", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.LibuvFunctions+uv_write_cb" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "err_name", - "Parameters": [ - { - "Name": "err", - "Type": "System.Int32" - } - ], - "ReturnType": "System.String", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "strerror", - "Parameters": [ - { - "Name": "err", - "Type": "System.Int32" - } - ], - "ReturnType": "System.String", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "loop_size", - "Parameters": [], - "ReturnType": "System.Int32", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "handle_size", - "Parameters": [ - { - "Name": "handleType", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.LibuvFunctions+HandleType" - } - ], - "ReturnType": "System.Int32", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "req_size", - "Parameters": [ - { - "Name": "reqType", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.LibuvFunctions+RequestType" - } - ], - "ReturnType": "System.Int32", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ip4_addr", - "Parameters": [ - { - "Name": "ip", - "Type": "System.String" - }, - { - "Name": "port", - "Type": "System.Int32" - }, - { - "Name": "addr", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.SockAddr", - "Direction": "Out" - }, - { - "Name": "error", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.UvException", - "Direction": "Out" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ip6_addr", - "Parameters": [ - { - "Name": "ip", - "Type": "System.String" - }, - { - "Name": "port", - "Type": "System.Int32" - }, - { - "Name": "addr", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.SockAddr", - "Direction": "Out" - }, - { - "Name": "error", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.UvException", - "Direction": "Out" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "walk", - "Parameters": [ - { - "Name": "loop", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.UvLoopHandle" - }, - { - "Name": "walk_cb", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.LibuvFunctions+uv_walk_cb" - }, - { - "Name": "arg", - "Type": "System.IntPtr" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "timer_init", - "Parameters": [ - { - "Name": "loop", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.UvLoopHandle" - }, - { - "Name": "handle", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.UvTimerHandle" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "timer_start", - "Parameters": [ - { - "Name": "handle", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.UvTimerHandle" - }, - { - "Name": "cb", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.LibuvFunctions+uv_timer_cb" - }, - { - "Name": "timeout", - "Type": "System.Int64" - }, - { - "Name": "repeat", - "Type": "System.Int64" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "timer_stop", - "Parameters": [ - { - "Name": "handle", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.UvTimerHandle" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "now", - "Parameters": [ - { - "Name": "loop", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.UvLoopHandle" - } - ], - "ReturnType": "System.Int64", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "tcp_getsockname", - "Parameters": [ - { - "Name": "handle", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.UvTcpHandle" - }, - { - "Name": "addr", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.SockAddr", - "Direction": "Out" - }, - { - "Name": "namelen", - "Type": "System.Int32", - "Direction": "Ref" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "tcp_getpeername", - "Parameters": [ - { - "Name": "handle", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.UvTcpHandle" - }, - { - "Name": "addr", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.SockAddr", - "Direction": "Out" - }, - { - "Name": "namelen", - "Type": "System.Int32", - "Direction": "Ref" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "buf_init", - "Parameters": [ - { - "Name": "memory", - "Type": "System.IntPtr" - }, - { - "Name": "len", - "Type": "System.Int32" - } - ], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.LibuvFunctions+uv_buf_t", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [], - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "onlyForTesting", - "Type": "System.Boolean" - } - ], - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "IsWindows", - "Parameters": [], - "ReturnType": "System.Boolean", - "ReadOnly": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "_uv_loop_init", - "Parameters": [], - "ReturnType": "System.Func", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "_uv_loop_close", - "Parameters": [], - "ReturnType": "System.Func", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "_uv_run", - "Parameters": [], - "ReturnType": "System.Func", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "_uv_stop", - "Parameters": [], - "ReturnType": "System.Action", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "_uv_ref", - "Parameters": [], - "ReturnType": "System.Action", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "_uv_unref", - "Parameters": [], - "ReturnType": "System.Action", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "_uv_fileno", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.LibuvFunctions+uv_fileno_func", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "_uv_close", - "Parameters": [], - "ReturnType": "System.Action", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "_uv_async_init", - "Parameters": [], - "ReturnType": "System.Func", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "_uv_async_send", - "Parameters": [], - "ReturnType": "System.Func", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "_uv_unsafe_async_send", - "Parameters": [], - "ReturnType": "System.Func", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "_uv_tcp_init", - "Parameters": [], - "ReturnType": "System.Func", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "_uv_tcp_bind", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.LibuvFunctions+uv_tcp_bind_func", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "_uv_tcp_open", - "Parameters": [], - "ReturnType": "System.Func", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "_uv_tcp_nodelay", - "Parameters": [], - "ReturnType": "System.Func", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "_uv_pipe_init", - "Parameters": [], - "ReturnType": "System.Func", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "_uv_pipe_bind", - "Parameters": [], - "ReturnType": "System.Func", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "_uv_pipe_open", - "Parameters": [], - "ReturnType": "System.Func", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "_uv_listen", - "Parameters": [], - "ReturnType": "System.Func", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "_uv_accept", - "Parameters": [], - "ReturnType": "System.Func", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "_uv_pipe_connect", - "Parameters": [], - "ReturnType": "System.Action", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "_uv_pipe_pending_count", - "Parameters": [], - "ReturnType": "System.Func", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "_uv_read_start", - "Parameters": [], - "ReturnType": "System.Func", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "_uv_read_stop", - "Parameters": [], - "ReturnType": "System.Func", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "_uv_try_write", - "Parameters": [], - "ReturnType": "System.Func", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "_uv_write", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.LibuvFunctions+uv_write_func", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "_uv_write2", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.LibuvFunctions+uv_write2_func", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "_uv_err_name", - "Parameters": [], - "ReturnType": "System.Func", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "_uv_strerror", - "Parameters": [], - "ReturnType": "System.Func", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "_uv_loop_size", - "Parameters": [], - "ReturnType": "System.Func", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "_uv_handle_size", - "Parameters": [], - "ReturnType": "System.Func", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "_uv_req_size", - "Parameters": [], - "ReturnType": "System.Func", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "_uv_ip4_addr", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.LibuvFunctions+uv_ip4_addr_func", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "_uv_ip6_addr", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.LibuvFunctions+uv_ip6_addr_func", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "_uv_walk", - "Parameters": [], - "ReturnType": "System.Func", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "_uv_timer_init", - "Parameters": [], - "ReturnType": "System.Func", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "_uv_timer_start", - "Parameters": [], - "ReturnType": "System.Func", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "_uv_timer_stop", - "Parameters": [], - "ReturnType": "System.Func", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "_uv_now", - "Parameters": [], - "ReturnType": "System.Func", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "_uv_tcp_getsockname", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.LibuvFunctions+uv_tcp_getsockname_func", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "_uv_tcp_getpeername", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.LibuvFunctions+uv_tcp_getpeername_func", - "Visibility": "Protected", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.PlatformApis", - "Visibility": "Public", - "Kind": "Class", - "Abstract": true, - "Static": true, - "Sealed": true, - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "get_IsWindows", - "Parameters": [], - "ReturnType": "System.Boolean", - "Static": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_IsDarwin", - "Parameters": [], - "ReturnType": "System.Boolean", - "Static": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "VolatileRead", - "Parameters": [ - { - "Name": "value", - "Type": "System.Int64", - "Direction": "Ref" - } - ], - "ReturnType": "System.Int64", - "Static": true, - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.SockAddr", - "Visibility": "Public", - "Kind": "Struct", - "Sealed": true, - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "GetIPEndPoint", - "Parameters": [], - "ReturnType": "System.Net.IPEndPoint", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_ScopeId", - "Parameters": [], - "ReturnType": "System.UInt32", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "set_ScopeId", - "Parameters": [ - { - "Name": "value", - "Type": "System.UInt32" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "ignored", - "Type": "System.Int64" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.UvAsyncHandle", - "Visibility": "Public", - "Kind": "Class", - "BaseType": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.UvHandle", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "Init", - "Parameters": [ - { - "Name": "loop", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.UvLoopHandle" - }, - { - "Name": "callback", - "Type": "System.Action" - }, - { - "Name": "queueCloseHandle", - "Type": "System.Action, System.IntPtr>" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Send", - "Parameters": [], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ReleaseHandle", - "Parameters": [], - "ReturnType": "System.Boolean", - "Virtual": true, - "Override": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "logger", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.ILibuvTrace" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.UvConnectRequest", - "Visibility": "Public", - "Kind": "Class", - "BaseType": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.UvRequest", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "Init", - "Parameters": [ - { - "Name": "thread", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.LibuvThread" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "Override": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "DangerousInit", - "Parameters": [ - { - "Name": "loop", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.UvLoopHandle" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Connect", - "Parameters": [ - { - "Name": "pipe", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.UvPipeHandle" - }, - { - "Name": "name", - "Type": "System.String" - }, - { - "Name": "callback", - "Type": "System.Action" - }, - { - "Name": "state", - "Type": "System.Object" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "logger", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.ILibuvTrace" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.UvException", - "Visibility": "Public", - "Kind": "Class", - "BaseType": "System.Exception", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "get_StatusCode", - "Parameters": [], - "ReturnType": "System.Int32", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "message", - "Type": "System.String" - }, - { - "Name": "statusCode", - "Type": "System.Int32" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.UvHandle", - "Visibility": "Public", - "Kind": "Class", - "Abstract": true, - "BaseType": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.UvMemory", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "CreateHandle", - "Parameters": [ - { - "Name": "uv", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.LibuvFunctions" - }, - { - "Name": "threadId", - "Type": "System.Int32" - }, - { - "Name": "size", - "Type": "System.Int32" - }, - { - "Name": "queueCloseHandle", - "Type": "System.Action, System.IntPtr>" - } - ], - "ReturnType": "System.Void", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ReleaseHandle", - "Parameters": [], - "ReturnType": "System.Boolean", - "Virtual": true, - "Override": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Reference", - "Parameters": [], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Unreference", - "Parameters": [], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "logger", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.ILibuvTrace" - } - ], - "Visibility": "Protected", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.UvLoopHandle", - "Visibility": "Public", - "Kind": "Class", - "BaseType": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.UvMemory", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "Init", - "Parameters": [ - { - "Name": "uv", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.LibuvFunctions" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Run", - "Parameters": [ - { - "Name": "mode", - "Type": "System.Int32", - "DefaultValue": "0" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Stop", - "Parameters": [], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Now", - "Parameters": [], - "ReturnType": "System.Int64", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ReleaseHandle", - "Parameters": [], - "ReturnType": "System.Boolean", - "Virtual": true, - "Override": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "logger", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.ILibuvTrace" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.UvMemory", - "Visibility": "Public", - "Kind": "Class", - "Abstract": true, - "BaseType": "System.Runtime.InteropServices.SafeHandle", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "get_Libuv", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.LibuvFunctions", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_IsInvalid", - "Parameters": [], - "ReturnType": "System.Boolean", - "Virtual": true, - "Override": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "get_ThreadId", - "Parameters": [], - "ReturnType": "System.Int32", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "CreateMemory", - "Parameters": [ - { - "Name": "uv", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.LibuvFunctions" - }, - { - "Name": "threadId", - "Type": "System.Int32" - }, - { - "Name": "size", - "Type": "System.Int32" - } - ], - "ReturnType": "System.Void", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "DestroyMemory", - "Parameters": [ - { - "Name": "memory", - "Type": "System.IntPtr" - } - ], - "ReturnType": "System.Void", - "Static": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "DestroyMemory", - "Parameters": [ - { - "Name": "memory", - "Type": "System.IntPtr" - }, - { - "Name": "gcHandlePtr", - "Type": "System.IntPtr" - } - ], - "ReturnType": "System.Void", - "Static": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "InternalGetHandle", - "Parameters": [], - "ReturnType": "System.IntPtr", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Validate", - "Parameters": [ - { - "Name": "closed", - "Type": "System.Boolean", - "DefaultValue": "False" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "FromIntPtr", - "Parameters": [ - { - "Name": "handle", - "Type": "System.IntPtr" - } - ], - "ReturnType": "T0", - "Static": true, - "Visibility": "Public", - "GenericParameter": [ - { - "ParameterName": "THandle", - "ParameterPosition": 0, - "BaseTypeOrInterfaces": [] - } - ] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "logger", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.ILibuvTrace" - }, - { - "Name": "handleType", - "Type": "System.Runtime.InteropServices.GCHandleType", - "DefaultValue": "0" - } - ], - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "_uv", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.LibuvFunctions", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "_threadId", - "Parameters": [], - "ReturnType": "System.Int32", - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Field", - "Name": "_log", - "Parameters": [], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.ILibuvTrace", - "ReadOnly": true, - "Visibility": "Protected", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.UvPipeHandle", - "Visibility": "Public", - "Kind": "Class", - "BaseType": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.UvStreamHandle", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "Init", - "Parameters": [ - { - "Name": "loop", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.UvLoopHandle" - }, - { - "Name": "queueCloseHandle", - "Type": "System.Action, System.IntPtr>" - }, - { - "Name": "ipc", - "Type": "System.Boolean", - "DefaultValue": "False" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Open", - "Parameters": [ - { - "Name": "fileDescriptor", - "Type": "System.IntPtr" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Bind", - "Parameters": [ - { - "Name": "name", - "Type": "System.String" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "PendingCount", - "Parameters": [], - "ReturnType": "System.Int32", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "logger", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.ILibuvTrace" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.UvRequest", - "Visibility": "Public", - "Kind": "Class", - "BaseType": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.UvMemory", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "Init", - "Parameters": [ - { - "Name": "thread", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.LibuvThread" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ReleaseHandle", - "Parameters": [], - "ReturnType": "System.Boolean", - "Virtual": true, - "Override": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "logger", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.ILibuvTrace" - } - ], - "Visibility": "Protected", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.UvStreamHandle", - "Visibility": "Public", - "Kind": "Class", - "Abstract": true, - "BaseType": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.UvHandle", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "ReleaseHandle", - "Parameters": [], - "ReturnType": "System.Boolean", - "Virtual": true, - "Override": true, - "Visibility": "Protected", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Listen", - "Parameters": [ - { - "Name": "backlog", - "Type": "System.Int32" - }, - { - "Name": "callback", - "Type": "System.Action" - }, - { - "Name": "state", - "Type": "System.Object" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Accept", - "Parameters": [ - { - "Name": "handle", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.UvStreamHandle" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ReadStart", - "Parameters": [ - { - "Name": "allocCallback", - "Type": "System.Func" - }, - { - "Name": "readCallback", - "Type": "System.Action" - }, - { - "Name": "state", - "Type": "System.Object" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "ReadStop", - "Parameters": [], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "TryWrite", - "Parameters": [ - { - "Name": "buf", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.LibuvFunctions+uv_buf_t" - } - ], - "ReturnType": "System.Int32", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "logger", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.ILibuvTrace" - } - ], - "Visibility": "Protected", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.UvTcpHandle", - "Visibility": "Public", - "Kind": "Class", - "BaseType": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.UvStreamHandle", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "Init", - "Parameters": [ - { - "Name": "loop", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.UvLoopHandle" - }, - { - "Name": "queueCloseHandle", - "Type": "System.Action, System.IntPtr>" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Open", - "Parameters": [ - { - "Name": "fileDescriptor", - "Type": "System.IntPtr" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Bind", - "Parameters": [ - { - "Name": "endPoint", - "Type": "System.Net.IPEndPoint" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "GetPeerIPEndPoint", - "Parameters": [], - "ReturnType": "System.Net.IPEndPoint", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "GetSockIPEndPoint", - "Parameters": [], - "ReturnType": "System.Net.IPEndPoint", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "NoDelay", - "Parameters": [ - { - "Name": "enable", - "Type": "System.Boolean" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "logger", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.ILibuvTrace" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.UvTimerHandle", - "Visibility": "Public", - "Kind": "Class", - "BaseType": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.UvHandle", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "Init", - "Parameters": [ - { - "Name": "loop", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.UvLoopHandle" - }, - { - "Name": "queueCloseHandle", - "Type": "System.Action, System.IntPtr>" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Start", - "Parameters": [ - { - "Name": "callback", - "Type": "System.Action" - }, - { - "Name": "timeout", - "Type": "System.Int64" - }, - { - "Name": "repeat", - "Type": "System.Int64" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Stop", - "Parameters": [], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "logger", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.ILibuvTrace" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.UvWriteReq", - "Visibility": "Public", - "Kind": "Class", - "BaseType": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.UvRequest", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "Init", - "Parameters": [ - { - "Name": "thread", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.LibuvThread" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "Override": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "DangerousInit", - "Parameters": [ - { - "Name": "loop", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.UvLoopHandle" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "WriteAsync", - "Parameters": [ - { - "Name": "handle", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.UvStreamHandle" - }, - { - "Name": "buffer", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.ReadableBuffer" - } - ], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.LibuvAwaitable", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "WriteAsync", - "Parameters": [ - { - "Name": "handle", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.UvStreamHandle" - }, - { - "Name": "bufs", - "Type": "System.ArraySegment>" - } - ], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.LibuvAwaitable", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "Write2", - "Parameters": [ - { - "Name": "handle", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.UvStreamHandle" - }, - { - "Name": "bufs", - "Type": "System.ArraySegment>" - }, - { - "Name": "sendHandle", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.UvStreamHandle" - }, - { - "Name": "callback", - "Type": "System.Action" - }, - { - "Name": "state", - "Type": "System.Object" - } - ], - "ReturnType": "System.Void", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "logger", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.ILibuvTrace" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.LibuvFunctions+uv_fileno_func", - "Visibility": "Protected", - "Kind": "Class", - "Sealed": true, - "BaseType": "System.MulticastDelegate", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "Invoke", - "Parameters": [ - { - "Name": "handle", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.UvHandle" - }, - { - "Name": "socket", - "Type": "System.IntPtr", - "Direction": "Ref" - } - ], - "ReturnType": "System.Int32", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "BeginInvoke", - "Parameters": [ - { - "Name": "handle", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.UvHandle" - }, - { - "Name": "socket", - "Type": "System.IntPtr", - "Direction": "Ref" - }, - { - "Name": "callback", - "Type": "System.AsyncCallback" - }, - { - "Name": "object", - "Type": "System.Object" - } - ], - "ReturnType": "System.IAsyncResult", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "EndInvoke", - "Parameters": [ - { - "Name": "socket", - "Type": "System.IntPtr", - "Direction": "Ref" - }, - { - "Name": "result", - "Type": "System.IAsyncResult" - } - ], - "ReturnType": "System.Int32", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "object", - "Type": "System.Object" - }, - { - "Name": "method", - "Type": "System.IntPtr" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.LibuvFunctions+uv_close_cb", - "Visibility": "Public", - "Kind": "Class", - "Sealed": true, - "BaseType": "System.MulticastDelegate", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "Invoke", - "Parameters": [ - { - "Name": "handle", - "Type": "System.IntPtr" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "BeginInvoke", - "Parameters": [ - { - "Name": "handle", - "Type": "System.IntPtr" - }, - { - "Name": "callback", - "Type": "System.AsyncCallback" - }, - { - "Name": "object", - "Type": "System.Object" - } - ], - "ReturnType": "System.IAsyncResult", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "EndInvoke", - "Parameters": [ - { - "Name": "result", - "Type": "System.IAsyncResult" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "object", - "Type": "System.Object" - }, - { - "Name": "method", - "Type": "System.IntPtr" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.LibuvFunctions+uv_async_cb", - "Visibility": "Public", - "Kind": "Class", - "Sealed": true, - "BaseType": "System.MulticastDelegate", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "Invoke", - "Parameters": [ - { - "Name": "handle", - "Type": "System.IntPtr" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "BeginInvoke", - "Parameters": [ - { - "Name": "handle", - "Type": "System.IntPtr" - }, - { - "Name": "callback", - "Type": "System.AsyncCallback" - }, - { - "Name": "object", - "Type": "System.Object" - } - ], - "ReturnType": "System.IAsyncResult", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "EndInvoke", - "Parameters": [ - { - "Name": "result", - "Type": "System.IAsyncResult" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "object", - "Type": "System.Object" - }, - { - "Name": "method", - "Type": "System.IntPtr" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.LibuvFunctions+uv_tcp_bind_func", - "Visibility": "Protected", - "Kind": "Class", - "Sealed": true, - "BaseType": "System.MulticastDelegate", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "Invoke", - "Parameters": [ - { - "Name": "handle", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.UvTcpHandle" - }, - { - "Name": "addr", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.SockAddr", - "Direction": "Ref" - }, - { - "Name": "flags", - "Type": "System.Int32" - } - ], - "ReturnType": "System.Int32", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "BeginInvoke", - "Parameters": [ - { - "Name": "handle", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.UvTcpHandle" - }, - { - "Name": "addr", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.SockAddr", - "Direction": "Ref" - }, - { - "Name": "flags", - "Type": "System.Int32" - }, - { - "Name": "callback", - "Type": "System.AsyncCallback" - }, - { - "Name": "object", - "Type": "System.Object" - } - ], - "ReturnType": "System.IAsyncResult", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "EndInvoke", - "Parameters": [ - { - "Name": "addr", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.SockAddr", - "Direction": "Ref" - }, - { - "Name": "result", - "Type": "System.IAsyncResult" - } - ], - "ReturnType": "System.Int32", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "object", - "Type": "System.Object" - }, - { - "Name": "method", - "Type": "System.IntPtr" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.LibuvFunctions+uv_connection_cb", - "Visibility": "Public", - "Kind": "Class", - "Sealed": true, - "BaseType": "System.MulticastDelegate", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "Invoke", - "Parameters": [ - { - "Name": "server", - "Type": "System.IntPtr" - }, - { - "Name": "status", - "Type": "System.Int32" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "BeginInvoke", - "Parameters": [ - { - "Name": "server", - "Type": "System.IntPtr" - }, - { - "Name": "status", - "Type": "System.Int32" - }, - { - "Name": "callback", - "Type": "System.AsyncCallback" - }, - { - "Name": "object", - "Type": "System.Object" - } - ], - "ReturnType": "System.IAsyncResult", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "EndInvoke", - "Parameters": [ - { - "Name": "result", - "Type": "System.IAsyncResult" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "object", - "Type": "System.Object" - }, - { - "Name": "method", - "Type": "System.IntPtr" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.LibuvFunctions+uv_connect_cb", - "Visibility": "Public", - "Kind": "Class", - "Sealed": true, - "BaseType": "System.MulticastDelegate", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "Invoke", - "Parameters": [ - { - "Name": "req", - "Type": "System.IntPtr" - }, - { - "Name": "status", - "Type": "System.Int32" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "BeginInvoke", - "Parameters": [ - { - "Name": "req", - "Type": "System.IntPtr" - }, - { - "Name": "status", - "Type": "System.Int32" - }, - { - "Name": "callback", - "Type": "System.AsyncCallback" - }, - { - "Name": "object", - "Type": "System.Object" - } - ], - "ReturnType": "System.IAsyncResult", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "EndInvoke", - "Parameters": [ - { - "Name": "result", - "Type": "System.IAsyncResult" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "object", - "Type": "System.Object" - }, - { - "Name": "method", - "Type": "System.IntPtr" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.LibuvFunctions+uv_alloc_cb", - "Visibility": "Public", - "Kind": "Class", - "Sealed": true, - "BaseType": "System.MulticastDelegate", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "Invoke", - "Parameters": [ - { - "Name": "server", - "Type": "System.IntPtr" - }, - { - "Name": "suggested_size", - "Type": "System.Int32" - }, - { - "Name": "buf", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.LibuvFunctions+uv_buf_t", - "Direction": "Out" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "BeginInvoke", - "Parameters": [ - { - "Name": "server", - "Type": "System.IntPtr" - }, - { - "Name": "suggested_size", - "Type": "System.Int32" - }, - { - "Name": "buf", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.LibuvFunctions+uv_buf_t", - "Direction": "Out" - }, - { - "Name": "callback", - "Type": "System.AsyncCallback" - }, - { - "Name": "object", - "Type": "System.Object" - } - ], - "ReturnType": "System.IAsyncResult", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "EndInvoke", - "Parameters": [ - { - "Name": "buf", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.LibuvFunctions+uv_buf_t", - "Direction": "Out" - }, - { - "Name": "result", - "Type": "System.IAsyncResult" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "object", - "Type": "System.Object" - }, - { - "Name": "method", - "Type": "System.IntPtr" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.LibuvFunctions+uv_read_cb", - "Visibility": "Public", - "Kind": "Class", - "Sealed": true, - "BaseType": "System.MulticastDelegate", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "Invoke", - "Parameters": [ - { - "Name": "server", - "Type": "System.IntPtr" - }, - { - "Name": "nread", - "Type": "System.Int32" - }, - { - "Name": "buf", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.LibuvFunctions+uv_buf_t", - "Direction": "Ref" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "BeginInvoke", - "Parameters": [ - { - "Name": "server", - "Type": "System.IntPtr" - }, - { - "Name": "nread", - "Type": "System.Int32" - }, - { - "Name": "buf", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.LibuvFunctions+uv_buf_t", - "Direction": "Ref" - }, - { - "Name": "callback", - "Type": "System.AsyncCallback" - }, - { - "Name": "object", - "Type": "System.Object" - } - ], - "ReturnType": "System.IAsyncResult", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "EndInvoke", - "Parameters": [ - { - "Name": "buf", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.LibuvFunctions+uv_buf_t", - "Direction": "Ref" - }, - { - "Name": "result", - "Type": "System.IAsyncResult" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "object", - "Type": "System.Object" - }, - { - "Name": "method", - "Type": "System.IntPtr" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.LibuvFunctions+uv_write_cb", - "Visibility": "Public", - "Kind": "Class", - "Sealed": true, - "BaseType": "System.MulticastDelegate", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "Invoke", - "Parameters": [ - { - "Name": "req", - "Type": "System.IntPtr" - }, - { - "Name": "status", - "Type": "System.Int32" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "BeginInvoke", - "Parameters": [ - { - "Name": "req", - "Type": "System.IntPtr" - }, - { - "Name": "status", - "Type": "System.Int32" - }, - { - "Name": "callback", - "Type": "System.AsyncCallback" - }, - { - "Name": "object", - "Type": "System.Object" - } - ], - "ReturnType": "System.IAsyncResult", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "EndInvoke", - "Parameters": [ - { - "Name": "result", - "Type": "System.IAsyncResult" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "object", - "Type": "System.Object" - }, - { - "Name": "method", - "Type": "System.IntPtr" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.LibuvFunctions+uv_write_func", - "Visibility": "Protected", - "Kind": "Class", - "Sealed": true, - "BaseType": "System.MulticastDelegate", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "Invoke", - "Parameters": [ - { - "Name": "req", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.UvRequest" - }, - { - "Name": "handle", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.UvStreamHandle" - }, - { - "Name": "bufs", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.LibuvFunctions+uv_buf_t*" - }, - { - "Name": "nbufs", - "Type": "System.Int32" - }, - { - "Name": "cb", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.LibuvFunctions+uv_write_cb" - } - ], - "ReturnType": "System.Int32", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "BeginInvoke", - "Parameters": [ - { - "Name": "req", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.UvRequest" - }, - { - "Name": "handle", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.UvStreamHandle" - }, - { - "Name": "bufs", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.LibuvFunctions+uv_buf_t*" - }, - { - "Name": "nbufs", - "Type": "System.Int32" - }, - { - "Name": "cb", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.LibuvFunctions+uv_write_cb" - }, - { - "Name": "callback", - "Type": "System.AsyncCallback" - }, - { - "Name": "object", - "Type": "System.Object" - } - ], - "ReturnType": "System.IAsyncResult", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "EndInvoke", - "Parameters": [ - { - "Name": "result", - "Type": "System.IAsyncResult" - } - ], - "ReturnType": "System.Int32", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "object", - "Type": "System.Object" - }, - { - "Name": "method", - "Type": "System.IntPtr" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.LibuvFunctions+uv_write2_func", - "Visibility": "Protected", - "Kind": "Class", - "Sealed": true, - "BaseType": "System.MulticastDelegate", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "Invoke", - "Parameters": [ - { - "Name": "req", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.UvRequest" - }, - { - "Name": "handle", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.UvStreamHandle" - }, - { - "Name": "bufs", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.LibuvFunctions+uv_buf_t*" - }, - { - "Name": "nbufs", - "Type": "System.Int32" - }, - { - "Name": "sendHandle", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.UvStreamHandle" - }, - { - "Name": "cb", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.LibuvFunctions+uv_write_cb" - } - ], - "ReturnType": "System.Int32", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "BeginInvoke", - "Parameters": [ - { - "Name": "req", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.UvRequest" - }, - { - "Name": "handle", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.UvStreamHandle" - }, - { - "Name": "bufs", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.LibuvFunctions+uv_buf_t*" - }, - { - "Name": "nbufs", - "Type": "System.Int32" - }, - { - "Name": "sendHandle", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.UvStreamHandle" - }, - { - "Name": "cb", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.LibuvFunctions+uv_write_cb" - }, - { - "Name": "callback", - "Type": "System.AsyncCallback" - }, - { - "Name": "object", - "Type": "System.Object" - } - ], - "ReturnType": "System.IAsyncResult", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "EndInvoke", - "Parameters": [ - { - "Name": "result", - "Type": "System.IAsyncResult" - } - ], - "ReturnType": "System.Int32", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "object", - "Type": "System.Object" - }, - { - "Name": "method", - "Type": "System.IntPtr" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.LibuvFunctions+uv_ip4_addr_func", - "Visibility": "Protected", - "Kind": "Class", - "Sealed": true, - "BaseType": "System.MulticastDelegate", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "Invoke", - "Parameters": [ - { - "Name": "ip", - "Type": "System.String" - }, - { - "Name": "port", - "Type": "System.Int32" - }, - { - "Name": "addr", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.SockAddr", - "Direction": "Out" - } - ], - "ReturnType": "System.Int32", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "BeginInvoke", - "Parameters": [ - { - "Name": "ip", - "Type": "System.String" - }, - { - "Name": "port", - "Type": "System.Int32" - }, - { - "Name": "addr", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.SockAddr", - "Direction": "Out" - }, - { - "Name": "callback", - "Type": "System.AsyncCallback" - }, - { - "Name": "object", - "Type": "System.Object" - } - ], - "ReturnType": "System.IAsyncResult", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "EndInvoke", - "Parameters": [ - { - "Name": "addr", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.SockAddr", - "Direction": "Out" - }, - { - "Name": "result", - "Type": "System.IAsyncResult" - } - ], - "ReturnType": "System.Int32", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "object", - "Type": "System.Object" - }, - { - "Name": "method", - "Type": "System.IntPtr" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.LibuvFunctions+uv_ip6_addr_func", - "Visibility": "Protected", - "Kind": "Class", - "Sealed": true, - "BaseType": "System.MulticastDelegate", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "Invoke", - "Parameters": [ - { - "Name": "ip", - "Type": "System.String" - }, - { - "Name": "port", - "Type": "System.Int32" - }, - { - "Name": "addr", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.SockAddr", - "Direction": "Out" - } - ], - "ReturnType": "System.Int32", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "BeginInvoke", - "Parameters": [ - { - "Name": "ip", - "Type": "System.String" - }, - { - "Name": "port", - "Type": "System.Int32" - }, - { - "Name": "addr", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.SockAddr", - "Direction": "Out" - }, - { - "Name": "callback", - "Type": "System.AsyncCallback" - }, - { - "Name": "object", - "Type": "System.Object" - } - ], - "ReturnType": "System.IAsyncResult", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "EndInvoke", - "Parameters": [ - { - "Name": "addr", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.SockAddr", - "Direction": "Out" - }, - { - "Name": "result", - "Type": "System.IAsyncResult" - } - ], - "ReturnType": "System.Int32", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "object", - "Type": "System.Object" - }, - { - "Name": "method", - "Type": "System.IntPtr" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.LibuvFunctions+uv_walk_cb", - "Visibility": "Public", - "Kind": "Class", - "Sealed": true, - "BaseType": "System.MulticastDelegate", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "Invoke", - "Parameters": [ - { - "Name": "handle", - "Type": "System.IntPtr" - }, - { - "Name": "arg", - "Type": "System.IntPtr" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "BeginInvoke", - "Parameters": [ - { - "Name": "handle", - "Type": "System.IntPtr" - }, - { - "Name": "arg", - "Type": "System.IntPtr" - }, - { - "Name": "callback", - "Type": "System.AsyncCallback" - }, - { - "Name": "object", - "Type": "System.Object" - } - ], - "ReturnType": "System.IAsyncResult", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "EndInvoke", - "Parameters": [ - { - "Name": "result", - "Type": "System.IAsyncResult" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "object", - "Type": "System.Object" - }, - { - "Name": "method", - "Type": "System.IntPtr" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.LibuvFunctions+uv_timer_cb", - "Visibility": "Public", - "Kind": "Class", - "Sealed": true, - "BaseType": "System.MulticastDelegate", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "Invoke", - "Parameters": [ - { - "Name": "handle", - "Type": "System.IntPtr" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "BeginInvoke", - "Parameters": [ - { - "Name": "handle", - "Type": "System.IntPtr" - }, - { - "Name": "callback", - "Type": "System.AsyncCallback" - }, - { - "Name": "object", - "Type": "System.Object" - } - ], - "ReturnType": "System.IAsyncResult", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "EndInvoke", - "Parameters": [ - { - "Name": "result", - "Type": "System.IAsyncResult" - } - ], - "ReturnType": "System.Void", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "object", - "Type": "System.Object" - }, - { - "Name": "method", - "Type": "System.IntPtr" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.LibuvFunctions+uv_tcp_getsockname_func", - "Visibility": "Public", - "Kind": "Class", - "Sealed": true, - "BaseType": "System.MulticastDelegate", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "Invoke", - "Parameters": [ - { - "Name": "handle", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.UvTcpHandle" - }, - { - "Name": "addr", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.SockAddr", - "Direction": "Out" - }, - { - "Name": "namelen", - "Type": "System.Int32", - "Direction": "Ref" - } - ], - "ReturnType": "System.Int32", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "BeginInvoke", - "Parameters": [ - { - "Name": "handle", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.UvTcpHandle" - }, - { - "Name": "addr", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.SockAddr", - "Direction": "Out" - }, - { - "Name": "namelen", - "Type": "System.Int32", - "Direction": "Ref" - }, - { - "Name": "callback", - "Type": "System.AsyncCallback" - }, - { - "Name": "object", - "Type": "System.Object" - } - ], - "ReturnType": "System.IAsyncResult", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "EndInvoke", - "Parameters": [ - { - "Name": "addr", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.SockAddr", - "Direction": "Out" - }, - { - "Name": "namelen", - "Type": "System.Int32", - "Direction": "Ref" - }, - { - "Name": "result", - "Type": "System.IAsyncResult" - } - ], - "ReturnType": "System.Int32", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "object", - "Type": "System.Object" - }, - { - "Name": "method", - "Type": "System.IntPtr" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.LibuvFunctions+uv_tcp_getpeername_func", - "Visibility": "Public", - "Kind": "Class", - "Sealed": true, - "BaseType": "System.MulticastDelegate", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "Invoke", - "Parameters": [ - { - "Name": "handle", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.UvTcpHandle" - }, - { - "Name": "addr", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.SockAddr", - "Direction": "Out" - }, - { - "Name": "namelen", - "Type": "System.Int32", - "Direction": "Ref" - } - ], - "ReturnType": "System.Int32", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "BeginInvoke", - "Parameters": [ - { - "Name": "handle", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.UvTcpHandle" - }, - { - "Name": "addr", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.SockAddr", - "Direction": "Out" - }, - { - "Name": "namelen", - "Type": "System.Int32", - "Direction": "Ref" - }, - { - "Name": "callback", - "Type": "System.AsyncCallback" - }, - { - "Name": "object", - "Type": "System.Object" - } - ], - "ReturnType": "System.IAsyncResult", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "EndInvoke", - "Parameters": [ - { - "Name": "addr", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.SockAddr", - "Direction": "Out" - }, - { - "Name": "namelen", - "Type": "System.Int32", - "Direction": "Ref" - }, - { - "Name": "result", - "Type": "System.IAsyncResult" - } - ], - "ReturnType": "System.Int32", - "Virtual": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "object", - "Type": "System.Object" - }, - { - "Name": "method", - "Type": "System.IntPtr" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.LibuvFunctions+uv_buf_t", - "Visibility": "Public", - "Kind": "Struct", - "Sealed": true, - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "memory", - "Type": "System.IntPtr" - }, - { - "Name": "len", - "Type": "System.Int32" - }, - { - "Name": "IsWindows", - "Type": "System.Boolean" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.LibuvFunctions+HandleType", - "Visibility": "Public", - "Kind": "Enumeration", - "Sealed": true, - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Field", - "Name": "Unknown", - "Parameters": [], - "GenericParameter": [], - "Literal": "0" - }, - { - "Kind": "Field", - "Name": "ASYNC", - "Parameters": [], - "GenericParameter": [], - "Literal": "1" - }, - { - "Kind": "Field", - "Name": "CHECK", - "Parameters": [], - "GenericParameter": [], - "Literal": "2" - }, - { - "Kind": "Field", - "Name": "FS_EVENT", - "Parameters": [], - "GenericParameter": [], - "Literal": "3" - }, - { - "Kind": "Field", - "Name": "FS_POLL", - "Parameters": [], - "GenericParameter": [], - "Literal": "4" - }, - { - "Kind": "Field", - "Name": "HANDLE", - "Parameters": [], - "GenericParameter": [], - "Literal": "5" - }, - { - "Kind": "Field", - "Name": "IDLE", - "Parameters": [], - "GenericParameter": [], - "Literal": "6" - }, - { - "Kind": "Field", - "Name": "NAMED_PIPE", - "Parameters": [], - "GenericParameter": [], - "Literal": "7" - }, - { - "Kind": "Field", - "Name": "POLL", - "Parameters": [], - "GenericParameter": [], - "Literal": "8" - }, - { - "Kind": "Field", - "Name": "PREPARE", - "Parameters": [], - "GenericParameter": [], - "Literal": "9" - }, - { - "Kind": "Field", - "Name": "PROCESS", - "Parameters": [], - "GenericParameter": [], - "Literal": "10" - }, - { - "Kind": "Field", - "Name": "STREAM", - "Parameters": [], - "GenericParameter": [], - "Literal": "11" - }, - { - "Kind": "Field", - "Name": "TCP", - "Parameters": [], - "GenericParameter": [], - "Literal": "12" - }, - { - "Kind": "Field", - "Name": "TIMER", - "Parameters": [], - "GenericParameter": [], - "Literal": "13" - }, - { - "Kind": "Field", - "Name": "TTY", - "Parameters": [], - "GenericParameter": [], - "Literal": "14" - }, - { - "Kind": "Field", - "Name": "UDP", - "Parameters": [], - "GenericParameter": [], - "Literal": "15" - }, - { - "Kind": "Field", - "Name": "SIGNAL", - "Parameters": [], - "GenericParameter": [], - "Literal": "16" - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.LibuvFunctions+RequestType", - "Visibility": "Public", - "Kind": "Enumeration", - "Sealed": true, - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Field", - "Name": "Unknown", - "Parameters": [], - "GenericParameter": [], - "Literal": "0" - }, - { - "Kind": "Field", - "Name": "REQ", - "Parameters": [], - "GenericParameter": [], - "Literal": "1" - }, - { - "Kind": "Field", - "Name": "CONNECT", - "Parameters": [], - "GenericParameter": [], - "Literal": "2" - }, - { - "Kind": "Field", - "Name": "WRITE", - "Parameters": [], - "GenericParameter": [], - "Literal": "3" - }, - { - "Kind": "Field", - "Name": "SHUTDOWN", - "Parameters": [], - "GenericParameter": [], - "Literal": "4" - }, - { - "Kind": "Field", - "Name": "UDP_SEND", - "Parameters": [], - "GenericParameter": [], - "Literal": "5" - }, - { - "Kind": "Field", - "Name": "FS", - "Parameters": [], - "GenericParameter": [], - "Literal": "6" - }, - { - "Kind": "Field", - "Name": "WORK", - "Parameters": [], - "GenericParameter": [], - "Literal": "7" - }, - { - "Kind": "Field", - "Name": "GETADDRINFO", - "Parameters": [], - "GenericParameter": [], - "Literal": "8" - }, - { - "Kind": "Field", - "Name": "GETNAMEINFO", - "Parameters": [], - "GenericParameter": [], - "Literal": "9" - } - ], - "GenericParameters": [] } ] } \ No newline at end of file diff --git a/src/Kestrel.Transport.Sockets/baseline.netcore.json b/src/Kestrel.Transport.Sockets/baseline.netcore.json index a39431c515..33448b164f 100644 --- a/src/Kestrel.Transport.Sockets/baseline.netcore.json +++ b/src/Kestrel.Transport.Sockets/baseline.netcore.json @@ -1,5 +1,5 @@ { - "AssemblyIdentity": "Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets, Version=2.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60", + "AssemblyIdentity": "Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets, Version=2.0.2.0, Culture=neutral, PublicKeyToken=adb9793829ddae60", "Types": [ { "Name": "Microsoft.AspNetCore.Hosting.WebHostBuilderSocketExtensions", @@ -83,14 +83,6 @@ { "Name": "options", "Type": "Microsoft.Extensions.Options.IOptions" - }, - { - "Name": "applicationLifetime", - "Type": "Microsoft.AspNetCore.Hosting.IApplicationLifetime" - }, - { - "Name": "loggerFactory", - "Type": "Microsoft.Extensions.Logging.ILoggerFactory" } ], "Visibility": "Public", diff --git a/src/Kestrel/baseline.netcore.json b/src/Kestrel/baseline.netcore.json index 59b757def6..7f71b30042 100644 --- a/src/Kestrel/baseline.netcore.json +++ b/src/Kestrel/baseline.netcore.json @@ -1,5 +1,5 @@ { - "AssemblyIdentity": "Microsoft.AspNetCore.Server.Kestrel, Version=2.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60", + "AssemblyIdentity": "Microsoft.AspNetCore.Server.Kestrel, Version=2.0.2.0, Culture=neutral, PublicKeyToken=adb9793829ddae60", "Types": [ { "Name": "Microsoft.AspNetCore.Hosting.WebHostBuilderKestrelExtensions", From e7aa60208d026566e39df1b2cec4022ed0d4a4bf Mon Sep 17 00:00:00 2001 From: Pranav K Date: Fri, 16 Mar 2018 11:15:29 -0700 Subject: [PATCH 1579/1662] Branching for 2.1.0-preview2 --- build/dependencies.props | 60 ++++++++++++++++++++-------------------- build/repo.props | 4 +-- build/sources.props | 2 +- 3 files changed, 33 insertions(+), 33 deletions(-) diff --git a/build/dependencies.props b/build/dependencies.props index 6916e0189a..8dfa3b5fcb 100644 --- a/build/dependencies.props +++ b/build/dependencies.props @@ -4,41 +4,41 @@ - 0.10.11 - 2.1.0-preview2-15728 + 0.10.13 + 2.1.0-preview2-15742 1.10.0 - 2.1.0-preview2-30301 - 2.1.0-preview2-30301 - 2.1.0-preview2-30301 - 2.1.0-preview2-30301 - 2.1.0-preview2-30301 - 2.1.0-preview2-30301 - 2.1.0-preview2-30301 - 2.1.0-preview2-30301 - 2.1.0-preview2-30301 - 2.1.0-preview2-30301 - 2.1.0-preview2-30301 - 2.1.0-preview2-30301 - 2.1.0-preview2-30301 - 2.1.0-preview2-30301 - 2.1.0-preview2-30301 - 2.1.0-preview2-30301 - 2.1.0-preview2-30301 - 2.1.0-preview2-30301 - 2.1.0-preview2-30301 + 2.1.0-preview2-30355 + 2.1.0-preview2-30355 + 2.1.0-preview2-30355 + 2.1.0-preview2-30355 + 2.1.0-preview2-30355 + 2.1.0-preview2-30355 + 2.1.0-preview2-30355 + 2.1.0-preview2-30355 + 2.1.0-preview2-30355 + 2.1.0-preview2-30355 + 2.1.0-preview2-30355 + 2.1.0-preview2-30355 + 2.1.0-preview2-30355 + 2.1.0-preview2-30355 + 2.1.0-preview2-30355 + 2.1.0-preview2-30355 + 2.1.0-preview2-30355 + 2.1.0-preview2-30355 + 2.1.0-preview2-30355 2.0.0 - 2.1.0-preview2-26308-01 - 2.1.0-preview2-30301 + 2.1.0-preview2-26314-02 + 2.1.0-preview2-30355 15.6.0 4.7.49 10.0.1 - 4.5.0-preview2-26313-02 - 4.5.0-preview2-26313-02 - 4.5.0-preview2-26313-02 - 4.5.0-preview2-26313-02 - 4.5.0-preview2-26313-02 - 4.5.0-preview2-26313-02 - 4.5.0-preview2-26313-02 + 4.5.0-preview2-26313-01 + 4.5.0-preview2-26313-01 + 4.5.0-preview2-26313-01 + 4.5.0-preview2-26313-01 + 4.5.0-preview2-26313-01 + 4.5.0-preview2-26313-01 + 4.5.0-preview2-26313-01 0.8.0 2.3.1 2.4.0-beta.1.build3945 diff --git a/build/repo.props b/build/repo.props index 2c858d96cf..551c916879 100644 --- a/build/repo.props +++ b/build/repo.props @@ -1,11 +1,11 @@ - + true Internal.AspNetCore.Universe.Lineup - https://dotnet.myget.org/F/aspnetcore-dev/api/v3/index.json + https://dotnet.myget.org/F/aspnetcore-release/api/v3/index.json diff --git a/build/sources.props b/build/sources.props index fe324c40e3..da95ef6a8f 100644 --- a/build/sources.props +++ b/build/sources.props @@ -6,7 +6,7 @@ $(RestoreSources); https://dotnet.myget.org/F/dotnet-core/api/v3/index.json; - https://dotnet.myget.org/F/aspnetcore-dev/api/v3/index.json; + https://dotnet.myget.org/F/aspnetcore-release/api/v3/index.json; https://dotnet.myget.org/F/aspnetcore-tools/api/v3/index.json; https://dotnet.myget.org/F/roslyn/api/v3/index.json; From 35b92f298c013aa453eb79023924375b9b73a015 Mon Sep 17 00:00:00 2001 From: Pranav K Date: Fri, 16 Mar 2018 11:27:02 -0700 Subject: [PATCH 1580/1662] Update version prefix to preview3 --- version.props | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version.props b/version.props index a11ea1ed52..24f2b00a0a 100644 --- a/version.props +++ b/version.props @@ -1,7 +1,7 @@ 2.1.0 - preview2 + preview3 $(VersionPrefix) $(VersionPrefix)-$(VersionSuffix)-final t000 From 34b911d188da21a889efce14bb9b157ef662878d Mon Sep 17 00:00:00 2001 From: Pranav K Date: Fri, 16 Mar 2018 12:31:04 -0700 Subject: [PATCH 1581/1662] Update KoreBuild channel --- korebuild.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/korebuild.json b/korebuild.json index bd5d51a51b..678d8bb948 100644 --- a/korebuild.json +++ b/korebuild.json @@ -1,4 +1,4 @@ { - "$schema": "https://raw.githubusercontent.com/aspnet/BuildTools/dev/tools/korebuild.schema.json", - "channel": "dev" + "$schema": "https://raw.githubusercontent.com/aspnet/BuildTools/release/2.1/tools/korebuild.schema.json", + "channel": "release/2.1" } From 5fa658c8008eb932020675623d260f3d7394b568 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Mon, 19 Mar 2018 17:29:49 -0700 Subject: [PATCH 1582/1662] Never run continuation inline in SocketAwaitable.OnCompleted (#2407) --- src/Kestrel.Transport.Sockets/Internal/SocketAwaitable.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Kestrel.Transport.Sockets/Internal/SocketAwaitable.cs b/src/Kestrel.Transport.Sockets/Internal/SocketAwaitable.cs index 1da07c9375..6c4de75c45 100644 --- a/src/Kestrel.Transport.Sockets/Internal/SocketAwaitable.cs +++ b/src/Kestrel.Transport.Sockets/Internal/SocketAwaitable.cs @@ -7,6 +7,7 @@ using System.IO.Pipelines; using System.Net.Sockets; using System.Runtime.CompilerServices; using System.Threading; +using System.Threading.Tasks; namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal { @@ -47,7 +48,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal if (ReferenceEquals(_callback, _callbackCompleted) || ReferenceEquals(Interlocked.CompareExchange(ref _callback, continuation, null), _callbackCompleted)) { - continuation(); + Task.Run(continuation); } } From b90766d09755c663e2af868380006213af1171f4 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Tue, 20 Mar 2018 12:19:20 -0700 Subject: [PATCH 1583/1662] React to aspnet/BuildTools#611 (#2409) --- test/SystemdActivation/docker.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/SystemdActivation/docker.sh b/test/SystemdActivation/docker.sh index 28560cf69f..f2ba5fe506 100644 --- a/test/SystemdActivation/docker.sh +++ b/test/SystemdActivation/docker.sh @@ -3,10 +3,10 @@ set -e scriptDir=$(dirname "${BASH_SOURCE[0]}") -PATH="$HOME/.dotnet/:$PATH" +PATH="$PWD/.dotnet/:$PATH" dotnet publish -f netcoreapp2.0 ./samples/SystemdTestApp/ cp -R ./samples/SystemdTestApp/bin/Debug/netcoreapp2.0/publish/ $scriptDir -cp -R ~/.dotnet/ $scriptDir +cp -R ./.dotnet/ $scriptDir image=$(docker build -qf $scriptDir/Dockerfile $scriptDir) container=$(docker run -Pd $image) From 54e538dcb5ff4f818120e52200761415c3b3e411 Mon Sep 17 00:00:00 2001 From: Nate McMaster Date: Wed, 21 Mar 2018 14:55:10 -0700 Subject: [PATCH 1584/1662] Remove dotnet tool install from instructions on using dotnet-dev-certs --- src/Kestrel.Core/CoreStrings.resx | 2 +- src/Kestrel.Core/Properties/CoreStrings.Designer.cs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Kestrel.Core/CoreStrings.resx b/src/Kestrel.Core/CoreStrings.resx index 286f64efc9..5eb49c1320 100644 --- a/src/Kestrel.Core/CoreStrings.resx +++ b/src/Kestrel.Core/CoreStrings.resx @@ -491,7 +491,7 @@ Unable to configure HTTPS endpoint. No server certificate was specified, and the default developer certificate could not be found. -To install the developer certificate first install the dev-certs tool by running 'dotnet install tool dotnet-dev-certs -g --version 2.1.0-preview1-final' and then run 'dotnet-dev-certs https'. To trust the certificate (Windows and macOS only) run 'dotnet-dev-certs https --trust'. +To generate a developer certificate run 'dotnet dev-certs https'. To trust the certificate (Windows and macOS only) run 'dotnet dev-certs https --trust'. For more information on configuring HTTPS see https://go.microsoft.com/fwlink/?linkid=848054. diff --git a/src/Kestrel.Core/Properties/CoreStrings.Designer.cs b/src/Kestrel.Core/Properties/CoreStrings.Designer.cs index a8a1937505..f964f3db90 100644 --- a/src/Kestrel.Core/Properties/CoreStrings.Designer.cs +++ b/src/Kestrel.Core/Properties/CoreStrings.Designer.cs @@ -1748,7 +1748,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core /// /// Unable to configure HTTPS endpoint. No server certificate was specified, and the default developer certificate could not be found. - /// To install the developer certificate first install the dev-certs tool by running 'dotnet install tool dotnet-dev-certs -g --version 2.1.0-preview1-final' and then run 'dotnet-dev-certs https'. To trust the certificate (Windows and macOS only) run 'dotnet-dev-certs https --trust'. + /// To generate a developer certificate run 'dotnet dev-certs https'. To trust the certificate (Windows and macOS only) run 'dotnet dev-certs https --trust'. /// For more information on configuring HTTPS see https://go.microsoft.com/fwlink/?linkid=848054. /// internal static string NoCertSpecifiedNoDevelopmentCertificateFound @@ -1758,7 +1758,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core /// /// Unable to configure HTTPS endpoint. No server certificate was specified, and the default developer certificate could not be found. - /// To install the developer certificate first install the dev-certs tool by running 'dotnet install tool dotnet-dev-certs -g --version 2.1.0-preview1-final' and then run 'dotnet-dev-certs https'. To trust the certificate (Windows and macOS only) run 'dotnet-dev-certs https --trust'. + /// To generate a developer certificate run 'dotnet dev-certs https'. To trust the certificate (Windows and macOS only) run 'dotnet dev-certs https --trust'. /// For more information on configuring HTTPS see https://go.microsoft.com/fwlink/?linkid=848054. /// internal static string FormatNoCertSpecifiedNoDevelopmentCertificateFound() From abdcb47b8f96d7bf6554575e2d3493a7e955fc68 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Thu, 22 Mar 2018 21:38:14 -0700 Subject: [PATCH 1585/1662] Renames from API review (#2413) * Renames from API review - Rename Microsoft.AspNetCore.Protocols.Abstractions to Microsoft.AspNetCore.Connections.Abstractions. - Renamed IConnectionHandler to IConnectionDispatcher (and related properties and types) - Added ConnectionHandler and UseConnectionHandler extension method to Connections.Abstractions. - Use ActivatorUtilties to create the ConnectionHandler --- KestrelHttpServer.sln | 2 +- .../InMemoryTransportBenchmark.cs | 10 ++--- build/dependencies.props | 1 + .../ConnectionBuilder.cs | 2 +- .../ConnectionBuilderExtensions.cs | 11 +++++- .../ConnectionContext.cs | 2 +- .../ConnectionDelegate.cs | 2 +- .../ConnectionHandler.cs | 20 ++++++++++ .../Connections.Abstractions.csproj} | 9 ++--- .../DefaultConnectionContext.cs | 4 +- .../DuplexPipe.cs | 0 .../Exceptions/AddressInUseException.cs | 2 +- .../Exceptions/ConnectionAbortedException.cs | 2 +- .../Exceptions/ConnectionResetException.cs | 2 +- .../Features/IApplicationTransportFeature.cs | 2 +- .../Features/IConnectionHeartbeatFeature.cs | 2 +- .../Features/IConnectionIdFeature.cs | 2 +- .../IConnectionInherentKeepAliveFeature.cs | 2 +- .../Features/IConnectionItemsFeature.cs | 2 +- .../Features/IConnectionTransportFeature.cs | 2 +- .../Features/IConnectionUserFeature.cs | 2 +- .../Features/IMemoryPoolFeature.cs | 2 +- .../Features/ITransferFormatFeature.cs | 2 +- .../Features/ITransportSchedulerFeature.cs | 2 +- .../IConnectionBuilder.cs | 2 +- .../TransferFormat.cs | 2 +- src/Kestrel.Core/Internal/AddressBinder.cs | 2 +- .../Internal/ConnectionLimitMiddleware.cs | 2 +- ...ectionHandler.cs => ConnectionListener.cs} | 10 ++--- .../Internal/Http/Http1Connection.cs | 2 +- .../Internal/Http/Http1MessageBody.cs | 2 +- .../Internal/Http/HttpProtocol.cs | 2 +- .../Internal/Http/HttpRequestStream.cs | 2 +- src/Kestrel.Core/Internal/Http/UrlDecoder.cs | 2 +- .../Internal/Http2/Http2Connection.cs | 2 +- .../HttpConnectionBuilderExtensions.cs | 2 +- .../Internal/HttpConnectionMiddleware.cs | 4 +- ...HttpConnectionManagerShutdownExtensions.cs | 2 +- src/Kestrel.Core/Kestrel.Core.csproj | 1 + src/Kestrel.Core/KestrelServer.cs | 4 +- src/Kestrel.Core/ListenOptions.cs | 2 +- ...ionHandler.cs => IConnectionDispatcher.cs} | 2 +- .../Internal/ITransportFactory.cs | 2 +- .../Internal/TransportConnection.Features.cs | 2 +- .../Kestrel.Transport.Abstractions.csproj | 2 +- .../Internal/LibuvConnection.cs | 6 +-- .../Internal/LibuvTransportContext.cs | 2 +- src/Kestrel.Transport.Libuv/LibuvTransport.cs | 2 +- .../LibuvTransportFactory.cs | 4 +- .../Internal/SocketConnection.cs | 6 +-- .../SocketTransport.cs | 12 +++--- .../SocketTransportFactory.cs | 8 ++-- test/Kestrel.Core.Tests/AddressBinderTests.cs | 2 +- ...rTests.cs => ConnectionDispatcherTests.cs} | 8 ++-- .../Http2ConnectionTests.cs | 2 +- test/Kestrel.Core.Tests/KestrelServerTests.cs | 12 +++--- test/Kestrel.Core.Tests/PipeOptionsTests.cs | 4 +- test/Kestrel.FunctionalTests/RequestTests.cs | 2 +- .../LibuvConnectionTests.cs | 38 +++++++++---------- .../LibuvThreadTests.cs | 4 +- .../LibuvTransportTests.cs | 4 +- .../ListenerPrimaryTests.cs | 14 +++---- ...Handler.cs => MockConnectionDispatcher.cs} | 6 +-- .../TestHelpers/TestLibuvTransportContext.cs | 2 +- 64 files changed, 154 insertions(+), 126 deletions(-) rename src/{Protocols.Abstractions => Connections.Abstractions}/ConnectionBuilder.cs (96%) rename src/{Protocols.Abstractions => Connections.Abstractions}/ConnectionBuilderExtensions.cs (64%) rename src/{Protocols.Abstractions => Connections.Abstractions}/ConnectionContext.cs (90%) rename src/{Protocols.Abstractions => Connections.Abstractions}/ConnectionDelegate.cs (72%) create mode 100644 src/Connections.Abstractions/ConnectionHandler.cs rename src/{Protocols.Abstractions/Protocols.Abstractions.csproj => Connections.Abstractions/Connections.Abstractions.csproj} (53%) rename src/{Protocols.Abstractions => Connections.Abstractions}/DefaultConnectionContext.cs (94%) rename src/{Protocols.Abstractions => Connections.Abstractions}/DuplexPipe.cs (100%) rename src/{Protocols.Abstractions => Connections.Abstractions}/Exceptions/AddressInUseException.cs (91%) rename src/{Protocols.Abstractions => Connections.Abstractions}/Exceptions/ConnectionAbortedException.cs (91%) rename src/{Protocols.Abstractions => Connections.Abstractions}/Exceptions/ConnectionResetException.cs (91%) rename src/{Protocols.Abstractions => Connections.Abstractions}/Features/IApplicationTransportFeature.cs (87%) rename src/{Protocols.Abstractions => Connections.Abstractions}/Features/IConnectionHeartbeatFeature.cs (85%) rename src/{Protocols.Abstractions => Connections.Abstractions}/Features/IConnectionIdFeature.cs (83%) rename src/{Protocols.Abstractions => Connections.Abstractions}/Features/IConnectionInherentKeepAliveFeature.cs (95%) rename src/{Protocols.Abstractions => Connections.Abstractions}/Features/IConnectionItemsFeature.cs (86%) rename src/{Protocols.Abstractions => Connections.Abstractions}/Features/IConnectionTransportFeature.cs (87%) rename src/{Protocols.Abstractions => Connections.Abstractions}/Features/IConnectionUserFeature.cs (71%) rename src/{Protocols.Abstractions => Connections.Abstractions}/Features/IMemoryPoolFeature.cs (86%) rename src/{Protocols.Abstractions => Connections.Abstractions}/Features/ITransferFormatFeature.cs (85%) rename src/{Protocols.Abstractions => Connections.Abstractions}/Features/ITransportSchedulerFeature.cs (88%) rename src/{Protocols.Abstractions => Connections.Abstractions}/IConnectionBuilder.cs (85%) rename src/{Protocols.Abstractions => Connections.Abstractions}/TransferFormat.cs (86%) rename src/Kestrel.Core/Internal/{ConnectionHandler.cs => ConnectionListener.cs} (91%) rename src/Kestrel.Transport.Abstractions/Internal/{IConnectionHandler.cs => IConnectionDispatcher.cs} (89%) rename test/Kestrel.Core.Tests/{ConnectionHandlerTests.cs => ConnectionDispatcherTests.cs} (89%) rename test/Kestrel.Transport.Libuv.Tests/TestHelpers/{MockConnectionHandler.cs => MockConnectionDispatcher.cs} (89%) diff --git a/KestrelHttpServer.sln b/KestrelHttpServer.sln index 0440b242cf..09077ead0e 100644 --- a/KestrelHttpServer.sln +++ b/KestrelHttpServer.sln @@ -100,7 +100,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Kestrel.Tests", "test\Kestr EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "benchmarks", "benchmarks", "{A95C3BE1-B850-4265-97A0-777ADCCD437F}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Protocols.Abstractions", "src\Protocols.Abstractions\Protocols.Abstractions.csproj", "{6956CF5C-3163-4398-8628-4ECA569245B5}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Connections.Abstractions", "src\Connections.Abstractions\Connections.Abstractions.csproj", "{6956CF5C-3163-4398-8628-4ECA569245B5}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "build", "build", "{C2910A13-B2C2-46D8-81D8-7E166F4F5981}" ProjectSection(SolutionItems) = preProject diff --git a/benchmarks/Kestrel.Performance/InMemoryTransportBenchmark.cs b/benchmarks/Kestrel.Performance/InMemoryTransportBenchmark.cs index 0cf3e137a3..1816531088 100644 --- a/benchmarks/Kestrel.Performance/InMemoryTransportBenchmark.cs +++ b/benchmarks/Kestrel.Performance/InMemoryTransportBenchmark.cs @@ -108,7 +108,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance _connectionsPerEndPoint = connectionsPerEndPoint; } - public ITransport Create(IEndPointInformation endPointInformation, IConnectionHandler handler) + public ITransport Create(IEndPointInformation endPointInformation, IConnectionDispatcher handler) { var connections = new InMemoryConnection[_connectionsPerEndPoint]; for (var i = 0; i < _connectionsPerEndPoint; i++) @@ -124,12 +124,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance public class InMemoryTransport : ITransport { - private readonly IConnectionHandler _handler; + private readonly IConnectionDispatcher _dispatcher; private readonly IReadOnlyList _connections; - public InMemoryTransport(IConnectionHandler handler, IReadOnlyList connections) + public InMemoryTransport(IConnectionDispatcher dispatcher, IReadOnlyList connections) { - _handler = handler; + _dispatcher = dispatcher; _connections = connections; } @@ -137,7 +137,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance { foreach (var connection in _connections) { - _handler.OnConnection(connection); + _dispatcher.OnConnection(connection); } return Task.CompletedTask; diff --git a/build/dependencies.props b/build/dependencies.props index 8dfa3b5fcb..ad44b59226 100644 --- a/build/dependencies.props +++ b/build/dependencies.props @@ -16,6 +16,7 @@ 2.1.0-preview2-30355 2.1.0-preview2-30355 2.1.0-preview2-30355 + 2.1.0-preview2-30355 2.1.0-preview2-30355 2.1.0-preview2-30355 2.1.0-preview2-30355 diff --git a/src/Protocols.Abstractions/ConnectionBuilder.cs b/src/Connections.Abstractions/ConnectionBuilder.cs similarity index 96% rename from src/Protocols.Abstractions/ConnectionBuilder.cs rename to src/Connections.Abstractions/ConnectionBuilder.cs index 68efce703f..b75e92b60f 100644 --- a/src/Protocols.Abstractions/ConnectionBuilder.cs +++ b/src/Connections.Abstractions/ConnectionBuilder.cs @@ -7,7 +7,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace Microsoft.AspNetCore.Protocols +namespace Microsoft.AspNetCore.Connections { public class ConnectionBuilder : IConnectionBuilder { diff --git a/src/Protocols.Abstractions/ConnectionBuilderExtensions.cs b/src/Connections.Abstractions/ConnectionBuilderExtensions.cs similarity index 64% rename from src/Protocols.Abstractions/ConnectionBuilderExtensions.cs rename to src/Connections.Abstractions/ConnectionBuilderExtensions.cs index 9db3e4c468..100917b009 100644 --- a/src/Protocols.Abstractions/ConnectionBuilderExtensions.cs +++ b/src/Connections.Abstractions/ConnectionBuilderExtensions.cs @@ -3,11 +3,20 @@ using System; using System.Threading.Tasks; +using Microsoft.Extensions.Internal; -namespace Microsoft.AspNetCore.Protocols +namespace Microsoft.AspNetCore.Connections { public static class ConnectionBuilderExtensions { + public static IConnectionBuilder UseConnectionHandler(this IConnectionBuilder connectionBuilder) where TConnectionHandler : ConnectionHandler + { + var handler = ActivatorUtilities.GetServiceOrCreateInstance(connectionBuilder.ApplicationServices); + + // This is a terminal middleware, so there's no need to use the 'next' parameter + return connectionBuilder.Run(connection => handler.OnConnectedAsync(connection)); + } + public static IConnectionBuilder Use(this IConnectionBuilder connectionBuilder, Func, Task> middleware) { return connectionBuilder.Use(next => diff --git a/src/Protocols.Abstractions/ConnectionContext.cs b/src/Connections.Abstractions/ConnectionContext.cs similarity index 90% rename from src/Protocols.Abstractions/ConnectionContext.cs rename to src/Connections.Abstractions/ConnectionContext.cs index f8175d3897..aba4abdfc0 100644 --- a/src/Protocols.Abstractions/ConnectionContext.cs +++ b/src/Connections.Abstractions/ConnectionContext.cs @@ -2,7 +2,7 @@ using System.IO.Pipelines; using Microsoft.AspNetCore.Http.Features; -namespace Microsoft.AspNetCore.Protocols +namespace Microsoft.AspNetCore.Connections { public abstract class ConnectionContext { diff --git a/src/Protocols.Abstractions/ConnectionDelegate.cs b/src/Connections.Abstractions/ConnectionDelegate.cs similarity index 72% rename from src/Protocols.Abstractions/ConnectionDelegate.cs rename to src/Connections.Abstractions/ConnectionDelegate.cs index ff0e4d75af..f0d64d1587 100644 --- a/src/Protocols.Abstractions/ConnectionDelegate.cs +++ b/src/Connections.Abstractions/ConnectionDelegate.cs @@ -1,6 +1,6 @@ using System.Threading.Tasks; -namespace Microsoft.AspNetCore.Protocols +namespace Microsoft.AspNetCore.Connections { public delegate Task ConnectionDelegate(ConnectionContext connection); } diff --git a/src/Connections.Abstractions/ConnectionHandler.cs b/src/Connections.Abstractions/ConnectionHandler.cs new file mode 100644 index 0000000000..e9e208d61a --- /dev/null +++ b/src/Connections.Abstractions/ConnectionHandler.cs @@ -0,0 +1,20 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System.Threading.Tasks; + +namespace Microsoft.AspNetCore.Connections +{ + /// + /// Represents an end point that multiple connections connect to. For HTTP, endpoints are URLs, for non HTTP it can be a TCP listener (or similar) + /// + public abstract class ConnectionHandler + { + /// + /// Called when a new connection is accepted to the endpoint + /// + /// The new + /// A that represents the connection lifetime. When the task completes, the connection is complete. + public abstract Task OnConnectedAsync(ConnectionContext connection); + } +} \ No newline at end of file diff --git a/src/Protocols.Abstractions/Protocols.Abstractions.csproj b/src/Connections.Abstractions/Connections.Abstractions.csproj similarity index 53% rename from src/Protocols.Abstractions/Protocols.Abstractions.csproj rename to src/Connections.Abstractions/Connections.Abstractions.csproj index cd52227801..6e3235be54 100644 --- a/src/Protocols.Abstractions/Protocols.Abstractions.csproj +++ b/src/Connections.Abstractions/Connections.Abstractions.csproj @@ -1,8 +1,8 @@ - Microsoft.AspNetCore.Protocols.Abstractions - Microsoft.AspNetCore.Protocols.Abstractions + Microsoft.AspNetCore.Connections.Abstractions + Microsoft.AspNetCore.Connections.Abstractions Core components of ASP.NET Core networking protocol stack. netstandard2.0 true @@ -13,11 +13,8 @@ - - - - + diff --git a/src/Protocols.Abstractions/DefaultConnectionContext.cs b/src/Connections.Abstractions/DefaultConnectionContext.cs similarity index 94% rename from src/Protocols.Abstractions/DefaultConnectionContext.cs rename to src/Connections.Abstractions/DefaultConnectionContext.cs index 6959062e69..920efba18b 100644 --- a/src/Protocols.Abstractions/DefaultConnectionContext.cs +++ b/src/Connections.Abstractions/DefaultConnectionContext.cs @@ -1,9 +1,9 @@ using System.Collections.Generic; using System.IO.Pipelines; using Microsoft.AspNetCore.Http.Features; -using Microsoft.AspNetCore.Protocols.Features; +using Microsoft.AspNetCore.Connections.Features; -namespace Microsoft.AspNetCore.Protocols +namespace Microsoft.AspNetCore.Connections { public class DefaultConnectionContext : ConnectionContext { diff --git a/src/Protocols.Abstractions/DuplexPipe.cs b/src/Connections.Abstractions/DuplexPipe.cs similarity index 100% rename from src/Protocols.Abstractions/DuplexPipe.cs rename to src/Connections.Abstractions/DuplexPipe.cs diff --git a/src/Protocols.Abstractions/Exceptions/AddressInUseException.cs b/src/Connections.Abstractions/Exceptions/AddressInUseException.cs similarity index 91% rename from src/Protocols.Abstractions/Exceptions/AddressInUseException.cs rename to src/Connections.Abstractions/Exceptions/AddressInUseException.cs index 3a0dddc671..817abe8998 100644 --- a/src/Protocols.Abstractions/Exceptions/AddressInUseException.cs +++ b/src/Connections.Abstractions/Exceptions/AddressInUseException.cs @@ -3,7 +3,7 @@ using System; -namespace Microsoft.AspNetCore.Protocols +namespace Microsoft.AspNetCore.Connections { public class AddressInUseException : InvalidOperationException { diff --git a/src/Protocols.Abstractions/Exceptions/ConnectionAbortedException.cs b/src/Connections.Abstractions/Exceptions/ConnectionAbortedException.cs similarity index 91% rename from src/Protocols.Abstractions/Exceptions/ConnectionAbortedException.cs rename to src/Connections.Abstractions/Exceptions/ConnectionAbortedException.cs index b1119b9c2e..7615010cc7 100644 --- a/src/Protocols.Abstractions/Exceptions/ConnectionAbortedException.cs +++ b/src/Connections.Abstractions/Exceptions/ConnectionAbortedException.cs @@ -1,6 +1,6 @@ using System; -namespace Microsoft.AspNetCore.Protocols +namespace Microsoft.AspNetCore.Connections { public class ConnectionAbortedException : OperationCanceledException { diff --git a/src/Protocols.Abstractions/Exceptions/ConnectionResetException.cs b/src/Connections.Abstractions/Exceptions/ConnectionResetException.cs similarity index 91% rename from src/Protocols.Abstractions/Exceptions/ConnectionResetException.cs rename to src/Connections.Abstractions/Exceptions/ConnectionResetException.cs index a19379628c..78765bc25a 100644 --- a/src/Protocols.Abstractions/Exceptions/ConnectionResetException.cs +++ b/src/Connections.Abstractions/Exceptions/ConnectionResetException.cs @@ -4,7 +4,7 @@ using System; using System.IO; -namespace Microsoft.AspNetCore.Protocols +namespace Microsoft.AspNetCore.Connections { public class ConnectionResetException : IOException { diff --git a/src/Protocols.Abstractions/Features/IApplicationTransportFeature.cs b/src/Connections.Abstractions/Features/IApplicationTransportFeature.cs similarity index 87% rename from src/Protocols.Abstractions/Features/IApplicationTransportFeature.cs rename to src/Connections.Abstractions/Features/IApplicationTransportFeature.cs index 10f22d135e..e4955996c0 100644 --- a/src/Protocols.Abstractions/Features/IApplicationTransportFeature.cs +++ b/src/Connections.Abstractions/Features/IApplicationTransportFeature.cs @@ -5,7 +5,7 @@ using System.Buffers; using System.IO.Pipelines; using System.Threading; -namespace Microsoft.AspNetCore.Protocols.Features +namespace Microsoft.AspNetCore.Connections.Features { public interface IApplicationTransportFeature { diff --git a/src/Protocols.Abstractions/Features/IConnectionHeartbeatFeature.cs b/src/Connections.Abstractions/Features/IConnectionHeartbeatFeature.cs similarity index 85% rename from src/Protocols.Abstractions/Features/IConnectionHeartbeatFeature.cs rename to src/Connections.Abstractions/Features/IConnectionHeartbeatFeature.cs index 9770143a34..cea40d8bdc 100644 --- a/src/Protocols.Abstractions/Features/IConnectionHeartbeatFeature.cs +++ b/src/Connections.Abstractions/Features/IConnectionHeartbeatFeature.cs @@ -3,7 +3,7 @@ using System; -namespace Microsoft.AspNetCore.Protocols.Features +namespace Microsoft.AspNetCore.Connections.Features { public interface IConnectionHeartbeatFeature { diff --git a/src/Protocols.Abstractions/Features/IConnectionIdFeature.cs b/src/Connections.Abstractions/Features/IConnectionIdFeature.cs similarity index 83% rename from src/Protocols.Abstractions/Features/IConnectionIdFeature.cs rename to src/Connections.Abstractions/Features/IConnectionIdFeature.cs index 4c6cd81e77..2fa7ebbadf 100644 --- a/src/Protocols.Abstractions/Features/IConnectionIdFeature.cs +++ b/src/Connections.Abstractions/Features/IConnectionIdFeature.cs @@ -1,7 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -namespace Microsoft.AspNetCore.Protocols.Features +namespace Microsoft.AspNetCore.Connections.Features { public interface IConnectionIdFeature { diff --git a/src/Protocols.Abstractions/Features/IConnectionInherentKeepAliveFeature.cs b/src/Connections.Abstractions/Features/IConnectionInherentKeepAliveFeature.cs similarity index 95% rename from src/Protocols.Abstractions/Features/IConnectionInherentKeepAliveFeature.cs rename to src/Connections.Abstractions/Features/IConnectionInherentKeepAliveFeature.cs index cc3a211e46..8056dfa957 100644 --- a/src/Protocols.Abstractions/Features/IConnectionInherentKeepAliveFeature.cs +++ b/src/Connections.Abstractions/Features/IConnectionInherentKeepAliveFeature.cs @@ -5,7 +5,7 @@ using System; using System.Collections.Generic; using System.Text; -namespace Microsoft.AspNetCore.Protocols.Features +namespace Microsoft.AspNetCore.Connections.Features { /// /// Indicates if the connection transport has an "inherent keep-alive", which means that the transport will automatically diff --git a/src/Protocols.Abstractions/Features/IConnectionItemsFeature.cs b/src/Connections.Abstractions/Features/IConnectionItemsFeature.cs similarity index 86% rename from src/Protocols.Abstractions/Features/IConnectionItemsFeature.cs rename to src/Connections.Abstractions/Features/IConnectionItemsFeature.cs index 136006b5a3..a3aef44310 100644 --- a/src/Protocols.Abstractions/Features/IConnectionItemsFeature.cs +++ b/src/Connections.Abstractions/Features/IConnectionItemsFeature.cs @@ -4,7 +4,7 @@ using System; using System.Collections.Generic; -namespace Microsoft.AspNetCore.Protocols.Features +namespace Microsoft.AspNetCore.Connections.Features { public interface IConnectionItemsFeature { diff --git a/src/Protocols.Abstractions/Features/IConnectionTransportFeature.cs b/src/Connections.Abstractions/Features/IConnectionTransportFeature.cs similarity index 87% rename from src/Protocols.Abstractions/Features/IConnectionTransportFeature.cs rename to src/Connections.Abstractions/Features/IConnectionTransportFeature.cs index bf7067be23..7468dbc722 100644 --- a/src/Protocols.Abstractions/Features/IConnectionTransportFeature.cs +++ b/src/Connections.Abstractions/Features/IConnectionTransportFeature.cs @@ -5,7 +5,7 @@ using System.Buffers; using System.IO.Pipelines; using System.Threading; -namespace Microsoft.AspNetCore.Protocols.Features +namespace Microsoft.AspNetCore.Connections.Features { public interface IConnectionTransportFeature { diff --git a/src/Protocols.Abstractions/Features/IConnectionUserFeature.cs b/src/Connections.Abstractions/Features/IConnectionUserFeature.cs similarity index 71% rename from src/Protocols.Abstractions/Features/IConnectionUserFeature.cs rename to src/Connections.Abstractions/Features/IConnectionUserFeature.cs index 5daf9fd232..3efb362fc7 100644 --- a/src/Protocols.Abstractions/Features/IConnectionUserFeature.cs +++ b/src/Connections.Abstractions/Features/IConnectionUserFeature.cs @@ -1,6 +1,6 @@ using System.Security.Claims; -namespace Microsoft.AspNetCore.Protocols.Features +namespace Microsoft.AspNetCore.Connections.Features { public interface IConnectionUserFeature { diff --git a/src/Protocols.Abstractions/Features/IMemoryPoolFeature.cs b/src/Connections.Abstractions/Features/IMemoryPoolFeature.cs similarity index 86% rename from src/Protocols.Abstractions/Features/IMemoryPoolFeature.cs rename to src/Connections.Abstractions/Features/IMemoryPoolFeature.cs index 128b9ae3c9..0a7e28533e 100644 --- a/src/Protocols.Abstractions/Features/IMemoryPoolFeature.cs +++ b/src/Connections.Abstractions/Features/IMemoryPoolFeature.cs @@ -5,7 +5,7 @@ using System.Buffers; using System.IO.Pipelines; using System.Threading; -namespace Microsoft.AspNetCore.Protocols.Features +namespace Microsoft.AspNetCore.Connections.Features { public interface IMemoryPoolFeature { diff --git a/src/Protocols.Abstractions/Features/ITransferFormatFeature.cs b/src/Connections.Abstractions/Features/ITransferFormatFeature.cs similarity index 85% rename from src/Protocols.Abstractions/Features/ITransferFormatFeature.cs rename to src/Connections.Abstractions/Features/ITransferFormatFeature.cs index 72c262673f..ea39a92760 100644 --- a/src/Protocols.Abstractions/Features/ITransferFormatFeature.cs +++ b/src/Connections.Abstractions/Features/ITransferFormatFeature.cs @@ -1,7 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -namespace Microsoft.AspNetCore.Protocols.Features +namespace Microsoft.AspNetCore.Connections.Features { public interface ITransferFormatFeature { diff --git a/src/Protocols.Abstractions/Features/ITransportSchedulerFeature.cs b/src/Connections.Abstractions/Features/ITransportSchedulerFeature.cs similarity index 88% rename from src/Protocols.Abstractions/Features/ITransportSchedulerFeature.cs rename to src/Connections.Abstractions/Features/ITransportSchedulerFeature.cs index 05c8b8d605..e5d3a8e8d0 100644 --- a/src/Protocols.Abstractions/Features/ITransportSchedulerFeature.cs +++ b/src/Connections.Abstractions/Features/ITransportSchedulerFeature.cs @@ -5,7 +5,7 @@ using System.Buffers; using System.IO.Pipelines; using System.Threading; -namespace Microsoft.AspNetCore.Protocols.Features +namespace Microsoft.AspNetCore.Connections.Features { public interface ITransportSchedulerFeature { diff --git a/src/Protocols.Abstractions/IConnectionBuilder.cs b/src/Connections.Abstractions/IConnectionBuilder.cs similarity index 85% rename from src/Protocols.Abstractions/IConnectionBuilder.cs rename to src/Connections.Abstractions/IConnectionBuilder.cs index 15a028c5db..4825748292 100644 --- a/src/Protocols.Abstractions/IConnectionBuilder.cs +++ b/src/Connections.Abstractions/IConnectionBuilder.cs @@ -1,6 +1,6 @@ using System; -namespace Microsoft.AspNetCore.Protocols +namespace Microsoft.AspNetCore.Connections { public interface IConnectionBuilder { diff --git a/src/Protocols.Abstractions/TransferFormat.cs b/src/Connections.Abstractions/TransferFormat.cs similarity index 86% rename from src/Protocols.Abstractions/TransferFormat.cs rename to src/Connections.Abstractions/TransferFormat.cs index dd7cb28f64..03fd936159 100644 --- a/src/Protocols.Abstractions/TransferFormat.cs +++ b/src/Connections.Abstractions/TransferFormat.cs @@ -3,7 +3,7 @@ using System; -namespace Microsoft.AspNetCore.Protocols +namespace Microsoft.AspNetCore.Connections { [Flags] public enum TransferFormat diff --git a/src/Kestrel.Core/Internal/AddressBinder.cs b/src/Kestrel.Core/Internal/AddressBinder.cs index 96ec14e51b..67ff4f1108 100644 --- a/src/Kestrel.Core/Internal/AddressBinder.cs +++ b/src/Kestrel.Core/Internal/AddressBinder.cs @@ -10,7 +10,7 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting.Server.Features; -using Microsoft.AspNetCore.Protocols; +using Microsoft.AspNetCore.Connections; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; using Microsoft.Extensions.Logging; diff --git a/src/Kestrel.Core/Internal/ConnectionLimitMiddleware.cs b/src/Kestrel.Core/Internal/ConnectionLimitMiddleware.cs index fd6823773f..5be3d5479a 100644 --- a/src/Kestrel.Core/Internal/ConnectionLimitMiddleware.cs +++ b/src/Kestrel.Core/Internal/ConnectionLimitMiddleware.cs @@ -2,7 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Threading.Tasks; -using Microsoft.AspNetCore.Protocols; +using Microsoft.AspNetCore.Connections; using Microsoft.AspNetCore.Server.Kestrel.Core.Features; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; diff --git a/src/Kestrel.Core/Internal/ConnectionHandler.cs b/src/Kestrel.Core/Internal/ConnectionListener.cs similarity index 91% rename from src/Kestrel.Core/Internal/ConnectionHandler.cs rename to src/Kestrel.Core/Internal/ConnectionListener.cs index db02fcd6ff..d3daa84158 100644 --- a/src/Kestrel.Core/Internal/ConnectionHandler.cs +++ b/src/Kestrel.Core/Internal/ConnectionListener.cs @@ -7,20 +7,20 @@ using System.IO.Pipelines; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Http.Features; -using Microsoft.AspNetCore.Protocols; -using Microsoft.AspNetCore.Protocols.Features; +using Microsoft.AspNetCore.Connections; +using Microsoft.AspNetCore.Connections.Features; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; using Microsoft.Extensions.Logging; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal { - public class ConnectionHandler : IConnectionHandler + public class ConnectionDispatcher : IConnectionDispatcher { private readonly ServiceContext _serviceContext; private readonly ConnectionDelegate _connectionDelegate; - public ConnectionHandler(ServiceContext serviceContext, ConnectionDelegate connectionDelegate) + public ConnectionDispatcher(ServiceContext serviceContext, ConnectionDelegate connectionDelegate) { _serviceContext = serviceContext; _connectionDelegate = connectionDelegate; @@ -61,7 +61,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal } catch (Exception ex) { - Log.LogCritical(0, ex, $"{nameof(ConnectionHandler)}.{nameof(Execute)}() {connectionContext.ConnectionId}"); + Log.LogCritical(0, ex, $"{nameof(ConnectionDispatcher)}.{nameof(Execute)}() {connectionContext.ConnectionId}"); } Log.ConnectionStop(connectionContext.ConnectionId); diff --git a/src/Kestrel.Core/Internal/Http/Http1Connection.cs b/src/Kestrel.Core/Internal/Http/Http1Connection.cs index d0105f9bfe..c6215fb1a4 100644 --- a/src/Kestrel.Core/Internal/Http/Http1Connection.cs +++ b/src/Kestrel.Core/Internal/Http/Http1Connection.cs @@ -10,7 +10,7 @@ using System.Runtime.InteropServices; using System.Text; using System.Threading.Tasks; using Microsoft.AspNetCore.Http.Features; -using Microsoft.AspNetCore.Protocols.Abstractions; +using Microsoft.AspNetCore.Connections.Abstractions; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http diff --git a/src/Kestrel.Core/Internal/Http/Http1MessageBody.cs b/src/Kestrel.Core/Internal/Http/Http1MessageBody.cs index 5ac13c69a4..54d400d3a9 100644 --- a/src/Kestrel.Core/Internal/Http/Http1MessageBody.cs +++ b/src/Kestrel.Core/Internal/Http/Http1MessageBody.cs @@ -8,7 +8,7 @@ using System.IO; using System.IO.Pipelines; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Protocols.Abstractions; +using Microsoft.AspNetCore.Connections.Abstractions; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http diff --git a/src/Kestrel.Core/Internal/Http/HttpProtocol.cs b/src/Kestrel.Core/Internal/Http/HttpProtocol.cs index 01bde85605..6bb16e24df 100644 --- a/src/Kestrel.Core/Internal/Http/HttpProtocol.cs +++ b/src/Kestrel.Core/Internal/Http/HttpProtocol.cs @@ -16,7 +16,7 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Hosting.Server; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http.Features; -using Microsoft.AspNetCore.Protocols; +using Microsoft.AspNetCore.Connections; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Primitives; diff --git a/src/Kestrel.Core/Internal/Http/HttpRequestStream.cs b/src/Kestrel.Core/Internal/Http/HttpRequestStream.cs index 2c47fad114..8ea4e9f922 100644 --- a/src/Kestrel.Core/Internal/Http/HttpRequestStream.cs +++ b/src/Kestrel.Core/Internal/Http/HttpRequestStream.cs @@ -7,7 +7,7 @@ using System.Runtime.ExceptionServices; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Http.Features; -using Microsoft.AspNetCore.Protocols; +using Microsoft.AspNetCore.Connections; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http diff --git a/src/Kestrel.Core/Internal/Http/UrlDecoder.cs b/src/Kestrel.Core/Internal/Http/UrlDecoder.cs index fcdb3cfef6..e5ed2c86fa 100644 --- a/src/Kestrel.Core/Internal/Http/UrlDecoder.cs +++ b/src/Kestrel.Core/Internal/Http/UrlDecoder.cs @@ -4,7 +4,7 @@ using System; -namespace Microsoft.AspNetCore.Protocols.Abstractions +namespace Microsoft.AspNetCore.Connections.Abstractions { internal class UrlDecoder { diff --git a/src/Kestrel.Core/Internal/Http2/Http2Connection.cs b/src/Kestrel.Core/Internal/Http2/Http2Connection.cs index 0e1928720f..549e804d33 100644 --- a/src/Kestrel.Core/Internal/Http2/Http2Connection.cs +++ b/src/Kestrel.Core/Internal/Http2/Http2Connection.cs @@ -10,7 +10,7 @@ using System.Text; using System.Threading.Tasks; using Microsoft.AspNetCore.Hosting.Server; using Microsoft.AspNetCore.Http.Features; -using Microsoft.AspNetCore.Protocols; +using Microsoft.AspNetCore.Connections; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2.HPack; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; diff --git a/src/Kestrel.Core/Internal/HttpConnectionBuilderExtensions.cs b/src/Kestrel.Core/Internal/HttpConnectionBuilderExtensions.cs index ed57343f27..dcd073855b 100644 --- a/src/Kestrel.Core/Internal/HttpConnectionBuilderExtensions.cs +++ b/src/Kestrel.Core/Internal/HttpConnectionBuilderExtensions.cs @@ -4,7 +4,7 @@ using System; using System.Collections.Generic; using Microsoft.AspNetCore.Hosting.Server; -using Microsoft.AspNetCore.Protocols; +using Microsoft.AspNetCore.Connections; using Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal diff --git a/src/Kestrel.Core/Internal/HttpConnectionMiddleware.cs b/src/Kestrel.Core/Internal/HttpConnectionMiddleware.cs index 3be295627d..87ae45c154 100644 --- a/src/Kestrel.Core/Internal/HttpConnectionMiddleware.cs +++ b/src/Kestrel.Core/Internal/HttpConnectionMiddleware.cs @@ -4,8 +4,8 @@ using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Hosting.Server; using Microsoft.AspNetCore.Http.Features; -using Microsoft.AspNetCore.Protocols; -using Microsoft.AspNetCore.Protocols.Features; +using Microsoft.AspNetCore.Connections; +using Microsoft.AspNetCore.Connections.Features; using Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal diff --git a/src/Kestrel.Core/Internal/Infrastructure/HttpConnectionManagerShutdownExtensions.cs b/src/Kestrel.Core/Internal/Infrastructure/HttpConnectionManagerShutdownExtensions.cs index 40e41874c4..24400fedef 100644 --- a/src/Kestrel.Core/Internal/Infrastructure/HttpConnectionManagerShutdownExtensions.cs +++ b/src/Kestrel.Core/Internal/Infrastructure/HttpConnectionManagerShutdownExtensions.cs @@ -4,7 +4,7 @@ using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; -using Microsoft.AspNetCore.Protocols; +using Microsoft.AspNetCore.Connections; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure { diff --git a/src/Kestrel.Core/Kestrel.Core.csproj b/src/Kestrel.Core/Kestrel.Core.csproj index 68a0b5aaf5..b81428efa5 100644 --- a/src/Kestrel.Core/Kestrel.Core.csproj +++ b/src/Kestrel.Core/Kestrel.Core.csproj @@ -24,6 +24,7 @@ + diff --git a/src/Kestrel.Core/KestrelServer.cs b/src/Kestrel.Core/KestrelServer.cs index 2ab8472cc3..9e549a2282 100644 --- a/src/Kestrel.Core/KestrelServer.cs +++ b/src/Kestrel.Core/KestrelServer.cs @@ -148,8 +148,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core connectionDelegate = new ConnectionLimitMiddleware(connectionDelegate, Options.Limits.MaxConcurrentConnections.Value, Trace).OnConnectionAsync; } - var connectionHandler = new ConnectionHandler(ServiceContext, connectionDelegate); - var transport = _transportFactory.Create(endpoint, connectionHandler); + var connectionDispatcher = new ConnectionDispatcher(ServiceContext, connectionDelegate); + var transport = _transportFactory.Create(endpoint, connectionDispatcher); _transports.Add(transport); await transport.BindAsync().ConfigureAwait(false); diff --git a/src/Kestrel.Core/ListenOptions.cs b/src/Kestrel.Core/ListenOptions.cs index 0ed675aac8..bdef463d60 100644 --- a/src/Kestrel.Core/ListenOptions.cs +++ b/src/Kestrel.Core/ListenOptions.cs @@ -6,7 +6,7 @@ using System.Collections.Generic; using System.Linq; using System.Net; using System.Threading.Tasks; -using Microsoft.AspNetCore.Protocols; +using Microsoft.AspNetCore.Connections; using Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal; using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; diff --git a/src/Kestrel.Transport.Abstractions/Internal/IConnectionHandler.cs b/src/Kestrel.Transport.Abstractions/Internal/IConnectionDispatcher.cs similarity index 89% rename from src/Kestrel.Transport.Abstractions/Internal/IConnectionHandler.cs rename to src/Kestrel.Transport.Abstractions/Internal/IConnectionDispatcher.cs index eec71ff61c..05b7d84ea2 100644 --- a/src/Kestrel.Transport.Abstractions/Internal/IConnectionHandler.cs +++ b/src/Kestrel.Transport.Abstractions/Internal/IConnectionDispatcher.cs @@ -5,7 +5,7 @@ using Microsoft.AspNetCore.Http.Features; namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal { - public interface IConnectionHandler + public interface IConnectionDispatcher { void OnConnection(TransportConnection connection); } diff --git a/src/Kestrel.Transport.Abstractions/Internal/ITransportFactory.cs b/src/Kestrel.Transport.Abstractions/Internal/ITransportFactory.cs index 326b6c1cfc..4037467e87 100644 --- a/src/Kestrel.Transport.Abstractions/Internal/ITransportFactory.cs +++ b/src/Kestrel.Transport.Abstractions/Internal/ITransportFactory.cs @@ -5,6 +5,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal { public interface ITransportFactory { - ITransport Create(IEndPointInformation endPointInformation, IConnectionHandler handler); + ITransport Create(IEndPointInformation endPointInformation, IConnectionDispatcher dispatcher); } } diff --git a/src/Kestrel.Transport.Abstractions/Internal/TransportConnection.Features.cs b/src/Kestrel.Transport.Abstractions/Internal/TransportConnection.Features.cs index c9e316557f..8ab96ba108 100644 --- a/src/Kestrel.Transport.Abstractions/Internal/TransportConnection.Features.cs +++ b/src/Kestrel.Transport.Abstractions/Internal/TransportConnection.Features.cs @@ -5,7 +5,7 @@ using System.Collections.Generic; using System.IO.Pipelines; using System.Net; using Microsoft.AspNetCore.Http.Features; -using Microsoft.AspNetCore.Protocols.Features; +using Microsoft.AspNetCore.Connections.Features; namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal { diff --git a/src/Kestrel.Transport.Abstractions/Kestrel.Transport.Abstractions.csproj b/src/Kestrel.Transport.Abstractions/Kestrel.Transport.Abstractions.csproj index b8877c964a..58529f72d0 100644 --- a/src/Kestrel.Transport.Abstractions/Kestrel.Transport.Abstractions.csproj +++ b/src/Kestrel.Transport.Abstractions/Kestrel.Transport.Abstractions.csproj @@ -13,7 +13,7 @@ - + diff --git a/src/Kestrel.Transport.Libuv/Internal/LibuvConnection.cs b/src/Kestrel.Transport.Libuv/Internal/LibuvConnection.cs index b5df138e61..b6295aa568 100644 --- a/src/Kestrel.Transport.Libuv/Internal/LibuvConnection.cs +++ b/src/Kestrel.Transport.Libuv/Internal/LibuvConnection.cs @@ -7,7 +7,7 @@ using System.IO; using System.IO.Pipelines; using System.Threading; using System.Threading.Tasks; -using Microsoft.AspNetCore.Protocols; +using Microsoft.AspNetCore.Connections; using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking; using Microsoft.Extensions.Logging; @@ -48,14 +48,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal public LibuvOutputConsumer OutputConsumer { get; set; } private ILibuvTrace Log => ListenerContext.TransportContext.Log; - private IConnectionHandler ConnectionHandler => ListenerContext.TransportContext.ConnectionHandler; + private IConnectionDispatcher ConnectionDispatcher => ListenerContext.TransportContext.ConnectionDispatcher; private LibuvThread Thread => ListenerContext.Thread; public async Task Start() { try { - ConnectionHandler.OnConnection(this); + ConnectionDispatcher.OnConnection(this); OutputConsumer = new LibuvOutputConsumer(Output, Thread, _socket, ConnectionId, Log); diff --git a/src/Kestrel.Transport.Libuv/Internal/LibuvTransportContext.cs b/src/Kestrel.Transport.Libuv/Internal/LibuvTransportContext.cs index 9256c85048..37074dc968 100644 --- a/src/Kestrel.Transport.Libuv/Internal/LibuvTransportContext.cs +++ b/src/Kestrel.Transport.Libuv/Internal/LibuvTransportContext.cs @@ -14,6 +14,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal public ILibuvTrace Log { get; set; } - public IConnectionHandler ConnectionHandler { get; set; } + public IConnectionDispatcher ConnectionDispatcher { get; set; } } } diff --git a/src/Kestrel.Transport.Libuv/LibuvTransport.cs b/src/Kestrel.Transport.Libuv/LibuvTransport.cs index 19eb6cf72e..35def2dc55 100644 --- a/src/Kestrel.Transport.Libuv/LibuvTransport.cs +++ b/src/Kestrel.Transport.Libuv/LibuvTransport.cs @@ -6,7 +6,7 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Hosting; -using Microsoft.AspNetCore.Protocols; +using Microsoft.AspNetCore.Connections; using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal; using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking; diff --git a/src/Kestrel.Transport.Libuv/LibuvTransportFactory.cs b/src/Kestrel.Transport.Libuv/LibuvTransportFactory.cs index a698388bea..418f43abd8 100644 --- a/src/Kestrel.Transport.Libuv/LibuvTransportFactory.cs +++ b/src/Kestrel.Transport.Libuv/LibuvTransportFactory.cs @@ -62,14 +62,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv }; } - public ITransport Create(IEndPointInformation endPointInformation, IConnectionHandler handler) + public ITransport Create(IEndPointInformation endPointInformation, IConnectionDispatcher dispatcher) { var transportContext = new LibuvTransportContext { Options = _baseTransportContext.Options, AppLifetime = _baseTransportContext.AppLifetime, Log = _baseTransportContext.Log, - ConnectionHandler = handler + ConnectionDispatcher = dispatcher }; return new LibuvTransport(transportContext, endPointInformation); diff --git a/src/Kestrel.Transport.Sockets/Internal/SocketConnection.cs b/src/Kestrel.Transport.Sockets/Internal/SocketConnection.cs index a70ec03f46..726d0372ca 100644 --- a/src/Kestrel.Transport.Sockets/Internal/SocketConnection.cs +++ b/src/Kestrel.Transport.Sockets/Internal/SocketConnection.cs @@ -10,7 +10,7 @@ using System.Net; using System.Net.Sockets; using System.Runtime.InteropServices; using System.Threading.Tasks; -using Microsoft.AspNetCore.Protocols; +using Microsoft.AspNetCore.Connections; using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; using Microsoft.Extensions.Logging; @@ -60,12 +60,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal public override PipeScheduler InputWriterScheduler => _scheduler; public override PipeScheduler OutputReaderScheduler => _scheduler; - public async Task StartAsync(IConnectionHandler connectionHandler) + public async Task StartAsync(IConnectionDispatcher connectionDispatcher) { Exception sendError = null; try { - connectionHandler.OnConnection(this); + connectionDispatcher.OnConnection(this); // Spawn send and receive logic Task receiveTask = DoReceive(); diff --git a/src/Kestrel.Transport.Sockets/SocketTransport.cs b/src/Kestrel.Transport.Sockets/SocketTransport.cs index 9a11e03a0f..725ee0546d 100644 --- a/src/Kestrel.Transport.Sockets/SocketTransport.cs +++ b/src/Kestrel.Transport.Sockets/SocketTransport.cs @@ -11,7 +11,7 @@ using System.Runtime.ExceptionServices; using System.Runtime.InteropServices; using System.Threading.Tasks; using Microsoft.AspNetCore.Hosting; -using Microsoft.AspNetCore.Protocols; +using Microsoft.AspNetCore.Connections; using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; using Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal; using Microsoft.Extensions.Logging; @@ -24,7 +24,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets private readonly MemoryPool _memoryPool = KestrelMemoryPool.Create(); private readonly IEndPointInformation _endPointInformation; - private readonly IConnectionHandler _handler; + private readonly IConnectionDispatcher _dispatcher; private readonly IApplicationLifetime _appLifetime; private readonly int _numSchedulers; private readonly PipeScheduler[] _schedulers; @@ -36,19 +36,19 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets internal SocketTransport( IEndPointInformation endPointInformation, - IConnectionHandler handler, + IConnectionDispatcher dispatcher, IApplicationLifetime applicationLifetime, int ioQueueCount, ISocketsTrace trace) { Debug.Assert(endPointInformation != null); Debug.Assert(endPointInformation.Type == ListenType.IPEndPoint); - Debug.Assert(handler != null); + Debug.Assert(dispatcher != null); Debug.Assert(applicationLifetime != null); Debug.Assert(trace != null); _endPointInformation = endPointInformation; - _handler = handler; + _dispatcher = dispatcher; _appLifetime = applicationLifetime; _trace = trace; @@ -155,7 +155,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets acceptSocket.NoDelay = _endPointInformation.NoDelay; var connection = new SocketConnection(acceptSocket, _memoryPool, _schedulers[schedulerIndex], _trace); - _ = connection.StartAsync(_handler); + _ = connection.StartAsync(_dispatcher); } catch (SocketException ex) when (ex.SocketErrorCode == SocketError.ConnectionReset) { diff --git a/src/Kestrel.Transport.Sockets/SocketTransportFactory.cs b/src/Kestrel.Transport.Sockets/SocketTransportFactory.cs index 473a1519cc..7ddd1d918d 100644 --- a/src/Kestrel.Transport.Sockets/SocketTransportFactory.cs +++ b/src/Kestrel.Transport.Sockets/SocketTransportFactory.cs @@ -40,7 +40,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets _trace = new SocketsTrace(logger); } - public ITransport Create(IEndPointInformation endPointInformation, IConnectionHandler handler) + public ITransport Create(IEndPointInformation endPointInformation, IConnectionDispatcher dispatcher) { if (endPointInformation == null) { @@ -52,12 +52,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets throw new ArgumentException(SocketsStrings.OnlyIPEndPointsSupported, nameof(endPointInformation)); } - if (handler == null) + if (dispatcher == null) { - throw new ArgumentNullException(nameof(handler)); + throw new ArgumentNullException(nameof(dispatcher)); } - return new SocketTransport(endPointInformation, handler, _appLifetime, _options.IOQueueCount, _trace); + return new SocketTransport(endPointInformation, dispatcher, _appLifetime, _options.IOQueueCount, _trace); } } } diff --git a/test/Kestrel.Core.Tests/AddressBinderTests.cs b/test/Kestrel.Core.Tests/AddressBinderTests.cs index 9308c8c14b..426e490502 100644 --- a/test/Kestrel.Core.Tests/AddressBinderTests.cs +++ b/test/Kestrel.Core.Tests/AddressBinderTests.cs @@ -5,7 +5,7 @@ using System; using System.IO; using System.Net; using System.Threading.Tasks; -using Microsoft.AspNetCore.Protocols; +using Microsoft.AspNetCore.Connections; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal; using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; using Microsoft.AspNetCore.Testing; diff --git a/test/Kestrel.Core.Tests/ConnectionHandlerTests.cs b/test/Kestrel.Core.Tests/ConnectionDispatcherTests.cs similarity index 89% rename from test/Kestrel.Core.Tests/ConnectionHandlerTests.cs rename to test/Kestrel.Core.Tests/ConnectionDispatcherTests.cs index 27128fe558..9f53e16750 100644 --- a/test/Kestrel.Core.Tests/ConnectionHandlerTests.cs +++ b/test/Kestrel.Core.Tests/ConnectionDispatcherTests.cs @@ -5,7 +5,7 @@ using System.Linq; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Http.Features; -using Microsoft.AspNetCore.Protocols.Features; +using Microsoft.AspNetCore.Connections.Features; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; @@ -14,18 +14,18 @@ using Xunit; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests { - public class ConnectionHandlerTests + public class ConnectionDispatcherTests { [Fact] public void OnConnectionCreatesLogScopeWithConnectionId() { var serviceContext = new TestServiceContext(); var tcs = new TaskCompletionSource(); - var handler = new ConnectionHandler(serviceContext, _ => tcs.Task); + var dispatcher = new ConnectionDispatcher(serviceContext, _ => tcs.Task); var connection = new TestConnection(); - handler.OnConnection(connection); + dispatcher.OnConnection(connection); // The scope should be created var scopeObjects = ((TestKestrelTrace)serviceContext.Log) diff --git a/test/Kestrel.Core.Tests/Http2ConnectionTests.cs b/test/Kestrel.Core.Tests/Http2ConnectionTests.cs index 46af33c2dc..341c9b21e6 100644 --- a/test/Kestrel.Core.Tests/Http2ConnectionTests.cs +++ b/test/Kestrel.Core.Tests/Http2ConnectionTests.cs @@ -12,7 +12,7 @@ using System.Text; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Protocols; +using Microsoft.AspNetCore.Connections; using Microsoft.AspNetCore.Server.Kestrel.Core.Features; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2; diff --git a/test/Kestrel.Core.Tests/KestrelServerTests.cs b/test/Kestrel.Core.Tests/KestrelServerTests.cs index fefd6bce51..10de4f2fa6 100644 --- a/test/Kestrel.Core.Tests/KestrelServerTests.cs +++ b/test/Kestrel.Core.Tests/KestrelServerTests.cs @@ -61,7 +61,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests Assert.Contains(server.Options.ListenOptions[0].ConnectionAdapters, adapter => adapter.IsHttps); } } - + [Fact] public void KestrelServerThrowsUsefulExceptionIfDefaultHttpsProviderNotAdded() { @@ -73,7 +73,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests Assert.Equal(CoreStrings.NoCertSpecifiedNoDevelopmentCertificateFound, ex.Message); } } - + [Fact] public void KestrelServerDoesNotThrowIfNoDefaultHttpsProviderButNoHttpUrls() { @@ -84,7 +84,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests StartDummyApplication(server); } } - + [Fact] public void KestrelServerDoesNotThrowIfNoDefaultHttpsProviderButManualListenOptions() { @@ -241,7 +241,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests var mockTransportFactory = new Mock(); mockTransportFactory - .Setup(transportFactory => transportFactory.Create(It.IsAny(), It.IsAny())) + .Setup(transportFactory => transportFactory.Create(It.IsAny(), It.IsAny())) .Returns(mockTransport.Object); var mockLoggerFactory = new Mock(); @@ -298,7 +298,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests var mockTransportFactory = new Mock(); mockTransportFactory - .Setup(transportFactory => transportFactory.Create(It.IsAny(), It.IsAny())) + .Setup(transportFactory => transportFactory.Create(It.IsAny(), It.IsAny())) .Returns(mockTransport.Object); var mockLoggerFactory = new Mock(); @@ -342,7 +342,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests private class MockTransportFactory : ITransportFactory { - public ITransport Create(IEndPointInformation endPointInformation, IConnectionHandler handler) + public ITransport Create(IEndPointInformation endPointInformation, IConnectionDispatcher handler) { return Mock.Of(); } diff --git a/test/Kestrel.Core.Tests/PipeOptionsTests.cs b/test/Kestrel.Core.Tests/PipeOptionsTests.cs index 0a15d06491..3643fc44ba 100644 --- a/test/Kestrel.Core.Tests/PipeOptionsTests.cs +++ b/test/Kestrel.Core.Tests/PipeOptionsTests.cs @@ -26,7 +26,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests serviceContext.Scheduler = PipeScheduler.ThreadPool; var mockScheduler = Mock.Of(); - var outputPipeOptions = ConnectionHandler.GetOutputPipeOptions(serviceContext, KestrelMemoryPool.Create(), readerScheduler: mockScheduler); + var outputPipeOptions = ConnectionDispatcher.GetOutputPipeOptions(serviceContext, KestrelMemoryPool.Create(), readerScheduler: mockScheduler); Assert.Equal(expectedMaximumSizeLow, outputPipeOptions.ResumeWriterThreshold); Assert.Equal(expectedMaximumSizeHigh, outputPipeOptions.PauseWriterThreshold); @@ -44,7 +44,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests serviceContext.Scheduler = PipeScheduler.ThreadPool; var mockScheduler = Mock.Of(); - var inputPipeOptions = ConnectionHandler.GetInputPipeOptions(serviceContext, KestrelMemoryPool.Create(), writerScheduler: mockScheduler); + var inputPipeOptions = ConnectionDispatcher.GetInputPipeOptions(serviceContext, KestrelMemoryPool.Create(), writerScheduler: mockScheduler); Assert.Equal(expectedMaximumSizeLow, inputPipeOptions.ResumeWriterThreshold); Assert.Equal(expectedMaximumSizeHigh, inputPipeOptions.PauseWriterThreshold); diff --git a/test/Kestrel.FunctionalTests/RequestTests.cs b/test/Kestrel.FunctionalTests/RequestTests.cs index 673cf42ff8..8aefc5f786 100644 --- a/test/Kestrel.FunctionalTests/RequestTests.cs +++ b/test/Kestrel.FunctionalTests/RequestTests.cs @@ -18,7 +18,7 @@ using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http.Features; -using Microsoft.AspNetCore.Protocols; +using Microsoft.AspNetCore.Connections; using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.AspNetCore.Server.Kestrel.Core.Features; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; diff --git a/test/Kestrel.Transport.Libuv.Tests/LibuvConnectionTests.cs b/test/Kestrel.Transport.Libuv.Tests/LibuvConnectionTests.cs index 2eeec77ab7..7a82e6da15 100644 --- a/test/Kestrel.Transport.Libuv.Tests/LibuvConnectionTests.cs +++ b/test/Kestrel.Transport.Libuv.Tests/LibuvConnectionTests.cs @@ -19,9 +19,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests [Fact] public async Task DoesNotEndConnectionOnZeroRead() { - var mockConnectionHandler = new MockConnectionHandler(); + var mockConnectionDispatcher = new MockConnectionDispatcher(); var mockLibuv = new MockLibuv(); - var transportContext = new TestLibuvTransportContext() { ConnectionHandler = mockConnectionHandler }; + var transportContext = new TestLibuvTransportContext() { ConnectionDispatcher = mockConnectionDispatcher }; var transport = new LibuvTransport(mockLibuv, transportContext, null); var thread = new LibuvThread(transport); @@ -42,7 +42,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests mockLibuv.ReadCallback(socket.InternalGetHandle(), 0, ref ignored); }, (object)null); - var readAwaitable = mockConnectionHandler.Input.Reader.ReadAsync(); + var readAwaitable = mockConnectionDispatcher.Input.Reader.ReadAsync(); Assert.False(readAwaitable.IsCompleted); } finally @@ -54,12 +54,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests [Fact] public async Task ConnectionDoesNotResumeAfterSocketCloseIfBackpressureIsApplied() { - var mockConnectionHandler = new MockConnectionHandler(); + var mockConnectionDispatcher = new MockConnectionDispatcher(); var mockLibuv = new MockLibuv(); - var transportContext = new TestLibuvTransportContext() { ConnectionHandler = mockConnectionHandler }; + var transportContext = new TestLibuvTransportContext() { ConnectionDispatcher = mockConnectionDispatcher }; var transport = new LibuvTransport(mockLibuv, transportContext, null); var thread = new LibuvThread(transport); - mockConnectionHandler.InputOptions = pool => + mockConnectionDispatcher.InputOptions = pool => new PipeOptions( pool: pool, pauseWriterThreshold: 3, @@ -69,7 +69,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests // We don't set the output writer scheduler here since we want to run the callback inline - mockConnectionHandler.OutputOptions = pool => new PipeOptions(pool: pool, readerScheduler: thread, writerScheduler: PipeScheduler.Inline, useSynchronizationContext: false); + mockConnectionDispatcher.OutputOptions = pool => new PipeOptions(pool: pool, readerScheduler: thread, writerScheduler: PipeScheduler.Inline, useSynchronizationContext: false); Task connectionTask = null; @@ -98,7 +98,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests Assert.Null(mockLibuv.ReadCallback); // Now complete the output writer so that the connection closes - mockConnectionHandler.Output.Writer.Complete(); + mockConnectionDispatcher.Output.Writer.Complete(); await connectionTask.TimeoutAfter(TestConstants.DefaultTimeout); @@ -115,9 +115,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests [Fact] public async Task ConnectionDoesNotResumeAfterReadCallbackScheduledAndSocketCloseIfBackpressureIsApplied() { - var mockConnectionHandler = new MockConnectionHandler(); + var mockConnectionDispatcher = new MockConnectionDispatcher(); var mockLibuv = new MockLibuv(); - var transportContext = new TestLibuvTransportContext() { ConnectionHandler = mockConnectionHandler }; + var transportContext = new TestLibuvTransportContext() { ConnectionDispatcher = mockConnectionDispatcher }; var transport = new LibuvTransport(mockLibuv, transportContext, null); var thread = new LibuvThread(transport); var mockScheduler = new Mock(); @@ -126,7 +126,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests { backPressure = () => a(o); }); - mockConnectionHandler.InputOptions = pool => + mockConnectionDispatcher.InputOptions = pool => new PipeOptions( pool: pool, pauseWriterThreshold: 3, @@ -135,7 +135,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests readerScheduler: PipeScheduler.Inline, useSynchronizationContext: false); - mockConnectionHandler.OutputOptions = pool => new PipeOptions(pool: pool, readerScheduler: thread, writerScheduler: PipeScheduler.Inline, useSynchronizationContext: false); + mockConnectionDispatcher.OutputOptions = pool => new PipeOptions(pool: pool, readerScheduler: thread, writerScheduler: PipeScheduler.Inline, useSynchronizationContext: false); Task connectionTask = null; try @@ -163,13 +163,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests Assert.Null(mockLibuv.ReadCallback); // Now release backpressure by reading the input - var result = await mockConnectionHandler.Input.Reader.ReadAsync(); + var result = await mockConnectionDispatcher.Input.Reader.ReadAsync(); // Calling advance will call into our custom scheduler that captures the back pressure // callback - mockConnectionHandler.Input.Reader.AdvanceTo(result.Buffer.End); + mockConnectionDispatcher.Input.Reader.AdvanceTo(result.Buffer.End); // Cancel the current pending flush - mockConnectionHandler.Input.Writer.CancelPendingFlush(); + mockConnectionDispatcher.Input.Writer.CancelPendingFlush(); // Now release the back pressure await thread.PostAsync(a => a(), backPressure); @@ -179,7 +179,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests Assert.Null(mockLibuv.ReadCallback); // Now complete the output writer and wait for the connection to close - mockConnectionHandler.Output.Writer.Complete(); + mockConnectionDispatcher.Output.Writer.Complete(); await connectionTask.TimeoutAfter(TestConstants.DefaultTimeout); @@ -196,9 +196,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests [Fact] public async Task DoesNotThrowIfOnReadCallbackCalledWithEOFButAllocCallbackNotCalled() { - var mockConnectionHandler = new MockConnectionHandler(); + var mockConnectionDispatcher = new MockConnectionDispatcher(); var mockLibuv = new MockLibuv(); - var transportContext = new TestLibuvTransportContext() { ConnectionHandler = mockConnectionHandler }; + var transportContext = new TestLibuvTransportContext() { ConnectionDispatcher = mockConnectionDispatcher }; var transport = new LibuvTransport(mockLibuv, transportContext, null); var thread = new LibuvThread(transport); @@ -219,7 +219,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests mockLibuv.ReadCallback(socket.InternalGetHandle(), TestConstants.EOF, ref ignored); }, (object)null); - var readAwaitable = await mockConnectionHandler.Input.Reader.ReadAsync(); + var readAwaitable = await mockConnectionDispatcher.Input.Reader.ReadAsync(); Assert.True(readAwaitable.IsCompleted); } finally diff --git a/test/Kestrel.Transport.Libuv.Tests/LibuvThreadTests.cs b/test/Kestrel.Transport.Libuv.Tests/LibuvThreadTests.cs index db3b3ebd8f..5177420d9c 100644 --- a/test/Kestrel.Transport.Libuv.Tests/LibuvThreadTests.cs +++ b/test/Kestrel.Transport.Libuv.Tests/LibuvThreadTests.cs @@ -18,9 +18,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests [Fact] public async Task LibuvThreadDoesNotThrowIfPostingWorkAfterDispose() { - var mockConnectionHandler = new MockConnectionHandler(); + var mockConnectionDispatcher = new MockConnectionDispatcher(); var mockLibuv = new MockLibuv(); - var transportContext = new TestLibuvTransportContext() { ConnectionHandler = mockConnectionHandler }; + var transportContext = new TestLibuvTransportContext() { ConnectionDispatcher = mockConnectionDispatcher }; var transport = new LibuvTransport(mockLibuv, transportContext, null); var thread = new LibuvThread(transport); var ranOne = false; diff --git a/test/Kestrel.Transport.Libuv.Tests/LibuvTransportTests.cs b/test/Kestrel.Transport.Libuv.Tests/LibuvTransportTests.cs index 3f478546da..388f78e3ba 100644 --- a/test/Kestrel.Transport.Libuv.Tests/LibuvTransportTests.cs +++ b/test/Kestrel.Transport.Libuv.Tests/LibuvTransportTests.cs @@ -67,7 +67,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests var transportContext = new TestLibuvTransportContext() { - ConnectionHandler = new ConnectionHandler(serviceContext, listenOptions.Build()) + ConnectionDispatcher = new ConnectionDispatcher(serviceContext, listenOptions.Build()) }; var transport = new LibuvTransport(transportContext, listenOptions); @@ -106,7 +106,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests var transportContext = new TestLibuvTransportContext() { - ConnectionHandler = new ConnectionHandler(serviceContext, listenOptions.Build()), + ConnectionDispatcher = new ConnectionDispatcher(serviceContext, listenOptions.Build()), Options = new LibuvTransportOptions { ThreadCount = threadCount } }; diff --git a/test/Kestrel.Transport.Libuv.Tests/ListenerPrimaryTests.cs b/test/Kestrel.Transport.Libuv.Tests/ListenerPrimaryTests.cs index cd243e815b..fa4198ccb4 100644 --- a/test/Kestrel.Transport.Libuv.Tests/ListenerPrimaryTests.cs +++ b/test/Kestrel.Transport.Libuv.Tests/ListenerPrimaryTests.cs @@ -8,7 +8,7 @@ using System.Linq; using System.Net; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Protocols; +using Microsoft.AspNetCore.Connections; using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal; using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; @@ -34,13 +34,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests var transportContextPrimary = new TestLibuvTransportContext(); var builderPrimary = new ConnectionBuilder(); builderPrimary.UseHttpServer(serviceContextPrimary, new DummyApplication(c => c.Response.WriteAsync("Primary")), HttpProtocols.Http1); - transportContextPrimary.ConnectionHandler = new ConnectionHandler(serviceContextPrimary, builderPrimary.Build()); + transportContextPrimary.ConnectionDispatcher = new ConnectionDispatcher(serviceContextPrimary, builderPrimary.Build()); var serviceContextSecondary = new TestServiceContext(); var builderSecondary = new ConnectionBuilder(); builderSecondary.UseHttpServer(serviceContextSecondary, new DummyApplication(c => c.Response.WriteAsync("Secondary")), HttpProtocols.Http1); var transportContextSecondary = new TestLibuvTransportContext(); - transportContextSecondary.ConnectionHandler = new ConnectionHandler(serviceContextSecondary, builderSecondary.Build()); + transportContextSecondary.ConnectionDispatcher = new ConnectionDispatcher(serviceContextSecondary, builderSecondary.Build()); var libuvTransport = new LibuvTransport(libuv, transportContextPrimary, listenOptions); @@ -103,7 +103,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests var builderPrimary = new ConnectionBuilder(); builderPrimary.UseHttpServer(serviceContextPrimary, new DummyApplication(c => c.Response.WriteAsync("Primary")), HttpProtocols.Http1); var transportContextPrimary = new TestLibuvTransportContext() { Log = new LibuvTrace(logger) }; - transportContextPrimary.ConnectionHandler = new ConnectionHandler(serviceContextPrimary, builderPrimary.Build()); + transportContextPrimary.ConnectionDispatcher = new ConnectionDispatcher(serviceContextPrimary, builderPrimary.Build()); var serviceContextSecondary = new TestServiceContext { @@ -115,7 +115,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests var builderSecondary = new ConnectionBuilder(); builderSecondary.UseHttpServer(serviceContextSecondary, new DummyApplication(c => c.Response.WriteAsync("Secondary")), HttpProtocols.Http1); var transportContextSecondary = new TestLibuvTransportContext(); - transportContextSecondary.ConnectionHandler = new ConnectionHandler(serviceContextSecondary, builderSecondary.Build()); + transportContextSecondary.ConnectionDispatcher = new ConnectionDispatcher(serviceContextSecondary, builderSecondary.Build()); var libuvTransport = new LibuvTransport(libuv, transportContextPrimary, listenOptions); @@ -214,7 +214,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests var builderPrimary = new ConnectionBuilder(); builderPrimary.UseHttpServer(serviceContextPrimary, new DummyApplication(c => c.Response.WriteAsync("Primary")), HttpProtocols.Http1); var transportContextPrimary = new TestLibuvTransportContext() { Log = new LibuvTrace(logger) }; - transportContextPrimary.ConnectionHandler = new ConnectionHandler(serviceContextPrimary, builderPrimary.Build()); + transportContextPrimary.ConnectionDispatcher = new ConnectionDispatcher(serviceContextPrimary, builderPrimary.Build()); var serviceContextSecondary = new TestServiceContext { @@ -226,7 +226,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests var builderSecondary = new ConnectionBuilder(); builderSecondary.UseHttpServer(serviceContextSecondary, new DummyApplication(c => c.Response.WriteAsync("Secondary")), HttpProtocols.Http1); var transportContextSecondary = new TestLibuvTransportContext(); - transportContextSecondary.ConnectionHandler = new ConnectionHandler(serviceContextSecondary, builderSecondary.Build()); + transportContextSecondary.ConnectionDispatcher = new ConnectionDispatcher(serviceContextSecondary, builderSecondary.Build()); var libuvTransport = new LibuvTransport(libuv, transportContextPrimary, listenOptions); diff --git a/test/Kestrel.Transport.Libuv.Tests/TestHelpers/MockConnectionHandler.cs b/test/Kestrel.Transport.Libuv.Tests/TestHelpers/MockConnectionDispatcher.cs similarity index 89% rename from test/Kestrel.Transport.Libuv.Tests/TestHelpers/MockConnectionHandler.cs rename to test/Kestrel.Transport.Libuv.Tests/TestHelpers/MockConnectionDispatcher.cs index edae9162f5..e4f17bbda4 100644 --- a/test/Kestrel.Transport.Libuv.Tests/TestHelpers/MockConnectionHandler.cs +++ b/test/Kestrel.Transport.Libuv.Tests/TestHelpers/MockConnectionDispatcher.cs @@ -5,13 +5,13 @@ using System; using System.Buffers; using System.IO.Pipelines; using Microsoft.AspNetCore.Http.Features; -using Microsoft.AspNetCore.Protocols; -using Microsoft.AspNetCore.Protocols.Features; +using Microsoft.AspNetCore.Connections; +using Microsoft.AspNetCore.Connections.Features; using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests.TestHelpers { - public class MockConnectionHandler : IConnectionHandler + public class MockConnectionDispatcher : IConnectionDispatcher { public Func, PipeOptions> InputOptions { get; set; } = pool => new PipeOptions(pool, readerScheduler: PipeScheduler.Inline, writerScheduler: PipeScheduler.Inline, useSynchronizationContext: false); public Func, PipeOptions> OutputOptions { get; set; } = pool => new PipeOptions(pool, readerScheduler: PipeScheduler.Inline, writerScheduler: PipeScheduler.Inline, useSynchronizationContext: false); diff --git a/test/Kestrel.Transport.Libuv.Tests/TestHelpers/TestLibuvTransportContext.cs b/test/Kestrel.Transport.Libuv.Tests/TestHelpers/TestLibuvTransportContext.cs index d764eaf940..c779b87647 100644 --- a/test/Kestrel.Transport.Libuv.Tests/TestHelpers/TestLibuvTransportContext.cs +++ b/test/Kestrel.Transport.Libuv.Tests/TestHelpers/TestLibuvTransportContext.cs @@ -13,7 +13,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests.TestHelpers var logger = new TestApplicationErrorLogger(); AppLifetime = new LifetimeNotImplemented(); - ConnectionHandler = new MockConnectionHandler(); + ConnectionDispatcher = new MockConnectionDispatcher(); Log = new LibuvTrace(logger); Options = new LibuvTransportOptions { ThreadCount = 1 }; } From af636fc8d4870aeba5b892cdcd3994a5d956c475 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Thu, 22 Mar 2018 21:56:53 -0700 Subject: [PATCH 1586/1662] Upgraded deps --- build/dependencies.props | 64 ++++++++++++++++++++-------------------- 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/build/dependencies.props b/build/dependencies.props index 6916e0189a..06d2332fae 100644 --- a/build/dependencies.props +++ b/build/dependencies.props @@ -4,41 +4,41 @@ - 0.10.11 - 2.1.0-preview2-15728 + 0.10.13 + 2.1.0-preview2-15742 1.10.0 - 2.1.0-preview2-30301 - 2.1.0-preview2-30301 - 2.1.0-preview2-30301 - 2.1.0-preview2-30301 - 2.1.0-preview2-30301 - 2.1.0-preview2-30301 - 2.1.0-preview2-30301 - 2.1.0-preview2-30301 - 2.1.0-preview2-30301 - 2.1.0-preview2-30301 - 2.1.0-preview2-30301 - 2.1.0-preview2-30301 - 2.1.0-preview2-30301 - 2.1.0-preview2-30301 - 2.1.0-preview2-30301 - 2.1.0-preview2-30301 - 2.1.0-preview2-30301 - 2.1.0-preview2-30301 - 2.1.0-preview2-30301 + 2.1.0-preview3-32017 + 2.1.0-preview3-32017 + 2.1.0-preview3-32017 + 2.1.0-preview3-32017 + 2.1.0-preview3-32017 + 2.1.0-preview3-32017 + 2.1.0-preview3-32017 + 2.1.0-preview3-32017 + 2.1.0-preview3-32017 + 2.1.0-preview3-32017 + 2.1.0-preview3-32017 + 2.1.0-preview3-32017 + 2.1.0-preview3-32017 + 2.1.0-preview3-32017 + 2.1.0-preview3-32017 + 2.1.0-preview3-32017 + 2.1.0-preview3-32017 + 2.1.0-preview3-32017 + 2.1.0-preview3-32017 2.0.0 - 2.1.0-preview2-26308-01 - 2.1.0-preview2-30301 - 15.6.0 + 2.1.0-preview2-26314-02 + 2.1.0-preview3-32017 + 15.6.1 4.7.49 - 10.0.1 - 4.5.0-preview2-26313-02 - 4.5.0-preview2-26313-02 - 4.5.0-preview2-26313-02 - 4.5.0-preview2-26313-02 - 4.5.0-preview2-26313-02 - 4.5.0-preview2-26313-02 - 4.5.0-preview2-26313-02 + 11.0.1 + 4.5.0-preview2-26313-01 + 4.5.0-preview2-26313-01 + 4.5.0-preview2-26313-01 + 4.5.0-preview2-26313-01 + 4.5.0-preview2-26313-01 + 4.5.0-preview2-26313-01 + 4.5.0-preview2-26313-01 0.8.0 2.3.1 2.4.0-beta.1.build3945 From 967b0dd0a4fa16a6a2ed1002914fe5a7b00e5883 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Thu, 22 Mar 2018 23:39:48 -0700 Subject: [PATCH 1587/1662] Fixed dependencies --- build/dependencies.props | 41 ++++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/build/dependencies.props b/build/dependencies.props index 06d2332fae..595fb0e5dd 100644 --- a/build/dependencies.props +++ b/build/dependencies.props @@ -7,28 +7,29 @@ 0.10.13 2.1.0-preview2-15742 1.10.0 - 2.1.0-preview3-32017 - 2.1.0-preview3-32017 - 2.1.0-preview3-32017 - 2.1.0-preview3-32017 - 2.1.0-preview3-32017 - 2.1.0-preview3-32017 - 2.1.0-preview3-32017 - 2.1.0-preview3-32017 - 2.1.0-preview3-32017 - 2.1.0-preview3-32017 - 2.1.0-preview3-32017 - 2.1.0-preview3-32017 - 2.1.0-preview3-32017 - 2.1.0-preview3-32017 - 2.1.0-preview3-32017 - 2.1.0-preview3-32017 - 2.1.0-preview3-32017 - 2.1.0-preview3-32017 - 2.1.0-preview3-32017 + 2.1.0-preview3-32019 + 2.1.0-preview3-32019 + 2.1.0-preview3-32019 + 2.1.0-preview3-32019 + 2.1.0-preview3-32019 + 2.1.0-preview3-32019 + 2.1.0-preview3-32019 + 2.1.0-preview3-32019 + 2.1.0-preview3-32019 + 2.1.0-preview3-32019 + 2.1.0-preview3-32019 + 2.1.0-preview3-32019 + 2.1.0-preview3-32019 + 2.1.0-preview3-32019 + 2.1.0-preview3-32019 + 2.1.0-preview3-32019 + 2.1.0-preview3-32019 + 2.1.0-preview3-32019 + 2.1.0-preview3-32019 + 2.1.0-preview3-32019 2.0.0 2.1.0-preview2-26314-02 - 2.1.0-preview3-32017 + 2.1.0-preview3-32019 15.6.1 4.7.49 11.0.1 From 408700698c1d46de5d67dc4780a65d68312232db Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Tue, 20 Mar 2018 12:19:20 -0700 Subject: [PATCH 1588/1662] React to aspnet/BuildTools#611 (#2409) --- test/SystemdActivation/docker.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/SystemdActivation/docker.sh b/test/SystemdActivation/docker.sh index 28560cf69f..f2ba5fe506 100644 --- a/test/SystemdActivation/docker.sh +++ b/test/SystemdActivation/docker.sh @@ -3,10 +3,10 @@ set -e scriptDir=$(dirname "${BASH_SOURCE[0]}") -PATH="$HOME/.dotnet/:$PATH" +PATH="$PWD/.dotnet/:$PATH" dotnet publish -f netcoreapp2.0 ./samples/SystemdTestApp/ cp -R ./samples/SystemdTestApp/bin/Debug/netcoreapp2.0/publish/ $scriptDir -cp -R ~/.dotnet/ $scriptDir +cp -R ./.dotnet/ $scriptDir image=$(docker build -qf $scriptDir/Dockerfile $scriptDir) container=$(docker run -Pd $image) From 63fd1e1a4d2371778ff90a31632728efefe66cc9 Mon Sep 17 00:00:00 2001 From: John Luo Date: Thu, 22 Mar 2018 18:52:42 -0700 Subject: [PATCH 1589/1662] Re-enable api check - Disable api check for Transport.Libuv due to breaking change - Add empty baseline files for unreleased packages --- Directory.Build.props | 2 - .../baseline.netcore.json | 2 + .../Kestrel.Transport.Libuv.csproj | 1 + .../baseline.netcore.json | 109 ------------------ 4 files changed, 3 insertions(+), 111 deletions(-) create mode 100644 src/Connections.Abstractions/baseline.netcore.json diff --git a/Directory.Build.props b/Directory.Build.props index ca80f126d5..170752b08d 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -17,7 +17,5 @@ true true latest - - false diff --git a/src/Connections.Abstractions/baseline.netcore.json b/src/Connections.Abstractions/baseline.netcore.json new file mode 100644 index 0000000000..7a73a41bfd --- /dev/null +++ b/src/Connections.Abstractions/baseline.netcore.json @@ -0,0 +1,2 @@ +{ +} \ No newline at end of file diff --git a/src/Kestrel.Transport.Libuv/Kestrel.Transport.Libuv.csproj b/src/Kestrel.Transport.Libuv/Kestrel.Transport.Libuv.csproj index bef2f77e60..3ae5b90b2b 100644 --- a/src/Kestrel.Transport.Libuv/Kestrel.Transport.Libuv.csproj +++ b/src/Kestrel.Transport.Libuv/Kestrel.Transport.Libuv.csproj @@ -9,6 +9,7 @@ aspnetcore;kestrel true CS1591;$(NoWarn) + false diff --git a/src/Kestrel.Transport.Sockets/baseline.netcore.json b/src/Kestrel.Transport.Sockets/baseline.netcore.json index 33448b164f..7a73a41bfd 100644 --- a/src/Kestrel.Transport.Sockets/baseline.netcore.json +++ b/src/Kestrel.Transport.Sockets/baseline.netcore.json @@ -1,111 +1,2 @@ { - "AssemblyIdentity": "Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets, Version=2.0.2.0, Culture=neutral, PublicKeyToken=adb9793829ddae60", - "Types": [ - { - "Name": "Microsoft.AspNetCore.Hosting.WebHostBuilderSocketExtensions", - "Visibility": "Public", - "Kind": "Class", - "Abstract": true, - "Static": true, - "Sealed": true, - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Method", - "Name": "UseSockets", - "Parameters": [ - { - "Name": "hostBuilder", - "Type": "Microsoft.AspNetCore.Hosting.IWebHostBuilder" - } - ], - "ReturnType": "Microsoft.AspNetCore.Hosting.IWebHostBuilder", - "Static": true, - "Extension": true, - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Method", - "Name": "UseSockets", - "Parameters": [ - { - "Name": "hostBuilder", - "Type": "Microsoft.AspNetCore.Hosting.IWebHostBuilder" - }, - { - "Name": "configureOptions", - "Type": "System.Action" - } - ], - "ReturnType": "Microsoft.AspNetCore.Hosting.IWebHostBuilder", - "Static": true, - "Extension": true, - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.SocketTransportFactory", - "Visibility": "Public", - "Kind": "Class", - "Sealed": true, - "ImplementedInterfaces": [ - "Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal.ITransportFactory" - ], - "Members": [ - { - "Kind": "Method", - "Name": "Create", - "Parameters": [ - { - "Name": "endPointInformation", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal.IEndPointInformation" - }, - { - "Name": "handler", - "Type": "Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal.IConnectionHandler" - } - ], - "ReturnType": "Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal.ITransport", - "Sealed": true, - "Virtual": true, - "ImplementedInterface": "Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal.ITransportFactory", - "Visibility": "Public", - "GenericParameter": [] - }, - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [ - { - "Name": "options", - "Type": "Microsoft.Extensions.Options.IOptions" - } - ], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - }, - { - "Name": "Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.SocketTransportOptions", - "Visibility": "Public", - "Kind": "Class", - "ImplementedInterfaces": [], - "Members": [ - { - "Kind": "Constructor", - "Name": ".ctor", - "Parameters": [], - "Visibility": "Public", - "GenericParameter": [] - } - ], - "GenericParameters": [] - } - ] } \ No newline at end of file From 6701339835adfa1efd84eab6c696fea4e358c2a2 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Sat, 24 Mar 2018 03:12:53 -0700 Subject: [PATCH 1590/1662] Expose DefaultConnectionContext POCO (#2421) - Made TransportConnecton derive from ConnectionContext - Less objects, less opinions about what the ConnectionContext is. This diverges from what we do with HttpContext but it seems better overall. - Made DefaultConnectionContext - Usable for unit testing - Usable for benchmarking --- .../ConnectionItems.cs | 7 +- .../DefaultConnectionContext.cs | 77 +++++++++++-------- .../Internal/ConnectionListener.cs | 2 +- .../Internal/TransportConnection.cs | 12 ++- 4 files changed, 56 insertions(+), 42 deletions(-) rename src/{Kestrel.Transport.Abstractions/Internal => Connections.Abstractions}/ConnectionItems.cs (95%) diff --git a/src/Kestrel.Transport.Abstractions/Internal/ConnectionItems.cs b/src/Connections.Abstractions/ConnectionItems.cs similarity index 95% rename from src/Kestrel.Transport.Abstractions/Internal/ConnectionItems.cs rename to src/Connections.Abstractions/ConnectionItems.cs index adb346df81..0f01a62111 100644 --- a/src/Kestrel.Transport.Abstractions/Internal/ConnectionItems.cs +++ b/src/Connections.Abstractions/ConnectionItems.cs @@ -3,11 +3,12 @@ using System; using System.Collections; +using System.Collections.Concurrent; using System.Collections.Generic; -namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal +namespace Microsoft.AspNetCore.Connections { - internal class ConnectionItems : IDictionary + public class ConnectionItems : IDictionary { public ConnectionItems() : this(new Dictionary()) @@ -115,4 +116,4 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal return Items.GetEnumerator(); } } -} \ No newline at end of file +} diff --git a/src/Connections.Abstractions/DefaultConnectionContext.cs b/src/Connections.Abstractions/DefaultConnectionContext.cs index 920efba18b..33607c0a5c 100644 --- a/src/Connections.Abstractions/DefaultConnectionContext.cs +++ b/src/Connections.Abstractions/DefaultConnectionContext.cs @@ -1,55 +1,64 @@ -using System.Collections.Generic; +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Collections.Generic; using System.IO.Pipelines; +using System.Security.Claims; +using System.Threading; +using System.Threading.Tasks; using Microsoft.AspNetCore.Http.Features; +using Microsoft.AspNetCore.Connections; using Microsoft.AspNetCore.Connections.Features; namespace Microsoft.AspNetCore.Connections { - public class DefaultConnectionContext : ConnectionContext + public class DefaultConnectionContext : ConnectionContext, + IConnectionIdFeature, + IConnectionItemsFeature, + IConnectionTransportFeature, + IApplicationTransportFeature, + IConnectionUserFeature { - private FeatureReferences _features; - - public DefaultConnectionContext(IFeatureCollection features) + public DefaultConnectionContext() : + this(Guid.NewGuid().ToString()) { - _features = new FeatureReferences(features); } - private IConnectionIdFeature ConnectionIdFeature => - _features.Fetch(ref _features.Cache.ConnectionId, _ => null); - - private IConnectionTransportFeature ConnectionTransportFeature => - _features.Fetch(ref _features.Cache.ConnectionTransport, _ => null); - - private IConnectionItemsFeature ConnectionItemsFeature => - _features.Fetch(ref _features.Cache.ConnectionItems, _ => null); - - public override string ConnectionId + /// + /// Creates the DefaultConnectionContext without Pipes to avoid upfront allocations. + /// The caller is expected to set the and pipes manually. + /// + /// + public DefaultConnectionContext(string id) { - get => ConnectionIdFeature.ConnectionId; - set => ConnectionIdFeature.ConnectionId = value; + ConnectionId = id; + + Features = new FeatureCollection(); + Features.Set(this); + Features.Set(this); + Features.Set(this); + Features.Set(this); + Features.Set(this); } - public override IFeatureCollection Features => _features.Collection; - - public override IDuplexPipe Transport + public DefaultConnectionContext(string id, IDuplexPipe transport, IDuplexPipe application) + : this(id) { - get => ConnectionTransportFeature.Transport; - set => ConnectionTransportFeature.Transport = value; + Transport = transport; + Application = application; } - public override IDictionary Items - { - get => ConnectionItemsFeature.Items; - set => ConnectionItemsFeature.Items = value; - } + public override string ConnectionId { get; set; } - struct FeatureInterfaces - { - public IConnectionIdFeature ConnectionId; + public override IFeatureCollection Features { get; } - public IConnectionTransportFeature ConnectionTransport; + public ClaimsPrincipal User { get; set; } - public IConnectionItemsFeature ConnectionItems; - } + public override IDictionary Items { get; set; } = new ConnectionItems(); + + public IDuplexPipe Application { get; set; } + + public override IDuplexPipe Transport { get; set; } } } diff --git a/src/Kestrel.Core/Internal/ConnectionListener.cs b/src/Kestrel.Core/Internal/ConnectionListener.cs index d3daa84158..abbbe6b50d 100644 --- a/src/Kestrel.Core/Internal/ConnectionListener.cs +++ b/src/Kestrel.Core/Internal/ConnectionListener.cs @@ -46,7 +46,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal // REVIEW: This task should be tracked by the server for graceful shutdown // Today it's handled specifically for http but not for aribitrary middleware - _ = Execute(new DefaultConnectionContext(connection)); + _ = Execute(connection); } private async Task Execute(ConnectionContext connectionContext) diff --git a/src/Kestrel.Transport.Abstractions/Internal/TransportConnection.cs b/src/Kestrel.Transport.Abstractions/Internal/TransportConnection.cs index b753dae64a..c3d014ea57 100644 --- a/src/Kestrel.Transport.Abstractions/Internal/TransportConnection.cs +++ b/src/Kestrel.Transport.Abstractions/Internal/TransportConnection.cs @@ -3,10 +3,12 @@ using System.Collections.Generic; using System.IO.Pipelines; using System.Net; using System.Threading; +using Microsoft.AspNetCore.Connections; +using Microsoft.AspNetCore.Http.Features; namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal { - public abstract partial class TransportConnection + public abstract partial class TransportConnection : ConnectionContext { private IDictionary _items; @@ -26,16 +28,18 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal public IPAddress LocalAddress { get; set; } public int LocalPort { get; set; } - public string ConnectionId { get; set; } + public override string ConnectionId { get; set; } + + public override IFeatureCollection Features => this; public virtual MemoryPool MemoryPool { get; } public virtual PipeScheduler InputWriterScheduler { get; } public virtual PipeScheduler OutputReaderScheduler { get; } - public IDuplexPipe Transport { get; set; } + public override IDuplexPipe Transport { get; set; } public IDuplexPipe Application { get; set; } - public IDictionary Items + public override IDictionary Items { get { From 8b13ab8485b26a67d6923498142f94cb89fe8408 Mon Sep 17 00:00:00 2001 From: "ASP.NET CI" Date: Sun, 25 Mar 2018 15:45:27 -0700 Subject: [PATCH 1591/1662] Update dependencies.props [auto-updated: dependencies] --- build/dependencies.props | 44 ++++++++++++++++++++-------------------- korebuild-lock.txt | 4 ++-- 2 files changed, 24 insertions(+), 24 deletions(-) diff --git a/build/dependencies.props b/build/dependencies.props index 595fb0e5dd..0365181477 100644 --- a/build/dependencies.props +++ b/build/dependencies.props @@ -5,31 +5,31 @@ 0.10.13 - 2.1.0-preview2-15742 + 2.1.0-preview3-17001 1.10.0 - 2.1.0-preview3-32019 - 2.1.0-preview3-32019 - 2.1.0-preview3-32019 - 2.1.0-preview3-32019 - 2.1.0-preview3-32019 - 2.1.0-preview3-32019 - 2.1.0-preview3-32019 - 2.1.0-preview3-32019 - 2.1.0-preview3-32019 - 2.1.0-preview3-32019 - 2.1.0-preview3-32019 - 2.1.0-preview3-32019 - 2.1.0-preview3-32019 - 2.1.0-preview3-32019 - 2.1.0-preview3-32019 - 2.1.0-preview3-32019 - 2.1.0-preview3-32019 - 2.1.0-preview3-32019 - 2.1.0-preview3-32019 - 2.1.0-preview3-32019 + 2.1.0-preview3-32037 + 2.1.0-preview3-32037 + 2.1.0-preview3-32037 + 2.1.0-preview3-32037 + 2.1.0-preview3-32037 + 2.1.0-preview3-32037 + 2.1.0-preview3-32037 + 2.1.0-preview3-32037 + 2.1.0-preview3-32037 + 2.1.0-preview3-32037 + 2.1.0-preview3-32037 + 2.1.0-preview3-32037 + 2.1.0-preview3-32037 + 2.1.0-preview3-32037 + 2.1.0-preview3-32037 + 2.1.0-preview3-32037 + 2.1.0-preview3-32037 + 2.1.0-preview3-32037 + 2.1.0-preview3-32037 + 2.1.0-preview3-32037 2.0.0 2.1.0-preview2-26314-02 - 2.1.0-preview3-32019 + 2.1.0-preview3-32037 15.6.1 4.7.49 11.0.1 diff --git a/korebuild-lock.txt b/korebuild-lock.txt index e40ef6651b..3a326c7d58 100644 --- a/korebuild-lock.txt +++ b/korebuild-lock.txt @@ -1,2 +1,2 @@ -version:2.1.0-preview2-15742 -commithash:21fbb0f2c3fe4a9216e2d59632b98cfd7d685962 +version:2.1.0-preview3-17001 +commithash:dda68c56abf0d3b911fe6a2315872c446b314585 From a1de323ff4346a1ae8640db7535fd76f2f6eecc9 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Mon, 26 Mar 2018 11:39:51 -0700 Subject: [PATCH 1592/1662] Make LibuvTransport(Factory) pubternal (#2426) --- .../{ => Internal}/LibuvTransport.cs | 3 +-- .../{ => Internal}/LibuvTransportFactory.cs | 3 +-- .../Kestrel.Transport.Libuv.csproj | 1 - .../WebHostBuilderLibuvExtensions.cs | 1 + .../breakingchanges.netcore.json | 10 ++++++++++ .../WebHostBuilderKestrelExtensionsTests.cs | 2 +- .../LibuvTransportFactoryTests.cs | 1 + .../LibuvTransportTests.cs | 3 +-- 8 files changed, 16 insertions(+), 8 deletions(-) rename src/Kestrel.Transport.Libuv/{ => Internal}/LibuvTransport.cs (97%) rename src/Kestrel.Transport.Libuv/{ => Internal}/LibuvTransportFactory.cs (95%) create mode 100644 src/Kestrel.Transport.Libuv/breakingchanges.netcore.json diff --git a/src/Kestrel.Transport.Libuv/LibuvTransport.cs b/src/Kestrel.Transport.Libuv/Internal/LibuvTransport.cs similarity index 97% rename from src/Kestrel.Transport.Libuv/LibuvTransport.cs rename to src/Kestrel.Transport.Libuv/Internal/LibuvTransport.cs index 35def2dc55..293745f38b 100644 --- a/src/Kestrel.Transport.Libuv/LibuvTransport.cs +++ b/src/Kestrel.Transport.Libuv/Internal/LibuvTransport.cs @@ -8,11 +8,10 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Connections; using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; -using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal; using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking; using Microsoft.Extensions.Logging; -namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv +namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal { public class LibuvTransport : ITransport { diff --git a/src/Kestrel.Transport.Libuv/LibuvTransportFactory.cs b/src/Kestrel.Transport.Libuv/Internal/LibuvTransportFactory.cs similarity index 95% rename from src/Kestrel.Transport.Libuv/LibuvTransportFactory.cs rename to src/Kestrel.Transport.Libuv/Internal/LibuvTransportFactory.cs index 418f43abd8..c2ff9e8a56 100644 --- a/src/Kestrel.Transport.Libuv/LibuvTransportFactory.cs +++ b/src/Kestrel.Transport.Libuv/Internal/LibuvTransportFactory.cs @@ -4,11 +4,10 @@ using System; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; -using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; -namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv +namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal { public class LibuvTransportFactory : ITransportFactory { diff --git a/src/Kestrel.Transport.Libuv/Kestrel.Transport.Libuv.csproj b/src/Kestrel.Transport.Libuv/Kestrel.Transport.Libuv.csproj index 3ae5b90b2b..bef2f77e60 100644 --- a/src/Kestrel.Transport.Libuv/Kestrel.Transport.Libuv.csproj +++ b/src/Kestrel.Transport.Libuv/Kestrel.Transport.Libuv.csproj @@ -9,7 +9,6 @@ aspnetcore;kestrel true CS1591;$(NoWarn) - false diff --git a/src/Kestrel.Transport.Libuv/WebHostBuilderLibuvExtensions.cs b/src/Kestrel.Transport.Libuv/WebHostBuilderLibuvExtensions.cs index 3d7f2fe3ae..386d0b6679 100644 --- a/src/Kestrel.Transport.Libuv/WebHostBuilderLibuvExtensions.cs +++ b/src/Kestrel.Transport.Libuv/WebHostBuilderLibuvExtensions.cs @@ -4,6 +4,7 @@ using System; using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal; using Microsoft.Extensions.DependencyInjection; namespace Microsoft.AspNetCore.Hosting diff --git a/src/Kestrel.Transport.Libuv/breakingchanges.netcore.json b/src/Kestrel.Transport.Libuv/breakingchanges.netcore.json new file mode 100644 index 0000000000..bb70d76ea8 --- /dev/null +++ b/src/Kestrel.Transport.Libuv/breakingchanges.netcore.json @@ -0,0 +1,10 @@ +[ + { + "TypeId": "public class Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.LibuvTransport : Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal.ITransport", + "Kind": "Removal" + }, + { + "TypeId": "public class Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.LibuvTransportFactory : Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal.ITransportFactory", + "Kind": "Removal" + } +] diff --git a/test/Kestrel.Tests/WebHostBuilderKestrelExtensionsTests.cs b/test/Kestrel.Tests/WebHostBuilderKestrelExtensionsTests.cs index bc0eff8af8..7ea16d4c85 100644 --- a/test/Kestrel.Tests/WebHostBuilderKestrelExtensionsTests.cs +++ b/test/Kestrel.Tests/WebHostBuilderKestrelExtensionsTests.cs @@ -4,7 +4,7 @@ using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; -using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal; using Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets; using Microsoft.Extensions.DependencyInjection; using Xunit; diff --git a/test/Kestrel.Transport.Libuv.Tests/LibuvTransportFactoryTests.cs b/test/Kestrel.Transport.Libuv.Tests/LibuvTransportFactoryTests.cs index 1e80201397..2db383f941 100644 --- a/test/Kestrel.Transport.Libuv.Tests/LibuvTransportFactoryTests.cs +++ b/test/Kestrel.Transport.Libuv.Tests/LibuvTransportFactoryTests.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal; using Microsoft.AspNetCore.Testing; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; diff --git a/test/Kestrel.Transport.Libuv.Tests/LibuvTransportTests.cs b/test/Kestrel.Transport.Libuv.Tests/LibuvTransportTests.cs index 388f78e3ba..4d2be2380c 100644 --- a/test/Kestrel.Transport.Libuv.Tests/LibuvTransportTests.cs +++ b/test/Kestrel.Transport.Libuv.Tests/LibuvTransportTests.cs @@ -1,19 +1,18 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System; using System.Collections.Generic; using System.Linq; using System.Net; using System.Net.Http; using System.Net.Sockets; using System.Text; -using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal; using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests.TestHelpers; using Microsoft.AspNetCore.Testing; using Microsoft.AspNetCore.Testing.xunit; From be04ccac6e1c445fc2b8ca125839d9aa8528a647 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Tue, 27 Mar 2018 02:02:15 -0700 Subject: [PATCH 1593/1662] Move DuplexPipe into Kestrel.Core as internal (#2428) --- .../Internal}/DuplexPipe.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename src/{Connections.Abstractions => Kestrel.Core/Internal}/DuplexPipe.cs (96%) diff --git a/src/Connections.Abstractions/DuplexPipe.cs b/src/Kestrel.Core/Internal/DuplexPipe.cs similarity index 96% rename from src/Connections.Abstractions/DuplexPipe.cs rename to src/Kestrel.Core/Internal/DuplexPipe.cs index e7a6ad1710..adc18c8c7d 100644 --- a/src/Connections.Abstractions/DuplexPipe.cs +++ b/src/Kestrel.Core/Internal/DuplexPipe.cs @@ -2,7 +2,7 @@ namespace System.IO.Pipelines { - public class DuplexPipe : IDuplexPipe + internal class DuplexPipe : IDuplexPipe { public DuplexPipe(PipeReader reader, PipeWriter writer) { From 2bceac304b75fbf0d377e52289065eed5c60effb Mon Sep 17 00:00:00 2001 From: "Nate McMaster (automated)" Date: Wed, 28 Mar 2018 10:52:25 -0700 Subject: [PATCH 1594/1662] Update dependencies.props [auto-updated: dependencies] --- build/dependencies.props | 64 ++++++++++++++++++++-------------------- korebuild-lock.txt | 4 +-- 2 files changed, 34 insertions(+), 34 deletions(-) diff --git a/build/dependencies.props b/build/dependencies.props index ad44b59226..db44bbd005 100644 --- a/build/dependencies.props +++ b/build/dependencies.props @@ -5,41 +5,41 @@ 0.10.13 - 2.1.0-preview2-15742 + 2.1.0-preview2-15749 1.10.0 - 2.1.0-preview2-30355 - 2.1.0-preview2-30355 - 2.1.0-preview2-30355 - 2.1.0-preview2-30355 - 2.1.0-preview2-30355 - 2.1.0-preview2-30355 - 2.1.0-preview2-30355 - 2.1.0-preview2-30355 - 2.1.0-preview2-30355 - 2.1.0-preview2-30355 - 2.1.0-preview2-30355 - 2.1.0-preview2-30355 - 2.1.0-preview2-30355 - 2.1.0-preview2-30355 - 2.1.0-preview2-30355 - 2.1.0-preview2-30355 - 2.1.0-preview2-30355 - 2.1.0-preview2-30355 - 2.1.0-preview2-30355 - 2.1.0-preview2-30355 + 2.1.0-preview2-30478 + 2.1.0-preview2-30478 + 2.1.0-preview2-30478 + 2.1.0-preview2-30478 + 2.1.0-preview2-30478 + 2.1.0-preview2-30478 + 2.1.0-preview2-30478 + 2.1.0-preview2-30478 + 2.1.0-preview2-30478 + 2.1.0-preview2-30478 + 2.1.0-preview2-30478 + 2.1.0-preview2-30478 + 2.1.0-preview2-30478 + 2.1.0-preview2-30478 + 2.1.0-preview2-30478 + 2.1.0-preview2-30478 + 2.1.0-preview2-30478 + 2.1.0-preview2-30478 + 2.1.0-preview2-30478 + 2.1.0-preview2-30478 2.0.0 - 2.1.0-preview2-26314-02 - 2.1.0-preview2-30355 - 15.6.0 + 2.1.0-preview2-26326-03 + 2.1.0-preview2-30478 + 15.6.1 4.7.49 - 10.0.1 - 4.5.0-preview2-26313-01 - 4.5.0-preview2-26313-01 - 4.5.0-preview2-26313-01 - 4.5.0-preview2-26313-01 - 4.5.0-preview2-26313-01 - 4.5.0-preview2-26313-01 - 4.5.0-preview2-26313-01 + 11.0.2 + 4.5.0-preview2-26326-04 + 4.5.0-preview2-26326-04 + 4.5.0-preview2-26326-04 + 4.5.0-preview2-26326-04 + 4.5.0-preview2-26326-04 + 4.5.0-preview2-26326-04 + 4.5.0-preview2-26326-04 0.8.0 2.3.1 2.4.0-beta.1.build3945 diff --git a/korebuild-lock.txt b/korebuild-lock.txt index e40ef6651b..b8e036fe2c 100644 --- a/korebuild-lock.txt +++ b/korebuild-lock.txt @@ -1,2 +1,2 @@ -version:2.1.0-preview2-15742 -commithash:21fbb0f2c3fe4a9216e2d59632b98cfd7d685962 +version:2.1.0-preview2-15749 +commithash:5544c9ab20fa5e24b9e155d8958a3c3b6f5f9df9 From 59bacd46e4aeb2dacc74d35813ecfa05762d4f13 Mon Sep 17 00:00:00 2001 From: Ryan Brandenburg Date: Tue, 27 Mar 2018 16:09:57 -0700 Subject: [PATCH 1595/1662] Skip flaky test --- test/Kestrel.FunctionalTests/RequestTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Kestrel.FunctionalTests/RequestTests.cs b/test/Kestrel.FunctionalTests/RequestTests.cs index 8aefc5f786..7344c56784 100644 --- a/test/Kestrel.FunctionalTests/RequestTests.cs +++ b/test/Kestrel.FunctionalTests/RequestTests.cs @@ -145,7 +145,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests return TestRemoteIPAddress("127.0.0.1", "127.0.0.1", "127.0.0.1"); } - [ConditionalFact] + [ConditionalFact(Skip="https://github.com/aspnet/KestrelHttpServer/issues/2406")] [IPv6SupportedCondition] public Task RemoteIPv6Address() { From cc8c140cca21b52c3270e72662a404ee357eb18a Mon Sep 17 00:00:00 2001 From: Ryan Brandenburg Date: Tue, 27 Mar 2018 16:09:57 -0700 Subject: [PATCH 1596/1662] Skip flaky test --- test/Kestrel.FunctionalTests/RequestTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Kestrel.FunctionalTests/RequestTests.cs b/test/Kestrel.FunctionalTests/RequestTests.cs index 8aefc5f786..7344c56784 100644 --- a/test/Kestrel.FunctionalTests/RequestTests.cs +++ b/test/Kestrel.FunctionalTests/RequestTests.cs @@ -145,7 +145,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests return TestRemoteIPAddress("127.0.0.1", "127.0.0.1", "127.0.0.1"); } - [ConditionalFact] + [ConditionalFact(Skip="https://github.com/aspnet/KestrelHttpServer/issues/2406")] [IPv6SupportedCondition] public Task RemoteIPv6Address() { From 7b3491e11e5acdddc558ffa6d95c094e7f618a60 Mon Sep 17 00:00:00 2001 From: Pavel Krymets Date: Thu, 29 Mar 2018 20:27:54 -0700 Subject: [PATCH 1597/1662] Prepare to 0 byte flush change (#2442) --- test/Kestrel.Core.Tests/PipelineExtensionTests.cs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/test/Kestrel.Core.Tests/PipelineExtensionTests.cs b/test/Kestrel.Core.Tests/PipelineExtensionTests.cs index 485183ff85..e3a89832da 100644 --- a/test/Kestrel.Core.Tests/PipelineExtensionTests.cs +++ b/test/Kestrel.Core.Tests/PipelineExtensionTests.cs @@ -84,11 +84,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests [InlineData(null, new byte[0])] public void EncodesAsAscii(string input, byte[] expected) { - var writerBuffer = _pipe.Writer; - var writer = new BufferWriter(writerBuffer); + var pipeWriter = _pipe.Writer; + var writer = new BufferWriter(pipeWriter); writer.WriteAsciiNoValidation(input); writer.Commit(); - writerBuffer.FlushAsync().GetAwaiter().GetResult(); + pipeWriter.FlushAsync().GetAwaiter().GetResult(); + pipeWriter.Complete(); + var reader = _pipe.Reader.ReadAsync().GetAwaiter().GetResult(); if (expected.Length > 0) From 67cb8a0e1178e00197725cb7d7a2214841358cfb Mon Sep 17 00:00:00 2001 From: David Fowler Date: Fri, 30 Mar 2018 15:20:31 -0700 Subject: [PATCH 1598/1662] Add IConnection to Connections.Abstractions (#2444) --- src/Connections.Abstractions/IConnection.cs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 src/Connections.Abstractions/IConnection.cs diff --git a/src/Connections.Abstractions/IConnection.cs b/src/Connections.Abstractions/IConnection.cs new file mode 100644 index 0000000000..4f116a8433 --- /dev/null +++ b/src/Connections.Abstractions/IConnection.cs @@ -0,0 +1,17 @@ +using System.Collections.Generic; +using System.IO.Pipelines; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Http.Features; + +namespace Microsoft.AspNetCore.Connections +{ + public interface IConnection + { + IDuplexPipe Transport { get; } + IFeatureCollection Features { get; } + + Task StartAsync(); + Task StartAsync(TransferFormat transferFormat); + Task DisposeAsync(); + } +} From 73821983567625b2eef5cf239db034ef81dd5dc1 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Sat, 31 Mar 2018 07:29:35 -0700 Subject: [PATCH 1599/1662] Copy connection middleware when using ListenLocalHost (#2447) - Connection middleware got removed during Clone when using ListenLocalhost --- src/Kestrel.Core/ListenOptions.cs | 8 ++--- src/Kestrel.Core/LocalhostListenOptions.cs | 4 ++- test/Kestrel.Core.Tests/ListenOptionsTests.cs | 34 +++++++++++++++++++ 3 files changed, 41 insertions(+), 5 deletions(-) diff --git a/src/Kestrel.Core/ListenOptions.cs b/src/Kestrel.Core/ListenOptions.cs index bdef463d60..dfc15ad1ae 100644 --- a/src/Kestrel.Core/ListenOptions.cs +++ b/src/Kestrel.Core/ListenOptions.cs @@ -24,7 +24,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core private FileHandleType _handleType; private HttpProtocols _protocols = HttpProtocols.Http1; internal bool _isHttp2Supported; - private readonly List> _components = new List>(); + internal readonly List> _middleware = new List>(); internal ListenOptions(IPEndPoint endPoint) { @@ -181,7 +181,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core public IConnectionBuilder Use(Func middleware) { - _components.Add(middleware); + _middleware.Add(middleware); return this; } @@ -192,9 +192,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core return Task.CompletedTask; }; - for (int i = _components.Count - 1; i >= 0; i--) + for (int i = _middleware.Count - 1; i >= 0; i--) { - var component = _components[i]; + var component = _middleware[i]; app = component(app); } diff --git a/src/Kestrel.Core/LocalhostListenOptions.cs b/src/Kestrel.Core/LocalhostListenOptions.cs index 39c49abbfc..ee28dce63e 100644 --- a/src/Kestrel.Core/LocalhostListenOptions.cs +++ b/src/Kestrel.Core/LocalhostListenOptions.cs @@ -72,7 +72,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core } // used for cloning to two IPEndpoints - private ListenOptions Clone(IPAddress address) + internal ListenOptions Clone(IPAddress address) { var options = new ListenOptions(new IPEndPoint(address, IPEndPoint.Port)) { @@ -81,6 +81,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core NoDelay = NoDelay, Protocols = Protocols, }; + + options._middleware.AddRange(_middleware); options.ConnectionAdapters.AddRange(ConnectionAdapters); return options; } diff --git a/test/Kestrel.Core.Tests/ListenOptionsTests.cs b/test/Kestrel.Core.Tests/ListenOptionsTests.cs index 808d4e6cdd..6b4f792f13 100644 --- a/test/Kestrel.Core.Tests/ListenOptionsTests.cs +++ b/test/Kestrel.Core.Tests/ListenOptionsTests.cs @@ -3,6 +3,10 @@ using System; using System.Net; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal; +using Microsoft.AspNetCore.Testing; +using Microsoft.Extensions.DependencyInjection; using Xunit; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests @@ -25,5 +29,35 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests ex = Assert.Throws(() => listenOptions.Protocols = HttpProtocols.Http2); Assert.Equal(CoreStrings.Http2NotSupported, ex.Message); } + + [Fact] + public void LocalHostListenOptionsClonesConnectionMiddleware() + { + var localhostListenOptions = new LocalhostListenOptions(1004); + localhostListenOptions.ConnectionAdapters.Add(new PassThroughConnectionAdapter()); + var serviceProvider = new ServiceCollection().BuildServiceProvider(); + localhostListenOptions.KestrelServerOptions = new KestrelServerOptions() + { + ApplicationServices = serviceProvider + }; + var middlewareRan = false; + localhostListenOptions.Use(next => + { + middlewareRan = true; + return context => Task.CompletedTask; + }); + + var clone = localhostListenOptions.Clone(IPAddress.IPv6Loopback); + var app = clone.Build(); + + // Execute the delegate + app(null); + + Assert.True(middlewareRan); + Assert.NotNull(clone.KestrelServerOptions); + Assert.NotNull(serviceProvider); + Assert.Same(serviceProvider, clone.ApplicationServices); + Assert.Single(clone.ConnectionAdapters); + } } } From a37fa83aee400f621b1f19fca6a777bd3d804f6f Mon Sep 17 00:00:00 2001 From: David Fowler Date: Sun, 1 Apr 2018 00:04:02 -0700 Subject: [PATCH 1600/1662] Fixed a parser bug found when trying out the array pool (#2450) - When using the array pool, we get terrible block density and as a result the header parser was failing. - This fixes the case where the parser needed to skip 2 blocks at the end (which is unrealistic). Comparing the current index to the reader index is incorrect since we may end up at the same index in another segment. --- src/Kestrel.Core/Internal/Http/HttpParser.cs | 7 ++- test/Kestrel.Core.Tests/HttpParserTests.cs | 51 +++++++++++++++++++- 2 files changed, 54 insertions(+), 4 deletions(-) diff --git a/src/Kestrel.Core/Internal/Http/HttpParser.cs b/src/Kestrel.Core/Internal/Http/HttpParser.cs index 594757eb4c..b3d8d90d9c 100644 --- a/src/Kestrel.Core/Internal/Http/HttpParser.cs +++ b/src/Kestrel.Core/Internal/Http/HttpParser.cs @@ -213,6 +213,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http var index = reader.CurrentSegmentIndex; int ch1; int ch2; + var readAhead = false; // Fast path, we're still looking at the same span if (remaining >= 2) @@ -229,6 +230,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http // Possibly split across spans ch1 = reader.Read(); ch2 = reader.Read(); + + readAhead = true; } if (ch1 == ByteCR) @@ -244,7 +247,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { // If we got 2 bytes from the span directly so skip ahead 2 so that // the reader's state matches what we expect - if (index == reader.CurrentSegmentIndex) + if (!readAhead) { reader.Advance(2); } @@ -259,7 +262,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http // We moved the reader so look ahead 2 bytes so reset both the reader // and the index - if (index != reader.CurrentSegmentIndex) + if (readAhead) { reader = start; index = reader.CurrentSegmentIndex; diff --git a/test/Kestrel.Core.Tests/HttpParserTests.cs b/test/Kestrel.Core.Tests/HttpParserTests.cs index dec3c68681..f40c25669b 100644 --- a/test/Kestrel.Core.Tests/HttpParserTests.cs +++ b/test/Kestrel.Core.Tests/HttpParserTests.cs @@ -27,8 +27,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests string expectedMethod, string expectedRawTarget, string expectedRawPath, -// This warns that theory methods should use all of their parameters, -// but this method is using a shared data collection with Http1ConnectionTests.TakeStartLineSetsHttpProtocolProperties and others. + // This warns that theory methods should use all of their parameters, + // but this method is using a shared data collection with Http1ConnectionTests.TakeStartLineSetsHttpProtocolProperties and others. #pragma warning disable xUnit1026 string expectedDecodedPath, string expectedQueryString, @@ -386,6 +386,30 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests Assert.Equal(buffer.End, examined); } + [Fact] + public void ParseHeadersWithGratuitouslySplitBuffers() + { + var parser = CreateParser(_nullTrace); + var buffer = BytePerSegmentTestSequenceFactory.Instance.CreateWithContent("Host:\r\nConnection: keep-alive\r\n\r\n"); + + var requestHandler = new RequestHandler(); + var result = parser.ParseHeaders(requestHandler, buffer, out var consumed, out var examined, out _); + + Assert.True(result); + } + + [Fact] + public void ParseHeadersWithGratuitouslySplitBuffers2() + { + var parser = CreateParser(_nullTrace); + var buffer = BytePerSegmentTestSequenceFactory.Instance.CreateWithContent("A:B\r\nB: C\r\n\r\n"); + + var requestHandler = new RequestHandler(); + var result = parser.ParseHeaders(requestHandler, buffer, out var consumed, out var examined, out _); + + Assert.True(result); + } + private void VerifyHeader( string headerName, string rawHeaderValue, @@ -469,5 +493,28 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests PathEncoded = pathEncoded; } } + + // Doesn't put empty blocks inbetween every byte + internal class BytePerSegmentTestSequenceFactory : ReadOnlySequenceFactory + { + public static ReadOnlySequenceFactory Instance { get; } = new HttpParserTests.BytePerSegmentTestSequenceFactory(); + + public override ReadOnlySequence CreateOfSize(int size) + { + return CreateWithContent(new byte[size]); + } + + public override ReadOnlySequence CreateWithContent(byte[] data) + { + var segments = new List(); + + foreach (var b in data) + { + segments.Add(new[] { b }); + } + + return CreateSegments(segments.ToArray()); + } + } } } From 6b183c5ac0c4cea4444dd817f695811603e3da44 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Mon, 2 Apr 2018 16:14:40 -0700 Subject: [PATCH 1601/1662] Use 4K as the minimum segment size (#2452) - This normalizes the behavior for kestrel no matter what memory pool implementation is used. The transports should behave the same (ask for 1/2 full blocks) across pool implementations. - Declare the minimum segment size in KestrelMemoryPool - Updated the AdaptedPipeline to use MinimumSegmentSize / 2 --- src/Kestrel.Core/Adapter/Internal/AdaptedPipeline.cs | 5 +++-- .../{ConnectionListener.cs => ConnectionDispatcher.cs} | 6 ++++-- src/Kestrel.Core/Internal/Http/HttpProtocol.cs | 6 ++++-- src/Kestrel.Core/Internal/HttpConnection.cs | 7 +++++-- .../Internal/KestrelMemoryPool.cs | 2 ++ src/Kestrel.Transport.Libuv/Internal/LibuvConnection.cs | 2 +- src/Kestrel.Transport.Sockets/Internal/SocketConnection.cs | 4 ++-- 7 files changed, 21 insertions(+), 11 deletions(-) rename src/Kestrel.Core/Internal/{ConnectionListener.cs => ConnectionDispatcher.cs} (95%) diff --git a/src/Kestrel.Core/Adapter/Internal/AdaptedPipeline.cs b/src/Kestrel.Core/Adapter/Internal/AdaptedPipeline.cs index 522768e270..221c4c1b84 100644 --- a/src/Kestrel.Core/Adapter/Internal/AdaptedPipeline.cs +++ b/src/Kestrel.Core/Adapter/Internal/AdaptedPipeline.cs @@ -3,15 +3,16 @@ using System; using System.IO; +using System.IO.Pipelines; using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; -using System.IO.Pipelines; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal { public class AdaptedPipeline : IDuplexPipe { - private const int MinAllocBufferSize = 2048; + private static readonly int MinAllocBufferSize = KestrelMemoryPool.MinimumSegmentSize / 2; private readonly IDuplexPipe _transport; private readonly IDuplexPipe _application; diff --git a/src/Kestrel.Core/Internal/ConnectionListener.cs b/src/Kestrel.Core/Internal/ConnectionDispatcher.cs similarity index 95% rename from src/Kestrel.Core/Internal/ConnectionListener.cs rename to src/Kestrel.Core/Internal/ConnectionDispatcher.cs index abbbe6b50d..f2d512b955 100644 --- a/src/Kestrel.Core/Internal/ConnectionListener.cs +++ b/src/Kestrel.Core/Internal/ConnectionDispatcher.cs @@ -86,7 +86,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal writerScheduler: writerScheduler, pauseWriterThreshold: serviceContext.ServerOptions.Limits.MaxRequestBufferSize ?? 0, resumeWriterThreshold: serviceContext.ServerOptions.Limits.MaxRequestBufferSize ?? 0, - useSynchronizationContext: false + useSynchronizationContext: false, + minimumSegmentSize: KestrelMemoryPool.MinimumSegmentSize ); internal static PipeOptions GetOutputPipeOptions(ServiceContext serviceContext, MemoryPool memoryPool, PipeScheduler readerScheduler) => new PipeOptions @@ -96,7 +97,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal writerScheduler: serviceContext.Scheduler, pauseWriterThreshold: GetOutputResponseBufferSize(serviceContext), resumeWriterThreshold: GetOutputResponseBufferSize(serviceContext), - useSynchronizationContext: false + useSynchronizationContext: false, + minimumSegmentSize: KestrelMemoryPool.MinimumSegmentSize ); private static long GetOutputResponseBufferSize(ServiceContext serviceContext) diff --git a/src/Kestrel.Core/Internal/Http/HttpProtocol.cs b/src/Kestrel.Core/Internal/Http/HttpProtocol.cs index 6bb16e24df..da1416c1a3 100644 --- a/src/Kestrel.Core/Internal/Http/HttpProtocol.cs +++ b/src/Kestrel.Core/Internal/Http/HttpProtocol.cs @@ -13,11 +13,12 @@ using System.Runtime.CompilerServices; using System.Text; using System.Threading; using System.Threading.Tasks; +using Microsoft.AspNetCore.Connections; using Microsoft.AspNetCore.Hosting.Server; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http.Features; -using Microsoft.AspNetCore.Connections; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Primitives; @@ -1340,7 +1341,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http writerScheduler: PipeScheduler.Inline, pauseWriterThreshold: 1, resumeWriterThreshold: 1, - useSynchronizationContext: false + useSynchronizationContext: false, + minimumSegmentSize: KestrelMemoryPool.MinimumSegmentSize )); } } diff --git a/src/Kestrel.Core/Internal/HttpConnection.cs b/src/Kestrel.Core/Internal/HttpConnection.cs index fce572a414..91b0887f01 100644 --- a/src/Kestrel.Core/Internal/HttpConnection.cs +++ b/src/Kestrel.Core/Internal/HttpConnection.cs @@ -17,6 +17,7 @@ using Microsoft.AspNetCore.Server.Kestrel.Core.Features; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; using Microsoft.Extensions.Logging; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal @@ -78,7 +79,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal writerScheduler: PipeScheduler.Inline, pauseWriterThreshold: _context.ServiceContext.ServerOptions.Limits.MaxRequestBufferSize ?? 0, resumeWriterThreshold: _context.ServiceContext.ServerOptions.Limits.MaxRequestBufferSize ?? 0, - useSynchronizationContext: false + useSynchronizationContext: false, + minimumSegmentSize: KestrelMemoryPool.MinimumSegmentSize ); internal PipeOptions AdaptedOutputPipeOptions => new PipeOptions @@ -88,7 +90,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal writerScheduler: PipeScheduler.Inline, pauseWriterThreshold: _context.ServiceContext.ServerOptions.Limits.MaxResponseBufferSize ?? 0, resumeWriterThreshold: _context.ServiceContext.ServerOptions.Limits.MaxResponseBufferSize ?? 0, - useSynchronizationContext: false + useSynchronizationContext: false, + minimumSegmentSize: KestrelMemoryPool.MinimumSegmentSize ); private IKestrelTrace Log => _context.ServiceContext.Log; diff --git a/src/Kestrel.Transport.Abstractions/Internal/KestrelMemoryPool.cs b/src/Kestrel.Transport.Abstractions/Internal/KestrelMemoryPool.cs index 61a065c6eb..f53c15d543 100644 --- a/src/Kestrel.Transport.Abstractions/Internal/KestrelMemoryPool.cs +++ b/src/Kestrel.Transport.Abstractions/Internal/KestrelMemoryPool.cs @@ -8,5 +8,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal public static class KestrelMemoryPool { public static MemoryPool Create() => new SlabMemoryPool(); + + public static readonly int MinimumSegmentSize = 4096; } } diff --git a/src/Kestrel.Transport.Libuv/Internal/LibuvConnection.cs b/src/Kestrel.Transport.Libuv/Internal/LibuvConnection.cs index b6295aa568..00844e73a3 100644 --- a/src/Kestrel.Transport.Libuv/Internal/LibuvConnection.cs +++ b/src/Kestrel.Transport.Libuv/Internal/LibuvConnection.cs @@ -16,7 +16,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal { public partial class LibuvConnection : LibuvConnectionContext { - private const int MinAllocBufferSize = 2048; + private static readonly int MinAllocBufferSize = KestrelMemoryPool.MinimumSegmentSize / 2; private static readonly Action _readCallback = (handle, status, state) => ReadCallback(handle, status, state); diff --git a/src/Kestrel.Transport.Sockets/Internal/SocketConnection.cs b/src/Kestrel.Transport.Sockets/Internal/SocketConnection.cs index 726d0372ca..0f73ad2571 100644 --- a/src/Kestrel.Transport.Sockets/Internal/SocketConnection.cs +++ b/src/Kestrel.Transport.Sockets/Internal/SocketConnection.cs @@ -18,8 +18,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal { internal sealed class SocketConnection : TransportConnection { - private const int MinAllocBufferSize = 2048; - public readonly static bool IsWindows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows); + private static readonly int MinAllocBufferSize = KestrelMemoryPool.MinimumSegmentSize / 2; + private static readonly bool IsWindows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows); private readonly Socket _socket; private readonly PipeScheduler _scheduler; From ba2b883db088b0a07a3b82f1963f34098be9c148 Mon Sep 17 00:00:00 2001 From: Pavel Krymets Date: Mon, 2 Apr 2018 16:44:13 -0700 Subject: [PATCH 1602/1662] Reaction to *Memory changes (#2446) --- build/dependencies.props | 24 +++++++++---------- src/Directory.Build.props | 4 ++++ .../Internal/LibuvConnection.cs | 7 +++--- .../Internal/Networking/UvWriteReq.cs | 4 ++-- 4 files changed, 21 insertions(+), 18 deletions(-) diff --git a/build/dependencies.props b/build/dependencies.props index db44bbd005..bcef3e3761 100644 --- a/build/dependencies.props +++ b/build/dependencies.props @@ -7,8 +7,8 @@ 0.10.13 2.1.0-preview2-15749 1.10.0 - 2.1.0-preview2-30478 - 2.1.0-preview2-30478 + 2.1.0-a-preview2-mpr-16443 + 2.1.0-a-preview2-mpr-16443 2.1.0-preview2-30478 2.1.0-preview2-30478 2.1.0-preview2-30478 @@ -17,8 +17,8 @@ 2.1.0-preview2-30478 2.1.0-preview2-30478 2.1.0-preview2-30478 - 2.1.0-preview2-30478 - 2.1.0-preview2-30478 + 2.1.0-a-preview2-mpr-16443 + 2.1.0-a-preview2-mpr-16443 2.1.0-preview2-30478 2.1.0-preview2-30478 2.1.0-preview2-30478 @@ -28,18 +28,18 @@ 2.1.0-preview2-30478 2.1.0-preview2-30478 2.0.0 - 2.1.0-preview2-26326-03 + 2.1.0-preview3-26331-01 2.1.0-preview2-30478 15.6.1 4.7.49 11.0.2 - 4.5.0-preview2-26326-04 - 4.5.0-preview2-26326-04 - 4.5.0-preview2-26326-04 - 4.5.0-preview2-26326-04 - 4.5.0-preview2-26326-04 - 4.5.0-preview2-26326-04 - 4.5.0-preview2-26326-04 + 4.5.0-preview3-26331-02 + 4.5.0-preview3-26331-02 + 4.5.0-preview3-26331-02 + 4.5.0-preview3-26331-02 + 4.5.0-preview3-26331-02 + 4.5.0-preview3-26331-02 + 4.5.0-preview3-26331-02 0.8.0 2.3.1 2.4.0-beta.1.build3945 diff --git a/src/Directory.Build.props b/src/Directory.Build.props index a1676ede80..6b85b2cf04 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -6,4 +6,8 @@ + + + false + diff --git a/src/Kestrel.Transport.Libuv/Internal/LibuvConnection.cs b/src/Kestrel.Transport.Libuv/Internal/LibuvConnection.cs index b6295aa568..116b67e39c 100644 --- a/src/Kestrel.Transport.Libuv/Internal/LibuvConnection.cs +++ b/src/Kestrel.Transport.Libuv/Internal/LibuvConnection.cs @@ -106,7 +106,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal private unsafe LibuvFunctions.uv_buf_t OnAlloc(UvStreamHandle handle, int suggestedSize) { var currentWritableBuffer = Input.GetMemory(MinAllocBufferSize); - _bufferHandle = currentWritableBuffer.Retain(true); + _bufferHandle = currentWritableBuffer.Pin(); return handle.Libuv.buf_init((IntPtr)_bufferHandle.Pointer, currentWritableBuffer.Length); } @@ -118,6 +118,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal private void OnRead(UvStreamHandle handle, int status) { + // Cleanup state from last OnAlloc. This is safe even if OnAlloc wasn't called. + _bufferHandle.Dispose(); if (status == 0) { // EAGAIN/EWOULDBLOCK so just return the buffer. @@ -168,9 +170,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal // Complete after aborting the connection Input.Complete(error); } - - // Cleanup state from last OnAlloc. This is safe even if OnAlloc wasn't called. - _bufferHandle.Dispose(); } private async Task ApplyBackpressureAsync(ValueTask flushTask) diff --git a/src/Kestrel.Transport.Libuv/Internal/Networking/UvWriteReq.cs b/src/Kestrel.Transport.Libuv/Internal/Networking/UvWriteReq.cs index 9a635ba5cc..e28c318616 100644 --- a/src/Kestrel.Transport.Libuv/Internal/Networking/UvWriteReq.cs +++ b/src/Kestrel.Transport.Libuv/Internal/Networking/UvWriteReq.cs @@ -94,7 +94,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networkin if (nBuffers == 1) { var memory = buffer.First; - var memoryHandle = memory.Retain(true); + var memoryHandle = memory.Pin(); _handles.Add(memoryHandle); // Fast path for single buffer @@ -108,7 +108,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networkin foreach (var memory in buffer) { // This won't actually pin the buffer since we're already using pinned memory - var memoryHandle = memory.Retain(true); + var memoryHandle = memory.Pin(); _handles.Add(memoryHandle); // create and pin each segment being written From a92da1b8f42875efbf23176fc8cb3029a9a6c74e Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Mon, 2 Apr 2018 18:42:02 -0700 Subject: [PATCH 1603/1662] Fix CopyToAsyncDoesNotCopyBlocks test (#2458) --- test/Kestrel.Core.Tests/MessageBodyTests.cs | 100 ++++++++++---------- 1 file changed, 48 insertions(+), 52 deletions(-) diff --git a/test/Kestrel.Core.Tests/MessageBodyTests.cs b/test/Kestrel.Core.Tests/MessageBodyTests.cs index 8a563474fe..e9647cbee4 100644 --- a/test/Kestrel.Core.Tests/MessageBodyTests.cs +++ b/test/Kestrel.Core.Tests/MessageBodyTests.cs @@ -2,9 +2,8 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.Collections.Generic; using System.IO; -using System.Linq; +using System.IO.Pipelines; using System.Runtime.InteropServices; using System.Text; using System.Threading; @@ -13,6 +12,7 @@ using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; using Microsoft.AspNetCore.Testing; using Moq; using Xunit; @@ -401,81 +401,77 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests } } - public static IEnumerable StreamData => new[] - { - new object[] { new ThrowOnWriteSynchronousStream() }, - new object[] { new ThrowOnWriteAsynchronousStream() }, - }; - - public static IEnumerable RequestData => new[] - { - // Content-Length - new object[] { new HttpRequestHeaders { HeaderContentLength = "12" }, new[] { "Hello ", "World!" } }, - // Chunked - new object[] { new HttpRequestHeaders { HeaderTransferEncoding = "chunked" }, new[] { "6\r\nHello \r\n", "6\r\nWorld!\r\n0\r\n\r\n" } }, - }; - - public static IEnumerable CombinedData => - from stream in StreamData - from request in RequestData - select new[] { stream[0], request[0], request[1] }; - - [Theory] - [MemberData(nameof(RequestData))] - public async Task CopyToAsyncDoesNotCopyBlocks(HttpRequestHeaders headers, string[] data) + [Fact] + public async Task CopyToAsyncDoesNotCopyBlocks() { var writeCount = 0; - var writeTcs = new TaskCompletionSource(); + var writeTcs = new TaskCompletionSource<(byte[], int, int)>(); var mockDestination = new Mock() { CallBase = true }; mockDestination .Setup(m => m.WriteAsync(It.IsAny(), It.IsAny(), It.IsAny(), CancellationToken.None)) .Callback((byte[] buffer, int offset, int count, CancellationToken cancellationToken) => { - writeTcs.SetResult(buffer); + writeTcs.SetResult((buffer, offset, count)); writeCount++; }) .Returns(Task.CompletedTask); - using (var input = new TestInput()) + using (var memoryPool = KestrelMemoryPool.Create()) { - var body = Http1MessageBody.For(HttpVersion.Http11, headers, input.Http1Connection); + var options = new PipeOptions(pool: memoryPool, readerScheduler: PipeScheduler.Inline, writerScheduler: PipeScheduler.Inline, useSynchronizationContext: false); + var pair = DuplexPipe.CreateConnectionPair(options, options); + var transport = pair.Transport; + var application = pair.Application; + var http1ConnectionContext = new Http1ConnectionContext + { + ServiceContext = new TestServiceContext(), + ConnectionFeatures = new FeatureCollection(), + Application = application, + Transport = transport, + MemoryPool = memoryPool, + TimeoutControl = Mock.Of() + }; + var http1Connection = new Http1Connection(http1ConnectionContext) + { + HasStartedConsumingRequestBody = true + }; + + var headers = new HttpRequestHeaders { HeaderContentLength = "12" }; + var body = Http1MessageBody.For(HttpVersion.Http11, headers, http1Connection); var copyToAsyncTask = body.CopyToAsync(mockDestination.Object); - // The block returned by IncomingStart always has at least 2048 available bytes, - // so no need to bounds check in this test. - var bytes = Encoding.ASCII.GetBytes(data[0]); - var buffer = input.Application.Output.GetMemory(2028); - ArraySegment block; - Assert.True(MemoryMarshal.TryGetArray(buffer, out block)); - Buffer.BlockCopy(bytes, 0, block.Array, block.Offset, bytes.Length); - input.Application.Output.Advance(bytes.Length); - await input.Application.Output.FlushAsync(); + var bytes = Encoding.ASCII.GetBytes("Hello "); + var buffer = http1Connection.RequestBodyPipe.Writer.GetMemory(2048); + ArraySegment segment; + Assert.True(MemoryMarshal.TryGetArray(buffer, out segment)); + Buffer.BlockCopy(bytes, 0, segment.Array, segment.Offset, bytes.Length); + http1Connection.RequestBodyPipe.Writer.Advance(bytes.Length); + await http1Connection.RequestBodyPipe.Writer.FlushAsync(); - // Verify the block passed to WriteAsync is the same one incoming data was written into. - Assert.Same(block.Array, await writeTcs.Task); + // Verify the block passed to Stream.WriteAsync() is the same one incoming data was written into. + Assert.Equal((segment.Array, segment.Offset, bytes.Length), await writeTcs.Task); - writeTcs = new TaskCompletionSource(); - bytes = Encoding.ASCII.GetBytes(data[1]); - buffer = input.Application.Output.GetMemory(2048); - Assert.True(MemoryMarshal.TryGetArray(buffer, out block)); - Buffer.BlockCopy(bytes, 0, block.Array, block.Offset, bytes.Length); - input.Application.Output.Advance(bytes.Length); - await input.Application.Output.FlushAsync(); + // Verify the again when GetMemory returns the tail space of the same block. + writeTcs = new TaskCompletionSource<(byte[], int, int)>(); + bytes = Encoding.ASCII.GetBytes("World!"); + buffer = http1Connection.RequestBodyPipe.Writer.GetMemory(2048); + Assert.True(MemoryMarshal.TryGetArray(buffer, out segment)); + Buffer.BlockCopy(bytes, 0, segment.Array, segment.Offset, bytes.Length); + http1Connection.RequestBodyPipe.Writer.Advance(bytes.Length); + await http1Connection.RequestBodyPipe.Writer.FlushAsync(); - Assert.Same(block.Array, await writeTcs.Task); + Assert.Equal((segment.Array, segment.Offset, bytes.Length), await writeTcs.Task); - if (headers.HeaderConnection == "close") - { - input.Application.Output.Complete(); - } + http1Connection.RequestBodyPipe.Writer.Complete(); await copyToAsyncTask; Assert.Equal(2, writeCount); - await body.StopAsync(); + // Don't call body.StopAsync() because PumpAsync() was never called. + http1Connection.RequestBodyPipe.Reader.Complete(); } } From 623c27ab013fcec0462345ce7c374c1397f38422 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Mon, 2 Apr 2018 19:48:17 -0700 Subject: [PATCH 1604/1662] Dispose SocketAsyncEventArgs when we dispose the Socket (#2459) --- src/Kestrel.Transport.Sockets/Internal/SocketConnection.cs | 2 ++ src/Kestrel.Transport.Sockets/Internal/SocketReceiver.cs | 7 ++++++- src/Kestrel.Transport.Sockets/Internal/SocketSender.cs | 7 ++++++- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/Kestrel.Transport.Sockets/Internal/SocketConnection.cs b/src/Kestrel.Transport.Sockets/Internal/SocketConnection.cs index 726d0372ca..59e5ff2e22 100644 --- a/src/Kestrel.Transport.Sockets/Internal/SocketConnection.cs +++ b/src/Kestrel.Transport.Sockets/Internal/SocketConnection.cs @@ -86,6 +86,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal // Dispose the socket(should noop if already called) _socket.Dispose(); + _receiver.Dispose(); + _sender.Dispose(); } catch (Exception ex) { diff --git a/src/Kestrel.Transport.Sockets/Internal/SocketReceiver.cs b/src/Kestrel.Transport.Sockets/Internal/SocketReceiver.cs index 150978e473..2116c03cd5 100644 --- a/src/Kestrel.Transport.Sockets/Internal/SocketReceiver.cs +++ b/src/Kestrel.Transport.Sockets/Internal/SocketReceiver.cs @@ -7,7 +7,7 @@ using System.Net.Sockets; namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal { - public class SocketReceiver + public class SocketReceiver : IDisposable { private readonly Socket _socket; private readonly SocketAsyncEventArgs _eventArgs = new SocketAsyncEventArgs(); @@ -37,5 +37,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal return _awaitable; } + + public void Dispose() + { + _eventArgs.Dispose(); + } } } diff --git a/src/Kestrel.Transport.Sockets/Internal/SocketSender.cs b/src/Kestrel.Transport.Sockets/Internal/SocketSender.cs index a8b0727c0a..26e22b664d 100644 --- a/src/Kestrel.Transport.Sockets/Internal/SocketSender.cs +++ b/src/Kestrel.Transport.Sockets/Internal/SocketSender.cs @@ -11,7 +11,7 @@ using System.Runtime.InteropServices; namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal { - public class SocketSender + public class SocketSender : IDisposable { private readonly Socket _socket; private readonly SocketAsyncEventArgs _eventArgs = new SocketAsyncEventArgs(); @@ -98,5 +98,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal return _bufferList; } + + public void Dispose() + { + _eventArgs.Dispose(); + } } } From ba06c58bcbfb2476176b39463297533803a7db1f Mon Sep 17 00:00:00 2001 From: Pavel Krymets Date: Tue, 3 Apr 2018 10:45:31 -0700 Subject: [PATCH 1605/1662] Merge release/2.1 into dev (#2460) --- build/dependencies.props | 17 ++++++++--------- src/Directory.Build.props | 4 ++++ .../Internal/LibuvConnection.cs | 7 +++---- .../Internal/Networking/UvWriteReq.cs | 4 ++-- .../Internal/SocketConnection.cs | 2 ++ .../Internal/SocketReceiver.cs | 7 ++++++- .../Internal/SocketSender.cs | 7 ++++++- 7 files changed, 31 insertions(+), 17 deletions(-) diff --git a/build/dependencies.props b/build/dependencies.props index 0365181477..3d317ffde2 100644 --- a/build/dependencies.props +++ b/build/dependencies.props @@ -28,18 +28,17 @@ 2.1.0-preview3-32037 2.1.0-preview3-32037 2.0.0 - 2.1.0-preview2-26314-02 2.1.0-preview3-32037 + 2.1.0-preview3-26331-01 15.6.1 4.7.49 - 11.0.1 - 4.5.0-preview2-26313-01 - 4.5.0-preview2-26313-01 - 4.5.0-preview2-26313-01 - 4.5.0-preview2-26313-01 - 4.5.0-preview2-26313-01 - 4.5.0-preview2-26313-01 - 4.5.0-preview2-26313-01 + 4.5.0-preview3-26331-02 + 4.5.0-preview3-26331-02 + 4.5.0-preview3-26331-02 + 4.5.0-preview3-26331-02 + 4.5.0-preview3-26331-02 + 4.5.0-preview3-26331-02 + 4.5.0-preview3-26331-02 0.8.0 2.3.1 2.4.0-beta.1.build3945 diff --git a/src/Directory.Build.props b/src/Directory.Build.props index a1676ede80..6b85b2cf04 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -6,4 +6,8 @@ + + + false + diff --git a/src/Kestrel.Transport.Libuv/Internal/LibuvConnection.cs b/src/Kestrel.Transport.Libuv/Internal/LibuvConnection.cs index 00844e73a3..21e3a6805e 100644 --- a/src/Kestrel.Transport.Libuv/Internal/LibuvConnection.cs +++ b/src/Kestrel.Transport.Libuv/Internal/LibuvConnection.cs @@ -106,7 +106,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal private unsafe LibuvFunctions.uv_buf_t OnAlloc(UvStreamHandle handle, int suggestedSize) { var currentWritableBuffer = Input.GetMemory(MinAllocBufferSize); - _bufferHandle = currentWritableBuffer.Retain(true); + _bufferHandle = currentWritableBuffer.Pin(); return handle.Libuv.buf_init((IntPtr)_bufferHandle.Pointer, currentWritableBuffer.Length); } @@ -118,6 +118,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal private void OnRead(UvStreamHandle handle, int status) { + // Cleanup state from last OnAlloc. This is safe even if OnAlloc wasn't called. + _bufferHandle.Dispose(); if (status == 0) { // EAGAIN/EWOULDBLOCK so just return the buffer. @@ -168,9 +170,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal // Complete after aborting the connection Input.Complete(error); } - - // Cleanup state from last OnAlloc. This is safe even if OnAlloc wasn't called. - _bufferHandle.Dispose(); } private async Task ApplyBackpressureAsync(ValueTask flushTask) diff --git a/src/Kestrel.Transport.Libuv/Internal/Networking/UvWriteReq.cs b/src/Kestrel.Transport.Libuv/Internal/Networking/UvWriteReq.cs index 9a635ba5cc..e28c318616 100644 --- a/src/Kestrel.Transport.Libuv/Internal/Networking/UvWriteReq.cs +++ b/src/Kestrel.Transport.Libuv/Internal/Networking/UvWriteReq.cs @@ -94,7 +94,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networkin if (nBuffers == 1) { var memory = buffer.First; - var memoryHandle = memory.Retain(true); + var memoryHandle = memory.Pin(); _handles.Add(memoryHandle); // Fast path for single buffer @@ -108,7 +108,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networkin foreach (var memory in buffer) { // This won't actually pin the buffer since we're already using pinned memory - var memoryHandle = memory.Retain(true); + var memoryHandle = memory.Pin(); _handles.Add(memoryHandle); // create and pin each segment being written diff --git a/src/Kestrel.Transport.Sockets/Internal/SocketConnection.cs b/src/Kestrel.Transport.Sockets/Internal/SocketConnection.cs index 0f73ad2571..a8b66a579c 100644 --- a/src/Kestrel.Transport.Sockets/Internal/SocketConnection.cs +++ b/src/Kestrel.Transport.Sockets/Internal/SocketConnection.cs @@ -86,6 +86,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal // Dispose the socket(should noop if already called) _socket.Dispose(); + _receiver.Dispose(); + _sender.Dispose(); } catch (Exception ex) { diff --git a/src/Kestrel.Transport.Sockets/Internal/SocketReceiver.cs b/src/Kestrel.Transport.Sockets/Internal/SocketReceiver.cs index 150978e473..2116c03cd5 100644 --- a/src/Kestrel.Transport.Sockets/Internal/SocketReceiver.cs +++ b/src/Kestrel.Transport.Sockets/Internal/SocketReceiver.cs @@ -7,7 +7,7 @@ using System.Net.Sockets; namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal { - public class SocketReceiver + public class SocketReceiver : IDisposable { private readonly Socket _socket; private readonly SocketAsyncEventArgs _eventArgs = new SocketAsyncEventArgs(); @@ -37,5 +37,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal return _awaitable; } + + public void Dispose() + { + _eventArgs.Dispose(); + } } } diff --git a/src/Kestrel.Transport.Sockets/Internal/SocketSender.cs b/src/Kestrel.Transport.Sockets/Internal/SocketSender.cs index a8b0727c0a..26e22b664d 100644 --- a/src/Kestrel.Transport.Sockets/Internal/SocketSender.cs +++ b/src/Kestrel.Transport.Sockets/Internal/SocketSender.cs @@ -11,7 +11,7 @@ using System.Runtime.InteropServices; namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal { - public class SocketSender + public class SocketSender : IDisposable { private readonly Socket _socket; private readonly SocketAsyncEventArgs _eventArgs = new SocketAsyncEventArgs(); @@ -98,5 +98,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal return _bufferList; } + + public void Dispose() + { + _eventArgs.Dispose(); + } } } From 769dd4684a2c7d52b099900420ec5d31f4e8be40 Mon Sep 17 00:00:00 2001 From: Pavel Krymets Date: Tue, 3 Apr 2018 11:08:13 -0700 Subject: [PATCH 1606/1662] Add NewtonsoftJsonPackageVersion back --- build/dependencies.props | 1 + 1 file changed, 1 insertion(+) diff --git a/build/dependencies.props b/build/dependencies.props index 3d317ffde2..5071b7be12 100644 --- a/build/dependencies.props +++ b/build/dependencies.props @@ -39,6 +39,7 @@ 4.5.0-preview3-26331-02 4.5.0-preview3-26331-02 4.5.0-preview3-26331-02 + 11.0.1 0.8.0 2.3.1 2.4.0-beta.1.build3945 From 5c87b44a3e4b78949572dba6fd24bf2dd0812260 Mon Sep 17 00:00:00 2001 From: "ASP.NET CI" Date: Tue, 3 Apr 2018 22:32:42 +0000 Subject: [PATCH 1607/1662] Update dependencies.props [auto-updated: dependencies] --- build/dependencies.props | 46 ++++++++++++++++++++-------------------- korebuild-lock.txt | 4 ++-- 2 files changed, 25 insertions(+), 25 deletions(-) diff --git a/build/dependencies.props b/build/dependencies.props index 5071b7be12..9831c511ea 100644 --- a/build/dependencies.props +++ b/build/dependencies.props @@ -5,33 +5,34 @@ 0.10.13 - 2.1.0-preview3-17001 + 2.1.0-preview3-17002 1.10.0 - 2.1.0-preview3-32037 - 2.1.0-preview3-32037 - 2.1.0-preview3-32037 - 2.1.0-preview3-32037 - 2.1.0-preview3-32037 - 2.1.0-preview3-32037 - 2.1.0-preview3-32037 - 2.1.0-preview3-32037 - 2.1.0-preview3-32037 - 2.1.0-preview3-32037 - 2.1.0-preview3-32037 - 2.1.0-preview3-32037 - 2.1.0-preview3-32037 - 2.1.0-preview3-32037 - 2.1.0-preview3-32037 - 2.1.0-preview3-32037 - 2.1.0-preview3-32037 - 2.1.0-preview3-32037 - 2.1.0-preview3-32037 - 2.1.0-preview3-32037 + 2.1.0-preview3-32110 + 2.1.0-preview3-32110 + 2.1.0-preview3-32110 + 2.1.0-preview3-32110 + 2.1.0-preview3-32110 + 2.1.0-preview3-32110 + 2.1.0-preview3-32110 + 2.1.0-preview3-32110 + 2.1.0-preview3-32110 + 2.1.0-preview3-32110 + 2.1.0-preview3-32110 + 2.1.0-preview3-32110 + 2.1.0-preview3-32110 + 2.1.0-preview3-32110 + 2.1.0-preview3-32110 + 2.1.0-preview3-32110 + 2.1.0-preview3-32110 + 2.1.0-preview3-32110 + 2.1.0-preview3-32110 + 2.1.0-preview3-32110 2.0.0 - 2.1.0-preview3-32037 2.1.0-preview3-26331-01 + 2.1.0-preview3-32110 15.6.1 4.7.49 + 11.0.2 4.5.0-preview3-26331-02 4.5.0-preview3-26331-02 4.5.0-preview3-26331-02 @@ -39,7 +40,6 @@ 4.5.0-preview3-26331-02 4.5.0-preview3-26331-02 4.5.0-preview3-26331-02 - 11.0.1 0.8.0 2.3.1 2.4.0-beta.1.build3945 diff --git a/korebuild-lock.txt b/korebuild-lock.txt index 3a326c7d58..b3af0b8bce 100644 --- a/korebuild-lock.txt +++ b/korebuild-lock.txt @@ -1,2 +1,2 @@ -version:2.1.0-preview3-17001 -commithash:dda68c56abf0d3b911fe6a2315872c446b314585 +version:2.1.0-preview3-17002 +commithash:b8e4e6ab104adc94c0719bb74229870e9b584a7f From 70ce0447781bfca57f6945e6a5f056045073e6ec Mon Sep 17 00:00:00 2001 From: Andrei Amialchenia Date: Wed, 4 Apr 2018 01:55:17 +0300 Subject: [PATCH 1608/1662] Corrects spelling of some comments (#2461) --- benchmarks/Kestrel.Performance/AsciiBytesToStringBenchmark.cs | 4 ++-- src/Kestrel.Core/Internal/Http/Http1MessageBody.cs | 2 +- src/Kestrel.Core/Internal/Infrastructure/StringUtilities.cs | 2 +- src/Kestrel.Transport.Libuv/Internal/LibuvThread.cs | 2 +- src/Kestrel.Transport.Sockets/SocketTransport.cs | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/benchmarks/Kestrel.Performance/AsciiBytesToStringBenchmark.cs b/benchmarks/Kestrel.Performance/AsciiBytesToStringBenchmark.cs index 173b7260e5..2f9c2423f5 100644 --- a/benchmarks/Kestrel.Performance/AsciiBytesToStringBenchmark.cs +++ b/benchmarks/Kestrel.Performance/AsciiBytesToStringBenchmark.cs @@ -224,7 +224,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance public static unsafe bool TryGetAsciiStringVectorWiden(byte* input, char* output, int count) { - // Calcuate end position + // Calculate end position var end = input + count; // Start as valid var isValid = true; @@ -324,7 +324,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance public static unsafe bool TryGetAsciiStringVectorCheck(byte* input, char* output, int count) { - // Calcuate end position + // Calculate end position var end = input + count; // Start as valid var isValid = true; diff --git a/src/Kestrel.Core/Internal/Http/Http1MessageBody.cs b/src/Kestrel.Core/Internal/Http/Http1MessageBody.cs index 54d400d3a9..6f82e27dd0 100644 --- a/src/Kestrel.Core/Internal/Http/Http1MessageBody.cs +++ b/src/Kestrel.Core/Internal/Http/Http1MessageBody.cs @@ -428,7 +428,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http readableBuffer = readableBuffer.Slice(consumed); } - // _consumedBytes aren't tracked for trailer headers, since headers have seperate limits. + // _consumedBytes aren't tracked for trailer headers, since headers have separate limits. if (_mode == Mode.TrailerHeaders) { if (_context.TakeMessageHeaders(readableBuffer, out consumed, out examined)) diff --git a/src/Kestrel.Core/Internal/Infrastructure/StringUtilities.cs b/src/Kestrel.Core/Internal/Infrastructure/StringUtilities.cs index 76c4a8576e..95073a97de 100644 --- a/src/Kestrel.Core/Internal/Infrastructure/StringUtilities.cs +++ b/src/Kestrel.Core/Internal/Infrastructure/StringUtilities.cs @@ -11,7 +11,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure { public static unsafe bool TryGetAsciiString(byte* input, char* output, int count) { - // Calcuate end position + // Calculate end position var end = input + count; // Start as valid var isValid = true; diff --git a/src/Kestrel.Transport.Libuv/Internal/LibuvThread.cs b/src/Kestrel.Transport.Libuv/Internal/LibuvThread.cs index 1e621f401b..f8145ae22d 100644 --- a/src/Kestrel.Transport.Libuv/Internal/LibuvThread.cs +++ b/src/Kestrel.Transport.Libuv/Internal/LibuvThread.cs @@ -305,7 +305,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal _post.Reference(); _post.Dispose(); - // We need this walk because we call ReadStop on on accepted connections when there's back pressure + // We need this walk because we call ReadStop on accepted connections when there's back pressure // Calling ReadStop makes the handle as in-active which means the loop can // end while there's still valid handles around. This makes loop.Dispose throw // with an EBUSY. To avoid that, we walk all of the handles and dispose them. diff --git a/src/Kestrel.Transport.Sockets/SocketTransport.cs b/src/Kestrel.Transport.Sockets/SocketTransport.cs index 725ee0546d..4882b47114 100644 --- a/src/Kestrel.Transport.Sockets/SocketTransport.cs +++ b/src/Kestrel.Transport.Sockets/SocketTransport.cs @@ -159,7 +159,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets } catch (SocketException ex) when (ex.SocketErrorCode == SocketError.ConnectionReset) { - // REVIEW: Should there be a seperate log message for a connection reset this early? + // REVIEW: Should there be a separate log message for a connection reset this early? _trace.ConnectionReset(connectionId: "(null)"); } catch (SocketException ex) when (!_unbinding) From 9ea2c50068c77978f0df7b3c58368167503dfa50 Mon Sep 17 00:00:00 2001 From: "Chris Ross (ASP.NET)" Date: Fri, 23 Mar 2018 10:23:17 -0700 Subject: [PATCH 1609/1662] Add SNI support #2357 --- build/dependencies.props | 58 ++--- samples/SampleApp/Startup.cs | 18 +- src/Kestrel.Core/CoreStrings.resx | 2 +- .../HttpsConnectionAdapterOptions.cs | 14 +- .../Internal/HttpsConnectionAdapter.cs | 52 ++++- .../KestrelConfigurationLoader.cs | 2 +- .../ListenOptionsHttpsExtensions.cs | 4 +- .../Properties/CoreStrings.Designer.cs | 8 +- .../HttpsConnectionAdapterTests.cs | 208 +++++++++++++++++- test/shared/TestResources.cs | 5 + 10 files changed, 323 insertions(+), 48 deletions(-) diff --git a/build/dependencies.props b/build/dependencies.props index bcef3e3761..c3d5165f83 100644 --- a/build/dependencies.props +++ b/build/dependencies.props @@ -7,39 +7,39 @@ 0.10.13 2.1.0-preview2-15749 1.10.0 - 2.1.0-a-preview2-mpr-16443 - 2.1.0-a-preview2-mpr-16443 - 2.1.0-preview2-30478 - 2.1.0-preview2-30478 - 2.1.0-preview2-30478 - 2.1.0-preview2-30478 - 2.1.0-preview2-30478 - 2.1.0-preview2-30478 - 2.1.0-preview2-30478 - 2.1.0-preview2-30478 - 2.1.0-a-preview2-mpr-16443 - 2.1.0-a-preview2-mpr-16443 - 2.1.0-preview2-30478 - 2.1.0-preview2-30478 - 2.1.0-preview2-30478 - 2.1.0-preview2-30478 - 2.1.0-preview2-30478 - 2.1.0-preview2-30478 - 2.1.0-preview2-30478 - 2.1.0-preview2-30478 + 2.1.0-preview2-30554 + 2.1.0-preview2-30554 + 2.1.0-preview2-30554 + 2.1.0-preview2-30554 + 2.1.0-preview2-30554 + 2.1.0-preview2-30554 + 2.1.0-preview2-30554 + 2.1.0-preview2-30554 + 2.1.0-preview2-30554 + 2.1.0-preview2-30554 + 2.1.0-preview2-30554 + 2.1.0-preview2-30554 + 2.1.0-preview2-30554 + 2.1.0-preview2-30554 + 2.1.0-preview2-30554 + 2.1.0-preview2-30554 + 2.1.0-preview2-30554 + 2.1.0-preview2-30554 + 2.1.0-preview2-30554 + 2.1.0-preview2-30554 2.0.0 - 2.1.0-preview3-26331-01 - 2.1.0-preview2-30478 + 2.1.0-preview2-26403-06 + 2.1.0-preview2-30554 15.6.1 4.7.49 11.0.2 - 4.5.0-preview3-26331-02 - 4.5.0-preview3-26331-02 - 4.5.0-preview3-26331-02 - 4.5.0-preview3-26331-02 - 4.5.0-preview3-26331-02 - 4.5.0-preview3-26331-02 - 4.5.0-preview3-26331-02 + 4.5.0-preview2-26403-05 + 4.5.0-preview2-26403-05 + 4.5.0-preview2-26403-05 + 4.5.0-preview2-26403-05 + 4.5.0-preview2-26403-05 + 4.5.0-preview2-26403-05 + 4.5.0-preview2-26403-05 0.8.0 2.3.1 2.4.0-beta.1.build3945 diff --git a/samples/SampleApp/Startup.cs b/samples/SampleApp/Startup.cs index 02c66a20be..3a4f29a3fd 100644 --- a/samples/SampleApp/Startup.cs +++ b/samples/SampleApp/Startup.cs @@ -12,6 +12,7 @@ using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Server.Kestrel.Core; +using Microsoft.AspNetCore.Server.Kestrel.Https.Internal; using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Logging; @@ -105,10 +106,23 @@ namespace SampleApp listenOptions.UseHttps(StoreName.My, "localhost", allowInvalid: true); }); + options.ListenAnyIP(basePort + 5, listenOptions => + { + listenOptions.UseHttps(httpsOptions => + { + var localhostCert = CertificateLoader.LoadFromStoreCert("localhost", "My", StoreLocation.CurrentUser, allowInvalid: true); + httpsOptions.ServerCertificateSelector = (features, name) => + { + // Here you would check the name, select an appropriate cert, and provide a fallback or fail for null names. + return localhostCert; + }; + }); + }); + options .Configure() - .Endpoint(IPAddress.Loopback, basePort + 5) - .LocalhostEndpoint(basePort + 6) + .Endpoint(IPAddress.Loopback, basePort + 6) + .LocalhostEndpoint(basePort + 7) .Load(); options diff --git a/src/Kestrel.Core/CoreStrings.resx b/src/Kestrel.Core/CoreStrings.resx index 5eb49c1320..0ba93c9219 100644 --- a/src/Kestrel.Core/CoreStrings.resx +++ b/src/Kestrel.Core/CoreStrings.resx @@ -477,7 +477,7 @@ Value must be a positive TimeSpan. - + The server certificate parameter is required. diff --git a/src/Kestrel.Core/HttpsConnectionAdapterOptions.cs b/src/Kestrel.Core/HttpsConnectionAdapterOptions.cs index 6ada701707..760c29cfc1 100644 --- a/src/Kestrel.Core/HttpsConnectionAdapterOptions.cs +++ b/src/Kestrel.Core/HttpsConnectionAdapterOptions.cs @@ -6,6 +6,7 @@ using System.Net.Security; using System.Security.Authentication; using System.Security.Cryptography.X509Certificates; using System.Threading; +using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Server.Kestrel.Core; namespace Microsoft.AspNetCore.Server.Kestrel.Https @@ -29,7 +30,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Https /// /// - /// Specifies the server certificate used to authenticate HTTPS connections. + /// Specifies the server certificate used to authenticate HTTPS connections. This is ignored if ServerCertificateSelector is set. /// /// /// If the server certificate has an Extended Key Usage extension, the usages must include Server Authentication (OID 1.3.6.1.5.5.7.3.1). @@ -37,6 +38,17 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Https /// public X509Certificate2 ServerCertificate { get; set; } + /// + /// + /// A callback that will be invoked to dynamically select a server certificate. This is higher priority than ServerCertificate. + /// If SNI is not avialable then the name parameter will be null. + /// + /// + /// If the server certificate has an Extended Key Usage extension, the usages must include Server Authentication (OID 1.3.6.1.5.5.7.3.1). + /// + /// + public Func ServerCertificateSelector { get; set; } + /// /// Specifies the client certificate requirements for a HTTPS connection. Defaults to . /// diff --git a/src/Kestrel.Core/Internal/HttpsConnectionAdapter.cs b/src/Kestrel.Core/Internal/HttpsConnectionAdapter.cs index c71aedfedb..4107da5118 100644 --- a/src/Kestrel.Core/Internal/HttpsConnectionAdapter.cs +++ b/src/Kestrel.Core/Internal/HttpsConnectionAdapter.cs @@ -22,6 +22,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Https.Internal private readonly HttpsConnectionAdapterOptions _options; private readonly X509Certificate2 _serverCertificate; + private readonly Func _serverCertificateSelector; + private readonly ILogger _logger; public HttpsConnectionAdapter(HttpsConnectionAdapterOptions options) @@ -36,15 +38,24 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Https.Internal throw new ArgumentNullException(nameof(options)); } - if (options.ServerCertificate == null) + // capture the certificate now so it can't be switched after validation + _serverCertificate = options.ServerCertificate; + _serverCertificateSelector = options.ServerCertificateSelector; + if (_serverCertificate == null && _serverCertificateSelector == null) { - throw new ArgumentException(CoreStrings.ServiceCertificateRequired, nameof(options)); + throw new ArgumentException(CoreStrings.ServerCertificateRequired, nameof(options)); } - // capture the certificate now so it can be switched after validation - _serverCertificate = options.ServerCertificate; - - EnsureCertificateIsAllowedForServerAuth(_serverCertificate); + // If a selector is provided then ignore the cert, it may be a default cert. + if (_serverCertificateSelector != null) + { + // SslStream doesn't allow both. + _serverCertificate = null; + } + else + { + EnsureCertificateIsAllowedForServerAuth(_serverCertificate); + } _options = options; _logger = loggerFactory?.CreateLogger(nameof(HttpsConnectionAdapter)); @@ -115,9 +126,26 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Https.Internal try { #if NETCOREAPP2_1 + // Adapt to the SslStream signature + ServerCertificateSelectionCallback selector = null; + if (_serverCertificateSelector != null) + { + selector = (sender, name) => + { + context.Features.Set(sslStream); + var cert = _serverCertificateSelector(context.Features, name); + if (cert != null) + { + EnsureCertificateIsAllowedForServerAuth(cert); + } + return cert; + }; + } + var sslOptions = new SslServerAuthenticationOptions() { ServerCertificate = _serverCertificate, + ServerCertificateSelectionCallback = selector, ClientCertificateRequired = certificateRequired, EnabledSslProtocols = _options.SslProtocols, CertificateRevocationCheckMode = _options.CheckCertificateRevocation ? X509RevocationMode.Online : X509RevocationMode.NoCheck, @@ -137,7 +165,17 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Https.Internal await sslStream.AuthenticateAsServerAsync(sslOptions, CancellationToken.None); #else - await sslStream.AuthenticateAsServerAsync(_serverCertificate, certificateRequired, + var serverCert = _serverCertificate; + if (_serverCertificateSelector != null) + { + context.Features.Set(sslStream); + serverCert = _serverCertificateSelector(context.Features, null); + if (serverCert != null) + { + EnsureCertificateIsAllowedForServerAuth(serverCert); + } + } + await sslStream.AuthenticateAsServerAsync(serverCert, certificateRequired, _options.SslProtocols, _options.CheckCertificateRevocation); #endif } diff --git a/src/Kestrel.Core/KestrelConfigurationLoader.cs b/src/Kestrel.Core/KestrelConfigurationLoader.cs index 71337a11d2..b6468374b2 100644 --- a/src/Kestrel.Core/KestrelConfigurationLoader.cs +++ b/src/Kestrel.Core/KestrelConfigurationLoader.cs @@ -236,7 +236,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel // EndpointDefaults or configureEndpoint may have added an https adapter. if (https && !listenOptions.ConnectionAdapters.Any(f => f.IsHttps)) { - if (httpsOptions.ServerCertificate == null) + if (httpsOptions.ServerCertificate == null && httpsOptions.ServerCertificateSelector == null) { throw new InvalidOperationException(CoreStrings.NoCertSpecifiedNoDevelopmentCertificateFound); } diff --git a/src/Kestrel.Core/ListenOptionsHttpsExtensions.cs b/src/Kestrel.Core/ListenOptionsHttpsExtensions.cs index 7cc267c5de..162ee59d40 100644 --- a/src/Kestrel.Core/ListenOptionsHttpsExtensions.cs +++ b/src/Kestrel.Core/ListenOptionsHttpsExtensions.cs @@ -179,7 +179,7 @@ namespace Microsoft.AspNetCore.Hosting listenOptions.KestrelServerOptions.ApplyHttpsDefaults(options); configureOptions(options); - if (options.ServerCertificate == null) + if (options.ServerCertificate == null && options.ServerCertificateSelector == null) { throw new InvalidOperationException(CoreStrings.NoCertSpecifiedNoDevelopmentCertificateFound); } @@ -192,7 +192,7 @@ namespace Microsoft.AspNetCore.Hosting var options = new HttpsConnectionAdapterOptions(); listenOptions.KestrelServerOptions.ApplyHttpsDefaults(options); - if (options.ServerCertificate == null) + if (options.ServerCertificate == null && options.ServerCertificateSelector == null) { return false; } diff --git a/src/Kestrel.Core/Properties/CoreStrings.Designer.cs b/src/Kestrel.Core/Properties/CoreStrings.Designer.cs index f964f3db90..dab35d664d 100644 --- a/src/Kestrel.Core/Properties/CoreStrings.Designer.cs +++ b/src/Kestrel.Core/Properties/CoreStrings.Designer.cs @@ -1693,16 +1693,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core /// /// The server certificate parameter is required. /// - internal static string ServiceCertificateRequired + internal static string ServerCertificateRequired { - get => GetString("ServiceCertificateRequired"); + get => GetString("ServerCertificateRequired"); } /// /// The server certificate parameter is required. /// - internal static string FormatServiceCertificateRequired() - => GetString("ServiceCertificateRequired"); + internal static string FormatServerCertificateRequired() + => GetString("ServerCertificateRequired"); /// /// No listening endpoints were configured. Binding to {address0} and {address1} by default. diff --git a/test/Kestrel.FunctionalTests/HttpsConnectionAdapterTests.cs b/test/Kestrel.FunctionalTests/HttpsConnectionAdapterTests.cs index c08d02fb3e..43ff38ce26 100644 --- a/test/Kestrel.FunctionalTests/HttpsConnectionAdapterTests.cs +++ b/test/Kestrel.FunctionalTests/HttpsConnectionAdapterTests.cs @@ -26,7 +26,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { public class HttpsConnectionAdapterTests { - private static X509Certificate2 _x509Certificate2 = new X509Certificate2(TestResources.TestCertificatePath, "testPassword"); + private static X509Certificate2 _x509Certificate2 = TestResources.GetTestCertificate(); + private static X509Certificate2 _x509Certificate2NoExt = TestResources.GetTestCertificate("no_extensions.pfx"); private readonly ITestOutputHelper _output; public HttpsConnectionAdapterTests(ITestOutputHelper output) @@ -148,6 +149,211 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } } + [Fact] + public async Task UsesProvidedServerCertificateSelector() + { + var selectorCalled = 0; + var serviceContext = new TestServiceContext(); + var listenOptions = new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0)) + { + ConnectionAdapters = + { + new HttpsConnectionAdapter(new HttpsConnectionAdapterOptions + { + ServerCertificateSelector = (features, name) => + { + Assert.NotNull(features); + Assert.NotNull(features.Get()); +#if NETCOREAPP2_1 + Assert.Equal("localhost", name); +#else + Assert.Null(name); +#endif + selectorCalled++; + return _x509Certificate2; + } + }) + } + }; + using (var server = new TestServer(context => Task.CompletedTask, serviceContext, listenOptions)) + { + using (var client = new TcpClient()) + { + // SslStream is used to ensure the certificate is actually passed to the server + // HttpClient might not send the certificate because it is invalid or it doesn't match any + // of the certificate authorities sent by the server in the SSL handshake. + var stream = await OpenSslStream(client, server); + await stream.AuthenticateAsClientAsync("localhost", new X509CertificateCollection(), SslProtocols.Tls12 | SslProtocols.Tls11, false); + Assert.True(stream.RemoteCertificate.Equals(_x509Certificate2)); + Assert.Equal(1, selectorCalled); + } + } + } + + [Fact] + public async Task UsesProvidedServerCertificateSelectorEachTime() + { + var selectorCalled = 0; + var serviceContext = new TestServiceContext(); + var listenOptions = new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0)) + { + ConnectionAdapters = + { + new HttpsConnectionAdapter(new HttpsConnectionAdapterOptions + { + ServerCertificateSelector = (features, name) => + { + Assert.NotNull(features); + Assert.NotNull(features.Get()); +#if NETCOREAPP2_1 + Assert.Equal("localhost", name); +#else + Assert.Null(name); +#endif + selectorCalled++; + if (selectorCalled == 1) + { + return _x509Certificate2; + } + return _x509Certificate2NoExt; + } + }) + } + }; + using (var server = new TestServer(context => Task.CompletedTask, serviceContext, listenOptions)) + { + using (var client = new TcpClient()) + { + // SslStream is used to ensure the certificate is actually passed to the server + // HttpClient might not send the certificate because it is invalid or it doesn't match any + // of the certificate authorities sent by the server in the SSL handshake. + var stream = await OpenSslStream(client, server); + await stream.AuthenticateAsClientAsync("localhost", new X509CertificateCollection(), SslProtocols.Tls12 | SslProtocols.Tls11, false); + Assert.True(stream.RemoteCertificate.Equals(_x509Certificate2)); + Assert.Equal(1, selectorCalled); + } + using (var client = new TcpClient()) + { + // SslStream is used to ensure the certificate is actually passed to the server + // HttpClient might not send the certificate because it is invalid or it doesn't match any + // of the certificate authorities sent by the server in the SSL handshake. + var stream = await OpenSslStream(client, server); + await stream.AuthenticateAsClientAsync("localhost", new X509CertificateCollection(), SslProtocols.Tls12 | SslProtocols.Tls11, false); + Assert.True(stream.RemoteCertificate.Equals(_x509Certificate2NoExt)); + Assert.Equal(2, selectorCalled); + } + } + } + + [Fact] + public async Task UsesProvidedServerCertificateSelectorValidatesEkus() + { + var selectorCalled = 0; + var serviceContext = new TestServiceContext(); + var listenOptions = new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0)) + { + ConnectionAdapters = + { + new HttpsConnectionAdapter(new HttpsConnectionAdapterOptions + { + ServerCertificateSelector = (features, name) => + { + selectorCalled++; + return TestResources.GetTestCertificate("eku.code_signing.pfx"); + } + }) + } + }; + using (var server = new TestServer(context => Task.CompletedTask, serviceContext, listenOptions)) + { + using (var client = new TcpClient()) + { + // SslStream is used to ensure the certificate is actually passed to the server + // HttpClient might not send the certificate because it is invalid or it doesn't match any + // of the certificate authorities sent by the server in the SSL handshake. + var stream = await OpenSslStream(client, server); + await Assert.ThrowsAsync(() => + stream.AuthenticateAsClientAsync("localhost", new X509CertificateCollection(), SslProtocols.Tls12 | SslProtocols.Tls11, false)); + Assert.Equal(1, selectorCalled); + } + } + } + + [Fact] + public async Task UsesProvidedServerCertificateSelectorOverridesServerCertificate() + { + var selectorCalled = 0; + var serviceContext = new TestServiceContext(); + var listenOptions = new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0)) + { + ConnectionAdapters = + { + new HttpsConnectionAdapter(new HttpsConnectionAdapterOptions + { + ServerCertificate = _x509Certificate2NoExt, + ServerCertificateSelector = (features, name) => + { + Assert.NotNull(features); + Assert.NotNull(features.Get()); +#if NETCOREAPP2_1 + Assert.Equal("localhost", name); +#else + Assert.Null(name); +#endif + selectorCalled++; + return _x509Certificate2; + } + }) + } + }; + using (var server = new TestServer(context => Task.CompletedTask, serviceContext, listenOptions)) + { + using (var client = new TcpClient()) + { + // SslStream is used to ensure the certificate is actually passed to the server + // HttpClient might not send the certificate because it is invalid or it doesn't match any + // of the certificate authorities sent by the server in the SSL handshake. + var stream = await OpenSslStream(client, server); + await stream.AuthenticateAsClientAsync("localhost", new X509CertificateCollection(), SslProtocols.Tls12 | SslProtocols.Tls11, false); + Assert.True(stream.RemoteCertificate.Equals(_x509Certificate2)); + Assert.Equal(1, selectorCalled); + } + } + } + + [Fact] + public async Task UsesProvidedServerCertificateSelectorFailsIfYouReturnNull() + { + var selectorCalled = 0; + var serviceContext = new TestServiceContext(); + var listenOptions = new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0)) + { + ConnectionAdapters = + { + new HttpsConnectionAdapter(new HttpsConnectionAdapterOptions + { + ServerCertificateSelector = (features, name) => + { + selectorCalled++; + return null; + } + }) + } + }; + using (var server = new TestServer(context => Task.CompletedTask, serviceContext, listenOptions)) + { + using (var client = new TcpClient()) + { + // SslStream is used to ensure the certificate is actually passed to the server + // HttpClient might not send the certificate because it is invalid or it doesn't match any + // of the certificate authorities sent by the server in the SSL handshake. + var stream = await OpenSslStream(client, server); + await Assert.ThrowsAsync(() => + stream.AuthenticateAsClientAsync("localhost", new X509CertificateCollection(), SslProtocols.Tls12 | SslProtocols.Tls11, false)); + Assert.Equal(1, selectorCalled); + } + } + } [Fact] public async Task CertificatePassedToHttpContext() diff --git a/test/shared/TestResources.cs b/test/shared/TestResources.cs index b8ae46d18f..3218a1eaca 100644 --- a/test/shared/TestResources.cs +++ b/test/shared/TestResources.cs @@ -17,5 +17,10 @@ namespace Microsoft.AspNetCore.Testing { return new X509Certificate2(TestCertificatePath, "testPassword"); } + + public static X509Certificate2 GetTestCertificate(string certName) + { + return new X509Certificate2(GetCertPath(certName), "testPassword"); + } } } From 2ee0d6e33790a22a263ee7134310234a2ba93d53 Mon Sep 17 00:00:00 2001 From: "Chris Ross (ASP.NET)" Date: Wed, 4 Apr 2018 12:22:42 -0700 Subject: [PATCH 1610/1662] Delay loading the dev cert #2422 --- .../Internal/KestrelServerOptionsSetup.cs | 33 ------------ .../KestrelConfigurationLoader.cs | 3 ++ src/Kestrel.Core/KestrelServerOptions.cs | 53 ++++++++++++++++++- .../ListenOptionsHttpsExtensions.cs | 2 + test/Kestrel.Core.Tests/KestrelServerTests.cs | 4 +- test/Kestrel.FunctionalTests/HttpsTests.cs | 50 +++++++++++++---- 6 files changed, 100 insertions(+), 45 deletions(-) diff --git a/src/Kestrel.Core/Internal/KestrelServerOptionsSetup.cs b/src/Kestrel.Core/Internal/KestrelServerOptionsSetup.cs index 013ce0ac80..18c96e2039 100644 --- a/src/Kestrel.Core/Internal/KestrelServerOptionsSetup.cs +++ b/src/Kestrel.Core/Internal/KestrelServerOptionsSetup.cs @@ -2,12 +2,6 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.Linq; -using System.Security.Cryptography.X509Certificates; -using Microsoft.AspNetCore.Certificates.Generation; -using Microsoft.AspNetCore.Server.Kestrel.Internal; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal @@ -24,33 +18,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal public void Configure(KestrelServerOptions options) { options.ApplicationServices = _services; - UseDefaultDeveloperCertificate(options); - } - - private void UseDefaultDeveloperCertificate(KestrelServerOptions options) - { - var logger = options.ApplicationServices.GetRequiredService>(); - X509Certificate2 certificate = null; - try - { - var certificateManager = new CertificateManager(); - certificate = certificateManager.ListCertificates(CertificatePurpose.HTTPS, StoreName.My, StoreLocation.CurrentUser, isValid: true) - .FirstOrDefault(); - } - catch - { - logger.UnableToLocateDevelopmentCertificate(); - } - - if (certificate != null) - { - logger.LocatedDevelopmentCertificate(certificate); - options.DefaultCertificate = certificate; - } - else - { - logger.UnableToLocateDevelopmentCertificate(); - } } } } diff --git a/src/Kestrel.Core/KestrelConfigurationLoader.cs b/src/Kestrel.Core/KestrelConfigurationLoader.cs index b6468374b2..60204443f6 100644 --- a/src/Kestrel.Core/KestrelConfigurationLoader.cs +++ b/src/Kestrel.Core/KestrelConfigurationLoader.cs @@ -225,6 +225,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel // Specified httpsOptions.ServerCertificate = LoadCertificate(endpoint.Certificate, endpoint.Name) ?? httpsOptions.ServerCertificate; + + // Fallback + Options.ApplyDefaultCert(httpsOptions); } if (EndpointConfigurations.TryGetValue(endpoint.Name, out var configureEndpoint)) diff --git a/src/Kestrel.Core/KestrelServerOptions.cs b/src/Kestrel.Core/KestrelServerOptions.cs index b4354d4c0a..6c62edc336 100644 --- a/src/Kestrel.Core/KestrelServerOptions.cs +++ b/src/Kestrel.Core/KestrelServerOptions.cs @@ -3,12 +3,17 @@ using System; using System.Collections.Generic; +using System.Linq; using System.Net; using System.Security.Cryptography.X509Certificates; +using Microsoft.AspNetCore.Certificates.Generation; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Server.Kestrel.Https; +using Microsoft.AspNetCore.Server.Kestrel.Internal; using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; namespace Microsoft.AspNetCore.Server.Kestrel.Core { @@ -75,10 +80,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core private Action HttpsDefaults { get; set; } = _ => { }; /// - /// The default server certificate for https endpoints. This is applied before HttpsDefaults. + /// The default server certificate for https endpoints. This is applied lazily after HttpsDefaults and user options. /// internal X509Certificate2 DefaultCertificate { get; set; } + /// + /// Has the default dev certificate load been attempted? + /// + internal bool IsDevCertLoaded { get; set; } + /// /// Specifies a configuration Action to run for each newly created endpoint. Calling this again will replace /// the prior action. @@ -105,10 +115,49 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core internal void ApplyHttpsDefaults(HttpsConnectionAdapterOptions httpsOptions) { - httpsOptions.ServerCertificate = DefaultCertificate; HttpsDefaults(httpsOptions); } + internal void ApplyDefaultCert(HttpsConnectionAdapterOptions httpsOptions) + { + if (httpsOptions.ServerCertificate != null || httpsOptions.ServerCertificateSelector != null) + { + return; + } + + EnsureDefaultCert(); + + httpsOptions.ServerCertificate = DefaultCertificate; + } + + private void EnsureDefaultCert() + { + if (DefaultCertificate == null && !IsDevCertLoaded) + { + IsDevCertLoaded = true; // Only try once + var logger = ApplicationServices.GetRequiredService>(); + try + { + var certificateManager = new CertificateManager(); + DefaultCertificate = certificateManager.ListCertificates(CertificatePurpose.HTTPS, StoreName.My, StoreLocation.CurrentUser, isValid: true) + .FirstOrDefault(); + + if (DefaultCertificate != null) + { + logger.LocatedDevelopmentCertificate(DefaultCertificate); + } + else + { + logger.UnableToLocateDevelopmentCertificate(); + } + } + catch + { + logger.UnableToLocateDevelopmentCertificate(); + } + } + } + /// /// Creates a configuration loader for setting up Kestrel. /// diff --git a/src/Kestrel.Core/ListenOptionsHttpsExtensions.cs b/src/Kestrel.Core/ListenOptionsHttpsExtensions.cs index 162ee59d40..80c6eda3d2 100644 --- a/src/Kestrel.Core/ListenOptionsHttpsExtensions.cs +++ b/src/Kestrel.Core/ListenOptionsHttpsExtensions.cs @@ -178,6 +178,7 @@ namespace Microsoft.AspNetCore.Hosting var options = new HttpsConnectionAdapterOptions(); listenOptions.KestrelServerOptions.ApplyHttpsDefaults(options); configureOptions(options); + listenOptions.KestrelServerOptions.ApplyDefaultCert(options); if (options.ServerCertificate == null && options.ServerCertificateSelector == null) { @@ -191,6 +192,7 @@ namespace Microsoft.AspNetCore.Hosting { var options = new HttpsConnectionAdapterOptions(); listenOptions.KestrelServerOptions.ApplyHttpsDefaults(options); + listenOptions.KestrelServerOptions.ApplyDefaultCert(options); if (options.ServerCertificate == null && options.ServerCertificateSelector == null) { diff --git a/test/Kestrel.Core.Tests/KestrelServerTests.cs b/test/Kestrel.Core.Tests/KestrelServerTests.cs index 10de4f2fa6..e8a2ca2a13 100644 --- a/test/Kestrel.Core.Tests/KestrelServerTests.cs +++ b/test/Kestrel.Core.Tests/KestrelServerTests.cs @@ -65,7 +65,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests [Fact] public void KestrelServerThrowsUsefulExceptionIfDefaultHttpsProviderNotAdded() { - using (var server = CreateServer(CreateServerOptions(), throwOnCriticalErrors: false)) + var options = CreateServerOptions(); + options.IsDevCertLoaded = true; // Prevent the system default from being loaded + using (var server = CreateServer(options, throwOnCriticalErrors: false)) { server.Features.Get().Addresses.Add("https://127.0.0.1:0"); diff --git a/test/Kestrel.FunctionalTests/HttpsTests.cs b/test/Kestrel.FunctionalTests/HttpsTests.cs index 481f3ef2bd..29a598dee1 100644 --- a/test/Kestrel.FunctionalTests/HttpsTests.cs +++ b/test/Kestrel.FunctionalTests/HttpsTests.cs @@ -47,25 +47,56 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests options.UseHttps(); }); + Assert.False(serverOptions.IsDevCertLoaded); + serverOptions.ListenLocalhost(5001, options => { options.UseHttps(opt => { - Assert.Equal(defaultCert, opt.ServerCertificate); + // The default cert is applied after UseHttps. + Assert.Null(opt.ServerCertificate); }); }); + Assert.False(serverOptions.IsDevCertLoaded); } [Fact] - public void ConfigureHttpsDefaultsOverridesDefaultCert() + public void ConfigureHttpsDefaultsNeverLoadsDefaultCert() { var serverOptions = CreateServerOptions(); - var defaultCert = new X509Certificate2(TestResources.TestCertificatePath, "testPassword"); - serverOptions.DefaultCertificate = defaultCert; + var testCert = new X509Certificate2(TestResources.TestCertificatePath, "testPassword"); serverOptions.ConfigureHttpsDefaults(options => { - Assert.Equal(defaultCert, options.ServerCertificate); - options.ServerCertificate = null; + Assert.Null(options.ServerCertificate); + options.ServerCertificate = testCert; + options.ClientCertificateMode = ClientCertificateMode.RequireCertificate; + }); + serverOptions.ListenLocalhost(5000, options => + { + options.UseHttps(opt => + { + Assert.Equal(testCert, opt.ServerCertificate); + Assert.Equal(ClientCertificateMode.RequireCertificate, opt.ClientCertificateMode); + }); + }); + // Never lazy loaded + Assert.False(serverOptions.IsDevCertLoaded); + Assert.Null(serverOptions.DefaultCertificate); + } + + [Fact] + public void ConfigureCertSelectorNeverLoadsDefaultCert() + { + var serverOptions = CreateServerOptions(); + var testCert = new X509Certificate2(TestResources.TestCertificatePath, "testPassword"); + serverOptions.ConfigureHttpsDefaults(options => + { + Assert.Null(options.ServerCertificate); + Assert.Null(options.ServerCertificateSelector); + options.ServerCertificateSelector = (features, name) => + { + return testCert; + }; options.ClientCertificateMode = ClientCertificateMode.RequireCertificate; }); serverOptions.ListenLocalhost(5000, options => @@ -73,12 +104,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests options.UseHttps(opt => { Assert.Null(opt.ServerCertificate); + Assert.NotNull(opt.ServerCertificateSelector); Assert.Equal(ClientCertificateMode.RequireCertificate, opt.ClientCertificateMode); - - // So UseHttps won't throw - opt.ServerCertificate = defaultCert; }); }); + // Never lazy loaded + Assert.False(serverOptions.IsDevCertLoaded); + Assert.Null(serverOptions.DefaultCertificate); } [Fact] From 4760cce6aa7c3e1040be36d461b5f0823f794636 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Sat, 7 Apr 2018 18:55:59 -0700 Subject: [PATCH 1611/1662] Remove IConnection (#2472) --- src/Connections.Abstractions/IConnection.cs | 17 ----------------- 1 file changed, 17 deletions(-) delete mode 100644 src/Connections.Abstractions/IConnection.cs diff --git a/src/Connections.Abstractions/IConnection.cs b/src/Connections.Abstractions/IConnection.cs deleted file mode 100644 index 4f116a8433..0000000000 --- a/src/Connections.Abstractions/IConnection.cs +++ /dev/null @@ -1,17 +0,0 @@ -using System.Collections.Generic; -using System.IO.Pipelines; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Http.Features; - -namespace Microsoft.AspNetCore.Connections -{ - public interface IConnection - { - IDuplexPipe Transport { get; } - IFeatureCollection Features { get; } - - Task StartAsync(); - Task StartAsync(TransferFormat transferFormat); - Task DisposeAsync(); - } -} From b030ab7e4910a6009802144d75c4ff5240dda8d4 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Mon, 9 Apr 2018 17:55:14 -0700 Subject: [PATCH 1612/1662] Update Connections.Abstractions.csproj (#2473) --- src/Connections.Abstractions/Connections.Abstractions.csproj | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Connections.Abstractions/Connections.Abstractions.csproj b/src/Connections.Abstractions/Connections.Abstractions.csproj index 6e3235be54..7ac34a26dd 100644 --- a/src/Connections.Abstractions/Connections.Abstractions.csproj +++ b/src/Connections.Abstractions/Connections.Abstractions.csproj @@ -7,7 +7,6 @@ netstandard2.0 true aspnetcore - true CS1591;$(NoWarn) From 7e5104573e69a803276918a6584b09b458ec2118 Mon Sep 17 00:00:00 2001 From: Ryan Brandenburg Date: Fri, 6 Apr 2018 15:14:21 -0700 Subject: [PATCH 1613/1662] Skip flaky tests --- test/Kestrel.FunctionalTests/AddressRegistrationTests.cs | 2 +- test/Kestrel.FunctionalTests/RequestBodyTimeoutTests.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/Kestrel.FunctionalTests/AddressRegistrationTests.cs b/test/Kestrel.FunctionalTests/AddressRegistrationTests.cs index 6e66f401bc..0c85a2a928 100644 --- a/test/Kestrel.FunctionalTests/AddressRegistrationTests.cs +++ b/test/Kestrel.FunctionalTests/AddressRegistrationTests.cs @@ -112,7 +112,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests await RegisterIPEndPoint_Success(endpoint, testUrl, 443); } - [ConditionalTheory] + [ConditionalTheory(Skip="https://github.com/aspnet/KestrelHttpServer/issues/2434")] [MemberData(nameof(AddressRegistrationDataIPv6))] [IPv6SupportedCondition] public async Task RegisterAddresses_IPv6_Success(string addressInput, string[] testUrls) diff --git a/test/Kestrel.FunctionalTests/RequestBodyTimeoutTests.cs b/test/Kestrel.FunctionalTests/RequestBodyTimeoutTests.cs index 2e162bd7a0..7cb1e1f33c 100644 --- a/test/Kestrel.FunctionalTests/RequestBodyTimeoutTests.cs +++ b/test/Kestrel.FunctionalTests/RequestBodyTimeoutTests.cs @@ -119,7 +119,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests && ((BadHttpRequestException)w.Exception).StatusCode == StatusCodes.Status408RequestTimeout); } - [Fact] + [Fact(Skip="https://github.com/aspnet/KestrelHttpServer/issues/2464")] public async Task ConnectionClosedEvenIfAppSwallowsException() { var gracePeriod = TimeSpan.FromSeconds(5); From e411cbf7e2910c848221b895cda19b77d7b9761d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Ros?= Date: Wed, 11 Apr 2018 14:27:34 -0700 Subject: [PATCH 1614/1662] Moving PlatformBenchmarks from aspnet/benchmarks (#2457) --- KestrelHttpServer.sln | 15 ++ .../PlatformBenchmarks/AsciiString.cs | 50 ++++++ .../BenchmarkApplication.cs | 156 +++++++++++++++++ .../BenchmarkConfigurationHelpers.cs | 81 +++++++++ .../BufferWriterExtensions.cs | 38 +++++ .../PlatformBenchmarks/DateHeader.cs | 59 +++++++ .../PlatformBenchmarks/HttpApplication.cs | 161 ++++++++++++++++++ .../PlatformBenchmarks.csproj | 28 +++ benchmarkapps/PlatformBenchmarks/Program.cs | 46 +++++ benchmarkapps/PlatformBenchmarks/Startup.cs | 19 +++ .../PlatformBenchmarks/benchmarks.json.json | 15 ++ .../benchmarks.plaintext.json | 26 +++ build/dependencies.props | 3 + 13 files changed, 697 insertions(+) create mode 100644 benchmarkapps/PlatformBenchmarks/AsciiString.cs create mode 100644 benchmarkapps/PlatformBenchmarks/BenchmarkApplication.cs create mode 100644 benchmarkapps/PlatformBenchmarks/BenchmarkConfigurationHelpers.cs create mode 100644 benchmarkapps/PlatformBenchmarks/BufferWriterExtensions.cs create mode 100644 benchmarkapps/PlatformBenchmarks/DateHeader.cs create mode 100644 benchmarkapps/PlatformBenchmarks/HttpApplication.cs create mode 100644 benchmarkapps/PlatformBenchmarks/PlatformBenchmarks.csproj create mode 100644 benchmarkapps/PlatformBenchmarks/Program.cs create mode 100644 benchmarkapps/PlatformBenchmarks/Startup.cs create mode 100644 benchmarkapps/PlatformBenchmarks/benchmarks.json.json create mode 100644 benchmarkapps/PlatformBenchmarks/benchmarks.plaintext.json diff --git a/KestrelHttpServer.sln b/KestrelHttpServer.sln index 09077ead0e..41323981f7 100644 --- a/KestrelHttpServer.sln +++ b/KestrelHttpServer.sln @@ -126,6 +126,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SystemdTestApp", "samples\S EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PlaintextApp", "samples\PlaintextApp\PlaintextApp.csproj", "{CE5523AE-6E38-4E20-998F-C64E02C5CC51}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PlatformBenchmarks", "benchmarkapps\PlatformBenchmarks\PlatformBenchmarks.csproj", "{7C24EAB8-57A9-4613-A8A6-4C21BB7D260D}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -364,6 +366,18 @@ Global {CE5523AE-6E38-4E20-998F-C64E02C5CC51}.Release|x64.Build.0 = Release|Any CPU {CE5523AE-6E38-4E20-998F-C64E02C5CC51}.Release|x86.ActiveCfg = Release|Any CPU {CE5523AE-6E38-4E20-998F-C64E02C5CC51}.Release|x86.Build.0 = Release|Any CPU + {7C24EAB8-57A9-4613-A8A6-4C21BB7D260D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {7C24EAB8-57A9-4613-A8A6-4C21BB7D260D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {7C24EAB8-57A9-4613-A8A6-4C21BB7D260D}.Debug|x64.ActiveCfg = Debug|Any CPU + {7C24EAB8-57A9-4613-A8A6-4C21BB7D260D}.Debug|x64.Build.0 = Debug|Any CPU + {7C24EAB8-57A9-4613-A8A6-4C21BB7D260D}.Debug|x86.ActiveCfg = Debug|Any CPU + {7C24EAB8-57A9-4613-A8A6-4C21BB7D260D}.Debug|x86.Build.0 = Debug|Any CPU + {7C24EAB8-57A9-4613-A8A6-4C21BB7D260D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {7C24EAB8-57A9-4613-A8A6-4C21BB7D260D}.Release|Any CPU.Build.0 = Release|Any CPU + {7C24EAB8-57A9-4613-A8A6-4C21BB7D260D}.Release|x64.ActiveCfg = Release|Any CPU + {7C24EAB8-57A9-4613-A8A6-4C21BB7D260D}.Release|x64.Build.0 = Release|Any CPU + {7C24EAB8-57A9-4613-A8A6-4C21BB7D260D}.Release|x86.ActiveCfg = Release|Any CPU + {7C24EAB8-57A9-4613-A8A6-4C21BB7D260D}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -390,6 +404,7 @@ Global {7BC22A4A-15D2-44C2-AB45-049F0FB562FA} = {8A3D00B8-1CCF-4BE6-A060-11104CE2D9CE} {A7994A41-CAF8-47A7-8975-F101F75B5BC1} = {8A3D00B8-1CCF-4BE6-A060-11104CE2D9CE} {CE5523AE-6E38-4E20-998F-C64E02C5CC51} = {8A3D00B8-1CCF-4BE6-A060-11104CE2D9CE} + {7C24EAB8-57A9-4613-A8A6-4C21BB7D260D} = {A95C3BE1-B850-4265-97A0-777ADCCD437F} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {2D10D020-6770-47CA-BB8D-2C23FE3AE071} diff --git a/benchmarkapps/PlatformBenchmarks/AsciiString.cs b/benchmarkapps/PlatformBenchmarks/AsciiString.cs new file mode 100644 index 0000000000..f84d42c978 --- /dev/null +++ b/benchmarkapps/PlatformBenchmarks/AsciiString.cs @@ -0,0 +1,50 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Text; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; + +namespace PlatformBenchmarks +{ + public struct AsciiString : IEquatable + { + private readonly byte[] _data; + + public AsciiString(string s) => _data = Encoding.ASCII.GetBytes(s); + + public int Length => _data.Length; + + public ReadOnlySpan AsSpan() => _data; + + public static implicit operator ReadOnlySpan(AsciiString str) => str._data; + public static implicit operator byte[] (AsciiString str) => str._data; + + public static implicit operator AsciiString(string str) => new AsciiString(str); + + public override string ToString() => HttpUtilities.GetAsciiStringNonNullCharacters(_data); + public static explicit operator string(AsciiString str) => str.ToString(); + + public bool Equals(AsciiString other) => ReferenceEquals(_data, other._data) || SequenceEqual(_data, other._data); + private bool SequenceEqual(byte[] data1, byte[] data2) => new Span(data1).SequenceEqual(data2); + + public static bool operator ==(AsciiString a, AsciiString b) => a.Equals(b); + public static bool operator !=(AsciiString a, AsciiString b) => !a.Equals(b); + public override bool Equals(object other) => (other is AsciiString) && Equals((AsciiString)other); + + public override int GetHashCode() + { + // Copied from x64 version of string.GetLegacyNonRandomizedHashCode() + // https://github.com/dotnet/coreclr/blob/master/src/mscorlib/src/System/String.Comparison.cs + var data = _data; + int hash1 = 5381; + int hash2 = hash1; + foreach (int b in data) + { + hash1 = ((hash1 << 5) + hash1) ^ b; + } + return hash1 + (hash2 * 1566083941); + } + + } +} diff --git a/benchmarkapps/PlatformBenchmarks/BenchmarkApplication.cs b/benchmarkapps/PlatformBenchmarks/BenchmarkApplication.cs new file mode 100644 index 0000000000..6551bee358 --- /dev/null +++ b/benchmarkapps/PlatformBenchmarks/BenchmarkApplication.cs @@ -0,0 +1,156 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Buffers; +using System.IO.Pipelines; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; +using Utf8Json; + +namespace PlatformBenchmarks +{ + public class BenchmarkApplication : HttpConnection + { + private static AsciiString _crlf = "\r\n"; + private static AsciiString _eoh = "\r\n\r\n"; // End Of Headers + private static AsciiString _http11OK = "HTTP/1.1 200 OK\r\n"; + private static AsciiString _headerServer = "Server: Custom"; + private static AsciiString _headerContentLength = "Content-Length: "; + private static AsciiString _headerContentLengthZero = "Content-Length: 0\r\n"; + private static AsciiString _headerContentTypeText = "Content-Type: text/plain\r\n"; + private static AsciiString _headerContentTypeJson = "Content-Type: application/json\r\n"; + + + private static AsciiString _plainTextBody = "Hello, World!"; + + private static class Paths + { + public static AsciiString Plaintext = "/plaintext"; + public static AsciiString Json = "/json"; + } + + private bool _isPlainText; + private bool _isJson; + + public override void OnStartLine(HttpMethod method, HttpVersion version, Span target, Span path, Span query, Span customMethod, bool pathEncoded) + { + if (path.StartsWith(Paths.Plaintext) && method == HttpMethod.Get) + { + _isPlainText = true; + } + else if (path.StartsWith(Paths.Json) && method == HttpMethod.Get) + { + _isJson = true; + } + else + { + _isPlainText = false; + _isJson = false; + } + } + + public override void OnHeader(Span name, Span value) + { + } + + public override ValueTask ProcessRequestAsync() + { + if (_isPlainText) + { + PlainText(Writer); + } + else if (_isJson) + { + Json(Writer); + } + else + { + Default(Writer); + } + + return default; + } + + public override async ValueTask OnReadCompletedAsync() + { + await Writer.FlushAsync(); + } + private static void PlainText(PipeWriter pipeWriter) + { + var writer = new BufferWriter(pipeWriter); + // HTTP 1.1 OK + writer.Write(_http11OK); + + // Server headers + writer.Write(_headerServer); + + // Date header + writer.Write(DateHeader.HeaderBytes); + + // Content-Type header + writer.Write(_headerContentTypeText); + + // Content-Length header + writer.Write(_headerContentLength); + writer.WriteNumeric((ulong)_plainTextBody.Length); + + // End of headers + writer.Write(_eoh); + + // Body + writer.Write(_plainTextBody); + writer.Commit(); + } + + private static void Json(PipeWriter pipeWriter) + { + var writer = new BufferWriter(pipeWriter); + + // HTTP 1.1 OK + writer.Write(_http11OK); + + // Server headers + writer.Write(_headerServer); + + // Date header + writer.Write(DateHeader.HeaderBytes); + + // Content-Type header + writer.Write(_headerContentTypeJson); + + // Content-Length header + writer.Write(_headerContentLength); + var jsonPayload = JsonSerializer.SerializeUnsafe(new { message = "Hello, World!" }); + writer.WriteNumeric((ulong)jsonPayload.Count); + + // End of headers + writer.Write(_eoh); + + // Body + writer.Write(jsonPayload); + writer.Commit(); + } + + private static void Default(PipeWriter pipeWriter) + { + var writer = new BufferWriter(pipeWriter); + + // HTTP 1.1 OK + writer.Write(_http11OK); + + // Server headers + writer.Write(_headerServer); + + // Date header + writer.Write(DateHeader.HeaderBytes); + + // Content-Length 0 + writer.Write(_headerContentLengthZero); + + // End of headers + writer.Write(_crlf); + writer.Commit(); + } + } +} diff --git a/benchmarkapps/PlatformBenchmarks/BenchmarkConfigurationHelpers.cs b/benchmarkapps/PlatformBenchmarks/BenchmarkConfigurationHelpers.cs new file mode 100644 index 0000000000..c6d2cdbdf9 --- /dev/null +++ b/benchmarkapps/PlatformBenchmarks/BenchmarkConfigurationHelpers.cs @@ -0,0 +1,81 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Net; +using Microsoft.AspNetCore; +using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Server.Kestrel.Core; +using Microsoft.Extensions.Configuration; + +namespace PlatformBenchmarks +{ + public static class BenchmarkConfigurationHelpers + { + public static IWebHostBuilder UseBenchmarksConfiguration(this IWebHostBuilder builder, IConfiguration configuration) + { + builder.UseConfiguration(configuration); + + // Handle the transport type + var webHost = builder.GetSetting("KestrelTransport"); + + // Handle the thread count + var threadCountRaw = builder.GetSetting("threadCount"); + int? theadCount = null; + + if (!string.IsNullOrEmpty(threadCountRaw) && + Int32.TryParse(threadCountRaw, out var value)) + { + theadCount = value; + } + + if (string.Equals(webHost, "Libuv", StringComparison.OrdinalIgnoreCase)) + { + builder.UseLibuv(options => + { + if (theadCount.HasValue) + { + options.ThreadCount = theadCount.Value; + } + }); + } + else if (string.Equals(webHost, "Sockets", StringComparison.OrdinalIgnoreCase)) + { + builder.UseSockets(options => + { + if (theadCount.HasValue) + { + options.IOQueueCount = theadCount.Value; + } + }); + } + + return builder; + } + + public static IPEndPoint CreateIPEndPoint(this IConfiguration config) + { + var url = config["server.urls"] ?? config["urls"]; + + if (string.IsNullOrEmpty(url)) + { + return new IPEndPoint(IPAddress.Loopback, 8080); + } + + var address = ServerAddress.FromUrl(url); + + IPAddress ip; + + if (string.Equals(address.Host, "localhost", StringComparison.OrdinalIgnoreCase)) + { + ip = IPAddress.Loopback; + } + else if (!IPAddress.TryParse(address.Host, out ip)) + { + ip = IPAddress.IPv6Any; + } + + return new IPEndPoint(ip, address.Port); + } + } +} diff --git a/benchmarkapps/PlatformBenchmarks/BufferWriterExtensions.cs b/benchmarkapps/PlatformBenchmarks/BufferWriterExtensions.cs new file mode 100644 index 0000000000..0da6b24fd4 --- /dev/null +++ b/benchmarkapps/PlatformBenchmarks/BufferWriterExtensions.cs @@ -0,0 +1,38 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System.Buffers.Text; +using System.Diagnostics; +using System.IO.Pipelines; +using System.Runtime.CompilerServices; + +namespace System.Buffers +{ + internal static class BufferWriterExtensions + { + private const int MaxULongByteLength = 20; + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + internal static void WriteNumeric(ref this BufferWriter buffer, ulong number) + { + // Try to format directly + if (Utf8Formatter.TryFormat(number, buffer.Span, out int bytesWritten)) + { + buffer.Advance(bytesWritten); + } + else + { + // Ask for at least 20 bytes + buffer.Ensure(MaxULongByteLength); + + Debug.Assert(buffer.Span.Length >= 20, "Buffer is < 20 bytes"); + + // Try again + if (Utf8Formatter.TryFormat(number, buffer.Span, out bytesWritten)) + { + buffer.Advance(bytesWritten); + } + } + } + } +} \ No newline at end of file diff --git a/benchmarkapps/PlatformBenchmarks/DateHeader.cs b/benchmarkapps/PlatformBenchmarks/DateHeader.cs new file mode 100644 index 0000000000..1d03d78b53 --- /dev/null +++ b/benchmarkapps/PlatformBenchmarks/DateHeader.cs @@ -0,0 +1,59 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Buffers.Text; +using System.Diagnostics; +using System.Text; +using System.Threading; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; + +namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http +{ + /// + /// Manages the generation of the date header value. + /// + internal static class DateHeader + { + const int prefixLength = 8; // "\r\nDate: ".Length + const int dateTimeRLength = 29; // Wed, 14 Mar 2018 14:20:00 GMT + const int suffixLength = 2; // crlf + const int suffixIndex = dateTimeRLength + prefixLength; + + private static readonly Timer s_timer = new Timer((s) => { + SetDateValues(DateTimeOffset.UtcNow); + }, null, 1000, 1000); + + private static byte[] s_headerBytesMaster = new byte[prefixLength + dateTimeRLength + suffixLength]; + private static byte[] s_headerBytesScratch = new byte[prefixLength + dateTimeRLength + suffixLength]; + + static DateHeader() + { + var utf8 = Encoding.ASCII.GetBytes("\r\nDate: ").AsSpan(); + utf8.CopyTo(s_headerBytesMaster); + utf8.CopyTo(s_headerBytesScratch); + s_headerBytesMaster[suffixIndex] = (byte)'\r'; + s_headerBytesMaster[suffixIndex + 1] = (byte)'\n'; + s_headerBytesScratch[suffixIndex] = (byte)'\r'; + s_headerBytesScratch[suffixIndex + 1] = (byte)'\n'; + SetDateValues(DateTimeOffset.UtcNow); + } + + public static ReadOnlySpan HeaderBytes => s_headerBytesMaster; + + private static void SetDateValues(DateTimeOffset value) + { + lock (s_headerBytesScratch) + { + if (!Utf8Formatter.TryFormat(value, s_headerBytesScratch.AsSpan().Slice(prefixLength), out int written, 'R')) + { + throw new Exception("date time format failed"); + } + Debug.Assert(written == dateTimeRLength); + var temp = s_headerBytesMaster; + s_headerBytesMaster = s_headerBytesScratch; + s_headerBytesScratch = temp; + } + } + } +} \ No newline at end of file diff --git a/benchmarkapps/PlatformBenchmarks/HttpApplication.cs b/benchmarkapps/PlatformBenchmarks/HttpApplication.cs new file mode 100644 index 0000000000..e9b20f5aaa --- /dev/null +++ b/benchmarkapps/PlatformBenchmarks/HttpApplication.cs @@ -0,0 +1,161 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Buffers; +using System.IO.Pipelines; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Connections; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; + +namespace PlatformBenchmarks +{ + public static class HttpApplicationConnectionBuilderExtensions + { + public static IConnectionBuilder UseHttpApplication(this IConnectionBuilder builder) where TConnection : HttpConnection, new() + { + return builder.Use(next => new HttpApplication().ExecuteAsync); + } + } + + public class HttpApplication where TConnection : HttpConnection, new() + { + public Task ExecuteAsync(ConnectionContext connection) + { + var parser = new HttpParser(); + + var httpConnection = new TConnection + { + Parser = parser, + Reader = connection.Transport.Input, + Writer = connection.Transport.Output + }; + return httpConnection.ExecuteAsync(); + } + } + + public class HttpConnection : IHttpHeadersHandler, IHttpRequestLineHandler + { + private State _state; + + public PipeReader Reader { get; set; } + public PipeWriter Writer { get; set; } + + internal HttpParser Parser { get; set; } + + public virtual void OnHeader(Span name, Span value) + { + + } + + public virtual void OnStartLine(HttpMethod method, HttpVersion version, Span target, Span path, Span query, Span customMethod, bool pathEncoded) + { + + } + + public virtual ValueTask ProcessRequestAsync() + { + return default; + } + + public virtual ValueTask OnReadCompletedAsync() + { + return default; + } + + public async Task ExecuteAsync() + { + try + { + await ProcessRequestsAsync(); + + Reader.Complete(); + } + catch (Exception ex) + { + Reader.Complete(ex); + } + finally + { + Writer.Complete(); + } + } + + private async Task ProcessRequestsAsync() + { + while (true) + { + var task = Reader.ReadAsync(); + + if (!task.IsCompleted) + { + // No more data in the input + await OnReadCompletedAsync(); + } + + var result = await task; + var buffer = result.Buffer; + var consumed = buffer.Start; + var examined = buffer.End; + + if (!buffer.IsEmpty) + { + ParseHttpRequest(buffer, out consumed, out examined); + + if (_state != State.Body && result.IsCompleted) + { + ThrowUnexpectedEndOfData(); + } + } + else if (result.IsCompleted) + { + break; + } + + Reader.AdvanceTo(consumed, examined); + + if (_state == State.Body) + { + await ProcessRequestAsync(); + + _state = State.StartLine; + } + } + } + + private void ParseHttpRequest(in ReadOnlySequence buffer, out SequencePosition consumed, out SequencePosition examined) + { + consumed = buffer.Start; + examined = buffer.End; + + var parsingStartLine = _state == State.StartLine; + if (parsingStartLine) + { + if (Parser.ParseRequestLine(this, buffer, out consumed, out examined)) + { + _state = State.Headers; + } + } + + if (_state == State.Headers) + { + if (Parser.ParseHeaders(this, parsingStartLine ? buffer.Slice(consumed) : buffer, out consumed, out examined, out int consumedBytes)) + { + _state = State.Body; + } + } + } + + private static void ThrowUnexpectedEndOfData() + { + throw new InvalidOperationException("Unexpected end of data!"); + } + + private enum State + { + StartLine, + Headers, + Body + } + } +} diff --git a/benchmarkapps/PlatformBenchmarks/PlatformBenchmarks.csproj b/benchmarkapps/PlatformBenchmarks/PlatformBenchmarks.csproj new file mode 100644 index 0000000000..a883710816 --- /dev/null +++ b/benchmarkapps/PlatformBenchmarks/PlatformBenchmarks.csproj @@ -0,0 +1,28 @@ + + + + netcoreapp2.1 + Exe + latest + true + + + + + + + + + + + + + + + + + + + + + diff --git a/benchmarkapps/PlatformBenchmarks/Program.cs b/benchmarkapps/PlatformBenchmarks/Program.cs new file mode 100644 index 0000000000..7776cbd1ce --- /dev/null +++ b/benchmarkapps/PlatformBenchmarks/Program.cs @@ -0,0 +1,46 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Net; +using Microsoft.AspNetCore; +using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Server.Kestrel.Core; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; + +namespace PlatformBenchmarks +{ + public class Program + { + public static void Main(string[] args) + { + BuildWebHost(args).Run(); + } + + public static IWebHost BuildWebHost(string[] args) + { + var config = new ConfigurationBuilder() + .AddEnvironmentVariables(prefix: "ASPNETCORE_") + .AddCommandLine(args) + .Build(); + + var host = new WebHostBuilder() + .UseBenchmarksConfiguration(config) + .UseKestrel((context, options) => + { + IPEndPoint endPoint = context.Configuration.CreateIPEndPoint(); + + options.Listen(endPoint, builder => + { + builder.UseHttpApplication(); + }); + }) + .UseStartup() + .Build(); + + return host; + } + } +} diff --git a/benchmarkapps/PlatformBenchmarks/Startup.cs b/benchmarkapps/PlatformBenchmarks/Startup.cs new file mode 100644 index 0000000000..bfc1f70375 --- /dev/null +++ b/benchmarkapps/PlatformBenchmarks/Startup.cs @@ -0,0 +1,19 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Net.WebSockets; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Hosting; + +namespace PlatformBenchmarks +{ + public class Startup + { + public void Configure(IApplicationBuilder app) + { + + } + } +} diff --git a/benchmarkapps/PlatformBenchmarks/benchmarks.json.json b/benchmarkapps/PlatformBenchmarks/benchmarks.json.json new file mode 100644 index 0000000000..157cee28dc --- /dev/null +++ b/benchmarkapps/PlatformBenchmarks/benchmarks.json.json @@ -0,0 +1,15 @@ +{ + "Default": { + "Client": "Wrk", + "PresetHeaders": "Json", + + "Source": { + "Repository": "https://github.com/aspnet/KestrelHttpServer.git", + "BranchOrCommit": "dev", + "Project": "benchmarkapps/PlatformBenchmarks/PlatformBenchmarks.csproj" + } + }, + "JsonPlatform": { + "Path": "/json" + } +} \ No newline at end of file diff --git a/benchmarkapps/PlatformBenchmarks/benchmarks.plaintext.json b/benchmarkapps/PlatformBenchmarks/benchmarks.plaintext.json new file mode 100644 index 0000000000..5ad58aee15 --- /dev/null +++ b/benchmarkapps/PlatformBenchmarks/benchmarks.plaintext.json @@ -0,0 +1,26 @@ +{ + "Default": { + "Client": "Wrk", + "PresetHeaders": "Plaintext", + "ClientProperties": { + "ScriptName": "pipeline", + "PipelineDepth": 16 + }, + "Source": { + "Repository": "https://github.com/aspnet/KestrelHttpServer.git", + "BranchOrCommit": "dev", + "Project": "benchmarkapps/PlatformBenchmarks/PlatformBenchmarks.csproj" + }, + "Port": 8080 + }, + "PlaintextPlatform": { + "Path": "/plaintext" + }, + "PlaintextNonPipelinedPlatform": { + "Path": "/plaintext", + "ClientProperties": { + "ScriptName": "", + "PipelineDepth": 0 + } + } +} diff --git a/build/dependencies.props b/build/dependencies.props index 9831c511ea..ace613e29c 100644 --- a/build/dependencies.props +++ b/build/dependencies.props @@ -7,6 +7,7 @@ 0.10.13 2.1.0-preview3-17002 1.10.0 + 2.1.0-preview3-32110 2.1.0-preview3-32110 2.1.0-preview3-32110 2.1.0-preview3-32110 @@ -20,6 +21,7 @@ 2.1.0-preview3-32110 2.1.0-preview3-32110 2.1.0-preview3-32110 + 2.1.0-preview3-32037 2.1.0-preview3-32110 2.1.0-preview3-32110 2.1.0-preview3-32110 @@ -40,6 +42,7 @@ 4.5.0-preview3-26331-02 4.5.0-preview3-26331-02 4.5.0-preview3-26331-02 + 1.3.7 0.8.0 2.3.1 2.4.0-beta.1.build3945 From e8bb88cb58638794b5b8683487b0e7ef85126c16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Ros?= Date: Wed, 11 Apr 2018 14:27:53 -0700 Subject: [PATCH 1615/1662] Fixing typo (#2477) --- src/Kestrel.Core/Internal/Infrastructure/KestrelTrace.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Kestrel.Core/Internal/Infrastructure/KestrelTrace.cs b/src/Kestrel.Core/Internal/Infrastructure/KestrelTrace.cs index bef321b8bf..0314b4fdf5 100644 --- a/src/Kestrel.Core/Internal/Infrastructure/KestrelTrace.cs +++ b/src/Kestrel.Core/Internal/Infrastructure/KestrelTrace.cs @@ -66,7 +66,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal LoggerMessage.Define(LogLevel.Information, new EventId(27, nameof(RequestBodyMininumDataRateNotSatisfied)), @"Connection id ""{ConnectionId}"", Request id ""{TraceIdentifier}"": the request timed out because it was not sent by the client at a minimum of {Rate} bytes/second."); private static readonly Action _responseMinimumDataRateNotSatisfied = - LoggerMessage.Define(LogLevel.Information, new EventId(28, nameof(ResponseMininumDataRateNotSatisfied)), @"Connection id ""{ConnectionId}"", Request id ""{TraceIdentifier}"": the connection was closed becuase the response was not read by the client at the specified minimum data rate."); + LoggerMessage.Define(LogLevel.Information, new EventId(28, nameof(ResponseMininumDataRateNotSatisfied)), @"Connection id ""{ConnectionId}"", Request id ""{TraceIdentifier}"": the connection was closed because the response was not read by the client at the specified minimum data rate."); private static readonly Action _http2ConnectionError = LoggerMessage.Define(LogLevel.Information, new EventId(29, nameof(Http2ConnectionError)), @"Connection id ""{ConnectionId}"": HTTP/2 connection error."); From f6b2880369f8ff81052f15ad7021753b0710f44e Mon Sep 17 00:00:00 2001 From: David Fowler Date: Wed, 11 Apr 2018 15:56:25 -0700 Subject: [PATCH 1616/1662] Flow the ConnectionContext to the SNI callback (#2478) --- .../Internal/ConnectionAdapterContext.cs | 9 ++++++--- .../HttpsConnectionAdapterOptions.cs | 4 ++-- src/Kestrel.Core/Internal/HttpConnection.cs | 4 ++-- .../Internal/HttpConnectionContext.cs | 2 ++ .../Internal/HttpConnectionMiddleware.cs | 3 ++- .../Internal/HttpsConnectionAdapter.cs | 7 ++++--- .../HttpsConnectionAdapterTests.cs | 18 +++++++++--------- 7 files changed, 27 insertions(+), 20 deletions(-) diff --git a/src/Kestrel.Core/Adapter/Internal/ConnectionAdapterContext.cs b/src/Kestrel.Core/Adapter/Internal/ConnectionAdapterContext.cs index 1f87c8311e..3896e1cf85 100644 --- a/src/Kestrel.Core/Adapter/Internal/ConnectionAdapterContext.cs +++ b/src/Kestrel.Core/Adapter/Internal/ConnectionAdapterContext.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.IO; +using Microsoft.AspNetCore.Connections; using Microsoft.AspNetCore.Http.Features; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal @@ -10,13 +11,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal // we want to add more connection metadata later. public class ConnectionAdapterContext { - internal ConnectionAdapterContext(IFeatureCollection features, Stream connectionStream) + internal ConnectionAdapterContext(ConnectionContext connectionContext, Stream connectionStream) { - Features = features; + ConnectionContext = connectionContext; ConnectionStream = connectionStream; } - public IFeatureCollection Features { get; } + internal ConnectionContext ConnectionContext { get; } + + public IFeatureCollection Features => ConnectionContext.Features; public Stream ConnectionStream { get; } } diff --git a/src/Kestrel.Core/HttpsConnectionAdapterOptions.cs b/src/Kestrel.Core/HttpsConnectionAdapterOptions.cs index 760c29cfc1..cf6bd88236 100644 --- a/src/Kestrel.Core/HttpsConnectionAdapterOptions.cs +++ b/src/Kestrel.Core/HttpsConnectionAdapterOptions.cs @@ -6,7 +6,7 @@ using System.Net.Security; using System.Security.Authentication; using System.Security.Cryptography.X509Certificates; using System.Threading; -using Microsoft.AspNetCore.Http.Features; +using Microsoft.AspNetCore.Connections; using Microsoft.AspNetCore.Server.Kestrel.Core; namespace Microsoft.AspNetCore.Server.Kestrel.Https @@ -47,7 +47,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Https /// If the server certificate has an Extended Key Usage extension, the usages must include Server Authentication (OID 1.3.6.1.5.5.7.3.1). /// /// - public Func ServerCertificateSelector { get; set; } + public Func ServerCertificateSelector { get; set; } /// /// Specifies the client certificate requirements for a HTTPS connection. Defaults to . diff --git a/src/Kestrel.Core/Internal/HttpConnection.cs b/src/Kestrel.Core/Internal/HttpConnection.cs index 91b0887f01..d57a7f920c 100644 --- a/src/Kestrel.Core/Internal/HttpConnection.cs +++ b/src/Kestrel.Core/Internal/HttpConnection.cs @@ -300,7 +300,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal { var connectionAdapters = _context.ConnectionAdapters; var stream = new RawStream(_context.Transport.Input, _context.Transport.Output); - var adapterContext = new ConnectionAdapterContext(_context.ConnectionFeatures, stream); + var adapterContext = new ConnectionAdapterContext(_context.ConnectionContext, stream); _adaptedConnections = new List(connectionAdapters.Count); try @@ -309,7 +309,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal { var adaptedConnection = await connectionAdapters[i].OnConnectionAsync(adapterContext); _adaptedConnections.Add(adaptedConnection); - adapterContext = new ConnectionAdapterContext(_context.ConnectionFeatures, adaptedConnection.ConnectionStream); + adapterContext = new ConnectionAdapterContext(_context.ConnectionContext, adaptedConnection.ConnectionStream); } } catch (Exception ex) diff --git a/src/Kestrel.Core/Internal/HttpConnectionContext.cs b/src/Kestrel.Core/Internal/HttpConnectionContext.cs index b60d5702ac..161ca647a7 100644 --- a/src/Kestrel.Core/Internal/HttpConnectionContext.cs +++ b/src/Kestrel.Core/Internal/HttpConnectionContext.cs @@ -5,6 +5,7 @@ using System.Buffers; using System.Collections.Generic; using System.IO.Pipelines; using System.Net; +using Microsoft.AspNetCore.Connections; using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal; @@ -15,6 +16,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal public string ConnectionId { get; set; } public long HttpConnectionId { get; set; } public HttpProtocols Protocols { get; set; } + public ConnectionContext ConnectionContext { get; set; } public ServiceContext ServiceContext { get; set; } public IFeatureCollection ConnectionFeatures { get; set; } public IList ConnectionAdapters { get; set; } diff --git a/src/Kestrel.Core/Internal/HttpConnectionMiddleware.cs b/src/Kestrel.Core/Internal/HttpConnectionMiddleware.cs index 87ae45c154..fad29ae0db 100644 --- a/src/Kestrel.Core/Internal/HttpConnectionMiddleware.cs +++ b/src/Kestrel.Core/Internal/HttpConnectionMiddleware.cs @@ -41,6 +41,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal var httpConnectionContext = new HttpConnectionContext { ConnectionId = connectionContext.ConnectionId, + ConnectionContext = connectionContext, HttpConnectionId = httpConnectionId, Protocols = _protocols, ServiceContext = _serviceContext, @@ -69,7 +70,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal var connection = new HttpConnection(httpConnectionContext); var processingTask = connection.StartRequestProcessing(_application); - + connectionContext.Transport.Input.OnWriterCompleted((error, state) => { ((HttpConnection)state).Abort(error); diff --git a/src/Kestrel.Core/Internal/HttpsConnectionAdapter.cs b/src/Kestrel.Core/Internal/HttpsConnectionAdapter.cs index 4107da5118..cab926bb63 100644 --- a/src/Kestrel.Core/Internal/HttpsConnectionAdapter.cs +++ b/src/Kestrel.Core/Internal/HttpsConnectionAdapter.cs @@ -8,6 +8,7 @@ using System.Net.Security; using System.Security.Cryptography.X509Certificates; using System.Threading; using System.Threading.Tasks; +using Microsoft.AspNetCore.Connections; using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal; @@ -22,7 +23,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Https.Internal private readonly HttpsConnectionAdapterOptions _options; private readonly X509Certificate2 _serverCertificate; - private readonly Func _serverCertificateSelector; + private readonly Func _serverCertificateSelector; private readonly ILogger _logger; @@ -133,7 +134,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Https.Internal selector = (sender, name) => { context.Features.Set(sslStream); - var cert = _serverCertificateSelector(context.Features, name); + var cert = _serverCertificateSelector(context.ConnectionContext, name); if (cert != null) { EnsureCertificateIsAllowedForServerAuth(cert); @@ -169,7 +170,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Https.Internal if (_serverCertificateSelector != null) { context.Features.Set(sslStream); - serverCert = _serverCertificateSelector(context.Features, null); + serverCert = _serverCertificateSelector(context.ConnectionContext, null); if (serverCert != null) { EnsureCertificateIsAllowedForServerAuth(serverCert); diff --git a/test/Kestrel.FunctionalTests/HttpsConnectionAdapterTests.cs b/test/Kestrel.FunctionalTests/HttpsConnectionAdapterTests.cs index 43ff38ce26..37bc3e4d87 100644 --- a/test/Kestrel.FunctionalTests/HttpsConnectionAdapterTests.cs +++ b/test/Kestrel.FunctionalTests/HttpsConnectionAdapterTests.cs @@ -160,10 +160,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { new HttpsConnectionAdapter(new HttpsConnectionAdapterOptions { - ServerCertificateSelector = (features, name) => + ServerCertificateSelector = (connection, name) => { - Assert.NotNull(features); - Assert.NotNull(features.Get()); + Assert.NotNull(connection); + Assert.NotNull(connection.Features.Get()); #if NETCOREAPP2_1 Assert.Equal("localhost", name); #else @@ -201,10 +201,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { new HttpsConnectionAdapter(new HttpsConnectionAdapterOptions { - ServerCertificateSelector = (features, name) => + ServerCertificateSelector = (connection, name) => { - Assert.NotNull(features); - Assert.NotNull(features.Get()); + Assert.NotNull(connection); + Assert.NotNull(connection.Features.Get()); #if NETCOREAPP2_1 Assert.Equal("localhost", name); #else @@ -291,10 +291,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests new HttpsConnectionAdapter(new HttpsConnectionAdapterOptions { ServerCertificate = _x509Certificate2NoExt, - ServerCertificateSelector = (features, name) => + ServerCertificateSelector = (connection, name) => { - Assert.NotNull(features); - Assert.NotNull(features.Get()); + Assert.NotNull(connection); + Assert.NotNull(connection.Features.Get()); #if NETCOREAPP2_1 Assert.Equal("localhost", name); #else From ca44b4adfc6ffdae99c34091cd317d07baa9cc1e Mon Sep 17 00:00:00 2001 From: David Fowler Date: Wed, 11 Apr 2018 20:23:48 -0700 Subject: [PATCH 1617/1662] Moved kestrel specific features into transport abstractions (#2482) --- src/Connections.Abstractions/DefaultConnectionContext.cs | 2 -- src/Kestrel.Core/Internal/HttpConnectionMiddleware.cs | 1 + .../Internal}/IApplicationTransportFeature.cs | 2 +- .../Internal}/ITransportSchedulerFeature.cs | 2 +- 4 files changed, 3 insertions(+), 4 deletions(-) rename src/{Connections.Abstractions/Features => Kestrel.Transport.Abstractions/Internal}/IApplicationTransportFeature.cs (81%) rename src/{Connections.Abstractions/Features => Kestrel.Transport.Abstractions/Internal}/ITransportSchedulerFeature.cs (84%) diff --git a/src/Connections.Abstractions/DefaultConnectionContext.cs b/src/Connections.Abstractions/DefaultConnectionContext.cs index 33607c0a5c..4b3377350d 100644 --- a/src/Connections.Abstractions/DefaultConnectionContext.cs +++ b/src/Connections.Abstractions/DefaultConnectionContext.cs @@ -17,7 +17,6 @@ namespace Microsoft.AspNetCore.Connections IConnectionIdFeature, IConnectionItemsFeature, IConnectionTransportFeature, - IApplicationTransportFeature, IConnectionUserFeature { public DefaultConnectionContext() : @@ -39,7 +38,6 @@ namespace Microsoft.AspNetCore.Connections Features.Set(this); Features.Set(this); Features.Set(this); - Features.Set(this); } public DefaultConnectionContext(string id, IDuplexPipe transport, IDuplexPipe application) diff --git a/src/Kestrel.Core/Internal/HttpConnectionMiddleware.cs b/src/Kestrel.Core/Internal/HttpConnectionMiddleware.cs index fad29ae0db..598dae82d8 100644 --- a/src/Kestrel.Core/Internal/HttpConnectionMiddleware.cs +++ b/src/Kestrel.Core/Internal/HttpConnectionMiddleware.cs @@ -7,6 +7,7 @@ using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Connections; using Microsoft.AspNetCore.Connections.Features; using Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal { diff --git a/src/Connections.Abstractions/Features/IApplicationTransportFeature.cs b/src/Kestrel.Transport.Abstractions/Internal/IApplicationTransportFeature.cs similarity index 81% rename from src/Connections.Abstractions/Features/IApplicationTransportFeature.cs rename to src/Kestrel.Transport.Abstractions/Internal/IApplicationTransportFeature.cs index e4955996c0..490cb7f065 100644 --- a/src/Connections.Abstractions/Features/IApplicationTransportFeature.cs +++ b/src/Kestrel.Transport.Abstractions/Internal/IApplicationTransportFeature.cs @@ -5,7 +5,7 @@ using System.Buffers; using System.IO.Pipelines; using System.Threading; -namespace Microsoft.AspNetCore.Connections.Features +namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal { public interface IApplicationTransportFeature { diff --git a/src/Connections.Abstractions/Features/ITransportSchedulerFeature.cs b/src/Kestrel.Transport.Abstractions/Internal/ITransportSchedulerFeature.cs similarity index 84% rename from src/Connections.Abstractions/Features/ITransportSchedulerFeature.cs rename to src/Kestrel.Transport.Abstractions/Internal/ITransportSchedulerFeature.cs index e5d3a8e8d0..be113bbe10 100644 --- a/src/Connections.Abstractions/Features/ITransportSchedulerFeature.cs +++ b/src/Kestrel.Transport.Abstractions/Internal/ITransportSchedulerFeature.cs @@ -5,7 +5,7 @@ using System.Buffers; using System.IO.Pipelines; using System.Threading; -namespace Microsoft.AspNetCore.Connections.Features +namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal { public interface ITransportSchedulerFeature { From c6fa9793eb345a82bc26597aba8c572414ac14b1 Mon Sep 17 00:00:00 2001 From: "Chris Ross (ASP.NET)" Date: Tue, 10 Apr 2018 11:36:36 -0700 Subject: [PATCH 1618/1662] Make Protocols internal --- samples/Http2SampleApp/Program.cs | 3 +-- samples/SampleApp/Startup.cs | 4 ++-- src/Kestrel.Core/ListenOptions.cs | 21 ++----------------- src/Kestrel.Core/Properties/AssemblyInfo.cs | 1 + test/Kestrel.Core.Tests/ListenOptionsTests.cs | 10 --------- .../HttpProtocolSelectionTests.cs | 2 -- 6 files changed, 6 insertions(+), 35 deletions(-) diff --git a/samples/Http2SampleApp/Program.cs b/samples/Http2SampleApp/Program.cs index e95177afe5..6e023ec03d 100644 --- a/samples/Http2SampleApp/Program.cs +++ b/samples/Http2SampleApp/Program.cs @@ -13,8 +13,6 @@ namespace Http2SampleApp { public static void Main(string[] args) { - AppContext.SetSwitch("Switch.Microsoft.AspNetCore.Server.Kestrel.Experimental.Http2", isEnabled: true); - var hostBuilder = new WebHostBuilder() .ConfigureLogging((_, factory) => { @@ -31,6 +29,7 @@ namespace Http2SampleApp options.Listen(IPAddress.Any, basePort, listenOptions => { + // This only works becuase InternalsVisibleTo is enabled for this sample. listenOptions.Protocols = HttpProtocols.Http1AndHttp2; listenOptions.UseHttps("testCert.pfx", "testPassword"); listenOptions.UseConnectionLogging(); diff --git a/samples/SampleApp/Startup.cs b/samples/SampleApp/Startup.cs index 3a4f29a3fd..bb070eb348 100644 --- a/samples/SampleApp/Startup.cs +++ b/samples/SampleApp/Startup.cs @@ -68,7 +68,7 @@ namespace SampleApp options.ConfigureEndpointDefaults(opt => { - opt.Protocols = HttpProtocols.Http1; + opt.NoDelay = true; }); options.ConfigureHttpsDefaults(httpsOptions => @@ -129,7 +129,7 @@ namespace SampleApp .Configure(context.Configuration.GetSection("Kestrel")) .Endpoint("NamedEndpoint", opt => { - opt.ListenOptions.Protocols = HttpProtocols.Http1; + opt.ListenOptions.NoDelay = true; }) .Endpoint("NamedHttpsEndpoint", opt => { diff --git a/src/Kestrel.Core/ListenOptions.cs b/src/Kestrel.Core/ListenOptions.cs index dfc15ad1ae..5ae8b31468 100644 --- a/src/Kestrel.Core/ListenOptions.cs +++ b/src/Kestrel.Core/ListenOptions.cs @@ -19,18 +19,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core /// public class ListenOptions : IEndPointInformation, IConnectionBuilder { - internal const string Http2ExperimentSwitch = "Switch.Microsoft.AspNetCore.Server.Kestrel.Experimental.Http2"; - private FileHandleType _handleType; - private HttpProtocols _protocols = HttpProtocols.Http1; - internal bool _isHttp2Supported; internal readonly List> _middleware = new List>(); internal ListenOptions(IPEndPoint endPoint) { Type = ListenType.IPEndPoint; IPEndPoint = endPoint; - AppContext.TryGetSwitch(Http2ExperimentSwitch, out _isHttp2Supported); } internal ListenOptions(string socketPath) @@ -127,20 +122,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core /// /// The protocols enabled on this endpoint. /// - /// Defaults to HTTP/1.x only. HTTP/2 support is experimental, see - /// https://go.microsoft.com/fwlink/?linkid=866785 to enable it. - public HttpProtocols Protocols - { - get => _protocols; - set - { - if (!_isHttp2Supported && (value == HttpProtocols.Http1AndHttp2 || value == HttpProtocols.Http2)) - { - throw new NotSupportedException(CoreStrings.Http2NotSupported); - } - _protocols = value; - } - } + /// Defaults to HTTP/1.x only. + internal HttpProtocols Protocols { get; set; } = HttpProtocols.Http1; /// /// Gets the that allows each connection diff --git a/src/Kestrel.Core/Properties/AssemblyInfo.cs b/src/Kestrel.Core/Properties/AssemblyInfo.cs index af17db4f34..793159eefb 100644 --- a/src/Kestrel.Core/Properties/AssemblyInfo.cs +++ b/src/Kestrel.Core/Properties/AssemblyInfo.cs @@ -9,3 +9,4 @@ using System.Runtime.CompilerServices; [assembly: InternalsVisibleTo("Microsoft.AspNetCore.Server.Kestrel.Core.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")] [assembly: InternalsVisibleTo("Kestrel.Performance, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")] [assembly: InternalsVisibleTo("Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")] +[assembly: InternalsVisibleTo("Http2SampleApp, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")] diff --git a/test/Kestrel.Core.Tests/ListenOptionsTests.cs b/test/Kestrel.Core.Tests/ListenOptionsTests.cs index 6b4f792f13..77e5a33bbf 100644 --- a/test/Kestrel.Core.Tests/ListenOptionsTests.cs +++ b/test/Kestrel.Core.Tests/ListenOptionsTests.cs @@ -20,16 +20,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests Assert.Equal(HttpProtocols.Http1, listenOptions.Protocols); } - [Fact] - public void Http2DisabledByDefault() - { - var listenOptions = new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0)); - var ex = Assert.Throws(() => listenOptions.Protocols = HttpProtocols.Http1AndHttp2); - Assert.Equal(CoreStrings.Http2NotSupported, ex.Message); - ex = Assert.Throws(() => listenOptions.Protocols = HttpProtocols.Http2); - Assert.Equal(CoreStrings.Http2NotSupported, ex.Message); - } - [Fact] public void LocalHostListenOptionsClonesConnectionMiddleware() { diff --git a/test/Kestrel.FunctionalTests/HttpProtocolSelectionTests.cs b/test/Kestrel.FunctionalTests/HttpProtocolSelectionTests.cs index e74c148218..b75496c097 100644 --- a/test/Kestrel.FunctionalTests/HttpProtocolSelectionTests.cs +++ b/test/Kestrel.FunctionalTests/HttpProtocolSelectionTests.cs @@ -50,7 +50,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { options.Listen(IPAddress.Loopback, 0, listenOptions => { - listenOptions._isHttp2Supported = true; listenOptions.Protocols = serverProtocols; }); }) @@ -81,7 +80,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests .ConfigureLogging(loggingBuilder => loggingBuilder.AddProvider(loggerProvider.Object)) .UseKestrel(options => options.Listen(IPAddress.Loopback, 0, listenOptions => { - listenOptions._isHttp2Supported = true; listenOptions.Protocols = serverProtocols; })) .Configure(app => app.Run(context => Task.CompletedTask)); From ee12c4fcf2205cf046769e97c045967bd6b3990d Mon Sep 17 00:00:00 2001 From: "Chris Ross (ASP.NET)" Date: Thu, 12 Apr 2018 09:25:44 -0700 Subject: [PATCH 1619/1662] Downgrade HTTPs handshake failures to debug #1853 --- .../Internal/HttpsConnectionAdapter.cs | 4 +-- test/Kestrel.FunctionalTests/HttpsTests.cs | 30 +++++++++++++------ 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/src/Kestrel.Core/Internal/HttpsConnectionAdapter.cs b/src/Kestrel.Core/Internal/HttpsConnectionAdapter.cs index cab926bb63..301c9c7a23 100644 --- a/src/Kestrel.Core/Internal/HttpsConnectionAdapter.cs +++ b/src/Kestrel.Core/Internal/HttpsConnectionAdapter.cs @@ -182,13 +182,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Https.Internal } catch (OperationCanceledException) { - _logger?.LogInformation(2, CoreStrings.AuthenticationTimedOut); + _logger?.LogDebug(2, CoreStrings.AuthenticationTimedOut); sslStream.Dispose(); return _closedAdaptedConnection; } catch (IOException ex) { - _logger?.LogInformation(1, ex, CoreStrings.AuthenticationFailed); + _logger?.LogDebug(1, ex, CoreStrings.AuthenticationFailed); sslStream.Dispose(); return _closedAdaptedConnection; } diff --git a/test/Kestrel.FunctionalTests/HttpsTests.cs b/test/Kestrel.FunctionalTests/HttpsTests.cs index 29a598dee1..051d11ab8d 100644 --- a/test/Kestrel.FunctionalTests/HttpsTests.cs +++ b/test/Kestrel.FunctionalTests/HttpsTests.cs @@ -114,7 +114,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } [Fact] - public async Task EmptyRequestLoggedAsInformation() + public async Task EmptyRequestLoggedAsDebug() { var loggerProvider = new HandshakeErrorLoggerProvider(); @@ -126,7 +126,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests listenOptions.UseHttps(TestResources.TestCertificatePath, "testPassword"); }); }) - .ConfigureLogging(builder => builder.AddProvider(loggerProvider)) + .ConfigureLogging(builder => + { + builder.AddProvider(loggerProvider); + builder.SetMinimumLevel(LogLevel.Debug); + }) .Configure(app => { }); using (var host = hostBuilder.Build()) @@ -142,13 +146,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } Assert.Equal(1, loggerProvider.FilterLogger.LastEventId.Id); - Assert.Equal(LogLevel.Information, loggerProvider.FilterLogger.LastLogLevel); + Assert.Equal(LogLevel.Debug, loggerProvider.FilterLogger.LastLogLevel); Assert.True(loggerProvider.ErrorLogger.TotalErrorsLogged == 0, userMessage: string.Join(Environment.NewLine, loggerProvider.ErrorLogger.ErrorMessages)); } [Fact] - public async Task ClientHandshakeFailureLoggedAsInformation() + public async Task ClientHandshakeFailureLoggedAsDebug() { var loggerProvider = new HandshakeErrorLoggerProvider(); @@ -160,7 +164,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests listenOptions.UseHttps(TestResources.TestCertificatePath, "testPassword"); }); }) - .ConfigureLogging(builder => builder.AddProvider(loggerProvider)) + .ConfigureLogging(builder => + { + builder.AddProvider(loggerProvider); + builder.SetMinimumLevel(LogLevel.Debug); + }) .Configure(app => { }); using (var host = hostBuilder.Build()) @@ -178,7 +186,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } Assert.Equal(1, loggerProvider.FilterLogger.LastEventId.Id); - Assert.Equal(LogLevel.Information, loggerProvider.FilterLogger.LastLogLevel); + Assert.Equal(LogLevel.Debug, loggerProvider.FilterLogger.LastLogLevel); Assert.True(loggerProvider.ErrorLogger.TotalErrorsLogged == 0, userMessage: string.Join(Environment.NewLine, loggerProvider.ErrorLogger.ErrorMessages)); } @@ -349,7 +357,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } [Fact] - public async Task HandshakeTimesOutAndIsLoggedAsInformation() + public async Task HandshakeTimesOutAndIsLoggedAsDebug() { var loggerProvider = new HandshakeErrorLoggerProvider(); var hostBuilder = TransportSelector.GetWebHostBuilder() @@ -364,7 +372,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests }); }); }) - .ConfigureLogging(builder => builder.AddProvider(loggerProvider)) + .ConfigureLogging(builder => + { + builder.AddProvider(loggerProvider); + builder.SetMinimumLevel(LogLevel.Debug); + }) .Configure(app => app.Run(httpContext => Task.CompletedTask)); using (var host = hostBuilder.Build()) @@ -381,7 +393,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests await loggerProvider.FilterLogger.LogTcs.Task.TimeoutAfter(TestConstants.DefaultTimeout); Assert.Equal(2, loggerProvider.FilterLogger.LastEventId); - Assert.Equal(LogLevel.Information, loggerProvider.FilterLogger.LastLogLevel); + Assert.Equal(LogLevel.Debug, loggerProvider.FilterLogger.LastLogLevel); } private class HandshakeErrorLoggerProvider : ILoggerProvider From 10f3b6863e36eab67e43e59ba8e6e900177a96ed Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Thu, 12 Apr 2018 17:29:34 -0700 Subject: [PATCH 1620/1662] Avoid nullref in KestrelEventSource (#2483) * Avoid nullref in KestrelEventSource * Improve HostNameIsReachableAttribute to speed up test discovery --- .../Infrastructure/KestrelEventSource.cs | 4 +- .../AddressRegistrationTests.cs | 4 +- .../HostNameIsReachableAttribute.cs | 88 +++++++++++++++++++ .../NetworkIsReachableAttribute.cs | 51 ----------- 4 files changed, 92 insertions(+), 55 deletions(-) create mode 100644 test/Kestrel.FunctionalTests/TestHelpers/HostNameIsReachableAttribute.cs delete mode 100644 test/Kestrel.FunctionalTests/TestHelpers/NetworkIsReachableAttribute.cs diff --git a/src/Kestrel.Core/Internal/Infrastructure/KestrelEventSource.cs b/src/Kestrel.Core/Internal/Infrastructure/KestrelEventSource.cs index ed70a3797a..7faf486d1f 100644 --- a/src/Kestrel.Core/Internal/Infrastructure/KestrelEventSource.cs +++ b/src/Kestrel.Core/Internal/Infrastructure/KestrelEventSource.cs @@ -32,8 +32,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure { ConnectionStart( connection.ConnectionId, - connection.LocalEndPoint.ToString(), - connection.RemoteEndPoint.ToString()); + connection.LocalEndPoint?.ToString(), + connection.RemoteEndPoint?.ToString()); } } diff --git a/test/Kestrel.FunctionalTests/AddressRegistrationTests.cs b/test/Kestrel.FunctionalTests/AddressRegistrationTests.cs index 0c85a2a928..b550c852c7 100644 --- a/test/Kestrel.FunctionalTests/AddressRegistrationTests.cs +++ b/test/Kestrel.FunctionalTests/AddressRegistrationTests.cs @@ -40,7 +40,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } [ConditionalFact] - [NetworkIsReachable] + [HostNameIsReachable] public async Task RegisterAddresses_HostName_Success() { var hostName = Dns.GetHostName(); @@ -308,7 +308,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } [ConditionalFact] - [NetworkIsReachable] + [HostNameIsReachable] public async Task ListenAnyIP_HostName_Success() { var hostName = Dns.GetHostName(); diff --git a/test/Kestrel.FunctionalTests/TestHelpers/HostNameIsReachableAttribute.cs b/test/Kestrel.FunctionalTests/TestHelpers/HostNameIsReachableAttribute.cs new file mode 100644 index 0000000000..bd120b6356 --- /dev/null +++ b/test/Kestrel.FunctionalTests/TestHelpers/HostNameIsReachableAttribute.cs @@ -0,0 +1,88 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Net; +using System.Net.Sockets; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Testing.xunit; + +namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests +{ + [AttributeUsage(AttributeTargets.Method, AllowMultiple = false)] + public class HostNameIsReachableAttribute : Attribute, ITestCondition + { + private string _hostname; + private string _error; + private bool? _isMet; + + public bool IsMet + { + get + { + return _isMet ?? (_isMet = HostNameIsReachable().GetAwaiter().GetResult()).Value; + } + } + + public string SkipReason => _hostname != null + ? $"Test cannot run when network is unreachable. Socket exception: '{_error}'" + : "Could not determine hostname for current test machine"; + + private async Task HostNameIsReachable() + { + try + { + _hostname = Dns.GetHostName(); + + // if the network is unreachable on macOS, throws with SocketError.NetworkUnreachable + // if the network device is not configured, throws with SocketError.HostNotFound + // if the network is reachable, throws with SocketError.ConnectionRefused or succeeds + var timeoutTask = Task.Delay(1000); + if (await Task.WhenAny(ConnectToHost(_hostname, 80), timeoutTask) == timeoutTask) + { + _error = "Attempt to establish a connection took over a second without success or failure."; + return false; + } + } + catch (SocketException ex) when ( + ex.SocketErrorCode == SocketError.NetworkUnreachable + || ex.SocketErrorCode == SocketError.HostNotFound) + { + _error = ex.Message; + return false; + } + catch + { + // Swallow other errors. Allows the test to throw the failures instead + } + + return true; + } + + public static async Task ConnectToHost(string hostName, int port) + { + var tcs = new TaskCompletionSource(); + + var socketArgs = new SocketAsyncEventArgs(); + socketArgs.RemoteEndPoint = new DnsEndPoint(hostName, port); + socketArgs.Completed += (s, e) => tcs.TrySetResult(e.ConnectSocket); + + // Must use static ConnectAsync(), since instance Connect() does not support DNS names on OSX/Linux. + if (Socket.ConnectAsync(SocketType.Stream, ProtocolType.Tcp, socketArgs)) + { + await tcs.Task.ConfigureAwait(false); + } + + var socket = socketArgs.ConnectSocket; + + if (socket == null) + { + throw new SocketException((int)socketArgs.SocketError); + } + else + { + return socket; + } + } + } +} diff --git a/test/Kestrel.FunctionalTests/TestHelpers/NetworkIsReachableAttribute.cs b/test/Kestrel.FunctionalTests/TestHelpers/NetworkIsReachableAttribute.cs deleted file mode 100644 index 9b62c0689b..0000000000 --- a/test/Kestrel.FunctionalTests/TestHelpers/NetworkIsReachableAttribute.cs +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using System.Net; -using System.Net.Sockets; -using Microsoft.AspNetCore.Testing; -using Microsoft.AspNetCore.Testing.xunit; - -namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests -{ - [AttributeUsage(AttributeTargets.Method, AllowMultiple = false)] - public class NetworkIsReachableAttribute : Attribute, ITestCondition - { - private string _hostname; - private string _error; - - public bool IsMet - { - get - { - try - { - _hostname = Dns.GetHostName(); - - // if the network is unreachable on macOS, throws with SocketError.NetworkUnreachable - // if the network device is not configured, throws with SocketError.HostNotFound - // if the network is reachable, throws with SocketError.ConnectionRefused or succeeds - HttpClientSlim.GetStringAsync($"http://{_hostname}").GetAwaiter().GetResult(); - } - catch (SocketException ex) when ( - ex.SocketErrorCode == SocketError.NetworkUnreachable - || ex.SocketErrorCode == SocketError.HostNotFound) - { - _error = ex.Message; - return false; - } - catch - { - // Swallow other errors. Allows the test to throw the failures instead - } - - return true; - } - } - - public string SkipReason => _hostname != null - ? $"Test cannot run when network is unreachable. Socket exception: '{_error}'" - : "Could not determine hostname for current test machine"; - } -} From d57da6b71f88665ba09f3599413b5c05895c8c61 Mon Sep 17 00:00:00 2001 From: Ahson Khan Date: Thu, 12 Apr 2018 23:33:47 -0700 Subject: [PATCH 1621/1662] Collapse AsSpan().Slice(..) into AsSpan(..) (#2491) --- benchmarkapps/PlatformBenchmarks/DateHeader.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/benchmarkapps/PlatformBenchmarks/DateHeader.cs b/benchmarkapps/PlatformBenchmarks/DateHeader.cs index 1d03d78b53..5cfbc5c3b2 100644 --- a/benchmarkapps/PlatformBenchmarks/DateHeader.cs +++ b/benchmarkapps/PlatformBenchmarks/DateHeader.cs @@ -45,7 +45,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { lock (s_headerBytesScratch) { - if (!Utf8Formatter.TryFormat(value, s_headerBytesScratch.AsSpan().Slice(prefixLength), out int written, 'R')) + if (!Utf8Formatter.TryFormat(value, s_headerBytesScratch.AsSpan(prefixLength), out int written, 'R')) { throw new Exception("date time format failed"); } From 2d51d236979ee731b8675e5879a56b708ec2fa4b Mon Sep 17 00:00:00 2001 From: John Luo Date: Tue, 10 Apr 2018 23:49:18 -0700 Subject: [PATCH 1622/1662] Add file logging to functional tests --- README.md | 4 + build/dependencies.props | 62 ++--- src/Kestrel.Core/Properties/AssemblyInfo.cs | 4 +- .../AddressRegistrationTests.cs | 64 +++--- .../BadHttpRequestTests.cs | 15 +- .../CertificateLoaderTests.cs | 17 +- .../ChunkedRequestTests.cs | 23 +- .../ChunkedResponseTests.cs | 25 +- .../ConnectionAdapterTests.cs | 17 +- .../ConnectionLimitTests.cs | 7 +- .../DefaultHeaderTests.cs | 5 +- .../EventSourceTests.cs | 5 +- .../HttpConnectionManagerTests.cs | 3 +- .../HttpProtocolSelectionTests.cs | 15 +- .../HttpsConnectionAdapterTests.cs | 66 ++---- test/Kestrel.FunctionalTests/HttpsTests.cs | 33 +-- .../KeepAliveTimeoutTests.cs | 5 +- .../LoggingConnectionAdapterTests.cs | 34 +-- .../MaxRequestBodySizeTests.cs | 23 +- .../MaxRequestBufferSizeTests.cs | 14 +- .../MaxRequestLineSizeTests.cs | 5 +- .../Properties/AssemblyInfo.cs | 4 + .../RequestBodyTimeoutTests.cs | 14 +- .../RequestHeaderLimitsTests.cs | 5 +- .../RequestHeadersTimeoutTests.cs | 5 +- .../RequestTargetProcessingTests.cs | 13 +- test/Kestrel.FunctionalTests/RequestTests.cs | 146 ++++++------ test/Kestrel.FunctionalTests/ResponseTests.cs | 214 ++++++++---------- .../TestApplicationErrorLoggerLoggedTest.cs | 18 ++ .../TestHelpers/TestServer.cs | 1 - test/Kestrel.FunctionalTests/UpgradeTests.cs | 29 +-- ...rel.Transport.Libuv.FunctionalTests.csproj | 4 +- .../ListenHandleTests.cs | 5 +- ...l.Transport.Sockets.FunctionalTests.csproj | 4 +- test/shared/TestApplicationErrorLogger.cs | 5 +- 35 files changed, 430 insertions(+), 483 deletions(-) create mode 100644 test/Kestrel.FunctionalTests/TestHelpers/TestApplicationErrorLoggerLoggedTest.cs diff --git a/README.md b/README.md index 7f2532761b..85a0a73610 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,10 @@ This project is part of ASP.NET Core. You can find samples, documentation and ge To run a complete build on command line only, execute `build.cmd` or `build.sh` without arguments. See [developer documentation](https://github.com/aspnet/Home/wiki) for more details. +## File logging for functional test + +Turn on file logging for Kestrel functional tests by specifying the environment variable ASPNETCORE_TEST_LOG_DIR to the log output directory. + ## Packages Kestrel is available as a NuGet package. diff --git a/build/dependencies.props b/build/dependencies.props index ace613e29c..2a1dc23c3b 100644 --- a/build/dependencies.props +++ b/build/dependencies.props @@ -7,41 +7,41 @@ 0.10.13 2.1.0-preview3-17002 1.10.0 - 2.1.0-preview3-32110 - 2.1.0-preview3-32110 - 2.1.0-preview3-32110 - 2.1.0-preview3-32110 - 2.1.0-preview3-32110 - 2.1.0-preview3-32110 - 2.1.0-preview3-32110 - 2.1.0-preview3-32110 - 2.1.0-preview3-32110 - 2.1.0-preview3-32110 - 2.1.0-preview3-32110 - 2.1.0-preview3-32110 - 2.1.0-preview3-32110 - 2.1.0-preview3-32110 - 2.1.0-preview3-32037 - 2.1.0-preview3-32110 - 2.1.0-preview3-32110 - 2.1.0-preview3-32110 - 2.1.0-preview3-32110 - 2.1.0-preview3-32110 - 2.1.0-preview3-32110 - 2.1.0-preview3-32110 + 2.1.0-preview3-32196 + 2.1.0-preview3-32196 + 2.1.0-preview3-32196 + 2.1.0-a-preview3-file-logger-16960 + 2.1.0-a-preview3-file-logger-16960 + 2.1.0-preview3-32196 + 2.1.0-preview3-32196 + 2.1.0-preview3-32196 + 2.1.0-preview3-32196 + 2.1.0-preview3-32196 + 2.1.0-preview3-32196 + 2.1.0-preview3-32196 + 2.1.0-preview3-32196 + 2.1.0-preview3-32196 + 2.1.0-preview3-32196 + 2.1.0-preview3-32196 + 2.1.0-preview3-32196 + 2.1.0-a-preview3-file-logger-16474 + 2.1.0-a-preview3-file-logger-16474 + 2.1.0-a-preview3-file-logger-16474 + 2.1.0-a-preview3-file-logger-16474 + 2.1.0-preview3-32196 2.0.0 - 2.1.0-preview3-26331-01 - 2.1.0-preview3-32110 + 2.1.0-preview2-26406-04 + 2.1.0-preview3-32196 15.6.1 4.7.49 11.0.2 - 4.5.0-preview3-26331-02 - 4.5.0-preview3-26331-02 - 4.5.0-preview3-26331-02 - 4.5.0-preview3-26331-02 - 4.5.0-preview3-26331-02 - 4.5.0-preview3-26331-02 - 4.5.0-preview3-26331-02 + 4.5.0-preview2-26406-04 + 4.5.0-preview2-26406-04 + 4.5.0-preview2-26406-04 + 4.5.0-preview2-26406-04 + 4.5.0-preview2-26406-04 + 4.5.0-preview2-26406-04 + 4.5.0-preview2-26406-04 1.3.7 0.8.0 2.3.1 diff --git a/src/Kestrel.Core/Properties/AssemblyInfo.cs b/src/Kestrel.Core/Properties/AssemblyInfo.cs index 793159eefb..27495d5268 100644 --- a/src/Kestrel.Core/Properties/AssemblyInfo.cs +++ b/src/Kestrel.Core/Properties/AssemblyInfo.cs @@ -4,8 +4,8 @@ using System.Runtime.CompilerServices; [assembly: InternalsVisibleTo("Microsoft.AspNetCore.Server.Kestrel.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")] -[assembly: InternalsVisibleTo("Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.FunctionalTests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")] -[assembly: InternalsVisibleTo("Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.FunctionalTests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")] +[assembly: InternalsVisibleTo("Libuv.FunctionalTests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")] +[assembly: InternalsVisibleTo("Sockets.FunctionalTests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")] [assembly: InternalsVisibleTo("Microsoft.AspNetCore.Server.Kestrel.Core.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")] [assembly: InternalsVisibleTo("Kestrel.Performance, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")] [assembly: InternalsVisibleTo("Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")] diff --git a/test/Kestrel.FunctionalTests/AddressRegistrationTests.cs b/test/Kestrel.FunctionalTests/AddressRegistrationTests.cs index b550c852c7..3843c6c532 100644 --- a/test/Kestrel.FunctionalTests/AddressRegistrationTests.cs +++ b/test/Kestrel.FunctionalTests/AddressRegistrationTests.cs @@ -23,22 +23,14 @@ using Microsoft.AspNetCore.Testing.xunit; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using Xunit; -using Xunit.Abstractions; using Xunit.Sdk; namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { - public class AddressRegistrationTests + public class AddressRegistrationTests : TestApplicationErrorLoggerLoggedTest { private const int MaxRetries = 10; - private readonly Action _configureLoggingDelegate; - - public AddressRegistrationTests(ITestOutputHelper output) - { - _configureLoggingDelegate = builder => builder.AddXunit(output); - } - [ConditionalFact] [HostNameIsReachable] public async Task RegisterAddresses_HostName_Success() @@ -165,7 +157,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { var hostBuilder = TransportSelector.GetWebHostBuilder() .UseKestrel() - .ConfigureLogging(_configureLoggingDelegate) + .ConfigureServices(AddTestLogging) .UseUrls(addressInput) .Configure(ConfigureEchoAddress); @@ -201,7 +193,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests listenOptions.UseHttps(TestResources.GetTestCertificate()); }); }) - .ConfigureLogging(_configureLoggingDelegate) + .ConfigureServices(AddTestLogging) .UseUrls("http://127.0.0.1:0") .Configure(app => { @@ -261,7 +253,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests private async Task RegisterIPEndPoint_Success(IPEndPoint endPoint, string testUrl, int testPort = 0) { var hostBuilder = TransportSelector.GetWebHostBuilder() - .ConfigureLogging(_configureLoggingDelegate) + .ConfigureServices(AddTestLogging) .UseKestrel(options => { options.Listen(endPoint, listenOptions => @@ -322,7 +314,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { options.ListenAnyIP(testPort); }) - .ConfigureLogging(_configureLoggingDelegate) + .ConfigureServices(AddTestLogging) .Configure(ConfigureEchoAddress); using (var host = hostBuilder.Build()) @@ -363,7 +355,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { options.ListenLocalhost(testPort); }) - .ConfigureLogging(_configureLoggingDelegate) + .ConfigureServices(AddTestLogging) .Configure(ConfigureEchoAddress); using (var host = hostBuilder.Build()) @@ -419,10 +411,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests private async Task RegisterDefaultServerAddresses_Success(IEnumerable addresses, bool mockHttps = false) { - var testLogger = new TestApplicationErrorLogger(); - var hostBuilder = TransportSelector.GetWebHostBuilder() - .ConfigureLogging(_configureLoggingDelegate) + .ConfigureServices(AddTestLogging) .UseKestrel(options => { if (mockHttps) @@ -430,9 +420,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests options.DefaultCertificate = new X509Certificate2(TestResources.TestCertificatePath, "testPassword"); } }) - .ConfigureLogging(builder => builder - .AddProvider(new KestrelTestLoggerProvider(testLogger)) - .SetMinimumLevel(LogLevel.Debug)) .Configure(ConfigureEchoAddress); using (var host = hostBuilder.Build()) @@ -446,7 +433,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests Assert.Contains(5001, host.GetPorts()); } - Assert.Single(testLogger.Messages, log => log.LogLevel == LogLevel.Debug && + Assert.Single(TestApplicationErrorLogger.Messages, log => log.LogLevel == LogLevel.Debug && (string.Equals(CoreStrings.FormatBindingToDefaultAddresses(Constants.DefaultServerAddress, Constants.DefaultServerHttpsAddress), log.Message, StringComparison.Ordinal) || string.Equals(CoreStrings.FormatBindingToDefaultAddress(Constants.DefaultServerAddress), log.Message, StringComparison.Ordinal))); @@ -467,7 +454,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests var port = ((IPEndPoint)socket.LocalEndPoint).Port; var hostBuilder = TransportSelector.GetWebHostBuilder() - .ConfigureLogging(_configureLoggingDelegate) .UseKestrel() .UseUrls($"http://127.0.0.1:{port}") .Configure(ConfigureEchoAddress); @@ -484,6 +470,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [IPv6SupportedCondition] public void ThrowsWhenBindingToIPv6AddressInUse() { + TestApplicationErrorLogger.IgnoredExceptions.Add(typeof(IOException)); + using (var socket = new Socket(AddressFamily.InterNetworkV6, SocketType.Stream, ProtocolType.Tcp)) { socket.Bind(new IPEndPoint(IPAddress.IPv6Loopback, 0)); @@ -491,7 +479,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests var port = ((IPEndPoint)socket.LocalEndPoint).Port; var hostBuilder = TransportSelector.GetWebHostBuilder() - .ConfigureLogging(_configureLoggingDelegate) + .ConfigureServices(AddTestLogging) .UseKestrel() .UseUrls($"http://[::1]:{port}") .Configure(ConfigureEchoAddress); @@ -508,7 +496,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests public async Task OverrideDirectConfigurationWithIServerAddressesFeature_Succeeds() { var useUrlsAddress = $"http://127.0.0.1:0"; - var testLogger = new TestApplicationErrorLogger(); var hostBuilder = TransportSelector.GetWebHostBuilder() .UseKestrel(options => { @@ -519,7 +506,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests }) .UseUrls(useUrlsAddress) .PreferHostingUrls(true) - .ConfigureLogging(builder => builder.AddProvider(new KestrelTestLoggerProvider(testLogger))) + .ConfigureServices(AddTestLogging) .Configure(ConfigureEchoAddress); using (var host = hostBuilder.Build()) @@ -535,7 +522,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests var useUrlsAddressWithPort = $"http://127.0.0.1:{port}"; Assert.Equal(serverAddresses.First(), useUrlsAddressWithPort); - Assert.Single(testLogger.Messages, log => log.LogLevel == LogLevel.Information && + Assert.Single(TestApplicationErrorLogger.Messages, log => log.LogLevel == LogLevel.Information && string.Equals(CoreStrings.FormatOverridingWithPreferHostingUrls(nameof(IServerAddressesFeature.PreferHostingUrls), useUrlsAddress), log.Message, StringComparison.Ordinal)); @@ -547,9 +534,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests public async Task DoesNotOverrideDirectConfigurationWithIServerAddressesFeature_IfPreferHostingUrlsFalse() { var useUrlsAddress = $"http://127.0.0.1:0"; - var testLogger = new TestApplicationErrorLogger(); + var hostBuilder = TransportSelector.GetWebHostBuilder() - .ConfigureLogging(_configureLoggingDelegate) + .ConfigureServices(AddTestLogging) .UseKestrel(options => { options.Listen(new IPEndPoint(IPAddress.Loopback, 0), listenOptions => @@ -559,7 +546,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests }) .UseUrls($"http://127.0.0.1:0") .PreferHostingUrls(false) - .ConfigureLogging(builder => builder.AddProvider(new KestrelTestLoggerProvider(testLogger))) .Configure(ConfigureEchoAddress); using (var host = hostBuilder.Build()) @@ -575,7 +561,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests var endPointAddress = $"https://127.0.0.1:{port}"; Assert.Equal(serverAddresses.First(), endPointAddress); - Assert.Single(testLogger.Messages, log => log.LogLevel == LogLevel.Warning && + Assert.Single(TestApplicationErrorLogger.Messages, log => log.LogLevel == LogLevel.Warning && string.Equals(CoreStrings.FormatOverridingWithKestrelOptions(useUrlsAddress, "UseKestrel()"), log.Message, StringComparison.Ordinal)); @@ -587,7 +573,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests public async Task DoesNotOverrideDirectConfigurationWithIServerAddressesFeature_IfAddressesEmpty() { var hostBuilder = TransportSelector.GetWebHostBuilder() - .ConfigureLogging(_configureLoggingDelegate) + .ConfigureServices(AddTestLogging) .UseKestrel(options => { options.Listen(new IPEndPoint(IPAddress.Loopback, 0), listenOptions => @@ -630,7 +616,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [Fact] public void ThrowsWhenBindingLocalhostToDynamicPort() { + TestApplicationErrorLogger.IgnoredExceptions.Add(typeof(InvalidOperationException)); + var hostBuilder = TransportSelector.GetWebHostBuilder() + .ConfigureServices(AddTestLogging) .UseKestrel() .UseUrls("http://localhost:0") .Configure(ConfigureEchoAddress); @@ -646,7 +635,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [InlineData("ssh://localhost")] public void ThrowsForUnsupportedAddressFromHosting(string addr) { + TestApplicationErrorLogger.IgnoredExceptions.Add(typeof(InvalidOperationException)); + var hostBuilder = TransportSelector.GetWebHostBuilder() + .ConfigureServices(AddTestLogging) .UseKestrel() .UseUrls(addr) .Configure(ConfigureEchoAddress); @@ -664,7 +656,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests var endPointAddress = $"http://127.0.0.1:{port}/"; var hostBuilder = TransportSelector.GetWebHostBuilder() - .ConfigureLogging(_configureLoggingDelegate) + .ConfigureServices(AddTestLogging) .UseKestrel(options => { options.Listen(IPAddress.Loopback, port); @@ -679,7 +671,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } hostBuilder = TransportSelector.GetWebHostBuilder() - .ConfigureLogging(_configureLoggingDelegate) .UseKestrel(options => { options.Listen(IPAddress.Loopback, port); @@ -703,7 +694,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests var ipv6endPointAddress = $"http://[::1]:{port}/"; var hostBuilder = TransportSelector.GetWebHostBuilder() - .ConfigureLogging(_configureLoggingDelegate) + .ConfigureServices(AddTestLogging) .UseKestrel(options => { options.Listen(IPAddress.Loopback, port); @@ -720,7 +711,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } hostBuilder = TransportSelector.GetWebHostBuilder() - .ConfigureLogging(_configureLoggingDelegate) .UseKestrel(options => { options.Listen(IPAddress.Loopback, port); @@ -739,6 +729,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests private void ThrowsWhenBindingLocalhostToAddressInUse(AddressFamily addressFamily) { + TestApplicationErrorLogger.IgnoredExceptions.Add(typeof(IOException)); + var addressInUseCount = 0; var wrongMessageCount = 0; @@ -771,7 +763,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } var hostBuilder = TransportSelector.GetWebHostBuilder() - .ConfigureLogging(_configureLoggingDelegate) + .ConfigureServices(AddTestLogging) .UseKestrel() .UseUrls($"http://localhost:{port}") .Configure(ConfigureEchoAddress); diff --git a/test/Kestrel.FunctionalTests/BadHttpRequestTests.cs b/test/Kestrel.FunctionalTests/BadHttpRequestTests.cs index d01f81b347..2954b3f7c2 100644 --- a/test/Kestrel.FunctionalTests/BadHttpRequestTests.cs +++ b/test/Kestrel.FunctionalTests/BadHttpRequestTests.cs @@ -15,7 +15,7 @@ using Xunit; namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { - public class BadHttpRequestTests + public class BadHttpRequestTests : LoggedTest { [Theory] [MemberData(nameof(InvalidRequestLineData))] @@ -153,13 +153,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [Fact] public async Task BadRequestLogsAreNotHigherThanInformation() { - var sink = new TestSink(); - var logger = new TestLogger("TestLogger", sink, enabled: true); - using (var server = new TestServer(async context => { await context.Request.Body.ReadAsync(new byte[1], 0, 1); - }, new TestServiceContext { Log = new KestrelTrace(logger) })) + }, new TestServiceContext(LoggerFactory))) { using (var connection = new TestConnection(server.Port)) { @@ -171,14 +168,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } } - Assert.All(sink.Writes, w => Assert.InRange(w.LogLevel, LogLevel.Trace, LogLevel.Information)); - Assert.Contains(sink.Writes, w => w.EventId.Id == 17 && w.LogLevel == LogLevel.Information); + Assert.All(TestSink.Writes, w => Assert.InRange(w.LogLevel, LogLevel.Trace, LogLevel.Information)); + Assert.Contains(TestSink.Writes, w => w.EventId.Id == 17 && w.LogLevel == LogLevel.Information); } [Fact] public async Task TestRequestSplitting() { - using (var server = new TestServer(context => Task.CompletedTask, new TestServiceContext { Log = Mock.Of() })) + using (var server = new TestServer(context => Task.CompletedTask, new TestServiceContext(LoggerFactory, Mock.Of()))) { using (var client = server.CreateConnection()) { @@ -202,7 +199,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests .Setup(trace => trace.ConnectionBadRequest(It.IsAny(), It.IsAny())) .Callback((connectionId, exception) => loggedException = exception); - using (var server = new TestServer(context => Task.CompletedTask, new TestServiceContext { Log = mockKestrelTrace.Object })) + using (var server = new TestServer(context => Task.CompletedTask, new TestServiceContext(LoggerFactory, mockKestrelTrace.Object))) { using (var connection = server.CreateConnection()) { diff --git a/test/Kestrel.FunctionalTests/CertificateLoaderTests.cs b/test/Kestrel.FunctionalTests/CertificateLoaderTests.cs index 21ad9704ed..86cbaa288d 100644 --- a/test/Kestrel.FunctionalTests/CertificateLoaderTests.cs +++ b/test/Kestrel.FunctionalTests/CertificateLoaderTests.cs @@ -5,26 +5,19 @@ using System.Linq; using System.Security.Cryptography.X509Certificates; using Microsoft.AspNetCore.Server.Kestrel.Https.Internal; using Microsoft.AspNetCore.Testing; +using Microsoft.Extensions.Logging.Testing; using Xunit; -using Xunit.Abstractions; namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { - public class CertificateLoaderTests + public class CertificateLoaderTests : LoggedTest { - private readonly ITestOutputHelper _output; - - public CertificateLoaderTests(ITestOutputHelper output) - { - _output = output; - } - [Theory] [InlineData("no_extensions.pfx")] public void IsCertificateAllowedForServerAuth_AllowWithNoExtensions(string testCertName) { var certPath = TestResources.GetCertPath(testCertName); - _output.WriteLine("Loading " + certPath); + TestOutputHelper.WriteLine("Loading " + certPath); var cert = new X509Certificate2(certPath, "testPassword"); Assert.Empty(cert.Extensions.OfType()); @@ -37,7 +30,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests public void IsCertificateAllowedForServerAuth_ValidatesEnhancedKeyUsageOnCertificate(string testCertName) { var certPath = TestResources.GetCertPath(testCertName); - _output.WriteLine("Loading " + certPath); + TestOutputHelper.WriteLine("Loading " + certPath); var cert = new X509Certificate2(certPath, "testPassword"); Assert.NotEmpty(cert.Extensions); var eku = Assert.Single(cert.Extensions.OfType()); @@ -52,7 +45,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests public void IsCertificateAllowedForServerAuth_RejectsCertificatesMissingServerEku(string testCertName) { var certPath = TestResources.GetCertPath(testCertName); - _output.WriteLine("Loading " + certPath); + TestOutputHelper.WriteLine("Loading " + certPath); var cert = new X509Certificate2(certPath, "testPassword"); Assert.NotEmpty(cert.Extensions); var eku = Assert.Single(cert.Extensions.OfType()); diff --git a/test/Kestrel.FunctionalTests/ChunkedRequestTests.cs b/test/Kestrel.FunctionalTests/ChunkedRequestTests.cs index 380f199768..8dba8331e1 100644 --- a/test/Kestrel.FunctionalTests/ChunkedRequestTests.cs +++ b/test/Kestrel.FunctionalTests/ChunkedRequestTests.cs @@ -10,11 +10,12 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.AspNetCore.Testing; +using Microsoft.Extensions.Logging.Testing; using Xunit; namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { - public class ChunkedRequestTests + public class ChunkedRequestTests : LoggedTest { public static TheoryData ConnectionAdapterData => new TheoryData { @@ -57,7 +58,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [MemberData(nameof(ConnectionAdapterData))] public async Task Http10TransferEncoding(ListenOptions listenOptions) { - var testContext = new TestServiceContext(); + var testContext = new TestServiceContext(LoggerFactory); using (var server = new TestServer(App, testContext, listenOptions)) { @@ -87,7 +88,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [MemberData(nameof(ConnectionAdapterData))] public async Task Http10KeepAliveTransferEncoding(ListenOptions listenOptions) { - var testContext = new TestServiceContext(); + var testContext = new TestServiceContext(LoggerFactory); using (var server = new TestServer(AppChunked, testContext, listenOptions)) { @@ -129,7 +130,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [MemberData(nameof(ConnectionAdapterData))] public async Task RequestBodyIsConsumedAutomaticallyIfAppDoesntConsumeItFully(ListenOptions listenOptions) { - var testContext = new TestServiceContext(); + var testContext = new TestServiceContext(LoggerFactory); using (var server = new TestServer(async httpContext => { @@ -213,7 +214,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests response.Headers["Content-Length"] = new[] { "11" }; await response.Body.WriteAsync(Encoding.ASCII.GetBytes("Hello World"), 0, 11); - }, new TestServiceContext(), listenOptions)) + }, new TestServiceContext(LoggerFactory), listenOptions)) { var response = string.Join("\r\n", new string[] { "HTTP/1.1 200 OK", @@ -274,7 +275,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests const string headerLine = "Header: value"; const string trailingHeaderLine = "Trailing-Header: trailing-value"; - var testContext = new TestServiceContext(); + var testContext = new TestServiceContext(LoggerFactory); testContext.ServerOptions.Limits.MaxRequestHeadersTotalSize = transferEncodingHeaderLine.Length + 2 + headerLine.Length + 2 + @@ -319,7 +320,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests const string headerLine = "Header: value"; const string trailingHeaderLine = "Trailing-Header: trailing-value"; - var testContext = new TestServiceContext(); + var testContext = new TestServiceContext(LoggerFactory); testContext.ServerOptions.Limits.MaxRequestHeaderCount = 2; using (var server = new TestServer(async context => @@ -357,7 +358,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [MemberData(nameof(ConnectionAdapterData))] public async Task ExtensionsAreIgnored(ListenOptions listenOptions) { - var testContext = new TestServiceContext(); + var testContext = new TestServiceContext(LoggerFactory); var requestCount = 10; var requestsReceived = 0; @@ -444,7 +445,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [MemberData(nameof(ConnectionAdapterData))] public async Task InvalidLengthResultsIn400(ListenOptions listenOptions) { - var testContext = new TestServiceContext(); + var testContext = new TestServiceContext(LoggerFactory); using (var server = new TestServer(async httpContext => { var response = httpContext.Response; @@ -488,7 +489,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [MemberData(nameof(ConnectionAdapterData))] public async Task InvalidSizedDataResultsIn400(ListenOptions listenOptions) { - var testContext = new TestServiceContext(); + var testContext = new TestServiceContext(LoggerFactory); using (var server = new TestServer(async httpContext => { var response = httpContext.Response; @@ -534,7 +535,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [MemberData(nameof(ConnectionAdapterData))] public async Task ChunkedNotFinalTransferCodingResultsIn400(ListenOptions listenOptions) { - var testContext = new TestServiceContext(); + var testContext = new TestServiceContext(LoggerFactory); using (var server = new TestServer(httpContext => { return Task.CompletedTask; diff --git a/test/Kestrel.FunctionalTests/ChunkedResponseTests.cs b/test/Kestrel.FunctionalTests/ChunkedResponseTests.cs index dc953808ce..c9a7e70747 100644 --- a/test/Kestrel.FunctionalTests/ChunkedResponseTests.cs +++ b/test/Kestrel.FunctionalTests/ChunkedResponseTests.cs @@ -9,11 +9,12 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.AspNetCore.Testing; +using Microsoft.Extensions.Logging.Testing; using Xunit; namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { - public class ChunkedResponseTests + public class ChunkedResponseTests : LoggedTest { public static TheoryData ConnectionAdapterData => new TheoryData { @@ -28,7 +29,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [MemberData(nameof(ConnectionAdapterData))] public async Task ResponsesAreChunkedAutomatically(ListenOptions listenOptions) { - var testContext = new TestServiceContext(); + var testContext = new TestServiceContext(LoggerFactory); using (var server = new TestServer(async httpContext => { @@ -64,7 +65,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [MemberData(nameof(ConnectionAdapterData))] public async Task ResponsesAreNotChunkedAutomaticallyForHttp10Requests(ListenOptions listenOptions) { - var testContext = new TestServiceContext(); + var testContext = new TestServiceContext(LoggerFactory); using (var server = new TestServer(async httpContext => { @@ -93,7 +94,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [MemberData(nameof(ConnectionAdapterData))] public async Task ResponsesAreChunkedAutomaticallyForHttp11NonKeepAliveRequests(ListenOptions listenOptions) { - var testContext = new TestServiceContext(); + var testContext = new TestServiceContext(LoggerFactory); using (var server = new TestServer(async httpContext => { @@ -130,7 +131,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [MemberData(nameof(ConnectionAdapterData))] public async Task SettingConnectionCloseHeaderInAppDoesNotDisableChunking(ListenOptions listenOptions) { - var testContext = new TestServiceContext(); + var testContext = new TestServiceContext(LoggerFactory); using (var server = new TestServer(async httpContext => { @@ -167,7 +168,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [MemberData(nameof(ConnectionAdapterData))] public async Task ZeroLengthWritesAreIgnored(ListenOptions listenOptions) { - var testContext = new TestServiceContext(); + var testContext = new TestServiceContext(LoggerFactory); using (var server = new TestServer(async httpContext => { @@ -204,7 +205,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [MemberData(nameof(ConnectionAdapterData))] public async Task ZeroLengthWritesFlushHeaders(ListenOptions listenOptions) { - var testContext = new TestServiceContext(); + var testContext = new TestServiceContext(LoggerFactory); var flushed = new SemaphoreSlim(0, 1); @@ -249,7 +250,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [MemberData(nameof(ConnectionAdapterData))] public async Task EmptyResponseBodyHandledCorrectlyWithZeroLengthWrite(ListenOptions listenOptions) { - var testContext = new TestServiceContext(); + var testContext = new TestServiceContext(LoggerFactory); using (var server = new TestServer(async httpContext => { @@ -280,7 +281,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [MemberData(nameof(ConnectionAdapterData))] public async Task ConnectionClosedIfExceptionThrownAfterWrite(ListenOptions listenOptions) { - var testContext = new TestServiceContext(); + var testContext = new TestServiceContext(LoggerFactory); using (var server = new TestServer(async httpContext => { @@ -314,7 +315,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [MemberData(nameof(ConnectionAdapterData))] public async Task ConnectionClosedIfExceptionThrownAfterZeroLengthWrite(ListenOptions listenOptions) { - var testContext = new TestServiceContext(); + var testContext = new TestServiceContext(LoggerFactory); using (var server = new TestServer(async httpContext => { @@ -347,7 +348,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [MemberData(nameof(ConnectionAdapterData))] public async Task WritesAreFlushedPriorToResponseCompletion(ListenOptions listenOptions) { - var testContext = new TestServiceContext(); + var testContext = new TestServiceContext(LoggerFactory); var flushWh = new ManualResetEventSlim(); @@ -394,7 +395,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [MemberData(nameof(ConnectionAdapterData))] public async Task ChunksCanBeWrittenManually(ListenOptions listenOptions) { - var testContext = new TestServiceContext(); + var testContext = new TestServiceContext(LoggerFactory); using (var server = new TestServer(async httpContext => { diff --git a/test/Kestrel.FunctionalTests/ConnectionAdapterTests.cs b/test/Kestrel.FunctionalTests/ConnectionAdapterTests.cs index 21e175d8e0..a4c719bbde 100644 --- a/test/Kestrel.FunctionalTests/ConnectionAdapterTests.cs +++ b/test/Kestrel.FunctionalTests/ConnectionAdapterTests.cs @@ -11,11 +11,12 @@ using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal; using Microsoft.AspNetCore.Testing; +using Microsoft.Extensions.Logging.Testing; using Xunit; namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { - public class ConnectionAdapterTests + public class ConnectionAdapterTests : LoggedTest { [Fact] public async Task CanReadAndWriteWithRewritingConnectionAdapter() @@ -26,7 +27,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests ConnectionAdapters = { adapter } }; - var serviceContext = new TestServiceContext(); + var serviceContext = new TestServiceContext(LoggerFactory); var sendString = "POST / HTTP/1.0\r\nContent-Length: 12\r\n\r\nHello World?"; @@ -56,7 +57,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests ConnectionAdapters = { new AsyncConnectionAdapter() } }; - var serviceContext = new TestServiceContext(); + var serviceContext = new TestServiceContext(LoggerFactory); using (var server = new TestServer(TestApp.EchoApp, serviceContext, listenOptions)) { @@ -85,7 +86,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests ConnectionAdapters = { new AsyncConnectionAdapter() } }; - var serviceContext = new TestServiceContext(); + var serviceContext = new TestServiceContext(LoggerFactory); using (var server = new TestServer(TestApp.EchoApp, serviceContext, listenOptions)) { @@ -106,7 +107,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests ConnectionAdapters = { new ThrowingConnectionAdapter() } }; - var serviceContext = new TestServiceContext(); + var serviceContext = new TestServiceContext(LoggerFactory); using (var server = new TestServer(TestApp.EchoApp, serviceContext, listenOptions)) { @@ -127,7 +128,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests ConnectionAdapters = { new AsyncConnectionAdapter() } }; - var serviceContext = new TestServiceContext(); + var serviceContext = new TestServiceContext(LoggerFactory); var stopTask = Task.CompletedTask; using (var server = new TestServer(TestApp.EchoApp, serviceContext, listenOptions)) @@ -149,7 +150,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests ConnectionAdapters = { new ThrowingConnectionAdapter() } }; - var serviceContext = new TestServiceContext(); + var serviceContext = new TestServiceContext(LoggerFactory); using (var server = new TestServer(TestApp.EchoApp, serviceContext, listenOptions)) { @@ -181,7 +182,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests ConnectionAdapters = { new PassThroughConnectionAdapter() } }; - var serviceContext = new TestServiceContext(); + var serviceContext = new TestServiceContext(LoggerFactory); using (var server = new TestServer(async context => { diff --git a/test/Kestrel.FunctionalTests/ConnectionLimitTests.cs b/test/Kestrel.FunctionalTests/ConnectionLimitTests.cs index db967776ed..8462050e36 100644 --- a/test/Kestrel.FunctionalTests/ConnectionLimitTests.cs +++ b/test/Kestrel.FunctionalTests/ConnectionLimitTests.cs @@ -12,11 +12,12 @@ using Microsoft.AspNetCore.Server.Kestrel.Core.Internal; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Tests; using Microsoft.AspNetCore.Testing; +using Microsoft.Extensions.Logging.Testing; using Xunit; namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { - public class ConnectionLimitTests + public class ConnectionLimitTests : LoggedTest { [Fact] public async Task ResetsCountWhenConnectionClosed() @@ -190,14 +191,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests private TestServer CreateServerWithMaxConnections(RequestDelegate app, long max) { - var serviceContext = new TestServiceContext(); + var serviceContext = new TestServiceContext(LoggerFactory); serviceContext.ServerOptions.Limits.MaxConcurrentConnections = max; return new TestServer(app, serviceContext); } private TestServer CreateServerWithMaxConnections(RequestDelegate app, ResourceCounter concurrentConnectionCounter) { - var serviceContext = new TestServiceContext(); + var serviceContext = new TestServiceContext(LoggerFactory); var listenOptions = new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0)); listenOptions.Use(next => { diff --git a/test/Kestrel.FunctionalTests/DefaultHeaderTests.cs b/test/Kestrel.FunctionalTests/DefaultHeaderTests.cs index 757a5a0a63..c9a564c68f 100644 --- a/test/Kestrel.FunctionalTests/DefaultHeaderTests.cs +++ b/test/Kestrel.FunctionalTests/DefaultHeaderTests.cs @@ -3,16 +3,17 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Testing; +using Microsoft.Extensions.Logging.Testing; using Xunit; namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { - public class DefaultHeaderTests + public class DefaultHeaderTests : LoggedTest { [Fact] public async Task TestDefaultHeaders() { - var testContext = new TestServiceContext() + var testContext = new TestServiceContext(LoggerFactory) { ServerOptions = { AddServerHeader = true } }; diff --git a/test/Kestrel.FunctionalTests/EventSourceTests.cs b/test/Kestrel.FunctionalTests/EventSourceTests.cs index 1d99ade358..eddc396925 100644 --- a/test/Kestrel.FunctionalTests/EventSourceTests.cs +++ b/test/Kestrel.FunctionalTests/EventSourceTests.cs @@ -10,11 +10,12 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; using Microsoft.AspNetCore.Testing; +using Microsoft.Extensions.Logging.Testing; using Xunit; namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { - public class EventSourceTests : IDisposable + public class EventSourceTests : LoggedTest, IDisposable { private readonly TestEventListener _listener = new TestEventListener(); @@ -34,7 +35,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests connectionId = context.Features.Get().ConnectionId; requestId = context.TraceIdentifier; return Task.CompletedTask; - })) + }, new TestServiceContext(LoggerFactory))) { port = server.Port; using (var connection = server.CreateConnection()) diff --git a/test/Kestrel.FunctionalTests/HttpConnectionManagerTests.cs b/test/Kestrel.FunctionalTests/HttpConnectionManagerTests.cs index f0df336587..7f5296763c 100644 --- a/test/Kestrel.FunctionalTests/HttpConnectionManagerTests.cs +++ b/test/Kestrel.FunctionalTests/HttpConnectionManagerTests.cs @@ -9,12 +9,13 @@ using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; using Microsoft.AspNetCore.Testing; using Microsoft.AspNetCore.Testing.xunit; using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Logging.Testing; using Moq; using Xunit; namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { - public class HttpConnectionManagerTests + public class HttpConnectionManagerTests : LoggedTest { // This test causes MemoryPoolBlocks to be finalized which in turn causes an assert failure in debug builds. #if !DEBUG diff --git a/test/Kestrel.FunctionalTests/HttpProtocolSelectionTests.cs b/test/Kestrel.FunctionalTests/HttpProtocolSelectionTests.cs index b75496c097..c5e4f34fbd 100644 --- a/test/Kestrel.FunctionalTests/HttpProtocolSelectionTests.cs +++ b/test/Kestrel.FunctionalTests/HttpProtocolSelectionTests.cs @@ -11,12 +11,12 @@ using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2; using Microsoft.AspNetCore.Testing; using Microsoft.Extensions.Logging; -using Moq; +using Microsoft.Extensions.Logging.Testing; using Xunit; namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { - public class HttpProtocolSelectionTests + public class HttpProtocolSelectionTests : TestApplicationErrorLoggerLoggedTest { [Fact] public Task Server_NoProtocols_Error() @@ -46,6 +46,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests private async Task TestSuccess(HttpProtocols serverProtocols, string request, string expectedResponse) { var builder = TransportSelector.GetWebHostBuilder() + .ConfigureServices(AddTestLogging) .UseKestrel(options => { options.Listen(IPAddress.Loopback, 0, listenOptions => @@ -70,14 +71,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests private async Task TestError(HttpProtocols serverProtocols, string expectedErrorMessage) where TException : Exception { - var logger = new TestApplicationErrorLogger(); - var loggerProvider = new Mock(); - loggerProvider - .Setup(provider => provider.CreateLogger(It.IsAny())) - .Returns(logger); - var builder = TransportSelector.GetWebHostBuilder() - .ConfigureLogging(loggingBuilder => loggingBuilder.AddProvider(loggerProvider.Object)) + .ConfigureServices(AddTestLogging) .UseKestrel(options => options.Listen(IPAddress.Loopback, 0, listenOptions => { listenOptions.Protocols = serverProtocols; @@ -94,7 +89,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } } - Assert.Single(logger.Messages, message => message.LogLevel == LogLevel.Error + Assert.Single(TestApplicationErrorLogger.Messages, message => message.LogLevel == LogLevel.Error && message.EventId.Id == 0 && message.Message == expectedErrorMessage); } diff --git a/test/Kestrel.FunctionalTests/HttpsConnectionAdapterTests.cs b/test/Kestrel.FunctionalTests/HttpsConnectionAdapterTests.cs index 37bc3e4d87..1531e07b97 100644 --- a/test/Kestrel.FunctionalTests/HttpsConnectionAdapterTests.cs +++ b/test/Kestrel.FunctionalTests/HttpsConnectionAdapterTests.cs @@ -19,28 +19,21 @@ using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.AspNetCore.Server.Kestrel.Https; using Microsoft.AspNetCore.Server.Kestrel.Https.Internal; using Microsoft.AspNetCore.Testing; +using Microsoft.Extensions.Logging.Testing; using Xunit; -using Xunit.Abstractions; namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { - public class HttpsConnectionAdapterTests + public class HttpsConnectionAdapterTests : LoggedTest { private static X509Certificate2 _x509Certificate2 = TestResources.GetTestCertificate(); private static X509Certificate2 _x509Certificate2NoExt = TestResources.GetTestCertificate("no_extensions.pfx"); - private readonly ITestOutputHelper _output; - - public HttpsConnectionAdapterTests(ITestOutputHelper output) - { - _output = output; - } // https://github.com/aspnet/KestrelHttpServer/issues/240 // This test currently fails on mono because of an issue with SslStream. [Fact] public async Task CanReadAndWriteWithHttpsConnectionAdapter() { - var serviceContext = new TestServiceContext(); var listenOptions = new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0)) { ConnectionAdapters = @@ -49,7 +42,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } }; - using (var server = new TestServer(App, serviceContext, listenOptions)) + using (var server = new TestServer(App, new TestServiceContext(LoggerFactory), listenOptions)) { var result = await HttpClientSlim.PostAsync($"https://localhost:{server.Port}/", new FormUrlEncodedContent(new[] { @@ -64,7 +57,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [Fact] public async Task RequireCertificateFailsWhenNoCertificate() { - var serviceContext = new TestServiceContext(); var listenOptions = new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0)) { ConnectionAdapters = @@ -78,7 +70,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests }; - using (var server = new TestServer(App, serviceContext, listenOptions)) + using (var server = new TestServer(App, new TestServiceContext(LoggerFactory), listenOptions)) { await Assert.ThrowsAnyAsync( () => HttpClientSlim.GetStringAsync($"https://localhost:{server.Port}/")); @@ -88,7 +80,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [Fact] public async Task AllowCertificateContinuesWhenNoCertificate() { - var serviceContext = new TestServiceContext(); var listenOptions = new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0)) { ConnectionAdapters = @@ -107,8 +98,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests Assert.NotNull(tlsFeature); Assert.Null(tlsFeature.ClientCertificate); return context.Response.WriteAsync("hello world"); - }, - serviceContext, listenOptions)) + }, new TestServiceContext(LoggerFactory), listenOptions)) { var result = await HttpClientSlim.GetStringAsync($"https://localhost:{server.Port}/", validateCertificate: false); Assert.Equal("hello world", result); @@ -126,7 +116,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [Fact] public async Task UsesProvidedServerCertificate() { - var serviceContext = new TestServiceContext(); var listenOptions = new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0)) { ConnectionAdapters = @@ -135,7 +124,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } }; - using (var server = new TestServer(context => Task.CompletedTask, serviceContext, listenOptions)) + using (var server = new TestServer(context => Task.CompletedTask, new TestServiceContext(LoggerFactory), listenOptions)) { using (var client = new TcpClient()) { @@ -153,7 +142,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests public async Task UsesProvidedServerCertificateSelector() { var selectorCalled = 0; - var serviceContext = new TestServiceContext(); var listenOptions = new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0)) { ConnectionAdapters = @@ -175,7 +163,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests }) } }; - using (var server = new TestServer(context => Task.CompletedTask, serviceContext, listenOptions)) + using (var server = new TestServer(context => Task.CompletedTask, new TestServiceContext(LoggerFactory), listenOptions)) { using (var client = new TcpClient()) { @@ -194,7 +182,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests public async Task UsesProvidedServerCertificateSelectorEachTime() { var selectorCalled = 0; - var serviceContext = new TestServiceContext(); var listenOptions = new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0)) { ConnectionAdapters = @@ -220,7 +207,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests }) } }; - using (var server = new TestServer(context => Task.CompletedTask, serviceContext, listenOptions)) + using (var server = new TestServer(context => Task.CompletedTask, new TestServiceContext(LoggerFactory), listenOptions)) { using (var client = new TcpClient()) { @@ -249,7 +236,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests public async Task UsesProvidedServerCertificateSelectorValidatesEkus() { var selectorCalled = 0; - var serviceContext = new TestServiceContext(); var listenOptions = new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0)) { ConnectionAdapters = @@ -264,7 +250,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests }) } }; - using (var server = new TestServer(context => Task.CompletedTask, serviceContext, listenOptions)) + using (var server = new TestServer(context => Task.CompletedTask, new TestServiceContext(LoggerFactory), listenOptions)) { using (var client = new TcpClient()) { @@ -283,7 +269,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests public async Task UsesProvidedServerCertificateSelectorOverridesServerCertificate() { var selectorCalled = 0; - var serviceContext = new TestServiceContext(); var listenOptions = new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0)) { ConnectionAdapters = @@ -306,7 +291,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests }) } }; - using (var server = new TestServer(context => Task.CompletedTask, serviceContext, listenOptions)) + using (var server = new TestServer(context => Task.CompletedTask, new TestServiceContext(LoggerFactory), listenOptions)) { using (var client = new TcpClient()) { @@ -325,7 +310,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests public async Task UsesProvidedServerCertificateSelectorFailsIfYouReturnNull() { var selectorCalled = 0; - var serviceContext = new TestServiceContext(); var listenOptions = new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0)) { ConnectionAdapters = @@ -340,7 +324,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests }) } }; - using (var server = new TestServer(context => Task.CompletedTask, serviceContext, listenOptions)) + using (var server = new TestServer(context => Task.CompletedTask, new TestServiceContext(LoggerFactory), listenOptions)) { using (var client = new TcpClient()) { @@ -358,7 +342,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [Fact] public async Task CertificatePassedToHttpContext() { - var serviceContext = new TestServiceContext(); var listenOptions = new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0)) { ConnectionAdapters = @@ -379,8 +362,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests Assert.NotNull(tlsFeature.ClientCertificate); Assert.NotNull(context.Connection.ClientCertificate); return context.Response.WriteAsync("hello world"); - }, - serviceContext, listenOptions)) + }, new TestServiceContext(LoggerFactory), listenOptions)) { using (var client = new TcpClient()) { @@ -404,9 +386,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests new HttpsConnectionAdapter(new HttpsConnectionAdapterOptions { ServerCertificate = _x509Certificate2 }) } }; - var serviceContext = new TestServiceContext(); - using (var server = new TestServer(context => context.Response.WriteAsync(context.Request.Scheme), serviceContext, listenOptions)) + using (var server = new TestServer(context => context.Response.WriteAsync(context.Request.Scheme), new TestServiceContext(LoggerFactory), listenOptions)) { var result = await HttpClientSlim.GetStringAsync($"https://localhost:{server.Port}/", validateCertificate: false); Assert.Equal("https", result); @@ -416,7 +397,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [Fact] public async Task DoesNotSupportTls10() { - var serviceContext = new TestServiceContext(); var listenOptions = new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0)) { ConnectionAdapters = @@ -430,7 +410,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } }; - using (var server = new TestServer(context => context.Response.WriteAsync("hello world"), serviceContext, listenOptions)) + using (var server = new TestServer(context => context.Response.WriteAsync("hello world"), new TestServiceContext(LoggerFactory), listenOptions)) { // SslStream is used to ensure the certificate is actually passed to the server // HttpClient might not send the certificate because it is invalid or it doesn't match any @@ -450,7 +430,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests public async Task ClientCertificateValidationGetsCalledWithNotNullParameters(ClientCertificateMode mode) { var clientCertificateValidationCalled = false; - var serviceContext = new TestServiceContext(); var listenOptions = new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0)) { ConnectionAdapters = @@ -470,7 +449,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } }; - using (var server = new TestServer(context => Task.CompletedTask, serviceContext, listenOptions)) + using (var server = new TestServer(context => Task.CompletedTask, new TestServiceContext(LoggerFactory), listenOptions)) { using (var client = new TcpClient()) { @@ -487,7 +466,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [InlineData(ClientCertificateMode.RequireCertificate)] public async Task ValidationFailureRejectsConnection(ClientCertificateMode mode) { - var serviceContext = new TestServiceContext(); var listenOptions = new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0)) { ConnectionAdapters = @@ -501,7 +479,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } }; - using (var server = new TestServer(context => Task.CompletedTask, serviceContext, listenOptions)) + using (var server = new TestServer(context => Task.CompletedTask, new TestServiceContext(LoggerFactory), listenOptions)) { using (var client = new TcpClient()) { @@ -517,7 +495,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [InlineData(ClientCertificateMode.RequireCertificate)] public async Task RejectsConnectionOnSslPolicyErrorsWhenNoValidation(ClientCertificateMode mode) { - var serviceContext = new TestServiceContext(); var listenOptions = new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0)) { ConnectionAdapters = @@ -530,7 +507,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } }; - using (var server = new TestServer(context => Task.CompletedTask, serviceContext, listenOptions)) + using (var server = new TestServer(context => Task.CompletedTask, new TestServiceContext(LoggerFactory), listenOptions)) { using (var client = new TcpClient()) { @@ -544,7 +521,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [Fact] public async Task CertificatePassedToHttpContextIsNotDisposed() { - var serviceContext = new TestServiceContext(); var listenOptions = new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0)) { ConnectionAdapters = @@ -568,7 +544,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests return context.Response.WriteAsync("hello world"); }; - using (var server = new TestServer(app, serviceContext, listenOptions)) + using (var server = new TestServer(app, new TestServiceContext(LoggerFactory), listenOptions)) { // SslStream is used to ensure the certificate is actually passed to the server // HttpClient might not send the certificate because it is invalid or it doesn't match any @@ -587,7 +563,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests public void AcceptsCertificateWithoutExtensions(string testCertName) { var certPath = TestResources.GetCertPath(testCertName); - _output.WriteLine("Loading " + certPath); + TestOutputHelper.WriteLine("Loading " + certPath); var cert = new X509Certificate2(certPath, "testPassword"); Assert.Empty(cert.Extensions.OfType()); @@ -603,7 +579,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests public void ValidatesEnhancedKeyUsageOnCertificate(string testCertName) { var certPath = TestResources.GetCertPath(testCertName); - _output.WriteLine("Loading " + certPath); + TestOutputHelper.WriteLine("Loading " + certPath); var cert = new X509Certificate2(certPath, "testPassword"); Assert.NotEmpty(cert.Extensions); var eku = Assert.Single(cert.Extensions.OfType()); @@ -621,7 +597,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests public void ThrowsForCertificatesMissingServerEku(string testCertName) { var certPath = TestResources.GetCertPath(testCertName); - _output.WriteLine("Loading " + certPath); + TestOutputHelper.WriteLine("Loading " + certPath); var cert = new X509Certificate2(certPath, "testPassword"); Assert.NotEmpty(cert.Extensions); var eku = Assert.Single(cert.Extensions.OfType()); diff --git a/test/Kestrel.FunctionalTests/HttpsTests.cs b/test/Kestrel.FunctionalTests/HttpsTests.cs index 051d11ab8d..eda9cbb5e6 100644 --- a/test/Kestrel.FunctionalTests/HttpsTests.cs +++ b/test/Kestrel.FunctionalTests/HttpsTests.cs @@ -20,11 +20,12 @@ using Microsoft.AspNetCore.Testing; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Abstractions.Internal; +using Microsoft.Extensions.Logging.Testing; using Xunit; namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { - public class HttpsTests + public class HttpsTests : LoggedTest { private KestrelServerOptions CreateServerOptions() { @@ -117,6 +118,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests public async Task EmptyRequestLoggedAsDebug() { var loggerProvider = new HandshakeErrorLoggerProvider(); + LoggerFactory.AddProvider(loggerProvider); var hostBuilder = TransportSelector.GetWebHostBuilder() .UseKestrel(options => @@ -126,11 +128,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests listenOptions.UseHttps(TestResources.TestCertificatePath, "testPassword"); }); }) - .ConfigureLogging(builder => - { - builder.AddProvider(loggerProvider); - builder.SetMinimumLevel(LogLevel.Debug); - }) + .ConfigureServices(AddTestLogging) + .ConfigureLogging(builder => builder.AddProvider(loggerProvider)) .Configure(app => { }); using (var host = hostBuilder.Build()) @@ -155,6 +154,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests public async Task ClientHandshakeFailureLoggedAsDebug() { var loggerProvider = new HandshakeErrorLoggerProvider(); + LoggerFactory.AddProvider(loggerProvider); var hostBuilder = TransportSelector.GetWebHostBuilder() .UseKestrel(options => @@ -164,11 +164,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests listenOptions.UseHttps(TestResources.TestCertificatePath, "testPassword"); }); }) - .ConfigureLogging(builder => - { - builder.AddProvider(loggerProvider); - builder.SetMinimumLevel(LogLevel.Debug); - }) + .ConfigureServices(AddTestLogging) .Configure(app => { }); using (var host = hostBuilder.Build()) @@ -196,6 +192,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests public async Task DoesNotThrowObjectDisposedExceptionOnConnectionAbort() { var loggerProvider = new HandshakeErrorLoggerProvider(); + LoggerFactory.AddProvider(loggerProvider); var hostBuilder = TransportSelector.GetWebHostBuilder() .UseKestrel(options => { @@ -204,6 +201,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests listenOptions.UseHttps(TestResources.TestCertificatePath, "testPassword"); }); }) + .ConfigureServices(AddTestLogging) .ConfigureLogging(builder => builder.AddProvider(loggerProvider)) .Configure(app => app.Run(async httpContext => { @@ -248,6 +246,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { var tcs = new TaskCompletionSource(); var loggerProvider = new HandshakeErrorLoggerProvider(); + LoggerFactory.AddProvider(loggerProvider); var hostBuilder = TransportSelector.GetWebHostBuilder() .UseKestrel(options => { @@ -256,6 +255,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests listenOptions.UseHttps(TestResources.TestCertificatePath, "testPassword"); }); }) + .ConfigureServices(AddTestLogging) .ConfigureLogging(builder => builder.AddProvider(loggerProvider)) .Configure(app => app.Run(async httpContext => { @@ -297,6 +297,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests public async Task DoesNotThrowObjectDisposedExceptionOnEmptyConnection() { var loggerProvider = new HandshakeErrorLoggerProvider(); + LoggerFactory.AddProvider(loggerProvider); var hostBuilder = TransportSelector.GetWebHostBuilder() .UseKestrel(options => { @@ -305,6 +306,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests listenOptions.UseHttps(TestResources.TestCertificatePath, "testPassword"); }); }) + .ConfigureServices(AddTestLogging) .ConfigureLogging(builder => builder.AddProvider(loggerProvider)) .Configure(app => app.Run(httpContext => Task.CompletedTask)); @@ -330,6 +332,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests public void ConnectionFilterDoesNotLeakBlock() { var loggerProvider = new HandshakeErrorLoggerProvider(); + LoggerFactory.AddProvider(loggerProvider); var hostBuilder = TransportSelector.GetWebHostBuilder() .UseKestrel(options => @@ -339,6 +342,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests listenOptions.UseHttps(TestResources.TestCertificatePath, "testPassword"); }); }) + .ConfigureServices(AddTestLogging) .ConfigureLogging(builder => builder.AddProvider(loggerProvider)) .Configure(app => { }); @@ -360,6 +364,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests public async Task HandshakeTimesOutAndIsLoggedAsDebug() { var loggerProvider = new HandshakeErrorLoggerProvider(); + LoggerFactory.AddProvider(loggerProvider); var hostBuilder = TransportSelector.GetWebHostBuilder() .UseKestrel(options => { @@ -372,11 +377,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests }); }); }) - .ConfigureLogging(builder => - { - builder.AddProvider(loggerProvider); - builder.SetMinimumLevel(LogLevel.Debug); - }) + .ConfigureServices(AddTestLogging) .Configure(app => app.Run(httpContext => Task.CompletedTask)); using (var host = hostBuilder.Build()) diff --git a/test/Kestrel.FunctionalTests/KeepAliveTimeoutTests.cs b/test/Kestrel.FunctionalTests/KeepAliveTimeoutTests.cs index 32278e4159..90c2b77cfa 100644 --- a/test/Kestrel.FunctionalTests/KeepAliveTimeoutTests.cs +++ b/test/Kestrel.FunctionalTests/KeepAliveTimeoutTests.cs @@ -9,11 +9,12 @@ using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; using Microsoft.AspNetCore.Testing; +using Microsoft.Extensions.Logging.Testing; using Xunit; namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { - public class KeepAliveTimeoutTests + public class KeepAliveTimeoutTests : LoggedTest { private static readonly TimeSpan _keepAliveTimeout = TimeSpan.FromSeconds(10); private static readonly TimeSpan _longDelay = TimeSpan.FromSeconds(30); @@ -185,7 +186,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests private TestServer CreateServer(CancellationToken longRunningCt, CancellationToken upgradeCt) { - return new TestServer(httpContext => App(httpContext, longRunningCt, upgradeCt), new TestServiceContext + return new TestServer(httpContext => App(httpContext, longRunningCt, upgradeCt), new TestServiceContext(LoggerFactory) { // Use real SystemClock so timeouts trigger. SystemClock = new SystemClock(), diff --git a/test/Kestrel.FunctionalTests/LoggingConnectionAdapterTests.cs b/test/Kestrel.FunctionalTests/LoggingConnectionAdapterTests.cs index 12f7e604e3..df211ed170 100644 --- a/test/Kestrel.FunctionalTests/LoggingConnectionAdapterTests.cs +++ b/test/Kestrel.FunctionalTests/LoggingConnectionAdapterTests.cs @@ -8,30 +8,18 @@ using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Testing; -using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Logging.Testing; using Xunit; -using Xunit.Abstractions; namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { - public class LoggingConnectionAdapterTests + public class LoggingConnectionAdapterTests : LoggedTest { - private readonly ITestOutputHelper _output; - - public LoggingConnectionAdapterTests(ITestOutputHelper output) - { - _output = output; - } - [Fact] public async Task LoggingConnectionAdapterCanBeAddedBeforeAndAfterHttpsAdapter() { var host = TransportSelector.GetWebHostBuilder() - .ConfigureLogging(builder => - { - builder.SetMinimumLevel(LogLevel.Trace); - builder.AddXunit(_output); - }) + .ConfigureServices(AddTestLogging) .UseKestrel(options => { options.Listen(new IPEndPoint(IPAddress.Loopback, 0), listenOptions => @@ -41,15 +29,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests listenOptions.UseConnectionLogging(); }); }) - .Configure(app => - { - app.Run(context => + .Configure(app => { - context.Response.ContentLength = 12; - return context.Response.WriteAsync("Hello World!"); - }); - }) - .Build(); + app.Run(context => + { + context.Response.ContentLength = 12; + return context.Response.WriteAsync("Hello World!"); + }); + }) + .Build(); using (host) { diff --git a/test/Kestrel.FunctionalTests/MaxRequestBodySizeTests.cs b/test/Kestrel.FunctionalTests/MaxRequestBodySizeTests.cs index 8c68fe3c39..4bc664f558 100644 --- a/test/Kestrel.FunctionalTests/MaxRequestBodySizeTests.cs +++ b/test/Kestrel.FunctionalTests/MaxRequestBodySizeTests.cs @@ -8,11 +8,12 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.AspNetCore.Testing; +using Microsoft.Extensions.Logging.Testing; using Xunit; namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { - public class MaxRequestBodySizeTests + public class MaxRequestBodySizeTests : LoggedTest { [Fact] public async Task RejectsRequestWithContentLengthHeaderExceedingGlobalLimit() @@ -28,7 +29,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests async () => await context.Request.Body.ReadAsync(buffer, 0, 1)); throw requestRejectedEx; }, - new TestServiceContext { ServerOptions = { Limits = { MaxRequestBodySize = globalMaxRequestBodySize } } })) + new TestServiceContext(LoggerFactory) { ServerOptions = { Limits = { MaxRequestBodySize = globalMaxRequestBodySize } } })) { using (var connection = server.CreateConnection()) { @@ -74,7 +75,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests async () => await context.Request.Body.ReadAsync(buffer, 0, 1)); throw requestRejectedEx; }, - new TestServiceContext { ServerOptions = { Limits = { MaxRequestBodySize = globalMaxRequestBodySize } } })) + new TestServiceContext(LoggerFactory) { ServerOptions = { Limits = { MaxRequestBodySize = globalMaxRequestBodySize } } })) { using (var connection = server.CreateConnection()) { @@ -118,7 +119,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests context.Response.ContentLength = 1; await context.Response.Body.WriteAsync(buffer, 0, 1); }, - new TestServiceContext { ServerOptions = { Limits = { MaxRequestBodySize = 0 } } })) + new TestServiceContext(LoggerFactory) { ServerOptions = { Limits = { MaxRequestBodySize = 0 } } })) { using (var connection = server.CreateConnection()) { @@ -190,7 +191,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests invalidOpEx = Assert.Throws(() => feature.MaxRequestBodySize = perRequestMaxRequestBodySize); throw invalidOpEx; - })) + }, new TestServiceContext(LoggerFactory))) { using (var connection = server.CreateConnection()) { @@ -230,7 +231,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests invalidOpEx = Assert.Throws(() => feature.MaxRequestBodySize = 0x10); throw invalidOpEx; - })) + }, new TestServiceContext(LoggerFactory))) { using (var connection = server.CreateConnection()) { @@ -267,7 +268,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests async () => await context.Request.Body.ReadAsync(buffer, 0, 1)); throw requestRejectedEx2; }, - new TestServiceContext { ServerOptions = { Limits = { MaxRequestBodySize = 0 } } })) + new TestServiceContext(LoggerFactory) { ServerOptions = { Limits = { MaxRequestBodySize = 0 } } })) { using (var connection = server.CreateConnection()) { @@ -314,7 +315,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests throw requestRejectedEx; }, - new TestServiceContext { ServerOptions = { Limits = { MaxRequestBodySize = globalMaxRequestBodySize } } })) + new TestServiceContext(LoggerFactory) { ServerOptions = { Limits = { MaxRequestBodySize = globalMaxRequestBodySize } } })) { using (var connection = server.CreateConnection()) { @@ -360,7 +361,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests Assert.Equal("Hello World", Encoding.ASCII.GetString(buffer)); Assert.Equal("trailing-value", context.Request.Headers["Trailing-Header"].ToString()); }, - new TestServiceContext { ServerOptions = { Limits = { MaxRequestBodySize = globalMaxRequestBodySize } } })) + new TestServiceContext(LoggerFactory) { ServerOptions = { Limits = { MaxRequestBodySize = globalMaxRequestBodySize } } })) { using (var connection = server.CreateConnection()) { @@ -419,7 +420,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests throw requestRejectedEx; } }, - new TestServiceContext { ServerOptions = { Limits = { MaxRequestBodySize = globalMaxRequestBodySize } } })) + new TestServiceContext(LoggerFactory) { ServerOptions = { Limits = { MaxRequestBodySize = globalMaxRequestBodySize } } })) { using (var connection = server.CreateConnection()) { @@ -466,7 +467,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests async () => await context.Request.Body.ReadAsync(buffer, 0, 1)); throw requestRejectedEx2; }, - new TestServiceContext { ServerOptions = { Limits = { MaxRequestBodySize = 0 } } })) + new TestServiceContext(LoggerFactory) { ServerOptions = { Limits = { MaxRequestBodySize = 0 } } })) { using (var connection = server.CreateConnection()) { diff --git a/test/Kestrel.FunctionalTests/MaxRequestBufferSizeTests.cs b/test/Kestrel.FunctionalTests/MaxRequestBufferSizeTests.cs index 79cdee5295..93919845ea 100644 --- a/test/Kestrel.FunctionalTests/MaxRequestBufferSizeTests.cs +++ b/test/Kestrel.FunctionalTests/MaxRequestBufferSizeTests.cs @@ -13,13 +13,12 @@ using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Testing; -using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Logging.Testing; using Xunit; -using Xunit.Abstractions; namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { - public class MaxRequestBufferSizeTests + public class MaxRequestBufferSizeTests : LoggedTest { private const int _dataLength = 20 * 1024 * 1024; @@ -30,13 +29,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests "\r\n" }; - private readonly Action _configureLoggingDelegate; - - public MaxRequestBufferSizeTests(ITestOutputHelper output) - { - _configureLoggingDelegate = builder => builder.AddXunit(output); - } - public static IEnumerable LargeUploadData { get @@ -259,7 +251,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests TaskCompletionSource clientFinishedSendingRequestBody) { var host = TransportSelector.GetWebHostBuilder() - .ConfigureLogging(_configureLoggingDelegate) + .ConfigureServices(AddTestLogging) .UseKestrel(options => { options.Listen(new IPEndPoint(IPAddress.Loopback, 0), listenOptions => diff --git a/test/Kestrel.FunctionalTests/MaxRequestLineSizeTests.cs b/test/Kestrel.FunctionalTests/MaxRequestLineSizeTests.cs index 0ac7785d11..6007877262 100644 --- a/test/Kestrel.FunctionalTests/MaxRequestLineSizeTests.cs +++ b/test/Kestrel.FunctionalTests/MaxRequestLineSizeTests.cs @@ -5,11 +5,12 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.AspNetCore.Testing; +using Microsoft.Extensions.Logging.Testing; using Xunit; namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { - public class MaxRequestLineSizeTests + public class MaxRequestLineSizeTests : LoggedTest { [Theory] [InlineData("GET / HTTP/1.1\r\nHost:\r\n\r\n", 16)] @@ -70,7 +71,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests private TestServer CreateServer(int maxRequestLineSize) { - return new TestServer(async httpContext => await httpContext.Response.WriteAsync("hello, world"), new TestServiceContext + return new TestServer(async httpContext => await httpContext.Response.WriteAsync("hello, world"), new TestServiceContext(LoggerFactory) { ServerOptions = new KestrelServerOptions { diff --git a/test/Kestrel.FunctionalTests/Properties/AssemblyInfo.cs b/test/Kestrel.FunctionalTests/Properties/AssemblyInfo.cs index 24fe027b5e..5e05b4461e 100644 --- a/test/Kestrel.FunctionalTests/Properties/AssemblyInfo.cs +++ b/test/Kestrel.FunctionalTests/Properties/AssemblyInfo.cs @@ -1,8 +1,12 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using Microsoft.Extensions.Logging.Testing; #if MACOS using Xunit; +#endif +[assembly: ShortClassName] +#if MACOS [assembly: CollectionBehavior(DisableTestParallelization = true)] #endif diff --git a/test/Kestrel.FunctionalTests/RequestBodyTimeoutTests.cs b/test/Kestrel.FunctionalTests/RequestBodyTimeoutTests.cs index 7cb1e1f33c..8e6c84296e 100644 --- a/test/Kestrel.FunctionalTests/RequestBodyTimeoutTests.cs +++ b/test/Kestrel.FunctionalTests/RequestBodyTimeoutTests.cs @@ -17,14 +17,14 @@ using Xunit; namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { - public class RequestBodyTimeoutTests + public class RequestBodyTimeoutTests : LoggedTest { [Fact] public async Task RequestTimesOutWhenRequestBodyNotReceivedAtSpecifiedMinimumRate() { var gracePeriod = TimeSpan.FromSeconds(5); var systemClock = new MockSystemClock(); - var serviceContext = new TestServiceContext + var serviceContext = new TestServiceContext(LoggerFactory) { SystemClock = systemClock, DateHeaderValueManager = new DateHeaderValueManager(systemClock) @@ -69,16 +69,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [Fact] public async Task RequestTimesOutWhenNotDrainedWithinDrainTimeoutPeriod() { - var sink = new TestSink(); - var logger = new TestLogger("TestLogger", sink, enabled: true); - // This test requires a real clock since we can't control when the drain timeout is set var systemClock = new SystemClock(); - var serviceContext = new TestServiceContext + var serviceContext = new TestServiceContext(LoggerFactory) { SystemClock = systemClock, DateHeaderValueManager = new DateHeaderValueManager(systemClock), - Log = new KestrelTrace(logger) }; var appRunningEvent = new ManualResetEventSlim(); @@ -115,7 +111,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } } - Assert.Contains(sink.Writes, w => w.EventId.Id == 17 && w.LogLevel == LogLevel.Information && w.Exception is BadHttpRequestException + Assert.Contains(TestSink.Writes, w => w.EventId.Id == 17 && w.LogLevel == LogLevel.Information && w.Exception is BadHttpRequestException && ((BadHttpRequestException)w.Exception).StatusCode == StatusCodes.Status408RequestTimeout); } @@ -124,7 +120,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { var gracePeriod = TimeSpan.FromSeconds(5); var systemClock = new MockSystemClock(); - var serviceContext = new TestServiceContext + var serviceContext = new TestServiceContext(LoggerFactory) { SystemClock = systemClock, DateHeaderValueManager = new DateHeaderValueManager(systemClock) diff --git a/test/Kestrel.FunctionalTests/RequestHeaderLimitsTests.cs b/test/Kestrel.FunctionalTests/RequestHeaderLimitsTests.cs index 375e92c255..6de4c37a99 100644 --- a/test/Kestrel.FunctionalTests/RequestHeaderLimitsTests.cs +++ b/test/Kestrel.FunctionalTests/RequestHeaderLimitsTests.cs @@ -6,11 +6,12 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.AspNetCore.Testing; +using Microsoft.Extensions.Logging.Testing; using Xunit; namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { - public class RequestHeaderLimitsTests + public class RequestHeaderLimitsTests : LoggedTest { [Theory] [InlineData(0, 1)] @@ -148,7 +149,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests options.Limits.MaxRequestHeadersTotalSize = maxRequestHeadersTotalSize.Value; } - return new TestServer(async httpContext => await httpContext.Response.WriteAsync("hello, world"), new TestServiceContext + return new TestServer(async httpContext => await httpContext.Response.WriteAsync("hello, world"), new TestServiceContext(LoggerFactory) { ServerOptions = options }); diff --git a/test/Kestrel.FunctionalTests/RequestHeadersTimeoutTests.cs b/test/Kestrel.FunctionalTests/RequestHeadersTimeoutTests.cs index 2520467a72..57fe8fc274 100644 --- a/test/Kestrel.FunctionalTests/RequestHeadersTimeoutTests.cs +++ b/test/Kestrel.FunctionalTests/RequestHeadersTimeoutTests.cs @@ -7,11 +7,12 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; using Microsoft.AspNetCore.Testing; +using Microsoft.Extensions.Logging.Testing; using Xunit; namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { - public class RequestHeadersTimeoutTests + public class RequestHeadersTimeoutTests : LoggedTest { private static readonly TimeSpan RequestHeadersTimeout = TimeSpan.FromSeconds(10); private static readonly TimeSpan LongDelay = TimeSpan.FromSeconds(30); @@ -96,7 +97,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests await httpContext.Request.Body.ReadAsync(new byte[1], 0, 1); await httpContext.Response.WriteAsync("hello, world"); }, - new TestServiceContext + new TestServiceContext(LoggerFactory) { // Use real SystemClock so timeouts trigger. SystemClock = new SystemClock(), diff --git a/test/Kestrel.FunctionalTests/RequestTargetProcessingTests.cs b/test/Kestrel.FunctionalTests/RequestTargetProcessingTests.cs index 4ebb7ce571..6bf18030a3 100644 --- a/test/Kestrel.FunctionalTests/RequestTargetProcessingTests.cs +++ b/test/Kestrel.FunctionalTests/RequestTargetProcessingTests.cs @@ -9,16 +9,17 @@ using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; using Microsoft.AspNetCore.Testing; +using Microsoft.Extensions.Logging.Testing; using Xunit; namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { - public class RequestTargetProcessingTests + public class RequestTargetProcessingTests : LoggedTest { [Fact] public async Task RequestPathIsNotNormalized() { - var testContext = new TestServiceContext(); + var testContext = new TestServiceContext(LoggerFactory); var listenOptions = new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0)); using (var server = new TestServer(async context => @@ -64,7 +65,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [InlineData("/base/hello%20world?foo=1&bar=2")] public async Task RequestFeatureContainsRawTarget(string requestTarget) { - var testContext = new TestServiceContext(); + var testContext = new TestServiceContext(LoggerFactory); using (var server = new TestServer(async context => { @@ -96,7 +97,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [InlineData(HttpMethod.Connect, "host")] public async Task NonPathRequestTargetSetInRawTarget(HttpMethod method, string requestTarget) { - var testContext = new TestServiceContext(); + var testContext = new TestServiceContext(LoggerFactory); using (var server = new TestServer(async context => { @@ -111,8 +112,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { using (var connection = server.CreateConnection()) { - var host = method == HttpMethod.Connect - ? requestTarget + var host = method == HttpMethod.Connect + ? requestTarget : string.Empty; await connection.Send( diff --git a/test/Kestrel.FunctionalTests/RequestTests.cs b/test/Kestrel.FunctionalTests/RequestTests.cs index 7344c56784..e7cadd4ae8 100644 --- a/test/Kestrel.FunctionalTests/RequestTests.cs +++ b/test/Kestrel.FunctionalTests/RequestTests.cs @@ -26,27 +26,20 @@ using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; using Microsoft.AspNetCore.Testing; using Microsoft.AspNetCore.Testing.xunit; using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Logging.Testing; using Moq; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using Xunit; -using Xunit.Abstractions; namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { - public class RequestTests + public class RequestTests : LoggedTest { private const int _connectionStartedEventId = 1; private const int _connectionResetEventId = 19; private static readonly int _semaphoreWaitTimeout = Debugger.IsAttached ? 10000 : 2500; - private readonly ITestOutputHelper _output; - - public RequestTests(ITestOutputHelper output) - { - _output = output; - } - public static TheoryData ConnectionAdapterData => new TheoryData { new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0)), @@ -70,6 +63,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests Assert.True(bufferLength % 256 == 0, $"{nameof(bufferLength)} must be evenly divisible by 256"); var builder = TransportSelector.GetWebHostBuilder() + .ConfigureServices(AddTestLogging) .UseKestrel(options => { options.Limits.MaxRequestBodySize = contentLength; @@ -158,6 +152,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests var builder = TransportSelector.GetWebHostBuilder() .UseKestrel() .UseUrls("http://127.0.0.1:0") + .ConfigureServices(AddTestLogging) .Configure(app => { app.Run(async context => @@ -186,28 +181,29 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests var responseBodyPersisted = false; var builder = TransportSelector.GetWebHostBuilder() - .UseKestrel() - .UseUrls("http://127.0.0.1:0") - .Configure(app => - { - app.Run(async context => - { - if (context.Request.Body is MemoryStream) - { - requestBodyPersisted = true; - } + .UseKestrel() + .UseUrls("http://127.0.0.1:0") + .ConfigureServices(AddTestLogging) + .Configure(app => + { + app.Run(async context => + { + if (context.Request.Body is MemoryStream) + { + requestBodyPersisted = true; + } - if (context.Response.Body is MemoryStream) - { - responseBodyPersisted = true; - } + if (context.Response.Body is MemoryStream) + { + responseBodyPersisted = true; + } - context.Request.Body = new MemoryStream(); - context.Response.Body = new MemoryStream(); + context.Request.Body = new MemoryStream(); + context.Response.Body = new MemoryStream(); - await context.Response.WriteAsync("hello, world"); - }); - }); + await context.Response.WriteAsync("hello, world"); + }); + }); using (var host = builder.Build()) { @@ -229,24 +225,25 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { var dataRead = false; var builder = TransportSelector.GetWebHostBuilder() - .UseKestrel() - .UseUrls("http://127.0.0.1:0") - .Configure(app => - { - app.Run(async context => - { - var stream = await context.Features.Get().UpgradeAsync(); - var data = new byte[3]; - var bytesRead = 0; + .UseKestrel() + .UseUrls("http://127.0.0.1:0") + .ConfigureServices(AddTestLogging) + .Configure(app => + { + app.Run(async context => + { + var stream = await context.Features.Get().UpgradeAsync(); + var data = new byte[3]; + var bytesRead = 0; - while (bytesRead < 3) - { - bytesRead += await stream.ReadAsync(data, bytesRead, data.Length - bytesRead); - } + while (bytesRead < 3) + { + bytesRead += await stream.ReadAsync(data, bytesRead, data.Length - bytesRead); + } - dataRead = Encoding.ASCII.GetString(data, 0, 3) == "abc"; - }); - }); + dataRead = Encoding.ASCII.GetString(data, 0, 3) == "abc"; + }); + }); using (var host = builder.Build()) { @@ -280,6 +277,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests .Setup(logger => logger.Log(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny>())) .Callback>((logLevel, eventId, state, exception, formatter) => { + Logger.Log(logLevel, eventId, state, exception, formatter); if (eventId.Id == _connectionStartedEventId) { connectionStarted.Release(); @@ -298,7 +296,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests var mockLoggerFactory = new Mock(); mockLoggerFactory .Setup(factory => factory.CreateLogger(It.IsAny())) - .Returns(Mock.Of()); + .Returns(Logger); mockLoggerFactory .Setup(factory => factory.CreateLogger(It.IsIn("Microsoft.AspNetCore.Server.Kestrel", "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv", @@ -340,6 +338,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests .Setup(logger => logger.Log(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny>())) .Callback>((logLevel, eventId, state, exception, formatter) => { + Logger.Log(logLevel, eventId, state, exception, formatter); if (eventId.Id == _connectionResetEventId) { connectionReset.Release(); @@ -354,7 +353,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests var mockLoggerFactory = new Mock(); mockLoggerFactory .Setup(factory => factory.CreateLogger(It.IsAny())) - .Returns(Mock.Of()); + .Returns(Logger); mockLoggerFactory .Setup(factory => factory.CreateLogger(It.IsIn("Microsoft.AspNetCore.Server.Kestrel", "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv", @@ -410,8 +409,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests .Setup(logger => logger.Log(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny>())) .Callback>((logLevel, eventId, state, exception, formatter) => { + Logger.Log(logLevel, eventId, state, exception, formatter); var log = $"Log {logLevel}[{eventId}]: {formatter(state, exception)} {exception}"; - _output.WriteLine(log); + TestOutputHelper.WriteLine(log); if (eventId.Id == _connectionResetEventId) { @@ -427,7 +427,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests var mockLoggerFactory = new Mock(); mockLoggerFactory .Setup(factory => factory.CreateLogger(It.IsAny())) - .Returns(Mock.Of()); + .Returns(Logger); mockLoggerFactory .Setup(factory => factory.CreateLogger(It.IsIn("Microsoft.AspNetCore.Server.Kestrel", "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv", @@ -472,6 +472,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests var expectedExceptionThrown = false; var builder = TransportSelector.GetWebHostBuilder() + .ConfigureServices(AddTestLogging) .UseKestrel() .UseUrls("http://127.0.0.1:0") .Configure(app => app.Run(async context => @@ -518,6 +519,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests var builder = TransportSelector.GetWebHostBuilder() .UseKestrel() .UseUrls("http://127.0.0.1:0") + .ConfigureServices(AddTestLogging) .Configure(app => app.Run(async context => { appStarted.Release(); @@ -548,6 +550,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests var builder = TransportSelector.GetWebHostBuilder() .UseKestrel() .UseUrls("http://127.0.0.1:0") + .ConfigureServices(AddTestLogging) .Configure(app => app.Run(context => { context.Abort(); @@ -597,7 +600,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests queryTcs.TrySetResult(context.Request.Query); rawTargetTcs.TrySetResult(context.Features.Get().RawTarget); await context.Response.WriteAsync("Done"); - })) + }, new TestServiceContext(LoggerFactory))) { using (var connection = server.CreateConnection()) { @@ -646,7 +649,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { context.TraceIdentifier = knownId; await context.Response.WriteAsync(context.TraceIdentifier); - })) + }, new TestServiceContext(LoggerFactory))) { var requestId = await HttpClientSlim.GetStringAsync($"http://{server.EndPoint}") .TimeoutAfter(TestConstants.DefaultTimeout); @@ -665,7 +668,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests Assert.Equal(identifierLength, Encoding.ASCII.GetByteCount(context.TraceIdentifier)); context.Response.ContentLength = identifierLength; await context.Response.WriteAsync(context.TraceIdentifier); - })) + }, new TestServiceContext(LoggerFactory))) { var usedIds = new ConcurrentBag(); var uri = $"http://{server.EndPoint}"; @@ -706,7 +709,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [MemberData(nameof(ConnectionAdapterData))] public async Task Http11KeptAliveByDefault(ListenOptions listenOptions) { - var testContext = new TestServiceContext(); + var testContext = new TestServiceContext(LoggerFactory); using (var server = new TestServer(TestApp.EchoAppChunked, testContext, listenOptions)) { @@ -741,7 +744,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [MemberData(nameof(ConnectionAdapterData))] public async Task Http10NotKeptAliveByDefault(ListenOptions listenOptions) { - var testContext = new TestServiceContext(); + var testContext = new TestServiceContext(LoggerFactory); using (var server = new TestServer(TestApp.EchoApp, testContext, listenOptions)) { @@ -781,7 +784,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [MemberData(nameof(ConnectionAdapterData))] public async Task Http10KeepAlive(ListenOptions listenOptions) { - var testContext = new TestServiceContext(); + var testContext = new TestServiceContext(LoggerFactory); using (var server = new TestServer(TestApp.EchoAppChunked, testContext, listenOptions)) { @@ -816,7 +819,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [MemberData(nameof(ConnectionAdapterData))] public async Task Http10KeepAliveNotHonoredIfResponseContentLengthNotSet(ListenOptions listenOptions) { - var testContext = new TestServiceContext(); + var testContext = new TestServiceContext(LoggerFactory); using (var server = new TestServer(TestApp.EchoApp, testContext, listenOptions)) { @@ -856,7 +859,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [MemberData(nameof(ConnectionAdapterData))] public async Task Http10KeepAliveHonoredIfResponseContentLengthSet(ListenOptions listenOptions) { - var testContext = new TestServiceContext(); + var testContext = new TestServiceContext(LoggerFactory); using (var server = new TestServer(TestApp.EchoAppChunked, testContext, listenOptions)) { @@ -913,7 +916,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [MemberData(nameof(ConnectionAdapterData))] public async Task Expect100ContinueHonored(ListenOptions listenOptions) { - var testContext = new TestServiceContext(); + var testContext = new TestServiceContext(LoggerFactory); using (var server = new TestServer(TestApp.EchoAppChunked, testContext, listenOptions)) { @@ -946,7 +949,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [MemberData(nameof(ConnectionAdapterData))] public async Task ZeroContentLengthAssumedOnNonKeepAliveRequestsWithoutContentLengthOrTransferEncodingHeader(ListenOptions listenOptions) { - var testContext = new TestServiceContext(); + var testContext = new TestServiceContext(LoggerFactory); using (var server = new TestServer(async httpContext => { @@ -996,7 +999,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [MemberData(nameof(ConnectionAdapterData))] public async Task ConnectionClosesWhenFinReceivedBeforeRequestCompletes(ListenOptions listenOptions) { - var testContext = new TestServiceContext(); + var testContext = new TestServiceContext(LoggerFactory); // FIN callbacks are scheduled so run inline to make this test more reliable testContext.Scheduler = PipeScheduler.Inline; @@ -1026,7 +1029,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [MemberData(nameof(ConnectionAdapterData))] public async Task RequestsCanBeAbortedMidRead(ListenOptions listenOptions) { - var testContext = new TestServiceContext(); + var testContext = new TestServiceContext(LoggerFactory); var readTcs = new TaskCompletionSource(); var registrationTcs = new TaskCompletionSource(); @@ -1106,7 +1109,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [MemberData(nameof(ConnectionAdapterData))] public async Task RequestHeadersAreResetOnEachRequest(ListenOptions listenOptions) { - var testContext = new TestServiceContext(); + var testContext = new TestServiceContext(LoggerFactory); IHeaderDictionary originalRequestHeaders = null; var firstRequest = true; @@ -1159,7 +1162,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { const string message = "Hello World"; - var testContext = new TestServiceContext(); + var testContext = new TestServiceContext(LoggerFactory); using (var server = new TestServer(async context => { @@ -1197,7 +1200,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [Fact] public async Task HeadersAndStreamsAreReusedAcrossRequests() { - var testContext = new TestServiceContext(); + var testContext = new TestServiceContext(LoggerFactory); var streamCount = 0; var requestHeadersCount = 0; var responseHeadersCount = 0; @@ -1274,7 +1277,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [MemberData(nameof(HostHeaderData))] public async Task MatchesValidRequestTargetAndHostHeader(string request, string hostHeader) { - using (var server = new TestServer(context => Task.CompletedTask)) + using (var server = new TestServer(context => Task.CompletedTask, new TestServiceContext(LoggerFactory))) { using (var connection = server.CreateConnection()) { @@ -1292,7 +1295,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests public async Task ServerConsumesKeepAliveContentLengthRequest() { // The app doesn't read the request body, so it should be consumed by the server - using (var server = new TestServer(context => Task.CompletedTask)) + using (var server = new TestServer(context => Task.CompletedTask, new TestServiceContext(LoggerFactory))) { using (var connection = server.CreateConnection()) { @@ -1333,7 +1336,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests public async Task ServerConsumesKeepAliveChunkedRequest() { // The app doesn't read the request body, so it should be consumed by the server - using (var server = new TestServer(context => Task.CompletedTask)) + using (var server = new TestServer(context => Task.CompletedTask, new TestServiceContext(LoggerFactory))) { using (var connection = server.CreateConnection()) { @@ -1381,7 +1384,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests public async Task NonKeepAliveRequestNotConsumedByAppCompletes() { // The app doesn't read the request body, so it should be consumed by the server - using (var server = new TestServer(context => Task.CompletedTask)) + using (var server = new TestServer(context => Task.CompletedTask, new TestServiceContext(LoggerFactory))) { using (var connection = server.CreateConnection()) { @@ -1414,7 +1417,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests var response = Encoding.ASCII.GetBytes("goodbye"); await duplexStream.WriteAsync(response, 0, response.Length); - })) + }, new TestServiceContext(LoggerFactory))) { using (var connection = server.CreateConnection()) { @@ -1440,7 +1443,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { var appEvent = new ManualResetEventSlim(); var delayEvent = new ManualResetEventSlim(); - var serviceContext = new TestServiceContext + var serviceContext = new TestServiceContext(LoggerFactory) { SystemClock = new SystemClock() }; @@ -1545,7 +1548,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests context.Response.ContentLength = 6; await context.Response.Body.WriteAsync(buffer, 0, 6); - })) + }, new TestServiceContext(LoggerFactory))) { using (var connection = server.CreateConnection()) { @@ -1576,7 +1579,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [Fact] public async Task SynchronousReadsCanBeDisallowedGlobally() { - var testContext = new TestServiceContext + var testContext = new TestServiceContext(LoggerFactory) { ServerOptions = { AllowSynchronousIO = false } }; @@ -1627,6 +1630,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests var builder = TransportSelector.GetWebHostBuilder() .UseKestrel() .UseUrls($"http://{registerAddress}:0") + .ConfigureServices(AddTestLogging) .Configure(app => { app.Run(async context => diff --git a/test/Kestrel.FunctionalTests/ResponseTests.cs b/test/Kestrel.FunctionalTests/ResponseTests.cs index ca9616dfcf..1482302999 100644 --- a/test/Kestrel.FunctionalTests/ResponseTests.cs +++ b/test/Kestrel.FunctionalTests/ResponseTests.cs @@ -33,11 +33,10 @@ using Microsoft.Extensions.Logging.Testing; using Microsoft.Extensions.Primitives; using Moq; using Xunit; -using Xunit.Abstractions; namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { - public class ResponseTests : LoggedTest + public class ResponseTests : TestApplicationErrorLoggerLoggedTest { public static TheoryData ConnectionAdapterData => new TheoryData { @@ -48,14 +47,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } }; - public ResponseTests(ITestOutputHelper outputHelper) : base(outputHelper) { } - [Fact] public async Task LargeDownload() { var hostBuilder = TransportSelector.GetWebHostBuilder() .UseKestrel() .UseUrls("http://127.0.0.1:0/") + .ConfigureServices(AddTestLogging) .Configure(app => { app.Run(async context => @@ -108,6 +106,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests var hostBuilder = TransportSelector.GetWebHostBuilder() .UseKestrel() .UseUrls("http://127.0.0.1:0/") + .ConfigureServices(AddTestLogging) .Configure(app => { app.Run(async context => @@ -151,6 +150,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests var hostBuilder = TransportSelector.GetWebHostBuilder() .UseKestrel() .UseUrls("http://127.0.0.1:0/") + .ConfigureServices(AddTestLogging) .Configure(app => { app.Run(context => @@ -189,6 +189,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests var hostBuilder = TransportSelector.GetWebHostBuilder() .UseKestrel() .UseUrls("http://127.0.0.1:0/") + .ConfigureServices(AddTestLogging) .Configure(app => { app.Run(async context => @@ -218,6 +219,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests public Task ResponseStatusCodeSetBeforeHttpContextDisposeAppException() { return ResponseStatusCodeSetBeforeHttpContextDispose( + TestSink, + LoggerFactory, context => { throw new Exception(); @@ -230,6 +233,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests public Task ResponseStatusCodeSetBeforeHttpContextDisposeRequestAborted() { return ResponseStatusCodeSetBeforeHttpContextDispose( + TestSink, + LoggerFactory, context => { context.Abort(); @@ -243,6 +248,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests public Task ResponseStatusCodeSetBeforeHttpContextDisposeRequestAbortedAppException() { return ResponseStatusCodeSetBeforeHttpContextDispose( + TestSink, + LoggerFactory, context => { context.Abort(); @@ -256,6 +263,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests public Task ResponseStatusCodeSetBeforeHttpContextDisposedRequestMalformed() { return ResponseStatusCodeSetBeforeHttpContextDispose( + TestSink, + LoggerFactory, context => { return Task.CompletedTask; @@ -269,6 +278,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests public Task ResponseStatusCodeSetBeforeHttpContextDisposedRequestMalformedRead() { return ResponseStatusCodeSetBeforeHttpContextDispose( + TestSink, + LoggerFactory, async context => { await context.Request.Body.ReadAsync(new byte[1], 0, 1); @@ -282,6 +293,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests public Task ResponseStatusCodeSetBeforeHttpContextDisposedRequestMalformedReadIgnored() { return ResponseStatusCodeSetBeforeHttpContextDispose( + TestSink, + LoggerFactory, async context => { try @@ -303,6 +316,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests var hostBuilder = TransportSelector.GetWebHostBuilder() .UseKestrel() .UseUrls("http://127.0.0.1:0/") + .ConfigureServices(AddTestLogging) .Configure(app => { app.Run(async context => @@ -331,6 +345,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests var hostBuilder = TransportSelector.GetWebHostBuilder() .UseKestrel() .UseUrls("http://127.0.0.1:0/") + .ConfigureServices(AddTestLogging) .Configure(app => { app.Run(async context => @@ -368,7 +383,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests onCompletedTcs.SetResult(null); })); return Task.CompletedTask; - })) + }, new TestServiceContext(LoggerFactory))) { using (var connection = server.CreateConnection()) { @@ -391,6 +406,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } private static async Task ResponseStatusCodeSetBeforeHttpContextDispose( + ITestSink testSink, + ILoggerFactory loggerFactory, RequestDelegate handler, HttpStatusCode? expectedClientStatusCode, HttpStatusCode expectedServerStatusCode, @@ -407,10 +424,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests disposedTcs.TrySetResult(c.Response.StatusCode); }); - var sink = new TestSink(); - var logger = new TestLogger("TestLogger", sink, enabled: true); - - using (var server = new TestServer(handler, new TestServiceContext() { Log = new KestrelTrace(logger) }, + using (var server = new TestServer(handler, new TestServiceContext(loggerFactory), new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0)), services => services.AddSingleton(mockHttpContextFactory.Object))) { @@ -470,12 +484,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests if (sendMalformedRequest) { - Assert.Contains(sink.Writes, w => w.EventId.Id == 17 && w.LogLevel == LogLevel.Information && w.Exception is BadHttpRequestException + Assert.Contains(testSink.Writes, w => w.EventId.Id == 17 && w.LogLevel == LogLevel.Information && w.Exception is BadHttpRequestException && ((BadHttpRequestException)w.Exception).StatusCode == StatusCodes.Status400BadRequest); } else { - Assert.DoesNotContain(sink.Writes, w => w.EventId.Id == 17 && w.LogLevel == LogLevel.Information && w.Exception is BadHttpRequestException + Assert.DoesNotContain(testSink.Writes, w => w.EventId.Id == 17 && w.LogLevel == LogLevel.Information && w.Exception is BadHttpRequestException && ((BadHttpRequestException)w.Exception).StatusCode == StatusCodes.Status400BadRequest); } } @@ -485,14 +499,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests public async Task NoErrorResponseSentWhenAppSwallowsBadRequestException() { BadHttpRequestException readException = null; - var sink = new TestSink(); - var logger = new TestLogger("TestLogger", sink, enabled: true); using (var server = new TestServer(async httpContext => { readException = await Assert.ThrowsAsync( async () => await httpContext.Request.Body.ReadAsync(new byte[1], 0, 1)); - }, new TestServiceContext() { Log = new KestrelTrace(logger) })) + }, new TestServiceContext(LoggerFactory))) { using (var connection = server.CreateConnection()) { @@ -513,7 +525,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests Assert.NotNull(readException); - Assert.Contains(sink.Writes, w => w.EventId.Id == 17 && w.LogLevel == LogLevel.Information && w.Exception is BadHttpRequestException + Assert.Contains(TestSink.Writes, w => w.EventId.Id == 17 && w.LogLevel == LogLevel.Information && w.Exception is BadHttpRequestException && ((BadHttpRequestException)w.Exception).StatusCode == StatusCodes.Status400BadRequest); } @@ -524,7 +536,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { await httpContext.Response.WriteAsync("hello, "); await httpContext.Response.WriteAsync("world"); - })) + }, new TestServiceContext(LoggerFactory))) { using (var connection = server.CreateConnection()) { @@ -559,7 +571,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { httpContext.Response.StatusCode = statusCode; return Task.CompletedTask; - })) + }, new TestServiceContext(LoggerFactory))) { using (var connection = server.CreateConnection()) { @@ -583,7 +595,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests using (var server = new TestServer(httpContext => { return Task.CompletedTask; - })) + }, new TestServiceContext(LoggerFactory))) { using (var connection = server.CreateConnection()) { @@ -616,7 +628,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { await httpContext.Response.WriteAsync(response); await httpContext.Response.Body.FlushAsync(); - }, new TestServiceContext { Log = mockKestrelTrace.Object })) + }, new TestServiceContext(LoggerFactory, mockKestrelTrace.Object))) { using (var connection = server.CreateConnection()) { @@ -645,10 +657,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [Fact] public async Task ThrowsAndClosesConnectionWhenAppWritesMoreThanContentLengthWrite() { - var testLogger = new TestApplicationErrorLogger(); - var serviceContext = new TestServiceContext + var serviceContext = new TestServiceContext(LoggerFactory) { - Log = new TestKestrelTrace(testLogger), ServerOptions = { AllowSynchronousIO = true } }; @@ -678,7 +688,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } } - var logMessage = Assert.Single(testLogger.Messages, message => message.LogLevel == LogLevel.Error); + var logMessage = Assert.Single(TestApplicationErrorLogger.Messages, message => message.LogLevel == LogLevel.Error); Assert.Equal( $"Response Content-Length mismatch: too many bytes written (12 of 11).", @@ -689,8 +699,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [Fact] public async Task ThrowsAndClosesConnectionWhenAppWritesMoreThanContentLengthWriteAsync() { - var testLogger = new TestApplicationErrorLogger(); - var serviceContext = new TestServiceContext { Log = new TestKestrelTrace(testLogger) }; + var serviceContext = new TestServiceContext(LoggerFactory); using (var server = new TestServer(async httpContext => { @@ -715,7 +724,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } } - var logMessage = Assert.Single(testLogger.Messages, message => message.LogLevel == LogLevel.Error); + var logMessage = Assert.Single(TestApplicationErrorLogger.Messages, message => message.LogLevel == LogLevel.Error); Assert.Equal( $"Response Content-Length mismatch: too many bytes written (12 of 11).", logMessage.Exception.Message); @@ -724,10 +733,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [Fact] public async Task InternalServerErrorAndConnectionClosedOnWriteWithMoreThanContentLengthAndResponseNotStarted() { - var testLogger = new TestApplicationErrorLogger(); - var serviceContext = new TestServiceContext + var serviceContext = new TestServiceContext(LoggerFactory) { - Log = new TestKestrelTrace(testLogger), ServerOptions = { AllowSynchronousIO = true } }; @@ -756,7 +763,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } } - var logMessage = Assert.Single(testLogger.Messages, message => message.LogLevel == LogLevel.Error); + var logMessage = Assert.Single(TestApplicationErrorLogger.Messages, message => message.LogLevel == LogLevel.Error); Assert.Equal( $"Response Content-Length mismatch: too many bytes written (12 of 5).", logMessage.Exception.Message); @@ -765,8 +772,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [Fact] public async Task InternalServerErrorAndConnectionClosedOnWriteAsyncWithMoreThanContentLengthAndResponseNotStarted() { - var testLogger = new TestApplicationErrorLogger(); - var serviceContext = new TestServiceContext { Log = new TestKestrelTrace(testLogger) }; + var serviceContext = new TestServiceContext(LoggerFactory); using (var server = new TestServer(httpContext => { @@ -792,7 +798,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } } - var logMessage = Assert.Single(testLogger.Messages, message => message.LogLevel == LogLevel.Error); + var logMessage = Assert.Single(TestApplicationErrorLogger.Messages, message => message.LogLevel == LogLevel.Error); Assert.Equal( $"Response Content-Length mismatch: too many bytes written (12 of 5).", logMessage.Exception.Message); @@ -814,7 +820,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { httpContext.Response.ContentLength = 13; await httpContext.Response.WriteAsync("hello, world"); - }, new TestServiceContext { Log = mockTrace.Object })) + }, new TestServiceContext(LoggerFactory, mockTrace.Object))) { using (var connection = server.CreateConnection()) { @@ -869,7 +875,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests // Wait until the request is aborted so we know HttpProtocol will skip the response content length check. Assert.True(await requestAborted.WaitAsync(TestConstants.DefaultTimeout)); - }, new TestServiceContext { Log = mockTrace.Object })) + }, new TestServiceContext(LoggerFactory, mockTrace.Object))) { using (var connection = server.CreateConnection()) { @@ -902,8 +908,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [Fact] public async Task WhenAppSetsContentLengthButDoesNotWriteBody500ResponseSentAndConnectionDoesNotClose() { - var testLogger = new TestApplicationErrorLogger(); - var serviceContext = new TestServiceContext { Log = new TestKestrelTrace(testLogger) }; + var serviceContext = new TestServiceContext(LoggerFactory); using (var server = new TestServer(httpContext => { @@ -934,9 +939,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } } - var error = testLogger.Messages.Where(message => message.LogLevel == LogLevel.Error); + var error = TestApplicationErrorLogger.Messages.Where(message => message.LogLevel == LogLevel.Error); Assert.Equal(2, error.Count()); - Assert.All(error, message => message.Equals("Response Content-Length mismatch: too few bytes written (0 of 5).")); + Assert.All(error, message => message.Message.Equals("Response Content-Length mismatch: too few bytes written (0 of 5).")); } [Theory] @@ -944,8 +949,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [InlineData(true)] public async Task WhenAppSetsContentLengthToZeroAndDoesNotWriteNoErrorIsThrown(bool flushResponse) { - var testLogger = new TestApplicationErrorLogger(); - var serviceContext = new TestServiceContext { Log = new TestKestrelTrace(testLogger) }; + var serviceContext = new TestServiceContext(LoggerFactory); using (var server = new TestServer(async httpContext => { @@ -973,7 +977,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } } - Assert.Equal(0, testLogger.ApplicationErrorsLogged); + Assert.Empty(TestApplicationErrorLogger.Messages.Where(message => message.LogLevel == LogLevel.Error)); } // https://tools.ietf.org/html/rfc7230#section-3.3.3 @@ -983,8 +987,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [Fact] public async Task WhenAppSetsTransferEncodingAndContentLengthWritingLessIsNotAnError() { - var testLogger = new TestApplicationErrorLogger(); - var serviceContext = new TestServiceContext { Log = new TestKestrelTrace(testLogger) }; + var serviceContext = new TestServiceContext(LoggerFactory); using (var server = new TestServer(async httpContext => { @@ -1010,7 +1013,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } } - Assert.Equal(0, testLogger.ApplicationErrorsLogged); + Assert.Empty(TestApplicationErrorLogger.Messages.Where(message => message.LogLevel == LogLevel.Error)); } // https://tools.ietf.org/html/rfc7230#section-3.3.3 @@ -1020,8 +1023,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [Fact] public async Task WhenAppSetsTransferEncodingAndContentLengthWritingMoreIsNotAnError() { - var testLogger = new TestApplicationErrorLogger(); - var serviceContext = new TestServiceContext { Log = new TestKestrelTrace(testLogger) }; + var serviceContext = new TestServiceContext(LoggerFactory); using (var server = new TestServer(async httpContext => { @@ -1047,7 +1049,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } } - Assert.Equal(0, testLogger.ApplicationErrorsLogged); + Assert.Empty(TestApplicationErrorLogger.Messages.Where(message => message.LogLevel == LogLevel.Error)); } [Fact] @@ -1057,7 +1059,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { httpContext.Response.ContentLength = 42; return Task.CompletedTask; - })) + }, new TestServiceContext(LoggerFactory))) { using (var connection = server.CreateConnection()) { @@ -1086,7 +1088,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests httpContext.Response.ContentLength = 12; await httpContext.Response.WriteAsync("hello, world"); await flushed.WaitAsync(); - })) + }, new TestServiceContext(LoggerFactory))) { using (var connection = server.CreateConnection()) { @@ -1111,7 +1113,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests public async Task HeadResponseBodyNotWrittenWithSyncWrite() { var flushed = new SemaphoreSlim(0, 1); - var serviceContext = new TestServiceContext { ServerOptions = { AllowSynchronousIO = true } }; + var serviceContext = new TestServiceContext(LoggerFactory) { ServerOptions = { AllowSynchronousIO = true } }; using (var server = new TestServer(httpContext => { @@ -1151,7 +1153,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests await httpContext.Response.WriteAsync(""); flushed.Wait(); await httpContext.Response.WriteAsync("hello, world"); - })) + }, new TestServiceContext(LoggerFactory))) { using (var connection = server.CreateConnection()) { @@ -1195,7 +1197,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { tcs.TrySetException(ex); } - })) + }, new TestServiceContext(LoggerFactory))) { using (var connection = server.CreateConnection()) { @@ -1236,7 +1238,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests await httpContext.Response.WriteAsync(ex.Message); responseWritten.Release(); } - })) + }, new TestServiceContext(LoggerFactory))) { using (var connection = server.CreateConnection()) { @@ -1266,7 +1268,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { httpContext.Response.Headers["Transfer-Encoding"] = responseTransferEncoding; await httpContext.Response.WriteAsync("hello, world"); - })) + }, new TestServiceContext(LoggerFactory))) { using (var connection = server.CreateConnection()) { @@ -1312,7 +1314,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests httpContext.Response.Headers["Connection"] = "keep-alive"; httpContext.Response.Headers["Transfer-Encoding"] = responseTransferEncoding; await httpContext.Response.WriteAsync("hello, world"); - })) + }, new TestServiceContext(LoggerFactory))) { using (var connection = server.CreateConnection()) { @@ -1359,7 +1361,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests // App would have to chunk manually, but here we don't care await httpContext.Response.WriteAsync("hello, world"); - })) + }, new TestServiceContext(LoggerFactory))) { using (var connection = server.CreateConnection()) { @@ -1394,7 +1396,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [Fact] public async Task FirstWriteVerifiedAfterOnStarting() { - var serviceContext = new TestServiceContext { ServerOptions = { AllowSynchronousIO = true } }; + var serviceContext = new TestServiceContext(LoggerFactory) { ServerOptions = { AllowSynchronousIO = true } }; using (var server = new TestServer(httpContext => { @@ -1437,7 +1439,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [Fact] public async Task SubsequentWriteVerifiedAfterOnStarting() { - var serviceContext = new TestServiceContext { ServerOptions = { AllowSynchronousIO = true } }; + var serviceContext = new TestServiceContext(LoggerFactory) { ServerOptions = { AllowSynchronousIO = true } }; using (var server = new TestServer(httpContext => { @@ -1497,7 +1499,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests // If OnStarting is not run before verifying writes, an error response will be sent. return httpContext.Response.Body.WriteAsync(response, 0, response.Length); - })) + }, new TestServiceContext(LoggerFactory))) { using (var connection = server.CreateConnection()) { @@ -1538,7 +1540,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests // If OnStarting is not run before verifying writes, an error response will be sent. await httpContext.Response.Body.WriteAsync(response, 0, response.Length / 2); await httpContext.Response.Body.WriteAsync(response, response.Length / 2, response.Length - response.Length / 2); - })) + }, new TestServiceContext(LoggerFactory))) { using (var connection = server.CreateConnection()) { @@ -1569,7 +1571,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests using (var server = new TestServer(async httpContext => { await httpContext.Response.WriteAsync("hello, world"); - })) + }, new TestServiceContext(LoggerFactory))) { using (var connection = server.CreateConnection()) { @@ -1603,11 +1605,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [Fact] public async Task WhenResponseNotStartedResponseEndedBeforeConsumingRequestBody() { - var sink = new TestSink(); - var logger = new TestLogger("TestLogger", sink, enabled: true); - using (var server = new TestServer(httpContext => Task.CompletedTask, - new TestServiceContext() { Log = new KestrelTrace(logger) })) + new TestServiceContext(LoggerFactory))) { using (var connection = server.CreateConnection()) { @@ -1630,20 +1629,17 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } } - Assert.Contains(sink.Writes, w => w.EventId.Id == 17 && w.LogLevel == LogLevel.Information && w.Exception is BadHttpRequestException + Assert.Contains(TestApplicationErrorLogger.Messages, w => w.EventId.Id == 17 && w.LogLevel == LogLevel.Information && w.Exception is BadHttpRequestException && ((BadHttpRequestException)w.Exception).StatusCode == StatusCodes.Status400BadRequest); } [Fact] public async Task Sending100ContinueDoesNotStartResponse() { - var sink = new TestSink(); - var logger = new TestLogger("TestLogger", sink, enabled: true); - using (var server = new TestServer(httpContext => { return httpContext.Request.Body.ReadAsync(new byte[1], 0, 1); - }, new TestServiceContext() { Log = new KestrelTrace(logger) })) + }, new TestServiceContext(LoggerFactory))) { using (var connection = server.CreateConnection()) { @@ -1685,7 +1681,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } } - Assert.Contains(sink.Writes, w => w.EventId.Id == 17 && w.LogLevel == LogLevel.Information && w.Exception is BadHttpRequestException + Assert.Contains(TestApplicationErrorLogger.Messages, w => w.EventId.Id == 17 && w.LogLevel == LogLevel.Information && w.Exception is BadHttpRequestException && ((BadHttpRequestException)w.Exception).StatusCode == StatusCodes.Status400BadRequest); } @@ -1696,7 +1692,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { await httpContext.Request.Body.ReadAsync(new byte[1], 0, 1); await httpContext.Response.WriteAsync("hello, world"); - })) + }, new TestServiceContext(LoggerFactory))) { using (var connection = server.CreateConnection()) { @@ -1740,7 +1736,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [MemberData(nameof(ConnectionAdapterData))] public async Task Http11ResponseSentToHttp10Request(ListenOptions listenOptions) { - var serviceContext = new TestServiceContext(); + var serviceContext = new TestServiceContext(LoggerFactory); using (var server = new TestServer(TestApp.EchoApp, serviceContext, listenOptions)) { @@ -1765,7 +1761,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [MemberData(nameof(ConnectionAdapterData))] public async Task ZeroContentLengthSetAutomaticallyAfterNoWrites(ListenOptions listenOptions) { - var testContext = new TestServiceContext(); + var testContext= new TestServiceContext(LoggerFactory); using (var server = new TestServer(TestApp.EmptyApp, testContext, listenOptions)) { @@ -1798,7 +1794,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [MemberData(nameof(ConnectionAdapterData))] public async Task ZeroContentLengthSetAutomaticallyForNonKeepAliveRequests(ListenOptions listenOptions) { - var testContext = new TestServiceContext(); + var testContext= new TestServiceContext(LoggerFactory); using (var server = new TestServer(async httpContext => { @@ -1843,7 +1839,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [MemberData(nameof(ConnectionAdapterData))] public async Task ZeroContentLengthNotSetAutomaticallyForHeadRequests(ListenOptions listenOptions) { - var testContext = new TestServiceContext(); + var testContext= new TestServiceContext(LoggerFactory); using (var server = new TestServer(TestApp.EmptyApp, testContext, listenOptions)) { @@ -1867,7 +1863,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [MemberData(nameof(ConnectionAdapterData))] public async Task ZeroContentLengthNotSetAutomaticallyForCertainStatusCodes(ListenOptions listenOptions) { - var testContext = new TestServiceContext(); + var testContext= new TestServiceContext(LoggerFactory); using (var server = new TestServer(async httpContext => { @@ -1924,7 +1920,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [MemberData(nameof(ConnectionAdapterData))] public async Task ConnectionClosedAfter101Response(ListenOptions listenOptions) { - var testContext = new TestServiceContext(); + var testContext= new TestServiceContext(LoggerFactory); using (var server = new TestServer(async httpContext => { @@ -1971,13 +1967,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [MemberData(nameof(ConnectionAdapterData))] public async Task ThrowingResultsIn500Response(ListenOptions listenOptions) { - var testContext = new TestServiceContext(); + var testContext= new TestServiceContext(LoggerFactory); bool onStartingCalled = false; - var testLogger = new TestApplicationErrorLogger(); - testContext.Log = new KestrelTrace(testLogger); - using (var server = new TestServer(httpContext => { var response = httpContext.Response; @@ -2018,7 +2011,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } Assert.False(onStartingCalled); - Assert.Equal(2, testLogger.ApplicationErrorsLogged); + Assert.Equal(2, TestApplicationErrorLogger.Messages.Where(message => message.LogLevel == LogLevel.Error).Count()); } [Theory] @@ -2028,9 +2021,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests var callback1Called = false; var callback2CallCount = 0; - var testContext = new TestServiceContext(); - var testLogger = new TestApplicationErrorLogger(); - testContext.Log = new KestrelTrace(testLogger); + var testContext= new TestServiceContext(LoggerFactory); using (var server = new TestServer(async httpContext => { @@ -2079,21 +2070,18 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests // since they are called LIFO order and the other one failed. Assert.False(callback1Called); Assert.Equal(2, callback2CallCount); - Assert.Equal(2, testLogger.ApplicationErrorsLogged); + Assert.Equal(2, TestApplicationErrorLogger.Messages.Where(message => message.LogLevel == LogLevel.Error).Count()); } [Theory] [MemberData(nameof(ConnectionAdapterData))] public async Task ThrowingInOnCompletedIsLogged(ListenOptions listenOptions) { - var testContext = new TestServiceContext(); + var testContext= new TestServiceContext(LoggerFactory); var onCompletedCalled1 = false; var onCompletedCalled2 = false; - var testLogger = new TestApplicationErrorLogger(); - testContext.Log = new KestrelTrace(testLogger); - using (var server = new TestServer(async httpContext => { var response = httpContext.Response; @@ -2130,7 +2118,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } // All OnCompleted callbacks should be called even if they throw. - Assert.Equal(2, testLogger.ApplicationErrorsLogged); + Assert.Equal(2, TestApplicationErrorLogger.Messages.Where(message => message.LogLevel == LogLevel.Error).Count()); Assert.True(onCompletedCalled1); Assert.True(onCompletedCalled2); } @@ -2139,13 +2127,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [MemberData(nameof(ConnectionAdapterData))] public async Task ThrowingAfterWritingKillsConnection(ListenOptions listenOptions) { - var testContext = new TestServiceContext(); + var testContext= new TestServiceContext(LoggerFactory); bool onStartingCalled = false; - var testLogger = new TestApplicationErrorLogger(); - testContext.Log = new KestrelTrace(testLogger); - using (var server = new TestServer(async httpContext => { var response = httpContext.Response; @@ -2177,20 +2162,17 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } Assert.True(onStartingCalled); - Assert.Equal(1, testLogger.ApplicationErrorsLogged); + Assert.Single(TestApplicationErrorLogger.Messages, message => message.LogLevel == LogLevel.Error); } [Theory] [MemberData(nameof(ConnectionAdapterData))] public async Task ThrowingAfterPartialWriteKillsConnection(ListenOptions listenOptions) { - var testContext = new TestServiceContext(); + var testContext= new TestServiceContext(LoggerFactory); bool onStartingCalled = false; - var testLogger = new TestApplicationErrorLogger(); - testContext.Log = new KestrelTrace(testLogger); - using (var server = new TestServer(async httpContext => { var response = httpContext.Response; @@ -2222,7 +2204,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } Assert.True(onStartingCalled); - Assert.Equal(1, testLogger.ApplicationErrorsLogged); + Assert.Single(TestApplicationErrorLogger.Messages, message => message.LogLevel == LogLevel.Error); } [Theory] @@ -2261,7 +2243,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } writeTcs.SetException(new Exception("This shouldn't be reached.")); - }, new TestServiceContext(), listenOptions)) + }, new TestServiceContext(LoggerFactory), listenOptions)) { using (var connection = server.CreateConnection()) { @@ -2288,10 +2270,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [MemberData(nameof(ConnectionAdapterData))] public async Task NoErrorsLoggedWhenServerEndsConnectionBeforeClient(ListenOptions listenOptions) { - var testContext = new TestServiceContext(); - - var testLogger = new TestApplicationErrorLogger(); - testContext.Log = new KestrelTrace(testLogger); + var testContext= new TestServiceContext(LoggerFactory); using (var server = new TestServer(async httpContext => { @@ -2316,14 +2295,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } } - Assert.Equal(0, testLogger.TotalErrorsLogged); + Assert.Empty(TestApplicationErrorLogger.Messages.Where(message => message.LogLevel == LogLevel.Error)); } [Theory] [MemberData(nameof(ConnectionAdapterData))] public async Task NoResponseSentWhenConnectionIsClosedByServerBeforeClientFinishesSendingRequest(ListenOptions listenOptions) { - var testContext = new TestServiceContext(); + var testContext= new TestServiceContext(LoggerFactory); using (var server = new TestServer(httpContext => { @@ -2347,7 +2326,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [MemberData(nameof(ConnectionAdapterData))] public async Task ResponseHeadersAreResetOnEachRequest(ListenOptions listenOptions) { - var testContext = new TestServiceContext(); + var testContext= new TestServiceContext(LoggerFactory); IHeaderDictionary originalResponseHeaders = null; var firstRequest = true; @@ -2400,7 +2379,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { const string response = "hello, world"; - var testContext = new TestServiceContext(); + var testContext= new TestServiceContext(LoggerFactory); var callOrder = new Stack(); var onStartingTcs = new TaskCompletionSource(); @@ -2452,7 +2431,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { const string response = "hello, world"; - var testContext = new TestServiceContext(); + var testContext= new TestServiceContext(LoggerFactory); var callOrder = new Stack(); var onCompletedTcs = new TaskCompletionSource(); @@ -2526,7 +2505,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests await context.Response.Body.WriteAsync(Encoding.ASCII.GetBytes("Hello2"), 0, 6); } - })) + }, new TestServiceContext(LoggerFactory))) { using (var connection = server.CreateConnection()) { @@ -2552,7 +2531,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [Fact] public async Task SynchronousWritesCanBeDisallowedGlobally() { - var testContext = new TestServiceContext + var testContext = new TestServiceContext(LoggerFactory) { ServerOptions = { AllowSynchronousIO = false } }; @@ -2698,9 +2677,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests .Setup(trace => trace.ResponseMininumDataRateNotSatisfied(It.IsAny(), It.IsAny())) .Callback(() => messageLogged.Set()); - var testContext = new TestServiceContext + var testContext = new TestServiceContext(LoggerFactory, mockKestrelTrace.Object) { - Log = mockKestrelTrace.Object, SystemClock = new SystemClock(), ServerOptions = { @@ -2768,7 +2746,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests response.ContentLength = 42; return Task.CompletedTask; - })) + }, new TestServiceContext(LoggerFactory))) { using (var connection = server.CreateConnection()) { diff --git a/test/Kestrel.FunctionalTests/TestHelpers/TestApplicationErrorLoggerLoggedTest.cs b/test/Kestrel.FunctionalTests/TestHelpers/TestApplicationErrorLoggerLoggedTest.cs new file mode 100644 index 0000000000..1dea888411 --- /dev/null +++ b/test/Kestrel.FunctionalTests/TestHelpers/TestApplicationErrorLoggerLoggedTest.cs @@ -0,0 +1,18 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using Microsoft.Extensions.Logging.Testing; + +namespace Microsoft.AspNetCore.Testing +{ + public class TestApplicationErrorLoggerLoggedTest : LoggedTest + { + public TestApplicationErrorLogger TestApplicationErrorLogger { get; private set; } + + public override void AdditionalSetup() + { + TestApplicationErrorLogger = new TestApplicationErrorLogger(); + LoggerFactory.AddProvider(new KestrelTestLoggerProvider(TestApplicationErrorLogger)); + } + } +} diff --git a/test/Kestrel.FunctionalTests/TestHelpers/TestServer.cs b/test/Kestrel.FunctionalTests/TestHelpers/TestServer.cs index 7cf3399dd5..7a54c418fa 100644 --- a/test/Kestrel.FunctionalTests/TestHelpers/TestServer.cs +++ b/test/Kestrel.FunctionalTests/TestHelpers/TestServer.cs @@ -16,7 +16,6 @@ using Microsoft.AspNetCore.Server.Kestrel.Core.Internal; using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; using Microsoft.AspNetCore.Testing; using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.DependencyInjection.Extensions; using Microsoft.Extensions.Options; namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests diff --git a/test/Kestrel.FunctionalTests/UpgradeTests.cs b/test/Kestrel.FunctionalTests/UpgradeTests.cs index 8b37add35f..5d89707335 100644 --- a/test/Kestrel.FunctionalTests/UpgradeTests.cs +++ b/test/Kestrel.FunctionalTests/UpgradeTests.cs @@ -9,20 +9,13 @@ using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Tests; using Microsoft.AspNetCore.Testing; +using Microsoft.Extensions.Logging.Testing; using Xunit; -using Xunit.Abstractions; namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { - public class UpgradeTests + public class UpgradeTests : LoggedTest { - private readonly ITestOutputHelper _output; - - public UpgradeTests(ITestOutputHelper output) - { - _output = output; - } - [Fact] public async Task ResponseThrowsAfterUpgrade() { @@ -42,7 +35,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } upgrade.TrySetResult(true); - })) + }, new TestServiceContext(LoggerFactory))) { using (var connection = server.CreateConnection()) { @@ -93,7 +86,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests upgrade.SetException(ex); throw; } - })) + }, new TestServiceContext(LoggerFactory))) { using (var connection = server.CreateConnection()) { @@ -136,7 +129,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { await Task.Delay(100); } - })) + }, new TestServiceContext(LoggerFactory))) using (var connection = server.CreateConnection()) { await connection.SendEmptyGetWithUpgrade(); @@ -155,7 +148,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [Fact] public async Task RejectsRequestWithContentLengthAndUpgrade() { - using (var server = new TestServer(context => Task.CompletedTask)) + using (var server = new TestServer(context => Task.CompletedTask, new TestServiceContext(LoggerFactory))) using (var connection = server.CreateConnection()) { await connection.Send("POST / HTTP/1.1", @@ -178,7 +171,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [Fact] public async Task AcceptsRequestWithNoContentLengthAndUpgrade() { - using (var server = new TestServer(context => Task.CompletedTask)) + using (var server = new TestServer(context => Task.CompletedTask, new TestServiceContext(LoggerFactory))) { using (var connection = server.CreateConnection()) { @@ -202,7 +195,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [Fact] public async Task RejectsRequestWithChunkedEncodingAndUpgrade() { - using (var server = new TestServer(context => Task.CompletedTask)) + using (var server = new TestServer(context => Task.CompletedTask, new TestServiceContext(LoggerFactory))) using (var connection = server.CreateConnection()) { await connection.Send("POST / HTTP/1.1", @@ -226,7 +219,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { var upgradeTcs = new TaskCompletionSource(); using (var server = new TestServer(async context => - { + { var feature = context.Features.Get(); Assert.False(feature.IsUpgradableRequest); try @@ -241,7 +234,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { upgradeTcs.TrySetResult(false); } - })) + }, new TestServiceContext(LoggerFactory))) { using (var connection = server.CreateConnection()) { @@ -259,7 +252,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { const int limit = 10; var upgradeTcs = new TaskCompletionSource(); - var serviceContext = new TestServiceContext(); + var serviceContext = new TestServiceContext(LoggerFactory); serviceContext.ConnectionManager = new HttpConnectionManager(serviceContext.Log, ResourceCounter.Quota(limit)); using (var server = new TestServer(async context => diff --git a/test/Kestrel.Transport.Libuv.FunctionalTests/Kestrel.Transport.Libuv.FunctionalTests.csproj b/test/Kestrel.Transport.Libuv.FunctionalTests/Kestrel.Transport.Libuv.FunctionalTests.csproj index 46b9aff122..4e48a8d666 100644 --- a/test/Kestrel.Transport.Libuv.FunctionalTests/Kestrel.Transport.Libuv.FunctionalTests.csproj +++ b/test/Kestrel.Transport.Libuv.FunctionalTests/Kestrel.Transport.Libuv.FunctionalTests.csproj @@ -1,8 +1,8 @@  - Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.FunctionalTests - Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.FunctionalTests + Libuv.FunctionalTests + Libuv.FunctionalTests $(StandardTestTfms) $(DefineConstants);MACOS true diff --git a/test/Kestrel.Transport.Libuv.FunctionalTests/ListenHandleTests.cs b/test/Kestrel.Transport.Libuv.FunctionalTests/ListenHandleTests.cs index 71278e954c..61a24966d0 100644 --- a/test/Kestrel.Transport.Libuv.FunctionalTests/ListenHandleTests.cs +++ b/test/Kestrel.Transport.Libuv.FunctionalTests/ListenHandleTests.cs @@ -7,11 +7,12 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.AspNetCore.Testing; using Microsoft.AspNetCore.Testing.xunit; +using Microsoft.Extensions.Logging.Testing; namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { [OSSkipCondition(OperatingSystems.Windows, SkipReason = "Listening to open TCP socket and/or pipe handles is not supported on Windows.")] - public class ListenHandleTests + public class ListenHandleTests : LoggedTest { [ConditionalFact] public async Task CanListenToOpenTcpSocketHandle() @@ -20,7 +21,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { listenSocket.Bind(new IPEndPoint(IPAddress.Loopback, 0)); - using (var server = new TestServer(_ => Task.CompletedTask, new TestServiceContext(), new ListenOptions((ulong)listenSocket.Handle))) + using (var server = new TestServer(_ => Task.CompletedTask, new TestServiceContext(LoggerFactory), new ListenOptions((ulong)listenSocket.Handle))) { using (var connection = new TestConnection(((IPEndPoint)listenSocket.LocalEndPoint).Port)) { diff --git a/test/Kestrel.Transport.Sockets.FunctionalTests/Kestrel.Transport.Sockets.FunctionalTests.csproj b/test/Kestrel.Transport.Sockets.FunctionalTests/Kestrel.Transport.Sockets.FunctionalTests.csproj index 901c8ca106..ca79f38600 100644 --- a/test/Kestrel.Transport.Sockets.FunctionalTests/Kestrel.Transport.Sockets.FunctionalTests.csproj +++ b/test/Kestrel.Transport.Sockets.FunctionalTests/Kestrel.Transport.Sockets.FunctionalTests.csproj @@ -1,8 +1,8 @@  - Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.FunctionalTests - Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.FunctionalTests + Sockets.FunctionalTests + Sockets.FunctionalTests $(StandardTestTfms) $(DefineConstants);MACOS $(DefineConstants);SOCKETS diff --git a/test/shared/TestApplicationErrorLogger.cs b/test/shared/TestApplicationErrorLogger.cs index 91a61f08f7..f447a32b38 100644 --- a/test/shared/TestApplicationErrorLogger.cs +++ b/test/shared/TestApplicationErrorLogger.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Concurrent; +using System.Collections.Generic; using System.Linq; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; @@ -15,6 +16,8 @@ namespace Microsoft.AspNetCore.Testing // Application errors are logged using 13 as the eventId. private const int ApplicationErrorEventId = 13; + public List IgnoredExceptions { get; } = new List(); + public bool ThrowOnCriticalErrors { get; set; } = true; public ConcurrentQueue Messages { get; } = new ConcurrentQueue(); @@ -49,7 +52,7 @@ namespace Microsoft.AspNetCore.Testing Console.WriteLine(log); - if (logLevel == LogLevel.Critical && ThrowOnCriticalErrors) + if (logLevel == LogLevel.Critical && ThrowOnCriticalErrors && !IgnoredExceptions.Contains(exception.GetType())) { throw new Exception($"Unexpected critical error. {log}", exception); } From e30a02cee5ff4919a3be82bf53bab6bb5146e7de Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Sat, 14 Apr 2018 02:21:50 +0100 Subject: [PATCH 1623/1662] Less StringValue struct copies for header checks (#2488) --- .../Internal/Http/Http1Connection.cs | 39 ++++--- .../Internal/Http/Http1MessageBody.cs | 11 +- .../Internal/Http/HttpHeaders.Generated.cs | 11 ++ src/Kestrel.Core/Internal/Http/HttpHeaders.cs | 11 +- .../Internal/Http/HttpProtocol.cs | 4 +- .../Internal/Http/HttpResponseHeaders.cs | 8 -- .../Internal/Http2/Http2Stream.cs | 5 +- .../Internal/Infrastructure/HttpUtilities.cs | 100 ++++++++++-------- test/Kestrel.Core.Tests/HttpUtilitiesTest.cs | 5 +- tools/CodeGenerator/KnownHeaders.cs | 27 ++++- 10 files changed, 137 insertions(+), 84 deletions(-) diff --git a/src/Kestrel.Core/Internal/Http/Http1Connection.cs b/src/Kestrel.Core/Internal/Http/Http1Connection.cs index c6215fb1a4..6fd58d08b0 100644 --- a/src/Kestrel.Core/Internal/Http/Http1Connection.cs +++ b/src/Kestrel.Core/Internal/Http/Http1Connection.cs @@ -360,9 +360,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http // request message that contains more than one Host header field or a // Host header field with an invalid field-value. - var host = HttpRequestHeaders.HeaderHost; - var hostText = host.ToString(); - if (host.Count <= 0) + var hostCount = HttpRequestHeaders.HostCount; + var hostText = HttpRequestHeaders.HeaderHost.ToString(); + if (hostCount <= 0) { if (_httpVersion == Http.HttpVersion.Http10) { @@ -370,13 +370,27 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http } BadHttpRequestException.Throw(RequestRejectionReason.MissingHostHeader); } - else if (host.Count > 1) + else if (hostCount > 1) { BadHttpRequestException.Throw(RequestRejectionReason.MultipleHostHeaders); } - else if (_requestTargetForm == HttpRequestTarget.AuthorityForm) + else if (_requestTargetForm != HttpRequestTarget.OriginForm) { - if (!host.Equals(RawTarget)) + // Tail call + ValidateNonOrginHostHeader(hostText); + } + else + { + // Tail call + HttpUtilities.ValidateHostHeader(hostText); + } + } + + private void ValidateNonOrginHostHeader(string hostText) + { + if (_requestTargetForm == HttpRequestTarget.AuthorityForm) + { + if (hostText != RawTarget) { BadHttpRequestException.Throw(RequestRejectionReason.InvalidHostHeader, hostText); } @@ -390,20 +404,18 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http // System.Uri doesn't not tell us if the port was in the original string or not. // When IsDefaultPort = true, we will allow Host: with or without the default port - if (host != _absoluteRequestTarget.Authority) + if (hostText != _absoluteRequestTarget.Authority) { if (!_absoluteRequestTarget.IsDefaultPort - || host != _absoluteRequestTarget.Authority + ":" + _absoluteRequestTarget.Port.ToString(CultureInfo.InvariantCulture)) + || hostText != _absoluteRequestTarget.Authority + ":" + _absoluteRequestTarget.Port.ToString(CultureInfo.InvariantCulture)) { BadHttpRequestException.Throw(RequestRejectionReason.InvalidHostHeader, hostText); } } } - if (!HttpUtilities.IsValidHostHeader(hostText)) - { - BadHttpRequestException.Throw(RequestRejectionReason.InvalidHostHeader, hostText); - } + // Tail call + HttpUtilities.ValidateHostHeader(hostText); } protected override void OnReset() @@ -454,8 +466,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { if (_requestProcessingStatus == RequestProcessingStatus.ParsingHeaders) { - BadHttpRequestException.Throw(RequestRejectionReason - .MalformedRequestInvalidHeaders); + BadHttpRequestException.Throw(RequestRejectionReason.MalformedRequestInvalidHeaders); } throw; } diff --git a/src/Kestrel.Core/Internal/Http/Http1MessageBody.cs b/src/Kestrel.Core/Internal/Http/Http1MessageBody.cs index 6f82e27dd0..90c05f53ee 100644 --- a/src/Kestrel.Core/Internal/Http/Http1MessageBody.cs +++ b/src/Kestrel.Core/Internal/Http/Http1MessageBody.cs @@ -213,11 +213,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http // see also http://tools.ietf.org/html/rfc2616#section-4.4 var keepAlive = httpVersion != HttpVersion.Http10; - var connection = headers.HeaderConnection; var upgrade = false; - if (connection.Count > 0) + if (headers.HasConnection) { - var connectionOptions = HttpHeaders.ParseConnection(connection); + var connectionOptions = HttpHeaders.ParseConnection(headers.HeaderConnection); upgrade = (connectionOptions & ConnectionOptions.Upgrade) == ConnectionOptions.Upgrade; keepAlive = (connectionOptions & ConnectionOptions.KeepAlive) == ConnectionOptions.KeepAlive; @@ -233,10 +232,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http return new ForUpgrade(context); } - var transferEncoding = headers.HeaderTransferEncoding; - if (transferEncoding.Count > 0) + if (headers.HasTransferEncoding) { - var transferCoding = HttpHeaders.GetFinalTransferCoding(headers.HeaderTransferEncoding); + var transferEncoding = headers.HeaderTransferEncoding; + var transferCoding = HttpHeaders.GetFinalTransferCoding(transferEncoding); // https://tools.ietf.org/html/rfc7230#section-3.3.3 // If a Transfer-Encoding header field diff --git a/src/Kestrel.Core/Internal/Http/HttpHeaders.Generated.cs b/src/Kestrel.Core/Internal/Http/HttpHeaders.Generated.cs index 27473181b7..d84f15706d 100644 --- a/src/Kestrel.Core/Internal/Http/HttpHeaders.Generated.cs +++ b/src/Kestrel.Core/Internal/Http/HttpHeaders.Generated.cs @@ -17,6 +17,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http private long _bits = 0; private HeaderReferences _headers; + + public bool HasConnection => (_bits & 2L) != 0; + public bool HasTransferEncoding => (_bits & 64L) != 0; + + public int HostCount => _headers._Host.Count; public StringValues HeaderCacheControl { @@ -4794,6 +4799,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http private long _bits = 0; private HeaderReferences _headers; + + public bool HasConnection => (_bits & 2L) != 0; + public bool HasDate => (_bits & 4L) != 0; + public bool HasTransferEncoding => (_bits & 64L) != 0; + public bool HasServer => (_bits & 33554432L) != 0; + public StringValues HeaderCacheControl { diff --git a/src/Kestrel.Core/Internal/Http/HttpHeaders.cs b/src/Kestrel.Core/Internal/Http/HttpHeaders.cs index 92061b5d87..444ac62774 100644 --- a/src/Kestrel.Core/Internal/Http/HttpHeaders.cs +++ b/src/Kestrel.Core/Internal/Http/HttpHeaders.cs @@ -45,7 +45,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { ThrowHeadersReadOnlyException(); } - SetValueFast(key, value); + if (value.Count == 0) + { + RemoveFast(key); + } + else + { + SetValueFast(key, value); + } } } @@ -164,7 +171,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http ThrowHeadersReadOnlyException(); } - if (!AddValueFast(key, value)) + if (value.Count > 0 && !AddValueFast(key, value)) { ThrowDuplicateKeyException(); } diff --git a/src/Kestrel.Core/Internal/Http/HttpProtocol.cs b/src/Kestrel.Core/Internal/Http/HttpProtocol.cs index da1416c1a3..93cb96499d 100644 --- a/src/Kestrel.Core/Internal/Http/HttpProtocol.cs +++ b/src/Kestrel.Core/Internal/Http/HttpProtocol.cs @@ -1111,7 +1111,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http var hasConnection = responseHeaders.HasConnection; var connectionOptions = HttpHeaders.ParseConnection(responseHeaders.HeaderConnection); var hasTransferEncoding = responseHeaders.HasTransferEncoding; - var transferCoding = HttpHeaders.GetFinalTransferCoding(responseHeaders.HeaderTransferEncoding); if (_keepAlive && hasConnection && (connectionOptions & ConnectionOptions.KeepAlive) != ConnectionOptions.KeepAlive) { @@ -1123,7 +1122,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http // chunked is applied to a response payload body, the sender MUST either // apply chunked as the final transfer coding or terminate the message // by closing the connection. - if (hasTransferEncoding && transferCoding != TransferCoding.Chunked) + if (hasTransferEncoding && + HttpHeaders.GetFinalTransferCoding(responseHeaders.HeaderTransferEncoding) != TransferCoding.Chunked) { _keepAlive = false; } diff --git a/src/Kestrel.Core/Internal/Http/HttpResponseHeaders.cs b/src/Kestrel.Core/Internal/Http/HttpResponseHeaders.cs index f559102c6a..1df80f3dc6 100644 --- a/src/Kestrel.Core/Internal/Http/HttpResponseHeaders.cs +++ b/src/Kestrel.Core/Internal/Http/HttpResponseHeaders.cs @@ -17,14 +17,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http private static readonly byte[] _CrLf = new[] { (byte)'\r', (byte)'\n' }; private static readonly byte[] _colonSpace = new[] { (byte)':', (byte)' ' }; - public bool HasConnection => HeaderConnection.Count != 0; - - public bool HasTransferEncoding => HeaderTransferEncoding.Count != 0; - - public bool HasServer => HeaderServer.Count != 0; - - public bool HasDate => HeaderDate.Count != 0; - public Enumerator GetEnumerator() { return new Enumerator(this); diff --git a/src/Kestrel.Core/Internal/Http2/Http2Stream.cs b/src/Kestrel.Core/Internal/Http2/Http2Stream.cs index fd73b5ac98..b1f754884a 100644 --- a/src/Kestrel.Core/Internal/Http2/Http2Stream.cs +++ b/src/Kestrel.Core/Internal/Http2/Http2Stream.cs @@ -110,10 +110,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 } var hostText = host.ToString(); - if (!HttpUtilities.IsValidHostHeader(hostText)) - { - BadHttpRequestException.Throw(RequestRejectionReason.InvalidHostHeader, hostText); - } + HttpUtilities.ValidateHostHeader(hostText); endConnection = false; return true; diff --git a/src/Kestrel.Core/Internal/Infrastructure/HttpUtilities.cs b/src/Kestrel.Core/Internal/Infrastructure/HttpUtilities.cs index bfc3baa89b..0af41644ff 100644 --- a/src/Kestrel.Core/Internal/Infrastructure/HttpUtilities.cs +++ b/src/Kestrel.Core/Internal/Infrastructure/HttpUtilities.cs @@ -426,45 +426,44 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure } } - public static bool IsValidHostHeader(string hostText) + public static void ValidateHostHeader(string hostText) { - // The spec allows empty values if (string.IsNullOrEmpty(hostText)) { - return true; + // The spec allows empty values + return; } - if (hostText[0] == '[') + var firstChar = hostText[0]; + if (firstChar == '[') { - return IsValidIPv6Host(hostText); + // Tail call + ValidateIPv6Host(hostText); } - - if (hostText[0] == ':') + else { - // Only a port - return false; - } - - var i = 0; - for (; i < hostText.Length; i++) - { - if (!IsValidHostChar(hostText[i])) + if (firstChar == ':') { - break; + // Only a port + BadHttpRequestException.Throw(RequestRejectionReason.InvalidHostHeader, hostText); + } + + // Enregister array + var hostCharValidity = HostCharValidity; + for (var i = 0; i < hostText.Length; i++) + { + if (!hostCharValidity[hostText[i]]) + { + // Tail call + ValidateHostPort(hostText, i); + return; + } } } - return IsValidHostPort(hostText, i); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - private static bool IsValidHostChar(char ch) - { - return ch < HostCharValidity.Length && HostCharValidity[ch]; } // The lead '[' was already checked - [MethodImpl(MethodImplOptions.AggressiveInlining)] - private static bool IsValidIPv6Host(string hostText) + private static void ValidateIPv6Host(string hostText) { for (var i = 1; i < hostText.Length; i++) { @@ -474,58 +473,69 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure // [::1] is the shortest valid IPv6 host if (i < 4) { - return false; + BadHttpRequestException.Throw(RequestRejectionReason.InvalidHostHeader, hostText); } - return IsValidHostPort(hostText, i + 1); + else if (i + 1 < hostText.Length) + { + // Tail call + ValidateHostPort(hostText, i + 1); + } + return; } if (!IsHex(ch) && ch != ':' && ch != '.') { - return false; + BadHttpRequestException.Throw(RequestRejectionReason.InvalidHostHeader, hostText); } } // Must contain a ']' - return false; + BadHttpRequestException.Throw(RequestRejectionReason.InvalidHostHeader, hostText); } - [MethodImpl(MethodImplOptions.AggressiveInlining)] - private static bool IsValidHostPort(string hostText, int offset) + private static void ValidateHostPort(string hostText, int offset) { - if (offset == hostText.Length) - { - return true; - } - - if (hostText[offset] != ':' || hostText.Length == offset + 1) + var firstChar = hostText[offset]; + offset++; + if (firstChar != ':' || offset == hostText.Length) { // Must have at least one number after the colon if present. - return false; + BadHttpRequestException.Throw(RequestRejectionReason.InvalidHostHeader, hostText); } - for (var i = offset + 1; i < hostText.Length; i++) + for (var i = offset; i < hostText.Length; i++) { if (!IsNumeric(hostText[i])) { - return false; + BadHttpRequestException.Throw(RequestRejectionReason.InvalidHostHeader, hostText); } } - - return true; } [MethodImpl(MethodImplOptions.AggressiveInlining)] private static bool IsNumeric(char ch) { - return '0' <= ch && ch <= '9'; + // '0' <= ch && ch <= '9' + // (uint)(ch - '0') <= (uint)('9' - '0') + + // Subtract start of range '0' + // Cast to uint to change negative numbers to large numbers + // Check if less than 10 representing chars '0' - '9' + return (uint)(ch - '0') < 10u; } [MethodImpl(MethodImplOptions.AggressiveInlining)] private static bool IsHex(char ch) { return IsNumeric(ch) - || ('a' <= ch && ch <= 'f') - || ('A' <= ch && ch <= 'F'); + // || ('a' <= ch && ch <= 'f') + // || ('A' <= ch && ch <= 'F'); + + // Lowercase indiscriminately (or with 32) + // Subtract start of range 'a' + // Cast to uint to change negative numbers to large numbers + // Check if less than 6 representing chars 'a' - 'f' + || (uint)((ch | 32) - 'a') < 6u; } } } diff --git a/test/Kestrel.Core.Tests/HttpUtilitiesTest.cs b/test/Kestrel.Core.Tests/HttpUtilitiesTest.cs index d2c1233cee..b503eab04e 100644 --- a/test/Kestrel.Core.Tests/HttpUtilitiesTest.cs +++ b/test/Kestrel.Core.Tests/HttpUtilitiesTest.cs @@ -170,7 +170,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests [MemberData(nameof(HostHeaderData))] public void ValidHostHeadersParsed(string host) { - Assert.True(HttpUtilities.IsValidHostHeader(host)); + HttpUtilities.ValidateHostHeader(host); + // Shouldn't throw } public static TheoryData HostHeaderInvalidData @@ -224,7 +225,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests [MemberData(nameof(HostHeaderInvalidData))] public void InvalidHostHeadersRejected(string host) { - Assert.False(HttpUtilities.IsValidHostHeader(host)); + Assert.Throws(() => HttpUtilities.ValidateHostHeader(host)); } } } \ No newline at end of file diff --git a/tools/CodeGenerator/KnownHeaders.cs b/tools/CodeGenerator/KnownHeaders.cs index 6aa1654681..08646dc61a 100644 --- a/tools/CodeGenerator/KnownHeaders.cs +++ b/tools/CodeGenerator/KnownHeaders.cs @@ -68,6 +68,8 @@ namespace CodeGenerator public byte[] Bytes => Encoding.ASCII.GetBytes($"\r\n{Name}: "); public int BytesOffset { get; set; } public int BytesCount { get; set; } + public bool ExistenceCheck { get; set; } + public bool FastCount { get; set; } public bool EnhancedSetter { get; set; } public bool PrimaryHeader { get; set; } public string TestBit() => $"(_bits & {1L << Index}L) != 0"; @@ -168,6 +170,15 @@ namespace CodeGenerator "Access-Control-Request-Method", "Access-Control-Request-Headers", }; + var requestHeadersExistence = new[] + { + "Connection", + "Transfer-Encoding", + }; + var requestHeadersCount = new[] + { + "Host" + }; var requestHeaders = commonHeaders.Concat(new[] { "Accept", @@ -197,7 +208,9 @@ namespace CodeGenerator { Name = header, Index = index, - PrimaryHeader = requestPrimaryHeaders.Contains(header) + PrimaryHeader = requestPrimaryHeaders.Contains(header), + ExistenceCheck = requestHeadersExistence.Contains(header), + FastCount = requestHeadersCount.Contains(header) }) .Concat(new[] { new KnownHeader { @@ -209,6 +222,13 @@ namespace CodeGenerator Debug.Assert(requestHeaders.Length <= 64); Debug.Assert(requestHeaders.Max(x => x.Index) <= 62); + var responseHeadersExistence = new[] + { + "Connection", + "Server", + "Date", + "Transfer-Encoding" + }; var enhancedHeaders = new[] { "Connection", @@ -245,6 +265,7 @@ namespace CodeGenerator Name = header, Index = index, EnhancedSetter = enhancedHeaders.Contains(header), + ExistenceCheck = responseHeadersExistence.Contains(header), PrimaryHeader = responsePrimaryHeaders.Contains(header) }) .Concat(new[] { new KnownHeader @@ -311,6 +332,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http private long _bits = 0; private HeaderReferences _headers; +{Each(loop.Headers.Where(header => header.ExistenceCheck), header => $@" + public bool Has{header.Identifier} => {header.TestBit()};")} +{Each(loop.Headers.Where(header => header.FastCount), header => $@" + public int {header.Identifier}Count => _headers._{header.Identifier}.Count;")} {Each(loop.Headers, header => $@" public StringValues Header{header.Identifier} {{{(header.Identifier == "ContentLength" ? $@" From a9e46b0d59c807aff304f3f847802fa6dd5ca5af Mon Sep 17 00:00:00 2001 From: "ASP.NET CI" Date: Sun, 15 Apr 2018 14:16:38 -0700 Subject: [PATCH 1624/1662] Update dependencies.props [auto-updated: dependencies] --- build/dependencies.props | 64 ++++++++++++++++++++-------------------- korebuild-lock.txt | 4 +-- 2 files changed, 34 insertions(+), 34 deletions(-) diff --git a/build/dependencies.props b/build/dependencies.props index 2a1dc23c3b..f7623e1971 100644 --- a/build/dependencies.props +++ b/build/dependencies.props @@ -5,43 +5,43 @@ 0.10.13 - 2.1.0-preview3-17002 + 2.1.0-preview3-17018 1.10.0 - 2.1.0-preview3-32196 - 2.1.0-preview3-32196 - 2.1.0-preview3-32196 - 2.1.0-a-preview3-file-logger-16960 - 2.1.0-a-preview3-file-logger-16960 - 2.1.0-preview3-32196 - 2.1.0-preview3-32196 - 2.1.0-preview3-32196 - 2.1.0-preview3-32196 - 2.1.0-preview3-32196 - 2.1.0-preview3-32196 - 2.1.0-preview3-32196 - 2.1.0-preview3-32196 - 2.1.0-preview3-32196 - 2.1.0-preview3-32196 - 2.1.0-preview3-32196 - 2.1.0-preview3-32196 - 2.1.0-a-preview3-file-logger-16474 - 2.1.0-a-preview3-file-logger-16474 - 2.1.0-a-preview3-file-logger-16474 - 2.1.0-a-preview3-file-logger-16474 - 2.1.0-preview3-32196 + 2.1.0-preview3-32233 + 2.1.0-preview3-32233 + 2.1.0-preview3-32233 + 2.1.0-preview3-32233 + 2.1.0-preview3-32233 + 2.1.0-preview3-32233 + 2.1.0-preview3-32233 + 2.1.0-preview3-32233 + 2.1.0-preview3-32233 + 2.1.0-preview3-32233 + 2.1.0-preview3-32233 + 2.1.0-preview3-32233 + 2.1.0-preview3-32233 + 2.1.0-preview3-32233 + 2.1.0-preview3-32233 + 2.1.0-preview3-32233 + 2.1.0-preview3-32233 + 2.1.0-preview3-32233 + 2.1.0-preview3-32233 + 2.1.0-preview3-32233 + 2.1.0-preview3-32233 + 2.1.0-preview3-32233 2.0.0 - 2.1.0-preview2-26406-04 - 2.1.0-preview3-32196 + 2.1.0-preview3-26413-05 + 2.1.0-preview3-32233 15.6.1 4.7.49 11.0.2 - 4.5.0-preview2-26406-04 - 4.5.0-preview2-26406-04 - 4.5.0-preview2-26406-04 - 4.5.0-preview2-26406-04 - 4.5.0-preview2-26406-04 - 4.5.0-preview2-26406-04 - 4.5.0-preview2-26406-04 + 4.5.0-preview3-26413-02 + 4.5.0-preview3-26413-02 + 4.5.0-preview3-26413-02 + 4.5.0-preview3-26413-02 + 4.5.0-preview3-26413-02 + 4.5.0-preview3-26413-02 + 4.5.0-preview3-26413-02 1.3.7 0.8.0 2.3.1 diff --git a/korebuild-lock.txt b/korebuild-lock.txt index b3af0b8bce..b419d767b9 100644 --- a/korebuild-lock.txt +++ b/korebuild-lock.txt @@ -1,2 +1,2 @@ -version:2.1.0-preview3-17002 -commithash:b8e4e6ab104adc94c0719bb74229870e9b584a7f +version:2.1.0-preview3-17018 +commithash:af264ca131f212b5ba8aafbc5110fc0fc510a2be From 3a45136cc48744165577bb52048b9ea2f45e5bc3 Mon Sep 17 00:00:00 2001 From: Andrew Stanton-Nurse Date: Mon, 16 Apr 2018 11:34:06 -0700 Subject: [PATCH 1625/1662] make IConnectionInherentKeepAliveFeature a boolean feature (#2496) --- .../Features/IConnectionInherentKeepAliveFeature.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Connections.Abstractions/Features/IConnectionInherentKeepAliveFeature.cs b/src/Connections.Abstractions/Features/IConnectionInherentKeepAliveFeature.cs index 8056dfa957..d5751f8bcf 100644 --- a/src/Connections.Abstractions/Features/IConnectionInherentKeepAliveFeature.cs +++ b/src/Connections.Abstractions/Features/IConnectionInherentKeepAliveFeature.cs @@ -19,6 +19,6 @@ namespace Microsoft.AspNetCore.Connections.Features /// public interface IConnectionInherentKeepAliveFeature { - TimeSpan KeepAliveInterval { get; } + bool HasInherentKeepAlive { get; } } } \ No newline at end of file From 6fd09af3742ea07c63894ec512cafabbca1a5d68 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Mon, 16 Apr 2018 11:53:10 -0700 Subject: [PATCH 1626/1662] Improve logging of request drain timeout (#2480) --- .../Kestrel.Performance/Mocks/MockTrace.cs | 2 + src/Kestrel.Core/BadHttpRequestException.cs | 73 ++++++++++--------- .../Internal/Http/Http1MessageBody.cs | 42 ++++++++++- .../Internal/Http/HttpProtocol.cs | 63 ++++++---------- .../Internal/Http/HttpRequestStream.cs | 5 -- .../Internal/Http/HttpResponseStream.cs | 5 -- .../Internal/Infrastructure/IKestrelTrace.cs | 4 + .../Internal/Infrastructure/KestrelTrace.cs | 16 ++++ .../Internal/Infrastructure/Streams.cs | 7 -- test/Kestrel.Core.Tests/MessageBodyTests.cs | 13 +++- .../RequestBodyTimeoutTests.cs | 4 +- test/Kestrel.FunctionalTests/ResponseTests.cs | 7 +- 12 files changed, 134 insertions(+), 107 deletions(-) diff --git a/benchmarks/Kestrel.Performance/Mocks/MockTrace.cs b/benchmarks/Kestrel.Performance/Mocks/MockTrace.cs index fef2b970f1..a06661cf3a 100644 --- a/benchmarks/Kestrel.Performance/Mocks/MockTrace.cs +++ b/benchmarks/Kestrel.Performance/Mocks/MockTrace.cs @@ -40,6 +40,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance public void ApplicationNeverCompleted(string connectionId) { } public void RequestBodyStart(string connectionId, string traceIdentifier) { } public void RequestBodyDone(string connectionId, string traceIdentifier) { } + public void RequestBodyNotEntirelyRead(string connectionId, string traceIdentifier) { } + public void RequestBodyDrainTimedOut(string connectionId, string traceIdentifier) { } public void RequestBodyMininumDataRateNotSatisfied(string connectionId, string traceIdentifier, double rate) { } public void ResponseMininumDataRateNotSatisfied(string connectionId, string traceIdentifier) { } public void Http2ConnectionError(string connectionId, Http2ConnectionErrorException ex) { } diff --git a/src/Kestrel.Core/BadHttpRequestException.cs b/src/Kestrel.Core/BadHttpRequestException.cs index 0530f53854..033c8d9e1b 100644 --- a/src/Kestrel.Core/BadHttpRequestException.cs +++ b/src/Kestrel.Core/BadHttpRequestException.cs @@ -13,14 +13,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core { public sealed class BadHttpRequestException : IOException { - private BadHttpRequestException(string message, int statusCode) - : this(message, statusCode, null) + private BadHttpRequestException(string message, int statusCode, RequestRejectionReason reason) + : this(message, statusCode, reason, null) { } - private BadHttpRequestException(string message, int statusCode, HttpMethod? requiredMethod) + private BadHttpRequestException(string message, int statusCode, RequestRejectionReason reason, HttpMethod? requiredMethod) : base(message) { StatusCode = statusCode; + Reason = reason; if (requiredMethod.HasValue) { @@ -32,6 +33,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core internal StringValues AllowedHeader { get; } + internal RequestRejectionReason Reason { get; } + [StackTraceHidden] internal static void Throw(RequestRejectionReason reason) { @@ -49,70 +52,70 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core switch (reason) { case RequestRejectionReason.InvalidRequestHeadersNoCRLF: - ex = new BadHttpRequestException(CoreStrings.BadRequest_InvalidRequestHeadersNoCRLF, StatusCodes.Status400BadRequest); + ex = new BadHttpRequestException(CoreStrings.BadRequest_InvalidRequestHeadersNoCRLF, StatusCodes.Status400BadRequest, reason); break; case RequestRejectionReason.InvalidRequestLine: - ex = new BadHttpRequestException(CoreStrings.BadRequest_InvalidRequestLine, StatusCodes.Status400BadRequest); + ex = new BadHttpRequestException(CoreStrings.BadRequest_InvalidRequestLine, StatusCodes.Status400BadRequest, reason); break; case RequestRejectionReason.MalformedRequestInvalidHeaders: - ex = new BadHttpRequestException(CoreStrings.BadRequest_MalformedRequestInvalidHeaders, StatusCodes.Status400BadRequest); + ex = new BadHttpRequestException(CoreStrings.BadRequest_MalformedRequestInvalidHeaders, StatusCodes.Status400BadRequest, reason); break; case RequestRejectionReason.MultipleContentLengths: - ex = new BadHttpRequestException(CoreStrings.BadRequest_MultipleContentLengths, StatusCodes.Status400BadRequest); + ex = new BadHttpRequestException(CoreStrings.BadRequest_MultipleContentLengths, StatusCodes.Status400BadRequest, reason); break; case RequestRejectionReason.UnexpectedEndOfRequestContent: - ex = new BadHttpRequestException(CoreStrings.BadRequest_UnexpectedEndOfRequestContent, StatusCodes.Status400BadRequest); + ex = new BadHttpRequestException(CoreStrings.BadRequest_UnexpectedEndOfRequestContent, StatusCodes.Status400BadRequest, reason); break; case RequestRejectionReason.BadChunkSuffix: - ex = new BadHttpRequestException(CoreStrings.BadRequest_BadChunkSuffix, StatusCodes.Status400BadRequest); + ex = new BadHttpRequestException(CoreStrings.BadRequest_BadChunkSuffix, StatusCodes.Status400BadRequest, reason); break; case RequestRejectionReason.BadChunkSizeData: - ex = new BadHttpRequestException(CoreStrings.BadRequest_BadChunkSizeData, StatusCodes.Status400BadRequest); + ex = new BadHttpRequestException(CoreStrings.BadRequest_BadChunkSizeData, StatusCodes.Status400BadRequest, reason); break; case RequestRejectionReason.ChunkedRequestIncomplete: - ex = new BadHttpRequestException(CoreStrings.BadRequest_ChunkedRequestIncomplete, StatusCodes.Status400BadRequest); + ex = new BadHttpRequestException(CoreStrings.BadRequest_ChunkedRequestIncomplete, StatusCodes.Status400BadRequest, reason); break; case RequestRejectionReason.InvalidCharactersInHeaderName: - ex = new BadHttpRequestException(CoreStrings.BadRequest_InvalidCharactersInHeaderName, StatusCodes.Status400BadRequest); + ex = new BadHttpRequestException(CoreStrings.BadRequest_InvalidCharactersInHeaderName, StatusCodes.Status400BadRequest, reason); break; case RequestRejectionReason.RequestLineTooLong: - ex = new BadHttpRequestException(CoreStrings.BadRequest_RequestLineTooLong, StatusCodes.Status414UriTooLong); + ex = new BadHttpRequestException(CoreStrings.BadRequest_RequestLineTooLong, StatusCodes.Status414UriTooLong, reason); break; case RequestRejectionReason.HeadersExceedMaxTotalSize: - ex = new BadHttpRequestException(CoreStrings.BadRequest_HeadersExceedMaxTotalSize, StatusCodes.Status431RequestHeaderFieldsTooLarge); + ex = new BadHttpRequestException(CoreStrings.BadRequest_HeadersExceedMaxTotalSize, StatusCodes.Status431RequestHeaderFieldsTooLarge, reason); break; case RequestRejectionReason.TooManyHeaders: - ex = new BadHttpRequestException(CoreStrings.BadRequest_TooManyHeaders, StatusCodes.Status431RequestHeaderFieldsTooLarge); + ex = new BadHttpRequestException(CoreStrings.BadRequest_TooManyHeaders, StatusCodes.Status431RequestHeaderFieldsTooLarge, reason); break; case RequestRejectionReason.RequestBodyTooLarge: - ex = new BadHttpRequestException(CoreStrings.BadRequest_RequestBodyTooLarge, StatusCodes.Status413PayloadTooLarge); + ex = new BadHttpRequestException(CoreStrings.BadRequest_RequestBodyTooLarge, StatusCodes.Status413PayloadTooLarge, reason); break; case RequestRejectionReason.RequestHeadersTimeout: - ex = new BadHttpRequestException(CoreStrings.BadRequest_RequestHeadersTimeout, StatusCodes.Status408RequestTimeout); + ex = new BadHttpRequestException(CoreStrings.BadRequest_RequestHeadersTimeout, StatusCodes.Status408RequestTimeout, reason); break; case RequestRejectionReason.RequestBodyTimeout: - ex = new BadHttpRequestException(CoreStrings.BadRequest_RequestBodyTimeout, StatusCodes.Status408RequestTimeout); + ex = new BadHttpRequestException(CoreStrings.BadRequest_RequestBodyTimeout, StatusCodes.Status408RequestTimeout, reason); break; case RequestRejectionReason.OptionsMethodRequired: - ex = new BadHttpRequestException(CoreStrings.BadRequest_MethodNotAllowed, StatusCodes.Status405MethodNotAllowed, HttpMethod.Options); + ex = new BadHttpRequestException(CoreStrings.BadRequest_MethodNotAllowed, StatusCodes.Status405MethodNotAllowed, reason, HttpMethod.Options); break; case RequestRejectionReason.ConnectMethodRequired: - ex = new BadHttpRequestException(CoreStrings.BadRequest_MethodNotAllowed, StatusCodes.Status405MethodNotAllowed, HttpMethod.Connect); + ex = new BadHttpRequestException(CoreStrings.BadRequest_MethodNotAllowed, StatusCodes.Status405MethodNotAllowed, reason, HttpMethod.Connect); break; case RequestRejectionReason.MissingHostHeader: - ex = new BadHttpRequestException(CoreStrings.BadRequest_MissingHostHeader, StatusCodes.Status400BadRequest); + ex = new BadHttpRequestException(CoreStrings.BadRequest_MissingHostHeader, StatusCodes.Status400BadRequest, reason); break; case RequestRejectionReason.MultipleHostHeaders: - ex = new BadHttpRequestException(CoreStrings.BadRequest_MultipleHostHeaders, StatusCodes.Status400BadRequest); + ex = new BadHttpRequestException(CoreStrings.BadRequest_MultipleHostHeaders, StatusCodes.Status400BadRequest, reason); break; case RequestRejectionReason.InvalidHostHeader: - ex = new BadHttpRequestException(CoreStrings.BadRequest_InvalidHostHeader, StatusCodes.Status400BadRequest); + ex = new BadHttpRequestException(CoreStrings.BadRequest_InvalidHostHeader, StatusCodes.Status400BadRequest, reason); break; case RequestRejectionReason.UpgradeRequestCannotHavePayload: - ex = new BadHttpRequestException(CoreStrings.BadRequest_UpgradeRequestCannotHavePayload, StatusCodes.Status400BadRequest); + ex = new BadHttpRequestException(CoreStrings.BadRequest_UpgradeRequestCannotHavePayload, StatusCodes.Status400BadRequest, reason); break; default: - ex = new BadHttpRequestException(CoreStrings.BadRequest, StatusCodes.Status400BadRequest); + ex = new BadHttpRequestException(CoreStrings.BadRequest, StatusCodes.Status400BadRequest, reason); break; } return ex; @@ -137,34 +140,34 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core switch (reason) { case RequestRejectionReason.InvalidRequestLine: - ex = new BadHttpRequestException(CoreStrings.FormatBadRequest_InvalidRequestLine_Detail(detail), StatusCodes.Status400BadRequest); + ex = new BadHttpRequestException(CoreStrings.FormatBadRequest_InvalidRequestLine_Detail(detail), StatusCodes.Status400BadRequest, reason); break; case RequestRejectionReason.InvalidRequestTarget: - ex = new BadHttpRequestException(CoreStrings.FormatBadRequest_InvalidRequestTarget_Detail(detail), StatusCodes.Status400BadRequest); + ex = new BadHttpRequestException(CoreStrings.FormatBadRequest_InvalidRequestTarget_Detail(detail), StatusCodes.Status400BadRequest, reason); break; case RequestRejectionReason.InvalidRequestHeader: - ex = new BadHttpRequestException(CoreStrings.FormatBadRequest_InvalidRequestHeader_Detail(detail), StatusCodes.Status400BadRequest); + ex = new BadHttpRequestException(CoreStrings.FormatBadRequest_InvalidRequestHeader_Detail(detail), StatusCodes.Status400BadRequest, reason); break; case RequestRejectionReason.InvalidContentLength: - ex = new BadHttpRequestException(CoreStrings.FormatBadRequest_InvalidContentLength_Detail(detail), StatusCodes.Status400BadRequest); + ex = new BadHttpRequestException(CoreStrings.FormatBadRequest_InvalidContentLength_Detail(detail), StatusCodes.Status400BadRequest, reason); break; case RequestRejectionReason.UnrecognizedHTTPVersion: - ex = new BadHttpRequestException(CoreStrings.FormatBadRequest_UnrecognizedHTTPVersion(detail), StatusCodes.Status505HttpVersionNotsupported); + ex = new BadHttpRequestException(CoreStrings.FormatBadRequest_UnrecognizedHTTPVersion(detail), StatusCodes.Status505HttpVersionNotsupported, reason); break; case RequestRejectionReason.FinalTransferCodingNotChunked: - ex = new BadHttpRequestException(CoreStrings.FormatBadRequest_FinalTransferCodingNotChunked(detail), StatusCodes.Status400BadRequest); + ex = new BadHttpRequestException(CoreStrings.FormatBadRequest_FinalTransferCodingNotChunked(detail), StatusCodes.Status400BadRequest, reason); break; case RequestRejectionReason.LengthRequired: - ex = new BadHttpRequestException(CoreStrings.FormatBadRequest_LengthRequired(detail), StatusCodes.Status411LengthRequired); + ex = new BadHttpRequestException(CoreStrings.FormatBadRequest_LengthRequired(detail), StatusCodes.Status411LengthRequired, reason); break; case RequestRejectionReason.LengthRequiredHttp10: - ex = new BadHttpRequestException(CoreStrings.FormatBadRequest_LengthRequiredHttp10(detail), StatusCodes.Status400BadRequest); + ex = new BadHttpRequestException(CoreStrings.FormatBadRequest_LengthRequiredHttp10(detail), StatusCodes.Status400BadRequest, reason); break; case RequestRejectionReason.InvalidHostHeader: - ex = new BadHttpRequestException(CoreStrings.FormatBadRequest_InvalidHostHeader_Detail(detail), StatusCodes.Status400BadRequest); + ex = new BadHttpRequestException(CoreStrings.FormatBadRequest_InvalidHostHeader_Detail(detail), StatusCodes.Status400BadRequest, reason); break; default: - ex = new BadHttpRequestException(CoreStrings.BadRequest, StatusCodes.Status400BadRequest); + ex = new BadHttpRequestException(CoreStrings.BadRequest, StatusCodes.Status400BadRequest, reason); break; } return ex; diff --git a/src/Kestrel.Core/Internal/Http/Http1MessageBody.cs b/src/Kestrel.Core/Internal/Http/Http1MessageBody.cs index 90c05f53ee..c47bf114b6 100644 --- a/src/Kestrel.Core/Internal/Http/Http1MessageBody.cs +++ b/src/Kestrel.Core/Internal/Http/Http1MessageBody.cs @@ -3,12 +3,11 @@ using System; using System.Buffers; -using System.Collections; using System.IO; using System.IO.Pipelines; using System.Threading.Tasks; +using Microsoft.AspNetCore.Connections; using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Connections.Abstractions; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http @@ -125,9 +124,36 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http return _pumpTask; } - protected override async Task OnConsumeAsync() + protected override Task OnConsumeAsync() { - _context.TimeoutControl.SetTimeout(Constants.RequestBodyDrainTimeout.Ticks, TimeoutAction.SendTimeoutResponse); + try + { + if (_context.RequestBodyPipe.Reader.TryRead(out var readResult)) + { + _context.RequestBodyPipe.Reader.AdvanceTo(readResult.Buffer.End); + + if (readResult.IsCompleted) + { + return Task.CompletedTask; + } + } + } + catch (BadHttpRequestException ex) + { + // At this point, the response has already been written, so this won't result in a 4XX response; + // however, we still need to stop the request processing loop and log. + _context.SetBadRequestState(ex); + return Task.CompletedTask; + } + + return OnConsumeAsyncAwaited(); + } + + private async Task OnConsumeAsyncAwaited() + { + Log.RequestBodyNotEntirelyRead(_context.ConnectionIdFeature, _context.TraceIdentifier); + + _context.TimeoutControl.SetTimeout(Constants.RequestBodyDrainTimeout.Ticks, TimeoutAction.AbortConnection); try { @@ -138,6 +164,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http _context.RequestBodyPipe.Reader.AdvanceTo(result.Buffer.End); } while (!result.IsCompleted); } + catch (BadHttpRequestException ex) + { + _context.SetBadRequestState(ex); + } + catch (ConnectionAbortedException) + { + Log.RequestBodyDrainTimedOut(_context.ConnectionIdFeature, _context.TraceIdentifier); + } finally { _context.TimeoutControl.CancelTimeout(); diff --git a/src/Kestrel.Core/Internal/Http/HttpProtocol.cs b/src/Kestrel.Core/Internal/Http/HttpProtocol.cs index 93cb96499d..7db0062a15 100644 --- a/src/Kestrel.Core/Internal/Http/HttpProtocol.cs +++ b/src/Kestrel.Core/Internal/Http/HttpProtocol.cs @@ -300,8 +300,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http (RequestBody, ResponseBody) = _streams.Start(messageBody); } - public void PauseStreams() => _streams.Pause(); - public void StopStreams() => _streams.Stop(); // For testing @@ -493,7 +491,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { // Keep-alive is default for HTTP/1.1 and HTTP/2; parsing and errors will change its value _keepAlive = true; - do + + while (_keepAlive) { BeginRequestProcessing(); @@ -525,7 +524,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http var httpContext = application.CreateContext(this); - BadHttpRequestException badRequestException = null; try { KestrelEventSource.Log.RequestStart(this); @@ -538,11 +536,17 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http VerifyResponseContentLength(); } } + catch (BadHttpRequestException ex) + { + // Capture BadHttpRequestException for further processing + // This has to be caught here so StatusCode is set properly before disposing the HttpContext + // (DisposeContext logs StatusCode). + SetBadRequestState(ex); + ReportApplicationError(ex); + } catch (Exception ex) { ReportApplicationError(ex); - // Capture BadHttpRequestException for further processing - badRequestException = ex as BadHttpRequestException; } KestrelEventSource.Log.RequestStop(this); @@ -556,9 +560,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http await FireOnStarting(); } - PauseStreams(); + // At this point all user code that needs use to the request or response streams has completed. + // Using these streams in the OnCompleted callback is not allowed. + StopStreams(); - if (badRequestException == null) + // 4XX responses are written by TryProduceInvalidRequestResponse during connection tear down. + if (_requestRejectedException == null) { // If _requestAbort is set, the connection has already been closed. if (_requestAborted == 0) @@ -576,21 +583,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http // HttpContext.Response.StatusCode is correctly set when // IHttpContextFactory.Dispose(HttpContext) is called. await ProduceEnd(); - - // ForZeroContentLength does not complete the reader nor the writer - if (!messageBody.IsEmpty) - { - try - { - // Finish reading the request body in case the app did not. - await messageBody.ConsumeAsync(); - } - catch (BadHttpRequestException ex) - { - // Capture BadHttpRequestException for further processing - badRequestException = ex; - } - } } else if (!HasResponseStarted) { @@ -605,19 +597,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http await FireOnCompleted(); } - if (badRequestException != null) - { - // Handle BadHttpRequestException thrown during app execution or remaining message body consumption. - // This has to be caught here so StatusCode is set properly before disposing the HttpContext - // (DisposeContext logs StatusCode). - SetBadRequestState(badRequestException); - } - application.DisposeContext(httpContext, _applicationException); - // StopStreams should be called before the end of the "if (!_requestProcessingStopping)" block - // to ensure InitializeStreams has been called. - StopStreams(); + // Even for non-keep-alive requests, try to consume the entire body to avoid RSTs. + if (_requestAborted == 0 && _requestRejectedException == null && !messageBody.IsEmpty) + { + await messageBody.ConsumeAsync(); + } if (HasStartedConsumingRequestBody) { @@ -629,14 +615,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http // At this point both the request body pipe reader and writer should be completed. RequestBodyPipe.Reset(); } - - if (badRequestException != null) - { - // Bad request reported, stop processing requests - return; - } - - } while (_keepAlive); + } } public void OnStarting(Func callback, object state) diff --git a/src/Kestrel.Core/Internal/Http/HttpRequestStream.cs b/src/Kestrel.Core/Internal/Http/HttpRequestStream.cs index 8ea4e9f922..51b7e7b6cd 100644 --- a/src/Kestrel.Core/Internal/Http/HttpRequestStream.cs +++ b/src/Kestrel.Core/Internal/Http/HttpRequestStream.cs @@ -169,11 +169,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http } } - public void PauseAcceptingReads() - { - _state = HttpStreamState.Closed; - } - public void StopAcceptingReads() { // Can't use dispose (or close) as can be disposed too early by user code diff --git a/src/Kestrel.Core/Internal/Http/HttpResponseStream.cs b/src/Kestrel.Core/Internal/Http/HttpResponseStream.cs index fb2cc91a9d..aefbe6fb19 100644 --- a/src/Kestrel.Core/Internal/Http/HttpResponseStream.cs +++ b/src/Kestrel.Core/Internal/Http/HttpResponseStream.cs @@ -129,11 +129,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http } } - public void PauseAcceptingWrites() - { - _state = HttpStreamState.Closed; - } - public void StopAcceptingWrites() { // Can't use dispose (or close) as can be disposed too early by user code diff --git a/src/Kestrel.Core/Internal/Infrastructure/IKestrelTrace.cs b/src/Kestrel.Core/Internal/Infrastructure/IKestrelTrace.cs index 46aed5b8ad..e58decaafe 100644 --- a/src/Kestrel.Core/Internal/Infrastructure/IKestrelTrace.cs +++ b/src/Kestrel.Core/Internal/Infrastructure/IKestrelTrace.cs @@ -44,6 +44,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure void RequestBodyDone(string connectionId, string traceIdentifier); + void RequestBodyNotEntirelyRead(string connectionId, string traceIdentifier); + + void RequestBodyDrainTimedOut(string connectionId, string traceIdentifier); + void RequestBodyMininumDataRateNotSatisfied(string connectionId, string traceIdentifier, double rate); void ResponseMininumDataRateNotSatisfied(string connectionId, string traceIdentifier); diff --git a/src/Kestrel.Core/Internal/Infrastructure/KestrelTrace.cs b/src/Kestrel.Core/Internal/Infrastructure/KestrelTrace.cs index 0314b4fdf5..b9c0e98d5a 100644 --- a/src/Kestrel.Core/Internal/Infrastructure/KestrelTrace.cs +++ b/src/Kestrel.Core/Internal/Infrastructure/KestrelTrace.cs @@ -65,6 +65,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal private static readonly Action _requestBodyMinimumDataRateNotSatisfied = LoggerMessage.Define(LogLevel.Information, new EventId(27, nameof(RequestBodyMininumDataRateNotSatisfied)), @"Connection id ""{ConnectionId}"", Request id ""{TraceIdentifier}"": the request timed out because it was not sent by the client at a minimum of {Rate} bytes/second."); + private static readonly Action _requestBodyNotEntirelyRead = + LoggerMessage.Define(LogLevel.Information, new EventId(32, nameof(RequestBodyNotEntirelyRead)), @"Connection id ""{ConnectionId}"", Request id ""{TraceIdentifier}"": the application completed without reading the entire request body."); + + private static readonly Action _requestBodyDrainTimedOut = + LoggerMessage.Define(LogLevel.Information, new EventId(33, nameof(RequestBodyDrainTimedOut)), @"Connection id ""{ConnectionId}"", Request id ""{TraceIdentifier}"": automatic draining of the request body timed out after taking over 5 seconds."); + private static readonly Action _responseMinimumDataRateNotSatisfied = LoggerMessage.Define(LogLevel.Information, new EventId(28, nameof(ResponseMininumDataRateNotSatisfied)), @"Connection id ""{ConnectionId}"", Request id ""{TraceIdentifier}"": the connection was closed because the response was not read by the client at the specified minimum data rate."); @@ -174,6 +180,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal _requestBodyMinimumDataRateNotSatisfied(_logger, connectionId, traceIdentifier, rate, null); } + public virtual void RequestBodyNotEntirelyRead(string connectionId, string traceIdentifier) + { + _requestBodyNotEntirelyRead(_logger, connectionId, traceIdentifier, null); + } + + public virtual void RequestBodyDrainTimedOut(string connectionId, string traceIdentifier) + { + _requestBodyDrainTimedOut(_logger, connectionId, traceIdentifier, null); + } + public virtual void ResponseMininumDataRateNotSatisfied(string connectionId, string traceIdentifier) { _responseMinimumDataRateNotSatisfied(_logger, connectionId, traceIdentifier, null); diff --git a/src/Kestrel.Core/Internal/Infrastructure/Streams.cs b/src/Kestrel.Core/Internal/Infrastructure/Streams.cs index 21a82b4648..a439928e5e 100644 --- a/src/Kestrel.Core/Internal/Infrastructure/Streams.cs +++ b/src/Kestrel.Core/Internal/Infrastructure/Streams.cs @@ -54,13 +54,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure } } - public void Pause() - { - _request.PauseAcceptingReads(); - _emptyRequest.PauseAcceptingReads(); - _response.PauseAcceptingWrites(); - } - public void Stop() { _request.StopAcceptingReads(); diff --git a/test/Kestrel.Core.Tests/MessageBodyTests.cs b/test/Kestrel.Core.Tests/MessageBodyTests.cs index e9647cbee4..fb2d8613db 100644 --- a/test/Kestrel.Core.Tests/MessageBodyTests.cs +++ b/test/Kestrel.Core.Tests/MessageBodyTests.cs @@ -599,14 +599,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests } [Fact] - public async Task ConsumeAsyncThrowsOnTimeout() + public async Task ConsumeAsyncCompletesAndDoesNotThrowOnTimeout() { using (var input = new TestInput()) { var mockTimeoutControl = new Mock(); - input.Http1ConnectionContext.TimeoutControl = mockTimeoutControl.Object; + var mockLogger = new Mock(); + input.Http1Connection.ServiceContext.Log = mockLogger.Object; + var body = Http1MessageBody.For(HttpVersion.Http11, new HttpRequestHeaders { HeaderContentLength = "5" }, input.Http1Connection); // Add some input and read it to start PumpAsync @@ -616,8 +618,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests // Time out on the next read input.Http1Connection.SendTimeoutResponse(); - var exception = await Assert.ThrowsAsync(() => body.ConsumeAsync()); - Assert.Equal(StatusCodes.Status408RequestTimeout, exception.StatusCode); + await body.ConsumeAsync(); + + mockLogger.Verify(logger => logger.ConnectionBadRequest( + It.IsAny(), + It.Is(ex => ex.Reason == RequestRejectionReason.RequestBodyTimeout))); await body.StopAsync(); } diff --git a/test/Kestrel.FunctionalTests/RequestBodyTimeoutTests.cs b/test/Kestrel.FunctionalTests/RequestBodyTimeoutTests.cs index 8e6c84296e..0ae0e9f0ce 100644 --- a/test/Kestrel.FunctionalTests/RequestBodyTimeoutTests.cs +++ b/test/Kestrel.FunctionalTests/RequestBodyTimeoutTests.cs @@ -111,8 +111,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } } - Assert.Contains(TestSink.Writes, w => w.EventId.Id == 17 && w.LogLevel == LogLevel.Information && w.Exception is BadHttpRequestException - && ((BadHttpRequestException)w.Exception).StatusCode == StatusCodes.Status408RequestTimeout); + Assert.Contains(TestSink.Writes, w => w.EventId.Id == 32 && w.LogLevel == LogLevel.Information); + Assert.Contains(TestSink.Writes, w => w.EventId.Id == 33 && w.LogLevel == LogLevel.Information); } [Fact(Skip="https://github.com/aspnet/KestrelHttpServer/issues/2464")] diff --git a/test/Kestrel.FunctionalTests/ResponseTests.cs b/test/Kestrel.FunctionalTests/ResponseTests.cs index 1482302999..961d670e23 100644 --- a/test/Kestrel.FunctionalTests/ResponseTests.cs +++ b/test/Kestrel.FunctionalTests/ResponseTests.cs @@ -341,7 +341,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [Fact] public async Task OnCompletedShouldNotBlockAResponse() { - var delay = Task.Delay(TestConstants.DefaultTimeout); + var delayTcs = new TaskCompletionSource(); var hostBuilder = TransportSelector.GetWebHostBuilder() .UseKestrel() .UseUrls("http://127.0.0.1:0/") @@ -352,7 +352,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { context.Response.OnCompleted(async () => { - await delay; + await delayTcs.Task; }); await context.Response.WriteAsync("hello, world"); }); @@ -366,8 +366,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { var response = await client.GetAsync($"http://127.0.0.1:{host.GetPort()}/"); Assert.Equal(HttpStatusCode.OK, response.StatusCode); - Assert.False(delay.IsCompleted); } + + delayTcs.SetResult(null); } } From 9662e2bd015b0884aff7882f8214da61e2e53715 Mon Sep 17 00:00:00 2001 From: Ryan Brandenburg Date: Mon, 16 Apr 2018 16:58:58 -0700 Subject: [PATCH 1627/1662] Branching for 2.1.0-rc1 --- build/repo.props | 3 ++- korebuild.json | 4 ++-- version.props | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/build/repo.props b/build/repo.props index 2c858d96cf..413dd9dd05 100644 --- a/build/repo.props +++ b/build/repo.props @@ -1,10 +1,11 @@ - + true Internal.AspNetCore.Universe.Lineup + 2.1.0-rc1-* https://dotnet.myget.org/F/aspnetcore-dev/api/v3/index.json diff --git a/korebuild.json b/korebuild.json index bd5d51a51b..678d8bb948 100644 --- a/korebuild.json +++ b/korebuild.json @@ -1,4 +1,4 @@ { - "$schema": "https://raw.githubusercontent.com/aspnet/BuildTools/dev/tools/korebuild.schema.json", - "channel": "dev" + "$schema": "https://raw.githubusercontent.com/aspnet/BuildTools/release/2.1/tools/korebuild.schema.json", + "channel": "release/2.1" } diff --git a/version.props b/version.props index 24f2b00a0a..e27532787e 100644 --- a/version.props +++ b/version.props @@ -1,7 +1,7 @@ 2.1.0 - preview3 + rc1 $(VersionPrefix) $(VersionPrefix)-$(VersionSuffix)-final t000 From 50a9af203c284910c94440a3ab11edacd4b0fcfb Mon Sep 17 00:00:00 2001 From: Nate McMaster Date: Thu, 19 Apr 2018 16:40:25 -0700 Subject: [PATCH 1628/1662] Set NETStandardImplicitPackageVersion via dependencies.props --- Directory.Build.targets | 1 + build/dependencies.props | 1 + 2 files changed, 2 insertions(+) diff --git a/Directory.Build.targets b/Directory.Build.targets index 894b1d0cf8..53b3f6e1da 100644 --- a/Directory.Build.targets +++ b/Directory.Build.targets @@ -2,5 +2,6 @@ $(MicrosoftNETCoreApp20PackageVersion) $(MicrosoftNETCoreApp21PackageVersion) + $(NETStandardLibrary20PackageVersion) diff --git a/build/dependencies.props b/build/dependencies.props index f7623e1971..1c189e53d0 100644 --- a/build/dependencies.props +++ b/build/dependencies.props @@ -33,6 +33,7 @@ 2.1.0-preview3-26413-05 2.1.0-preview3-32233 15.6.1 + 2.0.1 4.7.49 11.0.2 4.5.0-preview3-26413-02 From 3ab8461a8c771d20886f519f4134aec92a86535b Mon Sep 17 00:00:00 2001 From: "ASP.NET CI" Date: Thu, 19 Apr 2018 22:27:48 -0700 Subject: [PATCH 1629/1662] Update dependencies.props [auto-updated: dependencies] --- build/dependencies.props | 66 ++++++++++++++++++++-------------------- korebuild-lock.txt | 4 +-- 2 files changed, 35 insertions(+), 35 deletions(-) diff --git a/build/dependencies.props b/build/dependencies.props index 1c189e53d0..9290b0d72e 100644 --- a/build/dependencies.props +++ b/build/dependencies.props @@ -5,44 +5,44 @@ 0.10.13 - 2.1.0-preview3-17018 + 2.1.0-rc1-15774 1.10.0 - 2.1.0-preview3-32233 - 2.1.0-preview3-32233 - 2.1.0-preview3-32233 - 2.1.0-preview3-32233 - 2.1.0-preview3-32233 - 2.1.0-preview3-32233 - 2.1.0-preview3-32233 - 2.1.0-preview3-32233 - 2.1.0-preview3-32233 - 2.1.0-preview3-32233 - 2.1.0-preview3-32233 - 2.1.0-preview3-32233 - 2.1.0-preview3-32233 - 2.1.0-preview3-32233 - 2.1.0-preview3-32233 - 2.1.0-preview3-32233 - 2.1.0-preview3-32233 - 2.1.0-preview3-32233 - 2.1.0-preview3-32233 - 2.1.0-preview3-32233 - 2.1.0-preview3-32233 - 2.1.0-preview3-32233 + 2.1.0-rc1-30613 + 2.1.0-rc1-30613 + 2.1.0-rc1-30613 + 2.1.0-rc1-30613 + 2.1.0-rc1-30613 + 2.1.0-rc1-30613 + 2.1.0-rc1-30613 + 2.1.0-rc1-30613 + 2.1.0-rc1-30613 + 2.1.0-rc1-30613 + 2.1.0-rc1-30613 + 2.1.0-rc1-30613 + 2.1.0-rc1-30613 + 2.1.0-rc1-30613 + 2.1.0-rc1-30613 + 2.1.0-rc1-30613 + 2.1.0-rc1-30613 + 2.1.0-rc1-30613 + 2.1.0-rc1-30613 + 2.1.0-rc1-30613 + 2.1.0-rc1-30613 + 2.1.0-rc1-30613 2.0.0 - 2.1.0-preview3-26413-05 - 2.1.0-preview3-32233 + 2.1.0-rc1-26419-02 + 2.1.0-rc1-30613 15.6.1 - 2.0.1 4.7.49 + 2.0.1 11.0.2 - 4.5.0-preview3-26413-02 - 4.5.0-preview3-26413-02 - 4.5.0-preview3-26413-02 - 4.5.0-preview3-26413-02 - 4.5.0-preview3-26413-02 - 4.5.0-preview3-26413-02 - 4.5.0-preview3-26413-02 + 4.5.0-rc1-26419-03 + 4.5.0-rc1-26419-03 + 4.5.0-rc1-26419-03 + 4.5.0-rc1-26419-03 + 4.5.0-rc1-26419-03 + 4.5.0-rc1-26419-03 + 4.5.0-rc1-26419-03 1.3.7 0.8.0 2.3.1 diff --git a/korebuild-lock.txt b/korebuild-lock.txt index b419d767b9..9d4ef8c888 100644 --- a/korebuild-lock.txt +++ b/korebuild-lock.txt @@ -1,2 +1,2 @@ -version:2.1.0-preview3-17018 -commithash:af264ca131f212b5ba8aafbc5110fc0fc510a2be +version:2.1.0-rc1-15774 +commithash:ed5ca9de3c652347dbb0158a9a65eff3471d2114 From b0e1fa5e30fd3da74273d5117226f9a6073e8257 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Mon, 23 Apr 2018 16:58:11 -0700 Subject: [PATCH 1630/1662] Fix connection abort --- .../BenchmarkApplication.cs | 6 +- .../BufferWriterExtensions.cs | 38 -- .../PlatformBenchmarks.csproj | 2 - .../DefaultConnectionContext.cs | 24 +- .../Features/IConnectionLifetimeFeature.cs | 13 + src/Kestrel.Core/Internal/Http/ChunkWriter.cs | 4 +- .../Internal/Http/CountingBufferWriter.cs | 99 ++++++ .../Internal/Http/Http1Connection.cs | 11 +- .../Internal/Http/Http1OutputProducer.cs | 68 +++- .../Internal/Http/HttpHeaders.Generated.cs | 2 +- .../Internal/Http/HttpProtocol.cs | 16 +- .../Internal/Http/HttpResponseHeaders.cs | 2 +- .../Internal/Http/IHttpOutputProducer.cs | 2 +- .../Internal/Http/PipelineExtensions.cs | 8 +- .../Internal/Http2/Http2OutputProducer.cs | 2 +- src/Kestrel.Core/Internal/HttpConnection.cs | 33 +- src/Kestrel.Core/Properties/AssemblyInfo.cs | 1 + .../Internal/IBytesWrittenFeature.cs | 13 + .../Internal/TransportConnection.Features.cs | 65 +++- .../Internal/TransportConnection.cs | 11 +- .../Internal/LibuvConnection.cs | 25 ++ .../Internal/LibuvConnectionContext.cs | 1 - .../Internal/LibuvOutputConsumer.cs | 28 +- .../Internal/SocketConnection.cs | 61 +++- .../ConnectionDispatcherTests.cs | 18 +- .../Http1ConnectionTests.cs | 12 +- .../Kestrel.Core.Tests/HttpConnectionTests.cs | 59 +++- .../Kestrel.Core.Tests/OutputProducerTests.cs | 33 +- .../PipelineExtensionTests.cs | 12 +- test/Kestrel.Core.Tests/TestInput.cs | 7 +- test/Kestrel.FunctionalTests/HttpsTests.cs | 22 +- test/Kestrel.FunctionalTests/RequestTests.cs | 105 +++++- test/Kestrel.FunctionalTests/ResponseTests.cs | 326 ++++++++++++++---- .../LibuvOutputConsumerTests.cs | 8 +- tools/CodeGenerator/KnownHeaders.cs | 2 +- 35 files changed, 921 insertions(+), 218 deletions(-) delete mode 100644 benchmarkapps/PlatformBenchmarks/BufferWriterExtensions.cs create mode 100644 src/Connections.Abstractions/Features/IConnectionLifetimeFeature.cs create mode 100644 src/Kestrel.Core/Internal/Http/CountingBufferWriter.cs create mode 100644 src/Kestrel.Transport.Abstractions/Internal/IBytesWrittenFeature.cs diff --git a/benchmarkapps/PlatformBenchmarks/BenchmarkApplication.cs b/benchmarkapps/PlatformBenchmarks/BenchmarkApplication.cs index 6551bee358..d65452c13c 100644 --- a/benchmarkapps/PlatformBenchmarks/BenchmarkApplication.cs +++ b/benchmarkapps/PlatformBenchmarks/BenchmarkApplication.cs @@ -78,7 +78,7 @@ namespace PlatformBenchmarks } private static void PlainText(PipeWriter pipeWriter) { - var writer = new BufferWriter(pipeWriter); + var writer = new CountingBufferWriter(pipeWriter); // HTTP 1.1 OK writer.Write(_http11OK); @@ -105,7 +105,7 @@ namespace PlatformBenchmarks private static void Json(PipeWriter pipeWriter) { - var writer = new BufferWriter(pipeWriter); + var writer = new CountingBufferWriter(pipeWriter); // HTTP 1.1 OK writer.Write(_http11OK); @@ -134,7 +134,7 @@ namespace PlatformBenchmarks private static void Default(PipeWriter pipeWriter) { - var writer = new BufferWriter(pipeWriter); + var writer = new CountingBufferWriter(pipeWriter); // HTTP 1.1 OK writer.Write(_http11OK); diff --git a/benchmarkapps/PlatformBenchmarks/BufferWriterExtensions.cs b/benchmarkapps/PlatformBenchmarks/BufferWriterExtensions.cs deleted file mode 100644 index 0da6b24fd4..0000000000 --- a/benchmarkapps/PlatformBenchmarks/BufferWriterExtensions.cs +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System.Buffers.Text; -using System.Diagnostics; -using System.IO.Pipelines; -using System.Runtime.CompilerServices; - -namespace System.Buffers -{ - internal static class BufferWriterExtensions - { - private const int MaxULongByteLength = 20; - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - internal static void WriteNumeric(ref this BufferWriter buffer, ulong number) - { - // Try to format directly - if (Utf8Formatter.TryFormat(number, buffer.Span, out int bytesWritten)) - { - buffer.Advance(bytesWritten); - } - else - { - // Ask for at least 20 bytes - buffer.Ensure(MaxULongByteLength); - - Debug.Assert(buffer.Span.Length >= 20, "Buffer is < 20 bytes"); - - // Try again - if (Utf8Formatter.TryFormat(number, buffer.Span, out bytesWritten)) - { - buffer.Advance(bytesWritten); - } - } - } - } -} \ No newline at end of file diff --git a/benchmarkapps/PlatformBenchmarks/PlatformBenchmarks.csproj b/benchmarkapps/PlatformBenchmarks/PlatformBenchmarks.csproj index a883710816..4d4126c688 100644 --- a/benchmarkapps/PlatformBenchmarks/PlatformBenchmarks.csproj +++ b/benchmarkapps/PlatformBenchmarks/PlatformBenchmarks.csproj @@ -16,13 +16,11 @@ - - diff --git a/src/Connections.Abstractions/DefaultConnectionContext.cs b/src/Connections.Abstractions/DefaultConnectionContext.cs index 4b3377350d..1b161c7253 100644 --- a/src/Connections.Abstractions/DefaultConnectionContext.cs +++ b/src/Connections.Abstractions/DefaultConnectionContext.cs @@ -6,22 +6,25 @@ using System.Collections.Generic; using System.IO.Pipelines; using System.Security.Claims; using System.Threading; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Http.Features; -using Microsoft.AspNetCore.Connections; using Microsoft.AspNetCore.Connections.Features; +using Microsoft.AspNetCore.Http.Features; namespace Microsoft.AspNetCore.Connections { public class DefaultConnectionContext : ConnectionContext, + IDisposable, IConnectionIdFeature, IConnectionItemsFeature, IConnectionTransportFeature, - IConnectionUserFeature + IConnectionUserFeature, + IConnectionLifetimeFeature { + private CancellationTokenSource _connectionClosedTokenSource = new CancellationTokenSource(); + public DefaultConnectionContext() : this(Guid.NewGuid().ToString()) { + ConnectionClosed = _connectionClosedTokenSource.Token; } /// @@ -38,6 +41,7 @@ namespace Microsoft.AspNetCore.Connections Features.Set(this); Features.Set(this); Features.Set(this); + Features.Set(this); } public DefaultConnectionContext(string id, IDuplexPipe transport, IDuplexPipe application) @@ -58,5 +62,17 @@ namespace Microsoft.AspNetCore.Connections public IDuplexPipe Application { get; set; } public override IDuplexPipe Transport { get; set; } + + public CancellationToken ConnectionClosed { get; set; } + + public virtual void Abort() + { + ThreadPool.QueueUserWorkItem(cts => ((CancellationTokenSource)cts).Cancel(), _connectionClosedTokenSource); + } + + public void Dispose() + { + _connectionClosedTokenSource.Dispose(); + } } } diff --git a/src/Connections.Abstractions/Features/IConnectionLifetimeFeature.cs b/src/Connections.Abstractions/Features/IConnectionLifetimeFeature.cs new file mode 100644 index 0000000000..8f804de898 --- /dev/null +++ b/src/Connections.Abstractions/Features/IConnectionLifetimeFeature.cs @@ -0,0 +1,13 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System.Threading; + +namespace Microsoft.AspNetCore.Connections.Features +{ + public interface IConnectionLifetimeFeature + { + CancellationToken ConnectionClosed { get; set; } + void Abort(); + } +} diff --git a/src/Kestrel.Core/Internal/Http/ChunkWriter.cs b/src/Kestrel.Core/Internal/Http/ChunkWriter.cs index 3d8cc4566b..2184937b07 100644 --- a/src/Kestrel.Core/Internal/Http/ChunkWriter.cs +++ b/src/Kestrel.Core/Internal/Http/ChunkWriter.cs @@ -48,14 +48,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http return new ArraySegment(bytes, offset, 10 - offset); } - internal static int WriteBeginChunkBytes(ref BufferWriter start, int dataCount) + internal static int WriteBeginChunkBytes(ref CountingBufferWriter start, int dataCount) { var chunkSegment = BeginChunkBytes(dataCount); start.Write(new ReadOnlySpan(chunkSegment.Array, chunkSegment.Offset, chunkSegment.Count)); return chunkSegment.Count; } - internal static void WriteEndChunkBytes(ref BufferWriter start) + internal static void WriteEndChunkBytes(ref CountingBufferWriter start) { start.Write(new ReadOnlySpan(_endChunkBytes.Array, _endChunkBytes.Offset, _endChunkBytes.Count)); } diff --git a/src/Kestrel.Core/Internal/Http/CountingBufferWriter.cs b/src/Kestrel.Core/Internal/Http/CountingBufferWriter.cs new file mode 100644 index 0000000000..e3299c6027 --- /dev/null +++ b/src/Kestrel.Core/Internal/Http/CountingBufferWriter.cs @@ -0,0 +1,99 @@ + +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System.Runtime.CompilerServices; + +namespace System.Buffers +{ + // TODO: Once this is public, update the actual CountingBufferWriter in the Common repo, + // and go back to using that. + internal ref struct CountingBufferWriter where T: IBufferWriter + { + private T _output; + private Span _span; + private int _buffered; + private long _bytesCommitted; + + public CountingBufferWriter(T output) + { + _buffered = 0; + _bytesCommitted = 0; + _output = output; + _span = output.GetSpan(); + } + + public Span Span => _span; + public long BytesCommitted => _bytesCommitted; + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public void Commit() + { + var buffered = _buffered; + if (buffered > 0) + { + _bytesCommitted += buffered; + _buffered = 0; + _output.Advance(buffered); + } + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public void Advance(int count) + { + _buffered += count; + _span = _span.Slice(count); + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public void Write(ReadOnlySpan source) + { + if (_span.Length >= source.Length) + { + source.CopyTo(_span); + Advance(source.Length); + } + else + { + WriteMultiBuffer(source); + } + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public void Ensure(int count = 1) + { + if (_span.Length < count) + { + EnsureMore(count); + } + } + + [MethodImpl(MethodImplOptions.NoInlining)] + private void EnsureMore(int count = 0) + { + if (_buffered > 0) + { + Commit(); + } + + _output.GetMemory(count); + _span = _output.GetSpan(); + } + + private void WriteMultiBuffer(ReadOnlySpan source) + { + while (source.Length > 0) + { + if (_span.Length == 0) + { + EnsureMore(); + } + + var writable = Math.Min(source.Length, _span.Length); + source.Slice(0, writable).CopyTo(_span); + source = source.Slice(writable); + Advance(writable); + } + } + } +} diff --git a/src/Kestrel.Core/Internal/Http/Http1Connection.cs b/src/Kestrel.Core/Internal/Http/Http1Connection.cs index 6fd58d08b0..f93a7997fa 100644 --- a/src/Kestrel.Core/Internal/Http/Http1Connection.cs +++ b/src/Kestrel.Core/Internal/Http/Http1Connection.cs @@ -12,6 +12,8 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Connections.Abstractions; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; +using Microsoft.AspNetCore.Connections.Features; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { @@ -42,7 +44,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http _keepAliveTicks = ServerOptions.Limits.KeepAliveTimeout.Ticks; _requestHeadersTimeoutTicks = ServerOptions.Limits.RequestHeadersTimeout.Ticks; - Output = new Http1OutputProducer(_context.Application.Input, _context.Transport.Output, _context.ConnectionId, _context.ServiceContext.Log, _context.TimeoutControl); + Output = new Http1OutputProducer( + _context.Application.Input, + _context.Transport.Output, + _context.ConnectionId, + _context.ServiceContext.Log, + _context.TimeoutControl, + _context.ConnectionFeatures.Get(), + _context.ConnectionFeatures.Get()); } public PipeReader Input => _context.Transport.Input; diff --git a/src/Kestrel.Core/Internal/Http/Http1OutputProducer.cs b/src/Kestrel.Core/Internal/Http/Http1OutputProducer.cs index d767539185..4ef0dff24e 100644 --- a/src/Kestrel.Core/Internal/Http/Http1OutputProducer.cs +++ b/src/Kestrel.Core/Internal/Http/Http1OutputProducer.cs @@ -8,7 +8,9 @@ using System.Runtime.CompilerServices; using System.Text; using System.Threading; using System.Threading.Tasks; +using Microsoft.AspNetCore.Connections.Features; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { @@ -22,11 +24,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http private readonly string _connectionId; private readonly ITimeoutControl _timeoutControl; private readonly IKestrelTrace _log; + private readonly IConnectionLifetimeFeature _lifetimeFeature; + private readonly IBytesWrittenFeature _transportBytesWrittenFeature; // This locks access to to all of the below fields private readonly object _contextLock = new object(); private bool _completed = false; + private bool _aborted; + private long _unflushedBytes; + private long _totalBytesCommitted; private readonly PipeWriter _pipeWriter; private readonly PipeReader _outputPipeReader; @@ -45,7 +52,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http PipeWriter pipeWriter, string connectionId, IKestrelTrace log, - ITimeoutControl timeoutControl) + ITimeoutControl timeoutControl, + IConnectionLifetimeFeature lifetimeFeature, + IBytesWrittenFeature transportBytesWrittenFeature) { _outputPipeReader = outputPipeReader; _pipeWriter = pipeWriter; @@ -53,6 +62,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http _timeoutControl = timeoutControl; _log = log; _flushCompleted = OnFlushCompleted; + _lifetimeFeature = lifetimeFeature; + _transportBytesWrittenFeature = transportBytesWrittenFeature; } public Task WriteDataAsync(ReadOnlySpan buffer, CancellationToken cancellationToken = default(CancellationToken)) @@ -75,7 +86,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http return WriteAsync(Constants.EmptyData, cancellationToken); } - public void Write(Action callback, T state) + public void Write(Func callback, T state) { lock (_contextLock) { @@ -85,11 +96,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http } var buffer = _pipeWriter; - callback(buffer, state); + var bytesCommitted = callback(buffer, state); + _unflushedBytes += bytesCommitted; + _totalBytesCommitted += bytesCommitted; } } - public Task WriteAsync(Action callback, T state) + public Task WriteAsync(Func callback, T state) { lock (_contextLock) { @@ -99,7 +112,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http } var buffer = _pipeWriter; - callback(buffer, state); + var bytesCommitted = callback(buffer, state); + _unflushedBytes += bytesCommitted; + _totalBytesCommitted += bytesCommitted; } return FlushAsync(); @@ -115,14 +130,18 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http } var buffer = _pipeWriter; - var writer = new BufferWriter(buffer); + var writer = new CountingBufferWriter(buffer); writer.Write(_bytesHttpVersion11); var statusBytes = ReasonPhrases.ToStatusBytes(statusCode, reasonPhrase); writer.Write(statusBytes); responseHeaders.CopyTo(ref writer); writer.Write(_bytesEndHeaders); + writer.Commit(); + + _unflushedBytes += writer.BytesCommitted; + _totalBytesCommitted += writer.BytesCommitted; } } @@ -138,23 +157,41 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http _log.ConnectionDisconnect(_connectionId); _completed = true; _pipeWriter.Complete(); + + var unsentBytes = _totalBytesCommitted - _transportBytesWrittenFeature.TotalBytesWritten; + + if (unsentBytes > 0) + { + // unsentBytes should never be over 64KB in the default configuration. + _timeoutControl.StartTimingWrite((int)Math.Min(unsentBytes, int.MaxValue)); + _pipeWriter.OnReaderCompleted((ex, state) => ((ITimeoutControl)state).StopTimingWrite(), _timeoutControl); + } } } public void Abort(Exception error) { + // Abort can be called after Dispose if there's a flush timeout. + // It's important to still call _lifetimeFeature.Abort() in this case. + lock (_contextLock) { - if (_completed) + if (_aborted) { return; } - _log.ConnectionDisconnect(_connectionId); - _completed = true; + if (!_completed) + { + _log.ConnectionDisconnect(_connectionId); + _completed = true; - _outputPipeReader.CancelPendingRead(); - _pipeWriter.Complete(error); + _outputPipeReader.CancelPendingRead(); + _pipeWriter.Complete(error); + } + + _aborted = true; + _lifetimeFeature.Abort(); } } @@ -177,13 +214,18 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http } writableBuffer = _pipeWriter; - var writer = new BufferWriter(writableBuffer); + var writer = new CountingBufferWriter(writableBuffer); if (buffer.Length > 0) { writer.Write(buffer); - bytesWritten += buffer.Length; + + _unflushedBytes += buffer.Length; + _totalBytesCommitted += buffer.Length; } writer.Commit(); + + bytesWritten = _unflushedBytes; + _unflushedBytes = 0; } return FlushAsync(writableBuffer, bytesWritten, cancellationToken); diff --git a/src/Kestrel.Core/Internal/Http/HttpHeaders.Generated.cs b/src/Kestrel.Core/Internal/Http/HttpHeaders.Generated.cs index d84f15706d..f81e87a06c 100644 --- a/src/Kestrel.Core/Internal/Http/HttpHeaders.Generated.cs +++ b/src/Kestrel.Core/Internal/Http/HttpHeaders.Generated.cs @@ -7765,7 +7765,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http return true; } - internal void CopyToFast(ref BufferWriter output) + internal void CopyToFast(ref CountingBufferWriter output) { var tempBits = _bits | (_contentLength.HasValue ? -9223372036854775808L : 0); diff --git a/src/Kestrel.Core/Internal/Http/HttpProtocol.cs b/src/Kestrel.Core/Internal/Http/HttpProtocol.cs index 7db0062a15..1a4bd7940c 100644 --- a/src/Kestrel.Core/Internal/Http/HttpProtocol.cs +++ b/src/Kestrel.Core/Internal/Http/HttpProtocol.cs @@ -32,7 +32,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http private static readonly byte[] _bytesConnectionKeepAlive = Encoding.ASCII.GetBytes("\r\nConnection: keep-alive"); private static readonly byte[] _bytesTransferEncodingChunked = Encoding.ASCII.GetBytes("\r\nTransfer-Encoding: chunked"); private static readonly byte[] _bytesServer = Encoding.ASCII.GetBytes("\r\nServer: " + Constants.ServerName); - private static readonly Action> _writeChunk = WriteChunk; + private static readonly Func, long> _writeChunk = WriteChunk; private readonly object _onStartingSync = new Object(); private readonly object _onCompletedSync = new Object(); @@ -474,6 +474,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { OnRequestProcessingEnding(); await TryProduceInvalidRequestResponse(); + + // Prevent RequestAborted from firing. + Reset(); + Output.Dispose(); } catch (Exception ex) @@ -911,16 +915,22 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http return Output.WriteAsync(_writeChunk, data); } - private static void WriteChunk(PipeWriter writableBuffer, ReadOnlyMemory buffer) + private static long WriteChunk(PipeWriter writableBuffer, ReadOnlyMemory buffer) { - var writer = new BufferWriter(writableBuffer); + var bytesWritten = 0L; if (buffer.Length > 0) { + var writer = new CountingBufferWriter(writableBuffer); + ChunkWriter.WriteBeginChunkBytes(ref writer, buffer.Length); writer.Write(buffer.Span); ChunkWriter.WriteEndChunkBytes(ref writer); writer.Commit(); + + bytesWritten = writer.BytesCommitted; } + + return bytesWritten; } private static ArraySegment CreateAsciiByteArraySegment(string text) diff --git a/src/Kestrel.Core/Internal/Http/HttpResponseHeaders.cs b/src/Kestrel.Core/Internal/Http/HttpResponseHeaders.cs index 1df80f3dc6..a4b81cf69a 100644 --- a/src/Kestrel.Core/Internal/Http/HttpResponseHeaders.cs +++ b/src/Kestrel.Core/Internal/Http/HttpResponseHeaders.cs @@ -27,7 +27,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http return GetEnumerator(); } - internal void CopyTo(ref BufferWriter buffer) + internal void CopyTo(ref CountingBufferWriter buffer) { CopyToFast(ref buffer); if (MaybeUnknown != null) diff --git a/src/Kestrel.Core/Internal/Http/IHttpOutputProducer.cs b/src/Kestrel.Core/Internal/Http/IHttpOutputProducer.cs index abc2b4454a..0c45253bdc 100644 --- a/src/Kestrel.Core/Internal/Http/IHttpOutputProducer.cs +++ b/src/Kestrel.Core/Internal/Http/IHttpOutputProducer.cs @@ -11,7 +11,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http public interface IHttpOutputProducer : IDisposable { void Abort(Exception error); - Task WriteAsync(Action callback, T state); + Task WriteAsync(Func callback, T state); Task FlushAsync(CancellationToken cancellationToken); Task Write100ContinueAsync(CancellationToken cancellationToken); void WriteResponseHeaders(int statusCode, string ReasonPhrase, HttpResponseHeaders responseHeaders); diff --git a/src/Kestrel.Core/Internal/Http/PipelineExtensions.cs b/src/Kestrel.Core/Internal/Http/PipelineExtensions.cs index e56c43b23c..fce822b6c5 100644 --- a/src/Kestrel.Core/Internal/Http/PipelineExtensions.cs +++ b/src/Kestrel.Core/Internal/Http/PipelineExtensions.cs @@ -40,7 +40,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http return result; } - internal static unsafe void WriteAsciiNoValidation(ref this BufferWriter buffer, string data) + internal static unsafe void WriteAsciiNoValidation(ref this CountingBufferWriter buffer, string data) { if (string.IsNullOrEmpty(data)) { @@ -69,7 +69,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http } [MethodImpl(MethodImplOptions.AggressiveInlining)] - internal static unsafe void WriteNumeric(ref this BufferWriter buffer, ulong number) + internal static unsafe void WriteNumeric(ref this CountingBufferWriter buffer, ulong number) { const byte AsciiDigitStart = (byte)'0'; @@ -119,7 +119,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http } [MethodImpl(MethodImplOptions.NoInlining)] - private static void WriteNumericMultiWrite(ref this BufferWriter buffer, ulong number) + private static void WriteNumericMultiWrite(ref this CountingBufferWriter buffer, ulong number) { const byte AsciiDigitStart = (byte)'0'; @@ -140,7 +140,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http } [MethodImpl(MethodImplOptions.NoInlining)] - private unsafe static void WriteAsciiMultiWrite(ref this BufferWriter buffer, string data) + private unsafe static void WriteAsciiMultiWrite(ref this CountingBufferWriter buffer, string data) { var remaining = data.Length; diff --git a/src/Kestrel.Core/Internal/Http2/Http2OutputProducer.cs b/src/Kestrel.Core/Internal/Http2/Http2OutputProducer.cs index 571f5a32d2..0fe1fbf344 100644 --- a/src/Kestrel.Core/Internal/Http2/Http2OutputProducer.cs +++ b/src/Kestrel.Core/Internal/Http2/Http2OutputProducer.cs @@ -30,7 +30,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 // TODO: RST_STREAM? } - public Task WriteAsync(Action callback, T state) + public Task WriteAsync(Func callback, T state) { throw new NotImplementedException(); } diff --git a/src/Kestrel.Core/Internal/HttpConnection.cs b/src/Kestrel.Core/Internal/HttpConnection.cs index d57a7f920c..5673485d77 100644 --- a/src/Kestrel.Core/Internal/HttpConnection.cs +++ b/src/Kestrel.Core/Internal/HttpConnection.cs @@ -370,6 +370,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal public void Tick(DateTimeOffset now) { + if (_protocolSelectionState == ProtocolSelectionState.Stopped) + { + // It's safe to check for timeouts on a dead connection, + // but try not to in order to avoid extraneous logs. + return; + } + var timestamp = now.Ticks; CheckForTimeout(timestamp); @@ -554,17 +561,27 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal if (minResponseDataRate != null) { - var timeoutTicks = Math.Max( + // Add Heartbeat.Interval since this can be called right before the next heartbeat. + var currentTimeUpperBound = _lastTimestamp + Heartbeat.Interval.Ticks; + var ticksToCompleteWriteAtMinRate = TimeSpan.FromSeconds(size / minResponseDataRate.BytesPerSecond).Ticks; + + // If ticksToCompleteWriteAtMinRate is less than the configured grace period, + // allow that write to take up to the grace period to complete. Only add the grace period + // to the current time and not to any accumulated timeout. + var singleWriteTimeoutTimestamp = currentTimeUpperBound + Math.Max( minResponseDataRate.GracePeriod.Ticks, - TimeSpan.FromSeconds(size / minResponseDataRate.BytesPerSecond).Ticks); + ticksToCompleteWriteAtMinRate); - if (_writeTimingWrites == 0) - { - // Add Heartbeat.Interval since this can be called right before the next heartbeat. - _writeTimingTimeoutTimestamp = _lastTimestamp + Heartbeat.Interval.Ticks; - } + // Don't penalize a connection for completing previous writes more quickly than required. + // We don't want to kill a connection when flushing the chunk terminator just because the previous + // chunk was large if the previous chunk was flushed quickly. - _writeTimingTimeoutTimestamp += timeoutTicks; + // Don't add any grace period to this accumulated timeout because the grace period could + // get accumulated repeatedly making the timeout for a bunch of consecutive small writes + // far too conservative. + var accumulatedWriteTimeoutTimestamp = _writeTimingTimeoutTimestamp + ticksToCompleteWriteAtMinRate; + + _writeTimingTimeoutTimestamp = Math.Max(singleWriteTimeoutTimestamp, accumulatedWriteTimeoutTimestamp); _writeTimingWrites++; } } diff --git a/src/Kestrel.Core/Properties/AssemblyInfo.cs b/src/Kestrel.Core/Properties/AssemblyInfo.cs index 27495d5268..6898d541a6 100644 --- a/src/Kestrel.Core/Properties/AssemblyInfo.cs +++ b/src/Kestrel.Core/Properties/AssemblyInfo.cs @@ -10,3 +10,4 @@ using System.Runtime.CompilerServices; [assembly: InternalsVisibleTo("Kestrel.Performance, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")] [assembly: InternalsVisibleTo("Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")] [assembly: InternalsVisibleTo("Http2SampleApp, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")] +[assembly: InternalsVisibleTo("PlatformBenchmarks, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")] diff --git a/src/Kestrel.Transport.Abstractions/Internal/IBytesWrittenFeature.cs b/src/Kestrel.Transport.Abstractions/Internal/IBytesWrittenFeature.cs new file mode 100644 index 0000000000..e4bf998f37 --- /dev/null +++ b/src/Kestrel.Transport.Abstractions/Internal/IBytesWrittenFeature.cs @@ -0,0 +1,13 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; +using System.Collections.Generic; +using System.Text; + +namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal +{ + public interface IBytesWrittenFeature + { + long TotalBytesWritten { get; } + } +} diff --git a/src/Kestrel.Transport.Abstractions/Internal/TransportConnection.Features.cs b/src/Kestrel.Transport.Abstractions/Internal/TransportConnection.Features.cs index 8ab96ba108..4b65762f30 100644 --- a/src/Kestrel.Transport.Abstractions/Internal/TransportConnection.Features.cs +++ b/src/Kestrel.Transport.Abstractions/Internal/TransportConnection.Features.cs @@ -4,8 +4,9 @@ using System.Collections; using System.Collections.Generic; using System.IO.Pipelines; using System.Net; -using Microsoft.AspNetCore.Http.Features; +using System.Threading; using Microsoft.AspNetCore.Connections.Features; +using Microsoft.AspNetCore.Http.Features; namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal { @@ -16,7 +17,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal IConnectionItemsFeature, IMemoryPoolFeature, IApplicationTransportFeature, - ITransportSchedulerFeature + ITransportSchedulerFeature, + IConnectionLifetimeFeature, + IBytesWrittenFeature { private static readonly Type IHttpConnectionFeatureType = typeof(IHttpConnectionFeature); private static readonly Type IConnectionIdFeatureType = typeof(IConnectionIdFeature); @@ -25,6 +28,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal private static readonly Type IMemoryPoolFeatureType = typeof(IMemoryPoolFeature); private static readonly Type IApplicationTransportFeatureType = typeof(IApplicationTransportFeature); private static readonly Type ITransportSchedulerFeatureType = typeof(ITransportSchedulerFeature); + private static readonly Type IConnectionLifetimeFeatureType = typeof(IConnectionLifetimeFeature); + private static readonly Type IBytesWrittenFeatureType = typeof(IBytesWrittenFeature); private object _currentIHttpConnectionFeature; private object _currentIConnectionIdFeature; @@ -33,6 +38,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal private object _currentIMemoryPoolFeature; private object _currentIApplicationTransportFeature; private object _currentITransportSchedulerFeature; + private object _currentIConnectionLifetimeFeature; + private object _currentIBytesWrittenFeature; private int _featureRevision; @@ -127,6 +134,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal set => Items = value; } + CancellationToken IConnectionLifetimeFeature.ConnectionClosed + { + get => ConnectionClosed; + set => ConnectionClosed = value; + } + + void IConnectionLifetimeFeature.Abort() => Abort(); + + long IBytesWrittenFeature.TotalBytesWritten => TotalBytesWritten; + PipeScheduler ITransportSchedulerFeature.InputWriterScheduler => InputWriterScheduler; PipeScheduler ITransportSchedulerFeature.OutputReaderScheduler => OutputReaderScheduler; @@ -169,6 +186,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal return _currentITransportSchedulerFeature; } + if (key == IConnectionLifetimeFeatureType) + { + return _currentIConnectionLifetimeFeature; + } + + if (key == IBytesWrittenFeatureType) + { + return _currentIBytesWrittenFeature; + } + if (MaybeExtra != null) { return ExtraFeatureGet(key); @@ -208,6 +235,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal { _currentITransportSchedulerFeature = value; } + else if (key == IConnectionLifetimeFeatureType) + { + _currentIConnectionLifetimeFeature = value; + } + else if (key == IBytesWrittenFeatureType) + { + _currentIBytesWrittenFeature = value; + } else { ExtraFeatureSet(key, value); @@ -245,6 +280,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal { return (TFeature)_currentITransportSchedulerFeature; } + else if (typeof(TFeature) == typeof(IConnectionLifetimeFeature)) + { + return (TFeature)_currentIConnectionLifetimeFeature; + } + else if (typeof(TFeature) == typeof(IBytesWrittenFeature)) + { + return (TFeature)_currentIBytesWrittenFeature; + } else if (MaybeExtra != null) { return (TFeature)ExtraFeatureGet(typeof(TFeature)); @@ -285,6 +328,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal { _currentITransportSchedulerFeature = instance; } + else if (typeof(TFeature) == typeof(IConnectionLifetimeFeature)) + { + _currentIConnectionLifetimeFeature = instance; + } + else if (typeof(TFeature) == typeof(IBytesWrittenFeature)) + { + _currentIBytesWrittenFeature = instance; + } else { ExtraFeatureSet(typeof(TFeature), instance); @@ -332,6 +383,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal yield return new KeyValuePair(ITransportSchedulerFeatureType, _currentITransportSchedulerFeature); } + if (_currentIConnectionLifetimeFeature != null) + { + yield return new KeyValuePair(IConnectionLifetimeFeatureType, _currentIConnectionLifetimeFeature); + } + + if (_currentIBytesWrittenFeature != null) + { + yield return new KeyValuePair(IBytesWrittenFeatureType, _currentIBytesWrittenFeature); + } + if (MaybeExtra != null) { foreach (var item in MaybeExtra) diff --git a/src/Kestrel.Transport.Abstractions/Internal/TransportConnection.cs b/src/Kestrel.Transport.Abstractions/Internal/TransportConnection.cs index c3d014ea57..5791033da6 100644 --- a/src/Kestrel.Transport.Abstractions/Internal/TransportConnection.cs +++ b/src/Kestrel.Transport.Abstractions/Internal/TransportConnection.cs @@ -8,7 +8,7 @@ using Microsoft.AspNetCore.Http.Features; namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal { - public abstract partial class TransportConnection : ConnectionContext + public partial class TransportConnection : ConnectionContext { private IDictionary _items; @@ -21,6 +21,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal _currentIApplicationTransportFeature = this; _currentIMemoryPoolFeature = this; _currentITransportSchedulerFeature = this; + _currentIConnectionLifetimeFeature = this; + _currentIBytesWrittenFeature = this; } public IPAddress RemoteAddress { get; set; } @@ -35,6 +37,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal public virtual MemoryPool MemoryPool { get; } public virtual PipeScheduler InputWriterScheduler { get; } public virtual PipeScheduler OutputReaderScheduler { get; } + public virtual long TotalBytesWritten { get; } public override IDuplexPipe Transport { get; set; } public IDuplexPipe Application { get; set; } @@ -54,5 +57,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal public PipeWriter Input => Application.Output; public PipeReader Output => Application.Input; + + public CancellationToken ConnectionClosed { get; set; } + + public virtual void Abort() + { + } } } diff --git a/src/Kestrel.Transport.Libuv/Internal/LibuvConnection.cs b/src/Kestrel.Transport.Libuv/Internal/LibuvConnection.cs index 21e3a6805e..6277cb32d2 100644 --- a/src/Kestrel.Transport.Libuv/Internal/LibuvConnection.cs +++ b/src/Kestrel.Transport.Libuv/Internal/LibuvConnection.cs @@ -25,6 +25,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal (handle, suggestedsize, state) => AllocCallback(handle, suggestedsize, state); private readonly UvStreamHandle _socket; + private readonly CancellationTokenSource _connectionClosedTokenSource = new CancellationTokenSource(); private MemoryHandle _bufferHandle; @@ -42,6 +43,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal LocalAddress = localEndPoint.Address; LocalPort = localEndPoint.Port; + + ConnectionClosed = _connectionClosedTokenSource.Token; } } @@ -51,6 +54,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal private IConnectionDispatcher ConnectionDispatcher => ListenerContext.TransportContext.ConnectionDispatcher; private LibuvThread Thread => ListenerContext.Thread; + public override long TotalBytesWritten => OutputConsumer?.TotalBytesWritten ?? 0; + public async Task Start() { try @@ -89,6 +94,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal // We're done with the socket now _socket.Dispose(); + ThreadPool.QueueUserWorkItem(state => ((LibuvConnection)state).CancelConnectionClosedToken(), this); } } catch (Exception e) @@ -97,6 +103,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal } } + public override void Abort() + { + // This cancels any pending I/O. + Thread.Post(s => s.Dispose(), _socket); + } + // Called on Libuv thread private static LibuvFunctions.uv_buf_t AllocCallback(UvStreamHandle handle, int suggestedSize, object state) { @@ -203,5 +215,18 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal Input.Complete(error); } } + + private void CancelConnectionClosedToken() + { + try + { + _connectionClosedTokenSource.Cancel(); + _connectionClosedTokenSource.Dispose(); + } + catch (Exception ex) + { + Log.LogError(0, ex, $"Unexpected exception in {nameof(LibuvConnection)}.{nameof(CancelConnectionClosedToken)}."); + } + } } } diff --git a/src/Kestrel.Transport.Libuv/Internal/LibuvConnectionContext.cs b/src/Kestrel.Transport.Libuv/Internal/LibuvConnectionContext.cs index 1f2abb9f37..15f2e9d9b2 100644 --- a/src/Kestrel.Transport.Libuv/Internal/LibuvConnectionContext.cs +++ b/src/Kestrel.Transport.Libuv/Internal/LibuvConnectionContext.cs @@ -3,7 +3,6 @@ using System.Buffers; using System.IO.Pipelines; -using System.Threading; using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal diff --git a/src/Kestrel.Transport.Libuv/Internal/LibuvOutputConsumer.cs b/src/Kestrel.Transport.Libuv/Internal/LibuvOutputConsumer.cs index cb60e9a2e0..94195a3ffc 100644 --- a/src/Kestrel.Transport.Libuv/Internal/LibuvOutputConsumer.cs +++ b/src/Kestrel.Transport.Libuv/Internal/LibuvOutputConsumer.cs @@ -3,6 +3,7 @@ using System; using System.IO.Pipelines; +using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking; @@ -16,6 +17,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal private readonly ILibuvTrace _log; private readonly PipeReader _pipe; + private long _totalBytesWritten; + public LibuvOutputConsumer( PipeReader pipe, LibuvThread thread, @@ -28,10 +31,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal _socket = socket; _connectionId = connectionId; _log = log; - - _pipe.OnWriterCompleted(OnWriterCompleted, this); } + public long TotalBytesWritten => Interlocked.Read(ref _totalBytesWritten); + public async Task WriteOutputAsync() { var pool = _thread.WriteReqPool; @@ -46,7 +49,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal } catch { - // Handled in OnWriterCompleted + // Handled in LibuvConnection.Abort() return; } @@ -73,6 +76,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal var writeResult = await writeReq.WriteAsync(_socket, buffer); + // This is not interlocked because there could be a concurrent writer. + // Instead it's to prevent read tearing on 32-bit systems. + Interlocked.Add(ref _totalBytesWritten, buffer.Length); + LogWriteInfo(writeResult.Status, writeResult.Error); if (writeResult.Error != null) @@ -85,6 +92,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal { // Make sure we return the writeReq to the pool pool.Return(writeReq); + + // Null out writeReq so it doesn't get caught by CheckUvReqLeaks. + // It is rooted by a TestSink scope through Pipe continuations in + // ResponseTests.HttpsConnectionClosedWhenResponseDoesNotSatisfyMinimumDataRate + writeReq = null; } } else if (result.IsCompleted) @@ -99,16 +111,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal } } - private static void OnWriterCompleted(Exception ex, object state) - { - // Cut off writes if the writer is completed with an error. If a write request is pending, this will cancel it. - if (ex != null) - { - var libuvOutputConsumer = (LibuvOutputConsumer)state; - libuvOutputConsumer._socket.Dispose(); - } - } - private void LogWriteInfo(int status, Exception error) { if (error == null) diff --git a/src/Kestrel.Transport.Sockets/Internal/SocketConnection.cs b/src/Kestrel.Transport.Sockets/Internal/SocketConnection.cs index a8b66a579c..8f39a08540 100644 --- a/src/Kestrel.Transport.Sockets/Internal/SocketConnection.cs +++ b/src/Kestrel.Transport.Sockets/Internal/SocketConnection.cs @@ -9,6 +9,7 @@ using System.IO.Pipelines; using System.Net; using System.Net.Sockets; using System.Runtime.InteropServices; +using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Connections; using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; @@ -26,8 +27,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal private readonly ISocketsTrace _trace; private readonly SocketReceiver _receiver; private readonly SocketSender _sender; + private readonly CancellationTokenSource _connectionClosedTokenSource = new CancellationTokenSource(); + private readonly object _shutdownLock = new object(); private volatile bool _aborted; + private long _totalBytesWritten; internal SocketConnection(Socket socket, MemoryPool memoryPool, PipeScheduler scheduler, ISocketsTrace trace) { @@ -49,6 +53,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal RemoteAddress = remoteEndPoint.Address; RemotePort = remoteEndPoint.Port; + ConnectionClosed = _connectionClosedTokenSource.Token; + // On *nix platforms, Sockets already dispatches to the ThreadPool. var awaiterScheduler = IsWindows ? _scheduler : PipeScheduler.Inline; @@ -59,6 +65,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal public override MemoryPool MemoryPool { get; } public override PipeScheduler InputWriterScheduler => _scheduler; public override PipeScheduler OutputReaderScheduler => _scheduler; + public override long TotalBytesWritten => Interlocked.Read(ref _totalBytesWritten); public async Task StartAsync(IConnectionDispatcher connectionDispatcher) { @@ -88,6 +95,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal _socket.Dispose(); _receiver.Dispose(); _sender.Dispose(); + ThreadPool.QueueUserWorkItem(state => ((SocketConnection)state).CancelConnectionClosedToken(), this); } catch (Exception ex) { @@ -100,6 +108,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal } } + public override void Abort() + { + // Try to gracefully close the socket to match libuv behavior. + Shutdown(); + _socket.Dispose(); + } + private async Task DoReceive() { Exception error = null; @@ -216,15 +231,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal { error = new IOException(ex.Message, ex); } - finally - { - // Make sure to close the connection only after the _aborted flag is set. - // Without this, the RequestsCanBeAbortedMidRead test will sometimes fail when - // a BadHttpRequestException is thrown instead of a TaskCanceledException. - _aborted = true; - _trace.ConnectionWriteFin(ConnectionId); - _socket.Shutdown(SocketShutdown.Both); - } + + Shutdown(); return error; } @@ -249,6 +257,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal await _sender.SendAsync(buffer); } + // This is not interlocked because there could be a concurrent writer. + // Instead it's to prevent read tearing on 32-bit systems. + Interlocked.Add(ref _totalBytesWritten, buffer.Length); + Output.AdvanceTo(end); if (isCompleted) @@ -257,5 +269,36 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal } } } + + private void Shutdown() + { + lock (_shutdownLock) + { + if (!_aborted) + { + // Make sure to close the connection only after the _aborted flag is set. + // Without this, the RequestsCanBeAbortedMidRead test will sometimes fail when + // a BadHttpRequestException is thrown instead of a TaskCanceledException. + _aborted = true; + _trace.ConnectionWriteFin(ConnectionId); + + // Try to gracefully close the socket even for aborts to match libuv behavior. + _socket.Shutdown(SocketShutdown.Both); + } + } + } + + private void CancelConnectionClosedToken() + { + try + { + _connectionClosedTokenSource.Cancel(); + _connectionClosedTokenSource.Dispose(); + } + catch (Exception ex) + { + _trace.LogError(0, ex, $"Unexpected exception in {nameof(SocketConnection)}.{nameof(CancelConnectionClosedToken)}."); + } + } } } diff --git a/test/Kestrel.Core.Tests/ConnectionDispatcherTests.cs b/test/Kestrel.Core.Tests/ConnectionDispatcherTests.cs index 9f53e16750..24f8ded379 100644 --- a/test/Kestrel.Core.Tests/ConnectionDispatcherTests.cs +++ b/test/Kestrel.Core.Tests/ConnectionDispatcherTests.cs @@ -1,13 +1,10 @@ -using System.Buffers; +using System; +using System.Buffers; using System.Collections.Generic; using System.IO.Pipelines; using System.Linq; -using System.Threading; using System.Threading.Tasks; -using Microsoft.AspNetCore.Http.Features; -using Microsoft.AspNetCore.Connections.Features; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal; -using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; using Microsoft.AspNetCore.Testing; using Xunit; @@ -23,7 +20,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests var tcs = new TaskCompletionSource(); var dispatcher = new ConnectionDispatcher(serviceContext, _ => tcs.Task); - var connection = new TestConnection(); + var connection = new TransportConnection(); dispatcher.OnConnection(connection); @@ -44,14 +41,5 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests // Verify the scope was disposed after request processing completed Assert.True(((TestKestrelTrace)serviceContext.Log).Logger.Scopes.IsEmpty); } - - private class TestConnection : TransportConnection - { - public override MemoryPool MemoryPool { get; } = KestrelMemoryPool.Create(); - - public override PipeScheduler InputWriterScheduler => PipeScheduler.ThreadPool; - - public override PipeScheduler OutputReaderScheduler => PipeScheduler.ThreadPool; - } } } diff --git a/test/Kestrel.Core.Tests/Http1ConnectionTests.cs b/test/Kestrel.Core.Tests/Http1ConnectionTests.cs index 9d69dc79df..ffff5b1bcf 100644 --- a/test/Kestrel.Core.Tests/Http1ConnectionTests.cs +++ b/test/Kestrel.Core.Tests/Http1ConnectionTests.cs @@ -11,6 +11,7 @@ using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; +using Microsoft.AspNetCore.Connections.Features; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Server.Kestrel.Core.Features; @@ -48,12 +49,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests _transport = pair.Transport; _application = pair.Application; + var connectionFeatures = new FeatureCollection(); + connectionFeatures.Set(Mock.Of()); + connectionFeatures.Set(Mock.Of()); + _serviceContext = new TestServiceContext(); _timeoutControl = new Mock(); _http1ConnectionContext = new Http1ConnectionContext { ServiceContext = _serviceContext, - ConnectionFeatures = new FeatureCollection(), + ConnectionFeatures = connectionFeatures, MemoryPool = _pipelineFactory, TimeoutControl = _timeoutControl.Object, Application = pair.Application, @@ -727,8 +732,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests Assert.Equal(header0Count + header1Count, _http1Connection.RequestHeaders.Count); await _application.Output.WriteAsync(Encoding.ASCII.GetBytes("\r\n")); - Assert.Equal(header0Count + header1Count, _http1Connection.RequestHeaders.Count); - await requestProcessingTask.TimeoutAfter(TestConstants.DefaultTimeout); } @@ -767,9 +770,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests Assert.Equal(header0Count + header1Count, _http1Connection.RequestHeaders.Count); await _application.Output.WriteAsync(Encoding.ASCII.GetBytes("\r\n")); - Assert.Same(newRequestHeaders, _http1Connection.RequestHeaders); - Assert.Equal(header0Count + header1Count, _http1Connection.RequestHeaders.Count); - await requestProcessingTask.TimeoutAfter(TimeSpan.FromSeconds(10)); } diff --git a/test/Kestrel.Core.Tests/HttpConnectionTests.cs b/test/Kestrel.Core.Tests/HttpConnectionTests.cs index 8710055844..85243bd7ff 100644 --- a/test/Kestrel.Core.Tests/HttpConnectionTests.cs +++ b/test/Kestrel.Core.Tests/HttpConnectionTests.cs @@ -6,6 +6,8 @@ using System.Buffers; using System.Collections.Generic; using System.IO.Pipelines; using System.Threading; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Connections.Features; using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal; @@ -29,11 +31,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests var options = new PipeOptions(_memoryPool, readerScheduler: PipeScheduler.Inline, writerScheduler: PipeScheduler.Inline, useSynchronizationContext: false); var pair = DuplexPipe.CreateConnectionPair(options, options); + var connectionFeatures = new FeatureCollection(); + connectionFeatures.Set(Mock.Of()); + connectionFeatures.Set(Mock.Of()); + _httpConnectionContext = new HttpConnectionContext { ConnectionId = "0123456789", ConnectionAdapters = new List(), - ConnectionFeatures = new FeatureCollection(), + ConnectionFeatures = connectionFeatures, MemoryPool = _memoryPool, HttpConnectionId = long.MinValue, Application = pair.Application, @@ -531,5 +537,56 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests Assert.True(_httpConnection.RequestTimedOut); Assert.True(aborted.Wait(TimeSpan.FromSeconds(10))); } + + [Fact] + public async Task WriteTimingAbortsConnectionWhenRepeadtedSmallWritesDoNotCompleteWithMinimumDataRate() + { + var systemClock = new MockSystemClock(); + var minResponseDataRate = new MinDataRate(bytesPerSecond: 100, gracePeriod: TimeSpan.FromSeconds(5)); + var numWrites = 5; + var writeSize = 100; + var aborted = new TaskCompletionSource(); + + _httpConnectionContext.ServiceContext.ServerOptions.Limits.MinResponseDataRate = minResponseDataRate; + _httpConnectionContext.ServiceContext.SystemClock = systemClock; + + var mockLogger = new Mock(); + _httpConnectionContext.ServiceContext.Log = mockLogger.Object; + + _httpConnection.Initialize(_httpConnectionContext.Transport, _httpConnectionContext.Application); + _httpConnection.Http1Connection.Reset(); + _httpConnection.Http1Connection.RequestAborted.Register(() => + { + aborted.SetResult(null); + }); + + // Initialize timestamp + var startTime = systemClock.UtcNow; + _httpConnection.Tick(startTime); + + // 5 consecutive 100 byte writes. + for (var i = 0; i < numWrites - 1; i++) + { + _httpConnection.StartTimingWrite(writeSize); + _httpConnection.StopTimingWrite(); + } + + // Stall the last write. + _httpConnection.StartTimingWrite(writeSize); + + // Move the clock forward Heartbeat.Interval + MinDataRate.GracePeriod + 4 seconds. + // The grace period should only be added for the first write. The subsequent 4 100 byte writes should add 1 second each to the timeout given the 100 byte/s min rate. + systemClock.UtcNow += Heartbeat.Interval + minResponseDataRate.GracePeriod + TimeSpan.FromSeconds((numWrites - 1) * writeSize / minResponseDataRate.BytesPerSecond); + _httpConnection.Tick(systemClock.UtcNow); + + Assert.False(_httpConnection.RequestTimedOut); + + // On more tick forward triggers the timeout. + systemClock.UtcNow += TimeSpan.FromTicks(1); + _httpConnection.Tick(systemClock.UtcNow); + + Assert.True(_httpConnection.RequestTimedOut); + await aborted.Task.TimeoutAfter(TimeSpan.FromSeconds(10)); + } } } diff --git a/test/Kestrel.Core.Tests/OutputProducerTests.cs b/test/Kestrel.Core.Tests/OutputProducerTests.cs index dc063922ff..3f9750a11e 100644 --- a/test/Kestrel.Core.Tests/OutputProducerTests.cs +++ b/test/Kestrel.Core.Tests/OutputProducerTests.cs @@ -5,6 +5,7 @@ using System; using System.Buffers; using System.IO.Pipelines; using System.Threading; +using Microsoft.AspNetCore.Connections.Features; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; @@ -49,6 +50,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests socketOutput.Write((buffer, state) => { called = true; + return 0; }, 0); @@ -56,8 +58,33 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests } } - private Http1OutputProducer CreateOutputProducer(PipeOptions pipeOptions) + [Fact] + public void AbortsTransportEvenAfterDispose() { + var mockLifetimeFeature = new Mock(); + + var outputProducer = CreateOutputProducer(lifetimeFeature: mockLifetimeFeature.Object); + + outputProducer.Dispose(); + + mockLifetimeFeature.Verify(f => f.Abort(), Times.Never()); + + outputProducer.Abort(null); + + mockLifetimeFeature.Verify(f => f.Abort(), Times.Once()); + + outputProducer.Abort(null); + + mockLifetimeFeature.Verify(f => f.Abort(), Times.Once()); + } + + private Http1OutputProducer CreateOutputProducer( + PipeOptions pipeOptions = null, + IConnectionLifetimeFeature lifetimeFeature = null) + { + pipeOptions = pipeOptions ?? new PipeOptions(); + lifetimeFeature = lifetimeFeature ?? Mock.Of(); + var pipe = new Pipe(pipeOptions); var serviceContext = new TestServiceContext(); var socketOutput = new Http1OutputProducer( @@ -65,7 +92,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests pipe.Writer, "0", serviceContext.Log, - Mock.Of()); + Mock.Of(), + lifetimeFeature, + Mock.Of()); return socketOutput; } diff --git a/test/Kestrel.Core.Tests/PipelineExtensionTests.cs b/test/Kestrel.Core.Tests/PipelineExtensionTests.cs index e3a89832da..43c385772e 100644 --- a/test/Kestrel.Core.Tests/PipelineExtensionTests.cs +++ b/test/Kestrel.Core.Tests/PipelineExtensionTests.cs @@ -36,7 +36,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests public void WritesNumericToAscii(ulong number) { var writerBuffer = _pipe.Writer; - var writer = new BufferWriter(writerBuffer); + var writer = new CountingBufferWriter(writerBuffer); writer.WriteNumeric(number); writer.Commit(); writerBuffer.FlushAsync().GetAwaiter().GetResult(); @@ -54,7 +54,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests public void WritesNumericAcrossSpanBoundaries(int gapSize) { var writerBuffer = _pipe.Writer; - var writer = new BufferWriter(writerBuffer); + var writer = new CountingBufferWriter(writerBuffer); // almost fill up the first block var spacer = new byte[writer.Span.Length - gapSize]; writer.Write(spacer); @@ -85,7 +85,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests public void EncodesAsAscii(string input, byte[] expected) { var pipeWriter = _pipe.Writer; - var writer = new BufferWriter(pipeWriter); + var writer = new CountingBufferWriter(pipeWriter); writer.WriteAsciiNoValidation(input); writer.Commit(); pipeWriter.FlushAsync().GetAwaiter().GetResult(); @@ -115,7 +115,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests // WriteAscii doesn't validate if characters are in the ASCII range // but it shouldn't produce more than one byte per character var writerBuffer = _pipe.Writer; - var writer = new BufferWriter(writerBuffer); + var writer = new CountingBufferWriter(writerBuffer); writer.WriteAsciiNoValidation(input); writer.Commit(); writerBuffer.FlushAsync().GetAwaiter().GetResult(); @@ -129,7 +129,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests { const byte maxAscii = 0x7f; var writerBuffer = _pipe.Writer; - var writer = new BufferWriter(writerBuffer); + var writer = new CountingBufferWriter(writerBuffer); for (var i = 0; i < maxAscii; i++) { writer.WriteAsciiNoValidation(new string((char)i, 1)); @@ -159,7 +159,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests { var testString = new string(' ', stringLength); var writerBuffer = _pipe.Writer; - var writer = new BufferWriter(writerBuffer); + var writer = new CountingBufferWriter(writerBuffer); // almost fill up the first block var spacer = new byte[writer.Span.Length - gapSize]; writer.Write(spacer); diff --git a/test/Kestrel.Core.Tests/TestInput.cs b/test/Kestrel.Core.Tests/TestInput.cs index 1295121548..0552801d37 100644 --- a/test/Kestrel.Core.Tests/TestInput.cs +++ b/test/Kestrel.Core.Tests/TestInput.cs @@ -6,6 +6,7 @@ using System.Buffers; using System.IO.Pipelines; using System.Text; using System.Threading.Tasks; +using Microsoft.AspNetCore.Connections.Features; using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; @@ -27,10 +28,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests Transport = pair.Transport; Application = pair.Application; + var connectionFeatures = new FeatureCollection(); + connectionFeatures.Set(Mock.Of()); + connectionFeatures.Set(Mock.Of()); + Http1ConnectionContext = new Http1ConnectionContext { ServiceContext = new TestServiceContext(), - ConnectionFeatures = new FeatureCollection(), + ConnectionFeatures = connectionFeatures, Application = Application, Transport = Transport, MemoryPool = _memoryPool, diff --git a/test/Kestrel.FunctionalTests/HttpsTests.cs b/test/Kestrel.FunctionalTests/HttpsTests.cs index eda9cbb5e6..b20b3c5874 100644 --- a/test/Kestrel.FunctionalTests/HttpsTests.cs +++ b/test/Kestrel.FunctionalTests/HttpsTests.cs @@ -234,7 +234,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests var request = Encoding.ASCII.GetBytes("GET / HTTP/1.1\r\nHost:\r\n\r\n"); await sslStream.WriteAsync(request, 0, request.Length); - await sslStream.ReadAsync(new byte[32], 0, 32); + + // Temporary workaround for a deadlock when reading from an aborted client SslStream on Mac and Linux. + if (TestPlatformHelper.IsWindows) + { + await sslStream.ReadAsync(new byte[32], 0, 32); + } + else + { + await stream.ReadAsync(new byte[32], 0, 32); + } } } @@ -285,7 +294,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests var request = Encoding.ASCII.GetBytes("GET / HTTP/1.1\r\nHost:\r\n\r\n"); await sslStream.WriteAsync(request, 0, request.Length); - await sslStream.ReadAsync(new byte[32], 0, 32); + + // Temporary workaround for a deadlock when reading from an aborted client SslStream on Mac and Linux. + if (TestPlatformHelper.IsWindows) + { + await sslStream.ReadAsync(new byte[32], 0, 32); + } + else + { + await stream.ReadAsync(new byte[32], 0, 32); + } } } diff --git a/test/Kestrel.FunctionalTests/RequestTests.cs b/test/Kestrel.FunctionalTests/RequestTests.cs index e7cadd4ae8..63868ad897 100644 --- a/test/Kestrel.FunctionalTests/RequestTests.cs +++ b/test/Kestrel.FunctionalTests/RequestTests.cs @@ -15,10 +15,11 @@ using System.Text; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Connections; +using Microsoft.AspNetCore.Connections.Features; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http.Features; -using Microsoft.AspNetCore.Connections; using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.AspNetCore.Server.Kestrel.Core.Features; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; @@ -571,6 +572,108 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } } + [Theory] + [MemberData(nameof(ConnectionAdapterData))] + public async Task ConnectionClosedTokenFiresOnClientFIN(ListenOptions listenOptions) + { + var testContext = new TestServiceContext(LoggerFactory); + var appStartedTcs = new TaskCompletionSource(); + var connectionClosedTcs = new TaskCompletionSource(); + + using (var server = new TestServer(context => + { + appStartedTcs.SetResult(null); + + var connectionLifetimeFeature = context.Features.Get(); + connectionLifetimeFeature.ConnectionClosed.Register(() => connectionClosedTcs.SetResult(null)); + + return Task.CompletedTask; + }, testContext, listenOptions)) + { + using (var connection = server.CreateConnection()) + { + await connection.Send( + "GET / HTTP/1.1", + "Host:", + "", + ""); + + await appStartedTcs.Task.TimeoutAfter(TestConstants.DefaultTimeout); + + connection.Socket.Shutdown(SocketShutdown.Send); + + await connectionClosedTcs.Task.TimeoutAfter(TestConstants.DefaultTimeout); + } + } + } + + [Theory] + [MemberData(nameof(ConnectionAdapterData))] + public async Task ConnectionClosedTokenFiresOnServerFIN(ListenOptions listenOptions) + { + var testContext = new TestServiceContext(LoggerFactory); + var connectionClosedTcs = new TaskCompletionSource(); + + using (var server = new TestServer(context => + { + var connectionLifetimeFeature = context.Features.Get(); + connectionLifetimeFeature.ConnectionClosed.Register(() => connectionClosedTcs.SetResult(null)); + + return Task.CompletedTask; + }, testContext, listenOptions)) + { + using (var connection = server.CreateConnection()) + { + await connection.Send( + "GET / HTTP/1.1", + "Host:", + "Connection: close", + "", + ""); + + await connectionClosedTcs.Task.TimeoutAfter(TestConstants.DefaultTimeout); + + await connection.ReceiveEnd($"HTTP/1.1 200 OK", + "Connection: close", + $"Date: {server.Context.DateHeaderValue}", + "Content-Length: 0", + "", + ""); + } + } + } + + [Theory] + [MemberData(nameof(ConnectionAdapterData))] + public async Task ConnectionClosedTokenFiresOnServerAbort(ListenOptions listenOptions) + { + var testContext = new TestServiceContext(LoggerFactory); + var connectionClosedTcs = new TaskCompletionSource(); + + using (var server = new TestServer(context => + { + var connectionLifetimeFeature = context.Features.Get(); + connectionLifetimeFeature.ConnectionClosed.Register(() => connectionClosedTcs.SetResult(null)); + + context.Abort(); + + return Task.CompletedTask; + }, testContext, listenOptions)) + { + using (var connection = server.CreateConnection()) + { + await connection.Send( + "GET / HTTP/1.1", + "Host:", + "", + ""); + + await connectionClosedTcs.Task.TimeoutAfter(TestConstants.DefaultTimeout); + await connection.ReceiveForcedEnd(); + } + } + } + [Theory] [InlineData("http://localhost/abs/path", "/abs/path", null)] [InlineData("https://localhost/abs/path", "/abs/path", null)] // handles mismatch scheme diff --git a/test/Kestrel.FunctionalTests/ResponseTests.cs b/test/Kestrel.FunctionalTests/ResponseTests.cs index 961d670e23..6c85955a3e 100644 --- a/test/Kestrel.FunctionalTests/ResponseTests.cs +++ b/test/Kestrel.FunctionalTests/ResponseTests.cs @@ -21,7 +21,6 @@ using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal; -using Microsoft.AspNetCore.Server.Kestrel.Core.Internal; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Https; @@ -1635,7 +1634,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } [Fact] - public async Task Sending100ContinueDoesNotStartResponse() + public async Task Sending100ContinueDoesNotPreventAutomatic400Responses() { using (var server = new TestServer(httpContext => { @@ -1656,29 +1655,21 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests "HTTP/1.1 100 Continue", "", ""); - - // Let the app finish - await connection.Send( - "1", - "a", - ""); - - await connection.Receive( - "HTTP/1.1 200 OK", - $"Date: {server.Context.DateHeaderValue}", - "Content-Length: 0", - "", - ""); - - // This will be consumed by Http1Connection when it attempts to - // consume the request body and will cause an error. + + // Send an invalid chunk prefix to cause an error. await connection.Send( "gg"); // If 100 Continue sets HttpProtocol.HasResponseStarted to true, // a success response will be produced before the server sees the // bad chunk header above, making this test fail. - await connection.ReceiveEnd(); + await connection.ReceiveForcedEnd( + "HTTP/1.1 400 Bad Request", + "Connection: close", + $"Date: {server.Context.DateHeaderValue}", + "Content-Length: 0", + "", + ""); } } @@ -2569,21 +2560,27 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } [Fact] - public void ConnectionClosedWhenResponseDoesNotSatisfyMinimumDataRate() + public async Task ConnectionClosedWhenResponseDoesNotSatisfyMinimumDataRate() { using (StartLog(out var loggerFactory, "ConnClosedWhenRespDoesNotSatisfyMin")) { var logger = loggerFactory.CreateLogger($"{ typeof(ResponseTests).FullName}.{ nameof(ConnectionClosedWhenResponseDoesNotSatisfyMinimumDataRate)}"); - var chunkSize = 64 * 1024; - var chunks = 128; + const int chunkSize = 1024; + const int chunks = 256 * 1024; var responseSize = chunks * chunkSize; + var chunkData = new byte[chunkSize]; - var requestAborted = new ManualResetEventSlim(); - var messageLogged = new ManualResetEventSlim(); - var mockKestrelTrace = new Mock(loggerFactory.CreateLogger("Microsoft.AspNetCore.Server.Kestrel")) { CallBase = true }; + var responseRateTimeoutMessageLogged = new TaskCompletionSource(); + var connectionStopMessageLogged = new TaskCompletionSource(); + var requestAborted = new TaskCompletionSource(); + + var mockKestrelTrace = new Mock(); mockKestrelTrace .Setup(trace => trace.ResponseMininumDataRateNotSatisfied(It.IsAny(), It.IsAny())) - .Callback(() => messageLogged.Set()); + .Callback(() => responseRateTimeoutMessageLogged.SetResult(null)); + mockKestrelTrace + .Setup(trace => trace.ConnectionStop(It.IsAny())) + .Callback(() => connectionStopMessageLogged.SetResult(null));; var testContext = new TestServiceContext { @@ -2606,57 +2603,41 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests async Task App(HttpContext context) { appLogger.LogInformation("Request received"); - context.RequestAborted.Register(() => requestAborted.Set()); + context.RequestAborted.Register(() => requestAborted.SetResult(null)); context.Response.ContentLength = responseSize; for (var i = 0; i < chunks; i++) { - await context.Response.WriteAsync(new string('a', chunkSize), context.RequestAborted); + await context.Response.Body.WriteAsync(chunkData, 0, chunkData.Length, context.RequestAborted); appLogger.LogInformation("Wrote chunk of {chunkSize} bytes", chunkSize); } } using (var server = new TestServer(App, testContext, listenOptions)) { - using (var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)) + using (var connection = server.CreateConnection()) { - socket.ReceiveBufferSize = 1; - - socket.Connect(new IPEndPoint(IPAddress.Loopback, server.Port)); logger.LogInformation("Sending request"); - socket.Send(Encoding.ASCII.GetBytes("GET / HTTP/1.1\r\nHost: \r\n\r\n")); + await connection.Send( + "GET / HTTP/1.1", + "Host:", + "", + ""); + logger.LogInformation("Sent request"); var sw = Stopwatch.StartNew(); logger.LogInformation("Waiting for connection to abort."); - Assert.True(messageLogged.Wait(TimeSpan.FromSeconds(120)), "The expected message was not logged within the timeout period."); - Assert.True(requestAborted.Wait(TimeSpan.FromSeconds(120)), "The request was not aborted within the timeout period."); + + await requestAborted.Task.TimeoutAfter(TimeSpan.FromSeconds(60)); + await responseRateTimeoutMessageLogged.Task.TimeoutAfter(TimeSpan.FromSeconds(10)); + await connectionStopMessageLogged.Task.TimeoutAfter(TimeSpan.FromSeconds(10)); + + await AssertStreamAborted(connection.Reader.BaseStream, chunkSize * chunks); + sw.Stop(); logger.LogInformation("Connection was aborted after {totalMilliseconds}ms.", sw.ElapsedMilliseconds); - - var totalReceived = 0; - var received = 0; - - try - { - var buffer = new byte[chunkSize]; - - do - { - received = socket.Receive(buffer); - totalReceived += received; - } while (received > 0 && totalReceived < responseSize); - } - catch (SocketException) { } - catch (IOException) - { - // Socket.Receive could throw, and that is fine - } - - // Since we expect writes to be cut off by the rate control, we should never see the entire response - logger.LogInformation("Received {totalReceived} bytes", totalReceived); - Assert.NotEqual(responseSize, totalReceived); } } } @@ -2665,18 +2646,23 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [Fact] public async Task HttpsConnectionClosedWhenResponseDoesNotSatisfyMinimumDataRate() { - const int chunkSize = 64 * 1024; - const int chunks = 128; + const int chunkSize = 1024; + const int chunks = 256 * 1024; + var chunkData = new byte[chunkSize]; var certificate = new X509Certificate2(TestResources.TestCertificatePath, "testPassword"); - var messageLogged = new ManualResetEventSlim(); - var aborted = new ManualResetEventSlim(); + var responseRateTimeoutMessageLogged = new TaskCompletionSource(); + var connectionStopMessageLogged = new TaskCompletionSource(); + var aborted = new TaskCompletionSource(); var mockKestrelTrace = new Mock(); mockKestrelTrace .Setup(trace => trace.ResponseMininumDataRateNotSatisfied(It.IsAny(), It.IsAny())) - .Callback(() => messageLogged.Set()); + .Callback(() => responseRateTimeoutMessageLogged.SetResult(null)); + mockKestrelTrace + .Setup(trace => trace.ConnectionStop(It.IsAny())) + .Callback(() => connectionStopMessageLogged.SetResult(null)); var testContext = new TestServiceContext(LoggerFactory, mockKestrelTrace.Object) { @@ -2702,41 +2688,183 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { context.RequestAborted.Register(() => { - aborted.Set(); + aborted.SetResult(null); }); context.Response.ContentLength = chunks * chunkSize; for (var i = 0; i < chunks; i++) { - await context.Response.WriteAsync(new string('a', chunkSize), context.RequestAborted); + await context.Response.Body.WriteAsync(chunkData, 0, chunkData.Length, context.RequestAborted); } }, testContext, listenOptions)) { - using (var client = new TcpClient()) + using (var connection = server.CreateConnection()) { - await client.ConnectAsync(IPAddress.Loopback, server.Port); - - using (var sslStream = new SslStream(client.GetStream(), false, (sender, cert, chain, errors) => true, null)) + using (var sslStream = new SslStream(connection.Reader.BaseStream, false, (sender, cert, chain, errors) => true, null)) { await sslStream.AuthenticateAsClientAsync("localhost", new X509CertificateCollection(), SslProtocols.Tls12 | SslProtocols.Tls11, false); var request = Encoding.ASCII.GetBytes("GET / HTTP/1.1\r\nHost:\r\n\r\n"); await sslStream.WriteAsync(request, 0, request.Length); - Assert.True(aborted.Wait(TimeSpan.FromSeconds(60))); + await aborted.Task.TimeoutAfter(TimeSpan.FromSeconds(60)); + await responseRateTimeoutMessageLogged.Task.TimeoutAfter(TimeSpan.FromSeconds(10)); + await connectionStopMessageLogged.Task.TimeoutAfter(TimeSpan.FromSeconds(10)); - using (var reader = new StreamReader(sslStream, encoding: Encoding.ASCII, detectEncodingFromByteOrderMarks: false, bufferSize: 1024, leaveOpen: false)) + // Temporary workaround for a deadlock when reading from an aborted client SslStream on Mac and Linux. + if (TestPlatformHelper.IsWindows) { - await reader.ReadToEndAsync().TimeoutAfter(TestConstants.DefaultTimeout); + await AssertStreamAborted(sslStream, chunkSize * chunks); + } + else + { + await AssertStreamAborted(connection.Reader.BaseStream, chunkSize * chunks); } - - Assert.True(messageLogged.Wait(TestConstants.DefaultTimeout)); } } } } + [Fact] + public async Task ConnectionNotClosedWhenClientSatisfiesMinimumDataRateGivenLargeResponseChunks() + { + var chunkSize = 64 * 128 * 1024; + var chunkCount = 4; + var chunkData = new byte[chunkSize]; + + var requestAborted = false; + var mockKestrelTrace = new Mock(); + + var testContext = new TestServiceContext + { + Log = mockKestrelTrace.Object, + SystemClock = new SystemClock(), + ServerOptions = + { + Limits = + { + MinResponseDataRate = new MinDataRate(bytesPerSecond: 240, gracePeriod: TimeSpan.FromSeconds(2)) + } + } + }; + + var listenOptions = new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0)); + + async Task App(HttpContext context) + { + context.RequestAborted.Register(() => + { + requestAborted = true; + }); + + for (var i = 0; i < chunkCount; i++) + { + await context.Response.Body.WriteAsync(chunkData, 0, chunkData.Length, context.RequestAborted); + } + } + + using (var server = new TestServer(App, testContext, listenOptions)) + { + using (var connection = server.CreateConnection()) + { + // Close the connection with the last request so AssertStreamCompleted actually completes. + await connection.Send( + "GET / HTTP/1.1", + "Host:", + "Connection: close", + "", + ""); + + var minTotalOutputSize = chunkCount * chunkSize; + + // Make sure consuming a single chunk exceeds the 2 second timeout. + var targetBytesPerSecond = chunkSize / 4; + await AssertStreamCompleted(connection.Reader.BaseStream, minTotalOutputSize, targetBytesPerSecond); + + mockKestrelTrace.Verify(t => t.ResponseMininumDataRateNotSatisfied(It.IsAny(), It.IsAny()), Times.Never()); + mockKestrelTrace.Verify(t => t.ConnectionStop(It.IsAny()), Times.Once()); + Assert.False(requestAborted); + } + } + } + + [Fact] + public async Task ConnectionNotClosedWhenClientSatisfiesMinimumDataRateGivenLargeResponseHeaders() + { + var headerSize = 1024 * 1024; // 1 MB for each header value + var headerCount = 64; // 64 MB of headers per response + var requestCount = 4; // Minimum of 256 MB of total response headers + var headerValue = new string('a', headerSize); + var headerStringValues = new StringValues(Enumerable.Repeat(headerValue, headerCount).ToArray()); + + var requestAborted = false; + var mockKestrelTrace = new Mock(); + + var testContext = new TestServiceContext + { + Log = mockKestrelTrace.Object, + SystemClock = new SystemClock(), + ServerOptions = + { + Limits = + { + MinResponseDataRate = new MinDataRate(bytesPerSecond: 240, gracePeriod: TimeSpan.FromSeconds(2)) + } + } + }; + + var listenOptions = new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0)); + + async Task App(HttpContext context) + { + context.RequestAborted.Register(() => + { + requestAborted = true; + }); + + context.Response.Headers[$"X-Custom-Header"] = headerStringValues; + context.Response.ContentLength = 0; + + await context.Response.Body.FlushAsync(); + } + + using (var server = new TestServer(App, testContext, listenOptions)) + { + using (var connection = server.CreateConnection()) + { + for (var i = 0; i < requestCount - 1; i++) + { + await connection.Send( + "GET / HTTP/1.1", + "Host:", + "", + ""); + } + + // Close the connection with the last request so AssertStreamCompleted actually completes. + await connection.Send( + "GET / HTTP/1.1", + "Host:", + "Connection: close", + "", + ""); + + var responseSize = headerSize * headerCount; + var minTotalOutputSize = requestCount * responseSize; + + // Make sure consuming a single set of response headers exceeds the 2 second timeout. + var targetBytesPerSecond = responseSize / 4; + await AssertStreamCompleted(connection.Reader.BaseStream, minTotalOutputSize, targetBytesPerSecond); + + mockKestrelTrace.Verify(t => t.ResponseMininumDataRateNotSatisfied(It.IsAny(), It.IsAny()), Times.Never()); + mockKestrelTrace.Verify(t => t.ConnectionStop(It.IsAny()), Times.Once()); + Assert.False(requestAborted); + } + } + } + + [Fact] public async Task NonZeroContentLengthFor304StatusCodeIsAllowed() { @@ -2766,6 +2894,56 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } } + private async Task AssertStreamAborted(Stream stream, int totalBytes) + { + var receiveBuffer = new byte[64 * 1024]; + var totalReceived = 0; + + try + { + while (totalReceived < totalBytes) + { + var bytes = await stream.ReadAsync(receiveBuffer, 0, receiveBuffer.Length).TimeoutAfter(TimeSpan.FromSeconds(10)); + + if (bytes == 0) + { + break; + } + + totalReceived += bytes; + } + } + catch (IOException) + { + // This is expected given an abort. + } + + Assert.True(totalReceived < totalBytes, $"{nameof(AssertStreamAborted)} Stream completed successfully."); + } + + private async Task AssertStreamCompleted(Stream stream, long minimumBytes, int targetBytesPerSecond) + { + var receiveBuffer = new byte[64 * 1024]; + var received = 0; + var totalReceived = 0; + var startTime = DateTimeOffset.UtcNow; + + do + { + received = await stream.ReadAsync(receiveBuffer, 0, receiveBuffer.Length); + totalReceived += received; + + var expectedTimeElapsed = TimeSpan.FromSeconds(totalReceived / targetBytesPerSecond); + var timeElapsed = DateTimeOffset.UtcNow - startTime; + if (timeElapsed < expectedTimeElapsed) + { + await Task.Delay(expectedTimeElapsed - timeElapsed); + } + } while (received > 0); + + Assert.True(totalReceived >= minimumBytes, $"{nameof(AssertStreamCompleted)} Stream aborted prematurely."); + } + public static TheoryData NullHeaderData { get diff --git a/test/Kestrel.Transport.Libuv.Tests/LibuvOutputConsumerTests.cs b/test/Kestrel.Transport.Libuv.Tests/LibuvOutputConsumerTests.cs index ef024facfb..e269bda59c 100644 --- a/test/Kestrel.Transport.Libuv.Tests/LibuvOutputConsumerTests.cs +++ b/test/Kestrel.Transport.Libuv.Tests/LibuvOutputConsumerTests.cs @@ -7,6 +7,7 @@ using System.Collections.Concurrent; using System.IO.Pipelines; using System.Threading; using System.Threading.Tasks; +using Microsoft.AspNetCore.Connections.Features; using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; @@ -304,6 +305,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests outputProducer.Write((writableBuffer, state) => { writableBuffer.Write(state); + return state.Count; }, halfWriteBehindBuffer); @@ -729,10 +731,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests var socket = new MockSocket(_mockLibuv, _libuvThread.Loop.ThreadId, transportContext.Log); var consumer = new LibuvOutputConsumer(pair.Application.Input, _libuvThread, socket, "0", transportContext.Log); + var connectionFeatures = new FeatureCollection(); + connectionFeatures.Set(Mock.Of()); + connectionFeatures.Set(Mock.Of()); + var http1Connection = new Http1Connection(new Http1ConnectionContext { ServiceContext = serviceContext, - ConnectionFeatures = new FeatureCollection(), + ConnectionFeatures = connectionFeatures, MemoryPool = _memoryPool, TimeoutControl = Mock.Of(), Application = pair.Application, diff --git a/tools/CodeGenerator/KnownHeaders.cs b/tools/CodeGenerator/KnownHeaders.cs index 08646dc61a..badf9087a7 100644 --- a/tools/CodeGenerator/KnownHeaders.cs +++ b/tools/CodeGenerator/KnownHeaders.cs @@ -548,7 +548,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http return true; }} {(loop.ClassName == "HttpResponseHeaders" ? $@" - internal void CopyToFast(ref BufferWriter output) + internal void CopyToFast(ref CountingBufferWriter output) {{ var tempBits = _bits | (_contentLength.HasValue ? {1L << 63}L : 0); {Each(loop.Headers.Where(header => header.Identifier != "ContentLength").OrderBy(h => !h.PrimaryHeader), header => $@" From 0b44bf52f543d98d19c74fee4ed7a774151a66cc Mon Sep 17 00:00:00 2001 From: "Nate McMaster (automated)" Date: Mon, 30 Apr 2018 14:51:42 -0700 Subject: [PATCH 1631/1662] Bump version to 2.1.0-rtm --- version.props | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version.props b/version.props index e27532787e..b9552451d8 100644 --- a/version.props +++ b/version.props @@ -1,7 +1,7 @@ 2.1.0 - rc1 + rtm $(VersionPrefix) $(VersionPrefix)-$(VersionSuffix)-final t000 From 74d19cd4e49897da5251cdaec3bdc946167be160 Mon Sep 17 00:00:00 2001 From: "Chris Ross (ASP.NET)" Date: Wed, 2 May 2018 08:54:57 -0700 Subject: [PATCH 1632/1662] Remove netcoreapp2.0 test coverage --- test/Directory.Build.props | 2 +- test/Kestrel.Core.Tests/HttpRequestStreamTests.cs | 2 +- test/Kestrel.FunctionalTests/GeneratedCodeTests.cs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/test/Directory.Build.props b/test/Directory.Build.props index 3110e89ce7..44033a6dc3 100644 --- a/test/Directory.Build.props +++ b/test/Directory.Build.props @@ -4,7 +4,7 @@ netcoreapp2.1 $(DeveloperBuildTestTfms) - netcoreapp2.1;netcoreapp2.0 + netcoreapp2.1 $(StandardTestTfms);net461 diff --git a/test/Kestrel.Core.Tests/HttpRequestStreamTests.cs b/test/Kestrel.Core.Tests/HttpRequestStreamTests.cs index 8bff09b8a7..1ffa74b027 100644 --- a/test/Kestrel.Core.Tests/HttpRequestStreamTests.cs +++ b/test/Kestrel.Core.Tests/HttpRequestStreamTests.cs @@ -92,7 +92,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests var stream = new HttpRequestStream(Mock.Of()); Assert.Throws(() => stream.BeginWrite(new byte[1], 0, 1, null, null)); } -#elif NETCOREAPP2_0 || NETCOREAPP2_1 +#elif NETCOREAPP2_1 #else #error Target framework needs to be updated #endif diff --git a/test/Kestrel.FunctionalTests/GeneratedCodeTests.cs b/test/Kestrel.FunctionalTests/GeneratedCodeTests.cs index 2b7b1b6a99..bcf34ccaf9 100644 --- a/test/Kestrel.FunctionalTests/GeneratedCodeTests.cs +++ b/test/Kestrel.FunctionalTests/GeneratedCodeTests.cs @@ -1,7 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -#if NETCOREAPP2_0 || NETCOREAPP2_1 +#if NETCOREAPP2_1 using System.IO; using Xunit; From b85ab0a7d2d272591b45ac4cba01407f975ef8b2 Mon Sep 17 00:00:00 2001 From: "Chris Ross (ASP.NET)" Date: Mon, 26 Mar 2018 12:50:36 -0700 Subject: [PATCH 1633/1662] Fix Sending100ContinueDoesNotStartResponse #2507 --- test/Kestrel.FunctionalTests/ResponseTests.cs | 29 +++++++++++++++---- 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/test/Kestrel.FunctionalTests/ResponseTests.cs b/test/Kestrel.FunctionalTests/ResponseTests.cs index 961d670e23..cec6547cfd 100644 --- a/test/Kestrel.FunctionalTests/ResponseTests.cs +++ b/test/Kestrel.FunctionalTests/ResponseTests.cs @@ -1635,8 +1635,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } [Fact] - public async Task Sending100ContinueDoesNotStartResponse() + public async Task RequestDrainingFor100ContinueDoesNotBlockResponse() { + var foundMessage = false; using (var server = new TestServer(httpContext => { return httpContext.Request.Body.ReadAsync(new byte[1], 0, 1); @@ -1675,15 +1676,31 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests await connection.Send( "gg"); - // If 100 Continue sets HttpProtocol.HasResponseStarted to true, - // a success response will be produced before the server sees the - // bad chunk header above, making this test fail. + // Wait for the server to drain the request body and log an error. + // Time out after 10 seconds + for (int i = 0; i < 10 && !foundMessage; i++) + { + while (TestApplicationErrorLogger.Messages.TryDequeue(out var message)) + { + if (message.EventId.Id == 17 && message.LogLevel == LogLevel.Information && message.Exception is BadHttpRequestException + && ((BadHttpRequestException)message.Exception).StatusCode == StatusCodes.Status400BadRequest) + { + foundMessage = true; + break; + } + } + + if (!foundMessage) + { + await Task.Delay(TimeSpan.FromSeconds(1)); + } + } + await connection.ReceiveEnd(); } } - Assert.Contains(TestApplicationErrorLogger.Messages, w => w.EventId.Id == 17 && w.LogLevel == LogLevel.Information && w.Exception is BadHttpRequestException - && ((BadHttpRequestException)w.Exception).StatusCode == StatusCodes.Status400BadRequest); + Assert.True(foundMessage, "Expected log not found"); } [Fact] From 8d0d46f10de9b09738892ab53d63db07a80f86e6 Mon Sep 17 00:00:00 2001 From: "ASP.NET CI" Date: Fri, 4 May 2018 07:41:43 -0700 Subject: [PATCH 1634/1662] Update dependencies.props [auto-updated: dependencies] --- build/dependencies.props | 66 ++++++++++++++++++++-------------------- korebuild-lock.txt | 4 +-- 2 files changed, 35 insertions(+), 35 deletions(-) diff --git a/build/dependencies.props b/build/dependencies.props index 9290b0d72e..b27f54b527 100644 --- a/build/dependencies.props +++ b/build/dependencies.props @@ -5,44 +5,44 @@ 0.10.13 - 2.1.0-rc1-15774 + 2.1.0-rtm-15783 1.10.0 - 2.1.0-rc1-30613 - 2.1.0-rc1-30613 - 2.1.0-rc1-30613 - 2.1.0-rc1-30613 - 2.1.0-rc1-30613 - 2.1.0-rc1-30613 - 2.1.0-rc1-30613 - 2.1.0-rc1-30613 - 2.1.0-rc1-30613 - 2.1.0-rc1-30613 - 2.1.0-rc1-30613 - 2.1.0-rc1-30613 - 2.1.0-rc1-30613 - 2.1.0-rc1-30613 - 2.1.0-rc1-30613 - 2.1.0-rc1-30613 - 2.1.0-rc1-30613 - 2.1.0-rc1-30613 - 2.1.0-rc1-30613 - 2.1.0-rc1-30613 - 2.1.0-rc1-30613 - 2.1.0-rc1-30613 + 2.1.0-rtm-30721 + 2.1.0-rtm-30721 + 2.1.0-rtm-30721 + 2.1.0-rtm-30721 + 2.1.0-rtm-30721 + 2.1.0-rtm-30721 + 2.1.0-rtm-30721 + 2.1.0-rtm-30721 + 2.1.0-rtm-30721 + 2.1.0-rtm-30721 + 2.1.0-rtm-30721 + 2.1.0-rtm-30721 + 2.1.0-rtm-30721 + 2.1.0-rtm-30721 + 2.1.0-rtm-30721 + 2.1.0-rtm-30721 + 2.1.0-rtm-30721 + 2.1.0-rtm-30721 + 2.1.0-rtm-30721 + 2.1.0-rtm-30721 + 2.1.0-rtm-30721 + 2.1.0-rtm-30721 2.0.0 - 2.1.0-rc1-26419-02 - 2.1.0-rc1-30613 + 2.1.0-rtm-26502-02 + 2.1.0-rtm-30721 15.6.1 4.7.49 - 2.0.1 + 2.0.3 11.0.2 - 4.5.0-rc1-26419-03 - 4.5.0-rc1-26419-03 - 4.5.0-rc1-26419-03 - 4.5.0-rc1-26419-03 - 4.5.0-rc1-26419-03 - 4.5.0-rc1-26419-03 - 4.5.0-rc1-26419-03 + 4.5.0-rtm-26502-02 + 4.5.0-rtm-26502-02 + 4.5.0-rtm-26502-02 + 4.5.0-rtm-26502-02 + 4.5.0-rtm-26502-02 + 4.5.0-rtm-26502-02 + 4.5.0-rtm-26502-02 1.3.7 0.8.0 2.3.1 diff --git a/korebuild-lock.txt b/korebuild-lock.txt index 9d4ef8c888..3673744db9 100644 --- a/korebuild-lock.txt +++ b/korebuild-lock.txt @@ -1,2 +1,2 @@ -version:2.1.0-rc1-15774 -commithash:ed5ca9de3c652347dbb0158a9a65eff3471d2114 +version:2.1.0-rtm-15783 +commithash:5fc2b2f607f542a2ffde11c19825e786fc1a3774 From 5c17bff55d018946572245c435a0361bde06ffd1 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Fri, 4 May 2018 16:21:07 -0700 Subject: [PATCH 1635/1662] Don't throw on FIN from upgraded connections (#2533) * Allow app to drain request buffer after FIN --- .../Internal/Http/Http1MessageBody.cs | 8 ++++ .../Http/HttpProtocol.FeatureCollection.cs | 3 +- .../Internal/Http/HttpProtocol.cs | 28 +++++++++----- test/Kestrel.Core.Tests/MessageBodyTests.cs | 2 +- test/Kestrel.FunctionalTests/UpgradeTests.cs | 37 +++++++++++++++++++ 5 files changed, 66 insertions(+), 12 deletions(-) diff --git a/src/Kestrel.Core/Internal/Http/Http1MessageBody.cs b/src/Kestrel.Core/Internal/Http/Http1MessageBody.cs index c47bf114b6..d65805cc83 100644 --- a/src/Kestrel.Core/Internal/Http/Http1MessageBody.cs +++ b/src/Kestrel.Core/Internal/Http/Http1MessageBody.cs @@ -89,6 +89,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http } else if (result.IsCompleted) { + // Treat any FIN from an upgraded request as expected. + // It's up to higher-level consumer (i.e. WebSocket middleware) to determine + // if the end is actually expected based on higher-level framing. + if (RequestUpgrade) + { + break; + } + BadHttpRequestException.Throw(RequestRejectionReason.UnexpectedEndOfRequestContent); } diff --git a/src/Kestrel.Core/Internal/Http/HttpProtocol.FeatureCollection.cs b/src/Kestrel.Core/Internal/Http/HttpProtocol.FeatureCollection.cs index 055e8a1e76..3c53523f8a 100644 --- a/src/Kestrel.Core/Internal/Http/HttpProtocol.FeatureCollection.cs +++ b/src/Kestrel.Core/Internal/Http/HttpProtocol.FeatureCollection.cs @@ -8,6 +8,7 @@ using System.IO; using System.Net; using System.Threading; using System.Threading.Tasks; +using Microsoft.AspNetCore.Connections; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Server.Kestrel.Core.Features; @@ -282,7 +283,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http void IHttpRequestLifetimeFeature.Abort() { - Abort(error: null); + Abort(new ConnectionAbortedException()); } } } diff --git a/src/Kestrel.Core/Internal/Http/HttpProtocol.cs b/src/Kestrel.Core/Internal/Http/HttpProtocol.cs index 7db0062a15..95b716abf9 100644 --- a/src/Kestrel.Core/Internal/Http/HttpProtocol.cs +++ b/src/Kestrel.Core/Internal/Http/HttpProtocol.cs @@ -411,21 +411,29 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http } /// - /// Immediate kill the connection and poison the request and response streams. + /// Immediately kill the connection and poison the request and response streams with an error if there is one. /// public void Abort(Exception error) { - if (Interlocked.Exchange(ref _requestAborted, 1) == 0) + if (Interlocked.Exchange(ref _requestAborted, 1) != 0) { - _keepAlive = false; - - _streams?.Abort(error); - - Output.Abort(error); - - // Potentially calling user code. CancelRequestAbortedToken logs any exceptions. - ServiceContext.Scheduler.Schedule(state => ((HttpProtocol)state).CancelRequestAbortedToken(), this); + return; } + + _keepAlive = false; + + // If Abort() isn't called with an exception, there was a FIN. In this case, even though the connection is + // still closed immediately, we allow the app to drain the data in the request buffer. If the request data + // was truncated, MessageBody will complete the RequestBodyPipe with an error. + if (error != null) + { + _streams?.Abort(error); + } + + Output.Abort(error); + + // Potentially calling user code. CancelRequestAbortedToken logs any exceptions. + ServiceContext.Scheduler.Schedule(state => ((HttpProtocol)state).CancelRequestAbortedToken(), this); } public void OnHeader(Span name, Span value) diff --git a/test/Kestrel.Core.Tests/MessageBodyTests.cs b/test/Kestrel.Core.Tests/MessageBodyTests.cs index fb2d8613db..f472269e6c 100644 --- a/test/Kestrel.Core.Tests/MessageBodyTests.cs +++ b/test/Kestrel.Core.Tests/MessageBodyTests.cs @@ -786,7 +786,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests input.Fin(); - await Assert.ThrowsAsync(async () => await body.ReadAsync(new ArraySegment(new byte[1]))); + Assert.Equal(0, await body.ReadAsync(new ArraySegment(new byte[1]))); mockTimeoutControl.Verify(timeoutControl => timeoutControl.StartTimingReads(), Times.Never); mockTimeoutControl.Verify(timeoutControl => timeoutControl.StopTimingReads(), Times.Never); diff --git a/test/Kestrel.FunctionalTests/UpgradeTests.cs b/test/Kestrel.FunctionalTests/UpgradeTests.cs index 5d89707335..6a839aaad3 100644 --- a/test/Kestrel.FunctionalTests/UpgradeTests.cs +++ b/test/Kestrel.FunctionalTests/UpgradeTests.cs @@ -297,5 +297,42 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests var exception = await Assert.ThrowsAsync(async () => await upgradeTcs.Task.TimeoutAfter(TimeSpan.FromSeconds(60))); Assert.Equal(CoreStrings.UpgradedConnectionLimitReached, exception.Message); } + + [Fact] + public async Task DoesNotThrowOnFin() + { + var appCompletedTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + + using (var server = new TestServer(async context => + { + var feature = context.Features.Get(); + var duplexStream = await feature.UpgradeAsync(); + + try + { + await duplexStream.CopyToAsync(Stream.Null); + appCompletedTcs.SetResult(null); + } + catch (Exception ex) + { + appCompletedTcs.SetException(ex); + throw; + } + + }, new TestServiceContext(LoggerFactory))) + { + using (var connection = server.CreateConnection()) + { + await connection.SendEmptyGetWithUpgrade(); + await connection.Receive("HTTP/1.1 101 Switching Protocols", + "Connection: Upgrade", + $"Date: {server.Context.DateHeaderValue}", + "", + ""); + } + + await appCompletedTcs.Task.TimeoutAfter(TestConstants.DefaultTimeout); + } + } } } From 1a313715c87033380b80290453bf9ac8a86c84dd Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Mon, 7 May 2018 14:59:08 -0700 Subject: [PATCH 1636/1662] Merge fixup --- test/Kestrel.FunctionalTests/ResponseTests.cs | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/test/Kestrel.FunctionalTests/ResponseTests.cs b/test/Kestrel.FunctionalTests/ResponseTests.cs index 7339aaf7ab..bc940be76b 100644 --- a/test/Kestrel.FunctionalTests/ResponseTests.cs +++ b/test/Kestrel.FunctionalTests/ResponseTests.cs @@ -1657,7 +1657,21 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests "", ""); - // Send an invalid chunk prefix to cause an error. + // Let the app finish + await connection.Send( + "1", + "a", + ""); + + await connection.Receive( + "HTTP/1.1 200 OK", + $"Date: {server.Context.DateHeaderValue}", + "Content-Length: 0", + "", + ""); + + // This will be consumed by Http1Connection when it attempts to + // consume the request body and will cause an error. await connection.Send( "gg"); @@ -1691,7 +1705,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [Fact] public async Task Sending100ContinueDoesNotPreventAutomatic400Responses() { - var foundMessage = false; using (var server = new TestServer(httpContext => { return httpContext.Request.Body.ReadAsync(new byte[1], 0, 1); @@ -1729,7 +1742,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } } - Assert.True(foundMessage, "Expected log not found"); + Assert.Contains(TestApplicationErrorLogger.Messages, w => w.EventId.Id == 17 && w.LogLevel == LogLevel.Information && w.Exception is BadHttpRequestException + && ((BadHttpRequestException)w.Exception).StatusCode == StatusCodes.Status400BadRequest); } [Fact] From e6a88c1b9c44a62f7d96437527f55e88aacdce26 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Thu, 10 May 2018 17:13:57 -0700 Subject: [PATCH 1637/1662] Relieve response backpressure immediately when closing socket (#2557) * Relieve response backpressure immediately when closing socket --- .../Internal/SocketConnection.cs | 44 ++---- test/Kestrel.FunctionalTests/ResponseTests.cs | 131 ++++++++++++++++-- test/shared/TestConnection.cs | 2 + 3 files changed, 135 insertions(+), 42 deletions(-) diff --git a/src/Kestrel.Transport.Sockets/Internal/SocketConnection.cs b/src/Kestrel.Transport.Sockets/Internal/SocketConnection.cs index 8f39a08540..d410599663 100644 --- a/src/Kestrel.Transport.Sockets/Internal/SocketConnection.cs +++ b/src/Kestrel.Transport.Sockets/Internal/SocketConnection.cs @@ -20,7 +20,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal internal sealed class SocketConnection : TransportConnection { private static readonly int MinAllocBufferSize = KestrelMemoryPool.MinimumSegmentSize / 2; - private static readonly bool IsWindows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows); private readonly Socket _socket; private readonly PipeScheduler _scheduler; @@ -55,11 +54,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal ConnectionClosed = _connectionClosedTokenSource.Token; - // On *nix platforms, Sockets already dispatches to the ThreadPool. - var awaiterScheduler = IsWindows ? _scheduler : PipeScheduler.Inline; - - _receiver = new SocketReceiver(_socket, awaiterScheduler); - _sender = new SocketSender(_socket, awaiterScheduler); + _receiver = new SocketReceiver(_socket, _scheduler); + _sender = new SocketSender(_socket, _scheduler); } public override MemoryPool MemoryPool { get; } @@ -69,30 +65,18 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal public async Task StartAsync(IConnectionDispatcher connectionDispatcher) { - Exception sendError = null; try { connectionDispatcher.OnConnection(this); // Spawn send and receive logic - Task receiveTask = DoReceive(); - Task sendTask = DoSend(); - - // If the sending task completes then close the receive - // We don't need to do this in the other direction because the kestrel - // will trigger the output closing once the input is complete. - if (await Task.WhenAny(receiveTask, sendTask) == sendTask) - { - // Tell the reader it's being aborted - _socket.Dispose(); - } + var receiveTask = DoReceive(); + var sendTask = DoSend(); // Now wait for both to complete await receiveTask; - sendError = await sendTask; + await sendTask; - // Dispose the socket(should noop if already called) - _socket.Dispose(); _receiver.Dispose(); _sender.Dispose(); ThreadPool.QueueUserWorkItem(state => ((SocketConnection)state).CancelConnectionClosedToken(), this); @@ -101,18 +85,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal { _trace.LogError(0, ex, $"Unexpected exception in {nameof(SocketConnection)}.{nameof(StartAsync)}."); } - finally - { - // Complete the output after disposing the socket - Output.Complete(sendError); - } } public override void Abort() { // Try to gracefully close the socket to match libuv behavior. Shutdown(); - _socket.Dispose(); } private async Task DoReceive() @@ -207,7 +185,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal } } - private async Task DoSend() + private async Task DoSend() { Exception error = null; @@ -231,10 +209,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal { error = new IOException(ex.Message, ex); } + finally + { + Shutdown(); - Shutdown(); - - return error; + // Complete the output after disposing the socket + Output.Complete(error); + } } private async Task ProcessSends() @@ -284,6 +265,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal // Try to gracefully close the socket even for aborts to match libuv behavior. _socket.Shutdown(SocketShutdown.Both); + _socket.Dispose(); } } } diff --git a/test/Kestrel.FunctionalTests/ResponseTests.cs b/test/Kestrel.FunctionalTests/ResponseTests.cs index bc940be76b..72fe4d1ba2 100644 --- a/test/Kestrel.FunctionalTests/ResponseTests.cs +++ b/test/Kestrel.FunctionalTests/ResponseTests.cs @@ -2642,6 +2642,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests var responseRateTimeoutMessageLogged = new TaskCompletionSource(); var connectionStopMessageLogged = new TaskCompletionSource(); var requestAborted = new TaskCompletionSource(); + var appFuncCompleted = new TaskCompletionSource(); var mockKestrelTrace = new Mock(); mockKestrelTrace @@ -2649,7 +2650,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests .Callback(() => responseRateTimeoutMessageLogged.SetResult(null)); mockKestrelTrace .Setup(trace => trace.ConnectionStop(It.IsAny())) - .Callback(() => connectionStopMessageLogged.SetResult(null));; + .Callback(() => connectionStopMessageLogged.SetResult(null)); var testContext = new TestServiceContext { @@ -2660,7 +2661,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { Limits = { - MinResponseDataRate = new MinDataRate(bytesPerSecond: double.MaxValue, gracePeriod: TimeSpan.FromSeconds(2)) + MinResponseDataRate = new MinDataRate(bytesPerSecond: 1024 * 1024, gracePeriod: TimeSpan.FromSeconds(2)) } } }; @@ -2676,10 +2677,18 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests context.Response.ContentLength = responseSize; - for (var i = 0; i < chunks; i++) + try { - await context.Response.Body.WriteAsync(chunkData, 0, chunkData.Length, context.RequestAborted); - appLogger.LogInformation("Wrote chunk of {chunkSize} bytes", chunkSize); + for (var i = 0; i < chunks; i++) + { + await context.Response.Body.WriteAsync(chunkData, 0, chunkData.Length, context.RequestAborted); + appLogger.LogInformation("Wrote chunk of {chunkSize} bytes", chunkSize); + } + } + catch (OperationCanceledException) + { + appFuncCompleted.SetResult(null); + throw; } } @@ -2702,7 +2711,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests await requestAborted.Task.TimeoutAfter(TimeSpan.FromSeconds(60)); await responseRateTimeoutMessageLogged.Task.TimeoutAfter(TimeSpan.FromSeconds(10)); await connectionStopMessageLogged.Task.TimeoutAfter(TimeSpan.FromSeconds(10)); - + await appFuncCompleted.Task.TimeoutAfter(TimeSpan.FromSeconds(10)); await AssertStreamAborted(connection.Reader.BaseStream, chunkSize * chunks); sw.Stop(); @@ -2724,6 +2733,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests var responseRateTimeoutMessageLogged = new TaskCompletionSource(); var connectionStopMessageLogged = new TaskCompletionSource(); var aborted = new TaskCompletionSource(); + var appFuncCompleted = new TaskCompletionSource(); var mockKestrelTrace = new Mock(); mockKestrelTrace @@ -2740,7 +2750,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { Limits = { - MinResponseDataRate = new MinDataRate(bytesPerSecond: double.MaxValue, gracePeriod: TimeSpan.FromSeconds(2)) + MinResponseDataRate = new MinDataRate(bytesPerSecond: 1024 * 1024, gracePeriod: TimeSpan.FromSeconds(2)) } } }; @@ -2762,9 +2772,17 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests context.Response.ContentLength = chunks * chunkSize; - for (var i = 0; i < chunks; i++) + try { - await context.Response.Body.WriteAsync(chunkData, 0, chunkData.Length, context.RequestAborted); + for (var i = 0; i < chunks; i++) + { + await context.Response.Body.WriteAsync(chunkData, 0, chunkData.Length, context.RequestAborted); + } + } + catch (OperationCanceledException) + { + appFuncCompleted.SetResult(null); + throw; } }, testContext, listenOptions)) { @@ -2780,6 +2798,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests await aborted.Task.TimeoutAfter(TimeSpan.FromSeconds(60)); await responseRateTimeoutMessageLogged.Task.TimeoutAfter(TimeSpan.FromSeconds(10)); await connectionStopMessageLogged.Task.TimeoutAfter(TimeSpan.FromSeconds(10)); + await appFuncCompleted.Task.TimeoutAfter(TimeSpan.FromSeconds(10)); // Temporary workaround for a deadlock when reading from an aborted client SslStream on Mac and Linux. if (TestPlatformHelper.IsWindows) @@ -2795,6 +2814,93 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } } + [Fact] + public async Task ConnectionClosedWhenBothRequestAndResponseExperienceBackPressure() + { + const int bufferSize = 1024; + const int bufferCount = 256 * 1024; + var responseSize = bufferCount * bufferSize; + var buffer = new byte[bufferSize]; + + var responseRateTimeoutMessageLogged = new TaskCompletionSource(); + var connectionStopMessageLogged = new TaskCompletionSource(); + var requestAborted = new TaskCompletionSource(); + var appFuncCompleted = new TaskCompletionSource(); + + var mockKestrelTrace = new Mock(); + mockKestrelTrace + .Setup(trace => trace.ResponseMininumDataRateNotSatisfied(It.IsAny(), It.IsAny())) + .Callback(() => responseRateTimeoutMessageLogged.SetResult(null)); + mockKestrelTrace + .Setup(trace => trace.ConnectionStop(It.IsAny())) + .Callback(() => connectionStopMessageLogged.SetResult(null)); + + var testContext = new TestServiceContext + { + LoggerFactory = LoggerFactory, + Log = mockKestrelTrace.Object, + SystemClock = new SystemClock(), + ServerOptions = + { + Limits = + { + MinResponseDataRate = new MinDataRate(bytesPerSecond: 1024 * 1024, gracePeriod: TimeSpan.FromSeconds(2)), + MaxRequestBodySize = responseSize + } + } + }; + + var listenOptions = new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0)); + + async Task App(HttpContext context) + { + context.RequestAborted.Register(() => + { + requestAborted.SetResult(null); + }); + + try + { + await context.Request.Body.CopyToAsync(context.Response.Body); + } + catch + { + // This should always throw an OperationCanceledException. Unfortunately a ECONNRESET UvException sometimes gets thrown. + // This will be fixed by https://github.com/aspnet/KestrelHttpServer/pull/2547 + appFuncCompleted.SetResult(null); + throw; + } + } + + using (var server = new TestServer(App, testContext, listenOptions)) + { + using (var connection = server.CreateConnection()) + { + // Close the connection with the last request so AssertStreamCompleted actually completes. + await connection.Send( + "POST / HTTP/1.1", + "Host:", + $"Content-Length: {responseSize}", + "", + ""); + + var sendTask = Task.Run(async () => + { + for (var i = 0; i < bufferCount; i++) + { + await connection.Stream.WriteAsync(buffer, 0, buffer.Length); + } + }); + + await requestAborted.Task.TimeoutAfter(TimeSpan.FromSeconds(60)); + await responseRateTimeoutMessageLogged.Task.TimeoutAfter(TimeSpan.FromSeconds(10)); + await connectionStopMessageLogged.Task.TimeoutAfter(TimeSpan.FromSeconds(10)); + await appFuncCompleted.Task.TimeoutAfter(TimeSpan.FromSeconds(10)); + await AssertStreamAborted(connection.Stream, responseSize); + } + } + } + [Fact] public async Task ConnectionNotClosedWhenClientSatisfiesMinimumDataRateGivenLargeResponseChunks() { @@ -2803,6 +2909,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests var chunkData = new byte[chunkSize]; var requestAborted = false; + var appFuncCompleted = new TaskCompletionSource(); var mockKestrelTrace = new Mock(); var testContext = new TestServiceContext @@ -2831,6 +2938,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { await context.Response.Body.WriteAsync(chunkData, 0, chunkData.Length, context.RequestAborted); } + + appFuncCompleted.SetResult(null); } using (var server = new TestServer(App, testContext, listenOptions)) @@ -2850,6 +2959,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests // Make sure consuming a single chunk exceeds the 2 second timeout. var targetBytesPerSecond = chunkSize / 4; await AssertStreamCompleted(connection.Reader.BaseStream, minTotalOutputSize, targetBytesPerSecond); + await appFuncCompleted.Task.TimeoutAfter(TimeSpan.FromSeconds(10)); mockKestrelTrace.Verify(t => t.ResponseMininumDataRateNotSatisfied(It.IsAny(), It.IsAny()), Times.Never()); mockKestrelTrace.Verify(t => t.ConnectionStop(It.IsAny()), Times.Once()); @@ -2859,7 +2969,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } [Fact] - public async Task ConnectionNotClosedWhenClientSatisfiesMinimumDataRateGivenLargeResponseHeaders() + public async Task ConnectionNotClosedWhenClientSatisfiesMinimumDataRateGivenLargeResponseHeaders() { var headerSize = 1024 * 1024; // 1 MB for each header value var headerCount = 64; // 64 MB of headers per response @@ -2933,7 +3043,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } } - [Fact] public async Task NonZeroContentLengthFor304StatusCodeIsAllowed() { diff --git a/test/shared/TestConnection.cs b/test/shared/TestConnection.cs index fc6458c287..4f65da6bcf 100644 --- a/test/shared/TestConnection.cs +++ b/test/shared/TestConnection.cs @@ -49,6 +49,8 @@ namespace Microsoft.AspNetCore.Testing public Socket Socket => _socket; + public Stream Stream => _stream; + public StreamReader Reader => _reader; public void Dispose() From da21fc89cf9a68a2c86f9fdb77cd6ee813f31d24 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Thu, 10 May 2018 23:39:06 -0700 Subject: [PATCH 1638/1662] Handle exception in SocketConnection.Shutdown() (#2562) --- .../Internal/SocketConnection.cs | 12 +- test/Kestrel.FunctionalTests/RequestTests.cs | 144 ++++++++++++++ test/Kestrel.FunctionalTests/ResponseTests.cs | 180 ++++++++++++++++++ test/shared/PassThroughConnectionAdapter.cs | 139 +++++++++++++- 4 files changed, 472 insertions(+), 3 deletions(-) diff --git a/src/Kestrel.Transport.Sockets/Internal/SocketConnection.cs b/src/Kestrel.Transport.Sockets/Internal/SocketConnection.cs index d410599663..e1f323abba 100644 --- a/src/Kestrel.Transport.Sockets/Internal/SocketConnection.cs +++ b/src/Kestrel.Transport.Sockets/Internal/SocketConnection.cs @@ -263,8 +263,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal _aborted = true; _trace.ConnectionWriteFin(ConnectionId); - // Try to gracefully close the socket even for aborts to match libuv behavior. - _socket.Shutdown(SocketShutdown.Both); + try + { + // Try to gracefully close the socket even for aborts to match libuv behavior. + _socket.Shutdown(SocketShutdown.Both); + } + catch + { + // Ignore any errors from Socket.Shutdown since we're tearing down the connection anyway. + } + _socket.Dispose(); } } diff --git a/test/Kestrel.FunctionalTests/RequestTests.cs b/test/Kestrel.FunctionalTests/RequestTests.cs index 63868ad897..3f82426e5f 100644 --- a/test/Kestrel.FunctionalTests/RequestTests.cs +++ b/test/Kestrel.FunctionalTests/RequestTests.cs @@ -22,6 +22,7 @@ using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.AspNetCore.Server.Kestrel.Core.Features; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; using Microsoft.AspNetCore.Testing; @@ -1208,6 +1209,149 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests Assert.Equal(2, abortedRequestId); } + [Theory] + [MemberData(nameof(ConnectionAdapterData))] + public async Task ServerCanAbortConnectionAfterUnobservedClose(ListenOptions listenOptions) + { + const int connectionPausedEventId = 4; + const int connectionFinSentEventId = 7; + const int maxRequestBufferSize = 4096; + + var readCallbackUnwired = new TaskCompletionSource(TaskContinuationOptions.RunContinuationsAsynchronously); + var clientClosedConnection = new TaskCompletionSource(TaskContinuationOptions.RunContinuationsAsynchronously); + var serverClosedConnection = new TaskCompletionSource(TaskContinuationOptions.RunContinuationsAsynchronously); + var appFuncCompleted = new TaskCompletionSource(TaskContinuationOptions.RunContinuationsAsynchronously); + + var mockLogger = new Mock(); + mockLogger + .Setup(logger => logger.IsEnabled(It.IsAny())) + .Returns(true); + mockLogger + .Setup(logger => logger.Log(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny>())) + .Callback>((logLevel, eventId, state, exception, formatter) => + { + if (eventId.Id == connectionPausedEventId) + { + readCallbackUnwired.TrySetResult(null); + } + else if (eventId.Id == connectionFinSentEventId) + { + serverClosedConnection.SetResult(null); + } + + Logger.Log(logLevel, eventId, state, exception, formatter); + }); + + var mockLoggerFactory = new Mock(); + mockLoggerFactory + .Setup(factory => factory.CreateLogger(It.IsAny())) + .Returns(Logger); + mockLoggerFactory + .Setup(factory => factory.CreateLogger(It.IsIn("Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv", + "Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets"))) + .Returns(mockLogger.Object); + + var mockKestrelTrace = new Mock(Logger) { CallBase = true }; + var testContext = new TestServiceContext(mockLoggerFactory.Object) + { + Log = mockKestrelTrace.Object, + ServerOptions = + { + Limits = + { + MaxRequestBufferSize = maxRequestBufferSize, + MaxRequestLineSize = maxRequestBufferSize, + MaxRequestHeadersTotalSize = maxRequestBufferSize, + } + } + }; + + var scratchBuffer = new byte[maxRequestBufferSize * 2 + 1]; + + using (var server = new TestServer(async context => + { + await clientClosedConnection.Task; + + context.Abort(); + + await serverClosedConnection.Task; + + // TaskContinuationOptions.RunContinuationsAsynchronously sometimes runs inline anyway in + // situations such as this where the awaiter starts awaiting right when SetResult is called. + _ = Task.Run(() => appFuncCompleted.SetResult(null)); + }, testContext, listenOptions)) + { + using (var connection = server.CreateConnection()) + { + await connection.Send( + "POST / HTTP/1.1", + "Host:", + $"Content-Length: {scratchBuffer.Length}", + "", + ""); + + var ignore = connection.Stream.WriteAsync(scratchBuffer, 0, scratchBuffer.Length); + + // Wait until the read callback is no longer hooked up so that the connection disconnect isn't observed. + await readCallbackUnwired.Task.TimeoutAfter(TestConstants.DefaultTimeout); + } + + clientClosedConnection.SetResult(null); + + await appFuncCompleted.Task.TimeoutAfter(TestConstants.DefaultTimeout); + } + + mockKestrelTrace.Verify(t => t.ConnectionStop(It.IsAny()), Times.Once()); + } + + [Theory] + [MemberData(nameof(ConnectionAdapterData))] + public async Task AppCanHandleClientAbortingConnectionMidRequest(ListenOptions listenOptions) + { + var readTcs = new TaskCompletionSource(TaskContinuationOptions.RunContinuationsAsynchronously); + + var mockKestrelTrace = new Mock(Logger) { CallBase = true }; + var testContext = new TestServiceContext() + { + Log = mockKestrelTrace.Object, + }; + + var scratchBuffer = new byte[4096]; + + using (var server = new TestServer(async context => + { + try + { + await context.Request.Body.CopyToAsync(Stream.Null);; + } + catch (Exception ex) + { + readTcs.SetException(ex); + throw; + } + + readTcs.SetException(new Exception("This shouldn't be reached.")); + + }, testContext, listenOptions)) + { + using (var connection = server.CreateConnection()) + { + await connection.Send( + "POST / HTTP/1.1", + "Host:", + $"Content-Length: {scratchBuffer.Length * 2}", + "", + ""); + + await connection.Stream.WriteAsync(scratchBuffer, 0, scratchBuffer.Length); + } + + await Assert.ThrowsAnyAsync(() => readTcs.Task).TimeoutAfter(TestConstants.DefaultTimeout); + } + + mockKestrelTrace.Verify(t => t.ConnectionStop(It.IsAny()), Times.Once()); + } + [Theory] [MemberData(nameof(ConnectionAdapterData))] public async Task RequestHeadersAreResetOnEachRequest(ListenOptions listenOptions) diff --git a/test/Kestrel.FunctionalTests/ResponseTests.cs b/test/Kestrel.FunctionalTests/ResponseTests.cs index 72fe4d1ba2..3e7f4b7d58 100644 --- a/test/Kestrel.FunctionalTests/ResponseTests.cs +++ b/test/Kestrel.FunctionalTests/ResponseTests.cs @@ -21,6 +21,7 @@ using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Https; @@ -2327,6 +2328,185 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } } + [Theory] + [MemberData(nameof(ConnectionAdapterData))] + public async Task WritingToConnectionAfterUnobservedCloseTriggersRequestAbortedToken(ListenOptions listenOptions) + { + const int connectionPausedEventId = 4; + const int maxRequestBufferSize = 2048; + + var requestAborted = false; + var readCallbackUnwired = new TaskCompletionSource(TaskContinuationOptions.RunContinuationsAsynchronously); + var clientClosedConnection = new TaskCompletionSource(TaskContinuationOptions.RunContinuationsAsynchronously); + var writeTcs = new TaskCompletionSource(TaskContinuationOptions.RunContinuationsAsynchronously); + + var mockKestrelTrace = new Mock(Logger) { CallBase = true }; + var mockLogger = new Mock(); + mockLogger + .Setup(logger => logger.IsEnabled(It.IsAny())) + .Returns(true); + mockLogger + .Setup(logger => logger.Log(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny>())) + .Callback>((logLevel, eventId, state, exception, formatter) => + { + if (eventId.Id == connectionPausedEventId) + { + readCallbackUnwired.TrySetResult(null); + } + + Logger.Log(logLevel, eventId, state, exception, formatter); + }); + + var mockLoggerFactory = new Mock(); + mockLoggerFactory + .Setup(factory => factory.CreateLogger(It.IsAny())) + .Returns(Logger); + mockLoggerFactory + .Setup(factory => factory.CreateLogger(It.IsIn("Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv", + "Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets"))) + .Returns(mockLogger.Object); + + var testContext = new TestServiceContext(mockLoggerFactory.Object) + { + Log = mockKestrelTrace.Object, + ServerOptions = + { + Limits = + { + MaxRequestBufferSize = maxRequestBufferSize, + MaxRequestLineSize = maxRequestBufferSize, + MaxRequestHeadersTotalSize = maxRequestBufferSize, + } + } + }; + + var scratchBuffer = new byte[4096]; + + using (var server = new TestServer(async context => + { + context.RequestAborted.Register(() => + { + requestAborted = true; + }); + + await clientClosedConnection.Task; + + try + { + for (var i = 0; i < 1000; i++) + { + await context.Response.Body.WriteAsync(scratchBuffer, 0, scratchBuffer.Length, context.RequestAborted); + await Task.Delay(10); + } + } + catch (Exception ex) + { + // TaskContinuationOptions.RunContinuationsAsynchronously sometimes runs inline anyway in + // situations such as this where the awaiter starts awaiting right when SetResult is called. + _ = Task.Run(() => writeTcs.SetException(ex)); + throw; + } + + writeTcs.SetException(new Exception("This shouldn't be reached.")); + }, testContext, listenOptions)) + { + using (var connection = server.CreateConnection()) + { + await connection.Send( + "POST / HTTP/1.1", + "Host:", + $"Content-Length: {scratchBuffer.Length}", + "", + ""); + + var ignore = connection.Stream.WriteAsync(scratchBuffer, 0, scratchBuffer.Length); + + // Wait until the read callback is no longer hooked up so that the connection disconnect isn't observed. + await readCallbackUnwired.Task.TimeoutAfter(TestConstants.DefaultTimeout); + } + + clientClosedConnection.SetResult(null); + + await Assert.ThrowsAnyAsync(() => writeTcs.Task).TimeoutAfter(TestConstants.DefaultTimeout); + } + + mockKestrelTrace.Verify(t => t.ConnectionStop(It.IsAny()), Times.Once()); + Assert.True(requestAborted); + } + + [Theory] + [MemberData(nameof(ConnectionAdapterData))] + public async Task AppCanHandleClientAbortingConnectionMidResponse(ListenOptions listenOptions) + { + const int responseBodySegmentSize = 65536; + const int responseBodySegmentCount = 100; + const int responseBodySize = responseBodySegmentSize * responseBodySegmentCount; + + var requestAborted = false; + var appCompletedTcs = new TaskCompletionSource(TaskContinuationOptions.RunContinuationsAsynchronously); + + var mockKestrelTrace = new Mock(Logger) { CallBase = true }; + var testContext = new TestServiceContext() + { + Log = mockKestrelTrace.Object, + }; + + var scratchBuffer = new byte[responseBodySegmentSize]; + + using (var server = new TestServer(async context => + { + context.RequestAborted.Register(() => + { + requestAborted = true; + }); + + context.Response.ContentLength = responseBodySize; + + try + { + for (var i = 0; i < responseBodySegmentCount; i++) + { + await context.Response.Body.WriteAsync(scratchBuffer, 0, scratchBuffer.Length); + await Task.Delay(10); + } + } + finally + { + // WriteAsync shouldn't throw without a CancellationToken passed in. Unfortunately a ECONNRESET UvException sometimes gets thrown. + // This will be fixed by https://github.com/aspnet/KestrelHttpServer/pull/2547 + // TaskContinuationOptions.RunContinuationsAsynchronously sometimes runs inline anyway in + // situations such as this where the awaiter starts awaiting right when SetResult is called. + _ = Task.Run(() => appCompletedTcs.SetResult(null)); + } + }, testContext, listenOptions)) + { + using (var connection = server.CreateConnection()) + { + await connection.Send( + "GET / HTTP/1.1", + "Host:", + "", + ""); + + var readCount = 0; + + // Read just part of the response and close the connection. + // https://github.com/aspnet/KestrelHttpServer/issues/2554 + for (var i = 0; i < responseBodySegmentCount / 10; i++) + { + readCount += await connection.Stream.ReadAsync(scratchBuffer, 0, scratchBuffer.Length); + } + + connection.Socket.Shutdown(SocketShutdown.Send); + + await appCompletedTcs.Task.TimeoutAfter(TestConstants.DefaultTimeout); + } + } + + mockKestrelTrace.Verify(t => t.ConnectionStop(It.IsAny()), Times.Once()); + Assert.True(requestAborted); + } + [Theory] [MemberData(nameof(ConnectionAdapterData))] public async Task NoErrorsLoggedWhenServerEndsConnectionBeforeClient(ListenOptions listenOptions) diff --git a/test/shared/PassThroughConnectionAdapter.cs b/test/shared/PassThroughConnectionAdapter.cs index 5f10736595..cfad5c7e7c 100644 --- a/test/shared/PassThroughConnectionAdapter.cs +++ b/test/shared/PassThroughConnectionAdapter.cs @@ -1,7 +1,9 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; using System.IO; +using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal; @@ -13,7 +15,7 @@ namespace Microsoft.AspNetCore.Testing public Task OnConnectionAsync(ConnectionAdapterContext context) { - var adapted = new AdaptedConnection(new LoggingStream(context.ConnectionStream, new TestApplicationErrorLogger())); + var adapted = new AdaptedConnection(new PassThroughStream(context.ConnectionStream)); return Task.FromResult(adapted); } @@ -30,5 +32,140 @@ namespace Microsoft.AspNetCore.Testing { } } + + private class PassThroughStream : Stream + { + private readonly Stream _innerStream; + + public PassThroughStream(Stream innerStream) + { + _innerStream = innerStream; + } + + public override bool CanRead => _innerStream.CanRead; + + public override bool CanSeek => _innerStream.CanSeek; + + public override bool CanTimeout => _innerStream.CanTimeout; + + public override bool CanWrite => _innerStream.CanWrite; + + public override long Length => _innerStream.Length; + + public override long Position { get => _innerStream.Position; set => _innerStream.Position = value; } + + public override int ReadTimeout { get => _innerStream.ReadTimeout; set => _innerStream.ReadTimeout = value; } + + public override int WriteTimeout { get => _innerStream.WriteTimeout; set => _innerStream.WriteTimeout = value; } + + public override int Read(byte[] buffer, int offset, int count) + { + return _innerStream.Read(buffer, offset, count); + } + + public override int ReadByte() + { + return _innerStream.ReadByte(); + } + + public override Task ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) + { + return _innerStream.ReadAsync(buffer, offset, count, cancellationToken); + } + + public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback callback, object state) + { + return _innerStream.BeginRead(buffer, offset, count, callback, state); + } + + public override int EndRead(IAsyncResult asyncResult) + { + return _innerStream.EndRead(asyncResult); + } + + public override void Write(byte[] buffer, int offset, int count) + { + _innerStream.Write(buffer, offset, count); + } + + + public override void WriteByte(byte value) + { + _innerStream.WriteByte(value); + } + + public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) + { + return _innerStream.WriteAsync(buffer, offset, count, cancellationToken); + } + + public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback callback, object state) + { + return _innerStream.BeginWrite(buffer, offset, count, callback, state); + } + + public override void EndWrite(IAsyncResult asyncResult) + { + _innerStream.EndWrite(asyncResult); + } + + public override Task CopyToAsync(Stream destination, int bufferSize, CancellationToken cancellationToken) + { + return _innerStream.CopyToAsync(destination, bufferSize, cancellationToken); + } + + public override void Flush() + { + _innerStream.Flush(); + } + + public override Task FlushAsync(CancellationToken cancellationToken) + { + return _innerStream.FlushAsync(); + + } + + public override long Seek(long offset, SeekOrigin origin) + { + return _innerStream.Seek(offset, origin); + } + + public override void SetLength(long value) + { + _innerStream.SetLength(value); + } + + public override void Close() + { + _innerStream.Close(); + } + +#if NETCOREAPP2_1 + public override int Read(Span buffer) + { + return _innerStream.Read(buffer); + } + + public override ValueTask ReadAsync(Memory buffer, CancellationToken cancellationToken = default) + { + return _innerStream.ReadAsync(buffer, cancellationToken); + } + + public override void Write(ReadOnlySpan buffer) + { + _innerStream.Write(buffer); + } + + public override ValueTask WriteAsync(ReadOnlyMemory buffer, CancellationToken cancellationToken = default) + { + return _innerStream.WriteAsync(buffer, cancellationToken); + } + + public override void CopyTo(Stream destination, int bufferSize) + { + _innerStream.CopyTo(destination, bufferSize); + } +#endif + } } } From cc35474a7c7466c3adee127694cae7ba5c3a182c Mon Sep 17 00:00:00 2001 From: Nate McMaster Date: Wed, 23 May 2018 15:35:19 -0700 Subject: [PATCH 1639/1662] Bumping version from 2.1.0 to 2.1.1 --- version.props | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/version.props b/version.props index b9552451d8..669c874829 100644 --- a/version.props +++ b/version.props @@ -1,6 +1,6 @@ - + - 2.1.0 + 2.1.1 rtm $(VersionPrefix) $(VersionPrefix)-$(VersionSuffix)-final From 67afccfd16232588bf6f4bbccf3b191d00d43772 Mon Sep 17 00:00:00 2001 From: "ASP.NET CI" Date: Tue, 29 May 2018 09:44:22 -0700 Subject: [PATCH 1640/1662] Update dependencies.props [auto-updated: dependencies] --- build/dependencies.props | 64 ++++++++++++++++++++-------------------- korebuild-lock.txt | 4 +-- 2 files changed, 34 insertions(+), 34 deletions(-) diff --git a/build/dependencies.props b/build/dependencies.props index b27f54b527..3f6b4b6da1 100644 --- a/build/dependencies.props +++ b/build/dependencies.props @@ -5,44 +5,44 @@ 0.10.13 - 2.1.0-rtm-15783 + 2.1.1-rtm-15790 1.10.0 - 2.1.0-rtm-30721 - 2.1.0-rtm-30721 - 2.1.0-rtm-30721 - 2.1.0-rtm-30721 - 2.1.0-rtm-30721 - 2.1.0-rtm-30721 - 2.1.0-rtm-30721 - 2.1.0-rtm-30721 - 2.1.0-rtm-30721 - 2.1.0-rtm-30721 - 2.1.0-rtm-30721 - 2.1.0-rtm-30721 - 2.1.0-rtm-30721 - 2.1.0-rtm-30721 - 2.1.0-rtm-30721 - 2.1.0-rtm-30721 - 2.1.0-rtm-30721 - 2.1.0-rtm-30721 - 2.1.0-rtm-30721 - 2.1.0-rtm-30721 - 2.1.0-rtm-30721 - 2.1.0-rtm-30721 + 2.1.0 + 2.1.0 + 2.1.0 + 2.1.0 + 2.1.0 + 2.1.0 + 2.1.0 + 2.1.0 + 2.1.0 + 2.1.0 + 2.1.0 + 2.1.0 + 2.1.0 + 2.1.0 + 2.1.0 + 2.1.0 + 2.1.0 + 2.1.0 + 2.1.0 + 2.1.0 + 2.1.0 + 2.1.0 2.0.0 - 2.1.0-rtm-26502-02 - 2.1.0-rtm-30721 + 2.1.0 + 2.1.0 15.6.1 4.7.49 2.0.3 11.0.2 - 4.5.0-rtm-26502-02 - 4.5.0-rtm-26502-02 - 4.5.0-rtm-26502-02 - 4.5.0-rtm-26502-02 - 4.5.0-rtm-26502-02 - 4.5.0-rtm-26502-02 - 4.5.0-rtm-26502-02 + 4.5.0 + 4.5.0 + 4.5.0 + 4.5.0 + 4.5.0 + 4.5.0 + 4.5.0 1.3.7 0.8.0 2.3.1 diff --git a/korebuild-lock.txt b/korebuild-lock.txt index 3673744db9..cd5b409a1e 100644 --- a/korebuild-lock.txt +++ b/korebuild-lock.txt @@ -1,2 +1,2 @@ -version:2.1.0-rtm-15783 -commithash:5fc2b2f607f542a2ffde11c19825e786fc1a3774 +version:2.1.1-rtm-15790 +commithash:274c65868e735f29f4078c1884c61c4371ee1fc0 From 65336fe9cbe0c3e868416e7096b787898a861247 Mon Sep 17 00:00:00 2001 From: Nate McMaster Date: Tue, 29 May 2018 09:48:13 -0700 Subject: [PATCH 1641/1662] Bumping version from 2.1.1 to 2.1.2 --- version.props | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version.props b/version.props index 669c874829..478dfd16ed 100644 --- a/version.props +++ b/version.props @@ -1,6 +1,6 @@  - 2.1.1 + 2.1.2 rtm $(VersionPrefix) $(VersionPrefix)-$(VersionSuffix)-final From b08163d3b7bbc5e599bb895e49ad9d2abd67b848 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Tue, 29 May 2018 16:07:41 -0700 Subject: [PATCH 1642/1662] [2.1.1] Use TaskCreationOptions.RunContinuationsAsynchronously a lot (#2618) --- .../ConnectionLimitTests.cs | 12 ++-- .../HttpConnectionManagerTests.cs | 2 +- test/Kestrel.FunctionalTests/HttpsTests.cs | 6 +- .../MaxRequestBufferSizeTests.cs | 8 +-- test/Kestrel.FunctionalTests/RequestTests.cs | 32 +++++----- test/Kestrel.FunctionalTests/ResponseTests.cs | 62 +++++++++---------- .../HostNameIsReachableAttribute.cs | 2 +- test/Kestrel.FunctionalTests/UpgradeTests.cs | 10 +-- .../ListenerPrimaryTests.cs | 2 +- test/shared/TestConnection.cs | 2 +- 10 files changed, 66 insertions(+), 72 deletions(-) diff --git a/test/Kestrel.FunctionalTests/ConnectionLimitTests.cs b/test/Kestrel.FunctionalTests/ConnectionLimitTests.cs index 8462050e36..3aa1ad90f5 100644 --- a/test/Kestrel.FunctionalTests/ConnectionLimitTests.cs +++ b/test/Kestrel.FunctionalTests/ConnectionLimitTests.cs @@ -22,9 +22,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [Fact] public async Task ResetsCountWhenConnectionClosed() { - var requestTcs = new TaskCompletionSource(); - var releasedTcs = new TaskCompletionSource(); - var lockedTcs = new TaskCompletionSource(); + var requestTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var releasedTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var lockedTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); var counter = new EventRaisingResourceCounter(ResourceCounter.Quota(1)); counter.OnLock += (s, e) => lockedTcs.TrySetResult(e); counter.OnRelease += (s, e) => releasedTcs.TrySetResult(null); @@ -95,7 +95,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests public async Task RejectsConnectionsWhenLimitReached() { const int max = 10; - var requestTcs = new TaskCompletionSource(); + var requestTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); using (var server = CreateServerWithMaxConnections(async context => { @@ -140,8 +140,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests const int count = 100; var opened = 0; var closed = 0; - var openedTcs = new TaskCompletionSource(); - var closedTcs = new TaskCompletionSource(); + var openedTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var closedTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); var counter = new EventRaisingResourceCounter(ResourceCounter.Quota(uint.MaxValue)); diff --git a/test/Kestrel.FunctionalTests/HttpConnectionManagerTests.cs b/test/Kestrel.FunctionalTests/HttpConnectionManagerTests.cs index 7f5296763c..ef8ac428b1 100644 --- a/test/Kestrel.FunctionalTests/HttpConnectionManagerTests.cs +++ b/test/Kestrel.FunctionalTests/HttpConnectionManagerTests.cs @@ -42,7 +42,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests using (var server = new TestServer(context => { appStartedWh.Release(); - var tcs = new TaskCompletionSource(); + var tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); return tcs.Task; }, new TestServiceContext(new LoggerFactory(), mockTrace.Object))) diff --git a/test/Kestrel.FunctionalTests/HttpsTests.cs b/test/Kestrel.FunctionalTests/HttpsTests.cs index b20b3c5874..30ae3470ed 100644 --- a/test/Kestrel.FunctionalTests/HttpsTests.cs +++ b/test/Kestrel.FunctionalTests/HttpsTests.cs @@ -253,7 +253,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [Fact] public async Task DoesNotThrowObjectDisposedExceptionFromWriteAsyncAfterConnectionIsAborted() { - var tcs = new TaskCompletionSource(); + var tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); var loggerProvider = new HandshakeErrorLoggerProvider(); LoggerFactory.AddProvider(loggerProvider); var hostBuilder = TransportSelector.GetWebHostBuilder() @@ -441,13 +441,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { public LogLevel LastLogLevel { get; set; } public EventId LastEventId { get; set; } - public TaskCompletionSource LogTcs { get; } = new TaskCompletionSource(); + public TaskCompletionSource LogTcs { get; } = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); public void Log(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func formatter) { LastLogLevel = logLevel; LastEventId = eventId; - Task.Run(() => LogTcs.SetResult(null)); + LogTcs.SetResult(null); } public bool IsEnabled(LogLevel logLevel) diff --git a/test/Kestrel.FunctionalTests/MaxRequestBufferSizeTests.cs b/test/Kestrel.FunctionalTests/MaxRequestBufferSizeTests.cs index 93919845ea..64522f2202 100644 --- a/test/Kestrel.FunctionalTests/MaxRequestBufferSizeTests.cs +++ b/test/Kestrel.FunctionalTests/MaxRequestBufferSizeTests.cs @@ -89,8 +89,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests // Initialize data with random bytes (new Random()).NextBytes(data); - var startReadingRequestBody = new TaskCompletionSource(); - var clientFinishedSendingRequestBody = new TaskCompletionSource(); + var startReadingRequestBody = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var clientFinishedSendingRequestBody = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); var lastBytesWritten = DateTime.MaxValue; using (var host = StartWebHost(maxRequestBufferSize, data, connectionAdapter, startReadingRequestBody, clientFinishedSendingRequestBody)) @@ -181,8 +181,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests var bytesWrittenPollingInterval = TimeSpan.FromMilliseconds(bytesWrittenTimeout.TotalMilliseconds / 10); var maxSendSize = 4096; - var startReadingRequestBody = new TaskCompletionSource(); - var clientFinishedSendingRequestBody = new TaskCompletionSource(); + var startReadingRequestBody = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var clientFinishedSendingRequestBody = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); var lastBytesWritten = DateTime.MaxValue; using (var host = StartWebHost(16 * 1024, data, false, startReadingRequestBody, clientFinishedSendingRequestBody)) diff --git a/test/Kestrel.FunctionalTests/RequestTests.cs b/test/Kestrel.FunctionalTests/RequestTests.cs index 3f82426e5f..7d01075fc4 100644 --- a/test/Kestrel.FunctionalTests/RequestTests.cs +++ b/test/Kestrel.FunctionalTests/RequestTests.cs @@ -578,8 +578,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests public async Task ConnectionClosedTokenFiresOnClientFIN(ListenOptions listenOptions) { var testContext = new TestServiceContext(LoggerFactory); - var appStartedTcs = new TaskCompletionSource(); - var connectionClosedTcs = new TaskCompletionSource(); + var appStartedTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var connectionClosedTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); using (var server = new TestServer(context => { @@ -613,7 +613,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests public async Task ConnectionClosedTokenFiresOnServerFIN(ListenOptions listenOptions) { var testContext = new TestServiceContext(LoggerFactory); - var connectionClosedTcs = new TaskCompletionSource(); + var connectionClosedTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); using (var server = new TestServer(context => { @@ -649,7 +649,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests public async Task ConnectionClosedTokenFiresOnServerAbort(ListenOptions listenOptions) { var testContext = new TestServiceContext(LoggerFactory); - var connectionClosedTcs = new TaskCompletionSource(); + var connectionClosedTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); using (var server = new TestServer(context => { @@ -694,9 +694,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [InlineData("http://localhost/path%20with%20space?q=abc%20123", "/path with space", "abc 123")] public async Task CanHandleRequestsWithUrlInAbsoluteForm(string requestUrl, string expectedPath, string queryValue) { - var pathTcs = new TaskCompletionSource(); - var rawTargetTcs = new TaskCompletionSource(); - var queryTcs = new TaskCompletionSource(); + var pathTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var rawTargetTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var queryTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); using (var server = new TestServer(async context => { @@ -1135,8 +1135,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { var testContext = new TestServiceContext(LoggerFactory); - var readTcs = new TaskCompletionSource(); - var registrationTcs = new TaskCompletionSource(); + var readTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var registrationTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); var requestId = 0; using (var server = new TestServer(async httpContext => @@ -1217,10 +1217,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests const int connectionFinSentEventId = 7; const int maxRequestBufferSize = 4096; - var readCallbackUnwired = new TaskCompletionSource(TaskContinuationOptions.RunContinuationsAsynchronously); - var clientClosedConnection = new TaskCompletionSource(TaskContinuationOptions.RunContinuationsAsynchronously); - var serverClosedConnection = new TaskCompletionSource(TaskContinuationOptions.RunContinuationsAsynchronously); - var appFuncCompleted = new TaskCompletionSource(TaskContinuationOptions.RunContinuationsAsynchronously); + var readCallbackUnwired = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var clientClosedConnection = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var serverClosedConnection = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var appFuncCompleted = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); var mockLogger = new Mock(); mockLogger @@ -1276,9 +1276,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests await serverClosedConnection.Task; - // TaskContinuationOptions.RunContinuationsAsynchronously sometimes runs inline anyway in - // situations such as this where the awaiter starts awaiting right when SetResult is called. - _ = Task.Run(() => appFuncCompleted.SetResult(null)); + appFuncCompleted.SetResult(null); }, testContext, listenOptions)) { using (var connection = server.CreateConnection()) @@ -1308,7 +1306,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [MemberData(nameof(ConnectionAdapterData))] public async Task AppCanHandleClientAbortingConnectionMidRequest(ListenOptions listenOptions) { - var readTcs = new TaskCompletionSource(TaskContinuationOptions.RunContinuationsAsynchronously); + var readTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); var mockKestrelTrace = new Mock(Logger) { CallBase = true }; var testContext = new TestServiceContext() diff --git a/test/Kestrel.FunctionalTests/ResponseTests.cs b/test/Kestrel.FunctionalTests/ResponseTests.cs index 3e7f4b7d58..d652b8aff4 100644 --- a/test/Kestrel.FunctionalTests/ResponseTests.cs +++ b/test/Kestrel.FunctionalTests/ResponseTests.cs @@ -145,7 +145,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests public async Task OnCompleteCalledEvenWhenOnStartingNotCalled() { var onStartingCalled = false; - var onCompletedTcs = new TaskCompletionSource(); + var onCompletedTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); var hostBuilder = TransportSelector.GetWebHostBuilder() .UseKestrel() @@ -341,7 +341,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [Fact] public async Task OnCompletedShouldNotBlockAResponse() { - var delayTcs = new TaskCompletionSource(); + var delayTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); var hostBuilder = TransportSelector.GetWebHostBuilder() .UseKestrel() .UseUrls("http://127.0.0.1:0/") @@ -375,7 +375,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [Fact] public async Task InvalidChunkedEncodingInRequestShouldNotBlockOnCompleted() { - var onCompletedTcs = new TaskCompletionSource(); + var onCompletedTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); using (var server = new TestServer(httpContext => { @@ -418,7 +418,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests mockHttpContextFactory.Setup(f => f.Create(It.IsAny())) .Returns(fc => new DefaultHttpContext(fc)); - var disposedTcs = new TaskCompletionSource(); + var disposedTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); mockHttpContextFactory.Setup(f => f.Dispose(It.IsAny())) .Callback(c => { @@ -619,7 +619,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { const string response = "hello, world"; - var logTcs = new TaskCompletionSource(); + var logTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); var mockKestrelTrace = new Mock(); mockKestrelTrace .Setup(trace => trace.ConnectionHeadResponseBodyWrite(It.IsAny(), response.Length)) @@ -808,7 +808,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [Fact] public async Task WhenAppWritesLessThanContentLengthErrorLogged() { - var logTcs = new TaskCompletionSource(); + var logTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); var mockTrace = new Mock(); mockTrace .Setup(trace => trace.ApplicationError(It.IsAny(), It.IsAny(), It.IsAny())) @@ -1182,7 +1182,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { var connectionClosed = new ManualResetEventSlim(); var requestStarted = new ManualResetEventSlim(); - var tcs = new TaskCompletionSource(); + var tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); using (var server = new TestServer(async httpContext => { @@ -2279,7 +2279,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests // Ensure string is long enough to disable write-behind buffering var largeString = new string('a', maxBytesPreCompleted + 1); - var writeTcs = new TaskCompletionSource(); + var writeTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); var requestAbortedWh = new ManualResetEventSlim(); var requestStartWh = new ManualResetEventSlim(); @@ -2336,9 +2336,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests const int maxRequestBufferSize = 2048; var requestAborted = false; - var readCallbackUnwired = new TaskCompletionSource(TaskContinuationOptions.RunContinuationsAsynchronously); - var clientClosedConnection = new TaskCompletionSource(TaskContinuationOptions.RunContinuationsAsynchronously); - var writeTcs = new TaskCompletionSource(TaskContinuationOptions.RunContinuationsAsynchronously); + var readCallbackUnwired = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var clientClosedConnection = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var writeTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); var mockKestrelTrace = new Mock(Logger) { CallBase = true }; var mockLogger = new Mock(); @@ -2401,9 +2401,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } catch (Exception ex) { - // TaskContinuationOptions.RunContinuationsAsynchronously sometimes runs inline anyway in - // situations such as this where the awaiter starts awaiting right when SetResult is called. - _ = Task.Run(() => writeTcs.SetException(ex)); + writeTcs.SetException(ex); throw; } @@ -2443,7 +2441,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests const int responseBodySize = responseBodySegmentSize * responseBodySegmentCount; var requestAborted = false; - var appCompletedTcs = new TaskCompletionSource(TaskContinuationOptions.RunContinuationsAsynchronously); + var appCompletedTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); var mockKestrelTrace = new Mock(Logger) { CallBase = true }; var testContext = new TestServiceContext() @@ -2474,9 +2472,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { // WriteAsync shouldn't throw without a CancellationToken passed in. Unfortunately a ECONNRESET UvException sometimes gets thrown. // This will be fixed by https://github.com/aspnet/KestrelHttpServer/pull/2547 - // TaskContinuationOptions.RunContinuationsAsynchronously sometimes runs inline anyway in - // situations such as this where the awaiter starts awaiting right when SetResult is called. - _ = Task.Run(() => appCompletedTcs.SetResult(null)); + appCompletedTcs.SetResult(null); } }, testContext, listenOptions)) { @@ -2623,7 +2619,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests var testContext= new TestServiceContext(LoggerFactory); var callOrder = new Stack(); - var onStartingTcs = new TaskCompletionSource(); + var onStartingTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); using (var server = new TestServer(async context => { @@ -2675,7 +2671,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests var testContext= new TestServiceContext(LoggerFactory); var callOrder = new Stack(); - var onCompletedTcs = new TaskCompletionSource(); + var onCompletedTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); using (var server = new TestServer(async context => { @@ -2819,10 +2815,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests var responseSize = chunks * chunkSize; var chunkData = new byte[chunkSize]; - var responseRateTimeoutMessageLogged = new TaskCompletionSource(); - var connectionStopMessageLogged = new TaskCompletionSource(); - var requestAborted = new TaskCompletionSource(); - var appFuncCompleted = new TaskCompletionSource(); + var responseRateTimeoutMessageLogged = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var connectionStopMessageLogged = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var requestAborted = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var appFuncCompleted = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); var mockKestrelTrace = new Mock(); mockKestrelTrace @@ -2910,10 +2906,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests var certificate = new X509Certificate2(TestResources.TestCertificatePath, "testPassword"); - var responseRateTimeoutMessageLogged = new TaskCompletionSource(); - var connectionStopMessageLogged = new TaskCompletionSource(); - var aborted = new TaskCompletionSource(); - var appFuncCompleted = new TaskCompletionSource(); + var responseRateTimeoutMessageLogged = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var connectionStopMessageLogged = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var aborted = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var appFuncCompleted = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); var mockKestrelTrace = new Mock(); mockKestrelTrace @@ -3002,10 +2998,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests var responseSize = bufferCount * bufferSize; var buffer = new byte[bufferSize]; - var responseRateTimeoutMessageLogged = new TaskCompletionSource(); - var connectionStopMessageLogged = new TaskCompletionSource(); - var requestAborted = new TaskCompletionSource(); - var appFuncCompleted = new TaskCompletionSource(); + var responseRateTimeoutMessageLogged = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var connectionStopMessageLogged = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var requestAborted = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var appFuncCompleted = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); var mockKestrelTrace = new Mock(); mockKestrelTrace @@ -3089,7 +3085,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests var chunkData = new byte[chunkSize]; var requestAborted = false; - var appFuncCompleted = new TaskCompletionSource(); + var appFuncCompleted = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); var mockKestrelTrace = new Mock(); var testContext = new TestServiceContext diff --git a/test/Kestrel.FunctionalTests/TestHelpers/HostNameIsReachableAttribute.cs b/test/Kestrel.FunctionalTests/TestHelpers/HostNameIsReachableAttribute.cs index bd120b6356..5a83bd7c3f 100644 --- a/test/Kestrel.FunctionalTests/TestHelpers/HostNameIsReachableAttribute.cs +++ b/test/Kestrel.FunctionalTests/TestHelpers/HostNameIsReachableAttribute.cs @@ -61,7 +61,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests public static async Task ConnectToHost(string hostName, int port) { - var tcs = new TaskCompletionSource(); + var tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); var socketArgs = new SocketAsyncEventArgs(); socketArgs.RemoteEndPoint = new DnsEndPoint(hostName, port); diff --git a/test/Kestrel.FunctionalTests/UpgradeTests.cs b/test/Kestrel.FunctionalTests/UpgradeTests.cs index 6a839aaad3..d7a0f5073f 100644 --- a/test/Kestrel.FunctionalTests/UpgradeTests.cs +++ b/test/Kestrel.FunctionalTests/UpgradeTests.cs @@ -19,7 +19,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [Fact] public async Task ResponseThrowsAfterUpgrade() { - var upgrade = new TaskCompletionSource(); + var upgrade = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); using (var server = new TestServer(async context => { var feature = context.Features.Get(); @@ -58,7 +58,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests const string send = "Custom protocol send"; const string recv = "Custom protocol recv"; - var upgrade = new TaskCompletionSource(); + var upgrade = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); using (var server = new TestServer(async context => { try @@ -109,7 +109,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [Fact] public async Task UpgradeCannotBeCalledMultipleTimes() { - var upgradeTcs = new TaskCompletionSource(); + var upgradeTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); using (var server = new TestServer(async context => { var feature = context.Features.Get(); @@ -217,7 +217,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [Fact] public async Task ThrowsWhenUpgradingNonUpgradableRequest() { - var upgradeTcs = new TaskCompletionSource(); + var upgradeTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); using (var server = new TestServer(async context => { var feature = context.Features.Get(); @@ -251,7 +251,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests public async Task RejectsUpgradeWhenLimitReached() { const int limit = 10; - var upgradeTcs = new TaskCompletionSource(); + var upgradeTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); var serviceContext = new TestServiceContext(LoggerFactory); serviceContext.ConnectionManager = new HttpConnectionManager(serviceContext.Log, ResourceCounter.Quota(limit)); diff --git a/test/Kestrel.Transport.Libuv.Tests/ListenerPrimaryTests.cs b/test/Kestrel.Transport.Libuv.Tests/ListenerPrimaryTests.cs index fa4198ccb4..2d906fc2cf 100644 --- a/test/Kestrel.Transport.Libuv.Tests/ListenerPrimaryTests.cs +++ b/test/Kestrel.Transport.Libuv.Tests/ListenerPrimaryTests.cs @@ -140,7 +140,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests Assert.Equal("Primary", await HttpClientSlim.GetStringAsync(address)); // Create a pipe connection and keep it open without sending any data - var connectTcs = new TaskCompletionSource(); + var connectTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); var connectionTrace = new LibuvTrace(new TestApplicationErrorLogger()); var pipe = new UvPipeHandle(connectionTrace); diff --git a/test/shared/TestConnection.cs b/test/shared/TestConnection.cs index 4f65da6bcf..85e82590c0 100644 --- a/test/shared/TestConnection.cs +++ b/test/shared/TestConnection.cs @@ -217,7 +217,7 @@ namespace Microsoft.AspNetCore.Testing public Task WaitForConnectionClose() { - var tcs = new TaskCompletionSource(); + var tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); var eventArgs = new SocketAsyncEventArgs(); eventArgs.SetBuffer(new byte[128], 0, 128); eventArgs.Completed += ReceiveAsyncCompleted; From 5ec7bacdfea4e44217d2fc29d6b31ebfa83e8e07 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Tue, 29 May 2018 16:27:16 -0700 Subject: [PATCH 1643/1662] Lower severity of AuthenticationException logs from SslStream handshake (#2614) --- .../Internal/HttpsConnectionAdapter.cs | 3 +- test/Kestrel.FunctionalTests/HttpsTests.cs | 58 +++++++++++++------ test/Kestrel.FunctionalTests/RequestTests.cs | 2 +- 3 files changed, 43 insertions(+), 20 deletions(-) diff --git a/src/Kestrel.Core/Internal/HttpsConnectionAdapter.cs b/src/Kestrel.Core/Internal/HttpsConnectionAdapter.cs index 301c9c7a23..95ee435b43 100644 --- a/src/Kestrel.Core/Internal/HttpsConnectionAdapter.cs +++ b/src/Kestrel.Core/Internal/HttpsConnectionAdapter.cs @@ -5,6 +5,7 @@ using System; using System.Collections.Generic; using System.IO; using System.Net.Security; +using System.Security.Authentication; using System.Security.Cryptography.X509Certificates; using System.Threading; using System.Threading.Tasks; @@ -186,7 +187,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Https.Internal sslStream.Dispose(); return _closedAdaptedConnection; } - catch (IOException ex) + catch (Exception ex) when (ex is IOException || ex is AuthenticationException) { _logger?.LogDebug(1, ex, CoreStrings.AuthenticationFailed); sslStream.Dispose(); diff --git a/test/Kestrel.FunctionalTests/HttpsTests.cs b/test/Kestrel.FunctionalTests/HttpsTests.cs index 30ae3470ed..be9e9fe623 100644 --- a/test/Kestrel.FunctionalTests/HttpsTests.cs +++ b/test/Kestrel.FunctionalTests/HttpsTests.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; +using System.IO; using System.Net; using System.Net.Security; using System.Net.Sockets; @@ -235,15 +236,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests var request = Encoding.ASCII.GetBytes("GET / HTTP/1.1\r\nHost:\r\n\r\n"); await sslStream.WriteAsync(request, 0, request.Length); - // Temporary workaround for a deadlock when reading from an aborted client SslStream on Mac and Linux. - if (TestPlatformHelper.IsWindows) - { - await sslStream.ReadAsync(new byte[32], 0, 32); - } - else - { - await stream.ReadAsync(new byte[32], 0, 32); - } + await sslStream.ReadAsync(new byte[32], 0, 32); } } @@ -295,15 +288,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests var request = Encoding.ASCII.GetBytes("GET / HTTP/1.1\r\nHost:\r\n\r\n"); await sslStream.WriteAsync(request, 0, request.Length); - // Temporary workaround for a deadlock when reading from an aborted client SslStream on Mac and Linux. - if (TestPlatformHelper.IsWindows) - { - await sslStream.ReadAsync(new byte[32], 0, 32); - } - else - { - await stream.ReadAsync(new byte[32], 0, 32); - } + await sslStream.ReadAsync(new byte[32], 0, 32); } } @@ -415,6 +400,43 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests Assert.Equal(LogLevel.Debug, loggerProvider.FilterLogger.LastLogLevel); } + [Fact] + public async Task ClientAttemptingToUseUnsupportedProtocolIsLoggedAsDebug() + { + var loggerProvider = new HandshakeErrorLoggerProvider(); + LoggerFactory.AddProvider(loggerProvider); + var hostBuilder = TransportSelector.GetWebHostBuilder() + .UseKestrel(options => + { + options.Listen(new IPEndPoint(IPAddress.Loopback, 0), listenOptions => + { + listenOptions.UseHttps(TestResources.TestCertificatePath, "testPassword"); + }); + }) + .ConfigureServices(AddTestLogging) + .Configure(app => app.Run(httpContext => Task.CompletedTask)); + + using (var host = hostBuilder.Build()) + { + host.Start(); + + using (var socket = await HttpClientSlim.GetSocket(new Uri($"https://127.0.0.1:{host.GetPort()}/"))) + using (var stream = new NetworkStream(socket, ownsSocket: false)) + using (var sslStream = new SslStream(stream, true, (sender, certificate, chain, errors) => true)) + { + // SslProtocols.Tls is TLS 1.0 which isn't supported by Kestrel by default. + await Assert.ThrowsAsync(() => + sslStream.AuthenticateAsClientAsync("127.0.0.1", clientCertificates: null, + enabledSslProtocols: SslProtocols.Tls, + checkCertificateRevocation: false)); + } + } + + await loggerProvider.FilterLogger.LogTcs.Task.TimeoutAfter(TestConstants.DefaultTimeout); + Assert.Equal(1, loggerProvider.FilterLogger.LastEventId); + Assert.Equal(LogLevel.Debug, loggerProvider.FilterLogger.LastLogLevel); + } + private class HandshakeErrorLoggerProvider : ILoggerProvider { public HttpsConnectionFilterLogger FilterLogger { get; } = new HttpsConnectionFilterLogger(); diff --git a/test/Kestrel.FunctionalTests/RequestTests.cs b/test/Kestrel.FunctionalTests/RequestTests.cs index 7d01075fc4..d8d78fd6d8 100644 --- a/test/Kestrel.FunctionalTests/RequestTests.cs +++ b/test/Kestrel.FunctionalTests/RequestTests.cs @@ -1266,7 +1266,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } }; - var scratchBuffer = new byte[maxRequestBufferSize * 2 + 1]; + var scratchBuffer = new byte[maxRequestBufferSize * 8]; using (var server = new TestServer(async context => { From 9e15b2bca41ab1dcba50cbfe921bb03c104646b1 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Thu, 31 May 2018 11:27:38 -0700 Subject: [PATCH 1644/1662] Fix PipeReader consumption pattern [2.1] --- .../PlatformBenchmarks/HttpApplication.cs | 8 +-- .../Adapter/Internal/RawStream.cs | 3 +- .../Internal/Http/Http1MessageBody.cs | 4 +- src/Kestrel.Core/Internal/Http/MessageBody.cs | 6 ++- .../Internal/Http2/Http2Connection.cs | 19 +++---- .../Internal/LibuvOutputConsumer.cs | 3 +- .../ChunkedRequestTests.cs | 51 +++++++++++++++++++ 7 files changed, 73 insertions(+), 21 deletions(-) diff --git a/benchmarkapps/PlatformBenchmarks/HttpApplication.cs b/benchmarkapps/PlatformBenchmarks/HttpApplication.cs index e9b20f5aaa..698e8952b0 100644 --- a/benchmarkapps/PlatformBenchmarks/HttpApplication.cs +++ b/benchmarkapps/PlatformBenchmarks/HttpApplication.cs @@ -107,10 +107,6 @@ namespace PlatformBenchmarks ThrowUnexpectedEndOfData(); } } - else if (result.IsCompleted) - { - break; - } Reader.AdvanceTo(consumed, examined); @@ -120,6 +116,10 @@ namespace PlatformBenchmarks _state = State.StartLine; } + else if (result.IsCompleted) + { + break; + } } } diff --git a/src/Kestrel.Core/Adapter/Internal/RawStream.cs b/src/Kestrel.Core/Adapter/Internal/RawStream.cs index ea381c22b2..084eed2418 100644 --- a/src/Kestrel.Core/Adapter/Internal/RawStream.cs +++ b/src/Kestrel.Core/Adapter/Internal/RawStream.cs @@ -125,7 +125,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal readableBuffer.CopyTo(destination.Span); return count; } - else if (result.IsCompleted) + + if (result.IsCompleted) { return 0; } diff --git a/src/Kestrel.Core/Internal/Http/Http1MessageBody.cs b/src/Kestrel.Core/Internal/Http/Http1MessageBody.cs index d65805cc83..f11619d7f3 100644 --- a/src/Kestrel.Core/Internal/Http/Http1MessageBody.cs +++ b/src/Kestrel.Core/Internal/Http/Http1MessageBody.cs @@ -87,7 +87,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http break; } } - else if (result.IsCompleted) + + // Read() will have already have greedily consumed the entire request body if able. + if (result.IsCompleted) { // Treat any FIN from an upgraded request as expected. // It's up to higher-level consumer (i.e. WebSocket middleware) to determine diff --git a/src/Kestrel.Core/Internal/Http/MessageBody.cs b/src/Kestrel.Core/Internal/Http/MessageBody.cs index a406e64ffa..33bd8ebfb5 100644 --- a/src/Kestrel.Core/Internal/Http/MessageBody.cs +++ b/src/Kestrel.Core/Internal/Http/MessageBody.cs @@ -57,7 +57,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http slice.CopyTo(buffer.Span); return actual; } - else if (result.IsCompleted) + + if (result.IsCompleted) { return 0; } @@ -96,7 +97,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http #endif } } - else if (result.IsCompleted) + + if (result.IsCompleted) { return; } diff --git a/src/Kestrel.Core/Internal/Http2/Http2Connection.cs b/src/Kestrel.Core/Internal/Http2/Http2Connection.cs index 549e804d33..c3c0a53672 100644 --- a/src/Kestrel.Core/Internal/Http2/Http2Connection.cs +++ b/src/Kestrel.Core/Internal/Http2/Http2Connection.cs @@ -117,14 +117,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 try { - if (!readableBuffer.IsEmpty) + if (!readableBuffer.IsEmpty && ParsePreface(readableBuffer, out consumed, out examined)) { - if (ParsePreface(readableBuffer, out consumed, out examined)) - { - break; - } + break; } - else if (result.IsCompleted) + + if (result.IsCompleted) { return; } @@ -149,13 +147,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 try { - if (!readableBuffer.IsEmpty) + if (!readableBuffer.IsEmpty && Http2FrameReader.ReadFrame(readableBuffer, _incomingFrame, out consumed, out examined)) { - if (Http2FrameReader.ReadFrame(readableBuffer, _incomingFrame, out consumed, out examined)) - { - Log.LogTrace($"Connection id {ConnectionId} received {_incomingFrame.Type} frame with flags 0x{_incomingFrame.Flags:x} and length {_incomingFrame.Length} for stream ID {_incomingFrame.StreamId}"); - await ProcessFrameAsync(application); - } + Log.LogTrace($"Connection id {ConnectionId} received {_incomingFrame.Type} frame with flags 0x{_incomingFrame.Flags:x} and length {_incomingFrame.Length} for stream ID {_incomingFrame.StreamId}"); + await ProcessFrameAsync(application); } else if (result.IsCompleted) { diff --git a/src/Kestrel.Transport.Libuv/Internal/LibuvOutputConsumer.cs b/src/Kestrel.Transport.Libuv/Internal/LibuvOutputConsumer.cs index 94195a3ffc..e2ba7a09e3 100644 --- a/src/Kestrel.Transport.Libuv/Internal/LibuvOutputConsumer.cs +++ b/src/Kestrel.Transport.Libuv/Internal/LibuvOutputConsumer.cs @@ -99,7 +99,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal writeReq = null; } } - else if (result.IsCompleted) + + if (result.IsCompleted) { break; } diff --git a/test/Kestrel.FunctionalTests/ChunkedRequestTests.cs b/test/Kestrel.FunctionalTests/ChunkedRequestTests.cs index 8dba8331e1..10b68fdf45 100644 --- a/test/Kestrel.FunctionalTests/ChunkedRequestTests.cs +++ b/test/Kestrel.FunctionalTests/ChunkedRequestTests.cs @@ -1,14 +1,17 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Net; +using System.Net.Sockets; using System.Text; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Server.Kestrel.Core; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; using Microsoft.AspNetCore.Testing; using Microsoft.Extensions.Logging.Testing; using Xunit; @@ -634,6 +637,54 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } } } + + [Theory] + [MemberData(nameof(ConnectionAdapterData))] + public async Task ClosingConnectionMidChunkPrefixThrows(ListenOptions listenOptions) + { + var testContext = new TestServiceContext(LoggerFactory); + var readStartedTcs = new TaskCompletionSource(); + var exTcs = new TaskCompletionSource(); + + using (var server = new TestServer(async httpContext => + { + var readTask = httpContext.Request.Body.CopyToAsync(Stream.Null); + readStartedTcs.SetResult(null); + + try + { + await readTask; + } + catch (BadHttpRequestException badRequestEx) + { + exTcs.TrySetResult(badRequestEx); + } + catch (Exception ex) + { + exTcs.SetException(ex); + } + }, testContext, listenOptions)) + { + using (var connection = server.CreateConnection()) + { + await connection.SendAll( + "POST / HTTP/1.1", + "Host:", + "Transfer-Encoding: chunked", + "", + "1"); + + await readStartedTcs.Task.TimeoutAfter(TestConstants.DefaultTimeout); + + connection.Socket.Shutdown(SocketShutdown.Send); + + await connection.ReceiveEnd(); + + var badReqEx = await exTcs.Task.TimeoutAfter(TestConstants.DefaultTimeout); + Assert.Equal(RequestRejectionReason.UnexpectedEndOfRequestContent, badReqEx.Reason); + } + } + } } } From af177c5adcb467ad8cf7e6793a1020b7c830b03e Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Thu, 31 May 2018 15:44:39 -0700 Subject: [PATCH 1645/1662] Add Memory overloads to HttpUpgradeStream (#2622) --- .../Internal/Http/HttpUpgradeStream.cs | 14 ++++++++++++++ .../Internal/Infrastructure/WrappingStream.cs | 10 ++++++++++ 2 files changed, 24 insertions(+) diff --git a/src/Kestrel.Core/Internal/Http/HttpUpgradeStream.cs b/src/Kestrel.Core/Internal/Http/HttpUpgradeStream.cs index e7163b7ece..d6fedc0518 100644 --- a/src/Kestrel.Core/Internal/Http/HttpUpgradeStream.cs +++ b/src/Kestrel.Core/Internal/Http/HttpUpgradeStream.cs @@ -145,6 +145,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http return _requestStream.ReadAsync(buffer, offset, count, cancellationToken); } +#if NETCOREAPP2_1 + public override ValueTask ReadAsync(Memory destination, CancellationToken cancellationToken = default) + { + return _requestStream.ReadAsync(destination, cancellationToken); + } +#endif + public override Task CopyToAsync(Stream destination, int bufferSize, CancellationToken cancellationToken) { return _requestStream.CopyToAsync(destination, bufferSize, cancellationToken); @@ -155,6 +162,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http return _responseStream.WriteAsync(buffer, offset, count, cancellationToken); } +#if NETCOREAPP2_1 + public override ValueTask WriteAsync(ReadOnlyMemory source, CancellationToken cancellationToken = default) + { + return _responseStream.WriteAsync(source, cancellationToken); + } +#endif + public override long Seek(long offset, SeekOrigin origin) { return _requestStream.Seek(offset, origin); diff --git a/src/Kestrel.Core/Internal/Infrastructure/WrappingStream.cs b/src/Kestrel.Core/Internal/Infrastructure/WrappingStream.cs index a1c87ad8c8..9485392825 100644 --- a/src/Kestrel.Core/Internal/Infrastructure/WrappingStream.cs +++ b/src/Kestrel.Core/Internal/Infrastructure/WrappingStream.cs @@ -68,6 +68,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure public override Task ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) => _inner.ReadAsync(buffer, offset, count, cancellationToken); +#if NETCOREAPP2_1 + public override ValueTask ReadAsync(Memory destination, CancellationToken cancellationToken = default) + => _inner.ReadAsync(destination, cancellationToken); +#endif + public override int ReadByte() => _inner.ReadByte(); @@ -83,6 +88,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) => _inner.WriteAsync(buffer, offset, count, cancellationToken); +#if NETCOREAPP2_1 + public override ValueTask WriteAsync(ReadOnlyMemory source, CancellationToken cancellationToken = default) + => _inner.WriteAsync(source, cancellationToken); +#endif + public override void WriteByte(byte value) => _inner.WriteByte(value); From d1416e679bcc6604fd86d7a34015fddcf2ef5480 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Thu, 31 May 2018 15:45:26 -0700 Subject: [PATCH 1646/1662] [2.1.1] Provide clearer exception message for breaking change (#2623) - In 2.1, the default transport (Sockets) can no longer bind to certain endpoint types (Unix domain sockets and open socket handles). - The new message recommends manually selecting the libuv transport to work around this issue. --- .../Properties/SocketsStrings.Designer.cs | 4 ++-- src/Kestrel.Transport.Sockets/SocketsStrings.resx | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Kestrel.Transport.Sockets/Properties/SocketsStrings.Designer.cs b/src/Kestrel.Transport.Sockets/Properties/SocketsStrings.Designer.cs index 9d2e7e0182..2d26f8f398 100644 --- a/src/Kestrel.Transport.Sockets/Properties/SocketsStrings.Designer.cs +++ b/src/Kestrel.Transport.Sockets/Properties/SocketsStrings.Designer.cs @@ -11,7 +11,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets = new ResourceManager("Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.SocketsStrings", typeof(SocketsStrings).GetTypeInfo().Assembly); /// - /// Only ListenType.IPEndPoint is supported. + /// Only ListenType.IPEndPoint is supported by the Socket Transport. https://go.microsoft.com/fwlink/?linkid=874850 /// internal static string OnlyIPEndPointsSupported { @@ -19,7 +19,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets } /// - /// Only ListenType.IPEndPoint is supported. + /// Only ListenType.IPEndPoint is supported by the Socket Transport. https://go.microsoft.com/fwlink/?linkid=874850 /// internal static string FormatOnlyIPEndPointsSupported() => GetString("OnlyIPEndPointsSupported"); diff --git a/src/Kestrel.Transport.Sockets/SocketsStrings.resx b/src/Kestrel.Transport.Sockets/SocketsStrings.resx index 79cd2d7303..52b26c66bc 100644 --- a/src/Kestrel.Transport.Sockets/SocketsStrings.resx +++ b/src/Kestrel.Transport.Sockets/SocketsStrings.resx @@ -118,7 +118,7 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - Only ListenType.IPEndPoint is supported. + Only ListenType.IPEndPoint is supported by the Socket Transport. https://go.microsoft.com/fwlink/?linkid=874850 Transport is already bound. From e4d290b601ef646c5e02b5819012b49ad54f5a4e Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Thu, 31 May 2018 16:28:25 -0700 Subject: [PATCH 1647/1662] Fix Json regression in Socket Transport (#2578) --- .../Internal/SocketConnection.cs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/Kestrel.Transport.Sockets/Internal/SocketConnection.cs b/src/Kestrel.Transport.Sockets/Internal/SocketConnection.cs index e1f323abba..47a0dad85c 100644 --- a/src/Kestrel.Transport.Sockets/Internal/SocketConnection.cs +++ b/src/Kestrel.Transport.Sockets/Internal/SocketConnection.cs @@ -20,6 +20,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal internal sealed class SocketConnection : TransportConnection { private static readonly int MinAllocBufferSize = KestrelMemoryPool.MinimumSegmentSize / 2; + private static readonly bool IsWindows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows); private readonly Socket _socket; private readonly PipeScheduler _scheduler; @@ -54,8 +55,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal ConnectionClosed = _connectionClosedTokenSource.Token; - _receiver = new SocketReceiver(_socket, _scheduler); - _sender = new SocketSender(_socket, _scheduler); + // On *nix platforms, Sockets already dispatches to the ThreadPool. + // Yes, the IOQueues are still used for the PipeSchedulers. This is intentional. + // https://github.com/aspnet/KestrelHttpServer/issues/2573 + var awaiterScheduler = IsWindows ? _scheduler : PipeScheduler.Inline; + + _receiver = new SocketReceiver(_socket, awaiterScheduler); + _sender = new SocketSender(_socket, awaiterScheduler); } public override MemoryPool MemoryPool { get; } From ab5fb559e54244d0fa36b86ff18a0363530f4a46 Mon Sep 17 00:00:00 2001 From: "ASP.NET CI" Date: Tue, 12 Jun 2018 19:26:02 +0000 Subject: [PATCH 1648/1662] Update dependencies.props [auto-updated: dependencies] --- build/dependencies.props | 54 ++++++++++++++++++++-------------------- korebuild-lock.txt | 4 +-- 2 files changed, 29 insertions(+), 29 deletions(-) diff --git a/build/dependencies.props b/build/dependencies.props index 3f6b4b6da1..a53bc20e1f 100644 --- a/build/dependencies.props +++ b/build/dependencies.props @@ -5,44 +5,44 @@ 0.10.13 - 2.1.1-rtm-15790 + 2.1.1-rtm-15793 1.10.0 - 2.1.0 - 2.1.0 - 2.1.0 - 2.1.0 - 2.1.0 - 2.1.0 - 2.1.0 - 2.1.0 + 2.1.1 + 2.1.1 + 2.1.1 + 2.1.1 + 2.1.1 + 2.1.1 + 2.1.1 + 2.1.1 2.1.0 - 2.1.0 - 2.1.0 - 2.1.0 - 2.1.0 - 2.1.0 - 2.1.0 - 2.1.0 - 2.1.0 - 2.1.0 - 2.1.0 - 2.1.0 - 2.1.0 - 2.1.0 + 2.1.1 + 2.1.1 + 2.1.1 + 2.1.1 + 2.1.1 + 2.1.1 + 2.1.1 + 2.1.1 + 2.1.1 + 2.1.1 + 2.1.1 + 2.1.1 + 2.1.1 2.0.0 - 2.1.0 - 2.1.0 + 2.1.1 + 2.1.1 15.6.1 4.7.49 2.0.3 11.0.2 4.5.0 4.5.0 - 4.5.0 + 4.5.1 4.5.0 - 4.5.0 + 4.5.1 4.5.0 - 4.5.0 + 4.5.1 1.3.7 0.8.0 2.3.1 diff --git a/korebuild-lock.txt b/korebuild-lock.txt index cd5b409a1e..bc84e0cd53 100644 --- a/korebuild-lock.txt +++ b/korebuild-lock.txt @@ -1,2 +1,2 @@ -version:2.1.1-rtm-15790 -commithash:274c65868e735f29f4078c1884c61c4371ee1fc0 +version:2.1.1-rtm-15793 +commithash:988313f4b064d6c69fc6f7b845b6384a6af3447a From 11ddd9174c7c2af231ad70cf3efad85012e2fd73 Mon Sep 17 00:00:00 2001 From: Nate McMaster Date: Tue, 12 Jun 2018 14:13:52 -0700 Subject: [PATCH 1649/1662] Bumping version from 2.1.1 to 2.1.2 --- version.props | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version.props b/version.props index 669c874829..478dfd16ed 100644 --- a/version.props +++ b/version.props @@ -1,6 +1,6 @@  - 2.1.1 + 2.1.2 rtm $(VersionPrefix) $(VersionPrefix)-$(VersionSuffix)-final From 7f49500ffac8c0d6528ba9c7e331aed6683f89fa Mon Sep 17 00:00:00 2001 From: Nate McMaster Date: Wed, 27 Jun 2018 13:39:48 -0700 Subject: [PATCH 1650/1662] Bumping version from 2.1.2 to 2.1.3 --- version.props | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version.props b/version.props index 478dfd16ed..8d05c92ab8 100644 --- a/version.props +++ b/version.props @@ -1,6 +1,6 @@  - 2.1.2 + 2.1.3 rtm $(VersionPrefix) $(VersionPrefix)-$(VersionSuffix)-final From ac31e5ab30e6f6023ddb12b24f76fa72e764a94a Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Thu, 28 Jun 2018 10:51:22 -0700 Subject: [PATCH 1651/1662] [2.1.3] Consistently handle connection aborts (#2619) * Decouple connection objects from the server (#2535) - Making progress towards being able to use the connection objects on the client side. * Wait for input writer to complete before calling OnConnectionClosed (#2566) * Wait for the ConnectionClosed token to stop tracking connections (#2574) - The prior strategy of waiting for the pipe completed callbacks doesn't work because blocks are returned to the memory pool after the callbacks are fired. * Consistently handle connection resets (#2547) * Provide better connection abort exceptions and logs * void IConnectionDispatcher.OnConnection --- .../InMemoryTransportBenchmark.cs | 1 + .../Kestrel.Performance/Mocks/MockTrace.cs | 1 + .../ConnectionContext.cs | 16 +- .../DefaultConnectionContext.cs | 2 +- .../Adapter/Internal/AdaptedPipeline.cs | 22 +-- src/Kestrel.Core/CoreStrings.resx | 12 ++ .../Internal/ConnectionDispatcher.cs | 4 - .../Internal/Http/Http1Connection.cs | 3 +- .../Internal/Http/Http1ConnectionContext.cs | 2 + .../Internal/Http/Http1OutputProducer.cs | 22 +-- .../Http/HttpProtocol.FeatureCollection.cs | 3 +- .../Internal/Http/HttpProtocol.cs | 66 ++++--- .../Internal/Http/IHttpOutputProducer.cs | 3 +- .../Internal/Http2/Http2Connection.cs | 12 +- .../Internal/Http2/Http2OutputProducer.cs | 3 +- .../Internal/Http2/Http2Stream.cs | 11 ++ src/Kestrel.Core/Internal/HttpConnection.cs | 72 ++++--- .../Internal/HttpConnectionMiddleware.cs | 48 +++-- .../Internal/IRequestProcessor.cs | 4 +- ...HttpConnectionManagerShutdownExtensions.cs | 2 +- .../Internal/Infrastructure/IKestrelTrace.cs | 2 + .../Internal/Infrastructure/KestrelTrace.cs | 20 +- .../Properties/CoreStrings.Designer.cs | 56 ++++++ .../Internal/IConnectionDispatcher.cs | 2 - .../Internal/TransportConnection.cs | 9 +- .../Internal/LibuvConnection.cs | 103 ++++++---- .../Internal/LibuvConnectionContext.cs | 23 --- .../Internal/LibuvConstants.cs | 65 ++++++- .../Internal/LibuvOutputConsumer.cs | 18 +- .../Internal/Listener.cs | 10 +- .../Internal/ListenerContext.cs | 35 ++++ .../Internal/ListenerSecondary.cs | 18 +- .../Internal/SocketConnection.cs | 56 ++++-- .../SocketTransport.cs | 24 ++- .../ConnectionDispatcherTests.cs | 9 +- .../Http1ConnectionTests.cs | 8 +- .../Http2ConnectionTests.cs | 8 +- .../Kestrel.Core.Tests/HttpConnectionTests.cs | 2 + test/Kestrel.Core.Tests/KestrelServerTests.cs | 2 +- test/Kestrel.Core.Tests/MessageBodyTests.cs | 2 +- .../Kestrel.Core.Tests/OutputProducerTests.cs | 18 +- test/Kestrel.Core.Tests/TestInput.cs | 2 + .../ConnectionLimitTests.cs | 8 +- .../EventSourceTests.cs | 2 +- .../HttpProtocolSelectionTests.cs | 2 +- test/Kestrel.FunctionalTests/HttpsTests.cs | 10 +- .../LoggingConnectionAdapterTests.cs | 2 +- test/Kestrel.FunctionalTests/RequestTests.cs | 54 +++--- test/Kestrel.FunctionalTests/ResponseTests.cs | 183 +++++++++++------- test/Kestrel.FunctionalTests/UpgradeTests.cs | 14 +- .../LibuvConnectionTests.cs | 16 +- .../LibuvOutputConsumerTests.cs | 14 +- .../TestHelpers/MockConnectionDispatcher.cs | 3 - test/shared/TaskTimeoutExtensions.cs | 20 ++ test/shared/TestConnection.cs | 8 +- 55 files changed, 744 insertions(+), 393 deletions(-) delete mode 100644 src/Kestrel.Transport.Libuv/Internal/LibuvConnectionContext.cs create mode 100644 test/shared/TaskTimeoutExtensions.cs diff --git a/benchmarks/Kestrel.Performance/InMemoryTransportBenchmark.cs b/benchmarks/Kestrel.Performance/InMemoryTransportBenchmark.cs index 1816531088..0e77ddd9c5 100644 --- a/benchmarks/Kestrel.Performance/InMemoryTransportBenchmark.cs +++ b/benchmarks/Kestrel.Performance/InMemoryTransportBenchmark.cs @@ -3,6 +3,7 @@ using BenchmarkDotNet.Attributes; using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Connections; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; diff --git a/benchmarks/Kestrel.Performance/Mocks/MockTrace.cs b/benchmarks/Kestrel.Performance/Mocks/MockTrace.cs index a06661cf3a..8386402a78 100644 --- a/benchmarks/Kestrel.Performance/Mocks/MockTrace.cs +++ b/benchmarks/Kestrel.Performance/Mocks/MockTrace.cs @@ -44,6 +44,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance public void RequestBodyDrainTimedOut(string connectionId, string traceIdentifier) { } public void RequestBodyMininumDataRateNotSatisfied(string connectionId, string traceIdentifier, double rate) { } public void ResponseMininumDataRateNotSatisfied(string connectionId, string traceIdentifier) { } + public void ApplicationAbortedConnection(string connectionId, string traceIdentifier) { } public void Http2ConnectionError(string connectionId, Http2ConnectionErrorException ex) { } public void Http2StreamError(string connectionId, Http2StreamErrorException ex) { } public void HPackDecodingError(string connectionId, int streamId, HPackDecodingException ex) { } diff --git a/src/Connections.Abstractions/ConnectionContext.cs b/src/Connections.Abstractions/ConnectionContext.cs index aba4abdfc0..bb942f2627 100644 --- a/src/Connections.Abstractions/ConnectionContext.cs +++ b/src/Connections.Abstractions/ConnectionContext.cs @@ -1,5 +1,9 @@ -using System.Collections.Generic; +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System.Collections.Generic; using System.IO.Pipelines; +using Microsoft.AspNetCore.Connections.Features; using Microsoft.AspNetCore.Http.Features; namespace Microsoft.AspNetCore.Connections @@ -13,5 +17,15 @@ namespace Microsoft.AspNetCore.Connections public abstract IDictionary Items { get; set; } public abstract IDuplexPipe Transport { get; set; } + + public virtual void Abort(ConnectionAbortedException abortReason) + { + // We expect this to be overridden, but this helps maintain back compat + // with implementations of ConnectionContext that predate the addition of + // ConnectioContext.Abort() + Features.Get()?.Abort(); + } + + public virtual void Abort() => Abort(new ConnectionAbortedException("The connection was aborted by the application.")); } } diff --git a/src/Connections.Abstractions/DefaultConnectionContext.cs b/src/Connections.Abstractions/DefaultConnectionContext.cs index 1b161c7253..56c5d0424f 100644 --- a/src/Connections.Abstractions/DefaultConnectionContext.cs +++ b/src/Connections.Abstractions/DefaultConnectionContext.cs @@ -65,7 +65,7 @@ namespace Microsoft.AspNetCore.Connections public CancellationToken ConnectionClosed { get; set; } - public virtual void Abort() + public override void Abort(ConnectionAbortedException abortReason) { ThreadPool.QueueUserWorkItem(cts => ((CancellationTokenSource)cts).Cancel(), _connectionClosedTokenSource); } diff --git a/src/Kestrel.Core/Adapter/Internal/AdaptedPipeline.cs b/src/Kestrel.Core/Adapter/Internal/AdaptedPipeline.cs index 221c4c1b84..2cbb76e5b1 100644 --- a/src/Kestrel.Core/Adapter/Internal/AdaptedPipeline.cs +++ b/src/Kestrel.Core/Adapter/Internal/AdaptedPipeline.cs @@ -6,7 +6,9 @@ using System.IO; using System.IO.Pipelines; using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; +using Microsoft.Extensions.Logging; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal { @@ -15,23 +17,24 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal private static readonly int MinAllocBufferSize = KestrelMemoryPool.MinimumSegmentSize / 2; private readonly IDuplexPipe _transport; - private readonly IDuplexPipe _application; public AdaptedPipeline(IDuplexPipe transport, - IDuplexPipe application, Pipe inputPipe, - Pipe outputPipe) + Pipe outputPipe, + IKestrelTrace log) { _transport = transport; - _application = application; Input = inputPipe; Output = outputPipe; + Log = log; } public Pipe Input { get; } public Pipe Output { get; } + public IKestrelTrace Log { get; } + PipeReader IDuplexPipe.Input => Input.Reader; PipeWriter IDuplexPipe.Output => Output.Writer; @@ -47,8 +50,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal private async Task WriteOutputAsync(Stream stream) { - Exception error = null; - try { if (stream == null) @@ -63,13 +64,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal try { - if (result.IsCanceled) - { - // Forward the cancellation to the transport pipe - _application.Input.CancelPendingRead(); - break; - } - if (buffer.IsEmpty) { if (result.IsCompleted) @@ -108,7 +102,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal } catch (Exception ex) { - error = ex; + Log.LogError(0, ex, $"{nameof(AdaptedPipeline)}.{nameof(WriteOutputAsync)}"); } finally { diff --git a/src/Kestrel.Core/CoreStrings.resx b/src/Kestrel.Core/CoreStrings.resx index 0ba93c9219..ee80a16312 100644 --- a/src/Kestrel.Core/CoreStrings.resx +++ b/src/Kestrel.Core/CoreStrings.resx @@ -506,4 +506,16 @@ For more information on configuring HTTPS see https://go.microsoft.com/fwlink/?l Reading the request body timed out due to data arriving too slowly. See MinRequestBodyDataRate. + + The connection was aborted by the application. + + + The connection was aborted because the server is shutting down and request processing didn't complete within the time specified by HostOptions.ShutdownTimeout. + + + The connection was timed out by the server because the response was not read by the client at the specified minimum data rate. + + + The connection was timed out by the server. + \ No newline at end of file diff --git a/src/Kestrel.Core/Internal/ConnectionDispatcher.cs b/src/Kestrel.Core/Internal/ConnectionDispatcher.cs index f2d512b955..54b2d4a7e4 100644 --- a/src/Kestrel.Core/Internal/ConnectionDispatcher.cs +++ b/src/Kestrel.Core/Internal/ConnectionDispatcher.cs @@ -53,8 +53,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal { using (BeginConnectionScope(connectionContext)) { - Log.ConnectionStart(connectionContext.ConnectionId); - try { await _connectionDelegate(connectionContext); @@ -63,8 +61,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal { Log.LogCritical(0, ex, $"{nameof(ConnectionDispatcher)}.{nameof(Execute)}() {connectionContext.ConnectionId}"); } - - Log.ConnectionStop(connectionContext.ConnectionId); } } diff --git a/src/Kestrel.Core/Internal/Http/Http1Connection.cs b/src/Kestrel.Core/Internal/Http/Http1Connection.cs index f93a7997fa..61eac8a37c 100644 --- a/src/Kestrel.Core/Internal/Http/Http1Connection.cs +++ b/src/Kestrel.Core/Internal/Http/Http1Connection.cs @@ -45,12 +45,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http _requestHeadersTimeoutTicks = ServerOptions.Limits.RequestHeadersTimeout.Ticks; Output = new Http1OutputProducer( - _context.Application.Input, _context.Transport.Output, _context.ConnectionId, + _context.ConnectionContext, _context.ServiceContext.Log, _context.TimeoutControl, - _context.ConnectionFeatures.Get(), _context.ConnectionFeatures.Get()); } diff --git a/src/Kestrel.Core/Internal/Http/Http1ConnectionContext.cs b/src/Kestrel.Core/Internal/Http/Http1ConnectionContext.cs index 9dbcee29e7..28b5f95ed4 100644 --- a/src/Kestrel.Core/Internal/Http/Http1ConnectionContext.cs +++ b/src/Kestrel.Core/Internal/Http/Http1ConnectionContext.cs @@ -4,6 +4,7 @@ using System.Buffers; using System.IO.Pipelines; using System.Net; +using Microsoft.AspNetCore.Connections; using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; @@ -13,6 +14,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { public string ConnectionId { get; set; } public ServiceContext ServiceContext { get; set; } + public ConnectionContext ConnectionContext { get; set; } public IFeatureCollection ConnectionFeatures { get; set; } public MemoryPool MemoryPool { get; set; } public IPEndPoint RemoteEndPoint { get; set; } diff --git a/src/Kestrel.Core/Internal/Http/Http1OutputProducer.cs b/src/Kestrel.Core/Internal/Http/Http1OutputProducer.cs index 4ef0dff24e..0fd62301bd 100644 --- a/src/Kestrel.Core/Internal/Http/Http1OutputProducer.cs +++ b/src/Kestrel.Core/Internal/Http/Http1OutputProducer.cs @@ -8,6 +8,7 @@ using System.Runtime.CompilerServices; using System.Text; using System.Threading; using System.Threading.Tasks; +using Microsoft.AspNetCore.Connections; using Microsoft.AspNetCore.Connections.Features; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; @@ -22,9 +23,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http private static readonly ReadOnlyMemory _endChunkedResponseBytes = new ReadOnlyMemory(Encoding.ASCII.GetBytes("0\r\n\r\n")); private readonly string _connectionId; + private readonly ConnectionContext _connectionContext; private readonly ITimeoutControl _timeoutControl; private readonly IKestrelTrace _log; - private readonly IConnectionLifetimeFeature _lifetimeFeature; private readonly IBytesWrittenFeature _transportBytesWrittenFeature; // This locks access to to all of the below fields @@ -36,7 +37,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http private long _totalBytesCommitted; private readonly PipeWriter _pipeWriter; - private readonly PipeReader _outputPipeReader; // https://github.com/dotnet/corefxlab/issues/1334 // Pipelines don't support multiple awaiters on flush @@ -48,21 +48,19 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http private ValueTask _flushTask; public Http1OutputProducer( - PipeReader outputPipeReader, PipeWriter pipeWriter, string connectionId, + ConnectionContext connectionContext, IKestrelTrace log, ITimeoutControl timeoutControl, - IConnectionLifetimeFeature lifetimeFeature, IBytesWrittenFeature transportBytesWrittenFeature) { - _outputPipeReader = outputPipeReader; _pipeWriter = pipeWriter; _connectionId = connectionId; + _connectionContext = connectionContext; _timeoutControl = timeoutControl; _log = log; _flushCompleted = OnFlushCompleted; - _lifetimeFeature = lifetimeFeature; _transportBytesWrittenFeature = transportBytesWrittenFeature; } @@ -169,7 +167,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http } } - public void Abort(Exception error) + public void Abort(ConnectionAbortedException error) { // Abort can be called after Dispose if there's a flush timeout. // It's important to still call _lifetimeFeature.Abort() in this case. @@ -181,17 +179,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http return; } + _aborted = true; + _connectionContext.Abort(error); + if (!_completed) { _log.ConnectionDisconnect(_connectionId); _completed = true; - - _outputPipeReader.CancelPendingRead(); - _pipeWriter.Complete(error); + _pipeWriter.Complete(); } - - _aborted = true; - _lifetimeFeature.Abort(); } } diff --git a/src/Kestrel.Core/Internal/Http/HttpProtocol.FeatureCollection.cs b/src/Kestrel.Core/Internal/Http/HttpProtocol.FeatureCollection.cs index 3c53523f8a..118a4ca97e 100644 --- a/src/Kestrel.Core/Internal/Http/HttpProtocol.FeatureCollection.cs +++ b/src/Kestrel.Core/Internal/Http/HttpProtocol.FeatureCollection.cs @@ -283,7 +283,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http void IHttpRequestLifetimeFeature.Abort() { - Abort(new ConnectionAbortedException()); + Log.ApplicationAbortedConnection(ConnectionId, TraceIdentifier); + Abort(new ConnectionAbortedException(CoreStrings.ConnectionAbortedByApplication)); } } } diff --git a/src/Kestrel.Core/Internal/Http/HttpProtocol.cs b/src/Kestrel.Core/Internal/Http/HttpProtocol.cs index 4e35490a79..0c759c4451 100644 --- a/src/Kestrel.Core/Internal/Http/HttpProtocol.cs +++ b/src/Kestrel.Core/Internal/Http/HttpProtocol.cs @@ -39,11 +39,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http protected Streams _streams; - protected Stack, object>> _onStarting; - protected Stack, object>> _onCompleted; + private Stack, object>> _onStarting; + private Stack, object>> _onCompleted; - protected volatile int _requestAborted; - protected CancellationTokenSource _abortedCts; + private int _requestAborted; + private volatile int _ioCompleted; + private CancellationTokenSource _abortedCts; private CancellationToken? _manuallySetRequestAbortToken; protected RequestProcessingStatus _requestProcessingStatus; @@ -51,15 +52,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http protected bool _upgradeAvailable; private bool _canHaveBody; private bool _autoChunk; - protected Exception _applicationException; + private Exception _applicationException; private BadHttpRequestException _requestRejectedException; protected HttpVersion _httpVersion; private string _requestId; - protected int _requestHeadersParsed; + private int _requestHeadersParsed; - protected long _responseBytesWritten; + private long _responseBytesWritten; private readonly IHttpProtocolContext _context; @@ -247,7 +248,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http var cts = _abortedCts; return cts != null ? cts.Token : - (_requestAborted == 1) ? new CancellationToken(true) : + (_ioCompleted == 1) ? new CancellationToken(true) : RequestAbortedSource.Token; } set @@ -272,7 +273,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http var cts = LazyInitializer.EnsureInitialized(ref _abortedCts, () => new CancellationTokenSource()) ?? new CancellationTokenSource(); - if (_requestAborted == 1) + if (_ioCompleted == 1) { cts.Cancel(); } @@ -410,32 +411,40 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http } } - /// - /// Immediately kill the connection and poison the request and response streams with an error if there is one. - /// - public void Abort(Exception error) + public void OnInputOrOutputCompleted() { - if (Interlocked.Exchange(ref _requestAborted, 1) != 0) + if (Interlocked.Exchange(ref _ioCompleted, 1) != 0) { return; } _keepAlive = false; - // If Abort() isn't called with an exception, there was a FIN. In this case, even though the connection is - // still closed immediately, we allow the app to drain the data in the request buffer. If the request data - // was truncated, MessageBody will complete the RequestBodyPipe with an error. - if (error != null) - { - _streams?.Abort(error); - } - - Output.Abort(error); + Output.Dispose(); // Potentially calling user code. CancelRequestAbortedToken logs any exceptions. ServiceContext.Scheduler.Schedule(state => ((HttpProtocol)state).CancelRequestAbortedToken(), this); } + /// + /// Immediately kill the connection and poison the request and response streams with an error if there is one. + /// + public void Abort(ConnectionAbortedException abortReason) + { + if (Interlocked.Exchange(ref _requestAborted, 1) != 0) + { + return; + } + + _streams?.Abort(abortReason); + + // Abort output prior to calling OnIOCompleted() to give the transport the chance to + // complete the input with the correct error and message. + Output.Abort(abortReason); + + OnInputOrOutputCompleted(); + } + public void OnHeader(Span name, Span value) { _requestHeadersParsed++; @@ -543,7 +552,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http // Run the application code for this request await application.ProcessRequestAsync(httpContext); - if (_requestAborted == 0) + if (_ioCompleted == 0) { VerifyResponseContentLength(); } @@ -579,8 +588,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http // 4XX responses are written by TryProduceInvalidRequestResponse during connection tear down. if (_requestRejectedException == null) { - // If _requestAbort is set, the connection has already been closed. - if (_requestAborted == 0) + if (_ioCompleted == 0) { // Call ProduceEnd() before consuming the rest of the request body to prevent // delaying clients waiting for the chunk terminator: @@ -612,7 +620,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http application.DisposeContext(httpContext, _applicationException); // Even for non-keep-alive requests, try to consume the entire body to avoid RSTs. - if (_requestAborted == 0 && _requestRejectedException == null && !messageBody.IsEmpty) + if (_ioCompleted == 0 && _requestRejectedException == null && !messageBody.IsEmpty) { await messageBody.ConsumeAsync(); } @@ -1010,8 +1018,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http protected Task TryProduceInvalidRequestResponse() { - // If _requestAborted is set, the connection has already been closed. - if (_requestRejectedException != null && _requestAborted == 0) + // If _ioCompleted is set, the connection has already been closed. + if (_requestRejectedException != null && _ioCompleted == 0) { return ProduceEnd(); } diff --git a/src/Kestrel.Core/Internal/Http/IHttpOutputProducer.cs b/src/Kestrel.Core/Internal/Http/IHttpOutputProducer.cs index 0c45253bdc..41dfdbbbec 100644 --- a/src/Kestrel.Core/Internal/Http/IHttpOutputProducer.cs +++ b/src/Kestrel.Core/Internal/Http/IHttpOutputProducer.cs @@ -5,12 +5,13 @@ using System; using System.IO.Pipelines; using System.Threading; using System.Threading.Tasks; +using Microsoft.AspNetCore.Connections; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { public interface IHttpOutputProducer : IDisposable { - void Abort(Exception error); + void Abort(ConnectionAbortedException abortReason); Task WriteAsync(Func callback, T state); Task FlushAsync(CancellationToken cancellationToken); Task Write100ContinueAsync(CancellationToken cancellationToken); diff --git a/src/Kestrel.Core/Internal/Http2/Http2Connection.cs b/src/Kestrel.Core/Internal/Http2/Http2Connection.cs index 549e804d33..94ff8f5c54 100644 --- a/src/Kestrel.Core/Internal/Http2/Http2Connection.cs +++ b/src/Kestrel.Core/Internal/Http2/Http2Connection.cs @@ -89,7 +89,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 public IFeatureCollection ConnectionFeatures => _context.ConnectionFeatures; - public void Abort(Exception ex) + public void OnInputOrOutputCompleted() + { + _stopping = true; + _frameWriter.Abort(ex: null); + } + + public void Abort(ConnectionAbortedException ex) { _stopping = true; _frameWriter.Abort(ex); @@ -202,7 +208,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 { foreach (var stream in _streams.Values) { - stream.Abort(error); + stream.Http2Abort(error); } await _frameWriter.WriteGoAwayAsync(_highestOpenedStreamId, errorCode); @@ -464,7 +470,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 if (_streams.TryGetValue(_incomingFrame.StreamId, out var stream)) { - stream.Abort(error: null); + stream.Abort(abortReason: null); } return Task.CompletedTask; diff --git a/src/Kestrel.Core/Internal/Http2/Http2OutputProducer.cs b/src/Kestrel.Core/Internal/Http2/Http2OutputProducer.cs index 0fe1fbf344..e701654d1e 100644 --- a/src/Kestrel.Core/Internal/Http2/Http2OutputProducer.cs +++ b/src/Kestrel.Core/Internal/Http2/Http2OutputProducer.cs @@ -5,6 +5,7 @@ using System; using System.IO.Pipelines; using System.Threading; using System.Threading.Tasks; +using Microsoft.AspNetCore.Connections; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; @@ -25,7 +26,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 { } - public void Abort(Exception error) + public void Abort(ConnectionAbortedException error) { // TODO: RST_STREAM? } diff --git a/src/Kestrel.Core/Internal/Http2/Http2Stream.cs b/src/Kestrel.Core/Internal/Http2/Http2Stream.cs index b1f754884a..0234879a37 100644 --- a/src/Kestrel.Core/Internal/Http2/Http2Stream.cs +++ b/src/Kestrel.Core/Internal/Http2/Http2Stream.cs @@ -142,5 +142,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 RequestBodyPipe.Writer.Complete(ex); } } + + // TODO: The HTTP/2 tests expect the request and response streams to be aborted with + // non-ConnectionAbortedExceptions. The abortReasons can include things like + // Http2ConnectionErrorException which don't derive from IOException or + // OperationCanceledException. This is probably not a good idea. + public void Http2Abort(Exception abortReason) + { + _streams?.Abort(abortReason); + + OnInputOrOutputCompleted(); + } } } diff --git a/src/Kestrel.Core/Internal/HttpConnection.cs b/src/Kestrel.Core/Internal/HttpConnection.cs index 5673485d77..d1a32c6a29 100644 --- a/src/Kestrel.Core/Internal/HttpConnection.cs +++ b/src/Kestrel.Core/Internal/HttpConnection.cs @@ -10,6 +10,8 @@ using System.IO.Pipelines; using System.Net; using System.Threading; using System.Threading.Tasks; +using Microsoft.AspNetCore.Connections; +using Microsoft.AspNetCore.Connections.Features; using Microsoft.AspNetCore.Hosting.Server; using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal; @@ -105,6 +107,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal { try { + // TODO: When we start tracking all connection middleware for shutdown, go back + // to logging connections tart and stop in ConnectionDispatcher so we get these + // logs for all connection middleware. + Log.ConnectionStart(ConnectionId); KestrelEventSource.Log.ConnectionStart(this); AdaptedPipeline adaptedPipeline = null; @@ -119,9 +125,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal if (_context.ConnectionAdapters.Count > 0) { adaptedPipeline = new AdaptedPipeline(_adaptedTransport, - application, new Pipe(AdaptedInputPipeOptions), - new Pipe(AdaptedOutputPipeOptions)); + new Pipe(AdaptedOutputPipeOptions), + Log); _adaptedTransport = adaptedPipeline; } @@ -196,6 +202,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal _context.ServiceContext.ConnectionManager.UpgradedConnectionCount.ReleaseOne(); } + Log.ConnectionStop(ConnectionId); KestrelEventSource.Log.ConnectionStop(this); } } @@ -217,6 +224,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal LocalEndPoint = LocalEndPoint, RemoteEndPoint = RemoteEndPoint, ServiceContext = _context.ServiceContext, + ConnectionContext = _context.ConnectionContext, TimeoutControl = this, Transport = transport, Application = application @@ -238,10 +246,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal }); } - public void OnConnectionClosed(Exception ex) + public void OnConnectionClosed() { - Abort(ex); - _socketClosedTcs.TrySetResult(null); } @@ -252,15 +258,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal switch (_protocolSelectionState) { case ProtocolSelectionState.Initializing: - CloseUninitializedConnection(); - _protocolSelectionState = ProtocolSelectionState.Stopped; + CloseUninitializedConnection(abortReason: null); + _protocolSelectionState = ProtocolSelectionState.Aborted; break; case ProtocolSelectionState.Selected: _requestProcessor.StopProcessingNextRequest(); - _protocolSelectionState = ProtocolSelectionState.Stopping; break; - case ProtocolSelectionState.Stopping: - case ProtocolSelectionState.Stopped: + case ProtocolSelectionState.Aborted: break; } } @@ -268,28 +272,47 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal return _lifetimeTask; } - public void Abort(Exception ex) + public void OnInputOrOutputCompleted() { lock (_protocolSelectionLock) { switch (_protocolSelectionState) { case ProtocolSelectionState.Initializing: - CloseUninitializedConnection(); + CloseUninitializedConnection(abortReason: null); + _protocolSelectionState = ProtocolSelectionState.Aborted; break; case ProtocolSelectionState.Selected: - case ProtocolSelectionState.Stopping: - _requestProcessor.Abort(ex); + _requestProcessor.OnInputOrOutputCompleted(); break; - case ProtocolSelectionState.Stopped: + case ProtocolSelectionState.Aborted: break; } - _protocolSelectionState = ProtocolSelectionState.Stopped; } } - public Task AbortAsync(Exception ex) + public void Abort(ConnectionAbortedException ex) + { + lock (_protocolSelectionLock) + { + switch (_protocolSelectionState) + { + case ProtocolSelectionState.Initializing: + CloseUninitializedConnection(ex); + break; + case ProtocolSelectionState.Selected: + _requestProcessor.Abort(ex); + break; + case ProtocolSelectionState.Aborted: + break; + } + + _protocolSelectionState = ProtocolSelectionState.Aborted; + } + } + + public Task AbortAsync(ConnectionAbortedException ex) { Abort(ex); @@ -370,7 +393,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal public void Tick(DateTimeOffset now) { - if (_protocolSelectionState == ProtocolSelectionState.Stopped) + if (_protocolSelectionState == ProtocolSelectionState.Aborted) { // It's safe to check for timeouts on a dead connection, // but try not to in order to avoid extraneous logs. @@ -416,7 +439,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal break; case TimeoutAction.AbortConnection: // This is actually supported with HTTP/2! - Abort(new TimeoutException()); + Abort(new ConnectionAbortedException(CoreStrings.ConnectionTimedOutByServer)); break; } } @@ -479,7 +502,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal { RequestTimedOut = true; Log.ResponseMininumDataRateNotSatisfied(_http1Connection.ConnectionIdFeature, _http1Connection.TraceIdentifier); - Abort(new TimeoutException()); + Abort(new ConnectionAbortedException(CoreStrings.ConnectionTimedBecauseResponseMininumDataRateNotSatisfied)); } } } @@ -619,13 +642,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal ResetTimeout(timeSpan.Ticks, TimeoutAction.AbortConnection); } - private void CloseUninitializedConnection() + private void CloseUninitializedConnection(ConnectionAbortedException abortReason) { Debug.Assert(_adaptedTransport != null); - // CancelPendingRead signals the transport directly to close the connection - // without any potential interference from connection adapters. - _context.Application.Input.CancelPendingRead(); + _context.ConnectionContext.Abort(abortReason); _adaptedTransport.Input.Complete(); _adaptedTransport.Output.Complete(); @@ -635,8 +656,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal { Initializing, Selected, - Stopping, - Stopped + Aborted } } } diff --git a/src/Kestrel.Core/Internal/HttpConnectionMiddleware.cs b/src/Kestrel.Core/Internal/HttpConnectionMiddleware.cs index 598dae82d8..f7ffda4654 100644 --- a/src/Kestrel.Core/Internal/HttpConnectionMiddleware.cs +++ b/src/Kestrel.Core/Internal/HttpConnectionMiddleware.cs @@ -1,11 +1,14 @@ -using System.Collections.Generic; +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System.Collections.Generic; using System.Net; using System.Threading; using System.Threading.Tasks; -using Microsoft.AspNetCore.Hosting.Server; -using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Connections; using Microsoft.AspNetCore.Connections.Features; +using Microsoft.AspNetCore.Hosting.Server; +using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal; using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; @@ -30,7 +33,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal _connectionAdapters = adapters; } - public Task OnConnectionAsync(ConnectionContext connectionContext) + public async Task OnConnectionAsync(ConnectionContext connectionContext) { // We need the transport feature so that we can cancel the output reader that the transport is using // This is a bit of a hack but it preserves the existing semantics @@ -54,6 +57,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal }; var connectionFeature = connectionContext.Features.Get(); + var lifetimeFeature = connectionContext.Features.Get(); if (connectionFeature != null) { @@ -72,19 +76,33 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal var processingTask = connection.StartRequestProcessing(_application); - connectionContext.Transport.Input.OnWriterCompleted((error, state) => - { - ((HttpConnection)state).Abort(error); - }, - connection); + connectionContext.Transport.Input.OnWriterCompleted( + (_, state) => ((HttpConnection)state).OnInputOrOutputCompleted(), + connection); - connectionContext.Transport.Output.OnReaderCompleted((error, state) => - { - ((HttpConnection)state).OnConnectionClosed(error); - }, - connection); + connectionContext.Transport.Output.OnReaderCompleted( + (_, state) => ((HttpConnection)state).OnInputOrOutputCompleted(), + connection); - return processingTask; + await CancellationTokenAsTask(lifetimeFeature.ConnectionClosed); + + connection.OnConnectionClosed(); + + await processingTask; + } + + private static Task CancellationTokenAsTask(CancellationToken token) + { + if (token.IsCancellationRequested) + { + return Task.CompletedTask; + } + + // Transports already dispatch prior to tripping ConnectionClosed + // since application code can register to this token. + var tcs = new TaskCompletionSource(); + token.Register(() => tcs.SetResult(null)); + return tcs.Task; } } } diff --git a/src/Kestrel.Core/Internal/IRequestProcessor.cs b/src/Kestrel.Core/Internal/IRequestProcessor.cs index 5b40735ac8..d7385f9b96 100644 --- a/src/Kestrel.Core/Internal/IRequestProcessor.cs +++ b/src/Kestrel.Core/Internal/IRequestProcessor.cs @@ -3,6 +3,7 @@ using System; using System.Threading.Tasks; +using Microsoft.AspNetCore.Connections; using Microsoft.AspNetCore.Hosting.Server; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal @@ -11,6 +12,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal { Task ProcessRequestsAsync(IHttpApplication application); void StopProcessingNextRequest(); - void Abort(Exception ex); + void OnInputOrOutputCompleted(); + void Abort(ConnectionAbortedException ex); } } \ No newline at end of file diff --git a/src/Kestrel.Core/Internal/Infrastructure/HttpConnectionManagerShutdownExtensions.cs b/src/Kestrel.Core/Internal/Infrastructure/HttpConnectionManagerShutdownExtensions.cs index 24400fedef..1b601c919b 100644 --- a/src/Kestrel.Core/Internal/Infrastructure/HttpConnectionManagerShutdownExtensions.cs +++ b/src/Kestrel.Core/Internal/Infrastructure/HttpConnectionManagerShutdownExtensions.cs @@ -26,7 +26,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure public static async Task AbortAllConnectionsAsync(this HttpConnectionManager connectionManager) { var abortTasks = new List(); - var canceledException = new ConnectionAbortedException(); + var canceledException = new ConnectionAbortedException(CoreStrings.ConnectionAbortedDuringServerShutdown); connectionManager.Walk(connection => { diff --git a/src/Kestrel.Core/Internal/Infrastructure/IKestrelTrace.cs b/src/Kestrel.Core/Internal/Infrastructure/IKestrelTrace.cs index e58decaafe..caaf66cfae 100644 --- a/src/Kestrel.Core/Internal/Infrastructure/IKestrelTrace.cs +++ b/src/Kestrel.Core/Internal/Infrastructure/IKestrelTrace.cs @@ -52,6 +52,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure void ResponseMininumDataRateNotSatisfied(string connectionId, string traceIdentifier); + void ApplicationAbortedConnection(string connectionId, string traceIdentifier); + void Http2ConnectionError(string connectionId, Http2ConnectionErrorException ex); void Http2StreamError(string connectionId, Http2StreamErrorException ex); diff --git a/src/Kestrel.Core/Internal/Infrastructure/KestrelTrace.cs b/src/Kestrel.Core/Internal/Infrastructure/KestrelTrace.cs index b9c0e98d5a..3ef1aa1721 100644 --- a/src/Kestrel.Core/Internal/Infrastructure/KestrelTrace.cs +++ b/src/Kestrel.Core/Internal/Infrastructure/KestrelTrace.cs @@ -65,12 +65,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal private static readonly Action _requestBodyMinimumDataRateNotSatisfied = LoggerMessage.Define(LogLevel.Information, new EventId(27, nameof(RequestBodyMininumDataRateNotSatisfied)), @"Connection id ""{ConnectionId}"", Request id ""{TraceIdentifier}"": the request timed out because it was not sent by the client at a minimum of {Rate} bytes/second."); - private static readonly Action _requestBodyNotEntirelyRead = - LoggerMessage.Define(LogLevel.Information, new EventId(32, nameof(RequestBodyNotEntirelyRead)), @"Connection id ""{ConnectionId}"", Request id ""{TraceIdentifier}"": the application completed without reading the entire request body."); - - private static readonly Action _requestBodyDrainTimedOut = - LoggerMessage.Define(LogLevel.Information, new EventId(33, nameof(RequestBodyDrainTimedOut)), @"Connection id ""{ConnectionId}"", Request id ""{TraceIdentifier}"": automatic draining of the request body timed out after taking over 5 seconds."); - private static readonly Action _responseMinimumDataRateNotSatisfied = LoggerMessage.Define(LogLevel.Information, new EventId(28, nameof(ResponseMininumDataRateNotSatisfied)), @"Connection id ""{ConnectionId}"", Request id ""{TraceIdentifier}"": the connection was closed because the response was not read by the client at the specified minimum data rate."); @@ -83,6 +77,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal private static readonly Action _hpackDecodingError = LoggerMessage.Define(LogLevel.Information, new EventId(31, nameof(HPackDecodingError)), @"Connection id ""{ConnectionId}"": HPACK decoding error while decoding headers for stream ID {StreamId}."); + private static readonly Action _requestBodyNotEntirelyRead = + LoggerMessage.Define(LogLevel.Information, new EventId(32, nameof(RequestBodyNotEntirelyRead)), @"Connection id ""{ConnectionId}"", Request id ""{TraceIdentifier}"": the application completed without reading the entire request body."); + + private static readonly Action _requestBodyDrainTimedOut = + LoggerMessage.Define(LogLevel.Information, new EventId(33, nameof(RequestBodyDrainTimedOut)), @"Connection id ""{ConnectionId}"", Request id ""{TraceIdentifier}"": automatic draining of the request body timed out after taking over 5 seconds."); + + private static readonly Action _applicationAbortedConnection = + LoggerMessage.Define(LogLevel.Information, new EventId(34, nameof(RequestBodyDrainTimedOut)), @"Connection id ""{ConnectionId}"", Request id ""{TraceIdentifier}"": the application aborted the connection."); + protected readonly ILogger _logger; public KestrelTrace(ILogger logger) @@ -195,6 +198,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal _responseMinimumDataRateNotSatisfied(_logger, connectionId, traceIdentifier, null); } + public virtual void ApplicationAbortedConnection(string connectionId, string traceIdentifier) + { + _applicationAbortedConnection(_logger, connectionId, traceIdentifier, null); + } + public virtual void Http2ConnectionError(string connectionId, Http2ConnectionErrorException ex) { _http2ConnectionError(_logger, connectionId, ex); diff --git a/src/Kestrel.Core/Properties/CoreStrings.Designer.cs b/src/Kestrel.Core/Properties/CoreStrings.Designer.cs index dab35d664d..c813873491 100644 --- a/src/Kestrel.Core/Properties/CoreStrings.Designer.cs +++ b/src/Kestrel.Core/Properties/CoreStrings.Designer.cs @@ -1820,6 +1820,62 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core internal static string FormatBadRequest_RequestBodyTimeout() => GetString("BadRequest_RequestBodyTimeout"); + /// + /// The connection was aborted by the application. + /// + internal static string ConnectionAbortedByApplication + { + get => GetString("ConnectionAbortedByApplication"); + } + + /// + /// The connection was aborted by the application. + /// + internal static string FormatConnectionAbortedByApplication() + => GetString("ConnectionAbortedByApplication"); + + /// + /// The connection was aborted because the server is shutting down and request processing didn't complete within the time specified by HostOptions.ShutdownTimeout. + /// + internal static string ConnectionAbortedDuringServerShutdown + { + get => GetString("ConnectionAbortedDuringServerShutdown"); + } + + /// + /// The connection was aborted because the server is shutting down and request processing didn't complete within the time specified by HostOptions.ShutdownTimeout. + /// + internal static string FormatConnectionAbortedDuringServerShutdown() + => GetString("ConnectionAbortedDuringServerShutdown"); + + /// + /// The connection was timed out by the server because the response was not read by the client at the specified minimum data rate. + /// + internal static string ConnectionTimedBecauseResponseMininumDataRateNotSatisfied + { + get => GetString("ConnectionTimedBecauseResponseMininumDataRateNotSatisfied"); + } + + /// + /// The connection was timed out by the server because the response was not read by the client at the specified minimum data rate. + /// + internal static string FormatConnectionTimedBecauseResponseMininumDataRateNotSatisfied() + => GetString("ConnectionTimedBecauseResponseMininumDataRateNotSatisfied"); + + /// + /// The connection was timed out by the server. + /// + internal static string ConnectionTimedOutByServer + { + get => GetString("ConnectionTimedOutByServer"); + } + + /// + /// The connection was timed out by the server. + /// + internal static string FormatConnectionTimedOutByServer() + => GetString("ConnectionTimedOutByServer"); + private static string GetString(string name, params string[] formatterNames) { var value = _resourceManager.GetString(name); diff --git a/src/Kestrel.Transport.Abstractions/Internal/IConnectionDispatcher.cs b/src/Kestrel.Transport.Abstractions/Internal/IConnectionDispatcher.cs index 05b7d84ea2..dbcd7411aa 100644 --- a/src/Kestrel.Transport.Abstractions/Internal/IConnectionDispatcher.cs +++ b/src/Kestrel.Transport.Abstractions/Internal/IConnectionDispatcher.cs @@ -1,8 +1,6 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using Microsoft.AspNetCore.Http.Features; - namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal { public interface IConnectionDispatcher diff --git a/src/Kestrel.Transport.Abstractions/Internal/TransportConnection.cs b/src/Kestrel.Transport.Abstractions/Internal/TransportConnection.cs index 5791033da6..d96ceea0ec 100644 --- a/src/Kestrel.Transport.Abstractions/Internal/TransportConnection.cs +++ b/src/Kestrel.Transport.Abstractions/Internal/TransportConnection.cs @@ -60,8 +60,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal public CancellationToken ConnectionClosed { get; set; } - public virtual void Abort() + // DO NOT remove this override to ConnectionContext.Abort. Doing so would cause + // any TransportConnection that does not override Abort or calls base.Abort + // to stack overflow when IConnectionLifetimeFeature.Abort() is called. + // That said, all derived types should override this method should override + // this implementation of Abort because canceling pending output reads is not + // sufficient to abort the connection if there is backpressure. + public override void Abort(ConnectionAbortedException abortReason) { + Output.CancelPendingRead(); } } } diff --git a/src/Kestrel.Transport.Libuv/Internal/LibuvConnection.cs b/src/Kestrel.Transport.Libuv/Internal/LibuvConnection.cs index 6277cb32d2..f0aa50df8b 100644 --- a/src/Kestrel.Transport.Libuv/Internal/LibuvConnection.cs +++ b/src/Kestrel.Transport.Libuv/Internal/LibuvConnection.cs @@ -5,6 +5,7 @@ using System; using System.Buffers; using System.IO; using System.IO.Pipelines; +using System.Net; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Connections; @@ -14,7 +15,7 @@ using Microsoft.Extensions.Logging; namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal { - public partial class LibuvConnection : LibuvConnectionContext + public partial class LibuvConnection : TransportConnection { private static readonly int MinAllocBufferSize = KestrelMemoryPool.MinimumSegmentSize / 2; @@ -27,32 +28,31 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal private readonly UvStreamHandle _socket; private readonly CancellationTokenSource _connectionClosedTokenSource = new CancellationTokenSource(); + private volatile ConnectionAbortedException _abortReason; + private MemoryHandle _bufferHandle; - public LibuvConnection(ListenerContext context, UvStreamHandle socket) : base(context) + public LibuvConnection(UvStreamHandle socket, ILibuvTrace log, LibuvThread thread, IPEndPoint remoteEndPoint, IPEndPoint localEndPoint) { _socket = socket; - if (_socket is UvTcpHandle tcpHandle) - { - var remoteEndPoint = tcpHandle.GetPeerIPEndPoint(); - var localEndPoint = tcpHandle.GetSockIPEndPoint(); + RemoteAddress = remoteEndPoint?.Address; + RemotePort = remoteEndPoint?.Port ?? 0; - RemoteAddress = remoteEndPoint.Address; - RemotePort = remoteEndPoint.Port; + LocalAddress = localEndPoint?.Address; + LocalPort = localEndPoint?.Port ?? 0; - LocalAddress = localEndPoint.Address; - LocalPort = localEndPoint.Port; - - ConnectionClosed = _connectionClosedTokenSource.Token; - } + ConnectionClosed = _connectionClosedTokenSource.Token; + Log = log; + Thread = thread; } public LibuvOutputConsumer OutputConsumer { get; set; } - - private ILibuvTrace Log => ListenerContext.TransportContext.Log; - private IConnectionDispatcher ConnectionDispatcher => ListenerContext.TransportContext.ConnectionDispatcher; - private LibuvThread Thread => ListenerContext.Thread; + private ILibuvTrace Log { get; } + private LibuvThread Thread { get; } + public override MemoryPool MemoryPool => Thread.MemoryPool; + public override PipeScheduler InputWriterScheduler => Thread; + public override PipeScheduler OutputReaderScheduler => Thread; public override long TotalBytesWritten => OutputConsumer?.TotalBytesWritten ?? 0; @@ -60,13 +60,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal { try { - ConnectionDispatcher.OnConnection(this); - OutputConsumer = new LibuvOutputConsumer(Output, Thread, _socket, ConnectionId, Log); StartReading(); - Exception error = null; + Exception inputError = null; + Exception outputError = null; try { @@ -77,13 +76,27 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal } catch (UvException ex) { - error = new IOException(ex.Message, ex); + // The connection reset/error has already been logged by LibuvOutputConsumer + if (ex.StatusCode == LibuvConstants.ECANCELED) + { + // Connection was aborted. + } + else if (LibuvConstants.IsConnectionReset(ex.StatusCode)) + { + // Don't cause writes to throw for connection resets. + inputError = new ConnectionResetException(ex.Message, ex); + } + else + { + inputError = ex; + outputError = ex; + } } finally { // Now, complete the input so that no more reads can happen - Input.Complete(error ?? new ConnectionAbortedException()); - Output.Complete(error); + Input.Complete(inputError ?? _abortReason ?? new ConnectionAbortedException()); + Output.Complete(outputError); // Make sure it isn't possible for a paused read to resume reading after calling uv_close // on the stream handle @@ -103,8 +116,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal } } - public override void Abort() + public override void Abort(ConnectionAbortedException abortReason) { + _abortReason = abortReason; + Output.CancelPendingRead(); + // This cancels any pending I/O. Thread.Post(s => s.Dispose(), _socket); } @@ -156,7 +172,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal // Given a negative status, it's possible that OnAlloc wasn't called. _socket.ReadStop(); - IOException error = null; + Exception error = null; if (status == LibuvConstants.EOF) { @@ -165,18 +181,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal else { handle.Libuv.Check(status, out var uvError); - - // Log connection resets at a lower (Debug) level. - if (LibuvConstants.IsConnectionReset(status)) - { - Log.ConnectionReset(ConnectionId); - error = new ConnectionResetException(uvError.Message, uvError); - } - else - { - Log.ConnectionError(ConnectionId, uvError); - error = new IOException(uvError.Message, uvError); - } + error = LogAndWrapReadError(uvError); } // Complete after aborting the connection @@ -209,10 +214,27 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal { // ReadStart() can throw a UvException in some cases (e.g. socket is no longer connected). // This should be treated the same as OnRead() seeing a negative status. - Log.ConnectionReadFin(ConnectionId); - var error = new IOException(ex.Message, ex); + Input.Complete(LogAndWrapReadError(ex)); + } + } - Input.Complete(error); + private Exception LogAndWrapReadError(UvException uvError) + { + if (uvError.StatusCode == LibuvConstants.ECANCELED) + { + // The operation was canceled by the server not the client. No need for additional logs. + return new ConnectionAbortedException(uvError.Message, uvError); + } + else if (LibuvConstants.IsConnectionReset(uvError.StatusCode)) + { + // Log connection resets at a lower (Debug) level. + Log.ConnectionReset(ConnectionId); + return new ConnectionResetException(uvError.Message, uvError); + } + else + { + Log.ConnectionError(ConnectionId, uvError); + return new IOException(uvError.Message, uvError); } } @@ -221,7 +243,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal try { _connectionClosedTokenSource.Cancel(); - _connectionClosedTokenSource.Dispose(); } catch (Exception ex) { diff --git a/src/Kestrel.Transport.Libuv/Internal/LibuvConnectionContext.cs b/src/Kestrel.Transport.Libuv/Internal/LibuvConnectionContext.cs deleted file mode 100644 index 15f2e9d9b2..0000000000 --- a/src/Kestrel.Transport.Libuv/Internal/LibuvConnectionContext.cs +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System.Buffers; -using System.IO.Pipelines; -using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; - -namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal -{ - public class LibuvConnectionContext : TransportConnection - { - public LibuvConnectionContext(ListenerContext context) - { - ListenerContext = context; - } - - public ListenerContext ListenerContext { get; set; } - - public override MemoryPool MemoryPool => ListenerContext.Thread.MemoryPool; - public override PipeScheduler InputWriterScheduler => ListenerContext.Thread; - public override PipeScheduler OutputReaderScheduler => ListenerContext.Thread; - } -} diff --git a/src/Kestrel.Transport.Libuv/Internal/LibuvConstants.cs b/src/Kestrel.Transport.Libuv/Internal/LibuvConstants.cs index 650700ec00..d1657b63b8 100644 --- a/src/Kestrel.Transport.Libuv/Internal/LibuvConstants.cs +++ b/src/Kestrel.Transport.Libuv/Internal/LibuvConstants.cs @@ -15,11 +15,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal public static readonly int? EADDRINUSE = GetEADDRINUSE(); public static readonly int? ENOTSUP = GetENOTSUP(); public static readonly int? EPIPE = GetEPIPE(); + public static readonly int? ECANCELED = GetECANCELED(); + public static readonly int? ENOTCONN = GetENOTCONN(); + public static readonly int? EINVAL = GetEINVAL(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsConnectionReset(int errno) { - return errno == ECONNRESET || errno == EPIPE; + return errno == ECONNRESET || errno == EPIPE || errno == ENOTCONN | errno == EINVAL; } private static int? GetECONNRESET() @@ -41,11 +44,52 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal private static int? GetEPIPE() { - if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) + if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + { + return -4047; + } + else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) { return -32; } + else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) + { + return -32; + } + return null; + } + private static int? GetENOTCONN() + { + if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + { + return -4053; + } + else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) + { + return -107; + } + else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) + { + return -57; + } + return null; + } + + private static int? GetEINVAL() + { + if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + { + return -4071; + } + else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) + { + return -22; + } + else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) + { + return -22; + } return null; } @@ -78,5 +122,22 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal } return null; } + + private static int? GetECANCELED() + { + if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + { + return -4081; + } + else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) + { + return -125; + } + else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) + { + return -89; + } + return null; + } } } diff --git a/src/Kestrel.Transport.Libuv/Internal/LibuvOutputConsumer.cs b/src/Kestrel.Transport.Libuv/Internal/LibuvOutputConsumer.cs index 94195a3ffc..4666ae198e 100644 --- a/src/Kestrel.Transport.Libuv/Internal/LibuvOutputConsumer.cs +++ b/src/Kestrel.Transport.Libuv/Internal/LibuvOutputConsumer.cs @@ -41,17 +41,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal while (true) { - ReadResult result; - - try - { - result = await _pipe.ReadAsync(); - } - catch - { - // Handled in LibuvConnection.Abort() - return; - } + var result = await _pipe.ReadAsync(); var buffer = result.Buffer; var consumed = buffer.End; @@ -120,7 +110,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal else { // Log connection resets at a lower (Debug) level. - if (LibuvConstants.IsConnectionReset(status)) + if (status == LibuvConstants.ECANCELED) + { + // Connection was aborted. + } + else if (LibuvConstants.IsConnectionReset(status)) { _log.ConnectionReset(_connectionId); } diff --git a/src/Kestrel.Transport.Libuv/Internal/Listener.cs b/src/Kestrel.Transport.Libuv/Internal/Listener.cs index 26c6fba06a..f4b3520854 100644 --- a/src/Kestrel.Transport.Libuv/Internal/Listener.cs +++ b/src/Kestrel.Transport.Libuv/Internal/Listener.cs @@ -93,7 +93,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal try { pipe.Init(Thread.Loop, Thread.QueueCloseHandle, false); - + if (!useFileHandle) { pipe.Bind(EndPointInformation.SocketPath); @@ -172,6 +172,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal listenSocket.Accept(acceptSocket); DispatchConnection(acceptSocket); } + catch (UvException ex) when (LibuvConstants.IsConnectionReset(ex.StatusCode)) + { + Log.ConnectionReset("(null)"); + acceptSocket?.Dispose(); + } catch (UvException ex) { Log.LogError(0, ex, "Listener.OnConnection"); @@ -181,8 +186,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal protected virtual void DispatchConnection(UvStreamHandle socket) { - var connection = new LibuvConnection(this, socket); - _ = connection.Start(); + HandleConnectionAsync(socket); } public virtual async Task DisposeAsync() diff --git a/src/Kestrel.Transport.Libuv/Internal/ListenerContext.cs b/src/Kestrel.Transport.Libuv/Internal/ListenerContext.cs index 37ea4eed36..8399c90dfa 100644 --- a/src/Kestrel.Transport.Libuv/Internal/ListenerContext.cs +++ b/src/Kestrel.Transport.Libuv/Internal/ListenerContext.cs @@ -2,8 +2,11 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Net; +using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking; +using Microsoft.Extensions.Logging; namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal { @@ -38,6 +41,38 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal } } + protected void HandleConnectionAsync(UvStreamHandle socket) + { + try + { + IPEndPoint remoteEndPoint = null; + IPEndPoint localEndPoint = null; + + if (socket is UvTcpHandle tcpHandle) + { + try + { + remoteEndPoint = tcpHandle.GetPeerIPEndPoint(); + localEndPoint = tcpHandle.GetSockIPEndPoint(); + } + catch (UvException ex) when (LibuvConstants.IsConnectionReset(ex.StatusCode)) + { + TransportContext.Log.ConnectionReset("(null)"); + socket.Dispose(); + return; + } + } + + var connection = new LibuvConnection(socket, TransportContext.Log, Thread, remoteEndPoint, localEndPoint); + TransportContext.ConnectionDispatcher.OnConnection(connection); + _ = connection.Start(); + } + catch (Exception ex) + { + TransportContext.Log.LogCritical(ex, $"Unexpected exception in {nameof(ListenerContext)}.{nameof(HandleConnectionAsync)}."); + } + } + private UvTcpHandle AcceptTcp() { var socket = new UvTcpHandle(TransportContext.Log); diff --git a/src/Kestrel.Transport.Libuv/Internal/ListenerSecondary.cs b/src/Kestrel.Transport.Libuv/Internal/ListenerSecondary.cs index 59615c3121..03204caeb4 100644 --- a/src/Kestrel.Transport.Libuv/Internal/ListenerSecondary.cs +++ b/src/Kestrel.Transport.Libuv/Internal/ListenerSecondary.cs @@ -151,23 +151,17 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal try { DispatchPipe.Accept(acceptSocket); + HandleConnectionAsync(acceptSocket); + } + catch (UvException ex) when (LibuvConstants.IsConnectionReset(ex.StatusCode)) + { + Log.ConnectionReset("(null)"); + acceptSocket.Dispose(); } catch (UvException ex) { Log.LogError(0, ex, "DispatchPipe.Accept"); acceptSocket.Dispose(); - return; - } - - try - { - var connection = new LibuvConnection(this, acceptSocket); - _ = connection.Start(); - } - catch (UvException ex) - { - Log.LogError(0, ex, "ListenerSecondary.OnConnection"); - acceptSocket.Dispose(); } } diff --git a/src/Kestrel.Transport.Sockets/Internal/SocketConnection.cs b/src/Kestrel.Transport.Sockets/Internal/SocketConnection.cs index 47a0dad85c..db99693f67 100644 --- a/src/Kestrel.Transport.Sockets/Internal/SocketConnection.cs +++ b/src/Kestrel.Transport.Sockets/Internal/SocketConnection.cs @@ -31,6 +31,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal private readonly object _shutdownLock = new object(); private volatile bool _aborted; + private volatile ConnectionAbortedException _abortReason; private long _totalBytesWritten; internal SocketConnection(Socket socket, MemoryPool memoryPool, PipeScheduler scheduler, ISocketsTrace trace) @@ -69,12 +70,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal public override PipeScheduler OutputReaderScheduler => _scheduler; public override long TotalBytesWritten => Interlocked.Read(ref _totalBytesWritten); - public async Task StartAsync(IConnectionDispatcher connectionDispatcher) + public async Task StartAsync() { try { - connectionDispatcher.OnConnection(this); - // Spawn send and receive logic var receiveTask = DoReceive(); var sendTask = DoSend(); @@ -93,8 +92,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal } } - public override void Abort() + public override void Abort(ConnectionAbortedException abortReason) { + _abortReason = abortReason; + Output.CancelPendingRead(); + // Try to gracefully close the socket to match libuv behavior. Shutdown(); } @@ -107,20 +109,20 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal { await ProcessReceives(); } - catch (SocketException ex) when (ex.SocketErrorCode == SocketError.ConnectionReset) + catch (SocketException ex) when (IsConnectionResetError(ex.SocketErrorCode)) { - error = new ConnectionResetException(ex.Message, ex); - _trace.ConnectionReset(ConnectionId); + // A connection reset can be reported as SocketError.ConnectionAborted on Windows + if (!_aborted) + { + error = new ConnectionResetException(ex.Message, ex); + _trace.ConnectionReset(ConnectionId); + } } - catch (SocketException ex) when (ex.SocketErrorCode == SocketError.OperationAborted || - ex.SocketErrorCode == SocketError.ConnectionAborted || - ex.SocketErrorCode == SocketError.Interrupted || - ex.SocketErrorCode == SocketError.InvalidArgument) + catch (SocketException ex) when (IsConnectionAbortError(ex.SocketErrorCode)) { if (!_aborted) { // Calling Dispose after ReceiveAsync can cause an "InvalidArgument" error on *nix. - error = new ConnectionAbortedException(); _trace.ConnectionError(ConnectionId, error); } } @@ -128,7 +130,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal { if (!_aborted) { - error = new ConnectionAbortedException(); _trace.ConnectionError(ConnectionId, error); } } @@ -146,7 +147,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal { if (_aborted) { - error = error ?? new ConnectionAbortedException(); + error = error ?? _abortReason ?? new ConnectionAbortedException(); } Input.Complete(error); @@ -199,7 +200,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal { await ProcessSends(); } - catch (SocketException ex) when (ex.SocketErrorCode == SocketError.OperationAborted) + catch (SocketException ex) when (IsConnectionResetError(ex.SocketErrorCode)) + { + // A connection reset can be reported as SocketError.ConnectionAborted on Windows + error = null; + _trace.ConnectionReset(ConnectionId); + } + catch (SocketException ex) when (IsConnectionAbortError(ex.SocketErrorCode)) { error = null; } @@ -210,10 +217,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal catch (IOException ex) { error = ex; + _trace.ConnectionError(ConnectionId, error); } catch (Exception ex) { error = new IOException(ex.Message, ex); + _trace.ConnectionError(ConnectionId, error); } finally { @@ -228,8 +237,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal { while (true) { - // Wait for data to write from the pipe producer var result = await Output.ReadAsync(); + var buffer = result.Buffer; if (result.IsCanceled) @@ -289,12 +298,25 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal try { _connectionClosedTokenSource.Cancel(); - _connectionClosedTokenSource.Dispose(); } catch (Exception ex) { _trace.LogError(0, ex, $"Unexpected exception in {nameof(SocketConnection)}.{nameof(CancelConnectionClosedToken)}."); } } + + private static bool IsConnectionResetError(SocketError errorCode) + { + return errorCode == SocketError.ConnectionReset || + errorCode == SocketError.ConnectionAborted || + errorCode == SocketError.Shutdown; + } + + private static bool IsConnectionAbortError(SocketError errorCode) + { + return errorCode == SocketError.OperationAborted || + errorCode == SocketError.Interrupted || + errorCode == SocketError.InvalidArgument; + } } } diff --git a/src/Kestrel.Transport.Sockets/SocketTransport.cs b/src/Kestrel.Transport.Sockets/SocketTransport.cs index 4882b47114..1cf2782c15 100644 --- a/src/Kestrel.Transport.Sockets/SocketTransport.cs +++ b/src/Kestrel.Transport.Sockets/SocketTransport.cs @@ -155,17 +155,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets acceptSocket.NoDelay = _endPointInformation.NoDelay; var connection = new SocketConnection(acceptSocket, _memoryPool, _schedulers[schedulerIndex], _trace); - _ = connection.StartAsync(_dispatcher); + HandleConnectionAsync(connection); } - catch (SocketException ex) when (ex.SocketErrorCode == SocketError.ConnectionReset) + catch (SocketException) when (!_unbinding) { - // REVIEW: Should there be a separate log message for a connection reset this early? _trace.ConnectionReset(connectionId: "(null)"); } - catch (SocketException ex) when (!_unbinding) - { - _trace.ConnectionError(connectionId: "(null)", ex); - } } } } @@ -177,7 +172,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets } else { - _trace.LogCritical(ex, $"Unexpected exeption in {nameof(SocketTransport)}.{nameof(RunAcceptLoopAsync)}."); + _trace.LogCritical(ex, $"Unexpected exception in {nameof(SocketTransport)}.{nameof(RunAcceptLoopAsync)}."); _listenException = ex; // Request shutdown so we can rethrow this exception @@ -187,6 +182,19 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets } } + private void HandleConnectionAsync(SocketConnection connection) + { + try + { + _dispatcher.OnConnection(connection); + _ = connection.StartAsync(); + } + catch (Exception ex) + { + _trace.LogCritical(ex, $"Unexpected exception in {nameof(SocketTransport)}.{nameof(HandleConnectionAsync)}."); + } + } + [DllImport("libc", SetLastError = true)] private static extern int setsockopt(int socket, int level, int option_name, IntPtr option_value, uint option_len); diff --git a/test/Kestrel.Core.Tests/ConnectionDispatcherTests.cs b/test/Kestrel.Core.Tests/ConnectionDispatcherTests.cs index 24f8ded379..c9acd1c658 100644 --- a/test/Kestrel.Core.Tests/ConnectionDispatcherTests.cs +++ b/test/Kestrel.Core.Tests/ConnectionDispatcherTests.cs @@ -1,12 +1,13 @@ -using System; -using System.Buffers; +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + using System.Collections.Generic; -using System.IO.Pipelines; using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal; using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; using Microsoft.AspNetCore.Testing; +using Moq; using Xunit; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests @@ -20,7 +21,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests var tcs = new TaskCompletionSource(); var dispatcher = new ConnectionDispatcher(serviceContext, _ => tcs.Task); - var connection = new TransportConnection(); + var connection = Mock.Of(); dispatcher.OnConnection(connection); diff --git a/test/Kestrel.Core.Tests/Http1ConnectionTests.cs b/test/Kestrel.Core.Tests/Http1ConnectionTests.cs index ffff5b1bcf..42f689c125 100644 --- a/test/Kestrel.Core.Tests/Http1ConnectionTests.cs +++ b/test/Kestrel.Core.Tests/Http1ConnectionTests.cs @@ -11,6 +11,7 @@ using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; +using Microsoft.AspNetCore.Connections; using Microsoft.AspNetCore.Connections.Features; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http.Features; @@ -58,6 +59,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests _http1ConnectionContext = new Http1ConnectionContext { ServiceContext = _serviceContext, + ConnectionContext = Mock.Of(), ConnectionFeatures = connectionFeatures, MemoryPool = _pipelineFactory, TimeoutControl = _timeoutControl.Object, @@ -596,7 +598,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests _http1Connection.StopProcessingNextRequest(); Assert.IsNotType>(requestProcessingTask); - await requestProcessingTask.TimeoutAfter(TestConstants.DefaultTimeout); + await requestProcessingTask.DefaultTimeout(); _application.Output.Complete(); } @@ -732,7 +734,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests Assert.Equal(header0Count + header1Count, _http1Connection.RequestHeaders.Count); await _application.Output.WriteAsync(Encoding.ASCII.GetBytes("\r\n")); - await requestProcessingTask.TimeoutAfter(TestConstants.DefaultTimeout); + await requestProcessingTask.DefaultTimeout(); } [Theory] @@ -809,7 +811,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests var data = Encoding.ASCII.GetBytes("POST / HTTP/1.1\r\nHost:\r\nConnection: close\r\ncontent-length: 1\r\n\r\n"); await _application.Output.WriteAsync(data); - await requestProcessingTask.TimeoutAfter(TestConstants.DefaultTimeout); + await requestProcessingTask.DefaultTimeout(); mockMessageBody.Verify(body => body.ConsumeAsync(), Times.Once); } diff --git a/test/Kestrel.Core.Tests/Http2ConnectionTests.cs b/test/Kestrel.Core.Tests/Http2ConnectionTests.cs index 341c9b21e6..f8038dffff 100644 --- a/test/Kestrel.Core.Tests/Http2ConnectionTests.cs +++ b/test/Kestrel.Core.Tests/Http2ConnectionTests.cs @@ -213,7 +213,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests sem.Release(); }); - await sem.WaitAsync().TimeoutAfter(TestConstants.DefaultTimeout); + await sem.WaitAsync().DefaultTimeout(); }; _largeHeadersApplication = context => @@ -241,7 +241,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests sem.Release(); }); - await sem.WaitAsync().TimeoutAfter(TestConstants.DefaultTimeout); + await sem.WaitAsync().DefaultTimeout(); _runningStreams[streamIdFeature.StreamId].TrySetResult(null); }; @@ -261,7 +261,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests sem.Release(); }); - await sem.WaitAsync().TimeoutAfter(TestConstants.DefaultTimeout); + await sem.WaitAsync().DefaultTimeout(); await context.Response.Body.FlushAsync(); @@ -2459,7 +2459,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests private Task WaitForAllStreamsAsync() { - return Task.WhenAll(_runningStreams.Values.Select(tcs => tcs.Task)).TimeoutAfter(TestConstants.DefaultTimeout); + return Task.WhenAll(_runningStreams.Values.Select(tcs => tcs.Task)).DefaultTimeout(); } private Task SendAsync(ReadOnlySpan span) diff --git a/test/Kestrel.Core.Tests/HttpConnectionTests.cs b/test/Kestrel.Core.Tests/HttpConnectionTests.cs index 85243bd7ff..091b3cadea 100644 --- a/test/Kestrel.Core.Tests/HttpConnectionTests.cs +++ b/test/Kestrel.Core.Tests/HttpConnectionTests.cs @@ -7,6 +7,7 @@ using System.Collections.Generic; using System.IO.Pipelines; using System.Threading; using System.Threading.Tasks; +using Microsoft.AspNetCore.Connections; using Microsoft.AspNetCore.Connections.Features; using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal; @@ -38,6 +39,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests _httpConnectionContext = new HttpConnectionContext { ConnectionId = "0123456789", + ConnectionContext = Mock.Of(), ConnectionAdapters = new List(), ConnectionFeatures = connectionFeatures, MemoryPool = _memoryPool, diff --git a/test/Kestrel.Core.Tests/KestrelServerTests.cs b/test/Kestrel.Core.Tests/KestrelServerTests.cs index e8a2ca2a13..c5fbd18402 100644 --- a/test/Kestrel.Core.Tests/KestrelServerTests.cs +++ b/test/Kestrel.Core.Tests/KestrelServerTests.cs @@ -263,7 +263,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests unbind.Release(); stop.Release(); - await Task.WhenAll(new[] { stopTask1, stopTask2, stopTask3 }).TimeoutAfter(TestConstants.DefaultTimeout); + await Task.WhenAll(new[] { stopTask1, stopTask2, stopTask3 }).DefaultTimeout(); mockTransport.Verify(transport => transport.UnbindAsync(), Times.Once); mockTransport.Verify(transport => transport.StopAsync(), Times.Once); diff --git a/test/Kestrel.Core.Tests/MessageBodyTests.cs b/test/Kestrel.Core.Tests/MessageBodyTests.cs index f472269e6c..703808a400 100644 --- a/test/Kestrel.Core.Tests/MessageBodyTests.cs +++ b/test/Kestrel.Core.Tests/MessageBodyTests.cs @@ -148,7 +148,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests input.Add("\r\r\r\nHello\r\n0\r\n\r\n"); - Assert.Equal(5, await readTask.TimeoutAfter(TestConstants.DefaultTimeout)); + Assert.Equal(5, await readTask.DefaultTimeout()); Assert.Equal(0, await stream.ReadAsync(buffer, 0, buffer.Length)); await body.StopAsync(); diff --git a/test/Kestrel.Core.Tests/OutputProducerTests.cs b/test/Kestrel.Core.Tests/OutputProducerTests.cs index 3f9750a11e..7f3d566ff5 100644 --- a/test/Kestrel.Core.Tests/OutputProducerTests.cs +++ b/test/Kestrel.Core.Tests/OutputProducerTests.cs @@ -5,6 +5,7 @@ using System; using System.Buffers; using System.IO.Pipelines; using System.Threading; +using Microsoft.AspNetCore.Connections; using Microsoft.AspNetCore.Connections.Features; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; @@ -61,39 +62,38 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests [Fact] public void AbortsTransportEvenAfterDispose() { - var mockLifetimeFeature = new Mock(); + var mockConnectionContext = new Mock(); - var outputProducer = CreateOutputProducer(lifetimeFeature: mockLifetimeFeature.Object); + var outputProducer = CreateOutputProducer(connectionContext: mockConnectionContext.Object); outputProducer.Dispose(); - mockLifetimeFeature.Verify(f => f.Abort(), Times.Never()); + mockConnectionContext.Verify(f => f.Abort(It.IsAny()), Times.Never()); outputProducer.Abort(null); - mockLifetimeFeature.Verify(f => f.Abort(), Times.Once()); + mockConnectionContext.Verify(f => f.Abort(null), Times.Once()); outputProducer.Abort(null); - mockLifetimeFeature.Verify(f => f.Abort(), Times.Once()); + mockConnectionContext.Verify(f => f.Abort(null), Times.Once()); } private Http1OutputProducer CreateOutputProducer( PipeOptions pipeOptions = null, - IConnectionLifetimeFeature lifetimeFeature = null) + ConnectionContext connectionContext = null) { pipeOptions = pipeOptions ?? new PipeOptions(); - lifetimeFeature = lifetimeFeature ?? Mock.Of(); + connectionContext = connectionContext ?? Mock.Of(); var pipe = new Pipe(pipeOptions); var serviceContext = new TestServiceContext(); var socketOutput = new Http1OutputProducer( - pipe.Reader, pipe.Writer, "0", + connectionContext, serviceContext.Log, Mock.Of(), - lifetimeFeature, Mock.Of()); return socketOutput; diff --git a/test/Kestrel.Core.Tests/TestInput.cs b/test/Kestrel.Core.Tests/TestInput.cs index 0552801d37..ef0bf7613c 100644 --- a/test/Kestrel.Core.Tests/TestInput.cs +++ b/test/Kestrel.Core.Tests/TestInput.cs @@ -6,6 +6,7 @@ using System.Buffers; using System.IO.Pipelines; using System.Text; using System.Threading.Tasks; +using Microsoft.AspNetCore.Connections; using Microsoft.AspNetCore.Connections.Features; using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; @@ -35,6 +36,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests Http1ConnectionContext = new Http1ConnectionContext { ServiceContext = new TestServiceContext(), + ConnectionContext = Mock.Of(), ConnectionFeatures = connectionFeatures, Application = Application, Transport = Transport, diff --git a/test/Kestrel.FunctionalTests/ConnectionLimitTests.cs b/test/Kestrel.FunctionalTests/ConnectionLimitTests.cs index 3aa1ad90f5..df8a3b51e0 100644 --- a/test/Kestrel.FunctionalTests/ConnectionLimitTests.cs +++ b/test/Kestrel.FunctionalTests/ConnectionLimitTests.cs @@ -38,11 +38,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { await connection.SendEmptyGetAsKeepAlive(); ; await connection.Receive("HTTP/1.1 200 OK"); - Assert.True(await lockedTcs.Task.TimeoutAfter(TestConstants.DefaultTimeout)); + Assert.True(await lockedTcs.Task.DefaultTimeout()); requestTcs.TrySetResult(null); } - await releasedTcs.Task.TimeoutAfter(TestConstants.DefaultTimeout); + await releasedTcs.Task.DefaultTimeout(); } [Fact] @@ -86,7 +86,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests catch { } // connection should close without sending any data - await rejected.WaitForConnectionClose().TimeoutAfter(TestConstants.DefaultTimeout); + await rejected.WaitForConnectionClose().DefaultTimeout(); } } } @@ -126,7 +126,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests catch { } // connection should close without sending any data - await connection.WaitForConnectionClose().TimeoutAfter(TestConstants.DefaultTimeout); + await connection.WaitForConnectionClose().DefaultTimeout(); } } diff --git a/test/Kestrel.FunctionalTests/EventSourceTests.cs b/test/Kestrel.FunctionalTests/EventSourceTests.cs index eddc396925..b10b81d128 100644 --- a/test/Kestrel.FunctionalTests/EventSourceTests.cs +++ b/test/Kestrel.FunctionalTests/EventSourceTests.cs @@ -44,7 +44,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests "Host:", "", "") - .TimeoutAfter(TestConstants.DefaultTimeout); + .DefaultTimeout(); await connection.Receive("HTTP/1.1 200"); } } diff --git a/test/Kestrel.FunctionalTests/HttpProtocolSelectionTests.cs b/test/Kestrel.FunctionalTests/HttpProtocolSelectionTests.cs index c5e4f34fbd..e7bdaadcbf 100644 --- a/test/Kestrel.FunctionalTests/HttpProtocolSelectionTests.cs +++ b/test/Kestrel.FunctionalTests/HttpProtocolSelectionTests.cs @@ -85,7 +85,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests using (var connection = new TestConnection(host.GetPort())) { - await connection.WaitForConnectionClose().TimeoutAfter(TestConstants.DefaultTimeout); + await connection.WaitForConnectionClose().DefaultTimeout(); } } diff --git a/test/Kestrel.FunctionalTests/HttpsTests.cs b/test/Kestrel.FunctionalTests/HttpsTests.cs index be9e9fe623..b1cc95b24a 100644 --- a/test/Kestrel.FunctionalTests/HttpsTests.cs +++ b/test/Kestrel.FunctionalTests/HttpsTests.cs @@ -142,7 +142,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests // Close socket immediately } - await loggerProvider.FilterLogger.LogTcs.Task.TimeoutAfter(TestConstants.DefaultTimeout); + await loggerProvider.FilterLogger.LogTcs.Task.DefaultTimeout(); } Assert.Equal(1, loggerProvider.FilterLogger.LastEventId.Id); @@ -179,7 +179,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests await stream.WriteAsync(new byte[10], 0, 10); } - await loggerProvider.FilterLogger.LogTcs.Task.TimeoutAfter(TestConstants.DefaultTimeout); + await loggerProvider.FilterLogger.LogTcs.Task.DefaultTimeout(); } Assert.Equal(1, loggerProvider.FilterLogger.LastEventId.Id); @@ -292,7 +292,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } } - await tcs.Task.TimeoutAfter(TestConstants.DefaultTimeout); + await tcs.Task.DefaultTimeout(); } // Regression test for https://github.com/aspnet/KestrelHttpServer/issues/1693 @@ -391,11 +391,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests using (var stream = new NetworkStream(socket, ownsSocket: false)) { // No data should be sent and the connection should be closed in well under 30 seconds. - Assert.Equal(0, await stream.ReadAsync(new byte[1], 0, 1).TimeoutAfter(TestConstants.DefaultTimeout)); + Assert.Equal(0, await stream.ReadAsync(new byte[1], 0, 1).DefaultTimeout()); } } - await loggerProvider.FilterLogger.LogTcs.Task.TimeoutAfter(TestConstants.DefaultTimeout); + await loggerProvider.FilterLogger.LogTcs.Task.DefaultTimeout(); Assert.Equal(2, loggerProvider.FilterLogger.LastEventId); Assert.Equal(LogLevel.Debug, loggerProvider.FilterLogger.LastLogLevel); } diff --git a/test/Kestrel.FunctionalTests/LoggingConnectionAdapterTests.cs b/test/Kestrel.FunctionalTests/LoggingConnectionAdapterTests.cs index df211ed170..728d9a16fb 100644 --- a/test/Kestrel.FunctionalTests/LoggingConnectionAdapterTests.cs +++ b/test/Kestrel.FunctionalTests/LoggingConnectionAdapterTests.cs @@ -44,7 +44,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests await host.StartAsync(); var response = await HttpClientSlim.GetStringAsync($"https://localhost:{host.GetPort()}/", validateCertificate: false) - .TimeoutAfter(TimeSpan.FromSeconds(10)); + .DefaultTimeout(); Assert.Equal("Hello World!", response); } diff --git a/test/Kestrel.FunctionalTests/RequestTests.cs b/test/Kestrel.FunctionalTests/RequestTests.cs index d8d78fd6d8..eac3aaa369 100644 --- a/test/Kestrel.FunctionalTests/RequestTests.cs +++ b/test/Kestrel.FunctionalTests/RequestTests.cs @@ -312,8 +312,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests // Wait until connection is established Assert.True(await connectionStarted.WaitAsync(TestConstants.DefaultTimeout)); - // Force a reset - connection.Socket.LingerState = new LingerOption(true, 0); + connection.Reset(); } // If the reset is correctly logged as Debug, the wait below should complete shortly. @@ -381,8 +380,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests "", ""); + connection.Reset(); // Force a reset - connection.Socket.LingerState = new LingerOption(true, 0); } // If the reset is correctly logged as Debug, the wait below should complete shortly. @@ -450,8 +449,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests // Wait until connection is established Assert.True(await requestStarted.WaitAsync(TestConstants.DefaultTimeout), "request should have started"); - // Force a reset - connection.Socket.LingerState = new LingerOption(true, 0); + connection.Reset(); } // If the reset is correctly logged as Debug, the wait below should complete shortly. @@ -528,7 +526,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests var token = context.RequestAborted; token.Register(() => requestAborted.Release(2)); - await requestAborted.WaitAsync().TimeoutAfter(TestConstants.DefaultTimeout); + await requestAborted.WaitAsync().DefaultTimeout(); })); using (var host = builder.Build()) @@ -541,7 +539,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests socket.Send(Encoding.ASCII.GetBytes("GET / HTTP/1.1\r\nHost:\r\n\r\n")); await appStarted.WaitAsync(); socket.Shutdown(SocketShutdown.Send); - await requestAborted.WaitAsync().TimeoutAfter(TestConstants.DefaultTimeout); + await requestAborted.WaitAsync().DefaultTimeout(); } } } @@ -599,11 +597,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests "", ""); - await appStartedTcs.Task.TimeoutAfter(TestConstants.DefaultTimeout); + await appStartedTcs.Task.DefaultTimeout(); - connection.Socket.Shutdown(SocketShutdown.Send); + connection.Shutdown(SocketShutdown.Send); - await connectionClosedTcs.Task.TimeoutAfter(TestConstants.DefaultTimeout); + await connectionClosedTcs.Task.DefaultTimeout(); } } } @@ -632,7 +630,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests "", ""); - await connectionClosedTcs.Task.TimeoutAfter(TestConstants.DefaultTimeout); + await connectionClosedTcs.Task.DefaultTimeout(); await connection.ReceiveEnd($"HTTP/1.1 200 OK", "Connection: close", @@ -669,7 +667,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests "", ""); - await connectionClosedTcs.Task.TimeoutAfter(TestConstants.DefaultTimeout); + await connectionClosedTcs.Task.DefaultTimeout(); await connection.ReceiveForcedEnd(); } } @@ -728,9 +726,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests "", "4", "Done") - .TimeoutAfter(TestConstants.DefaultTimeout); + .DefaultTimeout(); - await Task.WhenAll(pathTcs.Task, rawTargetTcs.Task, queryTcs.Task).TimeoutAfter(TestConstants.DefaultTimeout); + await Task.WhenAll(pathTcs.Task, rawTargetTcs.Task, queryTcs.Task).DefaultTimeout(); Assert.Equal(new PathString(expectedPath), pathTcs.Task.Result); Assert.Equal(requestUrl, rawTargetTcs.Task.Result); if (queryValue == null) @@ -756,7 +754,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests }, new TestServiceContext(LoggerFactory))) { var requestId = await HttpClientSlim.GetStringAsync($"http://{server.EndPoint}") - .TimeoutAfter(TestConstants.DefaultTimeout); + .DefaultTimeout(); Assert.Equal(knownId, requestId); } } @@ -797,7 +795,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests $"Date: {server.Context.DateHeaderValue}", $"Content-Length: {identifierLength}", "", - "").TimeoutAfter(TestConstants.DefaultTimeout); + "").DefaultTimeout(); var read = await connection.Reader.ReadAsync(buffer, 0, identifierLength); Assert.Equal(identifierLength, read); @@ -1058,7 +1056,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests using (var server = new TestServer(async httpContext => { // This will hang if 0 content length is not assumed by the server - Assert.Equal(0, await httpContext.Request.Body.ReadAsync(new byte[1], 0, 1).TimeoutAfter(TestConstants.DefaultTimeout)); + Assert.Equal(0, await httpContext.Request.Body.ReadAsync(new byte[1], 0, 1).DefaultTimeout()); }, testContext, listenOptions)) { using (var connection = server.CreateConnection()) @@ -1133,6 +1131,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [MemberData(nameof(ConnectionAdapterData))] public async Task RequestsCanBeAbortedMidRead(ListenOptions listenOptions) { + const int applicationAbortedConnectionId = 34; + var testContext = new TestServiceContext(LoggerFactory); var readTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); @@ -1207,6 +1207,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests // The cancellation token for only the last request should be triggered. var abortedRequestId = await registrationTcs.Task; Assert.Equal(2, abortedRequestId); + + Assert.Single(TestSink.Writes.Where(w => w.LoggerName == "Microsoft.AspNetCore.Server.Kestrel" && + w.EventId == applicationAbortedConnectionId)); } [Theory] @@ -1291,12 +1294,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests var ignore = connection.Stream.WriteAsync(scratchBuffer, 0, scratchBuffer.Length); // Wait until the read callback is no longer hooked up so that the connection disconnect isn't observed. - await readCallbackUnwired.Task.TimeoutAfter(TestConstants.DefaultTimeout); + await readCallbackUnwired.Task.DefaultTimeout(); } clientClosedConnection.SetResult(null); - await appFuncCompleted.Task.TimeoutAfter(TestConstants.DefaultTimeout); + await appFuncCompleted.Task.DefaultTimeout(); } mockKestrelTrace.Verify(t => t.ConnectionStop(It.IsAny()), Times.Once()); @@ -1306,7 +1309,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [MemberData(nameof(ConnectionAdapterData))] public async Task AppCanHandleClientAbortingConnectionMidRequest(ListenOptions listenOptions) { - var readTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var readTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var appStartedTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); var mockKestrelTrace = new Mock(Logger) { CallBase = true }; var testContext = new TestServiceContext() @@ -1318,6 +1322,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests using (var server = new TestServer(async context => { + appStartedTcs.SetResult(null); + try { await context.Request.Body.CopyToAsync(Stream.Null);; @@ -1341,10 +1347,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests "", ""); + await appStartedTcs.Task.DefaultTimeout(); + await connection.Stream.WriteAsync(scratchBuffer, 0, scratchBuffer.Length); + + connection.Reset(); } - await Assert.ThrowsAnyAsync(() => readTcs.Task).TimeoutAfter(TestConstants.DefaultTimeout); + await Assert.ThrowsAnyAsync(() => readTcs.Task).DefaultTimeout(); } mockKestrelTrace.Verify(t => t.ConnectionStop(It.IsAny()), Times.Once()); @@ -1418,7 +1428,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests var read = 0; while (read < message.Length) { - read += await duplexStream.ReadAsync(buffer, read, buffer.Length - read).TimeoutAfter(TestConstants.DefaultTimeout); + read += await duplexStream.ReadAsync(buffer, read, buffer.Length - read).DefaultTimeout(); } await duplexStream.WriteAsync(buffer, 0, read); diff --git a/test/Kestrel.FunctionalTests/ResponseTests.cs b/test/Kestrel.FunctionalTests/ResponseTests.cs index d652b8aff4..9660dca2f3 100644 --- a/test/Kestrel.FunctionalTests/ResponseTests.cs +++ b/test/Kestrel.FunctionalTests/ResponseTests.cs @@ -176,7 +176,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests Assert.Equal(HttpStatusCode.InternalServerError, response.StatusCode); Assert.False(onStartingCalled); - await onCompletedTcs.Task.TimeoutAfter(TestConstants.DefaultTimeout); + await onCompletedTcs.Task.DefaultTimeout(); } } } @@ -403,7 +403,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } } - await onCompletedTcs.Task.TimeoutAfter(TestConstants.DefaultTimeout); + await onCompletedTcs.Task.DefaultTimeout(); } private static async Task ResponseStatusCodeSetBeforeHttpContextDispose( @@ -479,7 +479,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } } - var disposedStatusCode = await disposedTcs.Task.TimeoutAfter(TestConstants.DefaultTimeout); + var disposedStatusCode = await disposedTcs.Task.DefaultTimeout(); Assert.Equal(expectedServerStatusCode, (HttpStatusCode)disposedStatusCode); } @@ -647,7 +647,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests // Wait for message to be logged before disposing the socket. // Disposing the socket will abort the connection and HttpProtocol._requestAborted // might be 1 by the time ProduceEnd() gets called and the message is logged. - await logTcs.Task.TimeoutAfter(TestConstants.DefaultTimeout); + await logTcs.Task.DefaultTimeout(); } } @@ -685,7 +685,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests "", "hello,"); - await connection.WaitForConnectionClose().TimeoutAfter(TestConstants.DefaultTimeout); + await connection.WaitForConnectionClose().DefaultTimeout(); } } @@ -843,10 +843,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests "hello, world"); // Wait for error message to be logged. - await logTcs.Task.TimeoutAfter(TestConstants.DefaultTimeout); + await logTcs.Task.DefaultTimeout(); // The server should close the connection in this situation. - await connection.WaitForConnectionClose().TimeoutAfter(TestConstants.DefaultTimeout); + await connection.WaitForConnectionClose().DefaultTimeout(); } } @@ -1210,12 +1210,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests requestStarted.Wait(); connection.Shutdown(SocketShutdown.Send); - await connection.WaitForConnectionClose().TimeoutAfter(TestConstants.DefaultTimeout); + await connection.WaitForConnectionClose().DefaultTimeout(); } connectionClosed.Set(); - await tcs.Task.TimeoutAfter(TestConstants.DefaultTimeout); + await tcs.Task.DefaultTimeout(); } } @@ -1249,7 +1249,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests "Transfer-Encoding: chunked", "", "gg"); - await responseWritten.WaitAsync().TimeoutAfter(TestConstants.DefaultTimeout); + await responseWritten.WaitAsync().DefaultTimeout(); await connection.ReceiveEnd( "HTTP/1.1 400 Bad Request", $"Date: {server.Context.DateHeaderValue}", @@ -1860,7 +1860,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests using (var server = new TestServer(async httpContext => { - Assert.Equal(0, await httpContext.Request.Body.ReadAsync(new byte[1], 0, 1).TimeoutAfter(TestConstants.DefaultTimeout)); + Assert.Equal(0, await httpContext.Request.Body.ReadAsync(new byte[1], 0, 1).DefaultTimeout()); }, testContext, listenOptions)) { using (var connection = server.CreateConnection()) @@ -2321,7 +2321,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests // Write failed - can throw TaskCanceledException or OperationCanceledException, // dependending on how far the canceled write goes. - await Assert.ThrowsAnyAsync(async () => await writeTcs.Task).TimeoutAfter(TestConstants.DefaultTimeout); + await Assert.ThrowsAnyAsync(async () => await writeTcs.Task).DefaultTimeout(); // RequestAborted tripped Assert.True(requestAbortedWh.Wait(TestConstants.DefaultTimeout)); @@ -2338,7 +2338,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests var requestAborted = false; var readCallbackUnwired = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); var clientClosedConnection = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); - var writeTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var writeTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); var mockKestrelTrace = new Mock(Logger) { CallBase = true }; var mockLogger = new Mock(); @@ -2380,7 +2380,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } }; - var scratchBuffer = new byte[4096]; + var scratchBuffer = new byte[maxRequestBufferSize * 8]; using (var server = new TestServer(async context => { @@ -2420,12 +2420,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests var ignore = connection.Stream.WriteAsync(scratchBuffer, 0, scratchBuffer.Length); // Wait until the read callback is no longer hooked up so that the connection disconnect isn't observed. - await readCallbackUnwired.Task.TimeoutAfter(TestConstants.DefaultTimeout); + await readCallbackUnwired.Task.DefaultTimeout(); } clientClosedConnection.SetResult(null); - await Assert.ThrowsAnyAsync(() => writeTcs.Task).TimeoutAfter(TestConstants.DefaultTimeout); + await Assert.ThrowsAnyAsync(() => writeTcs.Task).DefaultTimeout(); } mockKestrelTrace.Verify(t => t.ConnectionStop(It.IsAny()), Times.Once()); @@ -2436,18 +2436,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [MemberData(nameof(ConnectionAdapterData))] public async Task AppCanHandleClientAbortingConnectionMidResponse(ListenOptions listenOptions) { + const int connectionResetEventId = 19; + const int connectionFinEventId = 6; + //const int connectionStopEventId = 2; + const int responseBodySegmentSize = 65536; const int responseBodySegmentCount = 100; - const int responseBodySize = responseBodySegmentSize * responseBodySegmentCount; - var requestAborted = false; var appCompletedTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); - - var mockKestrelTrace = new Mock(Logger) { CallBase = true }; - var testContext = new TestServiceContext() - { - Log = mockKestrelTrace.Object, - }; + var requestAborted = false; var scratchBuffer = new byte[responseBodySegmentSize]; @@ -2458,23 +2455,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests requestAborted = true; }); - context.Response.ContentLength = responseBodySize; + for (var i = 0; i < responseBodySegmentCount; i++) + { + await context.Response.Body.WriteAsync(scratchBuffer, 0, scratchBuffer.Length); + await Task.Delay(10); + } - try - { - for (var i = 0; i < responseBodySegmentCount; i++) - { - await context.Response.Body.WriteAsync(scratchBuffer, 0, scratchBuffer.Length); - await Task.Delay(10); - } - } - finally - { - // WriteAsync shouldn't throw without a CancellationToken passed in. Unfortunately a ECONNRESET UvException sometimes gets thrown. - // This will be fixed by https://github.com/aspnet/KestrelHttpServer/pull/2547 - appCompletedTcs.SetResult(null); - } - }, testContext, listenOptions)) + appCompletedTcs.SetResult(null); + }, new TestServiceContext(LoggerFactory), listenOptions)) { using (var connection = server.CreateConnection()) { @@ -2484,23 +2472,69 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests "", ""); - var readCount = 0; - // Read just part of the response and close the connection. // https://github.com/aspnet/KestrelHttpServer/issues/2554 - for (var i = 0; i < responseBodySegmentCount / 10; i++) + await connection.Stream.ReadAsync(scratchBuffer, 0, scratchBuffer.Length); + + connection.Reset(); + } + + await appCompletedTcs.Task.DefaultTimeout(); + + // After the app is done with the write loop, the connection reset should be logged. + // On Linux and macOS, the connection close is still sometimes observed as a FIN despite the LingerState. + var presShutdownTransportLogs = TestSink.Writes.Where( + w => w.LoggerName == "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv" || + w.LoggerName == "Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets"); + var connectionResetLogs = presShutdownTransportLogs.Where( + w => w.EventId == connectionResetEventId || + (!TestPlatformHelper.IsWindows && w.EventId == connectionFinEventId)); + + Assert.NotEmpty(connectionResetLogs); + } + + // TODO: Figure out what the following assertion is flaky. The server shouldn't shutdown before all + // the connections are closed, yet sometimes the connection stop log isn't observed here. + //var coreLogs = TestSink.Writes.Where(w => w.LoggerName == "Microsoft.AspNetCore.Server.Kestrel"); + //Assert.Single(coreLogs.Where(w => w.EventId == connectionStopEventId)); + + Assert.True(requestAborted, "RequestAborted token didn't fire."); + + var transportLogs = TestSink.Writes.Where(w => w.LoggerName == "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv" || + w.LoggerName == "Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets"); + Assert.Empty(transportLogs.Where(w => w.LogLevel > LogLevel.Debug)); + } + + [Theory] + [MemberData(nameof(ConnectionAdapterData))] + public async Task ClientAbortingConnectionImmediatelyIsNotLoggedHigherThanDebug(ListenOptions listenOptions) + { + // Attempt multiple connections to be extra sure the resets are consistently logged appropriately. + const int numConnections = 10; + + // There's not guarantee that the app even gets invoked in this test. The connection reset can be observed + // as early as accept. + using (var server = new TestServer(context => Task.CompletedTask, new TestServiceContext(LoggerFactory), listenOptions)) + { + for (var i = 0; i < numConnections; i++) + { + using (var connection = server.CreateConnection()) { - readCount += await connection.Stream.ReadAsync(scratchBuffer, 0, scratchBuffer.Length); + await connection.Send( + "GET / HTTP/1.1", + "Host:", + "", + ""); + + connection.Reset(); } - - connection.Socket.Shutdown(SocketShutdown.Send); - - await appCompletedTcs.Task.TimeoutAfter(TestConstants.DefaultTimeout); } } - mockKestrelTrace.Verify(t => t.ConnectionStop(It.IsAny()), Times.Once()); - Assert.True(requestAborted); + var transportLogs = TestSink.Writes.Where(w => w.LoggerName == "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv" || + w.LoggerName == "Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets"); + + Assert.Empty(transportLogs.Where(w => w.LogLevel > LogLevel.Debug)); } [Theory] @@ -2654,7 +2688,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests "hello, world"); // Wait for all callbacks to be called. - await onStartingTcs.Task.TimeoutAfter(TestConstants.DefaultTimeout); + await onStartingTcs.Task.DefaultTimeout(); } } @@ -2706,7 +2740,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests "hello, world"); // Wait for all callbacks to be called. - await onCompletedTcs.Task.TimeoutAfter(TestConstants.DefaultTimeout); + await onCompletedTcs.Task.DefaultTimeout(); } } @@ -2884,10 +2918,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests var sw = Stopwatch.StartNew(); logger.LogInformation("Waiting for connection to abort."); - await requestAborted.Task.TimeoutAfter(TimeSpan.FromSeconds(60)); - await responseRateTimeoutMessageLogged.Task.TimeoutAfter(TimeSpan.FromSeconds(10)); - await connectionStopMessageLogged.Task.TimeoutAfter(TimeSpan.FromSeconds(10)); - await appFuncCompleted.Task.TimeoutAfter(TimeSpan.FromSeconds(10)); + await requestAborted.Task.DefaultTimeout(); + await responseRateTimeoutMessageLogged.Task.DefaultTimeout(); + await connectionStopMessageLogged.Task.DefaultTimeout(); + await appFuncCompleted.Task.DefaultTimeout(); await AssertStreamAborted(connection.Reader.BaseStream, chunkSize * chunks); sw.Stop(); @@ -2971,10 +3005,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests var request = Encoding.ASCII.GetBytes("GET / HTTP/1.1\r\nHost:\r\n\r\n"); await sslStream.WriteAsync(request, 0, request.Length); - await aborted.Task.TimeoutAfter(TimeSpan.FromSeconds(60)); - await responseRateTimeoutMessageLogged.Task.TimeoutAfter(TimeSpan.FromSeconds(10)); - await connectionStopMessageLogged.Task.TimeoutAfter(TimeSpan.FromSeconds(10)); - await appFuncCompleted.Task.TimeoutAfter(TimeSpan.FromSeconds(10)); + await aborted.Task.DefaultTimeout(); + await responseRateTimeoutMessageLogged.Task.DefaultTimeout(); + await connectionStopMessageLogged.Task.DefaultTimeout(); + await appFuncCompleted.Task.DefaultTimeout(); // Temporary workaround for a deadlock when reading from an aborted client SslStream on Mac and Linux. if (TestPlatformHelper.IsWindows) @@ -2993,15 +3027,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [Fact] public async Task ConnectionClosedWhenBothRequestAndResponseExperienceBackPressure() { - const int bufferSize = 1024; - const int bufferCount = 256 * 1024; + const int bufferSize = 65536; + const int bufferCount = 100; var responseSize = bufferCount * bufferSize; var buffer = new byte[bufferSize]; var responseRateTimeoutMessageLogged = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); var connectionStopMessageLogged = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); var requestAborted = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); - var appFuncCompleted = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var copyToAsyncCts = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); var mockKestrelTrace = new Mock(); mockKestrelTrace @@ -3039,13 +3073,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { await context.Request.Body.CopyToAsync(context.Response.Body); } - catch + catch (Exception ex) { - // This should always throw an OperationCanceledException. Unfortunately a ECONNRESET UvException sometimes gets thrown. - // This will be fixed by https://github.com/aspnet/KestrelHttpServer/pull/2547 - appFuncCompleted.SetResult(null); + copyToAsyncCts.SetException(ex); throw; } + + copyToAsyncCts.SetException(new Exception("This shouldn't be reached.")); } using (var server = new TestServer(App, testContext, listenOptions)) @@ -3065,13 +3099,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests for (var i = 0; i < bufferCount; i++) { await connection.Stream.WriteAsync(buffer, 0, buffer.Length); + await Task.Delay(10); } }); - await requestAborted.Task.TimeoutAfter(TimeSpan.FromSeconds(60)); - await responseRateTimeoutMessageLogged.Task.TimeoutAfter(TimeSpan.FromSeconds(10)); - await connectionStopMessageLogged.Task.TimeoutAfter(TimeSpan.FromSeconds(10)); - await appFuncCompleted.Task.TimeoutAfter(TimeSpan.FromSeconds(10)); + await requestAborted.Task.DefaultTimeout(); + await responseRateTimeoutMessageLogged.Task.DefaultTimeout(); + await connectionStopMessageLogged.Task.DefaultTimeout(); + + // Expect OperationCanceledException instead of IOException because the server initiated the abort due to a response rate timeout. + await Assert.ThrowsAnyAsync(() => copyToAsyncCts.Task).DefaultTimeout(); await AssertStreamAborted(connection.Stream, responseSize); } } @@ -3135,7 +3172,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests // Make sure consuming a single chunk exceeds the 2 second timeout. var targetBytesPerSecond = chunkSize / 4; await AssertStreamCompleted(connection.Reader.BaseStream, minTotalOutputSize, targetBytesPerSecond); - await appFuncCompleted.Task.TimeoutAfter(TimeSpan.FromSeconds(10)); + await appFuncCompleted.Task.DefaultTimeout(); mockKestrelTrace.Verify(t => t.ResponseMininumDataRateNotSatisfied(It.IsAny(), It.IsAny()), Times.Never()); mockKestrelTrace.Verify(t => t.ConnectionStop(It.IsAny()), Times.Once()); @@ -3257,7 +3294,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { while (totalReceived < totalBytes) { - var bytes = await stream.ReadAsync(receiveBuffer, 0, receiveBuffer.Length).TimeoutAfter(TimeSpan.FromSeconds(10)); + var bytes = await stream.ReadAsync(receiveBuffer, 0, receiveBuffer.Length).DefaultTimeout(); if (bytes == 0) { diff --git a/test/Kestrel.FunctionalTests/UpgradeTests.cs b/test/Kestrel.FunctionalTests/UpgradeTests.cs index d7a0f5073f..2b4027d37c 100644 --- a/test/Kestrel.FunctionalTests/UpgradeTests.cs +++ b/test/Kestrel.FunctionalTests/UpgradeTests.cs @@ -47,7 +47,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests ""); await connection.Receive("New protocol data"); - await upgrade.Task.TimeoutAfter(TestConstants.DefaultTimeout); + await upgrade.Task.DefaultTimeout(); } } } @@ -67,7 +67,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests var stream = await feature.UpgradeAsync(); var buffer = new byte[128]; - var read = await context.Request.Body.ReadAsync(buffer, 0, 128).TimeoutAfter(TestConstants.DefaultTimeout); + var read = await context.Request.Body.ReadAsync(buffer, 0, 128).DefaultTimeout(); Assert.Equal(0, read); using (var reader = new StreamReader(stream)) @@ -101,7 +101,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests await connection.Send(send + "\r\n"); await connection.Receive(recv); - await upgrade.Task.TimeoutAfter(TestConstants.DefaultTimeout); + await upgrade.Task.DefaultTimeout(); } } } @@ -138,10 +138,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests $"Date: {server.Context.DateHeaderValue}", "", ""); - await connection.WaitForConnectionClose().TimeoutAfter(TestConstants.DefaultTimeout); + await connection.WaitForConnectionClose().DefaultTimeout(); } - var ex = await Assert.ThrowsAsync(async () => await upgradeTcs.Task.TimeoutAfter(TestConstants.DefaultTimeout)); + var ex = await Assert.ThrowsAsync(async () => await upgradeTcs.Task.DefaultTimeout()); Assert.Equal(CoreStrings.UpgradeCannotBeCalledMultipleTimes, ex.Message); } @@ -243,7 +243,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } } - var ex = await Assert.ThrowsAsync(async () => await upgradeTcs.Task).TimeoutAfter(TestConstants.DefaultTimeout); + var ex = await Assert.ThrowsAsync(async () => await upgradeTcs.Task).DefaultTimeout(); Assert.Equal(CoreStrings.CannotUpgradeNonUpgradableRequest, ex.Message); } @@ -331,7 +331,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests ""); } - await appCompletedTcs.Task.TimeoutAfter(TestConstants.DefaultTimeout); + await appCompletedTcs.Task.DefaultTimeout(); } } } diff --git a/test/Kestrel.Transport.Libuv.Tests/LibuvConnectionTests.cs b/test/Kestrel.Transport.Libuv.Tests/LibuvConnectionTests.cs index 7a82e6da15..0184cdb86f 100644 --- a/test/Kestrel.Transport.Libuv.Tests/LibuvConnectionTests.cs +++ b/test/Kestrel.Transport.Libuv.Tests/LibuvConnectionTests.cs @@ -35,7 +35,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests Thread = thread }; var socket = new MockSocket(mockLibuv, Thread.CurrentThread.ManagedThreadId, transportContext.Log); - var connection = new LibuvConnection(listenerContext, socket); + var connection = new LibuvConnection(socket, listenerContext.TransportContext.Log, thread, null, null); + listenerContext.TransportContext.ConnectionDispatcher.OnConnection(connection); _ = connection.Start(); mockLibuv.AllocCallback(socket.InternalGetHandle(), 2048, out var ignored); @@ -85,7 +86,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests Thread = thread }; var socket = new MockSocket(mockLibuv, Thread.CurrentThread.ManagedThreadId, transportContext.Log); - var connection = new LibuvConnection(listenerContext, socket); + var connection = new LibuvConnection(socket, listenerContext.TransportContext.Log, thread, null, null); + listenerContext.TransportContext.ConnectionDispatcher.OnConnection(connection); connectionTask = connection.Start(); mockLibuv.AllocCallback(socket.InternalGetHandle(), 2048, out var ignored); @@ -100,7 +102,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests // Now complete the output writer so that the connection closes mockConnectionDispatcher.Output.Writer.Complete(); - await connectionTask.TimeoutAfter(TestConstants.DefaultTimeout); + await connectionTask.DefaultTimeout(); // Assert that we don't try to start reading Assert.Null(mockLibuv.AllocCallback); @@ -150,7 +152,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests Thread = thread }; var socket = new MockSocket(mockLibuv, Thread.CurrentThread.ManagedThreadId, transportContext.Log); - var connection = new LibuvConnection(listenerContext, socket); + var connection = new LibuvConnection(socket, listenerContext.TransportContext.Log, thread, null, null); + listenerContext.TransportContext.ConnectionDispatcher.OnConnection(connection); connectionTask = connection.Start(); mockLibuv.AllocCallback(socket.InternalGetHandle(), 2048, out var ignored); @@ -181,7 +184,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests // Now complete the output writer and wait for the connection to close mockConnectionDispatcher.Output.Writer.Complete(); - await connectionTask.TimeoutAfter(TestConstants.DefaultTimeout); + await connectionTask.DefaultTimeout(); // Assert that we don't try to start reading Assert.Null(mockLibuv.AllocCallback); @@ -212,7 +215,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests Thread = thread }; var socket = new MockSocket(mockLibuv, Thread.CurrentThread.ManagedThreadId, transportContext.Log); - var connection = new LibuvConnection(listenerContext, socket); + var connection = new LibuvConnection(socket, listenerContext.TransportContext.Log, thread, null, null); + listenerContext.TransportContext.ConnectionDispatcher.OnConnection(connection); _ = connection.Start(); var ignored = new LibuvFunctions.uv_buf_t(); diff --git a/test/Kestrel.Transport.Libuv.Tests/LibuvOutputConsumerTests.cs b/test/Kestrel.Transport.Libuv.Tests/LibuvOutputConsumerTests.cs index e269bda59c..d2f6a4fb89 100644 --- a/test/Kestrel.Transport.Libuv.Tests/LibuvOutputConsumerTests.cs +++ b/test/Kestrel.Transport.Libuv.Tests/LibuvOutputConsumerTests.cs @@ -7,6 +7,7 @@ using System.Collections.Concurrent; using System.IO.Pipelines; using System.Threading; using System.Threading.Tasks; +using Microsoft.AspNetCore.Connections; using Microsoft.AspNetCore.Connections.Features; using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Server.Kestrel.Core; @@ -84,7 +85,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests var writeTask = outputProducer.WriteDataAsync(buffer); // Assert - await writeTask.TimeoutAfter(TestConstants.DefaultTimeout); + await writeTask.DefaultTimeout(); } } @@ -122,7 +123,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests var writeTask = outputProducer.WriteDataAsync(buffer); // Assert - await writeTask.TimeoutAfter(TestConstants.DefaultTimeout); + await writeTask.DefaultTimeout(); // Cleanup outputProducer.Dispose(); @@ -181,7 +182,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests await _libuvThread.PostAsync(cb => cb(0), triggerNextCompleted); // Assert - await writeTask.TimeoutAfter(TestConstants.DefaultTimeout); + await writeTask.DefaultTimeout(); // Cleanup outputProducer.Dispose(); @@ -245,7 +246,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests await _libuvThread.PostAsync(cb => cb(0), triggerNextCompleted); // Finishing the first write should allow the second write to pre-complete. - await writeTask2.TimeoutAfter(TestConstants.DefaultTimeout); + await writeTask2.DefaultTimeout(); // Cleanup outputProducer.Dispose(); @@ -738,6 +739,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests var http1Connection = new Http1Connection(new Http1ConnectionContext { ServiceContext = serviceContext, + ConnectionContext = Mock.Of(), ConnectionFeatures = connectionFeatures, MemoryPool = _memoryPool, TimeoutControl = Mock.Of(), @@ -764,12 +766,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests // Without ConfigureAwait(false), xunit will dispatch. await consumer.WriteOutputAsync().ConfigureAwait(false); - http1Connection.Abort(error: null); + http1Connection.Abort(abortReason: null); outputReader.Complete(); } catch (UvException ex) { - http1Connection.Abort(ex); + http1Connection.Abort(new ConnectionAbortedException(ex.Message, ex)); outputReader.Complete(ex); } } diff --git a/test/Kestrel.Transport.Libuv.Tests/TestHelpers/MockConnectionDispatcher.cs b/test/Kestrel.Transport.Libuv.Tests/TestHelpers/MockConnectionDispatcher.cs index e4f17bbda4..73cdfbb3a2 100644 --- a/test/Kestrel.Transport.Libuv.Tests/TestHelpers/MockConnectionDispatcher.cs +++ b/test/Kestrel.Transport.Libuv.Tests/TestHelpers/MockConnectionDispatcher.cs @@ -4,9 +4,6 @@ using System; using System.Buffers; using System.IO.Pipelines; -using Microsoft.AspNetCore.Http.Features; -using Microsoft.AspNetCore.Connections; -using Microsoft.AspNetCore.Connections.Features; using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests.TestHelpers diff --git a/test/shared/TaskTimeoutExtensions.cs b/test/shared/TaskTimeoutExtensions.cs new file mode 100644 index 0000000000..8e83a7a70e --- /dev/null +++ b/test/shared/TaskTimeoutExtensions.cs @@ -0,0 +1,20 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using Microsoft.AspNetCore.Testing; + +namespace System.Threading.Tasks +{ + public static class TaskTimeoutExtensions + { + public static Task DefaultTimeout(this Task task) + { + return task.TimeoutAfter(TestConstants.DefaultTimeout); + } + + public static Task DefaultTimeout(this Task task) + { + return task.TimeoutAfter(TestConstants.DefaultTimeout); + } + } +} diff --git a/test/shared/TestConnection.cs b/test/shared/TestConnection.cs index 85e82590c0..04e547214d 100644 --- a/test/shared/TestConnection.cs +++ b/test/shared/TestConnection.cs @@ -47,8 +47,6 @@ namespace Microsoft.AspNetCore.Testing _reader = new StreamReader(_stream, Encoding.ASCII); } - public Socket Socket => _socket; - public Stream Stream => _stream; public StreamReader Reader => _reader; @@ -215,6 +213,12 @@ namespace Microsoft.AspNetCore.Testing _socket.Shutdown(how); } + public void Reset() + { + _socket.LingerState = new LingerOption(true, 0); + _socket.Dispose(); + } + public Task WaitForConnectionClose() { var tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); From 181e521b4003d4adb61f749d58ffeb6c2f42ff27 Mon Sep 17 00:00:00 2001 From: Nate McMaster Date: Tue, 10 Jul 2018 12:37:07 -0700 Subject: [PATCH 1652/1662] Fix compiler error as a result of merging 2.1.2 into release/2.1 --- test/shared/TestConnection.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/shared/TestConnection.cs b/test/shared/TestConnection.cs index 04e547214d..2d760a5bc8 100644 --- a/test/shared/TestConnection.cs +++ b/test/shared/TestConnection.cs @@ -47,6 +47,8 @@ namespace Microsoft.AspNetCore.Testing _reader = new StreamReader(_stream, Encoding.ASCII); } + public Socket Socket => _socket; + public Stream Stream => _stream; public StreamReader Reader => _reader; From 128eefdef3825e1a2b8313f76b235c465b10b682 Mon Sep 17 00:00:00 2001 From: Nate McMaster Date: Wed, 11 Jul 2018 22:31:23 -0700 Subject: [PATCH 1653/1662] Remove usage of the Microsoft.Extensions.Buffers.Sources package, copy the source into Kestrel This moves source code that used to be in aspnet/Common. It was only used here, so this simplifies the process of working with these internal-only APIs. cref https://github.com/aspnet/Common/pull/386 --- build/dependencies.props | 2 - src/Kestrel.Core/Internal/BufferReader.cs | 125 ++++++++ src/Kestrel.Core/Internal/BufferWriter.cs | 93 ++++++ src/Kestrel.Core/Kestrel.Core.csproj | 5 +- .../Internal/MemoryPoolBlock.Debug.cs | 125 ++++++++ .../Internal/MemoryPoolBlock.Release.cs | 65 ++++ .../Internal/MemoryPoolSlab.cs | 97 ++++++ .../Internal/SlabMemoryPool.cs | 193 +++++++++++ .../Kestrel.Transport.Abstractions.csproj | 5 +- src/shared/ThrowHelper.cs | 87 +++++ test/Kestrel.Core.Tests/BufferReaderTests.cs | 300 ++++++++++++++++++ test/Kestrel.Core.Tests/BufferWriterTests.cs | 223 +++++++++++++ .../Kestrel.Core.Tests.csproj | 1 - test/shared/BufferSegment.cs | 24 ++ test/shared/CustomMemoryForTest.cs | 45 +++ test/shared/ReadOnlySequenceFactory.cs | 148 +++++++++ 16 files changed, 1532 insertions(+), 6 deletions(-) create mode 100644 src/Kestrel.Core/Internal/BufferReader.cs create mode 100644 src/Kestrel.Core/Internal/BufferWriter.cs create mode 100644 src/Kestrel.Transport.Abstractions/Internal/MemoryPoolBlock.Debug.cs create mode 100644 src/Kestrel.Transport.Abstractions/Internal/MemoryPoolBlock.Release.cs create mode 100644 src/Kestrel.Transport.Abstractions/Internal/MemoryPoolSlab.cs create mode 100644 src/Kestrel.Transport.Abstractions/Internal/SlabMemoryPool.cs create mode 100644 src/shared/ThrowHelper.cs create mode 100644 test/Kestrel.Core.Tests/BufferReaderTests.cs create mode 100644 test/Kestrel.Core.Tests/BufferWriterTests.cs create mode 100644 test/shared/BufferSegment.cs create mode 100644 test/shared/CustomMemoryForTest.cs create mode 100644 test/shared/ReadOnlySequenceFactory.cs diff --git a/build/dependencies.props b/build/dependencies.props index a53bc20e1f..90b286111a 100644 --- a/build/dependencies.props +++ b/build/dependencies.props @@ -18,8 +18,6 @@ 2.1.0 2.1.1 2.1.1 - 2.1.1 - 2.1.1 2.1.1 2.1.1 2.1.1 diff --git a/src/Kestrel.Core/Internal/BufferReader.cs b/src/Kestrel.Core/Internal/BufferReader.cs new file mode 100644 index 0000000000..5a1e75b69b --- /dev/null +++ b/src/Kestrel.Core/Internal/BufferReader.cs @@ -0,0 +1,125 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using System; +using System.Buffers; +using System.Runtime.CompilerServices; + +namespace System.Buffers +{ + internal ref struct BufferReader + { + private ReadOnlySpan _currentSpan; + private int _index; + + private ReadOnlySequence _sequence; + private SequencePosition _currentSequencePosition; + private SequencePosition _nextSequencePosition; + + private int _consumedBytes; + private bool _end; + + public BufferReader(ReadOnlySequence buffer) + { + _end = false; + _index = 0; + _consumedBytes = 0; + _sequence = buffer; + _currentSequencePosition = _sequence.Start; + _nextSequencePosition = _currentSequencePosition; + _currentSpan = ReadOnlySpan.Empty; + MoveNext(); + } + + public bool End => _end; + + public int CurrentSegmentIndex => _index; + + public SequencePosition Position => _sequence.GetPosition(_index, _currentSequencePosition); + + public ReadOnlySpan CurrentSegment => _currentSpan; + + public ReadOnlySpan UnreadSegment => _currentSpan.Slice(_index); + + public int ConsumedBytes => _consumedBytes; + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public int Peek() + { + if (_end) + { + return -1; + } + return _currentSpan[_index]; + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public int Read() + { + if (_end) + { + return -1; + } + + var value = _currentSpan[_index]; + _index++; + _consumedBytes++; + + if (_index >= _currentSpan.Length) + { + MoveNext(); + } + + return value; + } + + [MethodImpl(MethodImplOptions.NoInlining)] + private void MoveNext() + { + var previous = _nextSequencePosition; + while (_sequence.TryGet(ref _nextSequencePosition, out var memory, true)) + { + _currentSequencePosition = previous; + _currentSpan = memory.Span; + _index = 0; + if (_currentSpan.Length > 0) + { + return; + } + } + _end = true; + } + + public void Advance(int byteCount) + { + if (byteCount < 0) + { + ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.length); + } + + _consumedBytes += byteCount; + + while (!_end && byteCount > 0) + { + if ((_index + byteCount) < _currentSpan.Length) + { + _index += byteCount; + byteCount = 0; + break; + } + + var remaining = (_currentSpan.Length - _index); + + _index += remaining; + byteCount -= remaining; + + MoveNext(); + } + + if (byteCount > 0) + { + ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.length); + } + } + } +} diff --git a/src/Kestrel.Core/Internal/BufferWriter.cs b/src/Kestrel.Core/Internal/BufferWriter.cs new file mode 100644 index 0000000000..2b63ea920c --- /dev/null +++ b/src/Kestrel.Core/Internal/BufferWriter.cs @@ -0,0 +1,93 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Runtime.CompilerServices; + +namespace System.Buffers +{ + internal ref struct BufferWriter where T: IBufferWriter + { + private T _output; + private Span _span; + private int _buffered; + + public BufferWriter(T output) + { + _buffered = 0; + _output = output; + _span = output.GetSpan(); + } + + public Span Span => _span; + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public void Commit() + { + var buffered = _buffered; + if (buffered > 0) + { + _buffered = 0; + _output.Advance(buffered); + } + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public void Advance(int count) + { + _buffered += count; + _span = _span.Slice(count); + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public void Write(ReadOnlySpan source) + { + if (_span.Length >= source.Length) + { + source.CopyTo(_span); + Advance(source.Length); + } + else + { + WriteMultiBuffer(source); + } + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public void Ensure(int count = 1) + { + if (_span.Length < count) + { + EnsureMore(count); + } + } + + [MethodImpl(MethodImplOptions.NoInlining)] + private void EnsureMore(int count = 0) + { + if (_buffered > 0) + { + Commit(); + } + + _output.GetMemory(count); + _span = _output.GetSpan(); + } + + private void WriteMultiBuffer(ReadOnlySpan source) + { + while (source.Length > 0) + { + if (_span.Length == 0) + { + EnsureMore(); + } + + var writable = Math.Min(source.Length, _span.Length); + source.Slice(0, writable).CopyTo(_span); + source = source.Slice(writable); + Advance(writable); + } + } + } +} diff --git a/src/Kestrel.Core/Kestrel.Core.csproj b/src/Kestrel.Core/Kestrel.Core.csproj index b81428efa5..8551a56002 100644 --- a/src/Kestrel.Core/Kestrel.Core.csproj +++ b/src/Kestrel.Core/Kestrel.Core.csproj @@ -11,6 +11,10 @@ CS1591;$(NoWarn) + + + + @@ -21,7 +25,6 @@ - diff --git a/src/Kestrel.Transport.Abstractions/Internal/MemoryPoolBlock.Debug.cs b/src/Kestrel.Transport.Abstractions/Internal/MemoryPoolBlock.Debug.cs new file mode 100644 index 0000000000..6f815716d4 --- /dev/null +++ b/src/Kestrel.Transport.Abstractions/Internal/MemoryPoolBlock.Debug.cs @@ -0,0 +1,125 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +#if DEBUG + +using System.Threading; +using System.Diagnostics; + +namespace System.Buffers +{ + /// + /// Block tracking object used by the byte buffer memory pool. A slab is a large allocation which is divided into smaller blocks. The + /// individual blocks are then treated as independent array segments. + /// + internal sealed class MemoryPoolBlock : MemoryManager + { + private readonly int _offset; + private readonly int _length; + + private int _pinCount; + + /// + /// This object cannot be instantiated outside of the static Create method + /// + internal MemoryPoolBlock(SlabMemoryPool pool, MemoryPoolSlab slab, int offset, int length) + { + _offset = offset; + _length = length; + + Pool = pool; + Slab = slab; + } + + /// + /// Back-reference to the memory pool which this block was allocated from. It may only be returned to this pool. + /// + public SlabMemoryPool Pool { get; } + + /// + /// Back-reference to the slab from which this block was taken, or null if it is one-time-use memory. + /// + public MemoryPoolSlab Slab { get; } + + public override Memory Memory + { + get + { + if (!Slab.IsActive) ThrowHelper.ThrowObjectDisposedException(ExceptionArgument.MemoryPoolBlock); + + return CreateMemory(_length); + } + } + + +#if BLOCK_LEASE_TRACKING + public bool IsLeased { get; set; } + public string Leaser { get; set; } +#endif + + ~MemoryPoolBlock() + { + if (Slab != null && Slab.IsActive) + { + Debug.Assert(false, $"{Environment.NewLine}{Environment.NewLine}*** Block being garbage collected instead of returned to pool" + +#if BLOCK_LEASE_TRACKING + $": {Leaser}" + +#endif + $" ***{ Environment.NewLine}"); + + // Need to make a new object because this one is being finalized + Pool.Return(new MemoryPoolBlock(Pool, Slab, _offset, _length)); + } + } + + protected override void Dispose(bool disposing) + { + if (!Slab.IsActive) ThrowHelper.ThrowObjectDisposedException(ExceptionArgument.MemoryPoolBlock); + + if (Volatile.Read(ref _pinCount) > 0) + { + ThrowHelper.ThrowInvalidOperationException_ReturningPinnedBlock(); + } + + Pool.Return(this); + } + + public override Span GetSpan() => new Span(Slab.Array, _offset, _length); + + public override MemoryHandle Pin(int byteOffset = 0) + { + if (!Slab.IsActive) ThrowHelper.ThrowObjectDisposedException(ExceptionArgument.MemoryPoolBlock); + if (byteOffset < 0 || byteOffset > _length) ThrowHelper.ThrowArgumentOutOfRangeException(_length, byteOffset); + + Interlocked.Increment(ref _pinCount); + unsafe + { + return new MemoryHandle((Slab.NativePointer + _offset + byteOffset).ToPointer(), default, this); + } + } + + protected override bool TryGetArray(out ArraySegment segment) + { + segment = new ArraySegment(Slab.Array, _offset, _length); + return true; + } + + public override void Unpin() + { + if (Interlocked.Decrement(ref _pinCount) < 0) + { + ThrowHelper.ThrowInvalidOperationException_ReferenceCountZero(); + } + } + + public void Lease() + { +#if BLOCK_LEASE_TRACKING + Leaser = Environment.StackTrace; + IsLeased = true; +#endif + } + } +} + +#endif \ No newline at end of file diff --git a/src/Kestrel.Transport.Abstractions/Internal/MemoryPoolBlock.Release.cs b/src/Kestrel.Transport.Abstractions/Internal/MemoryPoolBlock.Release.cs new file mode 100644 index 0000000000..93784df05e --- /dev/null +++ b/src/Kestrel.Transport.Abstractions/Internal/MemoryPoolBlock.Release.cs @@ -0,0 +1,65 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +#if RELEASE + +using System.Runtime.InteropServices; + +namespace System.Buffers +{ + /// + /// Block tracking object used by the byte buffer memory pool. A slab is a large allocation which is divided into smaller blocks. The + /// individual blocks are then treated as independent array segments. + /// + internal sealed class MemoryPoolBlock : IMemoryOwner + { + private readonly int _offset; + private readonly int _length; + + /// + /// This object cannot be instantiated outside of the static Create method + /// + internal MemoryPoolBlock(SlabMemoryPool pool, MemoryPoolSlab slab, int offset, int length) + { + _offset = offset; + _length = length; + + Pool = pool; + Slab = slab; + + Memory = MemoryMarshal.CreateFromPinnedArray(slab.Array, _offset, _length); + } + + /// + /// Back-reference to the memory pool which this block was allocated from. It may only be returned to this pool. + /// + public SlabMemoryPool Pool { get; } + + /// + /// Back-reference to the slab from which this block was taken, or null if it is one-time-use memory. + /// + public MemoryPoolSlab Slab { get; } + + public Memory Memory { get; } + + ~MemoryPoolBlock() + { + if (Slab != null && Slab.IsActive) + { + // Need to make a new object because this one is being finalized + Pool.Return(new MemoryPoolBlock(Pool, Slab, _offset, _length)); + } + } + + public void Dispose() + { + Pool.Return(this); + } + + public void Lease() + { + } + } +} + +#endif diff --git a/src/Kestrel.Transport.Abstractions/Internal/MemoryPoolSlab.cs b/src/Kestrel.Transport.Abstractions/Internal/MemoryPoolSlab.cs new file mode 100644 index 0000000000..4b15f88233 --- /dev/null +++ b/src/Kestrel.Transport.Abstractions/Internal/MemoryPoolSlab.cs @@ -0,0 +1,97 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using System.Runtime.InteropServices; + +namespace System.Buffers +{ + /// + /// Slab tracking object used by the byte buffer memory pool. A slab is a large allocation which is divided into smaller blocks. The + /// individual blocks are then treated as independant array segments. + /// + internal class MemoryPoolSlab : IDisposable + { + /// + /// This handle pins the managed array in memory until the slab is disposed. This prevents it from being + /// relocated and enables any subsections of the array to be used as native memory pointers to P/Invoked API calls. + /// + private readonly GCHandle _gcHandle; + private readonly IntPtr _nativePointer; + private byte[] _data; + + private bool _isActive; + private bool _disposedValue; + + public MemoryPoolSlab(byte[] data) + { + _data = data; + _gcHandle = GCHandle.Alloc(data, GCHandleType.Pinned); + _nativePointer = _gcHandle.AddrOfPinnedObject(); + _isActive = true; + } + + /// + /// True as long as the blocks from this slab are to be considered returnable to the pool. In order to shrink the + /// memory pool size an entire slab must be removed. That is done by (1) setting IsActive to false and removing the + /// slab from the pool's _slabs collection, (2) as each block currently in use is Return()ed to the pool it will + /// be allowed to be garbage collected rather than re-pooled, and (3) when all block tracking objects are garbage + /// collected and the slab is no longer references the slab will be garbage collected and the memory unpinned will + /// be unpinned by the slab's Dispose. + /// + public bool IsActive => _isActive; + + public IntPtr NativePointer => _nativePointer; + + public byte[] Array => _data; + + public int Length => _data.Length; + + public static MemoryPoolSlab Create(int length) + { + // allocate and pin requested memory length + var array = new byte[length]; + + // allocate and return slab tracking object + return new MemoryPoolSlab(array); + } + + protected void Dispose(bool disposing) + { + if (!_disposedValue) + { + if (disposing) + { + // N/A: dispose managed state (managed objects). + } + + _isActive = false; + + if (_gcHandle.IsAllocated) + { + _gcHandle.Free(); + } + + // set large fields to null. + _data = null; + + _disposedValue = true; + } + } + + // override a finalizer only if Dispose(bool disposing) above has code to free unmanaged resources. + ~MemoryPoolSlab() + { + // Do not change this code. Put cleanup code in Dispose(bool disposing) above. + Dispose(false); + } + + // This code added to correctly implement the disposable pattern. + public void Dispose() + { + // Do not change this code. Put cleanup code in Dispose(bool disposing) above. + Dispose(true); + // uncomment the following line if the finalizer is overridden above. + GC.SuppressFinalize(this); + } + } +} diff --git a/src/Kestrel.Transport.Abstractions/Internal/SlabMemoryPool.cs b/src/Kestrel.Transport.Abstractions/Internal/SlabMemoryPool.cs new file mode 100644 index 0000000000..e36ec70adb --- /dev/null +++ b/src/Kestrel.Transport.Abstractions/Internal/SlabMemoryPool.cs @@ -0,0 +1,193 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using System.Collections.Concurrent; +using System.Diagnostics; + +namespace System.Buffers +{ + /// + /// Used to allocate and distribute re-usable blocks of memory. + /// + internal class SlabMemoryPool : MemoryPool + { + /// + /// The size of a block. 4096 is chosen because most operating systems use 4k pages. + /// + private const int _blockSize = 4096; + + /// + /// Allocating 32 contiguous blocks per slab makes the slab size 128k. This is larger than the 85k size which will place the memory + /// in the large object heap. This means the GC will not try to relocate this array, so the fact it remains pinned does not negatively + /// affect memory management's compactification. + /// + private const int _blockCount = 32; + + /// + /// Max allocation block size for pooled blocks, + /// larger values can be leased but they will be disposed after use rather than returned to the pool. + /// + public override int MaxBufferSize { get; } = _blockSize; + + /// + /// 4096 * 32 gives you a slabLength of 128k contiguous bytes allocated per slab + /// + private static readonly int _slabLength = _blockSize * _blockCount; + + /// + /// Thread-safe collection of blocks which are currently in the pool. A slab will pre-allocate all of the block tracking objects + /// and add them to this collection. When memory is requested it is taken from here first, and when it is returned it is re-added. + /// + private readonly ConcurrentQueue _blocks = new ConcurrentQueue(); + + /// + /// Thread-safe collection of slabs which have been allocated by this pool. As long as a slab is in this collection and slab.IsActive, + /// the blocks will be added to _blocks when returned. + /// + private readonly ConcurrentStack _slabs = new ConcurrentStack(); + + /// + /// This is part of implementing the IDisposable pattern. + /// + private bool _disposedValue = false; // To detect redundant calls + + /// + /// This default value passed in to Rent to use the default value for the pool. + /// + private const int AnySize = -1; + + public override IMemoryOwner Rent(int size = AnySize) + { + if (size == AnySize) size = _blockSize; + else if (size > _blockSize) + { + ThrowHelper.ThrowArgumentOutOfRangeException_BufferRequestTooLarge(_blockSize); + } + + var block = Lease(); + return block; + } + + /// + /// Called to take a block from the pool. + /// + /// The block that is reserved for the called. It must be passed to Return when it is no longer being used. + private MemoryPoolBlock Lease() + { + Debug.Assert(!_disposedValue, "Block being leased from disposed pool!"); + + if (_blocks.TryDequeue(out MemoryPoolBlock block)) + { + // block successfully taken from the stack - return it + + block.Lease(); + return block; + } + // no blocks available - grow the pool + block = AllocateSlab(); + block.Lease(); + return block; + } + + /// + /// Internal method called when a block is requested and the pool is empty. It allocates one additional slab, creates all of the + /// block tracking objects, and adds them all to the pool. + /// + private MemoryPoolBlock AllocateSlab() + { + var slab = MemoryPoolSlab.Create(_slabLength); + _slabs.Push(slab); + + var basePtr = slab.NativePointer; + // Page align the blocks + var firstOffset = (int)((((ulong)basePtr + (uint)_blockSize - 1) & ~((uint)_blockSize - 1)) - (ulong)basePtr); + // Ensure page aligned + Debug.Assert((((ulong)basePtr + (uint)firstOffset) & (uint)(_blockSize - 1)) == 0); + + var blockAllocationLength = ((_slabLength - firstOffset) & ~(_blockSize - 1)); + var offset = firstOffset; + for (; + offset + _blockSize < blockAllocationLength; + offset += _blockSize) + { + var block = new MemoryPoolBlock( + this, + slab, + offset, + _blockSize); +#if BLOCK_LEASE_TRACKING + block.IsLeased = true; +#endif + Return(block); + } + + Debug.Assert(offset + _blockSize - firstOffset == blockAllocationLength); + // return last block rather than adding to pool + var newBlock = new MemoryPoolBlock( + this, + slab, + offset, + _blockSize); + + return newBlock; + } + + /// + /// Called to return a block to the pool. Once Return has been called the memory no longer belongs to the caller, and + /// Very Bad Things will happen if the memory is read of modified subsequently. If a caller fails to call Return and the + /// block tracking object is garbage collected, the block tracking object's finalizer will automatically re-create and return + /// a new tracking object into the pool. This will only happen if there is a bug in the server, however it is necessary to avoid + /// leaving "dead zones" in the slab due to lost block tracking objects. + /// + /// The block to return. It must have been acquired by calling Lease on the same memory pool instance. + internal void Return(MemoryPoolBlock block) + { +#if BLOCK_LEASE_TRACKING + Debug.Assert(block.Pool == this, "Returned block was not leased from this pool"); + Debug.Assert(block.IsLeased, $"Block being returned to pool twice: {block.Leaser}{Environment.NewLine}"); + block.IsLeased = false; +#endif + + if (block.Slab != null && block.Slab.IsActive) + { + _blocks.Enqueue(block); + } + else + { + GC.SuppressFinalize(block); + } + } + + protected override void Dispose(bool disposing) + { + if (!_disposedValue) + { + _disposedValue = true; +#if DEBUG && !INNER_LOOP + GC.Collect(); + GC.WaitForPendingFinalizers(); + GC.Collect(); +#endif + if (disposing) + { + while (_slabs.TryPop(out MemoryPoolSlab slab)) + { + // dispose managed state (managed objects). + slab.Dispose(); + } + } + + // Discard blocks in pool + while (_blocks.TryDequeue(out MemoryPoolBlock block)) + { + GC.SuppressFinalize(block); + } + + // N/A: free unmanaged resources (unmanaged objects) and override a finalizer below. + + // N/A: set large fields to null. + + } + } + } +} diff --git a/src/Kestrel.Transport.Abstractions/Kestrel.Transport.Abstractions.csproj b/src/Kestrel.Transport.Abstractions/Kestrel.Transport.Abstractions.csproj index 58529f72d0..3dc81350fb 100644 --- a/src/Kestrel.Transport.Abstractions/Kestrel.Transport.Abstractions.csproj +++ b/src/Kestrel.Transport.Abstractions/Kestrel.Transport.Abstractions.csproj @@ -13,10 +13,11 @@ - + + - + diff --git a/src/shared/ThrowHelper.cs b/src/shared/ThrowHelper.cs new file mode 100644 index 0000000000..da31583777 --- /dev/null +++ b/src/shared/ThrowHelper.cs @@ -0,0 +1,87 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using System.Diagnostics; +using System.Runtime.CompilerServices; + +namespace System.Buffers +{ + internal class ThrowHelper + { + public static void ThrowArgumentOutOfRangeException(int sourceLength, int offset) + { + throw GetArgumentOutOfRangeException(sourceLength, offset); + } + + [MethodImpl(MethodImplOptions.NoInlining)] + private static ArgumentOutOfRangeException GetArgumentOutOfRangeException(int sourceLength, int offset) + { + if ((uint)offset > (uint)sourceLength) + { + // Offset is negative or less than array length + return new ArgumentOutOfRangeException(GetArgumentName(ExceptionArgument.offset)); + } + + // The third parameter (not passed) length must be out of range + return new ArgumentOutOfRangeException(GetArgumentName(ExceptionArgument.length)); + } + + public static void ThrowArgumentOutOfRangeException(ExceptionArgument argument) + { + throw GetArgumentOutOfRangeException(argument); + } + + public static void ThrowInvalidOperationException_ReferenceCountZero() + { + throw new InvalidOperationException("Can't release when reference count is already zero"); + } + + public static void ThrowInvalidOperationException_ReturningPinnedBlock() + { + throw new InvalidOperationException("Can't release when reference count is already zero"); + } + + public static void ThrowArgumentOutOfRangeException_BufferRequestTooLarge(int maxSize) + { + throw GetArgumentOutOfRangeException_BufferRequestTooLarge(maxSize); + } + + public static void ThrowObjectDisposedException(ExceptionArgument argument) + { + throw GetObjectDisposedException(argument); + } + + [MethodImpl(MethodImplOptions.NoInlining)] + private static ArgumentOutOfRangeException GetArgumentOutOfRangeException(ExceptionArgument argument) + { + return new ArgumentOutOfRangeException(GetArgumentName(argument)); + } + + [MethodImpl(MethodImplOptions.NoInlining)] + private static ArgumentOutOfRangeException GetArgumentOutOfRangeException_BufferRequestTooLarge(int maxSize) + { + return new ArgumentOutOfRangeException(GetArgumentName(ExceptionArgument.size), $"Cannot allocate more than {maxSize} bytes in a single buffer"); + } + + [MethodImpl(MethodImplOptions.NoInlining)] + private static ObjectDisposedException GetObjectDisposedException(ExceptionArgument argument) + { + return new ObjectDisposedException(GetArgumentName(argument)); + } + + private static string GetArgumentName(ExceptionArgument argument) + { + Debug.Assert(Enum.IsDefined(typeof(ExceptionArgument), argument), "The enum value is not defined, please check the ExceptionArgument Enum."); + + return argument.ToString(); + } + } + + internal enum ExceptionArgument + { + size, + offset, + length, + MemoryPoolBlock + } +} diff --git a/test/Kestrel.Core.Tests/BufferReaderTests.cs b/test/Kestrel.Core.Tests/BufferReaderTests.cs new file mode 100644 index 0000000000..294f61cdb0 --- /dev/null +++ b/test/Kestrel.Core.Tests/BufferReaderTests.cs @@ -0,0 +1,300 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using Xunit; + +namespace System.Buffers.Tests +{ + public abstract class ReadableBufferReaderFacts + { + public class Array : SingleSegment + { + public Array() : base(ReadOnlySequenceFactory.ArrayFactory) { } + internal Array(ReadOnlySequenceFactory factory) : base(factory) { } + } + + public class OwnedMemory : SingleSegment + { + public OwnedMemory() : base(ReadOnlySequenceFactory.OwnedMemoryFactory) { } + } + public class Memory : SingleSegment + { + public Memory() : base(ReadOnlySequenceFactory.MemoryFactory) { } + } + + public class SingleSegment : SegmentPerByte + { + public SingleSegment() : base(ReadOnlySequenceFactory.SingleSegmentFactory) { } + internal SingleSegment(ReadOnlySequenceFactory factory) : base(factory) { } + + [Fact] + public void AdvanceSingleBufferSkipsBytes() + { + var reader = new BufferReader(Factory.CreateWithContent(new byte[] { 1, 2, 3, 4, 5 })); + reader.Advance(2); + Assert.Equal(2, reader.CurrentSegmentIndex); + Assert.Equal(3, reader.CurrentSegment[reader.CurrentSegmentIndex]); + Assert.Equal(3, reader.Peek()); + reader.Advance(2); + Assert.Equal(5, reader.Peek()); + Assert.Equal(4, reader.CurrentSegmentIndex); + Assert.Equal(5, reader.CurrentSegment[reader.CurrentSegmentIndex]); + } + + [Fact] + public void TakeReturnsByteAndMoves() + { + var reader = new BufferReader(Factory.CreateWithContent(new byte[] { 1, 2 })); + Assert.Equal(0, reader.CurrentSegmentIndex); + Assert.Equal(1, reader.CurrentSegment[reader.CurrentSegmentIndex]); + Assert.Equal(1, reader.Read()); + Assert.Equal(1, reader.CurrentSegmentIndex); + Assert.Equal(2, reader.CurrentSegment[reader.CurrentSegmentIndex]); + Assert.Equal(2, reader.Read()); + Assert.Equal(-1, reader.Read()); + } + } + + public class SegmentPerByte : ReadableBufferReaderFacts + { + public SegmentPerByte() : base(ReadOnlySequenceFactory.SegmentPerByteFactory) { } + internal SegmentPerByte(ReadOnlySequenceFactory factory) : base(factory) { } + } + + internal ReadOnlySequenceFactory Factory { get; } + + internal ReadableBufferReaderFacts(ReadOnlySequenceFactory factory) + { + Factory = factory; + } + + [Fact] + public void PeekReturnsByteWithoutMoving() + { + var reader = new BufferReader(Factory.CreateWithContent(new byte[] { 1, 2 })); + Assert.Equal(1, reader.Peek()); + Assert.Equal(1, reader.Peek()); + } + + [Fact] + public void CursorIsCorrectAtEnd() + { + var reader = new BufferReader(Factory.CreateWithContent(new byte[] { 1, 2 })); + reader.Read(); + reader.Read(); + Assert.True(reader.End); + } + + [Fact] + public void CursorIsCorrectWithEmptyLastBlock() + { + var first = new BufferSegment(new byte[] { 1, 2 }); + var last = first.Append(new byte[4]); + + var reader = new BufferReader(new ReadOnlySequence(first, 0, last, 0)); + reader.Read(); + reader.Read(); + reader.Read(); + Assert.Same(last, reader.Position.GetObject()); + Assert.Equal(0, reader.Position.GetInteger()); + Assert.True(reader.End); + } + + [Fact] + public void PeekReturnsMinuOneByteInTheEnd() + { + var reader = new BufferReader(Factory.CreateWithContent(new byte[] { 1, 2 })); + Assert.Equal(1, reader.Read()); + Assert.Equal(2, reader.Read()); + Assert.Equal(-1, reader.Peek()); + } + + [Fact] + public void AdvanceToEndThenPeekReturnsMinusOne() + { + var reader = new BufferReader(Factory.CreateWithContent(new byte[] { 1, 2, 3, 4, 5 })); + reader.Advance(5); + Assert.True(reader.End); + Assert.Equal(-1, reader.Peek()); + } + + [Fact] + public void AdvancingPastLengthThrows() + { + var reader = new BufferReader(Factory.CreateWithContent(new byte[] { 1, 2, 3, 4, 5 })); + try + { + reader.Advance(6); + Assert.True(false); + } + catch (Exception ex) + { + Assert.True(ex is ArgumentOutOfRangeException); + } + } + + [Fact] + public void CtorFindsFirstNonEmptySegment() + { + var buffer = Factory.CreateWithContent(new byte[] { 1 }); + var reader = new BufferReader(buffer); + + Assert.Equal(1, reader.Peek()); + } + + [Fact] + public void EmptySegmentsAreSkippedOnMoveNext() + { + var buffer = Factory.CreateWithContent(new byte[] { 1, 2 }); + var reader = new BufferReader(buffer); + + Assert.Equal(1, reader.Peek()); + reader.Advance(1); + Assert.Equal(2, reader.Peek()); + } + + [Fact] + public void PeekGoesToEndIfAllEmptySegments() + { + var buffer = Factory.CreateOfSize(0); + var reader = new BufferReader(buffer); + + Assert.Equal(-1, reader.Peek()); + Assert.True(reader.End); + } + + [Fact] + public void AdvanceTraversesSegments() + { + var buffer = Factory.CreateWithContent(new byte[] { 1, 2, 3 }); + var reader = new BufferReader(buffer); + + reader.Advance(2); + Assert.Equal(3, reader.CurrentSegment[reader.CurrentSegmentIndex]); + Assert.Equal(3, reader.Read()); + } + + [Fact] + public void AdvanceThrowsPastLengthMultipleSegments() + { + var buffer = Factory.CreateWithContent(new byte[] { 1, 2, 3 }); + var reader = new BufferReader(buffer); + + try + { + reader.Advance(4); + Assert.True(false); + } + catch (Exception ex) + { + Assert.True(ex is ArgumentOutOfRangeException); + } + } + + [Fact] + public void TakeTraversesSegments() + { + var buffer = Factory.CreateWithContent(new byte[] { 1, 2, 3 }); + var reader = new BufferReader(buffer); + + Assert.Equal(1, reader.Read()); + Assert.Equal(2, reader.Read()); + Assert.Equal(3, reader.Read()); + Assert.Equal(-1, reader.Read()); + } + + [Fact] + public void PeekTraversesSegments() + { + var buffer = Factory.CreateWithContent(new byte[] { 1, 2 }); + var reader = new BufferReader(buffer); + + Assert.Equal(1, reader.CurrentSegment[reader.CurrentSegmentIndex]); + Assert.Equal(1, reader.Read()); + + Assert.Equal(2, reader.CurrentSegment[reader.CurrentSegmentIndex]); + Assert.Equal(2, reader.Peek()); + Assert.Equal(2, reader.Read()); + Assert.Equal(-1, reader.Peek()); + Assert.Equal(-1, reader.Read()); + } + + [Fact] + public void PeekWorkesWithEmptySegments() + { + var buffer = Factory.CreateWithContent(new byte[] { 1 }); + var reader = new BufferReader(buffer); + + Assert.Equal(0, reader.CurrentSegmentIndex); + Assert.Equal(1, reader.CurrentSegment.Length); + Assert.Equal(1, reader.Peek()); + Assert.Equal(1, reader.Read()); + Assert.Equal(-1, reader.Peek()); + Assert.Equal(-1, reader.Read()); + } + + [Fact] + public void WorkesWithEmptyBuffer() + { + var reader = new BufferReader(Factory.CreateWithContent(new byte[] { })); + + Assert.Equal(0, reader.CurrentSegmentIndex); + Assert.Equal(0, reader.CurrentSegment.Length); + Assert.Equal(-1, reader.Peek()); + Assert.Equal(-1, reader.Read()); + } + + [Theory] + [InlineData(0, false)] + [InlineData(5, false)] + [InlineData(10, false)] + [InlineData(11, true)] + [InlineData(12, true)] + [InlineData(15, true)] + public void ReturnsCorrectCursor(int takes, bool end) + { + var readableBuffer = Factory.CreateWithContent(new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }); + var reader = new BufferReader(readableBuffer); + for (int i = 0; i < takes; i++) + { + reader.Read(); + } + + var expected = end ? new byte[] { } : readableBuffer.Slice((long)takes).ToArray(); + Assert.Equal(expected, readableBuffer.Slice(reader.Position).ToArray()); + } + + [Fact] + public void SlicingBufferReturnsCorrectCursor() + { + var buffer = Factory.CreateWithContent(new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }); + var sliced = buffer.Slice(2L); + + var reader = new BufferReader(sliced); + Assert.Equal(sliced.ToArray(), buffer.Slice(reader.Position).ToArray()); + Assert.Equal(2, reader.Peek()); + Assert.Equal(0, reader.CurrentSegmentIndex); + } + + [Fact] + public void ReaderIndexIsCorrect() + { + var buffer = Factory.CreateWithContent(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }); + var reader = new BufferReader(buffer); + + var counter = 1; + while (!reader.End) + { + var span = reader.CurrentSegment; + for (int i = reader.CurrentSegmentIndex; i < span.Length; i++) + { + Assert.Equal(counter++, reader.CurrentSegment[i]); + } + reader.Advance(span.Length); + } + Assert.Equal(buffer.Length, reader.ConsumedBytes); + } + } + +} diff --git a/test/Kestrel.Core.Tests/BufferWriterTests.cs b/test/Kestrel.Core.Tests/BufferWriterTests.cs new file mode 100644 index 0000000000..8a071385a4 --- /dev/null +++ b/test/Kestrel.Core.Tests/BufferWriterTests.cs @@ -0,0 +1,223 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System.Buffers; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Xunit; + +namespace System.IO.Pipelines.Tests +{ + public class BufferWriterTests : IDisposable + { + protected Pipe Pipe; + public BufferWriterTests() + { + Pipe = new Pipe(new PipeOptions(useSynchronizationContext: false, pauseWriterThreshold: 0, resumeWriterThreshold: 0)); + } + + public void Dispose() + { + Pipe.Writer.Complete(); + Pipe.Reader.Complete(); + } + + private byte[] Read() + { + Pipe.Writer.FlushAsync().GetAwaiter().GetResult(); + Pipe.Writer.Complete(); + ReadResult readResult = Pipe.Reader.ReadAsync().GetAwaiter().GetResult(); + byte[] data = readResult.Buffer.ToArray(); + Pipe.Reader.AdvanceTo(readResult.Buffer.End); + return data; + } + + [Theory] + [InlineData(3, -1, 0)] + [InlineData(3, 0, -1)] + [InlineData(3, 0, 4)] + [InlineData(3, 4, 0)] + [InlineData(3, -1, -1)] + [InlineData(3, 4, 4)] + public void ThrowsForInvalidParameters(int arrayLength, int offset, int length) + { + BufferWriter writer = new BufferWriter(Pipe.Writer); + var array = new byte[arrayLength]; + for (var i = 0; i < array.Length; i++) + { + array[i] = (byte)(i + 1); + } + + writer.Write(new Span(array, 0, 0)); + writer.Write(new Span(array, array.Length, 0)); + + try + { + writer.Write(new Span(array, offset, length)); + Assert.True(false); + } + catch (Exception ex) + { + Assert.True(ex is ArgumentOutOfRangeException); + } + + writer.Write(new Span(array, 0, array.Length)); + writer.Commit(); + + Assert.Equal(array, Read()); + } + + [Theory] + [InlineData(0, 3)] + [InlineData(1, 2)] + [InlineData(2, 1)] + [InlineData(1, 1)] + public void CanWriteWithOffsetAndLenght(int offset, int length) + { + BufferWriter writer = new BufferWriter(Pipe.Writer); + var array = new byte[] { 1, 2, 3 }; + + writer.Write(new Span(array, offset, length)); + writer.Commit(); + + Assert.Equal(array.Skip(offset).Take(length).ToArray(), Read()); + } + + [Fact] + public void CanWriteEmpty() + { + BufferWriter writer = new BufferWriter(Pipe.Writer); + var array = new byte[] { }; + + writer.Write(array); + writer.Write(new Span(array, 0, array.Length)); + writer.Commit(); + + Assert.Equal(array, Read()); + } + + [Fact] + public void CanWriteIntoHeadlessBuffer() + { + BufferWriter writer = new BufferWriter(Pipe.Writer); + + writer.Write(new byte[] { 1, 2, 3 }); + writer.Commit(); + + Assert.Equal(new byte[] { 1, 2, 3 }, Read()); + } + + [Fact] + public void CanWriteMultipleTimes() + { + BufferWriter writer = new BufferWriter(Pipe.Writer); + + writer.Write(new byte[] { 1 }); + writer.Write(new byte[] { 2 }); + writer.Write(new byte[] { 3 }); + writer.Commit(); + + Assert.Equal(new byte[] { 1, 2, 3 }, Read()); + } + + [Fact] + public void CanWriteOverTheBlockLength() + { + Memory memory = Pipe.Writer.GetMemory(); + BufferWriter writer = new BufferWriter(Pipe.Writer); + + IEnumerable source = Enumerable.Range(0, memory.Length).Select(i => (byte)i); + byte[] expectedBytes = source.Concat(source).Concat(source).ToArray(); + + writer.Write(expectedBytes); + writer.Commit(); + + Assert.Equal(expectedBytes, Read()); + } + + [Fact] + public void EnsureAllocatesSpan() + { + BufferWriter writer = new BufferWriter(Pipe.Writer); + writer.Ensure(10); + Assert.True(writer.Span.Length > 10); + Assert.Equal(new byte[] { }, Read()); + } + + [Fact] + public void ExposesSpan() + { + int initialLength = Pipe.Writer.GetMemory().Length; + BufferWriter writer = new BufferWriter(Pipe.Writer); + Assert.Equal(initialLength, writer.Span.Length); + Assert.Equal(new byte[] { }, Read()); + } + + [Fact] + public void SlicesSpanAndAdvancesAfterWrite() + { + int initialLength = Pipe.Writer.GetMemory().Length; + + BufferWriter writer = new BufferWriter(Pipe.Writer); + + writer.Write(new byte[] { 1, 2, 3 }); + writer.Commit(); + + Assert.Equal(initialLength - 3, writer.Span.Length); + Assert.Equal(Pipe.Writer.GetMemory().Length, writer.Span.Length); + Assert.Equal(new byte[] { 1, 2, 3 }, Read()); + } + + [Theory] + [InlineData(5)] + [InlineData(50)] + [InlineData(500)] + [InlineData(5000)] + [InlineData(50000)] + public async Task WriteLargeDataBinary(int length) + { + var data = new byte[length]; + new Random(length).NextBytes(data); + PipeWriter output = Pipe.Writer; + output.Write(data); + await output.FlushAsync(); + + ReadResult result = await Pipe.Reader.ReadAsync(); + ReadOnlySequence input = result.Buffer; + Assert.Equal(data, input.ToArray()); + Pipe.Reader.AdvanceTo(input.End); + } + + [Fact] + public async Task CanWriteNothingToBuffer() + { + PipeWriter buffer = Pipe.Writer; + buffer.GetMemory(0); + buffer.Advance(0); // doing nothing, the hard way + await buffer.FlushAsync(); + } + + [Fact] + public void EmptyWriteDoesNotThrow() + { + Pipe.Writer.Write(new byte[0]); + } + + [Fact] + public void ThrowsOnAdvanceOverMemorySize() + { + Memory buffer = Pipe.Writer.GetMemory(1); + var exception = Assert.Throws(() => Pipe.Writer.Advance(buffer.Length + 1)); + Assert.Equal("Can't advance past buffer size.", exception.Message); + } + + [Fact] + public void ThrowsOnAdvanceWithNoMemory() + { + PipeWriter buffer = Pipe.Writer; + var exception = Assert.Throws(() => buffer.Advance(1)); + Assert.Equal("No writing operation. Make sure GetMemory() was called.", exception.Message); + } + } +} diff --git a/test/Kestrel.Core.Tests/Kestrel.Core.Tests.csproj b/test/Kestrel.Core.Tests/Kestrel.Core.Tests.csproj index 3229fd0fa7..fdbbd000ef 100644 --- a/test/Kestrel.Core.Tests/Kestrel.Core.Tests.csproj +++ b/test/Kestrel.Core.Tests/Kestrel.Core.Tests.csproj @@ -23,7 +23,6 @@ - diff --git a/test/shared/BufferSegment.cs b/test/shared/BufferSegment.cs new file mode 100644 index 0000000000..d89f4addd5 --- /dev/null +++ b/test/shared/BufferSegment.cs @@ -0,0 +1,24 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +namespace System.Buffers +{ + internal class BufferSegment : ReadOnlySequenceSegment + { + public BufferSegment(Memory memory) + { + Memory = memory; + } + + public BufferSegment Append(Memory memory) + { + var segment = new BufferSegment(memory) + { + RunningIndex = RunningIndex + Memory.Length + }; + Next = segment; + return segment; + } + } +} diff --git a/test/shared/CustomMemoryForTest.cs b/test/shared/CustomMemoryForTest.cs new file mode 100644 index 0000000000..20406f0a99 --- /dev/null +++ b/test/shared/CustomMemoryForTest.cs @@ -0,0 +1,45 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +namespace System.Buffers +{ + internal class CustomMemoryForTest : IMemoryOwner + { + private bool _disposed; + private T[] _array; + private readonly int _offset; + private readonly int _length; + + public CustomMemoryForTest(T[] array): this(array, 0, array.Length) + { + } + + public CustomMemoryForTest(T[] array, int offset, int length) + { + _array = array; + _offset = offset; + _length = length; + } + + public Memory Memory + { + get + { + if (_disposed) + throw new ObjectDisposedException(nameof(CustomMemoryForTest)); + return new Memory(_array, _offset, _length); + } + } + + public void Dispose() + { + if (_disposed) + return; + + _array = null; + _disposed = true; + } + } +} + diff --git a/test/shared/ReadOnlySequenceFactory.cs b/test/shared/ReadOnlySequenceFactory.cs new file mode 100644 index 0000000000..0fc0c6585f --- /dev/null +++ b/test/shared/ReadOnlySequenceFactory.cs @@ -0,0 +1,148 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Collections.Generic; +using System.Text; + +namespace System.Buffers +{ + internal abstract class ReadOnlySequenceFactory + { + public static ReadOnlySequenceFactory ArrayFactory { get; } = new ArrayTestSequenceFactory(); + public static ReadOnlySequenceFactory MemoryFactory { get; } = new MemoryTestSequenceFactory(); + public static ReadOnlySequenceFactory OwnedMemoryFactory { get; } = new OwnedMemoryTestSequenceFactory(); + public static ReadOnlySequenceFactory SingleSegmentFactory { get; } = new SingleSegmentTestSequenceFactory(); + public static ReadOnlySequenceFactory SegmentPerByteFactory { get; } = new BytePerSegmentTestSequenceFactory(); + + public abstract ReadOnlySequence CreateOfSize(int size); + public abstract ReadOnlySequence CreateWithContent(byte[] data); + + public ReadOnlySequence CreateWithContent(string data) + { + return CreateWithContent(Encoding.ASCII.GetBytes(data)); + } + + internal class ArrayTestSequenceFactory : ReadOnlySequenceFactory + { + public override ReadOnlySequence CreateOfSize(int size) + { + return new ReadOnlySequence(new byte[size + 20], 10, size); + } + + public override ReadOnlySequence CreateWithContent(byte[] data) + { + var startSegment = new byte[data.Length + 20]; + Array.Copy(data, 0, startSegment, 10, data.Length); + return new ReadOnlySequence(startSegment, 10, data.Length); + } + } + + internal class MemoryTestSequenceFactory : ReadOnlySequenceFactory + { + public override ReadOnlySequence CreateOfSize(int size) + { + return CreateWithContent(new byte[size]); + } + + public override ReadOnlySequence CreateWithContent(byte[] data) + { + var startSegment = new byte[data.Length + 20]; + Array.Copy(data, 0, startSegment, 10, data.Length); + return new ReadOnlySequence(new Memory(startSegment, 10, data.Length)); + } + } + + internal class OwnedMemoryTestSequenceFactory : ReadOnlySequenceFactory + { + public override ReadOnlySequence CreateOfSize(int size) + { + return CreateWithContent(new byte[size]); + } + + public override ReadOnlySequence CreateWithContent(byte[] data) + { + var startSegment = new byte[data.Length + 20]; + Array.Copy(data, 0, startSegment, 10, data.Length); + return new ReadOnlySequence(new CustomMemoryForTest(startSegment, 10, data.Length).Memory); + } + } + + internal class SingleSegmentTestSequenceFactory : ReadOnlySequenceFactory + { + public override ReadOnlySequence CreateOfSize(int size) + { + return CreateWithContent(new byte[size]); + } + + public override ReadOnlySequence CreateWithContent(byte[] data) + { + return CreateSegments(data); + } + } + + internal class BytePerSegmentTestSequenceFactory : ReadOnlySequenceFactory + { + public override ReadOnlySequence CreateOfSize(int size) + { + return CreateWithContent(new byte[size]); + } + + public override ReadOnlySequence CreateWithContent(byte[] data) + { + var segments = new List(); + + segments.Add(Array.Empty()); + foreach (var b in data) + { + segments.Add(new[] { b }); + segments.Add(Array.Empty()); + } + + return CreateSegments(segments.ToArray()); + } + } + + public static ReadOnlySequence CreateSegments(params byte[][] inputs) + { + if (inputs == null || inputs.Length == 0) + { + throw new InvalidOperationException(); + } + + int i = 0; + + BufferSegment last = null; + BufferSegment first = null; + + do + { + byte[] s = inputs[i]; + int length = s.Length; + int dataOffset = length; + var chars = new byte[length * 2]; + + for (int j = 0; j < length; j++) + { + chars[dataOffset + j] = s[j]; + } + + // Create a segment that has offset relative to the OwnedMemory and OwnedMemory itself has offset relative to array + var memory = new Memory(chars).Slice(length, length); + + if (first == null) + { + first = new BufferSegment(memory); + last = first; + } + else + { + last = last.Append(memory); + } + i++; + } while (i < inputs.Length); + + return new ReadOnlySequence(first, 0, last, last.Memory.Length); + } + } +} From f179339a79165b40e337d737f80a006407bf88fc Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Thu, 12 Jul 2018 11:58:49 -0700 Subject: [PATCH 1654/1662] Combine BufferWriter and CountingBufferWriter --- .../BenchmarkApplication.cs | 6 +- src/Kestrel.Core/Internal/BufferWriter.cs | 11 ++- src/Kestrel.Core/Internal/Http/ChunkWriter.cs | 4 +- .../Internal/Http/CountingBufferWriter.cs | 99 ------------------- .../Internal/Http/Http1OutputProducer.cs | 4 +- .../Internal/Http/HttpHeaders.Generated.cs | 2 +- .../Internal/Http/HttpProtocol.cs | 2 +- .../Internal/Http/HttpResponseHeaders.cs | 2 +- .../Internal/Http/PipelineExtensions.cs | 8 +- test/Kestrel.Core.Tests/BufferWriterTests.cs | 58 ++++------- .../PipelineExtensionTests.cs | 12 +-- tools/CodeGenerator/KnownHeaders.cs | 2 +- 12 files changed, 46 insertions(+), 164 deletions(-) delete mode 100644 src/Kestrel.Core/Internal/Http/CountingBufferWriter.cs diff --git a/benchmarkapps/PlatformBenchmarks/BenchmarkApplication.cs b/benchmarkapps/PlatformBenchmarks/BenchmarkApplication.cs index d65452c13c..6551bee358 100644 --- a/benchmarkapps/PlatformBenchmarks/BenchmarkApplication.cs +++ b/benchmarkapps/PlatformBenchmarks/BenchmarkApplication.cs @@ -78,7 +78,7 @@ namespace PlatformBenchmarks } private static void PlainText(PipeWriter pipeWriter) { - var writer = new CountingBufferWriter(pipeWriter); + var writer = new BufferWriter(pipeWriter); // HTTP 1.1 OK writer.Write(_http11OK); @@ -105,7 +105,7 @@ namespace PlatformBenchmarks private static void Json(PipeWriter pipeWriter) { - var writer = new CountingBufferWriter(pipeWriter); + var writer = new BufferWriter(pipeWriter); // HTTP 1.1 OK writer.Write(_http11OK); @@ -134,7 +134,7 @@ namespace PlatformBenchmarks private static void Default(PipeWriter pipeWriter) { - var writer = new CountingBufferWriter(pipeWriter); + var writer = new BufferWriter(pipeWriter); // HTTP 1.1 OK writer.Write(_http11OK); diff --git a/src/Kestrel.Core/Internal/BufferWriter.cs b/src/Kestrel.Core/Internal/BufferWriter.cs index 2b63ea920c..1f33f3e4cb 100644 --- a/src/Kestrel.Core/Internal/BufferWriter.cs +++ b/src/Kestrel.Core/Internal/BufferWriter.cs @@ -1,25 +1,27 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Runtime.CompilerServices; namespace System.Buffers { - internal ref struct BufferWriter where T: IBufferWriter + internal ref struct BufferWriter where T : IBufferWriter { private T _output; private Span _span; private int _buffered; + private long _bytesCommitted; public BufferWriter(T output) { _buffered = 0; + _bytesCommitted = 0; _output = output; _span = output.GetSpan(); } public Span Span => _span; + public long BytesCommitted => _bytesCommitted; [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Commit() @@ -27,6 +29,7 @@ namespace System.Buffers var buffered = _buffered; if (buffered > 0) { + _bytesCommitted += buffered; _buffered = 0; _output.Advance(buffered); } diff --git a/src/Kestrel.Core/Internal/Http/ChunkWriter.cs b/src/Kestrel.Core/Internal/Http/ChunkWriter.cs index 2184937b07..3d8cc4566b 100644 --- a/src/Kestrel.Core/Internal/Http/ChunkWriter.cs +++ b/src/Kestrel.Core/Internal/Http/ChunkWriter.cs @@ -48,14 +48,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http return new ArraySegment(bytes, offset, 10 - offset); } - internal static int WriteBeginChunkBytes(ref CountingBufferWriter start, int dataCount) + internal static int WriteBeginChunkBytes(ref BufferWriter start, int dataCount) { var chunkSegment = BeginChunkBytes(dataCount); start.Write(new ReadOnlySpan(chunkSegment.Array, chunkSegment.Offset, chunkSegment.Count)); return chunkSegment.Count; } - internal static void WriteEndChunkBytes(ref CountingBufferWriter start) + internal static void WriteEndChunkBytes(ref BufferWriter start) { start.Write(new ReadOnlySpan(_endChunkBytes.Array, _endChunkBytes.Offset, _endChunkBytes.Count)); } diff --git a/src/Kestrel.Core/Internal/Http/CountingBufferWriter.cs b/src/Kestrel.Core/Internal/Http/CountingBufferWriter.cs deleted file mode 100644 index e3299c6027..0000000000 --- a/src/Kestrel.Core/Internal/Http/CountingBufferWriter.cs +++ /dev/null @@ -1,99 +0,0 @@ - -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System.Runtime.CompilerServices; - -namespace System.Buffers -{ - // TODO: Once this is public, update the actual CountingBufferWriter in the Common repo, - // and go back to using that. - internal ref struct CountingBufferWriter where T: IBufferWriter - { - private T _output; - private Span _span; - private int _buffered; - private long _bytesCommitted; - - public CountingBufferWriter(T output) - { - _buffered = 0; - _bytesCommitted = 0; - _output = output; - _span = output.GetSpan(); - } - - public Span Span => _span; - public long BytesCommitted => _bytesCommitted; - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void Commit() - { - var buffered = _buffered; - if (buffered > 0) - { - _bytesCommitted += buffered; - _buffered = 0; - _output.Advance(buffered); - } - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void Advance(int count) - { - _buffered += count; - _span = _span.Slice(count); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void Write(ReadOnlySpan source) - { - if (_span.Length >= source.Length) - { - source.CopyTo(_span); - Advance(source.Length); - } - else - { - WriteMultiBuffer(source); - } - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void Ensure(int count = 1) - { - if (_span.Length < count) - { - EnsureMore(count); - } - } - - [MethodImpl(MethodImplOptions.NoInlining)] - private void EnsureMore(int count = 0) - { - if (_buffered > 0) - { - Commit(); - } - - _output.GetMemory(count); - _span = _output.GetSpan(); - } - - private void WriteMultiBuffer(ReadOnlySpan source) - { - while (source.Length > 0) - { - if (_span.Length == 0) - { - EnsureMore(); - } - - var writable = Math.Min(source.Length, _span.Length); - source.Slice(0, writable).CopyTo(_span); - source = source.Slice(writable); - Advance(writable); - } - } - } -} diff --git a/src/Kestrel.Core/Internal/Http/Http1OutputProducer.cs b/src/Kestrel.Core/Internal/Http/Http1OutputProducer.cs index 0fd62301bd..685980d1c6 100644 --- a/src/Kestrel.Core/Internal/Http/Http1OutputProducer.cs +++ b/src/Kestrel.Core/Internal/Http/Http1OutputProducer.cs @@ -128,7 +128,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http } var buffer = _pipeWriter; - var writer = new CountingBufferWriter(buffer); + var writer = new BufferWriter(buffer); writer.Write(_bytesHttpVersion11); var statusBytes = ReasonPhrases.ToStatusBytes(statusCode, reasonPhrase); @@ -210,7 +210,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http } writableBuffer = _pipeWriter; - var writer = new CountingBufferWriter(writableBuffer); + var writer = new BufferWriter(writableBuffer); if (buffer.Length > 0) { writer.Write(buffer); diff --git a/src/Kestrel.Core/Internal/Http/HttpHeaders.Generated.cs b/src/Kestrel.Core/Internal/Http/HttpHeaders.Generated.cs index f81e87a06c..d84f15706d 100644 --- a/src/Kestrel.Core/Internal/Http/HttpHeaders.Generated.cs +++ b/src/Kestrel.Core/Internal/Http/HttpHeaders.Generated.cs @@ -7765,7 +7765,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http return true; } - internal void CopyToFast(ref CountingBufferWriter output) + internal void CopyToFast(ref BufferWriter output) { var tempBits = _bits | (_contentLength.HasValue ? -9223372036854775808L : 0); diff --git a/src/Kestrel.Core/Internal/Http/HttpProtocol.cs b/src/Kestrel.Core/Internal/Http/HttpProtocol.cs index 0c759c4451..b0ae93147d 100644 --- a/src/Kestrel.Core/Internal/Http/HttpProtocol.cs +++ b/src/Kestrel.Core/Internal/Http/HttpProtocol.cs @@ -936,7 +936,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http var bytesWritten = 0L; if (buffer.Length > 0) { - var writer = new CountingBufferWriter(writableBuffer); + var writer = new BufferWriter(writableBuffer); ChunkWriter.WriteBeginChunkBytes(ref writer, buffer.Length); writer.Write(buffer.Span); diff --git a/src/Kestrel.Core/Internal/Http/HttpResponseHeaders.cs b/src/Kestrel.Core/Internal/Http/HttpResponseHeaders.cs index a4b81cf69a..1df80f3dc6 100644 --- a/src/Kestrel.Core/Internal/Http/HttpResponseHeaders.cs +++ b/src/Kestrel.Core/Internal/Http/HttpResponseHeaders.cs @@ -27,7 +27,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http return GetEnumerator(); } - internal void CopyTo(ref CountingBufferWriter buffer) + internal void CopyTo(ref BufferWriter buffer) { CopyToFast(ref buffer); if (MaybeUnknown != null) diff --git a/src/Kestrel.Core/Internal/Http/PipelineExtensions.cs b/src/Kestrel.Core/Internal/Http/PipelineExtensions.cs index fce822b6c5..e56c43b23c 100644 --- a/src/Kestrel.Core/Internal/Http/PipelineExtensions.cs +++ b/src/Kestrel.Core/Internal/Http/PipelineExtensions.cs @@ -40,7 +40,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http return result; } - internal static unsafe void WriteAsciiNoValidation(ref this CountingBufferWriter buffer, string data) + internal static unsafe void WriteAsciiNoValidation(ref this BufferWriter buffer, string data) { if (string.IsNullOrEmpty(data)) { @@ -69,7 +69,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http } [MethodImpl(MethodImplOptions.AggressiveInlining)] - internal static unsafe void WriteNumeric(ref this CountingBufferWriter buffer, ulong number) + internal static unsafe void WriteNumeric(ref this BufferWriter buffer, ulong number) { const byte AsciiDigitStart = (byte)'0'; @@ -119,7 +119,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http } [MethodImpl(MethodImplOptions.NoInlining)] - private static void WriteNumericMultiWrite(ref this CountingBufferWriter buffer, ulong number) + private static void WriteNumericMultiWrite(ref this BufferWriter buffer, ulong number) { const byte AsciiDigitStart = (byte)'0'; @@ -140,7 +140,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http } [MethodImpl(MethodImplOptions.NoInlining)] - private unsafe static void WriteAsciiMultiWrite(ref this CountingBufferWriter buffer, string data) + private unsafe static void WriteAsciiMultiWrite(ref this BufferWriter buffer, string data) { var remaining = data.Length; diff --git a/test/Kestrel.Core.Tests/BufferWriterTests.cs b/test/Kestrel.Core.Tests/BufferWriterTests.cs index 8a071385a4..2060ccdb32 100644 --- a/test/Kestrel.Core.Tests/BufferWriterTests.cs +++ b/test/Kestrel.Core.Tests/BufferWriterTests.cs @@ -4,7 +4,6 @@ using System.Buffers; using System.Collections.Generic; using System.Linq; -using System.Threading.Tasks; using Xunit; namespace System.IO.Pipelines.Tests @@ -73,15 +72,20 @@ namespace System.IO.Pipelines.Tests [InlineData(1, 2)] [InlineData(2, 1)] [InlineData(1, 1)] - public void CanWriteWithOffsetAndLenght(int offset, int length) + public void CanWriteWithOffsetAndLength(int offset, int length) { BufferWriter writer = new BufferWriter(Pipe.Writer); var array = new byte[] { 1, 2, 3 }; writer.Write(new Span(array, offset, length)); + + Assert.Equal(0, writer.BytesCommitted); + writer.Commit(); + Assert.Equal(length, writer.BytesCommitted); Assert.Equal(array.Skip(offset).Take(length).ToArray(), Read()); + Assert.Equal(length, writer.BytesCommitted); } [Fact] @@ -94,6 +98,7 @@ namespace System.IO.Pipelines.Tests writer.Write(new Span(array, 0, array.Length)); writer.Commit(); + Assert.Equal(0, writer.BytesCommitted); Assert.Equal(array, Read()); } @@ -105,6 +110,7 @@ namespace System.IO.Pipelines.Tests writer.Write(new byte[] { 1, 2, 3 }); writer.Commit(); + Assert.Equal(3, writer.BytesCommitted); Assert.Equal(new byte[] { 1, 2, 3 }, Read()); } @@ -118,6 +124,7 @@ namespace System.IO.Pipelines.Tests writer.Write(new byte[] { 3 }); writer.Commit(); + Assert.Equal(3, writer.BytesCommitted); Assert.Equal(new byte[] { 1, 2, 3 }, Read()); } @@ -133,6 +140,7 @@ namespace System.IO.Pipelines.Tests writer.Write(expectedBytes); writer.Commit(); + Assert.Equal(expectedBytes.LongLength, writer.BytesCommitted); Assert.Equal(expectedBytes, Read()); } @@ -142,6 +150,7 @@ namespace System.IO.Pipelines.Tests BufferWriter writer = new BufferWriter(Pipe.Writer); writer.Ensure(10); Assert.True(writer.Span.Length > 10); + Assert.Equal(0, writer.BytesCommitted); Assert.Equal(new byte[] { }, Read()); } @@ -164,6 +173,7 @@ namespace System.IO.Pipelines.Tests writer.Write(new byte[] { 1, 2, 3 }); writer.Commit(); + Assert.Equal(3, writer.BytesCommitted); Assert.Equal(initialLength - 3, writer.Span.Length); Assert.Equal(Pipe.Writer.GetMemory().Length, writer.Span.Length); Assert.Equal(new byte[] { 1, 2, 3 }, Read()); @@ -175,49 +185,17 @@ namespace System.IO.Pipelines.Tests [InlineData(500)] [InlineData(5000)] [InlineData(50000)] - public async Task WriteLargeDataBinary(int length) + public void WriteLargeDataBinary(int length) { var data = new byte[length]; new Random(length).NextBytes(data); - PipeWriter output = Pipe.Writer; - output.Write(data); - await output.FlushAsync(); - ReadResult result = await Pipe.Reader.ReadAsync(); - ReadOnlySequence input = result.Buffer; - Assert.Equal(data, input.ToArray()); - Pipe.Reader.AdvanceTo(input.End); - } + BufferWriter writer = new BufferWriter(Pipe.Writer); + writer.Write(data); + writer.Commit(); - [Fact] - public async Task CanWriteNothingToBuffer() - { - PipeWriter buffer = Pipe.Writer; - buffer.GetMemory(0); - buffer.Advance(0); // doing nothing, the hard way - await buffer.FlushAsync(); - } - - [Fact] - public void EmptyWriteDoesNotThrow() - { - Pipe.Writer.Write(new byte[0]); - } - - [Fact] - public void ThrowsOnAdvanceOverMemorySize() - { - Memory buffer = Pipe.Writer.GetMemory(1); - var exception = Assert.Throws(() => Pipe.Writer.Advance(buffer.Length + 1)); - Assert.Equal("Can't advance past buffer size.", exception.Message); - } - - [Fact] - public void ThrowsOnAdvanceWithNoMemory() - { - PipeWriter buffer = Pipe.Writer; - var exception = Assert.Throws(() => buffer.Advance(1)); - Assert.Equal("No writing operation. Make sure GetMemory() was called.", exception.Message); + Assert.Equal(length, writer.BytesCommitted); + Assert.Equal(data, Read()); } } } diff --git a/test/Kestrel.Core.Tests/PipelineExtensionTests.cs b/test/Kestrel.Core.Tests/PipelineExtensionTests.cs index 43c385772e..e3a89832da 100644 --- a/test/Kestrel.Core.Tests/PipelineExtensionTests.cs +++ b/test/Kestrel.Core.Tests/PipelineExtensionTests.cs @@ -36,7 +36,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests public void WritesNumericToAscii(ulong number) { var writerBuffer = _pipe.Writer; - var writer = new CountingBufferWriter(writerBuffer); + var writer = new BufferWriter(writerBuffer); writer.WriteNumeric(number); writer.Commit(); writerBuffer.FlushAsync().GetAwaiter().GetResult(); @@ -54,7 +54,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests public void WritesNumericAcrossSpanBoundaries(int gapSize) { var writerBuffer = _pipe.Writer; - var writer = new CountingBufferWriter(writerBuffer); + var writer = new BufferWriter(writerBuffer); // almost fill up the first block var spacer = new byte[writer.Span.Length - gapSize]; writer.Write(spacer); @@ -85,7 +85,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests public void EncodesAsAscii(string input, byte[] expected) { var pipeWriter = _pipe.Writer; - var writer = new CountingBufferWriter(pipeWriter); + var writer = new BufferWriter(pipeWriter); writer.WriteAsciiNoValidation(input); writer.Commit(); pipeWriter.FlushAsync().GetAwaiter().GetResult(); @@ -115,7 +115,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests // WriteAscii doesn't validate if characters are in the ASCII range // but it shouldn't produce more than one byte per character var writerBuffer = _pipe.Writer; - var writer = new CountingBufferWriter(writerBuffer); + var writer = new BufferWriter(writerBuffer); writer.WriteAsciiNoValidation(input); writer.Commit(); writerBuffer.FlushAsync().GetAwaiter().GetResult(); @@ -129,7 +129,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests { const byte maxAscii = 0x7f; var writerBuffer = _pipe.Writer; - var writer = new CountingBufferWriter(writerBuffer); + var writer = new BufferWriter(writerBuffer); for (var i = 0; i < maxAscii; i++) { writer.WriteAsciiNoValidation(new string((char)i, 1)); @@ -159,7 +159,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests { var testString = new string(' ', stringLength); var writerBuffer = _pipe.Writer; - var writer = new CountingBufferWriter(writerBuffer); + var writer = new BufferWriter(writerBuffer); // almost fill up the first block var spacer = new byte[writer.Span.Length - gapSize]; writer.Write(spacer); diff --git a/tools/CodeGenerator/KnownHeaders.cs b/tools/CodeGenerator/KnownHeaders.cs index badf9087a7..08646dc61a 100644 --- a/tools/CodeGenerator/KnownHeaders.cs +++ b/tools/CodeGenerator/KnownHeaders.cs @@ -548,7 +548,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http return true; }} {(loop.ClassName == "HttpResponseHeaders" ? $@" - internal void CopyToFast(ref CountingBufferWriter output) + internal void CopyToFast(ref BufferWriter output) {{ var tempBits = _bits | (_contentLength.HasValue ? {1L << 63}L : 0); {Each(loop.Headers.Where(header => header.Identifier != "ContentLength").OrderBy(h => !h.PrimaryHeader), header => $@" From d8c77335e835f9b633f994de6f7ba563ac4d603d Mon Sep 17 00:00:00 2001 From: Nate McMaster Date: Thu, 12 Jul 2018 13:17:28 -0700 Subject: [PATCH 1655/1662] Reorganize code so Kestrel now produces the Microsoft.Extensions.Buffers.Testing.Sources package --- NuGetPackageVerifier.json | 8 +++++++- .../BufferSegment.cs | 0 .../CustomMemoryForTest.cs | 0 .../ReadOnlySequenceFactory.cs | 0 test/Kestrel.Core.Tests/Kestrel.Core.Tests.csproj | 1 + 5 files changed, 8 insertions(+), 1 deletion(-) rename {test/shared => shared/Microsoft.Extensions.Buffers.Testing.Sources}/BufferSegment.cs (100%) rename {test/shared => shared/Microsoft.Extensions.Buffers.Testing.Sources}/CustomMemoryForTest.cs (100%) rename {test/shared => shared/Microsoft.Extensions.Buffers.Testing.Sources}/ReadOnlySequenceFactory.cs (100%) diff --git a/NuGetPackageVerifier.json b/NuGetPackageVerifier.json index b153ab1515..4f55b78b16 100644 --- a/NuGetPackageVerifier.json +++ b/NuGetPackageVerifier.json @@ -1,7 +1,13 @@ { + "adx-nonshipping": { + "rules": [], + "packages": { + "Microsoft.Extensions.Buffers.Testing.Sources": {} + } + }, "Default": { "rules": [ "DefaultCompositeRule" ] } -} \ No newline at end of file +} diff --git a/test/shared/BufferSegment.cs b/shared/Microsoft.Extensions.Buffers.Testing.Sources/BufferSegment.cs similarity index 100% rename from test/shared/BufferSegment.cs rename to shared/Microsoft.Extensions.Buffers.Testing.Sources/BufferSegment.cs diff --git a/test/shared/CustomMemoryForTest.cs b/shared/Microsoft.Extensions.Buffers.Testing.Sources/CustomMemoryForTest.cs similarity index 100% rename from test/shared/CustomMemoryForTest.cs rename to shared/Microsoft.Extensions.Buffers.Testing.Sources/CustomMemoryForTest.cs diff --git a/test/shared/ReadOnlySequenceFactory.cs b/shared/Microsoft.Extensions.Buffers.Testing.Sources/ReadOnlySequenceFactory.cs similarity index 100% rename from test/shared/ReadOnlySequenceFactory.cs rename to shared/Microsoft.Extensions.Buffers.Testing.Sources/ReadOnlySequenceFactory.cs diff --git a/test/Kestrel.Core.Tests/Kestrel.Core.Tests.csproj b/test/Kestrel.Core.Tests/Kestrel.Core.Tests.csproj index fdbbd000ef..2074ed6526 100644 --- a/test/Kestrel.Core.Tests/Kestrel.Core.Tests.csproj +++ b/test/Kestrel.Core.Tests/Kestrel.Core.Tests.csproj @@ -9,6 +9,7 @@ + From eb7835f4c83a6d7e06d9d06d0f89748aa761727a Mon Sep 17 00:00:00 2001 From: Nate McMaster Date: Wed, 11 Jul 2018 18:49:09 -0700 Subject: [PATCH 1656/1662] Updating dependencies to 2.1.2 and adding a section for pinned variable versions --- build/dependencies.props | 15 +++++++++++---- korebuild-lock.txt | 4 ++-- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/build/dependencies.props b/build/dependencies.props index 90b286111a..7a5f07df07 100644 --- a/build/dependencies.props +++ b/build/dependencies.props @@ -3,11 +3,13 @@ $(MSBuildAllProjects);$(MSBuildThisFileFullPath) - + + + 0.10.13 - 2.1.1-rtm-15793 + 2.1.3-rtm-15802 1.10.0 - 2.1.1 + 2.1.2 2.1.1 2.1.1 2.1.1 @@ -28,7 +30,7 @@ 2.1.1 2.1.1 2.0.0 - 2.1.1 + 2.1.2 2.1.1 15.6.1 4.7.49 @@ -46,5 +48,10 @@ 2.3.1 2.4.0-beta.1.build3945 + + + + + diff --git a/korebuild-lock.txt b/korebuild-lock.txt index bc84e0cd53..251c227c83 100644 --- a/korebuild-lock.txt +++ b/korebuild-lock.txt @@ -1,2 +1,2 @@ -version:2.1.1-rtm-15793 -commithash:988313f4b064d6c69fc6f7b845b6384a6af3447a +version:2.1.3-rtm-15802 +commithash:a7c08b45b440a7d2058a0aa1eaa3eb6ba811976a From 85bf01da82a2e6fd20c7dd3b9693468fcb2552e2 Mon Sep 17 00:00:00 2001 From: Nate McMaster Date: Thu, 12 Jul 2018 11:54:51 -0700 Subject: [PATCH 1657/1662] Pin version variables to the ASP.NET Core 2.1.2 baseline This reverts our previous policy of cascading versions on all servicing updates. This moves variables into the 'pinned' section, and points them to the latest stable release (versions that were used at the time of the 2.1.2 release). --- build/dependencies.props | 49 ++++++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 24 deletions(-) diff --git a/build/dependencies.props b/build/dependencies.props index 7a5f07df07..b855ca56d0 100644 --- a/build/dependencies.props +++ b/build/dependencies.props @@ -5,33 +5,12 @@ - + 0.10.13 2.1.3-rtm-15802 1.10.0 - 2.1.2 - 2.1.1 - 2.1.1 - 2.1.1 - 2.1.1 - 2.1.1 - 2.1.1 - 2.1.1 - 2.1.0 - 2.1.1 - 2.1.1 - 2.1.1 - 2.1.1 - 2.1.1 - 2.1.1 - 2.1.1 - 2.1.1 - 2.1.1 - 2.1.1 - 2.1.1 2.0.0 2.1.2 - 2.1.1 15.6.1 4.7.49 2.0.3 @@ -53,5 +32,27 @@ - - + + 2.1.2 + 2.1.1 + 2.1.1 + 2.1.1 + 2.1.1 + 2.1.1 + 2.1.1 + 2.1.1 + 2.1.0 + 2.1.1 + 2.1.1 + 2.1.1 + 2.1.1 + 2.1.1 + 2.1.1 + 2.1.1 + 2.1.1 + 2.1.1 + 2.1.1 + 2.1.1 + 2.1.1 + + \ No newline at end of file From 2f3b56540152cc57e3ed3130f1982608f3648506 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Mon, 11 Jun 2018 16:43:33 -0700 Subject: [PATCH 1658/1662] Minimize blocking threads to improve test reliability --- .../Kestrel.Core.Tests/HttpConnectionTests.cs | 26 ++++---- test/Kestrel.Core.Tests/MessageBodyTests.cs | 6 +- .../ChunkedResponseTests.cs | 6 +- .../RequestBodyTimeoutTests.cs | 61 ++++++++++++++----- test/Kestrel.FunctionalTests/RequestTests.cs | 12 ++-- test/Kestrel.FunctionalTests/ResponseTests.cs | 43 +++++++------ 6 files changed, 92 insertions(+), 62 deletions(-) diff --git a/test/Kestrel.Core.Tests/HttpConnectionTests.cs b/test/Kestrel.Core.Tests/HttpConnectionTests.cs index 091b3cadea..c8dbf28ba0 100644 --- a/test/Kestrel.Core.Tests/HttpConnectionTests.cs +++ b/test/Kestrel.Core.Tests/HttpConnectionTests.cs @@ -418,10 +418,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests } [Fact] - public void WriteTimingAbortsConnectionWhenWriteDoesNotCompleteWithMinimumDataRate() + public async Task WriteTimingAbortsConnectionWhenWriteDoesNotCompleteWithMinimumDataRate() { var systemClock = new MockSystemClock(); - var aborted = new ManualResetEventSlim(); + var aborted = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); _httpConnectionContext.ServiceContext.ServerOptions.Limits.MinResponseDataRate = new MinDataRate(bytesPerSecond: 100, gracePeriod: TimeSpan.FromSeconds(2)); @@ -434,7 +434,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests _httpConnection.Http1Connection.Reset(); _httpConnection.Http1Connection.RequestAborted.Register(() => { - aborted.Set(); + aborted.SetResult(null); }); // Initialize timestamp @@ -448,15 +448,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests _httpConnection.Tick(systemClock.UtcNow); Assert.True(_httpConnection.RequestTimedOut); - Assert.True(aborted.Wait(TimeSpan.FromSeconds(10))); + await aborted.Task.DefaultTimeout(); } [Fact] - public void WriteTimingAbortsConnectionWhenSmallWriteDoesNotCompleteWithinGracePeriod() + public async Task WriteTimingAbortsConnectionWhenSmallWriteDoesNotCompleteWithinGracePeriod() { var systemClock = new MockSystemClock(); var minResponseDataRate = new MinDataRate(bytesPerSecond: 100, gracePeriod: TimeSpan.FromSeconds(5)); - var aborted = new ManualResetEventSlim(); + var aborted = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); _httpConnectionContext.ServiceContext.ServerOptions.Limits.MinResponseDataRate = minResponseDataRate; _httpConnectionContext.ServiceContext.SystemClock = systemClock; @@ -468,7 +468,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests _httpConnection.Http1Connection.Reset(); _httpConnection.Http1Connection.RequestAborted.Register(() => { - aborted.Set(); + aborted.SetResult(null); }); // Initialize timestamp @@ -490,14 +490,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests _httpConnection.Tick(systemClock.UtcNow); Assert.True(_httpConnection.RequestTimedOut); - Assert.True(aborted.Wait(TimeSpan.FromSeconds(10))); + await aborted.Task.DefaultTimeout(); } [Fact] - public void WriteTimingTimeoutPushedOnConcurrentWrite() + public async Task WriteTimingTimeoutPushedOnConcurrentWrite() { var systemClock = new MockSystemClock(); - var aborted = new ManualResetEventSlim(); + var aborted = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); _httpConnectionContext.ServiceContext.ServerOptions.Limits.MinResponseDataRate = new MinDataRate(bytesPerSecond: 100, gracePeriod: TimeSpan.FromSeconds(2)); @@ -510,7 +510,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests _httpConnection.Http1Connection.Reset(); _httpConnection.Http1Connection.RequestAborted.Register(() => { - aborted.Set(); + aborted.SetResult(null); }); // Initialize timestamp @@ -537,7 +537,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests _httpConnection.Tick(systemClock.UtcNow); Assert.True(_httpConnection.RequestTimedOut); - Assert.True(aborted.Wait(TimeSpan.FromSeconds(10))); + await aborted.Task.DefaultTimeout(); } [Fact] @@ -547,7 +547,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests var minResponseDataRate = new MinDataRate(bytesPerSecond: 100, gracePeriod: TimeSpan.FromSeconds(5)); var numWrites = 5; var writeSize = 100; - var aborted = new TaskCompletionSource(); + var aborted = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); _httpConnectionContext.ServiceContext.ServerOptions.Limits.MinResponseDataRate = minResponseDataRate; _httpConnectionContext.ServiceContext.SystemClock = systemClock; diff --git a/test/Kestrel.Core.Tests/MessageBodyTests.cs b/test/Kestrel.Core.Tests/MessageBodyTests.cs index 703808a400..5f006b12e3 100644 --- a/test/Kestrel.Core.Tests/MessageBodyTests.cs +++ b/test/Kestrel.Core.Tests/MessageBodyTests.cs @@ -687,11 +687,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests { using (var input = new TestInput()) { - var logEvent = new ManualResetEventSlim(); + var logEvent = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); var mockLogger = new Mock(); mockLogger .Setup(logger => logger.RequestBodyDone("ConnectionId", "RequestId")) - .Callback(() => logEvent.Set()); + .Callback(() => logEvent.SetResult(null)); input.Http1Connection.ServiceContext.Log = mockLogger.Object; input.Http1Connection.ConnectionIdFeature = "ConnectionId"; input.Http1Connection.TraceIdentifier = "RequestId"; @@ -706,7 +706,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests input.Fin(); - Assert.True(logEvent.Wait(TestConstants.DefaultTimeout)); + await logEvent.Task.DefaultTimeout(); await body.StopAsync(); } diff --git a/test/Kestrel.FunctionalTests/ChunkedResponseTests.cs b/test/Kestrel.FunctionalTests/ChunkedResponseTests.cs index c9a7e70747..6cb1a9e439 100644 --- a/test/Kestrel.FunctionalTests/ChunkedResponseTests.cs +++ b/test/Kestrel.FunctionalTests/ChunkedResponseTests.cs @@ -350,7 +350,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { var testContext = new TestServiceContext(LoggerFactory); - var flushWh = new ManualResetEventSlim(); + var flushWh = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); using (var server = new TestServer(async httpContext => { @@ -358,7 +358,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests await response.Body.WriteAsync(Encoding.ASCII.GetBytes("Hello "), 0, 6); // Don't complete response until client has received the first chunk. - flushWh.Wait(); + await flushWh.Task.DefaultTimeout(); await response.Body.WriteAsync(Encoding.ASCII.GetBytes("World!"), 0, 6); }, testContext, listenOptions)) @@ -379,7 +379,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests "Hello ", ""); - flushWh.Set(); + flushWh.SetResult(null); await connection.ReceiveEnd( "6", diff --git a/test/Kestrel.FunctionalTests/RequestBodyTimeoutTests.cs b/test/Kestrel.FunctionalTests/RequestBodyTimeoutTests.cs index 0ae0e9f0ce..9d292e53fc 100644 --- a/test/Kestrel.FunctionalTests/RequestBodyTimeoutTests.cs +++ b/test/Kestrel.FunctionalTests/RequestBodyTimeoutTests.cs @@ -30,15 +30,39 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests DateHeaderValueManager = new DateHeaderValueManager(systemClock) }; - var appRunningEvent = new ManualResetEventSlim(); + var appRunningEvent = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); using (var server = new TestServer(context => { context.Features.Get().MinDataRate = new MinDataRate(bytesPerSecond: 1, gracePeriod: gracePeriod); - appRunningEvent.Set(); - return context.Request.Body.ReadAsync(new byte[1], 0, 1); + // The server must call Request.Body.ReadAsync() *before* the test sets systemClock.UtcNow (which is triggered by the + // server calling appRunningEvent.SetResult(null)). If systemClock.UtcNow is set first, it's possible for the test to fail + // due to the following race condition: + // + // 1. [test] systemClock.UtcNow += gracePeriod + TimeSpan.FromSeconds(1); + // 2. [server] Heartbeat._timer is triggered, which calls HttpConnection.Tick() + // 3. [server] HttpConnection.Tick() calls HttpConnection.CheckForReadDataRateTimeout() + // 4. [server] HttpConnection.CheckForReadDataRateTimeout() is a no-op, since _readTimingEnabled is false, + // since Request.Body.ReadAsync() has not been called yet + // 5. [server] HttpConnection.Tick() sets _lastTimestamp = timestamp + // 6. [server] Request.Body.ReadAsync() is called + // 6. [test] systemClock.UtcNow is never updated again, so server timestamp is never updated, + // so HttpConnection.CheckForReadDataRateTimeout() is always a no-op until test fails + // + // This is a pretty tight race, since the once-per-second Heartbeat._timer needs to fire between the test updating + // systemClock.UtcNow and the server calling Request.Body.ReadAsync(). But it happened often enough to cause + // test flakiness in our CI (https://github.com/aspnet/KestrelHttpServer/issues/2539). + // + // For verification, I was able to induce the race by adding a sleep in the RequestDelegate: + // appRunningEvent.SetResult(null); + // Thread.Sleep(5000); + // return context.Request.Body.ReadAsync(new byte[1], 0, 1); + + var readTask = context.Request.Body.ReadAsync(new byte[1], 0, 1); + appRunningEvent.SetResult(null); + return readTask; }, serviceContext)) { using (var connection = server.CreateConnection()) @@ -50,7 +74,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests "", ""); - Assert.True(appRunningEvent.Wait(TestConstants.DefaultTimeout)); + await appRunningEvent.Task.DefaultTimeout(); systemClock.UtcNow += gracePeriod + TimeSpan.FromSeconds(1); await connection.Receive( @@ -77,13 +101,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests DateHeaderValueManager = new DateHeaderValueManager(systemClock), }; - var appRunningEvent = new ManualResetEventSlim(); + var appRunningEvent = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); using (var server = new TestServer(context => { context.Features.Get().MinDataRate = null; - appRunningEvent.Set(); + appRunningEvent.SetResult(null); return Task.CompletedTask; }, serviceContext)) { @@ -96,7 +120,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests "", ""); - Assert.True(appRunningEvent.Wait(TestConstants.DefaultTimeout)); + await appRunningEvent.Task.DefaultTimeout(); await connection.Receive( "HTTP/1.1 200 OK", @@ -115,7 +139,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests Assert.Contains(TestSink.Writes, w => w.EventId.Id == 33 && w.LogLevel == LogLevel.Information); } - [Fact(Skip="https://github.com/aspnet/KestrelHttpServer/issues/2464")] + [Fact] public async Task ConnectionClosedEvenIfAppSwallowsException() { var gracePeriod = TimeSpan.FromSeconds(5); @@ -126,23 +150,30 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests DateHeaderValueManager = new DateHeaderValueManager(systemClock) }; - var appRunningEvent = new ManualResetEventSlim(); - var exceptionSwallowedEvent = new ManualResetEventSlim(); + var appRunningTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var exceptionSwallowedTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); using (var server = new TestServer(async context => { context.Features.Get().MinDataRate = new MinDataRate(bytesPerSecond: 1, gracePeriod: gracePeriod); - appRunningEvent.Set(); + // See comment in RequestTimesOutWhenRequestBodyNotReceivedAtSpecifiedMinimumRate for + // why we call ReadAsync before setting the appRunningEvent. + var readTask = context.Request.Body.ReadAsync(new byte[1], 0, 1); + appRunningTcs.SetResult(null); try { - await context.Request.Body.ReadAsync(new byte[1], 0, 1); + await readTask; } catch (BadHttpRequestException ex) when (ex.StatusCode == 408) { - exceptionSwallowedEvent.Set(); + exceptionSwallowedTcs.SetResult(null); + } + catch (Exception ex) + { + exceptionSwallowedTcs.SetException(ex); } var response = "hello, world"; @@ -159,9 +190,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests "", ""); - Assert.True(appRunningEvent.Wait(TestConstants.DefaultTimeout), "AppRunningEvent timed out."); + await appRunningTcs.Task.DefaultTimeout(); systemClock.UtcNow += gracePeriod + TimeSpan.FromSeconds(1); - Assert.True(exceptionSwallowedEvent.Wait(TestConstants.DefaultTimeout), "ExceptionSwallowedEvent timed out."); + await exceptionSwallowedTcs.Task.DefaultTimeout(); await connection.Receive( "HTTP/1.1 200 OK", diff --git a/test/Kestrel.FunctionalTests/RequestTests.cs b/test/Kestrel.FunctionalTests/RequestTests.cs index eac3aaa369..32dfac74fc 100644 --- a/test/Kestrel.FunctionalTests/RequestTests.cs +++ b/test/Kestrel.FunctionalTests/RequestTests.cs @@ -1696,8 +1696,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [Fact] public async Task DoesNotEnforceRequestBodyMinimumDataRateOnUpgradedRequest() { - var appEvent = new ManualResetEventSlim(); - var delayEvent = new ManualResetEventSlim(); + var appEvent = new TaskCompletionSource(); + var delayEvent = new TaskCompletionSource(); var serviceContext = new TestServiceContext(LoggerFactory) { SystemClock = new SystemClock() @@ -1710,12 +1710,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests using (var stream = await context.Features.Get().UpgradeAsync()) { - appEvent.Set(); + appEvent.SetResult(null); // Read once to go through one set of TryPauseTimingReads()/TryResumeTimingReads() calls await stream.ReadAsync(new byte[1], 0, 1); - delayEvent.Wait(); + await delayEvent.Task.DefaultTimeout(); // Read again to check that the connection is still alive await stream.ReadAsync(new byte[1], 0, 1); @@ -1735,11 +1735,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests "", "a"); - Assert.True(appEvent.Wait(TestConstants.DefaultTimeout)); + await appEvent.Task.DefaultTimeout(); await Task.Delay(TimeSpan.FromSeconds(5)); - delayEvent.Set(); + delayEvent.SetResult(null); await connection.Send("b"); diff --git a/test/Kestrel.FunctionalTests/ResponseTests.cs b/test/Kestrel.FunctionalTests/ResponseTests.cs index 9660dca2f3..2f22bc1f67 100644 --- a/test/Kestrel.FunctionalTests/ResponseTests.cs +++ b/test/Kestrel.FunctionalTests/ResponseTests.cs @@ -1116,12 +1116,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests var flushed = new SemaphoreSlim(0, 1); var serviceContext = new TestServiceContext(LoggerFactory) { ServerOptions = { AllowSynchronousIO = true } }; - using (var server = new TestServer(httpContext => + using (var server = new TestServer(async httpContext => { httpContext.Response.ContentLength = 12; httpContext.Response.Body.Write(Encoding.ASCII.GetBytes("hello, world"), 0, 12); - flushed.Wait(); - return Task.CompletedTask; + await flushed.WaitAsync(); }, serviceContext)) { using (var connection = server.CreateConnection()) @@ -1152,7 +1151,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { httpContext.Response.ContentLength = 12; await httpContext.Response.WriteAsync(""); - flushed.Wait(); + await flushed.WaitAsync(); await httpContext.Response.WriteAsync("hello, world"); }, new TestServiceContext(LoggerFactory))) { @@ -1180,23 +1179,23 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [Fact] public async Task WriteAfterConnectionCloseNoops() { - var connectionClosed = new ManualResetEventSlim(); - var requestStarted = new ManualResetEventSlim(); - var tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var connectionClosed = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var requestStarted = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var appCompleted = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); using (var server = new TestServer(async httpContext => { try { - requestStarted.Set(); - connectionClosed.Wait(); + requestStarted.SetResult(null); + await connectionClosed.Task.DefaultTimeout(); httpContext.Response.ContentLength = 12; await httpContext.Response.WriteAsync("hello, world"); - tcs.TrySetResult(null); + appCompleted.TrySetResult(null); } catch (Exception ex) { - tcs.TrySetException(ex); + appCompleted.TrySetException(ex); } }, new TestServiceContext(LoggerFactory))) { @@ -1208,14 +1207,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests "", ""); - requestStarted.Wait(); + await requestStarted.Task.DefaultTimeout(); connection.Shutdown(SocketShutdown.Send); await connection.WaitForConnectionClose().DefaultTimeout(); } - connectionClosed.Set(); + connectionClosed.SetResult(null); - await tcs.Task.DefaultTimeout(); + await appCompleted.Task.DefaultTimeout(); } } @@ -2280,19 +2279,19 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests var largeString = new string('a', maxBytesPreCompleted + 1); var writeTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); - var requestAbortedWh = new ManualResetEventSlim(); - var requestStartWh = new ManualResetEventSlim(); + var requestAbortedWh = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var requestStartWh = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); using (var server = new TestServer(async httpContext => { - requestStartWh.Set(); + requestStartWh.SetResult(null); var response = httpContext.Response; var request = httpContext.Request; var lifetime = httpContext.Features.Get(); - lifetime.RequestAborted.Register(() => requestAbortedWh.Set()); - Assert.True(requestAbortedWh.Wait(TestConstants.DefaultTimeout)); + lifetime.RequestAborted.Register(() => requestAbortedWh.SetResult(null)); + await requestAbortedWh.Task.DefaultTimeout(); try { @@ -2316,15 +2315,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests "", ""); - Assert.True(requestStartWh.Wait(TestConstants.DefaultTimeout)); + await requestStartWh.Task.DefaultTimeout(); } // Write failed - can throw TaskCanceledException or OperationCanceledException, - // dependending on how far the canceled write goes. + // depending on how far the canceled write goes. await Assert.ThrowsAnyAsync(async () => await writeTcs.Task).DefaultTimeout(); // RequestAborted tripped - Assert.True(requestAbortedWh.Wait(TestConstants.DefaultTimeout)); + await requestAbortedWh.Task.DefaultTimeout(); } } From 5ba327faa1306a3977acb58511728daedc31d243 Mon Sep 17 00:00:00 2001 From: John Luo Date: Tue, 11 Sep 2018 09:59:54 -0700 Subject: [PATCH 1659/1662] Relax connection stop checks in tests to reduce flakiness --- test/Kestrel.FunctionalTests/RequestTests.cs | 4 ++-- test/Kestrel.FunctionalTests/ResponseTests.cs | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/test/Kestrel.FunctionalTests/RequestTests.cs b/test/Kestrel.FunctionalTests/RequestTests.cs index 32dfac74fc..d0fe276273 100644 --- a/test/Kestrel.FunctionalTests/RequestTests.cs +++ b/test/Kestrel.FunctionalTests/RequestTests.cs @@ -1302,7 +1302,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests await appFuncCompleted.Task.DefaultTimeout(); } - mockKestrelTrace.Verify(t => t.ConnectionStop(It.IsAny()), Times.Once()); + mockKestrelTrace.Verify(t => t.ConnectionStop(It.IsAny()), Times.AtMostOnce()); } [Theory] @@ -1357,7 +1357,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests await Assert.ThrowsAnyAsync(() => readTcs.Task).DefaultTimeout(); } - mockKestrelTrace.Verify(t => t.ConnectionStop(It.IsAny()), Times.Once()); + mockKestrelTrace.Verify(t => t.ConnectionStop(It.IsAny()), Times.AtMostOnce()); } [Theory] diff --git a/test/Kestrel.FunctionalTests/ResponseTests.cs b/test/Kestrel.FunctionalTests/ResponseTests.cs index 2f22bc1f67..5763a54a5b 100644 --- a/test/Kestrel.FunctionalTests/ResponseTests.cs +++ b/test/Kestrel.FunctionalTests/ResponseTests.cs @@ -2427,7 +2427,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests await Assert.ThrowsAnyAsync(() => writeTcs.Task).DefaultTimeout(); } - mockKestrelTrace.Verify(t => t.ConnectionStop(It.IsAny()), Times.Once()); + mockKestrelTrace.Verify(t => t.ConnectionStop(It.IsAny()), Times.AtMostOnce()); Assert.True(requestAborted); } @@ -3174,7 +3174,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests await appFuncCompleted.Task.DefaultTimeout(); mockKestrelTrace.Verify(t => t.ResponseMininumDataRateNotSatisfied(It.IsAny(), It.IsAny()), Times.Never()); - mockKestrelTrace.Verify(t => t.ConnectionStop(It.IsAny()), Times.Once()); + mockKestrelTrace.Verify(t => t.ConnectionStop(It.IsAny()), Times.AtMostOnce()); Assert.False(requestAborted); } } @@ -3249,7 +3249,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests await AssertStreamCompleted(connection.Reader.BaseStream, minTotalOutputSize, targetBytesPerSecond); mockKestrelTrace.Verify(t => t.ResponseMininumDataRateNotSatisfied(It.IsAny(), It.IsAny()), Times.Never()); - mockKestrelTrace.Verify(t => t.ConnectionStop(It.IsAny()), Times.Once()); + mockKestrelTrace.Verify(t => t.ConnectionStop(It.IsAny()), Times.AtMostOnce()); Assert.False(requestAborted); } } From e5b2b680e07ec6142bfd0f2ca39592f1acf85b2f Mon Sep 17 00:00:00 2001 From: John Luo Date: Fri, 7 Sep 2018 18:18:02 -0700 Subject: [PATCH 1660/1662] Fix flaky test by ignoring indeterminant response --- test/Kestrel.FunctionalTests/ChunkedRequestTests.cs | 2 +- test/shared/TestConnection.cs | 12 +++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/test/Kestrel.FunctionalTests/ChunkedRequestTests.cs b/test/Kestrel.FunctionalTests/ChunkedRequestTests.cs index 10b68fdf45..ecbb6f23b2 100644 --- a/test/Kestrel.FunctionalTests/ChunkedRequestTests.cs +++ b/test/Kestrel.FunctionalTests/ChunkedRequestTests.cs @@ -678,7 +678,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests connection.Socket.Shutdown(SocketShutdown.Send); - await connection.ReceiveEnd(); + await connection.ReceiveEnd(ignoreResponse: true); var badReqEx = await exTcs.Task.TimeoutAfter(TestConstants.DefaultTimeout); Assert.Equal(RequestRejectionReason.UnexpectedEndOfRequestContent, badReqEx.Reason); diff --git a/test/shared/TestConnection.cs b/test/shared/TestConnection.cs index 2d760a5bc8..6469dd2d19 100644 --- a/test/shared/TestConnection.cs +++ b/test/shared/TestConnection.cs @@ -149,14 +149,20 @@ namespace Microsoft.AspNetCore.Testing Assert.Equal(expected, new string(actual, 0, offset)); } - public async Task ReceiveEnd(params string[] lines) + public Task ReceiveEnd(params string[] lines) + => ReceiveEnd(false, lines); + + public async Task ReceiveEnd(bool ignoreResponse, params string[] lines) { await Receive(lines).ConfigureAwait(false); _socket.Shutdown(SocketShutdown.Send); var ch = new char[128]; var count = await _reader.ReadAsync(ch, 0, 128).TimeoutAfter(Timeout).ConfigureAwait(false); - var text = new string(ch, 0, count); - Assert.Equal("", text); + if (!ignoreResponse) + { + var text = new string(ch, 0, count); + Assert.Equal("", text); + } } public async Task ReceiveForcedEnd(params string[] lines) From 15ba5065a9b220f545eb3118d9e552f0b7e824d0 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Tue, 18 Sep 2018 14:11:28 -0700 Subject: [PATCH 1661/1662] Skip connection reset tests on macOS in 2.1 (#2942) --- test/Kestrel.FunctionalTests/HttpsTests.cs | 4 +++- test/Kestrel.FunctionalTests/RequestTests.cs | 15 ++++++++++----- test/Kestrel.FunctionalTests/ResponseTests.cs | 7 +++++-- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/test/Kestrel.FunctionalTests/HttpsTests.cs b/test/Kestrel.FunctionalTests/HttpsTests.cs index b1cc95b24a..9de8a29b48 100644 --- a/test/Kestrel.FunctionalTests/HttpsTests.cs +++ b/test/Kestrel.FunctionalTests/HttpsTests.cs @@ -18,6 +18,7 @@ using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.AspNetCore.Server.Kestrel.Https; using Microsoft.AspNetCore.Server.Kestrel.Https.Internal; using Microsoft.AspNetCore.Testing; +using Microsoft.AspNetCore.Testing.xunit; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Abstractions.Internal; @@ -331,7 +332,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } // Regression test for https://github.com/aspnet/KestrelHttpServer/pull/1197 - [Fact] + [ConditionalFact] + [OSSkipCondition(OperatingSystems.MacOSX, SkipReason = "macOS EPIPE vs. EPROTOTYPE bug https://github.com/aspnet/KestrelHttpServer/issues/2885")] public void ConnectionFilterDoesNotLeakBlock() { var loggerProvider = new HandshakeErrorLoggerProvider(); diff --git a/test/Kestrel.FunctionalTests/RequestTests.cs b/test/Kestrel.FunctionalTests/RequestTests.cs index d0fe276273..b528e80b3a 100644 --- a/test/Kestrel.FunctionalTests/RequestTests.cs +++ b/test/Kestrel.FunctionalTests/RequestTests.cs @@ -264,7 +264,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests Assert.True(dataRead); } - [Fact] + [ConditionalFact] + [OSSkipCondition(OperatingSystems.MacOSX, SkipReason = "macOS EPIPE vs. EPROTOTYPE bug https://github.com/aspnet/KestrelHttpServer/issues/2885")] public async Task ConnectionResetPriorToRequestIsLoggedAsDebug() { var connectionStarted = new SemaphoreSlim(0); @@ -325,7 +326,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests Assert.False(loggedHigherThanDebug); } - [Fact] + [ConditionalFact] + [OSSkipCondition(OperatingSystems.MacOSX, SkipReason = "macOS EPIPE vs. EPROTOTYPE bug https://github.com/aspnet/KestrelHttpServer/issues/2885")] public async Task ConnectionResetBetweenRequestsIsLoggedAsDebug() { var connectionReset = new SemaphoreSlim(0); @@ -394,7 +396,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests Assert.False(loggedHigherThanDebug); } - [Fact] + [ConditionalFact] + [OSSkipCondition(OperatingSystems.MacOSX, SkipReason = "macOS EPIPE vs. EPROTOTYPE bug https://github.com/aspnet/KestrelHttpServer/issues/2885")] public async Task ConnectionResetMidRequestIsLoggedAsDebug() { var requestStarted = new SemaphoreSlim(0); @@ -463,7 +466,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests Assert.False(loggedHigherThanDebug, "Logged event should not have been higher than debug."); } - [Fact] + [ConditionalFact] + [OSSkipCondition(OperatingSystems.MacOSX, SkipReason = "macOS EPIPE vs. EPROTOTYPE bug https://github.com/aspnet/KestrelHttpServer/issues/2885")] public async Task ThrowsOnReadAfterConnectionError() { var requestStarted = new SemaphoreSlim(0); @@ -1305,7 +1309,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests mockKestrelTrace.Verify(t => t.ConnectionStop(It.IsAny()), Times.AtMostOnce()); } - [Theory] + [ConditionalTheory] + [OSSkipCondition(OperatingSystems.MacOSX, SkipReason = "macOS EPIPE vs. EPROTOTYPE bug https://github.com/aspnet/KestrelHttpServer/issues/2885")] [MemberData(nameof(ConnectionAdapterData))] public async Task AppCanHandleClientAbortingConnectionMidRequest(ListenOptions listenOptions) { diff --git a/test/Kestrel.FunctionalTests/ResponseTests.cs b/test/Kestrel.FunctionalTests/ResponseTests.cs index 5763a54a5b..39b6725ee3 100644 --- a/test/Kestrel.FunctionalTests/ResponseTests.cs +++ b/test/Kestrel.FunctionalTests/ResponseTests.cs @@ -27,6 +27,7 @@ using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Https; using Microsoft.AspNetCore.Server.Kestrel.Https.Internal; using Microsoft.AspNetCore.Testing; +using Microsoft.AspNetCore.Testing.xunit; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Testing; @@ -2431,7 +2432,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests Assert.True(requestAborted); } - [Theory] + [ConditionalTheory] + [OSSkipCondition(OperatingSystems.MacOSX, SkipReason = "macOS EPIPE vs. EPROTOTYPE bug https://github.com/aspnet/KestrelHttpServer/issues/2885")] [MemberData(nameof(ConnectionAdapterData))] public async Task AppCanHandleClientAbortingConnectionMidResponse(ListenOptions listenOptions) { @@ -2504,7 +2506,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests Assert.Empty(transportLogs.Where(w => w.LogLevel > LogLevel.Debug)); } - [Theory] + [ConditionalTheory] + [OSSkipCondition(OperatingSystems.MacOSX, SkipReason = "macOS EPIPE vs. EPROTOTYPE bug https://github.com/aspnet/KestrelHttpServer/issues/2885")] [MemberData(nameof(ConnectionAdapterData))] public async Task ClientAbortingConnectionImmediatelyIsNotLoggedHigherThanDebug(ListenOptions listenOptions) { From 9d0c69f277ab8e46f4e216a0bdcbb4d2ceaa993a Mon Sep 17 00:00:00 2001 From: Nate McMaster Date: Wed, 14 Nov 2018 09:49:54 -0800 Subject: [PATCH 1662/1662] Reorganize source code in preparation to move into aspnet/AspNetCore Prior to reorganization, this source code was found in https://github.com/aspnet/CodeGenerator/tree/15ba5065a9b220f545eb3118d9e552f0b7e824d0 --- .appveyor.yml | 13 - .gitattributes | 52 --- .gitignore | 37 -- .travis.yml | 27 -- .vscode/extensions.json | 8 - .vscode/launch.json | 103 ----- .vscode/settings.json | 10 - .vscode/tasks.json | 117 ----- CONTRIBUTING.md | 4 - Directory.Build.props | 21 - Directory.Build.targets | 7 - KestrelHttpServer.sln | 412 ------------------ LICENSE.txt | 14 - NuGet.config | 7 - NuGetPackageVerifier.json | 13 - README.md | 42 -- ToProjectReferences.ps1 | 45 -- .../Kestrel.Performance.csproj | 29 -- build.cmd | 2 - build.sh | 8 - build/Key.snk | Bin 596 -> 0 bytes build/buildpipeline/linux.groovy | 10 - build/buildpipeline/osx.groovy | 10 - build/buildpipeline/pipeline.groovy | 18 - build/buildpipeline/windows.groovy | 12 - build/dependencies.props | 58 --- build/repo.props | 16 - build/repo.targets | 17 - build/sources.props | 18 - korebuild-lock.txt | 2 - korebuild.json | 4 - run.cmd | 2 - run.ps1 | 208 --------- run.sh | 245 ----------- .../Connections.Abstractions.csproj | 19 - src/Directory.Build.props | 13 - src/Kestrel.Core/Kestrel.Core.csproj | 43 -- .../Kestrel.Transport.Libuv.csproj | 25 -- src/Kestrel/Kestrel.csproj | 23 - .../src}/ConnectionBuilder.cs | 0 .../src}/ConnectionBuilderExtensions.cs | 0 .../src}/ConnectionContext.cs | 0 .../src}/ConnectionDelegate.cs | 0 .../src}/ConnectionHandler.cs | 0 .../src}/ConnectionItems.cs | 0 .../src}/DefaultConnectionContext.cs | 0 .../src}/Exceptions/AddressInUseException.cs | 0 .../Exceptions/ConnectionAbortedException.cs | 0 .../Exceptions/ConnectionResetException.cs | 0 .../Features/IConnectionHeartbeatFeature.cs | 0 .../src}/Features/IConnectionIdFeature.cs | 0 .../IConnectionInherentKeepAliveFeature.cs | 0 .../src}/Features/IConnectionItemsFeature.cs | 0 .../Features/IConnectionLifetimeFeature.cs | 0 .../Features/IConnectionTransportFeature.cs | 0 .../src}/Features/IConnectionUserFeature.cs | 0 .../src}/Features/IMemoryPoolFeature.cs | 0 .../src}/Features/ITransferFormatFeature.cs | 0 .../src}/IConnectionBuilder.cs | 0 ...AspNetCore.Connections.Abstractions.csproj | 17 + .../src}/TransferFormat.cs | 0 .../src}/baseline.netcore.json | 0 src/Servers/Directory.Build.props | 9 + .../src}/Adapter/Internal/AdaptedPipeline.cs | 0 .../Internal/ConnectionAdapterContext.cs | 0 .../Adapter/Internal/IAdaptedConnection.cs | 0 .../Adapter/Internal/IConnectionAdapter.cs | 0 .../Internal/LoggingConnectionAdapter.cs | 0 .../src}/Adapter/Internal/LoggingStream.cs | 0 .../Core/src}/Adapter/Internal/RawStream.cs | 0 ...istenOptionsConnectionLoggingExtensions.cs | 0 .../Kestrel/Core/src}/AnyIPListenOptions.cs | 0 .../Core/src}/BadHttpRequestException.cs | 0 .../Core/src}/ClientCertificateMode.cs | 0 .../Kestrel/Core/src}/CoreStrings.resx | 0 .../Core/src}/EndpointConfiguration.cs | 0 .../Features/IConnectionTimeoutFeature.cs | 0 ...crementConcurrentConnectionCountFeature.cs | 0 .../src}/Features/IHttp2StreamIdFeature.cs | 0 .../IHttpMinRequestBodyDataRateFeature.cs | 0 .../IHttpMinResponseDataRateFeature.cs | 0 .../ITlsApplicationProtocolFeature.cs | 0 .../Kestrel/Core/src}/HttpProtocols.cs | 0 .../src}/HttpsConnectionAdapterOptions.cs | 0 .../Core/src}/Internal/AddressBindContext.cs | 0 .../Core/src}/Internal/AddressBinder.cs | 0 .../Core/src}/Internal/BufferReader.cs | 0 .../Core/src}/Internal/BufferWriter.cs | 0 .../Core/src}/Internal/CertificateLoader.cs | 0 .../Core/src}/Internal/ClosedStream.cs | 0 .../Core/src}/Internal/ConfigurationReader.cs | 0 .../src}/Internal/ConnectionDispatcher.cs | 0 .../Internal/ConnectionLimitMiddleware.cs | 0 .../Core/src}/Internal/ConnectionLogScope.cs | 0 .../Kestrel/Core/src}/Internal/DuplexPipe.cs | 0 .../Core/src}/Internal/Http/ChunkWriter.cs | 0 .../src}/Internal/Http/ConnectionOptions.cs | 0 .../Internal/Http/DateHeaderValueManager.cs | 0 .../Http/Http1Connection.FeatureCollection.cs | 0 .../src}/Internal/Http/Http1Connection.cs | 0 .../Internal/Http/Http1ConnectionContext.cs | 0 .../src}/Internal/Http/Http1MessageBody.cs | 0 .../src}/Internal/Http/Http1OutputProducer.cs | 0 .../src}/Internal/Http/Http1ParsingHandler.cs | 0 .../Internal/Http/HttpHeaders.Generated.cs | 0 .../Core/src}/Internal/Http/HttpHeaders.cs | 0 .../Core/src}/Internal/Http/HttpMethod.cs | 0 .../Core/src}/Internal/Http/HttpParser.cs | 0 .../Http/HttpProtocol.FeatureCollection.cs | 0 .../Internal/Http/HttpProtocol.Generated.cs | 0 .../Core/src}/Internal/Http/HttpProtocol.cs | 0 .../src}/Internal/Http/HttpRequestHeaders.cs | 0 .../src}/Internal/Http/HttpRequestStream.cs | 0 .../Internal/Http/HttpRequestTargetForm.cs | 0 .../src}/Internal/Http/HttpResponseHeaders.cs | 0 .../src}/Internal/Http/HttpResponseStream.cs | 0 .../Core/src}/Internal/Http/HttpScheme.cs | 0 .../src}/Internal/Http/HttpStreamState.cs | 0 .../src}/Internal/Http/HttpUpgradeStream.cs | 0 .../Core/src}/Internal/Http/HttpVersion.cs | 0 .../src}/Internal/Http/IHttpHeadersHandler.cs | 0 .../src}/Internal/Http/IHttpOutputProducer.cs | 0 .../Core/src}/Internal/Http/IHttpParser.cs | 0 .../Internal/Http/IHttpProtocolContext.cs | 0 .../Internal/Http/IHttpRequestLineHandler.cs | 0 .../Internal/Http/IHttpResponseControl.cs | 0 .../Core/src}/Internal/Http/MessageBody.cs | 0 .../Core/src}/Internal/Http/PathNormalizer.cs | 0 .../src}/Internal/Http/PipelineExtensions.cs | 0 .../Core/src}/Internal/Http/ProduceEndType.cs | 0 .../Core/src}/Internal/Http/ReasonPhrases.cs | 0 .../Internal/Http/RequestProcessingStatus.cs | 0 .../Internal/Http/RequestRejectionReason.cs | 0 .../Core/src}/Internal/Http/TransferCoding.cs | 0 .../Core/src}/Internal/Http/UrlDecoder.cs | 0 .../src}/Internal/Http2/HPack/DynamicTable.cs | 0 .../src}/Internal/Http2/HPack/HPackDecoder.cs | 0 .../Http2/HPack/HPackDecodingException.cs | 0 .../src}/Internal/Http2/HPack/HPackEncoder.cs | 0 .../src}/Internal/Http2/HPack/HeaderField.cs | 0 .../Core/src}/Internal/Http2/HPack/Huffman.cs | 0 .../Http2/HPack/HuffmanDecodingException.cs | 0 .../Internal/Http2/HPack/IntegerDecoder.cs | 0 .../Internal/Http2/HPack/IntegerEncoder.cs | 0 .../src}/Internal/Http2/HPack/StaticTable.cs | 0 .../src}/Internal/Http2/HPack/StatusCodes.cs | 0 .../src}/Internal/Http2/Http2Connection.cs | 0 .../Internal/Http2/Http2ConnectionContext.cs | 0 .../Http2/Http2ConnectionErrorException.cs | 0 .../Http2/Http2ContinuationFrameFlags.cs | 0 .../Internal/Http2/Http2DataFrameFlags.cs | 0 .../src}/Internal/Http2/Http2ErrorCode.cs | 0 .../Internal/Http2/Http2Frame.Continuation.cs | 0 .../src}/Internal/Http2/Http2Frame.Data.cs | 0 .../src}/Internal/Http2/Http2Frame.GoAway.cs | 0 .../src}/Internal/Http2/Http2Frame.Headers.cs | 0 .../src}/Internal/Http2/Http2Frame.Ping.cs | 0 .../Internal/Http2/Http2Frame.Priority.cs | 0 .../Internal/Http2/Http2Frame.RstStream.cs | 0 .../Internal/Http2/Http2Frame.Settings.cs | 0 .../Internal/Http2/Http2Frame.WindowUpdate.cs | 0 .../Core/src}/Internal/Http2/Http2Frame.cs | 0 .../src}/Internal/Http2/Http2FrameReader.cs | 0 .../src}/Internal/Http2/Http2FrameType.cs | 0 .../src}/Internal/Http2/Http2FrameWriter.cs | 0 .../Internal/Http2/Http2HeadersFrameFlags.cs | 0 .../src}/Internal/Http2/Http2MessageBody.cs | 0 .../Internal/Http2/Http2OutputProducer.cs | 0 .../src}/Internal/Http2/Http2PeerSetting.cs | 0 .../src}/Internal/Http2/Http2PeerSettings.cs | 0 .../Internal/Http2/Http2PingFrameFlags.cs | 0 .../Internal/Http2/Http2SettingsFrameFlags.cs | 0 .../Internal/Http2/Http2SettingsParameter.cs | 0 ...tp2SettingsParameterOutOfRangeException.cs | 0 .../Http2/Http2Stream.FeatureCollection.cs | 0 .../Core/src}/Internal/Http2/Http2Stream.cs | 0 .../src}/Internal/Http2/Http2StreamContext.cs | 0 .../Http2/Http2StreamErrorException.cs | 0 .../src}/Internal/Http2/IHttp2FrameWriter.cs | 0 .../Http2/IHttp2StreamLifetimeHandler.cs | 0 .../Core/src}/Internal/HttpConnection.cs | 0 .../HttpConnectionBuilderExtensions.cs | 0 .../src}/Internal/HttpConnectionContext.cs | 0 .../src}/Internal/HttpConnectionMiddleware.cs | 0 .../src}/Internal/HttpsConnectionAdapter.cs | 0 .../Core/src}/Internal/IRequestProcessor.cs | 0 .../CancellationTokenExtensions.cs | 0 .../src}/Internal/Infrastructure/Constants.cs | 0 .../Infrastructure/CorrelationIdGenerator.cs | 0 .../Infrastructure/DebuggerWrapper.cs | 0 .../Internal/Infrastructure/Disposable.cs | 0 .../Infrastructure/DisposableAction.cs | 0 .../src}/Internal/Infrastructure/Heartbeat.cs | 0 .../Infrastructure/HttpConnectionManager.cs | 0 ...HttpConnectionManagerShutdownExtensions.cs | 0 .../Infrastructure/HttpConnectionReference.cs | 0 .../Infrastructure/HttpHeartbeatManager.cs | 0 .../Infrastructure/HttpUtilities.Generated.cs | 0 .../Internal/Infrastructure/HttpUtilities.cs | 0 .../src}/Internal/Infrastructure/IDebugger.cs | 0 .../Infrastructure/IHeartbeatHandler.cs | 0 .../Internal/Infrastructure/IKestrelTrace.cs | 0 .../Internal/Infrastructure/ISystemClock.cs | 0 .../Infrastructure/ITimeoutControl.cs | 0 .../Infrastructure/KestrelEventSource.cs | 0 .../Internal/Infrastructure/KestrelTrace.cs | 0 .../Internal/Infrastructure/ReadOnlyStream.cs | 0 .../Infrastructure/ResourceCounter.cs | 0 .../StackTraceHiddenAttribute.cs | 0 .../src}/Internal/Infrastructure/Streams.cs | 0 .../Infrastructure/StringUtilities.cs | 0 .../Internal/Infrastructure/SystemClock.cs | 0 .../Infrastructure/ThrowingWriteOnlyStream.cs | 0 .../Internal/Infrastructure/TimeoutAction.cs | 0 .../Internal/Infrastructure/UriUtilities.cs | 0 .../Internal/Infrastructure/WrappingStream.cs | 0 .../Infrastructure/WriteOnlyStream.cs | 0 .../Internal/KestrelServerOptionsSetup.cs | 0 .../Core/src}/Internal/LoggerExtensions.cs | 0 .../src}/Internal/ServerAddressesFeature.cs | 0 .../Core/src}/Internal/ServiceContext.cs | 0 .../src}/Internal/TlsConnectionFeature.cs | 0 .../Core/src}/KestrelConfigurationLoader.cs | 0 .../Kestrel/Core/src}/KestrelServer.cs | 0 .../Kestrel/Core/src}/KestrelServerLimits.cs | 0 .../Kestrel/Core/src}/KestrelServerOptions.cs | 0 .../Kestrel/Core/src}/ListenOptions.cs | 0 .../Core/src}/ListenOptionsHttpsExtensions.cs | 0 .../Core/src}/LocalhostListenOptions.cs | 0 ...soft.AspNetCore.Server.Kestrel.Core.csproj | 38 ++ .../Kestrel/Core/src}/MinDataRate.cs | 0 .../Core/src}/Properties/AssemblyInfo.cs | 2 +- .../src}/Properties/CoreStrings.Designer.cs | 0 .../Kestrel/Core/src}/ServerAddress.cs | 0 .../KestrelServerOptionsSystemdExtensions.cs | 0 .../Kestrel/Core/src}/baseline.netcore.json | 0 .../Kestrel/Core/test}/AddressBinderTests.cs | 0 .../Kestrel/Core/test}/AsciiDecoding.cs | 0 .../Kestrel/Core/test}/BufferReaderTests.cs | 0 .../Kestrel/Core/test}/BufferWriterTests.cs | 0 .../Kestrel/Core/test}/ChunkWriterTests.cs | 0 .../Core/test}/ConnectionDispatcherTests.cs | 0 .../Core/test}/DateHeaderValueManagerTests.cs | 0 .../Kestrel/Core/test}/DynamicTableTests.cs | 0 .../Kestrel/Core/test}/HPackDecoderTests.cs | 0 .../Kestrel/Core/test}/HPackEncoderTests.cs | 0 .../Kestrel/Core/test}/HeartbeatTests.cs | 0 .../Core/test}/Http1ConnectionTests.cs | 0 .../Core/test}/Http2ConnectionTests.cs | 0 .../Core/test}/HttpConnectionManagerTests.cs | 0 .../Kestrel/Core/test}/HttpConnectionTests.cs | 0 .../Kestrel/Core/test}/HttpHeadersTests.cs | 0 .../Kestrel/Core/test}/HttpParserTests.cs | 0 .../HttpProtocolFeatureCollectionTests.cs | 0 .../Core/test}/HttpRequestHeadersTests.cs | 0 .../Core/test}/HttpRequestStreamTests.cs | 0 .../Core/test}/HttpResponseHeadersTests.cs | 0 .../Core/test}/HttpResponseStreamTests.cs | 0 .../Kestrel/Core/test}/HttpUtilitiesTest.cs | 0 .../Kestrel/Core/test}/HuffmanTests.cs | 0 .../Kestrel/Core/test}/IntegerDecoderTests.cs | 0 .../Kestrel/Core/test}/IntegerEncoderTests.cs | 0 .../Core/test}/KestrelEventSourceTests.cs | 0 .../Core/test}/KestrelServerLimitsTests.cs | 0 .../Core/test}/KestrelServerOptionsTests.cs | 0 .../Kestrel/Core/test}/KestrelServerTests.cs | 0 .../Kestrel/Core/test}/KnownStringsTests.cs | 0 .../Kestrel/Core/test}/ListenOptionsTests.cs | 0 .../Kestrel/Core/test}/MessageBodyTests.cs | 0 ...spNetCore.Server.Kestrel.Core.Tests.csproj | 23 + .../Kestrel/Core/test}/MinDataRateTests.cs | 0 .../Kestrel/Core/test}/OutputProducerTests.cs | 0 .../Kestrel/Core/test}/PathNormalizerTests.cs | 0 .../Kestrel/Core/test}/PipeOptionsTests.cs | 0 .../Core/test}/PipelineExtensionTests.cs | 0 .../Kestrel/Core/test}/ReasonPhrasesTests.cs | 0 .../Core/test}/ResourceCounterTests.cs | 0 .../Kestrel/Core/test}/ServerAddressTests.cs | 0 .../Kestrel/Core/test}/StreamsTests.cs | 0 .../Core/test}/StringUtilitiesTests.cs | 0 .../test}/TestHelpers/AssertExtensions.cs | 0 .../TestHelpers/MockHttpResponseControl.cs | 0 .../Servers/Kestrel/Core/test}/TestInput.cs | 0 .../test}/ThrowingWriteOnlyStreamTests.cs | 0 src/Servers/Kestrel/Directory.Build.props | 25 ++ ...ft.AspNetCore.Server.Kestrel.Https.csproj} | 9 +- .../Https/src}/Properties/AssemblyInfo.cs | 0 .../Kestrel/Https/src}/baseline.netcore.json | 0 ...Microsoft.AspNetCore.Server.Kestrel.csproj | 18 + .../src}/WebHostBuilderKestrelExtensions.cs | 0 .../Kestrel/src}/baseline.netcore.json | 0 .../Kestrel/test}/ConfigurationReaderTests.cs | 0 .../test}/KestrelConfigurationBuilderTests.cs | 0 ...oft.AspNetCore.Server.Kestrel.Tests.csproj | 17 + .../WebHostBuilderKestrelExtensionsTests.cs | 0 src/Servers/Kestrel/README.md | 8 + .../src}/Internal/FileHandleType.cs | 0 .../Internal/IApplicationTransportFeature.cs | 0 .../src}/Internal/IBytesWrittenFeature.cs | 0 .../src}/Internal/IConnectionDispatcher.cs | 0 .../src}/Internal/IEndPointInformation.cs | 0 .../src}/Internal/ITransport.cs | 0 .../src}/Internal/ITransportFactory.cs | 0 .../Internal/ITransportSchedulerFeature.cs | 0 .../src}/Internal/KestrelMemoryPool.cs | 0 .../src}/Internal/ListenType.cs | 0 .../src}/Internal/MemoryPoolBlock.Debug.cs | 0 .../src}/Internal/MemoryPoolBlock.Release.cs | 0 .../src}/Internal/MemoryPoolSlab.cs | 0 .../src}/Internal/SchedulingMode.cs | 0 .../src}/Internal/SlabMemoryPool.cs | 0 .../Internal/TransportConnection.Features.cs | 0 .../src}/Internal/TransportConnection.cs | 0 ...ver.Kestrel.Transport.Abstractions.csproj} | 6 +- .../src}/baseline.netcore.json | 0 .../src}/Internal/IAsyncDisposable.cs | 0 .../src}/Internal/ILibuvTrace.cs | 0 .../src}/Internal/LibuvAwaitable.cs | 0 .../src}/Internal/LibuvConnection.cs | 0 .../src}/Internal/LibuvConstants.cs | 0 .../src}/Internal/LibuvOutputConsumer.cs | 0 .../src}/Internal/LibuvThread.cs | 0 .../src}/Internal/LibuvTrace.cs | 0 .../src}/Internal/LibuvTransport.cs | 0 .../src}/Internal/LibuvTransportContext.cs | 0 .../src}/Internal/LibuvTransportFactory.cs | 0 .../Transport.Libuv/src}/Internal/Listener.cs | 0 .../src}/Internal/ListenerContext.cs | 0 .../src}/Internal/ListenerPrimary.cs | 0 .../src}/Internal/ListenerSecondary.cs | 0 .../Internal/Networking/LibuvFunctions.cs | 0 .../src}/Internal/Networking/PlatformApis.cs | 0 .../src}/Internal/Networking/SockAddr.cs | 0 .../src}/Internal/Networking/UvAsyncHandle.cs | 0 .../Internal/Networking/UvConnectRequest.cs | 0 .../src}/Internal/Networking/UvException.cs | 0 .../src}/Internal/Networking/UvHandle.cs | 0 .../src}/Internal/Networking/UvLoopHandle.cs | 0 .../src}/Internal/Networking/UvMemory.cs | 0 .../src}/Internal/Networking/UvPipeHandle.cs | 0 .../src}/Internal/Networking/UvRequest.cs | 0 .../Internal/Networking/UvStreamHandle.cs | 0 .../src}/Internal/Networking/UvTcpHandle.cs | 0 .../src}/Internal/Networking/UvTimerHandle.cs | 0 .../src}/Internal/Networking/UvWriteReq.cs | 0 .../src}/Internal/WriteReqPool.cs | 0 .../src}/LibuvTransportOptions.cs | 0 ...Core.Server.Kestrel.Transport.Libuv.csproj | 20 + .../src}/WebHostBuilderLibuvExtensions.cs | 0 .../src}/baseline.netcore.json | 0 .../src}/breakingchanges.netcore.json | 0 .../test}/LibuvConnectionTests.cs | 0 .../test}/LibuvOutputConsumerTests.cs | 0 .../Transport.Libuv/test}/LibuvThreadTests.cs | 0 .../test}/LibuvTransportFactoryTests.cs | 0 .../test}/LibuvTransportOptionsTests.cs | 0 .../test}/LibuvTransportTests.cs | 0 .../test}/ListenerPrimaryTests.cs | 0 ...erver.Kestrel.Transport.Libuv.Tests.csproj | 20 + .../test}/MultipleLoopTests.cs | 0 .../Transport.Libuv/test}/NetworkingTests.cs | 0 .../TestHelpers/MockConnectionDispatcher.cs | 0 .../test}/TestHelpers/MockLibuv.cs | 0 .../test}/TestHelpers/MockSocket.cs | 0 .../TestHelpers/TestLibuvTransportContext.cs | 0 .../test}/UvStreamHandleTests.cs | 0 .../test}/UvTimerHandleTests.cs | 0 .../src}/Internal/BufferExtensions.cs | 0 .../src}/Internal/IOQueue.cs | 0 .../src}/Internal/ISocketsTrace.cs | 0 .../src}/Internal/SocketAwaitable.cs | 0 .../src}/Internal/SocketConnection.cs | 0 .../src}/Internal/SocketReceiver.cs | 0 .../src}/Internal/SocketSender.cs | 0 .../src}/Internal/SocketsTrace.cs | 0 ...e.Server.Kestrel.Transport.Sockets.csproj} | 11 +- .../Properties/SocketsStrings.Designer.cs | 0 .../Transport.Sockets/src}/SocketTransport.cs | 0 .../src}/SocketTransportFactory.cs | 0 .../src}/SocketTransportOptions.cs | 0 .../src}/SocketsStrings.resx | 0 .../src}/WebHostBuilderSocketExtensions.cs | 0 .../src}/baseline.netcore.json | 0 .../AsciiBytesToStringBenchmark.cs | 0 .../perf}/Kestrel.Performance/AssemblyInfo.cs | 0 .../DotSegmentRemovalBenchmark.cs | 0 .../Kestrel.Performance/ErrorUtilities.cs | 0 .../Http1ConnectionBenchmark.cs | 0 ...Http1ConnectionParsingOverheadBenchmark.cs | 0 .../Http1WritingBenchmark.cs | 0 .../HttpParserBenchmark.cs | 0 .../HttpProtocolFeatureCollection.cs | 0 .../InMemoryTransportBenchmark.cs | 0 .../KnownStringsBenchmark.cs | 0 ...pNetCore.Server.Kestrel.Performance.csproj | 27 ++ .../Mocks/MockTimeoutControl.cs | 0 .../Kestrel.Performance/Mocks/MockTrace.cs | 0 .../Kestrel.Performance/Mocks/NullParser.cs | 0 .../PipeThroughputBenchmark.cs | 0 .../perf}/Kestrel.Performance/README.md | 0 .../RequestParsingBenchmark.cs | 0 .../Kestrel.Performance/RequestParsingData.cs | 0 .../ResponseHeaderCollectionBenchmark.cs | 0 .../ResponseHeadersWritingBenchmark.cs | 0 .../StringUtilitiesBenchmark.cs | 0 .../perf}/PlatformBenchmarks/AsciiString.cs | 0 .../BenchmarkApplication.cs | 0 .../BenchmarkConfigurationHelpers.cs | 0 .../perf}/PlatformBenchmarks/DateHeader.cs | 0 .../PlatformBenchmarks/HttpApplication.cs | 0 .../PlatformBenchmarks.csproj | 16 +- .../perf}/PlatformBenchmarks/Program.cs | 0 .../perf}/PlatformBenchmarks/Startup.cs | 0 .../PlatformBenchmarks/benchmarks.json.json | 0 .../benchmarks.plaintext.json | 0 .../samples}/Http2SampleApp/Dockerfile | 0 .../Http2SampleApp/Http2SampleApp.csproj | 9 +- .../samples}/Http2SampleApp/Program.cs | 0 .../samples}/Http2SampleApp/Startup.cs | 0 .../Http2SampleApp/scripts/build-docker.ps1 | 0 .../Http2SampleApp/scripts/build-docker.sh | 0 .../Http2SampleApp/scripts/run-docker.ps1 | 0 .../Http2SampleApp/scripts/run-docker.sh | 0 .../samples}/Http2SampleApp/testCert.pfx | Bin .../LargeResponseApp/LargeResponseApp.csproj | 2 +- .../samples}/LargeResponseApp/Startup.cs | 0 .../samples}/PlaintextApp/PlaintextApp.csproj | 2 +- .../Kestrel/samples}/PlaintextApp/Startup.cs | 0 .../samples}/SampleApp/SampleApp.csproj | 13 +- .../Kestrel/samples}/SampleApp/Startup.cs | 0 .../SampleApp/appsettings.Development.json | 0 .../SampleApp/appsettings.Production.json | 0 .../samples}/SampleApp/appsettings.json | 0 .../Kestrel/samples}/SampleApp/testCert.pfx | Bin .../samples}/SystemdTestApp/Startup.cs | 0 .../SystemdTestApp/SystemdTestApp.csproj | 9 +- .../samples}/SystemdTestApp/testCert.pfx | Bin .../Kestrel/shared/src}/ThrowHelper.cs | 0 .../Kestrel/shared/test}/DisposableStack.cs | 0 .../Kestrel/shared/test}/DummyApplication.cs | 0 .../test}/EventRaisingResourceCounter.cs | 0 .../Kestrel/shared/test}/HttpParsingData.cs | 0 .../shared/test}/KestrelTestLoggerProvider.cs | 0 .../shared/test}/LifetimeNotImplemented.cs | 0 .../Kestrel/shared/test}/MockLogger.cs | 0 .../Kestrel/shared/test}/MockSystemClock.cs | 0 .../test}/PassThroughConnectionAdapter.cs | 0 .../Kestrel/shared/test}/StringExtensions.cs | 0 .../shared/test}/TaskTimeoutExtensions.cs | 0 .../Servers/Kestrel/shared/test}/TestApp.cs | 0 .../test}/TestApplicationErrorLogger.cs | 0 .../test}/TestCertificates/aspnetdevcert.pfx | Bin .../test}/TestCertificates/eku.client.ini | 0 .../test}/TestCertificates/eku.client.pfx | Bin .../TestCertificates/eku.code_signing.ini | 0 .../TestCertificates/eku.code_signing.pfx | Bin .../TestCertificates/eku.multiple_usages.ini | 0 .../TestCertificates/eku.multiple_usages.pfx | Bin .../test}/TestCertificates/eku.server.ini | 0 .../test}/TestCertificates/eku.server.pfx | Bin .../test}/TestCertificates/make-test-certs.sh | 0 .../test}/TestCertificates/no_extensions.ini | 0 .../test}/TestCertificates/no_extensions.pfx | Bin .../test}/TestCertificates/testCert.pfx | Bin .../Kestrel/shared/test}/TestConnection.cs | 0 .../Kestrel/shared/test}/TestConstants.cs | 0 .../shared/test}/TestHttp1Connection.cs | 0 .../Kestrel/shared/test}/TestKestrelTrace.cs | 0 .../Kestrel/shared/test}/TestResources.cs | 0 .../shared/test}/TestServiceContext.cs | 0 .../AddressRegistrationTests.cs | 0 .../FunctionalTests}/BadHttpRequestTests.cs | 0 .../CertificateLoaderTests.cs | 0 .../FunctionalTests}/ChunkedRequestTests.cs | 0 .../FunctionalTests}/ChunkedResponseTests.cs | 0 .../ConnectionAdapterTests.cs | 0 .../FunctionalTests}/ConnectionLimitTests.cs | 0 .../FunctionalTests}/DefaultHeaderTests.cs | 0 .../test/FunctionalTests}/EventSourceTests.cs | 0 .../FunctionalTests}/GeneratedCodeTests.cs | 9 +- .../HttpConnectionManagerTests.cs | 0 .../HttpProtocolSelectionTests.cs | 0 .../HttpsConnectionAdapterOptionsTest.cs | 0 .../HttpsConnectionAdapterTests.cs | 0 .../test/FunctionalTests}/HttpsTests.cs | 0 .../FunctionalTests}/KeepAliveTimeoutTests.cs | 0 .../LoggingConnectionAdapterTests.cs | 0 .../MaxRequestBodySizeTests.cs | 0 .../MaxRequestBufferSizeTests.cs | 0 .../MaxRequestLineSizeTests.cs | 0 .../Properties/AssemblyInfo.cs | 0 .../RequestBodyTimeoutTests.cs | 0 .../RequestHeaderLimitsTests.cs | 0 .../RequestHeadersTimeoutTests.cs | 0 .../RequestTargetProcessingTests.cs | 0 .../test/FunctionalTests}/RequestTests.cs | 0 .../test/FunctionalTests}/ResponseTests.cs | 0 .../HostNameIsReachableAttribute.cs | 0 .../IPv6ScopeIdPresentConditionAttribute.cs | 0 .../IPv6SupportedConditionAttribute.cs | 0 .../TestHelpers/IWebHostPortExtensions.cs | 0 .../TestApplicationErrorLoggerLoggedTest.cs | 0 .../TestHelpers/TestServer.cs | 0 .../test/FunctionalTests}/UpgradeTests.cs | 0 .../Libuv.FunctionalTests.csproj | 30 ++ .../ListenHandleTests.cs | 0 .../TransportSelector.cs | 0 .../Sockets.FunctionalTests.csproj | 29 ++ .../TransportSelector.cs | 0 .../test}/SystemdActivation/Dockerfile | 0 .../SystemdActivation/docker-entrypoint.sh | 0 .../Kestrel/test}/SystemdActivation/docker.sh | 0 .../tools}/CodeGenerator/CodeGenerator.csproj | 7 +- .../HttpProtocolFeatureCollection.cs | 0 .../CombinationsWithoutRepetition.cs | 0 .../HttpUtilities/HttpUtilities.cs | 0 .../HttpUtilitiesGeneratorHelpers.cs | 0 .../tools}/CodeGenerator/KnownHeaders.cs | 0 .../Kestrel/tools}/CodeGenerator/Program.cs | 0 .../Servers/Kestrel}/xunit.runner.json | 0 .../Shared/Buffers.Testing}/BufferSegment.cs | 0 .../Buffers.Testing}/CustomMemoryForTest.cs | 0 .../ReadOnlySequenceFactory.cs | 0 test/Directory.Build.props | 31 -- .../Kestrel.Core.Tests.csproj | 29 -- test/Kestrel.Tests/Kestrel.Tests.csproj | 20 - ...rel.Transport.Libuv.FunctionalTests.csproj | 36 -- .../Kestrel.Transport.Libuv.Tests.csproj | 26 -- ...l.Transport.Sockets.FunctionalTests.csproj | 35 -- version.props | 12 - 530 files changed, 320 insertions(+), 1959 deletions(-) delete mode 100644 .appveyor.yml delete mode 100644 .gitattributes delete mode 100644 .gitignore delete mode 100644 .travis.yml delete mode 100644 .vscode/extensions.json delete mode 100644 .vscode/launch.json delete mode 100644 .vscode/settings.json delete mode 100644 .vscode/tasks.json delete mode 100644 CONTRIBUTING.md delete mode 100644 Directory.Build.props delete mode 100644 Directory.Build.targets delete mode 100644 KestrelHttpServer.sln delete mode 100644 LICENSE.txt delete mode 100644 NuGet.config delete mode 100644 NuGetPackageVerifier.json delete mode 100644 README.md delete mode 100644 ToProjectReferences.ps1 delete mode 100644 benchmarks/Kestrel.Performance/Kestrel.Performance.csproj delete mode 100644 build.cmd delete mode 100755 build.sh delete mode 100644 build/Key.snk delete mode 100644 build/buildpipeline/linux.groovy delete mode 100644 build/buildpipeline/osx.groovy delete mode 100644 build/buildpipeline/pipeline.groovy delete mode 100644 build/buildpipeline/windows.groovy delete mode 100644 build/dependencies.props delete mode 100644 build/repo.props delete mode 100644 build/repo.targets delete mode 100644 build/sources.props delete mode 100644 korebuild-lock.txt delete mode 100644 korebuild.json delete mode 100644 run.cmd delete mode 100644 run.ps1 delete mode 100755 run.sh delete mode 100644 src/Connections.Abstractions/Connections.Abstractions.csproj delete mode 100644 src/Directory.Build.props delete mode 100644 src/Kestrel.Core/Kestrel.Core.csproj delete mode 100644 src/Kestrel.Transport.Libuv/Kestrel.Transport.Libuv.csproj delete mode 100644 src/Kestrel/Kestrel.csproj rename src/{Connections.Abstractions => Servers/Connections.Abstractions/src}/ConnectionBuilder.cs (100%) rename src/{Connections.Abstractions => Servers/Connections.Abstractions/src}/ConnectionBuilderExtensions.cs (100%) rename src/{Connections.Abstractions => Servers/Connections.Abstractions/src}/ConnectionContext.cs (100%) rename src/{Connections.Abstractions => Servers/Connections.Abstractions/src}/ConnectionDelegate.cs (100%) rename src/{Connections.Abstractions => Servers/Connections.Abstractions/src}/ConnectionHandler.cs (100%) rename src/{Connections.Abstractions => Servers/Connections.Abstractions/src}/ConnectionItems.cs (100%) rename src/{Connections.Abstractions => Servers/Connections.Abstractions/src}/DefaultConnectionContext.cs (100%) rename src/{Connections.Abstractions => Servers/Connections.Abstractions/src}/Exceptions/AddressInUseException.cs (100%) rename src/{Connections.Abstractions => Servers/Connections.Abstractions/src}/Exceptions/ConnectionAbortedException.cs (100%) rename src/{Connections.Abstractions => Servers/Connections.Abstractions/src}/Exceptions/ConnectionResetException.cs (100%) rename src/{Connections.Abstractions => Servers/Connections.Abstractions/src}/Features/IConnectionHeartbeatFeature.cs (100%) rename src/{Connections.Abstractions => Servers/Connections.Abstractions/src}/Features/IConnectionIdFeature.cs (100%) rename src/{Connections.Abstractions => Servers/Connections.Abstractions/src}/Features/IConnectionInherentKeepAliveFeature.cs (100%) rename src/{Connections.Abstractions => Servers/Connections.Abstractions/src}/Features/IConnectionItemsFeature.cs (100%) rename src/{Connections.Abstractions => Servers/Connections.Abstractions/src}/Features/IConnectionLifetimeFeature.cs (100%) rename src/{Connections.Abstractions => Servers/Connections.Abstractions/src}/Features/IConnectionTransportFeature.cs (100%) rename src/{Connections.Abstractions => Servers/Connections.Abstractions/src}/Features/IConnectionUserFeature.cs (100%) rename src/{Connections.Abstractions => Servers/Connections.Abstractions/src}/Features/IMemoryPoolFeature.cs (100%) rename src/{Connections.Abstractions => Servers/Connections.Abstractions/src}/Features/ITransferFormatFeature.cs (100%) rename src/{Connections.Abstractions => Servers/Connections.Abstractions/src}/IConnectionBuilder.cs (100%) create mode 100644 src/Servers/Connections.Abstractions/src/Microsoft.AspNetCore.Connections.Abstractions.csproj rename src/{Connections.Abstractions => Servers/Connections.Abstractions/src}/TransferFormat.cs (100%) rename src/{Connections.Abstractions => Servers/Connections.Abstractions/src}/baseline.netcore.json (100%) create mode 100644 src/Servers/Directory.Build.props rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/Adapter/Internal/AdaptedPipeline.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/Adapter/Internal/ConnectionAdapterContext.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/Adapter/Internal/IAdaptedConnection.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/Adapter/Internal/IConnectionAdapter.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/Adapter/Internal/LoggingConnectionAdapter.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/Adapter/Internal/LoggingStream.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/Adapter/Internal/RawStream.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/Adapter/ListenOptionsConnectionLoggingExtensions.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/AnyIPListenOptions.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/BadHttpRequestException.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/ClientCertificateMode.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/CoreStrings.resx (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/EndpointConfiguration.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/Features/IConnectionTimeoutFeature.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/Features/IDecrementConcurrentConnectionCountFeature.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/Features/IHttp2StreamIdFeature.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/Features/IHttpMinRequestBodyDataRateFeature.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/Features/IHttpMinResponseDataRateFeature.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/Features/ITlsApplicationProtocolFeature.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/HttpProtocols.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/HttpsConnectionAdapterOptions.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/Internal/AddressBindContext.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/Internal/AddressBinder.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/Internal/BufferReader.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/Internal/BufferWriter.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/Internal/CertificateLoader.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/Internal/ClosedStream.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/Internal/ConfigurationReader.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/Internal/ConnectionDispatcher.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/Internal/ConnectionLimitMiddleware.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/Internal/ConnectionLogScope.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/Internal/DuplexPipe.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/Internal/Http/ChunkWriter.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/Internal/Http/ConnectionOptions.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/Internal/Http/DateHeaderValueManager.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/Internal/Http/Http1Connection.FeatureCollection.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/Internal/Http/Http1Connection.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/Internal/Http/Http1ConnectionContext.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/Internal/Http/Http1MessageBody.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/Internal/Http/Http1OutputProducer.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/Internal/Http/Http1ParsingHandler.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/Internal/Http/HttpHeaders.Generated.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/Internal/Http/HttpHeaders.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/Internal/Http/HttpMethod.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/Internal/Http/HttpParser.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/Internal/Http/HttpProtocol.FeatureCollection.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/Internal/Http/HttpProtocol.Generated.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/Internal/Http/HttpProtocol.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/Internal/Http/HttpRequestHeaders.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/Internal/Http/HttpRequestStream.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/Internal/Http/HttpRequestTargetForm.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/Internal/Http/HttpResponseHeaders.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/Internal/Http/HttpResponseStream.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/Internal/Http/HttpScheme.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/Internal/Http/HttpStreamState.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/Internal/Http/HttpUpgradeStream.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/Internal/Http/HttpVersion.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/Internal/Http/IHttpHeadersHandler.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/Internal/Http/IHttpOutputProducer.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/Internal/Http/IHttpParser.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/Internal/Http/IHttpProtocolContext.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/Internal/Http/IHttpRequestLineHandler.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/Internal/Http/IHttpResponseControl.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/Internal/Http/MessageBody.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/Internal/Http/PathNormalizer.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/Internal/Http/PipelineExtensions.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/Internal/Http/ProduceEndType.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/Internal/Http/ReasonPhrases.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/Internal/Http/RequestProcessingStatus.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/Internal/Http/RequestRejectionReason.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/Internal/Http/TransferCoding.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/Internal/Http/UrlDecoder.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/Internal/Http2/HPack/DynamicTable.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/Internal/Http2/HPack/HPackDecoder.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/Internal/Http2/HPack/HPackDecodingException.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/Internal/Http2/HPack/HPackEncoder.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/Internal/Http2/HPack/HeaderField.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/Internal/Http2/HPack/Huffman.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/Internal/Http2/HPack/HuffmanDecodingException.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/Internal/Http2/HPack/IntegerDecoder.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/Internal/Http2/HPack/IntegerEncoder.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/Internal/Http2/HPack/StaticTable.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/Internal/Http2/HPack/StatusCodes.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/Internal/Http2/Http2Connection.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/Internal/Http2/Http2ConnectionContext.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/Internal/Http2/Http2ConnectionErrorException.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/Internal/Http2/Http2ContinuationFrameFlags.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/Internal/Http2/Http2DataFrameFlags.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/Internal/Http2/Http2ErrorCode.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/Internal/Http2/Http2Frame.Continuation.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/Internal/Http2/Http2Frame.Data.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/Internal/Http2/Http2Frame.GoAway.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/Internal/Http2/Http2Frame.Headers.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/Internal/Http2/Http2Frame.Ping.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/Internal/Http2/Http2Frame.Priority.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/Internal/Http2/Http2Frame.RstStream.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/Internal/Http2/Http2Frame.Settings.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/Internal/Http2/Http2Frame.WindowUpdate.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/Internal/Http2/Http2Frame.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/Internal/Http2/Http2FrameReader.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/Internal/Http2/Http2FrameType.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/Internal/Http2/Http2FrameWriter.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/Internal/Http2/Http2HeadersFrameFlags.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/Internal/Http2/Http2MessageBody.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/Internal/Http2/Http2OutputProducer.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/Internal/Http2/Http2PeerSetting.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/Internal/Http2/Http2PeerSettings.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/Internal/Http2/Http2PingFrameFlags.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/Internal/Http2/Http2SettingsFrameFlags.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/Internal/Http2/Http2SettingsParameter.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/Internal/Http2/Http2SettingsParameterOutOfRangeException.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/Internal/Http2/Http2Stream.FeatureCollection.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/Internal/Http2/Http2Stream.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/Internal/Http2/Http2StreamContext.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/Internal/Http2/Http2StreamErrorException.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/Internal/Http2/IHttp2FrameWriter.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/Internal/Http2/IHttp2StreamLifetimeHandler.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/Internal/HttpConnection.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/Internal/HttpConnectionBuilderExtensions.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/Internal/HttpConnectionContext.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/Internal/HttpConnectionMiddleware.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/Internal/HttpsConnectionAdapter.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/Internal/IRequestProcessor.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/Internal/Infrastructure/CancellationTokenExtensions.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/Internal/Infrastructure/Constants.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/Internal/Infrastructure/CorrelationIdGenerator.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/Internal/Infrastructure/DebuggerWrapper.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/Internal/Infrastructure/Disposable.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/Internal/Infrastructure/DisposableAction.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/Internal/Infrastructure/Heartbeat.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/Internal/Infrastructure/HttpConnectionManager.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/Internal/Infrastructure/HttpConnectionManagerShutdownExtensions.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/Internal/Infrastructure/HttpConnectionReference.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/Internal/Infrastructure/HttpHeartbeatManager.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/Internal/Infrastructure/HttpUtilities.Generated.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/Internal/Infrastructure/HttpUtilities.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/Internal/Infrastructure/IDebugger.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/Internal/Infrastructure/IHeartbeatHandler.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/Internal/Infrastructure/IKestrelTrace.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/Internal/Infrastructure/ISystemClock.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/Internal/Infrastructure/ITimeoutControl.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/Internal/Infrastructure/KestrelEventSource.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/Internal/Infrastructure/KestrelTrace.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/Internal/Infrastructure/ReadOnlyStream.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/Internal/Infrastructure/ResourceCounter.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/Internal/Infrastructure/StackTraceHiddenAttribute.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/Internal/Infrastructure/Streams.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/Internal/Infrastructure/StringUtilities.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/Internal/Infrastructure/SystemClock.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/Internal/Infrastructure/ThrowingWriteOnlyStream.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/Internal/Infrastructure/TimeoutAction.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/Internal/Infrastructure/UriUtilities.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/Internal/Infrastructure/WrappingStream.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/Internal/Infrastructure/WriteOnlyStream.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/Internal/KestrelServerOptionsSetup.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/Internal/LoggerExtensions.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/Internal/ServerAddressesFeature.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/Internal/ServiceContext.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/Internal/TlsConnectionFeature.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/KestrelConfigurationLoader.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/KestrelServer.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/KestrelServerLimits.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/KestrelServerOptions.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/ListenOptions.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/ListenOptionsHttpsExtensions.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/LocalhostListenOptions.cs (100%) create mode 100644 src/Servers/Kestrel/Core/src/Microsoft.AspNetCore.Server.Kestrel.Core.csproj rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/MinDataRate.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/Properties/AssemblyInfo.cs (87%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/Properties/CoreStrings.Designer.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/ServerAddress.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/Systemd/KestrelServerOptionsSystemdExtensions.cs (100%) rename src/{Kestrel.Core => Servers/Kestrel/Core/src}/baseline.netcore.json (100%) rename {test/Kestrel.Core.Tests => src/Servers/Kestrel/Core/test}/AddressBinderTests.cs (100%) rename {test/Kestrel.Core.Tests => src/Servers/Kestrel/Core/test}/AsciiDecoding.cs (100%) rename {test/Kestrel.Core.Tests => src/Servers/Kestrel/Core/test}/BufferReaderTests.cs (100%) rename {test/Kestrel.Core.Tests => src/Servers/Kestrel/Core/test}/BufferWriterTests.cs (100%) rename {test/Kestrel.Core.Tests => src/Servers/Kestrel/Core/test}/ChunkWriterTests.cs (100%) rename {test/Kestrel.Core.Tests => src/Servers/Kestrel/Core/test}/ConnectionDispatcherTests.cs (100%) rename {test/Kestrel.Core.Tests => src/Servers/Kestrel/Core/test}/DateHeaderValueManagerTests.cs (100%) rename {test/Kestrel.Core.Tests => src/Servers/Kestrel/Core/test}/DynamicTableTests.cs (100%) rename {test/Kestrel.Core.Tests => src/Servers/Kestrel/Core/test}/HPackDecoderTests.cs (100%) rename {test/Kestrel.Core.Tests => src/Servers/Kestrel/Core/test}/HPackEncoderTests.cs (100%) rename {test/Kestrel.Core.Tests => src/Servers/Kestrel/Core/test}/HeartbeatTests.cs (100%) rename {test/Kestrel.Core.Tests => src/Servers/Kestrel/Core/test}/Http1ConnectionTests.cs (100%) rename {test/Kestrel.Core.Tests => src/Servers/Kestrel/Core/test}/Http2ConnectionTests.cs (100%) rename {test/Kestrel.Core.Tests => src/Servers/Kestrel/Core/test}/HttpConnectionManagerTests.cs (100%) rename {test/Kestrel.Core.Tests => src/Servers/Kestrel/Core/test}/HttpConnectionTests.cs (100%) rename {test/Kestrel.Core.Tests => src/Servers/Kestrel/Core/test}/HttpHeadersTests.cs (100%) rename {test/Kestrel.Core.Tests => src/Servers/Kestrel/Core/test}/HttpParserTests.cs (100%) rename {test/Kestrel.Core.Tests => src/Servers/Kestrel/Core/test}/HttpProtocolFeatureCollectionTests.cs (100%) rename {test/Kestrel.Core.Tests => src/Servers/Kestrel/Core/test}/HttpRequestHeadersTests.cs (100%) rename {test/Kestrel.Core.Tests => src/Servers/Kestrel/Core/test}/HttpRequestStreamTests.cs (100%) rename {test/Kestrel.Core.Tests => src/Servers/Kestrel/Core/test}/HttpResponseHeadersTests.cs (100%) rename {test/Kestrel.Core.Tests => src/Servers/Kestrel/Core/test}/HttpResponseStreamTests.cs (100%) rename {test/Kestrel.Core.Tests => src/Servers/Kestrel/Core/test}/HttpUtilitiesTest.cs (100%) rename {test/Kestrel.Core.Tests => src/Servers/Kestrel/Core/test}/HuffmanTests.cs (100%) rename {test/Kestrel.Core.Tests => src/Servers/Kestrel/Core/test}/IntegerDecoderTests.cs (100%) rename {test/Kestrel.Core.Tests => src/Servers/Kestrel/Core/test}/IntegerEncoderTests.cs (100%) rename {test/Kestrel.Core.Tests => src/Servers/Kestrel/Core/test}/KestrelEventSourceTests.cs (100%) rename {test/Kestrel.Core.Tests => src/Servers/Kestrel/Core/test}/KestrelServerLimitsTests.cs (100%) rename {test/Kestrel.Core.Tests => src/Servers/Kestrel/Core/test}/KestrelServerOptionsTests.cs (100%) rename {test/Kestrel.Core.Tests => src/Servers/Kestrel/Core/test}/KestrelServerTests.cs (100%) rename {test/Kestrel.Core.Tests => src/Servers/Kestrel/Core/test}/KnownStringsTests.cs (100%) rename {test/Kestrel.Core.Tests => src/Servers/Kestrel/Core/test}/ListenOptionsTests.cs (100%) rename {test/Kestrel.Core.Tests => src/Servers/Kestrel/Core/test}/MessageBodyTests.cs (100%) create mode 100644 src/Servers/Kestrel/Core/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests.csproj rename {test/Kestrel.Core.Tests => src/Servers/Kestrel/Core/test}/MinDataRateTests.cs (100%) rename {test/Kestrel.Core.Tests => src/Servers/Kestrel/Core/test}/OutputProducerTests.cs (100%) rename {test/Kestrel.Core.Tests => src/Servers/Kestrel/Core/test}/PathNormalizerTests.cs (100%) rename {test/Kestrel.Core.Tests => src/Servers/Kestrel/Core/test}/PipeOptionsTests.cs (100%) rename {test/Kestrel.Core.Tests => src/Servers/Kestrel/Core/test}/PipelineExtensionTests.cs (100%) rename {test/Kestrel.Core.Tests => src/Servers/Kestrel/Core/test}/ReasonPhrasesTests.cs (100%) rename {test/Kestrel.Core.Tests => src/Servers/Kestrel/Core/test}/ResourceCounterTests.cs (100%) rename {test/Kestrel.Core.Tests => src/Servers/Kestrel/Core/test}/ServerAddressTests.cs (100%) rename {test/Kestrel.Core.Tests => src/Servers/Kestrel/Core/test}/StreamsTests.cs (100%) rename {test/Kestrel.Core.Tests => src/Servers/Kestrel/Core/test}/StringUtilitiesTests.cs (100%) rename {test/Kestrel.Core.Tests => src/Servers/Kestrel/Core/test}/TestHelpers/AssertExtensions.cs (100%) rename {test/Kestrel.Core.Tests => src/Servers/Kestrel/Core/test}/TestHelpers/MockHttpResponseControl.cs (100%) rename {test/Kestrel.Core.Tests => src/Servers/Kestrel/Core/test}/TestInput.cs (100%) rename {test/Kestrel.Core.Tests => src/Servers/Kestrel/Core/test}/ThrowingWriteOnlyStreamTests.cs (100%) create mode 100644 src/Servers/Kestrel/Directory.Build.props rename src/{Kestrel.Https/Kestrel.Https.csproj => Servers/Kestrel/Https/src/Microsoft.AspNetCore.Server.Kestrel.Https.csproj} (53%) rename src/{Kestrel.Https => Servers/Kestrel/Https/src}/Properties/AssemblyInfo.cs (100%) rename src/{Kestrel.Https => Servers/Kestrel/Https/src}/baseline.netcore.json (100%) create mode 100644 src/Servers/Kestrel/Kestrel/src/Microsoft.AspNetCore.Server.Kestrel.csproj rename src/{Kestrel => Servers/Kestrel/Kestrel/src}/WebHostBuilderKestrelExtensions.cs (100%) rename src/{Kestrel => Servers/Kestrel/Kestrel/src}/baseline.netcore.json (100%) rename {test/Kestrel.Tests => src/Servers/Kestrel/Kestrel/test}/ConfigurationReaderTests.cs (100%) rename {test/Kestrel.Tests => src/Servers/Kestrel/Kestrel/test}/KestrelConfigurationBuilderTests.cs (100%) create mode 100644 src/Servers/Kestrel/Kestrel/test/Microsoft.AspNetCore.Server.Kestrel.Tests.csproj rename {test/Kestrel.Tests => src/Servers/Kestrel/Kestrel/test}/WebHostBuilderKestrelExtensionsTests.cs (100%) create mode 100644 src/Servers/Kestrel/README.md rename src/{Kestrel.Transport.Abstractions => Servers/Kestrel/Transport.Abstractions/src}/Internal/FileHandleType.cs (100%) rename src/{Kestrel.Transport.Abstractions => Servers/Kestrel/Transport.Abstractions/src}/Internal/IApplicationTransportFeature.cs (100%) rename src/{Kestrel.Transport.Abstractions => Servers/Kestrel/Transport.Abstractions/src}/Internal/IBytesWrittenFeature.cs (100%) rename src/{Kestrel.Transport.Abstractions => Servers/Kestrel/Transport.Abstractions/src}/Internal/IConnectionDispatcher.cs (100%) rename src/{Kestrel.Transport.Abstractions => Servers/Kestrel/Transport.Abstractions/src}/Internal/IEndPointInformation.cs (100%) rename src/{Kestrel.Transport.Abstractions => Servers/Kestrel/Transport.Abstractions/src}/Internal/ITransport.cs (100%) rename src/{Kestrel.Transport.Abstractions => Servers/Kestrel/Transport.Abstractions/src}/Internal/ITransportFactory.cs (100%) rename src/{Kestrel.Transport.Abstractions => Servers/Kestrel/Transport.Abstractions/src}/Internal/ITransportSchedulerFeature.cs (100%) rename src/{Kestrel.Transport.Abstractions => Servers/Kestrel/Transport.Abstractions/src}/Internal/KestrelMemoryPool.cs (100%) rename src/{Kestrel.Transport.Abstractions => Servers/Kestrel/Transport.Abstractions/src}/Internal/ListenType.cs (100%) rename src/{Kestrel.Transport.Abstractions => Servers/Kestrel/Transport.Abstractions/src}/Internal/MemoryPoolBlock.Debug.cs (100%) rename src/{Kestrel.Transport.Abstractions => Servers/Kestrel/Transport.Abstractions/src}/Internal/MemoryPoolBlock.Release.cs (100%) rename src/{Kestrel.Transport.Abstractions => Servers/Kestrel/Transport.Abstractions/src}/Internal/MemoryPoolSlab.cs (100%) rename src/{Kestrel.Transport.Abstractions => Servers/Kestrel/Transport.Abstractions/src}/Internal/SchedulingMode.cs (100%) rename src/{Kestrel.Transport.Abstractions => Servers/Kestrel/Transport.Abstractions/src}/Internal/SlabMemoryPool.cs (100%) rename src/{Kestrel.Transport.Abstractions => Servers/Kestrel/Transport.Abstractions/src}/Internal/TransportConnection.Features.cs (100%) rename src/{Kestrel.Transport.Abstractions => Servers/Kestrel/Transport.Abstractions/src}/Internal/TransportConnection.cs (100%) rename src/{Kestrel.Transport.Abstractions/Kestrel.Transport.Abstractions.csproj => Servers/Kestrel/Transport.Abstractions/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.csproj} (64%) rename src/{Kestrel.Transport.Abstractions => Servers/Kestrel/Transport.Abstractions/src}/baseline.netcore.json (100%) rename src/{Kestrel.Transport.Libuv => Servers/Kestrel/Transport.Libuv/src}/Internal/IAsyncDisposable.cs (100%) rename src/{Kestrel.Transport.Libuv => Servers/Kestrel/Transport.Libuv/src}/Internal/ILibuvTrace.cs (100%) rename src/{Kestrel.Transport.Libuv => Servers/Kestrel/Transport.Libuv/src}/Internal/LibuvAwaitable.cs (100%) rename src/{Kestrel.Transport.Libuv => Servers/Kestrel/Transport.Libuv/src}/Internal/LibuvConnection.cs (100%) rename src/{Kestrel.Transport.Libuv => Servers/Kestrel/Transport.Libuv/src}/Internal/LibuvConstants.cs (100%) rename src/{Kestrel.Transport.Libuv => Servers/Kestrel/Transport.Libuv/src}/Internal/LibuvOutputConsumer.cs (100%) rename src/{Kestrel.Transport.Libuv => Servers/Kestrel/Transport.Libuv/src}/Internal/LibuvThread.cs (100%) rename src/{Kestrel.Transport.Libuv => Servers/Kestrel/Transport.Libuv/src}/Internal/LibuvTrace.cs (100%) rename src/{Kestrel.Transport.Libuv => Servers/Kestrel/Transport.Libuv/src}/Internal/LibuvTransport.cs (100%) rename src/{Kestrel.Transport.Libuv => Servers/Kestrel/Transport.Libuv/src}/Internal/LibuvTransportContext.cs (100%) rename src/{Kestrel.Transport.Libuv => Servers/Kestrel/Transport.Libuv/src}/Internal/LibuvTransportFactory.cs (100%) rename src/{Kestrel.Transport.Libuv => Servers/Kestrel/Transport.Libuv/src}/Internal/Listener.cs (100%) rename src/{Kestrel.Transport.Libuv => Servers/Kestrel/Transport.Libuv/src}/Internal/ListenerContext.cs (100%) rename src/{Kestrel.Transport.Libuv => Servers/Kestrel/Transport.Libuv/src}/Internal/ListenerPrimary.cs (100%) rename src/{Kestrel.Transport.Libuv => Servers/Kestrel/Transport.Libuv/src}/Internal/ListenerSecondary.cs (100%) rename src/{Kestrel.Transport.Libuv => Servers/Kestrel/Transport.Libuv/src}/Internal/Networking/LibuvFunctions.cs (100%) rename src/{Kestrel.Transport.Libuv => Servers/Kestrel/Transport.Libuv/src}/Internal/Networking/PlatformApis.cs (100%) rename src/{Kestrel.Transport.Libuv => Servers/Kestrel/Transport.Libuv/src}/Internal/Networking/SockAddr.cs (100%) rename src/{Kestrel.Transport.Libuv => Servers/Kestrel/Transport.Libuv/src}/Internal/Networking/UvAsyncHandle.cs (100%) rename src/{Kestrel.Transport.Libuv => Servers/Kestrel/Transport.Libuv/src}/Internal/Networking/UvConnectRequest.cs (100%) rename src/{Kestrel.Transport.Libuv => Servers/Kestrel/Transport.Libuv/src}/Internal/Networking/UvException.cs (100%) rename src/{Kestrel.Transport.Libuv => Servers/Kestrel/Transport.Libuv/src}/Internal/Networking/UvHandle.cs (100%) rename src/{Kestrel.Transport.Libuv => Servers/Kestrel/Transport.Libuv/src}/Internal/Networking/UvLoopHandle.cs (100%) rename src/{Kestrel.Transport.Libuv => Servers/Kestrel/Transport.Libuv/src}/Internal/Networking/UvMemory.cs (100%) rename src/{Kestrel.Transport.Libuv => Servers/Kestrel/Transport.Libuv/src}/Internal/Networking/UvPipeHandle.cs (100%) rename src/{Kestrel.Transport.Libuv => Servers/Kestrel/Transport.Libuv/src}/Internal/Networking/UvRequest.cs (100%) rename src/{Kestrel.Transport.Libuv => Servers/Kestrel/Transport.Libuv/src}/Internal/Networking/UvStreamHandle.cs (100%) rename src/{Kestrel.Transport.Libuv => Servers/Kestrel/Transport.Libuv/src}/Internal/Networking/UvTcpHandle.cs (100%) rename src/{Kestrel.Transport.Libuv => Servers/Kestrel/Transport.Libuv/src}/Internal/Networking/UvTimerHandle.cs (100%) rename src/{Kestrel.Transport.Libuv => Servers/Kestrel/Transport.Libuv/src}/Internal/Networking/UvWriteReq.cs (100%) rename src/{Kestrel.Transport.Libuv => Servers/Kestrel/Transport.Libuv/src}/Internal/WriteReqPool.cs (100%) rename src/{Kestrel.Transport.Libuv => Servers/Kestrel/Transport.Libuv/src}/LibuvTransportOptions.cs (100%) create mode 100644 src/Servers/Kestrel/Transport.Libuv/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.csproj rename src/{Kestrel.Transport.Libuv => Servers/Kestrel/Transport.Libuv/src}/WebHostBuilderLibuvExtensions.cs (100%) rename src/{Kestrel.Transport.Libuv => Servers/Kestrel/Transport.Libuv/src}/baseline.netcore.json (100%) rename src/{Kestrel.Transport.Libuv => Servers/Kestrel/Transport.Libuv/src}/breakingchanges.netcore.json (100%) rename {test/Kestrel.Transport.Libuv.Tests => src/Servers/Kestrel/Transport.Libuv/test}/LibuvConnectionTests.cs (100%) rename {test/Kestrel.Transport.Libuv.Tests => src/Servers/Kestrel/Transport.Libuv/test}/LibuvOutputConsumerTests.cs (100%) rename {test/Kestrel.Transport.Libuv.Tests => src/Servers/Kestrel/Transport.Libuv/test}/LibuvThreadTests.cs (100%) rename {test/Kestrel.Transport.Libuv.Tests => src/Servers/Kestrel/Transport.Libuv/test}/LibuvTransportFactoryTests.cs (100%) rename {test/Kestrel.Transport.Libuv.Tests => src/Servers/Kestrel/Transport.Libuv/test}/LibuvTransportOptionsTests.cs (100%) rename {test/Kestrel.Transport.Libuv.Tests => src/Servers/Kestrel/Transport.Libuv/test}/LibuvTransportTests.cs (100%) rename {test/Kestrel.Transport.Libuv.Tests => src/Servers/Kestrel/Transport.Libuv/test}/ListenerPrimaryTests.cs (100%) create mode 100644 src/Servers/Kestrel/Transport.Libuv/test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests.csproj rename {test/Kestrel.Transport.Libuv.Tests => src/Servers/Kestrel/Transport.Libuv/test}/MultipleLoopTests.cs (100%) rename {test/Kestrel.Transport.Libuv.Tests => src/Servers/Kestrel/Transport.Libuv/test}/NetworkingTests.cs (100%) rename {test/Kestrel.Transport.Libuv.Tests => src/Servers/Kestrel/Transport.Libuv/test}/TestHelpers/MockConnectionDispatcher.cs (100%) rename {test/Kestrel.Transport.Libuv.Tests => src/Servers/Kestrel/Transport.Libuv/test}/TestHelpers/MockLibuv.cs (100%) rename {test/Kestrel.Transport.Libuv.Tests => src/Servers/Kestrel/Transport.Libuv/test}/TestHelpers/MockSocket.cs (100%) rename {test/Kestrel.Transport.Libuv.Tests => src/Servers/Kestrel/Transport.Libuv/test}/TestHelpers/TestLibuvTransportContext.cs (100%) rename {test/Kestrel.Transport.Libuv.Tests => src/Servers/Kestrel/Transport.Libuv/test}/UvStreamHandleTests.cs (100%) rename {test/Kestrel.Transport.Libuv.Tests => src/Servers/Kestrel/Transport.Libuv/test}/UvTimerHandleTests.cs (100%) rename src/{Kestrel.Transport.Sockets => Servers/Kestrel/Transport.Sockets/src}/Internal/BufferExtensions.cs (100%) rename src/{Kestrel.Transport.Sockets => Servers/Kestrel/Transport.Sockets/src}/Internal/IOQueue.cs (100%) rename src/{Kestrel.Transport.Sockets => Servers/Kestrel/Transport.Sockets/src}/Internal/ISocketsTrace.cs (100%) rename src/{Kestrel.Transport.Sockets => Servers/Kestrel/Transport.Sockets/src}/Internal/SocketAwaitable.cs (100%) rename src/{Kestrel.Transport.Sockets => Servers/Kestrel/Transport.Sockets/src}/Internal/SocketConnection.cs (100%) rename src/{Kestrel.Transport.Sockets => Servers/Kestrel/Transport.Sockets/src}/Internal/SocketReceiver.cs (100%) rename src/{Kestrel.Transport.Sockets => Servers/Kestrel/Transport.Sockets/src}/Internal/SocketSender.cs (100%) rename src/{Kestrel.Transport.Sockets => Servers/Kestrel/Transport.Sockets/src}/Internal/SocketsTrace.cs (100%) rename src/{Kestrel.Transport.Sockets/Kestrel.Transport.Sockets.csproj => Servers/Kestrel/Transport.Sockets/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.csproj} (52%) rename src/{Kestrel.Transport.Sockets => Servers/Kestrel/Transport.Sockets/src}/Properties/SocketsStrings.Designer.cs (100%) rename src/{Kestrel.Transport.Sockets => Servers/Kestrel/Transport.Sockets/src}/SocketTransport.cs (100%) rename src/{Kestrel.Transport.Sockets => Servers/Kestrel/Transport.Sockets/src}/SocketTransportFactory.cs (100%) rename src/{Kestrel.Transport.Sockets => Servers/Kestrel/Transport.Sockets/src}/SocketTransportOptions.cs (100%) rename src/{Kestrel.Transport.Sockets => Servers/Kestrel/Transport.Sockets/src}/SocketsStrings.resx (100%) rename src/{Kestrel.Transport.Sockets => Servers/Kestrel/Transport.Sockets/src}/WebHostBuilderSocketExtensions.cs (100%) rename src/{Kestrel.Transport.Sockets => Servers/Kestrel/Transport.Sockets/src}/baseline.netcore.json (100%) rename {benchmarks => src/Servers/Kestrel/perf}/Kestrel.Performance/AsciiBytesToStringBenchmark.cs (100%) rename {benchmarks => src/Servers/Kestrel/perf}/Kestrel.Performance/AssemblyInfo.cs (100%) rename {benchmarks => src/Servers/Kestrel/perf}/Kestrel.Performance/DotSegmentRemovalBenchmark.cs (100%) rename {benchmarks => src/Servers/Kestrel/perf}/Kestrel.Performance/ErrorUtilities.cs (100%) rename {benchmarks => src/Servers/Kestrel/perf}/Kestrel.Performance/Http1ConnectionBenchmark.cs (100%) rename {benchmarks => src/Servers/Kestrel/perf}/Kestrel.Performance/Http1ConnectionParsingOverheadBenchmark.cs (100%) rename {benchmarks => src/Servers/Kestrel/perf}/Kestrel.Performance/Http1WritingBenchmark.cs (100%) rename {benchmarks => src/Servers/Kestrel/perf}/Kestrel.Performance/HttpParserBenchmark.cs (100%) rename {benchmarks => src/Servers/Kestrel/perf}/Kestrel.Performance/HttpProtocolFeatureCollection.cs (100%) rename {benchmarks => src/Servers/Kestrel/perf}/Kestrel.Performance/InMemoryTransportBenchmark.cs (100%) rename {benchmarks => src/Servers/Kestrel/perf}/Kestrel.Performance/KnownStringsBenchmark.cs (100%) create mode 100644 src/Servers/Kestrel/perf/Kestrel.Performance/Microsoft.AspNetCore.Server.Kestrel.Performance.csproj rename {benchmarks => src/Servers/Kestrel/perf}/Kestrel.Performance/Mocks/MockTimeoutControl.cs (100%) rename {benchmarks => src/Servers/Kestrel/perf}/Kestrel.Performance/Mocks/MockTrace.cs (100%) rename {benchmarks => src/Servers/Kestrel/perf}/Kestrel.Performance/Mocks/NullParser.cs (100%) rename {benchmarks => src/Servers/Kestrel/perf}/Kestrel.Performance/PipeThroughputBenchmark.cs (100%) rename {benchmarks => src/Servers/Kestrel/perf}/Kestrel.Performance/README.md (100%) rename {benchmarks => src/Servers/Kestrel/perf}/Kestrel.Performance/RequestParsingBenchmark.cs (100%) rename {benchmarks => src/Servers/Kestrel/perf}/Kestrel.Performance/RequestParsingData.cs (100%) rename {benchmarks => src/Servers/Kestrel/perf}/Kestrel.Performance/ResponseHeaderCollectionBenchmark.cs (100%) rename {benchmarks => src/Servers/Kestrel/perf}/Kestrel.Performance/ResponseHeadersWritingBenchmark.cs (100%) rename {benchmarks => src/Servers/Kestrel/perf}/Kestrel.Performance/StringUtilitiesBenchmark.cs (100%) rename {benchmarkapps => src/Servers/Kestrel/perf}/PlatformBenchmarks/AsciiString.cs (100%) rename {benchmarkapps => src/Servers/Kestrel/perf}/PlatformBenchmarks/BenchmarkApplication.cs (100%) rename {benchmarkapps => src/Servers/Kestrel/perf}/PlatformBenchmarks/BenchmarkConfigurationHelpers.cs (100%) rename {benchmarkapps => src/Servers/Kestrel/perf}/PlatformBenchmarks/DateHeader.cs (100%) rename {benchmarkapps => src/Servers/Kestrel/perf}/PlatformBenchmarks/HttpApplication.cs (100%) rename {benchmarkapps => src/Servers/Kestrel/perf}/PlatformBenchmarks/PlatformBenchmarks.csproj (52%) rename {benchmarkapps => src/Servers/Kestrel/perf}/PlatformBenchmarks/Program.cs (100%) rename {benchmarkapps => src/Servers/Kestrel/perf}/PlatformBenchmarks/Startup.cs (100%) rename {benchmarkapps => src/Servers/Kestrel/perf}/PlatformBenchmarks/benchmarks.json.json (100%) rename {benchmarkapps => src/Servers/Kestrel/perf}/PlatformBenchmarks/benchmarks.plaintext.json (100%) rename {samples => src/Servers/Kestrel/samples}/Http2SampleApp/Dockerfile (100%) rename {samples => src/Servers/Kestrel/samples}/Http2SampleApp/Http2SampleApp.csproj (59%) rename {samples => src/Servers/Kestrel/samples}/Http2SampleApp/Program.cs (100%) rename {samples => src/Servers/Kestrel/samples}/Http2SampleApp/Startup.cs (100%) rename {samples => src/Servers/Kestrel/samples}/Http2SampleApp/scripts/build-docker.ps1 (100%) rename {samples => src/Servers/Kestrel/samples}/Http2SampleApp/scripts/build-docker.sh (100%) mode change 100755 => 100644 rename {samples => src/Servers/Kestrel/samples}/Http2SampleApp/scripts/run-docker.ps1 (100%) rename {samples => src/Servers/Kestrel/samples}/Http2SampleApp/scripts/run-docker.sh (100%) mode change 100755 => 100644 rename {samples => src/Servers/Kestrel/samples}/Http2SampleApp/testCert.pfx (100%) rename {samples => src/Servers/Kestrel/samples}/LargeResponseApp/LargeResponseApp.csproj (80%) rename {samples => src/Servers/Kestrel/samples}/LargeResponseApp/Startup.cs (100%) rename {samples => src/Servers/Kestrel/samples}/PlaintextApp/PlaintextApp.csproj (80%) rename {samples => src/Servers/Kestrel/samples}/PlaintextApp/Startup.cs (100%) rename {samples => src/Servers/Kestrel/samples}/SampleApp/SampleApp.csproj (61%) rename {samples => src/Servers/Kestrel/samples}/SampleApp/Startup.cs (100%) rename {samples => src/Servers/Kestrel/samples}/SampleApp/appsettings.Development.json (100%) rename {samples => src/Servers/Kestrel/samples}/SampleApp/appsettings.Production.json (100%) rename {samples => src/Servers/Kestrel/samples}/SampleApp/appsettings.json (100%) rename {samples => src/Servers/Kestrel/samples}/SampleApp/testCert.pfx (100%) rename {samples => src/Servers/Kestrel/samples}/SystemdTestApp/Startup.cs (100%) rename {samples => src/Servers/Kestrel/samples}/SystemdTestApp/SystemdTestApp.csproj (57%) rename {samples => src/Servers/Kestrel/samples}/SystemdTestApp/testCert.pfx (100%) rename src/{shared => Servers/Kestrel/shared/src}/ThrowHelper.cs (100%) rename {test/shared => src/Servers/Kestrel/shared/test}/DisposableStack.cs (100%) rename {test/shared => src/Servers/Kestrel/shared/test}/DummyApplication.cs (100%) rename {test/shared => src/Servers/Kestrel/shared/test}/EventRaisingResourceCounter.cs (100%) rename {test/shared => src/Servers/Kestrel/shared/test}/HttpParsingData.cs (100%) rename {test/shared => src/Servers/Kestrel/shared/test}/KestrelTestLoggerProvider.cs (100%) rename {test/shared => src/Servers/Kestrel/shared/test}/LifetimeNotImplemented.cs (100%) rename {test/shared => src/Servers/Kestrel/shared/test}/MockLogger.cs (100%) rename {test/shared => src/Servers/Kestrel/shared/test}/MockSystemClock.cs (100%) rename {test/shared => src/Servers/Kestrel/shared/test}/PassThroughConnectionAdapter.cs (100%) rename {test/shared => src/Servers/Kestrel/shared/test}/StringExtensions.cs (100%) rename {test/shared => src/Servers/Kestrel/shared/test}/TaskTimeoutExtensions.cs (100%) rename {test/shared => src/Servers/Kestrel/shared/test}/TestApp.cs (100%) rename {test/shared => src/Servers/Kestrel/shared/test}/TestApplicationErrorLogger.cs (100%) rename {test/shared => src/Servers/Kestrel/shared/test}/TestCertificates/aspnetdevcert.pfx (100%) rename {test/shared => src/Servers/Kestrel/shared/test}/TestCertificates/eku.client.ini (100%) rename {test/shared => src/Servers/Kestrel/shared/test}/TestCertificates/eku.client.pfx (100%) rename {test/shared => src/Servers/Kestrel/shared/test}/TestCertificates/eku.code_signing.ini (100%) rename {test/shared => src/Servers/Kestrel/shared/test}/TestCertificates/eku.code_signing.pfx (100%) rename {test/shared => src/Servers/Kestrel/shared/test}/TestCertificates/eku.multiple_usages.ini (100%) rename {test/shared => src/Servers/Kestrel/shared/test}/TestCertificates/eku.multiple_usages.pfx (100%) rename {test/shared => src/Servers/Kestrel/shared/test}/TestCertificates/eku.server.ini (100%) rename {test/shared => src/Servers/Kestrel/shared/test}/TestCertificates/eku.server.pfx (100%) rename {test/shared => src/Servers/Kestrel/shared/test}/TestCertificates/make-test-certs.sh (100%) mode change 100755 => 100644 rename {test/shared => src/Servers/Kestrel/shared/test}/TestCertificates/no_extensions.ini (100%) rename {test/shared => src/Servers/Kestrel/shared/test}/TestCertificates/no_extensions.pfx (100%) rename {test/shared => src/Servers/Kestrel/shared/test}/TestCertificates/testCert.pfx (100%) rename {test/shared => src/Servers/Kestrel/shared/test}/TestConnection.cs (100%) rename {test/shared => src/Servers/Kestrel/shared/test}/TestConstants.cs (100%) rename {test/shared => src/Servers/Kestrel/shared/test}/TestHttp1Connection.cs (100%) rename {test/shared => src/Servers/Kestrel/shared/test}/TestKestrelTrace.cs (100%) rename {test/shared => src/Servers/Kestrel/shared/test}/TestResources.cs (100%) rename {test/shared => src/Servers/Kestrel/shared/test}/TestServiceContext.cs (100%) rename {test/Kestrel.FunctionalTests => src/Servers/Kestrel/test/FunctionalTests}/AddressRegistrationTests.cs (100%) rename {test/Kestrel.FunctionalTests => src/Servers/Kestrel/test/FunctionalTests}/BadHttpRequestTests.cs (100%) rename {test/Kestrel.FunctionalTests => src/Servers/Kestrel/test/FunctionalTests}/CertificateLoaderTests.cs (100%) rename {test/Kestrel.FunctionalTests => src/Servers/Kestrel/test/FunctionalTests}/ChunkedRequestTests.cs (100%) rename {test/Kestrel.FunctionalTests => src/Servers/Kestrel/test/FunctionalTests}/ChunkedResponseTests.cs (100%) rename {test/Kestrel.FunctionalTests => src/Servers/Kestrel/test/FunctionalTests}/ConnectionAdapterTests.cs (100%) rename {test/Kestrel.FunctionalTests => src/Servers/Kestrel/test/FunctionalTests}/ConnectionLimitTests.cs (100%) rename {test/Kestrel.FunctionalTests => src/Servers/Kestrel/test/FunctionalTests}/DefaultHeaderTests.cs (100%) rename {test/Kestrel.FunctionalTests => src/Servers/Kestrel/test/FunctionalTests}/EventSourceTests.cs (100%) rename {test/Kestrel.FunctionalTests => src/Servers/Kestrel/test/FunctionalTests}/GeneratedCodeTests.cs (77%) rename {test/Kestrel.FunctionalTests => src/Servers/Kestrel/test/FunctionalTests}/HttpConnectionManagerTests.cs (100%) rename {test/Kestrel.FunctionalTests => src/Servers/Kestrel/test/FunctionalTests}/HttpProtocolSelectionTests.cs (100%) rename {test/Kestrel.FunctionalTests => src/Servers/Kestrel/test/FunctionalTests}/HttpsConnectionAdapterOptionsTest.cs (100%) rename {test/Kestrel.FunctionalTests => src/Servers/Kestrel/test/FunctionalTests}/HttpsConnectionAdapterTests.cs (100%) rename {test/Kestrel.FunctionalTests => src/Servers/Kestrel/test/FunctionalTests}/HttpsTests.cs (100%) rename {test/Kestrel.FunctionalTests => src/Servers/Kestrel/test/FunctionalTests}/KeepAliveTimeoutTests.cs (100%) rename {test/Kestrel.FunctionalTests => src/Servers/Kestrel/test/FunctionalTests}/LoggingConnectionAdapterTests.cs (100%) rename {test/Kestrel.FunctionalTests => src/Servers/Kestrel/test/FunctionalTests}/MaxRequestBodySizeTests.cs (100%) rename {test/Kestrel.FunctionalTests => src/Servers/Kestrel/test/FunctionalTests}/MaxRequestBufferSizeTests.cs (100%) rename {test/Kestrel.FunctionalTests => src/Servers/Kestrel/test/FunctionalTests}/MaxRequestLineSizeTests.cs (100%) rename {test/Kestrel.FunctionalTests => src/Servers/Kestrel/test/FunctionalTests}/Properties/AssemblyInfo.cs (100%) rename {test/Kestrel.FunctionalTests => src/Servers/Kestrel/test/FunctionalTests}/RequestBodyTimeoutTests.cs (100%) rename {test/Kestrel.FunctionalTests => src/Servers/Kestrel/test/FunctionalTests}/RequestHeaderLimitsTests.cs (100%) rename {test/Kestrel.FunctionalTests => src/Servers/Kestrel/test/FunctionalTests}/RequestHeadersTimeoutTests.cs (100%) rename {test/Kestrel.FunctionalTests => src/Servers/Kestrel/test/FunctionalTests}/RequestTargetProcessingTests.cs (100%) rename {test/Kestrel.FunctionalTests => src/Servers/Kestrel/test/FunctionalTests}/RequestTests.cs (100%) rename {test/Kestrel.FunctionalTests => src/Servers/Kestrel/test/FunctionalTests}/ResponseTests.cs (100%) rename {test/Kestrel.FunctionalTests => src/Servers/Kestrel/test/FunctionalTests}/TestHelpers/HostNameIsReachableAttribute.cs (100%) rename {test/Kestrel.FunctionalTests => src/Servers/Kestrel/test/FunctionalTests}/TestHelpers/IPv6ScopeIdPresentConditionAttribute.cs (100%) rename {test/Kestrel.FunctionalTests => src/Servers/Kestrel/test/FunctionalTests}/TestHelpers/IPv6SupportedConditionAttribute.cs (100%) rename {test/Kestrel.FunctionalTests => src/Servers/Kestrel/test/FunctionalTests}/TestHelpers/IWebHostPortExtensions.cs (100%) rename {test/Kestrel.FunctionalTests => src/Servers/Kestrel/test/FunctionalTests}/TestHelpers/TestApplicationErrorLoggerLoggedTest.cs (100%) rename {test/Kestrel.FunctionalTests => src/Servers/Kestrel/test/FunctionalTests}/TestHelpers/TestServer.cs (100%) rename {test/Kestrel.FunctionalTests => src/Servers/Kestrel/test/FunctionalTests}/UpgradeTests.cs (100%) create mode 100644 src/Servers/Kestrel/test/Libuv.FunctionalTests/Libuv.FunctionalTests.csproj rename {test/Kestrel.Transport.Libuv.FunctionalTests => src/Servers/Kestrel/test/Libuv.FunctionalTests}/ListenHandleTests.cs (100%) rename {test/Kestrel.Transport.Libuv.FunctionalTests => src/Servers/Kestrel/test/Libuv.FunctionalTests}/TransportSelector.cs (100%) create mode 100644 src/Servers/Kestrel/test/Sockets.FunctionalTests/Sockets.FunctionalTests.csproj rename {test/Kestrel.Transport.Sockets.FunctionalTests => src/Servers/Kestrel/test/Sockets.FunctionalTests}/TransportSelector.cs (100%) rename {test => src/Servers/Kestrel/test}/SystemdActivation/Dockerfile (100%) rename {test => src/Servers/Kestrel/test}/SystemdActivation/docker-entrypoint.sh (100%) rename {test => src/Servers/Kestrel/test}/SystemdActivation/docker.sh (100%) rename {tools => src/Servers/Kestrel/tools}/CodeGenerator/CodeGenerator.csproj (58%) rename {tools => src/Servers/Kestrel/tools}/CodeGenerator/HttpProtocolFeatureCollection.cs (100%) rename {tools => src/Servers/Kestrel/tools}/CodeGenerator/HttpUtilities/CombinationsWithoutRepetition.cs (100%) rename {tools => src/Servers/Kestrel/tools}/CodeGenerator/HttpUtilities/HttpUtilities.cs (100%) rename {tools => src/Servers/Kestrel/tools}/CodeGenerator/HttpUtilities/HttpUtilitiesGeneratorHelpers.cs (100%) rename {tools => src/Servers/Kestrel/tools}/CodeGenerator/KnownHeaders.cs (100%) rename {tools => src/Servers/Kestrel/tools}/CodeGenerator/Program.cs (100%) rename {test => src/Servers/Kestrel}/xunit.runner.json (100%) rename {shared/Microsoft.Extensions.Buffers.Testing.Sources => src/Shared/Buffers.Testing}/BufferSegment.cs (100%) rename {shared/Microsoft.Extensions.Buffers.Testing.Sources => src/Shared/Buffers.Testing}/CustomMemoryForTest.cs (100%) rename {shared/Microsoft.Extensions.Buffers.Testing.Sources => src/Shared/Buffers.Testing}/ReadOnlySequenceFactory.cs (100%) delete mode 100644 test/Directory.Build.props delete mode 100644 test/Kestrel.Core.Tests/Kestrel.Core.Tests.csproj delete mode 100644 test/Kestrel.Tests/Kestrel.Tests.csproj delete mode 100644 test/Kestrel.Transport.Libuv.FunctionalTests/Kestrel.Transport.Libuv.FunctionalTests.csproj delete mode 100644 test/Kestrel.Transport.Libuv.Tests/Kestrel.Transport.Libuv.Tests.csproj delete mode 100644 test/Kestrel.Transport.Sockets.FunctionalTests/Kestrel.Transport.Sockets.FunctionalTests.csproj delete mode 100644 version.props diff --git a/.appveyor.yml b/.appveyor.yml deleted file mode 100644 index 1f412bf6b5..0000000000 --- a/.appveyor.yml +++ /dev/null @@ -1,13 +0,0 @@ -init: -- git config --global core.autocrlf true -branches: - only: - - dev - - /^release\/.*$/ - - /^(.*\/)?ci-.*$/ -build_script: -- ps: .\run.ps1 -ci default-build -clone_depth: 1 -test: 'off' -deploy: 'off' -os: Visual Studio 2017 diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index c2f0f84273..0000000000 --- a/.gitattributes +++ /dev/null @@ -1,52 +0,0 @@ -*.doc diff=astextplain -*.DOC diff=astextplain -*.docx diff=astextplain -*.DOCX diff=astextplain -*.dot diff=astextplain -*.DOT diff=astextplain -*.pdf diff=astextplain -*.PDF diff=astextplain -*.rtf diff=astextplain -*.RTF diff=astextplain - -*.jpg binary -*.png binary -*.gif binary - -*.cs text=auto diff=csharp -*.vb text=auto -*.resx text=auto -*.c text=auto -*.cpp text=auto -*.cxx text=auto -*.h text=auto -*.hxx text=auto -*.py text=auto -*.rb text=auto -*.java text=auto -*.html text=auto -*.htm text=auto -*.css text=auto -*.scss text=auto -*.sass text=auto -*.less text=auto -*.js text=auto -*.lisp text=auto -*.clj text=auto -*.sql text=auto -*.php text=auto -*.lua text=auto -*.m text=auto -*.asm text=auto -*.erl text=auto -*.fs text=auto -*.fsx text=auto -*.hs text=auto - -*.csproj text=auto -*.vbproj text=auto -*.fsproj text=auto -*.dbproj text=auto -*.sln text=auto eol=crlf - -*.sh eol=lf \ No newline at end of file diff --git a/.gitignore b/.gitignore deleted file mode 100644 index 708c4155fa..0000000000 --- a/.gitignore +++ /dev/null @@ -1,37 +0,0 @@ -[Oo]bj/ -[Bb]in/ -TestResults/ -.nuget/ -*.sln.ide/ -_ReSharper.*/ -.idea/ -packages/ -artifacts/ -PublishProfiles/ -.vs/ -*.user -*.suo -*.cache -*.docstates -_ReSharper.* -nuget.exe -*net45.csproj -*net451.csproj -*k10.csproj -*.psess -*.vsp -*.pidb -*.userprefs -*DS_Store -*.ncrunchsolution -*.*sdf -*.ipch -*.swp -*~ -.build/ -.testPublish/ -launchSettings.json -BenchmarkDotNet.Artifacts/ -BDN.Generated/ -binaries/ -global.json diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 3b3d7d726b..0000000000 --- a/.travis.yml +++ /dev/null @@ -1,27 +0,0 @@ -language: csharp -sudo: required -dist: trusty -services: -- docker -addons: - apt: - packages: - - libunwind8 -mono: none -os: -- linux -- osx -osx_image: xcode8.2 -branches: - only: - - dev - - /^release\/.*$/ - - /^(.*\/)?ci-.*$/ -before_install: -- if test "$TRAVIS_OS_NAME" == "osx"; then brew update; brew install openssl; ln -s - /usr/local/opt/openssl/lib/libcrypto.1.0.0.dylib /usr/local/lib/; ln -s /usr/local/opt/openssl/lib/libssl.1.0.0.dylib - /usr/local/lib/; fi -script: -- ./build.sh --ci -- if test "$TRAVIS_OS_NAME" != "osx"; then bash test/SystemdActivation/docker.sh; - fi diff --git a/.vscode/extensions.json b/.vscode/extensions.json deleted file mode 100644 index e69a4b3fda..0000000000 --- a/.vscode/extensions.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "recommendations": [ - "ms-vscode.csharp", - "EditorConfig.EditorConfig", - "k--kato.docomment", - "PeterJausovec.vscode-docker" - ] -} diff --git a/.vscode/launch.json b/.vscode/launch.json deleted file mode 100644 index db6faceb9c..0000000000 --- a/.vscode/launch.json +++ /dev/null @@ -1,103 +0,0 @@ -{ - "version": "0.2.0", - "configurations": [ - { - "name": "Attach: .NET Core", - "type": "coreclr", - "request": "attach", - "processId": "${command:pickProcess}" - }, - { - "name": "Attach: .NET Framework", - "type": "clr", - "request": "attach", - "processId": "${command:pickProcess}" - }, - { - "name": "Debug: TlsApp", - "type": "coreclr", - "request": "launch", - "program": "${workspaceRoot}/samples/TlsApp/bin/Debug/netcoreapp2.0/TlsApp.dll", - "cwd": "${workspaceRoot}/samples/TlsApp", - "console": "internalConsole", - "stopAtEntry": false, - "internalConsoleOptions": "openOnSessionStart", - "launchBrowser": { - "enabled": true, - "args": "https://127.0.0.1:5000", - "windows": { - "command": "cmd.exe", - "args": "/C start ${auto-detect-url}" - }, - "osx": { - "command": "open" - }, - "linux": { - "command": "xdg-open" - } - } - }, - { - "name": "Debug: SampleApp", - "type": "coreclr", - "request": "launch", - "preLaunchTask": "Compile: solution", - "program": "${workspaceRoot}/samples/SampleApp/bin/Debug/netcoreapp2.0/SampleApp.dll", - "cwd": "${workspaceRoot}/samples/SampleApp", - "console": "internalConsole", - "stopAtEntry": false, - "internalConsoleOptions": "openOnSessionStart", - "launchBrowser": { - "enabled": true, - "args": "${auto-detect-url}", - "windows": { - "command": "cmd.exe", - "args": "/C start ${auto-detect-url}" - }, - "osx": { - "command": "open" - }, - "linux": { - "command": "xdg-open" - } - } - }, - { - "name": "Debug: LargeResponseApp", - "type": "coreclr", - "request": "launch", - "preLaunchTask": "Compile: solution", - "program": "${workspaceRoot}/samples/LargeResponseApp/bin/Debug/netcoreapp2.0/LargeResponseApp.dll", - "cwd": "${workspaceRoot}/samples/LargeResponseApp", - "console": "internalConsole", - "stopAtEntry": false, - "internalConsoleOptions": "openOnSessionStart", - "launchBrowser": { - "enabled": true, - "args": "${auto-detect-url}", - "windows": { - "command": "cmd.exe", - "args": "/C start ${auto-detect-url}" - }, - "osx": { - "command": "open" - }, - "linux": { - "command": "xdg-open" - } - } - }, - { - "name": "Debug: CodeGenerator", - "type": "coreclr", - "request": "launch", - "preLaunchTask": "Compile: CodeGenerator", - "program": "${workspaceRoot}/tools/CodeGenerator/bin/Debug/netcoreapp2.0/CodeGenerator.dll", - "args": [], - "cwd": "${workspaceRoot}", - "console": "internalConsole", - "stopAtEntry": true, - "internalConsoleOptions": "openOnSessionStart" - } - ] -} diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index 0c60b84e84..0000000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "[json]": { - "editor.tabSize": 2 - }, - "files.trimTrailingWhitespace": true, - "files.associations": { - "*.props": "xml", - "*.targets": "xml" - } -} diff --git a/.vscode/tasks.json b/.vscode/tasks.json deleted file mode 100644 index 97f0b7ad07..0000000000 --- a/.vscode/tasks.json +++ /dev/null @@ -1,117 +0,0 @@ -{ - "version": "2.0.0", - "options": { - "env": { - "DOTNET_SKIP_FIRST_TIME_EXPERIENCE": "true" - } - }, - // requires that you first run build.cmd or build.sh to install local builds of dotnet - "windows": { - "command": "${env:USERPROFILE}/.dotnet/x64/dotnet.exe" - }, - "osx": { - "command": "${env:HOME}/.dotnet/dotnet" - }, - "linux": { - "command": "${env:HOME}/.dotnet/dotnet" - }, - "suppressTaskName": true, - "tasks": [ - { - "taskName": "Restore: solution", - "args": [ - "restore" - ] - }, - { - "taskName": "Compile: solution", - "group": { - "isDefault": true, - "kind": "build" - }, - "presentation": { - "panel": "dedicated" - }, - "args": [ - "build", - "${workspaceRoot}/KestrelHttpServer.sln", - "/p:GenerateFullPaths=true" - ], - "problemMatcher": "$msCompile", - // these have to defined here because of https://github.com/Microsoft/vscode/issues/20740 - "osx": { - "options": { - "env": { - // The location of .NET Framework reference assembiles. - // These may not be installed yet if you have not run build.sh. - "ReferenceAssemblyRoot": "${env:HOME}/.dotnet/buildtools/netfx/4.6.1/" - } - } - }, - "linux": { - "options": { - "env": { - "ReferenceAssemblyRoot": "${env:HOME}/.dotnet/buildtools/netfx/4.6.1/" - } - } - } - }, - { - "taskName": "Test", - "args": [ - "test", - "/p:GenerateFullPaths=true" - ], - "problemMatcher": "$msCompile", - "group": "test" - }, - { - "taskName": "Compile: CodeGenerator", - "args": [ - "build", - "/p:GenerateFullPaths=true" - ], - "options": { - "cwd": "${workspaceRoot}/tools/CodeGenerator/" - }, - "problemMatcher": "$msCompile" - }, - { - "taskName": "Run: CodeGenerator", - "args": [ - "run" - ], - "options": { - "cwd": "${workspaceRoot}/tools/CodeGenerator/" - } - }, - { - "taskName": "Run: resx generation", - "suppressTaskName": true, - "command": "build.cmd", - "args": [ - "/t:resx" - ], - "options": { - "cwd": "${workspaceRoot}" - }, - "osx": { - "command": "./build.sh" - }, - "linux": { - "command": "./build.sh" - } - }, - { - "taskName": "Run: Benchmarks", - "args": [ - "run", - "-c", - "Release" - ], - "options": { - "cwd": "${workspaceRoot}/test/Kestrel.Performance/" - } - } - ] -} diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md deleted file mode 100644 index 952d5b87f3..0000000000 --- a/CONTRIBUTING.md +++ /dev/null @@ -1,4 +0,0 @@ -Contributing -============ - -Information on contributing to this repo is in the [Contributing Guide](https://github.com/aspnet/Home/blob/dev/CONTRIBUTING.md) in the Home repo. diff --git a/Directory.Build.props b/Directory.Build.props deleted file mode 100644 index 170752b08d..0000000000 --- a/Directory.Build.props +++ /dev/null @@ -1,21 +0,0 @@ - - - - - - - - - Microsoft ASP.NET Core - https://github.com/aspnet/KestrelHttpServer - git - $(MSBuildThisFileDirectory) - $(MSBuildThisFileDirectory)build\Key.snk - true - true - true - latest - - diff --git a/Directory.Build.targets b/Directory.Build.targets deleted file mode 100644 index 53b3f6e1da..0000000000 --- a/Directory.Build.targets +++ /dev/null @@ -1,7 +0,0 @@ - - - $(MicrosoftNETCoreApp20PackageVersion) - $(MicrosoftNETCoreApp21PackageVersion) - $(NETStandardLibrary20PackageVersion) - - diff --git a/KestrelHttpServer.sln b/KestrelHttpServer.sln deleted file mode 100644 index 41323981f7..0000000000 --- a/KestrelHttpServer.sln +++ /dev/null @@ -1,412 +0,0 @@ -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 15 -VisualStudioVersion = 15.0.27130.2010 -MinimumVisualStudioVersion = 15.0.26730.03 -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{7972A5D6-3385-4127-9277-428506DD44FF}" - ProjectSection(SolutionItems) = preProject - .appveyor.yml = .appveyor.yml - .gitattributes = .gitattributes - .gitignore = .gitignore - .travis.yml = .travis.yml - build.cmd = build.cmd - build.ps1 = build.ps1 - build.sh = build.sh - CONTRIBUTING.md = CONTRIBUTING.md - Directory.Build.props = Directory.Build.props - Directory.Build.targets = Directory.Build.targets - LICENSE.txt = LICENSE.txt - NuGet.Config = NuGet.Config - NuGetPackageVerifier.json = NuGetPackageVerifier.json - README.md = README.md - ToProjectReferences.ps1 = ToProjectReferences.ps1 - version.xml = version.xml - EndProjectSection -EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{2D5D5227-4DBD-499A-96B1-76A36B03B750}" - ProjectSection(SolutionItems) = preProject - src\Directory.Build.props = src\Directory.Build.props - EndProjectSection -EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{D3273454-EA07-41D2-BF0B-FCC3675C2483}" - ProjectSection(SolutionItems) = preProject - test\Directory.Build.props = test\Directory.Build.props - test\xunit.runner.json = test\xunit.runner.json - EndProjectSection -EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "samples", "samples", "{8A3D00B8-1CCF-4BE6-A060-11104CE2D9CE}" -EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tools", "tools", "{327F7880-D9AF-46BD-B45C-3B7E34A01DFD}" -EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "shared", "shared", "{0EF2ACDF-012F-4472-A13A-4272419E2903}" - ProjectSection(SolutionItems) = preProject - test\shared\DummyApplication.cs = test\shared\DummyApplication.cs - test\shared\HttpParsingData.cs = test\shared\HttpParsingData.cs - test\shared\KestrelTestLoggerProvider.cs = test\shared\KestrelTestLoggerProvider.cs - test\shared\LifetimeNotImplemented.cs = test\shared\LifetimeNotImplemented.cs - test\shared\MockConnectionInformation.cs = test\shared\MockConnectionInformation.cs - test\shared\MockLogger.cs = test\shared\MockLogger.cs - test\shared\MockSystemClock.cs = test\shared\MockSystemClock.cs - test\shared\StringExtensions.cs = test\shared\StringExtensions.cs - test\shared\TestApp.cs = test\shared\TestApp.cs - test\shared\TestApplicationErrorLogger.cs = test\shared\TestApplicationErrorLogger.cs - test\shared\TestConnection.cs = test\shared\TestConnection.cs - test\shared\TestFrame.cs = test\shared\TestFrame.cs - test\shared\TestKestrelTrace.cs = test\shared\TestKestrelTrace.cs - test\shared\TestResources.cs = test\shared\TestResources.cs - test\shared\TestServiceContext.cs = test\shared\TestServiceContext.cs - EndProjectSection -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Kestrel.Core", "src\Kestrel.Core\Kestrel.Core.csproj", "{F510611A-3BEE-4B88-A613-5F4A74ED82A1}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Kestrel.Core.Tests", "test\Kestrel.Core.Tests\Kestrel.Core.Tests.csproj", "{37F3BFB2-6454-49E5-9D7F-581BF755CCFE}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SampleApp", "samples\SampleApp\SampleApp.csproj", "{2C3CB3DC-EEBF-4F52-9E1C-4F2F972E76C3}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LargeResponseApp", "samples\LargeResponseApp\LargeResponseApp.csproj", "{B35D4D31-E74C-4646-8A11-7A7A40F0021E}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CodeGenerator", "tools\CodeGenerator\CodeGenerator.csproj", "{BD2D4D29-1BD9-40D0-BB31-337D5416B63C}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Kestrel.Https", "src\Kestrel.Https\Kestrel.Https.csproj", "{5F64B3C3-0C2E-431A-B820-A81BBFC863DA}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Kestrel.Performance", "benchmarks\Kestrel.Performance\Kestrel.Performance.csproj", "{EBFE9719-A44B-4978-A71F-D5C254E7F35A}" -EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "TestCertificates", "TestCertificates", "{2822C132-BFFB-4D53-AC5B-E7E47DD81A6E}" - ProjectSection(SolutionItems) = preProject - test\shared\TestCertificates\eku.client.ini = test\shared\TestCertificates\eku.client.ini - test\shared\TestCertificates\eku.client.pfx = test\shared\TestCertificates\eku.client.pfx - test\shared\TestCertificates\eku.code_signing.ini = test\shared\TestCertificates\eku.code_signing.ini - test\shared\TestCertificates\eku.code_signing.pfx = test\shared\TestCertificates\eku.code_signing.pfx - test\shared\TestCertificates\eku.multiple_usages.ini = test\shared\TestCertificates\eku.multiple_usages.ini - test\shared\TestCertificates\eku.multiple_usages.pfx = test\shared\TestCertificates\eku.multiple_usages.pfx - test\shared\TestCertificates\eku.server.ini = test\shared\TestCertificates\eku.server.ini - test\shared\TestCertificates\eku.server.pfx = test\shared\TestCertificates\eku.server.pfx - test\shared\TestCertificates\make-test-certs.sh = test\shared\TestCertificates\make-test-certs.sh - test\shared\TestCertificates\no_extensions.ini = test\shared\TestCertificates\no_extensions.ini - test\shared\TestCertificates\no_extensions.pfx = test\shared\TestCertificates\no_extensions.pfx - test\shared\TestCertificates\testCert.pfx = test\shared\TestCertificates\testCert.pfx - EndProjectSection -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Kestrel.Transport.Libuv", "src\Kestrel.Transport.Libuv\Kestrel.Transport.Libuv.csproj", "{A76B8C8C-0DC5-4DD3-9B1F-02E51A0915F4}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Kestrel", "src\Kestrel\Kestrel.csproj", "{56139957-5C29-4E7D-89BD-7D20598B4EAF}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Kestrel.Transport.Sockets", "src\Kestrel.Transport.Sockets\Kestrel.Transport.Sockets.csproj", "{6950B18F-A3D2-41A4-AFEC-8B7C49517611}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Kestrel.Transport.Abstractions", "src\Kestrel.Transport.Abstractions\Kestrel.Transport.Abstractions.csproj", "{2E9CB89D-EC8F-4DD9-A72B-08D5BABF752D}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Kestrel.Transport.Libuv.Tests", "test\Kestrel.Transport.Libuv.Tests\Kestrel.Transport.Libuv.Tests.csproj", "{D95A7EC3-48AC-4D03-B2E2-0DA3E13BD3A4}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Kestrel.Tests", "test\Kestrel.Tests\Kestrel.Tests.csproj", "{4F1C30F8-CCAA-48D7-9DF6-2A84021F5BCC}" -EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "benchmarks", "benchmarks", "{A95C3BE1-B850-4265-97A0-777ADCCD437F}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Connections.Abstractions", "src\Connections.Abstractions\Connections.Abstractions.csproj", "{6956CF5C-3163-4398-8628-4ECA569245B5}" -EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "build", "build", "{C2910A13-B2C2-46D8-81D8-7E166F4F5981}" - ProjectSection(SolutionItems) = preProject - build\dependencies.props = build\dependencies.props - build\repo.props = build\repo.props - build\repo.targets = build\repo.targets - EndProjectSection -EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "SystemdActivation", "SystemdActivation", "{B7B0EA74-528F-46B8-9BC4-909D9A67C194}" - ProjectSection(SolutionItems) = preProject - test\SystemdActivation\docker-entrypoint.sh = test\SystemdActivation\docker-entrypoint.sh - test\SystemdActivation\docker.sh = test\SystemdActivation\docker.sh - test\SystemdActivation\Dockerfile = test\SystemdActivation\Dockerfile - EndProjectSection -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Kestrel.Transport.Libuv.FunctionalTests", "test\Kestrel.Transport.Libuv.FunctionalTests\Kestrel.Transport.Libuv.FunctionalTests.csproj", "{74032D79-8EA7-4483-BD82-C38370420FFF}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Kestrel.Transport.Sockets.FunctionalTests", "test\Kestrel.Transport.Sockets.FunctionalTests\Kestrel.Transport.Sockets.FunctionalTests.csproj", "{9C7B6B5F-088A-436E-834B-6373EA36DEEE}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Http2SampleApp", "samples\Http2SampleApp\Http2SampleApp.csproj", "{7BC22A4A-15D2-44C2-AB45-049F0FB562FA}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SystemdTestApp", "samples\SystemdTestApp\SystemdTestApp.csproj", "{A7994A41-CAF8-47A7-8975-F101F75B5BC1}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PlaintextApp", "samples\PlaintextApp\PlaintextApp.csproj", "{CE5523AE-6E38-4E20-998F-C64E02C5CC51}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PlatformBenchmarks", "benchmarkapps\PlatformBenchmarks\PlatformBenchmarks.csproj", "{7C24EAB8-57A9-4613-A8A6-4C21BB7D260D}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Debug|x64 = Debug|x64 - Debug|x86 = Debug|x86 - Release|Any CPU = Release|Any CPU - Release|x64 = Release|x64 - Release|x86 = Release|x86 - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {F510611A-3BEE-4B88-A613-5F4A74ED82A1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {F510611A-3BEE-4B88-A613-5F4A74ED82A1}.Debug|Any CPU.Build.0 = Debug|Any CPU - {F510611A-3BEE-4B88-A613-5F4A74ED82A1}.Debug|x64.ActiveCfg = Debug|Any CPU - {F510611A-3BEE-4B88-A613-5F4A74ED82A1}.Debug|x64.Build.0 = Debug|Any CPU - {F510611A-3BEE-4B88-A613-5F4A74ED82A1}.Debug|x86.ActiveCfg = Debug|Any CPU - {F510611A-3BEE-4B88-A613-5F4A74ED82A1}.Debug|x86.Build.0 = Debug|Any CPU - {F510611A-3BEE-4B88-A613-5F4A74ED82A1}.Release|Any CPU.ActiveCfg = Release|Any CPU - {F510611A-3BEE-4B88-A613-5F4A74ED82A1}.Release|Any CPU.Build.0 = Release|Any CPU - {F510611A-3BEE-4B88-A613-5F4A74ED82A1}.Release|x64.ActiveCfg = Release|Any CPU - {F510611A-3BEE-4B88-A613-5F4A74ED82A1}.Release|x64.Build.0 = Release|Any CPU - {F510611A-3BEE-4B88-A613-5F4A74ED82A1}.Release|x86.ActiveCfg = Release|Any CPU - {F510611A-3BEE-4B88-A613-5F4A74ED82A1}.Release|x86.Build.0 = Release|Any CPU - {37F3BFB2-6454-49E5-9D7F-581BF755CCFE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {37F3BFB2-6454-49E5-9D7F-581BF755CCFE}.Debug|Any CPU.Build.0 = Debug|Any CPU - {37F3BFB2-6454-49E5-9D7F-581BF755CCFE}.Debug|x64.ActiveCfg = Debug|Any CPU - {37F3BFB2-6454-49E5-9D7F-581BF755CCFE}.Debug|x64.Build.0 = Debug|Any CPU - {37F3BFB2-6454-49E5-9D7F-581BF755CCFE}.Debug|x86.ActiveCfg = Debug|Any CPU - {37F3BFB2-6454-49E5-9D7F-581BF755CCFE}.Debug|x86.Build.0 = Debug|Any CPU - {37F3BFB2-6454-49E5-9D7F-581BF755CCFE}.Release|Any CPU.ActiveCfg = Release|Any CPU - {37F3BFB2-6454-49E5-9D7F-581BF755CCFE}.Release|Any CPU.Build.0 = Release|Any CPU - {37F3BFB2-6454-49E5-9D7F-581BF755CCFE}.Release|x64.ActiveCfg = Release|Any CPU - {37F3BFB2-6454-49E5-9D7F-581BF755CCFE}.Release|x64.Build.0 = Release|Any CPU - {37F3BFB2-6454-49E5-9D7F-581BF755CCFE}.Release|x86.ActiveCfg = Release|Any CPU - {37F3BFB2-6454-49E5-9D7F-581BF755CCFE}.Release|x86.Build.0 = Release|Any CPU - {2C3CB3DC-EEBF-4F52-9E1C-4F2F972E76C3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {2C3CB3DC-EEBF-4F52-9E1C-4F2F972E76C3}.Debug|Any CPU.Build.0 = Debug|Any CPU - {2C3CB3DC-EEBF-4F52-9E1C-4F2F972E76C3}.Debug|x64.ActiveCfg = Debug|Any CPU - {2C3CB3DC-EEBF-4F52-9E1C-4F2F972E76C3}.Debug|x64.Build.0 = Debug|Any CPU - {2C3CB3DC-EEBF-4F52-9E1C-4F2F972E76C3}.Debug|x86.ActiveCfg = Debug|Any CPU - {2C3CB3DC-EEBF-4F52-9E1C-4F2F972E76C3}.Debug|x86.Build.0 = Debug|Any CPU - {2C3CB3DC-EEBF-4F52-9E1C-4F2F972E76C3}.Release|Any CPU.ActiveCfg = Release|Any CPU - {2C3CB3DC-EEBF-4F52-9E1C-4F2F972E76C3}.Release|Any CPU.Build.0 = Release|Any CPU - {2C3CB3DC-EEBF-4F52-9E1C-4F2F972E76C3}.Release|x64.ActiveCfg = Release|Any CPU - {2C3CB3DC-EEBF-4F52-9E1C-4F2F972E76C3}.Release|x64.Build.0 = Release|Any CPU - {2C3CB3DC-EEBF-4F52-9E1C-4F2F972E76C3}.Release|x86.ActiveCfg = Release|Any CPU - {2C3CB3DC-EEBF-4F52-9E1C-4F2F972E76C3}.Release|x86.Build.0 = Release|Any CPU - {B35D4D31-E74C-4646-8A11-7A7A40F0021E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {B35D4D31-E74C-4646-8A11-7A7A40F0021E}.Debug|Any CPU.Build.0 = Debug|Any CPU - {B35D4D31-E74C-4646-8A11-7A7A40F0021E}.Debug|x64.ActiveCfg = Debug|Any CPU - {B35D4D31-E74C-4646-8A11-7A7A40F0021E}.Debug|x64.Build.0 = Debug|Any CPU - {B35D4D31-E74C-4646-8A11-7A7A40F0021E}.Debug|x86.ActiveCfg = Debug|Any CPU - {B35D4D31-E74C-4646-8A11-7A7A40F0021E}.Debug|x86.Build.0 = Debug|Any CPU - {B35D4D31-E74C-4646-8A11-7A7A40F0021E}.Release|Any CPU.ActiveCfg = Release|Any CPU - {B35D4D31-E74C-4646-8A11-7A7A40F0021E}.Release|Any CPU.Build.0 = Release|Any CPU - {B35D4D31-E74C-4646-8A11-7A7A40F0021E}.Release|x64.ActiveCfg = Release|Any CPU - {B35D4D31-E74C-4646-8A11-7A7A40F0021E}.Release|x64.Build.0 = Release|Any CPU - {B35D4D31-E74C-4646-8A11-7A7A40F0021E}.Release|x86.ActiveCfg = Release|Any CPU - {B35D4D31-E74C-4646-8A11-7A7A40F0021E}.Release|x86.Build.0 = Release|Any CPU - {BD2D4D29-1BD9-40D0-BB31-337D5416B63C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {BD2D4D29-1BD9-40D0-BB31-337D5416B63C}.Debug|Any CPU.Build.0 = Debug|Any CPU - {BD2D4D29-1BD9-40D0-BB31-337D5416B63C}.Debug|x64.ActiveCfg = Debug|Any CPU - {BD2D4D29-1BD9-40D0-BB31-337D5416B63C}.Debug|x64.Build.0 = Debug|Any CPU - {BD2D4D29-1BD9-40D0-BB31-337D5416B63C}.Debug|x86.ActiveCfg = Debug|Any CPU - {BD2D4D29-1BD9-40D0-BB31-337D5416B63C}.Debug|x86.Build.0 = Debug|Any CPU - {BD2D4D29-1BD9-40D0-BB31-337D5416B63C}.Release|Any CPU.ActiveCfg = Release|Any CPU - {BD2D4D29-1BD9-40D0-BB31-337D5416B63C}.Release|Any CPU.Build.0 = Release|Any CPU - {BD2D4D29-1BD9-40D0-BB31-337D5416B63C}.Release|x64.ActiveCfg = Release|Any CPU - {BD2D4D29-1BD9-40D0-BB31-337D5416B63C}.Release|x64.Build.0 = Release|Any CPU - {BD2D4D29-1BD9-40D0-BB31-337D5416B63C}.Release|x86.ActiveCfg = Release|Any CPU - {BD2D4D29-1BD9-40D0-BB31-337D5416B63C}.Release|x86.Build.0 = Release|Any CPU - {5F64B3C3-0C2E-431A-B820-A81BBFC863DA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {5F64B3C3-0C2E-431A-B820-A81BBFC863DA}.Debug|Any CPU.Build.0 = Debug|Any CPU - {5F64B3C3-0C2E-431A-B820-A81BBFC863DA}.Debug|x64.ActiveCfg = Debug|Any CPU - {5F64B3C3-0C2E-431A-B820-A81BBFC863DA}.Debug|x64.Build.0 = Debug|Any CPU - {5F64B3C3-0C2E-431A-B820-A81BBFC863DA}.Debug|x86.ActiveCfg = Debug|Any CPU - {5F64B3C3-0C2E-431A-B820-A81BBFC863DA}.Debug|x86.Build.0 = Debug|Any CPU - {5F64B3C3-0C2E-431A-B820-A81BBFC863DA}.Release|Any CPU.ActiveCfg = Release|Any CPU - {5F64B3C3-0C2E-431A-B820-A81BBFC863DA}.Release|Any CPU.Build.0 = Release|Any CPU - {5F64B3C3-0C2E-431A-B820-A81BBFC863DA}.Release|x64.ActiveCfg = Release|Any CPU - {5F64B3C3-0C2E-431A-B820-A81BBFC863DA}.Release|x64.Build.0 = Release|Any CPU - {5F64B3C3-0C2E-431A-B820-A81BBFC863DA}.Release|x86.ActiveCfg = Release|Any CPU - {5F64B3C3-0C2E-431A-B820-A81BBFC863DA}.Release|x86.Build.0 = Release|Any CPU - {EBFE9719-A44B-4978-A71F-D5C254E7F35A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {EBFE9719-A44B-4978-A71F-D5C254E7F35A}.Debug|Any CPU.Build.0 = Debug|Any CPU - {EBFE9719-A44B-4978-A71F-D5C254E7F35A}.Debug|x64.ActiveCfg = Debug|Any CPU - {EBFE9719-A44B-4978-A71F-D5C254E7F35A}.Debug|x64.Build.0 = Debug|Any CPU - {EBFE9719-A44B-4978-A71F-D5C254E7F35A}.Debug|x86.ActiveCfg = Debug|Any CPU - {EBFE9719-A44B-4978-A71F-D5C254E7F35A}.Debug|x86.Build.0 = Debug|Any CPU - {EBFE9719-A44B-4978-A71F-D5C254E7F35A}.Release|Any CPU.ActiveCfg = Release|Any CPU - {EBFE9719-A44B-4978-A71F-D5C254E7F35A}.Release|Any CPU.Build.0 = Release|Any CPU - {EBFE9719-A44B-4978-A71F-D5C254E7F35A}.Release|x64.ActiveCfg = Release|Any CPU - {EBFE9719-A44B-4978-A71F-D5C254E7F35A}.Release|x64.Build.0 = Release|Any CPU - {EBFE9719-A44B-4978-A71F-D5C254E7F35A}.Release|x86.ActiveCfg = Release|Any CPU - {EBFE9719-A44B-4978-A71F-D5C254E7F35A}.Release|x86.Build.0 = Release|Any CPU - {A76B8C8C-0DC5-4DD3-9B1F-02E51A0915F4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {A76B8C8C-0DC5-4DD3-9B1F-02E51A0915F4}.Debug|Any CPU.Build.0 = Debug|Any CPU - {A76B8C8C-0DC5-4DD3-9B1F-02E51A0915F4}.Debug|x64.ActiveCfg = Debug|Any CPU - {A76B8C8C-0DC5-4DD3-9B1F-02E51A0915F4}.Debug|x64.Build.0 = Debug|Any CPU - {A76B8C8C-0DC5-4DD3-9B1F-02E51A0915F4}.Debug|x86.ActiveCfg = Debug|Any CPU - {A76B8C8C-0DC5-4DD3-9B1F-02E51A0915F4}.Debug|x86.Build.0 = Debug|Any CPU - {A76B8C8C-0DC5-4DD3-9B1F-02E51A0915F4}.Release|Any CPU.ActiveCfg = Release|Any CPU - {A76B8C8C-0DC5-4DD3-9B1F-02E51A0915F4}.Release|Any CPU.Build.0 = Release|Any CPU - {A76B8C8C-0DC5-4DD3-9B1F-02E51A0915F4}.Release|x64.ActiveCfg = Release|Any CPU - {A76B8C8C-0DC5-4DD3-9B1F-02E51A0915F4}.Release|x64.Build.0 = Release|Any CPU - {A76B8C8C-0DC5-4DD3-9B1F-02E51A0915F4}.Release|x86.ActiveCfg = Release|Any CPU - {A76B8C8C-0DC5-4DD3-9B1F-02E51A0915F4}.Release|x86.Build.0 = Release|Any CPU - {56139957-5C29-4E7D-89BD-7D20598B4EAF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {56139957-5C29-4E7D-89BD-7D20598B4EAF}.Debug|Any CPU.Build.0 = Debug|Any CPU - {56139957-5C29-4E7D-89BD-7D20598B4EAF}.Debug|x64.ActiveCfg = Debug|Any CPU - {56139957-5C29-4E7D-89BD-7D20598B4EAF}.Debug|x64.Build.0 = Debug|Any CPU - {56139957-5C29-4E7D-89BD-7D20598B4EAF}.Debug|x86.ActiveCfg = Debug|Any CPU - {56139957-5C29-4E7D-89BD-7D20598B4EAF}.Debug|x86.Build.0 = Debug|Any CPU - {56139957-5C29-4E7D-89BD-7D20598B4EAF}.Release|Any CPU.ActiveCfg = Release|Any CPU - {56139957-5C29-4E7D-89BD-7D20598B4EAF}.Release|Any CPU.Build.0 = Release|Any CPU - {56139957-5C29-4E7D-89BD-7D20598B4EAF}.Release|x64.ActiveCfg = Release|Any CPU - {56139957-5C29-4E7D-89BD-7D20598B4EAF}.Release|x64.Build.0 = Release|Any CPU - {56139957-5C29-4E7D-89BD-7D20598B4EAF}.Release|x86.ActiveCfg = Release|Any CPU - {56139957-5C29-4E7D-89BD-7D20598B4EAF}.Release|x86.Build.0 = Release|Any CPU - {6950B18F-A3D2-41A4-AFEC-8B7C49517611}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {6950B18F-A3D2-41A4-AFEC-8B7C49517611}.Debug|Any CPU.Build.0 = Debug|Any CPU - {6950B18F-A3D2-41A4-AFEC-8B7C49517611}.Debug|x64.ActiveCfg = Debug|Any CPU - {6950B18F-A3D2-41A4-AFEC-8B7C49517611}.Debug|x64.Build.0 = Debug|Any CPU - {6950B18F-A3D2-41A4-AFEC-8B7C49517611}.Debug|x86.ActiveCfg = Debug|Any CPU - {6950B18F-A3D2-41A4-AFEC-8B7C49517611}.Debug|x86.Build.0 = Debug|Any CPU - {6950B18F-A3D2-41A4-AFEC-8B7C49517611}.Release|Any CPU.ActiveCfg = Release|Any CPU - {6950B18F-A3D2-41A4-AFEC-8B7C49517611}.Release|Any CPU.Build.0 = Release|Any CPU - {6950B18F-A3D2-41A4-AFEC-8B7C49517611}.Release|x64.ActiveCfg = Release|Any CPU - {6950B18F-A3D2-41A4-AFEC-8B7C49517611}.Release|x64.Build.0 = Release|Any CPU - {6950B18F-A3D2-41A4-AFEC-8B7C49517611}.Release|x86.ActiveCfg = Release|Any CPU - {6950B18F-A3D2-41A4-AFEC-8B7C49517611}.Release|x86.Build.0 = Release|Any CPU - {2E9CB89D-EC8F-4DD9-A72B-08D5BABF752D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {2E9CB89D-EC8F-4DD9-A72B-08D5BABF752D}.Debug|Any CPU.Build.0 = Debug|Any CPU - {2E9CB89D-EC8F-4DD9-A72B-08D5BABF752D}.Debug|x64.ActiveCfg = Debug|Any CPU - {2E9CB89D-EC8F-4DD9-A72B-08D5BABF752D}.Debug|x64.Build.0 = Debug|Any CPU - {2E9CB89D-EC8F-4DD9-A72B-08D5BABF752D}.Debug|x86.ActiveCfg = Debug|Any CPU - {2E9CB89D-EC8F-4DD9-A72B-08D5BABF752D}.Debug|x86.Build.0 = Debug|Any CPU - {2E9CB89D-EC8F-4DD9-A72B-08D5BABF752D}.Release|Any CPU.ActiveCfg = Release|Any CPU - {2E9CB89D-EC8F-4DD9-A72B-08D5BABF752D}.Release|Any CPU.Build.0 = Release|Any CPU - {2E9CB89D-EC8F-4DD9-A72B-08D5BABF752D}.Release|x64.ActiveCfg = Release|Any CPU - {2E9CB89D-EC8F-4DD9-A72B-08D5BABF752D}.Release|x64.Build.0 = Release|Any CPU - {2E9CB89D-EC8F-4DD9-A72B-08D5BABF752D}.Release|x86.ActiveCfg = Release|Any CPU - {2E9CB89D-EC8F-4DD9-A72B-08D5BABF752D}.Release|x86.Build.0 = Release|Any CPU - {D95A7EC3-48AC-4D03-B2E2-0DA3E13BD3A4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {D95A7EC3-48AC-4D03-B2E2-0DA3E13BD3A4}.Debug|Any CPU.Build.0 = Debug|Any CPU - {D95A7EC3-48AC-4D03-B2E2-0DA3E13BD3A4}.Debug|x64.ActiveCfg = Debug|Any CPU - {D95A7EC3-48AC-4D03-B2E2-0DA3E13BD3A4}.Debug|x64.Build.0 = Debug|Any CPU - {D95A7EC3-48AC-4D03-B2E2-0DA3E13BD3A4}.Debug|x86.ActiveCfg = Debug|Any CPU - {D95A7EC3-48AC-4D03-B2E2-0DA3E13BD3A4}.Debug|x86.Build.0 = Debug|Any CPU - {D95A7EC3-48AC-4D03-B2E2-0DA3E13BD3A4}.Release|Any CPU.ActiveCfg = Release|Any CPU - {D95A7EC3-48AC-4D03-B2E2-0DA3E13BD3A4}.Release|Any CPU.Build.0 = Release|Any CPU - {D95A7EC3-48AC-4D03-B2E2-0DA3E13BD3A4}.Release|x64.ActiveCfg = Release|Any CPU - {D95A7EC3-48AC-4D03-B2E2-0DA3E13BD3A4}.Release|x64.Build.0 = Release|Any CPU - {D95A7EC3-48AC-4D03-B2E2-0DA3E13BD3A4}.Release|x86.ActiveCfg = Release|Any CPU - {D95A7EC3-48AC-4D03-B2E2-0DA3E13BD3A4}.Release|x86.Build.0 = Release|Any CPU - {4F1C30F8-CCAA-48D7-9DF6-2A84021F5BCC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {4F1C30F8-CCAA-48D7-9DF6-2A84021F5BCC}.Debug|Any CPU.Build.0 = Debug|Any CPU - {4F1C30F8-CCAA-48D7-9DF6-2A84021F5BCC}.Debug|x64.ActiveCfg = Debug|Any CPU - {4F1C30F8-CCAA-48D7-9DF6-2A84021F5BCC}.Debug|x64.Build.0 = Debug|Any CPU - {4F1C30F8-CCAA-48D7-9DF6-2A84021F5BCC}.Debug|x86.ActiveCfg = Debug|Any CPU - {4F1C30F8-CCAA-48D7-9DF6-2A84021F5BCC}.Debug|x86.Build.0 = Debug|Any CPU - {4F1C30F8-CCAA-48D7-9DF6-2A84021F5BCC}.Release|Any CPU.ActiveCfg = Release|Any CPU - {4F1C30F8-CCAA-48D7-9DF6-2A84021F5BCC}.Release|Any CPU.Build.0 = Release|Any CPU - {4F1C30F8-CCAA-48D7-9DF6-2A84021F5BCC}.Release|x64.ActiveCfg = Release|Any CPU - {4F1C30F8-CCAA-48D7-9DF6-2A84021F5BCC}.Release|x64.Build.0 = Release|Any CPU - {4F1C30F8-CCAA-48D7-9DF6-2A84021F5BCC}.Release|x86.ActiveCfg = Release|Any CPU - {4F1C30F8-CCAA-48D7-9DF6-2A84021F5BCC}.Release|x86.Build.0 = Release|Any CPU - {6956CF5C-3163-4398-8628-4ECA569245B5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {6956CF5C-3163-4398-8628-4ECA569245B5}.Debug|Any CPU.Build.0 = Debug|Any CPU - {6956CF5C-3163-4398-8628-4ECA569245B5}.Debug|x64.ActiveCfg = Debug|Any CPU - {6956CF5C-3163-4398-8628-4ECA569245B5}.Debug|x64.Build.0 = Debug|Any CPU - {6956CF5C-3163-4398-8628-4ECA569245B5}.Debug|x86.ActiveCfg = Debug|Any CPU - {6956CF5C-3163-4398-8628-4ECA569245B5}.Debug|x86.Build.0 = Debug|Any CPU - {6956CF5C-3163-4398-8628-4ECA569245B5}.Release|Any CPU.ActiveCfg = Release|Any CPU - {6956CF5C-3163-4398-8628-4ECA569245B5}.Release|Any CPU.Build.0 = Release|Any CPU - {6956CF5C-3163-4398-8628-4ECA569245B5}.Release|x64.ActiveCfg = Release|Any CPU - {6956CF5C-3163-4398-8628-4ECA569245B5}.Release|x64.Build.0 = Release|Any CPU - {6956CF5C-3163-4398-8628-4ECA569245B5}.Release|x86.ActiveCfg = Release|Any CPU - {6956CF5C-3163-4398-8628-4ECA569245B5}.Release|x86.Build.0 = Release|Any CPU - {74032D79-8EA7-4483-BD82-C38370420FFF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {74032D79-8EA7-4483-BD82-C38370420FFF}.Debug|Any CPU.Build.0 = Debug|Any CPU - {74032D79-8EA7-4483-BD82-C38370420FFF}.Debug|x64.ActiveCfg = Debug|Any CPU - {74032D79-8EA7-4483-BD82-C38370420FFF}.Debug|x64.Build.0 = Debug|Any CPU - {74032D79-8EA7-4483-BD82-C38370420FFF}.Debug|x86.ActiveCfg = Debug|Any CPU - {74032D79-8EA7-4483-BD82-C38370420FFF}.Debug|x86.Build.0 = Debug|Any CPU - {74032D79-8EA7-4483-BD82-C38370420FFF}.Release|Any CPU.ActiveCfg = Release|Any CPU - {74032D79-8EA7-4483-BD82-C38370420FFF}.Release|Any CPU.Build.0 = Release|Any CPU - {74032D79-8EA7-4483-BD82-C38370420FFF}.Release|x64.ActiveCfg = Release|Any CPU - {74032D79-8EA7-4483-BD82-C38370420FFF}.Release|x64.Build.0 = Release|Any CPU - {74032D79-8EA7-4483-BD82-C38370420FFF}.Release|x86.ActiveCfg = Release|Any CPU - {74032D79-8EA7-4483-BD82-C38370420FFF}.Release|x86.Build.0 = Release|Any CPU - {9C7B6B5F-088A-436E-834B-6373EA36DEEE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {9C7B6B5F-088A-436E-834B-6373EA36DEEE}.Debug|Any CPU.Build.0 = Debug|Any CPU - {9C7B6B5F-088A-436E-834B-6373EA36DEEE}.Debug|x64.ActiveCfg = Debug|Any CPU - {9C7B6B5F-088A-436E-834B-6373EA36DEEE}.Debug|x64.Build.0 = Debug|Any CPU - {9C7B6B5F-088A-436E-834B-6373EA36DEEE}.Debug|x86.ActiveCfg = Debug|Any CPU - {9C7B6B5F-088A-436E-834B-6373EA36DEEE}.Debug|x86.Build.0 = Debug|Any CPU - {9C7B6B5F-088A-436E-834B-6373EA36DEEE}.Release|Any CPU.ActiveCfg = Release|Any CPU - {9C7B6B5F-088A-436E-834B-6373EA36DEEE}.Release|Any CPU.Build.0 = Release|Any CPU - {9C7B6B5F-088A-436E-834B-6373EA36DEEE}.Release|x64.ActiveCfg = Release|Any CPU - {9C7B6B5F-088A-436E-834B-6373EA36DEEE}.Release|x64.Build.0 = Release|Any CPU - {9C7B6B5F-088A-436E-834B-6373EA36DEEE}.Release|x86.ActiveCfg = Release|Any CPU - {9C7B6B5F-088A-436E-834B-6373EA36DEEE}.Release|x86.Build.0 = Release|Any CPU - {7BC22A4A-15D2-44C2-AB45-049F0FB562FA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {7BC22A4A-15D2-44C2-AB45-049F0FB562FA}.Debug|Any CPU.Build.0 = Debug|Any CPU - {7BC22A4A-15D2-44C2-AB45-049F0FB562FA}.Debug|x64.ActiveCfg = Debug|Any CPU - {7BC22A4A-15D2-44C2-AB45-049F0FB562FA}.Debug|x64.Build.0 = Debug|Any CPU - {7BC22A4A-15D2-44C2-AB45-049F0FB562FA}.Debug|x86.ActiveCfg = Debug|Any CPU - {7BC22A4A-15D2-44C2-AB45-049F0FB562FA}.Debug|x86.Build.0 = Debug|Any CPU - {7BC22A4A-15D2-44C2-AB45-049F0FB562FA}.Release|Any CPU.ActiveCfg = Release|Any CPU - {7BC22A4A-15D2-44C2-AB45-049F0FB562FA}.Release|Any CPU.Build.0 = Release|Any CPU - {7BC22A4A-15D2-44C2-AB45-049F0FB562FA}.Release|x64.ActiveCfg = Release|Any CPU - {7BC22A4A-15D2-44C2-AB45-049F0FB562FA}.Release|x64.Build.0 = Release|Any CPU - {7BC22A4A-15D2-44C2-AB45-049F0FB562FA}.Release|x86.ActiveCfg = Release|Any CPU - {7BC22A4A-15D2-44C2-AB45-049F0FB562FA}.Release|x86.Build.0 = Release|Any CPU - {A7994A41-CAF8-47A7-8975-F101F75B5BC1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {A7994A41-CAF8-47A7-8975-F101F75B5BC1}.Debug|Any CPU.Build.0 = Debug|Any CPU - {A7994A41-CAF8-47A7-8975-F101F75B5BC1}.Debug|x64.ActiveCfg = Debug|Any CPU - {A7994A41-CAF8-47A7-8975-F101F75B5BC1}.Debug|x64.Build.0 = Debug|Any CPU - {A7994A41-CAF8-47A7-8975-F101F75B5BC1}.Debug|x86.ActiveCfg = Debug|Any CPU - {A7994A41-CAF8-47A7-8975-F101F75B5BC1}.Debug|x86.Build.0 = Debug|Any CPU - {A7994A41-CAF8-47A7-8975-F101F75B5BC1}.Release|Any CPU.ActiveCfg = Release|Any CPU - {A7994A41-CAF8-47A7-8975-F101F75B5BC1}.Release|Any CPU.Build.0 = Release|Any CPU - {A7994A41-CAF8-47A7-8975-F101F75B5BC1}.Release|x64.ActiveCfg = Release|Any CPU - {A7994A41-CAF8-47A7-8975-F101F75B5BC1}.Release|x64.Build.0 = Release|Any CPU - {A7994A41-CAF8-47A7-8975-F101F75B5BC1}.Release|x86.ActiveCfg = Release|Any CPU - {A7994A41-CAF8-47A7-8975-F101F75B5BC1}.Release|x86.Build.0 = Release|Any CPU - {CE5523AE-6E38-4E20-998F-C64E02C5CC51}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {CE5523AE-6E38-4E20-998F-C64E02C5CC51}.Debug|Any CPU.Build.0 = Debug|Any CPU - {CE5523AE-6E38-4E20-998F-C64E02C5CC51}.Debug|x64.ActiveCfg = Debug|Any CPU - {CE5523AE-6E38-4E20-998F-C64E02C5CC51}.Debug|x64.Build.0 = Debug|Any CPU - {CE5523AE-6E38-4E20-998F-C64E02C5CC51}.Debug|x86.ActiveCfg = Debug|Any CPU - {CE5523AE-6E38-4E20-998F-C64E02C5CC51}.Debug|x86.Build.0 = Debug|Any CPU - {CE5523AE-6E38-4E20-998F-C64E02C5CC51}.Release|Any CPU.ActiveCfg = Release|Any CPU - {CE5523AE-6E38-4E20-998F-C64E02C5CC51}.Release|Any CPU.Build.0 = Release|Any CPU - {CE5523AE-6E38-4E20-998F-C64E02C5CC51}.Release|x64.ActiveCfg = Release|Any CPU - {CE5523AE-6E38-4E20-998F-C64E02C5CC51}.Release|x64.Build.0 = Release|Any CPU - {CE5523AE-6E38-4E20-998F-C64E02C5CC51}.Release|x86.ActiveCfg = Release|Any CPU - {CE5523AE-6E38-4E20-998F-C64E02C5CC51}.Release|x86.Build.0 = Release|Any CPU - {7C24EAB8-57A9-4613-A8A6-4C21BB7D260D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {7C24EAB8-57A9-4613-A8A6-4C21BB7D260D}.Debug|Any CPU.Build.0 = Debug|Any CPU - {7C24EAB8-57A9-4613-A8A6-4C21BB7D260D}.Debug|x64.ActiveCfg = Debug|Any CPU - {7C24EAB8-57A9-4613-A8A6-4C21BB7D260D}.Debug|x64.Build.0 = Debug|Any CPU - {7C24EAB8-57A9-4613-A8A6-4C21BB7D260D}.Debug|x86.ActiveCfg = Debug|Any CPU - {7C24EAB8-57A9-4613-A8A6-4C21BB7D260D}.Debug|x86.Build.0 = Debug|Any CPU - {7C24EAB8-57A9-4613-A8A6-4C21BB7D260D}.Release|Any CPU.ActiveCfg = Release|Any CPU - {7C24EAB8-57A9-4613-A8A6-4C21BB7D260D}.Release|Any CPU.Build.0 = Release|Any CPU - {7C24EAB8-57A9-4613-A8A6-4C21BB7D260D}.Release|x64.ActiveCfg = Release|Any CPU - {7C24EAB8-57A9-4613-A8A6-4C21BB7D260D}.Release|x64.Build.0 = Release|Any CPU - {7C24EAB8-57A9-4613-A8A6-4C21BB7D260D}.Release|x86.ActiveCfg = Release|Any CPU - {7C24EAB8-57A9-4613-A8A6-4C21BB7D260D}.Release|x86.Build.0 = Release|Any CPU - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(NestedProjects) = preSolution - {F510611A-3BEE-4B88-A613-5F4A74ED82A1} = {2D5D5227-4DBD-499A-96B1-76A36B03B750} - {37F3BFB2-6454-49E5-9D7F-581BF755CCFE} = {D3273454-EA07-41D2-BF0B-FCC3675C2483} - {2C3CB3DC-EEBF-4F52-9E1C-4F2F972E76C3} = {8A3D00B8-1CCF-4BE6-A060-11104CE2D9CE} - {B35D4D31-E74C-4646-8A11-7A7A40F0021E} = {8A3D00B8-1CCF-4BE6-A060-11104CE2D9CE} - {BD2D4D29-1BD9-40D0-BB31-337D5416B63C} = {327F7880-D9AF-46BD-B45C-3B7E34A01DFD} - {5F64B3C3-0C2E-431A-B820-A81BBFC863DA} = {2D5D5227-4DBD-499A-96B1-76A36B03B750} - {EBFE9719-A44B-4978-A71F-D5C254E7F35A} = {A95C3BE1-B850-4265-97A0-777ADCCD437F} - {2822C132-BFFB-4D53-AC5B-E7E47DD81A6E} = {0EF2ACDF-012F-4472-A13A-4272419E2903} - {A76B8C8C-0DC5-4DD3-9B1F-02E51A0915F4} = {2D5D5227-4DBD-499A-96B1-76A36B03B750} - {56139957-5C29-4E7D-89BD-7D20598B4EAF} = {2D5D5227-4DBD-499A-96B1-76A36B03B750} - {6950B18F-A3D2-41A4-AFEC-8B7C49517611} = {2D5D5227-4DBD-499A-96B1-76A36B03B750} - {2E9CB89D-EC8F-4DD9-A72B-08D5BABF752D} = {2D5D5227-4DBD-499A-96B1-76A36B03B750} - {D95A7EC3-48AC-4D03-B2E2-0DA3E13BD3A4} = {D3273454-EA07-41D2-BF0B-FCC3675C2483} - {4F1C30F8-CCAA-48D7-9DF6-2A84021F5BCC} = {D3273454-EA07-41D2-BF0B-FCC3675C2483} - {6956CF5C-3163-4398-8628-4ECA569245B5} = {2D5D5227-4DBD-499A-96B1-76A36B03B750} - {B7B0EA74-528F-46B8-9BC4-909D9A67C194} = {D3273454-EA07-41D2-BF0B-FCC3675C2483} - {74032D79-8EA7-4483-BD82-C38370420FFF} = {D3273454-EA07-41D2-BF0B-FCC3675C2483} - {9C7B6B5F-088A-436E-834B-6373EA36DEEE} = {D3273454-EA07-41D2-BF0B-FCC3675C2483} - {7BC22A4A-15D2-44C2-AB45-049F0FB562FA} = {8A3D00B8-1CCF-4BE6-A060-11104CE2D9CE} - {A7994A41-CAF8-47A7-8975-F101F75B5BC1} = {8A3D00B8-1CCF-4BE6-A060-11104CE2D9CE} - {CE5523AE-6E38-4E20-998F-C64E02C5CC51} = {8A3D00B8-1CCF-4BE6-A060-11104CE2D9CE} - {7C24EAB8-57A9-4613-A8A6-4C21BB7D260D} = {A95C3BE1-B850-4265-97A0-777ADCCD437F} - EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {2D10D020-6770-47CA-BB8D-2C23FE3AE071} - EndGlobalSection -EndGlobal diff --git a/LICENSE.txt b/LICENSE.txt deleted file mode 100644 index 7b2956ecee..0000000000 --- a/LICENSE.txt +++ /dev/null @@ -1,14 +0,0 @@ -Copyright (c) .NET Foundation and Contributors - -All rights reserved. - -Licensed under the Apache License, Version 2.0 (the "License"); you may not use -this file except in compliance with the License. You may obtain a copy of the -License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software distributed -under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR -CONDITIONS OF ANY KIND, either express or implied. See the License for the -specific language governing permissions and limitations under the License. diff --git a/NuGet.config b/NuGet.config deleted file mode 100644 index e32bddfd51..0000000000 --- a/NuGet.config +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - diff --git a/NuGetPackageVerifier.json b/NuGetPackageVerifier.json deleted file mode 100644 index 4f55b78b16..0000000000 --- a/NuGetPackageVerifier.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "adx-nonshipping": { - "rules": [], - "packages": { - "Microsoft.Extensions.Buffers.Testing.Sources": {} - } - }, - "Default": { - "rules": [ - "DefaultCompositeRule" - ] - } -} diff --git a/README.md b/README.md deleted file mode 100644 index 85a0a73610..0000000000 --- a/README.md +++ /dev/null @@ -1,42 +0,0 @@ -KestrelHttpServer -================= - -[![Join the chat at https://gitter.im/aspnet/KestrelHttpServer](https://badges.gitter.im/aspnet/KestrelHttpServer.svg)](https://gitter.im/aspnet/KestrelHttpServer?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) - -[![Travis build status][travis-badge]](https://travis-ci.org/aspnet/KestrelHttpServer/branches) -[![AppVeyor build status][appveyor-badge]](https://ci.appveyor.com/project/aspnetci/KestrelHttpServer/branch/dev) - -[travis-badge]: https://img.shields.io/travis/aspnet/KestrelHttpServer.svg?label=travis-ci&branch=dev&style=flat-square -[appveyor-badge]: https://img.shields.io/appveyor/ci/aspnetci/KestrelHttpServer/dev.svg?label=appveyor&style=flat-square - -This repo contains a cross-platform web server for ASP.NET Core. - -This project is part of ASP.NET Core. You can find samples, documentation and getting started instructions for ASP.NET Core at the [Home](https://github.com/aspnet/home) repo. - -## Building from source - -To run a complete build on command line only, execute `build.cmd` or `build.sh` without arguments. See [developer documentation](https://github.com/aspnet/Home/wiki) for more details. - -## File logging for functional test - -Turn on file logging for Kestrel functional tests by specifying the environment variable ASPNETCORE_TEST_LOG_DIR to the log output directory. - -## Packages - -Kestrel is available as a NuGet package. - - Package name | Stable | Nightly (`dev` branch) ---------------------------------------------|---------------------------------------------|------------------------------------------ -`Microsoft.AspNetCore.Server.Kestrel` | [![NuGet][main-nuget-badge]][main-nuget] | [![MyGet][main-myget-badge]][main-myget] -`Microsoft.AspNetCore.Server.Kestrel.Https` | [![NuGet][https-nuget-badge]][https-nuget] | [![MyGet][https-myget-badge]][https-myget] - - -[main-nuget]: https://www.nuget.org/packages/Microsoft.AspNetCore.Server.Kestrel/ -[main-nuget-badge]: https://img.shields.io/nuget/v/Microsoft.AspNetCore.Server.Kestrel.svg?style=flat-square&label=nuget -[main-myget]: https://dotnet.myget.org/feed/aspnetcore-dev/package/nuget/Microsoft.AspNetCore.Server.Kestrel -[main-myget-badge]: https://img.shields.io/dotnet.myget/aspnetcore-dev/vpre/Microsoft.AspNetCore.Server.Kestrel.svg?style=flat-square&label=myget - -[https-nuget]: https://www.nuget.org/packages/Microsoft.AspNetCore.Server.Kestrel.Https/ -[https-nuget-badge]: https://img.shields.io/nuget/v/Microsoft.AspNetCore.Server.Kestrel.Https.svg?style=flat-square&label=nuget -[https-myget]: https://dotnet.myget.org/feed/aspnetcore-dev/package/nuget/Microsoft.AspNetCore.Server.Kestrel.Https -[https-myget-badge]: https://img.shields.io/dotnet.myget/aspnetcore-dev/vpre/Microsoft.AspNetCore.Server.Kestrel.Https.svg?style=flat-square&label=myget diff --git a/ToProjectReferences.ps1 b/ToProjectReferences.ps1 deleted file mode 100644 index 4273aff929..0000000000 --- a/ToProjectReferences.ps1 +++ /dev/null @@ -1,45 +0,0 @@ -param($references) -$ErrorActionPreference = "Stop"; - -function ToProjectName($file) -{ - return $file.Directory.Name; -} - -$projectreferences = ls (Join-Path $references *.csproj) -rec; - -$localprojects = ls -rec *.csproj; - -foreach ($project in $localprojects) -{ - Write-Host "Processing $project"; - - [Reflection.Assembly]::LoadWithPartialName("System.Xml.Linq") | Out-Null; - - $changed = $false - $xDoc = [System.Xml.Linq.XDocument]::Load($project, [System.Xml.Linq.LoadOptions]::PreserveWhitespace); - $endpoints = $xDoc.Descendants("PackageReference") | %{ - $packageName = $_.Attribute("Include").Value; - $replacementProject = $projectreferences | ? { - return (ToProjectName($_)) -eq $packageName - }; - - if ($replacementProject) - { - $changed = $true - Write-Host " Replacing $packageName with $($project.FullName)"; - $_.Name = "ProjectReference"; - $_.Attribute("Include").Value = $replacementProject.FullName; - } - }; - if ($changed) - { - $settings = New-Object System.Xml.XmlWriterSettings - $settings.OmitXmlDeclaration = $true; - $writer = [System.Xml.XmlWriter]::Create($project, $settings) - - $xDoc.Save($writer); - $writer.Dispose(); - } - -} \ No newline at end of file diff --git a/benchmarks/Kestrel.Performance/Kestrel.Performance.csproj b/benchmarks/Kestrel.Performance/Kestrel.Performance.csproj deleted file mode 100644 index 0fb7d5af0a..0000000000 --- a/benchmarks/Kestrel.Performance/Kestrel.Performance.csproj +++ /dev/null @@ -1,29 +0,0 @@ - - - - - Kestrel.Performance - Microsoft.AspNetCore.Server.Kestrel.Performance - netcoreapp2.0 - Exe - true - true - false - - - - - - - - - - - - - - - - - - diff --git a/build.cmd b/build.cmd deleted file mode 100644 index c0050bda12..0000000000 --- a/build.cmd +++ /dev/null @@ -1,2 +0,0 @@ -@ECHO OFF -PowerShell -NoProfile -NoLogo -ExecutionPolicy unrestricted -Command "[System.Threading.Thread]::CurrentThread.CurrentCulture = ''; [System.Threading.Thread]::CurrentThread.CurrentUICulture = '';& '%~dp0run.ps1' default-build %*; exit $LASTEXITCODE" diff --git a/build.sh b/build.sh deleted file mode 100755 index 98a4b22765..0000000000 --- a/build.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/usr/bin/env bash - -set -euo pipefail -DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" - -# Call "sync" between "chmod" and execution to prevent "text file busy" error in Docker (aufs) -chmod +x "$DIR/run.sh"; sync -"$DIR/run.sh" default-build "$@" diff --git a/build/Key.snk b/build/Key.snk deleted file mode 100644 index e10e4889c125d3120cd9e81582243d70f7cbb806..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 596 zcmV-a0;~N80ssI2Bme+XQ$aES1ONa50098=Iw=HCsnz~#iVhm& zj%TU(_THUee?3yHBjk$37ysB?i5#7WD$={H zV4B!OxRPrb|8)HPg~A}8P>^=#y<)56#=E&NzcjOtPK~<4n6GHt=K$ro*T(lhby_@U zEk(hLzk1H)0yXj{A_5>fk-TgNoP|q6(tP2xo8zt8i%212CWM#AeCd?`hS|4~L({h~Moo(~vy&3Z z1uI}`fd^*>o=rwbAGymj6RM^pZm(*Kfhs+Y1#`-2JPWZMK8@;ZWCk2+9bX4YP);~fj-BU*R zQPvWv$89!{Rl9wM+zR>_TSkn^voYxA?2G iKnV#iZ6Ah`K>b=@=IjYJXrxL124zR(38)nxe+&q_$QXwJ diff --git a/build/buildpipeline/linux.groovy b/build/buildpipeline/linux.groovy deleted file mode 100644 index 903f218bb8..0000000000 --- a/build/buildpipeline/linux.groovy +++ /dev/null @@ -1,10 +0,0 @@ -@Library('dotnet-ci') _ - -simpleNode('Ubuntu16.04', 'latest-or-auto-docker') { - stage ('Checking out source') { - checkout scm - } - stage ('Build') { - sh './build.sh --ci' - } -} diff --git a/build/buildpipeline/osx.groovy b/build/buildpipeline/osx.groovy deleted file mode 100644 index aaac63686b..0000000000 --- a/build/buildpipeline/osx.groovy +++ /dev/null @@ -1,10 +0,0 @@ -@Library('dotnet-ci') _ - -simpleNode('OSX10.12','latest') { - stage ('Checking out source') { - checkout scm - } - stage ('Build') { - sh './build.sh --ci' - } -} diff --git a/build/buildpipeline/pipeline.groovy b/build/buildpipeline/pipeline.groovy deleted file mode 100644 index e915cadae1..0000000000 --- a/build/buildpipeline/pipeline.groovy +++ /dev/null @@ -1,18 +0,0 @@ -import org.dotnet.ci.pipelines.Pipeline - -def windowsPipeline = Pipeline.createPipeline(this, 'build/buildpipeline/windows.groovy') -def linuxPipeline = Pipeline.createPipeline(this, 'build/buildpipeline/linux.groovy') -def osxPipeline = Pipeline.createPipeline(this, 'build/buildpipeline/osx.groovy') -String configuration = 'Release' -def parameters = [ - 'Configuration': configuration -] - -windowsPipeline.triggerPipelineOnEveryGithubPR("Windows ${configuration} x64 Build", parameters) -windowsPipeline.triggerPipelineOnGithubPush(parameters) - -linuxPipeline.triggerPipelineOnEveryGithubPR("Ubuntu 16.04 ${configuration} Build", parameters) -linuxPipeline.triggerPipelineOnGithubPush(parameters) - -osxPipeline.triggerPipelineOnEveryGithubPR("OSX 10.12 ${configuration} Build", parameters) -osxPipeline.triggerPipelineOnGithubPush(parameters) diff --git a/build/buildpipeline/windows.groovy b/build/buildpipeline/windows.groovy deleted file mode 100644 index 8d26f313d4..0000000000 --- a/build/buildpipeline/windows.groovy +++ /dev/null @@ -1,12 +0,0 @@ -@Library('dotnet-ci') _ - -// 'node' indicates to Jenkins that the enclosed block runs on a node that matches -// the label 'windows-with-vs' -simpleNode('Windows_NT','latest') { - stage ('Checking out source') { - checkout scm - } - stage ('Build') { - bat '.\\run.cmd -CI default-build' - } -} diff --git a/build/dependencies.props b/build/dependencies.props deleted file mode 100644 index b855ca56d0..0000000000 --- a/build/dependencies.props +++ /dev/null @@ -1,58 +0,0 @@ - - - $(MSBuildAllProjects);$(MSBuildThisFileFullPath) - - - - - - 0.10.13 - 2.1.3-rtm-15802 - 1.10.0 - 2.0.0 - 2.1.2 - 15.6.1 - 4.7.49 - 2.0.3 - 11.0.2 - 4.5.0 - 4.5.0 - 4.5.1 - 4.5.0 - 4.5.1 - 4.5.0 - 4.5.1 - 1.3.7 - 0.8.0 - 2.3.1 - 2.4.0-beta.1.build3945 - - - - - - - - 2.1.2 - 2.1.1 - 2.1.1 - 2.1.1 - 2.1.1 - 2.1.1 - 2.1.1 - 2.1.1 - 2.1.0 - 2.1.1 - 2.1.1 - 2.1.1 - 2.1.1 - 2.1.1 - 2.1.1 - 2.1.1 - 2.1.1 - 2.1.1 - 2.1.1 - 2.1.1 - 2.1.1 - - \ No newline at end of file diff --git a/build/repo.props b/build/repo.props deleted file mode 100644 index 413dd9dd05..0000000000 --- a/build/repo.props +++ /dev/null @@ -1,16 +0,0 @@ - - - - - true - - Internal.AspNetCore.Universe.Lineup - 2.1.0-rc1-* - https://dotnet.myget.org/F/aspnetcore-dev/api/v3/index.json - - - - - - - diff --git a/build/repo.targets b/build/repo.targets deleted file mode 100644 index 820bc06a7f..0000000000 --- a/build/repo.targets +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - - Build - - - - - - - - - - diff --git a/build/sources.props b/build/sources.props deleted file mode 100644 index fe324c40e3..0000000000 --- a/build/sources.props +++ /dev/null @@ -1,18 +0,0 @@ - - - - - $(DotNetRestoreSources) - - $(RestoreSources); - https://dotnet.myget.org/F/dotnet-core/api/v3/index.json; - https://dotnet.myget.org/F/aspnetcore-dev/api/v3/index.json; - https://dotnet.myget.org/F/aspnetcore-tools/api/v3/index.json; - https://dotnet.myget.org/F/roslyn/api/v3/index.json; - - - $(RestoreSources); - https://api.nuget.org/v3/index.json; - - - diff --git a/korebuild-lock.txt b/korebuild-lock.txt deleted file mode 100644 index 251c227c83..0000000000 --- a/korebuild-lock.txt +++ /dev/null @@ -1,2 +0,0 @@ -version:2.1.3-rtm-15802 -commithash:a7c08b45b440a7d2058a0aa1eaa3eb6ba811976a diff --git a/korebuild.json b/korebuild.json deleted file mode 100644 index 678d8bb948..0000000000 --- a/korebuild.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "$schema": "https://raw.githubusercontent.com/aspnet/BuildTools/release/2.1/tools/korebuild.schema.json", - "channel": "release/2.1" -} diff --git a/run.cmd b/run.cmd deleted file mode 100644 index d52d5c7e68..0000000000 --- a/run.cmd +++ /dev/null @@ -1,2 +0,0 @@ -@ECHO OFF -PowerShell -NoProfile -NoLogo -ExecutionPolicy unrestricted -Command "[System.Threading.Thread]::CurrentThread.CurrentCulture = ''; [System.Threading.Thread]::CurrentThread.CurrentUICulture = '';& '%~dp0run.ps1' %*; exit $LASTEXITCODE" diff --git a/run.ps1 b/run.ps1 deleted file mode 100644 index 96c6c54c69..0000000000 --- a/run.ps1 +++ /dev/null @@ -1,208 +0,0 @@ -#!/usr/bin/env powershell -#requires -version 4 - -<# -.SYNOPSIS -Executes KoreBuild commands. - -.DESCRIPTION -Downloads korebuild if required. Then executes the KoreBuild command. To see available commands, execute with `-Command help`. - -.PARAMETER Command -The KoreBuild command to run. - -.PARAMETER Path -The folder to build. Defaults to the folder containing this script. - -.PARAMETER Channel -The channel of KoreBuild to download. Overrides the value from the config file. - -.PARAMETER DotNetHome -The directory where .NET Core tools will be stored. - -.PARAMETER ToolsSource -The base url where build tools can be downloaded. Overrides the value from the config file. - -.PARAMETER Update -Updates KoreBuild to the latest version even if a lock file is present. - -.PARAMETER Reinstall -Re-installs KoreBuild - -.PARAMETER ConfigFile -The path to the configuration file that stores values. Defaults to korebuild.json. - -.PARAMETER ToolsSourceSuffix -The Suffix to append to the end of the ToolsSource. Useful for query strings in blob stores. - -.PARAMETER CI -Sets up CI specific settings and variables. - -.PARAMETER Arguments -Arguments to be passed to the command - -.NOTES -This function will create a file $PSScriptRoot/korebuild-lock.txt. This lock file can be committed to source, but does not have to be. -When the lockfile is not present, KoreBuild will create one using latest available version from $Channel. - -The $ConfigFile is expected to be an JSON file. It is optional, and the configuration values in it are optional as well. Any options set -in the file are overridden by command line parameters. - -.EXAMPLE -Example config file: -```json -{ - "$schema": "https://raw.githubusercontent.com/aspnet/BuildTools/dev/tools/korebuild.schema.json", - "channel": "dev", - "toolsSource": "https://aspnetcore.blob.core.windows.net/buildtools" -} -``` -#> -[CmdletBinding(PositionalBinding = $false)] -param( - [Parameter(Mandatory = $true, Position = 0)] - [string]$Command, - [string]$Path = $PSScriptRoot, - [Alias('c')] - [string]$Channel, - [Alias('d')] - [string]$DotNetHome, - [Alias('s')] - [string]$ToolsSource, - [Alias('u')] - [switch]$Update, - [switch]$Reinstall, - [string]$ToolsSourceSuffix, - [string]$ConfigFile = $null, - [switch]$CI, - [Parameter(ValueFromRemainingArguments = $true)] - [string[]]$Arguments -) - -Set-StrictMode -Version 2 -$ErrorActionPreference = 'Stop' - -# -# Functions -# - -function Get-KoreBuild { - - $lockFile = Join-Path $Path 'korebuild-lock.txt' - - if (!(Test-Path $lockFile) -or $Update) { - Get-RemoteFile "$ToolsSource/korebuild/channels/$Channel/latest.txt" $lockFile $ToolsSourceSuffix - } - - $version = Get-Content $lockFile | Where-Object { $_ -like 'version:*' } | Select-Object -first 1 - if (!$version) { - Write-Error "Failed to parse version from $lockFile. Expected a line that begins with 'version:'" - } - $version = $version.TrimStart('version:').Trim() - $korebuildPath = Join-Paths $DotNetHome ('buildtools', 'korebuild', $version) - - if ($Reinstall -and (Test-Path $korebuildPath)) { - Remove-Item -Force -Recurse $korebuildPath - } - - if (!(Test-Path $korebuildPath)) { - Write-Host -ForegroundColor Magenta "Downloading KoreBuild $version" - New-Item -ItemType Directory -Path $korebuildPath | Out-Null - $remotePath = "$ToolsSource/korebuild/artifacts/$version/korebuild.$version.zip" - - try { - $tmpfile = Join-Path ([IO.Path]::GetTempPath()) "KoreBuild-$([guid]::NewGuid()).zip" - Get-RemoteFile $remotePath $tmpfile $ToolsSourceSuffix - if (Get-Command -Name 'Expand-Archive' -ErrorAction Ignore) { - # Use built-in commands where possible as they are cross-plat compatible - Expand-Archive -Path $tmpfile -DestinationPath $korebuildPath - } - else { - # Fallback to old approach for old installations of PowerShell - Add-Type -AssemblyName System.IO.Compression.FileSystem - [System.IO.Compression.ZipFile]::ExtractToDirectory($tmpfile, $korebuildPath) - } - } - catch { - Remove-Item -Recurse -Force $korebuildPath -ErrorAction Ignore - throw - } - finally { - Remove-Item $tmpfile -ErrorAction Ignore - } - } - - return $korebuildPath -} - -function Join-Paths([string]$path, [string[]]$childPaths) { - $childPaths | ForEach-Object { $path = Join-Path $path $_ } - return $path -} - -function Get-RemoteFile([string]$RemotePath, [string]$LocalPath, [string]$RemoteSuffix) { - if ($RemotePath -notlike 'http*') { - Copy-Item $RemotePath $LocalPath - return - } - - $retries = 10 - while ($retries -gt 0) { - $retries -= 1 - try { - Invoke-WebRequest -UseBasicParsing -Uri $($RemotePath + $RemoteSuffix) -OutFile $LocalPath - return - } - catch { - Write-Verbose "Request failed. $retries retries remaining" - } - } - - Write-Error "Download failed: '$RemotePath'." -} - -# -# Main -# - -# Load configuration or set defaults - -$Path = Resolve-Path $Path -if (!$ConfigFile) { $ConfigFile = Join-Path $Path 'korebuild.json' } - -if (Test-Path $ConfigFile) { - try { - $config = Get-Content -Raw -Encoding UTF8 -Path $ConfigFile | ConvertFrom-Json - if ($config) { - if (!($Channel) -and (Get-Member -Name 'channel' -InputObject $config)) { [string] $Channel = $config.channel } - if (!($ToolsSource) -and (Get-Member -Name 'toolsSource' -InputObject $config)) { [string] $ToolsSource = $config.toolsSource} - } - } - catch { - Write-Warning "$ConfigFile could not be read. Its settings will be ignored." - Write-Warning $Error[0] - } -} - -if (!$DotNetHome) { - $DotNetHome = if ($env:DOTNET_HOME) { $env:DOTNET_HOME } ` - elseif ($env:USERPROFILE) { Join-Path $env:USERPROFILE '.dotnet'} ` - elseif ($env:HOME) {Join-Path $env:HOME '.dotnet'}` - else { Join-Path $PSScriptRoot '.dotnet'} -} - -if (!$Channel) { $Channel = 'dev' } -if (!$ToolsSource) { $ToolsSource = 'https://aspnetcore.blob.core.windows.net/buildtools' } - -# Execute - -$korebuildPath = Get-KoreBuild -Import-Module -Force -Scope Local (Join-Path $korebuildPath 'KoreBuild.psd1') - -try { - Set-KoreBuildSettings -ToolsSource $ToolsSource -DotNetHome $DotNetHome -RepoPath $Path -ConfigFile $ConfigFile -CI:$CI - Invoke-KoreBuildCommand $Command @Arguments -} -finally { - Remove-Module 'KoreBuild' -ErrorAction Ignore -} diff --git a/run.sh b/run.sh deleted file mode 100755 index 4606a42e78..0000000000 --- a/run.sh +++ /dev/null @@ -1,245 +0,0 @@ -#!/usr/bin/env bash - -set -euo pipefail - -# -# variables -# - -RESET="\033[0m" -RED="\033[0;31m" -YELLOW="\033[0;33m" -MAGENTA="\033[0;95m" -DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -[ -z "${DOTNET_HOME:-}" ] && DOTNET_HOME="$HOME/.dotnet" -verbose=false -update=false -reinstall=false -repo_path="$DIR" -channel='' -tools_source='' -tools_source_suffix='' -ci=false - -# -# Functions -# -__usage() { - echo "Usage: $(basename "${BASH_SOURCE[0]}") command [options] [[--] ...]" - echo "" - echo "Arguments:" - echo " command The command to be run." - echo " ... Arguments passed to the command. Variable number of arguments allowed." - echo "" - echo "Options:" - echo " --verbose Show verbose output." - echo " -c|--channel The channel of KoreBuild to download. Overrides the value from the config file.." - echo " --config-file The path to the configuration file that stores values. Defaults to korebuild.json." - echo " -d|--dotnet-home The directory where .NET Core tools will be stored. Defaults to '\$DOTNET_HOME' or '\$HOME/.dotnet." - echo " --path The directory to build. Defaults to the directory containing the script." - echo " -s|--tools-source|-ToolsSource The base url where build tools can be downloaded. Overrides the value from the config file." - echo " --tools-source-suffix|-ToolsSourceSuffix The suffix to append to tools-source. Useful for query strings." - echo " -u|--update Update to the latest KoreBuild even if the lock file is present." - echo " --reinstall Reinstall KoreBuild." - echo " --ci Apply CI specific settings and environment variables." - echo "" - echo "Description:" - echo " This function will create a file \$DIR/korebuild-lock.txt. This lock file can be committed to source, but does not have to be." - echo " When the lockfile is not present, KoreBuild will create one using latest available version from \$channel." - - if [[ "${1:-}" != '--no-exit' ]]; then - exit 2 - fi -} - -get_korebuild() { - local version - local lock_file="$repo_path/korebuild-lock.txt" - if [ ! -f "$lock_file" ] || [ "$update" = true ]; then - __get_remote_file "$tools_source/korebuild/channels/$channel/latest.txt" "$lock_file" "$tools_source_suffix" - fi - version="$(grep 'version:*' -m 1 "$lock_file")" - if [[ "$version" == '' ]]; then - __error "Failed to parse version from $lock_file. Expected a line that begins with 'version:'" - return 1 - fi - version="$(echo "${version#version:}" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')" - local korebuild_path="$DOTNET_HOME/buildtools/korebuild/$version" - - if [ "$reinstall" = true ] && [ -d "$korebuild_path" ]; then - rm -rf "$korebuild_path" - fi - - { - if [ ! -d "$korebuild_path" ]; then - mkdir -p "$korebuild_path" - local remote_path="$tools_source/korebuild/artifacts/$version/korebuild.$version.zip" - tmpfile="$(mktemp)" - echo -e "${MAGENTA}Downloading KoreBuild ${version}${RESET}" - if __get_remote_file "$remote_path" "$tmpfile" "$tools_source_suffix"; then - unzip -q -d "$korebuild_path" "$tmpfile" - fi - rm "$tmpfile" || true - fi - - source "$korebuild_path/KoreBuild.sh" - } || { - if [ -d "$korebuild_path" ]; then - echo "Cleaning up after failed installation" - rm -rf "$korebuild_path" || true - fi - return 1 - } -} - -__error() { - echo -e "${RED}error: $*${RESET}" 1>&2 -} - -__warn() { - echo -e "${YELLOW}warning: $*${RESET}" -} - -__machine_has() { - hash "$1" > /dev/null 2>&1 - return $? -} - -__get_remote_file() { - local remote_path=$1 - local local_path=$2 - local remote_path_suffix=$3 - - if [[ "$remote_path" != 'http'* ]]; then - cp "$remote_path" "$local_path" - return 0 - fi - - local failed=false - if __machine_has wget; then - wget --tries 10 --quiet -O "$local_path" "${remote_path}${remote_path_suffix}" || failed=true - else - failed=true - fi - - if [ "$failed" = true ] && __machine_has curl; then - failed=false - curl --retry 10 -sSL -f --create-dirs -o "$local_path" "${remote_path}${remote_path_suffix}" || failed=true - fi - - if [ "$failed" = true ]; then - __error "Download failed: $remote_path" 1>&2 - return 1 - fi -} - -# -# main -# - -command="${1:-}" -shift - -while [[ $# -gt 0 ]]; do - case $1 in - -\?|-h|--help) - __usage --no-exit - exit 0 - ;; - -c|--channel|-Channel) - shift - channel="${1:-}" - [ -z "$channel" ] && __usage - ;; - --config-file|-ConfigFile) - shift - config_file="${1:-}" - [ -z "$config_file" ] && __usage - if [ ! -f "$config_file" ]; then - __error "Invalid value for --config-file. $config_file does not exist." - exit 1 - fi - ;; - -d|--dotnet-home|-DotNetHome) - shift - DOTNET_HOME="${1:-}" - [ -z "$DOTNET_HOME" ] && __usage - ;; - --path|-Path) - shift - repo_path="${1:-}" - [ -z "$repo_path" ] && __usage - ;; - -s|--tools-source|-ToolsSource) - shift - tools_source="${1:-}" - [ -z "$tools_source" ] && __usage - ;; - --tools-source-suffix|-ToolsSourceSuffix) - shift - tools_source_suffix="${1:-}" - [ -z "$tools_source_suffix" ] && __usage - ;; - -u|--update|-Update) - update=true - ;; - --reinstall|-[Rr]einstall) - reinstall=true - ;; - --ci) - ci=true - ;; - --verbose|-Verbose) - verbose=true - ;; - --) - shift - break - ;; - *) - break - ;; - esac - shift -done - -if ! __machine_has unzip; then - __error 'Missing required command: unzip' - exit 1 -fi - -if ! __machine_has curl && ! __machine_has wget; then - __error 'Missing required command. Either wget or curl is required.' - exit 1 -fi - -[ -z "${config_file:-}" ] && config_file="$repo_path/korebuild.json" -if [ -f "$config_file" ]; then - if __machine_has jq ; then - if jq '.' "$config_file" >/dev/null ; then - config_channel="$(jq -r 'select(.channel!=null) | .channel' "$config_file")" - config_tools_source="$(jq -r 'select(.toolsSource!=null) | .toolsSource' "$config_file")" - else - __warn "$config_file is invalid JSON. Its settings will be ignored." - fi - elif __machine_has python ; then - if python -c "import json,codecs;obj=json.load(codecs.open('$config_file', 'r', 'utf-8-sig'))" >/dev/null ; then - config_channel="$(python -c "import json,codecs;obj=json.load(codecs.open('$config_file', 'r', 'utf-8-sig'));print(obj['channel'] if 'channel' in obj else '')")" - config_tools_source="$(python -c "import json,codecs;obj=json.load(codecs.open('$config_file', 'r', 'utf-8-sig'));print(obj['toolsSource'] if 'toolsSource' in obj else '')")" - else - __warn "$config_file is invalid JSON. Its settings will be ignored." - fi - else - __warn 'Missing required command: jq or pyton. Could not parse the JSON file. Its settings will be ignored.' - fi - - [ ! -z "${config_channel:-}" ] && channel="$config_channel" - [ ! -z "${config_tools_source:-}" ] && tools_source="$config_tools_source" -fi - -[ -z "$channel" ] && channel='dev' -[ -z "$tools_source" ] && tools_source='https://aspnetcore.blob.core.windows.net/buildtools' - -get_korebuild -set_korebuildsettings "$tools_source" "$DOTNET_HOME" "$repo_path" "$config_file" "$ci" -invoke_korebuild_command "$command" "$@" diff --git a/src/Connections.Abstractions/Connections.Abstractions.csproj b/src/Connections.Abstractions/Connections.Abstractions.csproj deleted file mode 100644 index 7ac34a26dd..0000000000 --- a/src/Connections.Abstractions/Connections.Abstractions.csproj +++ /dev/null @@ -1,19 +0,0 @@ - - - - Microsoft.AspNetCore.Connections.Abstractions - Microsoft.AspNetCore.Connections.Abstractions - Core components of ASP.NET Core networking protocol stack. - netstandard2.0 - true - aspnetcore - CS1591;$(NoWarn) - - - - - - - - - diff --git a/src/Directory.Build.props b/src/Directory.Build.props deleted file mode 100644 index 6b85b2cf04..0000000000 --- a/src/Directory.Build.props +++ /dev/null @@ -1,13 +0,0 @@ - - - - $(DefineConstants);INNER_LOOP - - - - - - - false - - diff --git a/src/Kestrel.Core/Kestrel.Core.csproj b/src/Kestrel.Core/Kestrel.Core.csproj deleted file mode 100644 index 8551a56002..0000000000 --- a/src/Kestrel.Core/Kestrel.Core.csproj +++ /dev/null @@ -1,43 +0,0 @@ - - - - Microsoft.AspNetCore.Server.Kestrel.Core - Microsoft.AspNetCore.Server.Kestrel.Core - Core components of ASP.NET Core Kestrel cross-platform web server. - netstandard2.0;netcoreapp2.1 - true - aspnetcore;kestrel - true - CS1591;$(NoWarn) - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/Kestrel.Transport.Libuv/Kestrel.Transport.Libuv.csproj b/src/Kestrel.Transport.Libuv/Kestrel.Transport.Libuv.csproj deleted file mode 100644 index bef2f77e60..0000000000 --- a/src/Kestrel.Transport.Libuv/Kestrel.Transport.Libuv.csproj +++ /dev/null @@ -1,25 +0,0 @@ - - - - Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv - Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv - Libuv transport for the ASP.NET Core Kestrel cross-platform web server. - netstandard2.0 - true - aspnetcore;kestrel - true - CS1591;$(NoWarn) - - - - - - - - - - - - - - diff --git a/src/Kestrel/Kestrel.csproj b/src/Kestrel/Kestrel.csproj deleted file mode 100644 index f097863086..0000000000 --- a/src/Kestrel/Kestrel.csproj +++ /dev/null @@ -1,23 +0,0 @@ - - - - Microsoft.AspNetCore.Server.Kestrel - Microsoft.AspNetCore.Server.Kestrel - ASP.NET Core Kestrel cross-platform web server. - netstandard2.0 - true - aspnetcore;kestrel - CS1591;$(NoWarn) - - - - - - - - - - - - - diff --git a/src/Connections.Abstractions/ConnectionBuilder.cs b/src/Servers/Connections.Abstractions/src/ConnectionBuilder.cs similarity index 100% rename from src/Connections.Abstractions/ConnectionBuilder.cs rename to src/Servers/Connections.Abstractions/src/ConnectionBuilder.cs diff --git a/src/Connections.Abstractions/ConnectionBuilderExtensions.cs b/src/Servers/Connections.Abstractions/src/ConnectionBuilderExtensions.cs similarity index 100% rename from src/Connections.Abstractions/ConnectionBuilderExtensions.cs rename to src/Servers/Connections.Abstractions/src/ConnectionBuilderExtensions.cs diff --git a/src/Connections.Abstractions/ConnectionContext.cs b/src/Servers/Connections.Abstractions/src/ConnectionContext.cs similarity index 100% rename from src/Connections.Abstractions/ConnectionContext.cs rename to src/Servers/Connections.Abstractions/src/ConnectionContext.cs diff --git a/src/Connections.Abstractions/ConnectionDelegate.cs b/src/Servers/Connections.Abstractions/src/ConnectionDelegate.cs similarity index 100% rename from src/Connections.Abstractions/ConnectionDelegate.cs rename to src/Servers/Connections.Abstractions/src/ConnectionDelegate.cs diff --git a/src/Connections.Abstractions/ConnectionHandler.cs b/src/Servers/Connections.Abstractions/src/ConnectionHandler.cs similarity index 100% rename from src/Connections.Abstractions/ConnectionHandler.cs rename to src/Servers/Connections.Abstractions/src/ConnectionHandler.cs diff --git a/src/Connections.Abstractions/ConnectionItems.cs b/src/Servers/Connections.Abstractions/src/ConnectionItems.cs similarity index 100% rename from src/Connections.Abstractions/ConnectionItems.cs rename to src/Servers/Connections.Abstractions/src/ConnectionItems.cs diff --git a/src/Connections.Abstractions/DefaultConnectionContext.cs b/src/Servers/Connections.Abstractions/src/DefaultConnectionContext.cs similarity index 100% rename from src/Connections.Abstractions/DefaultConnectionContext.cs rename to src/Servers/Connections.Abstractions/src/DefaultConnectionContext.cs diff --git a/src/Connections.Abstractions/Exceptions/AddressInUseException.cs b/src/Servers/Connections.Abstractions/src/Exceptions/AddressInUseException.cs similarity index 100% rename from src/Connections.Abstractions/Exceptions/AddressInUseException.cs rename to src/Servers/Connections.Abstractions/src/Exceptions/AddressInUseException.cs diff --git a/src/Connections.Abstractions/Exceptions/ConnectionAbortedException.cs b/src/Servers/Connections.Abstractions/src/Exceptions/ConnectionAbortedException.cs similarity index 100% rename from src/Connections.Abstractions/Exceptions/ConnectionAbortedException.cs rename to src/Servers/Connections.Abstractions/src/Exceptions/ConnectionAbortedException.cs diff --git a/src/Connections.Abstractions/Exceptions/ConnectionResetException.cs b/src/Servers/Connections.Abstractions/src/Exceptions/ConnectionResetException.cs similarity index 100% rename from src/Connections.Abstractions/Exceptions/ConnectionResetException.cs rename to src/Servers/Connections.Abstractions/src/Exceptions/ConnectionResetException.cs diff --git a/src/Connections.Abstractions/Features/IConnectionHeartbeatFeature.cs b/src/Servers/Connections.Abstractions/src/Features/IConnectionHeartbeatFeature.cs similarity index 100% rename from src/Connections.Abstractions/Features/IConnectionHeartbeatFeature.cs rename to src/Servers/Connections.Abstractions/src/Features/IConnectionHeartbeatFeature.cs diff --git a/src/Connections.Abstractions/Features/IConnectionIdFeature.cs b/src/Servers/Connections.Abstractions/src/Features/IConnectionIdFeature.cs similarity index 100% rename from src/Connections.Abstractions/Features/IConnectionIdFeature.cs rename to src/Servers/Connections.Abstractions/src/Features/IConnectionIdFeature.cs diff --git a/src/Connections.Abstractions/Features/IConnectionInherentKeepAliveFeature.cs b/src/Servers/Connections.Abstractions/src/Features/IConnectionInherentKeepAliveFeature.cs similarity index 100% rename from src/Connections.Abstractions/Features/IConnectionInherentKeepAliveFeature.cs rename to src/Servers/Connections.Abstractions/src/Features/IConnectionInherentKeepAliveFeature.cs diff --git a/src/Connections.Abstractions/Features/IConnectionItemsFeature.cs b/src/Servers/Connections.Abstractions/src/Features/IConnectionItemsFeature.cs similarity index 100% rename from src/Connections.Abstractions/Features/IConnectionItemsFeature.cs rename to src/Servers/Connections.Abstractions/src/Features/IConnectionItemsFeature.cs diff --git a/src/Connections.Abstractions/Features/IConnectionLifetimeFeature.cs b/src/Servers/Connections.Abstractions/src/Features/IConnectionLifetimeFeature.cs similarity index 100% rename from src/Connections.Abstractions/Features/IConnectionLifetimeFeature.cs rename to src/Servers/Connections.Abstractions/src/Features/IConnectionLifetimeFeature.cs diff --git a/src/Connections.Abstractions/Features/IConnectionTransportFeature.cs b/src/Servers/Connections.Abstractions/src/Features/IConnectionTransportFeature.cs similarity index 100% rename from src/Connections.Abstractions/Features/IConnectionTransportFeature.cs rename to src/Servers/Connections.Abstractions/src/Features/IConnectionTransportFeature.cs diff --git a/src/Connections.Abstractions/Features/IConnectionUserFeature.cs b/src/Servers/Connections.Abstractions/src/Features/IConnectionUserFeature.cs similarity index 100% rename from src/Connections.Abstractions/Features/IConnectionUserFeature.cs rename to src/Servers/Connections.Abstractions/src/Features/IConnectionUserFeature.cs diff --git a/src/Connections.Abstractions/Features/IMemoryPoolFeature.cs b/src/Servers/Connections.Abstractions/src/Features/IMemoryPoolFeature.cs similarity index 100% rename from src/Connections.Abstractions/Features/IMemoryPoolFeature.cs rename to src/Servers/Connections.Abstractions/src/Features/IMemoryPoolFeature.cs diff --git a/src/Connections.Abstractions/Features/ITransferFormatFeature.cs b/src/Servers/Connections.Abstractions/src/Features/ITransferFormatFeature.cs similarity index 100% rename from src/Connections.Abstractions/Features/ITransferFormatFeature.cs rename to src/Servers/Connections.Abstractions/src/Features/ITransferFormatFeature.cs diff --git a/src/Connections.Abstractions/IConnectionBuilder.cs b/src/Servers/Connections.Abstractions/src/IConnectionBuilder.cs similarity index 100% rename from src/Connections.Abstractions/IConnectionBuilder.cs rename to src/Servers/Connections.Abstractions/src/IConnectionBuilder.cs diff --git a/src/Servers/Connections.Abstractions/src/Microsoft.AspNetCore.Connections.Abstractions.csproj b/src/Servers/Connections.Abstractions/src/Microsoft.AspNetCore.Connections.Abstractions.csproj new file mode 100644 index 0000000000..5546aef7b8 --- /dev/null +++ b/src/Servers/Connections.Abstractions/src/Microsoft.AspNetCore.Connections.Abstractions.csproj @@ -0,0 +1,17 @@ + + + + Core components of ASP.NET Core networking protocol stack. + netstandard2.0 + true + aspnetcore + CS1591;$(NoWarn) + + + + + + + + + diff --git a/src/Connections.Abstractions/TransferFormat.cs b/src/Servers/Connections.Abstractions/src/TransferFormat.cs similarity index 100% rename from src/Connections.Abstractions/TransferFormat.cs rename to src/Servers/Connections.Abstractions/src/TransferFormat.cs diff --git a/src/Connections.Abstractions/baseline.netcore.json b/src/Servers/Connections.Abstractions/src/baseline.netcore.json similarity index 100% rename from src/Connections.Abstractions/baseline.netcore.json rename to src/Servers/Connections.Abstractions/src/baseline.netcore.json diff --git a/src/Servers/Directory.Build.props b/src/Servers/Directory.Build.props new file mode 100644 index 0000000000..6b35802689 --- /dev/null +++ b/src/Servers/Directory.Build.props @@ -0,0 +1,9 @@ + + + + + $(RepositoryRoot)obj\$(MSBuildProjectName)\ + $(RepositoryRoot)bin\$(MSBuildProjectName)\ + + + diff --git a/src/Kestrel.Core/Adapter/Internal/AdaptedPipeline.cs b/src/Servers/Kestrel/Core/src/Adapter/Internal/AdaptedPipeline.cs similarity index 100% rename from src/Kestrel.Core/Adapter/Internal/AdaptedPipeline.cs rename to src/Servers/Kestrel/Core/src/Adapter/Internal/AdaptedPipeline.cs diff --git a/src/Kestrel.Core/Adapter/Internal/ConnectionAdapterContext.cs b/src/Servers/Kestrel/Core/src/Adapter/Internal/ConnectionAdapterContext.cs similarity index 100% rename from src/Kestrel.Core/Adapter/Internal/ConnectionAdapterContext.cs rename to src/Servers/Kestrel/Core/src/Adapter/Internal/ConnectionAdapterContext.cs diff --git a/src/Kestrel.Core/Adapter/Internal/IAdaptedConnection.cs b/src/Servers/Kestrel/Core/src/Adapter/Internal/IAdaptedConnection.cs similarity index 100% rename from src/Kestrel.Core/Adapter/Internal/IAdaptedConnection.cs rename to src/Servers/Kestrel/Core/src/Adapter/Internal/IAdaptedConnection.cs diff --git a/src/Kestrel.Core/Adapter/Internal/IConnectionAdapter.cs b/src/Servers/Kestrel/Core/src/Adapter/Internal/IConnectionAdapter.cs similarity index 100% rename from src/Kestrel.Core/Adapter/Internal/IConnectionAdapter.cs rename to src/Servers/Kestrel/Core/src/Adapter/Internal/IConnectionAdapter.cs diff --git a/src/Kestrel.Core/Adapter/Internal/LoggingConnectionAdapter.cs b/src/Servers/Kestrel/Core/src/Adapter/Internal/LoggingConnectionAdapter.cs similarity index 100% rename from src/Kestrel.Core/Adapter/Internal/LoggingConnectionAdapter.cs rename to src/Servers/Kestrel/Core/src/Adapter/Internal/LoggingConnectionAdapter.cs diff --git a/src/Kestrel.Core/Adapter/Internal/LoggingStream.cs b/src/Servers/Kestrel/Core/src/Adapter/Internal/LoggingStream.cs similarity index 100% rename from src/Kestrel.Core/Adapter/Internal/LoggingStream.cs rename to src/Servers/Kestrel/Core/src/Adapter/Internal/LoggingStream.cs diff --git a/src/Kestrel.Core/Adapter/Internal/RawStream.cs b/src/Servers/Kestrel/Core/src/Adapter/Internal/RawStream.cs similarity index 100% rename from src/Kestrel.Core/Adapter/Internal/RawStream.cs rename to src/Servers/Kestrel/Core/src/Adapter/Internal/RawStream.cs diff --git a/src/Kestrel.Core/Adapter/ListenOptionsConnectionLoggingExtensions.cs b/src/Servers/Kestrel/Core/src/Adapter/ListenOptionsConnectionLoggingExtensions.cs similarity index 100% rename from src/Kestrel.Core/Adapter/ListenOptionsConnectionLoggingExtensions.cs rename to src/Servers/Kestrel/Core/src/Adapter/ListenOptionsConnectionLoggingExtensions.cs diff --git a/src/Kestrel.Core/AnyIPListenOptions.cs b/src/Servers/Kestrel/Core/src/AnyIPListenOptions.cs similarity index 100% rename from src/Kestrel.Core/AnyIPListenOptions.cs rename to src/Servers/Kestrel/Core/src/AnyIPListenOptions.cs diff --git a/src/Kestrel.Core/BadHttpRequestException.cs b/src/Servers/Kestrel/Core/src/BadHttpRequestException.cs similarity index 100% rename from src/Kestrel.Core/BadHttpRequestException.cs rename to src/Servers/Kestrel/Core/src/BadHttpRequestException.cs diff --git a/src/Kestrel.Core/ClientCertificateMode.cs b/src/Servers/Kestrel/Core/src/ClientCertificateMode.cs similarity index 100% rename from src/Kestrel.Core/ClientCertificateMode.cs rename to src/Servers/Kestrel/Core/src/ClientCertificateMode.cs diff --git a/src/Kestrel.Core/CoreStrings.resx b/src/Servers/Kestrel/Core/src/CoreStrings.resx similarity index 100% rename from src/Kestrel.Core/CoreStrings.resx rename to src/Servers/Kestrel/Core/src/CoreStrings.resx diff --git a/src/Kestrel.Core/EndpointConfiguration.cs b/src/Servers/Kestrel/Core/src/EndpointConfiguration.cs similarity index 100% rename from src/Kestrel.Core/EndpointConfiguration.cs rename to src/Servers/Kestrel/Core/src/EndpointConfiguration.cs diff --git a/src/Kestrel.Core/Features/IConnectionTimeoutFeature.cs b/src/Servers/Kestrel/Core/src/Features/IConnectionTimeoutFeature.cs similarity index 100% rename from src/Kestrel.Core/Features/IConnectionTimeoutFeature.cs rename to src/Servers/Kestrel/Core/src/Features/IConnectionTimeoutFeature.cs diff --git a/src/Kestrel.Core/Features/IDecrementConcurrentConnectionCountFeature.cs b/src/Servers/Kestrel/Core/src/Features/IDecrementConcurrentConnectionCountFeature.cs similarity index 100% rename from src/Kestrel.Core/Features/IDecrementConcurrentConnectionCountFeature.cs rename to src/Servers/Kestrel/Core/src/Features/IDecrementConcurrentConnectionCountFeature.cs diff --git a/src/Kestrel.Core/Features/IHttp2StreamIdFeature.cs b/src/Servers/Kestrel/Core/src/Features/IHttp2StreamIdFeature.cs similarity index 100% rename from src/Kestrel.Core/Features/IHttp2StreamIdFeature.cs rename to src/Servers/Kestrel/Core/src/Features/IHttp2StreamIdFeature.cs diff --git a/src/Kestrel.Core/Features/IHttpMinRequestBodyDataRateFeature.cs b/src/Servers/Kestrel/Core/src/Features/IHttpMinRequestBodyDataRateFeature.cs similarity index 100% rename from src/Kestrel.Core/Features/IHttpMinRequestBodyDataRateFeature.cs rename to src/Servers/Kestrel/Core/src/Features/IHttpMinRequestBodyDataRateFeature.cs diff --git a/src/Kestrel.Core/Features/IHttpMinResponseDataRateFeature.cs b/src/Servers/Kestrel/Core/src/Features/IHttpMinResponseDataRateFeature.cs similarity index 100% rename from src/Kestrel.Core/Features/IHttpMinResponseDataRateFeature.cs rename to src/Servers/Kestrel/Core/src/Features/IHttpMinResponseDataRateFeature.cs diff --git a/src/Kestrel.Core/Features/ITlsApplicationProtocolFeature.cs b/src/Servers/Kestrel/Core/src/Features/ITlsApplicationProtocolFeature.cs similarity index 100% rename from src/Kestrel.Core/Features/ITlsApplicationProtocolFeature.cs rename to src/Servers/Kestrel/Core/src/Features/ITlsApplicationProtocolFeature.cs diff --git a/src/Kestrel.Core/HttpProtocols.cs b/src/Servers/Kestrel/Core/src/HttpProtocols.cs similarity index 100% rename from src/Kestrel.Core/HttpProtocols.cs rename to src/Servers/Kestrel/Core/src/HttpProtocols.cs diff --git a/src/Kestrel.Core/HttpsConnectionAdapterOptions.cs b/src/Servers/Kestrel/Core/src/HttpsConnectionAdapterOptions.cs similarity index 100% rename from src/Kestrel.Core/HttpsConnectionAdapterOptions.cs rename to src/Servers/Kestrel/Core/src/HttpsConnectionAdapterOptions.cs diff --git a/src/Kestrel.Core/Internal/AddressBindContext.cs b/src/Servers/Kestrel/Core/src/Internal/AddressBindContext.cs similarity index 100% rename from src/Kestrel.Core/Internal/AddressBindContext.cs rename to src/Servers/Kestrel/Core/src/Internal/AddressBindContext.cs diff --git a/src/Kestrel.Core/Internal/AddressBinder.cs b/src/Servers/Kestrel/Core/src/Internal/AddressBinder.cs similarity index 100% rename from src/Kestrel.Core/Internal/AddressBinder.cs rename to src/Servers/Kestrel/Core/src/Internal/AddressBinder.cs diff --git a/src/Kestrel.Core/Internal/BufferReader.cs b/src/Servers/Kestrel/Core/src/Internal/BufferReader.cs similarity index 100% rename from src/Kestrel.Core/Internal/BufferReader.cs rename to src/Servers/Kestrel/Core/src/Internal/BufferReader.cs diff --git a/src/Kestrel.Core/Internal/BufferWriter.cs b/src/Servers/Kestrel/Core/src/Internal/BufferWriter.cs similarity index 100% rename from src/Kestrel.Core/Internal/BufferWriter.cs rename to src/Servers/Kestrel/Core/src/Internal/BufferWriter.cs diff --git a/src/Kestrel.Core/Internal/CertificateLoader.cs b/src/Servers/Kestrel/Core/src/Internal/CertificateLoader.cs similarity index 100% rename from src/Kestrel.Core/Internal/CertificateLoader.cs rename to src/Servers/Kestrel/Core/src/Internal/CertificateLoader.cs diff --git a/src/Kestrel.Core/Internal/ClosedStream.cs b/src/Servers/Kestrel/Core/src/Internal/ClosedStream.cs similarity index 100% rename from src/Kestrel.Core/Internal/ClosedStream.cs rename to src/Servers/Kestrel/Core/src/Internal/ClosedStream.cs diff --git a/src/Kestrel.Core/Internal/ConfigurationReader.cs b/src/Servers/Kestrel/Core/src/Internal/ConfigurationReader.cs similarity index 100% rename from src/Kestrel.Core/Internal/ConfigurationReader.cs rename to src/Servers/Kestrel/Core/src/Internal/ConfigurationReader.cs diff --git a/src/Kestrel.Core/Internal/ConnectionDispatcher.cs b/src/Servers/Kestrel/Core/src/Internal/ConnectionDispatcher.cs similarity index 100% rename from src/Kestrel.Core/Internal/ConnectionDispatcher.cs rename to src/Servers/Kestrel/Core/src/Internal/ConnectionDispatcher.cs diff --git a/src/Kestrel.Core/Internal/ConnectionLimitMiddleware.cs b/src/Servers/Kestrel/Core/src/Internal/ConnectionLimitMiddleware.cs similarity index 100% rename from src/Kestrel.Core/Internal/ConnectionLimitMiddleware.cs rename to src/Servers/Kestrel/Core/src/Internal/ConnectionLimitMiddleware.cs diff --git a/src/Kestrel.Core/Internal/ConnectionLogScope.cs b/src/Servers/Kestrel/Core/src/Internal/ConnectionLogScope.cs similarity index 100% rename from src/Kestrel.Core/Internal/ConnectionLogScope.cs rename to src/Servers/Kestrel/Core/src/Internal/ConnectionLogScope.cs diff --git a/src/Kestrel.Core/Internal/DuplexPipe.cs b/src/Servers/Kestrel/Core/src/Internal/DuplexPipe.cs similarity index 100% rename from src/Kestrel.Core/Internal/DuplexPipe.cs rename to src/Servers/Kestrel/Core/src/Internal/DuplexPipe.cs diff --git a/src/Kestrel.Core/Internal/Http/ChunkWriter.cs b/src/Servers/Kestrel/Core/src/Internal/Http/ChunkWriter.cs similarity index 100% rename from src/Kestrel.Core/Internal/Http/ChunkWriter.cs rename to src/Servers/Kestrel/Core/src/Internal/Http/ChunkWriter.cs diff --git a/src/Kestrel.Core/Internal/Http/ConnectionOptions.cs b/src/Servers/Kestrel/Core/src/Internal/Http/ConnectionOptions.cs similarity index 100% rename from src/Kestrel.Core/Internal/Http/ConnectionOptions.cs rename to src/Servers/Kestrel/Core/src/Internal/Http/ConnectionOptions.cs diff --git a/src/Kestrel.Core/Internal/Http/DateHeaderValueManager.cs b/src/Servers/Kestrel/Core/src/Internal/Http/DateHeaderValueManager.cs similarity index 100% rename from src/Kestrel.Core/Internal/Http/DateHeaderValueManager.cs rename to src/Servers/Kestrel/Core/src/Internal/Http/DateHeaderValueManager.cs diff --git a/src/Kestrel.Core/Internal/Http/Http1Connection.FeatureCollection.cs b/src/Servers/Kestrel/Core/src/Internal/Http/Http1Connection.FeatureCollection.cs similarity index 100% rename from src/Kestrel.Core/Internal/Http/Http1Connection.FeatureCollection.cs rename to src/Servers/Kestrel/Core/src/Internal/Http/Http1Connection.FeatureCollection.cs diff --git a/src/Kestrel.Core/Internal/Http/Http1Connection.cs b/src/Servers/Kestrel/Core/src/Internal/Http/Http1Connection.cs similarity index 100% rename from src/Kestrel.Core/Internal/Http/Http1Connection.cs rename to src/Servers/Kestrel/Core/src/Internal/Http/Http1Connection.cs diff --git a/src/Kestrel.Core/Internal/Http/Http1ConnectionContext.cs b/src/Servers/Kestrel/Core/src/Internal/Http/Http1ConnectionContext.cs similarity index 100% rename from src/Kestrel.Core/Internal/Http/Http1ConnectionContext.cs rename to src/Servers/Kestrel/Core/src/Internal/Http/Http1ConnectionContext.cs diff --git a/src/Kestrel.Core/Internal/Http/Http1MessageBody.cs b/src/Servers/Kestrel/Core/src/Internal/Http/Http1MessageBody.cs similarity index 100% rename from src/Kestrel.Core/Internal/Http/Http1MessageBody.cs rename to src/Servers/Kestrel/Core/src/Internal/Http/Http1MessageBody.cs diff --git a/src/Kestrel.Core/Internal/Http/Http1OutputProducer.cs b/src/Servers/Kestrel/Core/src/Internal/Http/Http1OutputProducer.cs similarity index 100% rename from src/Kestrel.Core/Internal/Http/Http1OutputProducer.cs rename to src/Servers/Kestrel/Core/src/Internal/Http/Http1OutputProducer.cs diff --git a/src/Kestrel.Core/Internal/Http/Http1ParsingHandler.cs b/src/Servers/Kestrel/Core/src/Internal/Http/Http1ParsingHandler.cs similarity index 100% rename from src/Kestrel.Core/Internal/Http/Http1ParsingHandler.cs rename to src/Servers/Kestrel/Core/src/Internal/Http/Http1ParsingHandler.cs diff --git a/src/Kestrel.Core/Internal/Http/HttpHeaders.Generated.cs b/src/Servers/Kestrel/Core/src/Internal/Http/HttpHeaders.Generated.cs similarity index 100% rename from src/Kestrel.Core/Internal/Http/HttpHeaders.Generated.cs rename to src/Servers/Kestrel/Core/src/Internal/Http/HttpHeaders.Generated.cs diff --git a/src/Kestrel.Core/Internal/Http/HttpHeaders.cs b/src/Servers/Kestrel/Core/src/Internal/Http/HttpHeaders.cs similarity index 100% rename from src/Kestrel.Core/Internal/Http/HttpHeaders.cs rename to src/Servers/Kestrel/Core/src/Internal/Http/HttpHeaders.cs diff --git a/src/Kestrel.Core/Internal/Http/HttpMethod.cs b/src/Servers/Kestrel/Core/src/Internal/Http/HttpMethod.cs similarity index 100% rename from src/Kestrel.Core/Internal/Http/HttpMethod.cs rename to src/Servers/Kestrel/Core/src/Internal/Http/HttpMethod.cs diff --git a/src/Kestrel.Core/Internal/Http/HttpParser.cs b/src/Servers/Kestrel/Core/src/Internal/Http/HttpParser.cs similarity index 100% rename from src/Kestrel.Core/Internal/Http/HttpParser.cs rename to src/Servers/Kestrel/Core/src/Internal/Http/HttpParser.cs diff --git a/src/Kestrel.Core/Internal/Http/HttpProtocol.FeatureCollection.cs b/src/Servers/Kestrel/Core/src/Internal/Http/HttpProtocol.FeatureCollection.cs similarity index 100% rename from src/Kestrel.Core/Internal/Http/HttpProtocol.FeatureCollection.cs rename to src/Servers/Kestrel/Core/src/Internal/Http/HttpProtocol.FeatureCollection.cs diff --git a/src/Kestrel.Core/Internal/Http/HttpProtocol.Generated.cs b/src/Servers/Kestrel/Core/src/Internal/Http/HttpProtocol.Generated.cs similarity index 100% rename from src/Kestrel.Core/Internal/Http/HttpProtocol.Generated.cs rename to src/Servers/Kestrel/Core/src/Internal/Http/HttpProtocol.Generated.cs diff --git a/src/Kestrel.Core/Internal/Http/HttpProtocol.cs b/src/Servers/Kestrel/Core/src/Internal/Http/HttpProtocol.cs similarity index 100% rename from src/Kestrel.Core/Internal/Http/HttpProtocol.cs rename to src/Servers/Kestrel/Core/src/Internal/Http/HttpProtocol.cs diff --git a/src/Kestrel.Core/Internal/Http/HttpRequestHeaders.cs b/src/Servers/Kestrel/Core/src/Internal/Http/HttpRequestHeaders.cs similarity index 100% rename from src/Kestrel.Core/Internal/Http/HttpRequestHeaders.cs rename to src/Servers/Kestrel/Core/src/Internal/Http/HttpRequestHeaders.cs diff --git a/src/Kestrel.Core/Internal/Http/HttpRequestStream.cs b/src/Servers/Kestrel/Core/src/Internal/Http/HttpRequestStream.cs similarity index 100% rename from src/Kestrel.Core/Internal/Http/HttpRequestStream.cs rename to src/Servers/Kestrel/Core/src/Internal/Http/HttpRequestStream.cs diff --git a/src/Kestrel.Core/Internal/Http/HttpRequestTargetForm.cs b/src/Servers/Kestrel/Core/src/Internal/Http/HttpRequestTargetForm.cs similarity index 100% rename from src/Kestrel.Core/Internal/Http/HttpRequestTargetForm.cs rename to src/Servers/Kestrel/Core/src/Internal/Http/HttpRequestTargetForm.cs diff --git a/src/Kestrel.Core/Internal/Http/HttpResponseHeaders.cs b/src/Servers/Kestrel/Core/src/Internal/Http/HttpResponseHeaders.cs similarity index 100% rename from src/Kestrel.Core/Internal/Http/HttpResponseHeaders.cs rename to src/Servers/Kestrel/Core/src/Internal/Http/HttpResponseHeaders.cs diff --git a/src/Kestrel.Core/Internal/Http/HttpResponseStream.cs b/src/Servers/Kestrel/Core/src/Internal/Http/HttpResponseStream.cs similarity index 100% rename from src/Kestrel.Core/Internal/Http/HttpResponseStream.cs rename to src/Servers/Kestrel/Core/src/Internal/Http/HttpResponseStream.cs diff --git a/src/Kestrel.Core/Internal/Http/HttpScheme.cs b/src/Servers/Kestrel/Core/src/Internal/Http/HttpScheme.cs similarity index 100% rename from src/Kestrel.Core/Internal/Http/HttpScheme.cs rename to src/Servers/Kestrel/Core/src/Internal/Http/HttpScheme.cs diff --git a/src/Kestrel.Core/Internal/Http/HttpStreamState.cs b/src/Servers/Kestrel/Core/src/Internal/Http/HttpStreamState.cs similarity index 100% rename from src/Kestrel.Core/Internal/Http/HttpStreamState.cs rename to src/Servers/Kestrel/Core/src/Internal/Http/HttpStreamState.cs diff --git a/src/Kestrel.Core/Internal/Http/HttpUpgradeStream.cs b/src/Servers/Kestrel/Core/src/Internal/Http/HttpUpgradeStream.cs similarity index 100% rename from src/Kestrel.Core/Internal/Http/HttpUpgradeStream.cs rename to src/Servers/Kestrel/Core/src/Internal/Http/HttpUpgradeStream.cs diff --git a/src/Kestrel.Core/Internal/Http/HttpVersion.cs b/src/Servers/Kestrel/Core/src/Internal/Http/HttpVersion.cs similarity index 100% rename from src/Kestrel.Core/Internal/Http/HttpVersion.cs rename to src/Servers/Kestrel/Core/src/Internal/Http/HttpVersion.cs diff --git a/src/Kestrel.Core/Internal/Http/IHttpHeadersHandler.cs b/src/Servers/Kestrel/Core/src/Internal/Http/IHttpHeadersHandler.cs similarity index 100% rename from src/Kestrel.Core/Internal/Http/IHttpHeadersHandler.cs rename to src/Servers/Kestrel/Core/src/Internal/Http/IHttpHeadersHandler.cs diff --git a/src/Kestrel.Core/Internal/Http/IHttpOutputProducer.cs b/src/Servers/Kestrel/Core/src/Internal/Http/IHttpOutputProducer.cs similarity index 100% rename from src/Kestrel.Core/Internal/Http/IHttpOutputProducer.cs rename to src/Servers/Kestrel/Core/src/Internal/Http/IHttpOutputProducer.cs diff --git a/src/Kestrel.Core/Internal/Http/IHttpParser.cs b/src/Servers/Kestrel/Core/src/Internal/Http/IHttpParser.cs similarity index 100% rename from src/Kestrel.Core/Internal/Http/IHttpParser.cs rename to src/Servers/Kestrel/Core/src/Internal/Http/IHttpParser.cs diff --git a/src/Kestrel.Core/Internal/Http/IHttpProtocolContext.cs b/src/Servers/Kestrel/Core/src/Internal/Http/IHttpProtocolContext.cs similarity index 100% rename from src/Kestrel.Core/Internal/Http/IHttpProtocolContext.cs rename to src/Servers/Kestrel/Core/src/Internal/Http/IHttpProtocolContext.cs diff --git a/src/Kestrel.Core/Internal/Http/IHttpRequestLineHandler.cs b/src/Servers/Kestrel/Core/src/Internal/Http/IHttpRequestLineHandler.cs similarity index 100% rename from src/Kestrel.Core/Internal/Http/IHttpRequestLineHandler.cs rename to src/Servers/Kestrel/Core/src/Internal/Http/IHttpRequestLineHandler.cs diff --git a/src/Kestrel.Core/Internal/Http/IHttpResponseControl.cs b/src/Servers/Kestrel/Core/src/Internal/Http/IHttpResponseControl.cs similarity index 100% rename from src/Kestrel.Core/Internal/Http/IHttpResponseControl.cs rename to src/Servers/Kestrel/Core/src/Internal/Http/IHttpResponseControl.cs diff --git a/src/Kestrel.Core/Internal/Http/MessageBody.cs b/src/Servers/Kestrel/Core/src/Internal/Http/MessageBody.cs similarity index 100% rename from src/Kestrel.Core/Internal/Http/MessageBody.cs rename to src/Servers/Kestrel/Core/src/Internal/Http/MessageBody.cs diff --git a/src/Kestrel.Core/Internal/Http/PathNormalizer.cs b/src/Servers/Kestrel/Core/src/Internal/Http/PathNormalizer.cs similarity index 100% rename from src/Kestrel.Core/Internal/Http/PathNormalizer.cs rename to src/Servers/Kestrel/Core/src/Internal/Http/PathNormalizer.cs diff --git a/src/Kestrel.Core/Internal/Http/PipelineExtensions.cs b/src/Servers/Kestrel/Core/src/Internal/Http/PipelineExtensions.cs similarity index 100% rename from src/Kestrel.Core/Internal/Http/PipelineExtensions.cs rename to src/Servers/Kestrel/Core/src/Internal/Http/PipelineExtensions.cs diff --git a/src/Kestrel.Core/Internal/Http/ProduceEndType.cs b/src/Servers/Kestrel/Core/src/Internal/Http/ProduceEndType.cs similarity index 100% rename from src/Kestrel.Core/Internal/Http/ProduceEndType.cs rename to src/Servers/Kestrel/Core/src/Internal/Http/ProduceEndType.cs diff --git a/src/Kestrel.Core/Internal/Http/ReasonPhrases.cs b/src/Servers/Kestrel/Core/src/Internal/Http/ReasonPhrases.cs similarity index 100% rename from src/Kestrel.Core/Internal/Http/ReasonPhrases.cs rename to src/Servers/Kestrel/Core/src/Internal/Http/ReasonPhrases.cs diff --git a/src/Kestrel.Core/Internal/Http/RequestProcessingStatus.cs b/src/Servers/Kestrel/Core/src/Internal/Http/RequestProcessingStatus.cs similarity index 100% rename from src/Kestrel.Core/Internal/Http/RequestProcessingStatus.cs rename to src/Servers/Kestrel/Core/src/Internal/Http/RequestProcessingStatus.cs diff --git a/src/Kestrel.Core/Internal/Http/RequestRejectionReason.cs b/src/Servers/Kestrel/Core/src/Internal/Http/RequestRejectionReason.cs similarity index 100% rename from src/Kestrel.Core/Internal/Http/RequestRejectionReason.cs rename to src/Servers/Kestrel/Core/src/Internal/Http/RequestRejectionReason.cs diff --git a/src/Kestrel.Core/Internal/Http/TransferCoding.cs b/src/Servers/Kestrel/Core/src/Internal/Http/TransferCoding.cs similarity index 100% rename from src/Kestrel.Core/Internal/Http/TransferCoding.cs rename to src/Servers/Kestrel/Core/src/Internal/Http/TransferCoding.cs diff --git a/src/Kestrel.Core/Internal/Http/UrlDecoder.cs b/src/Servers/Kestrel/Core/src/Internal/Http/UrlDecoder.cs similarity index 100% rename from src/Kestrel.Core/Internal/Http/UrlDecoder.cs rename to src/Servers/Kestrel/Core/src/Internal/Http/UrlDecoder.cs diff --git a/src/Kestrel.Core/Internal/Http2/HPack/DynamicTable.cs b/src/Servers/Kestrel/Core/src/Internal/Http2/HPack/DynamicTable.cs similarity index 100% rename from src/Kestrel.Core/Internal/Http2/HPack/DynamicTable.cs rename to src/Servers/Kestrel/Core/src/Internal/Http2/HPack/DynamicTable.cs diff --git a/src/Kestrel.Core/Internal/Http2/HPack/HPackDecoder.cs b/src/Servers/Kestrel/Core/src/Internal/Http2/HPack/HPackDecoder.cs similarity index 100% rename from src/Kestrel.Core/Internal/Http2/HPack/HPackDecoder.cs rename to src/Servers/Kestrel/Core/src/Internal/Http2/HPack/HPackDecoder.cs diff --git a/src/Kestrel.Core/Internal/Http2/HPack/HPackDecodingException.cs b/src/Servers/Kestrel/Core/src/Internal/Http2/HPack/HPackDecodingException.cs similarity index 100% rename from src/Kestrel.Core/Internal/Http2/HPack/HPackDecodingException.cs rename to src/Servers/Kestrel/Core/src/Internal/Http2/HPack/HPackDecodingException.cs diff --git a/src/Kestrel.Core/Internal/Http2/HPack/HPackEncoder.cs b/src/Servers/Kestrel/Core/src/Internal/Http2/HPack/HPackEncoder.cs similarity index 100% rename from src/Kestrel.Core/Internal/Http2/HPack/HPackEncoder.cs rename to src/Servers/Kestrel/Core/src/Internal/Http2/HPack/HPackEncoder.cs diff --git a/src/Kestrel.Core/Internal/Http2/HPack/HeaderField.cs b/src/Servers/Kestrel/Core/src/Internal/Http2/HPack/HeaderField.cs similarity index 100% rename from src/Kestrel.Core/Internal/Http2/HPack/HeaderField.cs rename to src/Servers/Kestrel/Core/src/Internal/Http2/HPack/HeaderField.cs diff --git a/src/Kestrel.Core/Internal/Http2/HPack/Huffman.cs b/src/Servers/Kestrel/Core/src/Internal/Http2/HPack/Huffman.cs similarity index 100% rename from src/Kestrel.Core/Internal/Http2/HPack/Huffman.cs rename to src/Servers/Kestrel/Core/src/Internal/Http2/HPack/Huffman.cs diff --git a/src/Kestrel.Core/Internal/Http2/HPack/HuffmanDecodingException.cs b/src/Servers/Kestrel/Core/src/Internal/Http2/HPack/HuffmanDecodingException.cs similarity index 100% rename from src/Kestrel.Core/Internal/Http2/HPack/HuffmanDecodingException.cs rename to src/Servers/Kestrel/Core/src/Internal/Http2/HPack/HuffmanDecodingException.cs diff --git a/src/Kestrel.Core/Internal/Http2/HPack/IntegerDecoder.cs b/src/Servers/Kestrel/Core/src/Internal/Http2/HPack/IntegerDecoder.cs similarity index 100% rename from src/Kestrel.Core/Internal/Http2/HPack/IntegerDecoder.cs rename to src/Servers/Kestrel/Core/src/Internal/Http2/HPack/IntegerDecoder.cs diff --git a/src/Kestrel.Core/Internal/Http2/HPack/IntegerEncoder.cs b/src/Servers/Kestrel/Core/src/Internal/Http2/HPack/IntegerEncoder.cs similarity index 100% rename from src/Kestrel.Core/Internal/Http2/HPack/IntegerEncoder.cs rename to src/Servers/Kestrel/Core/src/Internal/Http2/HPack/IntegerEncoder.cs diff --git a/src/Kestrel.Core/Internal/Http2/HPack/StaticTable.cs b/src/Servers/Kestrel/Core/src/Internal/Http2/HPack/StaticTable.cs similarity index 100% rename from src/Kestrel.Core/Internal/Http2/HPack/StaticTable.cs rename to src/Servers/Kestrel/Core/src/Internal/Http2/HPack/StaticTable.cs diff --git a/src/Kestrel.Core/Internal/Http2/HPack/StatusCodes.cs b/src/Servers/Kestrel/Core/src/Internal/Http2/HPack/StatusCodes.cs similarity index 100% rename from src/Kestrel.Core/Internal/Http2/HPack/StatusCodes.cs rename to src/Servers/Kestrel/Core/src/Internal/Http2/HPack/StatusCodes.cs diff --git a/src/Kestrel.Core/Internal/Http2/Http2Connection.cs b/src/Servers/Kestrel/Core/src/Internal/Http2/Http2Connection.cs similarity index 100% rename from src/Kestrel.Core/Internal/Http2/Http2Connection.cs rename to src/Servers/Kestrel/Core/src/Internal/Http2/Http2Connection.cs diff --git a/src/Kestrel.Core/Internal/Http2/Http2ConnectionContext.cs b/src/Servers/Kestrel/Core/src/Internal/Http2/Http2ConnectionContext.cs similarity index 100% rename from src/Kestrel.Core/Internal/Http2/Http2ConnectionContext.cs rename to src/Servers/Kestrel/Core/src/Internal/Http2/Http2ConnectionContext.cs diff --git a/src/Kestrel.Core/Internal/Http2/Http2ConnectionErrorException.cs b/src/Servers/Kestrel/Core/src/Internal/Http2/Http2ConnectionErrorException.cs similarity index 100% rename from src/Kestrel.Core/Internal/Http2/Http2ConnectionErrorException.cs rename to src/Servers/Kestrel/Core/src/Internal/Http2/Http2ConnectionErrorException.cs diff --git a/src/Kestrel.Core/Internal/Http2/Http2ContinuationFrameFlags.cs b/src/Servers/Kestrel/Core/src/Internal/Http2/Http2ContinuationFrameFlags.cs similarity index 100% rename from src/Kestrel.Core/Internal/Http2/Http2ContinuationFrameFlags.cs rename to src/Servers/Kestrel/Core/src/Internal/Http2/Http2ContinuationFrameFlags.cs diff --git a/src/Kestrel.Core/Internal/Http2/Http2DataFrameFlags.cs b/src/Servers/Kestrel/Core/src/Internal/Http2/Http2DataFrameFlags.cs similarity index 100% rename from src/Kestrel.Core/Internal/Http2/Http2DataFrameFlags.cs rename to src/Servers/Kestrel/Core/src/Internal/Http2/Http2DataFrameFlags.cs diff --git a/src/Kestrel.Core/Internal/Http2/Http2ErrorCode.cs b/src/Servers/Kestrel/Core/src/Internal/Http2/Http2ErrorCode.cs similarity index 100% rename from src/Kestrel.Core/Internal/Http2/Http2ErrorCode.cs rename to src/Servers/Kestrel/Core/src/Internal/Http2/Http2ErrorCode.cs diff --git a/src/Kestrel.Core/Internal/Http2/Http2Frame.Continuation.cs b/src/Servers/Kestrel/Core/src/Internal/Http2/Http2Frame.Continuation.cs similarity index 100% rename from src/Kestrel.Core/Internal/Http2/Http2Frame.Continuation.cs rename to src/Servers/Kestrel/Core/src/Internal/Http2/Http2Frame.Continuation.cs diff --git a/src/Kestrel.Core/Internal/Http2/Http2Frame.Data.cs b/src/Servers/Kestrel/Core/src/Internal/Http2/Http2Frame.Data.cs similarity index 100% rename from src/Kestrel.Core/Internal/Http2/Http2Frame.Data.cs rename to src/Servers/Kestrel/Core/src/Internal/Http2/Http2Frame.Data.cs diff --git a/src/Kestrel.Core/Internal/Http2/Http2Frame.GoAway.cs b/src/Servers/Kestrel/Core/src/Internal/Http2/Http2Frame.GoAway.cs similarity index 100% rename from src/Kestrel.Core/Internal/Http2/Http2Frame.GoAway.cs rename to src/Servers/Kestrel/Core/src/Internal/Http2/Http2Frame.GoAway.cs diff --git a/src/Kestrel.Core/Internal/Http2/Http2Frame.Headers.cs b/src/Servers/Kestrel/Core/src/Internal/Http2/Http2Frame.Headers.cs similarity index 100% rename from src/Kestrel.Core/Internal/Http2/Http2Frame.Headers.cs rename to src/Servers/Kestrel/Core/src/Internal/Http2/Http2Frame.Headers.cs diff --git a/src/Kestrel.Core/Internal/Http2/Http2Frame.Ping.cs b/src/Servers/Kestrel/Core/src/Internal/Http2/Http2Frame.Ping.cs similarity index 100% rename from src/Kestrel.Core/Internal/Http2/Http2Frame.Ping.cs rename to src/Servers/Kestrel/Core/src/Internal/Http2/Http2Frame.Ping.cs diff --git a/src/Kestrel.Core/Internal/Http2/Http2Frame.Priority.cs b/src/Servers/Kestrel/Core/src/Internal/Http2/Http2Frame.Priority.cs similarity index 100% rename from src/Kestrel.Core/Internal/Http2/Http2Frame.Priority.cs rename to src/Servers/Kestrel/Core/src/Internal/Http2/Http2Frame.Priority.cs diff --git a/src/Kestrel.Core/Internal/Http2/Http2Frame.RstStream.cs b/src/Servers/Kestrel/Core/src/Internal/Http2/Http2Frame.RstStream.cs similarity index 100% rename from src/Kestrel.Core/Internal/Http2/Http2Frame.RstStream.cs rename to src/Servers/Kestrel/Core/src/Internal/Http2/Http2Frame.RstStream.cs diff --git a/src/Kestrel.Core/Internal/Http2/Http2Frame.Settings.cs b/src/Servers/Kestrel/Core/src/Internal/Http2/Http2Frame.Settings.cs similarity index 100% rename from src/Kestrel.Core/Internal/Http2/Http2Frame.Settings.cs rename to src/Servers/Kestrel/Core/src/Internal/Http2/Http2Frame.Settings.cs diff --git a/src/Kestrel.Core/Internal/Http2/Http2Frame.WindowUpdate.cs b/src/Servers/Kestrel/Core/src/Internal/Http2/Http2Frame.WindowUpdate.cs similarity index 100% rename from src/Kestrel.Core/Internal/Http2/Http2Frame.WindowUpdate.cs rename to src/Servers/Kestrel/Core/src/Internal/Http2/Http2Frame.WindowUpdate.cs diff --git a/src/Kestrel.Core/Internal/Http2/Http2Frame.cs b/src/Servers/Kestrel/Core/src/Internal/Http2/Http2Frame.cs similarity index 100% rename from src/Kestrel.Core/Internal/Http2/Http2Frame.cs rename to src/Servers/Kestrel/Core/src/Internal/Http2/Http2Frame.cs diff --git a/src/Kestrel.Core/Internal/Http2/Http2FrameReader.cs b/src/Servers/Kestrel/Core/src/Internal/Http2/Http2FrameReader.cs similarity index 100% rename from src/Kestrel.Core/Internal/Http2/Http2FrameReader.cs rename to src/Servers/Kestrel/Core/src/Internal/Http2/Http2FrameReader.cs diff --git a/src/Kestrel.Core/Internal/Http2/Http2FrameType.cs b/src/Servers/Kestrel/Core/src/Internal/Http2/Http2FrameType.cs similarity index 100% rename from src/Kestrel.Core/Internal/Http2/Http2FrameType.cs rename to src/Servers/Kestrel/Core/src/Internal/Http2/Http2FrameType.cs diff --git a/src/Kestrel.Core/Internal/Http2/Http2FrameWriter.cs b/src/Servers/Kestrel/Core/src/Internal/Http2/Http2FrameWriter.cs similarity index 100% rename from src/Kestrel.Core/Internal/Http2/Http2FrameWriter.cs rename to src/Servers/Kestrel/Core/src/Internal/Http2/Http2FrameWriter.cs diff --git a/src/Kestrel.Core/Internal/Http2/Http2HeadersFrameFlags.cs b/src/Servers/Kestrel/Core/src/Internal/Http2/Http2HeadersFrameFlags.cs similarity index 100% rename from src/Kestrel.Core/Internal/Http2/Http2HeadersFrameFlags.cs rename to src/Servers/Kestrel/Core/src/Internal/Http2/Http2HeadersFrameFlags.cs diff --git a/src/Kestrel.Core/Internal/Http2/Http2MessageBody.cs b/src/Servers/Kestrel/Core/src/Internal/Http2/Http2MessageBody.cs similarity index 100% rename from src/Kestrel.Core/Internal/Http2/Http2MessageBody.cs rename to src/Servers/Kestrel/Core/src/Internal/Http2/Http2MessageBody.cs diff --git a/src/Kestrel.Core/Internal/Http2/Http2OutputProducer.cs b/src/Servers/Kestrel/Core/src/Internal/Http2/Http2OutputProducer.cs similarity index 100% rename from src/Kestrel.Core/Internal/Http2/Http2OutputProducer.cs rename to src/Servers/Kestrel/Core/src/Internal/Http2/Http2OutputProducer.cs diff --git a/src/Kestrel.Core/Internal/Http2/Http2PeerSetting.cs b/src/Servers/Kestrel/Core/src/Internal/Http2/Http2PeerSetting.cs similarity index 100% rename from src/Kestrel.Core/Internal/Http2/Http2PeerSetting.cs rename to src/Servers/Kestrel/Core/src/Internal/Http2/Http2PeerSetting.cs diff --git a/src/Kestrel.Core/Internal/Http2/Http2PeerSettings.cs b/src/Servers/Kestrel/Core/src/Internal/Http2/Http2PeerSettings.cs similarity index 100% rename from src/Kestrel.Core/Internal/Http2/Http2PeerSettings.cs rename to src/Servers/Kestrel/Core/src/Internal/Http2/Http2PeerSettings.cs diff --git a/src/Kestrel.Core/Internal/Http2/Http2PingFrameFlags.cs b/src/Servers/Kestrel/Core/src/Internal/Http2/Http2PingFrameFlags.cs similarity index 100% rename from src/Kestrel.Core/Internal/Http2/Http2PingFrameFlags.cs rename to src/Servers/Kestrel/Core/src/Internal/Http2/Http2PingFrameFlags.cs diff --git a/src/Kestrel.Core/Internal/Http2/Http2SettingsFrameFlags.cs b/src/Servers/Kestrel/Core/src/Internal/Http2/Http2SettingsFrameFlags.cs similarity index 100% rename from src/Kestrel.Core/Internal/Http2/Http2SettingsFrameFlags.cs rename to src/Servers/Kestrel/Core/src/Internal/Http2/Http2SettingsFrameFlags.cs diff --git a/src/Kestrel.Core/Internal/Http2/Http2SettingsParameter.cs b/src/Servers/Kestrel/Core/src/Internal/Http2/Http2SettingsParameter.cs similarity index 100% rename from src/Kestrel.Core/Internal/Http2/Http2SettingsParameter.cs rename to src/Servers/Kestrel/Core/src/Internal/Http2/Http2SettingsParameter.cs diff --git a/src/Kestrel.Core/Internal/Http2/Http2SettingsParameterOutOfRangeException.cs b/src/Servers/Kestrel/Core/src/Internal/Http2/Http2SettingsParameterOutOfRangeException.cs similarity index 100% rename from src/Kestrel.Core/Internal/Http2/Http2SettingsParameterOutOfRangeException.cs rename to src/Servers/Kestrel/Core/src/Internal/Http2/Http2SettingsParameterOutOfRangeException.cs diff --git a/src/Kestrel.Core/Internal/Http2/Http2Stream.FeatureCollection.cs b/src/Servers/Kestrel/Core/src/Internal/Http2/Http2Stream.FeatureCollection.cs similarity index 100% rename from src/Kestrel.Core/Internal/Http2/Http2Stream.FeatureCollection.cs rename to src/Servers/Kestrel/Core/src/Internal/Http2/Http2Stream.FeatureCollection.cs diff --git a/src/Kestrel.Core/Internal/Http2/Http2Stream.cs b/src/Servers/Kestrel/Core/src/Internal/Http2/Http2Stream.cs similarity index 100% rename from src/Kestrel.Core/Internal/Http2/Http2Stream.cs rename to src/Servers/Kestrel/Core/src/Internal/Http2/Http2Stream.cs diff --git a/src/Kestrel.Core/Internal/Http2/Http2StreamContext.cs b/src/Servers/Kestrel/Core/src/Internal/Http2/Http2StreamContext.cs similarity index 100% rename from src/Kestrel.Core/Internal/Http2/Http2StreamContext.cs rename to src/Servers/Kestrel/Core/src/Internal/Http2/Http2StreamContext.cs diff --git a/src/Kestrel.Core/Internal/Http2/Http2StreamErrorException.cs b/src/Servers/Kestrel/Core/src/Internal/Http2/Http2StreamErrorException.cs similarity index 100% rename from src/Kestrel.Core/Internal/Http2/Http2StreamErrorException.cs rename to src/Servers/Kestrel/Core/src/Internal/Http2/Http2StreamErrorException.cs diff --git a/src/Kestrel.Core/Internal/Http2/IHttp2FrameWriter.cs b/src/Servers/Kestrel/Core/src/Internal/Http2/IHttp2FrameWriter.cs similarity index 100% rename from src/Kestrel.Core/Internal/Http2/IHttp2FrameWriter.cs rename to src/Servers/Kestrel/Core/src/Internal/Http2/IHttp2FrameWriter.cs diff --git a/src/Kestrel.Core/Internal/Http2/IHttp2StreamLifetimeHandler.cs b/src/Servers/Kestrel/Core/src/Internal/Http2/IHttp2StreamLifetimeHandler.cs similarity index 100% rename from src/Kestrel.Core/Internal/Http2/IHttp2StreamLifetimeHandler.cs rename to src/Servers/Kestrel/Core/src/Internal/Http2/IHttp2StreamLifetimeHandler.cs diff --git a/src/Kestrel.Core/Internal/HttpConnection.cs b/src/Servers/Kestrel/Core/src/Internal/HttpConnection.cs similarity index 100% rename from src/Kestrel.Core/Internal/HttpConnection.cs rename to src/Servers/Kestrel/Core/src/Internal/HttpConnection.cs diff --git a/src/Kestrel.Core/Internal/HttpConnectionBuilderExtensions.cs b/src/Servers/Kestrel/Core/src/Internal/HttpConnectionBuilderExtensions.cs similarity index 100% rename from src/Kestrel.Core/Internal/HttpConnectionBuilderExtensions.cs rename to src/Servers/Kestrel/Core/src/Internal/HttpConnectionBuilderExtensions.cs diff --git a/src/Kestrel.Core/Internal/HttpConnectionContext.cs b/src/Servers/Kestrel/Core/src/Internal/HttpConnectionContext.cs similarity index 100% rename from src/Kestrel.Core/Internal/HttpConnectionContext.cs rename to src/Servers/Kestrel/Core/src/Internal/HttpConnectionContext.cs diff --git a/src/Kestrel.Core/Internal/HttpConnectionMiddleware.cs b/src/Servers/Kestrel/Core/src/Internal/HttpConnectionMiddleware.cs similarity index 100% rename from src/Kestrel.Core/Internal/HttpConnectionMiddleware.cs rename to src/Servers/Kestrel/Core/src/Internal/HttpConnectionMiddleware.cs diff --git a/src/Kestrel.Core/Internal/HttpsConnectionAdapter.cs b/src/Servers/Kestrel/Core/src/Internal/HttpsConnectionAdapter.cs similarity index 100% rename from src/Kestrel.Core/Internal/HttpsConnectionAdapter.cs rename to src/Servers/Kestrel/Core/src/Internal/HttpsConnectionAdapter.cs diff --git a/src/Kestrel.Core/Internal/IRequestProcessor.cs b/src/Servers/Kestrel/Core/src/Internal/IRequestProcessor.cs similarity index 100% rename from src/Kestrel.Core/Internal/IRequestProcessor.cs rename to src/Servers/Kestrel/Core/src/Internal/IRequestProcessor.cs diff --git a/src/Kestrel.Core/Internal/Infrastructure/CancellationTokenExtensions.cs b/src/Servers/Kestrel/Core/src/Internal/Infrastructure/CancellationTokenExtensions.cs similarity index 100% rename from src/Kestrel.Core/Internal/Infrastructure/CancellationTokenExtensions.cs rename to src/Servers/Kestrel/Core/src/Internal/Infrastructure/CancellationTokenExtensions.cs diff --git a/src/Kestrel.Core/Internal/Infrastructure/Constants.cs b/src/Servers/Kestrel/Core/src/Internal/Infrastructure/Constants.cs similarity index 100% rename from src/Kestrel.Core/Internal/Infrastructure/Constants.cs rename to src/Servers/Kestrel/Core/src/Internal/Infrastructure/Constants.cs diff --git a/src/Kestrel.Core/Internal/Infrastructure/CorrelationIdGenerator.cs b/src/Servers/Kestrel/Core/src/Internal/Infrastructure/CorrelationIdGenerator.cs similarity index 100% rename from src/Kestrel.Core/Internal/Infrastructure/CorrelationIdGenerator.cs rename to src/Servers/Kestrel/Core/src/Internal/Infrastructure/CorrelationIdGenerator.cs diff --git a/src/Kestrel.Core/Internal/Infrastructure/DebuggerWrapper.cs b/src/Servers/Kestrel/Core/src/Internal/Infrastructure/DebuggerWrapper.cs similarity index 100% rename from src/Kestrel.Core/Internal/Infrastructure/DebuggerWrapper.cs rename to src/Servers/Kestrel/Core/src/Internal/Infrastructure/DebuggerWrapper.cs diff --git a/src/Kestrel.Core/Internal/Infrastructure/Disposable.cs b/src/Servers/Kestrel/Core/src/Internal/Infrastructure/Disposable.cs similarity index 100% rename from src/Kestrel.Core/Internal/Infrastructure/Disposable.cs rename to src/Servers/Kestrel/Core/src/Internal/Infrastructure/Disposable.cs diff --git a/src/Kestrel.Core/Internal/Infrastructure/DisposableAction.cs b/src/Servers/Kestrel/Core/src/Internal/Infrastructure/DisposableAction.cs similarity index 100% rename from src/Kestrel.Core/Internal/Infrastructure/DisposableAction.cs rename to src/Servers/Kestrel/Core/src/Internal/Infrastructure/DisposableAction.cs diff --git a/src/Kestrel.Core/Internal/Infrastructure/Heartbeat.cs b/src/Servers/Kestrel/Core/src/Internal/Infrastructure/Heartbeat.cs similarity index 100% rename from src/Kestrel.Core/Internal/Infrastructure/Heartbeat.cs rename to src/Servers/Kestrel/Core/src/Internal/Infrastructure/Heartbeat.cs diff --git a/src/Kestrel.Core/Internal/Infrastructure/HttpConnectionManager.cs b/src/Servers/Kestrel/Core/src/Internal/Infrastructure/HttpConnectionManager.cs similarity index 100% rename from src/Kestrel.Core/Internal/Infrastructure/HttpConnectionManager.cs rename to src/Servers/Kestrel/Core/src/Internal/Infrastructure/HttpConnectionManager.cs diff --git a/src/Kestrel.Core/Internal/Infrastructure/HttpConnectionManagerShutdownExtensions.cs b/src/Servers/Kestrel/Core/src/Internal/Infrastructure/HttpConnectionManagerShutdownExtensions.cs similarity index 100% rename from src/Kestrel.Core/Internal/Infrastructure/HttpConnectionManagerShutdownExtensions.cs rename to src/Servers/Kestrel/Core/src/Internal/Infrastructure/HttpConnectionManagerShutdownExtensions.cs diff --git a/src/Kestrel.Core/Internal/Infrastructure/HttpConnectionReference.cs b/src/Servers/Kestrel/Core/src/Internal/Infrastructure/HttpConnectionReference.cs similarity index 100% rename from src/Kestrel.Core/Internal/Infrastructure/HttpConnectionReference.cs rename to src/Servers/Kestrel/Core/src/Internal/Infrastructure/HttpConnectionReference.cs diff --git a/src/Kestrel.Core/Internal/Infrastructure/HttpHeartbeatManager.cs b/src/Servers/Kestrel/Core/src/Internal/Infrastructure/HttpHeartbeatManager.cs similarity index 100% rename from src/Kestrel.Core/Internal/Infrastructure/HttpHeartbeatManager.cs rename to src/Servers/Kestrel/Core/src/Internal/Infrastructure/HttpHeartbeatManager.cs diff --git a/src/Kestrel.Core/Internal/Infrastructure/HttpUtilities.Generated.cs b/src/Servers/Kestrel/Core/src/Internal/Infrastructure/HttpUtilities.Generated.cs similarity index 100% rename from src/Kestrel.Core/Internal/Infrastructure/HttpUtilities.Generated.cs rename to src/Servers/Kestrel/Core/src/Internal/Infrastructure/HttpUtilities.Generated.cs diff --git a/src/Kestrel.Core/Internal/Infrastructure/HttpUtilities.cs b/src/Servers/Kestrel/Core/src/Internal/Infrastructure/HttpUtilities.cs similarity index 100% rename from src/Kestrel.Core/Internal/Infrastructure/HttpUtilities.cs rename to src/Servers/Kestrel/Core/src/Internal/Infrastructure/HttpUtilities.cs diff --git a/src/Kestrel.Core/Internal/Infrastructure/IDebugger.cs b/src/Servers/Kestrel/Core/src/Internal/Infrastructure/IDebugger.cs similarity index 100% rename from src/Kestrel.Core/Internal/Infrastructure/IDebugger.cs rename to src/Servers/Kestrel/Core/src/Internal/Infrastructure/IDebugger.cs diff --git a/src/Kestrel.Core/Internal/Infrastructure/IHeartbeatHandler.cs b/src/Servers/Kestrel/Core/src/Internal/Infrastructure/IHeartbeatHandler.cs similarity index 100% rename from src/Kestrel.Core/Internal/Infrastructure/IHeartbeatHandler.cs rename to src/Servers/Kestrel/Core/src/Internal/Infrastructure/IHeartbeatHandler.cs diff --git a/src/Kestrel.Core/Internal/Infrastructure/IKestrelTrace.cs b/src/Servers/Kestrel/Core/src/Internal/Infrastructure/IKestrelTrace.cs similarity index 100% rename from src/Kestrel.Core/Internal/Infrastructure/IKestrelTrace.cs rename to src/Servers/Kestrel/Core/src/Internal/Infrastructure/IKestrelTrace.cs diff --git a/src/Kestrel.Core/Internal/Infrastructure/ISystemClock.cs b/src/Servers/Kestrel/Core/src/Internal/Infrastructure/ISystemClock.cs similarity index 100% rename from src/Kestrel.Core/Internal/Infrastructure/ISystemClock.cs rename to src/Servers/Kestrel/Core/src/Internal/Infrastructure/ISystemClock.cs diff --git a/src/Kestrel.Core/Internal/Infrastructure/ITimeoutControl.cs b/src/Servers/Kestrel/Core/src/Internal/Infrastructure/ITimeoutControl.cs similarity index 100% rename from src/Kestrel.Core/Internal/Infrastructure/ITimeoutControl.cs rename to src/Servers/Kestrel/Core/src/Internal/Infrastructure/ITimeoutControl.cs diff --git a/src/Kestrel.Core/Internal/Infrastructure/KestrelEventSource.cs b/src/Servers/Kestrel/Core/src/Internal/Infrastructure/KestrelEventSource.cs similarity index 100% rename from src/Kestrel.Core/Internal/Infrastructure/KestrelEventSource.cs rename to src/Servers/Kestrel/Core/src/Internal/Infrastructure/KestrelEventSource.cs diff --git a/src/Kestrel.Core/Internal/Infrastructure/KestrelTrace.cs b/src/Servers/Kestrel/Core/src/Internal/Infrastructure/KestrelTrace.cs similarity index 100% rename from src/Kestrel.Core/Internal/Infrastructure/KestrelTrace.cs rename to src/Servers/Kestrel/Core/src/Internal/Infrastructure/KestrelTrace.cs diff --git a/src/Kestrel.Core/Internal/Infrastructure/ReadOnlyStream.cs b/src/Servers/Kestrel/Core/src/Internal/Infrastructure/ReadOnlyStream.cs similarity index 100% rename from src/Kestrel.Core/Internal/Infrastructure/ReadOnlyStream.cs rename to src/Servers/Kestrel/Core/src/Internal/Infrastructure/ReadOnlyStream.cs diff --git a/src/Kestrel.Core/Internal/Infrastructure/ResourceCounter.cs b/src/Servers/Kestrel/Core/src/Internal/Infrastructure/ResourceCounter.cs similarity index 100% rename from src/Kestrel.Core/Internal/Infrastructure/ResourceCounter.cs rename to src/Servers/Kestrel/Core/src/Internal/Infrastructure/ResourceCounter.cs diff --git a/src/Kestrel.Core/Internal/Infrastructure/StackTraceHiddenAttribute.cs b/src/Servers/Kestrel/Core/src/Internal/Infrastructure/StackTraceHiddenAttribute.cs similarity index 100% rename from src/Kestrel.Core/Internal/Infrastructure/StackTraceHiddenAttribute.cs rename to src/Servers/Kestrel/Core/src/Internal/Infrastructure/StackTraceHiddenAttribute.cs diff --git a/src/Kestrel.Core/Internal/Infrastructure/Streams.cs b/src/Servers/Kestrel/Core/src/Internal/Infrastructure/Streams.cs similarity index 100% rename from src/Kestrel.Core/Internal/Infrastructure/Streams.cs rename to src/Servers/Kestrel/Core/src/Internal/Infrastructure/Streams.cs diff --git a/src/Kestrel.Core/Internal/Infrastructure/StringUtilities.cs b/src/Servers/Kestrel/Core/src/Internal/Infrastructure/StringUtilities.cs similarity index 100% rename from src/Kestrel.Core/Internal/Infrastructure/StringUtilities.cs rename to src/Servers/Kestrel/Core/src/Internal/Infrastructure/StringUtilities.cs diff --git a/src/Kestrel.Core/Internal/Infrastructure/SystemClock.cs b/src/Servers/Kestrel/Core/src/Internal/Infrastructure/SystemClock.cs similarity index 100% rename from src/Kestrel.Core/Internal/Infrastructure/SystemClock.cs rename to src/Servers/Kestrel/Core/src/Internal/Infrastructure/SystemClock.cs diff --git a/src/Kestrel.Core/Internal/Infrastructure/ThrowingWriteOnlyStream.cs b/src/Servers/Kestrel/Core/src/Internal/Infrastructure/ThrowingWriteOnlyStream.cs similarity index 100% rename from src/Kestrel.Core/Internal/Infrastructure/ThrowingWriteOnlyStream.cs rename to src/Servers/Kestrel/Core/src/Internal/Infrastructure/ThrowingWriteOnlyStream.cs diff --git a/src/Kestrel.Core/Internal/Infrastructure/TimeoutAction.cs b/src/Servers/Kestrel/Core/src/Internal/Infrastructure/TimeoutAction.cs similarity index 100% rename from src/Kestrel.Core/Internal/Infrastructure/TimeoutAction.cs rename to src/Servers/Kestrel/Core/src/Internal/Infrastructure/TimeoutAction.cs diff --git a/src/Kestrel.Core/Internal/Infrastructure/UriUtilities.cs b/src/Servers/Kestrel/Core/src/Internal/Infrastructure/UriUtilities.cs similarity index 100% rename from src/Kestrel.Core/Internal/Infrastructure/UriUtilities.cs rename to src/Servers/Kestrel/Core/src/Internal/Infrastructure/UriUtilities.cs diff --git a/src/Kestrel.Core/Internal/Infrastructure/WrappingStream.cs b/src/Servers/Kestrel/Core/src/Internal/Infrastructure/WrappingStream.cs similarity index 100% rename from src/Kestrel.Core/Internal/Infrastructure/WrappingStream.cs rename to src/Servers/Kestrel/Core/src/Internal/Infrastructure/WrappingStream.cs diff --git a/src/Kestrel.Core/Internal/Infrastructure/WriteOnlyStream.cs b/src/Servers/Kestrel/Core/src/Internal/Infrastructure/WriteOnlyStream.cs similarity index 100% rename from src/Kestrel.Core/Internal/Infrastructure/WriteOnlyStream.cs rename to src/Servers/Kestrel/Core/src/Internal/Infrastructure/WriteOnlyStream.cs diff --git a/src/Kestrel.Core/Internal/KestrelServerOptionsSetup.cs b/src/Servers/Kestrel/Core/src/Internal/KestrelServerOptionsSetup.cs similarity index 100% rename from src/Kestrel.Core/Internal/KestrelServerOptionsSetup.cs rename to src/Servers/Kestrel/Core/src/Internal/KestrelServerOptionsSetup.cs diff --git a/src/Kestrel.Core/Internal/LoggerExtensions.cs b/src/Servers/Kestrel/Core/src/Internal/LoggerExtensions.cs similarity index 100% rename from src/Kestrel.Core/Internal/LoggerExtensions.cs rename to src/Servers/Kestrel/Core/src/Internal/LoggerExtensions.cs diff --git a/src/Kestrel.Core/Internal/ServerAddressesFeature.cs b/src/Servers/Kestrel/Core/src/Internal/ServerAddressesFeature.cs similarity index 100% rename from src/Kestrel.Core/Internal/ServerAddressesFeature.cs rename to src/Servers/Kestrel/Core/src/Internal/ServerAddressesFeature.cs diff --git a/src/Kestrel.Core/Internal/ServiceContext.cs b/src/Servers/Kestrel/Core/src/Internal/ServiceContext.cs similarity index 100% rename from src/Kestrel.Core/Internal/ServiceContext.cs rename to src/Servers/Kestrel/Core/src/Internal/ServiceContext.cs diff --git a/src/Kestrel.Core/Internal/TlsConnectionFeature.cs b/src/Servers/Kestrel/Core/src/Internal/TlsConnectionFeature.cs similarity index 100% rename from src/Kestrel.Core/Internal/TlsConnectionFeature.cs rename to src/Servers/Kestrel/Core/src/Internal/TlsConnectionFeature.cs diff --git a/src/Kestrel.Core/KestrelConfigurationLoader.cs b/src/Servers/Kestrel/Core/src/KestrelConfigurationLoader.cs similarity index 100% rename from src/Kestrel.Core/KestrelConfigurationLoader.cs rename to src/Servers/Kestrel/Core/src/KestrelConfigurationLoader.cs diff --git a/src/Kestrel.Core/KestrelServer.cs b/src/Servers/Kestrel/Core/src/KestrelServer.cs similarity index 100% rename from src/Kestrel.Core/KestrelServer.cs rename to src/Servers/Kestrel/Core/src/KestrelServer.cs diff --git a/src/Kestrel.Core/KestrelServerLimits.cs b/src/Servers/Kestrel/Core/src/KestrelServerLimits.cs similarity index 100% rename from src/Kestrel.Core/KestrelServerLimits.cs rename to src/Servers/Kestrel/Core/src/KestrelServerLimits.cs diff --git a/src/Kestrel.Core/KestrelServerOptions.cs b/src/Servers/Kestrel/Core/src/KestrelServerOptions.cs similarity index 100% rename from src/Kestrel.Core/KestrelServerOptions.cs rename to src/Servers/Kestrel/Core/src/KestrelServerOptions.cs diff --git a/src/Kestrel.Core/ListenOptions.cs b/src/Servers/Kestrel/Core/src/ListenOptions.cs similarity index 100% rename from src/Kestrel.Core/ListenOptions.cs rename to src/Servers/Kestrel/Core/src/ListenOptions.cs diff --git a/src/Kestrel.Core/ListenOptionsHttpsExtensions.cs b/src/Servers/Kestrel/Core/src/ListenOptionsHttpsExtensions.cs similarity index 100% rename from src/Kestrel.Core/ListenOptionsHttpsExtensions.cs rename to src/Servers/Kestrel/Core/src/ListenOptionsHttpsExtensions.cs diff --git a/src/Kestrel.Core/LocalhostListenOptions.cs b/src/Servers/Kestrel/Core/src/LocalhostListenOptions.cs similarity index 100% rename from src/Kestrel.Core/LocalhostListenOptions.cs rename to src/Servers/Kestrel/Core/src/LocalhostListenOptions.cs diff --git a/src/Servers/Kestrel/Core/src/Microsoft.AspNetCore.Server.Kestrel.Core.csproj b/src/Servers/Kestrel/Core/src/Microsoft.AspNetCore.Server.Kestrel.Core.csproj new file mode 100644 index 0000000000..dae8056002 --- /dev/null +++ b/src/Servers/Kestrel/Core/src/Microsoft.AspNetCore.Server.Kestrel.Core.csproj @@ -0,0 +1,38 @@ + + + + Core components of ASP.NET Core Kestrel cross-platform web server. + netstandard2.0;netcoreapp2.1 + true + aspnetcore;kestrel + true + CS1591;$(NoWarn) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Kestrel.Core/MinDataRate.cs b/src/Servers/Kestrel/Core/src/MinDataRate.cs similarity index 100% rename from src/Kestrel.Core/MinDataRate.cs rename to src/Servers/Kestrel/Core/src/MinDataRate.cs diff --git a/src/Kestrel.Core/Properties/AssemblyInfo.cs b/src/Servers/Kestrel/Core/src/Properties/AssemblyInfo.cs similarity index 87% rename from src/Kestrel.Core/Properties/AssemblyInfo.cs rename to src/Servers/Kestrel/Core/src/Properties/AssemblyInfo.cs index 6898d541a6..1806c94cf2 100644 --- a/src/Kestrel.Core/Properties/AssemblyInfo.cs +++ b/src/Servers/Kestrel/Core/src/Properties/AssemblyInfo.cs @@ -7,7 +7,7 @@ using System.Runtime.CompilerServices; [assembly: InternalsVisibleTo("Libuv.FunctionalTests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")] [assembly: InternalsVisibleTo("Sockets.FunctionalTests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")] [assembly: InternalsVisibleTo("Microsoft.AspNetCore.Server.Kestrel.Core.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")] -[assembly: InternalsVisibleTo("Kestrel.Performance, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")] +[assembly: InternalsVisibleTo("Microsoft.AspNetCore.Server.Kestrel.Performance, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")] [assembly: InternalsVisibleTo("Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")] [assembly: InternalsVisibleTo("Http2SampleApp, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")] [assembly: InternalsVisibleTo("PlatformBenchmarks, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")] diff --git a/src/Kestrel.Core/Properties/CoreStrings.Designer.cs b/src/Servers/Kestrel/Core/src/Properties/CoreStrings.Designer.cs similarity index 100% rename from src/Kestrel.Core/Properties/CoreStrings.Designer.cs rename to src/Servers/Kestrel/Core/src/Properties/CoreStrings.Designer.cs diff --git a/src/Kestrel.Core/ServerAddress.cs b/src/Servers/Kestrel/Core/src/ServerAddress.cs similarity index 100% rename from src/Kestrel.Core/ServerAddress.cs rename to src/Servers/Kestrel/Core/src/ServerAddress.cs diff --git a/src/Kestrel.Core/Systemd/KestrelServerOptionsSystemdExtensions.cs b/src/Servers/Kestrel/Core/src/Systemd/KestrelServerOptionsSystemdExtensions.cs similarity index 100% rename from src/Kestrel.Core/Systemd/KestrelServerOptionsSystemdExtensions.cs rename to src/Servers/Kestrel/Core/src/Systemd/KestrelServerOptionsSystemdExtensions.cs diff --git a/src/Kestrel.Core/baseline.netcore.json b/src/Servers/Kestrel/Core/src/baseline.netcore.json similarity index 100% rename from src/Kestrel.Core/baseline.netcore.json rename to src/Servers/Kestrel/Core/src/baseline.netcore.json diff --git a/test/Kestrel.Core.Tests/AddressBinderTests.cs b/src/Servers/Kestrel/Core/test/AddressBinderTests.cs similarity index 100% rename from test/Kestrel.Core.Tests/AddressBinderTests.cs rename to src/Servers/Kestrel/Core/test/AddressBinderTests.cs diff --git a/test/Kestrel.Core.Tests/AsciiDecoding.cs b/src/Servers/Kestrel/Core/test/AsciiDecoding.cs similarity index 100% rename from test/Kestrel.Core.Tests/AsciiDecoding.cs rename to src/Servers/Kestrel/Core/test/AsciiDecoding.cs diff --git a/test/Kestrel.Core.Tests/BufferReaderTests.cs b/src/Servers/Kestrel/Core/test/BufferReaderTests.cs similarity index 100% rename from test/Kestrel.Core.Tests/BufferReaderTests.cs rename to src/Servers/Kestrel/Core/test/BufferReaderTests.cs diff --git a/test/Kestrel.Core.Tests/BufferWriterTests.cs b/src/Servers/Kestrel/Core/test/BufferWriterTests.cs similarity index 100% rename from test/Kestrel.Core.Tests/BufferWriterTests.cs rename to src/Servers/Kestrel/Core/test/BufferWriterTests.cs diff --git a/test/Kestrel.Core.Tests/ChunkWriterTests.cs b/src/Servers/Kestrel/Core/test/ChunkWriterTests.cs similarity index 100% rename from test/Kestrel.Core.Tests/ChunkWriterTests.cs rename to src/Servers/Kestrel/Core/test/ChunkWriterTests.cs diff --git a/test/Kestrel.Core.Tests/ConnectionDispatcherTests.cs b/src/Servers/Kestrel/Core/test/ConnectionDispatcherTests.cs similarity index 100% rename from test/Kestrel.Core.Tests/ConnectionDispatcherTests.cs rename to src/Servers/Kestrel/Core/test/ConnectionDispatcherTests.cs diff --git a/test/Kestrel.Core.Tests/DateHeaderValueManagerTests.cs b/src/Servers/Kestrel/Core/test/DateHeaderValueManagerTests.cs similarity index 100% rename from test/Kestrel.Core.Tests/DateHeaderValueManagerTests.cs rename to src/Servers/Kestrel/Core/test/DateHeaderValueManagerTests.cs diff --git a/test/Kestrel.Core.Tests/DynamicTableTests.cs b/src/Servers/Kestrel/Core/test/DynamicTableTests.cs similarity index 100% rename from test/Kestrel.Core.Tests/DynamicTableTests.cs rename to src/Servers/Kestrel/Core/test/DynamicTableTests.cs diff --git a/test/Kestrel.Core.Tests/HPackDecoderTests.cs b/src/Servers/Kestrel/Core/test/HPackDecoderTests.cs similarity index 100% rename from test/Kestrel.Core.Tests/HPackDecoderTests.cs rename to src/Servers/Kestrel/Core/test/HPackDecoderTests.cs diff --git a/test/Kestrel.Core.Tests/HPackEncoderTests.cs b/src/Servers/Kestrel/Core/test/HPackEncoderTests.cs similarity index 100% rename from test/Kestrel.Core.Tests/HPackEncoderTests.cs rename to src/Servers/Kestrel/Core/test/HPackEncoderTests.cs diff --git a/test/Kestrel.Core.Tests/HeartbeatTests.cs b/src/Servers/Kestrel/Core/test/HeartbeatTests.cs similarity index 100% rename from test/Kestrel.Core.Tests/HeartbeatTests.cs rename to src/Servers/Kestrel/Core/test/HeartbeatTests.cs diff --git a/test/Kestrel.Core.Tests/Http1ConnectionTests.cs b/src/Servers/Kestrel/Core/test/Http1ConnectionTests.cs similarity index 100% rename from test/Kestrel.Core.Tests/Http1ConnectionTests.cs rename to src/Servers/Kestrel/Core/test/Http1ConnectionTests.cs diff --git a/test/Kestrel.Core.Tests/Http2ConnectionTests.cs b/src/Servers/Kestrel/Core/test/Http2ConnectionTests.cs similarity index 100% rename from test/Kestrel.Core.Tests/Http2ConnectionTests.cs rename to src/Servers/Kestrel/Core/test/Http2ConnectionTests.cs diff --git a/test/Kestrel.Core.Tests/HttpConnectionManagerTests.cs b/src/Servers/Kestrel/Core/test/HttpConnectionManagerTests.cs similarity index 100% rename from test/Kestrel.Core.Tests/HttpConnectionManagerTests.cs rename to src/Servers/Kestrel/Core/test/HttpConnectionManagerTests.cs diff --git a/test/Kestrel.Core.Tests/HttpConnectionTests.cs b/src/Servers/Kestrel/Core/test/HttpConnectionTests.cs similarity index 100% rename from test/Kestrel.Core.Tests/HttpConnectionTests.cs rename to src/Servers/Kestrel/Core/test/HttpConnectionTests.cs diff --git a/test/Kestrel.Core.Tests/HttpHeadersTests.cs b/src/Servers/Kestrel/Core/test/HttpHeadersTests.cs similarity index 100% rename from test/Kestrel.Core.Tests/HttpHeadersTests.cs rename to src/Servers/Kestrel/Core/test/HttpHeadersTests.cs diff --git a/test/Kestrel.Core.Tests/HttpParserTests.cs b/src/Servers/Kestrel/Core/test/HttpParserTests.cs similarity index 100% rename from test/Kestrel.Core.Tests/HttpParserTests.cs rename to src/Servers/Kestrel/Core/test/HttpParserTests.cs diff --git a/test/Kestrel.Core.Tests/HttpProtocolFeatureCollectionTests.cs b/src/Servers/Kestrel/Core/test/HttpProtocolFeatureCollectionTests.cs similarity index 100% rename from test/Kestrel.Core.Tests/HttpProtocolFeatureCollectionTests.cs rename to src/Servers/Kestrel/Core/test/HttpProtocolFeatureCollectionTests.cs diff --git a/test/Kestrel.Core.Tests/HttpRequestHeadersTests.cs b/src/Servers/Kestrel/Core/test/HttpRequestHeadersTests.cs similarity index 100% rename from test/Kestrel.Core.Tests/HttpRequestHeadersTests.cs rename to src/Servers/Kestrel/Core/test/HttpRequestHeadersTests.cs diff --git a/test/Kestrel.Core.Tests/HttpRequestStreamTests.cs b/src/Servers/Kestrel/Core/test/HttpRequestStreamTests.cs similarity index 100% rename from test/Kestrel.Core.Tests/HttpRequestStreamTests.cs rename to src/Servers/Kestrel/Core/test/HttpRequestStreamTests.cs diff --git a/test/Kestrel.Core.Tests/HttpResponseHeadersTests.cs b/src/Servers/Kestrel/Core/test/HttpResponseHeadersTests.cs similarity index 100% rename from test/Kestrel.Core.Tests/HttpResponseHeadersTests.cs rename to src/Servers/Kestrel/Core/test/HttpResponseHeadersTests.cs diff --git a/test/Kestrel.Core.Tests/HttpResponseStreamTests.cs b/src/Servers/Kestrel/Core/test/HttpResponseStreamTests.cs similarity index 100% rename from test/Kestrel.Core.Tests/HttpResponseStreamTests.cs rename to src/Servers/Kestrel/Core/test/HttpResponseStreamTests.cs diff --git a/test/Kestrel.Core.Tests/HttpUtilitiesTest.cs b/src/Servers/Kestrel/Core/test/HttpUtilitiesTest.cs similarity index 100% rename from test/Kestrel.Core.Tests/HttpUtilitiesTest.cs rename to src/Servers/Kestrel/Core/test/HttpUtilitiesTest.cs diff --git a/test/Kestrel.Core.Tests/HuffmanTests.cs b/src/Servers/Kestrel/Core/test/HuffmanTests.cs similarity index 100% rename from test/Kestrel.Core.Tests/HuffmanTests.cs rename to src/Servers/Kestrel/Core/test/HuffmanTests.cs diff --git a/test/Kestrel.Core.Tests/IntegerDecoderTests.cs b/src/Servers/Kestrel/Core/test/IntegerDecoderTests.cs similarity index 100% rename from test/Kestrel.Core.Tests/IntegerDecoderTests.cs rename to src/Servers/Kestrel/Core/test/IntegerDecoderTests.cs diff --git a/test/Kestrel.Core.Tests/IntegerEncoderTests.cs b/src/Servers/Kestrel/Core/test/IntegerEncoderTests.cs similarity index 100% rename from test/Kestrel.Core.Tests/IntegerEncoderTests.cs rename to src/Servers/Kestrel/Core/test/IntegerEncoderTests.cs diff --git a/test/Kestrel.Core.Tests/KestrelEventSourceTests.cs b/src/Servers/Kestrel/Core/test/KestrelEventSourceTests.cs similarity index 100% rename from test/Kestrel.Core.Tests/KestrelEventSourceTests.cs rename to src/Servers/Kestrel/Core/test/KestrelEventSourceTests.cs diff --git a/test/Kestrel.Core.Tests/KestrelServerLimitsTests.cs b/src/Servers/Kestrel/Core/test/KestrelServerLimitsTests.cs similarity index 100% rename from test/Kestrel.Core.Tests/KestrelServerLimitsTests.cs rename to src/Servers/Kestrel/Core/test/KestrelServerLimitsTests.cs diff --git a/test/Kestrel.Core.Tests/KestrelServerOptionsTests.cs b/src/Servers/Kestrel/Core/test/KestrelServerOptionsTests.cs similarity index 100% rename from test/Kestrel.Core.Tests/KestrelServerOptionsTests.cs rename to src/Servers/Kestrel/Core/test/KestrelServerOptionsTests.cs diff --git a/test/Kestrel.Core.Tests/KestrelServerTests.cs b/src/Servers/Kestrel/Core/test/KestrelServerTests.cs similarity index 100% rename from test/Kestrel.Core.Tests/KestrelServerTests.cs rename to src/Servers/Kestrel/Core/test/KestrelServerTests.cs diff --git a/test/Kestrel.Core.Tests/KnownStringsTests.cs b/src/Servers/Kestrel/Core/test/KnownStringsTests.cs similarity index 100% rename from test/Kestrel.Core.Tests/KnownStringsTests.cs rename to src/Servers/Kestrel/Core/test/KnownStringsTests.cs diff --git a/test/Kestrel.Core.Tests/ListenOptionsTests.cs b/src/Servers/Kestrel/Core/test/ListenOptionsTests.cs similarity index 100% rename from test/Kestrel.Core.Tests/ListenOptionsTests.cs rename to src/Servers/Kestrel/Core/test/ListenOptionsTests.cs diff --git a/test/Kestrel.Core.Tests/MessageBodyTests.cs b/src/Servers/Kestrel/Core/test/MessageBodyTests.cs similarity index 100% rename from test/Kestrel.Core.Tests/MessageBodyTests.cs rename to src/Servers/Kestrel/Core/test/MessageBodyTests.cs diff --git a/src/Servers/Kestrel/Core/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests.csproj b/src/Servers/Kestrel/Core/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests.csproj new file mode 100644 index 0000000000..e11845c901 --- /dev/null +++ b/src/Servers/Kestrel/Core/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests.csproj @@ -0,0 +1,23 @@ + + + + netcoreapp2.1;net461 + true + + + + + + + + + + + + + + + + + + diff --git a/test/Kestrel.Core.Tests/MinDataRateTests.cs b/src/Servers/Kestrel/Core/test/MinDataRateTests.cs similarity index 100% rename from test/Kestrel.Core.Tests/MinDataRateTests.cs rename to src/Servers/Kestrel/Core/test/MinDataRateTests.cs diff --git a/test/Kestrel.Core.Tests/OutputProducerTests.cs b/src/Servers/Kestrel/Core/test/OutputProducerTests.cs similarity index 100% rename from test/Kestrel.Core.Tests/OutputProducerTests.cs rename to src/Servers/Kestrel/Core/test/OutputProducerTests.cs diff --git a/test/Kestrel.Core.Tests/PathNormalizerTests.cs b/src/Servers/Kestrel/Core/test/PathNormalizerTests.cs similarity index 100% rename from test/Kestrel.Core.Tests/PathNormalizerTests.cs rename to src/Servers/Kestrel/Core/test/PathNormalizerTests.cs diff --git a/test/Kestrel.Core.Tests/PipeOptionsTests.cs b/src/Servers/Kestrel/Core/test/PipeOptionsTests.cs similarity index 100% rename from test/Kestrel.Core.Tests/PipeOptionsTests.cs rename to src/Servers/Kestrel/Core/test/PipeOptionsTests.cs diff --git a/test/Kestrel.Core.Tests/PipelineExtensionTests.cs b/src/Servers/Kestrel/Core/test/PipelineExtensionTests.cs similarity index 100% rename from test/Kestrel.Core.Tests/PipelineExtensionTests.cs rename to src/Servers/Kestrel/Core/test/PipelineExtensionTests.cs diff --git a/test/Kestrel.Core.Tests/ReasonPhrasesTests.cs b/src/Servers/Kestrel/Core/test/ReasonPhrasesTests.cs similarity index 100% rename from test/Kestrel.Core.Tests/ReasonPhrasesTests.cs rename to src/Servers/Kestrel/Core/test/ReasonPhrasesTests.cs diff --git a/test/Kestrel.Core.Tests/ResourceCounterTests.cs b/src/Servers/Kestrel/Core/test/ResourceCounterTests.cs similarity index 100% rename from test/Kestrel.Core.Tests/ResourceCounterTests.cs rename to src/Servers/Kestrel/Core/test/ResourceCounterTests.cs diff --git a/test/Kestrel.Core.Tests/ServerAddressTests.cs b/src/Servers/Kestrel/Core/test/ServerAddressTests.cs similarity index 100% rename from test/Kestrel.Core.Tests/ServerAddressTests.cs rename to src/Servers/Kestrel/Core/test/ServerAddressTests.cs diff --git a/test/Kestrel.Core.Tests/StreamsTests.cs b/src/Servers/Kestrel/Core/test/StreamsTests.cs similarity index 100% rename from test/Kestrel.Core.Tests/StreamsTests.cs rename to src/Servers/Kestrel/Core/test/StreamsTests.cs diff --git a/test/Kestrel.Core.Tests/StringUtilitiesTests.cs b/src/Servers/Kestrel/Core/test/StringUtilitiesTests.cs similarity index 100% rename from test/Kestrel.Core.Tests/StringUtilitiesTests.cs rename to src/Servers/Kestrel/Core/test/StringUtilitiesTests.cs diff --git a/test/Kestrel.Core.Tests/TestHelpers/AssertExtensions.cs b/src/Servers/Kestrel/Core/test/TestHelpers/AssertExtensions.cs similarity index 100% rename from test/Kestrel.Core.Tests/TestHelpers/AssertExtensions.cs rename to src/Servers/Kestrel/Core/test/TestHelpers/AssertExtensions.cs diff --git a/test/Kestrel.Core.Tests/TestHelpers/MockHttpResponseControl.cs b/src/Servers/Kestrel/Core/test/TestHelpers/MockHttpResponseControl.cs similarity index 100% rename from test/Kestrel.Core.Tests/TestHelpers/MockHttpResponseControl.cs rename to src/Servers/Kestrel/Core/test/TestHelpers/MockHttpResponseControl.cs diff --git a/test/Kestrel.Core.Tests/TestInput.cs b/src/Servers/Kestrel/Core/test/TestInput.cs similarity index 100% rename from test/Kestrel.Core.Tests/TestInput.cs rename to src/Servers/Kestrel/Core/test/TestInput.cs diff --git a/test/Kestrel.Core.Tests/ThrowingWriteOnlyStreamTests.cs b/src/Servers/Kestrel/Core/test/ThrowingWriteOnlyStreamTests.cs similarity index 100% rename from test/Kestrel.Core.Tests/ThrowingWriteOnlyStreamTests.cs rename to src/Servers/Kestrel/Core/test/ThrowingWriteOnlyStreamTests.cs diff --git a/src/Servers/Kestrel/Directory.Build.props b/src/Servers/Kestrel/Directory.Build.props new file mode 100644 index 0000000000..ad68f6ce2a --- /dev/null +++ b/src/Servers/Kestrel/Directory.Build.props @@ -0,0 +1,25 @@ + + + + + $(DefineConstants);INNER_LOOP + + + + + false + $(MSBuildThisFileDirectory)shared\ + + + + + true + + + + + + diff --git a/src/Kestrel.Https/Kestrel.Https.csproj b/src/Servers/Kestrel/Https/src/Microsoft.AspNetCore.Server.Kestrel.Https.csproj similarity index 53% rename from src/Kestrel.Https/Kestrel.Https.csproj rename to src/Servers/Kestrel/Https/src/Microsoft.AspNetCore.Server.Kestrel.Https.csproj index 8b3226529e..9e6fde40bd 100644 --- a/src/Kestrel.Https/Kestrel.Https.csproj +++ b/src/Servers/Kestrel/Https/src/Microsoft.AspNetCore.Server.Kestrel.Https.csproj @@ -1,8 +1,6 @@  - Microsoft.AspNetCore.Server.Kestrel.Https - Microsoft.AspNetCore.Server.Kestrel.Https HTTPS support for the ASP.NET Core Kestrel cross-platform web server. netstandard2.0;netcoreapp2.1 true @@ -11,11 +9,8 @@ - - - - - + + diff --git a/src/Kestrel.Https/Properties/AssemblyInfo.cs b/src/Servers/Kestrel/Https/src/Properties/AssemblyInfo.cs similarity index 100% rename from src/Kestrel.Https/Properties/AssemblyInfo.cs rename to src/Servers/Kestrel/Https/src/Properties/AssemblyInfo.cs diff --git a/src/Kestrel.Https/baseline.netcore.json b/src/Servers/Kestrel/Https/src/baseline.netcore.json similarity index 100% rename from src/Kestrel.Https/baseline.netcore.json rename to src/Servers/Kestrel/Https/src/baseline.netcore.json diff --git a/src/Servers/Kestrel/Kestrel/src/Microsoft.AspNetCore.Server.Kestrel.csproj b/src/Servers/Kestrel/Kestrel/src/Microsoft.AspNetCore.Server.Kestrel.csproj new file mode 100644 index 0000000000..6b8de4426f --- /dev/null +++ b/src/Servers/Kestrel/Kestrel/src/Microsoft.AspNetCore.Server.Kestrel.csproj @@ -0,0 +1,18 @@ + + + + ASP.NET Core Kestrel cross-platform web server. + netstandard2.0 + true + aspnetcore;kestrel + CS1591;$(NoWarn) + + + + + + + + + + diff --git a/src/Kestrel/WebHostBuilderKestrelExtensions.cs b/src/Servers/Kestrel/Kestrel/src/WebHostBuilderKestrelExtensions.cs similarity index 100% rename from src/Kestrel/WebHostBuilderKestrelExtensions.cs rename to src/Servers/Kestrel/Kestrel/src/WebHostBuilderKestrelExtensions.cs diff --git a/src/Kestrel/baseline.netcore.json b/src/Servers/Kestrel/Kestrel/src/baseline.netcore.json similarity index 100% rename from src/Kestrel/baseline.netcore.json rename to src/Servers/Kestrel/Kestrel/src/baseline.netcore.json diff --git a/test/Kestrel.Tests/ConfigurationReaderTests.cs b/src/Servers/Kestrel/Kestrel/test/ConfigurationReaderTests.cs similarity index 100% rename from test/Kestrel.Tests/ConfigurationReaderTests.cs rename to src/Servers/Kestrel/Kestrel/test/ConfigurationReaderTests.cs diff --git a/test/Kestrel.Tests/KestrelConfigurationBuilderTests.cs b/src/Servers/Kestrel/Kestrel/test/KestrelConfigurationBuilderTests.cs similarity index 100% rename from test/Kestrel.Tests/KestrelConfigurationBuilderTests.cs rename to src/Servers/Kestrel/Kestrel/test/KestrelConfigurationBuilderTests.cs diff --git a/src/Servers/Kestrel/Kestrel/test/Microsoft.AspNetCore.Server.Kestrel.Tests.csproj b/src/Servers/Kestrel/Kestrel/test/Microsoft.AspNetCore.Server.Kestrel.Tests.csproj new file mode 100644 index 0000000000..9bb414d321 --- /dev/null +++ b/src/Servers/Kestrel/Kestrel/test/Microsoft.AspNetCore.Server.Kestrel.Tests.csproj @@ -0,0 +1,17 @@ + + + + netcoreapp2.1;net461 + + + + + + + + + + + + + diff --git a/test/Kestrel.Tests/WebHostBuilderKestrelExtensionsTests.cs b/src/Servers/Kestrel/Kestrel/test/WebHostBuilderKestrelExtensionsTests.cs similarity index 100% rename from test/Kestrel.Tests/WebHostBuilderKestrelExtensionsTests.cs rename to src/Servers/Kestrel/Kestrel/test/WebHostBuilderKestrelExtensionsTests.cs diff --git a/src/Servers/Kestrel/README.md b/src/Servers/Kestrel/README.md new file mode 100644 index 0000000000..5aaf71c466 --- /dev/null +++ b/src/Servers/Kestrel/README.md @@ -0,0 +1,8 @@ +KestrelHttpServer +================= + +Kestrel is a cross-platform web server for ASP.NET Core. + +## File logging for functional test + +Turn on file logging for Kestrel functional tests by specifying the environment variable ASPNETCORE_TEST_LOG_DIR to the log output directory. diff --git a/src/Kestrel.Transport.Abstractions/Internal/FileHandleType.cs b/src/Servers/Kestrel/Transport.Abstractions/src/Internal/FileHandleType.cs similarity index 100% rename from src/Kestrel.Transport.Abstractions/Internal/FileHandleType.cs rename to src/Servers/Kestrel/Transport.Abstractions/src/Internal/FileHandleType.cs diff --git a/src/Kestrel.Transport.Abstractions/Internal/IApplicationTransportFeature.cs b/src/Servers/Kestrel/Transport.Abstractions/src/Internal/IApplicationTransportFeature.cs similarity index 100% rename from src/Kestrel.Transport.Abstractions/Internal/IApplicationTransportFeature.cs rename to src/Servers/Kestrel/Transport.Abstractions/src/Internal/IApplicationTransportFeature.cs diff --git a/src/Kestrel.Transport.Abstractions/Internal/IBytesWrittenFeature.cs b/src/Servers/Kestrel/Transport.Abstractions/src/Internal/IBytesWrittenFeature.cs similarity index 100% rename from src/Kestrel.Transport.Abstractions/Internal/IBytesWrittenFeature.cs rename to src/Servers/Kestrel/Transport.Abstractions/src/Internal/IBytesWrittenFeature.cs diff --git a/src/Kestrel.Transport.Abstractions/Internal/IConnectionDispatcher.cs b/src/Servers/Kestrel/Transport.Abstractions/src/Internal/IConnectionDispatcher.cs similarity index 100% rename from src/Kestrel.Transport.Abstractions/Internal/IConnectionDispatcher.cs rename to src/Servers/Kestrel/Transport.Abstractions/src/Internal/IConnectionDispatcher.cs diff --git a/src/Kestrel.Transport.Abstractions/Internal/IEndPointInformation.cs b/src/Servers/Kestrel/Transport.Abstractions/src/Internal/IEndPointInformation.cs similarity index 100% rename from src/Kestrel.Transport.Abstractions/Internal/IEndPointInformation.cs rename to src/Servers/Kestrel/Transport.Abstractions/src/Internal/IEndPointInformation.cs diff --git a/src/Kestrel.Transport.Abstractions/Internal/ITransport.cs b/src/Servers/Kestrel/Transport.Abstractions/src/Internal/ITransport.cs similarity index 100% rename from src/Kestrel.Transport.Abstractions/Internal/ITransport.cs rename to src/Servers/Kestrel/Transport.Abstractions/src/Internal/ITransport.cs diff --git a/src/Kestrel.Transport.Abstractions/Internal/ITransportFactory.cs b/src/Servers/Kestrel/Transport.Abstractions/src/Internal/ITransportFactory.cs similarity index 100% rename from src/Kestrel.Transport.Abstractions/Internal/ITransportFactory.cs rename to src/Servers/Kestrel/Transport.Abstractions/src/Internal/ITransportFactory.cs diff --git a/src/Kestrel.Transport.Abstractions/Internal/ITransportSchedulerFeature.cs b/src/Servers/Kestrel/Transport.Abstractions/src/Internal/ITransportSchedulerFeature.cs similarity index 100% rename from src/Kestrel.Transport.Abstractions/Internal/ITransportSchedulerFeature.cs rename to src/Servers/Kestrel/Transport.Abstractions/src/Internal/ITransportSchedulerFeature.cs diff --git a/src/Kestrel.Transport.Abstractions/Internal/KestrelMemoryPool.cs b/src/Servers/Kestrel/Transport.Abstractions/src/Internal/KestrelMemoryPool.cs similarity index 100% rename from src/Kestrel.Transport.Abstractions/Internal/KestrelMemoryPool.cs rename to src/Servers/Kestrel/Transport.Abstractions/src/Internal/KestrelMemoryPool.cs diff --git a/src/Kestrel.Transport.Abstractions/Internal/ListenType.cs b/src/Servers/Kestrel/Transport.Abstractions/src/Internal/ListenType.cs similarity index 100% rename from src/Kestrel.Transport.Abstractions/Internal/ListenType.cs rename to src/Servers/Kestrel/Transport.Abstractions/src/Internal/ListenType.cs diff --git a/src/Kestrel.Transport.Abstractions/Internal/MemoryPoolBlock.Debug.cs b/src/Servers/Kestrel/Transport.Abstractions/src/Internal/MemoryPoolBlock.Debug.cs similarity index 100% rename from src/Kestrel.Transport.Abstractions/Internal/MemoryPoolBlock.Debug.cs rename to src/Servers/Kestrel/Transport.Abstractions/src/Internal/MemoryPoolBlock.Debug.cs diff --git a/src/Kestrel.Transport.Abstractions/Internal/MemoryPoolBlock.Release.cs b/src/Servers/Kestrel/Transport.Abstractions/src/Internal/MemoryPoolBlock.Release.cs similarity index 100% rename from src/Kestrel.Transport.Abstractions/Internal/MemoryPoolBlock.Release.cs rename to src/Servers/Kestrel/Transport.Abstractions/src/Internal/MemoryPoolBlock.Release.cs diff --git a/src/Kestrel.Transport.Abstractions/Internal/MemoryPoolSlab.cs b/src/Servers/Kestrel/Transport.Abstractions/src/Internal/MemoryPoolSlab.cs similarity index 100% rename from src/Kestrel.Transport.Abstractions/Internal/MemoryPoolSlab.cs rename to src/Servers/Kestrel/Transport.Abstractions/src/Internal/MemoryPoolSlab.cs diff --git a/src/Kestrel.Transport.Abstractions/Internal/SchedulingMode.cs b/src/Servers/Kestrel/Transport.Abstractions/src/Internal/SchedulingMode.cs similarity index 100% rename from src/Kestrel.Transport.Abstractions/Internal/SchedulingMode.cs rename to src/Servers/Kestrel/Transport.Abstractions/src/Internal/SchedulingMode.cs diff --git a/src/Kestrel.Transport.Abstractions/Internal/SlabMemoryPool.cs b/src/Servers/Kestrel/Transport.Abstractions/src/Internal/SlabMemoryPool.cs similarity index 100% rename from src/Kestrel.Transport.Abstractions/Internal/SlabMemoryPool.cs rename to src/Servers/Kestrel/Transport.Abstractions/src/Internal/SlabMemoryPool.cs diff --git a/src/Kestrel.Transport.Abstractions/Internal/TransportConnection.Features.cs b/src/Servers/Kestrel/Transport.Abstractions/src/Internal/TransportConnection.Features.cs similarity index 100% rename from src/Kestrel.Transport.Abstractions/Internal/TransportConnection.Features.cs rename to src/Servers/Kestrel/Transport.Abstractions/src/Internal/TransportConnection.Features.cs diff --git a/src/Kestrel.Transport.Abstractions/Internal/TransportConnection.cs b/src/Servers/Kestrel/Transport.Abstractions/src/Internal/TransportConnection.cs similarity index 100% rename from src/Kestrel.Transport.Abstractions/Internal/TransportConnection.cs rename to src/Servers/Kestrel/Transport.Abstractions/src/Internal/TransportConnection.cs diff --git a/src/Kestrel.Transport.Abstractions/Kestrel.Transport.Abstractions.csproj b/src/Servers/Kestrel/Transport.Abstractions/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.csproj similarity index 64% rename from src/Kestrel.Transport.Abstractions/Kestrel.Transport.Abstractions.csproj rename to src/Servers/Kestrel/Transport.Abstractions/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.csproj index 3dc81350fb..fe131c9dd6 100644 --- a/src/Kestrel.Transport.Abstractions/Kestrel.Transport.Abstractions.csproj +++ b/src/Servers/Kestrel/Transport.Abstractions/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.csproj @@ -1,8 +1,6 @@  - Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions - Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions Transport abstractions for the ASP.NET Core Kestrel cross-platform web server. netstandard2.0 true @@ -13,11 +11,11 @@ - + - + diff --git a/src/Kestrel.Transport.Abstractions/baseline.netcore.json b/src/Servers/Kestrel/Transport.Abstractions/src/baseline.netcore.json similarity index 100% rename from src/Kestrel.Transport.Abstractions/baseline.netcore.json rename to src/Servers/Kestrel/Transport.Abstractions/src/baseline.netcore.json diff --git a/src/Kestrel.Transport.Libuv/Internal/IAsyncDisposable.cs b/src/Servers/Kestrel/Transport.Libuv/src/Internal/IAsyncDisposable.cs similarity index 100% rename from src/Kestrel.Transport.Libuv/Internal/IAsyncDisposable.cs rename to src/Servers/Kestrel/Transport.Libuv/src/Internal/IAsyncDisposable.cs diff --git a/src/Kestrel.Transport.Libuv/Internal/ILibuvTrace.cs b/src/Servers/Kestrel/Transport.Libuv/src/Internal/ILibuvTrace.cs similarity index 100% rename from src/Kestrel.Transport.Libuv/Internal/ILibuvTrace.cs rename to src/Servers/Kestrel/Transport.Libuv/src/Internal/ILibuvTrace.cs diff --git a/src/Kestrel.Transport.Libuv/Internal/LibuvAwaitable.cs b/src/Servers/Kestrel/Transport.Libuv/src/Internal/LibuvAwaitable.cs similarity index 100% rename from src/Kestrel.Transport.Libuv/Internal/LibuvAwaitable.cs rename to src/Servers/Kestrel/Transport.Libuv/src/Internal/LibuvAwaitable.cs diff --git a/src/Kestrel.Transport.Libuv/Internal/LibuvConnection.cs b/src/Servers/Kestrel/Transport.Libuv/src/Internal/LibuvConnection.cs similarity index 100% rename from src/Kestrel.Transport.Libuv/Internal/LibuvConnection.cs rename to src/Servers/Kestrel/Transport.Libuv/src/Internal/LibuvConnection.cs diff --git a/src/Kestrel.Transport.Libuv/Internal/LibuvConstants.cs b/src/Servers/Kestrel/Transport.Libuv/src/Internal/LibuvConstants.cs similarity index 100% rename from src/Kestrel.Transport.Libuv/Internal/LibuvConstants.cs rename to src/Servers/Kestrel/Transport.Libuv/src/Internal/LibuvConstants.cs diff --git a/src/Kestrel.Transport.Libuv/Internal/LibuvOutputConsumer.cs b/src/Servers/Kestrel/Transport.Libuv/src/Internal/LibuvOutputConsumer.cs similarity index 100% rename from src/Kestrel.Transport.Libuv/Internal/LibuvOutputConsumer.cs rename to src/Servers/Kestrel/Transport.Libuv/src/Internal/LibuvOutputConsumer.cs diff --git a/src/Kestrel.Transport.Libuv/Internal/LibuvThread.cs b/src/Servers/Kestrel/Transport.Libuv/src/Internal/LibuvThread.cs similarity index 100% rename from src/Kestrel.Transport.Libuv/Internal/LibuvThread.cs rename to src/Servers/Kestrel/Transport.Libuv/src/Internal/LibuvThread.cs diff --git a/src/Kestrel.Transport.Libuv/Internal/LibuvTrace.cs b/src/Servers/Kestrel/Transport.Libuv/src/Internal/LibuvTrace.cs similarity index 100% rename from src/Kestrel.Transport.Libuv/Internal/LibuvTrace.cs rename to src/Servers/Kestrel/Transport.Libuv/src/Internal/LibuvTrace.cs diff --git a/src/Kestrel.Transport.Libuv/Internal/LibuvTransport.cs b/src/Servers/Kestrel/Transport.Libuv/src/Internal/LibuvTransport.cs similarity index 100% rename from src/Kestrel.Transport.Libuv/Internal/LibuvTransport.cs rename to src/Servers/Kestrel/Transport.Libuv/src/Internal/LibuvTransport.cs diff --git a/src/Kestrel.Transport.Libuv/Internal/LibuvTransportContext.cs b/src/Servers/Kestrel/Transport.Libuv/src/Internal/LibuvTransportContext.cs similarity index 100% rename from src/Kestrel.Transport.Libuv/Internal/LibuvTransportContext.cs rename to src/Servers/Kestrel/Transport.Libuv/src/Internal/LibuvTransportContext.cs diff --git a/src/Kestrel.Transport.Libuv/Internal/LibuvTransportFactory.cs b/src/Servers/Kestrel/Transport.Libuv/src/Internal/LibuvTransportFactory.cs similarity index 100% rename from src/Kestrel.Transport.Libuv/Internal/LibuvTransportFactory.cs rename to src/Servers/Kestrel/Transport.Libuv/src/Internal/LibuvTransportFactory.cs diff --git a/src/Kestrel.Transport.Libuv/Internal/Listener.cs b/src/Servers/Kestrel/Transport.Libuv/src/Internal/Listener.cs similarity index 100% rename from src/Kestrel.Transport.Libuv/Internal/Listener.cs rename to src/Servers/Kestrel/Transport.Libuv/src/Internal/Listener.cs diff --git a/src/Kestrel.Transport.Libuv/Internal/ListenerContext.cs b/src/Servers/Kestrel/Transport.Libuv/src/Internal/ListenerContext.cs similarity index 100% rename from src/Kestrel.Transport.Libuv/Internal/ListenerContext.cs rename to src/Servers/Kestrel/Transport.Libuv/src/Internal/ListenerContext.cs diff --git a/src/Kestrel.Transport.Libuv/Internal/ListenerPrimary.cs b/src/Servers/Kestrel/Transport.Libuv/src/Internal/ListenerPrimary.cs similarity index 100% rename from src/Kestrel.Transport.Libuv/Internal/ListenerPrimary.cs rename to src/Servers/Kestrel/Transport.Libuv/src/Internal/ListenerPrimary.cs diff --git a/src/Kestrel.Transport.Libuv/Internal/ListenerSecondary.cs b/src/Servers/Kestrel/Transport.Libuv/src/Internal/ListenerSecondary.cs similarity index 100% rename from src/Kestrel.Transport.Libuv/Internal/ListenerSecondary.cs rename to src/Servers/Kestrel/Transport.Libuv/src/Internal/ListenerSecondary.cs diff --git a/src/Kestrel.Transport.Libuv/Internal/Networking/LibuvFunctions.cs b/src/Servers/Kestrel/Transport.Libuv/src/Internal/Networking/LibuvFunctions.cs similarity index 100% rename from src/Kestrel.Transport.Libuv/Internal/Networking/LibuvFunctions.cs rename to src/Servers/Kestrel/Transport.Libuv/src/Internal/Networking/LibuvFunctions.cs diff --git a/src/Kestrel.Transport.Libuv/Internal/Networking/PlatformApis.cs b/src/Servers/Kestrel/Transport.Libuv/src/Internal/Networking/PlatformApis.cs similarity index 100% rename from src/Kestrel.Transport.Libuv/Internal/Networking/PlatformApis.cs rename to src/Servers/Kestrel/Transport.Libuv/src/Internal/Networking/PlatformApis.cs diff --git a/src/Kestrel.Transport.Libuv/Internal/Networking/SockAddr.cs b/src/Servers/Kestrel/Transport.Libuv/src/Internal/Networking/SockAddr.cs similarity index 100% rename from src/Kestrel.Transport.Libuv/Internal/Networking/SockAddr.cs rename to src/Servers/Kestrel/Transport.Libuv/src/Internal/Networking/SockAddr.cs diff --git a/src/Kestrel.Transport.Libuv/Internal/Networking/UvAsyncHandle.cs b/src/Servers/Kestrel/Transport.Libuv/src/Internal/Networking/UvAsyncHandle.cs similarity index 100% rename from src/Kestrel.Transport.Libuv/Internal/Networking/UvAsyncHandle.cs rename to src/Servers/Kestrel/Transport.Libuv/src/Internal/Networking/UvAsyncHandle.cs diff --git a/src/Kestrel.Transport.Libuv/Internal/Networking/UvConnectRequest.cs b/src/Servers/Kestrel/Transport.Libuv/src/Internal/Networking/UvConnectRequest.cs similarity index 100% rename from src/Kestrel.Transport.Libuv/Internal/Networking/UvConnectRequest.cs rename to src/Servers/Kestrel/Transport.Libuv/src/Internal/Networking/UvConnectRequest.cs diff --git a/src/Kestrel.Transport.Libuv/Internal/Networking/UvException.cs b/src/Servers/Kestrel/Transport.Libuv/src/Internal/Networking/UvException.cs similarity index 100% rename from src/Kestrel.Transport.Libuv/Internal/Networking/UvException.cs rename to src/Servers/Kestrel/Transport.Libuv/src/Internal/Networking/UvException.cs diff --git a/src/Kestrel.Transport.Libuv/Internal/Networking/UvHandle.cs b/src/Servers/Kestrel/Transport.Libuv/src/Internal/Networking/UvHandle.cs similarity index 100% rename from src/Kestrel.Transport.Libuv/Internal/Networking/UvHandle.cs rename to src/Servers/Kestrel/Transport.Libuv/src/Internal/Networking/UvHandle.cs diff --git a/src/Kestrel.Transport.Libuv/Internal/Networking/UvLoopHandle.cs b/src/Servers/Kestrel/Transport.Libuv/src/Internal/Networking/UvLoopHandle.cs similarity index 100% rename from src/Kestrel.Transport.Libuv/Internal/Networking/UvLoopHandle.cs rename to src/Servers/Kestrel/Transport.Libuv/src/Internal/Networking/UvLoopHandle.cs diff --git a/src/Kestrel.Transport.Libuv/Internal/Networking/UvMemory.cs b/src/Servers/Kestrel/Transport.Libuv/src/Internal/Networking/UvMemory.cs similarity index 100% rename from src/Kestrel.Transport.Libuv/Internal/Networking/UvMemory.cs rename to src/Servers/Kestrel/Transport.Libuv/src/Internal/Networking/UvMemory.cs diff --git a/src/Kestrel.Transport.Libuv/Internal/Networking/UvPipeHandle.cs b/src/Servers/Kestrel/Transport.Libuv/src/Internal/Networking/UvPipeHandle.cs similarity index 100% rename from src/Kestrel.Transport.Libuv/Internal/Networking/UvPipeHandle.cs rename to src/Servers/Kestrel/Transport.Libuv/src/Internal/Networking/UvPipeHandle.cs diff --git a/src/Kestrel.Transport.Libuv/Internal/Networking/UvRequest.cs b/src/Servers/Kestrel/Transport.Libuv/src/Internal/Networking/UvRequest.cs similarity index 100% rename from src/Kestrel.Transport.Libuv/Internal/Networking/UvRequest.cs rename to src/Servers/Kestrel/Transport.Libuv/src/Internal/Networking/UvRequest.cs diff --git a/src/Kestrel.Transport.Libuv/Internal/Networking/UvStreamHandle.cs b/src/Servers/Kestrel/Transport.Libuv/src/Internal/Networking/UvStreamHandle.cs similarity index 100% rename from src/Kestrel.Transport.Libuv/Internal/Networking/UvStreamHandle.cs rename to src/Servers/Kestrel/Transport.Libuv/src/Internal/Networking/UvStreamHandle.cs diff --git a/src/Kestrel.Transport.Libuv/Internal/Networking/UvTcpHandle.cs b/src/Servers/Kestrel/Transport.Libuv/src/Internal/Networking/UvTcpHandle.cs similarity index 100% rename from src/Kestrel.Transport.Libuv/Internal/Networking/UvTcpHandle.cs rename to src/Servers/Kestrel/Transport.Libuv/src/Internal/Networking/UvTcpHandle.cs diff --git a/src/Kestrel.Transport.Libuv/Internal/Networking/UvTimerHandle.cs b/src/Servers/Kestrel/Transport.Libuv/src/Internal/Networking/UvTimerHandle.cs similarity index 100% rename from src/Kestrel.Transport.Libuv/Internal/Networking/UvTimerHandle.cs rename to src/Servers/Kestrel/Transport.Libuv/src/Internal/Networking/UvTimerHandle.cs diff --git a/src/Kestrel.Transport.Libuv/Internal/Networking/UvWriteReq.cs b/src/Servers/Kestrel/Transport.Libuv/src/Internal/Networking/UvWriteReq.cs similarity index 100% rename from src/Kestrel.Transport.Libuv/Internal/Networking/UvWriteReq.cs rename to src/Servers/Kestrel/Transport.Libuv/src/Internal/Networking/UvWriteReq.cs diff --git a/src/Kestrel.Transport.Libuv/Internal/WriteReqPool.cs b/src/Servers/Kestrel/Transport.Libuv/src/Internal/WriteReqPool.cs similarity index 100% rename from src/Kestrel.Transport.Libuv/Internal/WriteReqPool.cs rename to src/Servers/Kestrel/Transport.Libuv/src/Internal/WriteReqPool.cs diff --git a/src/Kestrel.Transport.Libuv/LibuvTransportOptions.cs b/src/Servers/Kestrel/Transport.Libuv/src/LibuvTransportOptions.cs similarity index 100% rename from src/Kestrel.Transport.Libuv/LibuvTransportOptions.cs rename to src/Servers/Kestrel/Transport.Libuv/src/LibuvTransportOptions.cs diff --git a/src/Servers/Kestrel/Transport.Libuv/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.csproj b/src/Servers/Kestrel/Transport.Libuv/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.csproj new file mode 100644 index 0000000000..001e97cdb6 --- /dev/null +++ b/src/Servers/Kestrel/Transport.Libuv/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.csproj @@ -0,0 +1,20 @@ + + + + Libuv transport for the ASP.NET Core Kestrel cross-platform web server. + netstandard2.0 + true + aspnetcore;kestrel + true + CS1591;$(NoWarn) + + + + + + + + + + + diff --git a/src/Kestrel.Transport.Libuv/WebHostBuilderLibuvExtensions.cs b/src/Servers/Kestrel/Transport.Libuv/src/WebHostBuilderLibuvExtensions.cs similarity index 100% rename from src/Kestrel.Transport.Libuv/WebHostBuilderLibuvExtensions.cs rename to src/Servers/Kestrel/Transport.Libuv/src/WebHostBuilderLibuvExtensions.cs diff --git a/src/Kestrel.Transport.Libuv/baseline.netcore.json b/src/Servers/Kestrel/Transport.Libuv/src/baseline.netcore.json similarity index 100% rename from src/Kestrel.Transport.Libuv/baseline.netcore.json rename to src/Servers/Kestrel/Transport.Libuv/src/baseline.netcore.json diff --git a/src/Kestrel.Transport.Libuv/breakingchanges.netcore.json b/src/Servers/Kestrel/Transport.Libuv/src/breakingchanges.netcore.json similarity index 100% rename from src/Kestrel.Transport.Libuv/breakingchanges.netcore.json rename to src/Servers/Kestrel/Transport.Libuv/src/breakingchanges.netcore.json diff --git a/test/Kestrel.Transport.Libuv.Tests/LibuvConnectionTests.cs b/src/Servers/Kestrel/Transport.Libuv/test/LibuvConnectionTests.cs similarity index 100% rename from test/Kestrel.Transport.Libuv.Tests/LibuvConnectionTests.cs rename to src/Servers/Kestrel/Transport.Libuv/test/LibuvConnectionTests.cs diff --git a/test/Kestrel.Transport.Libuv.Tests/LibuvOutputConsumerTests.cs b/src/Servers/Kestrel/Transport.Libuv/test/LibuvOutputConsumerTests.cs similarity index 100% rename from test/Kestrel.Transport.Libuv.Tests/LibuvOutputConsumerTests.cs rename to src/Servers/Kestrel/Transport.Libuv/test/LibuvOutputConsumerTests.cs diff --git a/test/Kestrel.Transport.Libuv.Tests/LibuvThreadTests.cs b/src/Servers/Kestrel/Transport.Libuv/test/LibuvThreadTests.cs similarity index 100% rename from test/Kestrel.Transport.Libuv.Tests/LibuvThreadTests.cs rename to src/Servers/Kestrel/Transport.Libuv/test/LibuvThreadTests.cs diff --git a/test/Kestrel.Transport.Libuv.Tests/LibuvTransportFactoryTests.cs b/src/Servers/Kestrel/Transport.Libuv/test/LibuvTransportFactoryTests.cs similarity index 100% rename from test/Kestrel.Transport.Libuv.Tests/LibuvTransportFactoryTests.cs rename to src/Servers/Kestrel/Transport.Libuv/test/LibuvTransportFactoryTests.cs diff --git a/test/Kestrel.Transport.Libuv.Tests/LibuvTransportOptionsTests.cs b/src/Servers/Kestrel/Transport.Libuv/test/LibuvTransportOptionsTests.cs similarity index 100% rename from test/Kestrel.Transport.Libuv.Tests/LibuvTransportOptionsTests.cs rename to src/Servers/Kestrel/Transport.Libuv/test/LibuvTransportOptionsTests.cs diff --git a/test/Kestrel.Transport.Libuv.Tests/LibuvTransportTests.cs b/src/Servers/Kestrel/Transport.Libuv/test/LibuvTransportTests.cs similarity index 100% rename from test/Kestrel.Transport.Libuv.Tests/LibuvTransportTests.cs rename to src/Servers/Kestrel/Transport.Libuv/test/LibuvTransportTests.cs diff --git a/test/Kestrel.Transport.Libuv.Tests/ListenerPrimaryTests.cs b/src/Servers/Kestrel/Transport.Libuv/test/ListenerPrimaryTests.cs similarity index 100% rename from test/Kestrel.Transport.Libuv.Tests/ListenerPrimaryTests.cs rename to src/Servers/Kestrel/Transport.Libuv/test/ListenerPrimaryTests.cs diff --git a/src/Servers/Kestrel/Transport.Libuv/test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests.csproj b/src/Servers/Kestrel/Transport.Libuv/test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests.csproj new file mode 100644 index 0000000000..4aa1f389e4 --- /dev/null +++ b/src/Servers/Kestrel/Transport.Libuv/test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests.csproj @@ -0,0 +1,20 @@ + + + + netcoreapp2.1;net461 + true + true + + + + + + + + + + + + + + diff --git a/test/Kestrel.Transport.Libuv.Tests/MultipleLoopTests.cs b/src/Servers/Kestrel/Transport.Libuv/test/MultipleLoopTests.cs similarity index 100% rename from test/Kestrel.Transport.Libuv.Tests/MultipleLoopTests.cs rename to src/Servers/Kestrel/Transport.Libuv/test/MultipleLoopTests.cs diff --git a/test/Kestrel.Transport.Libuv.Tests/NetworkingTests.cs b/src/Servers/Kestrel/Transport.Libuv/test/NetworkingTests.cs similarity index 100% rename from test/Kestrel.Transport.Libuv.Tests/NetworkingTests.cs rename to src/Servers/Kestrel/Transport.Libuv/test/NetworkingTests.cs diff --git a/test/Kestrel.Transport.Libuv.Tests/TestHelpers/MockConnectionDispatcher.cs b/src/Servers/Kestrel/Transport.Libuv/test/TestHelpers/MockConnectionDispatcher.cs similarity index 100% rename from test/Kestrel.Transport.Libuv.Tests/TestHelpers/MockConnectionDispatcher.cs rename to src/Servers/Kestrel/Transport.Libuv/test/TestHelpers/MockConnectionDispatcher.cs diff --git a/test/Kestrel.Transport.Libuv.Tests/TestHelpers/MockLibuv.cs b/src/Servers/Kestrel/Transport.Libuv/test/TestHelpers/MockLibuv.cs similarity index 100% rename from test/Kestrel.Transport.Libuv.Tests/TestHelpers/MockLibuv.cs rename to src/Servers/Kestrel/Transport.Libuv/test/TestHelpers/MockLibuv.cs diff --git a/test/Kestrel.Transport.Libuv.Tests/TestHelpers/MockSocket.cs b/src/Servers/Kestrel/Transport.Libuv/test/TestHelpers/MockSocket.cs similarity index 100% rename from test/Kestrel.Transport.Libuv.Tests/TestHelpers/MockSocket.cs rename to src/Servers/Kestrel/Transport.Libuv/test/TestHelpers/MockSocket.cs diff --git a/test/Kestrel.Transport.Libuv.Tests/TestHelpers/TestLibuvTransportContext.cs b/src/Servers/Kestrel/Transport.Libuv/test/TestHelpers/TestLibuvTransportContext.cs similarity index 100% rename from test/Kestrel.Transport.Libuv.Tests/TestHelpers/TestLibuvTransportContext.cs rename to src/Servers/Kestrel/Transport.Libuv/test/TestHelpers/TestLibuvTransportContext.cs diff --git a/test/Kestrel.Transport.Libuv.Tests/UvStreamHandleTests.cs b/src/Servers/Kestrel/Transport.Libuv/test/UvStreamHandleTests.cs similarity index 100% rename from test/Kestrel.Transport.Libuv.Tests/UvStreamHandleTests.cs rename to src/Servers/Kestrel/Transport.Libuv/test/UvStreamHandleTests.cs diff --git a/test/Kestrel.Transport.Libuv.Tests/UvTimerHandleTests.cs b/src/Servers/Kestrel/Transport.Libuv/test/UvTimerHandleTests.cs similarity index 100% rename from test/Kestrel.Transport.Libuv.Tests/UvTimerHandleTests.cs rename to src/Servers/Kestrel/Transport.Libuv/test/UvTimerHandleTests.cs diff --git a/src/Kestrel.Transport.Sockets/Internal/BufferExtensions.cs b/src/Servers/Kestrel/Transport.Sockets/src/Internal/BufferExtensions.cs similarity index 100% rename from src/Kestrel.Transport.Sockets/Internal/BufferExtensions.cs rename to src/Servers/Kestrel/Transport.Sockets/src/Internal/BufferExtensions.cs diff --git a/src/Kestrel.Transport.Sockets/Internal/IOQueue.cs b/src/Servers/Kestrel/Transport.Sockets/src/Internal/IOQueue.cs similarity index 100% rename from src/Kestrel.Transport.Sockets/Internal/IOQueue.cs rename to src/Servers/Kestrel/Transport.Sockets/src/Internal/IOQueue.cs diff --git a/src/Kestrel.Transport.Sockets/Internal/ISocketsTrace.cs b/src/Servers/Kestrel/Transport.Sockets/src/Internal/ISocketsTrace.cs similarity index 100% rename from src/Kestrel.Transport.Sockets/Internal/ISocketsTrace.cs rename to src/Servers/Kestrel/Transport.Sockets/src/Internal/ISocketsTrace.cs diff --git a/src/Kestrel.Transport.Sockets/Internal/SocketAwaitable.cs b/src/Servers/Kestrel/Transport.Sockets/src/Internal/SocketAwaitable.cs similarity index 100% rename from src/Kestrel.Transport.Sockets/Internal/SocketAwaitable.cs rename to src/Servers/Kestrel/Transport.Sockets/src/Internal/SocketAwaitable.cs diff --git a/src/Kestrel.Transport.Sockets/Internal/SocketConnection.cs b/src/Servers/Kestrel/Transport.Sockets/src/Internal/SocketConnection.cs similarity index 100% rename from src/Kestrel.Transport.Sockets/Internal/SocketConnection.cs rename to src/Servers/Kestrel/Transport.Sockets/src/Internal/SocketConnection.cs diff --git a/src/Kestrel.Transport.Sockets/Internal/SocketReceiver.cs b/src/Servers/Kestrel/Transport.Sockets/src/Internal/SocketReceiver.cs similarity index 100% rename from src/Kestrel.Transport.Sockets/Internal/SocketReceiver.cs rename to src/Servers/Kestrel/Transport.Sockets/src/Internal/SocketReceiver.cs diff --git a/src/Kestrel.Transport.Sockets/Internal/SocketSender.cs b/src/Servers/Kestrel/Transport.Sockets/src/Internal/SocketSender.cs similarity index 100% rename from src/Kestrel.Transport.Sockets/Internal/SocketSender.cs rename to src/Servers/Kestrel/Transport.Sockets/src/Internal/SocketSender.cs diff --git a/src/Kestrel.Transport.Sockets/Internal/SocketsTrace.cs b/src/Servers/Kestrel/Transport.Sockets/src/Internal/SocketsTrace.cs similarity index 100% rename from src/Kestrel.Transport.Sockets/Internal/SocketsTrace.cs rename to src/Servers/Kestrel/Transport.Sockets/src/Internal/SocketsTrace.cs diff --git a/src/Kestrel.Transport.Sockets/Kestrel.Transport.Sockets.csproj b/src/Servers/Kestrel/Transport.Sockets/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.csproj similarity index 52% rename from src/Kestrel.Transport.Sockets/Kestrel.Transport.Sockets.csproj rename to src/Servers/Kestrel/Transport.Sockets/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.csproj index 8af8305852..82dde8daa8 100644 --- a/src/Kestrel.Transport.Sockets/Kestrel.Transport.Sockets.csproj +++ b/src/Servers/Kestrel/Transport.Sockets/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.csproj @@ -1,8 +1,6 @@  - Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets - Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets Managed socket transport for the ASP.NET Core Kestrel cross-platform web server. netstandard2.0;netcoreapp2.1 true @@ -12,12 +10,9 @@ - - - - - - + + + diff --git a/src/Kestrel.Transport.Sockets/Properties/SocketsStrings.Designer.cs b/src/Servers/Kestrel/Transport.Sockets/src/Properties/SocketsStrings.Designer.cs similarity index 100% rename from src/Kestrel.Transport.Sockets/Properties/SocketsStrings.Designer.cs rename to src/Servers/Kestrel/Transport.Sockets/src/Properties/SocketsStrings.Designer.cs diff --git a/src/Kestrel.Transport.Sockets/SocketTransport.cs b/src/Servers/Kestrel/Transport.Sockets/src/SocketTransport.cs similarity index 100% rename from src/Kestrel.Transport.Sockets/SocketTransport.cs rename to src/Servers/Kestrel/Transport.Sockets/src/SocketTransport.cs diff --git a/src/Kestrel.Transport.Sockets/SocketTransportFactory.cs b/src/Servers/Kestrel/Transport.Sockets/src/SocketTransportFactory.cs similarity index 100% rename from src/Kestrel.Transport.Sockets/SocketTransportFactory.cs rename to src/Servers/Kestrel/Transport.Sockets/src/SocketTransportFactory.cs diff --git a/src/Kestrel.Transport.Sockets/SocketTransportOptions.cs b/src/Servers/Kestrel/Transport.Sockets/src/SocketTransportOptions.cs similarity index 100% rename from src/Kestrel.Transport.Sockets/SocketTransportOptions.cs rename to src/Servers/Kestrel/Transport.Sockets/src/SocketTransportOptions.cs diff --git a/src/Kestrel.Transport.Sockets/SocketsStrings.resx b/src/Servers/Kestrel/Transport.Sockets/src/SocketsStrings.resx similarity index 100% rename from src/Kestrel.Transport.Sockets/SocketsStrings.resx rename to src/Servers/Kestrel/Transport.Sockets/src/SocketsStrings.resx diff --git a/src/Kestrel.Transport.Sockets/WebHostBuilderSocketExtensions.cs b/src/Servers/Kestrel/Transport.Sockets/src/WebHostBuilderSocketExtensions.cs similarity index 100% rename from src/Kestrel.Transport.Sockets/WebHostBuilderSocketExtensions.cs rename to src/Servers/Kestrel/Transport.Sockets/src/WebHostBuilderSocketExtensions.cs diff --git a/src/Kestrel.Transport.Sockets/baseline.netcore.json b/src/Servers/Kestrel/Transport.Sockets/src/baseline.netcore.json similarity index 100% rename from src/Kestrel.Transport.Sockets/baseline.netcore.json rename to src/Servers/Kestrel/Transport.Sockets/src/baseline.netcore.json diff --git a/benchmarks/Kestrel.Performance/AsciiBytesToStringBenchmark.cs b/src/Servers/Kestrel/perf/Kestrel.Performance/AsciiBytesToStringBenchmark.cs similarity index 100% rename from benchmarks/Kestrel.Performance/AsciiBytesToStringBenchmark.cs rename to src/Servers/Kestrel/perf/Kestrel.Performance/AsciiBytesToStringBenchmark.cs diff --git a/benchmarks/Kestrel.Performance/AssemblyInfo.cs b/src/Servers/Kestrel/perf/Kestrel.Performance/AssemblyInfo.cs similarity index 100% rename from benchmarks/Kestrel.Performance/AssemblyInfo.cs rename to src/Servers/Kestrel/perf/Kestrel.Performance/AssemblyInfo.cs diff --git a/benchmarks/Kestrel.Performance/DotSegmentRemovalBenchmark.cs b/src/Servers/Kestrel/perf/Kestrel.Performance/DotSegmentRemovalBenchmark.cs similarity index 100% rename from benchmarks/Kestrel.Performance/DotSegmentRemovalBenchmark.cs rename to src/Servers/Kestrel/perf/Kestrel.Performance/DotSegmentRemovalBenchmark.cs diff --git a/benchmarks/Kestrel.Performance/ErrorUtilities.cs b/src/Servers/Kestrel/perf/Kestrel.Performance/ErrorUtilities.cs similarity index 100% rename from benchmarks/Kestrel.Performance/ErrorUtilities.cs rename to src/Servers/Kestrel/perf/Kestrel.Performance/ErrorUtilities.cs diff --git a/benchmarks/Kestrel.Performance/Http1ConnectionBenchmark.cs b/src/Servers/Kestrel/perf/Kestrel.Performance/Http1ConnectionBenchmark.cs similarity index 100% rename from benchmarks/Kestrel.Performance/Http1ConnectionBenchmark.cs rename to src/Servers/Kestrel/perf/Kestrel.Performance/Http1ConnectionBenchmark.cs diff --git a/benchmarks/Kestrel.Performance/Http1ConnectionParsingOverheadBenchmark.cs b/src/Servers/Kestrel/perf/Kestrel.Performance/Http1ConnectionParsingOverheadBenchmark.cs similarity index 100% rename from benchmarks/Kestrel.Performance/Http1ConnectionParsingOverheadBenchmark.cs rename to src/Servers/Kestrel/perf/Kestrel.Performance/Http1ConnectionParsingOverheadBenchmark.cs diff --git a/benchmarks/Kestrel.Performance/Http1WritingBenchmark.cs b/src/Servers/Kestrel/perf/Kestrel.Performance/Http1WritingBenchmark.cs similarity index 100% rename from benchmarks/Kestrel.Performance/Http1WritingBenchmark.cs rename to src/Servers/Kestrel/perf/Kestrel.Performance/Http1WritingBenchmark.cs diff --git a/benchmarks/Kestrel.Performance/HttpParserBenchmark.cs b/src/Servers/Kestrel/perf/Kestrel.Performance/HttpParserBenchmark.cs similarity index 100% rename from benchmarks/Kestrel.Performance/HttpParserBenchmark.cs rename to src/Servers/Kestrel/perf/Kestrel.Performance/HttpParserBenchmark.cs diff --git a/benchmarks/Kestrel.Performance/HttpProtocolFeatureCollection.cs b/src/Servers/Kestrel/perf/Kestrel.Performance/HttpProtocolFeatureCollection.cs similarity index 100% rename from benchmarks/Kestrel.Performance/HttpProtocolFeatureCollection.cs rename to src/Servers/Kestrel/perf/Kestrel.Performance/HttpProtocolFeatureCollection.cs diff --git a/benchmarks/Kestrel.Performance/InMemoryTransportBenchmark.cs b/src/Servers/Kestrel/perf/Kestrel.Performance/InMemoryTransportBenchmark.cs similarity index 100% rename from benchmarks/Kestrel.Performance/InMemoryTransportBenchmark.cs rename to src/Servers/Kestrel/perf/Kestrel.Performance/InMemoryTransportBenchmark.cs diff --git a/benchmarks/Kestrel.Performance/KnownStringsBenchmark.cs b/src/Servers/Kestrel/perf/Kestrel.Performance/KnownStringsBenchmark.cs similarity index 100% rename from benchmarks/Kestrel.Performance/KnownStringsBenchmark.cs rename to src/Servers/Kestrel/perf/Kestrel.Performance/KnownStringsBenchmark.cs diff --git a/src/Servers/Kestrel/perf/Kestrel.Performance/Microsoft.AspNetCore.Server.Kestrel.Performance.csproj b/src/Servers/Kestrel/perf/Kestrel.Performance/Microsoft.AspNetCore.Server.Kestrel.Performance.csproj new file mode 100644 index 0000000000..1998485c20 --- /dev/null +++ b/src/Servers/Kestrel/perf/Kestrel.Performance/Microsoft.AspNetCore.Server.Kestrel.Performance.csproj @@ -0,0 +1,27 @@ + + + + netcoreapp2.0 + Exe + true + true + false + + + + + + + + + + + + + + + + + + + diff --git a/benchmarks/Kestrel.Performance/Mocks/MockTimeoutControl.cs b/src/Servers/Kestrel/perf/Kestrel.Performance/Mocks/MockTimeoutControl.cs similarity index 100% rename from benchmarks/Kestrel.Performance/Mocks/MockTimeoutControl.cs rename to src/Servers/Kestrel/perf/Kestrel.Performance/Mocks/MockTimeoutControl.cs diff --git a/benchmarks/Kestrel.Performance/Mocks/MockTrace.cs b/src/Servers/Kestrel/perf/Kestrel.Performance/Mocks/MockTrace.cs similarity index 100% rename from benchmarks/Kestrel.Performance/Mocks/MockTrace.cs rename to src/Servers/Kestrel/perf/Kestrel.Performance/Mocks/MockTrace.cs diff --git a/benchmarks/Kestrel.Performance/Mocks/NullParser.cs b/src/Servers/Kestrel/perf/Kestrel.Performance/Mocks/NullParser.cs similarity index 100% rename from benchmarks/Kestrel.Performance/Mocks/NullParser.cs rename to src/Servers/Kestrel/perf/Kestrel.Performance/Mocks/NullParser.cs diff --git a/benchmarks/Kestrel.Performance/PipeThroughputBenchmark.cs b/src/Servers/Kestrel/perf/Kestrel.Performance/PipeThroughputBenchmark.cs similarity index 100% rename from benchmarks/Kestrel.Performance/PipeThroughputBenchmark.cs rename to src/Servers/Kestrel/perf/Kestrel.Performance/PipeThroughputBenchmark.cs diff --git a/benchmarks/Kestrel.Performance/README.md b/src/Servers/Kestrel/perf/Kestrel.Performance/README.md similarity index 100% rename from benchmarks/Kestrel.Performance/README.md rename to src/Servers/Kestrel/perf/Kestrel.Performance/README.md diff --git a/benchmarks/Kestrel.Performance/RequestParsingBenchmark.cs b/src/Servers/Kestrel/perf/Kestrel.Performance/RequestParsingBenchmark.cs similarity index 100% rename from benchmarks/Kestrel.Performance/RequestParsingBenchmark.cs rename to src/Servers/Kestrel/perf/Kestrel.Performance/RequestParsingBenchmark.cs diff --git a/benchmarks/Kestrel.Performance/RequestParsingData.cs b/src/Servers/Kestrel/perf/Kestrel.Performance/RequestParsingData.cs similarity index 100% rename from benchmarks/Kestrel.Performance/RequestParsingData.cs rename to src/Servers/Kestrel/perf/Kestrel.Performance/RequestParsingData.cs diff --git a/benchmarks/Kestrel.Performance/ResponseHeaderCollectionBenchmark.cs b/src/Servers/Kestrel/perf/Kestrel.Performance/ResponseHeaderCollectionBenchmark.cs similarity index 100% rename from benchmarks/Kestrel.Performance/ResponseHeaderCollectionBenchmark.cs rename to src/Servers/Kestrel/perf/Kestrel.Performance/ResponseHeaderCollectionBenchmark.cs diff --git a/benchmarks/Kestrel.Performance/ResponseHeadersWritingBenchmark.cs b/src/Servers/Kestrel/perf/Kestrel.Performance/ResponseHeadersWritingBenchmark.cs similarity index 100% rename from benchmarks/Kestrel.Performance/ResponseHeadersWritingBenchmark.cs rename to src/Servers/Kestrel/perf/Kestrel.Performance/ResponseHeadersWritingBenchmark.cs diff --git a/benchmarks/Kestrel.Performance/StringUtilitiesBenchmark.cs b/src/Servers/Kestrel/perf/Kestrel.Performance/StringUtilitiesBenchmark.cs similarity index 100% rename from benchmarks/Kestrel.Performance/StringUtilitiesBenchmark.cs rename to src/Servers/Kestrel/perf/Kestrel.Performance/StringUtilitiesBenchmark.cs diff --git a/benchmarkapps/PlatformBenchmarks/AsciiString.cs b/src/Servers/Kestrel/perf/PlatformBenchmarks/AsciiString.cs similarity index 100% rename from benchmarkapps/PlatformBenchmarks/AsciiString.cs rename to src/Servers/Kestrel/perf/PlatformBenchmarks/AsciiString.cs diff --git a/benchmarkapps/PlatformBenchmarks/BenchmarkApplication.cs b/src/Servers/Kestrel/perf/PlatformBenchmarks/BenchmarkApplication.cs similarity index 100% rename from benchmarkapps/PlatformBenchmarks/BenchmarkApplication.cs rename to src/Servers/Kestrel/perf/PlatformBenchmarks/BenchmarkApplication.cs diff --git a/benchmarkapps/PlatformBenchmarks/BenchmarkConfigurationHelpers.cs b/src/Servers/Kestrel/perf/PlatformBenchmarks/BenchmarkConfigurationHelpers.cs similarity index 100% rename from benchmarkapps/PlatformBenchmarks/BenchmarkConfigurationHelpers.cs rename to src/Servers/Kestrel/perf/PlatformBenchmarks/BenchmarkConfigurationHelpers.cs diff --git a/benchmarkapps/PlatformBenchmarks/DateHeader.cs b/src/Servers/Kestrel/perf/PlatformBenchmarks/DateHeader.cs similarity index 100% rename from benchmarkapps/PlatformBenchmarks/DateHeader.cs rename to src/Servers/Kestrel/perf/PlatformBenchmarks/DateHeader.cs diff --git a/benchmarkapps/PlatformBenchmarks/HttpApplication.cs b/src/Servers/Kestrel/perf/PlatformBenchmarks/HttpApplication.cs similarity index 100% rename from benchmarkapps/PlatformBenchmarks/HttpApplication.cs rename to src/Servers/Kestrel/perf/PlatformBenchmarks/HttpApplication.cs diff --git a/benchmarkapps/PlatformBenchmarks/PlatformBenchmarks.csproj b/src/Servers/Kestrel/perf/PlatformBenchmarks/PlatformBenchmarks.csproj similarity index 52% rename from benchmarkapps/PlatformBenchmarks/PlatformBenchmarks.csproj rename to src/Servers/Kestrel/perf/PlatformBenchmarks/PlatformBenchmarks.csproj index 4d4126c688..faeef6ecb2 100644 --- a/benchmarkapps/PlatformBenchmarks/PlatformBenchmarks.csproj +++ b/src/Servers/Kestrel/perf/PlatformBenchmarks/PlatformBenchmarks.csproj @@ -5,22 +5,22 @@ Exe latest true + true - + - + - + - - - - + + + - + diff --git a/benchmarkapps/PlatformBenchmarks/Program.cs b/src/Servers/Kestrel/perf/PlatformBenchmarks/Program.cs similarity index 100% rename from benchmarkapps/PlatformBenchmarks/Program.cs rename to src/Servers/Kestrel/perf/PlatformBenchmarks/Program.cs diff --git a/benchmarkapps/PlatformBenchmarks/Startup.cs b/src/Servers/Kestrel/perf/PlatformBenchmarks/Startup.cs similarity index 100% rename from benchmarkapps/PlatformBenchmarks/Startup.cs rename to src/Servers/Kestrel/perf/PlatformBenchmarks/Startup.cs diff --git a/benchmarkapps/PlatformBenchmarks/benchmarks.json.json b/src/Servers/Kestrel/perf/PlatformBenchmarks/benchmarks.json.json similarity index 100% rename from benchmarkapps/PlatformBenchmarks/benchmarks.json.json rename to src/Servers/Kestrel/perf/PlatformBenchmarks/benchmarks.json.json diff --git a/benchmarkapps/PlatformBenchmarks/benchmarks.plaintext.json b/src/Servers/Kestrel/perf/PlatformBenchmarks/benchmarks.plaintext.json similarity index 100% rename from benchmarkapps/PlatformBenchmarks/benchmarks.plaintext.json rename to src/Servers/Kestrel/perf/PlatformBenchmarks/benchmarks.plaintext.json diff --git a/samples/Http2SampleApp/Dockerfile b/src/Servers/Kestrel/samples/Http2SampleApp/Dockerfile similarity index 100% rename from samples/Http2SampleApp/Dockerfile rename to src/Servers/Kestrel/samples/Http2SampleApp/Dockerfile diff --git a/samples/Http2SampleApp/Http2SampleApp.csproj b/src/Servers/Kestrel/samples/Http2SampleApp/Http2SampleApp.csproj similarity index 59% rename from samples/Http2SampleApp/Http2SampleApp.csproj rename to src/Servers/Kestrel/samples/Http2SampleApp/Http2SampleApp.csproj index cd660a6c80..08078fe3cf 100644 --- a/samples/Http2SampleApp/Http2SampleApp.csproj +++ b/src/Servers/Kestrel/samples/Http2SampleApp/Http2SampleApp.csproj @@ -1,4 +1,4 @@ - + netcoreapp2.1 @@ -7,11 +7,8 @@ - - - - - + + diff --git a/samples/Http2SampleApp/Program.cs b/src/Servers/Kestrel/samples/Http2SampleApp/Program.cs similarity index 100% rename from samples/Http2SampleApp/Program.cs rename to src/Servers/Kestrel/samples/Http2SampleApp/Program.cs diff --git a/samples/Http2SampleApp/Startup.cs b/src/Servers/Kestrel/samples/Http2SampleApp/Startup.cs similarity index 100% rename from samples/Http2SampleApp/Startup.cs rename to src/Servers/Kestrel/samples/Http2SampleApp/Startup.cs diff --git a/samples/Http2SampleApp/scripts/build-docker.ps1 b/src/Servers/Kestrel/samples/Http2SampleApp/scripts/build-docker.ps1 similarity index 100% rename from samples/Http2SampleApp/scripts/build-docker.ps1 rename to src/Servers/Kestrel/samples/Http2SampleApp/scripts/build-docker.ps1 diff --git a/samples/Http2SampleApp/scripts/build-docker.sh b/src/Servers/Kestrel/samples/Http2SampleApp/scripts/build-docker.sh old mode 100755 new mode 100644 similarity index 100% rename from samples/Http2SampleApp/scripts/build-docker.sh rename to src/Servers/Kestrel/samples/Http2SampleApp/scripts/build-docker.sh diff --git a/samples/Http2SampleApp/scripts/run-docker.ps1 b/src/Servers/Kestrel/samples/Http2SampleApp/scripts/run-docker.ps1 similarity index 100% rename from samples/Http2SampleApp/scripts/run-docker.ps1 rename to src/Servers/Kestrel/samples/Http2SampleApp/scripts/run-docker.ps1 diff --git a/samples/Http2SampleApp/scripts/run-docker.sh b/src/Servers/Kestrel/samples/Http2SampleApp/scripts/run-docker.sh old mode 100755 new mode 100644 similarity index 100% rename from samples/Http2SampleApp/scripts/run-docker.sh rename to src/Servers/Kestrel/samples/Http2SampleApp/scripts/run-docker.sh diff --git a/samples/Http2SampleApp/testCert.pfx b/src/Servers/Kestrel/samples/Http2SampleApp/testCert.pfx similarity index 100% rename from samples/Http2SampleApp/testCert.pfx rename to src/Servers/Kestrel/samples/Http2SampleApp/testCert.pfx diff --git a/samples/LargeResponseApp/LargeResponseApp.csproj b/src/Servers/Kestrel/samples/LargeResponseApp/LargeResponseApp.csproj similarity index 80% rename from samples/LargeResponseApp/LargeResponseApp.csproj rename to src/Servers/Kestrel/samples/LargeResponseApp/LargeResponseApp.csproj index 13fab4a63e..16d7aa18d1 100644 --- a/samples/LargeResponseApp/LargeResponseApp.csproj +++ b/src/Servers/Kestrel/samples/LargeResponseApp/LargeResponseApp.csproj @@ -7,7 +7,7 @@ - + diff --git a/samples/LargeResponseApp/Startup.cs b/src/Servers/Kestrel/samples/LargeResponseApp/Startup.cs similarity index 100% rename from samples/LargeResponseApp/Startup.cs rename to src/Servers/Kestrel/samples/LargeResponseApp/Startup.cs diff --git a/samples/PlaintextApp/PlaintextApp.csproj b/src/Servers/Kestrel/samples/PlaintextApp/PlaintextApp.csproj similarity index 80% rename from samples/PlaintextApp/PlaintextApp.csproj rename to src/Servers/Kestrel/samples/PlaintextApp/PlaintextApp.csproj index 238983e4f8..f2c0c8a820 100644 --- a/samples/PlaintextApp/PlaintextApp.csproj +++ b/src/Servers/Kestrel/samples/PlaintextApp/PlaintextApp.csproj @@ -7,7 +7,7 @@ - + diff --git a/samples/PlaintextApp/Startup.cs b/src/Servers/Kestrel/samples/PlaintextApp/Startup.cs similarity index 100% rename from samples/PlaintextApp/Startup.cs rename to src/Servers/Kestrel/samples/PlaintextApp/Startup.cs diff --git a/samples/SampleApp/SampleApp.csproj b/src/Servers/Kestrel/samples/SampleApp/SampleApp.csproj similarity index 61% rename from samples/SampleApp/SampleApp.csproj rename to src/Servers/Kestrel/samples/SampleApp/SampleApp.csproj index 036867ebc1..fff5a6c3bd 100644 --- a/samples/SampleApp/SampleApp.csproj +++ b/src/Servers/Kestrel/samples/SampleApp/SampleApp.csproj @@ -7,14 +7,11 @@ - - - - - - - - + + + + + diff --git a/samples/SampleApp/Startup.cs b/src/Servers/Kestrel/samples/SampleApp/Startup.cs similarity index 100% rename from samples/SampleApp/Startup.cs rename to src/Servers/Kestrel/samples/SampleApp/Startup.cs diff --git a/samples/SampleApp/appsettings.Development.json b/src/Servers/Kestrel/samples/SampleApp/appsettings.Development.json similarity index 100% rename from samples/SampleApp/appsettings.Development.json rename to src/Servers/Kestrel/samples/SampleApp/appsettings.Development.json diff --git a/samples/SampleApp/appsettings.Production.json b/src/Servers/Kestrel/samples/SampleApp/appsettings.Production.json similarity index 100% rename from samples/SampleApp/appsettings.Production.json rename to src/Servers/Kestrel/samples/SampleApp/appsettings.Production.json diff --git a/samples/SampleApp/appsettings.json b/src/Servers/Kestrel/samples/SampleApp/appsettings.json similarity index 100% rename from samples/SampleApp/appsettings.json rename to src/Servers/Kestrel/samples/SampleApp/appsettings.json diff --git a/samples/SampleApp/testCert.pfx b/src/Servers/Kestrel/samples/SampleApp/testCert.pfx similarity index 100% rename from samples/SampleApp/testCert.pfx rename to src/Servers/Kestrel/samples/SampleApp/testCert.pfx diff --git a/samples/SystemdTestApp/Startup.cs b/src/Servers/Kestrel/samples/SystemdTestApp/Startup.cs similarity index 100% rename from samples/SystemdTestApp/Startup.cs rename to src/Servers/Kestrel/samples/SystemdTestApp/Startup.cs diff --git a/samples/SystemdTestApp/SystemdTestApp.csproj b/src/Servers/Kestrel/samples/SystemdTestApp/SystemdTestApp.csproj similarity index 57% rename from samples/SystemdTestApp/SystemdTestApp.csproj rename to src/Servers/Kestrel/samples/SystemdTestApp/SystemdTestApp.csproj index 28c159a38e..a9bd0733b2 100644 --- a/samples/SystemdTestApp/SystemdTestApp.csproj +++ b/src/Servers/Kestrel/samples/SystemdTestApp/SystemdTestApp.csproj @@ -7,12 +7,9 @@ - - - - - - + + + diff --git a/samples/SystemdTestApp/testCert.pfx b/src/Servers/Kestrel/samples/SystemdTestApp/testCert.pfx similarity index 100% rename from samples/SystemdTestApp/testCert.pfx rename to src/Servers/Kestrel/samples/SystemdTestApp/testCert.pfx diff --git a/src/shared/ThrowHelper.cs b/src/Servers/Kestrel/shared/src/ThrowHelper.cs similarity index 100% rename from src/shared/ThrowHelper.cs rename to src/Servers/Kestrel/shared/src/ThrowHelper.cs diff --git a/test/shared/DisposableStack.cs b/src/Servers/Kestrel/shared/test/DisposableStack.cs similarity index 100% rename from test/shared/DisposableStack.cs rename to src/Servers/Kestrel/shared/test/DisposableStack.cs diff --git a/test/shared/DummyApplication.cs b/src/Servers/Kestrel/shared/test/DummyApplication.cs similarity index 100% rename from test/shared/DummyApplication.cs rename to src/Servers/Kestrel/shared/test/DummyApplication.cs diff --git a/test/shared/EventRaisingResourceCounter.cs b/src/Servers/Kestrel/shared/test/EventRaisingResourceCounter.cs similarity index 100% rename from test/shared/EventRaisingResourceCounter.cs rename to src/Servers/Kestrel/shared/test/EventRaisingResourceCounter.cs diff --git a/test/shared/HttpParsingData.cs b/src/Servers/Kestrel/shared/test/HttpParsingData.cs similarity index 100% rename from test/shared/HttpParsingData.cs rename to src/Servers/Kestrel/shared/test/HttpParsingData.cs diff --git a/test/shared/KestrelTestLoggerProvider.cs b/src/Servers/Kestrel/shared/test/KestrelTestLoggerProvider.cs similarity index 100% rename from test/shared/KestrelTestLoggerProvider.cs rename to src/Servers/Kestrel/shared/test/KestrelTestLoggerProvider.cs diff --git a/test/shared/LifetimeNotImplemented.cs b/src/Servers/Kestrel/shared/test/LifetimeNotImplemented.cs similarity index 100% rename from test/shared/LifetimeNotImplemented.cs rename to src/Servers/Kestrel/shared/test/LifetimeNotImplemented.cs diff --git a/test/shared/MockLogger.cs b/src/Servers/Kestrel/shared/test/MockLogger.cs similarity index 100% rename from test/shared/MockLogger.cs rename to src/Servers/Kestrel/shared/test/MockLogger.cs diff --git a/test/shared/MockSystemClock.cs b/src/Servers/Kestrel/shared/test/MockSystemClock.cs similarity index 100% rename from test/shared/MockSystemClock.cs rename to src/Servers/Kestrel/shared/test/MockSystemClock.cs diff --git a/test/shared/PassThroughConnectionAdapter.cs b/src/Servers/Kestrel/shared/test/PassThroughConnectionAdapter.cs similarity index 100% rename from test/shared/PassThroughConnectionAdapter.cs rename to src/Servers/Kestrel/shared/test/PassThroughConnectionAdapter.cs diff --git a/test/shared/StringExtensions.cs b/src/Servers/Kestrel/shared/test/StringExtensions.cs similarity index 100% rename from test/shared/StringExtensions.cs rename to src/Servers/Kestrel/shared/test/StringExtensions.cs diff --git a/test/shared/TaskTimeoutExtensions.cs b/src/Servers/Kestrel/shared/test/TaskTimeoutExtensions.cs similarity index 100% rename from test/shared/TaskTimeoutExtensions.cs rename to src/Servers/Kestrel/shared/test/TaskTimeoutExtensions.cs diff --git a/test/shared/TestApp.cs b/src/Servers/Kestrel/shared/test/TestApp.cs similarity index 100% rename from test/shared/TestApp.cs rename to src/Servers/Kestrel/shared/test/TestApp.cs diff --git a/test/shared/TestApplicationErrorLogger.cs b/src/Servers/Kestrel/shared/test/TestApplicationErrorLogger.cs similarity index 100% rename from test/shared/TestApplicationErrorLogger.cs rename to src/Servers/Kestrel/shared/test/TestApplicationErrorLogger.cs diff --git a/test/shared/TestCertificates/aspnetdevcert.pfx b/src/Servers/Kestrel/shared/test/TestCertificates/aspnetdevcert.pfx similarity index 100% rename from test/shared/TestCertificates/aspnetdevcert.pfx rename to src/Servers/Kestrel/shared/test/TestCertificates/aspnetdevcert.pfx diff --git a/test/shared/TestCertificates/eku.client.ini b/src/Servers/Kestrel/shared/test/TestCertificates/eku.client.ini similarity index 100% rename from test/shared/TestCertificates/eku.client.ini rename to src/Servers/Kestrel/shared/test/TestCertificates/eku.client.ini diff --git a/test/shared/TestCertificates/eku.client.pfx b/src/Servers/Kestrel/shared/test/TestCertificates/eku.client.pfx similarity index 100% rename from test/shared/TestCertificates/eku.client.pfx rename to src/Servers/Kestrel/shared/test/TestCertificates/eku.client.pfx diff --git a/test/shared/TestCertificates/eku.code_signing.ini b/src/Servers/Kestrel/shared/test/TestCertificates/eku.code_signing.ini similarity index 100% rename from test/shared/TestCertificates/eku.code_signing.ini rename to src/Servers/Kestrel/shared/test/TestCertificates/eku.code_signing.ini diff --git a/test/shared/TestCertificates/eku.code_signing.pfx b/src/Servers/Kestrel/shared/test/TestCertificates/eku.code_signing.pfx similarity index 100% rename from test/shared/TestCertificates/eku.code_signing.pfx rename to src/Servers/Kestrel/shared/test/TestCertificates/eku.code_signing.pfx diff --git a/test/shared/TestCertificates/eku.multiple_usages.ini b/src/Servers/Kestrel/shared/test/TestCertificates/eku.multiple_usages.ini similarity index 100% rename from test/shared/TestCertificates/eku.multiple_usages.ini rename to src/Servers/Kestrel/shared/test/TestCertificates/eku.multiple_usages.ini diff --git a/test/shared/TestCertificates/eku.multiple_usages.pfx b/src/Servers/Kestrel/shared/test/TestCertificates/eku.multiple_usages.pfx similarity index 100% rename from test/shared/TestCertificates/eku.multiple_usages.pfx rename to src/Servers/Kestrel/shared/test/TestCertificates/eku.multiple_usages.pfx diff --git a/test/shared/TestCertificates/eku.server.ini b/src/Servers/Kestrel/shared/test/TestCertificates/eku.server.ini similarity index 100% rename from test/shared/TestCertificates/eku.server.ini rename to src/Servers/Kestrel/shared/test/TestCertificates/eku.server.ini diff --git a/test/shared/TestCertificates/eku.server.pfx b/src/Servers/Kestrel/shared/test/TestCertificates/eku.server.pfx similarity index 100% rename from test/shared/TestCertificates/eku.server.pfx rename to src/Servers/Kestrel/shared/test/TestCertificates/eku.server.pfx diff --git a/test/shared/TestCertificates/make-test-certs.sh b/src/Servers/Kestrel/shared/test/TestCertificates/make-test-certs.sh old mode 100755 new mode 100644 similarity index 100% rename from test/shared/TestCertificates/make-test-certs.sh rename to src/Servers/Kestrel/shared/test/TestCertificates/make-test-certs.sh diff --git a/test/shared/TestCertificates/no_extensions.ini b/src/Servers/Kestrel/shared/test/TestCertificates/no_extensions.ini similarity index 100% rename from test/shared/TestCertificates/no_extensions.ini rename to src/Servers/Kestrel/shared/test/TestCertificates/no_extensions.ini diff --git a/test/shared/TestCertificates/no_extensions.pfx b/src/Servers/Kestrel/shared/test/TestCertificates/no_extensions.pfx similarity index 100% rename from test/shared/TestCertificates/no_extensions.pfx rename to src/Servers/Kestrel/shared/test/TestCertificates/no_extensions.pfx diff --git a/test/shared/TestCertificates/testCert.pfx b/src/Servers/Kestrel/shared/test/TestCertificates/testCert.pfx similarity index 100% rename from test/shared/TestCertificates/testCert.pfx rename to src/Servers/Kestrel/shared/test/TestCertificates/testCert.pfx diff --git a/test/shared/TestConnection.cs b/src/Servers/Kestrel/shared/test/TestConnection.cs similarity index 100% rename from test/shared/TestConnection.cs rename to src/Servers/Kestrel/shared/test/TestConnection.cs diff --git a/test/shared/TestConstants.cs b/src/Servers/Kestrel/shared/test/TestConstants.cs similarity index 100% rename from test/shared/TestConstants.cs rename to src/Servers/Kestrel/shared/test/TestConstants.cs diff --git a/test/shared/TestHttp1Connection.cs b/src/Servers/Kestrel/shared/test/TestHttp1Connection.cs similarity index 100% rename from test/shared/TestHttp1Connection.cs rename to src/Servers/Kestrel/shared/test/TestHttp1Connection.cs diff --git a/test/shared/TestKestrelTrace.cs b/src/Servers/Kestrel/shared/test/TestKestrelTrace.cs similarity index 100% rename from test/shared/TestKestrelTrace.cs rename to src/Servers/Kestrel/shared/test/TestKestrelTrace.cs diff --git a/test/shared/TestResources.cs b/src/Servers/Kestrel/shared/test/TestResources.cs similarity index 100% rename from test/shared/TestResources.cs rename to src/Servers/Kestrel/shared/test/TestResources.cs diff --git a/test/shared/TestServiceContext.cs b/src/Servers/Kestrel/shared/test/TestServiceContext.cs similarity index 100% rename from test/shared/TestServiceContext.cs rename to src/Servers/Kestrel/shared/test/TestServiceContext.cs diff --git a/test/Kestrel.FunctionalTests/AddressRegistrationTests.cs b/src/Servers/Kestrel/test/FunctionalTests/AddressRegistrationTests.cs similarity index 100% rename from test/Kestrel.FunctionalTests/AddressRegistrationTests.cs rename to src/Servers/Kestrel/test/FunctionalTests/AddressRegistrationTests.cs diff --git a/test/Kestrel.FunctionalTests/BadHttpRequestTests.cs b/src/Servers/Kestrel/test/FunctionalTests/BadHttpRequestTests.cs similarity index 100% rename from test/Kestrel.FunctionalTests/BadHttpRequestTests.cs rename to src/Servers/Kestrel/test/FunctionalTests/BadHttpRequestTests.cs diff --git a/test/Kestrel.FunctionalTests/CertificateLoaderTests.cs b/src/Servers/Kestrel/test/FunctionalTests/CertificateLoaderTests.cs similarity index 100% rename from test/Kestrel.FunctionalTests/CertificateLoaderTests.cs rename to src/Servers/Kestrel/test/FunctionalTests/CertificateLoaderTests.cs diff --git a/test/Kestrel.FunctionalTests/ChunkedRequestTests.cs b/src/Servers/Kestrel/test/FunctionalTests/ChunkedRequestTests.cs similarity index 100% rename from test/Kestrel.FunctionalTests/ChunkedRequestTests.cs rename to src/Servers/Kestrel/test/FunctionalTests/ChunkedRequestTests.cs diff --git a/test/Kestrel.FunctionalTests/ChunkedResponseTests.cs b/src/Servers/Kestrel/test/FunctionalTests/ChunkedResponseTests.cs similarity index 100% rename from test/Kestrel.FunctionalTests/ChunkedResponseTests.cs rename to src/Servers/Kestrel/test/FunctionalTests/ChunkedResponseTests.cs diff --git a/test/Kestrel.FunctionalTests/ConnectionAdapterTests.cs b/src/Servers/Kestrel/test/FunctionalTests/ConnectionAdapterTests.cs similarity index 100% rename from test/Kestrel.FunctionalTests/ConnectionAdapterTests.cs rename to src/Servers/Kestrel/test/FunctionalTests/ConnectionAdapterTests.cs diff --git a/test/Kestrel.FunctionalTests/ConnectionLimitTests.cs b/src/Servers/Kestrel/test/FunctionalTests/ConnectionLimitTests.cs similarity index 100% rename from test/Kestrel.FunctionalTests/ConnectionLimitTests.cs rename to src/Servers/Kestrel/test/FunctionalTests/ConnectionLimitTests.cs diff --git a/test/Kestrel.FunctionalTests/DefaultHeaderTests.cs b/src/Servers/Kestrel/test/FunctionalTests/DefaultHeaderTests.cs similarity index 100% rename from test/Kestrel.FunctionalTests/DefaultHeaderTests.cs rename to src/Servers/Kestrel/test/FunctionalTests/DefaultHeaderTests.cs diff --git a/test/Kestrel.FunctionalTests/EventSourceTests.cs b/src/Servers/Kestrel/test/FunctionalTests/EventSourceTests.cs similarity index 100% rename from test/Kestrel.FunctionalTests/EventSourceTests.cs rename to src/Servers/Kestrel/test/FunctionalTests/EventSourceTests.cs diff --git a/test/Kestrel.FunctionalTests/GeneratedCodeTests.cs b/src/Servers/Kestrel/test/FunctionalTests/GeneratedCodeTests.cs similarity index 77% rename from test/Kestrel.FunctionalTests/GeneratedCodeTests.cs rename to src/Servers/Kestrel/test/FunctionalTests/GeneratedCodeTests.cs index bcf34ccaf9..862890542f 100644 --- a/test/Kestrel.FunctionalTests/GeneratedCodeTests.cs +++ b/src/Servers/Kestrel/test/FunctionalTests/GeneratedCodeTests.cs @@ -3,6 +3,7 @@ #if NETCOREAPP2_1 using System.IO; +using Microsoft.AspNetCore.Testing; using Xunit; namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests @@ -12,9 +13,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [Fact] public void GeneratedCodeIsUpToDate() { - const string httpHeadersGeneratedPath = "../../../../../src/Kestrel.Core/Internal/Http/HttpHeaders.Generated.cs"; - const string httpProtocolGeneratedPath = "../../../../../src/Kestrel.Core/Internal/Http/HttpProtocol.Generated.cs"; - const string httpUtilitiesGeneratedPath = "../../../../../src/Kestrel.Core/Internal/Infrastructure/HttpUtilities.Generated.cs"; + var repositoryRoot = TestPathUtilities.GetSolutionRootDirectory("Microsoft.AspNetCore"); + + var httpHeadersGeneratedPath = Path.Combine(repositoryRoot, "src/Servers/Kestrel/Core/src/Internal/Http/HttpHeaders.Generated.cs"); + var httpProtocolGeneratedPath = Path.Combine(repositoryRoot, "src/Servers/Kestrel/Core/src/Internal/Http/HttpProtocol.Generated.cs"); + var httpUtilitiesGeneratedPath = Path.Combine(repositoryRoot, "src/Servers/Kestrel/Core/src/Internal/Infrastructure/HttpUtilities.Generated.cs"); var testHttpHeadersGeneratedPath = Path.GetTempFileName(); var testHttpProtocolGeneratedPath = Path.GetTempFileName(); diff --git a/test/Kestrel.FunctionalTests/HttpConnectionManagerTests.cs b/src/Servers/Kestrel/test/FunctionalTests/HttpConnectionManagerTests.cs similarity index 100% rename from test/Kestrel.FunctionalTests/HttpConnectionManagerTests.cs rename to src/Servers/Kestrel/test/FunctionalTests/HttpConnectionManagerTests.cs diff --git a/test/Kestrel.FunctionalTests/HttpProtocolSelectionTests.cs b/src/Servers/Kestrel/test/FunctionalTests/HttpProtocolSelectionTests.cs similarity index 100% rename from test/Kestrel.FunctionalTests/HttpProtocolSelectionTests.cs rename to src/Servers/Kestrel/test/FunctionalTests/HttpProtocolSelectionTests.cs diff --git a/test/Kestrel.FunctionalTests/HttpsConnectionAdapterOptionsTest.cs b/src/Servers/Kestrel/test/FunctionalTests/HttpsConnectionAdapterOptionsTest.cs similarity index 100% rename from test/Kestrel.FunctionalTests/HttpsConnectionAdapterOptionsTest.cs rename to src/Servers/Kestrel/test/FunctionalTests/HttpsConnectionAdapterOptionsTest.cs diff --git a/test/Kestrel.FunctionalTests/HttpsConnectionAdapterTests.cs b/src/Servers/Kestrel/test/FunctionalTests/HttpsConnectionAdapterTests.cs similarity index 100% rename from test/Kestrel.FunctionalTests/HttpsConnectionAdapterTests.cs rename to src/Servers/Kestrel/test/FunctionalTests/HttpsConnectionAdapterTests.cs diff --git a/test/Kestrel.FunctionalTests/HttpsTests.cs b/src/Servers/Kestrel/test/FunctionalTests/HttpsTests.cs similarity index 100% rename from test/Kestrel.FunctionalTests/HttpsTests.cs rename to src/Servers/Kestrel/test/FunctionalTests/HttpsTests.cs diff --git a/test/Kestrel.FunctionalTests/KeepAliveTimeoutTests.cs b/src/Servers/Kestrel/test/FunctionalTests/KeepAliveTimeoutTests.cs similarity index 100% rename from test/Kestrel.FunctionalTests/KeepAliveTimeoutTests.cs rename to src/Servers/Kestrel/test/FunctionalTests/KeepAliveTimeoutTests.cs diff --git a/test/Kestrel.FunctionalTests/LoggingConnectionAdapterTests.cs b/src/Servers/Kestrel/test/FunctionalTests/LoggingConnectionAdapterTests.cs similarity index 100% rename from test/Kestrel.FunctionalTests/LoggingConnectionAdapterTests.cs rename to src/Servers/Kestrel/test/FunctionalTests/LoggingConnectionAdapterTests.cs diff --git a/test/Kestrel.FunctionalTests/MaxRequestBodySizeTests.cs b/src/Servers/Kestrel/test/FunctionalTests/MaxRequestBodySizeTests.cs similarity index 100% rename from test/Kestrel.FunctionalTests/MaxRequestBodySizeTests.cs rename to src/Servers/Kestrel/test/FunctionalTests/MaxRequestBodySizeTests.cs diff --git a/test/Kestrel.FunctionalTests/MaxRequestBufferSizeTests.cs b/src/Servers/Kestrel/test/FunctionalTests/MaxRequestBufferSizeTests.cs similarity index 100% rename from test/Kestrel.FunctionalTests/MaxRequestBufferSizeTests.cs rename to src/Servers/Kestrel/test/FunctionalTests/MaxRequestBufferSizeTests.cs diff --git a/test/Kestrel.FunctionalTests/MaxRequestLineSizeTests.cs b/src/Servers/Kestrel/test/FunctionalTests/MaxRequestLineSizeTests.cs similarity index 100% rename from test/Kestrel.FunctionalTests/MaxRequestLineSizeTests.cs rename to src/Servers/Kestrel/test/FunctionalTests/MaxRequestLineSizeTests.cs diff --git a/test/Kestrel.FunctionalTests/Properties/AssemblyInfo.cs b/src/Servers/Kestrel/test/FunctionalTests/Properties/AssemblyInfo.cs similarity index 100% rename from test/Kestrel.FunctionalTests/Properties/AssemblyInfo.cs rename to src/Servers/Kestrel/test/FunctionalTests/Properties/AssemblyInfo.cs diff --git a/test/Kestrel.FunctionalTests/RequestBodyTimeoutTests.cs b/src/Servers/Kestrel/test/FunctionalTests/RequestBodyTimeoutTests.cs similarity index 100% rename from test/Kestrel.FunctionalTests/RequestBodyTimeoutTests.cs rename to src/Servers/Kestrel/test/FunctionalTests/RequestBodyTimeoutTests.cs diff --git a/test/Kestrel.FunctionalTests/RequestHeaderLimitsTests.cs b/src/Servers/Kestrel/test/FunctionalTests/RequestHeaderLimitsTests.cs similarity index 100% rename from test/Kestrel.FunctionalTests/RequestHeaderLimitsTests.cs rename to src/Servers/Kestrel/test/FunctionalTests/RequestHeaderLimitsTests.cs diff --git a/test/Kestrel.FunctionalTests/RequestHeadersTimeoutTests.cs b/src/Servers/Kestrel/test/FunctionalTests/RequestHeadersTimeoutTests.cs similarity index 100% rename from test/Kestrel.FunctionalTests/RequestHeadersTimeoutTests.cs rename to src/Servers/Kestrel/test/FunctionalTests/RequestHeadersTimeoutTests.cs diff --git a/test/Kestrel.FunctionalTests/RequestTargetProcessingTests.cs b/src/Servers/Kestrel/test/FunctionalTests/RequestTargetProcessingTests.cs similarity index 100% rename from test/Kestrel.FunctionalTests/RequestTargetProcessingTests.cs rename to src/Servers/Kestrel/test/FunctionalTests/RequestTargetProcessingTests.cs diff --git a/test/Kestrel.FunctionalTests/RequestTests.cs b/src/Servers/Kestrel/test/FunctionalTests/RequestTests.cs similarity index 100% rename from test/Kestrel.FunctionalTests/RequestTests.cs rename to src/Servers/Kestrel/test/FunctionalTests/RequestTests.cs diff --git a/test/Kestrel.FunctionalTests/ResponseTests.cs b/src/Servers/Kestrel/test/FunctionalTests/ResponseTests.cs similarity index 100% rename from test/Kestrel.FunctionalTests/ResponseTests.cs rename to src/Servers/Kestrel/test/FunctionalTests/ResponseTests.cs diff --git a/test/Kestrel.FunctionalTests/TestHelpers/HostNameIsReachableAttribute.cs b/src/Servers/Kestrel/test/FunctionalTests/TestHelpers/HostNameIsReachableAttribute.cs similarity index 100% rename from test/Kestrel.FunctionalTests/TestHelpers/HostNameIsReachableAttribute.cs rename to src/Servers/Kestrel/test/FunctionalTests/TestHelpers/HostNameIsReachableAttribute.cs diff --git a/test/Kestrel.FunctionalTests/TestHelpers/IPv6ScopeIdPresentConditionAttribute.cs b/src/Servers/Kestrel/test/FunctionalTests/TestHelpers/IPv6ScopeIdPresentConditionAttribute.cs similarity index 100% rename from test/Kestrel.FunctionalTests/TestHelpers/IPv6ScopeIdPresentConditionAttribute.cs rename to src/Servers/Kestrel/test/FunctionalTests/TestHelpers/IPv6ScopeIdPresentConditionAttribute.cs diff --git a/test/Kestrel.FunctionalTests/TestHelpers/IPv6SupportedConditionAttribute.cs b/src/Servers/Kestrel/test/FunctionalTests/TestHelpers/IPv6SupportedConditionAttribute.cs similarity index 100% rename from test/Kestrel.FunctionalTests/TestHelpers/IPv6SupportedConditionAttribute.cs rename to src/Servers/Kestrel/test/FunctionalTests/TestHelpers/IPv6SupportedConditionAttribute.cs diff --git a/test/Kestrel.FunctionalTests/TestHelpers/IWebHostPortExtensions.cs b/src/Servers/Kestrel/test/FunctionalTests/TestHelpers/IWebHostPortExtensions.cs similarity index 100% rename from test/Kestrel.FunctionalTests/TestHelpers/IWebHostPortExtensions.cs rename to src/Servers/Kestrel/test/FunctionalTests/TestHelpers/IWebHostPortExtensions.cs diff --git a/test/Kestrel.FunctionalTests/TestHelpers/TestApplicationErrorLoggerLoggedTest.cs b/src/Servers/Kestrel/test/FunctionalTests/TestHelpers/TestApplicationErrorLoggerLoggedTest.cs similarity index 100% rename from test/Kestrel.FunctionalTests/TestHelpers/TestApplicationErrorLoggerLoggedTest.cs rename to src/Servers/Kestrel/test/FunctionalTests/TestHelpers/TestApplicationErrorLoggerLoggedTest.cs diff --git a/test/Kestrel.FunctionalTests/TestHelpers/TestServer.cs b/src/Servers/Kestrel/test/FunctionalTests/TestHelpers/TestServer.cs similarity index 100% rename from test/Kestrel.FunctionalTests/TestHelpers/TestServer.cs rename to src/Servers/Kestrel/test/FunctionalTests/TestHelpers/TestServer.cs diff --git a/test/Kestrel.FunctionalTests/UpgradeTests.cs b/src/Servers/Kestrel/test/FunctionalTests/UpgradeTests.cs similarity index 100% rename from test/Kestrel.FunctionalTests/UpgradeTests.cs rename to src/Servers/Kestrel/test/FunctionalTests/UpgradeTests.cs diff --git a/src/Servers/Kestrel/test/Libuv.FunctionalTests/Libuv.FunctionalTests.csproj b/src/Servers/Kestrel/test/Libuv.FunctionalTests/Libuv.FunctionalTests.csproj new file mode 100644 index 0000000000..a0a9254fbf --- /dev/null +++ b/src/Servers/Kestrel/test/Libuv.FunctionalTests/Libuv.FunctionalTests.csproj @@ -0,0 +1,30 @@ + + + + netcoreapp2.1;net461 + $(DefineConstants);MACOS + true + + Libuv.FunctionalTests + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/Kestrel.Transport.Libuv.FunctionalTests/ListenHandleTests.cs b/src/Servers/Kestrel/test/Libuv.FunctionalTests/ListenHandleTests.cs similarity index 100% rename from test/Kestrel.Transport.Libuv.FunctionalTests/ListenHandleTests.cs rename to src/Servers/Kestrel/test/Libuv.FunctionalTests/ListenHandleTests.cs diff --git a/test/Kestrel.Transport.Libuv.FunctionalTests/TransportSelector.cs b/src/Servers/Kestrel/test/Libuv.FunctionalTests/TransportSelector.cs similarity index 100% rename from test/Kestrel.Transport.Libuv.FunctionalTests/TransportSelector.cs rename to src/Servers/Kestrel/test/Libuv.FunctionalTests/TransportSelector.cs diff --git a/src/Servers/Kestrel/test/Sockets.FunctionalTests/Sockets.FunctionalTests.csproj b/src/Servers/Kestrel/test/Sockets.FunctionalTests/Sockets.FunctionalTests.csproj new file mode 100644 index 0000000000..052fd78659 --- /dev/null +++ b/src/Servers/Kestrel/test/Sockets.FunctionalTests/Sockets.FunctionalTests.csproj @@ -0,0 +1,29 @@ + + + + netcoreapp2.1;net461 + $(DefineConstants);MACOS + $(DefineConstants);SOCKETS + true + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/Kestrel.Transport.Sockets.FunctionalTests/TransportSelector.cs b/src/Servers/Kestrel/test/Sockets.FunctionalTests/TransportSelector.cs similarity index 100% rename from test/Kestrel.Transport.Sockets.FunctionalTests/TransportSelector.cs rename to src/Servers/Kestrel/test/Sockets.FunctionalTests/TransportSelector.cs diff --git a/test/SystemdActivation/Dockerfile b/src/Servers/Kestrel/test/SystemdActivation/Dockerfile similarity index 100% rename from test/SystemdActivation/Dockerfile rename to src/Servers/Kestrel/test/SystemdActivation/Dockerfile diff --git a/test/SystemdActivation/docker-entrypoint.sh b/src/Servers/Kestrel/test/SystemdActivation/docker-entrypoint.sh similarity index 100% rename from test/SystemdActivation/docker-entrypoint.sh rename to src/Servers/Kestrel/test/SystemdActivation/docker-entrypoint.sh diff --git a/test/SystemdActivation/docker.sh b/src/Servers/Kestrel/test/SystemdActivation/docker.sh similarity index 100% rename from test/SystemdActivation/docker.sh rename to src/Servers/Kestrel/test/SystemdActivation/docker.sh diff --git a/tools/CodeGenerator/CodeGenerator.csproj b/src/Servers/Kestrel/tools/CodeGenerator/CodeGenerator.csproj similarity index 58% rename from tools/CodeGenerator/CodeGenerator.csproj rename to src/Servers/Kestrel/tools/CodeGenerator/CodeGenerator.csproj index c85676e21d..3a209fea5b 100644 --- a/tools/CodeGenerator/CodeGenerator.csproj +++ b/src/Servers/Kestrel/tools/CodeGenerator/CodeGenerator.csproj @@ -5,16 +5,17 @@ Exe false true + false - - + + - $(MSBuildThisFileDirectory)..\..\src\Kestrel.Core + $(MSBuildThisFileDirectory)..\..\Core\src Internal/Http/HttpHeaders.Generated.cs Internal/Http/HttpProtocol.Generated.cs Internal/Infrastructure/HttpUtilities.Generated.cs diff --git a/tools/CodeGenerator/HttpProtocolFeatureCollection.cs b/src/Servers/Kestrel/tools/CodeGenerator/HttpProtocolFeatureCollection.cs similarity index 100% rename from tools/CodeGenerator/HttpProtocolFeatureCollection.cs rename to src/Servers/Kestrel/tools/CodeGenerator/HttpProtocolFeatureCollection.cs diff --git a/tools/CodeGenerator/HttpUtilities/CombinationsWithoutRepetition.cs b/src/Servers/Kestrel/tools/CodeGenerator/HttpUtilities/CombinationsWithoutRepetition.cs similarity index 100% rename from tools/CodeGenerator/HttpUtilities/CombinationsWithoutRepetition.cs rename to src/Servers/Kestrel/tools/CodeGenerator/HttpUtilities/CombinationsWithoutRepetition.cs diff --git a/tools/CodeGenerator/HttpUtilities/HttpUtilities.cs b/src/Servers/Kestrel/tools/CodeGenerator/HttpUtilities/HttpUtilities.cs similarity index 100% rename from tools/CodeGenerator/HttpUtilities/HttpUtilities.cs rename to src/Servers/Kestrel/tools/CodeGenerator/HttpUtilities/HttpUtilities.cs diff --git a/tools/CodeGenerator/HttpUtilities/HttpUtilitiesGeneratorHelpers.cs b/src/Servers/Kestrel/tools/CodeGenerator/HttpUtilities/HttpUtilitiesGeneratorHelpers.cs similarity index 100% rename from tools/CodeGenerator/HttpUtilities/HttpUtilitiesGeneratorHelpers.cs rename to src/Servers/Kestrel/tools/CodeGenerator/HttpUtilities/HttpUtilitiesGeneratorHelpers.cs diff --git a/tools/CodeGenerator/KnownHeaders.cs b/src/Servers/Kestrel/tools/CodeGenerator/KnownHeaders.cs similarity index 100% rename from tools/CodeGenerator/KnownHeaders.cs rename to src/Servers/Kestrel/tools/CodeGenerator/KnownHeaders.cs diff --git a/tools/CodeGenerator/Program.cs b/src/Servers/Kestrel/tools/CodeGenerator/Program.cs similarity index 100% rename from tools/CodeGenerator/Program.cs rename to src/Servers/Kestrel/tools/CodeGenerator/Program.cs diff --git a/test/xunit.runner.json b/src/Servers/Kestrel/xunit.runner.json similarity index 100% rename from test/xunit.runner.json rename to src/Servers/Kestrel/xunit.runner.json diff --git a/shared/Microsoft.Extensions.Buffers.Testing.Sources/BufferSegment.cs b/src/Shared/Buffers.Testing/BufferSegment.cs similarity index 100% rename from shared/Microsoft.Extensions.Buffers.Testing.Sources/BufferSegment.cs rename to src/Shared/Buffers.Testing/BufferSegment.cs diff --git a/shared/Microsoft.Extensions.Buffers.Testing.Sources/CustomMemoryForTest.cs b/src/Shared/Buffers.Testing/CustomMemoryForTest.cs similarity index 100% rename from shared/Microsoft.Extensions.Buffers.Testing.Sources/CustomMemoryForTest.cs rename to src/Shared/Buffers.Testing/CustomMemoryForTest.cs diff --git a/shared/Microsoft.Extensions.Buffers.Testing.Sources/ReadOnlySequenceFactory.cs b/src/Shared/Buffers.Testing/ReadOnlySequenceFactory.cs similarity index 100% rename from shared/Microsoft.Extensions.Buffers.Testing.Sources/ReadOnlySequenceFactory.cs rename to src/Shared/Buffers.Testing/ReadOnlySequenceFactory.cs diff --git a/test/Directory.Build.props b/test/Directory.Build.props deleted file mode 100644 index 44033a6dc3..0000000000 --- a/test/Directory.Build.props +++ /dev/null @@ -1,31 +0,0 @@ - - - - - netcoreapp2.1 - $(DeveloperBuildTestTfms) - netcoreapp2.1 - $(StandardTestTfms);net461 - - - - - true - - - - - - - - - - - - - - - diff --git a/test/Kestrel.Core.Tests/Kestrel.Core.Tests.csproj b/test/Kestrel.Core.Tests/Kestrel.Core.Tests.csproj deleted file mode 100644 index 2074ed6526..0000000000 --- a/test/Kestrel.Core.Tests/Kestrel.Core.Tests.csproj +++ /dev/null @@ -1,29 +0,0 @@ - - - - Microsoft.AspNetCore.Server.Kestrel.Core.Tests - Microsoft.AspNetCore.Server.Kestrel.Core.Tests - $(StandardTestTfms) - true - - - - - - - - - - - - - - - - - - - - - - diff --git a/test/Kestrel.Tests/Kestrel.Tests.csproj b/test/Kestrel.Tests/Kestrel.Tests.csproj deleted file mode 100644 index d383f39603..0000000000 --- a/test/Kestrel.Tests/Kestrel.Tests.csproj +++ /dev/null @@ -1,20 +0,0 @@ - - - - Microsoft.AspNetCore.Server.Kestrel.Tests - Microsoft.AspNetCore.Server.Kestrel.Tests - $(StandardTestTfms) - - - - - - - - - - - - - - diff --git a/test/Kestrel.Transport.Libuv.FunctionalTests/Kestrel.Transport.Libuv.FunctionalTests.csproj b/test/Kestrel.Transport.Libuv.FunctionalTests/Kestrel.Transport.Libuv.FunctionalTests.csproj deleted file mode 100644 index 4e48a8d666..0000000000 --- a/test/Kestrel.Transport.Libuv.FunctionalTests/Kestrel.Transport.Libuv.FunctionalTests.csproj +++ /dev/null @@ -1,36 +0,0 @@ - - - - Libuv.FunctionalTests - Libuv.FunctionalTests - $(StandardTestTfms) - $(DefineConstants);MACOS - true - - Libuv.FunctionalTests - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/test/Kestrel.Transport.Libuv.Tests/Kestrel.Transport.Libuv.Tests.csproj b/test/Kestrel.Transport.Libuv.Tests/Kestrel.Transport.Libuv.Tests.csproj deleted file mode 100644 index ef4f1d7742..0000000000 --- a/test/Kestrel.Transport.Libuv.Tests/Kestrel.Transport.Libuv.Tests.csproj +++ /dev/null @@ -1,26 +0,0 @@ - - - - Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests - Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests - $(StandardTestTfms) - true - true - - - - - - - - - - - - - - - - - - diff --git a/test/Kestrel.Transport.Sockets.FunctionalTests/Kestrel.Transport.Sockets.FunctionalTests.csproj b/test/Kestrel.Transport.Sockets.FunctionalTests/Kestrel.Transport.Sockets.FunctionalTests.csproj deleted file mode 100644 index ca79f38600..0000000000 --- a/test/Kestrel.Transport.Sockets.FunctionalTests/Kestrel.Transport.Sockets.FunctionalTests.csproj +++ /dev/null @@ -1,35 +0,0 @@ - - - - Sockets.FunctionalTests - Sockets.FunctionalTests - $(StandardTestTfms) - $(DefineConstants);MACOS - $(DefineConstants);SOCKETS - true - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/version.props b/version.props deleted file mode 100644 index 8d05c92ab8..0000000000 --- a/version.props +++ /dev/null @@ -1,12 +0,0 @@ - - - 2.1.3 - rtm - $(VersionPrefix) - $(VersionPrefix)-$(VersionSuffix)-final - t000 - a- - $(FeatureBranchVersionPrefix)$(VersionSuffix)-$([System.Text.RegularExpressions.Regex]::Replace('$(FeatureBranchVersionSuffix)', '[^\w-]', '-')) - $(VersionSuffix)-$(BuildNumber) - -